UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.5 kB
import"./transcript-detached-async-context-BKXaSw-L.mjs";import"./transcript-openclaw-agent-db-BuScZLmj.mjs";import{a as e,m as t,o as n,p as r}from"./transcript-kysely-sync-CAP5xe3V.mjs";import{_ as i,c as a,d as o,h as s,i as c,l,n as u}from"./transcript-schemas-C_W5KYqZ.mjs";import{g as d,u as f}from"./transcript-json-values-C_3KtpDU.mjs";import{n as p}from"./transcript-openclaw-agent-db-readonly-BfbPmTwU.mjs";typeof process>`u`||process.getBuiltinModule(`node:async_hooks`).AsyncLocalStorage;const m=/^[0-9a-f]{64}$/,h=l({runId:s(),toolName:s(),startedAt:o(),status:u([`started`,`succeeded`,`failed`,`cancelled`,`blocked`])}),g=l({version:a(1),voiceSessionId:s(),agentId:s(),sessionKey:s(),provider:s().refine(e=>e.trim().length>0).transform(e=>e.trim()).optional(),origin:u([`client`,`relay`]),status:u([`open`,`closed`]),createdAt:o(),updatedAt:o(),consultRunIds:i().optional().transform(e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[]),effects:i().optional().transform(e=>Array.isArray(e)?e.flatMap(e=>{let t=h.safeParse(e);return t.success?[t.data]:[]}):[]),transcriptFailureKeys:i().optional().transform(e=>e??[]).pipe(c(s().regex(m)).max(41).refine(e=>new Set(e).size===e.length))});function parseStoredVoiceSessionRecord(e){if(typeof e==`string`)try{let t=g.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function voiceSessionRowsQuery(t){return e(t.db).selectFrom(`cache_entries`).select(`value_json`).where(`scope`,`=`,r.lit(`talk-client-voice-sessions`))}function voiceSessionField(e,n){let i=t();return i.case().when(d(e,i.ref(`value_json`))).then(f(e,i.ref(`value_json`),r.lit(`$.${n}`))).end()}function lookupOpenVoiceSessions(e,t){let i=voiceSessionRowsQuery(e).where(voiceSessionField(e.db,`status`),`=`,r.lit(`open`));t.kind===`legacy`?i=i.where(voiceSessionField(e.db,`agentId`),`=`,t.agentId).where(voiceSessionField(e.db,`sessionKey`),`=`,t.sessionKey).where(voiceSessionField(e.db,`origin`),`=`,`client`):(i=i.where(`updated_at`,`<=`,t.updatedBefore),t.excludeVoiceSessionId!==void 0&&(i=i.where(voiceSessionField(e.db,`voiceSessionId`),`!=`,t.excludeVoiceSessionId)));let a=[];for(let r of n(e.db,i)){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=p(e=>lookupOpenVoiceSessions(e,t),e);return{kind:`voice-sessions`,matches:n.found?n.value:[]}}export{readOpenVoiceSessions};