@ractive-ch/tab-mcp-client 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +454 -147
  2. package/always-allowed.d.ts +25 -6
  3. package/cdn/confirm-y30cx7e1.min.js +4 -0
  4. package/cdn/confirm-y30cx7e1.min.js.map +10 -0
  5. package/cdn/connect-bbhj2y7w.min.js +6 -0
  6. package/cdn/connect-bbhj2y7w.min.js.map +12 -0
  7. package/cdn/connection-0y7ngtq7.min.js +17 -0
  8. package/cdn/connection-0y7ngtq7.min.js.map +22 -0
  9. package/cdn/index-vt5zk9me.min.js +91 -0
  10. package/cdn/index-vt5zk9me.min.js.map +13 -0
  11. package/cdn/tab-mcp-client.min.js +3 -3
  12. package/cdn/tab-mcp-client.min.js.map +6 -6
  13. package/confirm-fgnjgd08.js +263 -0
  14. package/confirm-fgnjgd08.js.map +10 -0
  15. package/confirm.d.ts +54 -0
  16. package/connect-8jpb0k29.js +484 -0
  17. package/connect-8jpb0k29.js.map +10 -0
  18. package/connect.d.ts +40 -0
  19. package/{connection-g6wk37yd.js → connection-1d8rxgbq.js} +247 -126
  20. package/connection-1d8rxgbq.js.map +16 -0
  21. package/connection.d.ts +7 -4
  22. package/dialog.d.ts +83 -0
  23. package/{index-nmn1j689.js → index-5jyqehpk.js} +14 -10
  24. package/index-5jyqehpk.js.map +11 -0
  25. package/index-jnz7w9xa.js +392 -0
  26. package/index-jnz7w9xa.js.map +12 -0
  27. package/index.d.ts +1 -1
  28. package/index.js +257 -240
  29. package/index.js.map +6 -6
  30. package/mapping.d.ts +37 -4
  31. package/mcp.d.ts +23 -8
  32. package/package.json +1 -1
  33. package/react.d.ts +8 -10
  34. package/react.js +18 -14
  35. package/react.js.map +3 -3
  36. package/registry.d.ts +12 -5
  37. package/secret.d.ts +5 -2
  38. package/serve.d.ts +26 -4
  39. package/setup.d.ts +15 -25
  40. package/setup.js +1 -1
  41. package/strings.d.ts +107 -0
  42. package/tab-mcp.d.ts +60 -35
  43. package/types.d.ts +146 -68
  44. package/webmcp.d.ts +13 -18
  45. package/cdn/connection-hgt931xk.min.js +0 -12
  46. package/cdn/connection-hgt931xk.min.js.map +0 -22
  47. package/cdn/ui-2nv84ry7.min.js +0 -86
  48. package/cdn/ui-2nv84ry7.min.js.map +0 -14
  49. package/connection-g6wk37yd.js.map +0 -16
  50. package/index-nmn1j689.js.map +0 -11
  51. package/ui-04mwfxm9.js +0 -783
  52. package/ui-04mwfxm9.js.map +0 -11
  53. package/ui.d.ts +0 -83
package/react.js CHANGED
@@ -18,7 +18,6 @@ import {
18
18
  var EMPTY = Object.freeze([]);
19
19
  var SERVER_SNAPSHOT = Object.freeze({
20
20
  state: "disconnected",
21
- address: undefined,
22
21
  session: undefined,
23
22
  grants: EMPTY,
24
23
  pairingCode: undefined,
@@ -29,12 +28,9 @@ var SERVER_SNAPSHOT = Object.freeze({
29
28
  });
30
29
  var STATE_EVENTS = [
31
30
  "statechange",
32
- "connected",
33
- "disconnected",
34
31
  "grantschange",
35
32
  "pairingcode",
36
33
  "identitychange",
37
- "reconnecting",
38
34
  "toolschange"
39
35
  ];
40
36
 
@@ -66,7 +62,6 @@ class Store {
66
62
  const tools = mcp.tools;
67
63
  const next = {
68
64
  state: mcp.state,
69
- address: mcp.address,
70
65
  session: mcp.session,
71
66
  grants: mcp.grants,
72
67
  pairingCode: mcp.pairingCode,
@@ -125,6 +120,7 @@ function TabMcpProvider(props) {
125
120
  setState(current);
126
121
  const mcp = props.client ?? current.mcp;
127
122
  const previous = useRef(undefined);
123
+ const active = useRef(undefined);
128
124
  useEffect(() => {
129
125
  if (previous.current !== undefined && previous.current !== mcp && props.client === undefined) {
130
126
  console.warn("TabMcpProvider: relay or server.name changed, so the page has a new TabMcp; its tools and connection start over");
@@ -132,7 +128,14 @@ function TabMcpProvider(props) {
132
128
  previous.current = mcp;
133
129
  if (props.client !== undefined)
134
130
  return;
135
- return () => mcp.disconnect();
131
+ active.current = mcp;
132
+ return () => {
133
+ active.current = undefined;
134
+ queueMicrotask(() => {
135
+ if (active.current !== mcp)
136
+ mcp.disconnect();
137
+ });
138
+ };
136
139
  }, [mcp, props.client]);
137
140
  return createElement(Context.Provider, { value: mcp }, props.children);
138
141
  }
@@ -146,7 +149,7 @@ function useTabMcpState() {
146
149
  const store = storeOf(useTabMcp());
147
150
  return useSyncExternalStore(store.subscribe, store.getSnapshot, () => SERVER_SNAPSHOT);
148
151
  }
149
- function useTool(tool, deps = EMPTY, options = {}) {
152
+ function useTool(tool, options = {}) {
150
153
  const mcp = useTabMcp();
151
154
  const latest = useRef(tool);
152
155
  useInsertionEffect(() => {
@@ -160,8 +163,10 @@ function useTool(tool, deps = EMPTY, options = {}) {
160
163
  tool.title,
161
164
  tool.description,
162
165
  tool.inputSchema,
166
+ tool.outputSchema,
163
167
  tool.annotations,
164
- options.webmcp
168
+ options.callers,
169
+ options.exposedTo
165
170
  ]);
166
171
  useEffect(() => {
167
172
  const controller = new AbortController;
@@ -174,7 +179,7 @@ function useTool(tool, deps = EMPTY, options = {}) {
174
179
  setFailure({ error });
175
180
  });
176
181
  return () => controller.abort();
177
- }, [mcp, shape, ...deps]);
182
+ }, [mcp, shape]);
178
183
  }
179
184
  function useToolCalls(options = {}) {
180
185
  const mcp = useTabMcp();
@@ -203,8 +208,8 @@ var LOST_AFTER_ATTEMPTS = 3;
203
208
  function connectLabel(state) {
204
209
  if (state.state === "connected" && state.grants.length > 0)
205
210
  return state.grants.length === 1 ? "AI app connected" : `${state.grants.length} AI apps connected`;
206
- if (state.reconnecting !== undefined)
207
- return state.reconnecting.attempt > LOST_AFTER_ATTEMPTS ? "Connection lost, retrying…" : "Reconnecting…";
211
+ if (state.state === "reconnecting")
212
+ return (state.reconnecting?.attempt ?? 0) > LOST_AFTER_ATTEMPTS ? "Connection lost, retrying…" : "Reconnecting…";
208
213
  if (state.state === "connecting")
209
214
  return "Connecting…";
210
215
  return "Connect your AI app";
@@ -221,7 +226,7 @@ function ConnectButton({
221
226
  const label = children === undefined ? connectLabel(state) : typeof children === "function" ? children(state) : children;
222
227
  return createElement("button", {
223
228
  type: "button",
224
- "data-state": state.reconnecting !== undefined && state.state !== "connected" ? "reconnecting" : state.state,
229
+ "data-state": state.state,
225
230
  ...rest,
226
231
  onClick: (event) => {
227
232
  onClick?.(event);
@@ -236,12 +241,11 @@ function ConnectButton({
236
241
  export {
237
242
  ConnectButton,
238
243
  TabMcpProvider,
239
- connectLabel,
240
244
  useTabMcp,
241
245
  useTabMcpState,
242
246
  useTool,
243
247
  useToolCalls
244
248
  };
245
249
 
246
- //# debugId=D001B4C5A0DFFD1364756E2164756E21
250
+ //# debugId=5D06ACF2F7BEF98464756E2164756E21
247
251
  //# sourceMappingURL=react.js.map
package/react.js.map CHANGED
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/react.ts"],
4
4
  "sourcesContent": [
5
- "\"use client\";\n/**\n * `@ractive-ch/tab-mcp-client/react`: React bindings for single-page apps\n * (iteration 9). One `TabMcp` per `<TabMcpProvider>`, hooks for its state,\n * its tools and the calls of AI apps, and a button that opens the connect\n * dialog. `react` (18.3 or 19) is an optional peer dependency; the core\n * entry stays free of it.\n */\n\nimport {\n\ttype ButtonHTMLAttributes,\n\tcreateContext,\n\tcreateElement,\n\ttype DependencyList,\n\ttype MouseEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseInsertionEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport {\n\ttype ConfirmRequest,\n\ttype ConnectionState,\n\ttype Grant,\n\ttype IdentityAssertionRequest,\n\ttype IdentityState,\n\ttype PairingCode,\n\ttype ReconnectingInfo,\n\ttype RegisterToolOptions,\n\ttype SessionInfo,\n\tTabMcp,\n\ttype TabMcpEventMap,\n\ttype TabMcpOptions,\n\ttype Tool,\n\ttype ToolCallEnd,\n\ttype ToolCallStart,\n} from \"./index.ts\";\n\n/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */\nexport interface TabMcpSnapshot {\n\tstate: ConnectionState;\n\t/** The MCP address to give to AI apps, while connected. */\n\taddress: string | undefined;\n\tsession: SessionInfo | undefined;\n\t/** The AI apps connected to this address. */\n\tgrants: readonly Grant[];\n\t/** The pairing code to show, while the connect dialog is open. */\n\tpairingCode: PairingCode | undefined;\n\t/** Who the relay knows as the page's user (identity binding). */\n\tidentity: IdentityState;\n\t/** Why the relay refused the identity (`identity: \"refused\"`). */\n\tidentityMessage: string | undefined;\n\t/** While the library connects again by itself after the connection broke. */\n\treconnecting: ReconnectingInfo | undefined;\n\t/** Names of the registered tools. */\n\ttools: readonly string[];\n}\n\nconst EMPTY: readonly never[] = Object.freeze([]);\n\n/** What the server renders, and what hydration starts from. */\nconst SERVER_SNAPSHOT: TabMcpSnapshot = Object.freeze({\n\tstate: \"disconnected\",\n\taddress: undefined,\n\tsession: undefined,\n\tgrants: EMPTY,\n\tpairingCode: undefined,\n\tidentity: \"none\",\n\tidentityMessage: undefined,\n\treconnecting: undefined,\n\ttools: EMPTY,\n});\n\nconst STATE_EVENTS = [\n\t\"statechange\",\n\t\"connected\",\n\t\"disconnected\",\n\t\"grantschange\",\n\t\"pairingcode\",\n\t\"identitychange\",\n\t\"reconnecting\",\n\t\"toolschange\",\n] as const satisfies readonly (keyof TabMcpEventMap)[];\n\n/** The external store of one `TabMcp`: a snapshot that changes only with the instance. */\nclass Store {\n\treadonly #mcp: TabMcp;\n\treadonly #listeners = new Set<() => void>();\n\t#snapshot: TabMcpSnapshot;\n\n\tconstructor(mcp: TabMcp) {\n\t\tthis.#mcp = mcp;\n\t\tthis.#snapshot = this.#read(SERVER_SNAPSHOT);\n\t\tconst update = () => {\n\t\t\tconst next = this.#read(this.#snapshot);\n\t\t\tif (next === this.#snapshot) return;\n\t\t\tthis.#snapshot = next;\n\t\t\tfor (const listener of [...this.#listeners]) listener();\n\t\t};\n\t\tfor (const type of STATE_EVENTS) mcp.addEventListener(type, update);\n\t}\n\n\treadonly subscribe = (listener: () => void): (() => void) => {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t};\n\n\treadonly getSnapshot = (): TabMcpSnapshot => this.#snapshot;\n\n\t/** The current values; `previous` itself when none changed. */\n\t#read(previous: TabMcpSnapshot): TabMcpSnapshot {\n\t\tconst mcp = this.#mcp;\n\t\tconst tools = mcp.tools;\n\t\tconst next: TabMcpSnapshot = {\n\t\t\tstate: mcp.state,\n\t\t\taddress: mcp.address,\n\t\t\tsession: mcp.session,\n\t\t\tgrants: mcp.grants,\n\t\t\tpairingCode: mcp.pairingCode,\n\t\t\tidentity: mcp.identity,\n\t\t\tidentityMessage: mcp.identityMessage,\n\t\t\treconnecting: mcp.reconnecting,\n\t\t\ttools:\n\t\t\t\ttools.length === previous.tools.length &&\n\t\t\t\ttools.every((t, i) => t === previous.tools[i])\n\t\t\t\t\t? previous.tools\n\t\t\t\t\t: tools,\n\t\t};\n\t\tconst same = (Object.keys(next) as (keyof TabMcpSnapshot)[]).every(\n\t\t\t(key) => next[key] === previous[key],\n\t\t);\n\t\treturn same ? previous : next;\n\t}\n}\n\nconst stores = new WeakMap<TabMcp, Store>();\n\nfunction storeOf(mcp: TabMcp): Store {\n\tlet store = stores.get(mcp);\n\tif (store === undefined) {\n\t\tstore = new Store(mcp);\n\t\tstores.set(mcp, store);\n\t}\n\treturn store;\n}\n\nconst Context = createContext<TabMcp | undefined>(undefined);\n\n/** Props of `TabMcpProvider`: the `TabMcp` options, or an instance of your own. */\nexport type TabMcpProviderProps = (\n\t| (TabMcpOptions & { client?: undefined })\n\t| { client: TabMcp }\n) & { children?: ReactNode };\n\n/**\n * Makes one `TabMcp` for its tree from the props of its first render\n * (`relay` may be left out, as for `TabMcp`). A\n * changed `relay` or `server.name` makes a new instance (and warns); other\n * changes are ignored, but `onConfirm` and `identityAssertion` are always\n * the latest ones (also when added or removed later). Pass `client` to use an instance of your own instead. The\n * provider's own instance is disconnected when the provider unmounts; it\n * never connects on the server.\n */\nexport function TabMcpProvider(props: TabMcpProviderProps): ReactElement {\n\tconst latest = useRef(props);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = props;\n\t});\n\tconst own = props.client === undefined ? props : undefined;\n\tconst relay = own?.relay;\n\tconst serverName = own?.server?.name;\n\tconst create = (): TabMcp => {\n\t\tconst {\n\t\t\tchildren: _,\n\t\t\tclient: __,\n\t\t\t...options\n\t\t} = props as TabMcpOptions & {\n\t\t\tchildren?: ReactNode;\n\t\t\tclient?: undefined;\n\t\t};\n\t\t// Always installed, so that a handler added, changed or removed in a\n\t\t// later render counts: without one, the library's own behaviour.\n\t\tconst handlers = () => latest.current as Partial<TabMcpOptions>;\n\t\tconst instance: TabMcp = new TabMcp({\n\t\t\t...options,\n\t\t\tonConfirm: (request: ConfirmRequest) => {\n\t\t\t\tconst ask = handlers().onConfirm;\n\t\t\t\treturn ask === undefined\n\t\t\t\t\t? instance.confirmInPage(request)\n\t\t\t\t\t: ask(request);\n\t\t\t},\n\t\t\tidentityAssertion: (request: IdentityAssertionRequest) =>\n\t\t\t\thandlers().identityAssertion?.(request) ?? null,\n\t\t});\n\t\treturn instance;\n\t};\n\t// In state, not in `useMemo`, which React may discard and run again. A\n\t// changed relay or server name replaces it while rendering, as React\n\t// recommends for state that follows props.\n\tconst [state, setState] = useState(() =>\n\t\town === undefined ? undefined : { relay, serverName, mcp: create() },\n\t);\n\tlet current = state;\n\tif (own === undefined) {\n\t\tcurrent = undefined;\n\t} else if (\n\t\tcurrent === undefined ||\n\t\tcurrent.relay !== relay ||\n\t\tcurrent.serverName !== serverName\n\t) {\n\t\tcurrent = { relay, serverName, mcp: create() };\n\t}\n\tif (current !== state) setState(current);\n\tconst mcp = props.client ?? (current as { mcp: TabMcp }).mcp;\n\n\tconst previous = useRef<TabMcp | undefined>(undefined);\n\tuseEffect(() => {\n\t\tif (\n\t\t\tprevious.current !== undefined &&\n\t\t\tprevious.current !== mcp &&\n\t\t\tprops.client === undefined\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"TabMcpProvider: relay or server.name changed, so the page has a new TabMcp; its tools and connection start over\",\n\t\t\t);\n\t\t}\n\t\tprevious.current = mcp;\n\t\tif (props.client !== undefined) return;\n\t\treturn () => mcp.disconnect();\n\t}, [mcp, props.client]);\n\n\treturn createElement(Context.Provider, { value: mcp }, props.children);\n}\n\n/** The provider's `TabMcp`, for everything the hooks do not cover. */\nexport function useTabMcp(): TabMcp {\n\tconst mcp = useContext(Context);\n\tif (mcp === undefined)\n\t\tthrow new Error(\"useTabMcp: no <TabMcpProvider> above this component\");\n\treturn mcp;\n}\n\n/**\n * The connection state, address, grants, pairing code, identity and\n * reconnecting of the provider's `TabMcp`. Re-renders only when one of them\n * changes; the server and hydration see `disconnected`.\n */\nexport function useTabMcpState(): TabMcpSnapshot {\n\tconst store = storeOf(useTabMcp());\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getSnapshot,\n\t\t() => SERVER_SNAPSHOT,\n\t);\n}\n\n/** Options of `useTool`: `RegisterToolOptions` without the signal (the hook has its own). */\nexport type UseToolOptions = Omit<RegisterToolOptions, \"signal\">;\n\n/**\n * Registers a tool while the component is mounted (with an `AbortSignal`,\n * aborted on unmount). `execute` is always the latest one, so a new closure\n * on each render does not register again; the tool is registered again only\n * when its name, title, description, input schema or annotations change, or\n * `options.webmcp`, or one of `deps`. A duplicate name or an invalid tool is\n * thrown from the component's next render, for an error boundary.\n */\nexport function useTool<Input extends object = Record<string, unknown>>(\n\ttool: Tool<Input>,\n\tdeps: DependencyList = EMPTY,\n\toptions: UseToolOptions = {},\n): void {\n\tconst mcp = useTabMcp();\n\tconst latest = useRef(tool);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = tool;\n\t});\n\tconst [failure, setFailure] = useState<{ error: unknown } | undefined>();\n\tif (failure !== undefined) throw failure.error;\n\tconst shape = JSON.stringify([\n\t\ttool.name,\n\t\ttool.title,\n\t\ttool.description,\n\t\ttool.inputSchema,\n\t\ttool.annotations,\n\t\toptions.webmcp,\n\t]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: `shape` and `deps` stand for the tool and its options; `execute` is read through the ref\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\t\tconst { execute: _, ...fields } = latest.current;\n\t\tmcp\n\t\t\t.registerTool(\n\t\t\t\t{\n\t\t\t\t\t...fields,\n\t\t\t\t\texecute: (input: Input, options) =>\n\t\t\t\t\t\tlatest.current.execute(input, options),\n\t\t\t\t},\n\t\t\t\t{ ...options, signal: controller.signal },\n\t\t\t)\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (!controller.signal.aborted) setFailure({ error });\n\t\t\t});\n\t\treturn () => controller.abort();\n\t}, [mcp, shape, ...deps]);\n}\n\n/** A tool call of an AI app, as `useToolCalls()` lists it. */\nexport interface ToolCallRecord extends ToolCallStart {\n\t/** When it started, `Date.now()`. */\n\tstartedAt: number;\n\t/** How it ended; missing while it runs. */\n\tend?: ToolCallEnd;\n}\n\nexport interface UseToolCallsOptions {\n\t/** How many calls to keep; default 20. */\n\tlimit?: number;\n}\n\n/**\n * The recent tool calls of AI apps since the component mounted, newest\n * first, each with its end once it is over: for an activity view.\n */\nexport function useToolCalls(\n\toptions: UseToolCallsOptions = {},\n): readonly ToolCallRecord[] {\n\tconst mcp = useTabMcp();\n\tconst limit = Math.max(0, options.limit ?? 20);\n\tconst [calls, setCalls] = useState<readonly ToolCallRecord[]>(EMPTY);\n\tuseEffect(() => {\n\t\tconst started = (event: TabMcpEventMap[\"toolcall\"]) => {\n\t\t\tconst record: ToolCallRecord = { ...event.detail, startedAt: Date.now() };\n\t\t\tsetCalls((list) => [record, ...list].slice(0, limit));\n\t\t};\n\t\tconst ended = (event: TabMcpEventMap[\"toolcallend\"]) => {\n\t\t\tconst end = event.detail;\n\t\t\tsetCalls((list) =>\n\t\t\t\tlist.some((r) => r.id === end.id)\n\t\t\t\t\t? list.map((r) => (r.id === end.id ? { ...r, end } : r))\n\t\t\t\t\t: list,\n\t\t\t);\n\t\t};\n\t\tmcp.addEventListener(\"toolcall\", started);\n\t\tmcp.addEventListener(\"toolcallend\", ended);\n\t\tsetCalls((list) => (list.length > limit ? list.slice(0, limit) : list));\n\t\treturn () => {\n\t\t\tmcp.removeEventListener(\"toolcall\", started);\n\t\t\tmcp.removeEventListener(\"toolcallend\", ended);\n\t\t};\n\t}, [mcp, limit]);\n\treturn calls;\n}\n\n/** Props of `ConnectButton`: a button's, with `children` that may depend on the state. */\nexport interface ConnectButtonProps\n\textends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"type\"> {\n\t/** The label; default: the state (\"Connect your AI app\", \"AI app connected\"). */\n\tchildren?: ReactNode | ((state: TabMcpSnapshot) => ReactNode);\n}\n\n/** Failed reconnect attempts after which the default label says the connection is lost. */\nconst LOST_AFTER_ATTEMPTS = 3;\n\n/** The default label of `ConnectButton`. */\nexport function connectLabel(state: TabMcpSnapshot): string {\n\tif (state.state === \"connected\" && state.grants.length > 0)\n\t\treturn state.grants.length === 1\n\t\t\t? \"AI app connected\"\n\t\t\t: `${state.grants.length} AI apps connected`;\n\tif (state.reconnecting !== undefined)\n\t\treturn state.reconnecting.attempt > LOST_AFTER_ATTEMPTS\n\t\t\t? \"Connection lost, retrying…\"\n\t\t\t: \"Reconnecting…\";\n\tif (state.state === \"connecting\") return \"Connecting…\";\n\treturn \"Connect your AI app\";\n}\n\n/**\n * A button that opens the library's \"Connect your AI app\" dialog\n * (`showConnectDialog()`), labelled with the state. `data-state` is\n * `disconnected`, `connecting`, `connected` or `reconnecting`, for styling.\n * An `onClick` that calls `event.preventDefault()` keeps the dialog closed.\n * Renders nothing for a `TabMcp` without a relay: there is nothing to\n * connect.\n */\nexport function ConnectButton({\n\tchildren,\n\tonClick,\n\t...rest\n}: ConnectButtonProps): ReactElement | null {\n\tconst mcp = useTabMcp();\n\tconst state = useTabMcpState();\n\tif (!mcp.hasRelay) return null;\n\tconst label =\n\t\tchildren === undefined\n\t\t\t? connectLabel(state)\n\t\t\t: typeof children === \"function\"\n\t\t\t\t? children(state)\n\t\t\t\t: children;\n\treturn createElement(\n\t\t\"button\",\n\t\t{\n\t\t\ttype: \"button\",\n\t\t\t\"data-state\":\n\t\t\t\tstate.reconnecting !== undefined && state.state !== \"connected\"\n\t\t\t\t\t? \"reconnecting\"\n\t\t\t\t\t: state.state,\n\t\t\t...rest,\n\t\t\tonClick: (event: MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\t\t\t\tif (event.defaultPrevented) return;\n\t\t\t\tmcp.showConnectDialog().catch((error: unknown) => {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tlabel,\n\t);\n}\n"
5
+ "\"use client\";\n/**\n * `@ractive-ch/tab-mcp-client/react`: React bindings for single-page apps\n * (iteration 9). One `TabMcp` per `<TabMcpProvider>`, hooks for its state,\n * its tools and the calls of AI apps, and a button that opens the connect\n * dialog. `react` (18.3 or 19) is an optional peer dependency; the core\n * entry stays free of it.\n */\n\nimport {\n\ttype ButtonHTMLAttributes,\n\tcreateContext,\n\tcreateElement,\n\ttype MouseEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseInsertionEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport {\n\ttype ConfirmRequest,\n\ttype ConnectionState,\n\ttype Grant,\n\ttype IdentityAssertionRequest,\n\ttype IdentityState,\n\ttype PairingCode,\n\ttype ReconnectingInfo,\n\ttype RegisterToolOptions,\n\ttype SessionInfo,\n\tTabMcp,\n\ttype TabMcpEventMap,\n\ttype TabMcpOptions,\n\ttype Tool,\n\ttype ToolCallEnd,\n\ttype ToolCallStart,\n} from \"./index.ts\";\n\n/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */\nexport interface TabMcpSnapshot {\n\tstate: ConnectionState;\n\t/** The session while connected; `session.address` is the MCP address to give to AI apps. */\n\tsession: SessionInfo | undefined;\n\t/** The AI apps connected to this address. */\n\tgrants: readonly Grant[];\n\t/** The pairing code to show, while the connect dialog is open. */\n\tpairingCode: PairingCode | undefined;\n\t/** Who the relay knows as the page's user (identity binding). */\n\tidentity: IdentityState;\n\t/** Why the relay refused the identity (`identity: \"refused\"`). */\n\tidentityMessage: string | undefined;\n\t/** While `state` is `reconnecting`: the next attempt and when it starts. */\n\treconnecting: ReconnectingInfo | undefined;\n\t/** Names of the registered tools. */\n\ttools: readonly string[];\n}\n\nconst EMPTY: readonly never[] = Object.freeze([]);\n\n/** What the server renders, and what hydration starts from. */\nconst SERVER_SNAPSHOT: TabMcpSnapshot = Object.freeze({\n\tstate: \"disconnected\",\n\tsession: undefined,\n\tgrants: EMPTY,\n\tpairingCode: undefined,\n\tidentity: \"none\",\n\tidentityMessage: undefined,\n\treconnecting: undefined,\n\ttools: EMPTY,\n});\n\nconst STATE_EVENTS = [\n\t\"statechange\",\n\t\"grantschange\",\n\t\"pairingcode\",\n\t\"identitychange\",\n\t\"toolschange\",\n] as const satisfies readonly (keyof TabMcpEventMap)[];\n\n/** The external store of one `TabMcp`: a snapshot that changes only with the instance. */\nclass Store {\n\treadonly #mcp: TabMcp;\n\treadonly #listeners = new Set<() => void>();\n\t#snapshot: TabMcpSnapshot;\n\n\tconstructor(mcp: TabMcp) {\n\t\tthis.#mcp = mcp;\n\t\tthis.#snapshot = this.#read(SERVER_SNAPSHOT);\n\t\tconst update = () => {\n\t\t\tconst next = this.#read(this.#snapshot);\n\t\t\tif (next === this.#snapshot) return;\n\t\t\tthis.#snapshot = next;\n\t\t\tfor (const listener of [...this.#listeners]) listener();\n\t\t};\n\t\tfor (const type of STATE_EVENTS) mcp.addEventListener(type, update);\n\t}\n\n\treadonly subscribe = (listener: () => void): (() => void) => {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t};\n\n\treadonly getSnapshot = (): TabMcpSnapshot => this.#snapshot;\n\n\t/** The current values; `previous` itself when none changed. */\n\t#read(previous: TabMcpSnapshot): TabMcpSnapshot {\n\t\tconst mcp = this.#mcp;\n\t\tconst tools = mcp.tools;\n\t\tconst next: TabMcpSnapshot = {\n\t\t\tstate: mcp.state,\n\t\t\tsession: mcp.session,\n\t\t\tgrants: mcp.grants,\n\t\t\tpairingCode: mcp.pairingCode,\n\t\t\tidentity: mcp.identity,\n\t\t\tidentityMessage: mcp.identityMessage,\n\t\t\treconnecting: mcp.reconnecting,\n\t\t\ttools:\n\t\t\t\ttools.length === previous.tools.length &&\n\t\t\t\ttools.every((t, i) => t === previous.tools[i])\n\t\t\t\t\t? previous.tools\n\t\t\t\t\t: tools,\n\t\t};\n\t\tconst same = (Object.keys(next) as (keyof TabMcpSnapshot)[]).every(\n\t\t\t(key) => next[key] === previous[key],\n\t\t);\n\t\treturn same ? previous : next;\n\t}\n}\n\nconst stores = new WeakMap<TabMcp, Store>();\n\nfunction storeOf(mcp: TabMcp): Store {\n\tlet store = stores.get(mcp);\n\tif (store === undefined) {\n\t\tstore = new Store(mcp);\n\t\tstores.set(mcp, store);\n\t}\n\treturn store;\n}\n\nconst Context = createContext<TabMcp | undefined>(undefined);\n\n/** Props of `TabMcpProvider`: the `TabMcp` options, or an instance of your own. */\nexport type TabMcpProviderProps = (\n\t| (TabMcpOptions & { client?: undefined })\n\t| { client: TabMcp }\n) & { children?: ReactNode };\n\n/**\n * Makes one `TabMcp` for its tree from the props of its first render\n * (`relay` may be left out, as for `TabMcp`). A\n * changed `relay` or `server.name` makes a new instance (and warns); other\n * changes are ignored, but `onConfirm` and `identityAssertion` are always\n * the latest ones (also when added or removed later). Pass `client` to use an instance of your own instead. The\n * provider's own instance is disconnected when the provider unmounts; it\n * never connects on the server.\n */\nexport function TabMcpProvider(props: TabMcpProviderProps): ReactElement {\n\tconst latest = useRef(props);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = props;\n\t});\n\tconst own = props.client === undefined ? props : undefined;\n\tconst relay = own?.relay;\n\tconst serverName = own?.server?.name;\n\tconst create = (): TabMcp => {\n\t\tconst {\n\t\t\tchildren: _,\n\t\t\tclient: __,\n\t\t\t...options\n\t\t} = props as TabMcpOptions & {\n\t\t\tchildren?: ReactNode;\n\t\t\tclient?: undefined;\n\t\t};\n\t\t// Always installed, so that a handler added, changed or removed in a\n\t\t// later render counts: without one, the library's own behaviour.\n\t\tconst handlers = () => latest.current as Partial<TabMcpOptions>;\n\t\tconst instance: TabMcp = new TabMcp({\n\t\t\t...options,\n\t\t\tonConfirm: (request: ConfirmRequest) => {\n\t\t\t\tconst ask = handlers().onConfirm;\n\t\t\t\treturn ask === undefined\n\t\t\t\t\t? instance.confirmInPage(request)\n\t\t\t\t\t: ask(request);\n\t\t\t},\n\t\t\tidentityAssertion: (request: IdentityAssertionRequest) =>\n\t\t\t\thandlers().identityAssertion?.(request) ?? null,\n\t\t});\n\t\treturn instance;\n\t};\n\t// In state, not in `useMemo`, which React may discard and run again. A\n\t// changed relay or server name replaces it while rendering, as React\n\t// recommends for state that follows props.\n\tconst [state, setState] = useState(() =>\n\t\town === undefined ? undefined : { relay, serverName, mcp: create() },\n\t);\n\tlet current = state;\n\tif (own === undefined) {\n\t\tcurrent = undefined;\n\t} else if (\n\t\tcurrent === undefined ||\n\t\tcurrent.relay !== relay ||\n\t\tcurrent.serverName !== serverName\n\t) {\n\t\tcurrent = { relay, serverName, mcp: create() };\n\t}\n\tif (current !== state) setState(current);\n\tconst mcp = props.client ?? (current as { mcp: TabMcp }).mcp;\n\n\tconst previous = useRef<TabMcp | undefined>(undefined);\n\t/** The instance the mounted effect is for; `undefined` after its cleanup. */\n\tconst active = useRef<TabMcp | undefined>(undefined);\n\tuseEffect(() => {\n\t\tif (\n\t\t\tprevious.current !== undefined &&\n\t\t\tprevious.current !== mcp &&\n\t\t\tprops.client === undefined\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"TabMcpProvider: relay or server.name changed, so the page has a new TabMcp; its tools and connection start over\",\n\t\t\t);\n\t\t}\n\t\tprevious.current = mcp;\n\t\tif (props.client !== undefined) return;\n\t\tactive.current = mcp;\n\t\t// Disconnected a moment later, unless the effect ran again for the same\n\t\t// instance meanwhile: StrictMode's simulated unmount and mount would\n\t\t// otherwise cancel a `connect()` that a child's effect started (CU 24).\n\t\treturn () => {\n\t\t\tactive.current = undefined;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (active.current !== mcp) mcp.disconnect();\n\t\t\t});\n\t\t};\n\t}, [mcp, props.client]);\n\n\treturn createElement(Context.Provider, { value: mcp }, props.children);\n}\n\n/** The provider's `TabMcp`, for everything the hooks do not cover. */\nexport function useTabMcp(): TabMcp {\n\tconst mcp = useContext(Context);\n\tif (mcp === undefined)\n\t\tthrow new Error(\"useTabMcp: no <TabMcpProvider> above this component\");\n\treturn mcp;\n}\n\n/**\n * The connection state, address, grants, pairing code, identity and\n * reconnecting of the provider's `TabMcp`. Re-renders only when one of them\n * changes; the server and hydration see `disconnected`.\n */\nexport function useTabMcpState(): TabMcpSnapshot {\n\tconst store = storeOf(useTabMcp());\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getSnapshot,\n\t\t() => SERVER_SNAPSHOT,\n\t);\n}\n\n/** Options of `useTool`: `RegisterToolOptions` without the signal (the hook has its own). */\nexport type UseToolOptions = Omit<RegisterToolOptions, \"signal\">;\n\n/**\n * Registers a tool while the component is mounted (with an `AbortSignal`,\n * aborted on unmount). `execute` is always the latest one, so a new closure\n * on each render does not register again; the tool is registered again only\n * when its name, title, description, input or output schema or annotations\n * change, or `options.callers` or `options.exposedTo` (a tool allowed until reload stays allowed when it is\n * registered again unchanged). A duplicate name or an invalid tool is thrown\n * from the component's next render, for an error boundary.\n */\nexport function useTool<Input extends object = Record<string, unknown>>(\n\ttool: Tool<Input>,\n\toptions: UseToolOptions = {},\n): void {\n\tconst mcp = useTabMcp();\n\tconst latest = useRef(tool);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = tool;\n\t});\n\tconst [failure, setFailure] = useState<{ error: unknown } | undefined>();\n\tif (failure !== undefined) throw failure.error;\n\tconst shape = JSON.stringify([\n\t\ttool.name,\n\t\ttool.title,\n\t\ttool.description,\n\t\ttool.inputSchema,\n\t\ttool.outputSchema,\n\t\ttool.annotations,\n\t\toptions.callers,\n\t\toptions.exposedTo,\n\t]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: `shape` stands for the tool and its options; `execute` is read through the ref\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\t\tconst { execute: _, ...fields } = latest.current;\n\t\tmcp\n\t\t\t.registerTool(\n\t\t\t\t{\n\t\t\t\t\t...fields,\n\t\t\t\t\texecute: (input: Input, options) =>\n\t\t\t\t\t\tlatest.current.execute(input, options),\n\t\t\t\t},\n\t\t\t\t{ ...options, signal: controller.signal },\n\t\t\t)\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (!controller.signal.aborted) setFailure({ error });\n\t\t\t});\n\t\treturn () => controller.abort();\n\t}, [mcp, shape]);\n}\n\n/** A tool call of an AI app, as `useToolCalls()` lists it. */\nexport interface ToolCallRecord extends ToolCallStart {\n\t/** When it started, `Date.now()`. */\n\tstartedAt: number;\n\t/** How it ended; missing while it runs. */\n\tend?: ToolCallEnd;\n}\n\nexport interface UseToolCallsOptions {\n\t/** How many calls to keep; default 20. */\n\tlimit?: number;\n}\n\n/**\n * The recent tool calls of AI apps since the component mounted, newest\n * first, each with its end once it is over: for an activity view.\n */\nexport function useToolCalls(\n\toptions: UseToolCallsOptions = {},\n): readonly ToolCallRecord[] {\n\tconst mcp = useTabMcp();\n\tconst limit = Math.max(0, options.limit ?? 20);\n\tconst [calls, setCalls] = useState<readonly ToolCallRecord[]>(EMPTY);\n\tuseEffect(() => {\n\t\tconst started = (event: TabMcpEventMap[\"toolcall\"]) => {\n\t\t\tconst record: ToolCallRecord = { ...event.detail, startedAt: Date.now() };\n\t\t\tsetCalls((list) => [record, ...list].slice(0, limit));\n\t\t};\n\t\tconst ended = (event: TabMcpEventMap[\"toolcallend\"]) => {\n\t\t\tconst end = event.detail;\n\t\t\tsetCalls((list) =>\n\t\t\t\tlist.some((r) => r.id === end.id)\n\t\t\t\t\t? list.map((r) => (r.id === end.id ? { ...r, end } : r))\n\t\t\t\t\t: list,\n\t\t\t);\n\t\t};\n\t\tmcp.addEventListener(\"toolcall\", started);\n\t\tmcp.addEventListener(\"toolcallend\", ended);\n\t\tsetCalls((list) => (list.length > limit ? list.slice(0, limit) : list));\n\t\treturn () => {\n\t\t\tmcp.removeEventListener(\"toolcall\", started);\n\t\t\tmcp.removeEventListener(\"toolcallend\", ended);\n\t\t};\n\t}, [mcp, limit]);\n\treturn calls;\n}\n\n/** Props of `ConnectButton`: a button's, with `children` that may depend on the state. */\nexport interface ConnectButtonProps\n\textends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"type\"> {\n\t/** The label; default: the state (\"Connect your AI app\", \"AI app connected\"). */\n\tchildren?: ReactNode | ((state: TabMcpSnapshot) => ReactNode);\n}\n\n/** Failed reconnect attempts after which the default label says the connection is lost. */\nconst LOST_AFTER_ATTEMPTS = 3;\n\n/** The default label of `ConnectButton`. */\nfunction connectLabel(state: TabMcpSnapshot): string {\n\tif (state.state === \"connected\" && state.grants.length > 0)\n\t\treturn state.grants.length === 1\n\t\t\t? \"AI app connected\"\n\t\t\t: `${state.grants.length} AI apps connected`;\n\tif (state.state === \"reconnecting\")\n\t\treturn (state.reconnecting?.attempt ?? 0) > LOST_AFTER_ATTEMPTS\n\t\t\t? \"Connection lost, retrying…\"\n\t\t\t: \"Reconnecting…\";\n\tif (state.state === \"connecting\") return \"Connecting…\";\n\treturn \"Connect your AI app\";\n}\n\n/**\n * A button that opens the library's \"Connect your AI app\" dialog\n * (`showConnectDialog()`), labelled with the state. `data-state` is\n * `disconnected`, `connecting`, `connected` or `reconnecting`, for styling.\n * An `onClick` that calls `event.preventDefault()` keeps the dialog closed.\n * Renders nothing for a `TabMcp` without a relay: there is nothing to\n * connect.\n */\nexport function ConnectButton({\n\tchildren,\n\tonClick,\n\t...rest\n}: ConnectButtonProps): ReactElement | null {\n\tconst mcp = useTabMcp();\n\tconst state = useTabMcpState();\n\tif (!mcp.hasRelay) return null;\n\tconst label =\n\t\tchildren === undefined\n\t\t\t? connectLabel(state)\n\t\t\t: typeof children === \"function\"\n\t\t\t\t? children(state)\n\t\t\t\t: children;\n\treturn createElement(\n\t\t\"button\",\n\t\t{\n\t\t\ttype: \"button\",\n\t\t\t\"data-state\": state.state,\n\t\t\t...rest,\n\t\t\tonClick: (event: MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\t\t\t\tif (event.defaultPrevented) return;\n\t\t\t\tmcp.showConnectDialog().catch((error: unknown) => {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tlabel,\n\t);\n}\n"
6
6
  ],
7
- "mappings": ";;;AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA;AAAA;AAAA;AAxBA;AA8DA,IAAM,QAA0B,OAAO,OAAO,CAAC,CAAC;AAGhD,IAAM,kBAAkC,OAAO,OAAO;AAAA,EACrD,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,OAAO;AACR,CAAC;AAED,IAAM,eAAe;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAAA;AAGA,MAAM,MAAM;AAAA,EACF;AAAA,EACA,aAAa,IAAI;AAAA,EAC1B;AAAA,EAEA,WAAW,CAAC,KAAa;AAAA,IACxB,KAAK,OAAO;AAAA,IACZ,KAAK,YAAY,KAAK,MAAM,eAAe;AAAA,IAC3C,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IAAI,MAAM;AAAA,QAAkB;AAAA,MAC5B,IAAI,kBAAkB,EAAE,MAAM,CAAC,UAAmB;AAAA,QACjD,QAAQ,MAAM,KAAK;AAAA,OACnB;AAAA;AAAA,EAEH,GACA,KACD;AAAA;",
8
+ "debugId": "5D06ACF2F7BEF98464756E2164756E21",
9
9
  "names": []
10
10
  }
package/registry.d.ts CHANGED
@@ -2,17 +2,23 @@
2
2
  * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`
3
3
  * (DEC-010). Part of the eagerly loaded core.
4
4
  */
5
- import type { JsonSchema, RegisterToolOptions, Tool, ToolAnnotations } from "./types.js";
5
+ import type { JsonSchema, RegisterToolOptions, Tool, ToolAnnotations, ToolCaller } from "./types.js";
6
6
  /** A validated tool as the registry keeps it. */
7
7
  export interface RegisteredTool {
8
8
  readonly name: string;
9
9
  readonly title: string | undefined;
10
10
  readonly description: string;
11
11
  readonly inputSchema: JsonSchema;
12
+ readonly outputSchema?: JsonSchema | undefined;
12
13
  readonly annotations: ToolAnnotations;
13
14
  readonly execute: Tool["execute"];
14
- /** `RegisterToolOptions.webmcp`: offered through WebMCP even if consequential, or never. */
15
- readonly webmcp?: boolean | undefined;
15
+ /**
16
+ * `RegisterToolOptions.callers`, copied; `undefined`: the default, which
17
+ * `toolsFor` (serve.ts, the relay and a port) and `mirror` (webmcp.ts) apply.
18
+ */
19
+ readonly callers?: readonly ToolCaller[] | undefined;
20
+ /** `RegisterToolOptions.exposedTo`, passed on to the native registration. */
21
+ readonly exposedTo?: string[] | undefined;
16
22
  }
17
23
  /** Validate a tool; throws a `TypeError` naming the problem. */
18
24
  export declare function validateTool(tool: Tool): RegisteredTool;
@@ -21,8 +27,9 @@ export type SchemaCompiler = (tool: RegisteredTool) => void;
21
27
  export declare class ToolRegistry {
22
28
  #private;
23
29
  /**
24
- * Register a tool; throws `TypeError` for an invalid tool and an
25
- * `InvalidStateError` `DOMException` for a duplicate name.
30
+ * Register a tool; throws `TypeError` for an invalid tool, an
31
+ * `InvalidStateError` `DOMException` for a duplicate name and the abort
32
+ * reason for an aborted signal (as WebMCP).
26
33
  */
27
34
  register(tool: Tool, options?: RegisterToolOptions): void;
28
35
  /**
package/secret.d.ts CHANGED
@@ -11,8 +11,11 @@ export declare function isSecret(value: unknown): value is string;
11
11
  export declare class SecretStore {
12
12
  #private;
13
13
  constructor(storage: SecretStorage | null | undefined, key: string, oldKey?: string);
14
- /** The current secret; storage first, so a rotation in another tab is seen. */
15
- get(): string;
14
+ /**
15
+ * The current secret, or `undefined` while this page has none (none made
16
+ * yet); storage first, so a rotation in another tab is seen.
17
+ */
18
+ current(): string | undefined;
16
19
  /** Make and keep a new secret (a new address). */
17
20
  rotate(): string;
18
21
  }
package/serve.d.ts CHANGED
@@ -6,11 +6,27 @@
6
6
  * (iteration 28). Part of the lazily loaded chunk.
7
7
  */
8
8
  import type { CallHost } from "./internal.js";
9
- import { type CallContext, type McpHandler } from "./mcp.js";
9
+ import { type CallContext, type McpHandler, type ToolSource } from "./mcp.js";
10
10
  import type { HttpRequestMessage, TabMessage } from "./protocol.js";
11
- import type { ServeHandle, ServeOptions, ServerInfo, TunnelPort } from "./types.js";
12
- /** What a call through the relay, a port or WebMCP needs (`mcp.ts`), from the core's host. */
13
- export declare function callContext(host: CallHost): CallContext;
11
+ import type { ToolRegistry } from "./registry.js";
12
+ import type { ServeHandle, ServeOptions, ServerInfo, ToolCaller, TunnelPort } from "./types.js";
13
+ /**
14
+ * The tools that callers of `kind` see (`RegisterToolOptions.callers`): to
15
+ * the others a tool they cannot see does not exist, in `tools/list` and in
16
+ * `tools/call` alike. Without `callers`, the relay and a port see every tool.
17
+ * The rule for WebMCP lives in the core's `mirror` (webmcp.ts), and WebMCP
18
+ * calls come only for the tools it mirrored. Not one shared helper: a module
19
+ * the core and this chunk both import would split the core in two.
20
+ */
21
+ export declare function toolsFor(registry: ToolRegistry, kind: "relay" | "local"): ToolSource;
22
+ /**
23
+ * Calls `changed` when the list that `tools` gives changed, not on every
24
+ * change of the registry: a tool another kind of caller sees is no news to
25
+ * this one (`list_changed` per caller). Returns a function that stops.
26
+ */
27
+ export declare function watchTools(registry: ToolRegistry, tools: ToolSource, changed: () => void): () => void;
28
+ /** What a call of `kind` through the relay, a port or WebMCP needs (`mcp.ts`), from the core's host. */
29
+ export declare function callContext(host: CallHost, kind: ToolCaller): CallContext;
14
30
  /**
15
31
  * Split text into pieces of at most `max` UTF-16 units, never between the two
16
32
  * halves of a surrogate pair (a lone half would not survive JSON and UTF-8).
@@ -31,6 +47,12 @@ export declare function createTunnel(options: {
31
47
  maxChunk(): number;
32
48
  /** Something failed outside the handler. */
33
49
  error(error: Error): void;
50
+ /**
51
+ * How long a request may take until its answer has ended
52
+ * (`ServeOptions.requestTimeoutMs`); none for the relay's session, whose
53
+ * relay has its own. A `subscriptions/listen` stream is not limited.
54
+ */
55
+ timeoutMs?: number;
34
56
  }): Tunnel;
35
57
  /** What `serve` needs from the `TabMcp`. */
36
58
  export interface ServeHost extends CallHost {
package/setup.d.ts CHANGED
@@ -4,34 +4,23 @@
4
4
  * and extensions that show them in their own UI. Plain data, no DOM. An entry
5
5
  * of its own, out of the core (DEC-118).
6
6
  */
7
+ import type { SetupNotePart, SetupStep } from "./types.js";
8
+ export type { SetupNotePart, SetupStep };
7
9
  /** The guide for every AI app, step by step and what to do when it fails (its source is on ractive.ch). */
8
10
  export declare const SETUP_GUIDE = "https://ractive.ch/tab-mcp/connect/";
9
- /** A part of a {@link SetupInstruction}'s note: plain text, or code to show as code. */
10
- export type SetupNotePart = {
11
- text: string;
12
- } | {
13
- code: string;
14
- };
15
- /** The steps for one AI app. All strings are plain text (set them with `textContent`). */
16
- export interface SetupInstruction {
11
+ /**
12
+ * The steps for one AI app. All strings are plain text (set them with
13
+ * `textContent`). `command`, where present, is safe to show and to run: the
14
+ * server's name and the address in it are words that every shell (POSIX
15
+ * shells, PowerShell, cmd.exe) reads as plain, with nothing to quote. It is
16
+ * absent for apps without a command, and when the address is not
17
+ * shell-plain (only http or https, letters, digits and `. : [ ] / _ ~ -`);
18
+ * then `text` names the command instead. The relay's addresses are
19
+ * shell-plain.
20
+ */
21
+ export interface SetupInstruction extends SetupStep {
17
22
  /** Which app, stable across versions: `claude`, `chatgpt`, `claude-code` or `codex`. */
18
23
  id: "claude" | "chatgpt" | "claude-code" | "codex";
19
- /** The app's name as shown, such as "Claude Code". */
20
- app: string;
21
- /** What to do, a sentence or two. "Run:" when `command` follows. */
22
- text: string;
23
- /**
24
- * The commands to run in a terminal, one per line, to show with a Copy
25
- * button. Safe to show and to run: the server's name and the address in
26
- * them are words that every shell (POSIX shells, PowerShell, cmd.exe) reads
27
- * as plain, with nothing to quote. Absent for apps without a command, and
28
- * when the address is not shell-plain (only http or https, letters, digits
29
- * and `. : [ ] / _ ~ -`); then `text` names the command instead. The relay's
30
- * addresses are shell-plain.
31
- */
32
- command?: string;
33
- /** Shown after the command (or the text): text and code, in order. */
34
- note?: SetupNotePart[];
35
24
  }
36
25
  /**
37
26
  * The steps to add `address` (the page's MCP address from the relay) to
@@ -39,6 +28,7 @@ export interface SetupInstruction {
39
28
  * page's `server.name`; the commands name the server by it, reduced to a
40
29
  * shell-plain label (lower case, letters without marks, each run of other
41
30
  * characters as `-`, at most 40 characters, `tools` if nothing is left).
42
- * End the list with a link to {@link SETUP_GUIDE}.
31
+ * End the list with a link to {@link SETUP_GUIDE}: the steps here are the
32
+ * minimum (CU 20), the guide has the rest and follows the apps' menus.
43
33
  */
44
34
  export declare function setupInstructions(serverName: string, address: string): SetupInstruction[];
package/setup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SETUP_GUIDE2,
3
3
  setupInstructions2
4
- } from "./index-nmn1j689.js";
4
+ } from "./index-5jyqehpk.js";
5
5
  export {
6
6
  SETUP_GUIDE2 as SETUP_GUIDE,
7
7
  setupInstructions2 as setupInstructions
package/strings.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Every text of the library's dialogs, in one table (CU 5). A page passes
3
+ * its own for some or all keys (`ui: { strings }`); the dialogs use these for
4
+ * the rest. `{name}` is a placeholder the dialog fills in: names of tools
5
+ * and AI apps (isolated, so that they cannot reorder the sentence), the
6
+ * code, counts. Where English needs two forms, there are two keys
7
+ * (`…One` for one, `…Many` for more). `lang` and `dir` are the language and
8
+ * direction of the texts, set on every dialog.
9
+ */
10
+ export declare const STRINGS: {
11
+ lang: string;
12
+ dir: string;
13
+ /** Between the last two items of a list ("A, B and C"). */
14
+ and: string;
15
+ confirmTitle: string;
16
+ confirmWho: string;
17
+ deny: string;
18
+ allow: string;
19
+ allowUntilReload: string;
20
+ allowUntilReloadNote: string;
21
+ argumentsHidden: string;
22
+ scrollToAllow: string;
23
+ waitingOne: string;
24
+ waitingMany: string;
25
+ /** Before the page's title while a confirmation waits in a hidden tab. */
26
+ titlePrefix: string;
27
+ clientWebMcp: string;
28
+ clientLocal: string;
29
+ /** An AI app through the relay: its name and the host of its client id. */
30
+ clientRelay: string;
31
+ copy: string;
32
+ copied: string;
33
+ /** On the button after a refused Copy: the text is selected instead. */
34
+ pressMac: string;
35
+ pressOther: string;
36
+ /** The same on a touch screen, where there is no key to press. */
37
+ selected: string;
38
+ copyAddress: string;
39
+ copyCode: string;
40
+ copyCommand: string;
41
+ connectTitle: string;
42
+ connecting: string;
43
+ connectAgain: string;
44
+ reconnecting: string;
45
+ notConnected: string;
46
+ unreachable: string;
47
+ rateLimited: string;
48
+ refused: string;
49
+ ended: string;
50
+ lost: string;
51
+ closed: string;
52
+ disconnected: string;
53
+ checkingSignIn: string;
54
+ signInFirst: string;
55
+ signInRefused: string;
56
+ /** `{reason}`: the relay's reason, as it gave it. */
57
+ signInRefusedWhy: string;
58
+ readyApp: string;
59
+ readyPage: string;
60
+ addressLabel: string;
61
+ help: string;
62
+ guide: string;
63
+ codeSentence: string;
64
+ codeNote: string;
65
+ codeUsed: string;
66
+ signIn: string;
67
+ newAddress: string;
68
+ newAddressNote: string;
69
+ newAddressQuestionOne: string;
70
+ newAddressQuestionMany: string;
71
+ newAddressConfirm: string;
72
+ cancel: string;
73
+ gettingNewAddress: string;
74
+ newAddressDone: string;
75
+ connectedOne: string;
76
+ connectedMany: string;
77
+ connectedNextOne: string;
78
+ connectedNextMany: string;
79
+ connectAnother: string;
80
+ connectedHeading: string;
81
+ appConnected: string;
82
+ disconnect: string;
83
+ disconnectApp: string;
84
+ disconnectNote: string;
85
+ /** Disconnect failed: the relay could not save it (`store_unavailable`). */
86
+ storeUnavailable: string;
87
+ /** Disconnect failed for another reason. */
88
+ disconnectFailed: string;
89
+ /** Under a connected app: the tools allowed until reload for it. */
90
+ runsWithoutAsking: string;
91
+ askAgain: string;
92
+ askAgainApp: string;
93
+ closeNote: string;
94
+ close: string;
95
+ done: string;
96
+ replacedSiblingTitle: string;
97
+ replacedSibling: string;
98
+ replacedTitle: string;
99
+ replaced: string;
100
+ takenOverAgain: string;
101
+ /** `{reason}`: why getting a new address failed, one of the texts above. */
102
+ tryAgainOrClose: string;
103
+ };
104
+ /** The texts of the dialogs: the keys of {@link STRINGS}, each a string. */
105
+ export type DialogStrings = {
106
+ [K in keyof typeof STRINGS]: string;
107
+ };