@ractive-ch/tab-mcp-client 0.23.0 → 0.24.0-rc.1
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/CHANGELOG.md +35 -0
- package/README.md +56 -16
- package/cdn/connection-vxpnd3ex.min.js +17 -0
- package/cdn/{connection-m0e4xvcy.min.js.map → connection-vxpnd3ex.min.js.map} +5 -5
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +3 -3
- package/cdn/webmcp-jtsqzqas.min.js +4 -0
- package/cdn/webmcp-jtsqzqas.min.js.map +11 -0
- package/{connection-fnkfrvpc.js → connection-gqec88qp.js} +23 -10
- package/connection-gqec88qp.js.map +16 -0
- package/connection.d.ts +8 -4
- package/extension.d.ts +10 -0
- package/extension.js +3 -1
- package/extension.js.map +3 -3
- package/handshake.d.ts +24 -5
- package/index.js +15 -6
- package/index.js.map +3 -3
- package/mapping.d.ts +10 -1
- package/mcp.d.ts +8 -2
- package/package.json +1 -1
- package/skill/SKILL.md +13 -7
- package/skill/references/react.md +1 -1
- package/types.d.ts +22 -8
- package/{webmcp-wwma7nps.js → webmcp-ctk4bd8c.js} +7 -5
- package/webmcp-ctk4bd8c.js.map +11 -0
- package/webmcp.d.ts +4 -3
- package/cdn/connection-m0e4xvcy.min.js +0 -17
- package/cdn/webmcp-kkrmjqfh.min.js +0 -4
- package/cdn/webmcp-kkrmjqfh.min.js.map +0 -11
- package/connection-fnkfrvpc.js.map +0 -16
- package/webmcp-wwma7nps.js.map +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,40 @@ the Git tag `client-v<version>`. The format follows
|
|
|
6
6
|
[Semantic Versioning](https://semver.org/). The relay has its own
|
|
7
7
|
[changelog](https://github.com/ractive/tab-mcp/blob/main/packages/tab-mcp/CHANGELOG.md).
|
|
8
8
|
|
|
9
|
+
## [0.24.0-rc.1][client-0.24.0-rc.1] - 2026-11-23
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **WebMCP that comes after the page loaded.** A `TabMcp` that found no WebMCP when it
|
|
14
|
+
was made looks again when `document` hears `tab-mcp-webmcp` (`WEBMCP_EVENT`, exported
|
|
15
|
+
from `./extension`), and mirrors its tools if `Document.prototype` has `modelContext`
|
|
16
|
+
then (DEC-223). The tab-mcp browser extension dispatches it when a click on its icon
|
|
17
|
+
gives the tab its own WebMCP, so that a page with the library offers its tools there
|
|
18
|
+
in Chrome without WebMCP and in Firefox, also without access to all sites. Nothing
|
|
19
|
+
changes with `webmcp: false`, or where the tab had WebMCP from the start.
|
|
20
|
+
- **Pictures through the tab-mcp browser extension** (DEC-224). A WebMCP call the
|
|
21
|
+
extension announced with `result: "mcp"` (its vouch, or its new `claim` for a
|
|
22
|
+
read-only tool) resolves with the whole MCP result: `content` with its images,
|
|
23
|
+
`structuredContent` and `isError`, and every failure as an `isError` result with its
|
|
24
|
+
message. The extension passes that on, so an AI app connected through it gets a tool's
|
|
25
|
+
pictures as one connected to the page directly does. Any other WebMCP call, and a
|
|
26
|
+
vouch of an older extension, gets the value as before (an image as a line "[image
|
|
27
|
+
content left out: WebMCP results are text.]"). A tool that returns anything but an
|
|
28
|
+
MCP result is unchanged. A claim names the AI app in `toolcall` (`via`, `name`,
|
|
29
|
+
`host`) but allows nothing: `onConfirm` decides as for any WebMCP call.
|
|
30
|
+
`trustExtension: false` ignores claims as it ignores vouches.
|
|
31
|
+
- **`client.allowed`** on a WebMCP caller the tab-mcp browser extension named (in
|
|
32
|
+
`execute`, `toolcall`, `toolcallend` and `onConfirm`'s request): `true` when the user
|
|
33
|
+
allowed that call in the extension (a vouch), `false` when the extension only claimed
|
|
34
|
+
it (DEC-224).
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- **`client.via` is now also set for a read-only call the extension only claimed**
|
|
39
|
+
(DEC-224): `via: "tab-mcp-extension"` no longer means that the user allowed the call.
|
|
40
|
+
`allowed` says that. A page that skips its own question in `execute` when `via` is
|
|
41
|
+
set must check `allowed: true` instead.
|
|
42
|
+
|
|
9
43
|
## [0.23.0][client-0.23.0] - 2026-11-23
|
|
10
44
|
|
|
11
45
|
### Breaking
|
|
@@ -1209,6 +1243,7 @@ First alpha of the browser library, on the npm dist-tag `alpha`.
|
|
|
1209
1243
|
`<script type="module">` under `@ractive-ch/tab-mcp-client/cdn`.
|
|
1210
1244
|
- The connect dialog shows the pairing code from the relay.
|
|
1211
1245
|
|
|
1246
|
+
[client-0.24.0-rc.1]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.24.0-rc.1
|
|
1212
1247
|
[client-0.23.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.23.0
|
|
1213
1248
|
[client-0.22.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.22.0
|
|
1214
1249
|
[client-0.21.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.21.0
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ How the library, the relay and the tab-mcp browser extension fit together, with
|
|
|
17
17
|
picture:
|
|
18
18
|
[How the parts fit together](https://github.com/ractive/tab-mcp#how-the-parts-fit-together).
|
|
19
19
|
|
|
20
|
-
**Status: 0.
|
|
20
|
+
**Status: 0.24.0-rc.1.** Until 1.0, a new minor version can still change the API. Which AI apps
|
|
21
21
|
work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
|
|
22
22
|
|
|
23
23
|
## With a coding agent
|
|
@@ -76,7 +76,7 @@ Or without a bundler, from a CDN as an ES module:
|
|
|
76
76
|
|
|
77
77
|
```html
|
|
78
78
|
<script type="module">
|
|
79
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
79
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.24.0-rc.1/cdn/tab-mcp-client.min.js";
|
|
80
80
|
</script>
|
|
81
81
|
```
|
|
82
82
|
|
|
@@ -160,8 +160,10 @@ WebMCP draft's `registerTool` (`callers`: [which callers see a tool](#which-call
|
|
|
160
160
|
`id` and `name` the page gave `serve` ([Your own assistant](#your-own-assistant-on-the-page)),
|
|
161
161
|
or `{ kind: "webmcp" }` for a WebMCP caller ([WebMCP](#webmcp): an agent in the
|
|
162
162
|
browser, another extension, or a document of an `exposedTo` origin), of which nothing
|
|
163
|
-
more is known (unless the tab-mcp browser extension
|
|
164
|
-
|
|
163
|
+
more is known (unless the tab-mcp browser extension announced the call, with a vouch
|
|
164
|
+
or a claim: then
|
|
165
|
+
`{ kind: "webmcp", via: "tab-mcp-extension", name, host, allowed }`, `allowed` true
|
|
166
|
+
only when the user allowed that call in the extension, [with the
|
|
165
167
|
extension](#with-the-tab-mcp-browser-extension)). Check `client.kind` before you read `host`. Return a
|
|
166
168
|
string (one text block), an MCP result (passed through with its `_meta`: an object
|
|
167
169
|
whose `content` is an array of MCP content blocks, each with `type` `text`, `image`,
|
|
@@ -225,8 +227,14 @@ Chrome has WebMCP for sites in its
|
|
|
225
227
|
[origin trial](https://developer.chrome.com/blog/ai-webmcp-origin-trial) (Chrome 149 to
|
|
226
228
|
162; a site needs a trial token) and with `chrome://flags/#enable-webmcp-testing`
|
|
227
229
|
([Chrome's WebMCP docs](https://developer.chrome.com/docs/ai/webmcp)). Without either,
|
|
228
|
-
the mirror does nothing
|
|
229
|
-
|
|
230
|
+
the mirror does nothing, unless the tab-mcp browser extension gives the tab WebMCP of
|
|
231
|
+
its own. Each `new TabMcp` looks for WebMCP when it is made, so a trial token that a
|
|
232
|
+
script adds later counts for a `TabMcp` made after it. A `TabMcp` that found none looks
|
|
233
|
+
again when `document` hears the event `tab-mcp-webmcp` (`WEBMCP_EVENT` of
|
|
234
|
+
`@ractive-ch/tab-mcp-client/extension`), and starts its mirror if `Document.prototype`
|
|
235
|
+
has `modelContext` then (from 0.24 on, DEC-223): the tab-mcp browser extension
|
|
236
|
+
dispatches it when it gives the tab its WebMCP after the page loaded, at a click on its
|
|
237
|
+
icon. A page script that installs WebMCP late may dispatch it too.
|
|
230
238
|
|
|
231
239
|
#### Who asks before a tool that asks runs
|
|
232
240
|
|
|
@@ -242,7 +250,7 @@ on the caller (DEC-215):
|
|
|
242
250
|
or the caller itself can.
|
|
243
251
|
|
|
244
252
|
The table has the details. Every WebMCP call that the
|
|
245
|
-
tab-mcp browser extension did not vouch for reaches the page as
|
|
253
|
+
tab-mcp browser extension did not vouch for or claim reaches the page as
|
|
246
254
|
`client: { kind: "webmcp" }`, whoever made it: the page cannot tell the last three rows
|
|
247
255
|
apart.
|
|
248
256
|
|
|
@@ -262,7 +270,10 @@ the calling extension or the other origin's script, which the page does not know
|
|
|
262
270
|
page with a tool that must not run on such a caller's word decides in code or keeps the
|
|
263
271
|
tool away:
|
|
264
272
|
|
|
265
|
-
- **`onConfirm`** gets the call with `request.client.kind === "webmcp"
|
|
273
|
+
- **`onConfirm`** gets the call with `request.client.kind === "webmcp"`: without `via`,
|
|
274
|
+
or, for a call the tab-mcp browser extension only claimed (it ran a tool it takes for
|
|
275
|
+
read-only, nobody asked), with `via`, `name`, `host` and `allowed: false`. A call the
|
|
276
|
+
extension vouched for (`allowed: true`) never reaches it. Decide
|
|
266
277
|
there without showing anything an agent could click: refuse every such call, or apply
|
|
267
278
|
a rule of your own (arguments, the time of day, what the user is signed in as). A
|
|
268
279
|
question of your own in the page is no better than the library's against an agent
|
|
@@ -305,7 +316,14 @@ which ask nothing either.
|
|
|
305
316
|
its text blocks, one per line, each other block (an image, a resource) as a line that
|
|
306
317
|
says it was left out: WebMCP results are text, and an image as base64 inside JSON
|
|
307
318
|
costs the agent tokens for nothing. Nothing (`undefined`), which the browser cannot
|
|
308
|
-
serialize, and an empty MCP result resolve as `"Done."`.
|
|
319
|
+
serialize, and an empty MCP result resolve as `"Done."`. Not so for a call the tab-mcp
|
|
320
|
+
browser extension announced (from the release after 0.23 on, DEC-224): it passes
|
|
321
|
+
results on to an AI app outside the browser, which shows pictures, so such a call
|
|
322
|
+
resolves with the whole MCP result, its `content` with the images, its
|
|
323
|
+
`structuredContent` and its `isError` (not `_meta`), and every failure below as an
|
|
324
|
+
`isError` result with the message ([with the
|
|
325
|
+
extension](#with-the-tab-mcp-browser-extension)). A tool that returns anything else
|
|
326
|
+
resolves for it as for any caller.
|
|
309
327
|
- A failure resolves too, as
|
|
310
328
|
`{ error: "<message>" }`, so that the agent can read it: invalid arguments (the same
|
|
311
329
|
message as for an AI app), a refusal of `onConfirm` (`The user did not allow <tool> to
|
|
@@ -368,7 +386,8 @@ that an AI app reaches it through the extension:
|
|
|
368
386
|
arguments (key order aside) within 2 seconds runs without `onConfirm`: the user just
|
|
369
387
|
allowed exactly that call. Its caller in
|
|
370
388
|
`execute`, `toolcall` and `toolcallend` is
|
|
371
|
-
`{ kind: "webmcp", via: "tab-mcp-extension", name, host
|
|
389
|
+
`{ kind: "webmcp", via: "tab-mcp-extension", name, host, allowed: true }` (`allowed`
|
|
390
|
+
from the release after 0.23 on), so an activity view can say
|
|
372
391
|
"Claude (claude.ai) through the tab-mcp browser extension". A vouch is used once and
|
|
373
392
|
only for the tool registered under its name when it came (a tool registered anew
|
|
374
393
|
since asks). Everything else is as for any call: the arguments are checked, the
|
|
@@ -377,8 +396,25 @@ that an AI app reaches it through the extension:
|
|
|
377
396
|
reached the page) is dropped. Any call that matches no vouch (an agent in the
|
|
378
397
|
browser, another extension, an `exposedTo` origin, a call after the 2 seconds) is an
|
|
379
398
|
unvouched WebMCP call: `onConfirm` decides, without one it runs.
|
|
380
|
-
-
|
|
381
|
-
|
|
399
|
+
- **A claimed call** (from the release after 0.23 on, DEC-224). Right before the
|
|
400
|
+
extension runs a tool it does not ask about (one marked `readOnlyHint`), it tells the
|
|
401
|
+
page the same as for a vouch, as a `claim`. The call that matches it is named as the
|
|
402
|
+
extension's (`via`, `name`, `host`, as above, with `allowed: false`) and allows
|
|
403
|
+
nothing: a tool that asks goes to `onConfirm` as for any WebMCP call. So `via` alone
|
|
404
|
+
no longer means that the user allowed the call: a page that asks in `execute` itself
|
|
405
|
+
skips its question only for `allowed: true`. The page learns which AI app calls its
|
|
406
|
+
read-only tools through the extension, while the extension's AI access is on.
|
|
407
|
+
- **Pictures.** The extension asks for the whole MCP result with both (`result: "mcp"`),
|
|
408
|
+
and the call that matches one resolves with it ([above](#webmcp)): an AI app
|
|
409
|
+
connected through the extension gets a tool's images as one connected to the page
|
|
410
|
+
directly does. Any other WebMCP call, a vouch of an older extension and every call
|
|
411
|
+
with `trustExtension: false` get the result as text, each image a line "[image content
|
|
412
|
+
left out: WebMCP results are text.]". An agent in the browser that calls the same
|
|
413
|
+
tool with equal arguments in the moment before the extension's call reaches the page
|
|
414
|
+
takes the vouch or claim, and with it the whole result (A14 in the threat model).
|
|
415
|
+
- **`trustExtension: false`** treats a vouched or claimed call as any other WebMCP
|
|
416
|
+
call, for a site whose `onConfirm` insists on its own rule: no AI app named, the
|
|
417
|
+
result as text. `extension` is still reported.
|
|
382
418
|
- **What the page tells the extension:** the library's version, the app id and the AI
|
|
383
419
|
apps connected to the page directly (`name`, `host`, as `grants` has them; at most
|
|
384
420
|
64), again on
|
|
@@ -393,11 +429,15 @@ that an AI app reaches it through the extension:
|
|
|
393
429
|
parts the user trusts, not a security boundary. Only the top frame takes part.
|
|
394
430
|
- Old and new mix: an extension that does not know the handshake says nothing, and its
|
|
395
431
|
calls are unvouched WebMCP calls, which the library does not ask; the extension says nothing to a page that
|
|
396
|
-
did not announce the library.
|
|
432
|
+
did not announce the library. An extension that sends no claims and no `result:
|
|
433
|
+
"mcp"` gets text as before; a library of 0.23 or older ignores claims and `result`,
|
|
434
|
+
and answers the extension's calls with text as before.
|
|
397
435
|
|
|
398
436
|
A page that registers its WebMCP tools itself, without the library's mirror, can take
|
|
399
437
|
part the same way: answer the events as `src/handshake.ts` does, skip its own
|
|
400
|
-
question for a call that matches a vouch
|
|
438
|
+
question for a call that matches a vouch (never for a claim), answer a call that
|
|
439
|
+
matches either with `result: "mcp"` with the whole MCP result, and drop one the
|
|
440
|
+
extension withdraws.
|
|
401
441
|
|
|
402
442
|
### Your own assistant on the page
|
|
403
443
|
|
|
@@ -826,8 +866,8 @@ mcp.addEventListener("grantschange", drawSwitches);
|
|
|
826
866
|
that does not import it loads nothing of it. Take both from the same version:
|
|
827
867
|
|
|
828
868
|
```js
|
|
829
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
830
|
-
import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
869
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.24.0-rc.1/cdn/tab-mcp-client.min.js";
|
|
870
|
+
import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.24.0-rc.1/cdn/allowed.min.js";
|
|
831
871
|
```
|
|
832
872
|
|
|
833
873
|
**The risk.** An allowance outlives the user's attention: for up to the grant's 90 days,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var At=/^(?:\d{1,4}x\d{1,4}|any)$/;function Ot(e){let{src:t,mimeType:n,sizes:r,theme:o}=e;if(typeof t!=="string")return;let a=/^https?:/i.test(t)&&t.length<=2048,s=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!a&&!s)return;let i={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))i.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((b)=>String(b).toLowerCase()).filter((b)=>At.test(b)):[];if(u.length>0)i.sizes=u;if(o==="light"||o==="dark")i.theme=o;return i}function Oe(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?Ot(n):void 0;if(r!==void 0)t.push(r);if(t.length===8)break}return t}function be(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return Oe([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let o=n.getAttribute("sizes");if(o)r.sizes=o.trim().split(/\s+/);let a=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(a)r.theme=a[1]?.toLowerCase();return r}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let r=Array.isArray(e),o=Array.isArray(t);if(r!==o)return!1;if(r){let a=e.length;if(a!==t.length)return!1;for(let s=0;s<a;s++)if(!ue(e[s],t[s]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let a=Object.keys(e),s=Object.keys(t);if(a.length!==s.length)return!1;for(let u of a){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function U(e){return encodeURI(Pt(e)).replace(/#/g,"%23")}function Pt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var Nt=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,jt=/^%[0-9A-Fa-f]{2}$/,qt=/^[A-Za-z0-9._~-]$/;function Ht(e){let t="";for(let n=0;n<e.length;){let r=e[n],o=e.slice(n,n+3);if(r==="%"&&jt.test(o)){let s=String.fromCharCode(parseInt(o.slice(1),16));t+=qt.test(s)?s:o.toUpperCase(),n+=3;continue}let a=String.fromCodePoint(e.codePointAt(n));t+=Nt.test(a)?a:encodeURIComponent(a),n+=a.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?Ht(n.hash.slice(1)):"",n}var zt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},Dt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Jt={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},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 Z(e,t=Object.create(null),n=Ut,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let a=e.$id||e.id;if(a){let s=$e(a,n);if(s.hash.length>1)t[s.href]=e;else if(s.hash="",r==="")n=s;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let o=n.href+(r?"#"+r:"");if(t[o]!==void 0&&t[o]!==e)throw Error(`Duplicate schema URI "${o}".`);if(t[o]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:o});if(e.$ref&&e.__absolute_ref__===void 0){let a=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:a.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let a=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:a.href})}if(e.$anchor){let a=$e("#"+e.$anchor,n);t[a.href]=e}for(let a in e){if(Jt[a])continue;let s=`${r}/${U(a)}`,i=e[a];if(Array.isArray(i)){if(zt[a]){let u=i.length;for(let b=0;b<u;b++)Z(i[b],t,n,`${s}/${b}`)}}else if(Dt[a])for(let u in i)Z(i[u],t,n,`${s}/${U(u)}`);else Z(i,t,n,s)}return t}var Bt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Vt=[0,31,28,31,30,31,30,31,31,30,31,30,31],Gt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Qe=/^(?=.{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,Wt=/^(?:[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,Ft=/^(?:(?:[^\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,Kt=/^(?:(?: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,Yt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Xt=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Zt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Qt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Lt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,en=(e)=>{let t=e.match(Lt);if(!t)return!1;let n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){let o=r.slice(1,-1);if(/^ipv6:/i.test(o))return et.test(o.slice(5));return Le.test(o)}return Qe.test(r)},Le=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,et=/^((([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,tn=(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 G(e){return e.test.bind(e)}var Pe={date:tt,time:nt.bind(void 0,!0),"date-time":on,duration:tn,uri:dn,"uri-reference":G(Wt),"uri-template":G(Ft),url:G(Kt),email:en,hostname:G(Qe),ipv4:G(Le),ipv6:G(et),regex:ln,uuid:G(Yt),"json-pointer":G(Xt),"json-pointer-uri-fragment":G(Zt),"relative-json-pointer":G(Qt)};function nn(e){return e%4===0&&(e%100!==0||e%400===0)}function tt(e){let t=e.match(Bt);if(!t)return!1;let n=t[1],r=t[2],o=t[3];if(!n||!r||!o)return!1;let a=+n,s=+r,i=+o,u=s==2&&nn(a)?29:Vt[s];return s>=1&&s<=12&&i>=1&&u!==void 0&&i<=u}function nt(e,t){let n=t.match(Gt);if(!n)return!1;let r=n[1],o=n[2],a=n[3];if(!r||!o||!a)return!1;let s=+r,i=+o,u=+a,b=n[5],k=n[6],M=+(n[7]??0),C=+(n[8]??0);if(s>23||i>59||u>60||M>23||C>59||e&&b===void 0)return!1;if(u<60)return!0;let N=k==="+"?1:k==="-"?-1:0;return(s*60+i-N*(M*60+C)+1440)%1440===1439}var rn=/t|\s/i;function on(e){let[t,n,r]=e.split(rn);return t!==void 0&&n!==void 0&&r===void 0&&tt(t)&&nt(!0,n)}var sn=/\/|:/,an=/^(?:[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 dn(e){return sn.test(e)&&an.test(e)}var un=/[^\\]\\Z/;function ln(e){if(un.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function rt(e){let t=0,n=e.length,r=0,o;while(r<n)if(t++,o=e.charCodeAt(r++),o>=55296&&o<=56319&&r<n){if(o=e.charCodeAt(r),(o&64512)==56320)r++}return t}function se(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ot(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",o=n.indexOf("."),a=o===-1?0:n.length-o-1;return[BigInt(n.replace(".","")),Number(r)-a]}function fn(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=ot(e),[o,a]=ot(t),s=r-a;if(s>=0)return n*10n**BigInt(s)%o===0n;return n%(o*10n**BigInt(-s))===0n}function j(e,t,n="2019-09",r=Z(t),o=!0,a=null,s="#",i="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:s,keyword:"false",keywordLocation:s,error:"False boolean schema."}]};let b=typeof e,k;switch(b){case"boolean":case"number":case"string":k=b;break;case"object":if(e===null)k="null";else if(Array.isArray(e))k="array";else k="object";break;default:throw Error(`Instances of "${b}" type are not supported.`)}let{$ref:M,$recursiveRef:C,$recursiveAnchor:N,type:_,const:O,enum:q,required:B,not:f,anyOf:y,allOf:g,oneOf:x,if:h,then:R,else:A,format:E,properties:d,patternProperties:S,additionalProperties:H,unevaluatedProperties:z,minProperties:X,maxProperties:V,propertyNames:te,dependentRequired:ne,dependentSchemas:Ge,dependencies:Me,prefixItems:Ce,items:ce,additionalItems:We,unevaluatedItems:Fe,contains:Ke,minContains:K,maxContains:Se,minItems:_e,maxItems:Ee,uniqueItems:_t,minimum:re,maximum:oe,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ae,minLength:ye,maxLength:ge,pattern:Ye,__absolute_ref__:he,__absolute_recursive_ref__:Et}=t,c=[];if(N===!0&&a===null)a=t;if(C==="#"){let T=a===null?r[Et]:a,m=`${i}/$recursiveRef`,I=j(e,a===null?t:a,n,r,o,T,s,m,u);if(!I.valid)c.push({instanceLocation:s,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(M!==void 0){let m=r[he||M];if(m===void 0){let l=`Unresolved $ref "${M}".`;if(he&&he!==M)l+=` Absolute URI "${he}".`;throw l+=`
|
|
2
|
+
Known schemas:
|
|
3
|
+
- ${Object.keys(r).join(`
|
|
4
|
+
- `)}`,Error(l)}let I=`${i}/$ref`,p=j(e,m,n,r,o,a,s,I,u);if(!p.valid)c.push({instanceLocation:s,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...p.errors);if(n==="4"||n==="7")return{valid:c.length===0,errors:c}}if(Array.isArray(_)){let T=_.length,m=!1;for(let I=0;I<T;I++)if(k===_[I]||_[I]==="integer"&&k==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${_.join('", "')}".`})}else if(_==="integer"){if(k!=="number"||e%1||e!==e)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${_}".`})}else if(_!==void 0&&k!==_)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${_}".`});if(O!==void 0){if(k==="object"||k==="array"){if(!ue(e,O))c.push({instanceLocation:s,keyword:"const",keywordLocation:`${i}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:s,keyword:"const",keywordLocation:`${i}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}if(q!==void 0){if(k==="object"||k==="array"){if(!q.some((T)=>ue(e,T)))c.push({instanceLocation:s,keyword:"enum",keywordLocation:`${i}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}else if(!q.some((T)=>e===T))c.push({instanceLocation:s,keyword:"enum",keywordLocation:`${i}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}if(f!==void 0){let T=`${i}/not`;if(j(e,f,n,r,o,a,s,T).valid)c.push({instanceLocation:s,keyword:"not",keywordLocation:T,error:'Instance matched "not" schema.'})}let we=[];if(y!==void 0){let T=`${i}/anyOf`,m=c.length,I=!1;for(let[p,l]of y.entries()){let v=Object.create(u),w=j(e,l,n,r,o,N===!0?a:null,s,`${T}/${p}`,v);if(c.push(...w.errors),I=I||w.valid,w.valid)we.push(v)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:s,keyword:"anyOf",keywordLocation:T,error:"Instance does not match any subschemas."})}if(g!==void 0){let T=`${i}/allOf`,m=c.length,I=!0;for(let[p,l]of g.entries()){let v=Object.create(u),w=j(e,l,n,r,o,N===!0?a:null,s,`${T}/${p}`,v);if(c.push(...w.errors),I=I&&w.valid,w.valid)we.push(v)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:s,keyword:"allOf",keywordLocation:T,error:"Instance does not match every subschema."})}if(x!==void 0){let T=`${i}/oneOf`,m=c.length,I=x.filter((p,l)=>{let v=Object.create(u),w=j(e,p,n,r,o,N===!0?a:null,s,`${T}/${l}`,v);if(c.push(...w.errors),w.valid)we.push(v);return w.valid}).length;if(I===1)c.length=m;else c.splice(m,0,{instanceLocation:s,keyword:"oneOf",keywordLocation:T,error:`Instance does not match exactly one subschema (${I} matches).`})}if(k==="object"||k==="array")Object.assign(u,...we);if(h!==void 0){let T=`${i}/if`,m=Object.create(null);if(j(e,h,n,r,o,a,s,T,m).valid){if(Object.assign(u,m),R!==void 0){let p=j(e,R,n,r,o,a,s,`${i}/then`,u);if(!p.valid)c.push({instanceLocation:s,keyword:"if",keywordLocation:T,error:'Instance does not match "then" schema.'},...p.errors)}}else if(A!==void 0){let p=j(e,A,n,r,o,a,s,`${i}/else`,u);if(!p.valid)c.push({instanceLocation:s,keyword:"if",keywordLocation:T,error:'Instance does not match "else" schema.'},...p.errors)}}if(k==="object"){if(B!==void 0){for(let p of B)if(!se(e,p))c.push({instanceLocation:s,keyword:"required",keywordLocation:`${i}/required`,error:`Instance does not have required property "${p}".`})}let T=Object.keys(e);if(X!==void 0&&T.length<X)c.push({instanceLocation:s,keyword:"minProperties",keywordLocation:`${i}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&T.length>V)c.push({instanceLocation:s,keyword:"maxProperties",keywordLocation:`${i}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(te!==void 0){let p=`${i}/propertyNames`;for(let l in e){let v=`${s}/${U(l)}`,w=j(l,te,n,r,o,a,v,p);if(!w.valid)c.push({instanceLocation:s,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...w.errors)}}if(ne!==void 0){let p=`${i}/dependantRequired`;for(let l in ne)if(se(e,l)){let v=ne[l];for(let w of v)if(!se(e,w))c.push({instanceLocation:s,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}}if(Ge!==void 0)for(let[p,l]of Object.entries(Ge)){let v=`${i}/dependentSchemas`;if(se(e,p)){let w=j(e,l,n,r,o,a,s,`${v}/${U(p)}`,u);if(!w.valid)c.push({instanceLocation:s,keyword:"dependentSchemas",keywordLocation:v,error:`Instance has "${p}" but does not match dependant schema.`},...w.errors)}}if(Me!==void 0){let p=`${i}/dependencies`;for(let l in Me)if(se(e,l)){let v=Me[l];if(Array.isArray(v)){for(let w of v)if(!se(e,w))c.push({instanceLocation:s,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}else{let w=j(e,v,n,r,o,a,s,`${p}/${U(l)}`);if(!w.valid)c.push({instanceLocation:s,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not match dependant schema.`},...w.errors)}}}let m=Object.create(null),I=!1;if(d!==void 0){let p=`${i}/properties`;for(let[l,v]of Object.entries(d)){if(!se(e,l))continue;let w=`${s}/${U(l)}`,D=j(e[l],v,n,r,o,a,w,`${p}/${U(l)}`);if(m[l]=!0,D.valid)u[l]=!0;else if(I=o,c.push({instanceLocation:s,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...D.errors),I)break}}if(!I&&S!==void 0){let p=`${i}/patternProperties`;for(let[l,v]of Object.entries(S)){let w=new RegExp(l,"u");for(let D in e){if(!w.test(D))continue;let Xe=`${s}/${U(D)}`,Ze=j(e[D],v,n,r,o,a,Xe,`${p}/${U(l)}`);if(m[D]=!0,Ze.valid)u[D]=!0;else I=o,c.push({instanceLocation:s,keyword:"patternProperties",keywordLocation:p,error:`Property "${D}" matches pattern "${l}" but does not match associated schema.`},...Ze.errors)}}}if(!I&&H!==void 0){let p=`${i}/additionalProperties`;for(let l in e){if(m[l])continue;let v=`${s}/${U(l)}`,w=j(e[l],H,n,r,o,a,v,p);if(w.valid)u[l]=!0;else I=o,c.push({instanceLocation:s,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...w.errors)}}else if(!I&&z!==void 0){let p=`${i}/unevaluatedProperties`;for(let l in e)if(!u[l]){let v=`${s}/${U(l)}`,w=j(e[l],z,n,r,o,a,v,p);if(w.valid)u[l]=!0;else c.push({instanceLocation:s,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...w.errors)}}}else if(k==="array"){if(Ee!==void 0&&e.length>Ee)c.push({instanceLocation:s,keyword:"maxItems",keywordLocation:`${i}/maxItems`,error:`Array has too many items (${e.length} > ${Ee}).`});if(_e!==void 0&&e.length<_e)c.push({instanceLocation:s,keyword:"minItems",keywordLocation:`${i}/minItems`,error:`Array has too few items (${e.length} < ${_e}).`});let T=e.length,m=0,I=!1;if(Ce!==void 0){let p=`${i}/prefixItems`,l=Math.min(Ce.length,T);for(;m<l;m++){let v=j(e[m],Ce[m],n,r,o,a,`${s}/${m}`,`${p}/${m}`);if(u[m]=!0,!v.valid){if(I=o,c.push({instanceLocation:s,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...v.errors),I)break}}}if(ce!==void 0){let p=`${i}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,T);for(;m<l;m++){let v=j(e[m],ce[m],n,r,o,a,`${s}/${m}`,`${p}/${m}`);if(u[m]=!0,!v.valid){if(I=o,c.push({instanceLocation:s,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...v.errors),I)break}}}else for(;m<T;m++){let l=j(e[m],ce,n,r,o,a,`${s}/${m}`,p);if(u[m]=!0,!l.valid){if(I=o,c.push({instanceLocation:s,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&We!==void 0){let l=`${i}/additionalItems`;for(;m<T;m++){let v=j(e[m],We,n,r,o,a,`${s}/${m}`,l);if(u[m]=!0,!v.valid)I=o,c.push({instanceLocation:s,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...v.errors)}}}if(Ke!==void 0)if(T===0&&K===void 0)c.push({instanceLocation:s,keyword:"contains",keywordLocation:`${i}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(K!==void 0&&T<K)c.push({instanceLocation:s,keyword:"minContains",keywordLocation:`${i}/minContains`,error:`Array has less items (${T}) than minContains (${K}).`});else{let p=`${i}/contains`,l=c.length,v=0;for(let w=0;w<T;w++){let D=j(e[w],Ke,n,r,o,a,`${s}/${w}`,p);if(D.valid)u[w]=!0,v++;else c.push(...D.errors)}if(v>=(K||0))c.length=l;if(K===void 0&&v===0)c.splice(l,0,{instanceLocation:s,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&v<K)c.push({instanceLocation:s,keyword:"minContains",keywordLocation:`${i}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${v} items were found.`});else if(Se!==void 0&&v>Se)c.push({instanceLocation:s,keyword:"maxContains",keywordLocation:`${i}/maxContains`,error:`Array may contain at most ${Se} items matching schema. ${v} items were found.`})}if(!I&&Fe!==void 0){let p=`${i}/unevaluatedItems`;for(m;m<T;m++){if(u[m])continue;let l=j(e[m],Fe,n,r,o,a,`${s}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:s,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(_t)for(let p=0;p<T;p++){let l=e[p],v=typeof l==="object"&&l!==null;for(let w=0;w<T;w++){if(p===w)continue;let D=e[w];if(l===D||v&&(typeof D==="object"&&D!==null)&&ue(l,D))c.push({instanceLocation:s,keyword:"uniqueItems",keywordLocation:`${i}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${w}.`}),p=Number.MAX_SAFE_INTEGER,w=Number.MAX_SAFE_INTEGER}}}else if(k==="number"){if(n==="4"){if(re!==void 0&&(pe===!0&&e<=re||e<re))c.push({instanceLocation:s,keyword:"minimum",keywordLocation:`${i}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${re}.`});if(oe!==void 0&&(me===!0&&e>=oe||e>oe))c.push({instanceLocation:s,keyword:"maximum",keywordLocation:`${i}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${oe}.`})}else{if(re!==void 0&&e<re)c.push({instanceLocation:s,keyword:"minimum",keywordLocation:`${i}/minimum`,error:`${e} is less than ${re}.`});if(oe!==void 0&&e>oe)c.push({instanceLocation:s,keyword:"maximum",keywordLocation:`${i}/maximum`,error:`${e} is greater than ${oe}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:s,keyword:"exclusiveMinimum",keywordLocation:`${i}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:s,keyword:"exclusiveMaximum",keywordLocation:`${i}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ae!==void 0){if(!fn(e,Ae))c.push({instanceLocation:s,keyword:"multipleOf",keywordLocation:`${i}/multipleOf`,error:`${e} is not a multiple of ${Ae}.`})}}else if(k==="string"){let T=ye===void 0&&ge===void 0?0:rt(e);if(ye!==void 0&&T<ye)c.push({instanceLocation:s,keyword:"minLength",keywordLocation:`${i}/minLength`,error:`String is too short (${T} < ${ye}).`});if(ge!==void 0&&T>ge)c.push({instanceLocation:s,keyword:"maxLength",keywordLocation:`${i}/maxLength`,error:`String is too long (${T} > ${ge}).`});if(Ye!==void 0&&!new RegExp(Ye,"u").test(e))c.push({instanceLocation:s,keyword:"pattern",keywordLocation:`${i}/pattern`,error:"String does not match pattern."});if(E!==void 0&&Pe[E]&&!Pe[E](e))c.push({instanceLocation:s,keyword:"format",keywordLocation:`${i}/format`,error:`String does not match format "${E}".`})}return{valid:c.length===0,errors:c}}var st="ch.ractive.tab-mcp/annotations",cn=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],pn=["destructiveHint","idempotentHint","openWorldHint"];function it(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 o of pn){let a=e[o];if(a!==void 0)t[o]=a}let n={};for(let o of cn){let a=e[o];if(a!==void 0)n[o]=a}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function at(e){let t=e._meta??{},n=t["ch.ractive.tab-mcp/annotations"];return{...e,_meta:{...t,["ch.ractive.tab-mcp/annotations"]:{...Y(n)?n:{},untrustedContentHint:!0}}}}function Q(e){return{content:[{type:"text",text:e}],isError:!0}}function Y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var le=(e)=>typeof e==="string";function mn(e){if(!Y(e))return!1;switch(e.type){case"text":return le(e.text);case"image":case"audio":return le(e.data)&&le(e.mimeType);case"resource_link":return le(e.uri)&&le(e.name);case"resource":return Y(e.resource)&&le(e.resource.uri);default:return!1}}var yn=new Set(["content","structuredContent","isError","_meta","resultType"]);function xe(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:o}=e;return(t.length>0?t.every(mn):Object.keys(e).every((a)=>yn.has(a)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(o===void 0||Y(o))}function dt(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(xe(e))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return Q("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]},r=JSON.parse(t);if(Y(r))n.structuredContent=r;return n}function Ne(e,t=!1){return e.content.map((n)=>Y(n)&&n.type==="text"&&typeof n.text==="string"?n.text:t?`[${Y(n)?String(n.type):"A"} content left out: WebMCP results are text.]`:"").filter((n)=>n!=="").join(`
|
|
5
|
+
`)}function ut(e){if(xe(e))return e.structuredContent??(Ne(e,!0)||"Done.");return e===void 0?"Done.":e}function je(e){let{content:t,structuredContent:n,isError:r}=e;return{content:t,...n?{structuredContent:n}:{},...r?{isError:r}:{}}}function lt(e){let t=e instanceof Error?e.message:String(e);return Q(t||"The tool failed.")}var ie="2026-07-28",L="io.modelcontextprotocol/protocolVersion",ve="io.modelcontextprotocol/clientCapabilities",ft="io.modelcontextprotocol/clientInfo",ct="io.modelcontextprotocol/serverInfo",qe="io.modelcontextprotocol/subscriptionId",gn=-32020,pt=-32022,hn="The page may ask the user to allow each call, usually in the page's browser tab.",wn=0,mt=new WeakMap;function He(e){let t=mt.get(e);if(t!==void 0)return t;let n=e.inputSchema,r=yt(n,"inputSchema");if(e.outputSchema!==void 0)yt(e.outputSchema,"outputSchema");let o=(a)=>j(a,n,"2020-12",r,!1);return mt.set(e,o),o}class Te extends Error{what;constructor(e,t){super(t);this.what=e}}function yt(e,t){let n;try{n=Z(e)}catch(r){let o=r instanceof Error?r.message:String(r);throw new Te(t,o.split(`
|
|
6
|
+
`)[0]??"")}for(let r of Object.values(n)){if(typeof r!=="object"||r.$ref===void 0)continue;let o=r.__absolute_ref__;if(n[o??r.$ref]===void 0)throw new Te(t,`$ref ${JSON.stringify(r.$ref)} does not resolve`)}return n}function gt(e,t,n=""){let r=t instanceof Error?t.message:String(t),o=t instanceof Te?t.what:"inputSchema";return TypeError(`registerTool: the ${o} of ${e}: ${r}${n}`)}function bn(e){let t=[];for(let n of e.list())try{He(n)}catch(r){e.remove(n),t.push(gt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{He(n)}catch(r){throw gt(n.name,r)}}),t}function ht(e){try{return structuredClone(e)}catch{return e}}var $n=new TextEncoder;function ee(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function ze(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function J(e,t,n,r,o){let a={code:n,message:r};if(o!==void 0)a.data=o;return ze(e,{jsonrpc:"2.0",id:t,error:a})}function W(e,t,n){return J(400,e,gn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return $n.encode(`event: message
|
|
7
|
+
data: ${JSON.stringify(e)}
|
|
8
|
+
|
|
9
|
+
`)}var wt={"content-type":"text/event-stream","cache-control":"no-cache"};function xn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function vn(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),r=Uint8Array.from(n,(o)=>o.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function Tn(e){if(!(L in e))return{key:L,problem:"missing"};if(!(ve in e))return{key:ve,problem:"missing"};if(typeof e[L]!=="string")return{key:L,problem:"expected a protocol version string"};if(!ee(e[ve]))return{key:ve,problem:"expected an object"};let t=e[ft];if(t!==void 0&&!(ee(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:ft,problem:"expected {name, version}"};return}function kn(e){let t=e.notifications;return ee(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Rn(e,t){let n;try{n=He(e)(t)}catch(o){let a=o instanceof Error?o.message:String(o);return`The input schema of tool ${e.name} cannot be used: ${a}`}if(n.valid)return;let r=n.errors.filter((o)=>o.keyword!=="properties"&&o.keyword!=="$ref").map((o)=>`${o.instanceLocation} ${o.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${r||"the arguments do not match the schema"}`}async function bt(e,t,n,r,o,a){let s={id:++wn,tool:t.name,arguments:ht(n),client:{...o}};if(t.title!==void 0)s.title=t.title;let i=Date.now();e.observe?.start(s);let u={outcome:"error",result:Q("Internal error")};try{if(u=await Mn(e,t,n,r,o),t.annotations.untrustedContentHint===!0)u.result=at(u.result);let b=r.aborted?void 0:a?.(u.result);if(b!==void 0)u={outcome:"error",result:b}}finally{e.observe?.end({id:s.id,tool:t.name,client:{...o},outcome:u.outcome,result:ht(u.result),durationMs:Date.now()-i})}return u}var In="The user was asked and did not answer.";async function Mn(e,t,n,r,o){let a=(C,N,_)=>({outcome:C,result:Q(N),stop:_}),s=Rn(t,n);if(s!==void 0)return a("error",s,"invalid");let i=new Promise((C,N)=>{if(r.aborted)N(r.reason);r.addEventListener("abort",()=>N(r.reason))});i.catch(()=>{});let{consequentialHint:u,destructiveHint:b}=t.annotations;if((o.kind==="webmcp"?u??b:u)===!0){let C={tool:{name:t.name,description:t.description},arguments:n,client:o,signal:r};if(t.title!==void 0)C.tool.title=t.title;let N=!1;try{N=await Promise.race([e.confirm(C),i])}catch{N=!1}if(N!==!0){if(r.aborted)return a("cancelled","The call was cancelled.","cancelled");return N==="unanswered"?a("unanswered",In,"unanswered"):a("declined","The user did not allow this call.","declined")}}if(r.aborted)return a("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return a("error","The tool is no longer available","gone");let M;try{let C=await Promise.race([t.execute(n,{signal:r,client:o}),i]);M={outcome:"ok",result:dt(C),returned:{value:C}}}catch(C){M={outcome:"error",result:lt(C)}}if(r.aborted)return{...M,outcome:"cancelled",stop:"cancelled"};if(M.result.isError===!0)M.outcome="error";return M}async function $t(e,t,n,r,o,a=!1){let s=(k)=>a?Q(k):{error:k},i=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return s(i);if(!ee(n))return s("The input must be an object.");let u=await bt(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,o);if(u.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(u.stop==="declined")return s(`The user did not allow ${t.name} to run.`);if(u.stop==="unanswered")return s(`The user did not answer whether ${t.name} may run.`);if(u.stop==="gone")return s(i);if(u.result.isError===!0)return a?je(u.result):s(Ne(u.result)||"The tool failed.");let b=u.returned?.value;return a&&xe(b)?je(b):ut(b)}function ke(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let o=Oe(n.icons??[]),a=o.length>0?{...r,icons:o}:r,s=new Set,i=!1,u=(f={})=>({...f,[ct]:r});function b(f,y,g=u()){return{jsonrpc:"2.0",id:f,result:{...y,resultType:"complete",_meta:g}}}function k(){return t.list().map((f)=>{let y={name:f.name};if(f.title!==void 0)y.title=f.title;if(y.description=f.annotations.consequentialHint===!0&&!e.ownConfirm?`${f.description} ${hn}`:f.description,y.inputSchema=f.inputSchema,f.outputSchema!==void 0)y.outputSchema=f.outputSchema;let{annotations:g,meta:x}=it(f.annotations);if(g!==void 0)y.annotations=g;if(x!==void 0)y._meta={[st]:x};return y})}let M=(f)=>({kind:"invalid",message:f});async function C(f,y,g,x){let h=f.name;if(typeof h!=="string")return M("Invalid params: name must be a string");let R=t.get(h);if(R===void 0)return M(`Tool ${h} not found`);let A=f.arguments??{};if(!ee(A))return M("Invalid params: arguments must be an object");return{kind:"result",result:(await bt(e,R,A,y,e.client(g),x)).result}}function N(f,y,g,x){let h=(d)=>ae(b(f,d,u(d._meta))),R,A=(d)=>{let S;try{S=h(d)}catch{return Q("The tool returned a result that is not JSON.")}let H=e.maxBodyBytes?.();if(H!==void 0&&S.byteLength>H)return Q(`The result is ${S.byteLength} bytes; the relay passes on at most ${H}.`);R={result:d,event:S};return},E=new ReadableStream({start:(d)=>{let S=(H)=>{if(g.aborted)return;try{d.enqueue(H()),d.close()}catch{}};C(y,g,x,A).then((H)=>S(()=>H.kind==="invalid"?ae({jsonrpc:"2.0",id:f,error:{code:-32602,message:H.message}}):H.result===R?.result?R.event:h(H.result)),()=>S(()=>ae({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}})))}});return new Response(E,{status:200,headers:wt})}function _(f,y,g){let x=kn(y),h={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[qe]:f})}},R,A=new ReadableStream({start:(E)=>{if(E.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:x,_meta:{[qe]:f}}})),Object.keys(x).length===0){E.enqueue(ae(h)),E.close();return}let d={id:f,send:(S)=>{try{E.enqueue(ae(S))}catch{s.delete(d)}},end:()=>{s.delete(d);try{E.enqueue(ae(h)),E.close()}catch{}}};R=d,s.add(d),g.addEventListener("abort",()=>{s.delete(d);try{E.close()}catch{}})},cancel:()=>{if(R!==void 0)s.delete(R)}});return new Response(A,{status:200,headers:wt})}function O(f,y){if(Array.isArray(y))return J(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!ee(y)||y.jsonrpc!=="2.0")return J(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:g,id:x}=y;if(typeof g!=="string")return"result"in y||"error"in y?J(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):J(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let h=f.headers.get("mcp-protocol-version"),R=f.headers.get("mcp-method"),A=ee(y.params)?y.params:{},E=ee(A._meta)?A._meta:void 0,d=E!==void 0&&L in E,S=typeof E?.[L]==="string"?E[L]:void 0,H=h!==null&&h>=ie;if(x===void 0){if(S!==void 0&&h!==null&&h!==S)return W(null,h,`the notification envelope names protocol version ${S} but the MCP-Protocol-Version header names ${h}`);if((d||H)&&R!==null&&R!==g)return W(null,R,`the notification body names method ${g} but the Mcp-Method header names ${R}`);return"notification"}if(typeof x!=="string"&&typeof x!=="number")return J(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let z=x;if(!d||g==="initialize"&&(S===void 0||S<ie)){if(g==="initialize"){if(H)return W(z,h,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let V=typeof A.protocolVersion==="string"?A.protocolVersion:void 0;return q(z,V)}if(H){let V=E===void 0?["_meta"]:[L];return J(400,z,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${h}, but the request is missing the required per-request envelope key(s): ${V.join(", ")}`,{envelope:{missing:V}})}return q(z,h??void 0)}let X=Tn(E);if(X!==void 0)return J(400,z,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${X.key}: ${X.problem}`,{envelope:X});if(h!==null&&S!==void 0&&h!==S)return W(z,h,`the body envelope names protocol version ${S} but the MCP-Protocol-Version header names ${h}`);if(R!==null&&R!==g)return W(z,R,`the body names method ${g} but the Mcp-Method header names ${R}`);if(S!==ie)return q(z,S);if(h===null)return W(z,"(missing)",`the body envelope names protocol version ${S} but the required MCP-Protocol-Version header is absent`);if(R===null)return W(z,"(missing)",`the body names method ${g} but the required Mcp-Method header is absent`);if(g==="tools/call"&&typeof A.name==="string"){let V=A.name,te=f.headers.get("mcp-name");if(te===null)return W(z,"(missing)",`the body carries params.name="${V}" but the required Mcp-Name header is absent`);let ne=vn(te);if(ne===void 0)return W(z,te,"the Mcp-Name header carries an invalid Base64 sentinel value");if(ne!==V)return W(z,te,`the body carries params.name="${V}" but the Mcp-Name header names "${ne}"`)}return{id:z,method:g,params:A}}function q(f,y){return y===void 0?J(400,f,pt,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):J(400,f,pt,`Unsupported protocol version: ${y}`,{supported:[ie],requested:y})}async function B(f,y){if(f.method.toUpperCase()!=="POST")return J(405,null,-32000,"Method not allowed.");if(!xn(f.headers.get("content-type")))return J(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let g;try{g=JSON.parse(y.body??await f.text())}catch{return J(400,null,-32700,"Parse error: the request body is not valid JSON")}let x=O(f,g);if(x instanceof Response)return x;if(x==="notification")return new Response(null,{status:202});let{id:h,method:R,params:A}=x;switch(R){case"server/discover":{let E={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)E.instructions=n.instructions;return E.ttlMs=0,E.cacheScope="private",ze(200,b(h,E,{[ct]:a}))}case"tools/list":return ze(200,b(h,{tools:k(),ttlMs:0,cacheScope:"private"}));case"tools/call":return N(h,A,f.signal,y.grant);case"subscriptions/listen":return _(h,A,f.signal);default:return J(404,h,-32601,"Method not found")}}return{handle:(f,y)=>B(f,y).catch(()=>J(500,null,-32603,"Internal server error")),toolsChanged(){if(i)return;i=!0,queueMicrotask(()=>{i=!1;for(let f of[...s])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[qe]:f.id}}})})},close(){for(let f of[...s])f.end()}}}var Re="tab-mcp.v1",Cn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function xt(e){if(!fe(e)||!P(e.grantId)||!P(e.createdAt))return!1;let t=e.client;return fe(t)&&P(t.id)&&P(t.name)&&P(t.host)}function Sn(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function _n(e){return fe(e)&&Object.values(e).every(P)}function vt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return P(t.sessionId)&&P(t.address)&&P(t.origin)&&P(t.expiresAt)&&Sn(t.limits)&&Array.isArray(t.grants)&&t.grants.every(xt)&&(t.appName===void 0||P(t.appName))&&(t.pairing===void 0||P(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:P(t.reason)?t.reason:""};case"http.request":return P(t.id)&&P(t.method)&&P(t.path)&&_n(t.headers)&&P(t.body)&&fe(t.grant)&&P(t.grant.grantId)&&P(t.grant.clientId)?t:void 0;case"http.cancel":return P(t.id)?t:void 0;case"pairing.code":{if(!P(t.code)||!P(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},r=t.reason;if(typeof r==="string"&&Cn.has(r))n.reason=r;return n}case"pairing.open":{let n=t.expiresInMs;if(typeof n==="number"&&Number.isFinite(n)&&n>=0&&n<=2147483647)return{type:"pairing.open",expiresAt:new Date(Date.now()+n).toISOString()};return P(t.expiresAt)&&!Number.isNaN(Date.parse(t.expiresAt))?{type:"pairing.open",expiresAt:t.expiresAt}:void 0}case"grant.added":return xt(t.grant)?t:void 0;case"grant.removed":return P(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:P(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 P(t.code)?t:void 0;default:return}}function En(e,t){let n=(r)=>r&&(r.callers?.includes(t)??!0);return{list:()=>e.list().filter(n),get:(r)=>{let o=e.get(r);return n(o)?o:void 0}}}function Be(e,t,n){let r=t.list();return e.onChange(()=>{let o=t.list();if(o.length===r.length&&o.every((a,s)=>a===r[s]))return;r=o,n()})}function Ie(e,t){return{tools:t==="webmcp"?e.registry:En(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:!!e.onConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var An=["content-type","cache-control"];function*Ue(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),o=e.charCodeAt(r-1);if(r<e.length&&o>=55296&&o<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var On=-31002,Pn="The page did not answer in time.";function Nn(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Ve(e){let{handler:t,send:n,timeoutMs:r}=e,o=new Map,a=!1;async function s(i){let u=new AbortController;o.get(i.id)?.abort(),o.set(i.id,u);let b=()=>!a&&o.get(i.id)===u&&!u.signal.aborted,k=!1,M="",C=Object.entries(i.headers).some(([_,O])=>_.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),N=r===void 0||C?void 0:setTimeout(()=>{if(!b())return;u.abort();let _=JSON.stringify({jsonrpc:"2.0",id:Nn(i.body),error:{code:On,message:Pn}});if(!k){n({type:"http.response",id:i.id,status:200,headers:{"content-type":"application/json"},body:_});return}if(M===""||M===`
|
|
10
|
+
|
|
11
|
+
`)n({type:"http.response.chunk",id:i.id,data:`event: message
|
|
12
|
+
data: ${_}
|
|
13
|
+
|
|
14
|
+
`});n({type:"http.response.end",id:i.id})},r);try{let _=new Request(`https://tab.invalid${i.path}`,{method:i.method,headers:i.headers,signal:u.signal}),O=await t.handle(_,{grant:i.grant,body:i.body});if(!b()){await O.body?.cancel().catch(()=>{});return}let q={};for(let x of An){let h=O.headers.get(x);if(h!==null)q[x]=h}let B=(q["content-type"]??"").startsWith("text/event-stream"),f=e.maxChunk();if(!B||O.body===null){let x=await O.text();if(!b())return;if(x.length<=f){n({type:"http.response",id:i.id,status:O.status,headers:q,body:x});return}n({type:"http.response.start",id:i.id,status:O.status,headers:q});for(let h of Ue(x,f)){if(!b())break;n({type:"http.response.chunk",id:i.id,data:h})}if(b())n({type:"http.response.end",id:i.id});return}n({type:"http.response.start",id:i.id,status:O.status,headers:q}),k=!0;let y=O.body.getReader(),g=new TextDecoder;u.signal.addEventListener("abort",()=>{y.cancel().catch(()=>{})});for(;;){let{done:x,value:h}=await y.read();if(x||!b())break;let R=g.decode(h,{stream:!0});if(R!=="")M=(M+R).slice(-2);for(let A of Ue(R,f))n({type:"http.response.chunk",id:i.id,data:A})}if(b())n({type:"http.response.end",id:i.id})}catch(_){if(b())e.error(_ instanceof Error?_:Error(String(_))),n({type:"http.response",id:i.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(clearTimeout(N),o.get(i.id)===u)o.delete(i.id)}}return{request(i){if(!a)s(i)},cancel(i){o.get(i)?.abort(),o.delete(i)},close(){if(a)return;a=!0;for(let i of o.values())i.abort();o.clear()}}}var jn=65536,Tt=64,qn=300000,kt=128,De=new WeakSet,Hn=0,F=(e)=>typeof e==="string";function Je(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function zn(e,t,n){let r=n?.client;if(!Je(r)||!F(r.id)||r.id===""||r.name!==void 0&&!F(r.name))throw TypeError("serve: client needs an id (and may have a name)");let o=n.maxChunk??jn;if(!Number.isInteger(o)||o<Tt)throw TypeError(`serve: maxChunk must be a whole number of at least ${Tt}`);let a=n.requestTimeoutMs??qn;if(typeof a!=="number"||!(a>0)||a>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let s=n.onConfirm;if(s!==void 0&&typeof s!=="function")throw TypeError("serve: onConfirm must be a function");if(typeof t?.postMessage!=="function"||!("onmessage"in t))throw TypeError("serve: the port needs postMessage and onmessage");if(De.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let i={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")i.name=r.name;let u={grantId:`local:${++Hn}`,clientId:r.id,scopes:["tools"]},b=!1,k=(y)=>{if(b)return!1;try{return t.postMessage(y),!0}catch{return!1}},M=Ie(e,"local");if(s!==void 0)M.confirm=(y)=>Promise.resolve().then(()=>s(y)).then((g)=>g==="unanswered"?g:g===!0),M.ownConfirm=!0;let C=ke({...M,server:{...e.server,icons:e.server.icons??be()},client:()=>({...i})}),N=Be(e.registry,M.tools,()=>C.toolsChanged()),_=Ve({handler:C,send:k,maxChunk:()=>o,error:(y)=>e.error(y),timeoutMs:a}),O=(y,g)=>{let x={type:"error",code:"bad_message",message:y};if(F(g)&&g.length<=kt)x.id=g;k(x)},q=(y)=>{if(b)return;let g=y?.data;if(!Je(g)||!F(g.type)){O("not a message");return}let x=g.id;switch(g.type){case"http.request":{let{method:h,path:R,headers:A,body:E}=g;if(!F(x)||x===""||x.length>kt||!F(h)||!F(R)||!R.startsWith("/")||!Je(A)||!Object.values(A).every(F)||!F(E)){O("malformed http.request",x);return}_.request({type:"http.request",id:x,method:h,path:R,headers:A,body:E,grant:u});return}case"http.cancel":if(F(x))_.cancel(x);else O("malformed http.cancel");return;case"error":return;default:O(`unexpected ${g.type.slice(0,64)}`,x)}},B=t,f=()=>{if(b)return;if(n.signal?.removeEventListener("abort",f),B.removeEventListener?.("close",f),N(),_.close(),C.close(),De.delete(t))k({type:"bye",reason:"closed"});if(b=!0,t.onmessage===q)t.onmessage=null};if(n.signal?.aborted===!0)return f(),{close:f};return n.signal?.addEventListener("abort",f),B.addEventListener?.("close",f),De.add(t),t.onmessage=q,{close:f}}function Dn(e){let t="",n=0,r=0;for(let o of e){n=n<<8|o,r+=8;while(r>=5)r-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>r&31];n&=(1<<r)-1}if(r>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-r&31];return t}async function Jn(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 $r(e,t,n,r,o){let a=Ie(e,"webmcp");return $t({...a,confirm:(o?.allowed?void 0:e.onConfirm())??(()=>!0)},t,n,r,o===void 0?{kind:"webmcp"}:{kind:"webmcp",via:"tab-mcp-extension",name:o.app.name,host:o.app.host,allowed:o.allowed},o?.whole)}var Un=15000,Rt={1000:"closed",1001:"shutdown",1008:"policy",1009:"too_large",1011:"shutdown",1012:"shutdown",1013:"shutdown",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},It={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var Mt=512,Ct=6,St=64,Bn=Mt+Ct*St;function Vn(e){let t=Math.floor((e-Mt)/Ct);return t>=St?t:void 0}var Gn=1e4;function Wn(e,t,n){let r,o=!1,a=Number.NEGATIVE_INFINITY,s;try{if(e!==void 0&&typeof BroadcastChannel==="function")r=new BroadcastChannel(e),r.onmessage=(i)=>{let u=i.data;if(!o||u?.type!=="claimed"||u.address!==void 0&&u.address!==t)return;a=Date.now(),s?.()}}catch{r=void 0}return{claimed(){o=!0;try{r?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-a<=Gn)return Promise.resolve(!0);if(r===void 0)return Promise.resolve(!1);return new Promise((i)=>{let u=setTimeout(()=>i(!1),n);s=()=>{clearTimeout(u),i(!0)}})},close(){r?.close()}}}function xr(e,t,n,r,o){return new Promise((a,s)=>{let i=["grantschange","statechange","error"],u=(M)=>{clearTimeout(k);for(let C of i)e.removeEventListener(C,b);if(M)s(M);else a()},b=(M)=>{let C=M?.detail?.error;if(n())u();else if((C?.code==="store_unavailable"||C?.code==="unknown_id")&&(C.for===void 0||C.for===t.type&&C.grantId===t.grantId))u(C);else if(!r())u(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},k=setTimeout(()=>u(new DOMException("TabMcp: the relay did not answer","TimeoutError")),o);for(let M of i)e.addEventListener(M,b);b()})}function vr(e){let t=globalThis,n=globalThis.document,r=()=>{if(n?.visibilityState!=="hidden")e()};return n?.addEventListener("visibilitychange",r),t.addEventListener?.("online",e),()=>{n?.removeEventListener("visibilitychange",r),t.removeEventListener?.("online",e)}}function Tr(e,t,n,r){let o=r.revokeAll===!0,a=new WebSocket(t,Re),s="opening",i,u=65536,b,k,M=0,C=Wn(e.tabs,r.address,r.siblingGraceMs),N,_,O=new Promise((d,S)=>{N=d,_=S});O.catch(()=>{});let q=setTimeout(()=>{h(de("The relay did not answer in time.","network"))},Un),B=Ie(e,"relay"),f=ke({...B,server:{...e.server,icons:e.server.icons??be()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>b}),y=Be(e.registry,B.tools,()=>f.toolsChanged());function g(d){if(a.readyState!==WebSocket.OPEN)return!1;try{return a.send(JSON.stringify(d)),!0}catch{return!1}}function x(){if(M<=0)return;clearTimeout(k),k=setTimeout(()=>{i??="heartbeat",R(4003);try{a.close()}catch{}},M*2.5)}function h(d){if(s!=="opening")return;R(0),_(d);try{a.close()}catch{}}function R(d){if(s==="closed")return;let S=s==="ready";if(s="closed",clearTimeout(q),clearTimeout(k),y(),A.close(),f.close(),S){let H=i??Rt[d]??(d===1006?"network":"closed");if(e.closed(H,d),H==="replaced"){C.heard().then((z)=>{C.close(),e.replaced({sibling:z})});return}}C.close()}let A=Ve({handler:f,send:g,maxChunk:()=>u,error:(d)=>e.error(d)});function E(d){if(s==="opening"){if(d.type==="session"){let S=Vn(d.limits.maxMessageBytes);if(S===void 0){h(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Bn}.`,"policy"));return}if(o&&d.grants.length>0){h(de("The relay did not revoke the address's grants (it needs tab-mcp 0.5 or later).","policy"));return}u=S,b=d.limits.maxBodyBytes,s="ready",clearTimeout(q),M=d.limits.heartbeatMs,x(),C.claimed(),N(e.sessionStarted(d))}else if(d.type==="error")h(de(`The relay refused the connection: ${d.message||d.code}`,d.code==="rate_limited"?"rate_limited":"policy"));else if(d.type==="bye")h(de(`The relay ended the connection: ${d.reason}`,It[d.reason]??"closed"));return}if(s!=="ready")return;switch(d.type){case"ping":x(),g({type:"pong",t:d.t});return;case"http.request":A.request(d);return;case"http.cancel":A.cancel(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"pairing.open":e.pairingOpen(d.expiresAt);return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":e.grantRemoved(d.grantId);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(i=It[d.reason]??"closed",i==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}if(d.code==="unknown_id"&&d.for==="grant.revoke"&&typeof d.grantId==="string")e.grantRemoved(d.grantId);e.error(Object.assign(Error(`Relay error ${d.code}: ${d.message}`),{code:d.code},typeof d.for==="string"?{for:d.for}:{},typeof d.grantId==="string"?{grantId:d.grantId}:{}));return;case"session":return}}return a.addEventListener("open",()=>{if(a.protocol!==""&&a.protocol!==Re){h(de(`The relay speaks ${a.protocol}, not ${Re}.`,"policy"));return}g({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...o?{revokeAll:!0}:{}})}),a.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let S=vt(d.data);if(S===void 0)return;if(s==="ready")x();E(S)}),a.addEventListener("close",(d)=>{if(s==="opening"){R(d.code);let S=d.code===1006||d.code===1002;_(de(S?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${d.code}${d.reason?`: ${d.reason}`:""}).`,Rt[d.code]??(S?"network":"closed")));return}R(d.code)}),{ready:O,send:g,close(d){if(s==="closed")return;if(s==="opening"){h(new DOMException("The connection was cancelled","AbortError"));return}i=d,g({type:"bye",reason:"user"}),R(1000);try{a.close(1000,"bye")}catch{}}}}export{Bn as MIN_MESSAGE_BYTES,Gn as SIBLING_WINDOW_MS,Jn as addressIdOf,xr as answer,$r as callFromWebMcp,Vn as chunkSize,bn as compileRegistry,vr as onWake,Tr as openConnection,Ue as pieces,zn as servePort};
|
|
15
|
+
|
|
16
|
+
//# debugId=EE4691710649381E64756E2164756E21
|
|
17
|
+
//# sourceMappingURL=connection-vxpnd3ex.min.js.map
|