fix: preserve agent id casing

This commit is contained in:
Peter Steinberger
2026-01-24 12:23:11 +00:00
parent 49c518951c
commit fa746b05de
5 changed files with 23 additions and 25 deletions

View File

@@ -1,7 +1,6 @@
import type { Command } from "commander"; import type { Command } from "commander";
import type { CronJob } from "../../cron/types.js"; import type { CronJob } from "../../cron/types.js";
import { danger } from "../../globals.js"; import { danger } from "../../globals.js";
import { normalizeAgentId } from "../../routing/session-key.js";
import { defaultRuntime } from "../../runtime.js"; import { defaultRuntime } from "../../runtime.js";
import type { GatewayRpcOpts } from "../gateway-rpc.js"; import type { GatewayRpcOpts } from "../gateway-rpc.js";
import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js"; import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js";
@@ -139,9 +138,7 @@ export function registerCronAddCommand(cron: Command) {
} }
const agentId = const agentId =
typeof opts.agent === "string" && opts.agent.trim() typeof opts.agent === "string" && opts.agent.trim() ? opts.agent.trim() : undefined;
? normalizeAgentId(opts.agent)
: undefined;
const payload = (() => { const payload = (() => {
const systemEvent = typeof opts.systemEvent === "string" ? opts.systemEvent.trim() : ""; const systemEvent = typeof opts.systemEvent === "string" ? opts.systemEvent.trim() : "";

View File

@@ -1,6 +1,5 @@
import type { Command } from "commander"; import type { Command } from "commander";
import { danger } from "../../globals.js"; import { danger } from "../../globals.js";
import { normalizeAgentId } from "../../routing/session-key.js";
import { defaultRuntime } from "../../runtime.js"; import { defaultRuntime } from "../../runtime.js";
import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js"; import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js";
import { import {
@@ -91,7 +90,7 @@ export function registerCronEditCommand(cron: Command) {
throw new Error("Use --agent or --clear-agent, not both"); throw new Error("Use --agent or --clear-agent, not both");
} }
if (typeof opts.agent === "string" && opts.agent.trim()) { if (typeof opts.agent === "string" && opts.agent.trim()) {
patch.agentId = normalizeAgentId(opts.agent); patch.agentId = opts.agent.trim();
} }
if (opts.clearAgent) { if (opts.clearAgent) {
patch.agentId = null; patch.agentId = null;

View File

@@ -1,4 +1,3 @@
import { normalizeAgentId } from "../routing/session-key.js";
import { parseAbsoluteTimeMs } from "./parse.js"; import { parseAbsoluteTimeMs } from "./parse.js";
import { migrateLegacyCronPayload } from "./payload-migration.js"; import { migrateLegacyCronPayload } from "./payload-migration.js";
import type { CronJobCreate, CronJobPatch } from "./types.js"; import type { CronJobCreate, CronJobPatch } from "./types.js";
@@ -76,7 +75,7 @@ export function normalizeCronJobInput(
next.agentId = null; next.agentId = null;
} else if (typeof agentId === "string") { } else if (typeof agentId === "string") {
const trimmed = agentId.trim(); const trimmed = agentId.trim();
if (trimmed) next.agentId = normalizeAgentId(trimmed); if (trimmed) next.agentId = trimmed;
else delete next.agentId; else delete next.agentId;
} }
} }

View File

@@ -665,7 +665,7 @@ async function handleSendAction(ctx: ResolvedActionContext): Promise<MessageActi
threadId: threadId ?? slackAutoThreadId, threadId: threadId ?? slackAutoThreadId,
}) })
: null; : null;
if (outboundRoute && !dryRun && agentId) { if (outboundRoute && agentId && !dryRun) {
await ensureOutboundSessionEntry({ await ensureOutboundSessionEntry({
cfg, cfg,
agentId, agentId,

View File

@@ -92,12 +92,13 @@ function listAgents(cfg: ClawdbotConfig) {
} }
function pickFirstExistingAgentId(cfg: ClawdbotConfig, agentId: string): string { function pickFirstExistingAgentId(cfg: ClawdbotConfig, agentId: string): string {
const normalized = normalizeAgentId(agentId); const trimmed = (agentId ?? "").trim();
if (!trimmed) return normalizeAgentId(resolveDefaultAgentId(cfg));
const normalized = normalizeAgentId(trimmed);
const agents = listAgents(cfg); const agents = listAgents(cfg);
if (agents.length === 0) return normalized; if (agents.length === 0) return trimmed;
if (agents.some((agent) => normalizeAgentId(agent.id) === normalized)) { const match = agents.find((agent) => normalizeAgentId(agent.id) === normalized);
return normalized; if (match?.id?.trim()) return match.id.trim();
}
return normalizeAgentId(resolveDefaultAgentId(cfg)); return normalizeAgentId(resolveDefaultAgentId(cfg));
} }
@@ -155,21 +156,23 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR
const choose = (agentId: string, matchedBy: ResolvedAgentRoute["matchedBy"]) => { const choose = (agentId: string, matchedBy: ResolvedAgentRoute["matchedBy"]) => {
const resolvedAgentId = pickFirstExistingAgentId(input.cfg, agentId); const resolvedAgentId = pickFirstExistingAgentId(input.cfg, agentId);
const sessionKey = buildAgentSessionKey({
agentId: resolvedAgentId,
channel,
peer,
dmScope,
identityLinks,
}).toLowerCase();
const mainSessionKey = buildAgentMainSessionKey({
agentId: resolvedAgentId,
mainKey: DEFAULT_MAIN_KEY,
}).toLowerCase();
return { return {
agentId: resolvedAgentId, agentId: resolvedAgentId,
channel, channel,
accountId, accountId,
sessionKey: buildAgentSessionKey({ sessionKey,
agentId: resolvedAgentId, mainSessionKey,
channel,
peer,
dmScope,
identityLinks,
}),
mainSessionKey: buildAgentMainSessionKey({
agentId: resolvedAgentId,
mainKey: DEFAULT_MAIN_KEY,
}),
matchedBy, matchedBy,
}; };
}; };