@ractive-ch/tab-mcp-client 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui-168746sb.js ADDED
@@ -0,0 +1,233 @@
1
+ // src/ui.ts
2
+ var counter = 0;
3
+ function el(doc, tag, props = {}, ...children) {
4
+ const node = doc.createElement(tag);
5
+ if (props.className !== undefined)
6
+ node.className = props.className;
7
+ if (props.id !== undefined)
8
+ node.id = props.id;
9
+ if (props.text !== undefined)
10
+ node.textContent = props.text;
11
+ node.append(...children);
12
+ return node;
13
+ }
14
+ function button(doc, text, onClick) {
15
+ const node = el(doc, "button", { text });
16
+ node.type = "button";
17
+ node.addEventListener("click", onClick);
18
+ return node;
19
+ }
20
+ function newDialog(doc, className, title) {
21
+ const id = `tab-mcp-${++counter}`;
22
+ const dialog = el(doc, "dialog", {
23
+ className: `tab-mcp-dialog ${className}`
24
+ });
25
+ dialog.setAttribute("aria-labelledby", `${id}-title`);
26
+ const style = dialog.style;
27
+ style.setProperty("max-width", "var(--tab-mcp-max-width, 34rem)");
28
+ style.setProperty("font", "var(--tab-mcp-font, inherit)");
29
+ style.setProperty("color", "var(--tab-mcp-color, CanvasText)");
30
+ style.setProperty("background", "var(--tab-mcp-background, Canvas)");
31
+ style.setProperty("border", "var(--tab-mcp-border, 1px solid GrayText)");
32
+ style.setProperty("border-radius", "var(--tab-mcp-radius, 0.5rem)");
33
+ style.setProperty("padding", "var(--tab-mcp-padding, 1rem 1.25rem)");
34
+ const heading = el(doc, "h2", { id: `${id}-title`, text: title });
35
+ heading.style.setProperty("margin-top", "0");
36
+ heading.style.setProperty("font-size", "var(--tab-mcp-title-size, 1.25em)");
37
+ dialog.append(heading);
38
+ return { dialog, heading };
39
+ }
40
+ function clientLabel(client) {
41
+ const host = client.host || client.id;
42
+ return client.name !== undefined && client.name !== "" ? `${client.name} (${host})` : host;
43
+ }
44
+ function showArguments(args) {
45
+ try {
46
+ return JSON.stringify(args, null, 2);
47
+ } catch {
48
+ return;
49
+ }
50
+ }
51
+ var ALLOW_DELAY_MS = 750;
52
+ var MIN_ALLOW_DELAY_MS = 500;
53
+ function confirmDialog(request, doc, options = {}) {
54
+ const delay = Math.max(MIN_ALLOW_DELAY_MS, options.allowDelayMs ?? ALLOW_DELAY_MS);
55
+ if (request.signal.aborted)
56
+ return Promise.resolve(false);
57
+ const title = request.tool.title ?? request.tool.name;
58
+ const { dialog } = newDialog(doc, "tab-mcp-confirm", `Allow ${title}?`);
59
+ const deny = button(doc, "Don't allow", () => dialog.close("deny"));
60
+ const allow = button(doc, "Allow", () => {
61
+ if (!allow.disabled)
62
+ dialog.close("allow");
63
+ });
64
+ allow.disabled = true;
65
+ const actions = el(doc, "div", { className: "tab-mcp-actions" }, deny, " ", allow);
66
+ const shown = showArguments(request.arguments);
67
+ const args = el(doc, "pre", {
68
+ className: "tab-mcp-arguments",
69
+ text: shown ?? "The arguments cannot be shown, so this call cannot be allowed."
70
+ });
71
+ if (shown === undefined)
72
+ allow.hidden = true;
73
+ args.style.setProperty("white-space", "pre-wrap");
74
+ args.style.setProperty("max-height", "12rem");
75
+ args.style.setProperty("overflow", "auto");
76
+ args.hidden = Object.keys(request.arguments).length === 0;
77
+ dialog.append(el(doc, "p", {
78
+ text: `${clientLabel(request.client)} wants to run ${title}.`
79
+ }), el(doc, "p", {
80
+ className: "tab-mcp-description",
81
+ text: request.tool.description
82
+ }), args, actions);
83
+ doc.body.append(dialog);
84
+ return new Promise((resolve) => {
85
+ const onAbort = () => dialog.close("deny");
86
+ request.signal.addEventListener("abort", onAbort, { once: true });
87
+ let timer;
88
+ dialog.addEventListener("close", () => {
89
+ clearTimeout(timer);
90
+ request.signal.removeEventListener("abort", onAbort);
91
+ const allowed = dialog.returnValue === "allow";
92
+ dialog.remove();
93
+ resolve(allowed);
94
+ }, { once: true });
95
+ dialog.showModal();
96
+ deny.focus();
97
+ timer = setTimeout(() => {
98
+ allow.disabled = false;
99
+ }, delay);
100
+ });
101
+ }
102
+ var INSTRUCTIONS = [
103
+ [
104
+ "Claude (claude.ai and the desktop app)",
105
+ "Settings → Connectors → Add custom connector, then paste the address."
106
+ ],
107
+ [
108
+ "ChatGPT",
109
+ "Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."
110
+ ],
111
+ ["Claude Code", "Run: claude mcp add --transport http tools ADDRESS"]
112
+ ];
113
+ function showConnectDialog(mcp, connecting, doc) {
114
+ const { dialog } = newDialog(doc, "tab-mcp-connect", "Connect your AI tool");
115
+ const status = el(doc, "p", {
116
+ className: "tab-mcp-status",
117
+ text: "Connecting…"
118
+ });
119
+ status.setAttribute("role", "status");
120
+ const addressId = `tab-mcp-${++counter}-address`;
121
+ const label = el(doc, "label", { text: "Add this address to your AI tool:" });
122
+ label.htmlFor = addressId;
123
+ const address = el(doc, "input", {
124
+ id: addressId,
125
+ className: "tab-mcp-address-input"
126
+ });
127
+ address.readOnly = true;
128
+ address.style.setProperty("width", "100%");
129
+ address.style.setProperty("font-family", "var(--tab-mcp-mono, monospace)");
130
+ const copy = button(doc, "Copy", () => {
131
+ const done = () => {
132
+ copy.textContent = "Copied";
133
+ };
134
+ const clipboard = doc.defaultView?.navigator?.clipboard;
135
+ if (clipboard !== undefined)
136
+ clipboard.writeText(address.value).then(done, () => address.select());
137
+ else
138
+ address.select();
139
+ });
140
+ const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy);
141
+ const code = el(doc, "strong", { className: "tab-mcp-code-value" });
142
+ code.style.setProperty("font-size", "var(--tab-mcp-code-size, 1.5em)");
143
+ code.style.setProperty("letter-spacing", "0.1em");
144
+ const codeLine = el(doc, "p", { className: "tab-mcp-code" }, "When asked, enter the code ", code);
145
+ codeLine.setAttribute("aria-live", "polite");
146
+ const steps = el(doc, "ul");
147
+ const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: "How do I add it?" }), steps);
148
+ const appList = el(doc, "ul");
149
+ const apps = el(doc, "div", { className: "tab-mcp-apps" }, el(doc, "h3", { text: "Connected" }), appList);
150
+ const close = button(doc, "Close", () => dialog.close());
151
+ const actions = el(doc, "div", { className: "tab-mcp-actions" }, close);
152
+ dialog.append(status, addressBox, codeLine, help, apps, actions);
153
+ addressBox.hidden = true;
154
+ codeLine.hidden = true;
155
+ help.hidden = true;
156
+ apps.hidden = true;
157
+ const renderSession = (session) => {
158
+ if (session === undefined) {
159
+ addressBox.hidden = true;
160
+ help.hidden = true;
161
+ return;
162
+ }
163
+ address.value = session.address;
164
+ const appName = session.appName ?? mcp.appName;
165
+ status.textContent = appName !== undefined ? `${appName} is ready for your AI tool.` : "This page is ready for your AI tool.";
166
+ addressBox.hidden = false;
167
+ help.hidden = false;
168
+ steps.replaceChildren(...INSTRUCTIONS.map(([app, how]) => el(doc, "li", {}, el(doc, "strong", { text: app }), `: ${how.replace("ADDRESS", session.address)}`)));
169
+ };
170
+ const renderCode = () => {
171
+ const current = mcp.pairingCode;
172
+ code.textContent = current?.code ?? "";
173
+ codeLine.hidden = current === undefined;
174
+ };
175
+ const appsNote = el(doc, "p", { className: "tab-mcp-apps-note" });
176
+ apps.append(appsNote);
177
+ const renderGrants = () => {
178
+ const connected = mcp.state === "connected";
179
+ appList.replaceChildren(...mcp.grants.map((grant) => {
180
+ const disconnect = button(doc, "Disconnect", () => {
181
+ if (!mcp.revoke(grant.grantId))
182
+ renderGrants();
183
+ });
184
+ disconnect.disabled = !connected;
185
+ return el(doc, "li", {}, `${clientLabel(grant.client)} connected `, disconnect);
186
+ }));
187
+ appsNote.textContent = connected ? "" : "To disconnect an app, connect this page again first.";
188
+ appsNote.hidden = connected;
189
+ apps.hidden = mcp.grants.length === 0;
190
+ };
191
+ const onDisconnected = () => {
192
+ status.textContent = "Disconnected. AI tools can use this page again after you connect.";
193
+ renderSession(undefined);
194
+ renderGrants();
195
+ renderCode();
196
+ };
197
+ const onConnected = () => {
198
+ renderSession(mcp.session);
199
+ renderGrants();
200
+ };
201
+ mcp.addEventListener("pairingcode", renderCode);
202
+ mcp.addEventListener("grantschange", renderGrants);
203
+ mcp.addEventListener("connected", onConnected);
204
+ mcp.addEventListener("disconnected", onDisconnected);
205
+ doc.body.append(dialog);
206
+ mcp.startPairing();
207
+ renderGrants();
208
+ renderCode();
209
+ renderSession(mcp.session);
210
+ connecting.then((session) => renderSession(session), (error) => {
211
+ status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;
212
+ });
213
+ return new Promise((resolve) => {
214
+ dialog.addEventListener("close", () => {
215
+ mcp.stopPairing();
216
+ mcp.removeEventListener("pairingcode", renderCode);
217
+ mcp.removeEventListener("grantschange", renderGrants);
218
+ mcp.removeEventListener("connected", onConnected);
219
+ mcp.removeEventListener("disconnected", onDisconnected);
220
+ dialog.remove();
221
+ resolve();
222
+ }, { once: true });
223
+ dialog.showModal();
224
+ close.focus();
225
+ });
226
+ }
227
+ export {
228
+ confirmDialog,
229
+ showConnectDialog
230
+ };
231
+
232
+ //# debugId=8469CA3E90C836D064756E2164756E21
233
+ //# sourceMappingURL=ui-168746sb.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/ui.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The default UI, loaded on demand: the \"Connect your AI tool\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction 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\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn JSON.stringify(args, null, 2);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/**\n * Ask whether a consequential tool may run. Resolves `true` only for \"Allow\",\n * which stays disabled for `allowDelayMs` (default 750, at least 500) after\n * the dialog opens, so a click meant for the page cannot approve.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<boolean> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(false);\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tallow.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t);\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) allow.hidden = true;\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\n\t\t}),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t);\n\tdoc.body.append(dialog);\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst allowed = dialog.returnValue === \"allow\";\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(allowed);\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/**\n * The \"Connect your AI tool\" dialog: the address with a copy button, short\n * instructions, the pairing code while the relay sends one, and the connected\n * apps with Disconnect. Pairing is on while it is open.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI tool\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI tool:\" });\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\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\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\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\n\t);\n\tcodeLine.setAttribute(\"aria-live\", \"polite\");\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: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tstatus.textContent =\n\t\t\tappName !== undefined\n\t\t\t\t? `${appName} is ready for your AI tool.`\n\t\t\t\t: \"This page is ready for your AI tool.\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\tconst renderGrants = () => {\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t};\n\tconst onDisconnected = () => {\n\t\tstatus.textContent =\n\t\t\t\"Disconnected. AI tools can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\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\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\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\tclose.focus();\n\t});\n}\n"
6
+ ],
7
+ "mappings": ";AAgBA,IAAI,UAAU;AAEd,SAAS,EAAyC,CACjD,KACA,KACA,QAA4D,CAAC,MAC1D,UACwB;AAAA,EAC3B,MA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AA,MACpD,IAAI,oBAAoB,aAAa,WAAW;AAAA,MAChD,IAAI,oBAAoB,gBAAgB,cAAc;AAAA,MACtD,OAAO,OAAO;AAAA,MACd,QAAQ;AAAA,OAET,EAAE,MAAM,KAAK,CACd;AAAA,IACA,OAAO,UAAU;AAAA,IACjB,MAAM,MAAM;AAAA,GACZ;AAAA;",
8
+ "debugId": "8469CA3E90C836D064756E2164756E21",
9
+ "names": []
10
+ }
package/ui.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The default UI, loaded on demand: the "Connect your AI tool" dialog
3
+ * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`
4
+ * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all
5
+ * text set with `textContent`. Pages with their own UI use the events and
6
+ * methods of `TabMcp` instead.
7
+ */
8
+ import type { TabMcp } from "./tab-mcp.js";
9
+ import type { ConfirmRequest, SessionInfo } from "./types.js";
10
+ /** How long "Allow" stays disabled after the confirmation opens, and the floor. */
11
+ export declare const ALLOW_DELAY_MS = 750;
12
+ export declare const MIN_ALLOW_DELAY_MS = 500;
13
+ /**
14
+ * Ask whether a consequential tool may run. Resolves `true` only for "Allow",
15
+ * which stays disabled for `allowDelayMs` (default 750, at least 500) after
16
+ * the dialog opens, so a click meant for the page cannot approve.
17
+ */
18
+ export declare function confirmDialog(request: ConfirmRequest, doc: Document, options?: {
19
+ allowDelayMs?: number;
20
+ }): Promise<boolean>;
21
+ /**
22
+ * The "Connect your AI tool" dialog: the address with a copy button, short
23
+ * instructions, the pairing code while the relay sends one, and the connected
24
+ * apps with Disconnect. Pairing is on while it is open.
25
+ */
26
+ export declare function showConnectDialog(mcp: TabMcp, connecting: Promise<SessionInfo>, doc: Document): Promise<void>;
package/version.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */
2
+ export declare const LIBRARY_NAME = "@ractive-ch/tab-mcp-client";
3
+ export declare const VERSION = "0.1.0-alpha.0";