@cloud411716/fancy-webnovel 4.27.0 → 4.27.2
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/lib/task-list.js
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
* 不手动清空 —— 用户还能看到刚才做了哪些事,下一次对话开始时
|
|
24
24
|
* DSH 自己会清掉。失败时已完成步骤保持 completed,当前及后续
|
|
25
25
|
* 保持 pending,不谎报完成。
|
|
26
|
+
* 4. **长时间本地任务**:agent 一直 idle 时每 60 秒补写一次列表,
|
|
27
|
+
* 避免 UI 把长时间没有更新的任务栏收起。
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
30
|
import { installCommandRecovery, registerManagedCommand } from './command-recovery.js';
|
|
@@ -227,7 +229,7 @@ class TaskListController {
|
|
|
227
229
|
* 写回命令自己的版本。
|
|
228
230
|
*
|
|
229
231
|
* @param {object} invocation DSH command invocation
|
|
230
|
-
* @param {{onTurnEnd?: Function, stopAfterFirstEnd?: boolean}} [opts]
|
|
232
|
+
* @param {{onTurnEnd?: Function, stopAfterFirstEnd?: boolean, keepAliveMs?: number}} [opts]
|
|
231
233
|
*/
|
|
232
234
|
watchTurns(invocation, opts = {}) {
|
|
233
235
|
const agent = invocation && invocation.agent;
|
|
@@ -235,14 +237,21 @@ class TaskListController {
|
|
|
235
237
|
const onTurnEnd = typeof opts.onTurnEnd === 'function' ? opts.onTurnEnd : null;
|
|
236
238
|
const stopAfterFirstEnd = opts.stopAfterFirstEnd === true;
|
|
237
239
|
const timeoutMs = Number(opts.timeoutMs) > 0 ? Number(opts.timeoutMs) : 0;
|
|
240
|
+
// 长时间本地采集时 agent 一直是 idle,DSH 的 UI 可能把任务栏收起。
|
|
241
|
+
// 每 60 秒补写一次(只在 idle 时),让任务栏在整段采集中保持可见。
|
|
242
|
+
const keepAliveMs = Number(opts.keepAliveMs) > 0 ? Number(opts.keepAliveMs) : 60 * 1000;
|
|
238
243
|
const startedAt = Date.now();
|
|
244
|
+
let lastWriteAt = Date.now();
|
|
239
245
|
|
|
240
246
|
this._stopWatcher();
|
|
241
247
|
let running = agent.status === 'running';
|
|
242
248
|
this._watchState = { running };
|
|
243
249
|
// 启动时如果已经在 running,说明 turn/start 已经发生过,
|
|
244
250
|
// 当前列表可能刚被清空;先补写一次。
|
|
245
|
-
if (running)
|
|
251
|
+
if (running) {
|
|
252
|
+
this._write();
|
|
253
|
+
lastWriteAt = Date.now();
|
|
254
|
+
}
|
|
246
255
|
|
|
247
256
|
this._watcher = setInterval(() => {
|
|
248
257
|
if (this.closed) {
|
|
@@ -260,9 +269,11 @@ class TaskListController {
|
|
|
260
269
|
if (current && !running) {
|
|
261
270
|
// turn/start:DSH 已把列表投影清空,立刻写回
|
|
262
271
|
this._write();
|
|
272
|
+
lastWriteAt = Date.now();
|
|
263
273
|
} else if (!current && running) {
|
|
264
274
|
// turn/end:写回命令自己的列表,再执行调用方的收尾回调
|
|
265
275
|
this._write();
|
|
276
|
+
lastWriteAt = Date.now();
|
|
266
277
|
if (onTurnEnd) {
|
|
267
278
|
try { onTurnEnd(this); } catch (e) {
|
|
268
279
|
console.error('[task-list] onTurnEnd 失败:' + (e && e.message ? e.message : String(e)));
|
|
@@ -273,6 +284,13 @@ class TaskListController {
|
|
|
273
284
|
return;
|
|
274
285
|
}
|
|
275
286
|
}
|
|
287
|
+
// 长时间没有 turn(本地 OCR/采集)时也要定期刷新,否则 UI 可能
|
|
288
|
+
// 把任务栏当作过期内容隐藏。只在 idle 时写,running 期间不抢
|
|
289
|
+
// 模型自己的 todo。
|
|
290
|
+
if (!current && keepAliveMs > 0 && Date.now() - lastWriteAt >= keepAliveMs) {
|
|
291
|
+
this._write();
|
|
292
|
+
lastWriteAt = Date.now();
|
|
293
|
+
}
|
|
276
294
|
running = current;
|
|
277
295
|
}, WATCH_INTERVAL_MS);
|
|
278
296
|
if (this._watcher && typeof this._watcher.unref === 'function') this._watcher.unref();
|
package/package.json
CHANGED
|
@@ -128,6 +128,9 @@ export async function runVisionRecognition({
|
|
|
128
128
|
manifestPath,
|
|
129
129
|
date,
|
|
130
130
|
signal,
|
|
131
|
+
// 视觉识别在任务表里的下标(生产是第 3 步,下标 2)。
|
|
132
|
+
// 不传时退回“改当前步骤”,保持测试与旧调用兼容。
|
|
133
|
+
taskIndex = null,
|
|
131
134
|
// 测试注入点:生产调用不传,默认就是真实的 LLM 派活与等待。
|
|
132
135
|
followup = llmFollowup,
|
|
133
136
|
waitTurn = waitForAnalysisTurn,
|
|
@@ -149,6 +152,20 @@ export async function runVisionRecognition({
|
|
|
149
152
|
const failed = [];
|
|
150
153
|
let recognisableIndex = 0;
|
|
151
154
|
|
|
155
|
+
// 不能直接用 tasks.progress():采集和视觉识别是交错进行的,当前步骤
|
|
156
|
+
// 可能还停在“采集榜单并截图”上。直接改当前步骤会把第二行也改成
|
|
157
|
+
// “LLM 视觉识别截图”,和第三行重复。这里锁定视觉步骤的下标。
|
|
158
|
+
const setProgress = (text) => {
|
|
159
|
+
if (tasks && Number.isInteger(taskIndex) && typeof tasks.progressAt === 'function') {
|
|
160
|
+
tasks.progressAt(taskIndex, text);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (tasks && typeof tasks.progress === 'function') tasks.progress(text);
|
|
164
|
+
};
|
|
165
|
+
if (tasks && Number.isInteger(taskIndex) && typeof tasks.activate === 'function') {
|
|
166
|
+
tasks.activate(taskIndex);
|
|
167
|
+
}
|
|
168
|
+
|
|
152
169
|
for (let manifestIndex = 0; manifestIndex < allCategories.length; manifestIndex += 1) {
|
|
153
170
|
if (signal?.aborted) {
|
|
154
171
|
return { ok: false, aborted: true, error: '操作已取消' };
|
|
@@ -240,7 +257,7 @@ export async function runVisionRecognition({
|
|
|
240
257
|
if (!parsed) {
|
|
241
258
|
results.push({ name: catName, error: lastError || '模型没有返回可解析的识别结果' });
|
|
242
259
|
failed.push({ name: catName, error: lastError || '模型没有返回可解析的识别结果' });
|
|
243
|
-
|
|
260
|
+
setProgress(`LLM 视觉识别截图(${recognisableIndex}/${recognisable.length} 题材)`);
|
|
244
261
|
continue;
|
|
245
262
|
}
|
|
246
263
|
|
|
@@ -258,7 +275,7 @@ export async function runVisionRecognition({
|
|
|
258
275
|
// “部分识别成功”写进 md,否则整篇都是占位书名。
|
|
259
276
|
results.push({ name: catName, error: '识别结果与截图清单无法对应' });
|
|
260
277
|
failed.push({ name: catName, error: '识别结果与截图清单无法对应' });
|
|
261
|
-
|
|
278
|
+
setProgress(`LLM 视觉识别截图(${recognisableIndex}/${recognisable.length} 题材)`);
|
|
262
279
|
continue;
|
|
263
280
|
}
|
|
264
281
|
results.push({ name: catName, books: merged.books });
|
|
@@ -268,7 +285,7 @@ export async function runVisionRecognition({
|
|
|
268
285
|
error: `${merged.missing.length} 本没有识别到:${merged.missing.join('、')}`,
|
|
269
286
|
});
|
|
270
287
|
}
|
|
271
|
-
|
|
288
|
+
setProgress(`LLM 视觉识别截图(${recognisableIndex}/${recognisable.length} 题材)`);
|
|
272
289
|
}
|
|
273
290
|
|
|
274
291
|
// 一个题材都没识别成功时不要写空 md —— 让上层按失败处理,
|
|
@@ -562,7 +579,10 @@ export async function apply(ctx) {
|
|
|
562
579
|
const rankRow = RANK_LISTS[platform]?.find(r => r.id === rankId);
|
|
563
580
|
const rankLabel = rankRow ? rankRow.label : rankId;
|
|
564
581
|
processedRanks += 1;
|
|
565
|
-
tasks.progress(
|
|
582
|
+
// 采集步骤固定是下标 1。不能走 tasks.progress():视觉识别与采集
|
|
583
|
+
// 交错进行,当前步骤可能已经被切到别处。
|
|
584
|
+
tasks.progressAt(
|
|
585
|
+
1,
|
|
566
586
|
`${scanMode === SCAN_MODE_VISION ? '采集榜单并截图' : '采集榜单数据'}` +
|
|
567
587
|
`(${processedRanks}/${rankIds.length}:${rankLabel})`
|
|
568
588
|
);
|
|
@@ -649,7 +669,10 @@ export async function apply(ctx) {
|
|
|
649
669
|
if (signal?.aborted) {
|
|
650
670
|
return notify(session, 'error', scan.notify({ type: 'cancelled' }));
|
|
651
671
|
}
|
|
652
|
-
|
|
672
|
+
// 视觉识别固定是下标 2。先激活它,再单独更新它的文案,
|
|
673
|
+
// 这样第二行“采集榜单并截图”不会被覆盖成同名步骤。
|
|
674
|
+
tasks.activate(2);
|
|
675
|
+
tasks.progressAt(2, `LLM 视觉识别截图(准备中:${rankLabel})`);
|
|
653
676
|
const vr = await runVisionRecognition({
|
|
654
677
|
invocation,
|
|
655
678
|
tasks,
|
|
@@ -657,6 +680,7 @@ export async function apply(ctx) {
|
|
|
657
680
|
manifestPath,
|
|
658
681
|
date: receipt.date || lastDate,
|
|
659
682
|
signal,
|
|
683
|
+
taskIndex: 2,
|
|
660
684
|
});
|
|
661
685
|
if (vr.aborted) {
|
|
662
686
|
return notify(session, 'error', scan.notify({ type: 'cancelled' }));
|
|
@@ -207,10 +207,6 @@ function buildBooksSelfCheckPrompt({ request, resultPath, platform, rank }) {
|
|
|
207
207
|
'',
|
|
208
208
|
'## 第二步:读取截图',
|
|
209
209
|
'',
|
|
210
|
-
`平台:${platform}`,
|
|
211
|
-
`榜单:${rank}`,
|
|
212
|
-
`页面地址:${request.url || ''}`,
|
|
213
|
-
'',
|
|
214
210
|
'请用 read 工具读取以下截图(绝对路径):',
|
|
215
211
|
'',
|
|
216
212
|
...screenshots.map((file, index) => `${index + 1}. \`${file}\``),
|
|
@@ -236,6 +232,8 @@ function buildBooksSelfCheckPrompt({ request, resultPath, platform, rank }) {
|
|
|
236
232
|
}, null, 2),
|
|
237
233
|
'```',
|
|
238
234
|
'',
|
|
235
|
+
'上面只是格式示例,实际值必须按截图如实抄录。',
|
|
236
|
+
'',
|
|
239
237
|
'抄录规则:',
|
|
240
238
|
'- 按截图中显示的中文原文抄录,不要翻译、改写、概括或补全。',
|
|
241
239
|
'- 看不清的字段填空字符串 `""`,不要猜。',
|