jbc-dssi 1.1.69 → 1.1.70

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
@@ -2023,10 +2023,11 @@ class BridgeConnection {
2023
2023
  /*
2024
2024
  * 模型面板(2026-10-23):
2025
2025
  * 查询 = 手机点开「模型」胶囊时发;设置 = 用户点某一项时发。
2026
- * 两条都带 sessionId —— 手机有多条会话,必须按"正在看的那条"操作。
2026
+ * 单聊带 sessionId;群成员面板(2026-11-05)带 groupId + memberId,
2027
+ * 电脑侧按群会话映射换成 sessionId(见 #resolveTarget)。
2027
2028
  */
2028
2029
  case FRAME.MODEL_STATE_REQ:
2029
- this.#fire('model-state', this.#modelState(payload?.sessionId));
2030
+ this.#fire('model-state', this.#modelState(payload));
2030
2031
  break;
2031
2032
 
2032
2033
  case FRAME.MODEL_SET:
@@ -2047,11 +2048,11 @@ class BridgeConnection {
2047
2048
  * 压缩可能跑十几秒(要调模型生成摘要),所以走异步 fire,不挡其它帧。
2048
2049
  */
2049
2050
  case FRAME.CONTEXT_USAGE_REQ:
2050
- this.#fire('context-usage', this.#contextUsage(payload?.sessionId));
2051
+ this.#fire('context-usage', this.#contextUsage(payload));
2051
2052
  break;
2052
2053
 
2053
2054
  case FRAME.COMPACT:
2054
- this.#fire('compact', this.#compact(payload?.sessionId));
2055
+ this.#fire('compact', this.#compact(payload));
2055
2056
  break;
2056
2057
 
2057
2058
  /*
@@ -2362,15 +2363,45 @@ class BridgeConnection {
2362
2363
  * 为什么不向 DSH 要:没有"读当前选择"的接口;而 request/header 是事实来源,
2363
2364
  * 正好我们从 follow 流里本来就能看到。
2364
2365
  */
2365
- async #modelState(sessionId) {
2366
- const target = typeof sessionId === 'string' && sessionId ? sessionId : this.sessionId;
2367
- if (!target) {
2368
- this.fail('查询模型失败:还没附着会话');
2366
+ /**
2367
+ * 解析"这次操作的目标会话"(2026-11-05 群成员模型面板)。
2368
+ *
2369
+ * 两种入参二选一,都不给才退回当前附着会话:
2370
+ * · `{ groupId, memberId }` → 该成员**在这个群**的群会话(映射来自群状态;
2371
+ * 轮换后自动指向新会话)。纯加法:老手机只发 sessionId,走的还是原路径。
2372
+ * · `{ sessionId }` → 单聊会话(原行为)。
2373
+ *
2374
+ * 解析失败抛错,由调用方转成 ERROR 帧的"读取失败(原因)"。
2375
+ */
2376
+ async #resolveTarget(payload) {
2377
+ const groupId = typeof payload?.groupId === 'string' ? payload.groupId : '';
2378
+ const memberId = typeof payload?.memberId === 'string' ? payload.memberId : '';
2379
+ if (groupId && memberId) {
2380
+ if (!this.groups || typeof this.groups.memberSessionId !== 'function') {
2381
+ throw new Error('群聊能力未启用');
2382
+ }
2383
+ const sessionId = await this.groups.memberSessionId(groupId, memberId);
2384
+ if (!sessionId) throw new Error('该成员在本群没有会话映射');
2385
+ return { sessionId, echo: { groupId, memberId } };
2386
+ }
2387
+ const sessionId =
2388
+ typeof payload?.sessionId === 'string' && payload.sessionId ? payload.sessionId : this.sessionId;
2389
+ if (!sessionId) throw new Error('还没附着会话');
2390
+ return { sessionId, echo: {} };
2391
+ }
2392
+
2393
+ async #modelState(payload) {
2394
+ let target;
2395
+ let echo;
2396
+ try {
2397
+ ({ sessionId: target, echo } = await this.#resolveTarget(payload));
2398
+ } catch (err) {
2399
+ this.fail(`查询模型失败:${err?.message ?? err}`);
2369
2400
  return;
2370
2401
  }
2371
2402
  const catalog = await this.ctx.sessionController.modelCatalog();
2372
2403
  const selected = this.modelSelections.get(target) ?? selectionFromCatalog(catalog?.default);
2373
- this.send(FRAME.MODEL_STATE, modelStatePayload(target, catalog, selected));
2404
+ this.send(FRAME.MODEL_STATE, { ...modelStatePayload(target, catalog, selected), ...echo });
2374
2405
  }
2375
2406
 
2376
2407
  /**
@@ -2381,9 +2412,12 @@ class BridgeConnection {
2381
2412
  * 返回值用 DSH 归一化后的 selected(它可能把 provider/model 解析成别名)。
2382
2413
  */
2383
2414
  async #modelSet(payload) {
2384
- const target = typeof payload?.sessionId === 'string' && payload.sessionId ? payload.sessionId : this.sessionId;
2385
- if (!target) {
2386
- this.fail('设置模型失败:还没附着会话');
2415
+ let target;
2416
+ let echo;
2417
+ try {
2418
+ ({ sessionId: target, echo } = await this.#resolveTarget(payload));
2419
+ } catch (err) {
2420
+ this.fail(`设置模型失败:${err?.message ?? err}`);
2387
2421
  return;
2388
2422
  }
2389
2423
  const provider = typeof payload?.provider === 'string' ? payload.provider : '';
@@ -2410,7 +2444,7 @@ class BridgeConnection {
2410
2444
  (selected.effort ? ` · ${selected.effort}` : ''),
2411
2445
  );
2412
2446
  const catalog = await this.ctx.sessionController.modelCatalog();
2413
- this.send(FRAME.MODEL_STATE, modelStatePayload(target, catalog, selected));
2447
+ this.send(FRAME.MODEL_STATE, { ...modelStatePayload(target, catalog, selected), ...echo });
2414
2448
  }
2415
2449
 
2416
2450
  /**
@@ -2458,10 +2492,13 @@ class BridgeConnection {
2458
2492
  * percent = min(100, round(used / contextWindow * 100))。
2459
2493
  * 拿不到就回 null —— 手机端显示「—」,绝不编一个 0% 出来。
2460
2494
  */
2461
- async #contextUsage(sessionId) {
2462
- const target = typeof sessionId === 'string' && sessionId ? sessionId : this.sessionId;
2463
- if (!target) {
2464
- this.fail('查询上下文失败:还没附着会话');
2495
+ async #contextUsage(payload) {
2496
+ let target;
2497
+ let echo;
2498
+ try {
2499
+ ({ sessionId: target, echo } = await this.#resolveTarget(payload));
2500
+ } catch (err) {
2501
+ this.fail(`查询上下文失败:${err?.message ?? err}`);
2465
2502
  return;
2466
2503
  }
2467
2504
  let pressure;
@@ -2486,6 +2523,7 @@ class BridgeConnection {
2486
2523
  percent,
2487
2524
  usedTokens: typeof used === 'number' ? used : null,
2488
2525
  contextWindow: window,
2526
+ ...echo,
2489
2527
  });
2490
2528
  }
2491
2529
 
@@ -2499,10 +2537,13 @@ class BridgeConnection {
2499
2537
  * 为什么用 fire 异步执行:压缩要调一次模型生成摘要,可能十几秒 ——
2500
2538
  * 不能挡住其它帧(心跳、流式输出)的处理。
2501
2539
  */
2502
- async #compact(sessionId) {
2503
- const target = typeof sessionId === 'string' && sessionId ? sessionId : this.sessionId;
2504
- if (!target) {
2505
- this.fail('压缩失败:还没附着会话');
2540
+ async #compact(payload) {
2541
+ let target;
2542
+ let echo;
2543
+ try {
2544
+ ({ sessionId: target, echo } = await this.#resolveTarget(payload));
2545
+ } catch (err) {
2546
+ this.fail(`压缩失败:${err?.message ?? err}`);
2506
2547
  return;
2507
2548
  }
2508
2549
  const commands = this.ctx.get?.('commands');
@@ -2529,7 +2570,7 @@ class BridgeConnection {
2529
2570
  const result = execution.result ?? {};
2530
2571
  const text = compactText(result);
2531
2572
  this.opts.log(`[compact] ${target}: ${text}`);
2532
- this.send(FRAME.COMPACT_DONE, { sessionId: target, ok: result.kind === 'success', text });
2573
+ this.send(FRAME.COMPACT_DONE, { sessionId: target, ok: result.kind === 'success', text, ...echo });
2533
2574
  }
2534
2575
 
2535
2576
  async #list() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.69",
3
+ "version": "1.1.70",
4
4
  "type": "module",
5
5
  "description": "鲸编程 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [
@@ -552,6 +552,21 @@ export function createGroupsEngine({
552
552
  return engine?.rotationThresholds?.() ?? { ...rotationConfig };
553
553
  }
554
554
 
555
+ /**
556
+ * 成员在**这个群**里的群会话 id(2026-11-05 群成员模型面板用)。
557
+ *
558
+ * 只做查表,不建会话:群成员会话由引擎在首次投递时懒创建并写进
559
+ * `state.groupSessions`;轮换后映射指向新会话,所以这里天然拿到"当下正在用的那条"。
560
+ * 没有映射返回 null —— 调用方(插件 index)据此回"读取失败(会话映射缺失)",
561
+ * 绝不自己造一个会话出来。
562
+ */
563
+ async function memberSessionId(groupId, memberId) {
564
+ if (typeof groupId !== 'string' || !groupId) return null;
565
+ if (typeof memberId !== 'string' || !memberId) return null;
566
+ await ensure();
567
+ return state?.groupSessions?.[groupId]?.[memberId] ?? null;
568
+ }
569
+
555
570
  async function dispose() {
556
571
  loading = null;
557
572
  state = null;
@@ -567,5 +582,7 @@ export function createGroupsEngine({
567
582
  // 2026-11-05:阈值热调(插件读 ui-config 的 tuning.rotate 后调用)
568
583
  setRotationConfig,
569
584
  rotationThresholds,
585
+ // 2026-11-05:群成员模型面板要用"成员在这个群的会话 id"(只查表,不建会话)
586
+ memberSessionId,
570
587
  };
571
588
  }