Expand description
§ai-lib-rust
这是 AI-Protocol 规范的高性能 Rust 参考实现(工作区聚合 crate:ai-lib-core 执行层 + ai-lib-contact 策略层)。
Protocol Runtime for AI-Protocol — workspace facade over ai-lib-core and ai-lib-contact.
Modules§
- cache
- 响应缓存模块:提供可插拔的缓存后端以减少重复 API 调用。
- client
- 统一客户端接口:提供协议驱动的 AI 模型交互入口。
- drivers
- Provider 驱动抽象层 — 通过 trait 实现多厂商 API 适配的动态分发
- error
- 错误处理模块:提供统一的错误类型和结构化错误上下文。
- error_
code - V2 标准错误码:定义 13 个规范错误码及其重试/回退语义。
- feedback
- 核心反馈类型:提供 FeedbackSink trait 和多种反馈事件(始终编译)。
- pipeline
- 流水线处理模块:实现流式响应处理的核心算子执行引擎。
- plugins
- Plugin and middleware system.
- protocol
- 协议规范层:负责加载、验证和管理 AI-Protocol 规范文件。
- registry
- 能力注册表 — 根据 Manifest 声明动态加载和管理运行时模块
- resilience
- 弹性模式模块:提供熔断器和限流器等可靠性保障机制。
- structured
- Structured output module for ai-lib-rust.
- transport
- types
- 类型系统模块:定义基于 AI-Protocol 规范的核心数据类型。
- utils
- Utility modules
Structs§
- AiClient
- Unified AI client that works with any provider through protocol configuration.
- AiClient
Builder - Builder for creating clients with custom configuration.
- Call
Stats - Per-call statistics for observability and model selection.
- Cancel
Handle - Handle to cancel an in-flight streaming request.
- Chat
Batch Request - Batch chat request parameters (developer-friendly, small surface).
- Client
Metrics - Snapshot of cumulative client metrics for monitoring and routing.
- Error
Context - Structured error context for better error handling and debugging.
- Execution
Metadata - Metadata returned with every E-layer call for P-layer policy decisions.
- Execution
Result - Successful execution envelope from E: payload plus metadata for P.
- Execution
Usage - Token usage attached to an execution (aligned with driver
UsageInfo). - Message
- Unified message structure
- Tool
Call - Tool call (invocation from model)
Enums§
- Error
- Unified error type for the AI-Protocol Runtime This aggregates all low-level errors into actionable, high-level categories
- Feedback
Event - Typed feedback events (extensible).
- Message
Role - Message role
- Standard
Error Code - Standard AI-Protocol V2 error code.
- Streaming
Event - Unified streaming event enum
Traits§
- Endpoint
Ext - Feedback
Sink - Feedback sink trait.
Type Aliases§
- BoxStream
- A unified pinned, boxed stream that emits
PipeResult<T> - Pipe
Result - A specialized Result for pipeline operations
- Result
- Result type alias for the library