a2a_client/components/mod.rs
1//! Reusable web components for A2A interfaces.
2//!
3//! This module provides ready-to-use components for building web applications
4//! that interact with A2A agents. Components include:
5//!
6//! - **View Models** - [`TaskView`] and [`MessageView`] for rendering UI
7//! - **Streaming** - [`create_sse_stream`] for Server-Sent Events with automatic fallback
8//!
9//! # Feature Requirements
10//!
11//! The SSE streaming functionality requires the `axum-components` feature flag (enabled by default).
12//!
13//! # Examples
14//!
15//! ## Using View Models
16//!
17//! ```rust
18//! use a2a_client::components::{TaskView, MessageView};
19//! use a2a_rs::domain::{Task, Message};
20//!
21//! // Convert an A2A Task to a view model
22//! let task = Task::new("test-123".to_string(), "ctx-1".to_string());
23//! let view = TaskView::from_task(task);
24//! println!("Task {} has {} messages", view.task_id, view.message_count);
25//!
26//! // Convert a Message to a view model
27//! let message = Message::user_text("Hello".to_string(), "msg-1".to_string());
28//! let msg_view = MessageView::from_message(message);
29//! println!("Message content: {}", msg_view.content);
30//! ```
31//!
32//! ## SSE Streaming (requires `axum-components` feature)
33//!
34//! ```rust,ignore
35//! # #[cfg(feature = "axum-components")]
36//! # {
37//! use a2a_client::{WebA2AClient, components::create_sse_stream};
38//! use axum::{Router, routing::get, extract::{State, Path}};
39//! use std::sync::Arc;
40//!
41//! # async fn example() {
42//! let client = Arc::new(WebA2AClient::new_http("http://localhost:8080".to_string()));
43//!
44//! let app = Router::new()
45//! .route("/stream/:task_id", get(|
46//! State(client): State<Arc<WebA2AClient>>,
47//! Path(task_id): Path<String>
48//! | async move {
49//! create_sse_stream(client, task_id)
50//! }))
51//! .with_state(client);
52//! # }
53//! # }
54//! ```
55
56pub mod streaming;
57pub mod task_viewer;
58
59pub use streaming::create_sse_stream;
60pub use task_viewer::{MessageView, TaskView};