fixxxeeess

This commit is contained in:
pavel 2026-02-10 20:57:03 +01:00
commit c4d9ca19ce
8 changed files with 142 additions and 54 deletions

View file

@ -127,6 +127,7 @@ pub async fn start(db_url: &str) -> Result<(), Box<dyn std::error::Error>> {
.route("/tasks/:id/runs", post(rerun_task))
.route("/runs/recent", get(get_recent_runs))
.route("/auth/callback", get(auth_callback))
.route("/auth/refresh", post(auth_refresh))
.layer(cors)
.with_state(state);
@ -150,21 +151,24 @@ async fn list_tasks(
let response = tasks
.into_iter()
.map(|(t, runs)| TaskResponse {
id: t.id,
goal: t.goal,
cron: t.cron,
created_at: t.created_at,
runs: runs
.into_iter()
.map(|r| TaskRunResponse {
id: r.id,
status: r.status,
logs: r.logs,
answer: r.answer,
created_at: r.created_at,
})
.collect(),
.map(|(t, mut runs)| {
runs.sort_by(|a, b| b.created_at.cmp(&a.created_at));
TaskResponse {
id: t.id,
goal: t.goal,
cron: t.cron,
created_at: t.created_at,
runs: runs
.into_iter()
.map(|r| TaskRunResponse {
id: r.id,
status: r.status,
logs: r.logs,
answer: r.answer,
created_at: r.created_at,
})
.collect(),
}
})
.collect();
@ -240,7 +244,8 @@ async fn execute_agent_run(
state.zen_api_key.clone(),
state.tavily_api_key.clone(),
goal.clone(),
);
)
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
let (logs, answer) = match agent.run().await {
Ok((logs, answer)) => (logs, answer),
@ -298,6 +303,7 @@ async fn update_task(
get_task_inner(id, &state).await.map(Json)
}
#[allow(dead_code)]
pub struct AuthenticatedUser(pub crate::auth::Claims);
#[axum::async_trait]
@ -342,6 +348,23 @@ pub struct AuthCallbackQuery {
pub redirect_uri: String,
}
#[derive(Deserialize)]
struct RefreshRequest {
refresh_token: String,
}
async fn auth_refresh(
State(state): State<Arc<AppState>>,
Json(payload): Json<RefreshRequest>,
) -> Result<Json<serde_json::Value>, (StatusCode, String)> {
state
.authenticator
.refresh_token(payload.refresh_token)
.await
.map(Json)
.map_err(|e| (StatusCode::UNAUTHORIZED, e.to_string()))
}
async fn auth_callback(
State(state): State<Arc<AppState>>,
Query(query): Query<AuthCallbackQuery>,
@ -374,11 +397,13 @@ async fn get_task_inner(id: Uuid, state: &AppState) -> Result<TaskResponse, (Sta
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
let (t, runs) = results
let (t, mut runs) = results
.into_iter()
.next()
.ok_or((StatusCode::NOT_FOUND, "Task not found".to_string()))?;
runs.sort_by(|a, b| b.created_at.cmp(&a.created_at));
Ok(TaskResponse {
id: t.id,
goal: t.goal,