-
Notifications
You must be signed in to change notification settings - Fork 625
Bugfix/custom prompt cant load content #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughIntroduces GitHub Issue Forms for bug/enhancement and removes legacy Markdown templates. Adds a cache for custom prompts in ConfigPresenter with a new clear method. Updates McpPresenter to fetch custom prompts via a special client name. Adjusts renderer store mapping to the new client identifier. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as Renderer (loadPrompts)
participant MCP as McpPresenter.getPrompt
participant CFG as ConfigPresenter (cache)
note over UI: Prompts include client.name = "deepchat/custom-prompts-server"
User->>UI: Reference @custom-prompt
UI->>MCP: getPrompt({ client.name="deepchat/custom-prompts-server", name })
MCP->>CFG: getCustomPrompts()
alt Cache warm
CFG-->>MCP: prompts[] (from cache)
else Cache cold / error
CFG->>CFG: Load from store, cache result
CFG-->>MCP: prompts[]
end
MCP->>MCP: Find prompt by name
alt Found
MCP-->>UI: {name, description, content|messages|args}
else Not found
MCP-->>UI: throw Error("prompt not found")
end
rect rgba(230,245,255,0.4)
note right of MCP: Existing path (unchanged)
UI->>MCP: getPrompt({ client.name != custom-prompts })
MCP-->>UI: toolManager.getPromptByClient(...)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (8)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/stores/mcp.ts (1)
368-377: Add missing id field to custom prompt list entriesPromptListEntry objects elsewhere include an id (see mcpPresenter.getAllPrompts). Omitting it here risks keying/selection bugs.
Apply this diff:
- customPrompts = configPrompts.map((prompt) => ({ - name: prompt.name, + customPrompts = configPrompts.map((prompt) => ({ + id: prompt.name, + name: prompt.name, description: prompt.description, arguments: prompt.parameters || [], files: prompt.files || [], client: { name: 'deepchat/custom-prompts-server', icon: '⚙️' } }))
🧹 Nitpick comments (6)
src/renderer/src/stores/mcp.ts (1)
374-376: Avoid hardcoding the client identifier in multiple filesUse a shared constant to prevent drift between renderer and main.
Create a shared constant:
// src/shared/constants/mcp.ts export const CUSTOM_PROMPTS_CLIENT_NAME = 'deepchat/custom-prompts-server'Then import and use it here:
- name: 'deepchat/custom-prompts-server', + name: CUSTOM_PROMPTS_CLIENT_NAME,And add the import at top of file:
import { CUSTOM_PROMPTS_CLIENT_NAME } from '@shared/constants/mcp'src/main/presenter/mcpPresenter/index.ts (1)
1095-1118: Custom prompt resolution: solid; add files and de-duplicate identifierThe special-case works. Include files for parity with other prompt shapes, and use a shared constant for the client name.
Apply this diff:
- // Check if this is a custom prompt from deepchat/custom-prompts-server - if (prompt.client.name === 'deepchat/custom-prompts-server') { + // Check if this is a custom prompt from deepchat/custom-prompts-server + if (prompt.client.name === 'deepchat/custom-prompts-server') { console.log(`[MCP] Getting custom prompt: ${prompt.name}`) try { const customPrompts = await this.configPresenter.getCustomPrompts() const foundPrompt = customPrompts.find((p) => p.name === prompt.name) if (foundPrompt) { // Return the prompt in the expected format return { name: foundPrompt.name, description: foundPrompt.description, content: foundPrompt.content || '', messages: foundPrompt.messages || [], - arguments: foundPrompt.parameters || [] + arguments: foundPrompt.parameters || [], + files: foundPrompt.files || [] } } else { throw new Error(`Custom prompt "${prompt.name}" not found`) } } catch (error) { console.error(`[MCP] Failed to get custom prompt "${prompt.name}":`, error) throw error } }Additionally, prefer a shared constant:
// src/shared/constants/mcp.ts export const CUSTOM_PROMPTS_CLIENT_NAME = 'deepchat/custom-prompts-server'And in this file:
import { CUSTOM_PROMPTS_CLIENT_NAME } from '@shared/constants/mcp' ... if (prompt.client.name === CUSTOM_PROMPTS_CLIENT_NAME) { ... }src/main/presenter/configPresenter/index.ts (4)
1219-1224: Minor: comment language + log wordingUse English comments. Consider clarifying the log since cache is cleared, not “updated”.
Apply this diff:
- // 保存自定义 prompts (with cache update) + // Save custom prompts (with cache invalidation) async setCustomPrompts(prompts: Prompt[]): Promise<void> { await this.customPromptsStore.set('prompts', prompts) this.clearCustomPromptsCache() - console.log(`[Config] Custom prompts cache updated: ${prompts.length} prompts`) + console.log(`[Config] Custom prompts saved and cache cleared: ${prompts.length} prompts`) }
1226-1233: Remove redundant cache clear; comment languagesetCustomPrompts already clears the cache.
Apply this diff:
- // 添加单个 prompt (optimized with cache) + // Add a single prompt (optimized with cache) async addCustomPrompt(prompt: Prompt): Promise<void> { const prompts = await this.getCustomPrompts() const updatedPrompts = [...prompts, prompt] // Create new array await this.setCustomPrompts(updatedPrompts) - this.clearCustomPromptsCache() console.log(`[Config] Added custom prompt: ${prompt.name}`) }
1235-1249: Remove redundant cache clear; comment languagesetCustomPrompts already clears the cache.
Apply this diff:
- // 更新单个 prompt (optimized with cache) + // Update a single prompt (optimized with cache) async updateCustomPrompt(promptId: string, updates: Partial<Prompt>): Promise<void> { const prompts = await this.getCustomPrompts() const index = prompts.findIndex((p) => p.id === promptId) if (index !== -1) { const updatedPrompts = [...prompts] // Create new array updatedPrompts[index] = { ...updatedPrompts[index], ...updates } await this.setCustomPrompts(updatedPrompts) - // remove cache - this.clearCustomPromptsCache() console.log(`[Config] Updated custom prompt: ${promptId}`) } else { console.warn(`[Config] Custom prompt not found for update: ${promptId}`) } }
1251-1265: Remove redundant cache clear; comment languagesetCustomPrompts already clears the cache.
Apply this diff:
- // 删除单个 prompt (optimized with cache) + // Delete a single prompt (optimized with cache) async deleteCustomPrompt(promptId: string): Promise<void> { const prompts = await this.getCustomPrompts() const initialCount = prompts.length const filteredPrompts = prompts.filter((p) => p.id !== promptId) if (filteredPrompts.length === initialCount) { console.warn(`[Config] Custom prompt not found for deletion: ${promptId}`) return } await this.setCustomPrompts(filteredPrompts) - this.clearCustomPromptsCache() console.log(`[Config] Deleted custom prompt: ${promptId}`) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
.github/ISSUE_TEMPLATE/bug.yml(1 hunks).github/ISSUE_TEMPLATE/bug_report.md(0 hunks).github/ISSUE_TEMPLATE/feature.yml(1 hunks).github/ISSUE_TEMPLATE/feature_request.md(0 hunks).github/pull_request_template.md(0 hunks)src/main/presenter/configPresenter/index.ts(2 hunks)src/main/presenter/mcpPresenter/index.ts(1 hunks)src/renderer/src/stores/mcp.ts(1 hunks)
💤 Files with no reviewable changes (3)
- .github/ISSUE_TEMPLATE/feature_request.md
- .github/pull_request_template.md
- .github/ISSUE_TEMPLATE/bug_report.md
🧰 Additional context used
📓 Path-based instructions (20)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)
**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写
**/*.{js,jsx,ts,tsx}: Use OxLint for JS/TS code; pre-commit hooks run lint-staged and typecheck
Use camelCase for variables and functions
Use PascalCase for types and classes
Use SCREAMING_SNAKE_CASE for constants
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.tssrc/renderer/src/stores/mcp.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/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.tssrc/renderer/src/stores/mcp.ts
src/main/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)
Use Electron's built-in APIs for file system and native dialogs
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/error-logging.mdc)
**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.tssrc/renderer/src/stores/mcp.ts
src/main/**/*.{ts,js,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
主进程代码放在
src/main
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.ts
**/*.{ts,tsx,js,vue}
📄 CodeRabbit inference engine (CLAUDE.md)
Use English for all logs and comments
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.tssrc/renderer/src/stores/mcp.ts
**/*.{ts,tsx,vue}
📄 CodeRabbit inference engine (CLAUDE.md)
Enable and adhere to strict TypeScript typing (avoid implicit any, prefer precise types)
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.tssrc/renderer/src/stores/mcp.ts
src/main/presenter/mcpPresenter/index.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Register new MCP tools in src/main/presenter/mcpPresenter/index.ts
Files:
src/main/presenter/mcpPresenter/index.ts
src/main/**
📄 CodeRabbit inference engine (AGENTS.md)
Place all Electron main-process code under src/main/
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.ts
src/main/presenter/**
📄 CodeRabbit inference engine (AGENTS.md)
src/main/presenter/**: Organize main-process presenters under src/main/presenter/ (Window/Tab/Thread/Mcp/Config/LLMProvider)
Follow the Presenter pattern for main-process modules
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.ts
**/*.{js,jsx,ts,tsx,vue}
📄 CodeRabbit inference engine (AGENTS.md)
Apply Prettier formatting: single quotes, no semicolons, max width 100
Files:
src/main/presenter/mcpPresenter/index.tssrc/main/presenter/configPresenter/index.tssrc/renderer/src/stores/mcp.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/mcp.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/mcp.ts
src/renderer/**/*.{vue,ts,js,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
渲染进程代码放在
src/renderer
Files:
src/renderer/src/stores/mcp.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/mcp.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/mcp.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/mcp.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/mcp.ts
src/renderer/src/**
📄 CodeRabbit inference engine (AGENTS.md)
Put application code for the Vue app under src/renderer/src (components, stores, views, i18n, lib)
Files:
src/renderer/src/stores/mcp.ts
src/renderer/src/**/*.{vue,ts}
📄 CodeRabbit inference engine (AGENTS.md)
All user-facing strings in the renderer must use vue-i18n keys defined in src/renderer/src/i18n
Files:
src/renderer/src/stores/mcp.ts
🧠 Learnings (2)
📚 Learning: 2025-07-21T01:46:52.880Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-07-21T01:46:52.880Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : When a provider does not support native function calling, it must prepare messages using prompt wrapping (e.g., `prepareFunctionCallPrompt`) before making the API call.
Applied to files:
src/main/presenter/mcpPresenter/index.ts
📚 Learning: 2025-09-06T03:07:23.817Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-06T03:07:23.817Z
Learning: Applies to src/main/presenter/mcpPresenter/index.ts : Register new MCP tools in src/main/presenter/mcpPresenter/index.ts
Applied to files:
src/main/presenter/mcpPresenter/index.ts
🧬 Code graph analysis (1)
src/main/presenter/configPresenter/index.ts (1)
src/shared/types/presenters/legacy.presenters.d.ts (1)
Prompt(58-74)
⏰ 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 (3)
.github/ISSUE_TEMPLATE/feature.yml (1)
1-25: Issue form looks solidThe enhancement template is well structured with bilingual guidance, proper required fields, and correct YAML syntax. Nicely done.
.github/ISSUE_TEMPLATE/bug.yml (1)
1-43: Bug report template LGTMThe bug-report form captures the essential metadata, enforces the right required inputs, and keeps the bilingual context tidy. Looks ready to ship.
src/main/presenter/configPresenter/index.ts (1)
103-105: Good: adds in-memory cache for custom promptsThis will reduce disk IO on frequent access.
| // 获取所有自定义 prompts (with cache) | ||
| async getCustomPrompts(): Promise<Prompt[]> { | ||
| // Check cache first | ||
| if (this.customPromptsCache !== null) { | ||
| return this.customPromptsCache | ||
| } | ||
|
|
||
| // Load from store and cache it | ||
| try { | ||
| return this.customPromptsStore.get('prompts') || [] | ||
| } catch { | ||
| const prompts = this.customPromptsStore.get('prompts') || [] | ||
| this.customPromptsCache = prompts | ||
| console.log(`[Config] Custom prompts cache loaded: ${prompts.length} prompts`) | ||
| return prompts | ||
| } catch (error) { | ||
| console.error('[Config] Failed to load custom prompts:', error) | ||
| this.customPromptsCache = [] | ||
| return [] | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not cache failure results; also use English comments per guidelines
Caching [] on error locks out future reads until an external invalidation. Prefer leaving cache null after failures. Also, comments must be in English (see coding guidelines).
Apply this diff:
- // 获取所有自定义 prompts (with cache)
+ // Get all custom prompts (with cache)
async getCustomPrompts(): Promise<Prompt[]> {
// Check cache first
if (this.customPromptsCache !== null) {
return this.customPromptsCache
}
// Load from store and cache it
try {
const prompts = this.customPromptsStore.get('prompts') || []
this.customPromptsCache = prompts
console.log(`[Config] Custom prompts cache loaded: ${prompts.length} prompts`)
return prompts
} catch (error) {
console.error('[Config] Failed to load custom prompts:', error)
- this.customPromptsCache = []
+ this.customPromptsCache = null
return []
}
}🤖 Prompt for AI Agents
In src/main/presenter/configPresenter/index.ts around lines 1199 to 1217, change
the Chinese comment to English and stop caching failure results: update the
comment to "Get all custom prompts (with cache)"; when an error occurs, do not
set this.customPromptsCache = [] — leave this.customPromptsCache as null so
future reads can retry; keep logging the error but remove the cache assignment
in the catch block so failures aren't persisted.
| /** | ||
| * 清除自定义 prompts 缓存 | ||
| * 这将强制下次访问时重新加载 | ||
| */ | ||
| clearCustomPromptsCache(): void { | ||
| console.log('[Config] Clearing custom prompts cache') | ||
| this.customPromptsCache = null | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments must be in English
Align with repository guidelines.
Apply this diff:
- /**
- * 清除自定义 prompts 缓存
- * 这将强制下次访问时重新加载
- */
+ /**
+ * Clear custom prompts cache
+ * Forces reload on next access
+ */📝 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.
| /** | |
| * 清除自定义 prompts 缓存 | |
| * 这将强制下次访问时重新加载 | |
| */ | |
| clearCustomPromptsCache(): void { | |
| console.log('[Config] Clearing custom prompts cache') | |
| this.customPromptsCache = null | |
| } | |
| /** | |
| * Clear custom prompts cache | |
| * Forces reload on next access | |
| */ | |
| clearCustomPromptsCache(): void { | |
| console.log('[Config] Clearing custom prompts cache') | |
| this.customPromptsCache = null | |
| } |
🤖 Prompt for AI Agents
In src/main/presenter/configPresenter/index.ts around lines 1267 to 1274, the
block comment above clearCustomPromptsCache is written in Chinese; update the
comment to English to match repository guidelines—replace the existing Chinese
comment with a concise English JSDoc or single-line comment describing that the
method clears the custom prompts cache and forces reload on next access, keeping
the implementation unchanged.
Summary by CodeRabbit
New Features
Performance
Documentation
Chores