UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

58 lines (57 loc) • 2.02 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { d as normalizeMediaFacts, h as resolveMediaFactKind } from "./media-facts-B-0Dpo5L.mjs"; import { assertNoWindowsNetworkPath, safeFileURLToPath } from "@openclaw/fs-safe/advanced"; //#region src/media-understanding/attachments.normalize.ts /** Normalizes a local attachment path while rejecting remote file URLs and Windows UNC paths. */ function normalizeAttachmentPath(e) { const t = normalizeOptionalString(e); if (!t) return; if (/^file:/iu.test(t)) try { return safeFileURLToPath(t); } catch { return; } try { assertNoWindowsNetworkPath(t, "Attachment path"); } catch { return; } return t; } /** Converts ordered media facts into indexed attachment records. */ function normalizeAttachments(e) { return normalizeMediaFacts(e.media).map((e, t) => { const n = { path: e.path, url: e.url, mime: e.contentType, index: t, alreadyTranscribed: e.transcribed === true }; const r = e.fileName ? resolveMediaFactKind(e) ?? e.kind : e.kind; if (r) n.kind = r; if (e.fileName) n.fileName = e.fileName; if (e.workspaceDir) n.workspaceDir = e.workspaceDir; return n; }).filter((e) => Boolean(e.path ?? e.url)); } /** Classifies an attachment by authoritative kind, MIME, then canonical filename metadata. */ function resolveAttachmentKind(e) { const t = resolveMediaFactKind({ path: e.path, url: e.url, contentType: e.mime, kind: e.kind }); return t === "sticker" ? "image" : t === "document" ? "unknown" : t ?? "unknown"; } /** Returns true when the attachment is classified as audio media. */ function isAudioAttachment(e) { return resolveAttachmentKind(e) === "audio"; } /** Returns true when the attachment is classified as image media. */ function isImageAttachment(e) { return resolveAttachmentKind(e) === "image"; } //#endregion export { resolveAttachmentKind as a, normalizeAttachments as i, isImageAttachment as n, normalizeAttachmentPath as r, isAudioAttachment as t };