fix(sandbox): canonicalize agent main alias

This commit is contained in:
Peter Steinberger
2026-01-12 02:22:56 +00:00
parent 828d9955f2
commit 76c8fc8697
6 changed files with 68 additions and 16 deletions

View File

@@ -250,6 +250,33 @@ export function resolveAgentMainSessionKey(params: {
return buildAgentMainSessionKey({ agentId: params.agentId, mainKey });
}
export function canonicalizeMainSessionAlias(params: {
cfg?: { session?: { scope?: SessionScope; mainKey?: string } };
agentId: string;
sessionKey: string;
}): string {
const raw = params.sessionKey.trim();
if (!raw) return raw;
const agentId = normalizeAgentId(params.agentId);
const mainKey = normalizeMainKey(params.cfg?.session?.mainKey);
const agentMainSessionKey = buildAgentMainSessionKey({ agentId, mainKey });
const agentMainAliasKey = buildAgentMainSessionKey({
agentId,
mainKey: "main",
});
const isMainAlias =
raw === "main" ||
raw === mainKey ||
raw === agentMainSessionKey ||
raw === agentMainAliasKey;
if (params.cfg?.session?.scope === "global" && isMainAlias) return "global";
if (isMainAlias) return agentMainSessionKey;
return raw;
}
function normalizeGroupLabel(raw?: string) {
const trimmed = raw?.trim().toLowerCase() ?? "";
if (!trimmed) return "";