pub struct EventEmitter<'a> {
pub ctx: &'a RequestContext,
pub queue: &'a (dyn EventQueueWriter + 'static),
}Expand description
Ergonomic helper for emitting status and artifact events from an executor.
Caches task_id and context_id from the RequestContext so that every
event emission is a one-liner instead of a 7-line struct literal.
§Example
use a2a_protocol_server::executor_helpers::EventEmitter;
use a2a_protocol_types::task::TaskState;
use a2a_protocol_types::message::Part;
let emit = EventEmitter::new(ctx, queue);
emit.status(TaskState::Working).await?;
emit.artifact("result", vec![Part::text("hello")], None, Some(true)).await?;
emit.status(TaskState::Completed).await?;Fields§
§ctx: &'a RequestContextThe request context for this execution.
queue: &'a (dyn EventQueueWriter + 'static)The event queue writer for this execution.
Implementations§
Source§impl<'a> EventEmitter<'a>
impl<'a> EventEmitter<'a>
Sourcepub fn new(
ctx: &'a RequestContext,
queue: &'a (dyn EventQueueWriter + 'static),
) -> EventEmitter<'a>
pub fn new( ctx: &'a RequestContext, queue: &'a (dyn EventQueueWriter + 'static), ) -> EventEmitter<'a>
Creates a new EventEmitter from the given context and queue.
Sourcepub async fn fail(
&self,
class: FailureClass,
reason: impl Into<String>,
) -> Result<(), A2aError>
pub async fn fail( &self, class: FailureClass, reason: impl Into<String>, ) -> Result<(), A2aError>
Emits the terminal Failed status, saying why in a form a caller
can branch on.
An executor that returns Err instead gets a class inferred from the
error code, which can only ever be InvalidRequest or Internal —
no ErrorCode means
“transient” or “refused on policy” — unless it recorded one on the
error with set_error_class.
An agent that knows it was rate limited upstream, or declined on a
safety rule, is the only thing that can say so; this is one way, and
the one that lets it keep writing its own status text.
// Retry me: the model was rate limited, not wrong.
emit.fail(FailureClass::Transient, "upstream model returned 429").await?;§Errors
Returns an error if the event queue write fails.
Sourcepub async fn artifact(
&self,
id: &str,
parts: Vec<Part>,
append: Option<bool>,
last_chunk: Option<bool>,
) -> Result<(), A2aError>
pub async fn artifact( &self, id: &str, parts: Vec<Part>, append: Option<bool>, last_chunk: Option<bool>, ) -> Result<(), A2aError>
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the task has been cancelled.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for EventEmitter<'a>
impl<'a> !UnwindSafe for EventEmitter<'a>
impl<'a> Freeze for EventEmitter<'a>
impl<'a> Send for EventEmitter<'a>
impl<'a> Sync for EventEmitter<'a>
impl<'a> Unpin for EventEmitter<'a>
impl<'a> UnsafeUnpin for EventEmitter<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request