fix: clean docker onboarding warnings + preserve agentId casing
This commit is contained in:
@@ -2,7 +2,7 @@ import type { Command } from "commander";
|
||||
import type { CronJob } from "../../cron/types.js";
|
||||
import { danger } from "../../globals.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { normalizeAgentId } from "../../routing/session-key.js";
|
||||
import { sanitizeAgentId } from "../../routing/session-key.js";
|
||||
import type { GatewayRpcOpts } from "../gateway-rpc.js";
|
||||
import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js";
|
||||
import { parsePositiveIntOrUndefined } from "../program/helpers.js";
|
||||
@@ -140,7 +140,7 @@ export function registerCronAddCommand(cron: Command) {
|
||||
|
||||
const agentId =
|
||||
typeof opts.agent === "string" && opts.agent.trim()
|
||||
? normalizeAgentId(opts.agent.trim())
|
||||
? sanitizeAgentId(opts.agent.trim())
|
||||
: undefined;
|
||||
|
||||
const payload = (() => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Command } from "commander";
|
||||
import { danger } from "../../globals.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { normalizeAgentId } from "../../routing/session-key.js";
|
||||
import { sanitizeAgentId } from "../../routing/session-key.js";
|
||||
import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js";
|
||||
import {
|
||||
getCronChannelOptions,
|
||||
@@ -91,7 +91,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.trim());
|
||||
patch.agentId = sanitizeAgentId(opts.agent.trim());
|
||||
}
|
||||
if (opts.clearAgent) {
|
||||
patch.agentId = null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { normalizeAgentId } from "../routing/session-key.js";
|
||||
import { sanitizeAgentId } 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 +76,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 = sanitizeAgentId(trimmed);
|
||||
else delete next.agentId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user