ADR 0018: AI SDK Transport Layer
Status
Accepted
Context
ADR 0009 established the pi-shaped agent loop (agentLoop, Context, stream(), complete()). The LLM wire layer was initially implemented with vendor-specific HTTP clients and AIProvider.chat() bridges.
Vercel AI SDK provides mature, maintained provider transports. Maintaining parallel HTTP stacks (preset/spec, anthropic-bridge, openai-completions) duplicated effort and drifted from upstream fixes.
Decision
AI SDK is the LLM transport inside
@zhin.js/aionly.@ai-sdk/*andaiare not re-exported from public package APIs.Keep ADR 0009 surface unchanged:
agentLoop,Context,stream(),complete(),AssistantMessageEventStream.Configuration hard break:
ai.providers.<alias>.sdkreplacesapi,driver,preset, andspec.Closed sdk table (Phase 1):
sdk Notes openai@ai-sdk/openaianthropic@ai-sdk/anthropicgoogle@ai-sdk/googledeepseek@ai-sdk/deepseekollama@ai-sdk/openai-compatible→{host}/v1openai-compatibleGateways, 智谱, Moonshot, Cloudflare Workers AI chat Single ApiProvider registered as
ai-sdk;getModel()returnsapi: 'ai-sdk'with internalsdkmetadata.Model discovery unchanged: yaml
models:whitelist →/v1/models(OpenAI-compat) → static fallback.Image generation (Phase 1) uses AI SDK
generateImagewhere supported (openai,google,openai-compatible). Exception: Cloudflare Workers AI images remain on legacy/ai/run/{model}HTTP (non–OpenAI-compat path).IM naming unchanged:
endpoints(platform bots) vsai.providers(LLM instances) remain separate concepts.
Consequences
Positive
- One transport implementation; provider fixes flow from AI SDK releases.
- Config is simpler (
sdk+ connection params). - pi agent loop and harness tests remain stable.
Negative / limits
@ai-sdk/ollamais not published; Ollama uses OpenAI-compatible shim.- Not every gateway combo supports AI SDK image APIs; validate at config/runtime and document support matrix.
- Persisted assistant messages may still contain legacy
apivalues from older sessions; runtime usesai-sdk.