@yu_robotics/remote-cli-router 1.6.141 ā 1.6.146
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 +16 -1
- 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 +90 -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 +19 -1
- package/dist/utils/ToolFormatter.d.ts.map +1 -1
- package/dist/utils/ToolFormatter.js +90 -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,19 @@ 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.summary = (0, ToolFormatter_1.createToolCallSummary)(toolUse);
|
|
968
|
+
state.inputElements = (0, ToolFormatter_1.createToolUseElement)(toolUse);
|
|
969
|
+
streamData.elements[state.elementIndex] = (0, ToolFormatter_1.createToolCallElement)(state);
|
|
929
970
|
streamData.createdAt = Date.now();
|
|
930
971
|
// Immediately update card to show tool use
|
|
931
972
|
if (streamData.feishuMessageId) {
|
|
@@ -939,7 +980,7 @@ class RouterServer {
|
|
|
939
980
|
async handleToolResult(messageId, openId, toolResult) {
|
|
940
981
|
console.log(`[RouterServer] Received tool_result for ${messageId}: ${toolResult.tool_use_id}`);
|
|
941
982
|
const streamData = this.streamingMessages.get(messageId);
|
|
942
|
-
if (!streamData) {
|
|
983
|
+
if (!streamData || streamData.finalizing) {
|
|
943
984
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
944
985
|
return;
|
|
945
986
|
}
|
|
@@ -951,9 +992,16 @@ class RouterServer {
|
|
|
951
992
|
streamData.lastRenderedTextLength = 0;
|
|
952
993
|
}
|
|
953
994
|
streamData.updatePending = false;
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
995
|
+
const id = this.toolCallId(toolResult.tool_use_id);
|
|
996
|
+
let state = id ? streamData.toolCalls.get(id) : undefined;
|
|
997
|
+
if (!state) {
|
|
998
|
+
state = { elementIndex: streamData.elements.length, id };
|
|
999
|
+
if (id)
|
|
1000
|
+
streamData.toolCalls.set(id, state);
|
|
1001
|
+
}
|
|
1002
|
+
state.isError = Boolean(toolResult.is_error);
|
|
1003
|
+
state.resultElements = (0, ToolFormatter_1.createToolResultElement)(toolResult);
|
|
1004
|
+
streamData.elements[state.elementIndex] = (0, ToolFormatter_1.createToolCallElement)(state);
|
|
957
1005
|
streamData.createdAt = Date.now();
|
|
958
1006
|
// Immediately update card to show tool result
|
|
959
1007
|
if (streamData.feishuMessageId) {
|
|
@@ -961,12 +1009,17 @@ class RouterServer {
|
|
|
961
1009
|
streamData.hasUpdated = true;
|
|
962
1010
|
}
|
|
963
1011
|
}
|
|
1012
|
+
/** Missing and placeholder IDs cannot safely identify a tool invocation. */
|
|
1013
|
+
toolCallId(value) {
|
|
1014
|
+
return typeof value === 'string' && value.trim() && value !== 'unknown' && value.length <= 200
|
|
1015
|
+
&& !/[\u0000-\u001f\u007f-\u009f]/.test(value) ? value : undefined;
|
|
1016
|
+
}
|
|
964
1017
|
boundedDelegationProgressText(value, limit) {
|
|
965
1018
|
if (typeof value !== 'string')
|
|
966
1019
|
return undefined;
|
|
967
1020
|
return Array.from(value).slice(0, limit).join('');
|
|
968
1021
|
}
|
|
969
|
-
normalizeDelegationProgress(value, allowText) {
|
|
1022
|
+
normalizeDelegationProgress(value, allowText, allowActivity = false) {
|
|
970
1023
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
971
1024
|
return undefined;
|
|
972
1025
|
const raw = value;
|
|
@@ -974,7 +1027,11 @@ class RouterServer {
|
|
|
974
1027
|
const backend = this.boundedDelegationProgressText(raw.backend, 100);
|
|
975
1028
|
if (!taskId || !backend || typeof raw.phase !== 'string' || !DELEGATION_PROGRESS_PHASES.has(raw.phase))
|
|
976
1029
|
return undefined;
|
|
977
|
-
|
|
1030
|
+
const activity = allowActivity ? (0, ActivityProgress_1.parseActivityProgress)(raw.activity) : undefined;
|
|
1031
|
+
if (raw.phase === 'text' && !allowText && !activity)
|
|
1032
|
+
return undefined;
|
|
1033
|
+
if (allowActivity && raw.phase === 'text' && !activity
|
|
1034
|
+
&& !(allowText && typeof raw.latestText === 'string' && raw.latestText.trim()))
|
|
978
1035
|
return undefined;
|
|
979
1036
|
const toolUseRaw = raw.toolUse;
|
|
980
1037
|
const toolUse = toolUseRaw && typeof toolUseRaw === 'object' && !Array.isArray(toolUseRaw)
|
|
@@ -1011,7 +1068,9 @@ class RouterServer {
|
|
|
1011
1068
|
objective: this.boundedDelegationProgressText(raw.objective, 1000),
|
|
1012
1069
|
toolUse,
|
|
1013
1070
|
toolResult,
|
|
1014
|
-
latestText: this.boundedDelegationProgressText(raw.latestText, 1200),
|
|
1071
|
+
latestText: allowText || raw.phase !== 'text' ? this.boundedDelegationProgressText(raw.latestText, 1200) : undefined,
|
|
1072
|
+
...(activity ? { activity } : {}),
|
|
1073
|
+
...(allowActivity && typeof raw.waitingForInput === 'boolean' ? { waitingForInput: raw.waitingForInput } : {}),
|
|
1015
1074
|
summary: this.boundedDelegationProgressText(raw.summary, 4000),
|
|
1016
1075
|
error: this.boundedDelegationProgressText(raw.error, 4000),
|
|
1017
1076
|
startedAt,
|
|
@@ -1087,8 +1146,8 @@ class RouterServer {
|
|
|
1087
1146
|
state.currentToolStartedAt = activeId ? state.toolStartedAt.get(activeId) : undefined;
|
|
1088
1147
|
}
|
|
1089
1148
|
/** 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);
|
|
1149
|
+
async handleDelegationProgress(messageId, openId, value, allowText = false, contextDeviceId, allowActivity = false) {
|
|
1150
|
+
const progress = this.normalizeDelegationProgress(value, allowText, allowActivity);
|
|
1092
1151
|
if (!progress) {
|
|
1093
1152
|
console.log(`[RouterServer] Ignoring malformed delegation progress for ${messageId}`);
|
|
1094
1153
|
return;
|
|
@@ -1103,6 +1162,9 @@ class RouterServer {
|
|
|
1103
1162
|
}
|
|
1104
1163
|
if (state?.terminal)
|
|
1105
1164
|
return;
|
|
1165
|
+
if (allowActivity && state?.phase === 'waiting_input' && progress.phase === 'text'
|
|
1166
|
+
&& progress.waitingForInput !== false)
|
|
1167
|
+
return;
|
|
1106
1168
|
if (!state) {
|
|
1107
1169
|
if (streamData.currentTextContent.trim()) {
|
|
1108
1170
|
streamData.elements.push(...this.renderCurrentText(streamData));
|
|
@@ -1138,6 +1200,8 @@ class RouterServer {
|
|
|
1138
1200
|
}
|
|
1139
1201
|
if (progress.executionMetadata)
|
|
1140
1202
|
state.executionMetadata = progress.executionMetadata;
|
|
1203
|
+
if (progress.activity)
|
|
1204
|
+
state.activity = progress.activity;
|
|
1141
1205
|
if (progress.phase === 'waiting_input')
|
|
1142
1206
|
state.inputRequest = progress.summary;
|
|
1143
1207
|
else
|
|
@@ -1148,7 +1212,7 @@ class RouterServer {
|
|
|
1148
1212
|
state.error = progress.error;
|
|
1149
1213
|
if (progress.phase !== 'text' || state.activeToolIds.size === 0)
|
|
1150
1214
|
state.phase = progress.phase;
|
|
1151
|
-
if (progress.phase !== 'text' || progress.latestText)
|
|
1215
|
+
if (progress.phase !== 'text' || progress.latestText || progress.activity)
|
|
1152
1216
|
state.lastActivityAt = Date.now();
|
|
1153
1217
|
switch (progress.phase) {
|
|
1154
1218
|
case 'started':
|
|
@@ -1215,7 +1279,8 @@ class RouterServer {
|
|
|
1215
1279
|
}
|
|
1216
1280
|
state.activeToolCount = state.activeToolIds.size;
|
|
1217
1281
|
this.renderDelegationProgress(streamData, state);
|
|
1218
|
-
|
|
1282
|
+
if (progress.phase !== 'text' || progress.latestText)
|
|
1283
|
+
streamData.createdAt = Date.now();
|
|
1219
1284
|
try {
|
|
1220
1285
|
if (streamData.feishuMessageId)
|
|
1221
1286
|
await this.updateStreamingText(messageId, openId, streamData);
|
|
@@ -1232,7 +1297,7 @@ class RouterServer {
|
|
|
1232
1297
|
async handleRedactedThinking(messageId, openId) {
|
|
1233
1298
|
console.log(`[RouterServer] Received redacted_thinking for ${messageId}`);
|
|
1234
1299
|
const streamData = this.streamingMessages.get(messageId);
|
|
1235
|
-
if (!streamData) {
|
|
1300
|
+
if (!streamData || streamData.finalizing) {
|
|
1236
1301
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
1237
1302
|
return;
|
|
1238
1303
|
}
|
|
@@ -1262,7 +1327,7 @@ class RouterServer {
|
|
|
1262
1327
|
async handlePlanMode(messageId, openId, planContent) {
|
|
1263
1328
|
console.log(`[RouterServer] Received plan_mode for ${messageId}, plan length=${planContent.length}`);
|
|
1264
1329
|
const streamData = this.streamingMessages.get(messageId);
|
|
1265
|
-
if (!streamData) {
|
|
1330
|
+
if (!streamData || streamData.finalizing) {
|
|
1266
1331
|
console.log(`[RouterServer] No streaming session found for ${messageId}`);
|
|
1267
1332
|
return;
|
|
1268
1333
|
}
|
|
@@ -1289,6 +1354,8 @@ class RouterServer {
|
|
|
1289
1354
|
if (!image || image.type !== 'image' || typeof image.data !== 'string' || typeof image.mimeType !== 'string')
|
|
1290
1355
|
return;
|
|
1291
1356
|
const imageKey = await this.feishuLongConnHandler.uploadImage(image.data, image.mimeType);
|
|
1357
|
+
if (streamData.finalizing || this.streamingMessages.get(messageId) !== streamData)
|
|
1358
|
+
return;
|
|
1292
1359
|
if (!imageKey) {
|
|
1293
1360
|
streamData.elements.push((0, ToolFormatter_1.createMarkdownElement)('ā ļø Generated image could not be uploaded to Feishu.'));
|
|
1294
1361
|
return;
|
|
@@ -1410,6 +1477,7 @@ class RouterServer {
|
|
|
1410
1477
|
elements: [(0, ToolFormatter_1.createMarkdownElement)(intro)], currentTextContent: '', hasUpdated: false,
|
|
1411
1478
|
createdAt: Date.now(), updatePending: false, finalizing: false, lastRenderedTextLength: 0,
|
|
1412
1479
|
delegationProgress: new Map(),
|
|
1480
|
+
toolCalls: new Map(),
|
|
1413
1481
|
recoveryId: info.recoveryId, recoveryPlainText: true, recoveryCwd: info.cwd,
|
|
1414
1482
|
});
|
|
1415
1483
|
this.cardThreadMap.set(cardId, { threadId, deviceId, expiresAt: Date.now() + this.CARD_THREAD_MAP_TTL_MS });
|
|
@@ -1475,6 +1543,7 @@ class RouterServer {
|
|
|
1475
1543
|
finalizing: false,
|
|
1476
1544
|
lastRenderedTextLength: 0,
|
|
1477
1545
|
delegationProgress: new Map(),
|
|
1546
|
+
toolCalls: new Map(),
|
|
1478
1547
|
queueStarted: info,
|
|
1479
1548
|
threads: Array.isArray(message.threads) ? message.threads : undefined,
|
|
1480
1549
|
});
|
|
@@ -1571,7 +1640,7 @@ class RouterServer {
|
|
|
1571
1640
|
const errorMsg = error || 'Command failed';
|
|
1572
1641
|
finalElements.push((0, ToolFormatter_1.createMarkdownElement)(`\n\nā **Error:** ${errorMsg}`));
|
|
1573
1642
|
}
|
|
1574
|
-
const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata);
|
|
1643
|
+
const finalized = await this.feishuLongConnHandler.finalizeStreamingMessage(feishuMessageId, finalElements, undefined, openId, cwd, streamData.threadName, streamData.threads, streamData.threadId, queueConfirmation, executionMetadata, false);
|
|
1575
1644
|
if (finalized === false)
|
|
1576
1645
|
throw new Error('Failed to finalize task card');
|
|
1577
1646
|
}
|