@ractive-ch/tab-mcp-client 0.20.0 → 0.21.0-rc.2
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 +76 -0
- package/README.md +156 -58
- package/cdn/confirm-xgm1ymd0.min.js +4 -0
- package/cdn/confirm-xgm1ymd0.min.js.map +10 -0
- package/cdn/{connect-my0pbqd7.min.js → connect-3reh9k1f.min.js} +4 -4
- package/cdn/{connect-my0pbqd7.min.js.map → connect-3reh9k1f.min.js.map} +4 -4
- package/cdn/connection-cxgns38v.min.js +17 -0
- package/cdn/{connection-5x2krvfs.min.js.map → connection-cxgns38v.min.js.map} +5 -5
- package/cdn/strings.min.js +1 -1
- package/cdn/tab-mcp-client-gdj1e1wh.min.js +5 -0
- package/cdn/tab-mcp-client-gdj1e1wh.min.js.map +11 -0
- package/cdn/{tab-mcp-client-8r6h3wza.min.js → tab-mcp-client-yjcmhpdf.min.js} +5 -5
- package/cdn/tab-mcp-client-yjcmhpdf.min.js.map +11 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +4 -4
- package/cdn/webmcp-8xby3trn.min.js +4 -0
- package/cdn/{webmcp-ny13npet.min.js.map → webmcp-8xby3trn.min.js.map} +3 -3
- package/command.d.ts +9 -3
- package/{confirm-hymzwx3b.js → confirm-7de6dvpb.js} +11 -6
- package/confirm-7de6dvpb.js.map +10 -0
- package/confirm.d.ts +10 -5
- package/{connect-fhtjdmf3.js → connect-bc628ax6.js} +4 -4
- package/{connection-krd3ncrn.js → connection-arq7qm7b.js} +26 -11
- package/connection-arq7qm7b.js.map +16 -0
- package/connection.d.ts +8 -3
- package/dialog.d.ts +2 -2
- package/{index-7qqhn3zv.js → index-bt1rkngm.js} +3 -5
- package/index-bt1rkngm.js.map +10 -0
- package/{index-00p8b969.js → index-erm4h3sn.js} +2 -3
- package/index-erm4h3sn.js.map +11 -0
- package/{index-1tssct09.js → index-xx4gmtk5.js} +6 -4
- package/index-xx4gmtk5.js.map +11 -0
- package/index.js +15 -8
- package/index.js.map +4 -4
- package/internal.d.ts +7 -3
- package/mcp.d.ts +12 -5
- package/package.json +1 -1
- package/react.js +9 -5
- package/react.js.map +3 -3
- package/secret.d.ts +2 -1
- package/setup.d.ts +5 -5
- package/setup.js +2 -2
- package/skill/SKILL.md +476 -0
- package/skill/references/react.md +59 -0
- package/skill/references/sign-in.md +28 -0
- package/strings.d.ts +0 -1
- package/strings.js +1 -1
- package/tab-mcp.d.ts +2 -2
- package/types.d.ts +40 -18
- package/{webmcp-acj1tef8.js → webmcp-gw6rrbnh.js} +24 -3
- package/{webmcp-acj1tef8.js.map → webmcp-gw6rrbnh.js.map} +3 -3
- package/webmcp.d.ts +11 -4
- package/cdn/confirm-ba3dkf9p.min.js +0 -4
- package/cdn/confirm-ba3dkf9p.min.js.map +0 -10
- package/cdn/connection-5x2krvfs.min.js +0 -17
- package/cdn/tab-mcp-client-8r6h3wza.min.js.map +0 -11
- package/cdn/tab-mcp-client-nnxcwrxp.min.js +0 -5
- package/cdn/tab-mcp-client-nnxcwrxp.min.js.map +0 -11
- package/cdn/webmcp-ny13npet.min.js +0 -4
- package/confirm-hymzwx3b.js.map +0 -10
- package/connection-krd3ncrn.js.map +0 -16
- package/index-00p8b969.js.map +0 -11
- package/index-1tssct09.js.map +0 -11
- package/index-7qqhn3zv.js.map +0 -10
- /package/{connect-fhtjdmf3.js.map → connect-bc628ax6.js.map} +0 -0
package/types.d.ts
CHANGED
|
@@ -41,9 +41,14 @@ export interface RelayClient {
|
|
|
41
41
|
host: string;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* (`webmcp: true`)
|
|
46
|
-
*
|
|
44
|
+
* Whatever calls a mirrored tool through the browser's WebMCP
|
|
45
|
+
* (`webmcp: true`): an agent in the browser, which may drive the tab,
|
|
46
|
+
* another extension that passes on an AI app's calls, or a document of an
|
|
47
|
+
* origin in the tool's `exposedTo`. Not paired and not identified: nothing
|
|
48
|
+
* more is known, and the page cannot tell these apart, unless the tab-mcp
|
|
49
|
+
* browser extension vouched for the call (DEC-207). The library never shows
|
|
50
|
+
* an unvouched call its confirmation (DEC-215): only the page's own
|
|
51
|
+
* `onConfirm` decides, in code.
|
|
47
52
|
*/
|
|
48
53
|
export interface WebMcpClient {
|
|
49
54
|
kind: "webmcp";
|
|
@@ -129,8 +134,8 @@ export interface ServeOptions {
|
|
|
129
134
|
* `onConfirm`; a throw is a refusal. `request.signal` aborts when the call
|
|
130
135
|
* is cancelled, times out or the serve closes. The answer must come from
|
|
131
136
|
* the user: never let the other end of the port answer it, since that is
|
|
132
|
-
* the caller that wants the tool to run. Calls through the relay
|
|
133
|
-
* WebMCP
|
|
137
|
+
* the caller that wants the tool to run. Calls through the relay keep the
|
|
138
|
+
* page's `onConfirm` or dialog, WebMCP calls the page's `onConfirm`.
|
|
134
139
|
*/
|
|
135
140
|
onConfirm?: ConfirmHandler;
|
|
136
141
|
/**
|
|
@@ -199,18 +204,22 @@ export interface RegisterToolOptions {
|
|
|
199
204
|
signal?: AbortSignal;
|
|
200
205
|
/**
|
|
201
206
|
* Which callers see the tool: `"relay"` (AI apps through the relay),
|
|
202
|
-
* `"local"` (this site's own assistant over `serve`), `"webmcp"` (
|
|
203
|
-
*
|
|
207
|
+
* `"local"` (this site's own assistant over `serve`), `"webmcp"` (whatever
|
|
208
|
+
* calls through the browser's WebMCP, with `TabMcpOptions.webmcp` on). Others neither list nor
|
|
204
209
|
* call it: for them it does not exist. By default all of them, tools that
|
|
205
|
-
* ask included (DEC-209)
|
|
206
|
-
*
|
|
207
|
-
*
|
|
210
|
+
* ask included (DEC-209). Leave a caller out for privacy or identity, e.g.
|
|
211
|
+
* `["local"]` for data the site's own assistant may read but an AI app
|
|
212
|
+
* through the relay may not, or `["relay", "local"]` for a tool no WebMCP
|
|
213
|
+
* caller may run unasked: the library does not ask an unvouched WebMCP
|
|
214
|
+
* call (DEC-215).
|
|
208
215
|
*/
|
|
209
216
|
callers?: readonly ToolCaller[];
|
|
210
217
|
/**
|
|
211
218
|
* WebMCP's origins of other documents in this tab that may see the tool:
|
|
212
219
|
* passed on to the native `registerTool` of a mirrored tool, which checks
|
|
213
|
-
* it (an invalid list only warns).
|
|
220
|
+
* it (an invalid list only warns). A document of a listed origin can run
|
|
221
|
+
* the tool, and the library does not ask it (DEC-215): only `onConfirm`
|
|
222
|
+
* stops it. No effect on AI apps.
|
|
214
223
|
*/
|
|
215
224
|
exposedTo?: string[];
|
|
216
225
|
}
|
|
@@ -335,7 +344,17 @@ export interface TabMcpOptions {
|
|
|
335
344
|
* to open when the page is not open; at most 64 characters.
|
|
336
345
|
*/
|
|
337
346
|
appName?: string;
|
|
338
|
-
/**
|
|
347
|
+
/**
|
|
348
|
+
* Approves consequential tool calls; default: a dialog in the page. It
|
|
349
|
+
* gets every such call of an AI app through the relay and every WebMCP
|
|
350
|
+
* call, not one the tab-mcp browser extension vouched for. A WebMCP call is
|
|
351
|
+
* never shown the library's dialog (DEC-215): it may come from an agent
|
|
352
|
+
* that drives the tab and can click whatever the page shows, this
|
|
353
|
+
* handler's UI too, from another extension, or from an `exposedTo`
|
|
354
|
+
* origin. For it, decide in code (`request.client.kind` is `"webmcp"`),
|
|
355
|
+
* or keep the tool from WebMCP with `callers`; without a handler its call
|
|
356
|
+
* runs.
|
|
357
|
+
*/
|
|
339
358
|
onConfirm?: ConfirmHandler;
|
|
340
359
|
/**
|
|
341
360
|
* Let the user allow tools in the library's dialogs, so that their calls
|
|
@@ -391,9 +410,12 @@ export interface TabMcpOptions {
|
|
|
391
410
|
* (`document.modelContext.registerTool()`), where it has it, so that agents
|
|
392
411
|
* in the browser can call them, without pairing. Off by default. Every
|
|
393
412
|
* tool goes there unless its `callers` leave `"webmcp"` out, tools that ask
|
|
394
|
-
* included
|
|
395
|
-
* too
|
|
396
|
-
*
|
|
413
|
+
* included, marked `consequentialHint` (a tool marked only
|
|
414
|
+
* `destructiveHint` too: WebMCP has no `destructiveHint`; DEC-209), so
|
|
415
|
+
* that a caller that heeds it asks its user. The library shows an
|
|
416
|
+
* unvouched WebMCP call no question (DEC-215): it runs unless `onConfirm`
|
|
417
|
+
* refuses it. A
|
|
418
|
+
* failed native registration only warns in the console.
|
|
397
419
|
*
|
|
398
420
|
* With it, the page and the tab-mcp browser extension know of each other
|
|
399
421
|
* (DEC-207): `extension` says which AI apps reach the page through it,
|
|
@@ -403,9 +425,9 @@ export interface TabMcpOptions {
|
|
|
403
425
|
webmcp?: boolean;
|
|
404
426
|
/**
|
|
405
427
|
* With `webmcp: true`: a WebMCP call the tab-mcp browser extension vouches
|
|
406
|
-
* for runs without
|
|
407
|
-
*
|
|
408
|
-
* `
|
|
428
|
+
* for runs without `onConfirm` (the user allowed exactly that call there,
|
|
429
|
+
* a moment before). On by default; `false` treats it as any other WebMCP
|
|
430
|
+
* call: `onConfirm` decides, without one it runs (DEC-215). `extension`
|
|
409
431
|
* is reported either way.
|
|
410
432
|
*/
|
|
411
433
|
trustExtension?: boolean;
|
|
@@ -172,6 +172,24 @@ function mirror(registry, context, call, mcp, app, options, version) {
|
|
|
172
172
|
}
|
|
173
173
|
const mirrors = new Map;
|
|
174
174
|
const warned = new Set;
|
|
175
|
+
const unasked = new Set;
|
|
176
|
+
const warnUnasked = (tool, asks) => {
|
|
177
|
+
try {
|
|
178
|
+
const ask = options.onConfirm;
|
|
179
|
+
const page = globalThis.document?.location?.origin;
|
|
180
|
+
const others = (Array.isArray(tool.exposedTo) ? tool.exposedTo : []).filter((entry) => {
|
|
181
|
+
try {
|
|
182
|
+
return new URL(String(entry)).origin !== page;
|
|
183
|
+
} catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
if (asks !== true || others.length === 0 || ask && ask.own !== false || unasked.has(tool.name))
|
|
188
|
+
return;
|
|
189
|
+
unasked.add(tool.name);
|
|
190
|
+
console.warn(`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(", ")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`);
|
|
191
|
+
} catch {}
|
|
192
|
+
};
|
|
175
193
|
const sync = () => {
|
|
176
194
|
for (const [tool, controller] of mirrors) {
|
|
177
195
|
if (registry.get(tool.name) === tool)
|
|
@@ -200,7 +218,10 @@ function mirror(registry, context, call, mcp, app, options, version) {
|
|
|
200
218
|
outputSchema: tool.outputSchema,
|
|
201
219
|
annotations: hints,
|
|
202
220
|
execute: (input, options) => call(tool, input, options?.signal, handshake?.take(tool, input))
|
|
203
|
-
}, { signal, exposedTo: tool.exposedTo })).
|
|
221
|
+
}, { signal, exposedTo: tool.exposedTo })).then(() => {
|
|
222
|
+
if (!signal.aborted)
|
|
223
|
+
warnUnasked(tool, consequential);
|
|
224
|
+
}).catch((error) => {
|
|
204
225
|
if (signal.aborted)
|
|
205
226
|
return;
|
|
206
227
|
if (warned.has(tool.name))
|
|
@@ -217,5 +238,5 @@ export {
|
|
|
217
238
|
mirror
|
|
218
239
|
};
|
|
219
240
|
|
|
220
|
-
//# debugId=
|
|
221
|
-
//# sourceMappingURL=webmcp-
|
|
241
|
+
//# debugId=CA877CC5C132F0E764756E2164756E21
|
|
242
|
+
//# sourceMappingURL=webmcp-gw6rrbnh.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/handshake.ts", "../src/webmcp.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * The page's side of the handshake with the tab-mcp browser extension\n * (DEC-207), in the WebMCP mirror's chunk: only a page that offers its tools\n * to agents in the browser (`webmcp: true`) takes part.\n *\n * Plain DOM events on `document`, each with a JSON string as `detail`\n * (objects do not cross between a content script's world and the page's in\n * every browser): `tab-mcp-page` from the page, `tab-mcp-extension` from\n * the extension. Every message has `v: 1` and a `type`; a message of\n * another version, an unknown type or a malformed one is ignored, and so\n * are unknown fields.\n *\n * - The page announces itself (`hello`: the library's version, the app id,\n * the AI apps connected to it directly) when it starts, again (`update`)\n * when those apps change, and answers the extension's `hello` with an\n * `update`. It marks `<html data-tab-mcp-handshake>`, so that an\n * extension that starts later (its content script comes at\n * `document_idle`, or with a click) knows it may speak without having\n * heard the `hello`.\n * - The extension says what it is, whether it serves the page now and\n * which AI apps are connected to it (`hello`, `update`), and, right before\n * it runs a page tool the user allowed there, `vouch`: the tool, the exact\n * arguments, a nonce and the AI app; once that call ended or failed,\n * `withdraw` with the nonce, and a vouch still unused is dropped.\n * - Each side cuts the other's list of AI apps to 64 and sends no more.\n *\n * No proof of who sent what: anything that could fake the extension runs in\n * the page already, where it could skip any check. A convenience between\n * two parts the user trusts, not a security boundary.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension, Grant } from \"./types.ts\";\n\n/** From the page to the extension. */\nexport const PAGE_EVENT = \"tab-mcp-page\";\n/** From the extension to the page. */\nexport const EXTENSION_EVENT = \"tab-mcp-extension\";\n/** On `<html>`: this page takes part (for an extension that starts later). */\nexport const MARK = \"data-tab-mcp-handshake\";\n/** A vouch is kept this long (milliseconds), then dropped unused. */\nexport const VOUCH_MS = 2_000;\n/** At most this many vouches wait; beyond, the oldest goes. */\nconst MAX_VOUCHES = 16;\n/** Texts from the extension are taken up to these lengths, apps up to this count either way. */\nconst MAX_TEXT = 256;\nconst MAX_APPS = 64;\n\n/** One `TabMcp` of the page, as the handshake sees it. */\nexport interface HandshakePage {\n\t/** The library's version. */\n\treadonly version: string;\n\treadonly app: string;\n\treadonly registry: ToolRegistry;\n\t/** Vouches are taken for its tools (`trustExtension`). */\n\treadonly trust: boolean;\n\t/** The `TabMcp`: its `grants` and `grantschange`. */\n\treadonly mcp: EventTarget & { readonly grants: readonly Grant[] };\n\t/** The extension's state changed. */\n\tset(extension: BrowserExtension | undefined): void;\n}\n\n/** The AI app a vouched call came from. */\nexport interface VouchedBy {\n\tname: string;\n\thost: string;\n}\n\ninterface Vouch {\n\ttool: RegisteredTool;\n\t/** The arguments, canonical (`canonical`). */\n\targs: string;\n\tnonce: string;\n\tapp: VouchedBy;\n\tat: number;\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === \"string\" && value.length <= MAX_TEXT;\n\n/** An AI app as the extension names it; `undefined` if it is malformed. */\nfunction appOf(value: unknown): VouchedBy | undefined {\n\treturn isObject(value) && text(value[\"name\"]) && text(value[\"host\"])\n\t\t? { name: value[\"name\"], host: value[\"host\"] }\n\t\t: undefined;\n}\n\n/**\n * `value` as JSON with the keys of every object sorted: two argument\n * objects are equal when their canonical forms are.\n */\nexport function canonical(value: unknown): string {\n\treturn (\n\t\tJSON.stringify(value, (_key, v: unknown) =>\n\t\t\tisObject(v)\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n\t\t\t\t\t)\n\t\t\t\t: v,\n\t\t) ?? \"\"\n\t);\n}\n\n/** Monotonic milliseconds: a vouch's age must not follow the wall clock. */\nconst now = () => performance.now();\n\nclass Handshake {\n\treadonly #doc: Document;\n\treadonly #pages: HandshakePage[] = [];\n\t#extension: BrowserExtension | undefined;\n\t#vouches: Vouch[] = [];\n\n\tconstructor(doc: Document) {\n\t\tthis.#doc = doc;\n\t\tdoc.addEventListener(EXTENSION_EVENT, (event) =>\n\t\t\tthis.#heard((event as CustomEvent).detail),\n\t\t);\n\t\tdoc.documentElement?.setAttribute(MARK, \"1\");\n\t}\n\n\tjoin(page: HandshakePage): void {\n\t\tthis.#pages.push(page);\n\t\tif (this.#extension !== undefined) page.set(this.#extension);\n\t\tpage.mcp.addEventListener(\"grantschange\", () => this.#say(page, \"update\"));\n\t\tthis.#say(page, \"hello\");\n\t}\n\n\t#say(page: HandshakePage, type: \"hello\" | \"update\"): void {\n\t\t// The document's own `CustomEvent`: a document may take only events\n\t\t// of its realm.\n\t\tconst Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;\n\t\tthis.#doc.dispatchEvent(\n\t\t\tnew Custom(PAGE_EVENT, {\n\t\t\t\tdetail: JSON.stringify({\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttype,\n\t\t\t\t\tlibrary: page.version,\n\t\t\t\t\tapp: page.app,\n\t\t\t\t\t// Capped as the extension cuts what it hears: more would\n\t\t\t\t\t// not be heard anyway.\n\t\t\t\t\tapps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({\n\t\t\t\t\t\tname: g.client.name,\n\t\t\t\t\t\thost: g.client.host,\n\t\t\t\t\t})),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#heard(detail: unknown): void {\n\t\tlet m: unknown;\n\t\ttry {\n\t\t\tm = typeof detail === \"string\" ? JSON.parse(detail) : undefined;\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isObject(m) || m[\"v\"] !== 1) return;\n\t\tif (m[\"type\"] === \"vouch\") this.#vouch(m);\n\t\t// The call it was for ended or never reached the page: an unused vouch\n\t\t// must not wait its 2 s for another caller.\n\t\telse if (m[\"type\"] === \"withdraw\")\n\t\t\tthis.#vouches = this.#vouches.filter((v) => v.nonce !== m[\"nonce\"]);\n\t\telse if (m[\"type\"] === \"hello\" || m[\"type\"] === \"update\") {\n\t\t\tconst extension = extensionOf(m);\n\t\t\tif (extension === null) return;\n\t\t\tif (canonical(extension) !== canonical(this.#extension)) {\n\t\t\t\tthis.#extension = extension;\n\t\t\t\tfor (const page of this.#pages) page.set(extension);\n\t\t\t}\n\t\t\tif (m[\"type\"] === \"hello\")\n\t\t\t\tfor (const page of this.#pages) this.#say(page, \"update\");\n\t\t}\n\t}\n\n\t/**\n\t * A vouch, kept for the tool registered under its name now, by a page\n\t * that takes vouches: a tool registered anew after this does not get it.\n\t */\n\t#vouch(m: Record<string, unknown>): void {\n\t\tconst app = appOf(m[\"app\"]);\n\t\tconst name = m[\"tool\"];\n\t\tconst nonce = m[\"nonce\"];\n\t\tif (\n\t\t\tapp === undefined ||\n\t\t\ttypeof name !== \"string\" ||\n\t\t\ttypeof nonce !== \"string\" ||\n\t\t\t!isObject(m[\"arguments\"])\n\t\t)\n\t\t\treturn;\n\t\tthis.#drop();\n\t\t// The same vouch heard twice counts once.\n\t\tif (this.#vouches.some((v) => v.nonce === nonce)) return;\n\t\tfor (const page of this.#pages) {\n\t\t\tconst tool = page.trust ? page.registry.get(name) : undefined;\n\t\t\tif (tool === undefined) continue;\n\t\t\tthis.#vouches.push({\n\t\t\t\ttool,\n\t\t\t\targs: canonical(m[\"arguments\"]),\n\t\t\t\tnonce,\n\t\t\t\tapp,\n\t\t\t\tat: now(),\n\t\t\t});\n\t\t\tif (this.#vouches.length > MAX_VOUCHES) this.#vouches.shift();\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Forget the vouches older than `VOUCH_MS`. */\n\t#drop(): void {\n\t\tconst t = now();\n\t\tthis.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);\n\t}\n\n\t/**\n\t * The vouch for this call of `tool` with `input`, used up; `undefined`\n\t * if there is none (the call is asked as without the extension).\n\t */\n\ttake(tool: RegisteredTool, input: unknown): VouchedBy | undefined {\n\t\tthis.#drop();\n\t\tconst args = canonical(input);\n\t\tconst i = this.#vouches.findIndex(\n\t\t\t(v) => v.tool === tool && v.args === args,\n\t\t);\n\t\treturn i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;\n\t}\n}\n\n/**\n * The extension's state from its `hello` or `update`: `undefined` when it\n * does not serve the page now, `null` when the message is malformed.\n */\nfunction extensionOf(\n\tm: Record<string, unknown>,\n): BrowserExtension | undefined | null {\n\tif (m[\"on\"] !== true) return m[\"on\"] === false ? undefined : null;\n\tconst { name, version, apps } = m;\n\tif (!text(name) || !text(version) || !Array.isArray(apps)) return null;\n\tconst list = apps.slice(0, MAX_APPS).map(appOf);\n\tif (list.some((a) => a === undefined)) return null;\n\treturn Object.freeze({\n\t\tname,\n\t\tversion,\n\t\tapps: Object.freeze(list.map((a) => Object.freeze(a as VouchedBy))),\n\t\twhileInFront: m[\"whileInFront\"] !== false,\n\t});\n}\n\nconst handshakes = new WeakMap<Document, Handshake>();\n\n/**\n * The handshake of the page's top-level document, which `page` joins; the\n * extension speaks only to the top frame. `undefined` in a frame or\n * without a document.\n */\nexport function joinHandshake(page: HandshakePage): Handshake | undefined {\n\tconst doc = globalThis.document;\n\tif (doc === undefined || globalThis.top !== globalThis.window)\n\t\treturn undefined;\n\tlet handshake = handshakes.get(doc);\n\tif (handshake === undefined) {\n\t\thandshake = new Handshake(doc);\n\t\thandshakes.set(doc, handshake);\n\t}\n\thandshake.join(page);\n\treturn handshake;\n}\n",
|
|
6
|
-
"/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks
|
|
6
|
+
"/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.ts\";\n\n/** What the library uses of the browser's `ModelContext`. */\nexport interface ModelContext {\n\tregisterTool(\n\t\ttool: object,\n\t\toptions: { signal: AbortSignal; exposedTo: string[] | undefined },\n\t): unknown;\n}\n\n/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\n\n/** The WebMCP hints; the MCP-only ones are left out. */\nconst HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\n\n/**\n * Mirror `registry`'s tools into `context`, now and whenever the registry\n * changes: every tool, unless its `callers` leave `\"webmcp\"` out (DEC-165,\n * DEC-209). A tool that asks is marked `consequentialHint`, so that the agent\n * asks its user; MCP's `destructiveHint` counts as `consequentialHint`\n * (DEC-143). The page's `onConfirm` decides such a call, never the library's\n * dialog (DEC-215). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`, and `onConfirm` for the warning below), `version` the\n * library's. A tool that asks, mirrored with an `exposedTo` that names\n * other origins on a page without `onConfirm`, is warned about once per\n * name (`warnUnasked`): documents of those origins can run it, and the\n * library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean; onConfirm?: unknown },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; no call is vouched for.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst unasked = new Set<string>();\n\t/**\n\t * The warning about a tool that asks with `exposedTo` (DEC-215), once its\n\t * native registration succeeded (so Chrome accepted every origin), once\n\t * per name. Decided then: a handler the page removes later is not\n\t * caught. Never throws, whatever `exposedTo` holds.\n\t */\n\tconst warnUnasked = (tool: RegisteredTool, asks: boolean | undefined) => {\n\t\ttry {\n\t\t\t// React's provider always passes a handler; `own` says whether the\n\t\t\t// page gave one.\n\t\t\tconst ask = options.onConfirm as { own?: boolean } | undefined;\n\t\t\tconst page = globalThis.document?.location?.origin;\n\t\t\tconst others = (\n\t\t\t\tArray.isArray(tool.exposedTo) ? tool.exposedTo : []\n\t\t\t).filter((entry: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn new URL(String(entry)).origin !== page;\n\t\t\t\t} catch {\n\t\t\t\t\treturn false; // the browser refuses it anyway\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (\n\t\t\t\tasks !== true ||\n\t\t\t\tothers.length === 0 ||\n\t\t\t\t(ask && ask.own !== false) ||\n\t\t\t\tunasked.has(tool.name)\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tunasked.add(tool.name);\n\t\t\tconsole.warn(\n\t\t\t\t`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(\", \")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// a warning never stops the mirror\n\t\t}\n\t};\n\tconst sync = (): void => {\n\t\tfor (const [tool, controller] of mirrors) {\n\t\t\tif (registry.get(tool.name) === tool) continue;\n\t\t\tcontroller.abort();\n\t\t\tmirrors.delete(tool);\n\t\t}\n\t\tfor (const tool of registry.list()) {\n\t\t\tconst { annotations, callers } = tool;\n\t\t\tconst consequential =\n\t\t\t\tannotations.consequentialHint ?? annotations.destructiveHint;\n\t\t\t// The one place of the rule for WebMCP (the relay and a port: `toolsFor`).\n\t\t\tif (mirrors.has(tool) || !(callers?.includes(\"webmcp\") ?? true)) continue;\n\t\t\tconst controller = new AbortController();\n\t\t\tmirrors.set(tool, controller);\n\t\t\tconst hints: Record<string, boolean | undefined> = {\n\t\t\t\tconsequentialHint: consequential,\n\t\t\t};\n\t\t\tfor (const key of HINTS) hints[key] ??= annotations[key];\n\t\t\tconst { signal } = controller;\n\t\t\tPromise.resolve()\n\t\t\t\t// Not once unmirrored: whatever the browser does with an aborted\n\t\t\t\t// signal.\n\t\t\t\t.then(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\t\tcontext.registerTool(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t// WebIDL dictionaries: `undefined` is the same as left out.\n\t\t\t\t\t\t\t\ttitle: tool.title,\n\t\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t\t\t\t\t\toutputSchema: tool.outputSchema,\n\t\t\t\t\t\t\t\tannotations: hints,\n\t\t\t\t\t\t\t\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal, exposedTo: tool.exposedTo },\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (!signal.aborted) warnUnasked(tool, consequential);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // unmirrored meanwhile\n\t\t\t\t\tif (warned.has(tool.name)) return;\n\t\t\t\t\twarned.add(tool.name);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`tab-mcp: ${tool.name} is not offered through WebMCP:`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t};\n\tregistry.onChange(sync);\n\tsync();\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";AAmCO,IAAM,aAAa;AAEnB,IAAM,kBAAkB;AAExB,IAAM,OAAO;AAEb,IAAM,WAAW;AAExB,IAAM,cAAc;AAEpB,IAAM,WAAW;AACjB,IAAM,WAAW;AA+BjB,IAAM,WAAW,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,IAAM,OAAO,CAAC,UACb,OAAO,UAAU,YAAY,MAAM,UAAU;AAG9C,SAAS,KAAK,CAAC,OAAuC;AAAA,EACrD,OAAO,SAAS,KAAK,KAAK,KAAK,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO,IAChE,EAAE,MAAM,MAAM,SAAS,MAAM,MAAM,QAAQ,IAC3C;AAAA;AAOG,SAAS,SAAS,CAAC,OAAwB;AAAA,EACjD,OACC,KAAK,UAAU,OAAO,CAAC,MAAM,MAC5B,SAAS,CAAC,IACP,OAAO,YACP,OAAO,QAAQ,CAAC,EAAE,KAAK,EAAE,KAA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I,OAAO;AAAA,UAAS;AAAA,QACpB,IAAI,OAAO,IAAI,KAAK,IAAI;AAAA,UAAG;AAAA,QAC3B,OAAO,IAAI,KAAK,IAAI;AAAA,QACpB,QAAQ,KACP,YAAY,KAAK,uCACjB,KACD;AAAA,OACA;AAAA,IACH;AAAA;AAAA,EAED,SAAS,SAAS,IAAI;AAAA,EACtB,KAAK;AAAA;",
|
|
9
|
+
"debugId": "CA877CC5C132F0E764756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/webmcp.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `AbortController`, aborted when the tool leaves the registry. A chunk of
|
|
6
6
|
* its own (DEC-171), loaded by a `TabMcp` whose constructor found native
|
|
7
7
|
* WebMCP (`nativeContext` in the core); a call loads the connection chunk,
|
|
8
|
-
* which checks
|
|
8
|
+
* which checks and runs it. The handshake with the tab-mcp browser
|
|
9
9
|
* extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors
|
|
10
10
|
* takes part.
|
|
11
11
|
*/
|
|
@@ -26,15 +26,22 @@ export type WebMcpCall = (tool: RegisteredTool, input: unknown, signal: unknown,
|
|
|
26
26
|
/**
|
|
27
27
|
* Mirror `registry`'s tools into `context`, now and whenever the registry
|
|
28
28
|
* changes: every tool, unless its `callers` leave `"webmcp"` out (DEC-165,
|
|
29
|
-
* DEC-209). A tool that asks
|
|
30
|
-
* `destructiveHint` counts as `consequentialHint`
|
|
29
|
+
* DEC-209). A tool that asks is marked `consequentialHint`, so that the agent
|
|
30
|
+
* asks its user; MCP's `destructiveHint` counts as `consequentialHint`
|
|
31
|
+
* (DEC-143). The page's `onConfirm` decides such a call, never the library's
|
|
32
|
+
* dialog (DEC-215). Every failure of the native `registerTool()`
|
|
31
33
|
* stays here: warned once per name, the tool still offered through the relay.
|
|
32
34
|
* The page joins the handshake with the tab-mcp browser extension: `mcp`
|
|
33
35
|
* is its `TabMcp`, `app` its app id, `options` its options
|
|
34
|
-
* (`trustExtension
|
|
36
|
+
* (`trustExtension`, and `onConfirm` for the warning below), `version` the
|
|
37
|
+
* library's. A tool that asks, mirrored with an `exposedTo` that names
|
|
38
|
+
* other origins on a page without `onConfirm`, is warned about once per
|
|
39
|
+
* name (`warnUnasked`): documents of those origins can run it, and the
|
|
40
|
+
* library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined
|
|
35
41
|
* here on the instance (the core only declares it, for its bytes), and
|
|
36
42
|
* `extensionchange` is sent here.
|
|
37
43
|
*/
|
|
38
44
|
export declare function mirror(registry: ToolRegistry, context: ModelContext, call: WebMcpCall, mcp: HandshakePage["mcp"], app: string, options: {
|
|
39
45
|
trustExtension?: boolean;
|
|
46
|
+
onConfirm?: unknown;
|
|
40
47
|
}, version: string): void;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{u}from"./tab-mcp-client-nnxcwrxp.min.js";import{a,r,e,t,s,d,l}from"./tab-mcp-client-8r6h3wza.min.js";import{o}from"./tab-mcp-client-q758jr4g.min.js";function ee(f){try{return s(JSON.stringify(f,null,2))}catch{return}}var ne=750,te=500,J=new WeakMap;function K(f,n,b={}){if(f.signal.aborted)return Promise.resolve("deny");let g=J.get(n);if(g===void 0)g={shown:!1,waiting:[]},J.set(n,g);let c=g,i=()=>{let h=c.waiting.shift();c.shown=h!==void 0,h?.(),c.changed?.()},L=()=>{try{return ie(f,n,b,c,i)}catch(h){return i(),Promise.reject(h)}};if(!c.shown)return c.shown=!0,L();return new Promise((h)=>{let v=()=>{if(f.signal.removeEventListener("abort",E),b.allowedNow?.()===!0){h("allow"),i();return}h(L())},E=()=>{c.waiting.splice(c.waiting.indexOf(v),1),c.changed?.(),h("deny")};f.signal.addEventListener("abort",E,{once:!0}),c.waiting.push(v),c.changed?.()})}function ie(f,n,b,g,c){let i=b.strings??a(void 0),L=b.allowDelayMs??ne,h=f.tool.title??f.tool.name,v=d(f.client,i),E={tool:h,client:v},{dialog:m,id:C}=l(n,"tab-mcp-confirm",i,...r(n,i.confirmTitle,E)),I=e(n,"p",{className:"tab-mcp-waiting"}),S=()=>{let p=g.waiting.length;I.hidden=p===0,I.textContent=u(i.waiting,p,i)};g.changed=S,S();let z=t(n,i.deny,()=>m.close("deny"),"tab-mcp-deny","primary"),B=(p,j,R)=>{let A=t(n,p,()=>{if(!A.disabled)m.close(j)},R);return A},k=[B(i.allow,"allow","tab-mcp-allow")],W=[],Q=b.alwaysAllow;if(Q===!0||Q==="until-reload"){let p=Q===!0;k.unshift(B(p?i.alwaysAllow:i.allowUntilReload,"always","tab-mcp-always")),W.push(e(n,"p",{className:"tab-mcp-always-note"},...r(n,p?i.alwaysAllowNote:i.allowUntilReloadNote,E)))}let Y=e(n,"div",{className:"tab-mcp-actions"},z,...k.flatMap((p)=>[" ",p])),N=!1,U=!1,M=()=>{for(let p of k)p.disabled=!(N&&U)};M();let T=ee(f.arguments),y=e(n,"pre",{className:"tab-mcp-arguments",id:`${C}-arguments`,text:T??i.argumentsHidden});if(T===void 0)for(let p of[...k,...W])p.hidden=!0;y.dir="ltr",y.style.setProperty("white-space","pre-wrap"),y.style.setProperty("overflow-wrap","anywhere"),y.style.setProperty("max-height","var(--tab-mcp-arguments-height, min(50vh, 24rem))"),y.style.setProperty("overflow","auto"),y.hidden=Object.keys(f.arguments).length===0;let O=e(n,"p",{className:"tab-mcp-scroll-note",text:i.scrollToAllow});O.hidden=!0;let _=e(n,"p",{id:`${C}-who`},...r(n,i.confirmWho,E));m.setAttribute("aria-describedby",T!==void 0&&!y.hidden&&T.length<=te?`${_.id} ${y.id}`:_.id),m.append(_,e(n,"p",{className:"tab-mcp-description",text:f.tool.description}),y,O,Y,...W,I),n.body.append(m);let x=n.defaultView;return new Promise((p,j)=>{let R=()=>m.close("deny");f.signal.addEventListener("abort",R,{once:!0});let A,P,F=()=>{if(P!==void 0&&n.title===P.shown)n.title=P.page;P=void 0},X=()=>{if(n.visibilityState!=="hidden")F();else if(P===void 0)P={page:n.title,shown:`${i.titlePrefix}${n.title}`},n.title=P.shown},D=(w)=>{if(w?.type==="close"&&w.target===m)return;if(X(),clearTimeout(A),A=void 0,N=!1,M(),w?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;A=setTimeout(()=>{N=!0,M()},L)},H=()=>{if(U)return;if(y.scrollTop+y.clientHeight<y.scrollHeight-2){O.hidden=!1,y.tabIndex=0;return}U=!0,O.hidden=!0,M()},V=(w)=>{if(N)return;let q=w.target?.localName==="button";if(w.key==="Escape"||q&&(w.key==="Enter"||w.key===" "))w.preventDefault()},Z=(w)=>{if(!N)w.preventDefault()};n.addEventListener("visibilitychange",D),n.addEventListener("close",D,!0),x?.addEventListener("focus",D),x?.addEventListener("blur",D),x?.addEventListener("resize",H),y.addEventListener("scroll",H),m.addEventListener("keydown",V),m.addEventListener("keyup",V),m.addEventListener("cancel",Z);let G=()=>{if(clearTimeout(A),F(),n.removeEventListener("visibilitychange",D),n.removeEventListener("close",D,!0),x?.removeEventListener("focus",D),x?.removeEventListener("blur",D),x?.removeEventListener("resize",H),f.signal.removeEventListener("abort",R),m.remove(),g.changed===S)g.changed=void 0};m.addEventListener("close",()=>{let w=m.returnValue;G(),p(w==="allow"||w==="always"?w:"deny"),c()},{once:!0});try{m.showModal()}catch(w){G(),j(w),c();return}z.focus(),D(),H()})}function ae(f,n,b,g={}){let{client:c}=n,i=a(g.ui),{allowDelayMs:L}=g;if(c.kind!=="relay")return K(n,b,{strings:i,allowDelayMs:L}).then((C)=>C==="allow");let{grantId:h}=c,v=o(f),E=()=>v.allows(h,n.tool);if(E())return Promise.resolve(!0);let m=g.alwaysAllow??v.offered;return K(n,b,{strings:i,allowDelayMs:L,alwaysAllow:m!==!1&&(m===!0&&v.kept?!0:"until-reload"),allowedNow:E}).then((C)=>{if(C==="always")v.keep(h,n.tool);return C!=="deny"})}function se(f,n,b){let{client:g}=n;if(g.kind==="relay"&&o(f).allows(g.grantId,n.tool))return Promise.resolve(!0);if(b===void 0)return f.confirmInPage(n);return Promise.resolve().then(()=>b(n)).then((c)=>c==="unanswered"?c:c===!0)}export{se as confirmCall,ae as confirmInPage};
|
|
2
|
-
|
|
3
|
-
//# debugId=219E3EE7F5DA6FA064756E2164756E21
|
|
4
|
-
//# sourceMappingURL=confirm-ba3dkf9p.min.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/confirm.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * The confirmation of consequential tools, loaded on demand: a `<dialog>`\n * per call, one shown at a time per document, and Always allow (or Allow\n * until reload) for the tools a user allows (`always-allowed.ts`).\n */\n\nimport { allowedFor, type ConfirmHost } from \"./always-allowed.ts\";\nimport {\n\tbutton,\n\tclientLabel,\n\tel,\n\tfill,\n\tnewDialog,\n\tplural,\n\tstringsOf,\n\tvisible,\n} from \"./dialog.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmAnswer,\n\tConfirmHandler,\n\tConfirmRequest,\n\tDialogOptions,\n} from \"./types.ts\";\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) Invisible and\n * direction characters are shown as escapes, so the text is still JSON for\n * the same arguments; the tool gets them unchanged. `undefined` when they\n * cannot be shown, and then \"Allow once\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn visible(JSON.stringify(args, null, 2));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * How long \"Allow once\" stays disabled after the confirmation is shown, while the\n * page is visible and focused (CU 17: a constant; tests pass `allowDelayMs`).\n */\nexport const ALLOW_DELAY_MS = 750;\n\n/** The user's answer: \"always\" allows this tool for this AI app (Always allow, or until reload). */\nexport type DialogAnswer = \"allow\" | \"always\" | \"deny\";\n\n/** Arguments up to this many characters are read out with the question. */\nconst DESCRIBED_ARGUMENTS = 500;\n\n/** Options of `confirmDialog`. */\nexport interface ConfirmDialogOptions {\n\t/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */\n\tallowDelayMs?: number | undefined;\n\t/**\n\t * Offer a third button: `true` \"Always allow\" (kept until the app is\n\t * disconnected), `\"until-reload\"` \"Allow until reload\" (kept in memory).\n\t */\n\talwaysAllow?: boolean | \"until-reload\" | undefined;\n\t/** Asked when a waiting call's turn comes: `true` answers \"allow\" unseen. */\n\tallowedNow?: () => boolean;\n\tstrings?: DialogStrings;\n}\n\n/**\n * The confirmations of one document: one is shown at a time, the others\n * wait in order, so that the click that answered one cannot answer the next\n * (each starts its own delay when it is shown).\n */\ninterface ConfirmQueue {\n\tshown: boolean;\n\twaiting: (() => void)[];\n\t/** Updates the shown dialog's line about the calls that wait. */\n\tchanged?: (() => void) | undefined;\n}\n\nconst queues = new WeakMap<Document, ConfirmQueue>();\n\n/**\n * Ask whether a consequential tool may run. \"Always allow\" (or \"Allow until\n * reload\") is offered only with `alwaysAllow` (DEC-096, DEC-200); never\n * \"allow everything\": that is a deliberate act in the connect dialog, not\n * an answer to one question. One confirmation is shown at a time per\n * document; the others wait their turn, and a call cancelled while it waits\n * is never shown. \"Allow once\" and \"Always allow\" stay disabled until the\n * page has been visible and focused for 750 ms while the dialog is open and\n * is the top one, so a click meant for the page, the click that brings the\n * tab or window back, or the one that closed another dialog, cannot\n * approve; leaving the page disables them again. They also wait until the\n * arguments have been scrolled to their end. Before the delay has run out,\n * Enter or Space on a button and Escape are ignored, so typing meant for the\n * page cannot refuse either. Everything else (Don't allow, Escape, an\n * aborted call) is \"deny\". `allowedNow` is asked when a waiting call's turn\n * comes: `true` (the user allowed it meanwhile) answers \"allow\"\n * without showing it.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions = {},\n): Promise<DialogAnswer> {\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tlet queue = queues.get(doc);\n\tif (queue === undefined) {\n\t\tqueue = { shown: false, waiting: [] };\n\t\tqueues.set(doc, queue);\n\t}\n\tconst q = queue;\n\t/** The shown confirmation closed: the next one, if any. */\n\tconst next = () => {\n\t\tconst start = q.waiting.shift();\n\t\tq.shown = start !== undefined;\n\t\tstart?.();\n\t\tq.changed?.();\n\t};\n\tconst show = () => {\n\t\ttry {\n\t\t\treturn showConfirm(request, doc, options, q, next);\n\t\t} catch (error) {\n\t\t\tnext(); // not shown: the queue goes on\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t};\n\tif (!q.shown) {\n\t\tq.shown = true;\n\t\treturn show();\n\t}\n\treturn new Promise((resolve) => {\n\t\tconst start = () => {\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tif (options.allowedNow?.() === true) {\n\t\t\t\tresolve(\"allow\");\n\t\t\t\tnext();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(show());\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tq.waiting.splice(q.waiting.indexOf(start), 1);\n\t\t\tq.changed?.();\n\t\t\tresolve(\"deny\");\n\t\t};\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tq.waiting.push(start);\n\t\tq.changed?.();\n\t});\n}\n\n/** `confirmDialog` once it is this request's turn; calls `next` when it closes. */\nfunction showConfirm(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions,\n\tqueue: ConfirmQueue,\n\tnext: () => void,\n): Promise<DialogAnswer> {\n\tconst s = options.strings ?? stringsOf(undefined);\n\tconst delay = options.allowDelayMs ?? ALLOW_DELAY_MS;\n\tconst tool = request.tool.title ?? request.tool.name;\n\tconst client = clientLabel(request.client, s);\n\tconst names = { tool, client };\n\tconst { dialog, id } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-confirm\",\n\t\ts,\n\t\t...fill(doc, s.confirmTitle, names),\n\t);\n\tconst waiting = el(doc, \"p\", { className: \"tab-mcp-waiting\" });\n\tconst showWaiting = () => {\n\t\tconst n = queue.waiting.length;\n\t\twaiting.hidden = n === 0;\n\t\twaiting.textContent = plural(s.waiting, n, s);\n\t};\n\tqueue.changed = showWaiting;\n\tshowWaiting();\n\t// The safe choice is the default: focused, and the one that stands out.\n\tconst deny = button(\n\t\tdoc,\n\t\ts.deny,\n\t\t() => dialog.close(\"deny\"),\n\t\t\"tab-mcp-deny\",\n\t\t\"primary\",\n\t);\n\tconst approving = (text: string, answer: DialogAnswer, className: string) => {\n\t\tconst node = button(\n\t\t\tdoc,\n\t\t\ttext,\n\t\t\t() => {\n\t\t\t\tif (!node.disabled) dialog.close(answer);\n\t\t\t},\n\t\t\tclassName,\n\t\t);\n\t\treturn node;\n\t};\n\t// The approving buttons: Allow, and Always allow (or Allow until reload)\n\t// when the page offers it, saying how long it lasts.\n\tconst approve = [approving(s.allow, \"allow\", \"tab-mcp-allow\")];\n\tconst extra: HTMLElement[] = [];\n\tconst mode = options.alwaysAllow;\n\tif (mode === true || mode === \"until-reload\") {\n\t\tconst kept = mode === true;\n\t\t// Left of Allow: not where most platforms put the default (CU 11).\n\t\tapprove.unshift(\n\t\t\tapproving(\n\t\t\t\tkept ? s.alwaysAllow : s.allowUntilReload,\n\t\t\t\t\"always\",\n\t\t\t\t\"tab-mcp-always\",\n\t\t\t),\n\t\t);\n\t\textra.push(\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"p\",\n\t\t\t\t{ className: \"tab-mcp-always-note\" },\n\t\t\t\t...fill(doc, kept ? s.alwaysAllowNote : s.allowUntilReloadNote, names),\n\t\t\t),\n\t\t);\n\t}\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t...approve.flatMap((b) => [\" \", b]),\n\t);\n\t// Approving needs both: the delay ran out while the user saw the page\n\t// (`settled`), and the arguments were seen to their end (`seen`).\n\tlet settled = false;\n\tlet seen = false;\n\tconst enable = () => {\n\t\tfor (const b of approve) b.disabled = !(settled && seen);\n\t};\n\tenable();\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\tid: `${id}-arguments`,\n\t\ttext: shown ?? s.argumentsHidden,\n\t});\n\tif (shown === undefined) {\n\t\tfor (const node of [...approve, ...extra]) node.hidden = true;\n\t}\n\targs.dir = \"ltr\";\n\t// Inline, so the arguments stay readable in full without the stylesheet:\n\t// wrapped (also a long word, at 360 px), scrolling when long.\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"overflow-wrap\", \"anywhere\");\n\targs.style.setProperty(\n\t\t\"max-height\",\n\t\t\"var(--tab-mcp-arguments-height, min(50vh, 24rem))\",\n\t);\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\t// The caller chooses the order of the keys, so what matters may come\n\t// last: below the end of the box, the user is told, and Allow waits.\n\tconst scrollNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-scroll-note\",\n\t\ttext: s.scrollToAllow,\n\t});\n\tscrollNote.hidden = true;\n\tconst who = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ id: `${id}-who` },\n\t\t...fill(doc, s.confirmWho, names),\n\t);\n\tdialog.setAttribute(\n\t\t\"aria-describedby\",\n\t\tshown !== undefined && !args.hidden && shown.length <= DESCRIBED_ARGUMENTS\n\t\t\t? `${who.id} ${args.id}`\n\t\t\t: who.id,\n\t);\n\tdialog.append(\n\t\twho,\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tscrollNote,\n\t\tactions,\n\t\t...extra,\n\t\twaiting,\n\t);\n\tdoc.body.append(dialog);\n\tconst view = doc.defaultView;\n\treturn new Promise((resolve, reject) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t// In a hidden tab, the tab's title says that the page asks (CU 9): the\n\t\t// AI app waits meanwhile. Put back when the tab is shown or the dialog\n\t\t// closes, unless the page changed its title since.\n\t\tlet title: { page: string; shown: string } | undefined;\n\t\tconst untitle = () => {\n\t\t\tif (title !== undefined && doc.title === title.shown)\n\t\t\t\tdoc.title = title.page;\n\t\t\ttitle = undefined;\n\t\t};\n\t\tconst retitle = () => {\n\t\t\tif (doc.visibilityState !== \"hidden\") untitle();\n\t\t\telse if (title === undefined) {\n\t\t\t\ttitle = { page: doc.title, shown: `${s.titlePrefix}${doc.title}` };\n\t\t\t\tdoc.title = title.shown;\n\t\t\t}\n\t\t};\n\t\t// The delay counts only while the user can see the page: tools are\n\t\t// called while the user is in the AI app, so the dialog often opens in\n\t\t// a background tab or window. Any change starts it again from zero\n\t\t// (DEC-087), and so does another dialog of the page that closes over\n\t\t// this one.\n\t\tconst arm = (event?: Event) => {\n\t\t\tif (event?.type === \"close\" && event.target === dialog) return;\n\t\t\tretitle();\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t\tsettled = false;\n\t\t\tenable();\n\t\t\tif (\n\t\t\t\tevent?.type === \"blur\" ||\n\t\t\t\tdoc.visibilityState === \"hidden\" ||\n\t\t\t\t!doc.hasFocus()\n\t\t\t)\n\t\t\t\treturn;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tsettled = true;\n\t\t\t\tenable();\n\t\t\t}, delay);\n\t\t};\n\t\t// Scrolled to the end, or nothing to scroll (also without layout).\n\t\tconst check = () => {\n\t\t\tif (seen) return;\n\t\t\tif (args.scrollTop + args.clientHeight < args.scrollHeight - 2) {\n\t\t\t\tscrollNote.hidden = false;\n\t\t\t\targs.tabIndex = 0; // to scroll it with the keyboard\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tseen = true;\n\t\t\tscrollNote.hidden = true;\n\t\t\tenable();\n\t\t};\n\t\t// Not answered by a key before the delay has run out.\n\t\tconst guard = (event: KeyboardEvent) => {\n\t\t\tif (settled) return;\n\t\t\tconst onButton = (event.target as Element | null)?.localName === \"button\";\n\t\t\tif (\n\t\t\t\tevent.key === \"Escape\" ||\n\t\t\t\t(onButton && (event.key === \"Enter\" || event.key === \" \"))\n\t\t\t)\n\t\t\t\tevent.preventDefault();\n\t\t};\n\t\tconst onCancel = (event: Event) => {\n\t\t\tif (!settled) event.preventDefault();\n\t\t};\n\t\tdoc.addEventListener(\"visibilitychange\", arm);\n\t\tdoc.addEventListener(\"close\", arm, true); // `close` does not bubble\n\t\tview?.addEventListener(\"focus\", arm);\n\t\tview?.addEventListener(\"blur\", arm);\n\t\tview?.addEventListener(\"resize\", check);\n\t\targs.addEventListener(\"scroll\", check);\n\t\tdialog.addEventListener(\"keydown\", guard);\n\t\tdialog.addEventListener(\"keyup\", guard);\n\t\tdialog.addEventListener(\"cancel\", onCancel);\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tuntitle();\n\t\t\tdoc.removeEventListener(\"visibilitychange\", arm);\n\t\t\tdoc.removeEventListener(\"close\", arm, true);\n\t\t\tview?.removeEventListener(\"focus\", arm);\n\t\t\tview?.removeEventListener(\"blur\", arm);\n\t\t\tview?.removeEventListener(\"resize\", check);\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tdialog.remove();\n\t\t\tif (queue.changed === showWaiting) queue.changed = undefined;\n\t\t};\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tcleanup();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t\tnext();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\ttry {\n\t\t\tdialog.showModal();\n\t\t} catch (error) {\n\t\t\t// Never shown, so never closed: the queue must not wait for it.\n\t\t\tcleanup();\n\t\t\treject(error);\n\t\t\tnext();\n\t\t\treturn;\n\t\t}\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\tarm();\n\t\tcheck();\n\t});\n}\n\n/** Options of this chunk's `confirmInPage`. */\nexport interface ConfirmInPageOptions {\n\t/**\n\t * The third button, for an AI app through the relay (`kind: \"relay\"`):\n\t * `true` \"Always allow\" (kept in the `TabMcp`'s `storage`; \"Allow until\n\t * reload\" where it is kept in memory, as for a stand-in), `\"until-reload\"`\n\t * \"Allow until reload\", `false` none. Default: the `TabMcp`'s\n\t * `alwaysAllow`; none for a stand-in.\n\t */\n\talwaysAllow?: boolean | \"until-reload\" | undefined;\n\t/** Texts of the dialog, as `TabMcpOptions.ui`. */\n\tui?: DialogOptions | undefined;\n\t/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */\n\tallowDelayMs?: number | undefined;\n}\n\n/**\n * `TabMcp.confirmInPage`: the confirmation, and the tools the user allowed\n * (`always-allowed.ts`), which run unasked. Only for an AI app through the\n * relay: an agent in the browser and a served port have no identity to\n * remember an answer for (DEC-115, DEC-124).\n *\n * Code that loads this chunk itself may pass a stand-in of its own for\n * `mcp` (`ConfirmHost`: `grants`, optionally `grantschange` events). Its\n * allowances live in memory, for its grants only, until the page is\n * reloaded, and exist only where the caller offers them with\n * `options.alwaysAllow`; without it nothing is allowed and nothing is kept.\n */\nexport function confirmInPage(\n\tmcp: TabMcp | ConfirmHost,\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmInPageOptions = {},\n): Promise<boolean> {\n\tconst { client } = request;\n\tconst strings = stringsOf(options.ui);\n\tconst { allowDelayMs } = options;\n\tif (client.kind !== \"relay\")\n\t\treturn confirmDialog(request, doc, { strings, allowDelayMs }).then(\n\t\t\t(answer) => answer === \"allow\",\n\t\t);\n\tconst { grantId } = client;\n\tconst allowed = allowedFor(mcp);\n\tconst allowedNow = () => allowed.allows(grantId, request.tool);\n\tif (allowedNow()) return Promise.resolve(true);\n\tconst offer = options.alwaysAllow ?? allowed.offered;\n\t// Asked again when its turn comes: the call before it in the queue may\n\t// have been allowed meanwhile.\n\treturn confirmDialog(request, doc, {\n\t\tstrings,\n\t\tallowDelayMs,\n\t\t// \"Always\" only where it outlives a reload.\n\t\talwaysAllow:\n\t\t\toffer !== false &&\n\t\t\t(offer === true && allowed.kept ? true : \"until-reload\"),\n\t\tallowedNow,\n\t}).then((answer) => {\n\t\t// Only while the grant is still there: a revoked app gets nothing\n\t\t// (`keep` checks).\n\t\tif (answer === \"always\") allowed.keep(grantId, request.tool);\n\t\treturn answer !== \"deny\";\n\t});\n}\n\n/**\n * The core's question about a consequential call: an AI app's call that the\n * user allowed runs without asking, with the dialog and with the page's own\n * `onConfirm` alike; any other goes to `onConfirm`, else to the dialog.\n * Only AI apps through the relay have a grant to allow for.\n */\nexport function confirmCall(\n\tmcp: TabMcp,\n\trequest: ConfirmRequest,\n\tonConfirm: ConfirmHandler | undefined,\n): Promise<ConfirmAnswer> {\n\tconst { client } = request;\n\tif (\n\t\tclient.kind === \"relay\" &&\n\t\tallowedFor(mcp).allows(client.grantId, request.tool)\n\t)\n\t\treturn Promise.resolve(true);\n\tif (onConfirm === undefined) return mcp.confirmInPage(request);\n\t// Anything but true or \"unanswered\" is a refusal.\n\treturn Promise.resolve()\n\t\t.then(() => onConfirm(request))\n\t\t.then((answer) => (answer === \"unanswered\" ? answer : answer === true));\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "4JAiCA,SAAS,EAAa,CAAC,EAAmD,CACzE,GAAI,CACH,OAAO,EAAQ,KAAK,UAAU,EAAM,KAAM,CAAC,CAAC,EAC3C,KAAM,CACP,QAQK,IAAM,GAAiB,IAMxB,GAAsB,IA4BtB,EAAS,IAAI,QAoBZ,SAAS,CAAa,CAC5B,EACA,EACA,EAAgC,CAAC,EACT,CACxB,GAAI,EAAQ,OAAO,QAAS,OAAO,QAAQ,QAAQ,MAAM,EACzD,IAAI,EAAQ,EAAO,IAAI,CAAG,EAC1B,GAAI,IAAU,OACb,E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"219E3EE7F5DA6FA064756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var Ct=/^(?:\d{1,4}x\d{1,4}|any)$/;function Et(e){let{src:t,mimeType:n,sizes:r,theme:s}=e;if(typeof t!=="string")return;let i=/^https?:/i.test(t)&&t.length<=2048,o=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!i&&!o)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((v)=>String(v).toLowerCase()).filter((v)=>Ct.test(v)):[];if(u.length>0)a.sizes=u;if(s==="light"||s==="dark")a.theme=s;return a}function Se(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?Et(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 Se([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let s=n.getAttribute("sizes");if(s)r.sizes=s.trim().split(/\s+/);let i=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(i)r.theme=i[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),s=Array.isArray(t);if(r!==s)return!1;if(r){let i=e.length;if(i!==t.length)return!1;for(let o=0;o<i;o++)if(!ue(e[o],t[o]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let u of i){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function J(e){return encodeURI(St(e)).replace(/#/g,"%23")}function St(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var At=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,Ot=/^%[0-9A-Fa-f]{2}$/,Pt=/^[A-Za-z0-9._~-]$/;function Nt(e){let t="";for(let n=0;n<e.length;){let r=e[n],s=e.slice(n,n+3);if(r==="%"&&Ot.test(s)){let o=String.fromCharCode(parseInt(s.slice(1),16));t+=Pt.test(o)?o:s.toUpperCase(),n+=3;continue}let i=String.fromCodePoint(e.codePointAt(n));t+=At.test(i)?i:encodeURIComponent(i),n+=i.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?Nt(n.hash.slice(1)):"",n}var jt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},qt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Ht={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},zt=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=zt,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let i=e.$id||e.id;if(i){let o=$e(i,n);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",r==="")n=o;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(r?"#"+r:"");if(t[s]!==void 0&&t[s]!==e)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let i=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:i.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let i=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:i.href})}if(e.$anchor){let i=$e("#"+e.$anchor,n);t[i.href]=e}for(let i in e){if(Ht[i])continue;let o=`${r}/${J(i)}`,a=e[i];if(Array.isArray(a)){if(jt[i]){let u=a.length;for(let v=0;v<u;v++)Z(a[v],t,n,`${o}/${v}`)}}else if(qt[i])for(let u in a)Z(a[u],t,n,`${o}/${J(u)}`);else Z(a,t,n,o)}return t}var Dt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Bt=[0,31,28,31,30,31,30,31,31,30,31,30,31],Jt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Xe=/^(?=.{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,Ut=/^(?:[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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,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,Wt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Ft=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Kt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Yt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Xt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Zt=(e)=>{let t=e.match(Xt);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 s=r.slice(1,-1);if(/^ipv6:/i.test(s))return Qe.test(s.slice(5));return Ze.test(s)}return Xe.test(r)},Ze=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Qe=/^((([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 G(e){return e.test.bind(e)}var Ae={date:Le,time:et.bind(void 0,!0),"date-time":tn,duration:Qt,uri:on,"uri-reference":G(Ut),"uri-template":G(Vt),url:G(Gt),email:Zt,hostname:G(Xe),ipv4:G(Ze),ipv6:G(Qe),regex:an,uuid:G(Wt),"json-pointer":G(Ft),"json-pointer-uri-fragment":G(Kt),"relative-json-pointer":G(Yt)};function Lt(e){return e%4===0&&(e%100!==0||e%400===0)}function Le(e){let t=e.match(Dt);if(!t)return!1;let n=t[1],r=t[2],s=t[3];if(!n||!r||!s)return!1;let i=+n,o=+r,a=+s,u=o==2&&Lt(i)?29:Bt[o];return o>=1&&o<=12&&a>=1&&u!==void 0&&a<=u}function et(e,t){let n=t.match(Jt);if(!n)return!1;let r=n[1],s=n[2],i=n[3];if(!r||!s||!i)return!1;let o=+r,a=+s,u=+i,v=n[5],k=n[6],M=+(n[7]??0),_=+(n[8]??0);if(o>23||a>59||u>60||M>23||_>59||e&&v===void 0)return!1;if(u<60)return!0;let N=k==="+"?1:k==="-"?-1:0;return(o*60+a-N*(M*60+_)+1440)%1440===1439}var en=/t|\s/i;function tn(e){let[t,n,r]=e.split(en);return t!==void 0&&n!==void 0&&r===void 0&&Le(t)&&et(!0,n)}var nn=/\/|:/,rn=/^(?:[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 on(e){return nn.test(e)&&rn.test(e)}var sn=/[^\\]\\Z/;function an(e){if(sn.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function tt(e){let t=0,n=e.length,r=0,s;while(r<n)if(t++,s=e.charCodeAt(r++),s>=55296&&s<=56319&&r<n){if(s=e.charCodeAt(r),(s&64512)==56320)r++}return t}function oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function nt(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",s=n.indexOf("."),i=s===-1?0:n.length-s-1;return[BigInt(n.replace(".","")),Number(r)-i]}function dn(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=nt(e),[s,i]=nt(t),o=r-i;if(o>=0)return n*10n**BigInt(o)%s===0n;return n%(s*10n**BigInt(-o))===0n}function j(e,t,n="2019-09",r=Z(t),s=!0,i=null,o="#",a="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let v=typeof e,k;switch(v){case"boolean":case"number":case"string":k=v;break;case"object":if(e===null)k="null";else if(Array.isArray(e))k="array";else k="object";break;default:throw Error(`Instances of "${v}" type are not supported.`)}let{$ref:M,$recursiveRef:_,$recursiveAnchor:N,type:E,const:O,enum:q,required:U,not:f,anyOf:y,allOf:g,oneOf:b,if:h,then:R,else:A,format:S,properties:d,patternProperties:C,additionalProperties:H,unevaluatedProperties:z,minProperties:X,maxProperties:V,propertyNames:ee,dependentRequired:te,dependentSchemas:Ue,dependencies:Re,prefixItems:Ie,items:ce,additionalItems:Ve,unevaluatedItems:Ge,contains:We,minContains:K,maxContains:Me,minItems:_e,maxItems:Ce,uniqueItems:Mt,minimum:ne,maximum:re,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ee,minLength:ye,maxLength:ge,pattern:Fe,__absolute_ref__:he,__absolute_recursive_ref__:_t}=t,c=[];if(N===!0&&i===null)i=t;if(_==="#"){let T=i===null?r[_t]:i,m=`${a}/$recursiveRef`,I=j(e,i===null?t:i,n,r,s,T,o,m,u);if(!I.valid)c.push({instanceLocation:o,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=`${a}/$ref`,p=j(e,m,n,r,s,i,o,I,u);if(!p.valid)c.push({instanceLocation:o,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(E)){let T=E.length,m=!1;for(let I=0;I<T;I++)if(k===E[I]||E[I]==="integer"&&k==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${k}" is invalid. Expected "${E.join('", "')}".`})}else if(E==="integer"){if(k!=="number"||e%1||e!==e)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${k}" is invalid. Expected "${E}".`})}else if(E!==void 0&&k!==E)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${k}" is invalid. Expected "${E}".`});if(O!==void 0){if(k==="object"||k==="array"){if(!ue(e,O))c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/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:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}else if(!q.some((T)=>e===T))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}if(f!==void 0){let T=`${a}/not`;if(j(e,f,n,r,s,i,o,T).valid)c.push({instanceLocation:o,keyword:"not",keywordLocation:T,error:'Instance matched "not" schema.'})}let we=[];if(y!==void 0){let T=`${a}/anyOf`,m=c.length,I=!1;for(let[p,l]of y.entries()){let x=Object.create(u),w=j(e,l,n,r,s,N===!0?i:null,o,`${T}/${p}`,x);if(c.push(...w.errors),I=I||w.valid,w.valid)we.push(x)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:T,error:"Instance does not match any subschemas."})}if(g!==void 0){let T=`${a}/allOf`,m=c.length,I=!0;for(let[p,l]of g.entries()){let x=Object.create(u),w=j(e,l,n,r,s,N===!0?i:null,o,`${T}/${p}`,x);if(c.push(...w.errors),I=I&&w.valid,w.valid)we.push(x)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:T,error:"Instance does not match every subschema."})}if(b!==void 0){let T=`${a}/oneOf`,m=c.length,I=b.filter((p,l)=>{let x=Object.create(u),w=j(e,p,n,r,s,N===!0?i:null,o,`${T}/${l}`,x);if(c.push(...w.errors),w.valid)we.push(x);return w.valid}).length;if(I===1)c.length=m;else c.splice(m,0,{instanceLocation:o,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=`${a}/if`,m=Object.create(null);if(j(e,h,n,r,s,i,o,T,m).valid){if(Object.assign(u,m),R!==void 0){let p=j(e,R,n,r,s,i,o,`${a}/then`,u);if(!p.valid)c.push({instanceLocation:o,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,s,i,o,`${a}/else`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:T,error:'Instance does not match "else" schema.'},...p.errors)}}if(k==="object"){if(U!==void 0){for(let p of U)if(!oe(e,p))c.push({instanceLocation:o,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${p}".`})}let T=Object.keys(e);if(X!==void 0&&T.length<X)c.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&T.length>V)c.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(ee!==void 0){let p=`${a}/propertyNames`;for(let l in e){let x=`${o}/${J(l)}`,w=j(l,ee,n,r,s,i,x,p);if(!w.valid)c.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...w.errors)}}if(te!==void 0){let p=`${a}/dependantRequired`;for(let l in te)if(oe(e,l)){let x=te[l];for(let w of x)if(!oe(e,w))c.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}}if(Ue!==void 0)for(let[p,l]of Object.entries(Ue)){let x=`${a}/dependentSchemas`;if(oe(e,p)){let w=j(e,l,n,r,s,i,o,`${x}/${J(p)}`,u);if(!w.valid)c.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:x,error:`Instance has "${p}" but does not match dependant schema.`},...w.errors)}}if(Re!==void 0){let p=`${a}/dependencies`;for(let l in Re)if(oe(e,l)){let x=Re[l];if(Array.isArray(x)){for(let w of x)if(!oe(e,w))c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}else{let w=j(e,x,n,r,s,i,o,`${p}/${J(l)}`);if(!w.valid)c.push({instanceLocation:o,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=`${a}/properties`;for(let[l,x]of Object.entries(d)){if(!oe(e,l))continue;let w=`${o}/${J(l)}`,D=j(e[l],x,n,r,s,i,w,`${p}/${J(l)}`);if(m[l]=!0,D.valid)u[l]=!0;else if(I=s,c.push({instanceLocation:o,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...D.errors),I)break}}if(!I&&C!==void 0){let p=`${a}/patternProperties`;for(let[l,x]of Object.entries(C)){let w=new RegExp(l,"u");for(let D in e){if(!w.test(D))continue;let Ke=`${o}/${J(D)}`,Ye=j(e[D],x,n,r,s,i,Ke,`${p}/${J(l)}`);if(m[D]=!0,Ye.valid)u[D]=!0;else I=s,c.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:p,error:`Property "${D}" matches pattern "${l}" but does not match associated schema.`},...Ye.errors)}}}if(!I&&H!==void 0){let p=`${a}/additionalProperties`;for(let l in e){if(m[l])continue;let x=`${o}/${J(l)}`,w=j(e[l],H,n,r,s,i,x,p);if(w.valid)u[l]=!0;else I=s,c.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...w.errors)}}else if(!I&&z!==void 0){let p=`${a}/unevaluatedProperties`;for(let l in e)if(!u[l]){let x=`${o}/${J(l)}`,w=j(e[l],z,n,r,s,i,x,p);if(w.valid)u[l]=!0;else c.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...w.errors)}}}else if(k==="array"){if(Ce!==void 0&&e.length>Ce)c.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${Ce}).`});if(_e!==void 0&&e.length<_e)c.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${_e}).`});let T=e.length,m=0,I=!1;if(Ie!==void 0){let p=`${a}/prefixItems`,l=Math.min(Ie.length,T);for(;m<l;m++){let x=j(e[m],Ie[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=s,c.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...x.errors),I)break}}}if(ce!==void 0){let p=`${a}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,T);for(;m<l;m++){let x=j(e[m],ce[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...x.errors),I)break}}}else for(;m<T;m++){let l=j(e[m],ce,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&Ve!==void 0){let l=`${a}/additionalItems`;for(;m<T;m++){let x=j(e[m],Ve,n,r,s,i,`${o}/${m}`,l);if(u[m]=!0,!x.valid)I=s,c.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...x.errors)}}}if(We!==void 0)if(T===0&&K===void 0)c.push({instanceLocation:o,keyword:"contains",keywordLocation:`${a}/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:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${T}) than minContains (${K}).`});else{let p=`${a}/contains`,l=c.length,x=0;for(let w=0;w<T;w++){let D=j(e[w],We,n,r,s,i,`${o}/${w}`,p);if(D.valid)u[w]=!0,x++;else c.push(...D.errors)}if(x>=(K||0))c.length=l;if(K===void 0&&x===0)c.splice(l,0,{instanceLocation:o,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&x<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${x} items were found.`});else if(Me!==void 0&&x>Me)c.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Me} items matching schema. ${x} items were found.`})}if(!I&&Ge!==void 0){let p=`${a}/unevaluatedItems`;for(m;m<T;m++){if(u[m])continue;let l=j(e[m],Ge,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(Mt)for(let p=0;p<T;p++){let l=e[p],x=typeof l==="object"&&l!==null;for(let w=0;w<T;w++){if(p===w)continue;let D=e[w];if(l===D||x&&(typeof D==="object"&&D!==null)&&ue(l,D))c.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${a}/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(ne!==void 0&&(pe===!0&&e<=ne||e<ne))c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${ne}.`});if(re!==void 0&&(me===!0&&e>=re||e>re))c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${re}.`})}else{if(ne!==void 0&&e<ne)c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${ne}.`});if(re!==void 0&&e>re)c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${re}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ee!==void 0){if(!dn(e,Ee))c.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${Ee}.`})}}else if(k==="string"){let T=ye===void 0&&ge===void 0?0:tt(e);if(ye!==void 0&&T<ye)c.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${T} < ${ye}).`});if(ge!==void 0&&T>ge)c.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${T} > ${ge}).`});if(Fe!==void 0&&!new RegExp(Fe,"u").test(e))c.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(S!==void 0&&Ae[S]&&!Ae[S](e))c.push({instanceLocation:o,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${S}".`})}return{valid:c.length===0,errors:c}}var rt="ch.ractive.tab-mcp/annotations",un=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],ln=["destructiveHint","idempotentHint","openWorldHint"];function ot(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let s of ln){let i=e[s];if(i!==void 0)t[s]=i}let n={};for(let s of un){let i=e[s];if(i!==void 0)n[s]=i}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function st(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 se(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 fn(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 cn=new Set(["content","structuredContent","isError","_meta","resultType"]);function it(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:s}=e;return(t.length>0?t.every(fn):Object.keys(e).every((i)=>cn.has(i)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(s===void 0||Y(s))}function at(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(it(e))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return se("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 Oe(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 dt(e){if(it(e))return e.structuredContent??(Oe(e,!0)||"Done.");return e===void 0?"Done.":e}function ut(e){let t=e instanceof Error?e.message:String(e);return se(t||"The tool failed.")}var ie="2026-07-28",Q="io.modelcontextprotocol/protocolVersion",xe="io.modelcontextprotocol/clientCapabilities",lt="io.modelcontextprotocol/clientInfo",ft="io.modelcontextprotocol/serverInfo",Pe="io.modelcontextprotocol/subscriptionId",pn=-32020,ct=-32022,mn="The page may ask the user to allow each call, usually in the page's browser tab.",yn=0,pt=new WeakMap;function Ne(e){let t=pt.get(e);if(t!==void 0)return t;let n=e.inputSchema,r;try{r=Z(n)}catch(i){let o=i instanceof Error?i.message:String(i);throw Error(o.split(`
|
|
6
|
-
`)[0])}for(let i of Object.values(r)){if(typeof i!=="object"||i.$ref===void 0)continue;let o=i.__absolute_ref__;if(r[o??i.$ref]===void 0)throw Error(`$ref ${JSON.stringify(i.$ref)} does not resolve`)}let s=(i)=>j(i,n,"2020-12",r,!1);return pt.set(e,s),s}function mt(e,t,n=""){let r=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${r}${n}`)}function gn(e){let t=[];for(let n of e.list())try{Ne(n)}catch(r){e.remove(n),t.push(mt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Ne(n)}catch(r){throw mt(n.name,r)}}),t}function yt(e){try{return structuredClone(e)}catch{return e}}var hn=new TextEncoder;function L(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function je(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function B(e,t,n,r,s){let i={code:n,message:r};if(s!==void 0)i.data=s;return je(e,{jsonrpc:"2.0",id:t,error:i})}function W(e,t,n){return B(400,e,pn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return hn.encode(`event: message
|
|
7
|
-
data: ${JSON.stringify(e)}
|
|
8
|
-
|
|
9
|
-
`)}var gt={"content-type":"text/event-stream","cache-control":"no-cache"};function wn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function bn(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,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function $n(e){if(!(Q in e))return{key:Q,problem:"missing"};if(!(xe in e))return{key:xe,problem:"missing"};if(typeof e[Q]!=="string")return{key:Q,problem:"expected a protocol version string"};if(!L(e[xe]))return{key:xe,problem:"expected an object"};let t=e[lt];if(t!==void 0&&!(L(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:lt,problem:"expected {name, version}"};return}function xn(e){let t=e.notifications;return L(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function vn(e,t){let n;try{n=Ne(e)(t)}catch(s){let i=s instanceof Error?s.message:String(s);return`The input schema of tool ${e.name} cannot be used: ${i}`}if(n.valid)return;let r=n.errors.filter((s)=>s.keyword!=="properties"&&s.keyword!=="$ref").map((s)=>`${s.instanceLocation} ${s.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 ht(e,t,n,r,s,i){let o={id:++yn,tool:t.name,arguments:yt(n),client:{...s}};if(t.title!==void 0)o.title=t.title;let a=Date.now();e.observe?.start(o);let u={outcome:"error",result:se("Internal error")};try{if(u=await kn(e,t,n,r,s),t.annotations.untrustedContentHint===!0)u.result=st(u.result);let v=r.aborted?void 0:i?.(u.result);if(v!==void 0)u={outcome:"error",result:v}}finally{e.observe?.end({id:o.id,tool:t.name,client:{...s},outcome:u.outcome,result:yt(u.result),durationMs:Date.now()-a})}return u}var Tn="The user was asked and did not answer.";async function kn(e,t,n,r,s){let i=(_,N,E)=>({outcome:_,result:se(N),stop:E}),o=vn(t,n);if(o!==void 0)return i("error",o,"invalid");let a=new Promise((_,N)=>{if(r.aborted)N(r.reason);r.addEventListener("abort",()=>N(r.reason))});a.catch(()=>{});let{consequentialHint:u,destructiveHint:v}=t.annotations;if((s.kind==="webmcp"?u??v:u)===!0){let _={tool:{name:t.name,description:t.description},arguments:n,client:s,signal:r};if(t.title!==void 0)_.tool.title=t.title;let N=!1;try{N=await Promise.race([e.confirm(_),a])}catch{N=!1}if(N!==!0){if(r.aborted)return i("cancelled","The call was cancelled.","cancelled");return N==="unanswered"?i("unanswered",Tn,"unanswered"):i("declined","The user did not allow this call.","declined")}}if(r.aborted)return i("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return i("error","The tool is no longer available","gone");let M;try{let _=await Promise.race([t.execute(n,{signal:r,client:s}),a]);M={outcome:"ok",result:at(_),returned:{value:_}}}catch(_){M={outcome:"error",result:ut(_)}}if(r.aborted)return{...M,outcome:"cancelled",stop:"cancelled"};if(M.result.isError===!0)M.outcome="error";return M}async function qe(e,t,n,r,s){let i=(u)=>({error:u}),o=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return i(o);if(!L(n))return i("The input must be an object.");let a=await ht(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,s);if(a.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(a.stop==="declined")return i(`The user did not allow ${t.name} to run.`);if(a.stop==="unanswered")return i(`The user did not answer whether ${t.name} may run.`);if(a.stop==="gone")return i(o);if(a.result.isError===!0)return i(Oe(a.result)||"The tool failed.");return dt(a.returned?.value)}function ve(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let s=Se(n.icons??[]),i=s.length>0?{...r,icons:s}:r,o=new Set,a=!1,u=(f={})=>({...f,[ft]:r});function v(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} ${mn}`:f.description,y.inputSchema=f.inputSchema,f.outputSchema!==void 0)y.outputSchema=f.outputSchema;let{annotations:g,meta:b}=ot(f.annotations);if(g!==void 0)y.annotations=g;if(b!==void 0)y._meta={[rt]:b};return y})}let M=(f)=>({kind:"invalid",message:f});async function _(f,y,g,b){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(!L(A))return M("Invalid params: arguments must be an object");return{kind:"result",result:(await ht(e,R,A,y,e.client(g),b)).result}}function N(f,y,g,b){let h=(d)=>ae(v(f,d,u(d._meta))),R,A=(d)=>{let C;try{C=h(d)}catch{return se("The tool returned a result that is not JSON.")}let H=e.maxBodyBytes?.();if(H!==void 0&&C.byteLength>H)return se(`The result is ${C.byteLength} bytes; the relay passes on at most ${H}.`);R={result:d,event:C};return},S=new ReadableStream({start:(d)=>{let C=(H)=>{if(g.aborted)return;try{d.enqueue(H()),d.close()}catch{}};_(y,g,b,A).then((H)=>C(()=>H.kind==="invalid"?ae({jsonrpc:"2.0",id:f,error:{code:-32602,message:H.message}}):H.result===R?.result?R.event:h(H.result)),()=>C(()=>ae({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}})))}});return new Response(S,{status:200,headers:gt})}function E(f,y,g){let b=xn(y),h={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[Pe]:f})}},R,A=new ReadableStream({start:(S)=>{if(S.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:b,_meta:{[Pe]:f}}})),Object.keys(b).length===0){S.enqueue(ae(h)),S.close();return}let d={id:f,send:(C)=>{try{S.enqueue(ae(C))}catch{o.delete(d)}},end:()=>{o.delete(d);try{S.enqueue(ae(h)),S.close()}catch{}}};R=d,o.add(d),g.addEventListener("abort",()=>{o.delete(d);try{S.close()}catch{}})},cancel:()=>{if(R!==void 0)o.delete(R)}});return new Response(A,{status:200,headers:gt})}function O(f,y){if(Array.isArray(y))return B(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!L(y)||y.jsonrpc!=="2.0")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:g,id:b}=y;if(typeof g!=="string")return"result"in y||"error"in y?B(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):B(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=L(y.params)?y.params:{},S=L(A._meta)?A._meta:void 0,d=S!==void 0&&Q in S,C=typeof S?.[Q]==="string"?S[Q]:void 0,H=h!==null&&h>=ie;if(b===void 0){if(C!==void 0&&h!==null&&h!==C)return W(null,h,`the notification envelope names protocol version ${C} 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 b!=="string"&&typeof b!=="number")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let z=b;if(!d||g==="initialize"&&(C===void 0||C<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=S===void 0?["_meta"]:[Q];return B(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=$n(S);if(X!==void 0)return B(400,z,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${X.key}: ${X.problem}`,{envelope:X});if(h!==null&&C!==void 0&&h!==C)return W(z,h,`the body envelope names protocol version ${C} 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(C!==ie)return q(z,C);if(h===null)return W(z,"(missing)",`the body envelope names protocol version ${C} 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,ee=f.headers.get("mcp-name");if(ee===null)return W(z,"(missing)",`the body carries params.name="${V}" but the required Mcp-Name header is absent`);let te=bn(ee);if(te===void 0)return W(z,ee,"the Mcp-Name header carries an invalid Base64 sentinel value");if(te!==V)return W(z,ee,`the body carries params.name="${V}" but the Mcp-Name header names "${te}"`)}return{id:z,method:g,params:A}}function q(f,y){return y===void 0?B(400,f,ct,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):B(400,f,ct,`Unsupported protocol version: ${y}`,{supported:[ie],requested:y})}async function U(f,y){if(f.method.toUpperCase()!=="POST")return B(405,null,-32000,"Method not allowed.");if(!wn(f.headers.get("content-type")))return B(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 B(400,null,-32700,"Parse error: the request body is not valid JSON")}let b=O(f,g);if(b instanceof Response)return b;if(b==="notification")return new Response(null,{status:202});let{id:h,method:R,params:A}=b;switch(R){case"server/discover":{let S={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)S.instructions=n.instructions;return S.ttlMs=0,S.cacheScope="private",je(200,v(h,S,{[ft]:i}))}case"tools/list":return je(200,v(h,{tools:k(),ttlMs:0,cacheScope:"private"}));case"tools/call":return N(h,A,f.signal,y.grant);case"subscriptions/listen":return E(h,A,f.signal);default:return B(404,h,-32601,"Method not found")}}return{handle:(f,y)=>U(f,y).catch(()=>B(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let f of[...o])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Pe]:f.id}}})})},close(){for(let f of[...o])f.end()}}}var Te="tab-mcp.v1",Rn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function wt(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 In(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Mn(e){return fe(e)&&Object.values(e).every(P)}function bt(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)&&In(t.limits)&&Array.isArray(t.grants)&&t.grants.every(wt)&&(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)&&Mn(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"&&Rn.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 wt(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 _n(e,t){let n=(r)=>r&&(r.callers?.includes(t)??!0);return{list:()=>e.list().filter(n),get:(r)=>{let s=e.get(r);return n(s)?s:void 0}}}function Be(e,t,n){let r=t.list();return e.onChange(()=>{let s=t.list();if(s.length===r.length&&s.every((i,o)=>i===r[o]))return;r=s,n()})}function ke(e,t){return{tools:t==="webmcp"?e.registry:_n(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:e.ownConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var Cn=["content-type","cache-control"];function*De(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),s=e.charCodeAt(r-1);if(r<e.length&&s>=55296&&s<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var En=-31002,Sn="The page did not answer in time.";function An(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Je(e){let{handler:t,send:n,timeoutMs:r}=e,s=new Map,i=!1;async function o(a){let u=new AbortController;s.get(a.id)?.abort(),s.set(a.id,u);let v=()=>!i&&s.get(a.id)===u&&!u.signal.aborted,k=!1,M="",_=Object.entries(a.headers).some(([E,O])=>E.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),N=r===void 0||_?void 0:setTimeout(()=>{if(!v())return;u.abort();let E=JSON.stringify({jsonrpc:"2.0",id:An(a.body),error:{code:En,message:Sn}});if(!k){n({type:"http.response",id:a.id,status:200,headers:{"content-type":"application/json"},body:E});return}if(M===""||M===`
|
|
10
|
-
|
|
11
|
-
`)n({type:"http.response.chunk",id:a.id,data:`event: message
|
|
12
|
-
data: ${E}
|
|
13
|
-
|
|
14
|
-
`});n({type:"http.response.end",id:a.id})},r);try{let E=new Request(`https://tab.invalid${a.path}`,{method:a.method,headers:a.headers,signal:u.signal}),O=await t.handle(E,{grant:a.grant,body:a.body});if(!v()){await O.body?.cancel().catch(()=>{});return}let q={};for(let b of Cn){let h=O.headers.get(b);if(h!==null)q[b]=h}let U=(q["content-type"]??"").startsWith("text/event-stream"),f=e.maxChunk();if(!U||O.body===null){let b=await O.text();if(!v())return;if(b.length<=f){n({type:"http.response",id:a.id,status:O.status,headers:q,body:b});return}n({type:"http.response.start",id:a.id,status:O.status,headers:q});for(let h of De(b,f)){if(!v())break;n({type:"http.response.chunk",id:a.id,data:h})}if(v())n({type:"http.response.end",id:a.id});return}n({type:"http.response.start",id:a.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:b,value:h}=await y.read();if(b||!v())break;let R=g.decode(h,{stream:!0});if(R!=="")M=(M+R).slice(-2);for(let A of De(R,f))n({type:"http.response.chunk",id:a.id,data:A})}if(v())n({type:"http.response.end",id:a.id})}catch(E){if(v())e.error(E instanceof Error?E:Error(String(E))),n({type:"http.response",id:a.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),s.get(a.id)===u)s.delete(a.id)}}return{request(a){if(!i)o(a)},cancel(a){s.get(a)?.abort(),s.delete(a)},close(){if(i)return;i=!0;for(let a of s.values())a.abort();s.clear()}}}var On=65536,$t=64,Pn=300000,xt=128,He=new WeakSet,Nn=0,F=(e)=>typeof e==="string";function ze(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function jn(e,t,n){let r=n?.client;if(!ze(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 s=n.maxChunk??On;if(!Number.isInteger(s)||s<$t)throw TypeError(`serve: maxChunk must be a whole number of at least ${$t}`);let i=n.requestTimeoutMs??Pn;if(typeof i!=="number"||!(i>0)||i>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let o=n.onConfirm;if(o!==void 0&&typeof o!=="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(He.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let a={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")a.name=r.name;let u={grantId:`local:${++Nn}`,clientId:r.id,scopes:["tools"]},v=!1,k=(y)=>{if(v)return!1;try{return t.postMessage(y),!0}catch{return!1}},M=ke(e,"local");if(o!==void 0)M.confirm=(y)=>Promise.resolve().then(()=>o(y)).then((g)=>g==="unanswered"?g:g===!0),M.ownConfirm=!0;let _=ve({...M,server:{...e.server,icons:e.server.icons??be()},client:()=>({...a})}),N=Be(e.registry,M.tools,()=>_.toolsChanged()),E=Je({handler:_,send:k,maxChunk:()=>s,error:(y)=>e.error(y),timeoutMs:i}),O=(y,g)=>{let b={type:"error",code:"bad_message",message:y};if(F(g)&&g.length<=xt)b.id=g;k(b)},q=(y)=>{if(v)return;let g=y?.data;if(!ze(g)||!F(g.type)){O("not a message");return}let b=g.id;switch(g.type){case"http.request":{let{method:h,path:R,headers:A,body:S}=g;if(!F(b)||b===""||b.length>xt||!F(h)||!F(R)||!R.startsWith("/")||!ze(A)||!Object.values(A).every(F)||!F(S)){O("malformed http.request",b);return}E.request({type:"http.request",id:b,method:h,path:R,headers:A,body:S,grant:u});return}case"http.cancel":if(F(b))E.cancel(b);else O("malformed http.cancel");return;case"error":return;default:O(`unexpected ${g.type.slice(0,64)}`,b)}},U=t,f=()=>{if(v)return;if(n.signal?.removeEventListener("abort",f),U.removeEventListener?.("close",f),N(),E.close(),_.close(),He.delete(t))k({type:"bye",reason:"closed"});if(v=!0,t.onmessage===q)t.onmessage=null};if(n.signal?.aborted===!0)return f(),{close:f};return n.signal?.addEventListener("abort",f),U.addEventListener?.("close",f),He.add(t),t.onmessage=q,{close:f}}function qn(e){let t="",n=0,r=0;for(let s of e){n=n<<8|s,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 Hn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return qn(new Uint8Array(n))}catch{return}}function wr(e,t,n,r,s){let i=ke(e,"webmcp");return s===void 0?qe(i,t,n,r,{kind:"webmcp"}):qe({...i,confirm:()=>Promise.resolve(!0)},t,n,r,{kind:"webmcp",via:"tab-mcp-extension",name:s.name,host:s.host})}var zn=15000,vt={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"},Tt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var kt=512,Rt=6,It=64,Dn=kt+Rt*It;function Bn(e){let t=Math.floor((e-kt)/Rt);return t>=It?t:void 0}var Jn=1e4,Un=1000;function Vn(e,t){let n,r=!1,s=Number.NEGATIVE_INFINITY,i;try{if(e!==void 0&&typeof BroadcastChannel==="function")n=new BroadcastChannel(e),n.onmessage=(o)=>{let a=o.data;if(!r||a?.type!=="claimed"||a.address!==void 0&&a.address!==t)return;s=Date.now(),i?.()}}catch{n=void 0}return{claimed(){r=!0;try{n?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-s<=Jn)return Promise.resolve(!0);if(n===void 0)return Promise.resolve(!1);return new Promise((o)=>{let a=setTimeout(()=>o(!1),Un);i=()=>{clearTimeout(a),o(!0)}})},close(){n?.close()}}}function br(e,t,n,r,s){return new Promise((i,o)=>{let a=["grantschange","statechange","error"],u=(M)=>{clearTimeout(k);for(let _ of a)e.removeEventListener(_,v);if(M)o(M);else i()},v=(M)=>{let _=M?.detail?.error;if(n())u();else if((_?.code==="store_unavailable"||_?.code==="unknown_id")&&(_.for===void 0||_.for===t.type&&_.grantId===t.grantId))u(_);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")),s);for(let M of a)e.addEventListener(M,v);v()})}function $r(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 xr(e,t,n,r={}){let s=r.revokeAll===!0,i=new WebSocket(t,Te),o="opening",a,u=65536,v,k,M=0,_=Vn(e.tabs,r.address),N,E,O=new Promise((d,C)=>{N=d,E=C});O.catch(()=>{});let q=setTimeout(()=>{h(de("The relay did not answer in time.","network"))},zn),U=ke(e,"relay"),f=ve({...U,server:{...e.server,icons:e.server.icons??be()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>v}),y=Be(e.registry,U.tools,()=>f.toolsChanged());function g(d){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(d)),!0}catch{return!1}}function b(){if(M<=0)return;clearTimeout(k),k=setTimeout(()=>{a??="heartbeat",R(4003);try{i.close()}catch{}},M*2.5)}function h(d){if(o!=="opening")return;R(0),E(d);try{i.close()}catch{}}function R(d){if(o==="closed")return;let C=o==="ready";if(o="closed",clearTimeout(q),clearTimeout(k),y(),A.close(),f.close(),C){let H=a??vt[d]??(d===1006?"network":"closed");if(e.closed(H,d),H==="replaced"){_.heard().then((z)=>{_.close(),e.replaced({sibling:z})});return}}_.close()}let A=Je({handler:f,send:g,maxChunk:()=>u,error:(d)=>e.error(d)});function S(d){if(o==="opening"){if(d.type==="session"){let C=Bn(d.limits.maxMessageBytes);if(C===void 0){h(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Dn}.`,"policy"));return}if(s&&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=C,v=d.limits.maxBodyBytes,o="ready",clearTimeout(q),M=d.limits.heartbeatMs,b(),_.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}`,Tt[d.reason]??"closed"));return}if(o!=="ready")return;switch(d.type){case"ping":b(),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(a=Tt[d.reason]??"closed",a==="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 i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==Te){h(de(`The relay speaks ${i.protocol}, not ${Te}.`,"policy"));return}g({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...s?{revokeAll:!0}:{}})}),i.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let C=bt(d.data);if(C===void 0)return;if(o==="ready")b();S(C)}),i.addEventListener("close",(d)=>{if(o==="opening"){R(d.code);let C=d.code===1006||d.code===1002;E(de(C?"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}`:""}).`,vt[d.code]??(C?"network":"closed")));return}R(d.code)}),{ready:O,send:g,close(d){if(o==="closed")return;if(o==="opening"){h(new DOMException("The connection was cancelled","AbortError"));return}a=d,g({type:"bye",reason:"user"}),R(1000);try{i.close(1000,"bye")}catch{}}}}export{Dn as MIN_MESSAGE_BYTES,Un as SIBLING_GRACE_MS,Jn as SIBLING_WINDOW_MS,Hn as addressIdOf,br as answer,wr as callFromWebMcp,Bn as chunkSize,gn as compileRegistry,$r as onWake,xr as openConnection,De as pieces,jn as servePort};
|
|
15
|
-
|
|
16
|
-
//# debugId=225D663AD0F9EB7764756E2164756E21
|
|
17
|
-
//# sourceMappingURL=connection-5x2krvfs.min.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/visible.ts", "../../src/dialog.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * Text an AI app or a page wrote, made safe to show to the user before they\n * approve something: characters that are invisible, blank or turn the text's\n * direction are written as escapes, so the text cannot look like something\n * else. Shared by the library's confirmation dialog and the tab-mcp browser extension.\n */\n\n/**\n * Characters that are invisible, blank or change the direction of the text\n * around them: controls (C0 and C1, but tab and line feed, which are only\n * JSON's layout), format characters (bidi controls and isolates, zero-width\n * ones, tags), the other default-ignorable ones (variation selectors, U+034F,\n * the Hangul fillers), private-use, unassigned and lone surrogate code\n * points, line and paragraph separators, every space but the plain one\n * (U+00A0, U+2007, U+3000…) and the Braille blank (U+2800).\n */\nconst INVISIBLE =\n\t/(?![\\t\\n ])[\\p{Cc}\\p{Cf}\\p{Default_Ignorable_Code_Point}\\p{Co}\\p{Cn}\\p{Cs}\\p{Zl}\\p{Zp}\\p{Zs}\\u{2800}]/gu;\n\n/**\n * `text` with each such character as `\\uXXXX` (a surrogate pair for one\n * beyond U+FFFF), as JSON would write it: JSON stays JSON for the same value.\n */\nexport function escapeInvisible(text: string): string {\n\treturn text.replace(INVISIBLE, (ch) => {\n\t\tlet escaped = \"\";\n\t\tfor (let i = 0; i < ch.length; i++)\n\t\t\tescaped += `\\\\u${ch.charCodeAt(i).toString(16).toUpperCase().padStart(4, \"0\")}`;\n\t\treturn escaped;\n\t});\n}\n",
|
|
6
|
-
"/**\n * What the library's dialogs share: the stylesheet, elements, buttons, the\n * texts (`strings.ts`) and how a caller is named. The confirmation\n * (`confirm.ts`) and the connect dialog (`connect.ts`) are chunks of their\n * own, loaded on demand; pages with their own UI use the events and methods\n * of `TabMcp` instead.\n */\n\nimport { type DialogStrings, type PluralText, withEnglish } from \"./strings.ts\";\nimport { directionOf, format, listFormat, pluralForm } from \"./text.ts\";\nimport type { DialogOptions, Grant, ToolCallClient } from \"./types.ts\";\nimport { escapeInvisible } from \"./visible.ts\";\n\nexport { format, listOf, plural } from \"./text.ts\";\n\nlet counter = 0;\n\n/** A new id for the elements of one dialog. */\nexport function nextId(): string {\n\treturn `tab-mcp-${++counter}`;\n}\n\n/** The texts: the page's own (`ui.strings`) where it gave them, else English. */\nexport function stringsOf(options: DialogOptions | undefined): DialogStrings {\n\treturn withEnglish(options?.strings);\n}\n\n/**\n * `template` with its `{name}` placeholders filled in, as nodes: a string\n * value is a name, isolated so that it cannot reorder the words around it\n * (and may stand twice); a node is put in as it is.\n */\nexport function fill(\n\tdoc: Document,\n\ttemplate: string,\n\tvalues: Record<string, string | Node>,\n): (Node | string)[] {\n\treturn template.split(/\\{(\\w+)\\}/).map((part, i) => {\n\t\tif (i % 2 === 0) return part;\n\t\tconst value = values[part];\n\t\tif (value === undefined) return `{${part}}`;\n\t\treturn typeof value === \"string\" ? name(doc, value) : value;\n\t});\n}\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\n/**\n * A button. `className` is its own class; `kind` marks the one next step\n * (`tab-mcp-primary`) or one that disconnects (`tab-mcp-danger`); without\n * one it is a plain, outlined button.\n */\nexport function button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n\tclassName?: string,\n\tkind?: \"primary\" | \"danger\",\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tif (className !== undefined) node.classList.add(className);\n\tif (kind !== undefined) node.classList.add(`tab-mcp-${kind}`);\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/** A name in a sentence, isolated so that it cannot reorder the words around it. */\nexport function name(doc: Document, text: string): HTMLElement {\n\tconst node = el(doc, \"bdi\", { text });\n\tnode.dir = \"ltr\";\n\treturn node;\n}\n\n/**\n * The form of `text` for the number of `names`, with `{apps}` the names as\n * the texts' language lists them (\"A, B and C\"), each name isolated like\n * every other name in a dialog, as nodes.\n */\nexport function pluralNames(\n\tdoc: Document,\n\ttext: PluralText,\n\tnames: string[],\n\ts: DialogStrings,\n): (Node | string)[] {\n\tconst list = el(\n\t\tdoc,\n\t\t\"span\",\n\t\t{},\n\t\t...listFormat(s)\n\t\t\t.formatToParts(names)\n\t\t\t.map((part) =>\n\t\t\t\tpart.type === \"element\" ? name(doc, part.value) : part.value,\n\t\t\t),\n\t);\n\treturn fill(doc, pluralForm(text, names.length, s), { apps: list });\n}\n\n/** What each element shows through `showNames`, so that it is made only on a change. */\nconst shownNames = new WeakMap<Element, string>();\n\n/**\n * `node` says `text` for `names` (`pluralNames`), or nothing when there are\n * none. Its nodes are made again only when the words change: a render that\n * changes nothing removes nothing (a screen reader keeps its place).\n */\nexport function showNames(\n\tdoc: Document,\n\tnode: Element,\n\ttext: PluralText,\n\tnames: string[],\n\ts: DialogStrings,\n): void {\n\tconst key =\n\t\tnames.length === 0\n\t\t\t? \"\"\n\t\t\t: [pluralForm(text, names.length, s), ...names].join(\"\\n\");\n\tif ((shownNames.get(node) ?? \"\") === key) return;\n\tshownNames.set(node, key);\n\tnode.replaceChildren(\n\t\t...(names.length === 0 ? [] : pluralNames(doc, text, names, s)),\n\t);\n}\n\n/** Invisible, blank and direction characters as `\\uXXXX` (`visible.ts`). */\nexport const visible: (text: string) => string = escapeInvisible;\n\n/**\n * How the dialogs name a caller: an AI app's name and verified host; for\n * the caller of a served port, the name the page gave it and what it is.\n */\nexport function clientLabel(\n\tclient: ToolCallClient | Grant[\"client\"],\n\ts: DialogStrings,\n): string {\n\tif (\"kind\" in client && client.kind === \"webmcp\") return s.clientWebMcp;\n\tif (\"kind\" in client && client.kind === \"local\")\n\t\treturn format(s.clientLocal, { name: visible(client.name ?? client.id) });\n\tconst host = visible(client.host || client.id);\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? format(s.clientRelay, { name: visible(client.name), host })\n\t\t: host;\n}\n\n/**\n * The look of the dialogs. Every selector has the specificity of one class\n * (the rest is in `:where()`), so rules of the page for elements, such as\n * `button { … }` or a reset's `* { border-width: 0 }`, do not change the\n * dialogs. The rules for states (hover, focus, disabled) and the primary\n * and danger buttons add two elements (`html dialog.…`, `html button.…`),\n * so `button:hover`, `button:focus` or `button:disabled` of the page do not\n * either. A page overrides with two classes, `.tab-mcp-dialog .tab-mcp-x`,\n * which wins over all of them; one class does not. The `--tab-mcp-*`\n * custom properties (on `:root` or on `.tab-mcp-dialog`) change single\n * values; the library only reads them. The defaults use system colours and the\n * page's `color-scheme`, so the dialogs follow its light or dark scheme. The\n * `--_tab-mcp-*` properties are internal. Order matters among equals.\n */\nexport const DIALOG_CSS = `.tab-mcp-dialog {\n--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);\n--_tab-mcp-bg: var(--tab-mcp-background, Canvas);\n--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));\n--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);\n--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));\n--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));\n--_tab-mcp-success: var(--tab-mcp-success, light-dark(#1a7f37, #6fdd8b));\n--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);\nbox-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;\nfont: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);\nborder: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);\npadding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));\npointer-events: auto;\n}\n.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }\n.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }\n.tab-mcp-dialog :where([hidden]) { display: none !important; }\nhtml dialog.tab-mcp-dialog:where(:focus) { outline: none; }\n.tab-mcp-dialog :where(*) { box-sizing: border-box; color: inherit; }\n.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }\n.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }\n.tab-mcp-dialog :where(small) { font-size: 0.875em; }\n.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next, .tab-mcp-waiting, .tab-mcp-scroll-note) { color: var(--_tab-mcp-muted); }\nhtml dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }\n.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; text-transform: none; letter-spacing: normal; width: auto; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }\nhtml dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }\nhtml dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }\nhtml button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }\nhtml button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }\nhtml button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }\n.tab-mcp-copy { min-width: 6em; }\n.tab-mcp-close { font-size: 0.875em; }\n.tab-mcp-status { margin-top: -0.5rem; }\n.tab-mcp-description:where(:empty) { display: none; }\n.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }\n.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }\n.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }\n.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code > :where(span) { font-weight: 600; }\n.tab-mcp-code :where(br) { display: none; }\n.tab-mcp-code :where(small) { grid-column: 1 / -1; }\n.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }\n.tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }\n.tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }\n.tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }\n.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }\n.tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }\n.tab-mcp-help :where(li) { overflow-wrap: anywhere; }\n.tab-mcp-help :where(strong) { display: block; font-weight: 600; }\n.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }\n.tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-command-note { display: block; margin-top: 0.375rem; }\n.tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }\n.tab-mcp-apps :where(li) { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-app { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }\n.tab-mcp-allowed { display: grid; flex-basis: 100%; gap: 0.25rem; padding-top: 0.5rem; border-top: 1px solid var(--_tab-mcp-line); font-size: 0.875em; overflow-wrap: anywhere; }\n.tab-mcp-allowed-title { font-weight: 600; color: var(--_tab-mcp-muted); }\n.tab-mcp-switches { display: grid; gap: 0.125rem; }\n.tab-mcp-switch { display: flex; align-items: center; gap: 0.625rem; min-height: 2rem; cursor: pointer; }\n.tab-mcp-switch > :where(input) { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 2.25rem; height: 1.25rem; margin: 0; padding: 0; border: 1px solid var(--_tab-mcp-line); border-radius: 0.625rem; background: var(--_tab-mcp-surface); cursor: pointer; }\n.tab-mcp-switch > :where(input)::before { content: \"\"; position: absolute; top: 2px; left: 2px; width: calc(1.25rem - 6px); height: calc(1.25rem - 6px); border-radius: 50%; background: var(--_tab-mcp-muted); }\n.tab-mcp-switch > :where(input:checked) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); border-color: transparent; }\n.tab-mcp-switch > :where(input:checked)::before { left: calc(100% - 1.25rem + 4px); background: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); }\nhtml dialog.tab-mcp-dialog :where(.tab-mcp-switch > input:disabled) { opacity: 0.45; cursor: not-allowed; }\n.tab-mcp-destructive { color: var(--_tab-mcp-danger); }\n.tab-mcp-everything { font-weight: 600; }\n.tab-mcp-everything-note { color: var(--_tab-mcp-muted); }\n.tab-mcp-apps-note { margin-top: 0.5rem; }\n.tab-mcp-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-success-icon { flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; font-size: 1.5em; font-weight: 700; line-height: 1; color: var(--_tab-mcp-success); background: color-mix(in srgb, var(--_tab-mcp-success) 16%, transparent); }\n.tab-mcp-success-icon::before { content: \"\\\\2713\"; }\n.tab-mcp-success-text { display: grid; gap: 0.125rem; min-width: 0; }\n.tab-mcp-success-title { font-size: 1.125em; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-setup { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-setup-toggle { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem; text-align: start; font-weight: 600; border-color: var(--_tab-mcp-line); }\n.tab-mcp-setup-toggle::before { content: \"\"; flex: none; width: 0.45em; height: 0.45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateX(-0.1em) rotate(-45deg); }\n.tab-mcp-setup-toggle:where([aria-expanded=\"true\"])::before { transform: translateY(-0.15em) rotate(45deg); }\n.tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }\n.tab-mcp-disconnect-all-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }\n.tab-mcp-disconnect-all-row > :where(small) { flex: 1 1 14rem; color: var(--_tab-mcp-muted); }\n.tab-mcp-disconnect-all-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }\n.tab-mcp-close-note { flex: 1 1 12rem; }\n.tab-mcp-confirm :where(p bdi) { font-weight: 600; }\n.tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-always-note, .tab-mcp-waiting, .tab-mcp-scroll-note { font-size: 0.875em; }\n@media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } .tab-mcp-code { grid-template-columns: minmax(0, 1fr); } .tab-mcp-code > :where(button) { justify-self: start; } }\n@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } .tab-mcp-switch > :where(input)::before { transition: left 0.15s ease-out; } }\n@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } .tab-mcp-switch > :where(input) { forced-color-adjust: none; background: Canvas; border-color: ButtonText; } .tab-mcp-switch > :where(input)::before { forced-color-adjust: none; background: ButtonText; } .tab-mcp-switch > :where(input:checked) { background: Highlight; } .tab-mcp-switch > :where(input:checked)::before { background: HighlightText; } }\n@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }\n@keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }\n`;\n\nconst sheets = new WeakMap<Document, CSSStyleSheet>();\n\n/**\n * Adopts `DIALOG_CSS` into the document once, next to the page's own adopted\n * sheets. A constructed stylesheet needs no `style-src` exception under a\n * strict CSP. Where constructed stylesheets are not supported, the dialogs\n * keep the browser's default look and work the same.\n */\nfunction adoptStyles(doc: Document): void {\n\ttry {\n\t\tlet sheet = sheets.get(doc);\n\t\tif (sheet === undefined) {\n\t\t\tconst Sheet = (doc.defaultView as (Window & typeof globalThis) | null)\n\t\t\t\t?.CSSStyleSheet;\n\t\t\tif (Sheet === undefined || !Array.isArray(doc.adoptedStyleSheets)) return;\n\t\t\tsheet = new Sheet();\n\t\t\tsheet.replaceSync(DIALOG_CSS);\n\t\t\tsheets.set(doc, sheet);\n\t\t}\n\t\t// The page may have replaced the list since.\n\t\tif (!doc.adoptedStyleSheets.includes(sheet))\n\t\t\tdoc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];\n\t} catch {\n\t\t// Not supported: the default look.\n\t}\n}\n\n/**\n * A dialog with its heading (`title`, or filled in by the caller). It\n * carries the texts' language and direction (`lang` of the strings, and\n * `dir` or the direction of that language), whatever the page's: read out\n * with that voice, laid out that way.\n */\nexport function newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ts: DialogStrings,\n\t...title: (Node | string)[]\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement; id: string } {\n\tconst id = nextId();\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\tdialog.lang = s.lang;\n\tdialog.dir = directionOf(s);\n\tadoptStyles(doc);\n\tconst heading = el(doc, \"h2\", { id: `${id}-title` }, ...title);\n\tdialog.append(heading);\n\treturn { dialog, heading, id };\n}\n\n/** How long a Copy button says \"Copied\", and how long it says to press Ctrl+C. */\nexport const COPIED_MS = 2000;\nexport const SELECTED_MS = 8000;\n\n/** What the button says after a refused Copy, by the user's device. */\nfunction pressToCopy(doc: Document, s: DialogStrings): string {\n\tconst view = doc.defaultView;\n\tif (view?.matchMedia?.(\"(pointer: coarse)\").matches === true)\n\t\treturn s.selected;\n\tconst platform = view?.navigator.platform ?? \"\";\n\treturn /^(Mac|iP)/.test(platform) ? s.pressMac : s.pressOther;\n}\n\n/**\n * A Copy button for `value()`, read at click time. Says \"Copied\" for a\n * moment once the clipboard took it; without a clipboard (or when it refuses)\n * `select()` puts the text in the selection and the button says to press\n * Ctrl+C (⌘C on Apple devices). `label` names it for assistive technology\n * (\"Copy code\"), as the dialog has more than one Copy; while it says what\n * happened, that is its name, and `announce` says it too.\n */\nexport function copyButton(\n\tdoc: Document,\n\ts: DialogStrings,\n\tlabel: string,\n\tvalue: () => string,\n\tselect: () => void,\n\tannounce: (text: string) => void,\n\tclassName: string,\n\tkind?: \"primary\",\n): { button: HTMLButtonElement; reset: () => void } {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst say = (text: string, ms: number) => {\n\t\tnode.textContent = text;\n\t\tnode.removeAttribute(\"aria-label\");\n\t\tannounce(text);\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(reset, ms);\n\t};\n\tconst node = button(\n\t\tdoc,\n\t\ts.copy,\n\t\t() => {\n\t\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t\t?.clipboard;\n\t\t\tconst selected = () => {\n\t\t\t\tselect();\n\t\t\t\tsay(pressToCopy(doc, s), SELECTED_MS);\n\t\t\t};\n\t\t\tif (clipboard !== undefined)\n\t\t\t\tclipboard\n\t\t\t\t\t.writeText(value())\n\t\t\t\t\t.then(() => say(s.copied, COPIED_MS), selected);\n\t\t\telse selected();\n\t\t},\n\t\tclassName,\n\t\tkind,\n\t);\n\t// The same width for \"Copy\" and \"Copied\": nothing moves.\n\tnode.classList.add(\"tab-mcp-copy\");\n\tconst reset = () => {\n\t\tclearTimeout(timer);\n\t\ttimer = undefined;\n\t\tnode.textContent = s.copy;\n\t\tnode.setAttribute(\"aria-label\", label);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": "wDAgBA,IAAM,EACL,0GAMM,SAAS,CAAe,CAAC,EAAsB,CACrD,OAAO,EAAK,QAAQ,EAAW,CAAC,IAAO,CACtC,IAAI,EAAU,GACd,QAAS,EAAI,EAAG,EAAI,EAAG,OAAQ,IAC9B,GAAW,MAAM,EAAG,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,EAAG,GAAG,IAC7E,OAAO,EACP,ECdF,IAAI,EAAU,EAGP,SAAS,CAAM,EAAW,CAChC,MAAO,WAAW,EAAE,IAId,SAAS,CAAS,CAAC,EAAmD,CAC5E,OAAO,EAAY,GAAS,OAAO,EAQ7B,SAAS,CAAI,CACnB,EACA,EACA,EACoB,CACpB,OAAO,EAAS,MAAM,WAAW,EAAE,IAAI,CAAC,EAAM,IAAM,CAC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