fix: provider-aware model routing with fallback visibility

- Extract createClientFromConfig() to dispatch on provider field instead
  of hardcoding all tiers as AnthropicClient
- Add fallback/fallbackReason metadata to ChatResponse and ChatStreamEvent
  so callers know when a fallback model was used
- Enhance doctor check to report full model stack and warn on missing
  API keys for cloud providers
- Log fallback warnings in NativeAgent and display them in TUI
- Support tier names and local_providers entries in fallback_chain
- Add 8 tests for createClientFromConfig covering all provider types
This commit is contained in:
William Valentin
2026-02-06 09:58:56 -08:00
parent c9b1c607d5
commit e4b7f96d33
9 changed files with 334 additions and 56 deletions
+8
View File
@@ -79,6 +79,10 @@ export class NativeAgent {
const response = await this.chatWithRouter(request);
if (response.fallback) {
console.warn(`[Flynn] ${response.fallbackReason}`);
}
const assistantMsg: Message = { role: 'assistant', content: response.content };
this.addToHistory(assistantMsg);
@@ -106,6 +110,10 @@ export class NativeAgent {
const response = await this.chatWithRouter(request);
if (response.fallback) {
console.warn(`[Flynn] ${response.fallbackReason}`);
}
// If the model didn't request tool use, we're done
if (response.stopReason !== 'tool_use' || !response.toolCalls?.length) {
const assistantMsg: Message = { role: 'assistant', content: response.content };