@ractive-ch/tab-mcp-client 0.18.1 → 0.19.0-rc.1

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 (86) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +348 -68
  3. package/allowed.d.ts +2 -2
  4. package/allowed.js.map +1 -1
  5. package/always-allowed.d.ts +15 -15
  6. package/cdn/allowed.min.js +2 -2
  7. package/cdn/allowed.min.js.map +2 -2
  8. package/cdn/confirm-ba3dkf9p.min.js +4 -0
  9. package/cdn/confirm-ba3dkf9p.min.js.map +10 -0
  10. package/cdn/connect-my0pbqd7.min.js +6 -0
  11. package/cdn/connect-my0pbqd7.min.js.map +12 -0
  12. package/cdn/connection-yf2x9zz2.min.js +17 -0
  13. package/cdn/{connection-0xqwz17v.min.js.map → connection-yf2x9zz2.min.js.map} +5 -5
  14. package/cdn/strings.min.js +4 -0
  15. package/cdn/strings.min.js.map +9 -0
  16. package/cdn/{tab-mcp-client-2vx9mcww.min.js → tab-mcp-client-8r6h3wza.min.js} +9 -8
  17. package/cdn/tab-mcp-client-8r6h3wza.min.js.map +11 -0
  18. package/cdn/tab-mcp-client-nnxcwrxp.min.js +5 -0
  19. package/cdn/tab-mcp-client-nnxcwrxp.min.js.map +11 -0
  20. package/cdn/{tab-mcp-client-5j3brdf3.min.js → tab-mcp-client-q758jr4g.min.js} +4 -4
  21. package/cdn/tab-mcp-client-q758jr4g.min.js.map +10 -0
  22. package/cdn/tab-mcp-client.min.js +3 -3
  23. package/cdn/tab-mcp-client.min.js.map +4 -4
  24. package/cdn/webmcp-84k58gsw.min.js +4 -0
  25. package/cdn/webmcp-84k58gsw.min.js.map +11 -0
  26. package/{confirm-bqfdrx3f.js → confirm-hymzwx3b.js} +7 -5
  27. package/confirm-hymzwx3b.js.map +10 -0
  28. package/confirm.d.ts +2 -2
  29. package/{connect-ztsgybpq.js → connect-fhtjdmf3.js} +75 -37
  30. package/connect-fhtjdmf3.js.map +10 -0
  31. package/connect.d.ts +7 -6
  32. package/{connection-gang7f5x.js → connection-73fbg99k.js} +70 -8
  33. package/connection-73fbg99k.js.map +16 -0
  34. package/connection.d.ts +23 -2
  35. package/dialog.d.ts +19 -9
  36. package/extension.d.ts +347 -0
  37. package/extension.js +394 -0
  38. package/extension.js.map +10 -0
  39. package/handshake.d.ts +82 -0
  40. package/index-00p8b969.js +221 -0
  41. package/index-00p8b969.js.map +11 -0
  42. package/index-1tssct09.js +58 -0
  43. package/index-1tssct09.js.map +11 -0
  44. package/{index-c1c266tm.js → index-7qqhn3zv.js} +28 -110
  45. package/index-7qqhn3zv.js.map +10 -0
  46. package/index-s31xrfa2.js.map +1 -1
  47. package/index.d.ts +1 -1
  48. package/index.js +59 -64
  49. package/index.js.map +4 -4
  50. package/internal.d.ts +2 -0
  51. package/mcp.d.ts +5 -3
  52. package/package.json +11 -2
  53. package/protocol.d.ts +11 -1
  54. package/react.d.ts +11 -4
  55. package/react.js +57 -10
  56. package/react.js.map +5 -4
  57. package/secret.d.ts +1 -1
  58. package/setup.d.ts +4 -1
  59. package/setup.js +3 -2
  60. package/setup.js.map +1 -1
  61. package/strings.d.ts +149 -28
  62. package/strings.js +13 -0
  63. package/strings.js.map +9 -0
  64. package/tab-mcp.d.ts +30 -7
  65. package/text.d.ts +39 -0
  66. package/types.d.ts +76 -17
  67. package/webmcp-d2ec3v3g.js +221 -0
  68. package/webmcp-d2ec3v3g.js.map +11 -0
  69. package/webmcp.d.ts +17 -4
  70. package/cdn/confirm-d722a9eb.min.js +0 -4
  71. package/cdn/confirm-d722a9eb.min.js.map +0 -10
  72. package/cdn/connect-x6ws6wqt.min.js +0 -6
  73. package/cdn/connect-x6ws6wqt.min.js.map +0 -12
  74. package/cdn/connection-0xqwz17v.min.js +0 -17
  75. package/cdn/tab-mcp-client-2vx9mcww.min.js.map +0 -12
  76. package/cdn/tab-mcp-client-5j3brdf3.min.js.map +0 -10
  77. package/cdn/webmcp-khy4f5rj.min.js +0 -4
  78. package/cdn/webmcp-khy4f5rj.min.js.map +0 -10
  79. package/confirm-bqfdrx3f.js.map +0 -10
  80. package/connect-ztsgybpq.js.map +0 -10
  81. package/connection-gang7f5x.js.map +0 -16
  82. package/index-5jyqehpk.js +0 -63
  83. package/index-5jyqehpk.js.map +0 -11
  84. package/index-c1c266tm.js.map +0 -11
  85. package/webmcp-zq1enyz0.js +0 -57
  86. package/webmcp-zq1enyz0.js.map +0 -10
@@ -1,24 +1,27 @@
1
1
  import {
2
2
  allowedFor
3
3
  } from "./index-s31xrfa2.js";
4
+ import {
5
+ format,
6
+ plural
7
+ } from "./index-00p8b969.js";
4
8
  import"./index-dmh5vm5m.js";
5
9
  import {
6
10
  nextId,
7
11
  stringsOf,
8
- format,
9
12
  fill,
10
13
  el,
11
14
  button,
15
+ showNames,
12
16
  visible,
13
17
  clientLabel,
14
- listOf,
15
18
  newDialog,
16
19
  copyButton
17
- } from "./index-c1c266tm.js";
20
+ } from "./index-7qqhn3zv.js";
18
21
  import {
19
22
  SETUP_GUIDE2,
20
23
  setupInstructions2
21
- } from "./index-5jyqehpk.js";
24
+ } from "./index-1tssct09.js";
22
25
 
23
26
  // src/connect.ts
24
27
  function switchOf(doc, text, onToggle) {
@@ -33,7 +36,7 @@ function allowedSwitches(doc, s, allowed, grantId, app) {
33
36
  const title = el(doc, "p", {
34
37
  className: "tab-mcp-allowed-title",
35
38
  id: `${nextId()}-allowed`,
36
- text: s.runsWithoutAsking
39
+ text: allowed.kept ? s.alwaysAllow : s.allowUntilReload
37
40
  });
38
41
  const list = el(doc, "div", { className: "tab-mcp-switches" });
39
42
  const all = switchOf(doc, el(doc, "span", { text: s.allowEverything }), (on) => {
@@ -43,7 +46,7 @@ function allowedSwitches(doc, s, allowed, grantId, app) {
43
46
  });
44
47
  all.label.classList.add("tab-mcp-everything");
45
48
  all.input.setAttribute("aria-label", format(s.allowEverythingApp, { app }));
46
- const note = el(doc, "small", { className: "tab-mcp-everything-note", id: `${title.id}-note` }, ...fill(doc, s.allowEverythingNote, { app }));
49
+ const note = el(doc, "small", { className: "tab-mcp-everything-note", id: `${title.id}-note` }, ...fill(doc, allowed.kept ? s.allowEverythingNote : s.allowEverythingUntilReloadNote, { app }));
47
50
  all.input.setAttribute("aria-describedby", note.id);
48
51
  const box = el(doc, "div", { className: "tab-mcp-allowed" });
49
52
  box.setAttribute("role", "group");
@@ -189,11 +192,11 @@ function replacedNotice(mcp, doc, sibling, ui) {
189
192
  const actions = el(doc, "div", { className: "tab-mcp-actions" }, close);
190
193
  let first = close;
191
194
  if (!sibling) {
192
- const fresh = button(doc, s.newAddress, () => {
195
+ const fresh = button(doc, s.disconnectAll, () => {
193
196
  fresh.disabled = true;
194
197
  status.hidden = false;
195
- status.textContent = s.gettingNewAddress;
196
- mcp.newAddress().then(() => {
198
+ status.textContent = s.disconnectingAll;
199
+ mcp.disconnectAll().then(() => {
197
200
  dialog.close();
198
201
  mcp.showConnectDialog({ document: doc }).catch(() => {});
199
202
  }, (error) => {
@@ -202,7 +205,7 @@ function replacedNotice(mcp, doc, sibling, ui) {
202
205
  reason: connectFailure(error, s)
203
206
  });
204
207
  });
205
- }, "tab-mcp-new-address", "primary");
208
+ }, "tab-mcp-disconnect-all", "primary");
206
209
  actions.append(" ", fresh);
207
210
  first = fresh;
208
211
  }
@@ -237,6 +240,7 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
237
240
  const announce = (text) => {
238
241
  live.textContent = live.textContent === text ? `${text} ` : text;
239
242
  };
243
+ const viaExtension = el(doc, "p", { className: "tab-mcp-via-extension" });
240
244
  const successId = `${nextId()}-success`;
241
245
  const successTitle = el(doc, "p", { className: "tab-mcp-success-title" });
242
246
  const successNext = el(doc, "p", { className: "tab-mcp-success-next" });
@@ -253,17 +257,17 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
253
257
  address.readOnly = true;
254
258
  const { button: copy, reset: resetCopy } = copyButton(doc, s, s.copyAddress, () => address.value, () => address.select(), announce, "tab-mcp-address-copy", "primary");
255
259
  const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy);
256
- const fresh = button(doc, s.newAddress, () => askNewAddress(), "tab-mcp-new-address");
257
- const freshBox = el(doc, "div", { className: "tab-mcp-new-address-row" }, el(doc, "small", { text: s.newAddressNote }), " ", fresh);
258
- const questionId = `${nextId()}-new-address`;
260
+ const fresh = button(doc, s.disconnectAll, () => askDisconnectAll(), "tab-mcp-disconnect-all");
261
+ const freshBox = el(doc, "div", { className: "tab-mcp-disconnect-all-row" }, el(doc, "small", { text: s.disconnectAllNote }), " ", fresh);
262
+ const questionId = `${nextId()}-disconnect-all`;
259
263
  const questionText = el(doc, "p", { id: questionId });
260
264
  const cancelNew = button(doc, s.cancel, () => {
261
265
  asking = false;
262
266
  render();
263
267
  fresh.focus();
264
268
  });
265
- const confirmNew = button(doc, s.newAddressConfirm, () => getNewAddress(), "tab-mcp-new-address-confirm", "danger");
266
- const question = el(doc, "div", { className: "tab-mcp-new-address-question" }, questionText, el(doc, "div", { className: "tab-mcp-actions" }, cancelNew, " ", confirmNew));
269
+ const confirmNew = button(doc, s.disconnectAllConfirm, () => runDisconnectAll(), "tab-mcp-disconnect-all-confirm", "danger");
270
+ const question = el(doc, "div", { className: "tab-mcp-disconnect-all-question" }, questionText, el(doc, "div", { className: "tab-mcp-actions" }, cancelNew, " ", confirmNew));
267
271
  question.setAttribute("role", "group");
268
272
  question.setAttribute("aria-labelledby", questionId);
269
273
  const code = el(doc, "strong", { className: "tab-mcp-code-value" });
@@ -274,10 +278,24 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
274
278
  codeSentence.setAttribute("aria-live", "polite");
275
279
  const codeUsed = el(doc, "span", { className: "tab-mcp-code-used" });
276
280
  const codeLine = el(doc, "p", { className: "tab-mcp-code" }, codeSentence, codeUsed, " ", copyCode, el(doc, "br"), el(doc, "small", { className: "tab-mcp-code-note", text: s.codeNote }));
277
- const signInLine = el(doc, "p", {
278
- className: "tab-mcp-sign-in",
279
- text: s.signIn
281
+ const signInUntil = el(doc, "small", {
282
+ className: "tab-mcp-sign-in-until"
280
283
  });
284
+ const timeOf = (iso) => {
285
+ const time = new Date(iso);
286
+ try {
287
+ return time.toLocaleTimeString(s.lang, {
288
+ hour: "numeric",
289
+ minute: "2-digit"
290
+ });
291
+ } catch {
292
+ return time.toLocaleTimeString();
293
+ }
294
+ };
295
+ const signInLine = el(doc, "p", { className: "tab-mcp-sign-in" }, s.signIn, el(doc, "br"), signInUntil);
296
+ const more = button(doc, s.continuePairing, () => mcp.startPairing(), "tab-mcp-continue", "primary");
297
+ const timeUpText = el(doc, "span", { text: s.signInTimeUp });
298
+ const timeUp = el(doc, "p", { className: "tab-mcp-time-up" }, timeUpText, " ", more);
281
299
  const steps = el(doc, "ul");
282
300
  const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: s.help }), steps);
283
301
  const guideUrl = ui?.setup?.guide === undefined ? SETUP_GUIDE2 : ui.setup.guide;
@@ -288,9 +306,9 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
288
306
  guide.rel = "noopener noreferrer";
289
307
  help.append(el(doc, "p", { className: "tab-mcp-guide" }, guide));
290
308
  }
291
- const instructions = ui?.setup?.instructions ?? setupInstructions2;
309
+ const instructions = ui?.setup?.instructions ?? ((name, address) => setupInstructions2(name, address, s));
292
310
  const setupId = `${nextId()}-setup`;
293
- const setup = el(doc, "div", { className: "tab-mcp-setup", id: setupId }, addressBox, help, codeLine, signInLine, freshBox, question);
311
+ const setup = el(doc, "div", { className: "tab-mcp-setup", id: setupId }, addressBox, help, codeLine, signInLine, timeUp, freshBox, question);
294
312
  const setupToggle = button(doc, s.connectAnother, () => {
295
313
  expanded = !expanded;
296
314
  render();
@@ -320,7 +338,7 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
320
338
  render();
321
339
  }, "tab-mcp-retry", "primary");
322
340
  const actions = el(doc, "div", { className: "tab-mcp-actions" }, closeNote, " ", close, retry, done);
323
- dialog.append(success, status, apps, setupToggle, setup, actions, live);
341
+ dialog.append(viaExtension, success, status, apps, setupToggle, setup, actions, live);
324
342
  let expanded = false;
325
343
  let asking = false;
326
344
  let renewing = false;
@@ -331,6 +349,7 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
331
349
  let stepsFor;
332
350
  let shownCode;
333
351
  let usedTimer;
352
+ let untilTimer;
334
353
  let connectedView = false;
335
354
  const closer = () => connectedView ? done : retry.hidden ? close : retry;
336
355
  const start = () => connectedView ? done : copy;
@@ -408,6 +427,11 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
408
427
  const oidc = session?.pairing === "oidc";
409
428
  const signIn = oidc ? signInText(mcp, s) : undefined;
410
429
  const shown = session !== undefined && signIn === undefined;
430
+ const until = oidc ? mcp.pairingUntil : undefined;
431
+ const left = until === undefined ? 1 : Date.parse(until) - Date.now();
432
+ const over = connected && shown && left <= 0;
433
+ clearTimeout(untilTimer);
434
+ untilTimer = left > 0 && until !== undefined ? setTimeout(render, Math.min(left, 60000)) : undefined;
411
435
  const ids = new Set(grants.map((g) => g.grantId));
412
436
  const paired = connected && grants.some((g) => !grantsSeen.has(g.grantId));
413
437
  grantsSeen = ids;
@@ -420,20 +444,23 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
420
444
  if (names.length === 0 || !shown)
421
445
  asking = false;
422
446
  connectedView = !renewing && connected && grants.length > 0;
423
- const one = names.length === 1;
424
- successTitle.textContent = format(one ? s.connectedOne : s.connectedMany, {
425
- apps: listOf(names, s)
426
- });
427
- successNext.textContent = one ? s.connectedNextOne : s.connectedNextMany;
447
+ showNames(doc, successTitle, s.connected, names, s);
448
+ successNext.textContent = plural(s.connectedNext, names.length, s);
428
449
  if (connectedView)
429
450
  dialog.setAttribute("aria-describedby", successId);
430
451
  else
431
452
  dialog.removeAttribute("aria-describedby");
432
453
  success.hidden = !connectedView;
454
+ const extension = mcp.extension;
455
+ const via = [
456
+ ...new Set((extension?.apps ?? []).map((a) => clientLabel({ id: a.host, name: a.name, host: a.host }, s)))
457
+ ];
458
+ viaExtension.hidden = via.length === 0;
459
+ showNames(doc, viaExtension, extension?.whileInFront ? s.viaExtensionInFront : s.viaExtension, via, s);
433
460
  if (connected)
434
461
  message = undefined;
435
462
  const appName = session?.appName;
436
- status.textContent = renewing ? s.gettingNewAddress : state === "connecting" ? s.connecting : state === "reconnecting" ? s.reconnecting : !connected ? message ?? s.notConnected : signIn ?? (renewed ? s.newAddressDone : appName !== undefined ? format(s.readyApp, { app: appName }) : s.readyPage);
463
+ status.textContent = renewing ? s.disconnectingAll : state === "connecting" ? s.connecting : state === "reconnecting" ? s.reconnecting : !connected ? message ?? s.notConnected : signIn ?? (over ? s.signInTimeUp : renewed ? s.disconnectAllDone : appName !== undefined ? format(s.readyApp, { app: appName }) : s.readyPage);
437
464
  status.hidden = connectedView;
438
465
  const addressShownBefore = !addressBox.hidden;
439
466
  if (shown && address.value !== session.address) {
@@ -446,10 +473,14 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
446
473
  fresh.disabled = !connected;
447
474
  question.hidden = !asking;
448
475
  if (asking)
449
- questionText.textContent = format(one ? s.newAddressQuestionOne : s.newAddressQuestionMany, { apps: listOf(names, s) });
476
+ showNames(doc, questionText, s.disconnectAllQuestion, names, s);
450
477
  const hasCode = renderCode(paired);
451
478
  codeLine.hidden = oidc || !hasCode || !connected;
452
- signInLine.hidden = !oidc || mcp.identity !== "bound";
479
+ signInLine.hidden = !oidc || mcp.identity !== "bound" || over;
480
+ signInUntil.textContent = until === undefined ? "" : format(s.signInUntil, { time: timeOf(until) });
481
+ signInUntil.hidden = until === undefined;
482
+ timeUp.hidden = !over;
483
+ timeUpText.hidden = !connectedView;
453
484
  setupToggle.hidden = !connectedView;
454
485
  setupToggle.setAttribute("aria-expanded", String(expanded));
455
486
  setup.hidden = connectedView && !expanded;
@@ -479,7 +510,7 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
479
510
  done.hidden = !connectedView;
480
511
  retry.hidden = renewing || state !== "disconnected" && state !== "reconnecting";
481
512
  if (focused !== null && focused !== dialog && focused !== doc.body && (!focused.isConnected || dialog.contains(focused) && focused.closest("[hidden]") !== null))
482
- (question.contains(focused) && !freshBox.hidden ? fresh : closer()).focus();
513
+ (question.contains(focused) && !freshBox.hidden ? fresh : focused === more && !setup.hidden ? start() : closer()).focus();
483
514
  else if (doc.activeElement === dialog && (connectedView || shown))
484
515
  start().focus();
485
516
  else if (renewed && shown && !addressShownBefore && doc.activeElement === close)
@@ -487,24 +518,24 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
487
518
  if (paired && connectedView)
488
519
  announce(`${successTitle.textContent}. ${successNext.textContent}`);
489
520
  };
490
- const askNewAddress = () => {
521
+ const askDisconnectAll = () => {
491
522
  if (mcp.state !== "connected")
492
523
  return;
493
524
  if (mcp.grants.length === 0) {
494
- getNewAddress();
525
+ runDisconnectAll();
495
526
  return;
496
527
  }
497
528
  asking = true;
498
529
  render();
499
530
  cancelNew.focus();
500
531
  };
501
- const getNewAddress = () => {
532
+ const runDisconnectAll = () => {
502
533
  renewing = true;
503
534
  renewed = false;
504
535
  close.focus();
505
536
  asking = false;
506
537
  render();
507
- mcp.newAddress().then(() => {
538
+ mcp.disconnectAll().then(() => {
508
539
  renewing = false;
509
540
  renewed = true;
510
541
  render();
@@ -526,7 +557,7 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
526
557
  };
527
558
  const onState = (event) => {
528
559
  const { state, reason } = event.detail;
529
- if (reason !== undefined && reason !== "new_address") {
560
+ if (reason !== undefined && reason !== "disconnect_all") {
530
561
  message = disconnectedText(reason, s);
531
562
  renewed = false;
532
563
  }
@@ -541,8 +572,11 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
541
572
  const stopAllowed = allowed.onChange(render);
542
573
  mcp.addEventListener("statechange", onState);
543
574
  mcp.addEventListener("pairingcode", render);
575
+ mcp.addEventListener("pairinguntil", render);
576
+ doc.addEventListener("visibilitychange", render);
544
577
  mcp.addEventListener("grantschange", render);
545
578
  mcp.addEventListener("identitychange", render);
579
+ mcp.addEventListener("extensionchange", render);
546
580
  mcp.addEventListener("error", onError);
547
581
  mcp.addEventListener("replaced", onReplaced);
548
582
  doc.body.append(dialog);
@@ -555,12 +589,16 @@ function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
555
589
  return new Promise((resolve) => {
556
590
  dialog.addEventListener("close", () => {
557
591
  clearTimeout(usedTimer);
592
+ clearTimeout(untilTimer);
558
593
  mcp.stopPairing();
559
594
  stopAllowed();
560
595
  mcp.removeEventListener("statechange", onState);
561
596
  mcp.removeEventListener("pairingcode", render);
597
+ mcp.removeEventListener("pairinguntil", render);
598
+ doc.removeEventListener("visibilitychange", render);
562
599
  mcp.removeEventListener("grantschange", render);
563
600
  mcp.removeEventListener("identitychange", render);
601
+ mcp.removeEventListener("extensionchange", render);
564
602
  mcp.removeEventListener("error", onError);
565
603
  mcp.removeEventListener("replaced", onReplaced);
566
604
  dialog.remove();
@@ -577,5 +615,5 @@ export {
577
615
  showConnectDialog
578
616
  };
579
617
 
580
- //# debugId=90A68AE264A1104964756E2164756E21
581
- //# sourceMappingURL=connect-ztsgybpq.js.map
618
+ //# debugId=9A4352A5FEBFD1FE64756E2164756E21
619
+ //# sourceMappingURL=connect-fhtjdmf3.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/connect.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The \"Connect your AI app\" dialog (DEC-028) and the notice that the page\n * lost its address, loaded on demand when a page opens the dialog.\n */\n\nimport { type Allowances, allowedFor } from \"./always-allowed.ts\";\nimport {\n\tbutton,\n\tclientLabel,\n\tcopyButton,\n\tel,\n\tfill,\n\tformat,\n\tnewDialog,\n\tnextId,\n\tplural,\n\tshowNames,\n\tstringsOf,\n\tvisible,\n} from \"./dialog.ts\";\nimport { SETUP_GUIDE, setupInstructions } from \"./setup.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tDialogOptions,\n\tDisconnectReason,\n\tGrant,\n\tPairingCode,\n\tSessionInfo,\n\tStateChangeDetail,\n} from \"./types.ts\";\n\n/** A switch: a checkbox with `role=\"switch\"` in its label, which a click on the text turns too. */\nfunction switchOf(\n\tdoc: Document,\n\ttext: HTMLElement,\n\tonToggle: (on: boolean) => void,\n): { label: HTMLLabelElement; input: HTMLInputElement } {\n\tconst input = el(doc, \"input\");\n\tinput.type = \"checkbox\";\n\tinput.setAttribute(\"role\", \"switch\");\n\tinput.addEventListener(\"change\", () => onToggle(input.checked));\n\tconst label = el(doc, \"label\", { className: \"tab-mcp-switch\" }, input, text);\n\treturn { label, input };\n}\n\n/**\n * Under a connected app, the switches for what runs without asking. With\n * `alwaysAllow` (`offered`): a switch per tool that asks (its title or\n * name, destructive ones marked) and \"Always allow everything\" with what it\n * means, under the confirmation's own label (\"Always allow\", or \"Allow\n * until reload\" when nothing is kept), so the button and the switches it\n * turns on read alike. Without it, only what is allowed now, as switches that\n * can only be turned off (\"everything\" only while it is on): the user sees\n * what runs without asking and can end it, and is never offered more than\n * the page chose to offer. Tools allowed but not registered right now are\n * listed by name, also only to turn off. Each switch's accessible name names\n * the app: the list has one set per app. `render` updates it in place, so a\n * focused switch keeps its focus.\n */\nfunction allowedSwitches(\n\tdoc: Document,\n\ts: DialogStrings,\n\tallowed: Allowances,\n\tgrantId: string,\n\tapp: string,\n): { box: HTMLElement; render: () => void } {\n\tconst title = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-allowed-title\",\n\t\tid: `${nextId()}-allowed`,\n\t\ttext: allowed.kept ? s.alwaysAllow : s.allowUntilReload,\n\t});\n\tconst list = el(doc, \"div\", { className: \"tab-mcp-switches\" });\n\t// Turning on only where the page offers it; the store decides the rest.\n\tconst all = switchOf(\n\t\tdoc,\n\t\tel(doc, \"span\", { text: s.allowEverything }),\n\t\t(on) => {\n\t\t\tif (!on || allowed.offered) allowed.setEverything(grantId, on);\n\t\t\trender();\n\t\t},\n\t);\n\tall.label.classList.add(\"tab-mcp-everything\");\n\tall.input.setAttribute(\"aria-label\", format(s.allowEverythingApp, { app }));\n\tconst note = el(\n\t\tdoc,\n\t\t\"small\",\n\t\t{ className: \"tab-mcp-everything-note\", id: `${title.id}-note` },\n\t\t...fill(\n\t\t\tdoc,\n\t\t\tallowed.kept ? s.allowEverythingNote : s.allowEverythingUntilReloadNote,\n\t\t\t{ app },\n\t\t),\n\t);\n\tall.input.setAttribute(\"aria-describedby\", note.id);\n\t// Filled when first shown: a page without it has no switches in its DOM.\n\tconst box = el(doc, \"div\", { className: \"tab-mcp-allowed\" });\n\tbox.setAttribute(\"role\", \"group\");\n\tbox.setAttribute(\"aria-labelledby\", title.id);\n\tconst switches = new Map<\n\t\tstring,\n\t\tReturnType<typeof switchOf> & {\n\t\t\tname: HTMLElement;\n\t\t\tmark: HTMLElement;\n\t\t\toffOnly: boolean;\n\t\t}\n\t>();\n\tconst render = () => {\n\t\tconst everything = allowed.everything(grantId);\n\t\tconst listed = allowed.list(grantId);\n\t\tconst on = new Set(listed);\n\t\tconst asking = new Map(allowed.tools().map((t) => [t.name, t]));\n\t\tconst rows: {\n\t\t\tname: string;\n\t\t\tshown: string;\n\t\t\tdestructive: boolean;\n\t\t\toffOnly: boolean;\n\t\t}[] = [];\n\t\tif (allowed.offered)\n\t\t\tfor (const t of asking.values())\n\t\t\t\trows.push({\n\t\t\t\t\tname: t.name,\n\t\t\t\t\tshown: t.title ?? t.name,\n\t\t\t\t\tdestructive: t.destructive,\n\t\t\t\t\toffOnly: false,\n\t\t\t\t});\n\t\tfor (const name of listed) {\n\t\t\tif (allowed.offered && asking.has(name)) continue;\n\t\t\tconst t = asking.get(name);\n\t\t\trows.push({\n\t\t\t\tname,\n\t\t\t\tshown: t?.title ?? name,\n\t\t\t\tdestructive: t?.destructive === true,\n\t\t\t\toffOnly: true,\n\t\t\t});\n\t\t}\n\t\tconst showAll = allowed.offered || everything;\n\t\tbox.hidden = rows.length === 0 && !everything;\n\t\tif (box.hidden) return;\n\t\tif (!box.hasChildNodes()) box.append(title, list, all.label, note);\n\t\tconst names = new Set(rows.map((r) => r.name));\n\t\tfor (const [name, { label }] of switches) {\n\t\t\tif (names.has(name)) continue;\n\t\t\tlabel.remove();\n\t\t\tswitches.delete(name);\n\t\t}\n\t\trows.forEach((row, i) => {\n\t\t\tlet entry = switches.get(row.name);\n\t\t\tif (entry === undefined) {\n\t\t\t\tconst name = el(doc, \"span\");\n\t\t\t\tconst mark = el(doc, \"small\", {\n\t\t\t\t\tclassName: \"tab-mcp-destructive\",\n\t\t\t\t\ttext: s.destructive,\n\t\t\t\t});\n\t\t\t\tconst made = switchOf(\n\t\t\t\t\tdoc,\n\t\t\t\t\tel(doc, \"span\", {}, name, \" \", mark),\n\t\t\t\t\t(turnedOn) => {\n\t\t\t\t\t\tif (!turnedOn) allowed.ask(grantId, row.name);\n\t\t\t\t\t\telse if (switches.get(row.name)?.offOnly === false)\n\t\t\t\t\t\t\tallowed.allow(grantId, row.name);\n\t\t\t\t\t\trender(); // also when nothing changed: the switch says the truth\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tentry = { ...made, name, mark, offOnly: row.offOnly };\n\t\t\t\tswitches.set(row.name, entry);\n\t\t\t}\n\t\t\tentry.offOnly = row.offOnly;\n\t\t\tconst shown = visible(row.shown);\n\t\t\tentry.name.textContent = shown;\n\t\t\tentry.mark.hidden = !row.destructive;\n\t\t\tentry.input.setAttribute(\n\t\t\t\t\"aria-label\",\n\t\t\t\tformat(row.destructive ? s.allowDestructiveToolApp : s.allowToolApp, {\n\t\t\t\t\ttool: shown,\n\t\t\t\t\tapp,\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// What runs without asking now: also every tool under \"everything\".\n\t\t\tentry.input.checked = everything || on.has(row.name);\n\t\t\tentry.input.disabled = everything;\n\t\t\tif (list.children[i] !== entry.label)\n\t\t\t\tlist.insertBefore(entry.label, list.children[i] ?? null);\n\t\t});\n\t\tall.label.hidden = note.hidden = !showAll;\n\t\tall.input.checked = everything;\n\t};\n\treturn { box, render };\n}\n\n/**\n * The labels of the apps behind these grants, each once: an app can hold\n * more than one grant (paired twice), and is still one app.\n */\nfunction appLabels(grants: readonly Grant[], s: DialogStrings): string[] {\n\treturn [...new Set(grants.map((g) => clientLabel(g.client, s)))];\n}\n\n/**\n * Why connecting failed, in the user's words (CU 4). The error itself, with\n * the relay's wording, goes to the console. Without a `reason` it never\n * started (no user action, cancelled): just not connected.\n */\nfunction connectFailure(error: unknown, s: DialogStrings): string {\n\tconsole.warn(\"tab-mcp: could not connect.\", error);\n\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\tif (reason === undefined) return s.notConnected;\n\tif (reason === \"network\") return s.unreachable;\n\tif (reason === \"rate_limited\") return s.rateLimited;\n\treturn s.refused;\n}\n\n/** Why the page was disconnected, in the user's words (CU 4). */\nfunction disconnectedText(reason: DisconnectReason, s: DialogStrings): string {\n\tswitch (reason) {\n\t\tcase \"expired\":\n\t\tcase \"idle\":\n\t\t\treturn s.ended;\n\t\tcase \"user\":\n\t\t\treturn s.disconnected;\n\t\tcase \"network\":\n\t\tcase \"heartbeat\":\n\t\tcase \"shutdown\":\n\t\t\treturn s.lost;\n\t\tcase \"rate_limited\":\n\t\t\treturn s.rateLimited;\n\t\tdefault:\n\t\t\treturn s.closed;\n\t}\n}\n\n/**\n * With identity binding: what stands between the user and the address until\n * the relay knows who is signed in (CU 7). `undefined` once it does.\n */\nfunction signInText(mcp: TabMcp, s: DialogStrings): string | undefined {\n\tswitch (mcp.identity) {\n\t\tcase \"bound\":\n\t\t\treturn undefined;\n\t\tcase \"pending\":\n\t\t\treturn s.checkingSignIn;\n\t\tcase \"refused\":\n\t\t\treturn mcp.identityMessage\n\t\t\t\t? format(s.signInRefusedWhy, { reason: mcp.identityMessage })\n\t\t\t\t: s.signInRefused;\n\t\tdefault:\n\t\t\treturn s.signInFirst;\n\t}\n}\n\n/** The document and texts of the connect dialog per `TabMcp`, once it was opened. */\nconst watched = new WeakMap<TabMcp, { doc: Document; ui?: DialogOptions }>();\n\n/**\n * Once a page has opened the connect dialog, the default UI also says when\n * the page loses its address (`replaced`), in that dialog's document.\n */\nfunction watchReplaced(mcp: TabMcp, doc: Document, ui?: DialogOptions): void {\n\tconst known = watched.has(mcp);\n\twatched.set(mcp, ui === undefined ? { doc } : { doc, ui });\n\tif (known) return;\n\tmcp.addEventListener(\"replaced\", (event) => {\n\t\tconst current = watched.get(mcp);\n\t\t// Not when the page already went on (`disconnectAll()` or `connect()` since).\n\t\tif (current !== undefined && mcp.state === \"disconnected\")\n\t\t\treplacedNotice(mcp, current.doc, event.detail.sibling, current.ui);\n\t});\n}\n\n/**\n * Says that the page lost its address (`replaced`, DEC-095). A sibling tab\n * that announced it: \"Opened in another tab\", nothing to do. Otherwise a\n * warning that another tab or program took over, with \"Disconnect all apps\"\n * (`disconnectAll()`), which takes the page back, disconnects its apps,\n * connects with a new secret and opens the connect dialog to connect the AI\n * apps again.\n */\nexport function replacedNotice(\n\tmcp: TabMcp,\n\tdoc: Document,\n\tsibling: boolean,\n\tui?: DialogOptions,\n): void {\n\tconst s = stringsOf(ui);\n\t(\n\t\tdoc.querySelector(\"dialog.tab-mcp-replaced\") as HTMLDialogElement | null\n\t)?.close();\n\tconst { dialog } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-replaced\",\n\t\ts,\n\t\tsibling ? s.replacedSiblingTitle : s.replacedTitle,\n\t);\n\tconst status = el(doc, \"p\", { className: \"tab-mcp-status\" });\n\tstatus.setAttribute(\"role\", \"status\");\n\tstatus.hidden = true;\n\tconst close = button(\n\t\tdoc,\n\t\ts.close,\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-replaced-close\",\n\t\tsibling ? \"primary\" : undefined,\n\t);\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\tlet first = close;\n\tif (!sibling) {\n\t\tconst fresh = button(\n\t\t\tdoc,\n\t\t\ts.disconnectAll,\n\t\t\t() => {\n\t\t\t\tfresh.disabled = true;\n\t\t\t\tstatus.hidden = false;\n\t\t\t\tstatus.textContent = s.disconnectingAll;\n\t\t\t\tmcp.disconnectAll().then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdialog.close();\n\t\t\t\t\t\tmcp.showConnectDialog({ document: doc }).catch(() => {});\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tfresh.disabled = false;\n\t\t\t\t\t\tstatus.textContent =\n\t\t\t\t\t\t\t(error as { reason?: unknown } | null)?.reason === \"replaced\"\n\t\t\t\t\t\t\t\t? s.takenOverAgain\n\t\t\t\t\t\t\t\t: format(s.tryAgainOrClose, {\n\t\t\t\t\t\t\t\t\t\treason: connectFailure(error, s),\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"tab-mcp-disconnect-all\",\n\t\t\t\"primary\",\n\t\t);\n\t\tactions.append(\" \", fresh);\n\t\tfirst = fresh;\n\t}\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: sibling ? s.replacedSibling : s.replaced,\n\t\t}),\n\t\tstatus,\n\t\tactions,\n\t);\n\tdialog.addEventListener(\"close\", () => dialog.remove(), { once: true });\n\tdoc.body.append(dialog);\n\tdialog.showModal();\n\tfirst.focus();\n}\n\n/**\n * How long a used code stays \"Code used\" before its replacement is shown: the\n * AI app connects a moment after the code was entered (its token request), and\n * a new code in plain view meanwhile looks as if it did not work. Only when\n * the relay says the code was used (`reason: \"used\"`); a relay that does not\n * say why gets the new code shown at once.\n */\nexport const CODE_USED_WAIT_MS = 10_000;\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy, how to add it,\n * the pairing code (with Copy) while the relay sends one, Disconnect all apps, and\n * the connected apps with Disconnect (and, for each, switches for the tools\n * that run without asking). Pairing is on while it is open, so closing it\n * ends the code; the connection and the address stay. Until an app is\n * connected, only a small Close (and Escape) close it. Once one is, a\n * confirmation leads, the setup moves behind \"Connect another AI app\" and\n * Done is the primary button. Disconnect all apps asks first when it would\n * disconnect connected apps. When the page loses its address (`replaced`),\n * this dialog closes and `replacedNotice` says why, from then on also while\n * it is closed.\n *\n * Its nodes are built once; one `render()` derives what is shown from `mcp`\n * and a few flags of its own after every change, so nothing flickers and\n * focus stays, or moves to the next step when its control was hidden.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n\tserverName = \"tools\",\n\tui?: DialogOptions,\n): Promise<void> {\n\tconst s = stringsOf(ui);\n\tconst allowed = allowedFor(mcp);\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", s, s.connectTitle);\n\t// Focusable from script only, for the moment before the address is shown.\n\tdialog.tabIndex = -1;\n\tconst status = el(doc, \"p\", { className: \"tab-mcp-status\" });\n\tstatus.setAttribute(\"role\", \"status\");\n\t// What a Copy did, for assistive technology only; out of sight, also\n\t// without the stylesheet. The same message twice is still a change.\n\tconst live = el(doc, \"span\", { className: \"tab-mcp-announce\" });\n\tlive.setAttribute(\"aria-live\", \"polite\");\n\tfor (const [property, value] of [\n\t\t[\"position\", \"absolute\"],\n\t\t[\"width\", \"1px\"],\n\t\t[\"height\", \"1px\"],\n\t\t[\"overflow\", \"hidden\"],\n\t\t[\"clip-path\", \"inset(50%)\"],\n\t\t[\"white-space\", \"nowrap\"],\n\t] as const)\n\t\tlive.style.setProperty(property, value);\n\tconst announce = (text: string) => {\n\t\tlive.textContent = live.textContent === text ? `${text} ` : text;\n\t};\n\n\t// AI apps that reach the page through the tab-mcp browser extension\n\t// (DEC-207): said first, as the user may not need to connect at all.\n\t// Everything else stays: a phone or another browser still connects here.\n\tconst viaExtension = el(doc, \"p\", { className: \"tab-mcp-via-extension\" });\n\n\t// The confirmation once an app is connected: what happened, what next.\n\tconst successId = `${nextId()}-success`;\n\tconst successTitle = el(doc, \"p\", { className: \"tab-mcp-success-title\" });\n\tconst successNext = el(doc, \"p\", { className: \"tab-mcp-success-next\" });\n\t// A check mark in a tinted disk, drawn by the stylesheet (CU 19).\n\tconst check = el(doc, \"span\", { className: \"tab-mcp-success-icon\" });\n\tcheck.setAttribute(\"aria-hidden\", \"true\");\n\tconst success = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-success\", id: successId },\n\t\tcheck,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-success-text\" },\n\t\t\tsuccessTitle,\n\t\t\tsuccessNext,\n\t\t),\n\t);\n\n\tconst addressId = `${nextId()}-address`;\n\tconst label = el(doc, \"label\", { text: s.addressLabel });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\t// Copying the address is the first step: the primary button, until an\n\t// app is connected (then Done is).\n\tconst { button: copy, reset: resetCopy } = copyButton(\n\t\tdoc,\n\t\ts,\n\t\ts.copyAddress,\n\t\t() => address.value,\n\t\t() => address.select(),\n\t\tannounce,\n\t\t\"tab-mcp-address-copy\",\n\t\t\"primary\",\n\t);\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t);\n\n\t// Not next to Copy, and saying what it does (CU 23): with no AI app\n\t// connected it makes a new secret at once (the address stays), which\n\t// also ends what a pasted address could reach.\n\tconst fresh = button(\n\t\tdoc,\n\t\ts.disconnectAll,\n\t\t() => askDisconnectAll(),\n\t\t\"tab-mcp-disconnect-all\",\n\t);\n\tconst freshBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-disconnect-all-row\" },\n\t\tel(doc, \"small\", { text: s.disconnectAllNote }),\n\t\t\" \",\n\t\tfresh,\n\t);\n\t// Asked in the dialog before Disconnect all apps disconnects connected apps.\n\tconst questionId = `${nextId()}-disconnect-all`;\n\tconst questionText = el(doc, \"p\", { id: questionId });\n\tconst cancelNew = button(doc, s.cancel, () => {\n\t\tasking = false;\n\t\trender();\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(\n\t\tdoc,\n\t\ts.disconnectAllConfirm,\n\t\t() => runDisconnectAll(),\n\t\t\"tab-mcp-disconnect-all-confirm\",\n\t\t\"danger\",\n\t);\n\tconst question = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-disconnect-all-question\" },\n\t\tquestionText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tquestion.setAttribute(\"role\", \"group\");\n\tquestion.setAttribute(\"aria-labelledby\", questionId);\n\n\t// Large, in a monospace font: a new code takes the same room.\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\t// One click selects the whole code; it stays plain, selectable text.\n\tcode.style.setProperty(\"user-select\", \"all\");\n\tcode.style.setProperty(\"-webkit-user-select\", \"all\");\n\t// Reads the code shown at click time, so a rotated code is copied as shown.\n\tconst { button: copyCode, reset: resetCopyCode } = copyButton(\n\t\tdoc,\n\t\ts,\n\t\ts.copyCode,\n\t\t() => code.textContent ?? \"\",\n\t\t() => doc.getSelection()?.selectAllChildren(code),\n\t\tannounce,\n\t\t\"tab-mcp-code-copy\",\n\t);\n\t// Only the sentence with the code is announced when the code changes,\n\t// not its Copy button's \"Copied\".\n\tconst codeSentence = el(\n\t\tdoc,\n\t\t\"span\",\n\t\t{},\n\t\t...fill(doc, s.codeSentence, { code }),\n\t);\n\tcodeSentence.setAttribute(\"aria-live\", \"polite\");\n\t// In the code's place while the AI app finishes connecting with it.\n\tconst codeUsed = el(doc, \"span\", { className: \"tab-mcp-code-used\" });\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\tcodeUsed,\n\t\t\" \",\n\t\tcopyCode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", { className: \"tab-mcp-code-note\", text: s.codeNote }),\n\t);\n\t// Identity binding: no code, the same account at the AI app's sign-in,\n\t// until the time the relay gave (DEC-202); then Continue.\n\tconst signInUntil = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-sign-in-until\",\n\t});\n\t/** The time of `iso` in hours and minutes, as the dialog's language writes it. */\n\tconst timeOf = (iso: string) => {\n\t\tconst time = new Date(iso);\n\t\ttry {\n\t\t\treturn time.toLocaleTimeString(s.lang, {\n\t\t\t\thour: \"numeric\",\n\t\t\t\tminute: \"2-digit\",\n\t\t\t});\n\t\t} catch {\n\t\t\treturn time.toLocaleTimeString(); // a `lang` the browser does not know\n\t\t}\n\t};\n\tconst signInLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-sign-in\" },\n\t\ts.signIn,\n\t\tel(doc, \"br\"),\n\t\tsignInUntil,\n\t);\n\tconst more = button(\n\t\tdoc,\n\t\ts.continuePairing,\n\t\t() => mcp.startPairing(),\n\t\t\"tab-mcp-continue\",\n\t\t\"primary\",\n\t);\n\tconst timeUpText = el(doc, \"span\", { text: s.signInTimeUp });\n\tconst timeUp = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-time-up\" },\n\t\ttimeUpText,\n\t\t\" \",\n\t\tmore,\n\t);\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: s.help }),\n\t\tsteps,\n\t);\n\tconst guideUrl =\n\t\tui?.setup?.guide === undefined ? SETUP_GUIDE : ui.setup.guide;\n\tif (guideUrl !== null) {\n\t\tconst guide = el(doc, \"a\", { text: s.guide });\n\t\tguide.href = guideUrl;\n\t\tguide.target = \"_blank\";\n\t\tguide.rel = \"noopener noreferrer\";\n\t\thelp.append(el(doc, \"p\", { className: \"tab-mcp-guide\" }, guide));\n\t}\n\tconst instructions =\n\t\tui?.setup?.instructions ??\n\t\t((name: string, address: string) => setupInstructions(name, address, s));\n\n\t// Everything for adding the page to an AI app. Once one is connected, it\n\t// is behind \"Connect another AI app\", closed: the next code is not news.\n\t// Where to paste the address comes right after it, the code after that\n\t// (CU 23); Disconnect all apps last. The help stays closed (DEC-147).\n\tconst setupId = `${nextId()}-setup`;\n\tconst setup = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-setup\", id: setupId },\n\t\taddressBox,\n\t\thelp,\n\t\tcodeLine,\n\t\tsignInLine,\n\t\ttimeUp,\n\t\tfreshBox,\n\t\tquestion,\n\t);\n\tconst setupToggle = button(\n\t\tdoc,\n\t\ts.connectAnother,\n\t\t() => {\n\t\t\texpanded = !expanded;\n\t\t\trender();\n\t\t},\n\t\t\"tab-mcp-setup-toggle\",\n\t);\n\tsetupToggle.setAttribute(\"aria-controls\", setupId);\n\n\tconst appList = el(doc, \"ul\");\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tappsNote.setAttribute(\"role\", \"status\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: s.connectedHeading }),\n\t\tappList,\n\t\tappsNote,\n\t);\n\n\t// Until an app is connected, closing it is not the next step: a small\n\t// Close at the end, saying what closing does (the code stops, the address\n\t// stays). Once one is, a prominent Done replaces both.\n\tconst closeNote = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-close-note\",\n\t\ttext: s.closeNote,\n\t});\n\tconst close = button(doc, s.close, () => dialog.close(), \"tab-mcp-close\");\n\tconst done = button(\n\t\tdoc,\n\t\ts.done,\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-done\",\n\t\t\"primary\",\n\t);\n\t// While not connected (it failed, the session ended, it reconnects): the\n\t// next step, from a click, so it has the user action it needs (CU 4).\n\t// While reconnecting, connect() makes the next attempt at once.\n\tconst retry = button(\n\t\tdoc,\n\t\ts.connectAgain,\n\t\t() => {\n\t\t\tmessage = undefined;\n\t\t\tmcp.connect().then(\n\t\t\t\t() => {\n\t\t\t\t\tif (doc.activeElement === close) start().focus();\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tmessage = connectFailure(error, s);\n\t\t\t\t\trender();\n\t\t\t\t\t// Focus went to Close while it connected: back to Connect\n\t\t\t\t\t// again, so a second Enter tries again instead of closing.\n\t\t\t\t\tif (doc.activeElement === close && !retry.hidden) retry.focus();\n\t\t\t\t},\n\t\t\t);\n\t\t\trender();\n\t\t},\n\t\t\"tab-mcp-retry\",\n\t\t\"primary\",\n\t);\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tcloseNote,\n\t\t\" \",\n\t\tclose,\n\t\tretry,\n\t\tdone,\n\t);\n\tdialog.append(\n\t\tviaExtension,\n\t\tsuccess,\n\t\tstatus,\n\t\tapps,\n\t\tsetupToggle,\n\t\tsetup,\n\t\tactions,\n\t\tlive,\n\t);\n\n\t// The dialog's own state; the rest is read from `mcp` in `render()`.\n\t/** The setup is open while an app is connected. */\n\tlet expanded = false;\n\t/** The Disconnect all apps question is open. */\n\tlet asking = false;\n\t/** Disconnect all apps waits for the new session. */\n\tlet renewing = false;\n\t/** Disconnect all apps got its session; until an app pairs or it disconnects. */\n\tlet renewed = false;\n\t/** Why it is not connected, in the user's words, while it is not. */\n\tlet message: string | undefined;\n\t/** Why the last Disconnect failed, while connected. */\n\tlet appsProblem: string | undefined;\n\t/** The grants of the last render: a new one is an app that just paired. */\n\tlet grantsSeen = new Set(mcp.grants.map((g) => g.grantId));\n\t/** The address the help's steps were made for. */\n\tlet stepsFor: string | undefined;\n\t/** The code shown, and the wait after it was used (until the app connects). */\n\tlet shownCode: PairingCode | undefined;\n\tlet usedTimer: ReturnType<typeof setTimeout> | undefined;\n\t/** Renders again when the time for a sign-in is up. */\n\tlet untilTimer: ReturnType<typeof setTimeout> | undefined;\n\t/** Shown in the connected state. */\n\tlet connectedView = false;\n\n\t// Where focus goes when its control was hidden: the next step (Done or\n\t// Connect again), else Close.\n\tconst closer = () => (connectedView ? done : retry.hidden ? close : retry);\n\t// Where focus starts: Done once connected, else the address's Copy.\n\tconst start = () => (connectedView ? done : copy);\n\n\t// One item per grant, kept while the grant is: a focused Disconnect keeps\n\t// its focus. Under it, the switches for what runs without asking.\n\tconst items = new Map<\n\t\tstring,\n\t\t{\n\t\t\titem: HTMLLIElement;\n\t\t\tdisconnect: HTMLButtonElement;\n\t\t\trenderAllowed: () => void;\n\t\t}\n\t>();\n\tconst appItem = (grant: Grant) => {\n\t\tconst app = clientLabel(grant.client, s);\n\t\tconst disconnect = button(\n\t\t\tdoc,\n\t\t\ts.disconnect,\n\t\t\t() => {\n\t\t\t\tappsProblem = undefined;\n\t\t\t\tmcp.revoke(grant.grantId).catch((error: unknown) => {\n\t\t\t\t\t// Not connected any more: the note says so already.\n\t\t\t\t\tif (mcp.state === \"connected\")\n\t\t\t\t\t\tappsProblem =\n\t\t\t\t\t\t\t(error as { code?: unknown } | null)?.code === \"store_unavailable\"\n\t\t\t\t\t\t\t\t? s.storeUnavailable\n\t\t\t\t\t\t\t\t: s.disconnectFailed;\n\t\t\t\t\trender();\n\t\t\t\t});\n\t\t\t\trender();\n\t\t\t},\n\t\t\t\"tab-mcp-disconnect\",\n\t\t\t\"danger\",\n\t\t);\n\t\t// One name per button: each list item has its own Disconnect.\n\t\tdisconnect.setAttribute(\"aria-label\", format(s.disconnectApp, { app }));\n\t\tconst switches = allowedSwitches(doc, s, allowed, grant.grantId, app);\n\t\tconst item = el(\n\t\t\tdoc,\n\t\t\t\"li\",\n\t\t\t{},\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"span\",\n\t\t\t\t{ className: \"tab-mcp-app\" },\n\t\t\t\tformat(s.appConnected, { app }),\n\t\t\t),\n\t\t\t\" \",\n\t\t\tdisconnect,\n\t\t\tswitches.box,\n\t\t);\n\t\treturn { item, disconnect, renderAllowed: switches.render };\n\t};\n\n\t/** The steps for `address` in the help, made again when it changes. */\n\tconst renderSteps = (session: SessionInfo) => {\n\t\tif (stepsFor === session.address) return;\n\t\tstepsFor = session.address;\n\t\tsteps.replaceChildren(\n\t\t\t...instructions(serverName, session.address).map(\n\t\t\t\t({ app, text: how, command, note }) => {\n\t\t\t\t\tconst item = el(\n\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\"li\",\n\t\t\t\t\t\t{},\n\t\t\t\t\t\tel(doc, \"strong\", { text: `${app}:` }),\n\t\t\t\t\t\t` ${how}`,\n\t\t\t\t\t);\n\t\t\t\t\tif (command !== undefined) {\n\t\t\t\t\t\t// A block with its own Copy, like the code.\n\t\t\t\t\t\tconst text = el(doc, \"pre\", { text: command });\n\t\t\t\t\t\ttext.dir = \"ltr\";\n\t\t\t\t\t\tconst { button: copyCommand } = copyButton(\n\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\ts,\n\t\t\t\t\t\t\tformat(s.copyCommand, { app }),\n\t\t\t\t\t\t\t() => text.textContent ?? \"\",\n\t\t\t\t\t\t\t() => doc.getSelection()?.selectAllChildren(text),\n\t\t\t\t\t\t\tannounce,\n\t\t\t\t\t\t\t\"tab-mcp-command-copy\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"div\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command\" },\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tcopyCommand,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (note !== undefined)\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"small\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command-note\" },\n\t\t\t\t\t\t\t\t...note.map((part) =>\n\t\t\t\t\t\t\t\t\t\"code\" in part\n\t\t\t\t\t\t\t\t\t\t? el(doc, \"code\", { text: part.code })\n\t\t\t\t\t\t\t\t\t\t: part.text,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\treturn item;\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t};\n\n\t/** The pairing code, or \"Code used\" in its place while the AI app connects. */\n\tconst renderCode = (paired: boolean) => {\n\t\tconst current = mcp.pairingCode;\n\t\tif (current === undefined || paired) {\n\t\t\t// None any more, or the app connected: the next code shows.\n\t\t\tclearTimeout(usedTimer);\n\t\t\tusedTimer = undefined;\n\t\t} else if (current.code !== shownCode?.code) {\n\t\t\tif (current.reason === \"used\") {\n\t\t\t\t// Entered just now: no new code in plain view while the AI app\n\t\t\t\t// connects; it shows if none does.\n\t\t\t\tif (usedTimer === undefined) {\n\t\t\t\t\tusedTimer = setTimeout(() => {\n\t\t\t\t\t\t// No app came: the code shows (unless another came meanwhile).\n\t\t\t\t\t\tusedTimer = undefined;\n\t\t\t\t\t\tshownCode = mcp.pairingCode;\n\t\t\t\t\t\trender();\n\t\t\t\t\t}, CODE_USED_WAIT_MS);\n\t\t\t\t\tannounce(s.codeUsed);\n\t\t\t\t}\n\t\t\t} else if (usedTimer !== undefined) {\n\t\t\t\t// Expired meanwhile: the user needs this one now.\n\t\t\t\tclearTimeout(usedTimer);\n\t\t\t\tusedTimer = undefined;\n\t\t\t}\n\t\t}\n\t\tconst used = usedTimer !== undefined;\n\t\tif (!used) {\n\t\t\t// A new code is not copied yet.\n\t\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\t\tcode.textContent = current?.code ?? \"\";\n\t\t\tshownCode = current;\n\t\t}\n\t\tcodeSentence.hidden = used;\n\t\tcopyCode.hidden = used;\n\t\tcodeUsed.hidden = !used;\n\t\tcodeUsed.textContent = used ? s.codeUsed : \"\";\n\t\treturn current !== undefined;\n\t};\n\n\t/** Shows what `mcp` and the flags say; keeps the focus on a shown control. */\n\tconst render = () => {\n\t\tconst focused = doc.activeElement;\n\t\tconst { state, session, grants } = mcp;\n\t\tconst connected = state === \"connected\";\n\t\tconst oidc = session?.pairing === \"oidc\";\n\t\t// With identity binding, the address is of no use until the relay\n\t\t// knows who is signed in to the page: the status says what is missing.\n\t\tconst signIn = oidc ? signInText(mcp, s) : undefined;\n\t\tconst shown = session !== undefined && signIn === undefined;\n\t\t// A sign-in pairs the page only until the relay's time (DEC-202): then\n\t\t// the dialog says so and offers Continue. Without one (a relay up to\n\t\t// 0.12.1, or no answer yet) it shows what it showed before.\n\t\tconst until = oidc ? mcp.pairingUntil : undefined;\n\t\tconst left = until === undefined ? 1 : Date.parse(until) - Date.now();\n\t\tconst over = connected && shown && left <= 0;\n\t\tclearTimeout(untilTimer);\n\t\t// At most a minute ahead, so that a throttled timer is not the only\n\t\t// chance to see the end.\n\t\tuntilTimer =\n\t\t\tleft > 0 && until !== undefined\n\t\t\t\t? setTimeout(render, Math.min(left, 60_000))\n\t\t\t\t: undefined;\n\n\t\t// An app that paired just now: the setup closes again (unless the\n\t\t// Disconnect all apps question is open in it), and the confirmation is\n\t\t// announced.\n\t\tconst ids = new Set(grants.map((g) => g.grantId));\n\t\tconst paired = connected && grants.some((g) => !grantsSeen.has(g.grantId));\n\t\tgrantsSeen = ids;\n\t\tif (paired) {\n\t\t\trenewed = false;\n\t\t\tif (!asking) expanded = false;\n\t\t}\n\t\t// Nobody left to disconnect: no question needed.\n\t\tconst names = appLabels(grants, s);\n\t\tif (names.length === 0 || !shown) asking = false;\n\n\t\tconnectedView = !renewing && connected && grants.length > 0;\n\t\tshowNames(doc, successTitle, s.connected, names, s);\n\t\tsuccessNext.textContent = plural(s.connectedNext, names.length, s);\n\t\tif (connectedView) dialog.setAttribute(\"aria-describedby\", successId);\n\t\telse dialog.removeAttribute(\"aria-describedby\");\n\t\tsuccess.hidden = !connectedView;\n\n\t\t// Each app once, named as the connected apps are.\n\t\tconst extension = mcp.extension;\n\t\tconst via = [\n\t\t\t...new Set(\n\t\t\t\t(extension?.apps ?? []).map((a) =>\n\t\t\t\t\tclientLabel({ id: a.host, name: a.name, host: a.host }, s),\n\t\t\t\t),\n\t\t\t),\n\t\t];\n\t\tviaExtension.hidden = via.length === 0;\n\t\tshowNames(\n\t\t\tdoc,\n\t\t\tviaExtension,\n\t\t\textension?.whileInFront ? s.viaExtensionInFront : s.viaExtension,\n\t\t\tvia,\n\t\t\ts,\n\t\t);\n\n\t\t// The status line is for the setup; the confirmation says it otherwise.\n\t\tif (connected) message = undefined;\n\t\tconst appName = session?.appName;\n\t\tstatus.textContent = renewing\n\t\t\t? s.disconnectingAll\n\t\t\t: state === \"connecting\"\n\t\t\t\t? s.connecting\n\t\t\t\t: state === \"reconnecting\"\n\t\t\t\t\t? s.reconnecting\n\t\t\t\t\t: !connected\n\t\t\t\t\t\t? (message ?? s.notConnected)\n\t\t\t\t\t\t: (signIn ??\n\t\t\t\t\t\t\t(over\n\t\t\t\t\t\t\t\t? s.signInTimeUp\n\t\t\t\t\t\t\t\t: renewed\n\t\t\t\t\t\t\t\t\t? s.disconnectAllDone\n\t\t\t\t\t\t\t\t\t: appName !== undefined\n\t\t\t\t\t\t\t\t\t\t? format(s.readyApp, { app: appName })\n\t\t\t\t\t\t\t\t\t\t: s.readyPage));\n\t\tstatus.hidden = connectedView;\n\n\t\t// The address, its help and Disconnect all apps.\n\t\tconst addressShownBefore = !addressBox.hidden;\n\t\tif (shown && address.value !== session.address) {\n\t\t\taddress.value = session.address;\n\t\t\tresetCopy();\n\t\t}\n\t\tif (shown) renderSteps(session);\n\t\taddressBox.hidden = help.hidden = freshBox.hidden = !shown;\n\t\tfresh.disabled = !connected;\n\t\tquestion.hidden = !asking;\n\t\tif (asking) showNames(doc, questionText, s.disconnectAllQuestion, names, s);\n\t\tconst hasCode = renderCode(paired);\n\t\tcodeLine.hidden = oidc || !hasCode || !connected;\n\t\tsignInLine.hidden = !oidc || mcp.identity !== \"bound\" || over;\n\t\tsignInUntil.textContent =\n\t\t\tuntil === undefined ? \"\" : format(s.signInUntil, { time: timeOf(until) });\n\t\tsignInUntil.hidden = until === undefined;\n\t\ttimeUp.hidden = !over;\n\t\t// With an app connected the status is hidden: the reason goes here.\n\t\ttimeUpText.hidden = !connectedView;\n\n\t\tsetupToggle.hidden = !connectedView;\n\t\tsetupToggle.setAttribute(\"aria-expanded\", String(expanded));\n\t\tsetup.hidden = connectedView && !expanded;\n\t\tcopy.classList.toggle(\"tab-mcp-primary\", !connectedView);\n\n\t\t// The connected apps; only the relay can revoke, so only while connected.\n\t\tfor (const [id, { item }] of items) {\n\t\t\tif (ids.has(id)) continue;\n\t\t\titem.remove();\n\t\t\titems.delete(id);\n\t\t}\n\t\tgrants.forEach((grant, i) => {\n\t\t\tlet entry = items.get(grant.grantId);\n\t\t\tif (entry === undefined) {\n\t\t\t\tentry = appItem(grant);\n\t\t\t\titems.set(grant.grantId, entry);\n\t\t\t}\n\t\t\tentry.disconnect.disabled = !connected;\n\t\t\tentry.renderAllowed();\n\t\t\tif (appList.children[i] !== entry.item)\n\t\t\t\tappList.insertBefore(entry.item, appList.children[i] ?? null);\n\t\t});\n\t\tappsNote.textContent = connected ? (appsProblem ?? \"\") : s.disconnectNote;\n\t\tappsNote.hidden = connected && appsProblem === undefined;\n\t\tapps.hidden = grants.length === 0;\n\n\t\t// The note is about the code: only while one is shown and none connected.\n\t\tcloseNote.hidden = connectedView || codeLine.hidden;\n\t\tclose.hidden = connectedView;\n\t\tdone.hidden = !connectedView;\n\t\tretry.hidden =\n\t\t\trenewing || (state !== \"disconnected\" && state !== \"reconnecting\");\n\n\t\t// Focus never stays on a control that was hidden or removed; from the\n\t\t// Disconnect all apps question that closed, back to its button; from\n\t\t// Continue, once the relay took it, to the start.\n\t\tif (\n\t\t\tfocused !== null &&\n\t\t\tfocused !== dialog &&\n\t\t\tfocused !== doc.body &&\n\t\t\t(!focused.isConnected ||\n\t\t\t\t(dialog.contains(focused) && focused.closest(\"[hidden]\") !== null))\n\t\t)\n\t\t\t(question.contains(focused) && !freshBox.hidden\n\t\t\t\t? fresh\n\t\t\t\t: focused === more && !setup.hidden\n\t\t\t\t\t? start()\n\t\t\t\t\t: closer()\n\t\t\t).focus();\n\t\t// The address showed only now: start there (or at Done), or, after a\n\t\t// Disconnect all apps, at its Copy.\n\t\telse if (doc.activeElement === dialog && (connectedView || shown))\n\t\t\tstart().focus();\n\t\telse if (\n\t\t\trenewed &&\n\t\t\tshown &&\n\t\t\t!addressShownBefore &&\n\t\t\tdoc.activeElement === close\n\t\t)\n\t\t\tcopy.focus();\n\t\tif (paired && connectedView)\n\t\t\tannounce(`${successTitle.textContent}. ${successNext.textContent}`);\n\t};\n\n\tconst askDisconnectAll = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (mcp.grants.length === 0) {\n\t\t\trunDisconnectAll();\n\t\t\treturn;\n\t\t}\n\t\tasking = true;\n\t\trender();\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst runDisconnectAll = () => {\n\t\trenewing = true;\n\t\trenewed = false;\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tasking = false;\n\t\trender();\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.disconnectAll().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\trenewed = true;\n\t\t\t\trender();\n\t\t\t\t// At its Copy once the address shows again (with identity binding\n\t\t\t\t// maybe only later: `render()` moves it then).\n\t\t\t\tif (!addressBox.hidden) copy.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tmessage = connectFailure(error, s);\n\t\t\t\trender();\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\n\t// A refusal that stops reconnecting comes as `error` (with its `reason`)\n\t// just before the `statechange` to `disconnected`: that says why it stopped.\n\tlet stoppedBy: unknown;\n\tlet wasReconnecting = mcp.state === \"reconnecting\";\n\tconst onError = (event: CustomEvent<{ error: Error }>) => {\n\t\tconst { error } = event.detail;\n\t\tif (wasReconnecting && (error as { reason?: unknown }).reason !== undefined)\n\t\t\tstoppedBy = error;\n\t};\n\tconst onState = (event: CustomEvent<StateChangeDetail>) => {\n\t\tconst { state, reason } = event.detail;\n\t\tif (reason !== undefined && reason !== \"disconnect_all\") {\n\t\t\tmessage = disconnectedText(reason, s);\n\t\t\trenewed = false;\n\t\t}\n\t\t// Refused, or ended by the page (`disconnect()`) while it waited.\n\t\tif (state === \"disconnected\" && wasReconnecting)\n\t\t\tmessage =\n\t\t\t\tstoppedBy === undefined ? s.disconnected : connectFailure(stoppedBy, s);\n\t\twasReconnecting = state === \"reconnecting\";\n\t\tstoppedBy = undefined;\n\t\trender();\n\t};\n\n\t// The address was taken over: the notice says so instead of this dialog.\n\tconst onReplaced = () => dialog.close();\n\twatchReplaced(mcp, doc, ui);\n\tconst stopAllowed = allowed.onChange(render);\n\tmcp.addEventListener(\"statechange\", onState);\n\tmcp.addEventListener(\"pairingcode\", render);\n\tmcp.addEventListener(\"pairinguntil\", render);\n\t// A tab in the background may not have run the timer: look again.\n\tdoc.addEventListener(\"visibilitychange\", render);\n\tmcp.addEventListener(\"grantschange\", render);\n\tmcp.addEventListener(\"identitychange\", render);\n\tmcp.addEventListener(\"extensionchange\", render);\n\tmcp.addEventListener(\"error\", onError);\n\tmcp.addEventListener(\"replaced\", onReplaced);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trender();\n\tconnecting.then(render, (error: unknown) => {\n\t\tmessage = connectFailure(error, s);\n\t\trender();\n\t});\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(usedTimer);\n\t\t\t\tclearTimeout(untilTimer);\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tstopAllowed();\n\t\t\t\tmcp.removeEventListener(\"statechange\", onState);\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", render);\n\t\t\t\tmcp.removeEventListener(\"pairinguntil\", render);\n\t\t\t\tdoc.removeEventListener(\"visibilitychange\", render);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", render);\n\t\t\t\tmcp.removeEventListener(\"identitychange\", render);\n\t\t\t\tmcp.removeEventListener(\"extensionchange\", render);\n\t\t\t\tmcp.removeEventListener(\"error\", onError);\n\t\t\t\tmcp.removeEventListener(\"replaced\", onReplaced);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\t// Start at Done once connected, else at the address's Copy; until the\n\t\t// address is there, at the dialog itself (its title is read out), not\n\t\t// at Close.\n\t\tif (connectedView || !addressBox.hidden) start().focus();\n\t\telse dialog.focus();\n\t});\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAS,QAAQ,CAChB,KACA,MACA,UACuD;AAAA,EACvD,MAAM,QAAQ,GAAG,KAAK,OAAO;AAAA,EAC7B,MAAM,OAAO;AAAA,EACb,MAAM,aAAa,QAAQ,QAAQ;AAAA,EACnC,MAAM,iBAAiB,UAAU,MAAM,SAAS,MAAM,OAAO,CAAC;AAAA,EAC9D,MAAM,QAAQ,GAAG,KAAK,SAAS,EAAE,WAAW,iBAAiB,GAAG,OAAO,IAAI;AAAA,EAC3E,OAAO,EAAE,OAAO,MAAM;AAAA;AAiBvB,SAAS,eAAe,CACvB,KACA,GACA,SACA,SACA,KAC2C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AAAA,EAC9C,IAAI,iBAAiB,SAAS,OAAO;AAAA,EACrC,IAAI,iBAAiB,YAAY,UAAU;AAAA,EAC3C,IAAI,KAAK,OAAO,MAAM;AAAA,EACtB,IAAI,aAAa;AAAA,EACjB,OAAO;AAAA,EACP,WAAW,KAAK,QAAQ,CAAC,UAAmB;AAAA,IAC3C,UAAU,eAAe,OAAO,CAAC;AAAA,IACjC,OAAO;AAAA,GACP;AAAA,EAED,OAAO,IAAI,QAAQ,CAAC,YAAY;AAAA,IAC/B,OAAO,iBACN,SACA,MAAM;AAAA,MACL,aAAa,SAAS;AAAA,MACtB,aAAa,UAAU;AAAA,MACvB,IAAI,YAAY;AAAA,MAChB,YAAY;AAAA,MACZ,IAAI,oBAAoB,eAAe,OAAO;AAAA,MAC9C,IAAI,oBAAoB,eAAe,MAAM;AAAA,MAC7C,IAAI,oBAAoB,gBAAgB,MAAM;AAAA,MAC9C,IAAI,oBAAoB,oBAAoB,MAAM;AAAA,MAClD,IAAI,oBAAoB,gBAAgB,MAAM;AAAA,MAC9C,IAAI,oBAAoB,kBAAkB,MAAM;AAAA,MAChD,IAAI,oBAAoB,mBAAmB,MAAM;AAAA,MACjD,IAAI,oBAAoB,SAAS,OAAO;AAAA,MACxC,IAAI,oBAAoB,YAAY,UAAU;AAAA,MAC9C,OAAO,OAAO;AAAA,MACd,QAAQ;AAAA,OAET,EAAE,MAAM,KAAK,CACd;AAAA,IACA,OAAO,UAAU;AAAA,IAIjB,IAAI,iBAAiB,CAAC,WAAW;AAAA,MAAQ,MAAM,EAAE,MAAM;AAAA,IACvD;AAAA,MAAK,OAAO,MAAM;AAAA,GAClB;AAAA;",
8
+ "debugId": "9A4352A5FEBFD1FE64756E2164756E21",
9
+ "names": []
10
+ }
package/connect.d.ts CHANGED
@@ -7,9 +7,10 @@ import type { DialogOptions, SessionInfo } from "./types.js";
7
7
  /**
8
8
  * Says that the page lost its address (`replaced`, DEC-095). A sibling tab
9
9
  * that announced it: "Opened in another tab", nothing to do. Otherwise a
10
- * warning that another tab or program took over, with "New address", which
11
- * takes the address back, disconnects its apps, connects with a new one and
12
- * opens the connect dialog to add it to the AI apps again.
10
+ * warning that another tab or program took over, with "Disconnect all apps"
11
+ * (`disconnectAll()`), which takes the page back, disconnects its apps,
12
+ * connects with a new secret and opens the connect dialog to connect the AI
13
+ * apps again.
13
14
  */
14
15
  export declare function replacedNotice(mcp: TabMcp, doc: Document, sibling: boolean, ui?: DialogOptions): void;
15
16
  /**
@@ -22,13 +23,13 @@ export declare function replacedNotice(mcp: TabMcp, doc: Document, sibling: bool
22
23
  export declare const CODE_USED_WAIT_MS = 10000;
23
24
  /**
24
25
  * The "Connect your AI app" dialog: the address with Copy, how to add it,
25
- * the pairing code (with Copy) while the relay sends one, New address, and
26
+ * the pairing code (with Copy) while the relay sends one, Disconnect all apps, and
26
27
  * the connected apps with Disconnect (and, for each, switches for the tools
27
28
  * that run without asking). Pairing is on while it is open, so closing it
28
29
  * ends the code; the connection and the address stay. Until an app is
29
30
  * connected, only a small Close (and Escape) close it. Once one is, a
30
- * confirmation leads, the setup moves behind "Connect another app" and
31
- * Done is the primary button. New address asks first when it would
31
+ * confirmation leads, the setup moves behind "Connect another AI app" and
32
+ * Done is the primary button. Disconnect all apps asks first when it would
32
33
  * disconnect connected apps. When the page loses its address (`replaced`),
33
34
  * this dialog closes and `replacedNotice` says why, from then on also while
34
35
  * it is closed.
@@ -396,8 +396,8 @@ async function decideAndRun(context, tool, raw, signal, client) {
396
396
  }
397
397
  if (answer !== true) {
398
398
  if (signal.aborted)
399
- return stopped("cancelled", "The user declined", "cancelled");
400
- return answer === "unanswered" ? stopped("unanswered", UNANSWERED, "unanswered") : stopped("declined", "The user declined", "declined");
399
+ return stopped("cancelled", "The call was cancelled.", "cancelled");
400
+ return answer === "unanswered" ? stopped("unanswered", UNANSWERED, "unanswered") : stopped("declined", "The user did not allow this call.", "declined");
401
401
  }
402
402
  }
403
403
  if (signal.aborted)
@@ -424,14 +424,14 @@ async function decideAndRun(context, tool, raw, signal, client) {
424
424
  run.outcome = "error";
425
425
  return run;
426
426
  }
427
- async function webMcpCall(context, tool, input, signal) {
427
+ async function webMcpCall(context, tool, input, signal, client) {
428
428
  const failed = (error) => ({ error });
429
429
  const gone = `The tool ${tool.name} is no longer available.`;
430
430
  if (context.tools.get(tool.name) !== tool)
431
431
  return failed(gone);
432
432
  if (!isObject2(input))
433
433
  return failed("The input must be an object.");
434
- const run = await runCall(context, tool, input, signal instanceof AbortSignal ? signal : new AbortController().signal, { kind: "webmcp" });
434
+ const run = await runCall(context, tool, input, signal instanceof AbortSignal ? signal : new AbortController().signal, client);
435
435
  if (run.stop === "cancelled")
436
436
  throw new DOMException("Cancelled", "AbortError");
437
437
  if (run.stop === "declined")
@@ -744,6 +744,7 @@ function createMcpHandler(options) {
744
744
  // src/protocol.ts
745
745
  var SUBPROTOCOL = "tab-mcp.v1";
746
746
  var CODE_REASONS = new Set(["start", "used", "expired"]);
747
+ var MAX_DELAY_MS = 2147483647;
747
748
  function isObject3(v) {
748
749
  return typeof v === "object" && v !== null && !Array.isArray(v);
749
750
  }
@@ -803,6 +804,15 @@ function parseRelayMessage(text) {
803
804
  message.reason = reason;
804
805
  return message;
805
806
  }
807
+ case "pairing.open": {
808
+ const ms = v["expiresInMs"];
809
+ if (typeof ms === "number" && Number.isFinite(ms) && ms >= 0 && ms <= MAX_DELAY_MS)
810
+ return {
811
+ type: "pairing.open",
812
+ expiresAt: new Date(Date.now() + ms).toISOString()
813
+ };
814
+ return str(v["expiresAt"]) && !Number.isNaN(Date.parse(v["expiresAt"])) ? { type: "pairing.open", expiresAt: v["expiresAt"] } : undefined;
815
+ }
806
816
  case "grant.added":
807
817
  return isGrant(v["grant"]) ? v : undefined;
808
818
  case "grant.removed":
@@ -1205,8 +1215,14 @@ async function addressIdOf(secret, subtle = globalThis.crypto?.subtle ?? null) {
1205
1215
  }
1206
1216
 
1207
1217
  // src/connection.ts
1208
- function callFromWebMcp(host, tool, input, signal) {
1209
- return webMcpCall(callContext(host, "webmcp"), tool, input, signal);
1218
+ function callFromWebMcp(host, tool, input, signal, by) {
1219
+ const context = callContext(host, "webmcp");
1220
+ return by === undefined ? webMcpCall(context, tool, input, signal, { kind: "webmcp" }) : webMcpCall({ ...context, confirm: () => Promise.resolve(true) }, tool, input, signal, {
1221
+ kind: "webmcp",
1222
+ via: "tab-mcp-extension",
1223
+ name: by.name,
1224
+ host: by.host
1225
+ });
1210
1226
  }
1211
1227
  var CONNECT_TIMEOUT_MS = 15000;
1212
1228
  var CLOSE_REASONS = {
@@ -1287,6 +1303,47 @@ function siblingTabs(name, address) {
1287
1303
  }
1288
1304
  };
1289
1305
  }
1306
+ function answer(target, message, done, connected, timeoutMs) {
1307
+ return new Promise((resolve, reject) => {
1308
+ const types = ["grantschange", "statechange", "error"];
1309
+ const settle = (error) => {
1310
+ clearTimeout(timer);
1311
+ for (const type of types)
1312
+ target.removeEventListener(type, check);
1313
+ if (error)
1314
+ reject(error);
1315
+ else
1316
+ resolve();
1317
+ };
1318
+ const check = (event) => {
1319
+ const error = event?.detail?.error;
1320
+ if (done())
1321
+ settle();
1322
+ else if ((error?.code === "store_unavailable" || error?.code === "unknown_id") && (error.for === undefined || error.for === message.type && error.grantId === message.grantId))
1323
+ settle(error);
1324
+ else if (!connected())
1325
+ settle(new DOMException("TabMcp: the session ended before the relay answered", "NetworkError"));
1326
+ };
1327
+ const timer = setTimeout(() => settle(new DOMException("TabMcp: the relay did not answer", "TimeoutError")), timeoutMs);
1328
+ for (const type of types)
1329
+ target.addEventListener(type, check);
1330
+ check();
1331
+ });
1332
+ }
1333
+ function onWake(now) {
1334
+ const g = globalThis;
1335
+ const doc = globalThis.document;
1336
+ const visible = () => {
1337
+ if (doc?.visibilityState !== "hidden")
1338
+ now();
1339
+ };
1340
+ doc?.addEventListener("visibilitychange", visible);
1341
+ g.addEventListener?.("online", now);
1342
+ return () => {
1343
+ doc?.removeEventListener("visibilitychange", visible);
1344
+ g.removeEventListener?.("online", now);
1345
+ };
1346
+ }
1290
1347
  function openConnection(host, url, secret, options = {}) {
1291
1348
  const revokeAll = options.revokeAll === true;
1292
1349
  const ws = new WebSocket(url, SUBPROTOCOL);
@@ -1422,6 +1479,9 @@ function openConnection(host, url, secret, options = {}) {
1422
1479
  reason: message.reason
1423
1480
  });
1424
1481
  return;
1482
+ case "pairing.open":
1483
+ host.pairingOpen(message.expiresAt);
1484
+ return;
1425
1485
  case "grant.added":
1426
1486
  host.grantAdded(message.grant);
1427
1487
  return;
@@ -1505,13 +1565,15 @@ export {
1505
1565
  SIBLING_GRACE_MS,
1506
1566
  SIBLING_WINDOW_MS,
1507
1567
  addressIdOf,
1568
+ answer,
1508
1569
  callFromWebMcp,
1509
1570
  chunkSize,
1510
1571
  compileRegistry,
1572
+ onWake,
1511
1573
  openConnection,
1512
1574
  pieces,
1513
1575
  servePort
1514
1576
  };
1515
1577
 
1516
- //# debugId=159BA8A8F36DAAB264756E2164756E21
1517
- //# sourceMappingURL=connection-gang7f5x.js.map
1578
+ //# debugId=C98B282553A8BE7164756E2164756E21
1579
+ //# sourceMappingURL=connection-73fbg99k.js.map