@avocadostudio-ai/orchestrator-core 0.27.0 → 0.28.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.
@@ -766,6 +766,73 @@ function _requireListDiscriminator(manifestByType, blockType, listKey, item) {
766
766
  const choices = admissible.length > 0 ? `: ${admissible.join(", ")}` : "";
767
767
  throw new OperationError(`A new ${listKey} row must set "${discriminator}", which names its type${choices}`, { category: "schema_violation" });
768
768
  }
769
+ /*
770
+ * A list row must use the list's own field names.
771
+ *
772
+ * Integrations declare item schemas loose, so bookkeeping keys a CMS adds
773
+ * (`_type`, `_key`) ride through validation, and every field is optional. Such
774
+ * a schema accepts any object. A planner that had just written Avocado's
775
+ * built-in FAQ shape, `{ q, a }`, into a site whose accordion reads
776
+ * `{ title, body }` got an "applied" and a row that rendered empty, with the
777
+ * text present in the draft under names nothing reads.
778
+ *
779
+ * So a key is refused when the list neither declares it nor already holds it
780
+ * on another row: copying an existing row, undeclared keys and all, still
781
+ * works, and only a name the list has never seen is refused. The error names
782
+ * the fields the list does use, so the planner can correct itself. Lists with
783
+ * no declared item fields are left alone, since there is nothing to check
784
+ * against.
785
+ */
786
+ /** Property names an item of `listKey` may carry, per the block's JSON Schema. */
787
+ function _schemaItemKeys(definition, listKey) {
788
+ const props = definition.propsSchema?.properties;
789
+ const listSchema = props?.[listKey];
790
+ const keys = new Set();
791
+ const visit = (node) => {
792
+ if (!node || typeof node !== "object")
793
+ return;
794
+ const n = node;
795
+ for (const key of Object.keys(n.properties ?? {}))
796
+ keys.add(key);
797
+ for (const branch of [...(n.oneOf ?? []), ...(n.anyOf ?? []), ...(n.allOf ?? [])])
798
+ visit(branch);
799
+ };
800
+ visit(listSchema?.items);
801
+ return [...keys];
802
+ }
803
+ function _requireKnownItemKeys(manifestByType, blockType, listKey, list, item) {
804
+ const definition = manifestByType.get(blockType);
805
+ if (!definition)
806
+ return;
807
+ const listField = resolveManifestFieldMeta(definition).listFields[listKey];
808
+ if (!listField)
809
+ return;
810
+ const declared = new Set(Object.keys(listField.itemFields ?? {}));
811
+ for (const fields of Object.values(listField.itemFieldsByType ?? {})) {
812
+ for (const key of Object.keys(fields ?? {}))
813
+ declared.add(key);
814
+ }
815
+ if (listField.discriminator)
816
+ declared.add(listField.discriminator);
817
+ // The props schema names every item property, optional ones included; the
818
+ // field meta above names only what the panel offers.
819
+ for (const key of _schemaItemKeys(definition, listKey))
820
+ declared.add(key);
821
+ if (declared.size === 0)
822
+ return;
823
+ const known = new Set(declared);
824
+ for (const row of list) {
825
+ if (row && typeof row === "object" && !Array.isArray(row)) {
826
+ for (const key of Object.keys(row))
827
+ known.add(key);
828
+ }
829
+ }
830
+ const unknown = Object.keys(item).filter((key) => key !== "id" && !key.startsWith("_") && !known.has(key));
831
+ if (unknown.length === 0)
832
+ return;
833
+ throw new OperationError(`${listKey} rows have no field ${unknown.map((k) => `"${k}"`).join(", ")}. ` +
834
+ `Use the list's own fields: ${[...declared].join(", ")}`, { category: "schema_violation" });
835
+ }
769
836
  function _requireManifestComponent(manifestByType, blockType, operationName) {
770
837
  if (manifestByType.size === 0)
771
838
  return;
@@ -1449,6 +1516,7 @@ async function _applyOpsAtomicallyUnsafe(session, ops, options) {
1449
1516
  // silently resolve to the first occurrence.
1450
1517
  const newItem = structuredClone(op.item);
1451
1518
  _requireListDiscriminator(manifestByType, block.type, op.listKey, newItem);
1519
+ _requireKnownItemKeys(manifestByType, block.type, op.listKey, list, newItem);
1452
1520
  if (typeof newItem.id !== "string" ||
1453
1521
  newItem.id.length === 0 ||
1454
1522
  _itemIndexById(nextList, newItem.id) !== -1) {
@@ -1476,6 +1544,7 @@ async function _applyOpsAtomicallyUnsafe(session, ops, options) {
1476
1544
  // A patch must never clobber the stable item id (it's the addressing key).
1477
1545
  const itemPatch = { ...op.patch };
1478
1546
  delete itemPatch.id;
1547
+ _requireKnownItemKeys(manifestByType, block.type, op.listKey, list, itemPatch);
1479
1548
  const nextList = list.map((entry, idx) => {
1480
1549
  if (idx !== targetIndex)
1481
1550
  return entry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avocadostudio-ai/orchestrator-core",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -22,8 +22,8 @@
22
22
  "openai": "^4.87.1",
23
23
  "sharp": "^0.35.4",
24
24
  "zod": "^4.3.6",
25
- "@avocadostudio-ai/migration-sdk": "^0.27.0",
26
- "@avocadostudio-ai/shared": "^0.27.0"
25
+ "@avocadostudio-ai/migration-sdk": "^0.28.0",
26
+ "@avocadostudio-ai/shared": "^0.28.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@anthropic-ai/claude-agent-sdk": "^0.3.220",