mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
init
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { createPreprocessingWorkflow } from "./createPreprocessingWorkflow";
|
||||
|
||||
export async function executePreprocessingWorkflow({
|
||||
latestUserMessage,
|
||||
latestAiMessage,
|
||||
eventHost,
|
||||
streamId,
|
||||
chat: { messages, openai },
|
||||
}) {
|
||||
console.log(`Executing executePreprocessingWorkflow`);
|
||||
const initialState = { latestUserMessage, latestAiMessage };
|
||||
|
||||
// Add execution tracking flag to prevent duplicate runs
|
||||
const executionKey = `preprocessing-${crypto.randomUUID()}`;
|
||||
if (globalThis[executionKey]) {
|
||||
console.log("Preventing duplicate preprocessing workflow execution");
|
||||
return globalThis[executionKey];
|
||||
}
|
||||
|
||||
const workflows = {
|
||||
preprocessing: createPreprocessingWorkflow({
|
||||
eventHost,
|
||||
initialState,
|
||||
streamId,
|
||||
chat: { messages, openai },
|
||||
}),
|
||||
results: new Map(),
|
||||
};
|
||||
|
||||
try {
|
||||
// Store the promise to prevent parallel executions
|
||||
globalThis[executionKey] = (async () => {
|
||||
await workflows.preprocessing.navigate(latestUserMessage);
|
||||
await workflows.preprocessing.executeWorkflow(latestUserMessage);
|
||||
console.log(
|
||||
`executePreprocessingWorkflow::workflow::preprocessing::results`,
|
||||
{ state: JSON.stringify(workflows.preprocessing.state, null, 2) },
|
||||
);
|
||||
workflows.results.set("preprocessed", workflows.preprocessing.state);
|
||||
|
||||
// Cleanup after execution
|
||||
setTimeout(() => {
|
||||
delete globalThis[executionKey];
|
||||
}, 1000);
|
||||
|
||||
return workflows;
|
||||
})();
|
||||
|
||||
return await globalThis[executionKey];
|
||||
} catch (error) {
|
||||
delete globalThis[executionKey];
|
||||
throw new Error("Workflow execution failed");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user