@ractive-ch/tab-mcp-client 0.16.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +898 -0
  2. package/README.md +216 -90
  3. package/address.d.ts +8 -8
  4. package/allowed.d.ts +28 -0
  5. package/allowed.js +14 -0
  6. package/allowed.js.map +10 -0
  7. package/always-allowed.d.ts +140 -22
  8. package/cdn/allowed.min.js +4 -0
  9. package/cdn/allowed.min.js.map +10 -0
  10. package/cdn/confirm-f36n8xj5.min.js +4 -0
  11. package/cdn/confirm-f36n8xj5.min.js.map +10 -0
  12. package/cdn/connect-ph4xxen4.min.js +6 -0
  13. package/cdn/connect-ph4xxen4.min.js.map +12 -0
  14. package/cdn/{connection-w97tf22a.min.js → connection-0xqwz17v.min.js} +7 -7
  15. package/cdn/{connection-w97tf22a.min.js.map → connection-0xqwz17v.min.js.map} +5 -5
  16. package/cdn/{index-vt5zk9me.min.js → tab-mcp-client-2vx9mcww.min.js} +20 -9
  17. package/cdn/tab-mcp-client-2vx9mcww.min.js.map +12 -0
  18. package/cdn/tab-mcp-client-6gcmd7n8.min.js +5 -0
  19. package/cdn/tab-mcp-client-6gcmd7n8.min.js.map +10 -0
  20. package/cdn/tab-mcp-client.min.js +3 -3
  21. package/cdn/tab-mcp-client.min.js.map +4 -4
  22. package/{confirm-fgnjgd08.js → confirm-jbyqzy14.js} +29 -19
  23. package/confirm-jbyqzy14.js.map +10 -0
  24. package/confirm.d.ts +27 -20
  25. package/{connect-8jpb0k29.js → connect-13hkdpcx.js} +113 -16
  26. package/connect-13hkdpcx.js.map +10 -0
  27. package/connect.d.ts +2 -2
  28. package/{connection-g91xjjgm.js → connection-gang7f5x.js} +10 -23
  29. package/{connection-g91xjjgm.js.map → connection-gang7f5x.js.map} +5 -5
  30. package/connection.d.ts +2 -2
  31. package/dialog.d.ts +1 -1
  32. package/{index-jnz7w9xa.js → index-c1c266tm.js} +36 -98
  33. package/index-c1c266tm.js.map +11 -0
  34. package/index-dmh5vm5m.js.map +1 -1
  35. package/index-h8b3dc5p.js +245 -0
  36. package/index-h8b3dc5p.js.map +10 -0
  37. package/index.js +33 -22
  38. package/index.js.map +4 -4
  39. package/internal.d.ts +2 -0
  40. package/package.json +7 -2
  41. package/protocol.d.ts +6 -7
  42. package/react.d.ts +19 -0
  43. package/react.js +30 -1
  44. package/react.js.map +3 -3
  45. package/secret.d.ts +6 -0
  46. package/strings.d.ts +13 -4
  47. package/tab-mcp.d.ts +15 -5
  48. package/types.d.ts +32 -9
  49. package/visible.d.ts +1 -1
  50. package/cdn/confirm-y30cx7e1.min.js +0 -4
  51. package/cdn/confirm-y30cx7e1.min.js.map +0 -10
  52. package/cdn/connect-bbhj2y7w.min.js +0 -6
  53. package/cdn/connect-bbhj2y7w.min.js.map +0 -12
  54. package/cdn/index-vt5zk9me.min.js.map +0 -13
  55. package/confirm-fgnjgd08.js.map +0 -10
  56. package/connect-8jpb0k29.js.map +0 -10
  57. package/index-jnz7w9xa.js.map +0 -12
@@ -2,85 +2,6 @@ import {
2
2
  escapeInvisible2
3
3
  } from "./index-dmh5vm5m.js";
4
4
 
5
- // src/always-allowed.ts
6
- var seen = (tool) => JSON.stringify([tool.title, tool.description]);
7
-
8
- class AlwaysAllowed {
9
- #tools = new Map;
10
- #listeners = new Set;
11
- has(grantId, tool) {
12
- const tools = this.#tools.get(grantId);
13
- const allowed = tools?.get(tool.name)?.seen;
14
- if (allowed === undefined || allowed === seen(tool)) {
15
- return allowed !== undefined;
16
- }
17
- tools?.delete(tool.name);
18
- this.#changed();
19
- return false;
20
- }
21
- add(grantId, tool) {
22
- const tools = this.#tools.get(grantId) ?? new Map;
23
- tools.set(tool.name, { seen: seen(tool), label: tool.title ?? tool.name });
24
- this.#tools.set(grantId, tools);
25
- this.#changed();
26
- }
27
- list(grantId) {
28
- return [...this.#tools.get(grantId)?.values() ?? []].map((t) => t.label);
29
- }
30
- forget(grantId) {
31
- if (this.#tools.delete(grantId))
32
- this.#changed();
33
- }
34
- keepGrants(grantIds) {
35
- const keep = new Set(grantIds);
36
- for (const grantId of this.#tools.keys())
37
- if (!keep.has(grantId))
38
- this.forget(grantId);
39
- }
40
- keepTools(names) {
41
- const keep = new Set(names);
42
- let changed = false;
43
- for (const tools of this.#tools.values()) {
44
- for (const tool of tools.keys()) {
45
- if (keep.has(tool))
46
- continue;
47
- tools.delete(tool);
48
- changed = true;
49
- }
50
- }
51
- if (changed)
52
- this.#changed();
53
- }
54
- onChange(listener) {
55
- this.#listeners.add(listener);
56
- return () => this.#listeners.delete(listener);
57
- }
58
- #changed() {
59
- for (const listener of [...this.#listeners])
60
- listener();
61
- }
62
- }
63
- var allowed = new WeakMap;
64
- function allowedFor(mcp) {
65
- const kept = allowed.get(mcp);
66
- if (kept !== undefined)
67
- return kept;
68
- const made = new AlwaysAllowed;
69
- mcp.addEventListener("grantschange", (e) => made.keepGrants(e.detail.grants.map((g) => g.grantId)));
70
- let tools;
71
- mcp.addEventListener("toolschange", (e) => {
72
- if (tools === undefined)
73
- queueMicrotask(() => {
74
- if (tools !== undefined)
75
- made.keepTools(tools);
76
- tools = undefined;
77
- });
78
- tools = e.detail.tools;
79
- });
80
- allowed.set(mcp, made);
81
- return made;
82
- }
83
-
84
5
  // src/strings.ts
85
6
  var STRINGS = {
86
7
  lang: "en",
@@ -90,6 +11,8 @@ var STRINGS = {
90
11
  confirmWho: "{client} wants to run {tool}.",
91
12
  deny: "Don't allow",
92
13
  allow: "Allow",
14
+ alwaysAllow: "Always allow",
15
+ alwaysAllowNote: "Always allow: {tool} will run for {client} without asking, with any arguments, until you disconnect {client} from this page.",
93
16
  allowUntilReload: "Allow until reload",
94
17
  allowUntilReloadNote: "Allow until reload: {tool} will run for {client} without asking, with any arguments, until you reload this page or disconnect {client}.",
95
18
  argumentsHidden: "The arguments cannot be shown, so this call cannot be allowed.",
@@ -133,14 +56,14 @@ var STRINGS = {
133
56
  codeNote: "A new code appears every 2 minutes and after each use.",
134
57
  codeUsed: "Code used. Waiting for your AI app…",
135
58
  signIn: "When your AI app asks, sign in with the account you use on this page. No code is needed.",
136
- newAddress: "New address",
137
- newAddressNote: "Someone else may have this address, or is guessing codes? A new address disconnects every AI app from this one.",
138
- newAddressQuestionOne: "A new address disconnects {apps}. To use this page again, add the new address to it.",
139
- newAddressQuestionMany: "A new address disconnects {apps}. To use this page again, add the new address to them.",
140
- newAddressConfirm: "Disconnect and get new address",
59
+ newAddress: "Disconnect all apps",
60
+ newAddressNote: "An AI app is connected that should not be? This disconnects every AI app from this page; each one has to connect again with a new code.",
61
+ newAddressQuestionOne: "This disconnects {apps}. To use this page with it again, connect it again and enter a new code.",
62
+ newAddressQuestionMany: "This disconnects {apps}. To use this page with them again, connect them again and enter a new code.",
63
+ newAddressConfirm: "Disconnect all",
141
64
  cancel: "Cancel",
142
- gettingNewAddress: "Getting a new address…",
143
- newAddressDone: "This is a new address. Add it to your AI app again.",
65
+ gettingNewAddress: "Disconnecting…",
66
+ newAddressDone: "Every AI app is disconnected. Connect yours again.",
144
67
  connectedOne: "{apps} is connected",
145
68
  connectedMany: "{apps} are connected",
146
69
  connectedNextOne: "You can close this now and ask it to use the tools of this page.",
@@ -153,16 +76,20 @@ var STRINGS = {
153
76
  disconnectNote: "To disconnect an app, connect this page again first.",
154
77
  storeUnavailable: "The relay could not save this. Try again.",
155
78
  disconnectFailed: "Could not disconnect the app. Try again.",
156
- runsWithoutAsking: "Runs without asking: {tools}",
157
- askAgain: "Ask again",
158
- askAgainApp: "Ask again before {app} runs a tool",
159
- closeNote: "Closing this stops the code. The address stays the same: to connect later, open this again from the page.",
79
+ runsWithoutAsking: "Runs without asking",
80
+ destructive: "destructive",
81
+ allowToolApp: "{tool} runs without asking for {app}",
82
+ allowDestructiveToolApp: "{tool} (destructive) runs without asking for {app}",
83
+ allowEverything: "Allow everything, no questions asked",
84
+ allowEverythingApp: "Allow everything, no questions asked, for {app}",
85
+ allowEverythingNote: "Every tool of this page runs for {app} without asking, with any arguments: also tools you have not seen yet and ones that delete or overwrite.",
86
+ closeNote: "Closing this stops the code. To connect later, open this again from the page.",
160
87
  close: "Close",
161
88
  done: "Done",
162
89
  replacedSiblingTitle: "Opened in another tab",
163
90
  replacedSibling: "This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.",
164
91
  replacedTitle: "Another tab or program took over this page",
165
- replaced: "Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied its address. A new address disconnects every AI app from the old one; then add the new address to your AI apps again.",
92
+ replaced: "Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied what this page keeps to connect. “Disconnect all apps” ends that; then connect your AI apps again with a new code.",
166
93
  takenOverAgain: "It was taken over again before its AI apps were disconnected. Try again.",
167
94
  tryAgainOrClose: "{reason} Try again, or close this."
168
95
  };
@@ -256,7 +183,7 @@ html dialog.tab-mcp-dialog:where(:focus) { outline: none; }
256
183
  .tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
257
184
  .tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }
258
185
  .tab-mcp-dialog :where(small) { font-size: 0.875em; }
259
- .tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next, .tab-mcp-waiting, .tab-mcp-scroll-note, .tab-mcp-allowed) { color: var(--_tab-mcp-muted); }
186
+ .tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next, .tab-mcp-waiting, .tab-mcp-scroll-note) { color: var(--_tab-mcp-muted); }
260
187
  html dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }
261
188
  .tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; text-transform: none; letter-spacing: normal; width: auto; 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; }
262
189
  html dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }
@@ -291,7 +218,18 @@ html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-
291
218
  .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; }
292
219
  .tab-mcp-apps :where(li) { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 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); }
293
220
  .tab-mcp-app { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }
294
- .tab-mcp-allowed { display: flex; flex-basis: 100%; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.875em; overflow-wrap: anywhere; }
221
+ .tab-mcp-allowed { display: grid; flex-basis: 100%; gap: 0.25rem; padding-top: 0.5rem; border-top: 1px solid var(--_tab-mcp-line); font-size: 0.875em; overflow-wrap: anywhere; }
222
+ .tab-mcp-allowed-title { font-weight: 600; color: var(--_tab-mcp-muted); }
223
+ .tab-mcp-switches { display: grid; gap: 0.125rem; }
224
+ .tab-mcp-switch { display: flex; align-items: center; gap: 0.625rem; min-height: 2rem; cursor: pointer; }
225
+ .tab-mcp-switch > :where(input) { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 2.25rem; height: 1.25rem; margin: 0; padding: 0; border: 1px solid var(--_tab-mcp-line); border-radius: 0.625rem; background: var(--_tab-mcp-surface); cursor: pointer; }
226
+ .tab-mcp-switch > :where(input)::before { content: ""; position: absolute; top: 2px; left: 2px; width: calc(1.25rem - 6px); height: calc(1.25rem - 6px); border-radius: 50%; background: var(--_tab-mcp-muted); }
227
+ .tab-mcp-switch > :where(input:checked) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); border-color: transparent; }
228
+ .tab-mcp-switch > :where(input:checked)::before { left: calc(100% - 1.25rem + 4px); background: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); }
229
+ html dialog.tab-mcp-dialog :where(.tab-mcp-switch > input:disabled) { opacity: 0.45; cursor: not-allowed; }
230
+ .tab-mcp-destructive { color: var(--_tab-mcp-danger); }
231
+ .tab-mcp-everything { font-weight: 600; }
232
+ .tab-mcp-everything-note { color: var(--_tab-mcp-muted); }
295
233
  .tab-mcp-apps-note { margin-top: 0.5rem; }
296
234
  .tab-mcp-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }
297
235
  .tab-mcp-success-icon { flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; font-size: 1.5em; font-weight: 700; line-height: 1; color: var(--_tab-mcp-success); background: color-mix(in srgb, var(--_tab-mcp-success) 16%, transparent); }
@@ -312,8 +250,8 @@ html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-
312
250
  .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); }
313
251
  .tab-mcp-always-note, .tab-mcp-waiting, .tab-mcp-scroll-note { font-size: 0.875em; }
314
252
  @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; } .tab-mcp-code { grid-template-columns: minmax(0, 1fr); } .tab-mcp-code > :where(button) { justify-self: start; } }
315
- @media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } }
316
- @media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }
253
+ @media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } .tab-mcp-switch > :where(input)::before { transition: left 0.15s ease-out; } }
254
+ @media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } .tab-mcp-switch > :where(input) { forced-color-adjust: none; background: Canvas; border-color: ButtonText; } .tab-mcp-switch > :where(input)::before { forced-color-adjust: none; background: ButtonText; } .tab-mcp-switch > :where(input:checked) { background: Highlight; } .tab-mcp-switch > :where(input:checked)::before { background: HighlightText; } }
317
255
  @keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
318
256
  @keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }
319
257
  `;
@@ -386,7 +324,7 @@ function copyButton(doc, s, label, value, select, announce, className, kind) {
386
324
  return { button: node, reset };
387
325
  }
388
326
 
389
- export { allowedFor, nextId, stringsOf, format, fill, el, button, visible, clientLabel, listOf, newDialog, copyButton };
327
+ export { nextId, stringsOf, format, fill, el, button, visible, clientLabel, listOf, newDialog, copyButton };
390
328
 
391
- //# debugId=F1BE73806BEBC29B64756E2164756E21
392
- //# sourceMappingURL=index-jnz7w9xa.js.map
329
+ //# debugId=461C87FA3A5E330064756E2164756E21
330
+ //# sourceMappingURL=index-c1c266tm.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/strings.ts", "../src/dialog.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Every text of the library's dialogs, in one table (CU 5). A page passes\n * its own for some or all keys (`ui: { strings }`); the dialogs use these for\n * the rest. `{name}` is a placeholder the dialog fills in: names of tools\n * and AI apps (isolated, so that they cannot reorder the sentence), the\n * code, counts. Where English needs two forms, there are two keys\n * (`…One` for one, `…Many` for more). `lang` and `dir` are the language and\n * direction of the texts, set on every dialog.\n */\nexport const STRINGS = {\n\tlang: \"en\",\n\tdir: \"ltr\",\n\t/** Between the last two items of a list (\"A, B and C\"). */\n\tand: \"and\",\n\n\t// The confirmation of a consequential tool call.\n\tconfirmTitle: \"Allow {tool}?\",\n\tconfirmWho: \"{client} wants to run {tool}.\",\n\tdeny: \"Don't allow\",\n\tallow: \"Allow\",\n\t/** `alwaysAllow: true`: kept until the app is disconnected. */\n\talwaysAllow: \"Always allow\",\n\talwaysAllowNote:\n\t\t\"Always allow: {tool} will run for {client} without asking, with any arguments, until you disconnect {client} from this page.\",\n\t/** `alwaysAllow: \"until-reload\"`, or kept in memory only (`storage: null`). */\n\tallowUntilReload: \"Allow until reload\",\n\tallowUntilReloadNote:\n\t\t\"Allow until reload: {tool} will run for {client} without asking, with any arguments, until you reload this page or disconnect {client}.\",\n\targumentsHidden:\n\t\t\"The arguments cannot be shown, so this call cannot be allowed.\",\n\tscrollToAllow: \"Scroll to the end of the arguments to allow this call.\",\n\twaitingOne: \"1 more call is waiting after this one.\",\n\twaitingMany: \"{n} more calls are waiting after this one.\",\n\t/** Before the page's title while a confirmation waits in a hidden tab. */\n\ttitlePrefix: \"Allow? – \",\n\n\t// How the dialogs name a caller.\n\tclientWebMcp: \"An agent in this browser\",\n\tclientLocal: \"{name} (this site's assistant)\",\n\t/** An AI app through the relay: its name and the host of its client id. */\n\tclientRelay: \"{name} ({host})\",\n\n\t// Copy buttons.\n\tcopy: \"Copy\",\n\tcopied: \"Copied\",\n\t/** On the button after a refused Copy: the text is selected instead. */\n\tpressMac: \"Press ⌘C\",\n\tpressOther: \"Press Ctrl+C\",\n\t/** The same on a touch screen, where there is no key to press. */\n\tselected: \"Selected\",\n\tcopyAddress: \"Copy address\",\n\tcopyCode: \"Copy code\",\n\tcopyCommand: \"Copy {app} command\",\n\n\t// The connect dialog.\n\tconnectTitle: \"Connect your AI app\",\n\tconnecting: \"Connecting…\",\n\tconnectAgain: \"Connect again\",\n\treconnecting: \"Connection lost. Reconnecting…\",\n\tnotConnected: \"Not connected.\",\n\tunreachable: \"Could not connect. Check your internet connection.\",\n\trateLimited: \"Too many attempts. Wait a minute, then connect again.\",\n\trefused: \"The connection was refused.\",\n\tended: \"The session ended.\",\n\tlost: \"The connection was lost.\",\n\tclosed: \"The connection was closed.\",\n\tdisconnected: \"Disconnected.\",\n\tcheckingSignIn: \"Checking your sign-in…\",\n\tsignInFirst: \"Sign in to this page first.\",\n\tsignInRefused: \"Your sign-in on this page was not accepted.\",\n\t/** `{reason}`: the relay's reason, as it gave it. */\n\tsignInRefusedWhy: \"Your sign-in on this page was not accepted ({reason}).\",\n\treadyApp: \"{app} is ready for your AI app.\",\n\treadyPage: \"This page is ready for your AI app.\",\n\taddressLabel: \"Add this address to your AI app:\",\n\thelp: \"How do I add it?\",\n\tguide: \"Step by step, and what to do when it fails\",\n\tcodeSentence: \"When asked, enter the code {code}\",\n\tcodeNote: \"A new code appears every 2 minutes and after each use.\",\n\tcodeUsed: \"Code used. Waiting for your AI app…\",\n\tsignIn:\n\t\t\"When your AI app asks, sign in with the account you use on this page. No code is needed.\",\n\tnewAddress: \"Disconnect all apps\",\n\tnewAddressNote:\n\t\t\"An AI app is connected that should not be? This disconnects every AI app from this page; each one has to connect again with a new code.\",\n\tnewAddressQuestionOne:\n\t\t\"This disconnects {apps}. To use this page with it again, connect it again and enter a new code.\",\n\tnewAddressQuestionMany:\n\t\t\"This disconnects {apps}. To use this page with them again, connect them again and enter a new code.\",\n\tnewAddressConfirm: \"Disconnect all\",\n\tcancel: \"Cancel\",\n\tgettingNewAddress: \"Disconnecting…\",\n\tnewAddressDone: \"Every AI app is disconnected. Connect yours again.\",\n\tconnectedOne: \"{apps} is connected\",\n\tconnectedMany: \"{apps} are connected\",\n\tconnectedNextOne:\n\t\t\"You can close this now and ask it to use the tools of this page.\",\n\tconnectedNextMany:\n\t\t\"You can close this now and ask them to use the tools of this page.\",\n\tconnectAnother: \"Connect another app\",\n\tconnectedHeading: \"Connected\",\n\tappConnected: \"{app} connected\",\n\tdisconnect: \"Disconnect\",\n\tdisconnectApp: \"Disconnect {app}\",\n\tdisconnectNote: \"To disconnect an app, connect this page again first.\",\n\t/** Disconnect failed: the relay could not save it (`store_unavailable`). */\n\tstoreUnavailable: \"The relay could not save this. Try again.\",\n\t/** Disconnect failed for another reason. */\n\tdisconnectFailed: \"Could not disconnect the app. Try again.\",\n\t// Under a connected app: a switch per tool that asks, and one for all.\n\trunsWithoutAsking: \"Runs without asking\",\n\t/** After a tool's name: it may delete or overwrite (`destructiveHint`). */\n\tdestructive: \"destructive\",\n\t/** A tool's switch, as read out: starts with what it shows (WCAG 2.5.3). */\n\tallowToolApp: \"{tool} runs without asking for {app}\",\n\tallowDestructiveToolApp: \"{tool} (destructive) runs without asking for {app}\",\n\tallowEverything: \"Allow everything, no questions asked\",\n\tallowEverythingApp: \"Allow everything, no questions asked, for {app}\",\n\tallowEverythingNote:\n\t\t\"Every tool of this page runs for {app} without asking, with any arguments: also tools you have not seen yet and ones that delete or overwrite.\",\n\tcloseNote:\n\t\t\"Closing this stops the code. To connect later, open this again from the page.\",\n\tclose: \"Close\",\n\tdone: \"Done\",\n\n\t// The notice when another tab or program took over the address.\n\treplacedSiblingTitle: \"Opened in another tab\",\n\treplacedSibling:\n\t\t\"This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.\",\n\treplacedTitle: \"Another tab or program took over this page\",\n\treplaced:\n\t\t\"Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied what this page keeps to connect. “Disconnect all apps” ends that; then connect your AI apps again with a new code.\",\n\ttakenOverAgain:\n\t\t\"It was taken over again before its AI apps were disconnected. Try again.\",\n\t/** `{reason}`: why disconnecting all apps failed, one of the texts above. */\n\ttryAgainOrClose: \"{reason} Try again, or close this.\",\n};\n\n/** The texts of the dialogs: the keys of {@link STRINGS}, each a string. */\nexport type DialogStrings = { [K in keyof typeof STRINGS]: string };\n",
6
+ "/**\n * What the library's dialogs share: the stylesheet, elements, buttons, the\n * texts (`strings.ts`) and how a caller is named. The confirmation\n * (`confirm.ts`) and the connect dialog (`connect.ts`) are chunks of their\n * own, loaded on demand; pages with their own UI use the events and methods\n * of `TabMcp` instead.\n */\n\nimport { type DialogStrings, STRINGS } from \"./strings.ts\";\nimport type { DialogOptions, Grant, ToolCallClient } from \"./types.ts\";\nimport { escapeInvisible } from \"./visible.ts\";\n\nlet counter = 0;\n\n/** A new id for the elements of one dialog. */\nexport function nextId(): string {\n\treturn `tab-mcp-${++counter}`;\n}\n\n/** The texts: the page's own where it gave them, else the English ones. */\nexport function stringsOf(options: DialogOptions | undefined): DialogStrings {\n\tconst s: DialogStrings = { ...STRINGS };\n\t// Only strings: a missing translation (`undefined`) keeps the English text.\n\tfor (const [key, value] of Object.entries(options?.strings ?? {}))\n\t\tif (typeof value === \"string\" && key in s)\n\t\t\ts[key as keyof DialogStrings] = value;\n\treturn s;\n}\n\n/** `template` with its `{name}` placeholders filled in, as text. */\nexport function format(\n\ttemplate: string,\n\tvalues: Record<string, string>,\n): string {\n\treturn template.replace(\n\t\t/\\{(\\w+)\\}/g,\n\t\t(all, key: string) => values[key] ?? all,\n\t);\n}\n\n/**\n * `template` with its `{name}` placeholders filled in, as nodes: a string\n * value is a name, isolated so that it cannot reorder the words around it\n * (and may stand twice); a node is put in as it is.\n */\nexport function fill(\n\tdoc: Document,\n\ttemplate: string,\n\tvalues: Record<string, string | Node>,\n): (Node | string)[] {\n\treturn template.split(/\\{(\\w+)\\}/).map((part, i) => {\n\t\tif (i % 2 === 0) return part;\n\t\tconst value = values[part];\n\t\tif (value === undefined) return `{${part}}`;\n\t\treturn typeof value === \"string\" ? name(doc, value) : value;\n\t});\n}\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\n/**\n * A button. `className` is its own class; `kind` marks the one next step\n * (`tab-mcp-primary`) or one that disconnects (`tab-mcp-danger`); without\n * one it is a plain, outlined button.\n */\nexport function button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n\tclassName?: string,\n\tkind?: \"primary\" | \"danger\",\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tif (className !== undefined) node.classList.add(className);\n\tif (kind !== undefined) node.classList.add(`tab-mcp-${kind}`);\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/** A name in a sentence, isolated so that it cannot reorder the words around it. */\nexport function name(doc: Document, text: string): HTMLElement {\n\tconst node = el(doc, \"bdi\", { text });\n\tnode.dir = \"ltr\";\n\treturn node;\n}\n\n/** Invisible, blank and direction characters as `\\uXXXX` (`visible.ts`). */\nexport const visible: (text: string) => string = escapeInvisible;\n\n/**\n * How the dialogs name a caller: an AI app's name and verified host; for\n * the caller of a served port, the name the page gave it and what it is.\n */\nexport function clientLabel(\n\tclient: ToolCallClient | Grant[\"client\"],\n\ts: DialogStrings,\n): string {\n\tif (\"kind\" in client && client.kind === \"webmcp\") return s.clientWebMcp;\n\tif (\"kind\" in client && client.kind === \"local\")\n\t\treturn format(s.clientLocal, { name: visible(client.name ?? client.id) });\n\tconst host = visible(client.host || client.id);\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? format(s.clientRelay, { name: visible(client.name), host })\n\t\t: host;\n}\n\n/** \"A and B\", \"A, B and C\". */\nexport function listOf(items: string[], s: DialogStrings): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} ${s.and} ${items.at(-1)}`;\n}\n\n/**\n * The look of the dialogs. Every selector has the specificity of one class\n * (the rest is in `:where()`), so rules of the page for elements, such as\n * `button { … }` or a reset's `* { border-width: 0 }`, do not change the\n * dialogs. The rules for states (hover, focus, disabled) and the primary\n * and danger buttons add two elements (`html dialog.…`, `html button.…`),\n * so `button:hover`, `button:focus` or `button:disabled` of the page do not\n * either. A page overrides with two classes, `.tab-mcp-dialog .tab-mcp-x`,\n * which wins over all of them; one class does not. The `--tab-mcp-*`\n * custom properties (on `:root` or on `.tab-mcp-dialog`) change single\n * values; the library only reads them. The defaults use system colours and the\n * page's `color-scheme`, so the dialogs follow its light or dark scheme. The\n * `--_tab-mcp-*` properties are internal. Order matters among equals.\n */\nexport const DIALOG_CSS = `.tab-mcp-dialog {\n--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);\n--_tab-mcp-bg: var(--tab-mcp-background, Canvas);\n--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));\n--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);\n--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));\n--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));\n--_tab-mcp-success: var(--tab-mcp-success, light-dark(#1a7f37, #6fdd8b));\n--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);\nbox-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;\nfont: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);\nborder: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);\npadding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));\npointer-events: auto;\n}\n.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }\n.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }\n.tab-mcp-dialog :where([hidden]) { display: none !important; }\nhtml dialog.tab-mcp-dialog:where(:focus) { outline: none; }\n.tab-mcp-dialog :where(*) { box-sizing: border-box; color: inherit; }\n.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }\n.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }\n.tab-mcp-dialog :where(small) { font-size: 0.875em; }\n.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note, .tab-mcp-success-next, .tab-mcp-waiting, .tab-mcp-scroll-note) { color: var(--_tab-mcp-muted); }\nhtml dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }\n.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; text-transform: none; letter-spacing: normal; width: auto; 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; }\nhtml dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }\nhtml dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }\nhtml 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; }\nhtml button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }\nhtml button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }\n.tab-mcp-copy { min-width: 6em; }\n.tab-mcp-close { font-size: 0.875em; }\n.tab-mcp-status { margin-top: -0.5rem; }\n.tab-mcp-description:where(:empty) { display: none; }\n.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }\n.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }\n.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }\n.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); }\n.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); }\n.tab-mcp-code > :where(span) { font-weight: 600; }\n.tab-mcp-code :where(br) { display: none; }\n.tab-mcp-code :where(small) { grid-column: 1 / -1; }\n.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; }\n.tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }\n.tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }\n.tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }\n.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }\n.tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }\n.tab-mcp-help :where(li) { overflow-wrap: anywhere; }\n.tab-mcp-help :where(strong) { display: block; font-weight: 600; }\n.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }\n.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); }\n.tab-mcp-command-note { display: block; margin-top: 0.375rem; }\n.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; }\n.tab-mcp-apps :where(li) { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 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); }\n.tab-mcp-app { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }\n.tab-mcp-allowed { display: grid; flex-basis: 100%; gap: 0.25rem; padding-top: 0.5rem; border-top: 1px solid var(--_tab-mcp-line); font-size: 0.875em; overflow-wrap: anywhere; }\n.tab-mcp-allowed-title { font-weight: 600; color: var(--_tab-mcp-muted); }\n.tab-mcp-switches { display: grid; gap: 0.125rem; }\n.tab-mcp-switch { display: flex; align-items: center; gap: 0.625rem; min-height: 2rem; cursor: pointer; }\n.tab-mcp-switch > :where(input) { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 2.25rem; height: 1.25rem; margin: 0; padding: 0; border: 1px solid var(--_tab-mcp-line); border-radius: 0.625rem; background: var(--_tab-mcp-surface); cursor: pointer; }\n.tab-mcp-switch > :where(input)::before { content: \"\"; position: absolute; top: 2px; left: 2px; width: calc(1.25rem - 6px); height: calc(1.25rem - 6px); border-radius: 50%; background: var(--_tab-mcp-muted); }\n.tab-mcp-switch > :where(input:checked) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); border-color: transparent; }\n.tab-mcp-switch > :where(input:checked)::before { left: calc(100% - 1.25rem + 4px); background: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); }\nhtml dialog.tab-mcp-dialog :where(.tab-mcp-switch > input:disabled) { opacity: 0.45; cursor: not-allowed; }\n.tab-mcp-destructive { color: var(--_tab-mcp-danger); }\n.tab-mcp-everything { font-weight: 600; }\n.tab-mcp-everything-note { color: var(--_tab-mcp-muted); }\n.tab-mcp-apps-note { margin-top: 0.5rem; }\n.tab-mcp-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-success-icon { flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; font-size: 1.5em; font-weight: 700; line-height: 1; color: var(--_tab-mcp-success); background: color-mix(in srgb, var(--_tab-mcp-success) 16%, transparent); }\n.tab-mcp-success-icon::before { content: \"\\\\2713\"; }\n.tab-mcp-success-text { display: grid; gap: 0.125rem; min-width: 0; }\n.tab-mcp-success-title { font-size: 1.125em; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-setup { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-setup-toggle { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem; text-align: start; font-weight: 600; border-color: var(--_tab-mcp-line); }\n.tab-mcp-setup-toggle::before { content: \"\"; flex: none; width: 0.45em; height: 0.45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateX(-0.1em) rotate(-45deg); }\n.tab-mcp-setup-toggle:where([aria-expanded=\"true\"])::before { transform: translateY(-0.15em) rotate(45deg); }\n.tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }\n.tab-mcp-new-address-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }\n.tab-mcp-new-address-row > :where(small) { flex: 1 1 14rem; color: var(--_tab-mcp-muted); }\n.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); }\n.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }\n.tab-mcp-close-note { flex: 1 1 12rem; }\n.tab-mcp-confirm :where(p bdi) { font-weight: 600; }\n.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); }\n.tab-mcp-always-note, .tab-mcp-waiting, .tab-mcp-scroll-note { font-size: 0.875em; }\n@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; } .tab-mcp-code { grid-template-columns: minmax(0, 1fr); } .tab-mcp-code > :where(button) { justify-self: start; } }\n@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } .tab-mcp-switch > :where(input)::before { transition: left 0.15s ease-out; } }\n@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } .tab-mcp-switch > :where(input) { forced-color-adjust: none; background: Canvas; border-color: ButtonText; } .tab-mcp-switch > :where(input)::before { forced-color-adjust: none; background: ButtonText; } .tab-mcp-switch > :where(input:checked) { background: Highlight; } .tab-mcp-switch > :where(input:checked)::before { background: HighlightText; } }\n@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }\n@keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }\n`;\n\nconst sheets = new WeakMap<Document, CSSStyleSheet>();\n\n/**\n * Adopts `DIALOG_CSS` into the document once, next to the page's own adopted\n * sheets. A constructed stylesheet needs no `style-src` exception under a\n * strict CSP. Where constructed stylesheets are not supported, the dialogs\n * keep the browser's default look and work the same.\n */\nfunction adoptStyles(doc: Document): void {\n\ttry {\n\t\tlet sheet = sheets.get(doc);\n\t\tif (sheet === undefined) {\n\t\t\tconst Sheet = (doc.defaultView as (Window & typeof globalThis) | null)\n\t\t\t\t?.CSSStyleSheet;\n\t\t\tif (Sheet === undefined || !Array.isArray(doc.adoptedStyleSheets)) return;\n\t\t\tsheet = new Sheet();\n\t\t\tsheet.replaceSync(DIALOG_CSS);\n\t\t\tsheets.set(doc, sheet);\n\t\t}\n\t\t// The page may have replaced the list since.\n\t\tif (!doc.adoptedStyleSheets.includes(sheet))\n\t\t\tdoc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];\n\t} catch {\n\t\t// Not supported: the default look.\n\t}\n}\n\n/**\n * A dialog with its heading (`title`, or filled in by the caller). It\n * carries the texts' language and direction (`lang`, `dir` of the\n * strings), whatever the page's: read out with that voice, laid out that way.\n */\nexport function newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ts: DialogStrings,\n\t...title: (Node | string)[]\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement; id: string } {\n\tconst id = nextId();\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\tdialog.lang = s.lang;\n\tdialog.dir = s.dir;\n\tadoptStyles(doc);\n\tconst heading = el(doc, \"h2\", { id: `${id}-title` }, ...title);\n\tdialog.append(heading);\n\treturn { dialog, heading, id };\n}\n\n/** How long a Copy button says \"Copied\", and how long it says to press Ctrl+C. */\nexport const COPIED_MS = 2000;\nexport const SELECTED_MS = 8000;\n\n/** What the button says after a refused Copy, by the user's device. */\nfunction pressToCopy(doc: Document, s: DialogStrings): string {\n\tconst view = doc.defaultView;\n\tif (view?.matchMedia?.(\"(pointer: coarse)\").matches === true)\n\t\treturn s.selected;\n\tconst platform = view?.navigator.platform ?? \"\";\n\treturn /^(Mac|iP)/.test(platform) ? s.pressMac : s.pressOther;\n}\n\n/**\n * A Copy button for `value()`, read at click time. Says \"Copied\" for a\n * moment once the clipboard took it; without a clipboard (or when it refuses)\n * `select()` puts the text in the selection and the button says to press\n * Ctrl+C (⌘C on Apple devices). `label` names it for assistive technology\n * (\"Copy code\"), as the dialog has more than one Copy; while it says what\n * happened, that is its name, and `announce` says it too.\n */\nexport function copyButton(\n\tdoc: Document,\n\ts: DialogStrings,\n\tlabel: string,\n\tvalue: () => string,\n\tselect: () => void,\n\tannounce: (text: string) => void,\n\tclassName: string,\n\tkind?: \"primary\",\n): { button: HTMLButtonElement; reset: () => void } {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst say = (text: string, ms: number) => {\n\t\tnode.textContent = text;\n\t\tnode.removeAttribute(\"aria-label\");\n\t\tannounce(text);\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(reset, ms);\n\t};\n\tconst node = button(\n\t\tdoc,\n\t\ts.copy,\n\t\t() => {\n\t\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t\t?.clipboard;\n\t\t\tconst selected = () => {\n\t\t\t\tselect();\n\t\t\t\tsay(pressToCopy(doc, s), SELECTED_MS);\n\t\t\t};\n\t\t\tif (clipboard !== undefined)\n\t\t\t\tclipboard\n\t\t\t\t\t.writeText(value())\n\t\t\t\t\t.then(() => say(s.copied, COPIED_MS), selected);\n\t\t\telse selected();\n\t\t},\n\t\tclassName,\n\t\tkind,\n\t);\n\t// The same width for \"Copy\" and \"Copied\": nothing moves.\n\tnode.classList.add(\"tab-mcp-copy\");\n\tconst reset = () => {\n\t\tclearTimeout(timer);\n\t\ttimer = undefined;\n\t\tnode.textContent = s.copy;\n\t\tnode.setAttribute(\"aria-label\", label);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n"
7
+ ],
8
+ "mappings": ";;;;;AASO,IAAM,UAAU;AAAA,EACtB,MAAM;AAAA,EACN,KAAK;AAAA,EAEL,KAAK;AAAA,EAGL,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,OAAO;AAAA,EAEP,aAAa;AAAA,EACb,iBACC;AAAA,EAED,kBAAkB;AAAA,EAClB,sBACC;AAAA,EACD,iBACC;AAAA,EACD,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,aAAa;AAAA,EAEb,aAAa;AAAA,EAGb,cAAc;AAAA,EACd,aAAa;AAAA,EAEb,aAAa;AAAA,EAGb,MAAM;AAAA,EACN,QAAQ;AAAA,EAER,UAAU;AAAA,EACV,YAAY;AAAA,EAEZ,UAAU;AAAA,EACV,aAAa;AAAA,EACb,UAAU;AAAA,EACV,aAAa;AAAA,EAGb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,E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AA;AAW7C,SAAS,UAAU,CACzB,KACA,GACA,OACA,OACA,QACA,UACA,WACA,MACmD;AAAA,EACnD,IAAI;AAAA,EACJ,MAAM,MAAM,CAAC,MAAc,OAAe;AAAA,IACzC,KAAK,cAAc;AAAA,IACnB,KAAK,gBAAgB,YAAY;AAAA,IACjC,SAAS,IAAI;AAAA,IACb,aAAa,KAAK;AAAA,IAClB,QAAQ,WAAW,OAAO,EAAE;AAAA;AAAA,EAE7B,MAAM,OAAO,OACZ,KACA,EAAE,MACF,MAAM;AAAA,IACL,MAAM,YAAa,IAAI,aAAa,WACjC;AAAA,IACH,MAAM,WAAW,MAAM;AAAA,MACtB,OAAO;AAAA,MACP,IAAI,YAAY,KAAK,CAAC,GAAG,WAAW;AAAA;AAAA,IAErC,IAAI,cAAc;AAAA,MACjB,UACE,UAAU,MAAM,CAAC,EACjB,KAAK,MAAM,IAAI,EAAE,QAAQ,SAAS,GAAG,QAAQ;AAAA,IAChD;AAAA,MAAK,SAAS;AAAA,KAEf,WACA,IACD;AAAA,EAEA,KAAK,UAAU,IAAI,cAAc;AAAA,EACjC,MAAM,QAAQ,MAAM;AAAA,IACnB,aAAa,KAAK;AAAA,IAClB,QAAQ;AAAA,IACR,KAAK,cAAc,EAAE;AAAA,IACrB,KAAK,aAAa,cAAc,KAAK;AAAA;AAAA,EAEtC,MAAM;AAAA,EACN,OAAO,EAAE,QAAQ,MAAM,MAAM;AAAA;",
9
+ "debugId": "461C87FA3A5E330064756E2164756E21",
10
+ "names": []
11
+ }
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/visible.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Text an AI app or a page wrote, made safe to show to the user before they\n * approve something: characters that are invisible, blank or turn the text's\n * direction are written as escapes, so the text cannot look like something\n * else. Shared by the library's confirmation dialog and tab-mcp for Chrome.\n */\n\n/**\n * Characters that are invisible, blank or change the direction of the text\n * around them: controls (C0 and C1, but tab and line feed, which are only\n * JSON's layout), format characters (bidi controls and isolates, zero-width\n * ones, tags), the other default-ignorable ones (variation selectors, U+034F,\n * the Hangul fillers), private-use, unassigned and lone surrogate code\n * points, line and paragraph separators, every space but the plain one\n * (U+00A0, U+2007, U+3000…) and the Braille blank (U+2800).\n */\nconst INVISIBLE =\n\t/(?![\\t\\n ])[\\p{Cc}\\p{Cf}\\p{Default_Ignorable_Code_Point}\\p{Co}\\p{Cn}\\p{Cs}\\p{Zl}\\p{Zp}\\p{Zs}\\u{2800}]/gu;\n\n/**\n * `text` with each such character as `\\uXXXX` (a surrogate pair for one\n * beyond U+FFFF), as JSON would write it: JSON stays JSON for the same value.\n */\nexport function escapeInvisible(text: string): string {\n\treturn text.replace(INVISIBLE, (ch) => {\n\t\tlet escaped = \"\";\n\t\tfor (let i = 0; i < ch.length; i++)\n\t\t\tescaped += `\\\\u${ch.charCodeAt(i).toString(16).toUpperCase().padStart(4, \"0\")}`;\n\t\treturn escaped;\n\t});\n}\n"
5
+ "/**\n * Text an AI app or a page wrote, made safe to show to the user before they\n * approve something: characters that are invisible, blank or turn the text's\n * direction are written as escapes, so the text cannot look like something\n * else. Shared by the library's confirmation dialog and the tab-mcp browser extension.\n */\n\n/**\n * Characters that are invisible, blank or change the direction of the text\n * around them: controls (C0 and C1, but tab and line feed, which are only\n * JSON's layout), format characters (bidi controls and isolates, zero-width\n * ones, tags), the other default-ignorable ones (variation selectors, U+034F,\n * the Hangul fillers), private-use, unassigned and lone surrogate code\n * points, line and paragraph separators, every space but the plain one\n * (U+00A0, U+2007, U+3000…) and the Braille blank (U+2800).\n */\nconst INVISIBLE =\n\t/(?![\\t\\n ])[\\p{Cc}\\p{Cf}\\p{Default_Ignorable_Code_Point}\\p{Co}\\p{Cn}\\p{Cs}\\p{Zl}\\p{Zp}\\p{Zs}\\u{2800}]/gu;\n\n/**\n * `text` with each such character as `\\uXXXX` (a surrogate pair for one\n * beyond U+FFFF), as JSON would write it: JSON stays JSON for the same value.\n */\nexport function escapeInvisible(text: string): string {\n\treturn text.replace(INVISIBLE, (ch) => {\n\t\tlet escaped = \"\";\n\t\tfor (let i = 0; i < ch.length; i++)\n\t\t\tescaped += `\\\\u${ch.charCodeAt(i).toString(16).toUpperCase().padStart(4, \"0\")}`;\n\t\treturn escaped;\n\t});\n}\n"
6
6
  ],
7
7
  "mappings": ";AAgBA,IAAM,YACL;AAMM,SAAS,gBAAe,CAAC,MAAsB;AAAA,EACrD,OAAO,KAAK,QAAQ,WAAW,CAAC,OAAO;AAAA,IACtC,IAAI,UAAU;AAAA,IACd,SAAS,IAAI,EAAG,IAAI,GAAG,QAAQ;AAAA,MAC9B,WAAW,MAAM,GAAG,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,GAAG,GAAG;AAAA,IAC7E,OAAO;AAAA,GACP;AAAA;",
8
8
  "debugId": "8E3DD6DE0CE3A2E864756E2164756E21",
@@ -0,0 +1,245 @@
1
+ // src/always-allowed.ts
2
+ function fingerprint(secret) {
3
+ if (secret === undefined)
4
+ return "";
5
+ let hash = 2166136261;
6
+ for (let i = 0;i < secret.length; i++)
7
+ hash = Math.imul(hash ^ secret.charCodeAt(i), 16777619) >>> 0;
8
+ return hash.toString(16);
9
+ }
10
+ var isString = (v) => typeof v === "string";
11
+ function parse(text) {
12
+ const none = { secret: "", grants: new Map };
13
+ let value;
14
+ try {
15
+ value = JSON.parse(text);
16
+ } catch {
17
+ return none;
18
+ }
19
+ const v = value;
20
+ if (!isString(v?.secret) || !Array.isArray(v.grants))
21
+ return none;
22
+ const grants = new Map;
23
+ for (const g of v.grants) {
24
+ const e = g;
25
+ if (!isString(e?.grantId) || typeof e.everything !== "boolean" || !Array.isArray(e.tools))
26
+ return none;
27
+ const tools = [];
28
+ for (const t of e.tools) {
29
+ const tool = t;
30
+ if (!isString(tool?.name) || !isString(tool.description) || tool.title !== undefined && !isString(tool.title))
31
+ return none;
32
+ tools.push(seenOf(tool));
33
+ }
34
+ grants.set(e.grantId, { everything: e.everything, tools });
35
+ }
36
+ return { secret: v.secret, grants };
37
+ }
38
+ function serialize(state) {
39
+ return JSON.stringify({
40
+ secret: state.secret,
41
+ grants: [...state.grants].map(([grantId, e]) => ({ grantId, ...e }))
42
+ });
43
+ }
44
+ function seenOf(tool) {
45
+ const seen = { name: tool.name, description: tool.description };
46
+ if (tool.title !== undefined)
47
+ seen.title = tool.title;
48
+ return seen;
49
+ }
50
+ var sameSeen = (a, b) => a.title === b.title && a.description === b.description;
51
+ var counts = (kept, now) => now === undefined || sameSeen(kept, now);
52
+
53
+ class Allowances {
54
+ kept;
55
+ offered;
56
+ #mcp;
57
+ #registry;
58
+ #secret;
59
+ #storage;
60
+ #key;
61
+ #memory = { secret: "", grants: new Map };
62
+ #unsaved = false;
63
+ #listeners = new Set;
64
+ #unwatch;
65
+ constructor(mcp) {
66
+ const [registry, secrets, alwaysAllow] = mcp._allowed;
67
+ this.#mcp = mcp;
68
+ this.#registry = registry;
69
+ this.#secret = () => fingerprint(secrets?.current());
70
+ this.#storage = alwaysAllow === "until-reload" ? null : secrets?.storage ?? null;
71
+ this.#key = `${secrets?.key}#allowed`;
72
+ this.kept = this.#storage !== null;
73
+ this.offered = alwaysAllow === true || alwaysAllow === "until-reload";
74
+ }
75
+ tools = () => this.#registry.list().filter((t) => t.annotations.consequentialHint === true && (t.callers?.includes("relay") ?? true)).map((t) => {
76
+ const tool = {
77
+ name: t.name,
78
+ description: t.description,
79
+ destructive: t.annotations.destructiveHint === true
80
+ };
81
+ if (t.title !== undefined)
82
+ tool.title = t.title;
83
+ return tool;
84
+ });
85
+ list = (grantId) => (this.#read().get(grantId)?.tools ?? []).filter((t) => counts(t, this.#registry.get(t.name))).map((t) => t.name);
86
+ has = (grantId, name) => {
87
+ const tool = this.#registry.get(name);
88
+ return this.everything(grantId) || tool !== undefined && this.allows(grantId, tool);
89
+ };
90
+ allows(grantId, tool) {
91
+ const entry = this.#read().get(grantId);
92
+ if (entry === undefined)
93
+ return false;
94
+ if (entry.everything)
95
+ return true;
96
+ const kept = entry.tools.find((t) => t.name === tool.name);
97
+ return kept !== undefined && sameSeen(kept, tool);
98
+ }
99
+ allow = (grantId, name) => {
100
+ const tool = this.tools().find((t) => t.name === name);
101
+ if (tool !== undefined)
102
+ this.keep(grantId, tool);
103
+ };
104
+ keep(grantId, tool) {
105
+ if (!this.#granted(grantId))
106
+ return;
107
+ const grants = this.#read();
108
+ const entry = grants.get(grantId) ?? { everything: false, tools: [] };
109
+ entry.tools = [
110
+ ...entry.tools.filter((t) => t.name !== tool.name),
111
+ seenOf(tool)
112
+ ];
113
+ grants.set(grantId, entry);
114
+ this.#write(grants);
115
+ }
116
+ ask = (grantId, name) => {
117
+ const grants = this.#read();
118
+ const entry = grants.get(grantId);
119
+ if (entry === undefined)
120
+ return;
121
+ const tools = entry.tools.filter((t) => t.name !== name);
122
+ if (!entry.everything && tools.length === entry.tools.length)
123
+ return;
124
+ entry.everything = false;
125
+ entry.tools = tools;
126
+ if (tools.length === 0)
127
+ grants.delete(grantId);
128
+ this.#write(grants);
129
+ };
130
+ everything = (grantId) => this.#read().get(grantId)?.everything === true;
131
+ setEverything = (grantId, on) => {
132
+ if (on && !this.#granted(grantId))
133
+ return;
134
+ const grants = this.#read();
135
+ const entry = grants.get(grantId) ?? { everything: false, tools: [] };
136
+ if (entry.everything === on)
137
+ return;
138
+ entry.everything = on;
139
+ if (on || entry.tools.length > 0)
140
+ grants.set(grantId, entry);
141
+ else
142
+ grants.delete(grantId);
143
+ this.#write(grants);
144
+ };
145
+ forget = (grantId) => {
146
+ const grants = this.#read();
147
+ if (grants.delete(grantId))
148
+ this.#write(grants);
149
+ };
150
+ keepGrants(grantIds) {
151
+ const keep = new Set(grantIds);
152
+ const grants = this.#read();
153
+ let changed = this.#memory.grants !== grants && this.#memory.grants.size > 0;
154
+ for (const grantId of [...grants.keys()])
155
+ if (!keep.has(grantId))
156
+ changed = grants.delete(grantId) || changed;
157
+ if (changed)
158
+ this.#write(grants);
159
+ }
160
+ toolsChanged() {
161
+ const grants = this.#read();
162
+ let changed = false;
163
+ for (const [grantId, entry] of [...grants]) {
164
+ const tools = entry.tools.filter((t) => counts(t, this.#registry.get(t.name)));
165
+ if (tools.length === entry.tools.length)
166
+ continue;
167
+ changed = true;
168
+ entry.tools = tools;
169
+ if (!entry.everything && tools.length === 0)
170
+ grants.delete(grantId);
171
+ }
172
+ if (changed)
173
+ this.#write(grants);
174
+ else
175
+ this.#changed();
176
+ }
177
+ onChange = (listener) => {
178
+ this.#listeners.add(listener);
179
+ this.#watch();
180
+ return () => {
181
+ this.#listeners.delete(listener);
182
+ if (this.#listeners.size === 0) {
183
+ this.#unwatch?.();
184
+ this.#unwatch = undefined;
185
+ }
186
+ };
187
+ };
188
+ #watch() {
189
+ if (this.#unwatch !== undefined || this.#storage === null)
190
+ return;
191
+ const g = globalThis;
192
+ const changed = (event) => {
193
+ if (event.key === this.#key)
194
+ this.toolsChanged();
195
+ };
196
+ g.addEventListener?.("storage", changed);
197
+ this.#unwatch = () => g.removeEventListener?.("storage", changed);
198
+ }
199
+ #granted(grantId) {
200
+ return this.#mcp.grants.some((g) => g.grantId === grantId);
201
+ }
202
+ #read() {
203
+ if (this.#storage !== null && !this.#unsaved) {
204
+ try {
205
+ const text = this.#storage.getItem(this.#key);
206
+ if (text !== null)
207
+ this.#memory = parse(text);
208
+ } catch {}
209
+ }
210
+ return this.#memory.secret === this.#secret() ? this.#memory.grants : new Map;
211
+ }
212
+ #write(grants) {
213
+ this.#memory = { secret: this.#secret(), grants };
214
+ try {
215
+ this.#storage?.setItem(this.#key, serialize(this.#memory));
216
+ this.#unsaved = false;
217
+ } catch {
218
+ this.#unsaved = true;
219
+ }
220
+ this.#changed();
221
+ }
222
+ #changed() {
223
+ for (const listener of [...this.#listeners])
224
+ listener();
225
+ }
226
+ }
227
+ var allowances = new WeakMap;
228
+ function allowedFor(mcp) {
229
+ const kept = allowances.get(mcp);
230
+ if (kept !== undefined)
231
+ return kept;
232
+ const made = new Allowances(mcp);
233
+ allowances.set(mcp, made);
234
+ mcp.addEventListener("grantschange", (e) => made.keepGrants(e.detail.grants.map((g) => g.grantId)));
235
+ mcp._allowed[0].onChange(() => made.toolsChanged());
236
+ made.toolsChanged();
237
+ if (mcp.session !== undefined)
238
+ made.keepGrants(mcp.grants.map((g) => g.grantId));
239
+ return made;
240
+ }
241
+
242
+ export { allowedFor };
243
+
244
+ //# debugId=3630D6A5246D9F8464756E2164756E21
245
+ //# sourceMappingURL=index-h8b3dc5p.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/always-allowed.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The tools that run without asking, per AI app (grant), DEC-096 and\n * DEC-200: the ones the user allowed one by one, each with what the user\n * saw of it (title and description; a tool that changed since is asked\n * again and leaves the list), and \"everything\", which covers every tool of\n * the page, also ones the user has not seen.\n *\n * Kept in the page's `storage` under the secret's key with `#allowed`, so\n * that they outlive a reload; in memory with `alwaysAllow: \"until-reload\"`,\n * with `storage: null` and without a relay. Storage is read first on every\n * question, so that a change in another tab of the same address counts at\n * once (only one tab at a time holds the connection, DEC-095).\n *\n * An allowance ends with its grant, and only on what the relay says: the\n * grants of a new session, a removed grant, `newAddress()` (the relay\n * revoked them all). A dropped connection, or a page that has not connected\n * yet, keeps them: `grantschange` does not fire then. They also belong to\n * the address secret they were made under, so a new secret (`newAddress()`\n * here or in another tab) ends them even where nothing listened.\n *\n * Out of the core: the confirmation (`confirm.ts`, which the core loads for\n * every consequential call), the connect dialog and\n * `@ractive-ch/tab-mcp-client/allowed` import it.\n */\n\nimport type { ToolRegistry } from \"./registry.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type { ConfirmRequest, SecretStorage } from \"./types.ts\";\n\n/** What the user saw of a tool: its name, title and description. */\ntype ToolSeen = ConfirmRequest[\"tool\"];\n/** A tool as the registry or a call names it. */\ntype ToolNow = {\n\tname: string;\n\ttitle?: string | undefined;\n\tdescription: string;\n};\n\n/** A tool that asks before it runs, for a page's switch. */\nexport interface AllowedTool {\n\tname: string;\n\ttitle?: string;\n\tdescription: string;\n\t/** Marked `destructiveHint`: it may delete or overwrite. */\n\tdestructive: boolean;\n}\n\n/**\n * The tools that run without asking, per connected AI app (`Grant.grantId`),\n * for a page that draws its own switches: `allowedTools(mcp)` of\n * `@ractive-ch/tab-mcp-client/allowed`. The library's dialogs use the same.\n * The methods are bound: `const { allow } = allowedTools(mcp)` works. The\n * queries (`tools`, `list`, `has`, `everything`) only read: safe while\n * drawing.\n */\nexport interface AllowedTools {\n\t/**\n\t * `true`: kept in the page's `storage` until the app is disconnected;\n\t * `false`: in memory, until the page is reloaded or the app is\n\t * disconnected (`alwaysAllow: \"until-reload\"`, `storage: null`).\n\t */\n\treadonly kept: boolean;\n\t/**\n\t * The page's tools that ask before they run (`consequentialHint`, callable\n\t * by AI apps through the relay), in the order registered.\n\t */\n\ttools(): AllowedTool[];\n\t/**\n\t * The names of the tools allowed one by one for this app, in the order\n\t * allowed; also one that is not registered right now (it runs without\n\t * asking again once it is back unchanged). One registered now with another\n\t * title or description than the user allowed is not in it (it asks).\n\t */\n\tlist(grantId: string): string[];\n\t/**\n\t * Whether a call of this tool by this app runs without asking now:\n\t * \"everything\" is on, or the tool is allowed and registered unchanged.\n\t */\n\thas(grantId: string, name: string): boolean;\n\t/**\n\t * Allow one tool for this app from now on, as it is registered now (its\n\t * title and description). Nothing happens for an app that is not in\n\t * `mcp.grants` or a tool that is not in `tools()`.\n\t */\n\tallow(grantId: string, name: string): void;\n\t/**\n\t * Ask again before this app runs this tool. While \"everything\" is on for\n\t * the app, that goes off too (asking again errs towards asking); the\n\t * other tools allowed one by one stay allowed.\n\t */\n\task(grantId: string, name: string): void;\n\t/** Whether \"Allow everything, no questions asked\" is on for this app. */\n\teverything(grantId: string): boolean;\n\t/**\n\t * \"Allow everything, no questions asked\" for this app: every tool runs\n\t * without asking, with any arguments, also tools registered later, changed\n\t * ones and destructive ones. Turning it on does nothing for an app that\n\t * is not in `mcp.grants`.\n\t */\n\tsetEverything(grantId: string, on: boolean): void;\n\t/** Ask again for everything of this app: its tools and \"everything\". */\n\tforget(grantId: string): void;\n\t/**\n\t * Calls `listener` on every change of the allowances (also one in\n\t * another tab of the same address) and of `tools()`; returns what stops it.\n\t */\n\tonChange(listener: () => void): () => void;\n}\n\n/** One app's allowances. */\ninterface Entry {\n\teverything: boolean;\n\t/** In the order allowed; `title` and `description` as the user saw them. */\n\ttools: ToolSeen[];\n}\n\n/** What is kept: the grants' entries and the secret they belong to. */\ninterface State {\n\t/** {@link fingerprint} of the address secret. */\n\tsecret: string;\n\tgrants: Map<string, Entry>;\n}\n\n/**\n * A short fingerprint of the address secret (FNV-1a, 32 bits): enough to\n * tell that the secret changed, too short to say anything about it.\n */\nfunction fingerprint(secret: string | undefined): string {\n\tif (secret === undefined) return \"\";\n\tlet hash = 0x811c9dc5;\n\tfor (let i = 0; i < secret.length; i++)\n\t\thash = Math.imul(hash ^ secret.charCodeAt(i), 0x01000193) >>> 0;\n\treturn hash.toString(16);\n}\n\nconst isString = (v: unknown): v is string => typeof v === \"string\";\n\n/**\n * The kept text as a state; anything that is not exactly what\n * {@link serialize} writes allows nothing.\n */\nfunction parse(text: string): State {\n\tconst none: State = { secret: \"\", grants: new Map() };\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(text);\n\t} catch {\n\t\treturn none;\n\t}\n\tconst v = value as { secret?: unknown; grants?: unknown } | null;\n\tif (!isString(v?.secret) || !Array.isArray(v.grants)) return none;\n\tconst grants = new Map<string, Entry>();\n\tfor (const g of v.grants as unknown[]) {\n\t\tconst e = g as {\n\t\t\tgrantId?: unknown;\n\t\t\teverything?: unknown;\n\t\t\ttools?: unknown;\n\t\t} | null;\n\t\tif (\n\t\t\t!isString(e?.grantId) ||\n\t\t\ttypeof e.everything !== \"boolean\" ||\n\t\t\t!Array.isArray(e.tools)\n\t\t)\n\t\t\treturn none;\n\t\tconst tools: ToolSeen[] = [];\n\t\tfor (const t of e.tools as unknown[]) {\n\t\t\tconst tool = t as Partial<Record<keyof ToolSeen, unknown>> | null;\n\t\t\tif (\n\t\t\t\t!isString(tool?.name) ||\n\t\t\t\t!isString(tool.description) ||\n\t\t\t\t(tool.title !== undefined && !isString(tool.title))\n\t\t\t)\n\t\t\t\treturn none;\n\t\t\ttools.push(seenOf(tool as ToolSeen));\n\t\t}\n\t\tgrants.set(e.grantId, { everything: e.everything, tools });\n\t}\n\treturn { secret: v.secret, grants };\n}\n\n/** Grant ids, tool names and what the user saw of each: no arguments, no results. */\nfunction serialize(state: State): string {\n\treturn JSON.stringify({\n\t\tsecret: state.secret,\n\t\tgrants: [...state.grants].map(([grantId, e]) => ({ grantId, ...e })),\n\t});\n}\n\n/** Only what the user saw, as plain strings. */\nfunction seenOf(tool: ToolSeen): ToolSeen {\n\tconst seen: ToolSeen = { name: tool.name, description: tool.description };\n\tif (tool.title !== undefined) seen.title = tool.title;\n\treturn seen;\n}\n\nconst sameSeen = (a: ToolSeen, b: ToolNow) =>\n\ta.title === b.title && a.description === b.description;\n\n/**\n * Whether a tool allowed as `kept` still counts against what is registered\n * now (`now`, `undefined` when it is not): unchanged, or not registered. The\n * one rule for drawing (`list`) and for deciding (`has`).\n */\nconst counts = (kept: ToolSeen, now: ToolNow | undefined) =>\n\tnow === undefined || sameSeen(kept, now);\n\n/**\n * The allowances of one `TabMcp`. The public methods are arrow fields, so\n * that they work taken off the object; the queries never write.\n */\nexport class Allowances implements AllowedTools {\n\treadonly kept: boolean;\n\t/** The library's dialogs offer allowing (`alwaysAllow` on). */\n\treadonly offered: boolean;\n\treadonly #mcp: TabMcp;\n\treadonly #registry: ToolRegistry;\n\treadonly #secret: () => string;\n\t/** `null`: in memory only. */\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t#memory: State = { secret: \"\", grants: new Map() };\n\t/**\n\t * The last write to storage failed (quota, blocked): memory holds what the\n\t * user chose, for the page's lifetime, and storage is not read over it\n\t * until a write succeeds again.\n\t */\n\t#unsaved = false;\n\treadonly #listeners = new Set<() => void>();\n\t#unwatch: (() => void) | undefined;\n\n\tconstructor(mcp: TabMcp) {\n\t\tconst [registry, secrets, alwaysAllow] = mcp._allowed;\n\t\tthis.#mcp = mcp;\n\t\tthis.#registry = registry;\n\t\tthis.#secret = () => fingerprint(secrets?.current());\n\t\tthis.#storage =\n\t\t\talwaysAllow === \"until-reload\" ? null : (secrets?.storage ?? null);\n\t\tthis.#key = `${secrets?.key}#allowed`;\n\t\tthis.kept = this.#storage !== null;\n\t\tthis.offered = alwaysAllow === true || alwaysAllow === \"until-reload\";\n\t}\n\n\treadonly tools = (): AllowedTool[] =>\n\t\tthis.#registry\n\t\t\t.list()\n\t\t\t.filter(\n\t\t\t\t(t) =>\n\t\t\t\t\tt.annotations.consequentialHint === true &&\n\t\t\t\t\t(t.callers?.includes(\"relay\") ?? true),\n\t\t\t)\n\t\t\t.map((t) => {\n\t\t\t\tconst tool: AllowedTool = {\n\t\t\t\t\tname: t.name,\n\t\t\t\t\tdescription: t.description,\n\t\t\t\t\tdestructive: t.annotations.destructiveHint === true,\n\t\t\t\t};\n\t\t\t\tif (t.title !== undefined) tool.title = t.title;\n\t\t\t\treturn tool;\n\t\t\t});\n\n\treadonly list = (grantId: string): string[] =>\n\t\t(this.#read().get(grantId)?.tools ?? [])\n\t\t\t.filter((t) => counts(t, this.#registry.get(t.name)))\n\t\t\t.map((t) => t.name);\n\n\treadonly has = (grantId: string, name: string): boolean => {\n\t\tconst tool = this.#registry.get(name);\n\t\treturn (\n\t\t\tthis.everything(grantId) ||\n\t\t\t(tool !== undefined && this.allows(grantId, tool))\n\t\t);\n\t};\n\n\t/**\n\t * Whether this call runs without asking: \"everything\", or this tool as\n\t * the user saw it. Only reads: a tool that changed since asks, and leaves\n\t * the list when the registry or another tab's change is seen\n\t * (`toolsChanged`).\n\t */\n\tallows(grantId: string, tool: ToolNow): boolean {\n\t\tconst entry = this.#read().get(grantId);\n\t\tif (entry === undefined) return false;\n\t\tif (entry.everything) return true;\n\t\tconst kept = entry.tools.find((t) => t.name === tool.name);\n\t\treturn kept !== undefined && sameSeen(kept, tool);\n\t}\n\n\treadonly allow = (grantId: string, name: string): void => {\n\t\tconst tool = this.tools().find((t) => t.name === name);\n\t\tif (tool !== undefined) this.keep(grantId, tool);\n\t};\n\n\t/** Allow `tool` as the user saw it, for an app the relay still lists. */\n\tkeep(grantId: string, tool: ToolSeen): void {\n\t\tif (!this.#granted(grantId)) return;\n\t\tconst grants = this.#read();\n\t\tconst entry = grants.get(grantId) ?? { everything: false, tools: [] };\n\t\tentry.tools = [\n\t\t\t...entry.tools.filter((t) => t.name !== tool.name),\n\t\t\tseenOf(tool),\n\t\t];\n\t\tgrants.set(grantId, entry);\n\t\tthis.#write(grants);\n\t}\n\n\treadonly ask = (grantId: string, name: string): void => {\n\t\tconst grants = this.#read();\n\t\tconst entry = grants.get(grantId);\n\t\tif (entry === undefined) return;\n\t\tconst tools = entry.tools.filter((t) => t.name !== name);\n\t\t// Under \"everything\" this tool ran without asking too: asking again\n\t\t// for it turns that off; the tools allowed one by one stay.\n\t\tif (!entry.everything && tools.length === entry.tools.length) return;\n\t\tentry.everything = false;\n\t\tentry.tools = tools;\n\t\tif (tools.length === 0) grants.delete(grantId);\n\t\tthis.#write(grants);\n\t};\n\n\treadonly everything = (grantId: string): boolean =>\n\t\tthis.#read().get(grantId)?.everything === true;\n\n\treadonly setEverything = (grantId: string, on: boolean): void => {\n\t\tif (on && !this.#granted(grantId)) return;\n\t\tconst grants = this.#read();\n\t\tconst entry = grants.get(grantId) ?? { everything: false, tools: [] };\n\t\tif (entry.everything === on) return;\n\t\tentry.everything = on;\n\t\tif (on || entry.tools.length > 0) grants.set(grantId, entry);\n\t\telse grants.delete(grantId);\n\t\tthis.#write(grants);\n\t};\n\n\treadonly forget = (grantId: string): void => {\n\t\tconst grants = this.#read();\n\t\tif (grants.delete(grantId)) this.#write(grants);\n\t};\n\n\t/**\n\t * Only the grants the relay lists now: the others ended. What was kept\n\t * under another secret is dropped from storage too (it allowed nothing\n\t * already).\n\t */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tconst grants = this.#read();\n\t\t// Kept under another secret: nothing to write unless something was kept.\n\t\tlet changed =\n\t\t\tthis.#memory.grants !== grants && this.#memory.grants.size > 0;\n\t\tfor (const grantId of [...grants.keys()])\n\t\t\tif (!keep.has(grantId)) changed = grants.delete(grantId) || changed;\n\t\tif (changed) this.#write(grants);\n\t}\n\n\t/**\n\t * The registry changed, or another tab changed the allowances: a tool\n\t * registered with another title or description than the user saw leaves\n\t * every list. One that is not registered stays (a reload registers them\n\t * all again, a page may offer some only on some views). Tells the\n\t * listeners in any case.\n\t */\n\ttoolsChanged(): void {\n\t\tconst grants = this.#read();\n\t\tlet changed = false;\n\t\tfor (const [grantId, entry] of [...grants]) {\n\t\t\tconst tools = entry.tools.filter((t) =>\n\t\t\t\tcounts(t, this.#registry.get(t.name)),\n\t\t\t);\n\t\t\tif (tools.length === entry.tools.length) continue;\n\t\t\tchanged = true;\n\t\t\tentry.tools = tools;\n\t\t\tif (!entry.everything && tools.length === 0) grants.delete(grantId);\n\t\t}\n\t\tif (changed) this.#write(grants);\n\t\telse this.#changed();\n\t}\n\n\treadonly onChange = (listener: () => void): (() => void) => {\n\t\tthis.#listeners.add(listener);\n\t\tthis.#watch();\n\t\treturn () => {\n\t\t\tthis.#listeners.delete(listener);\n\t\t\tif (this.#listeners.size === 0) {\n\t\t\t\tthis.#unwatch?.();\n\t\t\t\tthis.#unwatch = undefined;\n\t\t\t}\n\t\t};\n\t};\n\n\t/**\n\t * Another tab changed them: clean up against this page's tools and tell\n\t * the listeners (only while there are some).\n\t */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined || this.#storage === null) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst changed = (event: Event) => {\n\t\t\tif ((event as StorageEvent).key === this.#key) this.toolsChanged();\n\t\t};\n\t\tg.addEventListener?.(\"storage\", changed);\n\t\tthis.#unwatch = () => g.removeEventListener?.(\"storage\", changed);\n\t}\n\n\t#granted(grantId: string): boolean {\n\t\treturn this.#mcp.grants.some((g) => g.grantId === grantId);\n\t}\n\n\t/**\n\t * The allowances now: storage first, so that another tab's change counts;\n\t * memory where storage cannot be read or the last write to it failed.\n\t * None once the secret changed.\n\t */\n\t#read(): Map<string, Entry> {\n\t\tif (this.#storage !== null && !this.#unsaved) {\n\t\t\ttry {\n\t\t\t\tconst text = this.#storage.getItem(this.#key);\n\t\t\t\tif (text !== null) this.#memory = parse(text);\n\t\t\t} catch {\n\t\t\t\t// unreadable: what this page kept in memory\n\t\t\t}\n\t\t}\n\t\treturn this.#memory.secret === this.#secret()\n\t\t\t? this.#memory.grants\n\t\t\t: new Map();\n\t}\n\n\t#write(grants: Map<string, Entry>): void {\n\t\tthis.#memory = { secret: this.#secret(), grants };\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, serialize(this.#memory));\n\t\t\tthis.#unsaved = false;\n\t\t} catch {\n\t\t\t// quota or blocked: kept in memory for the page's lifetime\n\t\t\tthis.#unsaved = true;\n\t\t}\n\t\tthis.#changed();\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n\n/** The allowances per `TabMcp`. */\nconst allowances = new WeakMap<TabMcp, Allowances>();\n\n/**\n * The allowances of `mcp`, made on first use. They follow its grants (only\n * when the relay names them, see above) and its tools.\n */\nexport function allowedFor(mcp: TabMcp): Allowances {\n\tconst kept = allowances.get(mcp);\n\tif (kept !== undefined) return kept;\n\tconst made = new Allowances(mcp);\n\tallowances.set(mcp, made);\n\tmcp.addEventListener(\"grantschange\", (e) =>\n\t\tmade.keepGrants(e.detail.grants.map((g) => g.grantId)),\n\t);\n\tmcp._allowed[0].onChange(() => made.toolsChanged());\n\tmade.toolsChanged(); // tools may have changed since the last page kept them\n\t// Made while connected: the grants are the relay's, the others ended.\n\tif (mc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