@yu_robotics/remote-cli-router 1.6.231 → 1.6.232
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.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +1 -0
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +59 -7
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -632,6 +632,7 @@ class RouterServer {
|
|
|
632
632
|
let deviceId = null;
|
|
633
633
|
let socketClosed = false;
|
|
634
634
|
let taskRecoveryEnabled = false;
|
|
635
|
+
let scheduleResultsEnabled = false;
|
|
635
636
|
let approvalCardsEnabled = false;
|
|
636
637
|
let delegationProgressEnabled = false;
|
|
637
638
|
let delegationProgressTextEnabled = false;
|
|
@@ -784,6 +785,9 @@ class RouterServer {
|
|
|
784
785
|
'task_resume', 'stream', 'stream_context', 'queue_started'].includes(message.type)
|
|
785
786
|
&& !await this.authorizeRecipientOutput(message, imageDevice, imageCurrent))
|
|
786
787
|
return;
|
|
788
|
+
if (message.queueStarted?.source !== undefined
|
|
789
|
+
&& (!scheduleResultsEnabled || !this.validScheduledResult(message)))
|
|
790
|
+
return;
|
|
787
791
|
// Establish routing before card creation awaits. Payload admission and
|
|
788
792
|
// response closure must occur before waiting for earlier operations.
|
|
789
793
|
if (imageDevice && taskRecoveryEnabled && message.type === 'task_resume') {
|
|
@@ -995,6 +999,8 @@ class RouterServer {
|
|
|
995
999
|
this.connectionHub.setFileSession(deviceId, { id: (0, crypto_1.randomUUID)(), openId: authenticatedOwner });
|
|
996
1000
|
this.fileTransfers.disconnect(deviceId);
|
|
997
1001
|
taskRecoveryEnabled = message.data.capabilities?.taskRecovery === true;
|
|
1002
|
+
scheduleResultsEnabled = taskRecoveryEnabled && message.data.capabilities?.queueStarted === true
|
|
1003
|
+
&& message.data.capabilities?.scheduleResultsV1 === true;
|
|
998
1004
|
approvalCardsEnabled = message.data.capabilities?.approvalCards === true;
|
|
999
1005
|
updateNoticeEnabled = message.data.capabilities?.updateNotice === true;
|
|
1000
1006
|
subscriptionInspectionEnabled = message.data.capabilities?.subscriptionInspection === true;
|
|
@@ -1043,6 +1049,7 @@ class RouterServer {
|
|
|
1043
1049
|
...(message.data.capabilities?.pendingOutputFilesV1 === true ? { pendingOutputFilesV1: true } : {}),
|
|
1044
1050
|
...(outputsEnabled ? { outputFilesV1: true } : {}),
|
|
1045
1051
|
...(taskRecoveryEnabled ? { taskRecovery: true } : {}),
|
|
1052
|
+
...(scheduleResultsEnabled ? { scheduleResultsV1: true } : {}),
|
|
1046
1053
|
...(approvalCardsEnabled ? { approvalCards: true } : {}),
|
|
1047
1054
|
...(delegationProgressEnabled ? { delegationProgress: true } : {}),
|
|
1048
1055
|
...(delegationProgressTextEnabled ? { delegationProgressText: true } : {}),
|
|
@@ -1072,6 +1079,19 @@ class RouterServer {
|
|
|
1072
1079
|
break;
|
|
1073
1080
|
case types_1.MessageType.RESPONSE:
|
|
1074
1081
|
(0, DeliveryDiagnostics_1.deliveryEvent)('task_result_received', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch });
|
|
1082
|
+
const scheduledSession = this.streamingMessages.get(message.messageId);
|
|
1083
|
+
if (scheduledSession?.queueStarted?.source === 'schedule') {
|
|
1084
|
+
if (!scheduleResultsEnabled || message.threadId !== scheduledSession.threadId
|
|
1085
|
+
|| message.cwd !== scheduledSession.cwd || message.queueConfirmation || message.data?.queueConfirmation
|
|
1086
|
+
|| (message.queueStarted && (message.queueStarted.scheduleId !== scheduledSession.queueStarted.scheduleId
|
|
1087
|
+
|| message.queueStarted.backend !== scheduledSession.queueStarted.backend)))
|
|
1088
|
+
break;
|
|
1089
|
+
}
|
|
1090
|
+
else if (message.queueStarted?.source === 'schedule'
|
|
1091
|
+
&& !(deviceId && this.isCompletedTask(message.messageId, deviceId))) {
|
|
1092
|
+
// A rejected/missing start must not fall through to an unthreaded plain response.
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1075
1095
|
if (taskRecoveryEnabled && deviceId && this.isCompletedTask(message.messageId, deviceId)) {
|
|
1076
1096
|
ws.send(JSON.stringify({ type: 'task_result_ack', messageId: message.messageId, timestamp: Date.now() }));
|
|
1077
1097
|
(0, DeliveryDiagnostics_1.deliveryEvent)('result_ack_send', { task: (0, DeliveryDiagnostics_1.taskCorrelation)(message.messageId), connectionEpoch, acceptedLocally: true, duplicate: true });
|
|
@@ -1146,7 +1166,9 @@ class RouterServer {
|
|
|
1146
1166
|
if (responseMessageId && responseOpenId) {
|
|
1147
1167
|
// Check if this was a streaming message (stream chunks were sent)
|
|
1148
1168
|
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);
|
|
1169
|
+
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);
|
|
1170
|
+
if (scheduledSession?.queueStarted?.source === 'schedule' && !delivered)
|
|
1171
|
+
break;
|
|
1150
1172
|
}
|
|
1151
1173
|
else {
|
|
1152
1174
|
// No streaming session found - session should have been created when command was sent
|
|
@@ -2309,6 +2331,18 @@ class RouterServer {
|
|
|
2309
2331
|
}
|
|
2310
2332
|
return true;
|
|
2311
2333
|
}
|
|
2334
|
+
/** Validate the additive scheduled-result envelope without changing ordinary queue metadata. */
|
|
2335
|
+
validScheduledResult(message) {
|
|
2336
|
+
const info = message.queueStarted;
|
|
2337
|
+
const bounded = (value, maximum, empty = false) => typeof value === 'string'
|
|
2338
|
+
&& (empty || value.length > 0) && value.length <= maximum;
|
|
2339
|
+
return (message.type === 'queue_started' || message.type === types_1.MessageType.RESPONSE)
|
|
2340
|
+
&& info?.source === 'schedule' && bounded(info.scheduleId, 256)
|
|
2341
|
+
&& bounded(message.messageId, 256) && bounded(message.openId, 256) && bounded(message.threadId, 256)
|
|
2342
|
+
&& (info.backend === 'claude' || info.backend === 'dsh') && bounded(info.threadName, 100, true) && bounded(info.cwd, 4096)
|
|
2343
|
+
&& bounded(info.preview, 240, true) && info.remainingCount === 0
|
|
2344
|
+
&& message.cwd === info.cwd;
|
|
2345
|
+
}
|
|
2312
2346
|
/** Create a fresh card before accepting any output for a dequeued task. */
|
|
2313
2347
|
async handleQueueStarted(message, deviceId, isCurrent = () => true) {
|
|
2314
2348
|
const info = message.queueStarted;
|
|
@@ -2319,6 +2353,8 @@ class RouterServer {
|
|
|
2319
2353
|
|| typeof info.cwd !== 'string' || typeof info.preview !== 'string'
|
|
2320
2354
|
|| !Number.isInteger(info.remainingCount) || info.remainingCount < 0)
|
|
2321
2355
|
return;
|
|
2356
|
+
if (info.source === 'schedule' && this.isCompletedTask(messageId, deviceId))
|
|
2357
|
+
return;
|
|
2322
2358
|
const selectionFence = this.selections.capture(openId, deviceId);
|
|
2323
2359
|
const previous = this.streamingMessages.get(messageId);
|
|
2324
2360
|
if (previous && (previous.deviceId !== deviceId || previous.openId !== openId
|
|
@@ -2327,13 +2363,18 @@ class RouterServer {
|
|
|
2327
2363
|
const pending = this.queueMessageOperations.get(messageId);
|
|
2328
2364
|
if (pending)
|
|
2329
2365
|
return pending;
|
|
2330
|
-
|
|
2366
|
+
// Disconnect cleanup removes unfinished sessions. A persisted schedule outbox
|
|
2367
|
+
// may recreate those cards; completed results are fenced by the receipt cache above.
|
|
2368
|
+
if (this.startedQueueMessages.has(messageId) && (info.source !== 'schedule' || previous?.feishuMessageId))
|
|
2331
2369
|
return;
|
|
2332
2370
|
this.startedQueueMessages.set(messageId, Date.now());
|
|
2333
2371
|
this.cancelImageReply(messageId);
|
|
2334
2372
|
const imageRoute = this.prepareImageReply(messageId, openId, deviceId, isCurrent, threadId, true);
|
|
2335
2373
|
const operation = Promise.resolve().then(async () => {
|
|
2336
|
-
const
|
|
2374
|
+
const escape = (value) => value.replace(/[\\`*_{}\[\]()<>!#|]/g, '\\$&');
|
|
2375
|
+
const intro = info.source === 'schedule'
|
|
2376
|
+
? `🕒 **Scheduled task result**\n\n**Thread:** ${escape(info.threadName)} · **Backend:** ${info.backend}\n**Working directory:** ${escape(info.cwd)}\n**Task:** ${escape(info.preview)}`
|
|
2377
|
+
: `▶️ **Queued task started**
|
|
2337
2378
|
|
|
2338
2379
|
**Thread:** ${info.threadName} · **Backend:** ${info.backend}
|
|
2339
2380
|
**Working directory:** \`${info.cwd}\`
|
|
@@ -2466,7 +2507,7 @@ class RouterServer {
|
|
|
2466
2507
|
async finalizeStreamingMessage(messageId, success, output, error, sessionAbbr, cwd, queueConfirmation, executionMetadata, settingsMenu) {
|
|
2467
2508
|
const streamData = this.streamingMessages.get(messageId);
|
|
2468
2509
|
if (!streamData)
|
|
2469
|
-
return;
|
|
2510
|
+
return false;
|
|
2470
2511
|
const task = (0, DeliveryDiagnostics_1.taskCorrelation)(messageId);
|
|
2471
2512
|
(0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_started', { task, card: (0, DeliveryDiagnostics_1.taskCorrelation)(streamData.feishuMessageId) });
|
|
2472
2513
|
try {
|
|
@@ -2480,7 +2521,7 @@ class RouterServer {
|
|
|
2480
2521
|
await accepted;
|
|
2481
2522
|
if (this.streamingMessages.get(messageId) !== streamData
|
|
2482
2523
|
|| (route && (this.imageReplies.get(messageId) !== route || !route.current())))
|
|
2483
|
-
return;
|
|
2524
|
+
return false;
|
|
2484
2525
|
if (route?.reply.failed)
|
|
2485
2526
|
this.noteImageFailure(messageId, streamData);
|
|
2486
2527
|
this.cancelImageReply(messageId);
|
|
@@ -2489,10 +2530,15 @@ class RouterServer {
|
|
|
2489
2530
|
this.clearDelegationProgressTimers(streamData);
|
|
2490
2531
|
await streamData.updateInFlight;
|
|
2491
2532
|
if (!await this.canDispatchStreamOutput(messageId, streamData))
|
|
2492
|
-
return;
|
|
2533
|
+
return false;
|
|
2493
2534
|
await this.admitInlineParent(messageId).catch(() => { });
|
|
2494
2535
|
const { feishuMessageId, openId } = streamData;
|
|
2495
2536
|
if (feishuMessageId) {
|
|
2537
|
+
if (streamData.queueStarted?.source === 'schedule') {
|
|
2538
|
+
// Scheduled results have no live stream. Replace the body on retry after a failed PATCH.
|
|
2539
|
+
streamData.elements = streamData.elements.slice(0, 1);
|
|
2540
|
+
streamData.currentTextContent = output || '';
|
|
2541
|
+
}
|
|
2496
2542
|
// Flush any remaining text content
|
|
2497
2543
|
if (streamData.currentTextContent.trim()) {
|
|
2498
2544
|
streamData.elements.push(...this.renderCurrentText(streamData));
|
|
@@ -2515,7 +2561,7 @@ class RouterServer {
|
|
|
2515
2561
|
if (!finalized) {
|
|
2516
2562
|
prepared.discard();
|
|
2517
2563
|
if (!await this.canDispatchStreamOutput(messageId, streamData))
|
|
2518
|
-
return;
|
|
2564
|
+
return false;
|
|
2519
2565
|
const delivered = await this.feishuLongConnHandler.sendMessage(openId, output || '⚙️ Settings are unavailable as a card. Use the text command.');
|
|
2520
2566
|
if (delivered === false)
|
|
2521
2567
|
throw new Error('Failed to deliver settings result');
|
|
@@ -2539,6 +2585,11 @@ class RouterServer {
|
|
|
2539
2585
|
}
|
|
2540
2586
|
}
|
|
2541
2587
|
else if (streamData.queueStarted) {
|
|
2588
|
+
if (streamData.queueStarted.source === 'schedule') {
|
|
2589
|
+
// An unthreaded plain message would lose the original reply route.
|
|
2590
|
+
// Leave this occurrence in the CLI outbox for a fresh card attempt.
|
|
2591
|
+
throw new Error('Scheduled result card is unavailable');
|
|
2592
|
+
}
|
|
2542
2593
|
// If card creation failed after session recovery, retain a text result
|
|
2543
2594
|
// rather than silently losing the completed queued task's output.
|
|
2544
2595
|
const text = streamData.elements
|
|
@@ -2557,6 +2608,7 @@ class RouterServer {
|
|
|
2557
2608
|
this.streamingMessages.delete(messageId);
|
|
2558
2609
|
this.lastStreamUpdateTime.delete(messageId);
|
|
2559
2610
|
}
|
|
2611
|
+
return true;
|
|
2560
2612
|
}
|
|
2561
2613
|
catch (failure) {
|
|
2562
2614
|
(0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_failed', { task, ...(0, DeliveryDiagnostics_1.safeCardError)(failure) });
|