refactor: consolidate core micro-helpers (#117825)

* refactor: centralize stable stringification

* refactor: reuse canonical record coercion

* refactor: reuse safe JSON parsing in cron storage

* refactor: centralize environment truthiness

* fix: enforce model scan and block reply timeouts

* refactor: consolidate signal-aware sleep helper

* fix: preserve plugin SDK sleep contract

* test: satisfy model scan timeout lint
This commit is contained in:
Peter Steinberger
2026-08-01 23:10:46 -07:00
committed by GitHub
parent df8cc5a458
commit 33ea3e16e9
71 changed files with 309 additions and 405 deletions
+1 -6
View File
@@ -5,7 +5,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
import { uniqueStrings } from "@openclaw/normalization-core/string-normalization";
import { isVitestRuntimeEnv } from "../infra/env.js";
import { isTruthyEnvValue, isVitestRuntimeEnv } from "../infra/env.js";
import { resolveOpenClawPackageRootSync } from "../infra/openclaw-root.js";
import { isPathInside } from "../infra/path-guards.js";
import { resolveUserPath } from "../utils.js";
@@ -39,11 +39,6 @@ function isSourceCheckoutRoot(packageRoot: string): boolean {
);
}
function isTruthyEnvValue(value: string | undefined): boolean {
const normalized = value?.trim().toLowerCase();
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
}
function shouldTrustTestBundledPluginsDirOverride(env: NodeJS.ProcessEnv): boolean {
const isVitestProcess = isVitestRuntimeEnv(env) || isVitestRuntimeEnv(process.env);
return (
@@ -1,4 +1,5 @@
// Checks web-search credential presence from config and plugin metadata.
import { asOptionalObjectRecord } from "@openclaw/normalization-core/record-coerce";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { loadManifestMetadataSnapshot } from "./manifest-contract-eligibility.js";
import type { PluginManifestRecord } from "./manifest-registry.js";
@@ -10,27 +11,24 @@ function hasConfiguredCredentialValue(value: unknown): boolean {
return value !== undefined && value !== null;
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
function hasConfiguredSearchCredentialCandidate(searchConfig: unknown): boolean {
if (!isRecord(searchConfig)) {
const record = asOptionalObjectRecord(searchConfig);
if (!record) {
return false;
}
return Object.entries(searchConfig).some(
return Object.entries(record).some(
([key, value]) => key !== "enabled" && hasConfiguredCredentialValue(value),
);
}
function hasConfiguredPluginWebSearchCandidate(config: OpenClawConfig): boolean {
const entries = isRecord(config.plugins?.entries) ? config.plugins.entries : undefined;
const entries = asOptionalObjectRecord(config.plugins?.entries);
if (!entries) {
return false;
}
return Object.values(entries).some((entry) => {
const pluginConfig = isRecord(entry) ? entry.config : undefined;
return isRecord(pluginConfig) && hasConfiguredSearchCredentialCandidate(pluginConfig.webSearch);
const pluginConfig = asOptionalObjectRecord(entry)?.config;
return hasConfiguredSearchCredentialCandidate(asOptionalObjectRecord(pluginConfig)?.webSearch);
});
}