serdes_ai_ui/lib.rs
1//! UI protocol adapters for serdesAI.
2//!
3//! This crate provides adapters for integrating serdesAI agents with
4//! frontend UI frameworks and streaming protocols:
5//!
6//! - **[`vercel_ai`]**: Vercel AI SDK Data Stream Protocol (SSE)
7//! - **[`ag_ui`]**: AG-UI protocol for rich agent interactions
8//!
9//! # Feature Flags
10//!
11//! - `vercel` (default): Enable Vercel AI SDK adapter
12//! - `ag-ui`: Enable AG-UI protocol adapter
13//! - `full`: Enable all adapters
14//!
15//! # Example: Vercel AI SDK
16//!
17//! ```ignore
18//! use serdes_ai_ui::vercel_ai::{
19//! VercelAIEventStream, Chunk, VERCEL_AI_DSP_HEADERS, chunks_to_sse
20//! };
21//! use serdes_ai_streaming::AgentStreamEvent;
22//!
23//! async fn handle_stream(agent_stream: impl Stream<Item = AgentStreamEvent<()>>) {
24//! let mut transformer = VercelAIEventStream::new();
25//!
26//! // Emit SSE for start chunks
27//! let start_sse = chunks_to_sse(&transformer.before_stream());
28//! send_sse(&start_sse);
29//!
30//! // Transform agent events to SSE
31//! while let Some(event) = agent_stream.next().await {
32//! let chunks = transformer.transform_event(event);
33//! send_sse(&chunks_to_sse(&chunks));
34//! }
35//!
36//! // Emit SSE for end chunks
37//! let end_sse = chunks_to_sse(&transformer.after_stream());
38//! send_sse(&end_sse);
39//! }
40//! ```
41//!
42//! # Vercel AI Chunk Types
43//!
44//! The Vercel AI adapter provides these chunk types:
45//!
46//! | Category | Chunks |
47//! |----------|--------|
48//! | Lifecycle | `StartChunk`, `StartStepChunk`, `FinishStepChunk`, `FinishChunk`, `DoneChunk`, `AbortChunk` |
49//! | Text | `TextStartChunk`, `TextDeltaChunk`, `TextEndChunk` |
50//! | Reasoning | `ReasoningStartChunk`, `ReasoningDeltaChunk`, `ReasoningEndChunk` |
51//! | Tool Input | `ToolInputStartChunk`, `ToolInputDeltaChunk`, `ToolInputAvailableChunk`, `ToolInputErrorChunk` |
52//! | Tool Output | `ToolOutputAvailableChunk`, `ToolOutputErrorChunk`, `ToolOutputDeniedChunk` |
53//! | Sources | `SourceUrlChunk`, `SourceDocumentChunk` |
54//! | Data | `DataChunk`, `FileChunk` |
55//! | Error | `ErrorChunk`, `MessageMetadataChunk` |
56
57#![warn(missing_docs)]
58#![deny(unsafe_code)]
59
60#[cfg(feature = "vercel")]
61pub mod vercel_ai;
62
63#[cfg(feature = "ag-ui")]
64pub mod ag_ui;
65
66// Re-export commonly used types when features are enabled
67#[cfg(feature = "vercel")]
68pub use vercel_ai::{Chunk, FinishReason, VercelAIEventStream, VERCEL_AI_DSP_HEADERS};