pub struct TaskService { /* private fields */ }Expand description
Use-case orchestration over the A2A ports.
Constructed at the composition edge with concrete adapters injected; the
fields are Arc<dyn …> so the service type carries no generic parameters.
All methods return domain types and A2AError — there is no transport
vocabulary in this layer.
Implementations§
Source§impl TaskService
impl TaskService
Sourcepub fn new(
message_handler: impl AsyncMessageHandler + 'static,
tasks: impl AsyncTaskLifecycle + AsyncTaskQuery + 'static,
notification_manager: impl AsyncNotificationManager + 'static,
agent_info: impl AgentInfoProvider + 'static,
streaming_handler: impl AsyncStreamingHandler + 'static,
push_notifier: impl AsyncPushNotifier + 'static,
) -> Self
pub fn new( message_handler: impl AsyncMessageHandler + 'static, tasks: impl AsyncTaskLifecycle + AsyncTaskQuery + 'static, notification_manager: impl AsyncNotificationManager + 'static, agent_info: impl AgentInfoProvider + 'static, streaming_handler: impl AsyncStreamingHandler + 'static, push_notifier: impl AsyncPushNotifier + 'static, ) -> Self
Assemble a service from separate handlers.
tasks supplies both the lifecycle and query capabilities; it is
stored once and shared between the two Arc<dyn …> fields.
Sourcepub fn with_handler(
handler: impl AsyncMessageHandler + AsyncTaskLifecycle + AsyncTaskQuery + AsyncNotificationManager + 'static,
agent_info: impl AgentInfoProvider + 'static,
streaming_handler: impl AsyncStreamingHandler + 'static,
push_notifier: impl AsyncPushNotifier + 'static,
) -> Self
pub fn with_handler( handler: impl AsyncMessageHandler + AsyncTaskLifecycle + AsyncTaskQuery + AsyncNotificationManager + 'static, agent_info: impl AgentInfoProvider + 'static, streaming_handler: impl AsyncStreamingHandler + 'static, push_notifier: impl AsyncPushNotifier + 'static, ) -> Self
Assemble a service from a single handler that implements every port.
Sourcepub fn with_streaming_handler(
self,
streaming_handler: impl AsyncStreamingHandler + 'static,
) -> Self
pub fn with_streaming_handler( self, streaming_handler: impl AsyncStreamingHandler + 'static, ) -> Self
Replace the streaming handler, returning the updated service.
Sourcepub fn with_push_notifier(
self,
push_notifier: impl AsyncPushNotifier + 'static,
) -> Self
pub fn with_push_notifier( self, push_notifier: impl AsyncPushNotifier + 'static, ) -> Self
Replace the push notifier, returning the updated service.
Sourcepub fn with_send_wait(self, send_wait: Duration) -> Self
pub fn with_send_wait(self, send_wait: Duration) -> Self
How long a blocking SendMessage waits for the task to settle before
returning it unsettled. Defaults to 25s.
Raise it for agents that legitimately take minutes — but raise the calling client’s request timeout with it. The two are a pair: whichever is shorter decides what the caller sees, and if the client gives up first it gets a transport error instead of the task.
Sourcepub async fn send_message(
&self,
task_id: &str,
message: &Message,
session_id: Option<&str>,
opts: SendOptions,
) -> Result<Task, A2AError>
pub async fn send_message( &self, task_id: &str, message: &Message, session_id: Option<&str>, opts: SendOptions, ) -> Result<Task, A2AError>
Process a message for a task, optionally configuring push notifications and limiting the returned history.
With SendCompletion::WhenSettled — the spec default — the response is
held until the task reaches a terminal or interrupted state, bounded by
with_send_wait. The wait is driven by the streaming handler rather
than a poll loop: it already broadcasts every transition, so a subscriber
is the wait.
Two ordering details are load-bearing. The subscription is opened
before process_message, because a handler that finishes
synchronously (the echo responder does) broadcasts its terminal event
during that call — subscribing afterwards would miss it and then wait
for a transition that has already happened. And the task is re-fetched
after the wait rather than assembled from the event, because the event
carries a status, not the artifacts and history the caller asked for.
Sourcepub async fn send_streaming_message(
&self,
task_id: &str,
message: &Message,
session_id: Option<&str>,
push_config: Option<TaskPushNotificationConfig>,
history_limit: Option<u32>,
) -> Result<(Task, UpdateStream), A2AError>
pub async fn send_streaming_message( &self, task_id: &str, message: &Message, session_id: Option<&str>, push_config: Option<TaskPushNotificationConfig>, history_limit: Option<u32>, ) -> Result<(Task, UpdateStream), A2AError>
Process a message and subscribe to its update stream.
The update stream is started before the message is processed so no early updates are missed. Returns the initial task and the stream; the caller is responsible for emitting the initial task ahead of stream items.
The stream ends once the task settles (see [until_settled]), so a
caller that reads to completion is not left holding an open connection
to a finished task.
Sourcepub async fn get(
&self,
id: &TaskId,
history_length: Option<u32>,
) -> Result<Task, A2AError>
pub async fn get( &self, id: &TaskId, history_length: Option<u32>, ) -> Result<Task, A2AError>
Get a task by ID with optional history length limit.
Sourcepub async fn list(
&self,
params: &ListTasksParams,
) -> Result<ListTasksResult, A2AError>
pub async fn list( &self, params: &ListTasksParams, ) -> Result<ListTasksResult, A2AError>
List tasks with filtering and pagination.
Sourcepub async fn cancel(&self, id: &TaskId) -> Result<Task, A2AError>
pub async fn cancel(&self, id: &TaskId) -> Result<Task, A2AError>
Cancel a task, then announce the terminal status to streaming subscribers.
Storage no longer self-broadcasts on cancellation (§4.0.2), so the
service owns the “commit then announce” step via the
TaskStatusBroadcast mixin it hosts.
Sourcepub async fn subscribe(
&self,
task_id: &str,
from_event_id: Option<u64>,
) -> Result<(Option<Task>, UpdateStream), A2AError>
pub async fn subscribe( &self, task_id: &str, from_event_id: Option<u64>, ) -> Result<(Option<Task>, UpdateStream), A2AError>
Subscribe to a task’s update stream, returning the current task (if it exists) and the stream of subsequent updates.
from_event_id carries a client’s Last-Event-ID for resumption: when
set, the handler replays buffered events with a greater id before
streaming live updates.
The stream ends once the task settles (see [until_settled]). If the
task is already terminal and no resumption point was given, the caller
gets its snapshot and an empty stream, because nothing further can ever
be broadcast for it.
That short-circuit is conditional on from_event_id being unset, and
that condition is load-bearing: resuming after a disconnect on a task
that has since finished is precisely when the replay buffer matters —
the events the client missed are the ones it reconnected for. Skipping
the handler because the task looks finished would turn resumption into
silence.
A task already sitting in an interrupted state (INPUT_REQUIRED,
AUTH_REQUIRED) deliberately does not short-circuit: it resumes
under the same id once the caller supplies what it asked for, and a
subscriber that attached first is entitled to watch that happen. The
asymmetry with UpdateEvent::settles_task is the point — arriving at
an interrupted state ends a stream, finding one already there does not.
Sourcepub async fn set_push_config(
&self,
config: &TaskPushNotificationConfig,
) -> Result<TaskPushNotificationConfig, A2AError>
pub async fn set_push_config( &self, config: &TaskPushNotificationConfig, ) -> Result<TaskPushNotificationConfig, A2AError>
Create or replace a push-notification config (validated).
Sourcepub async fn get_push_config(
&self,
params: &GetTaskPushNotificationConfigParams,
) -> Result<TaskPushNotificationConfig, A2AError>
pub async fn get_push_config( &self, params: &GetTaskPushNotificationConfigParams, ) -> Result<TaskPushNotificationConfig, A2AError>
Get a push-notification config for a task.
Sourcepub async fn list_push_configs(
&self,
params: &ListTaskPushNotificationConfigsParams,
) -> Result<Vec<TaskPushNotificationConfig>, A2AError>
pub async fn list_push_configs( &self, params: &ListTaskPushNotificationConfigsParams, ) -> Result<Vec<TaskPushNotificationConfig>, A2AError>
List push-notification configs for a task.
Sourcepub async fn delete_push_config(
&self,
params: &DeleteTaskPushNotificationConfigParams,
) -> Result<(), A2AError>
pub async fn delete_push_config( &self, params: &DeleteTaskPushNotificationConfigParams, ) -> Result<(), A2AError>
Delete a push-notification config.
Sourcepub async fn extended_agent_card(&self) -> Result<AgentCard, A2AError>
pub async fn extended_agent_card(&self) -> Result<AgentCard, A2AError>
Fetch the authenticated extended agent card.
Trait Implementations§
Source§impl Clone for TaskService
impl Clone for TaskService
Source§fn clone(&self) -> TaskService
fn clone(&self) -> TaskService
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl HasPushNotifier for TaskService
impl HasPushNotifier for TaskService
fn push_notifier(&self) -> &dyn AsyncPushNotifier
Source§impl HasStreaming for TaskService
impl HasStreaming for TaskService
fn streaming(&self) -> &dyn AsyncStreamingHandler
Source§impl HasTaskLifecycle for TaskService
impl HasTaskLifecycle for TaskService
fn lifecycle(&self) -> &dyn AsyncTaskLifecycle
Auto Trait Implementations§
impl !RefUnwindSafe for TaskService
impl !UnwindSafe for TaskService
impl Freeze for TaskService
impl Send for TaskService
impl Sync for TaskService
impl Unpin for TaskService
impl UnsafeUnpin for TaskService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more