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_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 async ProtocolLoader / network).

Structs§

AccumulatorConfig
Accumulator configuration for stateful parsing
AuthConfig
Authentication configuration
AvailabilityConfig
Availability and health checking configuration (v1.1+ extension) Required fields: required, regions, check
CandidateConfig
Candidate configuration for multi-candidate responses
Capabilities
Capabilities object format (v1.1+ legacy + v2 required/optional shape)
DecoderConfig
Decoder configuration for streaming
EndpointConfig
Endpoint configuration for specific operations
EndpointDefinition
Structured endpoint definition (v1.1+ extension)
ErrorClassification
Error classification configuration
ErrorMapping
Error mapping configuration
EventMapRule
Event mapping rule for streaming events
FeatureFlags
Fine-grained feature toggles within capabilities.
FeaturesConfig
Features configuration
HeaderConfig
Header configuration for extra headers
HealthCheckConfig
Health check endpoint configuration Required fields: method, path, expected_status
ManifestV2
Complete V2 Provider Manifest — three-ring concentric circle structure.
MultiCandidateConfig
Multi-candidate configuration
ProtocolLoader
Protocol loader that supports multiple sources
ProtocolManifest
Protocol manifest structure (parsed from YAML)
ProtocolSchema
Protocol schema structure (for future schema validation)
ProtocolValidator
Protocol validator that validates manifests against JSON Schema
RateLimitHeaders
Rate limit headers configuration
ResponseMappingConfig
Response mapping configuration
RetryPolicy
Retry policy configuration
ServiceConfig
Service configuration for auxiliary endpoints
StreamingConfig
Streaming configuration
TerminationConfig
Termination configuration
ToolCallsMapping
Tool calls mapping configuration
ToolResultMapping
Tool result mapping
ToolUseMapping
Tool use mapping
ToolingConfig
Tooling configuration
UnifiedRequest
Unified request format (for protocol compilation)

Enums§

CapabilitiesV2
V2 structured capability declaration with required/optional separation.
Capability
Standard capability identifiers aligned with schemas/v2/capabilities.json.
ProtocolError
Protocol error types

Functions§

load_manifest_validated
Parse and validate a provider manifest from in-memory YAML (PT-072 / WASI).