File tree Expand file tree Collapse file tree
ui/goose2/src/features/chat/lib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,4 +76,49 @@ describe("findExistingDraft", () => {
7676 } ) ,
7777 ) . toBeUndefined ( ) ;
7878 } ) ;
79+
80+ it ( "does not reuse the active empty draft without content" , ( ) => {
81+ const draft = makeSession ( "alpha-draft" , {
82+ projectId : "alpha" ,
83+ providerId : "goose" ,
84+ } ) ;
85+
86+ expect (
87+ findExistingDraft ( {
88+ sessions : [ draft ] ,
89+ activeSessionId : "alpha-draft" ,
90+ draftsBySession : { } ,
91+ messagesBySession : { } ,
92+ request : {
93+ title : "New Chat" ,
94+ projectId : "alpha" ,
95+ } ,
96+ } ) ,
97+ ) . toBeUndefined ( ) ;
98+ } ) ;
99+
100+ it ( "does not reuse a session with local messages even if messageCount is 0" , ( ) => {
101+ const session = makeSession ( "alpha-session" , {
102+ projectId : "alpha" ,
103+ providerId : "goose" ,
104+ messageCount : 0 ,
105+ } ) ;
106+
107+ expect (
108+ findExistingDraft ( {
109+ sessions : [ session ] ,
110+ activeSessionId : "alpha-session" ,
111+ draftsBySession : { } ,
112+ messagesBySession : {
113+ "alpha-session" : [
114+ { id : "msg-1" , role : "user" , content : "hello" } as any ,
115+ ] ,
116+ } ,
117+ request : {
118+ title : "New Chat" ,
119+ projectId : "alpha" ,
120+ } ,
121+ } ) ,
122+ ) . toBeUndefined ( ) ;
123+ } ) ;
79124} ) ;
Original file line number Diff line number Diff line change @@ -24,9 +24,13 @@ function isMatchingContext(
2424
2525function isReusableDraft (
2626 session : ChatSession ,
27- _localMessages : Message [ ] | undefined ,
27+ localMessages : Message [ ] | undefined ,
2828) : boolean {
29- return ! session . archivedAt && session . messageCount === 0 ;
29+ return (
30+ ! session . archivedAt &&
31+ session . messageCount === 0 &&
32+ ( localMessages ?. length ?? 0 ) === 0
33+ ) ;
3034}
3135
3236export function findExistingDraft ( {
@@ -60,5 +64,5 @@ export function findExistingDraft({
6064 ) ;
6165 }
6266
63- return candidates . find ( ( session ) => session . id === activeSessionId ) ;
67+ return undefined ;
6468}
You can’t perform that action at this time.
0 commit comments