@pixerate/editor 0.14.3 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/agent/index.cjs +28 -220
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +1 -1
  4. package/dist/agent/index.d.ts +1 -1
  5. package/dist/agent/index.js +5 -154
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/canvas/index.cjs +113 -377
  8. package/dist/canvas/index.cjs.map +1 -1
  9. package/dist/canvas/index.d.cts +2 -2
  10. package/dist/canvas/index.d.ts +2 -2
  11. package/dist/canvas/index.js +18 -208
  12. package/dist/canvas/index.js.map +1 -1
  13. package/dist/chunk-33UVEDOS.cjs +233 -0
  14. package/dist/chunk-33UVEDOS.cjs.map +1 -0
  15. package/dist/chunk-7FWEWE6T.js +1888 -0
  16. package/dist/chunk-7FWEWE6T.js.map +1 -0
  17. package/dist/chunk-BYCOFZAA.js +514 -0
  18. package/dist/chunk-BYCOFZAA.js.map +1 -0
  19. package/dist/chunk-CYKQLDYH.cjs +1290 -0
  20. package/dist/chunk-CYKQLDYH.cjs.map +1 -0
  21. package/dist/chunk-GLSIZKOX.js +17 -0
  22. package/dist/chunk-GLSIZKOX.js.map +1 -0
  23. package/dist/chunk-GWHJVZPI.js +233 -0
  24. package/dist/chunk-GWHJVZPI.js.map +1 -0
  25. package/dist/chunk-LDES3EOS.cjs +1888 -0
  26. package/dist/chunk-LDES3EOS.cjs.map +1 -0
  27. package/dist/chunk-MPPXH7U5.cjs +336 -0
  28. package/dist/chunk-MPPXH7U5.cjs.map +1 -0
  29. package/dist/chunk-NNJRJJSC.js +1290 -0
  30. package/dist/chunk-NNJRJJSC.js.map +1 -0
  31. package/dist/chunk-O7LOPQMH.js +336 -0
  32. package/dist/chunk-O7LOPQMH.js.map +1 -0
  33. package/dist/chunk-SEDR75VH.cjs +17 -0
  34. package/dist/chunk-SEDR75VH.cjs.map +1 -0
  35. package/dist/chunk-SHWP2A43.cjs +514 -0
  36. package/dist/chunk-SHWP2A43.cjs.map +1 -0
  37. package/dist/chunk-VHZCXHS4.js +222 -0
  38. package/dist/chunk-VHZCXHS4.js.map +1 -0
  39. package/dist/chunk-WADCJ7A7.cjs +222 -0
  40. package/dist/chunk-WADCJ7A7.cjs.map +1 -0
  41. package/dist/extensions/index.cjs +25 -1920
  42. package/dist/extensions/index.cjs.map +1 -1
  43. package/dist/extensions/index.js +22 -1868
  44. package/dist/extensions/index.js.map +1 -1
  45. package/dist/grammar/index.cjs +44 -387
  46. package/dist/grammar/index.cjs.map +1 -1
  47. package/dist/grammar/index.js +23 -321
  48. package/dist/grammar/index.js.map +1 -1
  49. package/dist/history/index.cjs +6 -257
  50. package/dist/history/index.cjs.map +1 -1
  51. package/dist/history/index.js +4 -227
  52. package/dist/history/index.js.map +1 -1
  53. package/dist/image-editor/index.cjs +63 -106
  54. package/dist/image-editor/index.cjs.map +1 -1
  55. package/dist/index.cjs +324 -7232
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +0 -4
  58. package/dist/index.d.ts +0 -4
  59. package/dist/index.js +258 -7007
  60. package/dist/index.js.map +1 -1
  61. package/dist/serializers/index.cjs +28 -558
  62. package/dist/serializers/index.cjs.map +1 -1
  63. package/dist/serializers/index.js +16 -496
  64. package/dist/serializers/index.js.map +1 -1
  65. package/dist/spreadsheet/index.cjs +21 -1319
  66. package/dist/spreadsheet/index.cjs.map +1 -1
  67. package/dist/spreadsheet/index.js +14 -1274
  68. package/dist/spreadsheet/index.js.map +1 -1
  69. package/dist/{types-lGtRobRV.d.cts → types-DC8b2TsA.d.cts} +1 -1
  70. package/dist/{types-lGtRobRV.d.ts → types-DC8b2TsA.d.ts} +1 -1
  71. package/package.json +1 -1
@@ -1,207 +1,16 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
29
2
 
30
- // src/agent/index.ts
31
- var agent_exports = {};
32
- __export(agent_exports, {
33
- EDITOR_MCP_TOOLS: () => EDITOR_MCP_TOOLS,
34
- EXPORT_EXCLUDED_SELECTORS: () => EXPORT_EXCLUDED_SELECTORS,
35
- MCP_TOOL_EDIT_CANVAS: () => MCP_TOOL_EDIT_CANVAS,
36
- MCP_TOOL_EDIT_PROMPT: () => MCP_TOOL_EDIT_PROMPT,
37
- MCP_TOOL_GET_EDITOR_STATE: () => MCP_TOOL_GET_EDITOR_STATE,
38
- MCP_TOOL_VIEW_EDITOR: () => MCP_TOOL_VIEW_EDITOR,
39
- planAgentCommand: () => planAgentCommand
40
- });
41
- module.exports = __toCommonJS(agent_exports);
42
3
 
43
- // src/canvas/layout.ts
44
- var import_dagre = __toESM(require("@dagrejs/dagre"), 1);
45
- var DEFAULT_NODE_WIDTH = 200;
46
- var DEFAULT_NODE_HEIGHT = 60;
47
- var DEFAULT_PLACEMENT_GAP = 48;
48
- function getLayoutedNodes(nodes, edges, getNodesBounds, options = {}) {
49
- if (nodes.length === 0) return [];
50
- const {
51
- direction = "LR",
52
- ranksep = 100,
53
- nodesep = 25,
54
- defaultNodeWidth = DEFAULT_NODE_WIDTH,
55
- defaultNodeHeight = DEFAULT_NODE_HEIGHT
56
- } = options;
57
- const dagreGraph = new import_dagre.default.graphlib.Graph();
58
- dagreGraph.setDefaultEdgeLabel(() => ({}));
59
- dagreGraph.setGraph({ rankdir: direction, ranksep, nodesep });
60
- const nodeIds = new Set(nodes.map((node) => node.id));
61
- nodes.forEach((node) => {
62
- const nodeWidth = node.measured?.width ?? node.width ?? defaultNodeWidth;
63
- const nodeHeight = node.measured?.height ?? node.height ?? defaultNodeHeight;
64
- dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });
65
- });
66
- edges.forEach((edge) => {
67
- if (nodeIds.has(edge.source) && nodeIds.has(edge.target)) {
68
- dagreGraph.setEdge(edge.source, edge.target);
69
- }
70
- });
71
- import_dagre.default.layout(dagreGraph);
72
- return nodes.map((node) => {
73
- const nodeWithPosition = dagreGraph.node(node.id);
74
- const nodeWidth = node.measured?.width ?? node.width ?? defaultNodeWidth;
75
- const nodeHeight = node.measured?.height ?? node.height ?? defaultNodeHeight;
76
- return {
77
- ...node,
78
- position: {
79
- x: nodeWithPosition.x - nodeWidth / 2,
80
- y: nodeWithPosition.y - nodeHeight / 2
81
- }
82
- };
83
- });
84
- }
85
- function boundsOf(rects) {
86
- if (!rects.length) return null;
87
- const minX = Math.min(...rects.map((r) => r.x));
88
- const minY = Math.min(...rects.map((r) => r.y));
89
- const maxX = Math.max(...rects.map((r) => r.x + r.width));
90
- const maxY = Math.max(...rects.map((r) => r.y + r.height));
91
- return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
92
- }
93
- function centre(r) {
94
- return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
95
- }
96
- function overlaps(a, b, pad = 16) {
97
- return a.x < b.x + b.width + pad && a.x + a.width + pad > b.x && a.y < b.y + b.height + pad && a.y + a.height + pad > b.y;
98
- }
99
- function ensureLayout(nodes, edges, options = {}) {
100
- if (nodes.length === 0) return [];
101
- const stored = options.storedPositions ?? {};
102
- const missing = nodes.filter((n) => !stored[n.id]);
103
- if (missing.length === 0) {
104
- return nodes.map((n) => ({
105
- ...n,
106
- position: { ...stored[n.id] }
107
- }));
108
- }
109
- const autoLayouted = getLayoutedNodes(nodes, edges, void 0, options);
110
- const autoMap = new Map(
111
- autoLayouted.map((n) => [n.id, n.position])
112
- );
113
- const both = nodes.filter((n) => stored[n.id] && autoMap.has(n.id));
114
- if (both.length === 0) {
115
- return autoLayouted;
116
- }
117
- let dx = 0;
118
- let dy = 0;
119
- for (const n of both) {
120
- const s = stored[n.id];
121
- const a = autoMap.get(n.id);
122
- dx += s.x - a.x;
123
- dy += s.y - a.y;
124
- }
125
- dx /= both.length;
126
- dy /= both.length;
127
- return nodes.map((node) => {
128
- if (stored[node.id]) {
129
- return {
130
- ...node,
131
- position: { ...stored[node.id] }
132
- };
133
- }
134
- const autoPos = autoMap.get(node.id) ?? { x: 0, y: 0 };
135
- return {
136
- ...node,
137
- position: {
138
- x: Math.round(autoPos.x + dx),
139
- y: Math.round(autoPos.y + dy)
140
- }
141
- };
142
- });
143
- }
144
- function placeBeside(rects, size, side, nearNodeId, options = {}) {
145
- const {
146
- gap = DEFAULT_PLACEMENT_GAP,
147
- ignore = [],
148
- maxAttempts = 32
149
- } = options;
150
- const skip = new Set([nearNodeId, ...ignore].filter(Boolean));
151
- const obstacles = Object.entries(rects).filter(([id]) => !skip.has(id)).map(([, r]) => r);
152
- const anchor = nearNodeId && rects[nearNodeId] || boundsOf(Object.values(rects)) || { x: 0, y: 0, width: 0, height: 0 };
153
- const anchorCenter = centre(anchor);
154
- let baseX;
155
- let baseY;
156
- switch (side) {
157
- case "right":
158
- baseX = anchor.x + anchor.width + gap;
159
- baseY = anchorCenter.y - size.height / 2;
160
- break;
161
- case "left":
162
- baseX = anchor.x - gap - size.width;
163
- baseY = anchorCenter.y - size.height / 2;
164
- break;
165
- case "above":
166
- baseX = anchorCenter.x - size.width / 2;
167
- baseY = anchor.y - gap - size.height;
168
- break;
169
- case "below":
170
- default:
171
- baseX = anchorCenter.x - size.width / 2;
172
- baseY = anchor.y + anchor.height + gap;
173
- break;
174
- }
175
- const isHorizontal = side === "right" || side === "left";
176
- const step = (isHorizontal ? size.height : size.width) + 20;
177
- for (let i = 0; i < maxAttempts; i++) {
178
- const offset = i === 0 ? 0 : Math.ceil(i / 2) * step * (i % 2 === 1 ? 1 : -1);
179
- const candidateBox = {
180
- x: isHorizontal ? baseX : baseX + offset,
181
- y: isHorizontal ? baseY + offset : baseY,
182
- width: size.width,
183
- height: size.height
184
- };
185
- if (!obstacles.some((obstacle) => overlaps(candidateBox, obstacle, 8))) {
186
- return {
187
- x: Math.round(candidateBox.x),
188
- y: Math.round(candidateBox.y)
189
- };
190
- }
191
- }
192
- return {
193
- x: Math.round(baseX),
194
- y: Math.round(baseY)
195
- };
196
- }
4
+
5
+ var _chunkWADCJ7A7cjs = require('../chunk-WADCJ7A7.cjs');
197
6
 
198
7
  // src/agent/planner.ts
199
8
  function planAgentCommand(command, snapshot, options = {}) {
200
- const defaultNodeSize = options.defaultNodeSize ?? { width: 200, height: 60 };
201
- const idGen = options.idGenerator ?? (() => `node-${Math.random().toString(36).substring(2, 9)}`);
9
+ const defaultNodeSize = _nullishCoalesce(options.defaultNodeSize, () => ( { width: 200, height: 60 }));
10
+ const idGen = _nullishCoalesce(options.idGenerator, () => ( (() => `node-${Math.random().toString(36).substring(2, 9)}`)));
202
11
  const edgeIdGen = () => `edge-${Math.random().toString(36).substring(2, 9)}`;
203
- const nodes = snapshot.canvas?.nodes ?? [];
204
- const edges = snapshot.canvas?.edges ?? [];
12
+ const nodes = _nullishCoalesce(_optionalChain([snapshot, 'access', _ => _.canvas, 'optionalAccess', _2 => _2.nodes]), () => ( []));
13
+ const edges = _nullishCoalesce(_optionalChain([snapshot, 'access', _3 => _3.canvas, 'optionalAccess', _4 => _4.edges]), () => ( []));
205
14
  switch (command.type) {
206
15
  case "canvas:add_node": {
207
16
  let pos = command.node.position;
@@ -212,14 +21,14 @@ function planAgentCommand(command, snapshot, options = {}) {
212
21
  rects[n.id] = {
213
22
  x: n.position.x,
214
23
  y: n.position.y,
215
- width: n.measured?.width ?? n.width ?? defaultNodeSize.width,
216
- height: n.measured?.height ?? n.height ?? defaultNodeSize.height
24
+ width: _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _5 => _5.measured, 'optionalAccess', _6 => _6.width]), () => ( n.width)), () => ( defaultNodeSize.width)),
25
+ height: _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _7 => _7.measured, 'optionalAccess', _8 => _8.height]), () => ( n.height)), () => ( defaultNodeSize.height))
217
26
  };
218
27
  }
219
- pos = placeBeside(
28
+ pos = _chunkWADCJ7A7cjs.placeBeside.call(void 0,
220
29
  rects,
221
30
  defaultNodeSize,
222
- command.side ?? "right",
31
+ _nullishCoalesce(command.side, () => ( "right")),
223
32
  command.nearNodeId
224
33
  );
225
34
  } else if (nodes.length > 0) {
@@ -229,11 +38,11 @@ function planAgentCommand(command, snapshot, options = {}) {
229
38
  rects[n.id] = {
230
39
  x: n.position.x,
231
40
  y: n.position.y,
232
- width: n.measured?.width ?? n.width ?? defaultNodeSize.width,
233
- height: n.measured?.height ?? n.height ?? defaultNodeSize.height
41
+ width: _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _9 => _9.measured, 'optionalAccess', _10 => _10.width]), () => ( n.width)), () => ( defaultNodeSize.width)),
42
+ height: _nullishCoalesce(_nullishCoalesce(_optionalChain([n, 'access', _11 => _11.measured, 'optionalAccess', _12 => _12.height]), () => ( n.height)), () => ( defaultNodeSize.height))
234
43
  };
235
44
  }
236
- pos = placeBeside(rects, defaultNodeSize, "right", lastNode.id);
45
+ pos = _chunkWADCJ7A7cjs.placeBeside.call(void 0, rects, defaultNodeSize, "right", lastNode.id);
237
46
  } else {
238
47
  pos = { x: 100, y: 100 };
239
48
  }
@@ -292,7 +101,7 @@ function planAgentCommand(command, snapshot, options = {}) {
292
101
  ];
293
102
  }
294
103
  case "canvas:layout": {
295
- const dir = command.direction ?? "LR";
104
+ const dir = _nullishCoalesce(command.direction, () => ( "LR"));
296
105
  let layouted;
297
106
  if (command.incremental) {
298
107
  const stored = {};
@@ -301,12 +110,12 @@ function planAgentCommand(command, snapshot, options = {}) {
301
110
  stored[n.id] = { ...n.position };
302
111
  }
303
112
  }
304
- layouted = ensureLayout(nodes, edges, {
113
+ layouted = _chunkWADCJ7A7cjs.ensureLayout.call(void 0, nodes, edges, {
305
114
  direction: dir,
306
115
  storedPositions: stored
307
116
  });
308
117
  } else {
309
- layouted = getLayoutedNodes(nodes, edges, void 0, { direction: dir });
118
+ layouted = _chunkWADCJ7A7cjs.getLayoutedNodes.call(void 0, nodes, edges, void 0, { direction: dir });
310
119
  }
311
120
  const positions = {};
312
121
  for (const node of layouted) {
@@ -332,8 +141,8 @@ function planAgentCommand(command, snapshot, options = {}) {
332
141
  {
333
142
  type: "step:canvas_highlight",
334
143
  nodeIds: command.nodeIds,
335
- color: command.color ?? "#3b82f6",
336
- durationMs: command.durationMs ?? 2e3
144
+ color: _nullishCoalesce(command.color, () => ( "#3b82f6")),
145
+ durationMs: _nullishCoalesce(command.durationMs, () => ( 2e3))
337
146
  }
338
147
  ];
339
148
  }
@@ -550,14 +359,13 @@ var EDITOR_MCP_TOOLS = [
550
359
  MCP_TOOL_EDIT_PROMPT,
551
360
  MCP_TOOL_VIEW_EDITOR
552
361
  ];
553
- // Annotate the CommonJS export names for ESM import in node:
554
- 0 && (module.exports = {
555
- EDITOR_MCP_TOOLS,
556
- EXPORT_EXCLUDED_SELECTORS,
557
- MCP_TOOL_EDIT_CANVAS,
558
- MCP_TOOL_EDIT_PROMPT,
559
- MCP_TOOL_GET_EDITOR_STATE,
560
- MCP_TOOL_VIEW_EDITOR,
561
- planAgentCommand
562
- });
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+ exports.EDITOR_MCP_TOOLS = EDITOR_MCP_TOOLS; exports.EXPORT_EXCLUDED_SELECTORS = EXPORT_EXCLUDED_SELECTORS; exports.MCP_TOOL_EDIT_CANVAS = MCP_TOOL_EDIT_CANVAS; exports.MCP_TOOL_EDIT_PROMPT = MCP_TOOL_EDIT_PROMPT; exports.MCP_TOOL_GET_EDITOR_STATE = MCP_TOOL_GET_EDITOR_STATE; exports.MCP_TOOL_VIEW_EDITOR = MCP_TOOL_VIEW_EDITOR; exports.planAgentCommand = planAgentCommand;
563
371
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/agent/index.ts","../../src/canvas/layout.ts","../../src/agent/planner.ts","../../src/agent/tools.ts"],"sourcesContent":["export * from './types.js';\nexport * from './planner.js';\nexport * from './tools.js';\n","import dagre from '@dagrejs/dagre';\nimport type {\n\tCanvasEdge,\n\tCanvasLayoutOptions,\n\tCanvasNode,\n\tIncrementalLayoutOptions,\n\tPlaceBesideOptions,\n\tRect,\n\tSide,\n\tXYPosition\n} from './types.js';\n\nexport const DEFAULT_NODE_WIDTH = 200;\nexport const DEFAULT_NODE_HEIGHT = 60;\nexport const DEFAULT_PLACEMENT_GAP = 48;\n\n/**\n * Calculates upper-left flow coordinate for an element to be centered in the viewport.\n */\nexport function getCenteredNodePosition(\n\twidth = 0,\n\theight = 0,\n\tscreenToFlowPosition: (position: XYPosition) => XYPosition,\n\tscreenDimensions?: { width: number; height: number }\n): XYPosition {\n\tconst rect =\n\t\tscreenDimensions ??\n\t\t(typeof document !== 'undefined'\n\t\t\t? { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight }\n\t\t\t: { width: 1920, height: 1080 });\n\n\tconst flowPos = screenToFlowPosition({ x: rect.width / 2, y: rect.height / 2 });\n\treturn {\n\t\tx: flowPos.x - width / 2,\n\t\ty: flowPos.y - height / 2\n\t};\n}\n\n/**\n * Updates positions of nodes so their collective bounding box is centered in the current viewport.\n */\nexport function centerNodes<TNode extends CanvasNode = CanvasNode>(\n\tnodes: TNode[],\n\tscreenToFlowPosition: (position: XYPosition) => XYPosition,\n\tgetNodesBounds: (nodes: TNode[]) => Rect,\n\tscreenDimensions?: { width: number; height: number }\n): TNode[] {\n\tif (nodes.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst bounds = getNodesBounds(nodes);\n\tconst boundingBoxOrigin = { x: bounds.x, y: bounds.y };\n\n\tconst centeredPosition = getCenteredNodePosition(\n\t\tbounds.width,\n\t\tbounds.height,\n\t\tscreenToFlowPosition,\n\t\tscreenDimensions\n\t);\n\n\tconst deltaX = centeredPosition.x - boundingBoxOrigin.x;\n\tconst deltaY = centeredPosition.y - boundingBoxOrigin.y;\n\n\treturn nodes.map((node) => ({\n\t\t...node,\n\t\tposition: {\n\t\t\tx: node.position.x + deltaX,\n\t\t\ty: node.position.y + deltaY\n\t\t}\n\t}));\n}\n\n/**\n * Automatically calculates directed hierarchical layout of nodes and edges using Dagre.\n */\nexport function getLayoutedNodes<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(\n\tnodes: TNode[],\n\tedges: TEdge[],\n\tgetNodesBounds?: (nodes: TNode[]) => Rect,\n\toptions: CanvasLayoutOptions = {}\n): TNode[] {\n\tif (nodes.length === 0) return [];\n\n\tconst {\n\t\tdirection = 'LR',\n\t\tranksep = 100,\n\t\tnodesep = 25,\n\t\tdefaultNodeWidth = DEFAULT_NODE_WIDTH,\n\t\tdefaultNodeHeight = DEFAULT_NODE_HEIGHT\n\t} = options;\n\n\tconst dagreGraph = new dagre.graphlib.Graph();\n\tdagreGraph.setDefaultEdgeLabel(() => ({}));\n\tdagreGraph.setGraph({ rankdir: direction, ranksep, nodesep });\n\n\tconst nodeIds = new Set(nodes.map((node) => node.id));\n\n\tnodes.forEach((node) => {\n\t\tconst nodeWidth = node.measured?.width ?? (node as any).width ?? defaultNodeWidth;\n\t\tconst nodeHeight = node.measured?.height ?? (node as any).height ?? defaultNodeHeight;\n\t\tdagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });\n\t});\n\n\tedges.forEach((edge) => {\n\t\tif (nodeIds.has(edge.source) && nodeIds.has(edge.target)) {\n\t\t\tdagreGraph.setEdge(edge.source, edge.target);\n\t\t}\n\t});\n\n\tdagre.layout(dagreGraph);\n\n\treturn nodes.map((node) => {\n\t\tconst nodeWithPosition = dagreGraph.node(node.id);\n\t\tconst nodeWidth = node.measured?.width ?? (node as any).width ?? defaultNodeWidth;\n\t\tconst nodeHeight = node.measured?.height ?? (node as any).height ?? defaultNodeHeight;\n\n\t\treturn {\n\t\t\t...node,\n\t\t\tposition: {\n\t\t\t\tx: nodeWithPosition.x - nodeWidth / 2,\n\t\t\t\ty: nodeWithPosition.y - nodeHeight / 2\n\t\t\t}\n\t\t};\n\t});\n}\n\n/**\n * Heuristic text-based node size estimator when DOM measurement is not available.\n */\nexport function estimateNodeSize(\n\tnode: CanvasNode,\n\tdefaultWidth = DEFAULT_NODE_WIDTH,\n\tdefaultHeight = DEFAULT_NODE_HEIGHT\n): { width: number; height: number } {\n\tconst label = String(node.data?.label ?? node.data?.title ?? node.id ?? '');\n\tconst lines = label.split(/\\n|<br\\s*\\/?>/);\n\tconst longest = Math.max(...lines.map((l) => l.replace(/<[^>]+>/g, '').length), 1);\n\tconst width = Math.min(480, Math.max(defaultWidth, longest * 8 + 48));\n\tconst height = Math.max(defaultHeight, lines.length * 20 + 24);\n\treturn { width, height };\n}\n\n/**\n * Computes bounding rectangle of an array of rectangles.\n */\nexport function boundsOf(rects: Rect[]): Rect | null {\n\tif (!rects.length) return null;\n\tconst minX = Math.min(...rects.map((r) => r.x));\n\tconst minY = Math.min(...rects.map((r) => r.y));\n\tconst maxX = Math.max(...rects.map((r) => r.x + r.width));\n\tconst maxY = Math.max(...rects.map((r) => r.y + r.height));\n\treturn { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/**\n * Center coordinate of a rectangle.\n */\nexport function centre(r: Rect): XYPosition {\n\treturn { x: r.x + r.width / 2, y: r.y + r.height / 2 };\n}\n\n/**\n * Determines whether two rectangles overlap, including an optional padding distance.\n */\nexport function overlaps(a: Rect, b: Rect, pad = 16): boolean {\n\treturn (\n\t\ta.x < b.x + b.width + pad &&\n\t\ta.x + a.width + pad > b.x &&\n\t\ta.y < b.y + b.height + pad &&\n\t\ta.y + a.height + pad > b.y\n\t);\n}\n\n/**\n * Maps directed layout flow to its natural forward growth side.\n */\nexport function flowSide(direction: 'LR' | 'TB' | 'RL' | 'BT' = 'LR'): Side {\n\tswitch (direction) {\n\t\tcase 'LR':\n\t\t\treturn 'right';\n\t\tcase 'RL':\n\t\t\treturn 'left';\n\t\tcase 'BT':\n\t\t\treturn 'above';\n\t\tcase 'TB':\n\t\tdefault:\n\t\t\treturn 'below';\n\t}\n}\n\n/**\n * Incremental layout blending:\n * Keeps established/manual node positions intact. Runs Dagre on the entire graph,\n * computes the centroid translation offset between auto and stored positions of existing nodes,\n * and places unpositioned/new nodes at (auto + offset).\n */\nexport function ensureLayout<\n\tTNode extends CanvasNode = CanvasNode,\n\tTEdge extends CanvasEdge = CanvasEdge\n>(\n\tnodes: TNode[],\n\tedges: TEdge[],\n\toptions: IncrementalLayoutOptions = {}\n): TNode[] {\n\tif (nodes.length === 0) return [];\n\n\tconst stored = options.storedPositions ?? {};\n\tconst missing = nodes.filter((n) => !stored[n.id]);\n\n\t// Case 1: Every node has an established coordinate -> preserve verbatim\n\tif (missing.length === 0) {\n\t\treturn nodes.map((n) => ({\n\t\t\t...n,\n\t\t\tposition: { ...stored[n.id]! }\n\t\t}));\n\t}\n\n\t// Calculate full dagre auto-layout\n\tconst autoLayouted = getLayoutedNodes(nodes, edges, undefined, options);\n\tconst autoMap = new Map<string, XYPosition>(\n\t\tautoLayouted.map((n) => [n.id, n.position])\n\t);\n\n\t// Case 2: No nodes have stored coordinates -> return auto layout directly\n\tconst both = nodes.filter((n) => stored[n.id] && autoMap.has(n.id));\n\tif (both.length === 0) {\n\t\treturn autoLayouted;\n\t}\n\n\t// Case 3: Blend! Align on centroid translation offset of overlapping nodes\n\tlet dx = 0;\n\tlet dy = 0;\n\tfor (const n of both) {\n\t\tconst s = stored[n.id]!;\n\t\tconst a = autoMap.get(n.id)!;\n\t\tdx += s.x - a.x;\n\t\tdy += s.y - a.y;\n\t}\n\tdx /= both.length;\n\tdy /= both.length;\n\n\treturn nodes.map((node) => {\n\t\tif (stored[node.id]) {\n\t\t\treturn {\n\t\t\t\t...node,\n\t\t\t\tposition: { ...stored[node.id]! }\n\t\t\t};\n\t\t}\n\t\tconst autoPos = autoMap.get(node.id) ?? { x: 0, y: 0 };\n\t\treturn {\n\t\t\t...node,\n\t\t\tposition: {\n\t\t\t\tx: Math.round(autoPos.x + dx),\n\t\t\t\ty: Math.round(autoPos.y + dy)\n\t\t\t}\n\t\t};\n\t});\n}\n\n/**\n * Finds a free top-left coordinate for a node of `size` adjacent to `nearNodeId` (or the cluster),\n * sliding along the perpendicular axis past any intersecting bounding boxes to guarantee non-overlapping placement.\n */\nexport function placeBeside(\n\trects: Record<string, Rect>,\n\tsize: { width: number; height: number },\n\tside: Side,\n\tnearNodeId?: string,\n\toptions: PlaceBesideOptions = {}\n): XYPosition {\n\tconst {\n\t\tgap = DEFAULT_PLACEMENT_GAP,\n\t\tignore = [],\n\t\tmaxAttempts = 32\n\t} = options;\n\n\tconst skip = new Set([nearNodeId, ...ignore].filter(Boolean));\n\tconst obstacles = Object.entries(rects)\n\t\t.filter(([id]) => !skip.has(id))\n\t\t.map(([, r]) => r);\n\n\tconst anchor =\n\t\t(nearNodeId && rects[nearNodeId]) ||\n\t\tboundsOf(Object.values(rects)) ||\n\t\t{ x: 0, y: 0, width: 0, height: 0 };\n\n\tconst anchorCenter = centre(anchor);\n\n\tlet baseX: number;\n\tlet baseY: number;\n\n\tswitch (side) {\n\t\tcase 'right':\n\t\t\tbaseX = anchor.x + anchor.width + gap;\n\t\t\tbaseY = anchorCenter.y - size.height / 2;\n\t\t\tbreak;\n\t\tcase 'left':\n\t\t\tbaseX = anchor.x - gap - size.width;\n\t\t\tbaseY = anchorCenter.y - size.height / 2;\n\t\t\tbreak;\n\t\tcase 'above':\n\t\t\tbaseX = anchorCenter.x - size.width / 2;\n\t\t\tbaseY = anchor.y - gap - size.height;\n\t\t\tbreak;\n\t\tcase 'below':\n\t\tdefault:\n\t\t\tbaseX = anchorCenter.x - size.width / 2;\n\t\t\tbaseY = anchor.y + anchor.height + gap;\n\t\t\tbreak;\n\t}\n\n\t// Slide perpendicular to growth direction, alternating positive and negative steps (+1, -1, +2, -2...)\n\tconst isHorizontal = side === 'right' || side === 'left';\n\tconst step = (isHorizontal ? size.height : size.width) + 20;\n\n\tfor (let i = 0; i < maxAttempts; i++) {\n\t\tconst offset = i === 0 ? 0 : Math.ceil(i / 2) * step * (i % 2 === 1 ? 1 : -1);\n\t\tconst candidateBox: Rect = {\n\t\t\tx: isHorizontal ? baseX : baseX + offset,\n\t\t\ty: isHorizontal ? baseY + offset : baseY,\n\t\t\twidth: size.width,\n\t\t\theight: size.height\n\t\t};\n\n\t\tif (!obstacles.some((obstacle) => overlaps(candidateBox, obstacle, 8))) {\n\t\t\treturn {\n\t\t\t\tx: Math.round(candidateBox.x),\n\t\t\t\ty: Math.round(candidateBox.y)\n\t\t\t};\n\t\t}\n\t}\n\n\treturn {\n\t\tx: Math.round(baseX),\n\t\ty: Math.round(baseY)\n\t};\n}\n","import { ensureLayout, getLayoutedNodes, placeBeside } from '../canvas/layout.js';\nimport type { CanvasEdge, CanvasNode, Rect } from '../canvas/types.js';\nimport type { AgentCommand, AgentStep, EditorSnapshot } from './types.js';\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\n\t\t\tif (!pos) {\n\t\t\t\tif (command.nearNodeId) {\n\t\t\t\t\t// Use collision-aware directional placement\n\t\t\t\t\tconst rects: Record<string, Rect> = {};\n\t\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\t\trects[n.id] = {\n\t\t\t\t\t\t\tx: n.position.x,\n\t\t\t\t\t\t\ty: n.position.y,\n\t\t\t\t\t\t\twidth: n.measured?.width ?? (n as any).width ?? defaultNodeSize.width,\n\t\t\t\t\t\t\theight: n.measured?.height ?? (n as any).height ?? defaultNodeSize.height\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tpos = placeBeside(\n\t\t\t\t\t\trects,\n\t\t\t\t\t\tdefaultNodeSize,\n\t\t\t\t\t\tcommand.side ?? 'right',\n\t\t\t\t\t\tcommand.nearNodeId\n\t\t\t\t\t);\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\tconst rects: Record<string, Rect> = {};\n\t\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\t\trects[n.id] = {\n\t\t\t\t\t\t\tx: n.position.x,\n\t\t\t\t\t\t\ty: n.position.y,\n\t\t\t\t\t\t\twidth: n.measured?.width ?? (n as any).width ?? defaultNodeSize.width,\n\t\t\t\t\t\t\theight: n.measured?.height ?? (n as any).height ?? defaultNodeSize.height\n\t\t\t\t\t\t};\n\t\t\t\t\t}\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 (command.nearNodeId) {\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: command.nearNodeId,\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\tif (command.incremental) {\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\tdefault: {\n\t\t\treturn [];\n\t\t}\n\t}\n}\n","/**\n * Standard MCP Tool Definitions for @pixerate/editor.\n * Compatible with the Model Context Protocol (MCP) tool specification schema.\n */\n\nexport const MCP_TOOL_GET_EDITOR_STATE = {\n\tname: 'get_editor_state',\n\tdescription:\n\t\t'Retrieves the current state of the document, variables, selection, and canvas graph (nodes and edges).',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\tincludeDocument: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to include the prompt document text and variables (default: true).'\n\t\t\t},\n\t\t\tincludeCanvas: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to include the canvas nodes and edges (default: true).'\n\t\t\t}\n\t\t}\n\t}\n} as const;\n\nexport const MCP_TOOL_EDIT_CANVAS = {\n\tname: 'edit_canvas',\n\tdescription:\n\t\t'Applies high-level structural operations to the visual canvas (adding nodes, connecting edges, organizing layout, or moving elements).',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\toperation: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: [\n\t\t\t\t\t'add_node',\n\t\t\t\t\t'remove_nodes',\n\t\t\t\t\t'connect',\n\t\t\t\t\t'update_node',\n\t\t\t\t\t'layout',\n\t\t\t\t\t'select',\n\t\t\t\t\t'highlight'\n\t\t\t\t],\n\t\t\t\tdescription: 'The canvas operation to execute.'\n\t\t\t},\n\t\t\tnode: {\n\t\t\t\ttype: 'object',\n\t\t\t\tdescription: 'Node definition when operation is add_node. Can omit position to auto-place.'\n\t\t\t},\n\t\t\tnearNodeId: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Anchor node ID to position beside using collision-aware placement.'\n\t\t\t},\n\t\t\tside: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['top', 'right', 'bottom', 'left'],\n\t\t\t\tdescription: 'Side of the anchor node to place the new node beside.'\n\t\t\t},\n\t\t\tnodeIds: {\n\t\t\t\ttype: 'array',\n\t\t\t\titems: { type: 'string' },\n\t\t\t\tdescription: 'Array of node IDs for remove_nodes, select, or highlight.'\n\t\t\t},\n\t\t\tsource: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Source node ID for connect operation.'\n\t\t\t},\n\t\t\ttarget: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Target node ID for connect operation.'\n\t\t\t},\n\t\t\tlabel: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Optional edge label for connect operation.'\n\t\t\t},\n\t\t\tdirection: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['LR', 'TB', 'RL', 'BT'],\n\t\t\t\tdescription: 'Layout direction (default LR).'\n\t\t\t},\n\t\t\tincremental: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Preserve existing node coordinates and blend layout (default true).'\n\t\t\t}\n\t\t},\n\t\trequired: ['operation']\n\t}\n} as const;\n\nexport const MCP_TOOL_EDIT_PROMPT = {\n\tname: 'edit_prompt',\n\tdescription:\n\t\t'Applies edits to the prompt template document, including inserting text, replacing ranges, and setting variables.',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\toperation: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['insert_text', 'replace_range', 'set_variable', 'select'],\n\t\t\t\tdescription: 'The prompt operation to execute.'\n\t\t\t},\n\t\t\ttext: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Text to insert or replace.'\n\t\t\t},\n\t\t\tat: {\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'Position to insert text at.'\n\t\t\t},\n\t\t\tfrom: {\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'Start offset for replace_range or select.'\n\t\t\t},\n\t\t\tto: {\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'End offset for replace_range or select.'\n\t\t\t},\n\t\t\tname: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Variable name for set_variable.'\n\t\t\t},\n\t\t\tvalue: {\n\t\t\t\tdescription: 'Variable value for set_variable.'\n\t\t\t}\n\t\t},\n\t\trequired: ['operation']\n\t}\n} as const;\n\nexport const MCP_TOOL_VIEW_EDITOR = {\n\tname: 'view_editor',\n\tdescription:\n\t\t'Captures a visual image snapshot (JPEG or PNG) of the editor canvas or viewport for multimodal evaluation. Active agent cursor indicators are automatically excluded from the snapshot.',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\tscope: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['viewport', 'canvas'],\n\t\t\t\tdescription: 'Whether to capture only the visible viewport or the full canvas bounding box (default: viewport).'\n\t\t\t},\n\t\t\tformat: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['jpeg', 'png'],\n\t\t\t\tdescription: 'Image format of the base64 snapshot (default: jpeg).'\n\t\t\t},\n\t\t\tmaxEdge: {\n\t\t\t\ttype: 'integer',\n\t\t\t\tdescription: 'Maximum width or height dimension in pixels (default: 1024).'\n\t\t\t}\n\t\t}\n\t}\n} as const;\n\n/**\n * CSS selectors for ephemeral UI overlays (such as agent cursors, presence tags, and transient bubbles)\n * that should be excluded during canvas image export and visual snapshot generation.\n */\nexport const EXPORT_EXCLUDED_SELECTORS = [\n\t'.pixerate-presence',\n\t'.agent-presence',\n\t'.ursula-presence'\n] as const;\n\nexport const EDITOR_MCP_TOOLS = [\n\tMCP_TOOL_GET_EDITOR_STATE,\n\tMCP_TOOL_EDIT_CANVAS,\n\tMCP_TOOL_EDIT_PROMPT,\n\tMCP_TOOL_VIEW_EDITOR\n] as const;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;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QACN,aAAa;AAAA,MACd;AAAA,MACA,MAAM;AAAA,QACL,MAAM;AAAA,QACN,aAAa;AAAA,MACd;AAAA,MACA,IAAI;AAAA,QACH,MAAM;AAAA,QACN,aAAa;AAAA,MACd;AAAA,MACA,MAAM;AAAA,QACL,MAAM;AAAA,QACN,aAAa;AAAA,MACd;AAAA,MACA,OAAO;AAAA,QACN,aAAa;AAAA,MACd;AAAA,IACD;AAAA,IACA,UAAU,CAAC,WAAW;AAAA,EACvB;AACD;AAEO,IAAM,uBAAuB;AAAA,EACnC,MAAM;AAAA,EACN,aACC;AAAA,EACD,aAAa;AAAA,IACZ,MAAM;AAAA,IACN,YAAY;AAAA,MACX,OAAO;AAAA,QACN,MAAM;AAAA,QACN,MAAM,CAAC,YAAY,QAAQ;AAAA,QAC3B,aAAa;AAAA,MACd;AAAA,MACA,QAAQ;AAAA,QACP,MAAM;AAAA,QACN,MAAM,CAAC,QAAQ,KAAK;AAAA,QACpB,aAAa;AAAA,MACd;AAAA,MACA,SAAS;AAAA,QACR,MAAM;AAAA,QACN,aAAa;AAAA,MACd;AAAA,IACD;AAAA,EACD;AACD;AAMO,IAAM,4BAA4B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,mBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;","names":["dagre"]}
1
+ {"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/agent/index.cjs","../../src/agent/planner.ts","../../src/agent/tools.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACA;ACCO,SAAS,gBAAA,CAIf,OAAA,EACA,QAAA,EACA,QAAA,EAGI,CAAC,CAAA,EACuB;AAC5B,EAAA,MAAM,gBAAA,mBAAkB,OAAA,CAAQ,eAAA,UAAmB,EAAE,KAAA,EAAO,GAAA,EAAK,MAAA,EAAQ,GAAG,GAAA;AAC5E,EAAA,MAAM,MAAA,mBAAQ,OAAA,CAAQ,W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B,EAAA;AACD;AAEoC;AAC7B,EAAA;AAEL,EAAA;AACY,EAAA;AACN,IAAA;AACM,IAAA;AACJ,MAAA;AACA,QAAA;AACqB,QAAA;AACd,QAAA;AACd,MAAA;AACQ,MAAA;AACD,QAAA;AACc,QAAA;AACP,QAAA;AACd,MAAA;AACS,MAAA;AACF,QAAA;AACO,QAAA;AACd,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAMyC;AACxC,EAAA;AACA,EAAA;AACA,EAAA;AACD;AAEgC;AAC/B,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACD;AFiMiG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/agent/index.cjs","sourcesContent":[null,"import { ensureLayout, getLayoutedNodes, placeBeside } from '../canvas/layout.js';\nimport type { CanvasEdge, CanvasNode, Rect } from '../canvas/types.js';\nimport type { AgentCommand, AgentStep, EditorSnapshot } from './types.js';\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\n\t\t\tif (!pos) {\n\t\t\t\tif (command.nearNodeId) {\n\t\t\t\t\t// Use collision-aware directional placement\n\t\t\t\t\tconst rects: Record<string, Rect> = {};\n\t\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\t\trects[n.id] = {\n\t\t\t\t\t\t\tx: n.position.x,\n\t\t\t\t\t\t\ty: n.position.y,\n\t\t\t\t\t\t\twidth: n.measured?.width ?? (n as any).width ?? defaultNodeSize.width,\n\t\t\t\t\t\t\theight: n.measured?.height ?? (n as any).height ?? defaultNodeSize.height\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tpos = placeBeside(\n\t\t\t\t\t\trects,\n\t\t\t\t\t\tdefaultNodeSize,\n\t\t\t\t\t\tcommand.side ?? 'right',\n\t\t\t\t\t\tcommand.nearNodeId\n\t\t\t\t\t);\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\tconst rects: Record<string, Rect> = {};\n\t\t\t\t\tfor (const n of nodes) {\n\t\t\t\t\t\trects[n.id] = {\n\t\t\t\t\t\t\tx: n.position.x,\n\t\t\t\t\t\t\ty: n.position.y,\n\t\t\t\t\t\t\twidth: n.measured?.width ?? (n as any).width ?? defaultNodeSize.width,\n\t\t\t\t\t\t\theight: n.measured?.height ?? (n as any).height ?? defaultNodeSize.height\n\t\t\t\t\t\t};\n\t\t\t\t\t}\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 (command.nearNodeId) {\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: command.nearNodeId,\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\tif (command.incremental) {\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\tdefault: {\n\t\t\treturn [];\n\t\t}\n\t}\n}\n","/**\n * Standard MCP Tool Definitions for @pixerate/editor.\n * Compatible with the Model Context Protocol (MCP) tool specification schema.\n */\n\nexport const MCP_TOOL_GET_EDITOR_STATE = {\n\tname: 'get_editor_state',\n\tdescription:\n\t\t'Retrieves the current state of the document, variables, selection, and canvas graph (nodes and edges).',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\tincludeDocument: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to include the prompt document text and variables (default: true).'\n\t\t\t},\n\t\t\tincludeCanvas: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to include the canvas nodes and edges (default: true).'\n\t\t\t}\n\t\t}\n\t}\n} as const;\n\nexport const MCP_TOOL_EDIT_CANVAS = {\n\tname: 'edit_canvas',\n\tdescription:\n\t\t'Applies high-level structural operations to the visual canvas (adding nodes, connecting edges, organizing layout, or moving elements).',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\toperation: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: [\n\t\t\t\t\t'add_node',\n\t\t\t\t\t'remove_nodes',\n\t\t\t\t\t'connect',\n\t\t\t\t\t'update_node',\n\t\t\t\t\t'layout',\n\t\t\t\t\t'select',\n\t\t\t\t\t'highlight'\n\t\t\t\t],\n\t\t\t\tdescription: 'The canvas operation to execute.'\n\t\t\t},\n\t\t\tnode: {\n\t\t\t\ttype: 'object',\n\t\t\t\tdescription: 'Node definition when operation is add_node. Can omit position to auto-place.'\n\t\t\t},\n\t\t\tnearNodeId: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Anchor node ID to position beside using collision-aware placement.'\n\t\t\t},\n\t\t\tside: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['top', 'right', 'bottom', 'left'],\n\t\t\t\tdescription: 'Side of the anchor node to place the new node beside.'\n\t\t\t},\n\t\t\tnodeIds: {\n\t\t\t\ttype: 'array',\n\t\t\t\titems: { type: 'string' },\n\t\t\t\tdescription: 'Array of node IDs for remove_nodes, select, or highlight.'\n\t\t\t},\n\t\t\tsource: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Source node ID for connect operation.'\n\t\t\t},\n\t\t\ttarget: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Target node ID for connect operation.'\n\t\t\t},\n\t\t\tlabel: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Optional edge label for connect operation.'\n\t\t\t},\n\t\t\tdirection: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['LR', 'TB', 'RL', 'BT'],\n\t\t\t\tdescription: 'Layout direction (default LR).'\n\t\t\t},\n\t\t\tincremental: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Preserve existing node coordinates and blend layout (default true).'\n\t\t\t}\n\t\t},\n\t\trequired: ['operation']\n\t}\n} as const;\n\nexport const MCP_TOOL_EDIT_PROMPT = {\n\tname: 'edit_prompt',\n\tdescription:\n\t\t'Applies edits to the prompt template document, including inserting text, replacing ranges, and setting variables.',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\toperation: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['insert_text', 'replace_range', 'set_variable', 'select'],\n\t\t\t\tdescription: 'The prompt operation to execute.'\n\t\t\t},\n\t\t\ttext: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Text to insert or replace.'\n\t\t\t},\n\t\t\tat: {\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'Position to insert text at.'\n\t\t\t},\n\t\t\tfrom: {\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'Start offset for replace_range or select.'\n\t\t\t},\n\t\t\tto: {\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'End offset for replace_range or select.'\n\t\t\t},\n\t\t\tname: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Variable name for set_variable.'\n\t\t\t},\n\t\t\tvalue: {\n\t\t\t\tdescription: 'Variable value for set_variable.'\n\t\t\t}\n\t\t},\n\t\trequired: ['operation']\n\t}\n} as const;\n\nexport const MCP_TOOL_VIEW_EDITOR = {\n\tname: 'view_editor',\n\tdescription:\n\t\t'Captures a visual image snapshot (JPEG or PNG) of the editor canvas or viewport for multimodal evaluation. Active agent cursor indicators are automatically excluded from the snapshot.',\n\tinputSchema: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\tscope: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['viewport', 'canvas'],\n\t\t\t\tdescription: 'Whether to capture only the visible viewport or the full canvas bounding box (default: viewport).'\n\t\t\t},\n\t\t\tformat: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: ['jpeg', 'png'],\n\t\t\t\tdescription: 'Image format of the base64 snapshot (default: jpeg).'\n\t\t\t},\n\t\t\tmaxEdge: {\n\t\t\t\ttype: 'integer',\n\t\t\t\tdescription: 'Maximum width or height dimension in pixels (default: 1024).'\n\t\t\t}\n\t\t}\n\t}\n} as const;\n\n/**\n * CSS selectors for ephemeral UI overlays (such as agent cursors, presence tags, and transient bubbles)\n * that should be excluded during canvas image export and visual snapshot generation.\n */\nexport const EXPORT_EXCLUDED_SELECTORS = [\n\t'.pixerate-presence',\n\t'.agent-presence',\n\t'.ursula-presence'\n] as const;\n\nexport const EDITOR_MCP_TOOLS = [\n\tMCP_TOOL_GET_EDITOR_STATE,\n\tMCP_TOOL_EDIT_CANVAS,\n\tMCP_TOOL_EDIT_PROMPT,\n\tMCP_TOOL_VIEW_EDITOR\n] as const;\n\n"]}
@@ -1,4 +1,4 @@
1
- import { d as CanvasNode, b as CanvasEdge, X as XYPosition, S as Side } from '../types-lGtRobRV.cjs';
1
+ import { C as CanvasNode, a as CanvasEdge, X as XYPosition, S as Side } from '../types-DC8b2TsA.cjs';
2
2
 
3
3
  /**
4
4
  * Agent presence state for visual multiplayer/agent choreography.
@@ -1,4 +1,4 @@
1
- import { d as CanvasNode, b as CanvasEdge, X as XYPosition, S as Side } from '../types-lGtRobRV.js';
1
+ import { C as CanvasNode, a as CanvasEdge, X as XYPosition, S as Side } from '../types-DC8b2TsA.js';
2
2
 
3
3
  /**
4
4
  * Agent presence state for visual multiplayer/agent choreography.
@@ -1,157 +1,8 @@
1
- // src/canvas/layout.ts
2
- import dagre from "@dagrejs/dagre";
3
- var DEFAULT_NODE_WIDTH = 200;
4
- var DEFAULT_NODE_HEIGHT = 60;
5
- var DEFAULT_PLACEMENT_GAP = 48;
6
- function getLayoutedNodes(nodes, edges, getNodesBounds, options = {}) {
7
- if (nodes.length === 0) return [];
8
- const {
9
- direction = "LR",
10
- ranksep = 100,
11
- nodesep = 25,
12
- defaultNodeWidth = DEFAULT_NODE_WIDTH,
13
- defaultNodeHeight = DEFAULT_NODE_HEIGHT
14
- } = options;
15
- const dagreGraph = new dagre.graphlib.Graph();
16
- dagreGraph.setDefaultEdgeLabel(() => ({}));
17
- dagreGraph.setGraph({ rankdir: direction, ranksep, nodesep });
18
- const nodeIds = new Set(nodes.map((node) => node.id));
19
- nodes.forEach((node) => {
20
- const nodeWidth = node.measured?.width ?? node.width ?? defaultNodeWidth;
21
- const nodeHeight = node.measured?.height ?? node.height ?? defaultNodeHeight;
22
- dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });
23
- });
24
- edges.forEach((edge) => {
25
- if (nodeIds.has(edge.source) && nodeIds.has(edge.target)) {
26
- dagreGraph.setEdge(edge.source, edge.target);
27
- }
28
- });
29
- dagre.layout(dagreGraph);
30
- return nodes.map((node) => {
31
- const nodeWithPosition = dagreGraph.node(node.id);
32
- const nodeWidth = node.measured?.width ?? node.width ?? defaultNodeWidth;
33
- const nodeHeight = node.measured?.height ?? node.height ?? defaultNodeHeight;
34
- return {
35
- ...node,
36
- position: {
37
- x: nodeWithPosition.x - nodeWidth / 2,
38
- y: nodeWithPosition.y - nodeHeight / 2
39
- }
40
- };
41
- });
42
- }
43
- function boundsOf(rects) {
44
- if (!rects.length) return null;
45
- const minX = Math.min(...rects.map((r) => r.x));
46
- const minY = Math.min(...rects.map((r) => r.y));
47
- const maxX = Math.max(...rects.map((r) => r.x + r.width));
48
- const maxY = Math.max(...rects.map((r) => r.y + r.height));
49
- return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
50
- }
51
- function centre(r) {
52
- return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
53
- }
54
- function overlaps(a, b, pad = 16) {
55
- return a.x < b.x + b.width + pad && a.x + a.width + pad > b.x && a.y < b.y + b.height + pad && a.y + a.height + pad > b.y;
56
- }
57
- function ensureLayout(nodes, edges, options = {}) {
58
- if (nodes.length === 0) return [];
59
- const stored = options.storedPositions ?? {};
60
- const missing = nodes.filter((n) => !stored[n.id]);
61
- if (missing.length === 0) {
62
- return nodes.map((n) => ({
63
- ...n,
64
- position: { ...stored[n.id] }
65
- }));
66
- }
67
- const autoLayouted = getLayoutedNodes(nodes, edges, void 0, options);
68
- const autoMap = new Map(
69
- autoLayouted.map((n) => [n.id, n.position])
70
- );
71
- const both = nodes.filter((n) => stored[n.id] && autoMap.has(n.id));
72
- if (both.length === 0) {
73
- return autoLayouted;
74
- }
75
- let dx = 0;
76
- let dy = 0;
77
- for (const n of both) {
78
- const s = stored[n.id];
79
- const a = autoMap.get(n.id);
80
- dx += s.x - a.x;
81
- dy += s.y - a.y;
82
- }
83
- dx /= both.length;
84
- dy /= both.length;
85
- return nodes.map((node) => {
86
- if (stored[node.id]) {
87
- return {
88
- ...node,
89
- position: { ...stored[node.id] }
90
- };
91
- }
92
- const autoPos = autoMap.get(node.id) ?? { x: 0, y: 0 };
93
- return {
94
- ...node,
95
- position: {
96
- x: Math.round(autoPos.x + dx),
97
- y: Math.round(autoPos.y + dy)
98
- }
99
- };
100
- });
101
- }
102
- function placeBeside(rects, size, side, nearNodeId, options = {}) {
103
- const {
104
- gap = DEFAULT_PLACEMENT_GAP,
105
- ignore = [],
106
- maxAttempts = 32
107
- } = options;
108
- const skip = new Set([nearNodeId, ...ignore].filter(Boolean));
109
- const obstacles = Object.entries(rects).filter(([id]) => !skip.has(id)).map(([, r]) => r);
110
- const anchor = nearNodeId && rects[nearNodeId] || boundsOf(Object.values(rects)) || { x: 0, y: 0, width: 0, height: 0 };
111
- const anchorCenter = centre(anchor);
112
- let baseX;
113
- let baseY;
114
- switch (side) {
115
- case "right":
116
- baseX = anchor.x + anchor.width + gap;
117
- baseY = anchorCenter.y - size.height / 2;
118
- break;
119
- case "left":
120
- baseX = anchor.x - gap - size.width;
121
- baseY = anchorCenter.y - size.height / 2;
122
- break;
123
- case "above":
124
- baseX = anchorCenter.x - size.width / 2;
125
- baseY = anchor.y - gap - size.height;
126
- break;
127
- case "below":
128
- default:
129
- baseX = anchorCenter.x - size.width / 2;
130
- baseY = anchor.y + anchor.height + gap;
131
- break;
132
- }
133
- const isHorizontal = side === "right" || side === "left";
134
- const step = (isHorizontal ? size.height : size.width) + 20;
135
- for (let i = 0; i < maxAttempts; i++) {
136
- const offset = i === 0 ? 0 : Math.ceil(i / 2) * step * (i % 2 === 1 ? 1 : -1);
137
- const candidateBox = {
138
- x: isHorizontal ? baseX : baseX + offset,
139
- y: isHorizontal ? baseY + offset : baseY,
140
- width: size.width,
141
- height: size.height
142
- };
143
- if (!obstacles.some((obstacle) => overlaps(candidateBox, obstacle, 8))) {
144
- return {
145
- x: Math.round(candidateBox.x),
146
- y: Math.round(candidateBox.y)
147
- };
148
- }
149
- }
150
- return {
151
- x: Math.round(baseX),
152
- y: Math.round(baseY)
153
- };
154
- }
1
+ import {
2
+ ensureLayout,
3
+ getLayoutedNodes,
4
+ placeBeside
5
+ } from "../chunk-VHZCXHS4.js";
155
6
 
156
7
  // src/agent/planner.ts
157
8
  function planAgentCommand(command, snapshot, options = {}) {