Skip to content

Add OpenRouter provider#317

Open
lukesbeard wants to merge 1 commit into
JerryZLiu:mainfrom
lukesbeard:feature/openrouter-provider
Open

Add OpenRouter provider#317
lukesbeard wants to merge 1 commit into
JerryZLiu:mainfrom
lukesbeard:feature/openrouter-provider

Conversation

@lukesbeard

Copy link
Copy Markdown

Summary

Adds a dedicated OpenRouter provider for Dayflow, enabling access to 300+ models (DeepSeek V4 Flash, Claude, GPT, Gemini, etc.) for screenshot transcription, activity card generation, and dashboard chat.

Changes

New files

  • OpenRouterProvider.swift — Core provider with OpenAI-compatible chat completions, model fetching from /v1/models, retry logic (exponential backoff), Keychain auth, structured error handling, and LLM telemetry integration
  • OpenRouterProvider+Transcription.swift — Vision-based screenshot transcription, activity card generation with JSON parsing, image resizing (~720p), and timestamp extraction

Integration

  • Extended LLMProviderType, LLMProviderID, and DashboardChatProvider enums
  • Wired into LLMService for batch processing, text generation, and chat streaming
  • Full onboarding flow: API key entry, model selection, connection test
  • Settings UI with provider config check and routing
  • Dashboard chat availability check via Keychain

Audit fixes

All findings from Claude Code audit addressed:

  • Safe bitmap allocation (removed force-unwrap crash)
  • Non-retryable 4xx errors skip retries
  • Screenshot timestamps use actual capture time
  • Colorspace corrected to .deviceRGB
  • Zero-size dimension crash guard
  • Optional content handling for model refusals
  • response_format support for structured JSON output

…nd chat integration

New files:
- OpenRouterProvider.swift — Core provider with OpenAI-compatible chat completions,
  model fetching, retry logic, error handling, text generation
- OpenRouterProvider+Transcription.swift — Screenshot transcription via vision API,
  activity card generation, image resizing

Modified files:
- LLMTypes.swift — Added .openRouter case to LLMProviderType, LLMProviderID,
  DashboardChatProvider enums
- LLMService.swift — Wired OR into batch processing, text generation, chat streaming
- OnboardingLLMSelectionView.swift — Added OpenRouter selection card with features
- LLMProviderSetupView.swift — Added 'Connect OpenRouter' header
- ProviderSetupState.swift — Added setup flow (key entry, model selection, test),
  Keychain persistence, openRouterModelId tracking
- ProvidersSettingsViewModel.swift — Added provider config check + routing
- ChatView+Actions.swift — Added OR availability check for dashboard chat

Fixes applied per Claude Code audit:
- HIGH: Safe bitmap allocation (removed force-unwrap)
- HIGH: Non-retryable 4xx errors no longer waste retries
- MED: Screenshot timestamps use wall-clock capture time
- MED: Colorspace changed to .deviceRGB
- MED: Zero-size dimension crash guard
- M2: content field made Optional (handles model refusals)
- M3: response_format support for JSON mode
@ping-Toven

Copy link
Copy Markdown

would love this :) currently using dayflow conifgured with openrouter through the local model config, technically works but it's a bit janky

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.

2 participants