Read-only mirror of github.com/ondeinference/ed.
Mirrored from https://github.com/ondeinference/ed.git
Synced Nov 23, 01:00 UTC
Release 1.3.5: setup picks a model the key can call
If an app isn't allowed the default tier, Onde Cloud answers that model with 503 "not available" and `--setup` (and the Tauri `set_api_key`) failed even though the key was fine. `LlmClient::verify_key` now lists /models when the configured model is refused, pings the first listed model and returns it. The CLI and the Tauri client write that model as <PREFIX>_MODEL. `check_auth` keeps its signature and wraps `verify_key`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Seto Elkahfi committed
Oct 29, 2026 at 19:03 UTC
eede53634f730b5240cde27f2a289579dfe72320
5 files changed
+160
-37
Cargo.lock
+9
-9
@@ -1995,7 +1995,7 @@ checksum = "e1d926b4d407d372f141f93bb444696142c29d32962ccbd3531117cf3aa0bfa9"
1995
1996
[[package]]
1997
name = "ed-acp"
1998
-version = "1.3.4"
1998
+version = "1.3.5"
1999
dependencies = [
2000
"agent-client-protocol",
2001
"anyhow",
@@ -2018,7 +2018,7 @@ dependencies = [
2018
2019
[[package]]
2020
name = "ed-acp-tauri"
2021
-version = "1.3.4"
2021
+version = "1.3.5"
2022
dependencies = [
2023
"agent-client-protocol",
2024
"ed-acp",
@@ -2034,7 +2034,7 @@ dependencies = [
2034
2035
[[package]]
2036
name = "ed-acp-testkit"
2037
-version = "1.3.4"
2037
+version = "1.3.5"
2038
dependencies = [
2039
"serde_json",
2040
"tokio",
@@ -2043,7 +2043,7 @@ dependencies = [
2043
2044
[[package]]
2045
name = "ed-acp-tui"
2046
-version = "1.3.4"
2046
+version = "1.3.5"
2047
dependencies = [
2048
"agent-client-protocol",
2049
"anyhow",
@@ -2055,7 +2055,7 @@ dependencies = [
2055
2056
[[package]]
2057
name = "ed-agent"
2058
-version = "1.3.4"
2058
+version = "1.3.5"
2059
dependencies = [
2060
"async-trait",
2061
"futures-core",
@@ -2069,7 +2069,7 @@ dependencies = [
2069
2070
[[package]]
2071
name = "ed-agent-ffi"
2072
-version = "1.3.4"
2072
+version = "1.3.5"
2073
dependencies = [
2074
"async-trait",
2075
"cc",
@@ -2084,7 +2084,7 @@ dependencies = [
2084
2085
[[package]]
2086
name = "ed-agent-tauri"
2087
-version = "1.3.4"
2087
+version = "1.3.5"
2088
dependencies = [
2089
"async-trait",
2090
"ed-agent",
@@ -2098,7 +2098,7 @@ dependencies = [
2098
2099
[[package]]
2100
name = "ed-mcp"
2101
-version = "1.3.4"
2101
+version = "1.3.5"
2102
dependencies = [
2103
"agent-client-protocol",
2104
"anyhow",
@@ -2117,7 +2117,7 @@ dependencies = [
2117
2118
[[package]]
2119
name = "ed-onde-account"
2120
-version = "1.3.4"
2120
+version = "1.3.5"
2121
dependencies = [
2122
"axum",
2123
"reqwest 0.13.5",
Cargo.toml
+8
-8
@@ -16,7 +16,7 @@ members = [
16
# Shared across every crate in the workspace so a release moves one number.
17
# `sync-version` tooling (see the Makefile) reads these.
18
[workspace.package]
19
-version = "1.3.4"
19
+version = "1.3.5"
20
edition = "2021"
21
rust-version = "1.94"
22
license = "MIT OR Apache-2.0"
@@ -59,13 +59,13 @@ directories = "6"
59
base64 = "0.23"
60
61
# Internal
62
-ed-agent = { version = "1.3.4", path = "crates/ed-agent" }
63
-ed-mcp = { version = "1.3.4", path = "crates/ed-mcp" }
64
-ed-acp = { version = "1.3.4", path = "crates/ed-acp" }
65
-ed-acp-tauri = { version = "1.3.4", path = "crates/ed-acp-tauri" }
66
-ed-acp-tui = { version = "1.3.4", path = "crates/ed-acp-tui" }
67
-ed-acp-testkit = { version = "1.3.4", path = "crates/ed-acp-testkit" }
68
-ed-onde-account = { version = "1.3.4", path = "crates/ed-onde-account" }
62
+ed-agent = { version = "1.3.5", path = "crates/ed-agent" }
63
+ed-mcp = { version = "1.3.5", path = "crates/ed-mcp" }
64
+ed-acp = { version = "1.3.5", path = "crates/ed-acp" }
65
+ed-acp-tauri = { version = "1.3.5", path = "crates/ed-acp-tauri" }
66
+ed-acp-tui = { version = "1.3.5", path = "crates/ed-acp-tui" }
67
+ed-acp-testkit = { version = "1.3.5", path = "crates/ed-acp-testkit" }
68
+ed-onde-account = { version = "1.3.5", path = "crates/ed-onde-account" }
69
70
# gemm-common (via candle, via onde) depends on sysctl for every
71
# `target_vendor = "apple"`, but sysctl 0.6.0 only has a `sys` module behind
crates/ed-acp-tauri/src/client.rs
+12
-4
@@ -102,8 +102,10 @@ pub fn status(host: &HostConfig) -> AgentStatus {
102
/// What `<agent> --setup` does for Onde Inference, minus the terminal: check the key with Onde
103
/// Cloud, then write it to the agent's `env` file (mode 0600). With a `model` it is written as
104
/// `<PREFIX>_MODEL` beside the key and used for the check, so the agent doesn't fall back to a
105
-/// default tier the key isn't allowed to call. In the App Store sandbox that file lives in
106
-/// the app's container, so a key stored by the command-line agent isn't shared.
105
+/// default tier the key isn't allowed to call; without one, or when the key can't call it,
106
+/// the model the check passed with is written instead (see `LlmClient::verify_key`). In the App
107
+/// Store sandbox that file lives in the app's container, so a key stored by the command-line
108
+/// agent isn't shared.
109
pub async fn set_api_key(host: &HostConfig, key: &str, model: Option<&str>) -> Result<(), String> {
110
let info = host.info();
111
let key = key.trim();
@@ -124,10 +126,16 @@ pub async fn set_api_key(host: &HostConfig, key: &str, model: Option<&str>) -> R
126
.map(|(_, v)| v.clone())
127
.or_else(|| std::env::var(name).ok())
128
});
127
- LlmClient::new(config)
128
- .check_auth()
129
+ let configured = config.model.clone();
130
+ let verified = LlmClient::new(config)
131
+ .verify_key()
132
.await
133
.map_err(|e| format!("Onde Cloud rejected the key: {e:#}"))?;
134
+ if verified != configured {
135
+ let model_var = info.env.var("MODEL");
136
+ vars.retain(|(k, _)| *k != model_var);
137
+ vars.push((model_var, verified));
138
+ }
139
140
let dir = info
141
.env
crates/ed-acp/src/cli.rs
+7
-2
@@ -142,8 +142,13 @@ pub async fn setup(info: &AgentInfo) -> anyhow::Result<()> {
142
});
143
print!("Verifying the key with {}… ", provider.display_name());
144
std::io::stdout().flush()?;
145
- match LlmClient::new(config).check_auth().await {
146
- Ok(()) => println!("OK"),
145
+ let configured = config.model.clone();
146
+ match LlmClient::new(config).verify_key().await {
147
+ Ok(model) if model != configured => {
148
+ println!("OK\n{configured} isn't available to this key; using {model}.");
149
+ vars.push((info.env.var("MODEL"), model));
150
+ }
151
+ Ok(_) => println!("OK"),
152
Err(e) => anyhow::bail!("\nKey check failed: {e:#}\nNothing was written."),
153
}
154
crates/ed-acp/src/llm.rs
+124
-14
@@ -442,6 +442,92 @@ mod tests {
442
assert_eq!(parsed.data[0].owned_by.as_deref(), Some("onde"));
443
assert_eq!(parsed.data[1].owned_by, None);
444
}
445
+
446
+ /// An Onde Cloud stand-in for one app allowed only `onde-air`: `good:key` is accepted,
447
+ /// other keys get 401, and any other model gets 503, as Onde Cloud answers a model outside
448
+ /// the app's allowed set. Returns the base URL.
449
+ async fn app_limited_to_onde_air() -> String {
450
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
451
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
452
+ let addr = listener.local_addr().unwrap();
453
+ tokio::spawn(async move {
454
+ loop {
455
+ let Ok((mut sock, _)) = listener.accept().await else {
456
+ return;
457
+ };
458
+ tokio::spawn(async move {
459
+ let mut buf = Vec::new();
460
+ let mut chunk = [0u8; 4096];
461
+ // Headers, then as much body as Content-Length says.
462
+ let request = loop {
463
+ let n = sock.read(&mut chunk).await.unwrap_or(0);
464
+ if n == 0 {
465
+ return;
466
+ }
467
+ buf.extend_from_slice(&chunk[..n]);
468
+ let text = String::from_utf8_lossy(&buf).to_string();
469
+ if let Some(end) = text.find("\r\n\r\n") {
470
+ let len = text[..end]
471
+ .lines()
472
+ .find_map(|l| {
473
+ l.to_ascii_lowercase()
474
+ .strip_prefix("content-length:")
475
+ .map(|v| v.trim().parse::<usize>().unwrap_or(0))
476
+ })
477
+ .unwrap_or(0);
478
+ if buf.len() >= end + 4 + len {
479
+ break text;
480
+ }
481
+ }
482
+ };
483
+ let authorized = request.contains("Bearer good:key");
484
+ let (status, body) = if !authorized {
485
+ ("401 Unauthorized", r#"{"error":{}}"#)
486
+ } else if request.starts_with("GET /v1/models") {
487
+ ("200 OK", r#"{"object":"list","data":[{"id":"onde-air"}]}"#)
488
+ } else if request.contains(r#""model":"onde-air""#) {
489
+ ("200 OK", r#"{"choices":[]}"#)
490
+ } else {
491
+ (
492
+ "503 Service Unavailable",
493
+ r#"{"error":{"message":"model onde-kkk is not available"}}"#,
494
+ )
495
+ };
496
+ let reply = format!(
497
+ "HTTP/1.1 {status}\r\ncontent-type: application/json\r\n\
498
+ content-length: {}\r\nconnection: close\r\n\r\n{body}",
499
+ body.len()
500
+ );
501
+ let _ = sock.write_all(reply.as_bytes()).await;
502
+ });
503
+ }
504
+ });
505
+ format!("http://{addr}/v1")
506
+ }
507
+
508
+ fn client(base_url: &str, key: &str, model: &str) -> LlmClient {
509
+ LlmClient::new(LlmConfig {
510
+ provider: Provider::Onde,
511
+ base_url: base_url.to_string(),
512
+ api_key: Some(key.to_string()),
513
+ model: model.to_string(),
514
+ })
515
+ }
516
+
517
+ #[tokio::test]
518
+ async fn verify_key_falls_back_to_a_model_the_app_allows() {
519
+ let url = app_limited_to_onde_air().await;
520
+ // Regression: a new app without the default tier failed setup with exit code 1.
521
+ let fallback = client(&url, "good:key", DEFAULT_MODEL).verify_key().await;
522
+ assert_eq!(fallback.unwrap(), "onde-air");
523
+ let allowed = client(&url, "good:key", "onde-air").verify_key().await;
524
+ assert_eq!(allowed.unwrap(), "onde-air");
525
+ let err = client(&url, "bad:key", DEFAULT_MODEL)
526
+ .verify_key()
527
+ .await
528
+ .unwrap_err();
529
+ assert!(err.to_string().contains("rejected the API key"), "{err:#}");
530
+ }
531
}
532
533
#[derive(Debug, Clone, Default)]
@@ -594,15 +680,48 @@ impl LlmClient {
680
/// Verify the configured key with a minimal chat completion.
681
/// Returns `Err` when no key is set, the key is rejected, or the endpoint is unreachable.
682
pub async fn check_auth(&self) -> Result<()> {
683
+ self.verify_key().await.map(drop)
684
+ }
685
+
686
+ /// [`Self::check_auth`], returning the model the check passed with: the configured one,
687
+ /// unless the endpoint refuses it while listing others for this key. Onde Cloud answers a
688
+ /// model outside an app's allowed set with 503 "not available", so a new app limited to,
689
+ /// say, `onde-air` would otherwise fail setup on the default tier. Then the first listed
690
+ /// model is tried and returned, for the caller to store as `<PREFIX>_MODEL`.
691
+ pub async fn verify_key(&self) -> Result<String> {
692
let provider = self.config.provider;
693
+ let model = &self.config.model;
694
if provider == Provider::Local {
599
- return Ok(());
695
+ return Ok(model.clone());
696
}
697
let Some(key) = &self.config.api_key else {
698
bail!("no {} configured", provider.key_var());
699
};
700
+ let (status, text) = self.ping(key, model).await?;
701
+ if status.is_success() {
702
+ return Ok(model.clone());
703
+ }
704
+ if matches!(status.as_u16(), 401 | 403) {
705
+ bail!(
706
+ "{} rejected the API key ({status})",
707
+ provider.display_name()
708
+ );
709
+ }
710
+ // The key got past authentication; the model may be what was refused.
711
+ if let Ok(models) = self.models().await
712
+ && !models.iter().any(|m| &m.id == model)
713
+ && let Some(other) = models.first()
714
+ && self.ping(key, &other.id).await?.0.is_success()
715
+ {
716
+ return Ok(other.id.clone());
717
+ }
718
+ bail!("{} returned {status}: {text}", provider.display_name());
719
+ }
720
+
721
+ /// A one-token, non-streaming chat completion with `model`: its status and body.
722
+ async fn ping(&self, key: &str, model: &str) -> Result<(reqwest::StatusCode, String)> {
723
let body = json!({
605
- "model": self.config.model,
724
+ "model": model,
725
"messages": [{ "role": "user", "content": "ping" }],
726
"max_tokens": 1,
727
"stream": false,
@@ -614,19 +733,10 @@ impl LlmClient {
733
.bearer_auth(key)
734
.send()
735
.await
617
- .with_context(|| format!("reaching {}", provider.display_name()))?;
736
+ .with_context(|| format!("reaching {}", self.config.provider.display_name()))?;
737
let status = resp.status();
619
- if matches!(status.as_u16(), 401 | 403) {
620
- bail!(
621
- "{} rejected the API key ({status})",
622
- provider.display_name()
623
- );
624
- }
625
- if !status.is_success() {
626
- let text = resp.text().await.unwrap_or_default();
627
- bail!("{} returned {status}: {text}", provider.display_name());
628
- }
629
- Ok(())
738
+ let text = resp.text().await.unwrap_or_default();
739
+ Ok((status, text))
740
}
741
742
/// List the models the configured endpoint serves (`GET {base_url}/models`).