@ractive-ch/tab-mcp-client 0.5.1 → 0.7.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/ui-gkxbbn8v.js ADDED
@@ -0,0 +1,557 @@
1
+ // src/ui.ts
2
+ var counter = 0;
3
+ function el(doc, tag, props = {}, ...children) {
4
+ const node = doc.createElement(tag);
5
+ if (props.className !== undefined)
6
+ node.className = props.className;
7
+ if (props.id !== undefined)
8
+ node.id = props.id;
9
+ if (props.text !== undefined)
10
+ node.textContent = props.text;
11
+ node.append(...children);
12
+ return node;
13
+ }
14
+ function button(doc, text, onClick, className, kind) {
15
+ const node = el(doc, "button", { text });
16
+ node.type = "button";
17
+ if (className !== undefined)
18
+ node.classList.add(className);
19
+ if (kind !== undefined)
20
+ node.classList.add(`tab-mcp-${kind}`);
21
+ node.addEventListener("click", onClick);
22
+ return node;
23
+ }
24
+ var DIALOG_CSS = `.tab-mcp-dialog {
25
+ --_tab-mcp-fg: var(--tab-mcp-color, CanvasText);
26
+ --_tab-mcp-bg: var(--tab-mcp-background, Canvas);
27
+ --_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));
28
+ --_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);
29
+ --_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));
30
+ --_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));
31
+ --_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
32
+ --_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);
33
+ box-sizing: border-box; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
34
+ font: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);
35
+ border: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);
36
+ 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));
37
+ }
38
+ .tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }
39
+ .tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }
40
+ .tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }
41
+ .tab-mcp-dialog :where([hidden]) { display: none !important; }
42
+ html dialog.tab-mcp-dialog:where(:focus) { outline: none; }
43
+ .tab-mcp-dialog :where(*) { box-sizing: border-box; }
44
+ .tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }
45
+ .tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
46
+ .tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }
47
+ .tab-mcp-dialog :where(small) { font-size: 0.875em; }
48
+ .tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note) { color: var(--_tab-mcp-muted); }
49
+ html dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }
50
+ .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; }
51
+ html dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }
52
+ html dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }
53
+ 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; }
54
+ html button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }
55
+ html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }
56
+ .tab-mcp-copy { min-width: 6em; }
57
+ .tab-mcp-close { font-size: 0.875em; }
58
+ .tab-mcp-status { margin-top: -0.5rem; }
59
+ .tab-mcp-description:where(:empty) { display: none; }
60
+ .tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
61
+ .tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
62
+ .tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }
63
+ .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); }
64
+ .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); }
65
+ .tab-mcp-code > :where(span) { font-weight: 600; }
66
+ .tab-mcp-code :where(br) { display: none; }
67
+ .tab-mcp-code :where(small) { grid-column: 1 / -1; }
68
+ .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; }
69
+ .tab-mcp-help :where(summary) { width: fit-content; cursor: pointer; }
70
+ .tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
71
+ .tab-mcp-help :where(ul) { margin-top: 0.75rem; gap: 0.75rem; }
72
+ .tab-mcp-help :where(li) { overflow-wrap: anywhere; }
73
+ .tab-mcp-help :where(strong) { display: block; font-weight: 600; }
74
+ .tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }
75
+ .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); }
76
+ .tab-mcp-command-note { display: block; margin-top: 0.375rem; }
77
+ .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; }
78
+ .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); }
79
+ .tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }
80
+ .tab-mcp-apps-note { margin-top: 0.5rem; }
81
+ .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); }
82
+ .tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }
83
+ .tab-mcp-close-note { flex: 1 1 12rem; }
84
+ .tab-mcp-confirm :where(p bdi) { font-weight: 600; }
85
+ .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); }
86
+ .tab-mcp-always-note { font-size: 0.875em; }
87
+ @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; } }
88
+ @media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } }
89
+ @media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }
90
+ @keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
91
+ `;
92
+ var sheets = new WeakMap;
93
+ function adoptStyles(doc) {
94
+ try {
95
+ let sheet = sheets.get(doc);
96
+ if (sheet === undefined) {
97
+ const Sheet = doc.defaultView?.CSSStyleSheet;
98
+ if (Sheet === undefined || !Array.isArray(doc.adoptedStyleSheets))
99
+ return;
100
+ sheet = new Sheet;
101
+ sheet.replaceSync(DIALOG_CSS);
102
+ sheets.set(doc, sheet);
103
+ }
104
+ if (!doc.adoptedStyleSheets.includes(sheet))
105
+ doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];
106
+ } catch {}
107
+ }
108
+ function copyButton(doc, noun, value, select, announce, className, kind) {
109
+ const node = button(doc, "Copy", () => {
110
+ const done = () => {
111
+ node.textContent = "Copied";
112
+ node.setAttribute("aria-label", `Copied ${noun}`);
113
+ announce(`${noun[0]?.toUpperCase()}${noun.slice(1)} copied`);
114
+ };
115
+ const selected = () => {
116
+ select();
117
+ announce("Selected: copy it with Ctrl+C or ⌘C");
118
+ };
119
+ const clipboard = doc.defaultView?.navigator?.clipboard;
120
+ if (clipboard !== undefined)
121
+ clipboard.writeText(value()).then(done, selected);
122
+ else
123
+ selected();
124
+ }, className, kind);
125
+ node.classList.add("tab-mcp-copy");
126
+ const reset = () => {
127
+ node.textContent = "Copy";
128
+ node.setAttribute("aria-label", `Copy ${noun}`);
129
+ };
130
+ reset();
131
+ return { button: node, reset };
132
+ }
133
+ function newDialog(doc, className, title) {
134
+ const id = `tab-mcp-${++counter}`;
135
+ const dialog = el(doc, "dialog", {
136
+ className: `tab-mcp-dialog ${className}`
137
+ });
138
+ dialog.setAttribute("aria-labelledby", `${id}-title`);
139
+ adoptStyles(doc);
140
+ const heading = el(doc, "h2", { id: `${id}-title`, text: title });
141
+ dialog.append(heading);
142
+ return { dialog, heading };
143
+ }
144
+ var INVISIBLE = /[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Co}\p{Cn}\u0080-\u009F\u2028\u2029]/gu;
145
+ function visible(text) {
146
+ return text.replace(INVISIBLE, (ch) => {
147
+ let escaped = "";
148
+ for (let i = 0;i < ch.length; i++)
149
+ escaped += `\\u${ch.charCodeAt(i).toString(16).toUpperCase().padStart(4, "0")}`;
150
+ return escaped;
151
+ });
152
+ }
153
+ function clientLabel(client) {
154
+ const host = visible(client.host || client.id);
155
+ return client.name !== undefined && client.name !== "" ? `${visible(client.name)} (${host})` : host;
156
+ }
157
+ function name(doc, text) {
158
+ const node = el(doc, "bdi", { text });
159
+ node.dir = "ltr";
160
+ return node;
161
+ }
162
+ function showArguments(args) {
163
+ try {
164
+ return visible(JSON.stringify(args, null, 2));
165
+ } catch {
166
+ return;
167
+ }
168
+ }
169
+ var ALLOW_DELAY_MS = 750;
170
+ var MIN_ALLOW_DELAY_MS = 500;
171
+ function allowDelay(ms) {
172
+ const value = typeof ms === "number" && Number.isFinite(ms) && ms < 2 ** 31 ? ms : ALLOW_DELAY_MS;
173
+ return Math.max(MIN_ALLOW_DELAY_MS, value);
174
+ }
175
+ function confirmDialog(request, doc, options = {}) {
176
+ const delay = allowDelay(options.allowDelayMs);
177
+ if (request.signal.aborted)
178
+ return Promise.resolve("deny");
179
+ const title = request.tool.title ?? request.tool.name;
180
+ const { dialog, heading } = newDialog(doc, "tab-mcp-confirm", "");
181
+ heading.append("Allow ", name(doc, title), "?");
182
+ const client = clientLabel(request.client);
183
+ const deny = button(doc, "Don't allow", () => dialog.close("deny"), "tab-mcp-deny", "primary");
184
+ const allow = button(doc, "Allow", () => {
185
+ if (!allow.disabled)
186
+ dialog.close("allow");
187
+ }, "tab-mcp-allow");
188
+ const always = button(doc, "Always allow", () => {
189
+ if (!always.disabled)
190
+ dialog.close("always");
191
+ }, "tab-mcp-always");
192
+ allow.disabled = true;
193
+ always.disabled = true;
194
+ const actions = el(doc, "div", { className: "tab-mcp-actions" }, deny, " ", allow, " ", always);
195
+ const alwaysNote = 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.");
196
+ const shown = showArguments(request.arguments);
197
+ const args = el(doc, "pre", {
198
+ className: "tab-mcp-arguments",
199
+ text: shown ?? "The arguments cannot be shown, so this call cannot be allowed."
200
+ });
201
+ if (shown === undefined) {
202
+ allow.hidden = true;
203
+ always.hidden = true;
204
+ alwaysNote.hidden = true;
205
+ }
206
+ args.dir = "ltr";
207
+ args.style.setProperty("white-space", "pre-wrap");
208
+ args.style.setProperty("overflow-wrap", "anywhere");
209
+ args.style.setProperty("max-height", "var(--tab-mcp-arguments-height, 12rem)");
210
+ args.style.setProperty("overflow", "auto");
211
+ args.hidden = Object.keys(request.arguments).length === 0;
212
+ dialog.append(el(doc, "p", {}, name(doc, client), " wants to run ", name(doc, title), "."), el(doc, "p", {
213
+ className: "tab-mcp-description",
214
+ text: request.tool.description
215
+ }), args, actions, alwaysNote);
216
+ doc.body.append(dialog);
217
+ const view = doc.defaultView;
218
+ return new Promise((resolve) => {
219
+ const onAbort = () => dialog.close("deny");
220
+ request.signal.addEventListener("abort", onAbort, { once: true });
221
+ let timer;
222
+ const arm = (event) => {
223
+ clearTimeout(timer);
224
+ timer = undefined;
225
+ allow.disabled = true;
226
+ always.disabled = true;
227
+ if (event?.type === "blur" || doc.visibilityState === "hidden" || !doc.hasFocus())
228
+ return;
229
+ timer = setTimeout(() => {
230
+ allow.disabled = false;
231
+ always.disabled = false;
232
+ }, delay);
233
+ };
234
+ doc.addEventListener("visibilitychange", arm);
235
+ view?.addEventListener("focus", arm);
236
+ view?.addEventListener("blur", arm);
237
+ dialog.addEventListener("close", () => {
238
+ clearTimeout(timer);
239
+ doc.removeEventListener("visibilitychange", arm);
240
+ view?.removeEventListener("focus", arm);
241
+ view?.removeEventListener("blur", arm);
242
+ request.signal.removeEventListener("abort", onAbort);
243
+ const value = dialog.returnValue;
244
+ dialog.remove();
245
+ resolve(value === "allow" || value === "always" ? value : "deny");
246
+ }, { once: true });
247
+ dialog.showModal();
248
+ deny.focus();
249
+ arm();
250
+ });
251
+ }
252
+ function commandName(name) {
253
+ const label = name.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "").slice(0, 40).replace(/-+$/, "");
254
+ return label === "" ? "tools" : label;
255
+ }
256
+ function commandAddress(address) {
257
+ try {
258
+ const href = new URL(address).href;
259
+ return /^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(href) ? href : undefined;
260
+ } catch {
261
+ return;
262
+ }
263
+ }
264
+ var CODEX_FEATURE = "mcp_2026_07_28";
265
+ function instructions(name, address) {
266
+ const n = commandName(name);
267
+ const a = commandAddress(address);
268
+ return [
269
+ [
270
+ "Claude (claude.ai and the desktop app)",
271
+ "Settings → Connectors → Add custom connector, then paste the address."
272
+ ],
273
+ [
274
+ "ChatGPT",
275
+ "Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."
276
+ ],
277
+ a === undefined ? ["Claude Code", "Add the address with claude mcp add --transport http."] : ["Claude Code", "Run:", `claude mcp add --transport http ${n} ${a}`],
278
+ [
279
+ "Codex",
280
+ ...a === undefined ? [
281
+ `Run codex features enable ${CODEX_FEATURE}, then add the address with codex mcp add --url.`,
282
+ undefined
283
+ ] : [
284
+ "Run:",
285
+ `codex features enable ${CODEX_FEATURE}
286
+ codex mcp add ${n} --url ${a}`
287
+ ],
288
+ [
289
+ "Start a new chat in Codex after it connects. The first line turns on a feature for all of Codex's MCP servers; ",
290
+ `codex features disable ${CODEX_FEATURE}`,
291
+ " turns it off."
292
+ ]
293
+ ]
294
+ ];
295
+ }
296
+ function listOf(items) {
297
+ return items.length < 2 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
298
+ }
299
+ function showConnectDialog(mcp, connecting, doc, serverName = "tools") {
300
+ const { dialog } = newDialog(doc, "tab-mcp-connect", "Connect your AI app");
301
+ dialog.tabIndex = -1;
302
+ const status = el(doc, "p", {
303
+ className: "tab-mcp-status",
304
+ text: "Connecting…"
305
+ });
306
+ status.setAttribute("role", "status");
307
+ const live = el(doc, "span", { className: "tab-mcp-announce" });
308
+ live.setAttribute("aria-live", "polite");
309
+ for (const [property, value] of [
310
+ ["position", "absolute"],
311
+ ["width", "1px"],
312
+ ["height", "1px"],
313
+ ["overflow", "hidden"],
314
+ ["clip-path", "inset(50%)"],
315
+ ["white-space", "nowrap"]
316
+ ])
317
+ live.style.setProperty(property, value);
318
+ const announce = (text) => {
319
+ live.textContent = live.textContent === text ? `${text} ` : text;
320
+ };
321
+ const addressId = `tab-mcp-${++counter}-address`;
322
+ const label = el(doc, "label", { text: "Add this address to your AI app:" });
323
+ label.htmlFor = addressId;
324
+ const address = el(doc, "input", {
325
+ id: addressId,
326
+ className: "tab-mcp-address-input"
327
+ });
328
+ address.readOnly = true;
329
+ const { button: copy, reset: resetCopy } = copyButton(doc, "address", () => address.value, () => address.select(), announce, "tab-mcp-address-copy", "primary");
330
+ const fresh = button(doc, "New address", () => askNewAddress(), "tab-mcp-new-address");
331
+ const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy, " ", fresh);
332
+ const confirmId = `tab-mcp-${++counter}-new-address`;
333
+ const confirmText = el(doc, "p", { id: confirmId });
334
+ const cancelNew = button(doc, "Cancel", () => {
335
+ confirmBox.hidden = true;
336
+ fresh.focus();
337
+ });
338
+ const confirmNew = button(doc, "Disconnect and get new address", () => getNewAddress(), "tab-mcp-new-address-confirm", "danger");
339
+ const confirmBox = el(doc, "div", { className: "tab-mcp-new-address-question" }, confirmText, el(doc, "div", { className: "tab-mcp-actions" }, cancelNew, " ", confirmNew));
340
+ confirmBox.setAttribute("role", "group");
341
+ confirmBox.setAttribute("aria-labelledby", confirmId);
342
+ confirmBox.hidden = true;
343
+ const code = el(doc, "strong", { className: "tab-mcp-code-value" });
344
+ code.style.setProperty("user-select", "all");
345
+ code.style.setProperty("-webkit-user-select", "all");
346
+ const { button: copyCode, reset: resetCopyCode } = copyButton(doc, "code", () => code.textContent ?? "", () => doc.getSelection()?.selectAllChildren(code), announce, "tab-mcp-code-copy");
347
+ const codeSentence = el(doc, "span", {}, "When asked, enter the code ", code);
348
+ codeSentence.setAttribute("aria-live", "polite");
349
+ const codeLine = el(doc, "p", { className: "tab-mcp-code" }, codeSentence, " ", copyCode, el(doc, "br"), el(doc, "small", {
350
+ className: "tab-mcp-code-note",
351
+ text: "A new code appears every 2 minutes and after each use."
352
+ }));
353
+ const signInLine = el(doc, "p", {
354
+ className: "tab-mcp-sign-in",
355
+ text: "When your AI app asks, sign in with the account you use on this page. No code is needed."
356
+ });
357
+ const steps = el(doc, "ul");
358
+ const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: "How do I add it?" }), steps);
359
+ const appList = el(doc, "ul");
360
+ const apps = el(doc, "div", { className: "tab-mcp-apps" }, el(doc, "h3", { text: "Connected" }), appList);
361
+ const closeNote = el(doc, "small", {
362
+ className: "tab-mcp-close-note",
363
+ text: "Closing this stops the code. The address stays the same: to connect later, open this again from the page."
364
+ });
365
+ const close = button(doc, "Close", () => dialog.close(), "tab-mcp-close");
366
+ const done = button(doc, "Done", () => dialog.close(), "tab-mcp-done", "primary");
367
+ done.hidden = true;
368
+ const actions = el(doc, "div", { className: "tab-mcp-actions" }, closeNote, " ", close, done);
369
+ let paired = false;
370
+ const pairedGrants = new Set;
371
+ const renderCloseNote = () => {
372
+ closeNote.hidden = paired || codeLine.hidden;
373
+ };
374
+ const setPaired = (value) => {
375
+ paired = value;
376
+ if (!paired)
377
+ pairedGrants.clear();
378
+ const focused = doc.activeElement;
379
+ renderCloseNote();
380
+ close.hidden = paired;
381
+ done.hidden = !paired;
382
+ if (paired && focused === close)
383
+ done.focus();
384
+ if (!paired && focused === done)
385
+ close.focus();
386
+ };
387
+ const closer = () => paired ? done : close;
388
+ dialog.append(status, addressBox, confirmBox, codeLine, signInLine, help, apps, actions, live);
389
+ addressBox.hidden = true;
390
+ codeLine.hidden = true;
391
+ signInLine.hidden = true;
392
+ help.hidden = true;
393
+ apps.hidden = true;
394
+ let renewing = false;
395
+ const renderQuestion = () => {
396
+ const names = mcp.grants.map((g) => clientLabel(g.client));
397
+ if (names.length === 0)
398
+ return false;
399
+ confirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? "it" : "them"}.`;
400
+ return true;
401
+ };
402
+ const askNewAddress = () => {
403
+ if (mcp.state !== "connected")
404
+ return;
405
+ if (!renderQuestion()) {
406
+ getNewAddress();
407
+ return;
408
+ }
409
+ confirmBox.hidden = false;
410
+ cancelNew.focus();
411
+ };
412
+ const getNewAddress = () => {
413
+ setPaired(false);
414
+ close.focus();
415
+ confirmBox.hidden = true;
416
+ renewing = true;
417
+ status.textContent = "Getting a new address…";
418
+ mcp.newAddress().then(() => {
419
+ renewing = false;
420
+ status.textContent = "This is a new address. Add it to your AI app again.";
421
+ copy.focus();
422
+ }, (error) => {
423
+ renewing = false;
424
+ status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;
425
+ closer().focus();
426
+ });
427
+ };
428
+ const renderSession = (session) => {
429
+ if (session === undefined) {
430
+ addressBox.hidden = true;
431
+ confirmBox.hidden = true;
432
+ help.hidden = true;
433
+ return;
434
+ }
435
+ address.value = session.address;
436
+ resetCopy();
437
+ const appName = session.appName ?? mcp.appName;
438
+ if (!renewing)
439
+ status.textContent = appName !== undefined ? `${appName} is ready for your AI app.` : "This page is ready for your AI app.";
440
+ fresh.disabled = mcp.state !== "connected";
441
+ addressBox.hidden = false;
442
+ if (doc.activeElement === dialog)
443
+ copy.focus();
444
+ help.hidden = false;
445
+ steps.replaceChildren(...instructions(serverName, session.address).map(([app, how, command, note]) => {
446
+ const item = el(doc, "li", {}, el(doc, "strong", { text: `${app}:` }), ` ${how}`);
447
+ if (command !== undefined) {
448
+ const text = el(doc, "pre", { text: command });
449
+ text.dir = "ltr";
450
+ const { button: copyCommand } = copyButton(doc, `${app} command`, () => text.textContent ?? "", () => doc.getSelection()?.selectAllChildren(text), announce, "tab-mcp-command-copy");
451
+ item.append(el(doc, "div", { className: "tab-mcp-command" }, text, copyCommand));
452
+ }
453
+ if (note !== undefined)
454
+ item.append(el(doc, "small", { className: "tab-mcp-command-note" }, ...note.map((part, i) => i % 2 === 1 ? el(doc, "code", { text: part }) : part)));
455
+ return item;
456
+ }));
457
+ };
458
+ const renderCode = () => {
459
+ const current = mcp.pairingCode;
460
+ const oidc = mcp.session?.pairing === "oidc";
461
+ if (code.textContent !== (current?.code ?? ""))
462
+ resetCopyCode();
463
+ code.textContent = current?.code ?? "";
464
+ codeLine.hidden = oidc || current === undefined;
465
+ signInLine.hidden = !oidc;
466
+ renderCloseNote();
467
+ };
468
+ const appsNote = el(doc, "p", { className: "tab-mcp-apps-note" });
469
+ apps.append(appsNote);
470
+ const known = new Set(mcp.grants.map((g) => g.grantId));
471
+ let session = mcp.session;
472
+ const renderGrants = () => {
473
+ if (mcp.session !== session) {
474
+ session = mcp.session;
475
+ for (const grant of mcp.grants)
476
+ known.add(grant.grantId);
477
+ }
478
+ for (const grant of mcp.grants) {
479
+ if (known.has(grant.grantId))
480
+ continue;
481
+ known.add(grant.grantId);
482
+ status.textContent = `${clientLabel(grant.client)} is connected.`;
483
+ pairedGrants.add(grant.grantId);
484
+ if (!paired)
485
+ setPaired(true);
486
+ }
487
+ if (paired && !mcp.grants.some((g) => pairedGrants.has(g.grantId))) {
488
+ setPaired(false);
489
+ }
490
+ const connected = mcp.state === "connected";
491
+ appList.replaceChildren(...mcp.grants.map((grant) => {
492
+ const disconnect = button(doc, "Disconnect", () => {
493
+ if (!mcp.revoke(grant.grantId))
494
+ renderGrants();
495
+ }, "tab-mcp-disconnect", "danger");
496
+ disconnect.disabled = !connected;
497
+ return el(doc, "li", {}, el(doc, "span", {
498
+ className: "tab-mcp-app",
499
+ text: `${clientLabel(grant.client)} connected `
500
+ }), disconnect);
501
+ }));
502
+ appsNote.textContent = connected ? "" : "To disconnect an app, connect this page again first.";
503
+ appsNote.hidden = connected;
504
+ apps.hidden = mcp.grants.length === 0;
505
+ if (!confirmBox.hidden && !renderQuestion()) {
506
+ confirmBox.hidden = true;
507
+ fresh.focus();
508
+ }
509
+ };
510
+ const onDisconnected = (event) => {
511
+ if (event.detail.reason !== "new_address")
512
+ status.textContent = "Disconnected. AI apps can use this page again after you connect.";
513
+ renderSession(undefined);
514
+ renderGrants();
515
+ renderCode();
516
+ };
517
+ const onConnected = () => {
518
+ renderSession(mcp.session);
519
+ renderGrants();
520
+ renderCode();
521
+ };
522
+ mcp.addEventListener("pairingcode", renderCode);
523
+ mcp.addEventListener("grantschange", renderGrants);
524
+ mcp.addEventListener("connected", onConnected);
525
+ mcp.addEventListener("disconnected", onDisconnected);
526
+ doc.body.append(dialog);
527
+ mcp.startPairing();
528
+ renderGrants();
529
+ renderCode();
530
+ renderSession(mcp.session);
531
+ connecting.then((session) => renderSession(session), (error) => {
532
+ status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;
533
+ });
534
+ return new Promise((resolve) => {
535
+ dialog.addEventListener("close", () => {
536
+ mcp.stopPairing();
537
+ mcp.removeEventListener("pairingcode", renderCode);
538
+ mcp.removeEventListener("grantschange", renderGrants);
539
+ mcp.removeEventListener("connected", onConnected);
540
+ mcp.removeEventListener("disconnected", onDisconnected);
541
+ dialog.remove();
542
+ resolve();
543
+ }, { once: true });
544
+ dialog.showModal();
545
+ if (!addressBox.hidden)
546
+ copy.focus();
547
+ else
548
+ dialog.focus();
549
+ });
550
+ }
551
+ export {
552
+ confirmDialog,
553
+ showConnectDialog
554
+ };
555
+
556
+ //# debugId=407E5B4A799538BD64756E2164756E21
557
+ //# sourceMappingURL=ui-gkxbbn8v.js.map