@ractive-ch/tab-mcp-client 0.19.0 → 0.20.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,20 @@ 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.20.0-rc.1][client-0.20.0-rc.1] - 2026-11-22
10
+
11
+ ### Breaking
12
+
13
+ - With `webmcp: true`, tools marked `consequentialHint` or `destructiveHint` are mirrored
14
+ into the browser's WebMCP too, unless their `callers` leave `"webmcp"` out (DEC-209).
15
+ They ask every WebMCP call (a call the tab-mcp browser extension vouched for was asked
16
+ there), and so does a tool marked only `destructiveHint`, which the page asks no AI
17
+ app for (DEC-022): WebMCP has no `destructiveHint`, so a WebMCP call asks by
18
+ `consequentialHint ?? destructiveHint`, the rule that already set the native hint. Until now they were left out unless `callers` listed
19
+ `"webmcp"`, and an agent that found no such tool used the page's own controls instead,
20
+ which ask nothing. To keep a tool from agents in the browser, as before, register it
21
+ with `callers: ["relay", "local"]`.
22
+
9
23
  ## [0.19.0][client-0.19.0] - 2026-11-21
10
24
 
11
25
  ### Breaking
@@ -1081,6 +1095,7 @@ First alpha of the browser library, on the npm dist-tag `alpha`.
1081
1095
  `<script type="module">` under `@ractive-ch/tab-mcp-client/cdn`.
1082
1096
  - The connect dialog shows the pairing code from the relay.
1083
1097
 
1098
+ [client-0.20.0-rc.1]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.20.0-rc.1
1084
1099
  [client-0.19.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.19.0
1085
1100
  [client-0.18.1]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.18.1
1086
1101
  [client-0.18.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.18.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.19.0.** Until 1.0, a new minor version can still change the API. Which AI apps
20
+ **Status: 0.20.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
  ## You need a relay
@@ -52,7 +52,7 @@ Or without a bundler, from a CDN as an ES module:
52
52
 
53
53
  ```html
54
54
  <script type="module">
55
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.19.0/cdn/tab-mcp-client.min.js";
55
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.20.0-rc.1/cdn/tab-mcp-client.min.js";
56
56
  </script>
57
57
  ```
58
58
 
@@ -196,11 +196,16 @@ Chrome has WebMCP for sites in its
196
196
  `webmcp: true` does nothing. Each `new TabMcp` looks for WebMCP when it is made, so a
197
197
  trial token that a script adds later counts for a `TabMcp` made after it.
198
198
 
199
- - Tools marked `consequentialHint`, or MCP's `destructiveHint`, are left out unless
200
- their registration lists `"webmcp"` in `callers` (`{ callers: ["relay", "webmcp"] }`):
201
- an agent in the browser often drives the very tab it calls into, so it can click Allow
202
- in the page's confirmation itself. `callers` without `"webmcp"` keeps any tool out of
203
- WebMCP ([which callers see a tool](#which-callers-see-a-tool)). A tool marked only
199
+ - Every tool goes there, tools marked `consequentialHint` or MCP's `destructiveHint`
200
+ included, and they ask every WebMCP call (below). A WebMCP call asks by
201
+ `consequentialHint ?? destructiveHint`, so a tool marked only `destructiveHint` asks
202
+ there too, though it does not ask an AI app (its own client sees the hint). `callers` without
203
+ `"webmcp"` keeps a tool out of WebMCP
204
+ ([which callers see a tool](#which-callers-see-a-tool)). Until 0.20 such tools were
205
+ left out unless `callers` listed `"webmcp"`; an agent that found no tool to delete with
206
+ then clicked the page's own Delete buttons, with no question at all (DEC-209). An agent
207
+ that drives the tab can click Allow in the page's dialog too, so a tool the page wants
208
+ kept from agents in the browser leaves `"webmcp"` out of `callers`. A tool marked only
204
209
  `destructiveHint: true` is registered natively with `consequentialHint: true`, since
205
210
  WebMCP has no `destructiveHint` (DEC-022 maps the other way).
206
211
  - The native registration gets the WebMCP fields: `name`, `title`, `description`,
@@ -481,13 +486,21 @@ between that text and the tool.
481
486
  #### Which callers see a tool
482
487
 
483
488
  `registerTool(tool, { callers })` lists the callers that see a tool: `"relay"` (AI apps
484
- through the relay), `"local"` (a served port) and `"webmcp"` (agents in the browser). By
485
- default all of them, except that a consequential tool goes to WebMCP only when `"webmcp"`
486
- is listed ([WebMCP](#webmcp)). For a caller that is not listed the tool does not exist:
487
- `tools/list` leaves it out, `notifications/tools/list_changed` does not fire for it, and a
488
- call gets the same error as a call of an unknown tool. `{ callers: ["local"] }` keeps a
489
- tool for the site's own assistant, `{ callers: ["relay", "webmcp"] }` keeps it from the
490
- port.
489
+ through the relay), `"local"` (a served port) and `"webmcp"` (agents in the browser),
490
+ by default all of them. A tool that asks asks each of them; whether a tool deletes
491
+ something is no reason to hide it from a caller. `callers` is for who may see it at all.
492
+ For a caller that is not listed the tool does not exist: `tools/list` leaves it out,
493
+ `notifications/tools/list_changed` does not fire for it, and a call gets the same error
494
+ as a call of an unknown tool. For example:
495
+
496
+ - `{ callers: ["local"] }`: data the site's own assistant may read under the site's
497
+ terms, but that should not pass through the relay to an AI app the site has no
498
+ contract with (a bank's `list_transactions`).
499
+ - `{ callers: ["relay"] }`: a tool that needs to know which AI app calls (a paired,
500
+ named app; an audit line, "Always allow" remembered per app), which an anonymous
501
+ WebMCP caller is not.
502
+ - `{ callers: ["relay", "webmcp"] }`: kept from the port, when the page serves it to a
503
+ chat frame of another origin.
491
504
 
492
505
  #### Untrusted results
493
506
 
@@ -712,8 +725,8 @@ mcp.addEventListener("grantschange", drawSwitches);
712
725
  that does not import it loads nothing of it. Take both from the same version:
713
726
 
714
727
  ```js
715
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.19.0/cdn/tab-mcp-client.min.js";
716
- import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.19.0/cdn/allowed.min.js";
728
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.20.0-rc.1/cdn/tab-mcp-client.min.js";
729
+ import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.20.0-rc.1/cdn/allowed.min.js";
717
730
  ```
718
731
 
719
732
  **The risk.** An allowance outlives the user's attention: for up to the grant's 90 days,
@@ -1,17 +1,17 @@
1
- var Ct=/^(?:\d{1,4}x\d{1,4}|any)$/;function Et(e){let{src:t,mimeType:n,sizes:r,theme:s}=e;if(typeof t!=="string")return;let i=/^https?:/i.test(t)&&t.length<=2048,o=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!i&&!o)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((y)=>String(y).toLowerCase()).filter((y)=>Ct.test(y)):[];if(u.length>0)a.sizes=u;if(s==="light"||s==="dark")a.theme=s;return a}function Se(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?Et(n):void 0;if(r!==void 0)t.push(r);if(t.length===8)break}return t}function be(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return Se([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let s=n.getAttribute("sizes");if(s)r.sizes=s.trim().split(/\s+/);let i=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(i)r.theme=i[1]?.toLowerCase();return r}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let r=Array.isArray(e),s=Array.isArray(t);if(r!==s)return!1;if(r){let i=e.length;if(i!==t.length)return!1;for(let o=0;o<i;o++)if(!ue(e[o],t[o]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let u of i){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function J(e){return encodeURI(St(e)).replace(/#/g,"%23")}function St(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var At=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,Ot=/^%[0-9A-Fa-f]{2}$/,Pt=/^[A-Za-z0-9._~-]$/;function Nt(e){let t="";for(let n=0;n<e.length;){let r=e[n],s=e.slice(n,n+3);if(r==="%"&&Ot.test(s)){let o=String.fromCharCode(parseInt(s.slice(1),16));t+=Pt.test(o)?o:s.toUpperCase(),n+=3;continue}let i=String.fromCodePoint(e.codePointAt(n));t+=At.test(i)?i:encodeURIComponent(i),n+=i.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?Nt(n.hash.slice(1)):"",n}var jt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},qt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Ht={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},zt=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function Z(e,t=Object.create(null),n=zt,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let i=e.$id||e.id;if(i){let o=$e(i,n);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",r==="")n=o;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(r?"#"+r:"");if(t[s]!==void 0&&t[s]!==e)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let i=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:i.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let i=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:i.href})}if(e.$anchor){let i=$e("#"+e.$anchor,n);t[i.href]=e}for(let i in e){if(Ht[i])continue;let o=`${r}/${J(i)}`,a=e[i];if(Array.isArray(a)){if(jt[i]){let u=a.length;for(let y=0;y<u;y++)Z(a[y],t,n,`${o}/${y}`)}}else if(qt[i])for(let u in a)Z(a[u],t,n,`${o}/${J(u)}`);else Z(a,t,n,o)}return t}var Dt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Bt=[0,31,28,31,30,31,30,31,31,30,31,30,31],Jt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Xe=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i,Ut=/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{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,Vt=/^(?:(?:[^\x00-\x20\x7f"<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Gt=/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,Wt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Ft=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Kt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Yt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Xt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Zt=(e)=>{let t=e.match(Xt);if(!t)return!1;let n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){let s=r.slice(1,-1);if(/^ipv6:/i.test(s))return Qe.test(s.slice(5));return Ze.test(s)}return Xe.test(r)},Ze=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Qe=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,Qt=(e)=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e);function G(e){return e.test.bind(e)}var Ae={date:Le,time:et.bind(void 0,!0),"date-time":tn,duration:Qt,uri:on,"uri-reference":G(Ut),"uri-template":G(Vt),url:G(Gt),email:Zt,hostname:G(Xe),ipv4:G(Ze),ipv6:G(Qe),regex:an,uuid:G(Wt),"json-pointer":G(Ft),"json-pointer-uri-fragment":G(Kt),"relative-json-pointer":G(Yt)};function Lt(e){return e%4===0&&(e%100!==0||e%400===0)}function Le(e){let t=e.match(Dt);if(!t)return!1;let n=t[1],r=t[2],s=t[3];if(!n||!r||!s)return!1;let i=+n,o=+r,a=+s,u=o==2&&Lt(i)?29:Bt[o];return o>=1&&o<=12&&a>=1&&u!==void 0&&a<=u}function et(e,t){let n=t.match(Jt);if(!n)return!1;let r=n[1],s=n[2],i=n[3];if(!r||!s||!i)return!1;let o=+r,a=+s,u=+i,y=n[5],b=n[6],_=+(n[7]??0),A=+(n[8]??0);if(o>23||a>59||u>60||_>23||A>59||e&&y===void 0)return!1;if(u<60)return!0;let D=b==="+"?1:b==="-"?-1:0;return(o*60+a-D*(_*60+A)+1440)%1440===1439}var en=/t|\s/i;function tn(e){let[t,n,r]=e.split(en);return t!==void 0&&n!==void 0&&r===void 0&&Le(t)&&et(!0,n)}var nn=/\/|:/,rn=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function on(e){return nn.test(e)&&rn.test(e)}var sn=/[^\\]\\Z/;function an(e){if(sn.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function tt(e){let t=0,n=e.length,r=0,s;while(r<n)if(t++,s=e.charCodeAt(r++),s>=55296&&s<=56319&&r<n){if(s=e.charCodeAt(r),(s&64512)==56320)r++}return t}function oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function nt(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",s=n.indexOf("."),i=s===-1?0:n.length-s-1;return[BigInt(n.replace(".","")),Number(r)-i]}function dn(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=nt(e),[s,i]=nt(t),o=r-i;if(o>=0)return n*10n**BigInt(o)%s===0n;return n%(s*10n**BigInt(-o))===0n}function N(e,t,n="2019-09",r=Z(t),s=!0,i=null,o="#",a="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let y=typeof e,b;switch(y){case"boolean":case"number":case"string":b=y;break;case"object":if(e===null)b="null";else if(Array.isArray(e))b="array";else b="object";break;default:throw Error(`Instances of "${y}" type are not supported.`)}let{$ref:_,$recursiveRef:A,$recursiveAnchor:D,type:C,const:O,enum:j,required:U,not:f,anyOf:g,allOf:h,oneOf:v,if:w,then:R,else:S,format:E,properties:d,patternProperties:M,additionalProperties:q,unevaluatedProperties:H,minProperties:X,maxProperties:V,propertyNames:ee,dependentRequired:te,dependentSchemas:Ue,dependencies:Re,prefixItems:Ie,items:ce,additionalItems:Ve,unevaluatedItems:Ge,contains:We,minContains:K,maxContains:Me,minItems:_e,maxItems:Ce,uniqueItems:Mt,minimum:ne,maximum:re,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ee,minLength:ye,maxLength:ge,pattern:Fe,__absolute_ref__:he,__absolute_recursive_ref__:_t}=t,c=[];if(D===!0&&i===null)i=t;if(A==="#"){let k=i===null?r[_t]:i,m=`${a}/$recursiveRef`,I=N(e,i===null?t:i,n,r,s,k,o,m,u);if(!I.valid)c.push({instanceLocation:o,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(_!==void 0){let m=r[he||_];if(m===void 0){let l=`Unresolved $ref "${_}".`;if(he&&he!==_)l+=` Absolute URI "${he}".`;throw l+=`
1
+ var Ct=/^(?:\d{1,4}x\d{1,4}|any)$/;function Et(e){let{src:t,mimeType:n,sizes:r,theme:s}=e;if(typeof t!=="string")return;let i=/^https?:/i.test(t)&&t.length<=2048,o=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!i&&!o)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((v)=>String(v).toLowerCase()).filter((v)=>Ct.test(v)):[];if(u.length>0)a.sizes=u;if(s==="light"||s==="dark")a.theme=s;return a}function Se(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?Et(n):void 0;if(r!==void 0)t.push(r);if(t.length===8)break}return t}function be(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return Se([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let s=n.getAttribute("sizes");if(s)r.sizes=s.trim().split(/\s+/);let i=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(i)r.theme=i[1]?.toLowerCase();return r}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let r=Array.isArray(e),s=Array.isArray(t);if(r!==s)return!1;if(r){let i=e.length;if(i!==t.length)return!1;for(let o=0;o<i;o++)if(!ue(e[o],t[o]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let u of i){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function J(e){return encodeURI(St(e)).replace(/#/g,"%23")}function St(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var At=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,Ot=/^%[0-9A-Fa-f]{2}$/,Pt=/^[A-Za-z0-9._~-]$/;function Nt(e){let t="";for(let n=0;n<e.length;){let r=e[n],s=e.slice(n,n+3);if(r==="%"&&Ot.test(s)){let o=String.fromCharCode(parseInt(s.slice(1),16));t+=Pt.test(o)?o:s.toUpperCase(),n+=3;continue}let i=String.fromCodePoint(e.codePointAt(n));t+=At.test(i)?i:encodeURIComponent(i),n+=i.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?Nt(n.hash.slice(1)):"",n}var jt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},qt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Ht={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},zt=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function Z(e,t=Object.create(null),n=zt,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let i=e.$id||e.id;if(i){let o=$e(i,n);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",r==="")n=o;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(r?"#"+r:"");if(t[s]!==void 0&&t[s]!==e)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let i=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:i.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let i=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:i.href})}if(e.$anchor){let i=$e("#"+e.$anchor,n);t[i.href]=e}for(let i in e){if(Ht[i])continue;let o=`${r}/${J(i)}`,a=e[i];if(Array.isArray(a)){if(jt[i]){let u=a.length;for(let v=0;v<u;v++)Z(a[v],t,n,`${o}/${v}`)}}else if(qt[i])for(let u in a)Z(a[u],t,n,`${o}/${J(u)}`);else Z(a,t,n,o)}return t}var Dt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Bt=[0,31,28,31,30,31,30,31,31,30,31,30,31],Jt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Xe=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i,Ut=/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{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,Vt=/^(?:(?:[^\x00-\x20\x7f"<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Gt=/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,Wt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Ft=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Kt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Yt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Xt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Zt=(e)=>{let t=e.match(Xt);if(!t)return!1;let n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){let s=r.slice(1,-1);if(/^ipv6:/i.test(s))return Qe.test(s.slice(5));return Ze.test(s)}return Xe.test(r)},Ze=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Qe=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,Qt=(e)=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e);function G(e){return e.test.bind(e)}var Ae={date:Le,time:et.bind(void 0,!0),"date-time":tn,duration:Qt,uri:on,"uri-reference":G(Ut),"uri-template":G(Vt),url:G(Gt),email:Zt,hostname:G(Xe),ipv4:G(Ze),ipv6:G(Qe),regex:an,uuid:G(Wt),"json-pointer":G(Ft),"json-pointer-uri-fragment":G(Kt),"relative-json-pointer":G(Yt)};function Lt(e){return e%4===0&&(e%100!==0||e%400===0)}function Le(e){let t=e.match(Dt);if(!t)return!1;let n=t[1],r=t[2],s=t[3];if(!n||!r||!s)return!1;let i=+n,o=+r,a=+s,u=o==2&&Lt(i)?29:Bt[o];return o>=1&&o<=12&&a>=1&&u!==void 0&&a<=u}function et(e,t){let n=t.match(Jt);if(!n)return!1;let r=n[1],s=n[2],i=n[3];if(!r||!s||!i)return!1;let o=+r,a=+s,u=+i,v=n[5],k=n[6],M=+(n[7]??0),_=+(n[8]??0);if(o>23||a>59||u>60||M>23||_>59||e&&v===void 0)return!1;if(u<60)return!0;let N=k==="+"?1:k==="-"?-1:0;return(o*60+a-N*(M*60+_)+1440)%1440===1439}var en=/t|\s/i;function tn(e){let[t,n,r]=e.split(en);return t!==void 0&&n!==void 0&&r===void 0&&Le(t)&&et(!0,n)}var nn=/\/|:/,rn=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function on(e){return nn.test(e)&&rn.test(e)}var sn=/[^\\]\\Z/;function an(e){if(sn.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function tt(e){let t=0,n=e.length,r=0,s;while(r<n)if(t++,s=e.charCodeAt(r++),s>=55296&&s<=56319&&r<n){if(s=e.charCodeAt(r),(s&64512)==56320)r++}return t}function oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function nt(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",s=n.indexOf("."),i=s===-1?0:n.length-s-1;return[BigInt(n.replace(".","")),Number(r)-i]}function dn(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=nt(e),[s,i]=nt(t),o=r-i;if(o>=0)return n*10n**BigInt(o)%s===0n;return n%(s*10n**BigInt(-o))===0n}function j(e,t,n="2019-09",r=Z(t),s=!0,i=null,o="#",a="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let v=typeof e,k;switch(v){case"boolean":case"number":case"string":k=v;break;case"object":if(e===null)k="null";else if(Array.isArray(e))k="array";else k="object";break;default:throw Error(`Instances of "${v}" type are not supported.`)}let{$ref:M,$recursiveRef:_,$recursiveAnchor:N,type:E,const:O,enum:q,required:U,not:f,anyOf:y,allOf:g,oneOf:b,if:h,then:R,else:A,format:S,properties:d,patternProperties:C,additionalProperties:H,unevaluatedProperties:z,minProperties:X,maxProperties:V,propertyNames:ee,dependentRequired:te,dependentSchemas:Ue,dependencies:Re,prefixItems:Ie,items:ce,additionalItems:Ve,unevaluatedItems:Ge,contains:We,minContains:K,maxContains:Me,minItems:_e,maxItems:Ce,uniqueItems:Mt,minimum:ne,maximum:re,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ee,minLength:ye,maxLength:ge,pattern:Fe,__absolute_ref__:he,__absolute_recursive_ref__:_t}=t,c=[];if(N===!0&&i===null)i=t;if(_==="#"){let T=i===null?r[_t]:i,m=`${a}/$recursiveRef`,I=j(e,i===null?t:i,n,r,s,T,o,m,u);if(!I.valid)c.push({instanceLocation:o,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(M!==void 0){let m=r[he||M];if(m===void 0){let l=`Unresolved $ref "${M}".`;if(he&&he!==M)l+=` Absolute URI "${he}".`;throw l+=`
2
2
  Known schemas:
3
3
  - ${Object.keys(r).join(`
4
- - `)}`,Error(l)}let I=`${a}/$ref`,p=N(e,m,n,r,s,i,o,I,u);if(!p.valid)c.push({instanceLocation:o,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...p.errors);if(n==="4"||n==="7")return{valid:c.length===0,errors:c}}if(Array.isArray(C)){let k=C.length,m=!1;for(let I=0;I<k;I++)if(b===C[I]||C[I]==="integer"&&b==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${b}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(b!=="number"||e%1||e!==e)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${b}" is invalid. Expected "${C}".`})}else if(C!==void 0&&b!==C)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${b}" is invalid. Expected "${C}".`});if(O!==void 0){if(b==="object"||b==="array"){if(!ue(e,O))c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}if(j!==void 0){if(b==="object"||b==="array"){if(!j.some((k)=>ue(e,k)))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(j)}.`})}else if(!j.some((k)=>e===k))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(j)}.`})}if(f!==void 0){let k=`${a}/not`;if(N(e,f,n,r,s,i,o,k).valid)c.push({instanceLocation:o,keyword:"not",keywordLocation:k,error:'Instance matched "not" schema.'})}let we=[];if(g!==void 0){let k=`${a}/anyOf`,m=c.length,I=!1;for(let[p,l]of g.entries()){let T=Object.create(u),x=N(e,l,n,r,s,D===!0?i:null,o,`${k}/${p}`,T);if(c.push(...x.errors),I=I||x.valid,x.valid)we.push(T)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:k,error:"Instance does not match any subschemas."})}if(h!==void 0){let k=`${a}/allOf`,m=c.length,I=!0;for(let[p,l]of h.entries()){let T=Object.create(u),x=N(e,l,n,r,s,D===!0?i:null,o,`${k}/${p}`,T);if(c.push(...x.errors),I=I&&x.valid,x.valid)we.push(T)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:k,error:"Instance does not match every subschema."})}if(v!==void 0){let k=`${a}/oneOf`,m=c.length,I=v.filter((p,l)=>{let T=Object.create(u),x=N(e,p,n,r,s,D===!0?i:null,o,`${k}/${l}`,T);if(c.push(...x.errors),x.valid)we.push(T);return x.valid}).length;if(I===1)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:k,error:`Instance does not match exactly one subschema (${I} matches).`})}if(b==="object"||b==="array")Object.assign(u,...we);if(w!==void 0){let k=`${a}/if`,m=Object.create(null);if(N(e,w,n,r,s,i,o,k,m).valid){if(Object.assign(u,m),R!==void 0){let p=N(e,R,n,r,s,i,o,`${a}/then`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:k,error:'Instance does not match "then" schema.'},...p.errors)}}else if(S!==void 0){let p=N(e,S,n,r,s,i,o,`${a}/else`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:k,error:'Instance does not match "else" schema.'},...p.errors)}}if(b==="object"){if(U!==void 0){for(let p of U)if(!oe(e,p))c.push({instanceLocation:o,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${p}".`})}let k=Object.keys(e);if(X!==void 0&&k.length<X)c.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&k.length>V)c.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(ee!==void 0){let p=`${a}/propertyNames`;for(let l in e){let T=`${o}/${J(l)}`,x=N(l,ee,n,r,s,i,T,p);if(!x.valid)c.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...x.errors)}}if(te!==void 0){let p=`${a}/dependantRequired`;for(let l in te)if(oe(e,l)){let T=te[l];for(let x of T)if(!oe(e,x))c.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${x}".`})}}if(Ue!==void 0)for(let[p,l]of Object.entries(Ue)){let T=`${a}/dependentSchemas`;if(oe(e,p)){let x=N(e,l,n,r,s,i,o,`${T}/${J(p)}`,u);if(!x.valid)c.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:T,error:`Instance has "${p}" but does not match dependant schema.`},...x.errors)}}if(Re!==void 0){let p=`${a}/dependencies`;for(let l in Re)if(oe(e,l)){let T=Re[l];if(Array.isArray(T)){for(let x of T)if(!oe(e,x))c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${x}".`})}else{let x=N(e,T,n,r,s,i,o,`${p}/${J(l)}`);if(!x.valid)c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not match dependant schema.`},...x.errors)}}}let m=Object.create(null),I=!1;if(d!==void 0){let p=`${a}/properties`;for(let[l,T]of Object.entries(d)){if(!oe(e,l))continue;let x=`${o}/${J(l)}`,z=N(e[l],T,n,r,s,i,x,`${p}/${J(l)}`);if(m[l]=!0,z.valid)u[l]=!0;else if(I=s,c.push({instanceLocation:o,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...z.errors),I)break}}if(!I&&M!==void 0){let p=`${a}/patternProperties`;for(let[l,T]of Object.entries(M)){let x=new RegExp(l,"u");for(let z in e){if(!x.test(z))continue;let Ke=`${o}/${J(z)}`,Ye=N(e[z],T,n,r,s,i,Ke,`${p}/${J(l)}`);if(m[z]=!0,Ye.valid)u[z]=!0;else I=s,c.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:p,error:`Property "${z}" matches pattern "${l}" but does not match associated schema.`},...Ye.errors)}}}if(!I&&q!==void 0){let p=`${a}/additionalProperties`;for(let l in e){if(m[l])continue;let T=`${o}/${J(l)}`,x=N(e[l],q,n,r,s,i,T,p);if(x.valid)u[l]=!0;else I=s,c.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...x.errors)}}else if(!I&&H!==void 0){let p=`${a}/unevaluatedProperties`;for(let l in e)if(!u[l]){let T=`${o}/${J(l)}`,x=N(e[l],H,n,r,s,i,T,p);if(x.valid)u[l]=!0;else c.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...x.errors)}}}else if(b==="array"){if(Ce!==void 0&&e.length>Ce)c.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${Ce}).`});if(_e!==void 0&&e.length<_e)c.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${_e}).`});let k=e.length,m=0,I=!1;if(Ie!==void 0){let p=`${a}/prefixItems`,l=Math.min(Ie.length,k);for(;m<l;m++){let T=N(e[m],Ie[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!T.valid){if(I=s,c.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...T.errors),I)break}}}if(ce!==void 0){let p=`${a}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,k);for(;m<l;m++){let T=N(e[m],ce[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!T.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...T.errors),I)break}}}else for(;m<k;m++){let l=N(e[m],ce,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&Ve!==void 0){let l=`${a}/additionalItems`;for(;m<k;m++){let T=N(e[m],Ve,n,r,s,i,`${o}/${m}`,l);if(u[m]=!0,!T.valid)I=s,c.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...T.errors)}}}if(We!==void 0)if(k===0&&K===void 0)c.push({instanceLocation:o,keyword:"contains",keywordLocation:`${a}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(K!==void 0&&k<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${k}) than minContains (${K}).`});else{let p=`${a}/contains`,l=c.length,T=0;for(let x=0;x<k;x++){let z=N(e[x],We,n,r,s,i,`${o}/${x}`,p);if(z.valid)u[x]=!0,T++;else c.push(...z.errors)}if(T>=(K||0))c.length=l;if(K===void 0&&T===0)c.splice(l,0,{instanceLocation:o,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&T<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${T} items were found.`});else if(Me!==void 0&&T>Me)c.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Me} items matching schema. ${T} items were found.`})}if(!I&&Ge!==void 0){let p=`${a}/unevaluatedItems`;for(m;m<k;m++){if(u[m])continue;let l=N(e[m],Ge,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(Mt)for(let p=0;p<k;p++){let l=e[p],T=typeof l==="object"&&l!==null;for(let x=0;x<k;x++){if(p===x)continue;let z=e[x];if(l===z||T&&(typeof z==="object"&&z!==null)&&ue(l,z))c.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${a}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${x}.`}),p=Number.MAX_SAFE_INTEGER,x=Number.MAX_SAFE_INTEGER}}}else if(b==="number"){if(n==="4"){if(ne!==void 0&&(pe===!0&&e<=ne||e<ne))c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${ne}.`});if(re!==void 0&&(me===!0&&e>=re||e>re))c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${re}.`})}else{if(ne!==void 0&&e<ne)c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${ne}.`});if(re!==void 0&&e>re)c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${re}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ee!==void 0){if(!dn(e,Ee))c.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${Ee}.`})}}else if(b==="string"){let k=ye===void 0&&ge===void 0?0:tt(e);if(ye!==void 0&&k<ye)c.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${k} < ${ye}).`});if(ge!==void 0&&k>ge)c.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${k} > ${ge}).`});if(Fe!==void 0&&!new RegExp(Fe,"u").test(e))c.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(E!==void 0&&Ae[E]&&!Ae[E](e))c.push({instanceLocation:o,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${E}".`})}return{valid:c.length===0,errors:c}}var rt="ch.ractive.tab-mcp/annotations",un=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],ln=["destructiveHint","idempotentHint","openWorldHint"];function ot(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let s of ln){let i=e[s];if(i!==void 0)t[s]=i}let n={};for(let s of un){let i=e[s];if(i!==void 0)n[s]=i}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function st(e){let t=e._meta??{},n=t["ch.ractive.tab-mcp/annotations"];return{...e,_meta:{...t,["ch.ractive.tab-mcp/annotations"]:{...Y(n)?n:{},untrustedContentHint:!0}}}}function se(e){return{content:[{type:"text",text:e}],isError:!0}}function Y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var le=(e)=>typeof e==="string";function fn(e){if(!Y(e))return!1;switch(e.type){case"text":return le(e.text);case"image":case"audio":return le(e.data)&&le(e.mimeType);case"resource_link":return le(e.uri)&&le(e.name);case"resource":return Y(e.resource)&&le(e.resource.uri);default:return!1}}var cn=new Set(["content","structuredContent","isError","_meta","resultType"]);function it(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:s}=e;return(t.length>0?t.every(fn):Object.keys(e).every((i)=>cn.has(i)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(s===void 0||Y(s))}function at(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(it(e))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return se("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]},r=JSON.parse(t);if(Y(r))n.structuredContent=r;return n}function Oe(e,t=!1){return e.content.map((n)=>Y(n)&&n.type==="text"&&typeof n.text==="string"?n.text:t?`[${Y(n)?String(n.type):"A"} content left out: WebMCP results are text.]`:"").filter((n)=>n!=="").join(`
4
+ - `)}`,Error(l)}let I=`${a}/$ref`,p=j(e,m,n,r,s,i,o,I,u);if(!p.valid)c.push({instanceLocation:o,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...p.errors);if(n==="4"||n==="7")return{valid:c.length===0,errors:c}}if(Array.isArray(E)){let T=E.length,m=!1;for(let I=0;I<T;I++)if(k===E[I]||E[I]==="integer"&&k==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${k}" is invalid. Expected "${E.join('", "')}".`})}else if(E==="integer"){if(k!=="number"||e%1||e!==e)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${k}" is invalid. Expected "${E}".`})}else if(E!==void 0&&k!==E)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${k}" is invalid. Expected "${E}".`});if(O!==void 0){if(k==="object"||k==="array"){if(!ue(e,O))c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}if(q!==void 0){if(k==="object"||k==="array"){if(!q.some((T)=>ue(e,T)))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}else if(!q.some((T)=>e===T))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(q)}.`})}if(f!==void 0){let T=`${a}/not`;if(j(e,f,n,r,s,i,o,T).valid)c.push({instanceLocation:o,keyword:"not",keywordLocation:T,error:'Instance matched "not" schema.'})}let we=[];if(y!==void 0){let T=`${a}/anyOf`,m=c.length,I=!1;for(let[p,l]of y.entries()){let x=Object.create(u),w=j(e,l,n,r,s,N===!0?i:null,o,`${T}/${p}`,x);if(c.push(...w.errors),I=I||w.valid,w.valid)we.push(x)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:T,error:"Instance does not match any subschemas."})}if(g!==void 0){let T=`${a}/allOf`,m=c.length,I=!0;for(let[p,l]of g.entries()){let x=Object.create(u),w=j(e,l,n,r,s,N===!0?i:null,o,`${T}/${p}`,x);if(c.push(...w.errors),I=I&&w.valid,w.valid)we.push(x)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:T,error:"Instance does not match every subschema."})}if(b!==void 0){let T=`${a}/oneOf`,m=c.length,I=b.filter((p,l)=>{let x=Object.create(u),w=j(e,p,n,r,s,N===!0?i:null,o,`${T}/${l}`,x);if(c.push(...w.errors),w.valid)we.push(x);return w.valid}).length;if(I===1)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:T,error:`Instance does not match exactly one subschema (${I} matches).`})}if(k==="object"||k==="array")Object.assign(u,...we);if(h!==void 0){let T=`${a}/if`,m=Object.create(null);if(j(e,h,n,r,s,i,o,T,m).valid){if(Object.assign(u,m),R!==void 0){let p=j(e,R,n,r,s,i,o,`${a}/then`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:T,error:'Instance does not match "then" schema.'},...p.errors)}}else if(A!==void 0){let p=j(e,A,n,r,s,i,o,`${a}/else`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:T,error:'Instance does not match "else" schema.'},...p.errors)}}if(k==="object"){if(U!==void 0){for(let p of U)if(!oe(e,p))c.push({instanceLocation:o,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${p}".`})}let T=Object.keys(e);if(X!==void 0&&T.length<X)c.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&T.length>V)c.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(ee!==void 0){let p=`${a}/propertyNames`;for(let l in e){let x=`${o}/${J(l)}`,w=j(l,ee,n,r,s,i,x,p);if(!w.valid)c.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...w.errors)}}if(te!==void 0){let p=`${a}/dependantRequired`;for(let l in te)if(oe(e,l)){let x=te[l];for(let w of x)if(!oe(e,w))c.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}}if(Ue!==void 0)for(let[p,l]of Object.entries(Ue)){let x=`${a}/dependentSchemas`;if(oe(e,p)){let w=j(e,l,n,r,s,i,o,`${x}/${J(p)}`,u);if(!w.valid)c.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:x,error:`Instance has "${p}" but does not match dependant schema.`},...w.errors)}}if(Re!==void 0){let p=`${a}/dependencies`;for(let l in Re)if(oe(e,l)){let x=Re[l];if(Array.isArray(x)){for(let w of x)if(!oe(e,w))c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${w}".`})}else{let w=j(e,x,n,r,s,i,o,`${p}/${J(l)}`);if(!w.valid)c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not match dependant schema.`},...w.errors)}}}let m=Object.create(null),I=!1;if(d!==void 0){let p=`${a}/properties`;for(let[l,x]of Object.entries(d)){if(!oe(e,l))continue;let w=`${o}/${J(l)}`,D=j(e[l],x,n,r,s,i,w,`${p}/${J(l)}`);if(m[l]=!0,D.valid)u[l]=!0;else if(I=s,c.push({instanceLocation:o,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...D.errors),I)break}}if(!I&&C!==void 0){let p=`${a}/patternProperties`;for(let[l,x]of Object.entries(C)){let w=new RegExp(l,"u");for(let D in e){if(!w.test(D))continue;let Ke=`${o}/${J(D)}`,Ye=j(e[D],x,n,r,s,i,Ke,`${p}/${J(l)}`);if(m[D]=!0,Ye.valid)u[D]=!0;else I=s,c.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:p,error:`Property "${D}" matches pattern "${l}" but does not match associated schema.`},...Ye.errors)}}}if(!I&&H!==void 0){let p=`${a}/additionalProperties`;for(let l in e){if(m[l])continue;let x=`${o}/${J(l)}`,w=j(e[l],H,n,r,s,i,x,p);if(w.valid)u[l]=!0;else I=s,c.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...w.errors)}}else if(!I&&z!==void 0){let p=`${a}/unevaluatedProperties`;for(let l in e)if(!u[l]){let x=`${o}/${J(l)}`,w=j(e[l],z,n,r,s,i,x,p);if(w.valid)u[l]=!0;else c.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...w.errors)}}}else if(k==="array"){if(Ce!==void 0&&e.length>Ce)c.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${Ce}).`});if(_e!==void 0&&e.length<_e)c.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${_e}).`});let T=e.length,m=0,I=!1;if(Ie!==void 0){let p=`${a}/prefixItems`,l=Math.min(Ie.length,T);for(;m<l;m++){let x=j(e[m],Ie[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=s,c.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...x.errors),I)break}}}if(ce!==void 0){let p=`${a}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,T);for(;m<l;m++){let x=j(e[m],ce[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!x.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...x.errors),I)break}}}else for(;m<T;m++){let l=j(e[m],ce,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&Ve!==void 0){let l=`${a}/additionalItems`;for(;m<T;m++){let x=j(e[m],Ve,n,r,s,i,`${o}/${m}`,l);if(u[m]=!0,!x.valid)I=s,c.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...x.errors)}}}if(We!==void 0)if(T===0&&K===void 0)c.push({instanceLocation:o,keyword:"contains",keywordLocation:`${a}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(K!==void 0&&T<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${T}) than minContains (${K}).`});else{let p=`${a}/contains`,l=c.length,x=0;for(let w=0;w<T;w++){let D=j(e[w],We,n,r,s,i,`${o}/${w}`,p);if(D.valid)u[w]=!0,x++;else c.push(...D.errors)}if(x>=(K||0))c.length=l;if(K===void 0&&x===0)c.splice(l,0,{instanceLocation:o,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&x<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${x} items were found.`});else if(Me!==void 0&&x>Me)c.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Me} items matching schema. ${x} items were found.`})}if(!I&&Ge!==void 0){let p=`${a}/unevaluatedItems`;for(m;m<T;m++){if(u[m])continue;let l=j(e[m],Ge,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(Mt)for(let p=0;p<T;p++){let l=e[p],x=typeof l==="object"&&l!==null;for(let w=0;w<T;w++){if(p===w)continue;let D=e[w];if(l===D||x&&(typeof D==="object"&&D!==null)&&ue(l,D))c.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${a}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${w}.`}),p=Number.MAX_SAFE_INTEGER,w=Number.MAX_SAFE_INTEGER}}}else if(k==="number"){if(n==="4"){if(ne!==void 0&&(pe===!0&&e<=ne||e<ne))c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${ne}.`});if(re!==void 0&&(me===!0&&e>=re||e>re))c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${re}.`})}else{if(ne!==void 0&&e<ne)c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${ne}.`});if(re!==void 0&&e>re)c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${re}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ee!==void 0){if(!dn(e,Ee))c.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${Ee}.`})}}else if(k==="string"){let T=ye===void 0&&ge===void 0?0:tt(e);if(ye!==void 0&&T<ye)c.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${T} < ${ye}).`});if(ge!==void 0&&T>ge)c.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${T} > ${ge}).`});if(Fe!==void 0&&!new RegExp(Fe,"u").test(e))c.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(S!==void 0&&Ae[S]&&!Ae[S](e))c.push({instanceLocation:o,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${S}".`})}return{valid:c.length===0,errors:c}}var rt="ch.ractive.tab-mcp/annotations",un=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],ln=["destructiveHint","idempotentHint","openWorldHint"];function ot(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let s of ln){let i=e[s];if(i!==void 0)t[s]=i}let n={};for(let s of un){let i=e[s];if(i!==void 0)n[s]=i}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function st(e){let t=e._meta??{},n=t["ch.ractive.tab-mcp/annotations"];return{...e,_meta:{...t,["ch.ractive.tab-mcp/annotations"]:{...Y(n)?n:{},untrustedContentHint:!0}}}}function se(e){return{content:[{type:"text",text:e}],isError:!0}}function Y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var le=(e)=>typeof e==="string";function fn(e){if(!Y(e))return!1;switch(e.type){case"text":return le(e.text);case"image":case"audio":return le(e.data)&&le(e.mimeType);case"resource_link":return le(e.uri)&&le(e.name);case"resource":return Y(e.resource)&&le(e.resource.uri);default:return!1}}var cn=new Set(["content","structuredContent","isError","_meta","resultType"]);function it(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:s}=e;return(t.length>0?t.every(fn):Object.keys(e).every((i)=>cn.has(i)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(s===void 0||Y(s))}function at(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(it(e))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return se("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]},r=JSON.parse(t);if(Y(r))n.structuredContent=r;return n}function Oe(e,t=!1){return e.content.map((n)=>Y(n)&&n.type==="text"&&typeof n.text==="string"?n.text:t?`[${Y(n)?String(n.type):"A"} content left out: WebMCP results are text.]`:"").filter((n)=>n!=="").join(`
5
5
  `)}function dt(e){if(it(e))return e.structuredContent??(Oe(e,!0)||"Done.");return e===void 0?"Done.":e}function ut(e){let t=e instanceof Error?e.message:String(e);return se(t||"The tool failed.")}var ie="2026-07-28",Q="io.modelcontextprotocol/protocolVersion",xe="io.modelcontextprotocol/clientCapabilities",lt="io.modelcontextprotocol/clientInfo",ft="io.modelcontextprotocol/serverInfo",Pe="io.modelcontextprotocol/subscriptionId",pn=-32020,ct=-32022,mn="The page may ask the user to allow each call, usually in the page's browser tab.",yn=0,pt=new WeakMap;function Ne(e){let t=pt.get(e);if(t!==void 0)return t;let n=e.inputSchema,r;try{r=Z(n)}catch(i){let o=i instanceof Error?i.message:String(i);throw Error(o.split(`
6
- `)[0])}for(let i of Object.values(r)){if(typeof i!=="object"||i.$ref===void 0)continue;let o=i.__absolute_ref__;if(r[o??i.$ref]===void 0)throw Error(`$ref ${JSON.stringify(i.$ref)} does not resolve`)}let s=(i)=>N(i,n,"2020-12",r,!1);return pt.set(e,s),s}function mt(e,t,n=""){let r=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${r}${n}`)}function gn(e){let t=[];for(let n of e.list())try{Ne(n)}catch(r){e.remove(n),t.push(mt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Ne(n)}catch(r){throw mt(n.name,r)}}),t}function yt(e){try{return structuredClone(e)}catch{return e}}var hn=new TextEncoder;function L(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function je(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function B(e,t,n,r,s){let i={code:n,message:r};if(s!==void 0)i.data=s;return je(e,{jsonrpc:"2.0",id:t,error:i})}function W(e,t,n){return B(400,e,pn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return hn.encode(`event: message
6
+ `)[0])}for(let i of Object.values(r)){if(typeof i!=="object"||i.$ref===void 0)continue;let o=i.__absolute_ref__;if(r[o??i.$ref]===void 0)throw Error(`$ref ${JSON.stringify(i.$ref)} does not resolve`)}let s=(i)=>j(i,n,"2020-12",r,!1);return pt.set(e,s),s}function mt(e,t,n=""){let r=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${r}${n}`)}function gn(e){let t=[];for(let n of e.list())try{Ne(n)}catch(r){e.remove(n),t.push(mt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Ne(n)}catch(r){throw mt(n.name,r)}}),t}function yt(e){try{return structuredClone(e)}catch{return e}}var hn=new TextEncoder;function L(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function je(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function B(e,t,n,r,s){let i={code:n,message:r};if(s!==void 0)i.data=s;return je(e,{jsonrpc:"2.0",id:t,error:i})}function W(e,t,n){return B(400,e,pn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return hn.encode(`event: message
7
7
  data: ${JSON.stringify(e)}
8
8
 
9
- `)}var gt={"content-type":"text/event-stream","cache-control":"no-cache"};function wn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function bn(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),r=Uint8Array.from(n,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function $n(e){if(!(Q in e))return{key:Q,problem:"missing"};if(!(xe in e))return{key:xe,problem:"missing"};if(typeof e[Q]!=="string")return{key:Q,problem:"expected a protocol version string"};if(!L(e[xe]))return{key:xe,problem:"expected an object"};let t=e[lt];if(t!==void 0&&!(L(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:lt,problem:"expected {name, version}"};return}function xn(e){let t=e.notifications;return L(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function vn(e,t){let n;try{n=Ne(e)(t)}catch(s){let i=s instanceof Error?s.message:String(s);return`The input schema of tool ${e.name} cannot be used: ${i}`}if(n.valid)return;let r=n.errors.filter((s)=>s.keyword!=="properties"&&s.keyword!=="$ref").map((s)=>`${s.instanceLocation} ${s.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${r||"the arguments do not match the schema"}`}async function ht(e,t,n,r,s,i){let o={id:++yn,tool:t.name,arguments:yt(n),client:{...s}};if(t.title!==void 0)o.title=t.title;let a=Date.now();e.observe?.start(o);let u={outcome:"error",result:se("Internal error")};try{if(u=await kn(e,t,n,r,s),t.annotations.untrustedContentHint===!0)u.result=st(u.result);let y=r.aborted?void 0:i?.(u.result);if(y!==void 0)u={outcome:"error",result:y}}finally{e.observe?.end({id:o.id,tool:t.name,client:{...s},outcome:u.outcome,result:yt(u.result),durationMs:Date.now()-a})}return u}var Tn="The user was asked and did not answer.";async function kn(e,t,n,r,s){let i=(y,b,_)=>({outcome:y,result:se(b),stop:_}),o=vn(t,n);if(o!==void 0)return i("error",o,"invalid");let a=new Promise((y,b)=>{if(r.aborted)b(r.reason);r.addEventListener("abort",()=>b(r.reason))});if(a.catch(()=>{}),t.annotations.consequentialHint===!0){let y={tool:{name:t.name,description:t.description},arguments:n,client:s,signal:r};if(t.title!==void 0)y.tool.title=t.title;let b=!1;try{b=await Promise.race([e.confirm(y),a])}catch{b=!1}if(b!==!0){if(r.aborted)return i("cancelled","The call was cancelled.","cancelled");return b==="unanswered"?i("unanswered",Tn,"unanswered"):i("declined","The user did not allow this call.","declined")}}if(r.aborted)return i("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return i("error","The tool is no longer available","gone");let u;try{let y=await Promise.race([t.execute(n,{signal:r,client:s}),a]);u={outcome:"ok",result:at(y),returned:{value:y}}}catch(y){u={outcome:"error",result:ut(y)}}if(r.aborted)return{...u,outcome:"cancelled",stop:"cancelled"};if(u.result.isError===!0)u.outcome="error";return u}async function qe(e,t,n,r,s){let i=(u)=>({error:u}),o=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return i(o);if(!L(n))return i("The input must be an object.");let a=await ht(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,s);if(a.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(a.stop==="declined")return i(`The user did not allow ${t.name} to run.`);if(a.stop==="unanswered")return i(`The user did not answer whether ${t.name} may run.`);if(a.stop==="gone")return i(o);if(a.result.isError===!0)return i(Oe(a.result)||"The tool failed.");return dt(a.returned?.value)}function ve(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let s=Se(n.icons??[]),i=s.length>0?{...r,icons:s}:r,o=new Set,a=!1,u=(f={})=>({...f,[ft]:r});function y(f,g,h=u()){return{jsonrpc:"2.0",id:f,result:{...g,resultType:"complete",_meta:h}}}function b(){return t.list().map((f)=>{let g={name:f.name};if(f.title!==void 0)g.title=f.title;if(g.description=f.annotations.consequentialHint===!0&&!e.ownConfirm?`${f.description} ${mn}`:f.description,g.inputSchema=f.inputSchema,f.outputSchema!==void 0)g.outputSchema=f.outputSchema;let{annotations:h,meta:v}=ot(f.annotations);if(h!==void 0)g.annotations=h;if(v!==void 0)g._meta={[rt]:v};return g})}let _=(f)=>({kind:"invalid",message:f});async function A(f,g,h,v){let w=f.name;if(typeof w!=="string")return _("Invalid params: name must be a string");let R=t.get(w);if(R===void 0)return _(`Tool ${w} not found`);let S=f.arguments??{};if(!L(S))return _("Invalid params: arguments must be an object");return{kind:"result",result:(await ht(e,R,S,g,e.client(h),v)).result}}function D(f,g,h,v){let w=(d)=>ae(y(f,d,u(d._meta))),R,S=(d)=>{let M;try{M=w(d)}catch{return se("The tool returned a result that is not JSON.")}let q=e.maxBodyBytes?.();if(q!==void 0&&M.byteLength>q)return se(`The result is ${M.byteLength} bytes; the relay passes on at most ${q}.`);R={result:d,event:M};return},E=new ReadableStream({start:(d)=>{let M=(q)=>{if(h.aborted)return;try{d.enqueue(q()),d.close()}catch{}};A(g,h,v,S).then((q)=>M(()=>q.kind==="invalid"?ae({jsonrpc:"2.0",id:f,error:{code:-32602,message:q.message}}):q.result===R?.result?R.event:w(q.result)),()=>M(()=>ae({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}})))}});return new Response(E,{status:200,headers:gt})}function C(f,g,h){let v=xn(g),w={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[Pe]:f})}},R,S=new ReadableStream({start:(E)=>{if(E.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:v,_meta:{[Pe]:f}}})),Object.keys(v).length===0){E.enqueue(ae(w)),E.close();return}let d={id:f,send:(M)=>{try{E.enqueue(ae(M))}catch{o.delete(d)}},end:()=>{o.delete(d);try{E.enqueue(ae(w)),E.close()}catch{}}};R=d,o.add(d),h.addEventListener("abort",()=>{o.delete(d);try{E.close()}catch{}})},cancel:()=>{if(R!==void 0)o.delete(R)}});return new Response(S,{status:200,headers:gt})}function O(f,g){if(Array.isArray(g))return B(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!L(g)||g.jsonrpc!=="2.0")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:h,id:v}=g;if(typeof h!=="string")return"result"in g||"error"in g?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 w=f.headers.get("mcp-protocol-version"),R=f.headers.get("mcp-method"),S=L(g.params)?g.params:{},E=L(S._meta)?S._meta:void 0,d=E!==void 0&&Q in E,M=typeof E?.[Q]==="string"?E[Q]:void 0,q=w!==null&&w>=ie;if(v===void 0){if(M!==void 0&&w!==null&&w!==M)return W(null,w,`the notification envelope names protocol version ${M} but the MCP-Protocol-Version header names ${w}`);if((d||q)&&R!==null&&R!==h)return W(null,R,`the notification body names method ${h} but the Mcp-Method header names ${R}`);return"notification"}if(typeof v!=="string"&&typeof v!=="number")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let H=v;if(!d||h==="initialize"&&(M===void 0||M<ie)){if(h==="initialize"){if(q)return W(H,w,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let V=typeof S.protocolVersion==="string"?S.protocolVersion:void 0;return j(H,V)}if(q){let V=E===void 0?["_meta"]:[Q];return B(400,H,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${w}, but the request is missing the required per-request envelope key(s): ${V.join(", ")}`,{envelope:{missing:V}})}return j(H,w??void 0)}let X=$n(E);if(X!==void 0)return B(400,H,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${X.key}: ${X.problem}`,{envelope:X});if(w!==null&&M!==void 0&&w!==M)return W(H,w,`the body envelope names protocol version ${M} but the MCP-Protocol-Version header names ${w}`);if(R!==null&&R!==h)return W(H,R,`the body names method ${h} but the Mcp-Method header names ${R}`);if(M!==ie)return j(H,M);if(w===null)return W(H,"(missing)",`the body envelope names protocol version ${M} but the required MCP-Protocol-Version header is absent`);if(R===null)return W(H,"(missing)",`the body names method ${h} but the required Mcp-Method header is absent`);if(h==="tools/call"&&typeof S.name==="string"){let V=S.name,ee=f.headers.get("mcp-name");if(ee===null)return W(H,"(missing)",`the body carries params.name="${V}" but the required Mcp-Name header is absent`);let te=bn(ee);if(te===void 0)return W(H,ee,"the Mcp-Name header carries an invalid Base64 sentinel value");if(te!==V)return W(H,ee,`the body carries params.name="${V}" but the Mcp-Name header names "${te}"`)}return{id:H,method:h,params:S}}function j(f,g){return g===void 0?B(400,f,ct,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):B(400,f,ct,`Unsupported protocol version: ${g}`,{supported:[ie],requested:g})}async function U(f,g){if(f.method.toUpperCase()!=="POST")return B(405,null,-32000,"Method not allowed.");if(!wn(f.headers.get("content-type")))return B(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let h;try{h=JSON.parse(g.body??await f.text())}catch{return B(400,null,-32700,"Parse error: the request body is not valid JSON")}let v=O(f,h);if(v instanceof Response)return v;if(v==="notification")return new Response(null,{status:202});let{id:w,method:R,params:S}=v;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",je(200,y(w,E,{[ft]:i}))}case"tools/list":return je(200,y(w,{tools:b(),ttlMs:0,cacheScope:"private"}));case"tools/call":return D(w,S,f.signal,g.grant);case"subscriptions/listen":return C(w,S,f.signal);default:return B(404,w,-32601,"Method not found")}}return{handle:(f,g)=>U(f,g).catch(()=>B(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let f of[...o])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Pe]:f.id}}})})},close(){for(let f of[...o])f.end()}}}var Te="tab-mcp.v1",Rn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function wt(e){if(!fe(e)||!P(e.grantId)||!P(e.createdAt))return!1;let t=e.client;return fe(t)&&P(t.id)&&P(t.name)&&P(t.host)}function In(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Mn(e){return fe(e)&&Object.values(e).every(P)}function bt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return P(t.sessionId)&&P(t.address)&&P(t.origin)&&P(t.expiresAt)&&In(t.limits)&&Array.isArray(t.grants)&&t.grants.every(wt)&&(t.appName===void 0||P(t.appName))&&(t.pairing===void 0||P(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:P(t.reason)?t.reason:""};case"http.request":return P(t.id)&&P(t.method)&&P(t.path)&&Mn(t.headers)&&P(t.body)&&fe(t.grant)&&P(t.grant.grantId)&&P(t.grant.clientId)?t:void 0;case"http.cancel":return P(t.id)?t:void 0;case"pairing.code":{if(!P(t.code)||!P(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},r=t.reason;if(typeof r==="string"&&Rn.has(r))n.reason=r;return n}case"pairing.open":{let n=t.expiresInMs;if(typeof n==="number"&&Number.isFinite(n)&&n>=0&&n<=2147483647)return{type:"pairing.open",expiresAt:new Date(Date.now()+n).toISOString()};return P(t.expiresAt)&&!Number.isNaN(Date.parse(t.expiresAt))?{type:"pairing.open",expiresAt:t.expiresAt}:void 0}case"grant.added":return wt(t.grant)?t:void 0;case"grant.removed":return P(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:P(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return P(t.code)?t:void 0;default:return}}function _n(e,t){let n=(r)=>r&&(r.callers?.includes(t)??!0);return{list:()=>e.list().filter(n),get:(r)=>{let s=e.get(r);return n(s)?s:void 0}}}function Be(e,t,n){let r=t.list();return e.onChange(()=>{let s=t.list();if(s.length===r.length&&s.every((i,o)=>i===r[o]))return;r=s,n()})}function ke(e,t){return{tools:t==="webmcp"?e.registry:_n(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:e.ownConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var Cn=["content-type","cache-control"];function*De(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),s=e.charCodeAt(r-1);if(r<e.length&&s>=55296&&s<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var En=-31002,Sn="The page did not answer in time.";function An(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Je(e){let{handler:t,send:n,timeoutMs:r}=e,s=new Map,i=!1;async function o(a){let u=new AbortController;s.get(a.id)?.abort(),s.set(a.id,u);let y=()=>!i&&s.get(a.id)===u&&!u.signal.aborted,b=!1,_="",A=Object.entries(a.headers).some(([C,O])=>C.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),D=r===void 0||A?void 0:setTimeout(()=>{if(!y())return;u.abort();let C=JSON.stringify({jsonrpc:"2.0",id:An(a.body),error:{code:En,message:Sn}});if(!b){n({type:"http.response",id:a.id,status:200,headers:{"content-type":"application/json"},body:C});return}if(_===""||_===`
9
+ `)}var gt={"content-type":"text/event-stream","cache-control":"no-cache"};function wn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function bn(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),r=Uint8Array.from(n,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function $n(e){if(!(Q in e))return{key:Q,problem:"missing"};if(!(xe in e))return{key:xe,problem:"missing"};if(typeof e[Q]!=="string")return{key:Q,problem:"expected a protocol version string"};if(!L(e[xe]))return{key:xe,problem:"expected an object"};let t=e[lt];if(t!==void 0&&!(L(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:lt,problem:"expected {name, version}"};return}function xn(e){let t=e.notifications;return L(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function vn(e,t){let n;try{n=Ne(e)(t)}catch(s){let i=s instanceof Error?s.message:String(s);return`The input schema of tool ${e.name} cannot be used: ${i}`}if(n.valid)return;let r=n.errors.filter((s)=>s.keyword!=="properties"&&s.keyword!=="$ref").map((s)=>`${s.instanceLocation} ${s.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${r||"the arguments do not match the schema"}`}async function ht(e,t,n,r,s,i){let o={id:++yn,tool:t.name,arguments:yt(n),client:{...s}};if(t.title!==void 0)o.title=t.title;let a=Date.now();e.observe?.start(o);let u={outcome:"error",result:se("Internal error")};try{if(u=await kn(e,t,n,r,s),t.annotations.untrustedContentHint===!0)u.result=st(u.result);let v=r.aborted?void 0:i?.(u.result);if(v!==void 0)u={outcome:"error",result:v}}finally{e.observe?.end({id:o.id,tool:t.name,client:{...s},outcome:u.outcome,result:yt(u.result),durationMs:Date.now()-a})}return u}var Tn="The user was asked and did not answer.";async function kn(e,t,n,r,s){let i=(_,N,E)=>({outcome:_,result:se(N),stop:E}),o=vn(t,n);if(o!==void 0)return i("error",o,"invalid");let a=new Promise((_,N)=>{if(r.aborted)N(r.reason);r.addEventListener("abort",()=>N(r.reason))});a.catch(()=>{});let{consequentialHint:u,destructiveHint:v}=t.annotations;if((s.kind==="webmcp"?u??v:u)===!0){let _={tool:{name:t.name,description:t.description},arguments:n,client:s,signal:r};if(t.title!==void 0)_.tool.title=t.title;let N=!1;try{N=await Promise.race([e.confirm(_),a])}catch{N=!1}if(N!==!0){if(r.aborted)return i("cancelled","The call was cancelled.","cancelled");return N==="unanswered"?i("unanswered",Tn,"unanswered"):i("declined","The user did not allow this call.","declined")}}if(r.aborted)return i("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return i("error","The tool is no longer available","gone");let M;try{let _=await Promise.race([t.execute(n,{signal:r,client:s}),a]);M={outcome:"ok",result:at(_),returned:{value:_}}}catch(_){M={outcome:"error",result:ut(_)}}if(r.aborted)return{...M,outcome:"cancelled",stop:"cancelled"};if(M.result.isError===!0)M.outcome="error";return M}async function qe(e,t,n,r,s){let i=(u)=>({error:u}),o=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return i(o);if(!L(n))return i("The input must be an object.");let a=await ht(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,s);if(a.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(a.stop==="declined")return i(`The user did not allow ${t.name} to run.`);if(a.stop==="unanswered")return i(`The user did not answer whether ${t.name} may run.`);if(a.stop==="gone")return i(o);if(a.result.isError===!0)return i(Oe(a.result)||"The tool failed.");return dt(a.returned?.value)}function ve(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let s=Se(n.icons??[]),i=s.length>0?{...r,icons:s}:r,o=new Set,a=!1,u=(f={})=>({...f,[ft]:r});function v(f,y,g=u()){return{jsonrpc:"2.0",id:f,result:{...y,resultType:"complete",_meta:g}}}function k(){return t.list().map((f)=>{let y={name:f.name};if(f.title!==void 0)y.title=f.title;if(y.description=f.annotations.consequentialHint===!0&&!e.ownConfirm?`${f.description} ${mn}`:f.description,y.inputSchema=f.inputSchema,f.outputSchema!==void 0)y.outputSchema=f.outputSchema;let{annotations:g,meta:b}=ot(f.annotations);if(g!==void 0)y.annotations=g;if(b!==void 0)y._meta={[rt]:b};return y})}let M=(f)=>({kind:"invalid",message:f});async function _(f,y,g,b){let h=f.name;if(typeof h!=="string")return M("Invalid params: name must be a string");let R=t.get(h);if(R===void 0)return M(`Tool ${h} not found`);let A=f.arguments??{};if(!L(A))return M("Invalid params: arguments must be an object");return{kind:"result",result:(await ht(e,R,A,y,e.client(g),b)).result}}function N(f,y,g,b){let h=(d)=>ae(v(f,d,u(d._meta))),R,A=(d)=>{let C;try{C=h(d)}catch{return se("The tool returned a result that is not JSON.")}let H=e.maxBodyBytes?.();if(H!==void 0&&C.byteLength>H)return se(`The result is ${C.byteLength} bytes; the relay passes on at most ${H}.`);R={result:d,event:C};return},S=new ReadableStream({start:(d)=>{let C=(H)=>{if(g.aborted)return;try{d.enqueue(H()),d.close()}catch{}};_(y,g,b,A).then((H)=>C(()=>H.kind==="invalid"?ae({jsonrpc:"2.0",id:f,error:{code:-32602,message:H.message}}):H.result===R?.result?R.event:h(H.result)),()=>C(()=>ae({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}})))}});return new Response(S,{status:200,headers:gt})}function E(f,y,g){let b=xn(y),h={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[Pe]:f})}},R,A=new ReadableStream({start:(S)=>{if(S.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:b,_meta:{[Pe]:f}}})),Object.keys(b).length===0){S.enqueue(ae(h)),S.close();return}let d={id:f,send:(C)=>{try{S.enqueue(ae(C))}catch{o.delete(d)}},end:()=>{o.delete(d);try{S.enqueue(ae(h)),S.close()}catch{}}};R=d,o.add(d),g.addEventListener("abort",()=>{o.delete(d);try{S.close()}catch{}})},cancel:()=>{if(R!==void 0)o.delete(R)}});return new Response(A,{status:200,headers:gt})}function O(f,y){if(Array.isArray(y))return B(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!L(y)||y.jsonrpc!=="2.0")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:g,id:b}=y;if(typeof g!=="string")return"result"in y||"error"in y?B(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let h=f.headers.get("mcp-protocol-version"),R=f.headers.get("mcp-method"),A=L(y.params)?y.params:{},S=L(A._meta)?A._meta:void 0,d=S!==void 0&&Q in S,C=typeof S?.[Q]==="string"?S[Q]:void 0,H=h!==null&&h>=ie;if(b===void 0){if(C!==void 0&&h!==null&&h!==C)return W(null,h,`the notification envelope names protocol version ${C} but the MCP-Protocol-Version header names ${h}`);if((d||H)&&R!==null&&R!==g)return W(null,R,`the notification body names method ${g} but the Mcp-Method header names ${R}`);return"notification"}if(typeof b!=="string"&&typeof b!=="number")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let z=b;if(!d||g==="initialize"&&(C===void 0||C<ie)){if(g==="initialize"){if(H)return W(z,h,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let V=typeof A.protocolVersion==="string"?A.protocolVersion:void 0;return q(z,V)}if(H){let V=S===void 0?["_meta"]:[Q];return B(400,z,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${h}, but the request is missing the required per-request envelope key(s): ${V.join(", ")}`,{envelope:{missing:V}})}return q(z,h??void 0)}let X=$n(S);if(X!==void 0)return B(400,z,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${X.key}: ${X.problem}`,{envelope:X});if(h!==null&&C!==void 0&&h!==C)return W(z,h,`the body envelope names protocol version ${C} but the MCP-Protocol-Version header names ${h}`);if(R!==null&&R!==g)return W(z,R,`the body names method ${g} but the Mcp-Method header names ${R}`);if(C!==ie)return q(z,C);if(h===null)return W(z,"(missing)",`the body envelope names protocol version ${C} but the required MCP-Protocol-Version header is absent`);if(R===null)return W(z,"(missing)",`the body names method ${g} but the required Mcp-Method header is absent`);if(g==="tools/call"&&typeof A.name==="string"){let V=A.name,ee=f.headers.get("mcp-name");if(ee===null)return W(z,"(missing)",`the body carries params.name="${V}" but the required Mcp-Name header is absent`);let te=bn(ee);if(te===void 0)return W(z,ee,"the Mcp-Name header carries an invalid Base64 sentinel value");if(te!==V)return W(z,ee,`the body carries params.name="${V}" but the Mcp-Name header names "${te}"`)}return{id:z,method:g,params:A}}function q(f,y){return y===void 0?B(400,f,ct,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):B(400,f,ct,`Unsupported protocol version: ${y}`,{supported:[ie],requested:y})}async function U(f,y){if(f.method.toUpperCase()!=="POST")return B(405,null,-32000,"Method not allowed.");if(!wn(f.headers.get("content-type")))return B(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let g;try{g=JSON.parse(y.body??await f.text())}catch{return B(400,null,-32700,"Parse error: the request body is not valid JSON")}let b=O(f,g);if(b instanceof Response)return b;if(b==="notification")return new Response(null,{status:202});let{id:h,method:R,params:A}=b;switch(R){case"server/discover":{let S={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)S.instructions=n.instructions;return S.ttlMs=0,S.cacheScope="private",je(200,v(h,S,{[ft]:i}))}case"tools/list":return je(200,v(h,{tools:k(),ttlMs:0,cacheScope:"private"}));case"tools/call":return N(h,A,f.signal,y.grant);case"subscriptions/listen":return E(h,A,f.signal);default:return B(404,h,-32601,"Method not found")}}return{handle:(f,y)=>U(f,y).catch(()=>B(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let f of[...o])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Pe]:f.id}}})})},close(){for(let f of[...o])f.end()}}}var Te="tab-mcp.v1",Rn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function wt(e){if(!fe(e)||!P(e.grantId)||!P(e.createdAt))return!1;let t=e.client;return fe(t)&&P(t.id)&&P(t.name)&&P(t.host)}function In(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Mn(e){return fe(e)&&Object.values(e).every(P)}function bt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return P(t.sessionId)&&P(t.address)&&P(t.origin)&&P(t.expiresAt)&&In(t.limits)&&Array.isArray(t.grants)&&t.grants.every(wt)&&(t.appName===void 0||P(t.appName))&&(t.pairing===void 0||P(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:P(t.reason)?t.reason:""};case"http.request":return P(t.id)&&P(t.method)&&P(t.path)&&Mn(t.headers)&&P(t.body)&&fe(t.grant)&&P(t.grant.grantId)&&P(t.grant.clientId)?t:void 0;case"http.cancel":return P(t.id)?t:void 0;case"pairing.code":{if(!P(t.code)||!P(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},r=t.reason;if(typeof r==="string"&&Rn.has(r))n.reason=r;return n}case"pairing.open":{let n=t.expiresInMs;if(typeof n==="number"&&Number.isFinite(n)&&n>=0&&n<=2147483647)return{type:"pairing.open",expiresAt:new Date(Date.now()+n).toISOString()};return P(t.expiresAt)&&!Number.isNaN(Date.parse(t.expiresAt))?{type:"pairing.open",expiresAt:t.expiresAt}:void 0}case"grant.added":return wt(t.grant)?t:void 0;case"grant.removed":return P(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:P(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return P(t.code)?t:void 0;default:return}}function _n(e,t){let n=(r)=>r&&(r.callers?.includes(t)??!0);return{list:()=>e.list().filter(n),get:(r)=>{let s=e.get(r);return n(s)?s:void 0}}}function Be(e,t,n){let r=t.list();return e.onChange(()=>{let s=t.list();if(s.length===r.length&&s.every((i,o)=>i===r[o]))return;r=s,n()})}function ke(e,t){return{tools:t==="webmcp"?e.registry:_n(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:e.ownConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var Cn=["content-type","cache-control"];function*De(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),s=e.charCodeAt(r-1);if(r<e.length&&s>=55296&&s<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var En=-31002,Sn="The page did not answer in time.";function An(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Je(e){let{handler:t,send:n,timeoutMs:r}=e,s=new Map,i=!1;async function o(a){let u=new AbortController;s.get(a.id)?.abort(),s.set(a.id,u);let v=()=>!i&&s.get(a.id)===u&&!u.signal.aborted,k=!1,M="",_=Object.entries(a.headers).some(([E,O])=>E.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),N=r===void 0||_?void 0:setTimeout(()=>{if(!v())return;u.abort();let E=JSON.stringify({jsonrpc:"2.0",id:An(a.body),error:{code:En,message:Sn}});if(!k){n({type:"http.response",id:a.id,status:200,headers:{"content-type":"application/json"},body:E});return}if(M===""||M===`
10
10
 
11
11
  `)n({type:"http.response.chunk",id:a.id,data:`event: message
12
- data: ${C}
12
+ data: ${E}
13
13
 
14
- `});n({type:"http.response.end",id:a.id})},r);try{let C=new Request(`https://tab.invalid${a.path}`,{method:a.method,headers:a.headers,signal:u.signal}),O=await t.handle(C,{grant:a.grant,body:a.body});if(!y()){await O.body?.cancel().catch(()=>{});return}let j={};for(let v of Cn){let w=O.headers.get(v);if(w!==null)j[v]=w}let U=(j["content-type"]??"").startsWith("text/event-stream"),f=e.maxChunk();if(!U||O.body===null){let v=await O.text();if(!y())return;if(v.length<=f){n({type:"http.response",id:a.id,status:O.status,headers:j,body:v});return}n({type:"http.response.start",id:a.id,status:O.status,headers:j});for(let w of De(v,f)){if(!y())break;n({type:"http.response.chunk",id:a.id,data:w})}if(y())n({type:"http.response.end",id:a.id});return}n({type:"http.response.start",id:a.id,status:O.status,headers:j}),b=!0;let g=O.body.getReader(),h=new TextDecoder;u.signal.addEventListener("abort",()=>{g.cancel().catch(()=>{})});for(;;){let{done:v,value:w}=await g.read();if(v||!y())break;let R=h.decode(w,{stream:!0});if(R!=="")_=(_+R).slice(-2);for(let S of De(R,f))n({type:"http.response.chunk",id:a.id,data:S})}if(y())n({type:"http.response.end",id:a.id})}catch(C){if(y())e.error(C instanceof Error?C:Error(String(C))),n({type:"http.response",id:a.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(clearTimeout(D),s.get(a.id)===u)s.delete(a.id)}}return{request(a){if(!i)o(a)},cancel(a){s.get(a)?.abort(),s.delete(a)},close(){if(i)return;i=!0;for(let a of s.values())a.abort();s.clear()}}}var On=65536,$t=64,Pn=300000,xt=128,He=new WeakSet,Nn=0,F=(e)=>typeof e==="string";function ze(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function jn(e,t,n){let r=n?.client;if(!ze(r)||!F(r.id)||r.id===""||r.name!==void 0&&!F(r.name))throw TypeError("serve: client needs an id (and may have a name)");let s=n.maxChunk??On;if(!Number.isInteger(s)||s<$t)throw TypeError(`serve: maxChunk must be a whole number of at least ${$t}`);let i=n.requestTimeoutMs??Pn;if(typeof i!=="number"||!(i>0)||i>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let o=n.onConfirm;if(o!==void 0&&typeof o!=="function")throw TypeError("serve: onConfirm must be a function");if(typeof t?.postMessage!=="function"||!("onmessage"in t))throw TypeError("serve: the port needs postMessage and onmessage");if(He.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let a={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")a.name=r.name;let u={grantId:`local:${++Nn}`,clientId:r.id,scopes:["tools"]},y=!1,b=(g)=>{if(y)return!1;try{return t.postMessage(g),!0}catch{return!1}},_=ke(e,"local");if(o!==void 0)_.confirm=(g)=>Promise.resolve().then(()=>o(g)).then((h)=>h==="unanswered"?h:h===!0),_.ownConfirm=!0;let A=ve({..._,server:{...e.server,icons:e.server.icons??be()},client:()=>({...a})}),D=Be(e.registry,_.tools,()=>A.toolsChanged()),C=Je({handler:A,send:b,maxChunk:()=>s,error:(g)=>e.error(g),timeoutMs:i}),O=(g,h)=>{let v={type:"error",code:"bad_message",message:g};if(F(h)&&h.length<=xt)v.id=h;b(v)},j=(g)=>{if(y)return;let h=g?.data;if(!ze(h)||!F(h.type)){O("not a message");return}let v=h.id;switch(h.type){case"http.request":{let{method:w,path:R,headers:S,body:E}=h;if(!F(v)||v===""||v.length>xt||!F(w)||!F(R)||!R.startsWith("/")||!ze(S)||!Object.values(S).every(F)||!F(E)){O("malformed http.request",v);return}C.request({type:"http.request",id:v,method:w,path:R,headers:S,body:E,grant:u});return}case"http.cancel":if(F(v))C.cancel(v);else O("malformed http.cancel");return;case"error":return;default:O(`unexpected ${h.type.slice(0,64)}`,v)}},U=t,f=()=>{if(y)return;if(n.signal?.removeEventListener("abort",f),U.removeEventListener?.("close",f),D(),C.close(),A.close(),He.delete(t))b({type:"bye",reason:"closed"});if(y=!0,t.onmessage===j)t.onmessage=null};if(n.signal?.aborted===!0)return f(),{close:f};return n.signal?.addEventListener("abort",f),U.addEventListener?.("close",f),He.add(t),t.onmessage=j,{close:f}}function qn(e){let t="",n=0,r=0;for(let s of e){n=n<<8|s,r+=8;while(r>=5)r-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>r&31];n&=(1<<r)-1}if(r>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-r&31];return t}async function Hn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return qn(new Uint8Array(n))}catch{return}}function wr(e,t,n,r,s){let i=ke(e,"webmcp");return s===void 0?qe(i,t,n,r,{kind:"webmcp"}):qe({...i,confirm:()=>Promise.resolve(!0)},t,n,r,{kind:"webmcp",via:"tab-mcp-extension",name:s.name,host:s.host})}var zn=15000,vt={1000:"closed",1001:"shutdown",1008:"policy",1009:"too_large",1011:"shutdown",1012:"shutdown",1013:"shutdown",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},Tt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var kt=512,Rt=6,It=64,Dn=kt+Rt*It;function Bn(e){let t=Math.floor((e-kt)/Rt);return t>=It?t:void 0}var Jn=1e4,Un=1000;function Vn(e,t){let n,r=!1,s=Number.NEGATIVE_INFINITY,i;try{if(e!==void 0&&typeof BroadcastChannel==="function")n=new BroadcastChannel(e),n.onmessage=(o)=>{let a=o.data;if(!r||a?.type!=="claimed"||a.address!==void 0&&a.address!==t)return;s=Date.now(),i?.()}}catch{n=void 0}return{claimed(){r=!0;try{n?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-s<=Jn)return Promise.resolve(!0);if(n===void 0)return Promise.resolve(!1);return new Promise((o)=>{let a=setTimeout(()=>o(!1),Un);i=()=>{clearTimeout(a),o(!0)}})},close(){n?.close()}}}function br(e,t,n,r,s){return new Promise((i,o)=>{let a=["grantschange","statechange","error"],u=(_)=>{clearTimeout(b);for(let A of a)e.removeEventListener(A,y);if(_)o(_);else i()},y=(_)=>{let A=_?.detail?.error;if(n())u();else if((A?.code==="store_unavailable"||A?.code==="unknown_id")&&(A.for===void 0||A.for===t.type&&A.grantId===t.grantId))u(A);else if(!r())u(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},b=setTimeout(()=>u(new DOMException("TabMcp: the relay did not answer","TimeoutError")),s);for(let _ of a)e.addEventListener(_,y);y()})}function $r(e){let t=globalThis,n=globalThis.document,r=()=>{if(n?.visibilityState!=="hidden")e()};return n?.addEventListener("visibilitychange",r),t.addEventListener?.("online",e),()=>{n?.removeEventListener("visibilitychange",r),t.removeEventListener?.("online",e)}}function xr(e,t,n,r={}){let s=r.revokeAll===!0,i=new WebSocket(t,Te),o="opening",a,u=65536,y,b,_=0,A=Vn(e.tabs,r.address),D,C,O=new Promise((d,M)=>{D=d,C=M});O.catch(()=>{});let j=setTimeout(()=>{w(de("The relay did not answer in time.","network"))},zn),U=ke(e,"relay"),f=ve({...U,server:{...e.server,icons:e.server.icons??be()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>y}),g=Be(e.registry,U.tools,()=>f.toolsChanged());function h(d){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(d)),!0}catch{return!1}}function v(){if(_<=0)return;clearTimeout(b),b=setTimeout(()=>{a??="heartbeat",R(4003);try{i.close()}catch{}},_*2.5)}function w(d){if(o!=="opening")return;R(0),C(d);try{i.close()}catch{}}function R(d){if(o==="closed")return;let M=o==="ready";if(o="closed",clearTimeout(j),clearTimeout(b),g(),S.close(),f.close(),M){let q=a??vt[d]??(d===1006?"network":"closed");if(e.closed(q,d),q==="replaced"){A.heard().then((H)=>{A.close(),e.replaced({sibling:H})});return}}A.close()}let S=Je({handler:f,send:h,maxChunk:()=>u,error:(d)=>e.error(d)});function E(d){if(o==="opening"){if(d.type==="session"){let M=Bn(d.limits.maxMessageBytes);if(M===void 0){w(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Dn}.`,"policy"));return}if(s&&d.grants.length>0){w(de("The relay did not revoke the address's grants (it needs tab-mcp 0.5 or later).","policy"));return}u=M,y=d.limits.maxBodyBytes,o="ready",clearTimeout(j),_=d.limits.heartbeatMs,v(),A.claimed(),D(e.sessionStarted(d))}else if(d.type==="error")w(de(`The relay refused the connection: ${d.message||d.code}`,d.code==="rate_limited"?"rate_limited":"policy"));else if(d.type==="bye")w(de(`The relay ended the connection: ${d.reason}`,Tt[d.reason]??"closed"));return}if(o!=="ready")return;switch(d.type){case"ping":v(),h({type:"pong",t:d.t});return;case"http.request":S.request(d);return;case"http.cancel":S.cancel(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"pairing.open":e.pairingOpen(d.expiresAt);return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":e.grantRemoved(d.grantId);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(a=Tt[d.reason]??"closed",a==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}if(d.code==="unknown_id"&&d.for==="grant.revoke"&&typeof d.grantId==="string")e.grantRemoved(d.grantId);e.error(Object.assign(Error(`Relay error ${d.code}: ${d.message}`),{code:d.code},typeof d.for==="string"?{for:d.for}:{},typeof d.grantId==="string"?{grantId:d.grantId}:{}));return;case"session":return}}return i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==Te){w(de(`The relay speaks ${i.protocol}, not ${Te}.`,"policy"));return}h({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...s?{revokeAll:!0}:{}})}),i.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let M=bt(d.data);if(M===void 0)return;if(o==="ready")v();E(M)}),i.addEventListener("close",(d)=>{if(o==="opening"){R(d.code);let M=d.code===1006||d.code===1002;C(de(M?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${d.code}${d.reason?`: ${d.reason}`:""}).`,vt[d.code]??(M?"network":"closed")));return}R(d.code)}),{ready:O,send:h,close(d){if(o==="closed")return;if(o==="opening"){w(new DOMException("The connection was cancelled","AbortError"));return}a=d,h({type:"bye",reason:"user"}),R(1000);try{i.close(1000,"bye")}catch{}}}}export{Dn as MIN_MESSAGE_BYTES,Un as SIBLING_GRACE_MS,Jn as SIBLING_WINDOW_MS,Hn as addressIdOf,br as answer,wr as callFromWebMcp,Bn as chunkSize,gn as compileRegistry,$r as onWake,xr as openConnection,De as pieces,jn as servePort};
14
+ `});n({type:"http.response.end",id:a.id})},r);try{let E=new Request(`https://tab.invalid${a.path}`,{method:a.method,headers:a.headers,signal:u.signal}),O=await t.handle(E,{grant:a.grant,body:a.body});if(!v()){await O.body?.cancel().catch(()=>{});return}let q={};for(let b of Cn){let h=O.headers.get(b);if(h!==null)q[b]=h}let U=(q["content-type"]??"").startsWith("text/event-stream"),f=e.maxChunk();if(!U||O.body===null){let b=await O.text();if(!v())return;if(b.length<=f){n({type:"http.response",id:a.id,status:O.status,headers:q,body:b});return}n({type:"http.response.start",id:a.id,status:O.status,headers:q});for(let h of De(b,f)){if(!v())break;n({type:"http.response.chunk",id:a.id,data:h})}if(v())n({type:"http.response.end",id:a.id});return}n({type:"http.response.start",id:a.id,status:O.status,headers:q}),k=!0;let y=O.body.getReader(),g=new TextDecoder;u.signal.addEventListener("abort",()=>{y.cancel().catch(()=>{})});for(;;){let{done:b,value:h}=await y.read();if(b||!v())break;let R=g.decode(h,{stream:!0});if(R!=="")M=(M+R).slice(-2);for(let A of De(R,f))n({type:"http.response.chunk",id:a.id,data:A})}if(v())n({type:"http.response.end",id:a.id})}catch(E){if(v())e.error(E instanceof Error?E:Error(String(E))),n({type:"http.response",id:a.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(clearTimeout(N),s.get(a.id)===u)s.delete(a.id)}}return{request(a){if(!i)o(a)},cancel(a){s.get(a)?.abort(),s.delete(a)},close(){if(i)return;i=!0;for(let a of s.values())a.abort();s.clear()}}}var On=65536,$t=64,Pn=300000,xt=128,He=new WeakSet,Nn=0,F=(e)=>typeof e==="string";function ze(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function jn(e,t,n){let r=n?.client;if(!ze(r)||!F(r.id)||r.id===""||r.name!==void 0&&!F(r.name))throw TypeError("serve: client needs an id (and may have a name)");let s=n.maxChunk??On;if(!Number.isInteger(s)||s<$t)throw TypeError(`serve: maxChunk must be a whole number of at least ${$t}`);let i=n.requestTimeoutMs??Pn;if(typeof i!=="number"||!(i>0)||i>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let o=n.onConfirm;if(o!==void 0&&typeof o!=="function")throw TypeError("serve: onConfirm must be a function");if(typeof t?.postMessage!=="function"||!("onmessage"in t))throw TypeError("serve: the port needs postMessage and onmessage");if(He.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let a={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")a.name=r.name;let u={grantId:`local:${++Nn}`,clientId:r.id,scopes:["tools"]},v=!1,k=(y)=>{if(v)return!1;try{return t.postMessage(y),!0}catch{return!1}},M=ke(e,"local");if(o!==void 0)M.confirm=(y)=>Promise.resolve().then(()=>o(y)).then((g)=>g==="unanswered"?g:g===!0),M.ownConfirm=!0;let _=ve({...M,server:{...e.server,icons:e.server.icons??be()},client:()=>({...a})}),N=Be(e.registry,M.tools,()=>_.toolsChanged()),E=Je({handler:_,send:k,maxChunk:()=>s,error:(y)=>e.error(y),timeoutMs:i}),O=(y,g)=>{let b={type:"error",code:"bad_message",message:y};if(F(g)&&g.length<=xt)b.id=g;k(b)},q=(y)=>{if(v)return;let g=y?.data;if(!ze(g)||!F(g.type)){O("not a message");return}let b=g.id;switch(g.type){case"http.request":{let{method:h,path:R,headers:A,body:S}=g;if(!F(b)||b===""||b.length>xt||!F(h)||!F(R)||!R.startsWith("/")||!ze(A)||!Object.values(A).every(F)||!F(S)){O("malformed http.request",b);return}E.request({type:"http.request",id:b,method:h,path:R,headers:A,body:S,grant:u});return}case"http.cancel":if(F(b))E.cancel(b);else O("malformed http.cancel");return;case"error":return;default:O(`unexpected ${g.type.slice(0,64)}`,b)}},U=t,f=()=>{if(v)return;if(n.signal?.removeEventListener("abort",f),U.removeEventListener?.("close",f),N(),E.close(),_.close(),He.delete(t))k({type:"bye",reason:"closed"});if(v=!0,t.onmessage===q)t.onmessage=null};if(n.signal?.aborted===!0)return f(),{close:f};return n.signal?.addEventListener("abort",f),U.addEventListener?.("close",f),He.add(t),t.onmessage=q,{close:f}}function qn(e){let t="",n=0,r=0;for(let s of e){n=n<<8|s,r+=8;while(r>=5)r-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>r&31];n&=(1<<r)-1}if(r>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-r&31];return t}async function Hn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return qn(new Uint8Array(n))}catch{return}}function wr(e,t,n,r,s){let i=ke(e,"webmcp");return s===void 0?qe(i,t,n,r,{kind:"webmcp"}):qe({...i,confirm:()=>Promise.resolve(!0)},t,n,r,{kind:"webmcp",via:"tab-mcp-extension",name:s.name,host:s.host})}var zn=15000,vt={1000:"closed",1001:"shutdown",1008:"policy",1009:"too_large",1011:"shutdown",1012:"shutdown",1013:"shutdown",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},Tt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var kt=512,Rt=6,It=64,Dn=kt+Rt*It;function Bn(e){let t=Math.floor((e-kt)/Rt);return t>=It?t:void 0}var Jn=1e4,Un=1000;function Vn(e,t){let n,r=!1,s=Number.NEGATIVE_INFINITY,i;try{if(e!==void 0&&typeof BroadcastChannel==="function")n=new BroadcastChannel(e),n.onmessage=(o)=>{let a=o.data;if(!r||a?.type!=="claimed"||a.address!==void 0&&a.address!==t)return;s=Date.now(),i?.()}}catch{n=void 0}return{claimed(){r=!0;try{n?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-s<=Jn)return Promise.resolve(!0);if(n===void 0)return Promise.resolve(!1);return new Promise((o)=>{let a=setTimeout(()=>o(!1),Un);i=()=>{clearTimeout(a),o(!0)}})},close(){n?.close()}}}function br(e,t,n,r,s){return new Promise((i,o)=>{let a=["grantschange","statechange","error"],u=(M)=>{clearTimeout(k);for(let _ of a)e.removeEventListener(_,v);if(M)o(M);else i()},v=(M)=>{let _=M?.detail?.error;if(n())u();else if((_?.code==="store_unavailable"||_?.code==="unknown_id")&&(_.for===void 0||_.for===t.type&&_.grantId===t.grantId))u(_);else if(!r())u(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},k=setTimeout(()=>u(new DOMException("TabMcp: the relay did not answer","TimeoutError")),s);for(let M of a)e.addEventListener(M,v);v()})}function $r(e){let t=globalThis,n=globalThis.document,r=()=>{if(n?.visibilityState!=="hidden")e()};return n?.addEventListener("visibilitychange",r),t.addEventListener?.("online",e),()=>{n?.removeEventListener("visibilitychange",r),t.removeEventListener?.("online",e)}}function xr(e,t,n,r={}){let s=r.revokeAll===!0,i=new WebSocket(t,Te),o="opening",a,u=65536,v,k,M=0,_=Vn(e.tabs,r.address),N,E,O=new Promise((d,C)=>{N=d,E=C});O.catch(()=>{});let q=setTimeout(()=>{h(de("The relay did not answer in time.","network"))},zn),U=ke(e,"relay"),f=ve({...U,server:{...e.server,icons:e.server.icons??be()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>v}),y=Be(e.registry,U.tools,()=>f.toolsChanged());function g(d){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(d)),!0}catch{return!1}}function b(){if(M<=0)return;clearTimeout(k),k=setTimeout(()=>{a??="heartbeat",R(4003);try{i.close()}catch{}},M*2.5)}function h(d){if(o!=="opening")return;R(0),E(d);try{i.close()}catch{}}function R(d){if(o==="closed")return;let C=o==="ready";if(o="closed",clearTimeout(q),clearTimeout(k),y(),A.close(),f.close(),C){let H=a??vt[d]??(d===1006?"network":"closed");if(e.closed(H,d),H==="replaced"){_.heard().then((z)=>{_.close(),e.replaced({sibling:z})});return}}_.close()}let A=Je({handler:f,send:g,maxChunk:()=>u,error:(d)=>e.error(d)});function S(d){if(o==="opening"){if(d.type==="session"){let C=Bn(d.limits.maxMessageBytes);if(C===void 0){h(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Dn}.`,"policy"));return}if(s&&d.grants.length>0){h(de("The relay did not revoke the address's grants (it needs tab-mcp 0.5 or later).","policy"));return}u=C,v=d.limits.maxBodyBytes,o="ready",clearTimeout(q),M=d.limits.heartbeatMs,b(),_.claimed(),N(e.sessionStarted(d))}else if(d.type==="error")h(de(`The relay refused the connection: ${d.message||d.code}`,d.code==="rate_limited"?"rate_limited":"policy"));else if(d.type==="bye")h(de(`The relay ended the connection: ${d.reason}`,Tt[d.reason]??"closed"));return}if(o!=="ready")return;switch(d.type){case"ping":b(),g({type:"pong",t:d.t});return;case"http.request":A.request(d);return;case"http.cancel":A.cancel(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"pairing.open":e.pairingOpen(d.expiresAt);return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":e.grantRemoved(d.grantId);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(a=Tt[d.reason]??"closed",a==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}if(d.code==="unknown_id"&&d.for==="grant.revoke"&&typeof d.grantId==="string")e.grantRemoved(d.grantId);e.error(Object.assign(Error(`Relay error ${d.code}: ${d.message}`),{code:d.code},typeof d.for==="string"?{for:d.for}:{},typeof d.grantId==="string"?{grantId:d.grantId}:{}));return;case"session":return}}return i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==Te){h(de(`The relay speaks ${i.protocol}, not ${Te}.`,"policy"));return}g({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...s?{revokeAll:!0}:{}})}),i.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let C=bt(d.data);if(C===void 0)return;if(o==="ready")b();S(C)}),i.addEventListener("close",(d)=>{if(o==="opening"){R(d.code);let C=d.code===1006||d.code===1002;E(de(C?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${d.code}${d.reason?`: ${d.reason}`:""}).`,vt[d.code]??(C?"network":"closed")));return}R(d.code)}),{ready:O,send:g,close(d){if(o==="closed")return;if(o==="opening"){h(new DOMException("The connection was cancelled","AbortError"));return}a=d,g({type:"bye",reason:"user"}),R(1000);try{i.close(1000,"bye")}catch{}}}}export{Dn as MIN_MESSAGE_BYTES,Un as SIBLING_GRACE_MS,Jn as SIBLING_WINDOW_MS,Hn as addressIdOf,br as answer,wr as callFromWebMcp,Bn as chunkSize,gn as compileRegistry,$r as onWake,xr as openConnection,De as pieces,jn as servePort};
15
15
 
16
- //# debugId=3578394AFE2A6D2164756E2164756E21
17
- //# sourceMappingURL=connection-yf2x9zz2.min.js.map
16
+ //# debugId=225D663AD0F9EB7764756E2164756E21
17
+ //# sourceMappingURL=connection-5x2krvfs.min.js.map