@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/extension.d.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ractive-ch/tab-mcp-client/extension`: for a browser extension that is a
|
|
3
|
+
* tab-mcp page itself (the tab-mcp browser extension, Sitegloss). It fills
|
|
4
|
+
* in the extension's own pairing code on the relay's pairing page
|
|
5
|
+
* (`/authorize`) when an AI app opens it in the same browser, after asking
|
|
6
|
+
* the user (DEC-199, DEC-203). What is the same for every such extension
|
|
7
|
+
* lives here, reviewed once (DEC-206); how the user is asked, where the
|
|
8
|
+
* setting is kept, the permission prompt, the content script's registration
|
|
9
|
+
* and holding pairing on are each extension's own, given as callbacks.
|
|
10
|
+
*
|
|
11
|
+
* The relay's page has no scripts (DEC-057), so it cannot call the
|
|
12
|
+
* extension: a content script reads the form's `data-tab-mcp-*` hooks and
|
|
13
|
+
* tells the worker who asks (the AI app's name and verified host). The
|
|
14
|
+
* worker asks its user and, on Allow, hands the code to that one page over
|
|
15
|
+
* its port. The content script never sees a code before that, and the
|
|
16
|
+
* worker never takes a page's word for where it is: any site can copy the
|
|
17
|
+
* markup, so the origin the browser reports for the port is the check.
|
|
18
|
+
*
|
|
19
|
+
* An entry of its own that a web page never loads, out of the core. It
|
|
20
|
+
* imports nothing of the rest of the library at run time and touches no
|
|
21
|
+
* `window` or `document` until called, so a service worker and a content
|
|
22
|
+
* script can both import it; a content script's bundle keeps only the page
|
|
23
|
+
* side (`runPairingPage` and what it uses). No `chrome` types: the browser's
|
|
24
|
+
* ports and senders are taken as the small structural types below.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* // The content script, registered for the relay's /authorize page:
|
|
28
|
+
* import { PAIRING_PORT, runPairingPage } from "@ractive-ch/tab-mcp-client/extension";
|
|
29
|
+
* runPairingPage({ app: "my-app", connect: () => chrome.runtime.connect({ name: PAIRING_PORT }) });
|
|
30
|
+
*
|
|
31
|
+
* // The worker:
|
|
32
|
+
* import { CodeFiller, PAIRING_PORT, pagePort } from "@ractive-ch/tab-mcp-client/extension";
|
|
33
|
+
* const filler = new CodeFiller({ extensionId: chrome.runtime.id, app: "my-app", ... });
|
|
34
|
+
* chrome.runtime.onConnect.addListener((port) => {
|
|
35
|
+
* if (port.name === PAIRING_PORT) void filler.page(pagePort(port));
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
import type { TabMcp } from "./tab-mcp.js";
|
|
40
|
+
import type { PairingCode } from "./types.js";
|
|
41
|
+
/** The name of the port a pairing page's content script opens. */
|
|
42
|
+
export declare const PAIRING_PORT = "pairing-page";
|
|
43
|
+
/** The relay's pairing page. */
|
|
44
|
+
export declare const PAIRING_PATH = "/authorize";
|
|
45
|
+
/** What the content script says once, on its page's port. */
|
|
46
|
+
export interface PairingHello {
|
|
47
|
+
type: "pairing-page";
|
|
48
|
+
/** This page load's own: the code comes back only with it. */
|
|
49
|
+
nonce: string;
|
|
50
|
+
/** `data-app`: the app the AI app asks to connect to. */
|
|
51
|
+
app: string;
|
|
52
|
+
/** `data-client-name`: the AI app's name for itself. */
|
|
53
|
+
clientName: string;
|
|
54
|
+
/** `data-client-host`: the host the relay verified for the AI app. */
|
|
55
|
+
clientHost: string;
|
|
56
|
+
/**
|
|
57
|
+
* The form's hidden `request_id`: the relay's id of this authorization
|
|
58
|
+
* request, the same on its page again after a wrong code. The one fill
|
|
59
|
+
* without a question is for this request only.
|
|
60
|
+
*/
|
|
61
|
+
requestId: string;
|
|
62
|
+
}
|
|
63
|
+
/** What the worker sends after the user's Allow: the code to fill in and submit. */
|
|
64
|
+
export interface FillMessage {
|
|
65
|
+
type: "fill";
|
|
66
|
+
nonce: string;
|
|
67
|
+
code: string;
|
|
68
|
+
}
|
|
69
|
+
/** The longest name and host a hello may carry (the relay's own limits are lower). */
|
|
70
|
+
export declare const MAX_CLIENT_NAME = 200;
|
|
71
|
+
export declare const MAX_CLIENT_HOST = 253;
|
|
72
|
+
/**
|
|
73
|
+
* The content script's hello, checked; `undefined` for anything else. The
|
|
74
|
+
* name and host are what the relay's page says, kept as they are: the
|
|
75
|
+
* extension's question must show invisible characters escaped (`./visible`).
|
|
76
|
+
*/
|
|
77
|
+
export declare function parseHello(message: unknown): PairingHello | undefined;
|
|
78
|
+
/** The worker's fill message, checked against this page's nonce. */
|
|
79
|
+
export declare function parseFill(message: unknown, nonce: string): FillMessage | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The origin of the relay's web pages for the relay address `relay`: its
|
|
82
|
+
* `ws:`/`wss:` forms are the same server's `http:`/`https:`. `undefined` for
|
|
83
|
+
* anything that is not one.
|
|
84
|
+
*/
|
|
85
|
+
export declare function relayPageOrigin(relay: string): string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* The host permission for the relay's site (`<scheme>://<host>/*`), the one
|
|
88
|
+
* origin to ask for (`permissions.request({ origins: [it] })`) before the
|
|
89
|
+
* extension can see the pairing page. `undefined` for an address that has
|
|
90
|
+
* no pattern: the user types the code.
|
|
91
|
+
*/
|
|
92
|
+
export declare function relaySitePattern(relay: string): string | undefined;
|
|
93
|
+
/** The match pattern of the relay's pairing page, for a content script's `matches`. */
|
|
94
|
+
export declare function pairingPagePattern(relay: string): string | undefined;
|
|
95
|
+
/** The page's pairing form, as far as filling it in needs it. */
|
|
96
|
+
export interface PairingForm {
|
|
97
|
+
form: HTMLFormElement;
|
|
98
|
+
field: HTMLInputElement;
|
|
99
|
+
button: HTMLButtonElement;
|
|
100
|
+
app: string;
|
|
101
|
+
clientName: string;
|
|
102
|
+
clientHost: string;
|
|
103
|
+
/** The relay's id of this request (the form's hidden `request_id`). */
|
|
104
|
+
requestId: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The pairing form of app `app` on `doc`, if this is a top-level page at
|
|
108
|
+
* `/authorize` with exactly one such form that has a code field and a
|
|
109
|
+
* Connect button (DEC-199's hooks, version 1). The worker checks the origin
|
|
110
|
+
* itself; this only spares it the pages that are not one. A page that pairs
|
|
111
|
+
* by sign-in only has no code field.
|
|
112
|
+
*/
|
|
113
|
+
export declare function findPairingForm(doc: Document, where: {
|
|
114
|
+
topLevel: boolean;
|
|
115
|
+
pathname: string;
|
|
116
|
+
}, app: string): PairingForm | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Write `code` into the form's field and submit it with its Connect button:
|
|
119
|
+
* the page's own post, as if the user had typed it and clicked.
|
|
120
|
+
*/
|
|
121
|
+
export declare function fillIn(found: PairingForm, code: string): void;
|
|
122
|
+
/** The hello for `found`, with this page load's nonce. */
|
|
123
|
+
export declare function helloFor(found: PairingForm, nonce: string): PairingHello;
|
|
124
|
+
/** The content script's end of its port (`chrome.runtime.Port` is one). */
|
|
125
|
+
export interface ContentPort {
|
|
126
|
+
postMessage(message: unknown): void;
|
|
127
|
+
readonly onMessage: {
|
|
128
|
+
addListener(listener: (message: unknown) => void): void;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The content script of the relay's pairing page: if the page has app
|
|
133
|
+
* `app`'s pairing form, open a port to the worker (`connect`, with the name
|
|
134
|
+
* PAIRING_PORT), say who asks, and wait. Only the worker's fill with this
|
|
135
|
+
* page load's nonce is taken, once: its code is written into the field and
|
|
136
|
+
* the form submitted. Once per document, also if the script is put in again
|
|
137
|
+
* (after the user gave access with the page already open). Whether the
|
|
138
|
+
* page has the form. `page` is the content script's own page unless a test
|
|
139
|
+
* gives one.
|
|
140
|
+
*/
|
|
141
|
+
export declare function runPairingPage(options: {
|
|
142
|
+
app: string;
|
|
143
|
+
connect: () => ContentPort;
|
|
144
|
+
page?: {
|
|
145
|
+
document: Document;
|
|
146
|
+
topLevel: boolean;
|
|
147
|
+
pathname: string;
|
|
148
|
+
};
|
|
149
|
+
}): boolean;
|
|
150
|
+
/** The sender of a port, as far as the check needs it (`chrome.runtime.MessageSender`). */
|
|
151
|
+
export interface PageSender {
|
|
152
|
+
id?: string;
|
|
153
|
+
url?: string;
|
|
154
|
+
/** Chrome gives the document's origin; Firefox may not. */
|
|
155
|
+
origin?: string;
|
|
156
|
+
tab?: unknown;
|
|
157
|
+
frameId?: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A port from the pairing page of the relay at `relayOrigin`: this
|
|
161
|
+
* extension's content script, in a tab, in its top frame, on a page whose
|
|
162
|
+
* origin is exactly the relay's (port included) and whose path is
|
|
163
|
+
* `/authorize`. A page anywhere else can carry the same markup: it is
|
|
164
|
+
* ignored.
|
|
165
|
+
*/
|
|
166
|
+
export declare function isPairingSender(sender: PageSender, extensionId: string, relayOrigin: string | undefined): boolean;
|
|
167
|
+
/** A page will not say who asks in this time: it is dropped. */
|
|
168
|
+
export declare const HELLO_WAIT_MS = 5000;
|
|
169
|
+
/**
|
|
170
|
+
* The same request's page in the same tab within this time after a fill is
|
|
171
|
+
* the relay's answer to it: the code was not taken.
|
|
172
|
+
*/
|
|
173
|
+
export declare const RETRY_WINDOW_MS = 30000;
|
|
174
|
+
/** `takeCode`: how long to wait for the next code. */
|
|
175
|
+
export declare const CODE_WAIT_MS = 10000;
|
|
176
|
+
/** `takeCode`: a code with less time left than this is not used, the next one is. */
|
|
177
|
+
export declare const MIN_CODE_LEFT_MS = 5000;
|
|
178
|
+
/**
|
|
179
|
+
* A filled-in page's port is closed this long after the fill: the page has
|
|
180
|
+
* posted by then, and its answer, if any, is a new document with a port of
|
|
181
|
+
* its own.
|
|
182
|
+
*/
|
|
183
|
+
export declare const FILLED_CLOSE_MS = 5000;
|
|
184
|
+
/** The worker's end of a page's port (`chrome.runtime.Port` is one). */
|
|
185
|
+
export interface WorkerPort {
|
|
186
|
+
readonly sender?: PageSender;
|
|
187
|
+
postMessage(message: unknown): void;
|
|
188
|
+
disconnect(): void;
|
|
189
|
+
readonly onMessage: {
|
|
190
|
+
addListener(listener: (message: unknown) => void): void;
|
|
191
|
+
removeListener(listener: (message: unknown) => void): void;
|
|
192
|
+
};
|
|
193
|
+
readonly onDisconnect: {
|
|
194
|
+
addListener(listener: () => void): void;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* A pairing page's port in the worker. Its first message and its end are
|
|
199
|
+
* taken from the moment it connects: the worker may still be starting, and
|
|
200
|
+
* Chrome hands a message only to the listeners there are.
|
|
201
|
+
*/
|
|
202
|
+
export interface PagePort {
|
|
203
|
+
readonly sender: PageSender;
|
|
204
|
+
/** The first message; `undefined` if the port went before one came. */
|
|
205
|
+
readonly hello: Promise<unknown>;
|
|
206
|
+
/** Aborted when the page goes (or the worker closes the port). */
|
|
207
|
+
readonly signal: AbortSignal;
|
|
208
|
+
send(message: FillMessage): void;
|
|
209
|
+
close(): void;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* `port`, taken over at once (see PagePort): call it in `onConnect` itself,
|
|
213
|
+
* before any `await`.
|
|
214
|
+
*/
|
|
215
|
+
export declare function pagePort(port: WorkerPort): PagePort;
|
|
216
|
+
/**
|
|
217
|
+
* The user's answer to "Connect <name> (<host>)?": only `allow` fills in.
|
|
218
|
+
* `busy`: the extension could not ask (too many questions wait); the page is
|
|
219
|
+
* reported (`failed("busy")`), not dropped unseen.
|
|
220
|
+
*/
|
|
221
|
+
export type FillAnswer = "allow" | "deny" | "timeout" | "busy";
|
|
222
|
+
/** Why a page that asked got no code: the extension tells its user. */
|
|
223
|
+
export type FillFailure =
|
|
224
|
+
/** It could not be asked about (`ask` answered `busy`). */
|
|
225
|
+
"busy"
|
|
226
|
+
/** Allow, but no code came from the relay (`code` gave none). */
|
|
227
|
+
| "no-code";
|
|
228
|
+
/** The page a fill is for: its tab and the AI app that asks there. */
|
|
229
|
+
export interface FillContext {
|
|
230
|
+
tabId: number;
|
|
231
|
+
/** The AI app's own name (may be `""`) and the host the relay verified, as `ask` gets them. */
|
|
232
|
+
client: {
|
|
233
|
+
name: string;
|
|
234
|
+
host: string;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/** What `CodeFiller` needs from the extension: its parts of the fill-in. */
|
|
238
|
+
export interface FillHost {
|
|
239
|
+
/** This extension's id (`chrome.runtime.id`): only its own content script speaks. */
|
|
240
|
+
extensionId: string;
|
|
241
|
+
/** The app id of the extension's page: only forms with this `data-app`. */
|
|
242
|
+
app: string;
|
|
243
|
+
/**
|
|
244
|
+
* The origin of the relay's pages (`relayPageOrigin`) whose pairing page
|
|
245
|
+
* may be filled in; `undefined` for none (another relay than the one the
|
|
246
|
+
* extension fills in for).
|
|
247
|
+
*/
|
|
248
|
+
relayOrigin(): string | undefined;
|
|
249
|
+
/** AI access is on: connected, or on its way. Off, nothing is asked. */
|
|
250
|
+
aiOn(): boolean;
|
|
251
|
+
/** The user turned filling in on, for this relay (opt-in, off by default). */
|
|
252
|
+
enabled(): boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Ask the user whether to connect the AI app `client` (its own name for
|
|
255
|
+
* itself and the host the relay verified, both to be shown with invisible
|
|
256
|
+
* characters escaped) in tab `tabId`. `signal` withdraws the question:
|
|
257
|
+
* the page went, AI access or the setting went off, the relay changed,
|
|
258
|
+
* or the AI app connected meanwhile; answer then with anything but
|
|
259
|
+
* `allow`.
|
|
260
|
+
*/
|
|
261
|
+
ask(tabId: number, client: {
|
|
262
|
+
name: string;
|
|
263
|
+
host: string;
|
|
264
|
+
}, signal: AbortSignal): Promise<FillAnswer>;
|
|
265
|
+
/**
|
|
266
|
+
* The code to fill in now on the page `context`, with pairing held on for
|
|
267
|
+
* the relay to check it (`takeCode`); `undefined` if none came or
|
|
268
|
+
* `signal` aborted (the page went, or the fill was withdrawn as a
|
|
269
|
+
* question is). Even with a code, nothing is sent if what holds for
|
|
270
|
+
* asking no longer does.
|
|
271
|
+
*/
|
|
272
|
+
code(signal: AbortSignal, context: FillContext): Promise<string | undefined>;
|
|
273
|
+
/**
|
|
274
|
+
* No fill needs pairing held on any more: a filled-in code paired its AI
|
|
275
|
+
* app, or a fill ended without sending its code (withdrawn, the page
|
|
276
|
+
* went, no code) while no other fill is under way or waits for the
|
|
277
|
+
* relay's check. It may come again with nothing held: ignore it then.
|
|
278
|
+
*/
|
|
279
|
+
release(): void;
|
|
280
|
+
/** The page `context` filled in nothing for `why`, or was not asked about: say so. */
|
|
281
|
+
failed(why: FillFailure, context: FillContext): void;
|
|
282
|
+
/** The clock (`Date.now`; a test's own). */
|
|
283
|
+
now(): number;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The worker's side of filling in the code (DEC-199, DEC-203): a page's port
|
|
287
|
+
* is taken only from this extension's content script in the top frame of a
|
|
288
|
+
* tab at exactly the relay's origin, and only while AI access is on and the
|
|
289
|
+
* user turned filling in on. Then the user is asked, with the AI app's
|
|
290
|
+
* verified host; on Allow the code goes to that one page, which fills it in
|
|
291
|
+
* and submits.
|
|
292
|
+
*
|
|
293
|
+
* No loops: one question per page load (one port per document, one hello
|
|
294
|
+
* per port). When the same tab shows the page of the same request (the
|
|
295
|
+
* relay's `request_id`) again soon after a fill, it is the relay's answer
|
|
296
|
+
* that the code was not taken (it had just changed): filled once more with
|
|
297
|
+
* the code of then, without asking; the time after, nothing. Any other
|
|
298
|
+
* request asks. With `retry: false` that page is asked about like any
|
|
299
|
+
* other: every fill has a yes of its own. Don't allow, a timeout, the page
|
|
300
|
+
* going, AI access or the setting going off, another relay or the AI app
|
|
301
|
+
* connecting meanwhile fill nothing, and typing by hand works as before.
|
|
302
|
+
*/
|
|
303
|
+
export declare class CodeFiller {
|
|
304
|
+
#private;
|
|
305
|
+
/**
|
|
306
|
+
* `grants`: the ids of the grants there are already, if the extension kept
|
|
307
|
+
* them between worker starts (not new when listed again); without them,
|
|
308
|
+
* the first `grantsChanged` is taken as the list there is, nothing in it
|
|
309
|
+
* new. `retry`: the one more fill without asking when the same request's
|
|
310
|
+
* page comes back to the same tab soon after a fill (on unless `false`;
|
|
311
|
+
* off, that page is asked about like any other, one question per page
|
|
312
|
+
* load, and never filled without a yes). `closeAfterMs`: FILLED_CLOSE_MS
|
|
313
|
+
* unless a test's is shorter.
|
|
314
|
+
*/
|
|
315
|
+
constructor(host: FillHost, options?: {
|
|
316
|
+
grants?: Iterable<string>;
|
|
317
|
+
retry?: boolean;
|
|
318
|
+
closeAfterMs?: number;
|
|
319
|
+
});
|
|
320
|
+
/**
|
|
321
|
+
* A pairing page's port: checked, then asked about and maybe filled in.
|
|
322
|
+
* Never rejects: a host callback that throws fills nothing, closes the
|
|
323
|
+
* port and is logged.
|
|
324
|
+
*/
|
|
325
|
+
page(port: PagePort): Promise<void>;
|
|
326
|
+
/**
|
|
327
|
+
* The relay's list of grants (`grantschange`): an AI app that just
|
|
328
|
+
* connected (typed by hand, or filled in) withdraws the questions for its
|
|
329
|
+
* host, and its fills are done with.
|
|
330
|
+
*/
|
|
331
|
+
grantsChanged(grants: readonly {
|
|
332
|
+
grantId: string;
|
|
333
|
+
host: string;
|
|
334
|
+
}[]): void;
|
|
335
|
+
/**
|
|
336
|
+
* AI access off, or filling in turned off: the questions waiting are
|
|
337
|
+
* withdrawn and no page gets the one more fill.
|
|
338
|
+
*/
|
|
339
|
+
withdrawAll(): void;
|
|
340
|
+
/**
|
|
341
|
+
* Another relay: no page of the one before is asked about or filled in,
|
|
342
|
+
* and the new relay's first list of grants is taken as it is.
|
|
343
|
+
*/
|
|
344
|
+
reset(): void;
|
|
345
|
+
}
|
|
346
|
+
/** Where the pairing codes come from (`pairingCodes(mcp)`). */
|
|
347
|
+
export interface CodeSource {
|
|
348
|
+
current(): PairingCode | undefined;
|
|
349
|
+
/** Call `listener` on every new code (or none); returns how to stop. */
|
|
350
|
+
onChange(listener: () => void): () => void;
|
|
351
|
+
}
|
|
352
|
+
/** The pairing codes of the extension's `TabMcp`, for `takeCode`. */
|
|
353
|
+
export declare function pairingCodes(mcp: Pick<TabMcp, "pairingCode" | "addEventListener" | "removeEventListener">): CodeSource;
|
|
354
|
+
/**
|
|
355
|
+
* The code to fill in. The current one if it has `minLeftMs` left by this
|
|
356
|
+
* clock (or an expiry that cannot be read); else the next one the relay
|
|
357
|
+
* sends, which is fresh whatever the clocks say. The same code sent again
|
|
358
|
+
* is not the next one: the relay answers each `pairing.start` with the code
|
|
359
|
+
* it shows, so `startPairing()` with pairing on already brings back the
|
|
360
|
+
* code that is about to change; it counts only if its expiry now leaves
|
|
361
|
+
* `minLeftMs`. If no next one comes within `waitMs`, the current one after
|
|
362
|
+
* all: with this clock ahead every code would look expired, so the fill
|
|
363
|
+
* then waits the whole `waitMs` before it gets that code. The relay
|
|
364
|
+
* refuses a code that has expired; the one more fill for the same request
|
|
365
|
+
* covers that, or with `retry: false` a new question. `undefined` only
|
|
366
|
+
* without any code, or when `signal` aborts. Pairing must be on
|
|
367
|
+
* (`startPairing()`) for codes to come.
|
|
368
|
+
*/
|
|
369
|
+
export declare function takeCode(source: CodeSource, signal: AbortSignal, options: {
|
|
370
|
+
now: number;
|
|
371
|
+
waitMs?: number;
|
|
372
|
+
minLeftMs?: number;
|
|
373
|
+
}): Promise<string | undefined>;
|