@ractive-ch/tab-mcp-client 0.15.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 +454 -147
- 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-g6wk37yd.js → connection-1d8rxgbq.js} +247 -126
- package/connection-1d8rxgbq.js.map +16 -0
- package/connection.d.ts +7 -4
- 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 +257 -240
- package/index.js.map +6 -6
- package/mapping.d.ts +37 -4
- package/mcp.d.ts +23 -8
- package/package.json +1 -1
- package/react.d.ts +8 -10
- package/react.js +18 -14
- package/react.js.map +3 -3
- package/registry.d.ts +12 -5
- package/secret.d.ts +5 -2
- package/serve.d.ts +26 -4
- package/setup.d.ts +15 -25
- package/setup.js +1 -1
- package/strings.d.ts +107 -0
- package/tab-mcp.d.ts +60 -35
- package/types.d.ts +146 -68
- package/webmcp.d.ts +13 -18
- package/cdn/connection-hgt931xk.min.js +0 -12
- package/cdn/connection-hgt931xk.min.js.map +0 -22
- package/cdn/ui-2nv84ry7.min.js +0 -86
- package/cdn/ui-2nv84ry7.min.js.map +0 -14
- package/connection-g6wk37yd.js.map +0 -16
- package/index-nmn1j689.js.map +0 -11
- package/ui-04mwfxm9.js +0 -783
- package/ui-04mwfxm9.js.map +0 -11
- package/ui.d.ts +0 -83
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allowedFor,
|
|
3
|
+
stringsOf,
|
|
4
|
+
format,
|
|
5
|
+
fill,
|
|
6
|
+
el,
|
|
7
|
+
button,
|
|
8
|
+
visible,
|
|
9
|
+
clientLabel,
|
|
10
|
+
newDialog
|
|
11
|
+
} from "./index-jnz7w9xa.js";
|
|
12
|
+
import"./index-dmh5vm5m.js";
|
|
13
|
+
|
|
14
|
+
// src/confirm.ts
|
|
15
|
+
function showArguments(args) {
|
|
16
|
+
try {
|
|
17
|
+
return visible(JSON.stringify(args, null, 2));
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
var ALLOW_DELAY_MS = 750;
|
|
23
|
+
var DESCRIBED_ARGUMENTS = 500;
|
|
24
|
+
var queues = new WeakMap;
|
|
25
|
+
function confirmDialog(request, doc, options = {}) {
|
|
26
|
+
if (request.signal.aborted)
|
|
27
|
+
return Promise.resolve("deny");
|
|
28
|
+
let queue = queues.get(doc);
|
|
29
|
+
if (queue === undefined) {
|
|
30
|
+
queue = { shown: false, waiting: [] };
|
|
31
|
+
queues.set(doc, queue);
|
|
32
|
+
}
|
|
33
|
+
const q = queue;
|
|
34
|
+
const next = () => {
|
|
35
|
+
const start = q.waiting.shift();
|
|
36
|
+
q.shown = start !== undefined;
|
|
37
|
+
start?.();
|
|
38
|
+
q.changed?.();
|
|
39
|
+
};
|
|
40
|
+
const show = () => {
|
|
41
|
+
try {
|
|
42
|
+
return showConfirm(request, doc, options, q, next);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
next();
|
|
45
|
+
return Promise.reject(error);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (!q.shown) {
|
|
49
|
+
q.shown = true;
|
|
50
|
+
return show();
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve) => {
|
|
53
|
+
const start = () => {
|
|
54
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
55
|
+
if (options.allowedNow?.() === true) {
|
|
56
|
+
resolve("allow");
|
|
57
|
+
next();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
resolve(show());
|
|
61
|
+
};
|
|
62
|
+
const onAbort = () => {
|
|
63
|
+
q.waiting.splice(q.waiting.indexOf(start), 1);
|
|
64
|
+
q.changed?.();
|
|
65
|
+
resolve("deny");
|
|
66
|
+
};
|
|
67
|
+
request.signal.addEventListener("abort", onAbort, { once: true });
|
|
68
|
+
q.waiting.push(start);
|
|
69
|
+
q.changed?.();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function showConfirm(request, doc, options, queue, next) {
|
|
73
|
+
const s = options.strings ?? stringsOf(undefined);
|
|
74
|
+
const delay = options.allowDelayMs ?? ALLOW_DELAY_MS;
|
|
75
|
+
const tool = request.tool.title ?? request.tool.name;
|
|
76
|
+
const client = clientLabel(request.client, s);
|
|
77
|
+
const names = { tool, client };
|
|
78
|
+
const { dialog, id } = newDialog(doc, "tab-mcp-confirm", s, ...fill(doc, s.confirmTitle, names));
|
|
79
|
+
const waiting = el(doc, "p", { className: "tab-mcp-waiting" });
|
|
80
|
+
const showWaiting = () => {
|
|
81
|
+
const n = queue.waiting.length;
|
|
82
|
+
waiting.hidden = n === 0;
|
|
83
|
+
waiting.textContent = n === 1 ? s.waitingOne : format(s.waitingMany, { n: String(n) });
|
|
84
|
+
};
|
|
85
|
+
queue.changed = showWaiting;
|
|
86
|
+
showWaiting();
|
|
87
|
+
const deny = button(doc, s.deny, () => dialog.close("deny"), "tab-mcp-deny", "primary");
|
|
88
|
+
const approving = (text, answer, className) => {
|
|
89
|
+
const node = button(doc, text, () => {
|
|
90
|
+
if (!node.disabled)
|
|
91
|
+
dialog.close(answer);
|
|
92
|
+
}, className);
|
|
93
|
+
return node;
|
|
94
|
+
};
|
|
95
|
+
const approve = [approving(s.allow, "allow", "tab-mcp-allow")];
|
|
96
|
+
const extra = [];
|
|
97
|
+
if (options.alwaysAllow === true) {
|
|
98
|
+
approve.unshift(approving(s.allowUntilReload, "always", "tab-mcp-always"));
|
|
99
|
+
extra.push(el(doc, "p", { className: "tab-mcp-always-note" }, ...fill(doc, s.allowUntilReloadNote, names)));
|
|
100
|
+
}
|
|
101
|
+
const actions = el(doc, "div", { className: "tab-mcp-actions" }, deny, ...approve.flatMap((b) => [" ", b]));
|
|
102
|
+
let settled = false;
|
|
103
|
+
let seen = false;
|
|
104
|
+
const enable = () => {
|
|
105
|
+
for (const b of approve)
|
|
106
|
+
b.disabled = !(settled && seen);
|
|
107
|
+
};
|
|
108
|
+
enable();
|
|
109
|
+
const shown = showArguments(request.arguments);
|
|
110
|
+
const args = el(doc, "pre", {
|
|
111
|
+
className: "tab-mcp-arguments",
|
|
112
|
+
id: `${id}-arguments`,
|
|
113
|
+
text: shown ?? s.argumentsHidden
|
|
114
|
+
});
|
|
115
|
+
if (shown === undefined) {
|
|
116
|
+
for (const node of [...approve, ...extra])
|
|
117
|
+
node.hidden = true;
|
|
118
|
+
}
|
|
119
|
+
args.dir = "ltr";
|
|
120
|
+
args.style.setProperty("white-space", "pre-wrap");
|
|
121
|
+
args.style.setProperty("overflow-wrap", "anywhere");
|
|
122
|
+
args.style.setProperty("max-height", "var(--tab-mcp-arguments-height, min(50vh, 24rem))");
|
|
123
|
+
args.style.setProperty("overflow", "auto");
|
|
124
|
+
args.hidden = Object.keys(request.arguments).length === 0;
|
|
125
|
+
const scrollNote = el(doc, "p", {
|
|
126
|
+
className: "tab-mcp-scroll-note",
|
|
127
|
+
text: s.scrollToAllow
|
|
128
|
+
});
|
|
129
|
+
scrollNote.hidden = true;
|
|
130
|
+
const who = el(doc, "p", { id: `${id}-who` }, ...fill(doc, s.confirmWho, names));
|
|
131
|
+
dialog.setAttribute("aria-describedby", shown !== undefined && !args.hidden && shown.length <= DESCRIBED_ARGUMENTS ? `${who.id} ${args.id}` : who.id);
|
|
132
|
+
dialog.append(who, el(doc, "p", {
|
|
133
|
+
className: "tab-mcp-description",
|
|
134
|
+
text: request.tool.description
|
|
135
|
+
}), args, scrollNote, actions, ...extra, waiting);
|
|
136
|
+
doc.body.append(dialog);
|
|
137
|
+
const view = doc.defaultView;
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
const onAbort = () => dialog.close("deny");
|
|
140
|
+
request.signal.addEventListener("abort", onAbort, { once: true });
|
|
141
|
+
let timer;
|
|
142
|
+
let title;
|
|
143
|
+
const untitle = () => {
|
|
144
|
+
if (title !== undefined && doc.title === title.shown)
|
|
145
|
+
doc.title = title.page;
|
|
146
|
+
title = undefined;
|
|
147
|
+
};
|
|
148
|
+
const retitle = () => {
|
|
149
|
+
if (doc.visibilityState !== "hidden")
|
|
150
|
+
untitle();
|
|
151
|
+
else if (title === undefined) {
|
|
152
|
+
title = { page: doc.title, shown: `${s.titlePrefix}${doc.title}` };
|
|
153
|
+
doc.title = title.shown;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const arm = (event) => {
|
|
157
|
+
if (event?.type === "close" && event.target === dialog)
|
|
158
|
+
return;
|
|
159
|
+
retitle();
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
timer = undefined;
|
|
162
|
+
settled = false;
|
|
163
|
+
enable();
|
|
164
|
+
if (event?.type === "blur" || doc.visibilityState === "hidden" || !doc.hasFocus())
|
|
165
|
+
return;
|
|
166
|
+
timer = setTimeout(() => {
|
|
167
|
+
settled = true;
|
|
168
|
+
enable();
|
|
169
|
+
}, delay);
|
|
170
|
+
};
|
|
171
|
+
const check = () => {
|
|
172
|
+
if (seen)
|
|
173
|
+
return;
|
|
174
|
+
if (args.scrollTop + args.clientHeight < args.scrollHeight - 2) {
|
|
175
|
+
scrollNote.hidden = false;
|
|
176
|
+
args.tabIndex = 0;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
seen = true;
|
|
180
|
+
scrollNote.hidden = true;
|
|
181
|
+
enable();
|
|
182
|
+
};
|
|
183
|
+
const guard = (event) => {
|
|
184
|
+
if (settled)
|
|
185
|
+
return;
|
|
186
|
+
const onButton = event.target?.localName === "button";
|
|
187
|
+
if (event.key === "Escape" || onButton && (event.key === "Enter" || event.key === " "))
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
};
|
|
190
|
+
const onCancel = (event) => {
|
|
191
|
+
if (!settled)
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
};
|
|
194
|
+
doc.addEventListener("visibilitychange", arm);
|
|
195
|
+
doc.addEventListener("close", arm, true);
|
|
196
|
+
view?.addEventListener("focus", arm);
|
|
197
|
+
view?.addEventListener("blur", arm);
|
|
198
|
+
view?.addEventListener("resize", check);
|
|
199
|
+
args.addEventListener("scroll", check);
|
|
200
|
+
dialog.addEventListener("keydown", guard);
|
|
201
|
+
dialog.addEventListener("keyup", guard);
|
|
202
|
+
dialog.addEventListener("cancel", onCancel);
|
|
203
|
+
const cleanup = () => {
|
|
204
|
+
clearTimeout(timer);
|
|
205
|
+
untitle();
|
|
206
|
+
doc.removeEventListener("visibilitychange", arm);
|
|
207
|
+
doc.removeEventListener("close", arm, true);
|
|
208
|
+
view?.removeEventListener("focus", arm);
|
|
209
|
+
view?.removeEventListener("blur", arm);
|
|
210
|
+
view?.removeEventListener("resize", check);
|
|
211
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
212
|
+
dialog.remove();
|
|
213
|
+
if (queue.changed === showWaiting)
|
|
214
|
+
queue.changed = undefined;
|
|
215
|
+
};
|
|
216
|
+
dialog.addEventListener("close", () => {
|
|
217
|
+
const value = dialog.returnValue;
|
|
218
|
+
cleanup();
|
|
219
|
+
resolve(value === "allow" || value === "always" ? value : "deny");
|
|
220
|
+
next();
|
|
221
|
+
}, { once: true });
|
|
222
|
+
try {
|
|
223
|
+
dialog.showModal();
|
|
224
|
+
} catch (error) {
|
|
225
|
+
cleanup();
|
|
226
|
+
reject(error);
|
|
227
|
+
next();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
deny.focus();
|
|
231
|
+
arm();
|
|
232
|
+
check();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function confirmInPage(mcp, request, doc, options = {}) {
|
|
236
|
+
const { client } = request;
|
|
237
|
+
const dialogOptions = {
|
|
238
|
+
strings: stringsOf(options.ui),
|
|
239
|
+
allowDelayMs: options.allowDelayMs
|
|
240
|
+
};
|
|
241
|
+
if (client.kind !== "relay")
|
|
242
|
+
return confirmDialog(request, doc, dialogOptions).then((answer) => answer === "allow");
|
|
243
|
+
const { grantId } = client;
|
|
244
|
+
const allowed = allowedFor(mcp);
|
|
245
|
+
const allowedNow = () => allowed.has(grantId, request.tool);
|
|
246
|
+
if (allowedNow())
|
|
247
|
+
return Promise.resolve(true);
|
|
248
|
+
return confirmDialog(request, doc, {
|
|
249
|
+
...dialogOptions,
|
|
250
|
+
alwaysAllow: options.alwaysAllow,
|
|
251
|
+
allowedNow
|
|
252
|
+
}).then((answer) => {
|
|
253
|
+
if (answer === "always" && mcp.grants.some((g) => g.grantId === grantId))
|
|
254
|
+
allowed.add(grantId, request.tool);
|
|
255
|
+
return answer !== "deny";
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
export {
|
|
259
|
+
confirmInPage
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
//# debugId=75D3F22D19548B9A64756E2164756E21
|
|
263
|
+
//# sourceMappingURL=confirm-fgnjgd08.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/confirm.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The confirmation of consequential tools, loaded on demand: a `<dialog>`\n * per call, one shown at a time per document, and the tools a user allowed\n * until reload (`always-allowed.ts`).\n */\n\nimport { allowedFor } from \"./always-allowed.ts\";\nimport {\n\tbutton,\n\tclientLabel,\n\tel,\n\tfill,\n\tformat,\n\tnewDialog,\n\tstringsOf,\n\tvisible,\n} from \"./dialog.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type { ConfirmRequest, DialogOptions } from \"./types.ts\";\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) Invisible and\n * direction characters are shown as escapes, so the text is still JSON for\n * the same arguments; the tool gets them unchanged. `undefined` when they\n * cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn visible(JSON.stringify(args, null, 2));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * How long \"Allow\" stays disabled after the confirmation is shown, while the\n * page is visible and focused (CU 17: a constant; tests pass `allowDelayMs`).\n */\nexport const ALLOW_DELAY_MS = 750;\n\n/** The user's answer: \"always\" allows this tool for this AI app until reload. */\nexport type DialogAnswer = \"allow\" | \"always\" | \"deny\";\n\n/** Arguments up to this many characters are read out with the question. */\nconst DESCRIBED_ARGUMENTS = 500;\n\n/** Options of `confirmDialog`. */\nexport interface ConfirmDialogOptions {\n\t/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */\n\tallowDelayMs?: number | undefined;\n\t/** Offer \"Allow until reload\". */\n\talwaysAllow?: boolean | undefined;\n\t/** Asked when a waiting call's turn comes: `true` answers \"allow\" unseen. */\n\tallowedNow?: () => boolean;\n\tstrings?: DialogStrings;\n}\n\n/**\n * The confirmations of one document: one is shown at a time, the others\n * wait in order, so that the click that answered one cannot answer the next\n * (each starts its own delay when it is shown).\n */\ninterface ConfirmQueue {\n\tshown: boolean;\n\twaiting: (() => void)[];\n\t/** Updates the shown dialog's line about the calls that wait. */\n\tchanged?: (() => void) | undefined;\n}\n\nconst queues = new WeakMap<Document, ConfirmQueue>();\n\n/**\n * Ask whether a consequential tool may run. \"Allow until reload\" is offered\n * only with `alwaysAllow` (DEC-096). One confirmation is shown at a time per\n * document; the others wait their turn, and a call cancelled while it waits\n * is never shown. \"Allow\" and \"Allow until reload\" stay disabled until the\n * page has been visible and focused for 750 ms while the dialog is open and\n * is the top one, so a click meant for the page, the click that brings the\n * tab or window back, or the one that closed another dialog, cannot\n * approve; leaving the page disables them again. They also wait until the\n * arguments have been scrolled to their end. Before the delay has run out,\n * Enter or Space on a button and Escape are ignored, so typing meant for the\n * page cannot refuse either. Everything else (Don't allow, Escape, an\n * aborted call) is \"deny\". `allowedNow` is asked when a waiting call's turn\n * comes: `true` (the user allowed it until reload meanwhile) answers \"allow\"\n * without showing it.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions = {},\n): Promise<DialogAnswer> {\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tlet queue = queues.get(doc);\n\tif (queue === undefined) {\n\t\tqueue = { shown: false, waiting: [] };\n\t\tqueues.set(doc, queue);\n\t}\n\tconst q = queue;\n\t/** The shown confirmation closed: the next one, if any. */\n\tconst next = () => {\n\t\tconst start = q.waiting.shift();\n\t\tq.shown = start !== undefined;\n\t\tstart?.();\n\t\tq.changed?.();\n\t};\n\tconst show = () => {\n\t\ttry {\n\t\t\treturn showConfirm(request, doc, options, q, next);\n\t\t} catch (error) {\n\t\t\tnext(); // not shown: the queue goes on\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t};\n\tif (!q.shown) {\n\t\tq.shown = true;\n\t\treturn show();\n\t}\n\treturn new Promise((resolve) => {\n\t\tconst start = () => {\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tif (options.allowedNow?.() === true) {\n\t\t\t\tresolve(\"allow\");\n\t\t\t\tnext();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(show());\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tq.waiting.splice(q.waiting.indexOf(start), 1);\n\t\t\tq.changed?.();\n\t\t\tresolve(\"deny\");\n\t\t};\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tq.waiting.push(start);\n\t\tq.changed?.();\n\t});\n}\n\n/** `confirmDialog` once it is this request's turn; calls `next` when it closes. */\nfunction showConfirm(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions,\n\tqueue: ConfirmQueue,\n\tnext: () => void,\n): Promise<DialogAnswer> {\n\tconst s = options.strings ?? stringsOf(undefined);\n\tconst delay = options.allowDelayMs ?? ALLOW_DELAY_MS;\n\tconst tool = request.tool.title ?? request.tool.name;\n\tconst client = clientLabel(request.client, s);\n\tconst names = { tool, client };\n\tconst { dialog, id } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-confirm\",\n\t\ts,\n\t\t...fill(doc, s.confirmTitle, names),\n\t);\n\tconst waiting = el(doc, \"p\", { className: \"tab-mcp-waiting\" });\n\tconst showWaiting = () => {\n\t\tconst n = queue.waiting.length;\n\t\twaiting.hidden = n === 0;\n\t\twaiting.textContent =\n\t\t\tn === 1 ? s.waitingOne : format(s.waitingMany, { n: String(n) });\n\t};\n\tqueue.changed = showWaiting;\n\tshowWaiting();\n\t// The safe choice is the default: focused, and the one that stands out.\n\tconst deny = button(\n\t\tdoc,\n\t\ts.deny,\n\t\t() => dialog.close(\"deny\"),\n\t\t\"tab-mcp-deny\",\n\t\t\"primary\",\n\t);\n\tconst approving = (text: string, answer: DialogAnswer, className: string) => {\n\t\tconst node = button(\n\t\t\tdoc,\n\t\t\ttext,\n\t\t\t() => {\n\t\t\t\tif (!node.disabled) dialog.close(answer);\n\t\t\t},\n\t\t\tclassName,\n\t\t);\n\t\treturn node;\n\t};\n\t// The approving buttons: Allow, and Allow until reload when the page offers it.\n\tconst approve = [approving(s.allow, \"allow\", \"tab-mcp-allow\")];\n\tconst extra: HTMLElement[] = [];\n\tif (options.alwaysAllow === true) {\n\t\t// Left of Allow: not where most platforms put the default (CU 11).\n\t\tapprove.unshift(approving(s.allowUntilReload, \"always\", \"tab-mcp-always\"));\n\t\textra.push(\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"p\",\n\t\t\t\t{ className: \"tab-mcp-always-note\" },\n\t\t\t\t...fill(doc, s.allowUntilReloadNote, names),\n\t\t\t),\n\t\t);\n\t}\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t...approve.flatMap((b) => [\" \", b]),\n\t);\n\t// Approving needs both: the delay ran out while the user saw the page\n\t// (`settled`), and the arguments were seen to their end (`seen`).\n\tlet settled = false;\n\tlet seen = false;\n\tconst enable = () => {\n\t\tfor (const b of approve) b.disabled = !(settled && seen);\n\t};\n\tenable();\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\tid: `${id}-arguments`,\n\t\ttext: shown ?? s.argumentsHidden,\n\t});\n\tif (shown === undefined) {\n\t\tfor (const node of [...approve, ...extra]) node.hidden = true;\n\t}\n\targs.dir = \"ltr\";\n\t// Inline, so the arguments stay readable in full without the stylesheet:\n\t// wrapped (also a long word, at 360 px), scrolling when long.\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"overflow-wrap\", \"anywhere\");\n\targs.style.setProperty(\n\t\t\"max-height\",\n\t\t\"var(--tab-mcp-arguments-height, min(50vh, 24rem))\",\n\t);\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\t// The caller chooses the order of the keys, so what matters may come\n\t// last: below the end of the box, the user is told, and Allow waits.\n\tconst scrollNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-scroll-note\",\n\t\ttext: s.scrollToAllow,\n\t});\n\tscrollNote.hidden = true;\n\tconst who = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ id: `${id}-who` },\n\t\t...fill(doc, s.confirmWho, names),\n\t);\n\tdialog.setAttribute(\n\t\t\"aria-describedby\",\n\t\tshown !== undefined && !args.hidden && shown.length <= DESCRIBED_ARGUMENTS\n\t\t\t? `${who.id} ${args.id}`\n\t\t\t: who.id,\n\t);\n\tdialog.append(\n\t\twho,\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tscrollNote,\n\t\tactions,\n\t\t...extra,\n\t\twaiting,\n\t);\n\tdoc.body.append(dialog);\n\tconst view = doc.defaultView;\n\treturn new Promise((resolve, reject) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t// In a hidden tab, the tab's title says that the page asks (CU 9): the\n\t\t// AI app waits meanwhile. Put back when the tab is shown or the dialog\n\t\t// closes, unless the page changed its title since.\n\t\tlet title: { page: string; shown: string } | undefined;\n\t\tconst untitle = () => {\n\t\t\tif (title !== undefined && doc.title === title.shown)\n\t\t\t\tdoc.title = title.page;\n\t\t\ttitle = undefined;\n\t\t};\n\t\tconst retitle = () => {\n\t\t\tif (doc.visibilityState !== \"hidden\") untitle();\n\t\t\telse if (title === undefined) {\n\t\t\t\ttitle = { page: doc.title, shown: `${s.titlePrefix}${doc.title}` };\n\t\t\t\tdoc.title = title.shown;\n\t\t\t}\n\t\t};\n\t\t// The delay counts only while the user can see the page: tools are\n\t\t// called while the user is in the AI app, so the dialog often opens in\n\t\t// a background tab or window. Any change starts it again from zero\n\t\t// (DEC-087), and so does another dialog of the page that closes over\n\t\t// this one.\n\t\tconst arm = (event?: Event) => {\n\t\t\tif (event?.type === \"close\" && event.target === dialog) return;\n\t\t\tretitle();\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t\tsettled = false;\n\t\t\tenable();\n\t\t\tif (\n\t\t\t\tevent?.type === \"blur\" ||\n\t\t\t\tdoc.visibilityState === \"hidden\" ||\n\t\t\t\t!doc.hasFocus()\n\t\t\t)\n\t\t\t\treturn;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tsettled = true;\n\t\t\t\tenable();\n\t\t\t}, delay);\n\t\t};\n\t\t// Scrolled to the end, or nothing to scroll (also without layout).\n\t\tconst check = () => {\n\t\t\tif (seen) return;\n\t\t\tif (args.scrollTop + args.clientHeight < args.scrollHeight - 2) {\n\t\t\t\tscrollNote.hidden = false;\n\t\t\t\targs.tabIndex = 0; // to scroll it with the keyboard\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tseen = true;\n\t\t\tscrollNote.hidden = true;\n\t\t\tenable();\n\t\t};\n\t\t// Not answered by a key before the delay has run out.\n\t\tconst guard = (event: KeyboardEvent) => {\n\t\t\tif (settled) return;\n\t\t\tconst onButton = (event.target as Element | null)?.localName === \"button\";\n\t\t\tif (\n\t\t\t\tevent.key === \"Escape\" ||\n\t\t\t\t(onButton && (event.key === \"Enter\" || event.key === \" \"))\n\t\t\t)\n\t\t\t\tevent.preventDefault();\n\t\t};\n\t\tconst onCancel = (event: Event) => {\n\t\t\tif (!settled) event.preventDefault();\n\t\t};\n\t\tdoc.addEventListener(\"visibilitychange\", arm);\n\t\tdoc.addEventListener(\"close\", arm, true); // `close` does not bubble\n\t\tview?.addEventListener(\"focus\", arm);\n\t\tview?.addEventListener(\"blur\", arm);\n\t\tview?.addEventListener(\"resize\", check);\n\t\targs.addEventListener(\"scroll\", check);\n\t\tdialog.addEventListener(\"keydown\", guard);\n\t\tdialog.addEventListener(\"keyup\", guard);\n\t\tdialog.addEventListener(\"cancel\", onCancel);\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tuntitle();\n\t\t\tdoc.removeEventListener(\"visibilitychange\", arm);\n\t\t\tdoc.removeEventListener(\"close\", arm, true);\n\t\t\tview?.removeEventListener(\"focus\", arm);\n\t\t\tview?.removeEventListener(\"blur\", arm);\n\t\t\tview?.removeEventListener(\"resize\", check);\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tdialog.remove();\n\t\t\tif (queue.changed === showWaiting) queue.changed = undefined;\n\t\t};\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tcleanup();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t\tnext();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\ttry {\n\t\t\tdialog.showModal();\n\t\t} catch (error) {\n\t\t\t// Never shown, so never closed: the queue must not wait for it.\n\t\t\tcleanup();\n\t\t\treject(error);\n\t\t\tnext();\n\t\t\treturn;\n\t\t}\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\tarm();\n\t\tcheck();\n\t});\n}\n\n/**\n * `TabMcp.confirmInPage`: the confirmation, and the tools allowed until\n * reload (`always-allowed.ts`). Only for an AI app through the relay: an\n * agent in the browser and a served port have no identity to remember an\n * answer for (DEC-115, DEC-124).\n */\nexport function confirmInPage(\n\tmcp: TabMcp,\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: {\n\t\talwaysAllow?: boolean | undefined;\n\t\tui?: DialogOptions | undefined;\n\t\t/** Tests only. */\n\t\tallowDelayMs?: number | undefined;\n\t} = {},\n): Promise<boolean> {\n\tconst { client } = request;\n\tconst dialogOptions = {\n\t\tstrings: stringsOf(options.ui),\n\t\tallowDelayMs: options.allowDelayMs,\n\t};\n\tif (client.kind !== \"relay\")\n\t\treturn confirmDialog(request, doc, dialogOptions).then(\n\t\t\t(answer) => answer === \"allow\",\n\t\t);\n\tconst { grantId } = client;\n\tconst allowed = allowedFor(mcp);\n\tconst allowedNow = () => allowed.has(grantId, request.tool);\n\tif (allowedNow()) return Promise.resolve(true);\n\t// Asked again when its turn comes: the call before it in the queue may\n\t// have been allowed until reload.\n\treturn confirmDialog(request, doc, {\n\t\t...dialogOptions,\n\t\talwaysAllow: options.alwaysAllow,\n\t\tallowedNow,\n\t}).then((answer) => {\n\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\tif (answer === \"always\" && mcp.grants.some((g) => g.grantId === grantId))\n\t\t\tallowed.add(grantId, request.tool);\n\t\treturn answer !== \"deny\";\n\t});\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;AA4BA,SAAS,aAAa,CAAC,MAAmD;AAAA,EACzE,IAAI;AAAA,IACH,OAAO,QAAQ,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;AAAA,IAC3C,MAAM;AAAA,IACP;AAAA;AAAA;AAQK,IAAM,iBAAiB;AAM9B,IAAM,sBAAsB;AAyB5B,IAAM,SAAS,IAAI;AAkBZ,SAAS,aAAa,CAC5B,SACA,KACA,UAAgC,CAAC,GACT;AAAA,EACxB,IAAI,QAAQ,OAAO;AAAA,IAAS,OAAO,QAAQ,QAAQ,MAAM;AAAA,EACzD,IAAI,QAAQ,OAAO,IAAI,GAAG;AAAA,EAC1B,IAAI,UAAU,WAAW;AAAA,IACxB,QAAQ,EAAE,OAAO,OAAO,SAAS,CAAC,EAAE;AAAA,IACpC,OAAO,IAAI,KAAK,KAAK;AAAA,EACtB;AAAA,EACA,MAAM,IAAI;AAAA,EAEV,MAAM,OAAO,MAAM;AAAA,IAClB,MAAM,QAAQ,EAAE,QAAQ,MAAM;AAAA,IAC9B,EAAE,QAAQ,UAAU;AAAA,IACpB,QAAQ;AAAA,IACR,EAAE,UAAU;AAAA;AAAA,EAEb,MAAM,OAAO,MAAM;AAAA,IAClB,IAAI;AAAA,MACH,OAAO,YAAY,SAAS,KAAK,SAAS,GAAG,IAAI;AAAA,MAChD,OAAO,OAAO;AAAA,MACf,KAAK;AAAA,MACL,OAAO,QA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KI,CAAC,GACc;AAAA,EACnB,QAAQ,WAAW;AAAA,EACnB,MAAM,gBAAgB;AAAA,IACrB,SAAS,UAAU,QAAQ,EAAE;AAAA,IAC7B,cAAc,QAAQ;AAAA,EACvB;AAAA,EACA,IAAI,OAAO,SAAS;AAAA,IACnB,OAAO,cAAc,SAAS,KAAK,aAAa,EAAE,KACjD,CAAC,WAAW,WAAW,OACxB;AAAA,EACD,QAAQ,YAAY;AAAA,EACpB,MAAM,UAAU,WAAW,GAAG;AAAA,EAC9B,MAAM,aAAa,MAAM,QAAQ,IAAI,SAAS,QAAQ,IAAI;AAAA,EAC1D,IAAI,WAAW;AAAA,IAAG,OAAO,QAAQ,QAAQ,IAAI;AAAA,EAG7C,OAAO,cAAc,SAAS,KAAK;AAAA,OAC/B;AAAA,IACH,aAAa,QAAQ;AAAA,IACrB;AAAA,EACD,CAAC,EAAE,KAAK,CAAC,WAAW;AAAA,IAEnB,IAAI,WAAW,YAAY,IAAI,OAAO,KAAK,CAAC,MAAM,EAAE,YAAY,OAAO;AAAA,MACtE,QAAQ,IAAI,SAAS,QAAQ,IAAI;AAAA,IAClC,OAAO,WAAW;AAAA,GAClB;AAAA;",
|
|
8
|
+
"debugId": "75D3F22D19548B9A64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/confirm.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The confirmation of consequential tools, loaded on demand: a `<dialog>`
|
|
3
|
+
* per call, one shown at a time per document, and the tools a user allowed
|
|
4
|
+
* until reload (`always-allowed.ts`).
|
|
5
|
+
*/
|
|
6
|
+
import type { DialogStrings } from "./strings.js";
|
|
7
|
+
import type { TabMcp } from "./tab-mcp.js";
|
|
8
|
+
import type { ConfirmRequest, DialogOptions } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* How long "Allow" stays disabled after the confirmation is shown, while the
|
|
11
|
+
* page is visible and focused (CU 17: a constant; tests pass `allowDelayMs`).
|
|
12
|
+
*/
|
|
13
|
+
export declare const ALLOW_DELAY_MS = 750;
|
|
14
|
+
/** The user's answer: "always" allows this tool for this AI app until reload. */
|
|
15
|
+
export type DialogAnswer = "allow" | "always" | "deny";
|
|
16
|
+
/** Options of `confirmDialog`. */
|
|
17
|
+
export interface ConfirmDialogOptions {
|
|
18
|
+
/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */
|
|
19
|
+
allowDelayMs?: number | undefined;
|
|
20
|
+
/** Offer "Allow until reload". */
|
|
21
|
+
alwaysAllow?: boolean | undefined;
|
|
22
|
+
/** Asked when a waiting call's turn comes: `true` answers "allow" unseen. */
|
|
23
|
+
allowedNow?: () => boolean;
|
|
24
|
+
strings?: DialogStrings;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Ask whether a consequential tool may run. "Allow until reload" is offered
|
|
28
|
+
* only with `alwaysAllow` (DEC-096). One confirmation is shown at a time per
|
|
29
|
+
* document; the others wait their turn, and a call cancelled while it waits
|
|
30
|
+
* is never shown. "Allow" and "Allow until reload" stay disabled until the
|
|
31
|
+
* page has been visible and focused for 750 ms while the dialog is open and
|
|
32
|
+
* is the top one, so a click meant for the page, the click that brings the
|
|
33
|
+
* tab or window back, or the one that closed another dialog, cannot
|
|
34
|
+
* approve; leaving the page disables them again. They also wait until the
|
|
35
|
+
* arguments have been scrolled to their end. Before the delay has run out,
|
|
36
|
+
* Enter or Space on a button and Escape are ignored, so typing meant for the
|
|
37
|
+
* page cannot refuse either. Everything else (Don't allow, Escape, an
|
|
38
|
+
* aborted call) is "deny". `allowedNow` is asked when a waiting call's turn
|
|
39
|
+
* comes: `true` (the user allowed it until reload meanwhile) answers "allow"
|
|
40
|
+
* without showing it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function confirmDialog(request: ConfirmRequest, doc: Document, options?: ConfirmDialogOptions): Promise<DialogAnswer>;
|
|
43
|
+
/**
|
|
44
|
+
* `TabMcp.confirmInPage`: the confirmation, and the tools allowed until
|
|
45
|
+
* reload (`always-allowed.ts`). Only for an AI app through the relay: an
|
|
46
|
+
* agent in the browser and a served port have no identity to remember an
|
|
47
|
+
* answer for (DEC-115, DEC-124).
|
|
48
|
+
*/
|
|
49
|
+
export declare function confirmInPage(mcp: TabMcp, request: ConfirmRequest, doc: Document, options?: {
|
|
50
|
+
alwaysAllow?: boolean | undefined;
|
|
51
|
+
ui?: DialogOptions | undefined;
|
|
52
|
+
/** Tests only. */
|
|
53
|
+
allowDelayMs?: number | undefined;
|
|
54
|
+
}): Promise<boolean>;
|