Skip to content
Merged
Show file tree
Hide file tree
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
401 changes: 401 additions & 0 deletions crates/elph-ai/src/auth/oauth/kilo.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions crates/elph-ai/src/auth/oauth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod callback;
mod device_code;
mod github_copilot;
mod hyper;
mod kilo;
mod kimi;
mod openai_codex;
mod openrouter;
Expand All @@ -30,6 +31,9 @@ pub use github_copilot::{
};
pub use hyper::refresh_hyper_token;
pub use hyper::{hyper_api_base_url, hyper_base_url, hyper_oauth, hyper_oauth_loader, hyper_user_agent, login_hyper};
pub use kilo::{
kilo_api_base_url, kilo_base_url, kilo_oauth, kilo_oauth_loader, kilo_org_id, login_kilo, refresh_kilo_token,
};
pub use kimi::{kimi_oauth, kimi_oauth_loader};
pub use openai_codex::{OPENAI_CODEX_BROWSER_LOGIN_METHOD, OPENAI_CODEX_DEVICE_CODE_LOGIN_METHOD};
pub use openai_codex::{login_openai_codex, login_openai_codex_device_code, openai_codex_oauth};
Expand Down
19 changes: 15 additions & 4 deletions crates/elph-ai/src/auth/oauth/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use std::sync::{Arc, LazyLock, RwLock};

use crate::auth::helpers::lazy_oauth;
use crate::auth::oauth::openai_codex_oauth_loader;
use crate::auth::oauth::{
anthropic_oauth_loader, github_copilot_oauth_loader, hyper_oauth_loader, kimi_oauth_loader,
openrouter_oauth_loader, radius_oauth_loader, xai_oauth_loader,
};
use crate::auth::oauth::{anthropic_oauth_loader, github_copilot_oauth_loader, hyper_oauth_loader};
use crate::auth::oauth::{kilo_oauth_loader, kimi_oauth_loader, openrouter_oauth_loader};
use crate::auth::oauth::{radius_oauth_loader, xai_oauth_loader};
use crate::auth::types::{AuthLoginCallbacks, ModelAuth, OAuthAuth, OAuthCredential};
use crate::models::catalog::builtin_catalog;
use crate::types::Model;
Expand Down Expand Up @@ -56,6 +55,16 @@ fn hyper_provider() -> OAuthProviderInterface {
}
}

fn kilo_provider() -> OAuthProviderInterface {
OAuthProviderInterface {
id: "kilo".to_string(),
name: "Kilo".to_string(),
auth: lazy_oauth("Kilo", kilo_oauth_loader()),
get_api_key: Arc::new(|c| c.access.clone()),
modify_models: None,
}
}

fn openai_codex_provider() -> OAuthProviderInterface {
OAuthProviderInterface {
id: "openai-codex".to_string(),
Expand All @@ -71,6 +80,7 @@ fn built_in_providers() -> Vec<OAuthProviderInterface> {
anthropic_provider(),
github_copilot_provider(),
hyper_provider(),
kilo_provider(),
openai_codex_provider(),
xai_provider(),
kimi_provider(),
Expand Down Expand Up @@ -304,6 +314,7 @@ pub fn builtin_oauth_provider_ids() -> Vec<&'static str> {
"anthropic",
"github-copilot",
"hyper",
"kilo",
"openai-codex",
"xai",
"kimi-coding",
Expand Down
35 changes: 24 additions & 11 deletions crates/elph-ai/src/providers/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::sync::Arc;

use crate::auth::env_api_key_auth;
use crate::auth::oauth::openai_codex_oauth;
use crate::auth::oauth::{
anthropic_oauth, github_copilot_oauth, hyper_api_base_url, hyper_oauth, hyper_user_agent, kimi_oauth,
};
use crate::auth::oauth::{anthropic_oauth, github_copilot_oauth};
use crate::auth::oauth::{hyper_api_base_url, hyper_oauth, hyper_user_agent};
use crate::auth::oauth::{kilo_api_base_url, kilo_oauth, kimi_oauth};
use crate::auth::{AuthResolveInput, AuthResult, ModelAuth, ProviderAuth};
use crate::models::catalog::builtin_catalog;
use crate::models::{CreateModelsOptions, CreateProviderOptions, MutableModels, Provider, ProviderApi};
Expand Down Expand Up @@ -402,6 +402,26 @@ pub fn fireworks_provider() -> Provider {
})
}

/// Kilo AI Gateway — OpenAI-compatible (https://kilo.ai/docs/gateway).
/// Base URL: https://api.kilo.ai/api/gateway · key: KILO_API_KEY (or OAuth login).
pub fn kilo_provider() -> Provider {
let mut headers = HashMap::new();
headers.insert("User-Agent".to_string(), Some("elph-kilo-provider".to_string()));
create_provider(CreateProviderOptions {
id: "kilo".to_string(),
name: Some("Kilo Gateway".to_string()),
base_url: Some(kilo_api_base_url()),
headers: Some(headers),
auth: ProviderAuth {
api_key: Some(env_api_key_auth("Kilo API key", vec!["KILO_API_KEY"])),
oauth: Some(kilo_oauth()),
},
models: builtin_catalog("kilo").as_ref().clone(),
refresh_models: None,
api: ProviderApi::Single(openai_completions_api()),
})
}

pub fn kimi_coding_provider() -> Provider {
create_provider(CreateProviderOptions {
id: "kimi-coding".to_string(),
Expand Down Expand Up @@ -602,14 +622,7 @@ pub fn builtin_providers() -> Vec<Provider> {
orca_router_provider(),
hyper_provider(),
infron_provider(),
// Kilo AI Gateway — OpenAI-compatible (https://kilo.ai/docs/gateway).
// Base URL: https://api.kilo.ai/api/gateway · key: KILO_API_KEY
simple_provider!(
"kilo",
"Kilo Gateway",
openai_completions_api,
(vec!["KILO_API_KEY"], "Kilo API key")
),
kilo_provider(),
kimi_coding_provider(),
simple_provider!(
"minimax",
Expand Down
2 changes: 1 addition & 1 deletion crates/elph-ai/tests/oauth_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn github_copilot_to_auth_falls_back_to_enterprise_then_individual() {
fn oauth_registry_lists_builtin_providers() {
let _guard = OAUTH_REGISTRY_LOCK.lock();
reset_oauth_providers();
assert_eq!(get_oauth_providers().len(), 8);
assert_eq!(get_oauth_providers().len(), 9);
for id in builtin_oauth_provider_ids() {
assert!(get_oauth_provider(id).is_some(), "missing provider {id}");
}
Expand Down
3 changes: 3 additions & 0 deletions docs/archive/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
- https://github.com/dodo-reach/pi-clarify
- https://crates.io/crates/shellflip
- https://tanmaymanojgandhi.github.io/circadia
- https://github.com/Kilo-Org/kilo-pi-provider
- https://github.com/osolmaz/pi-huggingface-oauth
- https://github.com/maxpaulus43/pi-cline
1 change: 1 addition & 0 deletions docs/porting/feature-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Mapping: `@earendil-works/pi-ai` → `crates/elph-ai`, `@earendil-works/pi-agent
| OpenAI Codex OAuth | `auth/oauth/openai-codex-oauth.ts` | `src/auth/oauth/openai_codex.rs` | **[Parity]** |
| GitHub Copilot OAuth | `auth/oauth/github-copilot-oauth.ts` | `src/auth/oauth/` (via `github_copilot_oauth()`) | **[Parity]** |
| Hyper OAuth (Elph-only) | — | `src/auth/oauth/hyper.rs` | **[Elph delta]** |
| Kilo OAuth (device code + org) | `auth/oauth/kilo.ts` (kilo-pi-provider) | `src/auth/oauth/kilo.rs` | **[Elph delta]** |
| Kimi Code OAuth | v0.82.0 | `src/auth/oauth/kimi.rs` | **[Parity]** |
| OpenRouter OAuth PKCE | v0.82.0 | `src/auth/oauth/openrouter.rs` | **[Parity]** |
| Radius OAuth gateway | `auth/oauth/radius.ts` | `src/auth/oauth/radius.rs` | **[Parity]** |
Expand Down
1 change: 1 addition & 0 deletions docs/porting/pi-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ Initial gap audit.
## Elph-only

- Hyper provider + OAuth (`providers/`, `models/hyper.json`, `auth/oauth/hyper.rs`)
- Kilo provider OAuth (device code + org selection, `auth/oauth/kilo.rs`, ported from `Kilo-Org/kilo-pi-provider`)
- models.dev catalog pipeline (`bin/generate_models/`: `models_dev`, `provider_sources`, `thinking_map`, …)
- OpenAI-compat gateway hardening + tool schema sanitize for non-standard gateways
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# rustup target add wasm32-unknown-unknown

[toolchain]
channel = "1.97.0"
channel = "1.97"
profile = "minimal"
components = ["clippy", "rustfmt", "rust-analysis", "rust-analyzer"]
# targets = [
# "aarch64-apple-darwin",
Expand Down