@cloud411716/fancy-webnovel 0.1.59 → 0.1.61
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 +5 -1
- package/package.json +1 -1
- package/plugins/fancy-scan/index.js +27 -14
package/infra.js
CHANGED
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
|
|
16
16
|
export function notify(session, text) {
|
|
17
|
+
const isHtml = String(text).startsWith('<');
|
|
17
18
|
queueMicrotask(() => {
|
|
18
19
|
session.append(
|
|
19
20
|
'user/message',
|
|
20
|
-
{
|
|
21
|
+
{
|
|
22
|
+
content: [{ type: isHtml ? 'html' : 'text', text: String(text) }],
|
|
23
|
+
source: { kind: 'user' }
|
|
24
|
+
},
|
|
21
25
|
{ surfaceOp: 'append' }
|
|
22
26
|
);
|
|
23
27
|
});
|
package/package.json
CHANGED
|
@@ -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
|
|
7
|
+
import { notify, llmFollowup } from '../../infra.js';
|
|
8
8
|
import { scan, PLATFORM_TABLE, platformLabel } from './templates.js';
|
|
9
9
|
|
|
10
10
|
export const inject = ['commands', 'userQuestions'];
|
|
@@ -92,24 +92,37 @@ export async function apply(ctx) {
|
|
|
92
92
|
|
|
93
93
|
notify(session, scan.notify({ type: 'collecting', platform, length }));
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
// 实时 spinner:每 400ms 追加一帧
|
|
96
|
+
const { spawn } = await import('child_process');
|
|
97
|
+
const FRAMES = '⠋⠙⠹⠸⠴⠦⠧⠇⠏';
|
|
98
|
+
let frame = 0;
|
|
99
|
+
const ticker = setInterval(() => {
|
|
100
|
+
const f = FRAMES[frame % FRAMES.length];
|
|
101
|
+
notify(session, `<span class="spin">${f}</span> 采集中...`);
|
|
102
|
+
frame++;
|
|
103
|
+
}, 80);
|
|
104
|
+
|
|
105
|
+
const proc = spawn('node', [join(SCAN_SCRIPTS_DIR, 'run-scan.js'),
|
|
106
|
+
'--project-root', projectRoot, '--platform', platform, '--length', length], {
|
|
107
|
+
timeout: 120000,
|
|
108
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const [code, out] = await new Promise(resolve => {
|
|
112
|
+
const chunks = [];
|
|
113
|
+
proc.stdout.on('data', d => chunks.push(d.toString()));
|
|
114
|
+
proc.on('close', (c) => resolve([c, chunks.join('')]));
|
|
115
|
+
});
|
|
116
|
+
clearInterval(ticker);
|
|
117
|
+
|
|
118
|
+
if (code !== 0) {
|
|
119
|
+
const err = out.slice(-300) || `exit ${code}`;
|
|
106
120
|
notify(session, scan.notify({ type: 'failed', err }));
|
|
107
121
|
return { kind: 'success', text: '' };
|
|
108
122
|
}
|
|
109
123
|
|
|
110
|
-
// 解析 receipt
|
|
111
124
|
let receipt;
|
|
112
|
-
try { receipt = JSON.parse(
|
|
125
|
+
try { receipt = JSON.parse(out); } catch (_) {
|
|
113
126
|
notify(session, scan.notify({ type: 'parse_error' }));
|
|
114
127
|
return { kind: 'success', text: '' };
|
|
115
128
|
}
|