Compare commits

...
22 Commits
Author SHA1 Message Date
梦圣智杰 2066b93b40 chore: 发布 v2.2.1 / Release v2.2.1 2026-11-06 01:35:17 +08:00
梦圣智杰 1e0cf30c7c fix: 双击标签打不开编辑弹窗 / Fix double-click not opening the editor
- README 修了几处排版:demo 图前面误入的零宽度空格和 Tab(会让那行变成代码块、图片不显示)、一处粗体末尾多出的空格(星号会直接显示出来),以及「git安转」的错字。
2026-11-06 01:32:42 +08:00
梦圣智杰 bf5cf58c23 chore: 发布 v2.2.0 / Release v2.2.0
- 新增右下角操作提示条,按操作类型分色,可在设置里关闭。
- 标签删除与添加加入过渡动画,删掉后其余标签平滑让位。
- 新增「点击节点时跟随切换」:点画布节点,侧边栏自动切过去。
- 拖动时可以实时预览顺序(节点标签区与明细表各一个开关,默认关)。
- 撤销快捷键改为 Shift+Alt+Z / 重做 Shift+Alt+Y,不再占用 Ctrl+Z。
- 右上角弹窗同类操作就地更新,不再一条接一条冒;出错提示停留延长到 8 秒。
- 英文标签小卡的眼睛与删除按钮分居两个角,不再叠在一起。
- 设置面板重新归置:「通用」项收进外观、语言与跟随切换,折叠新增「全部开启」总开关。
2026-11-05 17:08:25 +08:00
梦圣智杰 082f82cacf feat: 试验结束,设置面板定稿 / Finish the settings experiment
- 设置面板里的「语言与外观」改名「通用」,外观、语言、跟随选中节点都收进这一项里。
- 「跟随选中节点」不再单独占一行设置项,挪到「通用」里面、语言设置下面。
- 原来那个 bulingbuling 折叠改名「通知弹窗及实时动画预览」,最上面多了「全部开启」总开关,一次控制弹窗、提示条、两个拖动预览和增删动画。
- README 和架构文档同步了这些改名与位置调整。
2026-11-05 17:00:25 +08:00
梦圣智杰 f4821317ad docs: 更新 README / Update README
- README 按最近的功能改动重新整理了一遍:结构说明、新增的开关和提示条配色都同步了。
2026-11-05 16:44:12 +08:00
梦圣智杰 70b6c3f8be feat: 提示条按操作分色 / Color-code toasts by operation 2026-11-05 15:22:20 +08:00
梦圣智杰 770f5df5e3 merge: 合并 main 的节点 切换跟随/ Merge main into exp/bulingbuling 2026-11-05 15:05:15 +08:00
梦圣智杰 80bd7d6af7 feat: 新增「跟随选中节点」开关,点节点时侧边栏跟着切换 / Add a follow-selection switch so the sidebar follows the clicked node 2026-11-05 15:04:41 +08:00
梦圣智杰 eeddddf27a fix: 修插入到中间时标签跳动 / Fix tags jumping when inserting mid-list 2026-11-05 14:47:00 +08:00
梦圣智杰 14dab702ce feat: 标签增删动画 / Animate adding and removing tag
- 节点里删标签不再是一下子消失:那张卡先被一个大 X 从四个角划掉,整块铺上紫色,上下压出灰边,最后从左往右擦走;擦完剩下的标签滑过来补位。
- 添加标签时,新标签从左往右展开,旁边的标签滑开让位;底部快捷输入和搜词库点结果两条路都算。
- 两个动画共用一个开关
- 目前只做节点标签区(× 角标、选中后按 Delete、重复栏双击删除、底部快捷添加、搜词库点结果),明细表以后另做。
2026-11-04 16:32:04 +08:00
梦圣智杰 83c01742a0 merge: 合并 main 的角标改动 / Merge main into exp/bulingbuling 2026-10-31 08:07:02 +08:00
梦圣智杰 fea43bf66b fix: 隐藏按钮与删除按钮分居卡片两角 / Move the hide and delete corners apart
- 英文标签小卡右上角原来同时放着「眼睛(隐藏)」和「×(删除)」,两个按钮叠在一起容易点错;现在「×」变成卡片右上角的角标,「眼睛」挪到卡片右下角。
- 两个按钮都浮在卡片上、不占位置:卡片大小和以前完全一样,不会因为多了个按钮把标签撑大,也不会把刚好放得下一整行的标签挤到下一行;按钮压到文字时就盖在文字上面。
2026-10-31 07:59:44 +08:00
梦圣智杰 53994df55b feat: 优化错误提示 / Improve error notification 2026-10-31 07:43:04 +08:00
梦圣智杰 8e3f9cea0b feat: 拖动实时预览:拖动时其余标签实时让位 / Live drag preview with real-time reordering
- 新增「拖动实时预览」:拖动标签时其余标签实时让位,松手前就能看到最终顺序;
  节点标签区与明细表各一个开关,互不影响,默认关。关掉时行为与升级前一致
- 预览期间只调整界面上的顺序、不改动提示词文本,松手统一写入,撤销仍是一步
- 节点标签区:被拖的标签抬起跟随光标(不再放大),原位留空,其余标签平滑滑开
- 明细表:不做抬起、放大与半透明淡化,改用左侧实心色条 + 高亮底色 + 亮色文字来标记正在拖动的那一行
- 修复:拖回原位时其余标签不让位
- 修复:拖动途中其余标签疯狂左右闪
2026-10-31 05:49:58 +08:00
梦圣智杰 5065b4bd8f - 侧边栏「标签管理」写中文:「插件撤销:Shift+Alt+Z(重做:Shift+Alt+Y)」。 2026-10-31 03:37:37 +08:00
梦圣智杰 e6083bcd6a Merge branch 'main' into exp/bulingbuling 2026-10-31 03:21:20 +08:00
梦圣智杰 62c90526db fix: 节点内拖拽落点提示只对英文行生效 / Fix drop hint only matching the English row 2026-10-31 02:55:38 +08:00
梦圣智杰 12b0af695e - 弹窗退场时卡片后面多垫了一层:卡片(蓝)先向右滑走,接着是紫红那层,最后才是绿底纸,三层依次离场;平时看不到这层。 2026-10-30 02:16:14 +08:00
梦圣智杰 a15c27c879 feat: 新增右下角提示条,重构操作反馈与撤销提示 / Add bottom-right toast and rework operation feedback
- 新增右下角堆叠提示条:节点增删改、移动、隐藏与恢复、撤销重做、应用与改写、词库操作、翻译逐条结果、重复开关都走它;设置里可单独开关,关掉后退回右上角弹窗或状态栏
- 右上角弹窗改用插件主题配色,入场与退场整体提速
- 弹窗不再一条一冒:连点重复胶囊时右上角提示原地刷新内容、从最后一次点击重新计时;「翻译全部未知」期间只保留一张总进度卡,结束后弹一张新卡显示翻译与拒绝的条数
- 撤销快捷键改为 Shift+Alt+Z、重做 Shift+Alt+Y(Ctrl+Z 留给画布),界面不再提示 Ctrl+Z,侧边栏标签管理上方增加快捷键说明
- 撤销与编辑类提示改为中文,去掉「点眼睛斜线图标取消隐藏」这类冗长解释
2026-10-30 00:08:24 +08:00
梦圣智杰 575ab1814f chore: 发布 v2.1.9 / Release v2.1.9 2026-10-29 00:54:45 +08:00
梦圣智杰 7759128dac fix: 设置面板两项统一靠左对齐 / Align the two settings entries to the left edge
- 「语言与外观」与「助手设置」两块的内容改为顶到最左边,左边缘齐平,看起来是一整块
- 标题仍在:由各自的 h3 显示,收起的只是 ComfyUI 重复渲染出来的那个名称列
2026-10-29 00:51:33 +08:00
梦圣智杰 2cf72b1a10 feat: 助手设置可自动获取模型列表 / Fetch model list automatically in assistant settings
- OpenAI 兼容与 Ollama 两段的「模型名称」旁新增「获取模型」按钮,拉到的名字填进输入框自带的下拉,点箭头即可选择,名称也照旧可以手写
- 下拉挂在输入框上、不弹窗,ComfyUI 设置面板不用关也能用;按键即重新拉取,按钮显示拿到了几个
- 密钥以输入框里填的为准,留空就用已保存的那一份,只随这一次请求发出
- 列表只在本次会话内有效,地址一改自动清空,不写进配置文件
- 服务端返回非 JSON 的内容(纯文本报错、登录页之类)时,界面直接显示原文与状态码
2026-10-29 00:02:32 +08:00
21 changed files with 2213 additions and 197 deletions
+98
View File
@@ -1,5 +1,103 @@
# 更新记录
## v2.2.1(2026-11-06)
### 修复:双击标签打不开编辑弹窗
- 2.2.0 里在节点英文标签区双击一张标签打不开编辑弹窗了,第二下只会被当成又一次单击,弹不出权重 / 颜色 / 编辑 / 词条信息那个窗口。
- 原因:单击会立刻重渲染整个标签区,原来的卡片元素被换成新的,浏览器就不再把第二下算成「同一个东西被点两次」,双击事件根本不会触发。现在改由插件自己按「两次点击同一张卡、间隔够短」来判断双击,不再依赖元素身份。
- 多选不受影响:已经在一组多选里的标签,双击仍保持整组选中,不会被打回单选。
- 顺手修了 README 几处排版:demo 图前面误入的零宽空格和制表符(会让那行变成代码块、图片显示不出来)、一处粗体末尾多出的空格,以及「git安转」错字。
## v2.2.0(2026-11-05)
### 新增右下角提示条
- 节点的添加、删除、移动、隐藏与取消隐藏,撤销与重做,应用与改写,词库相关操作,「唯一」开关,以及翻译的逐条结果,现在都在屏幕右下角弹出一条提示条:新的出现在最下面,旧的往上顶,最多同时显示 5 条,过一会儿自己收走,也可以点右上角的 ✕ 立刻关掉。
- 按操作类型分色,一眼能看出刚发生了什么:改内容(应用改写、权重、词条保存等)蓝色,添加标签紫色,删除标签红色,移动标签青色,撤销重做灰色,翻译成功绿色,「唯一」开关橙色。翻译被拒绝的不走这里,仍用右上角的红色弹窗报;每条提示左侧的竖线、图标、出场时抹开的那层颜色都跟着变。
- 底部快捷输入加标签现在也弹提示条了(以前只写节点状态栏),和搜词库加标签走同一种紫色。
- 「设置 → 双语提示词检查器 → 通用」里多了一个「右下角提示条」开关,和原来的「右上角通知弹窗」并排;默认开启。关掉后这些提示退回原来的位置——右上角弹窗开着就走弹窗,都关了就走节点状态栏。
- 担心这点性能开销的可以直接关掉,关掉后行为和你没升级前一样。
### 删标签时的消失动画
- 节点里删标签多了一段过渡:那张卡先被一个大 X 从四个角向中心划掉,接着整块颜色铺满,上下各压出一条灰边,最后从左往右擦掉才真正消失。以前是点一下直接没了。
- 颜色用的是紫色,卡片多长都按实际宽高算,长短标签的动画都贴合卡片自己的边。
- 卡片擦掉之后,剩下的标签会平滑地滑过来补上空位,不再是一下子跳过去。
- 动画大约 0.9 秒,这期间那张卡点不动;真正删除在动画结束时才发生,撤销仍然只有一步。
- 「通用」里那个「通知弹窗及实时动画预览」折叠(以前叫 bulingbuling)多了一个「标签增删动画(节点标签区)」开关,和拖动预览那两个开关并排,默认关。
- 目前只做节点标签区(卡片右上角的 ×、选中后按 Delete、重复栏双击删除都算)
### 添加标签时的出现动画
- 添加标签也有过渡了:新标签从左往右展开出来,旁边的标签平滑滑开让位,不再是一下子出现在那里。底部快捷输入(中文会先翻译再加)和搜词库点结果这两条添加路都算。
- 加和删共用一个开关,就是上面那个「标签增删动画(节点标签区)」:打开两个动画都播,关掉两个都回到原来的样子。
- 加到中间时后面的标签也会平滑让位(之前只有加到末尾才正常,插在前面会跳一下);动画时长 0.42 秒,带一点淡入,看着更连贯。
### 右上角弹窗不再一条接一条地冒
- 连点重复栏里的胶囊时,弹窗不再每次新开一张,而是就地把「第 1 / 3 处」换成「第 2 / 3 处」,并从最后一次点击重新计时 5 秒,方便看清楚;只有手点 ✕ 才会立刻收起。
- 「翻译全部未知」期间右上角只保留一张总进度卡,显示「正在翻译未知标签 3 / 12」;全部译完后进度卡退场,弹出一张新卡显示翻译了多少条、被拒绝了多少条。以前是每译完一条就新冒一张。
- 弹窗整体换成插件的主题配色,入场和退场都比以前快一点;退场时卡片后面还垫着两层纸,卡片先滑走、接着中间那层、最后才是底纸,三层依次向右离场。
- 出错的提示停留时间从 3 秒延长到 8 秒——带原因的长句得读两遍才看清,3 秒一闪就过去了。出错时的配色也整体对调:平时离场那层和底边亮线是蓝色,出错时转成紫红,垫在后面的纸转成蓝。
### 撤销快捷键改为 Shift+Alt+Z / Shift+Alt+Y
- ComfyUI 里 `Ctrl+Z` 会触发画布自己的撤销,插件不再占用它:撤销改成 `Shift+Alt+Z`,重做改成 `Shift+Alt+Y`,只在节点文本框或英文标签区有焦点时生效。
- 界面上所有「按 Ctrl+Z 可撤销」的提示都删掉了,侧边栏「标签管理」上方加了一行小字说明插件自己的快捷键。
- 撤销、重做、删除、移动、隐藏、恢复这类提示全部改成中文,并去掉了「点眼睛斜线图标取消隐藏」这种冗长的解释,弹窗不再被撑得很大。
### 拖动时可以实时预览顺序
- 「设置 → 双语提示词检查器 → 通用」里那个「通知弹窗及实时动画预览」折叠里多了两个开关:「拖动实时预览(节点标签区)」和「拖动实时预览(明细表)」,各管一处、互不影响,默认都关着。关掉时和升级前一模一样:只有落点提示,松手才真正生效。
- 打开后,拖动途中其余标签会实时让位,顺序跟着你走,松手前就能看到最终排布,不用靠猜。
- 预览期间只挪动界面上的顺序,提示词文本一律不动;松手那一刻才统一写入,所以撤销仍然是一步就能回到拖动前。
### 拖动时的外观调整
- 节点标签区:被拖的标签抬起跟随光标,不再放大(原来的放大看着发虚),原位留一个空位,其余标签平滑滑开。
- 明细表:不做抬起、放大和半透明淡化——淡化会把字看糊。改成给正在拖的那一行加左侧实心色条 + 高亮底色 + 亮色文字,一眼看得出是哪一行在被拖;行自己留在原位,只跟着大家一起滑过去。
- 落点提示画在整张卡片上(英文行和下面的中文小块一起亮),拖到中文小块上也认。以前只认卡片上半的英文行,指针压在中文上就判定不到目标,插入提示不出现、落点还会被算到列表末尾去。
### 拖动更稳:修好不让位与疯狂闪烁
- 拖回原位时其余标签不让位:之前误加了「落点等于原位就直接返回」的判断,导致只有拖到相邻两个提示词中间才回得去。现在拖回哪儿都能正常让位。
- 拖动途中其余标签疯狂左右闪:把最后一个拖到最前面、或把长提示词往右拖时最明显。根因是让位动画播到一半就被下一次落点判定打断重来(原来的节流只挡一帧,动画却要跑 220ms),来回振荡。改成等动画播完才解锁下一次判定,另加 10px 滞回带——指针停在两个槽位分界线上抖一两像素不会再触发;动画缩短到 160ms 更跟手。
- 拖动激活阈值调高:节点 4px → 7px、明细表 3px → 6px,轻点着手柄不会误进入拖动。
### 点哪个节点,侧边栏就切到哪个节点
- 以前要改哪个节点的提示词,只能在侧边栏「标签管理」顶部的节点下拉里手动挑。现在多了个「点击节点时跟随切换」开关(默认关闭):设置 → 双语提示词检查器 → 通用 → 点击节点时跟随切换。
- 打开后:在画布上点一个「双语提示词检查器」节点,侧边栏「标签管理」就切到那个节点,下拉和下面的明细表一起换过去;点编码器、采样器这类别的节点不受影响,仍然停在原来那个检查器节点上。
- 侧边栏没打开、或者正停在别的分页时也记着:切回「标签管理」直接就是刚才点的那个节点。
- 关掉和以前一模一样,没有任何变化。开关长在「通用」这一项里、语言设置下面,外观和同处的那几个开关一致;状态存在本机浏览器里,跟着这台机器走,不进工作流。
### 隐藏的眼睛、删除的 × 各占一个角
- 英文标签区的每张小卡,鼠标移上去时右上角会同时出现「眼睛(隐藏)」和「×(删除)」,两个按钮叠在一起容易点错。现在「×」是卡片右上角的角标,不再跟英文标签挤在同一行;「眼睛」挪到卡片右下角,两个按钮不再抢同一个位置。
- 两个角标都浮在卡片上、不占位置:卡片大小和以前完全一样,不会因为多了个按钮把标签撑大、把刚好放得下一整行的标签挤到下一行去;角标压到文字时就是盖在文字上面。
### 设置面板重新归置
- 「语言与外观」改名叫「通用」:外观、语言、点击节点时跟随切换三项都收在这一项里。其中跟随节点原来是单独一项设置,单独放的话 ComfyUI 会按分类名排序、怎么调都排不到想要的位置,所以并进「通用」、排在语言下面。
- 那个叫「bulingbuling」的折叠改名「通知弹窗及实时动画预览」,名字写明白里面到底是什么。
- 折叠最上面多了一个「全部开启」总开关:一次控制右上角弹窗、右下角提示条、两个拖动预览和标签增删动画这五项;单独关掉其中任何一个,总开关会跟着变成未勾选。显存或电脑资源紧张时可以整组关掉,动画会吃一小部分性能。
## v2.1.9(2026-10-29)
### 助手设置里可以自动获取模型列表
- OpenAI 兼容和 Ollama 两段的「模型名称」旁边多了一个「获取模型」按钮:拿输入框里当前填的地址问一次服务端有哪些模型(OpenAI 兼容问 `/models`,Ollama 问 `/api/tags`),拉到的名字填进输入框自带的下拉——点输入框里的箭头就能选,名称也照旧可以手写。
- 下拉用浏览器原生的方式挂在输入框上,不弹任何窗口:助手设置长在 ComfyUI 的「设置」面板里,浮层会被它挡住点不动。
- 再点一次按钮就是重新拉取,按钮上显示拿到了几个;地址改了会自动清空,列表只在本次会话内有效、不写进配置文件。
- 这次请求用你在 API Key 输入框里填的密钥;输入框留空就用已经保存的那一份(密钥仍不会回传给浏览器),只会随这一次请求发出。
- 服务端返回看不懂的内容时(比如缺密钥时 DeepSeek 只回一行纯文本 `Authentication Fails`、或网关甩回来一整页登录页),界面直接显示那句原话和状态码,不再崩一段 `Expecting value: line 1 column 1 (char 0)`。「保存并测试连接」和翻译 / 优化走的是同一套解析,一起修好了。
- 地址照旧走既有的白名单:远端必须 https、内网与链路本地地址驳回、Ollama 只认本机。
### 设置面板两项统一靠左对齐
- 「语言与外观」与「助手设置」两块的内容顶到最左边,左边缘齐平,看起来是一整块。标题仍在,由各自的标题行显示,收起的只是 ComfyUI 重复渲染出来的那个名称列。
## v2.1.8(2026-10-26)
### 新增「适应高度」开关
+69 -16
View File
@@ -1,10 +1,11 @@
# ComfyUI 双语提示词管理器 v2.1.8
# ComfyUI 双语提示词管理器 v2.2.1
> ComfyUI 双语提示词节点:把英文提示词拆成可点击的标签,边写边看中文解释、调顺序、试效果。
<p align="center">
<img src="assets/screenshot-main.png" alt="主界面" width="880">
<img src="https://raw.githubusercontent.com/mengshengzhijie/tuchuan/master/assets/ComfyUI-Bilingual-Prompt-Inspector/screenshot-main.png" alt="主界面" width="880">
</p>
**它解决什么问题**:Anima / Danbooru 风格的提示词是一长串英文标签,写完很难确认模型到底读到了什么。这个节点把提示词变成可选中、可删除、可排序的芯片,每个芯片旁边就是它的中文解释;输出的永远只有英文提示词本身,中文只用于阅读。
---
@@ -18,6 +19,7 @@
- [上游提示词接管](#上游提示词接管)
- [收藏](#收藏)
- [侧边栏管理面板](#侧边栏管理面板)
- [操作反馈](#操作反馈)
- [界面导览](#界面导览)
- [安装](#安装)
- [快速上手](#快速上手)
@@ -36,7 +38,7 @@
<table>
<tr>
<td width="26%"><b>标签化视图</b></td>
<td>英文提示词按标签切成芯片,点一下就和下方的中文解释、明细行联动高亮。看不清楚的标签不用再猜。</td>
<td>英文提示词按标签切成芯片,每张卡片上半是英文、下半就是它的中文解释,点一下还会和侧边栏的明细行联动高亮。看不清楚的标签不用再猜。</td>
</tr>
<tr>
<td><b>编辑 / 标签两种形态</b></td>
@@ -44,11 +46,15 @@
</tr>
<tr>
<td><b>拖拽排序</b></td>
<td>按住标签直接拖,或在明细表里拖 <code>⠿</code> 手柄;也可以选中后用 <code>Alt+↑</code> / <code>Alt+↓</code> 微调。排版不会乱——逗号空格样式保留,换行分段不被合并。</td>
<td>按住标签直接拖,或在明细表里拖 <code>⠿</code> 手柄;也可以选中后用 <code>Alt+↑</code> / <code>Alt+↓</code> 微调。排版不会乱——逗号空格样式保留,换行分段不被合并。开启「拖动实时预览」后,被拖的标签会浮起来跟着光标走,其余标签像手机桌面挪图标那样平滑让开。</td>
</tr>
<tr>
<td><b>临时隐藏</b></td>
<td>点标签上的眼睛图标把它移出实际输出。标签不会从节点里消失,只是加删除线并灰化,照常可以拖动、改色、改权重,但模型完全看不到它。适合做「有 / 没有这个标签」的对比出图,之后逐个或一次性全部恢复。</td>
<td>鼠标移到标签卡片上,右下角会出现眼睛图标,点它把标签移出实际输出。标签不会从节点里消失,只是加删除线并灰化,照常可以拖动、改色、改权重,但模型完全看不到它。适合做「有 / 没有这个标签」的对比出图,之后逐个或一次性全部恢复。</td>
</tr>
<tr>
<td><b>删除标签</b></td>
<td>选中标签后卡片右上角出现 <code>×</code>,点它删除;也可以选中后直接按 <code>Delete</code>。删掉的标签会先被划掉、擦走,再从列表里消失;添加标签时新标签则展开出现——两个过渡共用一个开关,可以关掉。</td>
</tr>
<tr>
<td><b>权重编辑</b></td>
@@ -60,7 +66,7 @@
</tr>
<tr>
<td><b>撤销重做</b></td>
<td>删除、排序、隐藏、权重、清空全部支持 <code>Ctrl+Z</code> / <code>Ctrl+Y</code>。</td>
<td>删除、排序、隐藏、权重、清空全部支持撤销重做,快捷键 <code>Shift+Alt+Z</code> / <code>Shift+Alt+Y</code>(<code>Ctrl+Z</code> 留给 ComfyUI 画布自己的撤销,插件不抢)。快捷键只在节点文本框 / 英文标签区有焦点时生效。</td>
</tr>
<tr>
<td><b>换行分段</b></td>
@@ -120,13 +126,33 @@
- **使用**:侧边栏「收藏」分页按卡片浏览,卡片直接显示适合模型和备注;支持搜索(模型名也算)、编辑、复制、载入节点、删除,也可以整包导出 JSON 给别的机器导入。
- **存放位置**:`ComfyUI/user/bilingual-prompt-inspector/saved_prompts/`(`index.json` + 按 id 命名的图片文件),跟随 ComfyUI 用户目录,不在插件目录内,重装或更新插件不会丢。单图上限 5 MB,最多 2000 条。
> 「载入节点」会先弹窗确认再覆盖节点文本,这个动作**不支持 `Ctrl+Z` 撤销**。
> 「载入节点」会先弹窗确认再覆盖节点文本,这个动作**无法撤销**。
### 侧边栏管理面板
标签管理、词库维护、词库包、收藏四个分页收在侧边栏的「双语提示词管理」面板里,节点本身保持简洁。面板里的改动会实时同步到页面上所有同类节点,不需要刷新页面。
助手设置不在这个面板里:它在 ComfyUI 的「设置」面板中,「设置 → 双语提示词检查器」下有两项 ——「语言与外观」和「助手设置」,表单都直接铺在设置面板右侧。
「标签管理」默认跟着你点开的节点走:在画布上点一个「双语提示词检查器」节点,侧边栏就切到它。不想要这个行为,关掉「设置 → 通用」里的「点击节点时跟随切换」,之后只能在面板顶部的节点下拉里手动选。
助手设置不在这个面板里:它在 ComfyUI 的「设置」面板中,「设置 → 双语提示词检查器」下有两项 ——「通用」和「助手设置」,表单都直接铺在设置面板右侧。
### 操作反馈
每次操作都会给一条回执,按操作类型分色,不用再去状态栏找那一行字:
| 颜色 | 什么时候出现 |
|---|---|
| 蓝色 | 改内容:应用改写、改权重、隐藏 / 取消隐藏、保存词条、导入词库 |
| 紫色 | 添加标签(底部快捷输入、搜词库点结果) |
| 红色 | 删除标签 |
| 青色 | 移动标签 |
| 灰色 | 撤销 / 重做 |
| 绿色 | 翻译成功 |
| 橙色 | 「唯一」开关 |
- **右下角提示条**:新的出现在最下面,旧的往上顶,最多同时显示 5 条,过一会儿自己收走,也可以点 ✕ 立刻关掉。
- **右上角弹窗**:错误、翻译被拒、批量翻译的进度与汇总、重复标签的定位走这里,红色系、停留更久。同类操作会就地更新同一张卡(比如连点重复胶囊是在同一张卡里翻「第 2 / 3 处」),不会一条接一条地冒;批量翻译期间只留一张总进度卡。
- 两个都嫌打扰,可以在「设置 → 通用」里分别关掉「右上角通知弹窗」和「右下角提示条」,关掉后提示退回节点状态栏。
---
@@ -134,12 +160,13 @@
![ComfyUI 双语提示检查器截图](https://raw.githubusercontent.com/mengshengzhijie/tuchuan/master/assets/ComfyUI-Bilingual-Prompt-Inspector/screenshot-main.png)
节点上可以大致分成四块:
节点上可以大致分成三块:
1. **英文原文(实际输出)**——节点真正输出给下游的文本。上面有「编辑文本 / 完成」「清空」「插入换行」「收藏」「优化」「按 Anima 顺序排序」几个按钮。
2. **中文对照区**——英文标签逐条对应的中文,只用于阅读,不进入输出,也不会传给下游。
3. **明细表**——每行是一个标签:来源、翻译、权重、分类,右侧按行状态给出操作(翻译 / 确认并存 / 重新翻译 / 编辑中文 / 收藏 / 复制 / 删除个人词条)。上方有搜索框、模式选择、颜色模式、筛选(全部 / 未知 / 机器翻译 / 个人词库 / 收藏)和问题提示。
4. **快捷添加**——底部输入框,中文进英文出(自动翻译后追加),英文则直接追加。
2. **标签区**——每张卡片上半是英文标签、下半是它的中文解释,只用于阅读,不进入输出,也不会传给下游。标签多了这里会自己滚动,也可以在明细表上方的筛选栏打开「适应高度」,让它跟着节点一起变高。
3. **快捷添加**——底部输入框,中文进英文出(自动翻译后追加),英文则直接追加。
**明细表不在节点上**:它被侧边栏的「标签管理」借走了(节点旁边的画布空间要留给画面)。那里每行一个标签,列出每行的来源、翻译、权重、分类,右侧按行状态给出操作(翻译 / 确认并存 / 重新翻译 / 编辑中文 / 收藏 / 复制 / 删除个人词条);上方有搜索框、模式选择、颜色模式、筛选(全部 / 未知 / 机器翻译 / 个人词库 / 收藏)和问题提示。
---
@@ -161,7 +188,13 @@ cd ComfyUI/custom_nodes/
git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-Inspector.git
```
不过这里如果有动手能力的话推荐使用git安转,因为现在就我和我的朋友在使用,有时候修复bug和制作新功能我是总结下来然后一步一步的修复。直到把这次收录的bug和建议给完成之后才bump版本。
**如果网络受限也可以使用 gitee,或者用上神奇的 `-c`**:
```bash
git clone https://gitee.com/MengShengZhiJie/ComfyUI-Bilingual-Prompt-Inspector.git
```
不过这里如果有动手能力的话推荐使用 git 安装,因为现在就我和我的朋友在使用,有时候修复bug和制作新功能我是总结下来然后一步一步的修复。直到把这次收录的bug和建议给完成之后才bump版本。
重启 ComfyUI,在节点菜单的 **text/prompt** 分类里找到 **提示词翻译与管理(英文输出)**(英文界面下显示为 Prompt Translator & Manager),也可以直接搜索「提示词」。
@@ -179,7 +212,7 @@ git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-
1. 把节点接到 CLIP 文本编码器上,和普通提示词节点一样。
2. 在「英文原文」里写提示词,或点「编辑文本」写完后点「完成」。
3. 在标签视图里逐个检查:点标签看中文解释,双击调权重,拖动手柄排顺序。
4. 想确认某个标签到底有没有用?点眼睛图标隐藏它,重新出图对比,再一键恢复。
4. 想确认某个标签到底有没有用?鼠标移到标签卡片上,点右下角那颗眼睛隐藏它,重新出图对比,再一键恢复。
![Demo — run](https://raw.githubusercontent.com/mengshengzhijie/tuchuan/master/assets/ComfyUI-Bilingual-Prompt-Inspector/demo-run.gif)
@@ -199,6 +232,8 @@ git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-
| ↳ OpenAI 兼容 | API 地址、模型、可选 API Key、温度、超时,另有「使用 LM Studio 本地预设」一键填入 `1234/v1`。远端地址必须 https,本机回环(127.0.0.1 / localhost)才允许 http;内网、保留、链路本地地址一律拒绝 |
| ↳ Ollama | API 地址、模型、温度、超时,没有密钥,另有「使用 Ollama 本地预设」一键填入 `11434`。地址只能是本机回环地址,其它一律拒绝 |
模型名称旁边的「获取模型」按钮会拿输入框里当前填的地址问一次服务端有哪些模型(OpenAI 兼容问 `/models`,Ollama 问 `/api/tags`),拉到的名字直接填进输入框自带的下拉里——点输入框里的箭头就能选,也可以完全不管它自己手写。再点一次按钮就是重新拉取。列表只在本次会话内有效、地址一改就作废,不写进配置文件。密钥以输入框里填的为准,输入框留空就用你已经保存的那一份;无论哪种都只随这一次请求发出,不会随着设置一起回传给浏览器。服务端返回看不懂的内容(纯文本报错、登录页之类)时会原话告诉你,不会甩一段 JSON 报错。
两个后端还各有一套规则(翻译 / 翻译并优化 / 优化 / 自然语言):本地小模型与云端大模型要写的提示词往往不一样,分开存可以随时切换后端而不用重改规则。其中「自然语言」那套只在自然语言模式下被「优化」使用,结果按完整英文句子保留标点,不套 Anima 的标点限制。地址不合规时会在发出请求前直接报错。
### 大型词库(可选)
@@ -207,7 +242,18 @@ git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-
### 界面语言与外观
界面文案跟随 ComfyUI 的语言设置,也可以在「设置 → 双语提示词检查器 → 语言与外观」里固定为中文或英文。外观同样可在「跟随 ComfyUI / 暗色 / 亮色」之间切换,两项改完立即生效并单独保存。
界面文案跟随 ComfyUI 的语言设置,也可以在「设置 → 双语提示词检查器 → 通用」里固定为中文或英文。外观同样可在「跟随 ComfyUI / 暗色 / 亮色」之间切换,两项改完立即生效并单独保存。
这个折叠(「通知弹窗及实时动画预览」)里还收着几个手感和提示相关的开关,最上面另有一个「全部开启」总开关,一次控制下面这几项;各项都默认关闭,关掉就是原来那样:
| 开关 | 管什么 |
|---|---|
| 右上角通知弹窗 | 错误、被拒、批量翻译进度是否用右上角弹窗报 |
| 右下角提示条 | 操作回执是否用右下角提示条显示 |
| 拖动实时预览(节点标签区 / 明细表) | 拖动时其余标签是否实时让位,两个区域各管各的 |
| 标签增删动画(节点标签区) | 删除标签是否划掉擦走、添加标签是否展开出现 |
折叠上方还有一项「点击节点时跟随切换」:点画布上的节点时,侧边栏「标签管理」是否跟着切过去。
---
@@ -235,6 +281,12 @@ git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-
这两种操作只在标签模式与混合模式下可用,纯自然语言模式下没有意义。另外如果开了 ComfyUI 的「现代节点设计(Nodes 2.0)」,请关掉再试,原因见上文安装一节。
</details>
<details>
<summary><b>拖标签时整片标签在动,看不清落点</b></summary>
那是「拖动实时预览」在起作用(默认关闭)。它会让其余标签实时让开,长提示词下偶尔显得晃;到「设置 → 通用」把它关掉,就退回只有落点提示线的老样子,松手才真正挪动。
</details>
<details>
<summary><b>运行到一半卡住了,好像在等什么</b></summary>
这是上游接管的暂停确认。节点在等你整理导入的上游文本,点「继续」放行,或点「丢弃」终止本次等待;也可以直接点 ComfyUI 的取消中断。无人确认时约 20 秒会自动透传。
@@ -248,6 +300,7 @@ git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-
- 自动翻译与优化结果都需要人工复查。
- 自然语言块不支持按内部单词逐项删除,要回文本模式改。
- 拖拽排序与隐藏只在标签模式和混合模式下可用。
- 提示条、拖动实时预览、增删动画这几个都属于观感加成,默认关闭;关掉后行为和旧版本完全一致,不影响任何数据。
- 隐藏清单、接管开关与导入策略都保存在节点属性里,导出「API 格式」JSON 时不会带出——届时隐藏标记会丢失,被隐藏的标签会直接出现在输出里。
- 接管上游提示词需要浏览器界面来确认;用 API 提交工作流时节点自动透传,不会等待。
- 收藏不记录工作流名称与节点编号;载入节点会覆盖节点当前文本,只弹窗确认,不支持撤销。
@@ -279,6 +332,6 @@ git clone --depth 1 https://github.com/mengshengzhijie/ComfyUI-Bilingual-Prompt-
## 致谢与许可
基于 [Qiongyi44/ComfyUI-Bilingual-Prompt-Inspector](https://github.com/Qiongyi44/ComfyUI-Bilingual-Prompt-Inspector) 二次开发,现已独立维护。在原版基础上新增了百度翻译、侧边栏管理面板、标签拖拽排序、临时隐藏、上游接管与收藏。
基于 [Qiongyi44/ComfyUI-Bilingual-Prompt-Inspector](https://github.com/Qiongyi44/ComfyUI-Bilingual-Prompt-Inspector) 二次开发,现已独立维护。在原版基础上新增了百度翻译、侧边栏管理面板、标签拖拽排序、临时隐藏、上游接管与收藏,以及右下角提示条、拖动实时预览、标签增删动画这些交互细节。
词库数据来源与授权说明见 `THIRD_PARTY_NOTICE.md`,许可条款见 `LICENSE`,完整使用手册见 `release_docs/使用手册(原README).md`。
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 8L10 13M4 14L10 8L12 5M2 5H14M7 2H8M12.913 17H20.087M12.913 17L11 21M12.913 17L15.7783 11.009C16.0092 10.5263 16.1246 10.2849 16.2826 10.2086C16.4199 10.1423 16.5801 10.1423 16.7174 10.2086C16.8754 10.2849 16.9908 10.5263 17.2217 11.009L20.087 17M20.087 17L22 21" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 586 B

+62
View File
@@ -205,6 +205,68 @@ def openai_chat_endpoint(base_url):
return f"{base}/chat/completions"
def openai_models_endpoint(base_url):
"""Return a model-list endpoint for an OpenAI-compatible base URL."""
base = str(base_url or "").strip().rstrip("/")
if not base:
return ""
if base.endswith("/models"):
return base
if base.endswith("/chat/completions"):
base = base[: -len("/chat/completions")].rstrip("/")
return f"{base}/models"
def response_snippet(body):
"""错误应答常常是一整页 HTML 或带换行的纯文本;压成一行并截断,免得提示框被撑爆。"""
return re.sub(r"\s+", " ", str(body or "")).strip()[:160]
def upstream_error_message(body, status, who):
"""把上游错误应答压成一句能看懂的中文。
各家返回的不是齐步走的:OpenAI 系给 JSON,DeepSeek 缺密钥时回的是纯文本一行
“Authentication Fails”,还有网关直接甩一页 HTML。所以先看原文能不能解析成 JSON,
解析不了就退化成原文片段,绝不在取错误信息的路上把请求整条打崩。
`who` 是“Ollama” / “API” 这一类的来源名,只在连原文都没有时用来兜底。
"""
message = None
try:
data = json.loads(body)
except (TypeError, UnicodeDecodeError, json.JSONDecodeError):
data = None
if isinstance(data, dict):
detail = data.get("error")
if isinstance(detail, dict):
detail = detail.get("message")
message = str(detail).strip() if detail else None
hint = ";请检查 API 密钥是否已填写、是否有效" if status in {401, 403} else ""
return f"{message or response_snippet(body) or f'{who} 请求失败'}(HTTP {status}{hint})"
def parse_json_body(body, who):
"""解析成功应答;不是 JSON 或不是字典时给一句能看懂的提示,而不是抛堆栈。"""
try:
data = json.loads(body)
except (TypeError, UnicodeDecodeError, json.JSONDecodeError) as error:
raise ValueError(f"{who} 返回的不是 JSON(可能是登录页或错误页):{response_snippet(body)}") from error
if not isinstance(data, dict):
raise ValueError(f"{who} 返回的内容无法识别:{response_snippet(body)}")
return data
def ollama_tags_endpoint(base_url):
"""Return the local-model list endpoint for an Ollama base URL."""
base = str(base_url or "").strip().rstrip("/")
if not base:
return ""
if base.endswith("/v1"):
base = base[:-3].rstrip("/")
if base.endswith("/api/chat"):
base = base[: -len("/api/chat")].rstrip("/")
return f"{base}/api/tags"
def baidu_translate_params(appid, secret_key, query, to_lang, from_lang="auto", salt=None):
"""组装百度通用文本翻译接口参数;sign = MD5(appid + q + salt + 密钥)。"""
appid = str(appid or "")
+2 -2
View File
@@ -62,8 +62,8 @@
- `js/manager_panel.js`
- 在 ComfyUI 侧边栏注册「双语提示词管理」面板,包含标签管理、词库、词库包、收藏四个分页。
- 承担原节点内管理弹窗的全部职责:词条增删改、批量操作、个人词库导入导出、社区包与大型词库管理。
- 助手设置不在侧边栏:同一文件的 `registerExtension` 用 `settings` 在 ComfyUI「设置」面板的「双语提示词检查器」分类下注册两项 ——「语言与外观」(`appearanceControl()`)与「助手设置」(`assistantSettingsControl()`),表单都直接内嵌在设置面板右侧,配置仍写入 `assistant_store.py`。面板反复渲染会重建控件容器,所以每项的整块 DOM 只建一次后复用,避免输入到一半被清空。
- 语言与外观只提交 `appearance` / `language` 两个字段:`assistant_store.update()` 对 payload 里没给的字段一律取当前值,所以不会动翻译服务与密钥;助手设置的 payload 反过来已经不含这两项。
- 助手设置不在侧边栏:同一文件的 `registerExtension` 用 `settings` 在 ComfyUI「设置」面板的「双语提示词检查器」分类下注册两项 ——「通用」(`appearanceControl()`)与「助手设置」(`assistantSettingsControl()`),表单都直接内嵌在设置面板右侧,配置仍写入 `assistant_store.py`。面板反复渲染会重建控件容器,所以每项的整块 DOM 只建一次后复用,避免输入到一半被清空。
- 通用只提交 `appearance` / `language` 两个字段:`assistant_store.update()` 对 payload 里没给的字段一律取当前值,所以不会动翻译服务与密钥;助手设置的 payload 反过来已经不含这两项。
- AI 两个后端各一整套配置(地址 / 模型 / 温度 / 超时 / 三条规则),键名前缀 `openai_` 与 `ollama_`,`ai_provider` 只决定当前读哪一套;切换后端不清空任何一套。地址白名单在 `assistant_store.normalize_ai_base_url()`:OpenAI 远端必须 https、http 仅限本机回环,Ollama 只认本机回环,且 `server.py` 发请求前会再校验一次(防手改配置文件)。
- “标签管理”分页通过节点下拉列表挂载指定节点的标签翻译与词库搜索界面(DOM 直接移植,逻辑仍归属各节点闭包),节点删除时自动摘下。
- 修改后通过 `panelSyncHub` 通知当前页面所有节点刷新。
+12
View File
@@ -126,3 +126,15 @@
两套规则必须分开:`sanitize_anima_prompt` 会把句点收成逗号并只放行 Anima 标点白名单,完整句子喂进去会被判废,所以自然语言结果改走 `sanitize_natural_prompt`。
代价:已经排过序时要保留排序按钮,否则“取消排序”的入口会跟着一起消失。另外 mixed(标签 + 自然语言)不算自然语言模式——里面还有标签流可排。
## 20. 模型列表由服务端代问,且只在本次会话内缓存
决定:助手设置的「模型名称」输入框保持自由输入,旁边另加一个「获取模型」按钮。按钮把输入框里当前填的地址和密钥发给插件自己的 `/bpi/assistant/models`,由服务端去问那个 AI 后端(OpenAI 兼容问 `/models`,Ollama 问 `/api/tags`),把名字填进输入框自带的原生下拉(`<datalist>`);按钮显示「获取模型(N)」,再点一次就是重新拉取。
不弹窗是有原因的:助手设置长在 ComfyUI 的「设置」面板里,任何浮层都会被这块面板压住、点不动,逼着用户先关掉设置面板。下拉是浏览器原生的输入框附件,既没有层级问题,也不用自己处理定位与溢出。
原因:地址白名单(远端必须 https、内网与链路本地地址驳回、Ollama 只认本机回环)是整个插件的安全边界。让浏览器直接去拉,这份校验就得在前端重写一遍,而且可以绕过;交给服务端代发,还能顺带解决输入框里那份还没保存的密钥往哪发:填了就用填的,留空就用已存的那份,都只用于这一次请求,返回给浏览器的始终只有模型名字。
列表不持久化有两点考虑:各家网关的模型随时增减,写进配置文件第二天就是过期数据;地址一改缓存必须作废,把「这次问的地址」和列表绑在同一个闭包里最省事,也不用为它设计一份需要清理的存储格式。
代价:第一次点按钮要多等一次 `/models` 往返;各家返回结构不一样(`data[].id` 与 `models[].name`),得分别解析。面板一律不去猜哪个模型能聊天——embedding、rerank 之类照常列出,免得误伤名字奇怪但确实可用的模型。
+607 -109
View File
File diff suppressed because it is too large Load Diff
+68
View File
@@ -0,0 +1,68 @@
// 删除标签时的消失动画:X 从四角向心长出 → 颜色从中心铺满整块 → 上下压两条灰边 → 整块从左往右擦掉。
// 关掉就是原来的样子:卡片直接消失。这个开关同时管添加动画(见 bpi_insert_anim.js),
// 设置里显示为「标签增删动画(节点标签区)」,默认关。
const KEY = "bpi.deleteAnim.node.v1";
// 四拍各自的时长,加起来就是删掉一张卡要等的时间(≈0.9 秒)
const TIMING = { grow: 160, spread: 400, wipe: 350 };
export function deleteAnimNodeEnabled() {
try {
return window.localStorage.getItem(KEY) === "1";
} catch (error) {
return false;
}
}
export function setDeleteAnimNodeEnabled(next) {
try {
window.localStorage.setItem(KEY, next ? "1" : "0");
} catch (error) {
/* 隐私模式下写不进去,本次会话内仍按传入值生效 */
}
}
// 卡片尺寸跟着中英文长度变,所以每次删之前都量一遍:对角线角度、半对角线长度、
// 铺满整块需要的宽度、上下灰边的高度,全按当前宽高算(和 demo 里 measure() 一个算法)。
// onDone 在擦除结束时调用,真正的删除动作在那时才执行。
export function playDeleteAnim(card, onDone) {
if (!card || card.classList.contains("bpi-deleting")) {
onDone?.();
return;
}
const width = card.clientWidth;
const height = card.clientHeight;
const diagonal = Math.hypot(width, height);
card.style.setProperty("--bpi-del-angle", `${(Math.atan2(height, width) * 180) / Math.PI}deg`);
card.style.setProperty("--bpi-del-len", `${diagonal / 2}px`);
card.style.setProperty("--bpi-del-fill", `${((width * height) / diagonal) * 1.35}px`);
card.style.setProperty("--bpi-del-bar-h", `${Math.max(6, Math.min(14, Math.round(height * 0.16)))}px`);
const stage = document.createElement("div");
stage.className = "bpi-del-stage";
for (const corner of ["a1", "a2", "b1", "b2"]) {
const half = document.createElement("i");
half.className = `bpi-del-half bpi-del-half-${corner}`;
stage.appendChild(half);
}
const cover = document.createElement("i");
cover.className = "bpi-del-cover";
const topBar = document.createElement("i");
topBar.className = "bpi-del-bar bpi-del-bar-top";
const bottomBar = document.createElement("i");
bottomBar.className = "bpi-del-bar bpi-del-bar-bottom";
stage.append(cover, topBar, bottomBar);
card.appendChild(stage);
card.classList.add("bpi-deleting");
// 先让初始状态落一帧,否则浏览器会把 transition 一起跳过(X 会直接是满的)
requestAnimationFrame(() => card.classList.add("bpi-del-grow"));
window.setTimeout(() => card.classList.add("bpi-del-spread"), TIMING.grow);
window.setTimeout(() => card.classList.add("bpi-del-wipe"), TIMING.grow + TIMING.spread);
window.setTimeout(() => {
// 删除失败时卡片要能回到原样,所以先把动画痕迹全撤掉再交回去
card.classList.remove("bpi-deleting", "bpi-del-grow", "bpi-del-spread", "bpi-del-wipe");
stage.remove();
onDone?.();
}, TIMING.grow + TIMING.spread + TIMING.wipe);
}
+39
View File
@@ -0,0 +1,39 @@
// 拖动实时预览的开关:打开后,拖动标签时被拖的那一项会浮起来跟着光标走,
// 原位留一个等大的空位,其余标签用动画平滑让位;松手才真正改写文本,只留一条撤销记录。
// 关掉就是原来的样子:拖动过程中只有落点提示线,松手才见效。
// 平滑动效每次拖动都要量两遍布局,提示词很长时会多花一点 CPU,所以默认关。
// 节点标签区和明细表各一个开关,分开存,互不影响。
const NODE_KEY = "bpi.dragPreview.node.v1";
const TABLE_KEY = "bpi.dragPreview.table.v1";
const readFlag = (key) => {
try {
return window.localStorage.getItem(key) === "1";
} catch (error) {
return false;
}
};
const writeFlag = (key, next) => {
try {
window.localStorage.setItem(key, next ? "1" : "0");
} catch (error) {
/* 隐私模式下写不进去就算了,本次会话内仍按传入值生效 */
}
};
export function dragPreviewNodeEnabled() {
return readFlag(NODE_KEY);
}
export function setDragPreviewNodeEnabled(next) {
writeFlag(NODE_KEY, next);
}
export function dragPreviewTableEnabled() {
return readFlag(TABLE_KEY);
}
export function setDragPreviewTableEnabled(next) {
writeFlag(TABLE_KEY, next);
}
+12
View File
@@ -0,0 +1,12 @@
// 添加标签时的出现动画:新卡片从左往右展开(删除那套手势反过来用),
// 其余卡片同时滑开让位。开关跟删除共用一个(设置里那个「标签增删动画」),
// 所以这个文件只管播,不管开关。
// 时长比删除短一些,但留足 0.42 秒:太快会看着像「啪」一下跳出来的。
export const INSERT_MS = 420;
export function playInsertAnim(cards) {
for (const card of cards) {
card.classList.add("bpi-inserting");
window.setTimeout(() => card.classList.remove("bpi-inserting"), INSERT_MS + 60);
}
}
+445
View File
@@ -0,0 +1,445 @@
// 右上角通知弹窗:开关打开时,节点面板里的操作提示改成弹窗显示;关掉就还是原来那条状态文字。
// 动画时间线照抄 deepseek_html_20261028_2e0b65.html(副本存在 .workbuddy/refs/notif-template.html),
// 大号标识内联 assets/translate.svg(见下方 LOGO_SVG),尺寸按卡片高度算。
// 多条通知同时存在时从上往下堆叠(新的插在最上面,把旧的往下挤),最多同时 3 条。
import { element, t } from "./bpi_shared.js";
const STORAGE_KEY = "bpi.notify.v1";
const HOLD_MS = 3000;
// 报错停留更久:出错时要读两遍才看清(尤其是带原因的长句),3 秒一闪就过去了
const ERROR_HOLD_MS = 8000;
// 同一 group 的提示(节点里反复点「唯一」开关这类)停留更久,方便看清内容;
// 期间再来一条同组的就原地换字并把这段时间重新计一遍,不另开卡片
const REFRESH_HOLD_MS = 5000;
const STICKY_MAX_MS = 10000; // 「处理中」最多挂这么久,等不到结果也自己收掉
// 「处理中」至少完整露脸这么久(入场动画本身约 1150ms):加载太快时结果会瞬间顶掉它,
// 看着就是闪一下,所以结果先扣着,等这一阶段播够了再换
const MIN_BUSY_MS = 1200;
const PADDING_EXTRA = 38; // 卡片上下 padding 36 + 上下 border 2
// 标识尺寸 = 卡片初始高度 × 这个比例(下限/上限见下方 logoSize,防止太小或撑出卡片)
const LOGO_HEIGHT_RATIO = 0.58;
const MAX_CARDS = 3;
let injected = false;
let stack = null;
// 从上到下排列,cards[0] 是最新的那条
const cards = [];
// 开关状态只存本地:这是实验功能,先不惊动后端那套 assistant_settings
export function notifyEnabled() {
try {
return window.localStorage.getItem(STORAGE_KEY) === "1";
} catch (error) {
return false;
}
}
export function setNotifyEnabled(next) {
try {
window.localStorage.setItem(STORAGE_KEY, next ? "1" : "0");
} catch (error) {
/* 隐私模式下写不进去就算了,本次会话内仍按传入值生效 */
}
}
const STYLE_ID = "bpi-notify-style";
const CSS = `
/* 弹窗自己的主题色:只在这一层覆盖,插件别处的 --bpm-accent(绿)不受影响。
它用在入场最后落下的那层、和垫在最底下的那张纸(左侧竖条);换青色是为了和退场那层紫红搭。
另加两个分组变量,出错时这两个颜色对调(见下面 .bpi-notif-error):
--bpi-notif-front 管「离场上抹层 + 底边亮线」(默认蓝 #0b8ce9),
--bpi-notif-paper 管垫在卡片正后方那张纸(默认紫红 #d946ef)。 */
.bpi-notif-stack{position:fixed;top:30px;right:0;width:min(320px,calc(100vw - 40px));z-index:9999;display:flex;flex-direction:column;gap:10px;--bpm-accent:#14b8a6;--bpi-notif-front:#0b8ce9;--bpi-notif-front-rgb:11,140,233;--bpi-notif-paper:#d946ef}
/* 投影只有暗色下才需要那么重,亮色下换成淡的;其余颜色都跟着插件的 --bpi-* 主题变量走 */
[data-bpi-theme="light"] .bpi-notif-stack{--bpi-notif-shadow:0 14px 34px rgba(0,0,0,.16);--bpi-notif-logo-shadow:0 2px 10px rgba(0,0,0,.22)}
.bpi-notif-slot{position:relative;width:100%;flex:none}
/* 出错时「上抹层的蓝」和「垫纸的紫红」对调:上抹层与底边亮线转成紫红 #d946ef,
垫纸转成蓝 #0b8ce9,撤场那三层从前往后变成「紫红 → 蓝 → 红」。
左侧竖条(--bpm-accent)和入场两层保持红色,不参与这次对调 */
.bpi-notif-slot.bpi-notif-error{--bpm-accent:#e06c75;--bpi-notif-front:#d946ef;--bpi-notif-front-rgb:217,70,239;--bpi-notif-paper:#0b8ce9}
/* 双层纸的下面那张:只在卡片左侧露出 6px,用插件主题色,充当卡片左侧的色条 */
.bpi-notif-under{position:absolute;top:0;right:0;bottom:0;left:-6px;background:var(--bpm-accent,#45926f);border:0;z-index:0;pointer-events:none;opacity:0;transform:translateY(-120%);transition:transform .5s cubic-bezier(.16,1,.3,1),opacity .4s ease}
.bpi-notif-under.bpi-show{opacity:1;transform:translateY(0)}
.bpi-notif-under.bpi-wipe{transform:translateX(125%);transition:transform .32s cubic-bezier(.55,0,.8,.4)}
.bpi-notif{position:relative;z-index:1;width:100%;padding:18px 20px;background:var(--bpi-surface-modal,#20252d);border:1px solid var(--bpi-border,#3a4250);border-radius:0;box-shadow:var(--bpi-notif-shadow,0 20px 50px rgba(0,0,0,.65));overflow:hidden;max-height:90px;opacity:0;transform:translateY(-120%);transition:transform .5s cubic-bezier(.16,1,.3,1),opacity .4s ease,max-height .32s cubic-bezier(.3,.8,.3,1);will-change:transform,opacity,max-height}
.bpi-notif.bpi-play{opacity:1;transform:translateY(0)}
/* 底边亮线跟离场那层同色(--bpi-notif-front):默认蓝,出错时一起转紫红,
和垫在卡片后面那张纸(此时转成蓝)正好对调。它不是左侧竖条,竖条是 --bpm-accent */
.bpi-notif::after{content:"";position:absolute;left:0;right:0;bottom:0;height:3px;background:var(--bpi-notif-front,#0b8ce9);box-shadow:0 0 12px rgba(var(--bpi-notif-front-rgb,11,140,233),.55),0 0 4px rgba(var(--bpi-notif-front-rgb,11,140,233),.8);z-index:1;pointer-events:none}
.bpi-notif.bpi-out{pointer-events:none;animation:bpiExitSlide .36s cubic-bezier(.55,0,.8,.4) forwards}
@keyframes bpiExitSlide{from{transform:translateX(0)}to{transform:translateX(125%)}}
.bpi-notif-content{display:flex;flex-direction:column;gap:10px;position:relative;z-index:0}
.bpi-notif-head{padding-right:24px}
.bpi-notif-title{font-size:15px;font-weight:600;color:var(--bpi-text,#e6edf7);letter-spacing:.3px;line-height:1.35;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bpi-notif-extra{font-size:13px;color:var(--bpi-text-muted,#aab5c5);line-height:1.65;letter-spacing:.2px;opacity:0;transition:opacity .4s ease .1s;padding-bottom:6px;word-break:break-word}
.bpi-notif.bpi-expand .bpi-notif-extra{opacity:1}
.bpi-notif-logo{position:absolute;left:22px;top:50%;transform:translateY(-50%);line-height:0;color:#fff;pointer-events:none;user-select:none;filter:drop-shadow(var(--bpi-notif-logo-shadow,0 2px 14px rgba(0,0,0,.55)))}
.bpi-notif-logo svg{display:block;height:var(--bpi-notif-logo-size,36px);width:auto}
.bpi-notif-logo-standalone{z-index:9;opacity:0;transition:opacity .22s ease}
.bpi-notif.bpi-logo-visible .bpi-notif-logo-standalone{opacity:1}
/* 入场:先整块是蓝(mask 底色),再从上方落下绿色那层盖住 → 620ms 向右扫出去的瞬间是绿的 */
.bpi-notif-mask{position:absolute;inset:0;background:#0b8ce9;z-index:7;pointer-events:none;transform:translateX(0)}
.bpi-notif.bpi-play .bpi-notif-mask{animation:bpiMaskSweep .34s cubic-bezier(.55,0,.2,1) .48s forwards}
@keyframes bpiMaskSweep{from{transform:translateX(0)}to{transform:translateX(112%)}}
.bpi-notif-seq{position:absolute;inset:0;transform:translateY(-100%);will-change:transform}
.bpi-notif-seq:first-child{background:#0b8ce9;z-index:1}
/* 入场最后落下的那层:主题绿,扫出去露出内容前看到的颜色 */
.bpi-notif-seq:nth-child(2){background:var(--bpm-accent,#45926f);z-index:2}
.bpi-notif.bpi-play .bpi-notif-seq:first-child{animation:bpiSeqDrop .22s cubic-bezier(.3,.7,.3,1) 0s forwards}
.bpi-notif.bpi-play .bpi-notif-seq:nth-child(2){animation:bpiSeqDrop .22s cubic-bezier(.3,.7,.3,1) .08s forwards}
@keyframes bpiSeqDrop{from{transform:translateY(-100%)}to{transform:translateY(0)}}
.bpi-notif-logo-in-mask{z-index:3}
/* 离场时从卡片下方往上抹满整张卡片的那层:跟底边亮线同色(--bpi-notif-front),
默认蓝、出错时紫红 */
.bpi-notif-cover{position:absolute;inset:0;background:var(--bpi-notif-front,#0b8ce9);z-index:8;pointer-events:none;transform:translateY(calc(100% + 3px));transition:transform .38s cubic-bezier(.45,0,.2,1);will-change:transform}
.bpi-notif.bpi-covering .bpi-notif-cover{transform:translateY(0)}
/* 垫在卡片正后方的那张紫红纸:和卡片一样大、不往外露,所以静止时完全被卡片盖住看不见;
DOM 排在绿底纸之后 → 压在绿纸上面,卡片滑走后先看到它,它再滑走才轮到绿纸。
顺序:卡片(蓝)→ 紫红 → 绿,三层依次向右走;出错时前两层对调,变成紫红 → 蓝 → 红。 */
.bpi-notif-sheet{position:absolute;top:0;right:0;bottom:0;left:0;background:var(--bpi-notif-paper,#d946ef);border:0;z-index:0;pointer-events:none;opacity:0;transform:translateY(-120%);transition:transform .5s cubic-bezier(.16,1,.3,1),opacity .4s ease}
.bpi-notif-sheet.bpi-show{opacity:1;transform:translateY(0)}
.bpi-notif-sheet.bpi-wipe{transform:translateX(125%);transition:transform .32s cubic-bezier(.55,0,.8,.4)}
.bpi-notif-close{position:absolute;top:6px;right:6px;z-index:10;width:28px;height:28px;display:grid;place-items:center;padding:0;border:0;border-radius:0;background:transparent;color:var(--bpi-text-muted,#aab5c5);cursor:pointer;transition:background .15s ease,color .15s ease}
.bpi-notif-close:hover{background:var(--bpi-handle-hover-bg,#2b3a4d);color:var(--bpi-text,#e6edf7)}
.bpi-notif-close:active{background:var(--bpi-mini-hover-bg,#3c4b60)}
@media (prefers-reduced-motion: reduce){
.bpi-notif,.bpi-notif-extra,.bpi-notif.bpi-out,.bpi-notif-cover,.bpi-notif-logo-standalone,.bpi-notif-seq,.bpi-notif-sheet,.bpi-notif-under,.bpi-notif.bpi-play .bpi-notif-mask{animation-duration:.01ms !important;animation-delay:0s !important;transition-duration:.01ms !important}
}
`;
function injectStyles() {
if (injected || document.getElementById(STYLE_ID)) {
injected = true;
return;
}
const style = document.createElement("style");
style.id = STYLE_ID;
style.textContent = CSS;
document.head.appendChild(style);
injected = true;
}
// 标识内联 assets/translate.svg 的那条 path:插件的 /extensions 静态根只到 js/,
// assets/ 在插件根取不到(请求会 404),内联省得再搬一份文件,也不受静态服务影响。
// 原图 stroke 是黑的,这里改 currentColor 交给 CSS 上色。
const LOGO_SVG = '<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">'
+ '<path d="M5 8L10 13M4 14L10 8L12 5M2 5H14M7 2H8M12.913 17H20.087M12.913 17L11 21M12.913 17L15.7783 11.009C16.0092 10.5263 16.1246 10.2849 16.2826 10.2086C16.4199 10.1423 16.5801 10.1423 16.7174 10.2086C16.8754 10.2849 16.9908 10.5263 17.2217 11.009L20.087 17M20.087 17L22 21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
+ "</svg>";
function buildLogo(extraClass) {
const logo = element("div", `bpi-notif-logo ${extraClass}`);
logo.innerHTML = LOGO_SVG;
return logo;
}
function ensureStack() {
if (stack) return;
stack = element("div", "bpi-notif-stack");
document.body.appendChild(stack);
}
function createCard() {
const slot = element("div", "bpi-notif-slot");
// 由下而上:绿底纸 → 紫红垫纸 → 卡片(卡片盖住前两张,紫红只在卡片滑走后才露出来)
const under = element("div", "bpi-notif-under");
const sheet = element("div", "bpi-notif-sheet");
const notif = element("div", "bpi-notif");
const logoStandalone = buildLogo("bpi-notif-logo-standalone");
const content = element("div", "bpi-notif-content");
const head = element("div", "bpi-notif-head");
// 折叠时只显示标题那一行,消息正文放在展开后才淡入的 extra 里,不再重复一遍
const titleEl = element("div", "bpi-notif-title");
const extraEl = element("div", "bpi-notif-extra");
head.appendChild(titleEl);
content.append(head, extraEl);
const mask = element("div", "bpi-notif-mask");
mask.append(element("div", "bpi-notif-seq"), element("div", "bpi-notif-seq"));
mask.appendChild(buildLogo("bpi-notif-logo-in-mask"));
const cover = element("div", "bpi-notif-cover");
const close = element("button", "bpi-notif-close", "✕");
close.type = "button";
notif.append(logoStandalone, content, mask, cover, close);
slot.append(under, sheet, notif);
const card = {
slot, notif, under, sheet, content, head, titleEl, extraEl,
item: null,
sticky: false,
shownAt: 0,
pendingItem: null,
pendingTimer: null,
timers: [],
closed: false,
leaving: false,
};
close.addEventListener("click", () => dismissCard(card));
return card;
}
function clearCardTimers(card) {
card.timers.forEach((id) => clearTimeout(id));
card.timers = [];
}
// 状态词当标题,消息本身放正文:标题一行放不下的长句,展开后能看全
function titleFor(kind) {
if (kind === "ok") return "Done";
if (kind === "error") return "Something went wrong";
if (kind === "busy") return "Working...";
return "Notice";
}
function sameItem(a, b) {
return !!a && !!b && a.message === b.message && a.kind === b.kind;
}
// 「处理中」一直挂着,等下一条结果把它顶掉;真等不到结果,兜底这么多毫秒后自己收掉
function armDismiss(card) {
card.sticky = card.item.kind === "busy";
if (card.sticky) {
card.shownAt = Date.now();
card.timers.push(setTimeout(() => dismissCard(card), STICKY_MAX_MS));
return;
}
const baseHold = card.item.kind === "error" ? ERROR_HOLD_MS : HOLD_MS;
const hold = Number(card.item.hold) > 0 ? Number(card.item.hold) : baseHold;
card.timers.push(setTimeout(() => dismissCard(card), hold));
}
function measure(card) {
const notif = card.notif;
notif.style.transition = "none";
notif.style.maxHeight = "none";
void notif.offsetWidth;
const fullH = card.content.scrollHeight + PADDING_EXTRA;
const initialH = card.head.offsetHeight + PADDING_EXTRA;
// 标识跟着卡片大小走,再多也不许超过卡片宽度的四分之一,免得顶到外面被裁掉
const logoSize = Math.max(28, Math.min(Math.round(initialH * LOGO_HEIGHT_RATIO), Math.round(notif.offsetWidth * 0.24)));
notif.style.setProperty("--bpi-notif-logo-size", `${logoSize}px`);
return { fullH, initialH };
}
function playCard(card) {
clearCardTimers(card);
card.item = card.item || { message: "", kind: "" };
card.slot.classList.toggle("bpi-notif-error", card.item.kind === "error");
// 摘类之前先关掉过渡:卡片此刻停在屏幕右侧(上一次退场的位置),
// 带着过渡摘类会让它斜着飞回入场起点,看着就是「结束后往上一跳」
card.notif.style.transition = "none";
card.under.style.transition = "none";
card.sheet.style.transition = "none";
card.notif.classList.remove("bpi-play", "bpi-out", "bpi-expand", "bpi-covering", "bpi-logo-visible");
card.under.classList.remove("bpi-show", "bpi-wipe");
card.sheet.classList.remove("bpi-show", "bpi-wipe");
void card.notif.offsetWidth;
void card.under.offsetWidth;
void card.sheet.offsetWidth;
card.extraEl.textContent = t(card.item.message);
card.titleEl.textContent = t(titleFor(card.item.kind));
// 先放开量完整高度,再压回只够显示标题的高度,最后才恢复过渡
const { fullH, initialH } = measure(card);
card.initialH = initialH;
card.notif.style.maxHeight = `${initialH}px`;
void card.notif.offsetWidth;
card.notif.style.transition = "";
void card.notif.offsetWidth;
card.notif.classList.add("bpi-play");
card.under.style.transition = ""; // 归位已无过渡完成,这里恢复后才能滑入
card.sheet.style.transition = "";
void card.under.offsetWidth;
void card.sheet.offsetWidth;
card.under.classList.add("bpi-show");
card.sheet.classList.add("bpi-show");
card.timers.push(setTimeout(() => {
card.notif.classList.add("bpi-expand");
card.notif.style.maxHeight = `${fullH}px`;
}, 880));
armDismiss(card);
}
// 结果到了:不重播入场动画,直接换掉卡片里的文字,展开高度跟着新内容重算
function updateCardContent(card, item) {
clearCardTimers(card);
card.item = item;
card.slot.classList.toggle("bpi-notif-error", item.kind === "error");
card.extraEl.textContent = t(item.message);
card.titleEl.textContent = t(titleFor(item.kind));
card.notif.style.transition = "none";
card.notif.style.maxHeight = "none";
void card.notif.offsetWidth;
card.notif.style.maxHeight = `${card.content.scrollHeight + PADDING_EXTRA}px`;
void card.notif.offsetWidth;
card.notif.style.transition = "";
card.notif.classList.add("bpi-expand");
armDismiss(card);
}
// 结果来得太快时先扣着,等「处理中」播够时间再顶上去
function flushPending(card) {
card.pendingTimer = null;
const item = card.pendingItem;
card.pendingItem = null;
if (item && !card.closed) updateCardContent(card, item);
}
function dismissCard(card) {
// leaving 挡住重复调用:退场要跑 0.9 秒才真正从 cards 里摘掉,
// 期间 trimCards 可能又点到同一张卡,没有这个标记就会反复触发、甚至死循环
if (card.closed || card.leaving) return;
card.leaving = true;
clearCardTimers(card);
if (card.pendingTimer) {
clearTimeout(card.pendingTimer);
card.pendingTimer = null;
}
card.pendingItem = null;
card.notif.classList.remove("bpi-expand");
card.notif.classList.add("bpi-covering", "bpi-logo-visible");
card.notif.style.maxHeight = `${card.initialH}px`;
// 退场:先收高度 + 上抹层刷上来(默认蓝、出错时紫红),420ms 后卡片右移;垫纸晚 85ms 跟上,
// 最下面那张纸再晚 85ms,三层依次向右滑走 —— 紫红那张「和上抹层一样向右走,只不过在它后面」
card.timers.push(setTimeout(() => {
card.notif.classList.add("bpi-out");
card.timers.push(setTimeout(() => {
card.sheet.classList.add("bpi-wipe");
card.timers.push(setTimeout(() => {
card.under.classList.add("bpi-wipe");
card.timers.push(setTimeout(() => {
// 复位必须先关过渡:垫纸和底纸此刻停在屏幕右侧,直接摘类会让它一路斜着飞回入场起点
card.sheet.style.transition = "none";
card.sheet.classList.remove("bpi-show", "bpi-wipe");
void card.sheet.offsetWidth;
card.sheet.style.transition = "";
card.under.style.transition = "none";
card.under.classList.remove("bpi-show", "bpi-wipe");
void card.under.offsetWidth;
card.under.style.transition = "";
card.notif.classList.remove("bpi-logo-visible");
removeCard(card);
}, 330));
}, 85));
}, 85));
}, 420));
}
// 让位动画(FLIP):插入/移除卡片会让下面的卡片瞬间跳位,这里先把它们按原位置偏回去,
// 再过渡到新位置,看着就是平滑地被挤下去 / 收上来
function snapshotTops() {
const tops = new Map();
cards.forEach((card) => tops.set(card, card.slot.getBoundingClientRect().top));
return tops;
}
function nudgeStack(before) {
before.forEach((top, card) => {
if (card.leaving || card.closed) return;
const delta = top - card.slot.getBoundingClientRect().top;
if (!delta) return;
card.slot.style.transition = "none";
card.slot.style.transform = `translateY(${delta}px)`;
void card.slot.offsetWidth;
card.slot.style.transition = "transform .35s cubic-bezier(.16,1,.3,1)";
card.slot.style.transform = "";
});
}
function removeCard(card) {
if (card.closed) return;
card.closed = true;
clearCardTimers(card);
const index = cards.indexOf(card);
const before = snapshotTops();
if (index >= 0) cards.splice(index, 1);
card.slot.remove();
nudgeStack(before);
}
// 超过上限就把最旧的那条(在最下面)挤掉。正在退场的卡片不算数,也别重复点它
function trimCards() {
for (let index = cards.length - 1; index >= 0; index -= 1) {
const alive = cards.filter((card) => !card.leaving).length;
if (alive <= MAX_CARDS) return;
dismissCard(cards[index]);
}
}
export function notify(message, kind = "", options = null) {
if (!notifyEnabled() || !message) return false;
injectStyles();
ensureStack();
const opts = options || {};
const group = typeof opts.group === "string" ? opts.group : "";
const hold = Number(opts.hold) > 0 ? Number(opts.hold) : 0;
const fresh = opts.fresh === true;
const item = { message, kind, group, hold: hold || (group ? REFRESH_HOLD_MS : 0) };
// 正在退场的不算;fresh 会先让旧卡退场,所以每次都重新取一遍
const alive = () => cards.filter((card) => !card.leaving);
// fresh:让同组的旧卡(批量翻译那张「处理中」进度卡)先退场,再开一张全新的报结果,
// 避免「进度卡 + 汇总卡」并排挂着。没给 group 时退掉所有「处理中」卡。
if (fresh) {
alive()
.filter((card) => (group ? card.item && card.item.group === group : card.sticky))
.forEach((card) => dismissCard(card));
}
// 有 group 的提示(连点重复胶囊等):复用那张卡,换掉文字并把停留时间重新计一遍。
// 没有 group 时才走「一模一样就忽略」的旧逻辑;fresh 一律另开新卡。
if (!fresh) {
if (group) {
const groupCard = alive().find((card) => card.item && card.item.group === group && !card.sticky);
if (groupCard) {
updateCardContent(groupCard, item);
return true;
}
} else if (alive().some((card) => sameItem(card.item, item))) {
return true;
}
// 有「处理中」挂着:结果去顶掉它,不另开一张卡
const busyCard = alive().find((card) => card.sticky);
if (busyCard) {
const waited = Date.now() - busyCard.shownAt;
if (waited < MIN_BUSY_MS) {
busyCard.pendingItem = item;
if (busyCard.pendingTimer) clearTimeout(busyCard.pendingTimer);
busyCard.pendingTimer = setTimeout(() => flushPending(busyCard), MIN_BUSY_MS - waited);
return true;
}
updateCardContent(busyCard, item);
return true;
}
}
const card = createCard();
card.item = item;
const before = snapshotTops();
cards.unshift(card);
// 插在最上面,已有的往下挤
stack.insertBefore(card.slot, stack.firstChild);
trimCards();
// 先播(内部会量出真实高度并压回折叠高度),再让下面的卡片平滑让位:
// 顺序反过来会因为「插入时的默认高度 → 量完的真实高度」抖两次
playCard(card);
nudgeStack(before);
return true;
}
+85 -10
View File
@@ -199,6 +199,18 @@ async function getAssistantConfig() {
return result.data;
}
// 拿表单当前填的地址和密钥问一次「你有哪些模型」;后端不读已保存的密钥,也不写配置
async function listAssistantModels(payload) {
const response = await bpiFetch(`${API_ROOT}/assistant/models`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const result = await response.json().catch(() => null);
if (!response.ok || !result?.success) throw new Error(result?.error || "Failed to fetch models");
return Array.isArray(result.data?.models) ? result.data.models : [];
}
// 读 data/token_colors.json;用户可以不改源码只改这个文件管理节点标签卡的颜色池。
// 文件不在或格式不对时后端回退内置默认,这里只管透传。
let tokenColorsPromise = null;
@@ -1222,10 +1234,10 @@ function injectBpiStyles() {
const style = document.createElement("style");
style.id = "bpi-styles";
style.textContent = `
:root{--bpi-field-bg:#fff;--bpi-field-border:#bbb;--bpi-switch-off:#c9ced6;--bpi-switch-knob:#fff;--bpi-switch-off-border:#b0b6bf;--bpm-accent:#45926f;--bpm-accent-hover:#3a7d5e;--bpm-accent-border:#35755a;--bpi-custom-bg:#e6f6f1;--bpi-custom-border:#7fc9b0;--bpi-custom-text:#0f6e56;--bpi-surface:rgba(255,255,255,.92);--bpi-surface-2:#f5f5f5;--bpi-surface-3:#eaeaea;--bpi-surface-table:#f0f0f0;--bpi-surface-modal:#fff;--bpi-text:#333;--bpi-text-muted:#666;--bpi-text-faint:#999;--bpi-border:#ccc;--bpi-border-2:#bbb;--bpi-border-3:#e0e0e0;--bpi-button-bg:#e8e8e8;--bpi-button-text:#333;--bpi-input-bg:#fff;--bpi-input-text:#333;--bpi-head-bg:#e8e8e8;--bpi-danger-bg:#c0392b;--bpi-danger-bg-hover:#a53023;--bpi-danger-border:#a53023;--bpi-danger-text:#fff;--bpi-break-bg:#e6f6f1;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#7fc9b0;--bpi-break-text:#0f6e56;--bpi-primary-bg:#2b6cb0;--bpi-primary-bg-hover:#245a94;--bpi-primary-border:#1e4f85;--bpi-primary-text:#fff;--bpi-en-head-text:#17557f;--bpi-en-hint-text:#5b7f9e;--bpi-zh-head-text:#1f5c22;--bpi-zh-hint-text:#5b7d5e;--bpi-cat-name-text:#1e5a28;--bpi-info-text:#1f5f96;--bpi-link-text:#1a5f96;--bpi-zh-text:#18508a;--bpi-status-error:#b3261e;--bpi-status-ok:#1a7f45;--bpi-status-busy:#8a5a00;--bpi-badge-warn:#8a5a00;--bpi-badge-source:#0f6e56;--bpi-badge-suspected:#1c5f80;--bpi-badge-machine:#5b3fa8;--bpi-star-on:#a8750a;--bpi-star-off:#6b7280;--bpi-quick-head-text:#4a3a7a;--bpi-quick-hint-text:#6b5a8f;--bpi-handle-text:#4a6a85;--bpi-handle-hover:#1f5f96;--bpi-mini-hover-bg:#d8dee7;--bpi-handle-hover-bg:#e2e8ef;--bpi-chip-hide-bg:#eef1f5;--bpi-waiting-bg:#fdf1dc;--bpi-waiting-border:#d9a95a;--bpi-hidden-chip-hover-bg:#e8eef5;--bpi-issues-bg:#fdf6e8;--bpi-issues-border:#d9b98a;--bpi-issue-text:#7a5410;--bpi-row-hover-overlay:rgba(47,108,176,.06);--bpi-row-pinned-overlay:#cfe3f7;--bpi-row-hover-ring:rgba(47,108,176,.55);--bpi-row-pinned-ring:#1a5f96;--bpi-row-hover-text:#1f1f1f;--bpi-row-hover-shadow:none;--bpi-row-selected-bg:#dcebf8;--bpi-en-section-bg:rgba(43,108,176,.06);--bpi-quick-section-bg:rgba(107,85,148,.06);--bpi-dup-overlay:rgba(179,38,30,.12);--bpi-editor-bg:#fff;--bpi-hit-bg:#fbe49c;--bpi-hit-text:#7a5410}
.dark-theme{--bpi-field-bg:#0b0d10;--bpi-field-border:#333a45;--bpi-switch-off:#39414f;--bpi-switch-knob:#e8edf5;--bpi-switch-off-border:#4c5668;--bpi-custom-bg:#17342c;--bpi-custom-border:#3f8f77;--bpi-custom-text:#7fdcbd;--bpi-surface:rgba(10,12,18,.72);--bpi-surface-2:#171b22;--bpi-surface-3:#14181f;--bpi-surface-table:#11151b;--bpi-surface-modal:#20252d;--bpi-text:#e6edf7;--bpi-text-muted:#aab5c5;--bpi-text-faint:#7f8a9a;--bpi-border:#3a4250;--bpi-border-2:#4c5668;--bpi-border-3:#29313d;--bpi-button-bg:#2c3340;--bpi-button-text:#e8edf5;--bpi-input-bg:#171b22;--bpi-input-text:#eef3fb;--bpi-head-bg:#252c36;--bpi-danger-bg:#65313b;--bpi-danger-bg-hover:#7d3d49;--bpi-danger-border:#8d4653;--bpi-danger-text:#ffd9de;--bpi-break-bg:#17342c;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#3f8f77;--bpi-break-text:#7fdcbd;--bpi-primary-bg:#285f8e;--bpi-primary-bg-hover:#346f9f;--bpi-primary-border:#3f83ba;--bpi-primary-text:#eaf3fb;--bpi-en-head-text:#cbe8ff;--bpi-en-hint-text:#91b4cf;--bpi-zh-head-text:#cbe9c8;--bpi-zh-hint-text:#91ad93;--bpi-cat-name-text:#9ee8a7;--bpi-info-text:#87bfea;--bpi-link-text:#76c9ff;--bpi-zh-text:#9ed0ff;--bpi-status-error:#ff8b93;--bpi-status-ok:#7fdda2;--bpi-status-busy:#ffd27a;--bpi-badge-warn:#e2ca78;--bpi-badge-source:#86d5c4;--bpi-badge-suspected:#7fc4e0;--bpi-badge-machine:#cbb1ff;--bpi-star-on:#ffd45f;--bpi-star-off:#8f9aaa;--bpi-quick-head-text:#d9ccff;--bpi-quick-hint-text:#a795c6;--bpi-handle-text:#7194ad;--bpi-handle-hover:#a9c8e4;--bpi-mini-hover-bg:#3c4b60;--bpi-handle-hover-bg:#2b3a4d;--bpi-chip-hide-bg:#1d2937;--bpi-waiting-bg:rgba(70,52,25,.5);--bpi-waiting-border:#8a5f16;--bpi-hidden-chip-hover-bg:#31404f;--bpi-issues-bg:rgba(55,39,25,.55);--bpi-issues-border:#5b4a36;--bpi-issue-text:#e6c792;--bpi-row-hover-overlay:rgba(76,167,232,.34);--bpi-row-pinned-overlay:#314b68;--bpi-row-hover-ring:rgba(76,167,232,.7);--bpi-row-pinned-ring:#76c9ff;--bpi-row-hover-text:#fff;--bpi-row-hover-shadow:0 0 7px rgba(109,190,255,.6);--bpi-row-selected-bg:#314b68;--bpi-en-section-bg:rgba(76,167,232,.08);--bpi-quick-section-bg:rgba(167,149,198,.08);--bpi-dup-overlay:rgba(255,139,147,.22);--bpi-editor-bg:#111923;--bpi-hit-bg:#5a4413;--bpi-hit-text:#ffe6a8}
[data-bpi-theme="dark"]{--bpi-field-bg:#0b0d10;--bpi-field-border:#333a45;--bpi-switch-off:#39414f;--bpi-switch-knob:#e8edf5;--bpi-switch-off-border:#4c5668;--bpi-custom-bg:#17342c;--bpi-custom-border:#3f8f77;--bpi-custom-text:#7fdcbd;--bpi-surface:rgba(10,12,18,.72);--bpi-surface-2:#171b22;--bpi-surface-3:#14181f;--bpi-surface-table:#11151b;--bpi-surface-modal:#20252d;--bpi-text:#e6edf7;--bpi-text-muted:#aab5c5;--bpi-text-faint:#7f8a9a;--bpi-border:#3a4250;--bpi-border-2:#4c5668;--bpi-border-3:#29313d;--bpi-button-bg:#2c3340;--bpi-button-text:#e8edf5;--bpi-input-bg:#171b22;--bpi-input-text:#eef3fb;--bpi-head-bg:#252c36;--bpi-danger-bg:#65313b;--bpi-danger-bg-hover:#7d3d49;--bpi-danger-border:#8d4653;--bpi-danger-text:#ffd9de;--bpi-break-bg:#17342c;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#3f8f77;--bpi-break-text:#7fdcbd;--bpi-primary-bg:#285f8e;--bpi-primary-bg-hover:#346f9f;--bpi-primary-border:#3f83ba;--bpi-primary-text:#eaf3fb;--bpi-en-head-text:#cbe8ff;--bpi-en-hint-text:#91b4cf;--bpi-zh-head-text:#cbe9c8;--bpi-zh-hint-text:#91ad93;--bpi-cat-name-text:#9ee8a7;--bpi-info-text:#87bfea;--bpi-link-text:#76c9ff;--bpi-zh-text:#9ed0ff;--bpi-status-error:#ff8b93;--bpi-status-ok:#7fdda2;--bpi-status-busy:#ffd27a;--bpi-badge-warn:#e2ca78;--bpi-badge-source:#86d5c4;--bpi-badge-suspected:#7fc4e0;--bpi-badge-machine:#cbb1ff;--bpi-star-on:#ffd45f;--bpi-star-off:#8f9aaa;--bpi-quick-head-text:#d9ccff;--bpi-quick-hint-text:#a795c6;--bpi-handle-text:#7194ad;--bpi-handle-hover:#a9c8e4;--bpi-mini-hover-bg:#3c4b60;--bpi-handle-hover-bg:#2b3a4d;--bpi-chip-hide-bg:#1d2937;--bpi-waiting-bg:rgba(70,52,25,.5);--bpi-waiting-border:#8a5f16;--bpi-hidden-chip-hover-bg:#31404f;--bpi-issues-bg:rgba(55,39,25,.55);--bpi-issues-border:#5b4a36;--bpi-issue-text:#e6c792;--bpi-row-hover-overlay:rgba(76,167,232,.34);--bpi-row-pinned-overlay:#314b68;--bpi-row-hover-ring:rgba(76,167,232,.7);--bpi-row-pinned-ring:#76c9ff;--bpi-row-hover-text:#fff;--bpi-row-hover-shadow:0 0 7px rgba(109,190,255,.6);--bpi-row-selected-bg:#314b68;--bpi-en-section-bg:rgba(76,167,232,.08);--bpi-quick-section-bg:rgba(167,149,198,.08);--bpi-dup-overlay:rgba(255,139,147,.22);--bpi-editor-bg:#111923;--bpi-hit-bg:#5a4413;--bpi-hit-text:#ffe6a8}
[data-bpi-theme="light"]{--bpi-field-bg:#fff;--bpi-field-border:#bbb;--bpi-switch-off:#c9ced6;--bpi-switch-knob:#fff;--bpi-switch-off-border:#b0b6bf;--bpi-custom-bg:#e6f6f1;--bpi-custom-border:#7fc9b0;--bpi-custom-text:#0f6e56;--bpi-surface:rgba(255,255,255,.92);--bpi-surface-2:#f5f5f5;--bpi-surface-3:#eaeaea;--bpi-surface-table:#f0f0f0;--bpi-surface-modal:#fff;--bpi-text:#333;--bpi-text-muted:#666;--bpi-text-faint:#999;--bpi-border:#ccc;--bpi-border-2:#bbb;--bpi-border-3:#e0e0e0;--bpi-button-bg:#e8e8e8;--bpi-button-text:#333;--bpi-input-bg:#fff;--bpi-input-text:#333;--bpi-head-bg:#e8e8e8;--bpi-danger-bg:#c0392b;--bpi-danger-bg-hover:#a53023;--bpi-danger-border:#a53023;--bpi-danger-text:#fff;--bpi-break-bg:#e6f6f1;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#7fc9b0;--bpi-break-text:#0f6e56;--bpi-primary-bg:#2b6cb0;--bpi-primary-bg-hover:#245a94;--bpi-primary-border:#1e4f85;--bpi-primary-text:#fff;--bpi-en-head-text:#17557f;--bpi-en-hint-text:#5b7f9e;--bpi-zh-head-text:#1f5c22;--bpi-zh-hint-text:#5b7d5e;--bpi-cat-name-text:#1e5a28;--bpi-info-text:#1f5f96;--bpi-link-text:#1a5f96;--bpi-zh-text:#18508a;--bpi-status-error:#b3261e;--bpi-status-ok:#1a7f45;--bpi-status-busy:#8a5a00;--bpi-badge-warn:#8a5a00;--bpi-badge-source:#0f6e56;--bpi-badge-suspected:#1c5f80;--bpi-badge-machine:#5b3fa8;--bpi-star-on:#a8750a;--bpi-star-off:#6b7280;--bpi-quick-head-text:#4a3a7a;--bpi-quick-hint-text:#6b5a8f;--bpi-handle-text:#4a6a85;--bpi-handle-hover:#1f5f96;--bpi-mini-hover-bg:#d8dee7;--bpi-handle-hover-bg:#e2e8ef;--bpi-chip-hide-bg:#eef1f5;--bpi-waiting-bg:#fdf1dc;--bpi-waiting-border:#d9a95a;--bpi-hidden-chip-hover-bg:#e8eef5;--bpi-issues-bg:#fdf6e8;--bpi-issues-border:#d9b98a;--bpi-issue-text:#7a5410;--bpi-row-hover-overlay:rgba(47,108,176,.06);--bpi-row-pinned-overlay:#cfe3f7;--bpi-row-hover-ring:rgba(47,108,176,.55);--bpi-row-pinned-ring:#1a5f96;--bpi-row-hover-text:#1f1f1f;--bpi-row-hover-shadow:none;--bpi-row-selected-bg:#dcebf8;--bpi-en-section-bg:rgba(43,108,176,.06);--bpi-quick-section-bg:rgba(107,85,148,.06);--bpi-dup-overlay:rgba(179,38,30,.12);--bpi-editor-bg:#fff;--bpi-hit-bg:#fbe49c;--bpi-hit-text:#7a5410}
:root{--bpi-field-bg:#fff;--bpi-field-border:#bbb;--bpi-switch-off:#c9ced6;--bpi-switch-knob:#fff;--bpi-switch-off-border:#b0b6bf;--bpm-accent:#45926f;--bpm-accent-hover:#3a7d5e;--bpm-accent-border:#35755a;--bpi-custom-bg:#e6f6f1;--bpi-custom-border:#7fc9b0;--bpi-custom-text:#0f6e56;--bpi-surface:rgba(255,255,255,.92);--bpi-surface-2:#f5f5f5;--bpi-surface-3:#eaeaea;--bpi-surface-table:#f0f0f0;--bpi-surface-modal:#fff;--bpi-text:#333;--bpi-text-muted:#666;--bpi-text-faint:#999;--bpi-border:#ccc;--bpi-border-2:#bbb;--bpi-border-3:#e0e0e0;--bpi-button-bg:#e8e8e8;--bpi-button-text:#333;--bpi-input-bg:#fff;--bpi-input-text:#333;--bpi-head-bg:#e8e8e8;--bpi-danger-bg:#c0392b;--bpi-danger-bg-hover:#a53023;--bpi-danger-border:#a53023;--bpi-danger-text:#fff;--bpi-break-bg:#e6f6f1;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#7fc9b0;--bpi-break-text:#0f6e56;--bpi-primary-bg:#2b6cb0;--bpi-primary-bg-hover:#245a94;--bpi-primary-border:#1e4f85;--bpi-primary-text:#fff;--bpi-en-head-text:#17557f;--bpi-en-hint-text:#5b7f9e;--bpi-zh-head-text:#1f5c22;--bpi-zh-hint-text:#5b7d5e;--bpi-cat-name-text:#1e5a28;--bpi-info-text:#1f5f96;--bpi-link-text:#1a5f96;--bpi-zh-text:#18508a;--bpi-status-error:#b3261e;--bpi-status-ok:#1a7f45;--bpi-status-busy:#8a5a00;--bpi-badge-warn:#8a5a00;--bpi-badge-source:#0f6e56;--bpi-badge-suspected:#1c5f80;--bpi-badge-machine:#5b3fa8;--bpi-star-on:#a8750a;--bpi-star-off:#6b7280;--bpi-quick-head-text:#4a3a7a;--bpi-quick-hint-text:#6b5a8f;--bpi-handle-text:#4a6a85;--bpi-handle-hover:#1f5f96;--bpi-mini-hover-bg:#d8dee7;--bpi-handle-hover-bg:#e2e8ef;--bpi-chip-hide-bg:#eef1f5;--bpi-waiting-bg:#fdf1dc;--bpi-waiting-border:#d9a95a;--bpi-hidden-chip-hover-bg:#e8eef5;--bpi-issues-bg:#fdf6e8;--bpi-issues-border:#d9b98a;--bpi-issue-text:#7a5410;--bpi-row-hover-overlay:rgba(47,108,176,.06);--bpi-row-pinned-overlay:#cfe3f7;--bpi-row-hover-ring:rgba(47,108,176,.55);--bpi-row-pinned-ring:#1a5f96;--bpi-row-hover-text:#1f1f1f;--bpi-row-hover-shadow:none;--bpi-row-selected-bg:#dcebf8;--bpi-drag-row-bar:#45926f;--bpi-drag-row-bg:#d6efe4;--bpi-drag-row-text:#0f4d3a;--bpi-en-section-bg:rgba(43,108,176,.06);--bpi-quick-section-bg:rgba(107,85,148,.06);--bpi-dup-overlay:rgba(179,38,30,.12);--bpi-editor-bg:#fff;--bpi-hit-bg:#fbe49c;--bpi-hit-text:#7a5410}
.dark-theme{--bpi-field-bg:#0b0d10;--bpi-field-border:#333a45;--bpi-switch-off:#39414f;--bpi-switch-knob:#e8edf5;--bpi-switch-off-border:#4c5668;--bpi-custom-bg:#17342c;--bpi-custom-border:#3f8f77;--bpi-custom-text:#7fdcbd;--bpi-surface:rgba(10,12,18,.72);--bpi-surface-2:#171b22;--bpi-surface-3:#14181f;--bpi-surface-table:#11151b;--bpi-surface-modal:#20252d;--bpi-text:#e6edf7;--bpi-text-muted:#aab5c5;--bpi-text-faint:#7f8a9a;--bpi-border:#3a4250;--bpi-border-2:#4c5668;--bpi-border-3:#29313d;--bpi-button-bg:#2c3340;--bpi-button-text:#e8edf5;--bpi-input-bg:#171b22;--bpi-input-text:#eef3fb;--bpi-head-bg:#252c36;--bpi-danger-bg:#65313b;--bpi-danger-bg-hover:#7d3d49;--bpi-danger-border:#8d4653;--bpi-danger-text:#ffd9de;--bpi-break-bg:#17342c;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#3f8f77;--bpi-break-text:#7fdcbd;--bpi-primary-bg:#285f8e;--bpi-primary-bg-hover:#346f9f;--bpi-primary-border:#3f83ba;--bpi-primary-text:#eaf3fb;--bpi-en-head-text:#cbe8ff;--bpi-en-hint-text:#91b4cf;--bpi-zh-head-text:#cbe9c8;--bpi-zh-hint-text:#91ad93;--bpi-cat-name-text:#9ee8a7;--bpi-info-text:#87bfea;--bpi-link-text:#76c9ff;--bpi-zh-text:#9ed0ff;--bpi-status-error:#ff8b93;--bpi-status-ok:#7fdda2;--bpi-status-busy:#ffd27a;--bpi-badge-warn:#e2ca78;--bpi-badge-source:#86d5c4;--bpi-badge-suspected:#7fc4e0;--bpi-badge-machine:#cbb1ff;--bpi-star-on:#ffd45f;--bpi-star-off:#8f9aaa;--bpi-quick-head-text:#d9ccff;--bpi-quick-hint-text:#a795c6;--bpi-handle-text:#7194ad;--bpi-handle-hover:#a9c8e4;--bpi-mini-hover-bg:#3c4b60;--bpi-handle-hover-bg:#2b3a4d;--bpi-chip-hide-bg:#1d2937;--bpi-waiting-bg:rgba(70,52,25,.5);--bpi-waiting-border:#8a5f16;--bpi-hidden-chip-hover-bg:#31404f;--bpi-issues-bg:rgba(55,39,25,.55);--bpi-issues-border:#5b4a36;--bpi-issue-text:#e6c792;--bpi-row-hover-overlay:rgba(76,167,232,.34);--bpi-row-pinned-overlay:#314b68;--bpi-row-hover-ring:rgba(76,167,232,.7);--bpi-row-pinned-ring:#76c9ff;--bpi-row-hover-text:#fff;--bpi-row-hover-shadow:0 0 7px rgba(109,190,255,.6);--bpi-row-selected-bg:#314b68;--bpi-drag-row-bar:#5ec9a3;--bpi-drag-row-bg:rgba(63,143,119,.30);--bpi-drag-row-text:#eafff7;--bpi-en-section-bg:rgba(76,167,232,.08);--bpi-quick-section-bg:rgba(167,149,198,.08);--bpi-dup-overlay:rgba(255,139,147,.22);--bpi-editor-bg:#111923;--bpi-hit-bg:#5a4413;--bpi-hit-text:#ffe6a8}
[data-bpi-theme="dark"]{--bpi-field-bg:#0b0d10;--bpi-field-border:#333a45;--bpi-switch-off:#39414f;--bpi-switch-knob:#e8edf5;--bpi-switch-off-border:#4c5668;--bpi-custom-bg:#17342c;--bpi-custom-border:#3f8f77;--bpi-custom-text:#7fdcbd;--bpi-surface:rgba(10,12,18,.72);--bpi-surface-2:#171b22;--bpi-surface-3:#14181f;--bpi-surface-table:#11151b;--bpi-surface-modal:#20252d;--bpi-text:#e6edf7;--bpi-text-muted:#aab5c5;--bpi-text-faint:#7f8a9a;--bpi-border:#3a4250;--bpi-border-2:#4c5668;--bpi-border-3:#29313d;--bpi-button-bg:#2c3340;--bpi-button-text:#e8edf5;--bpi-input-bg:#171b22;--bpi-input-text:#eef3fb;--bpi-head-bg:#252c36;--bpi-danger-bg:#65313b;--bpi-danger-bg-hover:#7d3d49;--bpi-danger-border:#8d4653;--bpi-danger-text:#ffd9de;--bpi-break-bg:#17342c;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#3f8f77;--bpi-break-text:#7fdcbd;--bpi-primary-bg:#285f8e;--bpi-primary-bg-hover:#346f9f;--bpi-primary-border:#3f83ba;--bpi-primary-text:#eaf3fb;--bpi-en-head-text:#cbe8ff;--bpi-en-hint-text:#91b4cf;--bpi-zh-head-text:#cbe9c8;--bpi-zh-hint-text:#91ad93;--bpi-cat-name-text:#9ee8a7;--bpi-info-text:#87bfea;--bpi-link-text:#76c9ff;--bpi-zh-text:#9ed0ff;--bpi-status-error:#ff8b93;--bpi-status-ok:#7fdda2;--bpi-status-busy:#ffd27a;--bpi-badge-warn:#e2ca78;--bpi-badge-source:#86d5c4;--bpi-badge-suspected:#7fc4e0;--bpi-badge-machine:#cbb1ff;--bpi-star-on:#ffd45f;--bpi-star-off:#8f9aaa;--bpi-quick-head-text:#d9ccff;--bpi-quick-hint-text:#a795c6;--bpi-handle-text:#7194ad;--bpi-handle-hover:#a9c8e4;--bpi-mini-hover-bg:#3c4b60;--bpi-handle-hover-bg:#2b3a4d;--bpi-chip-hide-bg:#1d2937;--bpi-waiting-bg:rgba(70,52,25,.5);--bpi-waiting-border:#8a5f16;--bpi-hidden-chip-hover-bg:#31404f;--bpi-issues-bg:rgba(55,39,25,.55);--bpi-issues-border:#5b4a36;--bpi-issue-text:#e6c792;--bpi-row-hover-overlay:rgba(76,167,232,.34);--bpi-row-pinned-overlay:#314b68;--bpi-row-hover-ring:rgba(76,167,232,.7);--bpi-row-pinned-ring:#76c9ff;--bpi-row-hover-text:#fff;--bpi-row-hover-shadow:0 0 7px rgba(109,190,255,.6);--bpi-row-selected-bg:#314b68;--bpi-drag-row-bar:#5ec9a3;--bpi-drag-row-bg:rgba(63,143,119,.30);--bpi-drag-row-text:#eafff7;--bpi-en-section-bg:rgba(76,167,232,.08);--bpi-quick-section-bg:rgba(167,149,198,.08);--bpi-dup-overlay:rgba(255,139,147,.22);--bpi-editor-bg:#111923;--bpi-hit-bg:#5a4413;--bpi-hit-text:#ffe6a8}
[data-bpi-theme="light"]{--bpi-field-bg:#fff;--bpi-field-border:#bbb;--bpi-switch-off:#c9ced6;--bpi-switch-knob:#fff;--bpi-switch-off-border:#b0b6bf;--bpi-custom-bg:#e6f6f1;--bpi-custom-border:#7fc9b0;--bpi-custom-text:#0f6e56;--bpi-surface:rgba(255,255,255,.92);--bpi-surface-2:#f5f5f5;--bpi-surface-3:#eaeaea;--bpi-surface-table:#f0f0f0;--bpi-surface-modal:#fff;--bpi-text:#333;--bpi-text-muted:#666;--bpi-text-faint:#999;--bpi-border:#ccc;--bpi-border-2:#bbb;--bpi-border-3:#e0e0e0;--bpi-button-bg:#e8e8e8;--bpi-button-text:#333;--bpi-input-bg:#fff;--bpi-input-text:#333;--bpi-head-bg:#e8e8e8;--bpi-danger-bg:#c0392b;--bpi-danger-bg-hover:#a53023;--bpi-danger-border:#a53023;--bpi-danger-text:#fff;--bpi-break-bg:#e6f6f1;--bpi-break-bg-hover:#0f6e56;--bpi-break-border:#7fc9b0;--bpi-break-text:#0f6e56;--bpi-primary-bg:#2b6cb0;--bpi-primary-bg-hover:#245a94;--bpi-primary-border:#1e4f85;--bpi-primary-text:#fff;--bpi-en-head-text:#17557f;--bpi-en-hint-text:#5b7f9e;--bpi-zh-head-text:#1f5c22;--bpi-zh-hint-text:#5b7d5e;--bpi-cat-name-text:#1e5a28;--bpi-info-text:#1f5f96;--bpi-link-text:#1a5f96;--bpi-zh-text:#18508a;--bpi-status-error:#b3261e;--bpi-status-ok:#1a7f45;--bpi-status-busy:#8a5a00;--bpi-badge-warn:#8a5a00;--bpi-badge-source:#0f6e56;--bpi-badge-suspected:#1c5f80;--bpi-badge-machine:#5b3fa8;--bpi-star-on:#a8750a;--bpi-star-off:#6b7280;--bpi-quick-head-text:#4a3a7a;--bpi-quick-hint-text:#6b5a8f;--bpi-handle-text:#4a6a85;--bpi-handle-hover:#1f5f96;--bpi-mini-hover-bg:#d8dee7;--bpi-handle-hover-bg:#e2e8ef;--bpi-chip-hide-bg:#eef1f5;--bpi-waiting-bg:#fdf1dc;--bpi-waiting-border:#d9a95a;--bpi-hidden-chip-hover-bg:#e8eef5;--bpi-issues-bg:#fdf6e8;--bpi-issues-border:#d9b98a;--bpi-issue-text:#7a5410;--bpi-row-hover-overlay:rgba(47,108,176,.06);--bpi-row-pinned-overlay:#cfe3f7;--bpi-row-hover-ring:rgba(47,108,176,.55);--bpi-row-pinned-ring:#1a5f96;--bpi-row-hover-text:#1f1f1f;--bpi-row-hover-shadow:none;--bpi-row-selected-bg:#dcebf8;--bpi-drag-row-bar:#45926f;--bpi-drag-row-bg:#d6efe4;--bpi-drag-row-text:#0f4d3a;--bpi-en-section-bg:rgba(43,108,176,.06);--bpi-quick-section-bg:rgba(107,85,148,.06);--bpi-dup-overlay:rgba(179,38,30,.12);--bpi-editor-bg:#fff;--bpi-hit-bg:#fbe49c;--bpi-hit-text:#7a5410}
.bpi-panel{box-sizing:border-box;width:100%;height:100%;min-height:var(--bpi-collapsed-height,390px);max-height:var(--bpi-collapsed-height,390px);padding:8px;display:flex;flex-direction:column;gap:7px;color:var(--bpi-text);font:12px/1.4 Arial,sans-serif;background:var(--bpi-surface);border:1px solid var(--bpi-border);border-radius:8px;overflow-y:auto;scrollbar-gutter:stable}.bpi-panel.bpi-fill{max-height:none}.bpi-panel.bpi-fill > .bpi-english-section{display:flex;flex-direction:column;flex:1 1 auto;min-height:0}.bpi-panel.bpi-fill > .bpi-english-section > *{flex:none}.bpi-panel.bpi-fill > .bpi-english-section > .bpi-english-token-view{flex:1 1 auto;min-height:92px;max-height:none}.bpi-panel.bpi-fill > .bpi-english-section > .bpi-english-editor{flex:1 1 auto;min-height:120px}
.bpi-english-section{flex:none;border:1px solid #3e7197;border-radius:7px;background-color:var(--bpi-en-section-bg);overflow:hidden}.bpi-english-head{display:flex;align-items:center;gap:7px;padding:5px 8px;background:var(--bpi-head-bg);color:var(--bpi-en-head-text);font-weight:700;flex-wrap:wrap}.bpi-english-hint{margin-left:auto;color:var(--bpi-en-hint-text);font-size:10px;font-weight:400}.bpi-english-token-view{box-sizing:border-box;width:100%;height:auto;min-height:92px;max-height:360px;overflow:auto;scrollbar-gutter:stable;padding:8px 9px;outline:none;color:var(--bpi-text);font:12px/1.85 Consolas,monospace;white-space:normal}.bpi-english-token-view:focus{box-shadow:inset 0 0 0 1px #5aa6d8}.bpi-english-editor{box-sizing:border-box;width:100%;height:120px;min-height:92px;max-height:420px;overflow-y:auto;resize:vertical;border:0;border-top:1px solid #3e7197;background-color:transparent;color:var(--bpi-text);padding:9px;outline:none;font:12px/1.55 Consolas,monospace}.bpi-english-editor:focus{box-shadow:inset 0 0 0 1px #5aa6d8}.bpi-english-token{font-family:Consolas,monospace;color:var(--bpi-text)}.bpi-english-token.bpi-linked{background:#147fc3;border-color:#76c9ff;color:#fff;box-shadow:0 0 0 1px rgba(118,201,255,.32)}
.bpi-mirror-section{flex:none;border:1px solid #488739;border-radius:7px;background:var(--bpi-surface);overflow:visible}.bpi-section-head{display:flex;align-items:center;gap:7px;padding:5px 8px;background:var(--bpi-head-bg);color:var(--bpi-zh-head-text);font-weight:700;flex-wrap:wrap}.bpi-section-hint{margin-left:auto;color:var(--bpi-zh-hint-text);font-size:10px;font-weight:400}.bpi-mirror-actions{display:flex;gap:4px;align-items:center;flex-wrap:wrap}.bpi-chinese-mirror{box-sizing:border-box;width:100%;height:auto;min-height:92px;max-height:360px;overflow:auto;resize:none;scrollbar-gutter:stable;padding:8px 9px;outline:none;color:var(--bpi-text);line-height:1.85;cursor:text;white-space:normal}.bpi-chinese-mirror:focus{box-shadow:inset 0 0 0 1px #70b35f}.bpi-category-table{display:grid;grid-template-columns:minmax(110px,150px) minmax(0,1fr);border:1px solid #315f3a;border-radius:6px;overflow:hidden;background:var(--bpi-surface-3)}.bpi-category-row{display:contents}.bpi-category-name,.bpi-category-content{padding:6px 8px;border-top:1px solid #31513a}.bpi-category-row:first-child .bpi-category-name,.bpi-category-row:first-child .bpi-category-content{border-top:0}.bpi-category-name{background:var(--bpi-head-bg);border-right:1px solid #31513a;color:var(--bpi-cat-name-text);font-weight:700}.bpi-category-content{min-width:0}.bpi-chinese-editor{box-sizing:border-box;width:100%;height:auto;min-height:110px;max-height:600px;overflow-y:auto;resize:vertical;border:0;border-top:1px solid #3b693c;background:var(--bpi-editor-bg);color:var(--bpi-text);padding:9px;outline:none;font:12px/1.65 Arial,sans-serif}.bpi-chinese-editor:focus{box-shadow:inset 0 0 0 1px #70b35f}.bpi-hidden{display:none!important}.bpi-mirror-empty{color:var(--bpi-text-muted)}.bpi-mirror-token{display:inline-flex;align-items:center;border:1px solid transparent;border-radius:5px;padding:0 3px;margin:1px 0;cursor:pointer;transition:background .12s,border-color .12s,color .12s}.bpi-mirror-token:hover{background:#345a3b;border-color:#5c8d63;color:#fff}.bpi-mirror-token.bpi-linked{background:#315f83;border-color:#76a9ff;color:#fff}
@@ -1248,7 +1260,17 @@ function injectBpiStyles() {
.bpi-batch-bar{flex:none;gap:8px;padding:6px 8px;margin-bottom:6px;border:1px solid var(--bpi-border-2);border-radius:6px;background:var(--bpi-surface-3)}.bpi-filter-active{background:#365f84;border-color:#5792c4;color:#fff}.bpi-star{color:var(--bpi-star-off)}.bpi-star.bpi-starred{color:var(--bpi-star-on);border-color:#8f772f}.bpi-result.bpi-result-selected{background:var(--bpi-row-selected-bg);outline:1px solid var(--bpi-link-text)}.bpi-result-star{font-size:14px;color:var(--bpi-star-off);align-self:center}.bpi-result-star.bpi-starred{color:var(--bpi-star-on)}
.bpi-quick-section{flex:none;border:1px solid #6b5594;border-radius:7px;background-color:var(--bpi-quick-section-bg);overflow:hidden}.bpi-quick-head{display:flex;align-items:center;gap:7px;padding:5px 8px;background:var(--bpi-head-bg);color:var(--bpi-quick-head-text);font-weight:700;flex-wrap:wrap}.bpi-quick-hint{margin-left:auto;color:var(--bpi-quick-hint-text);font-size:10px;font-weight:400}.bpi-quick-target{padding:0 8px 6px;font-size:11px;color:var(--bpi-text-muted)}.bpi-quick-target-linked{color:var(--bpi-link-text)}.bpi-quick-row{display:flex;gap:6px;align-items:flex-start;padding:6px 8px}.bpi-quick-input{flex:1;min-width:0;box-sizing:border-box;height:44px;min-height:44px;max-height:140px;overflow-y:auto;resize:vertical;border:1px solid var(--bpi-border-2);border-radius:5px;background:var(--bpi-input-bg);color:var(--bpi-input-text);padding:5px 7px;outline:none;font:12px/1.55 Arial,sans-serif}.bpi-quick-input:focus{box-shadow:inset 0 0 0 1px #a98be0}.bpi-quick-row .bpi-button{flex:none}
.bpi-drag-handle{flex:none;cursor:grab;color:var(--bpi-handle-text);font-size:11px;line-height:1;user-select:none;padding:1px 2px;border-radius:3px}.bpi-drag-handle:hover{color:var(--bpi-handle-hover);background:var(--bpi-handle-hover-bg)}.bpi-drag-handle:active{cursor:grabbing}
.bpi-row.bpi-dragging,.bpi-english-token.bpi-dragging{opacity:.45}.bpi-english-token.bpi-dragging{cursor:grabbing}
/* 拖动中:明细表不用淡化(降透明度会把字看糊),改成左侧实心色条 + 高亮底 +
亮色文字,一眼看得出「就是这一行在被拖」。节点那边只留抬起阴影,不加底色 */
.bpi-row.bpi-dragging{background-color:var(--bpi-drag-row-bg);background-image:none;box-shadow:inset 3px 0 0 0 var(--bpi-drag-row-bar);outline:1px solid var(--bpi-drag-row-bar);outline-offset:-1px}
.bpi-row.bpi-dragging .bpi-cell{color:var(--bpi-drag-row-text)}
.bpi-row.bpi-dragging .bpi-drag-handle,.bpi-row.bpi-dragging .bpi-hide-btn{color:var(--bpi-drag-row-text)}
.bpi-english-token.bpi-dragging{opacity:.45;cursor:grabbing}
/* 拖动实时预览:被拖的那一项复制成 .bpi-drag-float 挂到 body 上跟着光标走,
原来的位置由 bpi-drag-source 占位(透明但仍参与命中测试,所以鼠标停在空位上
算「停在自己身上」,不会把落点算到别处去) */
.bpi-drag-source{opacity:0!important}
.bpi-drag-float{box-shadow:0 10px 26px rgba(0,0,0,.4);transition:transform .09s linear;cursor:grabbing;will-change:transform}
.bpi-drop-indicator{position:absolute;left:3px;right:3px;height:0;border-top:2px solid #76c9ff;box-shadow:0 0 5px rgba(118,201,255,.55);z-index:3;pointer-events:none}
.bpi-break-row{display:flex;align-items:center;gap:8px;border-top:1px solid var(--bpi-border-3);background:var(--bpi-break-bg);color:var(--bpi-break-text);padding:6px 10px;cursor:default}
.bpi-row.bpi-break-row:hover{background-color:var(--bpi-break-bg-hover);background-image:none;outline:0;color:#fff}
@@ -1268,7 +1290,34 @@ function injectBpiStyles() {
.bpi-hidden-term{text-decoration:line-through;color:var(--bpi-text-faint)}
.bpi-hide-btn-off{color:var(--bpi-badge-warn)}
.bpi-eye-off{color:var(--bpi-badge-warn)}
.bpi-chip-hide{position:absolute;top:2px;right:3px;display:none;cursor:pointer;padding:1px 2px;border-radius:999px;background:var(--bpi-chip-hide-bg);border:1px solid var(--bpi-border-2);color:var(--bpi-link-text);line-height:1;z-index:2}.bpi-token-card:hover .bpi-chip-hide{display:inline-flex}.bpi-chip-hide:hover{background:var(--bpi-primary-bg);border-color:var(--bpi-primary-border);color:#fff}
.bpi-chip-hide{position:absolute;bottom:2px;right:3px;display:none;cursor:pointer;padding:1px 2px;border-radius:999px;background:var(--bpi-chip-hide-bg);border:1px solid var(--bpi-border-2);color:var(--bpi-link-text);line-height:1;z-index:2}.bpi-token-card:hover .bpi-chip-hide{display:inline-flex}.bpi-chip-hide:hover{background:var(--bpi-primary-bg);border-color:var(--bpi-primary-border);color:#fff}
/* 删除的 × 是选中那张卡的右上角角标,和左上角的眼睛对称;不再跟英文标签挤在一行 */
.bpi-mirror-delete{position:absolute;top:2px;right:3px;cursor:pointer;padding:1px 3px;border-radius:999px;background:var(--bpi-chip-hide-bg);border:1px solid var(--bpi-border-2);color:var(--bpi-text-muted);font-size:11px;line-height:1;z-index:2}
.bpi-mirror-delete:hover{color:var(--bpi-status-error);border-color:var(--bpi-status-error)}
/* 删除标签的消失动画(设置里开关,默认关):X 从四角向心长出 → 颜色从中心铺满
→ 上下压两条灰边 → 整块从左往右擦掉。只加在正在删的那张卡上,别的卡不受影响 */
.bpi-token-card.bpi-deleting{--bpi-del-color:#a78bfa;--bpi-del-bar-color:#5a5a5a;overflow:hidden;pointer-events:none;clip-path:inset(0 0 0 0 round 5px);transition:clip-path .35s cubic-bezier(.4,0,.2,1)}
.bpi-token-card.bpi-deleting.bpi-del-wipe{clip-path:inset(0 0 0 100% round 5px)}
.bpi-del-stage{position:absolute;inset:0;pointer-events:none}
.bpi-del-half{position:absolute;width:var(--bpi-del-len,60px);height:2px;background-color:var(--bpi-del-color);transition:transform .16s cubic-bezier(.4,0,.2,1),height .4s cubic-bezier(.4,0,.2,1)}
.bpi-del-half-a1{left:0;top:0;transform-origin:0 0;transform:rotate(var(--bpi-del-angle,30deg)) scaleX(0)}
.bpi-del-half-a2{right:0;bottom:0;transform-origin:100% 100%;transform:rotate(var(--bpi-del-angle,30deg)) scaleX(0)}
.bpi-del-half-b1{right:0;top:0;transform-origin:100% 0;transform:rotate(calc(-1 * var(--bpi-del-angle,30deg))) scaleX(0)}
.bpi-del-half-b2{left:0;bottom:0;transform-origin:0 100%;transform:rotate(calc(-1 * var(--bpi-del-angle,30deg))) scaleX(0)}
.bpi-token-card.bpi-del-grow .bpi-del-half-a1{transform:rotate(var(--bpi-del-angle,30deg)) scaleX(1)}
.bpi-token-card.bpi-del-grow .bpi-del-half-a2{transform:rotate(var(--bpi-del-angle,30deg)) scaleX(1)}
.bpi-token-card.bpi-del-grow .bpi-del-half-b1{transform:rotate(calc(-1 * var(--bpi-del-angle,30deg))) scaleX(1)}
.bpi-token-card.bpi-del-grow .bpi-del-half-b2{transform:rotate(calc(-1 * var(--bpi-del-angle,30deg))) scaleX(1)}
.bpi-token-card.bpi-del-spread .bpi-del-half{height:var(--bpi-del-fill,60px)}
.bpi-del-cover{position:absolute;inset:0;background-color:var(--bpi-del-color);clip-path:inset(50% 50% 50% 50%);transition:clip-path .4s cubic-bezier(.4,0,.2,1);z-index:3}
.bpi-token-card.bpi-del-spread .bpi-del-cover{clip-path:inset(0 0 0 0)}
.bpi-del-bar{position:absolute;left:0;right:0;height:0;background-color:var(--bpi-del-bar-color);transition:height .1s ease;z-index:5}
.bpi-del-bar-top{top:0}.bpi-del-bar-bottom{bottom:0}
.bpi-token-card.bpi-del-wipe .bpi-del-bar{height:var(--bpi-del-bar-h,10px)}
/* 添加标签的出场动画:新卡片从左往右展开,旁边的卡片由 FLIP 滑开让位。
带宽高一起淡入,纯靠 clip-path 硬揭开会显得突然 */
@keyframes bpi-card-insert{from{clip-path:inset(0 100% 0 0 round 5px);opacity:.45}to{clip-path:inset(0 0 0 0 round 5px);opacity:1}}
.bpi-token-card.bpi-inserting{animation:bpi-card-insert .42s cubic-bezier(.32,.72,.28,1)}
.bpi-token-line{display:flex;flex-wrap:wrap;align-items:flex-end;gap:2px 0}
.bpi-token-card{position:relative;display:inline-flex;flex-direction:column;align-items:flex-start;max-width:100%;border:1px solid var(--bpi-border-3);border-radius:5px;background:var(--bpi-surface-3);padding:1px 5px;margin:2px 3px 2px 0;vertical-align:top;cursor:pointer}
.bpi-token-card:hover{border-color:var(--bpi-border-2)}
@@ -1278,6 +1327,11 @@ function injectBpiStyles() {
.bpi-token-card.bpi-card-linked .bpi-token-card-zh{color:#fff}
.bpi-token-card.bpi-card-linked .bpi-english-token{background:transparent;border-color:transparent;box-shadow:none;color:#fff}
.bpi-token-card-zh{min-height:15px;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--bpi-text-muted);font:11px/1.35 Arial,sans-serif}
/* 落点提示画在整张卡片上(英文行 + 中文小块一起亮)。必须排在
.bpi-card-linked 之后:两条规则特异度相同,靠后定义的才盖得住选中态
自己的 box-shadow,否则拖到已选中的卡片上看不出插入位置 */
.bpi-token-card.bpi-drop-before{box-shadow:-3px 0 0 0 #76c9ff,0 0 6px rgba(118,201,255,.45)}
.bpi-token-card.bpi-drop-after{box-shadow:3px 0 0 0 #76c9ff,0 0 6px rgba(118,201,255,.45)}
.bpi-category-content{display:flex;flex-wrap:wrap;gap:2px 3px}
.bpi-break-chip{position:relative;display:inline-flex;align-items:center;gap:3px;border:1px dashed var(--bpi-break-border);border-radius:5px;background:var(--bpi-break-bg);color:var(--bpi-break-text);padding:0 5px;margin:1px 0;cursor:grab;user-select:none;font-family:Consolas,monospace}
.bpi-break-chip:hover,.bpi-break-chip.bpi-drop-target{background:var(--bpi-break-bg-hover);border-color:var(--bpi-break-text);color:#fff}
@@ -1385,6 +1439,11 @@ function injectBpiStyles() {
.bpi-about-modal{width:min(460px,calc(100vw - 32px))}.bpi-about-name{margin-bottom:7px;color:var(--bpi-text);font-weight:700}.bpi-config-note{color:var(--bpi-text-muted);font-size:10px;word-break:break-all}
/* 同一句说明变成警告时用:只换颜色,不动字号字重,免得换行数变了把下面的表单顶走 */
.bpi-config-note-warn{color:var(--bpi-status-error)}
/* 「获取模型」:输入框照旧独占一行宽度,按钮挤在右边不换行 */
.bpi-model-line{display:flex;gap:6px;align-items:stretch;min-width:0}
.bpi-model-line input{flex:1 1 auto;min-width:0}
.bpi-model-line .bpi-button{flex:none;white-space:nowrap;background-color:var(--bpm-accent);border-color:var(--bpm-accent-border);color:#fff}
.bpi-model-line .bpi-button:hover{background-color:var(--bpm-accent-hover);border-color:var(--bpm-accent-border);color:#fff}
.bpi-help{position:relative;display:inline-flex;align-items:center;justify-content:center;width:13px;height:13px;margin-left:5px;border:1px solid var(--bpi-border);border-radius:50%;color:var(--bpi-text-muted);font:10px/1 Arial,sans-serif;vertical-align:middle;cursor:help;user-select:none}
.bpi-help:hover,.bpi-help:focus{color:var(--bpi-text);border-color:var(--bpi-border-2)}
.bpi-help-pop{position:absolute;left:50%;bottom:calc(100% + 6px);transform:translateX(-50%);z-index:80;display:none;box-sizing:border-box;width:290px;max-width:70vw;padding:7px 9px;border:1px solid var(--bpi-border-2);border-radius:6px;background:var(--bpi-surface-modal);color:var(--bpi-text-muted);font:11px/1.65 Arial,sans-serif;white-space:pre-line;text-align:left;cursor:default}
@@ -1410,10 +1469,25 @@ function injectBpiStyles() {
.bpm-loading{padding:24px;text-align:center;color:var(--bpi-text-faint)}
.bpi-form-actions{display:flex;justify-content:flex-end;gap:7px;margin-top:12px;flex-wrap:wrap}
/* 助手设置在 ComfyUI「设置」面板里:原生那一行是「标签 + 控件」,把标签收掉、控件占满整行 */
.bpi-settings-form{box-sizing:border-box;width:100%;padding:2px 0 6px}.bpi-settings-form h3{margin:0 0 10px;font-size:15px}
div:has(> .form-input > div > .bpi-settings-form){align-items:flex-start}
div:has(> .form-input > div > .bpi-settings-form) > .form-label{display:none}
div:has(> .form-input > div > .bpi-settings-form) > .form-input{flex:1 1 0%;min-width:0}
.bpi-settings-form{box-sizing:border-box;width:100%;padding:2px 0 6px}
/* 设置面板每一项 = 名称列 + 控件列,名称列宽度跟着名字长短走:插件这两项一个叫
「通用」一个叫「助手设置」,字数不同,右边的内容就被推得差了一格。
让名称列不占位、控件列占满,两块都从最左边开始,标题由各自的 h3 显示。
只在「我们的块不在第一列」时才生效,结构对不上时不会把内容自己藏掉。 */
*:has(> :not(:first-child) > .bpi-settings-form){align-items:flex-start}
*:has(> :not(:first-child) > .bpi-settings-form) > :first-child{display:none}
*:has(> :not(:first-child) > .bpi-settings-form) > :not(:first-child){flex:1 1 0%;min-width:0;justify-content:flex-start}
/* ComfyUI 给控件列自带 justify-end:宽度一占满就会把内容推到最右,这里改回靠左 */
*:has(> .bpi-settings-form){flex:1 1 0%;min-width:0}
/* 设置面板里的可展开分组:直接用原生 details,三角自己画,展开状态由 open 属性管 */
.bpi-fold{grid-column:1 / -1;margin-top:8px;border:1px solid var(--bpi-border-2);border-radius:6px}
.bpi-fold>summary{display:flex;align-items:center;gap:6px;padding:7px 10px;font-size:12px;font-weight:600;color:var(--bpi-text);cursor:pointer;list-style:none;user-select:none}
.bpi-fold>summary::-webkit-details-marker{display:none}
.bpi-fold>summary::before{flex:none;content:"";width:0;height:0;border-left:5px solid var(--bpi-text-muted);border-top:4px solid transparent;border-bottom:4px solid transparent;transition:transform .15s ease}
.bpi-fold[open]>summary::before{transform:rotate(90deg)}
.bpi-fold>summary:hover{background-image:linear-gradient(var(--bpi-row-hover-overlay),var(--bpi-row-hover-overlay))}
.bpi-fold-body{padding:8px 10px 10px;border-top:1px solid var(--bpi-border-3);display:flex;flex-direction:column;gap:8px}
.bpi-fold-note{font-size:10px;color:var(--bpi-text-faint)}
.bpi-switch-row{display:flex;align-items:center;gap:8px;cursor:pointer;user-select:none;width:fit-content}
.bpi-switch-row input{position:absolute;width:0;height:0;opacity:0;margin:0}
.bpi-switch-track{position:relative;flex:0 0 auto;width:34px;height:18px;border-radius:9px;background-color:var(--bpi-switch-off);border:1px solid var(--bpi-switch-off-border);transition:background-color .16s ease,border-color .16s ease}
@@ -1487,6 +1561,7 @@ export {
importTags,
bulkUpdateTags,
injectBpiStyles,
listAssistantModels,
listModelNames,
listSavedPrompts,
loadDictionary,
+260
View File
@@ -0,0 +1,260 @@
// 右下角贴边堆叠 Toast(临时提示)
// 模板原件:.workbuddy/refs/toast-template.html —— 动画、贴边造型、堆叠与防卡死写法照搬。
// 和右上角那套 js/bpi_notify.js 是两套,互不干扰:那边是双层纸 + 从上往下 + 展开正文,
// 这边是贴着右下角长出来、强调色遮罩从左往右刷过、整条向右滑走。
import { t } from "./i18n.js";
const STYLE_ID = "bpi-toast-style";
// 和右上角那套一样,开关只存本地:这是表现层的事,不进后端 assistant_settings
const STORAGE_KEY = "bpi.toast.v1";
// 默认开:逐条提示本来就在用,关掉才会退回状态栏
export function toastEnabled() {
try {
return window.localStorage.getItem(STORAGE_KEY) !== "0";
} catch (error) {
return true;
}
}
export function setToastEnabled(next) {
try {
window.localStorage.setItem(STORAGE_KEY, next ? "1" : "0");
} catch (error) {
/* 隐私模式下写不进去就算了,本次会话内仍按传入值生效 */
}
}
// JS 与 CSS 必须同步:COVER_DURATION 是 .bpi-toast-cover 的时长,SLIDE_DURATION 是 .is-out 的时长
const MAX_VISIBLE = 5;
const AUTO_DISMISS = 3000;
const COVER_DURATION = 180;
const SLIDE_DURATION = 320;
const REMOVE_DELAY = SLIDE_DURATION + 40;
// 同一车道(lane)最多同时挂几条:满了就顶掉最旧的一条。
// 车道是给「一批同类消息排队」准备的(试过给批量翻译用,已撤),目前没人传 lane
const LANE_MAX = 3;
// 被顶掉之前至少要显示这么久,免得结果来得太快、字还没看清就被刷走
const LANE_MIN_HOLD = 1200;
// 一个操作一类色,别都挤在蓝里:
// 蓝 = 改内容(应用改写 / 权重 / 隐藏恢复 / 词条保存)、紫 = 插入、红 = 删除、
// 青 = 移动、灰 = 撤销重做、绿 = 翻译成功、橙 = 重复开关
export const TOAST_ACCENTS = {
edit: "#60a5fa",
insert: "#a78bfa",
remove: "#e06c75",
move: "#22d3ee",
history: "#94a3b8",
translate: "#34d399",
duplicate: "#fbbf24",
};
// 图标是塞进 24×24 viewBox 的内联 SVG 片段,颜色靠 currentColor 吃 --bpi-toast-accent
const ICONS = {
duplicate:
'<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>',
translate:
'<path d="M5 8L10 13M4 14L10 8L12 5M2 5H14M7 2H8M12.913 17H20.087M12.913 17L11 21M12.913 17L15.7783 11.009C16.0092 10.5263 16.1246 10.2849 16.2826 10.2086C16.4199 10.1423 16.5801 10.1423 16.7174 10.2086C16.8754 10.2849 16.9908 10.5263 17.2217 11.009L20.087 17M20.087 17L22 21"/>',
notice: '<circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16h.01"/>',
edit: '<path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4 12.5-12.5z"/>',
insert: '<path d="M12 5v14M5 12h14"/>',
remove: '<path d="M4 7h16M9 7V4h6v3"/><path d="M6 7l1 13h10l1-13"/>',
move: '<path d="M4 12h16"/><path d="M8 8l-4 4 4 4M16 8l4 4-4 4"/>',
history: '<path d="M3.5 12a8.5 8.5 0 1 1 2.6 6.1"/><path d="M3 5v5h5"/><path d="M12 8v4l3 2"/>',
};
const CLOSE_SVG =
'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>';
// 强调线(::before)、图标、抹开遮罩三处共用这一个变量
const CSS = `
.bpi-toast-stack{position:fixed;right:0;bottom:0;width:340px;max-width:calc(100vw - 28px);display:flex;flex-direction:column-reverse;gap:10px;z-index:9999;pointer-events:none}
/* 亮色下不用那么重的黑影 */
[data-bpi-theme="light"] .bpi-toast-stack{--bpi-toast-shadow:0 10px 26px rgba(0,0,0,.14),0 2px 6px rgba(0,0,0,.10)}
.bpi-toast{position:relative;display:flex;align-items:center;gap:10px;padding:13px 16px;background:var(--bpi-surface-modal,#20252d);border:1px solid var(--bpi-border,#3a4250);border-right:0;border-radius:8px 0 0 8px;box-shadow:var(--bpi-toast-shadow,0 10px 30px rgba(0,0,0,.5),0 2px 6px rgba(0,0,0,.3));font-size:13px;line-height:1.45;color:var(--bpi-text,#e6edf7);pointer-events:auto;overflow:hidden;opacity:0;transform:translateX(100%);transition:transform .45s cubic-bezier(.16,1,.3,1),opacity .35s ease;will-change:transform,opacity}
.bpi-toast.is-in{opacity:1;transform:translateX(0)}
/* 位置被上下顶动时的平滑位移;必须写在 .is-out 之前,退场那条要能盖过它 */
.bpi-toast.bpi-flip{transition:transform .35s cubic-bezier(.16,1,.3,1)}
/* 退场全程不透明:淡出会让人觉得是「直接消失」 */
.bpi-toast.is-out{opacity:1;transform:translateX(100%);transition:transform .32s cubic-bezier(.55,0,.8,.4)}
.bpi-toast::before{content:"";position:absolute;left:0;top:0;bottom:0;width:3px;border-radius:8px 0 0 8px;background:var(--bpi-toast-accent,#fbbf24);z-index:1}
.bpi-toast-cover{position:absolute;inset:0;border-radius:8px 0 0 8px;background:var(--bpi-toast-accent,#fbbf24);transform:translateX(-101%);transition:transform .18s cubic-bezier(.45,0,.2,1);z-index:5;pointer-events:none;will-change:transform}
.bpi-toast.is-covering .bpi-toast-cover{transform:translateX(0)}
.bpi-toast-icon{flex:0 0 20px;width:20px;height:20px;display:grid;place-items:center;color:var(--bpi-toast-accent,#fbbf24);position:relative;z-index:2}
.bpi-toast-text{flex:1;min-width:0;word-break:break-word;position:relative;z-index:2}
.bpi-toast-close{flex:0 0 20px;width:20px;height:20px;display:grid;place-items:center;padding:0;border:0;border-radius:4px;background:transparent;color:var(--bpi-text-muted,#aab5c5);cursor:pointer;position:relative;z-index:6;transition:background .15s ease,color .15s ease}
.bpi-toast-close:hover{background:var(--bpi-handle-hover-bg,#2b3a4d);color:var(--bpi-text,#e6edf7)}
@media (prefers-reduced-motion: reduce){
.bpi-toast,.bpi-toast-cover{transition-duration:.01ms !important}
}
`;
let stack = null;
function injectStyle() {
if (document.getElementById(STYLE_ID)) return;
const style = document.createElement("style");
style.id = STYLE_ID;
style.textContent = CSS;
document.head.appendChild(style);
}
function ensureStack() {
if (stack && stack.isConnected) return stack;
injectStyle();
stack = document.createElement("div");
stack.className = "bpi-toast-stack";
document.body.appendChild(stack);
return stack;
}
// FLIP:记下每条当前的位置,等布局变了再让它们从旧位置滑到新位置,避免「闪现」
function snapshotTops(host, skip) {
const tops = new Map();
Array.from(host.children).forEach((el) => {
if (el !== skip) tops.set(el, el.getBoundingClientRect().top);
});
return tops;
}
function reflow(host, tops) {
tops.forEach((top, el) => {
// 只挪已经入场、又没在退场的:正在入场/退场的动自己的动画,别插手
if (!el.isConnected || el._dismissed || !el.classList.contains("is-in")) return;
const delta = top - el.getBoundingClientRect().top;
if (!delta) return;
el.style.transition = "none";
el.style.transform = `translateY(${delta}px)`;
void el.offsetWidth;
// 关键:必须把内联的 transition:none 交回 CSS,否则它一直压着 .is-out 的过渡,
// 这条之后退场就会「动画没播完直接消失」
el.style.transition = "";
el.classList.add("bpi-flip");
el.style.transform = "";
setTimeout(() => el.classList.remove("bpi-flip"), 380);
});
}
// 移除一条时让剩下的平滑补位
function dropEl(host, el) {
const tops = snapshotTops(host, el);
el.remove();
reflow(host, tops);
}
function dismiss(el, immediate = false) {
if (!el) return;
// 被顶走的分支必须排在最前面并无条件移除:
// 先判 _dismissed 的话,正在等动画的那条会一直留在 DOM 里,while 循环反复拿到它 → 卡死
if (immediate) {
el._dismissed = true;
clearTimeout(el._timer);
dropEl(el.parentNode, el);
return;
}
if (el._dismissed) return;
el._dismissed = true;
clearTimeout(el._timer);
// 补位动画可能还挂着,退场前先摘掉,别让它抢 .is-out 的过渡
el.classList.remove("bpi-flip");
el.style.transform = "";
el.style.transition = "";
el.classList.add("is-covering");
setTimeout(() => {
if (!el.isConnected) return;
el.classList.add("is-out");
setTimeout(() => {
if (el.isConnected) dropEl(el.parentNode, el);
}, REMOVE_DELAY);
}, COVER_DURATION);
}
// 车道内还活着(没被标记退场)的条目,顺序是 新 → 旧
function laneAlive(host, lane) {
return Array.from(host.children).filter((el) => el._lane === lane && !el._dismissed);
}
// 只多一条时给足停留时间;积压多了就立刻收,不然会越堆越高
function trimLane(host, lane) {
const alive = laneAlive(host, lane);
const excess = alive.length - LANE_MAX;
for (let i = 0; i < excess; i += 1) {
const victim = alive[alive.length - 1 - i];
if (!victim) break;
const wait = Math.max(0, LANE_MIN_HOLD - (Date.now() - victim._shownAt));
if (!wait || i > 0) {
dismiss(victim);
continue;
}
setTimeout(() => {
if (victim.isConnected && !victim._dismissed) dismiss(victim);
}, wait);
}
}
// message 走 t();type 决定强调色与图标,也可以直接传 accent / icon 覆盖。
// lane 相同的一批会共用 3 个位置:新的从最下面长出来,最旧的从上面被顶走。
export function showToast(message, options = {}) {
// 关掉时直接不建 DOM:调用方自己退回状态栏(返回 false 就是告诉它「我没显示」)
if (!toastEnabled()) return false;
const host = ensureStack();
const type = options.type || "";
const accent = options.accent || TOAST_ACCENTS[type] || TOAST_ACCENTS.duplicate;
const markup = options.icon || ICONS[type] || ICONS.notice;
const el = document.createElement("div");
el.className = "bpi-toast";
el.style.setProperty("--bpi-toast-accent", accent);
const cover = document.createElement("div");
cover.className = "bpi-toast-cover";
const icon = document.createElement("span");
icon.className = "bpi-toast-icon";
icon.innerHTML =
`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"` +
` stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${markup}</svg>`;
const text = document.createElement("span");
text.className = "bpi-toast-text";
text.textContent = t(message);
const close = document.createElement("button");
close.className = "bpi-toast-close";
close.type = "button";
close.title = t("Close");
close.setAttribute("aria-label", t("Close"));
close.innerHTML = CLOSE_SVG;
el.append(cover, icon, text, close);
el._lane = options.lane || "";
el._shownAt = Date.now();
// column-reverse 的主轴起点在下方,插到最前面 = 视觉最下面;旧的自然往上顶
const before = snapshotTops(host, null);
host.insertBefore(el, host.firstChild);
// 全局上限:超了取 DOM 最后一条(视觉最上面、最旧的那条)直接移除,不播动画
while (host.children.length > MAX_VISIBLE) {
dismiss(host.lastElementChild, true);
}
if (el._lane) trimLane(host, el._lane);
reflow(host, before);
// 双 rAF:确保初始样式(translateX(100%))已经渲染过一帧,否则过渡不会触发
requestAnimationFrame(() => requestAnimationFrame(() => {
if (el.isConnected) el.classList.add("is-in");
}));
close.addEventListener("click", () => dismiss(el));
el._timer = setTimeout(() => dismiss(el), AUTO_DISMISS);
return el;
}
+44 -28
View File
@@ -7,7 +7,7 @@
// · 运行时按英文原文查中文表,查不到就原样显示英文 —— 缺翻译只会退回英文,不会出现空文案
// · 「跟随 ComfyUI」读 ComfyUI 的 Comfy.Locale 设置,中文系语言走中文,其余走英文
//
// 带变量的文案(例如 `deleted “${term}”; press Ctrl+Z to undo`)没法直接整句做键,
// 带变量的文案(例如 `deleted “${term}”`)没法直接整句做键,
// 这里把「“...”」和数字统一折叠成 {} 再查表,命中后按出现顺序回填。
const STORAGE_KEY = "bpi.language.v1";
@@ -130,8 +130,8 @@ const ZH = {
"输入时保持文本编辑;失焦或点「完成」后切回标签视图",
"Switch between the English text editor and the linked tag view":
"在英文文本编辑框与联动标签视图之间切换",
"Requires a second click to clear the actual English output; after clearing, click the same button or press Ctrl+Z to undo":
"需要再点一次才会清空英文实际输出;清空后点同一个按钮或按 Ctrl+Z 可撤销",
"Requires a second click to clear the actual English output; after clearing, click the same button to undo":
"需要再点一次才会清空英文实际输出;清空后点同一个按钮撤销",
"Save the current English prompt to favorites in the user directory (a reference image can be attached)":
"把当前英文提示词保存到用户目录的收藏里(可附带参考图)",
"Hidden tags will not enter the actual output": "隐藏的标签不会进入实际输出",
@@ -193,18 +193,17 @@ const ZH = {
"Only optimizes existing English; does not translate": "只优化已有英文,不做翻译",
"press Anima stable sort by recommended categories, one row per non-empty category; natural language and BREAK/AND kept intact":
"按 Anima 推荐分类做稳定排序,每个非空分类一行;自然语言与 BREAK/AND 原样保留",
"Drag to reorder tags; or select then press Alt+↑/↓ to nudge; Ctrl+Z to undo":
"拖动可调整标签顺序;或选中后按 Alt+↑/↓ 微调;Ctrl+Z 撤销",
"applied {}; press Ctrl+Z to undo": "已应用 {};按 Ctrl+Z 可撤销",
"deleted {}; press Ctrl+Z to undo": "已删除「{}」;按 Ctrl+Z 可撤销",
"{}; press Ctrl+Z to undo": "{};按 Ctrl+Z 可撤销",
"moved {}; press Ctrl+Z to undo": "已移动「{}」;按 Ctrl+Z 可撤销",
"rewrote {}; press Ctrl+Z to undo": "已改写「{}」;按 Ctrl+Z 可撤销",
"rewrote {} tags; press Ctrl+Z to undo": "已改写 {} 个标签;按 Ctrl+Z 可撤销",
"hidden {} (excluded from actual output); can be restored anytime in the hidden section; press Ctrl+Z to undo":
"已隐藏「{}」(不计入实际输出);随时可在隐藏区恢复;按 Ctrl+Z 可撤销",
"restored {} to its original position; press Ctrl+Z to undo": "已把「{}」恢复到原位置;按 Ctrl+Z 可撤销",
"restored {} hidden tags; press Ctrl+Z to undo": "已恢复 {} 个隐藏标签;按 Ctrl+Z 可撤销",
"Drag to reorder tags; or select then press Alt+↑/↓ to nudge":
"拖动可调整标签顺序;或选中后按 Alt+↑/↓ 微调",
"applied {}": "已应用 {}",
"deleted {}": "已删除「{}」",
"moved {}": "已移动「{}」",
"rewrote {}": "已改写「{}」",
"rewrote {} tags": "已改写 {} 个标签",
"hidden {} (excluded from actual output); can be restored anytime in the hidden section":
"已隐藏「{}」(不计入实际输出);随时可在隐藏区恢复",
"restored {} to its original position": "已把「{}」恢复到原位置",
"restored {} hidden tags": "已恢复 {} 个隐藏标签",
"{} is already at the front": "「{}」已经在最前面",
"{} is already at the back": "「{}」已经在最后面",
"temporarily modified {}; not saved to dictionary": "已临时修改「{}」,未存入词库",
@@ -225,10 +224,10 @@ const ZH = {
"Hide {}: keeps it visible here (strikethrough) but excludes it from the actual output":
"隐藏「{}」:仍显示在节点里(加删除线),但不参与实际输出",
"Unhide {}: back into the actual output": "取消隐藏「{}」:重新参与实际输出",
"Hidden {}: stays visible and editable here, but excluded from the actual output; click the eye-slash to unhide; press Ctrl+Z to undo":
"已隐藏「{}」:仍显示、可照常编辑,但不参与实际输出;点眼睛斜线图标取消隐藏;按 Ctrl+Z 可撤销",
"Unhidden {}: back in the actual output; press Ctrl+Z to undo":
"已取消隐藏「{}」:重新参与实际输出;按 Ctrl+Z 可撤销",
"Hidden {}: stays visible and editable here, but excluded from the actual output; click the eye-slash to unhide":
"已隐藏「{}」:仍显示、可照常编辑,但不参与实际输出;点眼睛斜线图标取消隐藏",
"Unhidden {}: back in the actual output":
"已取消隐藏「{}」:重新参与实际输出",
"These tags stay visible above (strikethrough) but will not enter the actual output; click a tag to unhide":
"这些标签仍显示在上方(加删除线),但不会进入实际输出;点击标签取消隐藏",
"Click to unhide {}": "点击取消隐藏「{}」",
@@ -259,9 +258,9 @@ const ZH = {
"换行|拖到某个标签上可移动位置;点 × 删除(上下两行合并)",
"Delete this line break": "删除这个换行",
"Enter tags first, then insert a line break": "先输入标签,再插入换行",
"Inserted a line break; press Ctrl+Z to undo": "已插入换行;按 Ctrl+Z 撤销",
"Deleted a line break; press Ctrl+Z to undo": "已删除换行;按 Ctrl+Z 撤销",
"Moved the line break; press Ctrl+Z to undo": "已移动换行;按 Ctrl+Z 撤销",
"Inserted a line break": "已插入换行",
"Deleted a line break": "已删除换行",
"Moved the line break": "已移动换行",
"Check this machine translation; use the toolbar above the table to add several entries to the personal dictionary at once":
"勾选这条机器翻译;用表格上方的工具条可以一次把多条加入个人词库",
"Drag to resize the two columns; double-click to reset to the default ratio": "拖动调整左右两栏宽度;双击恢复默认比例",
@@ -431,6 +430,11 @@ const ZH = {
"Ollama only accepts a loopback address on this machine; anything else is rejected before a request is sent.":
"Ollama 只能填本机回环地址;其它地址在发出请求前就会被拒绝。",
"Model Name": "模型名称",
"Fetch Models": "获取模型",
"Fetch Models ({})": "获取模型({})",
"Fetching...": "获取中…",
"Fetched {} models": "已获取 {} 个模型",
Close: "关闭",
"Use LM Studio Local Preset": "使用 LM Studio 本地预设",
"Connects to localhost:1234 by default; no external API required.": "默认连接 localhost:1234,不需要外部接口。",
"LM Studio default URL filled; select a loaded model ID, then Save & Test": "已填入 LM Studio 默认地址;选择已加载的模型 ID 后保存并测试",
@@ -463,8 +467,16 @@ const ZH = {
"Follow ComfyUI language setting": "跟随 ComfyUI 语言设置",
"Choose the language for this plugin's own panels. \"Follow ComfyUI\" reads the ComfyUI language setting; \"Chinese\" and \"English\" force one. Applied to open panels right away; reload the page if anything still shows the old language.":
"选择本插件面板的语言。「跟随 ComfyUI 语言设置」会随 ComfyUI 的语言切换;「中文」「英文」为强制指定。已打开的面板会立即更新;若个别位置仍是旧语言,刷新页面即可。",
"Appearance & Language": "语言与外观",
"Appearance and language saved": "外观与语言已保存",
"Notification popup (top right)": "右上角通知弹窗",
"Operation results show as a popup in the top-right corner instead of the status line.": "操作结果改用右上角弹窗显示,不再写在状态栏上。",
"Notifications moved to the top-right popup": "已改为右上角弹窗提示",
"Notifications back in the status bar": "已改回状态栏提示",
// 弹窗标题:按提示类型给一个短词,消息本身放展开后的正文里
"Done": "已完成",
"Something went wrong": "出错了",
"Working...": "处理中",
"Notice": "提示",
// ── 标签来源 / 分类 / 模式 ──────────────────────────────────────────
"Inspector assistant": "检查器助手",
@@ -635,7 +647,7 @@ const ZH = {
"No matching favorites.": "没有匹配的收藏。",
"No favorites yet. Click the star button on a node to save the current prompt.":
"还没有收藏。点节点上的星标按钮即可保存当前提示词。",
"This will overwrite node #{} prompt. Cannot be undone with Ctrl+Z.": "这会覆盖节点 #{} 的提示词,Ctrl+Z 无法撤销。",
"This will overwrite node #{} prompt. This cannot be undone.": "这会覆盖节点 #{} 的提示词,此操作无法撤销。",
"Loaded to node #{}": "已载入到节点 #{}",
"Delete {}? Reference image will be deleted too.": "删除「{}」?参考图也会一并删除。",
"Node #{}": "节点 #{}",
@@ -679,10 +691,14 @@ const ZH = {
"「{}」第 {} / {} 处;再点一次跳下一处,双击删除这一处",
"Click a duplicate chip once to step to it before double-clicking to delete":
"先单击一次重复胶囊定位到某一处,再双击才会删除",
"{} now unique: only the first occurrence enters the actual output; press Ctrl+Z to undo":
"「{}」已设为唯一:只有第一次出现进入实际输出;按 Ctrl+Z 可撤销",
"{} no longer unique: all occurrences enter the actual output again; press Ctrl+Z to undo":
"「{}」已取消唯一:所有重复项重新进入实际输出;按 Ctrl+Z 可撤销",
"{} now unique": "「{}」已设为唯一",
"{} no longer unique": "「{}」已取消唯一",
"Bottom-right toast": "右下角提示条",
"Bottom-right toast on": "已开启右下角提示条",
"Bottom-right toast off": "已关闭右下角提示条,提示回到状态栏",
"Per-operation feedback (translation, tag edits, duplicate toggle) shows as a small bar stacked in the bottom-right corner. Turn it off to keep everything in the status line and save a bit of CPU.":
"逐条操作结果(翻译、标签增删改移、重复开关)用右下角堆叠的小条显示;关掉就全部回到状态栏,能省一点性能开销。",
"added {}": "已添加「{}」",
"Query: {} | {} is on: only the first occurrence reaches the actual output": "查询「{}」|已开「{}」:只有第一次出现进入实际输出",
"keep only the first {}": "只保留第一次出现的「{}」",
"restore duplicates of {}": "恢复「{}」的重复项",
+301 -11
View File
@@ -3,6 +3,15 @@ import { normalizeKey, validateTranslationResult } from "./parser.js";
import { mergeImportAsAliases, previewImport, toggleFavorite } from "./dictionary_tools.js";
import { panelSyncHub } from "./panel_sync.js";
import { installBpiWheelGuard } from "./wheel_guard.js";
import { notifyEnabled, setNotifyEnabled } from "./bpi_notify.js";
import { setToastEnabled, toastEnabled } from "./bpi_toast.js";
import {
dragPreviewNodeEnabled,
dragPreviewTableEnabled,
setDragPreviewNodeEnabled,
setDragPreviewTableEnabled,
} from "./bpi_drag_preview.js";
import { deleteAnimNodeEnabled, setDeleteAnimNodeEnabled } from "./bpi_delete_anim.js";
import {
MANAGER_OPEN_EVENT,
MANAGER_TAB_ID,
@@ -24,6 +33,7 @@ import {
bulkUpdateTags,
applyBpiAppearance,
injectBpiStyles,
listAssistantModels,
listSavedPrompts,
loadDictionary,
loadPreferences,
@@ -51,6 +61,9 @@ const SECTIONS = [
["favorites", "Favorites"],
];
// 「跟随选中节点」的开关状态:默认关,关着就是原来只能在下拉里选节点的行为
const FOLLOW_SELECTION_KEY = "bpi.followSelection.v1";
const manager = {
data: { tags: [], builtin: [], user: [], packs: [] },
preferences: loadPreferences(),
@@ -584,17 +597,53 @@ function openImportPreview(payload) {
modal.addEventListener("mousedown", (event) => event.stopPropagation());
}
// 设置面板每一项 = 名称列 + 控件列,名称列宽度跟着设置项名字长短走:
// 插件这两项一个「通用」一个「助手设置」,字数不同,右边的内容就被推得差了一格。
// CSS 里已经用 :has() 处理过一次,这里再兜一次——面板重建后内联样式会丢,
// 而设置面板每次打开都会重新调用下面的 control,正好顺势对齐一次。
// 只认「恰好两列、且第二列装着我们内容」的那一行,结构对不上就不动,免得误伤别的元素。
function alignSettingRow(node) {
let row = node.parentElement;
while (row && row !== document.body) {
if (row.children.length === 2 && row.children[1].contains(node)) break;
row = row.parentElement;
}
if (!row || row === document.body) return;
const [name, control] = row.children;
name.style.display = "none";
control.style.flex = "1 1 0%";
control.style.minWidth = "0";
// ComfyUI 给控件列自带 justify-end:宽度一占满,它反而把内容整个推到右边。
// 改回靠左,并让包着我们的那一层也占满,否则内容仍会缩在右侧。
control.style.justifyContent = "flex-start";
if (node.parentElement && node.parentElement !== control) {
node.parentElement.style.flex = "1 1 0%";
node.parentElement.style.minWidth = "0";
}
}
function alignWhenMounted(node, frames = 30) {
if (node.isConnected) {
alignSettingRow(node);
return;
}
if (frames > 0) requestAnimationFrame(() => alignWhenMounted(node, frames - 1));
}
// 外观 / 语言从助手设置里拆出来,和它并列挂在「设置」面板的插件分类下。
// 改动立刻生效并单独保存,不需要去点助手设置的保存按钮。
let appearanceSettingsNode = null;
function appearanceControl() {
if (appearanceSettingsNode) return appearanceSettingsNode;
if (appearanceSettingsNode) {
alignWhenMounted(appearanceSettingsNode);
return appearanceSettingsNode;
}
appearanceSettingsNode = element("div", "bpi-settings-form");
appearanceSettingsNode.appendChild(element("h3", "", "Appearance & Language"));
const loading = element("div", "bpm-loading", "Loading settings...");
appearanceSettingsNode.appendChild(loading);
buildAppearanceForm(appearanceSettingsNode, loading);
alignWhenMounted(appearanceSettingsNode);
return appearanceSettingsNode;
}
@@ -641,7 +690,125 @@ async function buildAppearanceForm(host, loading) {
languageSelect.value = config.language || "auto";
const languageNote = element("div", "bpi-config-note", "Choose the language for this plugin's own panels. \"Follow ComfyUI\" reads the ComfyUI language setting; \"Chinese\" and \"English\" force one. Applied to open panels right away; reload the page if anything still shows the old language.");
languageNote.style.gridColumn = "1 / -1";
form.append(languageLabel, languageSelect, languageNote, status);
// 「跟随选中节点」直接长在「通用」这一项里,排在语言设置下面。
// 单独注册成一个设置项的话,ComfyUI 会按分类名给各项排序,怎么调都排不到想要的位置。
const followRow = element("label", "bpi-switch-row bpi-switch-accent");
followRow.style.gridColumn = "1 / -1";
const followToggle = element("input", "bpi-switch");
followToggle.type = "checkbox";
followToggle.checked = followSelectionEnabled();
const followTrack = element("span", "bpi-switch-track");
followTrack.appendChild(element("span", "bpi-switch-thumb"));
followRow.append(followToggle, followTrack, element("span", "bpi-switch-text", "点击节点时跟随切换"));
followToggle.addEventListener("change", () => setFollowSelectionEnabled(followToggle.checked));
const followNote = element("div", "bpi-config-note", "开:在画布上点一个「双语提示词检查器」节点,侧边栏的「标签管理」就切到它。关:只能在「标签管理」的节点下拉里手动选。");
followNote.style.gridColumn = "1 / -1";
form.append(languageLabel, languageSelect, languageNote, followRow, followNote, status);
// 开:操作提示改成右上角弹窗;关:还是写回明细表上方那条状态文字
const fold = element("details", "bpi-fold");
const foldBody = element("div", "bpi-fold-body");
// 最上面一个总开关:一次把下面这几个弹窗 / 提示条 / 预览 / 动画全打开或全关掉
const masterRow = element("label", "bpi-switch-row bpi-switch-accent");
const masterSwitch = element("input", "bpi-switch");
masterSwitch.type = "checkbox";
const masterTrack = element("span", "bpi-switch-track");
masterTrack.appendChild(element("span", "bpi-switch-thumb"));
masterRow.append(masterSwitch, masterTrack, element("span", "bpi-switch-text", "全部开启"));
const masterNote = element("div", "bpi-fold-note", "小孩子才做选择,大人当然选择全都要!😁");
const masterNoteTail = element("div", "bpi-fold-note", "如果显存不够,或者电脑资源比较紧张,可以适当开启或关闭。动画会吃一小部分电脑性能。");
const popupRow = element("label", "bpi-switch-row bpi-switch-accent");
const popupSwitch = element("input", "bpi-switch");
popupSwitch.type = "checkbox";
popupSwitch.checked = notifyEnabled();
const popupTrack = element("span", "bpi-switch-track");
popupTrack.appendChild(element("span", "bpi-switch-thumb"));
popupRow.append(popupSwitch, popupTrack, element("span", "bpi-switch-text", "Notification popup (top right)"));
popupSwitch.addEventListener("change", () => {
setNotifyEnabled(popupSwitch.checked);
setText(status, popupSwitch.checked ? "Notifications moved to the top-right popup" : "Notifications back in the status bar");
status.dataset.kind = "ok";
});
// 右下角那套也一样给个总开关:关掉就退回状态栏,电脑省一点开销
const toastRow = element("label", "bpi-switch-row bpi-switch-accent");
const toastSwitch = element("input", "bpi-switch");
toastSwitch.type = "checkbox";
toastSwitch.checked = toastEnabled();
const toastTrack = element("span", "bpi-switch-track");
toastTrack.appendChild(element("span", "bpi-switch-thumb"));
toastRow.append(toastSwitch, toastTrack, element("span", "bpi-switch-text", "Bottom-right toast"));
toastSwitch.addEventListener("change", () => {
setToastEnabled(toastSwitch.checked);
setText(status, toastSwitch.checked ? "Bottom-right toast on" : "Bottom-right toast off");
status.dataset.kind = "ok";
});
// 拖动实时预览:默认关,节点标签区和明细表各一个开关,互不影响
const nodeDragRow = element("label", "bpi-switch-row bpi-switch-accent");
const nodeDragSwitch = element("input", "bpi-switch");
nodeDragSwitch.type = "checkbox";
nodeDragSwitch.checked = dragPreviewNodeEnabled();
const nodeDragTrack = element("span", "bpi-switch-track");
nodeDragTrack.appendChild(element("span", "bpi-switch-thumb"));
nodeDragRow.append(nodeDragSwitch, nodeDragTrack, element("span", "bpi-switch-text", "拖动实时预览(节点标签区)"));
nodeDragSwitch.addEventListener("change", () => {
setDragPreviewNodeEnabled(nodeDragSwitch.checked);
setText(status, nodeDragSwitch.checked ? "节点标签区拖动实时预览已开" : "节点标签区拖动实时预览已关");
status.dataset.kind = "ok";
});
const tableDragRow = element("label", "bpi-switch-row bpi-switch-accent");
const tableDragSwitch = element("input", "bpi-switch");
tableDragSwitch.type = "checkbox";
tableDragSwitch.checked = dragPreviewTableEnabled();
const tableDragTrack = element("span", "bpi-switch-track");
tableDragTrack.appendChild(element("span", "bpi-switch-thumb"));
tableDragRow.append(tableDragSwitch, tableDragTrack, element("span", "bpi-switch-text", "拖动实时预览(明细表)"));
tableDragSwitch.addEventListener("change", () => {
setDragPreviewTableEnabled(tableDragSwitch.checked);
setText(status, tableDragSwitch.checked ? "明细表拖动实时预览已开" : "明细表拖动实时预览已关");
status.dataset.kind = "ok";
});
const nodeDragNote = element("div", "bpi-fold-note", "开:按住标签会浮起来跟着鼠标走,原位留一个空位,其余标签像手机桌面挪图标那样平滑让开;松手才真正改写提示词,只留一条撤销记录。每次拖动都要量一遍布局,提示词很长时会多花一点 CPU,受不了就关掉。");
const tableDragNote = element("div", "bpi-fold-note", "同上,但只管明细表里的拖动(拖行首的 ⠿ 手柄)。两个开关各管一处,互不影响。");
const deleteAnimRow = element("label", "bpi-switch-row bpi-switch-accent");
const deleteAnimSwitch = element("input", "bpi-switch");
deleteAnimSwitch.type = "checkbox";
deleteAnimSwitch.checked = deleteAnimNodeEnabled();
const deleteAnimTrack = element("span", "bpi-switch-track");
deleteAnimTrack.appendChild(element("span", "bpi-switch-thumb"));
deleteAnimRow.append(deleteAnimSwitch, deleteAnimTrack, element("span", "bpi-switch-text", "标签增删动画(节点标签区)"));
deleteAnimSwitch.addEventListener("change", () => {
setDeleteAnimNodeEnabled(deleteAnimSwitch.checked);
setText(status, deleteAnimSwitch.checked ? "节点标签区增删动画已开" : "节点标签区增删动画已关");
status.dataset.kind = "ok";
});
const deleteAnimNote = element("div", "bpi-fold-note", "开:删标签时那张卡先被一个大 X 划掉,接着整块从左往右擦走,然后再消失(约 0.9 秒,这期间那张卡点不动);添加标签时新卡片从左往右展开,旁边的标签滑开让位。关掉就是原来那样:点一下直接没、加一个直接出现。");
const foldNote = element("div", "bpi-fold-note", "Operation results show as a popup in the top-right corner instead of the status line.");
const toastNote = element("div", "bpi-fold-note", "Per-operation feedback (translation, tag edits, duplicate toggle) shows as a small bar stacked in the bottom-right corner. Turn it off to keep everything in the status line and save a bit of CPU.");
// 总开关最后绑定:这时下面几个子开关都已经建好。
// 打开 = 五个全开;关掉 = 五个全关。单独动某个子开关时,总开关跟着反映"是不是全开着"
const effectSwitches = [
[popupSwitch, setNotifyEnabled],
[toastSwitch, setToastEnabled],
[nodeDragSwitch, setDragPreviewNodeEnabled],
[tableDragSwitch, setDragPreviewTableEnabled],
[deleteAnimSwitch, setDeleteAnimNodeEnabled],
];
const syncMasterSwitch = () => {
masterSwitch.checked = effectSwitches.every(([input]) => input.checked);
};
syncMasterSwitch();
masterSwitch.addEventListener("change", () => {
const next = masterSwitch.checked;
for (const [input, setter] of effectSwitches) {
input.checked = next;
setter(next);
}
setText(status, next ? "通知弹窗、提示条、拖动预览和增删动画已全部开启" : "已全部关闭,提示退回状态栏,动画也不再播放");
status.dataset.kind = "ok";
});
for (const [input] of effectSwitches) input.addEventListener("change", syncMasterSwitch);
foldBody.append(masterRow, masterNote, masterNoteTail, popupRow, foldNote, toastRow, toastNote, nodeDragRow, nodeDragNote, tableDragRow, tableDragNote, deleteAnimRow, deleteAnimNote);
fold.append(element("summary", "", "通知弹窗及实时动画预览"), foldBody);
form.appendChild(fold);
host.appendChild(form);
// 只提交这两项:后端 update 对没给的字段一律保留原值,不会动翻译服务和密钥
@@ -661,18 +828,40 @@ async function buildAppearanceForm(host, loading) {
languageSelect.addEventListener("change", save);
}
// 「跟随选中节点」:试验开关,单独一项设置,不和外观那块混在一起。
// 存在本机 localStorage 里,不走后端配置——它只管这一台机器上的操作习惯。
// 开关本体长在「通用」那一项里(见 buildAppearanceForm),这里只管读写状态
function followSelectionEnabled() {
try {
return localStorage.getItem(FOLLOW_SELECTION_KEY) === "1";
} catch {
return false;
}
}
function setFollowSelectionEnabled(enabled) {
try {
localStorage.setItem(FOLLOW_SELECTION_KEY, enabled ? "1" : "0");
} catch (error) {
console.warn("[BilingualPromptInspector] Failed to save the follow-selection switch", error);
}
}
// 助手设置直接长在 ComfyUI「设置」面板里(入口见下方 registerExtension 的 settings),
// 这一个函数返回的就是设置项右侧那块控件。
// 面板每次渲染都会重建控件容器,所以整块 DOM 只建一次后复用,输入到一半的内容不会丢。
let assistantSettingsNode = null;
function assistantSettingsControl() {
if (assistantSettingsNode) return assistantSettingsNode;
if (assistantSettingsNode) {
alignWhenMounted(assistantSettingsNode);
return assistantSettingsNode;
}
assistantSettingsNode = element("div", "bpi-settings-form");
assistantSettingsNode.appendChild(element("h3", "", "Assistant Settings"));
const loading = element("div", "bpm-loading", "Loading settings...");
assistantSettingsNode.appendChild(loading);
buildAssistantForm(assistantSettingsNode, loading);
alignWhenMounted(assistantSettingsNode);
return assistantSettingsNode;
}
@@ -729,6 +918,65 @@ async function buildAssistantForm(host, loading) {
list.push(form.querySelector(`label[for="${input.id}"]`), input);
return input;
};
// 模型名称这一行:输入框照旧可以手写,旁边的按钮去问一次服务端有哪些模型,填进输入框自带的下拉里。
// 用原生 datalist 而不是弹窗:助手设置长在 ComfyUI 的「设置」面板里,浮层会被它盖住且点不动。
const addModelRow = (list, name, value, placeholder, options) => {
const label = element("label", "", "Model Name");
label.htmlFor = `bpi-field-${name}`;
const input = element("input");
input.id = label.htmlFor;
input.name = name;
input.value = value ?? "";
setPlaceholder(input, placeholder);
// datalist 本身不渲染,挂在 form 里跟着这块设置 DOM 一起活;选项只在本次会话内有效
const dataList = element("datalist");
dataList.id = `bpi-models-${name}`;
input.setAttribute("list", dataList.id);
let models = null;
const trigger = button("Fetch Models", () => pick());
const line = element("div", "bpi-model-line");
line.append(input, trigger);
form.append(label, line, dataList);
list.push(label, line, dataList);
const countLabel = () => (models ? `Fetch Models (${models.length})` : "Fetch Models");
const forget = () => {
models = null;
dataList.textContent = "";
setText(trigger, countLabel());
};
// 地址改了就地作废:下拉里不能留着上一个地址的模型
options.baseUrl().addEventListener("change", forget);
const pick = async () => {
trigger.disabled = true;
setText(trigger, models ? countLabel() : "Fetching...");
try {
const url = options.baseUrl().value.trim();
const keyInput = options.apiKey();
models = await listAssistantModels({
backend: options.backend,
base_url: url,
api_key: keyInput ? keyInput.value.trim() : "",
});
dataList.textContent = "";
for (const model of models) {
const option = element("option");
option.value = model; // 模型名是服务端原样返回值,不参与翻译
dataList.appendChild(option);
}
setText(trigger, countLabel());
input.focus();
setText(error, `Fetched ${models.length} models`);
error.dataset.kind = "ok";
} catch (fetchError) {
setText(trigger, countLabel());
setText(error, fetchError.message);
error.dataset.kind = "error";
} finally {
trigger.disabled = false;
}
};
return input;
};
// 清除已保存的密钥:开关样式,打开后要保存才生效。返回的 input 上挂了整行(`.row`)
const clearSwitch = (labelText) => {
const row = element("label", "bpi-switch-row");
@@ -798,7 +1046,11 @@ async function buildAssistantForm(host, loading) {
form.append(openaiHead);
openaiOnly.push(openaiHead);
const openaiBaseUrl = addField(openaiOnly, "API URL", "assistant-openai-base-url", config.openai_base_url, "https://host/v1");
const openaiModel = addField(openaiOnly, "Model Name", "assistant-openai-model", config.openai_model, "provider model ID");
const openaiModel = addModelRow(openaiOnly, "assistant-openai-model", config.openai_model, "provider model ID", {
backend: "openai_compatible",
baseUrl: () => openaiBaseUrl,
apiKey: () => openaiApiKey,
});
const presetLine = element("div", "bpm-toolbar");
presetLine.style.gridColumn = "1 / -1";
const lmStudioPreset = button("Use LM Studio Local Preset", () => {
@@ -837,7 +1089,11 @@ async function buildAssistantForm(host, loading) {
form.append(ollamaHead);
ollamaOnly.push(ollamaHead);
const ollamaBaseUrl = addField(ollamaOnly, "API URL", "assistant-ollama-base-url", config.ollama_base_url, "http://127.0.0.1:11434");
const ollamaModel = addField(ollamaOnly, "Model Name", "assistant-ollama-model", config.ollama_model, "e.g.: qwen3:8b");
const ollamaModel = addModelRow(ollamaOnly, "assistant-ollama-model", config.ollama_model, "e.g.: qwen3:8b", {
backend: "ollama",
baseUrl: () => ollamaBaseUrl,
apiKey: () => null,
});
const ollamaPresetLine = element("div", "bpm-toolbar");
ollamaPresetLine.style.gridColumn = "1 / -1";
const ollamaPreset = button("Use Ollama Local Preset", () => {
@@ -1152,7 +1408,7 @@ async function loadFavoriteIntoNode(item) {
}
const confirmed = await confirmDialog(
"Load",
`This will overwrite node #${target.id} prompt. Cannot be undone with Ctrl+Z.`,
`This will overwrite node #${target.id} prompt. This cannot be undone.`,
);
if (!confirmed) return;
target._bilingualPromptInspector?.setText?.(item.text ?? "");
@@ -1356,6 +1612,34 @@ function rebuildTagManagerSection() {
target._bilingualPromptInspector.refreshAfterConfigure?.();
}
// 画布上点节点 → 「标签管理」跟着切过去。
// 只认真正的检查器节点:点编码器、采样器之类的不动,免得切走了还得手动选回来。
function followSelectedNode(node) {
if (!followSelectionEnabled()) return;
if (!node?._bilingualPromptInspector?.detailsBody) return;
const id = String(node.id ?? "");
if (!id || manager.tagManagerNodeId === id) return;
manager.tagManagerNodeId = id;
// 面板没打开、或停在别的分页时只记下节点号,等切到「标签管理」时按它渲染
if (manager.section === "tag-manager" && refs.tagManagerHost?.isConnected) rebuildTagManagerSection();
}
// canvas.onNodeSelected 只有一个位置,接管前先把原来的接回去(别的扩展也可能挂在上面)。
// 前端自己只读不改这个回调,所以在 setup 里装一次就够。
function installFollowSelection() {
const canvas = app.canvas;
if (!canvas || canvas.bpiFollowSelection) return;
const previous = canvas.onNodeSelected;
canvas.onNodeSelected = function (node, ...rest) {
try {
previous?.apply(this, [node, ...rest]);
} finally {
followSelectedNode(node);
}
};
canvas.bpiFollowSelection = true;
}
function build() {
root = element("div", "bpm-panel");
const head = element("div", "bpm-head");
@@ -1373,7 +1657,12 @@ function build() {
refs.sections.appendChild(refs.tagManagerSection);
refs.sections.appendChild(buildTagsSection());
refs.sections.appendChild(buildPacksSection());
root.append(head, refs.tabs, refs.sections);
// 撤销键没写在任何提示里,这里在分区上方给一行小字:
// Ctrl+Z 归画布,插件自己的撤销是 Shift+Alt+Z。这行直接写中文:
// 侧边栏面板的标题/提示不进 i18n 译表,写英文就会一路显示英文
const undoHint = element("div", "bpi-config-note", "插件撤销:Shift+Alt+Z(重做:Shift+Alt+Y)");
undoHint.style.cssText = "padding:0 10px 6px";
root.append(head, refs.tabs, undoHint, refs.sections);
root.addEventListener("mousedown", (event) => event.stopPropagation());
root.addEventListener("wheel", (event) => event.stopPropagation(), { passive: true });
// 面板每次都重建,收藏分页也要跟着重新懒加载
@@ -1523,10 +1812,10 @@ app.registerExtension({
settings: [
{
id: "BilingualPromptInspector.Appearance",
name: "语言与外观",
name: "通用",
type: appearanceControl,
defaultValue: "",
category: ["双语提示词检查器", "语言与外观"],
category: ["双语提示词检查器", "通用"],
},
{
id: "BilingualPromptInspector.AssistantSettings",
@@ -1537,6 +1826,7 @@ app.registerExtension({
},
],
async setup() {
installFollowSelection();
if (!app.extensionManager?.registerSidebarTab) {
console.warn("[BilingualPromptInspector] Current frontend does not support sidebar; panel unavailable");
return;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "comfyui-bilingual-prompt-inspector",
"version": "2.1.8",
"version": "2.2.1",
"description": "ComfyUI bilingual prompt inspection, translation, Anima sorting, and on-demand Danbooru dictionary extension.",
"private": true,
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "prompt-translator-manager"
version = "2.1.8"
version = "2.2.1"
# 与 Comfy Registry 页面上显示的描述保持一致: publish 会用这里的值覆盖网页上的手改
description = "ComfyUI prompt node with translation and management: bilingual tag view, drag-to-reorder, temporary hiding, multiple translation services and a sidebar dictionary manager.\nComfyUI 提示节点,支持翻译和管理:双语标签视图、拖拽排序、临时隐藏、多翻译服务和侧边栏词典管理器。"
license = { file = "LICENSE" }
+59 -9
View File
@@ -25,10 +25,14 @@ from .assistant_store import (
baidu_translate_params,
dictionary_translate,
normalize_ai_base_url,
ollama_tags_endpoint,
openai_chat_endpoint,
openai_models_endpoint,
parse_json_body,
sanitize_anima_prompt,
sanitize_natural_prompt,
translation_direction,
upstream_error_message,
)
from .dictionary_store import DictionaryStore, normalize_key
from .duplicate_check import find_duplicates
@@ -47,6 +51,7 @@ assistant_store.config() # 进程启动时立即清除与当前安装身份不
_SESSION_TOKEN = secrets.token_urlsafe(32)
_MAX_JSON_BYTES = 8 * 1024 * 1024
_MAX_ASSISTANT_JSON_BYTES = 256 * 1024
_MODEL_LIST_TIMEOUT_SECONDS = 20
_ASSISTANT_RATE_WINDOW = 60.0
_ASSISTANT_RATE_LIMIT = 30
_assistant_requests = deque()
@@ -250,10 +255,10 @@ async def _call_ai_assistant(action, text, instruction, config, connection_test=
}
async with ClientSession(timeout=timeout) as session:
async with session.post(endpoint, json=payload) as response:
data = await response.json(content_type=None)
body = await response.text()
if response.status >= 400:
raise ValueError(data.get("error") or f"Ollama 请求失败:HTTP {response.status}")
result = data.get("message", {}).get("content")
raise ValueError(upstream_error_message(body, response.status, "Ollama"))
result = parse_json_body(body, "Ollama").get("message", {}).get("content")
else:
# OpenAI 兼容:远端必须 https,本机回环才允许 http
base = normalize_ai_base_url(config["openai_base_url"], allow_remote=True)
@@ -269,13 +274,10 @@ async def _call_ai_assistant(action, text, instruction, config, connection_test=
}
async with ClientSession(timeout=timeout) as session:
async with session.post(openai_chat_endpoint(base), headers=headers, json=payload) as response:
data = await response.json(content_type=None)
body = await response.text()
if response.status >= 400:
detail = data.get("error") if isinstance(data, dict) else None
if isinstance(detail, dict):
detail = detail.get("message")
raise ValueError(detail or f"API 请求失败:HTTP {response.status}")
choices = data.get("choices") if isinstance(data, dict) else None
raise ValueError(upstream_error_message(body, response.status, "API"))
choices = parse_json_body(body, "API").get("choices")
result = choices[0].get("message", {}).get("content") if choices else None
result = _clean_assistant_result(result)
if not result:
@@ -338,6 +340,54 @@ async def save_assistant_config(request):
return error_response(error)
async def _list_backend_models(prefix, base_url, api_key):
"""向 AI 后端问一次「你有哪些模型」;地址沿用现有白名单,问完不留任何东西。"""
timeout = ClientTimeout(total=_MODEL_LIST_TIMEOUT_SECONDS)
async with ClientSession(timeout=timeout) as session:
if prefix == "ollama":
# Ollama 只认本机回环地址,这里再校验一次,挡住手改配置文件的情况
base = normalize_ai_base_url(base_url)
if not base:
raise ValueError("尚未填写 Ollama 地址")
async with session.get(ollama_tags_endpoint(base)) as response:
# 先读原文再看状态码:错误应答常常不是 JSON,按 JSON 硬解析会把整个请求打崩
body = await response.text()
if response.status >= 400:
raise ValueError(upstream_error_message(body, response.status, "Ollama"))
names = [item.get("name") for item in parse_json_body(body, "Ollama").get("models") or []]
else:
base = normalize_ai_base_url(base_url, allow_remote=True)
if not base:
raise ValueError("尚未填写 OpenAI 兼容 API 地址")
headers = {"Authorization": f"Bearer {api_key}"} if api_key else {}
async with session.get(openai_models_endpoint(base), headers=headers) as response:
body = await response.text()
if response.status >= 400:
raise ValueError(upstream_error_message(body, response.status, "API"))
names = [item.get("id") for item in parse_json_body(body, "API").get("data") or []]
models = sorted({str(name).strip() for name in names if str(name).strip()})
if not models:
raise ValueError("服务端没有返回任何模型;也可以直接在输入框里手写模型名称")
return models
@protected_route("post", "/bpi/assistant/models")
async def list_assistant_models(request):
"""用表单里当前填的地址问一次模型列表,只为给下拉候选用:不写配置,也不把密钥返回浏览器。"""
try:
payload = await _read_json(request, _MAX_ASSISTANT_JSON_BYTES)
if not isinstance(payload, dict):
raise ValueError("请求内容格式不正确")
_consume_assistant_rate_limit()
prefix = "ollama" if payload.get("backend") == "ollama" else "openai"
# 密钥输入框留空 = 用户已经存过、这次不想再敲一遍,就拿已存的那份去问;仍只用于这一次请求
api_key = str(payload.get("api_key") or "").strip() or str(assistant_store.config().get(f"{prefix}_api_key") or "").strip()
models = await _list_backend_models(prefix, str(payload.get("base_url") or "").strip(), api_key)
return web.json_response({"success": True, "data": {"models": models}})
except AssistantLimitError as error:
return error_response(error, 429)
except Exception as error:
return error_response(error)
@protected_route("post", "/bpi/assistant/test")
+36
View File
@@ -17,10 +17,14 @@ from assistant_store import (
baidu_translate_params,
dictionary_translate,
normalize_ai_base_url,
ollama_tags_endpoint,
openai_chat_endpoint,
openai_models_endpoint,
parse_json_body,
sanitize_anima_prompt,
sanitize_natural_prompt,
translation_direction,
upstream_error_message,
)
from dictionary_store import DictionaryStore
@@ -444,6 +448,38 @@ class AssistantStoreTests(unittest.TestCase):
path.write_text(json.dumps(raw, ensure_ascii=False), encoding="utf-8")
self.assertEqual(store.config()["baidu_qps"], 1.0)
def test_model_list_endpoints_reuse_the_saved_base_url_shape(self):
self.assertEqual(openai_models_endpoint("https://api.openai.com/v1"), "https://api.openai.com/v1/models")
self.assertEqual(openai_models_endpoint("http://127.0.0.1:1234/v1/"), "http://127.0.0.1:1234/v1/models")
self.assertEqual(openai_models_endpoint("https://x.cn/v1/chat/completions"), "https://x.cn/v1/models")
self.assertEqual(openai_models_endpoint("https://x.cn/models"), "https://x.cn/models")
self.assertEqual(ollama_tags_endpoint("http://127.0.0.1:11434"), "http://127.0.0.1:11434/api/tags")
self.assertEqual(ollama_tags_endpoint("http://127.0.0.1:11434/v1"), "http://127.0.0.1:11434/api/tags")
self.assertEqual(ollama_tags_endpoint("http://127.0.0.1:11434/api/chat"), "http://127.0.0.1:11434/api/tags")
self.assertEqual(openai_models_endpoint(""), "")
self.assertEqual(ollama_tags_endpoint(""), "")
def test_error_bodies_that_are_not_json_still_read_as_a_sentence(self):
# DeepSeek 缺密钥时回的是纯文本一行,不是 JSON;解析不了也不能把整条请求打崩
# 第三个参数和 server.py 里的调用保持一致:整条路径改签名时这里会先炸出来
self.assertIn("Authentication Fails", upstream_error_message("Authentication Fails (governor)", 401, "API"))
self.assertIn("请检查 API 密钥", upstream_error_message("Authentication Fails (governor)", 401, "API"))
self.assertEqual(
upstream_error_message('{"error":{"message":"Invalid API key"}}', 401, "API"),
"Invalid API key(HTTP 401;请检查 API 密钥是否已填写、是否有效)",
)
self.assertEqual(upstream_error_message("404 page not found", 404, "API"), "404 page not found(HTTP 404)")
self.assertEqual(upstream_error_message("", 502, "Ollama"), "Ollama 请求失败(HTTP 502)")
self.assertTrue(len(upstream_error_message("<html>" + "x" * 500 + "</html>", 403, "API")) < 220)
def test_non_json_success_body_reports_instead_of_crashing(self):
self.assertEqual(parse_json_body('{"data": []}', "API"), {"data": []})
with self.assertRaises(ValueError) as raised:
parse_json_body("<html>login</html>", "API")
self.assertIn("返回的不是 JSON", str(raised.exception))
with self.assertRaises(ValueError):
parse_json_body("[1, 2, 3]", "API")
def test_baidu_params_and_query_splitting(self):
params = baidu_translate_params("appid", "secret", "你好", "zh", salt="12345")
self.assertEqual(params["sign"], hashlib.md5("appid你好12345secret".encode("utf-8")).hexdigest())
+1 -2
View File
@@ -69,8 +69,7 @@ assert.equal(t("“1girl” appears 3 times; “Unique” is on, only the first
"「1girl」出现了 3 次;已开「唯一」:只有第一次进入实际输出");
assert.equal(t("“1girl” occurrence 2 of 3; click again for the next one, double-click to delete it"),
"「1girl」第 2 / 3 处;再点一次跳下一处,双击删除这一处");
assert.equal(t("“1girl” now unique: only the first occurrence enters the actual output; press Ctrl+Z to undo"),
"「1girl」已设为唯一:只有第一次出现进入实际输出;按 Ctrl+Z 可撤销");
assert.equal(t("“1girl” now unique"), "「1girl」已设为唯一");
// 「Unique」在译文里会被二次翻译,tooltip 读起来是一致的中文
assert.equal(t("Query: “1girl” | “Unique” is on: only the first occurrence reaches the actual output"),
"查询「1girl」|已开「唯一」:只有第一次出现进入实际输出");
+7 -8
View File
@@ -27,8 +27,8 @@ assert.equal(t(""), "");
assert.equal(t(undefined), undefined);
// 带变量的文案:「“...”」和数字折叠成占位符后回填
assert.equal(t("deleted “masterpiece”; press Ctrl+Z to undo"), "已删除「masterpiece」;按 Ctrl+Z 可撤销");
assert.equal(t("restored 3 hidden tags; press Ctrl+Z to undo"), "已恢复 3 个隐藏标签;按 Ctrl+Z 可撤销");
assert.equal(t("deleted “masterpiece”"), "已删除「masterpiece」");
assert.equal(t("restored 3 hidden tags"), "已恢复 3 个隐藏标签");
// 用户实际会看到的组合文案:统计行、词包信息、操作回执、模式提示
assert.equal(t("items 3 | recognized 1 | unknown 2"), "共 3 个标签|已识别 1|未收录 2");
@@ -74,7 +74,7 @@ assert.equal(
assert.equal(t("Large 12000 (on-demand)"), "大词库 12000(按需)");
assert.equal(t("Large 12000 (disabled)"), "大词库 12000(已停用)");
assert.equal(t("Common dictionary 952 items"), "通用词库 952 条");
assert.equal(t("moved “1girl”; press Ctrl+Z to undo"), "已移动「1girl」;按 Ctrl+Z 可撤销");
assert.equal(t("moved “1girl”"), "已移动「1girl」");
assert.equal(t("Mode: “Tag” | “标签式输入”"), "模式:标签|标签式输入");
assert.equal(t("Mode: “Tag”"), "模式:标签");
assert.equal(
@@ -94,7 +94,7 @@ for (const [source, expected] of [
"Optimize with the rule for the current mode: tag mode tidies the tag flow, natural language mode rewrites it as English sentences",
"按当前模式对应的规则优化:标签模式整理标签流,自然语言模式改写为英文自然语句",
],
["applied “Translate & optimize”; press Ctrl+Z to undo", "已应用 翻译并优化;按 Ctrl+Z 可撤销"],
["applied “Translate & optimize”", "已应用 翻译并优化"],
["Undone: “Sort to Anima order”", "已撤销:Sort to Anima order"],
["Redone: “Sort to Anima order”", "已重做:Sort to Anima order"],
["Running “Translate”…", "正在运行 翻译…"],
@@ -160,8 +160,7 @@ assert.equal(t("(weight 1.5)"), "(权重 1.5)");
// 插件名:侧边栏标签写死中文,面板/关于框走译表,三处必须同一个名字
assert.equal(t("Bilingual Prompt Manager"), "提示词翻译与管理");
assert.equal(t("Bilingual Prompt Inspector"), "提示词翻译与管理");
// 设置面板里「语言与外观」那一项
assert.equal(t("Appearance & Language"), "语言与外观");
// 「语言与外观 / 助手设置」两项的标题由 ComfyUI 渲染设置项名称,插件不再自带 h3
assert.equal(t("Appearance and language saved"), "外观与语言已保存");
// 两个本地预设按钮各有一套文案,别混
assert.equal(t("Use LM Studio Local Preset"), "使用 LM Studio 本地预设");
@@ -171,9 +170,9 @@ assert.equal(t("Ollama default URL filled; select a pulled model ID, then Save &
// 确认对话框:默认确认按钮是 "OK",必须译为「确认」而不是「正常」
assert.equal(t("OK"), "确认");
assert.equal(t("Cancel"), "取消");
assert.equal(t("This will overwrite node #3 prompt. Cannot be undone with Ctrl+Z."), "这会覆盖节点 #3 的提示词,Ctrl+Z 无法撤销。");
assert.equal(t("This will overwrite node #3 prompt. This cannot be undone."), "这会覆盖节点 #3 的提示词,此操作无法撤销。");
assert.equal(t("Delete “Fluffy”? Reference image will be deleted too."), "删除「Fluffy」?参考图也会一并删除。");
assert.equal(t("restored 3 hidden tags; press Ctrl+Z to undo"), "已恢复 3 个隐藏标签;按 Ctrl+Z 可撤销");
assert.equal(t("restored 3 hidden tags"), "已恢复 3 个隐藏标签");
assert.equal(t("Node #3"), "节点 #3");
// 状态提示(整句形态)