fix(wizard): use real EA2 flow/defines collections for steps
EA2's apply-batch doc collections are restricted to ['data','flow','rule', 'version','view']; there is no 'ea2_node'. Steps are themselves 'flow' documents (kind='definition') linked to the parent flow via the 'defines' edge collection with role='next' (or 'presentation'). handleStructureSave now does two batches: 1) create N step flows, capture server-assigned keys 2) wire parent->step1->...->stepN with create_edge on 'defines'
This commit is contained in:
+18
-14
@@ -103,23 +103,27 @@ export default function Wizard() {
|
||||
if (!draft.flowKey || !actor) return;
|
||||
setWorking(true);
|
||||
try {
|
||||
const ops: BatchOperation[] = [
|
||||
...draft.nodes.map(n =>
|
||||
wizardApi.ops.createNode(draft.flowKey!, {
|
||||
_key: n._key,
|
||||
display_name: n.display_name,
|
||||
dispatch_kind: n.dispatch_kind,
|
||||
agent_capability: n.agent_capability,
|
||||
})
|
||||
),
|
||||
...draft.nodes.slice(0, -1).map((n, i) =>
|
||||
wizardApi.ops.createEdge(draft.flowKey!, n._key, draft.nodes[i + 1]._key, "next")
|
||||
const createOps: BatchOperation[] = draft.nodes.map(n =>
|
||||
wizardApi.ops.createStep({
|
||||
display_name: n.display_name,
|
||||
dispatch_kind: n.dispatch_kind,
|
||||
agent_capability: n.agent_capability,
|
||||
})
|
||||
);
|
||||
const createRes = await wizardApi.applyBatch(draft.flowKey, createOps, actor);
|
||||
const createdKeys: string[] = (createRes?.result?.ops || []).map((o: any) => o.key);
|
||||
const nodesWithKeys = draft.nodes.map((n, i) => ({ ...n, _key: createdKeys[i] || n._key }));
|
||||
|
||||
const linkOps: BatchOperation[] = [
|
||||
wizardApi.ops.createStepEdge(draft.flowKey!, nodesWithKeys[0]._key),
|
||||
...nodesWithKeys.slice(0, -1).map((n, i) =>
|
||||
wizardApi.ops.createStepEdge(n._key, nodesWithKeys[i + 1]._key)
|
||||
),
|
||||
];
|
||||
if (linkOps.length) await wizardApi.applyBatch(draft.flowKey, linkOps, actor);
|
||||
|
||||
await wizardApi.applyBatch(draft.flowKey, ops, actor);
|
||||
updateDraft({ step: "Generate" });
|
||||
pushToast("ok", "Structure saved");
|
||||
updateDraft({ step: "Generate", nodes: nodesWithKeys });
|
||||
pushToast("ok", `Saved ${createdKeys.length} steps to EA2`);
|
||||
} catch (err: any) {
|
||||
pushToast("err", `Save failed: ${err.message}`);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user