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:
2026-06-14 12:23:22 +04:00
parent 7b4f76c1de
commit b7145c325b
2 changed files with 37 additions and 26 deletions
+19 -12
View File
@@ -120,30 +120,37 @@ export const wizardApi = {
return api.startTransaction(process_definition_id, business_subject, signal);
},
/** Helpers so call sites don't have to know the discriminated-union shape by heart. */
ops: {
createNode(flowKey: string, node: { _key: string; display_name: string; dispatch_kind: string; agent_capability?: string }): CreateOp {
const { _key, ...rest } = node;
createStep(node: { display_name: string; dispatch_kind: string; agent_capability?: string; description?: string }): CreateOp {
const name = node.display_name.toLowerCase().replace(/[^a-z0-9]+/g, "_").slice(0, 40) || "step";
return {
op: "create",
coll: "ea2_node",
data: { _key, flow_key: flowKey, ...rest },
coll: "flow",
data: {
kind: "definition",
name,
display_name: node.display_name,
status: "draft",
description: node.description || node.display_name,
source_context: "EA2_WIZARD_STEP",
dispatch_kind: node.dispatch_kind,
...(node.agent_capability ? { agent_capability: node.agent_capability } : {}),
},
};
},
createEdge(_flowKey: string, fromKey: string, toKey: string, role = "next"): CreateEdgeOp {
// EA2 server rejects `data` on create_edge despite the OpenAPI schema marking it optional.
createStepEdge(parentFlowKey: string, childFlowKey: string): CreateEdgeOp {
return {
op: "create_edge",
edge_coll: "ea2_edge",
from: `ea2_node/${fromKey}`,
to: `ea2_node/${toKey}`,
role,
edge_coll: "defines",
from: `flow/${parentFlowKey}`,
to: `flow/${childFlowKey}`,
role: "next",
};
},
publishFlow(flowKey: string): UpdateOp {
return {
op: "update",
coll: "ea2_flow",
coll: "flow",
key: flowKey,
data: { status: "published" },
};