refactor(sessions): add provider key normalizers

This commit is contained in:
Peter Steinberger
2026-03-08 01:17:06 +00:00
parent 8f719e541a
commit ad7399b6e6
5 changed files with 101 additions and 2 deletions

View File

@@ -2,6 +2,16 @@ import { describe, expect, it } from "vitest";
import { normalizeExplicitDiscordSessionKey } from "./session-key-normalization.js";
describe("normalizeExplicitDiscordSessionKey", () => {
it("rewrites bare discord:dm keys for direct chats", () => {
expect(
normalizeExplicitDiscordSessionKey("discord:dm:123456", {
ChatType: "direct",
From: "discord:123456",
SenderId: "123456",
}),
).toBe("discord:direct:123456");
});
it("rewrites legacy discord:dm keys for direct chats", () => {
expect(
normalizeExplicitDiscordSessionKey("agent:fina:discord:dm:123456", {

View File

@@ -10,6 +10,7 @@ export function normalizeExplicitDiscordSessionKey(
return normalized;
}
normalized = normalized.replace(/^(discord:)dm:/, "$1direct:");
normalized = normalized.replace(/^(agent:[^:]+:discord:)dm:/, "$1direct:");
const match = normalized.match(/^((?:agent:[^:]+:)?)discord:channel:([^:]+)$/);
if (!match) {