diff --git a/src/cli/cron-cli/register.cron-add.ts b/src/cli/cron-cli/register.cron-add.ts index 83a48650b..2fda55e98 100644 --- a/src/cli/cron-cli/register.cron-add.ts +++ b/src/cli/cron-cli/register.cron-add.ts @@ -1,7 +1,6 @@ import type { Command } from "commander"; import type { CronJob } from "../../cron/types.js"; import { danger } from "../../globals.js"; -import { normalizeAgentId } from "../../routing/session-key.js"; import { defaultRuntime } from "../../runtime.js"; import type { GatewayRpcOpts } from "../gateway-rpc.js"; import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js"; @@ -139,9 +138,7 @@ export function registerCronAddCommand(cron: Command) { } const agentId = - typeof opts.agent === "string" && opts.agent.trim() - ? normalizeAgentId(opts.agent) - : undefined; + typeof opts.agent === "string" && opts.agent.trim() ? opts.agent.trim() : undefined; const payload = (() => { const systemEvent = typeof opts.systemEvent === "string" ? opts.systemEvent.trim() : ""; diff --git a/src/cli/cron-cli/register.cron-edit.ts b/src/cli/cron-cli/register.cron-edit.ts index 3b50fc3f5..45eda04da 100644 --- a/src/cli/cron-cli/register.cron-edit.ts +++ b/src/cli/cron-cli/register.cron-edit.ts @@ -1,6 +1,5 @@ import type { Command } from "commander"; import { danger } from "../../globals.js"; -import { normalizeAgentId } from "../../routing/session-key.js"; import { defaultRuntime } from "../../runtime.js"; import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js"; import { @@ -91,7 +90,7 @@ export function registerCronEditCommand(cron: Command) { throw new Error("Use --agent or --clear-agent, not both"); } if (typeof opts.agent === "string" && opts.agent.trim()) { - patch.agentId = normalizeAgentId(opts.agent); + patch.agentId = opts.agent.trim(); } if (opts.clearAgent) { patch.agentId = null; diff --git a/src/cron/normalize.ts b/src/cron/normalize.ts index 25304edb4..3e5515ffe 100644 --- a/src/cron/normalize.ts +++ b/src/cron/normalize.ts @@ -1,4 +1,3 @@ -import { normalizeAgentId } from "../routing/session-key.js"; import { parseAbsoluteTimeMs } from "./parse.js"; import { migrateLegacyCronPayload } from "./payload-migration.js"; import type { CronJobCreate, CronJobPatch } from "./types.js"; @@ -76,7 +75,7 @@ export function normalizeCronJobInput( next.agentId = null; } else if (typeof agentId === "string") { const trimmed = agentId.trim(); - if (trimmed) next.agentId = normalizeAgentId(trimmed); + if (trimmed) next.agentId = trimmed; else delete next.agentId; } } diff --git a/src/infra/outbound/message-action-runner.ts b/src/infra/outbound/message-action-runner.ts index 3a4d13580..2a57db17c 100644 --- a/src/infra/outbound/message-action-runner.ts +++ b/src/infra/outbound/message-action-runner.ts @@ -665,7 +665,7 @@ async function handleSendAction(ctx: ResolvedActionContext): Promise normalizeAgentId(agent.id) === normalized)) { - return normalized; - } + if (agents.length === 0) return trimmed; + const match = agents.find((agent) => normalizeAgentId(agent.id) === normalized); + if (match?.id?.trim()) return match.id.trim(); return normalizeAgentId(resolveDefaultAgentId(cfg)); } @@ -155,21 +156,23 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR const choose = (agentId: string, matchedBy: ResolvedAgentRoute["matchedBy"]) => { 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 { agentId: resolvedAgentId, channel, accountId, - sessionKey: buildAgentSessionKey({ - agentId: resolvedAgentId, - channel, - peer, - dmScope, - identityLinks, - }), - mainSessionKey: buildAgentMainSessionKey({ - agentId: resolvedAgentId, - mainKey: DEFAULT_MAIN_KEY, - }), + sessionKey, + mainSessionKey, matchedBy, }; };