mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 15:01:41 +03:00
refactor: centralize agent concurrency defaults
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { resolveTalkApiKey } from "./talk.js";
|
||||
import type { ClawdbotConfig } from "./types.js";
|
||||
import { DEFAULT_AGENT_MAX_CONCURRENT, DEFAULT_SUBAGENT_MAX_CONCURRENT } from "./agent-limits.js";
|
||||
|
||||
type WarnState = { warned: boolean };
|
||||
|
||||
@@ -105,6 +106,43 @@ export function applyModelDefaults(cfg: ClawdbotConfig): ClawdbotConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export function applyAgentDefaults(cfg: ClawdbotConfig): ClawdbotConfig {
|
||||
const agents = cfg.agents;
|
||||
const defaults = agents?.defaults;
|
||||
const hasMax =
|
||||
typeof defaults?.maxConcurrent === "number" && Number.isFinite(defaults.maxConcurrent);
|
||||
const hasSubMax =
|
||||
typeof defaults?.subagents?.maxConcurrent === "number" &&
|
||||
Number.isFinite(defaults.subagents.maxConcurrent);
|
||||
if (hasMax && hasSubMax) return cfg;
|
||||
|
||||
let mutated = false;
|
||||
const nextDefaults = defaults ? { ...defaults } : {};
|
||||
if (!hasMax) {
|
||||
nextDefaults.maxConcurrent = DEFAULT_AGENT_MAX_CONCURRENT;
|
||||
mutated = true;
|
||||
}
|
||||
|
||||
const nextSubagents = defaults?.subagents ? { ...defaults.subagents } : {};
|
||||
if (!hasSubMax) {
|
||||
nextSubagents.maxConcurrent = DEFAULT_SUBAGENT_MAX_CONCURRENT;
|
||||
mutated = true;
|
||||
}
|
||||
|
||||
if (!mutated) return cfg;
|
||||
|
||||
return {
|
||||
...cfg,
|
||||
agents: {
|
||||
...agents,
|
||||
defaults: {
|
||||
...nextDefaults,
|
||||
subagents: nextSubagents,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function applyLoggingDefaults(cfg: ClawdbotConfig): ClawdbotConfig {
|
||||
const logging = cfg.logging;
|
||||
if (!logging) return cfg;
|
||||
|
||||
Reference in New Issue
Block a user