UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.34 kB
import{i as e}from"./transcript-record-coerce-CPLgmAk9.mjs";import{a as t,i as n,o as r,r as i}from"./transcript-kysely-sync-CAP5xe3V.mjs";import{o as a}from"./transcript-sqlite-transaction-CBQXI8WC.mjs";import{t as o}from"./transcript-sqlite-number-5mfxKD9j.mjs";import{t as s}from"./transcript-session-accessor.sqlite-scope-helpers-LCM13IZK.mjs";import{a as c,m as l}from"./transcript-transcript-payload-F5t-l1WZ.mjs";import{n as u,t as d}from"./transcript-session-cold-storage-state-BxQ0_xF8.mjs";import{n as f}from"./transcript-session-transcript-read-fence-Fb_G9Rx1.mjs";import{o as p}from"./transcript-transcript-only-openclaw-assistant-DcGn8i-E.mjs";import{t as m}from"./transcript-transcript-assistant-delivery-read-CPocPrdi.mjs";function loadTranscriptEventRowsAfterSeqInDatabase(e,t,n){return u(e,t,`incremental`,()=>{let r=s(e.db).selectFrom(`transcript_events`).select([l(e.db).as(`event_json`),`seq`]).where(`session_id`,`=`,t).where(`seq`,`>`,n);return i(e.db,r.orderBy(`seq`,`asc`)).rows.map(e=>({event:JSON.parse(e.event_json),seq:o(e.seq)}))})}function hasSessionTranscriptMessageInDatabase(e,i){let a=t(e.db);return u(e,i,`presence`,()=>{if(n(e.db,a.selectFrom(`transcript_event_identities`).select(`seq`).where(`session_id`,`=`,i).where(`event_type`,`=`,`message`).limit(1)))return!0;let t=a.selectFrom(`transcript_event_identities`).select(`seq`).where(`session_id`,`=`,i).where(`event_type`,`is not`,null);return findTranscriptEventInRows(r(e.db,a.selectFrom(`transcript_events`).select(c(e.db).as(`event_json`)).where(`session_id`,`=`,i).where(`seq`,`not in`,t).orderBy(`seq`,`desc`)),e=>typeof e==`object`&&!!e&&`type`in e&&e.type===`message`)!==void 0})}function findTranscriptEventInRows(e,t,n=`skip`){for(let r of e)try{let e=JSON.parse(r.event_json);if(t(e))return{event:e}}catch(e){if(n===`throw`)throw e}}function readTranscriptHeaderFromDatabase(e,r){return u(e,r,`header`,()=>{let i=t(e.db),a=n(e.db,i.selectFrom(`transcript_events`).select(l(e.db).as(`event_json`)).where(`session_id`,`=`,r).orderBy(`seq`,`asc`).limit(1));return a?JSON.parse(a.event_json):void 0})}function readLatestAssistantTextFromDatabase(e,n){return a(e.db,()=>{d(e.db,n.sessionId);let i=t(e.db),a=f({database:e,...n})?.beforeRawSeq,o=r(e.db,i.selectFrom(`transcript_events as te`).innerJoin(`transcript_event_identities as ti`,e=>e.onRef(`ti.session_id`,`=`,`te.session_id`).onRef(`ti.seq`,`=`,`te.seq`)).select(l(e.db,`te`).as(`event_json`)).where(`te.session_id`,`=`,n.sessionId).where(`ti.event_type`,`=`,`message`).$if(a!==void 0,e=>e.where(`ti.seq`,`<`,a)).orderBy(`ti.seq`,`desc`));for(let e of o){let t=parseLatestAssistantMessageEvent(e.event_json);if(!t)continue;let n=m(t.message,t.id);if(n)return n}},{databaseLabel:e.path,operationLabel:`latest assistant fenced read`})}function parseLatestAssistantMessageEvent(e){try{return readLatestAssistantMessageEvent(JSON.parse(e))}catch{return}}function readLatestAssistantMessageEvent(t){let n=e(t),r=e(n?.message);if(r&&r.role===`assistant`&&!p(r.provider,r.model))return{...typeof n?.id==`string`&&n.id.trim()?{id:n.id}:{},message:r}}export{readTranscriptHeaderFromDatabase as a,readLatestAssistantTextFromDatabase as i,hasSessionTranscriptMessageInDatabase as n,loadTranscriptEventRowsAfterSeqInDatabase as o,readLatestAssistantMessageEvent as r,findTranscriptEventInRows as t};