Skip to content

feat(new-api): add endpoint debug selection#1836

Merged
yyhhyyyyyy merged 2 commits into
devfrom
feat/newapi-endpoint-debug-selection
Jun 29, 2026
Merged

feat(new-api): add endpoint debug selection#1836
yyhhyyyyyy merged 2 commits into
devfrom
feat/newapi-endpoint-debug-selection

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

add new-api provider endpoint debug selection

Summary by CodeRabbit

  • New Features

    • Enhanced model type detection and endpoint selection for “new-api” providers, better covering chat, image, video, and embedding models.
    • Model settings now more accurately reflect manual type selection and provider metadata.
  • Bug Fixes

    • Fixed cases where model configuration could load with incorrect endpoint options or reset unexpectedly.
    • Improved consistency when switching between chat and media model types in settings, including safer initialization.
  • Tests

    • Expanded coverage for “new-api” model typing, endpoint-choices, and initialization/loading behavior.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Replaces ownedBy-based NewAPI endpoint selection with metadata-driven ModelType inference. Shared helpers, provider enrichment, and the settings dialog now derive selectable endpoint types from model metadata and explicit type precedence, with updated tests covering the new normalization and loading behavior.

Changes

New-API model type and selectable endpoint type resolution

Layer / File(s) Summary
Shared model type inference and selectable endpoint helpers
src/shared/model.ts
Adds internal chat/media endpoint groups, removes isOpenAiFamilyNewApiModel, introduces resolveNewApiModelTypeFromMetadata, and rewrites resolveNewApiSelectableEndpointTypes around inferred ModelType and deduped endpoint lists.
Provider-side new-api type propagation
src/main/presenter/configPresenter/providerModelHelper.ts, src/main/presenter/llmProviderPresenter/providers/aiSdkProvider.ts
Delegates NewAPI model-type inference to shared helpers, resolves effective NewAPI types before compatibility, and changes provider model transformation order.
ModelConfigDialog new-api normalization and loading guard
src/renderer/src/components/settings/ModelConfigDialog.vue
Adds effective NewAPI type derivation, endpoint fallback logic, payload normalization, and guarded config loading with request tracking.
Updated NewAPI inference and dialog tests
test/main/shared/model.test.ts, test/main/presenter/configPresenter/providerModelHelper.test.ts, test/main/presenter/llmProviderPresenter/newApiProvider.test.ts, test/renderer/components/ModelConfigDialog.test.ts
Expands coverage for shared inference, provider enrichment, routing, and dialog state/endpoint normalization behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • zerob13

Poem

🐇 I hopped through metadata, quick as a spark,
Chat and media paths now land in the mark.
The dialog waits while the config loads through,
Then endpoint types bloom in a tidy new view.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main change: adding endpoint debug selection for the new-api provider.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/newapi-endpoint-debug-selection

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
Contributor

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 `@src/renderer/src/components/settings/ModelConfigDialog.vue`:
- Around line 1561-1568: The watcher in ModelConfigDialog.vue only reacts to
config.value.endpointType, config.value.type, and
showEndpointTypeSelector.value, so it can miss provider metadata updates that
change availableEndpointTypes. Update that watcher’s source to also observe the
data that drives available endpoint types (or the resolved provider metadata) so
syncNewApiDerivedFields() reruns when the valid endpoint set changes. Keep the
existing calls to syncNewApiDerivedFields() and syncCapabilityProviderId() in
place, and ensure any invalid config.endpointType is revalidated/reset after
metadata arrives.
- Around line 1237-1344: The load guard in loadConfig is being cleared by
whichever async request finishes last, so overlapping calls from the immediate
watcher and onMounted can let an older load reset isLoadingModelConfig while a
newer one is still updating config. Update loadConfig in ModelConfigDialog.vue
to use a request token/counter (or otherwise ignore stale completions) so only
the latest invocation can clear the loading state and trigger follow-on watcher
behavior, or remove the duplicate initial call so initialization cannot overlap.

In `@src/shared/model.ts`:
- Around line 159-181: Update the model inference logic in model type detection
so known media model IDs are recognized before the chat fallback: in the
function that normalizes model IDs and returns ModelType (the block with
normalizeModelId, isPureNewApiMediaEndpointRoute, and the chat default), add
explicit checks for dalle-*, gpt-image-*, and sora-* and map them to
ImageGeneration or VideoGeneration as appropriate. This should happen before the
existing return-to-chat path so sparse NewAPI /models metadata still selects the
media debug endpoint instead of being treated as chat.
🪄 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

Run ID: 473a4c1c-3962-4dc7-9be1-ac706775b528

📥 Commits

Reviewing files that changed from the base of the PR and between 44810b1 and ffa19da.

📒 Files selected for processing (8)
  • src/main/presenter/configPresenter/providerModelHelper.ts
  • src/main/presenter/llmProviderPresenter/providers/aiSdkProvider.ts
  • src/renderer/src/components/settings/ModelConfigDialog.vue
  • src/shared/model.ts
  • test/main/presenter/configPresenter/providerModelHelper.test.ts
  • test/main/presenter/llmProviderPresenter/newApiProvider.test.ts
  • test/main/shared/model.test.ts
  • test/renderer/components/ModelConfigDialog.test.ts

Comment thread src/renderer/src/components/settings/ModelConfigDialog.vue
Comment thread src/renderer/src/components/settings/ModelConfigDialog.vue Outdated
Comment thread src/shared/model.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/renderer/components/ModelConfigDialog.test.ts (1)

1028-1055: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid pinning this test to mount-time call count.

Line 1054 makes the test depend on the current watcher/load scheduling by requiring exactly two getModelConfig calls right after setup(). That is brittle for harmless refactors that still preserve the real contract here: stale loads must not clear isLoadingModelConfig, and the latest load must win. Prefer explicitly triggering the second load in the test instead of relying on mount internals.

🤖 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 `@test/renderer/components/ModelConfigDialog.test.ts` around lines 1028 - 1055,
The test is too tightly coupled to mount-time scheduling by asserting an exact
`getModelConfig` call count immediately after `setup()`, which makes it brittle.
Update `ModelConfigDialog.test.ts` so the overlapping-load scenario is driven
explicitly through the component behavior or store action rather than relying on
the initial watcher/mount internals. Keep the focus on the real contract in
`isLoadingModelConfig`: stale requests must not clear the loading guard, and the
latest load should still be active until it resolves. Reference the existing
`getModelConfig`, `setup`, and `isLoadingModelConfig` paths when adjusting the
test.
🤖 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.

Nitpick comments:
In `@test/renderer/components/ModelConfigDialog.test.ts`:
- Around line 1028-1055: The test is too tightly coupled to mount-time
scheduling by asserting an exact `getModelConfig` call count immediately after
`setup()`, which makes it brittle. Update `ModelConfigDialog.test.ts` so the
overlapping-load scenario is driven explicitly through the component behavior or
store action rather than relying on the initial watcher/mount internals. Keep
the focus on the real contract in `isLoadingModelConfig`: stale requests must
not clear the loading guard, and the latest load should still be active until it
resolves. Reference the existing `getModelConfig`, `setup`, and
`isLoadingModelConfig` paths when adjusting the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05dfffb3-5dd8-4a34-9ac9-ba602d42614c

📥 Commits

Reviewing files that changed from the base of the PR and between ffa19da and 9e8ef1f.

📒 Files selected for processing (6)
  • src/renderer/src/components/settings/ModelConfigDialog.vue
  • src/shared/model.ts
  • test/main/presenter/configPresenter/providerModelHelper.test.ts
  • test/main/presenter/llmProviderPresenter/newApiProvider.test.ts
  • test/main/shared/model.test.ts
  • test/renderer/components/ModelConfigDialog.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/main/presenter/configPresenter/providerModelHelper.test.ts
  • src/shared/model.ts
  • test/main/presenter/llmProviderPresenter/newApiProvider.test.ts
  • src/renderer/src/components/settings/ModelConfigDialog.vue

@yyhhyyyyyy yyhhyyyyyy merged commit 90605e0 into dev Jun 29, 2026
3 checks passed
@zhangmo8 zhangmo8 deleted the feat/newapi-endpoint-debug-selection branch June 30, 2026 01:44
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