openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 600 B
JavaScript
function ok(e){return{ok:!0,value:e}}function err(e){return{ok:!1,error:e}}const e=/^[a-z0-9][a-z0-9_-]{0,63}$/i,t=/[^a-z0-9_-]+/g,n=/^-+/,r=/-+$/;function normalizeAgentId(e){let t=normalizeAgentIdStrict(e);return t.ok?t.value:`main`}function normalizeAgentIdStrict(i){let a=(i??``).trim(),o=a.toLowerCase();if(e.test(a))return ok(o);let s=o.replace(t,`-`).replace(n,``).replace(r,``).slice(0,64);return s?ok(s):err(`unrepresentable`)}function isValidAgentId(t){let n=(t??``).trim();return!!n&&e.test(n)}export{ok as a,err as i,normalizeAgentId as n,normalizeAgentIdStrict as r,isValidAgentId as t};