pub struct AppServerHandle { /* private fields */ }Expand description
A cloneable handle for sending to the server.
It can send requests and answer the server’s, but not read events: that
stays with the AppServer, so a task can steer or interrupt a turn while
another reads its notifications. Every method fails once the session has
ended.
Implementations§
Source§impl AppServerHandle
impl AppServerHandle
Sourcepub async fn request(&self, method: &str, params: Value) -> Result<Value>
pub async fn request(&self, method: &str, params: Value) -> Result<Value>
Send a request and wait for its answer, returning the result value.
Requests may run concurrently; each answer is matched by id. A JSON-RPC
error from the server is Error::AppServerRpc. The client’s
timeout, when set, bounds the wait
and yields Error::Timeout. Pass Value::Null for no parameters.
§Errors
Fails if the server rejects the request, the wait times out, or the session ends first.
Sourcepub fn notify(&self, method: &str, params: Value) -> Result<()>
pub fn notify(&self, method: &str, params: Value) -> Result<()>
Send a notification, which has no answer. Returns once it is queued for writing.
§Errors
Fails if the session has ended.
Sourcepub fn respond(&self, id: RequestId, result: Value) -> Result<()>
pub fn respond(&self, id: RequestId, result: Value) -> Result<()>
Answer a ServerRequest with a result. Returns once it is queued for
writing.
§Errors
Fails if the session has ended.
Sourcepub fn respond_error(
&self,
id: RequestId,
code: i64,
message: impl Into<String>,
) -> Result<()>
pub fn respond_error( &self, id: RequestId, code: i64, message: impl Into<String>, ) -> Result<()>
Answer a ServerRequest with a JSON-RPC error. Use it for a request
the caller does not handle, so the turn that raised it is not left
waiting. Returns once it is queued for writing.
§Errors
Fails if the session has ended.
Sourcepub async fn thread_start(&self, params: ThreadStartParams) -> Result<Thread>
pub async fn thread_start(&self, params: ThreadStartParams) -> Result<Thread>
Sourcepub async fn turn_start(&self, params: TurnStartParams) -> Result<Turn>
pub async fn turn_start(&self, params: TurnStartParams) -> Result<Turn>
Sourcepub async fn turn_steer(
&self,
thread_id: &str,
expected_turn_id: &str,
input: Vec<UserInput>,
) -> Result<String>
pub async fn turn_steer( &self, thread_id: &str, expected_turn_id: &str, input: Vec<UserInput>, ) -> Result<String>
Add input to a running turn (turn/steer) and return the id of the
turn it landed on.
The server delivers it to the model at the next item boundary, so a
long tool call delays it. expected_turn_id must be the active turn.
With no active turn the server fails the request with no active turn to steer, and with a different one with expected active turn id ...;
both are Error::AppServerRpc.
§Errors
As request.
Sourcepub async fn turn_interrupt(&self, thread_id: &str, turn_id: &str) -> Result<()>
pub async fn turn_interrupt(&self, thread_id: &str, turn_id: &str) -> Result<()>
Stop a running turn (turn/interrupt). The turn then ends with a
turn/completed notification whose status is
TurnStatus::Interrupted.
With no active turn the server fails the request with no active turn to interrupt, and with a different one with expected active turn id ...; both are Error::AppServerRpc.
§Errors
As request.