This commit is contained in:
geoffsee
2025-05-22 23:14:01 -04:00
commit 33679583af
242 changed files with 15090 additions and 0 deletions

View File

@@ -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");
}
}