mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-23 22:21:11 +00:00
* refactor(normalization): consolidate string helpers * refactor(normalization): consolidate agent ids * refactor(paths): consolidate user path resolution * refactor(gateway): preserve transcript helper facade * fix(normalization): align helper build aliases * fix(memory): keep helper import line neutral * chore(plugin-sdk): align consolidated helper surface * refactor(normalization): reuse lowercase string helper * refactor(normalization): reuse record guard * refactor(normalization): share surrogate boundary helper * refactor(agents): share token estimate constant * refactor(memory): distinguish standalone helper contracts * refactor(normalization): share error cause formatter * refactor(config): distinguish eligibility predicates * refactor(plugins): share registry state symbol * refactor(cli): reuse outbound dependency adapter * refactor(cron): distinguish positive duration parser * fix(gateway): keep transcript helper private * fix(paths): preserve public helper status * refactor(channels): reuse registry normalizer * refactor(agents): reuse agent core runtime facade * refactor(auth): reuse locked profile upsert * refactor(records): distinguish trap-safe guard * refactor(migrations): distinguish sync directory helper * test(plugins): drop stale duration alias expectations * fix(channels): remove stale registry import * chore(plugin-sdk): refresh helper API baseline * fix(memory): keep renamed helpers private * fix(plugins): keep registry state key private * fix(plugin-sdk): tighten wildcard surface budget * chore(plugin-sdk): refresh rebased helper API baseline
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { normalizeLowercaseStringOrEmpty } from "./string-coerce.js";
|
|
|
|
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. */
|
|
export function normalizeAgentId(value: string | undefined | null): string {
|
|
const trimmed = (value ?? "").trim();
|
|
if (!trimmed) {
|
|
return DEFAULT_AGENT_ID;
|
|
}
|
|
const normalized = normalizeLowercaseStringOrEmpty(trimmed);
|
|
if (VALID_ID_RE.test(trimmed)) {
|
|
return normalized;
|
|
}
|
|
return (
|
|
normalized
|
|
.replace(INVALID_CHARS_RE, "-")
|
|
.replace(LEADING_DASH_RE, "")
|
|
.replace(TRAILING_DASH_RE, "")
|
|
.slice(0, 64) || DEFAULT_AGENT_ID
|
|
);
|
|
}
|
|
|
|
/** Returns whether a value is already a canonical agent-id input. */
|
|
export function isValidAgentId(value: string | undefined | null): boolean {
|
|
const trimmed = (value ?? "").trim();
|
|
return Boolean(trimmed) && VALID_ID_RE.test(trimmed);
|
|
}
|