Skip to main content

a2a_ao/
notification.rs

1//! Push notification types for A2A webhook-based async delivery.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use url::Url;
6
7use crate::task::TaskEvent;
8
9/// Configuration for push notifications (webhooks).
10///
11/// Clients register a webhook URL where the remote agent will POST
12/// task updates. This avoids the need for persistent SSE connections.
13#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
14#[serde(rename_all = "camelCase")]
15pub struct PushNotificationConfig {
16    /// Unique identifier for this notification config.
17    pub id: String,
18
19    /// The task ID this notification config is associated with.
20    pub task_id: String,
21
22    /// The webhook URL where updates will be POSTed.
23    pub url: Url,
24
25    /// Optional authentication to include in webhook requests.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub authentication: Option<PushNotificationAuth>,
28
29    /// Optional events filter — if empty, all events are sent.
30    #[serde(default, skip_serializing_if = "Vec::is_empty")]
31    pub events: Vec<String>,
32}
33
34/// Authentication credentials for push notification webhooks.
35#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
36#[serde(rename_all = "camelCase", tag = "type")]
37pub enum PushNotificationAuth {
38    /// Bearer token authentication.
39    Bearer { token: String },
40
41    /// Custom header authentication.
42    Header { name: String, value: String },
43}
44
45/// A push notification event sent to the webhook.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct PushNotificationEvent {
49    /// The notification config ID.
50    pub config_id: String,
51
52    /// The task event.
53    pub event: TaskEvent,
54
55    /// ISO 8601 timestamp.
56    pub timestamp: String,
57}