@particle-academy/agent-integrations 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/bridges/artboard.d.cts +78 -0
  2. package/dist/bridges/artboard.d.ts +78 -0
  3. package/dist/bridges/charts.d.cts +3 -3
  4. package/dist/bridges/charts.d.ts +3 -3
  5. package/dist/bridges/code.d.cts +3 -3
  6. package/dist/bridges/code.d.ts +3 -3
  7. package/dist/bridges/flow.d.cts +3 -3
  8. package/dist/bridges/flow.d.ts +3 -3
  9. package/dist/bridges/forms.d.cts +3 -3
  10. package/dist/bridges/forms.d.ts +3 -3
  11. package/dist/bridges/scene.d.cts +3 -3
  12. package/dist/bridges/scene.d.ts +3 -3
  13. package/dist/bridges/screens.d.cts +3 -3
  14. package/dist/bridges/screens.d.ts +3 -3
  15. package/dist/bridges/sheets.d.cts +3 -3
  16. package/dist/bridges/sheets.d.ts +3 -3
  17. package/dist/bridges/slides.d.cts +58 -0
  18. package/dist/bridges/slides.d.ts +58 -0
  19. package/dist/bridges/whiteboard.d.cts +3 -3
  20. package/dist/bridges/whiteboard.d.ts +3 -3
  21. package/dist/bridges-artboard.cjs +576 -0
  22. package/dist/bridges-artboard.cjs.map +1 -0
  23. package/dist/bridges-artboard.js +418 -0
  24. package/dist/bridges-artboard.js.map +1 -0
  25. package/dist/bridges-slides.cjs +438 -0
  26. package/dist/bridges-slides.cjs.map +1 -0
  27. package/dist/bridges-slides.js +6 -0
  28. package/dist/bridges-slides.js.map +1 -0
  29. package/dist/chunk-NE3GIGQD.js +384 -0
  30. package/dist/chunk-NE3GIGQD.js.map +1 -0
  31. package/dist/components/SharedWhiteboard/index.d.cts +1 -1
  32. package/dist/components/SharedWhiteboard/index.d.ts +1 -1
  33. package/dist/index.cjs +377 -0
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +9 -7
  36. package/dist/index.d.ts +9 -7
  37. package/dist/index.js +3 -2
  38. package/dist/index.js.map +1 -1
  39. package/dist/mcp/index.d.cts +5 -5
  40. package/dist/mcp/index.d.ts +5 -5
  41. package/dist/presence/index.d.cts +1 -1
  42. package/dist/presence/index.d.ts +1 -1
  43. package/dist/{server-BsSwfemr.d.cts → server-C2OpfPEo.d.cts} +3 -3
  44. package/dist/{server-Du3-IGqM.d.ts → server-CKAqFTyc.d.ts} +3 -3
  45. package/dist/sharing/index.d.cts +4 -4
  46. package/dist/sharing/index.d.ts +4 -4
  47. package/dist/sheets-adapter.d.cts +3 -3
  48. package/dist/sheets-adapter.d.ts +3 -3
  49. package/dist/{token-CrJF76oH.d.cts → token-C1O22GxJ.d.cts} +1 -1
  50. package/dist/{token-CrJF76oH.d.ts → token-C1O22GxJ.d.ts} +1 -1
  51. package/dist/{tool-host-BQuUygLF.d.cts → tool-host-CX3WFXgh.d.cts} +1 -1
  52. package/dist/{tool-host-C8JMMGYq.d.ts → tool-host-DldwGNqR.d.ts} +1 -1
  53. package/dist/{types-aOQLTW0E.d.cts → types-C2zdUpzn.d.cts} +1 -1
  54. package/dist/{types-aOQLTW0E.d.ts → types-C2zdUpzn.d.ts} +1 -1
  55. package/dist/{types-CCSBGW9T.d.cts → types-Cq5u8MJ8.d.cts} +1 -1
  56. package/dist/{types-DIVNcIQO.d.ts → types-DyaHnqNC.d.ts} +1 -1
  57. package/dist/undo/index.d.cts +2 -2
  58. package/dist/undo/index.d.ts +2 -2
  59. package/package.json +17 -4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp/server.ts","../src/presence/registry.ts","../src/presence/wrap-tool-with-activity.ts","../src/undo/undo-stack.ts","../src/undo/undo-tools.ts","../src/bridges/artboard.ts"],"names":["history"],"mappings":";;;AAgLO,SAAS,UAAA,CAAW,MAAc,UAAA,EAAkC;AACzE,EAAA,OAAO;AAAA,IACL,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,CAAA;AAAA,IAChC,GAAI,UAAA,KAAe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AAA,OAAO,WAAW,CAAA,gBAAA,EAAc,IAAA,CAAK,UAAU,IAAI,CAAC,IAAI,IAAI,CAAA;AAAA,IAC9D,CAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,UAAA;AAAA,IACJ,KAAA,EAAO,UAAA;AAAA,IACP,SAAS,MAAM;AACb,MAAA,KAAA,MAAW,CAAA,IAAK,WAAW,CAAA,EAAE;AAC7B,MAAA,OAAA,CAAQ,iBAAiB,IAAI,CAAA;AAAA,IAC/B;AAAA,GACF;AACF","file":"bridges-artboard.cjs","sourcesContent":["import {\n type CallToolResult,\n type JsonObject,\n type JsonRpcMessage,\n type JsonRpcRequest,\n type JsonRpcId,\n type RegisteredTool,\n type ServerCapabilities,\n type ServerInfo,\n type ToolDefinition,\n type ToolHandler,\n JSONRPC_INTERNAL_ERROR,\n JSONRPC_INVALID_PARAMS,\n JSONRPC_METHOD_NOT_FOUND,\n MCP_PROTOCOL_VERSION,\n} from \"./types\";\nimport { ToolRegistry } from \"./tool-host\";\n\nexport type McpServerOptions = {\n info: ServerInfo;\n /** Defaults to { tools: { listChanged: true } } */\n capabilities?: ServerCapabilities;\n /** Free-text instructions surfaced to clients during initialize. */\n instructions?: string;\n};\n\nexport type Transport = {\n /** Called by the server when it has a message to deliver to the client. */\n send: (message: JsonRpcMessage) => void;\n /** Called by the server when it's torn down so the transport can clean up. */\n close?: () => void;\n};\n\n/**\n * MicroMcpServer — protocol-level MCP server, transport-agnostic.\n *\n * Use it like:\n *\n * const server = new MicroMcpServer({ info: { name: \"session\", version: \"0.1\" } });\n * server.registerTool({ name: \"...\", inputSchema: { type: \"object\" } }, async (args) => ({...}));\n * const transport = new InProcessTransport();\n * server.attach(transport);\n * transport.deliver({ ... }); // client → server frames\n *\n * The same server can serve multiple transports (e.g. an in-process agent\n * AND a relayed external client) by attaching each one.\n */\nexport class MicroMcpServer extends ToolRegistry {\n private transports = new Set<Transport>();\n private notifyListChangedScheduled = false;\n\n readonly info: ServerInfo;\n readonly capabilities: ServerCapabilities;\n readonly instructions?: string;\n\n constructor(options: McpServerOptions) {\n super();\n this.info = options.info;\n this.capabilities = options.capabilities ?? { tools: { listChanged: true } };\n this.instructions = options.instructions;\n }\n\n attach(transport: Transport): () => void {\n this.transports.add(transport);\n return () => this.detach(transport);\n }\n\n detach(transport: Transport): void {\n if (this.transports.delete(transport)) {\n transport.close?.();\n }\n }\n\n unregisterTool(name: string): void {\n if (this.tools.delete(name)) {\n this.scheduleListChangedNotification();\n }\n }\n\n protected onToolsChanged(): void {\n this.scheduleListChangedNotification();\n }\n\n /**\n * Receive a JSON-RPC frame from a client (called by the transport).\n * The transport is responsible for sending the response back.\n */\n async receive(transport: Transport, message: JsonRpcMessage): Promise<void> {\n if (!(\"method\" in message)) return; // It's a response, not a request — ignore.\n\n const isNotification = !(\"id\" in message);\n if (isNotification) {\n // Notifications are fire-and-forget. We ignore unknown methods.\n return;\n }\n\n const request = message as JsonRpcRequest;\n try {\n const result = await this.handle(request);\n transport.send({ jsonrpc: \"2.0\", id: request.id, result });\n } catch (err) {\n transport.send({\n jsonrpc: \"2.0\",\n id: request.id,\n error: this.toRpcError(err),\n });\n }\n }\n\n private async handle(request: JsonRpcRequest): Promise<any> {\n const { method, params } = request;\n switch (method) {\n case \"initialize\":\n return {\n protocolVersion: MCP_PROTOCOL_VERSION,\n capabilities: this.capabilities,\n serverInfo: this.info,\n ...(this.instructions ? { instructions: this.instructions } : {}),\n };\n\n case \"tools/list\":\n return { tools: this.listTools() };\n\n case \"tools/call\": {\n const name = params?.name;\n const args = (params?.arguments ?? {}) as JsonObject;\n if (typeof name !== \"string\") {\n throw rpcError(JSONRPC_INVALID_PARAMS, \"tools/call requires `name`\");\n }\n const tool = this.tools.get(name);\n if (!tool) {\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unknown tool: ${name}`);\n }\n const result = await tool.handler(args);\n return result satisfies CallToolResult;\n }\n\n case \"ping\":\n return {};\n\n default:\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unsupported method: ${method}`);\n }\n }\n\n private scheduleListChangedNotification(): void {\n if (this.notifyListChangedScheduled) return;\n this.notifyListChangedScheduled = true;\n queueMicrotask(() => {\n this.notifyListChangedScheduled = false;\n this.broadcast({ jsonrpc: \"2.0\", method: \"notifications/tools/list_changed\" });\n });\n }\n\n private broadcast(message: JsonRpcMessage): void {\n for (const t of this.transports) t.send(message);\n }\n\n private toRpcError(err: unknown): { code: number; message: string; data?: any } {\n if (err && typeof err === \"object\" && \"code\" in err && \"message\" in err) {\n return err as any;\n }\n return {\n code: JSONRPC_INTERNAL_ERROR,\n message: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nexport function rpcError(code: number, message: string, data?: any) {\n return { code, message, ...(data !== undefined ? { data } : {}) };\n}\n\n/**\n * Helper to build a CallToolResult from a string or structured value.\n */\nexport function textResult(text: string, structured?: any): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n ...(structured !== undefined ? { structuredContent: structured } : {}),\n };\n}\n\nexport function errorResult(text: string): CallToolResult {\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n// Internal helper so the JsonRpcId import isn't dropped by tsup\ntype _KeepIdImport = JsonRpcId;\n","import type { ActivityFilter, AgentActivityEvent, AgentActivityListener } from \"./types\";\n\n/**\n * In-process registry of agent activity events. Bridges call `emitActivity`\n * after a tool runs; React hooks + the SSE relay subscribe via\n * `onActivity()`.\n *\n * Holds a short scrollback of recent events (default 200) so newly-mounted\n * subscribers can render the recent past — useful for activity-log UIs\n * that rejoin a session mid-stream.\n */\n\nconst HISTORY_CAP = 200;\n\nconst listeners = new Set<AgentActivityListener>();\nconst history: AgentActivityEvent[] = [];\n\n/** Emit an activity event. All current listeners receive it synchronously. */\nexport function emitActivity(event: AgentActivityEvent): void {\n history.push(event);\n if (history.length > HISTORY_CAP) history.splice(0, history.length - HISTORY_CAP);\n for (const l of listeners) l(event);\n}\n\n/**\n * Subscribe to all events (or a filtered subset). Returns an unsubscribe\n * function. Filter checks all provided keys with strict equality; omit a\n * key to ignore it.\n */\nexport function onActivity(listener: AgentActivityListener, filter?: ActivityFilter): () => void {\n const wrapped: AgentActivityListener = filter\n ? (e) => { if (matches(e, filter)) listener(e); }\n : listener;\n listeners.add(wrapped);\n return () => listeners.delete(wrapped);\n}\n\n/** Read the recent history (newest last). Optional filter. */\nexport function readActivityHistory(filter?: ActivityFilter): AgentActivityEvent[] {\n if (!filter) return history.slice();\n return history.filter((e) => matches(e, filter));\n}\n\n/** Wipe history + clear listeners. Test/teardown helper. */\nexport function resetActivityRegistry(): void {\n listeners.clear();\n history.length = 0;\n}\n\nfunction matches(e: AgentActivityEvent, f: ActivityFilter): boolean {\n if (f.agentId !== undefined && e.agentId !== f.agentId) return false;\n if (f.screenId !== undefined && e.target.screenId !== f.screenId) return false;\n if (f.kind !== undefined && e.target.kind !== f.kind) return false;\n return true;\n}\n","import type { CallToolResult } from \"../mcp/types\";\nimport { emitActivity } from \"./registry\";\nimport type { AgentTarget } from \"./types\";\n\nexport type ActivityAgent = { id: string; name?: string; color?: string };\n\nexport type ActivityResolverContext<TArgs = Record<string, unknown>> = {\n /** Tool name as registered. */\n toolName: string;\n /** Arguments the tool was called with. */\n args: TArgs;\n /** The CallToolResult the underlying handler produced. */\n result: CallToolResult;\n};\n\n/**\n * Resolves an `AgentTarget` for an executed tool. Bridges declare one of\n * these per registration so the wrapper knows which surface / element /\n * screen the activity belongs to.\n *\n * The resolver runs AFTER the tool handler so it can inspect the result\n * (e.g. read a newly-created item id from `structuredContent`).\n */\nexport type ActivityTargetResolver<TArgs = Record<string, unknown>> = (\n ctx: ActivityResolverContext<TArgs>,\n) => AgentTarget | null;\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n args: TArgs,\n) => Promise<CallToolResult> | CallToolResult;\n\n/**\n * wrapToolWithActivity — decorate a bridge tool handler so every successful\n * call emits an `AgentActivityEvent`. Returns a new handler with the same shape.\n *\n * Usage in a bridge:\n *\n * server.registerTool(\n * definition,\n * wrapToolWithActivity(\n * handler,\n * { agent, kind: \"whiteboard\", resolveTarget: ({ args }) => ({\n * kind: \"whiteboard\", elementId: args.id as string,\n * }) },\n * ),\n * );\n */\nexport function wrapToolWithActivity<TArgs = Record<string, unknown>>(\n handler: ToolHandler<TArgs>,\n options: {\n toolName: string;\n agent: ActivityAgent;\n /** Optional fancy-screens screen id this bridge is scoped to. */\n screenId?: string;\n /** Default target kind if the resolver returns one without `kind`. */\n kind: AgentTarget[\"kind\"];\n /** Per-call resolver. Return `null` to skip emitting (e.g. for read-only tools). */\n resolveTarget?: ActivityTargetResolver<TArgs>;\n /** Optional ttl override. */\n ttlMs?: number;\n },\n): ToolHandler<TArgs> {\n return async (args) => {\n const result = await handler(args);\n if (result.isError) return result;\n\n let target: AgentTarget | null;\n if (options.resolveTarget) {\n target = options.resolveTarget({ toolName: options.toolName, args, result });\n } else {\n target = { kind: options.kind, screenId: options.screenId };\n }\n if (!target) return result;\n\n emitActivity({\n agentId: options.agent.id,\n agentName: options.agent.name,\n agentColor: options.agent.color,\n target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },\n action: options.toolName,\n timestamp: Date.now(),\n meta: extractMeta(result),\n ttlMs: options.ttlMs,\n });\n return result;\n };\n}\n\nfunction extractMeta(result: CallToolResult): Record<string, unknown> | undefined {\n const sc = result.structuredContent;\n if (sc && typeof sc === \"object\" && !Array.isArray(sc)) {\n return sc as Record<string, unknown>;\n }\n return undefined;\n}\n","/**\n * Generic undo/redo stack keyed by `agentId`. Each entry holds:\n * - `do` — re-applies the action (for redo)\n * - `undo` — reverses it\n * - `label` — human-readable summary surfaced in agent_history\n *\n * Bridges register entries by calling `pushUndoEntry` after a successful\n * mutation. The corresponding MCP tools (`agent_undo`, `agent_redo`,\n * `agent_history`) are registered once per server via `registerUndoTools`.\n *\n * Stacks are per-agent so multiple agents can rewind independently.\n */\n\nexport type UndoEntry = {\n /** Wall-clock ms. */\n timestamp: number;\n /** Bridge id (e.g. \"whiteboard\", \"form:signup\"). */\n bridgeId: string;\n /** Tool name that produced the entry. */\n action: string;\n /** Short human label, e.g. `Added sticky n_abc`. */\n label: string;\n /** Reverse the action. */\n undo: () => void | Promise<void>;\n /** Re-apply the action (used when redoing after an undo). */\n redo: () => void | Promise<void>;\n};\n\ntype Stack = { past: UndoEntry[]; future: UndoEntry[] };\n\nconst stacks = new Map<string, Stack>();\nconst CAP = 200;\n\nfunction getStack(agentId: string): Stack {\n let s = stacks.get(agentId);\n if (!s) {\n s = { past: [], future: [] };\n stacks.set(agentId, s);\n }\n return s;\n}\n\n/** Push a new undo entry on the agent's stack. Clears the redo (future) stack. */\nexport function pushUndoEntry(agentId: string, entry: UndoEntry): void {\n const s = getStack(agentId);\n s.past.push(entry);\n if (s.past.length > CAP) s.past.splice(0, s.past.length - CAP);\n s.future.length = 0;\n}\n\n/** Pop and undo the most recent entry. Returns the entry that ran, or null. */\nexport async function undoOne(agentId: string): Promise<UndoEntry | null> {\n const s = getStack(agentId);\n const entry = s.past.pop();\n if (!entry) return null;\n await entry.undo();\n s.future.push(entry);\n return entry;\n}\n\n/** Re-apply the most recently undone entry. Returns it, or null if no future. */\nexport async function redoOne(agentId: string): Promise<UndoEntry | null> {\n const s = getStack(agentId);\n const entry = s.future.pop();\n if (!entry) return null;\n await entry.redo();\n s.past.push(entry);\n return entry;\n}\n\n/** Read the past stack (oldest first). */\nexport function readHistory(agentId: string): UndoEntry[] {\n return getStack(agentId).past.slice();\n}\n\n/** Wipe an agent's stacks. */\nexport function clearStack(agentId: string): void {\n stacks.delete(agentId);\n}\n\n/** Test/teardown helper. */\nexport function resetAllUndoStacks(): void {\n stacks.clear();\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport { readHistory, redoOne, undoOne } from \"./undo-stack\";\n\nexport type UndoToolsOptions = {\n /** Default agent id when the caller doesn't pass one. */\n defaultAgentId?: string;\n};\n\n/**\n * Idempotent tracker so multiple bridges on the same server only register\n * agent_undo / agent_redo / agent_history once.\n */\nconst installedHosts = new WeakSet<ToolHost>();\n\n/**\n * ensureUndoToolsRegistered — bridges call this on construction. Safe to\n * call repeatedly with the same server; subsequent calls are no-ops.\n */\nexport function ensureUndoToolsRegistered(host: ToolHost, options: UndoToolsOptions = {}): void {\n if (installedHosts.has(host)) return;\n installedHosts.add(host);\n registerUndoTools(host, options);\n}\n\n/**\n * registerUndoTools — add agent_undo / agent_redo / agent_history to the\n * server. Returns a disposer that unregisters all three.\n */\nexport function registerUndoTools(host: ToolHost, options: UndoToolsOptions = {}): () => void {\n const defaultAgent = options.defaultAgentId ?? \"agent\";\n const disposers: Array<() => void> = [];\n const agentOf = (args: any): string =>\n typeof args?.agentId === \"string\" ? args.agentId : defaultAgent;\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_undo\",\n description: \"Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await undoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to undo.\");\n return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_redo\",\n description: \"Redo the most recently undone action.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await redoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to redo.\");\n return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_history\",\n description: \"List the agent's undo stack (oldest first). Useful for understanding what's reversible.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const history = readHistory(agentOf(args)).map(serialize);\n const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join(\"\\n\");\n return textResult(text || \"(empty)\", history);\n },\n ),\n );\n\n return () => disposers.forEach((d) => d());\n}\n\nfunction serialize(entry: import(\"./undo-stack\").UndoEntry) {\n return {\n timestamp: entry.timestamp,\n bridgeId: entry.bridgeId,\n action: entry.action,\n label: entry.label,\n };\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport type { AgentTarget } from \"../presence/types\";\nimport { pushUndoEntry } from \"../undo/undo-stack\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\n\n/**\n * Transport-level JSON shapes. These intentionally mirror fancy-artboard's\n * public `ArtBoardValue` but are defined LOCALLY so this bridge builds\n * independently of the sibling package — they are plain JSON crossing the\n * MCP wire, not the live component types. Keep them in sync with\n * @particle-academy/fancy-artboard's public surface.\n */\ntype Viewport = { x: number; y: number; zoom: number };\ntype ArtPieceContent =\n | { kind: \"image\"; src: string; alt?: string }\n | { kind: \"html\"; html: string }\n | { kind: \"node\" };\ntype ArtPieceData = {\n id: string;\n label?: string;\n width?: number;\n height?: number;\n content: ArtPieceContent;\n pending?: boolean;\n};\ntype ArtSectionData = {\n id: string;\n title: string;\n subtitle?: string;\n pieces: ArtPieceData[];\n};\ntype ArtBoardValue = { sections: ArtSectionData[] };\n\n/**\n * State accessors / mutators the bridge needs from the host. The host owns\n * artboard state (controlled props on fancy-artboard components); the bridge\n * calls into these to read or change it.\n */\nexport type ArtboardBridgeAdapter = {\n getValue: () => ArtBoardValue;\n setValue: (next: ArtBoardValue | ((prev: ArtBoardValue) => ArtBoardValue)) => void;\n getViewport: () => Viewport;\n setViewport: (next: Viewport) => void;\n getFocus: () => string | null;\n setFocus: (id: string | null) => void;\n /** Optional: agent presence cursor (for the visualizer). */\n setAgentCursor?: (cursor: { x: number; y: number } | null) => void;\n};\n\nexport type ArtboardBridgeOptions = {\n adapter: ArtboardBridgeAdapter;\n /** Identity used when the agent stamps authorship / cursor. */\n agent?: { id: string; name?: string; color?: string };\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\nconst num = (v: unknown, fallback?: number): number =>\n typeof v === \"number\" && Number.isFinite(v) ? v : fallback ?? 0;\nconst str = (v: unknown, fallback = \"\"): string => (typeof v === \"string\" ? v : fallback);\n\nconst newId = (prefix: string) =>\n `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`;\n\n/** Deep-clone helper for snapshotting pieces/sections for undo closures. */\nconst clone = <T,>(v: T): T => JSON.parse(JSON.stringify(v)) as T;\n\n/** Coerce arbitrary JSON into a valid ArtPieceContent, defaulting to a node. */\nconst coerceContent = (v: unknown): ArtPieceContent => {\n if (v && typeof v === \"object\") {\n const c = v as Record<string, unknown>;\n if (c.kind === \"image\") return { kind: \"image\", src: str(c.src), ...(c.alt !== undefined ? { alt: str(c.alt) } : {}) };\n if (c.kind === \"html\") return { kind: \"html\", html: str(c.html) };\n if (c.kind === \"node\") return { kind: \"node\" };\n }\n return { kind: \"node\" };\n};\n\n/**\n * registerArtboardBridge — wires a full MCP tool set against a fancy-artboard\n * session controlled by the host. Returns a Bridge handle the host can dispose\n * to tear everything down.\n */\nexport function registerArtboardBridge(\n host: ToolHost,\n options: ArtboardBridgeOptions,\n): Bridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const disposers: Array<() => void> = [];\n\n // Register agent_undo / agent_redo / agent_history once per server. Idempotent.\n ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n\n // Activity-target resolver shared by every mutation tool. Pulls the touched\n // piece/section id from the result (structuredContent) when present, falling\n // back to the args id for rename/remove/focus tools.\n const abTarget = (args: any, result: any): AgentTarget => ({\n kind: \"artboard\",\n id:\n (result?.structuredContent?.id as string | undefined) ??\n (args?.pieceId as string | undefined) ??\n (args?.sectionId as string | undefined),\n } as AgentTarget);\n\n const reg = (\n name: string,\n description: string,\n inputProperties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<any> | any,\n /** Optional: resolve the activity target so the presence layer can render\n * a focus indicator on the touched element. Read tools omit this. */\n resolveTarget?: (args: JsonObject, result: any) => AgentTarget | null,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n return errorResult(e instanceof Error ? e.message : String(e));\n }\n };\n const final = resolveTarget\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent: { id: agent.id, name: agent.name, color: agent.color },\n kind: \"artboard\",\n resolveTarget: ({ args, result }) => resolveTarget(args, result),\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n {\n name,\n description,\n inputSchema: {\n type: \"object\",\n properties: inputProperties as any,\n required,\n additionalProperties: false,\n },\n },\n final as any,\n ),\n );\n };\n\n // ───────────── Read tools ─────────────\n\n reg(\"artboard_get_state\", \"Get the full board state: viewport, focus, all sections and pieces.\", {}, [], () => {\n const state = {\n viewport: adapter.getViewport(),\n focus: adapter.getFocus(),\n sections: adapter.getValue().sections,\n };\n return textResult(JSON.stringify(state, null, 2), state);\n });\n\n reg(\"artboard_list_pieces\", \"List sections and their pieces with id, label, and content kind.\", {}, [], () => {\n const lines: string[] = [];\n const summary: Array<{ sectionId: string; title: string; pieces: Array<{ id: string; label?: string; kind: string; pending?: boolean }> }> = [];\n for (const s of adapter.getValue().sections) {\n lines.push(`section ${s.id}: \"${s.title}\"`);\n const pieces = s.pieces.map((p) => ({\n id: p.id,\n ...(p.label !== undefined ? { label: p.label } : {}),\n kind: p.content.kind,\n ...(p.pending ? { pending: true } : {}),\n }));\n for (const p of s.pieces) {\n lines.push(` piece ${p.id}: ${p.label ? `\"${p.label}\" ` : \"\"}[${p.content.kind}]${p.pending ? \" (pending)\" : \"\"}`);\n }\n summary.push({ sectionId: s.id, title: s.title, pieces });\n }\n return textResult(lines.join(\"\\n\") || \"(empty board)\", summary);\n });\n\n // ───────────── Piece tools ─────────────\n\n reg(\n \"artboard_add_piece\",\n \"Add a piece to a section. New agent-added pieces default to pending:true (trust-but-verify — a human confirms before it is final).\",\n {\n sectionId: { type: \"string\" },\n piece: {\n type: \"object\",\n description: \"Piece spec: { label?, width?, height?, content }. content is { kind: 'image', src, alt? } | { kind: 'html', html } | { kind: 'node' }.\",\n },\n index: { type: \"number\", description: \"Insertion index within the section. Defaults to the end.\" },\n },\n [\"sectionId\", \"piece\"],\n (args) => {\n const sectionId = str(args.sectionId);\n const section = adapter.getValue().sections.find((s) => s.id === sectionId);\n if (!section) return errorResult(`No section with id ${sectionId}`);\n const spec = (args.piece ?? {}) as Record<string, unknown>;\n const piece: ArtPieceData = {\n id: newId(\"p\"),\n ...(spec.label !== undefined ? { label: str(spec.label) } : {}),\n ...(spec.width !== undefined ? { width: num(spec.width) } : {}),\n ...(spec.height !== undefined ? { height: num(spec.height) } : {}),\n content: coerceContent(spec.content),\n pending: true,\n };\n const insertAt =\n args.index !== undefined ? Math.max(0, Math.min(num(args.index), section.pieces.length)) : section.pieces.length;\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId ? s : { ...s, pieces: [...s.pieces.slice(0, insertAt), piece, ...s.pieces.slice(insertAt)] },\n ),\n }));\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_add_piece\",\n label: `Added piece ${piece.id} to ${sectionId}`,\n undo: () =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId ? s : { ...s, pieces: s.pieces.filter((p) => p.id !== piece.id) },\n ),\n })),\n redo: () =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId ? s : { ...s, pieces: [...s.pieces.slice(0, insertAt), piece, ...s.pieces.slice(insertAt)] },\n ),\n })),\n });\n return textResult(`Added piece ${piece.id} to section ${sectionId} (pending)`, piece);\n },\n abTarget,\n );\n\n reg(\n \"artboard_remove_piece\",\n \"Remove a piece by id.\",\n { pieceId: { type: \"string\" } },\n [\"pieceId\"],\n (args) => {\n const pieceId = str(args.pieceId);\n let removed: ArtPieceData | null = null;\n let fromSection: string | null = null;\n let oldIndex = -1;\n for (const s of adapter.getValue().sections) {\n const idx = s.pieces.findIndex((p) => p.id === pieceId);\n if (idx !== -1) {\n removed = clone(s.pieces[idx]);\n fromSection = s.id;\n oldIndex = idx;\n break;\n }\n }\n if (!removed || fromSection === null) return errorResult(`No piece with id ${pieceId}`);\n const sectionId = fromSection;\n const snapshot = removed;\n const at = oldIndex;\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId ? s : { ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) },\n ),\n }));\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_remove_piece\",\n label: `Removed piece ${pieceId}`,\n undo: () =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId ? s : { ...s, pieces: [...s.pieces.slice(0, at), clone(snapshot), ...s.pieces.slice(at)] },\n ),\n })),\n redo: () =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId ? s : { ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) },\n ),\n })),\n });\n return textResult(`Removed piece ${pieceId}`, { id: pieceId });\n },\n abTarget,\n );\n\n reg(\n \"artboard_reorder_piece\",\n \"Move a piece to a new index, optionally into a different section.\",\n {\n pieceId: { type: \"string\" },\n sectionId: { type: \"string\", description: \"Target section id. Defaults to the piece's current section.\" },\n toIndex: { type: \"number\" },\n },\n [\"pieceId\", \"toIndex\"],\n (args) => {\n const pieceId = str(args.pieceId);\n const before = adapter.getValue();\n // Locate the piece.\n let piece: ArtPieceData | null = null;\n let srcSection: string | null = null;\n for (const s of before.sections) {\n const found = s.pieces.find((p) => p.id === pieceId);\n if (found) {\n piece = found;\n srcSection = s.id;\n break;\n }\n }\n if (!piece || srcSection === null) return errorResult(`No piece with id ${pieceId}`);\n const dstSection = args.sectionId !== undefined ? str(args.sectionId) : srcSection;\n if (!before.sections.some((s) => s.id === dstSection)) return errorResult(`No section with id ${dstSection}`);\n const toIndex = Math.max(0, num(args.toIndex));\n const moving = piece;\n const snapshot = clone(before);\n adapter.setValue((prev) => {\n // Remove from wherever it currently is.\n const stripped = prev.sections.map((s) => ({ ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) }));\n return {\n sections: stripped.map((s) => {\n if (s.id !== dstSection) return s;\n const clamped = Math.min(toIndex, s.pieces.length);\n return { ...s, pieces: [...s.pieces.slice(0, clamped), moving, ...s.pieces.slice(clamped)] };\n }),\n };\n });\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_reorder_piece\",\n label: `Reordered piece ${pieceId}`,\n undo: () => adapter.setValue(() => clone(snapshot)),\n redo: () =>\n adapter.setValue((prev) => {\n const stripped = prev.sections.map((s) => ({ ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) }));\n return {\n sections: stripped.map((s) => {\n if (s.id !== dstSection) return s;\n const clamped = Math.min(toIndex, s.pieces.length);\n return { ...s, pieces: [...s.pieces.slice(0, clamped), moving, ...s.pieces.slice(clamped)] };\n }),\n };\n }),\n });\n return textResult(`Reordered piece ${pieceId} → ${dstSection}[${toIndex}]`, { id: pieceId, sectionId: dstSection, toIndex });\n },\n abTarget,\n );\n\n reg(\n \"artboard_rename_piece\",\n \"Set a piece's label.\",\n { pieceId: { type: \"string\" }, label: { type: \"string\" } },\n [\"pieceId\", \"label\"],\n (args) => {\n const pieceId = str(args.pieceId);\n const label = str(args.label);\n const existing = adapter.getValue().sections.flatMap((s) => s.pieces).find((p) => p.id === pieceId);\n if (!existing) return errorResult(`No piece with id ${pieceId}`);\n const prevLabel = existing.label;\n const apply = (l: string | undefined) =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) => ({\n ...s,\n pieces: s.pieces.map((p) => (p.id !== pieceId ? p : { ...p, ...(l !== undefined ? { label: l } : {}) })),\n })),\n }));\n apply(label);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_rename_piece\",\n label: `Renamed piece ${pieceId}`,\n undo: () => apply(prevLabel),\n redo: () => apply(label),\n });\n return textResult(`Renamed piece ${pieceId} → \"${label}\"`, { id: pieceId, label });\n },\n abTarget,\n );\n\n reg(\n \"artboard_set_piece_content\",\n \"Replace a piece's content. content is { kind: 'image', src, alt? } | { kind: 'html', html } | { kind: 'node' }.\",\n { pieceId: { type: \"string\" }, content: { type: \"object\" } },\n [\"pieceId\", \"content\"],\n (args) => {\n const pieceId = str(args.pieceId);\n const existing = adapter.getValue().sections.flatMap((s) => s.pieces).find((p) => p.id === pieceId);\n if (!existing) return errorResult(`No piece with id ${pieceId}`);\n const prevContent = clone(existing.content);\n const nextContent = coerceContent(args.content);\n const apply = (c: ArtPieceContent) =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) => ({\n ...s,\n pieces: s.pieces.map((p) => (p.id !== pieceId ? p : { ...p, content: clone(c) })),\n })),\n }));\n apply(nextContent);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_set_piece_content\",\n label: `Set content of piece ${pieceId}`,\n undo: () => apply(prevContent),\n redo: () => apply(nextContent),\n });\n return textResult(`Set content of piece ${pieceId} → ${nextContent.kind}`, { id: pieceId, content: nextContent });\n },\n abTarget,\n );\n\n reg(\n \"artboard_focus_piece\",\n \"Focus a piece by id (or pass null to clear focus).\",\n { pieceId: { type: [\"string\", \"null\"] } },\n [],\n (args) => {\n const raw = args.pieceId;\n const pieceId = typeof raw === \"string\" ? raw : null;\n if (pieceId !== null && !adapter.getValue().sections.some((s) => s.pieces.some((p) => p.id === pieceId))) {\n return errorResult(`No piece with id ${pieceId}`);\n }\n adapter.setFocus(pieceId);\n return textResult(pieceId ? `Focused piece ${pieceId}` : \"Cleared focus\", { id: pieceId });\n },\n abTarget,\n );\n\n // ───────────── Section tools ─────────────\n\n reg(\n \"artboard_add_section\",\n \"Add a section. Provide an explicit id or one is generated.\",\n {\n section: { type: \"object\", description: \"Section spec: { id?, title, subtitle? }.\" },\n index: { type: \"number\", description: \"Insertion index. Defaults to the end.\" },\n },\n [\"section\"],\n (args) => {\n const spec = (args.section ?? {}) as Record<string, unknown>;\n const section: ArtSectionData = {\n id: spec.id !== undefined ? str(spec.id) : newId(\"sec\"),\n title: str(spec.title),\n ...(spec.subtitle !== undefined ? { subtitle: str(spec.subtitle) } : {}),\n pieces: [],\n };\n if (adapter.getValue().sections.some((s) => s.id === section.id)) {\n return errorResult(`Section id ${section.id} already exists`);\n }\n const insertAt =\n args.index !== undefined\n ? Math.max(0, Math.min(num(args.index), adapter.getValue().sections.length))\n : adapter.getValue().sections.length;\n adapter.setValue((prev) => ({\n sections: [...prev.sections.slice(0, insertAt), section, ...prev.sections.slice(insertAt)],\n }));\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_add_section\",\n label: `Added section ${section.id}`,\n undo: () => adapter.setValue((prev) => ({ sections: prev.sections.filter((s) => s.id !== section.id) })),\n redo: () =>\n adapter.setValue((prev) => ({\n sections: [...prev.sections.slice(0, insertAt), section, ...prev.sections.slice(insertAt)],\n })),\n });\n return textResult(`Added section ${section.id}`, section);\n },\n abTarget,\n );\n\n reg(\n \"artboard_rename_section\",\n \"Set a section's title and optionally its subtitle.\",\n { sectionId: { type: \"string\" }, title: { type: \"string\" }, subtitle: { type: \"string\" } },\n [\"sectionId\", \"title\"],\n (args) => {\n const sectionId = str(args.sectionId);\n const existing = adapter.getValue().sections.find((s) => s.id === sectionId);\n if (!existing) return errorResult(`No section with id ${sectionId}`);\n const prevTitle = existing.title;\n const prevSubtitle = existing.subtitle;\n const title = str(args.title);\n const hasSubtitle = args.subtitle !== undefined;\n const subtitle = hasSubtitle ? str(args.subtitle) : prevSubtitle;\n const apply = (t: string, sub: string | undefined) =>\n adapter.setValue((prev) => ({\n sections: prev.sections.map((s) =>\n s.id !== sectionId\n ? s\n : { ...s, title: t, ...(sub !== undefined ? { subtitle: sub } : {}) },\n ),\n }));\n apply(title, subtitle);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: \"artboard\",\n action: \"artboard_rename_section\",\n label: `Renamed section ${sectionId}`,\n undo: () => apply(prevTitle, prevSubtitle),\n redo: () => apply(title, subtitle),\n });\n return textResult(`Renamed section ${sectionId} → \"${title}\"`, { id: sectionId, title, subtitle });\n },\n abTarget,\n );\n\n // ───────────── Viewport ─────────────\n\n reg(\n \"artboard_set_viewport\",\n \"Pan / zoom the viewport.\",\n { x: { type: \"number\" }, y: { type: \"number\" }, zoom: { type: \"number\" } },\n [],\n (args) => {\n const v = adapter.getViewport();\n const next: Viewport = {\n x: args.x !== undefined ? num(args.x) : v.x,\n y: args.y !== undefined ? num(args.y) : v.y,\n zoom: args.zoom !== undefined ? num(args.zoom) : v.zoom,\n };\n adapter.setViewport(next);\n return textResult(`Viewport → ${JSON.stringify(next)}`, next);\n },\n abTarget,\n );\n\n return {\n id: \"artboard\",\n title: \"Artboard\",\n dispose: () => {\n for (const d of disposers) d();\n adapter.setAgentCursor?.(null);\n },\n };\n}\n"]}
@@ -0,0 +1,418 @@
1
+ import { ensureUndoToolsRegistered, pushUndoEntry } from './chunk-GQ7XXK7G.js';
2
+ import { wrapToolWithActivity } from './chunk-52S7XYZK.js';
3
+ import './chunk-JU2N4KK6.js';
4
+ import { errorResult, textResult } from './chunk-4KAIV6OD.js';
5
+
6
+ // src/bridges/artboard.ts
7
+ var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
8
+ var num = (v, fallback) => typeof v === "number" && Number.isFinite(v) ? v : fallback ?? 0;
9
+ var str = (v, fallback = "") => typeof v === "string" ? v : fallback;
10
+ var newId = (prefix) => `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`;
11
+ var clone = (v) => JSON.parse(JSON.stringify(v));
12
+ var coerceContent = (v) => {
13
+ if (v && typeof v === "object") {
14
+ const c = v;
15
+ if (c.kind === "image") return { kind: "image", src: str(c.src), ...c.alt !== void 0 ? { alt: str(c.alt) } : {} };
16
+ if (c.kind === "html") return { kind: "html", html: str(c.html) };
17
+ if (c.kind === "node") return { kind: "node" };
18
+ }
19
+ return { kind: "node" };
20
+ };
21
+ function registerArtboardBridge(host, options) {
22
+ const { adapter } = options;
23
+ const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
24
+ const disposers = [];
25
+ ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
26
+ const abTarget = (args, result) => ({
27
+ kind: "artboard",
28
+ id: result?.structuredContent?.id ?? args?.pieceId ?? args?.sectionId
29
+ });
30
+ const reg = (name, description, inputProperties, required, handler, resolveTarget) => {
31
+ const wrapped = async (args) => {
32
+ try {
33
+ return await handler(args);
34
+ } catch (e) {
35
+ return errorResult(e instanceof Error ? e.message : String(e));
36
+ }
37
+ };
38
+ const final = resolveTarget ? wrapToolWithActivity(wrapped, {
39
+ toolName: name,
40
+ agent: { id: agent.id, name: agent.name, color: agent.color },
41
+ kind: "artboard",
42
+ resolveTarget: ({ args, result }) => resolveTarget(args, result)
43
+ }) : wrapped;
44
+ disposers.push(
45
+ host.registerTool(
46
+ {
47
+ name,
48
+ description,
49
+ inputSchema: {
50
+ type: "object",
51
+ properties: inputProperties,
52
+ required,
53
+ additionalProperties: false
54
+ }
55
+ },
56
+ final
57
+ )
58
+ );
59
+ };
60
+ reg("artboard_get_state", "Get the full board state: viewport, focus, all sections and pieces.", {}, [], () => {
61
+ const state = {
62
+ viewport: adapter.getViewport(),
63
+ focus: adapter.getFocus(),
64
+ sections: adapter.getValue().sections
65
+ };
66
+ return textResult(JSON.stringify(state, null, 2), state);
67
+ });
68
+ reg("artboard_list_pieces", "List sections and their pieces with id, label, and content kind.", {}, [], () => {
69
+ const lines = [];
70
+ const summary = [];
71
+ for (const s of adapter.getValue().sections) {
72
+ lines.push(`section ${s.id}: "${s.title}"`);
73
+ const pieces = s.pieces.map((p) => ({
74
+ id: p.id,
75
+ ...p.label !== void 0 ? { label: p.label } : {},
76
+ kind: p.content.kind,
77
+ ...p.pending ? { pending: true } : {}
78
+ }));
79
+ for (const p of s.pieces) {
80
+ lines.push(` piece ${p.id}: ${p.label ? `"${p.label}" ` : ""}[${p.content.kind}]${p.pending ? " (pending)" : ""}`);
81
+ }
82
+ summary.push({ sectionId: s.id, title: s.title, pieces });
83
+ }
84
+ return textResult(lines.join("\n") || "(empty board)", summary);
85
+ });
86
+ reg(
87
+ "artboard_add_piece",
88
+ "Add a piece to a section. New agent-added pieces default to pending:true (trust-but-verify \u2014 a human confirms before it is final).",
89
+ {
90
+ sectionId: { type: "string" },
91
+ piece: {
92
+ type: "object",
93
+ description: "Piece spec: { label?, width?, height?, content }. content is { kind: 'image', src, alt? } | { kind: 'html', html } | { kind: 'node' }."
94
+ },
95
+ index: { type: "number", description: "Insertion index within the section. Defaults to the end." }
96
+ },
97
+ ["sectionId", "piece"],
98
+ (args) => {
99
+ const sectionId = str(args.sectionId);
100
+ const section = adapter.getValue().sections.find((s) => s.id === sectionId);
101
+ if (!section) return errorResult(`No section with id ${sectionId}`);
102
+ const spec = args.piece ?? {};
103
+ const piece = {
104
+ id: newId("p"),
105
+ ...spec.label !== void 0 ? { label: str(spec.label) } : {},
106
+ ...spec.width !== void 0 ? { width: num(spec.width) } : {},
107
+ ...spec.height !== void 0 ? { height: num(spec.height) } : {},
108
+ content: coerceContent(spec.content),
109
+ pending: true
110
+ };
111
+ const insertAt = args.index !== void 0 ? Math.max(0, Math.min(num(args.index), section.pieces.length)) : section.pieces.length;
112
+ adapter.setValue((prev) => ({
113
+ sections: prev.sections.map(
114
+ (s) => s.id !== sectionId ? s : { ...s, pieces: [...s.pieces.slice(0, insertAt), piece, ...s.pieces.slice(insertAt)] }
115
+ )
116
+ }));
117
+ pushUndoEntry(agent.id, {
118
+ timestamp: Date.now(),
119
+ bridgeId: "artboard",
120
+ action: "artboard_add_piece",
121
+ label: `Added piece ${piece.id} to ${sectionId}`,
122
+ undo: () => adapter.setValue((prev) => ({
123
+ sections: prev.sections.map(
124
+ (s) => s.id !== sectionId ? s : { ...s, pieces: s.pieces.filter((p) => p.id !== piece.id) }
125
+ )
126
+ })),
127
+ redo: () => adapter.setValue((prev) => ({
128
+ sections: prev.sections.map(
129
+ (s) => s.id !== sectionId ? s : { ...s, pieces: [...s.pieces.slice(0, insertAt), piece, ...s.pieces.slice(insertAt)] }
130
+ )
131
+ }))
132
+ });
133
+ return textResult(`Added piece ${piece.id} to section ${sectionId} (pending)`, piece);
134
+ },
135
+ abTarget
136
+ );
137
+ reg(
138
+ "artboard_remove_piece",
139
+ "Remove a piece by id.",
140
+ { pieceId: { type: "string" } },
141
+ ["pieceId"],
142
+ (args) => {
143
+ const pieceId = str(args.pieceId);
144
+ let removed = null;
145
+ let fromSection = null;
146
+ let oldIndex = -1;
147
+ for (const s of adapter.getValue().sections) {
148
+ const idx = s.pieces.findIndex((p) => p.id === pieceId);
149
+ if (idx !== -1) {
150
+ removed = clone(s.pieces[idx]);
151
+ fromSection = s.id;
152
+ oldIndex = idx;
153
+ break;
154
+ }
155
+ }
156
+ if (!removed || fromSection === null) return errorResult(`No piece with id ${pieceId}`);
157
+ const sectionId = fromSection;
158
+ const snapshot = removed;
159
+ const at = oldIndex;
160
+ adapter.setValue((prev) => ({
161
+ sections: prev.sections.map(
162
+ (s) => s.id !== sectionId ? s : { ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) }
163
+ )
164
+ }));
165
+ pushUndoEntry(agent.id, {
166
+ timestamp: Date.now(),
167
+ bridgeId: "artboard",
168
+ action: "artboard_remove_piece",
169
+ label: `Removed piece ${pieceId}`,
170
+ undo: () => adapter.setValue((prev) => ({
171
+ sections: prev.sections.map(
172
+ (s) => s.id !== sectionId ? s : { ...s, pieces: [...s.pieces.slice(0, at), clone(snapshot), ...s.pieces.slice(at)] }
173
+ )
174
+ })),
175
+ redo: () => adapter.setValue((prev) => ({
176
+ sections: prev.sections.map(
177
+ (s) => s.id !== sectionId ? s : { ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) }
178
+ )
179
+ }))
180
+ });
181
+ return textResult(`Removed piece ${pieceId}`, { id: pieceId });
182
+ },
183
+ abTarget
184
+ );
185
+ reg(
186
+ "artboard_reorder_piece",
187
+ "Move a piece to a new index, optionally into a different section.",
188
+ {
189
+ pieceId: { type: "string" },
190
+ sectionId: { type: "string", description: "Target section id. Defaults to the piece's current section." },
191
+ toIndex: { type: "number" }
192
+ },
193
+ ["pieceId", "toIndex"],
194
+ (args) => {
195
+ const pieceId = str(args.pieceId);
196
+ const before = adapter.getValue();
197
+ let piece = null;
198
+ let srcSection = null;
199
+ for (const s of before.sections) {
200
+ const found = s.pieces.find((p) => p.id === pieceId);
201
+ if (found) {
202
+ piece = found;
203
+ srcSection = s.id;
204
+ break;
205
+ }
206
+ }
207
+ if (!piece || srcSection === null) return errorResult(`No piece with id ${pieceId}`);
208
+ const dstSection = args.sectionId !== void 0 ? str(args.sectionId) : srcSection;
209
+ if (!before.sections.some((s) => s.id === dstSection)) return errorResult(`No section with id ${dstSection}`);
210
+ const toIndex = Math.max(0, num(args.toIndex));
211
+ const moving = piece;
212
+ const snapshot = clone(before);
213
+ adapter.setValue((prev) => {
214
+ const stripped = prev.sections.map((s) => ({ ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) }));
215
+ return {
216
+ sections: stripped.map((s) => {
217
+ if (s.id !== dstSection) return s;
218
+ const clamped = Math.min(toIndex, s.pieces.length);
219
+ return { ...s, pieces: [...s.pieces.slice(0, clamped), moving, ...s.pieces.slice(clamped)] };
220
+ })
221
+ };
222
+ });
223
+ pushUndoEntry(agent.id, {
224
+ timestamp: Date.now(),
225
+ bridgeId: "artboard",
226
+ action: "artboard_reorder_piece",
227
+ label: `Reordered piece ${pieceId}`,
228
+ undo: () => adapter.setValue(() => clone(snapshot)),
229
+ redo: () => adapter.setValue((prev) => {
230
+ const stripped = prev.sections.map((s) => ({ ...s, pieces: s.pieces.filter((p) => p.id !== pieceId) }));
231
+ return {
232
+ sections: stripped.map((s) => {
233
+ if (s.id !== dstSection) return s;
234
+ const clamped = Math.min(toIndex, s.pieces.length);
235
+ return { ...s, pieces: [...s.pieces.slice(0, clamped), moving, ...s.pieces.slice(clamped)] };
236
+ })
237
+ };
238
+ })
239
+ });
240
+ return textResult(`Reordered piece ${pieceId} \u2192 ${dstSection}[${toIndex}]`, { id: pieceId, sectionId: dstSection, toIndex });
241
+ },
242
+ abTarget
243
+ );
244
+ reg(
245
+ "artboard_rename_piece",
246
+ "Set a piece's label.",
247
+ { pieceId: { type: "string" }, label: { type: "string" } },
248
+ ["pieceId", "label"],
249
+ (args) => {
250
+ const pieceId = str(args.pieceId);
251
+ const label = str(args.label);
252
+ const existing = adapter.getValue().sections.flatMap((s) => s.pieces).find((p) => p.id === pieceId);
253
+ if (!existing) return errorResult(`No piece with id ${pieceId}`);
254
+ const prevLabel = existing.label;
255
+ const apply = (l) => adapter.setValue((prev) => ({
256
+ sections: prev.sections.map((s) => ({
257
+ ...s,
258
+ pieces: s.pieces.map((p) => p.id !== pieceId ? p : { ...p, ...l !== void 0 ? { label: l } : {} })
259
+ }))
260
+ }));
261
+ apply(label);
262
+ pushUndoEntry(agent.id, {
263
+ timestamp: Date.now(),
264
+ bridgeId: "artboard",
265
+ action: "artboard_rename_piece",
266
+ label: `Renamed piece ${pieceId}`,
267
+ undo: () => apply(prevLabel),
268
+ redo: () => apply(label)
269
+ });
270
+ return textResult(`Renamed piece ${pieceId} \u2192 "${label}"`, { id: pieceId, label });
271
+ },
272
+ abTarget
273
+ );
274
+ reg(
275
+ "artboard_set_piece_content",
276
+ "Replace a piece's content. content is { kind: 'image', src, alt? } | { kind: 'html', html } | { kind: 'node' }.",
277
+ { pieceId: { type: "string" }, content: { type: "object" } },
278
+ ["pieceId", "content"],
279
+ (args) => {
280
+ const pieceId = str(args.pieceId);
281
+ const existing = adapter.getValue().sections.flatMap((s) => s.pieces).find((p) => p.id === pieceId);
282
+ if (!existing) return errorResult(`No piece with id ${pieceId}`);
283
+ const prevContent = clone(existing.content);
284
+ const nextContent = coerceContent(args.content);
285
+ const apply = (c) => adapter.setValue((prev) => ({
286
+ sections: prev.sections.map((s) => ({
287
+ ...s,
288
+ pieces: s.pieces.map((p) => p.id !== pieceId ? p : { ...p, content: clone(c) })
289
+ }))
290
+ }));
291
+ apply(nextContent);
292
+ pushUndoEntry(agent.id, {
293
+ timestamp: Date.now(),
294
+ bridgeId: "artboard",
295
+ action: "artboard_set_piece_content",
296
+ label: `Set content of piece ${pieceId}`,
297
+ undo: () => apply(prevContent),
298
+ redo: () => apply(nextContent)
299
+ });
300
+ return textResult(`Set content of piece ${pieceId} \u2192 ${nextContent.kind}`, { id: pieceId, content: nextContent });
301
+ },
302
+ abTarget
303
+ );
304
+ reg(
305
+ "artboard_focus_piece",
306
+ "Focus a piece by id (or pass null to clear focus).",
307
+ { pieceId: { type: ["string", "null"] } },
308
+ [],
309
+ (args) => {
310
+ const raw = args.pieceId;
311
+ const pieceId = typeof raw === "string" ? raw : null;
312
+ if (pieceId !== null && !adapter.getValue().sections.some((s) => s.pieces.some((p) => p.id === pieceId))) {
313
+ return errorResult(`No piece with id ${pieceId}`);
314
+ }
315
+ adapter.setFocus(pieceId);
316
+ return textResult(pieceId ? `Focused piece ${pieceId}` : "Cleared focus", { id: pieceId });
317
+ },
318
+ abTarget
319
+ );
320
+ reg(
321
+ "artboard_add_section",
322
+ "Add a section. Provide an explicit id or one is generated.",
323
+ {
324
+ section: { type: "object", description: "Section spec: { id?, title, subtitle? }." },
325
+ index: { type: "number", description: "Insertion index. Defaults to the end." }
326
+ },
327
+ ["section"],
328
+ (args) => {
329
+ const spec = args.section ?? {};
330
+ const section = {
331
+ id: spec.id !== void 0 ? str(spec.id) : newId("sec"),
332
+ title: str(spec.title),
333
+ ...spec.subtitle !== void 0 ? { subtitle: str(spec.subtitle) } : {},
334
+ pieces: []
335
+ };
336
+ if (adapter.getValue().sections.some((s) => s.id === section.id)) {
337
+ return errorResult(`Section id ${section.id} already exists`);
338
+ }
339
+ const insertAt = args.index !== void 0 ? Math.max(0, Math.min(num(args.index), adapter.getValue().sections.length)) : adapter.getValue().sections.length;
340
+ adapter.setValue((prev) => ({
341
+ sections: [...prev.sections.slice(0, insertAt), section, ...prev.sections.slice(insertAt)]
342
+ }));
343
+ pushUndoEntry(agent.id, {
344
+ timestamp: Date.now(),
345
+ bridgeId: "artboard",
346
+ action: "artboard_add_section",
347
+ label: `Added section ${section.id}`,
348
+ undo: () => adapter.setValue((prev) => ({ sections: prev.sections.filter((s) => s.id !== section.id) })),
349
+ redo: () => adapter.setValue((prev) => ({
350
+ sections: [...prev.sections.slice(0, insertAt), section, ...prev.sections.slice(insertAt)]
351
+ }))
352
+ });
353
+ return textResult(`Added section ${section.id}`, section);
354
+ },
355
+ abTarget
356
+ );
357
+ reg(
358
+ "artboard_rename_section",
359
+ "Set a section's title and optionally its subtitle.",
360
+ { sectionId: { type: "string" }, title: { type: "string" }, subtitle: { type: "string" } },
361
+ ["sectionId", "title"],
362
+ (args) => {
363
+ const sectionId = str(args.sectionId);
364
+ const existing = adapter.getValue().sections.find((s) => s.id === sectionId);
365
+ if (!existing) return errorResult(`No section with id ${sectionId}`);
366
+ const prevTitle = existing.title;
367
+ const prevSubtitle = existing.subtitle;
368
+ const title = str(args.title);
369
+ const hasSubtitle = args.subtitle !== void 0;
370
+ const subtitle = hasSubtitle ? str(args.subtitle) : prevSubtitle;
371
+ const apply = (t, sub) => adapter.setValue((prev) => ({
372
+ sections: prev.sections.map(
373
+ (s) => s.id !== sectionId ? s : { ...s, title: t, ...sub !== void 0 ? { subtitle: sub } : {} }
374
+ )
375
+ }));
376
+ apply(title, subtitle);
377
+ pushUndoEntry(agent.id, {
378
+ timestamp: Date.now(),
379
+ bridgeId: "artboard",
380
+ action: "artboard_rename_section",
381
+ label: `Renamed section ${sectionId}`,
382
+ undo: () => apply(prevTitle, prevSubtitle),
383
+ redo: () => apply(title, subtitle)
384
+ });
385
+ return textResult(`Renamed section ${sectionId} \u2192 "${title}"`, { id: sectionId, title, subtitle });
386
+ },
387
+ abTarget
388
+ );
389
+ reg(
390
+ "artboard_set_viewport",
391
+ "Pan / zoom the viewport.",
392
+ { x: { type: "number" }, y: { type: "number" }, zoom: { type: "number" } },
393
+ [],
394
+ (args) => {
395
+ const v = adapter.getViewport();
396
+ const next = {
397
+ x: args.x !== void 0 ? num(args.x) : v.x,
398
+ y: args.y !== void 0 ? num(args.y) : v.y,
399
+ zoom: args.zoom !== void 0 ? num(args.zoom) : v.zoom
400
+ };
401
+ adapter.setViewport(next);
402
+ return textResult(`Viewport \u2192 ${JSON.stringify(next)}`, next);
403
+ },
404
+ abTarget
405
+ );
406
+ return {
407
+ id: "artboard",
408
+ title: "Artboard",
409
+ dispose: () => {
410
+ for (const d of disposers) d();
411
+ adapter.setAgentCursor?.(null);
412
+ }
413
+ };
414
+ }
415
+
416
+ export { registerArtboardBridge };
417
+ //# sourceMappingURL=bridges-artboard.js.map
418
+ //# sourceMappingURL=bridges-artboard.js.map