Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Async gateway client. Share it behind an Arc; methods take &self.

Every call is POST {gateway_url}/api/<method> with the session’s bearer token and headers, after re-checking the URL against the Policy. A client created with a Cursor access token (Client::connect_cursor / Client::with_cursor_token) re-runs EnsureSandBox once and retries when the gateway answers 401 or 417; persist the new session from Client::take_refreshed_session.

use grokbot_api::{Client, ClientOptions, Session};

let client = Client::new(
    Session::new("https://box.us1.cursorvm.com", "gateway-token"),
    ClientOptions::default(),
)?;
for agent in client.list_agents().await? {
    println!("{} {}", agent.id, agent.display_name());
}

Implementations§

Source§

impl Client

Source

pub fn new(session: Session, opts: ClientOptions) -> Result<Self>

Client for an existing gateway session. The URL is checked against the policy on every call.

Source

pub fn with_cursor_token( session: Session, cursor_token: impl Into<String>, opts: ClientOptions, ) -> Result<Self>

Like Client::new, but keeps the Cursor access token so a 401 triggers one EnsureSandBox re-exchange and a retry.

Source

pub async fn connect_cursor( access_token: &str, opts: ClientOptions, ) -> Result<Self>

EnsureSandBox then build a client that can re-exchange.

Source

pub fn session(&self) -> Session

The current session (it changes after a 401/417 re-exchange).

Source

pub fn take_refreshed_session(&self) -> Option<Session>

The new session if a 401 re-exchange happened since the last call (persist it).

Source

pub async fn call_raw(&self, method: &str, body: Value) -> Result<Value>

Call any gateway method with a raw JSON body and return the raw JSON response. Handles the 401/417 re-exchange like the typed methods.

Source

pub async fn list_agents(&self) -> Result<Vec<Agent>>

listAgents {} → bots and groups (hidden ones included; check hidden_from_sidebar).

Source

pub async fn create_agent(&self, input: &CreateAgent) -> Result<Option<Agent>>

createAgent {name, description, title, avatarShape, avatarColor, origin: "user"}.

Source

pub async fn update_agent( &self, id: &str, profile: &AgentProfile, ) -> Result<Value>

updateAgent {id, profile: {name, description, title?, avatarShape?, avatarColor?}}.

Source

pub async fn delete_agent(&self, id: &str) -> Result<Value>

deleteAgent {id}.

Source

pub async fn set_agent_notify_on_updates( &self, id: &str, enabled: bool, ) -> Result<Value>

setAgentNotifyOnUpdates {id, isEnabled}.

Source

pub async fn set_agent_hidden_from_sidebar( &self, id: &str, hidden: bool, ) -> Result<Value>

setAgentHiddenFromSidebar {id, isHidden}.

Source

pub async fn create_group(&self, input: &CreateGroup) -> Result<Option<Agent>>

createGroup {name, description, memberAgentIds} (1..=6 distinct members, no nested groups).

Source

pub async fn set_group_members( &self, group_id: &str, member_agent_ids: &[String], ) -> Result<Option<Agent>>

setGroupMembers {id, memberAgentIds}.

Source

pub fn set_agent_session(&self, agent_id: &str, session_id: &str)

Route calls for agent_id through session_id (a shared agent’s viewer session), sent as sessionId on sendPrompt, promptAcceptanceStatus and getAgentTranscriptTail. Client::list_team_agents sets this automatically.

Source

pub async fn list_team_agents(&self) -> Result<Option<Vec<TeamAgent>>>

Cursor backend GrokBotService/ListGrokBotTeamAgents: your agents plus team agents shared with you. Ok(None) when this client has no Cursor access token (a plain gateway session). Shared agents’ viewer sessions are remembered for later calls.

Source

pub async fn send_prompt(&self, req: &SendPrompt) -> Result<SendReceipt>

sendPrompt {agentId, prompt, clientNonce, replyToId?, sessionId?} → receipt only.

Replies arrive later: poll Client::transcript_tail. On error use Error::delivery: Unknown means the prompt may have landed, so check the transcript or Client::prompt_acceptance_status before resending. A gateway refusal ({status: "refused"} / {accepted: false}) is returned as Error::Http with status 422.

Source

pub async fn prompt_acceptance_status( &self, agent_id: &str, client_nonce: &str, ) -> Result<AcceptanceStatus>

promptAcceptanceStatus {agentId, clientNonce}: the gateway’s own lookup of whether a prompt with this nonce landed (what the desktop app uses when a send’s outcome is uncertain).

Source

pub async fn transcript_tail( &self, id: &str, limit: u32, before_seq: Option<u64>, ) -> Result<Transcript>

getAgentTranscriptTail {id, limit, beforeSeq?} (limit clamped to 1..=200).

Omitting before_seq returns the newest page. When the response includes nextBeforeSeq, pass it here to walk older pages (as the desktop app does).

Source

pub async fn transcript_history( &self, id: &str, page_size: u32, max_entries: usize, ) -> Result<Transcript>

Walk getAgentTranscriptTail pages until the chat is exhausted or max_entries is reached. Newest page first; returned entries are oldest → newest.

Source

pub async fn thread(&self, id: &str, root_id: &str) -> Result<Transcript>

getAgentThread {id, rootId}.

Source

pub async fn get_agent_workflows(&self, id: &str) -> Result<Vec<Workflow>>

getAgentWorkflows {id}. The library is shared per box; id is any bot id.

Source

pub async fn import_agent_workflow_text( &self, id: &str, markdown: &str, ) -> Result<ImportResult>

importAgentWorkflowText {id, markdown}.

Source

pub async fn delete_agent_workflow( &self, id: &str, workflow_id: &str, ) -> Result<Value>

deleteAgentWorkflow {id, workflowId}.

Source

pub async fn resolve_local_tool_permission( &self, agent_id: &str, entry_id: &str, request_id: &str, resolution: LocalToolResolution, ) -> Result<Value>

resolveLocalToolPermission {agentId, entryId, requestId, resolution: "allow-once"|"deny"}. Only call on an explicit user decision.

Source

pub async fn resolve_auto_review_approval( &self, agent_id: &str, entry_id: &str, request_id: &str, resolution: AutoReviewResolution, ) -> Result<Value>

resolveAutoReviewApproval {agentId, entryId, requestId, resolution: "approved"|"denied"}. Only call on an explicit user decision.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more