tl_cli/cli/commands/
chat.rs

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