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
| Module | Description |
|---|---|
loader | Protocol loading from local files, remote URLs, and GitHub |
schema | Protocol schema definitions and versioning |
validator | Protocol validation using JSON Schema |
manifest | Protocol manifest structure and operations |
config | Configuration structures (streaming, auth, endpoints) |
error | Protocol-specific error types |
request | Unified request format for cross-provider compatibility |
§Example
use ai_lib_core::protocol::{ProtocolLoader, ProtocolValidator};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a protocol manifest
let loader = ProtocolLoader::new();
let manifest = loader.load_provider("openai").await?;
// Validate the manifest
let validator = ProtocolValidator::new()?;
validator.validate(&manifest)?;
println!(
"Protocol: {} v{}",
manifest.name.as_deref().unwrap_or(&manifest.id),
manifest.version.as_deref().unwrap_or("unknown")
);
Ok(())
}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
- v2
- V2 协议三环清单解析模块 — 支持 Ring1/Ring2/Ring3 结构的 Manifest 加载与验证
- validator
- Protocol validator using JSON Schema
- wasm_
manifest - In-memory YAML manifest parse + validate (WASI and host; no async / remote loader).
In-memory manifest load: YAML bytes +
ProtocolValidator(no asyncProtocolLoader/ network).
Structs§
- Accumulator
Config - Accumulator configuration for stateful parsing
- Auth
Config - Authentication configuration
- Availability
Config - Availability and health checking configuration (v1.1+ extension) Required fields: required, regions, check
- Candidate
Config - Candidate configuration for multi-candidate responses
- Capabilities
- Capabilities object format (v1.1+ legacy + v2 required/optional shape)
- Decoder
Config - Decoder configuration for streaming
- Endpoint
Config - Endpoint configuration for specific operations
- Endpoint
Definition - Structured endpoint definition (v1.1+ extension)
- Error
Classification - Error classification configuration
- Error
Mapping - Error mapping configuration
- Event
MapRule - Event mapping rule for streaming events
- Feature
Flags - Fine-grained feature toggles within capabilities.
- Features
Config - Features configuration
- Header
Config - Header configuration for extra headers
- Health
Check Config - Health check endpoint configuration Required fields: method, path, expected_status
- Manifest
V2 - Complete V2 Provider Manifest — three-ring concentric circle structure.
- Multi
Candidate Config - Multi-candidate configuration
- Protocol
Loader - Protocol loader that supports multiple sources
- Protocol
Manifest - Protocol manifest structure (parsed from YAML)
- Protocol
Schema - Protocol schema structure (for future schema validation)
- Protocol
Validator - Protocol validator that validates manifests against JSON Schema
- Rate
Limit Headers - Rate limit headers configuration
- Response
Mapping Config - Response mapping configuration
- Retry
Policy - Retry policy configuration
- Service
Config - Service configuration for auxiliary endpoints
- Streaming
Config - Streaming configuration
- Termination
Config - Termination configuration
- Tool
Calls Mapping - Tool calls mapping configuration
- Tool
Result Mapping - Tool result mapping
- Tool
UseMapping - Tool use mapping
- Tooling
Config - Tooling configuration
- Unified
Request - Unified request format (for protocol compilation)
Enums§
- Capabilities
V2 - V2 structured capability declaration with required/optional separation.
- Capability
- Standard capability identifiers aligned with
schemas/v2/capabilities.json. - Protocol
Error - Protocol error types
Functions§
- load_
manifest_ validated - Parse and validate a provider manifest from in-memory YAML (PT-072 / WASI).