@ggboy123/dsh-paper-reader 1.9.0 → 1.10.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.md +7 -6
- package/dist/harness-translate.js +204 -0
- package/dist/host.js +133 -20
- package/dist/index.js +2 -1
- package/dist/translate-config.js +85 -12
- package/dist/translate.js +24 -16
- package/dist/translation-options.js +40 -0
- package/lib/client.js +346 -18
- package/package.json +1 -1
- package/reader/index.html +390 -119
- package/reader/vendor/PROVIDER_ICONS_LICENSE.txt +30 -0
- package/reader/vendor/anthropic.svg +1 -0
- package/reader/vendor/deepseek.svg +1 -0
- package/reader/vendor/gemini.svg +1 -0
- package/reader/vendor/kimi.svg +1 -0
- package/reader/vendor/openai.svg +1 -0
- package/reader/vendor/opencode.svg +1 -0
- package/reader/vendor/zhipu.svg +1 -0
- package/runtime/babeldoc-driver.py +4 -4
package/reader/index.html
CHANGED
|
@@ -317,25 +317,70 @@
|
|
|
317
317
|
#tr-body .tr-math-block .katex-display { margin: 0; }
|
|
318
318
|
#tr-body .tr-math-fallback { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-2); word-break: break-all; }
|
|
319
319
|
|
|
320
|
-
/* ----------
|
|
321
|
-
/* 阅读器在窄 iframe 里,宽度要能收缩 */
|
|
320
|
+
/* ---------- 全文翻译模型设置:与 dsh 设置页同一套跟随 / 覆盖语义 ---------- */
|
|
322
321
|
#cfg-pop, #theme-pop, #generate-pop { position: fixed; z-index: 60; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 10px; width: min(320px, calc(100vw - 32px)); }
|
|
322
|
+
#cfg-pop { width: min(640px, calc(100vw - 28px)); max-height: calc(100vh - 28px); overflow-y: auto; padding: 0; }
|
|
323
323
|
#cfg-pop h3, #theme-pop h3 { margin: 0; font-size: 13px; }
|
|
324
|
-
#cfg-
|
|
325
|
-
#cfg-
|
|
326
|
-
|
|
324
|
+
#cfg-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px 12px; border-bottom: 1px solid var(--border); }
|
|
325
|
+
#cfg-cancel { border: 0; background: transparent; color: var(--text-2); cursor: pointer; padding: 2px 5px; border-radius: 4px; }
|
|
326
|
+
#cfg-cancel:hover { background: var(--bg); color: var(--text); }
|
|
327
|
+
#cfg-hint { font-size: 12px; color: var(--text-2); line-height: 1.55; margin: 10px 16px 12px; }
|
|
328
|
+
#cfg-pop label, #theme-pop label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0 4px; }
|
|
327
329
|
#cfg-pop input[type="checkbox"], #theme-pop input[type="checkbox"] { width: auto; }
|
|
328
330
|
#theme-pop h3 { display: flex; align-items: center; justify-content: space-between; }
|
|
329
331
|
#theme-close { all: unset; cursor: pointer; font-size: 12px; color: var(--text-2); padding: 2px 6px; border-radius: 4px; }
|
|
330
332
|
#theme-close:hover { background: var(--bg); color: var(--text); }
|
|
331
|
-
#cfg-pop input, #cfg-pop select, #theme-pop input, #theme-pop select { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding:
|
|
332
|
-
#cfg-
|
|
333
|
+
#cfg-pop input, #cfg-pop select, #theme-pop input, #theme-pop select { box-sizing: border-box; width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font: inherit; background: var(--panel); color: var(--text); }
|
|
334
|
+
#cfg-pop input:focus, #cfg-pop select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
|
|
335
|
+
.cfg-modes { display: flex; gap: 9px; padding: 0 16px 14px; }
|
|
336
|
+
.cfg-mode, .cfg-provider, .cfg-model { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); cursor: pointer; text-align: left; }
|
|
337
|
+
.cfg-mode { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 9px; padding: 11px; border-radius: 8px; }
|
|
338
|
+
.cfg-mode.selected, .cfg-provider.selected, .cfg-model.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
|
|
339
|
+
.cfg-radio { width: 15px; height: 15px; flex: none; margin-top: 2px; border: 1.5px solid var(--text-2); border-radius: 50%; display: grid; place-items: center; }
|
|
340
|
+
.selected > .cfg-radio { border-color: var(--accent); }
|
|
341
|
+
.selected > .cfg-radio::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
|
|
342
|
+
.cfg-mode-name { display: block; font-size: 12px; font-weight: 650; }
|
|
343
|
+
.cfg-desc, .cfg-small { display: block; color: var(--text-2); font-size: 11px; line-height: 1.5; margin-top: 4px; }
|
|
344
|
+
#cfg-follow-panel { display: flex; align-items: center; gap: 12px; margin: 0 16px 14px; padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--accent-soft); }
|
|
345
|
+
#cfg-follow-model { margin-top: 4px; font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
|
|
346
|
+
#cfg-follow-note { margin-top: 4px; }
|
|
347
|
+
#cfg-custom-panel[hidden], #cfg-follow-panel[hidden] { display: none; }
|
|
348
|
+
.cfg-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 16px 9px; font-size: 12px; }
|
|
349
|
+
#cfg-provider-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; padding: 0 16px 13px; }
|
|
350
|
+
.cfg-provider { min-width: 0; display: flex; align-items: center; gap: 8px; padding: 9px; border-radius: 7px; }
|
|
351
|
+
.cfg-mark { width: 29px; height: 29px; flex: none; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 7px; color: var(--accent); background: var(--panel); font-size: 10px; font-weight: 650; }
|
|
352
|
+
.cfg-icon { width: 22px; height: 22px; display: block; object-fit: contain; background: #fff; border-radius: 4px; }
|
|
353
|
+
.cfg-provider-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 600; }
|
|
354
|
+
.cfg-provider-state { color: var(--text-2); font-size: 10px; margin-top: 3px; }
|
|
355
|
+
.cfg-provider-state.saved { color: #27845d; }
|
|
356
|
+
#cfg-config { margin: 0 16px 14px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
|
|
357
|
+
#cfg-config-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px 7px; font-size: 12px; }
|
|
358
|
+
#cfg-key-link { color: var(--accent); font-size: 11px; text-decoration: none; white-space: nowrap; }
|
|
359
|
+
#cfg-key-wrap { padding: 0 12px 11px; }
|
|
360
|
+
#cfg-model-hint, #cfg-source { font-size: 11.5px; color: var(--text-2); margin-top: 5px; line-height: 1.5; }
|
|
361
|
+
#cfg-source { padding: 0 16px 12px; text-align: center; }
|
|
362
|
+
#cfg-source.ok { color: #27845d; }
|
|
363
|
+
#cfg-source.err { color: #d54e4e; }
|
|
333
364
|
#cfg-source:empty { display: none; }
|
|
334
|
-
#cfg-
|
|
335
|
-
#cfg-
|
|
336
|
-
#cfg-
|
|
365
|
+
#cfg-advanced { margin-top: 9px; }
|
|
366
|
+
#cfg-endpoints { margin: 0 16px 12px; color: var(--text-2); font-size: 11px; }
|
|
367
|
+
#cfg-endpoints summary, #cfg-advanced summary { cursor: pointer; }
|
|
368
|
+
#cfg-endpoints #cfg-saved { margin-top: 7px; }
|
|
369
|
+
#cfg-options-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
|
|
370
|
+
#cfg-list-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
|
|
371
|
+
#cfg-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
|
|
372
|
+
#cfg-save, #generate-start { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
|
|
337
373
|
#cfg-save:disabled, #generate-start:disabled { opacity: .5; cursor: default; }
|
|
338
|
-
#cfg-
|
|
374
|
+
#cfg-delete { color: #d54e4e; }
|
|
375
|
+
#cfg-models-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 12px 7px; border-top: 1px solid var(--border); font-size: 12px; }
|
|
376
|
+
#cfg-models { display: grid; gap: 6px; max-height: 230px; overflow-y: auto; padding: 0 12px 12px; }
|
|
377
|
+
.cfg-model { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 10px; border-radius: 7px; }
|
|
378
|
+
.cfg-model-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 600; }
|
|
379
|
+
.cfg-model-action { color: var(--text-2); font-size: 11px; white-space: nowrap; }
|
|
380
|
+
.cfg-empty { padding: 14px; border: 1px dashed var(--border); border-radius: 7px; color: var(--text-2); font-size: 11px; line-height: 1.6; text-align: center; }
|
|
381
|
+
#cfg-scope { padding: 0 16px 13px; color: var(--text-2); font-size: 11px; line-height: 1.5; text-align: center; }
|
|
382
|
+
#generate-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
|
|
383
|
+
@media (max-width: 520px) { #cfg-provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cfg-modes { flex-direction: column; } }
|
|
339
384
|
|
|
340
385
|
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 13px; display: none; z-index: 99; max-width: 70%; }
|
|
341
386
|
/* ---------- 深色模式(方案 §A2.1;设置项 §A2.3)----------
|
|
@@ -514,31 +559,66 @@
|
|
|
514
559
|
<div id="tr-note"></div>
|
|
515
560
|
</div>
|
|
516
561
|
|
|
517
|
-
<div id="cfg-pop">
|
|
518
|
-
<h3
|
|
519
|
-
<div id="cfg-hint"
|
|
520
|
-
<div
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
<div id="cfg-list-actions">
|
|
524
|
-
<button id="cfg-new" class="tbtn">新增端点</button>
|
|
525
|
-
<button id="cfg-delete" class="tbtn">删除当前</button>
|
|
526
|
-
</div>
|
|
527
|
-
<label for="cfg-provider">供应商</label>
|
|
528
|
-
<select id="cfg-provider"></select>
|
|
529
|
-
<label for="cfg-url">端点 URL</label>
|
|
530
|
-
<input id="cfg-url" type="text" placeholder="https://api.deepseek.com/v1" autocomplete="off">
|
|
531
|
-
<label for="cfg-key">API Key</label>
|
|
532
|
-
<input id="cfg-key" type="password" placeholder="sk-..." autocomplete="new-password">
|
|
533
|
-
<label for="cfg-model">模型</label>
|
|
534
|
-
<input id="cfg-model" type="text" placeholder="deepseek-chat" autocomplete="off" list="cfg-model-list">
|
|
535
|
-
<datalist id="cfg-model-list"></datalist>
|
|
536
|
-
<div id="cfg-model-hint">glm-5.x / k3 / deepseek-flash 是推理型模型,服务端已自动关闭思考;选自定义端点时建议用非推理模型,否则会慢好几倍。</div>
|
|
537
|
-
<div id="cfg-actions">
|
|
538
|
-
<button id="cfg-cancel">取消</button>
|
|
539
|
-
<button id="cfg-save-new">另存为新端点</button>
|
|
540
|
-
<button id="cfg-save">保存</button>
|
|
562
|
+
<div id="cfg-pop" data-mode="follow">
|
|
563
|
+
<div id="cfg-head"><h3>全文翻译模型</h3><button id="cfg-cancel" title="关闭" aria-label="关闭">✕</button></div>
|
|
564
|
+
<div id="cfg-hint">生成中文版与划词翻译共用。默认跟随 Harness;专用配置只作用于翻译,不改变宿主模型设置。</div>
|
|
565
|
+
<div class="cfg-modes" role="radiogroup" aria-label="翻译模型来源">
|
|
566
|
+
<button id="cfg-follow" class="cfg-mode selected" role="radio" aria-checked="true"><span class="cfg-radio"></span><span><span class="cfg-mode-name">跟随 Harness <small>默认</small></span><span class="cfg-desc">与 Harness 当前模型保持一致</span></span></button>
|
|
567
|
+
<button id="cfg-custom" class="cfg-mode" role="radio" aria-checked="false"><span class="cfg-radio"></span><span><span class="cfg-mode-name">使用自定义模型</span><span class="cfg-desc">翻译任务单独使用另一套配置</span></span></button>
|
|
541
568
|
</div>
|
|
569
|
+
<section id="cfg-follow-panel">
|
|
570
|
+
<span id="cfg-follow-icon" class="cfg-mark"></span>
|
|
571
|
+
<div><div class="cfg-small">● 当前跟随</div><div id="cfg-follow-model"></div><div id="cfg-follow-note" class="cfg-small">Harness 切换模型后,下次翻译自动跟随;进行中的整篇翻译不变。</div></div>
|
|
572
|
+
</section>
|
|
573
|
+
<section id="cfg-custom-panel" hidden>
|
|
574
|
+
<div class="cfg-section-head"><strong>翻译服务商</strong><span id="cfg-saved-count" class="cfg-small"></span></div>
|
|
575
|
+
<div id="cfg-provider-grid"></div>
|
|
576
|
+
<details id="cfg-endpoints">
|
|
577
|
+
<summary>管理已保存配置</summary>
|
|
578
|
+
<label for="cfg-saved">编辑已保存配置</label>
|
|
579
|
+
<select id="cfg-saved"></select>
|
|
580
|
+
<div id="cfg-list-actions">
|
|
581
|
+
<button id="cfg-new" class="tbtn">新增端点</button>
|
|
582
|
+
<button id="cfg-delete" class="tbtn">删除当前</button>
|
|
583
|
+
<button id="cfg-save-new" class="tbtn">另存为新端点</button>
|
|
584
|
+
</div>
|
|
585
|
+
</details>
|
|
586
|
+
<div id="cfg-config">
|
|
587
|
+
<div id="cfg-config-head"><strong id="cfg-provider-name"></strong><a id="cfg-key-link" target="_blank" rel="noreferrer">申请 API Key ↗</a></div>
|
|
588
|
+
<div id="cfg-key-wrap">
|
|
589
|
+
<label for="cfg-key">API Key</label>
|
|
590
|
+
<input id="cfg-key" type="password" placeholder="sk-..." autocomplete="new-password">
|
|
591
|
+
<div id="cfg-model-hint">粘贴 Key 后自动验证并获取模型;选择模型后保存。</div>
|
|
592
|
+
<div id="cfg-url-wrap" hidden>
|
|
593
|
+
<label for="cfg-url">端点 URL</label>
|
|
594
|
+
<input id="cfg-url" type="text" placeholder="https://api.deepseek.com/v1" autocomplete="off">
|
|
595
|
+
</div>
|
|
596
|
+
<details id="cfg-advanced">
|
|
597
|
+
<summary>高级设置:整篇 PDF 翻译参数</summary>
|
|
598
|
+
<div id="cfg-manual-wrap" hidden>
|
|
599
|
+
<label for="cfg-model">手动模型名</label>
|
|
600
|
+
<input id="cfg-model" type="text" placeholder="deepseek-chat" autocomplete="off" list="cfg-model-list">
|
|
601
|
+
<datalist id="cfg-model-list"></datalist>
|
|
602
|
+
<div id="cfg-actions"><button id="cfg-save">使用此模型</button></div>
|
|
603
|
+
</div>
|
|
604
|
+
<label for="cfg-split-tokens">单段上下文上限(tokens)</label>
|
|
605
|
+
<input id="cfg-split-tokens" data-cfg-option="splitTokens" type="number" min="200" max="128000" step="1">
|
|
606
|
+
<div class="cfg-small">超过后自动拆段;调小可减少单次上下文,调大可减少拆段次数。</div>
|
|
607
|
+
<label for="cfg-max-output">单次输出上限(tokens)</label>
|
|
608
|
+
<input id="cfg-max-output" data-cfg-option="maxOutputTokens" type="number" min="0" max="32768" step="1">
|
|
609
|
+
<div class="cfg-small">0 表示跟随端点默认,不传 max_tokens。</div>
|
|
610
|
+
<label for="cfg-qps">并发请求数(QPS)</label>
|
|
611
|
+
<input id="cfg-qps" data-cfg-option="qps" type="number" min="1" max="32" step="1">
|
|
612
|
+
<div class="cfg-small">过高容易触发端点限流;遇到 429 时可调低。</div>
|
|
613
|
+
<div id="cfg-options-actions"><button id="cfg-options-save" class="tbtn">保存翻译参数</button></div>
|
|
614
|
+
</details>
|
|
615
|
+
</div>
|
|
616
|
+
<div id="cfg-models-head"><strong>选择翻译模型 <span id="cfg-model-count" class="cfg-small"></span></strong><button id="cfg-refresh" class="tbtn">刷新列表</button></div>
|
|
617
|
+
<div id="cfg-models"></div>
|
|
618
|
+
</div>
|
|
619
|
+
</section>
|
|
620
|
+
<div id="cfg-scope"></div>
|
|
621
|
+
<div id="cfg-source" role="status"></div>
|
|
542
622
|
</div>
|
|
543
623
|
|
|
544
624
|
<div id="generate-pop">
|
|
@@ -2401,6 +2481,7 @@ $('split-toggle').onclick = () => setViewMode(viewMode === 'split' ? 'orig' : 's
|
|
|
2401
2481
|
let generateForce = false;
|
|
2402
2482
|
let generateEndpoints = [];
|
|
2403
2483
|
function endpointDisplay(e) {
|
|
2484
|
+
if (e.source === 'harness') return `跟随 Harness · ${e.providerName || '当前模型'} / ${e.model}`;
|
|
2404
2485
|
const provider = providerOf(e.baseUrl).name;
|
|
2405
2486
|
return `${e.label || provider} · ${e.model || '未填模型'} · ${e.apiKeyHint || '无 Key'}`;
|
|
2406
2487
|
}
|
|
@@ -2505,65 +2586,175 @@ $('zh-regen').onclick = async () => {
|
|
|
2505
2586
|
regenArmTimer = setTimeout(disarmRegen, 3000);
|
|
2506
2587
|
};
|
|
2507
2588
|
|
|
2508
|
-
/* =================
|
|
2509
|
-
// 供应商预设(OpenAI 兼容端点,对齐 lflow 的供应商清单):选中即回填 URL + 推荐模型。
|
|
2510
|
-
// 一律走 Coding 套餐端点——买套餐是常态;套餐 key 走按量口会报余额不足。按量用户选「自定义」手填。
|
|
2511
|
-
// models 仅作 datalist 建议,输入框仍可自由填写(新型号上线不用发版)。
|
|
2512
|
-
// glm-5.x / k3 / deepseek-flash 是推理型,服务端会对这三家域名自动关 thinking(translate.ts)。
|
|
2589
|
+
/* ================= 全文翻译模型设置(与 dsh 设置页一致) ================= */
|
|
2513
2590
|
const PROVIDERS = [
|
|
2514
|
-
{ id: '
|
|
2515
|
-
{ id: '
|
|
2516
|
-
{ id: '
|
|
2517
|
-
{ id: '
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
{ id: 'opencode', name: 'OpenCode Go', baseUrl: 'https://opencode.ai/inference/go/openai/v1',
|
|
2591
|
+
{ id: 'deepseek', name: 'DeepSeek', mark: 'DS', icon: 'deepseek.svg', baseUrl: 'https://api.deepseek.com/v1', keyUrl: 'https://platform.deepseek.com/api_keys' },
|
|
2592
|
+
{ id: 'openai', name: 'OpenAI', mark: '◎', icon: 'openai.svg', mono: true, baseUrl: 'https://api.openai.com/v1', keyUrl: 'https://platform.openai.com/api-keys' },
|
|
2593
|
+
{ id: 'anthropic', name: 'Anthropic', mark: 'A', icon: 'anthropic.svg', baseUrl: 'https://api.anthropic.com/v1', keyUrl: 'https://console.anthropic.com/settings/keys' },
|
|
2594
|
+
{ id: 'gemini', name: 'Gemini', mark: '✦', icon: 'gemini.svg', baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai', keyUrl: 'https://aistudio.google.com/app/apikey' },
|
|
2595
|
+
{ id: 'zhipu', name: '智谱 GLM', mark: 'GL', icon: 'zhipu.svg', baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4', keyUrl: 'https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys' },
|
|
2596
|
+
{ id: 'kimi', name: 'Kimi', mark: 'K', icon: 'kimi.svg', mono: true, baseUrl: 'https://api.kimi.com/coding/v1', keyUrl: 'https://platform.kimi.com/console/api-keys' },
|
|
2597
|
+
{ id: 'opencode', name: 'OpenCode Go', mark: 'OC', icon: 'opencode.svg', mono: true, baseUrl: 'https://opencode.ai/inference/go/openai/v1', keyUrl: 'https://opencode.ai/' },
|
|
2598
|
+
{ id: 'custom', name: '自定义', mark: '+', baseUrl: '', keyUrl: '' },
|
|
2521
2599
|
];
|
|
2522
2600
|
const normUrl = (u) => (u || '').trim().replace(/\/+$/, '');
|
|
2523
|
-
|
|
2524
|
-
const
|
|
2525
|
-
|
|
2526
|
-
(
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
const p = PROVIDERS.find((x) => x.id === sel.value) || PROVIDERS[0];
|
|
2535
|
-
if (p.baseUrl) $('cfg-url').value = p.baseUrl; // custom 不动用户已填的 URL
|
|
2536
|
-
$('cfg-model-list').innerHTML = p.models.map((m) => `<option value="${esc(m)}">`).join('');
|
|
2537
|
-
if (p.models.length && !p.models.includes($('cfg-model').value.trim())) $('cfg-model').value = p.models[0];
|
|
2538
|
-
};
|
|
2539
|
-
})();
|
|
2601
|
+
function providerOf(baseUrl) {
|
|
2602
|
+
const u = (baseUrl || '').toLowerCase();
|
|
2603
|
+
if (/opencode\.ai/.test(u)) return PROVIDERS.find((p) => p.id === 'opencode');
|
|
2604
|
+
if (/kimi|moonshot/.test(u)) return PROVIDERS.find((p) => p.id === 'kimi');
|
|
2605
|
+
if (/deepseek/.test(u)) return PROVIDERS.find((p) => p.id === 'deepseek');
|
|
2606
|
+
if (/openai\.com/.test(u)) return PROVIDERS.find((p) => p.id === 'openai');
|
|
2607
|
+
if (/anthropic/.test(u)) return PROVIDERS.find((p) => p.id === 'anthropic');
|
|
2608
|
+
if (/googleapis\.com/.test(u)) return PROVIDERS.find((p) => p.id === 'gemini');
|
|
2609
|
+
if (/bigmodel|z\.ai/.test(u)) return PROVIDERS.find((p) => p.id === 'zhipu');
|
|
2610
|
+
return PROVIDERS.find((p) => p.id === 'custom');
|
|
2611
|
+
}
|
|
2540
2612
|
|
|
2541
|
-
// 保存成功后是否自动接着生成:点「中译」/「重翻」发现没配 → 弹本表单 → 填完直接开跑
|
|
2542
2613
|
let cfgRetryGenerate = false;
|
|
2543
|
-
let cfgRetryForce = false;
|
|
2544
|
-
let cfgRetryTranslate = false;
|
|
2614
|
+
let cfgRetryForce = false;
|
|
2615
|
+
let cfgRetryTranslate = false;
|
|
2616
|
+
let cfgData = null;
|
|
2545
2617
|
let cfgEndpoints = [];
|
|
2546
2618
|
let cfgEditingId = 'new';
|
|
2619
|
+
let cfgProviderId = 'deepseek';
|
|
2620
|
+
let cfgDraft = { baseUrl: PROVIDERS[0].baseUrl, model: '', apiKey: '' };
|
|
2621
|
+
let cfgModels = [];
|
|
2622
|
+
let cfgOptions = { splitTokens: 100000, maxOutputTokens: 32768, qps: 16 };
|
|
2623
|
+
const CFG_OPTION_IDS = { splitTokens: 'cfg-split-tokens', maxOutputTokens: 'cfg-max-output', qps: 'cfg-qps' };
|
|
2624
|
+
let cfgManualModel = false;
|
|
2625
|
+
let cfgMode = 'follow';
|
|
2626
|
+
let cfgBusy = '';
|
|
2627
|
+
let cfgModelRequest = 0;
|
|
2628
|
+
let cfgKeyTimer = null;
|
|
2547
2629
|
let cfgDeleteArmed = false;
|
|
2548
2630
|
|
|
2631
|
+
function cfgMessage(text, ok) {
|
|
2632
|
+
const el = $('cfg-source');
|
|
2633
|
+
el.textContent = text || '';
|
|
2634
|
+
el.className = text ? (ok ? 'ok' : 'err') : '';
|
|
2635
|
+
}
|
|
2636
|
+
function endpointProvider(e) {
|
|
2637
|
+
return PROVIDERS.some((p) => p.id === e?.provider) ? PROVIDERS.find((p) => p.id === e.provider) : providerOf(e?.baseUrl);
|
|
2638
|
+
}
|
|
2639
|
+
function cfgProviderIcon(provider) {
|
|
2640
|
+
if (!provider.icon) {
|
|
2641
|
+
const fallback = document.createElement('span');
|
|
2642
|
+
fallback.textContent = provider.mark || '+';
|
|
2643
|
+
return fallback;
|
|
2644
|
+
}
|
|
2645
|
+
const img = document.createElement('img');
|
|
2646
|
+
img.className = 'cfg-icon' + (provider.mono ? ' mono' : '');
|
|
2647
|
+
img.src = '/paper-reader/vendor/' + provider.icon;
|
|
2648
|
+
img.alt = '';
|
|
2649
|
+
img.setAttribute('aria-hidden', 'true');
|
|
2650
|
+
img.dataset.cfgProviderIcon = provider.id;
|
|
2651
|
+
return img;
|
|
2652
|
+
}
|
|
2653
|
+
function renderCfgModels() {
|
|
2654
|
+
const wrap = $('cfg-models');
|
|
2655
|
+
wrap.innerHTML = '';
|
|
2656
|
+
$('cfg-model-count').textContent = cfgModels.length ? `(${cfgModels.length})` : '';
|
|
2657
|
+
$('cfg-model-list').innerHTML = cfgModels.map((m) => `<option value="${esc(m)}">`).join('');
|
|
2658
|
+
if (!cfgModels.length) {
|
|
2659
|
+
const empty = document.createElement('div');
|
|
2660
|
+
empty.className = 'cfg-empty';
|
|
2661
|
+
empty.textContent = '填写 API Key 后,模型列表会自动出现在这里。';
|
|
2662
|
+
wrap.appendChild(empty);
|
|
2663
|
+
return;
|
|
2664
|
+
}
|
|
2665
|
+
for (const model of cfgModels) {
|
|
2666
|
+
const using = cfgData?.activeId === cfgEditingId && cfgData?.source !== 'harness' && cfgDraft.model === model;
|
|
2667
|
+
const btn = document.createElement('button');
|
|
2668
|
+
btn.type = 'button';
|
|
2669
|
+
btn.className = 'cfg-model' + (using ? ' selected' : '');
|
|
2670
|
+
btn.dataset.cfgModel = model;
|
|
2671
|
+
btn.disabled = cfgBusy === 'save';
|
|
2672
|
+
const radio = document.createElement('span'); radio.className = 'cfg-radio';
|
|
2673
|
+
const name = document.createElement('span'); name.className = 'cfg-model-name'; name.textContent = model;
|
|
2674
|
+
const action = document.createElement('span'); action.className = 'cfg-model-action'; action.textContent = using ? '使用中' : '使用';
|
|
2675
|
+
btn.append(radio, name, action);
|
|
2676
|
+
btn.onclick = () => saveCfg(false, model);
|
|
2677
|
+
wrap.appendChild(btn);
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
function renderCfg() {
|
|
2681
|
+
$('cfg-pop').dataset.mode = cfgMode;
|
|
2682
|
+
for (const [id, selected] of [['cfg-follow', cfgMode === 'follow'], ['cfg-custom', cfgMode === 'custom']]) {
|
|
2683
|
+
$(id).classList.toggle('selected', selected);
|
|
2684
|
+
$(id).setAttribute('aria-checked', String(selected));
|
|
2685
|
+
}
|
|
2686
|
+
$('cfg-follow').disabled = !cfgData?.harness;
|
|
2687
|
+
$('cfg-follow-panel').hidden = cfgMode !== 'follow';
|
|
2688
|
+
$('cfg-custom-panel').hidden = cfgMode !== 'custom';
|
|
2689
|
+
$('cfg-follow-icon').innerHTML = '';
|
|
2690
|
+
$('cfg-follow-icon').appendChild(cfgProviderIcon(providerOf(cfgData?.harness?.providerName || '')));
|
|
2691
|
+
$('cfg-follow-model').textContent = cfgData?.harness
|
|
2692
|
+
? `${cfgData.harness.model} · ${cfgData.harness.providerName}`
|
|
2693
|
+
: 'Harness 当前模型不可用,请先在 Harness 中完成模型设置。';
|
|
2694
|
+
$('cfg-scope').textContent = cfgMode === 'follow'
|
|
2695
|
+
? '跟随模式不保存或复制 Harness 的 Key,也不会改写 Harness 配置。'
|
|
2696
|
+
: '自定义配置仅用于翻译,不会写入或改变 Harness 的模型设置。';
|
|
2697
|
+
const provider = PROVIDERS.find((p) => p.id === cfgProviderId) || PROVIDERS[0];
|
|
2698
|
+
const savedForProvider = cfgEndpoints.some((e) => e.source === 'file' && endpointProvider(e).id === cfgProviderId);
|
|
2699
|
+
$('cfg-saved-count').textContent = `已保存 ${cfgEndpoints.filter((e) => e.source === 'file').length} 个`;
|
|
2700
|
+
$('cfg-provider-name').textContent = provider.name + (savedForProvider ? ' ● 已保存' : '');
|
|
2701
|
+
$('cfg-key-link').style.display = provider.keyUrl ? '' : 'none';
|
|
2702
|
+
$('cfg-key-link').href = provider.keyUrl || '#';
|
|
2703
|
+
$('cfg-key').value = cfgDraft.apiKey;
|
|
2704
|
+
$('cfg-key').placeholder = savedForProvider
|
|
2705
|
+
? `已保存(${cfgEndpoints.find((e) => e.id === cfgEditingId)?.apiKeyHint || '掩码'}),留空则不修改`
|
|
2706
|
+
: 'sk-...';
|
|
2707
|
+
$('cfg-url').value = cfgDraft.baseUrl;
|
|
2708
|
+
$('cfg-url-wrap').hidden = provider.id !== 'custom';
|
|
2709
|
+
$('cfg-manual-wrap').hidden = !cfgManualModel;
|
|
2710
|
+
for (const key of ['splitTokens', 'maxOutputTokens', 'qps']) {
|
|
2711
|
+
$(CFG_OPTION_IDS[key]).value = cfgOptions[key];
|
|
2712
|
+
}
|
|
2713
|
+
$('cfg-model').value = cfgDraft.model;
|
|
2714
|
+
$('cfg-model-hint').textContent = cfgBusy === 'models' ? '正在验证 Key 并获取模型…' : '粘贴 Key 后自动验证并获取模型;选择模型后保存。';
|
|
2715
|
+
$('cfg-refresh').disabled = cfgBusy === 'models' || cfgBusy === 'save';
|
|
2716
|
+
$('cfg-save').disabled = cfgBusy === 'save' || !cfgDraft.model.trim();
|
|
2717
|
+
$('cfg-save').textContent = cfgBusy === 'save' ? '测试连接中…' : '使用此模型';
|
|
2718
|
+
$('cfg-delete').disabled = cfgEditingId === 'new' || cfgEditingId === 'profile';
|
|
2719
|
+
$('cfg-delete').textContent = cfgDeleteArmed ? '确认删除?' : '删除当前';
|
|
2720
|
+
const grid = $('cfg-provider-grid');
|
|
2721
|
+
grid.innerHTML = '';
|
|
2722
|
+
for (const p of PROVIDERS) {
|
|
2723
|
+
const saved = cfgEndpoints.some((e) => e.source === 'file' && endpointProvider(e).id === p.id);
|
|
2724
|
+
const btn = document.createElement('button');
|
|
2725
|
+
btn.type = 'button';
|
|
2726
|
+
btn.className = 'cfg-provider' + (p.id === cfgProviderId ? ' selected' : '');
|
|
2727
|
+
btn.dataset.cfgProvider = p.id;
|
|
2728
|
+
const mark = cfgProviderIcon(p);
|
|
2729
|
+
const copy = document.createElement('span');
|
|
2730
|
+
const name = document.createElement('div'); name.className = 'cfg-provider-name'; name.textContent = p.name;
|
|
2731
|
+
const state = document.createElement('div'); state.className = 'cfg-provider-state' + (saved ? ' saved' : ''); state.textContent = saved ? '已保存' : (p.id === 'custom' ? 'OpenAI API' : '可选');
|
|
2732
|
+
copy.append(name, state);
|
|
2733
|
+
btn.append(mark, copy);
|
|
2734
|
+
btn.onclick = () => chooseCfgProvider(p.id);
|
|
2735
|
+
grid.appendChild(btn);
|
|
2736
|
+
}
|
|
2737
|
+
renderCfgModels();
|
|
2738
|
+
if ($('cfg-pop').style.display === 'block') positionCfgPop();
|
|
2739
|
+
}
|
|
2740
|
+
function positionCfgPop() {
|
|
2741
|
+
const pop = $('cfg-pop');
|
|
2742
|
+
pop.style.left = Math.max(8, (window.innerWidth - pop.offsetWidth) / 2) + 'px';
|
|
2743
|
+
pop.style.top = Math.max(14, (window.innerHeight - pop.offsetHeight) / 2) + 'px';
|
|
2744
|
+
}
|
|
2549
2745
|
function fillCfgEndpoint(e) {
|
|
2746
|
+
cfgModelRequest += 1;
|
|
2747
|
+
clearTimeout(cfgKeyTimer);
|
|
2748
|
+
cfgBusy = '';
|
|
2550
2749
|
cfgEditingId = e?.id || 'new';
|
|
2750
|
+
cfgProviderId = endpointProvider(e).id;
|
|
2751
|
+
const preset = PROVIDERS.find((p) => p.id === cfgProviderId) || PROVIDERS[0];
|
|
2752
|
+
cfgDraft = { baseUrl: e?.baseUrl || preset.baseUrl, model: e?.model || '', apiKey: '' };
|
|
2753
|
+
cfgModels = e?.model ? [e.model] : [];
|
|
2754
|
+
cfgManualModel = false;
|
|
2551
2755
|
cfgDeleteArmed = false;
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
$('cfg-url').value = e?.baseUrl || '';
|
|
2555
|
-
$('cfg-model').value = e?.model || '';
|
|
2556
|
-
const sel = $('cfg-provider');
|
|
2557
|
-
sel.value = providerOf(e?.baseUrl).id;
|
|
2558
|
-
const keepUrl = $('cfg-url').value, keepModel = $('cfg-model').value;
|
|
2559
|
-
sel.onchange();
|
|
2560
|
-
$('cfg-url').value = keepUrl || $('cfg-url').value;
|
|
2561
|
-
$('cfg-model').value = keepModel || $('cfg-model').value;
|
|
2562
|
-
$('cfg-key').value = '';
|
|
2563
|
-
$('cfg-key').placeholder = e?.hasApiKey ? `已保存(${e.apiKeyHint}),留空则不修改` : 'sk-...';
|
|
2564
|
-
$('cfg-source').textContent = e
|
|
2565
|
-
? `${e.source === 'profile' ? 'profile 默认配置(保存会另存为本界面配置)' : '本界面保存的配置'}(key ${e.apiKeyHint || '未填'})`
|
|
2566
|
-
: '新端点:保存前会先做连接测试';
|
|
2756
|
+
cfgMessage('');
|
|
2757
|
+
renderCfg();
|
|
2567
2758
|
}
|
|
2568
2759
|
function fillCfgList(activeId) {
|
|
2569
2760
|
const sel = $('cfg-saved');
|
|
@@ -2576,88 +2767,168 @@ function fillCfgList(activeId) {
|
|
|
2576
2767
|
const add = document.createElement('option');
|
|
2577
2768
|
add.value = 'new'; add.textContent = '+ 新建端点…';
|
|
2578
2769
|
sel.appendChild(add);
|
|
2579
|
-
const selected = cfgEndpoints.find((e) => e.id === activeId) || null;
|
|
2770
|
+
const selected = cfgEndpoints.find((e) => e.id === activeId) || cfgEndpoints[0] || null;
|
|
2580
2771
|
sel.value = selected?.id || 'new';
|
|
2581
2772
|
fillCfgEndpoint(selected);
|
|
2582
2773
|
}
|
|
2774
|
+
function chooseCfgProvider(id) {
|
|
2775
|
+
const saved = cfgEndpoints.find((e) => e.source === 'file' && endpointProvider(e).id === id);
|
|
2776
|
+
if (saved) {
|
|
2777
|
+
$('cfg-saved').value = saved.id;
|
|
2778
|
+
fillCfgEndpoint(saved);
|
|
2779
|
+
return;
|
|
2780
|
+
}
|
|
2781
|
+
const preset = PROVIDERS.find((p) => p.id === id) || PROVIDERS[0];
|
|
2782
|
+
$('cfg-saved').value = 'new';
|
|
2783
|
+
cfgModelRequest += 1;
|
|
2784
|
+
clearTimeout(cfgKeyTimer);
|
|
2785
|
+
cfgBusy = '';
|
|
2786
|
+
cfgEditingId = 'new';
|
|
2787
|
+
cfgProviderId = id;
|
|
2788
|
+
cfgDraft = { baseUrl: preset.baseUrl, model: '', apiKey: '' };
|
|
2789
|
+
cfgModels = [];
|
|
2790
|
+
cfgManualModel = false;
|
|
2791
|
+
cfgDeleteArmed = false;
|
|
2792
|
+
cfgMessage('');
|
|
2793
|
+
renderCfg();
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
async function discoverCfgModels() {
|
|
2797
|
+
if (cfgBusy === 'save' || cfgBusy === 'follow') return;
|
|
2798
|
+
const seq = ++cfgModelRequest;
|
|
2799
|
+
cfgBusy = 'models'; cfgMessage(''); renderCfg();
|
|
2800
|
+
try {
|
|
2801
|
+
const d = await api('/translate/models', {
|
|
2802
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
2803
|
+
body: JSON.stringify({ id: cfgEditingId, baseUrl: cfgDraft.baseUrl.trim(), apiKey: cfgDraft.apiKey.trim() }),
|
|
2804
|
+
});
|
|
2805
|
+
if (seq !== cfgModelRequest) return;
|
|
2806
|
+
cfgModels = d.models || [];
|
|
2807
|
+
cfgManualModel = false;
|
|
2808
|
+
if (!cfgModels.includes(cfgDraft.model)) cfgDraft.model = cfgModels[0] || cfgDraft.model;
|
|
2809
|
+
cfgMessage(`已获取 ${cfgModels.length} 个模型,请选择翻译模型`, true);
|
|
2810
|
+
} catch (e) {
|
|
2811
|
+
if (seq === cfgModelRequest) { cfgManualModel = true; cfgMessage(e.message, false); }
|
|
2812
|
+
} finally {
|
|
2813
|
+
if (seq === cfgModelRequest) { cfgBusy = ''; renderCfg(); }
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
function scheduleCfgDiscovery() {
|
|
2817
|
+
clearTimeout(cfgKeyTimer);
|
|
2818
|
+
if (!cfgDraft.apiKey.trim()) return;
|
|
2819
|
+
cfgKeyTimer = setTimeout(() => { void discoverCfgModels(); }, 700);
|
|
2820
|
+
}
|
|
2821
|
+
$('cfg-key').addEventListener('input', (e) => { cfgDraft.apiKey = e.target.value; scheduleCfgDiscovery(); });
|
|
2822
|
+
$('cfg-url').addEventListener('input', (e) => { cfgDraft.baseUrl = e.target.value; $('cfg-save').disabled = !cfgDraft.model.trim(); scheduleCfgDiscovery(); });
|
|
2823
|
+
$('cfg-model').addEventListener('input', (e) => { cfgDraft.model = e.target.value; $('cfg-save').disabled = !cfgDraft.model.trim(); });
|
|
2824
|
+
for (const key of ['splitTokens', 'maxOutputTokens', 'qps']) {
|
|
2825
|
+
$(CFG_OPTION_IDS[key]).addEventListener('input', (e) => { cfgOptions[key] = e.target.value; });
|
|
2826
|
+
}
|
|
2827
|
+
$('cfg-options-save').onclick = async () => {
|
|
2828
|
+
$('cfg-options-save').disabled = true;
|
|
2829
|
+
try {
|
|
2830
|
+
const d = await api('/translate/config/options', {
|
|
2831
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
2832
|
+
body: JSON.stringify({ splitTokens: Number(cfgOptions.splitTokens), maxOutputTokens: Number(cfgOptions.maxOutputTokens), qps: Number(cfgOptions.qps) }),
|
|
2833
|
+
});
|
|
2834
|
+
cfgOptions = d.options;
|
|
2835
|
+
cfgMessage('翻译参数已保存,下一篇 PDF 起生效', true);
|
|
2836
|
+
renderCfg();
|
|
2837
|
+
} catch (e) { cfgMessage(e.message, false); } finally { $('cfg-options-save').disabled = false; }
|
|
2838
|
+
};
|
|
2839
|
+
$('cfg-refresh').onclick = () => { void discoverCfgModels(); };
|
|
2583
2840
|
$('cfg-saved').onchange = () => fillCfgEndpoint(cfgEndpoints.find((e) => e.id === $('cfg-saved').value) || null);
|
|
2584
2841
|
$('cfg-new').onclick = () => { $('cfg-saved').value = 'new'; fillCfgEndpoint(null); };
|
|
2585
2842
|
$('cfg-delete').onclick = async () => {
|
|
2586
2843
|
const e = cfgEndpoints.find((x) => x.id === cfgEditingId);
|
|
2587
2844
|
if (!e || e.source === 'profile') return;
|
|
2588
2845
|
if (!cfgDeleteArmed) {
|
|
2589
|
-
cfgDeleteArmed = true;
|
|
2590
|
-
|
|
2591
|
-
setTimeout(() => { cfgDeleteArmed = false; $('cfg-delete').textContent = '删除当前'; }, 3000);
|
|
2846
|
+
cfgDeleteArmed = true; renderCfg();
|
|
2847
|
+
setTimeout(() => { cfgDeleteArmed = false; renderCfg(); }, 3000);
|
|
2592
2848
|
return;
|
|
2593
2849
|
}
|
|
2594
2850
|
try {
|
|
2595
2851
|
await api('/translate/config?id=' + encodeURIComponent(e.id), { method: 'DELETE' });
|
|
2596
|
-
|
|
2852
|
+
await api('/translate/config/selection', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: 'harness' }) });
|
|
2853
|
+
toast('端点已删除,已恢复跟随 Harness');
|
|
2597
2854
|
await openCfgPop(false);
|
|
2598
|
-
} catch (err) {
|
|
2855
|
+
} catch (err) { cfgMessage('删除失败:' + err.message, false); }
|
|
2599
2856
|
};
|
|
2600
2857
|
|
|
2601
2858
|
async function openCfgPop(retryGenerate) {
|
|
2602
|
-
$('theme-pop').style.display = 'none';
|
|
2859
|
+
$('theme-pop').style.display = 'none';
|
|
2603
2860
|
cfgRetryGenerate = Boolean(retryGenerate);
|
|
2604
2861
|
let cfg;
|
|
2605
|
-
try {
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2862
|
+
try { cfg = await api('/translate/config'); }
|
|
2863
|
+
catch (e) { toast('读取配置失败:' + e.message, 8000); return; }
|
|
2864
|
+
cfgData = cfg;
|
|
2865
|
+
cfgOptions = cfg.options || { splitTokens: 100000, maxOutputTokens: 32768, qps: 16 };
|
|
2866
|
+
cfgEndpoints = (cfg.endpoints || []).filter((e) => e.source !== 'harness');
|
|
2609
2867
|
fillCfgList(cfg.activeId);
|
|
2868
|
+
cfgMode = cfg.mode === 'follow' ? 'follow' : 'custom';
|
|
2869
|
+
cfgMessage('');
|
|
2870
|
+
renderCfg();
|
|
2610
2871
|
const pop = $('cfg-pop');
|
|
2611
2872
|
pop.style.display = 'block';
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
pop.style.top = Math.max(8, (window.innerHeight - pop.offsetHeight) / 3) + 'px';
|
|
2615
|
-
$('cfg-key').focus();
|
|
2873
|
+
positionCfgPop();
|
|
2874
|
+
(cfgMode === 'custom' ? $('cfg-key') : $('cfg-follow')).focus();
|
|
2616
2875
|
}
|
|
2617
2876
|
function closeCfgPop() { $('cfg-pop').style.display = 'none'; cfgRetryGenerate = false; cfgRetryForce = false; cfgRetryTranslate = false; }
|
|
2618
|
-
|
|
2619
|
-
// toggle 语义:面板开着时再点 ⚙ 直接收回(不重新拉配置重开)
|
|
2620
2877
|
$('cfg-open').onclick = (e) => {
|
|
2621
2878
|
e.stopPropagation();
|
|
2622
2879
|
if ($('cfg-pop').style.display === 'block') { closeCfgPop(); return; }
|
|
2623
2880
|
void openCfgPop(false);
|
|
2624
2881
|
};
|
|
2625
2882
|
document.addEventListener('click', (e) => {
|
|
2626
|
-
|
|
2627
|
-
//
|
|
2628
|
-
|
|
2883
|
+
// 厂商/模型点击会同步重绘并移除原按钮;composedPath 仍保留事件开始时的浮层路径,
|
|
2884
|
+
// 不能再用 e.target.closest()——那会把一次浮层内点击误判成外部点击并提前关闭。
|
|
2885
|
+
const path = e.composedPath();
|
|
2886
|
+
if (path.includes($('cfg-pop')) || path.includes($('cfg-open'))) return;
|
|
2887
|
+
if ($('cfg-pop').style.display === 'block') closeCfgPop();
|
|
2629
2888
|
});
|
|
2630
2889
|
$('cfg-cancel').onclick = closeCfgPop;
|
|
2890
|
+
$('cfg-custom').onclick = () => { cfgMode = 'custom'; cfgMessage(''); renderCfg(); };
|
|
2891
|
+
$('cfg-follow').onclick = async () => {
|
|
2892
|
+
if (cfgMode === 'follow' || !cfgData?.harness) return;
|
|
2893
|
+
cfgModelRequest += 1;
|
|
2894
|
+
cfgBusy = 'follow'; cfgMessage('');
|
|
2895
|
+
const retry = cfgRetryGenerate, force = cfgRetryForce, retryTr = cfgRetryTranslate;
|
|
2896
|
+
try {
|
|
2897
|
+
await api('/translate/config/selection', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: 'harness' }) });
|
|
2898
|
+
closeCfgPop();
|
|
2899
|
+
await refreshZhState();
|
|
2900
|
+
if (retry) startGenerate(force, 'harness');
|
|
2901
|
+
else if (retryTr) translateSelection();
|
|
2902
|
+
else toast('已恢复为跟随 Harness,自定义配置已保留');
|
|
2903
|
+
} catch (e) { cfgMessage(e.message, false); } finally { cfgBusy = ''; }
|
|
2904
|
+
};
|
|
2631
2905
|
|
|
2632
|
-
async function saveCfg(saveAsNew) {
|
|
2633
|
-
|
|
2634
|
-
|
|
2906
|
+
async function saveCfg(saveAsNew, modelOverride) {
|
|
2907
|
+
const model = (modelOverride ?? cfgDraft.model).trim();
|
|
2908
|
+
if (!model) return;
|
|
2635
2909
|
const retry = cfgRetryGenerate, force = cfgRetryForce, retryTr = cfgRetryTranslate;
|
|
2636
|
-
|
|
2910
|
+
cfgModelRequest += 1;
|
|
2911
|
+
cfgBusy = 'save'; cfgMessage(''); renderCfg();
|
|
2637
2912
|
let saved;
|
|
2638
2913
|
try {
|
|
2639
|
-
// 服务端先打一发极小的 chat/completions 验证 url/key/model,通过才落盘
|
|
2640
2914
|
saved = await api('/translate/config', {
|
|
2641
|
-
method: 'POST',
|
|
2642
|
-
headers: { 'content-type': 'application/json' },
|
|
2915
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
2643
2916
|
body: JSON.stringify({
|
|
2644
2917
|
id: saveAsNew ? 'new' : cfgEditingId,
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2918
|
+
label: PROVIDERS.find((p) => p.id === cfgProviderId)?.name || '自定义',
|
|
2919
|
+
provider: cfgProviderId,
|
|
2920
|
+
baseUrl: cfgDraft.baseUrl.trim(), apiKey: cfgDraft.apiKey.trim(), model,
|
|
2648
2921
|
}),
|
|
2649
2922
|
});
|
|
2650
2923
|
} catch (e) {
|
|
2651
|
-
|
|
2924
|
+
cfgMessage('保存失败:' + e.message, false);
|
|
2652
2925
|
return;
|
|
2653
|
-
} finally {
|
|
2654
|
-
btn.disabled = false; btn.textContent = label;
|
|
2655
|
-
}
|
|
2926
|
+
} finally { cfgBusy = ''; }
|
|
2656
2927
|
closeCfgPop();
|
|
2657
2928
|
await refreshZhState();
|
|
2658
|
-
if (retry) startGenerate(force, saved.id);
|
|
2659
|
-
else if (retryTr) translateSelection();
|
|
2660
|
-
else toast('
|
|
2929
|
+
if (retry) startGenerate(force, saved.id);
|
|
2930
|
+
else if (retryTr) translateSelection();
|
|
2931
|
+
else toast('翻译模型已保存,仅影响翻译');
|
|
2661
2932
|
}
|
|
2662
2933
|
$('cfg-save').onclick = () => saveCfg(false);
|
|
2663
2934
|
$('cfg-save-new').onclick = () => saveCfg(true);
|