diff --git a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx index 981dc9d0e5..5f1ba55808 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx +++ b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx @@ -445,6 +445,7 @@ export function UserInput({ sttPrefixRef.current = '' resetTranscript() currentFiles.clearAttachedFiles() + prevSelectedContextsRef.current = [] currentContext.clearContexts() if (textareaRef.current) { diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts index 0906d97a22..d61970c7ff 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts @@ -2391,6 +2391,16 @@ export function useChat( : undefined const requestChatId = selectedChatIdRef.current ?? chatIdRef.current + const messageContexts = contexts?.map((c) => ({ + kind: c.kind, + label: c.label, + ...('workflowId' in c && c.workflowId ? { workflowId: c.workflowId } : {}), + ...('knowledgeId' in c && c.knowledgeId ? { knowledgeId: c.knowledgeId } : {}), + ...('tableId' in c && c.tableId ? { tableId: c.tableId } : {}), + ...('fileId' in c && c.fileId ? { fileId: c.fileId } : {}), + ...('folderId' in c && c.folderId ? { folderId: c.folderId } : {}), + })) + if (requestChatId) { const cachedUserMsg: PersistedMessage = { id: userMessageId, @@ -2398,11 +2408,13 @@ export function useChat( content: message, timestamp: new Date().toISOString(), ...(storedAttachments && { fileAttachments: storedAttachments }), + ...(messageContexts && messageContexts.length > 0 ? { contexts: messageContexts } : {}), } queryClient.setQueryData(taskKeys.detail(requestChatId), (old) => { return old ? { ...old, + resources: resourcesRef.current.filter((r) => r.id !== 'streaming-file'), messages: [...old.messages, cachedUserMsg], activeStreamId: userMessageId, } @@ -2420,16 +2432,6 @@ export function useChat( : undefined, })) - const messageContexts = contexts?.map((c) => ({ - kind: c.kind, - label: c.label, - ...('workflowId' in c && c.workflowId ? { workflowId: c.workflowId } : {}), - ...('knowledgeId' in c && c.knowledgeId ? { knowledgeId: c.knowledgeId } : {}), - ...('tableId' in c && c.tableId ? { tableId: c.tableId } : {}), - ...('fileId' in c && c.fileId ? { fileId: c.fileId } : {}), - ...('folderId' in c && c.folderId ? { folderId: c.folderId } : {}), - })) - setMessages((prev) => [ ...prev, {