jbc-dssi 1.1.162 → 1.1.164
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/index.js +24 -10
- package/lib/edge-stream.js +79 -0
- package/lib/workspace-bytes.js +22 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -27,9 +27,10 @@ import { createScheduleEngine } from './lib/schedules.js';
|
|
|
27
27
|
import { createProcEngine } from './lib/proc-commands.js';
|
|
28
28
|
import { createTtsEngine } from './lib/tts.js';
|
|
29
29
|
import { createEdgeTts, EDGE_VOICES } from './lib/edge-tts.js';
|
|
30
|
+
import { createEdgeStream } from './lib/edge-stream.js';
|
|
30
31
|
import { createAppReleaseWatch } from './lib/app-release-watch.js';
|
|
31
32
|
import { PLUGIN_FEATURES } from './lib/plugin-features.js';
|
|
32
|
-
import { MAX_FILE_BYTES, mimeOfFile, resolveWorkspaceFilePath } from './lib/workspace-bytes.js';
|
|
33
|
+
import { MAX_FILE_BYTES, mimeOfFile, mimeOfImage, resolveWorkspaceFilePath } from './lib/workspace-bytes.js';
|
|
33
34
|
|
|
34
35
|
/*
|
|
35
36
|
* ★ 协议层与瘦身层**直接引用 core**,本目录不再保有自己的副本。
|
|
@@ -149,13 +150,14 @@ export const inject = ['sessionController'];
|
|
|
149
150
|
const PROTOCOL_VERSION = 1;
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
|
-
* 手机"点了才传"的图片大小上限(2 MB
|
|
153
|
+
* 手机"点了才传"的图片大小上限(5 MB 原图,2026-11-27 老谢从 2 MB 调上来)。
|
|
153
154
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
155
|
+
* 帧上限 8 MB,base64 再胀 1.33 倍 —— 5 MB 原图 ≈ 6.7 MB 帧,仍在帧上限之内,
|
|
156
|
+
* 但已经接近:再往上加就会撞 8 MB 的帧上限,得先改协议分片,别直接调这个数。
|
|
157
|
+
* 超过上限的图先让电脑侧压缩,比让一帧把连接堵住好(大帧在 4G 上传要十几秒,
|
|
158
|
+
* 期间所有消息都排在它后面)。
|
|
157
159
|
*/
|
|
158
|
-
const MAX_IMAGE_BYTES =
|
|
160
|
+
const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
159
161
|
|
|
160
162
|
/** 手机上没人回答时,最多等这么久就把审批交回浏览器处理。 */
|
|
161
163
|
const APPROVAL_TIMEOUT_MS = 5 * 60 * 1000;
|
|
@@ -2228,14 +2230,19 @@ class BridgeConnection {
|
|
|
2228
2230
|
if (op === 'stop') {
|
|
2229
2231
|
this.tts.stop(id);
|
|
2230
2232
|
this.edge?.stop(id);
|
|
2233
|
+
this.edgeStream?.stop(id);
|
|
2231
2234
|
return;
|
|
2232
2235
|
}
|
|
2233
2236
|
if (op === 'voices') {
|
|
2234
2237
|
this.send(FRAME.VOICE_LIST, { voices: EDGE_VOICES });
|
|
2235
2238
|
return;
|
|
2236
2239
|
}
|
|
2240
|
+
this.edge ??= createEdgeTts({ log: (message) => this.opts.log(message) });
|
|
2241
|
+
this.edgeStream ??= createEdgeStream({
|
|
2242
|
+
edge: this.edge,
|
|
2243
|
+
send: (frame) => this.send(FRAME.TTS_AUDIO, frame),
|
|
2244
|
+
});
|
|
2237
2245
|
if (op === 'player') {
|
|
2238
|
-
this.edge ??= createEdgeTts({ log: (message) => this.opts.log(message) });
|
|
2239
2246
|
const result = await this.edge.synthesize({
|
|
2240
2247
|
id,
|
|
2241
2248
|
text: payload?.text,
|
|
@@ -2247,6 +2254,11 @@ class BridgeConnection {
|
|
|
2247
2254
|
return;
|
|
2248
2255
|
}
|
|
2249
2256
|
if (op === 'open') {
|
|
2257
|
+
const voice = typeof payload?.voice === 'string' ? payload.voice : '';
|
|
2258
|
+
if (EDGE_VOICES.some((v) => v.id === voice)) {
|
|
2259
|
+
this.edgeStream.open(id, voice);
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2250
2262
|
await this.tts.open({
|
|
2251
2263
|
id,
|
|
2252
2264
|
voice: payload?.voice,
|
|
@@ -2257,11 +2269,13 @@ class BridgeConnection {
|
|
|
2257
2269
|
return;
|
|
2258
2270
|
}
|
|
2259
2271
|
if (op === 'text') {
|
|
2260
|
-
this.
|
|
2272
|
+
if (this.edgeStream?.has(id)) this.edgeStream.text(id, payload?.text);
|
|
2273
|
+
else this.tts.text(id, payload?.text);
|
|
2261
2274
|
return;
|
|
2262
2275
|
}
|
|
2263
2276
|
if (op === 'end') {
|
|
2264
|
-
this.
|
|
2277
|
+
if (this.edgeStream?.has(id)) this.edgeStream.end(id);
|
|
2278
|
+
else this.tts.end(id);
|
|
2265
2279
|
}
|
|
2266
2280
|
}
|
|
2267
2281
|
|
|
@@ -3667,7 +3681,7 @@ class BridgeConnection {
|
|
|
3667
3681
|
const mb = (st.size / 1024 / 1024).toFixed(1);
|
|
3668
3682
|
this.send(FRAME.IMAGE_DATA, {
|
|
3669
3683
|
path: raw,
|
|
3670
|
-
error: `图片太大(${mb} MB),超过
|
|
3684
|
+
error: `图片太大(${mb} MB),超过 5 MB 先在电脑上压缩`,
|
|
3671
3685
|
});
|
|
3672
3686
|
return;
|
|
3673
3687
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export function createEdgeStream({ edge, send }) {
|
|
2
|
+
const sessions = new Map();
|
|
3
|
+
|
|
4
|
+
function open(id, voice) {
|
|
5
|
+
sessions.set(id, { voice, queue: [], busy: false, done: false, cancelled: false });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function has(id) {
|
|
9
|
+
return sessions.has(id);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function text(id, text) {
|
|
13
|
+
const s = sessions.get(id);
|
|
14
|
+
if (!s || s.cancelled) return;
|
|
15
|
+
const body = typeof text === 'string' ? text : '';
|
|
16
|
+
if (body.trim() === '') return;
|
|
17
|
+
s.queue.push(body);
|
|
18
|
+
pump(id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function end(id) {
|
|
22
|
+
const s = sessions.get(id);
|
|
23
|
+
if (!s) return;
|
|
24
|
+
s.done = true;
|
|
25
|
+
if (!s.busy && s.queue.length === 0) finish(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function finish(id) {
|
|
29
|
+
const s = sessions.get(id);
|
|
30
|
+
if (!s) return;
|
|
31
|
+
sessions.delete(id);
|
|
32
|
+
if (!s.cancelled) send({ id, done: true, codec: 'mp3' });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function pump(id) {
|
|
36
|
+
const s = sessions.get(id);
|
|
37
|
+
if (!s || s.busy || s.cancelled) return;
|
|
38
|
+
s.busy = true;
|
|
39
|
+
try {
|
|
40
|
+
while (s.queue.length > 0 && !s.cancelled) {
|
|
41
|
+
const body = s.queue.shift();
|
|
42
|
+
const result = await edge.synthesize({
|
|
43
|
+
id,
|
|
44
|
+
text: body,
|
|
45
|
+
voice: s.voice,
|
|
46
|
+
onChunk: (frame) => {
|
|
47
|
+
if (!s.cancelled) send(frame);
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (!result?.ok) {
|
|
51
|
+
const current = sessions.get(id);
|
|
52
|
+
if (current) {
|
|
53
|
+
sessions.delete(id);
|
|
54
|
+
send({ id, error: { code: 'edge', message: result?.message ?? '语音合成失败' } });
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
s.busy = false;
|
|
61
|
+
}
|
|
62
|
+
if (s.done && s.queue.length === 0) finish(id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function stop(id) {
|
|
66
|
+
const s = sessions.get(id);
|
|
67
|
+
if (!s) return;
|
|
68
|
+
s.cancelled = true;
|
|
69
|
+
s.queue.length = 0;
|
|
70
|
+
sessions.delete(id);
|
|
71
|
+
edge.stop(id);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function stopAll() {
|
|
75
|
+
for (const id of [...sessions.keys()]) stop(id);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { open, has, text, end, stop, stopAll };
|
|
79
|
+
}
|
package/lib/workspace-bytes.js
CHANGED
|
@@ -3,6 +3,28 @@ import { join, resolve, sep } from 'node:path';
|
|
|
3
3
|
|
|
4
4
|
export const MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 按扩展名判「是不是图片」,是就返回 MIME,不是返回 null。
|
|
8
|
+
*
|
|
9
|
+
* ★ 2026-11-27 修:这个函数原本定义在 index.js 里,11-15 那次把 MIME 判断搬进本文件时
|
|
10
|
+
* 只搬了文件类型(mimeOfFile),`#readImage` 那处 `mimeOfImage(abs)` 调用忘了跟过来,
|
|
11
|
+
* 于是手机点正文图片 100% 抛 `mimeOfImage is not defined`、永远收不到图。
|
|
12
|
+
* 现在 MIME 知识统一放这里,两边都从这里取,别再各写一套。
|
|
13
|
+
*/
|
|
14
|
+
export function mimeOfImage(p) {
|
|
15
|
+
const m = /\.([a-z0-9]+)$/i.exec(String(p ?? ''));
|
|
16
|
+
if (!m) return null;
|
|
17
|
+
switch (m[1].toLowerCase()) {
|
|
18
|
+
case 'png': return 'image/png';
|
|
19
|
+
case 'jpg':
|
|
20
|
+
case 'jpeg': return 'image/jpeg';
|
|
21
|
+
case 'webp': return 'image/webp';
|
|
22
|
+
case 'gif': return 'image/gif';
|
|
23
|
+
case 'bmp': return 'image/bmp';
|
|
24
|
+
default: return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
6
28
|
export function mimeOfFile(p) {
|
|
7
29
|
const m = /\.([a-z0-9]+)$/i.exec(String(p ?? ''));
|
|
8
30
|
if (!m) return 'application/octet-stream';
|