openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.4 kB
JavaScript
import{t as e}from"./transcript-sqlite-jsonl-budget-error-DacbQ4UF.mjs";import{u as t}from"./transcript-sqlite-post-commit-B_pko32i.mjs";import{a as n,o as r}from"./transcript-kysely-sync-CAP5xe3V.mjs";import{Buffer as i}from"node:buffer";function assertSqliteJsonlReadBudget(a,o,s,c,l={}){let u=n(a),rejectOverflow=t=>{if(t>s)throw new e(`${c} is too large to export (at least ${t} bytes; limit ${s})`)},d=r(a,u.selectFrom(o).select(e=>[e.fn(`octet_length`,[`event_json`]).as(`bytes`),e.ref(`event_utf8_bytes`).as(`utf8_bytes`),(t(a)?e.val(`UTF-8`):e.selectFrom(`pragma_encoding`).select(`encoding`)).as(`encoding`)]).$if(l.maxRows!==void 0,e=>e.limit(l.maxRows+1))),f=0,p=0,m=0,h=0,g=0,_=0;for(let t of d){if(f+=1,l.maxRows!==void 0&&f>l.maxRows)throw new e(`${c} has too many rows to export (at least ${f}; limit ${l.maxRows})`);let n=t.utf8_bytes??(t.encoding===`UTF-8`?t.bytes:null);if(n===null&&t.bytes===null)throw Error(`${c} has a transcript row without byte metadata or identity text`);n===null?_+=1:h+=n,p+=(n??Math.ceil(t.bytes/2))+m,g+=m,rejectOverflow(p),m=l.separatorBytes??1}if(_===0)return;p=h+g;let v=u.selectFrom(o).select(`event_json`).where(`event_utf8_bytes`,`is`,null);for(let e of r(a,v)){if(e.event_json===null)throw Error(`${c} has a transcript row without identity text`);p+=i.byteLength(e.event_json,`utf8`),rejectOverflow(p)}}export{assertSqliteJsonlReadBudget as t};