Skip to main content

kaizen/shell/
proxy.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2//! `kaizen proxy run` — see `docs/llm-proxy.md`.
3
4use crate::core::config;
5use crate::proxy::ProxyRunOptions;
6use anyhow::Result;
7use std::path::Path;
8use std::sync::Arc;
9
10/// Run the local LLM forwarder until `Ctrl+C` or error.
11pub fn cmd_proxy_run(
12    workspace: Option<&Path>,
13    listen: Option<String>,
14    upstream: Option<String>,
15) -> Result<()> {
16    let dir = workspace
17        .map(std::path::Path::to_path_buf)
18        .unwrap_or_else(|| std::env::current_dir().expect("cwd"));
19    let dir = std::fs::canonicalize(&dir).unwrap_or(dir);
20    let cfg = config::load(&dir)?;
21    let o = Arc::new(ProxyRunOptions::from_config_with_overrides(
22        &cfg, listen, upstream,
23    ));
24    let rt = tokio::runtime::Builder::new_multi_thread()
25        .enable_all()
26        .build()?;
27    rt.block_on(async move { crate::proxy::run(o, dir, cfg).await })
28}