@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/README.md +4 -3
- package/dist/feishu/FeishuLongConnHandler.d.ts +3 -1
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +49 -47
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +122 -94
- package/dist/server.js.map +1 -1
- package/dist/utils/DeliveryDiagnostics.d.ts +46 -0
- package/dist/utils/DeliveryDiagnostics.d.ts.map +1 -0
- package/dist/utils/DeliveryDiagnostics.js +322 -0
- package/dist/utils/DeliveryDiagnostics.js.map +1 -0
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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 =>
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
streamData.
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
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 (
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
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
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
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
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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();
|