Skip to content

Commit 148c93f

Browse files
committed
connect ai-worker to flow-engine and be able to update ui nodes in the new structure
1 parent 1e80b93 commit 148c93f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

apps/vps-web/src/app/ai-flow-engine-worker/ai-flow-engine-worker.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,25 @@ self.addEventListener('message', (event: MessageEvent<AIWorkerMessage>) => {
9595
} as IComputeResult,
9696
});
9797
};
98-
flowEngine.initialize(data.flow.flows['flow'].nodes, registerWorkerNodes);
98+
flowEngine.initialize(
99+
data.flow.flows['flow'].nodes,
100+
registerWorkerNodes,
101+
{
102+
sendOutputToNode: (data, node) => {
103+
//console.log('sendOutputToNode', data, node);
104+
if (node.nodeInfo?.shouldNotSendOutputFromWorkerToMainThread) {
105+
return;
106+
}
107+
self.postMessage({
108+
message: 'node-update',
109+
result: {
110+
result: node.id,
111+
output: data,
112+
} as IComputeResult,
113+
});
114+
},
115+
}
116+
);
99117
flowEngine.canvasApp.elements.forEach((node) => {
100118
if (node && node.nodeInfo) {
101119
node.nodeInfo.offscreenCanvas = undefined;

apps/vps-web/src/app/flow-engine/flow-engine.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
import { CreateRunCounterContext } from '../custom-nodes/classes/base-rect-node-class';
3131

3232
export class RuntimeFlowEngine {
33-
public canvasApp: IFlowCanvasBase<NodeInfo>;
33+
public canvasApp: IFlowCanvasBase<NodeInfo, FlowEngine>;
3434
constructor() {
3535
this.canvasApp = createRuntimeFlowContext<NodeInfo>();
3636
}
@@ -43,7 +43,8 @@ export class RuntimeFlowEngine {
4343
registerNodeFactory: RegisterNodeFactoryFunction,
4444
createRunCounterContext: CreateRunCounterContext,
4545
flowEngine?: FlowEngine
46-
) => void
46+
) => void,
47+
flowEngine?: FlowEngine
4748
) {
4849
if (!this.canvasApp) {
4950
throw new Error('CanvasAppInstance not initialized');
@@ -73,7 +74,9 @@ export class RuntimeFlowEngine {
7374
},
7475
undefined,
7576
0,
76-
getNodeTaskFactory
77+
getNodeTaskFactory,
78+
undefined,
79+
flowEngine
7780
);
7881

7982
this.canvasApp.setAnimationFunctions({

0 commit comments

Comments
 (0)