@particle-academy/agent-integrations 0.52.0 → 0.53.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bridges/multi-instance.ts","../src/bridges/forms.ts"],"names":["resolve"],"mappings":";;;;;;;AAkEA,IAAM,OAAA,uBAAc,OAAA,EAAqD;AAEzE,IAAM,QAAA,GAAW,CAAC,GAAA,KAAkB,GAAA,CAAI,GAAA,CAAI,CAAC,EAAA,KAAO,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AAWjE,SAAS,kBAAA,CACd,IAAA,EACA,OAAA,EACA,EAAA,EACA,QAAA,EACuB;AACvB,EAAA,IAAI,OAAO,EAAA,KAAO,QAAA,IAAY,EAAA,CAAG,IAAA,OAAW,EAAA,EAAI;AAC9C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,EAAA,EAAK,OAAA,CAAQ,MAAM,CAAA,mDAAA,EAAsD,IAAA,CAAK,UAAU,EAAE,CAAC,CAAA,4CAAA,EAC3C,OAAA,CAAQ,QAAQ,CAAA,WAAA;AAAA,KAClE;AAAA,EACF;AAEA,EAAA,IAAI,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA;AAC/B,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,QAAA,uBAAe,GAAA,EAAI;AACnB,IAAA,OAAA,CAAQ,GAAA,CAAI,MAAM,QAAQ,CAAA;AAAA,EAC5B;AAEA,EAAA,IAAI,KAAA,GAAQ,QAAA,CAAS,GAAA,CAAI,OAAA,CAAQ,MAAM,CAAA;AACvC,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,MAAM,SAAA,uBAAgB,GAAA,EAAe;AACrC,IAAA,MAAM,MAAA,GAA4B;AAAA,MAChC,KAAK,MAAM,CAAC,GAAG,SAAA,CAAU,MAAM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,EAAa,EAAE,MAAA,EAAQ,MAAA,CAAO,QAAQ,CAAA;AAAA,IAC1D,CAAA;AAAA,IACA;AAAA,GACF;AAIA,EAAA,MAAM,UAAA,GAAa,kBAAA;AAAA,IACjB,IAAA;AAAA,IACA,EAAE,MAAA,EAAQ,MAAA,EAAQ,QAAA,EAAU,MAAA,EAAQ,QAAA,EAAU,WAAA,EAAa,OAAA,EAAS,CAAC,MAAA,KAAW,gBAAA,CAAiB,IAAA,EAAM,MAAM,CAAA,EAAE;AAAA,IAC/G,MAAA;AAAA,IACA,EAAE,SAAS,QAAA;AAAS,GACtB;AAEA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,QAAA;AAAA,IACJ,KAAA,EAAO,QAAQ,KAAA,IAAS,MAAA;AAAA,IACxB,SAAS,MAAM;AACb,MAAA,IAAI,QAAA,EAAU;AACd,MAAA,QAAA,GAAW,IAAA;AAEX,MAAA,UAAA,CAAW,KAAA,EAAM;AAEjB,MAAA,KAAA,MAAW,KAAA,IAAS,CAAC,GAAG,SAAS,GAAG,KAAA,EAAM;AAC1C,MAAA,SAAA,CAAU,KAAA,EAAM;AAAA,IAClB;AAAA,GACF;AACF","file":"chunk-AET2R7DJ.js","sourcesContent":["import type { ToolHost } from \"../mcp/tool-host\";\n\n/**\n * One bridge serving N instances on a host (docs/multi-form-hosts.md, option A).\n * Internal: not an entry point.\n *\n * A bridge whose tool names are not scoped to its adapter (`form_set_value`,\n * not `form_billing_set_value`) can only serve one instance per host unless the\n * instances share the tools. This is the sharing: the FIRST instance of a family\n * on a host installs the family's tools; later ones join a per-host router; each\n * tool resolves its target instance from an argument (`form`); the tools are\n * withdrawn when the last instance leaves. The tool list therefore stays the\n * same size however many instances come and go.\n *\n * Resolution rules, which are the agent-facing contract:\n * - exactly one instance mounted: the argument is optional;\n * - two or more: a call without it is refused with the ids listed;\n * - an id that is not mounted is refused with the ids listed, even when only\n * one is mounted (a call aimed at a form that closed must not land on another).\n *\n * The router does not register tools itself. `install` does, under one owner\n * the bridge chooses, so the 0.51.0 refusal still stops an unrelated registrant\n * taking a family tool name. If `install` throws (a name is already held), no\n * router is left behind.\n */\n\nexport type InstanceResolution<T> =\n | { ok: true; id: string; instance: T }\n | { ok: false; error: string };\n\nexport type InstanceRouter<T> = {\n /** Mounted instance ids, in mount order. */\n ids(): string[];\n /** Mounted instances, in mount order. */\n entries(): Array<[string, T]>;\n /** Pick the instance a tool call targets, from the raw argument value. */\n resolve(requested: unknown): InstanceResolution<T>;\n};\n\nexport type InstanceRouterOptions<T> = {\n /** Family key: one router per (host, family). E.g. \"form\". */\n family: string;\n /** Name of the tool argument that selects an instance. E.g. \"form\". */\n argument: string;\n /** The family's listing tool, named in errors so an agent can recover. E.g. \"form_list\". */\n listTool: string;\n /**\n * Register the family's shared tools on `host`, dispatching through `router`.\n * Called once, when the first instance joins. Returns the disposer that\n * withdraws them, called when the last instance leaves.\n */\n install: (router: InstanceRouter<T>) => () => void;\n};\n\nexport type InstanceMembership<T> = {\n router: InstanceRouter<T>;\n /** Remove THIS instance. Idempotent; a no-op if a later join replaced it. */\n leave: () => void;\n};\n\ntype RouterState<T> = {\n instances: Map<string, T>;\n router: InstanceRouter<T>;\n uninstall: () => void;\n};\n\nconst routers = new WeakMap<ToolHost, Map<string, RouterState<unknown>>>();\n\nconst quoteAll = (ids: string[]) => ids.map((id) => `\"${id}\"`).join(\", \");\n\n/**\n * Join `instance` under `id` to the host's router for `options.family`,\n * creating (and installing) the router if this is the first instance.\n *\n * A second join under an id that is already mounted REPLACES that entry: it\n * cannot be told apart from a remount whose cleanup has not run yet, and the\n * earlier membership's `leave` then becomes a no-op, so a late cleanup cannot\n * take the newer instance down.\n */\nexport function joinInstanceRouter<T>(\n host: ToolHost,\n options: InstanceRouterOptions<T>,\n id: string,\n instance: T,\n): InstanceMembership<T> {\n if (typeof id !== \"string\" || id.trim() === \"\") {\n throw new Error(\n `A ${options.family} on a shared host needs a non-empty string id (got ${JSON.stringify(id)}); `\n + `agents select it by that id through the \"${options.argument}\" argument.`,\n );\n }\n\n let byFamily = routers.get(host);\n if (!byFamily) {\n byFamily = new Map();\n routers.set(host, byFamily);\n }\n\n let state = byFamily.get(options.family) as RouterState<T> | undefined;\n if (!state) {\n const instances = new Map<string, T>();\n const router: InstanceRouter<T> = {\n ids: () => [...instances.keys()],\n entries: () => [...instances.entries()],\n resolve: (requested) => resolve(options, instances, requested),\n };\n // Installing may throw (a tool name held by an unrelated registrant). Nothing\n // has been recorded yet, so a failed install leaves no router behind.\n const uninstall = options.install(router);\n state = { instances, router, uninstall };\n byFamily.set(options.family, state as RouterState<unknown>);\n }\n\n const current = state;\n current.instances.set(id, instance);\n // Re-insertion keeps Map order; a remount should not jump the listing order.\n\n let left = false;\n const leave = () => {\n if (left) return;\n left = true;\n if (current.instances.get(id) !== instance) return; // replaced by a later join\n current.instances.delete(id);\n if (current.instances.size === 0 && byFamily!.get(options.family) === current) {\n byFamily!.delete(options.family);\n current.uninstall();\n }\n };\n\n return { router: current.router, leave };\n}\n\nfunction resolve<T>(\n options: InstanceRouterOptions<T>,\n instances: Map<string, T>,\n requested: unknown,\n): InstanceResolution<T> {\n const ids = [...instances.keys()];\n const { family, argument, listTool } = options;\n if (requested === undefined || requested === null || requested === \"\") {\n if (ids.length === 1) return { ok: true, id: ids[0], instance: instances.get(ids[0]) as T };\n if (ids.length === 0) return { ok: false, error: `No ${family} is mounted.` };\n return {\n ok: false,\n error:\n `${ids.length} ${family}s are mounted, so pass \"${argument}\" with one of: ${quoteAll(ids)}. `\n + `${listTool} describes them.`,\n };\n }\n if (typeof requested !== \"string\") {\n return { ok: false, error: `\"${argument}\" must be a ${family} id string. Mounted: ${quoteAll(ids)}.` };\n }\n if (!instances.has(requested)) {\n return {\n ok: false,\n error:\n `No ${family} \"${requested}\" is mounted. `\n + (ids.length ? `Mounted: ${quoteAll(ids)}. ` : \"\")\n + `${listTool} lists what is open.`,\n };\n }\n return { ok: true, id: requested, instance: instances.get(requested) as T };\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\nimport type { AgentTarget } from \"../presence/types\";\nimport { emitActivity } from \"../presence/registry\";\nimport { commit, hostErrorMessage } from \"./host-commit\";\nimport { joinInstanceRouter, type InstanceRouter } from \"./multi-instance\";\nimport type { CallToolResult } from \"../mcp/types\";\n\n/**\n * Field descriptor — what the host says about each form field. Mirrors the\n * subset of HTML / react-fancy input shapes agents care about.\n */\nexport type FormFieldDescriptor = {\n /** Form-local field name. Matches the key the host uses in its values map. */\n name: string;\n /** Display label. */\n label?: string;\n /** Logical type. Drives validation + agent expectations. */\n type:\n | \"text\"\n | \"textarea\"\n | \"number\"\n | \"email\"\n | \"password\"\n | \"url\"\n | \"date\"\n | \"select\"\n | \"multi-select\"\n | \"checkbox\"\n | \"switch\"\n | \"radio\"\n | \"file\"\n | \"json\";\n /** Allowed values for select / radio. */\n options?: Array<{ value: string; label: string }>;\n /** Whether the field must be filled before submit. */\n required?: boolean;\n /** Free-text hint surfaced to the agent. */\n description?: string;\n /** Default value (presented in get_value when nothing set). */\n defaultValue?: unknown;\n};\n\n/**\n * Adapter the host wires per form. Matches the controlled-state pattern\n * react-fancy already uses (`value` / `onValueChange`); this adapter just\n * exposes those state slots in a form-shaped way the bridge can call.\n *\n * `setValue` / `setValues` may be sync (`void`) or async (a Promise); see\n * {@link FormAdapterCommit}. Return a Promise when the host's write is\n * authoritative — a persisted draft, or one the host can refuse or report\n * stale — so the agent is told the truth instead of \"success\" before anything\n * was accepted.\n *\n * This bridge pushes NO undo entries: `agent_undo` cannot revert a form write.\n */\nexport type FormBridgeAdapter = {\n /** Stable id for the form (used in form_describe + presence target). */\n id: string;\n /** Display title for human-readable logs. */\n title?: string;\n /** Optional fancy-screens screen id this form belongs to. */\n screenId?: string;\n /** Field descriptors. The bridge uses these for schema introspection\n * (form_describe). Agents call this first to know what to fill. */\n getFields: () => FormFieldDescriptor[];\n /** Read a single field's current value. */\n getValue: (name: string) => unknown;\n /** Read all values as { fieldName: value }. */\n getValues: () => Record<string, unknown>;\n /**\n * Set a single field's value. The host wires this to its setState, or to\n * an authoritative write it awaits. Sync `void` behaves as it always has; a\n * Promise is awaited, and a rejection or `{ ok: false }` is the tool's error.\n */\n setValue: (name: string, value: unknown) => FormAdapterCommit;\n /**\n * Set many at once, ideally as one host commit. Same sync/async contract as\n * `setValue`. When absent, the bridge awaits `setValue` once per field in\n * order and stops at the first refusal (so that path is NOT atomic).\n */\n setValues?: (values: Record<string, unknown>) => FormAdapterCommit;\n /** Programmatically focus a field (host implements DOM focus). Optional. */\n focus?: (name: string) => void;\n /** Submit the form. Returns the values that were submitted (or rejection). */\n submit?: () => Promise<{ ok: boolean; values?: Record<string, unknown>; error?: string }>;\n /**\n * Human confirm gate for `form_submit` (trust-but-verify). When `pendingMode`\n * is on, the bridge calls this before submitting; return false to decline.\n * Wire it to a human control — submitting a form is a human-visible,\n * often-destructive action (checkout, delete, invite).\n */\n confirm?: (request: FormConfirmRequest) => Promise<boolean> | boolean;\n};\n\n/**\n * What an async `setValue` / `setValues` may resolve to, to acknowledge (or\n * refuse) a write. `{ ok: false }` is a refusal the agent can act on: `error`\n * is shown to the agent verbatim, so keep it a human-readable sentence (e.g.\n * \"Draft changed since you read it; re-read and retry\"), never a stack trace or\n * an internal path. `code` (e.g. `\"stale\"`, `\"forbidden\"`) is for the host's own\n * use; it is not shown to the agent.\n */\nexport type FormAdapterResult = { ok: true } | { ok: false; error: string; code?: string };\n\n/**\n * Return type of `setValue` / `setValues`. A sync `void` return keeps the\n * original behaviour. A Promise makes the bridge WAIT: the tool reports\n * success, and emits its AgentActivity event, only after the promise resolves\n * (to `void` or `{ ok: true }`). A rejection or `{ ok: false }` becomes that\n * tool call's error result and emits no activity. If the bridge is disposed\n * while the write is pending, the call settles at once as an error saying the\n * outcome is unknown, and a later settle is ignored.\n */\nexport type FormAdapterCommit = void | Promise<void | FormAdapterResult>;\n\n/** What a `form_submit` confirm gate is asked to approve. */\nexport type FormConfirmRequest = {\n action: \"submit\";\n form: string;\n title?: string;\n values: Record<string, unknown>;\n};\n\nexport type FormBridgeOptions = {\n adapter: FormBridgeAdapter;\n /** Identity tagged into activity events. */\n agent?: { id: string; name?: string; color?: string };\n /**\n * Stage `form_submit` for human confirmation via `adapter.confirm` instead of\n * submitting immediately. **Default: ON** (matches the navigation bridge and\n * the Human+ trust-but-verify contract). Set false only when auto-submit is\n * safe. If on without an `adapter.confirm`, submit proceeds (nothing to gate).\n */\n pendingMode?: boolean;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\n/**\n * The one registrant every form tool is held by. The tools are shared by all\n * forms on a host, so the forms themselves are not separate registrants; an\n * UNRELATED registrant claiming a form tool name is still refused (0.51.0).\n */\nconst FORM_TOOLS_OWNER = \"form-bridge\";\n\n/** Every form tool except `form_list` selects its form through this argument. */\nconst FORM_ARG = {\n type: \"string\",\n description: \"Id of the form to act on (see form_list). Optional while exactly one form is mounted; required when several are.\",\n};\n\ntype FormToolDef = {\n name: string;\n description: string;\n properties: Record<string, unknown>;\n required: string[];\n};\n\n/** The shared tool surface, registered once per host however many forms mount. */\nconst FORM_TOOL_DEFS: FormToolDef[] = [\n {\n name: \"form_describe\",\n description: \"Describe a form — fields, types, options, required flags. Call this first to know what's fillable.\",\n properties: {},\n required: [],\n },\n { name: \"form_get_value\", description: \"Read a single field's current value.\", properties: { field: { type: \"string\" } }, required: [\"field\"] },\n { name: \"form_get_values\", description: \"Read every field's current value as a JSON object.\", properties: {}, required: [] },\n {\n name: \"form_set_value\",\n description: \"Set one field's value. The host's controlled state updates and the human sees the field change.\",\n properties: {\n field: { type: \"string\" },\n value: { description: \"Value to set. Type depends on the field's `type`.\" },\n },\n required: [\"field\", \"value\"],\n },\n {\n name: \"form_set_values\",\n description: \"Set multiple fields atomically. Pass a `values` object keyed by field name.\",\n properties: { values: { type: \"object\" } },\n required: [\"values\"],\n },\n {\n name: \"form_focus\",\n description: \"Move browser focus to a field (host-implemented). Useful before streaming text into it.\",\n properties: { field: { type: \"string\" } },\n required: [\"field\"],\n },\n {\n name: \"form_submit\",\n description: \"Submit the form. Host returns ok + values (or an error). In pendingMode this is staged for the human to confirm first.\",\n properties: {},\n required: [],\n },\n];\n\ntype FormHandler = (args: JsonObject) => Promise<CallToolResult>;\n\n/** One mounted form: its adapter plus handlers built with ITS options. */\ntype FormInstance = {\n adapter: FormBridgeAdapter;\n handlers: Record<string, FormHandler>;\n};\n\n/** Register the shared form tools on `host`, routing each call to one form. */\nfunction installFormTools(host: ToolHost, router: InstanceRouter<FormInstance>): () => void {\n const disposers: Array<() => void> = [];\n try {\n for (const def of FORM_TOOL_DEFS) {\n disposers.push(\n host.registerTool(\n {\n name: def.name,\n description: def.description,\n inputSchema: {\n type: \"object\",\n properties: { form: FORM_ARG, ...def.properties } as any,\n required: def.required,\n additionalProperties: false,\n },\n },\n async (args) => {\n const target = router.resolve(args?.form);\n if (!target.ok) return errorResult(target.error);\n return target.instance.handlers[def.name](args);\n },\n { owner: FORM_TOOLS_OWNER },\n ),\n );\n }\n disposers.push(\n host.registerTool(\n {\n name: \"form_list\",\n description:\n \"List the forms mounted on this host — id, title, screen and fields. Pass an id as `form` to the other form tools when more than one is mounted.\",\n inputSchema: { type: \"object\", properties: {}, additionalProperties: false },\n },\n () => {\n try {\n const forms = router.entries().map(([id, { adapter }]) => ({\n id,\n title: adapter.title,\n screenId: adapter.screenId,\n fields: adapter.getFields(),\n }));\n const text = forms\n .map((f) => `${f.id}${f.title ? ` — ${f.title}` : \"\"}: ${f.fields.map((x) => x.name).join(\", \") || \"(no fields)\"}`)\n .join(\"\\n\");\n return textResult(text || \"(no forms)\", { forms });\n } catch (e) {\n return errorResult(hostErrorMessage(e, \"form_list failed.\"));\n }\n },\n { owner: FORM_TOOLS_OWNER },\n ),\n );\n } catch (e) {\n // A name was held by an unrelated registrant: withdraw what did register,\n // so a refused mount leaves nothing half-installed.\n for (const d of disposers) d();\n throw e;\n }\n return () => {\n for (const d of disposers) d();\n };\n}\n\n/**\n * registerFormBridge — wires schema-driven MCP access to a form.\n *\n * Several forms may share one host. The first form on a host registers the\n * form tools; later ones JOIN them (since 0.53.0; before, a second form threw).\n * Each tool takes an optional `form` argument naming the form by `adapter.id`:\n * optional while exactly one form is mounted, so a single-form host behaves as\n * it always did, and required once two or more are. `form_list` lists what is\n * mounted. The returned `dispose()` removes only this form; the tools are\n * withdrawn when the last form on the host is disposed. A second registration\n * with an id that is already mounted replaces it (a remount); the earlier\n * registration's `dispose()` then leaves the newer one in place.\n *\n * `pendingMode`, the confirm gate, the agent identity and the activity target\n * stay per form. See `docs/multi-form-hosts.md`.\n */\nexport function registerFormBridge(\n host: ToolHost,\n options: FormBridgeOptions,\n): Bridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const pendingMode = options.pendingMode ?? true;\n const formId = adapter?.id == null ? \"\" : String(adapter.id);\n if (formId.trim() === \"\") {\n throw new Error(\n \"registerFormBridge: adapter.id must be a non-empty string. It is how agents pick this form \" +\n \"(the `form` argument) when several forms share a host.\",\n );\n }\n // Surfaces in activity logs; per form, as before.\n const bridgeId = `form:${formId}`;\n\n // agent_undo / agent_redo / agent_history are registered whenever any bridge\n // mounts, so undo availability doesn't hinge on which bridges are co-present.\n ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n const handlers: Record<string, FormHandler> = {};\n\n // Close handling. A host may dispose the bridge (the form unmounts) while a\n // write or a human confirm is still pending; its promise may then never\n // settle. Every awaited host call is raced against dispose, so the tool call\n // settles at once instead of hanging, and a late settle is ignored.\n let disposed = false;\n const onDispose = new Set<() => void>();\n const CLOSED: unique symbol = Symbol(\"form-closed\");\n const untilClosed = <T>(p: Promise<T>): Promise<T | typeof CLOSED> => {\n if (disposed) {\n p.catch(() => {}); // a late rejection must never be unhandled\n return Promise.resolve(CLOSED);\n }\n return new Promise<T | typeof CLOSED>((resolve, reject) => {\n const close = () => resolve(CLOSED);\n onDispose.add(close);\n p.then(\n (v) => { onDispose.delete(close); resolve(v); },\n (e) => { onDispose.delete(close); reject(e); },\n );\n });\n };\n const closedUnknown = (what: string) =>\n errorResult(\n `Form \"${formId}\" was closed before the host confirmed ${what}, so whether it was applied is unknown. ` +\n \"Do not assume it was. If the form is open again, read it back (form_get_values) before retrying.\",\n );\n\n const target =(args: any): AgentTarget => ({\n kind: \"form\",\n screenId: adapter.screenId,\n elementId: typeof args?.field === \"string\" ? `${formId}:${args.field}` : formId,\n label: typeof args?.field === \"string\"\n ? `${adapter.title ?? formId} → ${args.field}`\n : adapter.title ?? formId,\n });\n\n // Builds THIS form's handler for a shared tool. The tool definitions live in\n // FORM_TOOL_DEFS; the router dispatches to these after resolving `form`.\n const reg = (\n name: string,\n handler: (args: JsonObject) => Promise<any> | any,\n isMutation: boolean,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n return errorResult(hostErrorMessage(e, `${name} failed.`));\n }\n };\n const final = isMutation\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent: { id: agent.id, name: agent.name, color: agent.color },\n kind: \"form\",\n screenId: adapter.screenId,\n resolveTarget: ({ args }) => target(args),\n })\n : wrapped;\n handlers[name] = final as FormHandler;\n };\n\n // ───────────── Read tools ─────────────\n\n reg(\n \"form_describe\",\n () => {\n const fields = adapter.getFields();\n const text = fields\n .map((f) => `${f.name}${f.required ? \"*\" : \"\"} (${f.type})${f.label ? ` — ${f.label}` : \"\"}`)\n .join(\"\\n\");\n return textResult(text || \"(no fields)\", { id: formId, title: adapter.title, fields });\n },\n false,\n );\n\n reg(\n \"form_get_value\",\n (args) => {\n const name = String(args.field ?? \"\");\n if (!adapter.getFields().find((f) => f.name === name)) {\n return errorResult(`Unknown field: ${name}`);\n }\n const value = adapter.getValue(name);\n return textResult(JSON.stringify(value), { field: name, value });\n },\n false,\n );\n\n reg(\n \"form_get_values\",\n () => {\n const values = adapter.getValues();\n return textResult(JSON.stringify(values, null, 2), values);\n },\n false,\n );\n\n // ───────────── Mutation tools ─────────────\n\n reg(\n \"form_set_value\",\n async (args) => {\n const name = String(args.field ?? \"\");\n const fieldDef = adapter.getFields().find((f) => f.name === name);\n if (!fieldDef) return errorResult(`Unknown field: ${name}`);\n const done = await untilClosed(\n commit(() => adapter.setValue(name, args.value), `Host refused the write to \"${name}\".`),\n );\n if (done === CLOSED) return closedUnknown(`the write to \"${name}\"`);\n if (!done.ok) return errorResult(done.error);\n return textResult(`${name} ← ${JSON.stringify(args.value)}`, { field: name, value: args.value });\n },\n true,\n );\n\n reg(\n \"form_set_values\",\n async (args) => {\n const values = (args.values && typeof args.values === \"object\") ? args.values as Record<string, unknown> : {};\n const fields = adapter.getFields();\n const known = new Set(fields.map((f) => f.name));\n const unknownKeys = Object.keys(values).filter((k) => !known.has(k));\n if (unknownKeys.length) return errorResult(`Unknown fields: ${unknownKeys.join(\", \")}`);\n const setValues = adapter.setValues;\n if (setValues) {\n const done = await untilClosed(commit(() => setValues(values), \"Host refused the write.\"));\n if (done === CLOSED) return closedUnknown(\"the write\");\n if (!done.ok) return errorResult(done.error);\n } else {\n // No batch setter: one host commit per field, in order, stopping at the\n // first refusal. Earlier fields stay committed, so say exactly which.\n const keys = Object.keys(values);\n const committed: string[] = [];\n for (const [i, k] of keys.entries()) {\n const done = await untilClosed(\n commit(() => adapter.setValue(k, values[k]), `Host refused the write to \"${k}\".`),\n );\n if (done === CLOSED) {\n return {\n ...closedUnknown(`the write to \"${k}\"`),\n structuredContent: { committed, pending: k, notAttempted: keys.slice(i + 1) },\n };\n }\n if (!done.ok) {\n const state = { committed, failed: k, notAttempted: keys.slice(i + 1) };\n if (committed.length) {\n // Those writes DID commit; every committed mutation is observable,\n // and wrapToolWithActivity skips error results, so emit it here.\n emitActivity({\n agentId: agent.id,\n agentName: agent.name,\n agentColor: agent.color,\n target: target({}),\n action: \"form_set_values\",\n timestamp: Date.now(),\n meta: state,\n });\n }\n return {\n ...errorResult(\n `\"${k}\" was refused: ${done.error} ` +\n (committed.length\n ? `Already committed and NOT rolled back: ${committed.join(\", \")}. `\n : \"Nothing was committed. \") +\n (state.notAttempted.length ? `Not attempted: ${state.notAttempted.join(\", \")}.` : \"\"),\n ),\n structuredContent: state,\n };\n }\n committed.push(k);\n }\n }\n return textResult(`Set ${Object.keys(values).length} field(s)`, { values });\n },\n true,\n );\n\n reg(\n \"form_focus\",\n (args) => {\n const name = String(args.field ?? \"\");\n if (!adapter.focus) return errorResult(\"Host did not provide a focus implementation.\");\n if (!adapter.getFields().find((f) => f.name === name)) {\n return errorResult(`Unknown field: ${name}`);\n }\n adapter.focus(name);\n return textResult(`Focused ${name}`, { field: name });\n },\n true,\n );\n\n reg(\n \"form_submit\",\n async () => {\n if (!adapter.submit) return errorResult(\"Host did not provide a submit implementation.\");\n // Trust-but-verify: a form submit is a human-visible / often-destructive\n // action, so gate it on a human confirm when one is wired.\n if (pendingMode && adapter.confirm) {\n const confirm = adapter.confirm;\n const ok = await untilClosed(Promise.resolve().then(() => confirm({\n action: \"submit\",\n form: formId,\n title: adapter.title,\n values: adapter.getValues(),\n })));\n // The form went away while the human was deciding: never submit a\n // form that is no longer on screen, whatever the late answer is.\n if (ok === CLOSED) {\n return errorResult(`Form \"${formId}\" was closed before the submit was confirmed. Nothing was submitted.`);\n }\n if (!ok) return errorResult(\"Declined by user\");\n }\n const submit = adapter.submit;\n const result = await untilClosed(Promise.resolve().then(() => submit()));\n if (result === CLOSED) return closedUnknown(\"the submit\");\n if (!result.ok) return errorResult(hostErrorMessage(result.error, \"Submit failed\"));\n return textResult(\"Submitted\", { values: result.values });\n },\n true,\n );\n\n // Join the host's form router. The first form installs the shared tools; a\n // refused install (a name held by an unrelated registrant) throws from here.\n const membership = joinInstanceRouter<FormInstance>(\n host,\n { family: \"form\", argument: \"form\", listTool: \"form_list\", install: (router) => installFormTools(host, router) },\n formId,\n { adapter, handlers },\n );\n\n return {\n id: bridgeId,\n title: adapter.title ?? formId,\n dispose: () => {\n if (disposed) return;\n disposed = true;\n // Only this form leaves; the tools go when the last form does.\n membership.leave();\n // Settle every call still waiting on the host; see untilClosed.\n for (const close of [...onDispose]) close();\n onDispose.clear();\n },\n };\n}\n"]}
package/dist/index.cjs CHANGED
@@ -633,16 +633,184 @@ async function commit(run, fallback) {
633
633
  }
634
634
  }
635
635
 
636
+ // src/bridges/multi-instance.ts
637
+ var routers = /* @__PURE__ */ new WeakMap();
638
+ var quoteAll = (ids) => ids.map((id) => `"${id}"`).join(", ");
639
+ function joinInstanceRouter(host, options, id, instance) {
640
+ if (typeof id !== "string" || id.trim() === "") {
641
+ throw new Error(
642
+ `A ${options.family} on a shared host needs a non-empty string id (got ${JSON.stringify(id)}); agents select it by that id through the "${options.argument}" argument.`
643
+ );
644
+ }
645
+ let byFamily = routers.get(host);
646
+ if (!byFamily) {
647
+ byFamily = /* @__PURE__ */ new Map();
648
+ routers.set(host, byFamily);
649
+ }
650
+ let state = byFamily.get(options.family);
651
+ if (!state) {
652
+ const instances = /* @__PURE__ */ new Map();
653
+ const router = {
654
+ ids: () => [...instances.keys()],
655
+ entries: () => [...instances.entries()],
656
+ resolve: (requested) => resolve(options, instances, requested)
657
+ };
658
+ const uninstall = options.install(router);
659
+ state = { instances, router, uninstall };
660
+ byFamily.set(options.family, state);
661
+ }
662
+ const current = state;
663
+ current.instances.set(id, instance);
664
+ let left = false;
665
+ const leave = () => {
666
+ if (left) return;
667
+ left = true;
668
+ if (current.instances.get(id) !== instance) return;
669
+ current.instances.delete(id);
670
+ if (current.instances.size === 0 && byFamily.get(options.family) === current) {
671
+ byFamily.delete(options.family);
672
+ current.uninstall();
673
+ }
674
+ };
675
+ return { router: current.router, leave };
676
+ }
677
+ function resolve(options, instances, requested) {
678
+ const ids = [...instances.keys()];
679
+ const { family, argument, listTool } = options;
680
+ if (requested === void 0 || requested === null || requested === "") {
681
+ if (ids.length === 1) return { ok: true, id: ids[0], instance: instances.get(ids[0]) };
682
+ if (ids.length === 0) return { ok: false, error: `No ${family} is mounted.` };
683
+ return {
684
+ ok: false,
685
+ error: `${ids.length} ${family}s are mounted, so pass "${argument}" with one of: ${quoteAll(ids)}. ${listTool} describes them.`
686
+ };
687
+ }
688
+ if (typeof requested !== "string") {
689
+ return { ok: false, error: `"${argument}" must be a ${family} id string. Mounted: ${quoteAll(ids)}.` };
690
+ }
691
+ if (!instances.has(requested)) {
692
+ return {
693
+ ok: false,
694
+ error: `No ${family} "${requested}" is mounted. ` + (ids.length ? `Mounted: ${quoteAll(ids)}. ` : "") + `${listTool} lists what is open.`
695
+ };
696
+ }
697
+ return { ok: true, id: requested, instance: instances.get(requested) };
698
+ }
699
+
636
700
  // src/bridges/forms.ts
637
701
  var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
702
+ var FORM_TOOLS_OWNER = "form-bridge";
703
+ var FORM_ARG = {
704
+ type: "string",
705
+ description: "Id of the form to act on (see form_list). Optional while exactly one form is mounted; required when several are."
706
+ };
707
+ var FORM_TOOL_DEFS = [
708
+ {
709
+ name: "form_describe",
710
+ description: "Describe a form \u2014 fields, types, options, required flags. Call this first to know what's fillable.",
711
+ properties: {},
712
+ required: []
713
+ },
714
+ { name: "form_get_value", description: "Read a single field's current value.", properties: { field: { type: "string" } }, required: ["field"] },
715
+ { name: "form_get_values", description: "Read every field's current value as a JSON object.", properties: {}, required: [] },
716
+ {
717
+ name: "form_set_value",
718
+ description: "Set one field's value. The host's controlled state updates and the human sees the field change.",
719
+ properties: {
720
+ field: { type: "string" },
721
+ value: { description: "Value to set. Type depends on the field's `type`." }
722
+ },
723
+ required: ["field", "value"]
724
+ },
725
+ {
726
+ name: "form_set_values",
727
+ description: "Set multiple fields atomically. Pass a `values` object keyed by field name.",
728
+ properties: { values: { type: "object" } },
729
+ required: ["values"]
730
+ },
731
+ {
732
+ name: "form_focus",
733
+ description: "Move browser focus to a field (host-implemented). Useful before streaming text into it.",
734
+ properties: { field: { type: "string" } },
735
+ required: ["field"]
736
+ },
737
+ {
738
+ name: "form_submit",
739
+ description: "Submit the form. Host returns ok + values (or an error). In pendingMode this is staged for the human to confirm first.",
740
+ properties: {},
741
+ required: []
742
+ }
743
+ ];
744
+ function installFormTools(host, router) {
745
+ const disposers = [];
746
+ try {
747
+ for (const def of FORM_TOOL_DEFS) {
748
+ disposers.push(
749
+ host.registerTool(
750
+ {
751
+ name: def.name,
752
+ description: def.description,
753
+ inputSchema: {
754
+ type: "object",
755
+ properties: { form: FORM_ARG, ...def.properties },
756
+ required: def.required,
757
+ additionalProperties: false
758
+ }
759
+ },
760
+ async (args) => {
761
+ const target = router.resolve(args?.form);
762
+ if (!target.ok) return errorResult(target.error);
763
+ return target.instance.handlers[def.name](args);
764
+ },
765
+ { owner: FORM_TOOLS_OWNER }
766
+ )
767
+ );
768
+ }
769
+ disposers.push(
770
+ host.registerTool(
771
+ {
772
+ name: "form_list",
773
+ description: "List the forms mounted on this host \u2014 id, title, screen and fields. Pass an id as `form` to the other form tools when more than one is mounted.",
774
+ inputSchema: { type: "object", properties: {}, additionalProperties: false }
775
+ },
776
+ () => {
777
+ try {
778
+ const forms = router.entries().map(([id, { adapter }]) => ({
779
+ id,
780
+ title: adapter.title,
781
+ screenId: adapter.screenId,
782
+ fields: adapter.getFields()
783
+ }));
784
+ const text = forms.map((f) => `${f.id}${f.title ? ` \u2014 ${f.title}` : ""}: ${f.fields.map((x) => x.name).join(", ") || "(no fields)"}`).join("\n");
785
+ return textResult(text || "(no forms)", { forms });
786
+ } catch (e) {
787
+ return errorResult(hostErrorMessage(e, "form_list failed."));
788
+ }
789
+ },
790
+ { owner: FORM_TOOLS_OWNER }
791
+ )
792
+ );
793
+ } catch (e) {
794
+ for (const d of disposers) d();
795
+ throw e;
796
+ }
797
+ return () => {
798
+ for (const d of disposers) d();
799
+ };
800
+ }
638
801
  function registerFormBridge(host, options) {
639
802
  const { adapter } = options;
640
803
  const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
641
804
  const pendingMode = options.pendingMode ?? true;
642
- const disposers = [];
643
- const bridgeId = `form:${adapter.id}`;
805
+ const formId = adapter?.id == null ? "" : String(adapter.id);
806
+ if (formId.trim() === "") {
807
+ throw new Error(
808
+ "registerFormBridge: adapter.id must be a non-empty string. It is how agents pick this form (the `form` argument) when several forms share a host."
809
+ );
810
+ }
811
+ const bridgeId = `form:${formId}`;
644
812
  ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
645
- const formId = adapter.id;
813
+ const handlers = {};
646
814
  let disposed = false;
647
815
  const onDispose = /* @__PURE__ */ new Set();
648
816
  const CLOSED = /* @__PURE__ */ Symbol("form-closed");
@@ -652,13 +820,13 @@ function registerFormBridge(host, options) {
652
820
  });
653
821
  return Promise.resolve(CLOSED);
654
822
  }
655
- return new Promise((resolve, reject) => {
656
- const close = () => resolve(CLOSED);
823
+ return new Promise((resolve2, reject) => {
824
+ const close = () => resolve2(CLOSED);
657
825
  onDispose.add(close);
658
826
  p.then(
659
827
  (v) => {
660
828
  onDispose.delete(close);
661
- resolve(v);
829
+ resolve2(v);
662
830
  },
663
831
  (e) => {
664
832
  onDispose.delete(close);
@@ -676,7 +844,7 @@ function registerFormBridge(host, options) {
676
844
  elementId: typeof args?.field === "string" ? `${formId}:${args.field}` : formId,
677
845
  label: typeof args?.field === "string" ? `${adapter.title ?? formId} \u2192 ${args.field}` : adapter.title ?? formId
678
846
  });
679
- const reg = (name, description, properties, required, handler, isMutation) => {
847
+ const reg = (name, handler, isMutation) => {
680
848
  const wrapped = async (args) => {
681
849
  try {
682
850
  return await handler(args);
@@ -691,23 +859,10 @@ function registerFormBridge(host, options) {
691
859
  screenId: adapter.screenId,
692
860
  resolveTarget: ({ args }) => target(args)
693
861
  }) : wrapped;
694
- disposers.push(
695
- host.registerTool(
696
- {
697
- name,
698
- description,
699
- inputSchema: { type: "object", properties, required, additionalProperties: false }
700
- },
701
- final,
702
- { owner: bridgeId }
703
- )
704
- );
862
+ handlers[name] = final;
705
863
  };
706
864
  reg(
707
865
  "form_describe",
708
- `Describe the form "${formId}" \u2014 fields, types, options, required flags. Call this first to know what's fillable.`,
709
- {},
710
- [],
711
866
  () => {
712
867
  const fields = adapter.getFields();
713
868
  const text = fields.map((f) => `${f.name}${f.required ? "*" : ""} (${f.type})${f.label ? ` \u2014 ${f.label}` : ""}`).join("\n");
@@ -717,9 +872,6 @@ function registerFormBridge(host, options) {
717
872
  );
718
873
  reg(
719
874
  "form_get_value",
720
- "Read a single field's current value.",
721
- { field: { type: "string" } },
722
- ["field"],
723
875
  (args) => {
724
876
  const name = String(args.field ?? "");
725
877
  if (!adapter.getFields().find((f) => f.name === name)) {
@@ -732,9 +884,6 @@ function registerFormBridge(host, options) {
732
884
  );
733
885
  reg(
734
886
  "form_get_values",
735
- "Read every field's current value as a JSON object.",
736
- {},
737
- [],
738
887
  () => {
739
888
  const values = adapter.getValues();
740
889
  return textResult(JSON.stringify(values, null, 2), values);
@@ -743,12 +892,6 @@ function registerFormBridge(host, options) {
743
892
  );
744
893
  reg(
745
894
  "form_set_value",
746
- "Set one field's value. The host's controlled state updates and the human sees the field change.",
747
- {
748
- field: { type: "string" },
749
- value: { description: "Value to set. Type depends on the field's `type`." }
750
- },
751
- ["field", "value"],
752
895
  async (args) => {
753
896
  const name = String(args.field ?? "");
754
897
  const fieldDef = adapter.getFields().find((f) => f.name === name);
@@ -764,9 +907,6 @@ function registerFormBridge(host, options) {
764
907
  );
765
908
  reg(
766
909
  "form_set_values",
767
- "Set multiple fields atomically. Pass a `values` object keyed by field name.",
768
- { values: { type: "object" } },
769
- ["values"],
770
910
  async (args) => {
771
911
  const values = args.values && typeof args.values === "object" ? args.values : {};
772
912
  const fields = adapter.getFields();
@@ -820,9 +960,6 @@ function registerFormBridge(host, options) {
820
960
  );
821
961
  reg(
822
962
  "form_focus",
823
- "Move browser focus to a field (host-implemented). Useful before streaming text into it.",
824
- { field: { type: "string" } },
825
- ["field"],
826
963
  (args) => {
827
964
  const name = String(args.field ?? "");
828
965
  if (!adapter.focus) return errorResult("Host did not provide a focus implementation.");
@@ -836,9 +973,6 @@ function registerFormBridge(host, options) {
836
973
  );
837
974
  reg(
838
975
  "form_submit",
839
- "Submit the form. Host returns ok + values (or an error). In pendingMode this is staged for the human to confirm first.",
840
- {},
841
- [],
842
976
  async () => {
843
977
  if (!adapter.submit) return errorResult("Host did not provide a submit implementation.");
844
978
  if (pendingMode && adapter.confirm) {
@@ -862,12 +996,19 @@ function registerFormBridge(host, options) {
862
996
  },
863
997
  true
864
998
  );
999
+ const membership = joinInstanceRouter(
1000
+ host,
1001
+ { family: "form", argument: "form", listTool: "form_list", install: (router) => installFormTools(host, router) },
1002
+ formId,
1003
+ { adapter, handlers }
1004
+ );
865
1005
  return {
866
1006
  id: bridgeId,
867
1007
  title: adapter.title ?? formId,
868
1008
  dispose: () => {
1009
+ if (disposed) return;
869
1010
  disposed = true;
870
- for (const d of disposers) d();
1011
+ membership.leave();
871
1012
  for (const close of [...onDispose]) close();
872
1013
  onDispose.clear();
873
1014
  }
@@ -3311,7 +3452,7 @@ function registerTerminalBridge(host, options) {
3311
3452
  const all = options.terminals ? options.terminals() : options.adapter ? [{ id: "terminal", label: "Terminal", active: true, ...options.adapter }] : [];
3312
3453
  return options.canAccess ? all.filter((t) => options.canAccess(t.id)) : all;
3313
3454
  };
3314
- const resolve = (id) => {
3455
+ const resolve2 = (id) => {
3315
3456
  const list = listTerminals();
3316
3457
  if (typeof id === "string" && id !== "") return list.find((t) => t.id === id);
3317
3458
  return list.find((t) => t.active) ?? list[0];
@@ -3376,7 +3517,7 @@ function registerTerminalBridge(host, options) {
3376
3517
  );
3377
3518
  };
3378
3519
  const need = (args) => {
3379
- const t = resolve(args.terminal);
3520
+ const t = resolve2(args.terminal);
3380
3521
  if (!t) {
3381
3522
  const ids = listTerminals().map((x) => x.id).join(", ") || "(none)";
3382
3523
  throw new Error(
@@ -3461,7 +3602,7 @@ function registerTerminalBridge(host, options) {
3461
3602
  (args) => stageOrExec(need(args), "write", String(args.data)),
3462
3603
  true,
3463
3604
  // Skip the peer broadcast while only staged; emit once it actually executes.
3464
- (args, result) => result?.structuredContent?.pending ? null : target(`write:${String(args.terminal ?? "")}`, resolve(args.terminal)?.id)
3605
+ (args, result) => result?.structuredContent?.pending ? null : target(`write:${String(args.terminal ?? "")}`, resolve2(args.terminal)?.id)
3465
3606
  );
3466
3607
  reg(
3467
3608
  "terminal_run",
@@ -3470,7 +3611,7 @@ function registerTerminalBridge(host, options) {
3470
3611
  ["command"],
3471
3612
  (args) => stageOrExec(need(args), "run", String(args.command)),
3472
3613
  true,
3473
- (args, result) => result?.structuredContent?.pending ? null : target(truncate(String(args.command ?? "")), resolve(args.terminal)?.id)
3614
+ (args, result) => result?.structuredContent?.pending ? null : target(truncate(String(args.command ?? "")), resolve2(args.terminal)?.id)
3474
3615
  );
3475
3616
  if (options.allowAgentConfirm) {
3476
3617
  reg(
@@ -3482,7 +3623,7 @@ function registerTerminalBridge(host, options) {
3482
3623
  const id = String(args.id);
3483
3624
  const entry = staged.get(id);
3484
3625
  if (!entry) return errorResult(`No staged command ${id}`);
3485
- const t = resolve(entry.terminalId);
3626
+ const t = resolve2(entry.terminalId);
3486
3627
  if (!t) return errorResult(`Terminal '${entry.terminalId}' is gone \u2014 cannot run ${id}`);
3487
3628
  staged.delete(id);
3488
3629
  await exec(t, entry.kind, entry.data);
@@ -3524,7 +3665,7 @@ function registerTerminalBridge(host, options) {
3524
3665
  return textResult(`cleared ${t.id}`, { terminal: t.id });
3525
3666
  },
3526
3667
  true,
3527
- (args) => target(`clear:${String(args.terminal ?? "")}`, resolve(args.terminal)?.id)
3668
+ (args) => target(`clear:${String(args.terminal ?? "")}`, resolve2(args.terminal)?.id)
3528
3669
  );
3529
3670
  }
3530
3671
  if (canShells) {
@@ -3564,7 +3705,7 @@ function registerTerminalBridge(host, options) {
3564
3705
  return textResult(`Switched ${t.id} shell to ${id}`, { shell: id, terminal: t.id });
3565
3706
  },
3566
3707
  true,
3567
- (args) => target(`shell:${String(args.id ?? "")}`, resolve(args.terminal)?.id)
3708
+ (args) => target(`shell:${String(args.id ?? "")}`, resolve2(args.terminal)?.id)
3568
3709
  );
3569
3710
  }
3570
3711
  return {
@@ -3578,7 +3719,7 @@ function registerTerminalBridge(host, options) {
3578
3719
  confirm: (id) => {
3579
3720
  const e = staged.get(id);
3580
3721
  if (e) {
3581
- const t = resolve(e.terminalId);
3722
+ const t = resolve2(e.terminalId);
3582
3723
  staged.delete(id);
3583
3724
  if (t) void exec(t, e.kind, e.data);
3584
3725
  }