pub struct JulesClient { /* private fields */ }Expand description
The main client for interacting with the Jules API.
JulesClient provides methods for all Jules API operations including
managing sessions, activities, and sources.
§Example
use jules_rs::JulesClient;
let client = JulesClient::new("YOUR_OAUTH_TOKEN")?;
// List sessions
let response = client.list_sessions(Some(10), None).await?;
println!("Found {} sessions", response.sessions.len());Implementations§
Source§impl JulesClient
impl JulesClient
Sourcepub fn new(token: impl Into<String>) -> Result<Self>
pub fn new(token: impl Into<String>) -> Result<Self>
Creates a new Jules API client.
§Arguments
api_key- An API key from jules.google.com/settings.
§Errors
Returns an error if the base URL cannot be parsed (should not happen under normal circumstances).
§Example
use jules_rs::JulesClient;
let client = JulesClient::new("YOUR_API_KEY").unwrap();Sourcepub async fn create_session(&self, session: &Session) -> Result<Session>
pub async fn create_session(&self, session: &Session) -> Result<Session>
Creates a new coding session.
§Arguments
session- The session configuration including prompt and source context.
§Returns
The created session with server-generated fields populated (name, id, etc.).
§Example
use jules_rs::{JulesClient, Session, SourceContext, GitHubRepoContext};
let client = JulesClient::new("TOKEN")?;
let session = Session {
prompt: "Fix the bug".to_string(),
source_context: SourceContext {
source: "sources/repo-id".to_string(),
github_repo_context: Some(GitHubRepoContext {
starting_branch: "main".to_string(),
}),
},
// ... other fields set to None/default
};
let created = client.create_session(&session).await?;Sourcepub async fn get_session(&self, name: &str) -> Result<Session>
pub async fn get_session(&self, name: &str) -> Result<Session>
Gets a session by its resource name.
§Arguments
name- The full resource name (e.g.,sessions/abc123).
Sourcepub async fn delete_session(&self, name: &str) -> Result<()>
pub async fn delete_session(&self, name: &str) -> Result<()>
Sourcepub async fn list_sessions(
&self,
page_size: Option<i32>,
page_token: Option<String>,
) -> Result<ListSessionsResponse>
pub async fn list_sessions( &self, page_size: Option<i32>, page_token: Option<String>, ) -> Result<ListSessionsResponse>
Sourcepub fn stream_sessions(
&self,
) -> Pin<Box<dyn Stream<Item = Result<Session>> + '_>>
pub fn stream_sessions( &self, ) -> Pin<Box<dyn Stream<Item = Result<Session>> + '_>>
Returns an async stream over all sessions.
This method automatically handles pagination, yielding sessions one at a time until all sessions have been retrieved.
§Example
use jules_rs::JulesClient;
use futures_util::StreamExt;
let client = JulesClient::new("TOKEN")?;
let mut stream = client.stream_sessions();
while let Some(result) = stream.next().await {
let session = result?;
println!("Session: {:?}", session.title);
}Sourcepub async fn send_message(&self, session_name: &str, prompt: &str) -> Result<()>
pub async fn send_message(&self, session_name: &str, prompt: &str) -> Result<()>
Sends a message to an active session.
Use this to provide additional context or respond to the agent’s questions during a session.
§Arguments
session_name- The full resource name of the session.prompt- The message to send.
Sourcepub async fn approve_plan(&self, session_name: &str) -> Result<()>
pub async fn approve_plan(&self, session_name: &str) -> Result<()>
Approves the current plan for a session.
When a session is in the AWAITING_PLAN_APPROVAL state, call this
method to approve the plan and allow the agent to proceed.
§Arguments
session_name- The full resource name of the session.
Sourcepub async fn get_activity(&self, name: &str) -> Result<Activity>
pub async fn get_activity(&self, name: &str) -> Result<Activity>
Gets an activity by its resource name.
§Arguments
name- The full resource name (e.g.,sessions/123/activities/456).
Sourcepub async fn list_activities(
&self,
session_name: &str,
page_size: Option<i32>,
page_token: Option<String>,
) -> Result<ListActivitiesResponse>
pub async fn list_activities( &self, session_name: &str, page_size: Option<i32>, page_token: Option<String>, ) -> Result<ListActivitiesResponse>
Lists activities for a session with pagination.
§Arguments
session_name- The full resource name of the session.page_size- Maximum number of activities to return.page_token- Token from a previous response for pagination.
Sourcepub async fn get_source(&self, name: &str) -> Result<Source>
pub async fn get_source(&self, name: &str) -> Result<Source>
Gets a source by its resource name.
§Arguments
name- The full resource name (e.g.,sources/abc123).
Sourcepub async fn list_sources(
&self,
filter: Option<String>,
page_size: Option<i32>,
page_token: Option<String>,
) -> Result<ListSourcesResponse>
pub async fn list_sources( &self, filter: Option<String>, page_size: Option<i32>, page_token: Option<String>, ) -> Result<ListSourcesResponse>
Lists available sources (connected repositories) with pagination.
§Arguments
filter- Optional filter expression.page_size- Maximum number of sources to return.page_token- Token from a previous response for pagination.