Skip to content

Commit cc1ae03

Browse files
author
Theodore Li
committed
Process task streams that are in the background
1 parent 170eb79 commit cc1ae03

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,17 @@ export function useChat(
697697
if (DEPLOY_TOOL_NAMES.has(tc.name) && tc.status === 'success') {
698698
const output = tc.result?.output as Record<string, unknown> | undefined
699699
const deployedWorkflowId = (output?.workflowId as string) ?? undefined
700-
if (deployedWorkflowId) {
701-
const isDeployed = output?.isDeployed !== false
700+
if (deployedWorkflowId && typeof output?.isDeployed === 'boolean') {
701+
const isDeployed = output.isDeployed as boolean
702+
const serverDeployedAt = output.deployedAt
703+
? new Date(output.deployedAt as string)
704+
: undefined
702705
useWorkflowRegistry
703706
.getState()
704707
.setDeploymentStatus(
705708
deployedWorkflowId,
706709
isDeployed,
707-
isDeployed ? new Date() : undefined
710+
isDeployed ? (serverDeployedAt ?? new Date()) : undefined
708711
)
709712
queryClient.invalidateQueries({
710713
queryKey: deploymentKeys.info(deployedWorkflowId),
@@ -1147,11 +1150,6 @@ export function useChat(
11471150
useEffect(() => {
11481151
return () => {
11491152
streamGenRef.current++
1150-
// Only drop the browser→Sim read; the Sim→Go stream stays open
1151-
// so the backend can finish persisting. Explicit abort is only
1152-
// triggered by the stop button via /api/copilot/chat/abort.
1153-
abortControllerRef.current?.abort()
1154-
abortControllerRef.current = null
11551153
sendingRef.current = false
11561154
}
11571155
}, [])

apps/sim/lib/copilot/client-sse/handlers.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ export const sseHandlers: Record<string, SSEHandler> = {
567567
}
568568
}
569569

570-
// Deploy tools: update deployment status in workflow registry
571570
if (
572571
targetState === ClientToolCallState.success &&
573572
(current.name === 'deploy_api' ||
@@ -579,21 +578,30 @@ export const sseHandlers: Record<string, SSEHandler> = {
579578
const resultPayload = asRecord(
580579
data?.result || eventData.result || eventData.data || data?.data
581580
)
582-
const input = asRecord(current.params)
583-
const workflowId =
584-
(resultPayload?.workflowId as string) ||
585-
(input?.workflowId as string) ||
586-
useWorkflowRegistry.getState().activeWorkflowId
587-
const isDeployed = resultPayload?.isDeployed !== false
588-
if (workflowId) {
589-
useWorkflowRegistry
590-
.getState()
591-
.setDeploymentStatus(workflowId, isDeployed, isDeployed ? new Date() : undefined)
592-
logger.info('[SSE] Updated deployment status from tool result', {
593-
toolName: current.name,
594-
workflowId,
595-
isDeployed,
596-
})
581+
if (typeof resultPayload?.isDeployed === 'boolean') {
582+
const input = asRecord(current.params)
583+
const workflowId =
584+
(resultPayload?.workflowId as string) ||
585+
(input?.workflowId as string) ||
586+
useWorkflowRegistry.getState().activeWorkflowId
587+
const isDeployed = resultPayload.isDeployed as boolean
588+
const serverDeployedAt = resultPayload.deployedAt
589+
? new Date(resultPayload.deployedAt as string)
590+
: undefined
591+
if (workflowId) {
592+
useWorkflowRegistry
593+
.getState()
594+
.setDeploymentStatus(
595+
workflowId,
596+
isDeployed,
597+
isDeployed ? (serverDeployedAt ?? new Date()) : undefined
598+
)
599+
logger.info('[SSE] Updated deployment status from tool result', {
600+
toolName: current.name,
601+
workflowId,
602+
isDeployed,
603+
})
604+
}
597605
}
598606
} catch (err) {
599607
logger.warn('[SSE] Failed to hydrate deployment status', {

apps/sim/lib/copilot/orchestrator/tool-executor/deployment-tools/deploy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export async function executeDeployChat(
8787
return { success: false, error: 'Unauthorized chat access' }
8888
}
8989
await db.delete(chat).where(eq(chat.id, existing[0].id))
90-
return { success: true, output: { success: true, action: 'undeploy', isDeployed: false } }
90+
return {
91+
success: true,
92+
output: { workflowId, success: true, action: 'undeploy', isChatDeployed: false },
93+
}
9194
}
9295

9396
const { hasAccess } = await checkWorkflowAccessForChatCreation(workflowId, context.userId)
@@ -199,9 +202,11 @@ export async function executeDeployChat(
199202
return {
200203
success: true,
201204
output: {
205+
workflowId,
202206
success: true,
203207
action: 'deploy',
204208
isDeployed: true,
209+
isChatDeployed: true,
205210
identifier,
206211
chatUrl: `${baseUrl}/chat/${identifier}`,
207212
apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`,
@@ -355,6 +360,7 @@ export async function executeRedeploy(
355360
success: true,
356361
output: {
357362
workflowId,
363+
isDeployed: true,
358364
deployedAt: result.deployedAt || null,
359365
version: result.version,
360366
apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`,

0 commit comments

Comments
 (0)