mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 02:01:11 +00:00
* refactor(plugin-sdk): narrow wildcard barrels to explicit used exports * refactor(tools): delete dead tool-planning module exposed by barrel narrowing * fix(plugin-sdk): restore deprecation tag on OpenClawSchemaType alias * test(agents): drop test for deleted runtime proxy module * refactor(tools): trim descriptor types to cache consumers * refactor(deadcode): harvest exports orphaned by barrel narrowing * refactor(deadcode): harvest exports orphaned by barrel narrowing (rest) * fix(agents): restore sdk imports and test markers via public predicate * fix(plugin-sdk): named type re-exports in plugin-entry; trim types barrel precisely * chore(plugin-sdk): account unmasked deprecated provider types in budgets * fix(plugins): name star-only type rows for dts bundling * fix(plugins): restore host-hook surface; unexport internal api compositions * fix(plugins): named type imports for api composition; restore needed source exports * fix(plugins): knip-visible type imports for registry surfaces * test: adapt tests to privatized media and command internals * fix(qa-lab): re-export snapshot conversation type * style: format sessions sdk imports * fix(plugins): restore smoke entry export; pin budgets to exact actuals * fix(plugins): canonical smoke-entry import; drop orphaned root shims * fix(plugins): allowlist manifest probe, repoint qa web import, drop dead browser barrels * fix(plugin-sdk): pin codex auth marker and scaffold provider type * fix(qa-lab): keep web-facing model-selection shim within boundary rules * fix(plugin-sdk): preserve merged contracts through narrowed barrels * chore(plugin-sdk): pin post-rebase surface budgets
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
/** Shared parsing and file helpers for secrets migration/runtime code. */
|
|
import path from "node:path";
|
|
import { privateFileStoreSync } from "../infra/private-file-store.js";
|
|
import { replaceFileAtomicSync } from "../infra/replace-file.js";
|
|
import { resolvePositiveTimerTimeoutMs } from "../shared/number-coercion.js";
|
|
export { isRecord } from "../utils.js";
|
|
|
|
/**
|
|
* Narrows to strings that contain non-whitespace content.
|
|
*/
|
|
export function isNonEmptyString(value: unknown): value is string {
|
|
return typeof value === "string" && value.trim().length > 0;
|
|
}
|
|
|
|
/**
|
|
* Parses a simple .env assignment value, stripping one matching quote pair after trimming.
|
|
*/
|
|
export function parseEnvValue(raw: string): string {
|
|
const trimmed = raw.trim();
|
|
if (
|
|
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
|
) {
|
|
return trimmed.slice(1, -1);
|
|
}
|
|
return trimmed;
|
|
}
|
|
|
|
/**
|
|
* Normalizes numeric config to a positive integer, falling back when the input is not finite.
|
|
*/
|
|
export function normalizePositiveInt(value: unknown, fallback: number): number {
|
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
return Math.max(1, Math.floor(value));
|
|
}
|
|
return Math.max(1, Math.floor(fallback));
|
|
}
|
|
|
|
/**
|
|
* Normalizes timer values with the shared timeout coercion rules used by secret providers.
|
|
*/
|
|
export function normalizePositiveTimerMs(value: unknown, fallback: number): number {
|
|
return resolvePositiveTimerTimeoutMs(value, fallback);
|
|
}
|
|
|
|
/**
|
|
* Splits a dotted config path into non-empty trimmed segments.
|
|
*/
|
|
export function parseDotPath(pathname: string): string[] {
|
|
return pathname
|
|
.split(".")
|
|
.map((segment) => segment.trim())
|
|
.filter((segment) => segment.length > 0);
|
|
}
|
|
|
|
/**
|
|
* Joins config path segments using the secrets command's dotted path format.
|
|
*/
|
|
export function toDotPath(segments: string[]): string {
|
|
return segments.join(".");
|
|
}
|
|
|
|
/**
|
|
* Atomically writes secret-adjacent text, using the private store for default 0600 files.
|
|
*/
|
|
export function writeTextFileAtomic(pathname: string, value: string, mode = 0o600): void {
|
|
if (mode !== 0o600) {
|
|
replaceFileAtomicSync({
|
|
filePath: pathname,
|
|
content: value,
|
|
mode,
|
|
tempPrefix: ".openclaw-secrets",
|
|
});
|
|
return;
|
|
}
|
|
privateFileStoreSync(path.dirname(pathname)).writeText(path.basename(pathname), value);
|
|
}
|