Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
feat(workflow-ops): saved batches can take an edge out
trohitg93b79a495b19
diff --git a/client/src/lib/__tests__/workflowOps.test.ts b/client/src/lib/__tests__/workflowOps.test.tsindex 1ba661da..ed700f7a 100644--- a/client/src/lib/__tests__/workflowOps.test.ts+++ b/client/src/lib/__tests__/workflowOps.test.ts@@ -292,6 +292,16 @@ describe('addSavedNodes / addSavedEdges', () => {expect(addSavedEdges([drawn], SAVED)).toEqual([drawn]);});++ it('takes out the edges the batch took out', () => {+ const direct: Edge = { id: 'e-agent-reply', source: '7:aiAgent:1', target: '7:whatsappSend:1', sourceHandle: 'output-main', targetHandle: 'input-main' };+ const ops: WorkflowOperation[] = [{ type: 'delete_edge', edge_id: 'e-agent-reply' }, ...SAVED];++ const edges = addSavedEdges([direct], ops);++ expect(edges.map((edge) => edge.id)).toEqual(['e-7:duckduckgoSearch:1-output-tool-7:aiAgent:1-input-tools']);+ expect(addSavedEdges(edges, ops)).toBe(edges);+ });});// ----- add_edge --------------------------------------------------------------diff --git a/client/src/lib/workflowOps.ts b/client/src/lib/workflowOps.tsindex ad90830d..7a95f7b7 100644--- a/client/src/lib/workflowOps.ts+++ b/client/src/lib/workflowOps.ts@@ -214,13 +214,19 @@ export function addSavedNodes(nodes: Node[], ops: WorkflowOperation[]): Node[] {}/**- * `edges` with the new edges of a saved batch, under the server's ids. An- * edge already there (the same id, or the same ends and handles) is- * skipped. Returns `edges` itself when nothing is new.+ * `edges` as a saved batch left them: its new edges, under the server's+ * ids, and without the ones it took out (`delete_edge`: a gate put between+ * an agent and its reply takes that edge's place). An edge already there+ * (the same id, or the same ends and handles) is skipped. Returns `edges`+ * itself when nothing changed.*/export function addSavedEdges(edges: Edge[], ops: WorkflowOperation[]): Edge[] {let next = edges;for (const op of ops) {+ if (op.type === 'delete_edge') {+ if (next.some(e => e.id === op.edge_id)) next = next.filter(e => e.id !== op.edge_id);+ continue;+ }if (op.type !== 'add_edge' || typeof op.source !== 'string' || typeof op.target !== 'string') continue;const edge = edgeFromOp(op, op.source, op.target);const known = next.some(e => e.id === edge.id || (