UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines (3 loc) • 7.79 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Gl as t,Ql as n,Qt as r,Xt as i,lo as a,tu as o}from"./control-ui-connection-Bfj9beF_.js";import{$t as s,en as c,tn as l}from"./deferred-ui-support-D-VedBtc.js";var u;function d(){return(d=e((()=>{u=`openclaw_agent_consult`})))()}function f(e){let n=t(e);return c(n,y)?n:void 0}function p(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)}function m(e){let t=f(e.mode);if(t)return{mode:t,shouldAutoControl:!0};let n=e.text.trim().toLowerCase();for(let[e,t]of E)if((e!==`cancel`||!p(n))&&t.some(e=>e.test(n)))return{mode:e,shouldAutoControl:!0};return{mode:`status`,shouldAutoControl:!1}}function h(e){return m({text:e}).shouldAutoControl}function g(e){let t=e;if(typeof e==`string`){let n=e.trim();try{t=n?JSON.parse(n):{}}catch{t={text:n}}}let r=n(t),i=l(r,[`text`,`message`,`request`,`query`]);if(!i)throw Error(`text required`);return{text:i,mode:f(r.mode)??m({text:i}).mode}}function _(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 v(e=`Cancelled the active OpenClaw run.`){return{status:`cancelled`,message:e}}var y,b,x,S,C,w,T,E;function D(){return(D=e((()=>{s(),y=[`status`,`steer`,`cancel`,`followup`],b=`openclaw_agent_control`,x=[/^(?:(?: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/],S=[/^(?:(?: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|[.!?])/],C=[/^(after that|when you'?re done|when it'?s done|next|then|also|one more thing|follow up)(\b|[,.!?])/],w=[/^(?:(?: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/],T=[/^(?:(?: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/],E=[[`steer`,T],[`cancel`,x],[`status`,S],[`followup`,C],[`steer`,w]]})))()}function O(e){let t=o(e);return t?typeof t.text==`string`?t.text:(Array.isArray(t.content)?t.content:[]).map(e=>{let t=o(e);return t?.type===`text`&&typeof t.text==`string`?t.text:``}).filter(Boolean).join(` `).trim():``}function k(e){if(!e)return;let t=e.error?.trim();if(e.status===`error`)return Error(t||`OpenClaw tool call failed`);if(e.status!==`timeout`||e.pendingError)return;let n=e.stopReason?.trim(),r=e.timeoutPhase?.trim(),i=e.livenessState?.trim();return e.endedAt!==void 0||t!==void 0||e.aborted===!0||i!==void 0&&i.length>0||e.yielded===!0||n!==void 0&&n.length>0||r===`preflight`||r===`provider`||r===`post_turn`||e.providerStarted===!0?Error(t||`OpenClaw tool call timed out`):void 0}function A(e){return new Promise((t,n)=>{if(e.signal?.aborted){n(new DOMException(`OpenClaw tool call aborted`,`AbortError`));return}let r=window.setTimeout(()=>{u(Error(e.timeoutMessage??`OpenClaw tool call timed out`))},e.timeoutMs),i=!1,o=!1,s,c=e.signal&&a(e.signal,`abort`,()=>{u(new DOMException(`OpenClaw tool call aborted`,`AbortError`))},{once:!0}),l=()=>void 0,u=e=>{i||(i=!0,window.clearTimeout(r),s!==void 0&&window.clearTimeout(s),c?.(),l(),typeof e==`string`?t(e):n(e))},d=()=>{o||(o=!0,e.client.request(`agent.wait`,{runId:e.runId,timeoutMs:e.timeoutMs}).then(e=>{if(i)return;let t=k(e);t?u(t):e?.status!==`timeout`&&(s=window.setTimeout(()=>{u(`OpenClaw finished with no text.`)},L))}).catch(e=>{u(e instanceof Error?e:Error(String(e)))}))};l=e.client.addEventListener(t=>{if(t.event!==`chat`)return;let n=t.payload;if(n&&n.runId===e.runId){if(n.state===`final`){let e=O(n.message);if(e){u(e);return}d()}else n.state===`aborted`?u(new DOMException(n.errorMessage??`OpenClaw tool call aborted`,`AbortError`)):n.state===`error`&&u(Error(n.errorMessage??`OpenClaw tool call failed`))}})})}function j(e,t,n,r){let i={sessionKey:e.sessionKey,text:n,...r?{mode:r}:{}};return t&&t.trim()?e.client.request(`talk.session.steer`,{sessionId:t,...i}):e.client.request(`talk.client.steer`,i)}function M(e){let t=o(e);return t?.ok===!0&&(t.mode===`cancel`||t.suppress===!0&&t.mode!==`steer`)}async function N(e){let t=e.text.trim();if(!t)return;let n=j(e.ctx,void 0,t);try{let t=await n;e.onControlResult?.(t);let r=o(t);if(e.speakControlResult&&r&&r.mode!==`cancel`){let t=typeof r.message==`string`?r.message.trim():``;(r.speak===!0&&r.suppress!==!0||r.ok===!0&&r.mode===`steer`&&r.suppress===!0)&&t&&e.speakControlResult(_(t))}}catch{}}async function P(e){if(e.signal?.aborted)return;let t;try{let n=g(e.args);if(t=await j(e.ctx,e.sessionId,n.text,n.mode),e.signal?.aborted)return}catch(n){if(t={error:i(n)},e.signal?.aborted||I(n))return}await e.submit(e.callId,t)}async function F(e){let{ctx:t,callId:n,submit:r}=e;t.callbacks.onStatus?.(`thinking`);let o,s=!1,c=!1,l=!1,d=async e=>{c||(c=!0,await r(n,e),l=!0)},f=async()=>{e.submitAbortResult!==!1&&await d(v())},p=()=>{s=!0,o&&!e.relaySessionId&&t.client.request(`chat.abort`,{sessionKey:o.agentSessionKey,agentId:o.agentId,runId:o.runId}).catch(()=>void 0)};if(e.signal?.aborted){await f();return}let m=e.signal&&a(e.signal,`abort`,p,{once:!0});try{let r=typeof e.args==`string`?JSON.parse(e.args||`{}`):e.args??{};if(await t.flushTranscriptWrites?.(),e.signal?.aborted){await f();return}if(o=await t.client.request(`talk.client.toolCall`,{sessionKey:t.sessionKey,...t.voiceSessionId?{voiceSessionId:t.voiceSessionId}:{},callId:n,name:u,args:r,...e.relaySessionId?{relaySessionId:e.relaySessionId}:{}}),e.signal?.aborted){p(),await f();return}await d({result:await A({client:t.client,runId:o.runId,timeoutMs:12e4,signal:e.signal})})}catch(t){if(c)throw t;if(s||e.signal?.aborted||I(t)){await f();return}await d({error:i(t)})}finally{m?.(),l&&!s&&!e.signal?.aborted&&t.callbacks.onStatus?.(`listening`)}}function I(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`AbortError`}var L;function R(){return(R=e((()=>{d(),D(),r(),L=500})))()}export{F as a,D as c,d,P as i,h as l,M as n,A as o,N as r,b as s,R as t,u};