jbc-dssi 1.1.159 → 1.1.161
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 +53 -1
- package/lib/protocol.js +4 -0
- package/lib/slim.js +33 -5
- package/package.json +1 -1
- package/vendor/groups/bridge/engine/rotate.js +6 -2
package/index.js
CHANGED
|
@@ -2161,6 +2161,54 @@ class BridgeConnection {
|
|
|
2161
2161
|
this.#fire('bots-refresh', this.#refreshBots({ force: true }));
|
|
2162
2162
|
}
|
|
2163
2163
|
|
|
2164
|
+
/**
|
|
2165
|
+
* 单聊上下文轮换(2026-11-26 老谢定):手机判定超过 500K 后发来交接文档,
|
|
2166
|
+
* 电脑侧在同工作区/同智能体下新开一个会话,把交接文档作为首条消息注入。
|
|
2167
|
+
*/
|
|
2168
|
+
async #rotateSession(payload) {
|
|
2169
|
+
const handoff = typeof payload?.text === 'string' ? payload.text : '';
|
|
2170
|
+
if (handoff.trim() === '') return;
|
|
2171
|
+
const entityId = typeof payload?.entityId === 'string' ? payload.entityId : '';
|
|
2172
|
+
const title = typeof payload?.title === 'string' ? payload.title : '';
|
|
2173
|
+
const oldSessionId = this.sessionId;
|
|
2174
|
+
|
|
2175
|
+
let newSessionId = null;
|
|
2176
|
+
try {
|
|
2177
|
+
if (entityId && this.dssAgent?.createSession) {
|
|
2178
|
+
const created = await this.dssAgent.createSession({
|
|
2179
|
+
entityId,
|
|
2180
|
+
title: title || undefined,
|
|
2181
|
+
});
|
|
2182
|
+
newSessionId = created?.sessionId ?? null;
|
|
2183
|
+
}
|
|
2184
|
+
if (!newSessionId) {
|
|
2185
|
+
const value = await this.ctx.sessionController.create({});
|
|
2186
|
+
newSessionId = value?.sessionId ?? null;
|
|
2187
|
+
}
|
|
2188
|
+
if (!newSessionId) throw new Error('没有拿到新会话 id');
|
|
2189
|
+
} catch (err) {
|
|
2190
|
+
this.fail(`开新会话失败:${err?.message ?? err}`);
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
try {
|
|
2195
|
+
await this.ctx.sessionController.prompt(
|
|
2196
|
+
{
|
|
2197
|
+
requestId: randomUUID(),
|
|
2198
|
+
sessionId: newSessionId,
|
|
2199
|
+
mode: 'queue',
|
|
2200
|
+
content: [{ type: 'text', text: handoff }],
|
|
2201
|
+
},
|
|
2202
|
+
new AbortController().signal,
|
|
2203
|
+
);
|
|
2204
|
+
} catch (err) {
|
|
2205
|
+
this.opts.log(`[rotate] 交接文档注入失败(新会话仍可用):${err?.message ?? err}`);
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
this.opts.log(`[rotate] 会话已轮换 old=${oldSessionId} new=${newSessionId}`);
|
|
2209
|
+
this.send(FRAME.ROTATE_DONE, { oldSessionId, sessionId: newSessionId });
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2164
2212
|
/**
|
|
2165
2213
|
* DeepSeek 语音合成(2026-11-25 老谢定):手机只发文本和音色,
|
|
2166
2214
|
* 电脑侧用 DeepSeek Key 调 `/v1/tools/tts`,PCM 边下边回、手机边收边播。
|
|
@@ -2478,6 +2526,10 @@ class BridgeConnection {
|
|
|
2478
2526
|
this.#fire('tts', this.#ttsCommand(payload));
|
|
2479
2527
|
break;
|
|
2480
2528
|
|
|
2529
|
+
case FRAME.ROTATE_REQ:
|
|
2530
|
+
this.#fire('rotate', this.#rotateSession(payload));
|
|
2531
|
+
break;
|
|
2532
|
+
|
|
2481
2533
|
case FRAME.FOCUS: {
|
|
2482
2534
|
this.focused = payload?.active === true;
|
|
2483
2535
|
/*
|
|
@@ -3168,7 +3220,7 @@ class BridgeConnection {
|
|
|
3168
3220
|
? Number(frame.cursor)
|
|
3169
3221
|
: 0;
|
|
3170
3222
|
// 裁剪:实测一个 80 条消息的快照原样是 1278 KB,裁完降到几十 KB
|
|
3171
|
-
this.send(FRAME.SNAPSHOT, frame);
|
|
3223
|
+
this.send(FRAME.SNAPSHOT, slimSnapshot(frame, { maxEvents: 400 }));
|
|
3172
3224
|
// 附着后的首个快照里已带最新投影:顺手刷新一次团队快照
|
|
3173
3225
|
this.#scheduleBotsRefresh(60);
|
|
3174
3226
|
break;
|
package/lib/protocol.js
CHANGED
package/lib/slim.js
CHANGED
|
@@ -69,6 +69,27 @@ function toEpochMs(value) {
|
|
|
69
69
|
return Number.isFinite(ms) ? ms : 0;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
function trimDeep(value, depth = 0) {
|
|
73
|
+
if (depth > 6) return null;
|
|
74
|
+
if (typeof value === 'string') {
|
|
75
|
+
if (value.length <= MAX_TEXT_CHARS) return value;
|
|
76
|
+
return `${value.slice(0, MAX_TEXT_CHARS)}\n…(还有 ${value.length - MAX_TEXT_CHARS} 字,手机上不传了)`;
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
return value.slice(0, 200).map((item) => trimDeep(item, depth + 1));
|
|
80
|
+
}
|
|
81
|
+
if (value && typeof value === 'object') {
|
|
82
|
+
const out = {};
|
|
83
|
+
let keys = 0;
|
|
84
|
+
for (const [k, v] of Object.entries(value)) {
|
|
85
|
+
if (keys++ >= 80) break;
|
|
86
|
+
out[k] = trimDeep(v, depth + 1);
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
|
|
72
93
|
function clip(text, limit = MAX_TEXT_CHARS) {
|
|
73
94
|
if (typeof text !== 'string') return text;
|
|
74
95
|
if (text.length <= limit) return text;
|
|
@@ -128,7 +149,7 @@ function userText(content) {
|
|
|
128
149
|
}
|
|
129
150
|
|
|
130
151
|
export function slimEvent(event) {
|
|
131
|
-
if (!event ||
|
|
152
|
+
if (!event || typeof event.type !== 'string' || event.type === '') return null;
|
|
132
153
|
|
|
133
154
|
const d = event.data ?? {};
|
|
134
155
|
let data;
|
|
@@ -203,7 +224,7 @@ export function slimEvent(event) {
|
|
|
203
224
|
|
|
204
225
|
default:
|
|
205
226
|
|
|
206
|
-
data = d;
|
|
227
|
+
data = trimDeep(d);
|
|
207
228
|
}
|
|
208
229
|
|
|
209
230
|
const out = { type: event.type, seq: event.seq, time: event.time, data };
|
|
@@ -211,7 +232,7 @@ export function slimEvent(event) {
|
|
|
211
232
|
return out;
|
|
212
233
|
}
|
|
213
234
|
|
|
214
|
-
export function slimSnapshot(snapshot) {
|
|
235
|
+
export function slimSnapshot(snapshot, { maxEvents = 400 } = {}) {
|
|
215
236
|
if (!snapshot || !Array.isArray(snapshot.records)) return snapshot;
|
|
216
237
|
|
|
217
238
|
const records = [];
|
|
@@ -220,12 +241,19 @@ export function slimSnapshot(snapshot) {
|
|
|
220
241
|
if (slim) records.push({ type: 'event', event: slim });
|
|
221
242
|
}
|
|
222
243
|
|
|
244
|
+
let trimmed = records;
|
|
245
|
+
let hasMore = snapshot.hasMore === true;
|
|
246
|
+
if (records.length > maxEvents) {
|
|
247
|
+
trimmed = records.slice(records.length - maxEvents);
|
|
248
|
+
hasMore = true;
|
|
249
|
+
}
|
|
250
|
+
|
|
223
251
|
return {
|
|
224
252
|
type: 'snapshot',
|
|
225
253
|
header: snapshot.header,
|
|
226
254
|
cursor: snapshot.cursor,
|
|
227
|
-
records,
|
|
228
|
-
hasMore
|
|
255
|
+
records: trimmed,
|
|
256
|
+
hasMore,
|
|
229
257
|
|
|
230
258
|
projections: null,
|
|
231
259
|
assistantStream: snapshot.assistantStream,
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export const CONTEXT_WINDOW_TOKENS = 1_000_000;
|
|
4
4
|
export const ROTATE_TOKEN_RATIO = 0.5;
|
|
5
|
+
export const ROTATE_TOKENS = 500_000;
|
|
5
6
|
export const ROTATE_ROUNDS = 40;
|
|
6
7
|
export const ROTATE_BYTES = 300 * 1024;
|
|
7
8
|
|
|
@@ -10,7 +11,7 @@ export const HANDOFF_MAX_CHARS = 24_000;
|
|
|
10
11
|
export const ROTATE_COOLDOWN_MS = 10 * 60_000;
|
|
11
12
|
|
|
12
13
|
export const ROTATION_DEFAULTS = Object.freeze({
|
|
13
|
-
maxContextTokens:
|
|
14
|
+
maxContextTokens: ROTATE_TOKENS,
|
|
14
15
|
maxRounds: ROTATE_ROUNDS,
|
|
15
16
|
maxBytes: ROTATE_BYTES,
|
|
16
17
|
});
|
|
@@ -24,7 +25,10 @@ export function normalizeRotationConfig(options = {}) {
|
|
|
24
25
|
const legacyWindow = positiveNumber(options.windowTokens) ?? CONTEXT_WINDOW_TOKENS;
|
|
25
26
|
const legacyRatio = positiveNumber(options.ratio) ?? ROTATE_TOKEN_RATIO;
|
|
26
27
|
const maxContextTokens =
|
|
27
|
-
positiveNumber(options.maxContextTokens) ??
|
|
28
|
+
positiveNumber(options.maxContextTokens) ??
|
|
29
|
+
(positiveNumber(options.windowTokens) || positiveNumber(options.ratio)
|
|
30
|
+
? legacyWindow * Math.min(legacyRatio, 1)
|
|
31
|
+
: ROTATE_TOKENS);
|
|
28
32
|
return {
|
|
29
33
|
maxContextTokens,
|
|
30
34
|
maxRounds: positiveNumber(options.maxRounds) ?? ROTATION_DEFAULTS.maxRounds,
|