@mcp-b/webmcp-polyfill 4.1.0-beta.20260702224704 → 5.0.0

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,255 +1,185 @@
1
1
  # @mcp-b/webmcp-polyfill
2
2
 
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;
17
- if (modelContext) {
18
- // Register tools...
19
- }
20
- ```
21
-
22
- `@mcp-b/webmcp-polyfill` installs only the strict core API:
23
-
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
27
- - `unregisterTool(nameOrTool)` (deprecated compatibility API)
28
-
29
- It does not install MCP bridge extensions like `callTool`, resources, or prompts.
30
-
31
- Important:
32
-
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(...)`.
35
- - For list/execute test flows, use `navigator.modelContextTesting` (when `installTestingShim` is enabled).
36
- - `provideContext()` and `clearContext()` were removed from the upstream WebMCP spec on March 5, 2026 and are not exposed by this polyfill.
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.
38
-
39
- ## Type Safety First
3
+ A browser polyfill for the current core WebMCP API on `document.modelContext`.
4
+ It implements tool registration, discovery, lifecycle events, and Chromium's
5
+ optional `executeTool()` extension. MCP features such as prompts, resources,
6
+ browser transport, and a composed MCP server belong to the MCP-B runtime built
7
+ by `@mcp-b/global`.
40
8
 
41
- `@mcp-b/webmcp-polyfill` is runtime-focused. For compile-time safety, pair it with
42
- `@mcp-b/webmcp-types`.
43
-
44
- Recommended setup:
45
-
46
- - `@mcp-b/webmcp-polyfill` for strict runtime behavior
47
- - `@mcp-b/webmcp-types` for schema-driven TypeScript inference
48
-
49
- ## Package Selection
50
-
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) |
9
+ The current WebMCP draft is published at
10
+ [webmachinelearning.github.io/webmcp](https://webmachinelearning.github.io/webmcp/).
56
11
 
57
12
  ## Install
58
13
 
59
14
  ```bash
60
15
  pnpm add @mcp-b/webmcp-polyfill
61
- # or
62
- npm install @mcp-b/webmcp-polyfill
63
16
  ```
64
17
 
65
- ## Quick Start (ESM)
18
+ ## Initialize
19
+
20
+ ES modules initialize explicitly:
66
21
 
67
22
  ```ts
68
23
  import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
69
24
 
70
25
  initializeWebMCPPolyfill();
71
-
72
- document.modelContext.registerTool({
73
- name: 'get-page-title',
74
- description: 'Get the current page title',
75
- inputSchema: { type: 'object', properties: {} },
76
- async execute() {
77
- return {
78
- content: [{ type: 'text', text: document.title }],
79
- };
80
- },
81
- });
82
26
  ```
83
27
 
84
- ## Quick Start (Script Tag / IIFE)
28
+ The standalone IIFE initializes when loaded:
85
29
 
86
30
  ```html
87
- <script>
88
- window.__webMCPPolyfillOptions = {
89
- installTestingShim: 'if-missing',
90
- };
91
- </script>
92
31
  <script src="https://unpkg.com/@mcp-b/webmcp-polyfill@latest/dist/index.iife.js"></script>
93
32
  ```
94
33
 
95
- The IIFE auto-initializes by default.
96
-
97
- ## Type Inference (with `@mcp-b/webmcp-types`)
98
-
99
- The polyfill provides runtime behavior. For strict compile-time inference, pair it with `@mcp-b/webmcp-types`.
100
-
101
- ```ts
102
- import type { JsonSchemaForInference } from '@mcp-b/webmcp-types';
103
- import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
104
-
105
- initializeWebMCPPolyfill();
34
+ Set testing options before loading the IIFE only when a test harness needs the
35
+ deprecated Chromium testing surface:
106
36
 
107
- const inputSchema = {
108
- type: 'object',
109
- properties: {
110
- query: { type: 'string' },
111
- limit: { type: 'integer', minimum: 1, maximum: 50 },
112
- },
113
- required: ['query'],
114
- additionalProperties: false,
115
- } as const satisfies JsonSchemaForInference;
116
-
117
- document.modelContext.registerTool({
118
- name: 'search',
119
- description: 'Search indexed docs',
120
- inputSchema,
121
- async execute(args) {
122
- // Inferred type:
123
- // { query: string; limit?: number }
124
- return {
125
- content: [{ type: 'text', text: `Searching for ${args.query} (${args.limit ?? 10})` }],
126
- };
127
- },
128
- });
37
+ ```html
38
+ <script>
39
+ window.__webMCPPolyfillOptions = { installTestingShim: true };
40
+ </script>
129
41
  ```
130
42
 
131
- Inference notes:
132
-
133
- - Best results come from literal schemas (`as const satisfies JsonSchemaForInference`).
134
- - Widened/runtime schemas fall back to `Record<string, unknown>` for safety.
43
+ ## Declare a form tool
135
44
 
136
- ## API
45
+ When the polyfill owns `document.modelContext`, it observes annotated forms in
46
+ the document and its open shadow roots and registers them as tools. It derives
47
+ input schemas from native named controls and keeps registrations synchronized
48
+ with DOM changes.
137
49
 
138
- ### `initializeWebMCPPolyfill(options?)`
139
-
140
- Installs the strict core polyfill on `document.modelContext` (canonical) and `navigator.modelContext` (deprecated alias to the same instance).
141
-
142
- | Option | Type | Default | Notes |
143
- | --------------------------------- | ------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------ |
144
- | `autoInitialize` | `boolean` | `true` | Used by auto-init flows (IIFE/import side effect). Set `false` to disable auto-init and initialize manually. |
145
- | `installTestingShim` | `boolean \| 'always' \| 'if-missing'` | `'if-missing'` | Controls whether `navigator.modelContextTesting` is installed. |
146
- | `disableIframeTransportByDefault` | `boolean` | n/a | Deprecated no-op, kept for compatibility. |
147
-
148
- Behavior:
149
-
150
- - No-op in non-browser environments.
151
- - Non-destructive by default: if either `document.modelContext` or `navigator.modelContext` already exists (e.g. native Chromium support), initialization is skipped.
152
- - Safe to call repeatedly.
153
-
154
- ### `initializeWebModelContextPolyfill(options?)`
155
-
156
- Alias of `initializeWebMCPPolyfill`.
50
+ ```html
51
+ <form toolname="search_catalog" tooldescription="Search the product catalog" toolautosubmit>
52
+ <input name="query" required toolparamdescription="Words to match" />
53
+ <button type="submit">Search</button>
54
+ </form>
157
55
 
158
- ### `cleanupWebMCPPolyfill()`
56
+ <script>
57
+ document.querySelector('form').addEventListener('submit', (event) => {
58
+ if (!event.agentInvoked) return;
159
59
 
160
- Restores previous `document.modelContext`, `navigator.modelContext`, and `navigator.modelContextTesting` descriptors and resets polyfill install state.
60
+ event.preventDefault();
61
+ event.respondWith(Promise.resolve({ matches: [] }));
62
+ });
63
+ </script>
64
+ ```
161
65
 
162
- ## Strict Core Behavior
66
+ Without `toolautosubmit`, invocation fills the form and waits for the user to
67
+ submit it. With `toolautosubmit`, the polyfill validates the form and calls
68
+ `requestSubmit()`. Agent submissions expose `SubmitEvent.agentInvoked` and
69
+ `SubmitEvent.respondWith()`.
163
70
 
164
- ### `registerTool(tool, options?)`
71
+ CI checks the standalone polyfill against the upstream
72
+ [declarative Web Platform Tests](https://github.com/web-platform-tests/wpt/tree/master/webmcp/declarative).
73
+ Repository-specific browser tests cover the polyfill and composed MCP-B runtime.
74
+ See Chrome's
75
+ [declarative API documentation](https://developer.chrome.com/docs/ai/webmcp/declarative-api)
76
+ for the evolving API. The Community Group draft's
77
+ [declarative section](https://webmachinelearning.github.io/webmcp/#declarative-webmcp)
78
+ is still incomplete.
165
79
 
166
- - Requires a non-empty `name`, non-empty `description`, and `execute` function.
167
- - Throws on duplicate tool names.
168
- - If `inputSchema` is omitted, runtime defaults to `{ type: 'object', properties: {} }`.
169
- - `options.signal` (optional `AbortSignal`) - when the signal aborts, the tool is unregistered. If the signal is already aborted at registration time, the polyfill skips the registration and logs a warning (matching the April 23, 2026 spec step).
80
+ ## Register a tool
170
81
 
171
82
  ```ts
172
- const ac = new AbortController();
173
- document.modelContext.registerTool(
83
+ const registration = new AbortController();
84
+
85
+ await document.modelContext.registerTool(
174
86
  {
175
- name: 'search',
176
- description: 'Search docs',
87
+ name: 'get-page-title',
88
+ description: 'Return the current page title',
177
89
  inputSchema: { type: 'object', properties: {} },
178
- async execute() {
179
- return { content: [{ type: 'text', text: 'ok' }] };
180
- },
90
+ execute: async () => ({ title: document.title }),
181
91
  },
182
- { signal: ac.signal }
92
+ { signal: registration.signal }
183
93
  );
184
94
 
185
- // Later - unregister cleanly:
186
- ac.abort();
95
+ // Remove the registration later.
96
+ registration.abort();
187
97
  ```
188
98
 
189
- ### `unregisterTool(nameOrTool)` (deprecated)
190
-
191
- - Removes a tool by name. MCP-B compatibility runtimes also accept the originally registered tool object.
192
- - Unknown names are a no-op.
193
- - Logs a one-time deprecation warning. Prefer the `AbortSignal` form on `registerTool(tool, options)`.
194
-
195
- ## Listing and Executing Tools
99
+ `registerTool()` resolves after the local `toolchange` notification. Duplicate
100
+ names, invalid descriptors, aborted registrations, and non-serializable schemas
101
+ reject the returned promise.
196
102
 
197
- In `@mcp-b/webmcp-polyfill`, listing and execution helpers are exposed on
198
- `navigator.modelContextTesting` (not `document.modelContext`) when the testing shim is enabled.
103
+ ## Discover and execute
199
104
 
200
105
  ```ts
201
- import { initializeWebMCPPolyfill } from '@mcp-b/webmcp-polyfill';
202
-
203
- initializeWebMCPPolyfill({ installTestingShim: true });
106
+ import type { ChromeModelContext } from '@mcp-b/webmcp-types';
204
107
 
205
- const tools = navigator.modelContextTesting?.listTools();
206
- const result = await navigator.modelContextTesting?.executeTool(
207
- 'search',
208
- JSON.stringify({ query: 'webmcp' })
209
- );
108
+ const context = document.modelContext as ChromeModelContext;
109
+ const [tool] = await context.getTools();
210
110
 
211
- void tools;
212
- void result;
111
+ if (tool && context.executeTool) {
112
+ const result = await context.executeTool(tool, JSON.stringify({}));
113
+ console.log(result);
114
+ }
213
115
  ```
214
116
 
215
- If you want `callTool(...)` / extension-style runtime methods on `document.modelContext`, use
216
- `@mcp-b/global`.
117
+ `executeTool()` is a Chromium extension, not part of the core `ModelContext`
118
+ interface. Feature-detect it.
217
119
 
218
- ## Input Schema Support
120
+ The local polyfill cannot securely implement cross-document discovery or
121
+ exposure. Non-empty `fromOrigins` and `exposedTo` arrays reject with
122
+ `NotSupportedError`; use native WebMCP for those capabilities. Where the host
123
+ browser exposes the `tools` Permissions Policy, the polyfill enforces it. In
124
+ browsers without that policy feature, cross-origin frames fail closed.
219
125
 
220
- `inputSchema` accepts:
221
-
222
- - Plain JSON Schema objects (`InputSchema`)
223
- - Standard Schema v1 validator objects (`~standard.validate(...)`)
224
- - Standard JSON Schema v1 objects (`~standard.jsonSchema.input(...)`)
225
-
226
- Notes:
227
-
228
- - Standard JSON Schema conversion is attempted with targets `draft-2020-12`, then `draft-07`.
229
- - When both Standard validator and Standard JSON Schema are present, JSON conversion is preferred for validation parity.
126
+ ## API
230
127
 
231
- ## Optional Testing Shim
128
+ ### `initializeWebMCPPolyfill(options?)`
232
129
 
233
- When enabled via `installTestingShim`, the polyfill can install a compatibility `navigator.modelContextTesting` with:
130
+ Installs `window.ModelContext` and `document.modelContext` when native WebMCP is
131
+ absent. It also keeps `navigator.modelContext` as the repository's deprecated
132
+ compatibility alias.
234
133
 
235
- - `listTools()`
236
- - `executeTool(toolName, inputArgsJson, options?)`
237
- - `registerToolsChangedCallback(callback)`
238
- - `getCrossDocumentScriptToolResult()`
134
+ ```ts
135
+ interface WebMCPPolyfillInitOptions {
136
+ installTestingShim?: boolean; // default: false
137
+ }
138
+ ```
239
139
 
240
- Older native previews also exposed `navigator.modelContextTesting.ontoolchange`; the polyfill keeps the callback-based compatibility API for now.
140
+ Initialization is idempotent and does not replace an existing native context or
141
+ testing implementation.
241
142
 
242
- `executeTool(...)` accepts JSON-string arguments and returns a serialized result string or `null` (for navigation-style responses).
143
+ ### `cleanupWebMCPPolyfill()`
243
144
 
244
- ## Interop with `@mcp-b/global`
145
+ Removes registrations, detaches their abort listeners, and restores every
146
+ property descriptor changed by initialization.
245
147
 
246
- - If this polyfill is installed first, `@mcp-b/global` can attach bridge features without replacing the existing core object identity.
247
- - Use `@mcp-b/global` directly when you need extension APIs such as `callTool`, resources, or prompts.
148
+ ## Testing shim
248
149
 
249
- ## Migration Notes
150
+ `installTestingShim: true` installs the deprecated, testing-only
151
+ `navigator.modelContextTesting` compatibility surface when it is absent:
250
152
 
251
- - `forceOverride` was removed from initialization options.
252
- - Existing code passing `forceOverride` should remove it.
153
+ - `listTools()`
154
+ - `executeTool(name, inputJson, options?)`
155
+ - `toolchange` events and `ontoolchange`
156
+
157
+ Prefer `getTools()` plus feature-detected `executeTool()` for native-browser
158
+ coverage.
159
+
160
+ ## Schema helpers
161
+
162
+ The `@mcp-b/webmcp-polyfill/schema` entry owns shared browser-runtime adapters
163
+ used by MCP-B packages. `normalizeInputSchema()` accepts plain JSON Schema and
164
+ Standard Schema v1 implementations that expose `~standard.jsonSchema.input()`.
165
+ This conversion is an MCP-B adapter feature; the strict WebMCP registration
166
+ boundary itself accepts JSON Schema.
167
+
168
+ For literal-schema TypeScript inference, install `@mcp-b/webmcp-types` and use
169
+ `JsonSchemaForInference`. Runtime-defined schemas safely fall back to
170
+ object-or-array input.
171
+
172
+ ## Compatibility boundary
173
+
174
+ - `document.modelContext` is canonical.
175
+ - `navigator.modelContext` is deprecated compatibility.
176
+ - Tool lifetime is owned by the `AbortSignal` passed to `registerTool()`.
177
+ - `unregisterTool()`, `provideContext()`, and `clearContext()` are not exposed.
178
+ - Importing the ESM entry has no initialization side effect.
179
+ - Declarative forms do not emulate native CSS tool-state pseudo-classes,
180
+ `toolcancel`, cross-navigation responses, file inputs, or custom
181
+ form-associated elements.
182
+ - Closed shadow roots cannot be inspected.
253
183
 
254
184
  ## License
255
185
 
package/dist/index.d.ts CHANGED
@@ -1,33 +1,17 @@
1
- import { StandardInputJsonSchema, StandardInputValidatorSchema, StandardJSONSchemaV1, ToolInputSchema, ToolOutputSchema, isPlainObject, normalizeInputSchema, toJsonValue, validateValueWithSchema } from "./schema.js";
2
-
3
1
  //#region src/index.d.ts
4
2
  interface WebMCPPolyfillInitOptions {
5
- /**
6
- * Controls whether the polyfill auto-initializes when loaded.
7
- * Set to false to prevent auto-initialization; then call initializeWebMCPPolyfill() manually.
8
- * @default true
9
- */
10
- autoInitialize?: boolean;
11
3
  /**
12
4
  * Controls installation of navigator.modelContextTesting when this polyfill provides modelContext.
13
- * - true or 'if-missing' (default): install only when modelContextTesting is missing.
14
- * - 'always': install even when modelContextTesting already exists.
15
- * - false: do not install.
16
- * @default 'if-missing'
17
- */
18
- installTestingShim?: boolean | 'always' | 'if-missing';
19
- /**
20
- * Deprecated no-op kept for backward compatibility with previous wrappers.
5
+ * The shim is testing-only and never replaces an existing implementation.
6
+ *
7
+ * Off by default so the polyfill stays spec-pure; modelContextTesting is a removed
8
+ * Chromium preview API. `@mcp-b/global` deliberately opts in (its own default is true).
9
+ * @default false
21
10
  */
22
- disableIframeTransportByDefault?: boolean;
11
+ installTestingShim?: boolean;
23
12
  }
24
13
  declare function initializeWebMCPPolyfill(options?: WebMCPPolyfillInitOptions): void;
25
14
  declare function cleanupWebMCPPolyfill(): void;
26
- declare global {
27
- interface Window {
28
- __webMCPPolyfillOptions?: WebMCPPolyfillInitOptions;
29
- }
30
- } //# sourceMappingURL=index.d.ts.map
31
15
  //#endregion
32
- export { type StandardInputJsonSchema, type StandardInputValidatorSchema, type StandardJSONSchemaV1, type ToolInputSchema, type ToolOutputSchema, WebMCPPolyfillInitOptions, cleanupWebMCPPolyfill, initializeWebMCPPolyfill, initializeWebMCPPolyfill as initializeWebModelContextPolyfill, isPlainObject, normalizeInputSchema, toJsonValue, validateValueWithSchema };
16
+ export { WebMCPPolyfillInitOptions, cleanupWebMCPPolyfill, initializeWebMCPPolyfill };
33
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
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})({});
1
+ var WebMCPPolyfill=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=`Tool was executed but the invocation failed. For example, the script function threw an error`,n=/^[A-Za-z0-9_.-]{1,128}$/u;function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function i(e){if(typeof e==`symbol`)throw TypeError(`Symbol values cannot be converted to a DOMString`);return String(e)}function a(e){let t=Reflect.get(e,`name`),n=Reflect.get(e,`description`),a=Reflect.get(e,`title`);if(t===void 0)throw TypeError(`Tool "name" is required`);if(n===void 0)throw TypeError(`Tool "description" is required`);let o=Reflect.get(e,`annotations`),s=r(o)?o:{},c=Reflect.get(e,`inputSchema`),l=Reflect.get(e,`outputSchema`),u=Reflect.get(e,`execute`);return{name:i(t),...a===void 0?{}:{title:i(a).toWellFormed()},description:i(n),...c===void 0?{}:{inputSchema:c},...l===void 0?{}:{outputSchema:l},execute:u,...o===void 0?{}:{annotations:{...s.title===void 0?{}:{title:i(s.title).toWellFormed()},readOnlyHint:!!s.readOnlyHint,...s.destructiveHint===void 0?{}:{destructiveHint:!!s.destructiveHint},...s.idempotentHint===void 0?{}:{idempotentHint:!!s.idempotentHint},...s.openWorldHint===void 0?{}:{openWorldHint:!!s.openWorldHint},untrustedContentHint:!!s.untrustedContentHint}}}}function o(e){return new DOMException(e,`UnknownError`)}function s(e){return o(e instanceof Error?`${t}: ${e.message}`:t)}function c(e){return new DOMException(e,`InvalidStateError`)}function l(e){if(e.name===``)throw c(`Tool "name" must be a non-empty string`);if(typeof e.name!=`string`||!n.test(e.name))throw c(`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 c(`Tool "description" must be a non-empty string`);if(typeof e.execute!=`function`)throw TypeError(`Tool "execute" must be a function`)}function u(e){return{readOnlyHint:e.readOnlyHint??!1,untrustedContentHint:e.untrustedContentHint??!1}}function d(e){try{let t=JSON.parse(e);if(Array.isArray(t)||r(t))return t}catch{}throw o(`Failed to parse input arguments`)}function f(e){if(typeof e==`object`&&e||typeof e==`function`)try{let t=JSON.stringify(e);if(t)return t}catch{}return String(e)||`Operation succeeded`}function p(e,t,n=()=>t?.reason){return t?t.aborted?Promise.reject(n()):new Promise((r,i)=>{let a=()=>{o(),i(n())},o=()=>t.removeEventListener(`abort`,a);t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{o(),r(e)},e=>{o(),i(e)})}):e}function m(e){let t=e.origin===`null`?e:new URL(e.origin),n=t.protocol;if([`https:`,`wss:`,`file:`,`chrome-extension:`,`moz-extension:`].includes(n))return!0;let r=t.hostname.toLowerCase(),i=r.split(`.`),a=i.length===4&&i.every(e=>/^\d{1,3}$/u.test(e)&&Number(e)<=255)&&Number(i[0])===127;return r===`::1`||r===`[::1]`||r===`localhost`||r===`localhost.`||r.endsWith(`.localhost`)||r.endsWith(`.localhost.`)||a}function h(e){for(let t of e??[]){let e;try{e=new URL(t)}catch{throw new DOMException(`Invalid or untrustworthy origin: ${String(t)}`,`SecurityError`)}if(!m(e))throw new DOMException(`Invalid or untrustworthy origin: ${t}`,`SecurityError`)}}function g(e){if(ee(),!e)return;let t=e.defaultView?.DOMException??DOMException,n=!1;try{let t=e.defaultView;n=!!(t&&t.document===e)}catch{}if(!n)throw new t(`The associated document is not fully active`,`InvalidStateError`);let r=Reflect.get(e,`permissionsPolicy`)??Reflect.get(e,`featurePolicy`);if(r&&typeof r==`object`){let e=Reflect.get(r,`features`),n=Reflect.get(r,`allowsFeature`);if(typeof e==`function`&&typeof n==`function`){let i=Reflect.apply(e,r,[]);if(Array.isArray(i)&&i.includes(`tools`)){if(Reflect.apply(n,r,[`tools`])===!0)return;throw new t(`WebMCP is disabled by Permissions Policy`,`NotAllowedError`)}}}let i=e.defaultView;if(!(!i||i.parent===i)){try{i.parent.document;return}catch{}throw new t(`WebMCP in cross-origin frames requires native Permissions Policy support`,`NotAllowedError`)}}function ee(){if(globalThis.originAgentCluster===!1&&globalThis.location?.protocol!==`file:`)throw new DOMException(``,`SecurityError`)}function te(e){try{if(new URL(String(e)).origin!==`null`)return}catch{}throw new DOMException(`Unsupported tool origin: ${String(e)}`,`NotSupportedError`)}function ne(e){if(e===null||typeof e!=`object`&&typeof e!=`function`)throw TypeError(`inputSchema must be an object`);let t=JSON.stringify(e);if(t===void 0)throw TypeError(`inputSchema must be JSON-serializable`);return t}let _=new WeakSet,v=new WeakMap,y=new WeakMap;function b(e){return e.isTrusted&&(_.has(e)||e.eventPhase!==Event.NONE&&e.target instanceof HTMLFormElement&&y.has(e.target))}function re(e,t){if(!b(e))throw new DOMException(`respondWith() is only available during an agent-invoked submit event`,`InvalidStateError`);if(!e.defaultPrevented)throw new DOMException(`respondWith() requires preventDefault() during an agent-invoked submit event`,`InvalidStateError`);if(e.eventPhase===Event.NONE)throw new DOMException(`respondWith() is only available while the submit event is being dispatched`,`InvalidStateError`);_.add(e);let n=Promise.resolve(t);v.set(e,n),e.target instanceof HTMLFormElement&&y.get(e.target)?.respond(e)}let x=new Set([`email`,`password`,`search`,`tel`,`text`,`url`]),ie=new Set([...x,`date`,`datetime-local`,`month`,`number`,`time`,`week`]);function S(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function C(e){return Reflect.get(HTMLFormElement.prototype,`elements`,e)}function w(e,t){return Reflect.apply(Element.prototype.getAttribute,e,[t])}function T(e,t){return Reflect.apply(Element.prototype.hasAttribute,e,[t])}function ae(e){return Reflect.get(Node.prototype,`isConnected`,e)}function oe(e){return Reflect.get(Element.prototype,`shadowRoot`,e)}function se(e){return Reflect.apply(HTMLFormElement.prototype.checkValidity,e,[])}function ce(e,t){Reflect.apply(HTMLFormElement.prototype.requestSubmit,e,t?[t]:[])}function le(e){return[...C(e)].filter(e=>S(e)&&!e.matches(`:disabled`)&&!(`readOnly`in e&&e.readOnly&&(e instanceof HTMLTextAreaElement||ie.has(e.type))))}function E(e){let t=new Map;for(let n of le(e)){let e=n.name.trim(),r=t.get(e);r?r.push(n):t.set(e,[n])}return t}function D(e){return[...e.labels??[]].map(e=>{let t=e.cloneNode(!0);return t instanceof HTMLElement?(t.querySelectorAll(`button, input, meter, output, progress, select, textarea`).forEach(e=>e.remove()),t.textContent?.trim()??``):``}).filter(Boolean).join(`; `)}function ue(e,t){for(let n=t[0]?.parentElement;n&&n!==e;n=n.parentElement)if(n instanceof HTMLFieldSetElement&&t.every(e=>n.contains(e)))return n}function de(e,t){if(t.length===1){let e=t[0];return e&&(e.getAttribute(`toolparamdescription`)||D(e)||e.getAttribute(`aria-description`))||void 0}return ue(e,t)?.getAttribute(`toolparamdescription`)||void 0}function O(e,t,n,r){let i=de(t,n),a=i&&r?`${i} (${r})`:i||r;return a?{...e,description:a}:e}function k(e,t){let n=e.getAttribute(t);if(n===null||n.trim()===``)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function fe(e,t){let n=e/t;return Math.abs(n-Math.round(n))<2**-52*16}function A(e){let t=e.getAttribute(`pattern`);if(t!==null)try{return new RegExp(t,`v`),t}catch{return}}function j(e,t=!0){let n={type:`number`},r=k(e,`min`),i=k(e,`max`);r!==void 0&&(n.minimum=r),i!==void 0&&(n.maximum=i);let a=e.getAttribute(`step`);if(a!==`any`){let t=a===null||a===``?1:Number(a),i=Number.isFinite(t)&&t>0?t:1,o=Number(e.getAttribute(`value`));fe(r??(Number.isFinite(o)?o:0),i)&&(n.multipleOf=i)}let o=t?A(e):void 0;return o!==void 0&&(n.pattern=o),n}function M(e,t){let n=e.getAttribute(`step`),r=n===null||n===``?60:Number(n),i=Number.isFinite(r)&&r>0?r:60;return i<1?`${t}(:[0-5][0-9](\\.[0-9]{1,3})?)?$`:i<60?`${t}(:[0-5][0-9])?$`:`${t}$`}function pe(e){return{anyOf:e.map(e=>({type:`string`,const:e.value,title:e.textContent??``})),enum:e.map(e=>e.value)}}function N(e){return{anyOf:e.map(e=>{let t=D(e);return{type:`string`,const:e.value,...t?{title:t}:{}}}),enum:e.map(e=>e.value)}}function P(e,t){let n=t[0];if(n){if(t.length>1)return t.every(e=>e instanceof HTMLInputElement)?t.every(e=>e.type===`checkbox`)?O({type:`array`,items:{type:`string`,...N(t)},uniqueItems:!0},e,t):t.every(e=>e.type===`radio`)?O({type:`string`,...N(t)},e,t):void 0:void 0;if(n instanceof HTMLTextAreaElement)return O({type:`string`},e,t);if(n instanceof HTMLSelectElement){let r=pe([...n.options]);return O(n.multiple?{type:`array`,items:{type:`string`,...r},uniqueItems:!0}:{type:`string`,...r},e,t)}if(x.has(n.type)){let r={type:`string`},i=A(n);return i!==void 0&&(r.pattern=i),O(r,e,t)}if(n.type===`hidden`)return n.getAttribute(`toolparamdescription`)?O({type:`string`},e,t):void 0;if(n.type===`number`)return O(j(n),e,t);if(n.type===`range`){let r=j(n,!1);return r.minimum??=0,r.maximum??=100,O(r,e,t)}if(n.type===`checkbox`)return O({type:`boolean`},e,t);if(n.type===`radio`)return O({type:`string`,...N([n])},e,t);if(n.type===`date`)return O({type:`string`,format:`date`},e,t,`Dates MUST be provided in 'YYYY-MM-DD' format.`);if(n.type===`month`)return O({type:`string`,format:`^[0-9]{4}-(0[1-9]|1[0-2])$`},e,t);if(n.type===`week`)return O({type:`string`,format:`^[0-9]{4}-W(0[1-9]|[1-4][0-9]|5[0-3])$`},e,t);if(n.type===`time`)return O({type:`string`,format:M(n,`^([01][0-9]|2[0-3]):[0-5][0-9]`)},e,t);if(n.type===`datetime-local`)return O({type:`string`,format:M(n,`^[0-9]{4}-(0[1-9]|1[0-2])-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]`)},e,t);if(n.type===`color`)return O({type:`string`,format:`^#[0-9a-zA-Z]{6}$`},e,t)}}function me(e){let t={},n=[];for(let[r,i]of E(e)){if(!r)continue;let a=P(e,i);a&&(Object.defineProperty(t,r,{configurable:!0,enumerable:!0,value:a,writable:!0}),i.some(e=>e.required)&&n.push(r))}return{type:`object`,properties:t,required:n}}function he(e){return{name:w(e,`toolname`)??``,title:w(e,`tooltitle`)??``,description:w(e,`tooldescription`)??``,inputSchema:me(e),autosubmit:T(e,`toolautosubmit`)}}function F(e){if(typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e))return String(e)}function I(e){if(typeof e==`boolean`)return e;if(typeof e==`number`&&Number.isInteger(e))return e!==0;if(typeof e==`string`){if(e===`1`||e.toLowerCase()===`true`)return!0;if(e===`0`||e.toLowerCase()===`false`)return!1}}function L(e,t){if(!Array.isArray(e))return!1;let n=new Set(t);for(let t of e){let e=F(t);if(e===void 0||!n.delete(e))return!1}return!0}function ge(e,t){if(t===``)return e.type!==`number`&&e.type!==`range`;let n=e.ownerDocument.createElement(`input`);return n.type=e.type,n.value=t,n.value!==``}function _e(e,t,n){let r=t[0];if(!r||!P(e,t))return!1;if(t.length>1){if(!t.every(e=>e instanceof HTMLInputElement))return!1;if(t.every(e=>e.type===`checkbox`))return L(n,new Set(t.map(e=>e.value)));if(t.every(e=>e.type===`radio`)){let e=F(n);return e!==void 0&&t.some(t=>t.value===e)}return!1}if(r instanceof HTMLSelectElement){let e=new Set([...r.options].map(e=>e.value));if(r.multiple)return L(n,e);let t=F(n);return t!==void 0&&e.has(t)}if(r instanceof HTMLTextAreaElement)return F(n)!==void 0;if(r.type===`checkbox`)return I(n)!==void 0;if(r.type===`radio`){let e=F(n);return e!==void 0&&r.value===e}let i=F(n);return i!==void 0&&ge(r,i)}function R(e){e.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0}))}function ve(e,t){let n=e instanceof HTMLInputElement?HTMLInputElement.prototype:HTMLTextAreaElement.prototype;Object.getOwnPropertyDescriptor(n,`value`)?.set?.call(e,t)}function z(e,t){Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,`checked`)?.set?.call(e,t)}function ye(e,t){let n=e[0];if(!n)return;if(e.length>1&&e.every(e=>e instanceof HTMLInputElement)){if(e.every(e=>e.type===`checkbox`)&&Array.isArray(t)){let n=new Set(t.map(F));for(let t of e){let e=n.has(t.value);t.checked!==e&&(z(t,e),R(t))}return}let n=F(t),r=e.find(e=>e.value===n);r&&!r.checked&&(z(r,!0),R(r));return}if(n instanceof HTMLSelectElement){if(n.multiple&&Array.isArray(t)){let e=new Set(t.map(F)),r=!1;for(let t of n.options){let n=e.has(t.value);t.selected!==n&&(t.selected=n,r=!0)}r&&R(n);return}let e=F(t);e!==void 0&&n.value!==e&&(n.value=e,R(n));return}if(n instanceof HTMLInputElement&&n.type===`checkbox`){let e=I(t);e!==void 0&&n.checked!==e&&(z(n,e),R(n));return}if(n instanceof HTMLInputElement&&n.type===`radio`){F(t)===n.value&&!n.checked&&(z(n,!0),R(n));return}let r=F(t);r!==void 0&&n.value!==r&&(ve(n,r),R(n))}function be(e,t){if(Array.isArray(t))throw TypeError(`Declarative tool input must be an object`);let n=E(e);for(let[r,i]of Object.entries(t)){let t=n.get(r);if(!t||!_e(e,t,i))throw TypeError(`Invalid value for declarative form parameter "${r}"`)}for(let[e,r]of Object.entries(t))ye(n.get(e)??[],r)}function xe(e){return[...C(e)].find(e=>!e.matches(`:disabled`)&&(e instanceof HTMLButtonElement&&e.type===`submit`||e instanceof HTMLInputElement&&[`image`,`submit`].includes(e.type)))}function Se(e){let t=[...C(e)].filter(e=>S(e)&&e.willValidate&&!e.validity.valid).map(e=>`${e.name.trim()||`{unknown}`}: ${e.validationMessage}`).join(`. `);return new DOMException(`Form validation failed: ${t}`,`UnknownError`)}function B(e){let t=new Event(`toolactivated`);return Object.defineProperty(t,`toolName`,{enumerable:!0,value:e}),t}function Ce(e,t,n,r){let{form:i}=e;return e.cancelPending?.(new DOMException(`Tool execution cancelled`,`UnknownError`)),new Promise((a,o)=>{let s=!1,c=()=>{Reflect.apply(EventTarget.prototype.removeEventListener,i,[`invalid`,f,!0]),y.delete(i),e.cancelPending===u&&delete e.cancelPending},l=e=>{s||(s=!0,c(),e())},u=e=>l(()=>o(e)),d=e=>{e.then(e=>l(()=>a(e)),e=>l(()=>o(e)))},f=e=>{e.isTrusted&&queueMicrotask(()=>{se(i)||u(Se(i))})};if(y.set(i,{complete(e){queueMicrotask(()=>{let t=v.get(e);t?d(t):e.defaultPrevented?u(new DOMException(`preventDefault() requires respondWith()`,`UnknownError`)):l(()=>a(void 0))})},direct(){l(()=>a(void 0))},respond(e){queueMicrotask(()=>{let t=v.get(e);t&&d(t)})}}),e.cancelPending=u,Reflect.apply(EventTarget.prototype.addEventListener,i,[`invalid`,f,!0]),!n){r?.focus(),window.dispatchEvent(B(t));return}try{ce(i,r),window.dispatchEvent(B(t))}catch(e){u(e)}})}function we(e,t){let n=!0,r=new Map,i=new Map,a=new Map,o=e=>{if(!(e instanceof SubmitEvent)||!e.isTrusted||!(e.target instanceof HTMLFormElement))return;let t=y.get(e.target);t&&(_.add(e),t.complete(e))},s=e=>{if(!e.isTrusted||!(e.target instanceof HTMLFormElement))return;let t=e.target;queueMicrotask(()=>{e.defaultPrevented||r.get(t)?.cancelPending?.(new DOMException(`Tool execution cancelled by form reset`,`UnknownError`))})};function c(e){a.get(e)?.disconnect(),a.delete(e),e.removeEventListener(`reset`,s,!0),e.removeEventListener(`submit`,o,!0)}function l(e){if(a.has(e))return;let t=new MutationObserver(u);a.set(e,t),t.observe(e,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),e.addEventListener(`reset`,s,!0),e.addEventListener(`submit`,o,!0)}function u(){l(e);for(let e of a.keys())e instanceof ShadowRoot&&!Reflect.get(Node.prototype,`isConnected`,e.host)&&c(e);let n=new Set,o=new Map,s=new Map;for(let e of a.keys())for(let t of e.querySelectorAll(`*`)){let e=oe(t);if(e&&l(e),!(t instanceof HTMLFormElement)||!T(t,`toolname`)||!T(t,`tooldescription`)||!ae(t))continue;let r=t;n.add(r);let a=he(r),c=JSON.stringify(a),u=i.get(r);if(u===c)continue;let d=u!==void 0;i.delete(r);let f=s.get(a.name);if(f&&!d){i.set(r,c);continue}if(f){let e=o.get(f);e&&(i.set(f,e.fingerprint),o.delete(f))}s.set(a.name,r),o.set(r,{definition:a,fingerprint:c})}for(let e of i.keys())n.has(e)||i.delete(e);for(let[e,t]of r)o.get(e)?.fingerprint!==t.fingerprint&&(t.cancelPending?.(new DOMException(`Tool execution cancelled because its form changed`,`UnknownError`)),t.controller.abort(),r.delete(e));for(let[e,{definition:n,fingerprint:i}]of o){if(r.has(e))continue;let a=new AbortController,o={controller:a,fingerprint:i,form:e};r.set(e,o),t.registerTool({name:n.name,title:n.title,description:n.description,inputSchema:n.inputSchema,execute(t){let r=xe(e);if(!n.autosubmit&&!r)throw new DOMException(`A declarative form without toolautosubmit requires a submit button`,`UnknownError`);return be(e,t),Ce(o,n.name,n.autosubmit,r)}},{signal:a.signal}).catch(e=>{a.abort(),e?.name!==`AbortError`&&console.error(`[webmcp] declarative form tool "${n.name}" was not registered:`,e)})}}let d=()=>{},f=e.defaultView?.Element.prototype,p=f?Object.getOwnPropertyDescriptor(f,`attachShadow`):void 0;if(f&&p?.configurable){let t=f.attachShadow,r=function(r){let i=t.call(this,r);return n&&i.mode===`open`&&Reflect.get(Node.prototype,`ownerDocument`,this)===e&&Reflect.get(Node.prototype,`isConnected`,this)&&l(i),i};Object.defineProperty(f,`attachShadow`,{...p,value:r}),d=()=>{f.attachShadow===r&&Object.defineProperty(f,`attachShadow`,p)}}let m=()=>{},h=e.defaultView?.HTMLFormElement.prototype,g=h?Object.getOwnPropertyDescriptor(h,`submit`):void 0;if(h&&g?.configurable){let e=h.submit,t=function(){e.call(this),n&&y.get(this)?.direct()};Object.defineProperty(h,`submit`,{...g,value:t}),m=()=>{h.submit===t&&Object.defineProperty(h,`submit`,g)}}return u(),()=>{n=!1,m(),d();for(let e of a.keys())c(e);i.clear();for(let e of r.values())e.cancelPending?.(new DOMException(`Tool execution cancelled`,`UnknownError`)),e.controller.abort();r.clear()}}let V=Symbol(`registeredInputSchema`),H=Symbol(`registrationSignal`),U=Symbol(`registrationAbort`),W=[],G=null,K=null;function q(){return typeof globalThis.origin==`string`?globalThis.origin:globalThis.location?.origin??``}function J(e,t,n){let r=Object.getOwnPropertyDescriptor(e,t);try{Object.defineProperty(e,t,n)}catch(e){throw $(),e}W.push({target:e,key:t,previous:r})}var Y=class extends EventTarget{#e=new Map;#t=null;#n=null;#r=e=>{this.#n?.call(this,e)};#i;#a;constructor(e){super(),this.#a=e,this.#i=e?.defaultView?.DOMException??DOMException,Object.defineProperty(this,`__isWebMCPPolyfill`,{value:!0,enumerable:!1,writable:!1,configurable:!1})}get ontoolchange(){return this.#n}set ontoolchange(e){let t=typeof e==`function`?e:null;if(t===null){this.#n=null,super.removeEventListener(`toolchange`,this.#r);return}this.#n===null&&super.addEventListener(`toolchange`,this.#r),this.#n=t}async registerTool(e,t={}){g(this.#a);let n=t?.signal,r=Ee(e,this.#e);if(n?.throwIfAborted(),h(t?.exposedTo),n?.throwIfAborted(),t?.exposedTo?.length)throw new this.#i(`Cross-document tool exposure requires native WebMCP`,`NotSupportedError`);if(this.#e.set(r.name,r),n){let e=()=>{this.#o(r.name,r)&&this.#c()};r[H]=n,r[U]=e,n.addEventListener(`abort`,e,{once:!0})}if(await this.#c(),n?.aborted)throw n.reason}async getTools(e={}){if(g(this.#a),h(e?.fromOrigins),e?.fromOrigins?.length)throw new this.#i(`Cross-document tool discovery requires native WebMCP`,`NotSupportedError`);let t=[...this.#e.values()].map(e=>{let t=e[V],n=t===void 0?void 0:JSON.parse(t);return{name:e.name,title:e.title??``,description:e.description,...r(n)?{inputSchema:n}:{},origin:q(),window:globalThis.window,...e.annotations?{annotations:u(e.annotations)}:{}}}).sort((e,t)=>e.name<t.name?-1:+(e.name>t.name));return await new Promise(e=>setTimeout(e,0)),t}async executeTool(e,t,n={}){if(g(this.#a),typeof e!=`object`||!e)throw TypeError(`RegisteredTool must be an object`);for(let t of[`name`,`description`,`window`,`origin`])if(!(t in e))throw TypeError(`RegisteredTool.${t} is required`);if(te(e.origin),e.window!==globalThis.window||e.origin!==q())throw o(`Tool not found: ${e.name}`);return this.#s(e.name,t,n)}static getTestingShim(e){return e.#t??=new Te(e),e.#t}static getToolInfos(e){return[...e.#e.values()].map(e=>({name:e.name,description:e.description,...e[V]===void 0?{}:{inputSchema:e[V]}}))}static executeToolForTesting(e,t,n,r){return g(e.#a),e.#s(t,n,r)}static dispose(e){for(let t of e.#e.keys())e.#o(t);e.ontoolchange=null,e.#t?.dispose()}#o(e,t){let n=this.#e.get(e);if(!n||t&&n!==t)return!1;let r=n[H],i=n[U];return r&&i&&r.removeEventListener(`abort`,i),this.#e.delete(e)}async#s(e,t,n){n?.signal?.throwIfAborted();let r=this.#e.get(e);if(!r)throw o(`Tool not found: ${e}`);let i=d(t);if(n?.signal?.throwIfAborted(),r[H]?.aborted)throw o(`Tool unregistered`);let a;try{let e=r[H];a=await p(p(Promise.resolve(r.execute(i)),e,()=>o(`Tool unregistered`)),n?.signal)}catch(e){throw n?.signal?.aborted&&e===n.signal.reason||r[H]?.aborted?e:s(e)}return f(a)}async#c(){await new Promise(e=>setTimeout(e,0)),this.dispatchEvent(new Event(`toolchange`)),this.#t?.dispatchToolChange()}};let X=function(){throw TypeError(`Illegal constructor`)};Object.defineProperty(X,`name`,{value:`ModelContext`}),Object.defineProperty(X,`prototype`,{value:Y.prototype,writable:!1}),Object.setPrototypeOf(X,EventTarget),Object.defineProperty(Y.prototype,`constructor`,{configurable:!0,writable:!0,value:X}),Object.defineProperty(Y.prototype,Symbol.toStringTag,{configurable:!0,value:`ModelContext`});for(let e of[`registerTool`,`getTools`,`executeTool`,`ontoolchange`]){let t=Object.getOwnPropertyDescriptor(Y.prototype,e);t&&Object.defineProperty(Y.prototype,e,{...t,enumerable:!0})}var Te=class extends EventTarget{_ontoolchange=null;ontoolchangeListener=e=>{this._ontoolchange?.call(this,e)};#e;constructor(e){super(),this.#e=e}listTools(){return Y.getToolInfos(this.#e)}executeTool(e,t,n){return Y.executeToolForTesting(this.#e,e,t,n)}get ontoolchange(){return this._ontoolchange}set ontoolchange(e){let t=typeof e==`function`?e:null;if(t===null){this._ontoolchange=null,super.removeEventListener(`toolchange`,this.ontoolchangeListener);return}this._ontoolchange===null&&super.addEventListener(`toolchange`,this.ontoolchangeListener),this._ontoolchange=t}dispatchToolChange(){this.dispatchEvent(new Event(`toolchange`))}dispose(){this.ontoolchange=null}};function Ee(e,t){if(!e||typeof e!=`object`)throw TypeError(`registerTool(tool) requires a tool object`);let n=a(e);if(l(n),t.has(n.name))throw c(`Tool already registered: ${n.name}`);let r=n.inputSchema===void 0?void 0:ne(n.inputSchema);return{name:n.name,...n.title===void 0?{}:{title:n.title},description:n.description,...n.inputSchema===void 0?{}:{inputSchema:n.inputSchema},...n.annotations===void 0?{}:{annotations:n.annotations},execute:e=>Reflect.apply(n.execute,void 0,[e]),...r===void 0?{}:{[V]:r}}}let Z=!1,De=new WeakMap,{modelContext:Oe}={modelContext(){if(!(this instanceof Document))throw TypeError(`Illegal invocation`);return De.get(this)}};Object.defineProperty(Oe,`name`,{value:`get modelContext`});function ke(e,t){De.set(e,t),!Object.hasOwn(Document.prototype,`modelContext`)&&J(Document.prototype,`modelContext`,{configurable:!0,enumerable:!0,get:Oe})}function Ae(e,t){J(e,`modelContext`,{configurable:!0,enumerable:!0,get(){return Z||(Z=!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 je(){let e=SubmitEvent.prototype;`agentInvoked`in e||J(e,`agentInvoked`,{configurable:!0,enumerable:!0,get(){return b(this)}}),`respondWith`in e||J(e,`respondWith`,{configurable:!0,enumerable:!0,writable:!0,value(e){re(this,e)}})}function Q(e){if(globalThis.isSecureContext===!1)return;let t=typeof navigator>`u`?null:navigator,n=typeof document>`u`?null:document;if(!t||!n||typeof window>`u`||n.modelContext)return;let r=t.modelContext;if(W.length>0&&$(),r){ke(n,r);return}let i=Object.getOwnPropertyDescriptor(window,`ModelContext`);if(i&&!i.configurable){if(!Object.is(Reflect.get(window,`ModelContext`),X))throw TypeError(`Cannot install ModelContext over a non-configurable global`)}else J(window,`ModelContext`,{configurable:!0,enumerable:!1,writable:!0,value:X});let a=new Y(n);G=a,ke(n,a),Z=!1,Ae(t,a),je(),e?.installTestingShim&&!t.modelContextTesting&&J(t,`modelContextTesting`,{configurable:!0,enumerable:!0,writable:!1,value:Y.getTestingShim(a)}),K=we(n,a)}function $(){K?.(),K=null,G&&Y.dispose(G),G=null;for(let{target:e,key:t,previous:n}of[...W].reverse())n?Object.defineProperty(e,t,n):Reflect.deleteProperty(e,t);W.length=0,Z=!1}try{Q(window.__webMCPPolyfillOptions)}catch(e){console.error(`[WebMCPPolyfill] Auto-initialization failed:`,e)}return e.cleanupWebMCPPolyfill=$,e.initializeWebMCPPolyfill=Q,e})({});