(options: SubagentRunOptions)
| 387 | } |
| 388 | |
| 389 | async run(options: SubagentRunOptions): Promise<SubagentRunResult> { |
| 390 | const models = [options.model, ...(options.fallbackModels ?? [])].filter( |
| 391 | (model): model is string => typeof model === "string" && model.length > 0, |
| 392 | ); |
| 393 | const attempts = models.length > 0 ? models : [undefined]; |
| 394 | let lastResult: SubagentRunResult | null = null; |
| 395 | for (let index = 0; index < attempts.length; index += 1) { |
| 396 | const model = attempts[index]; |
| 397 | const attemptOptions = { |
| 398 | ...options, |
| 399 | model, |
| 400 | fallbackModels: undefined, |
| 401 | }; |
| 402 | const result = await this.runOnce(attemptOptions); |
| 403 | if (result.ok) return result; |
| 404 | lastResult = result; |
| 405 | if (index >= attempts.length - 1 || !isFallbackEligible(result.reason)) { |
| 406 | return result; |
| 407 | } |
| 408 | } |
| 409 | return ( |
| 410 | lastResult ?? this.runOnce({ ...options, fallbackModels: undefined }) |
| 411 | ); |
| 412 | } |
| 413 | |
| 414 | private async runOnce( |
| 415 | options: SubagentRunOptions, |
no test coverage detected