@ractive-ch/tab-mcp-client 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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.7.0.** Until 1.0, a new minor version can still change the API. Which AI apps
9
+ **Status: 0.8.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
@@ -22,7 +22,7 @@ docker run --rm -p 8080:8080 \
22
22
  -e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
23
23
  -e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
24
24
  -e TAB_MCP_STORE=memory \
25
- ractive/tab-mcp:0.4.0
25
+ ractive/tab-mcp:0.5.0
26
26
  ```
27
27
 
28
28
  For production, see
@@ -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.7.0/cdn/tab-mcp-client.min.js";
41
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.8.0/cdn/tab-mcp-client.min.js";
42
42
  </script>
43
43
  ```
44
44
 
@@ -97,10 +97,16 @@ added and removed tools.
97
97
  ### Consequential tools
98
98
 
99
99
  Mark tools that change or delete something with `consequentialHint: true`. The page then
100
- asks the user before every call ("Allow", "Always allow" or "Don't allow"), showing the AI
101
- app and the arguments. "Always allow" lets that tool run without asking for that AI app
102
- until the page is reloaded or the app is disconnected. A refusal reaches the AI app as an
103
- error result, and so does a call whose tool was removed while the user was asked.
100
+ asks the user before every call ("Don't allow" or "Allow"), showing the AI app and the
101
+ arguments. A refusal reaches the AI app as an error result, and so does a call whose tool
102
+ was removed while the user was asked.
103
+
104
+ `alwaysAllow: true` adds "Always allow", which lets that tool run without asking for that
105
+ AI app until the page is reloaded or the app is disconnected. It is off by default: it
106
+ lifts the only brake at run time, which is what a prompt injection needs, and the relay
107
+ cannot help, since its one OAuth scope (`tools`) covers every tool of the page. Consent
108
+ per tool is the page's. Turn it on only for tools whose calls the user need not check one
109
+ by one.
104
110
 
105
111
  Tools are called while the user is in the AI app, so the dialog often opens in a tab in
106
112
  the background. "Allow" and "Always allow" can be clicked only once the page has been
@@ -170,6 +176,70 @@ sign-in page points users to it when someone else may be guessing codes. A page
170
176
  own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
171
177
  again; while the page is closed, they get "the page is not open".
172
178
 
179
+ When another tab or program connects with the same address, it takes the address over:
180
+ the page gets `disconnected` with reason `replaced` at once, then the event `replaced`,
181
+ and does not reconnect by itself. Tabs of the same page say on a `BroadcastChannel` (per
182
+ relay and storage key; it carries neither the secret nor the address) when the relay
183
+ accepted their session, so `replaced` says which it probably was:
184
+
185
+ - `event.detail.sibling` is `true`: a tab of the same page in this browser said so within
186
+ the last 10 seconds. That message usually comes just after the takeover, so the
187
+ library waits up to a second for it, and `replaced` may come that much after
188
+ `disconnected`. The usual cause, and harmless. Once the page has opened the default
189
+ dialog, the library shows "Opened in another tab".
190
+ - `false`: none did (or the browser has no `BroadcastChannel`). It may be a program with
191
+ a copy of the address secret, and the AI apps paired with the address now talk to it.
192
+ The library shows "Another tab or program took over this page" with "New address".
193
+
194
+ After a takeover, `newAddress()` (from the `replaced` listener, before it, or later)
195
+ first takes the address back: it connects with the old secret and asks the relay to
196
+ revoke every grant of the address in the same step (`hello.revokeAll`), and makes the new
197
+ address only once the relay confirmed that no grant is left. If the address is taken
198
+ over again before that, it rejects with an error whose `reason` is `"replaced"` and keeps
199
+ the old secret, so calling it again takes it back again. Against a relay of 0.4 or older
200
+ it sends `grants.revokeAll` and waits until every grant is gone. Then it connects with
201
+ the new address; the default notice opens the connect dialog to add it to the AI apps.
202
+
203
+ The default dialog closes when the page is replaced, and the notice appears also when the
204
+ dialog is closed, but only once the page has opened the dialog: a page that connects on
205
+ load with `connect({ resume: true })` and never opens it shows its own message. A page
206
+ with its own UI shows the same from `replaced`:
207
+
208
+ ```ts
209
+ mcp.addEventListener("replaced", (e) => {
210
+ if (e.detail.sibling) showNote("Opened in another tab.");
211
+ else showWarning("Another tab or program took over this page's address.", {
212
+ action: "New address",
213
+ onClick: () => mcp.newAddress(), // from the click
214
+ });
215
+ });
216
+ ```
217
+
218
+ Script on the page's origin can post on the channel and make a takeover look like a
219
+ sibling; such script can read the secret anyway, so `sibling` is a hint, not a proof.
220
+
221
+ ### Keeping the address safe
222
+
223
+ Whoever has the address secret can take over the page's address from anywhere, and the
224
+ AI apps paired with it then send their arguments to them and get their tool descriptions
225
+ and results, until the page gets a new address. They get no token and cannot pair a new
226
+ app without a code. Script on your origin (cross-site scripting, a compromised
227
+ third-party script, another page on the same origin) or access to the device can copy it
228
+ ([threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md), A4).
229
+
230
+ - For a page with user accounts, use [identity binding](#identity-binding-no-code): a
231
+ copied secret then gets nothing, since a session needs a fresh assertion from your
232
+ backend.
233
+ - Run the page on its own origin, not a shared one such as `*.github.io`, and keep
234
+ third-party scripts off it.
235
+ - On a page that pairs by code, grants follow the browser profile, not the person: on a
236
+ shared profile, or in a web app with accounts that pairs by code, the next user of the
237
+ page gets the AI apps the previous one paired. Call `newAddress()` when the user logs
238
+ out, or use identity binding.
239
+ - The page origin that the relay's sign-in page shows is what the page's browser
240
+ reported; a program can claim any origin. Do not tell users it proves which page they
241
+ pair with.
242
+
173
243
  When the connection breaks (reason `network`, `heartbeat` or `shutdown`: a dropped
174
244
  network, a phone pausing the tab in the background, a relay restart), the library
175
245
  connects again by itself: after 5, 10, 20 and 40 seconds, then every 60 seconds, and at
@@ -223,7 +293,8 @@ Instead of `showConnectDialog()`, use `connect()`, `disconnect()`, `newAddress()
223
293
  `startPairing()` and `stopPairing()` (codes come only while pairing is on),
224
294
  `revoke(grantId)`, the properties `state`, `address`, `pairingCode`, `grants`,
225
295
  `reconnecting` and `tools`, and the events `statechange`, `connected`, `disconnected`,
226
- `pairingcode`, `grantschange`, `reconnecting`, `toolschange`, `replaced` and `error`. For an activity log, `toolcall`
296
+ `pairingcode`, `grantschange`, `reconnecting`, `toolschange`, `replaced` (with
297
+ `detail.sibling`, see above) and `error`. For an activity log, `toolcall`
227
298
  and `toolcallend` report every call by an AI app: its id, tool, arguments and AI app as it
228
299
  starts, then its outcome (`ok`, `error`, `declined` or `cancelled`), result and duration.
229
300
 
@@ -276,14 +347,17 @@ rule with two classes, such as `.tab-mcp-dialog .tab-mcp-primary` (0,2,0), wins
276
347
  of them. A page rule of one element and one pseudo-class still changes a property that the
277
348
  dialogs set only in their base rules (for example `button:hover { padding: 0 }`). Write
278
349
  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
350
+ any layered rule. All dialogs are `dialog.tab-mcp-dialog`; the connect dialog is
280
351
  `.tab-mcp-connect` (with `.tab-mcp-status`, `.tab-mcp-address`, `.tab-mcp-code`,
281
352
  `.tab-mcp-code-value`, `.tab-mcp-help`, `.tab-mcp-apps`, `.tab-mcp-app`,
282
353
  `.tab-mcp-new-address-question`, `.tab-mcp-actions`), the confirmation is
283
354
  `.tab-mcp-confirm` (with `.tab-mcp-description`, `.tab-mcp-arguments`,
284
355
  `.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
356
+ `.tab-mcp-always`, with `alwaysAllow`), and the notice after `replaced` is
357
+ `.tab-mcp-replaced` (with `.tab-mcp-description`, `.tab-mcp-status`, and the buttons
358
+ `.tab-mcp-replaced-close` and `.tab-mcp-new-address`). Buttons are `.tab-mcp-primary` (the one
359
+ next step: Copy the address, Done, "Don't allow", the safe choice, and the notice's "New
360
+ address", or its "Close" after a sibling tab), `.tab-mcp-danger` (Disconnect and
287
361
  "Disconnect and get new address") or plain; every Copy button is also `.tab-mcp-copy`, and
288
362
  the Disconnect buttons in the apps list are `.tab-mcp-disconnect`. For example:
289
363
 
package/address.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The address id in the `/tab` URL (DEC-098): a load balancer in front of
3
+ * several relays routes every request of one address to one instance by it.
4
+ * Part of the lazily loaded chunk (DEC-035), not the core.
5
+ */
6
+ /**
7
+ * The address id of a secret, as the relay derives it (DEC-027):
8
+ * base32(sha256(secret)). `undefined` where Web Crypto is missing (`null`: a
9
+ * page on plain http other than localhost) or fails; the URL then has no id,
10
+ * which one relay accepts and only a load balancer cannot route.
11
+ */
12
+ export declare function addressIdOf(secret: string, subtle?: SubtleCrypto | null): Promise<string | undefined>;
13
+ /** The `/tab` URL with `?a=<id>`. Never the secret: URLs end up in logs. */
14
+ export declare function withAddress(url: string, address: string | undefined): string;
@@ -0,0 +1,11 @@
1
+ function ae(e,t){let n=typeof e;if(n!==typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;let i=e.length;if(i!==t.length)return!1;for(let s=0;s<i;s++)if(!ae(e[s],t[s]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),s=Object.keys(t);if(i.length!==s.length)return!1;for(let o of i)if(!ae(e[o],t[o]))return!1;return!0}return e===t}function H(e){return encodeURI(st(e))}function st(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var it={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},dt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},at={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},ut=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function ee(e,t=Object.create(null),n=ut,i=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let d=e.$id||e.id;if(d){let o=new URL(d,n.href);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",i==="")n=o;else ee(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(i?"#"+i:"");if(t[s]!==void 0)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let d=new URL(e.$ref,n.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:d.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let d=new URL(e.$recursiveRef,n.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:d.href})}if(e.$anchor){let d=new URL("#"+e.$anchor,n.href);t[d.href]=e}for(let d in e){if(at[d])continue;let o=`${i}/${H(d)}`,u=e[d];if(Array.isArray(u)){if(it[d]){let v=u.length;for(let N=0;N<v;N++)ee(u[N],t,n,`${o}/${N}`)}}else if(dt[d])for(let v in u)ee(u[v],t,n,`${o}/${H(v)}`);else ee(u,t,n,o)}return t}var lt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,ft=[0,31,28,31,30,31,30,31,31,30,31,30,31],ct=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,pt=/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,yt=/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,mt=/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,gt=/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,ht=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,$t=/^(?:\/(?:[^~/]|~0|~1)*)*$/,bt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,wt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,kt=(e)=>{if(e[0]==='"')return!1;let[t,n,...i]=e.split("@");if(!t||!n||i.length!==0||t.length>64||n.length>253)return!1;if(t[0]==="."||t.endsWith(".")||t.includes(".."))return!1;if(!/^[a-z0-9.-]+$/i.test(n)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t))return!1;return n.split(".").every((s)=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(s))},Rt=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,It=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,xt=(e)=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function K(e){return e.test.bind(e)}var xe={date:Ce,time:Ne.bind(void 0,!1),"date-time":_t,duration:xt,uri:Et,"uri-reference":K(yt),"uri-template":K(mt),url:K(gt),email:kt,hostname:K(pt),ipv4:K(Rt),ipv6:K(It),regex:At,uuid:K(ht),"json-pointer":K($t),"json-pointer-uri-fragment":K(bt),"relative-json-pointer":K(wt)};function Tt(e){return e%4===0&&(e%100!==0||e%400===0)}function Ce(e){let t=e.match(lt);if(!t)return!1;let n=+t[1],i=+t[2],s=+t[3];return i>=1&&i<=12&&s>=1&&s<=(i==2&&Tt(n)?29:ft[i])}function Ne(e,t){let n=t.match(ct);if(!n)return!1;let i=+n[1],s=+n[2],d=+n[3],o=!!n[5];return(i<=23&&s<=59&&d<=59||i==23&&s==59&&d==60)&&(!e||o)}var vt=/t|\s/i;function _t(e){let t=e.split(vt);return t.length==2&&Ce(t[0])&&Ne(!0,t[1])}var St=/\/|:/,Mt=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Et(e){return St.test(e)&&Mt.test(e)}var Ot=/[^\\]\\Z/;function At(e){if(Ot.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function qe(e){let t=0,n=e.length,i=0,s;while(i<n)if(t++,s=e.charCodeAt(i++),s>=55296&&s<=56319&&i<n){if(s=e.charCodeAt(i),(s&64512)==56320)i++}return t}function O(e,t,n="2019-09",i=ee(t),s=!0,d=null,o="#",u="#",v=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let N=typeof e,_;switch(N){case"boolean":case"number":case"string":_=N;break;case"object":if(e===null)_="null";else if(Array.isArray(e))_="array";else _="object";break;default:throw Error(`Instances of "${N}" type are not supported.`)}let{$ref:U,$recursiveRef:Q,$recursiveAnchor:V,type:P,const:D,enum:J,required:L,not:f,anyOf:p,allOf:R,oneOf:x,if:y,then:T,else:S,format:r,properties:I,patternProperties:k,additionalProperties:A,unevaluatedProperties:M,minProperties:q,maxProperties:z,propertyNames:G,dependentRequired:F,dependentSchemas:B,dependencies:W,prefixItems:fe,items:re,additionalItems:Se,unevaluatedItems:Me,contains:Ee,minContains:Z,maxContains:ye,minItems:Re,maxItems:Ie,uniqueItems:nt,minimum:ne,maximum:oe,exclusiveMinimum:ce,exclusiveMaximum:pe,multipleOf:me,minLength:ge,maxLength:he,pattern:Oe,__absolute_ref__:$e,__absolute_recursive_ref__:ot}=t,l=[];if(V===!0&&d===null)d=t;if(Q==="#"){let g=d===null?i[ot]:d,m=`${u}/$recursiveRef`,w=O(e,d===null?t:d,n,i,s,g,o,m,v);if(!w.valid)l.push({instanceLocation:o,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...w.errors)}if(U!==void 0){let m=i[$e||U];if(m===void 0){let a=`Unresolved $ref "${U}".`;if($e&&$e!==U)a+=` Absolute URI "${$e}".`;throw a+=`
2
+ Known schemas:
3
+ - ${Object.keys(i).join(`
4
+ - `)}`,Error(a)}let w=`${u}/$ref`,c=O(e,m,n,i,s,d,o,w,v);if(!c.valid)l.push({instanceLocation:o,keyword:"$ref",keywordLocation:w,error:"A subschema had errors."},...c.errors);if(n==="4"||n==="7")return{valid:l.length===0,errors:l}}if(Array.isArray(P)){let g=P.length,m=!1;for(let w=0;w<g;w++)if(_===P[w]||P[w]==="integer"&&_==="number"&&e%1===0&&e===e){m=!0;break}if(!m)l.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${_}" is invalid. Expected "${P.join('", "')}".`})}else if(P==="integer"){if(_!=="number"||e%1||e!==e)l.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${_}" is invalid. Expected "${P}".`})}else if(P!==void 0&&_!==P)l.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${_}" is invalid. Expected "${P}".`});if(D!==void 0){if(_==="object"||_==="array"){if(!ae(e,D))l.push({instanceLocation:o,keyword:"const",keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(D)}.`})}else if(e!==D)l.push({instanceLocation:o,keyword:"const",keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(D)}.`})}if(J!==void 0){if(_==="object"||_==="array"){if(!J.some((g)=>ae(e,g)))l.push({instanceLocation:o,keyword:"enum",keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(J)}.`})}else if(!J.some((g)=>e===g))l.push({instanceLocation:o,keyword:"enum",keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(J)}.`})}if(f!==void 0){let g=`${u}/not`;if(O(e,f,n,i,s,d,o,g).valid)l.push({instanceLocation:o,keyword:"not",keywordLocation:g,error:'Instance matched "not" schema.'})}let be=[];if(p!==void 0){let g=`${u}/anyOf`,m=l.length,w=!1;for(let c=0;c<p.length;c++){let a=p[c],b=Object.create(v),h=O(e,a,n,i,s,V===!0?d:null,o,`${g}/${c}`,b);if(l.push(...h.errors),w=w||h.valid,h.valid)be.push(b)}if(w)l.length=m;else l.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:g,error:"Instance does not match any subschemas."})}if(R!==void 0){let g=`${u}/allOf`,m=l.length,w=!0;for(let c=0;c<R.length;c++){let a=R[c],b=Object.create(v),h=O(e,a,n,i,s,V===!0?d:null,o,`${g}/${c}`,b);if(l.push(...h.errors),w=w&&h.valid,h.valid)be.push(b)}if(w)l.length=m;else l.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:g,error:"Instance does not match every subschema."})}if(x!==void 0){let g=`${u}/oneOf`,m=l.length,w=x.filter((c,a)=>{let b=Object.create(v),h=O(e,c,n,i,s,V===!0?d:null,o,`${g}/${a}`,b);if(l.push(...h.errors),h.valid)be.push(b);return h.valid}).length;if(w===1)l.length=m;else l.splice(m,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:g,error:`Instance does not match exactly one subschema (${w} matches).`})}if(_==="object"||_==="array")Object.assign(v,...be);if(y!==void 0){let g=`${u}/if`;if(O(e,y,n,i,s,d,o,g,v).valid){if(T!==void 0){let w=O(e,T,n,i,s,d,o,`${u}/then`,v);if(!w.valid)l.push({instanceLocation:o,keyword:"if",keywordLocation:g,error:'Instance does not match "then" schema.'},...w.errors)}}else if(S!==void 0){let w=O(e,S,n,i,s,d,o,`${u}/else`,v);if(!w.valid)l.push({instanceLocation:o,keyword:"if",keywordLocation:g,error:'Instance does not match "else" schema.'},...w.errors)}}if(_==="object"){if(L!==void 0){for(let c of L)if(!(c in e))l.push({instanceLocation:o,keyword:"required",keywordLocation:`${u}/required`,error:`Instance does not have required property "${c}".`})}let g=Object.keys(e);if(q!==void 0&&g.length<q)l.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${u}/minProperties`,error:`Instance does not have at least ${q} properties.`});if(z!==void 0&&g.length>z)l.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${u}/maxProperties`,error:`Instance does not have at least ${z} properties.`});if(G!==void 0){let c=`${u}/propertyNames`;for(let a in e){let b=`${o}/${H(a)}`,h=O(a,G,n,i,s,d,b,c);if(!h.valid)l.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:c,error:`Property name "${a}" does not match schema.`},...h.errors)}}if(F!==void 0){let c=`${u}/dependantRequired`;for(let a in F)if(a in e){let b=F[a];for(let h of b)if(!(h in e))l.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:c,error:`Instance has "${a}" but does not have "${h}".`})}}if(B!==void 0)for(let c in B){let a=`${u}/dependentSchemas`;if(c in e){let b=O(e,B[c],n,i,s,d,o,`${a}/${H(c)}`,v);if(!b.valid)l.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:a,error:`Instance has "${c}" but does not match dependant schema.`},...b.errors)}}if(W!==void 0){let c=`${u}/dependencies`;for(let a in W)if(a in e){let b=W[a];if(Array.isArray(b)){for(let h of b)if(!(h in e))l.push({instanceLocation:o,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not have "${h}".`})}else{let h=O(e,b,n,i,s,d,o,`${c}/${H(a)}`);if(!h.valid)l.push({instanceLocation:o,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not match dependant schema.`},...h.errors)}}}let m=Object.create(null),w=!1;if(I!==void 0){let c=`${u}/properties`;for(let a in I){if(!(a in e))continue;let b=`${o}/${H(a)}`,h=O(e[a],I[a],n,i,s,d,b,`${c}/${H(a)}`);if(h.valid)v[a]=m[a]=!0;else if(w=s,l.push({instanceLocation:o,keyword:"properties",keywordLocation:c,error:`Property "${a}" does not match schema.`},...h.errors),w)break}}if(!w&&k!==void 0){let c=`${u}/patternProperties`;for(let a in k){let b=new RegExp(a,"u"),h=k[a];for(let j in e){if(!b.test(j))continue;let Ae=`${o}/${H(j)}`,Pe=O(e[j],h,n,i,s,d,Ae,`${c}/${H(a)}`);if(Pe.valid)v[j]=m[j]=!0;else w=s,l.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:c,error:`Property "${j}" matches pattern "${a}" but does not match associated schema.`},...Pe.errors)}}}if(!w&&A!==void 0){let c=`${u}/additionalProperties`;for(let a in e){if(m[a])continue;let b=`${o}/${H(a)}`,h=O(e[a],A,n,i,s,d,b,c);if(h.valid)v[a]=!0;else w=s,l.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:c,error:`Property "${a}" does not match additional properties schema.`},...h.errors)}}else if(!w&&M!==void 0){let c=`${u}/unevaluatedProperties`;for(let a in e)if(!v[a]){let b=`${o}/${H(a)}`,h=O(e[a],M,n,i,s,d,b,c);if(h.valid)v[a]=!0;else l.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:c,error:`Property "${a}" does not match unevaluated properties schema.`},...h.errors)}}}else if(_==="array"){if(Ie!==void 0&&e.length>Ie)l.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${u}/maxItems`,error:`Array has too many items (${e.length} > ${Ie}).`});if(Re!==void 0&&e.length<Re)l.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${u}/minItems`,error:`Array has too few items (${e.length} < ${Re}).`});let g=e.length,m=0,w=!1;if(fe!==void 0){let c=`${u}/prefixItems`,a=Math.min(fe.length,g);for(;m<a;m++){let b=O(e[m],fe[m],n,i,s,d,`${o}/${m}`,`${c}/${m}`);if(v[m]=!0,!b.valid){if(w=s,l.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:c,error:"Items did not match schema."},...b.errors),w)break}}}if(re!==void 0){let c=`${u}/items`;if(Array.isArray(re)){let a=Math.min(re.length,g);for(;m<a;m++){let b=O(e[m],re[m],n,i,s,d,`${o}/${m}`,`${c}/${m}`);if(v[m]=!0,!b.valid){if(w=s,l.push({instanceLocation:o,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...b.errors),w)break}}}else for(;m<g;m++){let a=O(e[m],re,n,i,s,d,`${o}/${m}`,c);if(v[m]=!0,!a.valid){if(w=s,l.push({instanceLocation:o,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...a.errors),w)break}}if(!w&&Se!==void 0){let a=`${u}/additionalItems`;for(;m<g;m++){let b=O(e[m],Se,n,i,s,d,`${o}/${m}`,a);if(v[m]=!0,!b.valid)w=s,l.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:a,error:"Items did not match additional items schema."},...b.errors)}}}if(Ee!==void 0)if(g===0&&Z===void 0)l.push({instanceLocation:o,keyword:"contains",keywordLocation:`${u}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(Z!==void 0&&g<Z)l.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${u}/minContains`,error:`Array has less items (${g}) than minContains (${Z}).`});else{let c=`${u}/contains`,a=l.length,b=0;for(let h=0;h<g;h++){let j=O(e[h],Ee,n,i,s,d,`${o}/${h}`,c);if(j.valid)v[h]=!0,b++;else l.push(...j.errors)}if(b>=(Z||0))l.length=a;if(Z===void 0&&ye===void 0&&b===0)l.splice(a,0,{instanceLocation:o,keyword:"contains",keywordLocation:c,error:"Array does not contain item matching schema."});else if(Z!==void 0&&b<Z)l.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${u}/minContains`,error:`Array must contain at least ${Z} items matching schema. Only ${b} items were found.`});else if(ye!==void 0&&b>ye)l.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${u}/maxContains`,error:`Array may contain at most ${ye} items matching schema. ${b} items were found.`})}if(!w&&Me!==void 0){let c=`${u}/unevaluatedItems`;for(m;m<g;m++){if(v[m])continue;let a=O(e[m],Me,n,i,s,d,`${o}/${m}`,c);if(v[m]=!0,!a.valid)l.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:c,error:"Items did not match unevaluated items schema."},...a.errors)}}if(nt)for(let c=0;c<g;c++){let a=e[c],b=typeof a==="object"&&a!==null;for(let h=0;h<g;h++){if(c===h)continue;let j=e[h];if(a===j||b&&(typeof j==="object"&&j!==null)&&ae(a,j))l.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${u}/uniqueItems`,error:`Duplicate items at indexes ${c} and ${h}.`}),c=Number.MAX_SAFE_INTEGER,h=Number.MAX_SAFE_INTEGER}}}else if(_==="number"){if(n==="4"){if(ne!==void 0&&(ce===!0&&e<=ne||e<ne))l.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${u}/minimum`,error:`${e} is less than ${ce?"or equal to ":""} ${ne}.`});if(oe!==void 0&&(pe===!0&&e>=oe||e>oe))l.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${u}/maximum`,error:`${e} is greater than ${pe?"or equal to ":""} ${oe}.`})}else{if(ne!==void 0&&e<ne)l.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${u}/minimum`,error:`${e} is less than ${ne}.`});if(oe!==void 0&&e>oe)l.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${u}/maximum`,error:`${e} is greater than ${oe}.`});if(ce!==void 0&&e<=ce)l.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${u}/exclusiveMinimum`,error:`${e} is less than ${ce}.`});if(pe!==void 0&&e>=pe)l.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${u}/exclusiveMaximum`,error:`${e} is greater than or equal to ${pe}.`})}if(me!==void 0){let g=e%me;if(Math.abs(0-g)>=0.00000011920929&&Math.abs(me-g)>=0.00000011920929)l.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${u}/multipleOf`,error:`${e} is not a multiple of ${me}.`})}}else if(_==="string"){let g=ge===void 0&&he===void 0?0:qe(e);if(ge!==void 0&&g<ge)l.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${u}/minLength`,error:`String is too short (${g} < ${ge}).`});if(he!==void 0&&g>he)l.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${u}/maxLength`,error:`String is too long (${g} > ${he}).`});if(Oe!==void 0&&!new RegExp(Oe,"u").test(e))l.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${u}/pattern`,error:"String does not match pattern."});if(r!==void 0&&xe[r]&&!xe[r](e))l.push({instanceLocation:o,keyword:"format",keywordLocation:`${u}/format`,error:`String does not match format "${r}".`})}return{valid:l.length===0,errors:l}}var ze="ch.ractive.tab-mcp/annotations",Pt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Ct=["destructiveHint","idempotentHint","openWorldHint"];function He(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let s of Ct){let d=e[s];if(d!==void 0)t[s]=d}let n={};for(let s of Pt){let d=e[s];if(d!==void 0)n[s]=d}let i={};if(Object.keys(t).length>0)i.annotations=t;if(Object.keys(n).length>0)i.meta=n;return i}function X(e){return{content:[{type:"text",text:e}],isError:!0}}function je(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Je(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(je(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return X("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]};if(je(e))n.structuredContent=e;return n}function Be(e){let t=e instanceof Error?e.message:String(e);return X(t||"The tool failed.")}var se="2026-07-28",te="io.modelcontextprotocol/protocolVersion",we="io.modelcontextprotocol/clientCapabilities",Ue="io.modelcontextprotocol/clientInfo",Nt="io.modelcontextprotocol/serverInfo",Te="io.modelcontextprotocol/subscriptionId",qt=-32020,Ve=-32022,jt=0,De=new WeakMap;function ve(e){let t=De.get(e);if(t!==void 0)return t;let n=e.inputSchema,i;try{i=ee(n)}catch(d){let o=d instanceof Error?d.message:String(d);throw Error(o.split(`
5
+ `)[0])}for(let d of Object.values(i)){if(typeof d!=="object"||d.$ref===void 0)continue;let o=d.__absolute_ref__;if(i[o??d.$ref]===void 0)throw Error(`$ref ${JSON.stringify(d.$ref)} does not resolve`)}let s=(d)=>O(d,n,"2020-12",i,!1);return De.set(e,s),s}function Ge(e,t,n=""){let i=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${i}${n}`)}function zt(e){let t=[];for(let n of e.list())try{ve(n)}catch(i){e.remove(n),t.push(Ge(n.name,i,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{ve(n)}catch(i){throw Ge(n.name,i)}}),t}function We(e){try{return structuredClone(e)}catch{return e}}var Ht=new TextEncoder;function ie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function _e(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function C(e,t,n,i,s){let d={code:n,message:i};if(s!==void 0)d.data=s;return _e(e,{jsonrpc:"2.0",id:t,error:d})}function Y(e,t,n){return C(400,e,qt,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ue(e){return Ht.encode(`event: message
6
+ data: ${JSON.stringify(e)}
7
+
8
+ `)}var Ke={"content-type":"text/event-stream","cache-control":"no-cache"};function Jt(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function Bt(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),i=Uint8Array.from(n,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(i)}catch{return}}function Ut(e){if(!(te in e))return{key:te,problem:"missing"};if(!(we in e))return{key:we,problem:"missing"};if(typeof e[te]!=="string")return{key:te,problem:"expected a protocol version string"};if(!ie(e[we]))return{key:we,problem:"expected an object"};let t=e[Ue];if(t!==void 0&&!(ie(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ue,problem:"expected {name, version}"};return}function Vt(e){let t=e.notifications;return ie(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Ye(e){let{tools:t,server:n}=e,i={name:n.name,version:n.version};if(n.title!==void 0)i.title=n.title;let s=new Set,d=!1,o=(f={})=>({...f,[Nt]:i});function u(f,p){return{jsonrpc:"2.0",id:f,result:{...p,resultType:"complete",_meta:o()}}}function v(f,p){let R;try{R=ve(f)(p)}catch(y){let T=y instanceof Error?y.message:String(y);return`The input schema of tool ${f.name} cannot be used: ${T}`}if(R.valid)return;let x=R.errors.filter((y)=>y.keyword!=="properties"&&y.keyword!=="$ref").map((y)=>`${y.instanceLocation} ${y.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${f.name}: ${x||"the arguments do not match the schema"}`}function N(){return t.list().map((f)=>{let p={name:f.name};if(f.title!==void 0)p.title=f.title;p.description=f.description,p.inputSchema=f.inputSchema;let{annotations:R,meta:x}=He(f.annotations);if(R!==void 0)p.annotations=R;if(x!==void 0)p._meta={[ze]:x};return p})}let _=(f)=>({kind:"invalid",message:f});async function U(f,p,R){let x=f.name;if(typeof x!=="string")return _("Invalid params: name must be a string");let y=t.get(x);if(y===void 0)return _(`Tool ${x} not found`);let T=f.arguments??{};if(!ie(T))return _("Invalid params: arguments must be an object");let S=e.client(R),r={id:++jt,tool:y.name,arguments:We(T),client:{...S}};if(y.title!==void 0)r.title=y.title;let I=Date.now();e.observe?.start(r);let k="error",A=X("Internal error");try{[k,A]=await Q(y,T,p,S)}finally{e.observe?.end({id:r.id,tool:y.name,client:{...S},outcome:k,result:We(A),durationMs:Date.now()-I})}return{kind:"result",result:A}}async function Q(f,p,R,x){let y=v(f,p);if(y!==void 0)return["error",X(y)];if(f.annotations.consequentialHint===!0){let S={tool:{name:f.name,description:f.description},arguments:p,client:x,signal:R};if(f.title!==void 0)S.tool.title=f.title;let r=!1;try{r=await e.confirm(S)}catch{r=!1}if(!r)return[R.aborted?"cancelled":"declined",X("The user declined")]}if(R.aborted)return["cancelled",X("Cancelled")];if(t.get(f.name)!==f)return["error",X("The tool is no longer available")];let T;try{T=Je(await f.execute(p,{signal:R,client:x}))}catch(S){T=Be(S)}if(R.aborted)return["cancelled",T];return[T.isError===!0?"error":"ok",T]}function V(f,p,R,x){let y=new ReadableStream({start:(T)=>{let S=(r)=>{if(R.aborted)return;let I;try{I=ue(r)}catch{I=ue(u(f,X("The tool returned a result that is not JSON.")))}try{T.enqueue(I),T.close()}catch{}};U(p,R,x).then((r)=>S(r.kind==="invalid"?{jsonrpc:"2.0",id:f,error:{code:-32602,message:r.message}}:u(f,r.result)),()=>S({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}}))}});return new Response(y,{status:200,headers:Ke})}function P(f,p,R){let x=Vt(p),y={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:o({[Te]:f})}},T,S=new ReadableStream({start:(r)=>{if(r.enqueue(ue({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:x,_meta:{[Te]:f}}})),Object.keys(x).length===0){r.enqueue(ue(y)),r.close();return}let I={id:f,send:(k)=>{try{r.enqueue(ue(k))}catch{s.delete(I)}},end:()=>{s.delete(I);try{r.enqueue(ue(y)),r.close()}catch{}}};T=I,s.add(I),R.addEventListener("abort",()=>{s.delete(I);try{r.close()}catch{}})},cancel:()=>{if(T!==void 0)s.delete(T)}});return new Response(S,{status:200,headers:Ke})}function D(f,p){if(Array.isArray(p))return C(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!ie(p)||p.jsonrpc!=="2.0")return C(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:R,id:x}=p;if(typeof R!=="string")return"result"in p||"error"in p?C(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):C(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let y=f.headers.get("mcp-protocol-version"),T=f.headers.get("mcp-method"),S=ie(p.params)?p.params:{},r=ie(S._meta)?S._meta:void 0,I=r!==void 0&&te in r,k=typeof r?.[te]==="string"?r[te]:void 0,A=y!==null&&y>=se;if(x===void 0){if(k!==void 0&&y!==null&&y!==k)return Y(null,y,`the notification envelope names protocol version ${k} but the MCP-Protocol-Version header names ${y}`);if((I||A)&&T!==null&&T!==R)return Y(null,T,`the notification body names method ${R} but the Mcp-Method header names ${T}`);return"notification"}if(typeof x!=="string"&&typeof x!=="number")return C(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let M=x;if(!I||R==="initialize"&&(k===void 0||k<se)){if(R==="initialize"){if(A)return Y(M,y,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let z=typeof S.protocolVersion==="string"?S.protocolVersion:void 0;return J(M,z)}if(A){let z=r===void 0?["_meta"]:[te];return C(400,M,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${y}, but the request is missing the required per-request envelope key(s): ${z.join(", ")}`,{envelope:{missing:z}})}return J(M,y??void 0)}let q=Ut(r);if(q!==void 0)return C(400,M,-32602,`Invalid _meta envelope for protocol revision ${se}: ${q.key}: ${q.problem}`,{envelope:q});if(y!==null&&k!==void 0&&y!==k)return Y(M,y,`the body envelope names protocol version ${k} but the MCP-Protocol-Version header names ${y}`);if(T!==null&&T!==R)return Y(M,T,`the body names method ${R} but the Mcp-Method header names ${T}`);if(k!==se)return J(M,k);if(y===null)return Y(M,"(missing)",`the body envelope names protocol version ${k} but the required MCP-Protocol-Version header is absent`);if(T===null)return Y(M,"(missing)",`the body names method ${R} but the required Mcp-Method header is absent`);if(R==="tools/call"&&typeof S.name==="string"){let z=S.name,G=f.headers.get("mcp-name");if(G===null)return Y(M,"(missing)",`the body carries params.name="${z}" but the required Mcp-Name header is absent`);let F=Bt(G);if(F===void 0)return Y(M,G,"the Mcp-Name header carries an invalid Base64 sentinel value");if(F!==z)return Y(M,G,`the body carries params.name="${z}" but the Mcp-Name header names "${F}"`)}return{id:M,method:R,params:S}}function J(f,p){return p===void 0?C(400,f,Ve,"Unsupported protocol version: the request did not name a protocol version",{supported:[se]}):C(400,f,Ve,`Unsupported protocol version: ${p}`,{supported:[se],requested:p})}async function L(f,p){if(f.method.toUpperCase()!=="POST")return C(405,null,-32000,"Method not allowed.");if(!Jt(f.headers.get("content-type")))return C(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let R;try{R=JSON.parse(p.body??await f.text())}catch{return C(400,null,-32700,"Parse error: the request body is not valid JSON")}let x=D(f,R);if(x instanceof Response)return x;if(x==="notification")return new Response(null,{status:202});let{id:y,method:T,params:S}=x;switch(T){case"server/discover":{let r={supportedVersions:[se],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)r.instructions=n.instructions;return r.ttlMs=0,r.cacheScope="private",_e(200,u(y,r))}case"tools/list":return _e(200,u(y,{tools:N(),ttlMs:0,cacheScope:"private"}));case"tools/call":return V(y,S,f.signal,p.grant);case"subscriptions/listen":return P(y,S,f.signal);default:return C(404,y,-32601,"Method not found")}}return{handle:(f,p)=>L(f,p).catch(()=>C(500,null,-32603,"Internal server error")),toolsChanged(){if(d)return;d=!0,queueMicrotask(()=>{d=!1;for(let f of[...s])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Te]:f.id}}})})},close(){for(let f of[...s])f.end()}}}var ke="tab-mcp.v1";function le(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var E=(e)=>typeof e==="string";function Fe(e){if(!le(e)||!E(e.grantId)||!E(e.createdAt))return!1;let t=e.client;return le(t)&&E(t.id)&&E(t.name)&&E(t.host)}function Dt(e){if(!le(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Gt(e){return le(e)&&Object.values(e).every(E)}function Ze(e){let t;try{t=JSON.parse(e)}catch{return}if(!le(t))return;switch(t.type){case"session":return E(t.sessionId)&&E(t.address)&&E(t.origin)&&E(t.expiresAt)&&Dt(t.limits)&&Array.isArray(t.grants)&&t.grants.every(Fe)&&(t.appName===void 0||E(t.appName))&&(t.pairing===void 0||E(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:E(t.reason)?t.reason:""};case"http.request":return E(t.id)&&E(t.method)&&E(t.path)&&Gt(t.headers)&&E(t.body)&&le(t.grant)&&E(t.grant.grantId)&&E(t.grant.clientId)?t:void 0;case"http.cancel":return E(t.id)?t:void 0;case"pairing.code":return E(t.code)&&E(t.expiresAt)?t:void 0;case"grant.added":return Fe(t.grant)?t:void 0;case"grant.removed":return E(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:E(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return E(t.code)?t:void 0;default:return}}function Wt(e){let t="",n=0,i=0;for(let s of e){n=n<<8|s,i+=8;while(i>=5)i-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>i&31];n&=(1<<i)-1}if(i>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-i&31];return t}async function Kt(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return Wt(new Uint8Array(n))}catch{return}}function Yt(e,t){if(t===void 0)return e;let n=new URL(e);return n.searchParams.set("a",t),n.href}var Ft=15000,Xe={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited",4009:"policy"},Qe={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var Zt=["content-type","cache-control"];function Xt(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function Qt(e){try{let t=JSON.parse(e);if(typeof t!=="object"||t===null||typeof t.type!=="string")return;return typeof t.id==="string"?{type:t.type,id:t.id}:{type:t.type}}catch{return}}var Lt=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),et=512,tt=6,rt=64,er=et+tt*rt;function tr(e){let t=Math.floor((e-et)/tt);return t>=rt?t:void 0}function*Le(e,t){let n=0;while(n<e.length){let i=Math.min(n+t,e.length),s=e.charCodeAt(i-1);if(i<e.length&&s>=55296&&s<=56319)i+=i-1>n?-1:1;yield e.slice(n,i),n=i}}var rr=1e4,nr=1000;function or(e){let t,n=Number.NEGATIVE_INFINITY,i;try{if(e!==void 0&&typeof BroadcastChannel==="function")t=new BroadcastChannel(e),t.onmessage=(s)=>{if(s.data?.type!=="claimed")return;n=Date.now(),i?.()}}catch{t=void 0}return{claimed(){try{t?.postMessage({type:"claimed"})}catch{}},heard(){if(Date.now()-n<=rr)return Promise.resolve(!0);if(t===void 0)return Promise.resolve(!1);return new Promise((s)=>{let d=setTimeout(()=>s(!1),nr);i=()=>{clearTimeout(d),s(!0)}})},close(){t?.close()}}}function Tr(e,t,n,i=!1){let s=new WebSocket(t,ke),d=new Map,o="opening",u,v=65536,N,_=0,U=or(e.tabs),Q,V,P,D=new Promise((r,I)=>{V=r,P=I});D.catch(()=>{});let J=setTimeout(()=>{x(de("The relay did not answer in time.","network"))},Ft),L=Ye({tools:e.registry,server:e.server,confirm:(r)=>e.confirm(r),client:(r)=>e.clientFor(r),observe:{start:(r)=>e.toolCallStarted(r),end:(r)=>e.toolCallEnded(r)}}),f=e.registry.onChange(()=>L.toolsChanged());function p(r){if(s.readyState!==WebSocket.OPEN)return!1;try{return s.send(JSON.stringify(r)),!0}catch{return!1}}function R(){if(_<=0)return;clearTimeout(N),N=setTimeout(()=>{u??="heartbeat",y(4003);try{s.close()}catch{}},_*2.5)}function x(r){if(o!=="opening")return;y(0),P(r);try{s.close()}catch{}}function y(r){if(o==="closed")return;let I=o==="ready";o="closed",clearTimeout(J),clearTimeout(N),f();for(let k of d.values())k.abort();if(d.clear(),L.close(),I){let k=u??Xe[r]??(r===1006?"network":"closed");if(P(de("The address was taken over again before its AI apps were disconnected.",k)),e.closed(k,r),k==="replaced"){U.heard().then((A)=>{U.close(),e.replaced({sibling:A})});return}}U.close()}async function T(r){let I=new AbortController;d.set(r.id,I);let k=()=>o==="ready"&&d.get(r.id)===I&&!I.signal.aborted;try{let A=new Request(`https://tab.invalid${r.path}`,{method:r.method,headers:r.headers,signal:I.signal}),M=await L.handle(A,{grant:r.grant,body:r.body});if(!k()){await M.body?.cancel().catch(()=>{});return}let q={};for(let B of Zt){let W=M.headers.get(B);if(W!==null)q[B]=W}if(!(q["content-type"]??"").startsWith("text/event-stream")||M.body===null){let B=await M.text();if(!k())return;if(B.length<=v){p({type:"http.response",id:r.id,status:M.status,headers:q,body:B});return}p({type:"http.response.start",id:r.id,status:M.status,headers:q});for(let W of Le(B,v)){if(!k())break;p({type:"http.response.chunk",id:r.id,data:W})}if(k())p({type:"http.response.end",id:r.id});return}p({type:"http.response.start",id:r.id,status:M.status,headers:q});let G=M.body.getReader(),F=new TextDecoder;I.signal.addEventListener("abort",()=>{G.cancel().catch(()=>{})});for(;;){let{done:B,value:W}=await G.read();if(B||!k())break;let fe=F.decode(W,{stream:!0});for(let re of Le(fe,v))p({type:"http.response.chunk",id:r.id,data:re})}if(k())p({type:"http.response.end",id:r.id})}catch(A){if(k())e.error(A instanceof Error?A:Error(String(A))),p({type:"http.response",id:r.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(d.get(r.id)===I)d.delete(r.id)}}function S(r){if(o==="opening"){if(r.type==="session"){let I=tr(r.limits.maxMessageBytes);if(I===void 0){x(de(`The relay's message limit (${r.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${er}.`,"policy"));return}v=I,o="ready",clearTimeout(J),_=r.limits.heartbeatMs,R(),U.claimed();let k=e.sessionStarted(r);if(i&&r.grants.length>0){Q={left:new Set(r.grants.map((A)=>A.grantId)),session:k},p({type:"grants.revokeAll"});return}V(k)}else if(r.type==="error")x(de(`The relay refused the connection: ${r.message||r.code}`,r.code==="rate_limited"?"rate_limited":"policy"));else if(r.type==="bye")x(de(`The relay ended the connection: ${r.reason}`,Qe[r.reason]??"closed"));return}if(o!=="ready")return;switch(r.type){case"ping":R(),p({type:"pong",t:r.t});return;case"http.request":T(r);return;case"http.cancel":d.get(r.id)?.abort(),d.delete(r.id);return;case"pairing.code":e.pairingCode({code:r.code,expiresAt:r.expiresAt});return;case"grant.added":e.grantAdded(r.grant);return;case"grant.removed":if(e.grantRemoved(r.grantId),Q?.left.delete(r.grantId),Q?.left.size===0)V(Q.session);return;case"identity.bound":e.identityResult(!0,r.round);return;case"bye":if(u=Qe[r.reason]??"closed",u==="replaced")y(4005);return;case"error":if(r.code==="identity_refused"){e.identityResult(!1,typeof r.round==="number"?r.round:void 0,r.message);return}e.error(Error(`Relay error ${r.code}: ${r.message}`));return;case"session":return}}return s.addEventListener("open",()=>{if(s.protocol!==""&&s.protocol!==ke){x(de(`The relay speaks ${s.protocol}, not ${ke}.`,"policy"));return}let r={type:"hello",library:e.library,page:{title:Xt()},secret:n};if(e.appName!==void 0)r.app={name:e.appName};if(i)r.revokeAll=!0;p(r)}),s.addEventListener("message",(r)=>{if(typeof r.data!=="string")return;let I=Ze(r.data);if(I!==void 0){if(o==="ready")R();S(I);return}let k=Qt(r.data);if(k?.id!==void 0)p(Lt.has(k.type)?{type:"error",code:"bad_message",message:`malformed ${k.type}`,id:k.id}:{type:"error",code:"unknown_type",message:`unknown type ${k.type}`,id:k.id})}),s.addEventListener("close",(r)=>{if(o==="opening"){y(r.code);let I=r.code===1006||r.code===1002;P(de(I?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${r.code}${r.reason?`: ${r.reason}`:""}).`,Xe[r.code]??(I?"network":"closed")));return}y(r.code)}),{ready:D,send:p,close(r){if(o==="closed")return;if(o==="opening"){x(new DOMException("The connection was cancelled","AbortError"));return}u=r,p({type:"bye",reason:"user"}),y(1000);try{s.close(1000,"bye")}catch{}}}}export{Kt as addressIdOf,zt as compileRegistry,Tr as openConnection,Yt as withAddress};
9
+
10
+ //# debugId=82F57D842A282E8164756E2164756E21
11
+ //# sourceMappingURL=connection-ssyf3414.min.js.map