openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
63 lines (62 loc) • 2.16 kB
JavaScript
import { d as pathExists } from "./fs-safe-B6pvPGnf.js";
import { t as formatErrorMessage } from "./errors-Db3Ymjlb.js";
import { r as resolveSafeInstallDir, t as assertCanonicalPathWithinBase } from "./install-safe-path-CVdg_-66.js";
import fs from "node:fs/promises";
//#region src/infra/install-mode-options.ts
/** Resolves shared install/update mode options with a required logger fallback. */
function resolveInstallModeOptions(params, defaultLogger) {
return {
logger: params.logger ?? defaultLogger,
mode: params.mode ?? "install",
dryRun: params.dryRun ?? false
};
}
/** Resolves install/update mode options plus an operation timeout default. */
function resolveTimedInstallModeOptions(params, defaultLogger, defaultTimeoutMs = 12e4) {
return {
...resolveInstallModeOptions(params, defaultLogger),
timeoutMs: params.timeoutMs ?? defaultTimeoutMs
};
}
//#endregion
//#region src/infra/install-target.ts
/** Resolves and verifies an install target directory under a canonical base directory. */
async function resolveCanonicalInstallTarget(params) {
await fs.mkdir(params.baseDir, { recursive: true });
const targetDirResult = resolveSafeInstallDir({
baseDir: params.baseDir,
id: params.id,
invalidNameMessage: params.invalidNameMessage,
nameEncoder: params.nameEncoder
});
if (!targetDirResult.ok) return {
ok: false,
error: targetDirResult.error
};
try {
await assertCanonicalPathWithinBase({
baseDir: params.baseDir,
candidatePath: targetDirResult.path,
boundaryLabel: params.boundaryLabel
});
} catch (err) {
return {
ok: false,
error: formatErrorMessage(err)
};
}
return {
ok: true,
targetDir: targetDirResult.path
};
}
/** Ensures install mode does not overwrite an existing target; update mode may reuse it. */
async function ensureInstallTargetAvailable(params) {
if (params.mode === "install" && await pathExists(params.targetDir)) return {
ok: false,
error: params.alreadyExistsError
};
return { ok: true };
}
//#endregion
export { resolveTimedInstallModeOptions as i, resolveCanonicalInstallTarget as n, resolveInstallModeOptions as r, ensureInstallTargetAvailable as t };