openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
35 lines (34 loc) • 1.32 kB
JavaScript
import { s as normalizeNullableString } from "./string-coerce-CCIiB4H7.mjs";
import { t as DEFAULT_MAIN_KEY } from "./session-key-DW1jcHbM.mjs";
//#region packages/session-url-contract/src/grammar.ts
const SHORT_SESSION_REF_RE = /^(?:.*-)?([0-9a-f]{8,32})$/iu;
const FIXED_RESERVED_SESSION_RESTS = /* @__PURE__ */ new Set([
"main",
"global",
"boot",
"sessions"
]);
const SESSION_SLUG_MAX_LENGTH = 48;
function controlUiSessionSlug(e) {
return ((e ?? "").toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "").match(/^.*[g-z][a-z0-9]*/u)?.[0] ?? "").slice(0, SESSION_SLUG_MAX_LENGTH).replace(/-+$/gu, "");
}
function normalizeControlUiBasePath(e) {
const t = e?.trim().replace(/^\/+|\/+$/gu, "") ?? "";
return t ? `/${t}` : "";
}
function isReservedSessionRest(e, t) {
const n = e.toLowerCase();
const r = normalizeNullableString(t)?.toLowerCase() ?? "main";
return FIXED_RESERVED_SESSION_RESTS.has(n) || n === r;
}
function parseShortSessionRef(e) {
const t = e.match(SHORT_SESSION_REF_RE)?.[1]?.toLowerCase();
if (!t) return null;
const n = e.slice(0, e.length - t.length).replace(/-+$/u, "");
return n ? {
shortId: t,
slugHint: n
} : { shortId: t };
}
//#endregion
export { parseShortSessionRef as i, isReservedSessionRest as n, normalizeControlUiBasePath as r, controlUiSessionSlug as t };