Lines 1-25javascript
1async function Nt(n,t=0){let e=new TextEncoder().encode(n);if(!crypto.subtle)throw"Requires secure origin (localhost or https:)";let o=await crypto.subtle.digest("SHA-1",e),r=new Uint8Array(o),s=String.fromCodePoint(...r),a=btoa(s).replaceAll("+","-").replaceAll("/","_").replaceAll("=","");return t?a.substring(0,t):a}async function Me(n,t=0){let e=new TextEncoder().encode(n);if(!crypto.subtle)throw"Requires secure origin (localhost or https:)";let o=await crypto.subtle.digest("SHA-1",e),s=Array.from(new Uint8Array(o)).map(i=>i.toString(16).padStart(2,"0")).join("");return t?s.substring(0,t):s} ...
2`))>=0;){let x=c.slice(0,p);c=c.slice(p+1),await i(x)}}return c+=l.decode(),await i(c),s}normalizeTargetParty(t){let e=String(t??"").trim();if(!e)throw"Daemon host is required";try{let o=e.includes("://")?new URL(e):new URL(`${globalThis.location.protocol}//${e}`);if(!o.host)throw"missing host";return o.host}catch{throw`Invalid daemon host: ${t}`}}#r(){if(!this.#t)throw"Browser app is not initialised";return this.#t}};function Be(n=void 0){let t=new M;return t.register("browser_daemon_identity",{type:"function",name:"browser_daemon_identity",execution:"client",description:"Get the active chat ...
3${btoa(String.fromCharCode(...new Uint8Array(e))).match(/.{1,64}/g)?.join(`
5-----END PUBLIC KEY-----`}async privatePem(){if(!this.#e)throw"Must generate keypair";let t=this.#e.privateKey,e=await crypto.subtle.exportKey("pkcs8",t);return`-----BEGIN PRIVATE KEY-----
CriticalCritical Secret
Package contains a critical-looking secret pattern.
dist/index.jsView on unpkg · L5 6${btoa(String.fromCharCode(...new Uint8Array(e))).match(/.{1,64}/g)?.join(`
8-----END PRIVATE KEY-----`}};async function We(){let n=await y.getInstance(),t=n.getPartyOrigin(),e=new URL(`${t}/catalog`);e.searchParams.append("alert","");let r=await(await fetch(e,{headers:{"X-Tabserver-Token":n.getTokenBase64(),Accept:"application/json"}})).json();if("error"in r)throw r.error;return r.ok.alert.find(i=>i.type=="LAUNCH"&&i.sourceUrl==new URL(n.getAppUrl()))||null}var st=class{#t;#e;#o;#s;#n;#r;#l;async initWithKey(t,e,o,r){this.#e=e.startsWith("https:")?"https:":"http:",this.#o=t,this.#n=e,this.#t=o,this.#s=r,await this.#h()}async checkActivate(){if(!this.#r)throw"checkActi ...
10${n}`:t}function ht(n){return n!=null}var te="2025-06-18",D={"Access-Control-Allow-Origin":"*"},ee="POST, GET",pt=class{#t;constructor(t){this.#t=t}listTools(){return this.#t.map(t=>({name:t.name,...t.title===void 0?{}:{title:t.title},description:t.description,inputSchema:t.inputSchema,...t.outputSchema===void 0?{}:{outputSchema:t.outputSchema},...t.annotations===void 0?{}:{annotations:t.annotations}}))}async callTool(t,e,o){let r=this.#t.find(s=>s.name===t);if(!r)throw new f(-32602,`Unknown tool: ${t}`);return await r.call(e,o)}},j=class{#t;#e;#o;constructor(t,e){this.#t=t,typeof e=="function ...
13`,{headers:{...D,"Content-Type":"text/event-stream","Cache-Control":"no-cache"}})}function dt(){return new Response(null,{status:405,headers:{...D,Allow:ee}})}function re(n){return typeof n=="string"||typeof n=="number"||n===null?n:null}var H="application/x-ndjson",G=class extends Array{#t;constructor(t){super(),this.#t=t}static get[Symbol.species](){return Array}push(...t){for(let e of t)this.#t?.(e);return super.push(...t)}};function V(n,t){se(n,t.reasoning),t.content?n.push({role:"assistant",content:t.content}):t.toolCalls?.length||n.push({role:"assistant",content:""})}function se(n,t){for( ...
14${JSON.stringify(n.input,null,2)}`}function A(n,t,e,o,r=!1){o&&n.push({role:"tool-result",content:ie(t,e,r),...r?{error:!0}:{}})}function ie
15${t}`}function mt(n,t={}){let e=t.toolDetails??!0,o=t.clientToolNames,r=[];for(let s of n)if(s.role==="assistant"){if(V(r,s),e)for(let i of s.toolCalls??[])r.push({role:"tool",content:
16`)),i=new G(a=>s({type:"event",event:a}));try{let a=await t(i);s({type:"done",...a.clientToolCalls?.length?{clientToolCalls:a.clientToolCalls}:{}})}catch(a){console.error(a),s({type:"error",message:String(a)})}finally{r.close()}}});return new Response(o,{status:200,headers:{"Content-Type":H,"Cache-Control":"no-cache","Access-Control-Allow-Origin":"*"}})}async askExpert(t,e){let o=e.trim();if(!o)throw"Question is required";let r=this.#G(void 0),s=T(t),i=await this.#k(r,{expert:!0},s),a=this.#i.temperature,l=t.headers.get(_),c=l?Se(t,l):null;if(c)return await this.#T(t,r,s,c,i,a,o);let u=await t ...
17When answering expert MCP questions, prefer semantic and structured memory under root "${s}" when looking up remembered information.`:"",a=await this.#Z(t,o),l=await this.#et(t,o);return`${r}${i}${a}${l}`}async#Z(t,e){try{let o=await this.#x(t,e),r=z(),s=r?await this.#tt(t,r,e,o):await this.#E(t,{collections:o},e);return Ee(s)}catch{return`
19Semantic memory catalog is unavailable for this session.`}}async#tt(t,e,o,r){let s=await this.#E(t,{root:e,collections:r},o);return s.length?s:await this.#E(t,{collections:r},o)}async#E(t,e,o){let r=await this.#c(t,"/ai/memory/catalog",{kind:"semantic",...e.root?{root:e.root}:{},...e.collections?{collections:e.collections}:{}},o);return Array.isArray(r.resources)?r.resources:[]}async#et(t,e){try{let o=await this.#P(t,e),r=z(),s=r?await this.#F(t,{root:r,collections:o},e):[],i=r&&s.length?s:await this.#F(t,{collections:o},e);return Ne(i)}catch{return`
21Structured memory catalog is unavailable for this session.`}}async#F(t,e,o){let r=await this.#c(t,"/ai/memory/catalog",{kind:"structured",...e.root?{root:e.root}:{},...e.collections?{collections:e.collections}:{}},o);return Array.isArray(r.resources)?r.resources:[]}#N(){return this.#i.systemPrompt??this.#e}#ot(){return{...this.#i,systemPrompt:this.#N()}}#nt(t){if(t.systemPrompt!==void 0){if(typeof t.systemPrompt!="string")throw"systemPrompt must be a string";this.#i.systemPrompt=t.systemPrompt.trim()?t.systemPrompt:this.#e}if(t.temperature!==void 0){if(typeof t.temperature!="number"||!Number.i ...
23${e??"default"}`}function Se(n,t){try{let e=g.from(n);return e?`${e.getSub()}
25${t}`:null}catch{return null}}function Re(n){let t=n.headers.get(xt);if(t)return t;let e=n.headers.get(v);if(e)return e;throw`This request must provide a token in '${xt}'`}function T(n){let t
Long lines were clipped for display.