mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-23 23:59:50 +00:00
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { getRuntimeConfig } from "../../config/config.js";
|
|
import {
|
|
mutateConfigFile as mutateConfigFileInternal,
|
|
replaceConfigFile as replaceConfigFileInternal,
|
|
} from "../../config/mutate.js";
|
|
import { logWarn } from "../../logger.js";
|
|
import type { PluginRuntime } from "./types.js";
|
|
|
|
const RUNTIME_CONFIG_LOAD_WRITE_COMPAT_CODE = "runtime-config-load-write";
|
|
|
|
const warnedDeprecatedConfigApis = new Set<string>();
|
|
|
|
function warnDeprecatedConfigApiOnce(
|
|
name: "loadConfig" | "writeConfigFile",
|
|
replacement: string,
|
|
): void {
|
|
if (warnedDeprecatedConfigApis.has(name)) {
|
|
return;
|
|
}
|
|
warnedDeprecatedConfigApis.add(name);
|
|
logWarn(
|
|
`plugin runtime config.${name}() is deprecated (${RUNTIME_CONFIG_LOAD_WRITE_COMPAT_CODE}); use ${replacement}.`,
|
|
);
|
|
}
|
|
|
|
export function createRuntimeConfig(): PluginRuntime["config"] {
|
|
return {
|
|
current: getRuntimeConfig,
|
|
mutateConfigFile: async (params) =>
|
|
await mutateConfigFileInternal({
|
|
...params,
|
|
writeOptions: params.writeOptions,
|
|
}),
|
|
replaceConfigFile: async (params) =>
|
|
await replaceConfigFileInternal({
|
|
...params,
|
|
writeOptions: params.writeOptions,
|
|
}),
|
|
loadConfig: () => {
|
|
warnDeprecatedConfigApiOnce("loadConfig", "config.current()");
|
|
return getRuntimeConfig();
|
|
},
|
|
writeConfigFile: async (cfg, options) => {
|
|
warnDeprecatedConfigApiOnce(
|
|
"writeConfigFile",
|
|
"config.mutateConfigFile(...) or config.replaceConfigFile(...)",
|
|
);
|
|
await replaceConfigFileInternal({
|
|
nextConfig: cfg,
|
|
afterWrite: options?.afterWrite ?? { mode: "auto" },
|
|
writeOptions: options,
|
|
});
|
|
},
|
|
};
|
|
}
|