Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions crates/agent/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl AuthProvider for OndeAuth {

let flow = browser_auth::begin().map_err(|reason| {
error(format!(
"{reason}. Run `{} --setup` in a terminal to paste a key instead.",
"{}. Run `{} --setup` in a terminal to paste a key instead.",
capitalize(&reason),
INFO.name
))
})?;
Expand All @@ -78,9 +79,10 @@ impl AuthProvider for OndeAuth {
tracing::info!("authenticate: connected {}", describe(&grant));
Ok(())
}
// Clients such as Zed add their own "Sign-in did not complete:" lead-in.
Err(reason) => Err(error(format!(
"Sign-in did not complete ({reason}). Try again, or run `{} --setup` in a \
terminal to paste a key.",
"{}. Try again, or run `{} --setup` in a terminal to paste a key.",
capitalize(&reason),
INFO.name
))),
}
Expand Down Expand Up @@ -137,6 +139,15 @@ fn error(message: impl Into<String>) -> agent_client_protocol::Error {
agent_client_protocol::Error::new(ErrorCode::InternalError.into(), message.into())
}

/// `text` with its first character uppercased.
fn capitalize(text: &str) -> String {
let mut chars = text.chars();
match chars.next() {
Some(first) => first.to_uppercase().chain(chars).collect(),
None => String::new(),
}
}

/// Whether the endpoint accepts the key. `GET /models` checks the key without running a model,
/// so a model whose upstream is down doesn't make a good key look bad.
async fn key_is_valid(config: &LlmConfig) -> bool {
Expand Down Expand Up @@ -325,6 +336,17 @@ mod tests {
assert!(matches!(method, AuthMethod::Agent(_)));
}

#[test]
fn capitalize_uppercases_only_the_first_character() {
assert_eq!(
capitalize("the page was not opened"),
"The page was not opened"
);
assert_eq!(capitalize("Already"), "Already");
assert_eq!(capitalize("élan"), "Élan");
assert_eq!(capitalize(""), "");
}

#[test]
fn the_default_model_is_kept_when_the_app_allows_it_else_the_first_allowed() {
let default = INFO.env.default_model;
Expand Down
Loading