@threadbase-sh/streamer 1.69.5 → 1.69.6

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/dist/index.js CHANGED
@@ -9962,6 +9962,13 @@ var SessionHandlers = class {
9962
9962
  get sessionSubscribers() {
9963
9963
  return this.deps.sessionSubscribers;
9964
9964
  }
9965
+ // Prompt lifecycle events (question / permission and their cancellations)
9966
+ // carry prompt content and go ONLY to the session's subscribers — never to
9967
+ // every connected socket. A client that subscribes after a prompt opened
9968
+ // gets it from the subscribe replay (server-wiring), not from a broadcast.
9969
+ broadcastToSession(sessionId, message) {
9970
+ this.wsHub.broadcastToClients(this.sessionSubscribers.get(sessionId) ?? [], message);
9971
+ }
9965
9972
  get agentConfig() {
9966
9973
  return this.deps.agentConfig;
9967
9974
  }
@@ -10516,7 +10523,7 @@ var SessionHandlers = class {
10516
10523
  const toolUseId = `screen:${sessionId}:${key.length}`;
10517
10524
  this.pendingQuestions.set(sessionId, { toolUseId, questions, origin: "pty" });
10518
10525
  this.pendingQuestionKey.set(sessionId, key);
10519
- this.wsHub.broadcast({ type: "question", sessionId, toolUseId, questions });
10526
+ this.broadcastToSession(sessionId, { type: "question", sessionId, toolUseId, questions });
10520
10527
  }
10521
10528
  // Permission gate opened/closed (OSC 777 + scraped options). Broadcasts the
10522
10529
  // additive `permission` / `permission_cancelled` events. Mobile answers by
@@ -10526,7 +10533,7 @@ var SessionHandlers = class {
10526
10533
  if (!this.pendingPermission.has(sessionId)) return;
10527
10534
  this.pendingPermission.delete(sessionId);
10528
10535
  this.pendingPermissionKey.delete(sessionId);
10529
- this.wsHub.broadcast({ type: "permission_cancelled", sessionId });
10536
+ this.broadcastToSession(sessionId, { type: "permission_cancelled", sessionId });
10530
10537
  return;
10531
10538
  }
10532
10539
  const key = permissionContentKey(gate);
@@ -10540,7 +10547,7 @@ var SessionHandlers = class {
10540
10547
  `[ws.broadcast_permission] ${sessionId.slice(0, 8)} subscribers=${subscriberCount}`,
10541
10548
  { event: "ws.broadcast_permission", sessionId, subscriberCount }
10542
10549
  );
10543
- this.wsHub.broadcast({
10550
+ this.broadcastToSession(sessionId, {
10544
10551
  type: "permission",
10545
10552
  sessionId,
10546
10553
  ...gate.prompt ? { prompt: gate.prompt } : {},
@@ -10588,7 +10595,7 @@ var SessionHandlers = class {
10588
10595
  const gateClosed = () => {
10589
10596
  this.pendingPermission.delete(sessionId);
10590
10597
  this.pendingPermissionKey.delete(sessionId);
10591
- this.wsHub.broadcast({ type: "permission_cancelled", sessionId });
10598
+ this.broadcastToSession(sessionId, { type: "permission_cancelled", sessionId });
10592
10599
  json(res, 409, { ok: false, reason: "gate_closed" });
10593
10600
  };
10594
10601
  const gate = this.pendingPermission.get(sessionId);
@@ -10674,7 +10681,7 @@ var SessionHandlers = class {
10674
10681
  if (!await this.questionMenuStillOpen(sessionId)) {
10675
10682
  this.pendingQuestions.delete(sessionId);
10676
10683
  this.pendingQuestionKey.delete(sessionId);
10677
- this.wsHub.broadcast({ type: "question_cancelled", sessionId, toolUseId });
10684
+ this.broadcastToSession(sessionId, { type: "question_cancelled", sessionId, toolUseId });
10678
10685
  json(res, 409, { ok: false, reason: "question_gone" });
10679
10686
  return;
10680
10687
  }
@@ -10686,7 +10693,7 @@ var SessionHandlers = class {
10686
10693
  return;
10687
10694
  }
10688
10695
  this.pendingQuestions.delete(sessionId);
10689
- this.wsHub.broadcast({ type: "question_cancelled", sessionId, toolUseId });
10696
+ this.broadcastToSession(sessionId, { type: "question_cancelled", sessionId, toolUseId });
10690
10697
  json(res, 200, { ok: true });
10691
10698
  }
10692
10699
  // Best-effort: a session we don't own a PTY for, or one that raced away
@@ -17807,7 +17814,7 @@ var StreamerServer = class {
17807
17814
  priorToolUseId
17808
17815
  });
17809
17816
  this.pendingQuestionKey.set(sessionId, key);
17810
- if (broadcast) this.wsHub.broadcast(m);
17817
+ if (broadcast) this.wsHub.broadcastToClients(this.sessionSubscribers.get(sessionId) ?? [], m);
17811
17818
  }
17812
17819
  }
17813
17820
  cancelPendingQuestion(sessionId) {
@@ -17815,7 +17822,11 @@ var StreamerServer = class {
17815
17822
  if (!pq) return;
17816
17823
  this.pendingQuestions.delete(sessionId);
17817
17824
  this.pendingQuestionKey.delete(sessionId);
17818
- this.wsHub.broadcast({ type: "question_cancelled", sessionId, toolUseId: pq.toolUseId });
17825
+ this.wsHub.broadcastToClients(this.sessionSubscribers.get(sessionId) ?? [], {
17826
+ type: "question_cancelled",
17827
+ sessionId,
17828
+ toolUseId: pq.toolUseId
17829
+ });
17819
17830
  }
17820
17831
  async handleBrowse(url, res) {
17821
17832
  if (!this.browseRoot) {