@ractive-ch/tab-mcp-client 0.10.0 → 0.11.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 T,g,f,p=(e,t)=>{for(var[n,i,o]of T||[])for(var r=[e],a=globalThis,s=a.document,d,c,h,l,u;c=r.pop();)if(!g[c]&&(h=i[c])){g[c]=1;for(l=1;l<h.length;l++)r.push(o[h[l]]);if(!t&&c!==e&&(d=s&&s.head)){if(f===void 0)f=(l=s.querySelector("meta[property=csp-nonce]"))&&(l.nonce||l.getAttribute("nonce"))||"";if(u=s.createElement("link"),u.rel="modulepreload",u.crossOrigin="",f)u.nonce=f;u.href=new a.URL(h[0],n),d.appendChild(u)}}},A=(e,t,n,i)=>{for(var o={},r=0;r<t.length;r++)o[t[r]]=n[r];(T||=[]).push([e,o,t]),g||={},p(t[i],1)};A(import.meta.url,["ph0yfqv4","9w0rx0vf","406jbpym"],[["./tab-mcp-client.min.js"],["./connection-9w0rx0vf.min.js"],["./ui-406jbpym.min.js"]],0);
2
- var M=/^[A-Za-z0-9_.-]{1,128}$/;function m(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function S(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)=>S(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 L(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(!m(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"||!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 r!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let s=o??{type:"object"};if(!m(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${t} must be a JSON Schema object with "type": "object"`);if(S(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let d=L(s);if(d!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${d}`);let c;try{c=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${t} must be JSON`)}if(a!==void 0&&!m(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let h={};for(let[l,u]of Object.entries(a??{}))if(typeof u==="boolean")h[l]=u;return{name:t,title:n,description:i,inputSchema:c,annotations:h,execute:r}}class y{#e=new Map;#o=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.#r()}setCompiler(e){this.#a??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),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 k=/^[A-Za-z0-9_-]{43}$/;function D(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function N(){return D(crypto.getRandomValues(new Uint8Array(32)))}function v(e){return typeof e==="string"&&k.test(e)}function j(){try{return globalThis.localStorage??null}catch{return null}}class b{#e;#o;#a;#r;#p;constructor(e,t,n){this.#e=e===void 0?j():e,this.#o=t,this.#a=n,this.#r=n===void 0?void 0:`${n}#moved`}get(){let e=null;try{if(e=this.#e?.getItem(this.#o)??null,!v(e)&&this.#a!==void 0&&this.#r!==void 0&&this.#e?.getItem(this.#r)==null){let t=this.#e?.getItem(this.#a)??null;if(v(t))e=t,this.#m(t)}}catch{}if(v(e))return this.#p=e,e;return this.#p??this.rotate()}rotate(){let e=N();return this.#p=e,this.#m(e),e}#m(e){try{if(this.#e?.setItem(this.#o,e),this.#r!==void 0)this.#e?.setItem(this.#r,this.#o)}catch{}}}var E="@ractive-ch/tab-mcp-client",w="0.10.0";var _=new Set(["localhost","127.0.0.1","[::1]"]),C=[5000,1e4,20000,40000,60000],R=new Set(["network","heartbeat","shutdown"]);function H(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 I(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 K(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 G(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 z(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 y;#o;#a;#r;#p;#m;#x;#R;#k;#y=!1;#$;#w="none";#D;#h=0;#N;#n="disconnected";#l;#g=Object.freeze([]);#u=!1;#I;#i;#s;#v=0;#j;#d;#f;#T;#S=!1;#E;constructor(e){super();let{url:t,origin:n}=G(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.#x=t,this.#o={...i},this.#a=o,this.#r=e.onConfirm,this.#p=I("confirmDelayMs",e.confirmDelayMs),this.#m=e.alwaysAllow===!0,this.#$=e.identityAssertion,this.#N=I("identityTimeoutMs",e.identityTimeoutMs)??15000,this.#j=H(e.reconnect);let r=e.storageKey??`tab-mcp:secret:${n}:${encodeURIComponent(i.name)}`;this.#R=new b(e.storage,r,e.storageKey===void 0?`tab-mcp:secret:${n}`:void 0),this.#k=e.storage===null?void 0:`${r}#tabs`,this.#e.onChange(()=>this.#t("toolschange",{tools:this.tools}))}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.#l}get address(){return this.#l?.address}get appName(){return this.#l?.appName??this.#a}get grants(){return this.#g}get reconnecting(){return this.#d}get identity(){return this.#w}get identityMessage(){return this.#D}refreshIdentity(){let e=this.#l,t=this.#$;if(this.#n!=="connected"||e===void 0||t===void 0)return Promise.resolve(!1);let n=++this.#h,i=this.#i;this.#c("pending");let o=setTimeout(()=>{if(n!==this.#h||this.#w!=="pending")return;this.#h++,this.#c("none")},this.#N);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.#h||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.#h)return;this.#t("error",{error:s instanceof Error?s:Error(String(s))}),this.#c("none")})})}signOut(){if(this.#h++,this.#c("none"),this.#n!=="connected")return!1;return this.#i?.send({type:"identity.logout"})===!0}get pairing(){return this.#u}get pairingCode(){return this.#I}connect(e={}){if(this.#n==="connected"&&this.#l!==void 0)return Promise.resolve(this.#l);if(this.#s!==void 0){if(this.#d!==void 0)this.#S=!0;return this.#s}if(this.#d!==void 0)return this.#M(!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.#O()}#O(e){this.#b("connecting");let t=this.#K(this.#v,e);return this.#s=t,t.then(()=>{if(this.#s===t)this.#s=void 0},()=>{if(this.#s!==t)return;this.#s=void 0,this.#i=void 0,this.#b("disconnected")}),t}async#K(e,t){let{openConnection:n,compileRegistry:i,addressIdOf:o,withAddress:r}=await (p("9w0rx0vf"),import("./connection-9w0rx0vf.min.js"));for(let h of i(this.#e))this.#t("error",{error:h});let a=this.#R.get(),s=await o(a);if(e!==this.#v)throw new DOMException("The connection was cancelled","AbortError");let d={},c=n(this.#z(d),r(this.#x,s),a,t);return d.connection=c,this.#i=c,c.ready}disconnect(){this.#A("user")}newAddress(){if(this.#y)return this.#A("new_address"),this.#O(!0).then(()=>this.#_(!0),(e)=>{throw this.#y=!0,e});return this.#_(!1)}#_(e){let t=e||this.#n!=="disconnected"||this.#d!==void 0;if(this.#n==="connected")this.#i?.send({type:"grants.revokeAll"});return this.#A("new_address"),this.#R.rotate(),this.#y=!1,t?this.connect({resume:!0}):Promise.resolve(void 0)}#A(e){this.#P(),this.#v++;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.#l=void 0,this.#C(void 0),this.#h++,this.#c("none"),this.#b("disconnected"),n)this.#t("disconnected",{reason:e,code:1000})}#H(e,t){let n=this.#j;if(n===void 0)return;let i=n[Math.min(t,n.length)-1]??0;clearTimeout(this.#f),this.#f=setTimeout(()=>{this.#M().catch(()=>{})},i),this.#J(),this.#d={reason:e,attempt:t,at:Date.now()+i},this.#t("reconnecting",this.#d)}#M(e=!1){if(clearTimeout(this.#f),this.#f=void 0,this.#s!==void 0)return this.#s;let t=this.#d;this.#S=e;let n=this.#O();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.#H(t.reason,t.attempt+1);return}this.#P(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.#M().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)}}#P(e){if(clearTimeout(this.#f),this.#f=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.#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.#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.#G(t).finally(()=>{if(this.#E?.shown===i)this.#E=void 0});return this.#E={doc:t,shown:i},i}async#G(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("406jbpym"),import("./ui-406jbpym.min.js"));await n(this,t,e,this.#o.name)}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}))}#b(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.#D=e==="refused"?t:void 0,this.#t("identitychange",t===void 0?{state:e}:{state:e,message:t})}#C(e){if(this.#I===void 0&&e===void 0)return;this.#I=e,this.#t("pairingcode",e??null)}#L(e){this.#g=Object.freeze(e.map(K)),this.#t("grantschange",{grants:this.#g})}#U(e){if(this.#r!==void 0){let t=this.#r;return Promise.resolve().then(()=>t(e)).then((n)=>n===!0)}return this.confirmInPage(e)}confirmInPage(e){let t=globalThis.document;if(t===void 0)return Promise.resolve(!1);return (p("406jbpym"),import("./ui-406jbpym.min.js")).then((n)=>n.confirmInPage(this,e,t,{allowDelayMs:this.#p,alwaysAllow:this.#m}))}#z(e){let t=()=>e.connection!==void 0&&this.#i===e.connection,n=!1;return{registry:this.#e,server:this.#o,appName:this.#a,tabs:this.#k,library:{name:E,version:w},confirm:(i)=>this.#U(i),toolCallStarted:(i)=>this.#t("toolcall",i),toolCallEnded:(i)=>this.#t("toolcallend",i),clientFor:(i)=>{let o=this.#g.find((a)=>a.grantId===i.grantId),r={grantId:i.grantId,id:i.clientId,host:U(i.clientId)};if(o!==void 0)r.name=o.client.name;return r},sessionStarted:(i)=>{let o=z(i);if(!t())return o;if(this.#l=o,this.#y=!1,this.#P(),this.#b("connected"),this.#L([...i.grants]),this.#u)this.#i?.send({type:"pairing.start"});if(this.#t("connected",o),o.pairing==="oidc")this.refreshIdentity();return o},pairingCode:(i)=>{if(t()&&this.#u)this.#C(i)},grantAdded:(i)=>{if(!t())return;this.#L([...this.#g.filter((o)=>o.grantId!==i.grantId),i])},grantRemoved:(i)=>{if(!t())return;this.#L(this.#g.filter((o)=>o.grantId!==i))},replaced:(i)=>{if(n)this.#t("replaced",i)},identityResult:(i,o,r)=>{if(!t())return;if(o!==this.#h)return;if(i)this.#c("bound");else this.#c("refused",r??"")},error:(i)=>{if(t())this.#t("error",{error:i})},closed:(i,o)=>{if(!t())return;if(i==="replaced")this.#y=n=!0;let r=this.#v;if(this.#i=void 0,this.#l=void 0,this.#C(void 0),this.#h++,this.#c("none"),this.#b("disconnected"),this.#t("disconnected",{reason:i,code:o}),R.has(i)&&this.#v===r&&this.#n==="disconnected"&&this.#s===void 0)this.#H(i,1)}}}}export{O as TabMcp,w as VERSION};
1
+ var T,g,f,p=(e,t)=>{for(var[n,i,o]of T||[])for(var r=[e],a=globalThis,s=a.document,d,c,h,l,u;c=r.pop();)if(!g[c]&&(h=i[c])){g[c]=1;for(l=1;l<h.length;l++)r.push(o[h[l]]);if(!t&&c!==e&&(d=s&&s.head)){if(f===void 0)f=(l=s.querySelector("meta[property=csp-nonce]"))&&(l.nonce||l.getAttribute("nonce"))||"";if(u=s.createElement("link"),u.rel="modulepreload",u.crossOrigin="",f)u.nonce=f;u.href=new a.URL(h[0],n),d.appendChild(u)}}},A=(e,t,n,i)=>{for(var o={},r=0;r<t.length;r++)o[t[r]]=n[r];(T||=[]).push([e,o,t]),g||={},p(t[i],1)};A(import.meta.url,["0mnkp7hc","8zhj84k2","0wa4gyh3"],[["./tab-mcp-client.min.js"],["./connection-8zhj84k2.min.js"],["./ui-0wa4gyh3.min.js"]],0);
2
+ var M=/^[A-Za-z0-9_.-]{1,128}$/;function m(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function S(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)=>S(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 L(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(!m(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"||!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 r!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let s=o??{type:"object"};if(!m(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${t} must be a JSON Schema object with "type": "object"`);if(S(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let d=L(s);if(d!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${d}`);let c;try{c=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${t} must be JSON`)}if(a!==void 0&&!m(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let h={};for(let[l,u]of Object.entries(a??{}))if(typeof u==="boolean")h[l]=u;return{name:t,title:n,description:i,inputSchema:c,annotations:h,execute:r}}class y{#e=new Map;#o=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.#r()}setCompiler(e){this.#a??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),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 k=/^[A-Za-z0-9_-]{43}$/;function D(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function N(){return D(crypto.getRandomValues(new Uint8Array(32)))}function v(e){return typeof e==="string"&&k.test(e)}function j(){try{return globalThis.localStorage??null}catch{return null}}class b{#e;#o;#a;#r;#p;constructor(e,t,n){this.#e=e===void 0?j():e,this.#o=t,this.#a=n,this.#r=n===void 0?void 0:`${n}#moved`}get(){let e=null;try{if(e=this.#e?.getItem(this.#o)??null,!v(e)&&this.#a!==void 0&&this.#r!==void 0&&this.#e?.getItem(this.#r)==null){let t=this.#e?.getItem(this.#a)??null;if(v(t))e=t,this.#m(t)}}catch{}if(v(e))return this.#p=e,e;return this.#p??this.rotate()}rotate(){let e=N();return this.#p=e,this.#m(e),e}#m(e){try{if(this.#e?.setItem(this.#o,e),this.#r!==void 0)this.#e?.setItem(this.#r,this.#o)}catch{}}}var E="@ractive-ch/tab-mcp-client",w="0.11.0";var _=new Set(["localhost","127.0.0.1","[::1]"]),C=[5000,1e4,20000,40000,60000],R=new Set(["network","heartbeat","shutdown"]);function H(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 I(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 K(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 G(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 z(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 y;#o;#a;#r;#p;#m;#x;#R;#k;#y=!1;#$;#w="none";#D;#h=0;#N;#n="disconnected";#l;#g=Object.freeze([]);#u=!1;#I;#i;#s;#v=0;#j;#d;#f;#T;#S=!1;#E;constructor(e){super();let{url:t,origin:n}=G(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.#x=t,this.#o={...i},this.#a=o,this.#r=e.onConfirm,this.#p=I("confirmDelayMs",e.confirmDelayMs),this.#m=e.alwaysAllow===!0,this.#$=e.identityAssertion,this.#N=I("identityTimeoutMs",e.identityTimeoutMs)??15000,this.#j=H(e.reconnect);let r=e.storageKey??`tab-mcp:secret:${n}:${encodeURIComponent(i.name)}`;this.#R=new b(e.storage,r,e.storageKey===void 0?`tab-mcp:secret:${n}`:void 0),this.#k=e.storage===null?void 0:`${r}#tabs`,this.#e.onChange(()=>this.#t("toolschange",{tools:this.tools}))}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.#l}get address(){return this.#l?.address}get appName(){return this.#l?.appName??this.#a}get grants(){return this.#g}get reconnecting(){return this.#d}get identity(){return this.#w}get identityMessage(){return this.#D}refreshIdentity(){let e=this.#l,t=this.#$;if(this.#n!=="connected"||e===void 0||t===void 0)return Promise.resolve(!1);let n=++this.#h,i=this.#i;this.#c("pending");let o=setTimeout(()=>{if(n!==this.#h||this.#w!=="pending")return;this.#h++,this.#c("none")},this.#N);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.#h||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.#h)return;this.#t("error",{error:s instanceof Error?s:Error(String(s))}),this.#c("none")})})}signOut(){if(this.#h++,this.#c("none"),this.#n!=="connected")return!1;return this.#i?.send({type:"identity.logout"})===!0}get pairing(){return this.#u}get pairingCode(){return this.#I}connect(e={}){if(this.#n==="connected"&&this.#l!==void 0)return Promise.resolve(this.#l);if(this.#s!==void 0){if(this.#d!==void 0)this.#S=!0;return this.#s}if(this.#d!==void 0)return this.#M(!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.#O()}#O(e){this.#b("connecting");let t=this.#K(this.#v,e);return this.#s=t,t.then(()=>{if(this.#s===t)this.#s=void 0},()=>{if(this.#s!==t)return;this.#s=void 0,this.#i=void 0,this.#b("disconnected")}),t}async#K(e,t){let{openConnection:n,compileRegistry:i,addressIdOf:o,withAddress:r}=await (p("8zhj84k2"),import("./connection-8zhj84k2.min.js"));for(let h of i(this.#e))this.#t("error",{error:h});let a=this.#R.get(),s=await o(a);if(e!==this.#v)throw new DOMException("The connection was cancelled","AbortError");let d={},c=n(this.#z(d),r(this.#x,s),a,t);return d.connection=c,this.#i=c,c.ready}disconnect(){this.#A("user")}newAddress(){if(this.#y)return this.#A("new_address"),this.#O(!0).then(()=>this.#_(!0),(e)=>{throw this.#y=!0,e});return this.#_(!1)}#_(e){let t=e||this.#n!=="disconnected"||this.#d!==void 0;if(this.#n==="connected")this.#i?.send({type:"grants.revokeAll"});return this.#A("new_address"),this.#R.rotate(),this.#y=!1,t?this.connect({resume:!0}):Promise.resolve(void 0)}#A(e){this.#P(),this.#v++;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.#l=void 0,this.#C(void 0),this.#h++,this.#c("none"),this.#b("disconnected"),n)this.#t("disconnected",{reason:e,code:1000})}#H(e,t){let n=this.#j;if(n===void 0)return;let i=n[Math.min(t,n.length)-1]??0;clearTimeout(this.#f),this.#f=setTimeout(()=>{this.#M().catch(()=>{})},i),this.#J(),this.#d={reason:e,attempt:t,at:Date.now()+i},this.#t("reconnecting",this.#d)}#M(e=!1){if(clearTimeout(this.#f),this.#f=void 0,this.#s!==void 0)return this.#s;let t=this.#d;this.#S=e;let n=this.#O();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.#H(t.reason,t.attempt+1);return}this.#P(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.#M().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)}}#P(e){if(clearTimeout(this.#f),this.#f=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.#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.#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.#G(t).finally(()=>{if(this.#E?.shown===i)this.#E=void 0});return this.#E={doc:t,shown:i},i}async#G(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("0wa4gyh3"),import("./ui-0wa4gyh3.min.js"));await n(this,t,e,this.#o.name)}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}))}#b(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.#D=e==="refused"?t:void 0,this.#t("identitychange",t===void 0?{state:e}:{state:e,message:t})}#C(e){if(this.#I===void 0&&e===void 0)return;this.#I=e,this.#t("pairingcode",e??null)}#L(e){this.#g=Object.freeze(e.map(K)),this.#t("grantschange",{grants:this.#g})}#U(e){if(this.#r!==void 0){let t=this.#r;return Promise.resolve().then(()=>t(e)).then((n)=>n===!0)}return this.confirmInPage(e)}confirmInPage(e){let t=globalThis.document;if(t===void 0)return Promise.resolve(!1);return (p("0wa4gyh3"),import("./ui-0wa4gyh3.min.js")).then((n)=>n.confirmInPage(this,e,t,{allowDelayMs:this.#p,alwaysAllow:this.#m}))}#z(e){let t=()=>e.connection!==void 0&&this.#i===e.connection,n=!1;return{registry:this.#e,server:this.#o,appName:this.#a,tabs:this.#k,library:{name:E,version:w},confirm:(i)=>this.#U(i),toolCallStarted:(i)=>this.#t("toolcall",i),toolCallEnded:(i)=>this.#t("toolcallend",i),clientFor:(i)=>{let o=this.#g.find((a)=>a.grantId===i.grantId),r={grantId:i.grantId,id:i.clientId,host:U(i.clientId)};if(o!==void 0)r.name=o.client.name;return r},sessionStarted:(i)=>{let o=z(i);if(!t())return o;if(this.#l=o,this.#y=!1,this.#P(),this.#b("connected"),this.#L([...i.grants]),this.#u)this.#i?.send({type:"pairing.start"});if(this.#t("connected",o),o.pairing==="oidc")this.refreshIdentity();return o},pairingCode:(i)=>{if(t()&&this.#u)this.#C(i)},grantAdded:(i)=>{if(!t())return;this.#L([...this.#g.filter((o)=>o.grantId!==i.grantId),i])},grantRemoved:(i)=>{if(!t())return;this.#L(this.#g.filter((o)=>o.grantId!==i))},replaced:(i)=>{if(n)this.#t("replaced",i)},identityResult:(i,o,r)=>{if(!t())return;if(o!==this.#h)return;if(i)this.#c("bound");else this.#c("refused",r??"")},error:(i)=>{if(t())this.#t("error",{error:i})},closed:(i,o)=>{if(!t())return;if(i==="replaced")this.#y=n=!0;let r=this.#v;if(this.#i=void 0,this.#l=void 0,this.#C(void 0),this.#h++,this.#c("none"),this.#b("disconnected"),this.#t("disconnected",{reason:i,code:o}),R.has(i)&&this.#v===r&&this.#n==="disconnected"&&this.#s===void 0)this.#H(i,1)}}}}export{O as TabMcp,w as VERSION};
3
3
 
4
- //# debugId=5F62BFF627E293BF64756E2164756E21
4
+ //# debugId=56970BC4BF7A10E064756E2164756E21
5
5
  //# sourceMappingURL=tab-mcp-client.min.js.map
@@ -4,10 +4,10 @@
4
4
  "sourcesContent": [
5
5
  "/**\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",
6
6
  "/**\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",
7
- "/** 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.10.0\";\n",
7
+ "/** 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.11.0\";\n",
8
8
  "/**\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 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 #alwaysAllow: boolean;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t/** The channel of the tabs that share the secret (DEC-095). */\n\treadonly #tabs: string | undefined;\n\t/** Replaced since the last session: `newAddress()` takes the address back first. */\n\t#takenOver = false;\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\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.#alwaysAllow = options.alwaysAllow === true;\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\tconst key =\n\t\t\toptions.storageKey ??\n\t\t\t`tab-mcp:secret:${origin}:${encodeURIComponent(server.name)}`;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\tkey,\n\t\t\toptions.storageKey === undefined ? `tab-mcp:secret:${origin}` : undefined,\n\t\t);\n\t\t// Tabs that share the secret share this channel; with `storage: null`\n\t\t// every tab has an address of its own (DEC-095).\n\t\tthis.#tabs = options.storage === null ? undefined : `${key}#tabs`;\n\t\tthis.#registry.onChange(() =>\n\t\t\tthis.#emit(\"toolschange\", { tools: this.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<Input extends object = Record<string, unknown>>(\n\t\ttool: Tool<Input>,\n\t\toptions: RegisterToolOptions = {},\n\t): Promise<void> {\n\t\ttry {\n\t\t\t// The arguments are checked against `inputSchema` before `execute` runs.\n\t\t\tthis.#registry.register(tool as unknown as 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(revokeAll?: boolean): Promise<SessionInfo> {\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation, revokeAll);\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, revokeAll?: boolean): Promise<SessionInfo> {\n\t\tconst { openConnection, compileRegistry, addressIdOf, withAddress } =\n\t\t\tawait 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\tconst secret = this.#secrets.get();\n\t\tconst address = await addressIdOf(secret);\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\twithAddress(this.#relayUrl, address),\n\t\t\tsecret,\n\t\t\trevokeAll,\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. After `replaced`, it first connects with the old address\n\t * again, so that the relay disconnects the apps that now talk to whoever\n\t * took it over (DEC-095), then connects with the new one. Call it from a\n\t * user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tif (this.#takenOver) {\n\t\t\t// `hello.revokeAll`: the relay revokes as it hands the address back, and\n\t\t\t// the connection resolves only once no grant is left. Taken over again\n\t\t\t// first: reject, keep the secret, so that a retry takes it back again.\n\t\t\tthis.#end(\"new_address\");\n\t\t\treturn this.#start(true).then(\n\t\t\t\t() => this.#renew(true),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tthis.#takenOver = true;\n\t\t\t\t\tthrow error;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn this.#renew(false);\n\t}\n\n\t#renew(on: boolean): Promise<SessionInfo | undefined> {\n\t\tconst wasOn =\n\t\t\ton || this.#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\tthis.#takenOver = false; // nobody else has the new secret\n\t\t// It was on: the user chose that already, as for a reconnect.\n\t\treturn wasOn ? this.connect({ resume: true }) : 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, this.#server.name);\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.#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 Don't allow\n\t * and Allow, and Always allow with `alwaysAllow: true` (what runs without\n\t * `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 doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\t// The tools allowed always live in the UI chunk too: only it adds them.\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmInPage(this, request, doc, {\n\t\t\t\tallowDelayMs: this.#confirmDelayMs,\n\t\t\t\talwaysAllow: this.#alwaysAllow,\n\t\t\t}),\n\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\tlet replacedHere = false;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\ttabs: this.#tabs,\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.#takenOver = false;\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\t// After `closed`, so no longer current: only a connection that was\n\t\t\t// current when it was replaced reports it.\n\t\t\treplaced: (detail) => {\n\t\t\t\tif (replacedHere) this.#emit(\"replaced\", detail);\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// Taken over: `newAddress()` takes it back first, whatever runs by\n\t\t\t\t// then (review of PR 39).\n\t\t\t\tif (reason === \"replaced\") this.#takenOver = replacedHere = true;\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"
9
9
  ],
10
10
  "mappings": ";AAYA,IAAM,E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C,EAAQ,EAAG,OAChB,KAAK,GAAW,KAAK,GAAQ,OAAO,CAAC,IAAM,EAAE,UAAY,CAAO,CAAC,GAIlE,SAAU,CAAC,IAAW,CACrB,GAAI,EAAc,KAAK,GAAM,WAAY,CAAM,GAEhD,eAAgB,CAAC,EAAO,EAAO,IAAY,CAC1C,GAAI,CAAC,EAAQ,EAAG,OAGhB,GAAI,IAAU,KAAK,GAAgB,OACnC,GAAI,EAAO,KAAK,GAAa,OAAO,EACpC,KAAK,KAAK,GAAa,UAAW,GAAW,EAAE,GAEhD,MAAO,CAAC,IAAU,CACjB,GAAI,EAAQ,EAAG,KAAK,GAAM,QAAS,CAAE,OAAM,CAAC,GAE7C,OAAQ,CAAC,EAA0B,IAAiB,CACnD,GAAI,CAAC,EAAQ,EAAG,OAGhB,GAAI,IAAW,WAAY,KAAK,GAAa,EAAe,GAG5D,IAAM,EAAa,KAAK,GASxB,GARA,KAAK,GAAc,OACnB,KAAK,GAAW,OAChB,KAAK,GAAgB,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",
11
- "debugId": "5F62BFF627E293BF64756E2164756E21",
11
+ "debugId": "56970BC4BF7A10E064756E2164756E21",
12
12
  "names": []
13
13
  }
@@ -0,0 +1,86 @@
1
+ class ue{#e=new Map;has(e,n){return this.#e.get(e)?.has(n)===!0}add(e,n){let t=this.#e.get(e)??new Set;t.add(n),this.#e.set(e,t)}keepGrants(e){let n=new Set(e);for(let t of this.#e.keys())if(!n.has(t))this.#e.delete(t)}keepTools(e){let n=new Set(e);for(let t of this.#e.values())for(let o of t)if(!n.has(o))t.delete(o)}}var U=0;function r(e,n,t={},...o){let a=e.createElement(n);if(t.className!==void 0)a.className=t.className;if(t.id!==void 0)a.id=t.id;if(t.text!==void 0)a.textContent=t.text;return a.append(...o),a}function w(e,n,t,o,a){let i=r(e,"button",{text:n});if(i.type="button",o!==void 0)i.classList.add(o);if(a!==void 0)i.classList.add(`tab-mcp-${a}`);return i.addEventListener("click",t),i}var Ve=`.tab-mcp-dialog {
2
+ --_tab-mcp-fg: var(--tab-mcp-color, CanvasText);
3
+ --_tab-mcp-bg: var(--tab-mcp-background, Canvas);
4
+ --_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));
5
+ --_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);
6
+ --_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));
7
+ --_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));
8
+ --_tab-mcp-success: var(--tab-mcp-success, light-dark(#1a7f37, #6fdd8b));
9
+ --_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
10
+ --_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);
11
+ box-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
12
+ font: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);
13
+ border: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);
14
+ padding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));
15
+ }
16
+ .tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }
17
+ .tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }
18
+ .tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }
19
+ .tab-mcp-dialog :where([hidden]) { display: none !important; }
20
+ html dialog.tab-mcp-dialog:where(:focus) { outline: none; }
21
+ .tab-mcp-dialog :where(*) { box-sizing: border-box; }
22
+ .tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }
23
+ .tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
24
+ .tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }
25
+ .tab-mcp-dialog :where(small) { font-size: 0.875em; }
26
+ .tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next) { color: var(--_tab-mcp-muted); }
27
+ html dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }
28
+ .tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }
29
+ html dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }
30
+ html dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }
31
+ html button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }
32
+ html button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }
33
+ html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }
34
+ .tab-mcp-copy { min-width: 6em; }
35
+ .tab-mcp-close { font-size: 0.875em; }
36
+ .tab-mcp-status { margin-top: -0.5rem; }
37
+ .tab-mcp-description:where(:empty) { display: none; }
38
+ .tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
39
+ .tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
40
+ .tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }
41
+ .tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
42
+ .tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }
43
+ .tab-mcp-code > :where(span) { font-weight: 600; }
44
+ .tab-mcp-code :where(br) { display: none; }
45
+ .tab-mcp-code :where(small) { grid-column: 1 / -1; }
46
+ .tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
47
+ .tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
48
+ .tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }
49
+ .tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }
50
+ .tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }
51
+ .tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
52
+ .tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }
53
+ .tab-mcp-help :where(li) { overflow-wrap: anywhere; }
54
+ .tab-mcp-help :where(strong) { display: block; font-weight: 600; }
55
+ .tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }
56
+ .tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
57
+ .tab-mcp-command-note { display: block; margin-top: 0.375rem; }
58
+ .tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
59
+ .tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
60
+ .tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }
61
+ .tab-mcp-apps-note { margin-top: 0.5rem; }
62
+ .tab-mcp-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }
63
+ .tab-mcp-success-icon { flex: none; width: 2.75rem; height: 2.75rem; color: var(--_tab-mcp-success); }
64
+ .tab-mcp-success-text { display: grid; gap: 0.125rem; min-width: 0; }
65
+ .tab-mcp-success-title { font-size: 1.125em; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
66
+ .tab-mcp-setup { display: flex; flex-direction: column; gap: 1rem; }
67
+ .tab-mcp-setup-toggle { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem; text-align: start; font-weight: 600; border-color: var(--_tab-mcp-line); }
68
+ .tab-mcp-setup-toggle::before { content: ""; flex: none; width: 0.45em; height: 0.45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateX(-0.1em) rotate(-45deg); }
69
+ .tab-mcp-setup-toggle:where([aria-expanded="true"])::before { transform: translateY(-0.15em) rotate(45deg); }
70
+ .tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }
71
+ .tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }
72
+ .tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }
73
+ .tab-mcp-close-note { flex: 1 1 12rem; }
74
+ .tab-mcp-confirm :where(p bdi) { font-weight: 600; }
75
+ .tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
76
+ .tab-mcp-always-note { font-size: 0.875em; }
77
+ @media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }
78
+ @media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } }
79
+ @media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }
80
+ @keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
81
+ @keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }
82
+ `,Pe=new WeakMap;function Fe(e){try{let n=Pe.get(e);if(n===void 0){let t=e.defaultView?.CSSStyleSheet;if(t===void 0||!Array.isArray(e.adoptedStyleSheets))return;n=new t,n.replaceSync(Ve),Pe.set(e,n)}if(!e.adoptedStyleSheets.includes(n))e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]}catch{}}function be(e,n,t,o,a,i,u){let d=w(e,"Copy",()=>{let m=()=>{d.textContent="Copied",d.setAttribute("aria-label",`Copied ${n}`),a(`${n[0]?.toUpperCase()}${n.slice(1)} copied`)},v=()=>{o(),a("Selected: copy it with Ctrl+C or ⌘C")},k=e.defaultView?.navigator?.clipboard;if(k!==void 0)k.writeText(t()).then(m,v);else v()},i,u);d.classList.add("tab-mcp-copy");let l=()=>{d.textContent="Copy",d.setAttribute("aria-label",`Copy ${n}`)};return l(),{button:d,reset:l}}function ye(e,n,t){let o=`tab-mcp-${++U}`,a=r(e,"dialog",{className:`tab-mcp-dialog ${n}`});a.setAttribute("aria-labelledby",`${o}-title`),Fe(e);let i=r(e,"h2",{id:`${o}-title`,text:t});return a.append(i),{dialog:a,heading:i}}var je=/[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Co}\p{Cn}\u0080-\u009F\u2028\u2029]/gu;function ve(e){return e.replace(je,(n)=>{let t="";for(let o=0;o<n.length;o++)t+=`\\u${n.charCodeAt(o).toString(16).toUpperCase().padStart(4,"0")}`;return t})}function ne(e){let n=ve(e.host||e.id);return e.name!==void 0&&e.name!==""?`${ve(e.name)} (${n})`:n}function j(e,n){let t=r(e,"bdi",{text:n});return t.dir="ltr",t}function Ue(e){try{return ve(JSON.stringify(e,null,2))}catch{return}}var Ye=750,Ke=500;function Xe(e){let n=typeof e==="number"&&Number.isFinite(e)&&e<2147483648?e:Ye;return Math.max(Ke,n)}function Je(e,n,t={}){let o=Xe(t.allowDelayMs);if(e.signal.aborted)return Promise.resolve("deny");let a=e.tool.title??e.tool.name,{dialog:i,heading:u}=ye(n,"tab-mcp-confirm","");u.append("Allow ",j(n,a),"?");let d=ne(e.client),l=w(n,"Don't allow",()=>i.close("deny"),"tab-mcp-deny","primary"),m=w(n,"Allow",()=>{if(!m.disabled)i.close("allow")},"tab-mcp-allow"),v=[m],k=r(n,"div",{className:"tab-mcp-actions"},l," ",m),P=[];if(t.alwaysAllow===!0){let g=w(n,"Always allow",()=>{if(!g.disabled)i.close("always")},"tab-mcp-always");v.push(g),k.append(" ",g),P.push(r(n,"p",{className:"tab-mcp-always-note"},"Always allow: ",j(n,a)," runs without asking for ",j(n,d)," until you reload this page or disconnect it."))}let z=(g)=>{for(let A of v)A.disabled=!g};z(!1);let S=Ue(e.arguments),y=r(n,"pre",{className:"tab-mcp-arguments",text:S??"The arguments cannot be shown, so this call cannot be allowed."});if(S===void 0)for(let g of[...v,...P])g.hidden=!0;y.dir="ltr",y.style.setProperty("white-space","pre-wrap"),y.style.setProperty("overflow-wrap","anywhere"),y.style.setProperty("max-height","var(--tab-mcp-arguments-height, 12rem)"),y.style.setProperty("overflow","auto"),y.hidden=Object.keys(e.arguments).length===0,i.append(r(n,"p",{},j(n,d)," wants to run ",j(n,a),"."),r(n,"p",{className:"tab-mcp-description",text:e.tool.description}),y,k,...P),n.body.append(i);let G=n.defaultView;return new Promise((g)=>{let A=()=>i.close("deny");e.signal.addEventListener("abort",A,{once:!0});let T,_=(N)=>{if(clearTimeout(T),T=void 0,z(!1),N?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;T=setTimeout(()=>z(!0),o)};n.addEventListener("visibilitychange",_),G?.addEventListener("focus",_),G?.addEventListener("blur",_),i.addEventListener("close",()=>{clearTimeout(T),n.removeEventListener("visibilitychange",_),G?.removeEventListener("focus",_),G?.removeEventListener("blur",_),e.signal.removeEventListener("abort",A);let N=i.returnValue;i.remove(),g(N==="allow"||N==="always"?N:"deny")},{once:!0}),i.showModal(),l.focus(),_()})}var ge=new WeakMap;function it(e,n,t,o){let{grantId:a}=n.client,i=n.tool.name;if(ge.get(e)?.has(a,i))return Promise.resolve(!0);return Je(n,t,o).then((u)=>{if(u==="always"&&e.grants.some((d)=>d.grantId===a)){let d=ge.get(e);if(d===void 0){let l=new ue;e.addEventListener("grantschange",(m)=>l.keepGrants(m.detail.grants.map((v)=>v.grantId))),e.addEventListener("toolschange",(m)=>l.keepTools(m.detail.tools)),ge.set(e,l),d=l}d.add(a,i)}return u!=="deny"})}function Qe(e){let n=e.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"");return n===""?"tools":n}function Ze(e){try{let n=new URL(e).href;return/^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(n)?n:void 0}catch{return}}var qe="https://ractive.ch/tab-mcp/connect/",fe="mcp_2026_07_28";function et(e,n){let t=Qe(e),o=Ze(n);return[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","On chatgpt.com: Plugins, add an MCP server with the address. In the Mac app: Settings → Plugins → MCPs → Add, type Streamable HTTP; it needs the Codex feature below."],o===void 0?["Claude Code","Add the address with claude mcp add --transport http."]:["Claude Code","Run:",`claude mcp add --transport http ${t} ${o}`],["Codex",...o===void 0?[`Run codex features enable ${fe}, then add the address with codex mcp add --url.`,void 0]:["Run:",`codex features enable ${fe}
83
+ codex mcp add ${t} --url ${o}`],["Start a new chat in Codex after it connects. The first line turns on a feature for all of Codex's MCP servers; ",`codex features disable ${fe}`," turns it off."]]]}function ze(e){return[...new Set(e.map((n)=>ne(n.client)))]}function Ge(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}var he=new WeakMap;function tt(e,n){let t=he.has(e);if(he.set(e,n),t)return;e.addEventListener("replaced",(o)=>{let a=he.get(e);if(a!==void 0&&e.state==="disconnected")nt(e,a,o.detail.sibling)})}function nt(e,n,t){n.querySelector("dialog.tab-mcp-replaced")?.close();let{dialog:o}=ye(n,"tab-mcp-replaced",t?"Opened in another tab":"Another tab or program took over this page"),a=r(n,"p",{className:"tab-mcp-status"});a.setAttribute("role","status"),a.hidden=!0;let i=w(n,"Close",()=>o.close(),"tab-mcp-replaced-close",t?"primary":void 0),u=r(n,"div",{className:"tab-mcp-actions"},i),d=i;if(!t){let l=w(n,"New address",()=>{l.disabled=!0,a.hidden=!1,a.textContent="Getting a new address…",e.newAddress().then(()=>{o.close(),e.showConnectDialog({document:n}).catch(()=>{})},(m)=>{l.disabled=!1,a.textContent=m?.reason==="replaced"?"It was taken over again before its AI apps were disconnected. Try again.":`Could not connect: ${m instanceof Error?m.message:String(m)}. Try again, or close this.`})},"tab-mcp-new-address","primary");u.append(" ",l),d=l}o.append(r(n,"p",{className:"tab-mcp-description",text:t?"This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.":"Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied its address. A new address disconnects every AI app from the old one; then add the new address to your AI apps again."}),a,u),o.addEventListener("close",()=>o.remove(),{once:!0}),n.body.append(o),o.showModal(),d.focus()}var at=1e4,we="http://www.w3.org/2000/svg";function st(e){let n=(i,u)=>{for(let[d,l]of Object.entries(u))i.setAttribute(d,l)},t=e.createElementNS(we,"svg");n(t,{class:"tab-mcp-success-icon",viewBox:"0 0 48 48",width:"44",height:"44","aria-hidden":"true",focusable:"false"});let o=e.createElementNS(we,"circle");n(o,{cx:"24",cy:"24",r:"24",fill:"currentColor","fill-opacity":"0.16"});let a=e.createElementNS(we,"path");return n(a,{d:"M14 24.5l7 7 13-14",fill:"none",stroke:"currentColor","stroke-width":"4","stroke-linecap":"round","stroke-linejoin":"round"}),t.append(o,a),t}function dt(e,n,t,o="tools"){let{dialog:a}=ye(t,"tab-mcp-connect","Connect your AI app");a.tabIndex=-1;let i=r(t,"p",{className:"tab-mcp-status",text:"Connecting…"});i.setAttribute("role","status");let u=r(t,"span",{className:"tab-mcp-announce"});u.setAttribute("aria-live","polite");for(let[s,p]of[["position","absolute"],["width","1px"],["height","1px"],["overflow","hidden"],["clip-path","inset(50%)"],["white-space","nowrap"]])u.style.setProperty(s,p);let d=(s)=>{u.textContent=u.textContent===s?`${s} `:s},l=`tab-mcp-${++U}-success`,m=r(t,"p",{className:"tab-mcp-success-title"}),v=r(t,"p",{className:"tab-mcp-success-next"}),k=r(t,"div",{className:"tab-mcp-success",id:l},st(t),r(t,"div",{className:"tab-mcp-success-text"},m,v)),P=`tab-mcp-${++U}-address`,z=r(t,"label",{text:"Add this address to your AI app:"});z.htmlFor=P;let S=r(t,"input",{id:P,className:"tab-mcp-address-input"});S.readOnly=!0;let{button:y,reset:G}=be(t,"address",()=>S.value,()=>S.select(),d,"tab-mcp-address-copy","primary"),g=w(t,"New address",()=>Oe(),"tab-mcp-new-address"),A=r(t,"div",{className:"tab-mcp-address"},z,S," ",y," ",g),T=`tab-mcp-${++U}-new-address`,_=r(t,"p",{id:T}),N=w(t,"Cancel",()=>{x.hidden=!0,g.focus()}),Re=w(t,"Disconnect and get new address",()=>Ne(),"tab-mcp-new-address-confirm","danger"),x=r(t,"div",{className:"tab-mcp-new-address-question"},_,r(t,"div",{className:"tab-mcp-actions"},N," ",Re));x.setAttribute("role","group"),x.setAttribute("aria-labelledby",T),x.hidden=!0;let I=r(t,"strong",{className:"tab-mcp-code-value"});I.style.setProperty("user-select","all"),I.style.setProperty("-webkit-user-select","all");let{button:xe,reset:He}=be(t,"code",()=>I.textContent??"",()=>t.getSelection()?.selectAllChildren(I),d,"tab-mcp-code-copy"),ae=r(t,"span",{},"When asked, enter the code ",I);ae.setAttribute("aria-live","polite");let Y=r(t,"span",{className:"tab-mcp-code-used"});Y.hidden=!0;let K=r(t,"p",{className:"tab-mcp-code"},ae,Y," ",xe,r(t,"br"),r(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."})),se=r(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."}),Ce=r(t,"ul"),X=r(t,"a",{text:"Step by step, and what to do when it fails"});X.href=qe,X.target="_blank",X.rel="noopener noreferrer";let J=r(t,"details",{className:"tab-mcp-help"},r(t,"summary",{text:"How do I add it?"}),Ce,r(t,"p",{className:"tab-mcp-guide"},X)),Ae=`tab-mcp-${++U}-setup`,_e=r(t,"div",{className:"tab-mcp-setup",id:Ae},A,x,K,se,J),W=!1,O=w(t,"Connect another app",()=>{W=!W,M(!1)},"tab-mcp-setup-toggle");O.setAttribute("aria-controls",Ae);let Q=r(t,"ul"),re=r(t,"p",{className:"tab-mcp-apps-note"}),oe=r(t,"div",{className:"tab-mcp-apps"},r(t,"h3",{text:"Connected"}),Q,re),ie=r(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."}),Z=w(t,"Close",()=>a.close(),"tab-mcp-close"),B=w(t,"Done",()=>a.close(),"tab-mcp-done","primary");B.hidden=!0;let We=r(t,"div",{className:"tab-mcp-actions"},ie," ",Z,B);a.append(k,i,oe,O,_e,We,u),k.hidden=!0,O.hidden=!0,A.hidden=!0,K.hidden=!0,se.hidden=!0,J.hidden=!0,oe.hidden=!0;let V=!1,F=new Set,b=!1,de=!1,ce=()=>b?B:Z,ke=()=>b?B:y,Se=(s)=>s!==null&&s!==a&&s!==t.body&&(!s.isConnected||a.contains(s)&&s.closest("[hidden]")!==null),M=(s,p=t.activeElement)=>{if(b=!V&&e.state==="connected"&&e.grants.length>0,s&&x.hidden)W=!1;if(b){let C=e.grants.filter((c)=>F.has(c.grantId)),f=ze(C.length>0?C:e.grants),E=f.length===1;m.textContent=`${Ge(f)} ${E?"is":"are"} connected`,v.textContent=`You can close this now and ask ${E?"it":"them"} to use the tools of this page.`,a.setAttribute("aria-describedby",l)}else a.removeAttribute("aria-describedby");if(k.hidden=!b,i.hidden=b,O.hidden=!b,O.setAttribute("aria-expanded",String(W)),_e.hidden=b&&!W,y.classList.toggle("tab-mcp-primary",!b),ie.hidden=b||!de,Z.hidden=b,B.hidden=!b,Se(p))ce().focus();if(s&&b)d(`${m.textContent}. ${v.textContent}`)},Ee=()=>{let s=ze(e.grants);if(s.length===0)return!1;return _.textContent=`A new address disconnects ${Ge(s)}. To use this page again, add the new address to ${s.length===1?"it":"them"}.`,!0},Oe=()=>{if(e.state!=="connected")return;if(!Ee()){Ne();return}x.hidden=!1,N.focus()},Ne=()=>{F.clear(),V=!0,i.textContent="Getting a new address…",M(!1),Z.focus(),x.hidden=!0,e.newAddress().then(()=>{V=!1,i.textContent="This is a new address. Add it to your AI app again.",M(!1),y.focus()},(s)=>{V=!1,i.textContent=`Could not connect: ${s instanceof Error?s.message:String(s)}. Close this and connect again.`,M(!1),ce().focus()})},Le,q=(s)=>{if(s===void 0){A.hidden=!0,x.hidden=!0,J.hidden=!0,M(!1);return}if(S.value!==s.address)S.value=s.address,G();let p=s.appName??e.appName;if(!V)i.textContent=p!==void 0?`${p} is ready for your AI app.`:"This page is ready for your AI app.";if(g.disabled=e.state!=="connected",A.hidden=!1,J.hidden=!1,M(!1),t.activeElement===a)ke().focus();if(Le===s.address)return;Le=s.address,Ce.replaceChildren(...et(o,s.address).map(([C,f,E,c])=>{let L=r(t,"li",{},r(t,"strong",{text:`${C}:`}),` ${f}`);if(E!==void 0){let h=r(t,"pre",{text:E});h.dir="ltr";let{button:me}=be(t,`${C} command`,()=>h.textContent??"",()=>t.getSelection()?.selectAllChildren(h),d,"tab-mcp-command-copy");L.append(r(t,"div",{className:"tab-mcp-command"},h,me))}if(c!==void 0)L.append(r(t,"small",{className:"tab-mcp-command-note"},...c.map((h,me)=>me%2===1?r(t,"code",{text:h}):h)));return L}))},le,D,ee=()=>{clearTimeout(D),D=void 0},Te=()=>{ee(),le=e.pairingCode,R()},R=()=>{let s=t.activeElement,p=e.pairingCode,C=e.session?.pairing==="oidc";if(p===void 0)ee();else if(p.code!==le?.code){if(p.reason==="used"){if(D===void 0)D=setTimeout(Te,at),d("Code used. Waiting for your AI app…")}else if(D!==void 0)ee()}let f=D!==void 0;if(!f){if(I.textContent!==(p?.code??""))He();I.textContent=p?.code??"",le=p}if(ae.hidden=f,xe.hidden=f,Y.hidden=!f,Y.textContent=f?"Code used. Waiting for your AI app…":"",K.hidden=C||p===void 0,se.hidden=!C,de=!K.hidden,ie.hidden=b||!de,Se(s))ce().focus()},te=new Map,Be=(s)=>{let p=w(t,"Disconnect",()=>{if(!e.revoke(s.grantId))H()},"tab-mcp-disconnect","danger");return{item:r(t,"li",{},r(t,"span",{className:"tab-mcp-app",text:`${ne(s.client)} connected `}),p),disconnect:p}},pe=new Set(e.grants.map((s)=>s.grantId)),Ie=e.session,H=()=>{if(e.session!==Ie){Ie=e.session;for(let c of e.grants)pe.add(c.grantId)}let s=!1;for(let c of e.grants){if(pe.has(c.grantId))continue;pe.add(c.grantId),i.textContent=`${ne(c.client)} is connected.`,F.add(c.grantId),s=!0}let p=new Set(e.grants.map((c)=>c.grantId));for(let c of F)if(!p.has(c))F.delete(c);let C=t.activeElement;for(let[c,{item:L}]of te){if(p.has(c))continue;L.remove(),te.delete(c)}let f=e.state==="connected";if(e.grants.forEach((c,L)=>{let h=te.get(c.grantId);if(h===void 0)h=Be(c),te.set(c.grantId,h);if(h.disconnect.disabled=!f,Q.children[L]!==h.item)Q.insertBefore(h.item,Q.children[L]??null)}),re.textContent=f?"":"To disconnect an app, connect this page again first.",re.hidden=f,oe.hidden=e.grants.length===0,!x.hidden&&!Ee())x.hidden=!0,g.focus();if(s&&D!==void 0)Te();let E=t.activeElement;M(s,E===null||E===t.body?C:E)},$e=(s)=>{if(s.detail.reason!=="new_address")i.textContent="Disconnected. AI apps can use this page again after you connect.";q(void 0),H(),R()},Me=()=>{q(e.session),H(),R()},De=()=>a.close();return tt(e,t),e.addEventListener("pairingcode",R),e.addEventListener("grantschange",H),e.addEventListener("connected",Me),e.addEventListener("disconnected",$e),e.addEventListener("replaced",De),t.body.append(a),e.startPairing(),H(),R(),q(e.session),n.then((s)=>q(s),(s)=>{i.textContent=`Could not connect: ${s instanceof Error?s.message:String(s)}`}),new Promise((s)=>{if(a.addEventListener("close",()=>{ee(),e.stopPairing(),e.removeEventListener("pairingcode",R),e.removeEventListener("grantschange",H),e.removeEventListener("connected",Me),e.removeEventListener("disconnected",$e),e.removeEventListener("replaced",De),a.remove(),s()},{once:!0}),a.showModal(),b||!A.hidden)ke().focus();else a.focus()})}export{it as confirmInPage,dt as showConnectDialog};
84
+
85
+ //# debugId=0E9614E5BB974C0864756E2164756E21
86
+ //# sourceMappingURL=ui-0wa4gyh3.min.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/always-allowed.ts", "../../src/ui.ts"],
4
+ "sourcesContent": [
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 default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, all text set with `textContent`, styled by one constructed\n * stylesheet (`DIALOG_CSS`) that pages adjust through `--tab-mcp-*` custom\n * properties or their own CSS. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tPairingCode,\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\n/**\n * A button. `className` is its own class; `kind` marks the one next step\n * (`tab-mcp-primary`) or one that disconnects (`tab-mcp-danger`); without\n * one it is a plain, outlined button.\n */\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n\tclassName?: string,\n\tkind?: \"primary\" | \"danger\",\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tif (className !== undefined) node.classList.add(className);\n\tif (kind !== undefined) node.classList.add(`tab-mcp-${kind}`);\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/**\n * The look of both dialogs. Every selector has the specificity of one class\n * (the rest is in `:where()`), so rules of the page for elements, such as\n * `button { … }` or a reset's `* { border-width: 0 }`, do not change the\n * dialogs. The rules for states (hover, focus, disabled) and the primary\n * and danger buttons add two elements (`html dialog.…`, `html button.…`),\n * so `button:hover`, `button:focus` or `button:disabled` of the page do not\n * either. A rule with two classes, such as `.tab-mcp-dialog .tab-mcp-primary`,\n * wins over all of them. The `--tab-mcp-*`\n * custom properties (on `:root` or on `.tab-mcp-dialog`) change single\n * values; the library only reads them. The defaults use system colours and the\n * page's `color-scheme`, so the dialogs follow its light or dark scheme. The\n * `--_tab-mcp-*` properties are internal. Order matters among equals.\n */\nexport const DIALOG_CSS = `.tab-mcp-dialog {\n--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);\n--_tab-mcp-bg: var(--tab-mcp-background, Canvas);\n--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));\n--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);\n--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));\n--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));\n--_tab-mcp-success: var(--tab-mcp-success, light-dark(#1a7f37, #6fdd8b));\n--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);\nbox-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;\nfont: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);\nborder: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);\npadding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));\n}\n.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }\n.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }\n.tab-mcp-dialog :where([hidden]) { display: none !important; }\nhtml dialog.tab-mcp-dialog:where(:focus) { outline: none; }\n.tab-mcp-dialog :where(*) { box-sizing: border-box; }\n.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }\n.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }\n.tab-mcp-dialog :where(small) { font-size: 0.875em; }\n.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next) { color: var(--_tab-mcp-muted); }\nhtml dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }\n.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }\nhtml dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }\nhtml dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }\nhtml button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }\nhtml button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }\nhtml button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }\n.tab-mcp-copy { min-width: 6em; }\n.tab-mcp-close { font-size: 0.875em; }\n.tab-mcp-status { margin-top: -0.5rem; }\n.tab-mcp-description:where(:empty) { display: none; }\n.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }\n.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }\n.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }\n.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code > :where(span) { font-weight: 600; }\n.tab-mcp-code :where(br) { display: none; }\n.tab-mcp-code :where(small) { grid-column: 1 / -1; }\n.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }\n.tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }\n.tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }\n.tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }\n.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }\n.tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }\n.tab-mcp-help :where(li) { overflow-wrap: anywhere; }\n.tab-mcp-help :where(strong) { display: block; font-weight: 600; }\n.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }\n.tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-command-note { display: block; margin-top: 0.375rem; }\n.tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }\n.tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }\n.tab-mcp-apps-note { margin-top: 0.5rem; }\n.tab-mcp-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-success-icon { flex: none; width: 2.75rem; height: 2.75rem; color: var(--_tab-mcp-success); }\n.tab-mcp-success-text { display: grid; gap: 0.125rem; min-width: 0; }\n.tab-mcp-success-title { font-size: 1.125em; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-setup { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-setup-toggle { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem; text-align: start; font-weight: 600; border-color: var(--_tab-mcp-line); }\n.tab-mcp-setup-toggle::before { content: \"\"; flex: none; width: 0.45em; height: 0.45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateX(-0.1em) rotate(-45deg); }\n.tab-mcp-setup-toggle:where([aria-expanded=\"true\"])::before { transform: translateY(-0.15em) rotate(45deg); }\n.tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }\n.tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }\n.tab-mcp-close-note { flex: 1 1 12rem; }\n.tab-mcp-confirm :where(p bdi) { font-weight: 600; }\n.tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-always-note { font-size: 0.875em; }\n@media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }\n@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } }\n@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }\n@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }\n@keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }\n`;\n\nconst sheets = new WeakMap<Document, CSSStyleSheet>();\n\n/**\n * Adopts `DIALOG_CSS` into the document once, next to the page's own adopted\n * sheets. A constructed stylesheet needs no `style-src` exception under a\n * strict CSP. Where constructed stylesheets are not supported, the dialogs\n * keep the browser's default look and work the same.\n */\nfunction adoptStyles(doc: Document): void {\n\ttry {\n\t\tlet sheet = sheets.get(doc);\n\t\tif (sheet === undefined) {\n\t\t\tconst Sheet = (doc.defaultView as (Window & typeof globalThis) | null)\n\t\t\t\t?.CSSStyleSheet;\n\t\t\tif (Sheet === undefined || !Array.isArray(doc.adoptedStyleSheets)) return;\n\t\t\tsheet = new Sheet();\n\t\t\tsheet.replaceSync(DIALOG_CSS);\n\t\t\tsheets.set(doc, sheet);\n\t\t}\n\t\t// The page may have replaced the list since.\n\t\tif (!doc.adoptedStyleSheets.includes(sheet))\n\t\t\tdoc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];\n\t} catch {\n\t\t// Not supported: the default look.\n\t}\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; `announce`\n * says what happened (\"Code copied\", or that the text is selected).\n */\nfunction copyButton(\n\tdoc: Document,\n\tnoun: string,\n\tvalue: () => string,\n\tselect: () => void,\n\tannounce: (text: string) => void,\n\tclassName: string,\n\tkind?: \"primary\",\n): { button: HTMLButtonElement; reset: () => void } {\n\tconst node = button(\n\t\tdoc,\n\t\t\"Copy\",\n\t\t() => {\n\t\t\tconst done = () => {\n\t\t\t\tnode.textContent = \"Copied\";\n\t\t\t\tnode.setAttribute(\"aria-label\", `Copied ${noun}`);\n\t\t\t\tannounce(`${noun[0]?.toUpperCase()}${noun.slice(1)} copied`);\n\t\t\t};\n\t\t\tconst selected = () => {\n\t\t\t\tselect();\n\t\t\t\tannounce(\"Selected: copy it with Ctrl+C or ⌘C\");\n\t\t\t};\n\t\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t\t?.clipboard;\n\t\t\tif (clipboard !== undefined)\n\t\t\t\tclipboard.writeText(value()).then(done, selected);\n\t\t\telse selected();\n\t\t},\n\t\tclassName,\n\t\tkind,\n\t);\n\t// The same width for \"Copy\" and \"Copied\": nothing moves.\n\tnode.classList.add(\"tab-mcp-copy\");\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\tadoptStyles(doc);\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\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. \"Always allow\" is offered only\n * with `alwaysAllow` (DEC-096). \"Allow\" and \"Always allow\" stay disabled\n * until the page has been visible and focused for `allowDelayMs` (default\n * 750, at least 500) while the dialog is open, so a click meant for the page,\n * or the click that brings the tab or window back, cannot approve. Leaving\n * the page disables them again. Everything else (Don't allow, Escape, an\n * aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number | undefined; alwaysAllow?: boolean } = {},\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\t// The safe choice is the default: focused, and the one that stands out.\n\tconst deny = button(\n\t\tdoc,\n\t\t\"Don't allow\",\n\t\t() => dialog.close(\"deny\"),\n\t\t\"tab-mcp-deny\",\n\t\t\"primary\",\n\t);\n\tconst allow = button(\n\t\tdoc,\n\t\t\"Allow\",\n\t\t() => {\n\t\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t\t},\n\t\t\"tab-mcp-allow\",\n\t);\n\t// The approving buttons: Allow, and Always allow when the page offers it.\n\tconst approve = [allow];\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);\n\tconst extra: HTMLElement[] = [];\n\tif (options.alwaysAllow === true) {\n\t\tconst always = button(\n\t\t\tdoc,\n\t\t\t\"Always allow\",\n\t\t\t() => {\n\t\t\t\tif (!always.disabled) dialog.close(\"always\");\n\t\t\t},\n\t\t\t\"tab-mcp-always\",\n\t\t);\n\t\tapprove.push(always);\n\t\tactions.append(\" \", always);\n\t\textra.push(\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"p\",\n\t\t\t\t{ className: \"tab-mcp-always-note\" },\n\t\t\t\t\"Always allow: \",\n\t\t\t\tname(doc, title),\n\t\t\t\t\" runs without asking for \",\n\t\t\t\tname(doc, client),\n\t\t\t\t\" until you reload this page or disconnect it.\",\n\t\t\t),\n\t\t);\n\t}\n\tconst enable = (on: boolean) => {\n\t\tfor (const b of approve) b.disabled = !on;\n\t};\n\tenable(false);\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\tfor (const node of [...approve, ...extra]) node.hidden = true;\n\t}\n\targs.dir = \"ltr\";\n\t// Inline, so the arguments stay readable in full without the stylesheet:\n\t// wrapped (also a long word, at 360 px), scrolling when long.\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"overflow-wrap\", \"anywhere\");\n\targs.style.setProperty(\n\t\t\"max-height\",\n\t\t\"var(--tab-mcp-arguments-height, 12rem)\",\n\t);\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\t...extra,\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\tenable(false);\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(() => enable(true), 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\n/** The tools a user chose \"Always allow\" for, per `TabMcp`. */\nconst allowedAlways = new WeakMap<TabMcp, AlwaysAllowed>();\n\n/**\n * `TabMcp.confirmInPage`: the confirmation, and the tools allowed always. An\n * entry goes when its grant goes or its tool is unregistered, so a re-paired\n * app or a new tool under the same name is asked again.\n */\nexport function confirmInPage(\n\tmcp: TabMcp,\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number | undefined; alwaysAllow?: boolean },\n): Promise<boolean> {\n\tconst { grantId } = request.client;\n\tconst tool = request.tool.name;\n\tif (allowedAlways.get(mcp)?.has(grantId, tool)) return Promise.resolve(true);\n\treturn confirmDialog(request, doc, options).then((answer) => {\n\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\tif (answer === \"always\" && mcp.grants.some((g) => g.grantId === grantId)) {\n\t\t\tlet allowed = allowedAlways.get(mcp);\n\t\t\tif (allowed === undefined) {\n\t\t\t\tconst kept = new AlwaysAllowed();\n\t\t\t\tmcp.addEventListener(\"grantschange\", (e) =>\n\t\t\t\t\tkept.keepGrants(e.detail.grants.map((g) => g.grantId)),\n\t\t\t\t);\n\t\t\t\tmcp.addEventListener(\"toolschange\", (e) =>\n\t\t\t\t\tkept.keepTools(e.detail.tools),\n\t\t\t\t);\n\t\t\t\tallowedAlways.set(mcp, kept);\n\t\t\t\tallowed = kept;\n\t\t\t}\n\t\t\tallowed.add(grantId, tool);\n\t\t}\n\t\treturn answer !== \"deny\";\n\t});\n}\n\n/**\n * The server's name as a label that every shell (POSIX shells, PowerShell,\n * cmd.exe) reads as one plain word, so it needs no quoting: letters without\n * their marks (\"Bücher\" → \"bucher\"), lower case, each run of anything but\n * a-z, 0-9, _ and - as one \"-\", no \"-\" at either end (no option), at most 40\n * characters; \"tools\" when nothing is left. The page names its server, but\n * the command runs in the user's shell: nothing of the name may be quoted\n * text (review of PR 34).\n */\nexport function commandName(name: string): string {\n\tconst label = name\n\t\t.normalize(\"NFKD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_-]+/g, \"-\")\n\t\t.replace(/-{2,}/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 40)\n\t\t.replace(/-+$/, \"\");\n\treturn label === \"\" ? \"tools\" : label;\n}\n\n/**\n * The address for a command, only when all of it is plain in every shell\n * (http or https, letters, digits and . : [ ] / _ ~ -); else `undefined`, and\n * the help shows the steps without commands. The relay's addresses are.\n */\nexport function commandAddress(address: string): string | undefined {\n\ttry {\n\t\tconst href = new URL(address).href;\n\t\treturn /^https?:\\/\\/[A-Za-z0-9.:[\\]/_~-]+$/.test(href) ? href : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The guide for every AI app (its source is on ractive.ch). */\nconst GUIDE = \"https://ractive.ch/tab-mcp/connect/\";\n\n/** Codex's feature for MCP 2026-07-28, which the relay speaks; off by default in Codex 0.163. */\nconst CODEX_FEATURE = \"mcp_2026_07_28\";\n\n/**\n * Per AI app: its name, what to do, a command to run (one per line), and a\n * note after it, alternating text and code. `name` is the page's server name.\n */\nexport function instructions(\n\tname: string,\n\taddress: string,\n): [string, string, (string | undefined)?, string[]?][] {\n\tconst n = commandName(name);\n\tconst a = commandAddress(address);\n\treturn [\n\t\t[\n\t\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t\t],\n\t\t[\n\t\t\t\"ChatGPT\",\n\t\t\t\"On chatgpt.com: Plugins, add an MCP server with the address. In the Mac app: Settings → Plugins → MCPs → Add, type Streamable HTTP; it needs the Codex feature below.\",\n\t\t],\n\t\ta === undefined\n\t\t\t? [\"Claude Code\", \"Add the address with claude mcp add --transport http.\"]\n\t\t\t: [\"Claude Code\", \"Run:\", `claude mcp add --transport http ${n} ${a}`],\n\t\t[\n\t\t\t\"Codex\",\n\t\t\t...((a === undefined\n\t\t\t\t? [\n\t\t\t\t\t\t`Run codex features enable ${CODEX_FEATURE}, then add the address with codex mcp add --url.`,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t\"Run:\",\n\t\t\t\t\t\t`codex features enable ${CODEX_FEATURE}\\ncodex mcp add ${n} --url ${a}`,\n\t\t\t\t\t]) as [string, string | undefined]),\n\t\t\t[\n\t\t\t\t\"Start a new chat in Codex after it connects. The first line turns on a feature for all of Codex's MCP servers; \",\n\t\t\t\t`codex features disable ${CODEX_FEATURE}`,\n\t\t\t\t\" turns it off.\",\n\t\t\t],\n\t\t],\n\t];\n}\n\n/**\n * The labels of the apps behind these grants, each once: an app can hold\n * more than one grant (paired twice), and is still one app.\n */\nfunction appLabels(grants: readonly Grant[]): string[] {\n\treturn [...new Set(grants.map((g) => clientLabel(g.client)))];\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/** The document of the connect dialog per `TabMcp`, once it was opened. */\nconst watched = new WeakMap<TabMcp, Document>();\n\n/**\n * Once a page has opened the connect dialog, the default UI also says when\n * the page loses its address (`replaced`), in that dialog's document.\n */\nfunction watchReplaced(mcp: TabMcp, doc: Document): void {\n\tconst known = watched.has(mcp);\n\twatched.set(mcp, doc);\n\tif (known) return;\n\tmcp.addEventListener(\"replaced\", (event) => {\n\t\tconst current = watched.get(mcp);\n\t\t// Not when the page already went on (a New address or connect since).\n\t\tif (current !== undefined && mcp.state === \"disconnected\")\n\t\t\treplacedNotice(mcp, current, event.detail.sibling);\n\t});\n}\n\n/**\n * Says that the page lost its address (`replaced`, DEC-095). A sibling tab\n * that announced it: \"Opened in another tab\", nothing to do. Otherwise a\n * warning that another tab or program took over, with \"New address\", which\n * takes the address back, disconnects its apps, connects with a new one and\n * opens the connect dialog to add it to the AI apps again.\n */\nexport function replacedNotice(\n\tmcp: TabMcp,\n\tdoc: Document,\n\tsibling: boolean,\n): void {\n\t(\n\t\tdoc.querySelector(\"dialog.tab-mcp-replaced\") as HTMLDialogElement | null\n\t)?.close();\n\tconst { dialog } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-replaced\",\n\t\tsibling\n\t\t\t? \"Opened in another tab\"\n\t\t\t: \"Another tab or program took over this page\",\n\t);\n\tconst status = el(doc, \"p\", { className: \"tab-mcp-status\" });\n\tstatus.setAttribute(\"role\", \"status\");\n\tstatus.hidden = true;\n\tconst close = button(\n\t\tdoc,\n\t\t\"Close\",\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-replaced-close\",\n\t\tsibling ? \"primary\" : undefined,\n\t);\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\tlet first = close;\n\tif (!sibling) {\n\t\tconst fresh = button(\n\t\t\tdoc,\n\t\t\t\"New address\",\n\t\t\t() => {\n\t\t\t\tfresh.disabled = true;\n\t\t\t\tstatus.hidden = false;\n\t\t\t\tstatus.textContent = \"Getting a new address…\";\n\t\t\t\tmcp.newAddress().then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdialog.close();\n\t\t\t\t\t\tmcp.showConnectDialog({ document: doc }).catch(() => {});\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tfresh.disabled = false;\n\t\t\t\t\t\tstatus.textContent =\n\t\t\t\t\t\t\t(error as { reason?: unknown } | null)?.reason === \"replaced\"\n\t\t\t\t\t\t\t\t? \"It was taken over again before its AI apps were disconnected. Try again.\"\n\t\t\t\t\t\t\t\t: `Could not connect: ${error instanceof Error ? error.message : String(error)}. Try again, or close this.`;\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"tab-mcp-new-address\",\n\t\t\t\"primary\",\n\t\t);\n\t\tactions.append(\" \", fresh);\n\t\tfirst = fresh;\n\t}\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: sibling\n\t\t\t\t? \"This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.\"\n\t\t\t\t: \"Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied its address. A new address disconnects every AI app from the old one; then add the new address to your AI apps again.\",\n\t\t}),\n\t\tstatus,\n\t\tactions,\n\t);\n\tdialog.addEventListener(\"close\", () => dialog.remove(), { once: true });\n\tdoc.body.append(dialog);\n\tdialog.showModal();\n\tfirst.focus();\n}\n\n/**\n * How long a used code stays \"Code used\" before its replacement is shown: the\n * AI app connects a moment after the code was entered (its token request), and\n * a new code in plain view meanwhile looks as if it did not work. Only when\n * the relay says the code was used (`reason: \"used\"`); a relay that does not\n * say why gets the new code shown at once.\n */\nexport const CODE_USED_WAIT_MS = 10_000;\n\nconst SVG = \"http://www.w3.org/2000/svg\";\n\n/** A check mark in a tinted disk, in the text colour (`currentColor`). */\nfunction checkIcon(doc: Document): SVGSVGElement {\n\tconst set = (node: Element, attributes: Record<string, string>) => {\n\t\tfor (const [key, value] of Object.entries(attributes))\n\t\t\tnode.setAttribute(key, value);\n\t};\n\tconst svg = doc.createElementNS(SVG, \"svg\");\n\tset(svg, {\n\t\tclass: \"tab-mcp-success-icon\",\n\t\tviewBox: \"0 0 48 48\",\n\t\twidth: \"44\",\n\t\theight: \"44\",\n\t\t\"aria-hidden\": \"true\",\n\t\tfocusable: \"false\",\n\t});\n\tconst disk = doc.createElementNS(SVG, \"circle\");\n\tset(disk, {\n\t\tcx: \"24\",\n\t\tcy: \"24\",\n\t\tr: \"24\",\n\t\tfill: \"currentColor\",\n\t\t\"fill-opacity\": \"0.16\",\n\t});\n\tconst check = doc.createElementNS(SVG, \"path\");\n\tset(check, {\n\t\td: \"M14 24.5l7 7 13-14\",\n\t\tfill: \"none\",\n\t\tstroke: \"currentColor\",\n\t\t\"stroke-width\": \"4\",\n\t\t\"stroke-linecap\": \"round\",\n\t\t\"stroke-linejoin\": \"round\",\n\t});\n\tsvg.append(disk, check);\n\treturn svg;\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 * is connected, only a small Close (and Escape) close it. Once one is (it\n * pairs here, or was paired when the dialog opened), a confirmation with a\n * check mark leads, the setup moves behind \"Connect another app\" and Done is\n * the primary button. New address asks first when it would disconnect\n * connected apps (`newAddress()` revokes them). When the page loses its\n * address (`replaced`), this dialog closes and `replacedNotice` says why,\n * from then on also while it is closed. Its nodes are built once and shown or\n * hidden, not rebuilt on a change, so nothing flickers and focus stays.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n\tserverName = \"tools\",\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\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\t// What a Copy did, for assistive technology only; out of sight, also\n\t// without the stylesheet. The same message twice is still a change.\n\tconst live = el(doc, \"span\", { className: \"tab-mcp-announce\" });\n\tlive.setAttribute(\"aria-live\", \"polite\");\n\tfor (const [property, value] of [\n\t\t[\"position\", \"absolute\"],\n\t\t[\"width\", \"1px\"],\n\t\t[\"height\", \"1px\"],\n\t\t[\"overflow\", \"hidden\"],\n\t\t[\"clip-path\", \"inset(50%)\"],\n\t\t[\"white-space\", \"nowrap\"],\n\t])\n\t\tlive.style.setProperty(property as string, value as string);\n\tconst announce = (text: string) => {\n\t\tlive.textContent = live.textContent === text ? `${text} ` : text;\n\t};\n\n\t// The confirmation once an app is connected: what happened, what next.\n\tconst successId = `tab-mcp-${++counter}-success`;\n\tconst successTitle = el(doc, \"p\", { className: \"tab-mcp-success-title\" });\n\tconst successNext = el(doc, \"p\", { className: \"tab-mcp-success-next\" });\n\tconst success = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-success\", id: successId },\n\t\tcheckIcon(doc),\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-success-text\" },\n\t\t\tsuccessTitle,\n\t\t\tsuccessNext,\n\t\t),\n\t);\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\t// Copying the address is the first step: the primary button, until an\n\t// app is connected (then Done is).\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\tannounce,\n\t\t\"tab-mcp-address-copy\",\n\t\t\"primary\",\n\t);\n\tconst fresh = button(\n\t\tdoc,\n\t\t\"New address\",\n\t\t() => askNewAddress(),\n\t\t\"tab-mcp-new-address\",\n\t);\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(\n\t\tdoc,\n\t\t\"Disconnect and get new address\",\n\t\t() => getNewAddress(),\n\t\t\"tab-mcp-new-address-confirm\",\n\t\t\"danger\",\n\t);\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\t// Large, in a monospace font: a new code takes the same room.\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\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\tannounce,\n\t\t\"tab-mcp-code-copy\",\n\t);\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\t// In the code's place while the AI app finishes connecting with it.\n\tconst codeUsed = el(doc, \"span\", { className: \"tab-mcp-code-used\" });\n\tcodeUsed.hidden = true;\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\tcodeUsed,\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 guide = el(doc, \"a\", {\n\t\ttext: \"Step by step, and what to do when it fails\",\n\t});\n\tguide.href = GUIDE;\n\tguide.target = \"_blank\";\n\tguide.rel = \"noopener noreferrer\";\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\tel(doc, \"p\", { className: \"tab-mcp-guide\" }, guide),\n\t);\n\n\t// Everything for adding the page to an AI app. Once one is connected, it\n\t// is behind \"Connect another app\", closed: the next code is not news.\n\tconst setupId = `tab-mcp-${++counter}-setup`;\n\tconst setup = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-setup\", id: setupId },\n\t\taddressBox,\n\t\tconfirmBox,\n\t\tcodeLine,\n\t\tsignInLine,\n\t\thelp,\n\t);\n\t// Whether the user opened it while an app is connected.\n\tlet expanded = false;\n\tconst setupToggle = button(\n\t\tdoc,\n\t\t\"Connect another app\",\n\t\t() => {\n\t\t\texpanded = !expanded;\n\t\t\trenderView(false);\n\t\t},\n\t\t\"tab-mcp-setup-toggle\",\n\t);\n\tsetupToggle.setAttribute(\"aria-controls\", setupId);\n\n\tconst appList = el(doc, \"ul\");\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\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\tappsNote,\n\t);\n\n\t// Until an app is connected, closing it is not the next step: a small\n\t// Close at the end, saying what closing does (the code stops, the address\n\t// stays). Once one is, 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(), \"tab-mcp-close\");\n\tconst done = button(\n\t\tdoc,\n\t\t\"Done\",\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-done\",\n\t\t\"primary\",\n\t);\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\n\tdialog.append(success, status, apps, setupToggle, setup, actions, live);\n\tsuccess.hidden = true;\n\tsetupToggle.hidden = true;\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// Grants of apps that connected while this dialog is open (since the last\n\t// new address), and are still connected: the confirmation names them.\n\tconst pairedGrants = new Set<string>();\n\t// Whether the dialog shows the connected state: an app is connected.\n\tlet connectedView = false;\n\t// Whether a code is shown (or \"Code used\" in its place).\n\tlet codeShown = false;\n\t// The visible button that closes the dialog.\n\tconst closer = () => (connectedView ? done : close);\n\t// Where focus starts: Done once connected, else the address's Copy.\n\tconst start = () => (connectedView ? done : copy);\n\t/** Whether focus was on a control that is no longer shown, or no longer there. */\n\tconst focusLost = (focused: Element | null): boolean =>\n\t\tfocused !== null &&\n\t\tfocused !== dialog &&\n\t\tfocused !== doc.body &&\n\t\t(!focused.isConnected ||\n\t\t\t(dialog.contains(focused) && focused.closest(\"[hidden]\") !== null));\n\t/**\n\t * Shows the setup or the connected state. `paired`: an app just connected\n\t * here, so the setup closes again (unless the New address question is\n\t * open in it) and the confirmation is announced.\n\t */\n\tconst renderView = (paired: boolean, focused = doc.activeElement) => {\n\t\tconnectedView =\n\t\t\t!renewing && mcp.state === \"connected\" && mcp.grants.length > 0;\n\t\tif (paired && confirmBox.hidden) expanded = false;\n\t\tif (connectedView) {\n\t\t\tconst here = mcp.grants.filter((g) => pairedGrants.has(g.grantId));\n\t\t\tconst names = appLabels(here.length > 0 ? here : mcp.grants);\n\t\t\tconst one = names.length === 1;\n\t\t\tsuccessTitle.textContent = `${listOf(names)} ${one ? \"is\" : \"are\"} connected`;\n\t\t\tsuccessNext.textContent = `You can close this now and ask ${one ? \"it\" : \"them\"} to use the tools of this page.`;\n\t\t\tdialog.setAttribute(\"aria-describedby\", successId);\n\t\t} else dialog.removeAttribute(\"aria-describedby\");\n\t\tsuccess.hidden = !connectedView;\n\t\t// The confirmation says it; the status line is for the setup.\n\t\tstatus.hidden = connectedView;\n\t\tsetupToggle.hidden = !connectedView;\n\t\tsetupToggle.setAttribute(\"aria-expanded\", String(expanded));\n\t\tsetup.hidden = connectedView && !expanded;\n\t\tcopy.classList.toggle(\"tab-mcp-primary\", !connectedView);\n\t\t// The note is about the code: only while one is shown and none connected.\n\t\tcloseNote.hidden = connectedView || !codeShown;\n\t\tclose.hidden = connectedView;\n\t\tdone.hidden = !connectedView;\n\t\t// Focus never stays on a control that was just hidden or removed.\n\t\tif (focusLost(focused)) closer().focus();\n\t\tif (paired && connectedView)\n\t\t\tannounce(`${successTitle.textContent}. ${successNext.textContent}`);\n\t};\n\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = appLabels(mcp.grants);\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\tpairedGrants.clear();\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\trenderView(false);\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\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\trenderView(false);\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\trenderView(false);\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\t// The address the help's commands were made for.\n\tlet stepsFor: string | undefined;\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\trenderView(false);\n\t\t\treturn;\n\t\t}\n\t\t// The same address again (a reconnect): it stays as it is.\n\t\tif (address.value !== session.address) {\n\t\t\taddress.value = session.address;\n\t\t\tresetCopy();\n\t\t}\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\thelp.hidden = false;\n\t\trenderView(false);\n\t\t// Opened before the session was known: start at Done or the address's Copy.\n\t\tif (doc.activeElement === dialog) start().focus();\n\t\tif (stepsFor === session.address) return;\n\t\tstepsFor = session.address;\n\t\tsteps.replaceChildren(\n\t\t\t...instructions(serverName, session.address).map(\n\t\t\t\t([app, how, command, note]) => {\n\t\t\t\t\tconst item = el(\n\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\"li\",\n\t\t\t\t\t\t{},\n\t\t\t\t\t\tel(doc, \"strong\", { text: `${app}:` }),\n\t\t\t\t\t\t` ${how}`,\n\t\t\t\t\t);\n\t\t\t\t\tif (command !== undefined) {\n\t\t\t\t\t\t// A block with its own Copy, like the code.\n\t\t\t\t\t\tconst text = el(doc, \"pre\", { text: command });\n\t\t\t\t\t\ttext.dir = \"ltr\";\n\t\t\t\t\t\tconst { button: copyCommand } = copyButton(\n\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t`${app} command`,\n\t\t\t\t\t\t\t() => text.textContent ?? \"\",\n\t\t\t\t\t\t\t() => doc.getSelection()?.selectAllChildren(text),\n\t\t\t\t\t\t\tannounce,\n\t\t\t\t\t\t\t\"tab-mcp-command-copy\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"div\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command\" },\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tcopyCommand,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (note !== undefined)\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"small\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command-note\" },\n\t\t\t\t\t\t\t\t...note.map((part, i) =>\n\t\t\t\t\t\t\t\t\ti % 2 === 1 ? el(doc, \"code\", { text: part }) : part,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\treturn item;\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t};\n\n\t// The code shown, and the wait after it was used (until the app connects).\n\tlet shownCode: PairingCode | undefined;\n\tlet usedTimer: ReturnType<typeof setTimeout> | undefined;\n\tconst stopWaiting = () => {\n\t\tclearTimeout(usedTimer);\n\t\tusedTimer = undefined;\n\t};\n\t// The wait is over (the app connected, or none did): the next code shows.\n\tconst endWait = () => {\n\t\tstopWaiting();\n\t\tshownCode = mcp.pairingCode;\n\t\trenderCode();\n\t};\n\tconst renderCode = () => {\n\t\tconst focused = doc.activeElement;\n\t\tconst current = mcp.pairingCode;\n\t\tconst oidc = mcp.session?.pairing === \"oidc\";\n\t\tif (current === undefined) stopWaiting();\n\t\telse if (current.code !== shownCode?.code) {\n\t\t\tif (current.reason === \"used\") {\n\t\t\t\t// Entered just now: no new code in plain view while the AI app\n\t\t\t\t// connects; it shows if none does.\n\t\t\t\tif (usedTimer === undefined) {\n\t\t\t\t\tusedTimer = setTimeout(endWait, CODE_USED_WAIT_MS);\n\t\t\t\t\tannounce(\"Code used. Waiting for your AI app…\");\n\t\t\t\t}\n\t\t\t} else if (usedTimer !== undefined) {\n\t\t\t\t// Locked or expired meanwhile: the user needs this one now.\n\t\t\t\tstopWaiting();\n\t\t\t}\n\t\t}\n\t\tconst used = usedTimer !== undefined;\n\t\tif (!used) {\n\t\t\t// A new code is not copied yet.\n\t\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\t\tcode.textContent = current?.code ?? \"\";\n\t\t\tshownCode = current;\n\t\t}\n\t\tcodeSentence.hidden = used;\n\t\tcopyCode.hidden = used;\n\t\tcodeUsed.hidden = !used;\n\t\tcodeUsed.textContent = used ? \"Code used. Waiting for your AI app…\" : \"\";\n\t\tcodeLine.hidden = oidc || current === undefined;\n\t\tsignInLine.hidden = !oidc;\n\t\tcodeShown = !codeLine.hidden;\n\t\tcloseNote.hidden = connectedView || !codeShown;\n\t\t// The code's Copy had the focus: to the button that closes.\n\t\tif (focusLost(focused)) closer().focus();\n\t};\n\n\t// One item per grant, kept while the grant is: a change adds or removes\n\t// items, and a focused Disconnect keeps its focus.\n\tconst items = new Map<\n\t\tstring,\n\t\t{ item: HTMLLIElement; disconnect: HTMLButtonElement }\n\t>();\n\tconst appItem = (grant: Grant) => {\n\t\tconst disconnect = button(\n\t\t\tdoc,\n\t\t\t\"Disconnect\",\n\t\t\t() => {\n\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t},\n\t\t\t\"tab-mcp-disconnect\",\n\t\t\t\"danger\",\n\t\t);\n\t\tconst item = el(\n\t\t\tdoc,\n\t\t\t\"li\",\n\t\t\t{},\n\t\t\tel(doc, \"span\", {\n\t\t\t\tclassName: \"tab-mcp-app\",\n\t\t\t\ttext: `${clientLabel(grant.client)} connected `,\n\t\t\t}),\n\t\t\tdisconnect,\n\t\t);\n\t\treturn { item, disconnect };\n\t};\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\tlet paired = false;\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\tpaired = true;\n\t\t}\n\t\tconst ids = new Set(mcp.grants.map((g) => g.grantId));\n\t\tfor (const id of pairedGrants) if (!ids.has(id)) pairedGrants.delete(id);\n\t\t// Read before an item goes: a removed Disconnect may have had it.\n\t\tconst focused = doc.activeElement;\n\t\tfor (const [id, { item }] of items) {\n\t\t\tif (ids.has(id)) continue;\n\t\t\titem.remove();\n\t\t\titems.delete(id);\n\t\t}\n\t\t// Only the relay can revoke, so only while connected.\n\t\tconst connected = mcp.state === \"connected\";\n\t\tmcp.grants.forEach((grant, i) => {\n\t\t\tlet entry = items.get(grant.grantId);\n\t\t\tif (entry === undefined) {\n\t\t\t\tentry = appItem(grant);\n\t\t\t\titems.set(grant.grantId, entry);\n\t\t\t}\n\t\t\tentry.disconnect.disabled = !connected;\n\t\t\tif (appList.children[i] !== entry.item)\n\t\t\t\tappList.insertBefore(entry.item, appList.children[i] ?? null);\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\t// It connected: no \"Code used\" any more, the next code is ready.\n\t\tif (paired && usedTimer !== undefined) endWait();\n\t\t// Focus went to the body with a removed item: it was there.\n\t\tconst now = doc.activeElement;\n\t\trenderView(paired, now === null || now === doc.body ? focused : now);\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\t// The address was taken over: the notice says so instead of this dialog.\n\tconst onReplaced = () => dialog.close();\n\twatchReplaced(mcp, doc);\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tmcp.addEventListener(\"replaced\", onReplaced);\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\tstopWaiting();\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\tmcp.removeEventListener(\"replaced\", onReplaced);\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 Done once connected, else at the address's Copy; until the\n\t\t// address is there, at the dialog itself (its title is read out), not\n\t\t// at Close.\n\t\tif (connectedView || !addressBox.hidden) start().focus();\n\t\telse dialog.focus();\n\t});\n}\n"
7
+ ],
8
+ "mappings": "AAMO,MAAM,EAAc,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,IAAI,IAAI,CAAQ,EAC7B,QAAW,KAAW,KAAK,GAAO,KAAK,EACtC,GAAI,CAAC,EAAK,IAAI,CAAO,EAAG,KAAK,GAAO,OAAO,CAAO,EAKpD,SAAS,CAAC,EAA+B,CACxC,IAAM,EAAO,IAAI,IAAI,CAAK,EAC1B,QAAW,KAAS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