Skip to main content

subspace_client_github/copilot_agents/
model.rs

1//! The public agent-task types and the raw documents they map from.
2
3use serde::{Deserialize, Serialize};
4
5use crate::model::PrState;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "kebab-case")]
9pub enum SubjectKind {
10    /// A task the chat tool started; its subject id is the task id.
11    Chat,
12    Other,
13}
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct Subject {
16    pub kind: SubjectKind,
17    pub id: String,
18}
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20pub struct StartTask {
21    pub repo: String,
22    pub prompt: String,
23    pub model: Option<String>,
24    pub base_ref: Option<String>,
25    pub create_pull_request: bool,
26    pub subject: Option<Subject>,
27}
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29pub struct PullRequestArtifact {
30    pub number: u32,
31    pub url: String,
32    pub state: PrState,
33}
34#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35pub struct Task {
36    pub id: String,
37    pub repo: String,
38    pub name: String,
39    pub state: String,
40    pub html_url: String,
41    pub created_at: String,
42    pub updated_at: String,
43    pub pull_request: Option<PullRequestArtifact>,
44    pub subject: Option<Subject>,
45}
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct TaskScope {
48    pub configured_repos: Vec<String>,
49}
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub struct TaskList {
52    pub tasks: Vec<Task>,
53}
54
55/// One agent run inside a task, from `GET /agents/tasks/{task_id}`.
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
57pub struct TaskSession {
58    pub id: String,
59    #[serde(default)]
60    pub name: String,
61    pub state: String,
62    #[serde(default)]
63    pub created_at: String,
64    #[serde(default)]
65    pub updated_at: String,
66    #[serde(default)]
67    pub completed_at: Option<String>,
68    #[serde(default)]
69    pub prompt: String,
70    #[serde(default)]
71    pub head_ref: String,
72    #[serde(default)]
73    pub base_ref: String,
74    #[serde(default)]
75    pub model: String,
76    #[serde(default)]
77    pub usage: Option<SessionUsage>,
78    #[serde(default)]
79    pub error: Option<SessionError>,
80}
81
82/// What the session spent: `ai_credits` or `premium_requests`.
83#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
84pub struct SessionUsage {
85    #[serde(rename = "type")]
86    pub kind: String,
87    pub amount: f64,
88}
89
90#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
91pub struct SessionError {
92    #[serde(default)]
93    pub message: String,
94}
95
96/// A task with the sessions the detail endpoint adds.
97#[derive(Debug, Clone, PartialEq)]
98pub struct TaskDetail {
99    pub task: Task,
100    pub sessions: Vec<TaskSession>,
101}
102
103#[derive(Debug, Deserialize)]
104pub(super) struct RawSessions {
105    #[serde(default)]
106    pub(super) sessions: Vec<TaskSession>,
107}
108
109#[derive(Debug, Deserialize)]
110pub(super) struct RawArtifact {
111    #[serde(rename = "type")]
112    pub(super) kind: Option<String>,
113    pub(super) data: Option<RawArtifactData>,
114}
115#[derive(Debug, Deserialize)]
116pub(super) struct RawArtifactData {
117    pub(super) id: Option<u64>,
118    pub(super) global_id: Option<String>,
119}
120#[derive(Debug, Deserialize)]
121pub(super) struct RawPull {
122    pub(super) id: u64,
123    pub(super) number: u32,
124    pub(super) html_url: String,
125    pub(super) state: String,
126    pub(super) draft: bool,
127    pub(super) merged_at: Option<String>,
128}