zcode-pro 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +11 -4
- package/README.md +11 -4
- package/dist/inject.js +1895 -482
- package/package.json +2 -2
- package/src/host/helper.mjs +2412 -184
- package/src/host/hot-swap.mjs +76 -0
- package/src/host/main.mjs +35 -13
- package/src/host/prompt-inject.mjs +174 -0
- package/src/host/provider-proxy.mjs +298 -72
- package/src/host/proxy-chain.mjs +137 -0
- package/src/host/setup.mjs +39 -14
- package/src/host/taskIndex.mjs +7 -2
- package/src/host/tool-name-check.mjs +43 -12
- package/src/host/translate-lib.mjs +1 -1
- package/src/inject/core.js +240 -19
- package/src/inject/features/auto-continue.js +17 -15
- package/src/inject/features/hr-notice.js +70 -20
- package/src/inject/features/proxy-chain-notice.js +215 -0
- package/src/inject/features/settings-dialog.js +769 -338
- package/src/inject/features/status-bar.js +17 -6
- package/src/inject/features/turn-usage.js +22 -3
- package/src/inject/index.js +3 -0
- package/src/inject/locales/ja.js +121 -6
- package/src/inject/locales/ko.js +121 -6
- package/src/inject/locales/ru.js +121 -6
- package/src/inject/provider-model-thinking.js +142 -0
- package/src/inject/thinking-levels.js +12 -6
- package/src/inject/ui.js +113 -3
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// “ZCode Pro 增强设置”弹窗:功能开关 + 外观 + 运行状态。
|
|
2
2
|
// 顶部标签页切换(视觉参考侧栏“分组/项目”切换);配置写入 helper(~/.zcode/zcodepro.json)。
|
|
3
3
|
import { h, t, rpc, getConfig, clearConfigCache, errText, HELPER_URL, liveBoot, isZhLocale, uiLocale, isCjkLocale, isNewProjectSidebar, DEFAULT_SHORTCUTS, DEFAULT_STATUS_ITEMS, DEFAULT_TURN_ITEMS, STATUS_SESSION_IDS, STATUS_GLOBAL_IDS } from '../core.js';
|
|
4
|
-
import { openDialog, dialogFooter, btnPrimary, btnSecondary, btnSmall, settingRow, ensureStyle, showToast, numberField, unitField } from '../ui.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { openDialog, dialogFooter, btnPrimary, btnSecondary, btnSmall, settingRow, ensureStyle, showToast, numberField, unitField, confirmTip } from '../ui.js';
|
|
5
|
+
import { isManualConn } from '../provider-fields.js';
|
|
6
|
+
import { providerModelThinkingFields } from '../provider-model-thinking.js';
|
|
7
|
+
import { resolveThinkingOptions } from '../thinking-levels.js';
|
|
7
8
|
import { refreshAliases } from './alias.js';
|
|
8
9
|
import { migrationCard } from './alias-migration.js';
|
|
9
10
|
import { applyStyles, STYLE_DEFAULTS, showStyleHighlight, hideStyleHighlight } from './styles.js';
|
|
@@ -153,7 +154,40 @@ function makeUpgradeControls({ endpoint, metaRefresh, idleText }) {
|
|
|
153
154
|
return { btn, state, stop: stopPoll };
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
// 记住上次停留的标签页(一级 + 各级二级),下次打开恢复到原位。
|
|
158
|
+
// 存 localStorage 而不是配置文件:属于纯界面状态,不需要同步到别的机器。
|
|
159
|
+
// initialTab 显式指定时(如翻译面板的 ⚙ 直达“翻译”)优先用它,不读记忆值。
|
|
160
|
+
const SETTINGS_TAB_KEY = 'zcodepro-settings-tab';
|
|
161
|
+
const SETTINGS_SUBTAB_KEY = 'zcodepro-settings-subtab';
|
|
162
|
+
function readTabMemory(key) {
|
|
163
|
+
try {
|
|
164
|
+
const v = JSON.parse(localStorage.getItem(key) || 'null');
|
|
165
|
+
return v && typeof v === 'object' ? v : {};
|
|
166
|
+
} catch { return {}; }
|
|
167
|
+
}
|
|
168
|
+
function writeTabMemory(key, patch) {
|
|
169
|
+
try {
|
|
170
|
+
const cur = readTabMemory(key);
|
|
171
|
+
localStorage.setItem(key, JSON.stringify({ ...cur, ...patch }));
|
|
172
|
+
} catch { /* ignore */ }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// initialTab 默认空串而不是 'features':要区分“调用方没指定”(回到上次停留的
|
|
176
|
+
// tab)与“调用方明确要求打开功能页”两种意图。之前默认 'features' 会让
|
|
177
|
+
// explicitTab 永远有值,记忆功能失效、每次都停在功能页
|
|
178
|
+
// 当前打开着的设置弹窗。同一时刻只应有一个:再调用时先把旧的关掉再重开,不叠开新的。
|
|
179
|
+
// 叠开过一次:设置弹窗的遮罩不拦点击(pointer-events:none),两个弹窗同时开着时,
|
|
180
|
+
// 点在旧弹窗上的操作照常生效——用户看着新弹窗,实际改的是底下那个。
|
|
181
|
+
// 关掉再重开(而不是复用旧弹窗切页签):重开会按当前状态重新读配置,
|
|
182
|
+
// 旧弹窗里过时的内容不会被带到新弹窗里。不做定时刷新:为少见的场景每几秒读一次
|
|
183
|
+
// 配置不值当,弹窗开着时别处改了配置,重新打开就是最新的
|
|
184
|
+
let openSettingsHandle = null;
|
|
185
|
+
|
|
186
|
+
export function openSettingsDialog(initialTab = '', initialSub = '') {
|
|
187
|
+
if (openSettingsHandle && document.contains(openSettingsHandle.el)) {
|
|
188
|
+
try { openSettingsHandle.close(); } catch { /* ignore */ }
|
|
189
|
+
openSettingsHandle = null;
|
|
190
|
+
}
|
|
157
191
|
ensureStyle();
|
|
158
192
|
const L = t();
|
|
159
193
|
// Headroom / rtk 升级进度轮询的停止句柄:面板代码在 onMount 里赋值,关弹窗时停掉
|
|
@@ -174,6 +208,7 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
174
208
|
sizeKey: 'settings',
|
|
175
209
|
dismissOnOutside: false,
|
|
176
210
|
onClose: () => {
|
|
211
|
+
openSettingsHandle = null;
|
|
177
212
|
if (hrUpgradePollStop) hrUpgradePollStop();
|
|
178
213
|
if (rtkUpgradePollStop) rtkUpgradePollStop();
|
|
179
214
|
// 通知外部(翻译面板等)设置已关闭:它们可能在打开期间临时降了层级
|
|
@@ -512,10 +547,17 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
512
547
|
}));
|
|
513
548
|
|
|
514
549
|
// 标签页切换:功能(现有内容)/ 外观 / 全局提示词 / 视觉代理
|
|
515
|
-
// initialTab 供面板等入口直达指定标签(如翻译面板的 ⚙
|
|
516
|
-
|
|
550
|
+
// initialTab 供面板等入口直达指定标签(如翻译面板的 ⚙ 打开“翻译”页);
|
|
551
|
+
// 未显式指定时恢复上次停留的一级 tab(tabDefs 建好后再校验合法性)
|
|
552
|
+
const explicitTab = typeof initialTab === 'string' && initialTab ? initialTab : '';
|
|
553
|
+
const tabMemory = readTabMemory(SETTINGS_TAB_KEY);
|
|
554
|
+
let activeTab = explicitTab || (typeof tabMemory.last === 'string' ? tabMemory.last : '') || 'features';
|
|
517
555
|
// 二级 tab 栏(外观 / 行为各一条):登记后统一放到滚动区上方的固定区
|
|
518
556
|
const subTabBars = {};
|
|
557
|
+
// 二级 tab 记忆:每页一条 key(styles / agents / proxy),默认值保持原行为
|
|
558
|
+
const subMemory = readTabMemory(SETTINGS_SUBTAB_KEY);
|
|
559
|
+
const savedSub = (key, fallback) => (typeof subMemory[key] === 'string' && subMemory[key]) || fallback;
|
|
560
|
+
const rememberSub = (key, value) => writeTabMemory(SETTINGS_SUBTAB_KEY, { [key]: value });
|
|
519
561
|
// 插件更新卡片:显示 duanluan-zcode-plugins 市场状态,一键更新(helper /plugins/* 端点);
|
|
520
562
|
// 状态异步加载,打开弹窗不等待
|
|
521
563
|
|
|
@@ -733,6 +775,8 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
733
775
|
});
|
|
734
776
|
const switchTab = (name) => {
|
|
735
777
|
activeTab = name;
|
|
778
|
+
// 记住一级 tab,下次打开回到这里
|
|
779
|
+
writeTabMemory(SETTINGS_TAB_KEY, { last: name });
|
|
736
780
|
// 切走“快捷键”标签页时结束键位录制:否则在其它标签页打字会被录制监听吞掉
|
|
737
781
|
if (name !== 'shortcuts' && hkRecording) stopHkRecording();
|
|
738
782
|
for (const [id, pane] of Object.entries(panes)) pane.style.display = id === name ? '' : 'none';
|
|
@@ -745,11 +789,12 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
745
789
|
el?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
746
790
|
} catch { /* ignore */ }
|
|
747
791
|
};
|
|
748
|
-
//
|
|
749
|
-
|
|
750
|
-
// tab
|
|
751
|
-
|
|
752
|
-
|
|
792
|
+
// 登记给单实例逻辑用:已开着时再打开,先把它关掉
|
|
793
|
+
openSettingsHandle = { el: content.closest('.zcodepro-overlay') || content, close };
|
|
794
|
+
// 记忆的 tab 可能已不存在(版本升级删了某页、导入会话被关掉等):退回“功能”
|
|
795
|
+
activeTab = tabDefs.some(([id]) => id === activeTab) ? activeTab : 'features';
|
|
796
|
+
// 注意:真正的首次切换推迟到 onMount 末尾(所有 pane 都建好并 append 之后)。
|
|
797
|
+
// 这里只渲染一次 tab 按钮,避免内容区在 pane 未就绪时切过去留下空白。
|
|
753
798
|
|
|
754
799
|
// “样式”:一行两项、相关项同行;无描述文字,悬停名称显示 tip;
|
|
755
800
|
// 数字框滚轮/手输调节,改完即存即生效
|
|
@@ -1082,7 +1127,14 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1082
1127
|
custom: patch.custom !== undefined ? patch.custom : themeCfg.custom,
|
|
1083
1128
|
bg: { ...themeCfg.bg, ...(patch.bg || {}) },
|
|
1084
1129
|
};
|
|
1085
|
-
|
|
1130
|
+
// 只提交本次改动的字段(后端按字段合并):整对象提交会把弹窗打开期间
|
|
1131
|
+
// 别处(另一窗口、壁纸 CLI/技能)刚改的主题字段退回旧值。
|
|
1132
|
+
// skin/custom 没动就不带;bg 只带 patch 里出现过的子字段
|
|
1133
|
+
const bodyTheme = {};
|
|
1134
|
+
if (patch.skin !== undefined) bodyTheme.skin = themeCfg.skin;
|
|
1135
|
+
if (patch.custom !== undefined) bodyTheme.custom = themeCfg.custom;
|
|
1136
|
+
if (patch.bg && Object.keys(patch.bg).length) bodyTheme.bg = patch.bg;
|
|
1137
|
+
const res = await rpc('/config', { method: 'POST', body: Object.keys(bodyTheme).length ? { theme: bodyTheme } : {} });
|
|
1086
1138
|
clearConfigCache();
|
|
1087
1139
|
window.dispatchEvent(new CustomEvent('zcodepro:config-changed'));
|
|
1088
1140
|
if (!res.ok) showToast(L.failed + ': ' + errText(res), 'error');
|
|
@@ -1578,7 +1630,8 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1578
1630
|
void refreshBgFiles();
|
|
1579
1631
|
void refreshFolderInfo();
|
|
1580
1632
|
|
|
1581
|
-
|
|
1633
|
+
const STYLES_SUBS = ['bgimg', 'colors', 'styles', 'status'];
|
|
1634
|
+
let stylesSubTab = STYLES_SUBS.includes(savedSub('styles', '')) ? savedSub('styles', '') : 'bgimg';
|
|
1582
1635
|
const stylesSubTablist = h('div', { role: 'tablist', 'aria-orientation': 'horizontal', class: 'zcodepro-tablist' });
|
|
1583
1636
|
const renderStylesSubTabs = () => stylesSubTablist.replaceChildren(...[
|
|
1584
1637
|
['bgimg', L.themeBgPane],
|
|
@@ -1591,6 +1644,7 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1591
1644
|
'data-state': stylesSubTab === id ? 'active' : 'inactive',
|
|
1592
1645
|
onClick: () => {
|
|
1593
1646
|
stylesSubTab = id;
|
|
1647
|
+
rememberSub('styles', id);
|
|
1594
1648
|
paneStylesSub1.style.display = id === 'styles' ? '' : 'none';
|
|
1595
1649
|
paneStylesSub2.style.display = id === 'status' ? '' : 'none';
|
|
1596
1650
|
paneStylesSub3.style.display = id === 'colors' ? '' : 'none';
|
|
@@ -1598,6 +1652,11 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1598
1652
|
renderStylesSubTabs();
|
|
1599
1653
|
},
|
|
1600
1654
|
}, label)));
|
|
1655
|
+
// 按记住的子页设置初始可见性(首次打开时四个 pane 都会显示,必须显式关掉)
|
|
1656
|
+
paneStylesSub1.style.display = stylesSubTab === 'styles' ? '' : 'none';
|
|
1657
|
+
paneStylesSub2.style.display = stylesSubTab === 'status' ? '' : 'none';
|
|
1658
|
+
paneStylesSub3.style.display = stylesSubTab === 'colors' ? '' : 'none';
|
|
1659
|
+
paneStylesSub4.style.display = stylesSubTab === 'bgimg' ? '' : 'none';
|
|
1601
1660
|
renderStylesSubTabs();
|
|
1602
1661
|
subTabBars.styles = stylesSubTablist;
|
|
1603
1662
|
paneStyles.append(paneStylesSub1, paneStylesSub2, paneStylesSub3, paneStylesSub4);
|
|
@@ -1649,6 +1708,52 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1649
1708
|
// “行为 → ZCode CLI”:zcode-cli 运行时的行为配置(写 ~/.zcode/cli/config.json)+
|
|
1650
1709
|
// 技能清单检查。开关与预算数字框改动即存,每次只提交自己那个键;
|
|
1651
1710
|
// 目录列表显式保存
|
|
1711
|
+
// 工具名合规检查
|
|
1712
|
+
const toolNameState = h('p', { class: 'mt-2 text-ui-xs/relaxed text-foreground-subtle' });
|
|
1713
|
+
let toolNameBusy = false;
|
|
1714
|
+
const toolNameBtn = btnSmall(L.toolNameCheckBtn, () => { void runToolNameCheck(); }, 'shrink-0', 'primary');
|
|
1715
|
+
const runToolNameCheck = async () => {
|
|
1716
|
+
if (toolNameBusy) return;
|
|
1717
|
+
toolNameBusy = true;
|
|
1718
|
+
toolNameBtn.disabled = true;
|
|
1719
|
+
toolNameBtn.textContent = L.toolNameCheckRunning;
|
|
1720
|
+
toolNameState.textContent = '';
|
|
1721
|
+
toolNameState.className = 'mt-2 text-ui-xs/relaxed text-foreground-subtle';
|
|
1722
|
+
const res = await rpc('/tool-names/check', { method: 'POST', body: {} });
|
|
1723
|
+
toolNameBusy = false;
|
|
1724
|
+
toolNameBtn.disabled = false;
|
|
1725
|
+
toolNameBtn.textContent = L.toolNameCheckBtn;
|
|
1726
|
+
if (!res.ok) {
|
|
1727
|
+
toolNameState.className = 'mt-2 text-ui-xs/relaxed text-destructive';
|
|
1728
|
+
toolNameState.textContent = L.toolNameCheckFailed + ': ' + errText(res);
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
toolNameState.className = 'mt-2 text-ui-xs/relaxed ' + (res.warnings && res.warnings.length ? 'text-amber-500' : 'text-foreground-subtle');
|
|
1732
|
+
toolNameState.textContent = res.summary || '';
|
|
1733
|
+
};
|
|
1734
|
+
let toolNameAutoOn = config.toolNameAuto !== false;
|
|
1735
|
+
const toolNameAutoWrap = h('div', { class: 'ml-auto flex shrink-0 items-center gap-1.5' });
|
|
1736
|
+
const renderToolNameAuto = () => {
|
|
1737
|
+
const toggle = async () => {
|
|
1738
|
+
const next = !toolNameAutoOn;
|
|
1739
|
+
const res = await rpc('/config', { method: 'POST', body: { toolNameAuto: next } });
|
|
1740
|
+
if (!res.ok) { showToast(L.failed + ': ' + errText(res), 'error'); return; }
|
|
1741
|
+
toolNameAutoOn = (res.config && typeof res.config.toolNameAuto === 'boolean') ? res.config.toolNameAuto : next;
|
|
1742
|
+
renderToolNameAuto();
|
|
1743
|
+
};
|
|
1744
|
+
toolNameAutoWrap.replaceChildren(
|
|
1745
|
+
h('span', { class: 'text-ui-xs text-foreground-subtle', title: L.toolNameAutoDesc }, L.toolNameAuto),
|
|
1746
|
+
h('button', {
|
|
1747
|
+
type: 'button', role: 'switch', 'aria-checked': String(toolNameAutoOn),
|
|
1748
|
+
class: 'relative inline-flex shrink-0 cursor-pointer items-center',
|
|
1749
|
+
title: L.toolNameAutoDesc,
|
|
1750
|
+
onClick: () => { void toggle(); },
|
|
1751
|
+
}, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': toolNameAutoOn ? 'on' : 'off' },
|
|
1752
|
+
h('span', { class: 'zcodepro-switch-knob' }))),
|
|
1753
|
+
);
|
|
1754
|
+
};
|
|
1755
|
+
renderToolNameAuto();
|
|
1756
|
+
|
|
1652
1757
|
const paneZcode = h('div', { class: 'mt-2' });
|
|
1653
1758
|
let snap = zcodeConfigRes;
|
|
1654
1759
|
const setZcode = async (body) => {
|
|
@@ -1766,11 +1871,108 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1766
1871
|
h('div', { class: 'mt-0.5 text-ui-xs/relaxed text-foreground-subtle' }, L.zcodeSkillRootsDesc),
|
|
1767
1872
|
h('div', { class: 'mt-2' }, rootsArea),
|
|
1768
1873
|
h('div', { class: 'mt-2 flex justify-end' }, rootsSaveBtn)),
|
|
1874
|
+
h('div', { class: 'mt-2 rounded-xl border border-border p-3' },
|
|
1875
|
+
h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.toolNameCheckTitle),
|
|
1876
|
+
h('p', { class: 'mt-1 text-ui-xs/relaxed text-foreground-subtle' }, L.toolNameCheckDesc),
|
|
1877
|
+
h('div', { class: 'mt-2 flex items-center gap-2' }, toolNameBtn, toolNameAutoWrap),
|
|
1878
|
+
toolNameState),
|
|
1769
1879
|
);
|
|
1770
1880
|
}
|
|
1771
1881
|
// “行为”标签页:二级标签切换“ZCode / 全局提示词 / 任务名”。全局提示词编辑
|
|
1772
1882
|
// ~/.zcode/AGENTS.md;任务名(智能起名)面板复用 paneTitleGen(原本是
|
|
1773
1883
|
// 一级标签页,收进来后不再单独出现在顶部标签栏)
|
|
1884
|
+
// 提示词注入:与上面的 AGENTS.md 并排放在同一页,用户能直接看出两者的差别
|
|
1885
|
+
// (一个进对话层、一个进系统层)。正文只在点保存时提交;“也注入子代理”开关
|
|
1886
|
+
// 立即生效。长度不截断,超过 20000 字符只给一句提醒。
|
|
1887
|
+
const piCfg = (config && config.promptInjection) || { text: '', subagents: false };
|
|
1888
|
+
let piText = typeof piCfg.text === 'string' ? piCfg.text : '';
|
|
1889
|
+
let piSubagents = piCfg.subagents === true;
|
|
1890
|
+
// 卡片第一行的说明,后面跟着当前状态(已生效几家供应商)。只在打开弹窗时算一次,
|
|
1891
|
+
// 不做定时刷新
|
|
1892
|
+
const piChainHintText = h('span', { class: 'min-w-0 flex-1 text-ui-xs/relaxed text-foreground-subtle' }, L.injectChainHint);
|
|
1893
|
+
// 开关与卡片都用功能页同款样式,这里各自定义一份(主题页里的同名函数是局部作用域)
|
|
1894
|
+
const piSwitch = (checked) => h('button', {
|
|
1895
|
+
type: 'button', role: 'switch', 'aria-checked': String(checked),
|
|
1896
|
+
class: 'relative inline-flex shrink-0 cursor-pointer items-center',
|
|
1897
|
+
}, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': checked ? 'on' : 'off' },
|
|
1898
|
+
h('span', { class: 'zcodepro-switch-knob' })));
|
|
1899
|
+
const piCard = (titleText, body) => h('div', { class: 'rounded-xl border border-border p-3' },
|
|
1900
|
+
h('div', { class: 'text-ui-sm font-medium text-foreground' }, titleText),
|
|
1901
|
+
body);
|
|
1902
|
+
const piCount = h('span', { class: 'text-ui-xs text-foreground-subtle' });
|
|
1903
|
+
const piLongHint = h('span', { class: 'text-ui-xs text-foreground-subtle' }, L.injectLongHint);
|
|
1904
|
+
const piArea = h('textarea', {
|
|
1905
|
+
class: 'zcodepro-textarea zcodepro-textarea-lg',
|
|
1906
|
+
placeholder: L.injectPlaceholder,
|
|
1907
|
+
spellcheck: 'false',
|
|
1908
|
+
});
|
|
1909
|
+
piArea.value = piText;
|
|
1910
|
+
const piSaveBtn = btnSmall(L.agentsSave, () => { void saveInjectionText(); }, '', 'primary');
|
|
1911
|
+
const renderPiMeta = () => {
|
|
1912
|
+
piCount.textContent = L.injectChars.replace('{n}', String(piArea.value.length));
|
|
1913
|
+
piLongHint.style.display = piArea.value.length > 20000 ? '' : 'none';
|
|
1914
|
+
piSaveBtn.disabled = piArea.value === piText;
|
|
1915
|
+
};
|
|
1916
|
+
piArea.addEventListener('input', renderPiMeta);
|
|
1917
|
+
renderPiMeta();
|
|
1918
|
+
// 状态:问一次 helper 当前有多少已启用供应商真的在走转发,接在第一行说明的后面。
|
|
1919
|
+
// 几种状态的说法各自带着句读,拼起来就是一句完整的话
|
|
1920
|
+
const refreshPiStatus = async () => {
|
|
1921
|
+
const st = await rpc('/prompt-injection/status');
|
|
1922
|
+
if (!st.ok) { piChainHintText.textContent = L.injectChainHint; return; }
|
|
1923
|
+
let extra;
|
|
1924
|
+
if (!st.providers) extra = L.injectChainNone;
|
|
1925
|
+
else extra = L.injectChainStatus.replace('{active}', String(st.active || 0)).replace('{providers}', String(st.providers));
|
|
1926
|
+
piChainHintText.textContent = L.injectChainHint + extra;
|
|
1927
|
+
};
|
|
1928
|
+
const saveInjection = async (patch) => {
|
|
1929
|
+
const res = await rpc('/config', { method: 'POST', body: { promptInjection: patch } });
|
|
1930
|
+
if (!res.ok) { showToast(L.failed + ': ' + errText(res), 'error'); return false; }
|
|
1931
|
+
clearConfigCache();
|
|
1932
|
+
if (res.config && res.config.promptInjection) {
|
|
1933
|
+
piText = typeof res.config.promptInjection.text === 'string' ? res.config.promptInjection.text : piText;
|
|
1934
|
+
piSubagents = res.config.promptInjection.subagents === true;
|
|
1935
|
+
}
|
|
1936
|
+
// 对齐转发器要一点时间(拉起新端口、改写供应商地址),稍等再看状态
|
|
1937
|
+
setTimeout(() => { void refreshPiStatus(); }, 1200);
|
|
1938
|
+
return true;
|
|
1939
|
+
};
|
|
1940
|
+
const saveInjectionText = async () => {
|
|
1941
|
+
piSaveBtn.disabled = true;
|
|
1942
|
+
if (await saveInjection({ text: piArea.value })) {
|
|
1943
|
+
piText = piArea.value;
|
|
1944
|
+
showToast(L.injectSaved, 'success');
|
|
1945
|
+
}
|
|
1946
|
+
renderPiMeta();
|
|
1947
|
+
};
|
|
1948
|
+
// “也注入子代理”开关行
|
|
1949
|
+
const piSubLabel = h('span', {}, L.injectSubagents);
|
|
1950
|
+
const piSubKnob = h('span', {}, piSwitch(piSubagents));
|
|
1951
|
+
const renderPiSub = () => piSubKnob.replaceChildren(piSwitch(piSubagents));
|
|
1952
|
+
const piSubRow = h('div', {
|
|
1953
|
+
class: 'mt-2 flex cursor-pointer items-center gap-2 text-ui-sm text-foreground-subtle',
|
|
1954
|
+
onClick: () => {
|
|
1955
|
+
piSubagents = !piSubagents;
|
|
1956
|
+
renderPiSub();
|
|
1957
|
+
void saveInjection({ subagents: piSubagents });
|
|
1958
|
+
},
|
|
1959
|
+
}, piSubLabel, piSubKnob);
|
|
1960
|
+
void refreshPiStatus();
|
|
1961
|
+
// 注入只对在“代理 → 代理链”里勾选的供应商生效:卡片第一行给一句说明和一个跳转按钮
|
|
1962
|
+
//(原来这一行是注入开关,开关已去掉,位置留给这句说明)。showProxySub 定义在本段
|
|
1963
|
+
// 之后,点击时才调用
|
|
1964
|
+
const piChainGo = btnSmall(L.injectGoChain, () => { showProxySub('vendor'); switchTab('proxy'); }, 'shrink-0');
|
|
1965
|
+
const injectBlock = piCard(L.injectTitle, h('div', { class: 'mt-1' },
|
|
1966
|
+
h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.injectDesc),
|
|
1967
|
+
h('div', { class: 'mt-2 flex items-center justify-between gap-2' },
|
|
1968
|
+
piChainHintText,
|
|
1969
|
+
piChainGo),
|
|
1970
|
+
h('div', { class: 'mt-3' }, piArea),
|
|
1971
|
+
h('div', { class: 'mt-2 flex items-center justify-between gap-2' },
|
|
1972
|
+
h('div', { class: 'flex items-center gap-2' }, piCount, piLongHint),
|
|
1973
|
+
piSaveBtn),
|
|
1974
|
+
piSubRow));
|
|
1975
|
+
|
|
1774
1976
|
const agentsPromptPane = h('div', { class: 'mt-2' });
|
|
1775
1977
|
agentsPromptPane.append(
|
|
1776
1978
|
h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.agentsDesc),
|
|
@@ -1779,8 +1981,13 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1779
1981
|
: []),
|
|
1780
1982
|
h('div', { class: 'mt-3' }, agentsArea),
|
|
1781
1983
|
h('div', { class: 'mt-3 flex justify-end' }, agentsSaveBtn),
|
|
1984
|
+
h('div', { class: 'mt-5' }, injectBlock),
|
|
1782
1985
|
);
|
|
1783
|
-
|
|
1986
|
+
const AGENTS_SUBS = ['zcode', 'prompt', 'titleGen', 'autoContinue'];
|
|
1987
|
+
// 从外面直达行为页时(右下角卡片的“去自动重命名设置”“去运行时设置”)用指定的
|
|
1988
|
+
// 二级页签,与代理页的规则一致;否则用记住的
|
|
1989
|
+
const wantedAgentsSub = (initialTab === 'agents' && AGENTS_SUBS.includes(initialSub)) ? initialSub : savedSub('agents', '');
|
|
1990
|
+
let agentsSubTab = AGENTS_SUBS.includes(wantedAgentsSub) ? wantedAgentsSub : 'zcode';
|
|
1784
1991
|
const agentsSubPanes = { zcode: paneZcode, prompt: agentsPromptPane, titleGen: paneTitleGen, autoContinue: paneAutoContinue };
|
|
1785
1992
|
const agentsSubList = h('div', { role: 'tablist', 'aria-orientation': 'horizontal', class: 'zcodepro-tablist' });
|
|
1786
1993
|
const renderAgentsSubTabs = () => {
|
|
@@ -1795,6 +2002,7 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1795
2002
|
'data-state': agentsSubTab === id ? 'active' : 'inactive',
|
|
1796
2003
|
onClick: () => {
|
|
1797
2004
|
agentsSubTab = id;
|
|
2005
|
+
rememberSub('agents', id);
|
|
1798
2006
|
for (const [pid, pane] of Object.entries(agentsSubPanes)) pane.style.display = pid === id ? '' : 'none';
|
|
1799
2007
|
renderAgentsSubTabs();
|
|
1800
2008
|
},
|
|
@@ -1888,11 +2096,14 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1888
2096
|
};
|
|
1889
2097
|
renderProxyScopes();
|
|
1890
2098
|
// 两级 tab:软件代理(原有界面)/ 供应商代理(按供应商转发 + 工具名检查)
|
|
1891
|
-
|
|
2099
|
+
const PROXY_SUBS = ['software', 'vendor'];
|
|
2100
|
+
// 从外面直达代理页时(比如右下角卡片的“去代理链”)用指定的二级页签,否则用记住的
|
|
2101
|
+
const wantedProxySub = (initialTab === 'proxy' && PROXY_SUBS.includes(initialSub)) ? initialSub : savedSub('proxy', '');
|
|
2102
|
+
let proxySubTab = PROXY_SUBS.includes(wantedProxySub) ? wantedProxySub : 'software';
|
|
1892
2103
|
const proxySubTablist = h('div', { role: 'tablist', 'aria-orientation': 'horizontal', class: 'zcodepro-tablist' });
|
|
1893
2104
|
// mt-2 与“行为”二级 tab 保持一致:内容面板与上方 tab 栏之间留出间距
|
|
1894
2105
|
const paneProxySoftware = h('div', { class: 'mt-2' });
|
|
1895
|
-
const
|
|
2106
|
+
const proxyChainPane = h('div', { class: 'mt-2' });
|
|
1896
2107
|
const renderProxySubTabs = () => proxySubTablist.replaceChildren(...[
|
|
1897
2108
|
['software', L.proxySubSoftware],
|
|
1898
2109
|
['vendor', L.proxySubVendor],
|
|
@@ -1900,18 +2111,27 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1900
2111
|
type: 'button', role: 'tab', class: 'zcodepro-tab',
|
|
1901
2112
|
'aria-selected': String(proxySubTab === id),
|
|
1902
2113
|
'data-state': proxySubTab === id ? 'active' : 'inactive',
|
|
1903
|
-
onClick: () =>
|
|
1904
|
-
proxySubTab = id;
|
|
1905
|
-
paneProxySoftware.style.display = id === 'software' ? '' : 'none';
|
|
1906
|
-
paneProxyVendor.style.display = id === 'vendor' ? '' : 'none';
|
|
1907
|
-
if (id === 'vendor') void refreshVendorProxyStatus();
|
|
1908
|
-
renderProxySubTabs();
|
|
1909
|
-
},
|
|
2114
|
+
onClick: () => showProxySub(id),
|
|
1910
2115
|
}, label)));
|
|
2116
|
+
// 切换代理页的二级页签。refreshChainStatus 定义在本段之后(const 有暂时性死区),
|
|
2117
|
+
// 只能在事件回调里调;提示词注入那边的“去代理链勾选”按钮也走这里
|
|
2118
|
+
const showProxySub = (id) => {
|
|
2119
|
+
if (!PROXY_SUBS.includes(id)) return;
|
|
2120
|
+
proxySubTab = id;
|
|
2121
|
+
rememberSub('proxy', id);
|
|
2122
|
+
paneProxySoftware.style.display = id === 'software' ? '' : 'none';
|
|
2123
|
+
proxyChainPane.style.display = id === 'vendor' ? '' : 'none';
|
|
2124
|
+
if (id === 'vendor') void refreshChainStatus();
|
|
2125
|
+
renderProxySubTabs();
|
|
2126
|
+
};
|
|
1911
2127
|
renderProxySubTabs();
|
|
1912
2128
|
subTabBars.proxy = proxySubTablist;
|
|
1913
|
-
paneProxy.append(proxySubTablist, paneProxySoftware,
|
|
1914
|
-
|
|
2129
|
+
paneProxy.append(proxySubTablist, paneProxySoftware, proxyChainPane);
|
|
2130
|
+
// 按记住的子页设置初始可见性。refreshChainStatus 定义在本段之后
|
|
2131
|
+
// (const 有暂时性死区),这里不能直接调;延到下一个微任务再触发
|
|
2132
|
+
paneProxySoftware.style.display = proxySubTab === 'software' ? '' : 'none';
|
|
2133
|
+
proxyChainPane.style.display = proxySubTab === 'vendor' ? '' : 'none';
|
|
2134
|
+
if (proxySubTab === 'vendor') queueMicrotask(() => { try { void refreshChainStatus(); } catch { /* ignore */ } });
|
|
1915
2135
|
paneProxySoftware.append(
|
|
1916
2136
|
h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.proxyDesc),
|
|
1917
2137
|
h('div', { class: 'mt-3 flex items-center gap-2' },
|
|
@@ -1923,235 +2143,433 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
1923
2143
|
h('div', { class: 'mt-3 divide-y divide-border rounded-xl border border-border' }, proxyScopeWrap),
|
|
1924
2144
|
);
|
|
1925
2145
|
|
|
1926
|
-
// ——
|
|
1927
|
-
//
|
|
1928
|
-
//
|
|
1929
|
-
//
|
|
1930
|
-
let
|
|
1931
|
-
let
|
|
1932
|
-
let
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
//
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
2146
|
+
// —— 代理链:链是独立实体,可关联多个供应商 ——
|
|
2147
|
+
// 每条链有自己的有序节点(headroom / 注入 / 自定义代理),顺序即执行顺序。
|
|
2148
|
+
// 关联到同一条链的供应商共用这份配置和一个转发器。
|
|
2149
|
+
// 只写 headroom.json 的 chainTarget,绝不改供应商 baseURL。
|
|
2150
|
+
let chainProviders = []; // ZCode 供应商列表(/title-gen/providers)
|
|
2151
|
+
let chainList = Array.isArray(config.proxyChains) ? JSON.parse(JSON.stringify(config.proxyChains)) : [];
|
|
2152
|
+
let chainShared = Array.isArray(config.sharedProxies) ? [...config.sharedProxies] : [];
|
|
2153
|
+
let chainLastRun = null;
|
|
2154
|
+
let chainHeadroomPort = 8787;
|
|
2155
|
+
let chainPorts = new Map(); // chainId → helper 实际分配的端口(新建的链配置里还没有 port)
|
|
2156
|
+
const chainStatusText = h('p', { class: 'mt-2 text-ui-xs/relaxed text-foreground-subtle' });
|
|
2157
|
+
const chainListWrap = h('div', { class: 'mt-3 flex flex-col gap-2' });
|
|
2158
|
+
|
|
2159
|
+
// —— 代理链总开关 ——
|
|
2160
|
+
// 默认关:升级装上代理链的老用户,供应商地址不被自动改动;想用链再打开
|
|
2161
|
+
//(升级时仍在用旧“逐家转发”的供应商会被转成链里的勾选,并自动打开)。
|
|
2162
|
+
// 关=一键还原:链配置原样保留,所有勾选供应商的地址还原为真实上游、停止转发。
|
|
2163
|
+
// 开=勾在链上的供应商地址按链入口对齐。保存立即触发对齐,稍后刷状态
|
|
2164
|
+
const chainMasterWrap = h('div', {});
|
|
2165
|
+
const renderChainMaster = () => {
|
|
2166
|
+
chainMasterWrap.replaceChildren(
|
|
2167
|
+
settingRow(L.chainMasterSwitch, L.chainMasterSwitchDesc, config.proxyChainEnabled === true, async () => {
|
|
2168
|
+
const next = config.proxyChainEnabled !== true;
|
|
2169
|
+
const res = await rpc('/config', { method: 'POST', body: { proxyChainEnabled: next } });
|
|
2170
|
+
if (res.ok && res.config) {
|
|
2171
|
+
config.proxyChainEnabled = res.config.proxyChainEnabled === true;
|
|
2172
|
+
clearConfigCache();
|
|
2173
|
+
} else {
|
|
2174
|
+
showToast(L.failed + ': ' + errText(res), 'error');
|
|
2175
|
+
}
|
|
2176
|
+
renderChainMaster();
|
|
2177
|
+
setTimeout(() => { void refreshChainStatus(); }, 1200);
|
|
2178
|
+
}),
|
|
2179
|
+
);
|
|
2180
|
+
};
|
|
2181
|
+
renderChainMaster();
|
|
2182
|
+
|
|
2183
|
+
// —— OpenCode Go 兼容(默认开)——
|
|
2184
|
+
// OpenCode Go 套餐的端点要求请求带会话请求头,ZCode 只在供应商地址正好是它的
|
|
2185
|
+
// 网址时才加;供应商走链(地址是本机 8787)时由 zcode-pro 的转发器补上。
|
|
2186
|
+
// 关掉后这类供应商经链会被端点拒绝,只能直连。改了下发到链转发器,立即生效
|
|
2187
|
+
const chainGoWrap = h('div', {});
|
|
2188
|
+
const renderChainGo = () => {
|
|
2189
|
+
chainGoWrap.replaceChildren(
|
|
2190
|
+
settingRow(L.chainGoCompat, L.chainGoCompatDesc, config.opencodeGoCompat !== false, async () => {
|
|
2191
|
+
const next = config.opencodeGoCompat === false;
|
|
2192
|
+
const res = await rpc('/config', { method: 'POST', body: { opencodeGoCompat: next } });
|
|
2193
|
+
if (res.ok && res.config) {
|
|
2194
|
+
config.opencodeGoCompat = res.config.opencodeGoCompat !== false;
|
|
2195
|
+
clearConfigCache();
|
|
2196
|
+
} else {
|
|
2197
|
+
showToast(L.failed + ': ' + errText(res), 'error');
|
|
2198
|
+
}
|
|
2199
|
+
renderChainGo();
|
|
2200
|
+
}),
|
|
2201
|
+
);
|
|
2202
|
+
};
|
|
2203
|
+
renderChainGo();
|
|
2204
|
+
|
|
2205
|
+
const fieldCls = 'h-7 rounded-lg border border-border bg-input px-2 text-ui-xs text-foreground outline-none transition-shadow placeholder:text-foreground-subtle focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40';
|
|
2206
|
+
const providerName = (id) => (chainProviders.find((x) => x.id === id) || {}).name || id;
|
|
2207
|
+
// 链的转发端口:以 helper 对齐结果为准(新建的链配置里还没有 port),其次配置值
|
|
2208
|
+
const chainPortOf = (c) => chainPorts.get(c.id) || c.port || null;
|
|
2209
|
+
|
|
2210
|
+
// 三段式代理编辑器(协议 + 地址 + 端口),共享代理与自定义节点共用
|
|
2211
|
+
const proxyFields = ({ url = '', onCommit }) => {
|
|
2212
|
+
const parsed = /^(https?):\/\/([^/:]+):(\d+)$/.exec(url || '');
|
|
2213
|
+
const protoSel = h('select', { class: fieldCls + ' shrink-0' },
|
|
2214
|
+
h('option', { value: 'http' }, 'http'),
|
|
2215
|
+
h('option', { value: 'https' }, 'https'));
|
|
2216
|
+
protoSel.value = parsed ? parsed[1] : 'http';
|
|
2217
|
+
const hostInput = h('input', {
|
|
2218
|
+
type: 'text', value: parsed ? parsed[2] : '', placeholder: '127.0.0.1',
|
|
2219
|
+
spellcheck: 'false', class: fieldCls + ' min-w-0 flex-1',
|
|
2220
|
+
});
|
|
2221
|
+
const portInput = h('input', {
|
|
2222
|
+
type: 'text', value: parsed ? parsed[3] : '', placeholder: '7890',
|
|
2223
|
+
spellcheck: 'false', class: fieldCls + ' w-16 shrink-0',
|
|
2224
|
+
});
|
|
2225
|
+
const commit = () => {
|
|
2226
|
+
const host = hostInput.value.trim();
|
|
2227
|
+
const portText = portInput.value.trim();
|
|
2228
|
+
if (!host && !portText) return;
|
|
2229
|
+
if (!host) { showToast(L.failed + ': ' + L.proxySharedInvalid, 'error'); return; }
|
|
2230
|
+
const portNum = portText === '' ? 7890 : Number(portText);
|
|
2231
|
+
if (portText !== '' && (!/^\d+$/.test(portText) || !Number.isInteger(portNum) || portNum < 1 || portNum > 65535)) {
|
|
2232
|
+
showToast(L.failed + ': ' + L.proxySharedInvalid, 'error');
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
onCommit(`${protoSel.value}://${host}:${portNum}`);
|
|
2236
|
+
};
|
|
2237
|
+
protoSel.addEventListener('change', commit);
|
|
2238
|
+
hostInput.addEventListener('change', commit);
|
|
2239
|
+
portInput.addEventListener('change', commit);
|
|
2240
|
+
return h('div', { class: 'flex min-w-0 flex-1 items-center gap-1' }, protoSel, hostInput, portInput);
|
|
2241
|
+
};
|
|
2242
|
+
|
|
2243
|
+
// —— 共享代理 ——
|
|
2244
|
+
const sharedWrap = h('div', { class: 'flex flex-col gap-1.5' });
|
|
2245
|
+
// 共享代理整表提交前先取服务端最新列表:弹窗长开时 chainShared 是打开
|
|
2246
|
+
// 那一刻的快照,直接拿它覆盖会把别处(另一窗口/同步拉取)的修改退回去。
|
|
2247
|
+
// mutate 在最新列表上算出目标列表,提交仍是整表(后端按全量校验)
|
|
2248
|
+
const saveShared = async (mutate) => {
|
|
2249
|
+
const cur = await rpc('/config');
|
|
2250
|
+
const fresh = (cur.ok && cur.config && Array.isArray(cur.config.sharedProxies))
|
|
2251
|
+
? JSON.parse(JSON.stringify(cur.config.sharedProxies))
|
|
2252
|
+
: chainShared.map((e) => JSON.parse(JSON.stringify(e)));
|
|
2253
|
+
const list = mutate(fresh);
|
|
2254
|
+
const res = await rpc('/config', { method: 'POST', body: { sharedProxies: list } });
|
|
1953
2255
|
if (!res.ok) { showToast(L.failed + ': ' + errText(res), 'error'); return false; }
|
|
1954
|
-
|
|
1955
|
-
if (
|
|
2256
|
+
chainShared = Array.isArray(res.config && res.config.sharedProxies) ? res.config.sharedProxies : list;
|
|
2257
|
+
if (res.config && Array.isArray(res.config.proxyChains)) chainList = res.config.proxyChains;
|
|
2258
|
+
renderShared();
|
|
2259
|
+
renderChains();
|
|
1956
2260
|
return true;
|
|
1957
2261
|
};
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
const renderVendorRows = () => {
|
|
1969
|
-
if (!vendorProviders.length) {
|
|
1970
|
-
vendorListWrap.replaceChildren(h('p', { class: 'px-3 py-3 text-ui-sm text-foreground-subtle' }, L.proxyVendorEmpty));
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
// 只列已添加的(配置里有的)供应商;名称取列表里的显示名,查不到就用 id
|
|
1974
|
-
const added = Object.keys(vendorProxyState);
|
|
1975
|
-
if (!added.length) {
|
|
1976
|
-
vendorListWrap.replaceChildren(h('p', { class: 'px-3 py-3 text-ui-sm text-foreground-subtle' }, L.proxyVendorEmpty));
|
|
1977
|
-
return;
|
|
1978
|
-
}
|
|
1979
|
-
const nameOf = (id) => (vendorProviders.find((x) => x.id === id) || {}).name || id;
|
|
1980
|
-
vendorListWrap.replaceChildren(...added.map((id) => {
|
|
1981
|
-
const st = vendorProxyState[id] || { enabled: false, proxy: '', port: 18731, upstream: null };
|
|
1982
|
-
// 代理地址拆成 协议 / 地址 / 端口 三段:存的是拼好的 http(s)://host:port,
|
|
1983
|
-
// 地址留空 = 跟随全局代理(与原来一致)。
|
|
1984
|
-
const parsed = /^(https?):\/\/([^/:]+):(\d+)$/.exec(st.proxy || '');
|
|
1985
|
-
const fieldCls = 'h-7 rounded-lg border border-border bg-input px-2 text-ui-xs text-foreground outline-none transition-shadow placeholder:text-foreground-subtle focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40';
|
|
1986
|
-
const protoSel = h('select', { class: fieldCls + ' shrink-0' },
|
|
1987
|
-
h('option', { value: 'http' }, 'http'),
|
|
1988
|
-
h('option', { value: 'https' }, 'https'));
|
|
1989
|
-
protoSel.value = parsed ? parsed[1] : 'http';
|
|
1990
|
-
const hostInput = h('input', {
|
|
1991
|
-
type: 'text', value: parsed ? parsed[2] : '', placeholder: L.proxyVendorHostPlaceholder,
|
|
1992
|
-
spellcheck: 'false', title: L.proxyVendorHost, class: fieldCls + ' min-w-0 flex-1',
|
|
2262
|
+
const renderShared = () => {
|
|
2263
|
+
const rows = chainShared.map((sp) => {
|
|
2264
|
+
const displayName = (sp.name && sp.name !== sp.url) ? sp.name : '';
|
|
2265
|
+
const nameInput = h('input', { type: 'text', value: displayName, placeholder: L.proxySharedName, spellcheck: 'false', class: fieldCls + ' w-24 shrink-0' });
|
|
2266
|
+
const fields = proxyFields({
|
|
2267
|
+
url: sp.url || '',
|
|
2268
|
+
onCommit: (url) => {
|
|
2269
|
+
const name = nameInput.value.trim();
|
|
2270
|
+
void saveShared((fresh) => fresh.map((e) => (e.id === sp.id ? { ...e, name: name || url, url } : e)));
|
|
2271
|
+
},
|
|
1993
2272
|
});
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
2273
|
+
nameInput.addEventListener('change', () => {
|
|
2274
|
+
const name = nameInput.value.trim();
|
|
2275
|
+
if (name === displayName) return;
|
|
2276
|
+
void saveShared((fresh) => fresh.map((e) => (e.id === sp.id ? { ...e, name: name || e.url, url: e.url } : e)));
|
|
1997
2277
|
});
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2278
|
+
return h('div', { class: 'flex items-center gap-1.5' },
|
|
2279
|
+
nameInput, fields,
|
|
2280
|
+
btnSmall(L.proxySharedDelete, () => { void saveShared((fresh) => fresh.filter((e) => e.id !== sp.id)); }, 'shrink-0'));
|
|
2281
|
+
});
|
|
2282
|
+
sharedWrap.replaceChildren(
|
|
2283
|
+
...rows,
|
|
2284
|
+
...(chainShared.length ? [] : [h('p', { class: 'text-ui-xs/relaxed text-foreground-subtle' }, L.proxySharedEmpty)]),
|
|
2285
|
+
h('div', { class: 'flex justify-end' },
|
|
2286
|
+
btnSmall('+ ' + L.proxySharedAdd, () => {
|
|
2287
|
+
const id = `sp${Date.now().toString(36)}`;
|
|
2288
|
+
void saveShared((fresh) => [...fresh, { id, name: '', url: 'http://127.0.0.1:7890' }]);
|
|
2289
|
+
}, 'shrink-0')),
|
|
2290
|
+
);
|
|
2291
|
+
};
|
|
2292
|
+
|
|
2293
|
+
// —— 代理链 ——
|
|
2294
|
+
// 链整表提交前先取服务端最新列表(理由同 saveShared)。供应商勾选框
|
|
2295
|
+
// 的增删以最新列表里该链的 providers 为底,避免把对齐摘掉的已删供应商
|
|
2296
|
+
// 用旧快照写回去
|
|
2297
|
+
const saveChains = async (mutate) => {
|
|
2298
|
+
const cur = await rpc('/config');
|
|
2299
|
+
const fresh = (cur.ok && cur.config && Array.isArray(cur.config.proxyChains))
|
|
2300
|
+
? JSON.parse(JSON.stringify(cur.config.proxyChains))
|
|
2301
|
+
: chainList.map((c) => JSON.parse(JSON.stringify(c)));
|
|
2302
|
+
const list = mutate(fresh);
|
|
2303
|
+
// 取消勾选即退出压缩:对被移出链的供应商删 headroom 登记并还原 baseUrl
|
|
2304
|
+
//(勾回来时对齐的自动登记会补上,跨链移动=先退再进,中间窗口无害)
|
|
2305
|
+
const removed = [];
|
|
2306
|
+
for (const before of fresh) {
|
|
2307
|
+
const after = list.find((c) => c.id === before.id);
|
|
2308
|
+
if (!after) {
|
|
2309
|
+
// 整条链被删:它勾着的供应商全部退出(删链=退出压缩,与取消勾选同语义)
|
|
2310
|
+
for (const pid of before.providers || []) {
|
|
2311
|
+
if (!removed.includes(pid)) removed.push(pid);
|
|
2006
2312
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2313
|
+
continue;
|
|
2314
|
+
}
|
|
2315
|
+
for (const pid of before.providers || []) {
|
|
2316
|
+
if (!(after.providers || []).includes(pid) && !removed.includes(pid)) removed.push(pid);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
const res = await rpc('/config', { method: 'POST', body: { proxyChains: list } });
|
|
2320
|
+
if (!res.ok) { showToast(L.failed + ': ' + errText(res), 'error'); return false; }
|
|
2321
|
+
chainList = Array.isArray(res.config && res.config.proxyChains) ? res.config.proxyChains : list;
|
|
2322
|
+
if (removed.length) {
|
|
2323
|
+
void rpc('/headroom/restore', { method: 'POST', body: { ids: removed } }).then((r) => {
|
|
2324
|
+
if (!r.ok) showToast(L.chainLeaveHint + ': ' + errText(r), 'warning');
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
renderChains();
|
|
2328
|
+
setTimeout(() => { void refreshChainStatus(); }, 1200);
|
|
2329
|
+
return true;
|
|
2330
|
+
};
|
|
2331
|
+
const updateChain = (id, patch) => saveChains((fresh) => fresh.map((c) => (c.id === id ? { ...c, ...patch } : c)));
|
|
2332
|
+
// 删链先确认:一点就删、而且链上勾选的供应商会全部还原成直连并退出 headroom,
|
|
2333
|
+
// 误触的代价太大(出过一次:叠着的两个弹窗里,点击落到了底下那个的删除按钮上)。
|
|
2334
|
+
// 用贴着按钮的确认小弹窗(confirmTip),不另开全局对话框
|
|
2335
|
+
const confirmDeleteChain = (c, anchor) => {
|
|
2336
|
+
const n = (c.providers || []).length;
|
|
2337
|
+
confirmTip(anchor, {
|
|
2338
|
+
title: L.chainDeleteConfirmTitle,
|
|
2339
|
+
desc: n > 0 ? L.chainDeleteConfirmDesc.replace('{n}', String(n)) : L.chainDeleteConfirmDescEmpty,
|
|
2340
|
+
confirmLabel: L.chainDeleteConfirmGo,
|
|
2341
|
+
onConfirm: () => { void saveChains((fresh) => fresh.filter((x) => x.id !== c.id)); },
|
|
2342
|
+
});
|
|
2343
|
+
};
|
|
2344
|
+
|
|
2345
|
+
const renderChains = () => {
|
|
2346
|
+
if (!chainList.length) {
|
|
2347
|
+
chainListWrap.replaceChildren(h('p', { class: 'rounded-xl border border-border px-3 py-3 text-ui-sm text-foreground-subtle' }, L.chainEmpty));
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
chainListWrap.replaceChildren(...chainList.map((c) => {
|
|
2351
|
+
const nodes = Array.isArray(c.nodes) ? c.nodes : [];
|
|
2352
|
+
const chainRows = [];
|
|
2353
|
+
|
|
2354
|
+
const rowEl = (index, label, right, opts = {}) => h('div', {
|
|
2355
|
+
class: 'flex items-center gap-2 rounded-lg px-2 py-0.5 ' + (opts.muted ? 'opacity-50' : ''),
|
|
2356
|
+
},
|
|
2357
|
+
h('span', { class: 'w-4 shrink-0 text-ui-xs text-foreground-subtle' }, String(index)),
|
|
2358
|
+
h('span', { class: 'w-24 shrink-0 text-ui-xs text-foreground-subtle' }, label),
|
|
2359
|
+
h('div', { class: 'min-w-0 flex-1' }, right),
|
|
2360
|
+
...(opts.actions || []));
|
|
2361
|
+
|
|
2362
|
+
// 锁定图标:lucide 描边(与翻译面板一致),不用 emoji
|
|
2363
|
+
const lockIcon = () => {
|
|
2364
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
2365
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
2366
|
+
svg.setAttribute('fill', 'none');
|
|
2367
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
2368
|
+
svg.setAttribute('stroke-width', '2');
|
|
2369
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
2370
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
2371
|
+
svg.setAttribute('width', '12');
|
|
2372
|
+
svg.setAttribute('height', '12');
|
|
2373
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
2374
|
+
svg.innerHTML = '<rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/>';
|
|
2375
|
+
return svg;
|
|
2376
|
+
};
|
|
2377
|
+
const pinned = () => h('span', { class: 'inline-flex shrink-0 items-center opacity-40', title: L.chainNodePinned }, lockIcon());
|
|
2378
|
+
|
|
2379
|
+
nodes.forEach((n, i) => {
|
|
2380
|
+
const move = async (delta) => {
|
|
2381
|
+
const j = i + delta;
|
|
2382
|
+
if (j < 0 || j >= nodes.length) return;
|
|
2383
|
+
const list = nodes.slice();
|
|
2384
|
+
[list[i], list[j]] = [list[j], list[i]];
|
|
2385
|
+
await updateChain(c.id, { nodes: list });
|
|
2386
|
+
};
|
|
2387
|
+
const actions = [
|
|
2388
|
+
btnSmall('↑', () => { void move(-1); }, 'shrink-0' + (i === 0 ? ' opacity-30' : '')),
|
|
2389
|
+
btnSmall('↓', () => { void move(1); }, 'shrink-0' + (i === nodes.length - 1 ? ' opacity-30' : '')),
|
|
2390
|
+
btnSmall(L.proxyVendorRemove, () => {
|
|
2391
|
+
void updateChain(c.id, { nodes: nodes.filter((_, k) => k !== i) });
|
|
2392
|
+
}, 'shrink-0'),
|
|
2393
|
+
];
|
|
2394
|
+
if (n.type === 'headroom') {
|
|
2395
|
+
chainRows.push(rowEl(chainRows.length + 1, 'headroom',
|
|
2396
|
+
h('span', { class: 'text-ui-xs text-foreground-subtle' }, `127.0.0.1:${chainHeadroomPort}`),
|
|
2397
|
+
{ actions }));
|
|
2010
2398
|
return;
|
|
2011
2399
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
showToast(L.failed + ': ' + L.proxyVendorPortInvalid, 'error');
|
|
2016
|
-
portInput.focus();
|
|
2400
|
+
if (n.type === 'inject') {
|
|
2401
|
+
// 注入功能没有启停开关(在链里勾选就是唯一开关),这一行不再显示启停状态
|
|
2402
|
+
chainRows.push(rowEl(chainRows.length + 1, L.proxyChainInjection, null, { actions }));
|
|
2017
2403
|
return;
|
|
2018
2404
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2405
|
+
// 自定义代理节点
|
|
2406
|
+
const hit = n.proxyId ? chainShared.find((e) => e.id === n.proxyId) : null;
|
|
2407
|
+
const sel = h('select', { class: fieldCls + ' w-28 shrink-0' },
|
|
2408
|
+
h('option', { value: '' }, L.proxyChainCustom),
|
|
2409
|
+
...chainShared.map((sp) => h('option', { value: 'sp:' + sp.id }, sp.name || sp.url)));
|
|
2410
|
+
sel.value = n.proxyId ? 'sp:' + n.proxyId : '';
|
|
2411
|
+
const sharedView = h('span', {
|
|
2412
|
+
class: 'min-w-0 flex-1 truncate text-ui-xs text-foreground-subtle',
|
|
2413
|
+
title: hit ? hit.url : '',
|
|
2414
|
+
}, hit ? hit.url : (n.proxyId ? L.proxyChainSharedGone : ''));
|
|
2415
|
+
const fields = proxyFields({
|
|
2416
|
+
url: n.proxyId ? '' : (n.proxy || ''),
|
|
2417
|
+
onCommit: (v) => {
|
|
2418
|
+
const list = nodes.slice();
|
|
2419
|
+
list[i] = { type: 'custom', proxy: v };
|
|
2420
|
+
void updateChain(c.id, { nodes: list });
|
|
2421
|
+
},
|
|
2422
|
+
});
|
|
2423
|
+
fields.style.display = n.proxyId ? 'none' : '';
|
|
2424
|
+
sharedView.style.display = n.proxyId ? '' : 'none';
|
|
2425
|
+
sel.addEventListener('change', () => {
|
|
2426
|
+
const list = nodes.slice();
|
|
2427
|
+
list[i] = sel.value ? { type: 'custom', proxyId: sel.value.slice(3) } : { type: 'custom', proxy: '' };
|
|
2428
|
+
void updateChain(c.id, { nodes: list });
|
|
2429
|
+
});
|
|
2430
|
+
// 不显示「自定义」文本:把来源下拉放在原来 label 的位置
|
|
2431
|
+
chainRows.push(h('div', { class: 'flex items-center gap-2 rounded-lg px-2 py-0.5' },
|
|
2432
|
+
h('span', { class: 'w-4 shrink-0 text-ui-xs text-foreground-subtle' }, String(chainRows.length + 1)),
|
|
2433
|
+
sel,
|
|
2434
|
+
h('div', { class: 'flex min-w-0 flex-1 items-center gap-1.5' }, sharedView, fields),
|
|
2435
|
+
...actions));
|
|
2436
|
+
});
|
|
2437
|
+
|
|
2438
|
+
// 关联的供应商:多选,勾上即归属这条链
|
|
2439
|
+
const owner = new Map();
|
|
2440
|
+
for (const other of chainList) {
|
|
2441
|
+
for (const pid of other.providers || []) owner.set(pid, other.id);
|
|
2442
|
+
}
|
|
2443
|
+
// ZCode 自带的套餐供应商(id 以 builtin: 开头,比如 Start Plan、Coding Plan)不在
|
|
2444
|
+
// 可勾选列表里:链只改 provider_config.json 里有条目的供应商的地址,自带的没有条目,
|
|
2445
|
+
// 勾上也不会走链。已经在某条链里的照常显示,用户能看到并取消
|
|
2446
|
+
const selectableProviders = chainProviders.filter((p) => !String(p.id || '').startsWith('builtin:') || (c.providers || []).includes(p.id));
|
|
2447
|
+
const provBox = h('div', { class: 'mt-1 flex flex-wrap gap-x-3 gap-y-1' },
|
|
2448
|
+
...selectableProviders.map((p) => {
|
|
2449
|
+
const ownedByOther = owner.has(p.id) && owner.get(p.id) !== c.id;
|
|
2450
|
+
const box = h('input', {
|
|
2451
|
+
type: 'checkbox',
|
|
2452
|
+
...(ownedByOther ? { disabled: 'true', title: L.chainOwnedByOther } : {}),
|
|
2453
|
+
});
|
|
2454
|
+
box.checked = (c.providers || []).includes(p.id);
|
|
2455
|
+
box.addEventListener('change', () => {
|
|
2456
|
+
void saveChains((fresh) => fresh.map((ch) => {
|
|
2457
|
+
if (ch.id !== c.id) return ch;
|
|
2458
|
+
const cur = new Set(ch.providers || []);
|
|
2459
|
+
if (box.checked) cur.add(p.id); else cur.delete(p.id);
|
|
2460
|
+
return { ...ch, providers: [...cur] };
|
|
2461
|
+
}));
|
|
2462
|
+
});
|
|
2463
|
+
return h('label', { class: 'flex items-center gap-1 text-ui-xs' + (ownedByOther ? ' opacity-40' : '') },
|
|
2464
|
+
box, h('span', {}, p.name || p.id));
|
|
2465
|
+
}),
|
|
2466
|
+
...(selectableProviders.length ? [] : [h('span', { class: 'text-ui-xs text-foreground-subtle' }, L.chainNoProviders)]));
|
|
2467
|
+
|
|
2468
|
+
const head = h('div', { class: 'flex items-center gap-2' },
|
|
2469
|
+
h('input', {
|
|
2470
|
+
type: 'text', value: c.name || c.id, spellcheck: 'false',
|
|
2471
|
+
class: 'min-w-0 flex-1 rounded-lg border border-border bg-input px-2 py-1 text-ui-sm font-medium text-foreground outline-none',
|
|
2472
|
+
}).also?.() || h('input', {
|
|
2473
|
+
type: 'text', value: c.name || c.id, spellcheck: 'false',
|
|
2474
|
+
class: 'min-w-0 flex-1 rounded-lg border border-border bg-input px-2 py-1 text-ui-sm font-medium text-foreground outline-none',
|
|
2475
|
+
onChange: (e) => { void updateChain(c.id, { name: e.target.value.trim() || c.id }); },
|
|
2476
|
+
}),
|
|
2477
|
+
h('button', {
|
|
2478
|
+
type: 'button', role: 'switch', 'aria-checked': String(c.enabled !== false),
|
|
2479
|
+
title: L.chainSwitchHint,
|
|
2480
|
+
class: 'relative inline-flex shrink-0 cursor-pointer items-center',
|
|
2481
|
+
onClick: () => { void updateChain(c.id, { enabled: c.enabled === false }); },
|
|
2482
|
+
}, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': c.enabled !== false ? 'on' : 'off' },
|
|
2483
|
+
h('span', { class: 'zcodepro-switch-knob' }))),
|
|
2484
|
+
btnSmall(L.proxyVendorRemove, (e) => { confirmDeleteChain(c, e.currentTarget); }, 'shrink-0'),
|
|
2485
|
+
);
|
|
2486
|
+
|
|
2487
|
+
const addNode = (type) => {
|
|
2488
|
+
const list = nodes.slice();
|
|
2489
|
+
list.push(type === 'custom' ? { type: 'custom', proxy: '' } : { type });
|
|
2490
|
+
void updateChain(c.id, { nodes: list });
|
|
2025
2491
|
};
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
if (await saveVendorProxy(id, { enabled: next })) {
|
|
2042
|
-
refreshVendorView();
|
|
2043
|
-
setTimeout(() => { void refreshVendorProxyStatus(); }, 400);
|
|
2044
|
-
}
|
|
2045
|
-
},
|
|
2046
|
-
}, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': st.enabled ? 'on' : 'off' },
|
|
2047
|
-
h('span', { class: 'zcodepro-switch-knob' }))),
|
|
2048
|
-
// 文字按钮(与 vision 标签页的移除按钮一致),比一个 × 好点
|
|
2049
|
-
btnSmall(L.proxyVendorRemove, () => { void removeVendorProxy(id); }, 'shrink-0'),
|
|
2050
|
-
);
|
|
2051
|
-
return h('div', { class: 'px-2 py-1.5' },
|
|
2052
|
-
row,
|
|
2053
|
-
h('div', { class: 'mt-1 flex items-center gap-1.5 pl-0.5' }, protoSel, hostInput, portInput));
|
|
2492
|
+
const addRow = h('div', { class: 'mt-1 flex flex-wrap items-center justify-end gap-1.5' },
|
|
2493
|
+
...(nodes.some((n) => n.type === 'headroom') ? [] : [btnSmall('+ headroom', () => addNode('headroom'), 'shrink-0')]),
|
|
2494
|
+
...(nodes.some((n) => n.type === 'inject') ? [] : [btnSmall('+ ' + L.proxyChainInjection, () => addNode('inject'), 'shrink-0')]),
|
|
2495
|
+
btnSmall('+ ' + L.proxyChainAddNode, () => addNode('custom'), 'shrink-0'));
|
|
2496
|
+
|
|
2497
|
+
return h('div', { class: 'rounded-xl border border-border px-2.5 py-2' },
|
|
2498
|
+
head,
|
|
2499
|
+
h('div', { class: 'mt-1 flex flex-col' }, ...chainRows),
|
|
2500
|
+
addRow,
|
|
2501
|
+
h('div', { class: 'mt-2 border-t border-border pt-1.5' },
|
|
2502
|
+
h('div', { class: 'text-ui-xs text-foreground-subtle' }, L.chainProvidersLabel),
|
|
2503
|
+
provBox),
|
|
2504
|
+
h('div', { class: 'mt-1 text-ui-xs text-foreground-subtle' },
|
|
2505
|
+
`${L.chainForwardPort} ${chainPortOf(c) || '—'}`),
|
|
2506
|
+
);
|
|
2054
2507
|
}));
|
|
2055
2508
|
};
|
|
2056
|
-
|
|
2509
|
+
|
|
2510
|
+
const refreshChainStatus = async () => {
|
|
2057
2511
|
const res = await rpc('/provider-proxies/status');
|
|
2058
2512
|
if (!res.ok) return;
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
const
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
// 工具名合规检查:设置页按钮一行,跑完显示一行结果
|
|
2069
|
-
const toolNameState = h('p', { class: 'mt-2 text-ui-xs/relaxed text-foreground-subtle' });
|
|
2070
|
-
let toolNameBusy = false;
|
|
2071
|
-
const toolNameBtn = btnSmall(L.toolNameCheckBtn, () => { void runToolNameCheck(); }, 'shrink-0', 'primary');
|
|
2072
|
-
const runToolNameCheck = async () => {
|
|
2073
|
-
if (toolNameBusy) return;
|
|
2074
|
-
toolNameBusy = true;
|
|
2075
|
-
toolNameBtn.disabled = true;
|
|
2076
|
-
toolNameBtn.textContent = L.toolNameCheckRunning;
|
|
2077
|
-
toolNameState.textContent = '';
|
|
2078
|
-
toolNameState.className = 'mt-2 text-ui-xs/relaxed text-foreground-subtle';
|
|
2079
|
-
const res = await rpc('/tool-names/check', { method: 'POST', body: {} });
|
|
2080
|
-
toolNameBusy = false;
|
|
2081
|
-
toolNameBtn.disabled = false;
|
|
2082
|
-
toolNameBtn.textContent = L.toolNameCheckBtn;
|
|
2083
|
-
if (!res.ok) {
|
|
2084
|
-
toolNameState.className = 'mt-2 text-ui-xs/relaxed text-destructive';
|
|
2085
|
-
toolNameState.textContent = L.toolNameCheckFailed + ': ' + errText(res);
|
|
2086
|
-
return;
|
|
2513
|
+
chainLastRun = res.chainLastRun || null;
|
|
2514
|
+
// 链列表以服务端为准:对齐可能改了它(比如供应商地址被手动改过,自动退出了链)
|
|
2515
|
+
const cfgRes = await rpc('/config');
|
|
2516
|
+
if (cfgRes.ok && cfgRes.config && Array.isArray(cfgRes.config.proxyChains)) chainList = cfgRes.config.proxyChains;
|
|
2517
|
+
if (Number.isFinite(Number(res.headroomPort))) chainHeadroomPort = Number(res.headroomPort);
|
|
2518
|
+
// 端口以对齐结果为准:新建的链配置里没有 port,helper 拉起转发器后才分配
|
|
2519
|
+
chainPorts = new Map();
|
|
2520
|
+
for (const s of (chainLastRun && chainLastRun.started) || []) {
|
|
2521
|
+
if (s && s.id && Number.isFinite(Number(s.port))) chainPorts.set(s.id, Number(s.port));
|
|
2087
2522
|
}
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
if (!res.ok) { showToast(L.failed + ': ' + errText(res), 'error'); return; }
|
|
2099
|
-
toolNameAutoOn = (res.config && typeof res.config.toolNameAuto === 'boolean') ? res.config.toolNameAuto : next;
|
|
2100
|
-
renderToolNameAuto();
|
|
2101
|
-
};
|
|
2102
|
-
toolNameAutoWrap.replaceChildren(
|
|
2103
|
-
h('span', { class: 'text-ui-xs text-foreground-subtle', title: L.toolNameAutoDesc }, L.toolNameAuto),
|
|
2104
|
-
h('button', {
|
|
2105
|
-
type: 'button', role: 'switch', 'aria-checked': String(toolNameAutoOn),
|
|
2106
|
-
class: 'relative inline-flex shrink-0 cursor-pointer items-center',
|
|
2107
|
-
title: L.toolNameAutoDesc,
|
|
2108
|
-
onClick: () => { void toggle(); },
|
|
2109
|
-
}, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': toolNameAutoOn ? 'on' : 'off' },
|
|
2110
|
-
h('span', { class: 'zcodepro-switch-knob' }))),
|
|
2111
|
-
);
|
|
2523
|
+
renderChains();
|
|
2524
|
+
const errs = (chainLastRun && chainLastRun.errors) || [];
|
|
2525
|
+
chainStatusText.className = 'mt-2 text-ui-xs/relaxed ' + (errs.length ? 'text-amber-500' : 'text-foreground-subtle');
|
|
2526
|
+
// 总开关关闭时链全部不生效,优先提示这个(比对齐报错更可能是用户想找的答案)
|
|
2527
|
+
const auto = (chainLastRun && chainLastRun.autoUnchecked) || [];
|
|
2528
|
+
const autoText = auto.length
|
|
2529
|
+
? L.chainAutoUnchecked.replace('{list}', auto.map((a) => `${providerName(a.id)} → ${a.url}`).join(';'))
|
|
2530
|
+
: '';
|
|
2531
|
+
chainStatusText.textContent = errs.length ? errs.join(';')
|
|
2532
|
+
: (config.proxyChainEnabled !== true ? L.chainMasterOffHint : autoText);
|
|
2112
2533
|
};
|
|
2113
|
-
renderToolNameAuto();
|
|
2114
2534
|
|
|
2115
|
-
// “添加供应商”下拉:只列还没添加的供应商(已添加的不重复出现)。
|
|
2116
|
-
// 选中后建一条默认关闭的条目,用户再打开开关才真正生效。
|
|
2117
|
-
const addVendorWrap = h('div', { class: 'mt-2' });
|
|
2118
|
-
const renderAddVendor = () => {
|
|
2119
|
-
const available = vendorProviders.filter((p) => !vendorProxyState[p.id]);
|
|
2120
|
-
if (!available.length) { addVendorWrap.replaceChildren(); return; }
|
|
2121
|
-
const sel = h('select', {
|
|
2122
|
-
class: 'h-7 w-full rounded-lg border border-border bg-input px-2 text-ui-xs text-foreground outline-none',
|
|
2123
|
-
}, h('option', { value: '' }, '+ ' + L.proxyVendorAdd),
|
|
2124
|
-
...available.map((p) => h('option', { value: p.id }, p.name || p.id)));
|
|
2125
|
-
sel.addEventListener('change', async () => {
|
|
2126
|
-
const id = sel.value;
|
|
2127
|
-
if (!id) return;
|
|
2128
|
-
await addVendorProxy(id);
|
|
2129
|
-
renderAddVendor();
|
|
2130
|
-
});
|
|
2131
|
-
addVendorWrap.replaceChildren(sel);
|
|
2132
|
-
};
|
|
2133
|
-
// 上方的删除/添加要用同一个刷新入口:放在这里定义,闭包能同时看到两个渲染函数
|
|
2134
|
-
refreshVendorView = () => { renderVendorRows(); renderAddVendor(); };
|
|
2135
2535
|
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
h('div', { class: '
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2536
|
+
proxyChainPane.append(
|
|
2537
|
+
// 说明放最上面(二级页签正下方):链怎么工作 + 勾选的规则都在这一块,全页只写一次
|
|
2538
|
+
//(以前这两行规则挂在每条链下,几条链就重复几遍)
|
|
2539
|
+
h('p', { class: 'mt-2 text-ui-sm/relaxed text-foreground-subtle' }, L.chainDesc),
|
|
2540
|
+
h('div', { class: 'mt-1 text-ui-xs/relaxed text-foreground-subtle' }, L.chainProvidersHint),
|
|
2541
|
+
h('div', { class: 'text-ui-xs/relaxed text-foreground-subtle' }, L.chainManualEditHint),
|
|
2542
|
+
h('div', { class: 'mt-3 rounded-xl border border-border p-1' }, chainMasterWrap),
|
|
2543
|
+
h('div', { class: 'mt-2 rounded-xl border border-border p-1' }, chainGoWrap),
|
|
2544
|
+
h('div', { class: 'mt-3 rounded-xl border border-border p-3' },
|
|
2545
|
+
h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.proxySharedTitle),
|
|
2546
|
+
h('p', { class: 'mt-1 text-ui-xs/relaxed text-foreground-subtle' }, L.proxySharedDesc),
|
|
2547
|
+
h('div', { class: 'mt-2' }, sharedWrap)),
|
|
2548
|
+
chainListWrap,
|
|
2549
|
+
h('div', { class: 'mt-2 flex justify-end' },
|
|
2550
|
+
btnSmall('+ ' + L.chainAdd, () => {
|
|
2551
|
+
const id = `chain${Date.now().toString(36)}`;
|
|
2552
|
+
// 没装 headroom 插件时默认模板不带 headroom 节点——带了整条链会被跳过,
|
|
2553
|
+
// 新建出来就是哑的;装了插件(或读不到安装状态)才按 压缩 + 注入 起步
|
|
2554
|
+
void (async () => {
|
|
2555
|
+
let nodes = [{ type: 'headroom' }, { type: 'inject' }];
|
|
2556
|
+
try {
|
|
2557
|
+
const meta = await rpc('/headroom');
|
|
2558
|
+
if (meta && meta.ok && !meta.hook) nodes = [{ type: 'inject' }];
|
|
2559
|
+
} catch { /* 读不到按带 headroom 的模板,节点可以随时增删 */ }
|
|
2560
|
+
void saveChains((fresh) => [...fresh, { id, name: L.chainDefaultName, providers: [], nodes, enabled: true }]);
|
|
2561
|
+
})();
|
|
2562
|
+
}, 'shrink-0', 'primary')),
|
|
2563
|
+
chainStatusText,
|
|
2146
2564
|
);
|
|
2147
|
-
|
|
2148
|
-
|
|
2565
|
+
renderShared();
|
|
2566
|
+
renderChains();
|
|
2149
2567
|
void (async () => {
|
|
2150
|
-
const
|
|
2151
|
-
if (provRes.ok && Array.isArray(provRes.providers))
|
|
2152
|
-
|
|
2153
|
-
refreshVendorView();
|
|
2568
|
+
const provRes = await rpc('/title-gen/providers');
|
|
2569
|
+
if (provRes.ok && Array.isArray(provRes.providers)) chainProviders = provRes.providers;
|
|
2570
|
+
renderChains();
|
|
2154
2571
|
})();
|
|
2572
|
+
void refreshChainStatus();
|
|
2155
2573
|
|
|
2156
2574
|
// “性能”:空闲项目内存回收(开关 + 两个时长)与子代理活动判定时长。
|
|
2157
2575
|
// idleReclaimStartupMinutes 允许 0(启动后立即回收一次),取值不能用
|
|
@@ -2831,39 +3249,38 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
2831
3249
|
}, i === visionCfg.proxies.length - 1 ? 'pointer-events-none opacity-40' : ''),
|
|
2832
3250
|
smallBtn(L.visionRemove, () => { visionCfg.proxies.splice(i, 1); void persistVision(); renderVision(); }),
|
|
2833
3251
|
),
|
|
2834
|
-
|
|
2835
|
-
//
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
3252
|
+
(() => {
|
|
3253
|
+
// 供应商 + 模型 + 思考级别走统一封装(与翻译页、自动重命名同一实现)
|
|
3254
|
+
const pmt = providerModelThinkingFields({
|
|
3255
|
+
providers: titleGenProviders,
|
|
3256
|
+
L,
|
|
3257
|
+
provider: p.useProvider || '',
|
|
3258
|
+
model: p.model || '',
|
|
3259
|
+
thinking: p.thinking || 'off',
|
|
3260
|
+
sessionInfo: translateSessionRes.ok ? translateSessionRes.session : null,
|
|
3261
|
+
withManual: true,
|
|
3262
|
+
labels: { provider: L.visionUseProvider, model: L.visionModel, thinking: L.translateThinking },
|
|
3263
|
+
onChange: (patch) => {
|
|
3264
|
+
p.useProvider = patch.provider;
|
|
3265
|
+
p.model = patch.model;
|
|
3266
|
+
p.thinking = patch.thinking;
|
|
2841
3267
|
saveVisionSoon();
|
|
2842
|
-
// 下拉切换后重渲染整个面板:模型下拉选项随新供应商变化,接口
|
|
2843
|
-
// 地址/API Key 字段按“不跟随或供应商已删才显示”重新显隐
|
|
2844
|
-
if (src === 'select') renderVision();
|
|
2845
3268
|
},
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
//
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
followSession: (p.useProvider || '').trim() === 'session',
|
|
2852
|
-
followSessionLabel: L.titleGenModelFollowSession,
|
|
2853
|
-
}),
|
|
2854
|
-
(v) => { p.model = v; saveVisionSoon(); },
|
|
2855
|
-
{
|
|
2856
|
-
placeholder: modelPlaceholderOf(p.useProvider, L),
|
|
2857
|
-
emptyLabel: (p.useProvider || '').trim() === 'session'
|
|
2858
|
-
? L.titleGenModelFollowSession : L.titleGenModelEmpty,
|
|
2859
|
-
})),
|
|
2860
|
-
),
|
|
3269
|
+
requestRender: () => renderVision(),
|
|
3270
|
+
});
|
|
3271
|
+
// 三件套一行显示(与自动重命名页一致):窄屏单列、sm 以上三列
|
|
3272
|
+
return h('div', { class: 'mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3' }, ...pmt.fields);
|
|
3273
|
+
})(),
|
|
2861
3274
|
...manualConnCard,
|
|
2862
3275
|
(() => {
|
|
2863
3276
|
const n = h('textarea', { class: 'zcodepro-textarea zcodepro-textarea-sm', rows: '3', placeholder: L.visionPrompt });
|
|
2864
3277
|
n.value = p.prompt || '';
|
|
2865
3278
|
n.addEventListener('input', () => { p.prompt = n.value; saveVisionSoon(); });
|
|
2866
|
-
|
|
3279
|
+
// 上间距:与上方三件套/手动连接卡之间留出空隙(原来紧贴)。
|
|
3280
|
+
// 加在外层 label 上而不是 textarea,保证标签文字也跟着下移
|
|
3281
|
+
const f = field(L.visionPrompt, n);
|
|
3282
|
+
f.classList.add('mt-2');
|
|
3283
|
+
return f;
|
|
2867
3284
|
})(),
|
|
2868
3285
|
]);
|
|
2869
3286
|
});
|
|
@@ -3051,29 +3468,8 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
3051
3468
|
// 默认通道(LLM):供应商与模型照视觉代理页的接法(下拉+手输),
|
|
3052
3469
|
// 但不含“不跟随(自填地址)”——翻译通道只认 会话/供应商 两种来源
|
|
3053
3470
|
const chNow = () => (translateRes.config && translateRes.config.channel) || {};
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
[{ value: 'session', label: L.titleGenProviderSession }, ...titleGenProviders.map((p) => ({ value: p.id, label: p.name }))],
|
|
3057
|
-
(v, src) => {
|
|
3058
|
-
const c = chNow();
|
|
3059
|
-
persist({ channel: { ...c, type: 'llm', provider: v, model: v === 'session' ? '' : c.model } });
|
|
3060
|
-
if (src === 'select') renderTranslate();
|
|
3061
|
-
},
|
|
3062
|
-
{ staleLabel: L.titleGenProviderDeleted }));
|
|
3063
|
-
const modelField = field(L.translateModelLabel, comboField(
|
|
3064
|
-
chNow().model || '',
|
|
3065
|
-
modelOptionsOf(chNow().provider || 'session', titleGenProviders, {
|
|
3066
|
-
followSession: (chNow().provider || 'session') === 'session',
|
|
3067
|
-
followSessionLabel: L.titleGenModelFollowSession,
|
|
3068
|
-
}),
|
|
3069
|
-
(v, src) => {
|
|
3070
|
-
const cur = chNow();
|
|
3071
|
-
// 换模型后重绘整页:思考档位跟着所选模型变
|
|
3072
|
-
translateRes.config = { ...translateRes.config, channel: { ...cur, model: v.trim() } };
|
|
3073
|
-
persist({ channel: { ...cur, model: v.trim() } });
|
|
3074
|
-
if (src === 'select') renderTranslate();
|
|
3075
|
-
},
|
|
3076
|
-
{ placeholder: modelPlaceholderOf(chNow().provider || 'session', L) }));
|
|
3471
|
+
// 供应商 + 模型 + 思考级别在三处共用同一封装(见 provider-model-thinking.js)
|
|
3472
|
+
|
|
3077
3473
|
// 通用设置放最前(一行三个);翻译服务 = AI 翻译或某家机翻,选哪个
|
|
3078
3474
|
// 出现哪组选项(AI:供应商/模型/思考等级;机翻:该服务的密钥)
|
|
3079
3475
|
const ch0 = chNow();
|
|
@@ -3098,18 +3494,27 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
3098
3494
|
return [id, mtServiceName(id) + (s2 && !s2.configured ? '(' + L.translateUnconfigured + ')' : '')];
|
|
3099
3495
|
}),
|
|
3100
3496
|
], (v) => { if (v === 'llm') setChannel({ type: 'llm' }); else setChannel({ type: 'mt', service: v }); });
|
|
3497
|
+
// 三件套:供应商 / 模型 / 思考级别(统一封装,档位随模型自适应)
|
|
3498
|
+
const translatePmt = providerModelThinkingFields({
|
|
3499
|
+
providers: titleGenProviders,
|
|
3500
|
+
L,
|
|
3501
|
+
provider: ch0.provider || 'session',
|
|
3502
|
+
model: ch0.model || '',
|
|
3503
|
+
thinking: ch0.thinking || 'off',
|
|
3504
|
+
sessionInfo: translateSessionRes.ok ? translateSessionRes.session : null,
|
|
3505
|
+
// 翻译通道不提供“不跟随(自填地址)”:只认 会话/供应商 两种来源
|
|
3506
|
+
withManual: false,
|
|
3507
|
+
labels: { provider: L.translateProvider, model: L.translateModelLabel, thinking: L.translateThinking },
|
|
3508
|
+
onChange: (patch) => {
|
|
3509
|
+
const merged = { ...chNow(), type: 'llm', ...patch };
|
|
3510
|
+
translateRes.config = { ...translateRes.config, channel: merged };
|
|
3511
|
+
persist({ channel: merged });
|
|
3512
|
+
},
|
|
3513
|
+
requestRender: () => renderTranslate(),
|
|
3514
|
+
});
|
|
3101
3515
|
const engineArea = isLlm
|
|
3102
3516
|
? h('div', { class: 'mt-2 grid grid-cols-1 gap-3 sm:grid-cols-3' },
|
|
3103
|
-
|
|
3104
|
-
modelField,
|
|
3105
|
-
field(L.translateThinking, (() => {
|
|
3106
|
-
// 档位随所选模型变化;跟随会话当前模型时用会话模型的档位,
|
|
3107
|
-
// 并把已存档位自适应映射过去(如 max → enabled)
|
|
3108
|
-
const smi = translateSessionRes.ok ? translateSessionRes.session : null;
|
|
3109
|
-
const opts = resolveThinkingOptions(titleGenProviders, ch0, smi);
|
|
3110
|
-
return selIn(opts.display, opts.variants.map((k) => [k, thinkingLabel(k, L)]),
|
|
3111
|
-
(v) => setChannel({ type: 'llm', thinking: v }), opts.unsupported ? L.translateThinkingUnsupported : '');
|
|
3112
|
-
})()))
|
|
3517
|
+
...translatePmt.fields)
|
|
3113
3518
|
: (() => {
|
|
3114
3519
|
const mtCur = (tr.mt && tr.mt.services && tr.mt.services[mtSvc]) || {};
|
|
3115
3520
|
return h('div', { class: 'mt-2 flex flex-wrap gap-2' },
|
|
@@ -3550,14 +3955,36 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
3550
3955
|
fact(L.headroomWatcher, s.watcherRunning == null ? '—' : (s.watcherRunning ? L.headroomWatcherOn : L.headroomWatcherOff)),
|
|
3551
3956
|
fact(L.headroomSaverDetect, HR_DETECT[s.saverDetect] || s.saverDetect),
|
|
3552
3957
|
);
|
|
3553
|
-
//
|
|
3958
|
+
// 多实例模式:列出各压缩实例(端口/出口/供应商)与运行状态。
|
|
3959
|
+
// 走代理链时出口显示「链 <地址>」,因为真实发出方是链转发器、不是厂商域名;
|
|
3960
|
+
// 一个实例承载多个厂商时不能只显示第一个(转发器按 key 分流),
|
|
3961
|
+
// 改成「N 个上游」并用悬浮提示列出全部
|
|
3554
3962
|
const insts = Array.isArray(s.instances) ? s.instances : [];
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3963
|
+
const outletOf = (it) => (it.onChain ? `${L.hrInstChain} ${it.target}` : it.upstream);
|
|
3964
|
+
const outletTitle = (it) => {
|
|
3965
|
+
const lines = [];
|
|
3966
|
+
if (it.onChain) {
|
|
3967
|
+
lines.push(`${L.hrInstChain} ${it.target}`);
|
|
3968
|
+
const ups = Array.isArray(it.upstreams) && it.upstreams.length ? it.upstreams : [it.upstream];
|
|
3969
|
+
lines.push(`${L.hrInstUpstreams}: ${ups.join('、')}`);
|
|
3970
|
+
if (Array.isArray(it.proxies) && it.proxies.length) lines.push(`${L.hrInstVia}: ${it.proxies.join('、')}`);
|
|
3971
|
+
} else {
|
|
3972
|
+
lines.push(`${L.hrInstUpstreams}: ${it.upstream}`);
|
|
3973
|
+
}
|
|
3974
|
+
lines.push(`${L.hrInstProviders}: ${it.providers}`);
|
|
3975
|
+
return lines.join('\n');
|
|
3976
|
+
};
|
|
3977
|
+
hrInstList.replaceChildren(...insts.map((it) => {
|
|
3978
|
+
const ups = Array.isArray(it.upstreams) ? it.upstreams.filter(Boolean) : [];
|
|
3979
|
+
const many = ups.length > 1;
|
|
3980
|
+
return h('div', { class: 'flex min-w-0 items-center gap-2' },
|
|
3981
|
+
h('span', { class: 'shrink-0 font-mono text-ui-xs text-foreground-subtle' }, `:${it.port}`),
|
|
3982
|
+
h('span', { class: 'min-w-0 flex-1 truncate text-ui-xs text-foreground-subtle', title: outletTitle(it) },
|
|
3983
|
+
`${it.format} → ${outletOf(it)}${many ? ` (+${ups.length - 1})` : ''}`),
|
|
3984
|
+
h('span', { class: 'max-w-[40%] shrink-0 truncate text-ui-xs text-foreground-subtle/70', title: it.providers }, it.providers),
|
|
3985
|
+
h('span', { class: 'shrink-0 text-ui-xs ' + (it.up ? 'text-emerald-600' : 'text-destructive') }, it.up ? L.hrInstRunning : L.hrInstStopped),
|
|
3986
|
+
...(rb ? [rb] : []));
|
|
3987
|
+
}));
|
|
3561
3988
|
hrInstList.style.display = insts.length ? '' : 'none';
|
|
3562
3989
|
hrHintLine.textContent = s.saverHint || '';
|
|
3563
3990
|
hrHintLine.style.display = s.saverHint ? '' : 'none';
|
|
@@ -3807,29 +4234,24 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
3807
4234
|
// 手动输入过的模型保留(不在新列表里时显示为“手动输入”项,是否改选
|
|
3808
4235
|
// 由用户决定)
|
|
3809
4236
|
const showInlineConn = isManualConn(titleGenCfg.provider, titleGenProviders);
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
4237
|
+
// 供应商 + 模型 + 思考级别走统一封装(与翻译页、视觉代理同一实现)
|
|
4238
|
+
const titleGenPmt = providerModelThinkingFields({
|
|
4239
|
+
providers: titleGenProviders,
|
|
4240
|
+
L,
|
|
4241
|
+
provider: titleGenCfg.provider || '',
|
|
4242
|
+
model: titleGenCfg.model || '',
|
|
4243
|
+
thinking: titleGenCfg.thinking || 'off',
|
|
4244
|
+
sessionInfo: translateSessionRes.ok ? translateSessionRes.session : null,
|
|
4245
|
+
withManual: true,
|
|
4246
|
+
labels: { provider: L.titleGenProvider, model: L.titleGenModel, thinking: L.translateThinking },
|
|
4247
|
+
onChange: (patch) => {
|
|
4248
|
+
titleGenCfg.provider = patch.provider;
|
|
4249
|
+
titleGenCfg.model = patch.model;
|
|
4250
|
+
titleGenCfg.thinking = patch.thinking;
|
|
4251
|
+
saveTitleGenSoon();
|
|
3817
4252
|
},
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
titleGenCfg.model || '',
|
|
3821
|
-
// 跟随会话时选项表头部有“跟随当前会话当前模型”(值为空,生成时用
|
|
3822
|
-
// 会话当前模型),选了具体模型后也能再切回它
|
|
3823
|
-
modelOptionsOf(titleGenCfg.provider, titleGenProviders, {
|
|
3824
|
-
followSession: true,
|
|
3825
|
-
followSessionLabel: L.titleGenModelFollowSession,
|
|
3826
|
-
}),
|
|
3827
|
-
(v) => { titleGenCfg.model = v; saveTitleGenSoon(); },
|
|
3828
|
-
{
|
|
3829
|
-
placeholder: modelPlaceholderOf(titleGenCfg.provider, L),
|
|
3830
|
-
emptyLabel: (titleGenCfg.provider || '').trim() === 'session'
|
|
3831
|
-
? L.titleGenModelFollowSession : L.titleGenModelEmpty,
|
|
3832
|
-
});
|
|
4253
|
+
requestRender: () => { void persistTitleGen(); renderTitleGenPane(); },
|
|
4254
|
+
});
|
|
3833
4255
|
// 接口地址 / API Key / 协议(显隐见上方 showInlineConn):不跟随时由
|
|
3834
4256
|
// 用户填写;供应商被删时展示保存的副本,仍可直连或改填
|
|
3835
4257
|
const textIn = (value, onInput, { type = 'text', placeholder = '' } = {}) => {
|
|
@@ -3903,10 +4325,9 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
3903
4325
|
await persistTitleGen();
|
|
3904
4326
|
renderTitleGenPane();
|
|
3905
4327
|
}))),
|
|
3906
|
-
// 供应商 + 模型
|
|
3907
|
-
h('div', { class: 'mt-2 grid grid-cols-1 gap-2 rounded-xl border border-border p-2 sm:grid-cols-
|
|
3908
|
-
|
|
3909
|
-
field(L.titleGenModel, modelCombo)),
|
|
4328
|
+
// 供应商 + 模型 + 思考级别
|
|
4329
|
+
h('div', { class: 'mt-2 grid grid-cols-1 gap-2 rounded-xl border border-border p-2 sm:grid-cols-3' },
|
|
4330
|
+
...titleGenPmt.fields),
|
|
3910
4331
|
inlineConnCard,
|
|
3911
4332
|
// 提示词 + 载入默认
|
|
3912
4333
|
h('div', { class: 'mt-2 rounded-xl border border-border p-2' },
|
|
@@ -3981,20 +4402,26 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
3981
4402
|
// 空的已保存值保持为空:改其它开关时不能把当前语言的默认提示词写进配置,
|
|
3982
4403
|
// 否则之后切换语言就不会再跟随(运行时空值才取当前语言默认)
|
|
3983
4404
|
continueText: typeof raw.continueText === 'string' && raw.continueText.trim() ? raw.continueText : '',
|
|
3984
|
-
maxRetries: Number.isFinite(raw.maxRetries) ? raw.maxRetries :
|
|
3985
|
-
|
|
4405
|
+
maxRetries: Number.isFinite(raw.maxRetries) ? raw.maxRetries : 10,
|
|
4406
|
+
continueDelaySec: Number.isFinite(raw.continueDelaySec) ? raw.continueDelaySec : 120,
|
|
4407
|
+
continueDelayFactor: Number.isFinite(raw.continueDelayFactor) ? raw.continueDelayFactor : 1.3,
|
|
3986
4408
|
stuckAfterMin: Number.isFinite(raw.stuckAfterMin) ? raw.stuckAfterMin : 30,
|
|
3987
4409
|
failedAfterMin: Number.isFinite(raw.failedAfterMin) ? raw.failedAfterMin : 3,
|
|
3988
4410
|
};
|
|
3989
4411
|
}
|
|
3990
|
-
//
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
4412
|
+
// 每项独占一行:标题与说明在左,数值输入在右。step 支持小数(递增倍数 1.3);
|
|
4413
|
+
// fallback 用当前值,空输入回落到现有值而不是最小值
|
|
4414
|
+
const numRow = (labelText, hint, value, min, max, commit, step = 1) => h('div', {
|
|
4415
|
+
class: 'flex items-center gap-2 p-2',
|
|
4416
|
+
},
|
|
4417
|
+
h('div', { class: 'min-w-0 flex-1' },
|
|
4418
|
+
h('div', { class: 'text-ui-sm font-medium text-foreground' }, labelText),
|
|
4419
|
+
hint ? h('div', { class: 'mt-0.5 text-ui-xs/relaxed text-foreground-subtle', title: hint }, hint) : null),
|
|
4420
|
+
h('div', { class: 'shrink-0' },
|
|
4421
|
+
numberField({
|
|
4422
|
+
value, fallback: value, min, max, step,
|
|
4423
|
+
onCommit: (v) => { commit(v); saveAcSoon(); },
|
|
4424
|
+
}).el));
|
|
3998
4425
|
const area = h('textarea', { class: 'zcodepro-textarea zcodepro-textarea-sm', rows: '3', placeholder: L.acPrompt, title: L.acPrompt });
|
|
3999
4426
|
area.value = acCfg.continueText || defaultContinueText(); // 空值显示当前语言默认,但保存时仍为空
|
|
4000
4427
|
area.addEventListener('input', () => { acCfg.continueText = area.value; saveAcSoon(); });
|
|
@@ -4013,11 +4440,12 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
4013
4440
|
h('div', { class: 'mt-3 rounded-xl border border-border p-2' },
|
|
4014
4441
|
h('div', { class: 'mb-1 text-ui-xs font-medium text-foreground-subtle' }, L.acPrompt),
|
|
4015
4442
|
area),
|
|
4016
|
-
h('div', { class: 'mt-2
|
|
4443
|
+
h('div', { class: 'mt-2 divide-y divide-border rounded-xl border border-border' },
|
|
4017
4444
|
numRow(L.acMaxRetries, L.acMaxRetriesHint, acCfg.maxRetries, 1, 50, (v) => { acCfg.maxRetries = v; }),
|
|
4018
|
-
numRow(L.
|
|
4019
|
-
numRow(L.
|
|
4020
|
-
numRow(L.acFailedAfterMin, L.acFailedAfterMinHint, acCfg.failedAfterMin, 1, 60, (v) => { acCfg.failedAfterMin = v; })
|
|
4445
|
+
numRow(L.acContinueDelay, L.acContinueDelayHint, acCfg.continueDelaySec, 0, 3600, (v) => { acCfg.continueDelaySec = v; }),
|
|
4446
|
+
numRow(L.acContinueDelayFactor, L.acContinueDelayFactorHint, acCfg.continueDelayFactor, 1, 10, (v) => { acCfg.continueDelayFactor = v; }, 0.1),
|
|
4447
|
+
numRow(L.acFailedAfterMin, L.acFailedAfterMinHint, acCfg.failedAfterMin, 1, 60, (v) => { acCfg.failedAfterMin = v; }),
|
|
4448
|
+
numRow(L.acStuckAfterMin, L.acStuckAfterMinHint, acCfg.stuckAfterMin, 5, 720, (v) => { acCfg.stuckAfterMin = v; })),
|
|
4021
4449
|
);
|
|
4022
4450
|
paneAutoContinue.replaceChildren(...parts);
|
|
4023
4451
|
};
|
|
@@ -4051,6 +4479,9 @@ export function openSettingsDialog(initialTab = 'features') {
|
|
|
4051
4479
|
paneRtk,
|
|
4052
4480
|
paneDebug,
|
|
4053
4481
|
);
|
|
4482
|
+
// 所有 pane 就绪后再切到目标 tab:pane 与二级 pane 的初始可见性都已在上面
|
|
4483
|
+
// 设好,此后 switchTab 只会调整显示,不会出现“内容区空白”
|
|
4484
|
+
switchTab(activeTab);
|
|
4054
4485
|
},
|
|
4055
4486
|
});
|
|
4056
4487
|
}
|