ai: claude_cli provider (official claude binary, subscription billing)
This commit is contained in:
1 parent
bd9671804b
commit
769effc8b0
7 files changed
+293
-1
No files matched your search
@@ -117,6 +117,8 @@ struct Config {
|
||||
provider: Option<Kind>,
|
||||
model: Option<String>,
|
||||
claude_model: Option<String>,
|
||||
/// Run Claude through the official `claude` CLI (subscription billing). Value = extra `claude` args, `[]` for none.
|
||||
claude_cli: Option<Vec<String>>,
|
||||
/// OpenAI-compatible endpoint (Ollama, vLLM, LM Studio, OpenRouter, ...), provider "custom".
|
||||
openai_compat: Option<hx_ai::openai_compat::Config>,
|
||||
codex_model: Option<String>,
|
||||
@@ -193,6 +195,7 @@ impl Config {
|
||||
provider: o.provider.or(c.provider),
|
||||
model: o.model.or(c.model),
|
||||
claude_model: o.claude_model.or(c.claude_model),
|
||||
claude_cli: o.claude_cli.or(c.claude_cli),
|
||||
openai_compat: o.openai_compat.or(c.openai_compat),
|
||||
codex_model: o.codex_model.or(c.codex_model),
|
||||
compact_at: o.compact_at.or(c.compact_at),
|
||||
@@ -258,6 +261,7 @@ fn logged_in() -> Vec<Kind> {
|
||||
.into_iter()
|
||||
.filter(|k| match k {
|
||||
Kind::Custom => COMPAT.get().is_some(),
|
||||
Kind::Claude if CLAUDE_CLI.get().is_some() => true,
|
||||
k => hx_ai::auth::Auth::load(*k).is_ok(),
|
||||
})
|
||||
.collect()
|
||||
@@ -346,9 +350,19 @@ fn pricing(model: &str) -> Option<hx_ai::Pricing> {
|
||||
|
||||
/// `[openai_compat]` from config, set once at startup.
|
||||
static COMPAT: std::sync::OnceLock<hx_ai::openai_compat::Config> = std::sync::OnceLock::new();
|
||||
/// `claude_cli` from config: extra args for the `claude` binary.
|
||||
static CLAUDE_CLI: std::sync::OnceLock<Vec<String>> = std::sync::OnceLock::new();
|
||||
|
||||
fn provider(k: Kind) -> hx_ai::Result<Arc<dyn Provider>> {
|
||||
Ok(match k {
|
||||
Kind::Claude if CLAUDE_CLI.get().is_some() => {
|
||||
let c =
|
||||
hx_ai::claude_cli::ClaudeCli::new(CLAUDE_CLI.get().cloned().unwrap_or_default());
|
||||
Arc::new(match std::env::current_exe() {
|
||||
Ok(e) => c.with_mcp(e.to_string_lossy().into(), vec!["mcp-serve".into()]),
|
||||
Err(_) => c,
|
||||
})
|
||||
}
|
||||
Kind::Claude => {
|
||||
let a = Anthropic::login_default()?;
|
||||
Arc::new(match std::env::var("HX_BASE_URL") {
|
||||
@@ -615,6 +629,9 @@ async fn main() -> Result<()> {
|
||||
if let Some(oc) = cfg.openai_compat.clone() {
|
||||
let _ = COMPAT.set(oc);
|
||||
}
|
||||
if let Some(a) = cfg.claude_cli.clone() {
|
||||
let _ = CLAUDE_CLI.set(a);
|
||||
}
|
||||
// MCP servers connect while the model catalog loads
|
||||
let mcp_cfg = hx_mcp::config::load(&context::hx_home(), &cwd).map_err(anyhow::Error::msg)?;
|
||||
let mcp = hx_mcp::Hub::spawn(mcp_cfg);
|
||||
|
||||
Reference in new issue
Block a user