Files
openclaw/src/plugin-sdk/plugin-config-runtime.ts
T
Peter Steinberger 964c8c84c1 refactor: consolidate coercion ownership (#122299)
* refactor: consolidate coercion ownership

Centralize four canonical coercion helpers, migrate exact core and plugin duplicates through narrow Plugin SDK facades, and enforce declaration and plugin-normalization ownership boundaries.

The sweep adds eight focused SDK exports while deleting more production and tooling code than it adds. User-visible behavior is unchanged except for safer equivalent object and UI parsing at existing boundaries.

* fix: guard integer option ownership

Register resolveIntegerOption with the canonical function owner and extend the declaration-guard fixture so future local duplicates fail validation.

* fix: keep integer helpers on numeric facade

Remove the unshipped duplicate string-coerce exports and route every affected plugin consumer through the existing number-runtime contract.

* fix: point numeric coercion to number runtime

Make boundary and declaration diagnostics recommend the canonical numeric facade, with failing-before coverage for both guidance paths.
2026-08-11 17:14:53 -07:00

39 lines
1.7 KiB
TypeScript

// Plugin config runtime helpers load and normalize plugin-owned configuration at execution time.
import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce";
import type { OpenClawConfig } from "../config/types.js";
import { normalizePluginsConfig, resolveEffectiveEnableState } from "../plugins/config-state.js";
export { normalizePluginsConfig, resolveEffectiveEnableState };
export { mergeDeep } from "../infra/deep-merge.js";
/** Requires an already-resolved runtime config at plugin runtime boundaries. */
export function requireRuntimeConfig(config: OpenClawConfig, context: string): OpenClawConfig {
if (config) {
return config;
}
throw new Error(
`${context} requires a resolved runtime config. Load and resolve config at the command or gateway boundary, then pass cfg through the runtime path.`,
);
}
/** Reads a plugin's object-shaped `plugins.entries[id].config` block from resolved config. */
export function resolvePluginConfigObject(
config: OpenClawConfig | undefined,
pluginId: string,
): Record<string, unknown> | undefined {
const pluginConfig = normalizePluginsConfig(config?.plugins).entries[pluginId]?.config;
return asOptionalRecord(pluginConfig);
}
/** Resolves live plugin config through a loader, falling back to startup config when unavailable. */
export function resolveLivePluginConfigObject(
runtimeConfigLoader: (() => OpenClawConfig | undefined) | undefined,
pluginId: string,
startupPluginConfig?: Record<string, unknown>,
): Record<string, unknown> | undefined {
if (typeof runtimeConfigLoader !== "function") {
return startupPluginConfig;
}
return resolvePluginConfigObject(runtimeConfigLoader(), pluginId);
}