@plitzi/sdk-mcp 0.39.3 → 0.39.4

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 (99) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +39 -39
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2 -1
  5. package/dist/modules/mcp/answerBudgets.d.ts +29 -0
  6. package/dist/modules/mcp/answerBudgets.js +37 -0
  7. package/dist/modules/mcp/apps/example/view/index.tsx +0 -1
  8. package/dist/modules/mcp/apps/render/view/index.tsx +0 -1
  9. package/dist/modules/mcp/helpers/guide/reference.d.ts +1 -1
  10. package/dist/modules/mcp/helpers/guide/reference.js +7 -2
  11. package/dist/modules/mcp/helpers/guide/structure.d.ts +1 -1
  12. package/dist/modules/mcp/helpers/guide/structure.js +1 -0
  13. package/dist/modules/mcp/helpers/opResult.d.ts +3 -1
  14. package/dist/modules/mcp/helpers/opResult.js +3 -1
  15. package/dist/modules/mcp/localScreenshotClient.d.ts +10 -0
  16. package/dist/modules/mcp/localScreenshotClient.js +46 -16
  17. package/dist/modules/mcp/previewClient.js +2 -2
  18. package/dist/modules/mcp/resources/canonical.js +2 -2
  19. package/dist/modules/mcp/server.d.ts +1 -1
  20. package/dist/modules/mcp/server.js +3 -2
  21. package/dist/modules/mcp/tools/activity.js +2 -2
  22. package/dist/modules/mcp/tools/apply/dispatch.js +7 -1
  23. package/dist/modules/mcp/tools/apply/index.d.ts +25 -1
  24. package/dist/modules/mcp/tools/apply/index.js +21 -5
  25. package/dist/modules/mcp/tools/describeOperation.js +1 -1
  26. package/dist/modules/mcp/tools/intents.js +26 -4
  27. package/dist/modules/mcp/tools/look.d.ts +1 -0
  28. package/dist/modules/mcp/tools/look.js +2 -1
  29. package/dist/modules/mcp/tools/operations/actions/deleteAction.js +1 -1
  30. package/dist/modules/mcp/tools/operations/actions/patchAction.js +3 -3
  31. package/dist/modules/mcp/tools/operations/actions/upsertAction.js +1 -1
  32. package/dist/modules/mcp/tools/operations/connectors/deleteConnector.js +1 -1
  33. package/dist/modules/mcp/tools/operations/connectors/patchConnector.js +2 -2
  34. package/dist/modules/mcp/tools/operations/data/index.js +3 -3
  35. package/dist/modules/mcp/tools/operations/functions/index.js +2 -2
  36. package/dist/modules/mcp/tools/operations/index.d.ts +97 -4
  37. package/dist/modules/mcp/tools/operations/index.js +1 -0
  38. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +1 -1
  39. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +1 -1
  40. package/dist/modules/mcp/tools/operations/schema/components/deleteComponent.js +2 -2
  41. package/dist/modules/mcp/tools/operations/schema/components/upsertComponent.js +8 -8
  42. package/dist/modules/mcp/tools/operations/schema/elements/addSpec.d.ts +29 -0
  43. package/dist/modules/mcp/tools/operations/schema/elements/addSpec.js +118 -0
  44. package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +2 -2
  45. package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +4 -4
  46. package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +2 -2
  47. package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +2 -0
  48. package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +3 -3
  49. package/dist/modules/mcp/tools/operations/schema/flags/deleteFlag.js +1 -1
  50. package/dist/modules/mcp/tools/operations/schema/flags/upsertFlag.js +2 -2
  51. package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +1 -1
  52. package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +1 -1
  53. package/dist/modules/mcp/tools/operations/schema/index.d.ts +1 -0
  54. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +4 -4
  55. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +1 -1
  56. package/dist/modules/mcp/tools/operations/schema/operations.d.ts +25 -1
  57. package/dist/modules/mcp/tools/operations/schema/operations.js +2 -0
  58. package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.js +2 -2
  59. package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +1 -1
  60. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +4 -0
  61. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +14 -7
  62. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +8 -1
  63. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +9 -6
  64. package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +3 -2
  65. package/dist/modules/mcp/tools/operations/schema/write.js +3 -3
  66. package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +2 -1
  67. package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +1 -1
  68. package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.js +2 -2
  69. package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.js +1 -1
  70. package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +2 -1
  71. package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +1 -1
  72. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +2 -1
  73. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +1 -1
  74. package/dist/modules/mcp/tools/operations/style/validate.js +6 -6
  75. package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +3 -2
  76. package/dist/modules/mcp/tools/operations/style/write.js +1 -1
  77. package/dist/modules/mcp/tools/render.d.ts +24 -1
  78. package/dist/modules/mcp/tools/renderWidget.d.ts +24 -1
  79. package/dist/modules/mcp/tools/search.js +1 -1
  80. package/dist/modules/mcp/tools/shared/agentHtml.d.ts +8 -0
  81. package/dist/modules/mcp/tools/shared/agentHtml.js +18 -0
  82. package/dist/modules/mcp/tools/shared/lintDraft.js +1 -0
  83. package/dist/modules/mcp/tools/shared/look.d.ts +2 -0
  84. package/dist/modules/mcp/tools/shared/look.js +15 -8
  85. package/dist/modules/mcp/tools/shared/repeats.d.ts +1 -1
  86. package/dist/modules/mcp/tools/shared/repeats.js +1 -1
  87. package/dist/modules/mcp/tools/shared/tool.d.ts +2 -0
  88. package/dist/modules/mcp/tools/shared/validator/connectors.js +3 -0
  89. package/dist/modules/mcp/tools/shared/validator/css.js +2 -0
  90. package/dist/modules/mcp/tools/shared/validator/elements.js +3 -0
  91. package/dist/modules/mcp/tools/shared/validator/index.js +39 -0
  92. package/dist/modules/mcp/tools/shared/validator/interactions.js +1 -0
  93. package/dist/modules/mcp/tools/shared/validator/refs.js +3 -0
  94. package/dist/modules/mcp/tools/tryFunction.js +2 -2
  95. package/dist/modules/mcp/types/aiSchema.d.ts +3 -0
  96. package/dist/modules/mcp/types/previewTypes.d.ts +9 -1
  97. package/dist/options.d.ts +1 -1
  98. package/dist/preview/createPreview.js +38 -7
  99. package/package.json +8 -8
@@ -68,6 +68,18 @@ export declare const documentOperation: z.ZodDiscriminatedUnion<readonly [z.ZodO
68
68
  after: "after";
69
69
  inside: "inside";
70
70
  }>;
71
+ }, z.core.$strict>, z.ZodObject<{
72
+ type: z.ZodLiteral<"addSpec">;
73
+ pageRef: z.ZodString;
74
+ parentRef: z.ZodOptional<z.ZodString>;
75
+ position: z.ZodOptional<z.ZodEnum<{
76
+ before: "before";
77
+ after: "after";
78
+ inside: "inside";
79
+ }>>;
80
+ replaces: z.ZodOptional<z.ZodString>;
81
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
82
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
71
83
  }, z.core.$strict>, z.ZodObject<{
72
84
  type: z.ZodLiteral<"upsertPage">;
73
85
  ref: z.ZodString;
@@ -83,6 +95,10 @@ export declare const documentOperation: z.ZodDiscriminatedUnion<readonly [z.ZodO
83
95
  noBounce: "noBounce";
84
96
  }>>>;
85
97
  flag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
98
+ style: z.ZodOptional<z.ZodObject<{
99
+ base: z.ZodOptional<z.ZodArray<z.ZodString>>;
100
+ slots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
101
+ }, z.core.$strip>>;
86
102
  }, z.core.$strict>, z.ZodObject<{
87
103
  type: z.ZodLiteral<"deletePage">;
88
104
  ref: z.ZodString;
@@ -285,9 +301,16 @@ export declare const documentOperation: z.ZodDiscriminatedUnion<readonly [z.ZodO
285
301
  dark: z.ZodOptional<z.ZodString>;
286
302
  }, z.core.$strip>]>>;
287
303
  robotsTxt: z.ZodOptional<z.ZodString>;
288
- blockAiCrawlers: z.ZodOptional<z.ZodBoolean>;
304
+ securityTxt: z.ZodOptional<z.ZodString>;
305
+ llmsTxt: z.ZodOptional<z.ZodString>;
306
+ blockAiCrawlers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
307
+ training: "training";
308
+ assistants: "assistants";
309
+ search: "search";
310
+ }>>>;
289
311
  viewTransitions: z.ZodOptional<z.ZodBoolean>;
290
312
  withheldPage: z.ZodOptional<z.ZodString>;
313
+ wholeDocument: z.ZodOptional<z.ZodBoolean>;
291
314
  channels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<{
292
315
  access: z.ZodObject<{
293
316
  mode: z.ZodEnum<{
@@ -1508,6 +1531,18 @@ export declare const operation: z.ZodDiscriminatedUnion<[z.ZodObject<{
1508
1531
  after: "after";
1509
1532
  inside: "inside";
1510
1533
  }>;
1534
+ }, z.core.$strict>, z.ZodObject<{
1535
+ type: z.ZodLiteral<"addSpec">;
1536
+ pageRef: z.ZodString;
1537
+ parentRef: z.ZodOptional<z.ZodString>;
1538
+ position: z.ZodOptional<z.ZodEnum<{
1539
+ before: "before";
1540
+ after: "after";
1541
+ inside: "inside";
1542
+ }>>;
1543
+ replaces: z.ZodOptional<z.ZodString>;
1544
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1545
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1511
1546
  }, z.core.$strict>, z.ZodObject<{
1512
1547
  type: z.ZodLiteral<"upsertPage">;
1513
1548
  ref: z.ZodString;
@@ -1523,6 +1558,10 @@ export declare const operation: z.ZodDiscriminatedUnion<[z.ZodObject<{
1523
1558
  noBounce: "noBounce";
1524
1559
  }>>>;
1525
1560
  flag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1561
+ style: z.ZodOptional<z.ZodObject<{
1562
+ base: z.ZodOptional<z.ZodArray<z.ZodString>>;
1563
+ slots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
1564
+ }, z.core.$strip>>;
1526
1565
  }, z.core.$strict>, z.ZodObject<{
1527
1566
  type: z.ZodLiteral<"deletePage">;
1528
1567
  ref: z.ZodString;
@@ -1725,9 +1764,16 @@ export declare const operation: z.ZodDiscriminatedUnion<[z.ZodObject<{
1725
1764
  dark: z.ZodOptional<z.ZodString>;
1726
1765
  }, z.core.$strip>]>>;
1727
1766
  robotsTxt: z.ZodOptional<z.ZodString>;
1728
- blockAiCrawlers: z.ZodOptional<z.ZodBoolean>;
1767
+ securityTxt: z.ZodOptional<z.ZodString>;
1768
+ llmsTxt: z.ZodOptional<z.ZodString>;
1769
+ blockAiCrawlers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
1770
+ training: "training";
1771
+ assistants: "assistants";
1772
+ search: "search";
1773
+ }>>>;
1729
1774
  viewTransitions: z.ZodOptional<z.ZodBoolean>;
1730
1775
  withheldPage: z.ZodOptional<z.ZodString>;
1776
+ wholeDocument: z.ZodOptional<z.ZodBoolean>;
1731
1777
  channels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<{
1732
1778
  access: z.ZodObject<{
1733
1779
  mode: z.ZodEnum<{
@@ -3237,6 +3283,18 @@ export declare const operations: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject
3237
3283
  after: "after";
3238
3284
  inside: "inside";
3239
3285
  }>;
3286
+ }, z.core.$strict>, z.ZodObject<{
3287
+ type: z.ZodLiteral<"addSpec">;
3288
+ pageRef: z.ZodString;
3289
+ parentRef: z.ZodOptional<z.ZodString>;
3290
+ position: z.ZodOptional<z.ZodEnum<{
3291
+ before: "before";
3292
+ after: "after";
3293
+ inside: "inside";
3294
+ }>>;
3295
+ replaces: z.ZodOptional<z.ZodString>;
3296
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
3297
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
3240
3298
  }, z.core.$strict>, z.ZodObject<{
3241
3299
  type: z.ZodLiteral<"upsertPage">;
3242
3300
  ref: z.ZodString;
@@ -3252,6 +3310,10 @@ export declare const operations: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject
3252
3310
  noBounce: "noBounce";
3253
3311
  }>>>;
3254
3312
  flag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3313
+ style: z.ZodOptional<z.ZodObject<{
3314
+ base: z.ZodOptional<z.ZodArray<z.ZodString>>;
3315
+ slots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
3316
+ }, z.core.$strip>>;
3255
3317
  }, z.core.$strict>, z.ZodObject<{
3256
3318
  type: z.ZodLiteral<"deletePage">;
3257
3319
  ref: z.ZodString;
@@ -3454,9 +3516,16 @@ export declare const operations: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject
3454
3516
  dark: z.ZodOptional<z.ZodString>;
3455
3517
  }, z.core.$strip>]>>;
3456
3518
  robotsTxt: z.ZodOptional<z.ZodString>;
3457
- blockAiCrawlers: z.ZodOptional<z.ZodBoolean>;
3519
+ securityTxt: z.ZodOptional<z.ZodString>;
3520
+ llmsTxt: z.ZodOptional<z.ZodString>;
3521
+ blockAiCrawlers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3522
+ training: "training";
3523
+ assistants: "assistants";
3524
+ search: "search";
3525
+ }>>>;
3458
3526
  viewTransitions: z.ZodOptional<z.ZodBoolean>;
3459
3527
  withheldPage: z.ZodOptional<z.ZodString>;
3528
+ wholeDocument: z.ZodOptional<z.ZodBoolean>;
3460
3529
  channels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<{
3461
3530
  access: z.ZodObject<{
3462
3531
  mode: z.ZodEnum<{
@@ -4961,6 +5030,18 @@ export declare const documentOperations: z.ZodArray<z.ZodDiscriminatedUnion<read
4961
5030
  after: "after";
4962
5031
  inside: "inside";
4963
5032
  }>;
5033
+ }, z.core.$strict>, z.ZodObject<{
5034
+ type: z.ZodLiteral<"addSpec">;
5035
+ pageRef: z.ZodString;
5036
+ parentRef: z.ZodOptional<z.ZodString>;
5037
+ position: z.ZodOptional<z.ZodEnum<{
5038
+ before: "before";
5039
+ after: "after";
5040
+ inside: "inside";
5041
+ }>>;
5042
+ replaces: z.ZodOptional<z.ZodString>;
5043
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
5044
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
4964
5045
  }, z.core.$strict>, z.ZodObject<{
4965
5046
  type: z.ZodLiteral<"upsertPage">;
4966
5047
  ref: z.ZodString;
@@ -4976,6 +5057,10 @@ export declare const documentOperations: z.ZodArray<z.ZodDiscriminatedUnion<read
4976
5057
  noBounce: "noBounce";
4977
5058
  }>>>;
4978
5059
  flag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
5060
+ style: z.ZodOptional<z.ZodObject<{
5061
+ base: z.ZodOptional<z.ZodArray<z.ZodString>>;
5062
+ slots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
5063
+ }, z.core.$strip>>;
4979
5064
  }, z.core.$strict>, z.ZodObject<{
4980
5065
  type: z.ZodLiteral<"deletePage">;
4981
5066
  ref: z.ZodString;
@@ -5178,9 +5263,16 @@ export declare const documentOperations: z.ZodArray<z.ZodDiscriminatedUnion<read
5178
5263
  dark: z.ZodOptional<z.ZodString>;
5179
5264
  }, z.core.$strip>]>>;
5180
5265
  robotsTxt: z.ZodOptional<z.ZodString>;
5181
- blockAiCrawlers: z.ZodOptional<z.ZodBoolean>;
5266
+ securityTxt: z.ZodOptional<z.ZodString>;
5267
+ llmsTxt: z.ZodOptional<z.ZodString>;
5268
+ blockAiCrawlers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
5269
+ training: "training";
5270
+ assistants: "assistants";
5271
+ search: "search";
5272
+ }>>>;
5182
5273
  viewTransitions: z.ZodOptional<z.ZodBoolean>;
5183
5274
  withheldPage: z.ZodOptional<z.ZodString>;
5275
+ wholeDocument: z.ZodOptional<z.ZodBoolean>;
5184
5276
  channels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<{
5185
5277
  access: z.ZodObject<{
5186
5278
  mode: z.ZodEnum<{
@@ -6348,6 +6440,7 @@ export declare const compactDocumentOperations: z.ZodArray<z.ZodObject<{
6348
6440
  upsertBinding: "upsertBinding";
6349
6441
  deleteComponent: "deleteComponent";
6350
6442
  upsertComponent: "upsertComponent";
6443
+ addSpec: "addSpec";
6351
6444
  deleteElement: "deleteElement";
6352
6445
  moveElement: "moveElement";
6353
6446
  patchElement: "patchElement";
@@ -26,6 +26,7 @@ var documentOps = [
26
26
  closed(elementOps.patchElement),
27
27
  closed(elementOps.deleteElement),
28
28
  closed(elementOps.moveElement),
29
+ closed(elementOps.addSpec),
29
30
  closed(elementOps.upsertPage),
30
31
  closed(elementOps.deletePage),
31
32
  closed(elementOps.upsertLayout),
@@ -18,7 +18,7 @@ var deleteBinding = (space, env, op) => {
18
18
  const bindings = found.el.definition.bindings;
19
19
  const list = bindings?.[op.category];
20
20
  const index = list ? list.findIndex((b) => op.id ? b.id === op.id : b.to === op.to) : -1;
21
- if (!bindings || !list || index < 0) return fail("to", `No ${op.category} binding matching "${op.id ?? op.to}" on "${op.ref}"`, "Nothing to delete");
21
+ if (!bindings || !list || index < 0) return fail("missing", "to", `No ${op.category} binding matching "${op.id ?? op.to}" on "${op.ref}"`, "Read the element to list its bindings, and name one of them");
22
22
  list.splice(index, 1);
23
23
  if (list.length === 0) Reflect.deleteProperty(bindings, op.category);
24
24
  return {
@@ -20,7 +20,7 @@ var patchBinding = (space, env, op) => {
20
20
  const found = resolveElement(space, env, op.pageRef, op.ref);
21
21
  if ("error" in found) return found.error;
22
22
  const binding = (found.el.definition.bindings?.[op.category])?.find((b) => op.id ? b.id === op.id : b.to === op.to);
23
- if (!binding) return fail("to", `No ${op.category} binding matching "${op.id ?? op.to}" on "${op.ref}"`, "Use upsertBinding to add it");
23
+ if (!binding) return fail("missing", "to", `No ${op.category} binding matching "${op.id ?? op.to}" on "${op.ref}"`, "Use upsertBinding to add it");
24
24
  if (op.source !== void 0) binding.source = op.source;
25
25
  if (op.transformers !== void 0) binding.transformers = op.transformers;
26
26
  if (op.when !== void 0) binding.when = op.when;
@@ -8,9 +8,9 @@ var deleteComponentOp = z.object({
8
8
  ref: z.string()
9
9
  }).describe("Remove a component nothing places any more.");
10
10
  var deleteComponent = (space, env, op) => {
11
- if (!componentNamed(space.schema, op.ref)) return fail("ref", `Component "${op.ref}" not found`, `Read plitzi://schema/${env}/components for valid refs`);
11
+ if (!componentNamed(space.schema, op.ref)) return fail("missing", "ref", `Component "${op.ref}" not found`, `Read plitzi://schema/${env}/components for valid refs`);
12
12
  const placed = instancesOf(space.schema, op.ref);
13
- if (placed.length > 0 || !removeComponent(space.schema, op.ref)) return fail("ref", `Component "${op.ref}" is still placed by ${placed.map((instance) => `"${instance.id}"`).join(", ")}`, "detachInstance or deleteElement each of them first");
13
+ if (placed.length > 0 || !removeComponent(space.schema, op.ref)) return fail("in-use", "ref", `Component "${op.ref}" is still placed by ${placed.map((instance) => `"${instance.id}"`).join(", ")}`, "detachInstance or deleteElement each of them first");
14
14
  return {
15
15
  ...empty(),
16
16
  deleted: 1,
@@ -68,11 +68,11 @@ var upsertComponent = (space, env, op) => {
68
68
  const { schema } = space;
69
69
  const stale = [componentsUri(env), pageUri(env, op.ref)];
70
70
  const props = parseProps(op.props);
71
- if ("error" in props) return fail("props", props.error, "A prop is { type: \"text\" | \"textarea\" | \"number\" | \"boolean\" | \"select\" | \"scalar\" | \"json\", description, required?, default?, options? }");
71
+ if ("error" in props) return fail("bad-value", "props", props.error, "A prop is { type: \"text\" | \"textarea\" | \"number\" | \"boolean\" | \"select\" | \"scalar\" | \"json\", description, required?, default?, options? }");
72
72
  const declaration = declarationOf(op, props.props);
73
73
  const existing = componentNamed(schema, op.ref);
74
74
  if (existing) {
75
- if (op.fromRef) return fail("fromRef", `Component "${op.ref}" already exists`, "fromRef makes a NEW component; pick another ref");
75
+ if (op.fromRef) return fail("exists", "fromRef", `Component "${op.ref}" already exists`, "fromRef makes a NEW component; pick another ref");
76
76
  const problem = declarationProblem({
77
77
  ...existing,
78
78
  ...declaration
@@ -80,19 +80,19 @@ var upsertComponent = (space, env, op) => {
80
80
  if (problem || !updateComponent(schema, op.ref, {
81
81
  ...existing,
82
82
  ...declaration
83
- })) return fail("props", problem ?? `Component "${op.ref}" refused the declaration`, "Name props as {{ props.<name> }} reads them, and slots as elements of the tree");
83
+ })) return fail("bad-value", "props", problem ?? `Component "${op.ref}" refused the declaration`, "Name props as {{ props.<name> }} reads them, and slots as elements of the tree");
84
84
  return {
85
85
  ...empty(),
86
86
  updated: 1,
87
87
  staleResources: stale
88
88
  };
89
89
  }
90
- if (!isValidElementId(op.ref)) return fail("ref", `"${op.ref}" is not a name a component can have`, ID_REF_HINT);
90
+ if (!isValidElementId(op.ref)) return fail("bad-value", "ref", `"${op.ref}" is not a name a component can have`, ID_REF_HINT);
91
91
  if (op.fromRef) {
92
92
  const tree = treeOf(schema, op.fromRef);
93
93
  const element = tree?.flat[op.fromRef];
94
- if (!tree || !element?.definition.parentId) return fail("fromRef", `"${op.fromRef}" is not an element inside a page, a layout or a component`, "A page or a layout is a root, not a subtree — name an element inside one");
95
- if (!op.instanceRef) return fail("instanceRef", "fromRef needs the name of the instance that takes the element’s place", "e.g. instanceRef: \"hero-card\"");
94
+ if (!tree || !element?.definition.parentId) return fail("bad-value", "fromRef", `"${op.fromRef}" is not an element inside a page, a layout or a component`, "A page or a layout is a root, not a subtree — name an element inside one");
95
+ if (!op.instanceRef) return fail("wrong-options", "instanceRef", "fromRef needs the name of the instance that takes the element’s place", "e.g. instanceRef: \"hero-card\"");
96
96
  const guard = guardNewRef(space, op.instanceRef, "instanceRef");
97
97
  if (guard) return guard;
98
98
  const component = {
@@ -105,7 +105,7 @@ var upsertComponent = (space, env, op) => {
105
105
  if (problem || !addComponent(schema, component, {
106
106
  elementId: op.fromRef,
107
107
  instanceId: op.instanceRef
108
- })) return fail("props", problem ?? `"${op.fromRef}" could not be made a component`, "Slots name elements inside fromRef");
108
+ })) return fail("bad-value", "props", problem ?? `"${op.fromRef}" could not be made a component`, "Slots name elements inside fromRef");
109
109
  invalidateIndex(schema);
110
110
  return {
111
111
  ...empty(),
@@ -134,7 +134,7 @@ var upsertComponent = (space, env, op) => {
134
134
  } }
135
135
  };
136
136
  const problem = declarationProblem(declaration, component.flat);
137
- if (problem || !addComponent(schema, component)) return fail("props", problem ?? `Component "${op.ref}" could not be declared`, "A new component has one element yet — its root; add the rest with upsertElement { pageRef: \"<ref>\" } first, then name slots");
137
+ if (problem || !addComponent(schema, component)) return fail("bad-value", "props", problem ?? `Component "${op.ref}" could not be declared`, "A new component has one element yet — its root; add the rest with upsertElement { pageRef: \"<ref>\" } first, then name slots");
138
138
  return {
139
139
  ...empty(),
140
140
  created: 1,
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import { authorSnippet } from '@plitzi/sdk-authoring';
3
+ import { Space, OpResult } from '../../../../helpers';
4
+ import { Env } from '../../../../types';
5
+ export declare const addSpecOp: z.ZodObject<{
6
+ type: z.ZodLiteral<"addSpec">;
7
+ pageRef: z.ZodString;
8
+ parentRef: z.ZodOptional<z.ZodString>;
9
+ position: z.ZodOptional<z.ZodEnum<{
10
+ before: "before";
11
+ after: "after";
12
+ inside: "inside";
13
+ }>>;
14
+ replaces: z.ZodOptional<z.ZodString>;
15
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
16
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
17
+ }, z.core.$strip>;
18
+ export type AddSpec = z.infer<typeof addSpecOp>;
19
+ /**
20
+ * The spec authored as a snippet: authoring reads every field it is handed and refuses what it cannot, in its words —
21
+ * the shapes are its own, checked there, never here. A key of its own per call: an element the spec does not name is
22
+ * given an id from it, new to the space.
23
+ */
24
+ export declare const authorSpec: (op: Pick<AddSpec, "spec" | "classes">) => {
25
+ authored: ReturnType<typeof authorSnippet>;
26
+ } | {
27
+ error: string;
28
+ };
29
+ export declare const addSpec: (space: Space, env: Env, op: AddSpec) => OpResult;
@@ -0,0 +1,118 @@
1
+ import { empty, fail } from "../../../../helpers/opResult.js";
2
+ import { defsUri, pageUri } from "../../../../helpers/uris.js";
3
+ import { findRootByRef, indexAddElement, indexRemoveElements, resolveRef } from "../../../../helpers/space.js";
4
+ import { MODES } from "../../style/write.js";
5
+ import { position } from "../shared.js";
6
+ import { DROP_POSITION } from "../write.js";
7
+ import { randomUUID } from "node:crypto";
8
+ import { FlatMap, descendants, documentIds } from "@plitzi/sdk-schema";
9
+ import { authorSnippet } from "@plitzi/sdk-authoring";
10
+ import { z } from "zod";
11
+ // src/modules/mcp/tools/operations/schema/elements/addSpec.ts
12
+ var addSpecOp = z.object({
13
+ type: z.literal("addSpec"),
14
+ pageRef: z.string().describe("The page or layout"),
15
+ parentRef: z.string().optional().describe("The element it goes relative to; the page when left out"),
16
+ position: position.optional(),
17
+ replaces: z.string().optional().describe("An element it takes the place of, with all under it: their ids are free for the spec to name again"),
18
+ spec: z.record(z.string(), z.unknown()).describe("An element as authoring writes one, as JSON (what `container({ … })` returns): `type`, `id`, `attributes`, `class`, `css`, `bind`, `flows`, `visible`, `children`"),
19
+ classes: z.record(z.string(), z.record(z.string(), z.unknown())).optional().describe("The classes it names, as `styles(name, { … })` takes them")
20
+ }).describe("An element tree in the authoring skill's vocabulary, with the classes it names; every id new, or one `replaces` frees");
21
+ var AUTHORING_HINT = "Write it as the authoring skill does (its CHEATSHEET); plitzi_describe_operation { type: \"addSpec\" } gives the fields";
22
+ /**
23
+ * The spec authored as a snippet: authoring reads every field it is handed and refuses what it cannot, in its words —
24
+ * the shapes are its own, checked there, never here. A key of its own per call: an element the spec does not name is
25
+ * given an id from it, new to the space.
26
+ */
27
+ var authorSpec = (op) => {
28
+ try {
29
+ const spec = {
30
+ name: "MCP",
31
+ description: "Written by an agent",
32
+ key: `mcp-${randomUUID().slice(0, 8)}`,
33
+ root: op.spec,
34
+ ...op.classes ? { classes: op.classes } : {}
35
+ };
36
+ return { authored: authorSnippet(spec) };
37
+ } catch (error) {
38
+ return { error: error instanceof Error ? error.message : String(error) };
39
+ }
40
+ };
41
+ /**
42
+ * Where the tree goes: relative to `parentRef`, or in the place of what `replaces` names — after the sibling before it,
43
+ * before the one after it, or inside its parent when it had none — with that element and all under it, which go.
44
+ */
45
+ var placementOf = (space, page, op) => {
46
+ if (op.replaces === void 0) {
47
+ const anchor = op.parentRef === void 0 ? page : resolveRef(space.schema, page, op.parentRef);
48
+ if (!anchor) return { error: fail("missing", "parentRef", `"${op.parentRef ?? ""}" is no element of "${op.pageRef}"`, "Use an existing ref") };
49
+ return {
50
+ anchor: anchor.id,
51
+ drop: DROP_POSITION[op.position ?? "inside"],
52
+ replaced: []
53
+ };
54
+ }
55
+ if (op.parentRef !== void 0 || op.position !== void 0) return { error: fail("bad-value", "replaces", "A tree that replaces an element takes its place: `parentRef` and `position` would name another", "Leave them out, or leave out `replaces` to add the tree beside it") };
56
+ const old = resolveRef(space.schema, page, op.replaces);
57
+ const parent = old?.definition.parentId === void 0 ? void 0 : space.schema.flat[old.definition.parentId];
58
+ if (!old || old.id === page.id || !parent) return { error: fail("missing", "replaces", `"${op.replaces}" is no element of "${op.pageRef}"`, "Read the page resource for valid refs") };
59
+ const replaced = [old, ...descendants(space.schema.flat, old.id).map((id) => space.schema.flat[id])];
60
+ const siblings = parent.definition.items ?? [];
61
+ const at = siblings.indexOf(old.id);
62
+ if (at > 0) return {
63
+ anchor: siblings[at - 1],
64
+ drop: "bottom",
65
+ replaced
66
+ };
67
+ if (at >= 0 && at < siblings.length - 1) return {
68
+ anchor: siblings[at + 1],
69
+ drop: "top",
70
+ replaced
71
+ };
72
+ return {
73
+ anchor: parent.id,
74
+ drop: "inside",
75
+ replaced
76
+ };
77
+ };
78
+ var addSpec = (space, env, op) => {
79
+ const page = findRootByRef(space.schema, op.pageRef);
80
+ if (!page) return fail("missing", "pageRef", `Page or layout "${op.pageRef}" not found`, "Read the pages resource for valid refs");
81
+ const target = placementOf(space, page, op);
82
+ if ("error" in target) return target.error;
83
+ const authoring = authorSpec(op);
84
+ if ("error" in authoring) return fail("bad-value", "spec", authoring.error, AUTHORING_HINT);
85
+ const { authored } = authoring;
86
+ const fragment = authored.snippet.schema.flat;
87
+ const rootId = authored.snippet.definition.baseElementId;
88
+ const taken = documentIds(space.schema);
89
+ const freed = new Set(target.replaced.map((element) => element.id));
90
+ const clashing = Object.keys(fragment).filter((id) => taken.has(id) && !freed.has(id));
91
+ if (clashing.length > 0) return fail("exists", "spec", `The space already has ${clashing.map((id) => `"${id}"`).join(", ")}`, "Name them anew, or edit the ones there with patchElement");
92
+ const root = fragment[rootId];
93
+ for (const element of Object.values(fragment)) element.definition.rootId = page.id;
94
+ const flatMap = new FlatMap({ flat: space.schema.flat });
95
+ if (target.replaced.length > 0) {
96
+ flatMap.removeElement(target.replaced[0].id);
97
+ indexRemoveElements(space.schema, target.replaced);
98
+ }
99
+ if (!flatMap.addElement(root, target.anchor, target.drop)) return fail("bad-value", "parentRef", `It cannot go ${op.position ?? "inside"} "${op.parentRef ?? op.pageRef}"`, "An element goes inside one that holds children, or before/after one that has a parent");
100
+ indexAddElement(space.schema, root, page.id);
101
+ for (const element of Object.values(fragment)) if (element.id !== rootId) {
102
+ space.schema.flat[element.id] = element;
103
+ indexAddElement(space.schema, element, page.id);
104
+ }
105
+ const declared = Object.keys(op.classes ?? {});
106
+ for (const mode of MODES) {
107
+ const rules = authored.snippet.style.platform[mode];
108
+ for (const name of declared) if (Object.hasOwn(rules, name)) space.style.platform[mode][name] = rules[name];
109
+ }
110
+ return {
111
+ ...empty(),
112
+ created: Object.keys(fragment).length,
113
+ ...target.replaced.length > 0 ? { deleted: 1 } : {},
114
+ elementRefs: Object.keys(fragment),
115
+ staleResources: [pageUri(env, op.pageRef), ...declared.length > 0 ? [defsUri(env)] : []]
116
+ };
117
+ };
118
+ export { addSpec, addSpecOp, authorSpec };
@@ -11,9 +11,9 @@ var deleteElementOp = z.object({
11
11
  }).describe("Delete an element and all of its descendants from a page.");
12
12
  var deleteElement = (space, env, op) => {
13
13
  const page = findRootByRef(space.schema, op.pageRef);
14
- if (!page) return fail("pageRef", `Page or layout "${op.pageRef}" not found`, "Read the pages resource for valid refs");
14
+ if (!page) return fail("missing", "pageRef", `Page or layout "${op.pageRef}" not found`, "Read the pages resource for valid refs");
15
15
  const el = resolveRef(space.schema, page, op.ref);
16
- if (!el || el.id === page.id) return fail("ref", `Element "${op.ref}" not found in page "${op.pageRef}"`, "Read the page resource for valid refs");
16
+ if (!el || el.id === page.id) return fail("missing", "ref", `Element "${op.ref}" not found in page "${op.pageRef}"`, "Read the page resource for valid refs");
17
17
  const removed = [el.id, ...descendants(space.schema.flat, el.id)].map((id) => space.schema.flat[id]);
18
18
  new FlatMap({ flat: space.schema.flat }).removeElement(el.id);
19
19
  indexRemoveElements(space.schema, removed);
@@ -15,12 +15,12 @@ var moveElementOp = z.object({
15
15
  }).describe("Move an existing element to a new parent, or reorder it — its placement is set by position.");
16
16
  var moveElement = (space, env, op) => {
17
17
  const page = findRootByRef(space.schema, op.pageRef);
18
- if (!page) return fail("pageRef", `Page or layout "${op.pageRef}" not found`, "Read the pages resource for valid refs");
18
+ if (!page) return fail("missing", "pageRef", `Page or layout "${op.pageRef}" not found`, "Read the pages resource for valid refs");
19
19
  const el = resolveRef(space.schema, page, op.ref);
20
20
  const anchor = resolveRef(space.schema, page, op.toParentRef);
21
- if (!el || el.id === page.id) return fail("ref", `Element "${op.ref}" not found`, "Read the page resource for valid refs");
22
- if (!anchor) return fail("toParentRef", `Target "${op.toParentRef}" not found`, "Read the page resource for valid refs");
23
- if (!new FlatMap({ flat: space.schema.flat }).moveElement(el.definition.parentId ?? page.id, anchor.id, el.id, DROP_POSITION[op.position])) return fail("toParentRef", `"${op.ref}" cannot move ${op.position} "${op.toParentRef}"`, "An element cannot move inside itself or one of its own descendants, and before/after needs an anchor that has a parent.");
21
+ if (!el || el.id === page.id) return fail("missing", "ref", `Element "${op.ref}" not found`, "Read the page resource for valid refs");
22
+ if (!anchor) return fail("missing", "toParentRef", `Target "${op.toParentRef}" not found`, "Read the page resource for valid refs");
23
+ if (!new FlatMap({ flat: space.schema.flat }).moveElement(el.definition.parentId ?? page.id, anchor.id, el.id, DROP_POSITION[op.position])) return fail("bad-value", "toParentRef", `"${op.ref}" cannot move ${op.position} "${op.toParentRef}"`, "An element cannot move inside itself or one of its own descendants, and before/after needs an anchor that has a parent.");
24
24
  indexInvalidateDetails(space.schema);
25
25
  return {
26
26
  ...empty(),
@@ -26,9 +26,9 @@ var patchElementOp = z.object({
26
26
  }).describe("Partially update an EXISTING element: only the fields you pass change (props/style/initialState are merged, not replaced). Never creates — fails if ref does not resolve. Use upsertElement to create or fully replace.");
27
27
  var patchElement = (space, env, op) => {
28
28
  const page = findRootByRef(space.schema, op.pageRef);
29
- if (!page) return fail("pageRef", `Page or layout "${op.pageRef}" not found`, "Read plitzi://schema/" + env + "/pages for valid refs");
29
+ if (!page) return fail("missing", "pageRef", `Page or layout "${op.pageRef}" not found`, "Read plitzi://schema/" + env + "/pages for valid refs");
30
30
  const el = resolveRef(space.schema, page, op.ref);
31
- if (!el || el.id === page.id) return fail("ref", `Element "${op.ref}" not found in page "${op.pageRef}"`, "patchElement only updates an existing element; use upsertElement to create one");
31
+ if (!el || el.id === page.id) return fail("missing", "ref", `Element "${op.ref}" not found in page "${op.pageRef}"`, "patchElement only updates an existing element; use upsertElement to create one");
32
32
  if (op.rename !== void 0 && op.rename !== el.id) {
33
33
  const guard = guardNewRef(space, op.rename, "rename");
34
34
  if (guard) return guard;
@@ -96,6 +96,7 @@ var expandNode = (node, row, suffix, state) => {
96
96
  return element;
97
97
  };
98
98
  var rowError = (index, message, hint) => ({
99
+ code: "bad-value",
99
100
  path: `items[${index}]`,
100
101
  message,
101
102
  hint
@@ -129,6 +130,7 @@ var expandRepeat = (op) => {
129
130
  }
130
131
  if (errors.length > 0) return { errors };
131
132
  if (total > MAX_ROWS) return { errors: [{
133
+ code: "bad-value",
132
134
  path: "items",
133
135
  message: `This repeat expands to ${total} rows (max ${MAX_ROWS})`,
134
136
  hint: "Shorten the lists, or split the widget into several repeats."
@@ -16,7 +16,7 @@ var upsertElementOp = z.object({
16
16
  }).describe("Add an element to a page, or fully update it when element.ref already exists (props and style are REPLACED, not merged). To change only some fields of an existing element, use patchElement instead.");
17
17
  var upsertElement = (space, env, op) => {
18
18
  const page = findRootByRef(space.schema, op.pageRef);
19
- if (!page) return fail("pageRef", `Page or layout "${op.pageRef}" not found`, "Read plitzi://schema/" + env + "/pages for valid refs");
19
+ if (!page) return fail("missing", "pageRef", `Page or layout "${op.pageRef}" not found`, "Read plitzi://schema/" + env + "/pages for valid refs");
20
20
  const existing = resolveRef(space.schema, page, op.element.ref);
21
21
  if (existing && existing.id !== page.id) {
22
22
  if (op.element.label !== void 0) existing.definition.label = op.element.label;
@@ -53,11 +53,11 @@ var upsertElement = (space, env, op) => {
53
53
  let drop = "inside";
54
54
  if (op.parentRef) {
55
55
  const anchor = resolveRef(space.schema, page, op.parentRef);
56
- if (!anchor) return fail("parentRef", `Parent "${op.parentRef}" not found in page "${op.pageRef}"`, "Use an existing ref");
56
+ if (!anchor) return fail("missing", "parentRef", `Parent "${op.parentRef}" not found in page "${op.pageRef}"`, "Use an existing ref");
57
57
  anchorId = anchor.id;
58
58
  drop = DROP_POSITION[op.position ?? "inside"];
59
59
  }
60
- if (!createElement(space, page, op.element, anchorId, drop)) return fail("parentRef", `"${op.element.ref}" cannot be placed ${op.position ?? "inside"} "${op.parentRef ?? op.pageRef}"`, "An element goes inside an element that holds children, or before/after one that has a parent — a page has no siblings.");
60
+ if (!createElement(space, page, op.element, anchorId, drop)) return fail("bad-value", "parentRef", `"${op.element.ref}" cannot be placed ${op.position ?? "inside"} "${op.parentRef ?? op.pageRef}"`, "An element goes inside an element that holds children, or before/after one that has a parent — a page has no siblings.");
61
61
  return {
62
62
  ...empty(),
63
63
  created: 1,
@@ -8,7 +8,7 @@ var deleteFlagOp = z.object({
8
8
  }).describe("Remove a feature flag.");
9
9
  var deleteFlag = (space, env, op) => {
10
10
  const flags = space.schema.flags ?? {};
11
- if (!Object.hasOwn(flags, op.name)) return fail("name", `The space declares no flag "${op.name}"`, `Read ${flagsUri(env)}`);
11
+ if (!Object.hasOwn(flags, op.name)) return fail("missing", "name", `The space declares no flag "${op.name}"`, `Read ${flagsUri(env)}`);
12
12
  const { [op.name]: _removed, ...rest } = flags;
13
13
  space.schema.flags = rest;
14
14
  return {
@@ -16,13 +16,13 @@ var upsertFlagOp = z.object({
16
16
  rules: z.array(ruleInput).optional()
17
17
  }).describe("Declare or replace a feature flag (guide: Feature flags).");
18
18
  var upsertFlag = (space, env, op) => {
19
- if (!isFlagName(op.name)) return fail("name", `"${op.name}" is not a flag name`, "Letters, digits and \"_\", starting with a letter or \"_\"");
19
+ if (!isFlagName(op.name)) return fail("bad-value", "name", `"${op.name}" is not a flag name`, "Letters, digits and \"_\", starting with a letter or \"_\"");
20
20
  const flag = {
21
21
  ...op.description ? { description: op.description } : {},
22
22
  value: op.value,
23
23
  rules: op.rules ?? []
24
24
  };
25
- if (!isSchemaFlag(flag)) return fail("rules", "A rule is { when: { combinator, rules: [...] }, value: true | false }", "Fix the rule groups");
25
+ if (!isSchemaFlag(flag)) return fail("bad-value", "rules", "A rule is { when: { combinator, rules: [...] }, value: true | false }", "Fix the rule groups");
26
26
  const existed = Object.hasOwn(space.schema.flags ?? {}, op.name);
27
27
  space.schema.flags = {
28
28
  ...space.schema.flags,
@@ -10,7 +10,7 @@ var deleteFolderOp = z.object({
10
10
  var deleteFolder = (space, env, op) => {
11
11
  const folders = pageFoldersOf(space.schema);
12
12
  const folder = findFolderByRef(space.schema, op.ref);
13
- if (!folder) return fail("ref", `Folder "${op.ref}" not found`, "Read plitzi://folders for valid refs");
13
+ if (!folder) return fail("missing", "ref", `Folder "${op.ref}" not found`, "Read plitzi://folders for valid refs");
14
14
  const newParent = folder.parentId;
15
15
  for (const child of folders) if (child.parentId === folder.id) {
16
16
  if (newParent === void 0) Reflect.deleteProperty(child, "parentId");
@@ -15,7 +15,7 @@ var upsertFolder = (space, env, op) => {
15
15
  let parentId;
16
16
  if (op.parentId !== void 0 && op.parentId !== null) {
17
17
  const parent = findFolderByRef(space.schema, op.parentId);
18
- if (!parent) return fail("parentId", `Parent folder "${op.parentId}" not found`, "Create it with upsertFolder first");
18
+ if (!parent) return fail("missing", "parentId", `Parent folder "${op.parentId}" not found`, "Create it with upsertFolder first");
19
19
  parentId = parent.id;
20
20
  }
21
21
  const existing = findFolderByRef(space.schema, op.ref);
@@ -5,6 +5,7 @@ export * from './elements/upsertElement';
5
5
  export * from './elements/repeatElement';
6
6
  export * from './elements/patchElement';
7
7
  export * from './elements/deleteElement';
8
+ export * from './elements/addSpec';
8
9
  export * from './elements/moveElement';
9
10
  export * from './pages/upsertPage';
10
11
  export * from './pages/upsertLayout';
@@ -19,15 +19,15 @@ var removeFlow = (interactions, flowId) => {
19
19
  return deleted;
20
20
  };
21
21
  var deleteInteraction = (space, env, op) => {
22
- if (Boolean(op.flowId) === Boolean(op.nodeId)) return fail("nodeId", "Provide exactly one of flowId or nodeId", "flowId removes a whole flow; nodeId removes a step");
22
+ if (Boolean(op.flowId) === Boolean(op.nodeId)) return fail("wrong-options", "nodeId", "Provide exactly one of flowId or nodeId", "flowId removes a whole flow; nodeId removes a step");
23
23
  const found = resolveElement(space, env, op.pageRef, op.ref);
24
24
  if ("error" in found) return found.error;
25
25
  const interactions = found.el.definition.interactions;
26
- if (!interactions) return fail("ref", `Element "${op.ref}" has no interactions`, "Nothing to delete");
26
+ if (!interactions) return fail("missing", "ref", `Element "${op.ref}" has no interactions`, "Check the ref: read the element to see the flows it holds");
27
27
  let deleted = 0;
28
28
  if (op.flowId) deleted = removeFlow(interactions, op.flowId);
29
29
  else if (op.nodeId) {
30
- if (!(op.nodeId in interactions)) return fail("nodeId", `Interaction node "${op.nodeId}" not found on "${op.ref}"`, "Read the element to list nodes");
30
+ if (!(op.nodeId in interactions)) return fail("missing", "nodeId", `Interaction node "${op.nodeId}" not found on "${op.ref}"`, "Read the element to list nodes");
31
31
  const node = interactions[op.nodeId];
32
32
  if (node.type === "trigger") deleted = removeFlow(interactions, node.flowId || node.id);
33
33
  else {
@@ -39,7 +39,7 @@ var deleteInteraction = (space, env, op) => {
39
39
  deleted = 1;
40
40
  }
41
41
  }
42
- if (deleted === 0) return fail("flowId", `No interaction matching "${op.flowId ?? op.nodeId}" on "${op.ref}"`, "Nothing to delete");
42
+ if (deleted === 0) return fail("missing", "flowId", `No interaction matching "${op.flowId ?? op.nodeId}" on "${op.ref}"`, "Read the element to list its flows and their nodes, and name one of them");
43
43
  if (Object.keys(interactions).length === 0) Reflect.deleteProperty(found.el.definition, "interactions");
44
44
  return {
45
45
  ...empty(),
@@ -24,7 +24,7 @@ var patchInteractionNode = (space, env, op) => {
24
24
  const found = resolveElement(space, env, op.pageRef, op.ref);
25
25
  if ("error" in found) return found.error;
26
26
  const node = found.el.definition.interactions?.[op.nodeId];
27
- if (!node) return fail("nodeId", `Interaction node "${op.nodeId}" not found on "${op.ref}"`, "Read the element to list nodes");
27
+ if (!node) return fail("missing", "nodeId", `Interaction node "${op.nodeId}" not found on "${op.ref}"`, "Read the element to list nodes");
28
28
  if (op.title !== void 0) node.title = op.title;
29
29
  if (op.action !== void 0) node.action = op.action;
30
30
  if (op.params !== void 0) node.params = {