fix: prevent title regeneration on auto compact (#1628)
This commit is contained in:
@@ -48,6 +48,17 @@ export namespace Session {
|
|||||||
|
|
||||||
const OUTPUT_TOKEN_MAX = 32_000
|
const OUTPUT_TOKEN_MAX = 32_000
|
||||||
|
|
||||||
|
const parentSessionTitlePrefix = "New session - "
|
||||||
|
const childSessionTitlePrefix = "Child session - "
|
||||||
|
|
||||||
|
function createDefaultTitle(isChild = false) {
|
||||||
|
return (isChild ? childSessionTitlePrefix : parentSessionTitlePrefix) + new Date().toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDefaultTitle(title: string) {
|
||||||
|
return title.startsWith(parentSessionTitlePrefix)
|
||||||
|
}
|
||||||
|
|
||||||
export const Info = z
|
export const Info = z
|
||||||
.object({
|
.object({
|
||||||
id: Identifier.schema("session"),
|
id: Identifier.schema("session"),
|
||||||
@@ -153,7 +164,7 @@ export namespace Session {
|
|||||||
id: Identifier.descending("session"),
|
id: Identifier.descending("session"),
|
||||||
version: Installation.VERSION,
|
version: Installation.VERSION,
|
||||||
parentID,
|
parentID,
|
||||||
title: (parentID ? "Child session - " : "New Session - ") + new Date().toISOString(),
|
title: createDefaultTitle(!!parentID),
|
||||||
time: {
|
time: {
|
||||||
created: Date.now(),
|
created: Date.now(),
|
||||||
updated: Date.now(),
|
updated: Date.now(),
|
||||||
@@ -631,7 +642,7 @@ export namespace Session {
|
|||||||
const lastSummary = msgs.findLast((msg) => msg.info.role === "assistant" && msg.info.summary === true)
|
const lastSummary = msgs.findLast((msg) => msg.info.role === "assistant" && msg.info.summary === true)
|
||||||
if (lastSummary) msgs = msgs.filter((msg) => msg.info.id >= lastSummary.info.id)
|
if (lastSummary) msgs = msgs.filter((msg) => msg.info.id >= lastSummary.info.id)
|
||||||
|
|
||||||
if (msgs.length === 1 && !session.parentID) {
|
if (msgs.length === 1 && !session.parentID && isDefaultTitle(session.title)) {
|
||||||
const small = (await Provider.getSmallModel(input.providerID)) ?? model
|
const small = (await Provider.getSmallModel(input.providerID)) ?? model
|
||||||
generateText({
|
generateText({
|
||||||
maxOutputTokens: small.info.reasoning ? 1024 : 20,
|
maxOutputTokens: small.info.reasoning ? 1024 : 20,
|
||||||
|
|||||||
Reference in New Issue
Block a user