UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) • 2.44 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { f as resolveAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import { n as isAvatarDataUrl, o as isWindowsAbsolutePath, r as isAvatarHttpUrl, t as hasAvatarUriScheme } from "./avatar-policy-C1iXc49e.mjs"; import { o as resolveLocalAgentAvatarPath } from "./identity-avatar-file-CzRs1l0-.mjs"; import { i as loadAgentIdentityFromWorkspace } from "./identity-file-C4Fvs-OY.mjs"; import { n as resolveAgentIdentity } from "./identity-Cd2mxvzm.mjs"; import path from "node:path"; //#region src/agents/identity-avatar.ts /** * Resolves public avatar sources for configured agent identities. */ const PUBLIC_AVATAR_SOURCE_MAX_CHARS = 256; const PUBLIC_DATA_AVATAR_HEADER_MAX_CHARS = 64; function isSafeRelativeAvatarSource(e) { if (e.length > PUBLIC_AVATAR_SOURCE_MAX_CHARS || e.startsWith("~") || path.isAbsolute(e) || isWindowsAbsolutePath(e) || hasAvatarUriScheme(e) || e.includes("\0")) return false; return e.replace(/\\/g, "/").split("/").every((e) => e !== ".."); } /** Return a safe public description of the configured avatar source. */ function resolvePublicAgentAvatarSource(e) { const t = normalizeOptionalString(e.source) ?? null; if (!t) return; if (isAvatarDataUrl(t)) { const e = t.indexOf(","); return `${e > 0 ? t.slice(0, Math.min(e, PUBLIC_DATA_AVATAR_HEADER_MAX_CHARS)) : t.slice(0, PUBLIC_DATA_AVATAR_HEADER_MAX_CHARS)},...`; } if (isAvatarHttpUrl(t)) return "remote URL"; return isSafeRelativeAvatarSource(t) ? t : void 0; } /** Resolve the effective avatar for an agent, including config and IDENTITY.md. */ function resolveAgentAvatar(e, t) { const n = normalizeOptionalString(resolveAgentIdentity(e, t)?.avatar) ?? normalizeOptionalString(loadAgentIdentityFromWorkspace(resolveAgentWorkspaceDir(e, t))?.avatar); if (!n) return { kind: "none", reason: "missing" }; if (isAvatarHttpUrl(n)) return { kind: "remote", url: n, source: n }; if (isAvatarDataUrl(n)) return { kind: "data", url: n, source: n }; const r = resolveAgentWorkspaceDir(e, t); const i = resolveLocalAgentAvatarPath({ raw: n, workspaceDir: r }); if (!i.ok) return { kind: "none", reason: i.reason, source: n }; return { kind: "local", filePath: i.value.filePath, source: n }; } //#endregion export { resolvePublicAgentAvatarSource as n, resolveAgentAvatar as t };