reflectt-node 0.1.20 → 0.1.21

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,SAAS,CAAA;AAm8D9D,wBAAsB,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,CA0ghB7D"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,SAAS,CAAA;AAm8D9D,wBAAsB,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,CAyhhB7D"}
package/dist/server.js CHANGED
@@ -10627,6 +10627,9 @@ export async function createServer() {
10627
10627
  'Connection': 'keep-alive',
10628
10628
  'X-Accel-Buffering': 'no',
10629
10629
  });
10630
+ // Track live viewer
10631
+ liveViewerCount++;
10632
+ let viewersDirty = true;
10630
10633
  // Derive agents from task board — show ALL agents, not just canvas-state emitters
10631
10634
  const allTasks = taskManager.listTasks({});
10632
10635
  const agentStates = {};
@@ -10651,7 +10654,7 @@ export async function createServer() {
10651
10654
  }
10652
10655
  // Send current state as initial snapshot — include all agents from task board
10653
10656
  const activeSlots = canvasSlots.getActive();
10654
- reply.raw.write(`event: snapshot\ndata: ${JSON.stringify({ slots: activeSlots, agents: agentStates })}\n\n`);
10657
+ reply.raw.write(`event: snapshot\ndata: ${JSON.stringify({ slots: activeSlots, agents: agentStates, viewers: liveViewerCount })}\n\n`);
10655
10658
  // Subscribe to new render events
10656
10659
  const unsubscribe = subscribeCanvas((event, slot) => {
10657
10660
  try {
@@ -10672,10 +10675,19 @@ export async function createServer() {
10672
10675
  }, 15_000);
10673
10676
  // Cleanup on disconnect
10674
10677
  request.raw.on('close', () => {
10678
+ liveViewerCount = Math.max(0, liveViewerCount - 1);
10675
10679
  unsubscribe();
10676
10680
  clearInterval(heartbeat);
10677
10681
  });
10678
10682
  });
10683
+ // ── Live Viewer Counter ─────────────────────────────────────────────
10684
+ // Tracks open SSE connections to /canvas/stream with live=true
10685
+ // Exposed via GET /canvas/viewers
10686
+ let liveViewerCount = 0;
10687
+ app.get('/canvas/viewers', async (_request, reply) => {
10688
+ reply.header('cache-control', 'no-cache');
10689
+ return reply.send({ viewers: liveViewerCount });
10690
+ });
10679
10691
  // ── Feedback Collection ─────────────────────────────────────────────
10680
10692
  const VALID_CATEGORIES = new Set(['bug', 'feature', 'general']);
10681
10693
  app.post('/feedback', async (request, reply) => {