UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 8.56 kB
import{c as normalizeOptionalLowercaseString,l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{o as asRecord,t as asNonArrayRecord}from"./record-coerce-BTbqdJ3-.mjs";import{r as readTrimmedStringAlias,t as isStringOption}from"./string-readers-CdTvPGel.mjs"; //!src/talk/agent-run-control-shared.ts const REALTIME_VOICE_AGENT_CONTROL_MODES=[`status`,`steer`,`cancel`,`followup`];const REALTIME_VOICE_AGENT_CONTROL_TOOL_NAME=`openclaw_agent_control`;const AGENT_INPUT_UNCONFIRMED_MESSAGE=`OpenClaw could not confirm that input. It was not sent again; check the conversation before retrying.`;const REALTIME_VOICE_AGENT_CONTROL_TOOL={type:`function`,name:REALTIME_VOICE_AGENT_CONTROL_TOOL_NAME,description:`Control an active OpenClaw tool-backed voice run. Use this when the caller asks in any language for status/progress, cancellation, a redirect/change to the active work, or a follow-up after the current work. Do not use this for ordinary greetings or chatter unless the caller is asking about the active work.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`The caller's exact spoken request or a concise semantic equivalent.`},mode:{type:`string`,enum:REALTIME_VOICE_AGENT_CONTROL_MODES,description:`status for progress questions, cancel for stop/abort, steer for changing the current work, followup for work to do after the current result.`}},required:[`text`,`mode`]}};function normalizeRealtimeVoiceAgentControlMode(e){const t=normalizeOptionalLowercaseString(e);return isStringOption(t,REALTIME_VOICE_AGENT_CONTROL_MODES)?t:void 0}const CANCEL_CONTROL_PATTERNS=[/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:please\s+)?(?:cancel|cancle|abort)(?:\s+(?:that|this|it|the\s+(?:check|run|task|work)))?(?:\s*[.!?])?$/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:please\s+)?(?:never mind|nevermind|forget it|kill it|end that)(?:\s*[.!?])?$/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:please\s+)?stop(?:\s+(?:that|this|it|the\s+(?:check|run|task|work)))?(?:\s*[.!?])?$/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:can|could|would)\s+you\s+(?:please\s+)?(?:cancel|cancle|stop|abort)(?:\s+(?:that|this|it|the\s+(?:check|run|task|work)))?(?:\s*[.!?])?$/,/^(?:(?:ok|okay|alright|all right|actually)[,\s]+)?(?:can|could|would)\s+(?:we|you)\s+(?:just\s+)?(?:cancel|cancle|stop|abort)(?:\s+(?:that|this|it|the\s+(?:check|run|task|work)))?(?:\s*[.!?])?$/,/\b(?:cancel|cancle|stop|abort)\s+(?:that|this|it|the\s+(?:check|run|task|work))\b/];const STATUS_CONTROL_PATTERNS=[/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:status|progress|update)(?:\s*[.!?])?$/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:give me|what'?s|any)\s+(?:an?\s+)?update(?:\s*[.!?])?$/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(where are we|what'?s happening|what (?:are you|is it) doing|what'?s it doing|how (?:is|are) (?:it|you|that|this) going|how'?s it going|are you still working|is it done|did it finish)(\b|[.!?])/];const FOLLOWUP_CONTROL_PATTERNS=[/^(after that|when you'?re done|when it'?s done|next|then|also|one more thing|follow up)(\b|[,.!?])/];const STEER_CONTROL_PATTERNS=[/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:please\s+)?update\s+\S/,/^(?:actually|instead|change|switch|focus|use|try|prefer|make|do|check|look at|go with|redirect|steer|tell it to)\b/,/^(?:can|could|would)\s+you\s+(?:actually\s+)?(?:change|switch|focus|use|try|prefer|make|do|check|look at|go with|redirect|steer)\b/,/\b(?:instead|not that|rather than|change that|switch to|focus on|use the|try the|go with|tell it to)\b/];const STOP_REDIRECT_CONTROL_PATTERNS=[/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:please\s+)?stop\s+(?:using|doing|checking|looking at|focusing on|trying)\b/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:can|could|would)\s+(?:you|we)\s+(?:please\s+)?stop\s+(?:using|doing|checking|looking at|focusing on|trying)\b/,/^(?:(?:ok|okay|alright|all right)[,\s]+)?(?:please\s+)?stop\s+(?:that|this|it|the\s+(?:check|run|task|work))\s+from\b/];function hasNegatedCancelIntent(e){return/\b(?:don'?t|do\s+not|not|never)\s+(?:please\s+)?(?:cancel|cancle|stop|abort|kill|end)\b/.test(e)||/\bstop\s+(?:it|that|this)\s+from\b/.test(e)}const CONTROL_INTENT_RULES=[[`steer`,STOP_REDIRECT_CONTROL_PATTERNS],[`cancel`,CANCEL_CONTROL_PATTERNS],[`status`,STATUS_CONTROL_PATTERNS],[`followup`,FOLLOWUP_CONTROL_PATTERNS],[`steer`,STEER_CONTROL_PATTERNS]];function resolveRealtimeVoiceAgentControlIntent(e){const t=normalizeRealtimeVoiceAgentControlMode(e.mode);if(t)return{mode:t,shouldAutoControl:true};const n=e.text.trim().toLowerCase();for(const[e,t]of CONTROL_INTENT_RULES)if((e!==`cancel`||!hasNegatedCancelIntent(n))&&t.some(e=>e.test(n)))return{mode:e,shouldAutoControl:true};return{mode:`status`,shouldAutoControl:false}}function classifyRealtimeVoiceAgentControlText(e){return resolveRealtimeVoiceAgentControlIntent({text:e}).mode}function shouldAutoControlRealtimeVoiceAgentText(e){return resolveRealtimeVoiceAgentControlIntent({text:e}).shouldAutoControl}function parseRealtimeVoiceAgentControlToolArgs(e){let t=e;if(typeof e===`string`){const n=e.trim();try{t=n?JSON.parse(n):{}}catch{t={text:n}}}const n=asNonArrayRecord(t);const r=readTrimmedStringAlias(n,[`text`,`message`,`request`,`query`]);if(!r)throw new Error(`text required`);return{text:r,mode:normalizeRealtimeVoiceAgentControlMode(n.mode)??resolveRealtimeVoiceAgentControlIntent({text:r}).mode}}const REALTIME_VOICE_AGENT_CONTROL_FAILURE_MESSAGE=`OpenClaw could not process that voice control. Please try again.`;function buildRealtimeVoiceAgentControlSpeechMessage(e){return[`Internal OpenClaw voice control result.`,`Do not delegate this message or call any tools.`,`Speak this exact OpenClaw status to the voice call, without adding, removing, or rephrasing words.`,`Status: ${JSON.stringify(e)}`].join(` `)}function buildRealtimeVoiceAgentCancelProviderResult(e=`Cancelled the active OpenClaw run.`){return{status:`cancelled`,message:e}}function buildRealtimeVoiceAgentFollowupSteeringText(e){return[`Spoken follow-up for the current voice call.`,`If you are mid-task, incorporate this after the current step or result unless it directly changes the current task.`,``,e].join(` `)}function formatRealtimeVoiceAgentQueueRejection(e,t){if(t===`guarded_injection_unsupported`)return`This agent runtime cannot safely accept scoped voice steering. Check status, cancel the run, or start a new explicit request. Update the runtime when guarded injection is supported.`;if(t===`tool_authority_mismatch`)return`This agent runtime cannot safely accept scoped voice steering. Check status, cancel the run, or start a new explicit request.`;if(t===`compacting`)return`OpenClaw is compacting the active run and cannot accept voice steering yet.`;if(t===`injection_unavailable`||t===`not_streaming`)return`OpenClaw has an active run, but it is not currently accepting steering.`;return e===`followup`?`OpenClaw could not queue that follow-up.`:`OpenClaw could not steer the active run.`}function formatRealtimeVoiceAgentStatus(e){const t=e.recentEvents??[];if(!e.active)return t.findLast(e=>e.type===`turn.ended`)?`OpenClaw finished the last voice request.`:`I'm not working on an active request right now.`;const n=t.findLast(e=>e.type.startsWith(`tool.`)&&normalizeOptionalString(asRecord(e.payload).name)!==`openclaw_agent_control`);if(n){const e=asRecord(n.payload);const t=normalizeOptionalString(e.name);const r=normalizeOptionalString(e.phase);if(n.type===`tool.call`)return t?`OpenClaw is starting ${t}.`:`OpenClaw is starting a tool.`;if(n.type===`tool.result`)return t?`OpenClaw finished ${t} and is continuing.`:`OpenClaw finished a tool and is continuing.`;if(n.type===`tool.progress`)return t?`OpenClaw is working in ${t}${r?` (${r})`:``}.`:`OpenClaw is still working.`}if(e.activity?.activeToolName)return`OpenClaw is running ${e.activity.activeToolName}.`;if(e.activity?.activeWorkKind===`model_call`)return`OpenClaw is waiting on the model.`;return`OpenClaw is working on the current voice request.`}export{buildRealtimeVoiceAgentCancelProviderResult as a,classifyRealtimeVoiceAgentControlText as c,parseRealtimeVoiceAgentControlToolArgs as d,resolveRealtimeVoiceAgentControlIntent as f,REALTIME_VOICE_AGENT_CONTROL_TOOL_NAME as i,formatRealtimeVoiceAgentQueueRejection as l,REALTIME_VOICE_AGENT_CONTROL_FAILURE_MESSAGE as n,buildRealtimeVoiceAgentControlSpeechMessage as o,shouldAutoControlRealtimeVoiceAgentText as p,REALTIME_VOICE_AGENT_CONTROL_TOOL as r,buildRealtimeVoiceAgentFollowupSteeringText as s,AGENT_INPUT_UNCONFIRMED_MESSAGE as t,formatRealtimeVoiceAgentStatus as u};