@ractive-ch/tab-mcp-client 0.1.0-alpha.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,25 +1,44 @@
1
1
  # @ractive-ch/tab-mcp-client
2
2
 
3
- Offer a web page's functions as [MCP](https://modelcontextprotocol.io) tools to AI
4
- apps (Claude, ChatGPT, Claude Code, Cursor, …) through a
5
- [tab-mcp](https://github.com/ractive/tab-mcp) relay. The page connects to the relay
6
- and gets an address; the user adds that address to their AI app, which then calls the
7
- page's tools while the tab stays open.
3
+ Offer a web page's functions as [MCP](https://modelcontextprotocol.io) tools to AI apps
4
+ (Claude, ChatGPT, Claude Code) through a [tab-mcp](https://github.com/ractive/tab-mcp)
5
+ relay. The page connects to the relay and gets an address. The user adds that address to
6
+ their AI app and types a pairing code from the page; the AI app then calls the page's
7
+ tools while the tab stays open. Nothing is installed on the user's computer.
8
8
 
9
- **Status: alpha.** The API can still change. The relay is not on npm yet; run it from
10
- the [repository](https://github.com/ractive/tab-mcp).
9
+ **Status: 0.1.0.** Until 1.0, a new minor version can still change the API. Which AI apps
10
+ work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
11
+
12
+ ## You need a relay
13
+
14
+ The page talks to a tab-mcp relay, which only accepts pages from the origins its operator
15
+ allows. Run your own: the relay is on npm as
16
+ [`@ractive-ch/tab-mcp`](https://www.npmjs.com/package/@ractive-ch/tab-mcp) and on Docker
17
+ Hub as `ractive/tab-mcp`. For local development:
18
+
19
+ ```sh
20
+ docker run --rm -p 8080:8080 \
21
+ -e NODE_ENV=development \
22
+ -e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
23
+ -e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
24
+ -e TAB_MCP_STORE=memory \
25
+ ractive/tab-mcp:0.1.0
26
+ ```
27
+
28
+ For production, see
29
+ [self-hosting](https://github.com/ractive/tab-mcp/blob/main/docs/self-hosting.md).
11
30
 
12
31
  ## Install
13
32
 
14
33
  ```sh
15
- npm install @ractive-ch/tab-mcp-client@alpha
34
+ npm install @ractive-ch/tab-mcp-client
16
35
  ```
17
36
 
18
37
  Or without a bundler, from a CDN as an ES module:
19
38
 
20
39
  ```html
21
40
  <script type="module">
22
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.1.0-alpha.0/cdn/tab-mcp-client.min.js";
41
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.1.0/cdn/tab-mcp-client.min.js";
23
42
  </script>
24
43
  ```
25
44
 
@@ -52,7 +71,89 @@ button.addEventListener("click", () => mcp.showConnectDialog());
52
71
 
53
72
  Importing the library loads only a small core; `connect()` loads the rest.
54
73
 
55
- ## License
74
+ ### Tools
75
+
76
+ `registerTool(tool, { signal })` takes a tool in the shape of the WebMCP draft's
77
+ `registerTool`:
78
+
79
+ - `name` (1-128 characters of `A-Z a-z 0-9 _ - .`), `title`, `description` (not empty);
80
+ - `inputSchema`: a JSON Schema with `"type": "object"`. Arguments are checked against it
81
+ before `execute` runs;
82
+ - `execute(input, { signal, client })`: runs the tool. `signal` aborts when the AI app
83
+ gives up; `client` names the caller (`id`, verified `host`, declared `name`). Return a
84
+ string (one text block), an MCP result with a `content` array (passed through), or any
85
+ other JSON value (sent as JSON text, and as `structuredContent` for an object). A thrown
86
+ error becomes an error result with its message;
87
+ - `annotations`: `readOnlyHint`, `consequentialHint`, `untrustedContentHint`, and the
88
+ MCP hints `destructiveHint`, `idempotentHint`, `openWorldHint`.
89
+
90
+ Abort the `signal` to remove the tool. AI apps that listen for changes learn about
91
+ added and removed tools.
92
+
93
+ ### Consequential tools
94
+
95
+ Mark tools that change or delete something with `consequentialHint: true`. The page then
96
+ asks the user before every call ("Allow" or "Don't allow"), showing the AI app and the
97
+ arguments. A refusal reaches the AI app as an error result. Pass `onConfirm` to ask in
98
+ your own UI:
99
+
100
+ ```ts
101
+ const mcp = new TabMcp({
102
+ relay: "https://relay.example",
103
+ server: { name: "calculator", version: "1.0.0" },
104
+ onConfirm: ({ tool, arguments: args, client, signal }) =>
105
+ myDialog.ask(`${client.name ?? client.host} wants to run ${tool.name}.`, args, signal),
106
+ });
107
+ ```
108
+
109
+ ### Connecting and pairing
110
+
111
+ 1. The user clicks your button. `showConnectDialog()` connects (call it from the click
112
+ handler: browsers that report user activation refuse `connect()` without one) and
113
+ opens the "Connect your AI app" dialog.
114
+ 2. The dialog shows the address and short instructions for Claude, ChatGPT and Claude
115
+ Code. The user adds the address to their AI app.
116
+ 3. The AI app opens the relay's sign-in page in the browser. The dialog shows a 6-digit
117
+ code, which the user types there. The code changes every 2 minutes.
118
+ 4. The dialog lists the connected app with a Disconnect button.
119
+
120
+ The address stays the same across visits: the library keeps a secret per relay in
121
+ `localStorage`. "New address" in the dialog calls `newAddress()`, which disconnects every
122
+ app and makes a new address; when apps are connected, the dialog asks first. The relay's
123
+ sign-in page points users to it when someone else may be guessing codes. A page with its
124
+ own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
125
+ again; while the page is closed, they get "the page is not open".
126
+
127
+ The library never reconnects by itself. A page that offers something like "Keep AI
128
+ access on" can call `connect({ resume: true })` on load.
129
+
130
+ ### Your own UI
131
+
132
+ Instead of `showConnectDialog()`, use `connect()`, `disconnect()`, `newAddress()`,
133
+ `startPairing()` and `stopPairing()` (codes come only while pairing is on),
134
+ `revoke(grantId)`, the properties `state`, `address`, `pairingCode`, `grants` and
135
+ `tools`, and the events `statechange`, `connected`, `disconnected`, `pairingcode`,
136
+ `grantschange`, `toolschange`, `replaced` and `error`. The default dialogs take their
137
+ colours and sizes from `--tab-mcp-*` CSS custom properties (`--tab-mcp-font`,
138
+ `--tab-mcp-color`, `--tab-mcp-background`, `--tab-mcp-border`, `--tab-mcp-radius`, …)
139
+ and need no CSP exception.
140
+
141
+ ## Security
142
+
143
+ Connecting an AI app to a page means trusting that page, as with any MCP server. Keep
144
+ cross-site scripting out of your page: a script that reads the address secret can take
145
+ over the address. The library sends the secret only over `https:`/`wss:` (plain `http:`
146
+ only to `localhost`). See
147
+ [SECURITY.md](https://github.com/ractive/tab-mcp/blob/main/SECURITY.md) and the
148
+ [threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md).
149
+
150
+ ## More
151
+
152
+ - [Example: a calculator page](https://github.com/ractive/tab-mcp/tree/main/examples/calculator)
153
+ - [Tab–relay protocol](https://github.com/ractive/tab-mcp/blob/main/docs/protocol.md)
154
+ - [Changelog](https://github.com/ractive/tab-mcp/blob/main/CHANGELOG.md)
155
+
156
+ ## Licence
56
157
 
57
158
  MIT, see [LICENSE](LICENSE) and [AI_NOTICE](AI_NOTICE). The CDN build bundles
58
159
  third-party code; see [THIRD-PARTY-NOTICES.txt](THIRD-PARTY-NOTICES.txt).
@@ -1,5 +1,5 @@
1
- var w,g,f,p=(e,t)=>{for(var[n,o,r]of w||[])for(var i=[e],a=globalThis,s=a.document,c,h,u,d,l;h=i.pop();)if(!g[h]&&(u=o[h])){g[h]=1;for(d=1;d<u.length;d++)i.push(r[u[d]]);if(!t&&h!==e&&(c=s&&s.head)){if(f===void 0)f=(d=s.querySelector("meta[property=csp-nonce]"))&&(d.nonce||d.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",f)l.nonce=f;l.href=new a.URL(u[0],n),c.appendChild(l)}}},C=(e,t,n,o)=>{for(var r={},i=0;i<t.length;i++)r[t[i]]=n[i];(w||=[]).push([e,r,t]),g||={},p(t[o],1)};C(import.meta.url,["jt4n865w","cfq1n4kh","aac2cw9f"],[["./tab-mcp-client.min.js"],["./connection-cfq1n4kh.min.js"],["./ui-aac2cw9f.min.js"]],0);
2
- var O=/^[A-Za-z0-9_.-]{1,128}$/;function m(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function T(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)=>T(n,t+1))}function R(e,t){let n=e;for(let o of t.split("/").slice(1)){let r=decodeURIComponent(o).replaceAll("~1","/").replaceAll("~0","~");if(typeof n!=="object"||n===null||!Object.hasOwn(n,r))return;n=n[r]}return n}function A(e){let t=new Set,n=[],o=[],r=(i,a)=>{if(a>64||typeof i!=="object"||i===null)return;if(!Array.isArray(i)){let s=i;if(typeof s.$anchor==="string")t.add(s.$anchor);if(typeof s.$ref==="string")n.push(s.$ref);if(typeof s.pattern==="string")o.push(s.pattern);let c=s.patternProperties;if(typeof c==="object"&&c!==null)o.push(...Object.keys(c))}for(let s of Object.values(i))r(s,a+1)};r(e,0);for(let i of o)try{new RegExp(i,"u")}catch{return`pattern ${JSON.stringify(i)} is not a valid regular expression`}for(let i of n){if(!i.startsWith("#"))return`$ref ${JSON.stringify(i)} points outside the schema`;let a=i.slice(1);if(!(a===""||(a.startsWith("/")?R(e,a)!==void 0:t.has(a))))return`$ref ${JSON.stringify(i)} does not resolve`}return}function M(e){if(!m(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:o,inputSchema:r,execute:i,annotations:a}=e;if(typeof t!=="string"||!O.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 o!=="string"||o.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 i!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let s=r??{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(T(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let c=A(s);if(c!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${c}`);let h;try{h=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 u={};for(let[d,l]of Object.entries(a??{}))if(typeof l==="boolean")u[d]=l;return{name:t,title:n,description:o,inputSchema:h,annotations:u,execute:i}}class y{#e=new Map;#o=new Set;register(e,t={}){let n=M(e),{signal:o}=t;if(o?.aborted)return;if(this.#e.has(n.name))throw new DOMException(`registerTool: a tool named ${n.name} is already registered`,"InvalidStateError");this.#e.set(n.name,n),o?.addEventListener("abort",()=>{if(this.#e.get(n.name)===n)this.#e.delete(n.name),this.#r()},{once:!0}),this.#r()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#o.add(e),()=>this.#o.delete(e)}#r(){for(let e of[...this.#o])e()}}var L=/^[A-Za-z0-9_-]{43}$/;function I(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function x(){return I(crypto.getRandomValues(new Uint8Array(32)))}function P(e){return typeof e==="string"&&L.test(e)}function k(){try{return globalThis.localStorage??null}catch{return null}}class v{#e;#o;#r;constructor(e,t){this.#e=e===void 0?k():e,this.#o=t}get(){let e=null;try{e=this.#e?.getItem(this.#o)??null}catch{}if(P(e))return this.#r=e,e;return this.#r??this.rotate()}rotate(){let e=x();this.#r=e;try{this.#e?.setItem(this.#o,e)}catch{}return e}}var S="@ractive-ch/tab-mcp-client",b="0.1.0-alpha.0";var N=new Set(["localhost","127.0.0.1","[::1]"]);function j(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let n=t.protocol==="https:"||t.protocol==="wss:";if(!n&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!n&&!N.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let o=`${n?"https:":"http:"}//${t.host}`,r=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=r.endsWith("/tab")?r:`${r}/tab`,t.search="",t.hash="",{url:t.href,origin:o}}function D(e){try{return new URL(e).host}catch{return""}}function J(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}class E extends EventTarget{#e=new y;#o;#r;#u;#y;#v;#f;#t="disconnected";#s;#d=[];#c=!1;#p;#n;#a;#g=0;constructor(e){super();let{url:t,origin:n}=j(e.relay),{server:o,appName:r}=e;if(typeof o?.name!=="string"||typeof o.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(r!==void 0&&(typeof r!=="string"||r.length>64))throw TypeError("TabMcp: appName must be a string of at most 64 characters");this.#v=t,this.#o={...o},this.#r=r,this.#u=e.onConfirm,this.#y=e.confirmDelayMs,this.#f=new v(e.storage,e.storageKey??`tab-mcp:secret:${n}`),this.#e.onChange(()=>this.#i("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.#t}get session(){return this.#s}get address(){return this.#s?.address}get appName(){return this.#s?.appName??this.#r}get grants(){return this.#d}get pairing(){return this.#c}get pairingCode(){return this.#p}connect(e={}){if(this.#t==="connected"&&this.#s!==void 0)return Promise.resolve(this.#s);if(this.#a!==void 0)return this.#a;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"));this.#l("connecting");let n=this.#w(this.#g);return this.#a=n,n.then(()=>{if(this.#a===n)this.#a=void 0},()=>{if(this.#a!==n)return;this.#a=void 0,this.#n=void 0,this.#l("disconnected")}),n}async#w(e){let{openConnection:t}=await (p("cfq1n4kh"),import("./connection-cfq1n4kh.min.js"));if(e!==this.#g)throw new DOMException("The connection was cancelled","AbortError");let n={},o=t(this.#S(n),this.#v,this.#f.get());return n.connection=o,this.#n=o,o.ready}disconnect(){this.#b("user")}newAddress(){let e=this.#t!=="disconnected";if(this.#t==="connected")this.#n?.send({type:"grants.revokeAll"});return this.#b("new_address"),this.#f.rotate(),e?this.connect():Promise.resolve(void 0)}#b(e){this.#g++;let t=this.#n,n=this.#t==="connected";if(this.#n=void 0,this.#a=void 0,t?.close(e),this.#t==="disconnected")return;if(this.#s=void 0,this.#h(void 0),this.#l("disconnected"),n)this.#i("disconnected",{reason:e,code:1000})}startPairing(){if(this.#c)return;if(this.#c=!0,this.#t==="connected")this.#n?.send({type:"pairing.start"})}stopPairing(){if(!this.#c)return;if(this.#c=!1,this.#t==="connected")this.#n?.send({type:"pairing.stop"});this.#h(void 0)}revoke(e){if(this.#t!=="connected")return!1;return this.#n?.send({type:"grant.revoke",grantId:e})===!0}async showConnectDialog(e={}){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("aac2cw9f"),import("./ui-aac2cw9f.min.js"));await n(this,t,e.document??globalThis.document)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#i(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#l(e){if(this.#t===e)return;this.#t=e,this.#i("statechange",{state:e})}#h(e){if(this.#p===void 0&&e===void 0)return;this.#p=e,this.#i("pairingcode",e??null)}#m(e){this.#d=e,this.#i("grantschange",{grants:e})}#T(e){if(this.#u!==void 0){let o=this.#u;return Promise.resolve().then(()=>o(e)).then((r)=>r===!0)}let t=globalThis.document;if(t===void 0)return Promise.resolve(!1);let n=this.#y;return (p("aac2cw9f"),import("./ui-aac2cw9f.min.js")).then((o)=>o.confirmDialog(e,t,n===void 0?{}:{allowDelayMs:n}))}#S(e){let t=()=>e.connection!==void 0&&this.#n===e.connection;return{registry:this.#e,server:this.#o,appName:this.#r,library:{name:S,version:b},confirm:(n)=>this.#T(n),clientFor:(n)=>{let o=this.#d.find((i)=>i.grantId===n.grantId),r={grantId:n.grantId,id:n.clientId,host:D(n.clientId)};if(o!==void 0)r.name=o.client.name;return r},sessionStarted:(n)=>{let o=J(n);if(!t())return o;if(this.#s=o,this.#l("connected"),this.#m([...n.grants]),this.#c)this.#n?.send({type:"pairing.start"});return this.#i("connected",o),o},pairingCode:(n)=>{if(t()&&this.#c)this.#h(n)},grantAdded:(n)=>{if(!t())return;this.#m([...this.#d.filter((o)=>o.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#m(this.#d.filter((o)=>o.grantId!==n))},replaced:()=>{if(t())this.#i("replaced",null)},error:(n)=>{if(t())this.#i("error",{error:n})},closed:(n,o)=>{if(!t())return;this.#n=void 0,this.#s=void 0,this.#h(void 0),this.#l("disconnected"),this.#i("disconnected",{reason:n,code:o})}}}}export{E as TabMcp,b as VERSION};
1
+ var b,g,f,p=(e,t)=>{for(var[n,o,i]of b||[])for(var r=[e],a=globalThis,s=a.document,c,h,u,d,l;h=r.pop();)if(!g[h]&&(u=o[h])){g[h]=1;for(d=1;d<u.length;d++)r.push(i[u[d]]);if(!t&&h!==e&&(c=s&&s.head)){if(f===void 0)f=(d=s.querySelector("meta[property=csp-nonce]"))&&(d.nonce||d.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",f)l.nonce=f;l.href=new a.URL(u[0],n),c.appendChild(l)}}},C=(e,t,n,o)=>{for(var i={},r=0;r<t.length;r++)i[t[r]]=n[r];(b||=[]).push([e,i,t]),g||={},p(t[o],1)};C(import.meta.url,["qye297ee","cfq1n4kh","vp7pkb1j"],[["./tab-mcp-client.min.js"],["./connection-cfq1n4kh.min.js"],["./ui-vp7pkb1j.min.js"]],0);
2
+ var O=/^[A-Za-z0-9_.-]{1,128}$/;function m(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function T(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)=>T(n,t+1))}function R(e,t){let n=e;for(let o of t.split("/").slice(1)){let i=decodeURIComponent(o).replaceAll("~1","/").replaceAll("~0","~");if(typeof n!=="object"||n===null||!Object.hasOwn(n,i))return;n=n[i]}return n}function A(e){let t=new Set,n=[],o=[],i=(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")o.push(s.pattern);let c=s.patternProperties;if(typeof c==="object"&&c!==null)o.push(...Object.keys(c))}for(let s of Object.values(r))i(s,a+1)};i(e,0);for(let r of o)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("/")?R(e,a)!==void 0:t.has(a))))return`$ref ${JSON.stringify(r)} does not resolve`}return}function M(e){if(!m(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:o,inputSchema:i,execute:r,annotations:a}=e;if(typeof t!=="string"||!O.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 o!=="string"||o.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=i??{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(T(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let c=A(s);if(c!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${c}`);let h;try{h=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 u={};for(let[d,l]of Object.entries(a??{}))if(typeof l==="boolean")u[d]=l;return{name:t,title:n,description:o,inputSchema:h,annotations:u,execute:r}}class y{#e=new Map;#o=new Set;register(e,t={}){let n=M(e),{signal:o}=t;if(o?.aborted)return;if(this.#e.has(n.name))throw new DOMException(`registerTool: a tool named ${n.name} is already registered`,"InvalidStateError");this.#e.set(n.name,n),o?.addEventListener("abort",()=>{if(this.#e.get(n.name)===n)this.#e.delete(n.name),this.#r()},{once:!0}),this.#r()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#o.add(e),()=>this.#o.delete(e)}#r(){for(let e of[...this.#o])e()}}var x=/^[A-Za-z0-9_-]{43}$/;function L(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function I(){return L(crypto.getRandomValues(new Uint8Array(32)))}function P(e){return typeof e==="string"&&x.test(e)}function k(){try{return globalThis.localStorage??null}catch{return null}}class v{#e;#o;#r;constructor(e,t){this.#e=e===void 0?k():e,this.#o=t}get(){let e=null;try{e=this.#e?.getItem(this.#o)??null}catch{}if(P(e))return this.#r=e,e;return this.#r??this.rotate()}rotate(){let e=I();this.#r=e;try{this.#e?.setItem(this.#o,e)}catch{}return e}}var S="@ractive-ch/tab-mcp-client",w="0.1.0";var N=new Set(["localhost","127.0.0.1","[::1]"]);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 D(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&&!N.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let o=`${n?"https:":"http:"}//${t.host}`,i=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=i.endsWith("/tab")?i:`${i}/tab`,t.search="",t.hash="",{url:t.href,origin:o}}function J(e){try{return new URL(e).host}catch{return""}}function K(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}class E extends EventTarget{#e=new y;#o;#r;#u;#y;#v;#f;#t="disconnected";#s;#d=[];#c=!1;#p;#n;#a;#g=0;constructor(e){super();let{url:t,origin:n}=D(e.relay),{server:o,appName:i}=e;if(typeof o?.name!=="string"||typeof o.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(i!==void 0&&!j(i))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");this.#v=t,this.#o={...o},this.#r=i,this.#u=e.onConfirm,this.#y=e.confirmDelayMs,this.#f=new v(e.storage,e.storageKey??`tab-mcp:secret:${n}`),this.#e.onChange(()=>this.#i("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.#t}get session(){return this.#s}get address(){return this.#s?.address}get appName(){return this.#s?.appName??this.#r}get grants(){return this.#d}get pairing(){return this.#c}get pairingCode(){return this.#p}connect(e={}){if(this.#t==="connected"&&this.#s!==void 0)return Promise.resolve(this.#s);if(this.#a!==void 0)return this.#a;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"));this.#l("connecting");let n=this.#b(this.#g);return this.#a=n,n.then(()=>{if(this.#a===n)this.#a=void 0},()=>{if(this.#a!==n)return;this.#a=void 0,this.#n=void 0,this.#l("disconnected")}),n}async#b(e){let{openConnection:t}=await (p("cfq1n4kh"),import("./connection-cfq1n4kh.min.js"));if(e!==this.#g)throw new DOMException("The connection was cancelled","AbortError");let n={},o=t(this.#S(n),this.#v,this.#f.get());return n.connection=o,this.#n=o,o.ready}disconnect(){this.#w("user")}newAddress(){let e=this.#t!=="disconnected";if(this.#t==="connected")this.#n?.send({type:"grants.revokeAll"});return this.#w("new_address"),this.#f.rotate(),e?this.connect():Promise.resolve(void 0)}#w(e){this.#g++;let t=this.#n,n=this.#t==="connected";if(this.#n=void 0,this.#a=void 0,t?.close(e),this.#t==="disconnected")return;if(this.#s=void 0,this.#h(void 0),this.#l("disconnected"),n)this.#i("disconnected",{reason:e,code:1000})}startPairing(){if(this.#c)return;if(this.#c=!0,this.#t==="connected")this.#n?.send({type:"pairing.start"})}stopPairing(){if(!this.#c)return;if(this.#c=!1,this.#t==="connected")this.#n?.send({type:"pairing.stop"});this.#h(void 0)}revoke(e){if(this.#t!=="connected")return!1;return this.#n?.send({type:"grant.revoke",grantId:e})===!0}async showConnectDialog(e={}){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("vp7pkb1j"),import("./ui-vp7pkb1j.min.js"));await n(this,t,e.document??globalThis.document)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#i(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#l(e){if(this.#t===e)return;this.#t=e,this.#i("statechange",{state:e})}#h(e){if(this.#p===void 0&&e===void 0)return;this.#p=e,this.#i("pairingcode",e??null)}#m(e){this.#d=e,this.#i("grantschange",{grants:e})}#T(e){if(this.#u!==void 0){let o=this.#u;return Promise.resolve().then(()=>o(e)).then((i)=>i===!0)}let t=globalThis.document;if(t===void 0)return Promise.resolve(!1);let n=this.#y;return (p("vp7pkb1j"),import("./ui-vp7pkb1j.min.js")).then((o)=>o.confirmDialog(e,t,n===void 0?{}:{allowDelayMs:n}))}#S(e){let t=()=>e.connection!==void 0&&this.#n===e.connection;return{registry:this.#e,server:this.#o,appName:this.#r,library:{name:S,version:w},confirm:(n)=>this.#T(n),clientFor:(n)=>{let o=this.#d.find((r)=>r.grantId===n.grantId),i={grantId:n.grantId,id:n.clientId,host:J(n.clientId)};if(o!==void 0)i.name=o.client.name;return i},sessionStarted:(n)=>{let o=K(n);if(!t())return o;if(this.#s=o,this.#l("connected"),this.#m([...n.grants]),this.#c)this.#n?.send({type:"pairing.start"});return this.#i("connected",o),o},pairingCode:(n)=>{if(t()&&this.#c)this.#h(n)},grantAdded:(n)=>{if(!t())return;this.#m([...this.#d.filter((o)=>o.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#m(this.#d.filter((o)=>o.grantId!==n))},replaced:()=>{if(t())this.#i("replaced",null)},error:(n)=>{if(t())this.#i("error",{error:n})},closed:(n,o)=>{if(!t())return;this.#n=void 0,this.#s=void 0,this.#h(void 0),this.#l("disconnected"),this.#i("disconnected",{reason:n,code:o})}}}}export{E as TabMcp,w as VERSION};
3
3
 
4
- //# debugId=DB2A934C34B8D9CF64756E2164756E21
4
+ //# debugId=AC100AD7940C25C064756E2164756E21
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 */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tif (this.#tools.get(registered.name) === registered) {\n\t\t\t\t\tthis.#tools.delete(registered.name);\n\t\t\t\t\tthis.#changed();\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
6
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#memory: string | undefined;\n\n\tconstructor(storage: SecretStorage | null | undefined, key: string) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\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} 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\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t\treturn secret;\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.1.0-alpha.0\";\n",
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\tPairingCode,\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/** `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\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\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\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 (\n\t\t\tappName !== undefined &&\n\t\t\t(typeof appName !== \"string\" || appName.length > 64)\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be a string of at most 64 characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\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(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** 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 * Never reconnects by itself.\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) return this.#connecting;\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\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#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.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\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 tool\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmDialog(\n\t\t\t\trequest,\n\t\t\t\tdoc,\n\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\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\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\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.#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\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\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\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\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.1.0\";\n",
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\tPairingCode,\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/** 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\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\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\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\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(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** 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 * Never reconnects by itself.\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) return this.#connecting;\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\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#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.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmDialog(\n\t\t\t\trequest,\n\t\t\t\tdoc,\n\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\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\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\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.#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\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\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\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\n\t\t};\n\t}\n}\n"
9
9
  ],
10
- "mappings": ";AAYA,IAAM,EAAO,0BAYb,SAAS,CAAa,CAAC,EAA0C,CAChE,OAAO,OAAO,IAAM,UAAY,IAAM,MAAQ,CAAC,MAAM,QAAQ,CAAC,EAI/D,SAAS,CAAa,CAAC,EAAiB,EAAQ,EAAY,CAC3D,GAAI,EAAQ,IAAM,OAAO,IAAW,UAAY,IAAW,KAAM,MAAO,GACxE,GAAI,CAAC,MAAM,QAAQ,CAAM,GAAK,iBAAkB,EAAQ,MAAO,GAC/D,OAAO,OAAO,OAAO,CAAM,EAAE,KAAK,CAAC,IAAM,EAAc,EAAG,EAAQ,CAAC,CAAC,EAIrE,SAAS,CAAc,CAAC,EAAe,EAA0B,CAChE,IAAI,EAAgB,EACpB,QAAW,KAAO,EAAQ,MAAM,GAAG,EAAE,MAAM,CAAC,EAAG,CAC9C,IAAM,EAAM,mBAAmB,CAAG,EAChC,WAAW,KAAM,GAAG,EACpB,WAAW,KAAM,GAAG,EACtB,GAAI,OAAO,IAAS,UAAY,IAAS,MAAQ,CAAC,OAAO,OAAO,EAAM,CAAG,EACxE,OACD,EAAQ,EAAiC,GAE1C,OAAO,EAQR,SAAS,CAAa,CAAC,EAAmC,CACzD,IAAM,EAAU,IAAI,IACd,EAAiB,CAAC,EAClB,EAAqB,CAAC,EACtB,EAAO,CAAC,EAAe,IAAwB,CACpD,GAAI,EAAQ,IAAM,OAAO,IAAS,UAAY,IAAS,KAAM,OAC7D,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B,GAAI,CAAC,EAAQ,EAAG,OAAO,EAIvB,GAHA,KAAK,GAAW,EAChB,KAAK,GAAU,WAAW,EAC1B,KAAK,GAAW,CAAC,GAAG,EAAE,MAAM,CAAC,EACzB,KAAK,GAAU,KAAK,IAAa,KAAK,CAAE,KAAM,eAAgB,CAAC,EAEnE,OADA,KAAK,GAAM,YAAa,CAAO,EACxB,GAER,YAAa,CAAC,IAAS,CACtB,GAAI,EAAQ,GAAK,KAAK,GAAU,KAAK,GAAgB,CAAI,GAE1D,WAAY,CAAC,IAAU,CACtB,GAAI,CAAC,EAAQ,EAAG,OAChB,KAAK,GAAW,CACf,GAAG,KAAK,GAAQ,OAAO,CAAC,IAAM,EAAE,UAAY,EAAM,OAAO,EACzD,CACD,CAAC,GAEF,aAAc,CAAC,IAAY,CAC1B,GAAI,CAAC,EAAQ,EAAG,OAChB,KAAK,GAAW,KAAK,GAAQ,OAAO,CAAC,IAAM,EAAE,UAAY,CAAO,CAAC,GAElE,SAAU,IAAM,CACf,GAAI,EAAQ,EAAG,KAAK,GAAM,WAAY,IAAI,GAE3C,MAAO,CAAC,IAAU,CACjB,GAAI,EAAQ,EAAG,KAAK,GAAM,QAAS,CAAE,OAAM,CAAC,GAE7C,OAAQ,CAAC,EAA0B,IAAiB,CACnD,GAAI,CAAC,EAAQ,EAAG,OAChB,KAAK,GAAc,OACnB,KAAK,GAAW,OAChB,KAAK,GAAgB,MAAS,EAC9B,KAAK,GAAU,cAAc,EAC7B,KAAK,GAAM,eAAgB,CAAE,SAAQ,MAAK,CAAC,EAE7C,EAEF",
11
+ "debugId": "AC100AD7940C25C064756E2164756E21",
12
12
  "names": []
13
13
  }
@@ -0,0 +1,4 @@
1
+ var M=0;function s(e,r,t={},...i){let a=e.createElement(r);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(...i),a}function g(e,r,t){let i=s(e,"button",{text:r});return i.type="button",i.addEventListener("click",t),i}function B(e,r,t){let i=`tab-mcp-${++M}`,a=s(e,"dialog",{className:`tab-mcp-dialog ${r}`});a.setAttribute("aria-labelledby",`${i}-title`);let o=a.style;o.setProperty("max-width","var(--tab-mcp-max-width, 34rem)"),o.setProperty("font","var(--tab-mcp-font, inherit)"),o.setProperty("color","var(--tab-mcp-color, CanvasText)"),o.setProperty("background","var(--tab-mcp-background, Canvas)"),o.setProperty("border","var(--tab-mcp-border, 1px solid GrayText)"),o.setProperty("border-radius","var(--tab-mcp-radius, 0.5rem)"),o.setProperty("padding","var(--tab-mcp-padding, 1rem 1.25rem)");let l=s(e,"h2",{id:`${i}-title`,text:t});return l.style.setProperty("margin-top","0"),l.style.setProperty("font-size","var(--tab-mcp-title-size, 1.25em)"),a.append(l),{dialog:a,heading:l}}function I(e){let r=e.host||e.id;return e.name!==void 0&&e.name!==""?`${e.name} (${r})`:r}function V(e){try{return JSON.stringify(e,null,2)}catch{return}}var Y=750,F=500;function U(e,r,t={}){let i=Math.max(F,t.allowDelayMs??Y);if(e.signal.aborted)return Promise.resolve(!1);let a=e.tool.title??e.tool.name,{dialog:o}=B(r,"tab-mcp-confirm",`Allow ${a}?`),l=g(r,"Don't allow",()=>o.close("deny")),d=g(r,"Allow",()=>{if(!d.disabled)o.close("allow")});d.disabled=!0;let h=s(r,"div",{className:"tab-mcp-actions"},l," ",d),m=V(e.arguments),p=s(r,"pre",{className:"tab-mcp-arguments",text:m??"The arguments cannot be shown, so this call cannot be allowed."});if(m===void 0)d.hidden=!0;return p.style.setProperty("white-space","pre-wrap"),p.style.setProperty("max-height","12rem"),p.style.setProperty("overflow","auto"),p.hidden=Object.keys(e.arguments).length===0,o.append(s(r,"p",{text:`${I(e.client)} wants to run ${a}.`}),s(r,"p",{className:"tab-mcp-description",text:e.tool.description}),p,h),r.body.append(o),new Promise((w)=>{let b=()=>o.close("deny");e.signal.addEventListener("abort",b,{once:!0});let y;o.addEventListener("close",()=>{clearTimeout(y),e.signal.removeEventListener("abort",b);let C=o.returnValue==="allow";o.remove(),w(C)},{once:!0}),o.showModal(),l.focus(),y=setTimeout(()=>{d.disabled=!1},i)})}var J=[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."],["Claude Code","Run: claude mcp add --transport http tools ADDRESS"]];function Q(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function X(e,r,t){let{dialog:i}=B(t,"tab-mcp-connect","Connect your AI app"),a=s(t,"p",{className:"tab-mcp-status",text:"Connecting…"});a.setAttribute("role","status");let o=`tab-mcp-${++M}-address`,l=s(t,"label",{text:"Add this address to your AI app:"});l.htmlFor=o;let d=s(t,"input",{id:o,className:"tab-mcp-address-input"});d.readOnly=!0,d.style.setProperty("width","100%"),d.style.setProperty("font-family","var(--tab-mcp-mono, monospace)");let h=g(t,"Copy",()=>{let n=()=>{h.textContent="Copied"},c=t.defaultView?.navigator?.clipboard;if(c!==void 0)c.writeText(d.value).then(n,()=>d.select());else d.select()}),m=g(t,"New address",()=>W());m.className="tab-mcp-new-address";let p=s(t,"div",{className:"tab-mcp-address"},l,d," ",h," ",m),w=`tab-mcp-${++M}-new-address`,b=s(t,"p",{id:w}),y=g(t,"Cancel",()=>{u.hidden=!0,m.focus()}),C=g(t,"Disconnect and get new address",()=>O());C.className="tab-mcp-new-address-confirm";let u=s(t,"div",{className:"tab-mcp-new-address-question"},b,s(t,"div",{className:"tab-mcp-actions"},y," ",C));u.setAttribute("role","group"),u.setAttribute("aria-labelledby",w),u.hidden=!0;let x=s(t,"strong",{className:"tab-mcp-code-value"});x.style.setProperty("font-size","var(--tab-mcp-code-size, 1.5em)"),x.style.setProperty("letter-spacing","0.1em");let N=s(t,"p",{className:"tab-mcp-code"},"When asked, enter the code ",x,s(t,"br"),s(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."}));N.setAttribute("aria-live","polite");let k=s(t,"ul"),A=s(t,"details",{className:"tab-mcp-help"},s(t,"summary",{text:"How do I add it?"}),k),R=s(t,"ul"),L=s(t,"div",{className:"tab-mcp-apps"},s(t,"h3",{text:"Connected"}),R),v=g(t,"Close",()=>i.close()),K=s(t,"div",{className:"tab-mcp-actions"},v);i.append(a,p,u,N,A,L,K),p.hidden=!0,N.hidden=!0,A.hidden=!0,L.hidden=!0;let T=!1,H=()=>{let n=e.grants.map((c)=>I(c.client));if(n.length===0)return!1;return b.textContent=`A new address disconnects ${Q(n)}. To use this page again, add the new address to ${n.length===1?"it":"them"}.`,!0},W=()=>{if(e.state!=="connected")return;if(!H()){O();return}u.hidden=!1,y.focus()},O=()=>{v.focus(),u.hidden=!0,T=!0,a.textContent="Getting a new address…",e.newAddress().then(()=>{T=!1,a.textContent="This is a new address. Add it to your AI app again.",v.focus()},(n)=>{T=!1,a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}. Close this and connect again.`,v.focus()})},D=(n)=>{if(n===void 0){p.hidden=!0,u.hidden=!0,A.hidden=!0;return}d.value=n.address,h.textContent="Copy";let c=n.appName??e.appName;if(!T)a.textContent=c!==void 0?`${c} is ready for your AI app.`:"This page is ready for your AI app.";m.disabled=e.state!=="connected",p.hidden=!1,A.hidden=!1,k.replaceChildren(...J.map(([P,j])=>s(t,"li",{},s(t,"strong",{text:P}),`: ${j.replace("ADDRESS",n.address)}`)))},E=()=>{let n=e.pairingCode;x.textContent=n?.code??"",N.hidden=n===void 0},S=s(t,"p",{className:"tab-mcp-apps-note"});L.append(S);let G=new Set(e.grants.map((n)=>n.grantId)),f=()=>{for(let c of e.grants){if(G.has(c.grantId))continue;G.add(c.grantId),a.textContent=`${I(c.client)} is connected.`}let n=e.state==="connected";if(R.replaceChildren(...e.grants.map((c)=>{let P=g(t,"Disconnect",()=>{if(!e.revoke(c.grantId))f()});return P.disabled=!n,s(t,"li",{},`${I(c.client)} connected `,P)})),S.textContent=n?"":"To disconnect an app, connect this page again first.",S.hidden=n,L.hidden=e.grants.length===0,!u.hidden&&!H())u.hidden=!0,m.focus()},_=(n)=>{if(n.detail.reason!=="new_address")a.textContent="Disconnected. AI apps can use this page again after you connect.";D(void 0),f(),E()},z=()=>{D(e.session),f()};return e.addEventListener("pairingcode",E),e.addEventListener("grantschange",f),e.addEventListener("connected",z),e.addEventListener("disconnected",_),t.body.append(i),e.startPairing(),f(),E(),D(e.session),r.then((n)=>D(n),(n)=>{a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}`}),new Promise((n)=>{i.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",E),e.removeEventListener("grantschange",f),e.removeEventListener("connected",z),e.removeEventListener("disconnected",_),i.remove(),n()},{once:!0}),i.showModal(),v.focus()})}export{U as confirmDialog,X as showConnectDialog};
2
+
3
+ //# debugId=F5BA10D3953C81BE64756E2164756E21
4
+ //# sourceMappingURL=ui-vp7pkb1j.min.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\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.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn 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/**\n * Ask whether a consequential tool may run. Resolves `true` only for \"Allow\",\n * which stays disabled for `allowDelayMs` (default 750, at least 500) after\n * the dialog opens, so a click meant for the page cannot approve.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<boolean> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(false);\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tallow.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t);\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) allow.hidden = true;\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\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);\n\tdoc.body.append(dialog);\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\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst allowed = dialog.returnValue === \"allow\";\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(allowed);\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\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code while the relay sends one, and the\n * connected apps with Disconnect. Pairing is on while it is open. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\n\t});\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\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\tcodeLine.setAttribute(\"aria-live\", \"polite\");\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tclose.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\tclose.focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tcopy.textContent = \"Copy\";\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\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\tconst renderGrants = () => {\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}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tclose.focus();\n\t});\n}\n"
6
+ ],
7
+ "mappings": "AAiBA,IAAI,EAAU,EAEd,SAAS,CAAyC,CACjD,EACA,EACA,EAA4D,CAAC,KAC1D,EACwB,CAC3B,IAAM,EAAO,EAAI,cAAc,CAAG,EAClC,GAAI,EAAM,YAAc,OAAW,EAAK,UAAY,EAAM,UAC1D,GAAI,EAAM,KAAO,OAAW,EAAK,GAAK,EAAM,GAC5C,GAAI,EAAM,OAAS,OAAW,EAAK,YAAc,EAAM,KAEvD,OADA,EAAK,OAAO,GAAG,CAAQ,EAChB,EAGR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V,CAAC,IAAY,EAAc,CAAO,EAClC,CAAC,IAAmB,CACnB,EAAO,YAAc,sBAAsB,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,IAElG,EAEO,IAAI,QAAQ,CAAC,IAAY,CAC/B,EAAO,iBACN,QACA,IAAM,CACL,EAAI,YAAY,EAChB,EAAI,oBAAoB,cAAe,CAAU,EACjD,EAAI,oBAAoB,eAAgB,CAAY,EACpD,EAAI,oBAAoB,YAAa,CAAW,EAChD,EAAI,oBAAoB,eAAgB,CAAc,EACtD,EAAO,OAAO,EACd,EAAQ,GAET,CAAE,KAAM,EAAK,CACd,EACA,EAAO,UAAU,EACjB,EAAM,MAAM,EACZ",
8
+ "debugId": "F5BA10D3953C81BE64756E2164756E21",
9
+ "names": []
10
+ }
package/index.js CHANGED
@@ -28,7 +28,7 @@ var __chunks = (base, ids, nodes, entry) => {
28
28
  __chunkSeen ||= {};
29
29
  __preload(ids[entry], 1);
30
30
  };
31
- __chunks(import.meta.url,["1ne0rjc5","1gf7vqz2","168746sb"],[["./index.js"],["./connection-1gf7vqz2.js"],["./ui-168746sb.js"]],0);
31
+ __chunks(import.meta.url,["h569mgv4","1gf7vqz2","71qbaznx"],[["./index.js"],["./connection-1gf7vqz2.js"],["./ui-71qbaznx.js"]],0);
32
32
 
33
33
  // src/registry.ts
34
34
  var NAME = /^[A-Za-z0-9_.-]{1,128}$/;
@@ -230,10 +230,16 @@ class SecretStore {
230
230
 
231
231
  // src/version.ts
232
232
  var LIBRARY_NAME = "@ractive-ch/tab-mcp-client";
233
- var VERSION = "0.1.0-alpha.0";
233
+ var VERSION = "0.1.0";
234
234
 
235
235
  // src/tab-mcp.ts
236
236
  var LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]"]);
237
+ function isAppName(value) {
238
+ return typeof value === "string" && value.trim().length > 0 && value.length <= 64 && ![...value].some((ch) => {
239
+ const c = ch.codePointAt(0) ?? 0;
240
+ return c < 32 || c >= 127 && c <= 159;
241
+ });
242
+ }
237
243
  function tabUrl(relay) {
238
244
  let u;
239
245
  try {
@@ -299,8 +305,8 @@ class TabMcp extends EventTarget {
299
305
  if (typeof server?.name !== "string" || typeof server.version !== "string") {
300
306
  throw new TypeError("TabMcp: server needs a name and a version");
301
307
  }
302
- if (appName !== undefined && (typeof appName !== "string" || appName.length > 64)) {
303
- throw new TypeError("TabMcp: appName must be a string of at most 64 characters");
308
+ if (appName !== undefined && !isAppName(appName)) {
309
+ throw new TypeError("TabMcp: appName must be 1-64 characters without control characters");
304
310
  }
305
311
  this.#relayUrl = url;
306
312
  this.#server = { ...server };
@@ -427,7 +433,7 @@ class TabMcp extends EventTarget {
427
433
  async showConnectDialog(options = {}) {
428
434
  const connecting = this.connect();
429
435
  connecting.catch(() => {});
430
- const { showConnectDialog } = await (__preload("168746sb"), import("./ui-168746sb.js"));
436
+ const { showConnectDialog } = await (__preload("71qbaznx"), import("./ui-71qbaznx.js"));
431
437
  await showConnectDialog(this, connecting, options.document ?? globalThis.document);
432
438
  }
433
439
  addEventListener(type, listener, options) {
@@ -464,7 +470,7 @@ class TabMcp extends EventTarget {
464
470
  if (doc === undefined)
465
471
  return Promise.resolve(false);
466
472
  const delay = this.#confirmDelayMs;
467
- return (__preload("168746sb"), import("./ui-168746sb.js")).then((ui) => ui.confirmDialog(request, doc, delay === undefined ? {} : { allowDelayMs: delay }));
473
+ return (__preload("71qbaznx"), import("./ui-71qbaznx.js")).then((ui) => ui.confirmDialog(request, doc, delay === undefined ? {} : { allowDelayMs: delay }));
468
474
  }
469
475
  #host(ref) {
470
476
  const current = () => ref.connection !== undefined && this.#connection === ref.connection;
@@ -539,5 +545,5 @@ export {
539
545
  VERSION
540
546
  };
541
547
 
542
- //# debugId=6DE88C9192B15F2464756E2164756E21
548
+ //# debugId=024A7C181D75C70164756E2164756E21
543
549
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -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 */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tif (this.#tools.get(registered.name) === registered) {\n\t\t\t\t\tthis.#tools.delete(registered.name);\n\t\t\t\t\tthis.#changed();\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
6
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#memory: string | undefined;\n\n\tconstructor(storage: SecretStorage | null | undefined, key: string) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\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} 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\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t\treturn secret;\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.1.0-alpha.0\";\n",
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\tPairingCode,\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/** `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\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\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\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 (\n\t\t\tappName !== undefined &&\n\t\t\t(typeof appName !== \"string\" || appName.length > 64)\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be a string of at most 64 characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\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(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** 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 * Never reconnects by itself.\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) return this.#connecting;\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\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#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.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\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 tool\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmDialog(\n\t\t\t\trequest,\n\t\t\t\tdoc,\n\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\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\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\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.#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\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\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\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\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.1.0\";\n",
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\tPairingCode,\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/** 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\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\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\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\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(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** 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 * Never reconnects by itself.\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) return this.#connecting;\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\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#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.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmDialog(\n\t\t\t\trequest,\n\t\t\t\tdoc,\n\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\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\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\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.#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\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\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\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\n\t\t};\n\t}\n}\n"
9
9
  ],
10
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,IAAM,OAAO;AAYb,SAAS,aAAa,CAAC,GAA0C;AAAA,EAChE,OAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,MAAM,QAAQ,CAAC;AAAA;AAI/D,SAAS,aAAa,CAAC,QAAiB,QAAQ,GAAY;AAAA,EAC3D,IAAI,QAAQ,MAAM,OAAO,WAAW,YAAY,WAAW;AAAA,IAAM,OAAO;AAAA,EACxE,IAAI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AAY,CAAC,UAAU;AAAA,QACtB,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAChB,KAAK,WAAW;AAAA,UACf,GAAG,KAAK,QAAQ,OAAO,CAAC,MAAM,EAAE,YAAY,MAAM,OAAO;AAAA,UACzD;AAAA,QACD,CAAC;AAAA;AAAA,MAEF,cAAc,CAAC,YAAY;AAAA,QAC1B,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAChB,KAAK,WAAW,KAAK,QAAQ,OAAO,CAAC,MAAM,EAAE,YAAY,OAAO,CAAC;AAAA;AAAA,MAElE,UAAU,MAAM;AAAA,QACf,IAAI,QAAQ;AAAA,UAAG,KAAK,MAAM,YAAY,IAAI;AAAA;AAAA,MAE3C,OAAO,CAAC,UAAU;AAAA,QACjB,IAAI,QAAQ;AAAA,UAAG,KAAK,MAAM,SAAS,EAAE,MAAM,CAAC;AAAA;AAAA,MAE7C,QAAQ,CAAC,QAA0B,SAAiB;AAAA,QACnD,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAChB,KAAK,cAAc;AAAA,QACnB,KAAK,WAAW;AAAA,QAChB,KAAK,gBAAgB,SAAS;AAAA,QAC9B,KAAK,UAAU,cAAc;AAAA,QAC7B,KAAK,MAAM,gBAAgB,EAAE,QAAQ,KAAK,CAAC;AAAA;AAAA,IAE7C;AAAA;AAEF;",
11
+ "debugId": "024A7C181D75C70164756E2164756E21",
12
12
  "names": []
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ractive-ch/tab-mcp-client",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0",
4
4
  "description": "Browser library: offer a web page's tools to AI agents through a tab-mcp relay",
5
5
  "type": "module",
6
6
  "exports": {
package/tab-mcp.d.ts CHANGED
@@ -69,7 +69,7 @@ export declare class TabMcp extends EventTarget {
69
69
  */
70
70
  revoke(grantId: string): boolean;
71
71
  /**
72
- * Open the default "Connect your AI tool" dialog; connects first if needed
72
+ * Open the default "Connect your AI app" dialog; connects first if needed
73
73
  * (call it from a click). Resolves when the dialog closes. Pages with their
74
74
  * own UI use the events and methods instead.
75
75
  */
@@ -110,15 +110,18 @@ var INSTRUCTIONS = [
110
110
  ],
111
111
  ["Claude Code", "Run: claude mcp add --transport http tools ADDRESS"]
112
112
  ];
113
+ function listOf(items) {
114
+ return items.length < 2 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
115
+ }
113
116
  function showConnectDialog(mcp, connecting, doc) {
114
- const { dialog } = newDialog(doc, "tab-mcp-connect", "Connect your AI tool");
117
+ const { dialog } = newDialog(doc, "tab-mcp-connect", "Connect your AI app");
115
118
  const status = el(doc, "p", {
116
119
  className: "tab-mcp-status",
117
120
  text: "Connecting…"
118
121
  });
119
122
  status.setAttribute("role", "status");
120
123
  const addressId = `tab-mcp-${++counter}-address`;
121
- const label = el(doc, "label", { text: "Add this address to your AI tool:" });
124
+ const label = el(doc, "label", { text: "Add this address to your AI app:" });
122
125
  label.htmlFor = addressId;
123
126
  const address = el(doc, "input", {
124
127
  id: addressId,
@@ -137,11 +140,28 @@ function showConnectDialog(mcp, connecting, doc) {
137
140
  else
138
141
  address.select();
139
142
  });
140
- const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy);
143
+ const fresh = button(doc, "New address", () => askNewAddress());
144
+ fresh.className = "tab-mcp-new-address";
145
+ const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy, " ", fresh);
146
+ const confirmId = `tab-mcp-${++counter}-new-address`;
147
+ const confirmText = el(doc, "p", { id: confirmId });
148
+ const cancelNew = button(doc, "Cancel", () => {
149
+ confirmBox.hidden = true;
150
+ fresh.focus();
151
+ });
152
+ const confirmNew = button(doc, "Disconnect and get new address", () => getNewAddress());
153
+ confirmNew.className = "tab-mcp-new-address-confirm";
154
+ const confirmBox = el(doc, "div", { className: "tab-mcp-new-address-question" }, confirmText, el(doc, "div", { className: "tab-mcp-actions" }, cancelNew, " ", confirmNew));
155
+ confirmBox.setAttribute("role", "group");
156
+ confirmBox.setAttribute("aria-labelledby", confirmId);
157
+ confirmBox.hidden = true;
141
158
  const code = el(doc, "strong", { className: "tab-mcp-code-value" });
142
159
  code.style.setProperty("font-size", "var(--tab-mcp-code-size, 1.5em)");
143
160
  code.style.setProperty("letter-spacing", "0.1em");
144
- const codeLine = el(doc, "p", { className: "tab-mcp-code" }, "When asked, enter the code ", code);
161
+ const codeLine = el(doc, "p", { className: "tab-mcp-code" }, "When asked, enter the code ", code, el(doc, "br"), el(doc, "small", {
162
+ className: "tab-mcp-code-note",
163
+ text: "A new code appears every 2 minutes and after each use."
164
+ }));
145
165
  codeLine.setAttribute("aria-live", "polite");
146
166
  const steps = el(doc, "ul");
147
167
  const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: "How do I add it?" }), steps);
@@ -149,20 +169,57 @@ function showConnectDialog(mcp, connecting, doc) {
149
169
  const apps = el(doc, "div", { className: "tab-mcp-apps" }, el(doc, "h3", { text: "Connected" }), appList);
150
170
  const close = button(doc, "Close", () => dialog.close());
151
171
  const actions = el(doc, "div", { className: "tab-mcp-actions" }, close);
152
- dialog.append(status, addressBox, codeLine, help, apps, actions);
172
+ dialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);
153
173
  addressBox.hidden = true;
154
174
  codeLine.hidden = true;
155
175
  help.hidden = true;
156
176
  apps.hidden = true;
177
+ let renewing = false;
178
+ const renderQuestion = () => {
179
+ const names = mcp.grants.map((g) => clientLabel(g.client));
180
+ if (names.length === 0)
181
+ return false;
182
+ confirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? "it" : "them"}.`;
183
+ return true;
184
+ };
185
+ const askNewAddress = () => {
186
+ if (mcp.state !== "connected")
187
+ return;
188
+ if (!renderQuestion()) {
189
+ getNewAddress();
190
+ return;
191
+ }
192
+ confirmBox.hidden = false;
193
+ cancelNew.focus();
194
+ };
195
+ const getNewAddress = () => {
196
+ close.focus();
197
+ confirmBox.hidden = true;
198
+ renewing = true;
199
+ status.textContent = "Getting a new address…";
200
+ mcp.newAddress().then(() => {
201
+ renewing = false;
202
+ status.textContent = "This is a new address. Add it to your AI app again.";
203
+ close.focus();
204
+ }, (error) => {
205
+ renewing = false;
206
+ status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;
207
+ close.focus();
208
+ });
209
+ };
157
210
  const renderSession = (session) => {
158
211
  if (session === undefined) {
159
212
  addressBox.hidden = true;
213
+ confirmBox.hidden = true;
160
214
  help.hidden = true;
161
215
  return;
162
216
  }
163
217
  address.value = session.address;
218
+ copy.textContent = "Copy";
164
219
  const appName = session.appName ?? mcp.appName;
165
- status.textContent = appName !== undefined ? `${appName} is ready for your AI tool.` : "This page is ready for your AI tool.";
220
+ if (!renewing)
221
+ status.textContent = appName !== undefined ? `${appName} is ready for your AI app.` : "This page is ready for your AI app.";
222
+ fresh.disabled = mcp.state !== "connected";
166
223
  addressBox.hidden = false;
167
224
  help.hidden = false;
168
225
  steps.replaceChildren(...INSTRUCTIONS.map(([app, how]) => el(doc, "li", {}, el(doc, "strong", { text: app }), `: ${how.replace("ADDRESS", session.address)}`)));
@@ -174,7 +231,14 @@ function showConnectDialog(mcp, connecting, doc) {
174
231
  };
175
232
  const appsNote = el(doc, "p", { className: "tab-mcp-apps-note" });
176
233
  apps.append(appsNote);
234
+ const known = new Set(mcp.grants.map((g) => g.grantId));
177
235
  const renderGrants = () => {
236
+ for (const grant of mcp.grants) {
237
+ if (known.has(grant.grantId))
238
+ continue;
239
+ known.add(grant.grantId);
240
+ status.textContent = `${clientLabel(grant.client)} is connected.`;
241
+ }
178
242
  const connected = mcp.state === "connected";
179
243
  appList.replaceChildren(...mcp.grants.map((grant) => {
180
244
  const disconnect = button(doc, "Disconnect", () => {
@@ -187,9 +251,14 @@ function showConnectDialog(mcp, connecting, doc) {
187
251
  appsNote.textContent = connected ? "" : "To disconnect an app, connect this page again first.";
188
252
  appsNote.hidden = connected;
189
253
  apps.hidden = mcp.grants.length === 0;
254
+ if (!confirmBox.hidden && !renderQuestion()) {
255
+ confirmBox.hidden = true;
256
+ fresh.focus();
257
+ }
190
258
  };
191
- const onDisconnected = () => {
192
- status.textContent = "Disconnected. AI tools can use this page again after you connect.";
259
+ const onDisconnected = (event) => {
260
+ if (event.detail.reason !== "new_address")
261
+ status.textContent = "Disconnected. AI apps can use this page again after you connect.";
193
262
  renderSession(undefined);
194
263
  renderGrants();
195
264
  renderCode();
@@ -229,5 +298,5 @@ export {
229
298
  showConnectDialog
230
299
  };
231
300
 
232
- //# debugId=8469CA3E90C836D064756E2164756E21
233
- //# sourceMappingURL=ui-168746sb.js.map
301
+ //# debugId=76053A53913824D564756E2164756E21
302
+ //# sourceMappingURL=ui-71qbaznx.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/ui.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\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.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn 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/**\n * Ask whether a consequential tool may run. Resolves `true` only for \"Allow\",\n * which stays disabled for `allowDelayMs` (default 750, at least 500) after\n * the dialog opens, so a click meant for the page cannot approve.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<boolean> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(false);\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tallow.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t);\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) allow.hidden = true;\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\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);\n\tdoc.body.append(dialog);\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\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst allowed = dialog.returnValue === \"allow\";\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(allowed);\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\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code while the relay sends one, and the\n * connected apps with Disconnect. Pairing is on while it is open. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\n\t});\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\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\tcodeLine.setAttribute(\"aria-live\", \"polite\");\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tclose.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\tclose.focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tcopy.textContent = \"Copy\";\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\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\tconst renderGrants = () => {\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}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tclose.focus();\n\t});\n}\n"
6
+ ],
7
+ "mappings": ";AAiBA,IAAI,UAAU;AAEd,SAAS,EAAyC,CACjD,KACA,KACA,QAA4D,CAAC,MAC1D,UACwB;AAAA,EAC3B,MAAM,OAAO,IAAI,cAAc,GAAG;AAAA,EAClC,IAAI,MAAM,cAAc;AAAA,IAAW,KAAK,YAAY,MAAM;AAAA,EAC1D,IAAI,MAAM,OAAO;AAAA,IAAW,KAAK,KAAK,MAAM;AAAA,EAC5C,IAAI,MAAM,SAAS;AAAA,IAAW,KAAK,cAAc,MAAM;AAAA,EACvD,KAAK,OAAO,GAAG,QAAQ;AAAA,EACvB,OAAO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,MAAM,OAAO,WAAW;AAAA,MAC3B,OAAO,cACN;AAAA,IACF,cAAc,SAAS;AAAA,IACvB,aAAa;AAAA,IACb,WAAW;AAAA;AAAA,EAEZ,MAAM,cAAc,MAAM;AAAA,IACzB,cAAc,IAAI,OAAO;AAAA,IACzB,aAAa;AAAA;AAAA,EAGd,IAAI,iBAAiB,eAAe,UAAU;AAAA,EAC9C,IAAI,iBAAiB,gBAAgB,YAAY;AAAA,EACjD,IAAI,iBAAiB,aAAa,WAAW;AAAA,EAC7C,IAAI,iBAAiB,gBAAgB,cAAc;AAAA,EACnD,IAAI,KAAK,OAAO,MAAM;AAAA,EACtB,IAAI,aAAa;AAAA,EACjB,aAAa;AAAA,EACb,WAAW;AAAA,EACX,cAAc,IAAI,OAAO;AAAA,EACzB,WAAW,KACV,CAAC,YAAY,cAAc,OAAO,GAClC,CAAC,UAAmB;AAAA,IACnB,OAAO,cAAc,sBAAsB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,GAElG;AAAA,EAEA,OAAO,IAAI,QAAQ,CAAC,YAAY;AAAA,IAC/B,OAAO,iBACN,SACA,MAAM;AAAA,MACL,IAAI,YAAY;AAAA,MAChB,IAAI,oBAAoB,eAAe,UAAU;AAAA,MACjD,IAAI,oBAAoB,gBAAgB,YAAY;AAAA,MACpD,IAAI,oBAAoB,aAAa,WAAW;AAAA,MAChD,IAAI,oBAAoB,gBAAgB,cAAc;AAAA,MACtD,OAAO,OAAO;AAAA,MACd,QAAQ;AAAA,OAET,EAAE,MAAM,KAAK,CACd;AAAA,IACA,OAAO,UAAU;AAAA,IACjB,MAAM,MAAM;AAAA,GACZ;AAAA;",
8
+ "debugId": "76053A53913824D564756E2164756E21",
9
+ "names": []
10
+ }
package/ui.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The default UI, loaded on demand: the "Connect your AI tool" dialog
2
+ * The default UI, loaded on demand: the "Connect your AI app" dialog
3
3
  * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`
4
4
  * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all
5
5
  * text set with `textContent`. Pages with their own UI use the events and
@@ -19,8 +19,10 @@ export declare function confirmDialog(request: ConfirmRequest, doc: Document, op
19
19
  allowDelayMs?: number;
20
20
  }): Promise<boolean>;
21
21
  /**
22
- * The "Connect your AI tool" dialog: the address with a copy button, short
23
- * instructions, the pairing code while the relay sends one, and the connected
24
- * apps with Disconnect. Pairing is on while it is open.
22
+ * The "Connect your AI app" dialog: the address with Copy and New address,
23
+ * short instructions, the pairing code while the relay sends one, and the
24
+ * connected apps with Disconnect. Pairing is on while it is open. New address
25
+ * asks first when it would disconnect connected apps (`newAddress()` revokes
26
+ * them).
25
27
  */
26
28
  export declare function showConnectDialog(mcp: TabMcp, connecting: Promise<SessionInfo>, doc: Document): Promise<void>;
package/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */
2
2
  export declare const LIBRARY_NAME = "@ractive-ch/tab-mcp-client";
3
- export declare const VERSION = "0.1.0-alpha.0";
3
+ export declare const VERSION = "0.1.0";
@@ -1,4 +0,0 @@
1
- var A=0;function n(e,o,t={},...i){let r=e.createElement(o);if(t.className!==void 0)r.className=t.className;if(t.id!==void 0)r.id=t.id;if(t.text!==void 0)r.textContent=t.text;return r.append(...i),r}function h(e,o,t){let i=n(e,"button",{text:o});return i.type="button",i.addEventListener("click",t),i}function D(e,o,t){let i=`tab-mcp-${++A}`,r=n(e,"dialog",{className:`tab-mcp-dialog ${o}`});r.setAttribute("aria-labelledby",`${i}-title`);let a=r.style;a.setProperty("max-width","var(--tab-mcp-max-width, 34rem)"),a.setProperty("font","var(--tab-mcp-font, inherit)"),a.setProperty("color","var(--tab-mcp-color, CanvasText)"),a.setProperty("background","var(--tab-mcp-background, Canvas)"),a.setProperty("border","var(--tab-mcp-border, 1px solid GrayText)"),a.setProperty("border-radius","var(--tab-mcp-radius, 0.5rem)"),a.setProperty("padding","var(--tab-mcp-padding, 1rem 1.25rem)");let l=n(e,"h2",{id:`${i}-title`,text:t});return l.style.setProperty("margin-top","0"),l.style.setProperty("font-size","var(--tab-mcp-title-size, 1.25em)"),r.append(l),{dialog:r,heading:l}}function M(e){let o=e.host||e.id;return e.name!==void 0&&e.name!==""?`${e.name} (${o})`:o}function k(e){try{return JSON.stringify(e,null,2)}catch{return}}var R=750,H=500;function G(e,o,t={}){let i=Math.max(H,t.allowDelayMs??R);if(e.signal.aborted)return Promise.resolve(!1);let r=e.tool.title??e.tool.name,{dialog:a}=D(o,"tab-mcp-confirm",`Allow ${r}?`),l=h(o,"Don't allow",()=>a.close("deny")),d=h(o,"Allow",()=>{if(!d.disabled)a.close("allow")});d.disabled=!0;let y=n(o,"div",{className:"tab-mcp-actions"},l," ",d),m=k(e.arguments),c=n(o,"pre",{className:"tab-mcp-arguments",text:m??"The arguments cannot be shown, so this call cannot be allowed."});if(m===void 0)d.hidden=!0;return c.style.setProperty("white-space","pre-wrap"),c.style.setProperty("max-height","12rem"),c.style.setProperty("overflow","auto"),c.hidden=Object.keys(e.arguments).length===0,a.append(n(o,"p",{text:`${M(e.client)} wants to run ${r}.`}),n(o,"p",{className:"tab-mcp-description",text:e.tool.description}),c,y),o.body.append(a),new Promise((g)=>{let f=()=>a.close("deny");e.signal.addEventListener("abort",f,{once:!0});let u;a.addEventListener("close",()=>{clearTimeout(u),e.signal.removeEventListener("abort",f);let v=a.returnValue==="allow";a.remove(),g(v)},{once:!0}),a.showModal(),l.focus(),u=setTimeout(()=>{d.disabled=!1},i)})}var O=[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."],["Claude Code","Run: claude mcp add --transport http tools ADDRESS"]];function _(e,o,t){let{dialog:i}=D(t,"tab-mcp-connect","Connect your AI tool"),r=n(t,"p",{className:"tab-mcp-status",text:"Connecting…"});r.setAttribute("role","status");let a=`tab-mcp-${++A}-address`,l=n(t,"label",{text:"Add this address to your AI tool:"});l.htmlFor=a;let d=n(t,"input",{id:a,className:"tab-mcp-address-input"});d.readOnly=!0,d.style.setProperty("width","100%"),d.style.setProperty("font-family","var(--tab-mcp-mono, monospace)");let y=h(t,"Copy",()=>{let s=()=>{y.textContent="Copied"},p=t.defaultView?.navigator?.clipboard;if(p!==void 0)p.writeText(d.value).then(s,()=>d.select());else d.select()}),m=n(t,"div",{className:"tab-mcp-address"},l,d," ",y),c=n(t,"strong",{className:"tab-mcp-code-value"});c.style.setProperty("font-size","var(--tab-mcp-code-size, 1.5em)"),c.style.setProperty("letter-spacing","0.1em");let g=n(t,"p",{className:"tab-mcp-code"},"When asked, enter the code ",c);g.setAttribute("aria-live","polite");let f=n(t,"ul"),u=n(t,"details",{className:"tab-mcp-help"},n(t,"summary",{text:"How do I add it?"}),f),v=n(t,"ul"),C=n(t,"div",{className:"tab-mcp-apps"},n(t,"h3",{text:"Connected"}),v),P=h(t,"Close",()=>i.close()),S=n(t,"div",{className:"tab-mcp-actions"},P);i.append(r,m,g,u,C,S),m.hidden=!0,g.hidden=!0,u.hidden=!0,C.hidden=!0;let x=(s)=>{if(s===void 0){m.hidden=!0,u.hidden=!0;return}d.value=s.address;let p=s.appName??e.appName;r.textContent=p!==void 0?`${p} is ready for your AI tool.`:"This page is ready for your AI tool.",m.hidden=!1,u.hidden=!1,f.replaceChildren(...O.map(([N,I])=>n(t,"li",{},n(t,"strong",{text:N}),`: ${I.replace("ADDRESS",s.address)}`)))},w=()=>{let s=e.pairingCode;c.textContent=s?.code??"",g.hidden=s===void 0},L=n(t,"p",{className:"tab-mcp-apps-note"});C.append(L);let b=()=>{let s=e.state==="connected";v.replaceChildren(...e.grants.map((p)=>{let N=h(t,"Disconnect",()=>{if(!e.revoke(p.grantId))b()});return N.disabled=!s,n(t,"li",{},`${M(p.client)} connected `,N)})),L.textContent=s?"":"To disconnect an app, connect this page again first.",L.hidden=s,C.hidden=e.grants.length===0},E=()=>{r.textContent="Disconnected. AI tools can use this page again after you connect.",x(void 0),b(),w()},T=()=>{x(e.session),b()};return e.addEventListener("pairingcode",w),e.addEventListener("grantschange",b),e.addEventListener("connected",T),e.addEventListener("disconnected",E),t.body.append(i),e.startPairing(),b(),w(),x(e.session),o.then((s)=>x(s),(s)=>{r.textContent=`Could not connect: ${s instanceof Error?s.message:String(s)}`}),new Promise((s)=>{i.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",w),e.removeEventListener("grantschange",b),e.removeEventListener("connected",T),e.removeEventListener("disconnected",E),i.remove(),s()},{once:!0}),i.showModal(),P.focus()})}export{G as confirmDialog,_ as showConnectDialog};
2
-
3
- //# debugId=9D93C7850B75B8BA64756E2164756E21
4
- //# sourceMappingURL=ui-aac2cw9f.min.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/ui.ts"],
4
- "sourcesContent": [
5
- "/**\n * The default UI, loaded on demand: the \"Connect your AI tool\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\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.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn 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/**\n * Ask whether a consequential tool may run. Resolves `true` only for \"Allow\",\n * which stays disabled for `allowDelayMs` (default 750, at least 500) after\n * the dialog opens, so a click meant for the page cannot approve.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<boolean> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(false);\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tallow.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t);\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) allow.hidden = true;\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\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);\n\tdoc.body.append(dialog);\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\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst allowed = dialog.returnValue === \"allow\";\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(allowed);\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\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/**\n * The \"Connect your AI tool\" dialog: the address with a copy button, short\n * instructions, the pairing code while the relay sends one, and the connected\n * apps with Disconnect. Pairing is on while it is open.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI tool\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI tool:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\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);\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\n\t);\n\tcodeLine.setAttribute(\"aria-live\", \"polite\");\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tstatus.textContent =\n\t\t\tappName !== undefined\n\t\t\t\t? `${appName} is ready for your AI tool.`\n\t\t\t\t: \"This page is ready for your AI tool.\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\tconst renderGrants = () => {\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t};\n\tconst onDisconnected = () => {\n\t\tstatus.textContent =\n\t\t\t\"Disconnected. AI tools 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};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tclose.focus();\n\t});\n}\n"
6
- ],
7
- "mappings": "AAgBA,IAAI,EAAU,EAEd,SAAS,CAAyC,CACjD,EACA,EACA,EAA4D,CAAC,KAC1D,EACwB,CAC3B,IAAM,EAAO,EAAI,cAAc,CAAG,EAClC,GAAI,EAAM,YAAc,OAAW,EAAK,UAAY,EAAM,UAC1D,GAAI,EAAM,KAAO,OAAW,EAAK,GAAK,EAAM,GAC5C,GAAI,EAAM,OAAS,OAAW,EAAK,YAAc,EAAM,KAEvD,OAD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AAa,EAAO,EAAK,aAAc,IAAM,CAClD,GAAI,CAAC,EAAI,OAAO,EAAM,OAAO,EAAG,EAAa,EAC7C,EAGD,OADA,EAAW,SAAW,CAAC,EAChB,EACN,EACA,KACA,CAAC,EACD,GAAG,EAAY,EAAM,MAAM,eAC3B,CACD,EACA,CACF,EACA,EAAS,YAAc,EACpB,GACA,uDACH,EAAS,OAAS,EAClB,EAAK,OAAS,EAAI,OAAO,SAAW,GAE/B,EAAiB,IAAM,CAC5B,EAAO,YACN,oEACD,EAAc,MAAS,EACvB,EAAa,EACb,EAAW,GAEN,EAAc,IAAM,CACzB,EAAc,EAAI,OAAO,EACzB,EAAa,GAmBd,OAhBA,EAAI,iBAAiB,cAAe,CAAU,EAC9C,EAAI,iBAAiB,eAAgB,CAAY,EACjD,EAAI,iBAAiB,YAAa,CAAW,EAC7C,EAAI,iBAAiB,eAAgB,CAAc,EACnD,EAAI,KAAK,OAAO,CAAM,EACtB,EAAI,aAAa,EACjB,EAAa,EACb,EAAW,EACX,EAAc,EAAI,OAAO,EACzB,EAAW,KACV,CAAC,IAAY,EAAc,CAAO,EAClC,CAAC,IAAmB,CACnB,EAAO,YAAc,sBAAsB,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,IAElG,EAEO,IAAI,QAAQ,CAAC,IAAY,CAC/B,EAAO,iBACN,QACA,IAAM,CACL,EAAI,YAAY,EAChB,EAAI,oBAAoB,cAAe,CAAU,EACjD,EAAI,oBAAoB,eAAgB,CAAY,EACpD,EAAI,oBAAoB,YAAa,CAAW,EAChD,EAAI,oBAAoB,eAAgB,CAAc,EACtD,EAAO,OAAO,EACd,EAAQ,GAET,CAAE,KAAM,EAAK,CACd,EACA,EAAO,UAAU,EACjB,EAAM,MAAM,EACZ",
8
- "debugId": "9D93C7850B75B8BA64756E2164756E21",
9
- "names": []
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/ui.ts"],
4
- "sourcesContent": [
5
- "/**\n * The default UI, loaded on demand: the \"Connect your AI tool\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\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.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn 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/**\n * Ask whether a consequential tool may run. Resolves `true` only for \"Allow\",\n * which stays disabled for `allowDelayMs` (default 750, at least 500) after\n * the dialog opens, so a click meant for the page cannot approve.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<boolean> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(false);\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tallow.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t);\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) allow.hidden = true;\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\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);\n\tdoc.body.append(dialog);\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\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst allowed = dialog.returnValue === \"allow\";\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(allowed);\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\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/**\n * The \"Connect your AI tool\" dialog: the address with a copy button, short\n * instructions, the pairing code while the relay sends one, and the connected\n * apps with Disconnect. Pairing is on while it is open.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI tool\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI tool:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\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);\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\n\t);\n\tcodeLine.setAttribute(\"aria-live\", \"polite\");\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tstatus.textContent =\n\t\t\tappName !== undefined\n\t\t\t\t? `${appName} is ready for your AI tool.`\n\t\t\t\t: \"This page is ready for your AI tool.\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\tconst renderGrants = () => {\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t};\n\tconst onDisconnected = () => {\n\t\tstatus.textContent =\n\t\t\t\"Disconnected. AI tools 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};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tclose.focus();\n\t});\n}\n"
6
- ],
7
- "mappings": ";AAgBA,IAAI,UAAU;AAEd,SAAS,EAAyC,CACjD,KACA,KACA,QAA4D,CAAC,MAC1D,UACwB;AAAA,EAC3B,MAAM,OAAO,IAAI,cAAc,GAAG;AAAA,EAClC,IAAI,MAAM,cAAc;AAAA,IAAW,KAAK,YAAY,MAAM;AAAA,EAC1D,IAAI,MAAM,OAAO;AAAA,IAAW,KAAK,KAAK,MAAM;AAAA,EAC5C,IAAI,MAAM,SAAS;AAAA,IAAW,KAAK,cAAc,MAAM;AAAA,EACvD,KAAK,OAAO,GAAG,QAAQ;AAAA,EACvB,OAAO;AAAA;AAGR,SAAS,MAAM,CACd,KACA,MACA,SACoB;AAAA,EACpB,MAAM,OAAO,GAAG,KAAK,UAAU,EAAE,KAAK,CAAC;AAAA,EACvC,KAAK,OAAO;AAAA,EACZ,KAAK,iBAAiB,SAAS,OAAO;AAAA,EACtC,OAAO;AAAA;AAGR,SAAS,SAAS,CACjB,KACA,WACA,OAC6D;AAAA,EAC7D,MAAM,KAAK,WAAW,EAAE;AAAA,EACxB,MAAM,SAAS,GAAG,KAAK,UAAU;AAAA,IAChC,WAAW,kBAAkB;AAAA,EAC9B,CAAC;AAAA,EACD,OAAO,aAAa,mBAAmB,GAAG,UAAU;AAAA,EAEpD,MAAM,QAAQ,OAAO;AAAA,EACrB,MAAM,YAAY,aAAa,iCAAiC;AAAA,EAChE,MAAM,YAAY,QAAQ,8BAA8B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