@ractive-ch/tab-mcp-client 0.21.0-rc.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/webmcp.d.ts CHANGED
@@ -33,10 +33,15 @@ export type WebMcpCall = (tool: RegisteredTool, input: unknown, signal: unknown,
33
33
  * stays here: warned once per name, the tool still offered through the relay.
34
34
  * The page joins the handshake with the tab-mcp browser extension: `mcp`
35
35
  * is its `TabMcp`, `app` its app id, `options` its options
36
- * (`trustExtension`), `version` the library's. The extension's state is `mcp.extension`, defined
36
+ * (`trustExtension`, and `onConfirm` for the warning below), `version` the
37
+ * library's. A tool that asks, mirrored with an `exposedTo` that names
38
+ * other origins on a page without `onConfirm`, is warned about once per
39
+ * name (`warnUnasked`): documents of those origins can run it, and the
40
+ * library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined
37
41
  * here on the instance (the core only declares it, for its bytes), and
38
42
  * `extensionchange` is sent here.
39
43
  */
40
44
  export declare function mirror(registry: ToolRegistry, context: ModelContext, call: WebMcpCall, mcp: HandshakePage["mcp"], app: string, options: {
41
45
  trustExtension?: boolean;
46
+ onConfirm?: unknown;
42
47
  }, version: string): void;
@@ -1,4 +0,0 @@
1
- var l=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),h=(e)=>typeof e==="string"&&e.length<=256;function x(e){return l(e)&&h(e.name)&&h(e.host)?{name:e.name,host:e.host}:void 0}function u(e){return JSON.stringify(e,(n,t)=>l(t)?Object.fromEntries(Object.entries(t).sort(([o],[i])=>o<i?-1:o>i?1:0)):t)??""}var E=()=>performance.now();class T{#o;#n=[];#t;#e=[];constructor(e){this.#o=e,e.addEventListener("tab-mcp-extension",(n)=>this.#r(n.detail)),e.documentElement?.setAttribute("data-tab-mcp-handshake","1")}join(e){if(this.#n.push(e),this.#t!==void 0)e.set(this.#t);e.mcp.addEventListener("grantschange",()=>this.#s(e,"update")),this.#s(e,"hello")}#s(e,n){let t=this.#o.defaultView?.CustomEvent??CustomEvent;this.#o.dispatchEvent(new t("tab-mcp-page",{detail:JSON.stringify({v:1,type:n,library:e.version,app:e.app,apps:e.mcp.grants.slice(0,64).map((o)=>({name:o.client.name,host:o.client.host}))})}))}#r(e){let n;try{n=typeof e==="string"?JSON.parse(e):void 0}catch{return}if(!l(n)||n.v!==1)return;if(n.type==="vouch")this.#a(n);else if(n.type==="withdraw")this.#e=this.#e.filter((t)=>t.nonce!==n.nonce);else if(n.type==="hello"||n.type==="update"){let t=S(n);if(t===null)return;if(u(t)!==u(this.#t)){this.#t=t;for(let o of this.#n)o.set(t)}if(n.type==="hello")for(let o of this.#n)this.#s(o,"update")}}#a(e){let n=x(e.app),{tool:t,nonce:o}=e;if(n===void 0||typeof t!=="string"||typeof o!=="string"||!l(e.arguments))return;if(this.#i(),this.#e.some((i)=>i.nonce===o))return;for(let i of this.#n){let r=i.trust?i.registry.get(t):void 0;if(r===void 0)continue;if(this.#e.push({tool:r,args:u(e.arguments),nonce:o,app:n,at:E()}),this.#e.length>16)this.#e.shift();return}}#i(){let e=E();this.#e=this.#e.filter((n)=>e-n.at<=2000)}take(e,n){this.#i();let t=u(n),o=this.#e.findIndex((i)=>i.tool===e&&i.args===t);return o<0?void 0:this.#e.splice(o,1)[0]?.app}}function S(e){if(e.on!==!0)return e.on===!1?void 0:null;let{name:n,version:t,apps:o}=e;if(!h(n)||!h(t)||!Array.isArray(o))return null;let i=o.slice(0,64).map(x);if(i.some((r)=>r===void 0))return null;return Object.freeze({name:n,version:t,apps:Object.freeze(i.map((r)=>Object.freeze(r))),whileInFront:e.whileInFront!==!1})}var b=new WeakMap;function H(e){let n=globalThis.document;if(n===void 0||globalThis.top!==globalThis.window)return;let t=b.get(n);if(t===void 0)t=new T(n),b.set(n,t);return t.join(e),t}var C=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"];function R(e,n,t,o,i,r,A){let f;Object.defineProperty(o,"extension",{get:()=>f,configurable:!0});let g;try{g=H({version:A,app:i,registry:e,trust:r.trustExtension!==!1,mcp:o,set:(s)=>{f=s,o.dispatchEvent(new CustomEvent("extensionchange",{detail:{extension:s}}))}})}catch(s){console.warn("tab-mcp: no handshake with the browser extension:",s)}let d=new Map,y=new Set,m=()=>{for(let[s,c]of d){if(e.get(s.name)===s)continue;c.abort(),d.delete(s)}for(let s of e.list()){let{annotations:c,callers:v}=s,O=c.consequentialHint??c.destructiveHint;if(d.has(s)||!(v?.includes("webmcp")??!0))continue;let w=new AbortController;d.set(s,w);let k={consequentialHint:O};for(let a of C)k[a]??=c[a];let{signal:p}=w;Promise.resolve().then(()=>p.aborted||n.registerTool({name:s.name,title:s.title,description:s.description,inputSchema:s.inputSchema,outputSchema:s.outputSchema,annotations:k,execute:(a,P)=>t(s,a,P?.signal,g?.take(s,a))},{signal:p,exposedTo:s.exposedTo})).catch((a)=>{if(p.aborted)return;if(y.has(s.name))return;y.add(s.name),console.warn(`tab-mcp: ${s.name} is not offered through WebMCP:`,a)})}};e.onChange(m),m()}export{R as mirror};
2
-
3
- //# debugId=AF0EF5175E5359E464756E2164756E21
4
- //# sourceMappingURL=webmcp-ny13npet.min.js.map