@yu_robotics/remote-cli-router 1.6.139 ā 1.6.145
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 +42 -2
- package/dist/feishu/FeishuLongConnHandler.d.ts +6 -3
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +104 -15
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +89 -21
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/ActivityProgress.d.ts +14 -0
- package/dist/utils/ActivityProgress.d.ts.map +1 -0
- package/dist/utils/ActivityProgress.js +32 -0
- package/dist/utils/ActivityProgress.js.map +1 -0
- package/dist/utils/ToolFormatter.d.ts +15 -1
- package/dist/utils/ToolFormatter.d.ts.map +1 -1
- package/dist/utils/ToolFormatter.js +51 -2
- package/dist/utils/ToolFormatter.js.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -13,6 +13,7 @@ const FileTransfers_1 = require("./files/FileTransfers");
|
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
14
|
const os_1 = __importDefault(require("os"));
|
|
15
15
|
const crypto_1 = require("crypto");
|
|
16
|
+
const ActivityProgress_1 = require("./utils/ActivityProgress");
|
|
16
17
|
const ExecutionMetadata_1 = require("./utils/ExecutionMetadata");
|
|
17
18
|
const koa_1 = __importDefault(require("koa"));
|
|
18
19
|
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
|
|
@@ -169,6 +170,7 @@ class RouterServer {
|
|
|
169
170
|
finalizing: false,
|
|
170
171
|
lastRenderedTextLength: 0,
|
|
171
172
|
delegationProgress: new Map(),
|
|
173
|
+
toolCalls: new Map(),
|
|
172
174
|
});
|
|
173
175
|
// Populate cardThreadMap for parent_id-based routing
|
|
174
176
|
if (feishuMessageId && threadId) {
|
|
@@ -348,6 +350,7 @@ class RouterServer {
|
|
|
348
350
|
let delegationProgressTextEnabled = false;
|
|
349
351
|
let workerContextResetEnabled = false;
|
|
350
352
|
let streamingContextEnabled = false;
|
|
353
|
+
let activityProgressEnabled = false;
|
|
351
354
|
let updateNoticeEnabled = false;
|
|
352
355
|
let subscriptionInspectionEnabled = false;
|
|
353
356
|
let authenticationPending = false;
|
|
@@ -531,6 +534,7 @@ class RouterServer {
|
|
|
531
534
|
this.maintenanceConnections.set(deviceId, { updateNotice: updateNoticeEnabled,
|
|
532
535
|
current: () => ws.readyState === ws_1.WebSocket.OPEN && this.connectionHub.isCurrentConnection(requestedId, ws) });
|
|
533
536
|
streamingContextEnabled = message.data.capabilities?.streamingContext === true;
|
|
537
|
+
activityProgressEnabled = message.data.capabilities?.activityProgress === true;
|
|
534
538
|
delegationProgressEnabled = message.data.capabilities?.delegationProgress === true;
|
|
535
539
|
delegationProgressTextEnabled = delegationProgressEnabled
|
|
536
540
|
&& message.data.capabilities?.delegationProgressText === true;
|
|
@@ -548,7 +552,8 @@ class RouterServer {
|
|
|
548
552
|
success: true,
|
|
549
553
|
routerVersion: types_1.ROUTER_VERSION,
|
|
550
554
|
minCliVersion: types_1.MIN_SUPPORTED_CLI_VERSION,
|
|
551
|
-
...((taskRecoveryEnabled || approvalCardsEnabled || delegationProgressEnabled || streamingContextEnabled || filesEnabled || updateNoticeEnabled || subscriptionInspectionEnabled) ? { capabilities: {
|
|
555
|
+
...((taskRecoveryEnabled || approvalCardsEnabled || delegationProgressEnabled || streamingContextEnabled || activityProgressEnabled || filesEnabled || updateNoticeEnabled || subscriptionInspectionEnabled) ? { capabilities: {
|
|
556
|
+
...(activityProgressEnabled ? { activityProgress: true } : {}),
|
|
552
557
|
...(updateNoticeEnabled ? { updateNotice: true } : {}),
|
|
553
558
|
...(subscriptionInspectionEnabled ? { subscriptionInspection: true } : {}),
|
|
554
559
|
...(filesEnabled ? { fileTransferV1: true } : {}),
|
|
@@ -663,6 +668,11 @@ class RouterServer {
|
|
|
663
668
|
if (message.messageId && message.openId) {
|
|
664
669
|
const streamType = message.streamType || 'text';
|
|
665
670
|
switch (streamType) {
|
|
671
|
+
case 'activity':
|
|
672
|
+
if (activityProgressEnabled && this.matchesActivityStream(message, deviceId)) {
|
|
673
|
+
await this.handleActivityProgress(message);
|
|
674
|
+
}
|
|
675
|
+
break;
|
|
666
676
|
case 'text': {
|
|
667
677
|
const update = this.handleTextChunk(message.messageId, message.openId, message.chunk || '');
|
|
668
678
|
if (this.startedQueueMessages.has(message.messageId)) {
|
|
@@ -688,7 +698,9 @@ class RouterServer {
|
|
|
688
698
|
break;
|
|
689
699
|
case 'delegation_progress':
|
|
690
700
|
if (delegationProgressEnabled && message.delegationProgress) {
|
|
691
|
-
|
|
701
|
+
if (activityProgressEnabled && !this.matchesActivityStream(message, deviceId))
|
|
702
|
+
break;
|
|
703
|
+
await this.handleDelegationProgress(message.messageId, message.openId, message.delegationProgress, delegationProgressTextEnabled, workerContextResetEnabled ? deviceId ?? undefined : undefined, activityProgressEnabled);
|
|
692
704
|
}
|
|
693
705
|
break;
|
|
694
706
|
case 'redacted_thinking':
|
|
@@ -805,6 +817,25 @@ class RouterServer {
|
|
|
805
817
|
lastStreamUpdateTime = new Map();
|
|
806
818
|
STREAM_UPDATE_INTERVAL_MS = 500; // Update at least every 500ms
|
|
807
819
|
STREAM_UPDATE_MIN_LENGTH = 10; // Update every 10 characters
|
|
820
|
+
matchesActivityStream(message, deviceId) {
|
|
821
|
+
if (!deviceId || typeof message.messageId !== 'string' || typeof message.openId !== 'string'
|
|
822
|
+
|| typeof message.threadId !== 'string' || !message.threadId)
|
|
823
|
+
return false;
|
|
824
|
+
const stream = this.streamingMessages.get(message.messageId);
|
|
825
|
+
return !!stream && !stream.finalizing && stream.deviceId === deviceId
|
|
826
|
+
&& stream.openId === message.openId && stream.threadId === message.threadId;
|
|
827
|
+
}
|
|
828
|
+
async handleActivityProgress(message) {
|
|
829
|
+
const activity = (0, ActivityProgress_1.parseActivityProgress)(message.activity);
|
|
830
|
+
const stream = this.streamingMessages.get(message.messageId);
|
|
831
|
+
if (!activity || !stream || stream.finalizing)
|
|
832
|
+
return;
|
|
833
|
+
if (stream.activity?.source === activity.source && stream.activity.text === activity.text)
|
|
834
|
+
return;
|
|
835
|
+
stream.activity = activity;
|
|
836
|
+
// Display snapshots do not renew stream or worker liveness deadlines.
|
|
837
|
+
await this.updateStreamingText(message.messageId, stream.openId, stream);
|
|
838
|
+
}
|
|
808
839
|
/** Resolve the card header without waiting for backend text or completion. */
|
|
809
840
|
async handleStreamContext(message, deviceId) {
|
|
810
841
|
const { messageId, openId, threadId, threadName, cwd } = message;
|
|
@@ -902,7 +933,7 @@ class RouterServer {
|
|
|
902
933
|
else
|
|
903
934
|
elements.push((0, ToolFormatter_1.createMarkdownElement)('š¤ Processing...'));
|
|
904
935
|
this.lastStreamUpdateTime.set(messageId, Date.now());
|
|
905
|
-
await this.feishuLongConnHandler.updateStreamingMessage(streamData.feishuMessageId, elements, openId, streamData.threadName, streamData.cwd);
|
|
936
|
+
await this.feishuLongConnHandler.updateStreamingMessage(streamData.feishuMessageId, elements, openId, streamData.threadName, streamData.cwd, ...(streamData.activity ? [streamData.activity] : []));
|
|
906
937
|
} while (streamData.updatePending);
|
|
907
938
|
}
|
|
908
939
|
/**
|
|
@@ -911,7 +942,7 @@ class RouterServer {
|
|
|
911
942
|
async handleToolUse(messageId, openId, toolUse) {
|
|
912
943
|
console.log(`[RouterServer] Received tool_use for ${messageId}: ${toolUse.name}`);
|
|
913
944
|
const streamData = this.streamingMessages.get(messageId);
|
|
914
|
-
if (!streamData) {
|
|
945
|
+
if (!streamData || streamData.finalizing) {
|
|
915
946
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
916
947
|
return;
|
|
917
948
|
}
|
|
@@ -923,9 +954,18 @@ class RouterServer {
|
|
|
923
954
|
streamData.lastRenderedTextLength = 0;
|
|
924
955
|
}
|
|
925
956
|
streamData.updatePending = false;
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
957
|
+
const id = this.toolCallId(toolUse.id);
|
|
958
|
+
let state = id ? streamData.toolCalls.get(id) : undefined;
|
|
959
|
+
// A new start after a received result is another call, even if an adapter
|
|
960
|
+
// reuses its ID. A result-first placeholder can still acquire its identity.
|
|
961
|
+
if (!state || (state.inputElements !== undefined && state.resultElements !== undefined)) {
|
|
962
|
+
state = { elementIndex: streamData.elements.length, id };
|
|
963
|
+
if (id)
|
|
964
|
+
streamData.toolCalls.set(id, state);
|
|
965
|
+
}
|
|
966
|
+
state.name = typeof toolUse.name === 'string' ? toolUse.name.slice(0, 200) : undefined;
|
|
967
|
+
state.inputElements = (0, ToolFormatter_1.createToolUseElement)(toolUse);
|
|
968
|
+
streamData.elements[state.elementIndex] = (0, ToolFormatter_1.createToolCallElement)(state);
|
|
929
969
|
streamData.createdAt = Date.now();
|
|
930
970
|
// Immediately update card to show tool use
|
|
931
971
|
if (streamData.feishuMessageId) {
|
|
@@ -939,7 +979,7 @@ class RouterServer {
|
|
|
939
979
|
async handleToolResult(messageId, openId, toolResult) {
|
|
940
980
|
console.log(`[RouterServer] Received tool_result for ${messageId}: ${toolResult.tool_use_id}`);
|
|
941
981
|
const streamData = this.streamingMessages.get(messageId);
|
|
942
|
-
if (!streamData) {
|
|
982
|
+
if (!streamData || streamData.finalizing) {
|
|
943
983
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
944
984
|
return;
|
|
945
985
|
}
|
|
@@ -951,9 +991,16 @@ class RouterServer {
|
|
|
951
991
|
streamData.lastRenderedTextLength = 0;
|
|
952
992
|
}
|
|
953
993
|
streamData.updatePending = false;
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
994
|
+
const id = this.toolCallId(toolResult.tool_use_id);
|
|
995
|
+
let state = id ? streamData.toolCalls.get(id) : undefined;
|
|
996
|
+
if (!state) {
|
|
997
|
+
state = { elementIndex: streamData.elements.length, id };
|
|
998
|
+
if (id)
|
|
999
|
+
streamData.toolCalls.set(id, state);
|
|
1000
|
+
}
|
|
1001
|
+
state.isError = Boolean(toolResult.is_error);
|
|
1002
|
+
state.resultElements = (0, ToolFormatter_1.createToolResultElement)(toolResult);
|
|
1003
|
+
streamData.elements[state.elementIndex] = (0, ToolFormatter_1.createToolCallElement)(state);
|
|
957
1004
|
streamData.createdAt = Date.now();
|
|
958
1005
|
// Immediately update card to show tool result
|
|
959
1006
|
if (streamData.feishuMessageId) {
|
|
@@ -961,12 +1008,17 @@ class RouterServer {
|
|
|
961
1008
|
streamData.hasUpdated = true;
|
|
962
1009
|
}
|
|
963
1010
|
}
|
|
1011
|
+
/** Missing and placeholder IDs cannot safely identify a tool invocation. */
|
|
1012
|
+
toolCallId(value) {
|
|
1013
|
+
return typeof value === 'string' && value.trim() && value !== 'unknown' && value.length <= 200
|
|
1014
|
+
&& !/[\u0000-\u001f\u007f-\u009f]/.test(value) ? value : undefined;
|
|
1015
|
+
}
|
|
964
1016
|
boundedDelegationProgressText(value, limit) {
|
|
965
1017
|
if (typeof value !== 'string')
|
|
966
1018
|
return undefined;
|
|
967
1019
|
return Array.from(value).slice(0, limit).join('');
|
|
968
1020
|
}
|
|
969
|
-
normalizeDelegationProgress(value, allowText) {
|
|
1021
|
+
normalizeDelegationProgress(value, allowText, allowActivity = false) {
|
|
970
1022
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
971
1023
|
return undefined;
|
|
972
1024
|
const raw = value;
|
|
@@ -974,7 +1026,11 @@ class RouterServer {
|
|
|
974
1026
|
const backend = this.boundedDelegationProgressText(raw.backend, 100);
|
|
975
1027
|
if (!taskId || !backend || typeof raw.phase !== 'string' || !DELEGATION_PROGRESS_PHASES.has(raw.phase))
|
|
976
1028
|
return undefined;
|
|
977
|
-
|
|
1029
|
+
const activity = allowActivity ? (0, ActivityProgress_1.parseActivityProgress)(raw.activity) : undefined;
|
|
1030
|
+
if (raw.phase === 'text' && !allowText && !activity)
|
|
1031
|
+
return undefined;
|
|
1032
|
+
if (allowActivity && raw.phase === 'text' && !activity
|
|
1033
|
+
&& !(allowText && typeof raw.latestText === 'string' && raw.latestText.trim()))
|
|
978
1034
|
return undefined;
|
|
979
1035
|
const toolUseRaw = raw.toolUse;
|
|
980
1036
|
const toolUse = toolUseRaw && typeof toolUseRaw === 'object' && !Array.isArray(toolUseRaw)
|
|
@@ -1011,7 +1067,9 @@ class RouterServer {
|
|
|
1011
1067
|
objective: this.boundedDelegationProgressText(raw.objective, 1000),
|
|
1012
1068
|
toolUse,
|
|
1013
1069
|
toolResult,
|
|
1014
|
-
latestText: this.boundedDelegationProgressText(raw.latestText, 1200),
|
|
1070
|
+
latestText: allowText || raw.phase !== 'text' ? this.boundedDelegationProgressText(raw.latestText, 1200) : undefined,
|
|
1071
|
+
...(activity ? { activity } : {}),
|
|
1072
|
+
...(allowActivity && typeof raw.waitingForInput === 'boolean' ? { waitingForInput: raw.waitingForInput } : {}),
|
|
1015
1073
|
summary: this.boundedDelegationProgressText(raw.summary, 4000),
|
|
1016
1074
|
error: this.boundedDelegationProgressText(raw.error, 4000),
|
|
1017
1075
|
startedAt,
|
|
@@ -1087,8 +1145,8 @@ class RouterServer {
|
|
|
1087
1145
|
state.currentToolStartedAt = activeId ? state.toolStartedAt.get(activeId) : undefined;
|
|
1088
1146
|
}
|
|
1089
1147
|
/** Update one bounded, nested worker panel rather than flattening child tool cards. */
|
|
1090
|
-
async handleDelegationProgress(messageId, openId, value, allowText = false, contextDeviceId) {
|
|
1091
|
-
const progress = this.normalizeDelegationProgress(value, allowText);
|
|
1148
|
+
async handleDelegationProgress(messageId, openId, value, allowText = false, contextDeviceId, allowActivity = false) {
|
|
1149
|
+
const progress = this.normalizeDelegationProgress(value, allowText, allowActivity);
|
|
1092
1150
|
if (!progress) {
|
|
1093
1151
|
console.log(`[RouterServer] Ignoring malformed delegation progress for ${messageId}`);
|
|
1094
1152
|
return;
|
|
@@ -1103,6 +1161,9 @@ class RouterServer {
|
|
|
1103
1161
|
}
|
|
1104
1162
|
if (state?.terminal)
|
|
1105
1163
|
return;
|
|
1164
|
+
if (allowActivity && state?.phase === 'waiting_input' && progress.phase === 'text'
|
|
1165
|
+
&& progress.waitingForInput !== false)
|
|
1166
|
+
return;
|
|
1106
1167
|
if (!state) {
|
|
1107
1168
|
if (streamData.currentTextContent.trim()) {
|
|
1108
1169
|
streamData.elements.push(...this.renderCurrentText(streamData));
|
|
@@ -1138,6 +1199,8 @@ class RouterServer {
|
|
|
1138
1199
|
}
|
|
1139
1200
|
if (progress.executionMetadata)
|
|
1140
1201
|
state.executionMetadata = progress.executionMetadata;
|
|
1202
|
+
if (progress.activity)
|
|
1203
|
+
state.activity = progress.activity;
|
|
1141
1204
|
if (progress.phase === 'waiting_input')
|
|
1142
1205
|
state.inputRequest = progress.summary;
|
|
1143
1206
|
else
|
|
@@ -1148,7 +1211,7 @@ class RouterServer {
|
|
|
1148
1211
|
state.error = progress.error;
|
|
1149
1212
|
if (progress.phase !== 'text' || state.activeToolIds.size === 0)
|
|
1150
1213
|
state.phase = progress.phase;
|
|
1151
|
-
if (progress.phase !== 'text' || progress.latestText)
|
|
1214
|
+
if (progress.phase !== 'text' || progress.latestText || progress.activity)
|
|
1152
1215
|
state.lastActivityAt = Date.now();
|
|
1153
1216
|
switch (progress.phase) {
|
|
1154
1217
|
case 'started':
|
|
@@ -1215,7 +1278,8 @@ class RouterServer {
|
|
|
1215
1278
|
}
|
|
1216
1279
|
state.activeToolCount = state.activeToolIds.size;
|
|
1217
1280
|
this.renderDelegationProgress(streamData, state);
|
|
1218
|
-
|
|
1281
|
+
if (progress.phase !== 'text' || progress.latestText)
|
|
1282
|
+
streamData.createdAt = Date.now();
|
|
1219
1283
|
try {
|
|
1220
1284
|
if (streamData.feishuMessageId)
|
|
1221
1285
|
await this.updateStreamingText(messageId, openId, streamData);
|
|
@@ -1232,7 +1296,7 @@ class RouterServer {
|
|
|
1232
1296
|
async handleRedactedThinking(messageId, openId) {
|
|
1233
1297
|
console.log(`[RouterServer] Received redacted_thinking for ${messageId}`);
|
|
1234
1298
|
const streamData = this.streamingMessages.get(messageId);
|
|
1235
|
-
if (!streamData) {
|
|
1299
|
+
if (!streamData || streamData.finalizing) {
|
|
1236
1300
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
1237
1301
|
return;
|
|
1238
1302
|
}
|
|
@@ -1262,7 +1326,7 @@ class RouterServer {
|
|
|
1262
1326
|
async handlePlanMode(messageId, openId, planContent) {
|
|
1263
1327
|
console.log(`[RouterServer] Received plan_mode for ${messageId}, plan length=${planContent.length}`);
|
|
1264
1328
|
const streamData = this.streamingMessages.get(messageId);
|
|
1265
|
-
if (!streamData) {
|
|
1329
|
+
if (!streamData || streamData.finalizing) {
|
|
1266
1330
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
1267
1331
|
return;
|
|
1268
1332
|
}
|
|
@@ -1289,6 +1353,8 @@ class RouterServer {
|
|
|
1289
1353
|
if (!image || image.type !== 'image' || typeof image.data !== 'string' || typeof image.mimeType !== 'string')
|
|
1290
1354
|
return;
|
|
1291
1355
|
const imageKey = await this.feishuLongConnHandler.uploadImage(image.data, image.mimeType);
|
|
1356
|
+
if (streamData.finalizing || this.streamingMessages.get(messageId) !== streamData)
|
|
1357
|
+
return;
|
|
1292
1358
|
if (!imageKey) {
|
|
1293
1359
|
streamData.elements.push((0, ToolFormatter_1.createMarkdownElement)('ā ļø Generated image could not be uploaded to Feishu.'));
|
|
1294
1360
|
return;
|
|
@@ -1410,6 +1476,7 @@ class RouterServer {
|
|
|
1410
1476
|
elements: [(0, ToolFormatter_1.createMarkdownElement)(intro)], currentTextContent: '', hasUpdated: false,
|
|
1411
1477
|
createdAt: Date.now(), updatePending: false, finalizing: false, lastRenderedTextLength: 0,
|
|
1412
1478
|
delegationProgress: new Map(),
|
|
1479
|
+
toolCalls: new Map(),
|
|
1413
1480
|
recoveryId: info.recoveryId, recoveryPlainText: true, recoveryCwd: info.cwd,
|
|
1414
1481
|
});
|
|
1415
1482
|
this.cardThreadMap.set(cardId, { threadId, deviceId, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS });
|
|
@@ -1475,6 +1542,7 @@ class RouterServer {
|
|
|
1475
1542
|
finalizing: false,
|
|
1476
1543
|
lastRenderedTextLength: 0,
|
|
1477
1544
|
delegationProgress: new Map(),
|
|
1545
|
+
toolCalls: new Map(),
|
|
1478
1546
|
queueStarted: info,
|
|
1479
1547
|
threads: Array.isArray(message.threads) ? message.threads : undefined,
|
|
1480
1548
|
});
|
|
@@ -1571,7 +1639,7 @@ class RouterServer {
|
|
|
1571
1639
|
const errorMsg = error || 'Command failed';
|
|
1572
1640
|
finalElements.push((0, ToolFormatter_1.createMarkdownElement)(`\n\nā **Error:** ${errorMsg}`));
|
|
1573
1641
|
}
|
|
1574
|
-
const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata);
|
|
1642
|
+
const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, false);
|
|
1575
1643
|
if (finalized === false)
|
|
1576
1644
|
throw new Error('Failed to finalize task card');
|
|
1577
1645
|
}
|