mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 12:11:20 +00:00
refactor: share command config resolution
This commit is contained in:
46
src/cli/command-config-resolution.ts
Normal file
46
src/cli/command-config-resolution.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
|
||||
import type { OpenClawConfig } from "../config/types.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
type CommandSecretResolutionMode,
|
||||
resolveCommandSecretRefsViaGateway,
|
||||
} from "./command-secret-gateway.js";
|
||||
|
||||
export async function resolveCommandConfigWithSecrets<TConfig extends OpenClawConfig>(params: {
|
||||
config: TConfig;
|
||||
commandName: string;
|
||||
targetIds: Set<string>;
|
||||
mode?: CommandSecretResolutionMode;
|
||||
allowedPaths?: Set<string>;
|
||||
runtime?: RuntimeEnv;
|
||||
autoEnable?: boolean;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): Promise<{
|
||||
resolvedConfig: TConfig;
|
||||
effectiveConfig: TConfig;
|
||||
diagnostics: string[];
|
||||
}> {
|
||||
const { resolvedConfig, diagnostics } = await resolveCommandSecretRefsViaGateway({
|
||||
config: params.config,
|
||||
commandName: params.commandName,
|
||||
targetIds: params.targetIds,
|
||||
...(params.mode ? { mode: params.mode } : {}),
|
||||
...(params.allowedPaths ? { allowedPaths: params.allowedPaths } : {}),
|
||||
});
|
||||
if (params.runtime) {
|
||||
for (const entry of diagnostics) {
|
||||
params.runtime.log(`[secrets] ${entry}`);
|
||||
}
|
||||
}
|
||||
const effectiveConfig = params.autoEnable
|
||||
? applyPluginAutoEnable({
|
||||
config: resolvedConfig,
|
||||
env: params.env ?? process.env,
|
||||
}).config
|
||||
: resolvedConfig;
|
||||
return {
|
||||
resolvedConfig: resolvedConfig as TConfig,
|
||||
effectiveConfig: effectiveConfig as TConfig,
|
||||
diagnostics,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user