Add auto-sync upstream models feature for providers#8
Merged
Conversation
- 渠道表单新增「自动同步上游模型」选项:开启并保存时先校验上游 /v1/models,失败则整体报错、不落库;成功则立即用上游列表覆盖模型列表。 - 服务端每 24h 定时任务遍历开启该选项且启用中的渠道,重新拉取上游 模型列表并写库;单渠道失败只记日志、上游空列表时保留原有模型。 - console_providers 新增 auto_sync_models / models_synced_at 两列 (迁移 0010)。 - 新增 src/upstream-models.ts 统一上游 /v1/models 拉取逻辑,console 两个 上游模型拉取路由与自动同步复用同一实现。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S4YoQNdo1TzCjerUGFZoJy
- bunfig.toml 增加 [install] registry = npmjs,避免默认走 registry.npmmirror.com 经代理超时挂起。 - bun.lock 中 701 个 tarball URL 由 npmmirror 主机改写为 npmjs, 锁定版本保持不变(仅换源)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S4YoQNdo1TzCjerUGFZoJy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an "auto-sync upstream models" feature that allows providers to automatically synchronize their model lists from upstream
/v1/modelsendpoints. When enabled, the model list is fetched immediately on save and then synced every 24 hours via a scheduled task.Key Changes
New upstream models utility (
src/upstream-models.ts): Centralized logic for fetching model IDs from upstream/v1/modelsendpoints, supporting both OpenAI and Anthropic APIs with proper authentication header handling and timeout management.Provider auto-sync configuration:
autoSyncModelsboolean field to provider configuration and database schemamodelsSyncedAttimestamp to track last sync timesyncEntryModelsFromUpstream()function that validates upstream connectivity and replaces the provider's model list with upstream modelsImmediate sync on save: When creating or updating a provider with
autoSyncModelsenabled, the upstream models are fetched and validated before persisting to the database. If the fetch fails, the entire operation fails with a clear error message.24-hour scheduled sync: Added
runAutoModelSync()task inserver.tsthat runs every 24 hours to refresh model lists for all providers with auto-sync enabled.Console UI updates:
autoSyncModelsin the provider formfetchUpstreamModelIds()functionDatabase migration: Added
auto_sync_modelsandmodels_synced_atcolumns toconsole_providerstableImplementation Details
fetchUpstreamModelIds()function handles URL construction, authentication header normalization (auto-prefixingBearerfor authorization headers), and response parsing for both provider typeshttps://claude.ai/code/session_01S4YoQNdo1TzCjerUGFZoJy