@yu_robotics/remote-cli-router 1.6.225 → 1.6.227

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,8 @@ 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 Protocol_1 = require("./output/Protocol");
8
+ const InlineFileCards_1 = require("./output/InlineFileCards");
7
9
  const OutputTransfers_1 = require("./output/OutputTransfers");
8
10
  const DeliveryDiagnostics_1 = require("./utils/DeliveryDiagnostics");
9
11
  const IngressAdmission_1 = require("./security/IngressAdmission");
@@ -83,6 +85,8 @@ class RouterServer {
83
85
  automaticFileEnrollment;
84
86
  fileTransfers;
85
87
  outputTransfers;
88
+ inlineFileCards;
89
+ attachmentHintStatus = new Map();
86
90
  outputsAvailable = false;
87
91
  outputSessions = new Map();
88
92
  deviceEnrollments = new Set();
@@ -159,10 +163,23 @@ class RouterServer {
159
163
  send: (deviceId, message) => this.connectionHub.sendToDevice(deviceId, message),
160
164
  create: (openId, content, uuid) => this.feishuLongConnHandler.createOutputCard(openId, content, uuid),
161
165
  patch: (cardId, content) => this.feishuLongConnHandler.patchOutputCard(cardId, content),
166
+ inline: messageId => this.inlineFileCards.refresh(messageId),
167
+ parentAllowed: (identity, cardId) => this.inlineFileCards.allows(identity, cardId),
162
168
  upload: (filename, name) => this.feishuLongConnHandler.uploadOutputFile(filename, name),
163
169
  sendFile: (openId, content, uuid) => this.feishuLongConnHandler.sendOutputFile(openId, content, uuid),
164
170
  });
165
- this.feishuLongConnHandler.onOutputFileAction = (openId, cardId, payload) => this.outputTransfers.click(openId, cardId, payload);
171
+ this.inlineFileCards = new InlineFileCards_1.InlineFileCards(path_1.default.join(path_1.default.dirname(config.getConfigPath()
172
+ || path_1.default.join(os_1.default.homedir(), '.remote-cli-router', 'config.json')), 'inline-file-cards'), {
173
+ owns: async (owner) => this.selections.isOwnershipCurrent(owner.openId, owner.deviceId, owner.epoch)
174
+ && (await this.bindingManager.getDeviceBinding(owner.deviceId))?.openId === owner.openId,
175
+ rows: identity => this.outputTransfers.inlineRows(identity),
176
+ status: owner => !this.fileTransfers.enabled ? 'disabled' : this.outputSessions.has(owner.deviceId) ? 'ready' : this.attachmentHintStatus.get(owner.deviceId),
177
+ patch: (cardId, content) => this.feishuLongConnHandler.patchInlineOutputCard(cardId, content),
178
+ });
179
+ this.feishuLongConnHandler.inlineFiles = this.inlineFileCards;
180
+ this.feishuLongConnHandler.onInlineFilePage = (openId, cardId, action) => this.inlineFileCards.page(openId, cardId, action);
181
+ this.feishuLongConnHandler.onOutputFileAction = (openId, cardId, payload) => this.outputsAvailable
182
+ ? this.outputTransfers.click(openId, cardId, payload) : Promise.resolve('File retrieval is disabled.');
166
183
  this.feishuLongConnHandler.onFileMessage = input => this.fileTransfers.receive(input);
167
184
  this.feishuLongConnHandler.onResolveFile = (openId, sourceId) => this.fileTransfers.resolve(openId, sourceId);
168
185
  this.feishuLongConnHandler.onDeviceEnrollmentBoundary = (deviceId, phase) => {
@@ -280,6 +297,8 @@ class RouterServer {
280
297
  await this.outputTransfers.admitSource({ messageId, openId, deviceId, threadId,
281
298
  epoch: selectionIntent?.epoch ?? this.selections.capture(openId, deviceId).epoch }).catch(() => { });
282
299
  }
300
+ if (this.outputSessions.has(deviceId) || this.attachmentHintStatus.has(deviceId))
301
+ await this.admitInlineParent(messageId).catch(() => { });
283
302
  // Populate card associations for parent_id-based routing
284
303
  if (feishuMessageId && threadId) {
285
304
  await this.registerCardThread(feishuMessageId, { threadId, deviceId, openId, epoch: selectionIntent?.epoch ?? this.selections.capture(openId, deviceId).epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, () => this.streamingMessages.get(messageId)?.feishuMessageId === feishuMessageId);
@@ -654,6 +673,7 @@ class RouterServer {
654
673
  openId: stream.openId, threadId: stream.threadId,
655
674
  epoch: stream.selectionFence?.epoch ?? this.selections.capture(stream.openId, deviceId).epoch });
656
675
  }
676
+ await this.admitInlineParent(message.reference?.messageId).catch(() => { });
657
677
  await this.outputTransfers.offer(deviceId, message.reference);
658
678
  }
659
679
  return;
@@ -896,6 +916,10 @@ class RouterServer {
896
916
  const outputsEnabled = Boolean(this.outputsAvailable && authenticatedOwner && message.data.capabilities?.outputFilesV1 === true);
897
917
  if (outputsEnabled)
898
918
  this.outputSessions.set(deviceId, { id: (0, crypto_1.randomUUID)(), openId: authenticatedOwner });
919
+ this.attachmentHintStatus.delete(deviceId);
920
+ if (message.data.capabilities?.outputAttachmentHintsV1 === true)
921
+ this.attachmentHintStatus.set(deviceId, !this.fileTransfers.enabled ? 'disabled' : !authenticatedOwner ? 'approval'
922
+ : message.data.capabilities?.outputFilesV1 !== true ? 'upgrade' : !this.outputsAvailable ? 'unavailable' : 'ready');
899
923
  const filesEnabled = Boolean(this.fileTransfers.enabled && authenticatedOwner && message.data.capabilities?.fileTransferV1 === true);
900
924
  const enrollmentBinding = this.fileTransfers.enabled && !authenticatedOwner
901
925
  && message.data.capabilities?.automaticFileEnrollmentV1 === true
@@ -945,13 +969,14 @@ class RouterServer {
945
969
  success: true,
946
970
  routerVersion: types_1.ROUTER_VERSION,
947
971
  minCliVersion: types_1.MIN_SUPPORTED_CLI_VERSION,
948
- ...((taskRecoveryEnabled || approvalCardsEnabled || delegationProgressEnabled || streamingContextEnabled || activityProgressEnabled || filesEnabled || outputsEnabled || updateNoticeEnabled || subscriptionInspectionEnabled || settingsCardsEnabled || automaticEnrollmentEnabled) ? { capabilities: {
972
+ ...((taskRecoveryEnabled || approvalCardsEnabled || delegationProgressEnabled || streamingContextEnabled || activityProgressEnabled || filesEnabled || outputsEnabled || updateNoticeEnabled || subscriptionInspectionEnabled || settingsCardsEnabled || automaticEnrollmentEnabled || message.data.capabilities?.outputAttachmentHintsV1 === true) ? { capabilities: {
949
973
  ...(automaticEnrollmentEnabled ? { automaticFileEnrollmentV1: true } : {}),
950
974
  ...(activityProgressEnabled ? { activityProgress: true } : {}),
951
975
  ...(updateNoticeEnabled ? { updateNotice: true } : {}),
952
976
  ...(subscriptionInspectionEnabled ? { subscriptionInspection: true } : {}),
953
977
  ...(bankedResetReminderEnabled ? { bankedResetReminder: true } : {}),
954
978
  ...(filesEnabled ? { fileTransferV1: true } : {}),
979
+ ...(message.data.capabilities?.outputAttachmentHintsV1 === true ? { outputAttachmentHintsV1: true } : {}),
955
980
  ...(outputsEnabled ? { outputFilesV1: true } : {}),
956
981
  ...(taskRecoveryEnabled ? { taskRecovery: true } : {}),
957
982
  ...(approvalCardsEnabled ? { approvalCards: true } : {}),
@@ -1049,6 +1074,11 @@ class RouterServer {
1049
1074
  await this.selections.handleMissingThread(responseSession.openId, responseSession.deviceId, responseSession.selectionFence, responseSession.threadId, imageCurrent);
1050
1075
  }
1051
1076
  }
1077
+ const hints = this.attachmentHintStatus.has(deviceId) && (0, Protocol_1.parseAttachmentHints)(message.attachmentHints);
1078
+ if (hints && responseSession?.deviceId === deviceId && responseThreadId === responseSession.threadId) {
1079
+ await this.admitInlineParent(responseMessageId).catch(() => { });
1080
+ await this.inlineFileCards.hints(deviceId, { ...hints, messageId: responseMessageId, threadId: responseThreadId }, this.attachmentHintStatus.get(deviceId)).catch(() => { });
1081
+ }
1052
1082
  if (responseMessageId && responseOpenId) {
1053
1083
  // Check if this was a streaming message (stream chunks were sent)
1054
1084
  if (this.streamingMessages.has(responseMessageId)) {
@@ -1203,6 +1233,7 @@ class RouterServer {
1203
1233
  this.fileTransfers.disconnect(deviceId);
1204
1234
  this.outputTransfers.disconnect(deviceId);
1205
1235
  this.outputSessions.delete(deviceId);
1236
+ this.attachmentHintStatus.delete(deviceId);
1206
1237
  // Clean up any streaming sessions for this device
1207
1238
  this.approvalCards.disconnect(deviceId);
1208
1239
  this.maintenanceCards.disconnect(deviceId);
@@ -2123,6 +2154,22 @@ class RouterServer {
2123
2154
  if (previous && (previous.deviceId !== deviceId || previous.openId !== openId
2124
2155
  || (previous.threadId && previous.threadId !== threadId)))
2125
2156
  return false;
2157
+ const hints = this.attachmentHintStatus.has(deviceId) && (0, Protocol_1.parseAttachmentHints)(info.attachmentHints);
2158
+ const identity = { messageId, openId, deviceId, threadId, epoch: selectionFence.epoch,
2159
+ ...(hints ? { generation: hints.generation } : {}) };
2160
+ const sourceStatus = this.outputTransfers.identityStatus(identity);
2161
+ const inlineCapable = this.outputSessions.has(deviceId) || this.attachmentHintStatus.has(deviceId);
2162
+ const parentStatus = inlineCapable ? await this.inlineFileCards.identityStatus(identity).catch(() => 'unavailable') : 'unknown';
2163
+ if (!isCurrent() || sourceStatus === 'conflict' || parentStatus === 'conflict')
2164
+ return false;
2165
+ // A known empty initialized ledger can establish a new source. Disabled or
2166
+ // unavailable byte storage is never initialized just to authorize a hint.
2167
+ if (this.outputsAvailable && inlineCapable)
2168
+ await this.outputTransfers.admitSource(identity);
2169
+ // A missing journal cannot prove that an existing source was unpublished.
2170
+ const holdInline = !inlineCapable || parentStatus === 'unavailable'
2171
+ || (sourceStatus === 'match' && parentStatus === 'unknown')
2172
+ || (!this.outputsAvailable && parentStatus !== 'match');
2126
2173
  // A failed terminal patch can retry on its own recovery card, but an old
2127
2174
  // finalizing card cannot accept a newly resumed stream.
2128
2175
  const reusable = previous?.feishuMessageId && (!previous.finalizing
@@ -2191,7 +2238,13 @@ class RouterServer {
2191
2238
  });
2192
2239
  await this.registerCardThread(cardId, { threadId, deviceId, openId, epoch: selectionFence.epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, isCurrent);
2193
2240
  }
2241
+ const recoveredStream = this.streamingMessages.get(messageId);
2242
+ if (recoveredStream)
2243
+ recoveredStream.inlineRecoveryHeld = holdInline;
2194
2244
  this.bindImageStream(messageId);
2245
+ await this.admitInlineParent(messageId, true).catch(() => { });
2246
+ if (hints)
2247
+ await this.inlineFileCards.hints(deviceId, { ...hints, messageId, threadId }, this.attachmentHintStatus.get(deviceId)).catch(() => { });
2195
2248
  if (info.state !== 'running') {
2196
2249
  await this.finalizeStreamingMessage(messageId, info.state === 'completed', undefined, info.error, undefined, info.cwd, undefined, (0, ExecutionMetadata_1.parseExecutionMetadata)(info.executionMetadata));
2197
2250
  if (!isCurrent())
@@ -2330,6 +2383,18 @@ class RouterServer {
2330
2383
  /**
2331
2384
  * Finalize streaming message
2332
2385
  */
2386
+ async admitInlineParent(messageId, replacePending = false) {
2387
+ const stream = this.streamingMessages.get(messageId);
2388
+ if (!stream?.feishuMessageId || !stream.threadId || stream.inlineRecoveryHeld
2389
+ || (!this.outputSessions.has(stream.deviceId) && !this.attachmentHintStatus.has(stream.deviceId)))
2390
+ return;
2391
+ const owner = { messageId, rootId: stream.feishuMessageId, openId: stream.openId,
2392
+ deviceId: stream.deviceId, threadId: stream.threadId,
2393
+ epoch: stream.selectionFence?.epoch ?? this.selections.capture(stream.openId, stream.deviceId).epoch };
2394
+ if (this.outputTransfers.identityStatus(owner) === 'conflict')
2395
+ return;
2396
+ await this.inlineFileCards.admit(owner, replacePending);
2397
+ }
2333
2398
  async registerDeliveredThreadCards(messageId, streamData, cardIds) {
2334
2399
  if (!streamData.threadId || this.streamingMessages.get(messageId) !== streamData)
2335
2400
  return;
@@ -2339,6 +2404,7 @@ class RouterServer {
2339
2404
  const epoch = fence?.epoch ?? this.selections.capture(streamData.openId, streamData.deviceId).epoch;
2340
2405
  if (!this.selections.isOwnershipCurrent(streamData.openId, streamData.deviceId, epoch))
2341
2406
  return;
2407
+ await this.admitInlineParent(messageId).catch(() => { });
2342
2408
  const delivered = cardIds.filter(id => typeof id === 'string' && id.length > 0);
2343
2409
  streamData.deliveredCardIds ??= new Set();
2344
2410
  // Track the whole batch before disk I/O so interruption revokes pending writes too.
@@ -2376,6 +2442,7 @@ class RouterServer {
2376
2442
  await streamData.updateInFlight;
2377
2443
  if (!await this.canDispatchStreamOutput(messageId, streamData))
2378
2444
  return;
2445
+ await this.admitInlineParent(messageId).catch(() => { });
2379
2446
  const { feishuMessageId, openId } = streamData;
2380
2447
  if (feishuMessageId) {
2381
2448
  // Flush any remaining text content
@@ -2581,6 +2648,7 @@ class RouterServer {
2581
2648
  }
2582
2649
  this.streamingMessages.clear();
2583
2650
  this.lastStreamUpdateTime.clear();
2651
+ await attempt('Error destroying inline file cards', () => this.inlineFileCards.destroy());
2584
2652
  await attempt('Error stopping Feishu long connection', () => this.feishuLongConnHandler.stop());
2585
2653
  await attempt('Error closing WebSocket connections', () => this.connectionHub.closeAllConnections());
2586
2654
  if (this.wss) {