AI provider abstraction: one LlmProvider trait, four adapters (v0.1.3)#10
Merged
Conversation
No business logic. Single LlmProvider port in core with provider-neutral ChatRequest/ChatMessage/ModelInfo, token streaming (TokenStream) and a typed LlmError. devpilot-ai implements four thin reqwest adapters (rustls, no SDKs): Ollama (local, keyless reference), Claude, OpenAI, Gemini — each translating to its API's wire format and mapping errors. API keys are redacted from Debug. MockLlmProvider plus wiremock adapter tests cover SSE/NDJSON streaming, model listing and error mapping. No use cases, context building, DI wiring or UI. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The AI provider abstraction — one interface, four implementations. No business logic (no use cases, context building, DI wiring or UI).
LlmProviderin core: provider-neutralChatRequest/ChatMessage/Role/ModelInfo, token streaming viaTokenStream(BoxStreamof token results), and a typedLlmError(AuthFailed,RateLimited { retry_after },ContextTooLong,Network,Backend).devpilot-ai, each implementing the same trait over rawreqwest(rustls TLS, no OpenSSL), no SDKs or frameworks:OllamaProvider— local, needs no key (the reference adapter), NDJSON streaming.ClaudeProvider— Messages API, system prompt split out, SSEcontent_block_delta.OpenAiProvider— chat completions, SSE deltas.GeminiProvider—streamGenerateContent,user/modelroles + system instruction.Debugoutput.MockLlmProviderindevpilot-testing; wiremock adapter tests (no live APIs) covering SSE and NDJSON streaming, model listing, and error mapping (401 → auth, 429 → rate limited).Verification
cargo fmt --check,clippy -D warnings, fullcargo test --workspace: clean. reqwest+rustls and wiremock compile.pnpm build(tsc strict): clean.Not wired into the app yet — nothing consumes it until the chat use case (next). That keeps this PR to the abstraction only, per the request.
🤖 Generated with Claude Code