@yu_robotics/remote-cli-router 1.6.231 → 1.6.234
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/feishu/FeishuLongConnHandler.d.ts +3 -0
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +23 -0
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/feishu/ScheduleCards.d.ts +42 -0
- package/dist/feishu/ScheduleCards.d.ts.map +1 -0
- package/dist/feishu/ScheduleCards.js +253 -0
- package/dist/feishu/ScheduleCards.js.map +1 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +171 -12
- package/dist/server.js.map +1 -1
- package/dist/types/ScheduleCards.d.ts +56 -0
- package/dist/types/ScheduleCards.d.ts.map +1 -0
- package/dist/types/ScheduleCards.js +3 -0
- package/dist/types/ScheduleCards.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- 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 ScheduleCards_1 = require("./feishu/ScheduleCards");
|
|
7
8
|
const Protocol_1 = require("./output/Protocol");
|
|
8
9
|
const InlineFileCards_1 = require("./output/InlineFileCards");
|
|
9
10
|
const OutputTransfers_1 = require("./output/OutputTransfers");
|
|
@@ -64,6 +65,9 @@ class RouterServer {
|
|
|
64
65
|
workerContextCards;
|
|
65
66
|
workerContextConnections = new Map();
|
|
66
67
|
settingsCards;
|
|
68
|
+
scheduleCards;
|
|
69
|
+
scheduleToolDeliveries = new Map();
|
|
70
|
+
scheduleCardConnections = new Map();
|
|
67
71
|
settingsConnections = new Map();
|
|
68
72
|
maintenanceCards;
|
|
69
73
|
tips;
|
|
@@ -296,6 +300,13 @@ class RouterServer {
|
|
|
296
300
|
update: (cardId, elements, header) => this.feishuLongConnHandler.updateApprovalCard(cardId, elements, header),
|
|
297
301
|
});
|
|
298
302
|
this.feishuLongConnHandler.settingsCards = this.settingsCards;
|
|
303
|
+
this.scheduleCards = new ScheduleCards_1.ScheduleCards({
|
|
304
|
+
ownsDevice: async (openId, deviceId) => (await this.bindingManager.getDeviceBinding(deviceId))?.openId === openId,
|
|
305
|
+
available: deviceId => this.scheduleCardConnections.get(deviceId)?.() === true,
|
|
306
|
+
send: (deviceId, message) => this.connectionHub.sendToDevice(deviceId, message),
|
|
307
|
+
update: (cardId, elements) => this.feishuLongConnHandler.updateScheduleCard(cardId, elements),
|
|
308
|
+
});
|
|
309
|
+
this.feishuLongConnHandler.scheduleCards = this.scheduleCards;
|
|
299
310
|
this.maintenanceCards = new MaintenanceCards_1.MaintenanceCards(new NoticeReceipts_1.NoticeReceipts(path_1.default.join(path_1.default.dirname(config.getConfigPath() || path_1.default.join(os_1.default.homedir(), '.remote-cli-router', 'config.json')), 'notice-receipts.json')), {
|
|
300
311
|
owner: async (deviceId) => (await this.bindingManager.getDeviceBinding(deviceId))?.openId,
|
|
301
312
|
send: (deviceId, message) => this.connectionHub.sendToDevice(deviceId, message),
|
|
@@ -632,6 +643,9 @@ class RouterServer {
|
|
|
632
643
|
let deviceId = null;
|
|
633
644
|
let socketClosed = false;
|
|
634
645
|
let taskRecoveryEnabled = false;
|
|
646
|
+
let scheduleResultsEnabled = false;
|
|
647
|
+
let scheduleCardsEnabled = false;
|
|
648
|
+
let scheduleToolCardsEnabled = false;
|
|
635
649
|
let approvalCardsEnabled = false;
|
|
636
650
|
let delegationProgressEnabled = false;
|
|
637
651
|
let delegationProgressTextEnabled = false;
|
|
@@ -761,6 +775,20 @@ class RouterServer {
|
|
|
761
775
|
await this.workerContextCards.resolve(deviceId, message);
|
|
762
776
|
return;
|
|
763
777
|
}
|
|
778
|
+
if (message.type === 'schedule_tool_card') {
|
|
779
|
+
if (!scheduleToolCardsEnabled || !deviceId)
|
|
780
|
+
return;
|
|
781
|
+
const current = () => !socketClosed && ws.readyState === ws_1.WebSocket.OPEN && this.connectionHub.isCurrentConnection(deviceId, ws);
|
|
782
|
+
const success = await this.deliverScheduleToolCard(deviceId, message, current);
|
|
783
|
+
if (current())
|
|
784
|
+
ws.send(JSON.stringify({ type: 'schedule_tool_card_ack', messageId: message.messageId, success, timestamp: Date.now() }));
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (message.type === 'schedule_action_result') {
|
|
788
|
+
if (scheduleCardsEnabled && deviceId)
|
|
789
|
+
await this.scheduleCards.resolve(deviceId, message);
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
764
792
|
if (message.type === 'settings_result') {
|
|
765
793
|
if (settingsCardsEnabled && deviceId && (message.menu?.kind !== 'delegation' || delegationCardsEnabled)
|
|
766
794
|
&& (message.menu?.kind !== 'directory' || directoryCardsEnabled))
|
|
@@ -784,6 +812,9 @@ class RouterServer {
|
|
|
784
812
|
'task_resume', 'stream', 'stream_context', 'queue_started'].includes(message.type)
|
|
785
813
|
&& !await this.authorizeRecipientOutput(message, imageDevice, imageCurrent))
|
|
786
814
|
return;
|
|
815
|
+
if (message.queueStarted?.source !== undefined
|
|
816
|
+
&& (!scheduleResultsEnabled || !this.validScheduledResult(message)))
|
|
817
|
+
return;
|
|
787
818
|
// Establish routing before card creation awaits. Payload admission and
|
|
788
819
|
// response closure must occur before waiting for earlier operations.
|
|
789
820
|
if (imageDevice && taskRecoveryEnabled && message.type === 'task_resume') {
|
|
@@ -961,6 +992,8 @@ class RouterServer {
|
|
|
961
992
|
this.approvalCards.disconnect(deviceId);
|
|
962
993
|
this.maintenanceCards.disconnect(deviceId);
|
|
963
994
|
this.settingsCards.disconnect(deviceId);
|
|
995
|
+
this.scheduleCards.disconnect(deviceId);
|
|
996
|
+
this.scheduleCardConnections.delete(deviceId);
|
|
964
997
|
if (!this.connectionHub.isCurrentConnection(deviceId, ws))
|
|
965
998
|
this.cancelThreadInventories(deviceId);
|
|
966
999
|
if (message.data.capabilities?.queueStarted === true) {
|
|
@@ -995,6 +1028,14 @@ class RouterServer {
|
|
|
995
1028
|
this.connectionHub.setFileSession(deviceId, { id: (0, crypto_1.randomUUID)(), openId: authenticatedOwner });
|
|
996
1029
|
this.fileTransfers.disconnect(deviceId);
|
|
997
1030
|
taskRecoveryEnabled = message.data.capabilities?.taskRecovery === true;
|
|
1031
|
+
scheduleResultsEnabled = taskRecoveryEnabled && message.data.capabilities?.queueStarted === true
|
|
1032
|
+
&& message.data.capabilities?.scheduleResultsV1 === true;
|
|
1033
|
+
scheduleCardsEnabled = scheduleResultsEnabled && message.data.capabilities?.scheduleCardsV1 === true;
|
|
1034
|
+
scheduleToolCardsEnabled = scheduleCardsEnabled && message.data.capabilities?.scheduleToolCardsV1 === true;
|
|
1035
|
+
if (scheduleCardsEnabled)
|
|
1036
|
+
this.scheduleCardConnections.set(deviceId, () => this.connectionHub.isCurrentConnection(deviceId, ws) && ws.readyState === ws_1.WebSocket.OPEN);
|
|
1037
|
+
else
|
|
1038
|
+
this.scheduleCardConnections.delete(deviceId);
|
|
998
1039
|
approvalCardsEnabled = message.data.capabilities?.approvalCards === true;
|
|
999
1040
|
updateNoticeEnabled = message.data.capabilities?.updateNotice === true;
|
|
1000
1041
|
subscriptionInspectionEnabled = message.data.capabilities?.subscriptionInspection === true;
|
|
@@ -1043,6 +1084,9 @@ class RouterServer {
|
|
|
1043
1084
|
...(message.data.capabilities?.pendingOutputFilesV1 === true ? { pendingOutputFilesV1: true } : {}),
|
|
1044
1085
|
...(outputsEnabled ? { outputFilesV1: true } : {}),
|
|
1045
1086
|
...(taskRecoveryEnabled ? { taskRecovery: true } : {}),
|
|
1087
|
+
...(scheduleResultsEnabled ? { scheduleResultsV1: true } : {}),
|
|
1088
|
+
...(scheduleCardsEnabled ? { scheduleCardsV1: true } : {}),
|
|
1089
|
+
...(scheduleToolCardsEnabled ? { scheduleToolCardsV1: true } : {}),
|
|
1046
1090
|
...(approvalCardsEnabled ? { approvalCards: true } : {}),
|
|
1047
1091
|
...(delegationProgressEnabled ? { delegationProgress: true } : {}),
|
|
1048
1092
|
...(delegationProgressTextEnabled ? { delegationProgressText: true } : {}),
|
|
@@ -1072,6 +1116,19 @@ class RouterServer {
|
|
|
1072
1116
|
break;
|
|
1073
1117
|
case types_1.MessageType.RESPONSE:
|
|
1074
1118
|
(0, DeliveryDiagnostics_1.deliveryEvent)('task_result_received', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch });
|
|
1119
|
+
const scheduledSession = this.streamingMessages.get(message.messageId);
|
|
1120
|
+
if (scheduledSession?.queueStarted?.source === 'schedule') {
|
|
1121
|
+
if (!scheduleResultsEnabled || message.threadId !== scheduledSession.threadId
|
|
1122
|
+
|| message.cwd !== scheduledSession.cwd || message.queueConfirmation || message.data?.queueConfirmation
|
|
1123
|
+
|| (message.queueStarted && (message.queueStarted.scheduleId !== scheduledSession.queueStarted.scheduleId
|
|
1124
|
+
|| message.queueStarted.backend !== scheduledSession.queueStarted.backend)))
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
else if (message.queueStarted?.source === 'schedule'
|
|
1128
|
+
&& !(deviceId && this.isCompletedTask(message.messageId, deviceId))) {
|
|
1129
|
+
// A rejected/missing start must not fall through to an unthreaded plain response.
|
|
1130
|
+
break;
|
|
1131
|
+
}
|
|
1075
1132
|
if (taskRecoveryEnabled && deviceId && this.isCompletedTask(message.messageId, deviceId)) {
|
|
1076
1133
|
ws.send(JSON.stringify({ type: 'task_result_ack', messageId: message.messageId, timestamp: Date.now() }));
|
|
1077
1134
|
(0, DeliveryDiagnostics_1.deliveryEvent)('result_ack_send', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch, acceptedLocally: true, duplicate: true });
|
|
@@ -1097,6 +1154,9 @@ class RouterServer {
|
|
|
1097
1154
|
const settingsMenu = (candidateSettingsMenu?.kind === 'delegation' && !delegationCardsEnabled)
|
|
1098
1155
|
|| (candidateSettingsMenu?.kind === 'directory' && !directoryCardsEnabled) ? undefined : candidateSettingsMenu;
|
|
1099
1156
|
const responseSession = responseMessageId ? this.streamingMessages.get(responseMessageId) : undefined;
|
|
1157
|
+
const scheduleMenu = scheduleCardsEnabled && !queueConfirmation && !responseSession?.queueStarted
|
|
1158
|
+
&& responseSession?.threadId === (message.scheduleMenu ?? message.data?.scheduleMenu)?.threadId
|
|
1159
|
+
? (message.scheduleMenu ?? message.data?.scheduleMenu) : undefined;
|
|
1100
1160
|
const responseSuccess = message.success ?? message.data?.success;
|
|
1101
1161
|
let selectionWarning;
|
|
1102
1162
|
if (responseSession) {
|
|
@@ -1146,7 +1206,9 @@ class RouterServer {
|
|
|
1146
1206
|
if (responseMessageId && responseOpenId) {
|
|
1147
1207
|
// Check if this was a streaming message (stream chunks were sent)
|
|
1148
1208
|
if (this.streamingMessages.has(responseMessageId)) {
|
|
1149
|
-
await this.finalizeStreamingMessage(responseMessageId, message.success ?? message.data?.success, message.output || message.data?.output, message.error || message.data?.error, sessionAbbr, cwd, queueConfirmation, executionMetadata, settingsMenu);
|
|
1209
|
+
const delivered = await this.finalizeStreamingMessage(responseMessageId, message.success ?? message.data?.success, message.output || message.data?.output, message.error || message.data?.error, sessionAbbr, cwd, queueConfirmation, executionMetadata, settingsMenu, scheduleMenu);
|
|
1210
|
+
if (scheduledSession?.queueStarted?.source === 'schedule' && !delivered)
|
|
1211
|
+
break;
|
|
1150
1212
|
}
|
|
1151
1213
|
else {
|
|
1152
1214
|
// No streaming session found - session should have been created when command was sent
|
|
@@ -1294,6 +1356,8 @@ class RouterServer {
|
|
|
1294
1356
|
this.approvalCards.disconnect(deviceId);
|
|
1295
1357
|
this.maintenanceCards.disconnect(deviceId);
|
|
1296
1358
|
this.settingsCards.disconnect(deviceId);
|
|
1359
|
+
this.scheduleCards.disconnect(deviceId);
|
|
1360
|
+
this.scheduleCardConnections.delete(deviceId);
|
|
1297
1361
|
this.settingsConnections.delete(deviceId);
|
|
1298
1362
|
this.maintenanceConnections.delete(deviceId);
|
|
1299
1363
|
this.workerContextConnections.delete(deviceId);
|
|
@@ -2309,6 +2373,18 @@ class RouterServer {
|
|
|
2309
2373
|
}
|
|
2310
2374
|
return true;
|
|
2311
2375
|
}
|
|
2376
|
+
/** Validate the additive scheduled-result envelope without changing ordinary queue metadata. */
|
|
2377
|
+
validScheduledResult(message) {
|
|
2378
|
+
const info = message.queueStarted;
|
|
2379
|
+
const bounded = (value, maximum, empty = false) => typeof value === 'string'
|
|
2380
|
+
&& (empty || value.length > 0) && value.length <= maximum;
|
|
2381
|
+
return (message.type === 'queue_started' || message.type === types_1.MessageType.RESPONSE)
|
|
2382
|
+
&& info?.source === 'schedule' && bounded(info.scheduleId, 256)
|
|
2383
|
+
&& bounded(message.messageId, 256) && bounded(message.openId, 256) && bounded(message.threadId, 256)
|
|
2384
|
+
&& (info.backend === 'claude' || info.backend === 'dsh') && bounded(info.threadName, 100, true) && bounded(info.cwd, 4096)
|
|
2385
|
+
&& bounded(info.preview, 240, true) && info.remainingCount === 0
|
|
2386
|
+
&& message.cwd === info.cwd;
|
|
2387
|
+
}
|
|
2312
2388
|
/** Create a fresh card before accepting any output for a dequeued task. */
|
|
2313
2389
|
async handleQueueStarted(message, deviceId, isCurrent = () => true) {
|
|
2314
2390
|
const info = message.queueStarted;
|
|
@@ -2319,6 +2395,8 @@ class RouterServer {
|
|
|
2319
2395
|
|| typeof info.cwd !== 'string' || typeof info.preview !== 'string'
|
|
2320
2396
|
|| !Number.isInteger(info.remainingCount) || info.remainingCount < 0)
|
|
2321
2397
|
return;
|
|
2398
|
+
if (info.source === 'schedule' && this.isCompletedTask(messageId, deviceId))
|
|
2399
|
+
return;
|
|
2322
2400
|
const selectionFence = this.selections.capture(openId, deviceId);
|
|
2323
2401
|
const previous = this.streamingMessages.get(messageId);
|
|
2324
2402
|
if (previous && (previous.deviceId !== deviceId || previous.openId !== openId
|
|
@@ -2327,13 +2405,18 @@ class RouterServer {
|
|
|
2327
2405
|
const pending = this.queueMessageOperations.get(messageId);
|
|
2328
2406
|
if (pending)
|
|
2329
2407
|
return pending;
|
|
2330
|
-
|
|
2408
|
+
// Disconnect cleanup removes unfinished sessions. A persisted schedule outbox
|
|
2409
|
+
// may recreate those cards; completed results are fenced by the receipt cache above.
|
|
2410
|
+
if (this.startedQueueMessages.has(messageId) && (info.source !== 'schedule' || previous?.feishuMessageId))
|
|
2331
2411
|
return;
|
|
2332
2412
|
this.startedQueueMessages.set(messageId, Date.now());
|
|
2333
2413
|
this.cancelImageReply(messageId);
|
|
2334
2414
|
const imageRoute = this.prepareImageReply(messageId, openId, deviceId, isCurrent, threadId, true);
|
|
2335
2415
|
const operation = Promise.resolve().then(async () => {
|
|
2336
|
-
const
|
|
2416
|
+
const escape = (value) => value.replace(/[\\`*_{}\[\]()<>!#|]/g, '\\$&');
|
|
2417
|
+
const intro = info.source === 'schedule'
|
|
2418
|
+
? `🕒 **Scheduled task result**\n\n**Thread:** ${escape(info.threadName)} · **Backend:** ${info.backend}\n**Working directory:** ${escape(info.cwd)}\n**Task:** ${escape(info.preview)}`
|
|
2419
|
+
: `▶️ **Queued task started**
|
|
2337
2420
|
|
|
2338
2421
|
**Thread:** ${info.threadName} · **Backend:** ${info.backend}
|
|
2339
2422
|
**Working directory:** \`${info.cwd}\`
|
|
@@ -2443,6 +2526,62 @@ class RouterServer {
|
|
|
2443
2526
|
return;
|
|
2444
2527
|
await this.inlineFileCards.admit(owner, replacePending);
|
|
2445
2528
|
}
|
|
2529
|
+
async deliverScheduleToolCard(deviceId, message, current) {
|
|
2530
|
+
const valid = (value) => typeof value === 'string' && value.length > 0 && value.length <= 256;
|
|
2531
|
+
if (![message.messageId, message.parentMessageId, message.openId, message.threadId].every(valid))
|
|
2532
|
+
return false;
|
|
2533
|
+
const key = `${deviceId}:${message.messageId}`;
|
|
2534
|
+
const digest = (0, crypto_1.createHash)('sha256').update(JSON.stringify(message)).digest('hex');
|
|
2535
|
+
const previous = this.scheduleToolDeliveries.get(key);
|
|
2536
|
+
if (previous)
|
|
2537
|
+
return previous.digest === digest ? previous.done : false;
|
|
2538
|
+
if (this.scheduleToolDeliveries.size >= 500) {
|
|
2539
|
+
const stale = [...this.scheduleToolDeliveries].find(([, receipt]) => receipt.settled);
|
|
2540
|
+
if (!stale)
|
|
2541
|
+
return false;
|
|
2542
|
+
this.scheduleToolDeliveries.delete(stale[0]);
|
|
2543
|
+
}
|
|
2544
|
+
// Capture the admitted foreground source before yielding. Finalizing its answer
|
|
2545
|
+
// may remove that stream while this separate management card is being sent.
|
|
2546
|
+
const parent = this.streamingMessages.get(message.parentMessageId);
|
|
2547
|
+
if (!parent || parent.deviceId !== deviceId || parent.openId !== message.openId || parent.threadId !== message.threadId)
|
|
2548
|
+
return false;
|
|
2549
|
+
const epoch = parent.selectionFence?.epoch ?? this.selections.capture(message.openId, deviceId).epoch;
|
|
2550
|
+
const owned = () => current() && this.selections.isOwnershipCurrent(message.openId, deviceId, epoch);
|
|
2551
|
+
const done = Promise.resolve().then(async () => {
|
|
2552
|
+
if (!owned() || (await this.bindingManager.getDeviceBinding(deviceId))?.openId !== message.openId || !owned())
|
|
2553
|
+
return false;
|
|
2554
|
+
const prepared = this.scheduleCards.present({ openId: message.openId, deviceId, menu: message.menu, expectedThreadId: message.threadId });
|
|
2555
|
+
if (!prepared)
|
|
2556
|
+
return false;
|
|
2557
|
+
try {
|
|
2558
|
+
const content = JSON.stringify({ schema: '2.0', body: { elements: prepared.elements } });
|
|
2559
|
+
if (Buffer.byteLength(content) > 16 * 1024)
|
|
2560
|
+
throw new Error('Schedule card exceeds its budget.');
|
|
2561
|
+
const cardId = await this.feishuLongConnHandler.createOutputCard(message.openId, content, (0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 32));
|
|
2562
|
+
if (!owned() || (await this.bindingManager.getDeviceBinding(deviceId))?.openId !== message.openId || !owned()) {
|
|
2563
|
+
prepared.discard();
|
|
2564
|
+
return false;
|
|
2565
|
+
}
|
|
2566
|
+
await this.registerCardThread(cardId, { openId: message.openId, deviceId, threadId: message.threadId,
|
|
2567
|
+
epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, owned);
|
|
2568
|
+
if (!owned()) {
|
|
2569
|
+
prepared.discard();
|
|
2570
|
+
return false;
|
|
2571
|
+
}
|
|
2572
|
+
prepared.deliver([cardId]);
|
|
2573
|
+
return true;
|
|
2574
|
+
}
|
|
2575
|
+
catch {
|
|
2576
|
+
prepared.discard();
|
|
2577
|
+
return false;
|
|
2578
|
+
}
|
|
2579
|
+
});
|
|
2580
|
+
const receipt = { digest, done, settled: false };
|
|
2581
|
+
this.scheduleToolDeliveries.set(key, receipt);
|
|
2582
|
+
void done.then(() => { receipt.settled = true; }, () => { receipt.settled = true; });
|
|
2583
|
+
return done;
|
|
2584
|
+
}
|
|
2446
2585
|
async registerDeliveredThreadCards(messageId, streamData, cardIds) {
|
|
2447
2586
|
if (!streamData.threadId || this.streamingMessages.get(messageId) !== streamData)
|
|
2448
2587
|
return;
|
|
@@ -2463,10 +2602,10 @@ class RouterServer {
|
|
|
2463
2602
|
openId: streamData.openId, epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, () => this.streamingMessages.get(messageId) === streamData && (!streamData.currentConnection || streamData.currentConnection()));
|
|
2464
2603
|
}
|
|
2465
2604
|
}
|
|
2466
|
-
async finalizeStreamingMessage(messageId, success, output, error, sessionAbbr, cwd, queueConfirmation, executionMetadata, settingsMenu) {
|
|
2605
|
+
async finalizeStreamingMessage(messageId, success, output, error, sessionAbbr, cwd, queueConfirmation, executionMetadata, settingsMenu, scheduleMenu) {
|
|
2467
2606
|
const streamData = this.streamingMessages.get(messageId);
|
|
2468
2607
|
if (!streamData)
|
|
2469
|
-
return;
|
|
2608
|
+
return false;
|
|
2470
2609
|
const task = (0, DeliveryDiagnostics_1.taskCorrelation)(messageId);
|
|
2471
2610
|
(0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_started', { task, card: (0, DeliveryDiagnostics_1.taskCorrelation)(streamData.feishuMessageId) });
|
|
2472
2611
|
try {
|
|
@@ -2480,7 +2619,7 @@ class RouterServer {
|
|
|
2480
2619
|
await accepted;
|
|
2481
2620
|
if (this.streamingMessages.get(messageId) !== streamData
|
|
2482
2621
|
|| (route && (this.imageReplies.get(messageId) !== route || !route.current())))
|
|
2483
|
-
return;
|
|
2622
|
+
return false;
|
|
2484
2623
|
if (route?.reply.failed)
|
|
2485
2624
|
this.noteImageFailure(messageId, streamData);
|
|
2486
2625
|
this.cancelImageReply(messageId);
|
|
@@ -2489,10 +2628,15 @@ class RouterServer {
|
|
|
2489
2628
|
this.clearDelegationProgressTimers(streamData);
|
|
2490
2629
|
await streamData.updateInFlight;
|
|
2491
2630
|
if (!await this.canDispatchStreamOutput(messageId, streamData))
|
|
2492
|
-
return;
|
|
2631
|
+
return false;
|
|
2493
2632
|
await this.admitInlineParent(messageId).catch(() => { });
|
|
2494
2633
|
const { feishuMessageId, openId } = streamData;
|
|
2495
2634
|
if (feishuMessageId) {
|
|
2635
|
+
if (streamData.queueStarted?.source === 'schedule') {
|
|
2636
|
+
// Scheduled results have no live stream. Replace the body on retry after a failed PATCH.
|
|
2637
|
+
streamData.elements = streamData.elements.slice(0, 1);
|
|
2638
|
+
streamData.currentTextContent = output || '';
|
|
2639
|
+
}
|
|
2496
2640
|
// Flush any remaining text content
|
|
2497
2641
|
if (streamData.currentTextContent.trim()) {
|
|
2498
2642
|
streamData.elements.push(...this.renderCurrentText(streamData));
|
|
@@ -2507,15 +2651,21 @@ class RouterServer {
|
|
|
2507
2651
|
// interactive card bound to the original user/device/thread/request. The
|
|
2508
2652
|
// text output is for incapable peers or delivery failure only: including
|
|
2509
2653
|
// its complete catalog here would defeat pagination and its node/byte budget.
|
|
2510
|
-
const prepared =
|
|
2511
|
-
? this.
|
|
2512
|
-
:
|
|
2654
|
+
const prepared = scheduleMenu && success
|
|
2655
|
+
? this.scheduleCards.present({ openId: streamData.openId, deviceId: streamData.deviceId, menu: scheduleMenu, expectedThreadId: streamData.threadId })
|
|
2656
|
+
: settingsMenu && success
|
|
2657
|
+
? this.settingsCards.present({ openId: streamData.openId, deviceId: streamData.deviceId, menu: settingsMenu, requestMessageId: messageId, expectedThreadId: streamData.threadId })
|
|
2658
|
+
: undefined;
|
|
2513
2659
|
if (prepared) {
|
|
2514
|
-
const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, prepared.elements, undefined, openId, cwd, streamData.threadName, undefined, streamData.threadId, undefined, undefined, true, { bare: true, onDelivered:
|
|
2660
|
+
const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, prepared.elements, undefined, openId, cwd, streamData.threadName, undefined, streamData.threadId, undefined, undefined, true, { bare: true, onDelivered: async (cardIds) => {
|
|
2661
|
+
prepared.deliver(cardIds);
|
|
2662
|
+
if (scheduleMenu)
|
|
2663
|
+
await this.registerDeliveredThreadCards(messageId, streamData, cardIds);
|
|
2664
|
+
} });
|
|
2515
2665
|
if (!finalized) {
|
|
2516
2666
|
prepared.discard();
|
|
2517
2667
|
if (!await this.canDispatchStreamOutput(messageId, streamData))
|
|
2518
|
-
return;
|
|
2668
|
+
return false;
|
|
2519
2669
|
const delivered = await this.feishuLongConnHandler.sendMessage(openId, output || '⚙️ Settings are unavailable as a card. Use the text command.');
|
|
2520
2670
|
if (delivered === false)
|
|
2521
2671
|
throw new Error('Failed to deliver settings result');
|
|
@@ -2539,6 +2689,11 @@ class RouterServer {
|
|
|
2539
2689
|
}
|
|
2540
2690
|
}
|
|
2541
2691
|
else if (streamData.queueStarted) {
|
|
2692
|
+
if (streamData.queueStarted.source === 'schedule') {
|
|
2693
|
+
// An unthreaded plain message would lose the original reply route.
|
|
2694
|
+
// Leave this occurrence in the CLI outbox for a fresh card attempt.
|
|
2695
|
+
throw new Error('Scheduled result card is unavailable');
|
|
2696
|
+
}
|
|
2542
2697
|
// If card creation failed after session recovery, retain a text result
|
|
2543
2698
|
// rather than silently losing the completed queued task's output.
|
|
2544
2699
|
const text = streamData.elements
|
|
@@ -2557,6 +2712,7 @@ class RouterServer {
|
|
|
2557
2712
|
this.streamingMessages.delete(messageId);
|
|
2558
2713
|
this.lastStreamUpdateTime.delete(messageId);
|
|
2559
2714
|
}
|
|
2715
|
+
return true;
|
|
2560
2716
|
}
|
|
2561
2717
|
catch (failure) {
|
|
2562
2718
|
(0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_failed', { task, ...(0, DeliveryDiagnostics_1.safeCardError)(failure) });
|
|
@@ -2671,6 +2827,9 @@ class RouterServer {
|
|
|
2671
2827
|
this.workerContextCards.destroy();
|
|
2672
2828
|
this.workerContextConnections.clear();
|
|
2673
2829
|
this.settingsCards.destroy();
|
|
2830
|
+
this.scheduleCards.destroy();
|
|
2831
|
+
this.scheduleToolDeliveries.clear();
|
|
2832
|
+
this.scheduleCardConnections.clear();
|
|
2674
2833
|
this.settingsConnections.clear();
|
|
2675
2834
|
this.maintenanceCards.destroy();
|
|
2676
2835
|
this.maintenanceConnections.clear();
|