Expand description
Mirrors packages/ai/src — the unified, multi-provider LLM layer.
Provider-agnostic types (Content, Message, AssistantMessage,
AssistantMessageEvent, Context, Tool, Usage) live in types;
model-layer configuration (Model, compat structs) lives in model.
Schema validation + LLM-sloppy-JSON coercion (mirroring validation.ts) is
in schema; the SPSC streaming queue mirroring event-stream.ts is in
event_stream; the Provider trait seam is in provider; concrete
providers live under providers (faux now, anthropic in M3).
Every module’s doc comment names the TS file it mirrors.
Re-exports§
pub use error::AiError;pub use event_stream::AssistantMessageEventStream;pub use event_stream::AssistantMessageEventStreamProducer;pub use model::Model;pub use model::StreamingProtocolCompat;pub use provider::CacheRetention;pub use provider::ContextPatch;pub use provider::NoopProviderHooks;pub use provider::Provider;pub use provider::ProviderHooks;pub use provider::SimpleStreamOptions;pub use provider::SimpleStreamOptionsPatch;pub use provider::DEFAULT_LLM_API_TIMEOUT;pub use schema::validate_tool_arguments;pub use types::Api;pub use types::AssistantMessage;pub use types::AssistantMessageEvent;pub use types::Content;pub use types::Context;pub use types::DeferredHandle;pub use types::DoneReason;pub use types::ErrorReason;pub use types::ImageContent;pub use types::InputModality;pub use types::Message;pub use types::ModelCost;pub use types::ModelCostRates;pub use types::ModelCostTier;pub use types::ProviderId;pub use types::Schema;pub use types::StopReason;pub use types::TextContent;pub use types::ThinkingBudgets;pub use types::ThinkingContent;pub use types::ThinkingLevel;pub use types::ThinkingLevelMap;pub use types::Tool;pub use types::ToolCall;pub use types::ToolCallType;pub use types::ToolResultMessage;pub use types::Usage;pub use types::UsageCost;pub use types::UserContent;pub use types::UserMessage;
Modules§
- constrained
- Constrained sampling — grammar-constrained tool output formatting.
- error
- Mirrors the error surfaces implied by
packages/ai/src— no single TS file; the variants collect every failure mode the ai crate can surface to a caller. - event_
stream - Mirrors
packages/ai/src/utils/event-stream.ts— the SPSC async event stream that carriesAssistantMessageEvents from a provider to the agent loop, plus theresult()future resolving to the finalAssistantMessage. - frames
- Assistant message frames — a compact, durable encoding of one assistant stream.
- http
- HTTP client construction: system-proxy resolution and pooled-connection idle timeout.
- images
- Image generation API.
- json_
parse - Mirrors
packages/ai/src/utils/json-parse.ts— JSON repair + streaming partial-JSON parsing used by the Anthropic SSE mapper to recover tool-call arguments that arrive as malformed / incomplete JSON deltas. - model
- Mirrors
packages/ai/src/models.ts—Model<TApi>+ the compatibility structs. - provider
- Mirrors
packages/ai/src/models.ts::Provider— the trait every concrete provider (faux, anthropic, …) implements. The agent loop never touches a provider’s wire format directly; it callsstream_simpleand consumes the returnedAssistantMessageEventStream. - providers
- Concrete providers. Mirrors
packages/ai/src/api/*+ the in-tree faux provider (packages/agent/src/faux.ts, hoisted here so every crate’s tests can reuse it without depending onpi-agent). - schema
- Mirrors
packages/ai/src/utils/validation.ts— JSON-Schema validation of tool arguments plus a hand-writtencoerce_with_json_schemalayer that tolerates LLM-sloppy JSON (stringified numbers,"true", null on optional fields, …). - types
- Mirrors
packages/ai/src/types.ts— the core LLM type contract every other crate consumes.