Skip to content

Commit 88000f4

Browse files
author
Theodore Li
committed
Fix streaming file flash
1 parent 3cf4ba7 commit 88000f4

File tree

1 file changed

+24
-10
lines changed
  • apps/sim/app/workspace/[workspaceId]/home/hooks

1 file changed

+24
-10
lines changed

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -894,23 +894,37 @@ export function useChat(
894894
}
895895
}
896896

897-
if (tc.status === 'success' && isResourceToolName(tc.name)) {
898-
const resources = extractResourcesFromToolResult(
899-
tc.name,
900-
toolArgsMap.get(id) as Record<string, unknown> | undefined,
901-
tc.result?.output
902-
)
903-
for (const resource of resources) {
904-
invalidateResourceQueries(queryClient, workspaceId, resource.type, resource.id)
905-
}
897+
const extractedResources =
898+
tc.status === 'success' && isResourceToolName(tc.name)
899+
? extractResourcesFromToolResult(
900+
tc.name,
901+
toolArgsMap.get(id) as Record<string, unknown> | undefined,
902+
tc.result?.output
903+
)
904+
: []
905+
906+
for (const resource of extractedResources) {
907+
invalidateResourceQueries(queryClient, workspaceId, resource.type, resource.id)
906908
}
907909

908910
onToolResultRef.current?.(tc.name, tc.status === 'success', tc.result?.output)
909911

910912
if (tc.name === 'workspace_file') {
911913
setStreamingFile(null)
912914
streamingFileRef.current = null
913-
setResources((rs) => rs.filter((r) => r.id !== 'streaming-file'))
915+
916+
const fileResource = extractedResources.find((r) => r.type === 'file')
917+
if (fileResource) {
918+
setResources((rs) => {
919+
const without = rs.filter((r) => r.id !== 'streaming-file')
920+
if (without.some((r) => r.type === 'file' && r.id === fileResource.id))
921+
return without
922+
return [...without, fileResource]
923+
})
924+
setActiveResourceId(fileResource.id)
925+
} else {
926+
setResources((rs) => rs.filter((r) => r.id !== 'streaming-file'))
927+
}
914928
}
915929
}
916930

0 commit comments

Comments
 (0)