openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
28 lines (27 loc) • 1.15 kB
JavaScript
import { n as ok, t as err } from "./result-CV1-31DB.mjs";
//#region packages/normalization-core/src/agent-id.ts
const DEFAULT_AGENT_ID = "main";
const VALID_ID_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
const INVALID_CHARS_RE = /[^a-z0-9_-]+/g;
const LEADING_DASH_RE = /^-+/;
const TRAILING_DASH_RE = /-+$/;
/** Normalizes an OpenClaw agent id to its filesystem-safe canonical form. */
function normalizeAgentId(e) {
const t = normalizeAgentIdStrict(e);
return t.ok ? t.value : DEFAULT_AGENT_ID;
}
/** Normalizes an explicitly supplied agent id without falling back to the default agent. */
function normalizeAgentIdStrict(e) {
const t = (e ?? "").trim();
const n = t.toLowerCase();
if (VALID_ID_RE.test(t)) return ok(n);
const r = n.replace(INVALID_CHARS_RE, "-").replace(LEADING_DASH_RE, "").replace(TRAILING_DASH_RE, "").slice(0, 64);
return r ? ok(r) : err("unrepresentable");
}
/** Returns whether a value is already a canonical agent-id input. */
function isValidAgentId(e) {
const t = (e ?? "").trim();
return Boolean(t) && VALID_ID_RE.test(t);
}
//#endregion
export { normalizeAgentId as n, normalizeAgentIdStrict as r, isValidAgentId as t };