jules_rs/
models.rs

1//! Data models for the Jules API.
2//!
3//! This module contains all the types used to represent Jules API objects,
4//! including sessions, activities, sources, and their related types.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8
9/// The automation mode for a session.
10///
11/// Controls whether certain actions are performed automatically.
12#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
13#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
14pub enum AutomationMode {
15    /// No automation (default).
16    AutomationModeUnspecified,
17    /// Automatically create a pull request when code changes are ready.
18    AutoCreatePr,
19}
20
21/// The current state of a session.
22#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
23#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
24pub enum SessionState {
25    /// State is not specified.
26    StateUnspecified,
27    /// Session is queued and waiting to start.
28    Queued,
29    /// Agent is generating a plan.
30    Planning,
31    /// Waiting for user to approve the plan.
32    AwaitingPlanApproval,
33    /// Waiting for user feedback or input.
34    AwaitingUserFeedback,
35    /// Agent is actively working on the task.
36    InProgress,
37    /// Session is paused.
38    Paused,
39    /// Session failed due to an error.
40    Failed,
41    /// Session completed successfully.
42    Completed,
43}
44
45/// A coding session with the Jules agent.
46///
47/// Sessions represent a contiguous amount of work within the same context.
48/// Each session has a prompt describing the task and a source context
49/// specifying which repository to work on.
50#[derive(Debug, Serialize, Deserialize, Clone)]
51#[serde(rename_all = "camelCase")]
52pub struct Session {
53    /// The full resource name (e.g., `sessions/{session}`). Output only.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub name: Option<String>,
56    /// The session ID. Output only.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub id: Option<String>,
59    /// The prompt describing the coding task.
60    pub prompt: String,
61    /// The source repository and context for this session.
62    pub source_context: SourceContext,
63    /// Optional title for the session.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub title: Option<String>,
66    /// Whether plan approval is required before the agent starts work.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub require_plan_approval: Option<bool>,
69    /// The automation mode for this session.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub automation_mode: Option<AutomationMode>,
72    /// When the session was created. Output only.
73    #[serde(skip_serializing)]
74    pub create_time: Option<DateTime<Utc>>,
75    /// When the session was last updated. Output only.
76    #[serde(skip_serializing)]
77    pub update_time: Option<DateTime<Utc>>,
78    /// The current state of the session. Output only.
79    #[serde(skip_serializing)]
80    pub state: Option<SessionState>,
81    /// URL to view the session in the Jules web app. Output only.
82    #[serde(skip_serializing)]
83    pub url: Option<String>,
84    /// Outputs produced by the session (e.g., pull requests). Output only.
85    #[serde(skip_serializing)]
86    pub outputs: Option<Vec<SessionOutput>>,
87}
88
89/// Context for using a source in a session.
90#[derive(Debug, Serialize, Deserialize, Clone)]
91#[serde(rename_all = "camelCase")]
92pub struct SourceContext {
93    /// GitHub-specific context.
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub github_repo_context: Option<GitHubRepoContext>,
96    /// The source resource name (e.g., `sources/{source}`).
97    pub source: String,
98}
99
100/// GitHub repository context for a session.
101#[derive(Debug, Serialize, Deserialize, Clone)]
102#[serde(rename_all = "camelCase")]
103pub struct GitHubRepoContext {
104    /// The branch to start the session from.
105    pub starting_branch: String,
106}
107
108/// An output produced by a session.
109#[derive(Debug, Serialize, Deserialize, Clone)]
110#[serde(rename_all = "camelCase")]
111pub struct SessionOutput {
112    /// A pull request created by the session.
113    pub pull_request: Option<PullRequest>,
114}
115
116/// A pull request created by Jules.
117#[derive(Debug, Serialize, Deserialize, Clone)]
118#[serde(rename_all = "camelCase")]
119pub struct PullRequest {
120    /// The URL of the pull request.
121    pub url: String,
122    /// The title of the pull request.
123    pub title: String,
124    /// The description/body of the pull request.
125    pub description: String,
126}
127
128/// An activity within a session.
129///
130/// Activities represent individual units of work or events that occur
131/// during a session, such as messages, plan generation, and progress updates.
132#[derive(Debug, Serialize, Deserialize, Clone)]
133#[serde(rename_all = "camelCase")]
134pub struct Activity {
135    /// The full resource name.
136    pub name: String,
137    /// The activity ID.
138    pub id: String,
139    /// Description of this activity.
140    pub description: Option<String>,
141    /// When the activity was created.
142    pub create_time: DateTime<Utc>,
143    /// Who originated this activity (user, agent, or system).
144    pub originator: String,
145    /// The agent posted a message.
146    pub agent_messaged: Option<AgentMessaged>,
147    /// The user posted a message.
148    pub user_messaged: Option<UserMessaged>,
149    /// A plan was generated.
150    pub plan_generated: Option<PlanGenerated>,
151    /// A plan was approved.
152    pub plan_approved: Option<PlanApproved>,
153    /// Progress was updated.
154    pub progress_updated: Option<ProgressUpdated>,
155    /// The session completed.
156    pub session_completed: Option<serde_json::Value>,
157    /// The session failed.
158    pub session_failed: Option<SessionFailed>,
159    /// Artifacts produced by this activity.
160    pub artifacts: Option<Vec<Artifact>>,
161}
162
163/// Agent message activity.
164#[derive(Debug, Serialize, Deserialize, Clone)]
165#[serde(rename_all = "camelCase")]
166pub struct AgentMessaged {
167    /// The message content.
168    pub agent_message: String,
169}
170
171/// User message activity.
172#[derive(Debug, Serialize, Deserialize, Clone)]
173#[serde(rename_all = "camelCase")]
174pub struct UserMessaged {
175    /// The message content.
176    pub user_message: String,
177}
178
179/// Plan generation activity.
180#[derive(Debug, Serialize, Deserialize, Clone)]
181#[serde(rename_all = "camelCase")]
182pub struct PlanGenerated {
183    /// The generated plan.
184    pub plan: Plan,
185}
186
187/// A plan consisting of steps to complete the task.
188#[derive(Debug, Serialize, Deserialize, Clone)]
189#[serde(rename_all = "camelCase")]
190pub struct Plan {
191    /// Unique ID for this plan within the session.
192    pub id: String,
193    /// The steps in the plan.
194    pub steps: Vec<PlanStep>,
195    /// When the plan was created.
196    pub create_time: DateTime<Utc>,
197}
198
199/// A step in a plan.
200#[derive(Debug, Serialize, Deserialize, Clone)]
201#[serde(rename_all = "camelCase")]
202pub struct PlanStep {
203    /// Unique ID for this step within the plan.
204    pub id: String,
205    /// Title of the step.
206    pub title: String,
207    /// Description of what this step will do.
208    pub description: String,
209    /// 0-based index of this step.
210    pub index: i32,
211}
212
213/// Plan approval activity.
214#[derive(Debug, Serialize, Deserialize, Clone)]
215#[serde(rename_all = "camelCase")]
216pub struct PlanApproved {
217    /// ID of the approved plan.
218    pub plan_id: String,
219}
220
221/// Progress update activity.
222#[derive(Debug, Serialize, Deserialize, Clone)]
223#[serde(rename_all = "camelCase")]
224pub struct ProgressUpdated {
225    /// Title of the progress update.
226    pub title: String,
227    /// Description of current progress.
228    pub description: String,
229}
230
231/// Session failure activity.
232#[derive(Debug, Serialize, Deserialize, Clone)]
233#[serde(rename_all = "camelCase")]
234pub struct SessionFailed {
235    /// The reason for failure.
236    pub reason: String,
237}
238
239/// An artifact produced during a session.
240#[derive(Debug, Serialize, Deserialize, Clone)]
241#[serde(rename_all = "camelCase")]
242pub struct Artifact {
243    /// A set of code changes.
244    pub change_set: Option<ChangeSet>,
245    /// A media file (image, video, etc.).
246    pub media: Option<Media>,
247    /// Output from a bash command.
248    pub bash_output: Option<BashOutput>,
249}
250
251/// A set of code changes.
252#[derive(Debug, Serialize, Deserialize, Clone)]
253#[serde(rename_all = "camelCase")]
254pub struct ChangeSet {
255    /// The changes in git patch format.
256    pub git_patch: Option<GitPatch>,
257    /// The source this applies to.
258    pub source: String,
259}
260
261/// A git patch representing code changes.
262#[derive(Debug, Serialize, Deserialize, Clone)]
263#[serde(rename_all = "camelCase")]
264pub struct GitPatch {
265    /// The patch in unified diff format.
266    pub unidiff_patch: String,
267    /// The base commit this patch applies to.
268    pub base_commit_id: String,
269    /// Suggested commit message.
270    pub suggested_commit_message: Option<String>,
271}
272
273/// A media artifact.
274#[derive(Debug, Serialize, Deserialize, Clone)]
275#[serde(rename_all = "camelCase")]
276pub struct Media {
277    /// Base64-encoded media data.
278    pub data: String,
279    /// MIME type of the media.
280    pub mime_type: String,
281}
282
283/// Output from a bash command.
284#[derive(Debug, Serialize, Deserialize, Clone)]
285#[serde(rename_all = "camelCase")]
286pub struct BashOutput {
287    /// The command that was executed.
288    pub command: String,
289    /// Combined stdout and stderr output.
290    pub output: String,
291    /// Exit code of the command.
292    pub exit_code: i32,
293}
294
295/// A source repository.
296#[derive(Debug, Serialize, Deserialize, Clone)]
297#[serde(rename_all = "camelCase")]
298pub struct Source {
299    /// The full resource name.
300    pub name: String,
301    /// The source ID.
302    pub id: String,
303    /// GitHub repository details.
304    pub github_repo: Option<GitHubRepo>,
305}
306
307/// A GitHub repository.
308#[derive(Debug, Serialize, Deserialize, Clone)]
309#[serde(rename_all = "camelCase")]
310pub struct GitHubRepo {
311    /// Repository owner (user or organization).
312    pub owner: String,
313    /// Repository name.
314    pub repo: String,
315    /// Whether the repository is private.
316    pub is_private: bool,
317    /// The default branch.
318    pub default_branch: GitHubBranch,
319    /// Available branches.
320    pub branches: Vec<GitHubBranch>,
321}
322
323/// A GitHub branch.
324#[derive(Debug, Serialize, Deserialize, Clone)]
325#[serde(rename_all = "camelCase")]
326pub struct GitHubBranch {
327    /// The branch name.
328    pub display_name: String,
329}
330
331/// Response from listing sessions.
332#[derive(Debug, Serialize, Deserialize, Clone)]
333#[serde(rename_all = "camelCase")]
334pub struct ListSessionsResponse {
335    /// The sessions.
336    pub sessions: Vec<Session>,
337    /// Token for the next page, if any.
338    pub next_page_token: Option<String>,
339}
340
341/// Response from listing activities.
342#[derive(Debug, Serialize, Deserialize, Clone)]
343#[serde(rename_all = "camelCase")]
344pub struct ListActivitiesResponse {
345    /// The activities.
346    pub activities: Vec<Activity>,
347    /// Token for the next page, if any.
348    pub next_page_token: Option<String>,
349}
350
351/// Response from listing sources.
352#[derive(Debug, Serialize, Deserialize, Clone)]
353#[serde(rename_all = "camelCase")]
354pub struct ListSourcesResponse {
355    /// The sources.
356    pub sources: Vec<Source>,
357    /// Token for the next page, if any.
358    pub next_page_token: Option<String>,
359}
360
361/// Request to send a message to a session.
362#[derive(Debug, Serialize, Deserialize, Clone)]
363pub struct SendMessageRequest {
364    /// The message prompt to send.
365    pub prompt: String,
366}
367
368/// Request to approve a plan.
369#[derive(Debug, Serialize, Deserialize, Clone)]
370pub struct ApprovePlanRequest {}
371
372/// Empty response type for operations with no response body.
373#[derive(Debug, Serialize, Deserialize, Clone)]
374pub struct Empty {}