openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
54 lines (53 loc) • 3.38 kB
JavaScript
import { n as isTruthyEnvValue } from "./env-HehwidXj.mjs";
import { r as isRegularFile } from "./executable-path-D8oWZRS5.mjs";
import { Jn as string, qn as strictObject } from "./schemas-Cy6abvsu.mjs";
import { t as safeParseJsonWithSchema } from "./zod-parse-Bqd52uSa.mjs";
import { n as resolveStableNodePath } from "./stable-node-path-CgUjRwli.mjs";
import { o as isUpdateOwnedGatewayServiceCommand } from "./service-update-authority-wlK0pAdP.mjs";
import { s as resolvePinnedDaemonRuntimePath } from "./runtime-paths-xW9-a89Z.mjs";
import { n as buildGatewayInstallEntrypointCandidates } from "./gateway-entrypoint-BY8XHlJn.mjs";
import { d as OPENCLAW_WRAPPER_ENV_KEY } from "./service-hQiIzcTo.mjs";
import path from "node:path";
//#region src/cli/daemon-cli/install-restore-cli.ts
const expectedRuntimePinSchema = strictObject({
revision: string(),
definition: string().nullable()
});
function assertExpectedRuntimePin(e, t, n) {
const r = safeParseJsonWithSchema(expectedRuntimePinSchema, e);
if (!r) throw new Error("Invalid expected runtime pin snapshot.");
if (r.revision !== t.revision || r.definition !== (t.definition ?? null)) throw new Error(`${n} service or runtime pin changed before installation. The newer selection was preserved; inspect it before retrying.`);
}
const serviceFile = string().refine((e) => path.isAbsolute(e) && !/[\0\r\n]/.test(e) && isRegularFile(e));
const restoreServiceCliSchema = strictObject({
executable: string(),
entrypoint: serviceFile.refine((e) => path.basename(e) === "openclaw.mjs" || buildGatewayInstallEntrypointCandidates(path.dirname(path.dirname(e))).includes(path.normalize(e))).nullable(),
sqliteLibrary: serviceFile.nullable()
});
/** Validate recovery before config preparation; SQLite selection changes only the service env. */
async function resolveRestoreServiceCli(e, t, n) {
const r = safeParseJsonWithSchema(restoreServiceCliSchema, e);
if (!r) throw new Error("Invalid restore service CLI.");
const { runtime: i, runtimePath: a, wrapper: o, expectedRuntimePin: s } = t;
const { executable: c, sqliteLibrary: l } = r;
try {
if (s === void 0) throw new Error("requires --expected-runtime-pin.");
if (i !== "node" && i !== "bun" && i !== "standalone") throw new Error("requires an explicit --runtime (\"node\", \"bun\", or \"standalone\").");
if (i === "standalone" !== (r.entrypoint === null)) throw new Error("standalone recovery requires a null entrypoint; Node and Bun require an entry script.");
if (o !== void 0 || n["OPENCLAW_WRAPPER"]?.trim()) throw new Error("cannot be combined with a wrapper.");
if (a !== void 0 && path.normalize(a) !== path.normalize(c)) throw new Error("executable must match --runtime-path.");
if (isUpdateOwnedGatewayServiceCommand() || isTruthyEnvValue(process.env.OPENCLAW_UPDATE_IN_PROGRESS)) throw new Error("cannot be combined with update-owned reconciliation.");
if (l === null) delete n.OPENCLAW_SQLITE_LIBRARY;
else n.OPENCLAW_SQLITE_LIBRARY = l;
let e = await resolvePinnedDaemonRuntimePath(c, i, n);
if (i === "node" && a === void 0 && e) e = await resolveStableNodePath(e);
return {
serviceCli: r,
runtimePath: e
};
} catch (e) {
throw new Error(`--restore-service-cli ${e instanceof Error ? e.message : String(e)}`, { cause: e });
}
}
//#endregion
export { resolveRestoreServiceCli as n, assertExpectedRuntimePin as t };