模板规则变更检测 — 启动聊天时比对选项变更并弹窗确认#195
Open
Mizushima-Mihane wants to merge 4 commits into
Open
Conversation
- 新增 ruleChangeDialogOpen 状态,启动聊天时遍历 templateOptionsState 与 launchSession 逐一比对,检测 LLM 翻译/旁白规则等开关变更 - AlertDialog 新增可选 onClose / cancelTitle 属性 - 弹窗选项:是→快速重启,否→沿用旧规则启动,X→关闭不启动 - 动态比对:新增选项自动纳入检测,无需手动更新判断列表 - 新增中/英/日三语翻译 Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
审查者指南在启动聊天时实现模板选项规则变更的动态检测,新增确认对话框,让用户在“快速重新开始”和“继续使用旧规则”之间进行选择,并扩展共享的 AlertDialog/i18n,使其支持这一流程及多语言文案。 规则变更检测与启动流程的时序图sequenceDiagram
actor User
participant TemplateEditorPage
participant AlertDialog
participant launchMutation
User->>TemplateEditorPage: click AsyncButton launch
TemplateEditorPage->>TemplateEditorPage: compare templateOptionsState with launchSession
alt rules_changed
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(true)
TemplateEditorPage->>AlertDialog: render with open=true
alt User clicks Yes (confirm)
AlertDialog->>TemplateEditorPage: onConfirm()
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
TemplateEditorPage->>launchMutation: mutate(resetHistory=true)
else User clicks No (cancel)
AlertDialog->>TemplateEditorPage: onCancel()
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
else User clicks Close (X)
AlertDialog->>TemplateEditorPage: onClose()
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
end
else rules_unchanged
TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
end
文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideImplements dynamic detection of template option rule changes when launching a chat, adds a confirmation dialog that lets users choose between quick restart or continuing with old rules, and extends the shared AlertDialog/i18n to support this flow with multi-language copy. Sequence diagram for rule-change detection and launch flowsequenceDiagram
actor User
participant TemplateEditorPage
participant AlertDialog
participant launchMutation
User->>TemplateEditorPage: click AsyncButton launch
TemplateEditorPage->>TemplateEditorPage: compare templateOptionsState with launchSession
alt rules_changed
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(true)
TemplateEditorPage->>AlertDialog: render with open=true
alt User clicks Yes (confirm)
AlertDialog->>TemplateEditorPage: onConfirm()
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
TemplateEditorPage->>launchMutation: mutate(resetHistory=true)
else User clicks No (cancel)
AlertDialog->>TemplateEditorPage: onCancel()
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
else User clicks Close (X)
AlertDialog->>TemplateEditorPage: onClose()
TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
end
else rules_unchanged
TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - 我发现了一个问题,并留下了一些高层次的反馈:
- 启动按钮点击处理器中的规则变更检测逻辑有点臃肿;可以考虑把比较逻辑提取到一个小的辅助函数中(例如
hasTemplateRulesChanged(launchSession, templateOptionsState)),这样能让组件更易读,也便于将来修改比较逻辑。 - 你正在对
templateOptionsState的所有键直接使用launchSession[key] !== templateOptionsState[key]进行比较;如果这些值中有任何一个将来变成对象或数组,即使其逻辑内容相同,这种比较也总会报告为发生了变化。因此,更安全的做法可能是:要么将检查的键限制为已知的原始类型标志,要么使用能够体现预期语义的比较方式。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The rule-change detection logic in the launch button click handler is getting a bit dense; consider extracting the comparison into a small helper (e.g. `hasTemplateRulesChanged(launchSession, templateOptionsState)`) to keep the component more readable and make future changes to the comparison logic easier.
- You are directly comparing `launchSession[key] !== templateOptionsState[key]` for all keys of `templateOptionsState`; if any of these values ever become objects/arrays, this will always report a change even when the logical content is the same, so it might be safer to either restrict the checked keys to known primitive flags or use a comparison that reflects the intended semantics.
## Individual Comments
### Comment 1
<location path="frontend/src/shared/i18n/messages/en.ts" line_range="916" />
<code_context>
"template.noEffect": "No effect",
"template.quickRestart.body": "Clear the selected/default chat history and launch a fresh chat?",
"template.quickRestart.title": "Quick restart",
+ "template.ruleChangeDialog.body": "Content rule changes detected. Do you want to quick restart?",
+ "template.ruleChangeDialog.title": "Content Rule Changed",
+ "template.ruleChangeDialog.toast": "Chat will continue using previously saved rules",
</code_context>
<issue_to_address>
**nitpick (typo):** Minor wording issue in the new English message string.
The phrase "Do you want to quick restart?" is ungrammatical. Please update to something more natural, e.g. "Do you want to quick-restart?" or "Do you want to perform a quick restart?".
```suggestion
"template.ruleChangeDialog.body": "Content rule changes detected. Do you want to perform a quick restart?",
```
</issue_to_address>Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The rule-change detection logic in the launch button click handler is getting a bit dense; consider extracting the comparison into a small helper (e.g.
hasTemplateRulesChanged(launchSession, templateOptionsState)) to keep the component more readable and make future changes to the comparison logic easier. - You are directly comparing
launchSession[key] !== templateOptionsState[key]for all keys oftemplateOptionsState; if any of these values ever become objects/arrays, this will always report a change even when the logical content is the same, so it might be safer to either restrict the checked keys to known primitive flags or use a comparison that reflects the intended semantics.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The rule-change detection logic in the launch button click handler is getting a bit dense; consider extracting the comparison into a small helper (e.g. `hasTemplateRulesChanged(launchSession, templateOptionsState)`) to keep the component more readable and make future changes to the comparison logic easier.
- You are directly comparing `launchSession[key] !== templateOptionsState[key]` for all keys of `templateOptionsState`; if any of these values ever become objects/arrays, this will always report a change even when the logical content is the same, so it might be safer to either restrict the checked keys to known primitive flags or use a comparison that reflects the intended semantics.
## Individual Comments
### Comment 1
<location path="frontend/src/shared/i18n/messages/en.ts" line_range="916" />
<code_context>
"template.noEffect": "No effect",
"template.quickRestart.body": "Clear the selected/default chat history and launch a fresh chat?",
"template.quickRestart.title": "Quick restart",
+ "template.ruleChangeDialog.body": "Content rule changes detected. Do you want to quick restart?",
+ "template.ruleChangeDialog.title": "Content Rule Changed",
+ "template.ruleChangeDialog.toast": "Chat will continue using previously saved rules",
</code_context>
<issue_to_address>
**nitpick (typo):** Minor wording issue in the new English message string.
The phrase "Do you want to quick restart?" is ungrammatical. Please update to something more natural, e.g. "Do you want to quick-restart?" or "Do you want to perform a quick restart?".
```suggestion
"template.ruleChangeDialog.body": "Content rule changes detected. Do you want to perform a quick restart?",
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 将内联比对逻辑提取为 hasTemplateRulesChanged(session, options) - 加 typeof boolean 守卫:非原始值直接跳过,避免未来对象/数组误报变更 - 修 en.ts 语法:Do you want to quick restart → perform a quick restart Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
session as Record<string, unknown> → session as unknown as Record<string, unknown> TemplateLaunchSession 缺少索引签名,直接 cast 在 --pretty false 模式下报 TS2352 Co-Authored-By: Claude <noreply@anthropic.com>
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 by Sourcery
在启动聊天时,如果模板内容规则与上一次启动的会话不同,则添加一个确认对话框,让用户在快速重启和继续使用之前规则之间进行选择。
新功能:
AlertDialog组件,增加可选的关闭处理逻辑,以及用于取消操作的提示文本(tooltip)。增强改进:
onCancel分离的专用onClose处理函数,以更好地反映用户意图。Original summary in English
Summary by Sourcery
Add a confirmation dialog when launching a chat if template content rules differ from the last launched session, allowing users to choose between quick restart or continuing with previous rules.
New Features:
Enhancements: