@pixerate/editor 0.55.0 → 0.56.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/agent/index.cjs +18 -17
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.js +3 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/canvas/index.cjs +2105 -172
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +319 -23
- package/dist/canvas/index.d.ts +319 -23
- package/dist/canvas/index.js +2081 -148
- package/dist/canvas/index.js.map +1 -1
- package/dist/chart/index.cjs +32 -30
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.d.cts +4 -2
- package/dist/chart/index.d.ts +4 -2
- package/dist/chart/index.js +20 -18
- package/dist/chart/index.js.map +1 -1
- package/dist/{chunk-C3JHII3M.cjs → chunk-3I6V7PI4.cjs} +45 -45
- package/dist/{chunk-C3JHII3M.cjs.map → chunk-3I6V7PI4.cjs.map} +1 -1
- package/dist/{chunk-P43HUQRX.cjs → chunk-AHCENCU4.cjs} +12 -10
- package/dist/chunk-AHCENCU4.cjs.map +1 -0
- package/dist/chunk-II77MLHN.cjs +11106 -0
- package/dist/chunk-II77MLHN.cjs.map +1 -0
- package/dist/{chunk-OIKYP7XC.js → chunk-LMUDHBWR.js} +2 -2
- package/dist/{chunk-VODBAO32.js → chunk-OEFCLWZ3.js} +4 -1425
- package/dist/chunk-OEFCLWZ3.js.map +1 -0
- package/dist/{chunk-NK3WL5TJ.cjs → chunk-P2CTDJNF.cjs} +27 -1448
- package/dist/chunk-P2CTDJNF.cjs.map +1 -0
- package/dist/chunk-TKPPIVW7.cjs +1443 -0
- package/dist/chunk-TKPPIVW7.cjs.map +1 -0
- package/dist/chunk-WJSCGBJ2.js +11106 -0
- package/dist/chunk-WJSCGBJ2.js.map +1 -0
- package/dist/{chunk-RIXTW3C4.js → chunk-WLVZ235X.js} +5 -3
- package/dist/{chunk-RIXTW3C4.js.map → chunk-WLVZ235X.js.map} +1 -1
- package/dist/chunk-ZOH6X3VR.js +1443 -0
- package/dist/chunk-ZOH6X3VR.js.map +1 -0
- package/dist/{controller-DscWQbjO.d.ts → controller-D2rj5umx.d.ts} +2 -362
- package/dist/{controller-CX0QfSv0.d.cts → controller-R2biKk_E.d.cts} +2 -362
- package/dist/diagram/index.cjs +1457 -47
- package/dist/diagram/index.cjs.map +1 -1
- package/dist/diagram/index.d.cts +1734 -15
- package/dist/diagram/index.d.ts +1734 -15
- package/dist/diagram/index.js +1436 -26
- package/dist/diagram/index.js.map +1 -1
- package/dist/extensions/index.cjs +5 -4
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +4 -3
- package/dist/extensions/index.d.ts +4 -3
- package/dist/extensions/index.js +4 -3
- package/dist/{index-DIWB6xMf.d.cts → index-BcHyG0Wq.d.cts} +2 -1
- package/dist/{index-CALDD35B.d.ts → index-CTCc3m3C.d.ts} +2 -1
- package/dist/index.cjs +10 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/types-BRp-6zkY.d.cts +362 -0
- package/dist/types-BRp-6zkY.d.ts +362 -0
- package/dist/{types-BULrFyuQ.d.cts → types-DYkjhzdz.d.cts} +1 -1
- package/dist/{types-BULrFyuQ.d.ts → types-DYkjhzdz.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-H5K77C7Y.cjs +0 -3848
- package/dist/chunk-H5K77C7Y.cjs.map +0 -1
- package/dist/chunk-NK3WL5TJ.cjs.map +0 -1
- package/dist/chunk-P43HUQRX.cjs.map +0 -1
- package/dist/chunk-VODBAO32.js.map +0 -1
- package/dist/chunk-WWJNC7SX.js +0 -3848
- package/dist/chunk-WWJNC7SX.js.map +0 -1
- /package/dist/{chunk-OIKYP7XC.js.map → chunk-LMUDHBWR.js.map} +0 -0
package/dist/agent/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/agent/planner.ts","../../src/agent/providers.ts","../../src/agent/documentChartTools.ts","../../src/agent/componentTools.ts"],"sourcesContent":["import { ensureLayout, getLayoutedNodes, placeBeside } from '../canvas/layout.js';\nimport type { CanvasEdge, CanvasNode, Rect, Side } from '../canvas/types.js';\nimport type { AgentCommand, AgentStep, EditorSnapshot } from './types.js';\n\n/**\n * Normalizes a placement side from either the planner vocabulary (`right | below | left | above`)\n * or the MCP tool schema vocabulary (`top | right | bottom | left`). Unknown values fall back to `right`.\n */\nexport function normalizeSide(side: string | undefined | null): Side {\n\tswitch (side) {\n\t\tcase 'top':\n\t\tcase 'above':\n\t\t\treturn 'above';\n\t\tcase 'bottom':\n\t\tcase 'below':\n\t\t\treturn 'below';\n\t\tcase 'left':\n\t\t\treturn 'left';\n\t\tcase 'right':\n\t\tdefault:\n\t\t\treturn 'right';\n\t}\n}\n\n/**\n * Plans a sequence of atomic execution steps from a high-level agent command.\n */\nexport function planAgentCommand<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(\n\tcommand: AgentCommand<TNode, TEdge>,\n\tsnapshot: EditorSnapshot<TNode, TEdge>,\n\toptions: {\n\t\tdefaultNodeSize?: { width: number; height: number };\n\t\tidGenerator?: () => string;\n\t} = {}\n): AgentStep<TNode, TEdge>[] {\n\tconst defaultNodeSize = options.defaultNodeSize ?? { width: 200, height: 60 };\n\tconst idGen = options.idGenerator ?? (() => `node-${Math.random().toString(36).substring(2, 9)}`);\n\tconst edgeIdGen = () => `edge-${Math.random().toString(36).substring(2, 9)}`;\n\n\tconst nodes = snapshot.canvas?.nodes ?? [];\n\tconst edges = snapshot.canvas?.edges ?? [];\n\n\tswitch (command.type) {\n\t\tcase 'canvas:add_node': {\n\t\t\tlet pos = command.node.position;\n\t\t\t// Only anchor to (and connect from) a node that actually exists.\n\t\t\tconst anchorId =\n\t\t\t\tcommand.nearNodeId && nodes.some((n) => n.id === command.nearNodeId)\n\t\t\t\t\t? command.nearNodeId\n\t\t\t\t\t: undefined;\n\n\t\t\tif (!pos) {\n\t\t\t\tconst rects: Record<string, Rect> = {};\n\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\trects[n.id] = {\n\t\t\t\t\t\tx: n.position.x,\n\t\t\t\t\t\ty: n.position.y,\n\t\t\t\t\t\twidth: n.measured?.width ?? (n as any).width ?? defaultNodeSize.width,\n\t\t\t\t\t\theight: n.measured?.height ?? (n as any).height ?? defaultNodeSize.height\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (anchorId) {\n\t\t\t\t\t// Use collision-aware directional placement\n\t\t\t\t\tpos = placeBeside(rects, defaultNodeSize, normalizeSide(command.side), anchorId);\n\t\t\t\t} else if (nodes.length > 0) {\n\t\t\t\t\t// Default beside the last node\n\t\t\t\t\tconst lastNode = nodes[nodes.length - 1];\n\t\t\t\t\tpos = placeBeside(rects, defaultNodeSize, 'right', lastNode.id);\n\t\t\t\t} else {\n\t\t\t\t\tpos = { x: 100, y: 100 };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst fullNode: TNode = {\n\t\t\t\t...command.node,\n\t\t\t\tid: command.node.id || idGen(),\n\t\t\t\tposition: pos\n\t\t\t} as TNode;\n\n\t\t\tconst steps: AgentStep<TNode, TEdge>[] = [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_add_node',\n\t\t\t\t\tnode: fullNode\n\t\t\t\t}\n\t\t\t];\n\n\t\t\t// If attached to nearNode, optionally automatically connect\n\t\t\tif (anchorId) {\n\t\t\t\tsteps.push({\n\t\t\t\t\ttype: 'step:canvas_add_edge',\n\t\t\t\t\tedge: {\n\t\t\t\t\t\tid: edgeIdGen(),\n\t\t\t\t\t\tsource: anchorId,\n\t\t\t\t\t\ttarget: fullNode.id\n\t\t\t\t\t} as TEdge\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn steps;\n\t\t}\n\n\t\tcase 'canvas:remove_nodes': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_remove_nodes',\n\t\t\t\t\tnodeIds: command.nodeIds\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:connect': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_add_edge',\n\t\t\t\t\tedge: {\n\t\t\t\t\t\tid: edgeIdGen(),\n\t\t\t\t\t\tsource: command.source,\n\t\t\t\t\t\ttarget: command.target,\n\t\t\t\t\t\tlabel: command.label\n\t\t\t\t\t} as TEdge\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:update_node': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_update_node',\n\t\t\t\t\tid: command.id,\n\t\t\t\t\tdata: command.data\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:layout': {\n\t\t\tconst dir = command.direction ?? 'LR';\n\t\t\tlet layouted: TNode[];\n\n\t\t\t// Matches the MCP tool schema: `incremental` defaults to true.\n\t\t\tif (command.incremental ?? true) {\n\t\t\t\tconst stored: Record<string, { x: number; y: number }> = {};\n\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\tif (n.position && (n.position.x !== 0 || n.position.y !== 0)) {\n\t\t\t\t\t\tstored[n.id] = { ...n.position };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlayouted = ensureLayout(nodes, edges, {\n\t\t\t\t\tdirection: dir,\n\t\t\t\t\tstoredPositions: stored\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlayouted = getLayoutedNodes(nodes, edges, undefined, { direction: dir });\n\t\t\t}\n\n\t\t\tconst positions: Record<string, { x: number; y: number }> = {};\n\t\t\tfor (const node of layouted) {\n\t\t\t\tpositions[node.id] = { ...node.position };\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_move_nodes',\n\t\t\t\t\tpositions\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:select': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_select',\n\t\t\t\t\tnodeIds: command.nodeIds\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:highlight': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_highlight',\n\t\t\t\t\tnodeIds: command.nodeIds,\n\t\t\t\t\tcolor: command.color ?? '#3b82f6',\n\t\t\t\t\tdurationMs: command.durationMs ?? 2000\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:insert_text': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_insert',\n\t\t\t\t\ttext: command.text,\n\t\t\t\t\tat: command.at\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:replace_range': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_replace',\n\t\t\t\t\tfrom: command.from,\n\t\t\t\t\tto: command.to,\n\t\t\t\t\ttext: command.text\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:set_variable': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_set_variable',\n\t\t\t\t\tname: command.name,\n\t\t\t\t\tvalue: command.value\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:select': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_select',\n\t\t\t\t\tfrom: command.from,\n\t\t\t\t\tto: command.to\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'choreography:say': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:say',\n\t\t\t\t\ttext: command.text,\n\t\t\t\t\tatNodeId: command.atNodeId,\n\t\t\t\t\tposition: command.position\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'choreography:wait': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:wait',\n\t\t\t\t\tms: command.ms\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'tool:call': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:tool_call',\n\t\t\t\t\tname: command.name,\n\t\t\t\t\targuments: command.arguments ?? {}\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn [];\n\t\t}\n\t}\n}\n\nconst CANVAS_TOOL_OPERATIONS: Record<string, string> = {\n\tcanvas_add_node: 'add_node',\n\tcanvas_remove_nodes: 'remove_nodes',\n\tcanvas_connect: 'connect',\n\tcanvas_update_node: 'update_node',\n\tcanvas_layout: 'layout',\n\tcanvas_select: 'select',\n\tcanvas_highlight: 'highlight'\n};\n\nconst PROMPT_TOOL_OPERATIONS: Record<string, string> = {\n\tprompt_insert_text: 'insert_text',\n\tprompt_replace_range: 'replace_range',\n\tprompt_set_variable: 'set_variable',\n\tprompt_select: 'select'\n};\n\n/**\n * Converts an MCP tool call into a planner command. `edit_canvas` /\n * `edit_prompt` and the per-operation `canvas_*` / `prompt_*` tools (see\n * `tools/definitions.ts`) map to canvas/prompt commands using the MCP\n * schema's vocabulary; every other tool, including dynamic `ToolRegistry`\n * tools, becomes a `tool:call` command. Returns `null` when a static tool's\n * arguments are missing what the operation needs.\n */\nexport function toolCallToAgentCommand<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(name: string, args: Record<string, any> = {}): AgentCommand<TNode, TEdge> | null {\n\tconst ids = (value: unknown): string[] | null =>\n\t\tArray.isArray(value) && value.every((v) => typeof v === 'string') ? value : null;\n\tconst num = (value: unknown) => typeof value === 'number' && Number.isFinite(value);\n\n\tconst canvasOperation = name === 'edit_canvas' ? args.operation : CANVAS_TOOL_OPERATIONS[name];\n\tif (canvasOperation !== undefined) {\n\t\tswitch (canvasOperation) {\n\t\t\tcase 'add_node':\n\t\t\t\treturn args.node && typeof args.node === 'object' && !Array.isArray(args.node)\n\t\t\t\t\t? {\n\t\t\t\t\t\t\ttype: 'canvas:add_node',\n\t\t\t\t\t\t\tnode: { ...args.node, data: args.node.data ?? {} },\n\t\t\t\t\t\t\tnearNodeId: args.nearNodeId,\n\t\t\t\t\t\t\tside: args.side\n\t\t\t\t\t\t}\n\t\t\t\t\t: null;\n\t\t\tcase 'remove_nodes':\n\t\t\t\treturn ids(args.nodeIds) ? { type: 'canvas:remove_nodes', nodeIds: args.nodeIds } : null;\n\t\t\tcase 'connect':\n\t\t\t\treturn typeof args.source === 'string' && typeof args.target === 'string'\n\t\t\t\t\t? { type: 'canvas:connect', source: args.source, target: args.target, label: args.label }\n\t\t\t\t\t: null;\n\t\t\tcase 'update_node': {\n\t\t\t\tconst id = args.node?.id ?? args.id;\n\t\t\t\treturn typeof id === 'string'\n\t\t\t\t\t? { type: 'canvas:update_node', id, data: args.node?.data ?? args.data ?? {} }\n\t\t\t\t\t: null;\n\t\t\t}\n\t\t\tcase 'layout':\n\t\t\t\treturn { type: 'canvas:layout', direction: args.direction, incremental: args.incremental };\n\t\t\tcase 'select':\n\t\t\t\treturn ids(args.nodeIds) ? { type: 'canvas:select', nodeIds: args.nodeIds } : null;\n\t\t\tcase 'highlight':\n\t\t\t\treturn ids(args.nodeIds)\n\t\t\t\t\t? {\n\t\t\t\t\t\t\ttype: 'canvas:highlight',\n\t\t\t\t\t\t\tnodeIds: args.nodeIds,\n\t\t\t\t\t\t\t...(typeof args.color === 'string' ? { color: args.color } : {}),\n\t\t\t\t\t\t\t...(num(args.durationMs) ? { durationMs: args.durationMs } : {})\n\t\t\t\t\t\t}\n\t\t\t\t\t: null;\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst promptOperation = name === 'edit_prompt' ? args.operation : PROMPT_TOOL_OPERATIONS[name];\n\tif (promptOperation !== undefined) {\n\t\tswitch (promptOperation) {\n\t\t\tcase 'insert_text':\n\t\t\t\treturn typeof args.text === 'string'\n\t\t\t\t\t? { type: 'prompt:insert_text', text: args.text, at: num(args.at) ? args.at : undefined }\n\t\t\t\t\t: null;\n\t\t\tcase 'replace_range':\n\t\t\t\treturn typeof args.text === 'string' && num(args.from) && num(args.to)\n\t\t\t\t\t? { type: 'prompt:replace_range', from: args.from, to: args.to, text: args.text }\n\t\t\t\t\t: null;\n\t\t\tcase 'set_variable':\n\t\t\t\treturn typeof args.name === 'string'\n\t\t\t\t\t? { type: 'prompt:set_variable', name: args.name, value: args.value }\n\t\t\t\t\t: null;\n\t\t\tcase 'select':\n\t\t\t\treturn num(args.from) && num(args.to) ? { type: 'prompt:select', from: args.from, to: args.to } : null;\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn { type: 'tool:call', name, arguments: args };\n}\n\n/**\n * Checks a command against the snapshot before it is planned and returns a\n * message an agent can act on, or `null` when it is valid: node ids must\n * exist (and a new node's id must not), an edge needs two different existing\n * nodes, and prompt ranges must be ordered. Prompt positions are host-defined,\n * so their upper bound is left to the host's `applySteps`.\n * The planner itself stays lenient (it falls back instead of failing), so\n * tool providers call this first.\n */\nexport function validateAgentCommand<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(command: AgentCommand<TNode, TEdge>, snapshot: EditorSnapshot<TNode, TEdge>): string | null {\n\tconst known = new Set((snapshot.canvas?.nodes ?? []).map((n) => n.id));\n\tconst missing = (nodeIds: readonly string[]) => {\n\t\tconst unknown = nodeIds.filter((id) => !known.has(id));\n\t\treturn unknown.length\n\t\t\t? `Unknown node id${unknown.length > 1 ? 's' : ''}: ${unknown.map((id) => JSON.stringify(id)).join(', ')}. Call get_editor_state for the current ids.`\n\t\t\t: null;\n\t};\n\tconst range = (from: number, to: number) => {\n\t\tif (from < 0 || to < 0) return 'Positions must be >= 0.';\n\t\tif (from > to) return `\"from\" (${from}) must not be after \"to\" (${to}).`;\n\t\treturn null;\n\t};\n\n\tswitch (command.type) {\n\t\tcase 'canvas:add_node':\n\t\t\tif (command.node.id && known.has(command.node.id)) return `A node with id \"${command.node.id}\" already exists.`;\n\t\t\treturn command.nearNodeId ? missing([command.nearNodeId]) : null;\n\t\tcase 'canvas:remove_nodes':\n\t\tcase 'canvas:highlight':\n\t\t\treturn command.nodeIds.length ? missing(command.nodeIds) : 'Pass at least one node id.';\n\t\tcase 'canvas:select':\n\t\t\treturn missing(command.nodeIds);\n\t\tcase 'canvas:connect':\n\t\t\tif (command.source === command.target) return 'An edge needs two different nodes.';\n\t\t\treturn missing([command.source, command.target]);\n\t\tcase 'canvas:update_node':\n\t\t\treturn missing([command.id]);\n\t\tcase 'prompt:insert_text':\n\t\t\treturn command.at !== undefined ? range(command.at, command.at) : null;\n\t\tcase 'prompt:replace_range':\n\t\tcase 'prompt:select':\n\t\t\treturn range(command.from, command.to);\n\t\tcase 'choreography:say':\n\t\t\treturn command.atNodeId ? missing([command.atNodeId]) : null;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/**\n * Plans the steps for an MCP tool call: static editor tools are planned like\n * the equivalent commands, any other tool becomes a `step:tool_call` to be\n * executed with `ToolRegistry.callTool`. Returns `[]` for invalid arguments.\n */\nexport function planToolCall<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(\n\tname: string,\n\targs: Record<string, any>,\n\tsnapshot: EditorSnapshot<TNode, TEdge>,\n\toptions?: Parameters<typeof planAgentCommand>[2]\n): AgentStep<TNode, TEdge>[] {\n\tconst command = toolCallToAgentCommand<TNode, TEdge>(name, args);\n\treturn command ? planAgentCommand(command, snapshot, options) : [];\n}\n","import type { Editor } from '@tiptap/core';\nimport { plainTextToSlice, getEditorText } from '../serializers/plain-text.js';\nimport { getEditorMarkdown } from '../serializers/markdown.js';\nimport { TextSelection } from '@tiptap/pm/state';\nimport {\n\tTABLE_ACTIONS,\n\tgetTableActionState,\n\tgetTableState,\n\tisTableEnabled,\n\trunTableAction,\n\ttype TableAction\n} from '../extensions/table/actions.js';\nimport { applyReplacements, searchDocument, type FindMatch } from '../extensions/find-replace/search.js';\nimport type { FindOptions } from '../extensions/find-replace/pattern.js';\nimport type { SpreadsheetController } from '../spreadsheet/controller.js';\nimport { colNameToIndex, indexToColName, isFormulaError } from '../spreadsheet/formula/evaluator.js';\nimport { planAgentCommand, toolCallToAgentCommand, validateAgentCommand, type planToolCall } from './planner.js';\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport {\n\tEDIT_OPERATION_REQUIRED_ARGUMENTS,\n\tEDITOR_CANVAS_TOOLS,\n\tEDITOR_PROMPT_TOOLS,\n\tMCP_TOOL_EDIT_CANVAS,\n\tMCP_TOOL_EDIT_PROMPT,\n\tMCP_TOOL_GET_EDITOR_STATE,\n\tMCP_TOOL_VIEW_EDITOR\n} from '../tools/definitions.js';\nimport type { AgentStep, EditorSnapshot } from './types.js';\nimport { createDocumentChartTools } from './documentChartTools.js';\nimport type { CanvasEdge, CanvasNode } from '../canvas/types.js';\n\nexport interface ToolProviderOptions {\n\t/** Provider id (unique per registry). */\n\tid: string;\n\t/** Always prefix tool names with `<namespace>__`. */\n\tnamespace?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Rich-text editor provider\n// ---------------------------------------------------------------------------\n\n/** A TipTap editor, or anything exposing one as `.editor` (e.g. `EditorController`). */\nexport type RichTextToolTarget = Editor | { editor: Editor };\n\nconst toEditor = (target: RichTextToolTarget): Editor =>\n\t'commands' in target ? (target as Editor) : (target as { editor: Editor }).editor;\n\n/** Replaces `from..to` with literal text (HTML is not parsed; newlines split paragraphs). */\nfunction replaceWithText(editor: Editor, from: number, to: number, text: string) {\n\tconst { state, view } = editor;\n\tconst tr = /[\\r\\n]/.test(text)\n\t\t? state.tr.replace(from, to, plainTextToSlice(text, state.schema))\n\t\t: text\n\t\t\t? state.tr.insertText(text, from, to)\n\t\t\t: state.tr.delete(from, to);\n\tview.dispatch(tr.scrollIntoView());\n}\n\nfunction selectionInfo(editor: Editor) {\n\tconst { from, to } = editor.state.selection;\n\treturn { from, to, text: editor.state.doc.textBetween(from, to, '\\n') };\n}\n\n/** Throws a tool error unless `from..to` is an ordered range inside the document. */\nfunction checkRange(editor: Editor, from: number, to: number) {\n\tconst size = editor.state.doc.content.size;\n\tif (from > to) throw new Error(`\"from\" (${from}) must not be after \"to\" (${to}).`);\n\tif (to > size) throw new Error(`Position ${to} is outside the document (size ${size}).`);\n}\n\n/** Textblocks (paragraphs, headings, cells...) with the positions their text spans. */\nfunction textBlocks(editor: Editor) {\n\tconst blocks: Array<{ type: string; from: number; to: number; text: string }> = [];\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (!node.isTextblock) return true;\n\t\tblocks.push({ type: node.type.name, from: pos + 1, to: pos + 1 + node.content.size, text: node.textContent });\n\t\treturn false;\n\t});\n\treturn blocks;\n}\n\nconst FIND_SCHEMA_PROPERTIES = {\n\tmatchCase: { type: 'boolean', description: 'Case-sensitive match (default false).' },\n\twholeWord: { type: 'boolean', description: 'Match whole words only (default false).' },\n\tregex: {\n\t\ttype: 'boolean',\n\t\tdescription: 'Treat the query as a JavaScript regular expression (default false: literal text).'\n\t}\n} as const;\n\nconst CONTEXT_CHARS = 30;\n\n/** Runs a literal (or regex) search; throws a tool error for an invalid pattern. */\nfunction findMatches(\n\teditor: Editor,\n\tquery: string,\n\targs: { matchCase?: boolean; wholeWord?: boolean; regex?: boolean },\n\treplacement?: string\n): { matches: FindMatch[]; truncated: boolean } {\n\tconst options: FindOptions = {\n\t\tmatchCase: !!args.matchCase,\n\t\twholeWord: !!args.wholeWord,\n\t\t...(args.regex ? { regex: true } : { literal: true })\n\t};\n\tconst result = searchDocument(editor.state.doc, query, options, replacement !== undefined ? { replacement } : {});\n\tif (result.error) throw new Error(`Invalid search pattern: ${result.error.message}`);\n\treturn { matches: result.matches, truncated: result.truncated };\n}\n\n/**\n * Tools for a mounted rich-text editor: `get_text` and `find_text` (always),\n * plus `insert_text`, `replace_text`, `replace_range`, `replace_selection` and\n * `set_selection` while the editor is editable, `edit_table` when the\n * schema has tables (`createRichTextPreset`'s `table`), and the chart tools\n * (`list_document_charts`; `insert_chart`, `update_chart_in_document` and\n * `insert_sparkline` while editable) when it has charts (`chart`).\n * Positions are ProseMirror document positions (as in `selection.from`), not\n * plain-text offsets; `find_text` and `get_text {blocks: true}` return them.\n * The provider re-announces its tool list when editability changes and\n * exposes no tools once the editor is destroyed.\n */\nexport function createRichTextToolProvider(\n\ttarget: RichTextToolTarget,\n\toptions: ToolProviderOptions\n): AgentToolProvider {\n\tconst editor = () => toEditor(target);\n\tconst charts = createDocumentChartTools(editor);\n\n\tconst getText: AgentTool = {\n\t\tname: 'get_text',\n\t\ttitle: 'Get document text',\n\t\tdescription:\n\t\t\t'Returns the document content (plain text by default, or HTML / markdown), the current selection and the document size. ' +\n\t\t\t'Editing tools take document positions, not text offsets: pass `blocks: true` to get every paragraph with the positions ' +\n\t\t\t'its text spans, or use find_text to get the positions of a phrase.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tformat: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tenum: ['text', 'html', 'markdown'],\n\t\t\t\t\tdescription: 'Content format (default: text).'\n\t\t\t\t},\n\t\t\t\tblocks: {\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\tdescription: 'Also return `blocks`: each paragraph/heading/cell as {type, from, to, text} (default false).'\n\t\t\t\t}\n\t\t\t},\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Get document text',\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ format = 'text', blocks = false }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst content =\n\t\t\t\tformat === 'html' ? ed.getHTML() : format === 'markdown' ? getEditorMarkdown(ed) : getEditorText(ed);\n\t\t\treturn {\n\t\t\t\tformat,\n\t\t\t\tcontent,\n\t\t\t\tselection: selectionInfo(ed),\n\t\t\t\tsize: ed.state.doc.content.size,\n\t\t\t\t...(blocks ? { blocks: textBlocks(ed) } : {})\n\t\t\t};\n\t\t}\n\t};\n\n\tconst insertText: AgentTool = {\n\t\tname: 'insert_text',\n\t\ttitle: 'Insert text',\n\t\tdescription:\n\t\t\t'Inserts literal text (newlines start new paragraphs) at a document position, or at the cursor when `at` is omitted.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\ttext: { type: 'string', description: 'Text to insert.' },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position (default: the selection).' }\n\t\t\t},\n\t\t\trequired: ['text'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Insert text',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ text, at }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst size = ed.state.doc.content.size;\n\t\t\tif (at !== undefined && at > size) {\n\t\t\t\tthrow new Error(`Position ${at} is outside the document (size ${size}).`);\n\t\t\t}\n\t\t\tconst { from, to } = ed.state.selection;\n\t\t\treplaceWithText(ed, at ?? from, at ?? to, text);\n\t\t\treturn { inserted: text.length, selection: selectionInfo(ed) };\n\t\t}\n\t};\n\n\tconst findText: AgentTool = {\n\t\tname: 'find_text',\n\t\ttitle: 'Find text',\n\t\tdescription:\n\t\t\t'Finds a phrase (literal by default) and returns each match with its document positions {from, to}, ' +\n\t\t\t'ready for replace_range, insert_text `at` or set_selection, plus surrounding context.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tquery: { type: 'string', minLength: 1, description: 'Text (or regex) to find.' },\n\t\t\t\t...FIND_SCHEMA_PROPERTIES,\n\t\t\t\tmaxResults: { type: 'integer', minimum: 1, maximum: 500, description: 'Matches returned (default 50).' }\n\t\t\t},\n\t\t\trequired: ['query'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Find text',\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ query, maxResults = 50, ...flags }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst { doc } = ed.state;\n\t\t\tconst { matches, truncated } = findMatches(ed, query, flags);\n\t\t\treturn {\n\t\t\t\ttotal: matches.length,\n\t\t\t\ttruncated: truncated || matches.length > maxResults,\n\t\t\t\tmatches: matches.slice(0, maxResults).map((m) => ({\n\t\t\t\t\tfrom: m.from,\n\t\t\t\t\tto: m.to,\n\t\t\t\t\ttext: m.text,\n\t\t\t\t\tbefore: doc.textBetween(Math.max(0, m.from - CONTEXT_CHARS), m.from, '\\n', ' '),\n\t\t\t\t\tafter: doc.textBetween(m.to, Math.min(doc.content.size, m.to + CONTEXT_CHARS), '\\n', ' ')\n\t\t\t\t}))\n\t\t\t};\n\t\t}\n\t};\n\n\tconst replaceText: AgentTool = {\n\t\tname: 'replace_text',\n\t\ttitle: 'Find and replace',\n\t\tdescription:\n\t\t\t'Replaces occurrences of a phrase with literal text in one undoable step, keeping the found text\\'s formatting. ' +\n\t\t\t'Replaces every occurrence by default, or only the n-th with `occurrence`. Fails when nothing matches.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tfind: { type: 'string', minLength: 1, description: 'Text (or regex) to find.' },\n\t\t\t\treplace: { type: 'string', description: 'Replacement text (literal; an empty string deletes the matches).' },\n\t\t\t\t...FIND_SCHEMA_PROPERTIES,\n\t\t\t\toccurrence: {\n\t\t\t\t\ttype: 'integer',\n\t\t\t\t\tminimum: 1,\n\t\t\t\t\tdescription: 'Only replace the n-th match (1-based, in document order). Default: all matches.'\n\t\t\t\t}\n\t\t\t},\n\t\t\trequired: ['find', 'replace'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Find and replace',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ find, replace, occurrence, ...flags }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst { matches } = findMatches(ed, find, flags);\n\t\t\tif (matches.length === 0) throw new Error(`No match for ${JSON.stringify(find)}.`);\n\t\t\tif (occurrence !== undefined && occurrence > matches.length) {\n\t\t\t\tthrow new Error(`Occurrence ${occurrence} requested, but there are only ${matches.length} matches.`);\n\t\t\t}\n\t\t\t// The replacement is literal text: `\\r` / `\\n` split paragraphs / insert line breaks.\n\t\t\tconst chosen = (occurrence !== undefined ? [matches[occurrence - 1]] : matches).map((m) => ({\n\t\t\t\t...m,\n\t\t\t\treplacement: String(replace).replace(/\\r\\n?|\\n/g, '\\r')\n\t\t\t}));\n\t\t\tconst tr = ed.state.tr;\n\t\t\tconst ends = applyReplacements(tr, chosen);\n\t\t\ted.view.dispatch(tr.scrollIntoView());\n\t\t\treturn {\n\t\t\t\treplaced: chosen.length,\n\t\t\t\ttotal: matches.length,\n\t\t\t\tranges: chosen.map((m, i) => ({ from: tr.mapping.map(m.from, -1), to: ends[i] })),\n\t\t\t\tselection: selectionInfo(ed)\n\t\t\t};\n\t\t}\n\t};\n\n\tconst replaceRange: AgentTool = {\n\t\tname: 'replace_range',\n\t\ttitle: 'Replace a range',\n\t\tdescription:\n\t\t\t'Replaces the content between two document positions (from get_text `blocks` or find_text) with literal text. ' +\n\t\t\t'from === to inserts; an empty text deletes.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tfrom: { type: 'integer', minimum: 0, description: 'Start document position.' },\n\t\t\t\tto: { type: 'integer', minimum: 0, description: 'End document position.' },\n\t\t\t\ttext: { type: 'string', description: 'Replacement text (newlines start new paragraphs).' }\n\t\t\t},\n\t\t\trequired: ['from', 'to', 'text'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Replace a range',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ from, to, text }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckRange(ed, from, to);\n\t\t\treplaceWithText(ed, from, to, text);\n\t\t\treturn { replaced: { from, to }, selection: selectionInfo(ed), size: ed.state.doc.content.size };\n\t\t}\n\t};\n\n\tconst setSelection: AgentTool = {\n\t\tname: 'set_selection',\n\t\ttitle: 'Set the selection',\n\t\tdescription: 'Selects the content between two document positions (from === to places the cursor).',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tfrom: { type: 'integer', minimum: 0, description: 'Start document position.' },\n\t\t\t\tto: { type: 'integer', minimum: 0, description: 'End document position (default: from).' }\n\t\t\t},\n\t\t\trequired: ['from'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Set the selection',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ from, to = from }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckRange(ed, from, to);\n\t\t\tconst { doc } = ed.state;\n\t\t\ted.view.dispatch(ed.state.tr.setSelection(TextSelection.between(doc.resolve(from), doc.resolve(to))));\n\t\t\treturn { selection: selectionInfo(ed) };\n\t\t}\n\t};\n\n\tconst replaceSelection: AgentTool = {\n\t\tname: 'replace_selection',\n\t\ttitle: 'Replace selection',\n\t\tdescription: 'Replaces the selected content with literal text (an empty string deletes the selection).',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: { text: { type: 'string', description: 'Replacement text.' } },\n\t\t\trequired: ['text'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Replace selection',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ text }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst { from, to } = ed.state.selection;\n\t\t\treplaceWithText(ed, from, to, text);\n\t\t\treturn { replaced: { from, to }, selection: selectionInfo(ed) };\n\t\t}\n\t};\n\n\tconst editTable: AgentTool = {\n\t\tname: 'edit_table',\n\t\ttitle: 'Edit tables',\n\t\tdescription:\n\t\t\t'Inserts a table or edits the table at the cursor (or at `at`): add/delete rows and columns, delete the table, ' +\n\t\t\t'merge/split cells, toggle header row/column/cell, move between cells, set cell alignment or background. ' +\n\t\t\t'Returns the table size and the cursor cell afterwards.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\toperation: { type: 'string', enum: TABLE_ACTIONS.map((a) => a.action), description: 'Table operation.' },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position to place the cursor first (e.g. inside a cell).' },\n\t\t\t\trows: { type: 'integer', minimum: 1, maximum: 100, description: 'insertTable: rows (default 3).' },\n\t\t\t\tcols: { type: 'integer', minimum: 1, maximum: 50, description: 'insertTable: columns (default 3).' },\n\t\t\t\twithHeaderRow: { type: 'boolean', description: 'insertTable: first row is a header row (default true).' },\n\t\t\t\talign: {\n\t\t\t\t\ttype: ['string', 'null'],\n\t\t\t\t\tenum: ['left', 'center', 'right', 'justify', null],\n\t\t\t\t\tdescription: 'setCellAlignment: alignment, or null to clear.'\n\t\t\t\t},\n\t\t\t\tcolor: { type: ['string', 'null'], description: 'setCellBackground: CSS color, or null to clear.' }\n\t\t\t},\n\t\t\trequired: ['operation'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Edit tables',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ operation, at, ...params }) => {\n\t\t\tconst ed = editor();\n\t\t\tif (at !== undefined) {\n\t\t\t\tconst size = ed.state.doc.content.size;\n\t\t\t\tif (at > size) throw new Error(`Position ${at} is outside the document (size ${size}).`);\n\t\t\t\ted.view.dispatch(ed.state.tr.setSelection(TextSelection.near(ed.state.doc.resolve(at))));\n\t\t\t}\n\t\t\tconst action = operation as TableAction;\n\t\t\tconst state = getTableActionState(ed, action, params);\n\t\t\tif (state !== true) throw new Error(state);\n\t\t\trunTableAction(ed, action, params);\n\t\t\tconst table = getTableState(ed);\n\t\t\treturn {\n\t\t\t\toperation,\n\t\t\t\ttable: table.inTable\n\t\t\t\t\t? { rows: table.rows, columns: table.columns, row: table.row, column: table.column }\n\t\t\t\t\t: null,\n\t\t\t\tselection: selectionInfo(ed)\n\t\t\t};\n\t\t}\n\t};\n\n\treturn {\n\t\tid: options.id,\n\t\tnamespace: options.namespace,\n\t\ttools: () => {\n\t\t\tconst ed = editor();\n\t\t\tif (!ed || ed.isDestroyed) return [];\n\t\t\tif (!ed.isEditable) return [getText, findText, ...charts.read()];\n\t\t\tconst tools = [getText, findText, insertText, replaceText, replaceRange, replaceSelection, setSelection];\n\t\t\treturn [...tools, ...(isTableEnabled(ed) ? [editTable] : []), ...charts.read(), ...charts.write()];\n\t\t},\n\t\tsubscribe: (notify) => {\n\t\t\tconst ed = editor();\n\t\t\t// `setEditable` emits `update`; the registry ignores signals that don't change the list.\n\t\t\ted.on('update', notify);\n\t\t\ted.on('destroy', notify);\n\t\t\treturn () => {\n\t\t\t\ted.off('update', notify);\n\t\t\t\ted.off('destroy', notify);\n\t\t\t};\n\t\t}\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Spreadsheet provider\n// ---------------------------------------------------------------------------\n\nconst CELL_REF_REGEX = /^\\$?([A-Za-z]{1,3})\\$?(\\d{1,7})$/;\n\nfunction parseCell(ref: string): { col: number; row: number } {\n\tconst match = CELL_REF_REGEX.exec(ref.trim());\n\tif (!match) throw new Error(`Invalid cell reference \"${ref}\". Use A1 notation, e.g. \"B3\".`);\n\treturn { col: colNameToIndex(match[1].toUpperCase()), row: parseInt(match[2], 10) - 1 };\n}\n\nconst COLUMN_REGEX = /^[A-Za-z]{1,3}$/;\n\nfunction parseColumn(name: string): number {\n\tif (!COLUMN_REGEX.test(name.trim())) throw new Error(`Invalid column \"${name}\". Use a letter name, e.g. \"C\".`);\n\treturn colNameToIndex(name.trim().toUpperCase());\n}\n\nconst CELL_INPUT = { type: ['string', 'number', 'boolean', 'null'] } as const;\n\n/**\n * Tools for a spreadsheet controller: `get_range` (A1 notation, values and raw\n * input), `set_cell` and `set_range` (raw input; values starting with `=` are\n * formulas; `set_range` writes a whole block as one undo step), and\n * `insert_rows` / `delete_rows` / `insert_columns` / `delete_columns`\n * (formula references shift like a user edit).\n */\nexport function createSpreadsheetToolProvider(\n\tcontroller: SpreadsheetController,\n\toptions: ToolProviderOptions\n): AgentToolProvider {\n\tconst lookup = (row: number, col: number) => {\n\t\tconst rowDef = controller.document.rows[row];\n\t\tconst colDef = controller.document.columns[col];\n\t\treturn rowDef && colDef ? { rowDef, colDef } : null;\n\t};\n\n\tconst getRange: AgentTool = {\n\t\tname: 'get_range',\n\t\ttitle: 'Read cells',\n\t\tdescription:\n\t\t\t'Reads a cell range in A1 notation (e.g. \"A1:C5\" or \"B2\") and returns computed values, raw input and errors.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\trange: { type: 'string', description: 'A1-notation cell or range.' }\n\t\t\t},\n\t\t\trequired: ['range'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Read cells',\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ range }) => {\n\t\t\tconst [startRef, endRef = startRef] = String(range).split(':');\n\t\t\tconst start = parseCell(startRef);\n\t\t\tconst end = parseCell(endRef);\n\t\t\tconst rowCount = controller.document.rows.length;\n\t\t\tconst colCount = controller.document.columns.length;\n\t\t\tconst r0 = Math.min(start.row, end.row);\n\t\t\tconst r1 = Math.min(Math.max(start.row, end.row), rowCount - 1);\n\t\t\tconst c0 = Math.min(start.col, end.col);\n\t\t\tconst c1 = Math.min(Math.max(start.col, end.col), colCount - 1);\n\t\t\tconst values: unknown[][] = [];\n\t\t\tconst raw: string[][] = [];\n\t\t\tconst errors: Array<{ cell: string; error: string }> = [];\n\t\t\tfor (let r = r0; r <= r1; r++) {\n\t\t\t\tconst valueRow: unknown[] = [];\n\t\t\t\tconst rawRow: string[] = [];\n\t\t\t\tfor (let c = c0; c <= c1; c++) {\n\t\t\t\t\tconst found = lookup(r, c)!;\n\t\t\t\t\tconst cell = controller.getCell(found.rowDef.id, found.colDef.id);\n\t\t\t\t\tvalueRow.push(cell.error ?? cell.value);\n\t\t\t\t\trawRow.push(cell.raw);\n\t\t\t\t\tconst error = cell.error ?? (isFormulaError(cell.value) ? cell.value : undefined);\n\t\t\t\t\tif (error) errors.push({ cell: `${indexToColName(c)}${r + 1}`, error });\n\t\t\t\t}\n\t\t\t\tvalues.push(valueRow);\n\t\t\t\traw.push(rawRow);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trange: values.length && values[0].length ? `${indexToColName(c0)}${r0 + 1}:${indexToColName(c1)}${r1 + 1}` : null,\n\t\t\t\tvalues,\n\t\t\t\traw,\n\t\t\t\terrors,\n\t\t\t\tsheet: { rows: rowCount, columns: colCount }\n\t\t\t};\n\t\t}\n\t};\n\n\tconst setCell: AgentTool = {\n\t\tname: 'set_cell',\n\t\ttitle: 'Set a cell',\n\t\tdescription: 'Sets the raw input of one cell (A1 notation). Values starting with \"=\" are formulas.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tcell: { type: 'string', description: 'A1-notation cell, e.g. \"B3\".' },\n\t\t\t\tvalue: { type: ['string', 'number', 'boolean'], description: 'Raw cell input.' }\n\t\t\t},\n\t\t\trequired: ['cell', 'value'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Set a cell',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ cell, value }) => {\n\t\t\tconst { row, col } = parseCell(cell);\n\t\t\tconst found = lookup(row, col);\n\t\t\tif (!found) throw new Error(`Cell ${cell} is outside the sheet.`);\n\t\t\tconst { rowDef, colDef } = found;\n\t\t\tif (colDef.readOnly || controller.getCell(rowDef.id, colDef.id).readOnly || colDef.type === 'formula') {\n\t\t\t\tthrow new Error(`Cell ${cell} is read-only.`);\n\t\t\t}\n\t\t\tcontroller.setCellValue(rowDef.id, colDef.id, String(value));\n\t\t\tconst updated = controller.getCell(rowDef.id, colDef.id);\n\t\t\treturn { cell: cell.toUpperCase(), raw: updated.raw, value: updated.error ?? updated.value };\n\t\t}\n\t};\n\n\tconst isReadOnly = (row: number, col: number) => {\n\t\tconst found = lookup(row, col);\n\t\tif (!found) return false;\n\t\tconst { rowDef, colDef } = found;\n\t\treturn !!(colDef.readOnly || colDef.type === 'formula' || controller.getCell(rowDef.id, colDef.id).readOnly);\n\t};\n\n\tconst setRange: AgentTool = {\n\t\tname: 'set_range',\n\t\ttitle: 'Set a block of cells',\n\t\tdescription:\n\t\t\t'Writes a 2D block of raw inputs starting at a cell (A1 notation), row by row, as one undo step. ' +\n\t\t\t'Values starting with \"=\" are formulas; null or \"\" clears a cell. The sheet grows to fit. Fails without writing ' +\n\t\t\t'anything if any target cell is read-only.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tstart: { type: 'string', description: 'Top-left cell, e.g. \"A1\".' },\n\t\t\t\tvalues: {\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tminItems: 1,\n\t\t\t\t\tmaxItems: 10000,\n\t\t\t\t\titems: { type: 'array', items: CELL_INPUT, maxItems: 1000 },\n\t\t\t\t\tdescription: 'Rows of raw cell inputs, e.g. [[\"Name\", \"Total\"], [\"A\", \"=B3*2\"]].'\n\t\t\t\t}\n\t\t\t},\n\t\t\trequired: ['start', 'values'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Set a block of cells',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ start, values }) => {\n\t\t\tconst { row, col } = parseCell(start);\n\t\t\tconst rows = values as Array<Array<string | number | boolean | null>>;\n\t\t\tconst readOnly: string[] = [];\n\t\t\trows.forEach((line, r) =>\n\t\t\t\tline.forEach((_, c) => {\n\t\t\t\t\tif (isReadOnly(row + r, col + c)) readOnly.push(`${indexToColName(col + c)}${row + r + 1}`);\n\t\t\t\t})\n\t\t\t);\n\t\t\tif (readOnly.length) throw new Error(`Read-only cells: ${readOnly.slice(0, 20).join(', ')}. Nothing was written.`);\n\t\t\tcontroller.importRows(\n\t\t\t\trows.map((line) => line.map((v) => (v === null ? '' : String(v)))),\n\t\t\t\t{ startRow: row, startCol: col }\n\t\t\t);\n\t\t\tconst width = Math.max(0, ...rows.map((line) => line.length));\n\t\t\tconst end = `${indexToColName(col + Math.max(width, 1) - 1)}${row + rows.length}`;\n\t\t\tconst errors: Array<{ cell: string; error: string }> = [];\n\t\t\trows.forEach((line, r) =>\n\t\t\t\tline.forEach((_, c) => {\n\t\t\t\t\tconst found = lookup(row + r, col + c);\n\t\t\t\t\tif (!found) return;\n\t\t\t\t\tconst cell = controller.getCell(found.rowDef.id, found.colDef.id);\n\t\t\t\t\tconst error = cell.error ?? (isFormulaError(cell.value) ? cell.value : undefined);\n\t\t\t\t\tif (error) errors.push({ cell: `${indexToColName(col + c)}${row + r + 1}`, error: String(error) });\n\t\t\t\t})\n\t\t\t);\n\t\t\treturn {\n\t\t\t\trange: `${indexToColName(col)}${row + 1}:${end}`,\n\t\t\t\twritten: rows.reduce((n, line) => n + line.length, 0),\n\t\t\t\terrors,\n\t\t\t\tsheet: { rows: controller.document.rows.length, columns: controller.document.columns.length }\n\t\t\t};\n\t\t}\n\t};\n\n\tconst COUNT = { type: 'integer', minimum: 1, maximum: 1000, description: 'How many (default 1).' } as const;\n\tconst sheetSize = () => ({ rows: controller.document.rows.length, columns: controller.document.columns.length });\n\tconst structural = (\n\t\tname: string,\n\t\ttitle: string,\n\t\tdescription: string,\n\t\tproperties: Record<string, unknown>,\n\t\trequired: string[],\n\t\tdestructive: boolean,\n\t\thandler: AgentTool['handler']\n\t): AgentTool => ({\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: { type: 'object', properties: properties as never, required, additionalProperties: false },\n\t\tannotations: { title, readOnlyHint: false, destructiveHint: destructive, idempotentHint: false, openWorldHint: false },\n\t\thandler\n\t});\n\n\tconst insertRows = structural(\n\t\t'insert_rows',\n\t\t'Insert rows',\n\t\t'Inserts empty rows before a row number (1-based; one past the last row appends). References below shift down.',\n\t\t{ before: { type: 'integer', minimum: 1, description: 'Row number to insert before.' }, count: COUNT },\n\t\t['before'],\n\t\tfalse,\n\t\t({ before, count = 1 }) => {\n\t\t\tconst index = before - 1;\n\t\t\tif (index > controller.document.rows.length) throw new Error(`Row ${before} is past the end of the sheet (${controller.document.rows.length} rows).`);\n\t\t\tfor (let i = 0; i < count; i++) controller.insertRow(index);\n\t\t\treturn { inserted: count, rows: `${before}:${before + count - 1}`, sheet: sheetSize() };\n\t\t}\n\t);\n\tconst deleteRows = structural(\n\t\t'delete_rows',\n\t\t'Delete rows',\n\t\t'Deletes rows starting at a row number (1-based) with their contents. References below shift up; references to deleted cells become #REF!.',\n\t\t{ start: { type: 'integer', minimum: 1, description: 'First row number to delete.' }, count: COUNT },\n\t\t['start'],\n\t\ttrue,\n\t\t({ start, count = 1 }) => {\n\t\t\tconst rows = controller.document.rows.slice(start - 1, start - 1 + count);\n\t\t\tif (rows.length < count) throw new Error(`Rows ${start}-${start + count - 1} are not all in the sheet (${controller.document.rows.length} rows).`);\n\t\t\tfor (const row of rows) controller.deleteRow(row.id);\n\t\t\treturn { deleted: count, sheet: sheetSize() };\n\t\t}\n\t);\n\tconst insertColumns = structural(\n\t\t'insert_columns',\n\t\t'Insert columns',\n\t\t'Inserts empty columns before a column letter (one past the last column appends). References to the right shift.',\n\t\t{ before: { type: 'string', description: 'Column letter to insert before, e.g. \"C\".' }, count: COUNT },\n\t\t['before'],\n\t\tfalse,\n\t\t({ before, count = 1 }) => {\n\t\t\tconst index = parseColumn(before);\n\t\t\tif (index > controller.document.columns.length) throw new Error(`Column ${before} is past the end of the sheet (${controller.document.columns.length} columns).`);\n\t\t\tfor (let i = 0; i < count; i++) controller.insertColumn(index);\n\t\t\treturn { inserted: count, columns: `${indexToColName(index)}:${indexToColName(index + count - 1)}`, sheet: sheetSize() };\n\t\t}\n\t);\n\tconst deleteColumns = structural(\n\t\t'delete_columns',\n\t\t'Delete columns',\n\t\t'Deletes columns starting at a column letter with their contents. References to the right shift left; references to deleted cells become #REF!.',\n\t\t{ start: { type: 'string', description: 'First column letter to delete, e.g. \"C\".' }, count: COUNT },\n\t\t['start'],\n\t\ttrue,\n\t\t({ start, count = 1 }) => {\n\t\t\tconst index = parseColumn(start);\n\t\t\tconst columns = controller.document.columns.slice(index, index + count);\n\t\t\tif (columns.length < count) throw new Error(`Columns from ${start} (${count}) are not all in the sheet (${controller.document.columns.length} columns).`);\n\t\t\tfor (const column of columns) controller.deleteColumn(column.id);\n\t\t\treturn { deleted: count, sheet: sheetSize() };\n\t\t}\n\t);\n\n\treturn {\n\t\tid: options.id,\n\t\tnamespace: options.namespace,\n\t\ttools: [getRange, setCell, setRange, insertRows, deleteRows, insertColumns, deleteColumns]\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Static editor tools (tools.ts) as a provider\n// ---------------------------------------------------------------------------\n\nexport interface EditorMcpToolProviderOptions<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n> extends ToolProviderOptions {\n\t/** Current editor / canvas state. */\n\tgetSnapshot: () => EditorSnapshot<TNode, TEdge>;\n\t/** Applies planned steps (e.g. via your canvas runes / editor controller). */\n\tapplySteps: (steps: AgentStep<TNode, TEdge>[]) => void | Promise<void>;\n\t/** Optional `view_editor` implementation; the tool is only exposed when provided. */\n\tcaptureView?: (args: { scope?: 'viewport' | 'canvas'; format?: 'jpeg' | 'png'; maxEdge?: number }) =>\n\t\t| Promise<{ data: string; mimeType: string }>\n\t\t| { data: string; mimeType: string };\n\t/** Options forwarded to the planner. */\n\tplannerOptions?: Parameters<typeof planToolCall>[3];\n\t/**\n\t * `split` (default): one strictly typed tool per operation (`canvas_add_node`,\n\t * `canvas_connect`, ..., `prompt_insert_text`, ...). `combined`: the\n\t * `edit_canvas` / `edit_prompt` tools with an `operation` argument.\n\t */\n\ttoolStyle?: 'split' | 'combined';\n\t/** Which edit tools to expose (default both). */\n\tsurfaces?: { canvas?: boolean; prompt?: boolean };\n}\n\n/** Describes which arguments a combined `edit_*` call is missing. */\nfunction missingArgumentsMessage(name: 'edit_canvas' | 'edit_prompt', args: Record<string, any>): string {\n\tconst required = EDIT_OPERATION_REQUIRED_ARGUMENTS[name][args.operation as string];\n\tif (!required) return `Unknown operation \"${args.operation}\".`;\n\tconst missing = required.filter((key) =>\n\t\tkey === 'id' ? args.id === undefined && args.node?.id === undefined : args[key] === undefined\n\t);\n\treturn missing.length\n\t\t? `Operation \"${args.operation}\" requires ${required.join(', ')}; missing: ${missing.join(', ')}.`\n\t\t: `Operation \"${args.operation}\" has invalid arguments (expected ${required.join(', ')} with the types in the schema).`;\n}\n\n/** What a set of applied steps created, so the agent can refer to it next. */\nfunction describeSteps<TNode extends CanvasNode, TEdge extends CanvasEdge>(steps: AgentStep<TNode, TEdge>[]) {\n\tconst nodes: Array<{ id: string; position: { x: number; y: number } }> = [];\n\tconst edges: Array<{ id: string; source: string; target: string }> = [];\n\tfor (const step of steps) {\n\t\tif (step.type === 'step:canvas_add_node') nodes.push({ id: step.node.id, position: step.node.position });\n\t\tif (step.type === 'step:canvas_add_edge') edges.push({ id: step.edge.id, source: step.edge.source, target: step.edge.target });\n\t}\n\treturn {\n\t\tapplied: steps.length,\n\t\tsteps: steps.map((s) => s.type),\n\t\t...(nodes.length || edges.length ? { created: { nodes, edges } } : {})\n\t};\n}\n\n/**\n * Exposes the editor MCP tools (`get_editor_state`, the canvas and prompt\n * edit tools, and `view_editor` when `captureView` is given) through a\n * `ToolRegistry`. Edits are checked against the current snapshot\n * (`validateAgentCommand`: unknown node ids, duplicate ids, unordered ranges\n * are tool errors), planned with the planner and handed to `applySteps`.\n * Results list the ids of created nodes and edges.\n */\nexport function createEditorMcpToolProvider<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(options: EditorMcpToolProviderOptions<TNode, TEdge>): AgentToolProvider {\n\tconst edit = (name: string) => async (args: Record<string, any>) => {\n\t\tconst command = toolCallToAgentCommand<TNode, TEdge>(name, args);\n\t\tif (!command) {\n\t\t\tthrow new Error(\n\t\t\t\tname === 'edit_canvas' || name === 'edit_prompt'\n\t\t\t\t\t? missingArgumentsMessage(name, args)\n\t\t\t\t\t: `Invalid arguments for \"${name}\".`\n\t\t\t);\n\t\t}\n\t\tconst snapshot = options.getSnapshot();\n\t\tconst problem = validateAgentCommand(command, snapshot);\n\t\tif (problem) throw new Error(problem);\n\t\tconst steps = planAgentCommand(command, snapshot, options.plannerOptions);\n\t\tawait options.applySteps(steps);\n\t\treturn describeSteps(steps);\n\t};\n\n\tconst canvas = options.surfaces?.canvas ?? true;\n\tconst prompt = options.surfaces?.prompt ?? true;\n\tconst editTools =\n\t\toptions.toolStyle === 'combined'\n\t\t\t? [...(canvas ? [MCP_TOOL_EDIT_CANVAS] : []), ...(prompt ? [MCP_TOOL_EDIT_PROMPT] : [])]\n\t\t\t: [...(canvas ? EDITOR_CANVAS_TOOLS : []), ...(prompt ? EDITOR_PROMPT_TOOLS : [])];\n\n\tconst tools: AgentTool[] = [\n\t\t{\n\t\t\t...MCP_TOOL_GET_EDITOR_STATE,\n\t\t\thandler: ({ includeDocument = true, includeCanvas = true }) => {\n\t\t\t\tconst snapshot = options.getSnapshot();\n\t\t\t\treturn {\n\t\t\t\t\t...(includeDocument && snapshot.document ? { document: snapshot.document } : {}),\n\t\t\t\t\t...(includeCanvas && snapshot.canvas ? { canvas: snapshot.canvas } : {})\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t...editTools.map((definition) => ({ ...definition, handler: edit(definition.name) }))\n\t] as AgentTool[];\n\n\tif (options.captureView) {\n\t\tconst capture = options.captureView;\n\t\ttools.push({\n\t\t\t...MCP_TOOL_VIEW_EDITOR,\n\t\t\thandler: async (args) => {\n\t\t\t\tconst image = await capture(args);\n\t\t\t\treturn { content: [{ type: 'image', data: image.data, mimeType: image.mimeType }] };\n\t\t\t}\n\t\t} as AgentTool);\n\t}\n\n\treturn { id: options.id, namespace: options.namespace, tools };\n}\n","import type { Editor } from '@tiptap/core';\nimport { closeHistory } from '@tiptap/pm/history';\nimport type { Node as ProsemirrorNode } from '@tiptap/pm/model';\nimport { getDocumentCharts, type DocumentChart } from '../extensions/chart/chart-node.js';\nimport { MAX_SPARKLINE_VALUES, SPARKLINE_KINDS, normalizeSparklineValues, sparklineLabel } from '../extensions/chart/sparkline-node.js';\nimport { CHART_UPDATE_PROPERTIES, SERIES_PROPS, VALUE } from '../chart/schemas.js';\nimport { normalizeChartSpec, parseChartValue } from '../chart/spec.js';\nimport { describeChart } from '../chart/summary.js';\nimport type { ChartSpec } from '../chart/types.js';\nimport type { AgentTool } from '../tools/registry.js';\nimport type { JsonSchema } from '../tools/schema.js';\n\nconst READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false } as const;\nconst WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\n\nconst SIZE_WIDTH: JsonSchema = {\n\ttype: ['number', 'null'],\n\tminimum: 50,\n\tmaximum: 4096,\n\tdescription: 'Width in pixels, or null to fill the line (default null).'\n};\nconst SIZE_HEIGHT: JsonSchema = { type: 'number', minimum: 50, maximum: 4096, description: 'Height in pixels (default 320).' };\n\n/** The chart data and presentation fields an agent can pass (a `ChartSpec` without `version`). */\nconst SPEC_PROPERTIES: Record<string, JsonSchema> = {\n\t...CHART_UPDATE_PROPERTIES,\n\tcategories: { type: 'array', items: { type: 'string' }, description: 'Category labels in order (x axis labels, or pie slices).' },\n\tseries: {\n\t\ttype: 'array',\n\t\tdescription: 'The series, each with one value per category (padded with gaps).',\n\t\titems: {\n\t\t\ttype: 'object',\n\t\t\tproperties: { id: { type: 'string', description: 'Stable id (default: from the name).' }, ...SERIES_PROPS },\n\t\t\trequired: ['name', 'values'],\n\t\t\tadditionalProperties: false\n\t\t}\n\t}\n};\n\n/** Drops `null` from series fields (null means \"use the default\" in the tool schema). */\nfunction cleanSeries(series: unknown): unknown {\n\tif (!Array.isArray(series)) return series;\n\treturn series.map((s) => (s && typeof s === 'object' ? Object.fromEntries(Object.entries(s).filter(([, v]) => v !== null)) : s));\n}\n\n/** Normalizes agent input as a chart, throwing every problem as one sentence list. */\nfunction checkedSpec(input: Record<string, unknown>): ChartSpec {\n\tconst { spec, issues } = normalizeChartSpec({ ...input, ...(input.series !== undefined ? { series: cleanSeries(input.series) } : {}) });\n\tif (issues.length) throw new Error(`The chart was not changed: ${issues.map((i) => i.message).join(' ')}`);\n\treturn spec;\n}\n\nfunction describe(chart: DocumentChart, includeSpec: boolean) {\n\tconst { spec, node } = chart;\n\treturn {\n\t\tid: chart.id,\n\t\tpos: chart.pos,\n\t\ttype: spec.type,\n\t\ttitle: spec.title,\n\t\tcategories: spec.categories,\n\t\tseries: spec.series.map((s) => ({ id: s.id, name: s.name })),\n\t\twidth: node.attrs.width ?? null,\n\t\theight: node.attrs.height,\n\t\tdescription: describeChart(spec),\n\t\t...(includeSpec ? { spec } : {})\n\t};\n}\n\nfunction sparklines(doc: ProsemirrorNode) {\n\tconst found: { pos: number; kind: string; values: (number | null)[]; label: string }[] = [];\n\tdoc.descendants((node, pos) => {\n\t\tif (node.type.name === 'sparkline') found.push({ pos, kind: node.attrs.kind, values: node.attrs.values, label: sparklineLabel(node) });\n\t});\n\treturn found;\n}\n\nfunction checkPosition(editor: Editor, at: number | undefined) {\n\tconst size = editor.state.doc.content.size;\n\tif (at !== undefined && at > size) throw new Error(`Position ${at} is outside the document (size ${size}).`);\n}\n\n/**\n * Chart tools for a rich-text editor whose schema has the `chart` node:\n * `list_document_charts` (read), `insert_chart` and `update_chart_in_document` (writes), plus\n * `insert_sparkline` when the schema has `sparkline`. `createRichTextToolProvider` adds them.\n */\nexport function createDocumentChartTools(editor: () => Editor): { read: () => AgentTool[]; write: () => AgentTool[] } {\n\tconst chartType = () => editor().schema.nodes.chart;\n\tconst findChart = (args: { chartId?: string; pos?: number }): DocumentChart => {\n\t\tconst charts = getDocumentCharts(editor().state.doc);\n\t\tconst list = charts.map((c) => `\"${c.id}\" at ${c.pos}`).join(', ') || 'none; add one with insert_chart';\n\t\tif (args.chartId !== undefined) {\n\t\t\tconst chart = charts.find((c) => c.id === args.chartId);\n\t\t\tif (!chart) throw new Error(`There is no chart \"${args.chartId}\" in the document. Charts: ${list}.`);\n\t\t\tif (args.pos !== undefined && args.pos !== chart.pos) throw new Error(`Chart \"${args.chartId}\" is at ${chart.pos}, not ${args.pos}; pass one of chartId or pos.`);\n\t\t\treturn chart;\n\t\t}\n\t\tif (args.pos !== undefined) {\n\t\t\tconst chart = charts.find((c) => c.pos === args.pos);\n\t\t\tif (!chart) throw new Error(`There is no chart at position ${args.pos}. Charts: ${list}.`);\n\t\t\treturn chart;\n\t\t}\n\t\tthrow new Error(`Pass chartId or pos (from list_document_charts). Charts: ${list}.`);\n\t};\n\n\tconst listCharts: AgentTool = {\n\t\tname: 'list_document_charts',\n\t\ttitle: 'List charts in the document',\n\t\tdescription:\n\t\t\t'Lists the charts in the document in order: id, document position, type, title, categories, series (ids and names), size in pixels and a plain-language description of the data. Also lists inline sparklines (position, kind, values). Pass the id or position to update_chart_in_document.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: { includeSpec: { type: 'boolean', description: 'Also return each chart\\'s full spec (default false).' } },\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'List charts in the document', ...READ },\n\t\thandler: ({ includeSpec = false }) => {\n\t\t\tconst doc = editor().state.doc;\n\t\t\treturn { charts: getDocumentCharts(doc).map((c) => describe(c, includeSpec)), sparklines: editor().schema.nodes.sparkline ? sparklines(doc) : [] };\n\t\t}\n\t};\n\n\tconst insertChart: AgentTool = {\n\t\tname: 'insert_chart',\n\t\ttitle: 'Insert a chart',\n\t\tdescription:\n\t\t\t'Inserts a chart block at a document position (or the cursor), as one undo step. Give the categories and series (one value per category) and any presentation fields (type, titles, axes, legend, stacking, palette, …). Invalid fields change nothing and come back as sentences. Returns the new chart\\'s id, position and stored spec.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tspec: { type: 'object', description: 'The chart: categories and series, plus optional presentation fields.', properties: SPEC_PROPERTIES, required: ['categories', 'series'], additionalProperties: false },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position (default: the selection). A position inside a paragraph splits it.' },\n\t\t\t\twidth: SIZE_WIDTH,\n\t\t\t\theight: SIZE_HEIGHT\n\t\t\t},\n\t\t\trequired: ['spec'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'Insert a chart', ...WRITE },\n\t\thandler: ({ spec: input, at, width = null, height }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckPosition(ed, at);\n\t\t\tconst spec = checkedSpec(input);\n\t\t\tconst id = (ed.extensionManager.extensions.find((e) => e.name === 'chart')?.options.generateId as (() => string) | undefined)?.() ?? `chart-${Date.now().toString(36)}`;\n\t\t\tconst node = { type: 'chart', attrs: { id, spec, width, ...(height !== undefined ? { height } : {}) } };\n\t\t\t// Each tool call is its own undo step, however quickly calls follow each other.\n\t\t\tconst chain = ed.chain().command(({ tr }) => (closeHistory(tr), true));\n\t\t\tconst ok = (at !== undefined ? chain.insertContentAt(at, node) : chain.insertContent(node)).run();\n\t\t\tconst chart = getDocumentCharts(ed.state.doc).find((c) => c.id === id);\n\t\t\tif (!ok || !chart) throw new Error(`A chart cannot go at ${at ?? ed.state.selection.from}; pass a position between blocks or inside a paragraph.`);\n\t\t\treturn { id: chart.id, pos: chart.pos, spec: chart.spec, width: chart.node.attrs.width, height: chart.node.attrs.height };\n\t\t}\n\t};\n\n\tconst updateChart: AgentTool = {\n\t\tname: 'update_chart_in_document',\n\t\ttitle: 'Change a chart in the document',\n\t\tdescription:\n\t\t\t'Changes one chart (by id or position from list_document_charts) as one undo step: data (categories, series — given series replace all) and / or presentation fields, which merge into the current spec (axes and legend field by field), plus its size. All-or-nothing: invalid values change nothing and come back as sentences. Returns the chart\\'s id, position and new spec.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tchartId: { type: 'string', description: 'Chart id from list_document_charts.' },\n\t\t\t\tpos: { type: 'integer', minimum: 0, description: 'Document position of the chart (from list_document_charts), instead of chartId.' },\n\t\t\t\tchanges: { type: 'object', description: 'Fields to change; omitted fields keep their value.', properties: SPEC_PROPERTIES, additionalProperties: false },\n\t\t\t\twidth: SIZE_WIDTH,\n\t\t\t\theight: { ...SIZE_HEIGHT, description: 'Height in pixels (default: unchanged).' }\n\t\t\t},\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'Change a chart in the document', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ chartId, pos, changes, width, height }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst chart = findChart({ chartId, pos });\n\t\t\tif (!changes && width === undefined && height === undefined) throw new Error('Nothing to change: pass changes, width or height, e.g. {\"changes\": {\"type\": \"line\"}}.');\n\t\t\tconst s = chart.spec;\n\t\t\tconst patch = (changes ?? {}) as Record<string, any>;\n\t\t\tconst spec = checkedSpec({\n\t\t\t\t...s,\n\t\t\t\t...patch,\n\t\t\t\txAxis: patch.xAxis ? { ...s.xAxis, ...patch.xAxis } : s.xAxis,\n\t\t\t\tyAxis: patch.yAxis ? { ...s.yAxis, ...patch.yAxis } : s.yAxis,\n\t\t\t\tyAxis2: patch.yAxis2 ? { ...s.yAxis2, ...patch.yAxis2 } : s.yAxis2,\n\t\t\t\tlegend: patch.legend ? { ...s.legend, ...patch.legend } : s.legend\n\t\t\t});\n\t\t\tconst attrs = { ...chart.node.attrs, spec, ...(width !== undefined ? { width } : {}), ...(height !== undefined ? { height } : {}) };\n\t\t\ted.view.dispatch(closeHistory(ed.state.tr.setNodeMarkup(chart.pos, undefined, attrs)));\n\t\t\treturn { id: chart.id, pos: chart.pos, spec, width: attrs.width, height: attrs.height };\n\t\t}\n\t};\n\n\tconst insertSparkline: AgentTool = {\n\t\tname: 'insert_sparkline',\n\t\ttitle: 'Insert a sparkline',\n\t\tdescription: 'Inserts a word-sized chart into the text at a document position (or the cursor), as one undo step. Returns its position and stored values.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tvalues: { type: 'array', items: VALUE, minItems: 1, maxItems: MAX_SPARKLINE_VALUES, description: 'Values in order (null for a gap).' },\n\t\t\t\tkind: { type: 'string', enum: [...SPARKLINE_KINDS], description: 'line (default), column, or win-loss (sign only).' },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position inside a paragraph (default: the selection).' },\n\t\t\t\twidth: { type: 'number', minimum: 4, maximum: 1000, description: 'Width in pixels (default 80).' },\n\t\t\t\theight: { type: 'number', minimum: 4, maximum: 200, description: 'Height in pixels (default 18).' },\n\t\t\t\tcolor: { type: 'string', description: 'CSS colour (default: the first palette colour).' },\n\t\t\t\tlabel: { type: 'string', description: 'Accessible label (default: \"Trend from <first> to <last>\").' }\n\t\t\t},\n\t\t\trequired: ['values'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'Insert a sparkline', ...WRITE },\n\t\thandler: ({ values, kind = 'line', at, width = 80, height = 18, color = null, label = null }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckPosition(ed, at);\n\t\t\tconst parsed = (values as unknown[]).map((v) => parseChartValue(v));\n\t\t\tconst bad = parsed.findIndex((v) => v === undefined);\n\t\t\tif (bad >= 0) throw new Error(`values[${bad}] (\"${String(values[bad])}\") is not a number; pass numbers, numeric text or null. Nothing was inserted.`);\n\t\t\tconst pos = at ?? ed.state.selection.from;\n\t\t\tif (!ed.state.doc.resolve(pos).parent.inlineContent) throw new Error(`Position ${pos} is between blocks; a sparkline goes inside a paragraph (use a position from get_text {blocks: true}).`);\n\t\t\tconst stored = normalizeSparklineValues(parsed);\n\t\t\ted.chain().command(({ tr }) => (closeHistory(tr), true)).insertContentAt(pos, { type: 'sparkline', attrs: { values: stored, kind, width, height, color, label } }).run();\n\t\t\treturn { pos, kind, values: stored };\n\t\t}\n\t};\n\n\treturn {\n\t\tread: () => (chartType() ? [listCharts] : []),\n\t\twrite: () => (chartType() ? [insertChart, updateChart, ...(editor().schema.nodes.sparkline ? [insertSparkline] : [])] : [])\n\t};\n}\n","import { hasVariantCommands, type ComponentCommandTarget } from '../commands/builtins.js';\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport type { ToolProviderOptions } from './providers.js';\n\nconst IDS = { type: 'array', items: { type: 'string' }, description: 'Node ids (default: the selection).' } as const;\nconst ID = { type: 'string', description: 'An instance, or a layer inside one (default: the first selected node).' } as const;\n\nconst COMPONENT_ID = { type: 'string', description: 'Component or component set id (from list_components).' } as const;\nconst PARENT_ID = { type: 'string', description: 'Frame to place the instance in (default: the canvas root).' } as const;\nconst X = { type: 'number', description: 'X position (canvas coordinates, or relative to the parent frame).' } as const;\nconst Y = { type: 'number', description: 'Y position (canvas coordinates, or relative to the parent frame).' } as const;\n\nconst READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false } as const;\nconst DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false } as const;\n\n/** Tool titles shown by MCP clients. */\nconst TITLES: Record<string, string> = {\n\tlist_components: 'List components',\n\tinspect_instance: 'Inspect an instance',\n\tcreate_component: 'Create a component',\n\tcombine_as_variants: 'Combine as variants',\n\tcreate_instance: 'Create an instance',\n\tset_instance_properties: 'Set instance properties',\n\tswap_instance: 'Swap an instance',\n\treset_overrides: 'Reset overrides',\n\tpush_overrides: 'Push overrides to the main component',\n\tdetach_instance: 'Detach instances',\n\tgo_to_main_component: 'Go to the main component',\n\trestore_main_component: 'Restore the main component',\n\tadd_variant: 'Add a variant',\n\tremove_variant: 'Remove a variant',\n\tset_variant_properties: 'Set variant properties',\n\trename_variant_property: 'Rename a variant property',\n\trename_variant_value: 'Rename a variant value'\n};\n\n/** Tools that discard state the agent cannot get back by calling another tool. */\nconst DESTRUCTIVE_TOOLS = new Set(['reset_overrides', 'push_overrides', 'detach_instance', 'remove_variant']);\n\ntype Outcome = { ok: true; ids: string[] } | { ok: false; reason: string };\nconst check = (result: Outcome) => {\n\tif (!result.ok) throw new Error(result.reason);\n\treturn { ids: result.ids };\n};\n\n/**\n * Agent tools for canvas components and instances, backed by a components controller\n * (`createCanvasComponentsController`): `list_components`, `inspect_instance`,\n * `create_component`, `combine_as_variants`, `create_instance`, `set_instance_properties`\n * (variants and component properties), `swap_instance`, `reset_overrides`, `push_overrides`,\n * `detach_instance`, `go_to_main_component`, `restore_main_component` and (when the controller\n * has them) the variant editors `add_variant`, `remove_variant`, `set_variant_properties`,\n * `rename_variant_property` and `rename_variant_value`. Refused actions come back as tool errors\n * carrying the reason.\n */\nexport function createCanvasComponentToolProvider(\n\tcontroller: ComponentCommandTarget,\n\toptions: ToolProviderOptions = { id: 'canvas-components' }\n): AgentToolProvider {\n\tconst tool = (\n\t\tname: string,\n\t\tdescription: string,\n\t\tproperties: Record<string, unknown>,\n\t\thandler: AgentTool['handler'],\n\t\textra: { required?: string[]; readOnly?: boolean } = {}\n\t): AgentTool => ({\n\t\tname,\n\t\ttitle: TITLES[name],\n\t\tdescription,\n\t\tinputSchema: { type: 'object', properties: properties as never, ...(extra.required ? { required: extra.required } : {}), additionalProperties: false },\n\t\tannotations: {\n\t\t\ttitle: TITLES[name],\n\t\t\t...(extra.readOnly ? READ : DESTRUCTIVE_TOOLS.has(name) ? DESTRUCTIVE : WRITE)\n\t\t},\n\t\thandler\n\t});\n\tconst tools: AgentTool[] = [\n\t\ttool('list_components', 'Lists components (id, name, variant values, instance count) and component sets with their variant options.', {}, () => controller.list(), {\n\t\t\treadOnly: true\n\t\t}),\n\t\ttool(\n\t\t\t'inspect_instance',\n\t\t\t'Describes an instance: its main component, variant, component property values (with types) and the overrides of its layers.',\n\t\t\t{ id: ID },\n\t\t\t({ id }) => {\n\t\t\t\tconst info = controller.inspect(id);\n\t\t\t\tif (!info) throw new Error('Not an instance (or a layer inside one).');\n\t\t\t\treturn info;\n\t\t\t},\n\t\t\t{ readOnly: true }\n\t\t),\n\t\ttool('create_component', 'Turns the given frame into a main component, or wraps the given layers in a new one.', { ids: IDS }, ({ ids }) =>\n\t\t\tcheck(controller.createComponent(ids))\n\t\t),\n\t\ttool('combine_as_variants', 'Wraps sibling components in a component set (variants named \"Property=Value, …\").', { ids: IDS }, ({ ids }) =>\n\t\t\tcheck(controller.combineAsVariants(ids))\n\t\t),\n\t\ttool(\n\t\t\t'create_instance',\n\t\t\t'Places an instance of a component or component set, optionally inside a frame, at a position, with property values.',\n\t\t\t{\n\t\t\t\tcomponentId: COMPONENT_ID,\n\t\t\t\tparentId: PARENT_ID,\n\t\t\t\tx: X,\n\t\t\t\ty: Y,\n\t\t\t\tproperties: { type: 'object', additionalProperties: true, description: 'Variant and component property values.' }\n\t\t\t},\n\t\t\t({ componentId, parentId, x, y, properties }) =>\n\t\t\t\tcheck(\n\t\t\t\t\tcontroller.createInstance(componentId, {\n\t\t\t\t\t\t...(parentId !== undefined ? { parentId } : {}),\n\t\t\t\t\t\t...(x !== undefined || y !== undefined ? { position: { x: x ?? 0, y: y ?? 0 } } : {}),\n\t\t\t\t\t\t...(properties ? { properties } : {})\n\t\t\t\t\t})\n\t\t\t\t),\n\t\t\t{ required: ['componentId'] }\n\t\t),\n\t\ttool(\n\t\t\t'set_instance_properties',\n\t\t\t'Sets property values of instances: variant properties switch the variant (keeping compatible overrides), booleans toggle layers, text sets text, instance swap takes a component id.',\n\t\t\t{\n\t\t\t\tproperties: {\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\tdescription: 'Property name → value (see inspect_instance for the names and types).'\n\t\t\t\t},\n\t\t\t\tids: IDS\n\t\t\t},\n\t\t\t({ properties, ids }) => check(controller.setInstanceProperties(properties, ids)),\n\t\t\t{ required: ['properties'] }\n\t\t),\n\t\ttool(\n\t\t\t'swap_instance',\n\t\t\t'Makes instances show another component (or a set’s default variant), keeping overrides of layers with matching names.',\n\t\t\t{ componentId: COMPONENT_ID, ids: IDS },\n\t\t\t({ componentId, ids }) => check(controller.swapInstance(componentId, ids)),\n\t\t\t{ required: ['componentId'] }\n\t\t),\n\t\ttool(\n\t\t\t'reset_overrides',\n\t\t\t'Resets overrides: of a whole instance (default), of one layer, or one override group such as \"data.label\" or \"shape.fill\".',\n\t\t\t{ id: ID, group: { type: 'string', description: 'Override group, e.g. \"data.label\" or \"shape.fill\" (default: all).' } },\n\t\t\t({ id, group }) => check(controller.resetOverrides(id, group))\n\t\t),\n\t\ttool('push_overrides', 'Copies an instance’s overrides to its main component (and so to every other instance).', { id: ID }, ({ id }) =>\n\t\t\tcheck(controller.pushOverrides(id))\n\t\t),\n\t\ttool('detach_instance', 'Turns instances into plain frames that keep their current look.', { ids: IDS }, ({ ids }) => check(controller.detachInstance(ids))),\n\t\ttool('go_to_main_component', 'Selects the main component of an instance and returns its id.', { id: ID }, ({ id }) => {\n\t\t\tconst main = controller.goToMainComponent(id);\n\t\t\tif (!main) throw new Error('The main component was not found.');\n\t\t\treturn { id: main };\n\t\t}),\n\t\ttool('restore_main_component', 'Turns an instance whose main component was deleted back into the main component.', { id: ID }, ({ id }) =>\n\t\t\tcheck(controller.restoreMainComponent(id))\n\t\t)\n\t];\n\tif (hasVariantCommands(controller)) {\n\t\tconst SET = { type: 'string', description: 'Component set, or one of its variants (default: the selection’s set).' };\n\t\tconst VARIANT = { type: 'string', description: 'Variant id (default: the first selected variant).' };\n\t\tconst VALUES = { type: 'object', additionalProperties: { type: 'string' }, description: 'Variant property → value, e.g. { \"Size\": \"Medium\" }.' };\n\t\ttools.push(\n\t\t\ttool(\n\t\t\t\t'add_variant',\n\t\t\t\t'Adds a variant to a component set by duplicating one (default: the set’s default variant) with new property values. Unnamed properties keep the source’s values; new property names are added to every variant (\"Default\"). A combination another variant has is refused. Without values the next \"VariantN\" is used.',\n\t\t\t\t{ setId: SET, from: { type: 'string', description: 'Variant to duplicate.' }, variant: VALUES, x: X, y: Y },\n\t\t\t\t({ setId, from, variant, x, y }) =>\n\t\t\t\t\tcheck(\n\t\t\t\t\t\tcontroller.addVariant(setId, {\n\t\t\t\t\t\t\t...(from !== undefined ? { from } : {}),\n\t\t\t\t\t\t\t...(variant ? { variant } : {}),\n\t\t\t\t\t\t\t...(x !== undefined || y !== undefined ? { position: { x: x ?? 0, y: y ?? 0 } } : {})\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'remove_variant',\n\t\t\t\t'Removes a variant from its component set (not the last one). Its instances switch to the closest remaining variant, keeping overrides.',\n\t\t\t\t{ id: VARIANT },\n\t\t\t\t({ id }) => check(controller.removeVariant(id))\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'set_variant_properties',\n\t\t\t\t'Sets a variant’s property values (merged with its current ones); new property names are added to every variant. A combination another variant has is refused.',\n\t\t\t\t{ values: VALUES, id: VARIANT },\n\t\t\t\t({ values, id }) => check(controller.setVariantProperties(values, id)),\n\t\t\t\t{ required: ['values'] }\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'rename_variant_property',\n\t\t\t\t'Renames a variant property across a component set (instances keep their variant).',\n\t\t\t\t{\n\t\t\t\t\tname: { type: 'string', description: 'Current property name.' },\n\t\t\t\t\tnewName: { type: 'string', description: 'New property name.' },\n\t\t\t\t\tsetId: SET\n\t\t\t\t},\n\t\t\t\t({ name, newName, setId }) => check(controller.renameVariantProperty(name, newName, setId)),\n\t\t\t\t{ required: ['name', 'newName'] }\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'rename_variant_value',\n\t\t\t\t'Renames a value of a variant property across a component set (instances keep their variant).',\n\t\t\t\t{\n\t\t\t\t\tproperty: { type: 'string', description: 'Variant property name.' },\n\t\t\t\t\tvalue: { type: 'string', description: 'Current value.' },\n\t\t\t\t\tnewValue: { type: 'string', description: 'New value.' },\n\t\t\t\t\tsetId: SET\n\t\t\t\t},\n\t\t\t\t({ property, value, newValue, setId }) => check(controller.renameVariantValue(property, value, newValue, setId)),\n\t\t\t\t{ required: ['property', 'value', 'newValue'] }\n\t\t\t)\n\t\t);\n\t}\n\treturn { id: options.id, namespace: options.namespace, tools };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQO,SAAS,cAAc,MAAuC;AACpE,UAAQ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AA,UAC7D,OAAO;AAAA,QACR;AAAA,QACA,CAAC,EAAE,MAAM,SAAS,MAAM,MAAM,MAAM,WAAW,sBAAsB,MAAM,SAAS,KAAK,CAAC;AAAA,QAC1F,EAAE,UAAU,CAAC,QAAQ,SAAS,EAAE;AAAA,MACjC;AAAA,MACA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,UACC,UAAU,EAAE,MAAM,UAAU,aAAa,yBAAyB;AAAA,UAClE,OAAO,EAAE,MAAM,UAAU,aAAa,iBAAiB;AAAA,UACvD,UAAU,EAAE,MAAM,UAAU,aAAa,aAAa;AAAA,UACtD,OAAO;AAAA,QACR;AAAA,QACA,CAAC,EAAE,UAAU,OAAO,UAAU,MAAM,MAAM,MAAM,WAAW,mBAAmB,UAAU,OAAO,UAAU,KAAK,CAAC;AAAA,QAC/G,EAAE,UAAU,CAAC,YAAY,SAAS,UAAU,EAAE;AAAA,MAC/C;AAAA,IACD;AAAA,EACD;AACA,SAAO,EAAE,IAAI,QAAQ,IAAI,WAAW,QAAQ,WAAW,MAAM;AAC9D;","names":["READ","WRITE"]}
|
|
1
|
+
{"version":3,"sources":["../../src/agent/planner.ts","../../src/agent/providers.ts","../../src/agent/documentChartTools.ts","../../src/agent/componentTools.ts"],"sourcesContent":["import { ensureLayout, getLayoutedNodes, placeBeside } from '../canvas/layout.js';\nimport type { CanvasEdge, CanvasNode, Rect, Side } from '../canvas/types.js';\nimport type { AgentCommand, AgentStep, EditorSnapshot } from './types.js';\n\n/**\n * Normalizes a placement side from either the planner vocabulary (`right | below | left | above`)\n * or the MCP tool schema vocabulary (`top | right | bottom | left`). Unknown values fall back to `right`.\n */\nexport function normalizeSide(side: string | undefined | null): Side {\n\tswitch (side) {\n\t\tcase 'top':\n\t\tcase 'above':\n\t\t\treturn 'above';\n\t\tcase 'bottom':\n\t\tcase 'below':\n\t\t\treturn 'below';\n\t\tcase 'left':\n\t\t\treturn 'left';\n\t\tcase 'right':\n\t\tdefault:\n\t\t\treturn 'right';\n\t}\n}\n\n/**\n * Plans a sequence of atomic execution steps from a high-level agent command.\n */\nexport function planAgentCommand<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(\n\tcommand: AgentCommand<TNode, TEdge>,\n\tsnapshot: EditorSnapshot<TNode, TEdge>,\n\toptions: {\n\t\tdefaultNodeSize?: { width: number; height: number };\n\t\tidGenerator?: () => string;\n\t} = {}\n): AgentStep<TNode, TEdge>[] {\n\tconst defaultNodeSize = options.defaultNodeSize ?? { width: 200, height: 60 };\n\tconst idGen = options.idGenerator ?? (() => `node-${Math.random().toString(36).substring(2, 9)}`);\n\tconst edgeIdGen = () => `edge-${Math.random().toString(36).substring(2, 9)}`;\n\n\tconst nodes = snapshot.canvas?.nodes ?? [];\n\tconst edges = snapshot.canvas?.edges ?? [];\n\n\tswitch (command.type) {\n\t\tcase 'canvas:add_node': {\n\t\t\tlet pos = command.node.position;\n\t\t\t// Only anchor to (and connect from) a node that actually exists.\n\t\t\tconst anchorId =\n\t\t\t\tcommand.nearNodeId && nodes.some((n) => n.id === command.nearNodeId)\n\t\t\t\t\t? command.nearNodeId\n\t\t\t\t\t: undefined;\n\n\t\t\tif (!pos) {\n\t\t\t\tconst rects: Record<string, Rect> = {};\n\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\trects[n.id] = {\n\t\t\t\t\t\tx: n.position.x,\n\t\t\t\t\t\ty: n.position.y,\n\t\t\t\t\t\twidth: n.measured?.width ?? (n as any).width ?? defaultNodeSize.width,\n\t\t\t\t\t\theight: n.measured?.height ?? (n as any).height ?? defaultNodeSize.height\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (anchorId) {\n\t\t\t\t\t// Use collision-aware directional placement\n\t\t\t\t\tpos = placeBeside(rects, defaultNodeSize, normalizeSide(command.side), anchorId);\n\t\t\t\t} else if (nodes.length > 0) {\n\t\t\t\t\t// Default beside the last node\n\t\t\t\t\tconst lastNode = nodes[nodes.length - 1];\n\t\t\t\t\tpos = placeBeside(rects, defaultNodeSize, 'right', lastNode.id);\n\t\t\t\t} else {\n\t\t\t\t\tpos = { x: 100, y: 100 };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst fullNode: TNode = {\n\t\t\t\t...command.node,\n\t\t\t\tid: command.node.id || idGen(),\n\t\t\t\tposition: pos\n\t\t\t} as TNode;\n\n\t\t\tconst steps: AgentStep<TNode, TEdge>[] = [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_add_node',\n\t\t\t\t\tnode: fullNode\n\t\t\t\t}\n\t\t\t];\n\n\t\t\t// If attached to nearNode, optionally automatically connect\n\t\t\tif (anchorId) {\n\t\t\t\tsteps.push({\n\t\t\t\t\ttype: 'step:canvas_add_edge',\n\t\t\t\t\tedge: {\n\t\t\t\t\t\tid: edgeIdGen(),\n\t\t\t\t\t\tsource: anchorId,\n\t\t\t\t\t\ttarget: fullNode.id\n\t\t\t\t\t} as TEdge\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn steps;\n\t\t}\n\n\t\tcase 'canvas:remove_nodes': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_remove_nodes',\n\t\t\t\t\tnodeIds: command.nodeIds\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:connect': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_add_edge',\n\t\t\t\t\tedge: {\n\t\t\t\t\t\tid: edgeIdGen(),\n\t\t\t\t\t\tsource: command.source,\n\t\t\t\t\t\ttarget: command.target,\n\t\t\t\t\t\tlabel: command.label\n\t\t\t\t\t} as TEdge\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:update_node': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_update_node',\n\t\t\t\t\tid: command.id,\n\t\t\t\t\tdata: command.data\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:layout': {\n\t\t\tconst dir = command.direction ?? 'LR';\n\t\t\tlet layouted: TNode[];\n\n\t\t\t// Matches the MCP tool schema: `incremental` defaults to true.\n\t\t\tif (command.incremental ?? true) {\n\t\t\t\tconst stored: Record<string, { x: number; y: number }> = {};\n\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\tif (n.position && (n.position.x !== 0 || n.position.y !== 0)) {\n\t\t\t\t\t\tstored[n.id] = { ...n.position };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlayouted = ensureLayout(nodes, edges, {\n\t\t\t\t\tdirection: dir,\n\t\t\t\t\tstoredPositions: stored\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlayouted = getLayoutedNodes(nodes, edges, undefined, { direction: dir });\n\t\t\t}\n\n\t\t\tconst positions: Record<string, { x: number; y: number }> = {};\n\t\t\tfor (const node of layouted) {\n\t\t\t\tpositions[node.id] = { ...node.position };\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_move_nodes',\n\t\t\t\t\tpositions\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:select': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_select',\n\t\t\t\t\tnodeIds: command.nodeIds\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'canvas:highlight': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:canvas_highlight',\n\t\t\t\t\tnodeIds: command.nodeIds,\n\t\t\t\t\tcolor: command.color ?? '#3b82f6',\n\t\t\t\t\tdurationMs: command.durationMs ?? 2000\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:insert_text': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_insert',\n\t\t\t\t\ttext: command.text,\n\t\t\t\t\tat: command.at\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:replace_range': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_replace',\n\t\t\t\t\tfrom: command.from,\n\t\t\t\t\tto: command.to,\n\t\t\t\t\ttext: command.text\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:set_variable': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_set_variable',\n\t\t\t\t\tname: command.name,\n\t\t\t\t\tvalue: command.value\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'prompt:select': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:prompt_select',\n\t\t\t\t\tfrom: command.from,\n\t\t\t\t\tto: command.to\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'choreography:say': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:say',\n\t\t\t\t\ttext: command.text,\n\t\t\t\t\tatNodeId: command.atNodeId,\n\t\t\t\t\tposition: command.position\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'choreography:wait': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:wait',\n\t\t\t\t\tms: command.ms\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tcase 'tool:call': {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: 'step:tool_call',\n\t\t\t\t\tname: command.name,\n\t\t\t\t\targuments: command.arguments ?? {}\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn [];\n\t\t}\n\t}\n}\n\nconst CANVAS_TOOL_OPERATIONS: Record<string, string> = {\n\tcanvas_add_node: 'add_node',\n\tcanvas_remove_nodes: 'remove_nodes',\n\tcanvas_connect: 'connect',\n\tcanvas_update_node: 'update_node',\n\tcanvas_layout: 'layout',\n\tcanvas_select: 'select',\n\tcanvas_highlight: 'highlight'\n};\n\nconst PROMPT_TOOL_OPERATIONS: Record<string, string> = {\n\tprompt_insert_text: 'insert_text',\n\tprompt_replace_range: 'replace_range',\n\tprompt_set_variable: 'set_variable',\n\tprompt_select: 'select'\n};\n\n/**\n * Converts an MCP tool call into a planner command. `edit_canvas` /\n * `edit_prompt` and the per-operation `canvas_*` / `prompt_*` tools (see\n * `tools/definitions.ts`) map to canvas/prompt commands using the MCP\n * schema's vocabulary; every other tool, including dynamic `ToolRegistry`\n * tools, becomes a `tool:call` command. Returns `null` when a static tool's\n * arguments are missing what the operation needs.\n */\nexport function toolCallToAgentCommand<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(name: string, args: Record<string, any> = {}): AgentCommand<TNode, TEdge> | null {\n\tconst ids = (value: unknown): string[] | null =>\n\t\tArray.isArray(value) && value.every((v) => typeof v === 'string') ? value : null;\n\tconst num = (value: unknown) => typeof value === 'number' && Number.isFinite(value);\n\n\tconst canvasOperation = name === 'edit_canvas' ? args.operation : CANVAS_TOOL_OPERATIONS[name];\n\tif (canvasOperation !== undefined) {\n\t\tswitch (canvasOperation) {\n\t\t\tcase 'add_node':\n\t\t\t\treturn args.node && typeof args.node === 'object' && !Array.isArray(args.node)\n\t\t\t\t\t? {\n\t\t\t\t\t\t\ttype: 'canvas:add_node',\n\t\t\t\t\t\t\tnode: { ...args.node, data: args.node.data ?? {} },\n\t\t\t\t\t\t\tnearNodeId: args.nearNodeId,\n\t\t\t\t\t\t\tside: args.side\n\t\t\t\t\t\t}\n\t\t\t\t\t: null;\n\t\t\tcase 'remove_nodes':\n\t\t\t\treturn ids(args.nodeIds) ? { type: 'canvas:remove_nodes', nodeIds: args.nodeIds } : null;\n\t\t\tcase 'connect':\n\t\t\t\treturn typeof args.source === 'string' && typeof args.target === 'string'\n\t\t\t\t\t? { type: 'canvas:connect', source: args.source, target: args.target, label: args.label }\n\t\t\t\t\t: null;\n\t\t\tcase 'update_node': {\n\t\t\t\tconst id = args.node?.id ?? args.id;\n\t\t\t\treturn typeof id === 'string'\n\t\t\t\t\t? { type: 'canvas:update_node', id, data: args.node?.data ?? args.data ?? {} }\n\t\t\t\t\t: null;\n\t\t\t}\n\t\t\tcase 'layout':\n\t\t\t\treturn { type: 'canvas:layout', direction: args.direction, incremental: args.incremental };\n\t\t\tcase 'select':\n\t\t\t\treturn ids(args.nodeIds) ? { type: 'canvas:select', nodeIds: args.nodeIds } : null;\n\t\t\tcase 'highlight':\n\t\t\t\treturn ids(args.nodeIds)\n\t\t\t\t\t? {\n\t\t\t\t\t\t\ttype: 'canvas:highlight',\n\t\t\t\t\t\t\tnodeIds: args.nodeIds,\n\t\t\t\t\t\t\t...(typeof args.color === 'string' ? { color: args.color } : {}),\n\t\t\t\t\t\t\t...(num(args.durationMs) ? { durationMs: args.durationMs } : {})\n\t\t\t\t\t\t}\n\t\t\t\t\t: null;\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst promptOperation = name === 'edit_prompt' ? args.operation : PROMPT_TOOL_OPERATIONS[name];\n\tif (promptOperation !== undefined) {\n\t\tswitch (promptOperation) {\n\t\t\tcase 'insert_text':\n\t\t\t\treturn typeof args.text === 'string'\n\t\t\t\t\t? { type: 'prompt:insert_text', text: args.text, at: num(args.at) ? args.at : undefined }\n\t\t\t\t\t: null;\n\t\t\tcase 'replace_range':\n\t\t\t\treturn typeof args.text === 'string' && num(args.from) && num(args.to)\n\t\t\t\t\t? { type: 'prompt:replace_range', from: args.from, to: args.to, text: args.text }\n\t\t\t\t\t: null;\n\t\t\tcase 'set_variable':\n\t\t\t\treturn typeof args.name === 'string'\n\t\t\t\t\t? { type: 'prompt:set_variable', name: args.name, value: args.value }\n\t\t\t\t\t: null;\n\t\t\tcase 'select':\n\t\t\t\treturn num(args.from) && num(args.to) ? { type: 'prompt:select', from: args.from, to: args.to } : null;\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn { type: 'tool:call', name, arguments: args };\n}\n\n/**\n * Checks a command against the snapshot before it is planned and returns a\n * message an agent can act on, or `null` when it is valid: node ids must\n * exist (and a new node's id must not), an edge needs two different existing\n * nodes, and prompt ranges must be ordered. Prompt positions are host-defined,\n * so their upper bound is left to the host's `applySteps`.\n * The planner itself stays lenient (it falls back instead of failing), so\n * tool providers call this first.\n */\nexport function validateAgentCommand<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(command: AgentCommand<TNode, TEdge>, snapshot: EditorSnapshot<TNode, TEdge>): string | null {\n\tconst known = new Set((snapshot.canvas?.nodes ?? []).map((n) => n.id));\n\tconst missing = (nodeIds: readonly string[]) => {\n\t\tconst unknown = nodeIds.filter((id) => !known.has(id));\n\t\treturn unknown.length\n\t\t\t? `Unknown node id${unknown.length > 1 ? 's' : ''}: ${unknown.map((id) => JSON.stringify(id)).join(', ')}. Call get_editor_state for the current ids.`\n\t\t\t: null;\n\t};\n\tconst range = (from: number, to: number) => {\n\t\tif (from < 0 || to < 0) return 'Positions must be >= 0.';\n\t\tif (from > to) return `\"from\" (${from}) must not be after \"to\" (${to}).`;\n\t\treturn null;\n\t};\n\n\tswitch (command.type) {\n\t\tcase 'canvas:add_node':\n\t\t\tif (command.node.id && known.has(command.node.id)) return `A node with id \"${command.node.id}\" already exists.`;\n\t\t\treturn command.nearNodeId ? missing([command.nearNodeId]) : null;\n\t\tcase 'canvas:remove_nodes':\n\t\tcase 'canvas:highlight':\n\t\t\treturn command.nodeIds.length ? missing(command.nodeIds) : 'Pass at least one node id.';\n\t\tcase 'canvas:select':\n\t\t\treturn missing(command.nodeIds);\n\t\tcase 'canvas:connect':\n\t\t\tif (command.source === command.target) return 'An edge needs two different nodes.';\n\t\t\treturn missing([command.source, command.target]);\n\t\tcase 'canvas:update_node':\n\t\t\treturn missing([command.id]);\n\t\tcase 'prompt:insert_text':\n\t\t\treturn command.at !== undefined ? range(command.at, command.at) : null;\n\t\tcase 'prompt:replace_range':\n\t\tcase 'prompt:select':\n\t\t\treturn range(command.from, command.to);\n\t\tcase 'choreography:say':\n\t\t\treturn command.atNodeId ? missing([command.atNodeId]) : null;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/**\n * Plans the steps for an MCP tool call: static editor tools are planned like\n * the equivalent commands, any other tool becomes a `step:tool_call` to be\n * executed with `ToolRegistry.callTool`. Returns `[]` for invalid arguments.\n */\nexport function planToolCall<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(\n\tname: string,\n\targs: Record<string, any>,\n\tsnapshot: EditorSnapshot<TNode, TEdge>,\n\toptions?: Parameters<typeof planAgentCommand>[2]\n): AgentStep<TNode, TEdge>[] {\n\tconst command = toolCallToAgentCommand<TNode, TEdge>(name, args);\n\treturn command ? planAgentCommand(command, snapshot, options) : [];\n}\n","import type { Editor } from '@tiptap/core';\nimport { plainTextToSlice, getEditorText } from '../serializers/plain-text.js';\nimport { getEditorMarkdown } from '../serializers/markdown.js';\nimport { TextSelection } from '@tiptap/pm/state';\nimport {\n\tTABLE_ACTIONS,\n\tgetTableActionState,\n\tgetTableState,\n\tisTableEnabled,\n\trunTableAction,\n\ttype TableAction\n} from '../extensions/table/actions.js';\nimport { applyReplacements, searchDocument, type FindMatch } from '../extensions/find-replace/search.js';\nimport type { FindOptions } from '../extensions/find-replace/pattern.js';\nimport type { SpreadsheetController } from '../spreadsheet/controller.js';\nimport { colNameToIndex, indexToColName, isFormulaError } from '../spreadsheet/formula/evaluator.js';\nimport { planAgentCommand, toolCallToAgentCommand, validateAgentCommand, type planToolCall } from './planner.js';\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport {\n\tEDIT_OPERATION_REQUIRED_ARGUMENTS,\n\tEDITOR_CANVAS_TOOLS,\n\tEDITOR_PROMPT_TOOLS,\n\tMCP_TOOL_EDIT_CANVAS,\n\tMCP_TOOL_EDIT_PROMPT,\n\tMCP_TOOL_GET_EDITOR_STATE,\n\tMCP_TOOL_VIEW_EDITOR\n} from '../tools/definitions.js';\nimport type { AgentStep, EditorSnapshot } from './types.js';\nimport { createDocumentChartTools } from './documentChartTools.js';\nimport type { CanvasEdge, CanvasNode } from '../canvas/types.js';\n\nexport interface ToolProviderOptions {\n\t/** Provider id (unique per registry). */\n\tid: string;\n\t/** Always prefix tool names with `<namespace>__`. */\n\tnamespace?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Rich-text editor provider\n// ---------------------------------------------------------------------------\n\n/** A TipTap editor, or anything exposing one as `.editor` (e.g. `EditorController`). */\nexport type RichTextToolTarget = Editor | { editor: Editor };\n\nconst toEditor = (target: RichTextToolTarget): Editor =>\n\t'commands' in target ? (target as Editor) : (target as { editor: Editor }).editor;\n\n/** Replaces `from..to` with literal text (HTML is not parsed; newlines split paragraphs). */\nfunction replaceWithText(editor: Editor, from: number, to: number, text: string) {\n\tconst { state, view } = editor;\n\tconst tr = /[\\r\\n]/.test(text)\n\t\t? state.tr.replace(from, to, plainTextToSlice(text, state.schema))\n\t\t: text\n\t\t\t? state.tr.insertText(text, from, to)\n\t\t\t: state.tr.delete(from, to);\n\tview.dispatch(tr.scrollIntoView());\n}\n\nfunction selectionInfo(editor: Editor) {\n\tconst { from, to } = editor.state.selection;\n\treturn { from, to, text: editor.state.doc.textBetween(from, to, '\\n') };\n}\n\n/** Throws a tool error unless `from..to` is an ordered range inside the document. */\nfunction checkRange(editor: Editor, from: number, to: number) {\n\tconst size = editor.state.doc.content.size;\n\tif (from > to) throw new Error(`\"from\" (${from}) must not be after \"to\" (${to}).`);\n\tif (to > size) throw new Error(`Position ${to} is outside the document (size ${size}).`);\n}\n\n/** Textblocks (paragraphs, headings, cells...) with the positions their text spans. */\nfunction textBlocks(editor: Editor) {\n\tconst blocks: Array<{ type: string; from: number; to: number; text: string }> = [];\n\teditor.state.doc.descendants((node, pos) => {\n\t\tif (!node.isTextblock) return true;\n\t\tblocks.push({ type: node.type.name, from: pos + 1, to: pos + 1 + node.content.size, text: node.textContent });\n\t\treturn false;\n\t});\n\treturn blocks;\n}\n\nconst FIND_SCHEMA_PROPERTIES = {\n\tmatchCase: { type: 'boolean', description: 'Case-sensitive match (default false).' },\n\twholeWord: { type: 'boolean', description: 'Match whole words only (default false).' },\n\tregex: {\n\t\ttype: 'boolean',\n\t\tdescription: 'Treat the query as a JavaScript regular expression (default false: literal text).'\n\t}\n} as const;\n\nconst CONTEXT_CHARS = 30;\n\n/** Runs a literal (or regex) search; throws a tool error for an invalid pattern. */\nfunction findMatches(\n\teditor: Editor,\n\tquery: string,\n\targs: { matchCase?: boolean; wholeWord?: boolean; regex?: boolean },\n\treplacement?: string\n): { matches: FindMatch[]; truncated: boolean } {\n\tconst options: FindOptions = {\n\t\tmatchCase: !!args.matchCase,\n\t\twholeWord: !!args.wholeWord,\n\t\t...(args.regex ? { regex: true } : { literal: true })\n\t};\n\tconst result = searchDocument(editor.state.doc, query, options, replacement !== undefined ? { replacement } : {});\n\tif (result.error) throw new Error(`Invalid search pattern: ${result.error.message}`);\n\treturn { matches: result.matches, truncated: result.truncated };\n}\n\n/**\n * Tools for a mounted rich-text editor: `get_text` and `find_text` (always),\n * plus `insert_text`, `replace_text`, `replace_range`, `replace_selection` and\n * `set_selection` while the editor is editable, `edit_table` when the\n * schema has tables (`createRichTextPreset`'s `table`), and the chart tools\n * (`list_document_charts`; `insert_chart`, `update_chart_in_document` and\n * `insert_sparkline` while editable) when it has charts (`chart`).\n * Positions are ProseMirror document positions (as in `selection.from`), not\n * plain-text offsets; `find_text` and `get_text {blocks: true}` return them.\n * The provider re-announces its tool list when editability changes and\n * exposes no tools once the editor is destroyed.\n */\nexport function createRichTextToolProvider(\n\ttarget: RichTextToolTarget,\n\toptions: ToolProviderOptions\n): AgentToolProvider {\n\tconst editor = () => toEditor(target);\n\tconst charts = createDocumentChartTools(editor);\n\n\tconst getText: AgentTool = {\n\t\tname: 'get_text',\n\t\ttitle: 'Get document text',\n\t\tdescription:\n\t\t\t'Returns the document content (plain text by default, or HTML / markdown), the current selection and the document size. ' +\n\t\t\t'Editing tools take document positions, not text offsets: pass `blocks: true` to get every paragraph with the positions ' +\n\t\t\t'its text spans, or use find_text to get the positions of a phrase.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tformat: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tenum: ['text', 'html', 'markdown'],\n\t\t\t\t\tdescription: 'Content format (default: text).'\n\t\t\t\t},\n\t\t\t\tblocks: {\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\tdescription: 'Also return `blocks`: each paragraph/heading/cell as {type, from, to, text} (default false).'\n\t\t\t\t}\n\t\t\t},\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Get document text',\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ format = 'text', blocks = false }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst content =\n\t\t\t\tformat === 'html' ? ed.getHTML() : format === 'markdown' ? getEditorMarkdown(ed) : getEditorText(ed);\n\t\t\treturn {\n\t\t\t\tformat,\n\t\t\t\tcontent,\n\t\t\t\tselection: selectionInfo(ed),\n\t\t\t\tsize: ed.state.doc.content.size,\n\t\t\t\t...(blocks ? { blocks: textBlocks(ed) } : {})\n\t\t\t};\n\t\t}\n\t};\n\n\tconst insertText: AgentTool = {\n\t\tname: 'insert_text',\n\t\ttitle: 'Insert text',\n\t\tdescription:\n\t\t\t'Inserts literal text (newlines start new paragraphs) at a document position, or at the cursor when `at` is omitted.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\ttext: { type: 'string', description: 'Text to insert.' },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position (default: the selection).' }\n\t\t\t},\n\t\t\trequired: ['text'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Insert text',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ text, at }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst size = ed.state.doc.content.size;\n\t\t\tif (at !== undefined && at > size) {\n\t\t\t\tthrow new Error(`Position ${at} is outside the document (size ${size}).`);\n\t\t\t}\n\t\t\tconst { from, to } = ed.state.selection;\n\t\t\treplaceWithText(ed, at ?? from, at ?? to, text);\n\t\t\treturn { inserted: text.length, selection: selectionInfo(ed) };\n\t\t}\n\t};\n\n\tconst findText: AgentTool = {\n\t\tname: 'find_text',\n\t\ttitle: 'Find text',\n\t\tdescription:\n\t\t\t'Finds a phrase (literal by default) and returns each match with its document positions {from, to}, ' +\n\t\t\t'ready for replace_range, insert_text `at` or set_selection, plus surrounding context.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tquery: { type: 'string', minLength: 1, description: 'Text (or regex) to find.' },\n\t\t\t\t...FIND_SCHEMA_PROPERTIES,\n\t\t\t\tmaxResults: { type: 'integer', minimum: 1, maximum: 500, description: 'Matches returned (default 50).' }\n\t\t\t},\n\t\t\trequired: ['query'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Find text',\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ query, maxResults = 50, ...flags }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst { doc } = ed.state;\n\t\t\tconst { matches, truncated } = findMatches(ed, query, flags);\n\t\t\treturn {\n\t\t\t\ttotal: matches.length,\n\t\t\t\ttruncated: truncated || matches.length > maxResults,\n\t\t\t\tmatches: matches.slice(0, maxResults).map((m) => ({\n\t\t\t\t\tfrom: m.from,\n\t\t\t\t\tto: m.to,\n\t\t\t\t\ttext: m.text,\n\t\t\t\t\tbefore: doc.textBetween(Math.max(0, m.from - CONTEXT_CHARS), m.from, '\\n', ' '),\n\t\t\t\t\tafter: doc.textBetween(m.to, Math.min(doc.content.size, m.to + CONTEXT_CHARS), '\\n', ' ')\n\t\t\t\t}))\n\t\t\t};\n\t\t}\n\t};\n\n\tconst replaceText: AgentTool = {\n\t\tname: 'replace_text',\n\t\ttitle: 'Find and replace',\n\t\tdescription:\n\t\t\t'Replaces occurrences of a phrase with literal text in one undoable step, keeping the found text\\'s formatting. ' +\n\t\t\t'Replaces every occurrence by default, or only the n-th with `occurrence`. Fails when nothing matches.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tfind: { type: 'string', minLength: 1, description: 'Text (or regex) to find.' },\n\t\t\t\treplace: { type: 'string', description: 'Replacement text (literal; an empty string deletes the matches).' },\n\t\t\t\t...FIND_SCHEMA_PROPERTIES,\n\t\t\t\toccurrence: {\n\t\t\t\t\ttype: 'integer',\n\t\t\t\t\tminimum: 1,\n\t\t\t\t\tdescription: 'Only replace the n-th match (1-based, in document order). Default: all matches.'\n\t\t\t\t}\n\t\t\t},\n\t\t\trequired: ['find', 'replace'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Find and replace',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ find, replace, occurrence, ...flags }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst { matches } = findMatches(ed, find, flags);\n\t\t\tif (matches.length === 0) throw new Error(`No match for ${JSON.stringify(find)}.`);\n\t\t\tif (occurrence !== undefined && occurrence > matches.length) {\n\t\t\t\tthrow new Error(`Occurrence ${occurrence} requested, but there are only ${matches.length} matches.`);\n\t\t\t}\n\t\t\t// The replacement is literal text: `\\r` / `\\n` split paragraphs / insert line breaks.\n\t\t\tconst chosen = (occurrence !== undefined ? [matches[occurrence - 1]] : matches).map((m) => ({\n\t\t\t\t...m,\n\t\t\t\treplacement: String(replace).replace(/\\r\\n?|\\n/g, '\\r')\n\t\t\t}));\n\t\t\tconst tr = ed.state.tr;\n\t\t\tconst ends = applyReplacements(tr, chosen);\n\t\t\ted.view.dispatch(tr.scrollIntoView());\n\t\t\treturn {\n\t\t\t\treplaced: chosen.length,\n\t\t\t\ttotal: matches.length,\n\t\t\t\tranges: chosen.map((m, i) => ({ from: tr.mapping.map(m.from, -1), to: ends[i] })),\n\t\t\t\tselection: selectionInfo(ed)\n\t\t\t};\n\t\t}\n\t};\n\n\tconst replaceRange: AgentTool = {\n\t\tname: 'replace_range',\n\t\ttitle: 'Replace a range',\n\t\tdescription:\n\t\t\t'Replaces the content between two document positions (from get_text `blocks` or find_text) with literal text. ' +\n\t\t\t'from === to inserts; an empty text deletes.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tfrom: { type: 'integer', minimum: 0, description: 'Start document position.' },\n\t\t\t\tto: { type: 'integer', minimum: 0, description: 'End document position.' },\n\t\t\t\ttext: { type: 'string', description: 'Replacement text (newlines start new paragraphs).' }\n\t\t\t},\n\t\t\trequired: ['from', 'to', 'text'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Replace a range',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ from, to, text }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckRange(ed, from, to);\n\t\t\treplaceWithText(ed, from, to, text);\n\t\t\treturn { replaced: { from, to }, selection: selectionInfo(ed), size: ed.state.doc.content.size };\n\t\t}\n\t};\n\n\tconst setSelection: AgentTool = {\n\t\tname: 'set_selection',\n\t\ttitle: 'Set the selection',\n\t\tdescription: 'Selects the content between two document positions (from === to places the cursor).',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tfrom: { type: 'integer', minimum: 0, description: 'Start document position.' },\n\t\t\t\tto: { type: 'integer', minimum: 0, description: 'End document position (default: from).' }\n\t\t\t},\n\t\t\trequired: ['from'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Set the selection',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ from, to = from }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckRange(ed, from, to);\n\t\t\tconst { doc } = ed.state;\n\t\t\ted.view.dispatch(ed.state.tr.setSelection(TextSelection.between(doc.resolve(from), doc.resolve(to))));\n\t\t\treturn { selection: selectionInfo(ed) };\n\t\t}\n\t};\n\n\tconst replaceSelection: AgentTool = {\n\t\tname: 'replace_selection',\n\t\ttitle: 'Replace selection',\n\t\tdescription: 'Replaces the selected content with literal text (an empty string deletes the selection).',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: { text: { type: 'string', description: 'Replacement text.' } },\n\t\t\trequired: ['text'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Replace selection',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ text }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst { from, to } = ed.state.selection;\n\t\t\treplaceWithText(ed, from, to, text);\n\t\t\treturn { replaced: { from, to }, selection: selectionInfo(ed) };\n\t\t}\n\t};\n\n\tconst editTable: AgentTool = {\n\t\tname: 'edit_table',\n\t\ttitle: 'Edit tables',\n\t\tdescription:\n\t\t\t'Inserts a table or edits the table at the cursor (or at `at`): add/delete rows and columns, delete the table, ' +\n\t\t\t'merge/split cells, toggle header row/column/cell, move between cells, set cell alignment or background. ' +\n\t\t\t'Returns the table size and the cursor cell afterwards.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\toperation: { type: 'string', enum: TABLE_ACTIONS.map((a) => a.action), description: 'Table operation.' },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position to place the cursor first (e.g. inside a cell).' },\n\t\t\t\trows: { type: 'integer', minimum: 1, maximum: 100, description: 'insertTable: rows (default 3).' },\n\t\t\t\tcols: { type: 'integer', minimum: 1, maximum: 50, description: 'insertTable: columns (default 3).' },\n\t\t\t\twithHeaderRow: { type: 'boolean', description: 'insertTable: first row is a header row (default true).' },\n\t\t\t\talign: {\n\t\t\t\t\ttype: ['string', 'null'],\n\t\t\t\t\tenum: ['left', 'center', 'right', 'justify', null],\n\t\t\t\t\tdescription: 'setCellAlignment: alignment, or null to clear.'\n\t\t\t\t},\n\t\t\t\tcolor: { type: ['string', 'null'], description: 'setCellBackground: CSS color, or null to clear.' }\n\t\t\t},\n\t\t\trequired: ['operation'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Edit tables',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ operation, at, ...params }) => {\n\t\t\tconst ed = editor();\n\t\t\tif (at !== undefined) {\n\t\t\t\tconst size = ed.state.doc.content.size;\n\t\t\t\tif (at > size) throw new Error(`Position ${at} is outside the document (size ${size}).`);\n\t\t\t\ted.view.dispatch(ed.state.tr.setSelection(TextSelection.near(ed.state.doc.resolve(at))));\n\t\t\t}\n\t\t\tconst action = operation as TableAction;\n\t\t\tconst state = getTableActionState(ed, action, params);\n\t\t\tif (state !== true) throw new Error(state);\n\t\t\trunTableAction(ed, action, params);\n\t\t\tconst table = getTableState(ed);\n\t\t\treturn {\n\t\t\t\toperation,\n\t\t\t\ttable: table.inTable\n\t\t\t\t\t? { rows: table.rows, columns: table.columns, row: table.row, column: table.column }\n\t\t\t\t\t: null,\n\t\t\t\tselection: selectionInfo(ed)\n\t\t\t};\n\t\t}\n\t};\n\n\treturn {\n\t\tid: options.id,\n\t\tnamespace: options.namespace,\n\t\ttools: () => {\n\t\t\tconst ed = editor();\n\t\t\tif (!ed || ed.isDestroyed) return [];\n\t\t\tif (!ed.isEditable) return [getText, findText, ...charts.read()];\n\t\t\tconst tools = [getText, findText, insertText, replaceText, replaceRange, replaceSelection, setSelection];\n\t\t\treturn [...tools, ...(isTableEnabled(ed) ? [editTable] : []), ...charts.read(), ...charts.write()];\n\t\t},\n\t\tsubscribe: (notify) => {\n\t\t\tconst ed = editor();\n\t\t\t// `setEditable` emits `update`; the registry ignores signals that don't change the list.\n\t\t\ted.on('update', notify);\n\t\t\ted.on('destroy', notify);\n\t\t\treturn () => {\n\t\t\t\ted.off('update', notify);\n\t\t\t\ted.off('destroy', notify);\n\t\t\t};\n\t\t}\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Spreadsheet provider\n// ---------------------------------------------------------------------------\n\nconst CELL_REF_REGEX = /^\\$?([A-Za-z]{1,3})\\$?(\\d{1,7})$/;\n\nfunction parseCell(ref: string): { col: number; row: number } {\n\tconst match = CELL_REF_REGEX.exec(ref.trim());\n\tif (!match) throw new Error(`Invalid cell reference \"${ref}\". Use A1 notation, e.g. \"B3\".`);\n\treturn { col: colNameToIndex(match[1].toUpperCase()), row: parseInt(match[2], 10) - 1 };\n}\n\nconst COLUMN_REGEX = /^[A-Za-z]{1,3}$/;\n\nfunction parseColumn(name: string): number {\n\tif (!COLUMN_REGEX.test(name.trim())) throw new Error(`Invalid column \"${name}\". Use a letter name, e.g. \"C\".`);\n\treturn colNameToIndex(name.trim().toUpperCase());\n}\n\nconst CELL_INPUT = { type: ['string', 'number', 'boolean', 'null'] } as const;\n\n/**\n * Tools for a spreadsheet controller: `get_range` (A1 notation, values and raw\n * input), `set_cell` and `set_range` (raw input; values starting with `=` are\n * formulas; `set_range` writes a whole block as one undo step), and\n * `insert_rows` / `delete_rows` / `insert_columns` / `delete_columns`\n * (formula references shift like a user edit).\n */\nexport function createSpreadsheetToolProvider(\n\tcontroller: SpreadsheetController,\n\toptions: ToolProviderOptions\n): AgentToolProvider {\n\tconst lookup = (row: number, col: number) => {\n\t\tconst rowDef = controller.document.rows[row];\n\t\tconst colDef = controller.document.columns[col];\n\t\treturn rowDef && colDef ? { rowDef, colDef } : null;\n\t};\n\n\tconst getRange: AgentTool = {\n\t\tname: 'get_range',\n\t\ttitle: 'Read cells',\n\t\tdescription:\n\t\t\t'Reads a cell range in A1 notation (e.g. \"A1:C5\" or \"B2\") and returns computed values, raw input and errors.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\trange: { type: 'string', description: 'A1-notation cell or range.' }\n\t\t\t},\n\t\t\trequired: ['range'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Read cells',\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ range }) => {\n\t\t\tconst [startRef, endRef = startRef] = String(range).split(':');\n\t\t\tconst start = parseCell(startRef);\n\t\t\tconst end = parseCell(endRef);\n\t\t\tconst rowCount = controller.document.rows.length;\n\t\t\tconst colCount = controller.document.columns.length;\n\t\t\tconst r0 = Math.min(start.row, end.row);\n\t\t\tconst r1 = Math.min(Math.max(start.row, end.row), rowCount - 1);\n\t\t\tconst c0 = Math.min(start.col, end.col);\n\t\t\tconst c1 = Math.min(Math.max(start.col, end.col), colCount - 1);\n\t\t\tconst values: unknown[][] = [];\n\t\t\tconst raw: string[][] = [];\n\t\t\tconst errors: Array<{ cell: string; error: string }> = [];\n\t\t\tfor (let r = r0; r <= r1; r++) {\n\t\t\t\tconst valueRow: unknown[] = [];\n\t\t\t\tconst rawRow: string[] = [];\n\t\t\t\tfor (let c = c0; c <= c1; c++) {\n\t\t\t\t\tconst found = lookup(r, c)!;\n\t\t\t\t\tconst cell = controller.getCell(found.rowDef.id, found.colDef.id);\n\t\t\t\t\tvalueRow.push(cell.error ?? cell.value);\n\t\t\t\t\trawRow.push(cell.raw);\n\t\t\t\t\tconst error = cell.error ?? (isFormulaError(cell.value) ? cell.value : undefined);\n\t\t\t\t\tif (error) errors.push({ cell: `${indexToColName(c)}${r + 1}`, error });\n\t\t\t\t}\n\t\t\t\tvalues.push(valueRow);\n\t\t\t\traw.push(rawRow);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trange: values.length && values[0].length ? `${indexToColName(c0)}${r0 + 1}:${indexToColName(c1)}${r1 + 1}` : null,\n\t\t\t\tvalues,\n\t\t\t\traw,\n\t\t\t\terrors,\n\t\t\t\tsheet: { rows: rowCount, columns: colCount }\n\t\t\t};\n\t\t}\n\t};\n\n\tconst setCell: AgentTool = {\n\t\tname: 'set_cell',\n\t\ttitle: 'Set a cell',\n\t\tdescription: 'Sets the raw input of one cell (A1 notation). Values starting with \"=\" are formulas.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tcell: { type: 'string', description: 'A1-notation cell, e.g. \"B3\".' },\n\t\t\t\tvalue: { type: ['string', 'number', 'boolean'], description: 'Raw cell input.' }\n\t\t\t},\n\t\t\trequired: ['cell', 'value'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Set a cell',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ cell, value }) => {\n\t\t\tconst { row, col } = parseCell(cell);\n\t\t\tconst found = lookup(row, col);\n\t\t\tif (!found) throw new Error(`Cell ${cell} is outside the sheet.`);\n\t\t\tconst { rowDef, colDef } = found;\n\t\t\tif (colDef.readOnly || controller.getCell(rowDef.id, colDef.id).readOnly || colDef.type === 'formula') {\n\t\t\t\tthrow new Error(`Cell ${cell} is read-only.`);\n\t\t\t}\n\t\t\tcontroller.setCellValue(rowDef.id, colDef.id, String(value));\n\t\t\tconst updated = controller.getCell(rowDef.id, colDef.id);\n\t\t\treturn { cell: cell.toUpperCase(), raw: updated.raw, value: updated.error ?? updated.value };\n\t\t}\n\t};\n\n\tconst isReadOnly = (row: number, col: number) => {\n\t\tconst found = lookup(row, col);\n\t\tif (!found) return false;\n\t\tconst { rowDef, colDef } = found;\n\t\treturn !!(colDef.readOnly || colDef.type === 'formula' || controller.getCell(rowDef.id, colDef.id).readOnly);\n\t};\n\n\tconst setRange: AgentTool = {\n\t\tname: 'set_range',\n\t\ttitle: 'Set a block of cells',\n\t\tdescription:\n\t\t\t'Writes a 2D block of raw inputs starting at a cell (A1 notation), row by row, as one undo step. ' +\n\t\t\t'Values starting with \"=\" are formulas; null or \"\" clears a cell. The sheet grows to fit. Fails without writing ' +\n\t\t\t'anything if any target cell is read-only.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tstart: { type: 'string', description: 'Top-left cell, e.g. \"A1\".' },\n\t\t\t\tvalues: {\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tminItems: 1,\n\t\t\t\t\tmaxItems: 10000,\n\t\t\t\t\titems: { type: 'array', items: CELL_INPUT, maxItems: 1000 },\n\t\t\t\t\tdescription: 'Rows of raw cell inputs, e.g. [[\"Name\", \"Total\"], [\"A\", \"=B3*2\"]].'\n\t\t\t\t}\n\t\t\t},\n\t\t\trequired: ['start', 'values'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: {\n\t\t\ttitle: 'Set a block of cells',\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: false\n\t\t},\n\t\thandler: ({ start, values }) => {\n\t\t\tconst { row, col } = parseCell(start);\n\t\t\tconst rows = values as Array<Array<string | number | boolean | null>>;\n\t\t\tconst readOnly: string[] = [];\n\t\t\trows.forEach((line, r) =>\n\t\t\t\tline.forEach((_, c) => {\n\t\t\t\t\tif (isReadOnly(row + r, col + c)) readOnly.push(`${indexToColName(col + c)}${row + r + 1}`);\n\t\t\t\t})\n\t\t\t);\n\t\t\tif (readOnly.length) throw new Error(`Read-only cells: ${readOnly.slice(0, 20).join(', ')}. Nothing was written.`);\n\t\t\tcontroller.importRows(\n\t\t\t\trows.map((line) => line.map((v) => (v === null ? '' : String(v)))),\n\t\t\t\t{ startRow: row, startCol: col }\n\t\t\t);\n\t\t\tconst width = Math.max(0, ...rows.map((line) => line.length));\n\t\t\tconst end = `${indexToColName(col + Math.max(width, 1) - 1)}${row + rows.length}`;\n\t\t\tconst errors: Array<{ cell: string; error: string }> = [];\n\t\t\trows.forEach((line, r) =>\n\t\t\t\tline.forEach((_, c) => {\n\t\t\t\t\tconst found = lookup(row + r, col + c);\n\t\t\t\t\tif (!found) return;\n\t\t\t\t\tconst cell = controller.getCell(found.rowDef.id, found.colDef.id);\n\t\t\t\t\tconst error = cell.error ?? (isFormulaError(cell.value) ? cell.value : undefined);\n\t\t\t\t\tif (error) errors.push({ cell: `${indexToColName(col + c)}${row + r + 1}`, error: String(error) });\n\t\t\t\t})\n\t\t\t);\n\t\t\treturn {\n\t\t\t\trange: `${indexToColName(col)}${row + 1}:${end}`,\n\t\t\t\twritten: rows.reduce((n, line) => n + line.length, 0),\n\t\t\t\terrors,\n\t\t\t\tsheet: { rows: controller.document.rows.length, columns: controller.document.columns.length }\n\t\t\t};\n\t\t}\n\t};\n\n\tconst COUNT = { type: 'integer', minimum: 1, maximum: 1000, description: 'How many (default 1).' } as const;\n\tconst sheetSize = () => ({ rows: controller.document.rows.length, columns: controller.document.columns.length });\n\tconst structural = (\n\t\tname: string,\n\t\ttitle: string,\n\t\tdescription: string,\n\t\tproperties: Record<string, unknown>,\n\t\trequired: string[],\n\t\tdestructive: boolean,\n\t\thandler: AgentTool['handler']\n\t): AgentTool => ({\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: { type: 'object', properties: properties as never, required, additionalProperties: false },\n\t\tannotations: { title, readOnlyHint: false, destructiveHint: destructive, idempotentHint: false, openWorldHint: false },\n\t\thandler\n\t});\n\n\tconst insertRows = structural(\n\t\t'insert_rows',\n\t\t'Insert rows',\n\t\t'Inserts empty rows before a row number (1-based; one past the last row appends). References below shift down.',\n\t\t{ before: { type: 'integer', minimum: 1, description: 'Row number to insert before.' }, count: COUNT },\n\t\t['before'],\n\t\tfalse,\n\t\t({ before, count = 1 }) => {\n\t\t\tconst index = before - 1;\n\t\t\tif (index > controller.document.rows.length) throw new Error(`Row ${before} is past the end of the sheet (${controller.document.rows.length} rows).`);\n\t\t\tfor (let i = 0; i < count; i++) controller.insertRow(index);\n\t\t\treturn { inserted: count, rows: `${before}:${before + count - 1}`, sheet: sheetSize() };\n\t\t}\n\t);\n\tconst deleteRows = structural(\n\t\t'delete_rows',\n\t\t'Delete rows',\n\t\t'Deletes rows starting at a row number (1-based) with their contents. References below shift up; references to deleted cells become #REF!.',\n\t\t{ start: { type: 'integer', minimum: 1, description: 'First row number to delete.' }, count: COUNT },\n\t\t['start'],\n\t\ttrue,\n\t\t({ start, count = 1 }) => {\n\t\t\tconst rows = controller.document.rows.slice(start - 1, start - 1 + count);\n\t\t\tif (rows.length < count) throw new Error(`Rows ${start}-${start + count - 1} are not all in the sheet (${controller.document.rows.length} rows).`);\n\t\t\tfor (const row of rows) controller.deleteRow(row.id);\n\t\t\treturn { deleted: count, sheet: sheetSize() };\n\t\t}\n\t);\n\tconst insertColumns = structural(\n\t\t'insert_columns',\n\t\t'Insert columns',\n\t\t'Inserts empty columns before a column letter (one past the last column appends). References to the right shift.',\n\t\t{ before: { type: 'string', description: 'Column letter to insert before, e.g. \"C\".' }, count: COUNT },\n\t\t['before'],\n\t\tfalse,\n\t\t({ before, count = 1 }) => {\n\t\t\tconst index = parseColumn(before);\n\t\t\tif (index > controller.document.columns.length) throw new Error(`Column ${before} is past the end of the sheet (${controller.document.columns.length} columns).`);\n\t\t\tfor (let i = 0; i < count; i++) controller.insertColumn(index);\n\t\t\treturn { inserted: count, columns: `${indexToColName(index)}:${indexToColName(index + count - 1)}`, sheet: sheetSize() };\n\t\t}\n\t);\n\tconst deleteColumns = structural(\n\t\t'delete_columns',\n\t\t'Delete columns',\n\t\t'Deletes columns starting at a column letter with their contents. References to the right shift left; references to deleted cells become #REF!.',\n\t\t{ start: { type: 'string', description: 'First column letter to delete, e.g. \"C\".' }, count: COUNT },\n\t\t['start'],\n\t\ttrue,\n\t\t({ start, count = 1 }) => {\n\t\t\tconst index = parseColumn(start);\n\t\t\tconst columns = controller.document.columns.slice(index, index + count);\n\t\t\tif (columns.length < count) throw new Error(`Columns from ${start} (${count}) are not all in the sheet (${controller.document.columns.length} columns).`);\n\t\t\tfor (const column of columns) controller.deleteColumn(column.id);\n\t\t\treturn { deleted: count, sheet: sheetSize() };\n\t\t}\n\t);\n\n\treturn {\n\t\tid: options.id,\n\t\tnamespace: options.namespace,\n\t\ttools: [getRange, setCell, setRange, insertRows, deleteRows, insertColumns, deleteColumns]\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Static editor tools (tools.ts) as a provider\n// ---------------------------------------------------------------------------\n\nexport interface EditorMcpToolProviderOptions<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n> extends ToolProviderOptions {\n\t/** Current editor / canvas state. */\n\tgetSnapshot: () => EditorSnapshot<TNode, TEdge>;\n\t/** Applies planned steps (e.g. via your canvas runes / editor controller). */\n\tapplySteps: (steps: AgentStep<TNode, TEdge>[]) => void | Promise<void>;\n\t/** Optional `view_editor` implementation; the tool is only exposed when provided. */\n\tcaptureView?: (args: { scope?: 'viewport' | 'canvas'; format?: 'jpeg' | 'png'; maxEdge?: number }) =>\n\t\t| Promise<{ data: string; mimeType: string }>\n\t\t| { data: string; mimeType: string };\n\t/** Options forwarded to the planner. */\n\tplannerOptions?: Parameters<typeof planToolCall>[3];\n\t/**\n\t * `split` (default): one strictly typed tool per operation (`canvas_add_node`,\n\t * `canvas_connect`, ..., `prompt_insert_text`, ...). `combined`: the\n\t * `edit_canvas` / `edit_prompt` tools with an `operation` argument.\n\t */\n\ttoolStyle?: 'split' | 'combined';\n\t/** Which edit tools to expose (default both). */\n\tsurfaces?: { canvas?: boolean; prompt?: boolean };\n}\n\n/** Describes which arguments a combined `edit_*` call is missing. */\nfunction missingArgumentsMessage(name: 'edit_canvas' | 'edit_prompt', args: Record<string, any>): string {\n\tconst required = EDIT_OPERATION_REQUIRED_ARGUMENTS[name][args.operation as string];\n\tif (!required) return `Unknown operation \"${args.operation}\".`;\n\tconst missing = required.filter((key) =>\n\t\tkey === 'id' ? args.id === undefined && args.node?.id === undefined : args[key] === undefined\n\t);\n\treturn missing.length\n\t\t? `Operation \"${args.operation}\" requires ${required.join(', ')}; missing: ${missing.join(', ')}.`\n\t\t: `Operation \"${args.operation}\" has invalid arguments (expected ${required.join(', ')} with the types in the schema).`;\n}\n\n/** What a set of applied steps created, so the agent can refer to it next. */\nfunction describeSteps<TNode extends CanvasNode, TEdge extends CanvasEdge>(steps: AgentStep<TNode, TEdge>[]) {\n\tconst nodes: Array<{ id: string; position: { x: number; y: number } }> = [];\n\tconst edges: Array<{ id: string; source: string; target: string }> = [];\n\tfor (const step of steps) {\n\t\tif (step.type === 'step:canvas_add_node') nodes.push({ id: step.node.id, position: step.node.position });\n\t\tif (step.type === 'step:canvas_add_edge') edges.push({ id: step.edge.id, source: step.edge.source, target: step.edge.target });\n\t}\n\treturn {\n\t\tapplied: steps.length,\n\t\tsteps: steps.map((s) => s.type),\n\t\t...(nodes.length || edges.length ? { created: { nodes, edges } } : {})\n\t};\n}\n\n/**\n * Exposes the editor MCP tools (`get_editor_state`, the canvas and prompt\n * edit tools, and `view_editor` when `captureView` is given) through a\n * `ToolRegistry`. Edits are checked against the current snapshot\n * (`validateAgentCommand`: unknown node ids, duplicate ids, unordered ranges\n * are tool errors), planned with the planner and handed to `applySteps`.\n * Results list the ids of created nodes and edges.\n */\nexport function createEditorMcpToolProvider<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(options: EditorMcpToolProviderOptions<TNode, TEdge>): AgentToolProvider {\n\tconst edit = (name: string) => async (args: Record<string, any>) => {\n\t\tconst command = toolCallToAgentCommand<TNode, TEdge>(name, args);\n\t\tif (!command) {\n\t\t\tthrow new Error(\n\t\t\t\tname === 'edit_canvas' || name === 'edit_prompt'\n\t\t\t\t\t? missingArgumentsMessage(name, args)\n\t\t\t\t\t: `Invalid arguments for \"${name}\".`\n\t\t\t);\n\t\t}\n\t\tconst snapshot = options.getSnapshot();\n\t\tconst problem = validateAgentCommand(command, snapshot);\n\t\tif (problem) throw new Error(problem);\n\t\tconst steps = planAgentCommand(command, snapshot, options.plannerOptions);\n\t\tawait options.applySteps(steps);\n\t\treturn describeSteps(steps);\n\t};\n\n\tconst canvas = options.surfaces?.canvas ?? true;\n\tconst prompt = options.surfaces?.prompt ?? true;\n\tconst editTools =\n\t\toptions.toolStyle === 'combined'\n\t\t\t? [...(canvas ? [MCP_TOOL_EDIT_CANVAS] : []), ...(prompt ? [MCP_TOOL_EDIT_PROMPT] : [])]\n\t\t\t: [...(canvas ? EDITOR_CANVAS_TOOLS : []), ...(prompt ? EDITOR_PROMPT_TOOLS : [])];\n\n\tconst tools: AgentTool[] = [\n\t\t{\n\t\t\t...MCP_TOOL_GET_EDITOR_STATE,\n\t\t\thandler: ({ includeDocument = true, includeCanvas = true }) => {\n\t\t\t\tconst snapshot = options.getSnapshot();\n\t\t\t\treturn {\n\t\t\t\t\t...(includeDocument && snapshot.document ? { document: snapshot.document } : {}),\n\t\t\t\t\t...(includeCanvas && snapshot.canvas ? { canvas: snapshot.canvas } : {})\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t...editTools.map((definition) => ({ ...definition, handler: edit(definition.name) }))\n\t] as AgentTool[];\n\n\tif (options.captureView) {\n\t\tconst capture = options.captureView;\n\t\ttools.push({\n\t\t\t...MCP_TOOL_VIEW_EDITOR,\n\t\t\thandler: async (args) => {\n\t\t\t\tconst image = await capture(args);\n\t\t\t\treturn { content: [{ type: 'image', data: image.data, mimeType: image.mimeType }] };\n\t\t\t}\n\t\t} as AgentTool);\n\t}\n\n\treturn { id: options.id, namespace: options.namespace, tools };\n}\n","import type { Editor } from '@tiptap/core';\nimport { closeHistory } from '@tiptap/pm/history';\nimport type { Node as ProsemirrorNode } from '@tiptap/pm/model';\nimport { getDocumentCharts, type DocumentChart } from '../extensions/chart/chart-node.js';\nimport { MAX_SPARKLINE_VALUES, SPARKLINE_KINDS, normalizeSparklineValues, sparklineLabel } from '../extensions/chart/sparkline-node.js';\nimport { CHART_UPDATE_PROPERTIES, SERIES_PROPS, VALUE } from '../chart/schemas.js';\nimport { normalizeChartSpec, parseChartValue } from '../chart/spec.js';\nimport { describeChart } from '../chart/summary.js';\nimport type { ChartSpec } from '../chart/types.js';\nimport type { AgentTool } from '../tools/registry.js';\nimport type { JsonSchema } from '../tools/schema.js';\n\nconst READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false } as const;\nconst WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\n\nconst SIZE_WIDTH: JsonSchema = {\n\ttype: ['number', 'null'],\n\tminimum: 50,\n\tmaximum: 4096,\n\tdescription: 'Width in pixels, or null to fill the line (default null).'\n};\nconst SIZE_HEIGHT: JsonSchema = { type: 'number', minimum: 50, maximum: 4096, description: 'Height in pixels (default 320).' };\n\n/** The chart data and presentation fields an agent can pass (a `ChartSpec` without `version`). */\nconst SPEC_PROPERTIES: Record<string, JsonSchema> = {\n\t...CHART_UPDATE_PROPERTIES,\n\tcategories: { type: 'array', items: { type: 'string' }, description: 'Category labels in order (x axis labels, or pie slices).' },\n\tseries: {\n\t\ttype: 'array',\n\t\tdescription: 'The series, each with one value per category (padded with gaps).',\n\t\titems: {\n\t\t\ttype: 'object',\n\t\t\tproperties: { id: { type: 'string', description: 'Stable id (default: from the name).' }, ...SERIES_PROPS },\n\t\t\trequired: ['name', 'values'],\n\t\t\tadditionalProperties: false\n\t\t}\n\t}\n};\n\n/** Drops `null` from series fields (null means \"use the default\" in the tool schema). */\nfunction cleanSeries(series: unknown): unknown {\n\tif (!Array.isArray(series)) return series;\n\treturn series.map((s) => (s && typeof s === 'object' ? Object.fromEntries(Object.entries(s).filter(([, v]) => v !== null)) : s));\n}\n\n/** Normalizes agent input as a chart, throwing every problem as one sentence list. */\nfunction checkedSpec(input: Record<string, unknown>): ChartSpec {\n\tconst { spec, issues } = normalizeChartSpec({ ...input, ...(input.series !== undefined ? { series: cleanSeries(input.series) } : {}) });\n\tif (issues.length) throw new Error(`The chart was not changed: ${issues.map((i) => i.message).join(' ')}`);\n\treturn spec;\n}\n\nfunction describe(chart: DocumentChart, includeSpec: boolean) {\n\tconst { spec, node } = chart;\n\treturn {\n\t\tid: chart.id,\n\t\tpos: chart.pos,\n\t\ttype: spec.type,\n\t\ttitle: spec.title,\n\t\tcategories: spec.categories,\n\t\tseries: spec.series.map((s) => ({ id: s.id, name: s.name })),\n\t\twidth: node.attrs.width ?? null,\n\t\theight: node.attrs.height,\n\t\tdescription: describeChart(spec),\n\t\t...(includeSpec ? { spec } : {})\n\t};\n}\n\nfunction sparklines(doc: ProsemirrorNode) {\n\tconst found: { pos: number; kind: string; values: (number | null)[]; label: string }[] = [];\n\tdoc.descendants((node, pos) => {\n\t\tif (node.type.name === 'sparkline') found.push({ pos, kind: node.attrs.kind, values: node.attrs.values, label: sparklineLabel(node) });\n\t});\n\treturn found;\n}\n\nfunction checkPosition(editor: Editor, at: number | undefined) {\n\tconst size = editor.state.doc.content.size;\n\tif (at !== undefined && at > size) throw new Error(`Position ${at} is outside the document (size ${size}).`);\n}\n\n/**\n * Chart tools for a rich-text editor whose schema has the `chart` node:\n * `list_document_charts` (read), `insert_chart` and `update_chart_in_document` (writes), plus\n * `insert_sparkline` when the schema has `sparkline`. `createRichTextToolProvider` adds them.\n */\nexport function createDocumentChartTools(editor: () => Editor): { read: () => AgentTool[]; write: () => AgentTool[] } {\n\tconst chartType = () => editor().schema.nodes.chart;\n\tconst findChart = (args: { chartId?: string; pos?: number }): DocumentChart => {\n\t\tconst charts = getDocumentCharts(editor().state.doc);\n\t\tconst list = charts.map((c) => `\"${c.id}\" at ${c.pos}`).join(', ') || 'none; add one with insert_chart';\n\t\tif (args.chartId !== undefined) {\n\t\t\tconst chart = charts.find((c) => c.id === args.chartId);\n\t\t\tif (!chart) throw new Error(`There is no chart \"${args.chartId}\" in the document. Charts: ${list}.`);\n\t\t\tif (args.pos !== undefined && args.pos !== chart.pos) throw new Error(`Chart \"${args.chartId}\" is at ${chart.pos}, not ${args.pos}; pass one of chartId or pos.`);\n\t\t\treturn chart;\n\t\t}\n\t\tif (args.pos !== undefined) {\n\t\t\tconst chart = charts.find((c) => c.pos === args.pos);\n\t\t\tif (!chart) throw new Error(`There is no chart at position ${args.pos}. Charts: ${list}.`);\n\t\t\treturn chart;\n\t\t}\n\t\tthrow new Error(`Pass chartId or pos (from list_document_charts). Charts: ${list}.`);\n\t};\n\n\tconst listCharts: AgentTool = {\n\t\tname: 'list_document_charts',\n\t\ttitle: 'List charts in the document',\n\t\tdescription:\n\t\t\t'Lists the charts in the document in order: id, document position, type, title, categories, series (ids and names), size in pixels and a plain-language description of the data. Also lists inline sparklines (position, kind, values). Pass the id or position to update_chart_in_document.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: { includeSpec: { type: 'boolean', description: 'Also return each chart\\'s full spec (default false).' } },\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'List charts in the document', ...READ },\n\t\thandler: ({ includeSpec = false }) => {\n\t\t\tconst doc = editor().state.doc;\n\t\t\treturn { charts: getDocumentCharts(doc).map((c) => describe(c, includeSpec)), sparklines: editor().schema.nodes.sparkline ? sparklines(doc) : [] };\n\t\t}\n\t};\n\n\tconst insertChart: AgentTool = {\n\t\tname: 'insert_chart',\n\t\ttitle: 'Insert a chart',\n\t\tdescription:\n\t\t\t'Inserts a chart block at a document position (or the cursor), as one undo step. Give the categories and series (one value per category) and any presentation fields (type, titles, axes, legend, stacking, palette, …). Invalid fields change nothing and come back as sentences. Returns the new chart\\'s id, position and stored spec.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tspec: { type: 'object', description: 'The chart: categories and series, plus optional presentation fields.', properties: SPEC_PROPERTIES, required: ['categories', 'series'], additionalProperties: false },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position (default: the selection). A position inside a paragraph splits it.' },\n\t\t\t\twidth: SIZE_WIDTH,\n\t\t\t\theight: SIZE_HEIGHT\n\t\t\t},\n\t\t\trequired: ['spec'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'Insert a chart', ...WRITE },\n\t\thandler: ({ spec: input, at, width = null, height }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckPosition(ed, at);\n\t\t\tconst spec = checkedSpec(input);\n\t\t\tconst id = (ed.extensionManager.extensions.find((e) => e.name === 'chart')?.options.generateId as (() => string) | undefined)?.() ?? `chart-${Date.now().toString(36)}`;\n\t\t\tconst node = { type: 'chart', attrs: { id, spec, width, ...(height !== undefined ? { height } : {}) } };\n\t\t\t// Each tool call is its own undo step, however quickly calls follow each other.\n\t\t\tconst chain = ed.chain().command(({ tr }) => (closeHistory(tr), true));\n\t\t\tconst ok = (at !== undefined ? chain.insertContentAt(at, node) : chain.insertContent(node)).run();\n\t\t\tconst chart = getDocumentCharts(ed.state.doc).find((c) => c.id === id);\n\t\t\tif (!ok || !chart) throw new Error(`A chart cannot go at ${at ?? ed.state.selection.from}; pass a position between blocks or inside a paragraph.`);\n\t\t\treturn { id: chart.id, pos: chart.pos, spec: chart.spec, width: chart.node.attrs.width, height: chart.node.attrs.height };\n\t\t}\n\t};\n\n\tconst updateChart: AgentTool = {\n\t\tname: 'update_chart_in_document',\n\t\ttitle: 'Change a chart in the document',\n\t\tdescription:\n\t\t\t'Changes one chart (by id or position from list_document_charts) as one undo step: data (categories, series — given series replace all) and / or presentation fields, which merge into the current spec (axes and legend field by field), plus its size. All-or-nothing: invalid values change nothing and come back as sentences. Returns the chart\\'s id, position and new spec.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tchartId: { type: 'string', description: 'Chart id from list_document_charts.' },\n\t\t\t\tpos: { type: 'integer', minimum: 0, description: 'Document position of the chart (from list_document_charts), instead of chartId.' },\n\t\t\t\tchanges: { type: 'object', description: 'Fields to change; omitted fields keep their value.', properties: SPEC_PROPERTIES, additionalProperties: false },\n\t\t\t\twidth: SIZE_WIDTH,\n\t\t\t\theight: { ...SIZE_HEIGHT, description: 'Height in pixels (default: unchanged).' }\n\t\t\t},\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'Change a chart in the document', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ chartId, pos, changes, width, height }) => {\n\t\t\tconst ed = editor();\n\t\t\tconst chart = findChart({ chartId, pos });\n\t\t\tif (!changes && width === undefined && height === undefined) throw new Error('Nothing to change: pass changes, width or height, e.g. {\"changes\": {\"type\": \"line\"}}.');\n\t\t\tconst s = chart.spec;\n\t\t\tconst patch = (changes ?? {}) as Record<string, any>;\n\t\t\tconst spec = checkedSpec({\n\t\t\t\t...s,\n\t\t\t\t...patch,\n\t\t\t\txAxis: patch.xAxis ? { ...s.xAxis, ...patch.xAxis } : s.xAxis,\n\t\t\t\tyAxis: patch.yAxis ? { ...s.yAxis, ...patch.yAxis } : s.yAxis,\n\t\t\t\tyAxis2: patch.yAxis2 ? { ...s.yAxis2, ...patch.yAxis2 } : s.yAxis2,\n\t\t\t\tlegend: patch.legend ? { ...s.legend, ...patch.legend } : s.legend\n\t\t\t});\n\t\t\tconst attrs = { ...chart.node.attrs, spec, ...(width !== undefined ? { width } : {}), ...(height !== undefined ? { height } : {}) };\n\t\t\ted.view.dispatch(closeHistory(ed.state.tr.setNodeMarkup(chart.pos, undefined, attrs)));\n\t\t\treturn { id: chart.id, pos: chart.pos, spec, width: attrs.width, height: attrs.height };\n\t\t}\n\t};\n\n\tconst insertSparkline: AgentTool = {\n\t\tname: 'insert_sparkline',\n\t\ttitle: 'Insert a sparkline',\n\t\tdescription: 'Inserts a word-sized chart into the text at a document position (or the cursor), as one undo step. Returns its position and stored values.',\n\t\tinputSchema: {\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tvalues: { type: 'array', items: VALUE, minItems: 1, maxItems: MAX_SPARKLINE_VALUES, description: 'Values in order (null for a gap).' },\n\t\t\t\tkind: { type: 'string', enum: [...SPARKLINE_KINDS], description: 'line (default), column, or win-loss (sign only).' },\n\t\t\t\tat: { type: 'integer', minimum: 0, description: 'Document position inside a paragraph (default: the selection).' },\n\t\t\t\twidth: { type: 'number', minimum: 4, maximum: 1000, description: 'Width in pixels (default 80).' },\n\t\t\t\theight: { type: 'number', minimum: 4, maximum: 200, description: 'Height in pixels (default 18).' },\n\t\t\t\tcolor: { type: 'string', description: 'CSS colour (default: the first palette colour).' },\n\t\t\t\tlabel: { type: 'string', description: 'Accessible label (default: \"Trend from <first> to <last>\").' }\n\t\t\t},\n\t\t\trequired: ['values'],\n\t\t\tadditionalProperties: false\n\t\t},\n\t\tannotations: { title: 'Insert a sparkline', ...WRITE },\n\t\thandler: ({ values, kind = 'line', at, width = 80, height = 18, color = null, label = null }) => {\n\t\t\tconst ed = editor();\n\t\t\tcheckPosition(ed, at);\n\t\t\tconst parsed = (values as unknown[]).map((v) => parseChartValue(v));\n\t\t\tconst bad = parsed.findIndex((v) => v === undefined);\n\t\t\tif (bad >= 0) throw new Error(`values[${bad}] (\"${String(values[bad])}\") is not a number; pass numbers, numeric text or null. Nothing was inserted.`);\n\t\t\tconst pos = at ?? ed.state.selection.from;\n\t\t\tif (!ed.state.doc.resolve(pos).parent.inlineContent) throw new Error(`Position ${pos} is between blocks; a sparkline goes inside a paragraph (use a position from get_text {blocks: true}).`);\n\t\t\tconst stored = normalizeSparklineValues(parsed);\n\t\t\ted.chain().command(({ tr }) => (closeHistory(tr), true)).insertContentAt(pos, { type: 'sparkline', attrs: { values: stored, kind, width, height, color, label } }).run();\n\t\t\treturn { pos, kind, values: stored };\n\t\t}\n\t};\n\n\treturn {\n\t\tread: () => (chartType() ? [listCharts] : []),\n\t\twrite: () => (chartType() ? [insertChart, updateChart, ...(editor().schema.nodes.sparkline ? [insertSparkline] : [])] : [])\n\t};\n}\n","import { hasVariantCommands, type ComponentCommandTarget } from '../commands/builtins.js';\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport type { ToolProviderOptions } from './providers.js';\n\nconst IDS = { type: 'array', items: { type: 'string' }, description: 'Node ids (default: the selection).' } as const;\nconst ID = { type: 'string', description: 'An instance, or a layer inside one (default: the first selected node).' } as const;\n\nconst COMPONENT_ID = { type: 'string', description: 'Component or component set id (from list_components).' } as const;\nconst PARENT_ID = { type: 'string', description: 'Frame to place the instance in (default: the canvas root).' } as const;\nconst X = { type: 'number', description: 'X position (canvas coordinates, or relative to the parent frame).' } as const;\nconst Y = { type: 'number', description: 'Y position (canvas coordinates, or relative to the parent frame).' } as const;\n\nconst READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false } as const;\nconst DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false } as const;\n\n/** Tool titles shown by MCP clients. */\nconst TITLES: Record<string, string> = {\n\tlist_components: 'List components',\n\tinspect_instance: 'Inspect an instance',\n\tcreate_component: 'Create a component',\n\tcombine_as_variants: 'Combine as variants',\n\tcreate_instance: 'Create an instance',\n\tset_instance_properties: 'Set instance properties',\n\tswap_instance: 'Swap an instance',\n\treset_overrides: 'Reset overrides',\n\tpush_overrides: 'Push overrides to the main component',\n\tdetach_instance: 'Detach instances',\n\tgo_to_main_component: 'Go to the main component',\n\trestore_main_component: 'Restore the main component',\n\tadd_variant: 'Add a variant',\n\tremove_variant: 'Remove a variant',\n\tset_variant_properties: 'Set variant properties',\n\trename_variant_property: 'Rename a variant property',\n\trename_variant_value: 'Rename a variant value'\n};\n\n/** Tools that discard state the agent cannot get back by calling another tool. */\nconst DESTRUCTIVE_TOOLS = new Set(['reset_overrides', 'push_overrides', 'detach_instance', 'remove_variant']);\n\ntype Outcome = { ok: true; ids: string[] } | { ok: false; reason: string };\nconst check = (result: Outcome) => {\n\tif (!result.ok) throw new Error(result.reason);\n\treturn { ids: result.ids };\n};\n\n/**\n * Agent tools for canvas components and instances, backed by a components controller\n * (`createCanvasComponentsController`): `list_components`, `inspect_instance`,\n * `create_component`, `combine_as_variants`, `create_instance`, `set_instance_properties`\n * (variants and component properties), `swap_instance`, `reset_overrides`, `push_overrides`,\n * `detach_instance`, `go_to_main_component`, `restore_main_component` and (when the controller\n * has them) the variant editors `add_variant`, `remove_variant`, `set_variant_properties`,\n * `rename_variant_property` and `rename_variant_value`. Refused actions come back as tool errors\n * carrying the reason.\n */\nexport function createCanvasComponentToolProvider(\n\tcontroller: ComponentCommandTarget,\n\toptions: ToolProviderOptions = { id: 'canvas-components' }\n): AgentToolProvider {\n\tconst tool = (\n\t\tname: string,\n\t\tdescription: string,\n\t\tproperties: Record<string, unknown>,\n\t\thandler: AgentTool['handler'],\n\t\textra: { required?: string[]; readOnly?: boolean } = {}\n\t): AgentTool => ({\n\t\tname,\n\t\ttitle: TITLES[name],\n\t\tdescription,\n\t\tinputSchema: { type: 'object', properties: properties as never, ...(extra.required ? { required: extra.required } : {}), additionalProperties: false },\n\t\tannotations: {\n\t\t\ttitle: TITLES[name],\n\t\t\t...(extra.readOnly ? READ : DESTRUCTIVE_TOOLS.has(name) ? DESTRUCTIVE : WRITE)\n\t\t},\n\t\thandler\n\t});\n\tconst tools: AgentTool[] = [\n\t\ttool('list_components', 'Lists components (id, name, variant values, instance count) and component sets with their variant options.', {}, () => controller.list(), {\n\t\t\treadOnly: true\n\t\t}),\n\t\ttool(\n\t\t\t'inspect_instance',\n\t\t\t'Describes an instance: its main component, variant, component property values (with types) and the overrides of its layers.',\n\t\t\t{ id: ID },\n\t\t\t({ id }) => {\n\t\t\t\tconst info = controller.inspect(id);\n\t\t\t\tif (!info) throw new Error('Not an instance (or a layer inside one).');\n\t\t\t\treturn info;\n\t\t\t},\n\t\t\t{ readOnly: true }\n\t\t),\n\t\ttool('create_component', 'Turns the given frame into a main component, or wraps the given layers in a new one.', { ids: IDS }, ({ ids }) =>\n\t\t\tcheck(controller.createComponent(ids))\n\t\t),\n\t\ttool('combine_as_variants', 'Wraps sibling components in a component set (variants named \"Property=Value, …\").', { ids: IDS }, ({ ids }) =>\n\t\t\tcheck(controller.combineAsVariants(ids))\n\t\t),\n\t\ttool(\n\t\t\t'create_instance',\n\t\t\t'Places an instance of a component or component set, optionally inside a frame, at a position, with property values.',\n\t\t\t{\n\t\t\t\tcomponentId: COMPONENT_ID,\n\t\t\t\tparentId: PARENT_ID,\n\t\t\t\tx: X,\n\t\t\t\ty: Y,\n\t\t\t\tproperties: { type: 'object', additionalProperties: true, description: 'Variant and component property values.' }\n\t\t\t},\n\t\t\t({ componentId, parentId, x, y, properties }) =>\n\t\t\t\tcheck(\n\t\t\t\t\tcontroller.createInstance(componentId, {\n\t\t\t\t\t\t...(parentId !== undefined ? { parentId } : {}),\n\t\t\t\t\t\t...(x !== undefined || y !== undefined ? { position: { x: x ?? 0, y: y ?? 0 } } : {}),\n\t\t\t\t\t\t...(properties ? { properties } : {})\n\t\t\t\t\t})\n\t\t\t\t),\n\t\t\t{ required: ['componentId'] }\n\t\t),\n\t\ttool(\n\t\t\t'set_instance_properties',\n\t\t\t'Sets property values of instances: variant properties switch the variant (keeping compatible overrides), booleans toggle layers, text sets text, instance swap takes a component id.',\n\t\t\t{\n\t\t\t\tproperties: {\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\tdescription: 'Property name → value (see inspect_instance for the names and types).'\n\t\t\t\t},\n\t\t\t\tids: IDS\n\t\t\t},\n\t\t\t({ properties, ids }) => check(controller.setInstanceProperties(properties, ids)),\n\t\t\t{ required: ['properties'] }\n\t\t),\n\t\ttool(\n\t\t\t'swap_instance',\n\t\t\t'Makes instances show another component (or a set’s default variant), keeping overrides of layers with matching names.',\n\t\t\t{ componentId: COMPONENT_ID, ids: IDS },\n\t\t\t({ componentId, ids }) => check(controller.swapInstance(componentId, ids)),\n\t\t\t{ required: ['componentId'] }\n\t\t),\n\t\ttool(\n\t\t\t'reset_overrides',\n\t\t\t'Resets overrides: of a whole instance (default), of one layer, or one override group such as \"data.label\" or \"shape.fill\".',\n\t\t\t{ id: ID, group: { type: 'string', description: 'Override group, e.g. \"data.label\" or \"shape.fill\" (default: all).' } },\n\t\t\t({ id, group }) => check(controller.resetOverrides(id, group))\n\t\t),\n\t\ttool('push_overrides', 'Copies an instance’s overrides to its main component (and so to every other instance).', { id: ID }, ({ id }) =>\n\t\t\tcheck(controller.pushOverrides(id))\n\t\t),\n\t\ttool('detach_instance', 'Turns instances into plain frames that keep their current look.', { ids: IDS }, ({ ids }) => check(controller.detachInstance(ids))),\n\t\ttool('go_to_main_component', 'Selects the main component of an instance and returns its id.', { id: ID }, ({ id }) => {\n\t\t\tconst main = controller.goToMainComponent(id);\n\t\t\tif (!main) throw new Error('The main component was not found.');\n\t\t\treturn { id: main };\n\t\t}),\n\t\ttool('restore_main_component', 'Turns an instance whose main component was deleted back into the main component.', { id: ID }, ({ id }) =>\n\t\t\tcheck(controller.restoreMainComponent(id))\n\t\t)\n\t];\n\tif (hasVariantCommands(controller)) {\n\t\tconst SET = { type: 'string', description: 'Component set, or one of its variants (default: the selection’s set).' };\n\t\tconst VARIANT = { type: 'string', description: 'Variant id (default: the first selected variant).' };\n\t\tconst VALUES = { type: 'object', additionalProperties: { type: 'string' }, description: 'Variant property → value, e.g. { \"Size\": \"Medium\" }.' };\n\t\ttools.push(\n\t\t\ttool(\n\t\t\t\t'add_variant',\n\t\t\t\t'Adds a variant to a component set by duplicating one (default: the set’s default variant) with new property values. Unnamed properties keep the source’s values; new property names are added to every variant (\"Default\"). A combination another variant has is refused. Without values the next \"VariantN\" is used.',\n\t\t\t\t{ setId: SET, from: { type: 'string', description: 'Variant to duplicate.' }, variant: VALUES, x: X, y: Y },\n\t\t\t\t({ setId, from, variant, x, y }) =>\n\t\t\t\t\tcheck(\n\t\t\t\t\t\tcontroller.addVariant(setId, {\n\t\t\t\t\t\t\t...(from !== undefined ? { from } : {}),\n\t\t\t\t\t\t\t...(variant ? { variant } : {}),\n\t\t\t\t\t\t\t...(x !== undefined || y !== undefined ? { position: { x: x ?? 0, y: y ?? 0 } } : {})\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'remove_variant',\n\t\t\t\t'Removes a variant from its component set (not the last one). Its instances switch to the closest remaining variant, keeping overrides.',\n\t\t\t\t{ id: VARIANT },\n\t\t\t\t({ id }) => check(controller.removeVariant(id))\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'set_variant_properties',\n\t\t\t\t'Sets a variant’s property values (merged with its current ones); new property names are added to every variant. A combination another variant has is refused.',\n\t\t\t\t{ values: VALUES, id: VARIANT },\n\t\t\t\t({ values, id }) => check(controller.setVariantProperties(values, id)),\n\t\t\t\t{ required: ['values'] }\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'rename_variant_property',\n\t\t\t\t'Renames a variant property across a component set (instances keep their variant).',\n\t\t\t\t{\n\t\t\t\t\tname: { type: 'string', description: 'Current property name.' },\n\t\t\t\t\tnewName: { type: 'string', description: 'New property name.' },\n\t\t\t\t\tsetId: SET\n\t\t\t\t},\n\t\t\t\t({ name, newName, setId }) => check(controller.renameVariantProperty(name, newName, setId)),\n\t\t\t\t{ required: ['name', 'newName'] }\n\t\t\t),\n\t\t\ttool(\n\t\t\t\t'rename_variant_value',\n\t\t\t\t'Renames a value of a variant property across a component set (instances keep their variant).',\n\t\t\t\t{\n\t\t\t\t\tproperty: { type: 'string', description: 'Variant property name.' },\n\t\t\t\t\tvalue: { type: 'string', description: 'Current value.' },\n\t\t\t\t\tnewValue: { type: 'string', description: 'New value.' },\n\t\t\t\t\tsetId: SET\n\t\t\t\t},\n\t\t\t\t({ property, value, newValue, setId }) => check(controller.renameVariantValue(property, value, newValue, setId)),\n\t\t\t\t{ required: ['property', 'value', 'newValue'] }\n\t\t\t)\n\t\t);\n\t}\n\treturn { id: options.id, namespace: options.namespace, tools };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQO,SAAS,cAAc,MAAuC;AACpE,UAAQ,MAAM;AAAA,IACb,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAKO,SAAS,iBAIf,SACA,UACA,UAGI,CAAC,GACuB;AAC5B,QAAM,kBAAkB,QAAQ,mBAAmB,EAAE,OAAO,KAAK,QAAQ,GAAG;AAC5E,QAAM,QAAQ,QAAQ,gBAAgB,MAAM,QAAQ,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC,CAAC;AAC9F,QAAM,YAAY,MAAM,QAAQ,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC,CAAC;AAE1E,QAAM,QAAQ,SAAS,QAAQ,SAAS,CAAC;AACzC,QAAM,QAAQ,SAAS,Q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