1use stakpak_agent_core::ToolApprovalPolicy;
2pub use stakpak_shared::models::overrides::{AutoApproveOverride, RunOverrides};
3use std::sync::Arc;
4use tokio::sync::mpsc;
5use tokio_util::sync::CancellationToken;
6use uuid::Uuid;
7
8#[derive(Clone)]
9pub struct SessionHandle {
10 pub command_tx: mpsc::Sender<stakpak_agent_core::AgentCommand>,
11 pub cancel: CancellationToken,
12}
13
14impl std::fmt::Debug for SessionHandle {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 f.debug_struct("SessionHandle").finish_non_exhaustive()
17 }
18}
19
20impl SessionHandle {
21 pub fn new(
22 command_tx: mpsc::Sender<stakpak_agent_core::AgentCommand>,
23 cancel: CancellationToken,
24 ) -> Self {
25 Self { command_tx, cancel }
26 }
27}
28
29#[derive(Clone)]
30pub struct RunConfig {
31 pub model: stakai::Model,
32 pub inference: Arc<stakai::Inference>,
33 pub tool_approval_policy: ToolApprovalPolicy,
34 pub system_prompt: Option<String>,
35 pub max_turns: usize,
36}
37
38impl std::fmt::Debug for RunConfig {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 f.debug_struct("RunConfig")
41 .field("model", &self.model)
42 .field("tool_approval_policy", &self.tool_approval_policy)
43 .field("system_prompt", &self.system_prompt)
44 .field("max_turns", &self.max_turns)
45 .field("inference", &"<opaque>")
46 .finish()
47 }
48}
49
50#[derive(Debug, Clone, Default)]
51pub enum SessionRuntimeState {
52 #[default]
53 Idle,
54 Starting {
55 run_id: Uuid,
56 },
57 Running {
58 run_id: Uuid,
59 handle: SessionHandle,
60 },
61 Failed {
62 last_error: String,
63 },
64}
65
66impl SessionRuntimeState {
67 pub fn run_id(&self) -> Option<Uuid> {
68 match self {
69 SessionRuntimeState::Starting { run_id }
70 | SessionRuntimeState::Running { run_id, .. } => Some(*run_id),
71 SessionRuntimeState::Idle | SessionRuntimeState::Failed { .. } => None,
72 }
73 }
74
75 pub fn is_active(&self) -> bool {
76 matches!(
77 self,
78 SessionRuntimeState::Starting { .. } | SessionRuntimeState::Running { .. }
79 )
80 }
81}