@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.
Files changed (53) hide show
  1. package/README.md +454 -147
  2. package/always-allowed.d.ts +25 -6
  3. package/cdn/confirm-y30cx7e1.min.js +4 -0
  4. package/cdn/confirm-y30cx7e1.min.js.map +10 -0
  5. package/cdn/connect-bbhj2y7w.min.js +6 -0
  6. package/cdn/connect-bbhj2y7w.min.js.map +12 -0
  7. package/cdn/connection-0y7ngtq7.min.js +17 -0
  8. package/cdn/connection-0y7ngtq7.min.js.map +22 -0
  9. package/cdn/index-vt5zk9me.min.js +91 -0
  10. package/cdn/index-vt5zk9me.min.js.map +13 -0
  11. package/cdn/tab-mcp-client.min.js +3 -3
  12. package/cdn/tab-mcp-client.min.js.map +6 -6
  13. package/confirm-fgnjgd08.js +263 -0
  14. package/confirm-fgnjgd08.js.map +10 -0
  15. package/confirm.d.ts +54 -0
  16. package/connect-8jpb0k29.js +484 -0
  17. package/connect-8jpb0k29.js.map +10 -0
  18. package/connect.d.ts +40 -0
  19. package/{connection-g6wk37yd.js → connection-1d8rxgbq.js} +247 -126
  20. package/connection-1d8rxgbq.js.map +16 -0
  21. package/connection.d.ts +7 -4
  22. package/dialog.d.ts +83 -0
  23. package/{index-nmn1j689.js → index-5jyqehpk.js} +14 -10
  24. package/index-5jyqehpk.js.map +11 -0
  25. package/index-jnz7w9xa.js +392 -0
  26. package/index-jnz7w9xa.js.map +12 -0
  27. package/index.d.ts +1 -1
  28. package/index.js +257 -240
  29. package/index.js.map +6 -6
  30. package/mapping.d.ts +37 -4
  31. package/mcp.d.ts +23 -8
  32. package/package.json +1 -1
  33. package/react.d.ts +8 -10
  34. package/react.js +18 -14
  35. package/react.js.map +3 -3
  36. package/registry.d.ts +12 -5
  37. package/secret.d.ts +5 -2
  38. package/serve.d.ts +26 -4
  39. package/setup.d.ts +15 -25
  40. package/setup.js +1 -1
  41. package/strings.d.ts +107 -0
  42. package/tab-mcp.d.ts +60 -35
  43. package/types.d.ts +146 -68
  44. package/webmcp.d.ts +13 -18
  45. package/cdn/connection-hgt931xk.min.js +0 -12
  46. package/cdn/connection-hgt931xk.min.js.map +0 -22
  47. package/cdn/ui-2nv84ry7.min.js +0 -86
  48. package/cdn/ui-2nv84ry7.min.js.map +0 -14
  49. package/connection-g6wk37yd.js.map +0 -16
  50. package/index-nmn1j689.js.map +0 -11
  51. package/ui-04mwfxm9.js +0 -783
  52. package/ui-04mwfxm9.js.map +0 -11
  53. package/ui.d.ts +0 -83
package/ui-04mwfxm9.js DELETED
@@ -1,783 +0,0 @@
1
- import {
2
- SETUP_GUIDE2,
3
- setupInstructions2
4
- } from "./index-nmn1j689.js";
5
- import {
6
- escapeInvisible2
7
- } from "./index-dmh5vm5m.js";
8
-
9
- // src/always-allowed.ts
10
- class AlwaysAllowed {
11
- #tools = new Map;
12
- has(grantId, tool) {
13
- return this.#tools.get(grantId)?.has(tool) === true;
14
- }
15
- add(grantId, tool) {
16
- const tools = this.#tools.get(grantId) ?? new Set;
17
- tools.add(tool);
18
- this.#tools.set(grantId, tools);
19
- }
20
- keepGrants(grantIds) {
21
- const keep = new Set(grantIds);
22
- for (const grantId of this.#tools.keys()) {
23
- if (!keep.has(grantId))
24
- this.#tools.delete(grantId);
25
- }
26
- }
27
- keepTools(names) {
28
- const keep = new Set(names);
29
- for (const tools of this.#tools.values()) {
30
- for (const tool of tools)
31
- if (!keep.has(tool))
32
- tools.delete(tool);
33
- }
34
- }
35
- }
36
-
37
- // src/ui.ts
38
- var counter = 0;
39
- function el(doc, tag, props = {}, ...children) {
40
- const node = doc.createElement(tag);
41
- if (props.className !== undefined)
42
- node.className = props.className;
43
- if (props.id !== undefined)
44
- node.id = props.id;
45
- if (props.text !== undefined)
46
- node.textContent = props.text;
47
- node.append(...children);
48
- return node;
49
- }
50
- function button(doc, text, onClick, className, kind) {
51
- const node = el(doc, "button", { text });
52
- node.type = "button";
53
- if (className !== undefined)
54
- node.classList.add(className);
55
- if (kind !== undefined)
56
- node.classList.add(`tab-mcp-${kind}`);
57
- node.addEventListener("click", onClick);
58
- return node;
59
- }
60
- var DIALOG_CSS = `.tab-mcp-dialog {
61
- --_tab-mcp-fg: var(--tab-mcp-color, CanvasText);
62
- --_tab-mcp-bg: var(--tab-mcp-background, Canvas);
63
- --_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));
64
- --_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);
65
- --_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));
66
- --_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));
67
- --_tab-mcp-success: var(--tab-mcp-success, light-dark(#1a7f37, #6fdd8b));
68
- --_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
69
- --_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);
70
- box-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
71
- font: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);
72
- border: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);
73
- padding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));
74
- }
75
- .tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }
76
- .tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }
77
- .tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }
78
- .tab-mcp-dialog :where([hidden]) { display: none !important; }
79
- html dialog.tab-mcp-dialog:where(:focus) { outline: none; }
80
- .tab-mcp-dialog :where(*) { box-sizing: border-box; }
81
- .tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }
82
- .tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
83
- .tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }
84
- .tab-mcp-dialog :where(small) { font-size: 0.875em; }
85
- .tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next) { color: var(--_tab-mcp-muted); }
86
- html dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }
87
- .tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }
88
- html dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }
89
- html dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }
90
- html button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }
91
- html button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }
92
- html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }
93
- .tab-mcp-copy { min-width: 6em; }
94
- .tab-mcp-close { font-size: 0.875em; }
95
- .tab-mcp-status { margin-top: -0.5rem; }
96
- .tab-mcp-description:where(:empty) { display: none; }
97
- .tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
98
- .tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
99
- .tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }
100
- .tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
101
- .tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }
102
- .tab-mcp-code > :where(span) { font-weight: 600; }
103
- .tab-mcp-code :where(br) { display: none; }
104
- .tab-mcp-code :where(small) { grid-column: 1 / -1; }
105
- .tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
106
- .tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
107
- .tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }
108
- .tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }
109
- .tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }
110
- .tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
111
- .tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }
112
- .tab-mcp-help :where(li) { overflow-wrap: anywhere; }
113
- .tab-mcp-help :where(strong) { display: block; font-weight: 600; }
114
- .tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }
115
- .tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
116
- .tab-mcp-command-note { display: block; margin-top: 0.375rem; }
117
- .tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
118
- .tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
119
- .tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }
120
- .tab-mcp-apps-note { margin-top: 0.5rem; }
121
- .tab-mcp-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }
122
- .tab-mcp-success-icon { flex: none; width: 2.75rem; height: 2.75rem; color: var(--_tab-mcp-success); }
123
- .tab-mcp-success-text { display: grid; gap: 0.125rem; min-width: 0; }
124
- .tab-mcp-success-title { font-size: 1.125em; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
125
- .tab-mcp-setup { display: flex; flex-direction: column; gap: 1rem; }
126
- .tab-mcp-setup-toggle { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem; text-align: start; font-weight: 600; border-color: var(--_tab-mcp-line); }
127
- .tab-mcp-setup-toggle::before { content: ""; flex: none; width: 0.45em; height: 0.45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateX(-0.1em) rotate(-45deg); }
128
- .tab-mcp-setup-toggle:where([aria-expanded="true"])::before { transform: translateY(-0.15em) rotate(45deg); }
129
- .tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }
130
- .tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }
131
- .tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }
132
- .tab-mcp-close-note { flex: 1 1 12rem; }
133
- .tab-mcp-confirm :where(p bdi) { font-weight: 600; }
134
- .tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
135
- .tab-mcp-always-note { font-size: 0.875em; }
136
- @media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }
137
- @media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } }
138
- @media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }
139
- @keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
140
- @keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }
141
- `;
142
- var sheets = new WeakMap;
143
- function adoptStyles(doc) {
144
- try {
145
- let sheet = sheets.get(doc);
146
- if (sheet === undefined) {
147
- const Sheet = doc.defaultView?.CSSStyleSheet;
148
- if (Sheet === undefined || !Array.isArray(doc.adoptedStyleSheets))
149
- return;
150
- sheet = new Sheet;
151
- sheet.replaceSync(DIALOG_CSS);
152
- sheets.set(doc, sheet);
153
- }
154
- if (!doc.adoptedStyleSheets.includes(sheet))
155
- doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];
156
- } catch {}
157
- }
158
- function copyButton(doc, noun, value, select, announce, className, kind) {
159
- const node = button(doc, "Copy", () => {
160
- const done = () => {
161
- node.textContent = "Copied";
162
- node.setAttribute("aria-label", `Copied ${noun}`);
163
- announce(`${noun[0]?.toUpperCase()}${noun.slice(1)} copied`);
164
- };
165
- const selected = () => {
166
- select();
167
- announce("Selected: copy it with Ctrl+C or ⌘C");
168
- };
169
- const clipboard = doc.defaultView?.navigator?.clipboard;
170
- if (clipboard !== undefined)
171
- clipboard.writeText(value()).then(done, selected);
172
- else
173
- selected();
174
- }, className, kind);
175
- node.classList.add("tab-mcp-copy");
176
- const reset = () => {
177
- node.textContent = "Copy";
178
- node.setAttribute("aria-label", `Copy ${noun}`);
179
- };
180
- reset();
181
- return { button: node, reset };
182
- }
183
- function newDialog(doc, className, title) {
184
- const id = `tab-mcp-${++counter}`;
185
- const dialog = el(doc, "dialog", {
186
- className: `tab-mcp-dialog ${className}`
187
- });
188
- dialog.setAttribute("aria-labelledby", `${id}-title`);
189
- adoptStyles(doc);
190
- const heading = el(doc, "h2", { id: `${id}-title`, text: title });
191
- dialog.append(heading);
192
- return { dialog, heading };
193
- }
194
- var visible = escapeInvisible2;
195
- function clientLabel(client) {
196
- if ("kind" in client && client.kind === "webmcp")
197
- return "An agent in this browser";
198
- if ("kind" in client && client.kind === "local")
199
- return `${visible(client.name ?? client.id)} (this site's assistant)`;
200
- const host = visible(client.host || client.id);
201
- return client.name !== undefined && client.name !== "" ? `${visible(client.name)} (${host})` : host;
202
- }
203
- function name(doc, text) {
204
- const node = el(doc, "bdi", { text });
205
- node.dir = "ltr";
206
- return node;
207
- }
208
- function showArguments(args) {
209
- try {
210
- return visible(JSON.stringify(args, null, 2));
211
- } catch {
212
- return;
213
- }
214
- }
215
- var ALLOW_DELAY_MS = 750;
216
- var MIN_ALLOW_DELAY_MS = 500;
217
- function allowDelay(ms) {
218
- const value = typeof ms === "number" && Number.isFinite(ms) && ms < 2 ** 31 ? ms : ALLOW_DELAY_MS;
219
- return Math.max(MIN_ALLOW_DELAY_MS, value);
220
- }
221
- function confirmDialog(request, doc, options = {}) {
222
- const delay = allowDelay(options.allowDelayMs);
223
- if (request.signal.aborted)
224
- return Promise.resolve("deny");
225
- const title = request.tool.title ?? request.tool.name;
226
- const { dialog, heading } = newDialog(doc, "tab-mcp-confirm", "");
227
- heading.append("Allow ", name(doc, title), "?");
228
- const client = clientLabel(request.client);
229
- const deny = button(doc, "Don't allow", () => dialog.close("deny"), "tab-mcp-deny", "primary");
230
- const allow = button(doc, "Allow", () => {
231
- if (!allow.disabled)
232
- dialog.close("allow");
233
- }, "tab-mcp-allow");
234
- const approve = [allow];
235
- const actions = el(doc, "div", { className: "tab-mcp-actions" }, deny, " ", allow);
236
- const extra = [];
237
- if (options.alwaysAllow === true) {
238
- const always = button(doc, "Always allow", () => {
239
- if (!always.disabled)
240
- dialog.close("always");
241
- }, "tab-mcp-always");
242
- approve.push(always);
243
- actions.append(" ", always);
244
- extra.push(el(doc, "p", { className: "tab-mcp-always-note" }, "Always allow: ", name(doc, title), " runs without asking for ", name(doc, client), " until you reload this page or disconnect it."));
245
- }
246
- const enable = (on) => {
247
- for (const b of approve)
248
- b.disabled = !on;
249
- };
250
- enable(false);
251
- const shown = showArguments(request.arguments);
252
- const args = el(doc, "pre", {
253
- className: "tab-mcp-arguments",
254
- text: shown ?? "The arguments cannot be shown, so this call cannot be allowed."
255
- });
256
- if (shown === undefined) {
257
- for (const node of [...approve, ...extra])
258
- node.hidden = true;
259
- }
260
- args.dir = "ltr";
261
- args.style.setProperty("white-space", "pre-wrap");
262
- args.style.setProperty("overflow-wrap", "anywhere");
263
- args.style.setProperty("max-height", "var(--tab-mcp-arguments-height, 12rem)");
264
- args.style.setProperty("overflow", "auto");
265
- args.hidden = Object.keys(request.arguments).length === 0;
266
- dialog.append(el(doc, "p", {}, name(doc, client), " wants to run ", name(doc, title), "."), el(doc, "p", {
267
- className: "tab-mcp-description",
268
- text: request.tool.description
269
- }), args, actions, ...extra);
270
- doc.body.append(dialog);
271
- const view = doc.defaultView;
272
- return new Promise((resolve) => {
273
- const onAbort = () => dialog.close("deny");
274
- request.signal.addEventListener("abort", onAbort, { once: true });
275
- let timer;
276
- const arm = (event) => {
277
- clearTimeout(timer);
278
- timer = undefined;
279
- enable(false);
280
- if (event?.type === "blur" || doc.visibilityState === "hidden" || !doc.hasFocus())
281
- return;
282
- timer = setTimeout(() => enable(true), delay);
283
- };
284
- doc.addEventListener("visibilitychange", arm);
285
- view?.addEventListener("focus", arm);
286
- view?.addEventListener("blur", arm);
287
- dialog.addEventListener("close", () => {
288
- clearTimeout(timer);
289
- doc.removeEventListener("visibilitychange", arm);
290
- view?.removeEventListener("focus", arm);
291
- view?.removeEventListener("blur", arm);
292
- request.signal.removeEventListener("abort", onAbort);
293
- const value = dialog.returnValue;
294
- dialog.remove();
295
- resolve(value === "allow" || value === "always" ? value : "deny");
296
- }, { once: true });
297
- dialog.showModal();
298
- deny.focus();
299
- arm();
300
- });
301
- }
302
- var allowedAlways = new WeakMap;
303
- function confirmInPage(mcp, request, doc, options) {
304
- const { client } = request;
305
- if (client.kind !== "relay")
306
- return confirmDialog(request, doc, {
307
- allowDelayMs: options.allowDelayMs
308
- }).then((answer) => answer === "allow");
309
- const { grantId } = client;
310
- const tool = request.tool.name;
311
- if (allowedAlways.get(mcp)?.has(grantId, tool))
312
- return Promise.resolve(true);
313
- return confirmDialog(request, doc, options).then((answer) => {
314
- if (answer === "always" && mcp.grants.some((g) => g.grantId === grantId)) {
315
- let allowed = allowedAlways.get(mcp);
316
- if (allowed === undefined) {
317
- const kept = new AlwaysAllowed;
318
- mcp.addEventListener("grantschange", (e) => kept.keepGrants(e.detail.grants.map((g) => g.grantId)));
319
- mcp.addEventListener("toolschange", (e) => kept.keepTools(e.detail.tools));
320
- allowedAlways.set(mcp, kept);
321
- allowed = kept;
322
- }
323
- allowed.add(grantId, tool);
324
- }
325
- return answer !== "deny";
326
- });
327
- }
328
- function appLabels(grants) {
329
- return [...new Set(grants.map((g) => clientLabel(g.client)))];
330
- }
331
- function listOf(items) {
332
- return items.length < 2 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
333
- }
334
- var watched = new WeakMap;
335
- function watchReplaced(mcp, doc) {
336
- const known = watched.has(mcp);
337
- watched.set(mcp, doc);
338
- if (known)
339
- return;
340
- mcp.addEventListener("replaced", (event) => {
341
- const current = watched.get(mcp);
342
- if (current !== undefined && mcp.state === "disconnected")
343
- replacedNotice(mcp, current, event.detail.sibling);
344
- });
345
- }
346
- function replacedNotice(mcp, doc, sibling) {
347
- doc.querySelector("dialog.tab-mcp-replaced")?.close();
348
- const { dialog } = newDialog(doc, "tab-mcp-replaced", sibling ? "Opened in another tab" : "Another tab or program took over this page");
349
- const status = el(doc, "p", { className: "tab-mcp-status" });
350
- status.setAttribute("role", "status");
351
- status.hidden = true;
352
- const close = button(doc, "Close", () => dialog.close(), "tab-mcp-replaced-close", sibling ? "primary" : undefined);
353
- const actions = el(doc, "div", { className: "tab-mcp-actions" }, close);
354
- let first = close;
355
- if (!sibling) {
356
- const fresh = button(doc, "New address", () => {
357
- fresh.disabled = true;
358
- status.hidden = false;
359
- status.textContent = "Getting a new address…";
360
- mcp.newAddress().then(() => {
361
- dialog.close();
362
- mcp.showConnectDialog({ document: doc }).catch(() => {});
363
- }, (error) => {
364
- fresh.disabled = false;
365
- status.textContent = error?.reason === "replaced" ? "It was taken over again before its AI apps were disconnected. Try again." : `Could not connect: ${error instanceof Error ? error.message : String(error)}. Try again, or close this.`;
366
- });
367
- }, "tab-mcp-new-address", "primary");
368
- actions.append(" ", fresh);
369
- first = fresh;
370
- }
371
- dialog.append(el(doc, "p", {
372
- className: "tab-mcp-description",
373
- text: sibling ? "This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again." : "Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied its address. A new address disconnects every AI app from the old one; then add the new address to your AI apps again."
374
- }), status, actions);
375
- dialog.addEventListener("close", () => dialog.remove(), { once: true });
376
- doc.body.append(dialog);
377
- dialog.showModal();
378
- first.focus();
379
- }
380
- var CODE_USED_WAIT_MS = 1e4;
381
- var SVG = "http://www.w3.org/2000/svg";
382
- function checkIcon(doc) {
383
- const set = (node, attributes) => {
384
- for (const [key, value] of Object.entries(attributes))
385
- node.setAttribute(key, value);
386
- };
387
- const svg = doc.createElementNS(SVG, "svg");
388
- set(svg, {
389
- class: "tab-mcp-success-icon",
390
- viewBox: "0 0 48 48",
391
- width: "44",
392
- height: "44",
393
- "aria-hidden": "true",
394
- focusable: "false"
395
- });
396
- const disk = doc.createElementNS(SVG, "circle");
397
- set(disk, {
398
- cx: "24",
399
- cy: "24",
400
- r: "24",
401
- fill: "currentColor",
402
- "fill-opacity": "0.16"
403
- });
404
- const check = doc.createElementNS(SVG, "path");
405
- set(check, {
406
- d: "M14 24.5l7 7 13-14",
407
- fill: "none",
408
- stroke: "currentColor",
409
- "stroke-width": "4",
410
- "stroke-linecap": "round",
411
- "stroke-linejoin": "round"
412
- });
413
- svg.append(disk, check);
414
- return svg;
415
- }
416
- function showConnectDialog(mcp, connecting, doc, serverName = "tools") {
417
- const { dialog } = newDialog(doc, "tab-mcp-connect", "Connect your AI app");
418
- dialog.tabIndex = -1;
419
- const status = el(doc, "p", {
420
- className: "tab-mcp-status",
421
- text: "Connecting…"
422
- });
423
- status.setAttribute("role", "status");
424
- const live = el(doc, "span", { className: "tab-mcp-announce" });
425
- live.setAttribute("aria-live", "polite");
426
- for (const [property, value] of [
427
- ["position", "absolute"],
428
- ["width", "1px"],
429
- ["height", "1px"],
430
- ["overflow", "hidden"],
431
- ["clip-path", "inset(50%)"],
432
- ["white-space", "nowrap"]
433
- ])
434
- live.style.setProperty(property, value);
435
- const announce = (text) => {
436
- live.textContent = live.textContent === text ? `${text} ` : text;
437
- };
438
- const successId = `tab-mcp-${++counter}-success`;
439
- const successTitle = el(doc, "p", { className: "tab-mcp-success-title" });
440
- const successNext = el(doc, "p", { className: "tab-mcp-success-next" });
441
- const success = el(doc, "div", { className: "tab-mcp-success", id: successId }, checkIcon(doc), el(doc, "div", { className: "tab-mcp-success-text" }, successTitle, successNext));
442
- const addressId = `tab-mcp-${++counter}-address`;
443
- const label = el(doc, "label", { text: "Add this address to your AI app:" });
444
- label.htmlFor = addressId;
445
- const address = el(doc, "input", {
446
- id: addressId,
447
- className: "tab-mcp-address-input"
448
- });
449
- address.readOnly = true;
450
- const { button: copy, reset: resetCopy } = copyButton(doc, "address", () => address.value, () => address.select(), announce, "tab-mcp-address-copy", "primary");
451
- const fresh = button(doc, "New address", () => askNewAddress(), "tab-mcp-new-address");
452
- const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy, " ", fresh);
453
- const confirmId = `tab-mcp-${++counter}-new-address`;
454
- const confirmText = el(doc, "p", { id: confirmId });
455
- const cancelNew = button(doc, "Cancel", () => {
456
- confirmBox.hidden = true;
457
- fresh.focus();
458
- });
459
- const confirmNew = button(doc, "Disconnect and get new address", () => getNewAddress(), "tab-mcp-new-address-confirm", "danger");
460
- const confirmBox = el(doc, "div", { className: "tab-mcp-new-address-question" }, confirmText, el(doc, "div", { className: "tab-mcp-actions" }, cancelNew, " ", confirmNew));
461
- confirmBox.setAttribute("role", "group");
462
- confirmBox.setAttribute("aria-labelledby", confirmId);
463
- confirmBox.hidden = true;
464
- const code = el(doc, "strong", { className: "tab-mcp-code-value" });
465
- code.style.setProperty("user-select", "all");
466
- code.style.setProperty("-webkit-user-select", "all");
467
- const { button: copyCode, reset: resetCopyCode } = copyButton(doc, "code", () => code.textContent ?? "", () => doc.getSelection()?.selectAllChildren(code), announce, "tab-mcp-code-copy");
468
- const codeSentence = el(doc, "span", {}, "When asked, enter the code ", code);
469
- codeSentence.setAttribute("aria-live", "polite");
470
- const codeUsed = el(doc, "span", { className: "tab-mcp-code-used" });
471
- codeUsed.hidden = true;
472
- const codeLine = el(doc, "p", { className: "tab-mcp-code" }, codeSentence, codeUsed, " ", copyCode, el(doc, "br"), el(doc, "small", {
473
- className: "tab-mcp-code-note",
474
- text: "A new code appears every 2 minutes and after each use."
475
- }));
476
- const signInLine = el(doc, "p", {
477
- className: "tab-mcp-sign-in",
478
- text: "When your AI app asks, sign in with the account you use on this page. No code is needed."
479
- });
480
- const steps = el(doc, "ul");
481
- const guide = el(doc, "a", {
482
- text: "Step by step, and what to do when it fails"
483
- });
484
- guide.href = SETUP_GUIDE2;
485
- guide.target = "_blank";
486
- guide.rel = "noopener noreferrer";
487
- const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: "How do I add it?" }), steps, el(doc, "p", { className: "tab-mcp-guide" }, guide));
488
- const setupId = `tab-mcp-${++counter}-setup`;
489
- const setup = el(doc, "div", { className: "tab-mcp-setup", id: setupId }, addressBox, confirmBox, codeLine, signInLine, help);
490
- let expanded = false;
491
- const setupToggle = button(doc, "Connect another app", () => {
492
- expanded = !expanded;
493
- renderView(false);
494
- }, "tab-mcp-setup-toggle");
495
- setupToggle.setAttribute("aria-controls", setupId);
496
- const appList = el(doc, "ul");
497
- const appsNote = el(doc, "p", { className: "tab-mcp-apps-note" });
498
- const apps = el(doc, "div", { className: "tab-mcp-apps" }, el(doc, "h3", { text: "Connected" }), appList, appsNote);
499
- const closeNote = el(doc, "small", {
500
- className: "tab-mcp-close-note",
501
- text: "Closing this stops the code. The address stays the same: to connect later, open this again from the page."
502
- });
503
- const close = button(doc, "Close", () => dialog.close(), "tab-mcp-close");
504
- const done = button(doc, "Done", () => dialog.close(), "tab-mcp-done", "primary");
505
- done.hidden = true;
506
- const actions = el(doc, "div", { className: "tab-mcp-actions" }, closeNote, " ", close, done);
507
- dialog.append(success, status, apps, setupToggle, setup, actions, live);
508
- success.hidden = true;
509
- setupToggle.hidden = true;
510
- addressBox.hidden = true;
511
- codeLine.hidden = true;
512
- signInLine.hidden = true;
513
- help.hidden = true;
514
- apps.hidden = true;
515
- let renewing = false;
516
- const pairedGrants = new Set;
517
- let connectedView = false;
518
- let codeShown = false;
519
- const closer = () => connectedView ? done : close;
520
- const start = () => connectedView ? done : copy;
521
- const focusLost = (focused) => focused !== null && focused !== dialog && focused !== doc.body && (!focused.isConnected || dialog.contains(focused) && focused.closest("[hidden]") !== null);
522
- const renderView = (paired, focused = doc.activeElement) => {
523
- connectedView = !renewing && mcp.state === "connected" && mcp.grants.length > 0;
524
- if (paired && confirmBox.hidden)
525
- expanded = false;
526
- if (connectedView) {
527
- const here = mcp.grants.filter((g) => pairedGrants.has(g.grantId));
528
- const names = appLabels(here.length > 0 ? here : mcp.grants);
529
- const one = names.length === 1;
530
- successTitle.textContent = `${listOf(names)} ${one ? "is" : "are"} connected`;
531
- successNext.textContent = `You can close this now and ask ${one ? "it" : "them"} to use the tools of this page.`;
532
- dialog.setAttribute("aria-describedby", successId);
533
- } else
534
- dialog.removeAttribute("aria-describedby");
535
- success.hidden = !connectedView;
536
- status.hidden = connectedView;
537
- setupToggle.hidden = !connectedView;
538
- setupToggle.setAttribute("aria-expanded", String(expanded));
539
- setup.hidden = connectedView && !expanded;
540
- copy.classList.toggle("tab-mcp-primary", !connectedView);
541
- closeNote.hidden = connectedView || !codeShown;
542
- close.hidden = connectedView;
543
- done.hidden = !connectedView;
544
- if (focusLost(focused))
545
- closer().focus();
546
- if (paired && connectedView)
547
- announce(`${successTitle.textContent}. ${successNext.textContent}`);
548
- };
549
- const renderQuestion = () => {
550
- const names = appLabels(mcp.grants);
551
- if (names.length === 0)
552
- return false;
553
- confirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? "it" : "them"}.`;
554
- return true;
555
- };
556
- const askNewAddress = () => {
557
- if (mcp.state !== "connected")
558
- return;
559
- if (!renderQuestion()) {
560
- getNewAddress();
561
- return;
562
- }
563
- confirmBox.hidden = false;
564
- cancelNew.focus();
565
- };
566
- const getNewAddress = () => {
567
- pairedGrants.clear();
568
- renewing = true;
569
- status.textContent = "Getting a new address…";
570
- renderView(false);
571
- close.focus();
572
- confirmBox.hidden = true;
573
- mcp.newAddress().then(() => {
574
- renewing = false;
575
- status.textContent = "This is a new address. Add it to your AI app again.";
576
- renderView(false);
577
- copy.focus();
578
- }, (error) => {
579
- renewing = false;
580
- status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;
581
- renderView(false);
582
- closer().focus();
583
- });
584
- };
585
- let stepsFor;
586
- const renderSession = (session) => {
587
- if (session === undefined) {
588
- addressBox.hidden = true;
589
- confirmBox.hidden = true;
590
- help.hidden = true;
591
- renderView(false);
592
- return;
593
- }
594
- if (address.value !== session.address) {
595
- address.value = session.address;
596
- resetCopy();
597
- }
598
- const appName = session.appName ?? mcp.appName;
599
- if (!renewing)
600
- status.textContent = appName !== undefined ? `${appName} is ready for your AI app.` : "This page is ready for your AI app.";
601
- fresh.disabled = mcp.state !== "connected";
602
- addressBox.hidden = false;
603
- help.hidden = false;
604
- renderView(false);
605
- if (doc.activeElement === dialog)
606
- start().focus();
607
- if (stepsFor === session.address)
608
- return;
609
- stepsFor = session.address;
610
- steps.replaceChildren(...setupInstructions2(serverName, session.address).map(({ app, text: how, command, note }) => {
611
- const item = el(doc, "li", {}, el(doc, "strong", { text: `${app}:` }), ` ${how}`);
612
- if (command !== undefined) {
613
- const text = el(doc, "pre", { text: command });
614
- text.dir = "ltr";
615
- const { button: copyCommand } = copyButton(doc, `${app} command`, () => text.textContent ?? "", () => doc.getSelection()?.selectAllChildren(text), announce, "tab-mcp-command-copy");
616
- item.append(el(doc, "div", { className: "tab-mcp-command" }, text, copyCommand));
617
- }
618
- if (note !== undefined)
619
- item.append(el(doc, "small", { className: "tab-mcp-command-note" }, ...note.map((part) => ("code" in part) ? el(doc, "code", { text: part.code }) : part.text)));
620
- return item;
621
- }));
622
- };
623
- let shownCode;
624
- let usedTimer;
625
- const stopWaiting = () => {
626
- clearTimeout(usedTimer);
627
- usedTimer = undefined;
628
- };
629
- const endWait = () => {
630
- stopWaiting();
631
- shownCode = mcp.pairingCode;
632
- renderCode();
633
- };
634
- const renderCode = () => {
635
- const focused = doc.activeElement;
636
- const current = mcp.pairingCode;
637
- const oidc = mcp.session?.pairing === "oidc";
638
- if (current === undefined)
639
- stopWaiting();
640
- else if (current.code !== shownCode?.code) {
641
- if (current.reason === "used") {
642
- if (usedTimer === undefined) {
643
- usedTimer = setTimeout(endWait, CODE_USED_WAIT_MS);
644
- announce("Code used. Waiting for your AI app…");
645
- }
646
- } else if (usedTimer !== undefined) {
647
- stopWaiting();
648
- }
649
- }
650
- const used = usedTimer !== undefined;
651
- if (!used) {
652
- if (code.textContent !== (current?.code ?? ""))
653
- resetCopyCode();
654
- code.textContent = current?.code ?? "";
655
- shownCode = current;
656
- }
657
- codeSentence.hidden = used;
658
- copyCode.hidden = used;
659
- codeUsed.hidden = !used;
660
- codeUsed.textContent = used ? "Code used. Waiting for your AI app…" : "";
661
- codeLine.hidden = oidc || current === undefined;
662
- signInLine.hidden = !oidc;
663
- codeShown = !codeLine.hidden;
664
- closeNote.hidden = connectedView || !codeShown;
665
- if (focusLost(focused))
666
- closer().focus();
667
- };
668
- const items = new Map;
669
- const appItem = (grant) => {
670
- const disconnect = button(doc, "Disconnect", () => {
671
- if (!mcp.revoke(grant.grantId))
672
- renderGrants();
673
- }, "tab-mcp-disconnect", "danger");
674
- const item = el(doc, "li", {}, el(doc, "span", {
675
- className: "tab-mcp-app",
676
- text: `${clientLabel(grant.client)} connected `
677
- }), disconnect);
678
- return { item, disconnect };
679
- };
680
- const known = new Set(mcp.grants.map((g) => g.grantId));
681
- let session = mcp.session;
682
- const renderGrants = () => {
683
- if (mcp.session !== session) {
684
- session = mcp.session;
685
- for (const grant of mcp.grants)
686
- known.add(grant.grantId);
687
- }
688
- let paired = false;
689
- for (const grant of mcp.grants) {
690
- if (known.has(grant.grantId))
691
- continue;
692
- known.add(grant.grantId);
693
- status.textContent = `${clientLabel(grant.client)} is connected.`;
694
- pairedGrants.add(grant.grantId);
695
- paired = true;
696
- }
697
- const ids = new Set(mcp.grants.map((g) => g.grantId));
698
- for (const id of pairedGrants)
699
- if (!ids.has(id))
700
- pairedGrants.delete(id);
701
- const focused = doc.activeElement;
702
- for (const [id, { item }] of items) {
703
- if (ids.has(id))
704
- continue;
705
- item.remove();
706
- items.delete(id);
707
- }
708
- const connected = mcp.state === "connected";
709
- mcp.grants.forEach((grant, i) => {
710
- let entry = items.get(grant.grantId);
711
- if (entry === undefined) {
712
- entry = appItem(grant);
713
- items.set(grant.grantId, entry);
714
- }
715
- entry.disconnect.disabled = !connected;
716
- if (appList.children[i] !== entry.item)
717
- appList.insertBefore(entry.item, appList.children[i] ?? null);
718
- });
719
- appsNote.textContent = connected ? "" : "To disconnect an app, connect this page again first.";
720
- appsNote.hidden = connected;
721
- apps.hidden = mcp.grants.length === 0;
722
- if (!confirmBox.hidden && !renderQuestion()) {
723
- confirmBox.hidden = true;
724
- fresh.focus();
725
- }
726
- if (paired && usedTimer !== undefined)
727
- endWait();
728
- const now = doc.activeElement;
729
- renderView(paired, now === null || now === doc.body ? focused : now);
730
- };
731
- const onDisconnected = (event) => {
732
- if (event.detail.reason !== "new_address")
733
- status.textContent = "Disconnected. AI apps can use this page again after you connect.";
734
- renderSession(undefined);
735
- renderGrants();
736
- renderCode();
737
- };
738
- const onConnected = () => {
739
- renderSession(mcp.session);
740
- renderGrants();
741
- renderCode();
742
- };
743
- const onReplaced = () => dialog.close();
744
- watchReplaced(mcp, doc);
745
- mcp.addEventListener("pairingcode", renderCode);
746
- mcp.addEventListener("grantschange", renderGrants);
747
- mcp.addEventListener("connected", onConnected);
748
- mcp.addEventListener("disconnected", onDisconnected);
749
- mcp.addEventListener("replaced", onReplaced);
750
- doc.body.append(dialog);
751
- mcp.startPairing();
752
- renderGrants();
753
- renderCode();
754
- renderSession(mcp.session);
755
- connecting.then((session) => renderSession(session), (error) => {
756
- status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;
757
- });
758
- return new Promise((resolve) => {
759
- dialog.addEventListener("close", () => {
760
- stopWaiting();
761
- mcp.stopPairing();
762
- mcp.removeEventListener("pairingcode", renderCode);
763
- mcp.removeEventListener("grantschange", renderGrants);
764
- mcp.removeEventListener("connected", onConnected);
765
- mcp.removeEventListener("disconnected", onDisconnected);
766
- mcp.removeEventListener("replaced", onReplaced);
767
- dialog.remove();
768
- resolve();
769
- }, { once: true });
770
- dialog.showModal();
771
- if (connectedView || !addressBox.hidden)
772
- start().focus();
773
- else
774
- dialog.focus();
775
- });
776
- }
777
- export {
778
- confirmInPage,
779
- showConnectDialog
780
- };
781
-
782
- //# debugId=BBCCC525D96FC97D64756E2164756E21
783
- //# sourceMappingURL=ui-04mwfxm9.js.map