openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.71 kB
JavaScript
import"./transcript-detached-async-context-BKXaSw-L.mjs";import{n as e}from"./transcript-sql-connection-CRz-dHXM.mjs";import{a as t,h as n,m as r,o as i}from"./transcript-kysely-sync-DQ_Yn8jW.mjs";import{_ as a,c as o,d as s,h as c,i as l,l as u,n as d}from"./transcript-schemas-C_W5KYqZ.mjs";import{g as f,u as p}from"./transcript-json-values-CmANsVU4.mjs";import{r as m}from"./transcript-openclaw-agent-db-readonly-DE1r7rt-.mjs";import"./transcript-openclaw-agent-db-BBGql3JY.mjs";typeof process>`u`||process.getBuiltinModule(`node:async_hooks`).AsyncLocalStorage;const h=/^[0-9a-f]{64}$/,g=u({runId:c(),toolName:c(),startedAt:s(),status:d([`started`,`succeeded`,`failed`,`cancelled`,`blocked`])}),_=u({version:o(1),voiceSessionId:c(),agentId:c(),sessionKey:c(),provider:c().refine(e=>e.trim().length>0).transform(e=>e.trim()).optional(),origin:d([`client`,`relay`]),status:d([`open`,`closed`]),createdAt:s(),updatedAt:s(),consultRunIds:a().optional().transform(e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[]),effects:a().optional().transform(e=>Array.isArray(e)?e.flatMap(e=>{let t=g.safeParse(e);return t.success?[t.data]:[]}):[]),transcriptFailureKeys:a().optional().transform(e=>e??[]).pipe(l(c().regex(h)).max(41).refine(e=>new Set(e).size===e.length))});function parseStoredVoiceSessionRecord(e){if(typeof e==`string`)try{let t=_.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function voiceSessionRowsQuery(e){return t(e.db).selectFrom(`cache_entries`).select(`value_json`).where(`scope`,`=`,r.lit(`talk-client-voice-sessions`))}function voiceSessionField(t,i){let a=n(),o=a.ref(`value_json`);if(e(t)){let e=r`(${o}::json -> ${r.lit(i)})`;return r`CASE WHEN ${o} IS JSON THEN
CASE WHEN json_typeof(${e}) = 'string' THEN ${e} #>> '{}' END
END`}return a.case().when(f(t,o)).then(p(t,o,r.lit(`$.${i}`))).end()}function lookupOpenVoiceSessions(e,t){let n=voiceSessionRowsQuery(e).where(voiceSessionField(e.db,`status`),`=`,r.lit(`open`));t.kind===`legacy`?n=n.where(voiceSessionField(e.db,`agentId`),`=`,t.agentId).where(voiceSessionField(e.db,`sessionKey`),`=`,t.sessionKey).where(voiceSessionField(e.db,`origin`),`=`,`client`):(n=n.where(`updated_at`,`<=`,t.updatedBefore),t.excludeVoiceSessionId!==void 0&&(n=n.where(voiceSessionField(e.db,`voiceSessionId`),`!=`,t.excludeVoiceSessionId)));let a=[];for(let r of i(e.db,n)){let e=parseStoredVoiceSessionRecord(r.value_json);if(e&&(a.push({voiceSessionId:e.voiceSessionId,sessionKey:e.sessionKey}),t.kind===`legacy`&&a.length===2))break}return a}function readOpenVoiceSessions(e,t){let n=m(e=>lookupOpenVoiceSessions(e,t),e);return{kind:`voice-sessions`,matches:n.found?n.value:[]}}export{readOpenVoiceSessions};