refactor: harden broadcast groups

This commit is contained in:
Peter Steinberger
2026-01-09 21:29:07 +01:00
parent 374aa856f2
commit 7641b142ad
5 changed files with 730 additions and 454 deletions

View File

@@ -2,6 +2,10 @@ export const DEFAULT_AGENT_ID = "main";
export const DEFAULT_MAIN_KEY = "main";
export const DEFAULT_ACCOUNT_ID = "default";
function normalizeToken(value: string | undefined | null): string {
return (value ?? "").trim().toLowerCase();
}
export type ParsedAgentSessionKey = {
agentId: string;
rest: string;
@@ -97,6 +101,18 @@ export function buildAgentPeerSessionKey(params: {
return `agent:${normalizeAgentId(params.agentId)}:${provider}:${peerKind}:${peerId}`;
}
export function buildGroupHistoryKey(params: {
provider: string;
accountId?: string | null;
peerKind: "group" | "channel";
peerId: string;
}): string {
const provider = normalizeToken(params.provider) || "unknown";
const accountId = normalizeAccountId(params.accountId);
const peerId = params.peerId.trim() || "unknown";
return `${provider}:${accountId}:${params.peerKind}:${peerId}`;
}
export function resolveThreadSessionKeys(params: {
baseSessionKey: string;
threadId?: string | null;