Skip to content

feat: preview upstream model catalog refresh#162

Merged
g1331 merged 2 commits into
masterfrom
upstream-catalog-preview-refresh
May 16, 2026
Merged

feat: preview upstream model catalog refresh#162
g1331 merged 2 commits into
masterfrom
upstream-catalog-preview-refresh

Conversation

@g1331
Copy link
Copy Markdown
Owner

@g1331 g1331 commented May 16, 2026

Summary

Adds an upstream model catalog preview refresh flow so the edit dialog can refresh models from current form values before saving.

Related Issue

Closes #161

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (code improvement without changing functionality)
  • Tests (adding or updating tests)
  • Build/CI (changes to build system or CI configuration)

Changes

  • Added POST /api/admin/upstreams/[id]/catalog/preview to refresh a model catalog from editor values without updating the upstream record.
  • Updated the upstream edit dialog so refresh uses unsaved base_url, api_key, route capabilities, and discovery settings.
  • Changed catalog import in the edit dialog to update local model rules first, then persist catalog and rules together when saving.
  • Updated catalog refresh copy and added component, hook, and API coverage.

Test Plan

  • Local tests pass (pnpm test:run)
  • Type check passes (pnpm exec tsc --noEmit)
  • Lint passes (pnpm lint)
  • Manual testing completed

Commands run:

pnpm test:run tests/components/upstream-form-dialog.test.tsx tests/unit/api/admin/upstreams/catalog.test.ts tests/unit/hooks/use-upstreams.test.ts
pnpm exec tsc --noEmit --pretty false
pnpm format:check
pnpm lint
git diff --check

Checklist

  • Code follows the project's coding standards
  • Tests have been added where necessary
  • Documentation has been updated (if applicable)
  • Changes do not introduce security vulnerabilities
  • Commit messages follow conventions

Screenshots

Not captured.

Additional Notes

pnpm lint passes with existing JSDoc warnings and no errors.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

❌ Patch coverage is 65.45455% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.15%. Comparing base (fb3a0dd) to head (c14909a).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #162      +/-   ##
==========================================
- Coverage   80.22%   80.15%   -0.07%     
==========================================
  Files         118      118              
  Lines        9995    10035      +40     
  Branches     3501     3515      +14     
==========================================
+ Hits         8018     8044      +26     
- Misses       1280     1285       +5     
- Partials      697      706       +9     
Flag Coverage Δ *Carryforward flag
typescript 76.11% <ø> (ø) Carriedforward from ce5875a
verify 75.56% <65.45%> (-0.06%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new "preview" catalog refresh flow so the upstream edit dialog can refresh model catalogs against the editor's unsaved base_url, api_key, route capabilities, and discovery settings, persisting the previewed catalog alongside the form save instead of mutating the upstream record immediately. Catalog import is also reworked to populate local form rules first and persist on save.

Changes:

  • New POST /api/admin/upstreams/[id]/catalog/preview endpoint backed by a previewUpstreamCatalog service that runs the discovery against editor-supplied values, falling back to the stored API key when none is provided.
  • New usePreviewUpstreamCatalog hook plus refactored UpstreamFormDialog that previews into a workspace upstream, imports models locally into model_rules, and writes the previewed catalog fields on save.
  • Updated copy (catalogSavedConfigHint) and tests covering the API route, hook, and dialog flows.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/app/api/admin/upstreams/[id]/catalog/preview/route.ts New admin endpoint validating editor values and returning a preview catalog.
src/lib/services/upstream-crud.ts Adds UpstreamCatalogPreviewInput and previewUpstreamCatalog service (no DB write).
src/lib/services/upstream-service.ts Re-exports the new preview function and input type.
src/hooks/use-upstreams.ts Adds usePreviewUpstreamCatalog mutation.
src/types/api.ts Adds preview request/response API types.
src/components/admin/upstream-form-dialog.tsx Switches refresh to preview, imports catalog into local rules, persists previewed catalog on save, adjusts dirty/blocked logic.
src/messages/en.json, src/messages/zh-CN.json Updates the catalog hint copy to reflect the new behavior.
tests/unit/api/admin/upstreams/catalog.test.ts Adds API route test for the preview endpoint.
tests/unit/hooks/use-upstreams.test.ts Adds hook test for the preview mutation.
tests/components/upstream-form-dialog.test.tsx Replaces refresh/import tests with preview+save and local-import flows.

Comment thread src/hooks/use-upstreams.ts Outdated
@g1331 g1331 merged commit 85ee6c9 into master May 16, 2026
12 checks passed
@g1331 g1331 deleted the upstream-catalog-preview-refresh branch May 16, 2026 08:19
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