refactor: centralize agent timeout defaults
This commit is contained in:
35
src/agents/timeout.ts
Normal file
35
src/agents/timeout.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
|
||||
const DEFAULT_AGENT_TIMEOUT_SECONDS = 600;
|
||||
|
||||
const normalizeNumber = (value: unknown): number | undefined =>
|
||||
typeof value === "number" && Number.isFinite(value)
|
||||
? Math.floor(value)
|
||||
: undefined;
|
||||
|
||||
export function resolveAgentTimeoutSeconds(cfg?: ClawdbotConfig): number {
|
||||
const raw = normalizeNumber(cfg?.agent?.timeoutSeconds);
|
||||
const seconds = raw ?? DEFAULT_AGENT_TIMEOUT_SECONDS;
|
||||
return Math.max(seconds, 1);
|
||||
}
|
||||
|
||||
export function resolveAgentTimeoutMs(opts: {
|
||||
cfg?: ClawdbotConfig;
|
||||
overrideMs?: number | null;
|
||||
overrideSeconds?: number | null;
|
||||
minMs?: number;
|
||||
}): number {
|
||||
const minMs = Math.max(normalizeNumber(opts.minMs) ?? 1, 1);
|
||||
const defaultMs = resolveAgentTimeoutSeconds(opts.cfg) * 1000;
|
||||
const overrideMs = normalizeNumber(opts.overrideMs);
|
||||
if (overrideMs !== undefined) {
|
||||
if (overrideMs <= 0) return defaultMs;
|
||||
return Math.max(overrideMs, minMs);
|
||||
}
|
||||
const overrideSeconds = normalizeNumber(opts.overrideSeconds);
|
||||
if (overrideSeconds !== undefined) {
|
||||
if (overrideSeconds <= 0) return defaultMs;
|
||||
return Math.max(overrideSeconds * 1000, minMs);
|
||||
}
|
||||
return Math.max(defaultMs, minMs);
|
||||
}
|
||||
Reference in New Issue
Block a user