Archived
Fix automatic session title generation
This commit is contained in:
@@ -4,6 +4,7 @@ import type { ModelRegistry } from "@earendil-works/pi-coding-agent";
|
||||
const SESSION_NAME_TIMEOUT_MS = 10_000;
|
||||
const SESSION_NAME_MAX_INPUT_CHARS = 4_000;
|
||||
const SESSION_NAME_MAX_LENGTH = 60;
|
||||
const FALLBACK_SESSION_NAME_MAX_WORDS = 6;
|
||||
|
||||
export async function generateShortSessionName<TApi extends Api>(modelRegistry: ModelRegistry, model: Model<TApi>, firstMessage: string): Promise<string | undefined> {
|
||||
const provider = getApiProvider(model.api);
|
||||
@@ -23,7 +24,6 @@ export async function generateShortSessionName<TApi extends Api>(modelRegistry:
|
||||
}],
|
||||
},
|
||||
{
|
||||
temperature: 0.2,
|
||||
maxTokens: 24,
|
||||
reasoning: "minimal",
|
||||
signal: AbortSignal.timeout(SESSION_NAME_TIMEOUT_MS),
|
||||
@@ -43,10 +43,21 @@ export async function generateShortSessionName<TApi extends Api>(modelRegistry:
|
||||
return cleanSessionName(finalMessage === undefined ? streamedText : textFromAssistant(finalMessage));
|
||||
}
|
||||
|
||||
export function fallbackSessionName(firstMessage: string): string | undefined {
|
||||
return cleanSessionName(firstMessage
|
||||
.replace(/<skill name="[^"]+" location="[^"]+">[\s\S]*?<\/skill>/g, "")
|
||||
.replace(/```[\s\S]*?```/g, " ")
|
||||
.replace(/[`*_#[\](){}<>]/g, " ")
|
||||
.split(/\s+/)
|
||||
.filter(Boolean)
|
||||
.slice(0, FALLBACK_SESSION_NAME_MAX_WORDS)
|
||||
.join(" "));
|
||||
}
|
||||
|
||||
export function cleanSessionName(value: string): string | undefined {
|
||||
const title = (value.split("\n", 1)[0] ?? "")
|
||||
.replace(/^\s*(title|session title)\s*:\s*/i, "")
|
||||
.replace(/^\s*["'`]+|["'`.]+\s*$/g, "")
|
||||
.replace(/^(title|session title)\s*:\s*/i, "")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.slice(0, SESSION_NAME_MAX_LENGTH)
|
||||
|
||||
Reference in New Issue
Block a user