Repository navigation
feat(models): sync a provider's model list with its upstream endpoint - #916
jidekaixin2dian wants to merge 2 commits into
Conversation
2ab14d5 to
64d2462
Compare
"Import models..." only supported hand-picking from the upstream list, and it never removed models the endpoint stopped offering (agegr#880, agegr#860). Add a "Sync models" action to the provider detail that reconciles the configured model list with the discovered upstream list: - upstream additions always apply - models the upstream list no longer offers are reported and only dropped when the user opts in, because gateways, proxies, and paged endpoints can legitimately return a partial list The comparison is a pure helper (lib/model-sync.ts), so it is unit-tested without rendering the modal. Sync edits the existing draft, so Save is still the only path that writes models.json. Verification: npm test, tsc --noEmit, eslint, plus a browser run against the DeepSeek /v1/models endpoint covering the add path, the opt-in removal path, and the preserve-without-opt-in path.
Discovery required a baseUrl in models.json, so a models-only provider entry -- and every provider pi ships itself -- could not be refreshed even though pi already knows their endpoint. - resolveModelDiscoveryAuth() now also returns the effective baseUrl and api it composed from pi's provider catalog, and the discover route uses them when the request omits either. - The Models panel no longer disables "Import models..." on an empty base URL; the field explains that leaving it empty uses pi's endpoint. - e2e/models-sync.mjs covers the flow against a local OpenAI-compatible fixture: importing upstream models, dropping a stale id only when removal is ticked, and leaving other providers untouched.
64d2462 to
2245003
Compare
|
Thanks @jidekaixin2dian, the write-up and the e2e fixture are very thorough. I'm closing this one, though:
If the missing piece for you is discovery on a models-only entry that relies on pi's built-in endpoint, please open an issue for that alone. The Generated by Claude Code |
|
两处都认,这个版本废弃。 bug 确认。 范围同意。删过期 id 用逐个删除够了,补新增有 Import models…,Refresh catalog 管 pi 内置 provider。这个 reconcile 动作是整份 PR 里偏弱的一半。 另一半开成 #1006: #1006 不带: |
What
Adds a Sync models action next to the existing Import models… flow, and makes discovery work for providers that do not repeat their endpoint in
models.json.Two problems this closes:
Import models…(MODEL REFRESH BUTTON #880) could only hand-pick entries from the upstream list and never removed models the endpoint stopped offering, so a provider's list drifts until it is edited by hand (供应商模型列表过时/未能及时刷新 #860).baseUrlinmodels.json, so a models-only provider entry — and every provider pi ships itself — could not be refreshed at all, even though pi already knows the endpoint.Sync semantics
Also remove N models no longer offered upstreamRemoval is opt-in on purpose: gateways, proxies, and paged endpoints can legitimately return a partial list, and silently deleting a working entry is much worse than leaving a stale one. Existing models keep their order; additions append. Sync edits the modal draft, so
Saveis still the only path that writesmodels.json.Provider coverage
Discovery now resolves its endpoint from
models.jsonfirst and falls back to pi's provider catalog (resolveModelDiscoveryAuth()returns the effectivebaseUrl/apiit composed). That covers:{"deepseek": {"models": [...]}}— pi's own endpoint is usedmodels.jsonentryThe Import models… button is no longer disabled on an empty base URL, and the Base URL field states that leaving it empty uses pi's endpoint for that provider.
Relationship to the "Refresh catalog" button
#914/#938refreshes pi's remote provider catalog overlay (~/.pi/agent/models-store.json), which is a different mechanism: it can only surface models a catalog-backed provider publishes, and it never touches a provider's ownGET /models. For a provider defined only inmodels.json(a local relay, a self-hosted gateway) that button has nothing to refresh, so this PR covers the remaining case.How
lib/model-sync.ts(new) — pureplanModelSync(configuredIds, upstreamModels)returning{ additions, stale }. No React, no I/O; exact id comparison; dedupes and ignores blank ids on both sides.lib/model-discovery-auth.ts— returns the effectivebaseUrl/apialongside the credentials.app/api/models-config/discover/route.ts— uses the request values when present and the resolved ones otherwise; still reportsBase URL requiredwhen neither exists.components/ModelsConfig.tsx— sync summary/button/stale checkbox under the discovery list, wired into the modal's existing draft (merged with the newenabledModelscontroller from#930).en/zh-CN/zh-TW.Verification
Rebased onto
main(96966e5, pi 0.87.1) — the branch is currentlyMERGEABLEagainstmain.npx tsc --noEmit— clean.npm run lint— clean.npm test— 1316/1316 pass (Linux, the same environment CI uses).npm run test:e2e— the full browser suite passes, including the new check:PASS: models sync imports upstream models and only drops opted-in stale ids.lib/model-sync.test.mjs), the modal wiring, the base-URL gate, and the resolvedbaseUrl/api.e2e/models-sync.mjsdrives the real modal against a local OpenAI-compatible fixture that servesGET /v1/models: it imports the upstream list, drops a stale id only when removal is ticked, verifies a second, unticked pass keeps that id, and asserts another provider is untouched./v1/modelsendpoint during development: add path, opt-in removal path, and preserve-without-opt-in path all behaved as above, with no browser console or page errors.Demo
demo/components/ModelsConfig.tsxis a near-copy of the panel, but the demo answers/api/*from an in-browser mock that has no upstream to discover from. I left it untouched rather than ship a button that can only error in the public demo — happy to mirror the UI and add a mock/api/models-config/discoverif you want the demo to show it.Notes
#856(discovery dropping capability metadata) is complementary: onceparseDiscoveredModels()emitscontextWindow/maxTokens/reasoning, synced additions pick those up with no change here.e2e/models-sync.mjsopens the panel through the sidebar footer and falls back toSettings → Models, because the footer button's position depends on the layout the page loads with and a cold Turbopack compile can swallow the first clicks.