(value: unknown)
| 14660 | } |
| 14661 | |
| 14662 | function parseAgentLoopPolicy(value: unknown): AgentJobLoopPolicy { |
| 14663 | const parsed = value && typeof value === 'object' && !Array.isArray(value) |
| 14664 | ? value as Record<string, unknown> |
| 14665 | : {}; |
| 14666 | const defaults = buildDefaultAgentLoopPolicy(); |
| 14667 | return { |
| 14668 | maxAttempts: normalizeAgentLoopBudget(parsed.maxAttempts ?? parsed.max_attempts, defaults.maxAttempts ?? null), |
| 14669 | maxTurns: normalizeAgentLoopBudget(parsed.maxTurns ?? parsed.max_turns, defaults.maxTurns ?? null), |
| 14670 | maxCycles: normalizeAgentLoopBudget(parsed.maxCycles ?? parsed.max_cycles, defaults.maxCycles ?? null), |
| 14671 | maxNoProgressCycles: normalizeAgentLoopBudget( |
| 14672 | parsed.maxNoProgressCycles ?? parsed.max_no_progress_cycles, |
| 14673 | defaults.maxNoProgressCycles ?? null, |
| 14674 | ), |
| 14675 | }; |
| 14676 | } |
| 14677 | |
| 14678 | function normalizeAgentLoopBudget(value: unknown, fallback: number | null): number | null { |
| 14679 | if (value === null || value === undefined || value === '') { |
no test coverage detected