use chrono::{DateTime, Utc};
use uuid::Uuid;
use crate::entities::subagent::{RunKind, RunOutcome, SubagentProgress};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BackgroundKind {
Reflection,
Consolidation,
SelfConsolidation,
Compaction,
}
impl BackgroundKind {
pub fn label_key(self) -> &'static str {
match self {
BackgroundKind::Reflection => "ui.tasks.app.reflection",
BackgroundKind::Consolidation => "ui.tasks.app.consolidation",
BackgroundKind::SelfConsolidation => "ui.tasks.app.self_consolidation",
BackgroundKind::Compaction => "ui.tasks.app.compaction",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TaskRun {
pub id: Uuid,
pub kind: RunKind,
pub title: String,
pub parent: Uuid,
pub parent_title: String,
pub created_at: DateTime<Utc>,
pub finished_at: Option<DateTime<Utc>>,
pub outcome: Option<RunOutcome>,
pub running: bool,
pub background: bool,
pub tokens: u64,
pub position: Option<SubagentProgress>,
}
impl TaskRun {
#[cfg(test)]
pub fn fixture(title: &str) -> Self {
Self {
id: Uuid::new_v4(),
kind: RunKind::Subagent,
title: title.into(),
parent: Uuid::new_v4(),
parent_title: "Plans".into(),
created_at: Utc::now() - chrono::Duration::minutes(10),
finished_at: None,
outcome: None,
running: true,
background: true,
tokens: 0,
position: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AppTask {
pub kind: BackgroundKind,
pub running: bool,
pub waiting: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct TaskList {
pub runs: Vec<TaskRun>,
pub more_landed: usize,
pub app: Vec<AppTask>,
}
pub const TASK_LANDED_CAP: usize = 50;