@ggboy123/dsh-paper-reader 1.8.3 → 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 +9 -8
- package/dist/harness-translate.js +204 -0
- package/dist/host.js +165 -21
- package/dist/index.js +2 -1
- package/dist/library-manage.js +100 -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 +652 -92
- package/package.json +1 -1
- package/reader/index.html +460 -130
- 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
|
@@ -245,15 +245,24 @@
|
|
|
245
245
|
border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 600; flex: none; }
|
|
246
246
|
#note-head .spacer, #note-actions .spacer { flex: 1; }
|
|
247
247
|
#note-headcount { font-weight: 400; color: var(--text-2); font-variant-numeric: tabular-nums; }
|
|
248
|
-
#note-list { flex: 1; overflow: auto; padding:
|
|
249
|
-
.note-item {
|
|
250
|
-
background: var(--bg); color: var(--text);
|
|
251
|
-
.note-item:hover { border-color: var(--accent); }
|
|
252
|
-
.note-item
|
|
253
|
-
|
|
248
|
+
#note-list { flex: 1; overflow: auto; padding: 6px 8px 10px; }
|
|
249
|
+
.note-item { position: relative; width: 100%; margin: 6px 0; border: 1px solid var(--border); border-radius: 7px;
|
|
250
|
+
background: var(--bg); color: var(--text); font-size: 12px; line-height: 1.5; }
|
|
251
|
+
.note-item:hover, .note-item:focus-within { border-color: var(--accent); }
|
|
252
|
+
.note-item-main { display: block; width: 100%; padding: 7px 9px; border: 0; border-radius: 7px;
|
|
253
|
+
background: transparent; color: inherit; text-align: left; cursor: pointer; font: inherit; }
|
|
254
|
+
.note-item-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
|
|
255
|
+
.note-item .ni-meta { display: flex; align-items: center; color: var(--accent); font-size: 11px; margin-bottom: 3px; }
|
|
256
|
+
.note-item .ni-meta .ni-time { margin-left: auto; padding-right: 37px; color: var(--text-2); font-weight: 400; font-size: 10.5px; }
|
|
257
|
+
.note-item.delete-armed .ni-meta .ni-time { visibility: hidden; }
|
|
254
258
|
.note-item .ni-body { display: block; white-space: pre-wrap; word-break: break-word; }
|
|
255
|
-
.note-item .ni-quote { display: block; color: var(--text-2); font-size: 11px; margin-top:
|
|
259
|
+
.note-item .ni-quote { display: block; color: var(--text-2); font-size: 11px; margin-top: 4px;
|
|
256
260
|
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
261
|
+
.note-item-delete { position: absolute; z-index: 1; top: 5px; right: 6px; min-width: 32px; height: 21px; padding: 0 4px;
|
|
262
|
+
border: 0; border-radius: 4px; background: transparent; color: var(--text-2); cursor: pointer; font: inherit; font-size: 11px; }
|
|
263
|
+
.note-item-delete:hover, .note-item-delete:focus-visible { background: var(--panel); color: #cf222e; outline: 1px solid var(--border); }
|
|
264
|
+
.note-item-delete.armed { background: #cf222e; color: #fff; }
|
|
265
|
+
.note-item-delete:disabled { opacity: .55; cursor: default; }
|
|
257
266
|
#note-empty { padding: 14px 6px; color: var(--text-2); font-size: 12px; line-height: 1.6; }
|
|
258
267
|
#note-editor { display: none; flex-direction: column; flex: 1; min-height: 0; padding: 6px 8px 8px; }
|
|
259
268
|
#note-window.editing #note-list, #note-window.editing #note-empty { display: none; }
|
|
@@ -308,25 +317,70 @@
|
|
|
308
317
|
#tr-body .tr-math-block .katex-display { margin: 0; }
|
|
309
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; }
|
|
310
319
|
|
|
311
|
-
/* ----------
|
|
312
|
-
/* 阅读器在窄 iframe 里,宽度要能收缩 */
|
|
320
|
+
/* ---------- 全文翻译模型设置:与 dsh 设置页同一套跟随 / 覆盖语义 ---------- */
|
|
313
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; }
|
|
314
323
|
#cfg-pop h3, #theme-pop h3 { margin: 0; font-size: 13px; }
|
|
315
|
-
#cfg-
|
|
316
|
-
#cfg-
|
|
317
|
-
|
|
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; }
|
|
318
329
|
#cfg-pop input[type="checkbox"], #theme-pop input[type="checkbox"] { width: auto; }
|
|
319
330
|
#theme-pop h3 { display: flex; align-items: center; justify-content: space-between; }
|
|
320
331
|
#theme-close { all: unset; cursor: pointer; font-size: 12px; color: var(--text-2); padding: 2px 6px; border-radius: 4px; }
|
|
321
332
|
#theme-close:hover { background: var(--bg); color: var(--text); }
|
|
322
|
-
#cfg-pop input, #cfg-pop select, #theme-pop input, #theme-pop select { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding:
|
|
323
|
-
#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; }
|
|
324
364
|
#cfg-source:empty { display: none; }
|
|
325
|
-
#cfg-
|
|
326
|
-
#cfg-
|
|
327
|
-
#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; }
|
|
328
373
|
#cfg-save:disabled, #generate-start:disabled { opacity: .5; cursor: default; }
|
|
329
|
-
#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; } }
|
|
330
384
|
|
|
331
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%; }
|
|
332
386
|
/* ---------- 深色模式(方案 §A2.1;设置项 §A2.3)----------
|
|
@@ -505,31 +559,66 @@
|
|
|
505
559
|
<div id="tr-note"></div>
|
|
506
560
|
</div>
|
|
507
561
|
|
|
508
|
-
<div id="cfg-pop">
|
|
509
|
-
<h3
|
|
510
|
-
<div id="cfg-hint"
|
|
511
|
-
<div
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
<div id="cfg-list-actions">
|
|
515
|
-
<button id="cfg-new" class="tbtn">新增端点</button>
|
|
516
|
-
<button id="cfg-delete" class="tbtn">删除当前</button>
|
|
517
|
-
</div>
|
|
518
|
-
<label for="cfg-provider">供应商</label>
|
|
519
|
-
<select id="cfg-provider"></select>
|
|
520
|
-
<label for="cfg-url">端点 URL</label>
|
|
521
|
-
<input id="cfg-url" type="text" placeholder="https://api.deepseek.com/v1" autocomplete="off">
|
|
522
|
-
<label for="cfg-key">API Key</label>
|
|
523
|
-
<input id="cfg-key" type="password" placeholder="sk-..." autocomplete="new-password">
|
|
524
|
-
<label for="cfg-model">模型</label>
|
|
525
|
-
<input id="cfg-model" type="text" placeholder="deepseek-chat" autocomplete="off" list="cfg-model-list">
|
|
526
|
-
<datalist id="cfg-model-list"></datalist>
|
|
527
|
-
<div id="cfg-model-hint">glm-5.x / k3 / deepseek-flash 是推理型模型,服务端已自动关闭思考;选自定义端点时建议用非推理模型,否则会慢好几倍。</div>
|
|
528
|
-
<div id="cfg-actions">
|
|
529
|
-
<button id="cfg-cancel">取消</button>
|
|
530
|
-
<button id="cfg-save-new">另存为新端点</button>
|
|
531
|
-
<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>
|
|
532
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>
|
|
533
622
|
</div>
|
|
534
623
|
|
|
535
624
|
<div id="generate-pop">
|
|
@@ -1590,11 +1679,12 @@ window.dprFindDebug = () => {
|
|
|
1590
1679
|
盒子层 pointer-events:none,悬停/点击靠坐标命中测试 —— 绝不挡住划词选字。 */
|
|
1591
1680
|
const NOTE_WIN_KEY = 'dpr.noteWin';
|
|
1592
1681
|
const NOTE_BODY_MAX = 20000;
|
|
1593
|
-
const notes = { list: [], shown: false, editing: null, isNew: true, armed: false, loading: false };
|
|
1682
|
+
const notes = { list: [], shown: false, editing: null, isNew: true, armed: false, listDeleteId: null, loading: false };
|
|
1594
1683
|
let noteWin = { x: null, y: null, w: 330, h: 360 };
|
|
1595
1684
|
const noteWinEl = $('note-window');
|
|
1596
1685
|
const noteTipEl = $('note-tip');
|
|
1597
1686
|
let noteArmTimer = 0;
|
|
1687
|
+
let noteListDeleteTimer = 0;
|
|
1598
1688
|
let noteHoverRaf = 0;
|
|
1599
1689
|
let noteHoverId = null;
|
|
1600
1690
|
|
|
@@ -1882,6 +1972,7 @@ function noteWinShow(on) {
|
|
|
1882
1972
|
if (!on) {
|
|
1883
1973
|
noteWinEl.classList.remove('on');
|
|
1884
1974
|
notes.shown = false;
|
|
1975
|
+
noteResetListDelete();
|
|
1885
1976
|
noteHideTip();
|
|
1886
1977
|
return;
|
|
1887
1978
|
}
|
|
@@ -1900,6 +1991,7 @@ function renderNoteList() {
|
|
|
1900
1991
|
const list = $('note-list');
|
|
1901
1992
|
const head = $('note-headcount');
|
|
1902
1993
|
if (!list || !head) return;
|
|
1994
|
+
noteResetListDelete();
|
|
1903
1995
|
head.textContent = notes.list.length ? `${notes.list.length} 条` : '';
|
|
1904
1996
|
list.textContent = '';
|
|
1905
1997
|
if (!notes.list.length) {
|
|
@@ -1920,9 +2012,12 @@ function renderNoteList() {
|
|
|
1920
2012
|
});
|
|
1921
2013
|
const frag = document.createDocumentFragment();
|
|
1922
2014
|
for (const n of sorted) {
|
|
2015
|
+
const item = document.createElement('div');
|
|
2016
|
+
item.className = 'note-item';
|
|
2017
|
+
item.dataset.id = n.id;
|
|
1923
2018
|
const btn = document.createElement('button');
|
|
1924
2019
|
btn.type = 'button';
|
|
1925
|
-
btn.className = 'note-item';
|
|
2020
|
+
btn.className = 'note-item-main';
|
|
1926
2021
|
btn.dataset.id = n.id;
|
|
1927
2022
|
btn.title = n.anchor && n.anchor.page ? `跳到第 ${n.anchor.page} 页` : '这条笔记没有可定位的原文位置';
|
|
1928
2023
|
const meta = document.createElement('span');
|
|
@@ -1944,7 +2039,16 @@ function renderNoteList() {
|
|
|
1944
2039
|
q.textContent = '「' + String(n.quote).replace(/\s+/g, ' ') + '」';
|
|
1945
2040
|
btn.appendChild(q);
|
|
1946
2041
|
}
|
|
1947
|
-
|
|
2042
|
+
const del = document.createElement('button');
|
|
2043
|
+
del.type = 'button';
|
|
2044
|
+
del.className = 'note-item-delete';
|
|
2045
|
+
del.dataset.noteDelete = n.id;
|
|
2046
|
+
del.textContent = '删除';
|
|
2047
|
+
del.title = '删除这条笔记';
|
|
2048
|
+
del.setAttribute('aria-label', `删除笔记:${body.slice(0, 40)}`);
|
|
2049
|
+
item.appendChild(btn);
|
|
2050
|
+
item.appendChild(del);
|
|
2051
|
+
frag.appendChild(item);
|
|
1948
2052
|
}
|
|
1949
2053
|
list.appendChild(frag);
|
|
1950
2054
|
}
|
|
@@ -2005,6 +2109,33 @@ async function noteSave() {
|
|
|
2005
2109
|
} catch (e) { toast('保存失败:' + e.message, 6000); }
|
|
2006
2110
|
$('note-save').disabled = false;
|
|
2007
2111
|
}
|
|
2112
|
+
function noteResetListDelete() {
|
|
2113
|
+
clearTimeout(noteListDeleteTimer);
|
|
2114
|
+
notes.listDeleteId = null;
|
|
2115
|
+
for (const btn of document.querySelectorAll('.note-item-delete')) {
|
|
2116
|
+
btn.disabled = false;
|
|
2117
|
+
btn.classList.remove('armed');
|
|
2118
|
+
btn.textContent = '删除';
|
|
2119
|
+
btn.title = '删除这条笔记';
|
|
2120
|
+
btn.closest('.note-item')?.classList.remove('delete-armed');
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
function noteArmListDelete(note, btn) {
|
|
2124
|
+
if (!note || !note.id || !btn) return;
|
|
2125
|
+
if (notes.listDeleteId !== note.id) {
|
|
2126
|
+
noteResetListDelete();
|
|
2127
|
+
notes.listDeleteId = note.id;
|
|
2128
|
+
btn.classList.add('armed');
|
|
2129
|
+
btn.closest('.note-item')?.classList.add('delete-armed');
|
|
2130
|
+
btn.textContent = '确认删除';
|
|
2131
|
+
btn.title = '再点一次确认删除这条笔记';
|
|
2132
|
+
noteListDeleteTimer = setTimeout(noteResetListDelete, 3000);
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
clearTimeout(noteListDeleteTimer);
|
|
2136
|
+
btn.disabled = true;
|
|
2137
|
+
void noteDoDelete(note);
|
|
2138
|
+
}
|
|
2008
2139
|
function noteArmDelete() {
|
|
2009
2140
|
const btn = $('note-delete');
|
|
2010
2141
|
if (!notes.editing || notes.isNew) return;
|
|
@@ -2037,6 +2168,7 @@ async function noteDoDelete(note) {
|
|
|
2037
2168
|
notesReapply();
|
|
2038
2169
|
toast('笔记已删除');
|
|
2039
2170
|
} catch (e) { toast('删除失败:' + e.message, 6000); }
|
|
2171
|
+
finally { noteResetListDelete(); }
|
|
2040
2172
|
}
|
|
2041
2173
|
async function noteGoto(note) {
|
|
2042
2174
|
if (!note) return;
|
|
@@ -2089,7 +2221,14 @@ $('note-save').onclick = () => void noteSave();
|
|
|
2089
2221
|
$('note-cancel').onclick = () => noteSetEditing(false);
|
|
2090
2222
|
$('note-delete').onclick = () => noteArmDelete();
|
|
2091
2223
|
$('note-list').addEventListener('click', (e) => {
|
|
2092
|
-
const
|
|
2224
|
+
const del = e.target.closest ? e.target.closest('[data-note-delete]') : null;
|
|
2225
|
+
if (del) {
|
|
2226
|
+
e.preventDefault();
|
|
2227
|
+
e.stopPropagation();
|
|
2228
|
+
noteArmListDelete(noteById(del.dataset.noteDelete), del);
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
const btn = e.target.closest ? e.target.closest('.note-item-main') : null;
|
|
2093
2232
|
if (!btn) return;
|
|
2094
2233
|
void noteGoto(noteById(btn.dataset.id));
|
|
2095
2234
|
});
|
|
@@ -2342,6 +2481,7 @@ $('split-toggle').onclick = () => setViewMode(viewMode === 'split' ? 'orig' : 's
|
|
|
2342
2481
|
let generateForce = false;
|
|
2343
2482
|
let generateEndpoints = [];
|
|
2344
2483
|
function endpointDisplay(e) {
|
|
2484
|
+
if (e.source === 'harness') return `跟随 Harness · ${e.providerName || '当前模型'} / ${e.model}`;
|
|
2345
2485
|
const provider = providerOf(e.baseUrl).name;
|
|
2346
2486
|
return `${e.label || provider} · ${e.model || '未填模型'} · ${e.apiKeyHint || '无 Key'}`;
|
|
2347
2487
|
}
|
|
@@ -2446,65 +2586,175 @@ $('zh-regen').onclick = async () => {
|
|
|
2446
2586
|
regenArmTimer = setTimeout(disarmRegen, 3000);
|
|
2447
2587
|
};
|
|
2448
2588
|
|
|
2449
|
-
/* =================
|
|
2450
|
-
// 供应商预设(OpenAI 兼容端点,对齐 lflow 的供应商清单):选中即回填 URL + 推荐模型。
|
|
2451
|
-
// 一律走 Coding 套餐端点——买套餐是常态;套餐 key 走按量口会报余额不足。按量用户选「自定义」手填。
|
|
2452
|
-
// models 仅作 datalist 建议,输入框仍可自由填写(新型号上线不用发版)。
|
|
2453
|
-
// glm-5.x / k3 / deepseek-flash 是推理型,服务端会对这三家域名自动关 thinking(translate.ts)。
|
|
2589
|
+
/* ================= 全文翻译模型设置(与 dsh 设置页一致) ================= */
|
|
2454
2590
|
const PROVIDERS = [
|
|
2455
|
-
{ id: '
|
|
2456
|
-
{ id: '
|
|
2457
|
-
{ id: '
|
|
2458
|
-
{ id: '
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
{ 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: '' },
|
|
2462
2599
|
];
|
|
2463
2600
|
const normUrl = (u) => (u || '').trim().replace(/\/+$/, '');
|
|
2464
|
-
|
|
2465
|
-
const
|
|
2466
|
-
|
|
2467
|
-
(
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
const p = PROVIDERS.find((x) => x.id === sel.value) || PROVIDERS[0];
|
|
2476
|
-
if (p.baseUrl) $('cfg-url').value = p.baseUrl; // custom 不动用户已填的 URL
|
|
2477
|
-
$('cfg-model-list').innerHTML = p.models.map((m) => `<option value="${esc(m)}">`).join('');
|
|
2478
|
-
if (p.models.length && !p.models.includes($('cfg-model').value.trim())) $('cfg-model').value = p.models[0];
|
|
2479
|
-
};
|
|
2480
|
-
})();
|
|
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
|
+
}
|
|
2481
2612
|
|
|
2482
|
-
// 保存成功后是否自动接着生成:点「中译」/「重翻」发现没配 → 弹本表单 → 填完直接开跑
|
|
2483
2613
|
let cfgRetryGenerate = false;
|
|
2484
|
-
let cfgRetryForce = false;
|
|
2485
|
-
let cfgRetryTranslate = false;
|
|
2614
|
+
let cfgRetryForce = false;
|
|
2615
|
+
let cfgRetryTranslate = false;
|
|
2616
|
+
let cfgData = null;
|
|
2486
2617
|
let cfgEndpoints = [];
|
|
2487
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;
|
|
2488
2629
|
let cfgDeleteArmed = false;
|
|
2489
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
|
+
}
|
|
2490
2745
|
function fillCfgEndpoint(e) {
|
|
2746
|
+
cfgModelRequest += 1;
|
|
2747
|
+
clearTimeout(cfgKeyTimer);
|
|
2748
|
+
cfgBusy = '';
|
|
2491
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;
|
|
2492
2755
|
cfgDeleteArmed = false;
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
$('cfg-url').value = e?.baseUrl || '';
|
|
2496
|
-
$('cfg-model').value = e?.model || '';
|
|
2497
|
-
const sel = $('cfg-provider');
|
|
2498
|
-
sel.value = providerOf(e?.baseUrl).id;
|
|
2499
|
-
const keepUrl = $('cfg-url').value, keepModel = $('cfg-model').value;
|
|
2500
|
-
sel.onchange();
|
|
2501
|
-
$('cfg-url').value = keepUrl || $('cfg-url').value;
|
|
2502
|
-
$('cfg-model').value = keepModel || $('cfg-model').value;
|
|
2503
|
-
$('cfg-key').value = '';
|
|
2504
|
-
$('cfg-key').placeholder = e?.hasApiKey ? `已保存(${e.apiKeyHint}),留空则不修改` : 'sk-...';
|
|
2505
|
-
$('cfg-source').textContent = e
|
|
2506
|
-
? `${e.source === 'profile' ? 'profile 默认配置(保存会另存为本界面配置)' : '本界面保存的配置'}(key ${e.apiKeyHint || '未填'})`
|
|
2507
|
-
: '新端点:保存前会先做连接测试';
|
|
2756
|
+
cfgMessage('');
|
|
2757
|
+
renderCfg();
|
|
2508
2758
|
}
|
|
2509
2759
|
function fillCfgList(activeId) {
|
|
2510
2760
|
const sel = $('cfg-saved');
|
|
@@ -2517,88 +2767,168 @@ function fillCfgList(activeId) {
|
|
|
2517
2767
|
const add = document.createElement('option');
|
|
2518
2768
|
add.value = 'new'; add.textContent = '+ 新建端点…';
|
|
2519
2769
|
sel.appendChild(add);
|
|
2520
|
-
const selected = cfgEndpoints.find((e) => e.id === activeId) || null;
|
|
2770
|
+
const selected = cfgEndpoints.find((e) => e.id === activeId) || cfgEndpoints[0] || null;
|
|
2521
2771
|
sel.value = selected?.id || 'new';
|
|
2522
2772
|
fillCfgEndpoint(selected);
|
|
2523
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(); };
|
|
2524
2840
|
$('cfg-saved').onchange = () => fillCfgEndpoint(cfgEndpoints.find((e) => e.id === $('cfg-saved').value) || null);
|
|
2525
2841
|
$('cfg-new').onclick = () => { $('cfg-saved').value = 'new'; fillCfgEndpoint(null); };
|
|
2526
2842
|
$('cfg-delete').onclick = async () => {
|
|
2527
2843
|
const e = cfgEndpoints.find((x) => x.id === cfgEditingId);
|
|
2528
2844
|
if (!e || e.source === 'profile') return;
|
|
2529
2845
|
if (!cfgDeleteArmed) {
|
|
2530
|
-
cfgDeleteArmed = true;
|
|
2531
|
-
|
|
2532
|
-
setTimeout(() => { cfgDeleteArmed = false; $('cfg-delete').textContent = '删除当前'; }, 3000);
|
|
2846
|
+
cfgDeleteArmed = true; renderCfg();
|
|
2847
|
+
setTimeout(() => { cfgDeleteArmed = false; renderCfg(); }, 3000);
|
|
2533
2848
|
return;
|
|
2534
2849
|
}
|
|
2535
2850
|
try {
|
|
2536
2851
|
await api('/translate/config?id=' + encodeURIComponent(e.id), { method: 'DELETE' });
|
|
2537
|
-
|
|
2852
|
+
await api('/translate/config/selection', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: 'harness' }) });
|
|
2853
|
+
toast('端点已删除,已恢复跟随 Harness');
|
|
2538
2854
|
await openCfgPop(false);
|
|
2539
|
-
} catch (err) {
|
|
2855
|
+
} catch (err) { cfgMessage('删除失败:' + err.message, false); }
|
|
2540
2856
|
};
|
|
2541
2857
|
|
|
2542
2858
|
async function openCfgPop(retryGenerate) {
|
|
2543
|
-
$('theme-pop').style.display = 'none';
|
|
2859
|
+
$('theme-pop').style.display = 'none';
|
|
2544
2860
|
cfgRetryGenerate = Boolean(retryGenerate);
|
|
2545
2861
|
let cfg;
|
|
2546
|
-
try {
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
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');
|
|
2550
2867
|
fillCfgList(cfg.activeId);
|
|
2868
|
+
cfgMode = cfg.mode === 'follow' ? 'follow' : 'custom';
|
|
2869
|
+
cfgMessage('');
|
|
2870
|
+
renderCfg();
|
|
2551
2871
|
const pop = $('cfg-pop');
|
|
2552
2872
|
pop.style.display = 'block';
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
pop.style.top = Math.max(8, (window.innerHeight - pop.offsetHeight) / 3) + 'px';
|
|
2556
|
-
$('cfg-key').focus();
|
|
2873
|
+
positionCfgPop();
|
|
2874
|
+
(cfgMode === 'custom' ? $('cfg-key') : $('cfg-follow')).focus();
|
|
2557
2875
|
}
|
|
2558
2876
|
function closeCfgPop() { $('cfg-pop').style.display = 'none'; cfgRetryGenerate = false; cfgRetryForce = false; cfgRetryTranslate = false; }
|
|
2559
|
-
|
|
2560
|
-
// toggle 语义:面板开着时再点 ⚙ 直接收回(不重新拉配置重开)
|
|
2561
2877
|
$('cfg-open').onclick = (e) => {
|
|
2562
2878
|
e.stopPropagation();
|
|
2563
2879
|
if ($('cfg-pop').style.display === 'block') { closeCfgPop(); return; }
|
|
2564
2880
|
void openCfgPop(false);
|
|
2565
2881
|
};
|
|
2566
2882
|
document.addEventListener('click', (e) => {
|
|
2567
|
-
|
|
2568
|
-
//
|
|
2569
|
-
|
|
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();
|
|
2570
2888
|
});
|
|
2571
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
|
+
};
|
|
2572
2905
|
|
|
2573
|
-
async function saveCfg(saveAsNew) {
|
|
2574
|
-
|
|
2575
|
-
|
|
2906
|
+
async function saveCfg(saveAsNew, modelOverride) {
|
|
2907
|
+
const model = (modelOverride ?? cfgDraft.model).trim();
|
|
2908
|
+
if (!model) return;
|
|
2576
2909
|
const retry = cfgRetryGenerate, force = cfgRetryForce, retryTr = cfgRetryTranslate;
|
|
2577
|
-
|
|
2910
|
+
cfgModelRequest += 1;
|
|
2911
|
+
cfgBusy = 'save'; cfgMessage(''); renderCfg();
|
|
2578
2912
|
let saved;
|
|
2579
2913
|
try {
|
|
2580
|
-
// 服务端先打一发极小的 chat/completions 验证 url/key/model,通过才落盘
|
|
2581
2914
|
saved = await api('/translate/config', {
|
|
2582
|
-
method: 'POST',
|
|
2583
|
-
headers: { 'content-type': 'application/json' },
|
|
2915
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
2584
2916
|
body: JSON.stringify({
|
|
2585
2917
|
id: saveAsNew ? 'new' : cfgEditingId,
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2918
|
+
label: PROVIDERS.find((p) => p.id === cfgProviderId)?.name || '自定义',
|
|
2919
|
+
provider: cfgProviderId,
|
|
2920
|
+
baseUrl: cfgDraft.baseUrl.trim(), apiKey: cfgDraft.apiKey.trim(), model,
|
|
2589
2921
|
}),
|
|
2590
2922
|
});
|
|
2591
2923
|
} catch (e) {
|
|
2592
|
-
|
|
2924
|
+
cfgMessage('保存失败:' + e.message, false);
|
|
2593
2925
|
return;
|
|
2594
|
-
} finally {
|
|
2595
|
-
btn.disabled = false; btn.textContent = label;
|
|
2596
|
-
}
|
|
2926
|
+
} finally { cfgBusy = ''; }
|
|
2597
2927
|
closeCfgPop();
|
|
2598
2928
|
await refreshZhState();
|
|
2599
|
-
if (retry) startGenerate(force, saved.id);
|
|
2600
|
-
else if (retryTr) translateSelection();
|
|
2601
|
-
else toast('
|
|
2929
|
+
if (retry) startGenerate(force, saved.id);
|
|
2930
|
+
else if (retryTr) translateSelection();
|
|
2931
|
+
else toast('翻译模型已保存,仅影响翻译');
|
|
2602
2932
|
}
|
|
2603
2933
|
$('cfg-save').onclick = () => saveCfg(false);
|
|
2604
2934
|
$('cfg-save-new').onclick = () => saveCfg(true);
|