refactor: normalize main session key handling

This commit is contained in:
Peter Steinberger
2026-01-09 22:30:10 +01:00
parent 83270f98f7
commit 6c7a27c010
14 changed files with 40 additions and 30 deletions

View File

@@ -33,6 +33,7 @@ import {
setVoiceWakeTriggers,
} from "../infra/voicewake.js";
import { clearCommandLane } from "../process/command-queue.js";
import { normalizeMainKey } from "../routing/session-key.js";
import { defaultRuntime } from "../runtime.js";
import { buildMessageWithAttachments } from "./chat-attachments.js";
import {
@@ -944,8 +945,7 @@ export function createBridgeHandlers(ctx: BridgeHandlersContext) {
if (text.length > 20_000) return;
const sessionKeyRaw =
typeof obj.sessionKey === "string" ? obj.sessionKey.trim() : "";
const mainKey =
(loadConfig().session?.mainKey ?? "main").trim() || "main";
const mainKey = normalizeMainKey(loadConfig().session?.mainKey);
const sessionKey = sessionKeyRaw.length > 0 ? sessionKeyRaw : mainKey;
const { storePath, store, entry } = loadSessionEntry(sessionKey);
const now = Date.now();

View File

@@ -9,6 +9,7 @@ import {
saveSessionStore,
} from "../../config/sessions.js";
import { registerAgentRunContext } from "../../infra/agent-events.js";
import { normalizeMainKey } from "../../routing/session-key.js";
import { defaultRuntime } from "../../runtime.js";
import { resolveSendPolicy } from "../../sessions/send-policy.js";
import { normalizeMessageProvider } from "../../utils/message-provider.js";
@@ -129,7 +130,7 @@ export const agentHandlers: GatewayRequestHandlers = {
cfg,
agentId,
});
const rawMainKey = (cfg.session?.mainKey ?? "main").trim() || "main";
const rawMainKey = normalizeMainKey(cfg.session?.mainKey);
if (
requestedSessionKey === mainSessionKey ||
requestedSessionKey === rawMainKey

View File

@@ -21,8 +21,8 @@ import {
type SessionScope,
} from "../config/sessions.js";
import {
DEFAULT_MAIN_KEY,
normalizeAgentId,
normalizeMainKey,
parseAgentSessionKey,
} from "../routing/session-key.js";
@@ -255,8 +255,7 @@ export function listAgentsForGateway(cfg: ClawdbotConfig): {
agents: GatewayAgentRow[];
} {
const defaultId = normalizeAgentId(resolveDefaultAgentId(cfg));
const mainKey =
(cfg.session?.mainKey ?? DEFAULT_MAIN_KEY).trim() || DEFAULT_MAIN_KEY;
const mainKey = normalizeMainKey(cfg.session?.mainKey);
const scope = cfg.session?.scope ?? "per-sender";
const configuredById = new Map<string, { name?: string }>();
for (const entry of cfg.agents?.list ?? []) {