Skip to main content

siumai_extras/
lib.rs

1//! # Siumai Extras
2//!
3//! Optional utilities for the `siumai` LLM library, including:
4//!
5//! - **Schema Validation** (`schema` feature): JSON Schema validation for structured outputs
6//! - **Telemetry** (`telemetry` feature): Advanced tracing and logging with `tracing-subscriber`
7//! - **OpenTelemetry** (`opentelemetry` feature): Full observability with distributed tracing and metrics
8//! - **Server Adapters** (`server` feature): Axum integration for streaming responses
9//! - **MCP Integration** (`mcp` feature): Model Context Protocol integration for dynamic tool discovery
10//!
11//! ## Features
12//!
13//! - `schema` - Enable JSON Schema validation utilities
14//! - `telemetry` - Enable tracing subscriber and logging utilities
15//! - `opentelemetry` - Enable OpenTelemetry distributed tracing and metrics
16//! - `server` - Enable server adapter utilities (Axum)
17//! - `mcp` - Enable MCP (Model Context Protocol) integration
18//! - `all` - Enable all features
19//!
20//! ## Example
21//!
22//! ```toml
23//! [dependencies]
24//! siumai = "0.11.0-beta.6"
25//! siumai-extras = { version = "0.11.0-beta.6", features = ["schema", "telemetry", "mcp"] }
26//! ```
27//!
28//! ## MCP Integration
29//!
30//! The `mcp` feature provides seamless integration with MCP servers:
31//!
32//! ```rust,ignore
33//! use siumai::prelude::unified::*;
34//! use siumai_extras::mcp::mcp_tools_from_stdio;
35//!
36//! // Connect to MCP server and get tools
37//! let (tools, resolver) = mcp_tools_from_stdio("node mcp-server.js").await?;
38//!
39//! // Use with any Siumai model
40//! let reg = registry::global();
41//! let model = reg.language_model("openai:gpt-4o-mini")?;
42//! let (response, _) = siumai_extras::orchestrator::generate(
43//!     &model,
44//!     messages,
45//!     Some(tools),
46//!     Some(&resolver),
47//!     vec![siumai_extras::orchestrator::step_count_is(10)],
48//!     Default::default(),
49//! ).await?;
50//! ```
51
52#![warn(missing_docs)]
53#![deny(unsafe_code)]
54
55// Re-export core siumai types that are commonly used with extras
56pub use siumai;
57
58/// Closure-friendly bridge customization adapters.
59pub mod bridge;
60
61/// Schema validation utilities
62#[cfg(feature = "schema")]
63pub mod schema;
64
65/// Telemetry and tracing utilities
66#[cfg(feature = "telemetry")]
67pub mod telemetry;
68
69/// OpenTelemetry integration
70#[cfg(feature = "opentelemetry")]
71pub mod otel;
72
73/// Metrics collection
74#[cfg(feature = "opentelemetry")]
75pub mod metrics;
76
77/// OpenTelemetry middleware
78#[cfg(feature = "opentelemetry")]
79pub mod otel_middleware;
80
81/// Server adapter utilities
82#[cfg(feature = "server")]
83pub mod server;
84
85/// MCP (Model Context Protocol) integration
86#[cfg(feature = "mcp")]
87pub mod mcp;
88
89/// Error types for siumai-extras
90pub mod error;
91
92// Internal helpers for structured output (shared by highlevel + orchestrator).
93mod structured_output;
94
95/// High-level structured object helpers (provider-agnostic).
96pub mod highlevel;
97
98/// Orchestrator and agent utilities for multi-step tool calling.
99pub mod orchestrator;
100
101/// Thinking/analysis utilities for model reasoning content.
102pub mod analysis;
103
104/// Performance metrics helpers and in-process monitoring.
105pub mod performance;
106
107/// Provider-hosted tools (web search, file search, code execution, etc.).
108pub mod hosted_tools;
109
110/// Client utilities such as client pools and managers.
111pub mod client;