tl_cli/cli/commands/
chat.rs

1//! Chat mode command handler.
2
3use anyhow::Result;
4
5use super::load_config;
6use crate::chat::{ChatSession, SessionConfig};
7use crate::config::{ResolveOptions, resolve_config};
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    /// Translation style.
18    pub style: Option<String>,
19}
20
21/// Runs the interactive chat mode.
22///
23/// Starts a REPL-style session for translating text interactively.
24pub async fn run_chat(options: ChatOptions) -> Result<()> {
25    let (_manager, config_file) = load_config()?;
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(resolved, config_file.styles.clone());
37
38    let mut session = ChatSession::new(session_config);
39    session.run().await
40}