From 2d8b4e2db4642dede084801c03516046f205626b Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Thu, 28 May 2026 05:06:04 +0300 Subject: feat: expose agent session refs in api --- src/api/schema.rs | 14 ++++++++++++++ src/app/agents.rs | 1 + src/app/creation.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) (limited to 'src') diff --git a/src/api/schema.rs b/src/api/schema.rs index aa7cbd3c..cd82f99f 100644 --- a/src/api/schema.rs +++ b/src/api/schema.rs @@ -803,6 +803,8 @@ pub struct AgentInfo { pub custom_status: Option, #[serde(default, skip_serializing_if = "HashMap::is_empty")] pub state_labels: HashMap, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub agent_session: Option, pub workspace_id: String, pub tab_id: String, pub pane_id: String, @@ -834,9 +836,19 @@ pub struct PaneInfo { pub custom_status: Option, #[serde(default, skip_serializing_if = "HashMap::is_empty")] pub state_labels: HashMap, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub agent_session: Option, pub revision: u64, } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct AgentSessionInfo { + pub source: String, + pub agent: String, + pub kind: crate::agent_resume::AgentSessionRefKind, + pub value: String, +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct PaneReadResult { pub pane_id: String, @@ -1402,6 +1414,7 @@ mod tests { agent_status: AgentStatus::Unknown, custom_status: None, state_labels: HashMap::new(), + agent_session: None, revision: 0, }, worktree: WorktreeInfo { @@ -1451,6 +1464,7 @@ mod tests { agent_status: AgentStatus::Unknown, custom_status: None, state_labels: HashMap::new(), + agent_session: None, revision: 0, }, }, diff --git a/src/app/agents.rs b/src/app/agents.rs index 8868fb9c..55ee15df 100644 --- a/src/app/agents.rs +++ b/src/app/agents.rs @@ -417,6 +417,7 @@ impl App { agent_status: pane.agent_status, custom_status: pane.custom_status, state_labels: pane.state_labels, + agent_session: pane.agent_session, workspace_id: pane.workspace_id, tab_id: pane.tab_id, pane_id: pane.pane_id, diff --git a/src/app/creation.rs b/src/app/creation.rs index aa727dd5..d483eb1a 100644 --- a/src/app/creation.rs +++ b/src/app/creation.rs @@ -295,6 +295,7 @@ impl App { agent_status: pane_agent_status(terminal.state, pane.seen), custom_status: presentation.custom_status, state_labels: presentation.state_labels, + agent_session: terminal_agent_session_info(terminal), revision: terminal.revision, }) } @@ -345,3 +346,28 @@ impl App { } } } + +fn terminal_agent_session_info( + terminal: &crate::terminal::TerminalState, +) -> Option { + if let Some(authority) = terminal.hook_authority.as_ref() { + if let Some(session_ref) = authority.session_ref.as_ref() { + return Some(crate::api::schema::AgentSessionInfo { + source: authority.source.clone(), + agent: authority.agent_label.clone(), + kind: session_ref.kind, + value: session_ref.value.clone(), + }); + } + } + + terminal + .persisted_agent_session + .as_ref() + .map(|session| crate::api::schema::AgentSessionInfo { + source: session.source.clone(), + agent: session.agent.clone(), + kind: session.session_ref.kind, + value: session.session_ref.value.clone(), + }) +} -- cgit v1.2.3