Skip to content

Commit

Permalink
fix interactive edge
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jan 25, 2025
1 parent d2948d7 commit 16ed2ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/global/core/workflow/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ export const checkNodeRunStatus = ({
currentNode: node
});

// check skip(其中一组边,全 skip
// check skip(其中一组边,全是 skiped 则跳过运行
if (commonEdges.length > 0 && commonEdges.every((item) => item.status === 'skipped')) {
return 'skip';
}
if (recursiveEdges.length > 0 && recursiveEdges.every((item) => item.status === 'skipped')) {
return 'skip';
}

// check active(有一类边,不全是 wait 即可运行)
// check active(其中一组边,全不是 waiting 即可运行)
if (commonEdges.length > 0 && commonEdges.every((item) => item.status !== 'waiting')) {
return 'run';
}
Expand Down
25 changes: 24 additions & 1 deletion packages/service/core/workflow/dispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,35 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
});
});

const entryNodeSet = new Set(entryNodeIds);
const canReachEntry = (
edge: RuntimeEdgeItemType,
visited: Set<string> = new Set()
): boolean => {
const target = edge.target;
if (entryNodeSet.has(target)) return true;

if (visited.has(target)) return false;

visited.add(target);
const canReach = runtimeEdges
.filter((e) => e.source === target)
.some((nextEdge) => canReachEntry(nextEdge, new Set(visited)));

visited.delete(target);
return canReach;
};

const interactiveResult: WorkflowInteractiveResponseType = {
...interactiveResponse,
entryNodeIds,
memoryEdges: runtimeEdges.map((edge) => ({
...edge,
status: entryNodeIds.includes(edge.target) ? 'active' : edge.status
status: entryNodeSet.has(edge.target)
? 'active'
: canReachEntry(edge)
? edge.status
: 'waiting' // 未执行过的边,重置状态为waiting
})),
nodeOutputs
};
Expand Down

0 comments on commit 16ed2ab

Please sign in to comment.