fix: preserve agent id casing
This commit is contained in:
@@ -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() : "";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,7 +665,7 @@ async function handleSendAction(ctx: ResolvedActionContext): Promise<MessageActi
|
||||
threadId: threadId ?? slackAutoThreadId,
|
||||
})
|
||||
: null;
|
||||
if (outboundRoute && !dryRun && agentId) {
|
||||
if (outboundRoute && agentId && !dryRun) {
|
||||
await ensureOutboundSessionEntry({
|
||||
cfg,
|
||||
agentId,
|
||||
|
||||
@@ -92,12 +92,13 @@ function listAgents(cfg: ClawdbotConfig) {
|
||||
}
|
||||
|
||||
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);
|
||||
if (agents.length === 0) return normalized;
|
||||
if (agents.some((agent) => 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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user