mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 06:10:43 +00:00
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import type { OpenClawConfig } from "../config/types.js";
|
|
|
|
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.`,
|
|
);
|
|
}
|
|
|
|
export function resolvePluginConfigObject(
|
|
config: OpenClawConfig | undefined,
|
|
pluginId: string,
|
|
): Record<string, unknown> | undefined {
|
|
const plugins =
|
|
config?.plugins && typeof config.plugins === "object" && !Array.isArray(config.plugins)
|
|
? (config.plugins as Record<string, unknown>)
|
|
: undefined;
|
|
const entries =
|
|
plugins?.entries && typeof plugins.entries === "object" && !Array.isArray(plugins.entries)
|
|
? (plugins.entries as Record<string, unknown>)
|
|
: undefined;
|
|
const entry = entries?.[pluginId];
|
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
return undefined;
|
|
}
|
|
const pluginConfig = (entry as { config?: unknown }).config;
|
|
return pluginConfig && typeof pluginConfig === "object" && !Array.isArray(pluginConfig)
|
|
? (pluginConfig as Record<string, unknown>)
|
|
: undefined;
|
|
}
|
|
|
|
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);
|
|
}
|