UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) 3.56 kB
import { r as isPathInside } from "./path-guards-Cp-mGr3-.js"; import { n as normalizeAgentId } from "./agent-id-CeT3w4ap.js"; import "./session-key-BnWWjqNc.js"; import { n as normalizeAgentDirRegistryPath, t as isPathOwnedByAnotherRegisteredAgent } from "./agent-dir-registry-Dkh28921.js"; import { dt as resolveSqliteDatabaseFilePaths } from "./openclaw-state-db-BRTnL-D8.js"; import { a as assertNoOpenClawAgentDatabaseLeases, k as resolveOpenClawAgentSqlitePath } from "./openclaw-agent-db-lease-Djvd6LWN.js"; import { v as invalidateRegisteredAgentDatabasesMemo, y as listOpenClawRegisteredAgentDatabases } from "./openclaw-agent-db-maintenance-wTIy-jt-.js"; import { b as closeOpenClawAgentDatabaseByPath } from "./openclaw-agent-db-CWtDoRbC.js"; import { t as findOverlappingWorkspaceAgentIds } from "./agent-delete-safety-CIoplT3h.js"; import path from "node:path"; //#region src/agents/agent-delete-databases.ts /** Destructive planning includes every registered owner, regardless of runtime schema readiness. */ function readAgentDeleteDatabaseRegistry(options = {}) { invalidateRegisteredAgentDatabasesMemo(options); return listOpenClawRegisteredAgentDatabases({ ...options, includeIncompatibleSchemaVersions: true }); } function resolveSurvivingDatabaseFilePaths(registeredDatabases, agentId, env) { return [...new Set(registeredDatabases.filter((entry) => normalizeAgentId(entry.agentId) !== agentId).flatMap((entry) => resolveSqliteDatabaseFilePaths(entry.path)).map((pathname) => normalizeAgentDirRegistryPath(pathname, env)))]; } function isPathOwnedBySurvivingAgent(cfg, agentId, pathname, survivingDatabaseFilePaths = [], env) { const canonicalPath = normalizeAgentDirRegistryPath(pathname, env); return isPathOwnedByAnotherRegisteredAgent({ agentId, pathname, env }) || findOverlappingWorkspaceAgentIds(cfg, agentId, pathname, env).length > 0 || survivingDatabaseFilePaths.some((databasePath) => databasePath === canonicalPath || isPathInside(databasePath, canonicalPath) || isPathInside(canonicalPath, databasePath)); } function prepareAgentDeleteDatabases(cfg, agentId, agentDir, options = {}) { const registeredDatabases = readAgentDeleteDatabaseRegistry(options); const survivingDatabaseFilePaths = resolveSurvivingDatabaseFilePaths(registeredDatabases, agentId, options.env); const registeredDatabasePaths = /* @__PURE__ */ new Set([resolveOpenClawAgentSqlitePath({ agentId, env: options.env, path: path.join(agentDir, "openclaw-agent.sqlite") }), ...registeredDatabases.filter((entry) => normalizeAgentId(entry.agentId) === agentId).map((entry) => entry.path)]); for (const databasePath of registeredDatabasePaths) closeOpenClawAgentDatabaseByPath(databasePath, agentId); const databasePaths = [...registeredDatabasePaths].filter((pathname) => resolveSqliteDatabaseFilePaths(pathname).every((filePath) => !isPathOwnedBySurvivingAgent(cfg, agentId, filePath, survivingDatabaseFilePaths, options.env))); assertNoOpenClawAgentDatabaseLeases(agentId, options); const fileGroups = databasePaths.map(resolveSqliteDatabaseFilePaths); const relocatedFileGroups = fileGroups.filter((fileGroup) => { const relative = path.relative(agentDir, fileGroup[0] ?? agentDir); return relative.startsWith("..") || path.isAbsolute(relative); }); return { registrationPaths: [...registeredDatabasePaths], fileGroups, relocatedFileGroups }; } //#endregion export { resolveSurvivingDatabaseFilePaths as i, prepareAgentDeleteDatabases as n, readAgentDeleteDatabaseRegistry as r, isPathOwnedBySurvivingAgent as t };