papersearch 0.4.12 → 0.5.1
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/.env.example +8 -0
- package/README.en.md +89 -75
- package/README.md +90 -76
- package/assets/overview.en.png +0 -0
- package/assets/overview.png +0 -0
- package/carsi/paper_search_carsi/api_keys.py +138 -0
- package/carsi/paper_search_carsi/assets/api_keys.json +146 -0
- package/carsi/paper_search_carsi/assets/capsule.html +316 -29
- package/carsi/paper_search_carsi/assets/capsule_en.json +437 -0
- package/carsi/paper_search_carsi/cli.py +46 -4
- package/carsi/paper_search_carsi/cli_config.py +51 -0
- package/carsi/paper_search_carsi/config.py +2 -0
- package/carsi/paper_search_carsi/download_directory.py +5 -33
- package/carsi/paper_search_carsi/engine/batch_capture.py +19 -10
- package/carsi/paper_search_carsi/engine/bridge.py +2 -1
- package/carsi/paper_search_carsi/engine/pdf_guard.py +3 -6
- package/carsi/paper_search_carsi/extractors/pdf_extractor.py +4 -18
- package/carsi/paper_search_carsi/i18n.py +46 -0
- package/carsi/paper_search_carsi/orchestrator.py +14 -1
- package/carsi/paper_search_carsi/pdf_text.py +84 -0
- package/carsi/paper_search_carsi/pdf_utils.py +3 -12
- package/carsi/paper_search_carsi/progress_capsule.py +94 -10
- package/carsi/paper_search_carsi/progress_reporter.py +64 -4
- package/carsi/paper_search_carsi/server.py +9 -1
- package/carsi/paper_search_carsi/user_settings.py +17 -4
- package/carsi/pyproject.toml +6 -4
- package/dist/capabilities/citation-expansion/CitationService.d.ts +8 -0
- package/dist/capabilities/citation-expansion/CitationService.d.ts.map +1 -1
- package/dist/capabilities/citation-expansion/CitationService.js +14 -4
- package/dist/capabilities/citation-expansion/CitationService.js.map +1 -1
- package/dist/capabilities/citation-expansion/CrossrefReferences.d.ts +18 -0
- package/dist/capabilities/citation-expansion/CrossrefReferences.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/CrossrefReferences.js +83 -0
- package/dist/capabilities/citation-expansion/CrossrefReferences.js.map +1 -0
- package/dist/capabilities/citation-expansion/OpenAlexGraph.d.ts +36 -0
- package/dist/capabilities/citation-expansion/OpenAlexGraph.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/OpenAlexGraph.js +120 -0
- package/dist/capabilities/citation-expansion/OpenAlexGraph.js.map +1 -0
- package/dist/capabilities/citation-expansion/handler.d.ts +14 -5
- package/dist/capabilities/citation-expansion/handler.d.ts.map +1 -1
- package/dist/capabilities/citation-expansion/handler.js +64 -14
- package/dist/capabilities/citation-expansion/handler.js.map +1 -1
- package/dist/capabilities/citation-expansion/schemas.d.ts +1 -5
- package/dist/capabilities/citation-expansion/schemas.d.ts.map +1 -1
- package/dist/capabilities/citation-expansion/schemas.js +2 -2
- package/dist/capabilities/citation-expansion/schemas.js.map +1 -1
- package/dist/capabilities/citation-expansion/tools.d.ts +0 -18
- package/dist/capabilities/citation-expansion/tools.d.ts.map +1 -1
- package/dist/capabilities/citation-expansion/tools.js +4 -16
- package/dist/capabilities/citation-expansion/tools.js.map +1 -1
- package/dist/capabilities/citation-expansion/types.d.ts +4 -0
- package/dist/capabilities/citation-expansion/types.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts +8 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +36 -24
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts +3 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js +5 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.d.ts +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.js +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts +5 -0
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/outputLayout.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/outputLayout.js +2 -1
- package/dist/capabilities/pdf-discovery/outputLayout.js.map +1 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js +1 -0
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js.map +1 -1
- package/dist/cli.js +86 -11
- package/dist/cli.js.map +1 -1
- package/dist/config/ConfigService.d.ts +1 -1
- package/dist/config/ConfigService.d.ts.map +1 -1
- package/dist/config/ConfigService.js +3 -0
- package/dist/config/ConfigService.js.map +1 -1
- package/dist/config/apiKeySignup.d.ts +11 -1
- package/dist/config/apiKeySignup.d.ts.map +1 -1
- package/dist/config/apiKeySignup.js +18 -6
- package/dist/config/apiKeySignup.js.map +1 -1
- package/dist/config/apiKeyTest.d.ts +18 -0
- package/dist/config/apiKeyTest.d.ts.map +1 -0
- package/dist/config/apiKeyTest.js +109 -0
- package/dist/config/apiKeyTest.js.map +1 -0
- package/dist/config/selfCommand.d.ts +8 -0
- package/dist/config/selfCommand.d.ts.map +1 -0
- package/dist/config/selfCommand.js +10 -0
- package/dist/config/selfCommand.js.map +1 -0
- package/dist/management/capability-profile/index.js +4 -4
- package/dist/management/capability-profile/index.js.map +1 -1
- package/dist/management/carsi/autoUpdate.d.ts +21 -0
- package/dist/management/carsi/autoUpdate.d.ts.map +1 -0
- package/dist/management/carsi/autoUpdate.js +88 -0
- package/dist/management/carsi/autoUpdate.js.map +1 -0
- package/dist/management/carsi/installer.d.ts +1 -1
- package/dist/management/carsi/installer.d.ts.map +1 -1
- package/dist/management/carsi/installer.js +38 -7
- package/dist/management/carsi/installer.js.map +1 -1
- package/dist/management/carsi/runtime.d.ts +9 -0
- package/dist/management/carsi/runtime.d.ts.map +1 -1
- package/dist/management/carsi/runtime.js +11 -0
- package/dist/management/carsi/runtime.js.map +1 -1
- package/dist/management/carsi/settingsWindow.d.ts +30 -0
- package/dist/management/carsi/settingsWindow.d.ts.map +1 -0
- package/dist/management/carsi/settingsWindow.js +51 -0
- package/dist/management/carsi/settingsWindow.js.map +1 -0
- package/dist/management/diagnostics/index.d.ts.map +1 -1
- package/dist/management/diagnostics/index.js +16 -0
- package/dist/management/diagnostics/index.js.map +1 -1
- package/dist/management/skills/nextSteps.d.ts +5 -0
- package/dist/management/skills/nextSteps.d.ts.map +1 -0
- package/dist/management/skills/nextSteps.js +21 -0
- package/dist/management/skills/nextSteps.js.map +1 -0
- package/dist/platforms/ACMSearcher.d.ts.map +1 -1
- package/dist/platforms/ACMSearcher.js +3 -2
- package/dist/platforms/ACMSearcher.js.map +1 -1
- package/dist/platforms/CrossrefSearcher.d.ts.map +1 -1
- package/dist/platforms/CrossrefSearcher.js +4 -3
- package/dist/platforms/CrossrefSearcher.js.map +1 -1
- package/dist/platforms/OpenAlexSearcher.d.ts.map +1 -1
- package/dist/platforms/OpenAlexSearcher.js +4 -1
- package/dist/platforms/OpenAlexSearcher.js.map +1 -1
- package/dist/registry/platformMetadata.d.ts.map +1 -1
- package/dist/registry/platformMetadata.js +1 -0
- package/dist/registry/platformMetadata.js.map +1 -1
- package/dist/utils/plainText.d.ts +7 -0
- package/dist/utils/plainText.d.ts.map +1 -0
- package/dist/utils/plainText.js +19 -0
- package/dist/utils/plainText.js.map +1 -0
- package/package.json +3 -1
- package/skills/paper-search/SKILL.md +18 -5
- package/skills/paper-search/references/capability-routing.md +5 -3
- package/skills/paper-search/references/carsi-setup.md +6 -3
- package/skills/paper-search/references/cli-contract.md +9 -4
- package/skills/paper-search/references/management-layer.md +4 -4
- package/skills/paper-search/references/troubleshooting.md +1 -1
|
@@ -130,6 +130,41 @@ svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-widt
|
|
|
130
130
|
.switch.on { background: var(--accent); }
|
|
131
131
|
.switch.on::after { left: 16px; }
|
|
132
132
|
.foot { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 0.5px solid var(--line); }
|
|
133
|
+
/* Settings: a home list of three pages, each row with its current values; then the page itself. */
|
|
134
|
+
.nav-row, .key-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 0; border: none; border-top: 0.5px solid var(--line);
|
|
135
|
+
background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
|
|
136
|
+
.nav-row:first-child { margin-top: 8px; }
|
|
137
|
+
.nav-row:hover .nav-title, .key-row:hover .nav-title { color: var(--accent); }
|
|
138
|
+
.nav-row:focus-visible, .key-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px; }
|
|
139
|
+
.nav-row svg.i:last-child { color: var(--faint); }
|
|
140
|
+
.nav-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
141
|
+
.nav-sub { font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
142
|
+
.settings-note { font-size: 11px; color: var(--ok); margin-top: 8px; }
|
|
143
|
+
.key-group { font-size: 11px; color: var(--faint); margin: 12px 0 2px; }
|
|
144
|
+
.key-row.editing { cursor: default; }
|
|
145
|
+
.key-row.editing:hover .nav-title { color: inherit; }
|
|
146
|
+
.key-set { font-size: 12px; color: var(--ok); white-space: nowrap; }
|
|
147
|
+
.key-row .btn { pointer-events: none; }
|
|
148
|
+
.key-edit { background: var(--hover); border-radius: 8px; padding: 8px 10px; margin: 0 0 6px; }
|
|
149
|
+
.settings .key-edit input { width: 100%; text-align: left; background: var(--bg); }
|
|
150
|
+
.key-edit .err { text-align: left; margin: 6px 0 0; }
|
|
151
|
+
.key-edit .err:empty { display: none; }
|
|
152
|
+
.key-edit .err.ok { color: var(--ok); }
|
|
153
|
+
.key-edit .err.wait { color: var(--dim); }
|
|
154
|
+
.key-links, .key-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
|
|
155
|
+
.key-actions { gap: 6px; }
|
|
156
|
+
.key-links .grow, .key-actions .grow { flex: 1; }
|
|
157
|
+
.key-links .iconbtn { margin: 0; }
|
|
158
|
+
.iconbtn[aria-pressed="true"] { color: var(--accent); }
|
|
159
|
+
.strip { display: flex; align-items: center; gap: 6px; width: 100%; box-sizing: border-box; margin: 10px 0 2px; padding: 6px 10px;
|
|
160
|
+
border-radius: 8px; border: 0.5px solid var(--line); background: var(--hover); color: var(--dim); font: inherit; font-size: 12px;
|
|
161
|
+
text-align: left; cursor: pointer; }
|
|
162
|
+
.strip .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
163
|
+
.strip svg.i { width: 14px; height: 14px; }
|
|
164
|
+
.strip.warn-strip { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
|
|
165
|
+
.seg { display: inline-flex; border: 0.5px solid var(--line); border-radius: 7px; overflow: hidden; }
|
|
166
|
+
.seg button { font: inherit; font-size: 12px; padding: 3px 10px; border: none; background: none; color: var(--dim); cursor: pointer; }
|
|
167
|
+
.seg button.on { background: var(--accent); color: #fff; }
|
|
133
168
|
.prompt { display: flex; align-items: center; gap: 10px; }
|
|
134
169
|
.prompt svg.i { width: 22px; height: 22px; }
|
|
135
170
|
.prompt .t { font-weight: 600; font-size: 14px; }
|
|
@@ -178,6 +213,39 @@ svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-widt
|
|
|
178
213
|
<div id="root" class="pill capsule-drag-region"></div>
|
|
179
214
|
<script>
|
|
180
215
|
"use strict";
|
|
216
|
+
// English: the window's progress_language. The table (assets/capsule_en.json) is put
|
|
217
|
+
// in here when the window loads the page; every text shown passes through tr().
|
|
218
|
+
const EN = /*CAPSULE_EN*/null;
|
|
219
|
+
const EN_PATTERNS = EN ? EN.patterns.map(([source, target]) => [new RegExp(source), target]) : [];
|
|
220
|
+
const HAN = /[\u4e00-\u9fff]/;
|
|
221
|
+
let lang = "zh";
|
|
222
|
+
function tr(text) {
|
|
223
|
+
if (lang !== "en" || !EN || !text || !HAN.test(text)) return text;
|
|
224
|
+
return String(text).split(" · ").map((part) => {
|
|
225
|
+
const core = part.trim();
|
|
226
|
+
if (!core || !HAN.test(core)) return part;
|
|
227
|
+
let english = Object.hasOwn(EN.exact, core) ? EN.exact[core] : null;
|
|
228
|
+
if (english === null) {
|
|
229
|
+
const found = EN_PATTERNS.find(([pattern]) => pattern.test(core));
|
|
230
|
+
if (found) english = core.replace(found[0], found[1]);
|
|
231
|
+
}
|
|
232
|
+
return english === null ? part : part.replace(core, english);
|
|
233
|
+
}).join(" · ");
|
|
234
|
+
}
|
|
235
|
+
function localize(node) {
|
|
236
|
+
if (lang !== "en" || !EN) return;
|
|
237
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT);
|
|
238
|
+
for (let text = walker.nextNode(); text; text = walker.nextNode()) {
|
|
239
|
+
const english = tr(text.nodeValue);
|
|
240
|
+
if (english !== text.nodeValue) text.nodeValue = english;
|
|
241
|
+
}
|
|
242
|
+
node.querySelectorAll("[aria-label], [title], [placeholder]").forEach((element) => {
|
|
243
|
+
for (const name of ["aria-label", "title", "placeholder"]) {
|
|
244
|
+
const value = element.getAttribute(name);
|
|
245
|
+
if (value && tr(value) !== value) element.setAttribute(name, tr(value));
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
181
249
|
const ICONS = {
|
|
182
250
|
lock: '<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>',
|
|
183
251
|
shield: '<path d="M12 3l8 3.5v5.5c0 4.6-3.4 8.1-8 9-4.6-.9-8-4.4-8-9V6.5z"/><path d="M9 12l2 2 4-4"/>',
|
|
@@ -193,6 +261,10 @@ const ICONS = {
|
|
|
193
261
|
right: '<path d="M9 6l6 6-6 6"/>',
|
|
194
262
|
down: '<path d="M6 9l6 6 6-6"/>',
|
|
195
263
|
gear: gearPath(),
|
|
264
|
+
clock: '<circle cx="12" cy="12" r="8.5"/><path d="M12 7.5V12l3 2"/>',
|
|
265
|
+
key: '<circle cx="8" cy="15" r="4"/><path d="M10.8 12.2L19 4M16 7l2.5 2.5M14 9l2 2"/>',
|
|
266
|
+
eye: '<path d="M2.5 12s3.5-6.5 9.5-6.5S21.5 12 21.5 12s-3.5 6.5-9.5 6.5S2.5 12 2.5 12z"/><circle cx="12" cy="12" r="2.8"/>',
|
|
267
|
+
external: '<path d="M14 5h5v5M19 5l-8 8"/><path d="M18 14v4a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 4 18V7a1.5 1.5 0 0 1 1.5-1.5H10"/>',
|
|
196
268
|
};
|
|
197
269
|
function gearPath() {
|
|
198
270
|
// An eight-tooth gear, drawn here so no icon font or third-party artwork is needed.
|
|
@@ -221,6 +293,12 @@ let open = false; // the card is showing
|
|
|
221
293
|
let panel = ""; // "", "menu", "report", "confirm", "settings": kept until the user leaves it
|
|
222
294
|
let flash = { text: "", until: 0 };
|
|
223
295
|
let settings = null, settingsErrors = {}, notifyOn = true;
|
|
296
|
+
// Settings pages: "home" lists download, wait and keys. settingsOnly: this window was started
|
|
297
|
+
// just to show them (`paper-search-carsi settings`), so it closes with them unless a download runs.
|
|
298
|
+
const SETTINGS_PAGES = ["home", "download", "wait", "keys"];
|
|
299
|
+
let settingsPage = "home", settingsNote = "", settingsOnly = false, lastStrip = "";
|
|
300
|
+
// Not "keys": in the pywebview window that name is taken, and declaring it stops the whole page.
|
|
301
|
+
let apiKeys = null, editing = "", editValues = {}, confirmClear = "", revealed = false;
|
|
224
302
|
let lastHtml = "", hoverTimer = 0, leaveTimer = 0, pollTimer = 0, kinds = [];
|
|
225
303
|
const api = () => window.pywebview.api;
|
|
226
304
|
|
|
@@ -391,28 +469,178 @@ function idleCard() {
|
|
|
391
469
|
return '<div class="card-body">' + header("PaperSearch", "暂无下载任务", true) + "</div>";
|
|
392
470
|
}
|
|
393
471
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
472
|
+
const busy = () => V.mode === "running" || V.mode === "attention";
|
|
473
|
+
|
|
474
|
+
function taskStrip() {
|
|
475
|
+
// A download running behind the settings: one line, amber when it needs the user.
|
|
476
|
+
if (V.mode === "attention") {
|
|
477
|
+
return '<button type="button" class="strip warn-strip" data-act="show_browser">' + icon(V.attention.login ? "lock" : "alert")
|
|
478
|
+
+ '<span class="grow">' + esc(V.attention.short) + "</span><span>去处理 ›</span></button>";
|
|
479
|
+
}
|
|
480
|
+
if (V.mode === "running") {
|
|
481
|
+
return '<button type="button" class="strip" data-act="progress"><span class="grow">正在下载 '
|
|
482
|
+
+ esc(V.total ? V.done + "/" + V.total : V.done) + (V.publisher ? " · " + esc(V.publisher) : "")
|
|
483
|
+
+ "</span><span>返回进度 ›</span></button>";
|
|
484
|
+
}
|
|
485
|
+
return "";
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function settingsHead(title) {
|
|
489
|
+
// A window opened just for the settings closes from any page; the home page has nothing to go back to.
|
|
490
|
+
const closable = settingsOnly && !busy(), home = settingsPage === "home";
|
|
491
|
+
lastStrip = taskStrip();
|
|
492
|
+
return '<div class="head">' + (home && closable ? "" : '<button class="iconbtn" data-act="back" aria-label="返回">' + icon("left") + "</button>")
|
|
493
|
+
+ '<div class="drag capsule-drag-region"><div class="text"><div class="title">' + esc(title) + "</div>"
|
|
494
|
+
+ (home ? "" : '<div class="sub">设置</div>') + "</div></div>"
|
|
495
|
+
+ (closable ? '<button class="iconbtn" data-act="close_settings" aria-label="关闭">' + icon("close") + "</button>" : "")
|
|
496
|
+
+ '</div><div id="task-strip">' + lastStrip + "</div>";
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const fieldsOn = (page) => settings.fields.filter((f) => (f.page || "wait") === page);
|
|
500
|
+
const field = (name) => settings.fields.find((f) => f.name === name);
|
|
501
|
+
|
|
502
|
+
function settingsHome() {
|
|
503
|
+
const hourly = field("hourly"), login = field("login");
|
|
504
|
+
const rows = [
|
|
505
|
+
["download", "folder", "下载", [settings.download_dir, hourly ? "每家每小时 " + hourly.value + " 篇" : ""]],
|
|
506
|
+
["wait", "clock", "等待和提醒", [login ? "登录页 " + login.value + " 秒" : "", "系统通知" + (notifyOn ? "开" : "关")]],
|
|
507
|
+
["keys", "key", "API key", [apiKeys && apiKeys.ok ? "已填 " + apiKeys.filled + "/" + apiKeys.total : ""]],
|
|
508
|
+
];
|
|
509
|
+
return settingsHead("设置") + rows.map(([page, glyph, title, sub]) =>
|
|
510
|
+
'<button type="button" class="nav-row" data-act="settings_page" data-page="' + page + '">' + icon(glyph)
|
|
511
|
+
+ '<span class="nav-text"><span class="nav-title">' + title + '</span><span class="nav-sub">'
|
|
512
|
+
+ esc(sub.filter(Boolean).join(" · ")) + "</span></span>" + icon("right") + "</button>").join("")
|
|
513
|
+
// The language row reads the same in both languages.
|
|
514
|
+
+ '<div class="row"><span>语言</span><span class="seg">' + ["zh", "en"].map((code) => '<button type="button" data-act="language" data-lang="'
|
|
515
|
+
+ code + '" aria-pressed="' + (lang === code) + '"' + (lang === code ? ' class="on"' : "") + ">" + (code === "zh" ? "中文" : "English")
|
|
516
|
+
+ "</button>").join("") + "</span></div>"
|
|
517
|
+
+ (settingsNote ? '<div class="settings-note" role="status">' + esc(settingsNote) + "</div>" : "");
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function fieldRows(page) {
|
|
521
|
+
return fieldsOn(page).map((f) => '<div class="row"><span>' + esc(f.label) + '</span><span><input data-field="' + esc(f.name)
|
|
522
|
+
+ '" value="' + esc(f.value) + '" aria-label="' + esc(f.label) + '" inputmode="numeric"> <span class="dim">' + esc(f.unit) + "</span></span></div>"
|
|
523
|
+
+ (settingsErrors[f.name] ? '<div class="err">' + esc(settingsErrors[f.name]) + "</div>" : "")).join("");
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function settingsFoot() {
|
|
527
|
+
return (settingsErrors[""] ? '<div class="err">' + esc(settingsErrors[""]) + "</div>" : "")
|
|
528
|
+
+ '<div class="foot"><button class="btn link" style="color:var(--dim)" data-act="defaults">恢复默认</button>'
|
|
529
|
+
+ '<button class="btn primary" data-act="save">保存</button></div>';
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function settingsDownload() {
|
|
533
|
+
return settingsHead("下载")
|
|
397
534
|
+ '<div class="folder-setting"><label for="download-dir">默认下载文件夹</label><div class="folder-row">'
|
|
398
535
|
+ '<input id="download-dir" type="text" value="' + esc(settings.download_dir || '') + '" placeholder="输入完整路径">'
|
|
399
536
|
+ '<button class="btn" data-act="choose_folder">选择…</button></div>'
|
|
400
537
|
+ '<div class="hint">用于后续下载;命令中指定路径时优先使用指定路径。</div>'
|
|
401
|
-
+ (settingsErrors.download_dir ? '<div class="err">' + esc(settingsErrors.download_dir) + '</div>' : '') + '</div>'
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
538
|
+
+ (settingsErrors.download_dir ? '<div class="err">' + esc(settingsErrors.download_dir) + '</div>' : '') + '</div>'
|
|
539
|
+
+ fieldRows("download") + settingsFoot();
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function settingsWait() {
|
|
543
|
+
return settingsHead("等待和提醒") + fieldRows("wait")
|
|
544
|
+
+ '<div class="row"><span>需要处理时发系统通知</span><button class="switch' + (notifyOn ? " on" : "")
|
|
408
545
|
+ '" data-act="notify" role="switch" aria-checked="' + notifyOn + '" aria-label="系统通知"></button></div>'
|
|
409
|
-
+ '<div class="err" id="notify-error" role="status"></div>'
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
546
|
+
+ '<div class="err" id="notify-error" role="status"></div>' + settingsFoot();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function keyRow(s) {
|
|
550
|
+
const name = '<span class="nav-text"><span class="nav-title">' + esc(s.name) + "</span>"
|
|
551
|
+
+ (s.use ? '<span class="nav-sub">' + esc(s.use) + "</span>" : "") + "</span>";
|
|
552
|
+
if (editing !== s.id) {
|
|
553
|
+
return '<button type="button" class="key-row" data-act="edit_key" data-service="' + esc(s.id) + '">' + name
|
|
554
|
+
+ (s.set ? '<span class="key-set">' + esc(s.masked) + "</span>" : '<span class="btn">填写</span>') + "</button>";
|
|
555
|
+
}
|
|
556
|
+
let html = '<div class="key-row editing">' + name
|
|
557
|
+
+ (s.set ? '<span class="key-set">' + esc(s.masked) + "</span>" : '<span class="dim" style="font-size:12px">未填</span>')
|
|
558
|
+
+ '</div><div class="key-edit">';
|
|
559
|
+
// A saved key is in its field, hidden until the eye shows it.
|
|
560
|
+
for (const k of s.keys) {
|
|
561
|
+
html += '<input id="key-' + esc(k.key) + '" data-key="' + esc(k.key) + '" type="' + (revealed ? "text" : "password")
|
|
562
|
+
+ '" value="' + esc(editValues[k.key] || "") + '" autocomplete="off" spellcheck="false" aria-label="' + esc(s.name + " " + k.label)
|
|
563
|
+
+ '" placeholder="粘贴 key">';
|
|
564
|
+
}
|
|
565
|
+
return html + '<div class="key-links">'
|
|
566
|
+
+ '<button class="btn link" data-act="signup" data-service="' + esc(s.id) + '">去申请' + icon("external") + "</button>"
|
|
567
|
+
+ (s.guide ? '<button class="btn link" data-act="guide" data-service="' + esc(s.id) + '">' + esc(s.guide_label || "教程") + icon("external") + "</button>" : "")
|
|
568
|
+
+ '<span class="grow"></span>'
|
|
569
|
+
+ '<button class="iconbtn" data-act="reveal" aria-label="显示 key" aria-pressed="' + revealed + '">' + icon("eye") + "</button></div>"
|
|
570
|
+
+ '<div class="err" id="key-error" role="status"></div><div class="key-actions">'
|
|
571
|
+
+ '<button class="btn" data-act="test_key" data-service="' + esc(s.id) + '">测试</button><span class="grow"></span>'
|
|
572
|
+
+ (s.set ? '<button class="btn danger" data-act="clear_key" data-service="' + esc(s.id) + '">清除</button>' : "")
|
|
573
|
+
+ '<button class="btn" data-act="cancel_key">取消</button>'
|
|
574
|
+
+ '<button class="btn primary" data-act="save_key" data-service="' + esc(s.id) + '">保存</button></div></div>';
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function settingsKeys() {
|
|
578
|
+
let html = settingsHead("API key");
|
|
579
|
+
if (!apiKeys || !apiKeys.ok) return html + '<div class="err" style="text-align:left">' + esc((apiKeys && apiKeys.error) || "读取配置失败") + "</div>";
|
|
580
|
+
for (const group of apiKeys.groups) {
|
|
581
|
+
html += '<div class="key-group">' + esc(group.title) + "</div>" + group.services.map(keyRow).join("");
|
|
582
|
+
}
|
|
413
583
|
return html;
|
|
414
584
|
}
|
|
415
585
|
|
|
586
|
+
function settingsCard() {
|
|
587
|
+
const page = { download: settingsDownload, wait: settingsWait, keys: settingsKeys }[settingsPage] || settingsHome;
|
|
588
|
+
return '<div class="card-body settings">' + page() + "</div>";
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function updateStrip() {
|
|
592
|
+
// Progress behind the settings: refresh only this line, keeping what the user is typing.
|
|
593
|
+
const strip = root.querySelector("#task-strip");
|
|
594
|
+
const html = taskStrip();
|
|
595
|
+
if (!strip || html === lastStrip) return;
|
|
596
|
+
lastStrip = html;
|
|
597
|
+
const previous = root.getBoundingClientRect();
|
|
598
|
+
strip.innerHTML = html;
|
|
599
|
+
localize(strip);
|
|
600
|
+
// Measure the natural size as render does: a running resize animation keeps
|
|
601
|
+
// the surface absolutely positioned, which would measure as empty.
|
|
602
|
+
root.classList.remove("animating");
|
|
603
|
+
root.style.width = ""; root.style.height = "";
|
|
604
|
+
root.style.removeProperty("--content-max-height");
|
|
605
|
+
fit(previous);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
async function loadSettings() {
|
|
609
|
+
settings = await api().settings(); notifyOn = settings.notify; settingsErrors = {};
|
|
610
|
+
try { apiKeys = await api().api_keys(); } catch (error) { apiKeys = null; }
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
async function openSettings(request) {
|
|
614
|
+
await loadSettings();
|
|
615
|
+
panel = "settings"; open = true; settingsNote = ""; confirmClear = ""; revealed = false;
|
|
616
|
+
settingsPage = SETTINGS_PAGES.includes(request.page) ? request.page : "home";
|
|
617
|
+
editing = settingsPage === "keys" ? request.service || "" : "";
|
|
618
|
+
editValues = editing ? await savedValues(editing) : {};
|
|
619
|
+
if (request.new_window && !busy()) settingsOnly = true;
|
|
620
|
+
render(true);
|
|
621
|
+
const input = editing && root.querySelector(".key-edit input");
|
|
622
|
+
if (input) input.focus();
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
async function savedValues(service) {
|
|
626
|
+
try {
|
|
627
|
+
const result = await api().api_key_values(service);
|
|
628
|
+
return result && result.ok ? result.values : {};
|
|
629
|
+
} catch (error) { return {}; }
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function leaveSettings() {
|
|
633
|
+
panel = ""; editing = ""; editValues = {}; settingsNote = "";
|
|
634
|
+
if (settingsOnly && !busy()) return act("close");
|
|
635
|
+
return render(true);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function keyError(text, tone) {
|
|
639
|
+
// tone: "" (a problem, red), "ok" (green) or "wait" (grey).
|
|
640
|
+
const line = root.querySelector("#key-error");
|
|
641
|
+
if (line) { line.textContent = tr(text); line.className = "err" + (tone ? " " + tone : ""); }
|
|
642
|
+
}
|
|
643
|
+
|
|
416
644
|
let lastCls = "", hovering = false, closing = false, dragging = false, endingDrag = false;
|
|
417
645
|
let dragReady = Promise.resolve();
|
|
418
646
|
let attentionPointer = null;
|
|
@@ -421,8 +649,8 @@ let renderedAttention = null;
|
|
|
421
649
|
function updateAttentionCountdown() {
|
|
422
650
|
const a = V.attention;
|
|
423
651
|
const card = root.querySelector(".prompt.attention-target");
|
|
424
|
-
if (card) card.title = [a.message, a.remaining ? "剩 " + a.remaining : "",
|
|
425
|
-
|
|
652
|
+
if (card) card.title = tr([a.message, a.remaining ? "剩 " + a.remaining : "",
|
|
653
|
+
a.more ? "另有 " + a.more + " 项" : ""].filter(Boolean).join(" · "));
|
|
426
654
|
const countdown = root.querySelector(".attention-countdown");
|
|
427
655
|
if (!countdown || countdown.textContent === (a.remaining || "")) return false;
|
|
428
656
|
countdown.textContent = a.remaining || "";
|
|
@@ -431,7 +659,7 @@ function updateAttentionCountdown() {
|
|
|
431
659
|
|
|
432
660
|
function render(force) {
|
|
433
661
|
if (closing || dragging) return;
|
|
434
|
-
if (panel === "settings" && !force) return; // keep what the user is typing
|
|
662
|
+
if (panel === "settings" && !force) return updateStrip(); // keep what the user is typing
|
|
435
663
|
let html, shape = "card";
|
|
436
664
|
if (panel === "settings") html = settingsCard();
|
|
437
665
|
else if (!open) { html = pill(); shape = "pill"; }
|
|
@@ -452,6 +680,7 @@ function render(force) {
|
|
|
452
680
|
if (!unchanged) {
|
|
453
681
|
root.className = cls + " capsule-drag-region" + (cls !== lastCls ? " fade" : "");
|
|
454
682
|
root.innerHTML = '<div class="surface">' + html + "</div>";
|
|
683
|
+
localize(root);
|
|
455
684
|
if (attention) updateAttentionCountdown();
|
|
456
685
|
renderedAttention = attention ? V : null;
|
|
457
686
|
}
|
|
@@ -526,11 +755,15 @@ async function animateFit(generation, expanded, from, to, pad) {
|
|
|
526
755
|
async function tick() {
|
|
527
756
|
if (closing) return;
|
|
528
757
|
const before = V.mode;
|
|
529
|
-
try { V = await api().state(hovering || dragging); } catch (e) { return; }
|
|
758
|
+
try { V = await api().state(hovering || dragging || panel === "settings"); } catch (e) { return; }
|
|
759
|
+
if (busy()) settingsOnly = false; // a download started: this is its progress window now
|
|
760
|
+
const switched = Boolean(V.lang) && V.lang !== lang;
|
|
761
|
+
if (switched) lang = V.lang;
|
|
762
|
+
if (V.open_settings) return openSettings(V.open_settings);
|
|
530
763
|
// A prompt only turns the capsule amber (with a system notification); hovering opens it.
|
|
531
764
|
// Once the prompt is handled an open card folds back unless the pointer is on it.
|
|
532
765
|
if (before === "attention" && V.mode !== "attention" && !hovering && !dragging && !panel) open = false;
|
|
533
|
-
render(
|
|
766
|
+
render(switched);
|
|
534
767
|
// Also detect a real pointer departure when clamping moved the window away
|
|
535
768
|
// from a stationary cursor (there may be no further native boundary event).
|
|
536
769
|
if (document.body.classList.contains("mac")) observeHover();
|
|
@@ -560,9 +793,54 @@ async function act(action, target) {
|
|
|
560
793
|
case "stop": panel = ""; return say(await api().act("stop_batch", v.current, v.run_id));
|
|
561
794
|
case "skip_item": case "skip_journal": case "skip_publisher":
|
|
562
795
|
panel = ""; return say(await api().act(action, v.current, v.run_id));
|
|
563
|
-
case "settings":
|
|
564
|
-
|
|
565
|
-
|
|
796
|
+
case "settings": return openSettings({ page: "home" });
|
|
797
|
+
case "language": {
|
|
798
|
+
const result = await api().set_language(target.dataset.lang);
|
|
799
|
+
if (result.ok) lang = result.language;
|
|
800
|
+
return render(true);
|
|
801
|
+
}
|
|
802
|
+
case "settings_page":
|
|
803
|
+
settingsPage = target.dataset.page; settingsErrors = {}; settingsNote = ""; editing = ""; editValues = {}; return render(true);
|
|
804
|
+
case "back":
|
|
805
|
+
if (panel !== "settings") { panel = ""; return render(true); }
|
|
806
|
+
if (settingsPage === "home") return leaveSettings();
|
|
807
|
+
settingsPage = "home"; editing = ""; editValues = {}; settingsErrors = {}; return render(true);
|
|
808
|
+
case "progress": case "close_settings": return leaveSettings();
|
|
809
|
+
case "edit_key":
|
|
810
|
+
editValues = await savedValues(target.dataset.service);
|
|
811
|
+
editing = target.dataset.service; confirmClear = ""; revealed = false; render(true);
|
|
812
|
+
return root.querySelector(".key-edit input")?.focus();
|
|
813
|
+
case "cancel_key": editing = ""; editValues = {}; confirmClear = ""; return render(true);
|
|
814
|
+
case "reveal":
|
|
815
|
+
revealed = !revealed;
|
|
816
|
+
target.setAttribute("aria-pressed", String(revealed));
|
|
817
|
+
root.querySelectorAll(".key-edit input").forEach((input) => { input.type = revealed ? "text" : "password"; });
|
|
818
|
+
return;
|
|
819
|
+
case "signup": case "guide": {
|
|
820
|
+
const result = await api().open_signup(target.dataset.service, action === "guide");
|
|
821
|
+
return result.ok ? undefined : keyError(result.message);
|
|
822
|
+
}
|
|
823
|
+
case "test_key": {
|
|
824
|
+
const values = {};
|
|
825
|
+
root.querySelectorAll(".key-edit input[data-key]").forEach((input) => { values[input.dataset.key] = input.value; });
|
|
826
|
+
target.disabled = true; keyError("正在测试…", "wait");
|
|
827
|
+
try {
|
|
828
|
+
const result = await api().test_api_key(target.dataset.service, values);
|
|
829
|
+
keyError(result.message, result.status === "valid" ? "ok" : result.status === "invalid" ? "" : "wait");
|
|
830
|
+
} finally { target.disabled = false; }
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
case "save_key": case "clear_key": {
|
|
834
|
+
const service = target.dataset.service;
|
|
835
|
+
if (action === "clear_key" && confirmClear !== service) {
|
|
836
|
+
confirmClear = service; target.textContent = "确认清除"; return;
|
|
837
|
+
}
|
|
838
|
+
const values = {};
|
|
839
|
+
root.querySelectorAll(".key-edit input[data-key]").forEach((input) => { values[input.dataset.key] = input.value; });
|
|
840
|
+
const result = action === "save_key" ? await api().save_api_key(service, values) : await api().clear_api_key(service);
|
|
841
|
+
if (!result.ok) return keyError(result.error);
|
|
842
|
+
apiKeys = result; editing = ""; editValues = {}; confirmClear = ""; return render(true);
|
|
843
|
+
}
|
|
566
844
|
case "notify": {
|
|
567
845
|
target.disabled = true;
|
|
568
846
|
try {
|
|
@@ -584,19 +862,22 @@ async function act(action, target) {
|
|
|
584
862
|
return;
|
|
585
863
|
}
|
|
586
864
|
case "defaults":
|
|
587
|
-
for (const f of
|
|
865
|
+
for (const f of fieldsOn(settingsPage)) { const input = root.querySelector('input[data-field="' + f.name + '"]'); if (input) input.value = f.default; }
|
|
588
866
|
return;
|
|
589
867
|
case "save": {
|
|
868
|
+
// Only this page's fields; the notification switch has saved itself.
|
|
590
869
|
const values = {};
|
|
591
870
|
root.querySelectorAll("input[data-field]").forEach((input) => { values[input.dataset.field] = input.value; });
|
|
592
|
-
|
|
593
|
-
const result = await api().save_settings(values,
|
|
871
|
+
const folder = root.querySelector('#download-dir');
|
|
872
|
+
const result = await api().save_settings(values, folder ? folder.value : null);
|
|
594
873
|
if (!result.ok) {
|
|
595
874
|
settingsErrors = result.errors || {};
|
|
596
|
-
settings.fields.forEach((f) => { f.value = values[f.name]; });
|
|
875
|
+
settings.fields.forEach((f) => { if (f.name in values) f.value = values[f.name]; });
|
|
876
|
+
if (folder) settings.download_dir = folder.value;
|
|
597
877
|
return render(true);
|
|
598
878
|
}
|
|
599
|
-
|
|
879
|
+
await loadSettings();
|
|
880
|
+
settingsPage = "home"; settingsNote = "已保存,之后的下载按新设置"; return render(true);
|
|
600
881
|
}
|
|
601
882
|
}
|
|
602
883
|
}
|
|
@@ -714,8 +995,14 @@ window.addEventListener("pointerup", endAttentionPress);
|
|
|
714
995
|
window.addEventListener("pointercancel", endAttentionPress);
|
|
715
996
|
window.addEventListener("blur", endAttentionPress);
|
|
716
997
|
document.addEventListener("keydown", (event) => {
|
|
717
|
-
if (event.key === "Escape" && panel) {
|
|
718
|
-
|
|
998
|
+
if (event.key === "Escape" && panel) {
|
|
999
|
+
if (panel !== "settings") { panel = ""; render(true); }
|
|
1000
|
+
else act(editing ? "cancel_key" : "back");
|
|
1001
|
+
}
|
|
1002
|
+
if (event.key === "Enter" && panel === "settings" && event.target.tagName === "INPUT") {
|
|
1003
|
+
if (settingsPage === "keys" && editing) act("save_key", { dataset: { service: editing }, textContent: "" });
|
|
1004
|
+
else if (settingsPage === "download" || settingsPage === "wait") act("save");
|
|
1005
|
+
}
|
|
719
1006
|
});
|
|
720
1007
|
|
|
721
1008
|
window.addEventListener("pywebviewready", async () => {
|