Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ VITE_GITHUB_REDIRECT_URI=https://deepchatai.cn/auth/github/callback
VITE_LOG_IPC_CALL=0

VITE_APP_LIFECYCLE_HOOK_DELAY=0
VITE_PROVIDER_DB_URL=https://raw.githubusercontent.com/ThinkInAIXYZ/PublicProviderConf/refs/heads/dev/dist/all.json
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
VITE_GITHUB_CLIENT_ID: ${{ secrets.DC_GITHUB_CLIENT_ID }}
VITE_GITHUB_CLIENT_SECRET: ${{ secrets.DC_GITHUB_CLIENT_SECRET }}
VITE_GITHUB_REDIRECT_URI: ${{ secrets.DC_GITHUB_REDIRECT_URI }}
VITE_PROVIDER_DB_URL: ${{ secrets.CDN_PROVIDER_DB_URL }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -115,6 +116,7 @@ jobs:
VITE_GITHUB_CLIENT_ID: ${{ secrets.DC_GITHUB_CLIENT_ID }}
VITE_GITHUB_CLIENT_SECRET: ${{ secrets.DC_GITHUB_CLIENT_SECRET }}
VITE_GITHUB_REDIRECT_URI: ${{ secrets.DC_GITHUB_REDIRECT_URI }}
VITE_PROVIDER_DB_URL: ${{ secrets.CDN_PROVIDER_DB_URL }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -176,6 +178,7 @@ jobs:
VITE_GITHUB_CLIENT_SECRET: ${{ secrets.DC_GITHUB_CLIENT_SECRET }}
VITE_GITHUB_REDIRECT_URI: ${{ secrets.DC_GITHUB_REDIRECT_URI }}
NODE_OPTIONS: '--max-old-space-size=4096'
VITE_PROVIDER_DB_URL: ${{ secrets.CDN_PROVIDER_DB_URL }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ jobs:

- name: Build
run: pnpm run build
env:
VITE_PROVIDER_DB_URL: ${{ secrets.CDN_PROVIDER_DB_URL }}
2 changes: 2 additions & 0 deletions src/main/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface ImportMetaEnv {
readonly VITE_GITHUB_CLIENT_SECRET: string
readonly VITE_GITHUB_REDIRECT_URI: string
readonly VITE_LOG_IPC_CALL: string
readonly VITE_APP_LIFECYCLE_HOOK_DELAY?: string
readonly VITE_PROVIDER_DB_URL?: string
}

interface ImportMeta {
Expand Down
23 changes: 6 additions & 17 deletions src/main/presenter/configPresenter/modelConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,19 @@ export class ModelConfigHelper {

if (providerId) {
const cacheKey = this.generateCacheKey(providerId, modelId)
let cachedEntry = this.memoryCache.get(cacheKey)

if (!cachedEntry) {
const entryFromStore = this.modelConfigStore.get(cacheKey) as IModelConfig | undefined
if (entryFromStore) {
cachedEntry = entryFromStore
this.memoryCache.set(cacheKey, entryFromStore)
}
}
const cachedEntry = this.memoryCache.has(cacheKey)
? (this.memoryCache.get(cacheKey) as IModelConfig | undefined)
: undefined
Comment on lines +246 to +248
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.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify the cache behavior change is intentional.

The cache lookup logic now only checks the in-memory cache without falling back to the store on a miss. While initializeCache() is called at the start of getModelConfig(), this behavior change could cause issues if:

  • The memory cache is explicitly cleared via clearMemoryCache() or clearAllConfigs() without subsequent reinitialization
  • There are concurrent modifications to the store outside this class

Note that hasUserConfig() (line 439) still reads from the store as a fallback, which is inconsistent with this approach.

Run the following script to verify where the memory cache might be cleared:


🏁 Script executed:

#!/bin/bash
# Search for clearMemoryCache and clearAllConfigs calls
rg -nP '\bclearMemoryCache\s*\(|\bclearAllConfigs\s*\(' --type=ts -C3

Length of output: 1690


🏁 Script executed:

#!/bin/bash
rg -nP --type=ts 'getModelConfig\(' -C15 src/main/presenter/configPresenter/modelConfig.ts

Length of output: 1192


Restore store fallback or sync cache on writes

getModelConfig now returns undefined on a cache miss without falling back to modelConfigStore. Because initializeCache() only runs once, any configs added or updated afterward (e.g. via importConfigs) won’t be visible until the cache is reset. Either reintroduce a store lookup for cache misses or update memoryCache whenever the store changes.

🤖 Prompt for AI Agents
In src/main/presenter/configPresenter/modelConfig.ts around lines 246–248,
getModelConfig currently returns undefined on a memoryCache miss which breaks
visibility for configs added/updated after initializeCache; either reintroduce a
fallback lookup to modelConfigStore or ensure the store-write paths update
memoryCache. Fix by: on cache miss call the modelConfigStore to load the entry,
set it into memoryCache before returning, and/or update importConfigs/any config
write functions to write-through to memoryCache (i.e., after storing to
modelConfigStore, update memoryCache.set(cacheKey, newConfig)). Ensure both
synchronous return semantics and error handling for store access.


if (cachedEntry?.config) {
storedConfig = cachedEntry.config
storedSource = cachedEntry.source ?? (cachedEntry.config.isUserDefined ? 'user' : undefined)
} else if (normProviderId && normModelId) {
// 二次尝试:小写键(兼容历史大小写不一致的存储键)
const normKey = this.generateCacheKey(normProviderId, normModelId)
let normCached = this.memoryCache.get(normKey)
if (!normCached) {
const fromStore = this.modelConfigStore.get(normKey) as IModelConfig | undefined
if (fromStore) {
normCached = fromStore
this.memoryCache.set(normKey, fromStore)
}
}
const normCached = this.memoryCache.has(normKey)
? (this.memoryCache.get(normKey) as IModelConfig | undefined)
: undefined
if (normCached?.config) {
storedConfig = normCached.config
storedSource = normCached.source ?? (normCached.config.isUserDefined ? 'user' : undefined)
Expand Down
12 changes: 11 additions & 1 deletion src/main/presenter/configPresenter/providerDbLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,20 @@ export class ProviderDbLoader {
return Number.isFinite(v) && v > 0 ? v : 24
}

private getProviderDbUrl(): string {
const value = import.meta.env.VITE_PROVIDER_DB_URL
if (typeof value === 'string') {
const trimmed = value.trim()
if (trimmed.length > 0) return trimmed
}

return DEFAULT_PROVIDER_DB_URL
}

async refreshIfNeeded(force = false): Promise<void> {
const meta = this.readMeta()
const ttlHours = this.getTtlHours()
const url = process.env.PROVIDER_DB_URL || DEFAULT_PROVIDER_DB_URL
const url = this.getProviderDbUrl()

const needFirstFetch = !meta || !fs.existsSync(this.cacheFilePath)
const expired = meta ? this.now() - meta.lastUpdated > ttlHours * 3600 * 1000 : true
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface ImportMetaEnv {
readonly VITE_GITHUB_REDIRECT_URI: string
readonly VITE_LOG_IPC_CALL: string
readonly VITE_ENABLE_PLAYGROUND: 'true' | 'false'
readonly VITE_PROVIDER_DB_URL?: string
}

interface ImportMeta {
Expand Down