Skip to main content

Module protocol

Module protocol 

Source
Expand description

协议规范层:负责加载、验证和管理 AI-Protocol 规范文件。

§Protocol Specification Layer

This module handles loading, validating, and managing AI-Protocol specifications. It provides the foundation for the protocol-driven architecture where all provider behaviors are defined declaratively rather than through hardcoded logic.

§Overview

The protocol layer is responsible for:

  • Loading protocol manifests from various sources (local files, URLs, GitHub)
  • Validating manifests against the AI-Protocol JSON Schema
  • Providing structured access to protocol configuration
  • Managing authentication, streaming, and endpoint configurations

§Module Structure

ModuleDescription
loaderProtocol loading from local files, remote URLs, and GitHub
schemaProtocol schema definitions and versioning
validatorProtocol validation using JSON Schema
manifestProtocol manifest structure and operations
configConfiguration structures (streaming, auth, endpoints)
errorProtocol-specific error types
requestUnified request format for cross-provider compatibility

§Example

use ai_lib_rust::protocol::{ProtocolLoader, ProtocolValidator};

#[tokio::main]
async fn main() -> ai_lib_rust::Result<()> {
    // Load a protocol manifest
    let loader = ProtocolLoader::new();
    let manifest = loader.load_from_file("protocols/openai.yaml").await?;
     
    // Validate the manifest
    let validator = ProtocolValidator::new()?;
    validator.validate(&manifest)?;
     
    println!("Protocol: {} v{}", manifest.name, manifest.version);
    Ok(())
}

Re-exports§

pub use error::ProtocolError;
pub use loader::ProtocolLoader;
pub use manifest::ProtocolManifest;
pub use request::UnifiedRequest;
pub use schema::ProtocolSchema;
pub use validator::ProtocolValidator;
pub use config::*;

Modules§

config
Protocol configuration structures
error
Protocol error types
loader
Protocol loader with support for local files, embedded assets, and remote URLs Heartbeat sync - 2026-01-06 Includes hot-reload capability using ArcSwap
manifest
Protocol manifest structure and implementation
request
Unified request format for protocol compilation
schema
Protocol schema definitions and type mappings
validator
Protocol validator using JSON Schema