@ractive-ch/tab-mcp-client 0.5.1 → 0.6.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.
@@ -1,5 +1,5 @@
1
- var S,y,f,p=(e,t)=>{for(var[n,i,o]of S||[])for(var s=[e],r=globalThis,a=r.document,d,h,u,c,l;h=s.pop();)if(!y[h]&&(u=i[h])){y[h]=1;for(c=1;c<u.length;c++)s.push(o[u[c]]);if(!t&&h!==e&&(d=a&&a.head)){if(f===void 0)f=(c=a.querySelector("meta[property=csp-nonce]"))&&(c.nonce||c.getAttribute("nonce"))||"";if(l=a.createElement("link"),l.rel="modulepreload",l.crossOrigin="",f)l.nonce=f;l.href=new r.URL(u[0],n),d.appendChild(l)}}},A=(e,t,n,i)=>{for(var o={},s=0;s<t.length;s++)o[t[s]]=n[s];(S||=[]).push([e,o,t]),y||={},p(t[i],1)};A(import.meta.url,["2mjtg9am","by0y4k0a","xh7shp5z"],[["./tab-mcp-client.min.js"],["./connection-by0y4k0a.min.js"],["./ui-xh7shp5z.min.js"]],0);
2
- class m{#e=new Map;has(e,t){return this.#e.get(e)?.has(t)===!0}add(e,t){let n=this.#e.get(e)??new Set;n.add(t),this.#e.set(e,n)}keepGrants(e){let t=new Set(e);for(let n of this.#e.keys())if(!t.has(n))this.#e.delete(n)}keepTools(e){let t=new Set(e);for(let n of this.#e.values())for(let i of n)if(!t.has(i))n.delete(i)}}var M=/^[A-Za-z0-9_.-]{1,128}$/;function v(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function E(e,t=0){if(t>64||typeof e!=="object"||e===null)return!1;if(!Array.isArray(e)&&"x-mcp-header"in e)return!0;return Object.values(e).some((n)=>E(n,t+1))}function L(e,t){let n=e;for(let i of t.split("/").slice(1)){let o=decodeURIComponent(i).replaceAll("~1","/").replaceAll("~0","~");if(typeof n!=="object"||n===null||!Object.hasOwn(n,o))return;n=n[o]}return n}function P(e){let t=new Set,n=[],i=[],o=(s,r)=>{if(r>64||typeof s!=="object"||s===null)return;if(!Array.isArray(s)){let a=s;if(typeof a.$anchor==="string")t.add(a.$anchor);if(typeof a.$ref==="string")n.push(a.$ref);if(typeof a.pattern==="string")i.push(a.pattern);let d=a.patternProperties;if(typeof d==="object"&&d!==null)i.push(...Object.keys(d))}for(let a of Object.values(s))o(a,r+1)};o(e,0);for(let s of i)try{new RegExp(s,"u")}catch{return`pattern ${JSON.stringify(s)} is not a valid regular expression`}for(let s of n){if(!s.startsWith("#"))return`$ref ${JSON.stringify(s)} points outside the schema`;let r=s.slice(1);if(!(r===""||(r.startsWith("/")?L(e,r)!==void 0:t.has(r))))return`$ref ${JSON.stringify(s)} does not resolve`}return}function k(e){if(!v(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:i,inputSchema:o,execute:s,annotations:r}=e;if(typeof t!=="string"||!M.test(t))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(t)})`);if(typeof i!=="string"||i.trim()==="")throw TypeError(`registerTool: tool ${t} needs a description`);if(n!==void 0&&typeof n!=="string")throw TypeError(`registerTool: the title of ${t} must be a string`);if(typeof s!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let a=o??{type:"object"};if(!v(a)||a.type!=="object")throw TypeError(`registerTool: the inputSchema of ${t} must be a JSON Schema object with "type": "object"`);if(E(a))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let d=P(a);if(d!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${d}`);let h;try{h=JSON.parse(JSON.stringify(a))}catch{throw TypeError(`registerTool: the inputSchema of ${t} must be JSON`)}if(r!==void 0&&!v(r))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let u={};for(let[c,l]of Object.entries(r??{}))if(typeof l==="boolean")u[c]=l;return{name:t,title:n,description:i,inputSchema:h,annotations:u,execute:s}}class w{#e=new Map;#o=new Set;register(e,t={}){let n=k(e),{signal:i}=t;if(i?.aborted)return;if(this.#e.has(n.name))throw new DOMException(`registerTool: a tool named ${n.name} is already registered`,"InvalidStateError");this.#e.set(n.name,n),i?.addEventListener("abort",()=>{if(this.#e.get(n.name)===n)this.#e.delete(n.name),this.#r()},{once:!0}),this.#r()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#o.add(e),()=>this.#o.delete(e)}#r(){for(let e of[...this.#o])e()}}var x=/^[A-Za-z0-9_-]{43}$/;function N(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function D(){return N(crypto.getRandomValues(new Uint8Array(32)))}function b(e){return typeof e==="string"&&x.test(e)}function j(){try{return globalThis.localStorage??null}catch{return null}}class g{#e;#o;#r;#c;#p;constructor(e,t,n){this.#e=e===void 0?j():e,this.#o=t,this.#r=n,this.#c=n===void 0?void 0:`${n}#moved`}get(){let e=null;try{if(e=this.#e?.getItem(this.#o)??null,!b(e)&&this.#r!==void 0&&this.#c!==void 0&&this.#e?.getItem(this.#c)==null){let t=this.#e?.getItem(this.#r)??null;if(b(t))e=t,this.#y(t)}}catch{}if(b(e))return this.#p=e,e;return this.#p??this.rotate()}rotate(){let e=D();return this.#p=e,this.#y(e),e}#y(e){try{if(this.#e?.setItem(this.#o,e),this.#c!==void 0)this.#e?.setItem(this.#c,this.#o)}catch{}}}var I="@ractive-ch/tab-mcp-client",T="0.5.1";var _=new Set(["localhost","127.0.0.1","[::1]"]),C=[5000,1e4,20000,40000,60000],R=new Set(["network","heartbeat","shutdown"]);function K(e){if(e===!1)return;if(e===void 0||e===!0)return C;let t=e.delaysMs??C;if(!Array.isArray(t)||t.length===0||!t.every((n)=>typeof n==="number"&&n>=0&&n<2147483648))throw TypeError("TabMcp: reconnect.delaysMs: a non-empty list of ms");return[...t]}function H(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((t)=>{let n=t.codePointAt(0)??0;return n<32||n>=127&&n<=159})}function J(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let n=t.protocol==="https:"||t.protocol==="wss:";if(!n&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!n&&!_.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let i=`${n?"https:":"http:"}//${t.host}`,o=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=o.endsWith("/tab")?o:`${o}/tab`,t.search="",t.hash="",{url:t.href,origin:i}}function U(e){try{return new URL(e).host}catch{return""}}function G(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,pairing:e.pairing==="oidc"?"oidc":"code",expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}class O extends EventTarget{#e=new w;#o;#r;#c;#p;#y;#I;#M;#w="none";#L;#l=0;#P;#n="disconnected";#h;#g=[];#b=new m;#u=!1;#C;#i;#s;#m=0;#k;#a;#f;#T;#S=!1;constructor(e){super();let{url:t,origin:n}=J(e.relay),{server:i,appName:o}=e;if(typeof i?.name!=="string"||typeof i.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(o!==void 0&&!H(o))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");this.#y=t,this.#o={...i},this.#r=o,this.#c=e.onConfirm,this.#p=e.confirmDelayMs,this.#M=e.identityAssertion,this.#P=e.identityTimeoutMs??15000,this.#k=K(e.reconnect),this.#I=e.storageKey===void 0?new g(e.storage,`tab-mcp:secret:${n}:${encodeURIComponent(i.name)}`,`tab-mcp:secret:${n}`):new g(e.storage,e.storageKey),this.#e.onChange(()=>{let s=this.tools;this.#b.keepTools(s),this.#t("toolschange",{tools:s})})}registerTool(e,t={}){try{this.#e.register(e,t)}catch(n){return Promise.reject(n)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#n}get session(){return this.#h}get address(){return this.#h?.address}get appName(){return this.#h?.appName??this.#r}get grants(){return this.#g}get reconnecting(){return this.#a}get identity(){return this.#w}get identityMessage(){return this.#L}refreshIdentity(){let e=this.#h,t=this.#M;if(this.#n!=="connected"||e===void 0||t===void 0)return Promise.resolve(!1);let n=++this.#l,i=this.#i;return this.#d("pending"),new Promise((o)=>{let s=(r)=>{if(r.detail.state==="pending")return;this.removeEventListener("identitychange",s),o(r.detail.state==="bound")};this.addEventListener("identitychange",s),Promise.resolve().then(()=>t({address:e.address,sessionId:e.sessionId})).then((r)=>{if(n!==this.#l||this.#i!==i)return;if(typeof r!=="string"||r===""){this.#d("none");return}if(i?.send({type:"identity",assertion:r,round:n})!==!0){this.#d("none");return}setTimeout(()=>{if(n!==this.#l||this.#w!=="pending")return;this.#l++,this.#d("none")},this.#P)},(r)=>{if(n!==this.#l)return;this.#t("error",{error:r instanceof Error?r:Error(String(r))}),this.#d("none")})})}signOut(){if(this.#l++,this.#d("none"),this.#n!=="connected")return!1;return this.#i?.send({type:"identity.logout"})===!0}get pairing(){return this.#u}get pairingCode(){return this.#C}connect(e={}){if(this.#n==="connected"&&this.#h!==void 0)return Promise.resolve(this.#h);if(this.#s!==void 0){if(this.#a!==void 0)this.#S=!0;return this.#s}if(this.#a!==void 0)return this.#R(!0);let t=globalThis.navigator?.userActivation;if(e.resume!==!0&&t!==void 0&&!t.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));return this.#x()}#x(){this.#v("connecting");let e=this.#D(this.#m);return this.#s=e,e.then(()=>{if(this.#s===e)this.#s=void 0},()=>{if(this.#s!==e)return;this.#s=void 0,this.#i=void 0,this.#v("disconnected")}),e}async#D(e){let{openConnection:t}=await (p("by0y4k0a"),import("./connection-by0y4k0a.min.js"));if(e!==this.#m)throw new DOMException("The connection was cancelled","AbortError");let n={},i=t(this.#K(n),this.#y,this.#I.get());return n.connection=i,this.#i=i,i.ready}disconnect(){this.#$("user")}newAddress(){let e=this.#n!=="disconnected"||this.#a!==void 0;if(this.#n==="connected")this.#i?.send({type:"grants.revokeAll"});return this.#$("new_address"),this.#I.rotate(),e?this.connect():Promise.resolve(void 0)}#$(e){this.#O(),this.#m++;let t=this.#i,n=this.#n==="connected";if(this.#i=void 0,this.#s=void 0,t?.close(e),this.#n==="disconnected")return;if(this.#h=void 0,this.#E(void 0),this.#l++,this.#d("none"),this.#v("disconnected"),n)this.#t("disconnected",{reason:e,code:1000})}#N(e,t){let n=this.#k;if(n===void 0)return;let i=n[Math.min(t,n.length)-1]??0;clearTimeout(this.#f),this.#f=setTimeout(()=>{this.#R().catch(()=>{})},i),this.#j(),this.#a={reason:e,attempt:t,at:Date.now()+i},this.#t("reconnecting",this.#a)}#R(e=!1){if(clearTimeout(this.#f),this.#f=void 0,this.#s!==void 0)return this.#s;let t=this.#a;this.#S=e;let n=this.#x();return n.catch((i)=>{let o=this.#S;if(this.#S=!1,t===void 0||this.#a!==t)return;let s=i?.reason;if(s===void 0||R.has(s)){this.#N(t.reason,t.attempt+1);return}this.#O(o?void 0:i instanceof Error?i:Error(String(i)))}),n}#j(){if(this.#T!==void 0)return;let e=globalThis,t=globalThis.document,n=()=>{if(this.#f!==void 0)this.#R().catch(()=>{})},i=()=>{if(t?.visibilityState!=="hidden")n()};t?.addEventListener("visibilitychange",i),e.addEventListener?.("online",n),this.#T=()=>{t?.removeEventListener("visibilitychange",i),e.removeEventListener?.("online",n)}}#O(e){if(clearTimeout(this.#f),this.#f=void 0,this.#T?.(),this.#T=void 0,this.#a===void 0)return;if(this.#a=void 0,e!==void 0)this.#t("error",{error:e});this.#t("reconnecting",null)}startPairing(){if(this.#u)return;if(this.#u=!0,this.#n==="connected")this.#i?.send({type:"pairing.start"})}stopPairing(){if(!this.#u)return;if(this.#u=!1,this.#n==="connected")this.#i?.send({type:"pairing.stop"});this.#E(void 0)}revoke(e){if(this.#n!=="connected")return!1;return this.#i?.send({type:"grant.revoke",grantId:e})===!0}async showConnectDialog(e={}){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("xh7shp5z"),import("./ui-xh7shp5z.min.js"));await n(this,t,e.document??globalThis.document)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#t(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#v(e){if(this.#n===e)return;this.#n=e,this.#t("statechange",{state:e})}#d(e,t){if(this.#w===e&&t===void 0)return;this.#w=e,this.#L=e==="refused"?t:void 0,this.#t("identitychange",t===void 0?{state:e}:{state:e,message:t})}#E(e){if(this.#C===void 0&&e===void 0)return;this.#C=e,this.#t("pairingcode",e??null)}#A(e){this.#g=e,this.#b.keepGrants(e.map((t)=>t.grantId)),this.#t("grantschange",{grants:e})}#_(e){if(this.#c!==void 0){let t=this.#c;return Promise.resolve().then(()=>t(e)).then((n)=>n===!0)}return this.confirmInPage(e)}confirmInPage(e){let{grantId:t}=e.client;if(this.#b.has(t,e.tool.name))return Promise.resolve(!0);let n=globalThis.document;if(n===void 0)return Promise.resolve(!1);let i=this.#p;return (p("xh7shp5z"),import("./ui-xh7shp5z.min.js")).then((o)=>o.confirmDialog(e,n,i===void 0?{}:{allowDelayMs:i})).then((o)=>{if(o==="always"&&this.#g.some((s)=>s.grantId===t))this.#b.add(t,e.tool.name);return o!=="deny"})}#K(e){let t=()=>e.connection!==void 0&&this.#i===e.connection;return{registry:this.#e,server:this.#o,appName:this.#r,library:{name:I,version:T},confirm:(n)=>this.#_(n),toolCallStarted:(n)=>this.#t("toolcall",n),toolCallEnded:(n)=>this.#t("toolcallend",n),clientFor:(n)=>{let i=this.#g.find((s)=>s.grantId===n.grantId),o={grantId:n.grantId,id:n.clientId,host:U(n.clientId)};if(i!==void 0)o.name=i.client.name;return o},sessionStarted:(n)=>{let i=G(n);if(!t())return i;if(this.#h=i,this.#O(),this.#v("connected"),this.#A([...n.grants]),this.#u)this.#i?.send({type:"pairing.start"});if(this.#t("connected",i),i.pairing==="oidc")this.refreshIdentity();return i},pairingCode:(n)=>{if(t()&&this.#u)this.#E(n)},grantAdded:(n)=>{if(!t())return;this.#A([...this.#g.filter((i)=>i.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#A(this.#g.filter((i)=>i.grantId!==n))},replaced:()=>{if(t())this.#t("replaced",null)},identityResult:(n,i,o)=>{if(!t())return;if(i!==this.#l)return;if(n)this.#d("bound");else this.#d("refused",o??"")},error:(n)=>{if(t())this.#t("error",{error:n})},closed:(n,i)=>{if(!t())return;let o=this.#m;if(this.#i=void 0,this.#h=void 0,this.#E(void 0),this.#l++,this.#d("none"),this.#v("disconnected"),this.#t("disconnected",{reason:n,code:i}),R.has(n)&&this.#m===o&&this.#n==="disconnected"&&this.#s===void 0)this.#N(n,1)}}}}export{O as TabMcp,T as VERSION};
1
+ var S,m,f,p=(e,t)=>{for(var[n,i,o]of S||[])for(var r=[e],a=globalThis,s=a.document,d,h,u,c,l;h=r.pop();)if(!m[h]&&(u=i[h])){m[h]=1;for(c=1;c<u.length;c++)r.push(o[u[c]]);if(!t&&h!==e&&(d=s&&s.head)){if(f===void 0)f=(c=s.querySelector("meta[property=csp-nonce]"))&&(c.nonce||c.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",f)l.nonce=f;l.href=new a.URL(u[0],n),d.appendChild(l)}}},M=(e,t,n,i)=>{for(var o={},r=0;r<t.length;r++)o[t[r]]=n[r];(S||=[]).push([e,o,t]),m||={},p(t[i],1)};M(import.meta.url,["v6x0ap9k","nygehv52","yknfss9n"],[["./tab-mcp-client.min.js"],["./connection-nygehv52.min.js"],["./ui-yknfss9n.min.js"]],0);
2
+ class y{#e=new Map;has(e,t){return this.#e.get(e)?.has(t)===!0}add(e,t){let n=this.#e.get(e)??new Set;n.add(t),this.#e.set(e,n)}keepGrants(e){let t=new Set(e);for(let n of this.#e.keys())if(!t.has(n))this.#e.delete(n)}keepTools(e){let t=new Set(e);for(let n of this.#e.values())for(let i of n)if(!t.has(i))n.delete(i)}}var L=/^[A-Za-z0-9_.-]{1,128}$/;function v(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function E(e,t=0){if(t>64||typeof e!=="object"||e===null)return!1;if(!Array.isArray(e)&&"x-mcp-header"in e)return!0;return Object.values(e).some((n)=>E(n,t+1))}function P(e,t){let n=e;for(let i of t.split("/").slice(1)){let o=decodeURIComponent(i).replaceAll("~1","/").replaceAll("~0","~");if(typeof n!=="object"||n===null||!Object.hasOwn(n,o))return;n=n[o]}return n}function k(e){let t=new Set,n=[],i=[],o=(r,a)=>{if(a>64||typeof r!=="object"||r===null)return;if(!Array.isArray(r)){let s=r;if(typeof s.$anchor==="string")t.add(s.$anchor);if(typeof s.$ref==="string")n.push(s.$ref);if(typeof s.pattern==="string")i.push(s.pattern);let d=s.patternProperties;if(typeof d==="object"&&d!==null)i.push(...Object.keys(d))}for(let s of Object.values(r))o(s,a+1)};o(e,0);for(let r of i)try{new RegExp(r,"u")}catch{return`pattern ${JSON.stringify(r)} is not a valid regular expression`}for(let r of n){if(!r.startsWith("#"))return`$ref ${JSON.stringify(r)} points outside the schema`;let a=r.slice(1);if(!(a===""||(a.startsWith("/")?P(e,a)!==void 0:t.has(a))))return`$ref ${JSON.stringify(r)} does not resolve`}return}function x(e){if(!v(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:i,inputSchema:o,execute:r,annotations:a}=e;if(typeof t!=="string"||!L.test(t))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(t)})`);if(typeof i!=="string"||i.trim()==="")throw TypeError(`registerTool: tool ${t} needs a description`);if(n!==void 0&&typeof n!=="string")throw TypeError(`registerTool: the title of ${t} must be a string`);if(typeof r!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let s=o??{type:"object"};if(!v(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${t} must be a JSON Schema object with "type": "object"`);if(E(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let d=k(s);if(d!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${d}`);let h;try{h=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${t} must be JSON`)}if(a!==void 0&&!v(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let u={};for(let[c,l]of Object.entries(a??{}))if(typeof l==="boolean")u[c]=l;return{name:t,title:n,description:i,inputSchema:h,annotations:u,execute:r}}class w{#e=new Map;#r=new Set;#a;register(e,t={}){let n=x(e),{signal:i}=t;if(i?.aborted)return;if(this.#e.has(n.name))throw new DOMException(`registerTool: a tool named ${n.name} is already registered`,"InvalidStateError");this.#a?.(n),this.#e.set(n.name,n),i?.addEventListener("abort",()=>this.remove(n),{once:!0}),this.#o()}setCompiler(e){this.#a??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),this.#o()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#r.add(e),()=>this.#r.delete(e)}#o(){for(let e of[...this.#r])e()}}var D=/^[A-Za-z0-9_-]{43}$/;function N(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function j(){return N(crypto.getRandomValues(new Uint8Array(32)))}function b(e){return typeof e==="string"&&D.test(e)}function _(){try{return globalThis.localStorage??null}catch{return null}}class g{#e;#r;#a;#o;#g;constructor(e,t,n){this.#e=e===void 0?_():e,this.#r=t,this.#a=n,this.#o=n===void 0?void 0:`${n}#moved`}get(){let e=null;try{if(e=this.#e?.getItem(this.#r)??null,!b(e)&&this.#a!==void 0&&this.#o!==void 0&&this.#e?.getItem(this.#o)==null){let t=this.#e?.getItem(this.#a)??null;if(b(t))e=t,this.#m(t)}}catch{}if(b(e))return this.#g=e,e;return this.#g??this.rotate()}rotate(){let e=j();return this.#g=e,this.#m(e),e}#m(e){try{if(this.#e?.setItem(this.#r,e),this.#o!==void 0)this.#e?.setItem(this.#o,this.#r)}catch{}}}var C="@ractive-ch/tab-mcp-client",T="0.6.0";var K=new Set(["localhost","127.0.0.1","[::1]"]),I=[5000,1e4,20000,40000,60000],R=new Set(["network","heartbeat","shutdown"]);function G(e){if(e===!1)return;if(e===void 0||e===!0)return I;let t=e.delaysMs??I;if(!Array.isArray(t)||t.length===0||!t.every((n)=>typeof n==="number"&&n>=0&&n<2147483648))throw TypeError("TabMcp: reconnect.delaysMs: a non-empty list of ms");return[...t]}function O(e,t){if(t===void 0)return;if(typeof t!=="number"||!Number.isFinite(t)||t<0||t>=2147483648)throw TypeError(`TabMcp: ${e} must be a number of milliseconds`);return t}function H(e){return Object.freeze({...e,client:Object.freeze({...e.client})})}function J(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((t)=>{let n=t.codePointAt(0)??0;return n<32||n>=127&&n<=159})}function U(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let n=t.protocol==="https:"||t.protocol==="wss:";if(!n&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!n&&!K.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let i=`${n?"https:":"http:"}//${t.host}`,o=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=o.endsWith("/tab")?o:`${o}/tab`,t.search="",t.hash="",{url:t.href,origin:i}}function z(e){try{return new URL(e).host}catch{return""}}function W(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,pairing:e.pairing==="oidc"?"oidc":"code",expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}class A extends EventTarget{#e=new w;#r;#a;#o;#g;#m;#I;#L;#w="none";#P;#l=0;#k;#n="disconnected";#h;#u=Object.freeze([]);#b=new y;#f=!1;#R;#i;#s;#y=0;#x;#d;#p;#T;#S=!1;#E;constructor(e){super();let{url:t,origin:n}=U(e.relay),{server:i,appName:o}=e;if(typeof i?.name!=="string"||typeof i.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(o!==void 0&&!J(o))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");this.#m=t,this.#r={...i},this.#a=o,this.#o=e.onConfirm,this.#g=O("confirmDelayMs",e.confirmDelayMs),this.#L=e.identityAssertion,this.#k=O("identityTimeoutMs",e.identityTimeoutMs)??15000,this.#x=G(e.reconnect),this.#I=e.storageKey===void 0?new g(e.storage,`tab-mcp:secret:${n}:${encodeURIComponent(i.name)}`,`tab-mcp:secret:${n}`):new g(e.storage,e.storageKey),this.#e.onChange(()=>{let r=this.tools;this.#b.keepTools(r),this.#t("toolschange",{tools:r})})}registerTool(e,t={}){try{this.#e.register(e,t)}catch(n){return Promise.reject(n)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#n}get session(){return this.#h}get address(){return this.#h?.address}get appName(){return this.#h?.appName??this.#a}get grants(){return this.#u}get reconnecting(){return this.#d}get identity(){return this.#w}get identityMessage(){return this.#P}refreshIdentity(){let e=this.#h,t=this.#L;if(this.#n!=="connected"||e===void 0||t===void 0)return Promise.resolve(!1);let n=++this.#l,i=this.#i;this.#c("pending");let o=setTimeout(()=>{if(n!==this.#l||this.#w!=="pending")return;this.#l++,this.#c("none")},this.#k);return new Promise((r)=>{let a=(s)=>{if(s.detail.state==="pending")return;this.removeEventListener("identitychange",a),clearTimeout(o),r(s.detail.state==="bound")};this.addEventListener("identitychange",a),Promise.resolve().then(()=>t({address:e.address,sessionId:e.sessionId})).then((s)=>{if(n!==this.#l||this.#i!==i)return;if(typeof s!=="string"||s===""){this.#c("none");return}if(i?.send({type:"identity",assertion:s,round:n})!==!0)this.#c("none")},(s)=>{if(n!==this.#l)return;this.#t("error",{error:s instanceof Error?s:Error(String(s))}),this.#c("none")})})}signOut(){if(this.#l++,this.#c("none"),this.#n!=="connected")return!1;return this.#i?.send({type:"identity.logout"})===!0}get pairing(){return this.#f}get pairingCode(){return this.#R}connect(e={}){if(this.#n==="connected"&&this.#h!==void 0)return Promise.resolve(this.#h);if(this.#s!==void 0){if(this.#d!==void 0)this.#S=!0;return this.#s}if(this.#d!==void 0)return this.#O(!0);let t=globalThis.navigator?.userActivation;if(e.resume!==!0&&t!==void 0&&!t.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));return this.#$()}#$(){this.#v("connecting");let e=this.#j(this.#y);return this.#s=e,e.then(()=>{if(this.#s===e)this.#s=void 0},()=>{if(this.#s!==e)return;this.#s=void 0,this.#i=void 0,this.#v("disconnected")}),e}async#j(e){let{openConnection:t,compileRegistry:n}=await (p("nygehv52"),import("./connection-nygehv52.min.js"));for(let r of n(this.#e))this.#t("error",{error:r});if(e!==this.#y)throw new DOMException("The connection was cancelled","AbortError");let i={},o=t(this.#H(i),this.#m,this.#I.get());return i.connection=o,this.#i=o,o.ready}disconnect(){this.#D("user")}newAddress(){let e=this.#n!=="disconnected"||this.#d!==void 0;if(this.#n==="connected")this.#i?.send({type:"grants.revokeAll"});return this.#D("new_address"),this.#I.rotate(),e?this.connect():Promise.resolve(void 0)}#D(e){this.#A(),this.#y++;let t=this.#i,n=this.#n==="connected";if(this.#i=void 0,this.#s=void 0,t?.close(e),this.#n==="disconnected")return;if(this.#h=void 0,this.#C(void 0),this.#l++,this.#c("none"),this.#v("disconnected"),n)this.#t("disconnected",{reason:e,code:1000})}#N(e,t){let n=this.#x;if(n===void 0)return;let i=n[Math.min(t,n.length)-1]??0;clearTimeout(this.#p),this.#p=setTimeout(()=>{this.#O().catch(()=>{})},i),this.#_(),this.#d={reason:e,attempt:t,at:Date.now()+i},this.#t("reconnecting",this.#d)}#O(e=!1){if(clearTimeout(this.#p),this.#p=void 0,this.#s!==void 0)return this.#s;let t=this.#d;this.#S=e;let n=this.#$();return n.catch((i)=>{let o=this.#S;if(this.#S=!1,t===void 0||this.#d!==t)return;let r=i?.reason;if(r===void 0||R.has(r)){this.#N(t.reason,t.attempt+1);return}this.#A(o?void 0:i instanceof Error?i:Error(String(i)))}),n}#_(){if(this.#T!==void 0)return;let e=globalThis,t=globalThis.document,n=()=>{if(this.#p!==void 0)this.#O().catch(()=>{})},i=()=>{if(t?.visibilityState!=="hidden")n()};t?.addEventListener("visibilitychange",i),e.addEventListener?.("online",n),this.#T=()=>{t?.removeEventListener("visibilitychange",i),e.removeEventListener?.("online",n)}}#A(e){if(clearTimeout(this.#p),this.#p=void 0,this.#T?.(),this.#T=void 0,this.#d===void 0)return;if(this.#d=void 0,e!==void 0)this.#t("error",{error:e});this.#t("reconnecting",null)}startPairing(){if(this.#f)return;if(this.#f=!0,this.#n==="connected")this.#i?.send({type:"pairing.start"})}stopPairing(){if(!this.#f)return;if(this.#f=!1,this.#n==="connected")this.#i?.send({type:"pairing.stop"});this.#C(void 0)}revoke(e){if(this.#n!=="connected")return!1;return this.#i?.send({type:"grant.revoke",grantId:e})===!0}showConnectDialog(e={}){let t=e.document??globalThis.document,n=this.#E;if(n!==void 0)return n.doc===t?n.shown:Promise.reject(new DOMException("showConnectDialog: the dialog is already open in another document","InvalidStateError"));let i=this.#K(t).finally(()=>{if(this.#E?.shown===i)this.#E=void 0});return this.#E={doc:t,shown:i},i}async#K(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("yknfss9n"),import("./ui-yknfss9n.min.js"));await n(this,t,e)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#t(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#v(e){if(this.#n===e)return;this.#n=e,this.#t("statechange",{state:e})}#c(e,t){if(this.#w===e&&t===void 0)return;this.#w=e,this.#P=e==="refused"?t:void 0,this.#t("identitychange",t===void 0?{state:e}:{state:e,message:t})}#C(e){if(this.#R===void 0&&e===void 0)return;this.#R=e,this.#t("pairingcode",e??null)}#M(e){this.#u=Object.freeze(e.map(H)),this.#b.keepGrants(e.map((t)=>t.grantId)),this.#t("grantschange",{grants:this.#u})}#G(e){if(this.#o!==void 0){let t=this.#o;return Promise.resolve().then(()=>t(e)).then((n)=>n===!0)}return this.confirmInPage(e)}confirmInPage(e){let{grantId:t}=e.client;if(this.#b.has(t,e.tool.name))return Promise.resolve(!0);let n=globalThis.document;if(n===void 0)return Promise.resolve(!1);let i=this.#g;return (p("yknfss9n"),import("./ui-yknfss9n.min.js")).then((o)=>o.confirmDialog(e,n,i===void 0?{}:{allowDelayMs:i})).then((o)=>{if(o==="always"&&this.#u.some((r)=>r.grantId===t))this.#b.add(t,e.tool.name);return o!=="deny"})}#H(e){let t=()=>e.connection!==void 0&&this.#i===e.connection;return{registry:this.#e,server:this.#r,appName:this.#a,library:{name:C,version:T},confirm:(n)=>this.#G(n),toolCallStarted:(n)=>this.#t("toolcall",n),toolCallEnded:(n)=>this.#t("toolcallend",n),clientFor:(n)=>{let i=this.#u.find((r)=>r.grantId===n.grantId),o={grantId:n.grantId,id:n.clientId,host:z(n.clientId)};if(i!==void 0)o.name=i.client.name;return o},sessionStarted:(n)=>{let i=W(n);if(!t())return i;if(this.#h=i,this.#A(),this.#v("connected"),this.#M([...n.grants]),this.#f)this.#i?.send({type:"pairing.start"});if(this.#t("connected",i),i.pairing==="oidc")this.refreshIdentity();return i},pairingCode:(n)=>{if(t()&&this.#f)this.#C(n)},grantAdded:(n)=>{if(!t())return;this.#M([...this.#u.filter((i)=>i.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#M(this.#u.filter((i)=>i.grantId!==n))},replaced:()=>{if(t())this.#t("replaced",null)},identityResult:(n,i,o)=>{if(!t())return;if(i!==this.#l)return;if(n)this.#c("bound");else this.#c("refused",o??"")},error:(n)=>{if(t())this.#t("error",{error:n})},closed:(n,i)=>{if(!t())return;let o=this.#y;if(this.#i=void 0,this.#h=void 0,this.#C(void 0),this.#l++,this.#c("none"),this.#v("disconnected"),this.#t("disconnected",{reason:n,code:i}),R.has(n)&&this.#y===o&&this.#n==="disconnected"&&this.#s===void 0)this.#N(n,1)}}}}export{A as TabMcp,T as VERSION};
3
3
 
4
- //# debugId=AA69A74C9A4F372A64756E2164756E21
4
+ //# debugId=D99911AB9F09570E64756E2164756E21
5
5
  //# sourceMappingURL=tab-mcp-client.min.js.map
@@ -3,12 +3,12 @@
3
3
  "sources": ["../../src/always-allowed.ts", "../../src/registry.ts", "../../src/secret.ts", "../../src/version.ts", "../../src/tab-mcp.ts"],
4
4
  "sourcesContent": [
5
5
  "/**\n * The tools a user chose \"Always allow\" for, per grant (AI app). Kept in\n * memory for the page's lifetime; an entry goes when its grant goes or its\n * tool is unregistered, so a re-paired app or a new tool under the same name\n * is asked again.\n */\nexport class AlwaysAllowed {\n\treadonly #tools = new Map<string, Set<string>>();\n\n\thas(grantId: string, tool: string): boolean {\n\t\treturn this.#tools.get(grantId)?.has(tool) === true;\n\t}\n\n\tadd(grantId: string, tool: string): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Set();\n\t\ttools.add(tool);\n\t\tthis.#tools.set(grantId, tools);\n\t}\n\n\t/** Forget every grant not in `grantIds`. */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tfor (const grantId of this.#tools.keys()) {\n\t\t\tif (!keep.has(grantId)) this.#tools.delete(grantId);\n\t\t}\n\t}\n\n\t/** Forget every tool not in `names`. */\n\tkeepTools(names: Iterable<string>): void {\n\t\tconst keep = new Set(names);\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools) if (!keep.has(tool)) tools.delete(tool);\n\t\t}\n\t}\n}\n",
6
- "/**\n * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`\n * (DEC-010). Part of the eagerly loaded core.\n */\n\nimport type {\n\tJsonSchema,\n\tRegisterToolOptions,\n\tTool,\n\tToolAnnotations,\n} from \"./types.ts\";\n\nconst NAME = /^[A-Za-z0-9_.-]{1,128}$/;\n\n/** A validated tool as the registry keeps it. */\nexport interface RegisteredTool {\n\treadonly name: string;\n\treadonly title: string | undefined;\n\treadonly description: string;\n\treadonly inputSchema: JsonSchema;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** `x-mcp-header` makes the relay validate headers it does not know; not supported in v1. */\nfunction usesMcpHeader(schema: unknown, depth = 0): boolean {\n\tif (depth > 64 || typeof schema !== \"object\" || schema === null) return false;\n\tif (!Array.isArray(schema) && \"x-mcp-header\" in schema) return true;\n\treturn Object.values(schema).some((v) => usesMcpHeader(v, depth + 1));\n}\n\n/** A JSON pointer (`/a/b~1c`) inside `root`, or `undefined`. */\nfunction resolvePointer(root: unknown, pointer: string): unknown {\n\tlet node: unknown = root;\n\tfor (const raw of pointer.split(\"/\").slice(1)) {\n\t\tconst key = decodeURIComponent(raw)\n\t\t\t.replaceAll(\"~1\", \"/\")\n\t\t\t.replaceAll(\"~0\", \"~\");\n\t\tif (typeof node !== \"object\" || node === null || !Object.hasOwn(node, key))\n\t\t\treturn undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node;\n}\n\n/**\n * What the validator (loaded only on `connect()`) would throw on later, found\n * now so that a bad schema fails registration: patterns that are not\n * regular expressions, and `$ref`s that do not resolve inside the schema.\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tif (this.#tools.get(registered.name) === registered) {\n\t\t\t\t\tthis.#tools.delete(registered.name);\n\t\t\t\t\tthis.#changed();\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
6
+ "/**\n * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`\n * (DEC-010). Part of the eagerly loaded core.\n */\n\nimport type {\n\tJsonSchema,\n\tRegisterToolOptions,\n\tTool,\n\tToolAnnotations,\n} from \"./types.ts\";\n\nconst NAME = /^[A-Za-z0-9_.-]{1,128}$/;\n\n/** A validated tool as the registry keeps it. */\nexport interface RegisteredTool {\n\treadonly name: string;\n\treadonly title: string | undefined;\n\treadonly description: string;\n\treadonly inputSchema: JsonSchema;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** `x-mcp-header` makes the relay validate headers it does not know; not supported in v1. */\nfunction usesMcpHeader(schema: unknown, depth = 0): boolean {\n\tif (depth > 64 || typeof schema !== \"object\" || schema === null) return false;\n\tif (!Array.isArray(schema) && \"x-mcp-header\" in schema) return true;\n\treturn Object.values(schema).some((v) => usesMcpHeader(v, depth + 1));\n}\n\n/** A JSON pointer (`/a/b~1c`) inside `root`, or `undefined`. */\nfunction resolvePointer(root: unknown, pointer: string): unknown {\n\tlet node: unknown = root;\n\tfor (const raw of pointer.split(\"/\").slice(1)) {\n\t\tconst key = decodeURIComponent(raw)\n\t\t\t.replaceAll(\"~1\", \"/\")\n\t\t\t.replaceAll(\"~0\", \"~\");\n\t\tif (typeof node !== \"object\" || node === null || !Object.hasOwn(node, key))\n\t\t\treturn undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node;\n}\n\n/**\n * What the validator (loaded only on `connect()`) would throw on later, found\n * now so that a bad schema fails registration: patterns that are not\n * regular expressions, and `$ref`s that do not resolve inside the schema.\n * Without `$id`s; once the validator is loaded, it checks too (`setCompiler`).\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\n/** The validator's check of a schema: throws a `TypeError` naming the problem. */\nexport type SchemaCompiler = (tool: RegisteredTool) => void;\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\t#compile: SchemaCompiler | undefined;\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#compile?.(registered);\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\"abort\", () => this.remove(registered), {\n\t\t\tonce: true,\n\t\t});\n\t\tthis.#changed();\n\t}\n\n\t/**\n\t * The validator is loaded: from now on each schema is compiled when it is\n\t * registered, and a tool it refuses is refused (DEC-086).\n\t */\n\tsetCompiler(compile: SchemaCompiler): void {\n\t\tthis.#compile ??= compile;\n\t}\n\n\t/** Unregister this tool, if it still is. */\n\tremove(tool: RegisteredTool): void {\n\t\tif (this.#tools.get(tool.name) !== tool) return;\n\t\tthis.#tools.delete(tool.name);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
7
7
  "/**\n * The address secret (DEC-027): 32 random bytes as base64url without padding,\n * kept in `localStorage`. The relay derives the stable address from it.\n */\n\nimport type { SecretStorage } from \"./types.ts\";\n\nconst SECRET = /^[A-Za-z0-9_-]{43}$/;\n/** base64url without padding. */\nexport function base64url(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nexport function newSecret(): string {\n\treturn base64url(crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport function isSecret(value: unknown): value is string {\n\treturn typeof value === \"string\" && SECRET.test(value);\n}\n\n/** `localStorage`, or `null` where it is missing or blocked. */\nfunction defaultStorage(): SecretStorage | null {\n\ttry {\n\t\tconst storage = (globalThis as { localStorage?: SecretStorage })\n\t\t\t.localStorage;\n\t\treturn storage ?? null;\n\t} catch {\n\t\treturn null; // SecurityError: storage blocked for this page\n\t}\n}\n\n/** Reads, creates and rotates the secret; falls back to memory without storage. */\nexport class SecretStore {\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t/** A key the secret may still be under (the default of 0.4 and older). */\n\treadonly #oldKey: string | undefined;\n\t/** Set once a page of this origin took over the old key's secret. */\n\treadonly #claimKey: string | undefined;\n\t#memory: string | undefined;\n\n\tconstructor(\n\t\tstorage: SecretStorage | null | undefined,\n\t\tkey: string,\n\t\toldKey?: string,\n\t) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t\tthis.#oldKey = oldKey;\n\t\tthis.#claimKey = oldKey === undefined ? undefined : `${oldKey}#moved`;\n\t}\n\n\t/** The current secret; storage first, so a rotation in another tab is seen. */\n\tget(): string {\n\t\tlet stored: string | null = null;\n\t\ttry {\n\t\t\tstored = this.#storage?.getItem(this.#key) ?? null;\n\t\t\t// The old shared key's secret is copied once (DEC-083): the first page\n\t\t\t// keeps the address and marks it taken, so the next page gets its own.\n\t\t\t// The old key stays, for pages still on 0.4 and for a rollback.\n\t\t\tif (\n\t\t\t\t!isSecret(stored) &&\n\t\t\t\tthis.#oldKey !== undefined &&\n\t\t\t\tthis.#claimKey !== undefined &&\n\t\t\t\tthis.#storage?.getItem(this.#claimKey) == null\n\t\t\t) {\n\t\t\t\tconst old = this.#storage?.getItem(this.#oldKey) ?? null;\n\t\t\t\tif (isSecret(old)) {\n\t\t\t\t\tstored = old; // kept for this page even if the writes below fail\n\t\t\t\t\tthis.#claim(old);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// unreadable: use a page-lifetime secret\n\t\t}\n\t\tif (isSecret(stored)) {\n\t\t\tthis.#memory = stored;\n\t\t\treturn stored;\n\t\t}\n\t\treturn this.#memory ?? this.rotate();\n\t}\n\n\t/** Make and keep a new secret (a new address). */\n\trotate(): string {\n\t\tconst secret = newSecret();\n\t\tthis.#memory = secret;\n\t\t// Also marks the old shared secret taken: an address abandoned with \"New\n\t\t// address\" is not picked up again by another page of the site.\n\t\tthis.#claim(secret);\n\t\treturn secret;\n\t}\n\n\t#claim(secret: string): void {\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t\tif (this.#claimKey !== undefined)\n\t\t\t\tthis.#storage?.setItem(this.#claimKey, this.#key);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t}\n}\n",
8
- "/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.5.1\";\n",
9
- "/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tIdentityAssertionHandler,\n\tIdentityState,\n\tPairingCode,\n\tReconnectingInfo,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** The default waits before each reconnect attempt; the last one repeats. */\nconst RECONNECT_DELAYS_MS = [5_000, 10_000, 20_000, 40_000, 60_000];\n/** Reasons after which the library connects again by itself. */\nconst RECONNECT_REASONS = new Set<DisconnectReason>([\n\t\"network\",\n\t\"heartbeat\",\n\t\"shutdown\",\n]);\n\nfunction reconnectDelays(\n\toption: TabMcpOptions[\"reconnect\"],\n): readonly number[] | undefined {\n\tif (option === false) return undefined;\n\tif (option === undefined || option === true) return RECONNECT_DELAYS_MS;\n\tconst delays = option.delaysMs ?? RECONNECT_DELAYS_MS;\n\tif (\n\t\t!Array.isArray(delays) ||\n\t\tdelays.length === 0 ||\n\t\t!delays.every((d) => typeof d === \"number\" && d >= 0 && d < 2 ** 31)\n\t) {\n\t\tthrow new TypeError(\"TabMcp: reconnect.delaysMs: a non-empty list of ms\");\n\t}\n\treturn [...delays];\n}\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\tpairing: m.pairing === \"oidc\" ? \"oidc\" : \"code\",\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\treadonly #identityAssertion: IdentityAssertionHandler | undefined;\n\t#identity: IdentityState = \"none\";\n\t#identityMessage: string | undefined;\n\t/** Incremented per identity request, so a late answer of an older one is dropped. */\n\t#identityRound = 0;\n\treadonly #identityTimeoutMs: number;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\t/** Waits between reconnect attempts; `undefined`: reconnecting is off. */\n\treadonly #reconnectDelays: readonly number[] | undefined;\n\t#reconnecting: ReconnectingInfo | undefined;\n\t#reconnectTimer: ReturnType<typeof setTimeout> | undefined;\n\t#unwatch: (() => void) | undefined;\n\t/** The page's `connect()` waits on the running reconnect attempt: its promise tells it. */\n\t#pageWaits = false;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#identityAssertion = options.identityAssertion;\n\t\tthis.#identityTimeoutMs = options.identityTimeoutMs ?? 15_000;\n\t\tthis.#reconnectDelays = reconnectDelays(options.reconnect);\n\t\t// One address per relay and page (server name); the default of 0.4 and\n\t\t// older, per relay only, is moved over once (DEC-083).\n\t\tthis.#secrets =\n\t\t\toptions.storageKey === undefined\n\t\t\t\t? new SecretStore(\n\t\t\t\t\t\toptions.storage,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}:${encodeURIComponent(server.name)}`,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}`,\n\t\t\t\t\t)\n\t\t\t\t: new SecretStore(options.storage, options.storageKey);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/**\n\t * While the library connects again by itself after the connection broke:\n\t * the next attempt and when it starts. `undefined` otherwise.\n\t */\n\tget reconnecting(): ReconnectingInfo | undefined {\n\t\treturn this.#reconnecting;\n\t}\n\n\t/** Who the relay knows as the page's user (identity binding). */\n\tget identity(): IdentityState {\n\t\treturn this.#identity;\n\t}\n\n\t/** Why the relay refused the identity, while `identity` is `refused`. */\n\tget identityMessage(): string | undefined {\n\t\treturn this.#identityMessage;\n\t}\n\n\t/**\n\t * Ask the `identityAssertion` hook again and send the result, e.g. after\n\t * the user signed in without a page load. Resolves `true` once the relay\n\t * accepted it; `false` when nobody is signed in, it was refused, or the\n\t * page is not connected.\n\t */\n\trefreshIdentity(): Promise<boolean> {\n\t\tconst session = this.#session;\n\t\tconst ask = this.#identityAssertion;\n\t\tif (\n\t\t\tthis.#state !== \"connected\" ||\n\t\t\tsession === undefined ||\n\t\t\task === undefined\n\t\t) {\n\t\t\treturn Promise.resolve(false);\n\t\t}\n\t\tconst round = ++this.#identityRound;\n\t\tconst connection = this.#connection;\n\t\tthis.#setIdentity(\"pending\");\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst settle = (event: TabMcpEventMap[\"identitychange\"]) => {\n\t\t\t\tif (event.detail.state === \"pending\") return;\n\t\t\t\tthis.removeEventListener(\"identitychange\", settle);\n\t\t\t\tresolve(event.detail.state === \"bound\");\n\t\t\t};\n\t\t\tthis.addEventListener(\"identitychange\", settle);\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() =>\n\t\t\t\t\task({ address: session.address, sessionId: session.sessionId }),\n\t\t\t\t)\n\t\t\t\t.then(\n\t\t\t\t\t(assertion) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tround !== this.#identityRound ||\n\t\t\t\t\t\t\tthis.#connection !== connection\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Superseded (a newer request, a sign-out, a new connection): that one settles the state.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (typeof assertion !== \"string\" || assertion === \"\") {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tconnection?.send({ type: \"identity\", assertion, round }) !== true\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// No answer in time (an old relay, a lost message): give up.\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tif (round !== this.#identityRound || this.#identity !== \"pending\")\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tthis.#identityRound++; // a late answer is dropped\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t}, this.#identityTimeoutMs);\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\t\t\tthis.#emit(\"error\", {\n\t\t\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * The page's user signed out: the relay ends every AI connection of this\n\t * address at once (identity binding). Call it from the web app's logout.\n\t * Returns `false` when it could not be sent (not connected); the grants\n\t * then stay, but work only while a page signed in as the same person is\n\t * open.\n\t */\n\tsignOut(): boolean {\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"identity.logout\" }) === true;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * While reconnecting (`reconnecting`), it makes the next attempt at once.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) {\n\t\t\tif (this.#reconnecting !== undefined) this.#pageWaits = true;\n\t\t\treturn this.#connecting;\n\t\t}\n\t\tif (this.#reconnecting !== undefined) return this.#attemptReconnect(true);\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn this.#start();\n\t}\n\n\t#start(): Promise<SessionInfo> {\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn =\n\t\t\tthis.#state !== \"disconnected\" || this.#reconnecting !== undefined;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#stopReconnecting();\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** Wait, then connect again (attempt `attempt`, from 1). */\n\t#scheduleReconnect(reason: DisconnectReason, attempt: number): void {\n\t\tconst delays = this.#reconnectDelays;\n\t\tif (delays === undefined) return;\n\t\tconst delay = delays[Math.min(attempt, delays.length) - 1] ?? 0;\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = setTimeout(() => {\n\t\t\tthis.#attemptReconnect().catch(() => {}); // the next one is scheduled\n\t\t}, delay);\n\t\tthis.#watch();\n\t\tthis.#reconnecting = { reason, attempt, at: Date.now() + delay };\n\t\tthis.#emit(\"reconnecting\", this.#reconnecting);\n\t}\n\n\t/**\n\t * Make the next reconnect attempt now; on failure, schedule the one after.\n\t * `byPage`: from `connect()`, whose promise tells the page why it failed.\n\t */\n\t#attemptReconnect(byPage = false): Promise<SessionInfo> {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst info = this.#reconnecting;\n\t\tthis.#pageWaits = byPage;\n\t\tconst attempt = this.#start();\n\t\tattempt.catch((error: unknown) => {\n\t\t\tconst pageWaits = this.#pageWaits;\n\t\t\tthis.#pageWaits = false;\n\t\t\tif (info === undefined || this.#reconnecting !== info) return;\n\t\t\t// Only what may get better: an unreachable relay (network), a\n\t\t\t// heartbeat or a shutdown; a refusal stops it (DEC-082).\n\t\t\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\t\t\tif (reason === undefined || RECONNECT_REASONS.has(reason)) {\n\t\t\t\tthis.#scheduleReconnect(info.reason, info.attempt + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A refusal stops it. Without a connect() of the page's waiting on this\n\t\t\t// attempt, nothing else tells the page why: `error` does, before `null`.\n\t\t\tthis.#stopReconnecting(\n\t\t\t\tpageWaits\n\t\t\t\t\t? undefined\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: new Error(String(error)),\n\t\t\t);\n\t\t});\n\t\treturn attempt;\n\t}\n\n\t/** Back to the front, or online again: try at once instead of waiting. */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst doc = (globalThis as { document?: Document }).document;\n\t\tconst now = () => {\n\t\t\t// Only while waiting: an attempt that is running is not doubled.\n\t\t\tif (this.#reconnectTimer !== undefined)\n\t\t\t\tthis.#attemptReconnect().catch(() => {});\n\t\t};\n\t\tconst visible = () => {\n\t\t\tif (doc?.visibilityState !== \"hidden\") now();\n\t\t};\n\t\tdoc?.addEventListener(\"visibilitychange\", visible);\n\t\tg.addEventListener?.(\"online\", now);\n\t\tthis.#unwatch = () => {\n\t\t\tdoc?.removeEventListener(\"visibilitychange\", visible);\n\t\t\tg.removeEventListener?.(\"online\", now);\n\t\t};\n\t}\n\n\t/**\n\t * Stop reconnecting. `why` (a refusal) goes out as `error` before the\n\t * `null`, once the state is clear: a listener that calls `connect()` then\n\t * starts afresh, with the user-activation check.\n\t */\n\t#stopReconnecting(why?: Error): void {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tthis.#unwatch?.();\n\t\tthis.#unwatch = undefined;\n\t\tif (this.#reconnecting === undefined) return;\n\t\tthis.#reconnecting = undefined;\n\t\tif (why !== undefined) this.#emit(\"error\", { error: why });\n\t\tthis.#emit(\"reconnecting\", null);\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setIdentity(state: IdentityState, message?: string): void {\n\t\tif (this.#identity === state && message === undefined) return;\n\t\tthis.#identity = state;\n\t\tthis.#identityMessage = state === \"refused\" ? message : undefined;\n\t\tthis.#emit(\n\t\t\t\"identitychange\",\n\t\t\tmessage === undefined ? { state } : { state, message },\n\t\t);\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\treturn this.confirmInPage(request);\n\t}\n\n\t/**\n\t * The library's own confirmation: the dialog in the page with Allow,\n\t * Always allow and Deny (what runs without `onConfirm`). An `onConfirm`\n\t * may hand some calls to it. Resolves `false` where there is no document.\n\t */\n\tconfirmInPage(request: ConfirmRequest): Promise<boolean> {\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#stopReconnecting();\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\tif (session.pairing === \"oidc\") void this.refreshIdentity();\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\tidentityResult: (bound, round, message) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Only the answer to the newest assertion counts: the relay echoes\n\t\t\t\t// its round, so a lost or late answer cannot pass for a newer one.\n\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\tif (bound) this.#setIdentity(\"bound\");\n\t\t\t\telse this.#setIdentity(\"refused\", message ?? \"\");\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Any listener below may end it all (`disconnect()`, `newAddress()`):\n\t\t\t\t// that bumps the generation, and then nothing is scheduled.\n\t\t\t\tconst generation = this.#generation;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#identityRound++;\n\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t\t// After the page heard of it: its listener may have connected or ended it.\n\t\t\t\tif (\n\t\t\t\t\tRECONNECT_REASONS.has(reason) &&\n\t\t\t\t\tthis.#generation === generation &&\n\t\t\t\t\tthis.#state === \"disconnected\" &&\n\t\t\t\t\tthis.#connecting === undefined\n\t\t\t\t)\n\t\t\t\t\tthis.#scheduleReconnect(reason, 1);\n\t\t\t},\n\t\t};\n\t}\n}\n"
8
+ "/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.6.0\";\n",
9
+ "/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tIdentityAssertionHandler,\n\tIdentityState,\n\tPairingCode,\n\tReconnectingInfo,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** The default waits before each reconnect attempt; the last one repeats. */\nconst RECONNECT_DELAYS_MS = [5_000, 10_000, 20_000, 40_000, 60_000];\n/** Reasons after which the library connects again by itself. */\nconst RECONNECT_REASONS = new Set<DisconnectReason>([\n\t\"network\",\n\t\"heartbeat\",\n\t\"shutdown\",\n]);\n\nfunction reconnectDelays(\n\toption: TabMcpOptions[\"reconnect\"],\n): readonly number[] | undefined {\n\tif (option === false) return undefined;\n\tif (option === undefined || option === true) return RECONNECT_DELAYS_MS;\n\tconst delays = option.delaysMs ?? RECONNECT_DELAYS_MS;\n\tif (\n\t\t!Array.isArray(delays) ||\n\t\tdelays.length === 0 ||\n\t\t!delays.every((d) => typeof d === \"number\" && d >= 0 && d < 2 ** 31)\n\t) {\n\t\tthrow new TypeError(\"TabMcp: reconnect.delaysMs: a non-empty list of ms\");\n\t}\n\treturn [...delays];\n}\n\n/** A delay option: `undefined`, or a whole wait `setTimeout` can keep (below 2^31 ms). */\nfunction delayOption(name: string, value: unknown): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (\n\t\ttypeof value !== \"number\" ||\n\t\t!Number.isFinite(value) ||\n\t\tvalue < 0 ||\n\t\tvalue >= 2 ** 31\n\t) {\n\t\tthrow new TypeError(`TabMcp: ${name} must be a number of milliseconds`);\n\t}\n\treturn value;\n}\n\n/** A grant as the page sees it: frozen, so a page cannot change what decides Always allow. */\nfunction frozenGrant(grant: Grant): Grant {\n\treturn Object.freeze({\n\t\t...grant,\n\t\tclient: Object.freeze({ ...grant.client }),\n\t});\n}\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\tpairing: m.pairing === \"oidc\" ? \"oidc\" : \"code\",\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\treadonly #identityAssertion: IdentityAssertionHandler | undefined;\n\t#identity: IdentityState = \"none\";\n\t#identityMessage: string | undefined;\n\t/** Incremented per identity request, so a late answer of an older one is dropped. */\n\t#identityRound = 0;\n\treadonly #identityTimeoutMs: number;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: readonly Grant[] = Object.freeze([]);\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\t/** Waits between reconnect attempts; `undefined`: reconnecting is off. */\n\treadonly #reconnectDelays: readonly number[] | undefined;\n\t#reconnecting: ReconnectingInfo | undefined;\n\t#reconnectTimer: ReturnType<typeof setTimeout> | undefined;\n\t#unwatch: (() => void) | undefined;\n\t/** The page's `connect()` waits on the running reconnect attempt: its promise tells it. */\n\t#pageWaits = false;\n\t/** The open \"Connect your AI app\" dialog: one at a time. */\n\t#connectDialog: { doc: Document; shown: Promise<void> } | undefined;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = delayOption(\n\t\t\t\"confirmDelayMs\",\n\t\t\toptions.confirmDelayMs,\n\t\t);\n\t\tthis.#identityAssertion = options.identityAssertion;\n\t\tthis.#identityTimeoutMs =\n\t\t\tdelayOption(\"identityTimeoutMs\", options.identityTimeoutMs) ?? 15_000;\n\t\tthis.#reconnectDelays = reconnectDelays(options.reconnect);\n\t\t// One address per relay and page (server name); the default of 0.4 and\n\t\t// older, per relay only, is moved over once (DEC-083).\n\t\tthis.#secrets =\n\t\t\toptions.storageKey === undefined\n\t\t\t\t? new SecretStore(\n\t\t\t\t\t\toptions.storage,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}:${encodeURIComponent(server.name)}`,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}`,\n\t\t\t\t\t)\n\t\t\t\t: new SecretStore(options.storage, options.storageKey);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address (frozen; a new array when they change). */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/**\n\t * While the library connects again by itself after the connection broke:\n\t * the next attempt and when it starts. `undefined` otherwise.\n\t */\n\tget reconnecting(): ReconnectingInfo | undefined {\n\t\treturn this.#reconnecting;\n\t}\n\n\t/** Who the relay knows as the page's user (identity binding). */\n\tget identity(): IdentityState {\n\t\treturn this.#identity;\n\t}\n\n\t/** Why the relay refused the identity, while `identity` is `refused`. */\n\tget identityMessage(): string | undefined {\n\t\treturn this.#identityMessage;\n\t}\n\n\t/**\n\t * Ask the `identityAssertion` hook again and send the result, e.g. after\n\t * the user signed in without a page load. Resolves `true` once the relay\n\t * accepted it; `false` when nobody is signed in, it was refused, or the\n\t * page is not connected.\n\t */\n\trefreshIdentity(): Promise<boolean> {\n\t\tconst session = this.#session;\n\t\tconst ask = this.#identityAssertion;\n\t\tif (\n\t\t\tthis.#state !== \"connected\" ||\n\t\t\tsession === undefined ||\n\t\t\task === undefined\n\t\t) {\n\t\t\treturn Promise.resolve(false);\n\t\t}\n\t\tconst round = ++this.#identityRound;\n\t\tconst connection = this.#connection;\n\t\tthis.#setIdentity(\"pending\");\n\t\t// No answer in time, from the hook or the relay (an old relay, a lost\n\t\t// message, a hook that never settles): give up.\n\t\tconst timer = setTimeout(() => {\n\t\t\tif (round !== this.#identityRound || this.#identity !== \"pending\") return;\n\t\t\tthis.#identityRound++; // a late answer is dropped\n\t\t\tthis.#setIdentity(\"none\");\n\t\t}, this.#identityTimeoutMs);\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst settle = (event: TabMcpEventMap[\"identitychange\"]) => {\n\t\t\t\tif (event.detail.state === \"pending\") return;\n\t\t\t\tthis.removeEventListener(\"identitychange\", settle);\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(event.detail.state === \"bound\");\n\t\t\t};\n\t\t\tthis.addEventListener(\"identitychange\", settle);\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() =>\n\t\t\t\t\task({ address: session.address, sessionId: session.sessionId }),\n\t\t\t\t)\n\t\t\t\t.then(\n\t\t\t\t\t(assertion) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tround !== this.#identityRound ||\n\t\t\t\t\t\t\tthis.#connection !== connection\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Superseded (a newer request, a sign-out, a new connection): that one settles the state.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (typeof assertion !== \"string\" || assertion === \"\") {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tconnection?.send({ type: \"identity\", assertion, round }) !== true\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\t\t\tthis.#emit(\"error\", {\n\t\t\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * The page's user signed out: the relay ends every AI connection of this\n\t * address at once (identity binding). Call it from the web app's logout.\n\t * Returns `false` when it could not be sent (not connected); the grants\n\t * then stay, but work only while a page signed in as the same person is\n\t * open.\n\t */\n\tsignOut(): boolean {\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"identity.logout\" }) === true;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * While reconnecting (`reconnecting`), it makes the next attempt at once.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) {\n\t\t\tif (this.#reconnecting !== undefined) this.#pageWaits = true;\n\t\t\treturn this.#connecting;\n\t\t}\n\t\tif (this.#reconnecting !== undefined) return this.#attemptReconnect(true);\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn this.#start();\n\t}\n\n\t#start(): Promise<SessionInfo> {\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection, compileRegistry } = await import(\"./connection.ts\");\n\t\t// The validator is loaded: it checks the schemas from now on (DEC-086).\n\t\tfor (const error of compileRegistry(this.#registry))\n\t\t\tthis.#emit(\"error\", { error });\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn =\n\t\t\tthis.#state !== \"disconnected\" || this.#reconnecting !== undefined;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#stopReconnecting();\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** Wait, then connect again (attempt `attempt`, from 1). */\n\t#scheduleReconnect(reason: DisconnectReason, attempt: number): void {\n\t\tconst delays = this.#reconnectDelays;\n\t\tif (delays === undefined) return;\n\t\tconst delay = delays[Math.min(attempt, delays.length) - 1] ?? 0;\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = setTimeout(() => {\n\t\t\tthis.#attemptReconnect().catch(() => {}); // the next one is scheduled\n\t\t}, delay);\n\t\tthis.#watch();\n\t\tthis.#reconnecting = { reason, attempt, at: Date.now() + delay };\n\t\tthis.#emit(\"reconnecting\", this.#reconnecting);\n\t}\n\n\t/**\n\t * Make the next reconnect attempt now; on failure, schedule the one after.\n\t * `byPage`: from `connect()`, whose promise tells the page why it failed.\n\t */\n\t#attemptReconnect(byPage = false): Promise<SessionInfo> {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst info = this.#reconnecting;\n\t\tthis.#pageWaits = byPage;\n\t\tconst attempt = this.#start();\n\t\tattempt.catch((error: unknown) => {\n\t\t\tconst pageWaits = this.#pageWaits;\n\t\t\tthis.#pageWaits = false;\n\t\t\tif (info === undefined || this.#reconnecting !== info) return;\n\t\t\t// Only what may get better: an unreachable relay (network), a\n\t\t\t// heartbeat or a shutdown; a refusal stops it (DEC-082).\n\t\t\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\t\t\tif (reason === undefined || RECONNECT_REASONS.has(reason)) {\n\t\t\t\tthis.#scheduleReconnect(info.reason, info.attempt + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A refusal stops it. Without a connect() of the page's waiting on this\n\t\t\t// attempt, nothing else tells the page why: `error` does, before `null`.\n\t\t\tthis.#stopReconnecting(\n\t\t\t\tpageWaits\n\t\t\t\t\t? undefined\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: new Error(String(error)),\n\t\t\t);\n\t\t});\n\t\treturn attempt;\n\t}\n\n\t/** Back to the front, or online again: try at once instead of waiting. */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst doc = (globalThis as { document?: Document }).document;\n\t\tconst now = () => {\n\t\t\t// Only while waiting: an attempt that is running is not doubled.\n\t\t\tif (this.#reconnectTimer !== undefined)\n\t\t\t\tthis.#attemptReconnect().catch(() => {});\n\t\t};\n\t\tconst visible = () => {\n\t\t\tif (doc?.visibilityState !== \"hidden\") now();\n\t\t};\n\t\tdoc?.addEventListener(\"visibilitychange\", visible);\n\t\tg.addEventListener?.(\"online\", now);\n\t\tthis.#unwatch = () => {\n\t\t\tdoc?.removeEventListener(\"visibilitychange\", visible);\n\t\t\tg.removeEventListener?.(\"online\", now);\n\t\t};\n\t}\n\n\t/**\n\t * Stop reconnecting. `why` (a refusal) goes out as `error` before the\n\t * `null`, once the state is clear: a listener that calls `connect()` then\n\t * starts afresh, with the user-activation check.\n\t */\n\t#stopReconnecting(why?: Error): void {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tthis.#unwatch?.();\n\t\tthis.#unwatch = undefined;\n\t\tif (this.#reconnecting === undefined) return;\n\t\tthis.#reconnecting = undefined;\n\t\tif (why !== undefined) this.#emit(\"error\", { error: why });\n\t\tthis.#emit(\"reconnecting\", null);\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. One dialog at\n\t * a time (they would share one pairing): while it is open, a call for the\n\t * same document opens no second one and resolves with it, and a call for\n\t * another document rejects with an `InvalidStateError`. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tshowConnectDialog(options: { document?: Document } = {}): Promise<void> {\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tconst open = this.#connectDialog;\n\t\tif (open !== undefined) {\n\t\t\treturn open.doc === doc\n\t\t\t\t? open.shown\n\t\t\t\t: Promise.reject(\n\t\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\t\"showConnectDialog: the dialog is already open in another document\",\n\t\t\t\t\t\t\t\"InvalidStateError\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t}\n\t\tconst shown = this.#showConnectDialog(doc).finally(() => {\n\t\t\tif (this.#connectDialog?.shown === shown) this.#connectDialog = undefined;\n\t\t});\n\t\tthis.#connectDialog = { doc, shown };\n\t\treturn shown;\n\t}\n\n\tasync #showConnectDialog(doc: Document): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(this, connecting, doc);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setIdentity(state: IdentityState, message?: string): void {\n\t\tif (this.#identity === state && message === undefined) return;\n\t\tthis.#identity = state;\n\t\tthis.#identityMessage = state === \"refused\" ? message : undefined;\n\t\tthis.#emit(\n\t\t\t\"identitychange\",\n\t\t\tmessage === undefined ? { state } : { state, message },\n\t\t);\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: readonly Grant[]): void {\n\t\tthis.#grants = Object.freeze(grants.map(frozenGrant));\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants: this.#grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\treturn this.confirmInPage(request);\n\t}\n\n\t/**\n\t * The library's own confirmation: the dialog in the page with Allow,\n\t * Always allow and Deny (what runs without `onConfirm`). An `onConfirm`\n\t * may hand some calls to it. Resolves `false` where there is no document.\n\t */\n\tconfirmInPage(request: ConfirmRequest): Promise<boolean> {\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#stopReconnecting();\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\tif (session.pairing === \"oidc\") void this.refreshIdentity();\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\tidentityResult: (bound, round, message) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Only the answer to the newest assertion counts: the relay echoes\n\t\t\t\t// its round, so a lost or late answer cannot pass for a newer one.\n\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\tif (bound) this.#setIdentity(\"bound\");\n\t\t\t\telse this.#setIdentity(\"refused\", message ?? \"\");\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Any listener below may end it all (`disconnect()`, `newAddress()`):\n\t\t\t\t// that bumps the generation, and then nothing is scheduled.\n\t\t\t\tconst generation = this.#generation;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#identityRound++;\n\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t\t// After the page heard of it: its listener may have connected or ended it.\n\t\t\t\tif (\n\t\t\t\t\tRECONNECT_REASONS.has(reason) &&\n\t\t\t\t\tthis.#generation === generation &&\n\t\t\t\t\tthis.#state === \"disconnected\" &&\n\t\t\t\t\tthis.#connecting === undefined\n\t\t\t\t)\n\t\t\t\t\tthis.#scheduleReconnect(reason, 1);\n\t\t\t},\n\t\t};\n\t}\n}\n"
10
10
  ],
11
- "mappings": ";AAMO,MAAM,CAAc,CACjB,GAAS,IAAI,IAEtB,GAAG,CAAC,EAAiB,EAAuB,CAC3C,OAAO,KAAK,GAAO,IAAI,CAAO,GAAG,IAAI,CAAI,IAAM,GAGhD,GAAG,CAAC,EAAiB,EAAoB,CACxC,IAAM,EAAQ,KAAK,GAAO,IAAI,CAAO,GAAK,IAAI,IAC9C,EAAM,IAAI,CAAI,EACd,KAAK,GAAO,IAAI,EAAS,CAAK,EAI/B,UAAU,CAAC,EAAkC,CAC5C,IAAM,EAAO,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AgB,MAAS,EAC9B,KAAK,KACL,KAAK,GAAa,MAAM,EACxB,KAAK,GAAU,cAAc,EAC7B,KAAK,GAAM,eAAgB,CAAE,SAAQ,MAAK,CAAC,EAG1C,EAAkB,IAAI,CAAM,GAC5B,KAAK,KAAgB,GACrB,KAAK,KAAW,gBAChB,KAAK,KAAgB,OAErB,KAAK,GAAmB,EAAQ,CAAC,EAEpC,EAEF",
12
+ "debugId": "D99911AB9F09570E64756E2164756E21",
13
13
  "names": []
14
14
  }
@@ -0,0 +1,4 @@
1
+ var K=0;function a(e,n,t={},...r){let o=e.createElement(n);if(t.className!==void 0)o.className=t.className;if(t.id!==void 0)o.id=t.id;if(t.text!==void 0)o.textContent=t.text;return o.append(...r),o}function g(e,n,t){let r=a(e,"button",{text:n});return r.type="button",r.addEventListener("click",t),r}function ne(e,n,t,r){let o=g(e,"Copy",()=>{let m=()=>{o.textContent="Copied",o.setAttribute("aria-label",`Copied ${n}`)},l=e.defaultView?.navigator?.clipboard;if(l!==void 0)l.writeText(t()).then(m,r);else r()}),i=()=>{o.textContent="Copy",o.setAttribute("aria-label",`Copy ${n}`)};return i(),{button:o,reset:i}}function se(e,n,t){let r=`tab-mcp-${++K}`,o=a(e,"dialog",{className:`tab-mcp-dialog ${n}`});o.setAttribute("aria-labelledby",`${r}-title`);let i=o.style;i.setProperty("max-width","var(--tab-mcp-max-width, 34rem)"),i.setProperty("font","var(--tab-mcp-font, inherit)"),i.setProperty("color","var(--tab-mcp-color, CanvasText)"),i.setProperty("background","var(--tab-mcp-background, Canvas)"),i.setProperty("border","var(--tab-mcp-border, 1px solid GrayText)"),i.setProperty("border-radius","var(--tab-mcp-radius, 0.5rem)"),i.setProperty("padding","var(--tab-mcp-padding, 1rem 1.25rem)");let m=a(e,"h2",{id:`${r}-title`,text:t});return m.style.setProperty("margin-top","0"),m.style.setProperty("font-size","var(--tab-mcp-title-size, 1.25em)"),o.append(m),{dialog:o,heading:m}}var ie=/[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Co}\p{Cn}\u0080-\u009F\u2028\u2029]/gu;function U(e){return e.replace(ie,(n)=>{let t="";for(let r=0;r<n.length;r++)t+=`\\u${n.charCodeAt(r).toString(16).toUpperCase().padStart(4,"0")}`;return t})}function O(e){let n=U(e.host||e.id);return e.name!==void 0&&e.name!==""?`${U(e.name)} (${n})`:n}function S(e,n){let t=a(e,"bdi",{text:n});return t.dir="ltr",t}function de(e){try{return U(JSON.stringify(e,null,2))}catch{return}}var le=750,ce=500;function ue(e){let n=typeof e==="number"&&Number.isFinite(e)&&e<2147483648?e:le;return Math.max(ce,n)}function fe(e,n,t={}){let r=ue(t.allowDelayMs);if(e.signal.aborted)return Promise.resolve("deny");let o=e.tool.title??e.tool.name,{dialog:i,heading:m}=se(n,"tab-mcp-confirm","");m.append("Allow ",S(n,o),"?");let l=O(e.client),h=g(n,"Don't allow",()=>i.close("deny")),v=g(n,"Allow",()=>{if(!v.disabled)i.close("allow")}),u=g(n,"Always allow",()=>{if(!u.disabled)i.close("always")});v.disabled=!0,u.disabled=!0;let x=a(n,"div",{className:"tab-mcp-actions"},h," ",v," ",u),D=a(n,"p",{className:"tab-mcp-always-note"},"Always allow: ",S(n,o)," runs without asking for ",S(n,l)," until you reload this page or disconnect it."),T=de(e.arguments),y=a(n,"pre",{className:"tab-mcp-arguments",text:T??"The arguments cannot be shown, so this call cannot be allowed."});if(T===void 0)v.hidden=!0,u.hidden=!0,D.hidden=!0;y.dir="ltr",y.style.setProperty("white-space","pre-wrap"),y.style.setProperty("max-height","12rem"),y.style.setProperty("overflow","auto"),y.hidden=Object.keys(e.arguments).length===0,i.append(a(n,"p",{},S(n,l)," wants to run ",S(n,o),"."),a(n,"p",{className:"tab-mcp-description",text:e.tool.description}),y,x,D),n.body.append(i);let A=n.defaultView;return new Promise((p)=>{let c=()=>i.close("deny");e.signal.addEventListener("abort",c,{once:!0});let P,b=(w)=>{if(clearTimeout(P),P=void 0,v.disabled=!0,u.disabled=!0,w?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;P=setTimeout(()=>{v.disabled=!1,u.disabled=!1},r)};n.addEventListener("visibilitychange",b),A?.addEventListener("focus",b),A?.addEventListener("blur",b),i.addEventListener("close",()=>{clearTimeout(P),n.removeEventListener("visibilitychange",b),A?.removeEventListener("focus",b),A?.removeEventListener("blur",b),e.signal.removeEventListener("abort",c);let w=i.returnValue;i.remove(),p(w==="allow"||w==="always"?w:"deny")},{once:!0}),i.showModal(),h.focus(),b()})}var pe=[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."],["Claude Code","Run: claude mcp add --transport http tools ADDRESS"]];function me(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function ge(e,n,t){let{dialog:r}=se(t,"tab-mcp-connect","Connect your AI app");r.tabIndex=-1,r.style.setProperty("outline","none");let o=a(t,"p",{className:"tab-mcp-status",text:"Connecting…"});o.setAttribute("role","status");let i=`tab-mcp-${++K}-address`,m=a(t,"label",{text:"Add this address to your AI app:"});m.htmlFor=i;let l=a(t,"input",{id:i,className:"tab-mcp-address-input"});l.readOnly=!0,l.style.setProperty("width","100%"),l.style.setProperty("font-family","var(--tab-mcp-mono, monospace)");let{button:h,reset:v}=ne(t,"address",()=>l.value,()=>l.select());h.className="tab-mcp-address-copy";let u=g(t,"New address",()=>oe());u.className="tab-mcp-new-address";let x=a(t,"div",{className:"tab-mcp-address"},m,l," ",h," ",u),D=`tab-mcp-${++K}-new-address`,T=a(t,"p",{id:D}),y=g(t,"Cancel",()=>{p.hidden=!0,u.focus()}),A=g(t,"Disconnect and get new address",()=>Z());A.className="tab-mcp-new-address-confirm";let p=a(t,"div",{className:"tab-mcp-new-address-question"},T,a(t,"div",{className:"tab-mcp-actions"},y," ",A));p.setAttribute("role","group"),p.setAttribute("aria-labelledby",D),p.hidden=!0;let c=a(t,"strong",{className:"tab-mcp-code-value"});c.style.setProperty("font-size","var(--tab-mcp-code-size, 1.5em)"),c.style.setProperty("letter-spacing","0.1em"),c.style.setProperty("font-family","var(--tab-mcp-mono, monospace)"),c.style.setProperty("user-select","all"),c.style.setProperty("-webkit-user-select","all");let{button:P,reset:b}=ne(t,"code",()=>c.textContent??"",()=>t.getSelection()?.selectAllChildren(c));P.className="tab-mcp-code-copy";let w=a(t,"span",{},"When asked, enter the code ",c);w.setAttribute("aria-live","polite");let M=a(t,"p",{className:"tab-mcp-code"},w," ",P,a(t,"br"),a(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."})),B=a(t,"p",{className:"tab-mcp-sign-in",text:"When your AI app asks, sign in with the account you use on this page. No code is needed."}),Y=a(t,"ul"),k=a(t,"details",{className:"tab-mcp-help"},a(t,"summary",{text:"How do I add it?"}),Y),J=a(t,"ul"),H=a(t,"div",{className:"tab-mcp-apps"},a(t,"h3",{text:"Connected"}),J),z=a(t,"small",{className:"tab-mcp-close-note",text:"Closing this stops the code. The address stays the same: to connect later, open this again from the page."}),C=g(t,"Close",()=>r.close());C.className="tab-mcp-close",C.style.setProperty("font-size","0.875em");let N=g(t,"Done",()=>r.close());N.className="tab-mcp-done",N.style.setProperty("font-weight","bold"),N.hidden=!0;let E=a(t,"div",{className:"tab-mcp-actions"},z," ",C,N);E.style.setProperty("display","flex"),E.style.setProperty("align-items","center"),E.style.setProperty("justify-content","flex-end"),E.style.setProperty("gap","0.75rem"),E.style.setProperty("margin-top","1rem"),z.style.setProperty("flex","1");let f=!1,F=new Set,Q=()=>{z.hidden=f||M.hidden},V=(s)=>{if(f=s,!f)F.clear();let d=t.activeElement;if(Q(),C.hidden=f,N.hidden=!f,f&&d===C)N.focus();if(!f&&d===N)C.focus()},ae=()=>f?N:C;r.append(o,x,p,M,B,k,H,E),x.hidden=!0,M.hidden=!0,B.hidden=!0,k.hidden=!0,H.hidden=!0;let _=!1,X=()=>{let s=e.grants.map((d)=>O(d.client));if(s.length===0)return!1;return T.textContent=`A new address disconnects ${me(s)}. To use this page again, add the new address to ${s.length===1?"it":"them"}.`,!0},oe=()=>{if(e.state!=="connected")return;if(!X()){Z();return}p.hidden=!1,y.focus()},Z=()=>{V(!1),C.focus(),p.hidden=!0,_=!0,o.textContent="Getting a new address…",e.newAddress().then(()=>{_=!1,o.textContent="This is a new address. Add it to your AI app again.",h.focus()},(s)=>{_=!1,o.textContent=`Could not connect: ${s instanceof Error?s.message:String(s)}. Close this and connect again.`,ae().focus()})},R=(s)=>{if(s===void 0){x.hidden=!0,p.hidden=!0,k.hidden=!0;return}l.value=s.address,v();let d=s.appName??e.appName;if(!_)o.textContent=d!==void 0?`${d} is ready for your AI app.`:"This page is ready for your AI app.";if(u.disabled=e.state!=="connected",x.hidden=!1,t.activeElement===r)h.focus();k.hidden=!1,Y.replaceChildren(...pe.map(([G,re])=>a(t,"li",{},a(t,"strong",{text:G}),`: ${re.replace("ADDRESS",s.address)}`)))},I=()=>{let s=e.pairingCode,d=e.session?.pairing==="oidc";if(c.textContent!==(s?.code??""))b();c.textContent=s?.code??"",M.hidden=d||s===void 0,B.hidden=!d,Q()},W=a(t,"p",{className:"tab-mcp-apps-note"});H.append(W);let j=new Set(e.grants.map((s)=>s.grantId)),q=e.session,L=()=>{if(e.session!==q){q=e.session;for(let d of e.grants)j.add(d.grantId)}for(let d of e.grants){if(j.has(d.grantId))continue;if(j.add(d.grantId),o.textContent=`${O(d.client)} is connected.`,F.add(d.grantId),!f)V(!0)}if(f&&!e.grants.some((d)=>F.has(d.grantId)))V(!1);let s=e.state==="connected";if(J.replaceChildren(...e.grants.map((d)=>{let G=g(t,"Disconnect",()=>{if(!e.revoke(d.grantId))L()});return G.disabled=!s,a(t,"li",{},`${O(d.client)} connected `,G)})),W.textContent=s?"":"To disconnect an app, connect this page again first.",W.hidden=s,H.hidden=e.grants.length===0,!p.hidden&&!X())p.hidden=!0,u.focus()},ee=(s)=>{if(s.detail.reason!=="new_address")o.textContent="Disconnected. AI apps can use this page again after you connect.";R(void 0),L(),I()},te=()=>{R(e.session),L(),I()};return e.addEventListener("pairingcode",I),e.addEventListener("grantschange",L),e.addEventListener("connected",te),e.addEventListener("disconnected",ee),t.body.append(r),e.startPairing(),L(),I(),R(e.session),n.then((s)=>R(s),(s)=>{o.textContent=`Could not connect: ${s instanceof Error?s.message:String(s)}`}),new Promise((s)=>{if(r.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",I),e.removeEventListener("grantschange",L),e.removeEventListener("connected",te),e.removeEventListener("disconnected",ee),r.remove(),s()},{once:!0}),r.showModal(),!x.hidden)h.focus();else r.focus()})}export{fe as confirmDialog,ge as showConnectDialog};
2
+
3
+ //# debugId=C95128776619998A64756E2164756E21
4
+ //# sourceMappingURL=ui-yknfss9n.min.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/**\n * A Copy button for `value()`, read at click time. Shows \"Copied\" once the\n * clipboard took it; without a clipboard (or when it refuses) `select()` puts\n * the text in the selection for Ctrl+C instead. `noun` names it for assistive\n * technology (\"Copy code\"), as the dialog has more than one Copy.\n */\nfunction copyButton(\n\tdoc: Document,\n\tnoun: string,\n\tvalue: () => string,\n\tselect: () => void,\n): { button: HTMLButtonElement; reset: () => void } {\n\tconst node = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tnode.textContent = \"Copied\";\n\t\t\tnode.setAttribute(\"aria-label\", `Copied ${noun}`);\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(value()).then(done, select);\n\t\telse select();\n\t});\n\tconst reset = () => {\n\t\tnode.textContent = \"Copy\";\n\t\tnode.setAttribute(\"aria-label\", `Copy ${noun}`);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\n/**\n * Characters that are invisible or change the direction of the text around\n * them: format characters (bidi controls and isolates, zero-width ones, tags),\n * the other default-ignorable ones (fillers, variation selectors), private-use\n * and unassigned code points, C1 controls, and line and paragraph separators.\n */\nconst INVISIBLE =\n\t/[\\p{Cf}\\p{Default_Ignorable_Code_Point}\\p{Co}\\p{Cn}\\u0080-\\u009F\\u2028\\u2029]/gu;\n\n/** Each such character as `\\uXXXX` (a pair for one beyond U+FFFF), as JSON would write it. */\nfunction visible(text: string): string {\n\treturn text.replace(INVISIBLE, (ch) => {\n\t\tlet escaped = \"\";\n\t\tfor (let i = 0; i < ch.length; i++)\n\t\t\tescaped += `\\\\u${ch.charCodeAt(i).toString(16).toUpperCase().padStart(4, \"0\")}`;\n\t\treturn escaped;\n\t});\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = visible(client.host || client.id);\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${visible(client.name)} (${host})`\n\t\t: host;\n}\n\n/** A name in a sentence, isolated so that it cannot reorder the words around it. */\nfunction name(doc: Document, text: string): HTMLElement {\n\tconst node = el(doc, \"bdi\", { text });\n\tnode.dir = \"ltr\";\n\treturn node;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) Invisible and\n * direction characters are shown as escapes, so the text is still JSON for\n * the same arguments; the tool gets them unchanged. `undefined` when they\n * cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn visible(JSON.stringify(args, null, 2));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/** `allowDelayMs` as a usable delay: the default unless a number of ms, never below the floor. */\nfunction allowDelay(ms: number | undefined): number {\n\tconst value =\n\t\ttypeof ms === \"number\" && Number.isFinite(ms) && ms < 2 ** 31\n\t\t\t? ms\n\t\t\t: ALLOW_DELAY_MS;\n\treturn Math.max(MIN_ALLOW_DELAY_MS, value);\n}\n\n/**\n * Ask whether a consequential tool may run. \"Allow\" and \"Always allow\" stay\n * disabled until the page has been visible and focused for `allowDelayMs`\n * (default 750, at least 500) while the dialog is open, so a click meant for\n * the page, or the click that brings the tab or window back, cannot approve.\n * Leaving the page disables them again. Everything else (Don't allow,\n * Escape, an aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = allowDelay(options.allowDelayMs);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog, heading } = newDialog(doc, \"tab-mcp-confirm\", \"\");\n\theading.append(\"Allow \", name(doc, title), \"?\");\n\tconst client = clientLabel(request.client);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tconst always = button(doc, \"Always allow\", () => {\n\t\tif (!always.disabled) dialog.close(\"always\");\n\t});\n\tallow.disabled = true;\n\talways.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t\t\" \",\n\t\talways,\n\t);\n\tconst alwaysNote = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-always-note\" },\n\t\t\"Always allow: \",\n\t\tname(doc, title),\n\t\t\" runs without asking for \",\n\t\tname(doc, client),\n\t\t\" until you reload this page or disconnect it.\",\n\t);\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tallow.hidden = true;\n\t\talways.hidden = true;\n\t\talwaysNote.hidden = true;\n\t}\n\targs.dir = \"ltr\";\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"p\",\n\t\t\t{},\n\t\t\tname(doc, client),\n\t\t\t\" wants to run \",\n\t\t\tname(doc, title),\n\t\t\t\".\",\n\t\t),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\talwaysNote,\n\t);\n\tdoc.body.append(dialog);\n\tconst view = doc.defaultView;\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t// The delay counts only while the user can see the page: tools are\n\t\t// called while the user is in the AI app, so the dialog often opens in\n\t\t// a background tab or window. Any change starts it again from zero (DEC-087).\n\t\tconst arm = (event?: Event) => {\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t\tallow.disabled = true;\n\t\t\talways.disabled = true;\n\t\t\tif (\n\t\t\t\tevent?.type === \"blur\" ||\n\t\t\t\tdoc.visibilityState === \"hidden\" ||\n\t\t\t\t!doc.hasFocus()\n\t\t\t)\n\t\t\t\treturn;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tallow.disabled = false;\n\t\t\t\talways.disabled = false;\n\t\t\t}, delay);\n\t\t};\n\t\tdoc.addEventListener(\"visibilitychange\", arm);\n\t\tview?.addEventListener(\"focus\", arm);\n\t\tview?.addEventListener(\"blur\", arm);\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tdoc.removeEventListener(\"visibilitychange\", arm);\n\t\t\t\tview?.removeEventListener(\"focus\", arm);\n\t\t\t\tview?.removeEventListener(\"blur\", arm);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\tarm();\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code (with Copy) while the relay sends one,\n * and the connected apps with Disconnect. Pairing is on while it is open, so\n * closing it ends the code; the connection and the address stay. Until an app\n * connects, only a small Close (and Escape) close it; then a Done. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\t// Focusable from script only, for the moment before the address is shown.\n\tdialog.tabIndex = -1;\n\tdialog.style.setProperty(\"outline\", \"none\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst { button: copy, reset: resetCopy } = copyButton(\n\t\tdoc,\n\t\t\"address\",\n\t\t() => address.value,\n\t\t() => address.select(),\n\t);\n\tcopy.className = \"tab-mcp-address-copy\";\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tcode.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\t// One click selects the whole code; it stays plain, selectable text.\n\tcode.style.setProperty(\"user-select\", \"all\");\n\tcode.style.setProperty(\"-webkit-user-select\", \"all\");\n\t// Reads the code shown at click time, so a rotated code is copied as shown.\n\tconst { button: copyCode, reset: resetCopyCode } = copyButton(\n\t\tdoc,\n\t\t\"code\",\n\t\t() => code.textContent ?? \"\",\n\t\t() => doc.getSelection()?.selectAllChildren(code),\n\t);\n\tcopyCode.className = \"tab-mcp-code-copy\";\n\t// Only the sentence with the code is announced when the code changes,\n\t// not its Copy button's \"Copied\".\n\tconst codeSentence = el(doc, \"span\", {}, \"When asked, enter the code \", code);\n\tcodeSentence.setAttribute(\"aria-live\", \"polite\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\t\" \",\n\t\tcopyCode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\t// Identity binding: no code, the same account at the AI app's sign-in.\n\tconst signInLine = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-sign-in\",\n\t\ttext: \"When your AI app asks, sign in with the account you use on this page. No code is needed.\",\n\t});\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\t// Until an app connects in this dialog, closing it is not the next step:\n\t// a small Close at the end, saying what closing does (the code stops, the\n\t// address stays). Once one connects, a prominent Done replaces both.\n\tconst closeNote = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-close-note\",\n\t\ttext: \"Closing this stops the code. The address stays the same: to connect later, open this again from the page.\",\n\t});\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tclose.className = \"tab-mcp-close\";\n\tclose.style.setProperty(\"font-size\", \"0.875em\");\n\tconst done = button(doc, \"Done\", () => dialog.close());\n\tdone.className = \"tab-mcp-done\";\n\tdone.style.setProperty(\"font-weight\", \"bold\");\n\tdone.hidden = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tcloseNote,\n\t\t\" \",\n\t\tclose,\n\t\tdone,\n\t);\n\t// The note on the left, the button at the far right, apart from the code.\n\tactions.style.setProperty(\"display\", \"flex\");\n\tactions.style.setProperty(\"align-items\", \"center\");\n\tactions.style.setProperty(\"justify-content\", \"flex-end\");\n\tactions.style.setProperty(\"gap\", \"0.75rem\");\n\tactions.style.setProperty(\"margin-top\", \"1rem\");\n\tcloseNote.style.setProperty(\"flex\", \"1\");\n\t// An app connected while this dialog is open (since the last new address),\n\t// and still connected: the grants that made it so.\n\tlet paired = false;\n\tconst pairedGrants = new Set<string>();\n\t// The note is about the code: only while one is shown and nothing paired.\n\tconst renderCloseNote = () => {\n\t\tcloseNote.hidden = paired || codeLine.hidden;\n\t};\n\tconst setPaired = (value: boolean) => {\n\t\tpaired = value;\n\t\tif (!paired) pairedGrants.clear();\n\t\tconst focused = doc.activeElement;\n\t\trenderCloseNote();\n\t\tclose.hidden = paired;\n\t\tdone.hidden = !paired;\n\t\t// Focus never stays on a control that was just hidden.\n\t\tif (paired && focused === close) done.focus();\n\t\tif (!paired && focused === done) close.focus();\n\t};\n\t// The visible button that closes the dialog.\n\tconst closer = () => (paired ? done : close);\n\n\tdialog.append(\n\t\tstatus,\n\t\taddressBox,\n\t\tconfirmBox,\n\t\tcodeLine,\n\t\tsignInLine,\n\t\thelp,\n\t\tapps,\n\t\tactions,\n\t);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\tsignInLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// The apps are disconnected: the next one has to pair again.\n\t\tsetPaired(false);\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tcopy.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tresetCopy();\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\t// Opened before the session was known: start at the address's Copy.\n\t\tif (doc.activeElement === dialog) copy.focus();\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tconst oidc = mcp.session?.pairing === \"oidc\";\n\t\t// A new code is not copied yet.\n\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = oidc || current === undefined;\n\t\tsignInLine.hidden = !oidc;\n\t\trenderCloseNote();\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\t// Grants that come with a (new) session were there before; only the ones\n\t// added during a session are new connections.\n\tlet session = mcp.session;\n\tconst renderGrants = () => {\n\t\tif (mcp.session !== session) {\n\t\t\tsession = mcp.session;\n\t\t\tfor (const grant of mcp.grants) known.add(grant.grantId);\n\t\t}\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t\tpairedGrants.add(grant.grantId);\n\t\t\tif (!paired) setPaired(true);\n\t\t}\n\t\t// The app that connected here is gone again (Disconnect, or revoked):\n\t\t// back to Close and the note, the code still runs.\n\t\tif (paired && !mcp.grants.some((g) => pairedGrants.has(g.grantId))) {\n\t\t\tsetPaired(false);\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\t// Start at the address's Copy; until the address is there, at the\n\t\t// dialog itself (its title is read out), not at Close.\n\t\tif (!addressBox.hidden) copy.focus();\n\t\telse dialog.focus();\n\t});\n}\n"
6
+ ],
7
+ "mappings": "AAiBA,IAAI,EAAU,EAEd,SAAS,CA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