UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

43 lines (42 loc) • 1.41 kB
//#region packages/media-understanding-common/src/format.ts const sectionByKind = { "audio.transcription": { title: "Audio", label: "Transcript" }, "image.description": { title: "Image", label: "Description" }, "video.description": { title: "Video", label: "Description" } }; /** Formats media-understanding outputs into the chat body sent back to the model. */ function formatMediaUnderstandingBody(e) { const t = e.outputs.filter((e) => e.text.trim()); if (t.length === 0) return e.body ?? ""; const n = e.body?.trim() || void 0; const r = []; if (n && t.length > 1) r.push(`User text:\n${n}`); const i = /* @__PURE__ */ new Map(); for (const e of t) i.set(e.kind, (i.get(e.kind) ?? 0) + 1); const a = /* @__PURE__ */ new Map(); for (const e of t) { const o = i.get(e.kind) ?? 1; const s = (a.get(e.kind) ?? 0) + 1; a.set(e.kind, s); const c = o > 1 ? ` ${s}/${o}` : ""; const l = sectionByKind[e.kind]; const u = t.length === 1 && n ? `User text:\n${n}\n` : ""; r.push(`[${l.title}${c}]\n${u}${l.label}:\n${e.text}`); } return r.join("\n\n").trim(); } /** Formats one or more audio transcript outputs for legacy transcript-only callers. */ function formatAudioTranscripts(e) { return e.map((t, n) => e.length === 1 ? t.text : `Audio ${n + 1}:\n${t.text}`).join("\n\n"); } //#endregion export { formatMediaUnderstandingBody as n, formatAudioTranscripts as t };