openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
112 lines (111 loc) • 3.85 kB
JavaScript
import { t as normalizeControlUiBasePath } from "./control-ui-shared-_tUmz6W8.mjs";
//#region src/gateway/control-ui-user-avatar-route.ts
const CONTROL_UI_USER_AVATAR_PATH_PREFIX = "/api/users/";
const CONTROL_UI_USER_AVATAR_PATH_SUFFIX = "/avatar";
function buildControlUiUserAvatarPath(e, t, n) {
const r = `${normalizeControlUiBasePath(n)}${CONTROL_UI_USER_AVATAR_PATH_PREFIX}${encodeURIComponent(e)}${CONTROL_UI_USER_AVATAR_PATH_SUFFIX}`;
return t === void 0 ? r : `${r}?v=${encodeURIComponent(String(t))}`;
}
//#endregion
//#region src/gateway/control-ui-resource-routes.ts
const CONTROL_UI_ASSISTANT_MEDIA_PREFIX = "/__openclaw__/assistant-media";
function resolveAssistantMediaRoutePath(e) {
return `${e && e !== "/" ? e.endsWith("/") ? e.slice(0, -1) : e : ""}${CONTROL_UI_ASSISTANT_MEDIA_PREFIX}`;
}
const CONTROL_UI_RESOURCE_ROUTES = {
agentAvatar: {
prefix: "/avatar",
suffix: ""
},
catalogIcon: {
prefix: "/__openclaw__/catalog-icon",
suffix: ""
},
channelAvatar: {
prefix: "/__openclaw__/channel-avatar",
suffix: ""
},
linkFavicon: {
prefix: "/__openclaw__/link-favicon",
suffix: ""
},
pluginIcon: {
prefix: "/__openclaw__/plugin-icon",
suffix: ""
},
pluginActivityIcon: {
prefix: "/__openclaw__/plugin-activity-icon",
suffix: ""
},
pluginThemeArt: {
prefix: "/__openclaw__/plugin-theme-art",
suffix: ""
},
userAvatar: {
prefix: CONTROL_UI_USER_AVATAR_PATH_PREFIX.slice(0, -1),
suffix: CONTROL_UI_USER_AVATAR_PATH_SUFFIX
},
workspaceIcon: {
prefix: "/__openclaw__/workspace-icon",
suffix: ""
}
};
/** Builds one canonical, encoded Control UI resource path. */
function buildControlUiResourcePath(e, t, n, r = []) {
const i = CONTROL_UI_RESOURCE_ROUTES[e];
const a = [n, ...r].map(encodeURIComponent).join("/");
return `${normalizeControlUiBasePath(t)}${i.prefix}/${a}${i.suffix}`;
}
/** Parses exact encoded resource components while retaining malformed-route ownership. */
function parseControlUiResourcePath(e, t, n) {
if (!t) return { matched: false };
const r = CONTROL_UI_RESOURCE_ROUTES[e];
const i = `${normalizeControlUiBasePath(n)}${r.prefix}/`;
if (!t.startsWith(i)) return { matched: false };
const a = t.slice(i.length);
if (!a.endsWith(r.suffix)) return {
matched: true,
value: null
};
const o = (r.suffix ? a.slice(0, -r.suffix.length) : a).split("/");
if (o.length !== (e === "pluginThemeArt" ? 4 : 1) || o.some((e) => !e)) return {
matched: true,
value: null
};
try {
const [e, ...t] = o.map(decodeURIComponent);
return {
matched: true,
value: e || null,
...t.length ? { segments: t } : {}
};
} catch {
return {
matched: true,
value: null
};
}
}
function parseControlUiUserAvatarPath(e, t) {
const n = parseControlUiResourcePath("userAvatar", e);
return n.matched ? n : parseControlUiResourcePath("userAvatar", e, t);
}
/** Builds the authenticated conversation-avatar URL for a session. */
function buildControlUiChannelAvatarUrl(e, t, n) {
return `${buildControlUiResourcePath("channelAvatar", e, t)}?v=${encodeURIComponent(n)}`;
}
/** Matches an exact root-relative same-origin resource URL without parser reinterpretation. */
function matchControlUiResourceUrl(e, t, n) {
if (!t.startsWith("/") || t.startsWith("//") || t.includes("\\")) return;
const r = "http://openclaw.invalid";
const i = URL.parse(t, r);
if (i?.origin !== r || `${i.pathname}${i.search}${i.hash}` !== t) return;
const a = parseControlUiResourcePath(e, i.pathname, n);
return a.matched && a.value ? {
value: a.value,
search: i.search,
hash: i.hash
} : void 0;
}
//#endregion
export { parseControlUiUserAvatarPath as a, parseControlUiResourcePath as i, buildControlUiResourcePath as n, resolveAssistantMediaRoutePath as o, matchControlUiResourceUrl as r, buildControlUiUserAvatarPath as s, buildControlUiChannelAvatarUrl as t };