@ractive-ch/tab-mcp-client 0.21.0 → 0.22.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,24 @@ the Git tag `client-v<version>`. The format follows
6
6
  [Semantic Versioning](https://semver.org/). The relay has its own
7
7
  [changelog](https://github.com/ractive/tab-mcp/blob/main/packages/tab-mcp/CHANGELOG.md).
8
8
 
9
+ ## [0.22.0-rc.1][client-0.22.0-rc.1] - 2026-11-23
10
+
11
+ ### Breaking
12
+
13
+ - **`BrowserExtension` has no `version` any more** (`TabMcp.extension`,
14
+ `extensionchange`, the React snapshot's `extension`; DEC-221). The tab-mcp browser
15
+ extension no longer tells a page its version. A page that showed or checked it drops
16
+ that; `name`, `apps` and `whileInFront` are unchanged.
17
+
18
+ ### Changed
19
+
20
+ - **The library takes the extension's "on" without a version** (DEC-221), as the
21
+ tab-mcp browser extension after 0.3.2 sends it; a version an older extension sends is
22
+ ignored. While AI access is off, the extension answers no page and sends it
23
+ nothing, so `extension` stays `undefined`, as without the extension; a page it served
24
+ is told once that it went off. Once on, the extension greets the page with `hello`,
25
+ and the library's answer tells it what the page announces.
26
+
9
27
  ## [0.21.0][client-0.21.0] - 2026-11-22
10
28
 
11
29
  ### Breaking
@@ -1170,6 +1188,7 @@ First alpha of the browser library, on the npm dist-tag `alpha`.
1170
1188
  `<script type="module">` under `@ractive-ch/tab-mcp-client/cdn`.
1171
1189
  - The connect dialog shows the pairing code from the relay.
1172
1190
 
1191
+ [client-0.22.0-rc.1]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.22.0-rc.1
1173
1192
  [client-0.21.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.21.0
1174
1193
  [client-0.20.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.20.0
1175
1194
  [client-0.19.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.19.0
package/README.md CHANGED
@@ -17,7 +17,7 @@ How the library, the relay and the tab-mcp browser extension fit together, with
17
17
  picture:
18
18
  [How the parts fit together](https://github.com/ractive/tab-mcp#how-the-parts-fit-together).
19
19
 
20
- **Status: 0.21.0.** Until 1.0, a new minor version can still change the API. Which AI apps
20
+ **Status: 0.22.0-rc.1.** Until 1.0, a new minor version can still change the API. Which AI apps
21
21
  work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
22
22
 
23
23
  ## With a coding agent
@@ -57,7 +57,7 @@ docker run --rm -p 8080:8080 \
57
57
  -e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
58
58
  -e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
59
59
  -e TAB_MCP_STORE=memory \
60
- ractive/tab-mcp:0.13.2
60
+ ractive/tab-mcp:0.13.3-rc.1
61
61
  ```
62
62
 
63
63
  For production, see
@@ -76,7 +76,7 @@ Or without a bundler, from a CDN as an ES module:
76
76
 
77
77
  ```html
78
78
  <script type="module">
79
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.21.0/cdn/tab-mcp-client.min.js";
79
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.22.0-rc.1/cdn/tab-mcp-client.min.js";
80
80
  </script>
81
81
  ```
82
82
 
@@ -344,11 +344,13 @@ that an AI app reaches it through the extension:
344
344
 
345
345
  - **`extension`** (and the event `extensionchange`, `{ extension }`; in React the
346
346
  snapshot's `extension`): while the extension serves the page,
347
- `{ name, version, apps, whileInFront }`. `apps` are the AI apps connected to the
347
+ `{ name, apps, whileInFront }`. `apps` are the AI apps connected to the
348
348
  extension now, each `{ name, host }` (the AI app's own name and the host the relay
349
349
  verified), empty while none is. `whileInFront` is `true`: the extension serves only the
350
350
  tab in front of its window, so say "while this tab is in front". `undefined` without
351
- the extension, while its AI access is off, and without WebMCP. The connect dialog says
351
+ the extension, while its AI access is off, and without WebMCP. While AI access is off,
352
+ the extension answers no page and sends it nothing (DEC-221); a page it served hears
353
+ once that it stopped. It does not tell its version. The connect dialog says
352
354
  it first ("Claude (claude.ai) is connected through the tab-mcp browser extension,
353
355
  while this tab is in front.", `ui.strings.viaExtension…`) and keeps everything else:
354
356
  a phone or another browser still connects to the page directly.
@@ -816,8 +818,8 @@ mcp.addEventListener("grantschange", drawSwitches);
816
818
  that does not import it loads nothing of it. Take both from the same version:
817
819
 
818
820
  ```js
819
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.21.0/cdn/tab-mcp-client.min.js";
820
- import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.21.0/cdn/allowed.min.js";
821
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.22.0-rc.1/cdn/tab-mcp-client.min.js";
822
+ import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.22.0-rc.1/cdn/allowed.min.js";
821
823
  ```
822
824
 
823
825
  **The risk.** An allowance outlives the user's attention: for up to the grant's 90 days,
@@ -1075,14 +1077,14 @@ sign in with the account you use on this page" only once it is `bound`. Until th
1075
1077
  says what is missing: "Checking your sign-in…" (`pending`), "Sign in to this page first."
1076
1078
  (`none`), or that the sign-in was not accepted, with `identityMessage` (`refused`).
1077
1079
 
1078
- An open dialog counts for 10 minutes (relays after 0.13.2): a sign-in pairs the page
1080
+ An open dialog counts for 10 minutes (relays after 0.13.3-rc.1): a sign-in pairs the page
1079
1081
  only until 10 minutes after the last `startPairing()`, which the dialog calls when it
1080
1082
  opens. The relay says for how long (`pairing.open`); the library counts that on the
1081
1083
  page's own clock from the message's arrival and keeps the end in `pairingUntil` (an ISO
1082
1084
  time, event `pairinguntil`), so a page whose clock differs from the relay's still shows
1083
1085
  the right moment. `pairingUntil` is `undefined` while pairing is off, from each
1084
1086
  `startPairing()` until the relay answers, after the session ended (`disconnect()`,
1085
- `disconnectAll()`, a refusal), and with a relay up to 0.13.2. The dialog shows "Your AI
1087
+ `disconnectAll()`, a refusal), and with a relay up to 0.13.3-rc.1. The dialog shows "Your AI
1086
1088
  app can connect until 14:32." under the sign-in line and, once that time is up (also
1087
1089
  checked when the tab comes back to the front), "The time to connect your AI app is up"
1088
1090
  with Continue, which calls `startPairing()` again. Nothing starts the 10 minutes again
@@ -1090,7 +1092,7 @@ by itself: not a timer, and not a reconnect the library makes by itself once the
1090
1092
  was sent, answered or not (after one, `pairingUntil` is the time of the reconnect, so
1091
1093
  the dialog shows Continue). `connect()` from a click while reconnecting ("Connect again")
1092
1094
  does ask again; codes always come again after a reconnect. A custom UI does the same:
1093
- call `startPairing()` only from the user's click. With a relay up to 0.13.2 an open dialog
1095
+ call `startPairing()` only from the user's click. With a relay up to 0.13.3-rc.1 an open dialog
1094
1096
  counts as long as it is open, and after a reconnect the dialog shows Continue too. A
1095
1097
  sign-in that comes back after the time is up gets the relay's answer that no page is
1096
1098
  connecting with that account; Continue, then Connect again on the relay's page, pairs it.
@@ -1116,7 +1118,7 @@ the session ends after the message was sent and before the relay answered, and w
1116
1118
  or may not have done it, and `grants` says so once the page is connected again. They
1117
1119
  also reject with the relay's refusal of that message, an `Error` whose `code` is
1118
1120
  `store_unavailable` (the relay could not save the change: try again) or `unknown_id`.
1119
- A relay after 0.13.2 names the message it answers (`for`, and `grantId` for a
1121
+ A relay after 0.13.3-rc.1 names the message it answers (`for`, and `grantId` for a
1120
1122
  revocation), so with several revocations pending only the one it answers rejects; an
1121
1123
  older relay's refusal rejects every pending `revoke()` and `signOut()`. When the relay
1122
1124
  does not know a grant the page lists (it expired), the grant leaves `grants` (with
@@ -0,0 +1,4 @@
1
+ import{u}from"./tab-mcp-client-gdj1e1wh.min.js";import{a,r,e,t,s,d,l}from"./tab-mcp-client-yjcmhpdf.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={allowDelayMs:ne},ie=500,J=new WeakMap;function K(f,n,b={}){if(f.signal.aborted)return Promise.resolve("deny");let p=J.get(n);if(p===void 0)p={shown:!1,waiting:[]},J.set(n,p);let i=p,c=()=>{let h=i.waiting.shift();i.shown=h!==void 0,h?.(),i.changed?.()},C=()=>{try{return oe(f,n,b,i,c)}catch(h){return c(),Promise.reject(h)}};if(!i.shown)return i.shown=!0,C();return new Promise((h)=>{let v=()=>{if(f.signal.removeEventListener("abort",E),b.allowedNow?.()===!0){h("allow"),c();return}h(C())},E=()=>{i.waiting.splice(i.waiting.indexOf(v),1),i.changed?.(),h("deny")};f.signal.addEventListener("abort",E,{once:!0}),i.waiting.push(v),i.changed?.()})}function oe(f,n,b,p,i){let c=b.strings??a(void 0),C=b.allowDelayMs??te.allowDelayMs,h=f.tool.title??f.tool.name,v=d(f.client,c),E={tool:h,client:v},{dialog:m,id:L}=l(n,"tab-mcp-confirm",c,...r(n,c.confirmTitle,E)),I=e(n,"p",{className:"tab-mcp-waiting"}),S=()=>{let g=p.waiting.length;I.hidden=g===0,I.textContent=u(c.waiting,g,c)};p.changed=S,S();let z=t(n,c.deny,()=>m.close("deny"),"tab-mcp-deny","primary"),B=(g,j,O)=>{let A=t(n,g,()=>{if(!A.disabled)m.close(j)},O);return A},M=[B(c.allow,"allow","tab-mcp-allow")],W=[],Q=b.alwaysAllow;if(Q===!0||Q==="until-reload"){let g=Q===!0;M.unshift(B(g?c.alwaysAllow:c.allowUntilReload,"always","tab-mcp-always")),W.push(e(n,"p",{className:"tab-mcp-always-note"},...r(n,g?c.alwaysAllowNote:c.allowUntilReloadNote,E)))}let Y=e(n,"div",{className:"tab-mcp-actions"},z,...M.flatMap((g)=>[" ",g])),x=!1,U=!1,N=()=>{for(let g of M)g.disabled=!(x&&U)};N();let R=ee(f.arguments),y=e(n,"pre",{className:"tab-mcp-arguments",id:`${L}-arguments`,text:R??c.argumentsHidden});if(R===void 0)for(let g of[...M,...W])g.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 T=e(n,"p",{className:"tab-mcp-scroll-note",text:c.scrollToAllow});T.hidden=!0;let _=e(n,"p",{id:`${L}-who`},...r(n,c.confirmWho,E));m.setAttribute("aria-describedby",R!==void 0&&!y.hidden&&R.length<=ie?`${_.id} ${y.id}`:_.id),m.append(_,e(n,"p",{className:"tab-mcp-description",text:f.tool.description}),y,T,Y,...W,I),n.body.append(m);let k=n.defaultView;return new Promise((g,j)=>{let O=()=>m.close("deny");f.signal.addEventListener("abort",O,{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:`${c.titlePrefix}${n.title}`},n.title=P.shown},D=(w)=>{if(w?.type==="close"&&w.target===m)return;if(X(),clearTimeout(A),A=void 0,x=!1,N(),w?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;A=setTimeout(()=>{x=!0,N()},C)},H=()=>{if(U)return;if(y.scrollTop+y.clientHeight<y.scrollHeight-2){T.hidden=!1,y.tabIndex=0;return}U=!0,T.hidden=!0,N()},V=(w)=>{if(x)return;let q=w.target?.localName==="button";if(w.key==="Escape"||q&&(w.key==="Enter"||w.key===" "))w.preventDefault()},Z=(w)=>{if(!x)w.preventDefault()};n.addEventListener("visibilitychange",D),n.addEventListener("close",D,!0),k?.addEventListener("focus",D),k?.addEventListener("blur",D),k?.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),k?.removeEventListener("focus",D),k?.removeEventListener("blur",D),k?.removeEventListener("resize",H),f.signal.removeEventListener("abort",O),m.remove(),p.changed===S)p.changed=void 0};m.addEventListener("close",()=>{let w=m.returnValue;G(),g(w==="allow"||w==="always"?w:"deny"),i()},{once:!0});try{m.showModal()}catch(w){G(),j(w),i();return}z.focus(),D(),H()})}function ae(f,n,b,p={}){let{client:i}=n;if(i.kind==="webmcp")return Promise.resolve(!0);let c=a(p.ui),{allowDelayMs:C}=p;if(i.kind!=="relay")return K({...n,client:i},b,{strings:c,allowDelayMs:C}).then((L)=>L==="allow");let{grantId:h}=i,v=o(f),E=()=>v.allows(h,n.tool);if(E())return Promise.resolve(!0);let m=p.alwaysAllow??v.offered;return K({...n,client:i},b,{strings:c,allowDelayMs:C,alwaysAllow:m!==!1&&(m===!0&&v.kept?!0:"until-reload"),allowedNow:E}).then((L)=>{if(L==="always")v.keep(h,n.tool);return L!=="deny"})}function se(f,n,b){let{client:p}=n;if(p.kind==="relay"&&o(f).allows(p.grantId,n.tool))return Promise.resolve(!0);if(b===void 0)return f.confirmInPage(n);return Promise.resolve().then(()=>b(n)).then((i)=>i==="unanswered"?i:i===!0)}export{se as confirmCall,ae as confirmInPage};
2
+
3
+ //# debugId=2DBF4F0700228B9D64756E2164756E21
4
+ //# sourceMappingURL=confirm-zrz65vva.min.js.map
@@ -0,0 +1,10 @@
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\tLocalClient,\n\tRelayClient,\n} from \"./types.ts\";\n\n/** A request the dialog is shown for: never a WebMCP call's (DEC-215). */\nexport type AskedRequest = ConfirmRequest & {\n\tclient: RelayClient | LocalClient;\n};\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/**\n * Tests only: the delay a dialog gets when its caller passes none, for tests\n * whose subject is not the delay (the library's own `TabMcp` passes none).\n * Pages never change it; it starts as {@link ALLOW_DELAY_MS}.\n */\nexport const confirmTiming: { allowDelayMs: number } = {\n\tallowDelayMs: ALLOW_DELAY_MS,\n};\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: AskedRequest,\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: AskedRequest,\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 ?? confirmTiming.allowDelayMs;\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. Those only for an AI app through\n * the relay: a served port has no identity to remember an answer for\n * (DEC-115, DEC-124). A WebMCP call is never shown it (an agent that drives\n * the tab would answer it itself; DEC-215): it resolves `true`.\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\tif (client.kind === \"webmcp\") return Promise.resolve(true);\n\tconst strings = stringsOf(options.ui);\n\tconst { allowDelayMs } = options;\n\tif (client.kind !== \"relay\")\n\t\treturn confirmDialog({ ...request, client }, doc, {\n\t\t\tstrings,\n\t\t\tallowDelayMs,\n\t\t}).then((answer) => answer === \"allow\");\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, client }, 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": "4JAwCA,SAAS,EAAa,CAAC,EAAmD,CACzE,GAAI,CACH,OAAO,EAAQ,KAAK,UAAU,EAAM,KAAM,CAAC,CAAC,EAC3C,KAAM,CACP,QAQK,IAAM,GAAiB,IAOjB,GAA0C,CACtD,aAAc,EACf,EAMM,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,EAAQ,CAAE,MAAO,GAAO,QAAS,CAAC,CAAE,EACpC,EAAO,IAAI,EAAK,CAAK,EAEtB,IAAM,EAAI,EAEJ,EAAO,IAAM,CAClB,IAAM,EAAQ,EAAE,QAAQ,MAAM,EAC9B,EAAE,MAAQ,IAAU,OACpB,IAAQ,EACR,EAAE,UAAU,GAEP,EAAO,IAAM,CAClB,GAAI,CACH,OAAO,GAAY,EAAS,EAAK,EAAS,EAAG,CAA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<=2048,s=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!a&&!s)return;let i={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))i.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((v)=>String(v).toLowerCase()).filter((v)=>Et.test(v)):[];if(u.length>0)i.sizes=u;if(o==="light"||o==="dark")i.theme=o;return i}function Ae(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?At(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 Ae([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let o=n.getAttribute("sizes");if(o)r.sizes=o.trim().split(/\s+/);let a=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(a)r.theme=a[1]?.toLowerCase();return r}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let r=Array.isArray(e),o=Array.isArray(t);if(r!==o)return!1;if(r){let a=e.length;if(a!==t.length)return!1;for(let s=0;s<a;s++)if(!ue(e[s],t[s]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let a=Object.keys(e),s=Object.keys(t);if(a.length!==s.length)return!1;for(let u of a){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function J(e){return encodeURI(Ot(e)).replace(/#/g,"%23")}function Ot(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var Pt=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,Nt=/^%[0-9A-Fa-f]{2}$/,jt=/^[A-Za-z0-9._~-]$/;function qt(e){let t="";for(let n=0;n<e.length;){let r=e[n],o=e.slice(n,n+3);if(r==="%"&&Nt.test(o)){let s=String.fromCharCode(parseInt(o.slice(1),16));t+=jt.test(s)?s:o.toUpperCase(),n+=3;continue}let a=String.fromCodePoint(e.codePointAt(n));t+=Pt.test(a)?a:encodeURIComponent(a),n+=a.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?qt(n.hash.slice(1)):"",n}var Ht={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},zt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Dt={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},Bt=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=Bt,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let a=e.$id||e.id;if(a){let s=$e(a,n);if(s.hash.length>1)t[s.href]=e;else if(s.hash="",r==="")n=s;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let o=n.href+(r?"#"+r:"");if(t[o]!==void 0&&t[o]!==e)throw Error(`Duplicate schema URI "${o}".`);if(t[o]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:o});if(e.$ref&&e.__absolute_ref__===void 0){let a=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:a.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let a=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:a.href})}if(e.$anchor){let a=$e("#"+e.$anchor,n);t[a.href]=e}for(let a in e){if(Dt[a])continue;let s=`${r}/${J(a)}`,i=e[a];if(Array.isArray(i)){if(Ht[a]){let u=i.length;for(let v=0;v<u;v++)Z(i[v],t,n,`${s}/${v}`)}}else if(zt[a])for(let u in i)Z(i[u],t,n,`${s}/${J(u)}`);else Z(i,t,n,s)}return t}var Jt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Ut=[0,31,28,31,30,31,30,31,31,30,31,30,31],Vt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Ze=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i,Gt=/^(?:[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?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ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,Kt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Yt=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Xt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Zt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Qt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Lt=(e)=>{let t=e.match(Qt);if(!t)return!1;let n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){let o=r.slice(1,-1);if(/^ipv6:/i.test(o))return Le.test(o.slice(5));return Qe.test(o)}return Ze.test(r)},Qe=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Le=/^((([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,en=(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 Oe={date:et,time:tt.bind(void 0,!0),"date-time":rn,duration:en,uri:an,"uri-reference":G(Gt),"uri-template":G(Wt),url:G(Ft),email:Lt,hostname:G(Ze),ipv4:G(Qe),ipv6:G(Le),regex:un,uuid:G(Kt),"json-pointer":G(Yt),"json-pointer-uri-fragment":G(Xt),"relative-json-pointer":G(Zt)};function tn(e){return e%4===0&&(e%100!==0||e%400===0)}function et(e){let t=e.match(Jt);if(!t)return!1;let n=t[1],r=t[2],o=t[3];if(!n||!r||!o)return!1;let a=+n,s=+r,i=+o,u=s==2&&tn(a)?29:Ut[s];return s>=1&&s<=12&&i>=1&&u!==void 0&&i<=u}function tt(e,t){let n=t.match(Vt);if(!n)return!1;let r=n[1],o=n[2],a=n[3];if(!r||!o||!a)return!1;let s=+r,i=+o,u=+a,v=n[5],k=n[6],M=+(n[7]??0),S=+(n[8]??0);if(s>23||i>59||u>60||M>23||S>59||e&&v===void 0)return!1;if(u<60)return!0;let N=k==="+"?1:k==="-"?-1:0;return(s*60+i-N*(M*60+S)+1440)%1440===1439}var nn=/t|\s/i;function rn(e){let[t,n,r]=e.split(nn);return t!==void 0&&n!==void 0&&r===void 0&&et(t)&&tt(!0,n)}var on=/\/|:/,sn=/^(?:[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 an(e){return on.test(e)&&sn.test(e)}var dn=/[^\\]\\Z/;function un(e){if(dn.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function nt(e){let t=0,n=e.length,r=0,o;while(r<n)if(t++,o=e.charCodeAt(r++),o>=55296&&o<=56319&&r<n){if(o=e.charCodeAt(r),(o&64512)==56320)r++}return t}function oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function rt(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",o=n.indexOf("."),a=o===-1?0:n.length-o-1;return[BigInt(n.replace(".","")),Number(r)-a]}function ln(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=rt(e),[o,a]=rt(t),s=r-a;if(s>=0)return n*10n**BigInt(s)%o===0n;return n%(o*10n**BigInt(-s))===0n}function j(e,t,n="2019-09",r=Z(t),o=!0,a=null,s="#",i="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:s,keyword:"false",keywordLocation:s,error:"False boolean schema."}]};let 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:S,$recursiveAnchor:N,type:C,const:O,enum:q,required:U,not:f,anyOf:y,allOf:g,oneOf:b,if:h,then:R,else:A,format:E,properties:d,patternProperties:_,additionalProperties:H,unevaluatedProperties:z,minProperties:X,maxProperties:V,propertyNames:ee,dependentRequired:te,dependentSchemas:Ve,dependencies:Ie,prefixItems:Me,items:ce,additionalItems:Ge,unevaluatedItems:We,contains:Fe,minContains:K,maxContains:Se,minItems:_e,maxItems:Ce,uniqueItems:_t,minimum:ne,maximum:re,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ee,minLength:ye,maxLength:ge,pattern:Ke,__absolute_ref__:he,__absolute_recursive_ref__:Ct}=t,c=[];if(N===!0&&a===null)a=t;if(S==="#"){let T=a===null?r[Ct]:a,m=`${i}/$recursiveRef`,I=j(e,a===null?t:a,n,r,o,T,s,m,u);if(!I.valid)c.push({instanceLocation:s,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(M!==void 0){let m=r[he||M];if(m===void 0){let l=`Unresolved $ref "${M}".`;if(he&&he!==M)l+=` Absolute URI "${he}".`;throw l+=`
1
+ var Et=/^(?:\d{1,4}x\d{1,4}|any)$/;function At(e){let{src:t,mimeType:n,sizes:r,theme:o}=e;if(typeof t!=="string")return;let a=/^https?:/i.test(t)&&t.length<=2048,s=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!a&&!s)return;let i={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))i.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((v)=>String(v).toLowerCase()).filter((v)=>Et.test(v)):[];if(u.length>0)i.sizes=u;if(o==="light"||o==="dark")i.theme=o;return i}function Ae(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?At(n):void 0;if(r!==void 0)t.push(r);if(t.length===8)break}return t}function we(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return Ae([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let o=n.getAttribute("sizes");if(o)r.sizes=o.trim().split(/\s+/);let a=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(a)r.theme=a[1]?.toLowerCase();return r}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let r=Array.isArray(e),o=Array.isArray(t);if(r!==o)return!1;if(r){let a=e.length;if(a!==t.length)return!1;for(let s=0;s<a;s++)if(!ue(e[s],t[s]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let a=Object.keys(e),s=Object.keys(t);if(a.length!==s.length)return!1;for(let u of a){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function J(e){return encodeURI(Ot(e)).replace(/#/g,"%23")}function Ot(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var Pt=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,Nt=/^%[0-9A-Fa-f]{2}$/,jt=/^[A-Za-z0-9._~-]$/;function qt(e){let t="";for(let n=0;n<e.length;){let r=e[n],o=e.slice(n,n+3);if(r==="%"&&Nt.test(o)){let s=String.fromCharCode(parseInt(o.slice(1),16));t+=jt.test(s)?s:o.toUpperCase(),n+=3;continue}let a=String.fromCodePoint(e.codePointAt(n));t+=Pt.test(a)?a:encodeURIComponent(a),n+=a.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?qt(n.hash.slice(1)):"",n}var Ht={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},zt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Dt={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},Bt=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=Bt,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let a=e.$id||e.id;if(a){let s=$e(a,n);if(s.hash.length>1)t[s.href]=e;else if(s.hash="",r==="")n=s;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let o=n.href+(r?"#"+r:"");if(t[o]!==void 0&&t[o]!==e)throw Error(`Duplicate schema URI "${o}".`);if(t[o]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:o});if(e.$ref&&e.__absolute_ref__===void 0){let a=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:a.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let a=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:a.href})}if(e.$anchor){let a=$e("#"+e.$anchor,n);t[a.href]=e}for(let a in e){if(Dt[a])continue;let s=`${r}/${J(a)}`,i=e[a];if(Array.isArray(i)){if(Ht[a]){let u=i.length;for(let v=0;v<u;v++)Z(i[v],t,n,`${s}/${v}`)}}else if(zt[a])for(let u in i)Z(i[u],t,n,`${s}/${J(u)}`);else Z(i,t,n,s)}return t}var Jt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Ut=[0,31,28,31,30,31,30,31,31,30,31,30,31],Vt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Ze=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?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-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Lt=(e)=>{let t=e.match(Qt);if(!t)return!1;let n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){let o=r.slice(1,-1);if(/^ipv6:/i.test(o))return Le.test(o.slice(5));return Qe.test(o)}return Ze.test(r)},Qe=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Le=/^((([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,en=(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 Oe={date:et,time:tt.bind(void 0,!0),"date-time":rn,duration:en,uri:an,"uri-reference":G(Gt),"uri-template":G(Wt),url:G(Ft),email:Lt,hostname:G(Ze),ipv4:G(Qe),ipv6:G(Le),regex:un,uuid:G(Kt),"json-pointer":G(Yt),"json-pointer-uri-fragment":G(Xt),"relative-json-pointer":G(Zt)};function tn(e){return e%4===0&&(e%100!==0||e%400===0)}function et(e){let t=e.match(Jt);if(!t)return!1;let n=t[1],r=t[2],o=t[3];if(!n||!r||!o)return!1;let a=+n,s=+r,i=+o,u=s==2&&tn(a)?29:Ut[s];return s>=1&&s<=12&&i>=1&&u!==void 0&&i<=u}function tt(e,t){let n=t.match(Vt);if(!n)return!1;let r=n[1],o=n[2],a=n[3];if(!r||!o||!a)return!1;let s=+r,i=+o,u=+a,v=n[5],k=n[6],M=+(n[7]??0),S=+(n[8]??0);if(s>23||i>59||u>60||M>23||S>59||e&&v===void 0)return!1;if(u<60)return!0;let N=k==="+"?1:k==="-"?-1:0;return(s*60+i-N*(M*60+S)+1440)%1440===1439}var nn=/t|\s/i;function rn(e){let[t,n,r]=e.split(nn);return t!==void 0&&n!==void 0&&r===void 0&&et(t)&&tt(!0,n)}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/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function an(e){return on.test(e)&&sn.test(e)}var dn=/[^\\]\\Z/;function un(e){if(dn.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function nt(e){let t=0,n=e.length,r=0,o;while(r<n)if(t++,o=e.charCodeAt(r++),o>=55296&&o<=56319&&r<n){if(o=e.charCodeAt(r),(o&64512)==56320)r++}return t}function oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function rt(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",o=n.indexOf("."),a=o===-1?0:n.length-o-1;return[BigInt(n.replace(".","")),Number(r)-a]}function ln(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=rt(e),[o,a]=rt(t),s=r-a;if(s>=0)return n*10n**BigInt(s)%o===0n;return n%(o*10n**BigInt(-s))===0n}function j(e,t,n="2019-09",r=Z(t),o=!0,a=null,s="#",i="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:s,keyword:"false",keywordLocation:s,error:"False boolean schema."}]};let 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:S,$recursiveAnchor:N,type:_,const:O,enum:q,required:U,not:f,anyOf:y,allOf:g,oneOf:w,if:h,then:R,else:A,format:E,properties:d,patternProperties:C,additionalProperties:H,unevaluatedProperties:z,minProperties:X,maxProperties:V,propertyNames:ee,dependentRequired:te,dependentSchemas:Ve,dependencies:Ie,prefixItems:Me,items:ce,additionalItems:Ge,unevaluatedItems:We,contains:Fe,minContains:K,maxContains:Se,minItems:Ce,maxItems:_e,uniqueItems:Ct,minimum:ne,maximum:re,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ee,minLength:ye,maxLength:ge,pattern:Ke,__absolute_ref__:he,__absolute_recursive_ref__:_t}=t,c=[];if(N===!0&&a===null)a=t;if(S==="#"){let T=a===null?r[_t]:a,m=`${i}/$recursiveRef`,I=j(e,a===null?t:a,n,r,o,T,s,m,u);if(!I.valid)c.push({instanceLocation:s,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(M!==void 0){let m=r[he||M];if(m===void 0){let l=`Unresolved $ref "${M}".`;if(he&&he!==M)l+=` Absolute URI "${he}".`;throw l+=`
2
2
  Known schemas:
3
3
  - ${Object.keys(r).join(`
4
- - `)}`,Error(l)}let I=`${i}/$ref`,p=j(e,m,n,r,o,a,s,I,u);if(!p.valid)c.push({instanceLocation:s,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...p.errors);if(n==="4"||n==="7")return{valid:c.length===0,errors:c}}if(Array.isArray(C)){let T=C.length,m=!1;for(let I=0;I<T;I++)if(k===C[I]||C[I]==="integer"&&k==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(k!=="number"||e%1||e!==e)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${C}".`})}else if(C!==void 0&&k!==C)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${C}".`});if(O!==void 0){if(k==="object"||k==="array"){if(!ue(e,O))c.push({instanceLocation:s,keyword:"const",keywordLocation:`${i}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:s,keyword:"const",keywordLocation:`${i}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}if(q!==void 0){if(k==="object"||k==="array"){if(!q.some((T)=>ue(e,T)))c.push({instanceLocation:s,keyword:"enum",keywordLocation:`${i}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}else if(!q.some((T)=>e===T))c.push({instanceLocation:s,keyword:"enum",keywordLocation:`${i}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}if(f!==void 0){let T=`${i}/not`;if(j(e,f,n,r,o,a,s,T).valid)c.push({instanceLocation:s,keyword:"not",keywordLocation:T,error:'Instance matched "not" schema.'})}let we=[];if(y!==void 0){let T=`${i}/anyOf`,m=c.length,I=!1;for(let[p,l]of y.entries()){let x=Object.create(u),w=j(e,l,n,r,o,N===!0?a:null,s,`${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:s,keyword:"anyOf",keywordLocation:T,error:"Instance does not match any subschemas."})}if(g!==void 0){let T=`${i}/allOf`,m=c.length,I=!0;for(let[p,l]of g.entries()){let x=Object.create(u),w=j(e,l,n,r,o,N===!0?a:null,s,`${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:s,keyword:"allOf",keywordLocation:T,error:"Instance does not match every subschema."})}if(b!==void 0){let T=`${i}/oneOf`,m=c.length,I=b.filter((p,l)=>{let x=Object.create(u),w=j(e,p,n,r,o,N===!0?a:null,s,`${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:s,keyword:"oneOf",keywordLocation:T,error:`Instance does not match exactly one subschema (${I} matches).`})}if(k==="object"||k==="array")Object.assign(u,...we);if(h!==void 0){let T=`${i}/if`,m=Object.create(null);if(j(e,h,n,r,o,a,s,T,m).valid){if(Object.assign(u,m),R!==void 0){let p=j(e,R,n,r,o,a,s,`${i}/then`,u);if(!p.valid)c.push({instanceLocation:s,keyword:"if",keywordLocation:T,error:'Instance does not match "then" schema.'},...p.errors)}}else if(A!==void 0){let p=j(e,A,n,r,o,a,s,`${i}/else`,u);if(!p.valid)c.push({instanceLocation:s,keyword:"if",keywordLocation:T,error:'Instance does not match "else" schema.'},...p.errors)}}if(k==="object"){if(U!==void 0){for(let p of U)if(!oe(e,p))c.push({instanceLocation:s,keyword:"required",keywordLocation:`${i}/required`,error:`Instance does not have required property "${p}".`})}let T=Object.keys(e);if(X!==void 0&&T.length<X)c.push({instanceLocation:s,keyword:"minProperties",keywordLocation:`${i}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&T.length>V)c.push({instanceLocation:s,keyword:"maxProperties",keywordLocation:`${i}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(ee!==void 0){let p=`${i}/propertyNames`;for(let l in e){let x=`${s}/${J(l)}`,w=j(l,ee,n,r,o,a,x,p);if(!w.valid)c.push({instanceLocation:s,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...w.errors)}}if(te!==void 0){let p=`${i}/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:s,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}}if(Ve!==void 0)for(let[p,l]of Object.entries(Ve)){let x=`${i}/dependentSchemas`;if(oe(e,p)){let w=j(e,l,n,r,o,a,s,`${x}/${J(p)}`,u);if(!w.valid)c.push({instanceLocation:s,keyword:"dependentSchemas",keywordLocation:x,error:`Instance has "${p}" but does not match dependant schema.`},...w.errors)}}if(Ie!==void 0){let p=`${i}/dependencies`;for(let l in Ie)if(oe(e,l)){let x=Ie[l];if(Array.isArray(x)){for(let w of x)if(!oe(e,w))c.push({instanceLocation:s,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}else{let w=j(e,x,n,r,o,a,s,`${p}/${J(l)}`);if(!w.valid)c.push({instanceLocation:s,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not match dependant schema.`},...w.errors)}}}let m=Object.create(null),I=!1;if(d!==void 0){let p=`${i}/properties`;for(let[l,x]of Object.entries(d)){if(!oe(e,l))continue;let w=`${s}/${J(l)}`,D=j(e[l],x,n,r,o,a,w,`${p}/${J(l)}`);if(m[l]=!0,D.valid)u[l]=!0;else if(I=o,c.push({instanceLocation:s,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...D.errors),I)break}}if(!I&&_!==void 0){let p=`${i}/patternProperties`;for(let[l,x]of Object.entries(_)){let w=new RegExp(l,"u");for(let D in e){if(!w.test(D))continue;let Ye=`${s}/${J(D)}`,Xe=j(e[D],x,n,r,o,a,Ye,`${p}/${J(l)}`);if(m[D]=!0,Xe.valid)u[D]=!0;else I=o,c.push({instanceLocation:s,keyword:"patternProperties",keywordLocation:p,error:`Property "${D}" matches pattern "${l}" but does not match associated schema.`},...Xe.errors)}}}if(!I&&H!==void 0){let p=`${i}/additionalProperties`;for(let l in e){if(m[l])continue;let x=`${s}/${J(l)}`,w=j(e[l],H,n,r,o,a,x,p);if(w.valid)u[l]=!0;else I=o,c.push({instanceLocation:s,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...w.errors)}}else if(!I&&z!==void 0){let p=`${i}/unevaluatedProperties`;for(let l in e)if(!u[l]){let x=`${s}/${J(l)}`,w=j(e[l],z,n,r,o,a,x,p);if(w.valid)u[l]=!0;else c.push({instanceLocation:s,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...w.errors)}}}else if(k==="array"){if(Ce!==void 0&&e.length>Ce)c.push({instanceLocation:s,keyword:"maxItems",keywordLocation:`${i}/maxItems`,error:`Array has too many items (${e.length} > ${Ce}).`});if(_e!==void 0&&e.length<_e)c.push({instanceLocation:s,keyword:"minItems",keywordLocation:`${i}/minItems`,error:`Array has too few items (${e.length} < ${_e}).`});let T=e.length,m=0,I=!1;if(Me!==void 0){let p=`${i}/prefixItems`,l=Math.min(Me.length,T);for(;m<l;m++){let x=j(e[m],Me[m],n,r,o,a,`${s}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=o,c.push({instanceLocation:s,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...x.errors),I)break}}}if(ce!==void 0){let p=`${i}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,T);for(;m<l;m++){let x=j(e[m],ce[m],n,r,o,a,`${s}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=o,c.push({instanceLocation:s,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,o,a,`${s}/${m}`,p);if(u[m]=!0,!l.valid){if(I=o,c.push({instanceLocation:s,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&Ge!==void 0){let l=`${i}/additionalItems`;for(;m<T;m++){let x=j(e[m],Ge,n,r,o,a,`${s}/${m}`,l);if(u[m]=!0,!x.valid)I=o,c.push({instanceLocation:s,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...x.errors)}}}if(Fe!==void 0)if(T===0&&K===void 0)c.push({instanceLocation:s,keyword:"contains",keywordLocation:`${i}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(K!==void 0&&T<K)c.push({instanceLocation:s,keyword:"minContains",keywordLocation:`${i}/minContains`,error:`Array has less items (${T}) than minContains (${K}).`});else{let p=`${i}/contains`,l=c.length,x=0;for(let w=0;w<T;w++){let D=j(e[w],Fe,n,r,o,a,`${s}/${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:s,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&x<K)c.push({instanceLocation:s,keyword:"minContains",keywordLocation:`${i}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${x} items were found.`});else if(Se!==void 0&&x>Se)c.push({instanceLocation:s,keyword:"maxContains",keywordLocation:`${i}/maxContains`,error:`Array may contain at most ${Se} items matching schema. ${x} items were found.`})}if(!I&&We!==void 0){let p=`${i}/unevaluatedItems`;for(m;m<T;m++){if(u[m])continue;let l=j(e[m],We,n,r,o,a,`${s}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:s,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(_t)for(let p=0;p<T;p++){let l=e[p],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:s,keyword:"uniqueItems",keywordLocation:`${i}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${w}.`}),p=Number.MAX_SAFE_INTEGER,w=Number.MAX_SAFE_INTEGER}}}else if(k==="number"){if(n==="4"){if(ne!==void 0&&(pe===!0&&e<=ne||e<ne))c.push({instanceLocation:s,keyword:"minimum",keywordLocation:`${i}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${ne}.`});if(re!==void 0&&(me===!0&&e>=re||e>re))c.push({instanceLocation:s,keyword:"maximum",keywordLocation:`${i}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${re}.`})}else{if(ne!==void 0&&e<ne)c.push({instanceLocation:s,keyword:"minimum",keywordLocation:`${i}/minimum`,error:`${e} is less than ${ne}.`});if(re!==void 0&&e>re)c.push({instanceLocation:s,keyword:"maximum",keywordLocation:`${i}/maximum`,error:`${e} is greater than ${re}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:s,keyword:"exclusiveMinimum",keywordLocation:`${i}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:s,keyword:"exclusiveMaximum",keywordLocation:`${i}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ee!==void 0){if(!ln(e,Ee))c.push({instanceLocation:s,keyword:"multipleOf",keywordLocation:`${i}/multipleOf`,error:`${e} is not a multiple of ${Ee}.`})}}else if(k==="string"){let T=ye===void 0&&ge===void 0?0:nt(e);if(ye!==void 0&&T<ye)c.push({instanceLocation:s,keyword:"minLength",keywordLocation:`${i}/minLength`,error:`String is too short (${T} < ${ye}).`});if(ge!==void 0&&T>ge)c.push({instanceLocation:s,keyword:"maxLength",keywordLocation:`${i}/maxLength`,error:`String is too long (${T} > ${ge}).`});if(Ke!==void 0&&!new RegExp(Ke,"u").test(e))c.push({instanceLocation:s,keyword:"pattern",keywordLocation:`${i}/pattern`,error:"String does not match pattern."});if(E!==void 0&&Oe[E]&&!Oe[E](e))c.push({instanceLocation:s,keyword:"format",keywordLocation:`${i}/format`,error:`String does not match format "${E}".`})}return{valid:c.length===0,errors:c}}var ot="ch.ractive.tab-mcp/annotations",fn=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],cn=["destructiveHint","idempotentHint","openWorldHint"];function st(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let o of cn){let a=e[o];if(a!==void 0)t[o]=a}let n={};for(let o of fn){let a=e[o];if(a!==void 0)n[o]=a}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function it(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 pn(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 mn=new Set(["content","structuredContent","isError","_meta","resultType"]);function at(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:o}=e;return(t.length>0?t.every(pn):Object.keys(e).every((a)=>mn.has(a)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(o===void 0||Y(o))}function dt(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(at(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 Pe(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(`
4
+ - `)}`,Error(l)}let I=`${i}/$ref`,p=j(e,m,n,r,o,a,s,I,u);if(!p.valid)c.push({instanceLocation:s,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...p.errors);if(n==="4"||n==="7")return{valid:c.length===0,errors:c}}if(Array.isArray(_)){let T=_.length,m=!1;for(let I=0;I<T;I++)if(k===_[I]||_[I]==="integer"&&k==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${_.join('", "')}".`})}else if(_==="integer"){if(k!=="number"||e%1||e!==e)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${_}".`})}else if(_!==void 0&&k!==_)c.push({instanceLocation:s,keyword:"type",keywordLocation:`${i}/type`,error:`Instance type "${k}" is invalid. Expected "${_}".`});if(O!==void 0){if(k==="object"||k==="array"){if(!ue(e,O))c.push({instanceLocation:s,keyword:"const",keywordLocation:`${i}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:s,keyword:"const",keywordLocation:`${i}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}if(q!==void 0){if(k==="object"||k==="array"){if(!q.some((T)=>ue(e,T)))c.push({instanceLocation:s,keyword:"enum",keywordLocation:`${i}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}else if(!q.some((T)=>e===T))c.push({instanceLocation:s,keyword:"enum",keywordLocation:`${i}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}if(f!==void 0){let T=`${i}/not`;if(j(e,f,n,r,o,a,s,T).valid)c.push({instanceLocation:s,keyword:"not",keywordLocation:T,error:'Instance matched "not" schema.'})}let be=[];if(y!==void 0){let T=`${i}/anyOf`,m=c.length,I=!1;for(let[p,l]of y.entries()){let x=Object.create(u),b=j(e,l,n,r,o,N===!0?a:null,s,`${T}/${p}`,x);if(c.push(...b.errors),I=I||b.valid,b.valid)be.push(x)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:s,keyword:"anyOf",keywordLocation:T,error:"Instance does not match any subschemas."})}if(g!==void 0){let T=`${i}/allOf`,m=c.length,I=!0;for(let[p,l]of g.entries()){let x=Object.create(u),b=j(e,l,n,r,o,N===!0?a:null,s,`${T}/${p}`,x);if(c.push(...b.errors),I=I&&b.valid,b.valid)be.push(x)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:s,keyword:"allOf",keywordLocation:T,error:"Instance does not match every subschema."})}if(w!==void 0){let T=`${i}/oneOf`,m=c.length,I=w.filter((p,l)=>{let x=Object.create(u),b=j(e,p,n,r,o,N===!0?a:null,s,`${T}/${l}`,x);if(c.push(...b.errors),b.valid)be.push(x);return b.valid}).length;if(I===1)c.length=m;else c.splice(m,0,{instanceLocation:s,keyword:"oneOf",keywordLocation:T,error:`Instance does not match exactly one subschema (${I} matches).`})}if(k==="object"||k==="array")Object.assign(u,...be);if(h!==void 0){let T=`${i}/if`,m=Object.create(null);if(j(e,h,n,r,o,a,s,T,m).valid){if(Object.assign(u,m),R!==void 0){let p=j(e,R,n,r,o,a,s,`${i}/then`,u);if(!p.valid)c.push({instanceLocation:s,keyword:"if",keywordLocation:T,error:'Instance does not match "then" schema.'},...p.errors)}}else if(A!==void 0){let p=j(e,A,n,r,o,a,s,`${i}/else`,u);if(!p.valid)c.push({instanceLocation:s,keyword:"if",keywordLocation:T,error:'Instance does not match "else" schema.'},...p.errors)}}if(k==="object"){if(U!==void 0){for(let p of U)if(!oe(e,p))c.push({instanceLocation:s,keyword:"required",keywordLocation:`${i}/required`,error:`Instance does not have required property "${p}".`})}let T=Object.keys(e);if(X!==void 0&&T.length<X)c.push({instanceLocation:s,keyword:"minProperties",keywordLocation:`${i}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&T.length>V)c.push({instanceLocation:s,keyword:"maxProperties",keywordLocation:`${i}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(ee!==void 0){let p=`${i}/propertyNames`;for(let l in e){let x=`${s}/${J(l)}`,b=j(l,ee,n,r,o,a,x,p);if(!b.valid)c.push({instanceLocation:s,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...b.errors)}}if(te!==void 0){let p=`${i}/dependantRequired`;for(let l in te)if(oe(e,l)){let x=te[l];for(let b of x)if(!oe(e,b))c.push({instanceLocation:s,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${b}".`})}}if(Ve!==void 0)for(let[p,l]of Object.entries(Ve)){let x=`${i}/dependentSchemas`;if(oe(e,p)){let b=j(e,l,n,r,o,a,s,`${x}/${J(p)}`,u);if(!b.valid)c.push({instanceLocation:s,keyword:"dependentSchemas",keywordLocation:x,error:`Instance has "${p}" but does not match dependant schema.`},...b.errors)}}if(Ie!==void 0){let p=`${i}/dependencies`;for(let l in Ie)if(oe(e,l)){let x=Ie[l];if(Array.isArray(x)){for(let b of x)if(!oe(e,b))c.push({instanceLocation:s,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${b}".`})}else{let b=j(e,x,n,r,o,a,s,`${p}/${J(l)}`);if(!b.valid)c.push({instanceLocation:s,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not match dependant schema.`},...b.errors)}}}let m=Object.create(null),I=!1;if(d!==void 0){let p=`${i}/properties`;for(let[l,x]of Object.entries(d)){if(!oe(e,l))continue;let b=`${s}/${J(l)}`,D=j(e[l],x,n,r,o,a,b,`${p}/${J(l)}`);if(m[l]=!0,D.valid)u[l]=!0;else if(I=o,c.push({instanceLocation:s,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...D.errors),I)break}}if(!I&&C!==void 0){let p=`${i}/patternProperties`;for(let[l,x]of Object.entries(C)){let b=new RegExp(l,"u");for(let D in e){if(!b.test(D))continue;let Ye=`${s}/${J(D)}`,Xe=j(e[D],x,n,r,o,a,Ye,`${p}/${J(l)}`);if(m[D]=!0,Xe.valid)u[D]=!0;else I=o,c.push({instanceLocation:s,keyword:"patternProperties",keywordLocation:p,error:`Property "${D}" matches pattern "${l}" but does not match associated schema.`},...Xe.errors)}}}if(!I&&H!==void 0){let p=`${i}/additionalProperties`;for(let l in e){if(m[l])continue;let x=`${s}/${J(l)}`,b=j(e[l],H,n,r,o,a,x,p);if(b.valid)u[l]=!0;else I=o,c.push({instanceLocation:s,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...b.errors)}}else if(!I&&z!==void 0){let p=`${i}/unevaluatedProperties`;for(let l in e)if(!u[l]){let x=`${s}/${J(l)}`,b=j(e[l],z,n,r,o,a,x,p);if(b.valid)u[l]=!0;else c.push({instanceLocation:s,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...b.errors)}}}else if(k==="array"){if(_e!==void 0&&e.length>_e)c.push({instanceLocation:s,keyword:"maxItems",keywordLocation:`${i}/maxItems`,error:`Array has too many items (${e.length} > ${_e}).`});if(Ce!==void 0&&e.length<Ce)c.push({instanceLocation:s,keyword:"minItems",keywordLocation:`${i}/minItems`,error:`Array has too few items (${e.length} < ${Ce}).`});let T=e.length,m=0,I=!1;if(Me!==void 0){let p=`${i}/prefixItems`,l=Math.min(Me.length,T);for(;m<l;m++){let x=j(e[m],Me[m],n,r,o,a,`${s}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=o,c.push({instanceLocation:s,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...x.errors),I)break}}}if(ce!==void 0){let p=`${i}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,T);for(;m<l;m++){let x=j(e[m],ce[m],n,r,o,a,`${s}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=o,c.push({instanceLocation:s,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,o,a,`${s}/${m}`,p);if(u[m]=!0,!l.valid){if(I=o,c.push({instanceLocation:s,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&Ge!==void 0){let l=`${i}/additionalItems`;for(;m<T;m++){let x=j(e[m],Ge,n,r,o,a,`${s}/${m}`,l);if(u[m]=!0,!x.valid)I=o,c.push({instanceLocation:s,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...x.errors)}}}if(Fe!==void 0)if(T===0&&K===void 0)c.push({instanceLocation:s,keyword:"contains",keywordLocation:`${i}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(K!==void 0&&T<K)c.push({instanceLocation:s,keyword:"minContains",keywordLocation:`${i}/minContains`,error:`Array has less items (${T}) than minContains (${K}).`});else{let p=`${i}/contains`,l=c.length,x=0;for(let b=0;b<T;b++){let D=j(e[b],Fe,n,r,o,a,`${s}/${b}`,p);if(D.valid)u[b]=!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:s,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&x<K)c.push({instanceLocation:s,keyword:"minContains",keywordLocation:`${i}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${x} items were found.`});else if(Se!==void 0&&x>Se)c.push({instanceLocation:s,keyword:"maxContains",keywordLocation:`${i}/maxContains`,error:`Array may contain at most ${Se} items matching schema. ${x} items were found.`})}if(!I&&We!==void 0){let p=`${i}/unevaluatedItems`;for(m;m<T;m++){if(u[m])continue;let l=j(e[m],We,n,r,o,a,`${s}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:s,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(Ct)for(let p=0;p<T;p++){let l=e[p],x=typeof l==="object"&&l!==null;for(let b=0;b<T;b++){if(p===b)continue;let D=e[b];if(l===D||x&&(typeof D==="object"&&D!==null)&&ue(l,D))c.push({instanceLocation:s,keyword:"uniqueItems",keywordLocation:`${i}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${b}.`}),p=Number.MAX_SAFE_INTEGER,b=Number.MAX_SAFE_INTEGER}}}else if(k==="number"){if(n==="4"){if(ne!==void 0&&(pe===!0&&e<=ne||e<ne))c.push({instanceLocation:s,keyword:"minimum",keywordLocation:`${i}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${ne}.`});if(re!==void 0&&(me===!0&&e>=re||e>re))c.push({instanceLocation:s,keyword:"maximum",keywordLocation:`${i}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${re}.`})}else{if(ne!==void 0&&e<ne)c.push({instanceLocation:s,keyword:"minimum",keywordLocation:`${i}/minimum`,error:`${e} is less than ${ne}.`});if(re!==void 0&&e>re)c.push({instanceLocation:s,keyword:"maximum",keywordLocation:`${i}/maximum`,error:`${e} is greater than ${re}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:s,keyword:"exclusiveMinimum",keywordLocation:`${i}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:s,keyword:"exclusiveMaximum",keywordLocation:`${i}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ee!==void 0){if(!ln(e,Ee))c.push({instanceLocation:s,keyword:"multipleOf",keywordLocation:`${i}/multipleOf`,error:`${e} is not a multiple of ${Ee}.`})}}else if(k==="string"){let T=ye===void 0&&ge===void 0?0:nt(e);if(ye!==void 0&&T<ye)c.push({instanceLocation:s,keyword:"minLength",keywordLocation:`${i}/minLength`,error:`String is too short (${T} < ${ye}).`});if(ge!==void 0&&T>ge)c.push({instanceLocation:s,keyword:"maxLength",keywordLocation:`${i}/maxLength`,error:`String is too long (${T} > ${ge}).`});if(Ke!==void 0&&!new RegExp(Ke,"u").test(e))c.push({instanceLocation:s,keyword:"pattern",keywordLocation:`${i}/pattern`,error:"String does not match pattern."});if(E!==void 0&&Oe[E]&&!Oe[E](e))c.push({instanceLocation:s,keyword:"format",keywordLocation:`${i}/format`,error:`String does not match format "${E}".`})}return{valid:c.length===0,errors:c}}var ot="ch.ractive.tab-mcp/annotations",fn=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],cn=["destructiveHint","idempotentHint","openWorldHint"];function st(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let o of cn){let a=e[o];if(a!==void 0)t[o]=a}let n={};for(let o of fn){let a=e[o];if(a!==void 0)n[o]=a}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function it(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 pn(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 mn=new Set(["content","structuredContent","isError","_meta","resultType"]);function at(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:o}=e;return(t.length>0?t.every(pn):Object.keys(e).every((a)=>mn.has(a)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(o===void 0||Y(o))}function dt(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(at(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 Pe(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
5
  `)}function ut(e){if(at(e))return e.structuredContent??(Pe(e,!0)||"Done.");return e===void 0?"Done.":e}function lt(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",ft="io.modelcontextprotocol/clientInfo",ct="io.modelcontextprotocol/serverInfo",Ne="io.modelcontextprotocol/subscriptionId",yn=-32020,pt=-32022,gn="The page may ask the user to allow each call, usually in the page's browser tab.",hn=0,mt=new WeakMap;function je(e){let t=mt.get(e);if(t!==void 0)return t;let n=e.inputSchema,r=yt(n,"inputSchema");if(e.outputSchema!==void 0)yt(e.outputSchema,"outputSchema");let o=(a)=>j(a,n,"2020-12",r,!1);return mt.set(e,o),o}class ve extends Error{what;constructor(e,t){super(t);this.what=e}}function yt(e,t){let n;try{n=Z(e)}catch(r){let o=r instanceof Error?r.message:String(r);throw new ve(t,o.split(`
6
- `)[0]??"")}for(let r of Object.values(n)){if(typeof r!=="object"||r.$ref===void 0)continue;let o=r.__absolute_ref__;if(n[o??r.$ref]===void 0)throw new ve(t,`$ref ${JSON.stringify(r.$ref)} does not resolve`)}return n}function gt(e,t,n=""){let r=t instanceof Error?t.message:String(t),o=t instanceof ve?t.what:"inputSchema";return TypeError(`registerTool: the ${o} of ${e}: ${r}${n}`)}function wn(e){let t=[];for(let n of e.list())try{je(n)}catch(r){e.remove(n),t.push(gt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{je(n)}catch(r){throw gt(n.name,r)}}),t}function ht(e){try{return structuredClone(e)}catch{return e}}var bn=new TextEncoder;function L(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function qe(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function B(e,t,n,r,o){let a={code:n,message:r};if(o!==void 0)a.data=o;return qe(e,{jsonrpc:"2.0",id:t,error:a})}function W(e,t,n){return B(400,e,yn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return bn.encode(`event: message
6
+ `)[0]??"")}for(let r of Object.values(n)){if(typeof r!=="object"||r.$ref===void 0)continue;let o=r.__absolute_ref__;if(n[o??r.$ref]===void 0)throw new ve(t,`$ref ${JSON.stringify(r.$ref)} does not resolve`)}return n}function gt(e,t,n=""){let r=t instanceof Error?t.message:String(t),o=t instanceof ve?t.what:"inputSchema";return TypeError(`registerTool: the ${o} of ${e}: ${r}${n}`)}function bn(e){let t=[];for(let n of e.list())try{je(n)}catch(r){e.remove(n),t.push(gt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{je(n)}catch(r){throw gt(n.name,r)}}),t}function ht(e){try{return structuredClone(e)}catch{return e}}var wn=new TextEncoder;function L(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function qe(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function B(e,t,n,r,o){let a={code:n,message:r};if(o!==void 0)a.data=o;return qe(e,{jsonrpc:"2.0",id:t,error:a})}function W(e,t,n){return B(400,e,yn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return wn.encode(`event: message
7
7
  data: ${JSON.stringify(e)}
8
8
 
9
- `)}var wt={"content-type":"text/event-stream","cache-control":"no-cache"};function $n(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function xn(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),r=Uint8Array.from(n,(o)=>o.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function vn(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[ft];if(t!==void 0&&!(L(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:ft,problem:"expected {name, version}"};return}function Tn(e){let t=e.notifications;return L(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function kn(e,t){let n;try{n=je(e)(t)}catch(o){let a=o instanceof Error?o.message:String(o);return`The input schema of tool ${e.name} cannot be used: ${a}`}if(n.valid)return;let r=n.errors.filter((o)=>o.keyword!=="properties"&&o.keyword!=="$ref").map((o)=>`${o.instanceLocation} ${o.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${r||"the arguments do not match the schema"}`}async function bt(e,t,n,r,o,a){let s={id:++hn,tool:t.name,arguments:ht(n),client:{...o}};if(t.title!==void 0)s.title=t.title;let i=Date.now();e.observe?.start(s);let u={outcome:"error",result:se("Internal error")};try{if(u=await In(e,t,n,r,o),t.annotations.untrustedContentHint===!0)u.result=it(u.result);let v=r.aborted?void 0:a?.(u.result);if(v!==void 0)u={outcome:"error",result:v}}finally{e.observe?.end({id:s.id,tool:t.name,client:{...o},outcome:u.outcome,result:ht(u.result),durationMs:Date.now()-i})}return u}var Rn="The user was asked and did not answer.";async function In(e,t,n,r,o){let a=(S,N,C)=>({outcome:S,result:se(N),stop:C}),s=kn(t,n);if(s!==void 0)return a("error",s,"invalid");let i=new Promise((S,N)=>{if(r.aborted)N(r.reason);r.addEventListener("abort",()=>N(r.reason))});i.catch(()=>{});let{consequentialHint:u,destructiveHint:v}=t.annotations;if((o.kind==="webmcp"?u??v:u)===!0){let S={tool:{name:t.name,description:t.description},arguments:n,client:o,signal:r};if(t.title!==void 0)S.tool.title=t.title;let N=!1;try{N=await Promise.race([e.confirm(S),i])}catch{N=!1}if(N!==!0){if(r.aborted)return a("cancelled","The call was cancelled.","cancelled");return N==="unanswered"?a("unanswered",Rn,"unanswered"):a("declined","The user did not allow this call.","declined")}}if(r.aborted)return a("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return a("error","The tool is no longer available","gone");let M;try{let S=await Promise.race([t.execute(n,{signal:r,client:o}),i]);M={outcome:"ok",result:dt(S),returned:{value:S}}}catch(S){M={outcome:"error",result:lt(S)}}if(r.aborted)return{...M,outcome:"cancelled",stop:"cancelled"};if(M.result.isError===!0)M.outcome="error";return M}async function He(e,t,n,r,o){let a=(u)=>({error:u}),s=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return a(s);if(!L(n))return a("The input must be an object.");let i=await bt(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,o);if(i.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(i.stop==="declined")return a(`The user did not allow ${t.name} to run.`);if(i.stop==="unanswered")return a(`The user did not answer whether ${t.name} may run.`);if(i.stop==="gone")return a(s);if(i.result.isError===!0)return a(Pe(i.result)||"The tool failed.");return ut(i.returned?.value)}function Te(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let o=Ae(n.icons??[]),a=o.length>0?{...r,icons:o}:r,s=new Set,i=!1,u=(f={})=>({...f,[ct]: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} ${gn}`:f.description,y.inputSchema=f.inputSchema,f.outputSchema!==void 0)y.outputSchema=f.outputSchema;let{annotations:g,meta:b}=st(f.annotations);if(g!==void 0)y.annotations=g;if(b!==void 0)y._meta={[ot]:b};return y})}let M=(f)=>({kind:"invalid",message:f});async function S(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 bt(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 _;try{_=h(d)}catch{return se("The tool returned a result that is not JSON.")}let H=e.maxBodyBytes?.();if(H!==void 0&&_.byteLength>H)return se(`The result is ${_.byteLength} bytes; the relay passes on at most ${H}.`);R={result:d,event:_};return},E=new ReadableStream({start:(d)=>{let _=(H)=>{if(g.aborted)return;try{d.enqueue(H()),d.close()}catch{}};S(y,g,b,A).then((H)=>_(()=>H.kind==="invalid"?ae({jsonrpc:"2.0",id:f,error:{code:-32602,message:H.message}}):H.result===R?.result?R.event:h(H.result)),()=>_(()=>ae({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}})))}});return new Response(E,{status:200,headers:wt})}function C(f,y,g){let b=Tn(y),h={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[Ne]:f})}},R,A=new ReadableStream({start:(E)=>{if(E.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:b,_meta:{[Ne]:f}}})),Object.keys(b).length===0){E.enqueue(ae(h)),E.close();return}let d={id:f,send:(_)=>{try{E.enqueue(ae(_))}catch{s.delete(d)}},end:()=>{s.delete(d);try{E.enqueue(ae(h)),E.close()}catch{}}};R=d,s.add(d),g.addEventListener("abort",()=>{s.delete(d);try{E.close()}catch{}})},cancel:()=>{if(R!==void 0)s.delete(R)}});return new Response(A,{status:200,headers:wt})}function O(f,y){if(Array.isArray(y))return 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:{},E=L(A._meta)?A._meta:void 0,d=E!==void 0&&Q in E,_=typeof E?.[Q]==="string"?E[Q]:void 0,H=h!==null&&h>=ie;if(b===void 0){if(_!==void 0&&h!==null&&h!==_)return W(null,h,`the notification envelope names protocol version ${_} 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"&&(_===void 0||_<ie)){if(g==="initialize"){if(H)return W(z,h,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let V=typeof A.protocolVersion==="string"?A.protocolVersion:void 0;return q(z,V)}if(H){let V=E===void 0?["_meta"]:[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=vn(E);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&&_!==void 0&&h!==_)return W(z,h,`the body envelope names protocol version ${_} 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(_!==ie)return q(z,_);if(h===null)return W(z,"(missing)",`the body envelope names protocol version ${_} 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=xn(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,pt,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):B(400,f,pt,`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(!$n(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 E={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)E.instructions=n.instructions;return E.ttlMs=0,E.cacheScope="private",qe(200,v(h,E,{[ct]:a}))}case"tools/list":return qe(200,v(h,{tools:k(),ttlMs:0,cacheScope:"private"}));case"tools/call":return N(h,A,f.signal,y.grant);case"subscriptions/listen":return C(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(i)return;i=!0,queueMicrotask(()=>{i=!1;for(let f of[...s])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Ne]:f.id}}})})},close(){for(let f of[...s])f.end()}}}var ke="tab-mcp.v1",Mn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function $t(e){if(!fe(e)||!P(e.grantId)||!P(e.createdAt))return!1;let t=e.client;return fe(t)&&P(t.id)&&P(t.name)&&P(t.host)}function Sn(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function _n(e){return fe(e)&&Object.values(e).every(P)}function xt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return P(t.sessionId)&&P(t.address)&&P(t.origin)&&P(t.expiresAt)&&Sn(t.limits)&&Array.isArray(t.grants)&&t.grants.every($t)&&(t.appName===void 0||P(t.appName))&&(t.pairing===void 0||P(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:P(t.reason)?t.reason:""};case"http.request":return P(t.id)&&P(t.method)&&P(t.path)&&_n(t.headers)&&P(t.body)&&fe(t.grant)&&P(t.grant.grantId)&&P(t.grant.clientId)?t:void 0;case"http.cancel":return P(t.id)?t:void 0;case"pairing.code":{if(!P(t.code)||!P(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},r=t.reason;if(typeof r==="string"&&Mn.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 $t(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 Cn(e,t){let n=(r)=>r&&(r.callers?.includes(t)??!0);return{list:()=>e.list().filter(n),get:(r)=>{let o=e.get(r);return n(o)?o:void 0}}}function Je(e,t,n){let r=t.list();return e.onChange(()=>{let o=t.list();if(o.length===r.length&&o.every((a,s)=>a===r[s]))return;r=o,n()})}function Re(e,t){return{tools:t==="webmcp"?e.registry:Cn(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:!!e.onConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var En=["content-type","cache-control"];function*Be(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),o=e.charCodeAt(r-1);if(r<e.length&&o>=55296&&o<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var An=-31002,On="The page did not answer in time.";function Pn(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Ue(e){let{handler:t,send:n,timeoutMs:r}=e,o=new Map,a=!1;async function s(i){let u=new AbortController;o.get(i.id)?.abort(),o.set(i.id,u);let v=()=>!a&&o.get(i.id)===u&&!u.signal.aborted,k=!1,M="",S=Object.entries(i.headers).some(([C,O])=>C.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),N=r===void 0||S?void 0:setTimeout(()=>{if(!v())return;u.abort();let C=JSON.stringify({jsonrpc:"2.0",id:Pn(i.body),error:{code:An,message:On}});if(!k){n({type:"http.response",id:i.id,status:200,headers:{"content-type":"application/json"},body:C});return}if(M===""||M===`
9
+ `)}var bt={"content-type":"text/event-stream","cache-control":"no-cache"};function $n(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function xn(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),r=Uint8Array.from(n,(o)=>o.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function vn(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[ft];if(t!==void 0&&!(L(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:ft,problem:"expected {name, version}"};return}function Tn(e){let t=e.notifications;return L(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function kn(e,t){let n;try{n=je(e)(t)}catch(o){let a=o instanceof Error?o.message:String(o);return`The input schema of tool ${e.name} cannot be used: ${a}`}if(n.valid)return;let r=n.errors.filter((o)=>o.keyword!=="properties"&&o.keyword!=="$ref").map((o)=>`${o.instanceLocation} ${o.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${r||"the arguments do not match the schema"}`}async function wt(e,t,n,r,o,a){let s={id:++hn,tool:t.name,arguments:ht(n),client:{...o}};if(t.title!==void 0)s.title=t.title;let i=Date.now();e.observe?.start(s);let u={outcome:"error",result:se("Internal error")};try{if(u=await In(e,t,n,r,o),t.annotations.untrustedContentHint===!0)u.result=it(u.result);let v=r.aborted?void 0:a?.(u.result);if(v!==void 0)u={outcome:"error",result:v}}finally{e.observe?.end({id:s.id,tool:t.name,client:{...o},outcome:u.outcome,result:ht(u.result),durationMs:Date.now()-i})}return u}var Rn="The user was asked and did not answer.";async function In(e,t,n,r,o){let a=(S,N,_)=>({outcome:S,result:se(N),stop:_}),s=kn(t,n);if(s!==void 0)return a("error",s,"invalid");let i=new Promise((S,N)=>{if(r.aborted)N(r.reason);r.addEventListener("abort",()=>N(r.reason))});i.catch(()=>{});let{consequentialHint:u,destructiveHint:v}=t.annotations;if((o.kind==="webmcp"?u??v:u)===!0){let S={tool:{name:t.name,description:t.description},arguments:n,client:o,signal:r};if(t.title!==void 0)S.tool.title=t.title;let N=!1;try{N=await Promise.race([e.confirm(S),i])}catch{N=!1}if(N!==!0){if(r.aborted)return a("cancelled","The call was cancelled.","cancelled");return N==="unanswered"?a("unanswered",Rn,"unanswered"):a("declined","The user did not allow this call.","declined")}}if(r.aborted)return a("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return a("error","The tool is no longer available","gone");let M;try{let S=await Promise.race([t.execute(n,{signal:r,client:o}),i]);M={outcome:"ok",result:dt(S),returned:{value:S}}}catch(S){M={outcome:"error",result:lt(S)}}if(r.aborted)return{...M,outcome:"cancelled",stop:"cancelled"};if(M.result.isError===!0)M.outcome="error";return M}async function He(e,t,n,r,o){let a=(u)=>({error:u}),s=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return a(s);if(!L(n))return a("The input must be an object.");let i=await wt(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,o);if(i.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(i.stop==="declined")return a(`The user did not allow ${t.name} to run.`);if(i.stop==="unanswered")return a(`The user did not answer whether ${t.name} may run.`);if(i.stop==="gone")return a(s);if(i.result.isError===!0)return a(Pe(i.result)||"The tool failed.");return ut(i.returned?.value)}function Te(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let o=Ae(n.icons??[]),a=o.length>0?{...r,icons:o}:r,s=new Set,i=!1,u=(f={})=>({...f,[ct]: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} ${gn}`:f.description,y.inputSchema=f.inputSchema,f.outputSchema!==void 0)y.outputSchema=f.outputSchema;let{annotations:g,meta:w}=st(f.annotations);if(g!==void 0)y.annotations=g;if(w!==void 0)y._meta={[ot]:w};return y})}let M=(f)=>({kind:"invalid",message:f});async function S(f,y,g,w){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 wt(e,R,A,y,e.client(g),w)).result}}function N(f,y,g,w){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},E=new ReadableStream({start:(d)=>{let C=(H)=>{if(g.aborted)return;try{d.enqueue(H()),d.close()}catch{}};S(y,g,w,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(E,{status:200,headers:bt})}function _(f,y,g){let w=Tn(y),h={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[Ne]:f})}},R,A=new ReadableStream({start:(E)=>{if(E.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:w,_meta:{[Ne]:f}}})),Object.keys(w).length===0){E.enqueue(ae(h)),E.close();return}let d={id:f,send:(C)=>{try{E.enqueue(ae(C))}catch{s.delete(d)}},end:()=>{s.delete(d);try{E.enqueue(ae(h)),E.close()}catch{}}};R=d,s.add(d),g.addEventListener("abort",()=>{s.delete(d);try{E.close()}catch{}})},cancel:()=>{if(R!==void 0)s.delete(R)}});return new Response(A,{status:200,headers:bt})}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:w}=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:{},E=L(A._meta)?A._meta:void 0,d=E!==void 0&&Q in E,C=typeof E?.[Q]==="string"?E[Q]:void 0,H=h!==null&&h>=ie;if(w===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 w!=="string"&&typeof w!=="number")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let z=w;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=E===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=vn(E);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=xn(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,pt,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):B(400,f,pt,`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(!$n(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 w=O(f,g);if(w instanceof Response)return w;if(w==="notification")return new Response(null,{status:202});let{id:h,method:R,params:A}=w;switch(R){case"server/discover":{let E={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)E.instructions=n.instructions;return E.ttlMs=0,E.cacheScope="private",qe(200,v(h,E,{[ct]:a}))}case"tools/list":return qe(200,v(h,{tools:k(),ttlMs:0,cacheScope:"private"}));case"tools/call":return N(h,A,f.signal,y.grant);case"subscriptions/listen":return _(h,A,f.signal);default:return B(404,h,-32601,"Method not found")}}return{handle:(f,y)=>U(f,y).catch(()=>B(500,null,-32603,"Internal server error")),toolsChanged(){if(i)return;i=!0,queueMicrotask(()=>{i=!1;for(let f of[...s])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Ne]:f.id}}})})},close(){for(let f of[...s])f.end()}}}var ke="tab-mcp.v1",Mn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function $t(e){if(!fe(e)||!P(e.grantId)||!P(e.createdAt))return!1;let t=e.client;return fe(t)&&P(t.id)&&P(t.name)&&P(t.host)}function Sn(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Cn(e){return fe(e)&&Object.values(e).every(P)}function xt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return P(t.sessionId)&&P(t.address)&&P(t.origin)&&P(t.expiresAt)&&Sn(t.limits)&&Array.isArray(t.grants)&&t.grants.every($t)&&(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)&&Cn(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"&&Mn.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 $t(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 o=e.get(r);return n(o)?o:void 0}}}function Je(e,t,n){let r=t.list();return e.onChange(()=>{let o=t.list();if(o.length===r.length&&o.every((a,s)=>a===r[s]))return;r=o,n()})}function Re(e,t){return{tools:t==="webmcp"?e.registry:_n(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:!!e.onConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var En=["content-type","cache-control"];function*Be(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),o=e.charCodeAt(r-1);if(r<e.length&&o>=55296&&o<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var An=-31002,On="The page did not answer in time.";function Pn(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Ue(e){let{handler:t,send:n,timeoutMs:r}=e,o=new Map,a=!1;async function s(i){let u=new AbortController;o.get(i.id)?.abort(),o.set(i.id,u);let v=()=>!a&&o.get(i.id)===u&&!u.signal.aborted,k=!1,M="",S=Object.entries(i.headers).some(([_,O])=>_.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),N=r===void 0||S?void 0:setTimeout(()=>{if(!v())return;u.abort();let _=JSON.stringify({jsonrpc:"2.0",id:Pn(i.body),error:{code:An,message:On}});if(!k){n({type:"http.response",id:i.id,status:200,headers:{"content-type":"application/json"},body:_});return}if(M===""||M===`
10
10
 
11
11
  `)n({type:"http.response.chunk",id:i.id,data:`event: message
12
- data: ${C}
12
+ data: ${_}
13
13
 
14
- `});n({type:"http.response.end",id:i.id})},r);try{let C=new Request(`https://tab.invalid${i.path}`,{method:i.method,headers:i.headers,signal:u.signal}),O=await t.handle(C,{grant:i.grant,body:i.body});if(!v()){await O.body?.cancel().catch(()=>{});return}let q={};for(let b of En){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:i.id,status:O.status,headers:q,body:b});return}n({type:"http.response.start",id:i.id,status:O.status,headers:q});for(let h of Be(b,f)){if(!v())break;n({type:"http.response.chunk",id:i.id,data:h})}if(v())n({type:"http.response.end",id:i.id});return}n({type:"http.response.start",id:i.id,status:O.status,headers:q}),k=!0;let y=O.body.getReader(),g=new TextDecoder;u.signal.addEventListener("abort",()=>{y.cancel().catch(()=>{})});for(;;){let{done: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 Be(R,f))n({type:"http.response.chunk",id:i.id,data:A})}if(v())n({type:"http.response.end",id:i.id})}catch(C){if(v())e.error(C instanceof Error?C:Error(String(C))),n({type:"http.response",id:i.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(clearTimeout(N),o.get(i.id)===u)o.delete(i.id)}}return{request(i){if(!a)s(i)},cancel(i){o.get(i)?.abort(),o.delete(i)},close(){if(a)return;a=!0;for(let i of o.values())i.abort();o.clear()}}}var Nn=65536,vt=64,jn=300000,Tt=128,ze=new WeakSet,qn=0,F=(e)=>typeof e==="string";function De(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Hn(e,t,n){let r=n?.client;if(!De(r)||!F(r.id)||r.id===""||r.name!==void 0&&!F(r.name))throw TypeError("serve: client needs an id (and may have a name)");let o=n.maxChunk??Nn;if(!Number.isInteger(o)||o<vt)throw TypeError(`serve: maxChunk must be a whole number of at least ${vt}`);let a=n.requestTimeoutMs??jn;if(typeof a!=="number"||!(a>0)||a>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let s=n.onConfirm;if(s!==void 0&&typeof s!=="function")throw TypeError("serve: onConfirm must be a function");if(typeof t?.postMessage!=="function"||!("onmessage"in t))throw TypeError("serve: the port needs postMessage and onmessage");if(ze.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let i={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")i.name=r.name;let u={grantId:`local:${++qn}`,clientId:r.id,scopes:["tools"]},v=!1,k=(y)=>{if(v)return!1;try{return t.postMessage(y),!0}catch{return!1}},M=Re(e,"local");if(s!==void 0)M.confirm=(y)=>Promise.resolve().then(()=>s(y)).then((g)=>g==="unanswered"?g:g===!0),M.ownConfirm=!0;let S=Te({...M,server:{...e.server,icons:e.server.icons??be()},client:()=>({...i})}),N=Je(e.registry,M.tools,()=>S.toolsChanged()),C=Ue({handler:S,send:k,maxChunk:()=>o,error:(y)=>e.error(y),timeoutMs:a}),O=(y,g)=>{let b={type:"error",code:"bad_message",message:y};if(F(g)&&g.length<=Tt)b.id=g;k(b)},q=(y)=>{if(v)return;let g=y?.data;if(!De(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:E}=g;if(!F(b)||b===""||b.length>Tt||!F(h)||!F(R)||!R.startsWith("/")||!De(A)||!Object.values(A).every(F)||!F(E)){O("malformed http.request",b);return}C.request({type:"http.request",id:b,method:h,path:R,headers:A,body:E,grant:u});return}case"http.cancel":if(F(b))C.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(),C.close(),S.close(),ze.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),ze.add(t),t.onmessage=q,{close:f}}function zn(e){let t="",n=0,r=0;for(let o of e){n=n<<8|o,r+=8;while(r>=5)r-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>r&31];n&=(1<<r)-1}if(r>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-r&31];return t}async function Dn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return zn(new Uint8Array(n))}catch{return}}function $r(e,t,n,r,o){let a=Re(e,"webmcp");return o===void 0?He({...a,confirm:e.onConfirm()??(()=>!0)},t,n,r,{kind:"webmcp"}):He({...a,confirm:()=>!0},t,n,r,{kind:"webmcp",via:"tab-mcp-extension",name:o.name,host:o.host})}var Bn=15000,kt={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"},Rt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var It=512,Mt=6,St=64,Jn=It+Mt*St;function Un(e){let t=Math.floor((e-It)/Mt);return t>=St?t:void 0}var Vn=1e4,Gn=1000;function Wn(e,t){let n,r=!1,o=Number.NEGATIVE_INFINITY,a;try{if(e!==void 0&&typeof BroadcastChannel==="function")n=new BroadcastChannel(e),n.onmessage=(s)=>{let i=s.data;if(!r||i?.type!=="claimed"||i.address!==void 0&&i.address!==t)return;o=Date.now(),a?.()}}catch{n=void 0}return{claimed(){r=!0;try{n?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-o<=Vn)return Promise.resolve(!0);if(n===void 0)return Promise.resolve(!1);return new Promise((s)=>{let i=setTimeout(()=>s(!1),Gn);a=()=>{clearTimeout(i),s(!0)}})},close(){n?.close()}}}function xr(e,t,n,r,o){return new Promise((a,s)=>{let i=["grantschange","statechange","error"],u=(M)=>{clearTimeout(k);for(let S of i)e.removeEventListener(S,v);if(M)s(M);else a()},v=(M)=>{let S=M?.detail?.error;if(n())u();else if((S?.code==="store_unavailable"||S?.code==="unknown_id")&&(S.for===void 0||S.for===t.type&&S.grantId===t.grantId))u(S);else if(!r())u(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},k=setTimeout(()=>u(new DOMException("TabMcp: the relay did not answer","TimeoutError")),o);for(let M of i)e.addEventListener(M,v);v()})}function vr(e){let t=globalThis,n=globalThis.document,r=()=>{if(n?.visibilityState!=="hidden")e()};return n?.addEventListener("visibilitychange",r),t.addEventListener?.("online",e),()=>{n?.removeEventListener("visibilitychange",r),t.removeEventListener?.("online",e)}}function Tr(e,t,n,r={}){let o=r.revokeAll===!0,a=new WebSocket(t,ke),s="opening",i,u=65536,v,k,M=0,S=Wn(e.tabs,r.address),N,C,O=new Promise((d,_)=>{N=d,C=_});O.catch(()=>{});let q=setTimeout(()=>{h(de("The relay did not answer in time.","network"))},Bn),U=Re(e,"relay"),f=Te({...U,server:{...e.server,icons:e.server.icons??be()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>v}),y=Je(e.registry,U.tools,()=>f.toolsChanged());function g(d){if(a.readyState!==WebSocket.OPEN)return!1;try{return a.send(JSON.stringify(d)),!0}catch{return!1}}function b(){if(M<=0)return;clearTimeout(k),k=setTimeout(()=>{i??="heartbeat",R(4003);try{a.close()}catch{}},M*2.5)}function h(d){if(s!=="opening")return;R(0),C(d);try{a.close()}catch{}}function R(d){if(s==="closed")return;let _=s==="ready";if(s="closed",clearTimeout(q),clearTimeout(k),y(),A.close(),f.close(),_){let H=i??kt[d]??(d===1006?"network":"closed");if(e.closed(H,d),H==="replaced"){S.heard().then((z)=>{S.close(),e.replaced({sibling:z})});return}}S.close()}let A=Ue({handler:f,send:g,maxChunk:()=>u,error:(d)=>e.error(d)});function E(d){if(s==="opening"){if(d.type==="session"){let _=Un(d.limits.maxMessageBytes);if(_===void 0){h(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Jn}.`,"policy"));return}if(o&&d.grants.length>0){h(de("The relay did not revoke the address's grants (it needs tab-mcp 0.5 or later).","policy"));return}u=_,v=d.limits.maxBodyBytes,s="ready",clearTimeout(q),M=d.limits.heartbeatMs,b(),S.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}`,Rt[d.reason]??"closed"));return}if(s!=="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(i=Rt[d.reason]??"closed",i==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}if(d.code==="unknown_id"&&d.for==="grant.revoke"&&typeof d.grantId==="string")e.grantRemoved(d.grantId);e.error(Object.assign(Error(`Relay error ${d.code}: ${d.message}`),{code:d.code},typeof d.for==="string"?{for:d.for}:{},typeof d.grantId==="string"?{grantId:d.grantId}:{}));return;case"session":return}}return a.addEventListener("open",()=>{if(a.protocol!==""&&a.protocol!==ke){h(de(`The relay speaks ${a.protocol}, not ${ke}.`,"policy"));return}g({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...o?{revokeAll:!0}:{}})}),a.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let _=xt(d.data);if(_===void 0)return;if(s==="ready")b();E(_)}),a.addEventListener("close",(d)=>{if(s==="opening"){R(d.code);let _=d.code===1006||d.code===1002;C(de(_?"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}`:""}).`,kt[d.code]??(_?"network":"closed")));return}R(d.code)}),{ready:O,send:g,close(d){if(s==="closed")return;if(s==="opening"){h(new DOMException("The connection was cancelled","AbortError"));return}i=d,g({type:"bye",reason:"user"}),R(1000);try{a.close(1000,"bye")}catch{}}}}export{Jn as MIN_MESSAGE_BYTES,Gn as SIBLING_GRACE_MS,Vn as SIBLING_WINDOW_MS,Dn as addressIdOf,xr as answer,$r as callFromWebMcp,Un as chunkSize,wn as compileRegistry,vr as onWake,Tr as openConnection,Be as pieces,Hn as servePort};
14
+ `});n({type:"http.response.end",id:i.id})},r);try{let _=new Request(`https://tab.invalid${i.path}`,{method:i.method,headers:i.headers,signal:u.signal}),O=await t.handle(_,{grant:i.grant,body:i.body});if(!v()){await O.body?.cancel().catch(()=>{});return}let q={};for(let w of En){let h=O.headers.get(w);if(h!==null)q[w]=h}let U=(q["content-type"]??"").startsWith("text/event-stream"),f=e.maxChunk();if(!U||O.body===null){let w=await O.text();if(!v())return;if(w.length<=f){n({type:"http.response",id:i.id,status:O.status,headers:q,body:w});return}n({type:"http.response.start",id:i.id,status:O.status,headers:q});for(let h of Be(w,f)){if(!v())break;n({type:"http.response.chunk",id:i.id,data:h})}if(v())n({type:"http.response.end",id:i.id});return}n({type:"http.response.start",id:i.id,status:O.status,headers:q}),k=!0;let y=O.body.getReader(),g=new TextDecoder;u.signal.addEventListener("abort",()=>{y.cancel().catch(()=>{})});for(;;){let{done:w,value:h}=await y.read();if(w||!v())break;let R=g.decode(h,{stream:!0});if(R!=="")M=(M+R).slice(-2);for(let A of Be(R,f))n({type:"http.response.chunk",id:i.id,data:A})}if(v())n({type:"http.response.end",id:i.id})}catch(_){if(v())e.error(_ instanceof Error?_:Error(String(_))),n({type:"http.response",id:i.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(clearTimeout(N),o.get(i.id)===u)o.delete(i.id)}}return{request(i){if(!a)s(i)},cancel(i){o.get(i)?.abort(),o.delete(i)},close(){if(a)return;a=!0;for(let i of o.values())i.abort();o.clear()}}}var Nn=65536,vt=64,jn=300000,Tt=128,ze=new WeakSet,qn=0,F=(e)=>typeof e==="string";function De(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Hn(e,t,n){let r=n?.client;if(!De(r)||!F(r.id)||r.id===""||r.name!==void 0&&!F(r.name))throw TypeError("serve: client needs an id (and may have a name)");let o=n.maxChunk??Nn;if(!Number.isInteger(o)||o<vt)throw TypeError(`serve: maxChunk must be a whole number of at least ${vt}`);let a=n.requestTimeoutMs??jn;if(typeof a!=="number"||!(a>0)||a>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let s=n.onConfirm;if(s!==void 0&&typeof s!=="function")throw TypeError("serve: onConfirm must be a function");if(typeof t?.postMessage!=="function"||!("onmessage"in t))throw TypeError("serve: the port needs postMessage and onmessage");if(ze.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let i={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")i.name=r.name;let u={grantId:`local:${++qn}`,clientId:r.id,scopes:["tools"]},v=!1,k=(y)=>{if(v)return!1;try{return t.postMessage(y),!0}catch{return!1}},M=Re(e,"local");if(s!==void 0)M.confirm=(y)=>Promise.resolve().then(()=>s(y)).then((g)=>g==="unanswered"?g:g===!0),M.ownConfirm=!0;let S=Te({...M,server:{...e.server,icons:e.server.icons??we()},client:()=>({...i})}),N=Je(e.registry,M.tools,()=>S.toolsChanged()),_=Ue({handler:S,send:k,maxChunk:()=>o,error:(y)=>e.error(y),timeoutMs:a}),O=(y,g)=>{let w={type:"error",code:"bad_message",message:y};if(F(g)&&g.length<=Tt)w.id=g;k(w)},q=(y)=>{if(v)return;let g=y?.data;if(!De(g)||!F(g.type)){O("not a message");return}let w=g.id;switch(g.type){case"http.request":{let{method:h,path:R,headers:A,body:E}=g;if(!F(w)||w===""||w.length>Tt||!F(h)||!F(R)||!R.startsWith("/")||!De(A)||!Object.values(A).every(F)||!F(E)){O("malformed http.request",w);return}_.request({type:"http.request",id:w,method:h,path:R,headers:A,body:E,grant:u});return}case"http.cancel":if(F(w))_.cancel(w);else O("malformed http.cancel");return;case"error":return;default:O(`unexpected ${g.type.slice(0,64)}`,w)}},U=t,f=()=>{if(v)return;if(n.signal?.removeEventListener("abort",f),U.removeEventListener?.("close",f),N(),_.close(),S.close(),ze.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),ze.add(t),t.onmessage=q,{close:f}}function zn(e){let t="",n=0,r=0;for(let o of e){n=n<<8|o,r+=8;while(r>=5)r-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>r&31];n&=(1<<r)-1}if(r>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-r&31];return t}async function Dn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return zn(new Uint8Array(n))}catch{return}}function wr(e,t,n,r,o){let a=Re(e,"webmcp");return o===void 0?He({...a,confirm:e.onConfirm()??(()=>!0)},t,n,r,{kind:"webmcp"}):He({...a,confirm:()=>!0},t,n,r,{kind:"webmcp",via:"tab-mcp-extension",name:o.name,host:o.host})}var Bn=15000,kt={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"},Rt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var It=512,Mt=6,St=64,Jn=It+Mt*St;function Un(e){let t=Math.floor((e-It)/Mt);return t>=St?t:void 0}var Vn=1e4;function Gn(e,t,n){let r,o=!1,a=Number.NEGATIVE_INFINITY,s;try{if(e!==void 0&&typeof BroadcastChannel==="function")r=new BroadcastChannel(e),r.onmessage=(i)=>{let u=i.data;if(!o||u?.type!=="claimed"||u.address!==void 0&&u.address!==t)return;a=Date.now(),s?.()}}catch{r=void 0}return{claimed(){o=!0;try{r?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-a<=Vn)return Promise.resolve(!0);if(r===void 0)return Promise.resolve(!1);return new Promise((i)=>{let u=setTimeout(()=>i(!1),n);s=()=>{clearTimeout(u),i(!0)}})},close(){r?.close()}}}function $r(e,t,n,r,o){return new Promise((a,s)=>{let i=["grantschange","statechange","error"],u=(M)=>{clearTimeout(k);for(let S of i)e.removeEventListener(S,v);if(M)s(M);else a()},v=(M)=>{let S=M?.detail?.error;if(n())u();else if((S?.code==="store_unavailable"||S?.code==="unknown_id")&&(S.for===void 0||S.for===t.type&&S.grantId===t.grantId))u(S);else if(!r())u(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},k=setTimeout(()=>u(new DOMException("TabMcp: the relay did not answer","TimeoutError")),o);for(let M of i)e.addEventListener(M,v);v()})}function xr(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 vr(e,t,n,r){let o=r.revokeAll===!0,a=new WebSocket(t,ke),s="opening",i,u=65536,v,k,M=0,S=Gn(e.tabs,r.address,r.siblingGraceMs),N,_,O=new Promise((d,C)=>{N=d,_=C});O.catch(()=>{});let q=setTimeout(()=>{h(de("The relay did not answer in time.","network"))},Bn),U=Re(e,"relay"),f=Te({...U,server:{...e.server,icons:e.server.icons??we()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>v}),y=Je(e.registry,U.tools,()=>f.toolsChanged());function g(d){if(a.readyState!==WebSocket.OPEN)return!1;try{return a.send(JSON.stringify(d)),!0}catch{return!1}}function w(){if(M<=0)return;clearTimeout(k),k=setTimeout(()=>{i??="heartbeat",R(4003);try{a.close()}catch{}},M*2.5)}function h(d){if(s!=="opening")return;R(0),_(d);try{a.close()}catch{}}function R(d){if(s==="closed")return;let C=s==="ready";if(s="closed",clearTimeout(q),clearTimeout(k),y(),A.close(),f.close(),C){let H=i??kt[d]??(d===1006?"network":"closed");if(e.closed(H,d),H==="replaced"){S.heard().then((z)=>{S.close(),e.replaced({sibling:z})});return}}S.close()}let A=Ue({handler:f,send:g,maxChunk:()=>u,error:(d)=>e.error(d)});function E(d){if(s==="opening"){if(d.type==="session"){let C=Un(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 ${Jn}.`,"policy"));return}if(o&&d.grants.length>0){h(de("The relay did not revoke the address's grants (it needs tab-mcp 0.5 or later).","policy"));return}u=C,v=d.limits.maxBodyBytes,s="ready",clearTimeout(q),M=d.limits.heartbeatMs,w(),S.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}`,Rt[d.reason]??"closed"));return}if(s!=="ready")return;switch(d.type){case"ping":w(),g({type:"pong",t:d.t});return;case"http.request":A.request(d);return;case"http.cancel":A.cancel(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"pairing.open":e.pairingOpen(d.expiresAt);return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":e.grantRemoved(d.grantId);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(i=Rt[d.reason]??"closed",i==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}if(d.code==="unknown_id"&&d.for==="grant.revoke"&&typeof d.grantId==="string")e.grantRemoved(d.grantId);e.error(Object.assign(Error(`Relay error ${d.code}: ${d.message}`),{code:d.code},typeof d.for==="string"?{for:d.for}:{},typeof d.grantId==="string"?{grantId:d.grantId}:{}));return;case"session":return}}return a.addEventListener("open",()=>{if(a.protocol!==""&&a.protocol!==ke){h(de(`The relay speaks ${a.protocol}, not ${ke}.`,"policy"));return}g({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...o?{revokeAll:!0}:{}})}),a.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let C=xt(d.data);if(C===void 0)return;if(s==="ready")w();E(C)}),a.addEventListener("close",(d)=>{if(s==="opening"){R(d.code);let C=d.code===1006||d.code===1002;_(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}`:""}).`,kt[d.code]??(C?"network":"closed")));return}R(d.code)}),{ready:O,send:g,close(d){if(s==="closed")return;if(s==="opening"){h(new DOMException("The connection was cancelled","AbortError"));return}i=d,g({type:"bye",reason:"user"}),R(1000);try{a.close(1000,"bye")}catch{}}}}export{Jn as MIN_MESSAGE_BYTES,Vn as SIBLING_WINDOW_MS,Dn as addressIdOf,$r as answer,wr as callFromWebMcp,Un as chunkSize,bn as compileRegistry,xr as onWake,vr as openConnection,Be as pieces,Hn as servePort};
15
15
 
16
- //# debugId=C316A818A0C406F464756E2164756E21
17
- //# sourceMappingURL=connection-cxgns38v.min.js.map
16
+ //# debugId=9EC9A7C83CEB560164756E2164756E21
17
+ //# sourceMappingURL=connection-m0e4xvcy.min.js.map