UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

123 lines (122 loc) • 4.79 kB
import { parentPort } from "node:worker_threads"; //#region src/infra/update-candidate-state.worker.ts async function snapshotCandidateState() { const e = []; for await (const t of process.stdin) e.push(Buffer.isBuffer(t) ? t : Buffer.from(t)); const t = JSON.parse(Buffer.concat(e).toString("utf8")); const n = await inspectCandidateState(t); const { writeUpdateStateResult: r } = await import("../update-candidate-state.result-DuBBeA_z.mjs"); await r(n, t.resultPath); } async function inspectCandidateState(e) { if (e.mode === "runtime-retention") { const { prepareRetainedRuntimeFiles: t } = await import("../update-retained-runtime-files-DXgcroMv.mjs"); return t(e); } if ("stateDir" in e && e.mode !== "database-generations" && e.mode !== "snapshot") e.env = { ...e.env, OPENCLAW_STATE_DIR: e.stateDir }; if ("config" in e && "stateDir" in e) { const { normalizeLegacyWorkboardDatabaseConfig: t } = await import("../legacy-workboard-database-BiiwiTI3.mjs"); e.config = t(e.config, { ...process.env, OPENCLAW_STATE_DIR: e.stateDir }); } const { createUpdateStateInspectionReporter: t } = await import("../update-candidate-state.diagnostics-VKqRAb5c.mjs"); const { discoverUpdateStateSchemaInspectionInProcess: n, readUpdateCandidateStateInventoryInProcess: r, readUpdateStateSchemaVersionsInProcess: i, snapshotUpdateCandidateState: a } = await import("../update-candidate-state-g-1DTRyS.mjs"); switch (e.mode) { case "database-restore-preparation": { const { prepareUpdateDatabaseRestoreSourceInProcess: t } = await import("../update-database-restore-source-80K2LqER.mjs"); return t(e); } case "database-generations": { const { readUpdatePhysicalDatabaseGenerationPair: t, isLegacyUpdateGenerationRequest: n } = await import("../update-physical-database-generations-D_VxxvMy.mjs"); const r = await t(e.paths, e.pluginOwners); if (e.generationFormat === "paired") return r; return e.generationFormat === void 0 && await n({ ...process.env, OPENCLAW_STATE_DIR: e.stateDir }) ? r.physical : r.committed; } case "inventory": { const { resolveDatabaseFamilyEngines: n } = await import("../registry-CkMGXa4B.mjs"); const { databases: i, ...a } = await r({ ...e, onProgress: t(!e.streamProgress) }); return { ...a, databases: [...i], ...e.config.database?.engine !== "postgres" && !Object.values(n(e.config)).includes("postgres") ? { snapshotSpace: "single-generation" } : {} }; } case "database-backup": { const { createUpdateDatabaseBackupInProcess: n } = await import("../update-database-backup-BEjcvZKj.mjs"); return n({ ...e, onProgress: t() }); } case "snapshot": return a({ ...e, includeLocalStoreVersions: e.includeLocalStoreVersions === true, includeClientCredentialStoreVersion: e.includeClientCredentialStoreVersion === true, onProgress: t(!e.streamProgress) }); case "discover": return n({ ...e, onProgress: t() }); case "versions": return i({ ...e, includeLocalStoreVersions: e.includeLocalStoreVersions === true, includeClientCredentialStoreVersion: e.includeClientCredentialStoreVersion === true, onProgress: t(!e.inspectionPlan) }); default: throw new Error("Unknown update state inspection mode"); } } if (parentPort) { const { assertDirectoryIdentitySync: e } = await import("@openclaw/fs-safe/advanced"); const { root: t } = await import("../fs-safe-CZVDXVig.mjs"); const { copyUpdateCandidatePluginFile: n } = await import("../update-candidate-plugin-file-CVWzN4YY.mjs"); const { hashFileMutationSnapshotSync: r } = await import("../file-descriptor-uxpz6-OO.mjs"); const { serveWorkerTasks: i } = await import("../worker-task-server-BIyN3Txx.mjs"); let a; i(async (i, o, s) => s.runNativeSection(async () => { const o = i; try { if ("type" in o) return { type: "hashed", sha256: r(o.filePath, o.expected) }; e(o.privateRoot, o.rootIdentity); if (a?.path !== o.privateRoot) a = { path: o.privateRoot, root: await t(o.privateRoot) }; e(o.privateRoot, o.rootIdentity); await n(o, a.root); return { type: "copied" }; } catch (e) { return { type: "failed", error: e instanceof Error ? e : new Error(String(e)), ...e instanceof Error && "code" in e && typeof e.code === "string" ? { code: e.code } : {}, ...e instanceof Error && "details" in e ? { details: e.details } : {} }; } })); } else { const { routeLogsToStderr: e } = await import("../console-DzWOOvYF.mjs"); e(); const { formatUpdateStateInspectionError: t } = await import("../update-candidate-state.diagnostics-VKqRAb5c.mjs"); snapshotCandidateState().catch((e) => { process.stderr.write(t(e)); process.exitCode = 1; }); } //#endregion export {};