Open
Conversation
* 删除 uint8Array 重复封装 * 添加 ResourceService.loadByUrl 单元测试 --------- Co-authored-by: 王一之 <yz@ggnb.top>
…避免 supply chain 攻击) (#1341) * pnpm cooldown: 不抓取一星期内最新版 * pnpm: 提升至 10.33.0 以使用 minimumReleaseAge 避免 supply chain 攻击 * minimumReleaseAge 延长至 30 天(43200 分钟) --------- Co-authored-by: 王一之 <yz@ggnb.top>
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.
功能:为 ChatInput 添加 Prompt 优化按钮
描述
在 ChatInput 组件中新增一个“Optimize Prompt”按钮,允许用户使用 LLM 提供商 作为提示工程专家来改进他们的提示词。优化通过一次临时的无状态调用完成,不会持久化到对话历史中。
变更内容
后端服务层
src/app/service/agent/service_worker/agent.ts在
init()中注册新的消息处理器optimizePrompt新增私有方法
handleOptimizePrompt():ChatService.handleConversationChat(),并设置ephemeral: trueUI / Hook 层
src/pages/options/routes/AgentChat/hooks.ts新增
useOptimizePrompt()Hook:serviceWorker/agent/optimizePrompt处理器isOptimizing状态和流式数据收集{ isOptimizing, optimize, cancel }AbortController取消前端组件
src/pages/options/routes/AgentChat/ChatInput.tsx从 hooks 中引入
useOptimizePrompt在组件中调用:
const { isOptimizing, optimize } = useOptimizePrompt()新增
handleOptimizePrompt()处理函数:optimize(modelId, userInput)添加工具栏按钮(⚙️ 图标):
架构优势
✅ 无 UI 层提供商处理:按钮委托给服务层,无需在 UI 层重复实现 LLM 流程
✅ 自动支持多提供商:继承
providerRegistry,无需硬编码即可支持所有已注册提供商(OpenAI、Anthropic、智谱等)✅ 内置重试机制:使用
LLMClient.callLLM(),支持 5 次指数退避重试✅ 清晰分层:UI 仅管理状态,临时处理器负责 LLM 调用逻辑
✅ 支持取消:用户可中途取消优化,连接会被正确清理
✅ 不污染对话历史:临时模式不会将优化记录写入聊天历史
技术细节
conversationChat处理路径(ephemeral: true+ 自定义系统提示)LLMClient实现修改文件
src/app/service/agent/service_worker/agent.ts(+15 行)src/pages/options/routes/AgentChat/hooks.ts(+40 行)src/pages/options/routes/AgentChat/ChatInput.tsx(+60 行)src/pages/options/routes/AgentChat/styles.css(+4 行)测试建议