Skip to content

feat: Multi-backend AI enhancement (OpenAI-compatible + Anthropic cloud)#35

Open
sk8ersquare wants to merge 5 commits intopoodle64:mainfrom
sk8ersquare:pr/multi-backend-enhancement
Open

feat: Multi-backend AI enhancement (OpenAI-compatible + Anthropic cloud)#35
sk8ersquare wants to merge 5 commits intopoodle64:mainfrom
sk8ersquare:pr/multi-backend-enhancement

Conversation

@sk8ersquare
Copy link
Copy Markdown

Summary

Adds two new AI text enhancement backends alongside the existing Ollama support:

  1. OpenAI-compatible — works with any OpenAI-compatible API server (oMLX, LM Studio, LocalAI, etc.)
  2. Anthropic cloud — Claude models (Haiku 4.5, Sonnet 4.6, Opus 4.6) via the Messages API

Both backends are purely additive. Existing Ollama functionality is unchanged. All new config fields use serde(default) for full backward compatibility with existing installations.


What's Included

Commit 1: OpenAI-compatible backend

  • New OpenAiCompatClient with retry logic, exponential backoff, configurable timeout (30s default)
  • Config: backend selector (ollama/openai_compat), base_url, api_key fields
  • Settings UI: Cloud/Local tab switcher with endpoint + model configuration
  • Tauri commands: list_openai_models, enhance_openai
  • Comprehensive test coverage for client construction and API key handling

Commit 2: Anthropic cloud backend

  • New AnthropicClient with Messages API integration (API version 2023-06-01)
  • Auto-detection of ANTHROPIC_API_KEY from environment
  • Model selector: Haiku 4.5, Sonnet 4.6, Opus 4.6
  • Config: anthropic_api_key, anthropic_model, anthropic_base_url fields
  • Tauri commands: detect_anthropic_api_key, enhance_anthropic
  • Helper link to Anthropic console for key generation

Commit 3: Settings subtitle fix

  • Settings no longer says "Ollama-specific" since multiple backends are now supported

Commit 4: Cloud AI switching fix + UI polish

  • Critical bug fix: Pipeline was always sending config.enhancement.model (local Ollama model) regardless of backend selection. When Anthropic was selected, it still tried calling Ollama with the Anthropic API key.
  • Tray menu shows active backend and model (Cloud: claude-haiku-4-5-20251001 or Local: your-model)
  • Tray refreshes immediately after backend switch
  • Tabs replaced with slide toggle (Local AI ←→ Cloud AI)
  • Active backend pill shows what's currently running
  • Remembers last local backend on switch
  • SVG eye icon for API key show/hide (fixes broken emoji rendering)

Commit 5: Security hardening

  • Config file restricted to 0600 (owner-only) after write — config contains API keys in plaintext JSON
  • URL scheme validation on OpenAI-compat endpoints: rejects file://, ftp://, etc. (OWASP M4)
  • HTTPS warning for Anthropic when custom base_url is not HTTPS (prevents accidental plaintext key transmission; localhost exempted)
  • Added .claude/rules/20-enhancement-backends.md documenting backend patterns
  • Added .github/workflows/security-audit.yaml (cargo audit + npm audit, weekly schedule + push/PR)

Files Changed (12 files, +1584 / -117)

File What
src-tauri/src/enhancement/openai_compat.rs New — OpenAI-compat client
src-tauri/src/enhancement/anthropic.rs New — Anthropic client
src-tauri/src/enhancement/mod.rs Backend routing, model listing
src-tauri/src/config.rs Enhancement config fields + file permissions
src-tauri/src/lib.rs Tauri command registration
src-tauri/src/tray.rs Backend-aware model display
src/lib/components/AIEnhancementSettings.svelte Settings UI (slide toggle, pills, SVG icons)
src/lib/stores/config.svelte.ts Config store for new fields
src/lib/stores/pipeline.svelte.ts Backend-aware model routing
src/lib/windows/Settings.svelte Subtitle fix
.claude/rules/20-enhancement-backends.md New — Backend pattern rules
.github/workflows/security-audit.yaml New — Dependency audit CI

Not Included (fork-specific, excluded from this PR)

  • Version bumps (left for maintainer to decide)
  • About dialog changes (fork-specific credits/links)
  • No transcription changes, no model manager changes, no onboarding

Testing

  • Built and tested on macOS aarch64 (Apple Silicon)
  • Verified: Ollama backend still works unchanged
  • Verified: OpenAI-compat connects to oMLX, LM Studio
  • Verified: Anthropic connects to Claude API (Haiku, Sonnet, Opus)
  • Verified: Backend switching works correctly (tray updates, pipeline routes to correct model)
  • Verified: Old configs without new fields load cleanly (serde defaults)
  • Rust tests pass (cargo test in src-tauri/)

Screenshots

Settings with slide toggle and active backend pill — happy to add screenshots if helpful.


Built on top of the v2026.2.7 base. Rebased cleanly onto current main (6ecfe54).

Eve added 5 commits March 17, 2026 22:37
Adds a new backend option for AI text enhancement that works with any
OpenAI-compatible API server (oMLX, LM Studio, LocalAI, etc).

- New OpenAiCompatClient with retry logic, exponential backoff, timeout
- Config: backend selector (ollama/openai_compat), base_url, api_key fields
- Settings UI: Cloud/Local tab switcher with endpoint + model configuration
- Tauri commands: list_openai_models, enhance_openai for frontend integration
- All fields use serde(default) for backward compatibility with existing configs
- Comprehensive test coverage for client construction and API key handling

Ollama functionality unchanged — this is purely additive.
Adds Claude (Anthropic) as a cloud AI enhancement backend alongside
the existing Ollama and OpenAI-compatible local backends.

- New AnthropicClient with Messages API integration (2023-06-01)
- Auto-detection of ANTHROPIC_API_KEY from environment
- Model selector: Haiku 4.5, Sonnet 4.6, Opus 4.6
- Settings UI: dedicated Anthropic section with API key (show/hide toggle)
- Config: anthropic_api_key, anthropic_model, anthropic_base_url fields
- Tauri commands: detect_anthropic_api_key, enhance_anthropic
- Helper link to Anthropic console for key generation
- Backward compatible — all new config fields use serde(default)
Now that multiple AI backends are supported, the settings subtitle
should not reference Ollama specifically.
- Pipeline: enhancementModel now picks anthropicModel when backend is
  anthropic. Previously always sent config.enhancement.model (local
  Ollama model) regardless of backend selection — cloud AI was broken.
- Tray: shows correct model with backend prefix (Cloud:/Local:/Local OMLX:)
- Tray: refreshes immediately after backend switch
- UI: tabs replaced with slide toggle (Local AI ←→ Cloud AI)
- UI: active backend pill shows what's currently running
- UI: switchToLocal remembers last local backend
- Anthropic models: trimmed to 3 current (Haiku 4.5, Sonnet 4.6, Opus 4.6)
- API key show/hide: SVG eye icon instead of broken emoji rendering
Security hardening aligned with master-project governance (Profile 0):

- Config file: restrict to 0600 after write (contains API keys in plaintext)
- OpenAI-compat: validate URL scheme, reject non-http(s) (OWASP M4)
- Anthropic: warn if custom base_url is not HTTPS (credential exposure risk)
- Fix tray closure argument (compiler error on some Rust versions)
- Add .claude/rules/20-enhancement-backends.md (backend pattern rules)
- Add .github/workflows/security-audit.yaml (cargo audit + npm audit, weekly)
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