@particle-academy/agent-integrations 0.51.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.
package/dist/index.d.cts CHANGED
@@ -7,7 +7,7 @@ export { HumanPlusDisposition, HumanPlusEvent, HumanPlusEventPage, HumanPlusEven
7
7
  export { TuiBridgeOptions, TuiSurfaceRegistryLike, registerTuiBridge } from './bridges/tui.cjs';
8
8
  export { B as Bridge, a as BridgeFactory } from './types-D_H2f-wF.cjs';
9
9
  import { FormFieldDescriptor } from './bridges/forms.cjs';
10
- export { FormBridgeAdapter, FormBridgeOptions, registerFormBridge } from './bridges/forms.cjs';
10
+ export { FormAdapterCommit, FormAdapterResult, FormBridgeAdapter, FormBridgeOptions, FormConfirmRequest, registerFormBridge } from './bridges/forms.cjs';
11
11
  export { SheetsBridgeAdapter, SheetsBridgeOptions, registerSheetsBridge } from './bridges/sheets.cjs';
12
12
  export { SheetsAdapterOptions, SheetsCellHighlight, SheetsCellHighlightMap, SheetsHighlightOptions, UseSheetsAdapterResult, WorkbookLike, useSheetsActivityHighlights, useSheetsAdapter } from './sheets-adapter.cjs';
13
13
  export { CodeBridgeAdapter, CodeBridgeOptions, registerCodeBridge } from './bridges/code.cjs';
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { HumanPlusDisposition, HumanPlusEvent, HumanPlusEventPage, HumanPlusEven
7
7
  export { TuiBridgeOptions, TuiSurfaceRegistryLike, registerTuiBridge } from './bridges/tui.js';
8
8
  export { B as Bridge, a as BridgeFactory } from './types-D_TzdBsK.js';
9
9
  import { FormFieldDescriptor } from './bridges/forms.js';
10
- export { FormBridgeAdapter, FormBridgeOptions, registerFormBridge } from './bridges/forms.js';
10
+ export { FormAdapterCommit, FormAdapterResult, FormBridgeAdapter, FormBridgeOptions, FormConfirmRequest, registerFormBridge } from './bridges/forms.js';
11
11
  export { SheetsBridgeAdapter, SheetsBridgeOptions, registerSheetsBridge } from './bridges/sheets.js';
12
12
  export { SheetsAdapterOptions, SheetsCellHighlight, SheetsCellHighlightMap, SheetsHighlightOptions, UseSheetsAdapterResult, WorkbookLike, useSheetsActivityHighlights, useSheetsAdapter } from './sheets-adapter.js';
13
13
  export { CodeBridgeAdapter, CodeBridgeOptions, registerCodeBridge } from './bridges/code.js';
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ export { registerCodeBridge } from './chunk-P6SJBP5T.js';
26
26
  export { registerChartsBridge } from './chunk-VE7TRWZR.js';
27
27
  export { registerGridBridge } from './chunk-NB5AQIR2.js';
28
28
  export { registerSceneBridge } from './chunk-V6EHKHSF.js';
29
- export { registerScreensBridge } from './chunk-CP3EHLZJ.js';
29
+ export { registerScreensBridge } from './chunk-7HHZBPDE.js';
30
30
  export { SCREEN_TEXT_NODE_TYPE, registerScreenDocBridge } from './chunk-PMPBI6I3.js';
31
31
  export { registerDocBridge } from './chunk-VHB3VE53.js';
32
32
  export { registerSlidesBridge } from './chunk-OUUHFR4N.js';
@@ -34,8 +34,9 @@ export { registerMapBridge } from './chunk-QEVSNDJW.js';
34
34
  export { RelayTransport, attachRelay } from './chunk-G6N2TQVO.js';
35
35
  import { attachInProcess } from './chunk-AFUULW5E.js';
36
36
  export { InProcessTransport, attachInProcess } from './chunk-AFUULW5E.js';
37
- import { registerFormBridge } from './chunk-DNF3QVTW.js';
38
- export { registerFormBridge } from './chunk-DNF3QVTW.js';
37
+ import { registerFormBridge } from './chunk-AET2R7DJ.js';
38
+ export { registerFormBridge } from './chunk-AET2R7DJ.js';
39
+ import './chunk-DPBAEWB5.js';
39
40
  export { registerSheetsBridge } from './chunk-S4DA2UTJ.js';
40
41
  export { clearStack as clearUndoStack, ensureUndoToolsRegistered, pushUndoEntry, readHistory as readUndoHistory, redoOne, registerUndoTools, resetAllUndoStacks, undoOne } from './chunk-ZDKYKJFH.js';
41
42
  export { wrapToolWithActivity } from './chunk-2VENWGLZ.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sharing/bridge-contributions.ts","../src/sharing/use-co-browse-session.ts","../src/components/BridgedForm/BridgedForm.tsx","../src/components/ScreensActivityBridge/ScreensActivityBridge.tsx","../src/components/CoBrowsePresence/CoBrowsePresence.tsx","../src/components/CoBrowseCursorLayer/CoBrowseCursorLayer.tsx","../src/components/SimulateUsersButton/SimulateUsersButton.tsx"],"names":["useRef","useEffect","useMemo","jsx","LIFECYCLE_ACTIONS","useState","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCO,IAAM,sBAAN,MAA0B;AAAA,EAA1B,WAAA,GAAA;AACL,IAAA,IAAA,CAAiB,aAAA,uBAAoB,GAAA,EAAgC;AACrE,IAAA,IAAA,CAAiB,OAAA,uBAAc,GAAA,EAAwB;AACvD,IAAA,IAAA,CAAQ,MAAA,GAAgC,IAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxC,IAAI,UAAA,EAA4C;AAC9C,IAAA,MAAM,GAAA,0BAAa,qBAAqB,CAAA;AACxC,IAAA,IAAA,CAAK,aAAA,CAAc,GAAA,CAAI,GAAA,EAAK,UAAU,CAAA;AACtC,IAAA,IAAI,KAAK,MAAA,EAAQ,IAAA,CAAK,MAAM,GAAA,EAAK,UAAA,EAAY,KAAK,MAAM,CAAA;AAExD,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,aAAA,CAAc,OAAO,GAAG,CAAA;AAC7B,MAAA,IAAA,CAAK,SAAS,GAAG,CAAA;AAAA,IACnB,CAAA;AAAA,EACF;AAAA;AAAA,EAGA,KAAK,MAAA,EAA8B;AACjC,IAAA,IAAI,IAAA,CAAK,WAAW,MAAA,EAAQ;AAC5B,IAAA,IAAI,IAAA,CAAK,MAAA,EAAQ,IAAA,CAAK,MAAA,EAAO;AAC7B,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,KAAA,MAAW,CAAC,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A,OAAA,CAAQ,KAAK,CAAA;AAAA,IACf;AAAA,EACF;AAEA,EAAA,uBACEC,IAAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,QAAA;AAAA,MACL,yBAAA,EAAwB,EAAA;AAAA,MACxB,SAAA,EAAW,CAAC,oBAAA,EAAsB,SAAA,IAAa,EAAE,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAAA,MAC3E,OAAA,EAAS,OAAA;AAAA,MACT,QAAA,EAAU,IAAA;AAAA,MACV,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,aAAA;AAAA,QACT,UAAA,EAAY,QAAA;AAAA,QACZ,GAAA,EAAK,CAAA;AAAA,QACL,OAAA,EAAS,UAAA;AAAA,QACT,YAAA,EAAc,CAAA;AAAA,QACd,MAAA,EAAQ,gCAAA;AAAA,QACR,UAAA,EAAY,OAAO,uBAAA,GAA0B,sBAAA;AAAA,QAC7C,KAAA,EAAO,SAAA;AAAA,QACP,IAAA,EAAM,SAAA;AAAA,QACN,QAAA,EAAU,EAAA;AAAA,QACV,UAAA,EAAY,GAAA;AAAA,QACZ,MAAA,EAAQ,OAAO,UAAA,GAAa,SAAA;AAAA,QAC5B,OAAA,EAAS,OAAO,GAAA,GAAM,CAAA;AAAA,QACtB,GAAG;AAAA,OACL;AAAA,MAEA,QAAA,EAAA;AAAA,wBAAAH,IAAC,MAAA,EAAA,EAAK,aAAA,EAAW,IAAA,EAAE,QAAA,EAAA,IAAA,GAAO,WAAM,QAAA,EAAI,CAAA;AAAA,QACnC,KAAA,IAAS,YAAY,KAAK,CAAA,aAAA;AAAA;AAAA;AAAA,GAC7B;AAEJ","file":"index.js","sourcesContent":["import type { MicroMcpServer } from \"../mcp/server\";\n\n/**\n * A page's contribution to the shared tool surface.\n *\n * Return the disposer that withdraws it — typically the `Bridge`'s own\n * `dispose`, or the function `registerTool` returns. Returning nothing is\n * allowed (the original `extraBridges` was typed that way) but means the\n * contribution can never be withdrawn.\n */\nexport type BridgeContribution = (server: MicroMcpServer) => (() => void) | void;\n\n/**\n * The registry behind **\"site tools always; page tools while mounted\"**.\n *\n * `useCoBrowseSession` already had an `extraBridges` hook and already called it.\n * What that shape could not express is a tool surface that CHANGES under the\n * agent mid-session, because the callback is invoked exactly once while the\n * server is being built:\n *\n * - a page that mounts later never gets a chance to contribute;\n * - a page that unmounts cannot withdraw, so the agent keeps a tool aimed at\n * a surface that is gone and only finds out by calling it.\n *\n * Both are silent. Nothing errors; the agent just never sees the tools, or sees\n * dead ones. So contributions live in a registry that is applied when a server\n * appears, re-applied if it is replaced, and withdrawn when the page unmounts —\n * rather than a callback captured at construction.\n *\n * Withdrawal needs no notification machinery of its own: a bridge's disposer\n * unregisters its tools, `ToolRegistry` fires `onToolsChanged`, and\n * `MicroMcpServer` broadcasts `notifications/tools/list_changed`. That was\n * verified before this was written — a grep for `unregisterTool` reads as\n * \"nothing unregisters\", which is a false negative, because bridges use the\n * disposer `registerTool` returns.\n */\nexport class BridgeContributions {\n private readonly contributions = new Map<symbol, BridgeContribution>();\n private readonly applied = new Map<symbol, () => void>();\n private server: MicroMcpServer | null = null;\n\n /**\n * Contribute bridges for as long as the returned disposer is uncalled.\n *\n * Applies immediately when a server is already live, and is held for the next\n * one otherwise — so a page need not know whether sharing has started.\n */\n add(contribute: BridgeContribution): () => void {\n const key = Symbol(\"bridge-contribution\");\n this.contributions.set(key, contribute);\n if (this.server) this.apply(key, contribute, this.server);\n\n return () => {\n this.contributions.delete(key);\n this.withdraw(key);\n };\n }\n\n /** Attach a server and apply every live contribution to it. */\n bind(server: MicroMcpServer): void {\n if (this.server === server) return;\n if (this.server) this.unbind();\n this.server = server;\n for (const [key, contribute] of this.contributions) this.apply(key, contribute, server);\n }\n\n /**\n * Detach the current server, withdrawing what was applied to it. Contributions\n * themselves are KEPT: a session can be stopped and restarted under a page\n * that never unmounted, and its tools must come back rather than silently\n * vanish.\n */\n unbind(): void {\n for (const key of [...this.applied.keys()]) this.withdraw(key);\n this.server = null;\n }\n\n private apply(key: symbol, contribute: BridgeContribution, server: MicroMcpServer): void {\n const dispose = contribute(server);\n if (typeof dispose === \"function\") this.applied.set(key, dispose);\n }\n\n private withdraw(key: symbol): void {\n const dispose = this.applied.get(key);\n this.applied.delete(key);\n dispose?.();\n }\n}\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { MicroMcpServer } from \"../mcp/server\";\nimport { attachInProcess } from \"../mcp/transports\";\nimport { attachSseRelay, type RelayState, type SseRelayTransport } from \"./sse-relay\";\nimport { createSessionDescriptor, type SessionDescriptor } from \"./token\";\nimport { emitActivity } from \"../presence/registry\";\nimport type { AgentActivityEvent } from \"../presence/types\";\nimport { registerNavigationBridge, type NavigationBridgeAdapter } from \"../bridges/navigation\";\nimport { BridgeContributions, type BridgeContribution } from \"./bridge-contributions\";\n\n/** A thing the human did, surfaced so the connected agent stays aware. */\nexport type CoBrowseUserEvent =\n | { kind: \"navigation\"; url: string; title?: string; revision?: number }\n | { kind: \"scroll\"; y: number; revision?: number }\n | { kind: \"form\"; handle: string; value?: unknown; masked?: boolean; revision?: number }\n | { kind: \"click\"; handle: string; label?: string; revision?: number };\n\nexport type UseCoBrowseSessionOptions = {\n /**\n * The navigation adapter (Inertia + DOM in the sandbox). MUST be stable —\n * its methods should read live state via refs, since the bridge captures it\n * once on mount. Memoize it.\n */\n adapter: NavigationBridgeAdapter;\n /** Identity for the agent's presence (cursor/log color + name). */\n agent?: { id: string; name?: string; color?: string };\n /**\n * Which activity events this session forwards to its agent.\n *\n * Only needed when a page runs MORE THAN ONE session — site co-browse plus\n * the agent playground, say. The activity bus is global to the page, so\n * without a filter each relay forwards the other's traffic and every agent\n * sees every other agent's navigations.\n *\n * Omitted forwards everything, which is right for the single-session case.\n */\n activityFilter?: (event: AgentActivityEvent) => boolean;\n /** Relay base path. Default \"/agent-relay\" (the generic frame broker). */\n relayBaseUrl?: string;\n /** MCP server info advertised to the agent. */\n info?: { name: string; version: string; instructions?: string };\n /**\n * Register extra bridges (forms/screens/…) on the same server, once, at\n * construction.\n *\n * For a surface that comes and goes with navigation use\n * {@link CoBrowseSession.contributeBridges} instead: this callback fires\n * exactly once while the server is built, so a page mounted afterwards can\n * never contribute through it, and one that unmounts can never withdraw.\n */\n extraBridges?: (server: MicroMcpServer) => void;\n /** CSRF token for the relay register/unregister POSTs. */\n csrfToken?: () => string | null | undefined;\n /** Stage submit + destructive clicks for human confirm. Default true. */\n pendingMode?: boolean;\n};\n\nexport type CoBrowseSession = {\n server: MicroMcpServer | null;\n /**\n * Contribute bridges for as long as the returned disposer is uncalled —\n * \"site tools always; page tools while mounted\".\n *\n * Call it from a page's mount effect and return its disposer:\n *\n * ```tsx\n * useEffect(() => contributeBridges((server) =>\n * registerArtboardBridge(server, { adapter }).dispose), []);\n * ```\n *\n * Safe to call before sharing starts — the contribution is applied to the\n * server as soon as one exists, and re-applied if the session is restarted.\n */\n contributeBridges: (contribute: BridgeContribution) => () => void;\n session: SessionDescriptor | null;\n relayState: RelayState;\n /**\n * True once at least one remote agent is actually attached to the session.\n *\n * Distinct from `relayState === \"open\"`, which only says the BROWSER reached\n * the relay — true the moment sharing starts, before the link has been handed\n * to anyone. A UI that keys \"Agent is driving\" off the relay state therefore\n * announces a driver who does not exist, and stays silent when a real one\n * arrives.\n */\n agentConnected: boolean;\n /** How many remote agents are attached (0 when nobody has joined). */\n agentCount: number;\n startShare: () => Promise<void>;\n stopShare: () => void;\n /**\n * Report a human action so the connected agent is notified. Emits a\n * `source:\"user\"` activity event, which the SSE relay forwards to the agent\n * as a `notifications/agent_activity` frame.\n */\n observeUser: (event: CoBrowseUserEvent) => void;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\nconst USER = { id: \"human\", name: \"You\" };\n\n/**\n * Site-wide co-browsing session: one persistent in-page `MicroMcpServer` running\n * the navigation bridge, joinable by an external agent over the relay. Mount it\n * once at the app root; render `<CoBrowsePresence>` to show the agent + a Stop\n * control. The host wires `observeUser(...)` to navigation/scroll/form listeners\n * so the agent sees what the human does.\n */\nexport function useCoBrowseSession(options: UseCoBrowseSessionOptions): CoBrowseSession {\n const { adapter, extraBridges } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const relayBaseUrl = options.relayBaseUrl ?? \"/agent-relay\";\n\n const serverRef = useRef<MicroMcpServer | null>(null);\n // Survives re-renders AND server rebuilds: a page's contribution outlives any\n // one session, which is the entire reason this is not a captured callback.\n const contributionsRef = useRef<BridgeContributions>(null as unknown as BridgeContributions);\n if (!contributionsRef.current) contributionsRef.current = new BridgeContributions();\n const relayRef = useRef<SseRelayTransport | null>(null);\n const detachInProc = useRef<(() => void) | null>(null);\n const disposeBridge = useRef<(() => void) | null>(null);\n\n const [session, setSession] = useState<SessionDescriptor | null>(null);\n const [relayState, setRelayState] = useState<RelayState>(\"idle\");\n const [agentCount, setAgentCount] = useState(0);\n\n // Build the server + bridges once. The adapter is captured here, so it must\n // be stable (its methods read live state).\n useEffect(() => {\n const server = new MicroMcpServer({\n info: options.info ?? { name: \"fancy-co-browse\", version: \"0.1.0\" },\n instructions:\n options.info?.instructions ??\n \"Co-browse with a watching human. Call page_describe first; navigate, scroll, and (with confirm) fill/click via stable handles. You receive notifications/agent_activity for the human's actions (source:\\\"user\\\").\",\n });\n const bridge = registerNavigationBridge(server, { adapter, agent, pendingMode: options.pendingMode });\n extraBridges?.(server);\n // Apply whatever pages are already mounted, and keep the registry attached\n // so later mounts/unmounts add and withdraw live.\n contributionsRef.current.bind(server);\n const inProc = attachInProcess(server);\n detachInProc.current = () => inProc.close();\n disposeBridge.current = bridge.dispose;\n serverRef.current = server;\n\n return () => {\n relayRef.current?.close();\n relayRef.current = null;\n contributionsRef.current.unbind();\n disposeBridge.current?.();\n detachInProc.current?.();\n serverRef.current = null;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const startShare = useCallback(async () => {\n const server = serverRef.current;\n if (!server || relayRef.current) return;\n const descriptor = createSessionDescriptor();\n const csrf = options.csrfToken?.() ?? \"\";\n const response = await fetch(`${relayBaseUrl}/register`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", \"x-csrf-token\": csrf },\n body: JSON.stringify({ session: descriptor.id, token: descriptor.token }),\n });\n if (!response.ok) {\n throw new Error(`Relay registration failed (${response.status})`);\n }\n // Pass the session's agent identity down so the relay stamps its own\n // connect/disconnect events with it, and so a host that runs a SECOND\n // session (the agent playground alongside site co-browse) has something to\n // scope on. Without an `agent` this behaves exactly as before.\n const relay = attachSseRelay(server, {\n baseUrl: relayBaseUrl,\n sessionId: descriptor.id,\n token: descriptor.token,\n agent: options.agent,\n activityFilter: options.activityFilter,\n });\n relay.onStateChange(setRelayState);\n relay.onPeersChange(setAgentCount);\n relayRef.current = relay;\n setSession(descriptor);\n }, [relayBaseUrl, options]);\n\n const stopShare = useCallback(() => {\n const current = session;\n relayRef.current?.close();\n relayRef.current = null;\n setRelayState(\"idle\");\n setAgentCount(0);\n setSession(null);\n if (current) {\n const csrf = options.csrfToken?.() ?? \"\";\n void fetch(`${relayBaseUrl}/${current.id}/unregister?token=${encodeURIComponent(current.token)}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", \"x-csrf-token\": csrf },\n }).catch(() => {});\n }\n }, [relayBaseUrl, options, session]);\n\n const observeUser = useCallback((event: CoBrowseUserEvent) => {\n const label =\n event.kind === \"navigation\"\n ? `You navigated to ${event.url}`\n : event.kind === \"scroll\"\n ? \"You scrolled\"\n : event.kind === \"click\"\n ? `You clicked ${event.label ?? event.handle}`\n : `You edited ${event.handle}${event.masked ? \" (hidden)\" : \"\"}`;\n emitActivity({\n agentId: USER.id,\n agentName: USER.name,\n source: \"user\",\n target: { kind: \"navigation\", label },\n action: `user_${event.kind}`,\n timestamp: Date.now(),\n meta: event as Record<string, unknown>,\n });\n }, []);\n\n // Stable identity: a page passes this straight into a mount effect, so a new\n // function each render would re-register its bridges on every render.\n const contributeBridges = useCallback(\n (contribute: BridgeContribution) => contributionsRef.current.add(contribute),\n [],\n );\n\n return {\n server: serverRef.current,\n contributeBridges,\n session,\n relayState,\n agentConnected: agentCount > 0,\n agentCount,\n startShare,\n stopShare,\n observeUser,\n };\n}\n","import { type ReactNode, useEffect, useMemo, useRef } from \"react\";\nimport type { MicroMcpServer } from \"../../mcp/server\";\nimport { registerFormBridge, type FormBridgeAdapter, type FormFieldDescriptor } from \"../../bridges/forms\";\n\nexport type BridgedFormProps = {\n /** Stable id for this form. Used by agents in `form_*` tool calls. */\n id: string;\n /** Human title (also surfaced as the bridge title). */\n title?: string;\n /** Optional fancy-screens screen id this form lives in. */\n screenId?: string;\n /** Field descriptors — drives the agent-facing schema. */\n fields: FormFieldDescriptor[];\n /** Controlled values. */\n values: Record<string, unknown>;\n /** Setter — hosts pass their setState. */\n onChange: (next: Record<string, unknown>) => void;\n /** Optional submit handler. */\n onSubmit?: () => Promise<{ ok: boolean; values?: Record<string, unknown>; error?: string }>;\n /** The MicroMcpServer the bridge registers against. Pass null/undefined\n * to render without a bridge (useful for stories / non-shared use). */\n server?: MicroMcpServer | null;\n /** Identity used in activity events. */\n agent?: { id: string; name?: string; color?: string };\n children: ReactNode;\n};\n\n/**\n * BridgedForm — wraps a react-fancy form (or any controlled inputs)\n * with a `registerFormBridge` lifecycle. Children render the actual form\n * using `values` + `onChange`; this component only manages the bridge.\n *\n * Hosts use it like:\n *\n * <BridgedForm id=\"signup\" fields={...} values={values} onChange={setValues} server={server}>\n * <Field><Input value={values.email} onValueChange={(v) => onChange({ ...values, email: v })} /></Field>\n * ...\n * </BridgedForm>\n *\n * Agents can then call form_describe, form_set_value, form_submit, etc.\n */\nexport function BridgedForm({\n id,\n title,\n screenId,\n fields,\n values,\n onChange,\n onSubmit,\n server,\n agent,\n children,\n}: BridgedFormProps) {\n // Refs so the adapter sees fresh values without re-installing the bridge.\n const valuesRef = useRef(values);\n const onChangeRef = useRef(onChange);\n const fieldsRef = useRef(fields);\n const submitRef = useRef(onSubmit);\n useEffect(() => { valuesRef.current = values; }, [values]);\n useEffect(() => { onChangeRef.current = onChange; }, [onChange]);\n useEffect(() => { fieldsRef.current = fields; }, [fields]);\n useEffect(() => { submitRef.current = onSubmit; }, [onSubmit]);\n\n const focusElement = (name: string) => {\n if (typeof document === \"undefined\") return;\n const el = document.querySelector(`[data-form-id=\"${id}\"] [name=\"${name}\"]`) as HTMLElement | null;\n el?.focus();\n };\n\n const adapter = useMemo<FormBridgeAdapter>(() => ({\n id,\n title,\n screenId,\n getFields: () => fieldsRef.current,\n getValue: (name) => valuesRef.current[name],\n getValues: () => ({ ...valuesRef.current }),\n setValue: (name, v) => onChangeRef.current({ ...valuesRef.current, [name]: v }),\n setValues: (next) => onChangeRef.current({ ...valuesRef.current, ...next }),\n focus: focusElement,\n submit: async () => {\n if (!submitRef.current) {\n return { ok: true, values: { ...valuesRef.current } };\n }\n return submitRef.current();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [id, title, screenId]);\n\n useEffect(() => {\n if (!server) return;\n const bridge = registerFormBridge(server, { adapter, agent });\n return () => bridge.dispose();\n }, [server, adapter, agent]);\n\n return <div data-form-id={id}>{children}</div>;\n}\n","import { useEffect } from \"react\";\nimport { onActivity } from \"../../presence/registry\";\n\n/**\n * Loose shape of the fancy-screens system context — kept here so this\n * component doesn't hard-import `@particle-academy/fancy-screens`.\n */\ntype ScreenSystemLike = {\n registry: Map<string, { id: string; agentActivity?: unknown }>;\n updateScreen: (id: string, patch: { agentActivity?: unknown }) => void;\n};\n\nexport type ScreensActivityBridgeProps = {\n /** The value returned by `useScreenSystem()` from fancy-screens. */\n system: ScreenSystemLike;\n /** ms to wait after the last activity before clearing the screen's badge. Default 1500. */\n fadeMs?: number;\n};\n\n/**\n * ScreensActivityBridge — subscribe to the in-process activity registry\n * and patch each event into the matching screen's `agentActivity` field.\n * Fade-out clears the badge after `fadeMs`.\n *\n * Use it once near the root of your app, ABOVE every <Screen>:\n *\n * const system = useScreenSystem();\n * <>\n * <ScreensActivityBridge system={system} />\n * <Screen id=\"dashboard\">…</Screen>\n * <Screen id=\"form\">…</Screen>\n * </>\n *\n * Renders nothing; pure side-effect component.\n */\nexport function ScreensActivityBridge({ system, fadeMs = 1500 }: ScreensActivityBridgeProps) {\n useEffect(() => {\n const fadeTimers = new Map<string, ReturnType<typeof setTimeout>>();\n const off = onActivity((event) => {\n const screenId = event.target.screenId;\n if (!screenId) return;\n // Only patch screens that are currently registered.\n if (!system.registry.has(screenId)) return;\n const activity = {\n agentId: event.agentId,\n agentName: event.agentName,\n agentColor: event.agentColor,\n action: event.action,\n timestamp: event.timestamp,\n elementId: event.target.elementId,\n label: event.target.label,\n };\n system.updateScreen(screenId, { agentActivity: activity });\n const prev = fadeTimers.get(screenId);\n if (prev) clearTimeout(prev);\n fadeTimers.set(\n screenId,\n setTimeout(() => {\n system.updateScreen(screenId, { agentActivity: null });\n fadeTimers.delete(screenId);\n }, event.ttlMs ?? fadeMs),\n );\n });\n return () => {\n off();\n for (const t of fadeTimers.values()) clearTimeout(t);\n };\n }, [system, fadeMs]);\n return null;\n}\n","import { useMemo } from \"react\";\nimport { useAgentActivity } from \"../../presence/use-agent-activity\";\nimport { ShareControls } from \"../ShareControls/ShareControls\";\nimport { ConnectorButtons } from \"../../connectors/ConnectorButtons\";\nimport type { AgentActivity } from \"../AgentPanel\";\nimport type { AgentActivityEvent } from \"../../presence/types\";\nimport type { CoBrowseSession } from \"../../sharing/use-co-browse-session\";\n\nexport type CoBrowsePresenceProps = {\n /** The session from `useCoBrowseSession`. */\n session: CoBrowseSession;\n /** Public MCP/connect URL shown to the user (for ConnectorButtons), optional. */\n connectUrl?: string;\n /** Base URL used to build the shareable session link. */\n shareBaseUrl?: string;\n className?: string;\n};\n\n/** Lifecycle chatter — real to the session, but not something the agent *did*. */\nconst LIFECYCLE_ACTIONS = new Set([\"agent_connected\", \"agent_disconnected\"]);\n\n/**\n * The human's view of a site-wide co-browsing session: a \"Let an agent drive\"\n * starter, the share/connect surface until an agent arrives, a live log of what\n * it is doing once one has, and a Stop / take-back-control button.\n *\n * Staged-action confirms are rendered by the HOST (via the navigation adapter's\n * `confirm`), so this component stays presentation-only.\n */\nexport function CoBrowsePresence({ session, connectUrl, shareBaseUrl, className }: CoBrowsePresenceProps) {\n const { events } = useAgentActivity(undefined, { capacity: 40 });\n const lastAgentAction = [...events]\n .reverse()\n .find((e) => (e.source ?? \"agent\") !== \"user\" && !LIFECYCLE_ACTIONS.has(e.action));\n\n // Whether an agent is HERE, not whether the browser reached the relay. The\n // latter is true the instant sharing starts, so keying the badge on it told\n // every human \"Agent is driving\" before they had handed the link to anyone.\n const connected = session.agentConnected;\n\n const activity = useMemo(() => events.map(toPanelActivity), [events]);\n\n if (!session.session) {\n return (\n <div className={className} data-co-browse-presence=\"idle\">\n <button type=\"button\" onClick={() => void session.startShare()} data-co-browse-start>\n Let an agent drive\n </button>\n </div>\n );\n }\n\n return (\n <div className={className} data-co-browse-presence={connected ? \"connected\" : \"waiting\"}>\n <div data-co-browse-bar>\n <span data-co-browse-dot data-state={session.relayState} />\n <span data-co-browse-status>\n {connected ? \"Agent is driving\" : `Waiting for an agent… (${session.relayState})`}\n </span>\n {lastAgentAction && <span data-co-browse-last>{lastAgentAction.target?.label ?? lastAgentAction.action}</span>}\n <button type=\"button\" onClick={session.stopShare} data-co-browse-stop>\n Stop\n </button>\n </div>\n\n <ShareControls\n session={session.session}\n onStart={() => void session.startShare()}\n onStop={session.stopShare}\n status={session.relayState}\n agentConnected={connected}\n activity={activity}\n shareBaseUrl={shareBaseUrl}\n />\n\n {connectUrl && <ConnectorButtons serverName=\"Fancy UI co-browse\" mcpUrl={connectUrl} />}\n </div>\n );\n}\n\n/**\n * Presence event → the `AgentActivity` row `<ShareControls>` / `<AgentPanel>`\n * render. One shape for both, so a host already collecting presence needs no\n * second stream.\n */\nfunction toPanelActivity(event: AgentActivityEvent): AgentActivity {\n const who = (event.source ?? \"agent\") === \"user\" ? \"You\" : (event.agentName ?? \"Agent\");\n return {\n id: `${event.timestamp}-${event.action}-${event.target?.elementId ?? event.target?.label ?? \"\"}`,\n at: event.timestamp,\n kind: LIFECYCLE_ACTIONS.has(event.action) ? \"info\" : \"tool\",\n source: who,\n text: event.target?.label ?? event.action,\n detail: event.meta,\n };\n}\n\nCoBrowsePresence.displayName = \"CoBrowsePresence\";\n","import { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useAgentActivity } from \"../../presence/use-agent-activity\";\nimport { AgentCursor } from \"../AgentCursor/AgentCursor\";\nimport { AgentActivityHighlight } from \"../AgentActivityHighlight/AgentActivityHighlight\";\n\ntype Rect = { x: number; y: number; width: number; height: number };\n\nconst CURSOR_EDGE_INSET = 24;\nconst FLUID_CURSOR_SPEED_PX_PER_SECOND = 1_050;\nconst MIN_GLIDE_MS = 240;\nconst MAX_GLIDE_MS = 1_200;\n\nexport function visibleCursorPoint(rect: Rect, viewport: { width: number; height: number }) {\n const x = rect.x + rect.width / 2;\n const y = rect.y + rect.height / 2;\n return {\n x: Math.min(Math.max(x, CURSOR_EDGE_INSET), Math.max(CURSOR_EDGE_INSET, viewport.width - CURSOR_EDGE_INSET)),\n y: Math.min(Math.max(y, CURSOR_EDGE_INSET), Math.max(CURSOR_EDGE_INSET, viewport.height - CURSOR_EDGE_INSET)),\n };\n}\n\nexport function fluidGlideDuration(from: { x: number; y: number } | null, to: { x: number; y: number }) {\n if (!from) return 0;\n const distance = Math.hypot(to.x - from.x, to.y - from.y);\n return Math.round(Math.min(MAX_GLIDE_MS, Math.max(MIN_GLIDE_MS, (distance / FLUID_CURSOR_SPEED_PX_PER_SECOND) * 1_000)));\n}\n\nexport type CoBrowseCursorLayerProps = {\n /** Render the overlay only while a session is live. Default true. */\n active?: boolean;\n /** Stacking order of the overlay. Default just under the max. */\n zIndex?: number;\n /**\n * Retire the cursor after this long without a tool call. Default 15s;\n * `0` keeps it on screen indefinitely.\n *\n * A cursor that sits still is not neutral — it reads as \"the agent is\n * broken\", which is worse than showing nothing. Continuous presence belongs\n * in the activity log; the cursor is for *motion*.\n */\n idleAfterMs?: number;\n};\n\n/**\n * Session lifecycle chatter. Real events, but nothing the agent DID — so they\n * must never conjure a cursor. `agent_connected` used to, parking a motionless\n * pointer captioned \"Agent connected\" in the middle of the viewport for a\n * session in which the agent had not yet made a single tool call.\n */\nconst LIFECYCLE_ACTIONS = new Set([\"agent_connected\", \"agent_disconnected\"]);\n\n/**\n * Page-wide agent presence for co-browsing — the missing \"all actors present\"\n * half of Human+ UX. A fixed, click-through overlay (portaled to <body>) that\n * shows the connected agent as a live cursor + pings/highlights the element it\n * just acted on, gliding between targets. Same visual language as the whiteboard\n * demo's agent cursor, but mapped from the navigation bridge's STABLE HANDLES\n * (the agent has no real mouse) — each tool reports the acted element's viewport\n * rect in `meta.rect` (see `NavigationBridgeAdapter.rectFor`).\n *\n * Mount it once near the app root (e.g. in your CoBrowseProvider), gated on an\n * active session. SSR-safe: renders null on the server / until the first action.\n */\nexport function CoBrowseCursorLayer({\n active = true,\n zIndex = 2147483000,\n idleAfterMs = 15_000,\n}: CoBrowseCursorLayerProps) {\n const { latest } = useAgentActivity(undefined, { capacity: 12 });\n const [cursor, setCursor] = useState<{ x: number; y: number; name: string; color: string; status?: string; glideMs: number } | null>(\n null,\n );\n const [pulse, setPulse] = useState<{ rect: Rect; color: string; key: number } | null>(null);\n // Timestamp of the last real tool call — the only thing that keeps the cursor\n // alive. Deliberately NOT bumped by lifecycle events, so a relay client\n // reconnecting every call can't hold a stale pointer on screen forever.\n const [lastActionAt, setLastActionAt] = useState(0);\n\n useEffect(() => {\n if (!latest || (latest.source ?? \"agent\") === \"user\") return;\n if (LIFECYCLE_ACTIONS.has(latest.action)) {\n // Connecting is not acting. Relay clients may also be intentionally\n // short-lived (one process per MCP call), so a disconnect is not the end\n // of the session either — if a cursor is already on screen from real work,\n // leave it and just say so. What we must NOT do is create one: an agent\n // that has connected and done nothing has nowhere to point.\n setCursor((prev) => (prev ? { ...prev, status: \"Standing by\", glideMs: 0 } : null));\n setPulse(null);\n return;\n }\n setLastActionAt(latest.timestamp);\n const color = latest.agentColor ?? \"#a855f7\";\n const name = latest.agentName ?? \"Agent\";\n const status = latest.target?.label ?? latest.action;\n const rect = (latest.meta as { rect?: Rect } | undefined)?.rect;\n if (rect) {\n // Keep off-screen targets represented at the nearest viewport edge, then\n // glide at a distance-aware pace that a watching human can comfortably\n // follow. This is presence, not a teleport animation.\n const target = visibleCursorPoint(rect, { width: window.innerWidth, height: window.innerHeight });\n const reduceMotion = window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches ?? false;\n setCursor((prev) => ({\n ...target,\n name,\n color,\n status,\n glideMs: reduceMotion ? 0 : fluidGlideDuration(prev, target),\n }));\n setPulse({ rect, color, key: latest.timestamp });\n } else {\n // nav / scroll — no element. Keep (or first-show, at viewport center) the\n // cursor so the agent stays visibly present; just refresh its caption.\n setCursor((prev) =>\n prev\n ? { ...prev, status, name, color }\n : { x: window.innerWidth / 2, y: window.innerHeight / 2, name, color, status, glideMs: 0 },\n );\n }\n }, [latest?.timestamp]);\n\n // Retire the cursor once the agent goes quiet. Presence that never changes\n // stops being information — the human reads a frozen pointer as a hung agent,\n // and the activity log is where \"still connected\" is supposed to live.\n useEffect(() => {\n if (!idleAfterMs || !lastActionAt) return;\n const timer = setTimeout(() => {\n setCursor(null);\n setPulse(null);\n }, idleAfterMs);\n return () => clearTimeout(timer);\n }, [lastActionAt, idleAfterMs]);\n\n if (!active || !cursor || typeof document === \"undefined\") return null;\n\n return createPortal(\n <div data-co-browse-cursor-layer=\"\" style={{ position: \"fixed\", inset: 0, pointerEvents: \"none\", zIndex }}>\n {pulse && (\n <AgentActivityHighlight\n x={pulse.rect.x}\n y={pulse.rect.y}\n width={pulse.rect.width}\n height={pulse.rect.height}\n color={pulse.color}\n pulseKey={pulse.key}\n />\n )}\n <AgentCursor\n x={cursor.x}\n y={cursor.y}\n name={cursor.name}\n color={cursor.color}\n status={cursor.status}\n style={{\n transition: cursor.glideMs\n ? `left ${cursor.glideMs}ms cubic-bezier(.22,.61,.36,1), top ${cursor.glideMs}ms cubic-bezier(.22,.61,.36,1)`\n : \"none\",\n }}\n />\n </div>,\n document.body,\n );\n}\n\nCoBrowseCursorLayer.displayName = \"CoBrowseCursorLayer\";\n","import { type CSSProperties, useState } from \"react\";\n\nexport type SimulateUsersButtonProps = {\n /** Endpoint that injects the fake active users. Default `/active-users/simulate`. */\n endpoint?: string;\n /** How many fake users to simulate (sent as `count`). Default `10`. */\n count?: number;\n /** Button label. Default `Simulate {count} active users`. */\n label?: string;\n /**\n * CSRF token sent as `X-CSRF-TOKEN`. If omitted, falls back to a\n * `<meta name=\"csrf-token\">` on the page (the Laravel default).\n */\n csrfToken?: string;\n /** Called after a successful trigger. */\n onTriggered?: () => void;\n /** Called if the request fails. */\n onError?: (error: unknown) => void;\n className?: string;\n style?: CSSProperties;\n};\n\nfunction resolveCsrf(explicit?: string): string | undefined {\n if (explicit) return explicit;\n if (typeof document === \"undefined\") return undefined;\n return document.querySelector<HTMLMetaElement>('meta[name=\"csrf-token\"]')?.content;\n}\n\n/**\n * A button that asks the host to inject N **fake** active users (injected\n * dummies, not real accounts) so the live ActiveUser stream / presence overlay\n * has something to animate in a demo. POSTs `{ count }` to `endpoint`.\n *\n * Self-contained (inline styles, no react-fancy dependency) so it drops into any\n * host. The fakes + their staggered activity are produced server-side; this\n * button only triggers them.\n */\nexport function SimulateUsersButton({\n endpoint = \"/active-users/simulate\",\n count = 10,\n label,\n csrfToken,\n onTriggered,\n onError,\n className,\n style,\n}: SimulateUsersButtonProps) {\n const [busy, setBusy] = useState(false);\n\n async function trigger() {\n if (busy) return;\n setBusy(true);\n try {\n const token = resolveCsrf(csrfToken);\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Requested-With\": \"XMLHttpRequest\",\n ...(token ? { \"X-CSRF-TOKEN\": token } : {}),\n },\n credentials: \"same-origin\",\n body: JSON.stringify({ count }),\n });\n if (!res.ok) throw new Error(`Simulate request failed: ${res.status}`);\n onTriggered?.();\n } catch (err) {\n onError?.(err);\n } finally {\n setBusy(false);\n }\n }\n\n return (\n <button\n type=\"button\"\n data-fai-simulate-users=\"\"\n className={[\"fai-simulate-users\", className ?? \"\"].filter(Boolean).join(\" \")}\n onClick={trigger}\n disabled={busy}\n style={{\n display: \"inline-flex\",\n alignItems: \"center\",\n gap: 8,\n padding: \"8px 14px\",\n borderRadius: 8,\n border: \"1px solid rgba(139,92,246,0.4)\",\n background: busy ? \"rgba(139,92,246,0.15)\" : \"rgba(139,92,246,0.1)\",\n color: \"#7c3aed\",\n font: \"inherit\",\n fontSize: 13,\n fontWeight: 500,\n cursor: busy ? \"progress\" : \"pointer\",\n opacity: busy ? 0.7 : 1,\n ...style,\n }}\n >\n <span aria-hidden>{busy ? \"⏳\" : \"✨\"}</span>\n {label ?? `Simulate ${count} active users`}\n </button>\n );\n}\n"]}
1
+ {"version":3,"sources":["../src/sharing/bridge-contributions.ts","../src/sharing/use-co-browse-session.ts","../src/components/BridgedForm/BridgedForm.tsx","../src/components/ScreensActivityBridge/ScreensActivityBridge.tsx","../src/components/CoBrowsePresence/CoBrowsePresence.tsx","../src/components/CoBrowseCursorLayer/CoBrowseCursorLayer.tsx","../src/components/SimulateUsersButton/SimulateUsersButton.tsx"],"names":["useRef","useEffect","useMemo","jsx","LIFECYCLE_ACTIONS","useState","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCO,IAAM,sBAAN,MAA0B;AAAA,EAA1B,WAAA,GAAA;AACL,IAAA,IAAA,CAAiB,aAAA,uBAAoB,GAAA,EAAgC;AACrE,IAAA,IAAA,CAAiB,OAAA,uBAAc,GAAA,EAAwB;AACvD,IAAA,IAAA,CAAQ,MAAA,GAAgC,IAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;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AAA;AAAA,QAC7C,KAAA,EAAO,SAAA;AAAA,QACP,IAAA,EAAM,SAAA;AAAA,QACN,QAAA,EAAU,EAAA;AAAA,QACV,UAAA,EAAY,GAAA;AAAA,QACZ,MAAA,EAAQ,OAAO,UAAA,GAAa,SAAA;AAAA,QAC5B,OAAA,EAAS,OAAO,GAAA,GAAM,CAAA;AAAA,QACtB,GAAG;AAAA,OACL;AAAA,MAEA,QAAA,EAAA;AAAA,wBAAAH,IAAC,MAAA,EAAA,EAAK,aAAA,EAAW,IAAA,EAAE,QAAA,EAAA,IAAA,GAAO,WAAM,QAAA,EAAI,CAAA;AAAA,QACnC,KAAA,IAAS,YAAY,KAAK,CAAA,aAAA;AAAA;AAAA;AAAA,GAC7B;AAEJ","file":"index.js","sourcesContent":["import type { MicroMcpServer } from \"../mcp/server\";\n\n/**\n * A page's contribution to the shared tool surface.\n *\n * Return the disposer that withdraws it — typically the `Bridge`'s own\n * `dispose`, or the function `registerTool` returns. Returning nothing is\n * allowed (the original `extraBridges` was typed that way) but means the\n * contribution can never be withdrawn.\n */\nexport type BridgeContribution = (server: MicroMcpServer) => (() => void) | void;\n\n/**\n * The registry behind **\"site tools always; page tools while mounted\"**.\n *\n * `useCoBrowseSession` already had an `extraBridges` hook and already called it.\n * What that shape could not express is a tool surface that CHANGES under the\n * agent mid-session, because the callback is invoked exactly once while the\n * server is being built:\n *\n * - a page that mounts later never gets a chance to contribute;\n * - a page that unmounts cannot withdraw, so the agent keeps a tool aimed at\n * a surface that is gone and only finds out by calling it.\n *\n * Both are silent. Nothing errors; the agent just never sees the tools, or sees\n * dead ones. So contributions live in a registry that is applied when a server\n * appears, re-applied if it is replaced, and withdrawn when the page unmounts —\n * rather than a callback captured at construction.\n *\n * Withdrawal needs no notification machinery of its own: a bridge's disposer\n * unregisters its tools, `ToolRegistry` fires `onToolsChanged`, and\n * `MicroMcpServer` broadcasts `notifications/tools/list_changed`. That was\n * verified before this was written — a grep for `unregisterTool` reads as\n * \"nothing unregisters\", which is a false negative, because bridges use the\n * disposer `registerTool` returns.\n */\nexport class BridgeContributions {\n private readonly contributions = new Map<symbol, BridgeContribution>();\n private readonly applied = new Map<symbol, () => void>();\n private server: MicroMcpServer | null = null;\n\n /**\n * Contribute bridges for as long as the returned disposer is uncalled.\n *\n * Applies immediately when a server is already live, and is held for the next\n * one otherwise — so a page need not know whether sharing has started.\n */\n add(contribute: BridgeContribution): () => void {\n const key = Symbol(\"bridge-contribution\");\n this.contributions.set(key, contribute);\n if (this.server) this.apply(key, contribute, this.server);\n\n return () => {\n this.contributions.delete(key);\n this.withdraw(key);\n };\n }\n\n /** Attach a server and apply every live contribution to it. */\n bind(server: MicroMcpServer): void {\n if (this.server === server) return;\n if (this.server) this.unbind();\n this.server = server;\n for (const [key, contribute] of this.contributions) this.apply(key, contribute, server);\n }\n\n /**\n * Detach the current server, withdrawing what was applied to it. Contributions\n * themselves are KEPT: a session can be stopped and restarted under a page\n * that never unmounted, and its tools must come back rather than silently\n * vanish.\n */\n unbind(): void {\n for (const key of [...this.applied.keys()]) this.withdraw(key);\n this.server = null;\n }\n\n private apply(key: symbol, contribute: BridgeContribution, server: MicroMcpServer): void {\n const dispose = contribute(server);\n if (typeof dispose === \"function\") this.applied.set(key, dispose);\n }\n\n private withdraw(key: symbol): void {\n const dispose = this.applied.get(key);\n this.applied.delete(key);\n dispose?.();\n }\n}\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { MicroMcpServer } from \"../mcp/server\";\nimport { attachInProcess } from \"../mcp/transports\";\nimport { attachSseRelay, type RelayState, type SseRelayTransport } from \"./sse-relay\";\nimport { createSessionDescriptor, type SessionDescriptor } from \"./token\";\nimport { emitActivity } from \"../presence/registry\";\nimport type { AgentActivityEvent } from \"../presence/types\";\nimport { registerNavigationBridge, type NavigationBridgeAdapter } from \"../bridges/navigation\";\nimport { BridgeContributions, type BridgeContribution } from \"./bridge-contributions\";\n\n/** A thing the human did, surfaced so the connected agent stays aware. */\nexport type CoBrowseUserEvent =\n | { kind: \"navigation\"; url: string; title?: string; revision?: number }\n | { kind: \"scroll\"; y: number; revision?: number }\n | { kind: \"form\"; handle: string; value?: unknown; masked?: boolean; revision?: number }\n | { kind: \"click\"; handle: string; label?: string; revision?: number };\n\nexport type UseCoBrowseSessionOptions = {\n /**\n * The navigation adapter (Inertia + DOM in the sandbox). MUST be stable —\n * its methods should read live state via refs, since the bridge captures it\n * once on mount. Memoize it.\n */\n adapter: NavigationBridgeAdapter;\n /** Identity for the agent's presence (cursor/log color + name). */\n agent?: { id: string; name?: string; color?: string };\n /**\n * Which activity events this session forwards to its agent.\n *\n * Only needed when a page runs MORE THAN ONE session — site co-browse plus\n * the agent playground, say. The activity bus is global to the page, so\n * without a filter each relay forwards the other's traffic and every agent\n * sees every other agent's navigations.\n *\n * Omitted forwards everything, which is right for the single-session case.\n */\n activityFilter?: (event: AgentActivityEvent) => boolean;\n /** Relay base path. Default \"/agent-relay\" (the generic frame broker). */\n relayBaseUrl?: string;\n /** MCP server info advertised to the agent. */\n info?: { name: string; version: string; instructions?: string };\n /**\n * Register extra bridges (forms/screens/…) on the same server, once, at\n * construction.\n *\n * For a surface that comes and goes with navigation use\n * {@link CoBrowseSession.contributeBridges} instead: this callback fires\n * exactly once while the server is built, so a page mounted afterwards can\n * never contribute through it, and one that unmounts can never withdraw.\n */\n extraBridges?: (server: MicroMcpServer) => void;\n /** CSRF token for the relay register/unregister POSTs. */\n csrfToken?: () => string | null | undefined;\n /** Stage submit + destructive clicks for human confirm. Default true. */\n pendingMode?: boolean;\n};\n\nexport type CoBrowseSession = {\n server: MicroMcpServer | null;\n /**\n * Contribute bridges for as long as the returned disposer is uncalled —\n * \"site tools always; page tools while mounted\".\n *\n * Call it from a page's mount effect and return its disposer:\n *\n * ```tsx\n * useEffect(() => contributeBridges((server) =>\n * registerArtboardBridge(server, { adapter }).dispose), []);\n * ```\n *\n * Safe to call before sharing starts — the contribution is applied to the\n * server as soon as one exists, and re-applied if the session is restarted.\n */\n contributeBridges: (contribute: BridgeContribution) => () => void;\n session: SessionDescriptor | null;\n relayState: RelayState;\n /**\n * True once at least one remote agent is actually attached to the session.\n *\n * Distinct from `relayState === \"open\"`, which only says the BROWSER reached\n * the relay — true the moment sharing starts, before the link has been handed\n * to anyone. A UI that keys \"Agent is driving\" off the relay state therefore\n * announces a driver who does not exist, and stays silent when a real one\n * arrives.\n */\n agentConnected: boolean;\n /** How many remote agents are attached (0 when nobody has joined). */\n agentCount: number;\n startShare: () => Promise<void>;\n stopShare: () => void;\n /**\n * Report a human action so the connected agent is notified. Emits a\n * `source:\"user\"` activity event, which the SSE relay forwards to the agent\n * as a `notifications/agent_activity` frame.\n */\n observeUser: (event: CoBrowseUserEvent) => void;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\nconst USER = { id: \"human\", name: \"You\" };\n\n/**\n * Site-wide co-browsing session: one persistent in-page `MicroMcpServer` running\n * the navigation bridge, joinable by an external agent over the relay. Mount it\n * once at the app root; render `<CoBrowsePresence>` to show the agent + a Stop\n * control. The host wires `observeUser(...)` to navigation/scroll/form listeners\n * so the agent sees what the human does.\n */\nexport function useCoBrowseSession(options: UseCoBrowseSessionOptions): CoBrowseSession {\n const { adapter, extraBridges } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const relayBaseUrl = options.relayBaseUrl ?? \"/agent-relay\";\n\n const serverRef = useRef<MicroMcpServer | null>(null);\n // Survives re-renders AND server rebuilds: a page's contribution outlives any\n // one session, which is the entire reason this is not a captured callback.\n const contributionsRef = useRef<BridgeContributions>(null as unknown as BridgeContributions);\n if (!contributionsRef.current) contributionsRef.current = new BridgeContributions();\n const relayRef = useRef<SseRelayTransport | null>(null);\n const detachInProc = useRef<(() => void) | null>(null);\n const disposeBridge = useRef<(() => void) | null>(null);\n\n const [session, setSession] = useState<SessionDescriptor | null>(null);\n const [relayState, setRelayState] = useState<RelayState>(\"idle\");\n const [agentCount, setAgentCount] = useState(0);\n\n // Build the server + bridges once. The adapter is captured here, so it must\n // be stable (its methods read live state).\n useEffect(() => {\n const server = new MicroMcpServer({\n info: options.info ?? { name: \"fancy-co-browse\", version: \"0.1.0\" },\n instructions:\n options.info?.instructions ??\n \"Co-browse with a watching human. Call page_describe first; navigate, scroll, and (with confirm) fill/click via stable handles. You receive notifications/agent_activity for the human's actions (source:\\\"user\\\").\",\n });\n const bridge = registerNavigationBridge(server, { adapter, agent, pendingMode: options.pendingMode });\n extraBridges?.(server);\n // Apply whatever pages are already mounted, and keep the registry attached\n // so later mounts/unmounts add and withdraw live.\n contributionsRef.current.bind(server);\n const inProc = attachInProcess(server);\n detachInProc.current = () => inProc.close();\n disposeBridge.current = bridge.dispose;\n serverRef.current = server;\n\n return () => {\n relayRef.current?.close();\n relayRef.current = null;\n contributionsRef.current.unbind();\n disposeBridge.current?.();\n detachInProc.current?.();\n serverRef.current = null;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const startShare = useCallback(async () => {\n const server = serverRef.current;\n if (!server || relayRef.current) return;\n const descriptor = createSessionDescriptor();\n const csrf = options.csrfToken?.() ?? \"\";\n const response = await fetch(`${relayBaseUrl}/register`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", \"x-csrf-token\": csrf },\n body: JSON.stringify({ session: descriptor.id, token: descriptor.token }),\n });\n if (!response.ok) {\n throw new Error(`Relay registration failed (${response.status})`);\n }\n // Pass the session's agent identity down so the relay stamps its own\n // connect/disconnect events with it, and so a host that runs a SECOND\n // session (the agent playground alongside site co-browse) has something to\n // scope on. Without an `agent` this behaves exactly as before.\n const relay = attachSseRelay(server, {\n baseUrl: relayBaseUrl,\n sessionId: descriptor.id,\n token: descriptor.token,\n agent: options.agent,\n activityFilter: options.activityFilter,\n });\n relay.onStateChange(setRelayState);\n relay.onPeersChange(setAgentCount);\n relayRef.current = relay;\n setSession(descriptor);\n }, [relayBaseUrl, options]);\n\n const stopShare = useCallback(() => {\n const current = session;\n relayRef.current?.close();\n relayRef.current = null;\n setRelayState(\"idle\");\n setAgentCount(0);\n setSession(null);\n if (current) {\n const csrf = options.csrfToken?.() ?? \"\";\n void fetch(`${relayBaseUrl}/${current.id}/unregister?token=${encodeURIComponent(current.token)}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", \"x-csrf-token\": csrf },\n }).catch(() => {});\n }\n }, [relayBaseUrl, options, session]);\n\n const observeUser = useCallback((event: CoBrowseUserEvent) => {\n const label =\n event.kind === \"navigation\"\n ? `You navigated to ${event.url}`\n : event.kind === \"scroll\"\n ? \"You scrolled\"\n : event.kind === \"click\"\n ? `You clicked ${event.label ?? event.handle}`\n : `You edited ${event.handle}${event.masked ? \" (hidden)\" : \"\"}`;\n emitActivity({\n agentId: USER.id,\n agentName: USER.name,\n source: \"user\",\n target: { kind: \"navigation\", label },\n action: `user_${event.kind}`,\n timestamp: Date.now(),\n meta: event as Record<string, unknown>,\n });\n }, []);\n\n // Stable identity: a page passes this straight into a mount effect, so a new\n // function each render would re-register its bridges on every render.\n const contributeBridges = useCallback(\n (contribute: BridgeContribution) => contributionsRef.current.add(contribute),\n [],\n );\n\n return {\n server: serverRef.current,\n contributeBridges,\n session,\n relayState,\n agentConnected: agentCount > 0,\n agentCount,\n startShare,\n stopShare,\n observeUser,\n };\n}\n","import { type ReactNode, useEffect, useMemo, useRef } from \"react\";\nimport type { MicroMcpServer } from \"../../mcp/server\";\nimport { registerFormBridge, type FormBridgeAdapter, type FormFieldDescriptor } from \"../../bridges/forms\";\n\nexport type BridgedFormProps = {\n /** Stable id for this form. Used by agents in `form_*` tool calls. */\n id: string;\n /** Human title (also surfaced as the bridge title). */\n title?: string;\n /** Optional fancy-screens screen id this form lives in. */\n screenId?: string;\n /** Field descriptors — drives the agent-facing schema. */\n fields: FormFieldDescriptor[];\n /** Controlled values. */\n values: Record<string, unknown>;\n /** Setter — hosts pass their setState. */\n onChange: (next: Record<string, unknown>) => void;\n /** Optional submit handler. */\n onSubmit?: () => Promise<{ ok: boolean; values?: Record<string, unknown>; error?: string }>;\n /** The MicroMcpServer the bridge registers against. Pass null/undefined\n * to render without a bridge (useful for stories / non-shared use). */\n server?: MicroMcpServer | null;\n /** Identity used in activity events. */\n agent?: { id: string; name?: string; color?: string };\n children: ReactNode;\n};\n\n/**\n * BridgedForm — wraps a react-fancy form (or any controlled inputs)\n * with a `registerFormBridge` lifecycle. Children render the actual form\n * using `values` + `onChange`; this component only manages the bridge.\n *\n * Hosts use it like:\n *\n * <BridgedForm id=\"signup\" fields={...} values={values} onChange={setValues} server={server}>\n * <Field><Input value={values.email} onValueChange={(v) => onChange({ ...values, email: v })} /></Field>\n * ...\n * </BridgedForm>\n *\n * Agents can then call form_describe, form_set_value, form_submit, etc.\n */\nexport function BridgedForm({\n id,\n title,\n screenId,\n fields,\n values,\n onChange,\n onSubmit,\n server,\n agent,\n children,\n}: BridgedFormProps) {\n // Refs so the adapter sees fresh values without re-installing the bridge.\n const valuesRef = useRef(values);\n const onChangeRef = useRef(onChange);\n const fieldsRef = useRef(fields);\n const submitRef = useRef(onSubmit);\n useEffect(() => { valuesRef.current = values; }, [values]);\n useEffect(() => { onChangeRef.current = onChange; }, [onChange]);\n useEffect(() => { fieldsRef.current = fields; }, [fields]);\n useEffect(() => { submitRef.current = onSubmit; }, [onSubmit]);\n\n const focusElement = (name: string) => {\n if (typeof document === \"undefined\") return;\n const el = document.querySelector(`[data-form-id=\"${id}\"] [name=\"${name}\"]`) as HTMLElement | null;\n el?.focus();\n };\n\n const adapter = useMemo<FormBridgeAdapter>(() => ({\n id,\n title,\n screenId,\n getFields: () => fieldsRef.current,\n getValue: (name) => valuesRef.current[name],\n getValues: () => ({ ...valuesRef.current }),\n setValue: (name, v) => onChangeRef.current({ ...valuesRef.current, [name]: v }),\n setValues: (next) => onChangeRef.current({ ...valuesRef.current, ...next }),\n focus: focusElement,\n submit: async () => {\n if (!submitRef.current) {\n return { ok: true, values: { ...valuesRef.current } };\n }\n return submitRef.current();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [id, title, screenId]);\n\n useEffect(() => {\n if (!server) return;\n const bridge = registerFormBridge(server, { adapter, agent });\n return () => bridge.dispose();\n }, [server, adapter, agent]);\n\n return <div data-form-id={id}>{children}</div>;\n}\n","import { useEffect } from \"react\";\nimport { onActivity } from \"../../presence/registry\";\n\n/**\n * Loose shape of the fancy-screens system context — kept here so this\n * component doesn't hard-import `@particle-academy/fancy-screens`.\n */\ntype ScreenSystemLike = {\n registry: Map<string, { id: string; agentActivity?: unknown }>;\n updateScreen: (id: string, patch: { agentActivity?: unknown }) => void;\n};\n\nexport type ScreensActivityBridgeProps = {\n /** The value returned by `useScreenSystem()` from fancy-screens. */\n system: ScreenSystemLike;\n /** ms to wait after the last activity before clearing the screen's badge. Default 1500. */\n fadeMs?: number;\n};\n\n/**\n * ScreensActivityBridge — subscribe to the in-process activity registry\n * and patch each event into the matching screen's `agentActivity` field.\n * Fade-out clears the badge after `fadeMs`.\n *\n * Use it once near the root of your app, ABOVE every <Screen>:\n *\n * const system = useScreenSystem();\n * <>\n * <ScreensActivityBridge system={system} />\n * <Screen id=\"dashboard\">…</Screen>\n * <Screen id=\"form\">…</Screen>\n * </>\n *\n * Renders nothing; pure side-effect component.\n */\nexport function ScreensActivityBridge({ system, fadeMs = 1500 }: ScreensActivityBridgeProps) {\n useEffect(() => {\n const fadeTimers = new Map<string, ReturnType<typeof setTimeout>>();\n const off = onActivity((event) => {\n const screenId = event.target.screenId;\n if (!screenId) return;\n // Only patch screens that are currently registered.\n if (!system.registry.has(screenId)) return;\n const activity = {\n agentId: event.agentId,\n agentName: event.agentName,\n agentColor: event.agentColor,\n action: event.action,\n timestamp: event.timestamp,\n elementId: event.target.elementId,\n label: event.target.label,\n };\n system.updateScreen(screenId, { agentActivity: activity });\n const prev = fadeTimers.get(screenId);\n if (prev) clearTimeout(prev);\n fadeTimers.set(\n screenId,\n setTimeout(() => {\n system.updateScreen(screenId, { agentActivity: null });\n fadeTimers.delete(screenId);\n }, event.ttlMs ?? fadeMs),\n );\n });\n return () => {\n off();\n for (const t of fadeTimers.values()) clearTimeout(t);\n };\n }, [system, fadeMs]);\n return null;\n}\n","import { useMemo } from \"react\";\nimport { useAgentActivity } from \"../../presence/use-agent-activity\";\nimport { ShareControls } from \"../ShareControls/ShareControls\";\nimport { ConnectorButtons } from \"../../connectors/ConnectorButtons\";\nimport type { AgentActivity } from \"../AgentPanel\";\nimport type { AgentActivityEvent } from \"../../presence/types\";\nimport type { CoBrowseSession } from \"../../sharing/use-co-browse-session\";\n\nexport type CoBrowsePresenceProps = {\n /** The session from `useCoBrowseSession`. */\n session: CoBrowseSession;\n /** Public MCP/connect URL shown to the user (for ConnectorButtons), optional. */\n connectUrl?: string;\n /** Base URL used to build the shareable session link. */\n shareBaseUrl?: string;\n className?: string;\n};\n\n/** Lifecycle chatter — real to the session, but not something the agent *did*. */\nconst LIFECYCLE_ACTIONS = new Set([\"agent_connected\", \"agent_disconnected\"]);\n\n/**\n * The human's view of a site-wide co-browsing session: a \"Let an agent drive\"\n * starter, the share/connect surface until an agent arrives, a live log of what\n * it is doing once one has, and a Stop / take-back-control button.\n *\n * Staged-action confirms are rendered by the HOST (via the navigation adapter's\n * `confirm`), so this component stays presentation-only.\n */\nexport function CoBrowsePresence({ session, connectUrl, shareBaseUrl, className }: CoBrowsePresenceProps) {\n const { events } = useAgentActivity(undefined, { capacity: 40 });\n const lastAgentAction = [...events]\n .reverse()\n .find((e) => (e.source ?? \"agent\") !== \"user\" && !LIFECYCLE_ACTIONS.has(e.action));\n\n // Whether an agent is HERE, not whether the browser reached the relay. The\n // latter is true the instant sharing starts, so keying the badge on it told\n // every human \"Agent is driving\" before they had handed the link to anyone.\n const connected = session.agentConnected;\n\n const activity = useMemo(() => events.map(toPanelActivity), [events]);\n\n if (!session.session) {\n return (\n <div className={className} data-co-browse-presence=\"idle\">\n <button type=\"button\" onClick={() => void session.startShare()} data-co-browse-start>\n Let an agent drive\n </button>\n </div>\n );\n }\n\n return (\n <div className={className} data-co-browse-presence={connected ? \"connected\" : \"waiting\"}>\n <div data-co-browse-bar>\n <span data-co-browse-dot data-state={session.relayState} />\n <span data-co-browse-status>\n {connected ? \"Agent is driving\" : `Waiting for an agent… (${session.relayState})`}\n </span>\n {lastAgentAction && <span data-co-browse-last>{lastAgentAction.target?.label ?? lastAgentAction.action}</span>}\n <button type=\"button\" onClick={session.stopShare} data-co-browse-stop>\n Stop\n </button>\n </div>\n\n <ShareControls\n session={session.session}\n onStart={() => void session.startShare()}\n onStop={session.stopShare}\n status={session.relayState}\n agentConnected={connected}\n activity={activity}\n shareBaseUrl={shareBaseUrl}\n />\n\n {connectUrl && <ConnectorButtons serverName=\"Fancy UI co-browse\" mcpUrl={connectUrl} />}\n </div>\n );\n}\n\n/**\n * Presence event → the `AgentActivity` row `<ShareControls>` / `<AgentPanel>`\n * render. One shape for both, so a host already collecting presence needs no\n * second stream.\n */\nfunction toPanelActivity(event: AgentActivityEvent): AgentActivity {\n const who = (event.source ?? \"agent\") === \"user\" ? \"You\" : (event.agentName ?? \"Agent\");\n return {\n id: `${event.timestamp}-${event.action}-${event.target?.elementId ?? event.target?.label ?? \"\"}`,\n at: event.timestamp,\n kind: LIFECYCLE_ACTIONS.has(event.action) ? \"info\" : \"tool\",\n source: who,\n text: event.target?.label ?? event.action,\n detail: event.meta,\n };\n}\n\nCoBrowsePresence.displayName = \"CoBrowsePresence\";\n","import { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useAgentActivity } from \"../../presence/use-agent-activity\";\nimport { AgentCursor } from \"../AgentCursor/AgentCursor\";\nimport { AgentActivityHighlight } from \"../AgentActivityHighlight/AgentActivityHighlight\";\n\ntype Rect = { x: number; y: number; width: number; height: number };\n\nconst CURSOR_EDGE_INSET = 24;\nconst FLUID_CURSOR_SPEED_PX_PER_SECOND = 1_050;\nconst MIN_GLIDE_MS = 240;\nconst MAX_GLIDE_MS = 1_200;\n\nexport function visibleCursorPoint(rect: Rect, viewport: { width: number; height: number }) {\n const x = rect.x + rect.width / 2;\n const y = rect.y + rect.height / 2;\n return {\n x: Math.min(Math.max(x, CURSOR_EDGE_INSET), Math.max(CURSOR_EDGE_INSET, viewport.width - CURSOR_EDGE_INSET)),\n y: Math.min(Math.max(y, CURSOR_EDGE_INSET), Math.max(CURSOR_EDGE_INSET, viewport.height - CURSOR_EDGE_INSET)),\n };\n}\n\nexport function fluidGlideDuration(from: { x: number; y: number } | null, to: { x: number; y: number }) {\n if (!from) return 0;\n const distance = Math.hypot(to.x - from.x, to.y - from.y);\n return Math.round(Math.min(MAX_GLIDE_MS, Math.max(MIN_GLIDE_MS, (distance / FLUID_CURSOR_SPEED_PX_PER_SECOND) * 1_000)));\n}\n\nexport type CoBrowseCursorLayerProps = {\n /** Render the overlay only while a session is live. Default true. */\n active?: boolean;\n /** Stacking order of the overlay. Default just under the max. */\n zIndex?: number;\n /**\n * Retire the cursor after this long without a tool call. Default 15s;\n * `0` keeps it on screen indefinitely.\n *\n * A cursor that sits still is not neutral — it reads as \"the agent is\n * broken\", which is worse than showing nothing. Continuous presence belongs\n * in the activity log; the cursor is for *motion*.\n */\n idleAfterMs?: number;\n};\n\n/**\n * Session lifecycle chatter. Real events, but nothing the agent DID — so they\n * must never conjure a cursor. `agent_connected` used to, parking a motionless\n * pointer captioned \"Agent connected\" in the middle of the viewport for a\n * session in which the agent had not yet made a single tool call.\n */\nconst LIFECYCLE_ACTIONS = new Set([\"agent_connected\", \"agent_disconnected\"]);\n\n/**\n * Page-wide agent presence for co-browsing — the missing \"all actors present\"\n * half of Human+ UX. A fixed, click-through overlay (portaled to <body>) that\n * shows the connected agent as a live cursor + pings/highlights the element it\n * just acted on, gliding between targets. Same visual language as the whiteboard\n * demo's agent cursor, but mapped from the navigation bridge's STABLE HANDLES\n * (the agent has no real mouse) — each tool reports the acted element's viewport\n * rect in `meta.rect` (see `NavigationBridgeAdapter.rectFor`).\n *\n * Mount it once near the app root (e.g. in your CoBrowseProvider), gated on an\n * active session. SSR-safe: renders null on the server / until the first action.\n */\nexport function CoBrowseCursorLayer({\n active = true,\n zIndex = 2147483000,\n idleAfterMs = 15_000,\n}: CoBrowseCursorLayerProps) {\n const { latest } = useAgentActivity(undefined, { capacity: 12 });\n const [cursor, setCursor] = useState<{ x: number; y: number; name: string; color: string; status?: string; glideMs: number } | null>(\n null,\n );\n const [pulse, setPulse] = useState<{ rect: Rect; color: string; key: number } | null>(null);\n // Timestamp of the last real tool call — the only thing that keeps the cursor\n // alive. Deliberately NOT bumped by lifecycle events, so a relay client\n // reconnecting every call can't hold a stale pointer on screen forever.\n const [lastActionAt, setLastActionAt] = useState(0);\n\n useEffect(() => {\n if (!latest || (latest.source ?? \"agent\") === \"user\") return;\n if (LIFECYCLE_ACTIONS.has(latest.action)) {\n // Connecting is not acting. Relay clients may also be intentionally\n // short-lived (one process per MCP call), so a disconnect is not the end\n // of the session either — if a cursor is already on screen from real work,\n // leave it and just say so. What we must NOT do is create one: an agent\n // that has connected and done nothing has nowhere to point.\n setCursor((prev) => (prev ? { ...prev, status: \"Standing by\", glideMs: 0 } : null));\n setPulse(null);\n return;\n }\n setLastActionAt(latest.timestamp);\n const color = latest.agentColor ?? \"#a855f7\";\n const name = latest.agentName ?? \"Agent\";\n const status = latest.target?.label ?? latest.action;\n const rect = (latest.meta as { rect?: Rect } | undefined)?.rect;\n if (rect) {\n // Keep off-screen targets represented at the nearest viewport edge, then\n // glide at a distance-aware pace that a watching human can comfortably\n // follow. This is presence, not a teleport animation.\n const target = visibleCursorPoint(rect, { width: window.innerWidth, height: window.innerHeight });\n const reduceMotion = window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches ?? false;\n setCursor((prev) => ({\n ...target,\n name,\n color,\n status,\n glideMs: reduceMotion ? 0 : fluidGlideDuration(prev, target),\n }));\n setPulse({ rect, color, key: latest.timestamp });\n } else {\n // nav / scroll — no element. Keep (or first-show, at viewport center) the\n // cursor so the agent stays visibly present; just refresh its caption.\n setCursor((prev) =>\n prev\n ? { ...prev, status, name, color }\n : { x: window.innerWidth / 2, y: window.innerHeight / 2, name, color, status, glideMs: 0 },\n );\n }\n }, [latest?.timestamp]);\n\n // Retire the cursor once the agent goes quiet. Presence that never changes\n // stops being information — the human reads a frozen pointer as a hung agent,\n // and the activity log is where \"still connected\" is supposed to live.\n useEffect(() => {\n if (!idleAfterMs || !lastActionAt) return;\n const timer = setTimeout(() => {\n setCursor(null);\n setPulse(null);\n }, idleAfterMs);\n return () => clearTimeout(timer);\n }, [lastActionAt, idleAfterMs]);\n\n if (!active || !cursor || typeof document === \"undefined\") return null;\n\n return createPortal(\n <div data-co-browse-cursor-layer=\"\" style={{ position: \"fixed\", inset: 0, pointerEvents: \"none\", zIndex }}>\n {pulse && (\n <AgentActivityHighlight\n x={pulse.rect.x}\n y={pulse.rect.y}\n width={pulse.rect.width}\n height={pulse.rect.height}\n color={pulse.color}\n pulseKey={pulse.key}\n />\n )}\n <AgentCursor\n x={cursor.x}\n y={cursor.y}\n name={cursor.name}\n color={cursor.color}\n status={cursor.status}\n style={{\n transition: cursor.glideMs\n ? `left ${cursor.glideMs}ms cubic-bezier(.22,.61,.36,1), top ${cursor.glideMs}ms cubic-bezier(.22,.61,.36,1)`\n : \"none\",\n }}\n />\n </div>,\n document.body,\n );\n}\n\nCoBrowseCursorLayer.displayName = \"CoBrowseCursorLayer\";\n","import { type CSSProperties, useState } from \"react\";\n\nexport type SimulateUsersButtonProps = {\n /** Endpoint that injects the fake active users. Default `/active-users/simulate`. */\n endpoint?: string;\n /** How many fake users to simulate (sent as `count`). Default `10`. */\n count?: number;\n /** Button label. Default `Simulate {count} active users`. */\n label?: string;\n /**\n * CSRF token sent as `X-CSRF-TOKEN`. If omitted, falls back to a\n * `<meta name=\"csrf-token\">` on the page (the Laravel default).\n */\n csrfToken?: string;\n /** Called after a successful trigger. */\n onTriggered?: () => void;\n /** Called if the request fails. */\n onError?: (error: unknown) => void;\n className?: string;\n style?: CSSProperties;\n};\n\nfunction resolveCsrf(explicit?: string): string | undefined {\n if (explicit) return explicit;\n if (typeof document === \"undefined\") return undefined;\n return document.querySelector<HTMLMetaElement>('meta[name=\"csrf-token\"]')?.content;\n}\n\n/**\n * A button that asks the host to inject N **fake** active users (injected\n * dummies, not real accounts) so the live ActiveUser stream / presence overlay\n * has something to animate in a demo. POSTs `{ count }` to `endpoint`.\n *\n * Self-contained (inline styles, no react-fancy dependency) so it drops into any\n * host. The fakes + their staggered activity are produced server-side; this\n * button only triggers them.\n */\nexport function SimulateUsersButton({\n endpoint = \"/active-users/simulate\",\n count = 10,\n label,\n csrfToken,\n onTriggered,\n onError,\n className,\n style,\n}: SimulateUsersButtonProps) {\n const [busy, setBusy] = useState(false);\n\n async function trigger() {\n if (busy) return;\n setBusy(true);\n try {\n const token = resolveCsrf(csrfToken);\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Requested-With\": \"XMLHttpRequest\",\n ...(token ? { \"X-CSRF-TOKEN\": token } : {}),\n },\n credentials: \"same-origin\",\n body: JSON.stringify({ count }),\n });\n if (!res.ok) throw new Error(`Simulate request failed: ${res.status}`);\n onTriggered?.();\n } catch (err) {\n onError?.(err);\n } finally {\n setBusy(false);\n }\n }\n\n return (\n <button\n type=\"button\"\n data-fai-simulate-users=\"\"\n className={[\"fai-simulate-users\", className ?? \"\"].filter(Boolean).join(\" \")}\n onClick={trigger}\n disabled={busy}\n style={{\n display: \"inline-flex\",\n alignItems: \"center\",\n gap: 8,\n padding: \"8px 14px\",\n borderRadius: 8,\n border: \"1px solid rgba(139,92,246,0.4)\",\n background: busy ? \"rgba(139,92,246,0.15)\" : \"rgba(139,92,246,0.1)\",\n color: \"#7c3aed\",\n font: \"inherit\",\n fontSize: 13,\n fontWeight: 500,\n cursor: busy ? \"progress\" : \"pointer\",\n opacity: busy ? 0.7 : 1,\n ...style,\n }}\n >\n <span aria-hidden>{busy ? \"⏳\" : \"✨\"}</span>\n {label ?? `Simulate ${count} active users`}\n </button>\n );\n}\n"]}
@@ -0,0 +1,163 @@
1
+ # Several forms on one host — design note
2
+
3
+ **Status: option A is BUILT (0.53.0).** The owner chose A on 2026-10-30. The
4
+ proposal below is kept as written against 0.51.0 for the reasoning; "Where it
5
+ stands" describes the state before 0.53.0. What was built, and what another
6
+ bridge would need to adopt it, is at the end ("As built").
7
+
8
+ ## Where it stood (0.51.0 and 0.52.0)
9
+
10
+ `registerFormBridge` registers `form_describe`, `form_get_value`,
11
+ `form_get_values`, `form_set_value`, `form_set_values`, `form_focus` and
12
+ `form_submit`. The names are not scoped to the form. Since 0.51.0 a tool name
13
+ held by a different registrant is refused, and each form bridge registers as
14
+ `form:<adapter.id>`, so a second form with a different id on the same host
15
+ throws. Before 0.51.0 it did not throw, but the second form silently took over
16
+ the first one's tools, so two forms on one host have never worked. 0.51.0 made
17
+ the existing failure visible.
18
+
19
+ The same limit applies to every bridge whose registrant id carries an adapter
20
+ id: charts, grids, code editors, scenes, catalogs, feature panels and passkey
21
+ surfaces. Whatever is chosen for forms should be the pattern for those too.
22
+ There is already one precedent for scoping: `registerScreenDocBridge` takes a
23
+ `surface` option that prefixes its tool names (`screen_checkout_add`).
24
+
25
+ Until 0.53.0 the supported answer was **one form bridge per host**.
26
+
27
+ ## Options
28
+
29
+ ### A. One form bridge serving N forms: a `form` argument plus `form_list`
30
+
31
+ The first `registerFormBridge` on a host creates a per-host form router. Later
32
+ calls on the same host **join** it instead of throwing (the same per-host
33
+ pattern `ensureUndoToolsRegistered` uses for the undo tools). Each returned
34
+ `Bridge.dispose()` removes only its own form. Tools gain a `form` argument, and
35
+ a new `form_list` tool returns `{ id, title, screenId }` for each mounted form.
36
+
37
+ - With exactly one form mounted, `form` is optional, so every existing
38
+ single-form consumer and agent prompt keeps working unchanged.
39
+ - With two or more forms, a call without `form` is an error that lists the form
40
+ ids, so an agent that guessed corrects itself on the next call.
41
+ - Presence and activity already target `formId:field`, so nothing changes there.
42
+ Closing one form settles only that form's pending writes.
43
+
44
+ Pros: stable, short `tools/list` (7 + 1 tools however many forms); no
45
+ `tools/list_changed` churn when forms mount and unmount; forms come and go as
46
+ data, which is how an agent reasons about them ("which form?"); no consumer code
47
+ change, because the call that throws today starts working. The router can be a
48
+ shared helper, so charts and grids get the same model later.
49
+
50
+ Cons: the largest change of the three. Tool descriptions become generic (today
51
+ `form_describe` names its form in the description). Per-form options such as
52
+ `pendingMode` and `agent` must stay per form inside one router. A host that
53
+ *relied* on the 0.51.0 throw to detect a double mount loses that signal, though
54
+ nothing first-party does.
55
+
56
+ ### B. Instance-scoped tool names via an option
57
+
58
+ Add `toolPrefix` (or reuse the name `surface`, as screen-doc does):
59
+ `registerFormBridge(host, { adapter, surface: "form_billing" })` registers
60
+ `form_billing_set_value`, and so on. The default stays `form`, so existing
61
+ consumers are unaffected.
62
+
63
+ Pros: small, mirrors an existing option, fully backward compatible, and each
64
+ tool name says which form it drives.
65
+
66
+ Cons: `tools/list` grows by 7 per form, and some clients cap or truncate long
67
+ tool lists. Mounting and unmounting forms churns `tools/list`, and not every
68
+ client re-reads it. The agent must infer that `form_billing_*` and
69
+ `form_shipping_*` are the same tool family. MCP tool names are limited (64
70
+ characters, `[A-Za-z0-9_-]`), so the host must choose a valid prefix or the
71
+ bridge must sanitise one. Nothing stops two hosts from choosing different
72
+ conventions.
73
+
74
+ ### C. One MCP host per form
75
+
76
+ Already supported. No change.
77
+
78
+ Pros: zero work and no new surface; isolation is total.
79
+
80
+ Cons: the agent needs one connection per form, or the consumer builds its own
81
+ router. Cross-form work ("copy billing into shipping") spans connections. Undo
82
+ history and presence split per host. This does not scale to dynamic forms. It
83
+ is a workaround, not a model.
84
+
85
+ ## Recommendation
86
+
87
+ **A**, built as a small shared per-host router so the charts, grid and other
88
+ multi-instance bridges can adopt it later. It is the only option that keeps the
89
+ tool list stable while forms come and go, and it needs no consumer change: the
90
+ code that throws today starts working. Keep **B** as the escape hatch only if a
91
+ client turns out to need flat, self-describing tool names. Document **C** as the
92
+ interim answer until A ships.
93
+
94
+ Suggested acceptance tests for A: two forms on one host both drivable; a call
95
+ without `form` while two are mounted is refused with both ids listed; with one
96
+ form mounted every existing call shape still succeeds; disposing one form leaves
97
+ the other drivable and settles only the disposed form's pending writes; a remount
98
+ of the same id re-joins rather than duplicating; `form_list` reflects mounts and
99
+ unmounts.
100
+
101
+ ## As built (0.53.0)
102
+
103
+ - `src/bridges/multi-instance.ts` holds the shared piece, `joinInstanceRouter`.
104
+ It is internal (no entry point). It keeps one router per (host, family) in a
105
+ `WeakMap`, calls the family's `install` once when the first instance joins,
106
+ and calls the disposer `install` returned when the last instance leaves. It
107
+ also resolves the selecting argument by the rules below. If `install` throws
108
+ because a name is held by an unrelated registrant, no router is left behind.
109
+ - `registerFormBridge` builds its handlers per form, with that form's adapter,
110
+ `pendingMode`, `agent` and close handling, then joins the `"form"` router. The
111
+ shared tools are registered once, under the single owner `"form-bridge"`.
112
+ Each one resolves `form` and then calls the chosen form's handler, so the
113
+ activity, presence target and outcome-unknown settling stay per form.
114
+ - Resolution: with exactly one form mounted `form` is optional. With two or
115
+ more, a call without it is an error listing the ids. An id that is not
116
+ mounted is an error listing the ids, even when only one form is mounted, so a
117
+ call aimed at a form that has closed never lands on another one.
118
+ - A registration whose `adapter.id` is already mounted **replaces** it. A
119
+ duplicate cannot be told apart from a remount whose cleanup has not run yet,
120
+ and 0.51.0 already let the same form re-register, so this keeps that
121
+ behaviour. The earlier registration's `dispose()` then leaves the newer one
122
+ in place. A missing or empty `adapter.id` throws.
123
+ - Tool descriptions are now generic (the "Cons" above). `form_describe` still
124
+ returns the form's `id` and `title` in its result.
125
+
126
+ Acceptance tests: `src/bridges/__tests__/forms-multi.test.ts` (the form
127
+ behaviour) and `src/bridges/__tests__/multi-instance.test.ts` (the helper).
128
+
129
+ ### Adopting it in another bridge (charts, grids, code, scene, …)
130
+
131
+ Charts and grids have the same shape as forms did: tools named for the family
132
+ (`chart_set_option`, `grid_sort`), a registrant id carrying `adapter.id`, and
133
+ handlers that close over one adapter. Adopting the router takes four steps:
134
+
135
+ 1. **Lift the tool definitions out of the factory** into a module-level list,
136
+ and add the selecting argument (`chart`, `grid`) to every tool's schema as
137
+ an optional string.
138
+ 2. **Build the handlers per instance** inside `register<X>Bridge`, wrapped with
139
+ `wrapToolWithActivity` using that instance's agent and `screenId`, into a
140
+ `name -> handler` record. Today they are registered directly.
141
+ 3. **Write an `install(router)`** that registers each shared tool under one
142
+ family owner (`"chart-bridge"`). Its handler calls
143
+ `router.resolve(args.<argument>)`, returns the error if resolution fails,
144
+ and otherwise calls `instance.handlers[name](args)`. Add a `<family>_list`
145
+ tool. On a registration failure, withdraw whatever was already registered
146
+ and rethrow, as `installFormTools` does.
147
+ 4. **Join and leave.** Call `joinInstanceRouter(host, { family, argument,
148
+ listTool, install }, adapter.id, { adapter, handlers })`, and make the
149
+ bridge's `dispose()` call `leave()` and then settle anything that
150
+ instance still has pending.
151
+
152
+ Per-bridge points to check:
153
+
154
+ - **Undo** (grid, charts): `pushUndoEntry` closes over the instance's own
155
+ adapter, so it is per instance already. The entry's `bridgeId`
156
+ (`grid:<id>`) should keep naming the instance.
157
+ - **Descriptions** that name the instance today become generic. The
158
+ `<family>_list` result carries the names instead.
159
+ - **Census:** `tool-name-census.test.ts` builds each bridge with a proxy
160
+ adapter whose `id` is not a string. Coerce the id with `String(...)` as
161
+ `registerFormBridge` does, or the census throws.
162
+ - Bridges that already scope their names (screen-doc's `surface`) or are
163
+ inherently singletons (navigation, screens, tui) should not adopt it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-academy/agent-integrations",
3
- "version": "0.51.0",
3
+ "version": "0.53.0",
4
4
  "description": "MCP-driven agent presence in collab sessions: per-session micro-MCP server, pluggable bridges to fancy-* packages, and agent UX components (panel + on-canvas cursor).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bridges/screens.ts"],"names":[],"mappings":";;;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A,IACT,OAAO,IAAA,KAAS;AACd,MAAA,MAAM,QAAA,GAAW,MAAA,CAAO,IAAA,CAAK,MAAA,IAAU,EAAE,CAAA;AACzC,MAAA,MAAM,OAAA,GAAU,QAAQ,WAAA,EAAY;AACpC,MAAA,IAAI,CAAC,QAAQ,IAAA,CAAK,CAAC,MAAM,CAAA,CAAE,EAAA,KAAO,QAAQ,CAAA,EAAG;AAC3C,QAAA,OAAO,WAAA,CAAY,CAAA,8BAAA,EAAiC,QAAQ,CAAA,2BAAA,CAA6B,CAAA;AAAA,MAC3F;AACA,MAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,MAAM,OAAA,CAAQ,UAAU,QAAQ,CAAA,EAAG,CAAA,mCAAA,EAAsC,QAAQ,CAAA,EAAA,CAAI,CAAA;AAC/G,MAAA,IAAI,CAAC,IAAA,CAAK,EAAA,EAAI,OAAO,WAAA,CAAY,KAAK,KAAK,CAAA;AAC3C,MAAA,OAAO,WAAW,CAAA,aAAA,EAAgB,QAAQ,IAAI,EAAE,MAAA,EAAQ,UAAU,CAAA;AAAA,IACpE,CAAA;AAAA,IACA,IAAA;AAAA,IACA,CAAC,IAAA,KAAS,MAAA,CAAO,OAAO,IAAA,CAAK,MAAA,IAAU,EAAE,CAAC;AAAA,GAC5C;AAEA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,QAAA;AAAA,IACJ,KAAA,EAAO,SAAA;AAAA,IACP,SAAS,MAAM;AAAE,MAAA,KAAA,MAAW,CAAA,IAAK,WAAW,CAAA,EAAE;AAAA,IAAG;AAAA,GACnD;AACF","file":"chunk-CP3EHLZJ.js","sourcesContent":["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 { emitActivity } from \"../presence/registry\";\nimport type { AgentTarget } from \"../presence/types\";\n\n/**\n * Loose snapshot of a screen — what's in fancy-screens' ScreenMeta plus\n * the host's optional activity status. Kept here so this bridge has no\n * hard dep on fancy-screens.\n */\nexport type ScreenSnapshot = {\n id: string;\n title?: string;\n /** Whether this screen is the one the human / agent is looking at. */\n active: boolean;\n /** Optional category / kind (e.g. \"form\", \"whiteboard\"). */\n kind?: string;\n};\n\n/**\n * Spec for a dynamically-created screen. The host's `createScreen`\n * implementation looks up `kind` in its template registry and instantiates\n * the matching surface (form / whiteboard / sheet / chart / markdown / etc.).\n */\nexport type ScreenCreateSpec = {\n id: string;\n title?: string;\n /** Template kind. Hosts decide the catalog. */\n kind: string;\n /** Template-specific config. Form: { fields }. Sheet: { headers }. etc. */\n config?: Record<string, unknown>;\n};\n\n/**\n * What a mutating adapter method may resolve to, to acknowledge (or refuse)\n * a commit. `{ ok: false }` is a refusal the agent can act on: `error` is\n * shown to the agent verbatim, so keep it a human-readable sentence, never a\n * stack trace or an internal path. `code` is a machine-readable hint\n * (e.g. `\"conflict\"`) for the host's own use; it is not shown to the agent.\n */\nexport type ScreensAdapterResult = { ok: true } | { ok: false; error: string; code?: string };\n\n/**\n * Return type of every mutating adapter method. A sync `void` return keeps\n * the original behaviour. A Promise makes the bridge WAIT: the tool reports\n * success, and emits its AgentActivity event, only after the promise\n * resolves. A rejection or an `{ ok: false }` result becomes an error result\n * and emits no activity.\n */\nexport type ScreensAdapterCommit = void | Promise<void | ScreensAdapterResult>;\n\n/**\n * Adapter exposes the host's screen-navigation surface to the bridge.\n * Hosts wire this up against react-router, a custom tab state, or the\n * fancy-screens registry — wherever \"current screen\" lives.\n *\n * The optional create / destroy / update hooks let agents author screens\n * dynamically against a host-defined template catalog.\n *\n * Every mutating method may be sync (`void`) or async (`Promise`); see\n * {@link ScreensAdapterCommit}. Return a Promise when the host's commit is\n * authoritative — persisted, or able to refuse or conflict — so the agent is\n * told the truth instead of \"success\" before anything was committed.\n *\n * This bridge pushes NO undo entries: `agent_undo` cannot revert a screens\n * tool. A host that needs undo for navigation or screen authoring must keep\n * its own history.\n */\nexport type ScreensBridgeAdapter = {\n /** List every available screen. */\n listScreens: () => ScreenSnapshot[];\n /** Read which screen is currently active. */\n getActive: () => string | null;\n /** Navigate to a screen by id. Host updates router / tab state. */\n setActive: (screenId: string) => ScreensAdapterCommit;\n /** Optional: instantiate a new screen from a template + config. */\n createScreen?: (spec: ScreenCreateSpec) => ScreensAdapterCommit;\n /** Optional: remove a previously-created screen. */\n destroyScreen?: (screenId: string) => ScreensAdapterCommit;\n /** Optional: shallow-merge new config into an existing screen. */\n updateScreenContent?: (screenId: string, partial: Record<string, unknown>) => ScreensAdapterCommit;\n /** Optional: enumerate the kinds the host knows how to instantiate. */\n listKinds?: () => Array<{ kind: string; label?: string; description?: string; configSchema?: unknown }>;\n};\n\nexport type ScreensBridgeOptions = {\n adapter: ScreensBridgeAdapter;\n agent?: { id: string; name?: string; color?: string };\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\n/**\n * The agent-facing text for a host failure. Only the message is used — never\n * `stack`, which carries file paths — matching the other bridges. A message\n * that itself embeds stack frames is cut at the first frame. A non-Error\n * rejection (a plain object, a response) has no reliable message, so it gets\n * the fallback rather than \"[object Object]\".\n */\nfunction hostErrorMessage(e: unknown, fallback: string): string {\n let msg: string | undefined;\n if (e instanceof Error) msg = e.message;\n else if (typeof e === \"string\") msg = e;\n else if (e && typeof e === \"object\" && typeof (e as { message?: unknown }).message === \"string\") {\n msg = (e as { message: string }).message;\n }\n const firstFrame = msg ? msg.search(/\\n\\s+at\\s/) : -1;\n if (msg && firstFrame >= 0) msg = msg.slice(0, firstFrame);\n msg = msg?.trim();\n return msg ? msg : fallback;\n}\n\ntype CommitOutcome = { ok: true } | { ok: false; error: string };\n\n/** Run one adapter commit, await it, and normalise every way it can fail. */\nasync function commit(run: () => ScreensAdapterCommit, fallback: string): Promise<CommitOutcome> {\n try {\n const r = await run();\n if (r && typeof r === \"object\" && r.ok === false) {\n return { ok: false, error: hostErrorMessage(r.error, fallback) };\n }\n return { ok: true };\n } catch (e) {\n return { ok: false, error: hostErrorMessage(e, fallback) };\n }\n}\n\n/**\n * registerScreensBridge — top-level navigation bridge so agents can\n * switch between screens (`screens_navigate`) and discover what surfaces\n * exist (`screens_list`, `screens_describe_active`).\n *\n * Pair with the per-surface bridges (whiteboard, form, sheet, etc.) so\n * the agent has both navigation and per-screen control.\n */\nexport function registerScreensBridge(\n host: ToolHost,\n options: ScreensBridgeOptions,\n): Bridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const disposers: Array<() => void> = [];\n // The bridge id is also its registrant identity on the host: the same bridge\n // may re-register (a remount), a different one claiming a name is refused.\n const bridgeId = \"screens\";\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\n const target = (screenId: string): AgentTarget => ({\n kind: \"screens\",\n screenId,\n label: `Screen ${screenId}`,\n });\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<any> | any,\n isMutation: boolean,\n targetFromArgs?: (args: JsonObject) => AgentTarget,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try { return await handler(args); }\n catch (e) { return errorResult(hostErrorMessage(e, `${name} failed.`)); }\n };\n const final = isMutation\n ? wrapToolWithActivity(wrapped, {\n toolName: name, agent, kind: \"screens\",\n resolveTarget: ({ args }) => targetFromArgs?.(args) ?? null,\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n { name, description, inputSchema: { type: \"object\", properties: properties as any, required, additionalProperties: false } },\n final as any,\n { owner: bridgeId },\n ),\n );\n };\n\n reg(\n \"screens_list\",\n \"List every screen the host has registered. Returns id, title, active flag, and optional kind.\",\n {},\n [],\n () => {\n const screens = adapter.listScreens();\n const text = screens\n .map((s) => `${s.active ? \"▸\" : \" \"} ${s.id}${s.title ? ` — ${s.title}` : \"\"}${s.kind ? ` [${s.kind}]` : \"\"}`)\n .join(\"\\n\");\n return textResult(text || \"(no screens)\", { screens, active: adapter.getActive() });\n },\n false,\n );\n\n reg(\n \"screens_describe_active\",\n \"Get the currently-active screen id (or null).\",\n {},\n [],\n () => {\n const active = adapter.getActive();\n return textResult(active ?? \"(none)\", { active });\n },\n false,\n );\n\n reg(\n \"screens_list_kinds\",\n \"List the screen kinds (templates) the host knows how to instantiate. Use this before screens_create to know what's available.\",\n {},\n [],\n () => {\n if (!adapter.listKinds) return errorResult(\"Host did not register a kind catalog. Cannot create screens dynamically.\");\n const kinds = adapter.listKinds();\n const text = kinds.map((k) => `${k.kind}${k.label ? ` — ${k.label}` : \"\"}${k.description ? ` (${k.description})` : \"\"}`).join(\"\\n\");\n return textResult(text || \"(no kinds registered)\", kinds);\n },\n false,\n );\n\n reg(\n \"screens_create\",\n \"Instantiate a new screen from a template kind + config. Switches the active view to the new screen.\",\n {\n id: { type: \"string\", description: \"Stable screen id. Must be unique.\" },\n title: { type: \"string\" },\n kind: { type: \"string\", description: \"Template kind — call screens_list_kinds for the catalog.\" },\n config: { type: \"object\", description: \"Template-specific config (e.g. { fields: [...] } for a form).\" },\n },\n [\"id\", \"kind\"],\n async (args) => {\n const createScreen = adapter.createScreen;\n if (!createScreen) return errorResult(\"Host did not provide createScreen.\");\n const id = String(args.id);\n const kind = String(args.kind);\n if (adapter.listScreens().find((s) => s.id === id)) {\n return errorResult(`Screen ${id} already exists. Use screens_destroy first or pick a fresh id.`);\n }\n const created = await commit(() => createScreen({\n id,\n title: typeof args.title === \"string\" ? args.title : undefined,\n kind,\n config: (args.config && typeof args.config === \"object\") ? args.config as Record<string, unknown> : undefined,\n }), `Host failed to create screen \"${id}\".`);\n // Nothing was created, so there is nothing to activate.\n if (!created.ok) return errorResult(created.error);\n\n const activated = await commit(() => adapter.setActive(id), `Host failed to activate screen \"${id}\".`);\n if (!activated.ok) {\n // Partial commit: the screen EXISTS but is not showing. Reported as an\n // error so an agent branching on isError does not go on to tell the\n // human \"look at the new screen\". The create DID commit, though, and\n // every committed mutation must be observable, so its activity is\n // emitted here by hand (wrapToolWithActivity skips error results).\n const state = { id, kind, created: true, activated: false };\n emitActivity({\n agentId: agent.id,\n agentName: agent.name,\n agentColor: agent.color,\n target: target(id),\n action: \"screens_create\",\n timestamp: Date.now(),\n meta: state,\n });\n return {\n ...errorResult(\n `Screen \"${id}\" was created but not activated: ${activated.error} ` +\n \"The screen exists; do not call screens_create again. \" +\n \"Call screens_navigate to show it, or screens_destroy to remove it.\",\n ),\n structuredContent: state,\n };\n }\n return textResult(`Created ${kind} screen \"${id}\"`, { id, kind });\n },\n true,\n (args) => target(String(args.id ?? \"\")),\n );\n\n reg(\n \"screens_destroy\",\n \"Remove a previously-created screen. Active screen falls back to the first remaining one (or null).\",\n { id: { type: \"string\" } },\n [\"id\"],\n async (args) => {\n const destroyScreen = adapter.destroyScreen;\n if (!destroyScreen) return errorResult(\"Host did not provide destroyScreen.\");\n const id = String(args.id);\n if (!adapter.listScreens().find((s) => s.id === id)) {\n return errorResult(`No screen with id ${id}`);\n }\n const done = await commit(() => destroyScreen(id), `Host failed to destroy screen \"${id}\".`);\n if (!done.ok) return errorResult(done.error);\n return textResult(`Destroyed screen ${id}`, { id });\n },\n true,\n (args) => target(String(args.id ?? \"\")),\n );\n\n reg(\n \"screens_set_layout\",\n \"Change the layout of an existing composite screen. Layouts: 'single', 'split-h' (left/right), 'split-v' (top/bottom), 'grid-2x2', 'stack' (tabs).\",\n {\n id: { type: \"string\" },\n layout: { type: \"string\", enum: [\"single\", \"split-h\", \"split-v\", \"grid-2x2\", \"stack\"] },\n },\n [\"id\", \"layout\"],\n async (args) => {\n const updateScreenContent = adapter.updateScreenContent;\n if (!updateScreenContent) return errorResult(\"Host did not provide updateScreenContent.\");\n const id = String(args.id);\n const done = await commit(\n () => updateScreenContent(id, { layout: String(args.layout) }),\n `Host failed to change the layout of screen \"${id}\".`,\n );\n if (!done.ok) return errorResult(done.error);\n return textResult(`Layout of ${args.id} → ${args.layout}`, { id: args.id, layout: args.layout });\n },\n true,\n (args) => target(String(args.id ?? \"\")),\n );\n\n reg(\n \"screens_update_content\",\n \"Merge new config into an existing screen (e.g. add a field to a form, append a sheet column, change chart series).\",\n {\n id: { type: \"string\" },\n partial: { type: \"object\", description: \"Shallow-merged into the screen's config.\" },\n },\n [\"id\", \"partial\"],\n async (args) => {\n const updateScreenContent = adapter.updateScreenContent;\n if (!updateScreenContent) return errorResult(\"Host did not provide updateScreenContent.\");\n const id = String(args.id);\n const partial = (args.partial && typeof args.partial === \"object\") ? args.partial as Record<string, unknown> : {};\n const done = await commit(() => updateScreenContent(id, partial), `Host failed to update screen \"${id}\".`);\n if (!done.ok) return errorResult(done.error);\n return textResult(`Updated content of ${id}`, { id });\n },\n true,\n (args) => target(String(args.id ?? \"\")),\n );\n\n reg(\n \"screens_navigate\",\n \"Switch the human's view to a different screen. The host updates its router / tab state and re-renders.\",\n { screen: { type: \"string\", description: \"Screen id to activate.\" } },\n [\"screen\"],\n async (args) => {\n const screenId = String(args.screen ?? \"\");\n const screens = adapter.listScreens();\n if (!screens.find((s) => s.id === screenId)) {\n return errorResult(`No screen registered with id \"${screenId}\". Call screens_list first.`);\n }\n const done = await commit(() => adapter.setActive(screenId), `Host failed to navigate to screen \"${screenId}\".`);\n if (!done.ok) return errorResult(done.error);\n return textResult(`Navigated to ${screenId}`, { screen: screenId });\n },\n true,\n (args) => target(String(args.screen ?? \"\")),\n );\n\n return {\n id: bridgeId,\n title: \"Screens\",\n dispose: () => { for (const d of disposers) d(); },\n };\n}\n"]}