fix: clean docker onboarding warnings + preserve agentId casing

This commit is contained in:
Peter Steinberger
2026-01-24 19:07:01 +00:00
parent bcedeb4e1f
commit 6d79c6cd26
8 changed files with 111 additions and 14 deletions

View File

@@ -7,6 +7,7 @@ import {
DEFAULT_ACCOUNT_ID,
DEFAULT_MAIN_KEY,
normalizeAgentId,
sanitizeAgentId,
} from "./session-key.js";
export type RoutePeerKind = "dm" | "group" | "channel";
@@ -93,13 +94,13 @@ function listAgents(cfg: ClawdbotConfig) {
function pickFirstExistingAgentId(cfg: ClawdbotConfig, agentId: string): string {
const trimmed = (agentId ?? "").trim();
if (!trimmed) return normalizeAgentId(resolveDefaultAgentId(cfg));
if (!trimmed) return sanitizeAgentId(resolveDefaultAgentId(cfg));
const normalized = normalizeAgentId(trimmed);
const agents = listAgents(cfg);
if (agents.length === 0) return normalized;
if (agents.length === 0) return sanitizeAgentId(trimmed);
const match = agents.find((agent) => normalizeAgentId(agent.id) === normalized);
if (match?.id?.trim()) return normalizeAgentId(match.id.trim());
return normalizeAgentId(resolveDefaultAgentId(cfg));
if (match?.id?.trim()) return sanitizeAgentId(match.id.trim());
return sanitizeAgentId(resolveDefaultAgentId(cfg));
}
function matchesChannel(

View File

@@ -64,6 +64,19 @@ export function normalizeAgentId(value: string | undefined | null): string {
);
}
export function sanitizeAgentId(value: string | undefined | null): string {
const trimmed = (value ?? "").trim();
if (!trimmed) return DEFAULT_AGENT_ID;
if (/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(trimmed)) return trimmed;
return (
trimmed
.replace(/[^a-z0-9_-]+/gi, "-")
.replace(/^-+/, "")
.replace(/-+$/, "")
.slice(0, 64) || DEFAULT_AGENT_ID
);
}
export function normalizeAccountId(value: string | undefined | null): string {
const trimmed = (value ?? "").trim();
if (!trimmed) return DEFAULT_ACCOUNT_ID;