@ractive-ch/tab-mcp-client 0.10.0 → 0.12.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 +71 -18
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/cdn/connection-gh2ayv77.min.js +11 -0
- package/cdn/connection-gh2ayv77.min.js.map +21 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +2 -2
- package/cdn/ui-j8sthahc.min.js +86 -0
- package/cdn/ui-j8sthahc.min.js.map +14 -0
- package/command.d.ts +20 -0
- package/{connection-eqqkev02.js → connection-c0vttra5.js} +21 -5
- package/{connection-eqqkev02.js.map → connection-c0vttra5.js.map} +4 -4
- package/index-dmh5vm5m.js +15 -0
- package/index-dmh5vm5m.js.map +10 -0
- package/index-nmn1j689.js +59 -0
- package/index-nmn1j689.js.map +11 -0
- package/index.d.ts +1 -1
- package/index.js +6 -6
- package/index.js.map +2 -2
- package/package.json +10 -2
- package/protocol.d.ts +3 -1
- package/setup.d.ts +44 -0
- package/setup.js +11 -0
- package/setup.js.map +9 -0
- package/types.d.ts +8 -0
- package/{ui-57hyd701.js → ui-azxkzgky.js} +217 -113
- package/ui-azxkzgky.js.map +11 -0
- package/ui.d.ts +17 -26
- package/version.d.ts +1 -1
- package/visible.d.ts +11 -0
- package/visible.js +9 -0
- package/visible.js.map +9 -0
- package/cdn/connection-9w0rx0vf.min.js +0 -11
- package/cdn/connection-9w0rx0vf.min.js.map +0 -21
- package/cdn/ui-406jbpym.min.js +0 -75
- package/cdn/ui-406jbpym.min.js.map +0 -11
- package/ui-57hyd701.js.map +0 -11
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.12.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.
|
|
25
|
+
ractive/tab-mcp:0.9.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.
|
|
41
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.12.0/cdn/tab-mcp-client.min.js";
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -126,21 +126,28 @@ Tools are called while the user is in the AI app, so the dialog often opens in a
|
|
|
126
126
|
the background. "Allow" and "Always allow" can be clicked only once the page has been
|
|
127
127
|
visible and focused for `confirmDelayMs` (750 ms) with the dialog open; leaving the page
|
|
128
128
|
disables them and coming back starts the wait again, so the click that brings the page
|
|
129
|
-
forward cannot approve. Characters that are invisible
|
|
130
|
-
as U+202E) are shown in the arguments
|
|
131
|
-
|
|
129
|
+
forward cannot approve. Characters that are invisible, blank (such as U+00A0, U+3000 or
|
|
130
|
+
U+2800) or change the text direction (such as U+202E) are shown in the arguments and the
|
|
131
|
+
AI app's name as `\uXXXX`, so the AI app cannot make them look like something else; the
|
|
132
|
+
tool gets the arguments unchanged.
|
|
132
133
|
|
|
133
134
|
Pass `onConfirm` to ask in your own UI (it is asked every time; remember answers there if
|
|
134
135
|
you want to). Show the verified `client.host` next to the name the AI app declares, as the
|
|
135
|
-
library's dialog does, since anyone can declare any name
|
|
136
|
+
library's dialog does, since anyone can declare any name. Escape the arguments and the
|
|
137
|
+
name as the dialog does with `escapeInvisible` from `@ractive-ch/tab-mcp-client/visible`
|
|
138
|
+
(an entry of its own, not in the core):
|
|
136
139
|
|
|
137
140
|
```ts
|
|
141
|
+
import { escapeInvisible } from "@ractive-ch/tab-mcp-client/visible";
|
|
142
|
+
|
|
138
143
|
const mcp = new TabMcp({
|
|
139
144
|
relay: "https://relay.example",
|
|
140
145
|
server: { name: "calculator", version: "1.0.0" },
|
|
141
146
|
onConfirm: ({ tool, arguments: args, client, signal }) => {
|
|
142
|
-
const
|
|
143
|
-
|
|
147
|
+
const name = client.name ? escapeInvisible(client.name) : undefined;
|
|
148
|
+
const app = name ? `${name} (${client.host})` : client.host;
|
|
149
|
+
const shown = escapeInvisible(JSON.stringify(args, null, 2));
|
|
150
|
+
return myDialog.ask(`${app} wants to run ${tool.name}.`, shown, signal);
|
|
144
151
|
},
|
|
145
152
|
});
|
|
146
153
|
```
|
|
@@ -169,10 +176,22 @@ handles only some calls itself.
|
|
|
169
176
|
3. The AI app opens the relay's sign-in page in the browser. The dialog shows a 6-digit
|
|
170
177
|
code with a Copy button, which the user types or pastes there. The code changes every
|
|
171
178
|
2 minutes and after each use.
|
|
172
|
-
4.
|
|
173
|
-
"
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
4. Once the AI app connects, the dialog says so at the top: a check mark, "Claude
|
|
180
|
+
(claude.ai) is connected" and what to do next (close it and ask the app to use the
|
|
181
|
+
page's tools); screen readers hear the same. The setup (address, code, help) moves
|
|
182
|
+
behind "Connect another app", closed, so the next code does not appear in view; the
|
|
183
|
+
connected app is listed with a Disconnect button, and "Done" closes the dialog.
|
|
184
|
+
Opened again while an app is connected, the dialog starts like this, with the focus
|
|
185
|
+
on Done.
|
|
186
|
+
|
|
187
|
+
The relay makes a new code the moment one is entered, but the AI app connects only a
|
|
188
|
+
moment later. When the relay says the code was used (`reason: "used"` in the event
|
|
189
|
+
`pairingcode`), the dialog shows "Code used. Waiting for your AI app…" instead of the new
|
|
190
|
+
code, for up to 10 seconds; if no app connects by then, the new code appears. A code that
|
|
191
|
+
replaces an expired or locked one (too many wrong tries), or one from a relay that does not
|
|
192
|
+
say why, shows at once.
|
|
193
|
+
|
|
194
|
+
Until an app is connected, the dialog offers no prominent button under the code: only a small
|
|
176
195
|
"Close" at the bottom (and Escape). Closing it stops the code (`stopPairing()`); the page
|
|
177
196
|
stays connected and the address stays the same, so calling `showConnectDialog()` again
|
|
178
197
|
shows the same address with a new code. While the dialog is open, calling it again (a
|
|
@@ -345,14 +364,43 @@ mcp.addEventListener("toolcallend", (e) => {
|
|
|
345
364
|
});
|
|
346
365
|
```
|
|
347
366
|
|
|
367
|
+
### Setup steps in your own UI
|
|
368
|
+
|
|
369
|
+
`@ractive-ch/tab-mcp-client/setup` has the steps the connect dialog shows under "How do I
|
|
370
|
+
add it?", as data for your own UI. An entry of its own, out of the core, and not in the CDN
|
|
371
|
+
build. `setupInstructions(serverName, address)` returns one entry per AI app (Claude,
|
|
372
|
+
ChatGPT, Claude Code, Codex, in that order): `id` (`claude`, `chatgpt`, `claude-code`,
|
|
373
|
+
`codex`), `app` (its name as shown), `text` (what to do), `command` (lines to run, for
|
|
374
|
+
Claude Code and Codex) and `note` (text and code parts, for Codex). Every string is plain
|
|
375
|
+
text: set it with `textContent`. The commands name the server by a label made from
|
|
376
|
+
`serverName` and contain the address only when every shell reads both as plain words (see
|
|
377
|
+
step 2 above), so they are safe to show with a Copy button; for an address that is not
|
|
378
|
+
plain, `command` is left out and `text` names the command instead. `SETUP_GUIDE` is the
|
|
379
|
+
guide with every step and what to do when it fails.
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
import { SETUP_GUIDE, setupInstructions } from "@ractive-ch/tab-mcp-client/setup";
|
|
383
|
+
|
|
384
|
+
const el = (tag: string, text: string) =>
|
|
385
|
+
Object.assign(document.createElement(tag), { textContent: text });
|
|
386
|
+
// `session` is what `mcp.connect()` resolved to; "notes" is your `server.name`.
|
|
387
|
+
for (const { app, text, command, note } of setupInstructions("notes", session.address)) {
|
|
388
|
+
const li = list.appendChild(document.createElement("li"));
|
|
389
|
+
li.append(el("strong", app), ` ${text}`);
|
|
390
|
+
if (command) li.append(el("pre", command)); // and a Copy button for it
|
|
391
|
+
for (const part of note ?? []) li.append("code" in part ? el("code", part.code) : part.text);
|
|
392
|
+
}
|
|
393
|
+
guide.href = SETUP_GUIDE;
|
|
394
|
+
```
|
|
395
|
+
|
|
348
396
|
### Styling the default dialogs
|
|
349
397
|
|
|
350
398
|
The default dialogs bring their own stylesheet, a constructed stylesheet added to
|
|
351
399
|
`document.adoptedStyleSheets`, so a strict CSP needs no `style-src` exception. It uses
|
|
352
400
|
the page's font and system colours, and follows the page's `color-scheme`: declare
|
|
353
401
|
`color-scheme: light dark` (or `<meta name="color-scheme" content="light dark">`) and the
|
|
354
|
-
dialogs are dark in dark mode. They fit a 360 px wide screen, and they open
|
|
355
|
-
animation when the user prefers reduced motion.
|
|
402
|
+
dialogs are dark in dark mode. They fit a 360 px wide screen, and they open (and show the
|
|
403
|
+
check mark of a connected app) without animation when the user prefers reduced motion.
|
|
356
404
|
|
|
357
405
|
To adjust single values, set these custom properties on `:root` or on `.tab-mcp-dialog`:
|
|
358
406
|
|
|
@@ -366,6 +414,7 @@ To adjust single values, set these custom properties on `:root` or on `.tab-mcp-
|
|
|
366
414
|
| `--tab-mcp-accent` | the text colour | background of the primary button |
|
|
367
415
|
| `--tab-mcp-accent-text` | the background colour | text of the primary button |
|
|
368
416
|
| `--tab-mcp-danger` | dark red, light red in dark mode | Disconnect buttons |
|
|
417
|
+
| `--tab-mcp-success` | dark green, light green in dark mode | the check mark and the box of "… is connected" |
|
|
369
418
|
| `--tab-mcp-focus` | the text colour | focus ring |
|
|
370
419
|
| `--tab-mcp-border` | `1px solid` the text colour at 22 % | border of the dialog |
|
|
371
420
|
| `--tab-mcp-radius` | `0.75rem` | corners of the dialog (buttons and boxes: 60 % of it) |
|
|
@@ -389,14 +438,18 @@ dialogs set only in their base rules (for example `button:hover { padding: 0 }`)
|
|
|
389
438
|
overrides outside cascade layers: the dialogs' rules are not in a layer, so they win over
|
|
390
439
|
any layered rule. All dialogs are `dialog.tab-mcp-dialog`; the connect dialog is
|
|
391
440
|
`.tab-mcp-connect` (with `.tab-mcp-status`, `.tab-mcp-address`, `.tab-mcp-code`,
|
|
392
|
-
`.tab-mcp-code-value`, `.tab-mcp-
|
|
393
|
-
`.tab-mcp-new-address-question`, `.tab-mcp-actions
|
|
441
|
+
`.tab-mcp-code-value`, `.tab-mcp-code-used`, `.tab-mcp-help`, `.tab-mcp-apps`,
|
|
442
|
+
`.tab-mcp-app`, `.tab-mcp-new-address-question`, `.tab-mcp-actions`; once an app is
|
|
443
|
+
connected `.tab-mcp-success`, with `.tab-mcp-success-icon` (the check mark, an inline
|
|
444
|
+
`svg` in `currentColor`), `.tab-mcp-success-title` and `.tab-mcp-success-next`, and the
|
|
445
|
+
button `.tab-mcp-setup-toggle`, "Connect another app", with `aria-expanded`, which shows
|
|
446
|
+
and hides `.tab-mcp-setup`, the address, code and help), the confirmation is
|
|
394
447
|
`.tab-mcp-confirm` (with `.tab-mcp-description`, `.tab-mcp-arguments`,
|
|
395
448
|
`.tab-mcp-always-note`, and the buttons `.tab-mcp-deny`, `.tab-mcp-allow`,
|
|
396
449
|
`.tab-mcp-always`, with `alwaysAllow`), and the notice after `replaced` is
|
|
397
450
|
`.tab-mcp-replaced` (with `.tab-mcp-description`, `.tab-mcp-status`, and the buttons
|
|
398
451
|
`.tab-mcp-replaced-close` and `.tab-mcp-new-address`). Buttons are `.tab-mcp-primary` (the one
|
|
399
|
-
next step: Copy the address, Done, "Don't allow", the safe choice, and the notice's "New
|
|
452
|
+
next step: Copy the address until an app is connected, then Done, "Don't allow", the safe choice, and the notice's "New
|
|
400
453
|
address", or its "Close" after a sibling tab), `.tab-mcp-danger` (Disconnect and
|
|
401
454
|
"Disconnect and get new address") or plain; every Copy button is also `.tab-mcp-copy`, and
|
|
402
455
|
the Disconnect buttons in the apps list are `.tab-mcp-disconnect`. For example:
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -5,7 +5,7 @@ bundler build (index.js and its chunks) does not include it; it is installed
|
|
|
5
5
|
as a dependency instead.
|
|
6
6
|
|
|
7
7
|
------------------------------------------------------------------------------
|
|
8
|
-
@cfworker/json-schema 4.1.
|
|
8
|
+
@cfworker/json-schema 4.1.6
|
|
9
9
|
https://github.com/cfworker/cfworker
|
|
10
10
|
------------------------------------------------------------------------------
|
|
11
11
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var mt=/^(?:\d{1,4}x\d{1,4}|any)$/;function yt(e){let{src:t,mimeType:n,sizes:s,theme:i}=e;if(typeof t!=="string")return;let d=/^https?:/i.test(t)&&t.length<=2048,r=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!d&&!r)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let b=Array.isArray(s)?s.map((E)=>String(E).toLowerCase()).filter((E)=>mt.test(E)):[];if(b.length>0)a.sizes=b;if(i==="light"||i==="dark")a.theme=i;return a}function Te(e){let t=[];for(let n of e){let s=typeof n==="object"&&n!==null?yt(n):void 0;if(s!==void 0)t.push(s);if(t.length===8)break}return t}function qe(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return Te([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let s={src:n.href};if(n.type)s.mimeType=n.type;let i=n.getAttribute("sizes");if(i)s.sizes=i.trim().split(/\s+/);let d=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(d)s.theme=d[1]?.toLowerCase();return s}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let s=Array.isArray(e),i=Array.isArray(t);if(s!==i)return!1;if(s){let d=e.length;if(d!==t.length)return!1;for(let r=0;r<d;r++)if(!ue(e[r],t[r]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let d=Object.keys(e),r=Object.keys(t);if(d.length!==r.length)return!1;for(let b of d){if(!Object.prototype.hasOwnProperty.call(t,b))return!1;if(!ue(e[b],t[b]))return!1}return!0}return e===t}function D(e){return encodeURI(gt(e)).replace(/#/g,"%23")}function gt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var ht=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,$t=/^%[0-9A-Fa-f]{2}$/,bt=/^[A-Za-z0-9._~-]$/;function wt(e){let t="";for(let n=0;n<e.length;){let s=e[n],i=e.slice(n,n+3);if(s==="%"&&$t.test(i)){let r=String.fromCharCode(parseInt(i.slice(1),16));t+=bt.test(r)?r:i.toUpperCase(),n+=3;continue}let d=String.fromCodePoint(e.codePointAt(n));t+=ht.test(d)?d:encodeURIComponent(d),n+=d.length}return t}function be(e,t){let n=new URL(e,t.href);return n.hash=n.hash?wt(n.hash.slice(1)):"",n}var xt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},It={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Rt={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!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},kt=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=kt,s=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let d=e.$id||e.id;if(d){let r=be(d,n);if(r.hash.length>1)t[r.href]=e;else if(r.hash="",s==="")n=r;else ee(e,t,n)}}else if(e!==!0&&e!==!1)return t;let i=n.href+(s?"#"+s:"");if(t[i]!==void 0&&t[i]!==e)throw Error(`Duplicate schema URI "${i}".`);if(t[i]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:i});if(e.$ref&&e.__absolute_ref__===void 0){let d=be(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:d.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let d=be(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:d.href})}if(e.$anchor){let d=be("#"+e.$anchor,n);t[d.href]=e}for(let d in e){if(Rt[d])continue;let r=`${s}/${D(d)}`,a=e[d];if(Array.isArray(a)){if(xt[d]){let b=a.length;for(let E=0;E<b;E++)ee(a[E],t,n,`${r}/${E}`)}}else if(It[d])for(let b in a)ee(a[b],t,n,`${r}/${D(b)}`);else ee(a,t,n,r)}return t}var _t=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Tt=[0,31,28,31,30,31,30,31,31,30,31,30,31],St=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,ze=/^(?=.{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,vt=/^(?:[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\x7f"<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Ot=/^(?:(?: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,Et=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,At=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Pt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Ct=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Nt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,jt=(e)=>{let t=e.match(Nt);if(!t)return!1;let n=t[1],s=t[2];if(!n||!s||n.length>64||s.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(s.startsWith("[")&&s.endsWith("]")){let i=s.slice(1,-1);if(/^ipv6:/i.test(i))return Je.test(i.slice(5));return He.test(i)}return ze.test(s)},He=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Je=/^((([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,qt=(e)=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e);function K(e){return e.test.bind(e)}var Se={date:Ue,time:Be.bind(void 0,!0),"date-time":Jt,duration:qt,uri:Dt,"uri-reference":K(vt),"uri-template":K(Mt),url:K(Ot),email:jt,hostname:K(ze),ipv4:K(He),ipv6:K(Je),regex:Gt,uuid:K(Et),"json-pointer":K(At),"json-pointer-uri-fragment":K(Pt),"relative-json-pointer":K(Ct)};function zt(e){return e%4===0&&(e%100!==0||e%400===0)}function Ue(e){let t=e.match(_t);if(!t)return!1;let n=t[1],s=t[2],i=t[3];if(!n||!s||!i)return!1;let d=+n,r=+s,a=+i,b=r==2&&zt(d)?29:Tt[r];return r>=1&&r<=12&&a>=1&&b!==void 0&&a<=b}function Be(e,t){let n=t.match(St);if(!n)return!1;let s=n[1],i=n[2],d=n[3];if(!s||!i||!d)return!1;let r=+s,a=+i,b=+d,E=n[5],T=n[6],H=+(n[7]??0),B=+(n[8]??0);if(r>23||a>59||b>60||H>23||B>59||e&&E===void 0)return!1;if(b<60)return!0;let V=T==="+"?1:T==="-"?-1:0;return(r*60+a-V*(H*60+B)+1440)%1440===1439}var Ht=/t|\s/i;function Jt(e){let[t,n,s]=e.split(Ht);return t!==void 0&&n!==void 0&&s===void 0&&Ue(t)&&Be(!0,n)}var Ut=/\/|:/,Bt=/^(?:[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 Dt(e){return Ut.test(e)&&Bt.test(e)}var Vt=/[^\\]\\Z/;function Gt(e){if(Vt.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function De(e){let t=0,n=e.length,s=0,i;while(s<n)if(t++,i=e.charCodeAt(s++),i>=55296&&i<=56319&&s<n){if(i=e.charCodeAt(s),(i&64512)==56320)s++}return t}function se(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ve(e){let t=Math.abs(e).toString().split("e"),n=t[0],s=t[1]??"0",i=n.indexOf("."),d=i===-1?0:n.length-i-1;return[BigInt(n.replace(".","")),Number(s)-d]}function Wt(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,s]=Ve(e),[i,d]=Ve(t),r=s-d;if(r>=0)return n*10n**BigInt(r)%i===0n;return n%(i*10n**BigInt(-r))===0n}function O(e,t,n="2019-09",s=ee(t),i=!0,d=null,r="#",a="#",b=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:r,keyword:"false",keywordLocation:r,error:"False boolean schema."}]};let E=typeof e,T;switch(E){case"boolean":case"number":case"string":T=E;break;case"object":if(e===null)T="null";else if(Array.isArray(e))T="array";else T="object";break;default:throw Error(`Instances of "${E}" type are not supported.`)}let{$ref:H,$recursiveRef:B,$recursiveAnchor:V,type:C,const:G,enum:W,required:Q,not:L,anyOf:A,allOf:l,oneOf:g,if:I,then:_,else:y,format:o,properties:w,patternProperties:p,additionalProperties:v,unevaluatedProperties:S,minProperties:N,maxProperties:P,propertyNames:F,dependentRequired:J,dependentSchemas:q,dependencies:U,prefixItems:ce,items:ne,additionalItems:Ee,unevaluatedItems:Ae,contains:Pe,minContains:Z,maxContains:Ie,minItems:Re,maxItems:ke,uniqueItems:ct,minimum:re,maximum:oe,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:_e,minLength:ye,maxLength:ge,pattern:Ce,__absolute_ref__:he,__absolute_recursive_ref__:pt}=t,f=[];if(V===!0&&d===null)d=t;if(B==="#"){let R=d===null?s[pt]:d,m=`${a}/$recursiveRef`,k=O(e,d===null?t:d,n,s,i,R,r,m,b);if(!k.valid)f.push({instanceLocation:r,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...k.errors)}if(H!==void 0){let m=s[he||H];if(m===void 0){let u=`Unresolved $ref "${H}".`;if(he&&he!==H)u+=` Absolute URI "${he}".`;throw u+=`
|
|
2
|
+
Known schemas:
|
|
3
|
+
- ${Object.keys(s).join(`
|
|
4
|
+
- `)}`,Error(u)}let k=`${a}/$ref`,c=O(e,m,n,s,i,d,r,k,b);if(!c.valid)f.push({instanceLocation:r,keyword:"$ref",keywordLocation:k,error:"A subschema had errors."},...c.errors);if(n==="4"||n==="7")return{valid:f.length===0,errors:f}}if(Array.isArray(C)){let R=C.length,m=!1;for(let k=0;k<R;k++)if(T===C[k]||C[k]==="integer"&&T==="number"&&e%1===0&&e===e){m=!0;break}if(!m)f.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${T}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(T!=="number"||e%1||e!==e)f.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${T}" is invalid. Expected "${C}".`})}else if(C!==void 0&&T!==C)f.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${T}" is invalid. Expected "${C}".`});if(G!==void 0){if(T==="object"||T==="array"){if(!ue(e,G))f.push({instanceLocation:r,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}else if(e!==G)f.push({instanceLocation:r,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}if(W!==void 0){if(T==="object"||T==="array"){if(!W.some((R)=>ue(e,R)))f.push({instanceLocation:r,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(W)}.`})}else if(!W.some((R)=>e===R))f.push({instanceLocation:r,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(W)}.`})}if(L!==void 0){let R=`${a}/not`;if(O(e,L,n,s,i,d,r,R).valid)f.push({instanceLocation:r,keyword:"not",keywordLocation:R,error:'Instance matched "not" schema.'})}let $e=[];if(A!==void 0){let R=`${a}/anyOf`,m=f.length,k=!1;for(let[c,u]of A.entries()){let x=Object.create(b),h=O(e,u,n,s,i,V===!0?d:null,r,`${R}/${c}`,x);if(f.push(...h.errors),k=k||h.valid,h.valid)$e.push(x)}if(k)f.length=m;else f.splice(m,0,{instanceLocation:r,keyword:"anyOf",keywordLocation:R,error:"Instance does not match any subschemas."})}if(l!==void 0){let R=`${a}/allOf`,m=f.length,k=!0;for(let[c,u]of l.entries()){let x=Object.create(b),h=O(e,u,n,s,i,V===!0?d:null,r,`${R}/${c}`,x);if(f.push(...h.errors),k=k&&h.valid,h.valid)$e.push(x)}if(k)f.length=m;else f.splice(m,0,{instanceLocation:r,keyword:"allOf",keywordLocation:R,error:"Instance does not match every subschema."})}if(g!==void 0){let R=`${a}/oneOf`,m=f.length,k=g.filter((c,u)=>{let x=Object.create(b),h=O(e,c,n,s,i,V===!0?d:null,r,`${R}/${u}`,x);if(f.push(...h.errors),h.valid)$e.push(x);return h.valid}).length;if(k===1)f.length=m;else f.splice(m,0,{instanceLocation:r,keyword:"oneOf",keywordLocation:R,error:`Instance does not match exactly one subschema (${k} matches).`})}if(T==="object"||T==="array")Object.assign(b,...$e);if(I!==void 0){let R=`${a}/if`,m=Object.create(null);if(O(e,I,n,s,i,d,r,R,m).valid){if(Object.assign(b,m),_!==void 0){let c=O(e,_,n,s,i,d,r,`${a}/then`,b);if(!c.valid)f.push({instanceLocation:r,keyword:"if",keywordLocation:R,error:'Instance does not match "then" schema.'},...c.errors)}}else if(y!==void 0){let c=O(e,y,n,s,i,d,r,`${a}/else`,b);if(!c.valid)f.push({instanceLocation:r,keyword:"if",keywordLocation:R,error:'Instance does not match "else" schema.'},...c.errors)}}if(T==="object"){if(Q!==void 0){for(let c of Q)if(!se(e,c))f.push({instanceLocation:r,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${c}".`})}let R=Object.keys(e);if(N!==void 0&&R.length<N)f.push({instanceLocation:r,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${N} properties.`});if(P!==void 0&&R.length>P)f.push({instanceLocation:r,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${P} properties.`});if(F!==void 0){let c=`${a}/propertyNames`;for(let u in e){let x=`${r}/${D(u)}`,h=O(u,F,n,s,i,d,x,c);if(!h.valid)f.push({instanceLocation:r,keyword:"propertyNames",keywordLocation:c,error:`Property name "${u}" does not match schema.`},...h.errors)}}if(J!==void 0){let c=`${a}/dependantRequired`;for(let u in J)if(se(e,u)){let x=J[u];for(let h of x)if(!se(e,h))f.push({instanceLocation:r,keyword:"dependentRequired",keywordLocation:c,error:`Instance has "${u}" but does not have "${h}".`})}}if(q!==void 0)for(let[c,u]of Object.entries(q)){let x=`${a}/dependentSchemas`;if(se(e,c)){let h=O(e,u,n,s,i,d,r,`${x}/${D(c)}`,b);if(!h.valid)f.push({instanceLocation:r,keyword:"dependentSchemas",keywordLocation:x,error:`Instance has "${c}" but does not match dependant schema.`},...h.errors)}}if(U!==void 0){let c=`${a}/dependencies`;for(let u in U)if(se(e,u)){let x=U[u];if(Array.isArray(x)){for(let h of x)if(!se(e,h))f.push({instanceLocation:r,keyword:"dependencies",keywordLocation:c,error:`Instance has "${u}" but does not have "${h}".`})}else{let h=O(e,x,n,s,i,d,r,`${c}/${D(u)}`);if(!h.valid)f.push({instanceLocation:r,keyword:"dependencies",keywordLocation:c,error:`Instance has "${u}" but does not match dependant schema.`},...h.errors)}}}let m=Object.create(null),k=!1;if(w!==void 0){let c=`${a}/properties`;for(let[u,x]of Object.entries(w)){if(!se(e,u))continue;let h=`${r}/${D(u)}`,j=O(e[u],x,n,s,i,d,h,`${c}/${D(u)}`);if(m[u]=!0,j.valid)b[u]=!0;else if(k=i,f.push({instanceLocation:r,keyword:"properties",keywordLocation:c,error:`Property "${u}" does not match schema.`},...j.errors),k)break}}if(!k&&p!==void 0){let c=`${a}/patternProperties`;for(let[u,x]of Object.entries(p)){let h=new RegExp(u,"u");for(let j in e){if(!h.test(j))continue;let Ne=`${r}/${D(j)}`,je=O(e[j],x,n,s,i,d,Ne,`${c}/${D(u)}`);if(m[j]=!0,je.valid)b[j]=!0;else k=i,f.push({instanceLocation:r,keyword:"patternProperties",keywordLocation:c,error:`Property "${j}" matches pattern "${u}" but does not match associated schema.`},...je.errors)}}}if(!k&&v!==void 0){let c=`${a}/additionalProperties`;for(let u in e){if(m[u])continue;let x=`${r}/${D(u)}`,h=O(e[u],v,n,s,i,d,x,c);if(h.valid)b[u]=!0;else k=i,f.push({instanceLocation:r,keyword:"additionalProperties",keywordLocation:c,error:`Property "${u}" does not match additional properties schema.`},...h.errors)}}else if(!k&&S!==void 0){let c=`${a}/unevaluatedProperties`;for(let u in e)if(!b[u]){let x=`${r}/${D(u)}`,h=O(e[u],S,n,s,i,d,x,c);if(h.valid)b[u]=!0;else f.push({instanceLocation:r,keyword:"unevaluatedProperties",keywordLocation:c,error:`Property "${u}" does not match unevaluated properties schema.`},...h.errors)}}}else if(T==="array"){if(ke!==void 0&&e.length>ke)f.push({instanceLocation:r,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${ke}).`});if(Re!==void 0&&e.length<Re)f.push({instanceLocation:r,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${Re}).`});let R=e.length,m=0,k=!1;if(ce!==void 0){let c=`${a}/prefixItems`,u=Math.min(ce.length,R);for(;m<u;m++){let x=O(e[m],ce[m],n,s,i,d,`${r}/${m}`,`${c}/${m}`);if(b[m]=!0,!x.valid){if(k=i,f.push({instanceLocation:r,keyword:"prefixItems",keywordLocation:c,error:"Items did not match schema."},...x.errors),k)break}}}if(ne!==void 0){let c=`${a}/items`;if(Array.isArray(ne)){let u=Math.min(ne.length,R);for(;m<u;m++){let x=O(e[m],ne[m],n,s,i,d,`${r}/${m}`,`${c}/${m}`);if(b[m]=!0,!x.valid){if(k=i,f.push({instanceLocation:r,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...x.errors),k)break}}}else for(;m<R;m++){let u=O(e[m],ne,n,s,i,d,`${r}/${m}`,c);if(b[m]=!0,!u.valid){if(k=i,f.push({instanceLocation:r,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...u.errors),k)break}}if(!k&&Ee!==void 0){let u=`${a}/additionalItems`;for(;m<R;m++){let x=O(e[m],Ee,n,s,i,d,`${r}/${m}`,u);if(b[m]=!0,!x.valid)k=i,f.push({instanceLocation:r,keyword:"additionalItems",keywordLocation:u,error:"Items did not match additional items schema."},...x.errors)}}}if(Pe!==void 0)if(R===0&&Z===void 0)f.push({instanceLocation:r,keyword:"contains",keywordLocation:`${a}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(Z!==void 0&&R<Z)f.push({instanceLocation:r,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${R}) than minContains (${Z}).`});else{let c=`${a}/contains`,u=f.length,x=0;for(let h=0;h<R;h++){let j=O(e[h],Pe,n,s,i,d,`${r}/${h}`,c);if(j.valid)b[h]=!0,x++;else f.push(...j.errors)}if(x>=(Z||0))f.length=u;if(Z===void 0&&x===0)f.splice(u,0,{instanceLocation:r,keyword:"contains",keywordLocation:c,error:"Array does not contain item matching schema."});else if(Z!==void 0&&x<Z)f.push({instanceLocation:r,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${Z} items matching schema. Only ${x} items were found.`});else if(Ie!==void 0&&x>Ie)f.push({instanceLocation:r,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Ie} items matching schema. ${x} items were found.`})}if(!k&&Ae!==void 0){let c=`${a}/unevaluatedItems`;for(m;m<R;m++){if(b[m])continue;let u=O(e[m],Ae,n,s,i,d,`${r}/${m}`,c);if(b[m]=!0,!u.valid)f.push({instanceLocation:r,keyword:"unevaluatedItems",keywordLocation:c,error:"Items did not match unevaluated items schema."},...u.errors)}}if(ct)for(let c=0;c<R;c++){let u=e[c],x=typeof u==="object"&&u!==null;for(let h=0;h<R;h++){if(c===h)continue;let j=e[h];if(u===j||x&&(typeof j==="object"&&j!==null)&&ue(u,j))f.push({instanceLocation:r,keyword:"uniqueItems",keywordLocation:`${a}/uniqueItems`,error:`Duplicate items at indexes ${c} and ${h}.`}),c=Number.MAX_SAFE_INTEGER,h=Number.MAX_SAFE_INTEGER}}}else if(T==="number"){if(n==="4"){if(re!==void 0&&(pe===!0&&e<=re||e<re))f.push({instanceLocation:r,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${re}.`});if(oe!==void 0&&(me===!0&&e>=oe||e>oe))f.push({instanceLocation:r,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${oe}.`})}else{if(re!==void 0&&e<re)f.push({instanceLocation:r,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${re}.`});if(oe!==void 0&&e>oe)f.push({instanceLocation:r,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${oe}.`});if(pe!==void 0&&e<=pe)f.push({instanceLocation:r,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)f.push({instanceLocation:r,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(_e!==void 0){if(!Wt(e,_e))f.push({instanceLocation:r,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${_e}.`})}}else if(T==="string"){let R=ye===void 0&&ge===void 0?0:De(e);if(ye!==void 0&&R<ye)f.push({instanceLocation:r,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${R} < ${ye}).`});if(ge!==void 0&&R>ge)f.push({instanceLocation:r,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${R} > ${ge}).`});if(Ce!==void 0&&!new RegExp(Ce,"u").test(e))f.push({instanceLocation:r,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(o!==void 0&&Se[o]&&!Se[o](e))f.push({instanceLocation:r,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${o}".`})}return{valid:f.length===0,errors:f}}var We="ch.ractive.tab-mcp/annotations",Ft=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Kt=["destructiveHint","idempotentHint","openWorldHint"];function Fe(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 i of Kt){let d=e[i];if(d!==void 0)t[i]=d}let n={};for(let i of Ft){let d=e[i];if(d!==void 0)n[i]=d}let s={};if(Object.keys(t).length>0)s.annotations=t;if(Object.keys(n).length>0)s.meta=n;return s}function X(e){return{content:[{type:"text",text:e}],isError:!0}}function Ge(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ke(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(Ge(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(Ge(e))n.structuredContent=e;return n}function Ye(e){let t=e instanceof Error?e.message:String(e);return X(t||"The tool failed.")}var ie="2026-07-28",te="io.modelcontextprotocol/protocolVersion",we="io.modelcontextprotocol/clientCapabilities",Ze="io.modelcontextprotocol/clientInfo",Xe="io.modelcontextprotocol/serverInfo",ve="io.modelcontextprotocol/subscriptionId",Yt=-32020,Qe=-32022,Zt=0,Le=new WeakMap;function Me(e){let t=Le.get(e);if(t!==void 0)return t;let n=e.inputSchema,s;try{s=ee(n)}catch(d){let r=d instanceof Error?d.message:String(d);throw Error(r.split(`
|
|
5
|
+
`)[0])}for(let d of Object.values(s)){if(typeof d!=="object"||d.$ref===void 0)continue;let r=d.__absolute_ref__;if(s[r??d.$ref]===void 0)throw Error(`$ref ${JSON.stringify(d.$ref)} does not resolve`)}let i=(d)=>O(d,n,"2020-12",s,!1);return Le.set(e,i),i}function et(e,t,n=""){let s=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${s}${n}`)}function Xt(e){let t=[];for(let n of e.list())try{Me(n)}catch(s){e.remove(n),t.push(et(n.name,s,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Me(n)}catch(s){throw et(n.name,s)}}),t}function tt(e){try{return structuredClone(e)}catch{return e}}var Qt=new TextEncoder;function de(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Oe(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function z(e,t,n,s,i){let d={code:n,message:s};if(i!==void 0)d.data=i;return Oe(e,{jsonrpc:"2.0",id:t,error:d})}function Y(e,t,n){return z(400,e,Yt,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function le(e){return Qt.encode(`event: message
|
|
6
|
+
data: ${JSON.stringify(e)}
|
|
7
|
+
|
|
8
|
+
`)}var nt={"content-type":"text/event-stream","cache-control":"no-cache"};function Lt(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function en(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),s=Uint8Array.from(n,(i)=>i.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(s)}catch{return}}function tn(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(!de(e[we]))return{key:we,problem:"expected an object"};let t=e[Ze];if(t!==void 0&&!(de(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ze,problem:"expected {name, version}"};return}function nn(e){let t=e.notifications;return de(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function rt(e){let{tools:t,server:n}=e,s={name:n.name,version:n.version};if(n.title!==void 0)s.title=n.title;let i=Te(n.icons??[]),d=i.length>0?{...s,icons:i}:s,r=new Set,a=!1,b=(l={})=>({...l,[Xe]:s});function E(l,g,I=b()){return{jsonrpc:"2.0",id:l,result:{...g,resultType:"complete",_meta:I}}}function T(l,g){let I;try{I=Me(l)(g)}catch(y){let o=y instanceof Error?y.message:String(y);return`The input schema of tool ${l.name} cannot be used: ${o}`}if(I.valid)return;let _=I.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 ${l.name}: ${_||"the arguments do not match the schema"}`}function H(){return t.list().map((l)=>{let g={name:l.name};if(l.title!==void 0)g.title=l.title;g.description=l.description,g.inputSchema=l.inputSchema;let{annotations:I,meta:_}=Fe(l.annotations);if(I!==void 0)g.annotations=I;if(_!==void 0)g._meta={[We]:_};return g})}let B=(l)=>({kind:"invalid",message:l});async function V(l,g,I){let _=l.name;if(typeof _!=="string")return B("Invalid params: name must be a string");let y=t.get(_);if(y===void 0)return B(`Tool ${_} not found`);let o=l.arguments??{};if(!de(o))return B("Invalid params: arguments must be an object");let w=e.client(I),p={id:++Zt,tool:y.name,arguments:tt(o),client:{...w}};if(y.title!==void 0)p.title=y.title;let v=Date.now();e.observe?.start(p);let S="error",N=X("Internal error");try{[S,N]=await C(y,o,g,w)}finally{e.observe?.end({id:p.id,tool:y.name,client:{...w},outcome:S,result:tt(N),durationMs:Date.now()-v})}return{kind:"result",result:N}}async function C(l,g,I,_){let y=T(l,g);if(y!==void 0)return["error",X(y)];if(l.annotations.consequentialHint===!0){let w={tool:{name:l.name,description:l.description},arguments:g,client:_,signal:I};if(l.title!==void 0)w.tool.title=l.title;let p=!1;try{p=await e.confirm(w)}catch{p=!1}if(!p)return[I.aborted?"cancelled":"declined",X("The user declined")]}if(I.aborted)return["cancelled",X("Cancelled")];if(t.get(l.name)!==l)return["error",X("The tool is no longer available")];let o;try{o=Ke(await l.execute(g,{signal:I,client:_}))}catch(w){o=Ye(w)}if(I.aborted)return["cancelled",o];return[o.isError===!0?"error":"ok",o]}function G(l,g,I,_){let y=new ReadableStream({start:(o)=>{let w=(p)=>{if(I.aborted)return;let v;try{v=le(p)}catch{v=le(E(l,X("The tool returned a result that is not JSON.")))}try{o.enqueue(v),o.close()}catch{}};V(g,I,_).then((p)=>w(p.kind==="invalid"?{jsonrpc:"2.0",id:l,error:{code:-32602,message:p.message}}:E(l,p.result)),()=>w({jsonrpc:"2.0",id:l,error:{code:-32603,message:"Internal error"}}))}});return new Response(y,{status:200,headers:nt})}function W(l,g,I){let _=nn(g),y={jsonrpc:"2.0",id:l,result:{resultType:"complete",_meta:b({[ve]:l})}},o,w=new ReadableStream({start:(p)=>{if(p.enqueue(le({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:_,_meta:{[ve]:l}}})),Object.keys(_).length===0){p.enqueue(le(y)),p.close();return}let v={id:l,send:(S)=>{try{p.enqueue(le(S))}catch{r.delete(v)}},end:()=>{r.delete(v);try{p.enqueue(le(y)),p.close()}catch{}}};o=v,r.add(v),I.addEventListener("abort",()=>{r.delete(v);try{p.close()}catch{}})},cancel:()=>{if(o!==void 0)r.delete(o)}});return new Response(w,{status:200,headers:nt})}function Q(l,g){if(Array.isArray(g))return z(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!de(g)||g.jsonrpc!=="2.0")return z(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:I,id:_}=g;if(typeof I!=="string")return"result"in g||"error"in g?z(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):z(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let y=l.headers.get("mcp-protocol-version"),o=l.headers.get("mcp-method"),w=de(g.params)?g.params:{},p=de(w._meta)?w._meta:void 0,v=p!==void 0&&te in p,S=typeof p?.[te]==="string"?p[te]:void 0,N=y!==null&&y>=ie;if(_===void 0){if(S!==void 0&&y!==null&&y!==S)return Y(null,y,`the notification envelope names protocol version ${S} but the MCP-Protocol-Version header names ${y}`);if((v||N)&&o!==null&&o!==I)return Y(null,o,`the notification body names method ${I} but the Mcp-Method header names ${o}`);return"notification"}if(typeof _!=="string"&&typeof _!=="number")return z(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let P=_;if(!v||I==="initialize"&&(S===void 0||S<ie)){if(I==="initialize"){if(N)return Y(P,y,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let J=typeof w.protocolVersion==="string"?w.protocolVersion:void 0;return L(P,J)}if(N){let J=p===void 0?["_meta"]:[te];return z(400,P,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${y}, but the request is missing the required per-request envelope key(s): ${J.join(", ")}`,{envelope:{missing:J}})}return L(P,y??void 0)}let F=tn(p);if(F!==void 0)return z(400,P,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${F.key}: ${F.problem}`,{envelope:F});if(y!==null&&S!==void 0&&y!==S)return Y(P,y,`the body envelope names protocol version ${S} but the MCP-Protocol-Version header names ${y}`);if(o!==null&&o!==I)return Y(P,o,`the body names method ${I} but the Mcp-Method header names ${o}`);if(S!==ie)return L(P,S);if(y===null)return Y(P,"(missing)",`the body envelope names protocol version ${S} but the required MCP-Protocol-Version header is absent`);if(o===null)return Y(P,"(missing)",`the body names method ${I} but the required Mcp-Method header is absent`);if(I==="tools/call"&&typeof w.name==="string"){let J=w.name,q=l.headers.get("mcp-name");if(q===null)return Y(P,"(missing)",`the body carries params.name="${J}" but the required Mcp-Name header is absent`);let U=en(q);if(U===void 0)return Y(P,q,"the Mcp-Name header carries an invalid Base64 sentinel value");if(U!==J)return Y(P,q,`the body carries params.name="${J}" but the Mcp-Name header names "${U}"`)}return{id:P,method:I,params:w}}function L(l,g){return g===void 0?z(400,l,Qe,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):z(400,l,Qe,`Unsupported protocol version: ${g}`,{supported:[ie],requested:g})}async function A(l,g){if(l.method.toUpperCase()!=="POST")return z(405,null,-32000,"Method not allowed.");if(!Lt(l.headers.get("content-type")))return z(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let I;try{I=JSON.parse(g.body??await l.text())}catch{return z(400,null,-32700,"Parse error: the request body is not valid JSON")}let _=Q(l,I);if(_ instanceof Response)return _;if(_==="notification")return new Response(null,{status:202});let{id:y,method:o,params:w}=_;switch(o){case"server/discover":{let p={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)p.instructions=n.instructions;return p.ttlMs=0,p.cacheScope="private",Oe(200,E(y,p,{[Xe]:d}))}case"tools/list":return Oe(200,E(y,{tools:H(),ttlMs:0,cacheScope:"private"}));case"tools/call":return G(y,w,l.signal,g.grant);case"subscriptions/listen":return W(y,w,l.signal);default:return z(404,y,-32601,"Method not found")}}return{handle:(l,g)=>A(l,g).catch(()=>z(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let l of[...r])l.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[ve]:l.id}}})})},close(){for(let l of[...r])l.end()}}}var xe="tab-mcp.v1",rn=new Set(["start","used","locked","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var M=(e)=>typeof e==="string";function ot(e){if(!fe(e)||!M(e.grantId)||!M(e.createdAt))return!1;let t=e.client;return fe(t)&&M(t.id)&&M(t.name)&&M(t.host)}function on(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function sn(e){return fe(e)&&Object.values(e).every(M)}function st(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return M(t.sessionId)&&M(t.address)&&M(t.origin)&&M(t.expiresAt)&&on(t.limits)&&Array.isArray(t.grants)&&t.grants.every(ot)&&(t.appName===void 0||M(t.appName))&&(t.pairing===void 0||M(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:M(t.reason)?t.reason:""};case"http.request":return M(t.id)&&M(t.method)&&M(t.path)&&sn(t.headers)&&M(t.body)&&fe(t.grant)&&M(t.grant.grantId)&&M(t.grant.clientId)?t:void 0;case"http.cancel":return M(t.id)?t:void 0;case"pairing.code":{if(!M(t.code)||!M(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},s=t.reason;if(typeof s==="string"&&rn.has(s))n.reason=s;return n}case"grant.added":return ot(t.grant)?t:void 0;case"grant.removed":return M(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:M(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 M(t.code)?t:void 0;default:return}}function dn(e){let t="",n=0,s=0;for(let i of e){n=n<<8|i,s+=8;while(s>=5)s-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>s&31];n&=(1<<s)-1}if(s>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-s&31];return t}async function an(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return dn(new Uint8Array(n))}catch{return}}function un(e,t){if(t===void 0)return e;let n=new URL(e);return n.searchParams.set("a",t),n.href}var ln=15000,it={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited",4009:"policy"},dt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function ae(e,t){return Object.assign(Error(e),{reason:t})}var fn=["content-type","cache-control"];function cn(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function pn(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 mn=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),ut=512,lt=6,ft=64,yn=ut+lt*ft;function gn(e){let t=Math.floor((e-ut)/lt);return t>=ft?t:void 0}function*at(e,t){let n=0;while(n<e.length){let s=Math.min(n+t,e.length),i=e.charCodeAt(s-1);if(s<e.length&&i>=55296&&i<=56319)s+=s-1>n?-1:1;yield e.slice(n,s),n=s}}var hn=1e4,$n=1000;function bn(e){let t,n=Number.NEGATIVE_INFINITY,s;try{if(e!==void 0&&typeof BroadcastChannel==="function")t=new BroadcastChannel(e),t.onmessage=(i)=>{if(i.data?.type!=="claimed")return;n=Date.now(),s?.()}}catch{t=void 0}return{claimed(){try{t?.postMessage({type:"claimed"})}catch{}},heard(){if(Date.now()-n<=hn)return Promise.resolve(!0);if(t===void 0)return Promise.resolve(!1);return new Promise((i)=>{let d=setTimeout(()=>i(!1),$n);s=()=>{clearTimeout(d),i(!0)}})},close(){t?.close()}}}function Dn(e,t,n,s=!1){let i=new WebSocket(t,xe),d=new Map,r="opening",a,b=65536,E,T=0,H=bn(e.tabs),B,V,C,G=new Promise((o,w)=>{V=o,C=w});G.catch(()=>{});let W=setTimeout(()=>{g(ae("The relay did not answer in time.","network"))},ln),Q=rt({tools:e.registry,server:{...e.server,icons:e.server.icons??qe()},confirm:(o)=>e.confirm(o),client:(o)=>e.clientFor(o),observe:{start:(o)=>e.toolCallStarted(o),end:(o)=>e.toolCallEnded(o)}}),L=e.registry.onChange(()=>Q.toolsChanged());function A(o){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(o)),!0}catch{return!1}}function l(){if(T<=0)return;clearTimeout(E),E=setTimeout(()=>{a??="heartbeat",I(4003);try{i.close()}catch{}},T*2.5)}function g(o){if(r!=="opening")return;I(0),C(o);try{i.close()}catch{}}function I(o){if(r==="closed")return;let w=r==="ready";r="closed",clearTimeout(W),clearTimeout(E),L();for(let p of d.values())p.abort();if(d.clear(),Q.close(),w){let p=a??it[o]??(o===1006?"network":"closed");if(C(ae("The address was taken over again before its AI apps were disconnected.",p)),e.closed(p,o),p==="replaced"){H.heard().then((v)=>{H.close(),e.replaced({sibling:v})});return}}H.close()}async function _(o){let w=new AbortController;d.set(o.id,w);let p=()=>r==="ready"&&d.get(o.id)===w&&!w.signal.aborted;try{let v=new Request(`https://tab.invalid${o.path}`,{method:o.method,headers:o.headers,signal:w.signal}),S=await Q.handle(v,{grant:o.grant,body:o.body});if(!p()){await S.body?.cancel().catch(()=>{});return}let N={};for(let q of fn){let U=S.headers.get(q);if(U!==null)N[q]=U}if(!(N["content-type"]??"").startsWith("text/event-stream")||S.body===null){let q=await S.text();if(!p())return;if(q.length<=b){A({type:"http.response",id:o.id,status:S.status,headers:N,body:q});return}A({type:"http.response.start",id:o.id,status:S.status,headers:N});for(let U of at(q,b)){if(!p())break;A({type:"http.response.chunk",id:o.id,data:U})}if(p())A({type:"http.response.end",id:o.id});return}A({type:"http.response.start",id:o.id,status:S.status,headers:N});let F=S.body.getReader(),J=new TextDecoder;w.signal.addEventListener("abort",()=>{F.cancel().catch(()=>{})});for(;;){let{done:q,value:U}=await F.read();if(q||!p())break;let ce=J.decode(U,{stream:!0});for(let ne of at(ce,b))A({type:"http.response.chunk",id:o.id,data:ne})}if(p())A({type:"http.response.end",id:o.id})}catch(v){if(p())e.error(v instanceof Error?v:Error(String(v))),A({type:"http.response",id:o.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(o.id)===w)d.delete(o.id)}}function y(o){if(r==="opening"){if(o.type==="session"){let w=gn(o.limits.maxMessageBytes);if(w===void 0){g(ae(`The relay's message limit (${o.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${yn}.`,"policy"));return}b=w,r="ready",clearTimeout(W),T=o.limits.heartbeatMs,l(),H.claimed();let p=e.sessionStarted(o);if(s&&o.grants.length>0){B={left:new Set(o.grants.map((v)=>v.grantId)),session:p},A({type:"grants.revokeAll"});return}V(p)}else if(o.type==="error")g(ae(`The relay refused the connection: ${o.message||o.code}`,o.code==="rate_limited"?"rate_limited":"policy"));else if(o.type==="bye")g(ae(`The relay ended the connection: ${o.reason}`,dt[o.reason]??"closed"));return}if(r!=="ready")return;switch(o.type){case"ping":l(),A({type:"pong",t:o.t});return;case"http.request":_(o);return;case"http.cancel":d.get(o.id)?.abort(),d.delete(o.id);return;case"pairing.code":e.pairingCode(o.reason===void 0?{code:o.code,expiresAt:o.expiresAt}:{code:o.code,expiresAt:o.expiresAt,reason:o.reason});return;case"grant.added":e.grantAdded(o.grant);return;case"grant.removed":if(e.grantRemoved(o.grantId),B?.left.delete(o.grantId),B?.left.size===0)V(B.session);return;case"identity.bound":e.identityResult(!0,o.round);return;case"bye":if(a=dt[o.reason]??"closed",a==="replaced")I(4005);return;case"error":if(o.code==="identity_refused"){e.identityResult(!1,typeof o.round==="number"?o.round:void 0,o.message);return}e.error(Error(`Relay error ${o.code}: ${o.message}`));return;case"session":return}}return i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==xe){g(ae(`The relay speaks ${i.protocol}, not ${xe}.`,"policy"));return}let o={type:"hello",library:e.library,page:{title:cn()},secret:n};if(e.appName!==void 0)o.app={name:e.appName};if(s)o.revokeAll=!0;A(o)}),i.addEventListener("message",(o)=>{if(typeof o.data!=="string")return;let w=st(o.data);if(w!==void 0){if(r==="ready")l();y(w);return}let p=pn(o.data);if(p?.id!==void 0)A(mn.has(p.type)?{type:"error",code:"bad_message",message:`malformed ${p.type}`,id:p.id}:{type:"error",code:"unknown_type",message:`unknown type ${p.type}`,id:p.id})}),i.addEventListener("close",(o)=>{if(r==="opening"){I(o.code);let w=o.code===1006||o.code===1002;C(ae(w?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${o.code}${o.reason?`: ${o.reason}`:""}).`,it[o.code]??(w?"network":"closed")));return}I(o.code)}),{ready:G,send:A,close(o){if(r==="closed")return;if(r==="opening"){g(new DOMException("The connection was cancelled","AbortError"));return}a=o,A({type:"bye",reason:"user"}),I(1000);try{i.close(1000,"bye")}catch{}}}}export{an as addressIdOf,Xt as compileRegistry,Dn as openConnection,un as withAddress};
|
|
9
|
+
|
|
10
|
+
//# debugId=9BC1BF191CDB411864756E2164756E21
|
|
11
|
+
//# sourceMappingURL=connection-gh2ayv77.min.js.map
|