Merge branch 'feat/graph-construction-call'

# Conflicts:
#	src/graph/construction.ts
#	test/graph/construction.test.ts
This commit is contained in:
2026-05-21 22:06:51 +00:00
6 changed files with 784 additions and 41 deletions

View File

@@ -88,6 +88,7 @@ export class WorkflowReactiveRoot implements EventLogProjection {
blockedByFailure: Map<string, ReadonlySignal<boolean>>;
resultMap: Map<string, ReadonlySignal<CallResult | undefined>>;
nodeKeyToRequestId: Map<string, string>;
requestIdToNodeKey: Map<string, string>;
private graph: DirectedGraph;
private effectDisposers: (() => void)[];
@@ -106,10 +107,16 @@ export class WorkflowReactiveRoot implements EventLogProjection {
this.effectDisposers = [];
this.eventLog = [];
this.nodeKeyToRequestId = new Map();
this.requestIdToNodeKey = new Map();
this._failurePolicy = options?.failurePolicy ?? "continue-running";
this.initializeSignals();
}
setRequestId(nodeKey: string, requestId: string): void {
this.nodeKeyToRequestId.set(nodeKey, requestId);
this.requestIdToNodeKey.set(requestId, nodeKey);
}
private initializeSignals(): void {
for (const node of this.graph.nodes()) {
const predecessors: string[] = this.graph.inNeighbors(node) ?? [];
@@ -213,15 +220,29 @@ export class WorkflowReactiveRoot implements EventLogProjection {
if (!("requestId" in event)) return;
const nodeId = this.findNodeByRequestId(event.requestId);
let nodeId = this.requestIdToNodeKey.get(event.requestId);
if (nodeId === undefined) {
for (const [nId, rid] of this.nodeKeyToRequestId) {
if (rid === event.requestId) {
nodeId = nId;
this.requestIdToNodeKey.set(event.requestId, nId);
break;
}
}
}
if (nodeId === undefined) return;
const statusSignal = this.statusMap.get(nodeId);
if (!statusSignal) return;
const currentRequestId = this.nodeKeyToRequestId.get(nodeId);
if (currentRequestId === event.requestId) {
const statusSignal = this.statusMap.get(nodeId);
if (!statusSignal) return;
const derived = EVENT_TO_STATUS[event.type];
if (derived !== undefined) {
statusSignal.value = derived;
const derived = EVENT_TO_STATUS[event.type];
if (derived !== undefined) {
statusSignal.value = derived;
}
}
}
@@ -254,12 +275,17 @@ export class WorkflowReactiveRoot implements EventLogProjection {
}
getEvents(nodeId: string): CallEventMapValue[] {
const requestId = this.nodeKeyToRequestId.get(nodeId);
if (!requestId) return [];
const requestIds = new Set<string>();
for (const [rid, nId] of this.requestIdToNodeKey) {
if (nId === nodeId) {
requestIds.add(rid);
}
}
if (requestIds.size === 0) return [];
const events: CallEventMapValue[] = [];
for (const e of this.eventLog) {
if ("requestId" in e && e.requestId === requestId) {
if ("requestId" in e && requestIds.has(e.requestId)) {
events.push(e);
}
}
@@ -325,13 +351,7 @@ export class WorkflowReactiveRoot implements EventLogProjection {
this.blockedByFailure.clear();
this.resultMap.clear();
this.nodeKeyToRequestId.clear();
this.requestIdToNodeKey.clear();
this.eventLog = [];
}
private findNodeByRequestId(requestId: string): string | undefined {
for (const [nodeId, rid] of this.nodeKeyToRequestId) {
if (rid === requestId) return nodeId;
}
return undefined;
}
}