fix: Allow starting a new session in a project after creating one (#8766)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -76,4 +76,49 @@ describe("findExistingDraft", () => {
|
|||||||
}),
|
}),
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not reuse the active empty draft without content", () => {
|
||||||
|
const draft = makeSession("alpha-draft", {
|
||||||
|
projectId: "alpha",
|
||||||
|
providerId: "goose",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
findExistingDraft({
|
||||||
|
sessions: [draft],
|
||||||
|
activeSessionId: "alpha-draft",
|
||||||
|
draftsBySession: {},
|
||||||
|
messagesBySession: {},
|
||||||
|
request: {
|
||||||
|
title: "New Chat",
|
||||||
|
projectId: "alpha",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not reuse a session with local messages even if messageCount is 0", () => {
|
||||||
|
const session = makeSession("alpha-session", {
|
||||||
|
projectId: "alpha",
|
||||||
|
providerId: "goose",
|
||||||
|
messageCount: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
findExistingDraft({
|
||||||
|
sessions: [session],
|
||||||
|
activeSessionId: "alpha-session",
|
||||||
|
draftsBySession: {},
|
||||||
|
messagesBySession: {
|
||||||
|
"alpha-session": [
|
||||||
|
{ id: "msg-1", role: "user", content: "hello" } as any,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
request: {
|
||||||
|
title: "New Chat",
|
||||||
|
projectId: "alpha",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ function isMatchingContext(
|
|||||||
|
|
||||||
function isReusableDraft(
|
function isReusableDraft(
|
||||||
session: ChatSession,
|
session: ChatSession,
|
||||||
_localMessages: Message[] | undefined,
|
localMessages: Message[] | undefined,
|
||||||
): boolean {
|
): boolean {
|
||||||
return !session.archivedAt && session.messageCount === 0;
|
return (
|
||||||
|
!session.archivedAt &&
|
||||||
|
session.messageCount === 0 &&
|
||||||
|
(localMessages?.length ?? 0) === 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findExistingDraft({
|
export function findExistingDraft({
|
||||||
@@ -60,5 +64,5 @@ export function findExistingDraft({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return candidates.find((session) => session.id === activeSessionId);
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user