openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.3 kB
JavaScript
import{l as asNonNegativeFiniteNumber}from"./number-coercion-B3CfI447.mjs";
//!src/gateway/server-methods/attachment-normalize.ts
function normalizeAttachmentContent(e){if(typeof e===`string`)return e;if(ArrayBuffer.isView(e))return Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`);if(e instanceof ArrayBuffer)return Buffer.from(e).toString(`base64`)}function normalizeRpcAttachmentsToChatAttachments(e){return e?.map(e=>{const t=e?.source&&typeof e.source===`object`?e.source:void 0;const n=typeof t?.media_type===`string`?t.media_type:void 0;const r=t?.type===`base64`?normalizeAttachmentContent(t.data):void 0;const i=asNonNegativeFiniteNumber(e?.sizeBytes);const a=asNonNegativeFiniteNumber(e?.durationMs);const o=asNonNegativeFiniteNumber(e?.width);const s=asNonNegativeFiniteNumber(e?.height);return{type:typeof e?.type===`string`?e.type:void 0,mimeType:typeof e?.mimeType===`string`?e.mimeType:n,fileName:typeof e?.fileName===`string`?e.fileName:void 0,content:normalizeAttachmentContent(e?.content)??r,...e?.origin===`paste`||e?.origin===`file`?{origin:e.origin}:{},...i!==void 0?{sizeBytes:i}:{},...a!==void 0?{durationMs:a}:{},...o!==void 0?{width:o}:{},...s!==void 0?{height:s}:{}}}).filter(e=>e.content!==void 0)??[]}export{normalizeRpcAttachmentsToChatAttachments as t};