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
4 changes: 3 additions & 1 deletion .agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ cargo clippy --all-targets -- -D warnings
cargo fmt -- --check
```

The build **requires** these env vars (read from `.env` via `build.rs`): `ONDE_APP_ID`, `ONDE_APP_SECRET`, `GRESIQ_API_KEY`, `GRESIQ_API_SECRET`. `HF_TOKEN` is optional. They are baked in at compile time via `env!(...)` in `src/app.rs`. Changing `.env` triggers a full rebuild.
`build.rs` reads these env vars (from `.env` or the environment) and bakes them in at compile time with `env!(...)` in `src/config.rs`: `ONDE_APP_ID`, `ONDE_APP_SECRET`, `GRESIQ_API_KEY`, `GRESIQ_API_SECRET`, and the optional `HF_TOKEN`. Changing `.env` triggers a full rebuild.

They are optional. A build without them (a contributor's checkout, `cargo install`) still fine-tunes, merges, exports and evaluates, and `config::is_connected()` is false, so sign-in, publishing and app assignment answer with `config::NOT_CONNECTED`. Official builds must carry them, so the release workflows set `ONDE_REQUIRE_CREDENTIALS=1`, which makes a missing value fail the build. Any new cloud entry point has to check `is_connected()` (or go through `gresiq.rs`, which does).

On macOS, candle's `metal` + `accelerate` features are added automatically. **Fine-tuning always runs on CPU** — Metal's backward pass in candle 0.10.2 produces corrupt gradients (1e6–1e29 in magnitude, where CPU gives ~40–65 for identical losses). Use `ONDE_FINETUNE_METAL=1` only to test newer candle versions, and verify with `ONDE_FINETUNE_GRAD_DEBUG=1` (per-step loss/max_abs/norm).

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ concurrency:

env:
CARGO_TERM_COLOR: always
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-desktop-direct.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
permissions:
contents: write
env:
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-desktop-macos-appstore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
runs-on: macos-26
timeout-minutes: 120
env:
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ permissions:
env:
PROJECT_NAME: onde
CARGO_TERM_COLOR: always
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ permissions:

env:
CARGO_TERM_COLOR: always
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ env:
CARGO_TERM_COLOR: always
DOTNET_VERSION: 8.0.x
NUGET_PACKAGE_ID: Onde.Cli
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ permissions:

env:
CARGO_TERM_COLOR: always
# A release must never ship without the credentials, so a missing one fails the build.
ONDE_REQUIRE_CREDENTIALS: "1"
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ cargo install onde-cli
```

More ways, including pip/uv, .NET, Dart pub, winget, Scoop and pre-built binaries, are in
[docs/install.md](docs/install.md).
[docs/install.md](docs/install.md). A `cargo install` build works on your machine but has cloud
sign-in off; [why](docs/install.md#build-from-source).

## Use it

Expand Down
50 changes: 39 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ fn main() {
// Load .env for local builds. In CI these vars already come from the environment.
let _ = dotenvy::dotenv();

// These must be present or the build should fail.
// Official builds carry the Onde credentials and must never ship without
// them, so the release workflows set ONDE_REQUIRE_CREDENTIALS and a missing
// value stops the build. Anyone else (a contributor, `cargo install`) gets a
// build with empty credentials: fine-tuning, merging, export and eval all
// work, and the cloud features say that this build is not connected.
println!("cargo:rerun-if-env-changed=ONDE_REQUIRE_CREDENTIALS");
let required = std::env::var("ONDE_REQUIRE_CREDENTIALS").is_ok_and(|v| !v.is_empty());
let mut missing = Vec::new();
for var in [
"ONDE_APP_ID",
"ONDE_APP_SECRET",
Expand All @@ -11,17 +18,38 @@ fn main() {
] {
println!("cargo:rerun-if-env-changed={var}");

match std::env::var(var) {
Ok(val) => {
println!("cargo:rustc-env={var}={val}");
}
Err(_) => {
eprintln!("error: required build variable `{var}` is not set.");
eprintln!(" → Add it to .env for local builds.");
eprintln!(" → Add it as a GitHub Actions secret for CI builds.");
std::process::exit(1);
}
// An unset variable and one set to an empty string both leave the
// build disconnected, so treat them the same. Otherwise `ONDE_APP_ID=`
// in .env or an empty CI secret would slip past the required-creds gate
// and ship a release that cannot reach the backend.
let val = std::env::var(var).unwrap_or_default();
println!("cargo:rustc-env={var}={val}");
if val.is_empty() {
missing.push(var);
}
}
if !missing.is_empty() {
if required {
eprintln!(
"error: required build variable(s) not set or empty: {}.",
missing.join(", ")
);
eprintln!(" → Add them to .env for local builds.");
eprintln!(" → Add them as GitHub Actions secrets for CI builds.");
std::process::exit(1);
}
// Name only the features the missing vars actually gate. The Onde auth
// keys gate sign-in (and everything behind it); the GresIQ keys gate
// publishing and app assignment on their own.
let off = if missing.iter().any(|v| v.starts_with("ONDE_")) {
"cloud sign-in, publishing and app assignment are off"
} else {
"publishing and app assignment are off"
};
println!(
"cargo:warning=building without some Onde credentials ({}); {off} in this build",
missing.join(", ")
);
}

// Optional vars: bake them in when present, use an empty string otherwise.
Expand Down
10 changes: 10 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ scoop bucket add onde https://github.com/ondeinference/scoop-bucket
scoop install onde
```

## Build from source

```sh
cargo install onde-cli # from crates.io
# or, in a checkout:
cargo build --release
```

A build you make yourself has no Onde credentials. It fine-tunes, merges, exports to GGUF and evaluates models on your machine, and chat works. Cloud sign-in, publishing to Hugging Face through your Onde account and assigning models to apps are off, and say so when you try them. The binaries on GitHub Releases and in the package managers include the credentials. To get them in a build of your own you need the Onde values in a `.env` file or the environment.

## Pre-built binary

Download a release from [GitHub Releases](https://github.com/ondeinference/onde-cli/releases):
Expand Down
1 change: 1 addition & 0 deletions packaging/app/src-tauri/src/commands/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub async fn oauth_sign_in(
pending: State<'_, PendingSignIn>,
provider: Provider,
) -> Result<Profile, CommandError> {
crate::desktop::auth::ensure_connected()?;
let state = oauth::new_state();
let cancelled = pending.begin();

Expand Down
19 changes: 18 additions & 1 deletion packaging/app/src-tauri/src/desktop/auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::error::CommandError;
use onde_cli::{config::credentials, token};
use onde_cli::{
config::{NOT_CONNECTED, credentials, is_connected},
token,
};
use serde::Serialize;
use smbcloud_auth_sdk::{
login::login_with_client, logout::logout_with_client, me::me_with_client,
Expand All @@ -25,6 +28,9 @@ fn error_text(e: &ErrorResponse) -> String {
/// The signed-in user, if a saved token is still valid. A rejected token is
/// cleared so the next launch starts signed out.
pub async fn restore() -> Option<Profile> {
if !is_connected() {
return None;
}
let saved = token::load()?;
match me_with_client(Environment::Production, credentials(), &saved).await {
Ok(user) => Some(Profile { email: user.email }),
Expand Down Expand Up @@ -61,7 +67,17 @@ pub async fn finish_sign_in(
}
}

/// Refuses cloud sign-in in a build that carries no Onde credentials.
pub fn ensure_connected() -> Result<(), CommandError> {
if is_connected() {
Ok(())
} else {
Err(CommandError::Auth(NOT_CONNECTED.into()))
}
}

pub async fn sign_in(email: String, password: String) -> Result<Profile, CommandError> {
ensure_connected()?;
let status = login_with_client(
Environment::Production,
credentials(),
Expand All @@ -83,6 +99,7 @@ pub async fn sign_in(email: String, password: String) -> Result<Profile, Command
}

pub async fn sign_up(email: String, password: String) -> Result<String, CommandError> {
ensure_connected()?;
signup_with_client(Environment::Production, credentials(), email, password)
.await
.map(|r| r.message)
Expand Down
9 changes: 8 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,9 @@ pub async fn run<B: ratatui::backend::Backend>(terminal: &mut ratatui::Terminal<
let mut events = EventStream::new();

// pick up where we left off if there is a saved token
if let Some(saved_token) = token::load() {
if crate::config::is_connected()
&& let Some(saved_token) = token::load()
{
app.busy = true;
app.status = Status::neutral("Restoring session…");
let tx2 = tx.clone();
Expand Down Expand Up @@ -2795,6 +2797,11 @@ fn submit(app: &mut App, tx: mpsc::UnboundedSender<AuthEvent>) {
let email = app.email.trim().to_string();
let password = app.password.clone();

if !crate::config::is_connected() {
app.status = Status::error(crate::config::NOT_CONNECTED);
return;
}

if email.is_empty() || password.is_empty() {
app.status = Status::error("Email and password are required.");
return;
Expand Down
37 changes: 37 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,47 @@ pub const HF_TOKEN: &str = env!("HF_TOKEN");
pub(crate) const GRESIQ_API_KEY: &str = env!("GRESIQ_API_KEY");
pub(crate) const GRESIQ_API_SECRET: &str = env!("GRESIQ_API_SECRET");

/// What a cloud feature says when this build carries no Onde auth credentials:
/// a source build made without a `.env`, or `cargo install`. Sign-in is off,
/// and with no way to sign in, publishing and app assignment are too.
pub const NOT_CONNECTED: &str = "This build has no Onde credentials, so cloud sign-in, publishing and app assignment are off. Fine-tuning, merging, export and eval still work. Official releases include the credentials.";
Comment thread
setoelkahfi marked this conversation as resolved.
Resolved

/// What the apps-and-models features say when sign-in works (the Onde auth
/// credentials are present) but the GresIQ keys are missing. Reaching this
/// path means the user already signed in, so it does not claim sign-in is off.
pub const NOT_CONNECTED_GRESIQ: &str = "This build has no GresIQ credentials, so publishing and app assignment are off. Sign-in and the local tools still work. Official releases include the credentials.";

fn connected(app_id: &str, app_secret: &str) -> bool {
!app_id.is_empty() && !app_secret.is_empty()
}

/// True when this build can talk to Onde's auth backend.
pub fn is_connected() -> bool {
connected(ONDE_APP_ID, ONDE_APP_SECRET)
}

/// True when this build can talk to GresIQ (apps and models).
pub fn gresiq_connected() -> bool {
connected(GRESIQ_API_KEY, GRESIQ_API_SECRET)
}

/// The Auth client credentials identifying this build to the backend.
pub fn credentials() -> ClientCredentials<'static> {
ClientCredentials {
app_id: ONDE_APP_ID,
app_secret: ONDE_APP_SECRET,
}
}

#[cfg(test)]
mod tests {
use super::connected;

#[test]
fn a_build_is_connected_only_with_both_values() {
assert!(connected("id", "secret"));
assert!(!connected("", "secret"));
assert!(!connected("id", ""));
assert!(!connected("", ""));
}
}
49 changes: 26 additions & 23 deletions src/gresiq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
//! need to pass the user's access token.
use smbcloud_gresiq_sdk::{CreateModelParams, Environment, OndeApp, OndeModel};

fn api_key() -> &'static str {
crate::config::GRESIQ_API_KEY
}

fn api_secret() -> &'static str {
crate::config::GRESIQ_API_SECRET
/// The GresIQ key and secret, or an error saying this build has none.
fn keys() -> anyhow::Result<(&'static str, &'static str)> {
if !crate::config::gresiq_connected() {
anyhow::bail!(crate::config::NOT_CONNECTED_GRESIQ);
}
Ok((
crate::config::GRESIQ_API_KEY,
crate::config::GRESIQ_API_SECRET,
))
}

pub async fn load_apps(token: &str) -> anyhow::Result<Vec<OndeApp>> {
smbcloud_gresiq_sdk::list_apps(&Environment::Production, api_key(), api_secret(), token)
let (api_key, api_secret) = keys()?;
smbcloud_gresiq_sdk::list_apps(&Environment::Production, api_key, api_secret, token)
.await
.map_err(|e| anyhow::anyhow!("{e}"))
}

pub async fn create_app(token: &str, name: &str) -> anyhow::Result<OndeApp> {
smbcloud_gresiq_sdk::create_app(
&Environment::Production,
api_key(),
api_secret(),
token,
name,
)
.await
.map_err(|e| anyhow::anyhow!("{e}"))
let (api_key, api_secret) = keys()?;
smbcloud_gresiq_sdk::create_app(&Environment::Production, api_key, api_secret, token, name)
.await
.map_err(|e| anyhow::anyhow!("{e}"))
}

pub async fn load_models(token: &str) -> anyhow::Result<Vec<OndeModel>> {
smbcloud_gresiq_sdk::list_models(&Environment::Production, api_key(), api_secret(), token)
let (api_key, api_secret) = keys()?;
smbcloud_gresiq_sdk::list_models(&Environment::Production, api_key, api_secret, token)
.await
.map_err(|e| anyhow::anyhow!("{e}"))
}
Expand All @@ -46,10 +46,11 @@ pub async fn create_model(
gguf_file: Option<&str>,
approx_size_bytes: Option<i64>,
) -> anyhow::Result<OndeModel> {
let (api_key, api_secret) = keys()?;
smbcloud_gresiq_sdk::create_model(
&Environment::Production,
api_key(),
api_secret(),
api_key,
api_secret,
token,
CreateModelParams {
hf_repo_id,
Expand All @@ -69,10 +70,11 @@ pub async fn create_model(
}

pub async fn assign_model(token: &str, onde_app_id: &str, model_id: &str) -> anyhow::Result<()> {
let (api_key, api_secret) = keys()?;
smbcloud_gresiq_sdk::assign_model(
&Environment::Production,
api_key(),
api_secret(),
api_key,
api_secret,
token,
onde_app_id,
model_id,
Expand All @@ -82,10 +84,11 @@ pub async fn assign_model(token: &str, onde_app_id: &str, model_id: &str) -> any
}

pub async fn rename_app(token: &str, onde_app_id: &str, new_name: &str) -> anyhow::Result<OndeApp> {
let (api_key, api_secret) = keys()?;
smbcloud_gresiq_sdk::rename_app(
&Environment::Production,
api_key(),
api_secret(),
api_key,
api_secret,
token,
onde_app_id,
new_name,
Expand Down
Loading
Loading