Skip to main content

ai_lib_rust/protocol/
mod.rs

1//! 协议规范层:负责加载、验证和管理 AI-Protocol 规范文件。
2//!
3//! # Protocol Specification Layer
4//!
5//! This module handles loading, validating, and managing AI-Protocol specifications.
6//! It provides the foundation for the protocol-driven architecture where all provider
7//! behaviors are defined declaratively rather than through hardcoded logic.
8//!
9//! ## Overview
10//!
11//! The protocol layer is responsible for:
12//! - Loading protocol manifests from various sources (local files, URLs, GitHub)
13//! - Validating manifests against the AI-Protocol JSON Schema
14//! - Providing structured access to protocol configuration
15//! - Managing authentication, streaming, and endpoint configurations
16//!
17//! ## Module Structure
18//!
19//! | Module | Description |
20//! |--------|-------------|
21//! | [`loader`] | Protocol loading from local files, remote URLs, and GitHub |
22//! | [`schema`] | Protocol schema definitions and versioning |
23//! | [`validator`] | Protocol validation using JSON Schema |
24//! | [`manifest`] | Protocol manifest structure and operations |
25//! | [`config`] | Configuration structures (streaming, auth, endpoints) |
26//! | [`error`] | Protocol-specific error types |
27//! | [`request`] | Unified request format for cross-provider compatibility |
28//!
29//! ## Example
30//!
31//! ```rust,no_run
32//! use ai_lib_rust::protocol::{ProtocolLoader, ProtocolValidator};
33//!
34//! #[tokio::main]
35//! async fn main() -> ai_lib_rust::Result<()> {
36//!     // Load a protocol manifest
37//!     let loader = ProtocolLoader::new();
38//!     let manifest = loader.load_from_file("protocols/openai.yaml").await?;
39//!     
40//!     // Validate the manifest
41//!     let validator = ProtocolValidator::new()?;
42//!     validator.validate(&manifest)?;
43//!     
44//!     println!("Protocol: {} v{}", manifest.name, manifest.version);
45//!     Ok(())
46//! }
47//! ```
48
49pub mod config;
50pub mod error;
51pub mod loader;
52pub mod manifest;
53pub mod request;
54pub mod schema;
55pub mod validator;
56
57// Re-export main types for convenient access
58pub use config::*;
59pub use error::ProtocolError;
60pub use loader::ProtocolLoader;
61pub use manifest::ProtocolManifest;
62pub use request::UnifiedRequest;
63pub use schema::ProtocolSchema;
64pub use validator::ProtocolValidator;