model switch also switches provider (gpt models were sent to the Claude API)
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes committed 2026-10-01 12:15:39 +00:00
1 parent 658ada46f7
commit ad73e8f1c2
7 files changed
+171 -21

No files matched your search

+17 -1
View File
@@ -324,6 +324,11 @@ async fn main() -> Result<()> {
.or(kinds.first().copied())
.unwrap_or(Kind::Claude);
let models = catalog(&kinds).await;
// an explicit model picks its provider unless --provider says otherwise
let kind = match (&cli.provider, cli.model.as_deref().or(cfg.model.as_deref())) {
(None, Some(m)) => hx_ai::models::kind_of(&models, m).unwrap_or(kind),
_ => kind,
};
let model = cli.model.or(cfg.model).unwrap_or_else(|| {
match kind {
Kind::Claude => cfg.claude_model.clone(),
@@ -455,7 +460,18 @@ async fn main() -> Result<()> {
}
let specs = command_specs(&mcp, &cwd, &models, &kinds);
if cli.mode == Mode::Rpc {
let r = rpc::serve(agent, abort, specs, hx_tui::project_files(&cwd), dir).await;
let r = rpc::serve(
agent,
abort,
rpc::Ctx {
specs,
files: hx_tui::project_files(&cwd),
session_dir: dir,
models: models.clone(),
make_provider: provider,
},
)
.await;
mgr.shutdown().await;
return r;
}
+28 -10
View File
@@ -47,13 +47,22 @@ fn reply(id: &Value, r: Result<Value, String>) {
/// `state`, `messages`, `fork {id}`, `clear`, `set_model {model}`, `compact`,
/// `complete {line, cursor?}` (cursor = byte offset, default end), `sessions {scope?: project|all}`,
/// `new`, `resume {path}`. One prompt at a time.
pub async fn serve(
mut agent: Agent,
abort: AbortHandle,
specs: Vec<hx_core::command::CmdSpec>,
files: Vec<String>,
session_dir: std::path::PathBuf,
) -> Result<()> {
pub struct Ctx {
pub specs: Vec<hx_core::command::CmdSpec>,
pub files: Vec<String>,
pub session_dir: std::path::PathBuf,
pub models: Vec<hx_ai::models::ModelInfo>,
pub make_provider: fn(hx_ai::auth::Kind) -> hx_ai::Result<Arc<dyn hx_ai::Provider>>,
}
pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()> {
let Ctx {
specs,
files,
session_dir,
models,
make_provider,
} = cx;
agent.bus.add(Notify);
let agent = Arc::new(Mutex::new(agent));
let busy = Arc::new(std::sync::atomic::AtomicBool::new(false));
@@ -136,10 +145,19 @@ pub async fn serve(
.map(|_| json!({}))
.map_err(|e| e.to_string()),
"set_model" => match p["model"].as_str() {
Some(m) => {
a.model = m.into();
Ok(json!({"model": m}))
// switch provider too when the model belongs to another one
Some(m) => match hx_ai::models::kind_of(&models, m) {
Some(k) => make_provider(k).map(|prov| {
a.provider = prov;
a.model = m.into();
json!({"model": m, "provider": format!("{k:?}").to_lowercase()})
}),
None => {
a.model = m.into();
Ok(json!({"model": m}))
}
}
.map_err(|e| e.to_string()),
None => Err("params.model required".into()),
},
"compact" => a