@yu_robotics/remote-cli-router 1.6.226 → 1.6.228
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 +14 -2
- package/dist/feishu/FeishuLongConnHandler.d.ts +5 -0
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +47 -12
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/output/InlineFileCards.d.ts +66 -0
- package/dist/output/InlineFileCards.d.ts.map +1 -0
- package/dist/output/InlineFileCards.js +364 -0
- package/dist/output/InlineFileCards.js.map +1 -0
- package/dist/output/OutputTransfers.d.ts +11 -2
- package/dist/output/OutputTransfers.d.ts.map +1 -1
- package/dist/output/OutputTransfers.js +94 -59
- package/dist/output/OutputTransfers.js.map +1 -1
- package/dist/output/Protocol.d.ts +6 -0
- package/dist/output/Protocol.d.ts.map +1 -1
- package/dist/output/Protocol.js +9 -0
- package/dist/output/Protocol.js.map +1 -1
- package/dist/server.d.ts +3 -10
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +74 -41
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +3 -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,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.
|
|
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);
|
|
@@ -618,6 +637,10 @@ class RouterServer {
|
|
|
618
637
|
return;
|
|
619
638
|
// Update heartbeat on any message
|
|
620
639
|
resetHeartbeat();
|
|
640
|
+
// Retired presentation: ignore legacy background terminal frames before
|
|
641
|
+
// recipient lookup, card creation, logging or reply-route mutation.
|
|
642
|
+
if (message.type === types_1.MessageType.TASK_NOTIFICATION)
|
|
643
|
+
return;
|
|
621
644
|
if (message.type === 'automatic_file_enrollment') {
|
|
622
645
|
const current = () => registered && !this.stopping && this.connectionHub.isCurrentConnection(deviceId, ws) && ws.readyState === ws_1.WebSocket.OPEN;
|
|
623
646
|
if (!deviceId || !automaticEnrollmentEnabled || !automaticEnrollmentAuthority || !this.fileTransfers.enabled
|
|
@@ -654,6 +677,7 @@ class RouterServer {
|
|
|
654
677
|
openId: stream.openId, threadId: stream.threadId,
|
|
655
678
|
epoch: stream.selectionFence?.epoch ?? this.selections.capture(stream.openId, deviceId).epoch });
|
|
656
679
|
}
|
|
680
|
+
await this.admitInlineParent(message.reference?.messageId).catch(() => { });
|
|
657
681
|
await this.outputTransfers.offer(deviceId, message.reference);
|
|
658
682
|
}
|
|
659
683
|
return;
|
|
@@ -701,7 +725,7 @@ class RouterServer {
|
|
|
701
725
|
const imageDevice = deviceId;
|
|
702
726
|
const imageCurrent = () => !socketClosed && ws.readyState === ws_1.WebSocket.OPEN
|
|
703
727
|
&& !!imageDevice && this.connectionHub.isCurrentConnection(imageDevice, ws);
|
|
704
|
-
if ([types_1.MessageType.RESPONSE, types_1.MessageType.NOTIFICATION,
|
|
728
|
+
if ([types_1.MessageType.RESPONSE, types_1.MessageType.NOTIFICATION,
|
|
705
729
|
'task_resume', 'stream', 'stream_context', 'queue_started'].includes(message.type)
|
|
706
730
|
&& !await this.authorizeRecipientOutput(message, imageDevice, imageCurrent))
|
|
707
731
|
return;
|
|
@@ -896,6 +920,10 @@ class RouterServer {
|
|
|
896
920
|
const outputsEnabled = Boolean(this.outputsAvailable && authenticatedOwner && message.data.capabilities?.outputFilesV1 === true);
|
|
897
921
|
if (outputsEnabled)
|
|
898
922
|
this.outputSessions.set(deviceId, { id: (0, crypto_1.randomUUID)(), openId: authenticatedOwner });
|
|
923
|
+
this.attachmentHintStatus.delete(deviceId);
|
|
924
|
+
if (message.data.capabilities?.outputAttachmentHintsV1 === true)
|
|
925
|
+
this.attachmentHintStatus.set(deviceId, !this.fileTransfers.enabled ? 'disabled' : !authenticatedOwner ? 'approval'
|
|
926
|
+
: message.data.capabilities?.outputFilesV1 !== true ? 'upgrade' : !this.outputsAvailable ? 'unavailable' : 'ready');
|
|
899
927
|
const filesEnabled = Boolean(this.fileTransfers.enabled && authenticatedOwner && message.data.capabilities?.fileTransferV1 === true);
|
|
900
928
|
const enrollmentBinding = this.fileTransfers.enabled && !authenticatedOwner
|
|
901
929
|
&& message.data.capabilities?.automaticFileEnrollmentV1 === true
|
|
@@ -945,13 +973,14 @@ class RouterServer {
|
|
|
945
973
|
success: true,
|
|
946
974
|
routerVersion: types_1.ROUTER_VERSION,
|
|
947
975
|
minCliVersion: types_1.MIN_SUPPORTED_CLI_VERSION,
|
|
948
|
-
...((taskRecoveryEnabled || approvalCardsEnabled || delegationProgressEnabled || streamingContextEnabled || activityProgressEnabled || filesEnabled || outputsEnabled || updateNoticeEnabled || subscriptionInspectionEnabled || settingsCardsEnabled || automaticEnrollmentEnabled) ? { capabilities: {
|
|
976
|
+
...((taskRecoveryEnabled || approvalCardsEnabled || delegationProgressEnabled || streamingContextEnabled || activityProgressEnabled || filesEnabled || outputsEnabled || updateNoticeEnabled || subscriptionInspectionEnabled || settingsCardsEnabled || automaticEnrollmentEnabled || message.data.capabilities?.outputAttachmentHintsV1 === true) ? { capabilities: {
|
|
949
977
|
...(automaticEnrollmentEnabled ? { automaticFileEnrollmentV1: true } : {}),
|
|
950
978
|
...(activityProgressEnabled ? { activityProgress: true } : {}),
|
|
951
979
|
...(updateNoticeEnabled ? { updateNotice: true } : {}),
|
|
952
980
|
...(subscriptionInspectionEnabled ? { subscriptionInspection: true } : {}),
|
|
953
981
|
...(bankedResetReminderEnabled ? { bankedResetReminder: true } : {}),
|
|
954
982
|
...(filesEnabled ? { fileTransferV1: true } : {}),
|
|
983
|
+
...(message.data.capabilities?.outputAttachmentHintsV1 === true ? { outputAttachmentHintsV1: true } : {}),
|
|
955
984
|
...(outputsEnabled ? { outputFilesV1: true } : {}),
|
|
956
985
|
...(taskRecoveryEnabled ? { taskRecovery: true } : {}),
|
|
957
986
|
...(approvalCardsEnabled ? { approvalCards: true } : {}),
|
|
@@ -1049,6 +1078,11 @@ class RouterServer {
|
|
|
1049
1078
|
await this.selections.handleMissingThread(responseSession.openId, responseSession.deviceId, responseSession.selectionFence, responseSession.threadId, imageCurrent);
|
|
1050
1079
|
}
|
|
1051
1080
|
}
|
|
1081
|
+
const hints = this.attachmentHintStatus.has(deviceId) && (0, Protocol_1.parseAttachmentHints)(message.attachmentHints);
|
|
1082
|
+
if (hints && responseSession?.deviceId === deviceId && responseThreadId === responseSession.threadId) {
|
|
1083
|
+
await this.admitInlineParent(responseMessageId).catch(() => { });
|
|
1084
|
+
await this.inlineFileCards.hints(deviceId, { ...hints, messageId: responseMessageId, threadId: responseThreadId }, this.attachmentHintStatus.get(deviceId)).catch(() => { });
|
|
1085
|
+
}
|
|
1052
1086
|
if (responseMessageId && responseOpenId) {
|
|
1053
1087
|
// Check if this was a streaming message (stream chunks were sent)
|
|
1054
1088
|
if (this.streamingMessages.has(responseMessageId)) {
|
|
@@ -1156,16 +1190,6 @@ class RouterServer {
|
|
|
1156
1190
|
}
|
|
1157
1191
|
}
|
|
1158
1192
|
break;
|
|
1159
|
-
case types_1.MessageType.TASK_NOTIFICATION:
|
|
1160
|
-
// Background task terminal-state event (Claude Code 2.x).
|
|
1161
|
-
// Not tied to any streaming session — rendered as a standalone card.
|
|
1162
|
-
if (message.openId && message.taskNotification) {
|
|
1163
|
-
await this.handleTaskNotification(message.openId, message.taskNotification, message.threadId, deviceId, message.threadName, imageCurrent);
|
|
1164
|
-
}
|
|
1165
|
-
else {
|
|
1166
|
-
console.log('[RouterServer] Ignoring task_notification with missing openId or payload');
|
|
1167
|
-
}
|
|
1168
|
-
break;
|
|
1169
1193
|
default:
|
|
1170
1194
|
console.log('Unknown message type:', message.type);
|
|
1171
1195
|
}
|
|
@@ -1203,6 +1227,7 @@ class RouterServer {
|
|
|
1203
1227
|
this.fileTransfers.disconnect(deviceId);
|
|
1204
1228
|
this.outputTransfers.disconnect(deviceId);
|
|
1205
1229
|
this.outputSessions.delete(deviceId);
|
|
1230
|
+
this.attachmentHintStatus.delete(deviceId);
|
|
1206
1231
|
// Clean up any streaming sessions for this device
|
|
1207
1232
|
this.approvalCards.disconnect(deviceId);
|
|
1208
1233
|
this.maintenanceCards.disconnect(deviceId);
|
|
@@ -2123,6 +2148,22 @@ class RouterServer {
|
|
|
2123
2148
|
if (previous && (previous.deviceId !== deviceId || previous.openId !== openId
|
|
2124
2149
|
|| (previous.threadId && previous.threadId !== threadId)))
|
|
2125
2150
|
return false;
|
|
2151
|
+
const hints = this.attachmentHintStatus.has(deviceId) && (0, Protocol_1.parseAttachmentHints)(info.attachmentHints);
|
|
2152
|
+
const identity = { messageId, openId, deviceId, threadId, epoch: selectionFence.epoch,
|
|
2153
|
+
...(hints ? { generation: hints.generation } : {}) };
|
|
2154
|
+
const sourceStatus = this.outputTransfers.identityStatus(identity);
|
|
2155
|
+
const inlineCapable = this.outputSessions.has(deviceId) || this.attachmentHintStatus.has(deviceId);
|
|
2156
|
+
const parentStatus = inlineCapable ? await this.inlineFileCards.identityStatus(identity).catch(() => 'unavailable') : 'unknown';
|
|
2157
|
+
if (!isCurrent() || sourceStatus === 'conflict' || parentStatus === 'conflict')
|
|
2158
|
+
return false;
|
|
2159
|
+
// A known empty initialized ledger can establish a new source. Disabled or
|
|
2160
|
+
// unavailable byte storage is never initialized just to authorize a hint.
|
|
2161
|
+
if (this.outputsAvailable && inlineCapable)
|
|
2162
|
+
await this.outputTransfers.admitSource(identity);
|
|
2163
|
+
// A missing journal cannot prove that an existing source was unpublished.
|
|
2164
|
+
const holdInline = !inlineCapable || parentStatus === 'unavailable'
|
|
2165
|
+
|| (sourceStatus === 'match' && parentStatus === 'unknown')
|
|
2166
|
+
|| (!this.outputsAvailable && parentStatus !== 'match');
|
|
2126
2167
|
// A failed terminal patch can retry on its own recovery card, but an old
|
|
2127
2168
|
// finalizing card cannot accept a newly resumed stream.
|
|
2128
2169
|
const reusable = previous?.feishuMessageId && (!previous.finalizing
|
|
@@ -2191,7 +2232,13 @@ class RouterServer {
|
|
|
2191
2232
|
});
|
|
2192
2233
|
await this.registerCardThread(cardId, { threadId, deviceId, openId, epoch: selectionFence.epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, isCurrent);
|
|
2193
2234
|
}
|
|
2235
|
+
const recoveredStream = this.streamingMessages.get(messageId);
|
|
2236
|
+
if (recoveredStream)
|
|
2237
|
+
recoveredStream.inlineRecoveryHeld = holdInline;
|
|
2194
2238
|
this.bindImageStream(messageId);
|
|
2239
|
+
await this.admitInlineParent(messageId, true).catch(() => { });
|
|
2240
|
+
if (hints)
|
|
2241
|
+
await this.inlineFileCards.hints(deviceId, { ...hints, messageId, threadId }, this.attachmentHintStatus.get(deviceId)).catch(() => { });
|
|
2195
2242
|
if (info.state !== 'running') {
|
|
2196
2243
|
await this.finalizeStreamingMessage(messageId, info.state === 'completed', undefined, info.error, undefined, info.cwd, undefined, (0, ExecutionMetadata_1.parseExecutionMetadata)(info.executionMetadata));
|
|
2197
2244
|
if (!isCurrent())
|
|
@@ -2299,37 +2346,20 @@ class RouterServer {
|
|
|
2299
2346
|
}
|
|
2300
2347
|
}
|
|
2301
2348
|
/**
|
|
2302
|
-
*
|
|
2303
|
-
*
|
|
2304
|
-
* Sent as a standalone one-shot card — the event may arrive while no
|
|
2305
|
-
* streaming session exists (the originating command's card is often
|
|
2306
|
-
* already finalized), so it deliberately never touches streamingMessages.
|
|
2307
|
-
* The new card has a durable association so the user can reply to it
|
|
2308
|
-
* to continue working in the originating thread.
|
|
2349
|
+
* Finalize streaming message
|
|
2309
2350
|
*/
|
|
2310
|
-
async
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
// createTaskNotificationElement renders them with a neutral label.
|
|
2315
|
-
if (!info || typeof info.taskId !== 'string' || info.taskId.length === 0 || typeof info.summary !== 'string') {
|
|
2316
|
-
console.log('[RouterServer] Ignoring task_notification with invalid payload:', JSON.stringify(info).slice(0, 200));
|
|
2351
|
+
async admitInlineParent(messageId, replacePending = false) {
|
|
2352
|
+
const stream = this.streamingMessages.get(messageId);
|
|
2353
|
+
if (!stream?.feishuMessageId || !stream.threadId || stream.inlineRecoveryHeld
|
|
2354
|
+
|| (!this.outputSessions.has(stream.deviceId) && !this.attachmentHintStatus.has(stream.deviceId)))
|
|
2317
2355
|
return;
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
const feishuMessageId = await this.feishuLongConnHandler.sendTaskNotificationCard(openId, elements);
|
|
2325
|
-
if (feishuMessageId && threadId && deviceId && selectionFence) {
|
|
2326
|
-
await this.registerCardThread(feishuMessageId, { threadId, deviceId, openId, epoch: selectionFence.epoch, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS }, current);
|
|
2327
|
-
console.log(`[RouterServer] Registered task notification card ${feishuMessageId} for thread ${threadId}`);
|
|
2328
|
-
}
|
|
2356
|
+
const owner = { messageId, rootId: stream.feishuMessageId, openId: stream.openId,
|
|
2357
|
+
deviceId: stream.deviceId, threadId: stream.threadId,
|
|
2358
|
+
epoch: stream.selectionFence?.epoch ?? this.selections.capture(stream.openId, stream.deviceId).epoch };
|
|
2359
|
+
if (this.outputTransfers.identityStatus(owner) === 'conflict')
|
|
2360
|
+
return;
|
|
2361
|
+
await this.inlineFileCards.admit(owner, replacePending);
|
|
2329
2362
|
}
|
|
2330
|
-
/**
|
|
2331
|
-
* Finalize streaming message
|
|
2332
|
-
*/
|
|
2333
2363
|
async registerDeliveredThreadCards(messageId, streamData, cardIds) {
|
|
2334
2364
|
if (!streamData.threadId || this.streamingMessages.get(messageId) !== streamData)
|
|
2335
2365
|
return;
|
|
@@ -2339,6 +2369,7 @@ class RouterServer {
|
|
|
2339
2369
|
const epoch = fence?.epoch ?? this.selections.capture(streamData.openId, streamData.deviceId).epoch;
|
|
2340
2370
|
if (!this.selections.isOwnershipCurrent(streamData.openId, streamData.deviceId, epoch))
|
|
2341
2371
|
return;
|
|
2372
|
+
await this.admitInlineParent(messageId).catch(() => { });
|
|
2342
2373
|
const delivered = cardIds.filter(id => typeof id === 'string' && id.length > 0);
|
|
2343
2374
|
streamData.deliveredCardIds ??= new Set();
|
|
2344
2375
|
// Track the whole batch before disk I/O so interruption revokes pending writes too.
|
|
@@ -2376,6 +2407,7 @@ class RouterServer {
|
|
|
2376
2407
|
await streamData.updateInFlight;
|
|
2377
2408
|
if (!await this.canDispatchStreamOutput(messageId, streamData))
|
|
2378
2409
|
return;
|
|
2410
|
+
await this.admitInlineParent(messageId).catch(() => { });
|
|
2379
2411
|
const { feishuMessageId, openId } = streamData;
|
|
2380
2412
|
if (feishuMessageId) {
|
|
2381
2413
|
// Flush any remaining text content
|
|
@@ -2581,6 +2613,7 @@ class RouterServer {
|
|
|
2581
2613
|
}
|
|
2582
2614
|
this.streamingMessages.clear();
|
|
2583
2615
|
this.lastStreamUpdateTime.clear();
|
|
2616
|
+
await attempt('Error destroying inline file cards', () => this.inlineFileCards.destroy());
|
|
2584
2617
|
await attempt('Error stopping Feishu long connection', () => this.feishuLongConnHandler.stop());
|
|
2585
2618
|
await attempt('Error closing WebSocket connections', () => this.connectionHub.closeAllConnections());
|
|
2586
2619
|
if (this.wss) {
|