@@ -951,7 +951,7 @@ export function useChat(
951951 selectedChatIdRef . current = initialChatId
952952 const appliedChatHistoryKeyRef = useRef < string | undefined > ( undefined )
953953 const activeTurnRef = useRef < ActiveTurn | null > ( null )
954- const pendingUserMsgRef = useRef < { id : string ; content : string } | null > ( null )
954+ const pendingUserMsgRef = useRef < PersistedMessage | null > ( null )
955955 const streamIdRef = useRef < string | undefined > ( undefined )
956956 const locallyTerminalStreamIdRef = useRef < string | undefined > ( undefined )
957957 const lastCursorRef = useRef ( '0' )
@@ -1079,6 +1079,7 @@ export function useChat(
10791079
10801080 const removeResource = useCallback ( ( resourceType : MothershipResourceType , resourceId : string ) => {
10811081 setResources ( ( prev ) => prev . filter ( ( r ) => ! ( r . type === resourceType && r . id === resourceId ) ) )
1082+ setActiveResourceId ( ( prev ) => ( prev === resourceId ? null : prev ) )
10821083 } , [ ] )
10831084
10841085 const reorderResources = useCallback ( ( newOrder : MothershipResource [ ] ) => {
@@ -1594,16 +1595,9 @@ export function useChat(
15941595 queryClient . setQueryData < TaskChatHistory > ( taskKeys . detail ( payloadChatId ) , {
15951596 id : payloadChatId ,
15961597 title : null ,
1597- messages : [
1598- {
1599- id : userMsg . id ,
1600- role : 'user' ,
1601- content : userMsg . content ,
1602- timestamp : new Date ( ) . toISOString ( ) ,
1603- } ,
1604- ] ,
1598+ messages : [ userMsg ] ,
16051599 activeStreamId,
1606- resources : [ ] ,
1600+ resources : resourcesRef . current ,
16071601 } )
16081602 }
16091603 if ( ! workflowIdRef . current ) {
@@ -2652,7 +2646,6 @@ export function useChat(
26522646 const userMessageId = generateId ( )
26532647 const assistantId = generateId ( )
26542648
2655- pendingUserMsgRef . current = { id : userMessageId , content : message }
26562649 streamIdRef . current = userMessageId
26572650 lastCursorRef . current = '0'
26582651 resetStreamingBuffers ( )
@@ -2686,6 +2679,7 @@ export function useChat(
26862679 ...( storedAttachments && { fileAttachments : storedAttachments } ) ,
26872680 ...( messageContexts && messageContexts . length > 0 ? { contexts : messageContexts } : { } ) ,
26882681 }
2682+ pendingUserMsgRef . current = cachedUserMsg
26892683
26902684 const userAttachments = storedAttachments ?. map ( ( f ) => ( {
26912685 id : f . id ,
0 commit comments