UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.45 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{c as readFileDescriptorBoundedSync}from"./boundary-file-read-bB9An35K.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import{N as parseAgentSessionKey}from"./session-key-BPgKfU2m.mjs";import{u as tryResolveDefaultAgentId}from"./agent-roster-4XrgUgPK.mjs";import{i as isPrimarySessionTranscriptFileName}from"./transcript-file-names-eSXc53rr.mjs";import"./artifacts-CxKxmpYV.mjs";import{a as resolveUnsuffixedSqliteTargetFromSessionStorePath}from"./session-sqlite-target-paths-CA4CNfL-.mjs";import{o as resolveSessionFilePathCore}from"./paths-CcxgiC3g.mjs";import{A as tryResolveLegacyCompatibilityAgentId}from"./agent-scope-config-CG9CFpGX.mjs";import{r as decodeUtf8Input}from"./utf8-input-CiFSnxL0.mjs";import"./agent-scope-Dw5XRSEh.mjs";import"./legacy.default-agent-owner-DUgZJ5NH.mjs";import{t as assertSupportedSessionStoreEntry}from"./supported-session-store-BV2wor2U.mjs";import{n as parseSqliteSessionFileMarker}from"./legacy-sqlite-marker-BOXSzMrL.mjs";import{c as resolveStoredSessionOwnerAgentId}from"./session-store-key-DZXBwthg.mjs";import fs from"node:fs";import path from"node:path"; //!src/config/sessions/legacy-store-inspection.ts function listLegacySessionTranscriptFiles(e){if(!fs.existsSync(e))return[];return fs.readdirSync(e,{withFileTypes:true}).filter(e=>e.isFile()&&isPrimarySessionTranscriptFileName(e.name)).map(t=>path.join(e,t.name))}function readLegacySessionStoreEntries(e,t,n={}){const r=process.platform===`win32`?`r`:fs.constants.O_RDONLY|fs.constants.O_NONBLOCK;let i;try{i=fs.openSync(n.sourcePath??e.storePath,r)}catch(r){if(n.allowMissingStore===true&&hasErrnoCode(r,`ENOENT`)){try{if(!fs.statSync(path.dirname(e.storePath)).isDirectory())t.push({code:`store_unreadable`,message:`${e.storePath}: parent path is not a directory`})}catch(n){if(!hasErrnoCode(n,`ENOENT`))t.push({code:`store_unreadable`,message:`${e.storePath}: ${String(n)}`})}return{entries:[]}}t.push({code:`store_unreadable`,message:`${e.storePath}: ${String(r)}`});return{entries:[]}}try{let n;let r;try{const a=fs.fstatSync(i);if(!a.isFile()){t.push({code:`store_unreadable`,message:`${e.storePath}: not a regular file`});return{entries:[]}}r=readFileDescriptorBoundedSync(i,a.size);n=JSON.parse(decodeUtf8Input(r,`Legacy session index ${e.storePath}`))}catch(n){t.push({code:`store_unreadable`,message:`${e.storePath}: ${String(n)}`});return{entries:[]}}if(!isRecord(n)){t.push({code:`store_not_object`,message:`${e.storePath} does not contain an object session store.`});return{entries:[]}}const a=[];for(const[r,i]of Object.entries(n)){assertSupportedSessionStoreEntry(i);if(!isSessionEntry(i)){t.push({code:`entry_invalid`,message:`${e.storePath}: session entry is missing a valid sessionId; skipped while preserving the original index for recovery.`,sessionKey:r});continue}a.push({entry:i,sessionKey:r})}return{entries:a,bytes:r}}finally{fs.closeSync(i)}}function isLegacySessionRecordOwnedByTarget(e,t,n){if(t.sqlitePath){const r=parseAgentSessionKey(n)?.agentId??e.agents?.defaults?.sessionStore?.agentId?.trim()??tryResolveLegacyCompatibilityAgentId(e);return r?normalizeAgentId(r)===normalizeAgentId(t.agentId):false}const r=resolveStoredSessionOwnerAgentId({cfg:e,agentId:t.agentId,sessionKey:n});return r?r===t.agentId:t.agentId===tryResolveDefaultAgentId(e)}function shouldFilterLegacySessionRecordsByTarget(e){return!resolveUnsuffixedSqliteTargetFromSessionStorePath(e.storePath).agentId}function resolveLegacyTranscriptPaths(e,t,n){const r=typeof t.sessionFile===`string`?t.sessionFile:void 0;if(parseSqliteSessionFileMarker(r))return{transcriptCandidates:[],transcriptDependencies:[]};const i=path.dirname(e.storePath);const a=r?.trim()?path.join(i,path.basename(r)):void 0;let o;try{o=resolveSessionFilePathCore(t.sessionId,t,{agentId:e.agentId,sessionsDir:i})}catch(e){if(!a)throw e;o=a}const s=a?[o,a]:[o];return{transcriptPath:s.find(e=>n?.has(path.resolve(e)))??s.find(e=>fs.existsSync(e))??(a?o:void 0),transcriptCandidates:s,transcriptDependencies:s.map(e=>path.join(i,path.basename(e)))}}function isSessionEntry(e){return isRecord(e)&&typeof e.sessionId===`string`&&e.sessionId.trim()!==``}export{shouldFilterLegacySessionRecordsByTarget as a,resolveLegacyTranscriptPaths as i,listLegacySessionTranscriptFiles as n,readLegacySessionStoreEntries as r,isLegacySessionRecordOwnedByTarget as t};