artifactize 0.31.0

The AI-native collaboration layer for one-of-a-kind teammates and their agents: split a project into Artifacts with their own evals, and reuse every review while it still holds.
//! Model listing. Sign-in belongs to each agent's own CLI, and an API key to its environment
//! variable or the desktop app's Settings.

use std::io::{self, Write};

use artifactize_core::config::Backend;

use super::{Context, print_json};

pub(super) async fn models(context: Context, provider: Backend) -> Result<u8, String> {
    let listing = artifactize_core::llm::models::list(
        provider,
        context.state_dir.as_deref(),
        context.repo.as_deref(),
    )
    .await?;
    if context.json {
        print_json(&listing)?;
    } else {
        let mut out = io::stdout().lock();
        for model in listing.models {
            writeln!(out, "{}\t{}", model.slug, model.display_name).map_err(|e| e.to_string())?;
        }
    }
    Ok(0)
}