Skip to content

Conversation

@zerob13
Copy link
Collaborator

@zerob13 zerob13 commented Nov 10, 2025

Summary by CodeRabbit

  • New Features

    • Font size level and CSS class properties now accessible for enhanced customization.
  • Improvements

    • Enhanced model configuration handling with improved normalization of user-defined settings.
    • Model configuration refresh operations now execute asynchronously in the background for better application responsiveness.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Walkthrough

The changes refactor model configuration handling in the settings store to support user-defined model merging and introduce asynchronous provider refresh scheduling. Font size level and CSS class are now exposed as public store properties.

Changes

Cohort / File(s) Summary
Settings Store Configuration Refactoring
src/renderer/src/stores/settings.ts
Added ModelConfig type import from @shared/presenter. Introduced applyUserDefinedModelConfig helper function to normalize and merge user-defined configs into model metadata. Modified refreshCustomModels and refreshStandardModels to apply user-defined configs during model building. Introduced scheduleProviderRefresh for asynchronous background refresh with error logging. Converted setModelConfig and resetModelConfig to use async refresh instead of synchronous updates. Exposed fontSizeLevel and fontSizeClass as public store properties.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant setModelConfig
    participant scheduleProviderRefresh
    participant Background as Background Task

    rect rgb(240, 248, 255)
    Note over Caller,Background: New Async Flow
    Caller->>setModelConfig: setModelConfig(config)
    setModelConfig->>setModelConfig: Write config to state
    setModelConfig->>scheduleProviderRefresh: scheduleProviderRefresh(providerId)
    setModelConfig-->>Caller: Return immediately
    end

    rect rgb(245, 255, 250)
    Note over Background: Async Background Execution
    scheduleProviderRefresh->>Background: Schedule async refresh
    Background->>Background: Refresh provider models<br/>with user-defined configs
    Background->>Background: Error handling & logging
    Background->>Background: Update model state
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Review the applyUserDefinedModelConfig helper function logic for correct config merging and field handling
  • Verify async scheduling in scheduleProviderRefresh handles errors appropriately and doesn't cause race conditions
  • Confirm refreshCustomModels and refreshStandardModels correctly apply user-defined configs during model building
  • Check that public store return properties are correctly computed/reactive

Possibly related PRs

Suggested labels

codex

Poem

🐰 Configs now flow like morning dew,
User-defined models merged anew,
Async whispers in the background hum,
Font sizes dance—refreshed, not glum!
Settings store, you're looking grand,
With gentle scheduling, all so planned. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: toggle model config refresh' is specific and directly related to the main changes in the pull request, which involve refactoring model config refresh logic to use asynchronous scheduling instead of synchronous immediate refresh.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/model-config-refresh

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 636a56d and 2608490.

📒 Files selected for processing (1)
  • src/renderer/src/stores/settings.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写

Files:

  • src/renderer/src/stores/settings.ts
src/{main,renderer}/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

src/{main,renderer}/**/*.ts: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging

Files:

  • src/renderer/src/stores/settings.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/error-logging.mdc)

**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/src/**/*

📄 CodeRabbit inference engine (.cursor/rules/i18n.mdc)

src/renderer/src/**/*: All user-facing strings must use i18n keys (avoid hardcoded user-visible text in code)
Use the 'vue-i18n' framework for all internationalization in the renderer
Ensure all user-visible text in the renderer uses the translation system

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/src/stores/**/*.{vue,ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/pinia-best-practices.mdc)

src/renderer/src/stores/**/*.{vue,ts,tsx,js,jsx}: Use modules to organize related state and actions
Implement proper state persistence for maintaining data across sessions
Use getters for computed state properties
Utilize actions for side effects and asynchronous operations
Keep the store focused on global state, not component-specific data

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/**/*.{vue,ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

渲染进程代码放在 src/renderer

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/vue-best-practices.mdc)

src/renderer/src/**/*.{vue,ts,tsx,js,jsx}: Use the Composition API for better code organization and reusability
Implement proper state management with Pinia
Utilize Vue Router for navigation and route management
Leverage Vue's built-in reactivity system for efficient data handling

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,tsx,vue}: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/**/*.{vue,ts}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

Implement lazy loading for routes and components.

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/**/*.{ts,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,vue}: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.

Use Pinia for frontend state management (do not introduce alternative state libraries)

Files:

  • src/renderer/src/stores/settings.ts
**/*.{ts,tsx,js,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for all logs and comments

Files:

  • src/renderer/src/stores/settings.ts
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Enable and adhere to strict TypeScript typing (avoid implicit any, prefer precise types)

Use PascalCase for TypeScript types and classes

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/src/**

📄 CodeRabbit inference engine (AGENTS.md)

Place Vue 3 app source under src/renderer/src (components, stores, views, i18n, lib)

Files:

  • src/renderer/src/stores/settings.ts
src/renderer/src/**/*.{vue,ts}

📄 CodeRabbit inference engine (AGENTS.md)

All user-facing strings must use vue-i18n ($t/keys) rather than hardcoded literals

Files:

  • src/renderer/src/stores/settings.ts
**/*.{ts,tsx,js,jsx,vue,css,scss,md,json,yml,yaml}

📄 CodeRabbit inference engine (AGENTS.md)

Prettier style: single quotes, no semicolons, print width 100; run pnpm run format

Files:

  • src/renderer/src/stores/settings.ts
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx,vue}: Use OxLint for JS/TS code; keep lint clean
Use camelCase for variables and functions
Use SCREAMING_SNAKE_CASE for constants

Files:

  • src/renderer/src/stores/settings.ts
🧠 Learnings (12)
📚 Learning: 2025-09-06T03:07:23.817Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-06T03:07:23.817Z
Learning: Applies to src/main/presenter/configPresenter/providers.ts : Add provider configuration entries in src/main/presenter/configPresenter/providers.ts

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-21T01:47:03.479Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/pinia-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:47:03.479Z
Learning: Applies to src/renderer/src/stores/**/*.{vue,ts,tsx,js,jsx} : Implement proper state persistence for maintaining data across sessions

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-21T01:45:54.229Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:45:54.229Z
Learning: Applies to src/shared/*.d.ts : The shared/*.d.ts files are used to define the types of objects exposed by the main process to the renderer process

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-23T00:45:57.322Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/vue-shadcn.mdc:0-0
Timestamp: 2025-07-23T00:45:57.322Z
Learning: Applies to src/renderer/stores/**/*.ts : Use Pinia for state management.

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-10-14T08:02:59.495Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-14T08:02:59.495Z
Learning: Use TypeScript + Vue 3 Composition API with Pinia for state and Tailwind for styles in the renderer

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-21T01:47:28.817Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/vue-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:47:28.817Z
Learning: Applies to src/renderer/src/**/*.{vue,ts,tsx,js,jsx} : Implement proper state management with Pinia

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-09-06T03:07:23.817Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-06T03:07:23.817Z
Learning: Applies to src/renderer/**/*.{ts,vue} : Use Pinia for frontend state management (do not introduce alternative state libraries)

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-21T01:47:03.479Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/pinia-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:47:03.479Z
Learning: Applies to src/renderer/src/stores/**/*.{vue,ts,tsx,js,jsx} : Keep the store focused on global state, not component-specific data

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-21T01:47:03.479Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/pinia-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:47:03.479Z
Learning: Applies to src/renderer/src/stores/**/*.{vue,ts,tsx,js,jsx} : Use modules to organize related state and actions

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-09-04T11:03:30.184Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/provider-guidelines.mdc:0-0
Timestamp: 2025-09-04T11:03:30.184Z
Learning: Integrate via the llmProviderPresenter entry point (src/main/presenter/llmProviderPresenter/index.ts) as the related implementation entry

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-10-14T08:02:59.495Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-14T08:02:59.495Z
Learning: Applies to src/main/presenter/LLMProvider/**/*.ts : Implement the two-layer LLM provider (Agent Loop + Provider) under src/main/presenter/LLMProvider

Applied to files:

  • src/renderer/src/stores/settings.ts
📚 Learning: 2025-07-23T00:45:57.322Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/vue-shadcn.mdc:0-0
Timestamp: 2025-07-23T00:45:57.322Z
Learning: Applies to src/renderer/**/*.{vue} : Leverage ref, reactive, and computed for reactive state management.

Applied to files:

  • src/renderer/src/stores/settings.ts
🧬 Code graph analysis (1)
src/renderer/src/stores/settings.ts (4)
src/shared/types/presenters/legacy.presenters.d.ts (2)
  • RENDERER_MODEL_META (552-566)
  • ModelConfig (132-150)
src/shared/types/presenters/llmprovider.presenter.d.ts (1)
  • RENDERER_MODEL_META (10-25)
src/main/presenter/configPresenter/modelConfig.ts (2)
  • setModelConfig (377-402)
  • resetModelConfig (409-416)
src/main/presenter/configPresenter/index.ts (2)
  • setModelConfig (1163-1178)
  • resetModelConfig (1185-1194)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-check (x64)
🔇 Additional comments (4)
src/renderer/src/stores/settings.ts (4)

3-8: LGTM: Import addition is appropriate.

The ModelConfig type import is properly added and used by the new applyUserDefinedModelConfig function.


446-456: LGTM: User-defined config integration is well-implemented.

The use of Promise.all with applyUserDefinedModelConfig properly handles async operations and ensures all custom models have user-defined configurations applied before updating the store.


597-612: LGTM: Consistent implementation with custom models.

Standard models now correctly apply user-defined configurations using the same pattern as custom models, maintaining consistency across the codebase.


1988-1992: LGTM: Font size properties properly exposed.

The fontSizeLevel and fontSizeClass properties are now correctly exposed in the store's public API, enabling external consumers to read font size settings.

Comment on lines +1966 to +1970
const scheduleProviderRefresh = (providerId: string) => {
refreshProviderModels(providerId).catch((error) => {
console.error(`后台刷新模型失败: ${providerId}`, error)
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix Chinese error message.

Line 1968: The error message "后台刷新模型失败" is in Chinese. As per coding guidelines, all logs and comments must use English.

As per coding guidelines.

Apply this diff:

-      console.error(`后台刷新模型失败: ${providerId}`, error)
+      console.error(`Background model refresh failed: ${providerId}`, error)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const scheduleProviderRefresh = (providerId: string) => {
refreshProviderModels(providerId).catch((error) => {
console.error(`后台刷新模型失败: ${providerId}`, error)
})
}
const scheduleProviderRefresh = (providerId: string) => {
refreshProviderModels(providerId).catch((error) => {
console.error(`Background model refresh failed: ${providerId}`, error)
})
}
🤖 Prompt for AI Agents
In src/renderer/src/stores/settings.ts around lines 1966 to 1970, the
console.error message uses Chinese text ("后台刷新模型失败"); replace it with an English
message such as "Failed to refresh provider models in background" (or similar),
preserving inclusion of providerId and the error object in the log call so the
output remains: console.error("Failed to refresh provider models in
background:", providerId, error).

@zerob13 zerob13 merged commit f7a76c2 into dev Nov 10, 2025
2 checks passed
zerob13 added a commit that referenced this pull request Nov 10, 2025
* Merge pull request #1079 from ThinkInAIXYZ/bugfix/refresh-model

fix: custom provider add refresh-model

* fix: add tool call context for better conv (#1081)

* fix: update `tag_name` for release artifact urls (#1084)

Signed-off-by: Rui Chen <rui@chenrui.dev>

* refactor: standardize image block data structure (#1082)

* refactor: standardize image block data structure with backward compatibility

Normalize image_data structure in ThreadPresenter to ensure consistent mimeType handling. Update MessageBlockImage component to support legacy data formats (content as object/string/data URI) while maintaining compatibility with new image_data field.

* fix: properly normalize image data URIs before persistence

Extract base64 content and mime type from data URIs (data:image/jpeg;base64,...) to prevent double-encoding in renderer. This fixes image display errors where data:image/png;base64,data:image/jpeg;base64,... was being constructed.

- Parse data URIs to extract real mime type and base64 content
- Force URL schemes (http://, https://, imgcache://) to deepchat/image-url
- Preserve provided mime types when available
- Fallback to image/png only for raw base64 without metadata

* fix: normalize legacy data URIs in renderer to prevent double-encoding

Handle historical image_data records that may still contain full data:image/...;base64,... URIs. Extract base64 content and mime type before template binding to prevent constructing invalid data:image/png;base64,data:image/png;base64,... URIs.

- Parse data URIs in both new image_data and legacy content formats
- Always provide mimeType fallback for historical records
- Ensure normalized data format before template consumption

* feat: add request trace for llm (#1085)

* feat: add trace support wip

* feat: add trace dialog with monaco

* feat: add i18n for trace dialog

* feat: add config for trace params

* fix: prevent stale previews when messageId changes

* fix: toggle model config refresh (#1086)

* release: 0.4.5

---------

Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: 韦伟 <xweimvp@gmail.com>
@zerob13 zerob13 deleted the bugfix/model-config-refresh branch November 23, 2025 13:52
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