use ai_cortex_sdk::{CortexClient, CortexConfig};
#[tokio::main]
async fn main() {
let server_url = "http://localhost:40404";
let pat = std::env::args()
.nth(1)
.unwrap_or_else(|| "REPLACE_WITH_YOUR_PAT".to_string());
let software_id = "00000000-0000-0000-0000-000000000000".to_string();
let config = CortexConfig::new(server_url, pat, software_id).with_timeout(30);
let client = CortexClient::new(config);
println!("=== Software Store ===");
match client.list_software().await {
Ok(items) => {
if items.is_empty() {
println!("No software available.");
}
for (i, item) in items.iter().enumerate() {
let version_str = item
.latest_version
.as_ref()
.map(|v| format!("v{} ({} bytes)", v.version, v.file_size))
.unwrap_or_else(|| "no version".to_string());
println!(
"{}. {} — {} [{}]",
i + 1,
item.software.name,
item.software.description,
version_str
);
}
if let Some(item) = items.first() {
if let Some(version) = &item.latest_version {
println!("\n=== Download ===");
match client.download(&version.id).await {
Ok(info) => {
println!(
"Download: v{}, size={} bytes\n URL: {}",
info.version, info.file_size, info.download_url
);
}
Err(e) => eprintln!("Download failed: {e}"),
}
}
}
}
Err(e) => eprintln!("List software failed: {e}"),
}
println!("\n=== My Devices ===");
match client.list_devices().await {
Ok(devices) => {
if devices.is_empty() {
println!("No bound devices yet (heartbeat may not have fired yet).");
}
for d in devices {
println!(
"- id={}, fingerprint={}, last_active={}",
d.id, d.fingerprint, d.last_active_time
);
}
}
Err(e) => eprintln!("List devices failed: {e}"),
}
}