@ractive-ch/tab-mcp-client 0.18.1 → 0.19.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +175 -0
- package/README.md +360 -68
- package/allowed.d.ts +2 -2
- package/allowed.js.map +1 -1
- package/always-allowed.d.ts +15 -15
- package/cdn/allowed.min.js +2 -2
- package/cdn/allowed.min.js.map +2 -2
- package/cdn/confirm-ba3dkf9p.min.js +4 -0
- package/cdn/confirm-ba3dkf9p.min.js.map +10 -0
- package/cdn/connect-my0pbqd7.min.js +6 -0
- package/cdn/connect-my0pbqd7.min.js.map +12 -0
- package/cdn/connection-yf2x9zz2.min.js +17 -0
- package/cdn/{connection-0xqwz17v.min.js.map → connection-yf2x9zz2.min.js.map} +5 -5
- package/cdn/strings.min.js +4 -0
- package/cdn/strings.min.js.map +9 -0
- package/cdn/{tab-mcp-client-2vx9mcww.min.js → tab-mcp-client-8r6h3wza.min.js} +9 -8
- package/cdn/tab-mcp-client-8r6h3wza.min.js.map +11 -0
- package/cdn/tab-mcp-client-nnxcwrxp.min.js +5 -0
- package/cdn/tab-mcp-client-nnxcwrxp.min.js.map +11 -0
- package/cdn/{tab-mcp-client-5j3brdf3.min.js → tab-mcp-client-q758jr4g.min.js} +4 -4
- package/cdn/tab-mcp-client-q758jr4g.min.js.map +10 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +4 -4
- package/cdn/webmcp-84k58gsw.min.js +4 -0
- package/cdn/webmcp-84k58gsw.min.js.map +11 -0
- package/{confirm-bqfdrx3f.js → confirm-hymzwx3b.js} +7 -5
- package/confirm-hymzwx3b.js.map +10 -0
- package/confirm.d.ts +2 -2
- package/{connect-ztsgybpq.js → connect-fhtjdmf3.js} +75 -37
- package/connect-fhtjdmf3.js.map +10 -0
- package/connect.d.ts +7 -6
- package/{connection-gang7f5x.js → connection-73fbg99k.js} +70 -8
- package/connection-73fbg99k.js.map +16 -0
- package/connection.d.ts +23 -2
- package/dialog.d.ts +19 -9
- package/extension.d.ts +373 -0
- package/extension.js +415 -0
- package/extension.js.map +10 -0
- package/handshake.d.ts +82 -0
- package/index-00p8b969.js +221 -0
- package/index-00p8b969.js.map +11 -0
- package/index-1tssct09.js +58 -0
- package/index-1tssct09.js.map +11 -0
- package/{index-c1c266tm.js → index-7qqhn3zv.js} +28 -110
- package/index-7qqhn3zv.js.map +10 -0
- package/index-s31xrfa2.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +59 -64
- package/index.js.map +4 -4
- package/internal.d.ts +2 -0
- package/mcp.d.ts +5 -3
- package/package.json +11 -2
- package/protocol.d.ts +11 -1
- package/react.d.ts +11 -4
- package/react.js +57 -10
- package/react.js.map +5 -4
- package/secret.d.ts +1 -1
- package/setup.d.ts +4 -1
- package/setup.js +3 -2
- package/setup.js.map +1 -1
- package/strings.d.ts +149 -28
- package/strings.js +13 -0
- package/strings.js.map +9 -0
- package/tab-mcp.d.ts +30 -7
- package/text.d.ts +39 -0
- package/types.d.ts +76 -17
- package/webmcp-d2ec3v3g.js +221 -0
- package/webmcp-d2ec3v3g.js.map +11 -0
- package/webmcp.d.ts +17 -4
- package/cdn/confirm-d722a9eb.min.js +0 -4
- package/cdn/confirm-d722a9eb.min.js.map +0 -10
- package/cdn/connect-x6ws6wqt.min.js +0 -6
- package/cdn/connect-x6ws6wqt.min.js.map +0 -12
- package/cdn/connection-0xqwz17v.min.js +0 -17
- package/cdn/tab-mcp-client-2vx9mcww.min.js.map +0 -12
- package/cdn/tab-mcp-client-5j3brdf3.min.js.map +0 -10
- package/cdn/webmcp-khy4f5rj.min.js +0 -4
- package/cdn/webmcp-khy4f5rj.min.js.map +0 -10
- package/confirm-bqfdrx3f.js.map +0 -10
- package/connect-ztsgybpq.js.map +0 -10
- package/connection-gang7f5x.js.map +0 -16
- package/index-5jyqehpk.js +0 -63
- package/index-5jyqehpk.js.map +0 -11
- package/index-c1c266tm.js.map +0 -11
- package/webmcp-zq1enyz0.js +0 -57
- package/webmcp-zq1enyz0.js.map +0 -10
package/tab-mcp.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* events, the pairing state and the address secret; `connect()` loads the
|
|
4
4
|
* connection and the MCP handler with a dynamic `import()`.
|
|
5
5
|
*/
|
|
6
|
-
import type { ConfirmRequest, ConnectionState, ConnectOptions, Grant, IdentityState, PairingCode, ReconnectingInfo, RegisterToolOptions, ServeHandle, ServeOptions, SessionInfo, TabMcpEventMap, TabMcpOptions, Tool, TunnelPort } from "./types.js";
|
|
6
|
+
import type { BrowserExtension, ConfirmRequest, ConnectionState, ConnectOptions, Grant, IdentityState, PairingCode, ReconnectingInfo, RegisterToolOptions, ServeHandle, ServeOptions, SessionInfo, TabMcpEventMap, TabMcpOptions, Tool, TunnelPort } from "./types.js";
|
|
7
7
|
/**
|
|
8
8
|
* The library's waits, in milliseconds: constants for pages (CU 17), which
|
|
9
9
|
* only tests change. `reconnectDelaysMs`: before each reconnect attempt,
|
|
@@ -39,6 +39,15 @@ type Listener<K extends keyof TabMcpEventMap> = (event: TabMcpEventMap[K]) => vo
|
|
|
39
39
|
*/
|
|
40
40
|
export declare class TabMcp extends EventTarget {
|
|
41
41
|
#private;
|
|
42
|
+
/**
|
|
43
|
+
* With `webmcp: true`: the tab-mcp browser extension while it serves this
|
|
44
|
+
* page, with the AI apps that reach the page's tools through it (DEC-207);
|
|
45
|
+
* `extensionchange` says when it changes. `undefined` without it, while
|
|
46
|
+
* its AI access is off, and without WebMCP. Declared only: the mirror's
|
|
47
|
+
* chunk defines it on the instance once it hears the extension, so that
|
|
48
|
+
* the core carries no bytes for it (until then it is `undefined`).
|
|
49
|
+
*/
|
|
50
|
+
readonly extension: BrowserExtension | undefined;
|
|
42
51
|
constructor(options: TabMcpOptions);
|
|
43
52
|
/**
|
|
44
53
|
* Register a tool (WebMCP shape). Allowed before and after `connect()`;
|
|
@@ -85,6 +94,15 @@ export declare class TabMcp extends EventTarget {
|
|
|
85
94
|
signOut(): Promise<void>;
|
|
86
95
|
/** The pairing code to show, if the relay sent one. */
|
|
87
96
|
get pairingCode(): PairingCode | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Identity binding: until when a sign-in pairs this page (ISO time, on
|
|
99
|
+
* the page's clock: the relay's duration counted from its answer to the
|
|
100
|
+
* last `startPairing()`, DEC-202). A reconnect the library makes by
|
|
101
|
+
* itself does not start it anew: it is the time of the reconnect then.
|
|
102
|
+
* `undefined` while pairing is off, until the relay answers, after the
|
|
103
|
+
* session ended, and from relays up to 0.12.1, which do not say.
|
|
104
|
+
*/
|
|
105
|
+
get pairingUntil(): string | undefined;
|
|
88
106
|
/**
|
|
89
107
|
* Connect to the relay: loads the connection and MCP handler, opens the
|
|
90
108
|
* WebSocket, resolves with the session. Call it from a user action (a
|
|
@@ -117,20 +135,25 @@ export declare class TabMcp extends EventTarget {
|
|
|
117
135
|
* Disconnect every AI app and start over with a new secret. The address
|
|
118
136
|
* people add to an AI app names the app and stays the same (DEC-196);
|
|
119
137
|
* what changes is the page behind it, so every AI app has to pair again.
|
|
120
|
-
* If the page has a secret already, it first takes
|
|
138
|
+
* If the page has a secret already, it first takes it back: it
|
|
121
139
|
* connects with the old secret and the relay revokes every grant of it in
|
|
122
140
|
* the same step (`hello.revokeAll`, DEC-095, DEC-136), connected or not,
|
|
123
141
|
* taken over or not. Then it makes a new secret and connects with it if
|
|
124
142
|
* the page was connected, connecting or reconnecting, and resolves once
|
|
125
143
|
* that is done (the new session is `session`). Rejects, and keeps the old
|
|
126
|
-
* secret so that a retry takes it back again, when the old
|
|
144
|
+
* secret so that a retry takes it back again, when the old secret could
|
|
127
145
|
* not be taken back (relay unreachable, taken over again first). With a
|
|
128
|
-
* relay, every rejection has `
|
|
129
|
-
* only connecting with the new
|
|
146
|
+
* relay, every rejection has `secretChanged`: `false` then, `true` when
|
|
147
|
+
* only connecting with the new secret failed (without one: a
|
|
130
148
|
* `TypeError`). Call it from a user action.
|
|
131
149
|
*/
|
|
132
|
-
|
|
133
|
-
/**
|
|
150
|
+
disconnectAll(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* The pairing dialog opened: ask the relay for codes (DEC-028). With
|
|
153
|
+
* identity binding each call while connected starts the relay's ten
|
|
154
|
+
* minutes for a sign-in anew (`pairingUntil`, DEC-202): call it only
|
|
155
|
+
* when the user acts (opens the dialog, continues after the time is up).
|
|
156
|
+
*/
|
|
134
157
|
startPairing(): void;
|
|
135
158
|
/** The pairing dialog closed: the code becomes invalid. */
|
|
136
159
|
stopPairing(): void;
|
package/text.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filling in the texts of `strings.ts`: placeholders, plural forms and lists,
|
|
3
|
+
* by the rules of the texts' language (`Intl`), not by grammar made by hand.
|
|
4
|
+
* No DOM and no texts, so that `./react` can use it without loading the
|
|
5
|
+
* table, as well as the dialogs.
|
|
6
|
+
*/
|
|
7
|
+
import type { DialogStrings, PluralText } from "./strings.js";
|
|
8
|
+
/** What the helpers need of the texts: their language. */
|
|
9
|
+
type InLanguage = {
|
|
10
|
+
lang: string;
|
|
11
|
+
};
|
|
12
|
+
/** `template` with its `{name}` placeholders filled in, as text. */
|
|
13
|
+
export declare function format(template: string, values: Record<string, string>): string;
|
|
14
|
+
/** Whether `value` is a plural text: an object of strings with `other`. */
|
|
15
|
+
export declare const isPlural: (value: unknown) => value is PluralText;
|
|
16
|
+
/**
|
|
17
|
+
* A table with texts but no `lang` is taken as English: its plural forms
|
|
18
|
+
* follow English rules and the dialogs say `lang="en"`. Said once per table
|
|
19
|
+
* in the console, as it is almost always a translation that forgot its tag.
|
|
20
|
+
*/
|
|
21
|
+
export declare function warnWithoutLang(strings: object | undefined): void;
|
|
22
|
+
/**
|
|
23
|
+
* The form of `text` for the count `n`, by the plural rules of the texts'
|
|
24
|
+
* language, with `{n}` filled in; `other` where the table lacks the form.
|
|
25
|
+
*/
|
|
26
|
+
export declare function pluralForm(text: PluralText, n: number, s: InLanguage): string;
|
|
27
|
+
/** `pluralForm` with the other placeholders filled in too, as text. */
|
|
28
|
+
export declare function plural(text: PluralText, n: number, s: InLanguage, values?: Record<string, string>): string;
|
|
29
|
+
/** How the texts' language joins a list ("A, B and C"). */
|
|
30
|
+
export declare function listFormat(s: InLanguage): Intl.ListFormat;
|
|
31
|
+
/** "A and B", "A, B and C", as the texts' language joins a list. */
|
|
32
|
+
export declare function listOf(items: string[], s: InLanguage): string;
|
|
33
|
+
/**
|
|
34
|
+
* The direction of the texts: their own `dir`, else the one the browser
|
|
35
|
+
* knows for `lang` (`Intl.Locale`'s text info, not in every browser), else
|
|
36
|
+
* left to right.
|
|
37
|
+
*/
|
|
38
|
+
export declare function directionOf(s: DialogStrings): "ltr" | "rtl";
|
|
39
|
+
export {};
|
package/types.d.ts
CHANGED
|
@@ -42,10 +42,46 @@ export interface RelayClient {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* An agent in this browser that calls a mirrored tool through WebMCP
|
|
45
|
-
* (`webmcp: true`). Not paired and not identified: nothing more is known
|
|
45
|
+
* (`webmcp: true`). Not paired and not identified: nothing more is known,
|
|
46
|
+
* unless the tab-mcp browser extension vouched for the call (DEC-207).
|
|
46
47
|
*/
|
|
47
48
|
export interface WebMcpClient {
|
|
48
49
|
kind: "webmcp";
|
|
50
|
+
/**
|
|
51
|
+
* Set when the tab-mcp browser extension ran this call for an AI app
|
|
52
|
+
* connected to it, after the user allowed the call there: the page did
|
|
53
|
+
* not ask (no question, no `onConfirm`). Absent for every other agent in
|
|
54
|
+
* the browser, and with `trustExtension: false`.
|
|
55
|
+
*/
|
|
56
|
+
via?: "tab-mcp-extension";
|
|
57
|
+
/** With `via`: the AI app's own name for itself, as the extension knows it. */
|
|
58
|
+
name?: string;
|
|
59
|
+
/** With `via`: the host of the AI app's client id, as the relay verified it for the extension. */
|
|
60
|
+
host?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The tab-mcp browser extension, as it tells a page that offers its tools
|
|
64
|
+
* through WebMCP (`TabMcp.extension`, DEC-207): it is serving this page, and
|
|
65
|
+
* these AI apps can call the page's tools through it.
|
|
66
|
+
*/
|
|
67
|
+
export interface BrowserExtension {
|
|
68
|
+
/** As the extension names itself ("tab-mcp browser extension"). */
|
|
69
|
+
name: string;
|
|
70
|
+
version: string;
|
|
71
|
+
/**
|
|
72
|
+
* The AI apps connected to the extension now (each one's own name and
|
|
73
|
+
* the host the relay verified); empty while none is.
|
|
74
|
+
*/
|
|
75
|
+
apps: readonly {
|
|
76
|
+
name: string;
|
|
77
|
+
host: string;
|
|
78
|
+
}[];
|
|
79
|
+
/**
|
|
80
|
+
* The extension serves only the tab in front of its window: say "while
|
|
81
|
+
* this tab is in front" when telling the user that an app is connected
|
|
82
|
+
* through it.
|
|
83
|
+
*/
|
|
84
|
+
whileInFront: boolean;
|
|
49
85
|
}
|
|
50
86
|
/**
|
|
51
87
|
* This site's own assistant, which the page serves its tools to over a port
|
|
@@ -227,9 +263,11 @@ export interface SetupStep {
|
|
|
227
263
|
/** Options of the library's dialogs (`TabMcpOptions.ui`). */
|
|
228
264
|
export interface DialogOptions {
|
|
229
265
|
/**
|
|
230
|
-
*
|
|
231
|
-
* the
|
|
232
|
-
*
|
|
266
|
+
* Every text the library shows a person, key by key, in one table given
|
|
267
|
+
* once: the dialogs, their setup steps and `ConnectButton` of `./react`
|
|
268
|
+
* read it. Missing keys stay English (`STRINGS` of `./strings`). `lang`
|
|
269
|
+
* is the language of the texts: the dialogs carry it, and plural forms
|
|
270
|
+
* (`Intl.PluralRules`) and lists (`Intl.ListFormat`) follow it.
|
|
233
271
|
*/
|
|
234
272
|
strings?: Partial<DialogStrings>;
|
|
235
273
|
/** The help in the connect dialog ("How do I add it?"). */
|
|
@@ -275,7 +313,7 @@ export interface TabMcpOptions {
|
|
|
275
313
|
/**
|
|
276
314
|
* The relay, e.g. `https://relay.example` or `wss://relay.example`.
|
|
277
315
|
* Without one the page offers its tools only through `serve` and WebMCP:
|
|
278
|
-
* `connect()`, `showConnectDialog()` and `
|
|
316
|
+
* `connect()`, `showConnectDialog()` and `disconnectAll()` reject, and no
|
|
279
317
|
* address secret is read or written.
|
|
280
318
|
*/
|
|
281
319
|
relay?: string;
|
|
@@ -304,13 +342,13 @@ export interface TabMcpOptions {
|
|
|
304
342
|
* run without asking for one AI app, with any arguments (DEC-200):
|
|
305
343
|
*
|
|
306
344
|
* - `true`: the confirmation offers "Always allow", and the connect
|
|
307
|
-
* dialog a switch per tool and "
|
|
308
|
-
* under each connected app. Kept in `storage` next to the secret until
|
|
309
|
-
* the app is disconnected (in memory with `storage: null`).
|
|
345
|
+
* dialog a switch per tool and "Always allow everything"
|
|
346
|
+
* under each connected AI app. Kept in `storage` next to the secret until
|
|
347
|
+
* the AI app is disconnected (in memory with `storage: null`).
|
|
310
348
|
* - `"until-reload"`: the same, offered as "Allow until reload": kept in
|
|
311
|
-
* memory only, until the page is reloaded or the app is disconnected.
|
|
349
|
+
* memory only, until the page is reloaded or the AI app is disconnected.
|
|
312
350
|
* - unset or `false` (DEC-096): the confirmation shows only "Don't allow"
|
|
313
|
-
* and "Allow", and every call asks. A page can still offer its own
|
|
351
|
+
* and "Allow once", and every call asks. A page can still offer its own
|
|
314
352
|
* switches with `@ractive-ch/tab-mcp-client/allowed`, kept as with `true`.
|
|
315
353
|
*
|
|
316
354
|
* Turn it on only for tools whose calls the user does not need to check
|
|
@@ -321,16 +359,16 @@ export interface TabMcpOptions {
|
|
|
321
359
|
ui?: DialogOptions;
|
|
322
360
|
/**
|
|
323
361
|
* Where the address secret lives; default `localStorage`. `null` keeps it
|
|
324
|
-
* only for the page's lifetime (a new
|
|
362
|
+
* only for the page's lifetime (a new secret, so no paired AI app, on every visit).
|
|
325
363
|
*/
|
|
326
364
|
storage?: SecretStorage | null;
|
|
327
365
|
/**
|
|
328
366
|
* Storage key of the secret; default `tab-mcp:secret:<relay origin>:<server.name>`
|
|
329
367
|
* (the name URI-encoded), so pages of one site with different server names get
|
|
330
|
-
* different
|
|
368
|
+
* different secrets. Changing `server.name` therefore changes the secret: set
|
|
331
369
|
* `storageKey` to keep it. Without it, a secret kept under 0.4's default
|
|
332
370
|
* `tab-mcp:secret:<relay origin>` is copied to the new key by the first page that
|
|
333
|
-
* connects, so that page keeps its
|
|
371
|
+
* connects, so that page keeps its AI apps.
|
|
334
372
|
*/
|
|
335
373
|
storageKey?: string;
|
|
336
374
|
/**
|
|
@@ -356,8 +394,21 @@ export interface TabMcpOptions {
|
|
|
356
394
|
* their `callers` list `"webmcp"`: an agent that drives this tab can
|
|
357
395
|
* click Allow in the page's confirmation itself. A failed native
|
|
358
396
|
* registration only warns in the console.
|
|
397
|
+
*
|
|
398
|
+
* With it, the page and the tab-mcp browser extension know of each other
|
|
399
|
+
* (DEC-207): `extension` says which AI apps reach the page through it,
|
|
400
|
+
* and a call the user allowed in the extension is not asked again here
|
|
401
|
+
* (see `trustExtension`).
|
|
359
402
|
*/
|
|
360
403
|
webmcp?: boolean;
|
|
404
|
+
/**
|
|
405
|
+
* With `webmcp: true`: a WebMCP call the tab-mcp browser extension vouches
|
|
406
|
+
* for runs without the page's question and without `onConfirm` (the user
|
|
407
|
+
* allowed exactly that call there, a moment before). On by default;
|
|
408
|
+
* `false` asks every WebMCP call as without the extension. `extension`
|
|
409
|
+
* is reported either way.
|
|
410
|
+
*/
|
|
411
|
+
trustExtension?: boolean;
|
|
361
412
|
}
|
|
362
413
|
/** The library is reconnecting by itself (`state` is `reconnecting`). */
|
|
363
414
|
export interface ReconnectingInfo {
|
|
@@ -452,8 +503,8 @@ export type ConnectionState = "disconnected" | "connecting" | "connected" | "rec
|
|
|
452
503
|
export type DisconnectReason =
|
|
453
504
|
/** `disconnect()` was called. */
|
|
454
505
|
"user"
|
|
455
|
-
/** `
|
|
456
|
-
| "
|
|
506
|
+
/** `disconnectAll()` ended the old session. */
|
|
507
|
+
| "disconnect_all"
|
|
457
508
|
/** Another tab connected with the same address. */
|
|
458
509
|
| "replaced"
|
|
459
510
|
/** The session lifetime is over. */
|
|
@@ -479,7 +530,7 @@ export interface StateChangeDetail {
|
|
|
479
530
|
/**
|
|
480
531
|
* Why it ended: on the change from `connected` (to `disconnected`, or to
|
|
481
532
|
* `reconnecting` when the connection broke), and when `disconnect()` or
|
|
482
|
-
* `
|
|
533
|
+
* `disconnectAll()` ends connecting or reconnecting (`user`, `disconnect_all`).
|
|
483
534
|
*/
|
|
484
535
|
reason?: DisconnectReason;
|
|
485
536
|
}
|
|
@@ -491,7 +542,7 @@ export interface ReplacedDetail {
|
|
|
491
542
|
* tab"). `false`: no such tab was heard (or the browser has no
|
|
492
543
|
* `BroadcastChannel`), so it may be a program with a copy of the address
|
|
493
544
|
* secret, and the AI apps paired with the address now talk to it. Offer
|
|
494
|
-
* `
|
|
545
|
+
* `disconnectAll()`, which takes the address back and disconnects them
|
|
495
546
|
* (DEC-095). Script on the page's origin can make a takeover look like a
|
|
496
547
|
* sibling, so `true` is a hint, not a proof.
|
|
497
548
|
*/
|
|
@@ -554,6 +605,10 @@ export interface TabMcpEventMap {
|
|
|
554
605
|
pairingcode: CustomEvent<{
|
|
555
606
|
pairingCode: PairingCode | undefined;
|
|
556
607
|
}>;
|
|
608
|
+
/** `pairingUntil` changed (identity binding, DEC-202). */
|
|
609
|
+
pairinguntil: CustomEvent<{
|
|
610
|
+
pairingUntil: string | undefined;
|
|
611
|
+
}>;
|
|
557
612
|
grantschange: CustomEvent<{
|
|
558
613
|
grants: readonly Grant[];
|
|
559
614
|
}>;
|
|
@@ -565,6 +620,10 @@ export interface TabMcpEventMap {
|
|
|
565
620
|
toolschange: CustomEvent<{
|
|
566
621
|
tools: readonly string[];
|
|
567
622
|
}>;
|
|
623
|
+
/** `extension` changed: the tab-mcp browser extension, its AI apps (DEC-207). */
|
|
624
|
+
extensionchange: CustomEvent<{
|
|
625
|
+
extension: BrowserExtension | undefined;
|
|
626
|
+
}>;
|
|
568
627
|
/** An AI app called a tool (before any confirmation). */
|
|
569
628
|
toolcall: CustomEvent<ToolCallStart>;
|
|
570
629
|
/** That call ended; also when the user declined it, did not answer, or the AI app cancelled it. */
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// src/handshake.ts
|
|
2
|
+
var PAGE_EVENT = "tab-mcp-page";
|
|
3
|
+
var EXTENSION_EVENT = "tab-mcp-extension";
|
|
4
|
+
var MARK = "data-tab-mcp-handshake";
|
|
5
|
+
var VOUCH_MS = 2000;
|
|
6
|
+
var MAX_VOUCHES = 16;
|
|
7
|
+
var MAX_TEXT = 256;
|
|
8
|
+
var MAX_APPS = 64;
|
|
9
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
var text = (value) => typeof value === "string" && value.length <= MAX_TEXT;
|
|
11
|
+
function appOf(value) {
|
|
12
|
+
return isObject(value) && text(value["name"]) && text(value["host"]) ? { name: value["name"], host: value["host"] } : undefined;
|
|
13
|
+
}
|
|
14
|
+
function canonical(value) {
|
|
15
|
+
return JSON.stringify(value, (_key, v) => isObject(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : v) ?? "";
|
|
16
|
+
}
|
|
17
|
+
var now = () => performance.now();
|
|
18
|
+
|
|
19
|
+
class Handshake {
|
|
20
|
+
#doc;
|
|
21
|
+
#pages = [];
|
|
22
|
+
#extension;
|
|
23
|
+
#vouches = [];
|
|
24
|
+
constructor(doc) {
|
|
25
|
+
this.#doc = doc;
|
|
26
|
+
doc.addEventListener(EXTENSION_EVENT, (event) => this.#heard(event.detail));
|
|
27
|
+
doc.documentElement?.setAttribute(MARK, "1");
|
|
28
|
+
}
|
|
29
|
+
join(page) {
|
|
30
|
+
this.#pages.push(page);
|
|
31
|
+
if (this.#extension !== undefined)
|
|
32
|
+
page.set(this.#extension);
|
|
33
|
+
page.mcp.addEventListener("grantschange", () => this.#say(page, "update"));
|
|
34
|
+
this.#say(page, "hello");
|
|
35
|
+
}
|
|
36
|
+
#say(page, type) {
|
|
37
|
+
const Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;
|
|
38
|
+
this.#doc.dispatchEvent(new Custom(PAGE_EVENT, {
|
|
39
|
+
detail: JSON.stringify({
|
|
40
|
+
v: 1,
|
|
41
|
+
type,
|
|
42
|
+
library: page.version,
|
|
43
|
+
app: page.app,
|
|
44
|
+
apps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({
|
|
45
|
+
name: g.client.name,
|
|
46
|
+
host: g.client.host
|
|
47
|
+
}))
|
|
48
|
+
})
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
#heard(detail) {
|
|
52
|
+
let m;
|
|
53
|
+
try {
|
|
54
|
+
m = typeof detail === "string" ? JSON.parse(detail) : undefined;
|
|
55
|
+
} catch {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!isObject(m) || m["v"] !== 1)
|
|
59
|
+
return;
|
|
60
|
+
if (m["type"] === "vouch")
|
|
61
|
+
this.#vouch(m);
|
|
62
|
+
else if (m["type"] === "withdraw")
|
|
63
|
+
this.#vouches = this.#vouches.filter((v) => v.nonce !== m["nonce"]);
|
|
64
|
+
else if (m["type"] === "hello" || m["type"] === "update") {
|
|
65
|
+
const extension = extensionOf(m);
|
|
66
|
+
if (extension === null)
|
|
67
|
+
return;
|
|
68
|
+
if (canonical(extension) !== canonical(this.#extension)) {
|
|
69
|
+
this.#extension = extension;
|
|
70
|
+
for (const page of this.#pages)
|
|
71
|
+
page.set(extension);
|
|
72
|
+
}
|
|
73
|
+
if (m["type"] === "hello")
|
|
74
|
+
for (const page of this.#pages)
|
|
75
|
+
this.#say(page, "update");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
#vouch(m) {
|
|
79
|
+
const app = appOf(m["app"]);
|
|
80
|
+
const name = m["tool"];
|
|
81
|
+
const nonce = m["nonce"];
|
|
82
|
+
if (app === undefined || typeof name !== "string" || typeof nonce !== "string" || !isObject(m["arguments"]))
|
|
83
|
+
return;
|
|
84
|
+
this.#drop();
|
|
85
|
+
if (this.#vouches.some((v) => v.nonce === nonce))
|
|
86
|
+
return;
|
|
87
|
+
for (const page of this.#pages) {
|
|
88
|
+
const tool = page.trust ? page.registry.get(name) : undefined;
|
|
89
|
+
if (tool === undefined)
|
|
90
|
+
continue;
|
|
91
|
+
this.#vouches.push({
|
|
92
|
+
tool,
|
|
93
|
+
args: canonical(m["arguments"]),
|
|
94
|
+
nonce,
|
|
95
|
+
app,
|
|
96
|
+
at: now()
|
|
97
|
+
});
|
|
98
|
+
if (this.#vouches.length > MAX_VOUCHES)
|
|
99
|
+
this.#vouches.shift();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
#drop() {
|
|
104
|
+
const t = now();
|
|
105
|
+
this.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);
|
|
106
|
+
}
|
|
107
|
+
take(tool, input) {
|
|
108
|
+
this.#drop();
|
|
109
|
+
const args = canonical(input);
|
|
110
|
+
const i = this.#vouches.findIndex((v) => v.tool === tool && v.args === args);
|
|
111
|
+
return i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function extensionOf(m) {
|
|
115
|
+
if (m["on"] !== true)
|
|
116
|
+
return m["on"] === false ? undefined : null;
|
|
117
|
+
const { name, version, apps } = m;
|
|
118
|
+
if (!text(name) || !text(version) || !Array.isArray(apps))
|
|
119
|
+
return null;
|
|
120
|
+
const list = apps.slice(0, MAX_APPS).map(appOf);
|
|
121
|
+
if (list.some((a) => a === undefined))
|
|
122
|
+
return null;
|
|
123
|
+
return Object.freeze({
|
|
124
|
+
name,
|
|
125
|
+
version,
|
|
126
|
+
apps: Object.freeze(list.map((a) => Object.freeze(a))),
|
|
127
|
+
whileInFront: m["whileInFront"] !== false
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
var handshakes = new WeakMap;
|
|
131
|
+
function joinHandshake(page) {
|
|
132
|
+
const doc = globalThis.document;
|
|
133
|
+
if (doc === undefined || globalThis.top !== globalThis.window)
|
|
134
|
+
return;
|
|
135
|
+
let handshake = handshakes.get(doc);
|
|
136
|
+
if (handshake === undefined) {
|
|
137
|
+
handshake = new Handshake(doc);
|
|
138
|
+
handshakes.set(doc, handshake);
|
|
139
|
+
}
|
|
140
|
+
handshake.join(page);
|
|
141
|
+
return handshake;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/webmcp.ts
|
|
145
|
+
var HINTS = [
|
|
146
|
+
"readOnlyHint",
|
|
147
|
+
"untrustedContentHint",
|
|
148
|
+
"consequentialHint",
|
|
149
|
+
"debugging"
|
|
150
|
+
];
|
|
151
|
+
function mirror(registry, context, call, mcp, app, options, version) {
|
|
152
|
+
let state;
|
|
153
|
+
Object.defineProperty(mcp, "extension", {
|
|
154
|
+
get: () => state,
|
|
155
|
+
configurable: true
|
|
156
|
+
});
|
|
157
|
+
let handshake;
|
|
158
|
+
try {
|
|
159
|
+
handshake = joinHandshake({
|
|
160
|
+
version,
|
|
161
|
+
app,
|
|
162
|
+
registry,
|
|
163
|
+
trust: options.trustExtension !== false,
|
|
164
|
+
mcp,
|
|
165
|
+
set: (extension) => {
|
|
166
|
+
state = extension;
|
|
167
|
+
mcp.dispatchEvent(new CustomEvent("extensionchange", { detail: { extension } }));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.warn("tab-mcp: no handshake with the browser extension:", error);
|
|
172
|
+
}
|
|
173
|
+
const mirrors = new Map;
|
|
174
|
+
const warned = new Set;
|
|
175
|
+
const sync = () => {
|
|
176
|
+
for (const [tool, controller] of mirrors) {
|
|
177
|
+
if (registry.get(tool.name) === tool)
|
|
178
|
+
continue;
|
|
179
|
+
controller.abort();
|
|
180
|
+
mirrors.delete(tool);
|
|
181
|
+
}
|
|
182
|
+
for (const tool of registry.list()) {
|
|
183
|
+
const { annotations, callers } = tool;
|
|
184
|
+
const consequential = annotations.consequentialHint ?? annotations.destructiveHint;
|
|
185
|
+
if (mirrors.has(tool) || !(callers?.includes("webmcp") ?? !consequential))
|
|
186
|
+
continue;
|
|
187
|
+
const controller = new AbortController;
|
|
188
|
+
mirrors.set(tool, controller);
|
|
189
|
+
const hints = {
|
|
190
|
+
consequentialHint: consequential
|
|
191
|
+
};
|
|
192
|
+
for (const key of HINTS)
|
|
193
|
+
hints[key] ??= annotations[key];
|
|
194
|
+
const { signal } = controller;
|
|
195
|
+
Promise.resolve().then(() => signal.aborted || context.registerTool({
|
|
196
|
+
name: tool.name,
|
|
197
|
+
title: tool.title,
|
|
198
|
+
description: tool.description,
|
|
199
|
+
inputSchema: tool.inputSchema,
|
|
200
|
+
outputSchema: tool.outputSchema,
|
|
201
|
+
annotations: hints,
|
|
202
|
+
execute: (input, options) => call(tool, input, options?.signal, handshake?.take(tool, input))
|
|
203
|
+
}, { signal, exposedTo: tool.exposedTo })).catch((error) => {
|
|
204
|
+
if (signal.aborted)
|
|
205
|
+
return;
|
|
206
|
+
if (warned.has(tool.name))
|
|
207
|
+
return;
|
|
208
|
+
warned.add(tool.name);
|
|
209
|
+
console.warn(`tab-mcp: ${tool.name} is not offered through WebMCP:`, error);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
registry.onChange(sync);
|
|
214
|
+
sync();
|
|
215
|
+
}
|
|
216
|
+
export {
|
|
217
|
+
mirror
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
//# debugId=9B8AD3FC9B9645ED64756E2164756E21
|
|
221
|
+
//# sourceMappingURL=webmcp-d2ec3v3g.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/handshake.ts", "../src/webmcp.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The page's side of the handshake with the tab-mcp browser extension\n * (DEC-207), in the WebMCP mirror's chunk: only a page that offers its tools\n * to agents in the browser (`webmcp: true`) takes part.\n *\n * Plain DOM events on `document`, each with a JSON string as `detail`\n * (objects do not cross between a content script's world and the page's in\n * every browser): `tab-mcp-page` from the page, `tab-mcp-extension` from\n * the extension. Every message has `v: 1` and a `type`; a message of\n * another version, an unknown type or a malformed one is ignored, and so\n * are unknown fields.\n *\n * - The page announces itself (`hello`: the library's version, the app id,\n * the AI apps connected to it directly) when it starts, again (`update`)\n * when those apps change, and answers the extension's `hello` with an\n * `update`. It marks `<html data-tab-mcp-handshake>`, so that an\n * extension that starts later (its content script comes at\n * `document_idle`, or with a click) knows it may speak without having\n * heard the `hello`.\n * - The extension says what it is, whether it serves the page now and\n * which AI apps are connected to it (`hello`, `update`), and, right before\n * it runs a page tool the user allowed there, `vouch`: the tool, the exact\n * arguments, a nonce and the AI app; once that call ended or failed,\n * `withdraw` with the nonce, and a vouch still unused is dropped.\n * - Each side cuts the other's list of AI apps to 64 and sends no more.\n *\n * No proof of who sent what: anything that could fake the extension runs in\n * the page already, where it could skip any check. A convenience between\n * two parts the user trusts, not a security boundary.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension, Grant } from \"./types.ts\";\n\n/** From the page to the extension. */\nexport const PAGE_EVENT = \"tab-mcp-page\";\n/** From the extension to the page. */\nexport const EXTENSION_EVENT = \"tab-mcp-extension\";\n/** On `<html>`: this page takes part (for an extension that starts later). */\nexport const MARK = \"data-tab-mcp-handshake\";\n/** A vouch is kept this long (milliseconds), then dropped unused. */\nexport const VOUCH_MS = 2_000;\n/** At most this many vouches wait; beyond, the oldest goes. */\nconst MAX_VOUCHES = 16;\n/** Texts from the extension are taken up to these lengths, apps up to this count either way. */\nconst MAX_TEXT = 256;\nconst MAX_APPS = 64;\n\n/** One `TabMcp` of the page, as the handshake sees it. */\nexport interface HandshakePage {\n\t/** The library's version. */\n\treadonly version: string;\n\treadonly app: string;\n\treadonly registry: ToolRegistry;\n\t/** Vouches are taken for its tools (`trustExtension`). */\n\treadonly trust: boolean;\n\t/** The `TabMcp`: its `grants` and `grantschange`. */\n\treadonly mcp: EventTarget & { readonly grants: readonly Grant[] };\n\t/** The extension's state changed. */\n\tset(extension: BrowserExtension | undefined): void;\n}\n\n/** The AI app a vouched call came from. */\nexport interface VouchedBy {\n\tname: string;\n\thost: string;\n}\n\ninterface Vouch {\n\ttool: RegisteredTool;\n\t/** The arguments, canonical (`canonical`). */\n\targs: string;\n\tnonce: string;\n\tapp: VouchedBy;\n\tat: number;\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === \"string\" && value.length <= MAX_TEXT;\n\n/** An AI app as the extension names it; `undefined` if it is malformed. */\nfunction appOf(value: unknown): VouchedBy | undefined {\n\treturn isObject(value) && text(value[\"name\"]) && text(value[\"host\"])\n\t\t? { name: value[\"name\"], host: value[\"host\"] }\n\t\t: undefined;\n}\n\n/**\n * `value` as JSON with the keys of every object sorted: two argument\n * objects are equal when their canonical forms are.\n */\nexport function canonical(value: unknown): string {\n\treturn (\n\t\tJSON.stringify(value, (_key, v: unknown) =>\n\t\t\tisObject(v)\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n\t\t\t\t\t)\n\t\t\t\t: v,\n\t\t) ?? \"\"\n\t);\n}\n\n/** Monotonic milliseconds: a vouch's age must not follow the wall clock. */\nconst now = () => performance.now();\n\nclass Handshake {\n\treadonly #doc: Document;\n\treadonly #pages: HandshakePage[] = [];\n\t#extension: BrowserExtension | undefined;\n\t#vouches: Vouch[] = [];\n\n\tconstructor(doc: Document) {\n\t\tthis.#doc = doc;\n\t\tdoc.addEventListener(EXTENSION_EVENT, (event) =>\n\t\t\tthis.#heard((event as CustomEvent).detail),\n\t\t);\n\t\tdoc.documentElement?.setAttribute(MARK, \"1\");\n\t}\n\n\tjoin(page: HandshakePage): void {\n\t\tthis.#pages.push(page);\n\t\tif (this.#extension !== undefined) page.set(this.#extension);\n\t\tpage.mcp.addEventListener(\"grantschange\", () => this.#say(page, \"update\"));\n\t\tthis.#say(page, \"hello\");\n\t}\n\n\t#say(page: HandshakePage, type: \"hello\" | \"update\"): void {\n\t\t// The document's own `CustomEvent`: a document may take only events\n\t\t// of its realm.\n\t\tconst Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;\n\t\tthis.#doc.dispatchEvent(\n\t\t\tnew Custom(PAGE_EVENT, {\n\t\t\t\tdetail: JSON.stringify({\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttype,\n\t\t\t\t\tlibrary: page.version,\n\t\t\t\t\tapp: page.app,\n\t\t\t\t\t// Capped as the extension cuts what it hears: more would\n\t\t\t\t\t// not be heard anyway.\n\t\t\t\t\tapps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({\n\t\t\t\t\t\tname: g.client.name,\n\t\t\t\t\t\thost: g.client.host,\n\t\t\t\t\t})),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#heard(detail: unknown): void {\n\t\tlet m: unknown;\n\t\ttry {\n\t\t\tm = typeof detail === \"string\" ? JSON.parse(detail) : undefined;\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isObject(m) || m[\"v\"] !== 1) return;\n\t\tif (m[\"type\"] === \"vouch\") this.#vouch(m);\n\t\t// The call it was for ended or never reached the page: an unused vouch\n\t\t// must not wait its 2 s for another caller.\n\t\telse if (m[\"type\"] === \"withdraw\")\n\t\t\tthis.#vouches = this.#vouches.filter((v) => v.nonce !== m[\"nonce\"]);\n\t\telse if (m[\"type\"] === \"hello\" || m[\"type\"] === \"update\") {\n\t\t\tconst extension = extensionOf(m);\n\t\t\tif (extension === null) return;\n\t\t\tif (canonical(extension) !== canonical(this.#extension)) {\n\t\t\t\tthis.#extension = extension;\n\t\t\t\tfor (const page of this.#pages) page.set(extension);\n\t\t\t}\n\t\t\tif (m[\"type\"] === \"hello\")\n\t\t\t\tfor (const page of this.#pages) this.#say(page, \"update\");\n\t\t}\n\t}\n\n\t/**\n\t * A vouch, kept for the tool registered under its name now, by a page\n\t * that takes vouches: a tool registered anew after this does not get it.\n\t */\n\t#vouch(m: Record<string, unknown>): void {\n\t\tconst app = appOf(m[\"app\"]);\n\t\tconst name = m[\"tool\"];\n\t\tconst nonce = m[\"nonce\"];\n\t\tif (\n\t\t\tapp === undefined ||\n\t\t\ttypeof name !== \"string\" ||\n\t\t\ttypeof nonce !== \"string\" ||\n\t\t\t!isObject(m[\"arguments\"])\n\t\t)\n\t\t\treturn;\n\t\tthis.#drop();\n\t\t// The same vouch heard twice counts once.\n\t\tif (this.#vouches.some((v) => v.nonce === nonce)) return;\n\t\tfor (const page of this.#pages) {\n\t\t\tconst tool = page.trust ? page.registry.get(name) : undefined;\n\t\t\tif (tool === undefined) continue;\n\t\t\tthis.#vouches.push({\n\t\t\t\ttool,\n\t\t\t\targs: canonical(m[\"arguments\"]),\n\t\t\t\tnonce,\n\t\t\t\tapp,\n\t\t\t\tat: now(),\n\t\t\t});\n\t\t\tif (this.#vouches.length > MAX_VOUCHES) this.#vouches.shift();\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Forget the vouches older than `VOUCH_MS`. */\n\t#drop(): void {\n\t\tconst t = now();\n\t\tthis.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);\n\t}\n\n\t/**\n\t * The vouch for this call of `tool` with `input`, used up; `undefined`\n\t * if there is none (the call is asked as without the extension).\n\t */\n\ttake(tool: RegisteredTool, input: unknown): VouchedBy | undefined {\n\t\tthis.#drop();\n\t\tconst args = canonical(input);\n\t\tconst i = this.#vouches.findIndex(\n\t\t\t(v) => v.tool === tool && v.args === args,\n\t\t);\n\t\treturn i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;\n\t}\n}\n\n/**\n * The extension's state from its `hello` or `update`: `undefined` when it\n * does not serve the page now, `null` when the message is malformed.\n */\nfunction extensionOf(\n\tm: Record<string, unknown>,\n): BrowserExtension | undefined | null {\n\tif (m[\"on\"] !== true) return m[\"on\"] === false ? undefined : null;\n\tconst { name, version, apps } = m;\n\tif (!text(name) || !text(version) || !Array.isArray(apps)) return null;\n\tconst list = apps.slice(0, MAX_APPS).map(appOf);\n\tif (list.some((a) => a === undefined)) return null;\n\treturn Object.freeze({\n\t\tname,\n\t\tversion,\n\t\tapps: Object.freeze(list.map((a) => Object.freeze(a as VouchedBy))),\n\t\twhileInFront: m[\"whileInFront\"] !== false,\n\t});\n}\n\nconst handshakes = new WeakMap<Document, Handshake>();\n\n/**\n * The handshake of the page's top-level document, which `page` joins; the\n * extension speaks only to the top frame. `undefined` in a frame or\n * without a document.\n */\nexport function joinHandshake(page: HandshakePage): Handshake | undefined {\n\tconst doc = globalThis.document;\n\tif (doc === undefined || globalThis.top !== globalThis.window)\n\t\treturn undefined;\n\tlet handshake = handshakes.get(doc);\n\tif (handshake === undefined) {\n\t\thandshake = new Handshake(doc);\n\t\thandshakes.set(doc, handshake);\n\t}\n\thandshake.join(page);\n\treturn handshake;\n}\n",
|
|
6
|
+
"/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks, confirms and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.ts\";\n\n/** What the library uses of the browser's `ModelContext`. */\nexport interface ModelContext {\n\tregisterTool(\n\t\ttool: object,\n\t\toptions: { signal: AbortSignal; exposedTo: string[] | undefined },\n\t): unknown;\n}\n\n/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\n\n/** The WebMCP hints; the MCP-only ones are left out. */\nconst HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\n\n/**\n * Mirror `registry`'s tools into `context`, now and whenever the registry\n * changes: those whose `callers` list `\"webmcp\"`, and without `callers` those\n * not marked consequential, where MCP's `destructiveHint` counts as\n * `consequentialHint` (DEC-143, DEC-165). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`), `version` the library's. The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; their calls are asked.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst sync = (): void => {\n\t\tfor (const [tool, controller] of mirrors) {\n\t\t\tif (registry.get(tool.name) === tool) continue;\n\t\t\tcontroller.abort();\n\t\t\tmirrors.delete(tool);\n\t\t}\n\t\tfor (const tool of registry.list()) {\n\t\t\tconst { annotations, callers } = tool;\n\t\t\tconst consequential =\n\t\t\t\tannotations.consequentialHint ?? annotations.destructiveHint;\n\t\t\t// The one place of the rule for WebMCP (the relay and a port: `toolsFor`).\n\t\t\tif (mirrors.has(tool) || !(callers?.includes(\"webmcp\") ?? !consequential))\n\t\t\t\tcontinue;\n\t\t\tconst controller = new AbortController();\n\t\t\tmirrors.set(tool, controller);\n\t\t\tconst hints: Record<string, boolean | undefined> = {\n\t\t\t\tconsequentialHint: consequential,\n\t\t\t};\n\t\t\tfor (const key of HINTS) hints[key] ??= annotations[key];\n\t\t\tconst { signal } = controller;\n\t\t\tPromise.resolve()\n\t\t\t\t// Not once unmirrored: whatever the browser does with an aborted\n\t\t\t\t// signal.\n\t\t\t\t.then(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\t\tcontext.registerTool(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t// WebIDL dictionaries: `undefined` is the same as left out.\n\t\t\t\t\t\t\t\ttitle: tool.title,\n\t\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t\t\t\t\t\toutputSchema: tool.outputSchema,\n\t\t\t\t\t\t\t\tannotations: hints,\n\t\t\t\t\t\t\t\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal, exposedTo: tool.exposedTo },\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // unmirrored meanwhile\n\t\t\t\t\tif (warned.has(tool.name)) return;\n\t\t\t\t\twarned.add(tool.name);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`tab-mcp: ${tool.name} is not offered through WebMCP:`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t};\n\tregistry.onChange(sync);\n\tsync();\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAmCO,IAAM,aAAa;AAEnB,IAAM,kBAAkB;AAExB,IAAM,OAAO;AAEb,IAAM,WAAW;AAExB,IAAM,cAAc;AAEpB,IAAM,WAAW;AACjB,IAAM,WAAW;AA+BjB,IAAM,WAAW,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,IAAM,OAAO,CAAC,UACb,OAAO,UAAU,YAAY,MAAM,UAAU;AAG9C,SAAS,KAAK,CAAC,OAAuC;AAAA,EACrD,OAAO,SAAS,KAAK,KAAK,KAAK,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO,IAChE,EAAE,MAAM,MAAM,SAAS,MAAM,MAAM,QAAQ,IAC3C;AAAA;AAOG,SAAS,SAAS,CAAC,OAAwB;AAAA,EACjD,OACC,KAAK,UAAU,OAAO,CAAC,MAAM,MAC5B,SAAS,CAA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Q,SAAS,KAAK,GAAG;AAAA,MACnC,QAAQ,aAAa,YAAY;AAAA,MACjC,MAAM,gBACL,YAAY,qBAAqB,YAAY;AAAA,MAE9C,IAAI,QAAQ,IAAI,IAAI,KAAK,EAAE,SAAS,SAAS,QAAQ,KAAK,CAAC;AAAA,QAC1D;AAAA,MACD,MAAM,aAAa,IAAI;AAAA,MACvB,QAAQ,IAAI,MAAM,UAAU;AAAA,MAC5B,MAAM,QAA6C;AAAA,QAClD,mBAAmB;AAAA,MACpB;AAAA,MACA,WAAW,OAAO;AAAA,QAAO,MAAM,SAAS,YAAY;AAAA,MACpD,QAAQ,WAAW;AAAA,MACnB,QAAQ,QAAQ,EAGd,KACA,MACC,OAAO,WACP,QAAQ,aACP;AAAA,QACC,MAAM,KAAK;AAAA,QAEX,OAAO,KAAK;AAAA,QACZ,aAAa,KAAK;AAAA,QAClB,aAAa,KAAK;AAAA,QAClB,cAAc,KAAK;AAAA,QACnB,aAAa;AAAA,QAGb,SAAS,CAAC,OAAgB,YACzB,KACC,MACA,OACA,SAAS,QACT,WAAW,KAAK,MAAM,KAAK,CAC5B;AAAA,MACF,GACA,EAAE,QAAQ,WAAW,KAAK,UAAU,CACrC,CACF,EACC,MAAM,CAAC,UAAmB;AAAA,QAC1B,IAAI,OAAO;AAAA,UAAS;AAAA,QACpB,IAAI,OAAO,IAAI,KAAK,IAAI;AAAA,UAAG;AAAA,QAC3B,OAAO,IAAI,KAAK,IAAI;AAAA,QACpB,QAAQ,KACP,YAAY,KAAK,uCACjB,KACD;AAAA,OACA;AAAA,IACH;AAAA;AAAA,EAED,SAAS,SAAS,IAAI;AAAA,EACtB,KAAK;AAAA;",
|
|
9
|
+
"debugId": "9B8AD3FC9B9645ED64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/webmcp.d.ts
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* `AbortController`, aborted when the tool leaves the registry. A chunk of
|
|
6
6
|
* its own (DEC-171), loaded by a `TabMcp` whose constructor found native
|
|
7
7
|
* WebMCP (`nativeContext` in the core); a call loads the connection chunk,
|
|
8
|
-
* which checks, confirms and runs it.
|
|
8
|
+
* which checks, confirms and runs it. The handshake with the tab-mcp browser
|
|
9
|
+
* extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors
|
|
10
|
+
* takes part.
|
|
9
11
|
*/
|
|
12
|
+
import { type HandshakePage, type VouchedBy } from "./handshake.js";
|
|
10
13
|
import type { RegisteredTool, ToolRegistry } from "./registry.js";
|
|
11
14
|
/** What the library uses of the browser's `ModelContext`. */
|
|
12
15
|
export interface ModelContext {
|
|
@@ -15,13 +18,23 @@ export interface ModelContext {
|
|
|
15
18
|
exposedTo: string[] | undefined;
|
|
16
19
|
}): unknown;
|
|
17
20
|
}
|
|
18
|
-
/**
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Runs a call of a mirrored tool; `signal` is the browser's, if it gives
|
|
23
|
+
* one; `by`: the AI app the tab-mcp browser extension vouched for it.
|
|
24
|
+
*/
|
|
25
|
+
export type WebMcpCall = (tool: RegisteredTool, input: unknown, signal: unknown, by: VouchedBy | undefined) => Promise<unknown>;
|
|
20
26
|
/**
|
|
21
27
|
* Mirror `registry`'s tools into `context`, now and whenever the registry
|
|
22
28
|
* changes: those whose `callers` list `"webmcp"`, and without `callers` those
|
|
23
29
|
* not marked consequential, where MCP's `destructiveHint` counts as
|
|
24
30
|
* `consequentialHint` (DEC-143, DEC-165). Every failure of the native `registerTool()`
|
|
25
31
|
* stays here: warned once per name, the tool still offered through the relay.
|
|
32
|
+
* The page joins the handshake with the tab-mcp browser extension: `mcp`
|
|
33
|
+
* is its `TabMcp`, `app` its app id, `options` its options
|
|
34
|
+
* (`trustExtension`), `version` the library's. The extension's state is `mcp.extension`, defined
|
|
35
|
+
* here on the instance (the core only declares it, for its bytes), and
|
|
36
|
+
* `extensionchange` is sent here.
|
|
26
37
|
*/
|
|
27
|
-
export declare function mirror(registry: ToolRegistry, context: ModelContext, call: WebMcpCall
|
|
38
|
+
export declare function mirror(registry: ToolRegistry, context: ModelContext, call: WebMcpCall, mcp: HandshakePage["mcp"], app: string, options: {
|
|
39
|
+
trustExtension?: boolean;
|
|
40
|
+
}, version: string): void;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{a,t,o,e,n,s,d,l}from"./tab-mcp-client-2vx9mcww.min.js";import{r}from"./tab-mcp-client-5j3brdf3.min.js";function ee(u){try{return s(JSON.stringify(u,null,2))}catch{return}}var ne=750,te=500,J=new WeakMap;function K(u,i,b={}){if(u.signal.aborted)return Promise.resolve("deny");let g=J.get(i);if(g===void 0)g={shown:!1,waiting:[]},J.set(i,g);let f=g,c=()=>{let h=f.waiting.shift();f.shown=h!==void 0,h?.(),f.changed?.()},L=()=>{try{return ie(u,i,b,f,c)}catch(h){return c(),Promise.reject(h)}};if(!f.shown)return f.shown=!0,L();return new Promise((h)=>{let v=()=>{if(u.signal.removeEventListener("abort",E),b.allowedNow?.()===!0){h("allow"),c();return}h(L())},E=()=>{f.waiting.splice(f.waiting.indexOf(v),1),f.changed?.(),h("deny")};u.signal.addEventListener("abort",E,{once:!0}),f.waiting.push(v),f.changed?.()})}function ie(u,i,b,g,f){let c=b.strings??a(void 0),L=b.allowDelayMs??ne,h=u.tool.title??u.tool.name,v=d(u.client,c),E={tool:h,client:v},{dialog:m,id:C}=l(i,"tab-mcp-confirm",c,...o(i,c.confirmTitle,E)),H=e(i,"p",{className:"tab-mcp-waiting"}),I=()=>{let p=g.waiting.length;H.hidden=p===0,H.textContent=p===1?c.waitingOne:t(c.waitingMany,{n:String(p)})};g.changed=I,I();let z=n(i,c.deny,()=>m.close("deny"),"tab-mcp-deny","primary"),B=(p,j,R)=>{let A=n(i,p,()=>{if(!A.disabled)m.close(j)},R);return A},k=[B(c.allow,"allow","tab-mcp-allow")],W=[],Q=b.alwaysAllow;if(Q===!0||Q==="until-reload"){let p=Q===!0;k.unshift(B(p?c.alwaysAllow:c.allowUntilReload,"always","tab-mcp-always")),W.push(e(i,"p",{className:"tab-mcp-always-note"},...o(i,p?c.alwaysAllowNote:c.allowUntilReloadNote,E)))}let Y=e(i,"div",{className:"tab-mcp-actions"},z,...k.flatMap((p)=>[" ",p])),N=!1,U=!1,M=()=>{for(let p of k)p.disabled=!(N&&U)};M();let O=ee(u.arguments),y=e(i,"pre",{className:"tab-mcp-arguments",id:`${C}-arguments`,text:O??c.argumentsHidden});if(O===void 0)for(let p of[...k,...W])p.hidden=!0;y.dir="ltr",y.style.setProperty("white-space","pre-wrap"),y.style.setProperty("overflow-wrap","anywhere"),y.style.setProperty("max-height","var(--tab-mcp-arguments-height, min(50vh, 24rem))"),y.style.setProperty("overflow","auto"),y.hidden=Object.keys(u.arguments).length===0;let T=e(i,"p",{className:"tab-mcp-scroll-note",text:c.scrollToAllow});T.hidden=!0;let _=e(i,"p",{id:`${C}-who`},...o(i,c.confirmWho,E));m.setAttribute("aria-describedby",O!==void 0&&!y.hidden&&O.length<=te?`${_.id} ${y.id}`:_.id),m.append(_,e(i,"p",{className:"tab-mcp-description",text:u.tool.description}),y,T,Y,...W,H),i.body.append(m);let x=i.defaultView;return new Promise((p,j)=>{let R=()=>m.close("deny");u.signal.addEventListener("abort",R,{once:!0});let A,P,F=()=>{if(P!==void 0&&i.title===P.shown)i.title=P.page;P=void 0},X=()=>{if(i.visibilityState!=="hidden")F();else if(P===void 0)P={page:i.title,shown:`${c.titlePrefix}${i.title}`},i.title=P.shown},D=(w)=>{if(w?.type==="close"&&w.target===m)return;if(X(),clearTimeout(A),A=void 0,N=!1,M(),w?.type==="blur"||i.visibilityState==="hidden"||!i.hasFocus())return;A=setTimeout(()=>{N=!0,M()},L)},S=()=>{if(U)return;if(y.scrollTop+y.clientHeight<y.scrollHeight-2){T.hidden=!1,y.tabIndex=0;return}U=!0,T.hidden=!0,M()},V=(w)=>{if(N)return;let q=w.target?.localName==="button";if(w.key==="Escape"||q&&(w.key==="Enter"||w.key===" "))w.preventDefault()},Z=(w)=>{if(!N)w.preventDefault()};i.addEventListener("visibilitychange",D),i.addEventListener("close",D,!0),x?.addEventListener("focus",D),x?.addEventListener("blur",D),x?.addEventListener("resize",S),y.addEventListener("scroll",S),m.addEventListener("keydown",V),m.addEventListener("keyup",V),m.addEventListener("cancel",Z);let G=()=>{if(clearTimeout(A),F(),i.removeEventListener("visibilitychange",D),i.removeEventListener("close",D,!0),x?.removeEventListener("focus",D),x?.removeEventListener("blur",D),x?.removeEventListener("resize",S),u.signal.removeEventListener("abort",R),m.remove(),g.changed===I)g.changed=void 0};m.addEventListener("close",()=>{let w=m.returnValue;G(),p(w==="allow"||w==="always"?w:"deny"),f()},{once:!0});try{m.showModal()}catch(w){G(),j(w),f();return}z.focus(),D(),S()})}function ae(u,i,b,g={}){let{client:f}=i,c=a(g.ui),{allowDelayMs:L}=g;if(f.kind!=="relay")return K(i,b,{strings:c,allowDelayMs:L}).then((C)=>C==="allow");let{grantId:h}=f,v=r(u),E=()=>v.allows(h,i.tool);if(E())return Promise.resolve(!0);let m=g.alwaysAllow??v.offered;return K(i,b,{strings:c,allowDelayMs:L,alwaysAllow:m!==!1&&(m===!0&&v.kept?!0:"until-reload"),allowedNow:E}).then((C)=>{if(C==="always")v.keep(h,i.tool);return C!=="deny"})}function se(u,i,b){let{client:g}=i;if(g.kind==="relay"&&r(u).allows(g.grantId,i.tool))return Promise.resolve(!0);if(b===void 0)return u.confirmInPage(i);return Promise.resolve().then(()=>b(i)).then((f)=>f==="unanswered"?f:f===!0)}export{se as confirmCall,ae as confirmInPage};
|
|
2
|
-
|
|
3
|
-
//# debugId=D0E23A81AC714FF364756E2164756E21
|
|
4
|
-
//# sourceMappingURL=confirm-d722a9eb.min.js.map
|