jbc-dssi 1.1.160 → 1.1.162

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 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
  /*
package/lib/protocol.js CHANGED
@@ -132,6 +132,10 @@ export const FRAME = {
132
132
 
133
133
  VOICE_LIST: 0x42,
134
134
 
135
+ ROTATE_REQ: 0x43,
136
+
137
+ ROTATE_DONE: 0x44,
138
+
135
139
  TTS_AUDIO: 0x7e,
136
140
 
137
141
  PING: 0x40,
package/lib/tts.js CHANGED
@@ -7,9 +7,7 @@ export const TTS_VOICES = [
7
7
  ];
8
8
 
9
9
  const TTS_WS = 'wss://api.deepseek.com/v1/tools/tts';
10
- const MAX_CHARS = 8000;
11
- const MAX_INFLIGHT = 2;
12
- const CONNECT_TIMEOUT_MS = 15_000;
10
+
13
11
 
14
12
  function voiceOf(id) {
15
13
  return TTS_VOICES.some((v) => v.id === id) ? id : TTS_VOICES[0].id;
@@ -37,10 +35,6 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
37
35
 
38
36
  async function open({ id, voice, onPage, onDone, onError }) {
39
37
  if (typeof id !== 'string' || id === '') return;
40
- if (sessions.size >= MAX_INFLIGHT) {
41
- onError?.({ id, error: normalizeError('busy') });
42
- return;
43
- }
44
38
  const early = [];
45
39
  let earlyEnd = false;
46
40
  sessions.set(id, {
@@ -82,7 +76,6 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
82
76
  };
83
77
  sessions.set(id, session);
84
78
 
85
- const timer = setTimeout(() => finish(session, id, { code: 'timeout' }), CONNECT_TIMEOUT_MS);
86
79
 
87
80
  function flushPages(bytes) {
88
81
  for (const chunk of bytes) {
@@ -94,7 +87,6 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
94
87
  function finish(target, sessionId, error) {
95
88
  if (target.settled) return;
96
89
  target.settled = true;
97
- clearTimeout(timer);
98
90
  sessions.delete(sessionId);
99
91
  try {
100
92
  target.ws.close();
@@ -119,8 +111,6 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
119
111
  session.pending.push(text);
120
112
  return;
121
113
  }
122
- if (session.chars >= MAX_CHARS) return;
123
- session.chars += text.length;
124
114
  try {
125
115
  ws.send(JSON.stringify({ event: 'text', text }));
126
116
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.160",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "description": "鲸聊 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [
@@ -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: CONTEXT_WINDOW_TOKENS * ROTATE_TOKEN_RATIO,
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) ?? legacyWindow * Math.min(legacyRatio, 1);
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,