@yu_robotics/remote-cli-router 1.6.271 → 1.6.273

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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/feishu/CommandMenu.d.ts.map +1 -1
  3. package/dist/feishu/CommandMenu.js +3 -4
  4. package/dist/feishu/CommandMenu.js.map +1 -1
  5. package/dist/feishu/FeishuLongConnHandler.d.ts +11 -6
  6. package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
  7. package/dist/feishu/FeishuLongConnHandler.js +149 -107
  8. package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
  9. package/dist/feishu/MachineCommandForm.d.ts +5 -12
  10. package/dist/feishu/MachineCommandForm.d.ts.map +1 -1
  11. package/dist/feishu/MachineCommandForm.js +2 -4
  12. package/dist/feishu/MachineCommandForm.js.map +1 -1
  13. package/dist/feishu/ScheduleCards.d.ts.map +1 -1
  14. package/dist/feishu/ScheduleCards.js +7 -4
  15. package/dist/feishu/ScheduleCards.js.map +1 -1
  16. package/dist/files/AutomaticFileEnrollment.d.ts +1 -0
  17. package/dist/files/AutomaticFileEnrollment.d.ts.map +1 -1
  18. package/dist/files/AutomaticFileEnrollment.js +20 -6
  19. package/dist/files/AutomaticFileEnrollment.js.map +1 -1
  20. package/dist/files/FileTransfers.d.ts.map +1 -1
  21. package/dist/files/FileTransfers.js +29 -10
  22. package/dist/files/FileTransfers.js.map +1 -1
  23. package/dist/server.d.ts.map +1 -1
  24. package/dist/server.js +69 -24
  25. package/dist/server.js.map +1 -1
  26. package/dist/storage/CardThreadState.d.ts +1 -0
  27. package/dist/storage/CardThreadState.d.ts.map +1 -1
  28. package/dist/storage/CardThreadState.js +6 -3
  29. package/dist/storage/CardThreadState.js.map +1 -1
  30. package/dist/tips/TipCatalog.js +2 -2
  31. package/dist/tips/assets/abort-consequences.png +0 -0
  32. package/dist/tips/assets/clear-thread-context.png +0 -0
  33. package/dist/tips/assets/command-menu-navigation.png +0 -0
  34. package/dist/tips/assets/reply-in-original-thread.png +0 -0
  35. package/dist/tips/assets/schedule-in-original-thread.png +0 -0
  36. package/dist/tips/catalog.zh-CN.json +93 -24
  37. package/dist/tips/ui.zh-CN.json +22 -2
  38. package/dist/websocket/ConnectionHub.js +2 -1
  39. package/dist/websocket/ConnectionHub.js.map +1 -1
  40. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -330,6 +330,16 @@ class RouterServer {
330
330
  })
331
331
  : this.maintenanceCards.reply(openId, id, cardId, action);
332
332
  // Register callback for streaming message start
333
+ this.feishuLongConnHandler.onCommandNotSent = async (messageId) => {
334
+ const session = this.streamingMessages.get(messageId);
335
+ if (!session)
336
+ return;
337
+ this.streamingMessages.delete(messageId);
338
+ this.clearDelegationProgressTimers(session);
339
+ this.cancelImageReply(messageId);
340
+ this.lastStreamUpdateTime.delete(messageId);
341
+ await Promise.all(this.removeActiveCardRoutes(session));
342
+ };
333
343
  this.feishuLongConnHandler.setOnCaptureSelection((openId, deviceId) => this.selections.capture(openId, deviceId));
334
344
  this.feishuLongConnHandler.setOnValidateSelection(fence => this.selections.isCurrent(fence));
335
345
  this.feishuLongConnHandler.setOnStartStreaming(async (messageId, openId, feishuMessageId, deviceId, threadId, pendingNewThread, queueCardId, threadName, selectionIntent) => {
@@ -1201,9 +1211,9 @@ class RouterServer {
1201
1211
  const cwd = message.cwd || message.data?.cwd || this.streamingMessages.get(message.messageId)?.queueStarted?.cwd
1202
1212
  || this.streamingMessages.get(message.messageId)?.recoveryCwd
1203
1213
  || this.streamingMessages.get(message.messageId)?.cwd;
1204
- const responseThreadId = message.threadId || message.data?.threadId;
1205
1214
  const responseThreads = message.threads || message.data?.threads;
1206
1215
  const queueConfirmation = message.queueConfirmation || message.data?.queueConfirmation;
1216
+ const responseThreadId = message.threadId || message.data?.threadId || queueConfirmation?.threadId;
1207
1217
  const executionMetadata = (0, ExecutionMetadata_1.parseExecutionMetadata)(message.executionMetadata ?? message.data?.executionMetadata);
1208
1218
  // Interactive settings menus only from a capable CLI on this connection;
1209
1219
  // the menu is bound to the original streaming session, never to a
@@ -1214,6 +1224,9 @@ class RouterServer {
1214
1224
  const settingsMenu = (candidateSettingsMenu?.kind === 'delegation' && !delegationCardsEnabled)
1215
1225
  || (candidateSettingsMenu?.kind === 'directory' && !directoryCardsEnabled) ? undefined : candidateSettingsMenu;
1216
1226
  const responseSession = responseMessageId ? this.streamingMessages.get(responseMessageId) : undefined;
1227
+ if (queueConfirmation && (!responseSession || queueConfirmation.threadId !== responseThreadId
1228
+ || (responseSession.threadId && responseSession.threadId !== responseThreadId)))
1229
+ break;
1217
1230
  const requestedMenu = message.scheduleMenu ?? message.data?.scheduleMenu;
1218
1231
  if (requestedMenu && (!responseSession || responseSession.threadId !== responseThreadId
1219
1232
  || !scheduleBindingCurrent(responseOpenId)))
@@ -1228,9 +1241,10 @@ class RouterServer {
1228
1241
  let selectionWarning;
1229
1242
  if (responseSession) {
1230
1243
  if (responseThreadId) {
1231
- if (responseSession.feishuMessageId && responseSession.threadId !== responseThreadId) {
1244
+ if (responseSession.threadId !== responseThreadId) {
1232
1245
  responseSession.threadId = responseThreadId;
1233
- await this.registerCardThread(responseSession.feishuMessageId, { threadId: responseThreadId, deviceId: responseSession.deviceId, openId: responseSession.openId, epoch: responseSession.selectionFence?.epoch ?? this.selections.capture(responseSession.openId, responseSession.deviceId).epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, () => this.streamingMessages.get(responseMessageId) === responseSession && imageCurrent());
1246
+ if (responseSession.feishuMessageId)
1247
+ await this.registerCardThread(responseSession.feishuMessageId, { threadId: responseThreadId, deviceId: responseSession.deviceId, openId: responseSession.openId, epoch: responseSession.selectionFence?.epoch ?? this.selections.capture(responseSession.openId, responseSession.deviceId).epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, () => this.streamingMessages.get(responseMessageId) === responseSession && imageCurrent());
1234
1248
  }
1235
1249
  if (responseThreads) {
1236
1250
  const match = responseThreads.find(t => t.id === responseThreadId);
@@ -1275,9 +1289,11 @@ class RouterServer {
1275
1289
  || this.streamingMessages.get(responseMessageId) !== responseSession))
1276
1290
  break;
1277
1291
  // Check if this was a streaming message (stream chunks were sent)
1278
- if (this.streamingMessages.has(responseMessageId)) {
1292
+ if (responseSession) {
1293
+ if (this.streamingMessages.get(responseMessageId) !== responseSession)
1294
+ break;
1279
1295
  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, menuOwned);
1280
- if (menuOwned && (!delivered || !await menuOwned()))
1296
+ if (!delivered || (menuOwned && !await menuOwned()))
1281
1297
  break;
1282
1298
  }
1283
1299
  else {
@@ -1523,6 +1539,15 @@ class RouterServer {
1523
1539
  const stream = this.streamingMessages.get(messageId);
1524
1540
  if (stream && (stream.deviceId !== deviceId || stream.openId !== openId))
1525
1541
  return false;
1542
+ if (stream?.selectionFence && !this.selections.isOwnershipCurrent(openId, deviceId, stream.selectionFence.epoch))
1543
+ return false;
1544
+ if (stream && !stream.feishuMessageId && !stream.pendingNewThread) {
1545
+ const threadId = message.threadId ?? message.data?.threadId;
1546
+ if (stream.threadId && threadId && stream.threadId !== threadId)
1547
+ return false;
1548
+ if (!stream.threadId && message.type === 'stream' && typeof threadId === 'string' && threadId)
1549
+ stream.threadId = threadId;
1550
+ }
1526
1551
  const route = this.imageReplies.get(messageId);
1527
1552
  if (route && (route.deviceId !== deviceId || route.openId !== openId))
1528
1553
  return false;
@@ -1537,6 +1562,7 @@ class RouterServer {
1537
1562
  return false;
1538
1563
  const binding = await this.bindingManager.getDeviceBinding(stream.deviceId);
1539
1564
  return this.streamingMessages.get(messageId) === stream && binding?.openId === stream.openId
1565
+ && (!stream.selectionFence || this.selections.isOwnershipCurrent(stream.openId, stream.deviceId, stream.selectionFence.epoch))
1540
1566
  && (!current || current());
1541
1567
  }
1542
1568
  /** Cancellation is definitive only before the storage FIFO admits the guarded draft. */
@@ -2437,8 +2463,8 @@ class RouterServer {
2437
2463
  if (hints)
2438
2464
  await this.inlineFileCards.hints(deviceId, { ...hints, messageId, threadId }, this.attachmentHintStatus.get(deviceId)).catch(() => { });
2439
2465
  if (info.state !== 'running') {
2440
- await this.finalizeStreamingMessage(messageId, info.state === 'completed', undefined, info.error, undefined, info.cwd, undefined, (0, ExecutionMetadata_1.parseExecutionMetadata)(info.executionMetadata));
2441
- if (!isCurrent())
2466
+ const delivered = await this.finalizeStreamingMessage(messageId, info.state === 'completed', undefined, info.error, undefined, info.cwd, undefined, (0, ExecutionMetadata_1.parseExecutionMetadata)(info.executionMetadata));
2467
+ if (!delivered || !isCurrent())
2442
2468
  return false;
2443
2469
  this.rememberCompletedTask(messageId, deviceId);
2444
2470
  }
@@ -2476,6 +2502,8 @@ class RouterServer {
2476
2502
  if (previous && (previous.deviceId !== deviceId || previous.openId !== openId
2477
2503
  || (previous.threadId && previous.threadId !== threadId)))
2478
2504
  return;
2505
+ if (previous?.queueCardId && previous.selectionFence?.epoch !== selectionFence.epoch)
2506
+ return;
2479
2507
  if (previous && (info.source === 'schedule' || previous.queueStarted?.source === 'schedule')
2480
2508
  && (previous.queueStarted?.source !== info.source || previous.queueStarted?.scheduleId !== info.scheduleId
2481
2509
  || previous.queueStarted?.backend !== info.backend || previous.cwd !== info.cwd
@@ -2504,6 +2532,8 @@ class RouterServer {
2504
2532
  Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2505
2533
  let cardId = null;
2506
2534
  const current = () => isCurrent() && this.selections.isOwnershipCurrent(openId, deviceId, selectionFence.epoch);
2535
+ if (previous?.queueCardId && !current())
2536
+ return;
2507
2537
  const owned = this.scheduleOwnerCheck(openId, deviceId, info.bindingEpoch ?? selectionFence.epoch, isCurrent, !!info.bindingEpoch);
2508
2538
  if (info.source === 'schedule' && !await owned())
2509
2539
  return;
@@ -2517,7 +2547,7 @@ Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2517
2547
  }
2518
2548
  if (info.source === 'schedule' && !await owned())
2519
2549
  return;
2520
- if (!isCurrent() || (imageRoute && this.imageReplies.get(messageId) !== imageRoute))
2550
+ if (!isCurrent() || (previous?.queueCardId && !current()) || (imageRoute && this.imageReplies.get(messageId) !== imageRoute))
2521
2551
  return;
2522
2552
  const fallbackCardId = previous?.feishuMessageId || previous?.queueCardId || null;
2523
2553
  if (previous && this.streamingMessages.get(messageId) === previous) {
@@ -2557,7 +2587,7 @@ Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2557
2587
  if (!oldCard || oldCard === cardId)
2558
2588
  continue;
2559
2589
  try {
2560
- await this.feishuLongConnHandler.markQueueCardStarted(oldCard);
2590
+ await this.feishuLongConnHandler.markQueueCardStarted(oldCard, current);
2561
2591
  }
2562
2592
  catch (error) {
2563
2593
  // The new execution card remains usable if its old receipt expired.
@@ -2670,7 +2700,7 @@ Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2670
2700
  void done.then(() => { receipt.settled = true; }, () => { receipt.settled = true; });
2671
2701
  return done;
2672
2702
  }
2673
- async registerDeliveredThreadCards(messageId, streamData, cardIds) {
2703
+ async registerDeliveredThreadCards(messageId, streamData, cardIds, queueCardId, queueId) {
2674
2704
  if (!streamData.threadId || this.streamingMessages.get(messageId) !== streamData)
2675
2705
  return;
2676
2706
  const fence = streamData.selectionFence;
@@ -2687,7 +2717,8 @@ Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2687
2717
  streamData.deliveredCardIds.add(cardId);
2688
2718
  for (const cardId of delivered) {
2689
2719
  await this.registerCardThread(cardId, { threadId: streamData.threadId, deviceId: streamData.deviceId,
2690
- openId: streamData.openId, epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, () => this.streamingMessages.get(messageId) === streamData && (!streamData.currentConnection || streamData.currentConnection()));
2720
+ openId: streamData.openId, epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS,
2721
+ ...(cardId === queueCardId && queueId ? { queueId } : {}) }, () => this.streamingMessages.get(messageId) === streamData && (!streamData.currentConnection || streamData.currentConnection()));
2691
2722
  }
2692
2723
  }
2693
2724
  scheduleOwnerCheck(openId, deviceId, epoch, connectionCurrent, hostResult = false) {
@@ -2776,7 +2807,7 @@ Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2776
2807
  }
2777
2808
  }
2778
2809
  else if (success) {
2779
- const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, streamData.elements, sessionAbbr, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, true, { current: deliveryCurrent, onDelivered: cardIds => this.registerDeliveredThreadCards(messageId, streamData, cardIds) });
2810
+ const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, streamData.elements, sessionAbbr, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, true, { current: deliveryCurrent, onDelivered: (ids, queueCard) => this.registerDeliveredThreadCards(messageId, streamData, ids, queueCard, queueConfirmation?.id) });
2780
2811
  if (finalized === false)
2781
2812
  throw new Error('Failed to finalize task card');
2782
2813
  }
@@ -2787,28 +2818,42 @@ Directory: \`${escape(info.cwd)}\` · Remaining: ${info.remainingCount}</font>`;
2787
2818
  const errorMsg = error || 'Command failed';
2788
2819
  finalElements.push((0, ToolFormatter_1.createMarkdownElement)(`\n\n❌ **Error:** ${errorMsg}`));
2789
2820
  }
2790
- const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, false, { current: deliveryCurrent, onDelivered: cardIds => this.registerDeliveredThreadCards(messageId, streamData, cardIds) });
2821
+ const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, false, { current: deliveryCurrent, onDelivered: (ids, queueCard) => this.registerDeliveredThreadCards(messageId, streamData, ids, queueCard, queueConfirmation?.id) });
2791
2822
  if (finalized === false)
2792
2823
  throw new Error('Failed to finalize task card');
2793
2824
  }
2794
2825
  }
2795
- else if (streamData.queueStarted) {
2796
- if (streamData.queueStarted.source === 'schedule') {
2826
+ else {
2827
+ if (streamData.queueStarted?.source === 'schedule') {
2797
2828
  // An unthreaded plain message would lose the original reply route.
2798
2829
  // Leave this occurrence in the CLI outbox for a fresh card attempt.
2799
2830
  throw new Error('Scheduled result card is unavailable');
2800
2831
  }
2801
- // If card creation failed after session recovery, retain a text result
2802
- // rather than silently losing the completed queued task's output.
2803
- const text = streamData.elements
2832
+ const parts = streamData.elements
2804
2833
  .filter((element) => element.tag === 'markdown')
2805
2834
  .map((element) => element.content)
2806
- .concat(streamData.currentTextContent, output || '')
2807
- .filter(Boolean)
2808
- .join('\n\n');
2809
- const delivered = await this.feishuLongConnHandler.sendMessage(openId, `${text}\n\n${success ? '✅ Completed' : `❌ Error: ${error || 'Command failed'}`}`);
2810
- if (delivered === false)
2811
- throw new Error('Failed to deliver task result');
2835
+ .concat(streamData.currentTextContent)
2836
+ .filter(Boolean);
2837
+ if (output && !parts.includes(output))
2838
+ parts.push(output);
2839
+ if (!await this.canDispatchStreamOutput(messageId, streamData))
2840
+ return false;
2841
+ const receipt = streamData.fallbackReceipt ??= this.feishuLongConnHandler.sendMessageWithReceipt(openId, [...parts, success ? '✅ Completed' : `❌ Error: ${error || 'Command failed'}`].join('\n\n'));
2842
+ const deliveredId = await receipt;
2843
+ if (!deliveredId) {
2844
+ if (streamData.fallbackReceipt === receipt)
2845
+ streamData.fallbackReceipt = undefined;
2846
+ return false;
2847
+ }
2848
+ if (streamData.threadId) {
2849
+ await this.registerDeliveredThreadCards(messageId, streamData, [deliveredId]);
2850
+ const route = this.store.getCardThread(deliveredId);
2851
+ if (route?.threadId !== streamData.threadId || route.deviceId !== streamData.deviceId || route.openId !== openId
2852
+ || !this.selections.isOwnershipCurrent(openId, streamData.deviceId, route.epoch))
2853
+ return false;
2854
+ }
2855
+ if (!await this.canDispatchStreamOutput(messageId, streamData))
2856
+ return false;
2812
2857
  }
2813
2858
  (0, DeliveryDiagnostics_1.deliveryEvent)('task_finalization_complete', { task });
2814
2859
  // Keep durable card associations after removing the completed streaming session.