Skip to content

Commit ba5b490

Browse files
committed
Fix
1 parent c0a4471 commit ba5b490

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ export function useChat(
10741074
while (!chatIdRef.current && sendingRef.current && Date.now() - start < 3000) {
10751075
await new Promise((r) => setTimeout(r, 50))
10761076
}
1077+
if (!chatIdRef.current) return
10771078
}
10781079

10791080
if (sendingRef.current) {

apps/sim/lib/copilot/chat-streaming.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ const pendingChatStreams = new Map<
2929
>()
3030

3131
function registerPendingChatStream(chatId: string, streamId: string): void {
32-
let resolve: () => void
32+
if (pendingChatStreams.has(chatId)) {
33+
logger.warn(`registerPendingChatStream: overwriting existing entry for chatId ${chatId}`)
34+
}
35+
let resolve!: () => void
3336
const promise = new Promise<void>((r) => {
3437
resolve = r
3538
})
36-
pendingChatStreams.set(chatId, { promise, resolve: resolve!, streamId })
39+
pendingChatStreams.set(chatId, { promise, resolve, streamId })
3740
}
3841

39-
function resolvePendingChatStream(chatId: string): void {
42+
function resolvePendingChatStream(chatId: string, streamId: string): void {
4043
const entry = pendingChatStreams.get(chatId)
41-
if (entry) {
44+
if (entry && entry.streamId === streamId) {
4245
entry.resolve()
4346
pendingChatStreams.delete(chatId)
4447
}
@@ -255,7 +258,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
255258
} finally {
256259
activeStreams.delete(streamId)
257260
if (chatId) {
258-
resolvePendingChatStream(chatId)
261+
resolvePendingChatStream(chatId, streamId)
259262
}
260263
try {
261264
controller.close()

0 commit comments

Comments
 (0)