@ractive-ch/tab-mcp-client 0.6.0 → 0.7.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 +73 -8
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +4 -4
- package/cdn/ui-n9c73wge.min.js +72 -0
- package/cdn/ui-n9c73wge.min.js.map +10 -0
- package/index.js +6 -6
- package/index.js.map +4 -4
- package/package.json +1 -1
- package/{ui-htav9g19.js → ui-gkxbbn8v.js} +190 -63
- package/ui-gkxbbn8v.js.map +10 -0
- package/ui.d.ts +40 -3
- package/version.d.ts +1 -1
- package/cdn/ui-yknfss9n.min.js +0 -4
- package/cdn/ui-yknfss9n.min.js.map +0 -10
- package/ui-htav9g19.js.map +0 -10
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ relay. The page connects to the relay and gets an address. The user adds that ad
|
|
|
6
6
|
their AI app and types a pairing code from the page; the AI app then calls the page's
|
|
7
7
|
tools while the tab stays open. Nothing is installed on the user's computer.
|
|
8
8
|
|
|
9
|
-
**Status: 0.
|
|
9
|
+
**Status: 0.7.0.** Until 1.0, a new minor version can still change the API. Which AI apps
|
|
10
10
|
work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
|
|
11
11
|
|
|
12
12
|
## You need a relay
|
|
@@ -38,7 +38,7 @@ Or without a bundler, from a CDN as an ES module:
|
|
|
38
38
|
|
|
39
39
|
```html
|
|
40
40
|
<script type="module">
|
|
41
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
41
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.7.0/cdn/tab-mcp-client.min.js";
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -133,8 +133,16 @@ handles only some calls itself.
|
|
|
133
133
|
1. The user clicks your button. `showConnectDialog()` connects (call it from the click
|
|
134
134
|
handler: browsers that report user activation refuse `connect()` without one) and
|
|
135
135
|
opens the "Connect your AI app" dialog.
|
|
136
|
-
2. The dialog shows the address and short instructions for Claude, ChatGPT
|
|
137
|
-
|
|
136
|
+
2. The dialog shows the address and short instructions for Claude, ChatGPT, Claude Code
|
|
137
|
+
and Codex. The commands for Claude Code and Codex each have a Copy. They name the
|
|
138
|
+
server by a label made from `server.name` that every shell reads as one plain word:
|
|
139
|
+
lower case, letters without marks, each run of other characters as `-`, at most 40
|
|
140
|
+
characters, `tools` if nothing is left ("Bücher" gives `bucher`). The address goes
|
|
141
|
+
into a command only if it has nothing but plain URL characters; otherwise the help
|
|
142
|
+
shows the steps without commands. Codex 0.163 needs its feature `mcp_2026_07_28` for the relay's MCP
|
|
143
|
+
revision, so its command turns that on first (for all of Codex's MCP servers;
|
|
144
|
+
`codex features disable mcp_2026_07_28` turns it off). The user adds the address to
|
|
145
|
+
their AI app.
|
|
138
146
|
3. The AI app opens the relay's sign-in page in the browser. The dialog shows a 6-digit
|
|
139
147
|
code with a Copy button, which the user types or pastes there. The code changes every
|
|
140
148
|
2 minutes and after each use.
|
|
@@ -226,10 +234,67 @@ mcp.addEventListener("toolcallend", (e) => {
|
|
|
226
234
|
});
|
|
227
235
|
```
|
|
228
236
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
237
|
+
### Styling the default dialogs
|
|
238
|
+
|
|
239
|
+
The default dialogs bring their own stylesheet, a constructed stylesheet added to
|
|
240
|
+
`document.adoptedStyleSheets`, so a strict CSP needs no `style-src` exception. It uses
|
|
241
|
+
the page's font and system colours, and follows the page's `color-scheme`: declare
|
|
242
|
+
`color-scheme: light dark` (or `<meta name="color-scheme" content="light dark">`) and the
|
|
243
|
+
dialogs are dark in dark mode. They fit a 360 px wide screen, and they open without
|
|
244
|
+
animation when the user prefers reduced motion.
|
|
245
|
+
|
|
246
|
+
To adjust single values, set these custom properties on `:root` or on `.tab-mcp-dialog`:
|
|
247
|
+
|
|
248
|
+
| Property | Default | |
|
|
249
|
+
| --- | --- | --- |
|
|
250
|
+
| `--tab-mcp-font` | `inherit` | font shorthand |
|
|
251
|
+
| `--tab-mcp-color` | `CanvasText` | text |
|
|
252
|
+
| `--tab-mcp-background` | `Canvas` | background |
|
|
253
|
+
| `--tab-mcp-muted` | the text colour at 72 % | secondary text |
|
|
254
|
+
| `--tab-mcp-surface` | the text colour at 6 % | the code box, the address, the arguments |
|
|
255
|
+
| `--tab-mcp-accent` | the text colour | background of the primary button |
|
|
256
|
+
| `--tab-mcp-accent-text` | the background colour | text of the primary button |
|
|
257
|
+
| `--tab-mcp-danger` | dark red, light red in dark mode | Disconnect buttons |
|
|
258
|
+
| `--tab-mcp-focus` | the text colour | focus ring |
|
|
259
|
+
| `--tab-mcp-border` | `1px solid` the text colour at 22 % | border of the dialog |
|
|
260
|
+
| `--tab-mcp-radius` | `0.75rem` | corners of the dialog (buttons and boxes: 60 % of it) |
|
|
261
|
+
| `--tab-mcp-padding` | `clamp(1rem, 5vw, 1.5rem)` | |
|
|
262
|
+
| `--tab-mcp-max-width` | `34rem` | |
|
|
263
|
+
| `--tab-mcp-shadow` | `0 1rem 3rem rgb(0 0 0 / 0.3)` | |
|
|
264
|
+
| `--tab-mcp-backdrop` | `rgb(0 0 0 / 0.4)` | behind the dialog |
|
|
265
|
+
| `--tab-mcp-title-size` | `1.25em` | |
|
|
266
|
+
| `--tab-mcp-mono` | `ui-monospace, …, monospace` | the address, the code, the arguments |
|
|
267
|
+
| `--tab-mcp-code-size` | `2em` | the pairing code |
|
|
268
|
+
| `--tab-mcp-arguments-height` | `12rem` | the arguments scroll beyond this |
|
|
269
|
+
|
|
270
|
+
For more, write CSS for the class names. Each of the dialogs' rules has the specificity
|
|
271
|
+
of one class, so the page's rules for elements (`button { … }`, a reset's
|
|
272
|
+
`* { border-width: 0 }`) do not change them. The rules for hover, focus and disabled, and
|
|
273
|
+
for the primary and danger buttons, have one class and two elements (0,1,2), so the page's
|
|
274
|
+
`button:hover`, `button:focus` or `button:disabled` (0,1,1) do not change those either. A
|
|
275
|
+
rule with two classes, such as `.tab-mcp-dialog .tab-mcp-primary` (0,2,0), wins over all
|
|
276
|
+
of them. A page rule of one element and one pseudo-class still changes a property that the
|
|
277
|
+
dialogs set only in their base rules (for example `button:hover { padding: 0 }`). Write
|
|
278
|
+
overrides outside cascade layers: the dialogs' rules are not in a layer, so they win over
|
|
279
|
+
any layered rule. Both dialogs are `dialog.tab-mcp-dialog`; the connect dialog is
|
|
280
|
+
`.tab-mcp-connect` (with `.tab-mcp-status`, `.tab-mcp-address`, `.tab-mcp-code`,
|
|
281
|
+
`.tab-mcp-code-value`, `.tab-mcp-help`, `.tab-mcp-apps`, `.tab-mcp-app`,
|
|
282
|
+
`.tab-mcp-new-address-question`, `.tab-mcp-actions`), the confirmation is
|
|
283
|
+
`.tab-mcp-confirm` (with `.tab-mcp-description`, `.tab-mcp-arguments`,
|
|
284
|
+
`.tab-mcp-always-note`, and the buttons `.tab-mcp-deny`, `.tab-mcp-allow`,
|
|
285
|
+
`.tab-mcp-always`). Buttons are `.tab-mcp-primary` (the one next step: Copy the
|
|
286
|
+
address, Done, and "Don't allow", the safe choice), `.tab-mcp-danger` (Disconnect and
|
|
287
|
+
"Disconnect and get new address") or plain; every Copy button is also `.tab-mcp-copy`, and
|
|
288
|
+
the Disconnect buttons in the apps list are `.tab-mcp-disconnect`. For example:
|
|
289
|
+
|
|
290
|
+
```css
|
|
291
|
+
:root {
|
|
292
|
+
--tab-mcp-accent: #1f5fbf;
|
|
293
|
+
--tab-mcp-accent-text: #fff;
|
|
294
|
+
--tab-mcp-radius: 0.5rem;
|
|
295
|
+
}
|
|
296
|
+
.tab-mcp-dialog .tab-mcp-primary { text-transform: uppercase; }
|
|
297
|
+
```
|
|
233
298
|
|
|
234
299
|
## React
|
|
235
300
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var S,m,f,p=(e,t)=>{for(var[n,i,o]of S||[])for(var r=[e],a=globalThis,s=a.document,d,h,u,c,l;h=r.pop();)if(!m[h]&&(u=i[h])){m[h]=1;for(c=1;c<u.length;c++)r.push(o[u[c]]);if(!t&&h!==e&&(d=s&&s.head)){if(f===void 0)f=(c=s.querySelector("meta[property=csp-nonce]"))&&(c.nonce||c.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",f)l.nonce=f;l.href=new a.URL(u[0],n),d.appendChild(l)}}},M=(e,t,n,i)=>{for(var o={},r=0;r<t.length;r++)o[t[r]]=n[r];(S||=[]).push([e,o,t]),m||={},p(t[i],1)};M(import.meta.url,["
|
|
2
|
-
class y{#e=new Map;has(e,t){return this.#e.get(e)?.has(t)===!0}add(e,t){let n=this.#e.get(e)??new Set;n.add(t),this.#e.set(e,n)}keepGrants(e){let t=new Set(e);for(let n of this.#e.keys())if(!t.has(n))this.#e.delete(n)}keepTools(e){let t=new Set(e);for(let n of this.#e.values())for(let i of n)if(!t.has(i))n.delete(i)}}var L=/^[A-Za-z0-9_.-]{1,128}$/;function v(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function E(e,t=0){if(t>64||typeof e!=="object"||e===null)return!1;if(!Array.isArray(e)&&"x-mcp-header"in e)return!0;return Object.values(e).some((n)=>E(n,t+1))}function P(e,t){let n=e;for(let i of t.split("/").slice(1)){let o=decodeURIComponent(i).replaceAll("~1","/").replaceAll("~0","~");if(typeof n!=="object"||n===null||!Object.hasOwn(n,o))return;n=n[o]}return n}function k(e){let t=new Set,n=[],i=[],o=(r,a)=>{if(a>64||typeof r!=="object"||r===null)return;if(!Array.isArray(r)){let s=r;if(typeof s.$anchor==="string")t.add(s.$anchor);if(typeof s.$ref==="string")n.push(s.$ref);if(typeof s.pattern==="string")i.push(s.pattern);let d=s.patternProperties;if(typeof d==="object"&&d!==null)i.push(...Object.keys(d))}for(let s of Object.values(r))o(s,a+1)};o(e,0);for(let r of i)try{new RegExp(r,"u")}catch{return`pattern ${JSON.stringify(r)} is not a valid regular expression`}for(let r of n){if(!r.startsWith("#"))return`$ref ${JSON.stringify(r)} points outside the schema`;let a=r.slice(1);if(!(a===""||(a.startsWith("/")?P(e,a)!==void 0:t.has(a))))return`$ref ${JSON.stringify(r)} does not resolve`}return}function x(e){if(!v(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:i,inputSchema:o,execute:r,annotations:a}=e;if(typeof t!=="string"||!L.test(t))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(t)})`);if(typeof i!=="string"||i.trim()==="")throw TypeError(`registerTool: tool ${t} needs a description`);if(n!==void 0&&typeof n!=="string")throw TypeError(`registerTool: the title of ${t} must be a string`);if(typeof r!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let s=o??{type:"object"};if(!v(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${t} must be a JSON Schema object with "type": "object"`);if(E(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let d=k(s);if(d!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${d}`);let h;try{h=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${t} must be JSON`)}if(a!==void 0&&!v(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let u={};for(let[c,l]of Object.entries(a??{}))if(typeof l==="boolean")u[c]=l;return{name:t,title:n,description:i,inputSchema:h,annotations:u,execute:r}}class w{#e=new Map;#r=new Set;#a;register(e,t={}){let n=x(e),{signal:i}=t;if(i?.aborted)return;if(this.#e.has(n.name))throw new DOMException(`registerTool: a tool named ${n.name} is already registered`,"InvalidStateError");this.#a?.(n),this.#e.set(n.name,n),i?.addEventListener("abort",()=>this.remove(n),{once:!0}),this.#o()}setCompiler(e){this.#a??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),this.#o()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#r.add(e),()=>this.#r.delete(e)}#o(){for(let e of[...this.#r])e()}}var D=/^[A-Za-z0-9_-]{43}$/;function N(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function j(){return N(crypto.getRandomValues(new Uint8Array(32)))}function b(e){return typeof e==="string"&&D.test(e)}function _(){try{return globalThis.localStorage??null}catch{return null}}class g{#e;#r;#a;#o;#g;constructor(e,t,n){this.#e=e===void 0?_():e,this.#r=t,this.#a=n,this.#o=n===void 0?void 0:`${n}#moved`}get(){let e=null;try{if(e=this.#e?.getItem(this.#r)??null,!b(e)&&this.#a!==void 0&&this.#o!==void 0&&this.#e?.getItem(this.#o)==null){let t=this.#e?.getItem(this.#a)??null;if(b(t))e=t,this.#m(t)}}catch{}if(b(e))return this.#g=e,e;return this.#g??this.rotate()}rotate(){let e=j();return this.#g=e,this.#m(e),e}#m(e){try{if(this.#e?.setItem(this.#r,e),this.#o!==void 0)this.#e?.setItem(this.#o,this.#r)}catch{}}}var C="@ractive-ch/tab-mcp-client",T="0.6.0";var K=new Set(["localhost","127.0.0.1","[::1]"]),I=[5000,1e4,20000,40000,60000],R=new Set(["network","heartbeat","shutdown"]);function G(e){if(e===!1)return;if(e===void 0||e===!0)return I;let t=e.delaysMs??I;if(!Array.isArray(t)||t.length===0||!t.every((n)=>typeof n==="number"&&n>=0&&n<2147483648))throw TypeError("TabMcp: reconnect.delaysMs: a non-empty list of ms");return[...t]}function O(e,t){if(t===void 0)return;if(typeof t!=="number"||!Number.isFinite(t)||t<0||t>=2147483648)throw TypeError(`TabMcp: ${e} must be a number of milliseconds`);return t}function H(e){return Object.freeze({...e,client:Object.freeze({...e.client})})}function J(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((t)=>{let n=t.codePointAt(0)??0;return n<32||n>=127&&n<=159})}function U(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let n=t.protocol==="https:"||t.protocol==="wss:";if(!n&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!n&&!K.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let i=`${n?"https:":"http:"}//${t.host}`,o=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=o.endsWith("/tab")?o:`${o}/tab`,t.search="",t.hash="",{url:t.href,origin:i}}function z(e){try{return new URL(e).host}catch{return""}}function W(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,pairing:e.pairing==="oidc"?"oidc":"code",expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}class A extends EventTarget{#e=new w;#r;#a;#o;#g;#m;#I;#L;#w="none";#P;#l=0;#k;#n="disconnected";#h;#u=Object.freeze([]);#b=new y;#f=!1;#R;#i;#s;#y=0;#x;#d;#p;#T;#S=!1;#E;constructor(e){super();let{url:t,origin:n}=U(e.relay),{server:i,appName:o}=e;if(typeof i?.name!=="string"||typeof i.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(o!==void 0&&!J(o))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");this.#m=t,this.#r={...i},this.#a=o,this.#o=e.onConfirm,this.#g=O("confirmDelayMs",e.confirmDelayMs),this.#L=e.identityAssertion,this.#k=O("identityTimeoutMs",e.identityTimeoutMs)??15000,this.#x=G(e.reconnect),this.#I=e.storageKey===void 0?new g(e.storage,`tab-mcp:secret:${n}:${encodeURIComponent(i.name)}`,`tab-mcp:secret:${n}`):new g(e.storage,e.storageKey),this.#e.onChange(()=>{let r=this.tools;this.#b.keepTools(r),this.#t("toolschange",{tools:r})})}registerTool(e,t={}){try{this.#e.register(e,t)}catch(n){return Promise.reject(n)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#n}get session(){return this.#h}get address(){return this.#h?.address}get appName(){return this.#h?.appName??this.#a}get grants(){return this.#u}get reconnecting(){return this.#d}get identity(){return this.#w}get identityMessage(){return this.#P}refreshIdentity(){let e=this.#h,t=this.#L;if(this.#n!=="connected"||e===void 0||t===void 0)return Promise.resolve(!1);let n=++this.#l,i=this.#i;this.#c("pending");let o=setTimeout(()=>{if(n!==this.#l||this.#w!=="pending")return;this.#l++,this.#c("none")},this.#k);return new Promise((r)=>{let a=(s)=>{if(s.detail.state==="pending")return;this.removeEventListener("identitychange",a),clearTimeout(o),r(s.detail.state==="bound")};this.addEventListener("identitychange",a),Promise.resolve().then(()=>t({address:e.address,sessionId:e.sessionId})).then((s)=>{if(n!==this.#l||this.#i!==i)return;if(typeof s!=="string"||s===""){this.#c("none");return}if(i?.send({type:"identity",assertion:s,round:n})!==!0)this.#c("none")},(s)=>{if(n!==this.#l)return;this.#t("error",{error:s instanceof Error?s:Error(String(s))}),this.#c("none")})})}signOut(){if(this.#l++,this.#c("none"),this.#n!=="connected")return!1;return this.#i?.send({type:"identity.logout"})===!0}get pairing(){return this.#f}get pairingCode(){return this.#R}connect(e={}){if(this.#n==="connected"&&this.#h!==void 0)return Promise.resolve(this.#h);if(this.#s!==void 0){if(this.#d!==void 0)this.#S=!0;return this.#s}if(this.#d!==void 0)return this.#O(!0);let t=globalThis.navigator?.userActivation;if(e.resume!==!0&&t!==void 0&&!t.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));return this.#$()}#$(){this.#v("connecting");let e=this.#j(this.#y);return this.#s=e,e.then(()=>{if(this.#s===e)this.#s=void 0},()=>{if(this.#s!==e)return;this.#s=void 0,this.#i=void 0,this.#v("disconnected")}),e}async#j(e){let{openConnection:t,compileRegistry:n}=await (p("nygehv52"),import("./connection-nygehv52.min.js"));for(let r of n(this.#e))this.#t("error",{error:r});if(e!==this.#y)throw new DOMException("The connection was cancelled","AbortError");let i={},o=t(this.#H(i),this.#m,this.#I.get());return i.connection=o,this.#i=o,o.ready}disconnect(){this.#D("user")}newAddress(){let e=this.#n!=="disconnected"||this.#d!==void 0;if(this.#n==="connected")this.#i?.send({type:"grants.revokeAll"});return this.#D("new_address"),this.#I.rotate(),e?this.connect():Promise.resolve(void 0)}#D(e){this.#A(),this.#y++;let t=this.#i,n=this.#n==="connected";if(this.#i=void 0,this.#s=void 0,t?.close(e),this.#n==="disconnected")return;if(this.#h=void 0,this.#C(void 0),this.#l++,this.#c("none"),this.#v("disconnected"),n)this.#t("disconnected",{reason:e,code:1000})}#N(e,t){let n=this.#x;if(n===void 0)return;let i=n[Math.min(t,n.length)-1]??0;clearTimeout(this.#p),this.#p=setTimeout(()=>{this.#O().catch(()=>{})},i),this.#_(),this.#d={reason:e,attempt:t,at:Date.now()+i},this.#t("reconnecting",this.#d)}#O(e=!1){if(clearTimeout(this.#p),this.#p=void 0,this.#s!==void 0)return this.#s;let t=this.#d;this.#S=e;let n=this.#$();return n.catch((i)=>{let o=this.#S;if(this.#S=!1,t===void 0||this.#d!==t)return;let r=i?.reason;if(r===void 0||R.has(r)){this.#N(t.reason,t.attempt+1);return}this.#A(o?void 0:i instanceof Error?i:Error(String(i)))}),n}#_(){if(this.#T!==void 0)return;let e=globalThis,t=globalThis.document,n=()=>{if(this.#p!==void 0)this.#O().catch(()=>{})},i=()=>{if(t?.visibilityState!=="hidden")n()};t?.addEventListener("visibilitychange",i),e.addEventListener?.("online",n),this.#T=()=>{t?.removeEventListener("visibilitychange",i),e.removeEventListener?.("online",n)}}#A(e){if(clearTimeout(this.#p),this.#p=void 0,this.#T?.(),this.#T=void 0,this.#d===void 0)return;if(this.#d=void 0,e!==void 0)this.#t("error",{error:e});this.#t("reconnecting",null)}startPairing(){if(this.#f)return;if(this.#f=!0,this.#n==="connected")this.#i?.send({type:"pairing.start"})}stopPairing(){if(!this.#f)return;if(this.#f=!1,this.#n==="connected")this.#i?.send({type:"pairing.stop"});this.#C(void 0)}revoke(e){if(this.#n!=="connected")return!1;return this.#i?.send({type:"grant.revoke",grantId:e})===!0}showConnectDialog(e={}){let t=e.document??globalThis.document,n=this.#E;if(n!==void 0)return n.doc===t?n.shown:Promise.reject(new DOMException("showConnectDialog: the dialog is already open in another document","InvalidStateError"));let i=this.#K(t).finally(()=>{if(this.#E?.shown===i)this.#E=void 0});return this.#E={doc:t,shown:i},i}async#K(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("yknfss9n"),import("./ui-yknfss9n.min.js"));await n(this,t,e)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#t(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#v(e){if(this.#n===e)return;this.#n=e,this.#t("statechange",{state:e})}#c(e,t){if(this.#w===e&&t===void 0)return;this.#w=e,this.#P=e==="refused"?t:void 0,this.#t("identitychange",t===void 0?{state:e}:{state:e,message:t})}#C(e){if(this.#R===void 0&&e===void 0)return;this.#R=e,this.#t("pairingcode",e??null)}#M(e){this.#u=Object.freeze(e.map(H)),this.#b.keepGrants(e.map((t)=>t.grantId)),this.#t("grantschange",{grants:this.#u})}#G(e){if(this.#o!==void 0){let t=this.#o;return Promise.resolve().then(()=>t(e)).then((n)=>n===!0)}return this.confirmInPage(e)}confirmInPage(e){let{grantId:t}=e.client;if(this.#b.has(t,e.tool.name))return Promise.resolve(!0);let n=globalThis.document;if(n===void 0)return Promise.resolve(!1);let i=this.#g;return (p("yknfss9n"),import("./ui-yknfss9n.min.js")).then((o)=>o.confirmDialog(e,n,i===void 0?{}:{allowDelayMs:i})).then((o)=>{if(o==="always"&&this.#u.some((r)=>r.grantId===t))this.#b.add(t,e.tool.name);return o!=="deny"})}#H(e){let t=()=>e.connection!==void 0&&this.#i===e.connection;return{registry:this.#e,server:this.#r,appName:this.#a,library:{name:C,version:T},confirm:(n)=>this.#G(n),toolCallStarted:(n)=>this.#t("toolcall",n),toolCallEnded:(n)=>this.#t("toolcallend",n),clientFor:(n)=>{let i=this.#u.find((r)=>r.grantId===n.grantId),o={grantId:n.grantId,id:n.clientId,host:z(n.clientId)};if(i!==void 0)o.name=i.client.name;return o},sessionStarted:(n)=>{let i=W(n);if(!t())return i;if(this.#h=i,this.#A(),this.#v("connected"),this.#M([...n.grants]),this.#f)this.#i?.send({type:"pairing.start"});if(this.#t("connected",i),i.pairing==="oidc")this.refreshIdentity();return i},pairingCode:(n)=>{if(t()&&this.#f)this.#C(n)},grantAdded:(n)=>{if(!t())return;this.#M([...this.#u.filter((i)=>i.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#M(this.#u.filter((i)=>i.grantId!==n))},replaced:()=>{if(t())this.#t("replaced",null)},identityResult:(n,i,o)=>{if(!t())return;if(i!==this.#l)return;if(n)this.#c("bound");else this.#c("refused",o??"")},error:(n)=>{if(t())this.#t("error",{error:n})},closed:(n,i)=>{if(!t())return;let o=this.#y;if(this.#i=void 0,this.#h=void 0,this.#C(void 0),this.#l++,this.#c("none"),this.#v("disconnected"),this.#t("disconnected",{reason:n,code:i}),R.has(n)&&this.#y===o&&this.#n==="disconnected"&&this.#s===void 0)this.#N(n,1)}}}}export{A as TabMcp,T as VERSION};
|
|
1
|
+
var S,m,f,p=(e,t)=>{for(var[n,i,o]of S||[])for(var r=[e],a=globalThis,s=a.document,d,h,u,c,l;h=r.pop();)if(!m[h]&&(u=i[h])){m[h]=1;for(c=1;c<u.length;c++)r.push(o[u[c]]);if(!t&&h!==e&&(d=s&&s.head)){if(f===void 0)f=(c=s.querySelector("meta[property=csp-nonce]"))&&(c.nonce||c.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",f)l.nonce=f;l.href=new a.URL(u[0],n),d.appendChild(l)}}},M=(e,t,n,i)=>{for(var o={},r=0;r<t.length;r++)o[t[r]]=n[r];(S||=[]).push([e,o,t]),m||={},p(t[i],1)};M(import.meta.url,["7093nb1r","nygehv52","n9c73wge"],[["./tab-mcp-client.min.js"],["./connection-nygehv52.min.js"],["./ui-n9c73wge.min.js"]],0);
|
|
2
|
+
class y{#e=new Map;has(e,t){return this.#e.get(e)?.has(t)===!0}add(e,t){let n=this.#e.get(e)??new Set;n.add(t),this.#e.set(e,n)}keepGrants(e){let t=new Set(e);for(let n of this.#e.keys())if(!t.has(n))this.#e.delete(n)}keepTools(e){let t=new Set(e);for(let n of this.#e.values())for(let i of n)if(!t.has(i))n.delete(i)}}var L=/^[A-Za-z0-9_.-]{1,128}$/;function v(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function E(e,t=0){if(t>64||typeof e!=="object"||e===null)return!1;if(!Array.isArray(e)&&"x-mcp-header"in e)return!0;return Object.values(e).some((n)=>E(n,t+1))}function P(e,t){let n=e;for(let i of t.split("/").slice(1)){let o=decodeURIComponent(i).replaceAll("~1","/").replaceAll("~0","~");if(typeof n!=="object"||n===null||!Object.hasOwn(n,o))return;n=n[o]}return n}function k(e){let t=new Set,n=[],i=[],o=(r,a)=>{if(a>64||typeof r!=="object"||r===null)return;if(!Array.isArray(r)){let s=r;if(typeof s.$anchor==="string")t.add(s.$anchor);if(typeof s.$ref==="string")n.push(s.$ref);if(typeof s.pattern==="string")i.push(s.pattern);let d=s.patternProperties;if(typeof d==="object"&&d!==null)i.push(...Object.keys(d))}for(let s of Object.values(r))o(s,a+1)};o(e,0);for(let r of i)try{new RegExp(r,"u")}catch{return`pattern ${JSON.stringify(r)} is not a valid regular expression`}for(let r of n){if(!r.startsWith("#"))return`$ref ${JSON.stringify(r)} points outside the schema`;let a=r.slice(1);if(!(a===""||(a.startsWith("/")?P(e,a)!==void 0:t.has(a))))return`$ref ${JSON.stringify(r)} does not resolve`}return}function x(e){if(!v(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:i,inputSchema:o,execute:r,annotations:a}=e;if(typeof t!=="string"||!L.test(t))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(t)})`);if(typeof i!=="string"||i.trim()==="")throw TypeError(`registerTool: tool ${t} needs a description`);if(n!==void 0&&typeof n!=="string")throw TypeError(`registerTool: the title of ${t} must be a string`);if(typeof r!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let s=o??{type:"object"};if(!v(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${t} must be a JSON Schema object with "type": "object"`);if(E(s))throw TypeError(`registerTool: ${t} uses x-mcp-header, which tab-mcp does not support`);let d=k(s);if(d!==void 0)throw TypeError(`registerTool: the inputSchema of ${t}: ${d}`);let h;try{h=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${t} must be JSON`)}if(a!==void 0&&!v(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let u={};for(let[c,l]of Object.entries(a??{}))if(typeof l==="boolean")u[c]=l;return{name:t,title:n,description:i,inputSchema:h,annotations:u,execute:r}}class w{#e=new Map;#o=new Set;#a;register(e,t={}){let n=x(e),{signal:i}=t;if(i?.aborted)return;if(this.#e.has(n.name))throw new DOMException(`registerTool: a tool named ${n.name} is already registered`,"InvalidStateError");this.#a?.(n),this.#e.set(n.name,n),i?.addEventListener("abort",()=>this.remove(n),{once:!0}),this.#r()}setCompiler(e){this.#a??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),this.#r()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#o.add(e),()=>this.#o.delete(e)}#r(){for(let e of[...this.#o])e()}}var D=/^[A-Za-z0-9_-]{43}$/;function N(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function j(){return N(crypto.getRandomValues(new Uint8Array(32)))}function b(e){return typeof e==="string"&&D.test(e)}function _(){try{return globalThis.localStorage??null}catch{return null}}class g{#e;#o;#a;#r;#g;constructor(e,t,n){this.#e=e===void 0?_():e,this.#o=t,this.#a=n,this.#r=n===void 0?void 0:`${n}#moved`}get(){let e=null;try{if(e=this.#e?.getItem(this.#o)??null,!b(e)&&this.#a!==void 0&&this.#r!==void 0&&this.#e?.getItem(this.#r)==null){let t=this.#e?.getItem(this.#a)??null;if(b(t))e=t,this.#m(t)}}catch{}if(b(e))return this.#g=e,e;return this.#g??this.rotate()}rotate(){let e=j();return this.#g=e,this.#m(e),e}#m(e){try{if(this.#e?.setItem(this.#o,e),this.#r!==void 0)this.#e?.setItem(this.#r,this.#o)}catch{}}}var C="@ractive-ch/tab-mcp-client",T="0.7.0";var K=new Set(["localhost","127.0.0.1","[::1]"]),I=[5000,1e4,20000,40000,60000],R=new Set(["network","heartbeat","shutdown"]);function G(e){if(e===!1)return;if(e===void 0||e===!0)return I;let t=e.delaysMs??I;if(!Array.isArray(t)||t.length===0||!t.every((n)=>typeof n==="number"&&n>=0&&n<2147483648))throw TypeError("TabMcp: reconnect.delaysMs: a non-empty list of ms");return[...t]}function O(e,t){if(t===void 0)return;if(typeof t!=="number"||!Number.isFinite(t)||t<0||t>=2147483648)throw TypeError(`TabMcp: ${e} must be a number of milliseconds`);return t}function H(e){return Object.freeze({...e,client:Object.freeze({...e.client})})}function J(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((t)=>{let n=t.codePointAt(0)??0;return n<32||n>=127&&n<=159})}function U(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let n=t.protocol==="https:"||t.protocol==="wss:";if(!n&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!n&&!K.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let i=`${n?"https:":"http:"}//${t.host}`,o=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=o.endsWith("/tab")?o:`${o}/tab`,t.search="",t.hash="",{url:t.href,origin:i}}function z(e){try{return new URL(e).host}catch{return""}}function W(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,pairing:e.pairing==="oidc"?"oidc":"code",expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}class A extends EventTarget{#e=new w;#o;#a;#r;#g;#m;#I;#L;#w="none";#P;#l=0;#k;#n="disconnected";#h;#u=Object.freeze([]);#b=new y;#f=!1;#R;#i;#s;#y=0;#x;#d;#p;#T;#S=!1;#E;constructor(e){super();let{url:t,origin:n}=U(e.relay),{server:i,appName:o}=e;if(typeof i?.name!=="string"||typeof i.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(o!==void 0&&!J(o))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");this.#m=t,this.#o={...i},this.#a=o,this.#r=e.onConfirm,this.#g=O("confirmDelayMs",e.confirmDelayMs),this.#L=e.identityAssertion,this.#k=O("identityTimeoutMs",e.identityTimeoutMs)??15000,this.#x=G(e.reconnect),this.#I=e.storageKey===void 0?new g(e.storage,`tab-mcp:secret:${n}:${encodeURIComponent(i.name)}`,`tab-mcp:secret:${n}`):new g(e.storage,e.storageKey),this.#e.onChange(()=>{let r=this.tools;this.#b.keepTools(r),this.#t("toolschange",{tools:r})})}registerTool(e,t={}){try{this.#e.register(e,t)}catch(n){return Promise.reject(n)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#n}get session(){return this.#h}get address(){return this.#h?.address}get appName(){return this.#h?.appName??this.#a}get grants(){return this.#u}get reconnecting(){return this.#d}get identity(){return this.#w}get identityMessage(){return this.#P}refreshIdentity(){let e=this.#h,t=this.#L;if(this.#n!=="connected"||e===void 0||t===void 0)return Promise.resolve(!1);let n=++this.#l,i=this.#i;this.#c("pending");let o=setTimeout(()=>{if(n!==this.#l||this.#w!=="pending")return;this.#l++,this.#c("none")},this.#k);return new Promise((r)=>{let a=(s)=>{if(s.detail.state==="pending")return;this.removeEventListener("identitychange",a),clearTimeout(o),r(s.detail.state==="bound")};this.addEventListener("identitychange",a),Promise.resolve().then(()=>t({address:e.address,sessionId:e.sessionId})).then((s)=>{if(n!==this.#l||this.#i!==i)return;if(typeof s!=="string"||s===""){this.#c("none");return}if(i?.send({type:"identity",assertion:s,round:n})!==!0)this.#c("none")},(s)=>{if(n!==this.#l)return;this.#t("error",{error:s instanceof Error?s:Error(String(s))}),this.#c("none")})})}signOut(){if(this.#l++,this.#c("none"),this.#n!=="connected")return!1;return this.#i?.send({type:"identity.logout"})===!0}get pairing(){return this.#f}get pairingCode(){return this.#R}connect(e={}){if(this.#n==="connected"&&this.#h!==void 0)return Promise.resolve(this.#h);if(this.#s!==void 0){if(this.#d!==void 0)this.#S=!0;return this.#s}if(this.#d!==void 0)return this.#O(!0);let t=globalThis.navigator?.userActivation;if(e.resume!==!0&&t!==void 0&&!t.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));return this.#$()}#$(){this.#v("connecting");let e=this.#j(this.#y);return this.#s=e,e.then(()=>{if(this.#s===e)this.#s=void 0},()=>{if(this.#s!==e)return;this.#s=void 0,this.#i=void 0,this.#v("disconnected")}),e}async#j(e){let{openConnection:t,compileRegistry:n}=await (p("nygehv52"),import("./connection-nygehv52.min.js"));for(let r of n(this.#e))this.#t("error",{error:r});if(e!==this.#y)throw new DOMException("The connection was cancelled","AbortError");let i={},o=t(this.#H(i),this.#m,this.#I.get());return i.connection=o,this.#i=o,o.ready}disconnect(){this.#D("user")}newAddress(){let e=this.#n!=="disconnected"||this.#d!==void 0;if(this.#n==="connected")this.#i?.send({type:"grants.revokeAll"});return this.#D("new_address"),this.#I.rotate(),e?this.connect():Promise.resolve(void 0)}#D(e){this.#A(),this.#y++;let t=this.#i,n=this.#n==="connected";if(this.#i=void 0,this.#s=void 0,t?.close(e),this.#n==="disconnected")return;if(this.#h=void 0,this.#C(void 0),this.#l++,this.#c("none"),this.#v("disconnected"),n)this.#t("disconnected",{reason:e,code:1000})}#N(e,t){let n=this.#x;if(n===void 0)return;let i=n[Math.min(t,n.length)-1]??0;clearTimeout(this.#p),this.#p=setTimeout(()=>{this.#O().catch(()=>{})},i),this.#_(),this.#d={reason:e,attempt:t,at:Date.now()+i},this.#t("reconnecting",this.#d)}#O(e=!1){if(clearTimeout(this.#p),this.#p=void 0,this.#s!==void 0)return this.#s;let t=this.#d;this.#S=e;let n=this.#$();return n.catch((i)=>{let o=this.#S;if(this.#S=!1,t===void 0||this.#d!==t)return;let r=i?.reason;if(r===void 0||R.has(r)){this.#N(t.reason,t.attempt+1);return}this.#A(o?void 0:i instanceof Error?i:Error(String(i)))}),n}#_(){if(this.#T!==void 0)return;let e=globalThis,t=globalThis.document,n=()=>{if(this.#p!==void 0)this.#O().catch(()=>{})},i=()=>{if(t?.visibilityState!=="hidden")n()};t?.addEventListener("visibilitychange",i),e.addEventListener?.("online",n),this.#T=()=>{t?.removeEventListener("visibilitychange",i),e.removeEventListener?.("online",n)}}#A(e){if(clearTimeout(this.#p),this.#p=void 0,this.#T?.(),this.#T=void 0,this.#d===void 0)return;if(this.#d=void 0,e!==void 0)this.#t("error",{error:e});this.#t("reconnecting",null)}startPairing(){if(this.#f)return;if(this.#f=!0,this.#n==="connected")this.#i?.send({type:"pairing.start"})}stopPairing(){if(!this.#f)return;if(this.#f=!1,this.#n==="connected")this.#i?.send({type:"pairing.stop"});this.#C(void 0)}revoke(e){if(this.#n!=="connected")return!1;return this.#i?.send({type:"grant.revoke",grantId:e})===!0}showConnectDialog(e={}){let t=e.document??globalThis.document,n=this.#E;if(n!==void 0)return n.doc===t?n.shown:Promise.reject(new DOMException("showConnectDialog: the dialog is already open in another document","InvalidStateError"));let i=this.#K(t).finally(()=>{if(this.#E?.shown===i)this.#E=void 0});return this.#E={doc:t,shown:i},i}async#K(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (p("n9c73wge"),import("./ui-n9c73wge.min.js"));await n(this,t,e,this.#o.name)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#t(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#v(e){if(this.#n===e)return;this.#n=e,this.#t("statechange",{state:e})}#c(e,t){if(this.#w===e&&t===void 0)return;this.#w=e,this.#P=e==="refused"?t:void 0,this.#t("identitychange",t===void 0?{state:e}:{state:e,message:t})}#C(e){if(this.#R===void 0&&e===void 0)return;this.#R=e,this.#t("pairingcode",e??null)}#M(e){this.#u=Object.freeze(e.map(H)),this.#b.keepGrants(e.map((t)=>t.grantId)),this.#t("grantschange",{grants:this.#u})}#G(e){if(this.#r!==void 0){let t=this.#r;return Promise.resolve().then(()=>t(e)).then((n)=>n===!0)}return this.confirmInPage(e)}confirmInPage(e){let{grantId:t}=e.client;if(this.#b.has(t,e.tool.name))return Promise.resolve(!0);let n=globalThis.document;if(n===void 0)return Promise.resolve(!1);let i=this.#g;return (p("n9c73wge"),import("./ui-n9c73wge.min.js")).then((o)=>o.confirmDialog(e,n,i===void 0?{}:{allowDelayMs:i})).then((o)=>{if(o==="always"&&this.#u.some((r)=>r.grantId===t))this.#b.add(t,e.tool.name);return o!=="deny"})}#H(e){let t=()=>e.connection!==void 0&&this.#i===e.connection;return{registry:this.#e,server:this.#o,appName:this.#a,library:{name:C,version:T},confirm:(n)=>this.#G(n),toolCallStarted:(n)=>this.#t("toolcall",n),toolCallEnded:(n)=>this.#t("toolcallend",n),clientFor:(n)=>{let i=this.#u.find((r)=>r.grantId===n.grantId),o={grantId:n.grantId,id:n.clientId,host:z(n.clientId)};if(i!==void 0)o.name=i.client.name;return o},sessionStarted:(n)=>{let i=W(n);if(!t())return i;if(this.#h=i,this.#A(),this.#v("connected"),this.#M([...n.grants]),this.#f)this.#i?.send({type:"pairing.start"});if(this.#t("connected",i),i.pairing==="oidc")this.refreshIdentity();return i},pairingCode:(n)=>{if(t()&&this.#f)this.#C(n)},grantAdded:(n)=>{if(!t())return;this.#M([...this.#u.filter((i)=>i.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#M(this.#u.filter((i)=>i.grantId!==n))},replaced:()=>{if(t())this.#t("replaced",null)},identityResult:(n,i,o)=>{if(!t())return;if(i!==this.#l)return;if(n)this.#c("bound");else this.#c("refused",o??"")},error:(n)=>{if(t())this.#t("error",{error:n})},closed:(n,i)=>{if(!t())return;let o=this.#y;if(this.#i=void 0,this.#h=void 0,this.#C(void 0),this.#l++,this.#c("none"),this.#v("disconnected"),this.#t("disconnected",{reason:n,code:i}),R.has(n)&&this.#y===o&&this.#n==="disconnected"&&this.#s===void 0)this.#N(n,1)}}}}export{A as TabMcp,T as VERSION};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=46EA6D81FE71A62B64756E2164756E21
|
|
5
5
|
//# sourceMappingURL=tab-mcp-client.min.js.map
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"/**\n * The tools a user chose \"Always allow\" for, per grant (AI app). Kept in\n * memory for the page's lifetime; an entry goes when its grant goes or its\n * tool is unregistered, so a re-paired app or a new tool under the same name\n * is asked again.\n */\nexport class AlwaysAllowed {\n\treadonly #tools = new Map<string, Set<string>>();\n\n\thas(grantId: string, tool: string): boolean {\n\t\treturn this.#tools.get(grantId)?.has(tool) === true;\n\t}\n\n\tadd(grantId: string, tool: string): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Set();\n\t\ttools.add(tool);\n\t\tthis.#tools.set(grantId, tools);\n\t}\n\n\t/** Forget every grant not in `grantIds`. */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tfor (const grantId of this.#tools.keys()) {\n\t\t\tif (!keep.has(grantId)) this.#tools.delete(grantId);\n\t\t}\n\t}\n\n\t/** Forget every tool not in `names`. */\n\tkeepTools(names: Iterable<string>): void {\n\t\tconst keep = new Set(names);\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools) if (!keep.has(tool)) tools.delete(tool);\n\t\t}\n\t}\n}\n",
|
|
6
6
|
"/**\n * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`\n * (DEC-010). Part of the eagerly loaded core.\n */\n\nimport type {\n\tJsonSchema,\n\tRegisterToolOptions,\n\tTool,\n\tToolAnnotations,\n} from \"./types.ts\";\n\nconst NAME = /^[A-Za-z0-9_.-]{1,128}$/;\n\n/** A validated tool as the registry keeps it. */\nexport interface RegisteredTool {\n\treadonly name: string;\n\treadonly title: string | undefined;\n\treadonly description: string;\n\treadonly inputSchema: JsonSchema;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** `x-mcp-header` makes the relay validate headers it does not know; not supported in v1. */\nfunction usesMcpHeader(schema: unknown, depth = 0): boolean {\n\tif (depth > 64 || typeof schema !== \"object\" || schema === null) return false;\n\tif (!Array.isArray(schema) && \"x-mcp-header\" in schema) return true;\n\treturn Object.values(schema).some((v) => usesMcpHeader(v, depth + 1));\n}\n\n/** A JSON pointer (`/a/b~1c`) inside `root`, or `undefined`. */\nfunction resolvePointer(root: unknown, pointer: string): unknown {\n\tlet node: unknown = root;\n\tfor (const raw of pointer.split(\"/\").slice(1)) {\n\t\tconst key = decodeURIComponent(raw)\n\t\t\t.replaceAll(\"~1\", \"/\")\n\t\t\t.replaceAll(\"~0\", \"~\");\n\t\tif (typeof node !== \"object\" || node === null || !Object.hasOwn(node, key))\n\t\t\treturn undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node;\n}\n\n/**\n * What the validator (loaded only on `connect()`) would throw on later, found\n * now so that a bad schema fails registration: patterns that are not\n * regular expressions, and `$ref`s that do not resolve inside the schema.\n * Without `$id`s; once the validator is loaded, it checks too (`setCompiler`).\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\n/** The validator's check of a schema: throws a `TypeError` naming the problem. */\nexport type SchemaCompiler = (tool: RegisteredTool) => void;\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\t#compile: SchemaCompiler | undefined;\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#compile?.(registered);\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\"abort\", () => this.remove(registered), {\n\t\t\tonce: true,\n\t\t});\n\t\tthis.#changed();\n\t}\n\n\t/**\n\t * The validator is loaded: from now on each schema is compiled when it is\n\t * registered, and a tool it refuses is refused (DEC-086).\n\t */\n\tsetCompiler(compile: SchemaCompiler): void {\n\t\tthis.#compile ??= compile;\n\t}\n\n\t/** Unregister this tool, if it still is. */\n\tremove(tool: RegisteredTool): void {\n\t\tif (this.#tools.get(tool.name) !== tool) return;\n\t\tthis.#tools.delete(tool.name);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
|
|
7
7
|
"/**\n * The address secret (DEC-027): 32 random bytes as base64url without padding,\n * kept in `localStorage`. The relay derives the stable address from it.\n */\n\nimport type { SecretStorage } from \"./types.ts\";\n\nconst SECRET = /^[A-Za-z0-9_-]{43}$/;\n/** base64url without padding. */\nexport function base64url(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nexport function newSecret(): string {\n\treturn base64url(crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport function isSecret(value: unknown): value is string {\n\treturn typeof value === \"string\" && SECRET.test(value);\n}\n\n/** `localStorage`, or `null` where it is missing or blocked. */\nfunction defaultStorage(): SecretStorage | null {\n\ttry {\n\t\tconst storage = (globalThis as { localStorage?: SecretStorage })\n\t\t\t.localStorage;\n\t\treturn storage ?? null;\n\t} catch {\n\t\treturn null; // SecurityError: storage blocked for this page\n\t}\n}\n\n/** Reads, creates and rotates the secret; falls back to memory without storage. */\nexport class SecretStore {\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t/** A key the secret may still be under (the default of 0.4 and older). */\n\treadonly #oldKey: string | undefined;\n\t/** Set once a page of this origin took over the old key's secret. */\n\treadonly #claimKey: string | undefined;\n\t#memory: string | undefined;\n\n\tconstructor(\n\t\tstorage: SecretStorage | null | undefined,\n\t\tkey: string,\n\t\toldKey?: string,\n\t) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t\tthis.#oldKey = oldKey;\n\t\tthis.#claimKey = oldKey === undefined ? undefined : `${oldKey}#moved`;\n\t}\n\n\t/** The current secret; storage first, so a rotation in another tab is seen. */\n\tget(): string {\n\t\tlet stored: string | null = null;\n\t\ttry {\n\t\t\tstored = this.#storage?.getItem(this.#key) ?? null;\n\t\t\t// The old shared key's secret is copied once (DEC-083): the first page\n\t\t\t// keeps the address and marks it taken, so the next page gets its own.\n\t\t\t// The old key stays, for pages still on 0.4 and for a rollback.\n\t\t\tif (\n\t\t\t\t!isSecret(stored) &&\n\t\t\t\tthis.#oldKey !== undefined &&\n\t\t\t\tthis.#claimKey !== undefined &&\n\t\t\t\tthis.#storage?.getItem(this.#claimKey) == null\n\t\t\t) {\n\t\t\t\tconst old = this.#storage?.getItem(this.#oldKey) ?? null;\n\t\t\t\tif (isSecret(old)) {\n\t\t\t\t\tstored = old; // kept for this page even if the writes below fail\n\t\t\t\t\tthis.#claim(old);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// unreadable: use a page-lifetime secret\n\t\t}\n\t\tif (isSecret(stored)) {\n\t\t\tthis.#memory = stored;\n\t\t\treturn stored;\n\t\t}\n\t\treturn this.#memory ?? this.rotate();\n\t}\n\n\t/** Make and keep a new secret (a new address). */\n\trotate(): string {\n\t\tconst secret = newSecret();\n\t\tthis.#memory = secret;\n\t\t// Also marks the old shared secret taken: an address abandoned with \"New\n\t\t// address\" is not picked up again by another page of the site.\n\t\tthis.#claim(secret);\n\t\treturn secret;\n\t}\n\n\t#claim(secret: string): void {\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t\tif (this.#claimKey !== undefined)\n\t\t\t\tthis.#storage?.setItem(this.#claimKey, this.#key);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t}\n}\n",
|
|
8
|
-
"/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.
|
|
9
|
-
"/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tIdentityAssertionHandler,\n\tIdentityState,\n\tPairingCode,\n\tReconnectingInfo,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** The default waits before each reconnect attempt; the last one repeats. */\nconst RECONNECT_DELAYS_MS = [5_000, 10_000, 20_000, 40_000, 60_000];\n/** Reasons after which the library connects again by itself. */\nconst RECONNECT_REASONS = new Set<DisconnectReason>([\n\t\"network\",\n\t\"heartbeat\",\n\t\"shutdown\",\n]);\n\nfunction reconnectDelays(\n\toption: TabMcpOptions[\"reconnect\"],\n): readonly number[] | undefined {\n\tif (option === false) return undefined;\n\tif (option === undefined || option === true) return RECONNECT_DELAYS_MS;\n\tconst delays = option.delaysMs ?? RECONNECT_DELAYS_MS;\n\tif (\n\t\t!Array.isArray(delays) ||\n\t\tdelays.length === 0 ||\n\t\t!delays.every((d) => typeof d === \"number\" && d >= 0 && d < 2 ** 31)\n\t) {\n\t\tthrow new TypeError(\"TabMcp: reconnect.delaysMs: a non-empty list of ms\");\n\t}\n\treturn [...delays];\n}\n\n/** A delay option: `undefined`, or a whole wait `setTimeout` can keep (below 2^31 ms). */\nfunction delayOption(name: string, value: unknown): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (\n\t\ttypeof value !== \"number\" ||\n\t\t!Number.isFinite(value) ||\n\t\tvalue < 0 ||\n\t\tvalue >= 2 ** 31\n\t) {\n\t\tthrow new TypeError(`TabMcp: ${name} must be a number of milliseconds`);\n\t}\n\treturn value;\n}\n\n/** A grant as the page sees it: frozen, so a page cannot change what decides Always allow. */\nfunction frozenGrant(grant: Grant): Grant {\n\treturn Object.freeze({\n\t\t...grant,\n\t\tclient: Object.freeze({ ...grant.client }),\n\t});\n}\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\tpairing: m.pairing === \"oidc\" ? \"oidc\" : \"code\",\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\treadonly #identityAssertion: IdentityAssertionHandler | undefined;\n\t#identity: IdentityState = \"none\";\n\t#identityMessage: string | undefined;\n\t/** Incremented per identity request, so a late answer of an older one is dropped. */\n\t#identityRound = 0;\n\treadonly #identityTimeoutMs: number;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: readonly Grant[] = Object.freeze([]);\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\t/** Waits between reconnect attempts; `undefined`: reconnecting is off. */\n\treadonly #reconnectDelays: readonly number[] | undefined;\n\t#reconnecting: ReconnectingInfo | undefined;\n\t#reconnectTimer: ReturnType<typeof setTimeout> | undefined;\n\t#unwatch: (() => void) | undefined;\n\t/** The page's `connect()` waits on the running reconnect attempt: its promise tells it. */\n\t#pageWaits = false;\n\t/** The open \"Connect your AI app\" dialog: one at a time. */\n\t#connectDialog: { doc: Document; shown: Promise<void> } | undefined;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = delayOption(\n\t\t\t\"confirmDelayMs\",\n\t\t\toptions.confirmDelayMs,\n\t\t);\n\t\tthis.#identityAssertion = options.identityAssertion;\n\t\tthis.#identityTimeoutMs =\n\t\t\tdelayOption(\"identityTimeoutMs\", options.identityTimeoutMs) ?? 15_000;\n\t\tthis.#reconnectDelays = reconnectDelays(options.reconnect);\n\t\t// One address per relay and page (server name); the default of 0.4 and\n\t\t// older, per relay only, is moved over once (DEC-083).\n\t\tthis.#secrets =\n\t\t\toptions.storageKey === undefined\n\t\t\t\t? new SecretStore(\n\t\t\t\t\t\toptions.storage,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}:${encodeURIComponent(server.name)}`,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}`,\n\t\t\t\t\t)\n\t\t\t\t: new SecretStore(options.storage, options.storageKey);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address (frozen; a new array when they change). */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/**\n\t * While the library connects again by itself after the connection broke:\n\t * the next attempt and when it starts. `undefined` otherwise.\n\t */\n\tget reconnecting(): ReconnectingInfo | undefined {\n\t\treturn this.#reconnecting;\n\t}\n\n\t/** Who the relay knows as the page's user (identity binding). */\n\tget identity(): IdentityState {\n\t\treturn this.#identity;\n\t}\n\n\t/** Why the relay refused the identity, while `identity` is `refused`. */\n\tget identityMessage(): string | undefined {\n\t\treturn this.#identityMessage;\n\t}\n\n\t/**\n\t * Ask the `identityAssertion` hook again and send the result, e.g. after\n\t * the user signed in without a page load. Resolves `true` once the relay\n\t * accepted it; `false` when nobody is signed in, it was refused, or the\n\t * page is not connected.\n\t */\n\trefreshIdentity(): Promise<boolean> {\n\t\tconst session = this.#session;\n\t\tconst ask = this.#identityAssertion;\n\t\tif (\n\t\t\tthis.#state !== \"connected\" ||\n\t\t\tsession === undefined ||\n\t\t\task === undefined\n\t\t) {\n\t\t\treturn Promise.resolve(false);\n\t\t}\n\t\tconst round = ++this.#identityRound;\n\t\tconst connection = this.#connection;\n\t\tthis.#setIdentity(\"pending\");\n\t\t// No answer in time, from the hook or the relay (an old relay, a lost\n\t\t// message, a hook that never settles): give up.\n\t\tconst timer = setTimeout(() => {\n\t\t\tif (round !== this.#identityRound || this.#identity !== \"pending\") return;\n\t\t\tthis.#identityRound++; // a late answer is dropped\n\t\t\tthis.#setIdentity(\"none\");\n\t\t}, this.#identityTimeoutMs);\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst settle = (event: TabMcpEventMap[\"identitychange\"]) => {\n\t\t\t\tif (event.detail.state === \"pending\") return;\n\t\t\t\tthis.removeEventListener(\"identitychange\", settle);\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(event.detail.state === \"bound\");\n\t\t\t};\n\t\t\tthis.addEventListener(\"identitychange\", settle);\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() =>\n\t\t\t\t\task({ address: session.address, sessionId: session.sessionId }),\n\t\t\t\t)\n\t\t\t\t.then(\n\t\t\t\t\t(assertion) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tround !== this.#identityRound ||\n\t\t\t\t\t\t\tthis.#connection !== connection\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Superseded (a newer request, a sign-out, a new connection): that one settles the state.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (typeof assertion !== \"string\" || assertion === \"\") {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tconnection?.send({ type: \"identity\", assertion, round }) !== true\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\t\t\tthis.#emit(\"error\", {\n\t\t\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * The page's user signed out: the relay ends every AI connection of this\n\t * address at once (identity binding). Call it from the web app's logout.\n\t * Returns `false` when it could not be sent (not connected); the grants\n\t * then stay, but work only while a page signed in as the same person is\n\t * open.\n\t */\n\tsignOut(): boolean {\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"identity.logout\" }) === true;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * While reconnecting (`reconnecting`), it makes the next attempt at once.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) {\n\t\t\tif (this.#reconnecting !== undefined) this.#pageWaits = true;\n\t\t\treturn this.#connecting;\n\t\t}\n\t\tif (this.#reconnecting !== undefined) return this.#attemptReconnect(true);\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn this.#start();\n\t}\n\n\t#start(): Promise<SessionInfo> {\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection, compileRegistry } = await import(\"./connection.ts\");\n\t\t// The validator is loaded: it checks the schemas from now on (DEC-086).\n\t\tfor (const error of compileRegistry(this.#registry))\n\t\t\tthis.#emit(\"error\", { error });\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn =\n\t\t\tthis.#state !== \"disconnected\" || this.#reconnecting !== undefined;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#stopReconnecting();\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** Wait, then connect again (attempt `attempt`, from 1). */\n\t#scheduleReconnect(reason: DisconnectReason, attempt: number): void {\n\t\tconst delays = this.#reconnectDelays;\n\t\tif (delays === undefined) return;\n\t\tconst delay = delays[Math.min(attempt, delays.length) - 1] ?? 0;\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = setTimeout(() => {\n\t\t\tthis.#attemptReconnect().catch(() => {}); // the next one is scheduled\n\t\t}, delay);\n\t\tthis.#watch();\n\t\tthis.#reconnecting = { reason, attempt, at: Date.now() + delay };\n\t\tthis.#emit(\"reconnecting\", this.#reconnecting);\n\t}\n\n\t/**\n\t * Make the next reconnect attempt now; on failure, schedule the one after.\n\t * `byPage`: from `connect()`, whose promise tells the page why it failed.\n\t */\n\t#attemptReconnect(byPage = false): Promise<SessionInfo> {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst info = this.#reconnecting;\n\t\tthis.#pageWaits = byPage;\n\t\tconst attempt = this.#start();\n\t\tattempt.catch((error: unknown) => {\n\t\t\tconst pageWaits = this.#pageWaits;\n\t\t\tthis.#pageWaits = false;\n\t\t\tif (info === undefined || this.#reconnecting !== info) return;\n\t\t\t// Only what may get better: an unreachable relay (network), a\n\t\t\t// heartbeat or a shutdown; a refusal stops it (DEC-082).\n\t\t\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\t\t\tif (reason === undefined || RECONNECT_REASONS.has(reason)) {\n\t\t\t\tthis.#scheduleReconnect(info.reason, info.attempt + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A refusal stops it. Without a connect() of the page's waiting on this\n\t\t\t// attempt, nothing else tells the page why: `error` does, before `null`.\n\t\t\tthis.#stopReconnecting(\n\t\t\t\tpageWaits\n\t\t\t\t\t? undefined\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: new Error(String(error)),\n\t\t\t);\n\t\t});\n\t\treturn attempt;\n\t}\n\n\t/** Back to the front, or online again: try at once instead of waiting. */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst doc = (globalThis as { document?: Document }).document;\n\t\tconst now = () => {\n\t\t\t// Only while waiting: an attempt that is running is not doubled.\n\t\t\tif (this.#reconnectTimer !== undefined)\n\t\t\t\tthis.#attemptReconnect().catch(() => {});\n\t\t};\n\t\tconst visible = () => {\n\t\t\tif (doc?.visibilityState !== \"hidden\") now();\n\t\t};\n\t\tdoc?.addEventListener(\"visibilitychange\", visible);\n\t\tg.addEventListener?.(\"online\", now);\n\t\tthis.#unwatch = () => {\n\t\t\tdoc?.removeEventListener(\"visibilitychange\", visible);\n\t\t\tg.removeEventListener?.(\"online\", now);\n\t\t};\n\t}\n\n\t/**\n\t * Stop reconnecting. `why` (a refusal) goes out as `error` before the\n\t * `null`, once the state is clear: a listener that calls `connect()` then\n\t * starts afresh, with the user-activation check.\n\t */\n\t#stopReconnecting(why?: Error): void {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tthis.#unwatch?.();\n\t\tthis.#unwatch = undefined;\n\t\tif (this.#reconnecting === undefined) return;\n\t\tthis.#reconnecting = undefined;\n\t\tif (why !== undefined) this.#emit(\"error\", { error: why });\n\t\tthis.#emit(\"reconnecting\", null);\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. One dialog at\n\t * a time (they would share one pairing): while it is open, a call for the\n\t * same document opens no second one and resolves with it, and a call for\n\t * another document rejects with an `InvalidStateError`. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tshowConnectDialog(options: { document?: Document } = {}): Promise<void> {\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tconst open = this.#connectDialog;\n\t\tif (open !== undefined) {\n\t\t\treturn open.doc === doc\n\t\t\t\t? open.shown\n\t\t\t\t: Promise.reject(\n\t\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\t\"showConnectDialog: the dialog is already open in another document\",\n\t\t\t\t\t\t\t\"InvalidStateError\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t}\n\t\tconst shown = this.#showConnectDialog(doc).finally(() => {\n\t\t\tif (this.#connectDialog?.shown === shown) this.#connectDialog = undefined;\n\t\t});\n\t\tthis.#connectDialog = { doc, shown };\n\t\treturn shown;\n\t}\n\n\tasync #showConnectDialog(doc: Document): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(this, connecting, doc);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setIdentity(state: IdentityState, message?: string): void {\n\t\tif (this.#identity === state && message === undefined) return;\n\t\tthis.#identity = state;\n\t\tthis.#identityMessage = state === \"refused\" ? message : undefined;\n\t\tthis.#emit(\n\t\t\t\"identitychange\",\n\t\t\tmessage === undefined ? { state } : { state, message },\n\t\t);\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: readonly Grant[]): void {\n\t\tthis.#grants = Object.freeze(grants.map(frozenGrant));\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants: this.#grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\treturn this.confirmInPage(request);\n\t}\n\n\t/**\n\t * The library's own confirmation: the dialog in the page with Allow,\n\t * Always allow and Deny (what runs without `onConfirm`). An `onConfirm`\n\t * may hand some calls to it. Resolves `false` where there is no document.\n\t */\n\tconfirmInPage(request: ConfirmRequest): Promise<boolean> {\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#stopReconnecting();\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\tif (session.pairing === \"oidc\") void this.refreshIdentity();\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\tidentityResult: (bound, round, message) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Only the answer to the newest assertion counts: the relay echoes\n\t\t\t\t// its round, so a lost or late answer cannot pass for a newer one.\n\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\tif (bound) this.#setIdentity(\"bound\");\n\t\t\t\telse this.#setIdentity(\"refused\", message ?? \"\");\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Any listener below may end it all (`disconnect()`, `newAddress()`):\n\t\t\t\t// that bumps the generation, and then nothing is scheduled.\n\t\t\t\tconst generation = this.#generation;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#identityRound++;\n\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t\t// After the page heard of it: its listener may have connected or ended it.\n\t\t\t\tif (\n\t\t\t\t\tRECONNECT_REASONS.has(reason) &&\n\t\t\t\t\tthis.#generation === generation &&\n\t\t\t\t\tthis.#state === \"disconnected\" &&\n\t\t\t\t\tthis.#connecting === undefined\n\t\t\t\t)\n\t\t\t\t\tthis.#scheduleReconnect(reason, 1);\n\t\t\t},\n\t\t};\n\t}\n}\n"
|
|
8
|
+
"/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.7.0\";\n",
|
|
9
|
+
"/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tIdentityAssertionHandler,\n\tIdentityState,\n\tPairingCode,\n\tReconnectingInfo,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** The default waits before each reconnect attempt; the last one repeats. */\nconst RECONNECT_DELAYS_MS = [5_000, 10_000, 20_000, 40_000, 60_000];\n/** Reasons after which the library connects again by itself. */\nconst RECONNECT_REASONS = new Set<DisconnectReason>([\n\t\"network\",\n\t\"heartbeat\",\n\t\"shutdown\",\n]);\n\nfunction reconnectDelays(\n\toption: TabMcpOptions[\"reconnect\"],\n): readonly number[] | undefined {\n\tif (option === false) return undefined;\n\tif (option === undefined || option === true) return RECONNECT_DELAYS_MS;\n\tconst delays = option.delaysMs ?? RECONNECT_DELAYS_MS;\n\tif (\n\t\t!Array.isArray(delays) ||\n\t\tdelays.length === 0 ||\n\t\t!delays.every((d) => typeof d === \"number\" && d >= 0 && d < 2 ** 31)\n\t) {\n\t\tthrow new TypeError(\"TabMcp: reconnect.delaysMs: a non-empty list of ms\");\n\t}\n\treturn [...delays];\n}\n\n/** A delay option: `undefined`, or a whole wait `setTimeout` can keep (below 2^31 ms). */\nfunction delayOption(name: string, value: unknown): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (\n\t\ttypeof value !== \"number\" ||\n\t\t!Number.isFinite(value) ||\n\t\tvalue < 0 ||\n\t\tvalue >= 2 ** 31\n\t) {\n\t\tthrow new TypeError(`TabMcp: ${name} must be a number of milliseconds`);\n\t}\n\treturn value;\n}\n\n/** A grant as the page sees it: frozen, so a page cannot change what decides Always allow. */\nfunction frozenGrant(grant: Grant): Grant {\n\treturn Object.freeze({\n\t\t...grant,\n\t\tclient: Object.freeze({ ...grant.client }),\n\t});\n}\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\tpairing: m.pairing === \"oidc\" ? \"oidc\" : \"code\",\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\treadonly #identityAssertion: IdentityAssertionHandler | undefined;\n\t#identity: IdentityState = \"none\";\n\t#identityMessage: string | undefined;\n\t/** Incremented per identity request, so a late answer of an older one is dropped. */\n\t#identityRound = 0;\n\treadonly #identityTimeoutMs: number;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: readonly Grant[] = Object.freeze([]);\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\t/** Waits between reconnect attempts; `undefined`: reconnecting is off. */\n\treadonly #reconnectDelays: readonly number[] | undefined;\n\t#reconnecting: ReconnectingInfo | undefined;\n\t#reconnectTimer: ReturnType<typeof setTimeout> | undefined;\n\t#unwatch: (() => void) | undefined;\n\t/** The page's `connect()` waits on the running reconnect attempt: its promise tells it. */\n\t#pageWaits = false;\n\t/** The open \"Connect your AI app\" dialog: one at a time. */\n\t#connectDialog: { doc: Document; shown: Promise<void> } | undefined;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = delayOption(\n\t\t\t\"confirmDelayMs\",\n\t\t\toptions.confirmDelayMs,\n\t\t);\n\t\tthis.#identityAssertion = options.identityAssertion;\n\t\tthis.#identityTimeoutMs =\n\t\t\tdelayOption(\"identityTimeoutMs\", options.identityTimeoutMs) ?? 15_000;\n\t\tthis.#reconnectDelays = reconnectDelays(options.reconnect);\n\t\t// One address per relay and page (server name); the default of 0.4 and\n\t\t// older, per relay only, is moved over once (DEC-083).\n\t\tthis.#secrets =\n\t\t\toptions.storageKey === undefined\n\t\t\t\t? new SecretStore(\n\t\t\t\t\t\toptions.storage,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}:${encodeURIComponent(server.name)}`,\n\t\t\t\t\t\t`tab-mcp:secret:${origin}`,\n\t\t\t\t\t)\n\t\t\t\t: new SecretStore(options.storage, options.storageKey);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address (frozen; a new array when they change). */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/**\n\t * While the library connects again by itself after the connection broke:\n\t * the next attempt and when it starts. `undefined` otherwise.\n\t */\n\tget reconnecting(): ReconnectingInfo | undefined {\n\t\treturn this.#reconnecting;\n\t}\n\n\t/** Who the relay knows as the page's user (identity binding). */\n\tget identity(): IdentityState {\n\t\treturn this.#identity;\n\t}\n\n\t/** Why the relay refused the identity, while `identity` is `refused`. */\n\tget identityMessage(): string | undefined {\n\t\treturn this.#identityMessage;\n\t}\n\n\t/**\n\t * Ask the `identityAssertion` hook again and send the result, e.g. after\n\t * the user signed in without a page load. Resolves `true` once the relay\n\t * accepted it; `false` when nobody is signed in, it was refused, or the\n\t * page is not connected.\n\t */\n\trefreshIdentity(): Promise<boolean> {\n\t\tconst session = this.#session;\n\t\tconst ask = this.#identityAssertion;\n\t\tif (\n\t\t\tthis.#state !== \"connected\" ||\n\t\t\tsession === undefined ||\n\t\t\task === undefined\n\t\t) {\n\t\t\treturn Promise.resolve(false);\n\t\t}\n\t\tconst round = ++this.#identityRound;\n\t\tconst connection = this.#connection;\n\t\tthis.#setIdentity(\"pending\");\n\t\t// No answer in time, from the hook or the relay (an old relay, a lost\n\t\t// message, a hook that never settles): give up.\n\t\tconst timer = setTimeout(() => {\n\t\t\tif (round !== this.#identityRound || this.#identity !== \"pending\") return;\n\t\t\tthis.#identityRound++; // a late answer is dropped\n\t\t\tthis.#setIdentity(\"none\");\n\t\t}, this.#identityTimeoutMs);\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst settle = (event: TabMcpEventMap[\"identitychange\"]) => {\n\t\t\t\tif (event.detail.state === \"pending\") return;\n\t\t\t\tthis.removeEventListener(\"identitychange\", settle);\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(event.detail.state === \"bound\");\n\t\t\t};\n\t\t\tthis.addEventListener(\"identitychange\", settle);\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() =>\n\t\t\t\t\task({ address: session.address, sessionId: session.sessionId }),\n\t\t\t\t)\n\t\t\t\t.then(\n\t\t\t\t\t(assertion) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tround !== this.#identityRound ||\n\t\t\t\t\t\t\tthis.#connection !== connection\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Superseded (a newer request, a sign-out, a new connection): that one settles the state.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (typeof assertion !== \"string\" || assertion === \"\") {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tconnection?.send({ type: \"identity\", assertion, round }) !== true\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\t\t\tthis.#emit(\"error\", {\n\t\t\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * The page's user signed out: the relay ends every AI connection of this\n\t * address at once (identity binding). Call it from the web app's logout.\n\t * Returns `false` when it could not be sent (not connected); the grants\n\t * then stay, but work only while a page signed in as the same person is\n\t * open.\n\t */\n\tsignOut(): boolean {\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"identity.logout\" }) === true;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * While reconnecting (`reconnecting`), it makes the next attempt at once.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) {\n\t\t\tif (this.#reconnecting !== undefined) this.#pageWaits = true;\n\t\t\treturn this.#connecting;\n\t\t}\n\t\tif (this.#reconnecting !== undefined) return this.#attemptReconnect(true);\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn this.#start();\n\t}\n\n\t#start(): Promise<SessionInfo> {\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection, compileRegistry } = await import(\"./connection.ts\");\n\t\t// The validator is loaded: it checks the schemas from now on (DEC-086).\n\t\tfor (const error of compileRegistry(this.#registry))\n\t\t\tthis.#emit(\"error\", { error });\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn =\n\t\t\tthis.#state !== \"disconnected\" || this.#reconnecting !== undefined;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#stopReconnecting();\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** Wait, then connect again (attempt `attempt`, from 1). */\n\t#scheduleReconnect(reason: DisconnectReason, attempt: number): void {\n\t\tconst delays = this.#reconnectDelays;\n\t\tif (delays === undefined) return;\n\t\tconst delay = delays[Math.min(attempt, delays.length) - 1] ?? 0;\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = setTimeout(() => {\n\t\t\tthis.#attemptReconnect().catch(() => {}); // the next one is scheduled\n\t\t}, delay);\n\t\tthis.#watch();\n\t\tthis.#reconnecting = { reason, attempt, at: Date.now() + delay };\n\t\tthis.#emit(\"reconnecting\", this.#reconnecting);\n\t}\n\n\t/**\n\t * Make the next reconnect attempt now; on failure, schedule the one after.\n\t * `byPage`: from `connect()`, whose promise tells the page why it failed.\n\t */\n\t#attemptReconnect(byPage = false): Promise<SessionInfo> {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst info = this.#reconnecting;\n\t\tthis.#pageWaits = byPage;\n\t\tconst attempt = this.#start();\n\t\tattempt.catch((error: unknown) => {\n\t\t\tconst pageWaits = this.#pageWaits;\n\t\t\tthis.#pageWaits = false;\n\t\t\tif (info === undefined || this.#reconnecting !== info) return;\n\t\t\t// Only what may get better: an unreachable relay (network), a\n\t\t\t// heartbeat or a shutdown; a refusal stops it (DEC-082).\n\t\t\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\t\t\tif (reason === undefined || RECONNECT_REASONS.has(reason)) {\n\t\t\t\tthis.#scheduleReconnect(info.reason, info.attempt + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A refusal stops it. Without a connect() of the page's waiting on this\n\t\t\t// attempt, nothing else tells the page why: `error` does, before `null`.\n\t\t\tthis.#stopReconnecting(\n\t\t\t\tpageWaits\n\t\t\t\t\t? undefined\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: new Error(String(error)),\n\t\t\t);\n\t\t});\n\t\treturn attempt;\n\t}\n\n\t/** Back to the front, or online again: try at once instead of waiting. */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst doc = (globalThis as { document?: Document }).document;\n\t\tconst now = () => {\n\t\t\t// Only while waiting: an attempt that is running is not doubled.\n\t\t\tif (this.#reconnectTimer !== undefined)\n\t\t\t\tthis.#attemptReconnect().catch(() => {});\n\t\t};\n\t\tconst visible = () => {\n\t\t\tif (doc?.visibilityState !== \"hidden\") now();\n\t\t};\n\t\tdoc?.addEventListener(\"visibilitychange\", visible);\n\t\tg.addEventListener?.(\"online\", now);\n\t\tthis.#unwatch = () => {\n\t\t\tdoc?.removeEventListener(\"visibilitychange\", visible);\n\t\t\tg.removeEventListener?.(\"online\", now);\n\t\t};\n\t}\n\n\t/**\n\t * Stop reconnecting. `why` (a refusal) goes out as `error` before the\n\t * `null`, once the state is clear: a listener that calls `connect()` then\n\t * starts afresh, with the user-activation check.\n\t */\n\t#stopReconnecting(why?: Error): void {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tthis.#unwatch?.();\n\t\tthis.#unwatch = undefined;\n\t\tif (this.#reconnecting === undefined) return;\n\t\tthis.#reconnecting = undefined;\n\t\tif (why !== undefined) this.#emit(\"error\", { error: why });\n\t\tthis.#emit(\"reconnecting\", null);\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. One dialog at\n\t * a time (they would share one pairing): while it is open, a call for the\n\t * same document opens no second one and resolves with it, and a call for\n\t * another document rejects with an `InvalidStateError`. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tshowConnectDialog(options: { document?: Document } = {}): Promise<void> {\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tconst open = this.#connectDialog;\n\t\tif (open !== undefined) {\n\t\t\treturn open.doc === doc\n\t\t\t\t? open.shown\n\t\t\t\t: Promise.reject(\n\t\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\t\"showConnectDialog: the dialog is already open in another document\",\n\t\t\t\t\t\t\t\"InvalidStateError\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t}\n\t\tconst shown = this.#showConnectDialog(doc).finally(() => {\n\t\t\tif (this.#connectDialog?.shown === shown) this.#connectDialog = undefined;\n\t\t});\n\t\tthis.#connectDialog = { doc, shown };\n\t\treturn shown;\n\t}\n\n\tasync #showConnectDialog(doc: Document): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(this, connecting, doc, this.#server.name);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setIdentity(state: IdentityState, message?: string): void {\n\t\tif (this.#identity === state && message === undefined) return;\n\t\tthis.#identity = state;\n\t\tthis.#identityMessage = state === \"refused\" ? message : undefined;\n\t\tthis.#emit(\n\t\t\t\"identitychange\",\n\t\t\tmessage === undefined ? { state } : { state, message },\n\t\t);\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: readonly Grant[]): void {\n\t\tthis.#grants = Object.freeze(grants.map(frozenGrant));\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants: this.#grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\treturn this.confirmInPage(request);\n\t}\n\n\t/**\n\t * The library's own confirmation: the dialog in the page with Allow,\n\t * Always allow and Deny (what runs without `onConfirm`). An `onConfirm`\n\t * may hand some calls to it. Resolves `false` where there is no document.\n\t */\n\tconfirmInPage(request: ConfirmRequest): Promise<boolean> {\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#stopReconnecting();\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\tif (session.pairing === \"oidc\") void this.refreshIdentity();\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\tidentityResult: (bound, round, message) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Only the answer to the newest assertion counts: the relay echoes\n\t\t\t\t// its round, so a lost or late answer cannot pass for a newer one.\n\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\tif (bound) this.#setIdentity(\"bound\");\n\t\t\t\telse this.#setIdentity(\"refused\", message ?? \"\");\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Any listener below may end it all (`disconnect()`, `newAddress()`):\n\t\t\t\t// that bumps the generation, and then nothing is scheduled.\n\t\t\t\tconst generation = this.#generation;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#identityRound++;\n\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t\t// After the page heard of it: its listener may have connected or ended it.\n\t\t\t\tif (\n\t\t\t\t\tRECONNECT_REASONS.has(reason) &&\n\t\t\t\t\tthis.#generation === generation &&\n\t\t\t\t\tthis.#state === \"disconnected\" &&\n\t\t\t\t\tthis.#connecting === undefined\n\t\t\t\t)\n\t\t\t\t\tthis.#scheduleReconnect(reason, 1);\n\t\t\t},\n\t\t};\n\t}\n}\n"
|
|
10
10
|
],
|
|
11
|
-
"mappings": ";AAMO,MAAM,CAAc,CACjB,GAAS,IAAI,IAEtB,GAAG,CAAC,EAAiB,EAAuB,CAC3C,OAAO,KAAK,GAAO,IAAI,CAAO,GAAG,IAAI,CAAI,IAAM,GAGhD,GAAG,CAAC,EAAiB,EAAoB,CACxC,IAAM,EAAQ,KAAK,GAAO,IAAI,CAAO,GAAK,IAAI,IAC9C,EAAM,IAAI,CAAI,EACd,KAAK,GAAO,IAAI,EAAS,CAAK,EAI/B,UAAU,CAAC,EAAkC,CAC5C,IAAM,EAAO,IAAI,IAAI,CAAQ,EAC7B,QAAW,KAAW,KAAK,GAAO,KAAK,EACtC,GAAI,CAAC,EAAK,IAAI,CAAO,EAAG,KAAK,GAAO,OAAO,CAAO,EAKpD,SAAS,CAAC,EAA+B,CACxC,IAAM,EAAO,IAAI,IAAI,CAAK,EAC1B,QAAW,KAAS,KAAK,GAAO,OAAO,EACtC,QAAW,KAAQ,EAAO,GAAI,CAAC,EAAK,IAAI,CAAI,EAAG,EAAM,OAAO,CAAI,EAGnE,CCtBA,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,CA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KAAK,GAAM,WAAY,IAAI,GAE3C,eAAgB,CAAC,EAAO,EAAO,IAAY,CAC1C,GAAI,CAAC,EAAQ,EAAG,OAGhB,GAAI,IAAU,KAAK,GAAgB,OACnC,GAAI,EAAO,KAAK,GAAa,OAAO,EAC/B,UAAK,GAAa,UAAW,GAAW,EAAE,GAEhD,MAAO,CAAC,IAAU,CACjB,GAAI,EAAQ,EAAG,KAAK,GAAM,QAAS,CAAE,OAAM,CAAC,GAE7C,OAAQ,CAAC,EAA0B,IAAiB,CACnD,GAAI,CAAC,EAAQ,EAAG,OAGhB,IAAM,EAAa,KAAK,GASxB,GARA,KAAK,GAAc,OACnB,KAAK,GAAW,OAChB,KAAK,GAAgB,MAAS,EAC9B,KAAK,KACL,KAAK,GAAa,MAAM,EACxB,KAAK,GAAU,cAAc,EAC7B,KAAK,GAAM,eAAgB,CAAE,SAAQ,MAAK,CAAC,EAG1C,EAAkB,IAAI,CAAM,GAC5B,KAAK,KAAgB,GACrB,KAAK,KAAW,gBAChB,KAAK,KAAgB,OAErB,KAAK,GAAmB,EAAQ,CAAC,EAEpC,EAEF",
|
|
12
|
+
"debugId": "46EA6D81FE71A62B64756E2164756E21",
|
|
13
13
|
"names": []
|
|
14
14
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var J=0;function r(e,n,t={},...d){let s=e.createElement(n);if(t.className!==void 0)s.className=t.className;if(t.id!==void 0)s.id=t.id;if(t.text!==void 0)s.textContent=t.text;return s.append(...d),s}function f(e,n,t,d,s){let o=r(e,"button",{text:n});if(o.type="button",d!==void 0)o.classList.add(d);if(s!==void 0)o.classList.add(`tab-mcp-${s}`);return o.addEventListener("click",t),o}var he=`.tab-mcp-dialog {
|
|
2
|
+
--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);
|
|
3
|
+
--_tab-mcp-bg: var(--tab-mcp-background, Canvas);
|
|
4
|
+
--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));
|
|
5
|
+
--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);
|
|
6
|
+
--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));
|
|
7
|
+
--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));
|
|
8
|
+
--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
9
|
+
--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);
|
|
10
|
+
box-sizing: border-box; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
|
|
11
|
+
font: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);
|
|
12
|
+
border: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);
|
|
13
|
+
padding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));
|
|
14
|
+
}
|
|
15
|
+
.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }
|
|
16
|
+
.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }
|
|
17
|
+
.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }
|
|
18
|
+
.tab-mcp-dialog :where([hidden]) { display: none !important; }
|
|
19
|
+
html dialog.tab-mcp-dialog:where(:focus) { outline: none; }
|
|
20
|
+
.tab-mcp-dialog :where(*) { box-sizing: border-box; }
|
|
21
|
+
.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }
|
|
22
|
+
.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
|
|
23
|
+
.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }
|
|
24
|
+
.tab-mcp-dialog :where(small) { font-size: 0.875em; }
|
|
25
|
+
.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note) { color: var(--_tab-mcp-muted); }
|
|
26
|
+
html dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }
|
|
27
|
+
.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }
|
|
28
|
+
html dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }
|
|
29
|
+
html dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }
|
|
30
|
+
html button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }
|
|
31
|
+
html button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }
|
|
32
|
+
html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }
|
|
33
|
+
.tab-mcp-copy { min-width: 6em; }
|
|
34
|
+
.tab-mcp-close { font-size: 0.875em; }
|
|
35
|
+
.tab-mcp-status { margin-top: -0.5rem; }
|
|
36
|
+
.tab-mcp-description:where(:empty) { display: none; }
|
|
37
|
+
.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
|
|
38
|
+
.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
|
|
39
|
+
.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }
|
|
40
|
+
.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
41
|
+
.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }
|
|
42
|
+
.tab-mcp-code > :where(span) { font-weight: 600; }
|
|
43
|
+
.tab-mcp-code :where(br) { display: none; }
|
|
44
|
+
.tab-mcp-code :where(small) { grid-column: 1 / -1; }
|
|
45
|
+
.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
|
|
46
|
+
.tab-mcp-help :where(summary) { width: fit-content; cursor: pointer; }
|
|
47
|
+
.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
|
|
48
|
+
.tab-mcp-help :where(ul) { margin-top: 0.75rem; gap: 0.75rem; }
|
|
49
|
+
.tab-mcp-help :where(li) { overflow-wrap: anywhere; }
|
|
50
|
+
.tab-mcp-help :where(strong) { display: block; font-weight: 600; }
|
|
51
|
+
.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }
|
|
52
|
+
.tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
53
|
+
.tab-mcp-command-note { display: block; margin-top: 0.375rem; }
|
|
54
|
+
.tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
|
|
55
|
+
.tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
56
|
+
.tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }
|
|
57
|
+
.tab-mcp-apps-note { margin-top: 0.5rem; }
|
|
58
|
+
.tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }
|
|
59
|
+
.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }
|
|
60
|
+
.tab-mcp-close-note { flex: 1 1 12rem; }
|
|
61
|
+
.tab-mcp-confirm :where(p bdi) { font-weight: 600; }
|
|
62
|
+
.tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
63
|
+
.tab-mcp-always-note { font-size: 0.875em; }
|
|
64
|
+
@media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }
|
|
65
|
+
@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } }
|
|
66
|
+
@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }
|
|
67
|
+
@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
|
|
68
|
+
`,ce=new WeakMap;function we(e){try{let n=ce.get(e);if(n===void 0){let t=e.defaultView?.CSSStyleSheet;if(t===void 0||!Array.isArray(e.adoptedStyleSheets))return;n=new t,n.replaceSync(he),ce.set(e,n)}if(!e.adoptedStyleSheets.includes(n))e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]}catch{}}function U(e,n,t,d,s,o,h){let p=f(e,"Copy",()=>{let b=()=>{p.textContent="Copied",p.setAttribute("aria-label",`Copied ${n}`),s(`${n[0]?.toUpperCase()}${n.slice(1)} copied`)},l=()=>{d(),s("Selected: copy it with Ctrl+C or ⌘C")},w=e.defaultView?.navigator?.clipboard;if(w!==void 0)w.writeText(t()).then(b,l);else l()},o,h);p.classList.add("tab-mcp-copy");let v=()=>{p.textContent="Copy",p.setAttribute("aria-label",`Copy ${n}`)};return v(),{button:p,reset:v}}function le(e,n,t){let d=`tab-mcp-${++J}`,s=r(e,"dialog",{className:`tab-mcp-dialog ${n}`});s.setAttribute("aria-labelledby",`${d}-title`),we(e);let o=r(e,"h2",{id:`${d}-title`,text:t});return s.append(o),{dialog:s,heading:o}}var ve=/[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Co}\p{Cn}\u0080-\u009F\u2028\u2029]/gu;function Q(e){return e.replace(ve,(n)=>{let t="";for(let d=0;d<n.length;d++)t+=`\\u${n.charCodeAt(d).toString(16).toUpperCase().padStart(4,"0")}`;return t})}function O(e){let n=Q(e.host||e.id);return e.name!==void 0&&e.name!==""?`${Q(e.name)} (${n})`:n}function D(e,n){let t=r(e,"bdi",{text:n});return t.dir="ltr",t}function ye(e){try{return Q(JSON.stringify(e,null,2))}catch{return}}var xe=750,Ce=500;function _e(e){let n=typeof e==="number"&&Number.isFinite(e)&&e<2147483648?e:xe;return Math.max(Ce,n)}function ke(e,n,t={}){let d=_e(t.allowDelayMs);if(e.signal.aborted)return Promise.resolve("deny");let s=e.tool.title??e.tool.name,{dialog:o,heading:h}=le(n,"tab-mcp-confirm","");h.append("Allow ",D(n,s),"?");let p=O(e.client),v=f(n,"Don't allow",()=>o.close("deny"),"tab-mcp-deny","primary"),b=f(n,"Allow",()=>{if(!b.disabled)o.close("allow")},"tab-mcp-allow"),l=f(n,"Always allow",()=>{if(!l.disabled)o.close("always")},"tab-mcp-always");b.disabled=!0,l.disabled=!0;let w=r(n,"div",{className:"tab-mcp-actions"},v," ",b," ",l),T=r(n,"p",{className:"tab-mcp-always-note"},"Always allow: ",D(n,s)," runs without asking for ",D(n,p)," until you reload this page or disconnect it."),y=ye(e.arguments),m=r(n,"pre",{className:"tab-mcp-arguments",text:y??"The arguments cannot be shown, so this call cannot be allowed."});if(y===void 0)b.hidden=!0,l.hidden=!0,T.hidden=!0;m.dir="ltr",m.style.setProperty("white-space","pre-wrap"),m.style.setProperty("overflow-wrap","anywhere"),m.style.setProperty("max-height","var(--tab-mcp-arguments-height, 12rem)"),m.style.setProperty("overflow","auto"),m.hidden=Object.keys(e.arguments).length===0,o.append(r(n,"p",{},D(n,p)," wants to run ",D(n,s),"."),r(n,"p",{className:"tab-mcp-description",text:e.tool.description}),m,w,T),n.body.append(o);let x=n.defaultView;return new Promise((I)=>{let L=()=>o.close("deny");e.signal.addEventListener("abort",L,{once:!0});let _,c=(u)=>{if(clearTimeout(_),_=void 0,b.disabled=!0,l.disabled=!0,u?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;_=setTimeout(()=>{b.disabled=!1,l.disabled=!1},d)};n.addEventListener("visibilitychange",c),x?.addEventListener("focus",c),x?.addEventListener("blur",c),o.addEventListener("close",()=>{clearTimeout(_),n.removeEventListener("visibilitychange",c),x?.removeEventListener("focus",c),x?.removeEventListener("blur",c),e.signal.removeEventListener("abort",L);let u=o.returnValue;o.remove(),I(u==="allow"||u==="always"?u:"deny")},{once:!0}),o.showModal(),v.focus(),c()})}function Ne(e){let n=e.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"");return n===""?"tools":n}function Ae(e){try{let n=new URL(e).href;return/^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(n)?n:void 0}catch{return}}var Y="mcp_2026_07_28";function Se(e,n){let t=Ne(e),d=Ae(n);return[["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."],d===void 0?["Claude Code","Add the address with claude mcp add --transport http."]:["Claude Code","Run:",`claude mcp add --transport http ${t} ${d}`],["Codex",...d===void 0?[`Run codex features enable ${Y}, then add the address with codex mcp add --url.`,void 0]:["Run:",`codex features enable ${Y}
|
|
69
|
+
codex mcp add ${t} --url ${d}`],["Start a new chat in Codex after it connects. The first line turns on a feature for all of Codex's MCP servers; ",`codex features disable ${Y}`," turns it off."]]]}function Le(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function Ee(e,n,t,d="tools"){let{dialog:s}=le(t,"tab-mcp-connect","Connect your AI app");s.tabIndex=-1;let o=r(t,"p",{className:"tab-mcp-status",text:"Connecting…"});o.setAttribute("role","status");let h=r(t,"span",{className:"tab-mcp-announce"});h.setAttribute("aria-live","polite");for(let[a,i]of[["position","absolute"],["width","1px"],["height","1px"],["overflow","hidden"],["clip-path","inset(50%)"],["white-space","nowrap"]])h.style.setProperty(a,i);let p=(a)=>{h.textContent=h.textContent===a?`${a} `:a},v=`tab-mcp-${++J}-address`,b=r(t,"label",{text:"Add this address to your AI app:"});b.htmlFor=v;let l=r(t,"input",{id:v,className:"tab-mcp-address-input"});l.readOnly=!0;let{button:w,reset:T}=U(t,"address",()=>l.value,()=>l.select(),p,"tab-mcp-address-copy","primary"),y=f(t,"New address",()=>ge(),"tab-mcp-new-address"),m=r(t,"div",{className:"tab-mcp-address"},b,l," ",w," ",y),x=`tab-mcp-${++J}-new-address`,I=r(t,"p",{id:x}),L=f(t,"Cancel",()=>{c.hidden=!0,y.focus()}),_=f(t,"Disconnect and get new address",()=>ae(),"tab-mcp-new-address-confirm","danger"),c=r(t,"div",{className:"tab-mcp-new-address-question"},I,r(t,"div",{className:"tab-mcp-actions"},L," ",_));c.setAttribute("role","group"),c.setAttribute("aria-labelledby",x),c.hidden=!0;let u=r(t,"strong",{className:"tab-mcp-code-value"});u.style.setProperty("user-select","all"),u.style.setProperty("-webkit-user-select","all");let{button:pe,reset:me}=U(t,"code",()=>u.textContent??"",()=>t.getSelection()?.selectAllChildren(u),p,"tab-mcp-code-copy"),X=r(t,"span",{},"When asked, enter the code ",u);X.setAttribute("aria-live","polite");let M=r(t,"p",{className:"tab-mcp-code"},X," ",pe,r(t,"br"),r(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."})),B=r(t,"p",{className:"tab-mcp-sign-in",text:"When your AI app asks, sign in with the account you use on this page. No code is needed."}),Z=r(t,"ul"),P=r(t,"details",{className:"tab-mcp-help"},r(t,"summary",{text:"How do I add it?"}),Z),q=r(t,"ul"),z=r(t,"div",{className:"tab-mcp-apps"},r(t,"h3",{text:"Connected"}),q),ee=r(t,"small",{className:"tab-mcp-close-note",text:"Closing this stops the code. The address stays the same: to connect later, open this again from the page."}),N=f(t,"Close",()=>s.close(),"tab-mcp-close"),A=f(t,"Done",()=>s.close(),"tab-mcp-done","primary");A.hidden=!0;let ue=r(t,"div",{className:"tab-mcp-actions"},ee," ",N,A),g=!1,F=new Set,te=()=>{ee.hidden=g||M.hidden},G=(a)=>{if(g=a,!g)F.clear();let i=t.activeElement;if(te(),N.hidden=g,A.hidden=!g,g&&i===N)A.focus();if(!g&&i===A)N.focus()},be=()=>g?A:N;s.append(o,m,c,M,B,P,z,ue,h),m.hidden=!0,M.hidden=!0,B.hidden=!0,P.hidden=!0,z.hidden=!0;let R=!1,ne=()=>{let a=e.grants.map((i)=>O(i.client));if(a.length===0)return!1;return I.textContent=`A new address disconnects ${Le(a)}. To use this page again, add the new address to ${a.length===1?"it":"them"}.`,!0},ge=()=>{if(e.state!=="connected")return;if(!ne()){ae();return}c.hidden=!1,L.focus()},ae=()=>{G(!1),N.focus(),c.hidden=!0,R=!0,o.textContent="Getting a new address…",e.newAddress().then(()=>{R=!1,o.textContent="This is a new address. Add it to your AI app again.",w.focus()},(a)=>{R=!1,o.textContent=`Could not connect: ${a instanceof Error?a.message:String(a)}. Close this and connect again.`,be().focus()})},H=(a)=>{if(a===void 0){m.hidden=!0,c.hidden=!0,P.hidden=!0;return}l.value=a.address,T();let i=a.appName??e.appName;if(!R)o.textContent=i!==void 0?`${i} is ready for your AI app.`:"This page is ready for your AI app.";if(y.disabled=e.state!=="connected",m.hidden=!1,t.activeElement===s)w.focus();P.hidden=!1,Z.replaceChildren(...Se(d,a.address).map(([E,fe,ie,de])=>{let V=r(t,"li",{},r(t,"strong",{text:`${E}:`}),` ${fe}`);if(ie!==void 0){let C=r(t,"pre",{text:ie});C.dir="ltr";let{button:K}=U(t,`${E} command`,()=>C.textContent??"",()=>t.getSelection()?.selectAllChildren(C),p,"tab-mcp-command-copy");V.append(r(t,"div",{className:"tab-mcp-command"},C,K))}if(de!==void 0)V.append(r(t,"small",{className:"tab-mcp-command-note"},...de.map((C,K)=>K%2===1?r(t,"code",{text:C}):C)));return V}))},k=()=>{let a=e.pairingCode,i=e.session?.pairing==="oidc";if(u.textContent!==(a?.code??""))me();u.textContent=a?.code??"",M.hidden=i||a===void 0,B.hidden=!i,te()},W=r(t,"p",{className:"tab-mcp-apps-note"});z.append(W);let j=new Set(e.grants.map((a)=>a.grantId)),re=e.session,S=()=>{if(e.session!==re){re=e.session;for(let i of e.grants)j.add(i.grantId)}for(let i of e.grants){if(j.has(i.grantId))continue;if(j.add(i.grantId),o.textContent=`${O(i.client)} is connected.`,F.add(i.grantId),!g)G(!0)}if(g&&!e.grants.some((i)=>F.has(i.grantId)))G(!1);let a=e.state==="connected";if(q.replaceChildren(...e.grants.map((i)=>{let E=f(t,"Disconnect",()=>{if(!e.revoke(i.grantId))S()},"tab-mcp-disconnect","danger");return E.disabled=!a,r(t,"li",{},r(t,"span",{className:"tab-mcp-app",text:`${O(i.client)} connected `}),E)})),W.textContent=a?"":"To disconnect an app, connect this page again first.",W.hidden=a,z.hidden=e.grants.length===0,!c.hidden&&!ne())c.hidden=!0,y.focus()},oe=(a)=>{if(a.detail.reason!=="new_address")o.textContent="Disconnected. AI apps can use this page again after you connect.";H(void 0),S(),k()},se=()=>{H(e.session),S(),k()};return e.addEventListener("pairingcode",k),e.addEventListener("grantschange",S),e.addEventListener("connected",se),e.addEventListener("disconnected",oe),t.body.append(s),e.startPairing(),S(),k(),H(e.session),n.then((a)=>H(a),(a)=>{o.textContent=`Could not connect: ${a instanceof Error?a.message:String(a)}`}),new Promise((a)=>{if(s.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",k),e.removeEventListener("grantschange",S),e.removeEventListener("connected",se),e.removeEventListener("disconnected",oe),s.remove(),a()},{once:!0}),s.showModal(),!m.hidden)w.focus();else s.focus()})}export{ke as confirmDialog,Ee as showConnectDialog};
|
|
70
|
+
|
|
71
|
+
//# debugId=A1374C5C3245218E64756E2164756E21
|
|
72
|
+
//# sourceMappingURL=ui-n9c73wge.min.js.map
|