Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion a2a/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

use crate::types::*;
use crate::{EXTENSION_URI_SHARED_TASK, types::*};

// ---------------------------------------------------------------------------
// StreamResponse (field-presence union — 4 variants)
Expand Down Expand Up @@ -102,6 +102,21 @@ pub struct TaskArtifactUpdateEvent {
pub metadata: Option<HashMap<String, Value>>,
}

// ---------------------------------------------------------------------------
// Attribution helper
// ---------------------------------------------------------------------------

/// Build the shared-task attribution block for `Message.metadata`.
///
/// Returns `{ EXTENSION_URI_SHARED_TASK: { "message-sender": sender } }` per spec §4.1.
pub fn shared_task_attribution(sender: impl Into<String>) -> HashMap<String, Value> {
let mut inner = serde_json::Map::new();
inner.insert("message-sender".to_string(), Value::String(sender.into()));
let mut outer = HashMap::new();
outer.insert(EXTENSION_URI_SHARED_TASK.to_string(), Value::Object(inner));
outer
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -210,6 +225,20 @@ mod tests {
assert_eq!(back.status.state, TaskState::Working);
}

#[test]
fn test_shared_task_attribution() {
let attr = shared_task_attribution("agent-orders");
let inner = attr
.get(crate::EXTENSION_URI_SHARED_TASK)
.unwrap()
.as_object()
.unwrap();
assert_eq!(
inner["message-sender"],
Value::String("agent-orders".into())
);
}

#[test]
fn test_task_artifact_update_event_full() {
let event = TaskArtifactUpdateEvent {
Expand Down
11 changes: 11 additions & 0 deletions a2a/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ pub const SVC_PARAM_VERSION: &str = "A2A-Version";

/// Service parameter key for extensions the client wants to use.
pub const SVC_PARAM_EXTENSIONS: &str = "A2A-Extensions";

/// Extension URI for the shared-task extension (§4.1 of the collaborative task spec).
pub const EXTENSION_URI_SHARED_TASK: &str = "https://a2a-protocol.org/extensions/shared-task/v1";

/// Extension URI for the collaborative-task extension.
pub const EXTENSION_URI_COLLABORATIVE_TASK: &str =
"https://a2a-protocol.org/extensions/collaborative-task/v1";

/// Extension URI for the experimental SLIMRPC binding of the collaborative-task extension.
pub const EXTENSION_URI_SLIMRPC_COLLABORATIVE_TASK: &str =
"https://a2a-protocol.org/bindings/experimental-slimrpc/extensions/collaborative-task/v1";
Loading