mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:00:43 +00:00
perf: lazy load system run config
This commit is contained in:
@@ -13,7 +13,11 @@ import {
|
||||
type Mock,
|
||||
vi,
|
||||
} from "vitest";
|
||||
import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } from "../config/config.js";
|
||||
import {
|
||||
clearRuntimeConfigSnapshot,
|
||||
getRuntimeConfigSnapshot,
|
||||
setRuntimeConfigSnapshot,
|
||||
} from "../config/runtime-snapshot.js";
|
||||
import type { SystemRunApprovalPlan } from "../infra/exec-approvals.js";
|
||||
import { loadExecApprovals, saveExecApprovals } from "../infra/exec-approvals.js";
|
||||
import type { ExecHostResponse } from "../infra/exec-host.js";
|
||||
@@ -474,6 +478,7 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
|
||||
sendInvokeResult,
|
||||
sendExecFinishedEvent,
|
||||
preferMacAppExecHost: params.preferMacAppExecHost,
|
||||
loadConfig: () => getRuntimeConfigSnapshot() ?? {},
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import crypto from "node:crypto";
|
||||
import { resolveAgentConfig } from "../agents/agent-scope.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import type { GatewayClient } from "../gateway/client.js";
|
||||
import {
|
||||
addDurableCommandApproval,
|
||||
@@ -171,8 +171,17 @@ export type HandleSystemRunInvokeOptions = {
|
||||
sendInvokeResult: (result: SystemRunInvokeResult) => Promise<void>;
|
||||
sendExecFinishedEvent: (params: ExecFinishedEventParams) => Promise<void>;
|
||||
preferMacAppExecHost: boolean;
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
};
|
||||
|
||||
async function loadSystemRunConfig(opts: HandleSystemRunInvokeOptions): Promise<OpenClawConfig> {
|
||||
if (opts.loadConfig) {
|
||||
return opts.loadConfig();
|
||||
}
|
||||
const { loadConfig } = await import("../config/config.js");
|
||||
return loadConfig();
|
||||
}
|
||||
|
||||
async function sendSystemRunDenied(
|
||||
opts: Pick<
|
||||
HandleSystemRunInvokeOptions,
|
||||
@@ -343,7 +352,7 @@ async function evaluateSystemRunPolicyPhase(
|
||||
opts: HandleSystemRunInvokeOptions,
|
||||
parsed: SystemRunParsePhase,
|
||||
): Promise<SystemRunPolicyPhase | null> {
|
||||
const cfg = loadConfig();
|
||||
const cfg = await loadSystemRunConfig(opts);
|
||||
const agentExec = parsed.agentId
|
||||
? resolveAgentConfig(cfg, parsed.agentId)?.tools?.exec
|
||||
: undefined;
|
||||
|
||||
Reference in New Issue
Block a user