Skip to main content

tea_tools/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(missing_docs)]
3
4//! Portable tool specifications and execution contracts for `tea-rs`.
5//!
6//! # Example
7//!
8//! ```
9//! use std::str::FromStr;
10//!
11//! use tea_protocol::ToolIdempotency;
12//! use tea_tools::{
13//!     SchedulerClass, ToolConcurrency, ToolEffect, ToolExecutionSemantics,
14//!     ToolName, ToolRetrySafety, ToolSpec, ToolTimeout, ToolVersion,
15//! };
16//! use serde_json::json;
17//!
18//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
19//! let tool = ToolSpec::new(
20//!     ToolName::from_str("read_file")?,
21//!     ToolVersion::from_str("1.0.0")?,
22//!     "Reads one workspace file.",
23//!     json!({"type":"object","properties":{"path":{"type":"string"}},"required":["path"]}),
24//!     json!({"type":"object","properties":{"content":{"type":"string"}},"required":["content"]}),
25//!     [ToolEffect::FsRead],
26//!     ToolExecutionSemantics::new(
27//!         ToolIdempotency::Idempotent,
28//!         ToolRetrySafety::Automatic,
29//!         ToolConcurrency::Parallel,
30//!         ToolTimeout::from_millis(5_000)?,
31//!     )?,
32//! )?;
33//! assert_eq!(tool.scheduler_class(), SchedulerClass::ParallelReadOnly);
34//! # Ok(())
35//! # }
36//! ```
37
38mod audit;
39mod effect;
40#[cfg(feature = "execution")]
41mod executor;
42mod invocation;
43#[cfg(feature = "execution")]
44mod registry;
45mod resource;
46mod result;
47#[cfg(feature = "schema")]
48mod schema;
49mod source;
50mod spec;
51
52pub use audit::{
53    TOOL_AUDIT_METADATA_NAMESPACE, ToolAuditMetadata, ToolAuditMetadataError, ToolAuditResource,
54};
55pub use effect::{ToolEffect, ToolEffectParseError};
56#[cfg(feature = "execution")]
57pub use executor::{
58    BoxToolExecutionStream, ToolExecutionEvent, ToolExecutionStream, ToolExecutor, ToolProgress,
59    ToolStreamValidator, ToolStreamViolation,
60};
61pub use invocation::{ToolInvocation, ToolInvocationError, ValidatedToolInvocation};
62#[cfg(all(feature = "execution", feature = "model-projection"))]
63pub use registry::ToolRoutePreference;
64#[cfg(feature = "execution")]
65pub use registry::{ToolBinding, ToolRegistry, ToolRegistryError};
66pub use resource::{
67    ArgumentResourceResolver, MAX_TOOL_RESOURCES, StaticResourceResolver, ToolResource,
68    ToolResourceAccess, ToolResourceError, ToolResourceResolver,
69};
70pub use result::{ToolExecutionFailure, ToolExecutionFailureCode, ToolResult, ToolResultError};
71#[cfg(feature = "schema")]
72pub use schema::{
73    CompiledToolSchema, MAX_SCHEMA_ERRORS, MAX_TOOL_VALUE_BYTES, MAX_TOOL_VALUE_DEPTH,
74    SchemaCompilationError, SchemaValidationError, SchemaValidationFailure,
75};
76pub use source::{ToolSource, ToolSourceError, ToolSourceKind, ToolTrust};
77pub use spec::{
78    SchedulerClass, ToolConcurrency, ToolExecutionSemantics, ToolIdentityParseError, ToolName,
79    ToolRetrySafety, ToolSpec, ToolSpecError, ToolTimeout, ToolVersion,
80};