fix: canonicalize main session keys

This commit is contained in:
Peter Steinberger
2026-01-15 08:04:27 +00:00
parent a5a9788b20
commit 53d0bf653a
4 changed files with 98 additions and 4 deletions

View File

@@ -22,6 +22,16 @@ export const PresenceEntrySchema = Type.Object(
export const HealthSnapshotSchema = Type.Any();
export const SessionDefaultsSchema = Type.Object(
{
defaultAgentId: NonEmptyString,
mainKey: NonEmptyString,
mainSessionKey: NonEmptyString,
scope: Type.Optional(NonEmptyString),
},
{ additionalProperties: false },
);
export const StateVersionSchema = Type.Object(
{
presence: Type.Integer({ minimum: 0 }),
@@ -38,6 +48,7 @@ export const SnapshotSchema = Type.Object(
uptimeMs: Type.Integer({ minimum: 0 }),
configPath: Type.Optional(NonEmptyString),
stateDir: Type.Optional(NonEmptyString),
sessionDefaults: Type.Optional(SessionDefaultsSchema),
},
{ additionalProperties: false },
);

View File

@@ -1,5 +1,8 @@
import { resolveDefaultAgentId } from "../../agents/agent-scope.js";
import { getHealthSnapshot, type HealthSummary } from "../../commands/health.js";
import { CONFIG_PATH_CLAWDBOT, STATE_DIR_CLAWDBOT } from "../../config/config.js";
import { CONFIG_PATH_CLAWDBOT, STATE_DIR_CLAWDBOT, loadConfig } from "../../config/config.js";
import { resolveMainSessionKey } from "../../config/sessions.js";
import { normalizeMainKey } from "../../routing/session-key.js";
import { listSystemPresence } from "../../infra/system-presence.js";
import type { Snapshot } from "../protocol/index.js";
@@ -10,6 +13,11 @@ let healthRefresh: Promise<HealthSummary> | null = null;
let broadcastHealthUpdate: ((snap: HealthSummary) => void) | null = null;
export function buildGatewaySnapshot(): Snapshot {
const cfg = loadConfig();
const defaultAgentId = resolveDefaultAgentId(cfg);
const mainKey = normalizeMainKey(cfg.session?.mainKey);
const mainSessionKey = resolveMainSessionKey(cfg);
const scope = cfg.session?.scope ?? "per-sender";
const presence = listSystemPresence();
const uptimeMs = Math.round(process.uptime() * 1000);
// Health is async; caller should await getHealthSnapshot and replace later if needed.
@@ -22,6 +30,12 @@ export function buildGatewaySnapshot(): Snapshot {
// Surface resolved paths so UIs can display the true config location.
configPath: CONFIG_PATH_CLAWDBOT,
stateDir: STATE_DIR_CLAWDBOT,
sessionDefaults: {
defaultAgentId,
mainKey,
mainSessionKey,
scope,
},
};
}