openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
4 lines • 3.37 kB
JavaScript
import{l as resolveRuntimeServiceCommit,o as resolveRuntimeServiceBuildId,t as VERSION}from"./version-DrZ9Nfde.mjs";import{W as backupDoctorSqliteRepair}from"./openclaw-state-db-BlgxYkYw.mjs";import{s as runOpenClawAgentWriteTransaction}from"./openclaw-agent-db-BUym2U31.mjs";import{o as INBOUND_CONTEXT_MARKER}from"./strip-inbound-meta-ftpq205E.mjs";import{o as updateSqliteTranscriptEventJsonInTransaction}from"./session-accessor.sqlite-transcript-store-CHxqudYm.mjs";import{b as readTranscriptEventRows}from"./session-accessor.sqlite-read-B5RvcnvD.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{n as normalizeLegacyInboundContextLabels,t as mayContainLegacyInboundContextLabels}from"./legacy-inbound-context-labels-Bm1DlRAz.mjs";import{t as countLabel}from"./doctor-state-integrity-format-2pYQQBOH.mjs";import{n as transcriptSnapshotsMatch,t as scanDoctorSessionTranscripts}from"./doctor-session-transcript-scan-DcGdmgAQ.mjs";
//!src/commands/doctor-session-transcript-labels.ts
const NOTE_TITLE=`Chat history labels`;async function noteSessionTranscriptLabelHealth(e){const t=e.env??process.env;let n=0;let r=0;let i=0;let a=0;const o=/* @__PURE__ */ new Set;await scanDoctorSessionTranscripts({cfg:e.cfg,env:t,title:NOTE_TITLE,failureLabel:`Failed to inspect or rewrite labels`,cleanScanIdentity:n=>[`session-transcript-labels:v1`,VERSION,resolveRuntimeServiceBuildId(),resolveRuntimeServiceCommit(),process.versions.node,INBOUND_CONTEXT_MARKER,t.OPENCLAW_PROFILE??null,n.agentId,n.storePath,e.shouldRepair,e.integrityCheck??`quick`]},async({reader:t,target:s,databaseOptions:c,reportError:l,sessionId:u})=>{const{agentId:d}=s;const f=t.labelRepairSnapshot(u,normalizeLegacyInboundContextLabels,mayContainLegacyInboundContextLabels);if(!f.ok){l(`- Failed to read transcript for session ${u} (${d})`,f.error);return false}const p=[];let m=false;for(const e of f.rows){let t;try{t=JSON.parse(e.eventJson)}catch{m=true;continue}if(normalizeLegacyInboundContextLabels(t))p.push({seq:e.seq,eventJson:JSON.stringify(t)})}if(p.length===0)return true;n+=1;r+=p.length;if(e.shouldRepair)try{if(m)throw new Error(`transcript contains malformed event JSON for ${u}`);if(!o.has(s.sqlitePath)){const e=await backupDoctorSqliteRepair(s.sqlitePath,`transcript-labels`);o.add(s.sqlitePath);note(`- Saved pre-repair SQLite backup: ${e}`,NOTE_TITLE)}runOpenClawAgentWriteTransaction(e=>{const t=readTranscriptEventRows(e,u);if(!transcriptSnapshotsMatch(f.rows,t))throw new Error(`transcript changed while preparing rewrite for ${u}`);updateSqliteTranscriptEventJsonInTransaction(e,u,p)},c,{operationLabel:`doctor.session-transcript-labels`,repairAdmission:{integrityCheck:e.integrityCheck??`quick`,integrityTables:[`transcript_events`,`transcript_rewrite_watermarks`,`session_windows`,`session_transcript_index_state`,`session_transcript_active_events`,`session_transcript_fts_rows`,`session_transcript_fts`]}});i+=1;a+=p.length}catch(e){l(`- Failed to rewrite labels for session ${u} (${d})`,e)}return false});if(e.shouldRepair&&i>0)note(`- Rewrote legacy inbound-context labels in ${countLabel(i,`session`)} (${countLabel(a,`event`)}).`,NOTE_TITLE);else if(!e.shouldRepair&&r>0)note([`- Found ${countLabel(n,`session`)} with legacy inbound-context labels.`,`- Run "openclaw doctor --fix" to rewrite them.`].join(`
`),NOTE_TITLE)}export{noteSessionTranscriptLabelHealth};