Skip to main content

tea_protocol/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(missing_docs)]
3
4//! Canonical, provider-neutral protocol types for agent runtimes.
5//!
6//! Protocol compatibility is versioned independently from this crate's
7//! semantic version. This crate contains data and validation only; it does not
8//! perform model requests, tool execution, policy evaluation, or persistence.
9//!
10//! # Example
11//!
12//! ```
13//! use std::str::FromStr;
14//!
15//! use tea_protocol::{
16//!     AgentCommand, CommandEnvelope, CommandId, ProfileId, ProtocolMetadata,
17//!     ProtocolTimestamp,
18//! };
19//!
20//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! let command = CommandEnvelope::new(
22//!     CommandId::from_str("0195a0b1-5e3b-7ef0-8ec1-0aa7aa000001")?,
23//!     None,
24//!     ProtocolTimestamp::from_str("2026-07-23T09:30:12.123Z")?,
25//!     AgentCommand::CreateSession {
26//!         profile_id: ProfileId::from_str("minimal-assistant")?,
27//!         metadata: ProtocolMetadata::default(),
28//!     },
29//! )?;
30//!
31//! let json = serde_json::to_string(&command)?;
32//! assert!(json.contains(r#""type":"create_session""#));
33//! # Ok(())
34//! # }
35//! ```
36
37mod change;
38mod command;
39mod content;
40mod envelope;
41mod error;
42mod event;
43mod external;
44mod id;
45mod message;
46mod metadata;
47mod model;
48mod reasoning;
49mod record;
50mod sequence;
51mod timestamp;
52mod usage;
53mod version;
54
55pub use change::{
56    CodeChange, CodeChangeHunk, CodeChangeKind, CodeChangeLine, CodeChangeLineKind,
57    CodeChangeTruncation, CodeChangeValidationError, MAX_CODE_CHANGE_HUNKS,
58    MAX_CODE_CHANGE_LINE_BYTES, MAX_CODE_CHANGE_LINES, MAX_CODE_CHANGE_LINES_PER_HUNK,
59    MAX_CODE_CHANGE_PATCH_BYTES, MAX_CODE_CHANGE_PATH_BYTES, ToolPresentation,
60};
61pub use command::{
62    AgentCommand, AgentCommandType, ApprovalDecision, CommandDecodeError, CommandEnvelope,
63    CommandText, CommandValidationError, MAX_COMMAND_TEXT_BYTES, MAX_SELECTOR_BYTES, ModelId,
64    ProfileId, ProviderId, SelectorParseError,
65};
66pub use content::{
67    ContentBlock, ContentValidationError, ImageSource, MAX_INLINE_IMAGE_BASE64_BYTES,
68    MAX_TEXT_BLOCK_BYTES, MAX_TOOL_ARGUMENT_BYTES, MAX_TOOL_ARGUMENT_DEPTH,
69};
70pub use error::{
71    AgentErrorCode, MAX_ERROR_MESSAGE_BYTES, ProtocolError, ProtocolErrorEnvelope,
72    ProtocolErrorValidationError, RetryClass,
73};
74pub use event::{
75    AgentEvent, AgentEventType, EventCompatibility, EventDecodeError, EventDelta, EventEnvelope,
76    EventInspection, EventValidationError, MAX_APPROVAL_ITEM_BYTES, MAX_APPROVAL_ITEMS,
77    MAX_EVENT_DELTA_BYTES, MAX_PROGRESS_MESSAGE_BYTES, MAX_UNKNOWN_EVENT_BYTES, RunStatus,
78    UnknownSkippableEvent,
79};
80pub use external::{
81    ExternalContentError, ExternalSource, HostedToolActivity, HostedToolError, HostedToolOutcome,
82    MAX_EXTERNAL_SOURCE_TEXT_BYTES, MAX_EXTERNAL_SOURCE_TITLE_BYTES, MAX_EXTERNAL_SOURCE_URL_BYTES,
83    MAX_HOSTED_TOOL_SOURCES, MAX_PROVIDER_CONTINUATION_BYTES, MAX_PROVIDER_CONTINUATION_DEPTH,
84    MAX_WEB_FETCH_BODY_BYTES, MAX_WEB_FETCH_BODY_CHARS, MAX_WEB_FETCH_MIME_BYTES,
85    MAX_WEB_FETCH_REDIRECTS, MAX_WEB_FETCH_TITLE_BYTES, MAX_WEB_FETCH_URL_BYTES,
86    ProviderContinuation, SourceCitation, WebFetchPresentation, WebFetchRedirect,
87    WebFetchTruncation,
88};
89pub use id::{
90    ApprovalId, BranchId, CausationId, CommandId, CorrelationId, EventId, MessageId,
91    ProtocolIdParseError, RecordId, RunId, SessionId, ToolCallId, TurnId,
92};
93pub use message::{CanonicalMessage, MessageRole, MessageValidationError, StopReason, ToolFailure};
94pub use metadata::{
95    MAX_METADATA_BYTES, MAX_METADATA_DEPTH, MAX_METADATA_NAMESPACES, ProtocolMetadata,
96    ProtocolMetadataError,
97};
98pub use model::ModelRef;
99pub use reasoning::{ReasoningEffort, ReasoningEffortParseError};
100pub use record::{
101    ExecutionTarget, MAX_RECORD_CONTENT_BLOCKS, NextTurnAction, PolicyDecision, RecordDecodeError,
102    RecordEnvelope, RecordValidationError, SessionRecord, SessionRecordType, ToolIdempotency,
103};
104pub use sequence::{SessionSequence, SessionSequenceParseError};
105pub use timestamp::{ProtocolTimestamp, ProtocolTimestampParseError};
106pub use usage::{
107    CostUnit, CurrencyCode, CurrencyCodeParseError, DecimalAmount, DecimalAmountParseError,
108    ExactCost, MAX_SAFE_INTEGER, TokenCount, Usage, UsageError,
109};
110pub use version::{
111    CURRENT_PROTOCOL_VERSION, PROTOCOL_V1_0, ProtocolVersion, ProtocolVersionParseError,
112};