openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines • 7.47 kB
JavaScript
import{c as normalizeOptionalLowercaseString,l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{L as resolvePositiveTimerTimeoutMs,d as asPositiveFiniteNumber}from"./number-coercion-B3CfI447.mjs";import{o as asRecord}from"./record-coerce-BTbqdJ3-.mjs";import{c as normalizeOptionalTrimmedStringList}from"./string-normalization-D_oBUpO3.mjs";import{f as resolveRealtimeVoiceAgentConsultToolPolicy}from"./agent-consult-tool-CCU5qa7O.mjs";
//!src/meeting-bot/sox-audio-command.ts
function formatArgs(e){return[`-t`,`raw`,`-r`,String(e.sampleRate),`-c`,String(e.channels),`-e`,e.encoding,`-b`,String(e.bits),...e.endian===`little`?[`-L`]:e.endian===`big`?[`-B`]:[],`-`]}function withBuffer(e,t,n){return[e,`-q`,`--buffer`,String(t),...n]}function buildMeetingSoxAudioCommands(e){const t=formatArgs(e.format);const n=e.device?[`-t`,e.deviceType??`coreaudio`,e.device]:[];return{inputCommand:withBuffer(e.inputExecutable??(e.device?`sox`:`rec`),e.bufferBytes,[...n,...t]),outputCommand:withBuffer(e.outputExecutable??(e.device?`sox`:`play`),e.bufferBytes,[...t,...n])}}
//!src/meeting-bot/audio-backend.ts
const PIPEWIRE_SINK_NAME=`openclaw_meeting_audio`;const PIPEWIRE_MONITOR_NAME=`${PIPEWIRE_SINK_NAME}.monitor`;const PIPEWIRE_SOURCE_NAME=PIPEWIRE_SINK_NAME;const PIPEWIRE_MEETING_AUDIO_DEVICE_LABEL=`OpenClaw Meeting Audio`;const BLACKHOLE_MEETING_AUDIO_DEVICE_LABEL=`BlackHole 2ch`;function resolveMeetingAudioBackend(e,t=process.platform){if(e&&e!==`auto`){if(e===`blackhole-2ch`&&t!==`darwin`)throw new Error(`BlackHole 2ch meeting audio requires macOS.`);if(e===`pipewire-pulse`&&t!==`linux`)throw new Error(`PipeWire-Pulse meeting audio requires Linux.`);return e}if(t===`darwin`)return`blackhole-2ch`;if(t===`linux`)return`pipewire-pulse`;throw new Error(`Local Chrome meeting talk-back is unsupported on ${t}; use transcribe mode or a macOS/Linux Chrome node.`)}function resolveMeetingAudioRuntimeForFormat(e){const t=e.format===`g711-ulaw-8khz`?{sampleRate:8e3,channels:1,encoding:`mu-law`,bits:8}:{sampleRate:24e3,channels:1,encoding:`signed-integer`,bits:16,endian:`little`};const n=resolveMeetingAudioBackend(e.backend,e.platform);const r=t.sampleRate*t.channels*Math.ceil(t.bits/8);const i=Math.max(1,Math.ceil(e.bufferBytes/r*1e3));const pulseCommand=(e,n)=>[e,`--raw`,...e===`pacat`?[`--playback`]:[],`--device=${n}`,`--format=${t.encoding===`mu-law`?`ulaw`:`s16le`}`,`--rate=${t.sampleRate}`,`--channels=${t.channels}`,`--latency-msec=${i}`];const a=n===`blackhole-2ch`?buildMeetingSoxAudioCommands({bufferBytes:e.bufferBytes,device:BLACKHOLE_MEETING_AUDIO_DEVICE_LABEL,deviceType:`coreaudio`,format:t}):{inputCommand:pulseCommand(`parec`,PIPEWIRE_SOURCE_NAME),outputCommand:pulseCommand(`pacat`,PIPEWIRE_SINK_NAME)};return{backend:n,deviceLabel:n===`blackhole-2ch`?BLACKHOLE_MEETING_AUDIO_DEVICE_LABEL:PIPEWIRE_MEETING_AUDIO_DEVICE_LABEL,inputCommand:e.inputCommand?[...e.inputCommand]:a.inputCommand,outputCommand:e.outputCommand?[...e.outputCommand]:a.outputCommand}}function commandOutput(e){return`${e.stdout??``}\n${e.stderr??``}`}function pulseListContains(e,t){return e.split(/\r?\n/u).some(e=>e.split(/\s+/u)[1]===t)}function assertCommandSucceeded(e,t){if(e.code===0)return;const n=commandOutput(e).trim();throw new Error(n?`${t}: ${n}`:t)}async function ensureMeetingAudioBackend(e){if(e.backend===`blackhole-2ch`){const t=await e.run([`/usr/sbin/system_profiler`,`SPAudioDataType`],e.timeoutMs);if(t.code!==0||!commandOutput(t).toLowerCase().includes(`blackhole 2ch`))throw new Error(`BlackHole 2ch audio device not found. Install BlackHole 2ch and SoX, then reboot.`);return}assertCommandSucceeded(await e.run([`pactl`,`info`],e.timeoutMs),`PipeWire-Pulse is unavailable. Start pipewire-pulse and install pulseaudio-utils`);const ensurePulseModule=async(t,n,r)=>{if(pulseListContains((await e.run([`pactl`,`list`,`short`,`${t}s`],e.timeoutMs)).stdout??``,n))return;const i=await e.run([`pactl`,`load-module`,...r],e.timeoutMs);if(i.code!==0){if(!pulseListContains((await e.run([`pactl`,`list`,`short`,`${t}s`],e.timeoutMs)).stdout??``,n))assertCommandSucceeded(i,`Could not create the OpenClaw PipeWire-Pulse ${t}`)}};await ensurePulseModule(`sink`,PIPEWIRE_SINK_NAME,[`module-null-sink`,`sink_name=${PIPEWIRE_SINK_NAME}`,`rate=48000`,`channels=2`,`channel_map=front-left,front-right`,`sink_properties='device.description="${PIPEWIRE_MEETING_AUDIO_DEVICE_LABEL}"'`]);await ensurePulseModule(`source`,PIPEWIRE_SOURCE_NAME,[`module-remap-source`,`source_name=${PIPEWIRE_SOURCE_NAME}`,`master=${PIPEWIRE_MONITOR_NAME}`,`channels=2`,`master_channel_map=front-left,front-right`,`channel_map=front-left,front-right`,`remix=no`,`source_properties='device.description="${PIPEWIRE_MEETING_AUDIO_DEVICE_LABEL}"'`])}
//!src/plugin-sdk/meeting-config.ts
function buildMeetingConfigAudioCommands(e,t,n){return resolveMeetingAudioRuntimeForFormat({backend:e,format:t,bufferBytes:n,platform:e===`pipewire-pulse`||e===`auto`&&process.platform===`linux`?`linux`:`darwin`})}function resolveMeetingChromeConfig(e,t){const n=Math.max(17,Math.trunc(asPositiveFiniteNumber(e.audioBufferBytes)??4096));const r=normalizeOptionalLowercaseString(e.audioBackend)?.replaceAll(`_`,`-`);const i=r===`blackhole-2ch`||r===`pipewire-pulse`?r:`auto`;const a=normalizeOptionalTrimmedStringList(e.audioInputCommand);const o=normalizeOptionalTrimmedStringList(e.audioOutputCommand);const s=t.resolveAudioFormat(a!==void 0||o!==void 0);const c=buildMeetingConfigAudioCommands(i,s,n);return{audioBackend:i,audioFormat:s,audioBufferBytes:n,launch:typeof e.launch===`boolean`?e.launch:true,browserProfile:normalizeOptionalString(e.browserProfile),guestName:normalizeOptionalString(e.guestName)??`OpenClaw Agent`,reuseExistingTab:typeof e.reuseExistingTab===`boolean`?e.reuseExistingTab:true,autoJoin:typeof e.autoJoin===`boolean`?e.autoJoin:true,joinTimeoutMs:resolvePositiveTimerTimeoutMs(e.joinTimeoutMs,3e4),waitForInCallMs:resolvePositiveTimerTimeoutMs(e.waitForInCallMs,t.waitForInCallMs),audioInputCommand:a??c.inputCommand,audioOutputCommand:o??c.outputCommand,audioInputCommandOverride:a,audioOutputCommandOverride:o,bargeInInputCommand:normalizeOptionalTrimmedStringList(e.bargeInInputCommand),bargeInRmsThreshold:asPositiveFiniteNumber(e.bargeInRmsThreshold)??650,bargeInPeakThreshold:asPositiveFiniteNumber(e.bargeInPeakThreshold)??2500,bargeInCooldownMs:resolvePositiveTimerTimeoutMs(e.bargeInCooldownMs,900)}}function resolveMeetingRealtimeConfig(e,t){const n={};for(const[t,r]of Object.entries(asRecord(e.providers))){const e=normalizeOptionalLowercaseString(t);if(e)n[e]=asRecord(r)}return{strategy:normalizeOptionalLowercaseString(e.strategy)===`bidi`?`bidi`:`agent`,provider:normalizeOptionalString(e.provider)??`openai`,transcriptionProvider:normalizeOptionalString(e.transcriptionProvider)??t.transcriptionProvider,voiceProvider:normalizeOptionalString(e.voiceProvider),model:normalizeOptionalString(e.model),instructions:normalizeOptionalString(e.instructions)??t.instructions,introMessage:typeof e.introMessage===`string`?e.introMessage.trim():`Say exactly: I'm here and listening.`,agentId:normalizeOptionalString(e.agentId),toolPolicy:resolveRealtimeVoiceAgentConsultToolPolicy(e.toolPolicy,`safe-read-only`),providers:n}}export{resolveMeetingAudioRuntimeForFormat as a,ensureMeetingAudioBackend as i,resolveMeetingChromeConfig as n,buildMeetingSoxAudioCommands as o,resolveMeetingRealtimeConfig as r,buildMeetingConfigAudioCommands as t};