openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.97 kB
JavaScript
import{r as resolveStateDir}from"./state-dir-BwIClCab.mjs";import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import{a as resolveUnsuffixedSqliteTargetFromSessionStorePath,r as parseSqliteTargetSuffixIndex}from"./session-sqlite-target-paths-CA4CNfL-.mjs";import{r as isUpdateRehearsalReadOnlyPath}from"./update-rehearsal-paths-C4qLj9oD.mjs";import{s as resolveConfiguredAgentDatabaseTargets}from"./targets-DZpbOEi4.mjs";import path from"node:path";
//!src/commands/doctor-relative-session-store-paths.ts
function resolveDoctorAgentMigrationTargets(e,t,n){const r=n.skipConfigured?[]:resolveConfiguredAgentDatabaseTargets(e,{env:t,registeredDatabases:n.registeredDatabases});if(n.mode===`doctor`)r.push(...resolveRelativeSessionStoreMigrationTargets(e,t,n.registeredDatabases).filter(e=>!isUpdateRehearsalReadOnlyPath(e.path,t)));return r}function registeredRelativeStoreBase(e,t,n,r){const i=t.split(path.sep);let a=0;while(i[0]===`..`){i.shift();a++}const o=i.pop();if(!o)return;const s=path.basename(e);if(s!==o&&(!r||parseSqliteTargetSuffixIndex(s,`${path.basename(o,`.sqlite`)}.${n}`)===void 0))return;const c=path.join(...i,s);if(!e.endsWith(`${path.sep}${c}`))return;const l=e.slice(0,-c.length);return path.join(l,...Array(a).fill(`.old-session-cwd`))}function resolveRelativeSessionStoreMigrationTargets(e,t,n){const r=e.session?.store;const i=[];if(!r||r.startsWith(`~`)||path.isAbsolute(r))return i;const a=path.join(resolveStateDir(t),`.relative-session-store-probe`);for(const t of listAgentIds(e)){const e=r.replaceAll(`{agentId}`,t);const o=resolveUnsuffixedSqliteTargetFromSessionStorePath(path.resolve(a,e));for(const r of n){if(!o.shared&&r.agentId!==t)continue;const n=registeredRelativeStoreBase(r.path,path.relative(a,o.path),r.agentId,!o.agentId&&!o.shared);if(n!==void 0)i.push({...r,configuredAgentId:t,storePath:path.resolve(n,e)})}}return i}export{resolveRelativeSessionStoreMigrationTargets as n,resolveDoctorAgentMigrationTargets as t};