fix(agent): normalize session names
This commit is contained in:
@@ -234,12 +234,13 @@ export class Session<TMetadata extends SessionMetadata = SessionMetadata> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async appendSessionName(name: string): Promise<string> {
|
async appendSessionName(name: string): Promise<string> {
|
||||||
|
const sanitizedName = name.replace(/[\r\n]+/g, " ").trim();
|
||||||
return this.appendTypedEntry({
|
return this.appendTypedEntry({
|
||||||
type: "session_info",
|
type: "session_info",
|
||||||
id: await this.storage.createEntryId(),
|
id: await this.storage.createEntryId(),
|
||||||
parentId: await this.storage.getLeafId(),
|
parentId: await this.storage.getLeafId(),
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
name: name.trim(),
|
name: sanitizedName,
|
||||||
} satisfies SessionInfoEntry);
|
} satisfies SessionInfoEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,12 @@ async function runSessionSuite(
|
|||||||
expect(context.messages[1]?.role).toBe("custom");
|
expect(context.messages[1]?.role).toBe("custom");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("normalizes session names", async () => {
|
||||||
|
const session = new Session(await createStorage());
|
||||||
|
await session.appendSessionName(" hello\nworld\r\nagain ");
|
||||||
|
expect(await session.getSessionName()).toBe("hello world again");
|
||||||
|
});
|
||||||
|
|
||||||
it("supports labels and session info entries without affecting context", async () => {
|
it("supports labels and session info entries without affecting context", async () => {
|
||||||
const session = new Session(await createStorage());
|
const session = new Session(await createStorage());
|
||||||
const user1 = await session.appendMessage(createUserMessage("one"));
|
const user1 = await session.appendMessage(createUserMessage("one"));
|
||||||
|
|||||||
Reference in New Issue
Block a user