Skip to content

Commit f7acc18

Browse files
author
Theodore Li
committed
fix(agent) subagent and main agent text being merged without spacing
1 parent 4df7e78 commit f7acc18

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ export function useChat(workspaceId: string, initialChatId?: string): UseChatRet
427427
let lastTableId: string | null = null
428428
let lastWorkflowId: string | null = null
429429
let runningText = ''
430+
let lastContentSource: 'main' | 'subagent' | null = null
430431

431432
streamingContentRef.current = ''
432433
toolArgsMapRef.current.clear()
@@ -497,9 +498,17 @@ export function useChat(workspaceId: string, initialChatId?: string): UseChatRet
497498
case 'content': {
498499
const chunk = typeof parsed.data === 'string' ? parsed.data : (parsed.content ?? '')
499500
if (chunk) {
501+
const contentSource: 'main' | 'subagent' = activeSubagent ? 'subagent' : 'main'
502+
const needsBoundaryNewline =
503+
lastContentSource !== null &&
504+
lastContentSource !== contentSource &&
505+
runningText.length > 0 &&
506+
!runningText.endsWith('\n')
500507
const tb = ensureTextBlock()
501-
tb.content = (tb.content ?? '') + chunk
502-
runningText += chunk
508+
const normalizedChunk = needsBoundaryNewline ? `\n${chunk}` : chunk
509+
tb.content = (tb.content ?? '') + normalizedChunk
510+
runningText += normalizedChunk
511+
lastContentSource = contentSource
503512
streamingContentRef.current = runningText
504513
flush()
505514
}

apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createLogger } from '@sim/logger'
22
import { STREAM_TIMEOUT_MS } from '@/lib/copilot/constants'
3-
import { isWorkflowToolName } from '@/lib/copilot/workflow-tools'
43
import {
54
asRecord,
65
getEventData,

0 commit comments

Comments
 (0)