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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# API Keys (at least one required)
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
GEMINI_API_KEY=

# Backend-v2
BIND_ADDR=127.0.0.1:8080
LOG_LEVEL=info
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Thumbs.db
# Backend data (downloaded via scripts/setup-data.sh)
backend/data/

# Speedwagon store (auto-created on first request)
backend-v2/.speedwagon/

# Claude Code / OMC / Plugin state
.claude/
CLAUDE.md
Expand Down
27 changes: 24 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ members = [
]

[workspace.dependencies]
ailoy = { git = "https://github.com/brekkylab/ailoy.git", rev = "922d25b2c0733b7c95df4d4fe232a73cfdcef928", features = ["sandbox"] }
# ailoy = { path = "../ailoy", features = ["sandbox"] }
ailoy = { git = "https://github.com/brekkylab/ailoy.git", rev = "098a8289272ccce3cf5719e20732050cb047d04a", features = ["sandbox"] }
speedwagon = { path = "./speedwagon", default-features = false }
3 changes: 2 additions & 1 deletion backend-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ axum = { version = "0.8", features = ["multipart"] }
axum-extra = { version = "0.10", features = ["typed-header"] }
bytes = "1"
chrono = { version = "0.4.42", features = ["serde", "clock"] }
dashmap = "6"
dotenvy = "0.15"
futures-util = "0.3"
schemars = { version = "0.8", features = ["uuid1", "chrono"] }
Expand All @@ -28,7 +29,7 @@ serde_json = "1.0.149"
speedwagon = { workspace = true }
sqlx = { version = "0.8.6", features = ["sqlite", "runtime-tokio-rustls"] }
thiserror = "2.0.17"
tokio = { version = "1.48.0", features = ["sync", "fs", "rt", "rt-multi-thread", "macros"] }
tokio = { version = "1.48.0", features = ["sync", "fs", "rt", "rt-multi-thread", "macros", "time"] }
tokio-stream = "0.1"
tower-http = { version = "0.6", features = ["cors"] }
tracing = "0.1"
Expand Down
28 changes: 13 additions & 15 deletions backend-v2/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use schemars::JsonSchema;
use serde::Serialize;

use axum::{Json, http::StatusCode};

pub type ApiError = (StatusCode, Json<AppError>);
pub type ApiResult<T> = Result<T, ApiError>;

#[derive(Debug, JsonSchema, Serialize)]
pub struct AppError {
error: String,
Expand All @@ -12,19 +17,12 @@ impl AppError {
error: errstr.into(),
}
}
// fn not_found(msg: impl Into<String>) -> ApiErr {
// (StatusCode::NOT_FOUND, Json(Self { error: msg.into() }))
// }
// fn conflict(msg: impl Into<String>) -> ApiErr {
// (StatusCode::CONFLICT, Json(Self { error: msg.into() }))
// }
// fn bad_request(msg: impl Into<String>) -> ApiErr {
// (StatusCode::BAD_REQUEST, Json(Self { error: msg.into() }))
// }
// fn internal(msg: impl Into<String>) -> ApiErr {
// (
// StatusCode::INTERNAL_SERVER_ERROR,
// Json(Self { error: msg.into() }),
// )
// }

pub fn internal(msg: impl Into<String>) -> ApiError {
(StatusCode::INTERNAL_SERVER_ERROR, Json(Self::new(msg)))
}

pub fn not_found(msg: impl Into<String>) -> ApiError {
(StatusCode::NOT_FOUND, Json(Self::new(msg)))
}
}
36 changes: 34 additions & 2 deletions backend-v2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::path::PathBuf;
use std::sync::Arc;

use agent_k_backend::{repository, router, state::AppState};
use aide::axum::ApiRouter;
use aide::openapi::{Info, OpenApi};
use aide::scalar::Scalar;
use ailoy::agent::default_provider_mut;
use ailoy::lang_model::LangModelProvider;
use axum::Extension;
use axum::response::IntoResponse;
use tokio::sync::Mutex;
use speedwagon::{Store, build_tools};
use tokio::sync::RwLock;
use tower_http::cors::{Any, CorsLayer};

#[tokio::main]
Expand Down Expand Up @@ -46,7 +50,35 @@ async fn main() -> std::io::Result<()> {
.await
.expect("failed to initialise repository");

let app_state = Arc::new(Mutex::new(AppState::new(repo)));
let store_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".speedwagon");
let store = Arc::new(RwLock::new(
Store::new(store_path).expect("speedwagon store init"),
));

// Register API keys with the global provider (needed by Agent::try_with_tools)
{
let mut provider = default_provider_mut().await;

if let Ok(key) = std::env::var("OPENAI_API_KEY") {
provider
.models
.insert("openai/*".into(), LangModelProvider::openai(key));
}
if let Ok(key) = std::env::var("ANTHROPIC_API_KEY") {
provider
.models
.insert("anthropic/*".into(), LangModelProvider::anthropic(key));
}
if let Ok(key) = std::env::var("GEMINI_API_KEY") {
provider
.models
.insert("google/*".into(), LangModelProvider::gemini(key));
}

provider.tools = build_tools(store.clone());
}

let app_state = Arc::new(AppState::new(repo, store));
let app = router::get_router(app_state)
.finish_api(&mut openapi)
.merge(
Expand Down
4 changes: 2 additions & 2 deletions backend-v2/src/model/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use uuid::Uuid;
#[serde(deny_unknown_fields)]
pub struct CreateSessionRequest {}

/// API representation of a session.
/// API response for GET /sessions (list) and POST /sessions (create) -- no messages
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Session {
pub struct SessionResponse {
pub id: Uuid,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
Expand Down
Loading