agtrace_sdk/query/list.rs
1//! List sessions query types.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use super::Provider;
7use crate::SessionSummary;
8
9/// List recent AI agent sessions with cursor-based pagination.
10#[derive(Debug, Serialize, Deserialize, JsonSchema)]
11pub struct ListSessionsArgs {
12 /// Maximum number of sessions to return (default: 10, max: 50)
13 #[serde(default)]
14 pub limit: Option<usize>,
15 /// Pagination cursor from previous response's next_cursor field. Omit for first page.
16 #[serde(default)]
17 pub cursor: Option<String>,
18 /// Filter by provider
19 pub provider: Option<Provider>,
20 /// Filter by project root path (e.g., "/Users/me/projects/my-app").
21 /// Prefer this over project_hash when the agent knows the current working directory.
22 /// Server will automatically resolve this to the correct project hash.
23 pub project_root: Option<String>,
24 /// Filter by project hash (internal ID).
25 /// Use only when you have the exact hash; prefer project_root for ergonomic filtering.
26 pub project_hash: Option<String>,
27 /// Show sessions after this timestamp (ISO 8601)
28 pub since: Option<String>,
29 /// Show sessions before this timestamp (ISO 8601)
30 pub until: Option<String>,
31 /// Include child sessions (subagents) in the list. By default, only top-level sessions are shown.
32 #[serde(default)]
33 pub include_children: Option<bool>,
34}
35
36#[derive(Debug, Serialize)]
37pub struct ListSessionsViewModel {
38 pub sessions: Vec<SessionSummary>,
39 pub total_in_page: usize,
40 pub next_cursor: Option<String>,
41}
42
43impl ListSessionsViewModel {
44 pub fn new(sessions: Vec<SessionSummary>, next_cursor: Option<String>) -> Self {
45 let total_in_page = sessions.len();
46 Self {
47 sessions,
48 total_in_page,
49 next_cursor,
50 }
51 }
52}