From 24319744c32d1344d2e3cfb29a21918fa9ff3919 Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Tue, 3 Feb 2026 19:19:26 -0800 Subject: [PATCH] Streaming seems to work but copilot is dumb --- apps/sim/stores/panel/copilot/store.ts | 18 ++++++++++++++++-- apps/sim/stores/workflow-diff/store.ts | 8 ++++++++ apps/sim/stores/workflow-diff/utils.ts | 18 +++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/sim/stores/panel/copilot/store.ts b/apps/sim/stores/panel/copilot/store.ts index 39a933dd1..9d7bdb6dc 100644 --- a/apps/sim/stores/panel/copilot/store.ts +++ b/apps/sim/stores/panel/copilot/store.ts @@ -1303,11 +1303,25 @@ const sseHandlers: Record = { const resultPayload = data?.result || data?.data?.result || data?.data?.data || data?.data || {} const workflowState = resultPayload?.workflowState + logger.info('[SSE] edit_workflow result received', { + hasWorkflowState: !!workflowState, + blockCount: workflowState ? Object.keys(workflowState.blocks || {}).length : 0, + edgeCount: workflowState?.edges?.length ?? 0, + }) if (workflowState) { const diffStore = useWorkflowDiffStore.getState() - void diffStore.setProposedChanges(workflowState) + // Await the diff application to catch any errors + diffStore.setProposedChanges(workflowState).catch((err) => { + logger.error('[SSE] Failed to apply edit_workflow diff', { + error: err instanceof Error ? err.message : String(err), + }) + }) } - } catch {} + } catch (err) { + logger.error('[SSE] edit_workflow result handling failed', { + error: err instanceof Error ? err.message : String(err), + }) + } } } diff --git a/apps/sim/stores/workflow-diff/store.ts b/apps/sim/stores/workflow-diff/store.ts index 285be7e11..abd57d0ae 100644 --- a/apps/sim/stores/workflow-diff/store.ts +++ b/apps/sim/stores/workflow-diff/store.ts @@ -121,6 +121,13 @@ export const useWorkflowDiffStore = create `${e.source} -> ${e.target}`), + }) const workflowStore = useWorkflowStore.getState() - workflowStore.replaceWorkflowState(cloneWorkflowState(workflowState), options) + const cloned = cloneWorkflowState(workflowState) + logger.info('[applyWorkflowStateToStores] Cloned state edges', { + clonedEdgeCount: cloned.edges?.length ?? 0, + }) + workflowStore.replaceWorkflowState(cloned, options) const subBlockValues = extractSubBlockValues(workflowState) useSubBlockStore.getState().setWorkflowValues(workflowId, subBlockValues) + + // Verify what's in the store after apply + const afterState = workflowStore.getWorkflowState() + logger.info('[applyWorkflowStateToStores] After apply', { + afterEdgeCount: afterState.edges?.length ?? 0, + }) } export function captureBaselineSnapshot(workflowId: string): WorkflowState {