2026-02-08 15:01:42 +09:00
import { z } from "zod"
2026-03-17 16:31:04 +09:00
const CircuitBreakerConfigSchema = z . object ( {
2026-03-17 13:29:06 -06:00
enabled : z.boolean ( ) . optional ( ) ,
2026-03-17 16:31:04 +09:00
maxToolCalls : z.number ( ) . int ( ) . min ( 10 ) . optional ( ) ,
2026-03-18 14:32:27 +09:00
consecutiveThreshold : z.number ( ) . int ( ) . min ( 5 ) . optional ( ) ,
2026-03-17 16:31:04 +09:00
} )
2026-02-08 15:01:42 +09:00
export const BackgroundTaskConfigSchema = z . object ( {
defaultConcurrency : z.number ( ) . min ( 1 ) . optional ( ) ,
providerConcurrency : z.record ( z . string ( ) , z . number ( ) . min ( 0 ) ) . optional ( ) ,
modelConcurrency : z.record ( z . string ( ) , z . number ( ) . min ( 0 ) ) . optional ( ) ,
2026-03-11 17:46:04 +09:00
maxDepth : z.number ( ) . int ( ) . min ( 1 ) . optional ( ) ,
maxDescendants : z.number ( ) . int ( ) . min ( 1 ) . optional ( ) ,
2026-02-08 15:01:42 +09:00
/** Stale timeout in milliseconds - interrupt tasks with no activity for this duration (default: 180000 = 3 minutes, minimum: 60000 = 1 minute) */
staleTimeoutMs : z.number ( ) . min ( 60000 ) . optional ( ) ,
2026-03-12 01:14:43 +09:00
/** Timeout for tasks that never received any progress update, falling back to startedAt (default: 1800000 = 30 minutes, minimum: 60000 = 1 minute) */
2026-02-14 14:56:51 +09:00
messageStalenessTimeoutMs : z.number ( ) . min ( 60000 ) . optional ( ) ,
2026-03-27 16:06:38 +09:00
/** Absolute TTL for non-terminal tasks in milliseconds (default: 1800000 = 30 minutes, minimum: 300000 = 5 minutes). Tasks exceeding this age from their last activity (or startedAt if no progress) are pruned. */
taskTtlMs : z.number ( ) . min ( 300000 ) . optional ( ) ,
2026-03-27 15:43:01 +09:00
/** Timeout for tasks whose session has completely disappeared from the status registry (default: 60000 = 1 minute, minimum: 10000 = 10 seconds). When a session is gone (likely crashed), this shorter timeout is used instead of the normal stale timeout. */
sessionGoneTimeoutMs : z.number ( ) . min ( 10000 ) . optional ( ) ,
2026-02-27 13:54:50 +08:00
syncPollTimeoutMs : z.number ( ) . min ( 60000 ) . optional ( ) ,
2026-03-16 10:28:38 +09:00
/** Maximum tool calls per subagent task before circuit breaker triggers (default: 200, minimum: 10). Prevents runaway loops from burning unlimited tokens. */
maxToolCalls : z.number ( ) . int ( ) . min ( 10 ) . optional ( ) ,
2026-03-17 16:31:04 +09:00
circuitBreaker : CircuitBreakerConfigSchema.optional ( ) ,
2026-02-08 15:01:42 +09:00
} )
export type BackgroundTaskConfig = z . infer < typeof BackgroundTaskConfigSchema >