@cloud411716/fancy-webnovel 0.1.65 → 0.1.66

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/infra.js CHANGED
@@ -23,8 +23,32 @@ export function notify(session, text) {
23
23
  });
24
24
  }
25
25
 
26
- // ---------------------------------------------------------------------------
27
- // llmFollowup发送消息给 LLM,让 LLM 在同一 session 继续处理
26
+ // --------------------------------------------------------------------------
27
+ // notifyReplaceable同步追加消息,返回 SessionEvent(用于后续原地 replace)
28
+ // --------------------------------------------------------------------------
29
+
30
+ export function notifyReplaceable(session, text) {
31
+ return session.append(
32
+ 'user/message',
33
+ { content: [{ type: 'text', text: String(text) }], source: { kind: 'user' } },
34
+ { surfaceOp: 'append' }
35
+ );
36
+ }
37
+
38
+ // --------------------------------------------------------------------------
39
+ // replaceMessage — 原地替换指定 seq 的消息内容
40
+ // --------------------------------------------------------------------------
41
+
42
+ export function replaceMessage(session, seq, text) {
43
+ session.append(
44
+ 'user/message',
45
+ { content: [{ type: 'text', text: String(text) }], source: { kind: 'user' } },
46
+ { surfaceOp: { op: 'replace', start: seq, end: seq } }
47
+ );
48
+ }
49
+
50
+ // --------------------------------------------------------------------------
51
+ // llmFollowup
28
52
  // ---------------------------------------------------------------------------
29
53
 
30
54
  export function llmFollowup(invocation, content) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -4,7 +4,7 @@
4
4
  import { fileURLToPath } from 'url';
5
5
  import { dirname, join } from 'path';
6
6
  import { existsSync } from 'fs';
7
- import { notify, llmFollowup, spawnScript } from '../../infra.js';
7
+ import { notify, llmFollowup, spawnScript, notifyReplaceable, replaceMessage } from '../../infra.js';
8
8
  import { scan, PLATFORM_TABLE, platformLabel } from './templates.js';
9
9
 
10
10
  export const inject = ['commands', 'userQuestions'];
@@ -92,12 +92,26 @@ export async function apply(ctx) {
92
92
 
93
93
  notify(session, scan.notify({ type: 'collecting', platform, length }));
94
94
 
95
- const scriptResult = await spawnScript(
96
- 'node',
97
- [join(SCAN_SCRIPTS_DIR, 'run-scan.js'),
98
- '--project-root', projectRoot, '--platform', platform, '--length', length],
99
- { timeout: 120000 }
100
- );
95
+ // 原地 spinner:追加一条消息,后续每 400ms原地更新
96
+ const FRAMES = '⠋⠙⠹⠸⠴⠦⠧⠇⠏';
97
+ let frame = 0;
98
+ const spinnerEv = notifyReplaceable(session, `⏳ ${FRAMES[frame]} 采集中...`);
99
+ const spinnerSeq = spinnerEv.seq;
100
+
101
+ const scriptResult = await new Promise(async (resolve) => {
102
+ const ticker = setInterval(() => {
103
+ frame++;
104
+ replaceMessage(session, spinnerSeq, `⏳ ${FRAMES[frame % FRAMES.length]} 采集中...`);
105
+ }, 400);
106
+
107
+ const result = await spawnScript('node',
108
+ [join(SCAN_SCRIPTS_DIR, 'run-scan.js'),
109
+ '--project-root', projectRoot, '--platform', platform, '--length', length],
110
+ { timeout: 120000 }
111
+ );
112
+ clearInterval(ticker);
113
+ resolve(result);
114
+ });
101
115
 
102
116
  if (!scriptResult.ok) {
103
117
  const err = (typeof scriptResult.error === 'object' && scriptResult.error !== null)