@tangle-network/agent-app 0.12.0 → 0.14.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 (41) hide show
  1. package/dist/DesignCanvas-3JEEIT6Y.js +10 -0
  2. package/dist/DesignCanvas-3JEEIT6Y.js.map +1 -0
  3. package/dist/DesignCanvasEditor-37LPJIIR.js +9 -0
  4. package/dist/DesignCanvasEditor-37LPJIIR.js.map +1 -0
  5. package/dist/chunk-2Q73HGDI.js +1743 -0
  6. package/dist/chunk-2Q73HGDI.js.map +1 -0
  7. package/dist/{chunk-3WAJWYKD.js → chunk-6UOE5CTA.js} +9 -92
  8. package/dist/{chunk-3WAJWYKD.js.map → chunk-6UOE5CTA.js.map} +1 -1
  9. package/dist/chunk-7QCIYDGC.js +1119 -0
  10. package/dist/chunk-7QCIYDGC.js.map +1 -0
  11. package/dist/chunk-A76ZHWNF.js +194 -0
  12. package/dist/chunk-A76ZHWNF.js.map +1 -0
  13. package/dist/chunk-F5KTWRO7.js +2276 -0
  14. package/dist/chunk-F5KTWRO7.js.map +1 -0
  15. package/dist/chunk-JZAJE3JL.js +990 -0
  16. package/dist/chunk-JZAJE3JL.js.map +1 -0
  17. package/dist/{chunk-CF5DZELC.js → chunk-SSX2A6XX.js} +39 -2
  18. package/dist/chunk-SSX2A6XX.js.map +1 -0
  19. package/dist/design-canvas/drizzle.d.ts +569 -0
  20. package/dist/design-canvas/drizzle.js +183 -0
  21. package/dist/design-canvas/drizzle.js.map +1 -0
  22. package/dist/design-canvas/index.d.ts +261 -0
  23. package/dist/design-canvas/index.js +96 -0
  24. package/dist/design-canvas/index.js.map +1 -0
  25. package/dist/design-canvas-react/index.d.ts +916 -0
  26. package/dist/design-canvas-react/index.js +423 -0
  27. package/dist/design-canvas-react/index.js.map +1 -0
  28. package/dist/export-presets-Dl5Aa5xj.d.ts +284 -0
  29. package/dist/index.d.ts +6 -1
  30. package/dist/index.js +103 -3
  31. package/dist/mcp-rpc-DLw_r9PQ.d.ts +55 -0
  32. package/dist/model-BHLN208Z.d.ts +183 -0
  33. package/dist/sequences/index.d.ts +4 -0
  34. package/dist/sequences/index.js +2 -2
  35. package/dist/store-CUStmtdH.d.ts +64 -0
  36. package/dist/tools/index.d.ts +64 -2
  37. package/dist/tools/index.js +10 -2
  38. package/package.json +28 -3
  39. package/dist/chunk-CF5DZELC.js.map +0 -1
  40. package/dist/chunk-IJZJWKUK.js +0 -77
  41. package/dist/chunk-IJZJWKUK.js.map +0 -1
@@ -0,0 +1,1119 @@
1
+ import {
2
+ SCENE_ELEMENT_KINDS,
3
+ SCENE_SCHEMA_VERSION,
4
+ collectSlots,
5
+ elementAabb,
6
+ requirePage,
7
+ storeApplyScenePlan
8
+ } from "./chunk-JZAJE3JL.js";
9
+ import {
10
+ DEFAULT_HEADER_NAMES,
11
+ buildHttpMcpServer,
12
+ createMcpToolHandler
13
+ } from "./chunk-A76ZHWNF.js";
14
+
15
+ // src/design-canvas/operations.ts
16
+ var SCENE_OPERATION_TYPES = [
17
+ "add_element",
18
+ "set_attrs",
19
+ "reorder_element",
20
+ "delete_element",
21
+ "group_elements",
22
+ "ungroup_element",
23
+ "add_page",
24
+ "duplicate_page",
25
+ "delete_page",
26
+ "reorder_page",
27
+ "set_page_props",
28
+ "set_page_guides",
29
+ "bind_slot",
30
+ "apply_data",
31
+ "set_document_title"
32
+ ];
33
+
34
+ // src/design-canvas/templates.ts
35
+ function listTemplateSlots(document) {
36
+ const raw = collectSlots(document);
37
+ const slots = [];
38
+ for (const [name, { pageId, elementId, kind }] of raw) {
39
+ slots.push({ name, pageId, elementId, elementKind: kind, fillKind: fillKindForElementKind(kind) });
40
+ }
41
+ return slots;
42
+ }
43
+ function fillKindForElementKind(kind) {
44
+ switch (kind) {
45
+ case "text":
46
+ return "text";
47
+ case "image":
48
+ case "video":
49
+ return "src";
50
+ case "rect":
51
+ case "ellipse":
52
+ return "color";
53
+ case "line":
54
+ case "group":
55
+ throw new Error(
56
+ `slot on "${kind}" element has no defined fill kind \u2014 bind_slot should not target line or group elements`
57
+ );
58
+ }
59
+ }
60
+ function validateBindings(document, bindings) {
61
+ const slots = collectSlots(document);
62
+ const problems = [];
63
+ for (const key of Object.keys(bindings)) {
64
+ if (!slots.has(key)) {
65
+ problems.push(`binding key "${key}" does not match any slot in the document`);
66
+ }
67
+ }
68
+ return problems;
69
+ }
70
+ function instantiateTemplate(document, options) {
71
+ const bindings = options.bindings ?? {};
72
+ const problems = validateBindings(document, bindings);
73
+ if (problems.length > 0) {
74
+ throw new Error(`template bindings are invalid:
75
+ ${problems.map((p) => ` - ${p}`).join("\n")}`);
76
+ }
77
+ const idMap = /* @__PURE__ */ new Map();
78
+ const allocate = (sourceId) => {
79
+ if (idMap.has(sourceId)) return idMap.get(sourceId);
80
+ const minted = options.mintId(sourceId);
81
+ idMap.set(sourceId, minted);
82
+ return minted;
83
+ };
84
+ for (const page of document.pages) {
85
+ allocate(page.id);
86
+ collectElementIds(page.elements, allocate);
87
+ }
88
+ const newPages = document.pages.map((page) => ({
89
+ ...page,
90
+ id: idMap.get(page.id),
91
+ elements: copyElements(page.elements, idMap)
92
+ }));
93
+ const newDocument = {
94
+ schemaVersion: SCENE_SCHEMA_VERSION,
95
+ title: options.title,
96
+ pages: newPages,
97
+ settings: { ...document.settings },
98
+ metadata: {
99
+ ...document.metadata,
100
+ templateSourceId: document.title
101
+ }
102
+ };
103
+ return Object.keys(bindings).length > 0 ? applyBindings(newDocument, bindings) : newDocument;
104
+ }
105
+ function applyBindingsToDocument(document, bindings) {
106
+ const problems = validateBindings(document, bindings);
107
+ if (problems.length > 0) {
108
+ throw new Error(`apply_data bindings are invalid:
109
+ ${problems.map((p) => ` - ${p}`).join("\n")}`);
110
+ }
111
+ return applyBindings(document, bindings);
112
+ }
113
+ function applyBindings(document, bindings) {
114
+ const slots = collectSlots(document);
115
+ const targetMap = /* @__PURE__ */ new Map();
116
+ for (const [slotName, { elementId }] of slots) {
117
+ const value = bindings[slotName];
118
+ if (value !== void 0) {
119
+ targetMap.set(elementId, { slotName, value });
120
+ }
121
+ }
122
+ const newPages = document.pages.map((page) => ({
123
+ ...page,
124
+ elements: applyBindingsToElements(page.elements, targetMap)
125
+ }));
126
+ return { ...document, pages: newPages };
127
+ }
128
+ function applyBindingsToElements(elements, targetMap) {
129
+ return elements.map((element) => {
130
+ const target = targetMap.get(element.id);
131
+ let updated = element;
132
+ if (target !== void 0) {
133
+ updated = applyBindingToElement(element, target.value, target.slotName);
134
+ }
135
+ if (updated.kind === "group") {
136
+ return { ...updated, children: applyBindingsToElements(updated.children, targetMap) };
137
+ }
138
+ return updated;
139
+ });
140
+ }
141
+ function applyBindingToElement(element, value, slotName) {
142
+ switch (element.kind) {
143
+ case "text":
144
+ return { ...element, text: value };
145
+ case "image":
146
+ return { ...element, src: value };
147
+ case "video":
148
+ return { ...element, src: value };
149
+ case "rect":
150
+ return { ...element, fill: value };
151
+ case "ellipse":
152
+ return { ...element, fill: value };
153
+ case "line":
154
+ case "group":
155
+ throw new Error(
156
+ `slot "${slotName}" on "${element.kind}" element cannot accept a binding \u2014 remove the slot or use a supported element kind`
157
+ );
158
+ }
159
+ }
160
+ function collectElementIds(elements, allocate) {
161
+ for (const element of elements) {
162
+ allocate(element.id);
163
+ if (element.kind === "group") collectElementIds(element.children, allocate);
164
+ }
165
+ }
166
+ function copyElements(elements, idMap) {
167
+ return elements.map((element) => copyElement(element, idMap));
168
+ }
169
+ function copyElement(element, idMap) {
170
+ const newId = idMap.get(element.id);
171
+ if (newId === void 0) throw new Error(`element ${element.id} was not pre-allocated in the id map \u2014 this is a bug in instantiateTemplate`);
172
+ const base = { ...element, id: newId };
173
+ if (base.kind === "group") {
174
+ return { ...base, children: copyElements(base.children, idMap) };
175
+ }
176
+ return base;
177
+ }
178
+
179
+ // src/design-canvas/mcp-tools.ts
180
+ function isRecord(value) {
181
+ return typeof value === "object" && value !== null && !Array.isArray(value);
182
+ }
183
+ function requireString(args, name) {
184
+ const value = args[name];
185
+ if (typeof value !== "string" || value.trim().length === 0) {
186
+ throw new Error(`${name} is required and must be a non-empty string`);
187
+ }
188
+ return value;
189
+ }
190
+ function optionalString(args, name) {
191
+ const value = args[name];
192
+ if (value === void 0 || value === null) return void 0;
193
+ if (typeof value !== "string") throw new Error(`${name} must be a string when provided`);
194
+ return value;
195
+ }
196
+ function requireNumber(args, name) {
197
+ const value = args[name];
198
+ if (typeof value !== "number" || !Number.isFinite(value)) {
199
+ throw new Error(`${name} is required and must be a finite number`);
200
+ }
201
+ return value;
202
+ }
203
+ function optionalNumber(args, name) {
204
+ const value = args[name];
205
+ if (value === void 0 || value === null) return void 0;
206
+ if (typeof value !== "number" || !Number.isFinite(value)) {
207
+ throw new Error(`${name} must be a finite number when provided`);
208
+ }
209
+ return value;
210
+ }
211
+ function optionalNonNegativeInteger(args, name) {
212
+ const value = args[name];
213
+ if (value === void 0 || value === null) return void 0;
214
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
215
+ throw new Error(`${name} must be a non-negative integer when provided`);
216
+ }
217
+ return value;
218
+ }
219
+ function requireStringArray(args, name) {
220
+ const value = args[name];
221
+ if (!Array.isArray(value) || value.length === 0 || value.some((v) => typeof v !== "string")) {
222
+ throw new Error(`${name} is required and must be a non-empty array of strings`);
223
+ }
224
+ return value;
225
+ }
226
+ function optionalRecord(args, name) {
227
+ const value = args[name];
228
+ if (value === void 0 || value === null) return void 0;
229
+ if (!isRecord(value) || Object.values(value).some((v) => typeof v !== "string")) {
230
+ throw new Error(`${name} must be an object mapping string keys to string values when provided`);
231
+ }
232
+ return value;
233
+ }
234
+ function requireEnum(args, name, values) {
235
+ const value = args[name];
236
+ if (typeof value !== "string" || !values.includes(value)) {
237
+ throw new Error(`${name} must be one of: ${values.join(", ")}`);
238
+ }
239
+ return value;
240
+ }
241
+ function optionalEnum(args, name, values) {
242
+ const value = args[name];
243
+ if (value === void 0 || value === null) return void 0;
244
+ return requireEnum(args, name, values);
245
+ }
246
+ function resolvePageId(document, args) {
247
+ const pageId = optionalString(args, "page_id");
248
+ if (pageId) {
249
+ requirePage(document, pageId);
250
+ return pageId;
251
+ }
252
+ const first = document.pages[0];
253
+ if (!first) throw new Error("document has no pages");
254
+ return first.id;
255
+ }
256
+ function elementAabbRecord(el) {
257
+ const aabb = elementAabb(el);
258
+ return { x: aabb.x, y: aabb.y, width: aabb.width, height: aabb.height };
259
+ }
260
+ function pageSnapshot(page) {
261
+ return {
262
+ id: page.id,
263
+ name: page.name,
264
+ width: page.width,
265
+ height: page.height,
266
+ background: page.background,
267
+ bleed: page.bleed,
268
+ element_count: page.elements.length,
269
+ elements: page.elements.map((el) => ({
270
+ id: el.id,
271
+ kind: el.kind,
272
+ name: el.name,
273
+ aabb: elementAabbRecord(el),
274
+ rotation: el.rotation,
275
+ opacity: el.opacity,
276
+ locked: el.locked,
277
+ visible: el.visible,
278
+ ...el.slot ? { slot: el.slot } : {}
279
+ }))
280
+ };
281
+ }
282
+ async function applyPlan(store, mintId, summary, operations) {
283
+ const plan = { summary, operations };
284
+ const { record } = await storeApplyScenePlan(store, plan, { actorKind: "agent_edit", mintId });
285
+ return { rev: record.rev, operation_count: operations.length };
286
+ }
287
+ function collectPageSlotAttrs(page) {
288
+ const slots = /* @__PURE__ */ new Map();
289
+ const stack = [...page.elements];
290
+ while (stack.length > 0) {
291
+ const el = stack.pop();
292
+ if (el.slot) {
293
+ if (slots.has(el.slot)) {
294
+ throw new Error(`duplicate slot name "${el.slot}" on page ${page.id}`);
295
+ }
296
+ slots.set(el.slot, { elementId: el.id, kind: el.kind });
297
+ }
298
+ if (el.kind === "group") stack.push(...el.children);
299
+ }
300
+ return slots;
301
+ }
302
+ function objectSchema(properties, required) {
303
+ return { type: "object", properties, required, additionalProperties: false };
304
+ }
305
+ var pageIdProp = { type: "string", description: "Page id to target. Omit to target the first page." };
306
+ var elementIdProp = { type: "string", description: "Element id to target." };
307
+ var xProp = { type: "number", description: "X position in page coordinates (px)." };
308
+ var yProp = { type: "number", description: "Y position in page coordinates (px)." };
309
+ var widthProp = { type: "number", description: "Width in px (must be > 0)." };
310
+ var heightProp = { type: "number", description: "Height in px (must be > 0)." };
311
+ var colorProp = (label) => ({ type: "string", description: `${label} \u2014 hex (#rrggbb), rgb(), rgba(), or "transparent".` });
312
+ var CANVAS_MCP_TOOLS = [
313
+ // ─── read ────────────────────────────────────────────────────────────────
314
+ {
315
+ name: "get_scene_state",
316
+ description: "Read the full scene document: title, settings, all pages with dimensions and background, and every element with its axis-aligned bounding box (so you can reason about layout and overlap without rendering). Call this before editing to get real page and element ids.",
317
+ inputSchema: objectSchema({}, []),
318
+ async run(_args, env) {
319
+ const { document, rev } = await env.store.getDocument();
320
+ return {
321
+ rev,
322
+ title: document.title,
323
+ schema_version: document.schemaVersion,
324
+ settings: document.settings,
325
+ pages: document.pages.map(pageSnapshot)
326
+ };
327
+ }
328
+ },
329
+ {
330
+ name: "describe_page",
331
+ description: "Read one page in detail: name, dimensions, background, bleed, guides, and every element with geometry, attributes, and slot bindings. Use this when you need attribute values (fill, font, src) the compact get_scene_state summary omits.",
332
+ inputSchema: objectSchema(
333
+ { page_id: pageIdProp },
334
+ ["page_id"]
335
+ ),
336
+ async run(args, env) {
337
+ const pageId = requireString(args, "page_id");
338
+ const { document, rev } = await env.store.getDocument();
339
+ const page = requirePage(document, pageId);
340
+ return {
341
+ rev,
342
+ id: page.id,
343
+ name: page.name,
344
+ width: page.width,
345
+ height: page.height,
346
+ background: page.background,
347
+ bleed: page.bleed,
348
+ guides: page.guides,
349
+ elements: page.elements.map((el) => ({ ...el, aabb: elementAabbRecord(el) }))
350
+ };
351
+ }
352
+ },
353
+ {
354
+ name: "list_decisions",
355
+ description: "List recent agent decisions recorded against this document. Useful to audit what the agent has already done this session.",
356
+ inputSchema: objectSchema(
357
+ { limit: { type: "number", description: "Max decisions to return (default 20, max 100)." } },
358
+ []
359
+ ),
360
+ async run(args, env) {
361
+ const limitRaw = optionalNumber(args, "limit") ?? 20;
362
+ const limit = Math.min(100, Math.max(1, Math.round(limitRaw)));
363
+ const decisions = await env.store.listDecisions(limit);
364
+ return { decisions };
365
+ }
366
+ },
367
+ // ─── add convenience wrappers ─────────────────────────────────────────────
368
+ {
369
+ name: "add_text",
370
+ description: "Place a text element on a page. The element id is minted server-side and returned. x/y are the top-left in page coordinates (px). width sets the wrap column; height derives from content at render time.",
371
+ inputSchema: objectSchema(
372
+ {
373
+ page_id: pageIdProp,
374
+ text: { type: "string", description: "Initial text content." },
375
+ x: xProp,
376
+ y: yProp,
377
+ width: widthProp,
378
+ font_size: { type: "number", description: "Font size in px (must be > 0). Default 24." },
379
+ font_family: { type: "string", description: 'CSS font family. Default "Inter".' },
380
+ font_style: { type: "string", enum: ["normal", "bold", "italic", "bold italic"], description: 'Default "normal".' },
381
+ fill: colorProp('Text color. Default "#000000".'),
382
+ align: { type: "string", enum: ["left", "center", "right"], description: 'Default "left".' },
383
+ line_height: { type: "number", description: "Line height multiplier. Default 1.2." },
384
+ letter_spacing: { type: "number", description: "Letter spacing in px. Default 0." },
385
+ name: { type: "string", description: "Layer name. Defaults to the first 32 chars of text." },
386
+ slot: { type: "string", description: "Template slot name \u2014 allows apply_data to replace this text programmatically." }
387
+ },
388
+ ["text", "x", "y", "width"]
389
+ ),
390
+ async run(args, env) {
391
+ const { document } = await env.store.getDocument();
392
+ const pageId = resolvePageId(document, args);
393
+ const id = env.mintId();
394
+ const text = requireString(args, "text");
395
+ const element = {
396
+ id,
397
+ kind: "text",
398
+ name: optionalString(args, "name") ?? text.slice(0, 32),
399
+ x: requireNumber(args, "x"),
400
+ y: requireNumber(args, "y"),
401
+ width: requireNumber(args, "width"),
402
+ text,
403
+ fontFamily: optionalString(args, "font_family") ?? "Inter",
404
+ fontSize: optionalNumber(args, "font_size") ?? 24,
405
+ fontStyle: optionalEnum(args, "font_style", ["normal", "bold", "italic", "bold italic"]) ?? "normal",
406
+ fill: optionalString(args, "fill") ?? "#000000",
407
+ align: optionalEnum(args, "align", ["left", "center", "right"]) ?? "left",
408
+ lineHeight: optionalNumber(args, "line_height") ?? 1.2,
409
+ letterSpacing: optionalNumber(args, "letter_spacing") ?? 0,
410
+ rotation: 0,
411
+ opacity: 1,
412
+ locked: false,
413
+ visible: true,
414
+ ...(() => {
415
+ const s = optionalString(args, "slot");
416
+ return s ? { slot: s } : {};
417
+ })()
418
+ };
419
+ const result = await applyPlan(env.store, env.mintId, `add text "${text.slice(0, 40)}"`, [
420
+ { type: "add_element", pageId, element }
421
+ ]);
422
+ return { element_id: id, ...result };
423
+ }
424
+ },
425
+ {
426
+ name: "add_image",
427
+ description: "Place an image element on a page. src must be an http(s) URL or a rooted /api/ path \u2014 never a data: blob. The element id is minted server-side and returned.",
428
+ inputSchema: objectSchema(
429
+ {
430
+ page_id: pageIdProp,
431
+ src: { type: "string", description: "Image URL (https://...) or /api/ path." },
432
+ x: xProp,
433
+ y: yProp,
434
+ width: widthProp,
435
+ height: heightProp,
436
+ fit: { type: "string", enum: ["fill", "cover", "contain"], description: 'How the source maps into the frame. Default "cover".' },
437
+ name: { type: "string", description: 'Layer name. Default "Image".' },
438
+ slot: { type: "string", description: "Template slot name \u2014 allows apply_data to swap this image's src." }
439
+ },
440
+ ["src", "x", "y", "width", "height"]
441
+ ),
442
+ async run(args, env) {
443
+ const { document } = await env.store.getDocument();
444
+ const pageId = resolvePageId(document, args);
445
+ const id = env.mintId();
446
+ const element = {
447
+ id,
448
+ kind: "image",
449
+ name: optionalString(args, "name") ?? "Image",
450
+ x: requireNumber(args, "x"),
451
+ y: requireNumber(args, "y"),
452
+ width: requireNumber(args, "width"),
453
+ height: requireNumber(args, "height"),
454
+ src: requireString(args, "src"),
455
+ fit: optionalEnum(args, "fit", ["fill", "cover", "contain"]) ?? "cover",
456
+ rotation: 0,
457
+ opacity: 1,
458
+ locked: false,
459
+ visible: true,
460
+ ...(() => {
461
+ const s = optionalString(args, "slot");
462
+ return s ? { slot: s } : {};
463
+ })()
464
+ };
465
+ const result = await applyPlan(env.store, env.mintId, "add image element", [
466
+ { type: "add_element", pageId, element }
467
+ ]);
468
+ return { element_id: id, ...result };
469
+ }
470
+ },
471
+ {
472
+ name: "add_shape",
473
+ description: 'Place a geometric shape on a page. kind must be "rect", "ellipse", or "line". For line: provide points as a flat [x0,y0,x1,y1,...] array (relative to x,y); for rect/ellipse: provide width and height.',
474
+ inputSchema: objectSchema(
475
+ {
476
+ page_id: pageIdProp,
477
+ kind: { type: "string", enum: ["rect", "ellipse", "line"], description: "Shape type." },
478
+ x: xProp,
479
+ y: yProp,
480
+ width: { type: "number", description: "Width in px (required for rect and ellipse)." },
481
+ height: { type: "number", description: "Height in px (required for rect and ellipse)." },
482
+ fill: colorProp('Fill color (rect/ellipse). Default "#cccccc".'),
483
+ stroke: colorProp("Stroke/line color."),
484
+ stroke_width: { type: "number", description: "Stroke width in px." },
485
+ corner_radius: { type: "number", description: "Corner radius in px (rect only)." },
486
+ points: {
487
+ type: "array",
488
+ items: { type: "number" },
489
+ description: 'Flat [x0,y0,x1,y1,...] array for lines, relative to (x,y). Required for kind="line".'
490
+ },
491
+ name: { type: "string", description: "Layer name." }
492
+ },
493
+ ["kind", "x", "y"]
494
+ ),
495
+ async run(args, env) {
496
+ const { document } = await env.store.getDocument();
497
+ const pageId = resolvePageId(document, args);
498
+ const id = env.mintId();
499
+ const kind = requireEnum(args, "kind", ["rect", "ellipse", "line"]);
500
+ const x = requireNumber(args, "x");
501
+ const y = requireNumber(args, "y");
502
+ let element;
503
+ if (kind === "rect") {
504
+ const rect = {
505
+ id,
506
+ kind,
507
+ x,
508
+ y,
509
+ name: optionalString(args, "name") ?? "Rectangle",
510
+ width: requireNumber(args, "width"),
511
+ height: requireNumber(args, "height"),
512
+ fill: optionalString(args, "fill") ?? "#cccccc",
513
+ rotation: 0,
514
+ opacity: 1,
515
+ locked: false,
516
+ visible: true,
517
+ ...optionalString(args, "stroke") ? { stroke: optionalString(args, "stroke") } : {},
518
+ ...optionalNumber(args, "stroke_width") !== void 0 ? { strokeWidth: optionalNumber(args, "stroke_width") } : {},
519
+ ...optionalNumber(args, "corner_radius") !== void 0 ? { cornerRadius: optionalNumber(args, "corner_radius") } : {}
520
+ };
521
+ element = rect;
522
+ } else if (kind === "ellipse") {
523
+ const ellipse = {
524
+ id,
525
+ kind,
526
+ x,
527
+ y,
528
+ name: optionalString(args, "name") ?? "Ellipse",
529
+ width: requireNumber(args, "width"),
530
+ height: requireNumber(args, "height"),
531
+ fill: optionalString(args, "fill") ?? "#cccccc",
532
+ rotation: 0,
533
+ opacity: 1,
534
+ locked: false,
535
+ visible: true,
536
+ ...optionalString(args, "stroke") ? { stroke: optionalString(args, "stroke") } : {},
537
+ ...optionalNumber(args, "stroke_width") !== void 0 ? { strokeWidth: optionalNumber(args, "stroke_width") } : {}
538
+ };
539
+ element = ellipse;
540
+ } else {
541
+ const rawPoints = args["points"];
542
+ if (!Array.isArray(rawPoints) || rawPoints.length < 4 || rawPoints.length % 2 !== 0) {
543
+ throw new Error('points is required for kind="line" and must be a flat [x0,y0,...] array with \u2265 2 points');
544
+ }
545
+ const points = rawPoints;
546
+ const line = {
547
+ id,
548
+ kind,
549
+ x,
550
+ y,
551
+ points,
552
+ name: optionalString(args, "name") ?? "Line",
553
+ stroke: optionalString(args, "stroke") ?? "#000000",
554
+ strokeWidth: optionalNumber(args, "stroke_width") ?? 2,
555
+ rotation: 0,
556
+ opacity: 1,
557
+ locked: false,
558
+ visible: true
559
+ };
560
+ element = line;
561
+ }
562
+ const result = await applyPlan(env.store, env.mintId, `add ${kind} shape`, [
563
+ { type: "add_element", pageId, element }
564
+ ]);
565
+ return { element_id: id, ...result };
566
+ }
567
+ },
568
+ {
569
+ name: "add_video",
570
+ description: "Place a video element on a page. Video renders and exports as its poster frame \u2014 motion belongs to the sequences surface. src must be an http(s) URL or /api/ path.",
571
+ inputSchema: objectSchema(
572
+ {
573
+ page_id: pageIdProp,
574
+ src: { type: "string", description: "Video URL (https://...) or /api/ path." },
575
+ x: xProp,
576
+ y: yProp,
577
+ width: widthProp,
578
+ height: heightProp,
579
+ poster_src: { type: "string", description: "Poster frame URL shown before render. Optional." },
580
+ name: { type: "string", description: 'Layer name. Default "Video".' }
581
+ },
582
+ ["src", "x", "y", "width", "height"]
583
+ ),
584
+ async run(args, env) {
585
+ const { document } = await env.store.getDocument();
586
+ const pageId = resolvePageId(document, args);
587
+ const id = env.mintId();
588
+ const element = {
589
+ id,
590
+ kind: "video",
591
+ name: optionalString(args, "name") ?? "Video",
592
+ x: requireNumber(args, "x"),
593
+ y: requireNumber(args, "y"),
594
+ width: requireNumber(args, "width"),
595
+ height: requireNumber(args, "height"),
596
+ src: requireString(args, "src"),
597
+ rotation: 0,
598
+ opacity: 1,
599
+ locked: false,
600
+ visible: true,
601
+ ...(() => {
602
+ const s = optionalString(args, "poster_src");
603
+ return s ? { posterSrc: s } : {};
604
+ })()
605
+ };
606
+ const result = await applyPlan(env.store, env.mintId, "add video element", [
607
+ { type: "add_element", pageId, element }
608
+ ]);
609
+ return { element_id: id, ...result };
610
+ }
611
+ },
612
+ // ─── mutations ────────────────────────────────────────────────────────────
613
+ {
614
+ name: "set_attrs",
615
+ description: "Set one or more attributes on an existing element. Only provide the attrs you want to change \u2014 omitted attributes are unchanged. Attempting to change kind or id is an error. For convenience transforms (x/y/width/height/rotation) prefer move_element, resize_element, or rotate_element.",
616
+ inputSchema: objectSchema(
617
+ {
618
+ page_id: pageIdProp,
619
+ element_id: elementIdProp,
620
+ attrs: {
621
+ type: "object",
622
+ description: "Attribute patch \u2014 any subset of the element's mutable fields.",
623
+ additionalProperties: true
624
+ }
625
+ },
626
+ ["page_id", "element_id", "attrs"]
627
+ ),
628
+ async run(args, env) {
629
+ const pageId = requireString(args, "page_id");
630
+ const elementId = requireString(args, "element_id");
631
+ if (!isRecord(args["attrs"])) throw new Error("attrs must be an object");
632
+ const attrs = args["attrs"];
633
+ const result = await applyPlan(env.store, env.mintId, `set attrs on ${elementId}`, [
634
+ { type: "set_attrs", pageId, elementId, attrs }
635
+ ]);
636
+ return result;
637
+ }
638
+ },
639
+ {
640
+ name: "move_element",
641
+ description: "Move an element to a new (x, y) position in page coordinates. Sugar for set_attrs({x, y}).",
642
+ inputSchema: objectSchema(
643
+ { page_id: pageIdProp, element_id: elementIdProp, x: xProp, y: yProp },
644
+ ["page_id", "element_id", "x", "y"]
645
+ ),
646
+ async run(args, env) {
647
+ const pageId = requireString(args, "page_id");
648
+ const elementId = requireString(args, "element_id");
649
+ const x = requireNumber(args, "x");
650
+ const y = requireNumber(args, "y");
651
+ const result = await applyPlan(env.store, env.mintId, `move element ${elementId} to (${x}, ${y})`, [
652
+ { type: "set_attrs", pageId, elementId, attrs: { x, y } }
653
+ ]);
654
+ return result;
655
+ }
656
+ },
657
+ {
658
+ name: "resize_element",
659
+ description: "Resize an element by setting its width and height. Sugar for set_attrs({width, height}). Not valid on lines (use set_attrs with points instead).",
660
+ inputSchema: objectSchema(
661
+ { page_id: pageIdProp, element_id: elementIdProp, width: widthProp, height: heightProp },
662
+ ["page_id", "element_id", "width", "height"]
663
+ ),
664
+ async run(args, env) {
665
+ const pageId = requireString(args, "page_id");
666
+ const elementId = requireString(args, "element_id");
667
+ const width = requireNumber(args, "width");
668
+ const height = requireNumber(args, "height");
669
+ const result = await applyPlan(env.store, env.mintId, `resize element ${elementId} to ${width}\xD7${height}`, [
670
+ { type: "set_attrs", pageId, elementId, attrs: { width, height } }
671
+ ]);
672
+ return result;
673
+ }
674
+ },
675
+ {
676
+ name: "rotate_element",
677
+ description: "Set an element's rotation in degrees (clockwise, about the element's top-left origin). Sugar for set_attrs({rotation}).",
678
+ inputSchema: objectSchema(
679
+ {
680
+ page_id: pageIdProp,
681
+ element_id: elementIdProp,
682
+ degrees: { type: "number", description: "Rotation in degrees (clockwise, 0\u2013360 or negative)." }
683
+ },
684
+ ["page_id", "element_id", "degrees"]
685
+ ),
686
+ async run(args, env) {
687
+ const pageId = requireString(args, "page_id");
688
+ const elementId = requireString(args, "element_id");
689
+ const rotation = requireNumber(args, "degrees");
690
+ const result = await applyPlan(env.store, env.mintId, `rotate element ${elementId} to ${rotation}\xB0`, [
691
+ { type: "set_attrs", pageId, elementId, attrs: { rotation } }
692
+ ]);
693
+ return result;
694
+ }
695
+ },
696
+ {
697
+ name: "reorder_element",
698
+ description: "Change an element's z-order within its owner (page root or parent group). toIndex is 0-based within the owner's element list: 0 = bottom, length-1 = top.",
699
+ inputSchema: objectSchema(
700
+ {
701
+ page_id: pageIdProp,
702
+ element_id: elementIdProp,
703
+ to_index: { type: "number", description: "0-based target z-index within the element's owner." }
704
+ },
705
+ ["page_id", "element_id", "to_index"]
706
+ ),
707
+ async run(args, env) {
708
+ const pageId = requireString(args, "page_id");
709
+ const elementId = requireString(args, "element_id");
710
+ const toIndex = optionalNonNegativeInteger(args, "to_index") ?? 0;
711
+ const result = await applyPlan(env.store, env.mintId, `reorder element ${elementId} to index ${toIndex}`, [
712
+ { type: "reorder_element", pageId, elementId, toIndex }
713
+ ]);
714
+ return result;
715
+ }
716
+ },
717
+ {
718
+ name: "delete_element",
719
+ description: "Permanently delete an element (and all its children if it is a group) from a page.",
720
+ inputSchema: objectSchema(
721
+ { page_id: pageIdProp, element_id: elementIdProp },
722
+ ["page_id", "element_id"]
723
+ ),
724
+ async run(args, env) {
725
+ const pageId = requireString(args, "page_id");
726
+ const elementId = requireString(args, "element_id");
727
+ const result = await applyPlan(env.store, env.mintId, `delete element ${elementId}`, [
728
+ { type: "delete_element", pageId, elementId }
729
+ ]);
730
+ return result;
731
+ }
732
+ },
733
+ {
734
+ name: "group_elements",
735
+ description: "Group 2+ sibling elements into a new group. Elements must share the same owner (page root or the same parent group). The group's origin is set to the minimum bounding box of the members; children are rebased to group-local coordinates.",
736
+ inputSchema: objectSchema(
737
+ {
738
+ page_id: pageIdProp,
739
+ element_ids: { type: "array", items: { type: "string" }, minItems: 2, description: "\u22652 sibling element ids to group." },
740
+ name: { type: "string", description: 'Layer name for the new group. Default "Group".' }
741
+ },
742
+ ["page_id", "element_ids"]
743
+ ),
744
+ async run(args, env) {
745
+ const pageId = requireString(args, "page_id");
746
+ const elementIds = requireStringArray(args, "element_ids");
747
+ const groupId = env.mintId();
748
+ const result = await applyPlan(env.store, env.mintId, `group ${elementIds.length} elements`, [
749
+ { type: "group_elements", pageId, elementIds, groupId, name: optionalString(args, "name") }
750
+ ]);
751
+ return { group_id: groupId, ...result };
752
+ }
753
+ },
754
+ {
755
+ name: "ungroup_element",
756
+ description: "Dissolve a group, promoting its children to the group's parent owner at page coordinates. The group element is removed.",
757
+ inputSchema: objectSchema(
758
+ { page_id: pageIdProp, group_id: { type: "string", description: "Id of the group element to ungroup." } },
759
+ ["page_id", "group_id"]
760
+ ),
761
+ async run(args, env) {
762
+ const pageId = requireString(args, "page_id");
763
+ const groupId = requireString(args, "group_id");
764
+ const result = await applyPlan(env.store, env.mintId, `ungroup ${groupId}`, [
765
+ { type: "ungroup_element", pageId, groupId }
766
+ ]);
767
+ return result;
768
+ }
769
+ },
770
+ // ─── page management ──────────────────────────────────────────────────────
771
+ {
772
+ name: "add_page",
773
+ description: "Add a new blank page to the document. Returns the new page's id.",
774
+ inputSchema: objectSchema(
775
+ {
776
+ name: { type: "string", description: "Page name." },
777
+ width: { type: "number", description: "Width in px. Default 1080." },
778
+ height: { type: "number", description: "Height in px. Default 1080." },
779
+ background: colorProp('Page background. Default "#ffffff".'),
780
+ index: { type: "number", description: "Position in the page list (0-based). Omit to append." }
781
+ },
782
+ []
783
+ ),
784
+ async run(args, env) {
785
+ const pageId = env.mintId();
786
+ const result = await applyPlan(env.store, env.mintId, "add page", [
787
+ {
788
+ type: "add_page",
789
+ pageId,
790
+ options: {
791
+ name: optionalString(args, "name"),
792
+ width: optionalNumber(args, "width"),
793
+ height: optionalNumber(args, "height"),
794
+ background: optionalString(args, "background")
795
+ },
796
+ index: optionalNonNegativeInteger(args, "index")
797
+ }
798
+ ]);
799
+ return { page_id: pageId, ...result };
800
+ }
801
+ },
802
+ {
803
+ name: "duplicate_page",
804
+ description: "Duplicate an existing page including all its elements. Element ids are re-minted server-side to avoid conflicts. Returns the new page's id.",
805
+ inputSchema: objectSchema(
806
+ {
807
+ source_page_id: { type: "string", description: "Page id to copy." }
808
+ },
809
+ ["source_page_id"]
810
+ ),
811
+ async run(args, env) {
812
+ const sourcePageId = requireString(args, "source_page_id");
813
+ const pageId = env.mintId();
814
+ const result = await applyPlan(env.store, env.mintId, `duplicate page ${sourcePageId}`, [
815
+ { type: "duplicate_page", sourcePageId, pageId }
816
+ ]);
817
+ return { page_id: pageId, ...result };
818
+ }
819
+ },
820
+ {
821
+ name: "delete_page",
822
+ description: "Delete a page. Fails if the document has only one page.",
823
+ inputSchema: objectSchema(
824
+ { page_id: { type: "string", description: "Page id to delete." } },
825
+ ["page_id"]
826
+ ),
827
+ async run(args, env) {
828
+ const pageId = requireString(args, "page_id");
829
+ const result = await applyPlan(env.store, env.mintId, `delete page ${pageId}`, [
830
+ { type: "delete_page", pageId }
831
+ ]);
832
+ return result;
833
+ }
834
+ },
835
+ {
836
+ name: "set_page_props",
837
+ description: "Update a page's name, dimensions, background color, or bleed. Pass null for bleed to clear it. Omit fields you don't want to change.",
838
+ inputSchema: objectSchema(
839
+ {
840
+ page_id: { type: "string", description: "Page id to update." },
841
+ name: { type: "string", description: "New page name." },
842
+ width: { type: "number", description: "New width in px." },
843
+ height: { type: "number", description: "New height in px." },
844
+ background: colorProp("New background color."),
845
+ bleed: {
846
+ type: "object",
847
+ description: "Bleed extents in px drawn OUTSIDE the page trim edge. Pass null to clear bleed.",
848
+ properties: {
849
+ top: { type: "number" },
850
+ right: { type: "number" },
851
+ bottom: { type: "number" },
852
+ left: { type: "number" }
853
+ },
854
+ required: ["top", "right", "bottom", "left"],
855
+ nullable: true
856
+ }
857
+ },
858
+ ["page_id"]
859
+ ),
860
+ async run(args, env) {
861
+ const pageId = requireString(args, "page_id");
862
+ let bleed;
863
+ if ("bleed" in args) {
864
+ if (args["bleed"] === null) {
865
+ bleed = null;
866
+ } else if (isRecord(args["bleed"])) {
867
+ const b = args["bleed"];
868
+ bleed = {
869
+ top: requireNumber(b, "top"),
870
+ right: requireNumber(b, "right"),
871
+ bottom: requireNumber(b, "bottom"),
872
+ left: requireNumber(b, "left")
873
+ };
874
+ } else {
875
+ throw new Error("bleed must be an object with top/right/bottom/left or null to clear");
876
+ }
877
+ }
878
+ const result = await applyPlan(env.store, env.mintId, `set props on page ${pageId}`, [
879
+ {
880
+ type: "set_page_props",
881
+ pageId,
882
+ name: optionalString(args, "name"),
883
+ width: optionalNumber(args, "width"),
884
+ height: optionalNumber(args, "height"),
885
+ background: optionalString(args, "background"),
886
+ ...bleed !== void 0 ? { bleed } : {}
887
+ }
888
+ ]);
889
+ return result;
890
+ }
891
+ },
892
+ {
893
+ name: "set_page_guides",
894
+ description: "Set ruler guides on a page. Replaces ALL existing guides for that axis \u2014 pass the full updated arrays.",
895
+ inputSchema: objectSchema(
896
+ {
897
+ page_id: { type: "string", description: "Page id to update." },
898
+ vertical: { type: "array", items: { type: "number" }, description: "Vertical guide positions in page-coordinate px." },
899
+ horizontal: { type: "array", items: { type: "number" }, description: "Horizontal guide positions in page-coordinate px." }
900
+ },
901
+ ["page_id", "vertical", "horizontal"]
902
+ ),
903
+ async run(args, env) {
904
+ const pageId = requireString(args, "page_id");
905
+ if (!Array.isArray(args["vertical"])) throw new Error("vertical must be an array of numbers");
906
+ if (!Array.isArray(args["horizontal"])) throw new Error("horizontal must be an array of numbers");
907
+ const vertical = args["vertical"];
908
+ const horizontal = args["horizontal"];
909
+ const result = await applyPlan(env.store, env.mintId, `set guides on page ${pageId}`, [
910
+ { type: "set_page_guides", pageId, guides: { vertical, horizontal } }
911
+ ]);
912
+ return result;
913
+ }
914
+ },
915
+ // ─── template / data binding ──────────────────────────────────────────────
916
+ {
917
+ name: "bind_slot",
918
+ description: "Bind or unbind a template slot name to an element. Slot names are unique document-wide. Text elements accept string data; image/video elements accept src URLs. Pass null for slot to unbind.",
919
+ inputSchema: objectSchema(
920
+ {
921
+ page_id: pageIdProp,
922
+ element_id: elementIdProp,
923
+ slot: { type: ["string", "null"], description: "Slot name to bind, or null to unbind." }
924
+ },
925
+ ["page_id", "element_id", "slot"]
926
+ ),
927
+ async run(args, env) {
928
+ const pageId = requireString(args, "page_id");
929
+ const elementId = requireString(args, "element_id");
930
+ const slot = args["slot"] === null ? null : requireString(args, "slot");
931
+ const result = await applyPlan(env.store, env.mintId, `bind slot "${slot}" to ${elementId}`, [
932
+ { type: "bind_slot", pageId, elementId, slot }
933
+ ]);
934
+ return result;
935
+ }
936
+ },
937
+ {
938
+ name: "apply_data",
939
+ description: "Fill template slots with data. bindings is a {slot_name: value} map. Text slots accept any string; image/video slots accept http(s) URLs or /api/ paths; unknown slot names throw. Partial application is allowed.",
940
+ inputSchema: objectSchema(
941
+ {
942
+ bindings: {
943
+ type: "object",
944
+ description: "Map of slot name \u2192 value. Text slots: string. Image/video slots: URL.",
945
+ additionalProperties: { type: "string" }
946
+ }
947
+ },
948
+ ["bindings"]
949
+ ),
950
+ async run(args, env) {
951
+ if (!isRecord(args["bindings"])) throw new Error("bindings must be an object");
952
+ const bindings = args["bindings"];
953
+ const result = await applyPlan(env.store, env.mintId, `apply data to ${Object.keys(bindings).length} slots`, [
954
+ { type: "apply_data", bindings }
955
+ ]);
956
+ return result;
957
+ }
958
+ },
959
+ {
960
+ name: "instantiate_template",
961
+ description: "Clone this document's page(s) with freshly minted element ids and fill the declared slots with the provided data bindings in one atomic call. Use this to produce personalized copies of a template document without modifying the original. Returns the new page ids in order. Note: this mutates the SAME document by appending copies of the requested pages with re-minted ids and applying data \u2014 it does NOT create a separate document. After calling, the document contains both the original pages and the new copies.",
962
+ inputSchema: objectSchema(
963
+ {
964
+ source_page_ids: {
965
+ type: "array",
966
+ items: { type: "string" },
967
+ description: "Page ids to clone. Omit to clone all pages."
968
+ },
969
+ bindings: {
970
+ type: "object",
971
+ description: "Slot name \u2192 value map applied after cloning.",
972
+ additionalProperties: { type: "string" }
973
+ }
974
+ },
975
+ []
976
+ ),
977
+ async run(args, env) {
978
+ const { document } = await env.store.getDocument();
979
+ const rawSourceIds = Array.isArray(args["source_page_ids"]) ? args["source_page_ids"] : document.pages.map((p) => p.id);
980
+ const bindings = optionalRecord(args, "bindings") ?? {};
981
+ if (rawSourceIds.length === 0) throw new Error("source_page_ids must not be empty");
982
+ const unbindOps = [];
983
+ const rebindOps = [];
984
+ const dupOps = [];
985
+ const newPageIds = [];
986
+ for (const sourcePageId of rawSourceIds) {
987
+ const sourcePage = requirePage(document, sourcePageId);
988
+ const sourceSlots = collectPageSlotAttrs(sourcePage);
989
+ for (const [slotName, { elementId }] of sourceSlots) {
990
+ unbindOps.push({ type: "bind_slot", pageId: sourcePageId, elementId, slot: null });
991
+ rebindOps.push({ type: "bind_slot", pageId: sourcePageId, elementId, slot: slotName });
992
+ }
993
+ const pageId = env.mintId();
994
+ newPageIds.push(pageId);
995
+ dupOps.push({ type: "duplicate_page", sourcePageId, pageId });
996
+ }
997
+ const applyDataOps = Object.keys(bindings).length > 0 ? [{ type: "apply_data", bindings }] : [];
998
+ const allOps = [
999
+ ...dupOps,
1000
+ ...unbindOps,
1001
+ ...applyDataOps,
1002
+ ...rebindOps
1003
+ ];
1004
+ const result = await applyPlan(
1005
+ env.store,
1006
+ env.mintId,
1007
+ `instantiate template (${rawSourceIds.length} pages)`,
1008
+ allOps
1009
+ );
1010
+ return { new_page_ids: newPageIds, ...result };
1011
+ }
1012
+ },
1013
+ // ─── exports ──────────────────────────────────────────────────────────────
1014
+ {
1015
+ name: "create_export",
1016
+ description: 'Queue a document export. For "png" and "jpeg", a render job is queued and status starts as "queued" \u2014 the host renders the Konva canvas and uploads the result. For "json", the export completes immediately with the full document JSON in metadata. Returns the export record id and initial status.',
1017
+ inputSchema: objectSchema(
1018
+ {
1019
+ format: { type: "string", enum: ["png", "jpeg", "json"], description: "Export format." },
1020
+ page_id: { type: "string", description: "Page to export. Omit to export all pages (first page for images)." },
1021
+ pixel_ratio: { type: "number", description: "Device pixel ratio for raster exports. Default 1." }
1022
+ },
1023
+ ["format"]
1024
+ ),
1025
+ async run(args, env) {
1026
+ const format = requireEnum(args, "format", ["png", "jpeg", "json"]);
1027
+ const pageId = optionalString(args, "page_id");
1028
+ const pixelRatio = optionalNumber(args, "pixel_ratio") ?? 1;
1029
+ let metadata = {
1030
+ pageId: pageId ?? null,
1031
+ pixelRatio
1032
+ };
1033
+ if (format === "json") {
1034
+ const { document, rev } = await env.store.getDocument();
1035
+ metadata = { ...metadata, document, rev };
1036
+ }
1037
+ const exportRecord = await env.store.createExport(format, metadata);
1038
+ await env.store.recordDecision({
1039
+ kind: "export",
1040
+ instruction: `create ${format} export${pageId ? ` for page ${pageId}` : ""}`,
1041
+ metadata: { tool: "create_export", export_id: exportRecord.id, format }
1042
+ });
1043
+ return {
1044
+ export_id: exportRecord.id,
1045
+ format: exportRecord.format,
1046
+ status: exportRecord.status,
1047
+ metadata: exportRecord.metadata,
1048
+ created_at: exportRecord.createdAt
1049
+ };
1050
+ }
1051
+ }
1052
+ ];
1053
+ function findCanvasMcpTool(name) {
1054
+ return CANVAS_MCP_TOOLS.find((tool) => tool.name === name);
1055
+ }
1056
+ var CANVAS_MCP_TOOL_NAMES = CANVAS_MCP_TOOLS.map((t) => t.name);
1057
+ var CANVAS_ELEMENT_KINDS = SCENE_ELEMENT_KINDS;
1058
+
1059
+ // src/design-canvas/mcp-handler.ts
1060
+ function createDesignCanvasMcpHandler(opts) {
1061
+ const serverInfo = opts.serverInfo ?? { name: "design-canvas", version: "1.0.0" };
1062
+ return createMcpToolHandler({
1063
+ serverInfo,
1064
+ tools: CANVAS_MCP_TOOLS,
1065
+ buildEnv: (_request) => ({ store: opts.store, mintId: opts.mintId })
1066
+ });
1067
+ }
1068
+
1069
+ // src/design-canvas/mcp-entry.ts
1070
+ var DEFAULT_DESIGN_CANVAS_MCP_DESCRIPTION = "Live visual asset editor for the current design document: read scene state, add/move/resize/delete elements, manage pages, bind template slots, apply data, and queue exports. All coordinates are CSS pixels.";
1071
+ function buildDesignCanvasMcpServerEntry(opts) {
1072
+ if (opts.token.trim().length === 0) {
1073
+ throw new Error(
1074
+ "buildDesignCanvasMcpServerEntry requires a capability token \u2014 omit the design-canvas MCP server when none is available"
1075
+ );
1076
+ }
1077
+ if (!opts.path.startsWith("/")) {
1078
+ throw new Error(
1079
+ `buildDesignCanvasMcpServerEntry path must start with "/" (got "${opts.path}")`
1080
+ );
1081
+ }
1082
+ const description = opts.description ?? DEFAULT_DESIGN_CANVAS_MCP_DESCRIPTION;
1083
+ if (opts.ctx) {
1084
+ return buildHttpMcpServer({
1085
+ path: opts.path,
1086
+ baseUrl: opts.baseUrl,
1087
+ token: opts.token,
1088
+ ctx: opts.ctx,
1089
+ description,
1090
+ headerNames: opts.headerNames ?? DEFAULT_HEADER_NAMES
1091
+ });
1092
+ }
1093
+ return {
1094
+ transport: "http",
1095
+ url: `${opts.baseUrl.replace(/\/+$/, "")}${opts.path}`,
1096
+ headers: {
1097
+ Authorization: `Bearer ${opts.token}`,
1098
+ "Content-Type": "application/json"
1099
+ },
1100
+ enabled: true,
1101
+ metadata: { description }
1102
+ };
1103
+ }
1104
+
1105
+ export {
1106
+ SCENE_OPERATION_TYPES,
1107
+ listTemplateSlots,
1108
+ validateBindings,
1109
+ instantiateTemplate,
1110
+ applyBindingsToDocument,
1111
+ CANVAS_MCP_TOOLS,
1112
+ findCanvasMcpTool,
1113
+ CANVAS_MCP_TOOL_NAMES,
1114
+ CANVAS_ELEMENT_KINDS,
1115
+ createDesignCanvasMcpHandler,
1116
+ DEFAULT_DESIGN_CANVAS_MCP_DESCRIPTION,
1117
+ buildDesignCanvasMcpServerEntry
1118
+ };
1119
+ //# sourceMappingURL=chunk-7QCIYDGC.js.map