Skip to content

AI provider abstraction: one LlmProvider trait, four adapters (v0.1.3)#10

Merged
s1rry merged 1 commit into
mainfrom
feature/ai-providers
Jul 4, 2026
Merged

AI provider abstraction: one LlmProvider trait, four adapters (v0.1.3)#10
s1rry merged 1 commit into
mainfrom
feature/ai-providers

Conversation

@s1rry

@s1rry s1rry commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What

The AI provider abstraction — one interface, four implementations. No business logic (no use cases, context building, DI wiring or UI).

  • Port LlmProvider in core: provider-neutral ChatRequest / ChatMessage / Role / ModelInfo, token streaming via TokenStream (BoxStream of token results), and a typed LlmError (AuthFailed, RateLimited { retry_after }, ContextTooLong, Network, Backend).
  • Four adapters in devpilot-ai, each implementing the same trait over raw reqwest (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, SSE content_block_delta.
    • OpenAiProvider — chat completions, SSE deltas.
    • GeminiProviderstreamGenerateContent, user/model roles + system instruction.
    • API keys are redacted from Debug output.
  • Mock + tests: MockLlmProvider in devpilot-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, full cargo 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

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>
@s1rry s1rry merged commit da58cec into main Jul 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant