@yu_robotics/remote-cli-router 1.6.271 → 1.6.272
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/feishu/FeishuLongConnHandler.d.ts +11 -6
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +142 -106
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/feishu/ScheduleCards.d.ts.map +1 -1
- package/dist/feishu/ScheduleCards.js +7 -4
- package/dist/feishu/ScheduleCards.js.map +1 -1
- package/dist/files/AutomaticFileEnrollment.d.ts +1 -0
- package/dist/files/AutomaticFileEnrollment.d.ts.map +1 -1
- package/dist/files/AutomaticFileEnrollment.js +20 -6
- package/dist/files/AutomaticFileEnrollment.js.map +1 -1
- package/dist/files/FileTransfers.d.ts.map +1 -1
- package/dist/files/FileTransfers.js +29 -10
- package/dist/files/FileTransfers.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +69 -24
- package/dist/server.js.map +1 -1
- package/dist/storage/CardThreadState.d.ts +1 -0
- package/dist/storage/CardThreadState.d.ts.map +1 -1
- package/dist/storage/CardThreadState.js +6 -3
- package/dist/storage/CardThreadState.js.map +1 -1
- package/dist/websocket/ConnectionHub.js +2 -1
- package/dist/websocket/ConnectionHub.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,6 +18,11 @@ export interface FeishuLongConnHandlerConfig {
|
|
|
18
18
|
appSecret: string;
|
|
19
19
|
store: JsonStore;
|
|
20
20
|
}
|
|
21
|
+
interface CardDeliveryOptions {
|
|
22
|
+
bare?: boolean;
|
|
23
|
+
current?: () => Promise<boolean>;
|
|
24
|
+
onDelivered?: (cardIds: string[], queueCardId?: string) => void | Promise<void>;
|
|
25
|
+
}
|
|
21
26
|
/**
|
|
22
27
|
* Feishu Long Connection Handler
|
|
23
28
|
* Uses Feishu SDK's WSClient for WebSocket long connection
|
|
@@ -31,6 +36,7 @@ export declare class FeishuLongConnHandler {
|
|
|
31
36
|
private client;
|
|
32
37
|
private wsClient;
|
|
33
38
|
private bindingManager;
|
|
39
|
+
private readonly store;
|
|
34
40
|
private connectionHub;
|
|
35
41
|
private appId;
|
|
36
42
|
private appSecret;
|
|
@@ -131,6 +137,7 @@ export declare class FeishuLongConnHandler {
|
|
|
131
137
|
*/
|
|
132
138
|
private onResolveActiveThread?;
|
|
133
139
|
onRecoverThreads?: (openId: string, deviceId: string, messageId: string, fence?: SelectionFence) => Promise<boolean>;
|
|
140
|
+
onCommandNotSent?: (messageId: string) => Promise<void>;
|
|
134
141
|
/**
|
|
135
142
|
* Set active thread resolution callback
|
|
136
143
|
*/
|
|
@@ -230,6 +237,7 @@ export declare class FeishuLongConnHandler {
|
|
|
230
237
|
* Send message to user
|
|
231
238
|
*/
|
|
232
239
|
sendMessage(openId: string, text: string): Promise<boolean>;
|
|
240
|
+
sendMessageWithReceipt(openId: string, text: string): Promise<string | null>;
|
|
233
241
|
/**
|
|
234
242
|
* Send streaming message with card update support
|
|
235
243
|
* Returns message_id for updating
|
|
@@ -351,11 +359,7 @@ export declare class FeishuLongConnHandler {
|
|
|
351
359
|
* @param openId User's open_id for creating continuation messages
|
|
352
360
|
* @param replyThreadId Thread that produced the reply, independent of the selected thread
|
|
353
361
|
*/
|
|
354
|
-
finalizeStreamingMessage(messageId: string, elements: any[], sessionAbbr?: string, openId?: string, cwd?: string, threadName?: string, threads?: ThreadSummary[], replyThreadId?: string, queueConfirmation?: QueueConfirmationInfo, executionMetadata?: ExecutionMetadata, success?: boolean, options?:
|
|
355
|
-
bare?: boolean;
|
|
356
|
-
current?: () => Promise<boolean>;
|
|
357
|
-
onDelivered?: (cardIds: string[]) => void | Promise<void>;
|
|
358
|
-
}): Promise<boolean>;
|
|
362
|
+
finalizeStreamingMessage(messageId: string, elements: any[], sessionAbbr?: string, openId?: string, cwd?: string, threadName?: string, threads?: ThreadSummary[], replyThreadId?: string, queueConfirmation?: QueueConfirmationInfo, executionMetadata?: ExecutionMetadata, success?: boolean, options?: CardDeliveryOptions): Promise<boolean>;
|
|
359
363
|
private _finalizeStreamingMessage;
|
|
360
364
|
/**
|
|
361
365
|
* Create Feishu Card 2.0 elements for thread switching buttons.
|
|
@@ -392,7 +396,7 @@ export declare class FeishuLongConnHandler {
|
|
|
392
396
|
/** Register confirmed work; capable clients request a card when execution starts. */
|
|
393
397
|
sendQueueActionFromCardAction(openId: string, action: 'confirm' | 'cancel', queueId: string, threadId: string, cardMessageId?: string): Promise<'sent' | 'already_processed'>;
|
|
394
398
|
/** Leave a historical queue receipt after output moves to a new card. */
|
|
395
|
-
markQueueCardStarted(cardMessageId: string): Promise<void>;
|
|
399
|
+
markQueueCardStarted(cardMessageId: string, current?: () => boolean): Promise<void>;
|
|
396
400
|
private removeExpiredQueueActionStates;
|
|
397
401
|
private updateQueueConfirmationCard;
|
|
398
402
|
/**
|
|
@@ -408,4 +412,5 @@ export declare class FeishuLongConnHandler {
|
|
|
408
412
|
*/
|
|
409
413
|
getBindingManager(): BindingManager;
|
|
410
414
|
}
|
|
415
|
+
export {};
|
|
411
416
|
//# sourceMappingURL=FeishuLongConnHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeishuLongConnHandler.d.ts","sourceRoot":"","sources":["../../src/feishu/FeishuLongConnHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAMjE,OAAO,EAAE,cAAc,EAAE,KAAK,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAA4B,aAAa,EAAc,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtG,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC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
80
81
|
appSecret;
|
|
@@ -112,6 +113,7 @@ class FeishuLongConnHandler {
|
|
|
112
113
|
constructor(config) {
|
|
113
114
|
this.appId = config.appId;
|
|
114
115
|
this.appSecret = config.appSecret;
|
|
116
|
+
this.store = config.store;
|
|
115
117
|
this.bindingManager = new BindingManager_1.BindingManager(config.store);
|
|
116
118
|
// Initialize Feishu SDK client for API calls
|
|
117
119
|
this.client = new lark.Client({
|
|
@@ -198,6 +200,7 @@ class FeishuLongConnHandler {
|
|
|
198
200
|
*/
|
|
199
201
|
onResolveActiveThread;
|
|
200
202
|
onRecoverThreads;
|
|
203
|
+
onCommandNotSent;
|
|
201
204
|
/**
|
|
202
205
|
* Set active thread resolution callback
|
|
203
206
|
*/
|
|
@@ -446,31 +449,32 @@ class FeishuLongConnHandler {
|
|
|
446
449
|
* Handle slash command passthrough to client
|
|
447
450
|
* Passes unknown slash commands to the local Claude Code instance
|
|
448
451
|
*/
|
|
449
|
-
async handleSlashCommandPassthrough(openId, messageId, content, command, threadId, threadName, sourceDeviceId, useActiveThread = false, originalFence) {
|
|
452
|
+
async handleSlashCommandPassthrough(openId, messageId, content, command, threadId, threadName, sourceDeviceId, useActiveThread = false, originalFence, fromMenu = false) {
|
|
453
|
+
const fail = async (message) => {
|
|
454
|
+
if (fromMenu)
|
|
455
|
+
return message;
|
|
456
|
+
await this.replyToMessage(messageId, message);
|
|
457
|
+
};
|
|
450
458
|
try {
|
|
451
459
|
// Find user binding
|
|
452
460
|
const binding = await this.bindingManager.getUserBinding(openId);
|
|
453
461
|
if (!binding) {
|
|
454
|
-
|
|
455
|
-
return;
|
|
462
|
+
return fail('❌ You have not bound a device yet, please send /bind <binding-code> to bind first');
|
|
456
463
|
}
|
|
457
464
|
// Resolve the destination and selection together.
|
|
458
465
|
const activeDevice = sourceDeviceId
|
|
459
466
|
? binding.devices.find((device) => device.deviceId === sourceDeviceId)
|
|
460
467
|
: await this.bindingManager.getActiveDevice(openId);
|
|
461
468
|
if (!activeDevice) {
|
|
462
|
-
|
|
463
|
-
return;
|
|
469
|
+
return fail('❌ No active device found. Please use /device list to view your devices');
|
|
464
470
|
}
|
|
465
471
|
// Check if ConnectionHub is available
|
|
466
472
|
if (!this.connectionHub) {
|
|
467
|
-
|
|
468
|
-
return;
|
|
473
|
+
return fail('❌ Server error: ConnectionHub not initialized');
|
|
469
474
|
}
|
|
470
475
|
// Check if device is online
|
|
471
476
|
if (!this.connectionHub.isDeviceOnline(activeDevice.deviceId)) {
|
|
472
|
-
|
|
473
|
-
return;
|
|
477
|
+
return fail(`❌ Device ${activeDevice.deviceName} is currently offline, please ensure the device is started and connected to the server`);
|
|
474
478
|
}
|
|
475
479
|
if (useActiveThread && (content.trim() === '/thread' || content.trim() === '/thread list')
|
|
476
480
|
&& await this.onRecoverThreads?.(openId, activeDevice.deviceId, messageId))
|
|
@@ -483,16 +487,14 @@ class FeishuLongConnHandler {
|
|
|
483
487
|
}
|
|
484
488
|
catch (error) {
|
|
485
489
|
if (error instanceof Error && error.message.startsWith('Saved thread selection is invalid')) {
|
|
486
|
-
|
|
487
|
-
return;
|
|
490
|
+
return fail(`❌ ${error.message}`);
|
|
488
491
|
}
|
|
489
492
|
throw error;
|
|
490
493
|
}
|
|
491
494
|
}
|
|
492
495
|
const selectionFence = originalFence ?? this.onCaptureSelection?.(openId, activeDevice.deviceId);
|
|
493
496
|
if (selectionFence && this.onValidateSelection && !this.onValidateSelection(selectionFence)) {
|
|
494
|
-
|
|
495
|
-
return;
|
|
497
|
+
return fail('The device or thread selection changed. Reopen /skills.');
|
|
496
498
|
}
|
|
497
499
|
console.log(`[FeishuHandler] Passing through slash command: ${command}${threadId ? ` (threadId=${threadId})` : ''}`);
|
|
498
500
|
// Generate message ID first
|
|
@@ -501,17 +503,17 @@ class FeishuLongConnHandler {
|
|
|
501
503
|
const feishuMessageId = await this.sendStreamingStart(openId, `🤔 Executing ${command}...`, threadName, undefined, commandMessageId);
|
|
502
504
|
const currentBinding = await this.bindingManager.getUserBinding(openId);
|
|
503
505
|
if (!currentBinding?.devices.some((device) => device.deviceId === activeDevice.deviceId)) {
|
|
504
|
-
|
|
506
|
+
return fail('Device ownership changed before the command could be sent. Reopen /skills.');
|
|
505
507
|
}
|
|
506
508
|
if (selectionFence && this.onValidateSelection && !this.onValidateSelection(selectionFence)) {
|
|
507
|
-
|
|
509
|
+
return fail('This command was superseded or the device changed before it could be sent. Reopen /skills.');
|
|
508
510
|
}
|
|
509
511
|
console.log(`[FeishuHandler] Created card ${feishuMessageId} for slash command ${commandMessageId}`);
|
|
510
512
|
if (this.onStartStreaming) {
|
|
511
513
|
await this.onStartStreaming(commandMessageId, openId, feishuMessageId, activeDevice.deviceId, threadId, false, undefined, threadName, selectionFence);
|
|
512
514
|
}
|
|
513
515
|
if (selectionFence && this.onValidateSelection && !this.onValidateSelection(selectionFence)) {
|
|
514
|
-
|
|
516
|
+
return fail('This command was superseded or the device changed before it could be sent. Reopen /skills.');
|
|
515
517
|
}
|
|
516
518
|
// Send slash command to device - the client will execute it locally
|
|
517
519
|
const success = await this.connectionHub.sendToDevice(activeDevice.deviceId, {
|
|
@@ -524,12 +526,12 @@ class FeishuLongConnHandler {
|
|
|
524
526
|
threadId, // Forward threadId to CLI for per-thread routing
|
|
525
527
|
});
|
|
526
528
|
if (!success) {
|
|
527
|
-
|
|
529
|
+
return fail('❌ Command sending failed, please try again later');
|
|
528
530
|
}
|
|
529
531
|
}
|
|
530
532
|
catch (error) {
|
|
531
533
|
console.error('Error handling slash command passthrough:', error);
|
|
532
|
-
|
|
534
|
+
return fail('❌ Error processing command, please try again later');
|
|
533
535
|
}
|
|
534
536
|
}
|
|
535
537
|
/**
|
|
@@ -823,17 +825,25 @@ class FeishuLongConnHandler {
|
|
|
823
825
|
const state = this.commandMenus.get(cardId);
|
|
824
826
|
if (!state || state.openId !== openId || state.expires <= Date.now())
|
|
825
827
|
throw new Error('Reopen /skills for a fresh menu.');
|
|
828
|
+
const validate = () => {
|
|
829
|
+
if (this.commandMenus.get(cardId) !== state || state.expires <= Date.now())
|
|
830
|
+
throw new Error('Reopen /skills for a fresh menu.');
|
|
831
|
+
if (state.fence && !this.onValidateSelection?.(state.fence))
|
|
832
|
+
throw new Error('Selection changed. Reopen /skills.');
|
|
833
|
+
};
|
|
834
|
+
validate();
|
|
826
835
|
return state.menu.click(action, form, async (elements) => {
|
|
836
|
+
validate();
|
|
827
837
|
const result = await this.client.im.message.patch({ path: { message_id: cardId },
|
|
828
838
|
data: { content: JSON.stringify({ schema: '2.0', header: CommandMenu_1.commandMenuHeader, body: { elements } }) } });
|
|
829
839
|
if (result.code)
|
|
830
840
|
throw new Error('Menu update failed.');
|
|
831
841
|
}, async (content) => {
|
|
832
842
|
const [command, operation, target] = content.split(/\s+/);
|
|
833
|
-
|
|
834
|
-
throw new Error('Selection changed. Reopen /skills.');
|
|
843
|
+
validate();
|
|
835
844
|
if (command === '/device' && (operation === 'switch' || operation === 'unbind')) {
|
|
836
845
|
const binding = await this.bindingManager.getUserBinding(openId);
|
|
846
|
+
validate();
|
|
837
847
|
const epoch = state.deviceEpochs.get(target);
|
|
838
848
|
if (!binding || !epoch || this.bindingManager.getCardThreadEpoch(openId, target) !== epoch
|
|
839
849
|
|| !binding.devices.some(device => device.deviceId === target))
|
|
@@ -853,7 +863,9 @@ class FeishuLongConnHandler {
|
|
|
853
863
|
if (command === '/thread' && content === '/thread list' && state.topLevel
|
|
854
864
|
&& await this.onRecoverThreads?.(openId, state.deviceId, cardId, state.fence))
|
|
855
865
|
return;
|
|
856
|
-
await this.handleSlashCommandPassthrough(openId, cardId, content, command, state.threadId, state.threadName, state.deviceId, false, state.fence);
|
|
866
|
+
const failure = await this.handleSlashCommandPassthrough(openId, cardId, content, command, state.threadId, state.threadName, state.deviceId, false, state.fence, true);
|
|
867
|
+
if (failure)
|
|
868
|
+
throw new Error(failure);
|
|
857
869
|
});
|
|
858
870
|
}
|
|
859
871
|
async handleHelpCommand(openId, messageId) {
|
|
@@ -914,6 +926,7 @@ Examples:
|
|
|
914
926
|
* Handle regular command (non-slash commands)
|
|
915
927
|
*/
|
|
916
928
|
async handleRegularCommand(openId, messageId, content, threadId, pendingNewThread = false, threadName, attachments, fileReference, sourceDeviceId, useActiveThread = false, selectionIntent) {
|
|
929
|
+
let unsent;
|
|
917
930
|
try {
|
|
918
931
|
// Find user binding
|
|
919
932
|
const binding = await this.bindingManager.getUserBinding(openId);
|
|
@@ -964,6 +977,7 @@ Examples:
|
|
|
964
977
|
// Register streaming session BEFORE sending command to avoid race condition
|
|
965
978
|
// where stream chunks arrive before registration
|
|
966
979
|
const feishuMessageId = await this.sendStreamingStart(openId, attachments ? '🖼️ Processing image...' : '🤔 Processing...', threadName, undefined, commandMessageId);
|
|
980
|
+
unsent = { commandId: commandMessageId, cardId: feishuMessageId };
|
|
967
981
|
const currentBinding = await this.bindingManager.getUserBinding(openId);
|
|
968
982
|
if (!currentBinding?.devices.some((device) => device.deviceId === activeDevice.deviceId)) {
|
|
969
983
|
throw new Error('Device ownership changed before the command could be sent.');
|
|
@@ -989,16 +1003,24 @@ Examples:
|
|
|
989
1003
|
openId,
|
|
990
1004
|
threadId, // Forward threadId to CLI for per-thread routing
|
|
991
1005
|
});
|
|
992
|
-
if (!success)
|
|
993
|
-
|
|
994
|
-
if (this.onStartStreaming) {
|
|
995
|
-
// We need a way to clean up, for now just send error as new message
|
|
996
|
-
await this.replyToMessage(messageId, '❌ Command sending failed, please try again later');
|
|
997
|
-
}
|
|
998
|
-
}
|
|
1006
|
+
if (!success)
|
|
1007
|
+
throw new Error('Command sending failed.');
|
|
999
1008
|
}
|
|
1000
1009
|
catch (error) {
|
|
1001
1010
|
console.error('Error handling regular command:', error);
|
|
1011
|
+
if (unsent) {
|
|
1012
|
+
const notice = 'Command was not sent. Check the device and thread, then resend your message.';
|
|
1013
|
+
try {
|
|
1014
|
+
await this.onCommandNotSent?.(unsent.commandId);
|
|
1015
|
+
}
|
|
1016
|
+
catch (failure) {
|
|
1017
|
+
(0, DeliveryDiagnostics_1.deliveryEvent)('unsent_command_cleanup_failed', (0, DeliveryDiagnostics_1.safeCardError)(failure));
|
|
1018
|
+
}
|
|
1019
|
+
if (unsent.cardId && await this.finalizeStreamingMessage(unsent.cardId, [{ tag: 'markdown', content: notice }], undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, false, { bare: true }))
|
|
1020
|
+
return;
|
|
1021
|
+
await this.replyToMessage(messageId, notice);
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1002
1024
|
await this.replyToMessage(messageId, '❌ Error processing command, please try again later');
|
|
1003
1025
|
}
|
|
1004
1026
|
}
|
|
@@ -1103,8 +1125,11 @@ Examples:
|
|
|
1103
1125
|
* Send message to user
|
|
1104
1126
|
*/
|
|
1105
1127
|
async sendMessage(openId, text) {
|
|
1128
|
+
return !!await this.sendMessageWithReceipt(openId, text);
|
|
1129
|
+
}
|
|
1130
|
+
async sendMessageWithReceipt(openId, text) {
|
|
1106
1131
|
try {
|
|
1107
|
-
await this.client.im.message.create({
|
|
1132
|
+
const receipt = await this.client.im.message.create({
|
|
1108
1133
|
params: { receive_id_type: 'open_id' },
|
|
1109
1134
|
data: {
|
|
1110
1135
|
receive_id: openId,
|
|
@@ -1112,11 +1137,14 @@ Examples:
|
|
|
1112
1137
|
content: JSON.stringify({ text }),
|
|
1113
1138
|
},
|
|
1114
1139
|
});
|
|
1115
|
-
|
|
1140
|
+
const id = receipt?.data?.message_id;
|
|
1141
|
+
if (receipt?.code || typeof id !== 'string' || !id.trim())
|
|
1142
|
+
throw new Error('Feishu text delivery was not confirmed.');
|
|
1143
|
+
return id;
|
|
1116
1144
|
}
|
|
1117
1145
|
catch (error) {
|
|
1118
1146
|
(0, DeliveryDiagnostics_1.deliveryEvent)('text_message_failed', (0, DeliveryDiagnostics_1.safeCardError)(error));
|
|
1119
|
-
return
|
|
1147
|
+
return null;
|
|
1120
1148
|
}
|
|
1121
1149
|
}
|
|
1122
1150
|
/**
|
|
@@ -1138,7 +1166,7 @@ Examples:
|
|
|
1138
1166
|
content,
|
|
1139
1167
|
},
|
|
1140
1168
|
}));
|
|
1141
|
-
return result?.data?.message_id || null;
|
|
1169
|
+
return result?.code ? null : result?.data?.message_id || null;
|
|
1142
1170
|
}
|
|
1143
1171
|
catch (error) {
|
|
1144
1172
|
// Actual request failures are already aggregated at the send boundary.
|
|
@@ -1839,9 +1867,8 @@ Examples:
|
|
|
1839
1867
|
if (metadataElement)
|
|
1840
1868
|
footerElements.push(metadataElement);
|
|
1841
1869
|
finalElements.push(...elements, ...footerElements);
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
}
|
|
1870
|
+
const queueElements = queueConfirmation ? this.createQueueConfirmationElements(queueConfirmation) : [];
|
|
1871
|
+
finalElements.push(...queueElements);
|
|
1845
1872
|
// Append thread switch buttons when at least one thread exists
|
|
1846
1873
|
let threadSwitchElements = [];
|
|
1847
1874
|
// The reply's owner and the destination of new messages are independent.
|
|
@@ -1875,8 +1902,15 @@ Examples:
|
|
|
1875
1902
|
// card IDs before any callback can arrive.
|
|
1876
1903
|
if (options?.onDelivered) {
|
|
1877
1904
|
const delivered = this.messageChains.get(messageId);
|
|
1878
|
-
if (delivered
|
|
1879
|
-
|
|
1905
|
+
if (delivered?.length) {
|
|
1906
|
+
if (queueElements.length) {
|
|
1907
|
+
const chunks = this.splitElementsIntoChunks(finalElements, headerElements, trailingElements, undefined, keepCompletionWithBody, this.inlineFiles?.hasRoot(messageId));
|
|
1908
|
+
const page = chunks.findIndex(chunk => chunk.includes(queueElements.at(-1)));
|
|
1909
|
+
await options.onDelivered([...delivered], delivered[page]);
|
|
1910
|
+
}
|
|
1911
|
+
else
|
|
1912
|
+
await options.onDelivered([...delivered]);
|
|
1913
|
+
}
|
|
1880
1914
|
}
|
|
1881
1915
|
if (!bare && this.inlineFiles) {
|
|
1882
1916
|
const chunks = this.splitElementsIntoChunks(finalElements, headerElements, trailingElements, undefined, keepCompletionWithBody, this.inlineFiles?.hasRoot(messageId));
|
|
@@ -2134,7 +2168,7 @@ Examples:
|
|
|
2134
2168
|
return { toast };
|
|
2135
2169
|
void click.then(result => {
|
|
2136
2170
|
if (result.type === 'error')
|
|
2137
|
-
return this.
|
|
2171
|
+
return this.replyToMessage(data.context.open_message_id, result.content);
|
|
2138
2172
|
}).catch(() => { });
|
|
2139
2173
|
return { toast: { type: 'info', content: 'Processing your selection.' } };
|
|
2140
2174
|
}
|
|
@@ -2294,11 +2328,13 @@ Examples:
|
|
|
2294
2328
|
if (queueActionResult === 'already_processed') {
|
|
2295
2329
|
return { toast: { type: 'info', content: 'This queue request was already processed' } };
|
|
2296
2330
|
}
|
|
2297
|
-
|
|
2331
|
+
if (queueActionResult !== 'sent')
|
|
2332
|
+
throw new Error('Queue action unavailable.');
|
|
2333
|
+
return { toast: { type: 'info', content: parsed.action === 'queue_confirm' ? 'Queue confirmation sent' : 'Queue cancellation sent' } };
|
|
2298
2334
|
}
|
|
2299
2335
|
catch (error) {
|
|
2300
2336
|
(0, DeliveryDiagnostics_1.deliveryEvent)('card_queue_action_failed', (0, DeliveryDiagnostics_1.safeCardError)(error));
|
|
2301
|
-
return { toast: { type: 'error', content: 'Queue action failed' } };
|
|
2337
|
+
return { toast: { type: 'error', content: 'Queue action failed. Check /queue on the original device.' } };
|
|
2302
2338
|
}
|
|
2303
2339
|
}
|
|
2304
2340
|
}
|
|
@@ -2314,83 +2350,79 @@ Examples:
|
|
|
2314
2350
|
}
|
|
2315
2351
|
/** Register confirmed work; capable clients request a card when execution starts. */
|
|
2316
2352
|
async sendQueueActionFromCardAction(openId, action, queueId, threadId, cardMessageId) {
|
|
2353
|
+
const route = cardMessageId && this.store.getCardThread(cardMessageId);
|
|
2354
|
+
if (!cardMessageId || !route || route.queueId !== queueId || route.openId !== openId || route.threadId !== threadId) {
|
|
2355
|
+
throw new Error('This queue card has expired. Use /queue on the original device.');
|
|
2356
|
+
}
|
|
2357
|
+
const { deviceId, epoch } = route;
|
|
2358
|
+
const fence = this.onCaptureSelection?.(openId, deviceId);
|
|
2359
|
+
const current = () => this.store.getCardThread(cardMessageId) === route
|
|
2360
|
+
&& (!fence || (fence.epoch === epoch && this.onValidateSelection?.(fence) === true));
|
|
2361
|
+
const device = await this.bindingManager.getActiveDevice(openId);
|
|
2362
|
+
const hub = this.connectionHub;
|
|
2363
|
+
if (!current() || device?.deviceId !== deviceId || !hub?.isDeviceOnline(deviceId)) {
|
|
2364
|
+
throw new Error('The original device changed or is offline.');
|
|
2365
|
+
}
|
|
2317
2366
|
this.removeExpiredQueueActionStates();
|
|
2318
|
-
const
|
|
2319
|
-
|
|
2367
|
+
const key = JSON.stringify([openId, deviceId, epoch, threadId, queueId]);
|
|
2368
|
+
const previous = this.queueActionStates.get(key);
|
|
2369
|
+
if (previous) {
|
|
2370
|
+
await previous.sent;
|
|
2320
2371
|
return 'already_processed';
|
|
2321
2372
|
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
const
|
|
2334
|
-
|
|
2335
|
-
:
|
|
2336
|
-
try {
|
|
2337
|
-
await this.onStartStreaming?.(executionMessageId, openId, feishuMessageId, activeDevice.deviceId, threadId, false, cardMessageId, undefined, selectionFence);
|
|
2338
|
-
}
|
|
2339
|
-
catch (error) {
|
|
2340
|
-
// No command was sent. A failed durable route must not consume the confirmation.
|
|
2341
|
-
this.queueActionStates.delete(queueId);
|
|
2342
|
-
throw error;
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
if (selectionFence && this.onValidateSelection && !this.onValidateSelection(selectionFence)) {
|
|
2346
|
-
this.queueActionStates.delete(queueId);
|
|
2347
|
-
throw new Error('This queue action was superseded or the device changed before it could be sent.');
|
|
2348
|
-
}
|
|
2349
|
-
const controlMessageId = (0, uuid_1.v4)();
|
|
2350
|
-
const suffix = executionMessageId ? ` ${executionMessageId}` : '';
|
|
2351
|
-
// An idle thread can start immediately. Its receipt must not be patched
|
|
2352
|
-
// back to "waiting" after the start event has already arrived.
|
|
2353
|
-
let finishDecision;
|
|
2354
|
-
const decision = new Promise((resolve) => { finishDecision = resolve; });
|
|
2355
|
-
if (cardMessageId)
|
|
2356
|
-
this.queueCardDecisions.set(cardMessageId, decision);
|
|
2357
|
-
try {
|
|
2358
|
-
const success = await this.connectionHub.sendToDevice(activeDevice.deviceId, {
|
|
2359
|
-
type: types_1.MessageType.COMMAND,
|
|
2360
|
-
messageId: controlMessageId,
|
|
2361
|
-
timestamp: Date.now(),
|
|
2362
|
-
content: `/queue ${action} ${queueId}${suffix}`,
|
|
2363
|
-
openId,
|
|
2364
|
-
threadId,
|
|
2373
|
+
const send = async () => {
|
|
2374
|
+
let executionId;
|
|
2375
|
+
if (action === 'confirm') {
|
|
2376
|
+
executionId = (0, uuid_1.v4)();
|
|
2377
|
+
const placeholder = hub.supportsQueueStarted(deviceId) ? null
|
|
2378
|
+
: await this.sendStreamingStart(openId, 'Requesting queue confirmation...', undefined, undefined, executionId);
|
|
2379
|
+
await this.onStartStreaming?.(executionId, openId, placeholder, deviceId, threadId, false, cardMessageId, undefined, fence);
|
|
2380
|
+
}
|
|
2381
|
+
if (!current())
|
|
2382
|
+
throw new Error('The device changed before the queue action could be sent.');
|
|
2383
|
+
const suffix = executionId ? ` ${executionId}` : '';
|
|
2384
|
+
const sent = await hub.sendToDevice(deviceId, {
|
|
2385
|
+
type: types_1.MessageType.COMMAND, messageId: (0, uuid_1.v4)(), timestamp: Date.now(),
|
|
2386
|
+
content: `/queue ${action} ${queueId}${suffix}`, openId, threadId,
|
|
2365
2387
|
});
|
|
2366
|
-
if (!
|
|
2388
|
+
if (!sent)
|
|
2367
2389
|
throw new Error('Failed to send queue action to device');
|
|
2368
|
-
|
|
2369
|
-
|
|
2390
|
+
await this.updateQueueConfirmationCard(cardMessageId, action, current);
|
|
2391
|
+
};
|
|
2392
|
+
const sent = Promise.resolve().then(send);
|
|
2393
|
+
this.queueActionStates.set(key, { sent, processedAt: Date.now() });
|
|
2394
|
+
// An idle thread can start before the send promise settles.
|
|
2395
|
+
this.queueCardDecisions.set(cardMessageId, sent);
|
|
2396
|
+
try {
|
|
2397
|
+
await sent;
|
|
2370
2398
|
return 'sent';
|
|
2371
2399
|
}
|
|
2372
2400
|
catch (error) {
|
|
2373
|
-
this.queueActionStates.delete(
|
|
2401
|
+
this.queueActionStates.delete(key);
|
|
2374
2402
|
throw error;
|
|
2375
2403
|
}
|
|
2376
2404
|
finally {
|
|
2377
|
-
|
|
2378
|
-
if (cardMessageId)
|
|
2379
|
-
this.queueCardDecisions.delete(cardMessageId);
|
|
2405
|
+
this.queueCardDecisions.delete(cardMessageId);
|
|
2380
2406
|
}
|
|
2381
2407
|
}
|
|
2382
2408
|
/** Leave a historical queue receipt after output moves to a new card. */
|
|
2383
|
-
async markQueueCardStarted(cardMessageId) {
|
|
2409
|
+
async markQueueCardStarted(cardMessageId, current = () => true) {
|
|
2384
2410
|
await this.queueCardDecisions.get(cardMessageId);
|
|
2385
|
-
await this.withMessageLock(cardMessageId, () =>
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2411
|
+
await this.withMessageLock(cardMessageId, async () => {
|
|
2412
|
+
if (!current())
|
|
2413
|
+
return;
|
|
2414
|
+
const result = await this.client.im.message.patch({
|
|
2415
|
+
path: { message_id: cardMessageId },
|
|
2416
|
+
data: {
|
|
2417
|
+
content: JSON.stringify({
|
|
2418
|
+
schema: '2.0',
|
|
2419
|
+
body: { elements: [{ tag: 'markdown', content: "<text_tag color='blue'>Running</text_tag>\n\nThe queued message is now running. Follow progress in the new execution card." }] },
|
|
2420
|
+
}),
|
|
2421
|
+
},
|
|
2422
|
+
});
|
|
2423
|
+
if (result?.code)
|
|
2424
|
+
throw new Error('Queue start card update failed.');
|
|
2425
|
+
});
|
|
2394
2426
|
}
|
|
2395
2427
|
removeExpiredQueueActionStates() {
|
|
2396
2428
|
const expiry = Date.now() - this.QUEUE_ACTION_STATE_TTL_MS;
|
|
@@ -2400,13 +2432,15 @@ Examples:
|
|
|
2400
2432
|
}
|
|
2401
2433
|
}
|
|
2402
2434
|
}
|
|
2403
|
-
async updateQueueConfirmationCard(cardMessageId, action) {
|
|
2435
|
+
async updateQueueConfirmationCard(cardMessageId, action, current) {
|
|
2404
2436
|
const content = action === 'confirm'
|
|
2405
|
-
? "
|
|
2406
|
-
: "
|
|
2437
|
+
? "Queue confirmation sent. See the CLI response or use /queue to check its status. If the queue is paused, use /queue continue to resume."
|
|
2438
|
+
: "Queue cancellation sent. See the CLI response or use /queue to check its status.";
|
|
2407
2439
|
try {
|
|
2408
2440
|
await this.withMessageLock(cardMessageId, async () => {
|
|
2409
|
-
|
|
2441
|
+
if (!current())
|
|
2442
|
+
return;
|
|
2443
|
+
const result = await this.client.im.message.patch({
|
|
2410
2444
|
path: { message_id: cardMessageId },
|
|
2411
2445
|
data: {
|
|
2412
2446
|
content: JSON.stringify({
|
|
@@ -2415,6 +2449,8 @@ Examples:
|
|
|
2415
2449
|
}),
|
|
2416
2450
|
},
|
|
2417
2451
|
});
|
|
2452
|
+
if (result?.code)
|
|
2453
|
+
throw new Error('Queue confirmation card update failed.');
|
|
2418
2454
|
});
|
|
2419
2455
|
}
|
|
2420
2456
|
catch (error) {
|