@@ -13,7 +13,7 @@ import { parseNetworkError } from "../lib/opencode-errors";
1313import { showToast } from "../lib/toast" ;
1414import { useSessionStatus } from "../stores/sessionStatusStore" ;
1515import { useSendErrorStore } from "../stores/sendErrorStore" ;
16- import { invalidateSessionListCaches } from "../lib/queryInvalidation" ;
16+ import { invalidateSessionListCaches , messagesQueryKey } from "../lib/queryInvalidation" ;
1717
1818type AssistantMessage = components [ "schemas" ] [ "AssistantMessage" ] ;
1919
@@ -140,7 +140,7 @@ export const useMessages = (opcodeUrl: string | null | undefined, sessionID: str
140140 const client = useOpenCodeClient ( opcodeUrl , directory ) ;
141141
142142 return useQuery ( {
143- queryKey : [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
143+ queryKey : messagesQueryKey ( opcodeUrl , sessionID , directory ) ,
144144 queryFn : async ( ) => {
145145 const response = await client ! . listMessages ( sessionID ! )
146146 return response as MessageWithParts [ ]
@@ -404,15 +404,15 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
404404 ) ;
405405 const userMessageInfo = createOptimisticUserMessageInfo ( sessionID , optimisticUserID , model , agent , variant ) ;
406406
407- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
408- await queryClient . cancelQueries ( { queryKey : messagesQueryKey } ) ;
407+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
408+ await queryClient . cancelQueries ( { queryKey } ) ;
409409
410410 const optimisticMessageWithParts : MessageWithParts = {
411411 info : userMessageInfo ,
412412 parts : userMessageParts ,
413413 }
414414 queryClient . setQueryData < MessageWithParts [ ] > (
415- messagesQueryKey ,
415+ queryKey ,
416416 ( old ) => [ ...( old || [ ] ) , optimisticMessageWithParts ] ,
417417 ) ;
418418
@@ -483,11 +483,11 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
483483 } ,
484484 onError : ( error , variables ) => {
485485 const { sessionID } = variables ;
486- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
486+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
487487
488488 setSessionStatus ( sessionID , { type : "idle" } ) ;
489489 queryClient . setQueryData < MessageWithParts [ ] > (
490- messagesQueryKey ,
490+ queryKey ,
491491 ( old ) => old ?. filter ( ( msgWithParts ) => ! msgWithParts . info . id . startsWith ( "optimistic_" ) ) ,
492492 ) ;
493493
@@ -509,17 +509,17 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
509509 onSuccess : async ( data , variables ) => {
510510 const { sessionID } = variables ;
511511 const { response } = data ;
512- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
512+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
513513
514514 useSendErrorStore . getState ( ) . clearError ( sessionID ) ;
515515
516516 if ( data . queued || ! response ) {
517- queryClient . invalidateQueries ( { queryKey : messagesQueryKey } ) ;
517+ queryClient . invalidateQueries ( { queryKey } ) ;
518518 return ;
519519 }
520520
521521 queryClient . setQueryData < MessageWithParts [ ] > (
522- messagesQueryKey ,
522+ queryKey ,
523523 ( old ) => {
524524 if ( ! old ) return old ;
525525
@@ -553,7 +553,7 @@ export const useAbortSession = (
553553 const retryCountRef = useRef ( 0 ) ;
554554
555555 const forceCompleteMessages = useCallback ( ( targetSessionID : string ) => {
556- const queryKey = [ "opencode" , "messages" , opcodeUrl , targetSessionID , directory ] ;
556+ const queryKey = messagesQueryKey ( opcodeUrl , targetSessionID , directory ) ;
557557 const now = Date . now ( ) ;
558558
559559 queryClient . setQueryData < MessageWithParts [ ] > ( queryKey , ( old ) => {
@@ -616,7 +616,7 @@ export const useAbortSession = (
616616 } , [ ] ) ;
617617
618618 const isSessionComplete = useCallback ( ( targetSessionID : string ) => {
619- const queryKey = [ "opencode" , "messages" , opcodeUrl , targetSessionID , directory ] ;
619+ const queryKey = messagesQueryKey ( opcodeUrl , targetSessionID , directory ) ;
620620 const messages = queryClient . getQueryData < MessageWithParts [ ] > ( queryKey ) ;
621621
622622 const hasIncompleteMessages = messages ?. some ( msgWithParts => {
@@ -632,7 +632,7 @@ export const useAbortSession = (
632632 if ( ! sessionID ) return ;
633633
634634 const unsubscribe = queryClient . getQueryCache ( ) . subscribe ( ( event ) => {
635- const queryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
635+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
636636 if ( event . query . queryKey . join ( "," ) === queryKey . join ( "," ) ) {
637637 if ( isSessionComplete ( sessionID ) && retryIntervalRef . current ) {
638638 stopRetrying ( ) ;
@@ -716,15 +716,15 @@ export const useSendShell = (opcodeUrl: string | null | undefined, directory?: s
716716 ) ;
717717 const userMessageInfo = createOptimisticUserMessageInfo ( sessionID , optimisticUserID ) ;
718718
719- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
720- await queryClient . cancelQueries ( { queryKey : messagesQueryKey } ) ;
719+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
720+ await queryClient . cancelQueries ( { queryKey } ) ;
721721
722722 const optimisticMessageWithParts : MessageWithParts = {
723723 info : userMessageInfo ,
724724 parts : userMessageParts ,
725725 }
726726 queryClient . setQueryData < MessageWithParts [ ] > (
727- messagesQueryKey ,
727+ queryKey ,
728728 ( old ) => [ ...( old || [ ] ) , optimisticMessageWithParts ] ,
729729 ) ;
730730
@@ -739,7 +739,7 @@ export const useSendShell = (opcodeUrl: string | null | undefined, directory?: s
739739 const { sessionID } = variables ;
740740 setSessionStatus ( sessionID , { type : "idle" } ) ;
741741 queryClient . setQueryData < MessageWithParts [ ] > (
742- [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
742+ messagesQueryKey ( opcodeUrl , sessionID , directory ) ,
743743 ( old ) => {
744744 if ( ! old ) return old ;
745745 return old . filter ( ( msgWithParts ) => ! msgWithParts . info . id . startsWith ( "optimistic_" ) ) ;
@@ -753,7 +753,7 @@ export const useSendShell = (opcodeUrl: string | null | undefined, directory?: s
753753 const { optimisticUserID } = data ;
754754
755755 queryClient . setQueryData < MessageWithParts [ ] > (
756- [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
756+ messagesQueryKey ( opcodeUrl , sessionID , directory ) ,
757757 ( old ) => {
758758 if ( ! old ) return old ;
759759 return old . filter ( ( msgWithParts ) => msgWithParts . info . id !== optimisticUserID ) ;
@@ -810,7 +810,7 @@ export const useLoadSkill = (
810810 setSessionStatus ( sessionID , { type : "busy" } ) ;
811811
812812 const optimisticUserID = `optimistic_user_${ Date . now ( ) } _${ Math . random ( ) } ` ;
813- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
813+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
814814
815815 const userMessageParts = createOptimisticUserMessageParts (
816816 sessionID ,
@@ -823,9 +823,9 @@ export const useLoadSkill = (
823823 parts : userMessageParts ,
824824 } ;
825825
826- await queryClient . cancelQueries ( { queryKey : messagesQueryKey } ) ;
826+ await queryClient . cancelQueries ( { queryKey } ) ;
827827 queryClient . setQueryData < MessageWithParts [ ] > (
828- messagesQueryKey ,
828+ queryKey ,
829829 ( old ) => [ ...( old || [ ] ) , optimisticMessageWithParts ] ,
830830 ) ;
831831
@@ -834,21 +834,21 @@ export const useLoadSkill = (
834834 } ,
835835 onError : ( error ) => {
836836 if ( sessionID ) {
837- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
837+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
838838 setSessionStatus ( sessionID ! , { type : "idle" } ) ;
839839 queryClient . setQueryData < MessageWithParts [ ] > (
840- messagesQueryKey ,
840+ queryKey ,
841841 ( old ) => old ?. filter ( ( m ) => ! m . info . id . startsWith ( "optimistic_" ) ) ,
842842 ) ;
843843 }
844844 showToast . error ( error instanceof Error ? error . message : "Failed to load skill" ) ;
845845 } ,
846846 onSuccess : ( data ) => {
847847 const { response } = data ;
848- const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
848+ const queryKey = messagesQueryKey ( opcodeUrl , sessionID , directory ) ;
849849
850850 queryClient . setQueryData < MessageWithParts [ ] > (
851- messagesQueryKey ,
851+ queryKey ,
852852 ( old ) => {
853853 if ( ! old ) return old ;
854854
0 commit comments