Skip to content

fix(ai): support /v1-in-base endpoints, dedupe providers, model searc… - #106

Merged
ddutchie merged 2 commits into
mainfrom
ddutchie/persistence
Jul 31, 2026
Merged

ddutchie merged 2 commits into
mainfrom
ddutchie/persistence

Conversation

@ddutchie

@ddutchie ddutchie commented Jul 31, 2026 •

Copy link
Copy Markdown
Owner

What does this PR do?

  • llm: don't strip a mid-path /v1; new buildApiUrl only appends /v1 when the base has no version segment, so gateways like .../v1/openai resolve correctly. Route all chat/models/key fetch sites through it.
  • providers: dedupe savedProviders by id on add/edit/delete + hydration (self-heals doubled entries / duplicate React keys); disable switch/add/edit/ delete while a provider form is open.
  • model picker: add a search box and per-model favorites (global, persisted); favorites sort to the top. Star toggles without selecting/closing the menu.

Type of change

  • Bug fix
  • New feature
  • Refactor / code quality
  • Docs / changelog
  • Tests

Screenshots / recording

Checklist

  • npm run type-check:all passes
  • npm run lint passes
  • npm test passes (runs npm run compile first so electron/bundle-guard.test.ts actually executes — npm run test:bundle to run just that)
  • npm run test:e2e passes (run before merging UI changes or cutting a release)
  • If this ships a major, user-facing feature: added an entry to scripts/features.config.js so it appears in the "What's New" modal (generated JSON — run node scripts/generate-features.js)
  • No hardcoded colours — CSS variables only (var(--accent), var(--text-primary), etc.)
  • No text-[Npx] pixel font classes — rem equivalents only (text-[0.714rem], text-xs, etc.)
  • New IPC handlers wrapped in handle() and return IpcResult<T>
  • New DB migrations appended (not edited) in schema.ts
  • New SQL goes in electron/db/queries.ts — single source of truth (imported by both Electron main process and MCP server); never construct a Database instance outside db/client.ts (Electron) or mcp-server.ts (MCP runtime)
  • New dependencies or devDependencies added to ROLE_MAP in scripts/generate-licenses.js and licenses.json regenerated
  • New MCP tools registered in electron/mcp/tools/index.ts dispatch + electron/lib/tool-schemas.ts Zod schema
  • If you added/removed a --external:<pkg> flag in the compile script: updated the appropriate allowlist group (RUNTIME_PROVIDED / OPTIONAL_TRANSITIVE / SUBPROCESS_ONLY / SHIPPED_NATIVE) in electron/bundle-guard.test.ts and (if SHIPPED_NATIVE) shipped the package via electron-builder.yml

Notes for reviewer

Quick Follow Up to Last PR

Summary by CodeRabbit

  • New Features

    • Search models across chat and provider settings.
    • Mark models as favorites and access them first in chat and coding-agent pickers.
    • Favorites persist across sessions and are shared throughout the app.
  • Bug Fixes

    • Improved compatibility with OpenAI-compatible endpoints using nested or existing version paths.
    • Removed duplicate saved provider entries while preserving the latest settings.
    • Prevented conflicting provider edits and model changes while provider forms are open.

…h + favorites

- llm: don't strip a mid-path /v1; new buildApiUrl only appends /v1 when the
  base has no version segment, so gateways like .../v1/openai resolve correctly.
  Route all chat/models/key fetch sites through it.
- providers: dedupe savedProviders by id on add/edit/delete + hydration
  (self-heals doubled entries / duplicate React keys); disable switch/add/edit/
  delete while a provider form is open.
- model picker: add a search box and per-model favorites (global, persisted);
  favorites sort to the top. Star toggles without selecting/closing the menu.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ddutchie, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ce1efce-4d89-4ff3-b949-6e1c99f4cdba

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7bcb0 and 3081ef6.

📒 Files selected for processing (3)
  • electron/lib/llm-url.test.ts
  • electron/lib/llm.ts
  • src/store/slices/ui.ts
📝 Walkthrough

Walkthrough

The changes centralize OpenAI-compatible endpoint construction, remove duplicate saved providers, restrict provider controls during editing, and add globally persisted model search and favorites across model pickers.

Changes

AI endpoint construction

Layer / File(s) Summary
URL construction helpers and validation
electron/lib/llm.ts, electron/lib/llm-url.test.ts, changelogs/v2.5.18.md
normaliseBaseUrl and buildApiUrl preserve existing versioned or nested paths. Tests cover version, slash, local, and scheme-less URL variants.
Endpoint call-site integration
electron/ipc/*, electron/lib/*
AI handlers, probes, chat loops, compaction, scoring, and agent requests use buildApiUrl for models, key, and chat-completion endpoints.

Saved provider normalization

Layer / File(s) Summary
Provider de-duplication and persistence
src/store/slices/ui.ts, src/store/slices/ui.test.ts, changelogs/v2.5.18.md
Provider hydration and CRUD operations de-duplicate entries by ID. Tests cover ordering and last-value retention.
Provider editing controls
src/components/settings/ProviderManager.tsx
Provider controls are disabled or hidden while the provider form is open.

Model picker search and favorites

Layer / File(s) Summary
Favorite model state and restoration
src/store/slices/ui.ts, src/store/index.ts, src/store/slices/ui.test.ts
Favorite model IDs are stored in a Set, restored from local storage, toggled, and persisted.
Searchable model picker
src/components/ui/model-picker.tsx, src/components/ui/dropdown.tsx, changelogs/v2.5.18.md
The picker filters models, shows favorites first, manages search focus, and isolates favorite toggles from model selection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • ddutchie/cairn#73: Overlaps with the shared endpoint construction changes in the tool builder and LLM request loops.
  • ddutchie/cairn#95: Overlaps with saved-provider and shared model-picker changes.
  • ddutchie/cairn#96: Overlaps with AI model-fetching endpoint handling in ai-handlers.ts.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: endpoint support, provider deduplication, and model search.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ddutchie/persistence

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@electron/lib/llm.ts`:
- Around line 30-40: Update buildApiUrl to separate any query string or fragment
from baseUrl before appending cleanPath, then append the preserved suffix after
the resulting endpoint path. Ensure both query-only and fragment-containing base
URLs produce the correct path, and add coverage for both forms.

In `@src/store/slices/ui.ts`:
- Line 20: Run npm run type-check:all and resolve every TypeScript error related
to FAVORITE_MODELS_KEY and its imports/usages. Update src/store/slices/ui.ts
(20-20), src/store/slices/ui.test.ts (3-3), and
src/components/settings/ProviderManager.tsx (9-9) so the symbol’s declaration
and references use consistent, valid types and imports; verify the command
passes cleanly.
- Around line 155-159: Move the saved-provider normalization around rawProviders
and dedupeProviders before the window.electron?.secrets availability check in
the hydration flow. Ensure duplicate providers set changed and are persisted
even when the secrets bridge is unavailable, while preserving the existing
secrets-dependent behavior afterward.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: de073b2d-f0e0-43b1-88a9-c89e7fb659e3

📥 Commits

Reviewing files that changed from the base of the PR and between bf60981 and 5b7bcb0.

📒 Files selected for processing (17)
  • changelogs/v2.5.18.md
  • electron/ipc/ai-handlers.ts
  • electron/ipc/tool-builder.ts
  • electron/lib/bench-endpoint.ts
  • electron/lib/chat-loop.ts
  • electron/lib/chat-quality-scorer.test.ts
  • electron/lib/chat-subagent-loop.ts
  • electron/lib/compaction.ts
  • electron/lib/llm-url.test.ts
  • electron/lib/llm.ts
  • electron/lib/pi-agent-loop.ts
  • src/components/settings/ProviderManager.tsx
  • src/components/ui/dropdown.tsx
  • src/components/ui/model-picker.tsx
  • src/store/index.ts
  • src/store/slices/ui.test.ts
  • src/store/slices/ui.ts

Comment thread electron/lib/llm.ts Outdated
Comment thread src/store/slices/ui.ts

export const HIDDEN_VIEWS_KEY = "hiddenViews";
export const SEEN_FEATURES_KEY = "seenFeatures";
export const FAVORITE_MODELS_KEY = "favoriteModels";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
npm run type-check:all

Repository: ddutchie/cairn

Length of output: 1362


Ensure a clean npm run type-check:all passes.

The type-check command exits now, and the TypeScript files require npm run type-check:all to pass before these changes can land.

📍 Affects 3 files
  • src/store/slices/ui.ts#L20-L20 (this comment)
  • src/store/slices/ui.test.ts#L3-L3
  • src/components/settings/ProviderManager.tsx#L9-L9
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/store/slices/ui.ts` at line 20, Run npm run type-check:all and resolve
every TypeScript error related to FAVORITE_MODELS_KEY and its imports/usages.
Update src/store/slices/ui.ts (20-20), src/store/slices/ui.test.ts (3-3), and
src/components/settings/ProviderManager.tsx (9-9) so the symbol’s declaration
and references use consistent, valid types and imports; verify the command
passes cleanly.

Source: Coding guidelines

Comment thread src/store/slices/ui.ts Outdated
…ore secrets guard

- buildApiUrl: peel off any ?query/#fragment before appending the API path and
  re-append it after, so bases like ".../v1?token=x" resolve correctly. Add
  coverage for query-only and fragment-containing bases.
- migrateLlmKeysToKeychain: run saved-provider dedup before the secrets-bridge
  availability check so a doubled list self-heals (and is persisted) even on
  web / no-secrets builds; key-migration behavior after the guard is unchanged.
@ddutchie
ddutchie merged commit 0f55537 into main Jul 31, 2026
6 checks passed
@ddutchie
ddutchie deleted the ddutchie/persistence branch July 31, 2026 22:52
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