(config?: ToolLoopDetectionConfig)
| 62 | } |
| 63 | |
| 64 | function resolveLoopDetectionConfig(config?: ToolLoopDetectionConfig): ResolvedLoopDetectionConfig { |
| 65 | let warningThreshold = asPositiveInt( |
| 66 | config?.warningThreshold, |
| 67 | DEFAULT_LOOP_DETECTION_CONFIG.warningThreshold, |
| 68 | ); |
| 69 | let criticalThreshold = asPositiveInt( |
| 70 | config?.criticalThreshold, |
| 71 | DEFAULT_LOOP_DETECTION_CONFIG.criticalThreshold, |
| 72 | ); |
| 73 | let globalCircuitBreakerThreshold = asPositiveInt( |
| 74 | config?.globalCircuitBreakerThreshold, |
| 75 | DEFAULT_LOOP_DETECTION_CONFIG.globalCircuitBreakerThreshold, |
| 76 | ); |
| 77 | |
| 78 | if (criticalThreshold <= warningThreshold) { |
| 79 | criticalThreshold = warningThreshold + 1; |
| 80 | } |
| 81 | if (globalCircuitBreakerThreshold <= criticalThreshold) { |
| 82 | globalCircuitBreakerThreshold = criticalThreshold + 1; |
| 83 | } |
| 84 | |
| 85 | return { |
| 86 | enabled: config?.enabled ?? DEFAULT_LOOP_DETECTION_CONFIG.enabled, |
| 87 | historySize: asPositiveInt(config?.historySize, DEFAULT_LOOP_DETECTION_CONFIG.historySize), |
| 88 | warningThreshold, |
| 89 | criticalThreshold, |
| 90 | globalCircuitBreakerThreshold, |
| 91 | detectors: { |
| 92 | genericRepeat: |
| 93 | config?.detectors?.genericRepeat ?? DEFAULT_LOOP_DETECTION_CONFIG.detectors.genericRepeat, |
| 94 | knownPollNoProgress: |
| 95 | config?.detectors?.knownPollNoProgress ?? |
| 96 | DEFAULT_LOOP_DETECTION_CONFIG.detectors.knownPollNoProgress, |
| 97 | pingPong: config?.detectors?.pingPong ?? DEFAULT_LOOP_DETECTION_CONFIG.detectors.pingPong, |
| 98 | }, |
| 99 | }; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Hash a tool call for pattern matching. |
no test coverage detected