Files
owlen/crates/app/ui/src/lib.rs
vikingowl f97bd44f05 feat(engine): Implement dynamic provider/model switching
Add shared ProviderManager architecture for runtime provider/model switching
between TUI and Engine:

Core Architecture:
- Add SwitchProvider and SwitchModel messages to UserAction enum
- Create run_engine_loop_dynamic() with shared ProviderManager
- Add ClientSource enum to AgentManager (Fixed vs Dynamic)
- Implement get_client() that resolves provider at call time

TUI Integration:
- Add ProviderMode::Shared variant for shared manager
- Add with_shared_provider_manager() constructor
- Update switch_provider/set_current_model for shared mode
- Fix /model command to update shared ProviderManager (was only
  updating local TUI state, not propagating to engine)
- Fix /provider command to use switch_provider()

Infrastructure:
- Wire main.rs to create shared ProviderManager for both TUI and engine
- Add HTTP status code validation to Ollama client
- Consolidate messages.rs and state.rs into agent-core

Both TUI and Engine now share the same ProviderManager via
Arc<Mutex<>>. Provider/model changes via [1]/[2]/[3] keys, model
picker, or /model command now properly propagate to the engine.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 22:13:00 +01:00

50 lines
1.7 KiB
Rust

pub mod app;
pub mod completions;
pub mod components;
pub mod events;
pub mod formatting;
pub mod layout;
pub mod output;
pub mod provider_manager;
pub mod theme;
pub use app::TuiApp;
pub use completions::{CompletionEngine, Completion, CommandInfo};
pub use events::AppEvent;
pub use output::{CommandOutput, OutputFormat, TreeNode, ListItem};
pub use formatting::{
FormattedContent, MarkdownRenderer, SyntaxHighlighter,
format_file_path, format_tool_name, format_error, format_success, format_warning, format_info,
};
pub use provider_manager::ProviderManager;
use auth_manager::AuthManager;
use color_eyre::eyre::Result;
use std::sync::Arc;
/// Run the TUI application with a single provider (legacy mode)
pub async fn run(
client: Arc<dyn llm_core::LlmProvider>,
opts: llm_core::ChatOptions,
perms: permissions::PermissionManager,
settings: config_agent::Settings,
) -> Result<()> {
let mut app = TuiApp::new(client, opts, perms, settings)?;
app.run().await
}
/// Run the TUI application with multi-provider support and engine integration
/// Uses a shared ProviderManager for dynamic provider/model switching
pub async fn run_with_providers(
provider_manager: Arc<tokio::sync::Mutex<ProviderManager>>,
perms: permissions::PermissionManager,
settings: config_agent::Settings,
engine_tx: tokio::sync::mpsc::Sender<agent_core::messages::Message>,
shared_state: Arc<tokio::sync::Mutex<agent_core::state::AppState>>,
engine_rx: tokio::sync::mpsc::Receiver<agent_core::messages::Message>,
) -> Result<()> {
let mut app = TuiApp::with_shared_provider_manager(provider_manager, perms, settings)?;
app.set_engine(engine_tx, shared_state, engine_rx);
app.run().await
}