tl_cli/cli/commands/
chat.rs

1//! Chat mode command handler.
2
3use anyhow::Result;
4
5use super::translate::{TranslateOptions, resolve_config};
6use crate::chat::{ChatSession, SessionConfig};
7use crate::config::ConfigManager;
8
9/// Options for the chat command.
10pub struct ChatOptions {
11    /// Target language code.
12    pub to: Option<String>,
13    /// Provider name.
14    pub provider: Option<String>,
15    /// Model name.
16    pub model: Option<String>,
17}
18
19/// Runs the interactive chat mode.
20///
21/// Starts a REPL-style session for translating text interactively.
22pub async fn run_chat(options: ChatOptions) -> Result<()> {
23    let manager = ConfigManager::new()?;
24    let config_file = manager.load_or_default();
25
26    // Reuse resolve_config from translate
27    let translate_options = TranslateOptions {
28        file: None,
29        to: options.to,
30        provider: options.provider,
31        model: options.model,
32        no_cache: false,
33        write: false,
34    };
35
36    let resolved = resolve_config(&translate_options, &config_file)?;
37
38    let session_config = SessionConfig::new(
39        resolved.provider_name,
40        resolved.endpoint,
41        resolved.model,
42        resolved.api_key,
43        resolved.target_language,
44    );
45
46    let mut session = ChatSession::new(session_config);
47    session.run().await
48}