feat(agent): support clearing session names

This commit is contained in:
David Brailovsky 2026-08-08 19:19:17 +02:00
parent c185d41238
commit 7bdb16c28d
12 changed files with 69 additions and 32 deletions

View file

@ -606,7 +606,7 @@ class SqliteSessionStorage implements SessionStorage<SqliteSessionMetadata> {
kind: "fact" as const,
seq: row.seq,
fact: "name" as const,
name: JSON.parse(row.value ?? "null") as string,
name: row.value === null ? undefined : (JSON.parse(row.value) as string),
};
return {
kind: "fact" as const,
@ -627,10 +627,10 @@ class SqliteSessionStorage implements SessionStorage<SqliteSessionMetadata> {
return row?.value === undefined || row.value === null ? undefined : (JSON.parse(row.value) as string);
}
async setName(name: string): Promise<void> {
async setName(name: string | undefined): Promise<void> {
return this.enqueueWrite(() => {
const seq = getNextSequence(this.db, this.metadata.id);
appendFact(this.db, this.metadata.id, seq, "name", null, JSON.stringify(name));
appendFact(this.db, this.metadata.id, seq, "name", null, name === undefined ? null : JSON.stringify(name));
advanceSequence(this.db, this.metadata.id, seq);
});
}

View file

@ -98,10 +98,8 @@ export function deleteSessionRow(db: SqliteDatabase, sessionId: string) {
sql`DELETE FROM sessions WHERE id = ${sessionId}`.run(db);
}
function parseSessionName(value: string | null, sessionId: string): string {
if (value === null) {
throw new SessionError("storage", `Invalid SQLite session ${sessionId}: name must be a string`);
}
function parseSessionName(value: string | null, sessionId: string): string | undefined {
if (value === null) return undefined;
let parsed: unknown;
try {
parsed = JSON.parse(value);