UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.51 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Qt as t,Xt as n,wa as r,xa as i}from"./control-ui-connection-Bfj9beF_.js";import{gx as a,mx as o}from"./control-ui-boot-shared-DFTSUQQ0.js";import{r as s,t as c}from"./composer-dictation-session-BhPkpaHO.js";import{o as l,t as u}from"./shared-B2BynUo8.js";var d;function f(){return(f=e((()=>{i(),t(),o(),s(),u(),d=class{constructor(e,t,n,r,i){this.client=e,this.sessionKey=t,this.callbacks=n,this.options=r,this.inputDeviceId=i,this.capture=null}async start(){return this.callbacks.onVideoCapability?.(!1),await this.listen(),this.closed?`cancelled`:`ready`}stop({disposition:e=`abort`}={}){if(this.closed)return;this.closed=e;let t=this.capture;this.capture=null,t?.cancel().catch(()=>void 0),this.options.playback.stop(),this.chatAbort?.abort(),this.runId&&e===`abort`&&this.abortRun(this.runId),this.runId=void 0,this.callbacks.onInputLevel?.(0)}async listen(){if(this.closed)return;let e=new c(this.client,{onReady:()=>this.callbacks.onStatus?.(`listening`),onError:e=>this.fail(Error(e)),onLevel:e=>this.callbacks.onInputLevel?.(e),onTranscriptChange:()=>void 0,onSilence:()=>void this.completeTurn(e)},{sessionKey:this.sessionKey,inputDeviceId:this.inputDeviceId,silenceTimeoutMs:this.options.silenceTimeoutMs});this.capture=e,await e.start()}async completeTurn(e){if(!(this.closed||this.capture!==e)){this.callbacks.onStatus?.(`thinking`);try{let t=await e.finish();if(this.closed||this.capture!==e)return;if(this.capture=null,t){let e=await this.send(t);if(this.closed)return;e&&await this.options.playback.speak(this.client,e,this.options.speechMethod,()=>!this.closed,this.options.maxTextLength)}await this.listen()}catch(e){this.fail(e)}}}async send(e){let t=crypto.randomUUID();this.runId=t;let n=new AbortController;this.chatAbort=n;let i={client:this.client,runId:t,timeoutMs:12e4,timeoutMessage:r(`chat.voice.replyTimedOut`),signal:n.signal},o=l(i);o.catch(()=>void 0);try{let n=await this.options.sendMessage(e,t);if(this.closed)return this.closed===`abort`&&await this.abortRun(n.runId),``;if(a(n))throw Error(r(`chat.voice.replyFailed`));i.runId=n.runId,this.runId=n.runId;let s=await o;return this.runId=void 0,s}finally{n.abort(),this.chatAbort===n&&(this.chatAbort=void 0)}}async abortRun(e){await this.client.request(`chat.abort`,{sessionKey:this.sessionKey,runId:e}).catch(()=>void 0)}fail(e){this.closed||(this.stop({disposition:`detach`}),this.callbacks.onStatus?.(`error`,n(e)))}}})))()}f();export{d as SplitTalkTransport};