@mcp-b/webmcp-polyfill 2.3.2 → 3.0.0-beta.20260702171253

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,21 +1,39 @@
1
1
  # @mcp-b/webmcp-polyfill
2
2
 
3
- Strict WebMCP core runtime polyfill for `navigator.modelContext`.
3
+ Strict WebMCP core runtime polyfill for `document.modelContext` (with a
4
+ backward-compatible `navigator.modelContext` alias).
5
+
6
+ > **Heads up — WebMCP spec migration.** The `modelContext` getter moved from
7
+ > `Navigator` to `Document` in
8
+ > [webmachinelearning/webmcp#184](https://github.com/webmachinelearning/webmcp/pull/184)
9
+ > and Chrome 150 deprecates `navigator.modelContext`. The polyfill installs on
10
+ > both surfaces today: `document.modelContext` is the canonical install
11
+ > location, and `navigator.modelContext` remains as a deprecated alias that
12
+ > resolves to the same instance and logs a one-time console warning on first
13
+ > access. Prefer `document.modelContext` for new code.
14
+
15
+ ```js
16
+ const modelContext = document.modelContext || navigator.modelContext;
17
+ if (modelContext) {
18
+ // Register tools…
19
+ }
20
+ ```
4
21
 
5
22
  `@mcp-b/webmcp-polyfill` installs only the strict core API:
6
23
 
7
24
  - `registerTool(tool, options?)` — pass `options.signal` (`AbortSignal`) to unregister when aborted
25
+ - `getTools()` — async Chromium producer-preview discovery API
26
+ - `executeTool(toolFromGetTools, inputArgsJson, options?)` — Chromium producer-preview execution API
8
27
  - `unregisterTool(nameOrTool)` (deprecated compatibility API)
9
- - `provideContext(options?)` (deprecated compatibility API)
10
- - `clearContext()` (deprecated compatibility API)
11
28
 
12
29
  It does not install MCP bridge extensions like `callTool`, resources, or prompts.
13
30
 
14
31
  Important:
15
32
 
16
- - `navigator.modelContext` in this package does not provide `listTools()` or `callTool(...)`.
33
+ - `document.modelContext` is the canonical install location. `navigator.modelContext` is kept as a backward-compatible alias that returns the same instance and logs a one-time deprecation warning on first access. The upstream WebMCP draft moved the getter from Navigator to Document on May 27, 2026 ([webmachinelearning/webmcp#184](https://github.com/webmachinelearning/webmcp/pull/184)) and Chrome 150 deprecates `navigator.modelContext`. The polyfill will remove the Navigator alias in the next major version.
34
+ - `document.modelContext` in this package does not provide `listTools()` or `callTool(...)`; producer discovery/execution uses `getTools()` and `executeTool(...)`.
17
35
  - For list/execute test flows, use `navigator.modelContextTesting` (when `installTestingShim` is enabled).
18
- - `provideContext()` and `clearContext()` still work for now, but the upstream WebMCP spec removed them on March 5, 2026. The polyfill logs a deprecation warning and will remove them in the next major version.
36
+ - `provideContext()` and `clearContext()` were removed from the upstream WebMCP spec on March 5, 2026 and are not exposed by this polyfill.
19
37
  - `unregisterTool(name)` was removed from the WebMCP draft on April 23, 2026 in favor of `AbortSignal`-driven unregistration. The polyfill keeps it functional with a one-time deprecation warning; it will be removed in the next major version.
20
38
 
21
39
  ## Type Safety First
@@ -30,11 +48,11 @@ Recommended setup:
30
48
 
31
49
  ## Package Selection
32
50
 
33
- | Package | Use When |
34
- | ------------------------ | ---------------------------------------------------------- |
35
- | `@mcp-b/webmcp-types` | You only need compile-time types (no runtime) |
36
- | `@mcp-b/webmcp-polyfill` | You need strict `navigator.modelContext` core runtime only |
37
- | `@mcp-b/global` | You want full MCPB runtime (core + bridge extensions) |
51
+ | Package | Use When |
52
+ | ------------------------ | --------------------------------------------------------- |
53
+ | `@mcp-b/webmcp-types` | You only need compile-time types (no runtime) |
54
+ | `@mcp-b/webmcp-polyfill` | You need strict `document.modelContext` core runtime only |
55
+ | `@mcp-b/global` | You want full MCPB runtime (core + bridge extensions) |
38
56
 
39
57
  ## Install
40
58
 
@@ -51,7 +69,7 @@ import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
51
69
 
52
70
  initializeWebMCPPolyfill();
53
71
 
54
- navigator.modelContext.registerTool({
72
+ document.modelContext.registerTool({
55
73
  name: 'get-page-title',
56
74
  description: 'Get the current page title',
57
75
  inputSchema: { type: 'object', properties: {} },
@@ -96,7 +114,7 @@ const inputSchema = {
96
114
  additionalProperties: false,
97
115
  } as const satisfies JsonSchemaForInference;
98
116
 
99
- navigator.modelContext.registerTool({
117
+ document.modelContext.registerTool({
100
118
  name: 'search',
101
119
  description: 'Search indexed docs',
102
120
  inputSchema,
@@ -119,7 +137,7 @@ Inference notes:
119
137
 
120
138
  ### `initializeWebMCPPolyfill(options?)`
121
139
 
122
- Installs the strict core polyfill on `navigator.modelContext`.
140
+ Installs the strict core polyfill on `document.modelContext` (canonical) and `navigator.modelContext` (deprecated alias to the same instance).
123
141
 
124
142
  | Option | Type | Default | Notes |
125
143
  | --------------------------------- | ------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------ |
@@ -130,7 +148,7 @@ Installs the strict core polyfill on `navigator.modelContext`.
130
148
  Behavior:
131
149
 
132
150
  - No-op in non-browser environments.
133
- - Non-destructive by default: if `navigator.modelContext` already exists, initialization is skipped.
151
+ - Non-destructive by default: if either `document.modelContext` or `navigator.modelContext` already exists (e.g. native Chromium support), initialization is skipped.
134
152
  - Safe to call repeatedly.
135
153
 
136
154
  ### `initializeWebModelContextPolyfill(options?)`
@@ -139,16 +157,10 @@ Alias of `initializeWebMCPPolyfill`.
139
157
 
140
158
  ### `cleanupWebMCPPolyfill()`
141
159
 
142
- Restores previous `navigator.modelContext` and `navigator.modelContextTesting` descriptors and resets polyfill install state.
160
+ Restores previous `document.modelContext`, `navigator.modelContext`, and `navigator.modelContextTesting` descriptors and resets polyfill install state.
143
161
 
144
162
  ## Strict Core Behavior
145
163
 
146
- ### `provideContext(options?)`
147
-
148
- - Deprecated compatibility API.
149
- - Replaces the active tool registry with `options.tools`.
150
- - Clears previously registered tools before applying new tools.
151
-
152
164
  ### `registerTool(tool, options?)`
153
165
 
154
166
  - Requires a non-empty `name`, non-empty `description`, and `execute` function.
@@ -158,7 +170,7 @@ Restores previous `navigator.modelContext` and `navigator.modelContextTesting` d
158
170
 
159
171
  ```ts
160
172
  const ac = new AbortController();
161
- navigator.modelContext.registerTool(
173
+ document.modelContext.registerTool(
162
174
  {
163
175
  name: 'search',
164
176
  description: 'Search docs',
@@ -180,15 +192,10 @@ ac.abort();
180
192
  - Unknown names are a no-op.
181
193
  - Logs a one-time deprecation warning. Prefer the `AbortSignal` form on `registerTool(tool, options)`.
182
194
 
183
- ### `clearContext()`
184
-
185
- - Deprecated compatibility API.
186
- - Removes all registered tools.
187
-
188
195
  ## Listing and Executing Tools
189
196
 
190
197
  In `@mcp-b/webmcp-polyfill`, listing and execution helpers are exposed on
191
- `navigator.modelContextTesting` (not `navigator.modelContext`) when the testing shim is enabled.
198
+ `navigator.modelContextTesting` (not `document.modelContext`) when the testing shim is enabled.
192
199
 
193
200
  ```ts
194
201
  import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
@@ -205,7 +212,7 @@ void tools;
205
212
  void result;
206
213
  ```
207
214
 
208
- If you want `callTool(...)` / extension-style runtime methods on `navigator.modelContext`, use
215
+ If you want `callTool(...)` / extension-style runtime methods on `document.modelContext`, use
209
216
  `@mcp-b/global`.
210
217
 
211
218
  ## Input Schema Support
package/dist/index.d.ts CHANGED
@@ -1,33 +1,6 @@
1
- import { InputSchema } from "@mcp-b/webmcp-types";
2
- import { StandardSchemaV1 } from "@standard-schema/spec";
1
+ import { StandardInputJsonSchema, StandardInputValidatorSchema, StandardJSONSchemaV1, ToolInputSchema, ToolOutputSchema, isPlainObject, normalizeInputSchema, toJsonValue, validateValueWithSchema } from "./schema.js";
3
2
 
4
3
  //#region src/index.d.ts
5
- type StandardInputValidatorSchema = StandardSchemaV1<Record<string, unknown>, Record<string, unknown>>;
6
- interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
7
- readonly '~standard': {
8
- readonly version: 1;
9
- readonly vendor: string;
10
- readonly types?: {
11
- readonly input: Input;
12
- readonly output: Output;
13
- } | undefined;
14
- readonly jsonSchema: {
15
- readonly input: (options: {
16
- readonly target: 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | ({} & string);
17
- readonly libraryOptions?: Record<string, unknown> | undefined;
18
- }) => Record<string, unknown>;
19
- readonly output: (options: {
20
- readonly target: 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | ({} & string);
21
- readonly libraryOptions?: Record<string, unknown> | undefined;
22
- }) => Record<string, unknown>;
23
- };
24
- };
25
- }
26
- type StandardInputJsonSchema = StandardJSONSchemaV1<Record<string, unknown>, Record<string, unknown>>;
27
- type ToolInputSchema = InputSchema | StandardInputValidatorSchema | StandardInputJsonSchema;
28
- type ToolOutputSchema = InputSchema | StandardInputJsonSchema;
29
- type StandardValidationResult = Awaited<ReturnType<StandardInputValidatorSchema['~standard']['validate']>>;
30
- type StandardValidationIssue = NonNullable<StandardValidationResult['issues']>[number];
31
4
  interface WebMCPPolyfillInitOptions {
32
5
  /**
33
6
  * Controls whether the polyfill auto-initializes when loaded.
@@ -48,8 +21,6 @@ interface WebMCPPolyfillInitOptions {
48
21
  */
49
22
  disableIframeTransportByDefault?: boolean;
50
23
  }
51
- declare function isPlainObject(value: unknown): value is Record<string, unknown>;
52
- declare function validateArgsWithSchema(args: Record<string, unknown>, schema: InputSchema): StandardValidationIssue | null;
53
24
  declare function initializeWebMCPPolyfill(options?: WebMCPPolyfillInitOptions): void;
54
25
  declare function cleanupWebMCPPolyfill(): void;
55
26
  declare global {
@@ -58,5 +29,5 @@ declare global {
58
29
  }
59
30
  } //# sourceMappingURL=index.d.ts.map
60
31
  //#endregion
61
- export { StandardInputJsonSchema, StandardInputValidatorSchema, StandardJSONSchemaV1, ToolInputSchema, ToolOutputSchema, WebMCPPolyfillInitOptions, cleanupWebMCPPolyfill, initializeWebMCPPolyfill, initializeWebMCPPolyfill as initializeWebModelContextPolyfill, isPlainObject, validateArgsWithSchema };
32
+ export { type StandardInputJsonSchema, type StandardInputValidatorSchema, type StandardJSONSchemaV1, type ToolInputSchema, type ToolOutputSchema, WebMCPPolyfillInitOptions, cleanupWebMCPPolyfill, initializeWebMCPPolyfill, initializeWebMCPPolyfill as initializeWebModelContextPolyfill, isPlainObject, normalizeInputSchema, toJsonValue, validateValueWithSchema };
62
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;KA2BY,4BAAA,GAA+B,gBAAA,CACzC,MAAA,mBACA,MAAA;AAAA,UAEe,oBAAA,2BAA+C,KAAA;EAAA,SACrD,WAAA;IAAA,SACE,OAAA;IAAA,SACA,MAAA;IAAA,SACA,KAAA;MAAA,SAAmB,KAAA,EAAO,KAAA;MAAA,SAAgB,MAAA,EAAQ,MAAA;IAAA;IAAA,SAClD,UAAA;MAAA,SACE,KAAA,GAAQ,OAAA;QAAA,SACN,MAAA;QAAA,SACA,cAAA,GAAiB,MAAA;MAAA,MACtB,MAAA;MAAA,SACG,MAAA,GAAS,OAAA;QAAA,SACP,MAAA;QAAA,SACA,cAAA,GAAiB,MAAA;MAAA,MACtB,MAAA;IAAA;EAAA;AAAA;AAAA,KAIA,uBAAA,GAA0B,oBAAA,CACpC,MAAA,mBACA,MAAA;AAAA,KAEU,eAAA,GAAkB,WAAA,GAAc,4BAAA,GAA+B,uBAAA;AAAA,KAC/D,gBAAA,GAAmB,WAAA,GAAc,uBAAA;AAAA,KAExC,wBAAA,GAA2B,OAAA,CAC9B,UAAA,CAAW,4BAAA;AAAA,KAER,uBAAA,GAA0B,WAAA,CAAY,wBAAA;AAAA,UA4B1B,yBAAA;EAvDqB;;;;;EA6DpC,cAAA;EAzDW;;;;;;;EAkEX,kBAAA;EA9De;;;EAmEf,+BAAA;AAAA;AAAA,iBAsTc,aAAA,CAAc,KAAA,YAAiB,KAAA,IAAS,MAAA;AAAA,iBAmRxC,sBAAA,CACd,IAAA,EAAM,MAAA,mBACN,MAAA,EAAQ,WAAA,GACP,uBAAA;AAAA,iBAsOa,wBAAA,CAAyB,OAAA,GAAU,yBAAA;AAAA,iBAiDnC,qBAAA,CAAA;AAAA,QA4BR,MAAA;EAAA,UACI,MAAA;IACR,uBAAA,GAA0B,yBAAA;EAAA;AAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAkFiB,yBAAA;EAAA;;;;;EAMf,cAAA;EAcA;;;AA0mBF;;;;EA/mBE,kBAAA;EAmsBc;;;EA9rBd,+BAAA;AAAA;AAAA,iBA0mBc,wBAAA,CAAyB,OAAA,GAAU,yBAAA;AAAA,iBAoFnC,qBAAA,CAAA;AAAA,QA+CR,MAAA;EAAA,UACI,MAAA;IACR,uBAAA,GAA0B,yBAAA;EAAA;AAAA"}
@@ -1,2 +1,2 @@
1
- var WebMCPPolyfill=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,n){let r=typeof e;if(r!==typeof n)return!1;if(Array.isArray(e)){if(!Array.isArray(n))return!1;let r=e.length;if(r!==n.length)return!1;for(let i=0;i<r;i++)if(!t(e[i],n[i]))return!1;return!0}if(r===`object`){if(!e||!n)return e===n;let r=Object.keys(e),i=Object.keys(n);if(r.length!==i.length)return!1;for(let i of r)if(!t(e[i],n[i]))return!1;return!0}return e===n}function n(e){return encodeURI(r(e))}function r(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}let i={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},a={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},o={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!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},s=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 c(e,t=Object.create(null),r=s,l=``){if(e&&typeof e==`object`&&!Array.isArray(e)){let n=e.$id||e.id;if(n){let i=new URL(n,r.href);i.hash.length>1?t[i.href]=e:(i.hash=``,l===``?r=i:c(e,t,r))}}else if(e!==!0&&e!==!1)return t;let u=r.href+(l?`#`+l:``);if(t[u]!==void 0)throw Error(`Duplicate schema URI "${u}".`);if(t[u]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0&&Object.defineProperty(e,`__absolute_uri__`,{enumerable:!1,value:u}),e.$ref&&e.__absolute_ref__===void 0){let t=new URL(e.$ref,r.href);t.hash=t.hash,Object.defineProperty(e,`__absolute_ref__`,{enumerable:!1,value:t.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let t=new URL(e.$recursiveRef,r.href);t.hash=t.hash,Object.defineProperty(e,`__absolute_recursive_ref__`,{enumerable:!1,value:t.href})}if(e.$anchor){let n=new URL(`#`+e.$anchor,r.href);t[n.href]=e}for(let s in e){if(o[s])continue;let u=`${l}/${n(s)}`,d=e[s];if(Array.isArray(d)){if(i[s]){let e=d.length;for(let n=0;n<e;n++)c(d[n],t,r,`${u}/${n}`)}}else if(a[s])for(let e in d)c(d[e],t,r,`${u}/${n(e)}`);else c(d,t,r,u)}return t}let l=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,u=[0,31,28,31,30,31,30,31,31,30,31,30,31],d=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,f=/^(?=.{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,p=/^(?:[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,m=/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,ee=/^(?:(?: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,h=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,g=/^(?:\/(?:[^~/]|~0|~1)*)*$/,_=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,v=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,te=e=>{if(e[0]===`"`)return!1;let[t,n,...r]=e.split(`@`);return!t||!n||r.length!==0||t.length>64||n.length>253||t[0]===`.`||t.endsWith(`.`)||t.includes(`..`)||!/^[a-z0-9.-]+$/i.test(n)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t)?!1:n.split(`.`).every(e=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(e))},ne=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,y=/^((([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,b=e=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function x(e){return e.test.bind(e)}let re={date:S,time:C.bind(void 0,!1),"date-time":T,duration:b,uri:oe,"uri-reference":x(p),"uri-template":x(m),url:x(ee),email:te,hostname:x(f),ipv4:x(ne),ipv6:x(y),regex:O,uuid:x(h),"json-pointer":x(g),"json-pointer-uri-fragment":x(_),"relative-json-pointer":x(v)};function ie(e){return e%4==0&&(e%100!=0||e%400==0)}function S(e){let t=e.match(l);if(!t)return!1;let n=+t[1],r=+t[2],i=+t[3];return r>=1&&r<=12&&i>=1&&i<=(r==2&&ie(n)?29:u[r])}function C(e,t){let n=t.match(d);if(!n)return!1;let r=+n[1],i=+n[2],a=+n[3],o=!!n[5];return(r<=23&&i<=59&&a<=59||r==23&&i==59&&a==60)&&(!e||o)}let w=/t|\s/i;function T(e){let t=e.split(w);return t.length==2&&S(t[0])&&C(!0,t[1])}let E=/\/|:/,ae=/^(?:[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 oe(e){return E.test(e)&&ae.test(e)}let D=/[^\\]\\Z/;function O(e){if(D.test(e))return!1;try{return new RegExp(e,`u`),!0}catch{return!1}}function se(e){let t=0,n=e.length,r=0,i;for(;r<n;)t++,i=e.charCodeAt(r++),i>=55296&&i<=56319&&r<n&&(i=e.charCodeAt(r),(i&64512)==56320&&r++);return t}function k(e,r,i=`2019-09`,a=c(r),o=!0,s=null,l=`#`,u=`#`,d=Object.create(null)){if(r===!0)return{valid:!0,errors:[]};if(r===!1)return{valid:!1,errors:[{instanceLocation:l,keyword:`false`,keywordLocation:l,error:`False boolean schema.`}]};let f=typeof e,p;switch(f){case`boolean`:case`number`:case`string`:p=f;break;case`object`:p=e===null?`null`:Array.isArray(e)?`array`:`object`;break;default:throw Error(`Instances of "${f}" type are not supported.`)}let{$ref:m,$recursiveRef:ee,$recursiveAnchor:h,type:g,const:_,enum:v,required:te,not:ne,anyOf:y,allOf:b,oneOf:x,if:ie,then:S,else:C,format:w,properties:T,patternProperties:E,additionalProperties:ae,unevaluatedProperties:oe,minProperties:D,maxProperties:O,propertyNames:ce,dependentRequired:A,dependentSchemas:j,dependencies:M,prefixItems:N,items:P,additionalItems:F,unevaluatedItems:I,contains:le,minContains:L,maxContains:R,minItems:z,maxItems:B,uniqueItems:V,minimum:H,maximum:U,exclusiveMinimum:W,exclusiveMaximum:G,multipleOf:K,minLength:q,maxLength:J,pattern:Y,__absolute_ref__:X,__absolute_recursive_ref__:Z}=r,Q=[];if(h===!0&&s===null&&(s=r),ee===`#`){let t=s===null?a[Z]:s,n=`${u}/$recursiveRef`,c=k(e,s===null?r:s,i,a,o,t,l,n,d);c.valid||Q.push({instanceLocation:l,keyword:`$recursiveRef`,keywordLocation:n,error:`A subschema had errors.`},...c.errors)}if(m!==void 0){let t=a[X||m];if(t===void 0){let e=`Unresolved $ref "${m}".`;throw X&&X!==m&&(e+=` Absolute URI "${X}".`),e+=`\nKnown schemas:\n- ${Object.keys(a).join(`
2
- - `)}`,Error(e)}let n=`${u}/$ref`,r=k(e,t,i,a,o,s,l,n,d);if(r.valid||Q.push({instanceLocation:l,keyword:`$ref`,keywordLocation:n,error:`A subschema had errors.`},...r.errors),i===`4`||i===`7`)return{valid:Q.length===0,errors:Q}}if(Array.isArray(g)){let t=g.length,n=!1;for(let r=0;r<t;r++)if(p===g[r]||g[r]===`integer`&&p===`number`&&e%1==0&&e===e){n=!0;break}n||Q.push({instanceLocation:l,keyword:`type`,keywordLocation:`${u}/type`,error:`Instance type "${p}" is invalid. Expected "${g.join(`", "`)}".`})}else g===`integer`?(p!==`number`||e%1||e!==e)&&Q.push({instanceLocation:l,keyword:`type`,keywordLocation:`${u}/type`,error:`Instance type "${p}" is invalid. Expected "${g}".`}):g!==void 0&&p!==g&&Q.push({instanceLocation:l,keyword:`type`,keywordLocation:`${u}/type`,error:`Instance type "${p}" is invalid. Expected "${g}".`});if(_!==void 0&&(p===`object`||p===`array`?t(e,_)||Q.push({instanceLocation:l,keyword:`const`,keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(_)}.`}):e!==_&&Q.push({instanceLocation:l,keyword:`const`,keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(_)}.`})),v!==void 0&&(p===`object`||p===`array`?v.some(n=>t(e,n))||Q.push({instanceLocation:l,keyword:`enum`,keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`}):v.some(t=>e===t)||Q.push({instanceLocation:l,keyword:`enum`,keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`})),ne!==void 0){let t=`${u}/not`;k(e,ne,i,a,o,s,l,t).valid&&Q.push({instanceLocation:l,keyword:`not`,keywordLocation:t,error:`Instance matched "not" schema.`})}let $=[];if(y!==void 0){let t=`${u}/anyOf`,n=Q.length,r=!1;for(let n=0;n<y.length;n++){let c=y[n],u=Object.create(d),f=k(e,c,i,a,o,h===!0?s:null,l,`${t}/${n}`,u);Q.push(...f.errors),r||=f.valid,f.valid&&$.push(u)}r?Q.length=n:Q.splice(n,0,{instanceLocation:l,keyword:`anyOf`,keywordLocation:t,error:`Instance does not match any subschemas.`})}if(b!==void 0){let t=`${u}/allOf`,n=Q.length,r=!0;for(let n=0;n<b.length;n++){let c=b[n],u=Object.create(d),f=k(e,c,i,a,o,h===!0?s:null,l,`${t}/${n}`,u);Q.push(...f.errors),r&&=f.valid,f.valid&&$.push(u)}r?Q.length=n:Q.splice(n,0,{instanceLocation:l,keyword:`allOf`,keywordLocation:t,error:`Instance does not match every subschema.`})}if(x!==void 0){let t=`${u}/oneOf`,n=Q.length,r=x.filter((n,r)=>{let c=Object.create(d),u=k(e,n,i,a,o,h===!0?s:null,l,`${t}/${r}`,c);return Q.push(...u.errors),u.valid&&$.push(c),u.valid}).length;r===1?Q.length=n:Q.splice(n,0,{instanceLocation:l,keyword:`oneOf`,keywordLocation:t,error:`Instance does not match exactly one subschema (${r} matches).`})}if((p===`object`||p===`array`)&&Object.assign(d,...$),ie!==void 0){let t=`${u}/if`;if(k(e,ie,i,a,o,s,l,t,d).valid){if(S!==void 0){let n=k(e,S,i,a,o,s,l,`${u}/then`,d);n.valid||Q.push({instanceLocation:l,keyword:`if`,keywordLocation:t,error:`Instance does not match "then" schema.`},...n.errors)}}else if(C!==void 0){let n=k(e,C,i,a,o,s,l,`${u}/else`,d);n.valid||Q.push({instanceLocation:l,keyword:`if`,keywordLocation:t,error:`Instance does not match "else" schema.`},...n.errors)}}if(p===`object`){if(te!==void 0)for(let t of te)t in e||Q.push({instanceLocation:l,keyword:`required`,keywordLocation:`${u}/required`,error:`Instance does not have required property "${t}".`});let t=Object.keys(e);if(D!==void 0&&t.length<D&&Q.push({instanceLocation:l,keyword:`minProperties`,keywordLocation:`${u}/minProperties`,error:`Instance does not have at least ${D} properties.`}),O!==void 0&&t.length>O&&Q.push({instanceLocation:l,keyword:`maxProperties`,keywordLocation:`${u}/maxProperties`,error:`Instance does not have at least ${O} properties.`}),ce!==void 0){let t=`${u}/propertyNames`;for(let r in e){let e=`${l}/${n(r)}`,c=k(r,ce,i,a,o,s,e,t);c.valid||Q.push({instanceLocation:l,keyword:`propertyNames`,keywordLocation:t,error:`Property name "${r}" does not match schema.`},...c.errors)}}if(A!==void 0){let t=`${u}/dependantRequired`;for(let n in A)if(n in e){let r=A[n];for(let i of r)i in e||Q.push({instanceLocation:l,keyword:`dependentRequired`,keywordLocation:t,error:`Instance has "${n}" but does not have "${i}".`})}}if(j!==void 0)for(let t in j){let r=`${u}/dependentSchemas`;if(t in e){let c=k(e,j[t],i,a,o,s,l,`${r}/${n(t)}`,d);c.valid||Q.push({instanceLocation:l,keyword:`dependentSchemas`,keywordLocation:r,error:`Instance has "${t}" but does not match dependant schema.`},...c.errors)}}if(M!==void 0){let t=`${u}/dependencies`;for(let r in M)if(r in e){let c=M[r];if(Array.isArray(c))for(let n of c)n in e||Q.push({instanceLocation:l,keyword:`dependencies`,keywordLocation:t,error:`Instance has "${r}" but does not have "${n}".`});else{let u=k(e,c,i,a,o,s,l,`${t}/${n(r)}`);u.valid||Q.push({instanceLocation:l,keyword:`dependencies`,keywordLocation:t,error:`Instance has "${r}" but does not match dependant schema.`},...u.errors)}}}let r=Object.create(null),c=!1;if(T!==void 0){let t=`${u}/properties`;for(let u in T){if(!(u in e))continue;let f=`${l}/${n(u)}`,p=k(e[u],T[u],i,a,o,s,f,`${t}/${n(u)}`);if(p.valid)d[u]=r[u]=!0;else if(c=o,Q.push({instanceLocation:l,keyword:`properties`,keywordLocation:t,error:`Property "${u}" does not match schema.`},...p.errors),c)break}}if(!c&&E!==void 0){let t=`${u}/patternProperties`;for(let u in E){let f=new RegExp(u,`u`),p=E[u];for(let m in e){if(!f.test(m))continue;let ee=`${l}/${n(m)}`,h=k(e[m],p,i,a,o,s,ee,`${t}/${n(u)}`);h.valid?d[m]=r[m]=!0:(c=o,Q.push({instanceLocation:l,keyword:`patternProperties`,keywordLocation:t,error:`Property "${m}" matches pattern "${u}" but does not match associated schema.`},...h.errors))}}}if(!c&&ae!==void 0){let t=`${u}/additionalProperties`;for(let u in e){if(r[u])continue;let f=`${l}/${n(u)}`,p=k(e[u],ae,i,a,o,s,f,t);p.valid?d[u]=!0:(c=o,Q.push({instanceLocation:l,keyword:`additionalProperties`,keywordLocation:t,error:`Property "${u}" does not match additional properties schema.`},...p.errors))}}else if(!c&&oe!==void 0){let t=`${u}/unevaluatedProperties`;for(let r in e)if(!d[r]){let c=`${l}/${n(r)}`,u=k(e[r],oe,i,a,o,s,c,t);u.valid?d[r]=!0:Q.push({instanceLocation:l,keyword:`unevaluatedProperties`,keywordLocation:t,error:`Property "${r}" does not match unevaluated properties schema.`},...u.errors)}}}else if(p===`array`){B!==void 0&&e.length>B&&Q.push({instanceLocation:l,keyword:`maxItems`,keywordLocation:`${u}/maxItems`,error:`Array has too many items (${e.length} > ${B}).`}),z!==void 0&&e.length<z&&Q.push({instanceLocation:l,keyword:`minItems`,keywordLocation:`${u}/minItems`,error:`Array has too few items (${e.length} < ${z}).`});let n=e.length,r=0,c=!1;if(N!==void 0){let t=`${u}/prefixItems`,f=Math.min(N.length,n);for(;r<f;r++){let n=k(e[r],N[r],i,a,o,s,`${l}/${r}`,`${t}/${r}`);if(d[r]=!0,!n.valid&&(c=o,Q.push({instanceLocation:l,keyword:`prefixItems`,keywordLocation:t,error:`Items did not match schema.`},...n.errors),c))break}}if(P!==void 0){let t=`${u}/items`;if(Array.isArray(P)){let u=Math.min(P.length,n);for(;r<u;r++){let n=k(e[r],P[r],i,a,o,s,`${l}/${r}`,`${t}/${r}`);if(d[r]=!0,!n.valid&&(c=o,Q.push({instanceLocation:l,keyword:`items`,keywordLocation:t,error:`Items did not match schema.`},...n.errors),c))break}}else for(;r<n;r++){let n=k(e[r],P,i,a,o,s,`${l}/${r}`,t);if(d[r]=!0,!n.valid&&(c=o,Q.push({instanceLocation:l,keyword:`items`,keywordLocation:t,error:`Items did not match schema.`},...n.errors),c))break}if(!c&&F!==void 0){let t=`${u}/additionalItems`;for(;r<n;r++){let n=k(e[r],F,i,a,o,s,`${l}/${r}`,t);d[r]=!0,n.valid||(c=o,Q.push({instanceLocation:l,keyword:`additionalItems`,keywordLocation:t,error:`Items did not match additional items schema.`},...n.errors))}}}if(le!==void 0)if(n===0&&L===void 0)Q.push({instanceLocation:l,keyword:`contains`,keywordLocation:`${u}/contains`,error:`Array is empty. It must contain at least one item matching the schema.`});else if(L!==void 0&&n<L)Q.push({instanceLocation:l,keyword:`minContains`,keywordLocation:`${u}/minContains`,error:`Array has less items (${n}) than minContains (${L}).`});else{let t=`${u}/contains`,r=Q.length,c=0;for(let r=0;r<n;r++){let n=k(e[r],le,i,a,o,s,`${l}/${r}`,t);n.valid?(d[r]=!0,c++):Q.push(...n.errors)}c>=(L||0)&&(Q.length=r),L===void 0&&R===void 0&&c===0?Q.splice(r,0,{instanceLocation:l,keyword:`contains`,keywordLocation:t,error:`Array does not contain item matching schema.`}):L!==void 0&&c<L?Q.push({instanceLocation:l,keyword:`minContains`,keywordLocation:`${u}/minContains`,error:`Array must contain at least ${L} items matching schema. Only ${c} items were found.`}):R!==void 0&&c>R&&Q.push({instanceLocation:l,keyword:`maxContains`,keywordLocation:`${u}/maxContains`,error:`Array may contain at most ${R} items matching schema. ${c} items were found.`})}if(!c&&I!==void 0){let t=`${u}/unevaluatedItems`;for(;r<n;r++){if(d[r])continue;let n=k(e[r],I,i,a,o,s,`${l}/${r}`,t);d[r]=!0,n.valid||Q.push({instanceLocation:l,keyword:`unevaluatedItems`,keywordLocation:t,error:`Items did not match unevaluated items schema.`},...n.errors)}}if(V)for(let r=0;r<n;r++){let i=e[r],a=typeof i==`object`&&!!i;for(let o=0;o<n;o++){if(r===o)continue;let n=e[o];(i===n||a&&typeof n==`object`&&n&&t(i,n))&&(Q.push({instanceLocation:l,keyword:`uniqueItems`,keywordLocation:`${u}/uniqueItems`,error:`Duplicate items at indexes ${r} and ${o}.`}),r=2**53-1,o=2**53-1)}}}else if(p===`number`){if(i===`4`?(H!==void 0&&(W===!0&&e<=H||e<H)&&Q.push({instanceLocation:l,keyword:`minimum`,keywordLocation:`${u}/minimum`,error:`${e} is less than ${W?`or equal to `:``} ${H}.`}),U!==void 0&&(G===!0&&e>=U||e>U)&&Q.push({instanceLocation:l,keyword:`maximum`,keywordLocation:`${u}/maximum`,error:`${e} is greater than ${G?`or equal to `:``} ${U}.`})):(H!==void 0&&e<H&&Q.push({instanceLocation:l,keyword:`minimum`,keywordLocation:`${u}/minimum`,error:`${e} is less than ${H}.`}),U!==void 0&&e>U&&Q.push({instanceLocation:l,keyword:`maximum`,keywordLocation:`${u}/maximum`,error:`${e} is greater than ${U}.`}),W!==void 0&&e<=W&&Q.push({instanceLocation:l,keyword:`exclusiveMinimum`,keywordLocation:`${u}/exclusiveMinimum`,error:`${e} is less than ${W}.`}),G!==void 0&&e>=G&&Q.push({instanceLocation:l,keyword:`exclusiveMaximum`,keywordLocation:`${u}/exclusiveMaximum`,error:`${e} is greater than or equal to ${G}.`})),K!==void 0){let t=e%K;Math.abs(0-t)>=1.1920929e-7&&Math.abs(K-t)>=1.1920929e-7&&Q.push({instanceLocation:l,keyword:`multipleOf`,keywordLocation:`${u}/multipleOf`,error:`${e} is not a multiple of ${K}.`})}}else if(p===`string`){let t=q===void 0&&J===void 0?0:se(e);q!==void 0&&t<q&&Q.push({instanceLocation:l,keyword:`minLength`,keywordLocation:`${u}/minLength`,error:`String is too short (${t} < ${q}).`}),J!==void 0&&t>J&&Q.push({instanceLocation:l,keyword:`maxLength`,keywordLocation:`${u}/maxLength`,error:`String is too long (${t} > ${J}).`}),Y!==void 0&&!new RegExp(Y,`u`).test(e)&&Q.push({instanceLocation:l,keyword:`pattern`,keywordLocation:`${u}/pattern`,error:`String does not match pattern.`}),w!==void 0&&re[w]&&!re[w](e)&&Q.push({instanceLocation:l,keyword:`format`,keywordLocation:`${u}/format`,error:`String does not match format "${w}".`})}return{valid:Q.length===0,errors:Q}}var ce=class{schema;draft;shortCircuit;lookup;constructor(e,t=`2019-09`,n=!0){this.schema=e,this.draft=t,this.shortCircuit=n,this.lookup=c(e)}validate(e){return k(e,this.schema,this.draft,this.lookup,this.shortCircuit)}addSchema(e,t){t&&(e={...e,$id:t}),c(e,this.lookup)}};let A=`Failed to parse input arguments`,j=`Tool was executed but the invocation failed. For example, the script function threw an error`,M=`Tool was cancelled`,N={type:`object`,properties:{}},P=[`draft-2020-12`,`draft-07`],F=Symbol(`standardValidator`),I={installed:!1,previousModelContextDescriptor:void 0,previousModelContextTestingDescriptor:void 0};var le=class extends EventTarget{tools=new Map;testingShim=null;_ontoolchange=null;provideContextDeprecationWarned=!1;clearContextDeprecationWarned=!1;unregisterToolDeprecationWarned=!1;get ontoolchange(){return this._ontoolchange}set ontoolchange(e){this._ontoolchange=e}provideContext(e={}){this.warnProvideContextDeprecationOnce();let t=new Map;for(let n of e.tools??[]){let e=X(n,t);t.set(e.name,e)}this.tools=t,this.notifyToolsChanged()}clearContext(){this.warnClearContextDeprecationOnce(),this.tools.clear(),this.notifyToolsChanged()}registerTool(e,t){let n=t?.signal;if(n?.aborted){console.warn(`[WebMCPPolyfill] registerTool("${e?.name??`<unknown>`}") skipped: options.signal was already aborted.`);return}let r=X(e,this.tools);this.tools.set(r.name,r),this.notifyToolsChanged(),n&&n.addEventListener(`abort`,()=>{this.tools.delete(r.name)&&this.notifyToolsChanged()},{once:!0})}unregisterTool(e){this.warnUnregisterToolDeprecationOnce();let t=B(e);this.tools.delete(t)&&this.notifyToolsChanged()}getTools(){return this.getToolInfos()}getTestingShim(){return this.testingShim||=new L(this),this.testingShim}getToolInfos(){return[...this.tools.values()].map(e=>{let t;try{t=JSON.stringify(e.inputSchema??{type:`object`})}catch{t=`{"type":"object"}`}return{name:e.name,description:e.description,inputSchema:t}})}async executeToolForTesting(e,t,n){if(n?.signal?.aborted)throw R(M);let r=this.tools.get(e);if(!r)throw R(`Tool not found: ${e}`);let i=z(t),a=await ue(i,r);if(a)throw R(a);let o=!0,s={requestUserInteraction:async t=>{if(!o)throw Error(`ModelContextClient for tool "${e}" is no longer active after execute() resolved`);if(typeof t!=`function`)throw TypeError(`requestUserInteraction(callback) requires a function callback`);return t()}};try{let e=r.execute(i,s);return ve(ge(await ye(Promise.resolve(e),n?.signal)))}catch(e){throw R(e instanceof Error?`${j}: ${e.message}`:j)}finally{o=!1}}notifyToolsChanged(){queueMicrotask(()=>{let e=new Event(`toolchange`);try{this._ontoolchange?.call(this,e)}catch(e){console.warn(`[WebMCPPolyfill] navigator.modelContext.ontoolchange handler threw:`,e)}this.dispatchEvent(e),this.testingShim?.dispatchToolChange()})}warnProvideContextDeprecationOnce(){this.provideContextDeprecationWarned||(this.provideContextDeprecationWarned=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext.provideContext() is deprecated and will be removed in the next major version. Register tools individually with registerTool() instead.`))}warnClearContextDeprecationOnce(){this.clearContextDeprecationWarned||(this.clearContextDeprecationWarned=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext.clearContext() is deprecated and will be removed in the next major version. Unregister individual tools instead.`))}warnUnregisterToolDeprecationOnce(){this.unregisterToolDeprecationWarned||(this.unregisterToolDeprecationWarned=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext.unregisterTool() is deprecated. The April 23, 2026 WebMCP draft removed it in favor of registerTool(tool, { signal }) — pass an AbortSignal and abort it to unregister.`))}},L=class extends EventTarget{context;_ontoolchange=null;constructor(e){super(),this.context=e}listTools(){return this.context.getToolInfos()}executeTool(e,t,n){return this.context.executeToolForTesting(e,t,n)}getCrossDocumentScriptToolResult(){return Promise.resolve(`[]`)}get ontoolchange(){return this._ontoolchange}set ontoolchange(e){this._ontoolchange=e}registerToolsChangedCallback(e){if(typeof e!=`function`)throw TypeError(`Failed to execute 'registerToolsChangedCallback' on 'ModelContextTesting': parameter 1 is not of type 'Function'.`);this.addEventListener(`toolchange`,e)}dispatchToolChange(){let e=new Event(`toolchange`);try{this._ontoolchange?.call(this,e)}catch(e){console.warn(`[WebMCPPolyfill] ontoolchange handler threw:`,e)}this.dispatchEvent(e),this.dispatchEvent(new Event(`toolschanged`))}};function R(e){try{return new DOMException(e,`UnknownError`)}catch{let t=Error(e);return t.name=`UnknownError`,t}}function z(e){let t;try{t=JSON.parse(e)}catch{throw R(A)}if(!t||typeof t!=`object`||Array.isArray(t))throw R(A);return t}function B(e){if(typeof e==`string`)return e;if(V(e)&&typeof e.name==`string`)return e.name;throw TypeError(`Failed to execute 'unregisterTool' on 'ModelContext': parameter 1 must be a string or an object with a string name.`)}function V(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function H(e){if(!V(e))return null;let t=e[`~standard`];return V(t)?t:null}function U(e){let t=H(e);return!!(t&&t.version===1&&typeof t.validate==`function`)}function W(e){let t=H(e);return!t||t.version!==1||!V(t.jsonSchema)?!1:typeof t.jsonSchema.input==`function`}function G(e){return{"~standard":{version:1,vendor:`@mcp-b/webmcp-polyfill-json-schema`,validate(t){if(!V(t))return{issues:[{message:`expected object arguments`}]};let n=Z(t,e);return n?{issues:[n]}:{value:t}}}}}function K(e){for(let t of P)try{let n=e[`~standard`].jsonSchema.input({target:t});return J(n),n}catch(e){console.warn(`[WebMCPPolyfill] Standard JSON Schema conversion failed for target "${t}":`,e)}throw Error(`Failed to convert Standard JSON Schema inputSchema to a JSON Schema object`)}function q(e){if(e===void 0){let e=N;return{inputSchema:e,standardValidator:G(e)}}if(W(e)){let t=K(e);return{inputSchema:t,standardValidator:G(t)}}if(U(e))return{inputSchema:N,standardValidator:e};if(J(e),Object.keys(e).length===0)return{inputSchema:N,standardValidator:G(N)};let t=e.type===void 0?{type:`object`,...e}:e;return{inputSchema:t,standardValidator:G(t)}}function J(e){if(!V(e))throw Error(`inputSchema must be a JSON Schema object`);Y(e,`$`)}function Y(e,t){let n=e.type;if(n!==void 0&&typeof n!=`string`&&!(Array.isArray(n)&&n.every(e=>typeof e==`string`&&e.length>0)))throw Error(`Invalid JSON Schema at ${t}: "type" must be a string or string[]`);let r=e.required;if(r!==void 0&&!(Array.isArray(r)&&r.every(e=>typeof e==`string`)))throw Error(`Invalid JSON Schema at ${t}: "required" must be an array of strings`);let i=e.properties;if(i!==void 0){if(!V(i))throw Error(`Invalid JSON Schema at ${t}: "properties" must be an object`);for(let[e,n]of Object.entries(i)){if(!V(n))throw Error(`Invalid JSON Schema at ${t}.properties.${e}: expected object schema`);Y(n,`${t}.properties.${e}`)}}let a=e.items;if(a!==void 0)if(Array.isArray(a))for(let[e,n]of a.entries()){if(!V(n))throw Error(`Invalid JSON Schema at ${t}.items[${e}]: expected object schema`);Y(n,`${t}.items[${e}]`)}else if(V(a))Y(a,`${t}.items`);else throw Error(`Invalid JSON Schema at ${t}: "items" must be an object or object[]`);for(let n of[`allOf`,`anyOf`,`oneOf`]){let r=e[n];if(r!==void 0){if(!Array.isArray(r))throw Error(`Invalid JSON Schema at ${t}: "${n}" must be an array`);for(let[e,i]of r.entries()){if(!V(i))throw Error(`Invalid JSON Schema at ${t}.${n}[${e}]: expected object schema`);Y(i,`${t}.${n}[${e}]`)}}}let o=e.not;if(o!==void 0){if(!V(o))throw Error(`Invalid JSON Schema at ${t}: "not" must be an object schema`);Y(o,`${t}.not`)}try{JSON.stringify(e)}catch{throw Error(`Invalid JSON Schema at ${t}: schema must be JSON-serializable`)}}function X(e,t){if(!e||typeof e!=`object`)throw TypeError(`registerTool(tool) requires a tool object`);if(typeof e.name!=`string`||e.name.length===0)throw TypeError(`Tool "name" must be a non-empty string`);if(typeof e.description!=`string`||e.description.length===0)throw TypeError(`Tool "description" must be a non-empty string`);if(typeof e.execute!=`function`)throw TypeError(`Tool "execute" must be a function`);if(t.has(e.name))throw Error(`Tool already registered: ${e.name}`);let n=q(e.inputSchema),r=e.annotations,i=r?{...r,...r.readOnlyHint===`true`?{readOnlyHint:!0}:r.readOnlyHint===`false`?{readOnlyHint:!1}:{},...r.destructiveHint===`true`?{destructiveHint:!0}:r.destructiveHint===`false`?{destructiveHint:!1}:{},...r.idempotentHint===`true`?{idempotentHint:!0}:r.idempotentHint===`false`?{idempotentHint:!1}:{},...r.openWorldHint===`true`?{openWorldHint:!0}:r.openWorldHint===`false`?{openWorldHint:!1}:{}}:void 0;return{...e,...i?{annotations:i}:{},inputSchema:n.inputSchema,[F]:n.standardValidator}}function Z(e,t){let n=new ce(t,`2020-12`,!0).validate(e);if(n.valid)return null;let r=n.errors[n.errors.length-1];return r?{message:r.error}:{message:`Input validation failed`}}function Q(e){if(!e||e.length===0)return null;let t=e.map(e=>V(e)&&`key`in e?e.key:e).map(e=>String(e)).filter(e=>e.length>0);return t.length===0?null:t.join(`.`)}async function $(e,t){let n;try{n=await Promise.resolve(t[`~standard`].validate(e))}catch(e){let t=e instanceof Error?`: ${e.message}`:``;return console.error(`[WebMCPPolyfill] Standard Schema validation threw unexpectedly:`,e),`Input validation error: schema validation failed${t}`}if(!n.issues||n.issues.length===0)return null;let r=n.issues[0];if(!r)return`Input validation error`;let i=Q(r?.path);return i?`Input validation error: ${r.message} at ${i}`:`Input validation error: ${r.message}`}async function ue(e,t){return $(e,t[F])}function de(e){return V(e)&&Array.isArray(e.content)}function fe(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function pe(e){return fe(e)?Number.isFinite(e)||typeof e!=`number`:Array.isArray(e)?e.every(e=>pe(e)):V(e)?Object.values(e).every(e=>pe(e)):!1}function me(e){if(!(!V(e)||!pe(e)))return e}function he(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function ge(e){if(de(e))return e;let t=me(e);return{content:[{type:`text`,text:he(e)}],...t?{structuredContent:t}:{},isError:!1}}function _e(e){for(let t of e.content??[])if(t.type===`text`&&`text`in t&&typeof t.text==`string`)return t.text;return null}function ve(e){if(e.isError)throw R(_e(e)?.replace(/^Error:\s*/i,``).trim()||j);let t=e.metadata;if(t&&typeof t==`object`&&t.willNavigate)return null;try{return JSON.stringify(e)}catch{throw R(j)}}function ye(e,t){return t?t.aborted?Promise.reject(R(M)):new Promise((n,r)=>{let i=()=>{a(),r(R(M))},a=()=>{t.removeEventListener(`abort`,i)};t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{a(),n(e)},e=>{a(),r(e)})}):e}function be(){return typeof navigator<`u`?navigator:null}function xe(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!1,value:n})}function Se(e){let t=be();if(!t||t.modelContext)return;I.installed&&Ce();let n=new le,r=n;r.__isWebMCPPolyfill=!0,I.previousModelContextDescriptor=Object.getOwnPropertyDescriptor(t,`modelContext`),I.previousModelContextTestingDescriptor=Object.getOwnPropertyDescriptor(t,`modelContextTesting`),xe(t,`modelContext`,r);let i=e?.installTestingShim??`if-missing`,a=!!t.modelContextTesting;(i===`always`||(i===!0||i===`if-missing`)&&!a)&&xe(t,`modelContextTesting`,n.getTestingShim()),I.installed=!0}function Ce(){let e=be();if(!e||!I.installed)return;let t=(t,n)=>{if(n){Object.defineProperty(e,t,n);return}delete e[t]};t(`modelContext`,I.previousModelContextDescriptor),t(`modelContextTesting`,I.previousModelContextTestingDescriptor),I.installed=!1,I.previousModelContextDescriptor=void 0,I.previousModelContextTestingDescriptor=void 0}if(typeof window<`u`&&typeof document<`u`){let e=window.__webMCPPolyfillOptions;if(e?.autoInitialize!==!1)try{Se(e)}catch(e){console.error(`[WebMCPPolyfill] Auto-initialization failed:`,e)}}return e.cleanupWebMCPPolyfill=Ce,e.initializeWebMCPPolyfill=Se,e.initializeWebModelContextPolyfill=Se,e.isPlainObject=V,e.validateArgsWithSchema=Z,e})({});
1
+ var WebMCPPolyfill=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,n){let r=typeof e;if(r!==typeof n)return!1;if(Array.isArray(e)){if(!Array.isArray(n))return!1;let r=e.length;if(r!==n.length)return!1;for(let i=0;i<r;i++)if(!t(e[i],n[i]))return!1;return!0}if(r===`object`){if(!e||!n)return e===n;let r=Object.keys(e),i=Object.keys(n);if(r.length!==i.length)return!1;for(let i of r)if(!t(e[i],n[i]))return!1;return!0}return e===n}function n(e){return encodeURI(r(e))}function r(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}let i={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},a={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},o={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!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},s=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 c(e,t=Object.create(null),r=s,l=``){if(e&&typeof e==`object`&&!Array.isArray(e)){let n=e.$id||e.id;if(n){let i=new URL(n,r.href);i.hash.length>1?t[i.href]=e:(i.hash=``,l===``?r=i:c(e,t,r))}}else if(e!==!0&&e!==!1)return t;let u=r.href+(l?`#`+l:``);if(t[u]!==void 0)throw Error(`Duplicate schema URI "${u}".`);if(t[u]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0&&Object.defineProperty(e,`__absolute_uri__`,{enumerable:!1,value:u}),e.$ref&&e.__absolute_ref__===void 0){let t=new URL(e.$ref,r.href);t.hash=t.hash,Object.defineProperty(e,`__absolute_ref__`,{enumerable:!1,value:t.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let t=new URL(e.$recursiveRef,r.href);t.hash=t.hash,Object.defineProperty(e,`__absolute_recursive_ref__`,{enumerable:!1,value:t.href})}if(e.$anchor){let n=new URL(`#`+e.$anchor,r.href);t[n.href]=e}for(let s in e){if(o[s])continue;let u=`${l}/${n(s)}`,d=e[s];if(Array.isArray(d)){if(i[s]){let e=d.length;for(let n=0;n<e;n++)c(d[n],t,r,`${u}/${n}`)}}else if(a[s])for(let e in d)c(d[e],t,r,`${u}/${n(e)}`);else c(d,t,r,u)}return t}let l=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,u=[0,31,28,31,30,31,30,31,31,30,31,30,31],d=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,f=/^(?=.{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,p=/^(?:[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,m=/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,ee=/^(?:(?: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,h=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,g=/^(?:\/(?:[^~/]|~0|~1)*)*$/,_=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,v=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,te=e=>{if(e[0]===`"`)return!1;let[t,n,...r]=e.split(`@`);return!t||!n||r.length!==0||t.length>64||n.length>253||t[0]===`.`||t.endsWith(`.`)||t.includes(`..`)||!/^[a-z0-9.-]+$/i.test(n)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t)?!1:n.split(`.`).every(e=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(e))},ne=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,y=/^((([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,b=e=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function x(e){return e.test.bind(e)}let re={date:S,time:C.bind(void 0,!1),"date-time":T,duration:b,uri:oe,"uri-reference":x(p),"uri-template":x(m),url:x(ee),email:te,hostname:x(f),ipv4:x(ne),ipv6:x(y),regex:O,uuid:x(h),"json-pointer":x(g),"json-pointer-uri-fragment":x(_),"relative-json-pointer":x(v)};function ie(e){return e%4==0&&(e%100!=0||e%400==0)}function S(e){let t=e.match(l);if(!t)return!1;let n=+t[1],r=+t[2],i=+t[3];return r>=1&&r<=12&&i>=1&&i<=(r==2&&ie(n)?29:u[r])}function C(e,t){let n=t.match(d);if(!n)return!1;let r=+n[1],i=+n[2],a=+n[3],o=!!n[5];return(r<=23&&i<=59&&a<=59||r==23&&i==59&&a==60)&&(!e||o)}let w=/t|\s/i;function T(e){let t=e.split(w);return t.length==2&&S(t[0])&&C(!0,t[1])}let E=/\/|:/,ae=/^(?:[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 oe(e){return E.test(e)&&ae.test(e)}let D=/[^\\]\\Z/;function O(e){if(D.test(e))return!1;try{return new RegExp(e,`u`),!0}catch{return!1}}function se(e){let t=0,n=e.length,r=0,i;for(;r<n;)t++,i=e.charCodeAt(r++),i>=55296&&i<=56319&&r<n&&(i=e.charCodeAt(r),(i&64512)==56320&&r++);return t}function k(e,r,i=`2019-09`,a=c(r),o=!0,s=null,l=`#`,u=`#`,d=Object.create(null)){if(r===!0)return{valid:!0,errors:[]};if(r===!1)return{valid:!1,errors:[{instanceLocation:l,keyword:`false`,keywordLocation:l,error:`False boolean schema.`}]};let f=typeof e,p;switch(f){case`boolean`:case`number`:case`string`:p=f;break;case`object`:p=e===null?`null`:Array.isArray(e)?`array`:`object`;break;default:throw Error(`Instances of "${f}" type are not supported.`)}let{$ref:m,$recursiveRef:ee,$recursiveAnchor:h,type:g,const:_,enum:v,required:te,not:ne,anyOf:y,allOf:b,oneOf:x,if:ie,then:S,else:C,format:w,properties:T,patternProperties:E,additionalProperties:ae,unevaluatedProperties:oe,minProperties:D,maxProperties:O,propertyNames:ce,dependentRequired:A,dependentSchemas:j,dependencies:M,prefixItems:N,items:P,additionalItems:F,unevaluatedItems:I,contains:le,minContains:L,maxContains:R,minItems:z,maxItems:B,uniqueItems:ue,minimum:V,maximum:H,exclusiveMinimum:U,exclusiveMaximum:W,multipleOf:G,minLength:K,maxLength:q,pattern:J,__absolute_ref__:Y,__absolute_recursive_ref__:de}=r,X=[];if(h===!0&&s===null&&(s=r),ee===`#`){let t=s===null?a[de]:s,n=`${u}/$recursiveRef`,c=k(e,s===null?r:s,i,a,o,t,l,n,d);c.valid||X.push({instanceLocation:l,keyword:`$recursiveRef`,keywordLocation:n,error:`A subschema had errors.`},...c.errors)}if(m!==void 0){let t=a[Y||m];if(t===void 0){let e=`Unresolved $ref "${m}".`;throw Y&&Y!==m&&(e+=` Absolute URI "${Y}".`),e+=`\nKnown schemas:\n- ${Object.keys(a).join(`
2
+ - `)}`,Error(e)}let n=`${u}/$ref`,r=k(e,t,i,a,o,s,l,n,d);if(r.valid||X.push({instanceLocation:l,keyword:`$ref`,keywordLocation:n,error:`A subschema had errors.`},...r.errors),i===`4`||i===`7`)return{valid:X.length===0,errors:X}}if(Array.isArray(g)){let t=g.length,n=!1;for(let r=0;r<t;r++)if(p===g[r]||g[r]===`integer`&&p===`number`&&e%1==0&&e===e){n=!0;break}n||X.push({instanceLocation:l,keyword:`type`,keywordLocation:`${u}/type`,error:`Instance type "${p}" is invalid. Expected "${g.join(`", "`)}".`})}else g===`integer`?(p!==`number`||e%1||e!==e)&&X.push({instanceLocation:l,keyword:`type`,keywordLocation:`${u}/type`,error:`Instance type "${p}" is invalid. Expected "${g}".`}):g!==void 0&&p!==g&&X.push({instanceLocation:l,keyword:`type`,keywordLocation:`${u}/type`,error:`Instance type "${p}" is invalid. Expected "${g}".`});if(_!==void 0&&(p===`object`||p===`array`?t(e,_)||X.push({instanceLocation:l,keyword:`const`,keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(_)}.`}):e!==_&&X.push({instanceLocation:l,keyword:`const`,keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(_)}.`})),v!==void 0&&(p===`object`||p===`array`?v.some(n=>t(e,n))||X.push({instanceLocation:l,keyword:`enum`,keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`}):v.some(t=>e===t)||X.push({instanceLocation:l,keyword:`enum`,keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`})),ne!==void 0){let t=`${u}/not`;k(e,ne,i,a,o,s,l,t).valid&&X.push({instanceLocation:l,keyword:`not`,keywordLocation:t,error:`Instance matched "not" schema.`})}let Z=[];if(y!==void 0){let t=`${u}/anyOf`,n=X.length,r=!1;for(let n=0;n<y.length;n++){let c=y[n],u=Object.create(d),f=k(e,c,i,a,o,h===!0?s:null,l,`${t}/${n}`,u);X.push(...f.errors),r||=f.valid,f.valid&&Z.push(u)}r?X.length=n:X.splice(n,0,{instanceLocation:l,keyword:`anyOf`,keywordLocation:t,error:`Instance does not match any subschemas.`})}if(b!==void 0){let t=`${u}/allOf`,n=X.length,r=!0;for(let n=0;n<b.length;n++){let c=b[n],u=Object.create(d),f=k(e,c,i,a,o,h===!0?s:null,l,`${t}/${n}`,u);X.push(...f.errors),r&&=f.valid,f.valid&&Z.push(u)}r?X.length=n:X.splice(n,0,{instanceLocation:l,keyword:`allOf`,keywordLocation:t,error:`Instance does not match every subschema.`})}if(x!==void 0){let t=`${u}/oneOf`,n=X.length,r=x.filter((n,r)=>{let c=Object.create(d),u=k(e,n,i,a,o,h===!0?s:null,l,`${t}/${r}`,c);return X.push(...u.errors),u.valid&&Z.push(c),u.valid}).length;r===1?X.length=n:X.splice(n,0,{instanceLocation:l,keyword:`oneOf`,keywordLocation:t,error:`Instance does not match exactly one subschema (${r} matches).`})}if((p===`object`||p===`array`)&&Object.assign(d,...Z),ie!==void 0){let t=`${u}/if`;if(k(e,ie,i,a,o,s,l,t,d).valid){if(S!==void 0){let n=k(e,S,i,a,o,s,l,`${u}/then`,d);n.valid||X.push({instanceLocation:l,keyword:`if`,keywordLocation:t,error:`Instance does not match "then" schema.`},...n.errors)}}else if(C!==void 0){let n=k(e,C,i,a,o,s,l,`${u}/else`,d);n.valid||X.push({instanceLocation:l,keyword:`if`,keywordLocation:t,error:`Instance does not match "else" schema.`},...n.errors)}}if(p===`object`){if(te!==void 0)for(let t of te)t in e||X.push({instanceLocation:l,keyword:`required`,keywordLocation:`${u}/required`,error:`Instance does not have required property "${t}".`});let t=Object.keys(e);if(D!==void 0&&t.length<D&&X.push({instanceLocation:l,keyword:`minProperties`,keywordLocation:`${u}/minProperties`,error:`Instance does not have at least ${D} properties.`}),O!==void 0&&t.length>O&&X.push({instanceLocation:l,keyword:`maxProperties`,keywordLocation:`${u}/maxProperties`,error:`Instance does not have at least ${O} properties.`}),ce!==void 0){let t=`${u}/propertyNames`;for(let r in e){let e=`${l}/${n(r)}`,c=k(r,ce,i,a,o,s,e,t);c.valid||X.push({instanceLocation:l,keyword:`propertyNames`,keywordLocation:t,error:`Property name "${r}" does not match schema.`},...c.errors)}}if(A!==void 0){let t=`${u}/dependantRequired`;for(let n in A)if(n in e){let r=A[n];for(let i of r)i in e||X.push({instanceLocation:l,keyword:`dependentRequired`,keywordLocation:t,error:`Instance has "${n}" but does not have "${i}".`})}}if(j!==void 0)for(let t in j){let r=`${u}/dependentSchemas`;if(t in e){let c=k(e,j[t],i,a,o,s,l,`${r}/${n(t)}`,d);c.valid||X.push({instanceLocation:l,keyword:`dependentSchemas`,keywordLocation:r,error:`Instance has "${t}" but does not match dependant schema.`},...c.errors)}}if(M!==void 0){let t=`${u}/dependencies`;for(let r in M)if(r in e){let c=M[r];if(Array.isArray(c))for(let n of c)n in e||X.push({instanceLocation:l,keyword:`dependencies`,keywordLocation:t,error:`Instance has "${r}" but does not have "${n}".`});else{let u=k(e,c,i,a,o,s,l,`${t}/${n(r)}`);u.valid||X.push({instanceLocation:l,keyword:`dependencies`,keywordLocation:t,error:`Instance has "${r}" but does not match dependant schema.`},...u.errors)}}}let r=Object.create(null),c=!1;if(T!==void 0){let t=`${u}/properties`;for(let u in T){if(!(u in e))continue;let f=`${l}/${n(u)}`,p=k(e[u],T[u],i,a,o,s,f,`${t}/${n(u)}`);if(p.valid)d[u]=r[u]=!0;else if(c=o,X.push({instanceLocation:l,keyword:`properties`,keywordLocation:t,error:`Property "${u}" does not match schema.`},...p.errors),c)break}}if(!c&&E!==void 0){let t=`${u}/patternProperties`;for(let u in E){let f=new RegExp(u,`u`),p=E[u];for(let m in e){if(!f.test(m))continue;let ee=`${l}/${n(m)}`,h=k(e[m],p,i,a,o,s,ee,`${t}/${n(u)}`);h.valid?d[m]=r[m]=!0:(c=o,X.push({instanceLocation:l,keyword:`patternProperties`,keywordLocation:t,error:`Property "${m}" matches pattern "${u}" but does not match associated schema.`},...h.errors))}}}if(!c&&ae!==void 0){let t=`${u}/additionalProperties`;for(let u in e){if(r[u])continue;let f=`${l}/${n(u)}`,p=k(e[u],ae,i,a,o,s,f,t);p.valid?d[u]=!0:(c=o,X.push({instanceLocation:l,keyword:`additionalProperties`,keywordLocation:t,error:`Property "${u}" does not match additional properties schema.`},...p.errors))}}else if(!c&&oe!==void 0){let t=`${u}/unevaluatedProperties`;for(let r in e)if(!d[r]){let c=`${l}/${n(r)}`,u=k(e[r],oe,i,a,o,s,c,t);u.valid?d[r]=!0:X.push({instanceLocation:l,keyword:`unevaluatedProperties`,keywordLocation:t,error:`Property "${r}" does not match unevaluated properties schema.`},...u.errors)}}}else if(p===`array`){B!==void 0&&e.length>B&&X.push({instanceLocation:l,keyword:`maxItems`,keywordLocation:`${u}/maxItems`,error:`Array has too many items (${e.length} > ${B}).`}),z!==void 0&&e.length<z&&X.push({instanceLocation:l,keyword:`minItems`,keywordLocation:`${u}/minItems`,error:`Array has too few items (${e.length} < ${z}).`});let n=e.length,r=0,c=!1;if(N!==void 0){let t=`${u}/prefixItems`,f=Math.min(N.length,n);for(;r<f;r++){let n=k(e[r],N[r],i,a,o,s,`${l}/${r}`,`${t}/${r}`);if(d[r]=!0,!n.valid&&(c=o,X.push({instanceLocation:l,keyword:`prefixItems`,keywordLocation:t,error:`Items did not match schema.`},...n.errors),c))break}}if(P!==void 0){let t=`${u}/items`;if(Array.isArray(P)){let u=Math.min(P.length,n);for(;r<u;r++){let n=k(e[r],P[r],i,a,o,s,`${l}/${r}`,`${t}/${r}`);if(d[r]=!0,!n.valid&&(c=o,X.push({instanceLocation:l,keyword:`items`,keywordLocation:t,error:`Items did not match schema.`},...n.errors),c))break}}else for(;r<n;r++){let n=k(e[r],P,i,a,o,s,`${l}/${r}`,t);if(d[r]=!0,!n.valid&&(c=o,X.push({instanceLocation:l,keyword:`items`,keywordLocation:t,error:`Items did not match schema.`},...n.errors),c))break}if(!c&&F!==void 0){let t=`${u}/additionalItems`;for(;r<n;r++){let n=k(e[r],F,i,a,o,s,`${l}/${r}`,t);d[r]=!0,n.valid||(c=o,X.push({instanceLocation:l,keyword:`additionalItems`,keywordLocation:t,error:`Items did not match additional items schema.`},...n.errors))}}}if(le!==void 0)if(n===0&&L===void 0)X.push({instanceLocation:l,keyword:`contains`,keywordLocation:`${u}/contains`,error:`Array is empty. It must contain at least one item matching the schema.`});else if(L!==void 0&&n<L)X.push({instanceLocation:l,keyword:`minContains`,keywordLocation:`${u}/minContains`,error:`Array has less items (${n}) than minContains (${L}).`});else{let t=`${u}/contains`,r=X.length,c=0;for(let r=0;r<n;r++){let n=k(e[r],le,i,a,o,s,`${l}/${r}`,t);n.valid?(d[r]=!0,c++):X.push(...n.errors)}c>=(L||0)&&(X.length=r),L===void 0&&R===void 0&&c===0?X.splice(r,0,{instanceLocation:l,keyword:`contains`,keywordLocation:t,error:`Array does not contain item matching schema.`}):L!==void 0&&c<L?X.push({instanceLocation:l,keyword:`minContains`,keywordLocation:`${u}/minContains`,error:`Array must contain at least ${L} items matching schema. Only ${c} items were found.`}):R!==void 0&&c>R&&X.push({instanceLocation:l,keyword:`maxContains`,keywordLocation:`${u}/maxContains`,error:`Array may contain at most ${R} items matching schema. ${c} items were found.`})}if(!c&&I!==void 0){let t=`${u}/unevaluatedItems`;for(;r<n;r++){if(d[r])continue;let n=k(e[r],I,i,a,o,s,`${l}/${r}`,t);d[r]=!0,n.valid||X.push({instanceLocation:l,keyword:`unevaluatedItems`,keywordLocation:t,error:`Items did not match unevaluated items schema.`},...n.errors)}}if(ue)for(let r=0;r<n;r++){let i=e[r],a=typeof i==`object`&&!!i;for(let o=0;o<n;o++){if(r===o)continue;let n=e[o];(i===n||a&&typeof n==`object`&&n&&t(i,n))&&(X.push({instanceLocation:l,keyword:`uniqueItems`,keywordLocation:`${u}/uniqueItems`,error:`Duplicate items at indexes ${r} and ${o}.`}),r=2**53-1,o=2**53-1)}}}else if(p===`number`){if(i===`4`?(V!==void 0&&(U===!0&&e<=V||e<V)&&X.push({instanceLocation:l,keyword:`minimum`,keywordLocation:`${u}/minimum`,error:`${e} is less than ${U?`or equal to `:``} ${V}.`}),H!==void 0&&(W===!0&&e>=H||e>H)&&X.push({instanceLocation:l,keyword:`maximum`,keywordLocation:`${u}/maximum`,error:`${e} is greater than ${W?`or equal to `:``} ${H}.`})):(V!==void 0&&e<V&&X.push({instanceLocation:l,keyword:`minimum`,keywordLocation:`${u}/minimum`,error:`${e} is less than ${V}.`}),H!==void 0&&e>H&&X.push({instanceLocation:l,keyword:`maximum`,keywordLocation:`${u}/maximum`,error:`${e} is greater than ${H}.`}),U!==void 0&&e<=U&&X.push({instanceLocation:l,keyword:`exclusiveMinimum`,keywordLocation:`${u}/exclusiveMinimum`,error:`${e} is less than ${U}.`}),W!==void 0&&e>=W&&X.push({instanceLocation:l,keyword:`exclusiveMaximum`,keywordLocation:`${u}/exclusiveMaximum`,error:`${e} is greater than or equal to ${W}.`})),G!==void 0){let t=e%G;Math.abs(0-t)>=1.1920929e-7&&Math.abs(G-t)>=1.1920929e-7&&X.push({instanceLocation:l,keyword:`multipleOf`,keywordLocation:`${u}/multipleOf`,error:`${e} is not a multiple of ${G}.`})}}else if(p===`string`){let t=K===void 0&&q===void 0?0:se(e);K!==void 0&&t<K&&X.push({instanceLocation:l,keyword:`minLength`,keywordLocation:`${u}/minLength`,error:`String is too short (${t} < ${K}).`}),q!==void 0&&t>q&&X.push({instanceLocation:l,keyword:`maxLength`,keywordLocation:`${u}/maxLength`,error:`String is too long (${t} > ${q}).`}),J!==void 0&&!new RegExp(J,`u`).test(e)&&X.push({instanceLocation:l,keyword:`pattern`,keywordLocation:`${u}/pattern`,error:`String does not match pattern.`}),w!==void 0&&re[w]&&!re[w](e)&&X.push({instanceLocation:l,keyword:`format`,keywordLocation:`${u}/format`,error:`String does not match format "${w}".`})}return{valid:X.length===0,errors:X}}var ce=class{schema;draft;shortCircuit;lookup;constructor(e,t=`2019-09`,n=!0){this.schema=e,this.draft=t,this.shortCircuit=n,this.lookup=c(e)}validate(e){return k(e,this.schema,this.draft,this.lookup,this.shortCircuit)}addSchema(e,t){t&&(e={...e,$id:t}),c(e,this.lookup)}};let A={type:`object`,properties:{}},j=[`draft-2020-12`,`draft-07`];function M(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function N(e){if(!M(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function P(e,t=new WeakSet){if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(typeof e!=`object`||t.has(e))return!1;t.add(e);try{return(Array.isArray(e)?e:N(e)?Object.values(e):null)?.every(e=>P(e,t))??!1}catch{return!1}finally{t.delete(e)}}function F(e){return P(e)?e:void 0}function I(e){if(!M(e))return null;let t=e[`~standard`];return M(t)?t:null}function le(e){let t=I(e);return!!(t&&t.version===1&&typeof t.validate==`function`)}function L(e){let t=I(e);return!t||t.version!==1||!M(t.jsonSchema)?!1:typeof t.jsonSchema.input==`function`}function R(e){return{"~standard":{version:1,vendor:`@mcp-b/webmcp-polyfill-json-schema`,validate(t){if(!M(t))return{issues:[{message:`expected object arguments`}]};let n=H(t,e);return n?{issues:[n]}:{value:t}}}}}function z(e){let t=[];for(let n of j)try{let t=e[`~standard`].jsonSchema.input({target:n});return ue(t),t}catch(e){t.push({target:n,error:e})}throw console.warn(`[WebMCPPolyfill] Standard JSON Schema conversion failed:`,t),Error(`Failed to convert Standard JSON Schema inputSchema to a JSON Schema object`)}function B(e){if(e===void 0){let e=A;return{inputSchema:e,standardValidator:R(e)}}if(L(e)){let t=z(e);return{inputSchema:t,standardValidator:R(t)}}if(le(e))return{inputSchema:A,standardValidator:e};if(ue(e),Object.keys(e).length===0)return{inputSchema:A,standardValidator:R(A)};let t=e.type===void 0?{type:`object`,...e}:e;return{inputSchema:t,standardValidator:R(t)}}function ue(e){if(!M(e))throw Error(`inputSchema must be a JSON Schema object`);V(e,`$`)}function V(e,t){let n=e.type;if(n!==void 0&&typeof n!=`string`&&!(Array.isArray(n)&&n.every(e=>typeof e==`string`&&e.length>0)))throw Error(`Invalid JSON Schema at ${t}: "type" must be a string or string[]`);let r=e.required;if(r!==void 0&&!(Array.isArray(r)&&r.every(e=>typeof e==`string`)))throw Error(`Invalid JSON Schema at ${t}: "required" must be an array of strings`);let i=e.properties;if(i!==void 0){if(!M(i))throw Error(`Invalid JSON Schema at ${t}: "properties" must be an object`);for(let[e,n]of Object.entries(i)){if(!M(n))throw Error(`Invalid JSON Schema at ${t}.properties.${e}: expected object schema`);V(n,`${t}.properties.${e}`)}}let a=e.items;if(a!==void 0)if(Array.isArray(a))for(let[e,n]of a.entries()){if(!M(n))throw Error(`Invalid JSON Schema at ${t}.items[${e}]: expected object schema`);V(n,`${t}.items[${e}]`)}else if(M(a))V(a,`${t}.items`);else throw Error(`Invalid JSON Schema at ${t}: "items" must be an object or object[]`);for(let n of[`allOf`,`anyOf`,`oneOf`]){let r=e[n];if(r!==void 0){if(!Array.isArray(r))throw Error(`Invalid JSON Schema at ${t}: "${n}" must be an array`);for(let[e,i]of r.entries()){if(!M(i))throw Error(`Invalid JSON Schema at ${t}.${n}[${e}]: expected object schema`);V(i,`${t}.${n}[${e}]`)}}}let o=e.not;if(o!==void 0){if(!M(o))throw Error(`Invalid JSON Schema at ${t}: "not" must be an object schema`);V(o,`${t}.not`)}try{JSON.stringify(e)}catch{throw Error(`Invalid JSON Schema at ${t}: schema must be JSON-serializable`)}}function H(e,t){let n=new ce(t,`2020-12`,!0).validate(e);if(n.valid)return null;let r=n.errors[n.errors.length-1];return r?{message:r.error}:{message:`Input validation failed`}}let U=`Failed to parse input arguments`,W=`Tool was executed but the invocation failed. For example, the script function threw an error`,G=`Tool was cancelled`,K=/^[A-Za-z0-9_\-.]{1,128}$/u,q=Symbol(`standardValidator`);function J(){return new DOMException(`signal is aborted without reason`,`AbortError`)}let Y={installed:!1,previousNavigatorModelContextDescriptor:void 0,previousNavigatorModelContextTestingDescriptor:void 0,previousDocumentModelContextDescriptor:void 0,installedNavigatorModelContext:!1,installedNavigatorModelContextTesting:!1,installedDocumentModelContext:!1};var de=class extends EventTarget{tools=new Map;testingShim=null;_ontoolchange=null;unregisterToolDeprecationWarned=!1;toolsChangedQueued=!1;get ontoolchange(){return this._ontoolchange}set ontoolchange(e){this._ontoolchange=e}registerTool(e,t){let n=t?.signal;if(n?.aborted)return Promise.reject(J());let r=he(e,this.tools);return this.tools.set(r.name,r),this.notifyToolsChanged(),n&&n.addEventListener(`abort`,()=>{this.tools.delete(r.name)&&this.notifyToolsChanged()},{once:!0}),Promise.resolve()}unregisterTool(e){this.warnUnregisterToolDeprecationOnce();let t=me(e);this.tools.delete(t)&&this.notifyToolsChanged()}getTools(){return Promise.resolve(this.getRegisteredToolInfos())}executeTool(e,t,n){return this.executeToolByName(e.name,t,n,!1)}getTestingShim(){return this.testingShim||=new X(this),this.testingShim}getToolInfos(){return[...this.tools.values()].map(e=>{let t;try{t=JSON.stringify(e.inputSchema??{type:`object`})}catch{t=`{"type":"object"}`}return{name:e.name,description:e.description,inputSchema:t}})}getRegisteredToolInfos(){return this.getToolInfos().map(e=>{let t=this.tools.get(e.name);return{...e,title:t?.title??``,origin:globalThis.location?.origin??``,window:globalThis.window}})}async executeToolForTesting(e,t,n){return this.executeToolByName(e,t,n,!0)}async executeToolByName(e,t,n,r){if(n?.signal?.aborted)throw Z(G);let i=this.tools.get(e);if(!i)throw Z(`Tool not found: ${e}`);let a=pe(t),o=await ve(a,i);if(o)throw Z(o);let s=!0,c={requestUserInteraction:async t=>{if(!s)throw Error(`ModelContextClient for tool "${e}" is no longer active after execute() resolved`);if(typeof t!=`function`)throw TypeError(`requestUserInteraction(callback) requires a function callback`);return t()}};try{let e=i.execute(a,c),t=await Te(Promise.resolve(e),n?.signal),o=Se(t),s=ye(o,i);if(s)throw Error(s);if(r)return we(o);let l=JSON.stringify(t);return l===void 0?null:l}catch(e){throw Z(e instanceof Error?`${W}: ${e.message}`:W)}finally{s=!1}}notifyToolsChanged(){this.toolsChangedQueued||(this.toolsChangedQueued=!0,queueMicrotask(()=>{this.toolsChangedQueued=!1;let e=new Event(`toolchange`);try{this._ontoolchange?.call(this,e)}catch(e){console.warn(`[WebMCPPolyfill] navigator.modelContext.ontoolchange handler threw:`,e)}this.dispatchEvent(e),this.testingShim?.dispatchToolChange()}))}warnUnregisterToolDeprecationOnce(){this.unregisterToolDeprecationWarned||(this.unregisterToolDeprecationWarned=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext.unregisterTool() is deprecated. The April 23, 2026 WebMCP draft removed it in favor of registerTool(tool, { signal }) — pass an AbortSignal and abort it to unregister.`))}},X=class extends EventTarget{context;_ontoolchange=null;constructor(e){super(),this.context=e}listTools(){return this.context.getToolInfos()}executeTool(e,t,n){return this.context.executeToolForTesting(e,t,n)}getCrossDocumentScriptToolResult(){return Promise.resolve(`[]`)}get ontoolchange(){return this._ontoolchange}set ontoolchange(e){this._ontoolchange=e}registerToolsChangedCallback(e){if(typeof e!=`function`)throw TypeError(`Failed to execute 'registerToolsChangedCallback' on 'ModelContextTesting': parameter 1 is not of type 'Function'.`);this.addEventListener(`toolchange`,e)}dispatchToolChange(){let e=new Event(`toolchange`);try{this._ontoolchange?.call(this,e)}catch(e){console.warn(`[WebMCPPolyfill] ontoolchange handler threw:`,e)}this.dispatchEvent(e),this.dispatchEvent(new Event(`toolschanged`))}};function Z(e){try{return new DOMException(e,`UnknownError`)}catch{let t=Error(e);return t.name=`UnknownError`,t}}function fe(e){try{return new DOMException(e,`InvalidStateError`)}catch{let t=Error(e);return t.name=`InvalidStateError`,t}}function pe(e){let t;try{t=JSON.parse(e)}catch{throw Z(U)}if(!t||typeof t!=`object`||Array.isArray(t))throw Z(U);return t}function me(e){if(typeof e==`string`)return e;if(M(e)&&typeof e.name==`string`)return e.name;throw TypeError(`Failed to execute 'unregisterTool' on 'ModelContext': parameter 1 must be a string or an object with a string name.`)}function he(e,t){if(!e||typeof e!=`object`)throw TypeError(`registerTool(tool) requires a tool object`);if(typeof e.name!=`string`||e.name.length===0)throw fe(`Tool "name" must be a non-empty string`);if(!K.test(e.name)||Array.from(e.name).length>128)throw fe(`Tool "name" must be 1–128 characters and contain only ASCII alphanumeric, underscore, hyphen, or period`);if(typeof e.description!=`string`||e.description.length===0)throw fe(`Tool "description" must be a non-empty string`);if(typeof e.execute!=`function`)throw TypeError(`Tool "execute" must be a function`);if(t.has(e.name))throw Error(`Tool already registered: ${e.name}`);let n=B(e.inputSchema),r=e.annotations,i=r?{...r,...r.readOnlyHint===`true`?{readOnlyHint:!0}:r.readOnlyHint===`false`?{readOnlyHint:!1}:{},...r.destructiveHint===`true`?{destructiveHint:!0}:r.destructiveHint===`false`?{destructiveHint:!1}:{},...r.idempotentHint===`true`?{idempotentHint:!0}:r.idempotentHint===`false`?{idempotentHint:!1}:{},...r.openWorldHint===`true`?{openWorldHint:!0}:r.openWorldHint===`false`?{openWorldHint:!1}:{}}:void 0;return{...e,...i?{annotations:i}:{},inputSchema:n.inputSchema,[q]:n.standardValidator}}function ge(e){if(!e||e.length===0)return null;let t=e.map(e=>M(e)&&`key`in e?e.key:e).map(e=>String(e)).filter(e=>e.length>0);return t.length===0?null:t.join(`.`)}async function _e(e,t){let n;try{n=await Promise.resolve(t[`~standard`].validate(e))}catch(e){let t=e instanceof Error?`: ${e.message}`:``;return console.error(`[WebMCPPolyfill] Standard Schema validation threw unexpectedly:`,e),`Input validation error: schema validation failed${t}`}if(!n.issues||n.issues.length===0)return null;let r=n.issues[0];if(!r)return`Input validation error`;let i=ge(r?.path);return i?`Input validation error: ${r.message} at ${i}`:`Input validation error: ${r.message}`}async function ve(e,t){return _e(e,t[q])}function ye(e,t){if(!t.outputSchema||e.isError)return null;if(e.structuredContent===void 0)return`Output validation error: Tool ${t.name} has an output schema but no structured content was provided`;let n=H(e.structuredContent,t.outputSchema);return n?`Output validation error: ${n.message}`:null}function be(e){return M(e)&&Array.isArray(e.content)}function xe(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function Se(e){if(be(e))return e;let t=F(e);return{content:[{type:`text`,text:xe(e)}],...t===void 0?{}:{structuredContent:t},isError:!1}}function Ce(e){for(let t of e.content??[])if(t.type===`text`&&`text`in t&&typeof t.text==`string`)return t.text;return null}function we(e){if(e.isError)throw Z(Ce(e)?.replace(/^Error:\s*/i,``).trim()||W);let t=e.metadata;if(t&&typeof t==`object`&&t.willNavigate)return null;try{return JSON.stringify(e)}catch{throw Z(W)}}function Te(e,t){return t?t.aborted?Promise.reject(Z(G)):new Promise((n,r)=>{let i=()=>{a(),r(Z(G))},a=()=>{t.removeEventListener(`abort`,i)};t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{a(),n(e)},e=>{a(),r(e)})}):e}function Ee(){return typeof navigator<`u`?navigator:null}function De(){return typeof document<`u`?document:null}function Oe(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!1,value:n})}function ke(e,t){Object.defineProperty(e,`modelContext`,{configurable:!0,enumerable:!0,writable:!1,value:t})}let Q=!1;function Ae(e,t){Object.defineProperty(e,`modelContext`,{configurable:!0,enumerable:!0,get(){return Q||(Q=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext is deprecated. The May 27, 2026 WebMCP draft moved the modelContext getter from Navigator to Document — use document.modelContext instead. See https://github.com/webmachinelearning/webmcp/pull/184.`)),t}})}function $(e){let t=Ee(),n=De();if(!t&&!n||n?.modelContext)return;let r=t?.modelContext,i=!!r;if(Y.installed&&je(),n&&r){Y.previousDocumentModelContextDescriptor=Object.getOwnPropertyDescriptor(n,`modelContext`),ke(n,r),Y.installedDocumentModelContext=!0,Y.installed=!0;return}if(i)return;let a=new de,o=a;if(o.__isWebMCPPolyfill=!0,n&&(Y.previousDocumentModelContextDescriptor=Object.getOwnPropertyDescriptor(n,`modelContext`),ke(n,o),Y.installedDocumentModelContext=!0),t){Y.previousNavigatorModelContextDescriptor=Object.getOwnPropertyDescriptor(t,`modelContext`),Y.previousNavigatorModelContextTestingDescriptor=Object.getOwnPropertyDescriptor(t,`modelContextTesting`),Q=!1,Ae(t,o),Y.installedNavigatorModelContext=!0;let n=e?.installTestingShim??`if-missing`,r=!!t.modelContextTesting;(n===`always`||(n===!0||n===`if-missing`)&&!r)&&(Oe(t,`modelContextTesting`,a.getTestingShim()),Y.installedNavigatorModelContextTesting=!0)}Y.installed=!0}function je(){if(!Y.installed)return;let e=(e,t,n)=>{if(n){Object.defineProperty(e,t,n);return}delete e[t]},t=Ee(),n=De();n&&Y.installedDocumentModelContext&&e(n,`modelContext`,Y.previousDocumentModelContextDescriptor),t&&Y.installedNavigatorModelContext&&e(t,`modelContext`,Y.previousNavigatorModelContextDescriptor),t&&Y.installedNavigatorModelContextTesting&&e(t,`modelContextTesting`,Y.previousNavigatorModelContextTestingDescriptor),Y.installed=!1,Y.previousDocumentModelContextDescriptor=void 0,Y.previousNavigatorModelContextDescriptor=void 0,Y.previousNavigatorModelContextTestingDescriptor=void 0,Y.installedDocumentModelContext=!1,Y.installedNavigatorModelContext=!1,Y.installedNavigatorModelContextTesting=!1,Q=!1}if(typeof window<`u`&&typeof document<`u`){let e=window.__webMCPPolyfillOptions;if(e?.autoInitialize!==!1)try{$(e)}catch(e){console.error(`[WebMCPPolyfill] Auto-initialization failed:`,e)}}return e.cleanupWebMCPPolyfill=je,e.initializeWebMCPPolyfill=$,e.initializeWebModelContextPolyfill=$,e.isPlainObject=M,e.normalizeInputSchema=B,e.toJsonValue=F,e.validateValueWithSchema=H,e})({});