@yu_robotics/remote-cli-router 1.6.219 → 1.6.220

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/server.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RouterServer = void 0;
7
+ const DeliveryDiagnostics_1 = require("./utils/DeliveryDiagnostics");
7
8
  const IngressAdmission_1 = require("./security/IngressAdmission");
8
9
  const ApprovalCards_1 = require("./feishu/ApprovalCards");
9
10
  const WorkerContextCards_1 = require("./feishu/WorkerContextCards");
@@ -208,6 +209,8 @@ class RouterServer {
208
209
  this.feishuLongConnHandler.setOnCaptureSelection((openId, deviceId) => this.selections.capture(openId, deviceId));
209
210
  this.feishuLongConnHandler.setOnValidateSelection(fence => this.selections.isCurrent(fence));
210
211
  this.feishuLongConnHandler.setOnStartStreaming(async (messageId, openId, feishuMessageId, deviceId, threadId, pendingNewThread, queueCardId, threadName, selectionIntent) => {
212
+ if (feishuMessageId)
213
+ this.feishuLongConnHandler.bindDiagnosticTask?.(feishuMessageId, messageId);
211
214
  console.log(`[RouterServer] Registering streaming session: msgId=${messageId}, feishuMsgId=${feishuMessageId}, deviceId=${deviceId}, threadId=${threadId}, pendingNewThread=${pendingNewThread}`);
212
215
  this.cancelImageReply(messageId);
213
216
  const previous = this.streamingMessages.get(messageId);
@@ -471,6 +474,7 @@ class RouterServer {
471
474
  this.app.use(router.routes());
472
475
  this.app.use(router.allowedMethods());
473
476
  }
477
+ diagnosticConnectionEpoch = 0;
474
478
  /**
475
479
  * Setup WebSocket server
476
480
  */
@@ -481,6 +485,7 @@ class RouterServer {
481
485
  maxPayload: IngressAdmission_1.INGRESS_LIMITS.payloadBytes
482
486
  });
483
487
  this.wss.on('connection', (ws, req) => {
488
+ const connectionEpoch = ++this.diagnosticConnectionEpoch;
484
489
  const admission = this.stopping ? undefined : this.ingress.admit(req.socket.remoteAddress ?? 'unknown');
485
490
  if (!admission) {
486
491
  ws.on('error', () => { });
@@ -537,7 +542,7 @@ class RouterServer {
537
542
  // If no heartbeat received within 3x interval, consider connection dead
538
543
  const interval = this.config.get('websocket', 'heartbeatInterval');
539
544
  heartbeatTimeout = setTimeout(() => {
540
- console.log('Heartbeat timeout for device:', deviceId);
545
+ (0, DeliveryDiagnostics_1.deliveryEvent)('socket_heartbeat_timeout', { connectionEpoch });
541
546
  ws.close();
542
547
  }, interval * 3);
543
548
  };
@@ -681,17 +686,20 @@ class RouterServer {
681
686
  break;
682
687
  const current = imageCurrent;
683
688
  let success = false;
689
+ (0, DeliveryDiagnostics_1.deliveryEvent)('task_resume_received', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch });
684
690
  try {
685
691
  success = await this.handleTaskResume(message, deviceId, current);
686
692
  }
687
693
  catch (error) {
688
- console.error('[RouterServer] Failed to recover task card:', error);
694
+ (0, DeliveryDiagnostics_1.deliveryEvent)('task_resume_failed', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch, ...(0, DeliveryDiagnostics_1.safeCardError)(error) });
689
695
  }
690
696
  if (!success && current())
691
697
  this.cancelImageReply(message.messageId);
692
- if (current())
698
+ if (current()) {
693
699
  ws.send(JSON.stringify({ type: 'task_resume_ack', messageId: message.messageId,
694
700
  recoveryId: message.taskResume?.recoveryId, state: message.taskResume?.state, success, timestamp: Date.now() }));
701
+ (0, DeliveryDiagnostics_1.deliveryEvent)('resume_ack_send', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch, success, acceptedLocally: true });
702
+ }
695
703
  break;
696
704
  }
697
705
  case types_1.MessageType.BINDING_REQUEST:
@@ -848,8 +856,10 @@ class RouterServer {
848
856
  }));
849
857
  break;
850
858
  case types_1.MessageType.RESPONSE:
859
+ (0, DeliveryDiagnostics_1.deliveryEvent)('task_result_received', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch });
851
860
  if (taskRecoveryEnabled && deviceId && this.isCompletedTask(message.messageId, deviceId)) {
852
861
  ws.send(JSON.stringify({ type: 'task_result_ack', messageId: message.messageId, timestamp: Date.now() }));
862
+ (0, DeliveryDiagnostics_1.deliveryEvent)('result_ack_send', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch, acceptedLocally: true, duplicate: true });
853
863
  break;
854
864
  }
855
865
  // Device sends response to command - forward to Feishu via long connection
@@ -945,6 +955,7 @@ class RouterServer {
945
955
  this.rememberCompletedTask(responseMessageId, deviceId);
946
956
  if (this.connectionHub.isCurrentConnection(deviceId, ws)) {
947
957
  ws.send(JSON.stringify({ type: 'task_result_ack', messageId: responseMessageId, timestamp: Date.now() }));
958
+ (0, DeliveryDiagnostics_1.deliveryEvent)('result_ack_send', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(responseMessageId), connectionEpoch, acceptedLocally: true, duplicate: false });
948
959
  }
949
960
  }
950
961
  break;
@@ -968,7 +979,7 @@ class RouterServer {
968
979
  // Text is accumulated synchronously. Let subsequent deltas
969
980
  // coalesce while the card patch runs; finalization still
970
981
  // waits for updateInFlight before rendering the result.
971
- void update.catch(error => console.error('[RouterServer] Failed to update queued text:', error));
982
+ void update.catch(error => (0, DeliveryDiagnostics_1.deliveryEvent)('queued_text_failed', (0, DeliveryDiagnostics_1.safeCardError)(error)));
972
983
  }
973
984
  else {
974
985
  await update;
@@ -1034,7 +1045,7 @@ class RouterServer {
1034
1045
  }
1035
1046
  }
1036
1047
  catch (error) {
1037
- console.error('Error processing message:', error);
1048
+ (0, DeliveryDiagnostics_1.deliveryEvent)('router_message_failed', { connectionEpoch, ...(0, DeliveryDiagnostics_1.safeCardError)(error) });
1038
1049
  }
1039
1050
  finally {
1040
1051
  finishQueueMessage?.();
@@ -1050,7 +1061,8 @@ class RouterServer {
1050
1061
  }
1051
1062
  });
1052
1063
  // Handle connection close
1053
- ws.on('close', () => {
1064
+ ws.on('close', (code, reason) => {
1065
+ (0, DeliveryDiagnostics_1.deliveryEvent)('socket_close', { connectionEpoch, code, reasonBytes: reason?.length, registered });
1054
1066
  socketClosed = true;
1055
1067
  releaseAdmission();
1056
1068
  for (const [id, route] of this.imageReplies) {
@@ -1071,7 +1083,7 @@ class RouterServer {
1071
1083
  this.maintenanceConnections.delete(deviceId);
1072
1084
  this.workerContextConnections.delete(deviceId);
1073
1085
  void this.cleanupStreamingSessionsForDevice(deviceId).catch(() => console.error('Failed to expire disconnected streaming cards.'));
1074
- console.log('Device disconnected:', deviceId);
1086
+ (0, DeliveryDiagnostics_1.deliveryEvent)('registered_socket_removed', { connectionEpoch });
1075
1087
  }
1076
1088
  });
1077
1089
  // Handle errors
@@ -1087,7 +1099,7 @@ class RouterServer {
1087
1099
  if (!registered || (ws.readyState !== ws_1.WebSocket.CLOSING && ws.readyState !== ws_1.WebSocket.CLOSED)) {
1088
1100
  ws.terminate();
1089
1101
  }
1090
- console.error('WebSocket error:', error);
1102
+ (0, DeliveryDiagnostics_1.deliveryEvent)('socket_error', { connectionEpoch, ...(0, DeliveryDiagnostics_1.safeCardError)(error) });
1091
1103
  });
1092
1104
  });
1093
1105
  console.log('WebSocket server listening on /ws');
@@ -1599,7 +1611,7 @@ class RouterServer {
1599
1611
  await this.updateStreamingText(messageId, streamData.openId, streamData);
1600
1612
  }
1601
1613
  catch (error) {
1602
- console.error('[RouterServer] Failed to refresh delegated worker progress:', error);
1614
+ (0, DeliveryDiagnostics_1.deliveryEvent)('worker_progress_failed', (0, DeliveryDiagnostics_1.safeCardError)(error));
1603
1615
  }
1604
1616
  finally {
1605
1617
  if (this.isLiveDelegationProgress(messageId, streamData, state)) {
@@ -1979,6 +1991,8 @@ class RouterServer {
1979
1991
  const reusable = previous?.feishuMessageId && (!previous.finalizing
1980
1992
  || (previous.recoveryId === info.recoveryId && info.state !== 'running'));
1981
1993
  if (previous && reusable) {
1994
+ (0, DeliveryDiagnostics_1.deliveryEvent)('resume_card_reused', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(messageId), card: (0, DeliveryDiagnostics_1.taskCorrelation)(previous.feishuMessageId),
1995
+ reason: previous.finalizing ? 'same_recovery_terminal_retry' : 'existing_active_card' });
1982
1996
  if (previous.recoveryId !== info.recoveryId) {
1983
1997
  await previous.updateInFlight;
1984
1998
  if (!isCurrent() || this.streamingMessages.get(messageId) !== previous || previous.finalizing)
@@ -2022,9 +2036,12 @@ class RouterServer {
2022
2036
  + `Output before this card, including output during disconnection, was not retained.\n\n`
2023
2037
  + `**Thread:** <raw>${escape(info.threadName)}</raw> · **Backend:** <raw>${escape(info.backend)}</raw>\n`
2024
2038
  + `**Working directory:** <raw>${escape(info.cwd)}</raw>\n**Task:** <raw>${escape(info.preview)}</raw>`;
2025
- const cardId = await this.feishuLongConnHandler.sendStreamingStart(openId, intro, info.threadName, info.cwd);
2039
+ const cardId = await this.feishuLongConnHandler.sendStreamingStart(openId, intro, info.threadName, info.cwd, messageId);
2026
2040
  if (!cardId || !isCurrent())
2027
2041
  return false;
2042
+ this.feishuLongConnHandler.bindDiagnosticTask?.(cardId, messageId);
2043
+ (0, DeliveryDiagnostics_1.deliveryEvent)('resume_card_created', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(messageId), card: (0, DeliveryDiagnostics_1.taskCorrelation)(cardId),
2044
+ reason: previous?.finalizing ? 'previous_card_finalizing' : previous ? 'previous_card_missing' : 'no_previous_stream' });
2028
2045
  if (previous)
2029
2046
  this.clearDelegationProgressTimers(previous);
2030
2047
  this.streamingMessages.set(messageId, {
@@ -2078,10 +2095,12 @@ class RouterServer {
2078
2095
  **Remaining in queue:** ${info.remainingCount}`;
2079
2096
  let cardId = null;
2080
2097
  try {
2081
- cardId = await this.feishuLongConnHandler.sendStreamingStart(openId, intro, info.threadName, info.cwd);
2098
+ cardId = await this.feishuLongConnHandler.sendStreamingStart(openId, intro, info.threadName, info.cwd, messageId);
2099
+ if (cardId)
2100
+ this.feishuLongConnHandler.bindDiagnosticTask?.(cardId, messageId);
2082
2101
  }
2083
2102
  catch (error) {
2084
- console.error('[RouterServer] Failed to create queued execution card:', error);
2103
+ (0, DeliveryDiagnostics_1.deliveryEvent)('queued_card_create_failed', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(messageId), ...(0, DeliveryDiagnostics_1.safeCardError)(error) });
2085
2104
  }
2086
2105
  if (!isCurrent() || (imageRoute && this.imageReplies.get(messageId) !== imageRoute))
2087
2106
  return;
@@ -2127,7 +2146,7 @@ class RouterServer {
2127
2146
  }
2128
2147
  catch (error) {
2129
2148
  // The new execution card remains usable if its old receipt expired.
2130
- console.error('[RouterServer] Failed to update queue receipt:', error);
2149
+ (0, DeliveryDiagnostics_1.deliveryEvent)('queue_receipt_failed', (0, DeliveryDiagnostics_1.safeCardError)(error));
2131
2150
  }
2132
2151
  }
2133
2152
  }
@@ -2197,90 +2216,99 @@ class RouterServer {
2197
2216
  const streamData = this.streamingMessages.get(messageId);
2198
2217
  if (!streamData)
2199
2218
  return;
2200
- const route = this.imageReplies.get(messageId);
2201
- if (route)
2202
- this.images.close(route.reply);
2203
- this.closeImageIntake(streamData, route?.reply.deadline);
2204
- // Snapshot accepted work before awaiting; intake is already closed.
2205
- const accepted = route?.reply.tail;
2206
- if (accepted)
2207
- await accepted;
2208
- if (this.streamingMessages.get(messageId) !== streamData
2209
- || (route && (this.imageReplies.get(messageId) !== route || !route.current())))
2210
- return;
2211
- if (route?.reply.failed)
2212
- this.noteImageFailure(messageId, streamData);
2213
- this.cancelImageReply(messageId);
2214
- streamData.finalizing = true;
2215
- streamData.updatePending = false;
2216
- this.clearDelegationProgressTimers(streamData);
2217
- await streamData.updateInFlight;
2218
- if (!await this.canDispatchStreamOutput(messageId, streamData))
2219
- return;
2220
- const { feishuMessageId, openId } = streamData;
2221
- if (feishuMessageId) {
2222
- // Flush any remaining text content
2223
- if (streamData.currentTextContent.trim()) {
2224
- streamData.elements.push(...this.renderCurrentText(streamData));
2225
- streamData.currentTextContent = '';
2226
- streamData.recoveryPlainText = false;
2227
- }
2228
- // If there are no elements at all, use the output parameter as fallback
2229
- if (streamData.elements.length === 0 && output) {
2230
- streamData.elements.push((0, ToolFormatter_1.createMarkdownElement)(output));
2231
- }
2232
- // A capable CLI's settings menu replaces the placeholder with a dedicated
2233
- // interactive card bound to the original user/device/thread/request. The
2234
- // text output is for incapable peers or delivery failure only: including
2235
- // its complete catalog here would defeat pagination and its node/byte budget.
2236
- const prepared = settingsMenu && success
2237
- ? this.settingsCards.present({ openId: streamData.openId, deviceId: streamData.deviceId, menu: settingsMenu, requestMessageId: messageId, expectedThreadId: streamData.threadId })
2238
- : undefined;
2239
- if (prepared) {
2240
- const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, prepared.elements, undefined, openId, cwd, streamData.threadName, undefined, streamData.threadId, undefined, undefined, true, { bare: true, onDelivered: cardIds => prepared.deliver(cardIds) });
2241
- if (!finalized) {
2242
- prepared.discard();
2243
- if (!await this.canDispatchStreamOutput(messageId, streamData))
2244
- return;
2245
- const delivered = await this.feishuLongConnHandler.sendMessage(openId, output || '⚙️ Settings are unavailable as a card. Use the text command.');
2246
- if (delivered === false)
2247
- throw new Error('Failed to deliver settings result');
2219
+ const task = (0, DeliveryDiagnostics_1.taskCorrelation)(messageId);
2220
+ (0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_started', { task, card: (0, DeliveryDiagnostics_1.taskCorrelation)(streamData.feishuMessageId) });
2221
+ try {
2222
+ const route = this.imageReplies.get(messageId);
2223
+ if (route)
2224
+ this.images.close(route.reply);
2225
+ this.closeImageIntake(streamData, route?.reply.deadline);
2226
+ // Snapshot accepted work before awaiting; intake is already closed.
2227
+ const accepted = route?.reply.tail;
2228
+ if (accepted)
2229
+ await accepted;
2230
+ if (this.streamingMessages.get(messageId) !== streamData
2231
+ || (route && (this.imageReplies.get(messageId) !== route || !route.current())))
2232
+ return;
2233
+ if (route?.reply.failed)
2234
+ this.noteImageFailure(messageId, streamData);
2235
+ this.cancelImageReply(messageId);
2236
+ streamData.finalizing = true;
2237
+ streamData.updatePending = false;
2238
+ this.clearDelegationProgressTimers(streamData);
2239
+ await streamData.updateInFlight;
2240
+ if (!await this.canDispatchStreamOutput(messageId, streamData))
2241
+ return;
2242
+ const { feishuMessageId, openId } = streamData;
2243
+ if (feishuMessageId) {
2244
+ // Flush any remaining text content
2245
+ if (streamData.currentTextContent.trim()) {
2246
+ streamData.elements.push(...this.renderCurrentText(streamData));
2247
+ streamData.currentTextContent = '';
2248
+ streamData.recoveryPlainText = false;
2249
+ }
2250
+ // If there are no elements at all, use the output parameter as fallback
2251
+ if (streamData.elements.length === 0 && output) {
2252
+ streamData.elements.push((0, ToolFormatter_1.createMarkdownElement)(output));
2253
+ }
2254
+ // A capable CLI's settings menu replaces the placeholder with a dedicated
2255
+ // interactive card bound to the original user/device/thread/request. The
2256
+ // text output is for incapable peers or delivery failure only: including
2257
+ // its complete catalog here would defeat pagination and its node/byte budget.
2258
+ const prepared = settingsMenu && success
2259
+ ? this.settingsCards.present({ openId: streamData.openId, deviceId: streamData.deviceId, menu: settingsMenu, requestMessageId: messageId, expectedThreadId: streamData.threadId })
2260
+ : undefined;
2261
+ if (prepared) {
2262
+ const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, prepared.elements, undefined, openId, cwd, streamData.threadName, undefined, streamData.threadId, undefined, undefined, true, { bare: true, onDelivered: cardIds => prepared.deliver(cardIds) });
2263
+ if (!finalized) {
2264
+ prepared.discard();
2265
+ if (!await this.canDispatchStreamOutput(messageId, streamData))
2266
+ return;
2267
+ const delivered = await this.feishuLongConnHandler.sendMessage(openId, output || '⚙️ Settings are unavailable as a card. Use the text command.');
2268
+ if (delivered === false)
2269
+ throw new Error('Failed to deliver settings result');
2270
+ }
2271
+ }
2272
+ else if (success) {
2273
+ const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, streamData.elements, sessionAbbr, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, true, { onDelivered: cardIds => this.registerDeliveredThreadCards(messageId, streamData, cardIds) });
2274
+ if (finalized === false)
2275
+ throw new Error('Failed to finalize task card');
2276
+ }
2277
+ else {
2278
+ // Add error message to elements
2279
+ const finalElements = [...streamData.elements];
2280
+ if (!queueConfirmation) {
2281
+ const errorMsg = error || 'Command failed';
2282
+ finalElements.push((0, ToolFormatter_1.createMarkdownElement)(`\n\n❌ **Error:** ${errorMsg}`));
2283
+ }
2284
+ const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, false, { onDelivered: cardIds => this.registerDeliveredThreadCards(messageId, streamData, cardIds) });
2285
+ if (finalized === false)
2286
+ throw new Error('Failed to finalize task card');
2248
2287
  }
2249
2288
  }
2250
- else if (success) {
2251
- const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, streamData.elements, sessionAbbr, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, true, { onDelivered: cardIds => this.registerDeliveredThreadCards(messageId, streamData, cardIds) });
2252
- if (finalized === false)
2253
- throw new Error('Failed to finalize task card');
2289
+ else if (streamData.queueStarted) {
2290
+ // If card creation failed after session recovery, retain a text result
2291
+ // rather than silently losing the completed queued task's output.
2292
+ const text = streamData.elements
2293
+ .filter((element) => element.tag === 'markdown')
2294
+ .map((element) => element.content)
2295
+ .concat(streamData.currentTextContent, output || '')
2296
+ .filter(Boolean)
2297
+ .join('\n\n');
2298
+ const delivered = await this.feishuLongConnHandler.sendMessage(openId, `${text}\n\n${success ? '✅ Completed' : `❌ Error: ${error || 'Command failed'}`}`);
2299
+ if (delivered === false)
2300
+ throw new Error('Failed to deliver task result');
2254
2301
  }
2255
- else {
2256
- // Add error message to elements
2257
- const finalElements = [...streamData.elements];
2258
- if (!queueConfirmation) {
2259
- const errorMsg = error || 'Command failed';
2260
- finalElements.push((0, ToolFormatter_1.createMarkdownElement)(`\n\n❌ **Error:** ${errorMsg}`));
2261
- }
2262
- const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, false, { onDelivered: cardIds => this.registerDeliveredThreadCards(messageId, streamData, cardIds) });
2263
- if (finalized === false)
2264
- throw new Error('Failed to finalize task card');
2302
+ (0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_complete', { task });
2303
+ // Keep durable card associations after removing the completed streaming session.
2304
+ if (this.streamingMessages.get(messageId) === streamData) {
2305
+ this.streamingMessages.delete(messageId);
2306
+ this.lastStreamUpdateTime.delete(messageId);
2265
2307
  }
2266
2308
  }
2267
- else if (streamData.queueStarted) {
2268
- // If card creation failed after session recovery, retain a text result
2269
- // rather than silently losing the completed queued task's output.
2270
- const text = streamData.elements
2271
- .filter((element) => element.tag === 'markdown')
2272
- .map((element) => element.content)
2273
- .concat(streamData.currentTextContent, output || '')
2274
- .filter(Boolean)
2275
- .join('\n\n');
2276
- const delivered = await this.feishuLongConnHandler.sendMessage(openId, `${text}\n\n${success ? '✅ Completed' : `❌ Error: ${error || 'Command failed'}`}`);
2277
- if (delivered === false)
2278
- throw new Error('Failed to deliver task result');
2279
- }
2280
- // Keep durable card associations after removing the completed streaming session.
2281
- if (this.streamingMessages.get(messageId) === streamData) {
2282
- this.streamingMessages.delete(messageId);
2283
- this.lastStreamUpdateTime.delete(messageId);
2309
+ catch (failure) {
2310
+ (0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_failed', { task, ...(0, DeliveryDiagnostics_1.safeCardError)(failure) });
2311
+ throw failure;
2284
2312
  }
2285
2313
  }
2286
2314
  removeActiveCardRoutes(session) {
@@ -2353,7 +2381,7 @@ class RouterServer {
2353
2381
  if (failed?.status === 'rejected')
2354
2382
  throw failed.reason;
2355
2383
  if (cleanedCount > 0) {
2356
- console.log(`[RouterServer] Cleaned up ${cleanedCount} streaming sessions for device ${deviceId}, remaining: ${this.streamingMessages.size}`);
2384
+ (0, DeliveryDiagnostics_1.deliveryEvent)('disconnected_streams_cleaned', { count: cleanedCount, remaining: this.streamingMessages.size });
2357
2385
  }
2358
2386
  }
2359
2387
  /**
@@ -2409,7 +2437,7 @@ class RouterServer {
2409
2437
  catch (error) {
2410
2438
  failed = true;
2411
2439
  firstError ??= error;
2412
- console.error(`[RouterServer] Failed to finalize streaming card ${messageId} during shutdown:`, error);
2440
+ (0, DeliveryDiagnostics_1.deliveryEvent)('shutdown_card_finalize_failed', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(messageId), ...(0, DeliveryDiagnostics_1.safeCardError)(error) });
2413
2441
  }
2414
2442
  }
2415
2443
  this.streamingMessages.clear();