openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 13.4 kB
JavaScript
import{yt as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{H as t}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{_ as n}from"./openclaw-state-read-openclaw-state-db-cache-DyomEqgV.mjs";import{C as r,u as i}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import{t as a}from"./openclaw-state-read-sqlite-schema-facts-Dtolu7-X.mjs";import{a as o,i as s,m as c,o as l}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{c as u,d,i as f}from"./openclaw-state-read-json-values-sW-ax-AH.mjs";import{n as p,r as m}from"./openclaw-state-read.worker.js";import{t as h}from"./openclaw-state-read-closed-object-D3QW4nRZ.mjs";import{t as g}from"./openclaw-state-read-primitives-B8yGv9fM.mjs";import{t as _}from"./openclaw-state-read-string-literal-union-A6jxKQ93.mjs";import"node:crypto";import"node:util";import{Type as v}from"typebox";const y=1048576,b=4194304,x=v.String({minLength:1,maxLength:y}),S=v.String({minLength:1,maxLength:256}),C=v.Union([v.String(),v.Null()]),w={limit:v.Optional(v.Integer({minimum:1,maximum:100})),cursor:v.Optional(v.String({minLength:1,maxLength:y})),query:v.Optional(v.String({maxLength:256}))},T=_([`model`,`heuristic`]),E=_([`live-audio`,`live-caption`,`posthoc-transcript`,`recording-stt`]),D=_([`optional`,`required`]),O=h({providerId:g,kind:v.Optional(E),accountId:v.Optional(v.String()),guildId:v.Optional(v.String()),channelId:v.Optional(v.String()),meetingUrl:v.Optional(v.String()),threadTs:v.Optional(v.String()),fileId:v.Optional(v.String())}),k=h({selector:x,sessionId:g,title:v.Optional(v.String()),providerId:g,providerName:v.Optional(v.String()),source:O,startedAt:g,stoppedAt:v.Optional(v.String()),active:v.Boolean(),utteranceCount:v.Integer({minimum:0}),participants:v.Array(v.String()),hasSummary:v.Boolean(),summarySource:v.Optional(T),overview:v.Optional(v.String({maxLength:280})),agentId:C,updatedAt:v.String(),lastUtteranceAt:C,activeSubscription:v.Boolean()}),A=h({sequence:v.Integer({minimum:0}),id:v.Optional(v.String()),startedAt:v.Optional(v.String()),endedAt:v.Optional(v.String()),speakerId:v.Optional(v.String()),speakerLabel:v.Optional(v.String()),text:v.String(),final:v.Optional(v.Boolean())});h({...w,limit:v.Optional(v.Integer({minimum:1,maximum:200,default:50})),providerId:v.Optional(g),accountId:v.Optional(S),agentId:v.Optional(S),startedAfter:v.Optional(v.String({format:`date-time`,maxLength:64})),startedBefore:v.Optional(v.String({format:`date-time`,maxLength:64}))}),h({sessions:v.Array(k,{maxItems:200}),nextCursor:C}),h({selector:x}),h({selector:x,includeUtterances:v.Optional(v.Boolean()),...w}),h({session:k,summary:v.Optional(h({generatedAt:v.String(),overview:v.String(),decisions:v.Array(v.String()),actionItems:v.Array(v.String()),risks:v.Array(v.String()),participants:v.Array(v.String()),source:v.Optional(T),model:v.Optional(v.String()),markdown:v.String(),utteranceCount:v.Integer({minimum:0})})),utterances:v.Optional(v.Array(A,{maxItems:2e3})),nextCursor:C}),h({selector:x,format:_([`markdown`,`jsonl`])}),h({selector:x,filename:v.String(),mimeType:v.String(),encoding:v.Literal(`base64`),data:v.String(),sizeBytes:v.Integer({minimum:0,maximum:b})}),h({}),h({enabled:v.Boolean(),providers:v.Array(h({providerId:v.String(),pluginId:v.Optional(v.String()),name:v.String(),availability:_([`enabled`,`disabled`,`unavailable`,`unknown`]),sourceKinds:v.Optional(v.Array(E)),canStart:v.Optional(v.Boolean()),canStop:v.Optional(v.Boolean()),canImport:v.Optional(v.Boolean()),autoStart:v.Optional(h({accountId:v.Optional(D),guildId:v.Optional(D),channelId:v.Optional(D),meetingUrl:v.Optional(D)}))}),{maxItems:100}),configuredSources:v.Array(h({source:O,title:v.Optional(v.String()),sessionId:v.Optional(v.String()),state:_([`disabled`,`armed`,`not-active`,`unknown`]),activeSelectors:v.Array(x,{maxItems:100}),startDiagnostic:v.Optional(_([`starting`,`retrying`,`id-conflict`,`admitted-start-failed`,`start-failed`,`ended`]))}),{maxItems:100}),active:v.Array(k,{maxItems:100}),latestTranscript:v.Union([k,v.Null()]),omitted:h({providers:v.Integer({minimum:0}),configuredSources:v.Integer({minimum:0}),active:v.Integer({minimum:0})})});function meetingTranscriptDb(e){return o(e)}function meetingTranscriptSessionQuery(e,t){return meetingTranscriptDb(e).selectFrom(`meeting_transcript_sessions`).where(`session_id`,`=`,t.sessionId).where(`started_at`,`=`,t.startedAt)}function meetingTranscriptUtteranceQuery(e,t){return meetingTranscriptDb(e).selectFrom(`meeting_transcript_utterances`).where(`session_id`,`=`,t.sessionId).where(`session_started_at`,`=`,t.startedAt)}function parseOptionalJsonRecord(t){if(t)return e(JSON.parse(t))}function sessionFromRow(e){let t=parseOptionalJsonRecord(e.source_json),n=parseOptionalJsonRecord(e.metadata_json);if(!t||typeof t.providerId!=`string`)throw Error(`invalid meeting transcript source for ${e.session_id}`);return{sessionId:e.session_id,source:t,startedAt:e.started_at,...e.title===null?{}:{title:e.title},...e.stopped_at===null?{}:{stoppedAt:e.stopped_at},...n?{metadata:n}:{}}}function utteranceFromRow(e){let t=e.speaker_label===null?void 0:{label:e.speaker_label,...e.speaker_id===null?{}:{id:e.speaker_id}},n=parseOptionalJsonRecord(e.metadata_json);return{sessionId:e.session_id,text:e.text,...e.utterance_id===null?{}:{id:e.utterance_id},...e.started_at===null?{}:{startedAt:e.started_at},...e.ended_at===null?{}:{endedAt:e.ended_at},...t?{speaker:t}:{},...e.final===null?{}:{final:e.final===1},...n?{metadata:n}:{}}}var TranscriptLibraryError=class extends Error{constructor(e,t,n){super(t),this.type=e,this.maxBytes=n}};function assertTranscriptByteCount(e,t=y,n=!1){if(e>t)throw new TranscriptLibraryError(n?`transcript_export_too_large`:`transcript_result_too_large`,n?`Transcript exceeds the download limit; use a local transcript export.`:`Transcript response exceeds the read limit; request a smaller page or use a local transcript export.`,t)}function byteLimit(e){return e===`legacy`?void 0:e===`export`?b:y}function assertReadBytes(e,t){let n=byteLimit(t);n!==void 0&&assertTranscriptByteCount(e,n,t===`export`)}function textBytes(...e){let t=c(),n=e.reduce((e,n)=>t(e,`+`,t.fn.coalesce(t.fn(`octet_length`,[n]),t.val(0))),t.val(0));return t.parens(n)}function boundedText(e,t,n){return n===void 0?c().parens(e):c().case().when(t,`<=`,n).then(e).else(``).end()}function readQuery(e,t,n=`page`){let r=c(t),i=r.selectFrom(`meeting_transcript_summaries as notes`).whereRef(`notes.session_id`,`=`,`meeting_transcript_sessions.session_id`).whereRef(`notes.session_started_at`,`=`,`meeting_transcript_sessions.started_at`),a=i.select(`notes.overview`).$asScalar(),o=i.select(t=>f(e,t.ref(`notes.summary_json`),`source`).as(`source`)).$asScalar(),s=r.selectFrom(`meeting_transcript_utterances as u`).whereRef(`u.session_id`,`=`,`meeting_transcript_sessions.session_id`).whereRef(`u.session_started_at`,`=`,`meeting_transcript_sessions.started_at`),l=s.select(`u.speaker_label`).select(e=>e.fn.min(`u.sequence`).as(`first_sequence`)).where(`u.speaker_label`,`is not`,null).where(`u.speaker_label`,`!=`,``).groupBy(`u.speaker_label`).orderBy(e=>e.fn.min(`u.sequence`),`asc`),d=r.selectFrom(l.as(`speakers`)).select(t=>u(e,t.ref(`speakers.speaker_label`),t.ref(`speakers.first_sequence`)).as(`participants`)).$asScalar(),p=s.select(e=>e.fn.coalesce(`u.ended_at`,`u.started_at`).as(`at`)).orderBy(`u.sequence`,`desc`).limit(1).$asScalar(),m=textBytes(r.ref(`session_id`),r.ref(`started_at`),r.ref(`selector`)),h=textBytes(r.ref(`session_id`),r.ref(`started_at`),r.ref(`selector`),r.ref(`source_json`),r.ref(`metadata_json`),r.ref(`title`),r.ref(`stopped_at`),p,a,o,d),g=byteLimit(n),columns=e=>[boundedText(r.ref(`session_id`),m,g).as(`session_id`),boundedText(r.ref(`started_at`),m,g).as(`started_at`),boundedText(r.ref(`selector`),m,g).as(`selector`),boundedText(r.ref(`source_json`),e,g).as(`source_json`),boundedText(r.ref(`metadata_json`),e,g).as(`metadata_json`),boundedText(r.ref(`title`),e,g).as(`title`),boundedText(r.ref(`stopped_at`),e,g).as(`stopped_at`),boundedText(p,e,g).as(`last_utterance_at`),boundedText(a,e,g).as(`overview`),boundedText(o,e,g).as(`summary_source`),boundedText(d,e,g).as(`participants_json`),r.parens(e).as(`payload_bytes`),m.as(`identity_bytes`),s.select(e=>e.fn.countAll().as(`count`)).$asScalar().as(`utterance_count`),`updated_at_ms`,r.exists(i.select(`notes.session_id`)).as(`has_summary`)];return g===void 0?t.select(columns(h)):meetingTranscriptDb(e).with(e=>e(`read_sizes`).materialized(),()=>t.select([`session_id as read_session_id`,`started_at as read_started_at`,h.as(`payload_bytes`)])).selectFrom(`read_sizes`).innerJoin(`meeting_transcript_sessions`,e=>e.onRef(`meeting_transcript_sessions.session_id`,`=`,`read_sizes.read_session_id`).onRef(`meeting_transcript_sessions.started_at`,`=`,`read_sizes.read_started_at`)).select(e=>columns(e.ref(`read_sizes.payload_bytes`)))}function transcriptReadEntryFromRow(e,t=`page`){assertReadBytes(e.payload_bytes,t);let n=sessionFromRow(e),r=e.summary_source===`model`||e.summary_source===`heuristic`?e.summary_source:void 0;return{session:n,selector:e.selector,hasSummary:!!e.has_summary,utteranceCount:e.utterance_count,participants:JSON.parse(e.participants_json??`[]`),overview:typeof e.overview==`string`?e.overview:void 0,summarySource:r,updatedAt:new Date(e.updated_at_ms).toISOString(),lastUtteranceAt:e.last_utterance_at??null}}function readTranscriptEntry(e,t,n=`page`){let r=s(e,readQuery(e,meetingTranscriptDb(e).selectFrom(`meeting_transcript_sessions`).where(`selector`,`=`,t),n));if(r)return assertReadBytes(r.identity_bytes,n),r.selector===t?transcriptReadEntryFromRow(r,n):void 0}function utteranceQuery(e,t,n){return meetingTranscriptUtteranceQuery(e,t).select(e=>{let t=byteLimit(n),r=n===`legacy`?e.val(null):e.ref(`utterance_id`),i=textBytes(r,e.ref(`started_at`),e.ref(`ended_at`),e.ref(`speaker_id`),e.ref(`speaker_label`),e.ref(`text`));return[boundedText(r,i,t).as(`utterance_id`),boundedText(e.ref(`started_at`),i,t).as(`started_at`),boundedText(e.ref(`ended_at`),i,t).as(`ended_at`),boundedText(e.ref(`speaker_id`),i,t).as(`speaker_id`),boundedText(e.ref(`speaker_label`),i,t).as(`speaker_label`),boundedText(e.ref(`text`),i,t).as(`text`),i.as(`payload_bytes`),`sequence`,`final`]})}function transcriptReadUtteranceFromRow(e){return{sequence:e.sequence,id:e.utterance_id??void 0,startedAt:e.started_at??void 0,endedAt:e.ended_at??void 0,speakerId:e.speaker_id??void 0,speakerLabel:e.speaker_label??void 0,text:e.text,final:e.final===null?void 0:e.final===1}}function readStoredTranscriptNotes(e,t,n=`page`){let r=s(e,meetingTranscriptDb(e).selectFrom(`meeting_transcript_summaries`).select(t=>{let r=d(e,t.ref(`summary_json`),`transcript`),i=textBytes(r,t.ref(`markdown`));return[boundedText(r,i,byteLimit(n)).as(`summary`),boundedText(t.ref(`markdown`),i,byteLimit(n)).as(`markdown`),i.as(`payload_bytes`)]}).where(`session_id`,`=`,t.sessionId).where(`session_started_at`,`=`,t.startedAt));if(!r)return{};assertReadBytes(r.payload_bytes,n);let i;return r.summary&&(i=JSON.parse(r.summary)),{summary:i,markdown:r.markdown??void 0}}function requireTranscriptReadEntry(e,t,n){let r=readTranscriptEntry(e,t,n);if(!r)throw new TranscriptLibraryError(`transcript_session_not_found`,`Transcript not found; refresh the library and use its full selector.`);return r}function*iterateTranscriptExport(e,t,n){let r=requireTranscriptReadEntry(e,t,`export`);for(let t of l(e,utteranceQuery(e,r.session,`export`).orderBy(`sequence`,`asc`)))assertTranscriptByteCount(t.payload_bytes,b,!0),yield transcriptReadUtteranceFromRow(t);return{entry:r,notes:n?readStoredTranscriptNotes(e,r.session,`export`):void 0}}function*iterateArtifact(e,t){let n=s(e,meetingTranscriptSessionQuery(e,t).select(`next_utterance_seq`))?.next_utterance_seq;if(n===void 0)throw Error(`transcripts session not found: ${t.sessionId}`);if(n!==0)for(let r of l(e,meetingTranscriptUtteranceQuery(e,t).selectAll().where(`sequence`,`<`,n).orderBy(`sequence`,`asc`)))yield`${JSON.stringify(utteranceFromRow(r))}\n`}async function streamTranscriptExportInWorker(e,o,s,c){let l=m(e.databasePath,e.location,e.expectedIdentity,e.snapshotRoot),{db:u}=l.database,d=[],f={ok:!0};try{u.exec(i(u)?`BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY`:`BEGIN`),p(u,e.databasePath),i(u)||a(u),c();let t=o.format===`library`?iterateTranscriptExport(u,o.selector,o.includeNotes):iterateArtifact(u,o.session),n=o.format===`library`?{format:`library`,utterances:[]}:{format:`artifact`,jsonl:``},r=0,l=0;try{for(let e=t.next();;e=t.next()){if(e.done){l&&(await s.request(n)).consumed(),f={ok:!0,read:e.value??void 0};break}let t=e.value,i=Buffer.byteLength(typeof t==`string`?t:JSON.stringify(t));l&&(l===64||r+i>1048576)&&((await s.request(n)).consumed(),n=o.format===`library`?{format:`library`,utterances:[]}:{format:`artifact`,jsonl:``},r=0,l=0),n.format===`artifact`&&typeof t==`string`?n.jsonl+=t:n.format===`library`&&typeof t!=`string`&&n.utterances.push(t),r+=i,l++}}finally{t.return(void 0)}}catch(e){e instanceof TranscriptLibraryError?f={ok:!1,error:{type:e.type,message:e.message,maxBytes:e.maxBytes}}:(!i(u)&&t(e)&&n(u),d.push(e))}try{u.isTransaction&&u.exec(`ROLLBACK`)}catch(e){d.push(e)}try{l.close()}catch(e){d.push(e)}return r(d,`Transcript export and reader cleanup failed`),f}export{streamTranscriptExportInWorker};