UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

87 lines (86 loc) • 3.02 kB
import { d as normalizeMediaFacts } from "./media-facts-B-0Dpo5L.mjs"; import { i as shouldLogVerbose, r as logVerbose } from "./globals-CgepmiqE.mjs"; import { t as formatAudioTranscripts } from "./format-DRIP403s.mjs"; import { t as isAudioAttachment } from "./attachments.normalize-_9E9xPsg.mjs"; import { n as runCapability } from "./runner-owrA54Pb.mjs"; import { r as sendTranscriptEcho, t as DEFAULT_ECHO_TRANSCRIPT_FORMAT } from "./echo-transcript-C-BDqHL2.mjs"; import { i as resolveMediaAttachmentLocalRoots, r as normalizeMediaAttachments, t as createMediaAttachmentCache } from "./runner.attachments-Dzrzdim3.mjs"; import { t as buildMediaUnderstandingRegistry } from "./provider-registry-KU-YX8vG.mjs"; //#region src/media-understanding/audio-preflight.ts /** * Transcribes the first audio attachment BEFORE mention checking. * This allows voice notes to be processed in group chats with requireMention: true. * Returns the transcript or undefined if transcription fails or no audio is found. */ async function transcribeFirstAudio(e) { return transcribeAudio(e, true); } /** Transcribes the configured audio selection before an internal user turn is staged. */ async function transcribeAudioAttachments(e) { return transcribeAudio(e, false); } async function transcribeAudio(e, t) { const { ctx: n, cfg: r } = e; const i = r.tools?.media?.audio; if (i?.enabled === false) return; const a = normalizeMediaAttachments(n); const o = a.find((e) => isAudioAttachment(e) && !e.alreadyTranscribed); if (!o) return; try { const s = t ? [o] : a; const { agentDir: c, providers: l, activeModel: u } = e; const d = resolveMediaAttachmentLocalRoots({ cfg: r, ctx: n }); const f = buildMediaUnderstandingRegistry(l, r); const p = createMediaAttachmentCache(s, { localPathRoots: d, ssrfPolicy: r.tools?.web?.fetch?.ssrfPolicy }); let m; try { m = await runCapability({ capability: "audio", cfg: r, ctx: n, attachments: p, media: s, agentDir: c, workspaceDir: e.workspaceDir, assertCurrent: e.assertCurrent, providerRegistry: f, config: r.tools?.media?.audio, activeModel: u }); } finally { await p.cleanup(); } if (!t) n.MediaUnderstandingDecisions = [...n.MediaUnderstandingDecisions ?? [], m.decision]; const h = m.outputs.filter((e) => e.kind === "audio.transcription" && e.text.trim()); const g = formatAudioTranscripts(h).trim(); if (!g) return; if (i?.echoTranscript) await sendTranscriptEcho({ ctx: n, cfg: r, transcript: g, format: i.echoFormat ?? "📝 \"{transcript}\"" }); const _ = normalizeMediaFacts(n.media); for (const e of h) { const n = t ? o.index : e.attachmentIndex; const r = _[n]; if (r) _[n] = { ...r, transcribed: true }; } n.media = _; return g; } catch (e) { if (shouldLogVerbose()) logVerbose(`audio-preflight: transcription failed: ${String(e)}`); return; } } //#endregion export { transcribeAudioAttachments, transcribeFirstAudio };