@ractive-ch/tab-mcp-client 0.14.0 → 0.16.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 +538 -126
- package/always-allowed.d.ts +25 -6
- package/cdn/confirm-y30cx7e1.min.js +4 -0
- package/cdn/confirm-y30cx7e1.min.js.map +10 -0
- package/cdn/connect-bbhj2y7w.min.js +6 -0
- package/cdn/connect-bbhj2y7w.min.js.map +12 -0
- package/cdn/connection-0y7ngtq7.min.js +17 -0
- package/cdn/connection-0y7ngtq7.min.js.map +22 -0
- package/cdn/index-vt5zk9me.min.js +91 -0
- package/cdn/index-vt5zk9me.min.js.map +13 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +6 -6
- package/confirm-fgnjgd08.js +263 -0
- package/confirm-fgnjgd08.js.map +10 -0
- package/confirm.d.ts +54 -0
- package/connect-8jpb0k29.js +484 -0
- package/connect-8jpb0k29.js.map +10 -0
- package/connect.d.ts +40 -0
- package/{connection-eqsag07j.js → connection-1d8rxgbq.js} +515 -242
- package/connection-1d8rxgbq.js.map +16 -0
- package/connection.d.ts +9 -9
- package/dialog.d.ts +83 -0
- package/{index-nmn1j689.js → index-5jyqehpk.js} +14 -10
- package/index-5jyqehpk.js.map +11 -0
- package/index-jnz7w9xa.js +392 -0
- package/index-jnz7w9xa.js.map +12 -0
- package/index.d.ts +1 -1
- package/index.js +285 -244
- package/index.js.map +6 -6
- package/mapping.d.ts +37 -4
- package/mcp.d.ts +23 -8
- package/package.json +5 -1
- package/react.d.ts +13 -12
- package/react.js +20 -14
- package/react.js.map +3 -3
- package/registry.d.ts +12 -5
- package/secret.d.ts +5 -2
- package/serve.d.ts +68 -0
- package/setup.d.ts +15 -25
- package/setup.js +1 -1
- package/strings.d.ts +107 -0
- package/tab-mcp.d.ts +76 -36
- package/tunnel.d.ts +74 -0
- package/tunnel.js +263 -0
- package/tunnel.js.map +10 -0
- package/types.d.ts +206 -73
- package/webmcp.d.ts +13 -18
- package/cdn/connection-dweyrdbn.min.js +0 -12
- package/cdn/connection-dweyrdbn.min.js.map +0 -21
- package/cdn/ui-5zecjy7s.min.js +0 -86
- package/cdn/ui-5zecjy7s.min.js.map +0 -14
- package/connection-eqsag07j.js.map +0 -15
- package/index-nmn1j689.js.map +0 -11
- package/ui-4qv8d1a3.js +0 -781
- package/ui-4qv8d1a3.js.map +0 -11
- package/ui.d.ts +0 -83
package/types.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Public types of `@ractive-ch/tab-mcp-client`. Self-contained on purpose: the
|
|
3
3
|
* published declarations must not import from other workspace packages.
|
|
4
4
|
*/
|
|
5
|
+
import type { DialogStrings } from "./strings.js";
|
|
6
|
+
export type { DialogStrings };
|
|
5
7
|
/** A JSON Schema document (draft 2020-12) describing a tool's input object. */
|
|
6
8
|
export type JsonSchema = {
|
|
7
9
|
[key: string]: unknown;
|
|
@@ -45,8 +47,77 @@ export interface RelayClient {
|
|
|
45
47
|
export interface WebMcpClient {
|
|
46
48
|
kind: "webmcp";
|
|
47
49
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* This site's own assistant, which the page serves its tools to over a port
|
|
52
|
+
* (`serve`). Not paired: the page chose who holds the other end of the port,
|
|
53
|
+
* and `id` and `name` are what the page said in `serve`.
|
|
54
|
+
*/
|
|
55
|
+
export interface LocalClient {
|
|
56
|
+
kind: "local";
|
|
57
|
+
/** `ServeOptions.client.id`. */
|
|
58
|
+
id: string;
|
|
59
|
+
/** `ServeOptions.client.name`. */
|
|
60
|
+
name?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Who calls a tool (`kind`): an AI app through the relay, an agent in the
|
|
64
|
+
* browser, or this site's own assistant over a port.
|
|
65
|
+
*/
|
|
66
|
+
export type ToolCallClient = RelayClient | WebMcpClient | LocalClient;
|
|
67
|
+
/**
|
|
68
|
+
* What `serve` talks over: a `MessagePort`, or an object of your own around
|
|
69
|
+
* another channel. The messages are plain objects (`docs/protocol.md`, "The
|
|
70
|
+
* tunnel without a relay"); `serve` sets `onmessage`.
|
|
71
|
+
*/
|
|
72
|
+
export interface TunnelPort {
|
|
73
|
+
postMessage(message: unknown): void;
|
|
74
|
+
onmessage: TunnelPortHandler | null;
|
|
75
|
+
}
|
|
76
|
+
/** `TunnelPort.onmessage` (declared as a method, so that a `MessagePort` fits). */
|
|
77
|
+
export type TunnelPortHandler = {
|
|
78
|
+
handler(event: {
|
|
79
|
+
data: unknown;
|
|
80
|
+
}): void;
|
|
81
|
+
}["handler"];
|
|
82
|
+
/** Options of `serve`. */
|
|
83
|
+
export interface ServeOptions {
|
|
84
|
+
/** Who is on the other end: shown in confirmations, passed to `execute` and the events. */
|
|
85
|
+
client: {
|
|
86
|
+
id: string;
|
|
87
|
+
name?: string;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Approves the consequential tool calls that come through this port, in
|
|
91
|
+
* place of `TabMcpOptions.onConfirm` and the library's dialog, for
|
|
92
|
+
* example as a question in the site's own chat. Same answers as
|
|
93
|
+
* `onConfirm`; a throw is a refusal. `request.signal` aborts when the call
|
|
94
|
+
* is cancelled, times out or the serve closes. The answer must come from
|
|
95
|
+
* the user: never let the other end of the port answer it, since that is
|
|
96
|
+
* the caller that wants the tool to run. Calls through the relay and
|
|
97
|
+
* WebMCP keep the page's `onConfirm` or dialog.
|
|
98
|
+
*/
|
|
99
|
+
onConfirm?: ConfirmHandler;
|
|
100
|
+
/**
|
|
101
|
+
* How long one request may take until its answer has ended, in
|
|
102
|
+
* milliseconds; 300000 by default, as `createTunnelFetch`, below 2^31. On
|
|
103
|
+
* expiry the call is aborted (`execute`'s signal), `toolcallend` says
|
|
104
|
+
* `cancelled`, a late answer is dropped, and the other end gets the
|
|
105
|
+
* JSON-RPC error `-31002`. A `subscriptions/listen` stream is not limited.
|
|
106
|
+
*/
|
|
107
|
+
requestTimeoutMs?: number;
|
|
108
|
+
/** Aborting it stops serving: calls in flight are aborted, the port is let go. */
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
/**
|
|
111
|
+
* The largest piece of a response body in one message, in characters
|
|
112
|
+
* (UTF-16 units); 65536 by default, at least 64. Longer bodies are streamed.
|
|
113
|
+
*/
|
|
114
|
+
maxChunk?: number;
|
|
115
|
+
}
|
|
116
|
+
/** What `serve` resolves with. */
|
|
117
|
+
export interface ServeHandle {
|
|
118
|
+
/** Stop serving this port: calls in flight are aborted, the port is let go. */
|
|
119
|
+
close(): void;
|
|
120
|
+
}
|
|
50
121
|
/** Second argument of `execute`. */
|
|
51
122
|
export interface ToolExecuteOptions {
|
|
52
123
|
/**
|
|
@@ -54,7 +125,7 @@ export interface ToolExecuteOptions {
|
|
|
54
125
|
* (a WebMCP call: when the browser cancels it).
|
|
55
126
|
*/
|
|
56
127
|
signal: AbortSignal;
|
|
57
|
-
/** Who is calling: `client.kind` is `"relay"` or `"
|
|
128
|
+
/** Who is calling: `client.kind` is `"relay"`, `"webmcp"` or `"local"`. */
|
|
58
129
|
client: ToolCallClient;
|
|
59
130
|
}
|
|
60
131
|
/**
|
|
@@ -70,22 +141,41 @@ export interface Tool<Input extends object = Record<string, unknown>> {
|
|
|
70
141
|
description: string;
|
|
71
142
|
/** JSON Schema of the input object; defaults to `{ "type": "object" }`. */
|
|
72
143
|
inputSchema?: JsonSchema;
|
|
144
|
+
/**
|
|
145
|
+
* JSON Schema of the result object (`"type": "object"`), listed to AI apps
|
|
146
|
+
* and passed on to WebMCP. Not checked by the library. MCP wants every
|
|
147
|
+
* result of such a tool to have `structuredContent` that matches it, so
|
|
148
|
+
* `execute` should return a plain object (DEC-023), not a string.
|
|
149
|
+
*/
|
|
150
|
+
outputSchema?: JsonSchema;
|
|
73
151
|
/** Runs the tool. Its return value becomes the result (DEC-023). */
|
|
74
152
|
execute: (input: Input, options: ToolExecuteOptions) => unknown;
|
|
75
153
|
annotations?: ToolAnnotations;
|
|
76
154
|
}
|
|
155
|
+
/** A kind of caller (`ToolCallClient.kind`), for `RegisterToolOptions.callers`. */
|
|
156
|
+
export type ToolCaller = ToolCallClient["kind"];
|
|
77
157
|
/** Options of `registerTool`. */
|
|
78
158
|
export interface RegisterToolOptions {
|
|
79
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Aborting it unregisters the tool. Already aborted: `registerTool`
|
|
161
|
+
* rejects with its reason and registers nothing (as WebMCP).
|
|
162
|
+
*/
|
|
80
163
|
signal?: AbortSignal;
|
|
81
164
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
165
|
+
* Which callers see the tool: `"relay"` (AI apps through the relay),
|
|
166
|
+
* `"local"` (this site's own assistant over `serve`), `"webmcp"` (agents
|
|
167
|
+
* in the browser, with `TabMcpOptions.webmcp` on). Others neither list nor
|
|
168
|
+
* call it: for them it does not exist. By default all of them, except
|
|
169
|
+
* that a consequential tool (`consequentialHint` or `destructiveHint`)
|
|
170
|
+
* goes to WebMCP only when `"webmcp"` is listed: an agent that drives
|
|
171
|
+
* this tab can click Allow in the page's confirmation itself.
|
|
172
|
+
*/
|
|
173
|
+
callers?: readonly ToolCaller[];
|
|
174
|
+
/**
|
|
175
|
+
* WebMCP's origins of other documents in this tab that may see the tool:
|
|
176
|
+
* passed on to the native `registerTool` of a mirrored tool, which checks
|
|
177
|
+
* it (an invalid list only warns). No effect on AI apps.
|
|
86
178
|
*/
|
|
87
|
-
webmcp?: boolean;
|
|
88
|
-
/** WebMCP's cross-document exposure; ignored by tab-mcp. */
|
|
89
179
|
exposedTo?: string[];
|
|
90
180
|
}
|
|
91
181
|
/** An icon the AI app may show for the page (MCP `Icon`). */
|
|
@@ -114,6 +204,48 @@ export interface ServerInfo {
|
|
|
114
204
|
/** Instructions for the model, e.g. how the tools fit together. */
|
|
115
205
|
instructions?: string;
|
|
116
206
|
}
|
|
207
|
+
/** A part of a {@link SetupStep}'s note: plain text, or code to show as code. */
|
|
208
|
+
export type SetupNotePart = {
|
|
209
|
+
text: string;
|
|
210
|
+
} | {
|
|
211
|
+
code: string;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* How to add the page's address to one AI app, as the connect dialog shows it
|
|
215
|
+
* under "How do I add it?". All strings are plain text.
|
|
216
|
+
*/
|
|
217
|
+
export interface SetupStep {
|
|
218
|
+
/** The app's name as shown, such as "Claude Code". */
|
|
219
|
+
app: string;
|
|
220
|
+
/** What to do, a sentence or two. "Run:" when `command` follows. */
|
|
221
|
+
text: string;
|
|
222
|
+
/** Commands to run in a terminal, one per line, shown with a Copy button. */
|
|
223
|
+
command?: string;
|
|
224
|
+
/** Shown after the command (or the text): text and code, in order. */
|
|
225
|
+
note?: SetupNotePart[];
|
|
226
|
+
}
|
|
227
|
+
/** Options of the library's dialogs (`TabMcpOptions.ui`). */
|
|
228
|
+
export interface DialogOptions {
|
|
229
|
+
/**
|
|
230
|
+
* Texts of the dialogs, key by key; the rest stay English. The keys and
|
|
231
|
+
* the English texts are in `src/strings.ts`; `{name}` placeholders are
|
|
232
|
+
* filled in. Set `lang` and `dir` with the texts' language.
|
|
233
|
+
*/
|
|
234
|
+
strings?: Partial<DialogStrings>;
|
|
235
|
+
/** The help in the connect dialog ("How do I add it?"). */
|
|
236
|
+
setup?: {
|
|
237
|
+
/**
|
|
238
|
+
* The link at its end; default the guide on ractive.ch, `null` for none
|
|
239
|
+
* (then pass `instructions` too: the default steps refer to the guide).
|
|
240
|
+
*/
|
|
241
|
+
guide?: string | null;
|
|
242
|
+
/**
|
|
243
|
+
* The steps per AI app for the page's `server.name` and address;
|
|
244
|
+
* default `setupInstructions` of `@ractive-ch/tab-mcp-client/setup`.
|
|
245
|
+
*/
|
|
246
|
+
instructions?: (serverName: string, address: string) => SetupStep[];
|
|
247
|
+
};
|
|
248
|
+
}
|
|
117
249
|
/** A consequential tool call waiting for the user's approval. */
|
|
118
250
|
export interface ConfirmRequest {
|
|
119
251
|
tool: {
|
|
@@ -140,8 +272,13 @@ export interface SecretStorage {
|
|
|
140
272
|
setItem(key: string, value: string): void;
|
|
141
273
|
}
|
|
142
274
|
export interface TabMcpOptions {
|
|
143
|
-
/**
|
|
144
|
-
|
|
275
|
+
/**
|
|
276
|
+
* The relay, e.g. `https://relay.example` or `wss://relay.example`.
|
|
277
|
+
* Without one the page offers its tools only through `serve` and WebMCP:
|
|
278
|
+
* `connect()`, `showConnectDialog()` and `newAddress()` reject, and no
|
|
279
|
+
* address secret is read or written.
|
|
280
|
+
*/
|
|
281
|
+
relay?: string;
|
|
145
282
|
/** Name, version and instructions of the page's MCP server. */
|
|
146
283
|
server: ServerInfo;
|
|
147
284
|
/** The page's app name (e.g. `saturnus`), shown when an AI app pairs; at most 64 characters. */
|
|
@@ -149,20 +286,16 @@ export interface TabMcpOptions {
|
|
|
149
286
|
/** Approves consequential tool calls; default: a dialog in the page. */
|
|
150
287
|
onConfirm?: ConfirmHandler;
|
|
151
288
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Offer "Always allow" in the default confirmation: it lets a tool run
|
|
160
|
-
* without asking for one AI app until the page is reloaded or the app is
|
|
161
|
-
* disconnected. Off by default (DEC-096): the confirmation then shows only
|
|
162
|
-
* "Don't allow" and "Allow", and every call asks. Turn it on only for
|
|
163
|
-
* tools whose calls the user does not need to check one by one.
|
|
289
|
+
* Offer "Allow until reload" in the default confirmation: it lets a tool
|
|
290
|
+
* run without asking for one AI app, with any arguments, until the page
|
|
291
|
+
* is reloaded or the app is disconnected; the connect dialog lists it
|
|
292
|
+
* with a reset. Off by default (DEC-096): the confirmation then shows
|
|
293
|
+
* only "Don't allow" and "Allow", and every call asks. Turn it on only
|
|
294
|
+
* for tools whose calls the user does not need to check one by one.
|
|
164
295
|
*/
|
|
165
296
|
alwaysAllow?: boolean;
|
|
297
|
+
/** Texts and help of the library's dialogs. */
|
|
298
|
+
ui?: DialogOptions;
|
|
166
299
|
/**
|
|
167
300
|
* Where the address secret lives; default `localStorage`. `null` keeps it
|
|
168
301
|
* only for the page's lifetime (a new address on every visit).
|
|
@@ -184,39 +317,26 @@ export interface TabMcpOptions {
|
|
|
184
317
|
* and by `refreshIdentity()`; only for relays whose site pairs by `oidc`.
|
|
185
318
|
*/
|
|
186
319
|
identityAssertion?: IdentityAssertionHandler;
|
|
187
|
-
/**
|
|
188
|
-
* How long to wait for an assertion and the relay's answer to it, from
|
|
189
|
-
* when `identityAssertion` is asked, before `identity` goes back to
|
|
190
|
-
* `none`, in milliseconds; default 15000.
|
|
191
|
-
*/
|
|
192
|
-
identityTimeoutMs?: number;
|
|
193
320
|
/**
|
|
194
321
|
* Connect again by itself after the connection broke (reason `network`,
|
|
195
|
-
* `heartbeat` or `shutdown`): after
|
|
196
|
-
*
|
|
197
|
-
* network returns. On by default;
|
|
322
|
+
* `heartbeat` or `shutdown`; `state` is `reconnecting` meanwhile): after
|
|
323
|
+
* about 5, 10, 20 and 40 seconds, then every 60 seconds, and at once when
|
|
324
|
+
* the tab comes back to the front or the network returns. On by default;
|
|
325
|
+
* `false` leaves it to the page.
|
|
198
326
|
*/
|
|
199
|
-
reconnect?: boolean
|
|
327
|
+
reconnect?: boolean;
|
|
200
328
|
/**
|
|
201
329
|
* Also register the tools with the browser's own WebMCP
|
|
202
330
|
* (`document.modelContext.registerTool()`), where it has it, so that agents
|
|
203
331
|
* in the browser can call them, without pairing. Off by default. Tools
|
|
204
|
-
* marked `consequentialHint` are left out unless
|
|
205
|
-
* `
|
|
206
|
-
* page's confirmation itself. A failed native
|
|
207
|
-
* the console.
|
|
332
|
+
* marked `consequentialHint` or `destructiveHint` are left out unless
|
|
333
|
+
* their `callers` list `"webmcp"`: an agent that drives this tab can
|
|
334
|
+
* click Allow in the page's confirmation itself. A failed native
|
|
335
|
+
* registration only warns in the console.
|
|
208
336
|
*/
|
|
209
337
|
webmcp?: boolean;
|
|
210
338
|
}
|
|
211
|
-
/**
|
|
212
|
-
export interface ReconnectOptions {
|
|
213
|
-
/**
|
|
214
|
-
* The waits before each attempt in milliseconds; the last one repeats.
|
|
215
|
-
* Default `[5000, 10000, 20000, 40000, 60000]`.
|
|
216
|
-
*/
|
|
217
|
-
delaysMs?: readonly number[];
|
|
218
|
-
}
|
|
219
|
-
/** The library is reconnecting by itself (`reconnecting`). */
|
|
339
|
+
/** The library is reconnecting by itself (`state` is `reconnecting`). */
|
|
220
340
|
export interface ReconnectingInfo {
|
|
221
341
|
/** Why the connection ended. */
|
|
222
342
|
reason: DisconnectReason;
|
|
@@ -299,7 +419,12 @@ export interface ConnectOptions {
|
|
|
299
419
|
*/
|
|
300
420
|
resume?: boolean;
|
|
301
421
|
}
|
|
302
|
-
|
|
422
|
+
/**
|
|
423
|
+
* The connection to the relay. `reconnecting`: it broke, and the library
|
|
424
|
+
* connects again by itself (waiting for the next attempt or making it;
|
|
425
|
+
* `TabMcp.reconnecting` says which attempt and when).
|
|
426
|
+
*/
|
|
427
|
+
export type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
303
428
|
/** Why a session ended. */
|
|
304
429
|
export type DisconnectReason =
|
|
305
430
|
/** `disconnect()` was called. */
|
|
@@ -312,7 +437,10 @@ export type DisconnectReason =
|
|
|
312
437
|
| "expired"
|
|
313
438
|
/** No AI app used the tools for a long time. */
|
|
314
439
|
| "idle"
|
|
315
|
-
/**
|
|
440
|
+
/**
|
|
441
|
+
* The relay is shutting down or restarting (also close codes 1001, 1011,
|
|
442
|
+
* 1012 and 1013, which a proxy in front of it sends).
|
|
443
|
+
*/
|
|
316
444
|
| "shutdown"
|
|
317
445
|
/** The connection stopped answering. */
|
|
318
446
|
| "heartbeat"
|
|
@@ -322,10 +450,15 @@ export type DisconnectReason =
|
|
|
322
450
|
| "closed"
|
|
323
451
|
/** The network connection broke. */
|
|
324
452
|
| "network";
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
453
|
+
/** The `statechange` event. */
|
|
454
|
+
export interface StateChangeDetail {
|
|
455
|
+
state: ConnectionState;
|
|
456
|
+
/**
|
|
457
|
+
* Why it ended: on the change from `connected` (to `disconnected`, or to
|
|
458
|
+
* `reconnecting` when the connection broke), and when `disconnect()` or
|
|
459
|
+
* `newAddress()` ends connecting or reconnecting (`user`, `new_address`).
|
|
460
|
+
*/
|
|
461
|
+
reason?: DisconnectReason;
|
|
329
462
|
}
|
|
330
463
|
/** The `replaced` event: who took over the page's address. */
|
|
331
464
|
export interface ReplacedDetail {
|
|
@@ -371,44 +504,44 @@ export interface ToolCallEnd {
|
|
|
371
504
|
result: ToolCallResult;
|
|
372
505
|
durationMs: number;
|
|
373
506
|
}
|
|
374
|
-
/**
|
|
507
|
+
/**
|
|
508
|
+
* Events of `TabMcp`. Every detail is an object; a change event names the
|
|
509
|
+
* new values like the properties they change (`grantschange` has `grants`,
|
|
510
|
+
* the value of `mcp.grants`), and a value that is gone is `undefined`.
|
|
511
|
+
*/
|
|
375
512
|
export interface TabMcpEventMap {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
513
|
+
/**
|
|
514
|
+
* `state` changed (`session` with it), or, while `reconnecting`, the next
|
|
515
|
+
* attempt was scheduled (`mcp.reconnecting`). A refusal that stops
|
|
516
|
+
* reconnecting comes as `error` just before the change to `disconnected`.
|
|
517
|
+
*/
|
|
518
|
+
statechange: CustomEvent<StateChangeDetail>;
|
|
381
519
|
/**
|
|
382
520
|
* Another tab, or a program with this page's address secret, took over
|
|
383
|
-
* the address. It follows `
|
|
384
|
-
* later while the library listens for a sibling tab. `sibling`
|
|
385
|
-
* probably was.
|
|
521
|
+
* the address. It follows the `statechange` with reason `replaced`, up to
|
|
522
|
+
* a second later while the library listens for a sibling tab. `sibling`
|
|
523
|
+
* says which it probably was.
|
|
386
524
|
*/
|
|
387
525
|
replaced: CustomEvent<ReplacedDetail>;
|
|
388
526
|
/** Something went wrong outside a pending promise (e.g. a relay error message). */
|
|
389
527
|
error: CustomEvent<{
|
|
390
528
|
error: Error;
|
|
391
529
|
}>;
|
|
392
|
-
/** A new pairing code, or `
|
|
393
|
-
pairingcode: CustomEvent<
|
|
530
|
+
/** A new pairing code, or `undefined` when there is none (any more). */
|
|
531
|
+
pairingcode: CustomEvent<{
|
|
532
|
+
pairingCode: PairingCode | undefined;
|
|
533
|
+
}>;
|
|
394
534
|
grantschange: CustomEvent<{
|
|
395
535
|
grants: readonly Grant[];
|
|
396
536
|
}>;
|
|
397
537
|
/** The relay accepted or refused the page's identity, or it was cleared. */
|
|
398
538
|
identitychange: CustomEvent<{
|
|
399
|
-
|
|
400
|
-
|
|
539
|
+
identity: IdentityState;
|
|
540
|
+
identityMessage: string | undefined;
|
|
401
541
|
}>;
|
|
402
542
|
toolschange: CustomEvent<{
|
|
403
543
|
tools: readonly string[];
|
|
404
544
|
}>;
|
|
405
|
-
/**
|
|
406
|
-
* Reconnecting by itself: the next attempt and when it starts, or `null`
|
|
407
|
-
* when it stopped (connected again, `disconnect()`, or the relay refused
|
|
408
|
-
* an attempt: then `error` says why just before, unless the attempt was
|
|
409
|
-
* the page's own `connect()`, whose promise rejects).
|
|
410
|
-
*/
|
|
411
|
-
reconnecting: CustomEvent<ReconnectingInfo | null>;
|
|
412
545
|
/** An AI app called a tool (before any confirmation). */
|
|
413
546
|
toolcall: CustomEvent<ToolCallStart>;
|
|
414
547
|
/** That call ended; also when the user declined it, did not answer, or the AI app cancelled it. */
|
package/webmcp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,
|
|
3
|
-
* DEC-119): with `webmcp: true`, each tool that is offered there is
|
|
4
|
-
* registered with `document.modelContext.registerTool()`, under its own
|
|
3
|
+
* DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is
|
|
4
|
+
* also registered with `document.modelContext.registerTool()`, under its own
|
|
5
5
|
* `AbortController`, aborted when the tool leaves the registry. Part of the
|
|
6
6
|
* core: only the detection, the registrations and the `<html>` attribute;
|
|
7
7
|
* a call loads the lazy chunk, which checks, confirms and runs it.
|
|
@@ -11,28 +11,23 @@ import type { RegisteredTool, ToolRegistry } from "./registry.js";
|
|
|
11
11
|
export interface ModelContext {
|
|
12
12
|
registerTool(tool: object, options: {
|
|
13
13
|
signal: AbortSignal;
|
|
14
|
+
exposedTo: string[] | undefined;
|
|
14
15
|
}): unknown;
|
|
15
16
|
}
|
|
16
17
|
/** Runs a call of a mirrored tool; `signal` is the browser's, if it gives one. */
|
|
17
18
|
export type WebMcpCall = (tool: RegisteredTool, input: unknown, signal: unknown) => Promise<unknown>;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
export declare function capture(): void;
|
|
24
|
-
/**
|
|
25
|
-
* The browser's own `ModelContext` of this document, through
|
|
26
|
-
* `Document.prototype`'s getter: never an own `document.modelContext` (a
|
|
27
|
-
* polyfill such as `@mcp-b/global`, or any page script). `undefined` without
|
|
28
|
-
* native WebMCP.
|
|
20
|
+
* The browser's own `ModelContext` of this document, read when a `TabMcp` is
|
|
21
|
+
* made, through `Document.prototype`'s getter: never an own
|
|
22
|
+
* `document.modelContext` (a polyfill such as `@mcp-b/global`, or any page
|
|
23
|
+
* script; DEC-115). `undefined` without native WebMCP or a document.
|
|
29
24
|
*/
|
|
30
25
|
export declare function nativeContext(): ModelContext | undefined;
|
|
31
26
|
/**
|
|
32
|
-
* Mirror `registry`'s tools
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
27
|
+
* Mirror `registry`'s tools into `context`, now and whenever the registry
|
|
28
|
+
* changes: those whose `callers` list `"webmcp"`, and without `callers` those
|
|
29
|
+
* not marked consequential, where MCP's `destructiveHint` counts as
|
|
30
|
+
* `consequentialHint` (DEC-143, DEC-165). Every failure of the native `registerTool()`
|
|
31
|
+
* stays here: warned once per name, the tool still offered through the relay.
|
|
37
32
|
*/
|
|
38
|
-
export declare function mirror(registry: ToolRegistry, context: ModelContext,
|
|
33
|
+
export declare function mirror(registry: ToolRegistry, context: ModelContext, call: WebMcpCall): void;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
var ht=/^(?:\d{1,4}x\d{1,4}|any)$/;function $t(e){let{src:t,mimeType:n,sizes:o,theme:s}=e;if(typeof t!=="string")return;let i=/^https?:/i.test(t)&&t.length<=2048,r=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!i&&!r)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let c=Array.isArray(o)?o.map((_)=>String(_).toLowerCase()).filter((_)=>ht.test(_)):[];if(c.length>0)a.sizes=c;if(s==="light"||s==="dark")a.theme=s;return a}function ve(e){let t=[];for(let n of e){let o=typeof n==="object"&&n!==null?$t(n):void 0;if(o!==void 0)t.push(o);if(t.length===8)break}return t}function qe(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return ve([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let o={src:n.href};if(n.type)o.mimeType=n.type;let s=n.getAttribute("sizes");if(s)o.sizes=s.trim().split(/\s+/);let i=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(i)o.theme=i[1]?.toLowerCase();return o}))}catch{return[]}}function ae(e,t){let n=typeof e;if(n!==typeof t)return!1;let o=Array.isArray(e),s=Array.isArray(t);if(o!==s)return!1;if(o){let i=e.length;if(i!==t.length)return!1;for(let r=0;r<i;r++)if(!ae(e[r],t[r]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(let c of i){if(!Object.prototype.hasOwnProperty.call(t,c))return!1;if(!ae(e[c],t[c]))return!1}return!0}return e===t}function J(e){return encodeURI(wt(e)).replace(/#/g,"%23")}function wt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var bt=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,xt=/^%[0-9A-Fa-f]{2}$/,Rt=/^[A-Za-z0-9._~-]$/;function kt(e){let t="";for(let n=0;n<e.length;){let o=e[n],s=e.slice(n,n+3);if(o==="%"&&xt.test(s)){let r=String.fromCharCode(parseInt(s.slice(1),16));t+=Rt.test(r)?r:s.toUpperCase(),n+=3;continue}let i=String.fromCodePoint(e.codePointAt(n));t+=bt.test(i)?i:encodeURIComponent(i),n+=i.length}return t}function we(e,t){let n=new URL(e,t.href);return n.hash=n.hash?kt(n.hash.slice(1)):"",n}var It={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},Tt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},vt={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},_t=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 ee(e,t=Object.create(null),n=_t,o=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let i=e.$id||e.id;if(i){let r=we(i,n);if(r.hash.length>1)t[r.href]=e;else if(r.hash="",o==="")n=r;else ee(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(o?"#"+o:"");if(t[s]!==void 0&&t[s]!==e)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let i=we(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:i.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let i=we(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:i.href})}if(e.$anchor){let i=we("#"+e.$anchor,n);t[i.href]=e}for(let i in e){if(vt[i])continue;let r=`${o}/${J(i)}`,a=e[i];if(Array.isArray(a)){if(It[i]){let c=a.length;for(let _=0;_<c;_++)ee(a[_],t,n,`${r}/${_}`)}}else if(Tt[i])for(let c in a)ee(a[c],t,n,`${r}/${J(c)}`);else ee(a,t,n,r)}return t}var St=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Mt=[0,31,28,31,30,31,30,31,31,30,31,30,31],At=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,ze=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i,Et=/^(?:[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,Ot=/^(?:(?:[^\x00-\x20\x7f"<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Ct=/^(?:(?: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,Pt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Nt=/^(?:\/(?:[^~/]|~0|~1)*)*$/,jt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,qt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,zt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Ht=(e)=>{let t=e.match(zt);if(!t)return!1;let n=t[1],o=t[2];if(!n||!o||n.length>64||o.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(o.startsWith("[")&&o.endsWith("]")){let s=o.slice(1,-1);if(/^ipv6:/i.test(s))return Je.test(s.slice(5));return He.test(s)}return ze.test(o)},He=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Je=/^((([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,Jt=(e)=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e);function K(e){return e.test.bind(e)}var _e={date:Ue,time:De.bind(void 0,!0),"date-time":Bt,duration:Jt,uri:Wt,"uri-reference":K(Et),"uri-template":K(Ot),url:K(Ct),email:Ht,hostname:K(ze),ipv4:K(He),ipv6:K(Je),regex:Kt,uuid:K(Pt),"json-pointer":K(Nt),"json-pointer-uri-fragment":K(jt),"relative-json-pointer":K(qt)};function Ut(e){return e%4===0&&(e%100!==0||e%400===0)}function Ue(e){let t=e.match(St);if(!t)return!1;let n=t[1],o=t[2],s=t[3];if(!n||!o||!s)return!1;let i=+n,r=+o,a=+s,c=r==2&&Ut(i)?29:Mt[r];return r>=1&&r<=12&&a>=1&&c!==void 0&&a<=c}function De(e,t){let n=t.match(At);if(!n)return!1;let o=n[1],s=n[2],i=n[3];if(!o||!s||!i)return!1;let r=+o,a=+s,c=+i,_=n[5],I=n[6],N=+(n[7]??0),B=+(n[8]??0);if(r>23||a>59||c>60||N>23||B>59||e&&_===void 0)return!1;if(c<60)return!0;let U=I==="+"?1:I==="-"?-1:0;return(r*60+a-U*(N*60+B)+1440)%1440===1439}var Dt=/t|\s/i;function Bt(e){let[t,n,o]=e.split(Dt);return t!==void 0&&n!==void 0&&o===void 0&&Ue(t)&&De(!0,n)}var Vt=/\/|:/,Gt=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[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 Wt(e){return Vt.test(e)&&Gt.test(e)}var Ft=/[^\\]\\Z/;function Kt(e){if(Ft.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function Be(e){let t=0,n=e.length,o=0,s;while(o<n)if(t++,s=e.charCodeAt(o++),s>=55296&&s<=56319&&o<n){if(s=e.charCodeAt(o),(s&64512)==56320)o++}return t}function se(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ve(e){let t=Math.abs(e).toString().split("e"),n=t[0],o=t[1]??"0",s=n.indexOf("."),i=s===-1?0:n.length-s-1;return[BigInt(n.replace(".","")),Number(o)-i]}function Yt(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,o]=Ve(e),[s,i]=Ve(t),r=o-i;if(r>=0)return n*10n**BigInt(r)%s===0n;return n%(s*10n**BigInt(-r))===0n}function E(e,t,n="2019-09",o=ee(t),s=!0,i=null,r="#",a="#",c=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:r,keyword:"false",keywordLocation:r,error:"False boolean schema."}]};let _=typeof e,I;switch(_){case"boolean":case"number":case"string":I=_;break;case"object":if(e===null)I="null";else if(Array.isArray(e))I="array";else I="object";break;default:throw Error(`Instances of "${_}" type are not supported.`)}let{$ref:N,$recursiveRef:B,$recursiveAnchor:U,type:C,const:G,enum:D,required:L,not:m,anyOf:y,allOf:T,oneOf:v,if:R,then:S,else:O,format:d,properties:k,patternProperties:b,additionalProperties:j,unevaluatedProperties:M,minProperties:z,maxProperties:H,propertyNames:W,dependentRequired:Z,dependentSchemas:V,dependencies:F,prefixItems:ce,items:ne,additionalItems:Ee,unevaluatedItems:Oe,contains:Ce,minContains:X,maxContains:Re,minItems:ke,maxItems:Ie,uniqueItems:yt,minimum:re,maximum:oe,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Te,minLength:ye,maxLength:ge,pattern:Pe,__absolute_ref__:he,__absolute_recursive_ref__:gt}=t,l=[];if(U===!0&&i===null)i=t;if(B==="#"){let w=i===null?o[gt]:i,p=`${a}/$recursiveRef`,x=E(e,i===null?t:i,n,o,s,w,r,p,c);if(!x.valid)l.push({instanceLocation:r,keyword:"$recursiveRef",keywordLocation:p,error:"A subschema had errors."},...x.errors)}if(N!==void 0){let p=o[he||N];if(p===void 0){let u=`Unresolved $ref "${N}".`;if(he&&he!==N)u+=` Absolute URI "${he}".`;throw u+=`
|
|
2
|
-
Known schemas:
|
|
3
|
-
- ${Object.keys(o).join(`
|
|
4
|
-
- `)}`,Error(u)}let x=`${a}/$ref`,f=E(e,p,n,o,s,i,r,x,c);if(!f.valid)l.push({instanceLocation:r,keyword:"$ref",keywordLocation:x,error:"A subschema had errors."},...f.errors);if(n==="4"||n==="7")return{valid:l.length===0,errors:l}}if(Array.isArray(C)){let w=C.length,p=!1;for(let x=0;x<w;x++)if(I===C[x]||C[x]==="integer"&&I==="number"&&e%1===0&&e===e){p=!0;break}if(!p)l.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${I}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(I!=="number"||e%1||e!==e)l.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${I}" is invalid. Expected "${C}".`})}else if(C!==void 0&&I!==C)l.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${I}" is invalid. Expected "${C}".`});if(G!==void 0){if(I==="object"||I==="array"){if(!ae(e,G))l.push({instanceLocation:r,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}else if(e!==G)l.push({instanceLocation:r,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}if(D!==void 0){if(I==="object"||I==="array"){if(!D.some((w)=>ae(e,w)))l.push({instanceLocation:r,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(D)}.`})}else if(!D.some((w)=>e===w))l.push({instanceLocation:r,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(D)}.`})}if(m!==void 0){let w=`${a}/not`;if(E(e,m,n,o,s,i,r,w).valid)l.push({instanceLocation:r,keyword:"not",keywordLocation:w,error:'Instance matched "not" schema.'})}let $e=[];if(y!==void 0){let w=`${a}/anyOf`,p=l.length,x=!1;for(let[f,u]of y.entries()){let h=Object.create(c),g=E(e,u,n,o,s,U===!0?i:null,r,`${w}/${f}`,h);if(l.push(...g.errors),x=x||g.valid,g.valid)$e.push(h)}if(x)l.length=p;else l.splice(p,0,{instanceLocation:r,keyword:"anyOf",keywordLocation:w,error:"Instance does not match any subschemas."})}if(T!==void 0){let w=`${a}/allOf`,p=l.length,x=!0;for(let[f,u]of T.entries()){let h=Object.create(c),g=E(e,u,n,o,s,U===!0?i:null,r,`${w}/${f}`,h);if(l.push(...g.errors),x=x&&g.valid,g.valid)$e.push(h)}if(x)l.length=p;else l.splice(p,0,{instanceLocation:r,keyword:"allOf",keywordLocation:w,error:"Instance does not match every subschema."})}if(v!==void 0){let w=`${a}/oneOf`,p=l.length,x=v.filter((f,u)=>{let h=Object.create(c),g=E(e,f,n,o,s,U===!0?i:null,r,`${w}/${u}`,h);if(l.push(...g.errors),g.valid)$e.push(h);return g.valid}).length;if(x===1)l.length=p;else l.splice(p,0,{instanceLocation:r,keyword:"oneOf",keywordLocation:w,error:`Instance does not match exactly one subschema (${x} matches).`})}if(I==="object"||I==="array")Object.assign(c,...$e);if(R!==void 0){let w=`${a}/if`,p=Object.create(null);if(E(e,R,n,o,s,i,r,w,p).valid){if(Object.assign(c,p),S!==void 0){let f=E(e,S,n,o,s,i,r,`${a}/then`,c);if(!f.valid)l.push({instanceLocation:r,keyword:"if",keywordLocation:w,error:'Instance does not match "then" schema.'},...f.errors)}}else if(O!==void 0){let f=E(e,O,n,o,s,i,r,`${a}/else`,c);if(!f.valid)l.push({instanceLocation:r,keyword:"if",keywordLocation:w,error:'Instance does not match "else" schema.'},...f.errors)}}if(I==="object"){if(L!==void 0){for(let f of L)if(!se(e,f))l.push({instanceLocation:r,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${f}".`})}let w=Object.keys(e);if(z!==void 0&&w.length<z)l.push({instanceLocation:r,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${z} properties.`});if(H!==void 0&&w.length>H)l.push({instanceLocation:r,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${H} properties.`});if(W!==void 0){let f=`${a}/propertyNames`;for(let u in e){let h=`${r}/${J(u)}`,g=E(u,W,n,o,s,i,h,f);if(!g.valid)l.push({instanceLocation:r,keyword:"propertyNames",keywordLocation:f,error:`Property name "${u}" does not match schema.`},...g.errors)}}if(Z!==void 0){let f=`${a}/dependantRequired`;for(let u in Z)if(se(e,u)){let h=Z[u];for(let g of h)if(!se(e,g))l.push({instanceLocation:r,keyword:"dependentRequired",keywordLocation:f,error:`Instance has "${u}" but does not have "${g}".`})}}if(V!==void 0)for(let[f,u]of Object.entries(V)){let h=`${a}/dependentSchemas`;if(se(e,f)){let g=E(e,u,n,o,s,i,r,`${h}/${J(f)}`,c);if(!g.valid)l.push({instanceLocation:r,keyword:"dependentSchemas",keywordLocation:h,error:`Instance has "${f}" but does not match dependant schema.`},...g.errors)}}if(F!==void 0){let f=`${a}/dependencies`;for(let u in F)if(se(e,u)){let h=F[u];if(Array.isArray(h)){for(let g of h)if(!se(e,g))l.push({instanceLocation:r,keyword:"dependencies",keywordLocation:f,error:`Instance has "${u}" but does not have "${g}".`})}else{let g=E(e,h,n,o,s,i,r,`${f}/${J(u)}`);if(!g.valid)l.push({instanceLocation:r,keyword:"dependencies",keywordLocation:f,error:`Instance has "${u}" but does not match dependant schema.`},...g.errors)}}}let p=Object.create(null),x=!1;if(k!==void 0){let f=`${a}/properties`;for(let[u,h]of Object.entries(k)){if(!se(e,u))continue;let g=`${r}/${J(u)}`,P=E(e[u],h,n,o,s,i,g,`${f}/${J(u)}`);if(p[u]=!0,P.valid)c[u]=!0;else if(x=s,l.push({instanceLocation:r,keyword:"properties",keywordLocation:f,error:`Property "${u}" does not match schema.`},...P.errors),x)break}}if(!x&&b!==void 0){let f=`${a}/patternProperties`;for(let[u,h]of Object.entries(b)){let g=new RegExp(u,"u");for(let P in e){if(!g.test(P))continue;let Ne=`${r}/${J(P)}`,je=E(e[P],h,n,o,s,i,Ne,`${f}/${J(u)}`);if(p[P]=!0,je.valid)c[P]=!0;else x=s,l.push({instanceLocation:r,keyword:"patternProperties",keywordLocation:f,error:`Property "${P}" matches pattern "${u}" but does not match associated schema.`},...je.errors)}}}if(!x&&j!==void 0){let f=`${a}/additionalProperties`;for(let u in e){if(p[u])continue;let h=`${r}/${J(u)}`,g=E(e[u],j,n,o,s,i,h,f);if(g.valid)c[u]=!0;else x=s,l.push({instanceLocation:r,keyword:"additionalProperties",keywordLocation:f,error:`Property "${u}" does not match additional properties schema.`},...g.errors)}}else if(!x&&M!==void 0){let f=`${a}/unevaluatedProperties`;for(let u in e)if(!c[u]){let h=`${r}/${J(u)}`,g=E(e[u],M,n,o,s,i,h,f);if(g.valid)c[u]=!0;else l.push({instanceLocation:r,keyword:"unevaluatedProperties",keywordLocation:f,error:`Property "${u}" does not match unevaluated properties schema.`},...g.errors)}}}else if(I==="array"){if(Ie!==void 0&&e.length>Ie)l.push({instanceLocation:r,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${Ie}).`});if(ke!==void 0&&e.length<ke)l.push({instanceLocation:r,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${ke}).`});let w=e.length,p=0,x=!1;if(ce!==void 0){let f=`${a}/prefixItems`,u=Math.min(ce.length,w);for(;p<u;p++){let h=E(e[p],ce[p],n,o,s,i,`${r}/${p}`,`${f}/${p}`);if(c[p]=!0,!h.valid){if(x=s,l.push({instanceLocation:r,keyword:"prefixItems",keywordLocation:f,error:"Items did not match schema."},...h.errors),x)break}}}if(ne!==void 0){let f=`${a}/items`;if(Array.isArray(ne)){let u=Math.min(ne.length,w);for(;p<u;p++){let h=E(e[p],ne[p],n,o,s,i,`${r}/${p}`,`${f}/${p}`);if(c[p]=!0,!h.valid){if(x=s,l.push({instanceLocation:r,keyword:"items",keywordLocation:f,error:"Items did not match schema."},...h.errors),x)break}}}else for(;p<w;p++){let u=E(e[p],ne,n,o,s,i,`${r}/${p}`,f);if(c[p]=!0,!u.valid){if(x=s,l.push({instanceLocation:r,keyword:"items",keywordLocation:f,error:"Items did not match schema."},...u.errors),x)break}}if(!x&&Ee!==void 0){let u=`${a}/additionalItems`;for(;p<w;p++){let h=E(e[p],Ee,n,o,s,i,`${r}/${p}`,u);if(c[p]=!0,!h.valid)x=s,l.push({instanceLocation:r,keyword:"additionalItems",keywordLocation:u,error:"Items did not match additional items schema."},...h.errors)}}}if(Ce!==void 0)if(w===0&&X===void 0)l.push({instanceLocation:r,keyword:"contains",keywordLocation:`${a}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(X!==void 0&&w<X)l.push({instanceLocation:r,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${w}) than minContains (${X}).`});else{let f=`${a}/contains`,u=l.length,h=0;for(let g=0;g<w;g++){let P=E(e[g],Ce,n,o,s,i,`${r}/${g}`,f);if(P.valid)c[g]=!0,h++;else l.push(...P.errors)}if(h>=(X||0))l.length=u;if(X===void 0&&h===0)l.splice(u,0,{instanceLocation:r,keyword:"contains",keywordLocation:f,error:"Array does not contain item matching schema."});else if(X!==void 0&&h<X)l.push({instanceLocation:r,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${X} items matching schema. Only ${h} items were found.`});else if(Re!==void 0&&h>Re)l.push({instanceLocation:r,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Re} items matching schema. ${h} items were found.`})}if(!x&&Oe!==void 0){let f=`${a}/unevaluatedItems`;for(p;p<w;p++){if(c[p])continue;let u=E(e[p],Oe,n,o,s,i,`${r}/${p}`,f);if(c[p]=!0,!u.valid)l.push({instanceLocation:r,keyword:"unevaluatedItems",keywordLocation:f,error:"Items did not match unevaluated items schema."},...u.errors)}}if(yt)for(let f=0;f<w;f++){let u=e[f],h=typeof u==="object"&&u!==null;for(let g=0;g<w;g++){if(f===g)continue;let P=e[g];if(u===P||h&&(typeof P==="object"&&P!==null)&&ae(u,P))l.push({instanceLocation:r,keyword:"uniqueItems",keywordLocation:`${a}/uniqueItems`,error:`Duplicate items at indexes ${f} and ${g}.`}),f=Number.MAX_SAFE_INTEGER,g=Number.MAX_SAFE_INTEGER}}}else if(I==="number"){if(n==="4"){if(re!==void 0&&(pe===!0&&e<=re||e<re))l.push({instanceLocation:r,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${re}.`});if(oe!==void 0&&(me===!0&&e>=oe||e>oe))l.push({instanceLocation:r,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${oe}.`})}else{if(re!==void 0&&e<re)l.push({instanceLocation:r,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${re}.`});if(oe!==void 0&&e>oe)l.push({instanceLocation:r,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${oe}.`});if(pe!==void 0&&e<=pe)l.push({instanceLocation:r,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)l.push({instanceLocation:r,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Te!==void 0){if(!Yt(e,Te))l.push({instanceLocation:r,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${Te}.`})}}else if(I==="string"){let w=ye===void 0&&ge===void 0?0:Be(e);if(ye!==void 0&&w<ye)l.push({instanceLocation:r,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${w} < ${ye}).`});if(ge!==void 0&&w>ge)l.push({instanceLocation:r,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${w} > ${ge}).`});if(Pe!==void 0&&!new RegExp(Pe,"u").test(e))l.push({instanceLocation:r,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(d!==void 0&&_e[d]&&!_e[d](e))l.push({instanceLocation:r,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${d}".`})}return{valid:l.length===0,errors:l}}var We="ch.ractive.tab-mcp/annotations",Zt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Xt=["destructiveHint","idempotentHint","openWorldHint"];function Fe(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let s of Xt){let i=e[s];if(i!==void 0)t[s]=i}let n={};for(let s of Zt){let i=e[s];if(i!==void 0)n[s]=i}let o={};if(Object.keys(t).length>0)o.annotations=t;if(Object.keys(n).length>0)o.meta=n;return o}function ue(e){return{content:[{type:"text",text:e}],isError:!0}}function Ge(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ke(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(Ge(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return ue("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]};if(Ge(e))n.structuredContent=e;return n}function Ye(e){let t=e instanceof Error?e.message:String(e);return ue(t||"The tool failed.")}var ie="2026-07-28",te="io.modelcontextprotocol/protocolVersion",be="io.modelcontextprotocol/clientCapabilities",Ze="io.modelcontextprotocol/clientInfo",Xe="io.modelcontextprotocol/serverInfo",Se="io.modelcontextprotocol/subscriptionId",Qt=-32020,Qe=-32022,Lt=0,Le=new WeakMap;function Me(e){let t=Le.get(e);if(t!==void 0)return t;let n=e.inputSchema,o;try{o=ee(n)}catch(i){let r=i instanceof Error?i.message:String(i);throw Error(r.split(`
|
|
5
|
-
`)[0])}for(let i of Object.values(o)){if(typeof i!=="object"||i.$ref===void 0)continue;let r=i.__absolute_ref__;if(o[r??i.$ref]===void 0)throw Error(`$ref ${JSON.stringify(i.$ref)} does not resolve`)}let s=(i)=>E(i,n,"2020-12",o,!1);return Le.set(e,s),s}function et(e,t,n=""){let o=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${o}${n}`)}function en(e){let t=[];for(let n of e.list())try{Me(n)}catch(o){e.remove(n),t.push(et(n.name,o,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Me(n)}catch(o){throw et(n.name,o)}}),t}function tt(e){try{return structuredClone(e)}catch{return e}}var tn=new TextEncoder;function Q(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ae(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function q(e,t,n,o,s){let i={code:n,message:o};if(s!==void 0)i.data=s;return Ae(e,{jsonrpc:"2.0",id:t,error:i})}function Y(e,t,n){return q(400,e,Qt,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function le(e){return tn.encode(`event: message
|
|
6
|
-
data: ${JSON.stringify(e)}
|
|
7
|
-
|
|
8
|
-
`)}var nt={"content-type":"text/event-stream","cache-control":"no-cache"};function nn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function rn(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),o=Uint8Array.from(n,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(o)}catch{return}}function on(e){if(!(te in e))return{key:te,problem:"missing"};if(!(be in e))return{key:be,problem:"missing"};if(typeof e[te]!=="string")return{key:te,problem:"expected a protocol version string"};if(!Q(e[be]))return{key:be,problem:"expected an object"};let t=e[Ze];if(t!==void 0&&!(Q(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ze,problem:"expected {name, version}"};return}function sn(e){let t=e.notifications;return Q(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function dn(e,t){let n;try{n=Me(e)(t)}catch(s){let i=s instanceof Error?s.message:String(s);return`The input schema of tool ${e.name} cannot be used: ${i}`}if(n.valid)return;let o=n.errors.filter((s)=>s.keyword!=="properties"&&s.keyword!=="$ref").map((s)=>`${s.instanceLocation} ${s.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${o||"the arguments do not match the schema"}`}async function rt(e,t,n,o,s){let i={id:++Lt,tool:t.name,arguments:tt(n),client:{...s}};if(t.title!==void 0)i.title=t.title;let r=Date.now();e.observe?.start(i);let a={outcome:"error",result:ue("Internal error")};try{a=await un(e,t,n,o,s)}finally{e.observe?.end({id:i.id,tool:t.name,client:{...s},outcome:a.outcome,result:tt(a.result),durationMs:Date.now()-r})}return a}var an="The user was asked and did not answer.";async function un(e,t,n,o,s){let i=(c,_,I)=>({outcome:c,result:ue(_),stop:I}),r=dn(t,n);if(r!==void 0)return i("error",r,"invalid");if(t.annotations.consequentialHint===!0){let c={tool:{name:t.name,description:t.description},arguments:n,client:s,signal:o};if(t.title!==void 0)c.tool.title=t.title;let _=!1;try{_=await e.confirm(c)}catch{_=!1}if(_!==!0){if(o.aborted)return i("cancelled","The user declined","cancelled");return _==="unanswered"?i("unanswered",an,"unanswered"):i("declined","The user declined","declined")}}if(o.aborted)return i("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return i("error","The tool is no longer available","gone");let a;try{let c=await t.execute(n,{signal:o,client:s});a={outcome:"ok",result:Ke(c),returned:{value:c}}}catch(c){a={outcome:"error",result:Ye(c)}}if(o.aborted)return{...a,outcome:"cancelled",stop:"cancelled"};if(a.result.isError===!0)a.outcome="error";return a}async function ot(e,t,n,o){let s=(a)=>({error:a}),i=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return s(i);if(!Q(n))return s("The input must be an object.");let r=await rt(e,t,n,o instanceof AbortSignal?o:new AbortController().signal,{kind:"webmcp"});if(r.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(r.stop==="declined")return s(`The user did not allow ${t.name} to run.`);if(r.stop==="unanswered")return s(`The user did not answer whether ${t.name} may run.`);if(r.stop==="gone")return s(i);if(r.result.isError===!0)return s(ln(r.result)||"The tool failed.");return r.returned?.value}function ln(e){return e.content.map((t)=>Q(t)&&t.type==="text"&&typeof t.text==="string"?t.text:"").filter((t)=>t!=="").join(`
|
|
9
|
-
`)}function st(e){let{tools:t,server:n}=e,o={name:n.name,version:n.version};if(n.title!==void 0)o.title=n.title;let s=ve(n.icons??[]),i=s.length>0?{...o,icons:s}:o,r=new Set,a=!1,c=(m={})=>({...m,[Xe]:o});function _(m,y,T=c()){return{jsonrpc:"2.0",id:m,result:{...y,resultType:"complete",_meta:T}}}function I(){return t.list().map((m)=>{let y={name:m.name};if(m.title!==void 0)y.title=m.title;y.description=m.description,y.inputSchema=m.inputSchema;let{annotations:T,meta:v}=Fe(m.annotations);if(T!==void 0)y.annotations=T;if(v!==void 0)y._meta={[We]:v};return y})}let N=(m)=>({kind:"invalid",message:m});async function B(m,y,T){let v=m.name;if(typeof v!=="string")return N("Invalid params: name must be a string");let R=t.get(v);if(R===void 0)return N(`Tool ${v} not found`);let S=m.arguments??{};if(!Q(S))return N("Invalid params: arguments must be an object");return{kind:"result",result:(await rt(e,R,S,y,e.client(T))).result}}function U(m,y,T,v){let R=new ReadableStream({start:(S)=>{let O=(d)=>{if(T.aborted)return;let k;try{k=le(d)}catch{k=le(_(m,ue("The tool returned a result that is not JSON.")))}try{S.enqueue(k),S.close()}catch{}};B(y,T,v).then((d)=>O(d.kind==="invalid"?{jsonrpc:"2.0",id:m,error:{code:-32602,message:d.message}}:_(m,d.result)),()=>O({jsonrpc:"2.0",id:m,error:{code:-32603,message:"Internal error"}}))}});return new Response(R,{status:200,headers:nt})}function C(m,y,T){let v=sn(y),R={jsonrpc:"2.0",id:m,result:{resultType:"complete",_meta:c({[Se]:m})}},S,O=new ReadableStream({start:(d)=>{if(d.enqueue(le({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:v,_meta:{[Se]:m}}})),Object.keys(v).length===0){d.enqueue(le(R)),d.close();return}let k={id:m,send:(b)=>{try{d.enqueue(le(b))}catch{r.delete(k)}},end:()=>{r.delete(k);try{d.enqueue(le(R)),d.close()}catch{}}};S=k,r.add(k),T.addEventListener("abort",()=>{r.delete(k);try{d.close()}catch{}})},cancel:()=>{if(S!==void 0)r.delete(S)}});return new Response(O,{status:200,headers:nt})}function G(m,y){if(Array.isArray(y))return q(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!Q(y)||y.jsonrpc!=="2.0")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:T,id:v}=y;if(typeof T!=="string")return"result"in y||"error"in y?q(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let R=m.headers.get("mcp-protocol-version"),S=m.headers.get("mcp-method"),O=Q(y.params)?y.params:{},d=Q(O._meta)?O._meta:void 0,k=d!==void 0&&te in d,b=typeof d?.[te]==="string"?d[te]:void 0,j=R!==null&&R>=ie;if(v===void 0){if(b!==void 0&&R!==null&&R!==b)return Y(null,R,`the notification envelope names protocol version ${b} but the MCP-Protocol-Version header names ${R}`);if((k||j)&&S!==null&&S!==T)return Y(null,S,`the notification body names method ${T} but the Mcp-Method header names ${S}`);return"notification"}if(typeof v!=="string"&&typeof v!=="number")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let M=v;if(!k||T==="initialize"&&(b===void 0||b<ie)){if(T==="initialize"){if(j)return Y(M,R,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let H=typeof O.protocolVersion==="string"?O.protocolVersion:void 0;return D(M,H)}if(j){let H=d===void 0?["_meta"]:[te];return q(400,M,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${R}, but the request is missing the required per-request envelope key(s): ${H.join(", ")}`,{envelope:{missing:H}})}return D(M,R??void 0)}let z=on(d);if(z!==void 0)return q(400,M,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${z.key}: ${z.problem}`,{envelope:z});if(R!==null&&b!==void 0&&R!==b)return Y(M,R,`the body envelope names protocol version ${b} but the MCP-Protocol-Version header names ${R}`);if(S!==null&&S!==T)return Y(M,S,`the body names method ${T} but the Mcp-Method header names ${S}`);if(b!==ie)return D(M,b);if(R===null)return Y(M,"(missing)",`the body envelope names protocol version ${b} but the required MCP-Protocol-Version header is absent`);if(S===null)return Y(M,"(missing)",`the body names method ${T} but the required Mcp-Method header is absent`);if(T==="tools/call"&&typeof O.name==="string"){let H=O.name,W=m.headers.get("mcp-name");if(W===null)return Y(M,"(missing)",`the body carries params.name="${H}" but the required Mcp-Name header is absent`);let Z=rn(W);if(Z===void 0)return Y(M,W,"the Mcp-Name header carries an invalid Base64 sentinel value");if(Z!==H)return Y(M,W,`the body carries params.name="${H}" but the Mcp-Name header names "${Z}"`)}return{id:M,method:T,params:O}}function D(m,y){return y===void 0?q(400,m,Qe,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):q(400,m,Qe,`Unsupported protocol version: ${y}`,{supported:[ie],requested:y})}async function L(m,y){if(m.method.toUpperCase()!=="POST")return q(405,null,-32000,"Method not allowed.");if(!nn(m.headers.get("content-type")))return q(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let T;try{T=JSON.parse(y.body??await m.text())}catch{return q(400,null,-32700,"Parse error: the request body is not valid JSON")}let v=G(m,T);if(v instanceof Response)return v;if(v==="notification")return new Response(null,{status:202});let{id:R,method:S,params:O}=v;switch(S){case"server/discover":{let d={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)d.instructions=n.instructions;return d.ttlMs=0,d.cacheScope="private",Ae(200,_(R,d,{[Xe]:i}))}case"tools/list":return Ae(200,_(R,{tools:I(),ttlMs:0,cacheScope:"private"}));case"tools/call":return U(R,O,m.signal,y.grant);case"subscriptions/listen":return C(R,O,m.signal);default:return q(404,R,-32601,"Method not found")}}return{handle:(m,y)=>L(m,y).catch(()=>q(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let m of[...r])m.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Se]:m.id}}})})},close(){for(let m of[...r])m.end()}}}var xe="tab-mcp.v1",fn=new Set(["start","used","locked","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var A=(e)=>typeof e==="string";function it(e){if(!fe(e)||!A(e.grantId)||!A(e.createdAt))return!1;let t=e.client;return fe(t)&&A(t.id)&&A(t.name)&&A(t.host)}function cn(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function pn(e){return fe(e)&&Object.values(e).every(A)}function dt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return A(t.sessionId)&&A(t.address)&&A(t.origin)&&A(t.expiresAt)&&cn(t.limits)&&Array.isArray(t.grants)&&t.grants.every(it)&&(t.appName===void 0||A(t.appName))&&(t.pairing===void 0||A(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:A(t.reason)?t.reason:""};case"http.request":return A(t.id)&&A(t.method)&&A(t.path)&&pn(t.headers)&&A(t.body)&&fe(t.grant)&&A(t.grant.grantId)&&A(t.grant.clientId)?t:void 0;case"http.cancel":return A(t.id)?t:void 0;case"pairing.code":{if(!A(t.code)||!A(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},o=t.reason;if(typeof o==="string"&&fn.has(o))n.reason=o;return n}case"grant.added":return it(t.grant)?t:void 0;case"grant.removed":return A(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:A(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return A(t.code)?t:void 0;default:return}}function mn(e){let t="",n=0,o=0;for(let s of e){n=n<<8|s,o+=8;while(o>=5)o-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>o&31];n&=(1<<o)-1}if(o>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-o&31];return t}async function yn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return mn(new Uint8Array(n))}catch{return}}function gn(e,t){if(t===void 0)return e;let n=new URL(e);return n.searchParams.set("a",t),n.href}function ft(e){return{tools:e.registry,confirm:(t)=>e.confirm(t),observe:{start:(t)=>e.toolCallStarted(t),end:(t)=>e.toolCallEnded(t)}}}function Zn(e,t,n,o){return ot(ft(e),t,n,o)}var hn=15000,at={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited",4009:"policy"},ut={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var $n=["content-type","cache-control"];function wn(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function bn(e){try{let t=JSON.parse(e);if(typeof t!=="object"||t===null||typeof t.type!=="string")return;return typeof t.id==="string"?{type:t.type,id:t.id}:{type:t.type}}catch{return}}var xn=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),ct=512,pt=6,mt=64,Rn=ct+pt*mt;function kn(e){let t=Math.floor((e-ct)/pt);return t>=mt?t:void 0}function*lt(e,t){let n=0;while(n<e.length){let o=Math.min(n+t,e.length),s=e.charCodeAt(o-1);if(o<e.length&&s>=55296&&s<=56319)o+=o-1>n?-1:1;yield e.slice(n,o),n=o}}var In=1e4,Tn=1000;function vn(e){let t,n=Number.NEGATIVE_INFINITY,o;try{if(e!==void 0&&typeof BroadcastChannel==="function")t=new BroadcastChannel(e),t.onmessage=(s)=>{if(s.data?.type!=="claimed")return;n=Date.now(),o?.()}}catch{t=void 0}return{claimed(){try{t?.postMessage({type:"claimed"})}catch{}},heard(){if(Date.now()-n<=In)return Promise.resolve(!0);if(t===void 0)return Promise.resolve(!1);return new Promise((s)=>{let i=setTimeout(()=>s(!1),Tn);o=()=>{clearTimeout(i),s(!0)}})},close(){t?.close()}}}function Xn(e,t,n,o=!1){let s=new WebSocket(t,xe),i=new Map,r="opening",a,c=65536,_,I=0,N=vn(e.tabs),B,U,C,G=new Promise((d,k)=>{U=d,C=k});G.catch(()=>{});let D=setTimeout(()=>{v(de("The relay did not answer in time.","network"))},hn),L=st({...ft(e),server:{...e.server,icons:e.server.icons??qe()},client:(d)=>e.clientFor(d)}),m=e.registry.onChange(()=>L.toolsChanged());function y(d){if(s.readyState!==WebSocket.OPEN)return!1;try{return s.send(JSON.stringify(d)),!0}catch{return!1}}function T(){if(I<=0)return;clearTimeout(_),_=setTimeout(()=>{a??="heartbeat",R(4003);try{s.close()}catch{}},I*2.5)}function v(d){if(r!=="opening")return;R(0),C(d);try{s.close()}catch{}}function R(d){if(r==="closed")return;let k=r==="ready";r="closed",clearTimeout(D),clearTimeout(_),m();for(let b of i.values())b.abort();if(i.clear(),L.close(),k){let b=a??at[d]??(d===1006?"network":"closed");if(C(de("The address was taken over again before its AI apps were disconnected.",b)),e.closed(b,d),b==="replaced"){N.heard().then((j)=>{N.close(),e.replaced({sibling:j})});return}}N.close()}async function S(d){let k=new AbortController;i.set(d.id,k);let b=()=>r==="ready"&&i.get(d.id)===k&&!k.signal.aborted;try{let j=new Request(`https://tab.invalid${d.path}`,{method:d.method,headers:d.headers,signal:k.signal}),M=await L.handle(j,{grant:d.grant,body:d.body});if(!b()){await M.body?.cancel().catch(()=>{});return}let z={};for(let V of $n){let F=M.headers.get(V);if(F!==null)z[V]=F}if(!(z["content-type"]??"").startsWith("text/event-stream")||M.body===null){let V=await M.text();if(!b())return;if(V.length<=c){y({type:"http.response",id:d.id,status:M.status,headers:z,body:V});return}y({type:"http.response.start",id:d.id,status:M.status,headers:z});for(let F of lt(V,c)){if(!b())break;y({type:"http.response.chunk",id:d.id,data:F})}if(b())y({type:"http.response.end",id:d.id});return}y({type:"http.response.start",id:d.id,status:M.status,headers:z});let W=M.body.getReader(),Z=new TextDecoder;k.signal.addEventListener("abort",()=>{W.cancel().catch(()=>{})});for(;;){let{done:V,value:F}=await W.read();if(V||!b())break;let ce=Z.decode(F,{stream:!0});for(let ne of lt(ce,c))y({type:"http.response.chunk",id:d.id,data:ne})}if(b())y({type:"http.response.end",id:d.id})}catch(j){if(b())e.error(j instanceof Error?j:Error(String(j))),y({type:"http.response",id:d.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(i.get(d.id)===k)i.delete(d.id)}}function O(d){if(r==="opening"){if(d.type==="session"){let k=kn(d.limits.maxMessageBytes);if(k===void 0){v(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Rn}.`,"policy"));return}c=k,r="ready",clearTimeout(D),I=d.limits.heartbeatMs,T(),N.claimed();let b=e.sessionStarted(d);if(o&&d.grants.length>0){B={left:new Set(d.grants.map((j)=>j.grantId)),session:b},y({type:"grants.revokeAll"});return}U(b)}else if(d.type==="error")v(de(`The relay refused the connection: ${d.message||d.code}`,d.code==="rate_limited"?"rate_limited":"policy"));else if(d.type==="bye")v(de(`The relay ended the connection: ${d.reason}`,ut[d.reason]??"closed"));return}if(r!=="ready")return;switch(d.type){case"ping":T(),y({type:"pong",t:d.t});return;case"http.request":S(d);return;case"http.cancel":i.get(d.id)?.abort(),i.delete(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":if(e.grantRemoved(d.grantId),B?.left.delete(d.grantId),B?.left.size===0)U(B.session);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(a=ut[d.reason]??"closed",a==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}e.error(Error(`Relay error ${d.code}: ${d.message}`));return;case"session":return}}return s.addEventListener("open",()=>{if(s.protocol!==""&&s.protocol!==xe){v(de(`The relay speaks ${s.protocol}, not ${xe}.`,"policy"));return}let d={type:"hello",library:e.library,page:{title:wn()},secret:n};if(e.appName!==void 0)d.app={name:e.appName};if(o)d.revokeAll=!0;y(d)}),s.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let k=dt(d.data);if(k!==void 0){if(r==="ready")T();O(k);return}let b=bn(d.data);if(b?.id!==void 0)y(xn.has(b.type)?{type:"error",code:"bad_message",message:`malformed ${b.type}`,id:b.id}:{type:"error",code:"unknown_type",message:`unknown type ${b.type}`,id:b.id})}),s.addEventListener("close",(d)=>{if(r==="opening"){R(d.code);let k=d.code===1006||d.code===1002;C(de(k?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${d.code}${d.reason?`: ${d.reason}`:""}).`,at[d.code]??(k?"network":"closed")));return}R(d.code)}),{ready:G,send:y,close(d){if(r==="closed")return;if(r==="opening"){v(new DOMException("The connection was cancelled","AbortError"));return}a=d,y({type:"bye",reason:"user"}),R(1000);try{s.close(1000,"bye")}catch{}}}}export{Rn as MIN_MESSAGE_BYTES,Tn as SIBLING_GRACE_MS,In as SIBLING_WINDOW_MS,yn as addressIdOf,Zn as callFromWebMcp,kn as chunkSize,en as compileRegistry,Xn as openConnection,lt as pieces,gn as withAddress};
|
|
10
|
-
|
|
11
|
-
//# debugId=9B25EB37D1FB4FD964756E2164756E21
|
|
12
|
-
//# sourceMappingURL=connection-dweyrdbn.min.js.map
|