Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ export function UserInput({
sttPrefixRef.current = ''
resetTranscript()
currentFiles.clearAttachedFiles()
prevSelectedContextsRef.current = []
currentContext.clearContexts()

if (textareaRef.current) {
Expand Down
22 changes: 12 additions & 10 deletions apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2391,18 +2391,30 @@ 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,
role: 'user' as const,
content: message,
timestamp: new Date().toISOString(),
...(storedAttachments && { fileAttachments: storedAttachments }),
...(messageContexts && messageContexts.length > 0 ? { contexts: messageContexts } : {}),
}
queryClient.setQueryData<TaskChatHistory>(taskKeys.detail(requestChatId), (old) => {
return old
? {
...old,
resources: resourcesRef.current.filter((r) => r.id !== 'streaming-file'),
messages: [...old.messages, cachedUserMsg],
activeStreamId: userMessageId,
}
Expand All @@ -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,
{
Expand Down
Loading