@yu_robotics/remote-cli-router 1.6.166 → 1.6.169
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 +13 -0
- package/dist/feishu/FeishuLongConnHandler.d.ts +10 -1
- package/dist/feishu/FeishuLongConnHandler.d.ts.map +1 -1
- package/dist/feishu/FeishuLongConnHandler.js +172 -29
- package/dist/feishu/FeishuLongConnHandler.js.map +1 -1
- package/dist/feishu/SettingsCards.d.ts +1 -0
- package/dist/feishu/SettingsCards.d.ts.map +1 -1
- package/dist/feishu/SettingsCards.js +79 -3
- package/dist/feishu/SettingsCards.js.map +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +16 -4
- package/dist/server.js.map +1 -1
- package/dist/types/Settings.d.ts +12 -2
- package/dist/types/Settings.d.ts.map +1 -1
- package/dist/utils/ToolFormatter.d.ts +1 -0
- package/dist/utils/ToolFormatter.d.ts.map +1 -1
- package/dist/utils/ToolFormatter.js +4 -2
- package/dist/utils/ToolFormatter.js.map +1 -1
- package/dist/utils/WorkerResultMarkdown.d.ts.map +1 -1
- package/dist/utils/WorkerResultMarkdown.js +6 -0
- package/dist/utils/WorkerResultMarkdown.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ Backend executable discovery is local-client behavior. CLI 1.6.119 supplements L
|
|
|
6
6
|
|
|
7
7
|
## Public Activity
|
|
8
8
|
|
|
9
|
+
From Router 1.6.169, reply-card thread lists start collapsed. Use **Show threads** to expand the list in the same card, or **Switch to this thread** to select the thread that produced the reply. Opening or hiding the list does not change the input target; a successful switch hides the list and confirms the new target without changing the reply's source label. No separate thread-management card is sent. The recursive element budget is 180 instead of 150, with room reserved for the expanded controls; table and size thresholds are unchanged. This presentation update requires the newer Router, not a new CLI protocol capability.
|
|
10
|
+
|
|
9
11
|
From Router 1.6.158, completion pagination keeps the final body item (or complete worker group) with the completion note, optional model metadata and thread controls when they fit together. This avoids preventable footer-only continuations, including replies without model metadata. Indivisible oversized groups still split according to node, size and table limits; thread-button refreshes preserve the final body. This does not change streaming completion timing or the wire protocol.
|
|
10
12
|
|
|
11
13
|
From CLI 1.6.153, Codex shell calls no longer lose their label when native command actions are absent or unknown. Native reads, searches, and directory listings remain preferred. Other calls use fixed operation labels such as `Run npm command` or `Run Git command` for simple allowlisted programs, and `Run shell command` for compound or unrecognized commands. These are deterministic operation labels, not model-authored purpose summaries: installed Codex 0.160.0 command items have no per-call description field. Arguments, full paths, output, and execution-wide reasoning are never copied into these fallback labels. Late native action metadata can enrich a pending row before its first result; repeated results retain one row. Existing description fields, heading limits, and card-node counts are unchanged; upgrade the CLI, with no new Router capability required.
|
|
@@ -230,6 +232,15 @@ bound retained delegation results, not backend output buffers. Worker timeouts,
|
|
|
230
232
|
cancellation, and cleanup still apply. This requires a local CLI upgrade and
|
|
231
233
|
works with existing Routers.
|
|
232
234
|
|
|
235
|
+
With CLI and Router 1.6.167 or newer, terminal Worker card excerpts retain up to
|
|
236
|
+
4 KiB of UTF-8 text. Excerpts containing standalone omission markers are shown
|
|
237
|
+
as escaped plain text with a separate explanation rather than interpreting
|
|
238
|
+
contextless Markdown fragments. Intact result Markdown is preserved. Upgrade
|
|
239
|
+
both peers for the larger preview; newer Routers also safely display older
|
|
240
|
+
CLI omission markers. Older or unknown Routers keep the legacy 1000-byte
|
|
241
|
+
head/tail summary, including after reconnect. The 32 KiB result and 64 KiB
|
|
242
|
+
continuation limits stay unchanged.
|
|
243
|
+
|
|
233
244
|
CLI 1.6.89 can compact/retry result continuations that launched no new workers.
|
|
234
245
|
Results remain retained until the coordinator execution succeeds. If its reply
|
|
235
246
|
still fails, bounded completed worker results appear as plain text alongside the
|
|
@@ -320,6 +331,8 @@ The Feishu command reference includes the cross-backend `/status`, `/context`, a
|
|
|
320
331
|
|
|
321
332
|
CLI 1.6.93 makes `/cd` to a different directory start fresh conversations for all backends in that thread, including inactive ones. Returning to the old directory does not restore its old conversations. Same-directory `/cd` and backend-only switches preserve context. Thread settings and native history files remain intact. The CLI enforces this behavior without a protocol change; upgrading only the Router does not change an older CLI's directory behavior.
|
|
322
333
|
|
|
334
|
+
From 1.6.168, `directoryCards` is an optional capability requiring `settingsCards` on both peers. Bare `/cd` becomes a directory-only browser; older peers retain text `/cd <path>`. Router reuses settings-card owner/device/delivered-card/revision binding, pending suppression, and exact-request confirmation. Child, Parent, roots, and refresh actions query the original CLI with opaque tokens; Router never reads the CLI filesystem. Only Use this directory applies a cwd change; Cancel closes locally. Navigation leaves context unchanged. The CLI checks policy, snapshot, directory/ancestor identity, busy/queue state, and shared mutation admission at Apply. Large lists use budget-driven paging and bounded scans with explicit omissions. Directory symlinks are omitted, and Parent stops at the nearest allowed root. These checks are not an OS sandbox or complete protection from concurrent filesystem changes or bind mounts. Protocol version remains 1.
|
|
335
|
+
|
|
323
336
|
With CLI 1.6.84 or newer, `/status` also shows `Delegation: on/off (current thread)`.
|
|
324
337
|
The CLI reads this effective setting without initializing delegation or starting workers.
|
|
325
338
|
|
|
@@ -84,6 +84,8 @@ export declare class FeishuLongConnHandler {
|
|
|
84
84
|
* RouterServer sets this directly after construction.
|
|
85
85
|
*/
|
|
86
86
|
onCardNewThread?: (openId: string) => Promise<void>;
|
|
87
|
+
/** Latest device-reported inventory; missing inventory fails closed for new controls. */
|
|
88
|
+
onCardThreadExists?: (deviceId: string, threadId: string) => boolean;
|
|
87
89
|
/** Callback invoked when a user confirms or cancels a queued command. */
|
|
88
90
|
onApprovalAction?: (openId: string, requestId: string, cardId: string, decision: string) => Promise<string>;
|
|
89
91
|
onMaintenanceAction?: (openId: string, id: string, cardId: string, action: string, offset?: number) => Promise<string>;
|
|
@@ -227,7 +229,7 @@ export declare class FeishuLongConnHandler {
|
|
|
227
229
|
* Split Card 2.0 elements into chunks based on Feishu limits
|
|
228
230
|
*
|
|
229
231
|
* Card packing budgets:
|
|
230
|
-
* 1. Element count: Max 200 tagged nodes per card (we use
|
|
232
|
+
* 1. Element count: Max 200 tagged nodes per card (we use 180 for safety)
|
|
231
233
|
* 2. Data size: Max 3,000,000 characters in the data field (JSON.stringify result)
|
|
232
234
|
* 3. Tables: A conservative budget including tables embedded in Markdown
|
|
233
235
|
*
|
|
@@ -248,6 +250,7 @@ export declare class FeishuLongConnHandler {
|
|
|
248
250
|
* According to Feishu docs, all nodes with 'tag' property count towards the 200 limit
|
|
249
251
|
*
|
|
250
252
|
* @param obj The object or array to count tags in
|
|
253
|
+
* @param reserveWorkerErrors Reserve a future error row for each Worker context control
|
|
251
254
|
* @returns Total count of nodes with 'tag' property
|
|
252
255
|
*/
|
|
253
256
|
private countTaggedNodes;
|
|
@@ -319,6 +322,12 @@ export declare class FeishuLongConnHandler {
|
|
|
319
322
|
* split across rows so desktop clients do not compress every button into one line.
|
|
320
323
|
*/
|
|
321
324
|
private createThreadSwitchElements;
|
|
325
|
+
/** The source action never accepts a target from the callback payload. */
|
|
326
|
+
private createThreadSelectorElements;
|
|
327
|
+
/** Caller owns the root message lock. Commit UI state only after a successful patch. */
|
|
328
|
+
private patchThreadSelector;
|
|
329
|
+
private assertThreadSelectorBudget;
|
|
330
|
+
private handleThreadSelector;
|
|
322
331
|
private threadButtonLabel;
|
|
323
332
|
private createResponseHeaderElements;
|
|
324
333
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeishuLongConnHandler.d.ts","sourceRoot":"","sources":["../../src/feishu/FeishuLongConnHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,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;AAIxE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AA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A0B;YAMpB,oBAAoB;IAoClC,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,4BAA4B;IAgBpC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,+BAA+B;IAsCvC,OAAO,CAAC,YAAY;IAapB;;;OAGG;YACW,0BAA0B;IAyBlC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7E;;;OAGG;IACG,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC;QAAE,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC;IAiIlE;;;OAGG;IACG,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzG,qFAAqF;IAC/E,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,mBAAmB,CAAC;IAoDnL,yEAAyE;IACnE,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAchE,OAAO,CAAC,8BAA8B;YASxB,2BAA2B;IAyBzC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4C5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B3B;;OAEG;IACH,iBAAiB,IAAI,cAAc;CAGpC"}
|
|
@@ -62,9 +62,8 @@ class FeishuLongConnHandler {
|
|
|
62
62
|
// Feishu message size limit (4000 chars per message) - DEPRECATED for Card 2.0
|
|
63
63
|
FEISHU_MESSAGE_LIMIT = 4000;
|
|
64
64
|
// Feishu Card 2.0 limits (from official docs)
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
CARD_ELEMENT_LIMIT = 150; // Conservative: 150 tagged nodes per card (official: 200)
|
|
65
|
+
// Keep headroom while counting nested text, icons, and container nodes.
|
|
66
|
+
CARD_ELEMENT_LIMIT = 180;
|
|
68
67
|
CARD_DATA_SIZE_LIMIT = 3000000; // Max 3MB (3,000,000 chars) for data field
|
|
69
68
|
CARD_SIZE_BUFFER = 100000; // Safety buffer: use 2.9MB instead of 3MB
|
|
70
69
|
THREAD_BUTTONS_PER_ROW = 3;
|
|
@@ -140,6 +139,8 @@ class FeishuLongConnHandler {
|
|
|
140
139
|
* RouterServer sets this directly after construction.
|
|
141
140
|
*/
|
|
142
141
|
onCardNewThread;
|
|
142
|
+
/** Latest device-reported inventory; missing inventory fails closed for new controls. */
|
|
143
|
+
onCardThreadExists;
|
|
143
144
|
/** Callback invoked when a user confirms or cancels a queued command. */
|
|
144
145
|
onApprovalAction;
|
|
145
146
|
onMaintenanceAction;
|
|
@@ -989,7 +990,7 @@ Examples:
|
|
|
989
990
|
* Split Card 2.0 elements into chunks based on Feishu limits
|
|
990
991
|
*
|
|
991
992
|
* Card packing budgets:
|
|
992
|
-
* 1. Element count: Max 200 tagged nodes per card (we use
|
|
993
|
+
* 1. Element count: Max 200 tagged nodes per card (we use 180 for safety)
|
|
993
994
|
* 2. Data size: Max 3,000,000 characters in the data field (JSON.stringify result)
|
|
994
995
|
* 3. Tables: A conservative budget including tables embedded in Markdown
|
|
995
996
|
*
|
|
@@ -1024,10 +1025,10 @@ Examples:
|
|
|
1024
1025
|
const headerTables = (0, CardTables_1.countCardTables)(continuationHeaderElements);
|
|
1025
1026
|
// Reserve space for continuation indicators and the repeated card header.
|
|
1026
1027
|
const continuationHeaderSize = JSON.stringify(continuationHeaderElements).length;
|
|
1027
|
-
const continuationHeaderTaggedNodes = continuationHeaderElements.reduce((total, element) => total + this.countTaggedNodes(element), 0);
|
|
1028
|
+
const continuationHeaderTaggedNodes = continuationHeaderElements.reduce((total, element) => total + this.countTaggedNodes(element, true), 0);
|
|
1028
1029
|
// Reserve the bounded tail while packing so it never displaces content onto an activity-only page.
|
|
1029
1030
|
const continuationIndicatorSize = 200 + continuationHeaderSize + (activityTail ? JSON.stringify(activityTail).length : 0);
|
|
1030
|
-
const continuationIndicatorCount = 2 + continuationHeaderTaggedNodes + (activityTail ? this.countTaggedNodes(activityTail) : 0);
|
|
1031
|
+
const continuationIndicatorCount = 2 + continuationHeaderTaggedNodes + (activityTail ? this.countTaggedNodes(activityTail, true) : 0);
|
|
1031
1032
|
// Keep the completion block with the final body item when they fit on a
|
|
1032
1033
|
// continuation card. Include the whole worker group, never just its details.
|
|
1033
1034
|
const trailingStart = keepCompletionWithBody && trailingElements.length ? elements.indexOf(trailingElements[0]) : -1;
|
|
@@ -1039,13 +1040,13 @@ Examples:
|
|
|
1039
1040
|
const finalGroup = finalBodyStart >= continuationHeaderElements.length
|
|
1040
1041
|
? elements.slice(finalBodyStart) : [];
|
|
1041
1042
|
const keepFinalBody = finalGroup.length > trailingElements.length
|
|
1042
|
-
&& finalGroup.reduce((sum, item) => sum + this.countTaggedNodes(item), 0) + continuationIndicatorCount <= this.CARD_ELEMENT_LIMIT
|
|
1043
|
+
&& finalGroup.reduce((sum, item) => sum + this.countTaggedNodes(item, true), 0) + continuationIndicatorCount <= this.CARD_ELEMENT_LIMIT
|
|
1043
1044
|
&& finalGroup.reduce((sum, item) => sum + JSON.stringify(item).length, 0) + continuationIndicatorSize <= this.CARD_DATA_SIZE_LIMIT - this.CARD_SIZE_BUFFER
|
|
1044
1045
|
&& (0, CardTables_1.countCardTables)(finalGroup) + headerTables <= CardTables_1.CARD_TABLE_LIMIT;
|
|
1045
1046
|
for (let i = 0; i < elements.length; i++) {
|
|
1046
1047
|
const element = elements[i];
|
|
1047
1048
|
const elementSize = JSON.stringify(element).length;
|
|
1048
|
-
const elementTaggedNodes = this.countTaggedNodes(element);
|
|
1049
|
+
const elementTaggedNodes = this.countTaggedNodes(element, true);
|
|
1049
1050
|
const elementTables = (0, CardTables_1.countCardTables)(element);
|
|
1050
1051
|
// Keep worker identity, visible content and diagnostics together when packing cards.
|
|
1051
1052
|
const workerPrefix = /^dw_\d+_header$/.test(element.element_id ?? '')
|
|
@@ -1057,7 +1058,7 @@ Examples:
|
|
|
1057
1058
|
const group = keepFinalBody && i === finalBodyStart ? finalGroup
|
|
1058
1059
|
: isWorkerGroup ? workerGroup : element === trailingElements[0] ? trailingElements : [element];
|
|
1059
1060
|
const groupSize = group.reduce((sum, item) => sum + JSON.stringify(item).length, 0);
|
|
1060
|
-
const groupTaggedNodes = group.reduce((sum, item) => sum + this.countTaggedNodes(item), 0);
|
|
1061
|
+
const groupTaggedNodes = group.reduce((sum, item) => sum + this.countTaggedNodes(item, true), 0);
|
|
1061
1062
|
const groupTables = (0, CardTables_1.countCardTables)(group);
|
|
1062
1063
|
// Check if adding this element would exceed limits
|
|
1063
1064
|
// Reserve space for continuation indicators
|
|
@@ -1114,9 +1115,10 @@ Examples:
|
|
|
1114
1115
|
* According to Feishu docs, all nodes with 'tag' property count towards the 200 limit
|
|
1115
1116
|
*
|
|
1116
1117
|
* @param obj The object or array to count tags in
|
|
1118
|
+
* @param reserveWorkerErrors Reserve a future error row for each Worker context control
|
|
1117
1119
|
* @returns Total count of nodes with 'tag' property
|
|
1118
1120
|
*/
|
|
1119
|
-
countTaggedNodes(obj) {
|
|
1121
|
+
countTaggedNodes(obj, reserveWorkerErrors = false) {
|
|
1120
1122
|
if (!obj || typeof obj !== 'object') {
|
|
1121
1123
|
return 0;
|
|
1122
1124
|
}
|
|
@@ -1125,6 +1127,13 @@ Examples:
|
|
|
1125
1127
|
if (obj.tag) {
|
|
1126
1128
|
count = 1;
|
|
1127
1129
|
}
|
|
1130
|
+
// WorkerContextCards.decorate can add one error row after pagination, including
|
|
1131
|
+
// on a later reset failure. Already-decorated rows must not be counted twice.
|
|
1132
|
+
const controlElements = obj.columns?.[0]?.elements;
|
|
1133
|
+
if (reserveWorkerErrors && typeof obj.element_id === 'string' && obj.element_id.startsWith('wc_')
|
|
1134
|
+
&& controlElements?.[0]?.behaviors?.[0]?.value?.action === 'worker_context_clear'
|
|
1135
|
+
&& !controlElements.some((element) => element.tag === 'markdown'))
|
|
1136
|
+
count += 1;
|
|
1128
1137
|
// Recursively count in all properties
|
|
1129
1138
|
for (const key in obj) {
|
|
1130
1139
|
if (obj.hasOwnProperty(key)) {
|
|
@@ -1132,12 +1141,12 @@ Examples:
|
|
|
1132
1141
|
if (Array.isArray(value)) {
|
|
1133
1142
|
// Recursively count in array elements
|
|
1134
1143
|
for (const item of value) {
|
|
1135
|
-
count += this.countTaggedNodes(item);
|
|
1144
|
+
count += this.countTaggedNodes(item, reserveWorkerErrors);
|
|
1136
1145
|
}
|
|
1137
1146
|
}
|
|
1138
1147
|
else if (typeof value === 'object' && value !== null) {
|
|
1139
1148
|
// Recursively count in nested objects
|
|
1140
|
-
count += this.countTaggedNodes(value);
|
|
1149
|
+
count += this.countTaggedNodes(value, reserveWorkerErrors);
|
|
1141
1150
|
}
|
|
1142
1151
|
}
|
|
1143
1152
|
}
|
|
@@ -1155,7 +1164,7 @@ Examples:
|
|
|
1155
1164
|
return false;
|
|
1156
1165
|
}
|
|
1157
1166
|
// Check element count limit - MUST count ALL nodes with 'tag' property recursively
|
|
1158
|
-
const totalTaggedNodes = elements.reduce((sum, element) => sum + this.countTaggedNodes(element), 0);
|
|
1167
|
+
const totalTaggedNodes = elements.reduce((sum, element) => sum + this.countTaggedNodes(element, true), 0);
|
|
1159
1168
|
console.log(`[FeishuHandler] Element count check: top-level=${elements.length}, total tagged nodes=${totalTaggedNodes}, limit=${this.CARD_ELEMENT_LIMIT}`);
|
|
1160
1169
|
if (totalTaggedNodes > this.CARD_ELEMENT_LIMIT) {
|
|
1161
1170
|
console.log(`[FeishuHandler] Total tagged nodes (${totalTaggedNodes}) exceeds limit (${this.CARD_ELEMENT_LIMIT})`);
|
|
@@ -1302,7 +1311,7 @@ Examples:
|
|
|
1302
1311
|
return this._updateStreamingMessage(messageId, [...headerElements, ...elements], openId, headerElements);
|
|
1303
1312
|
});
|
|
1304
1313
|
}
|
|
1305
|
-
async _updateStreamingMessage(messageId, elements, openId, continuationHeaderElements = [], trailingElements = [], keepCompletionWithBody = false) {
|
|
1314
|
+
async _updateStreamingMessage(messageId, elements, openId, continuationHeaderElements = [], trailingElements = [], keepCompletionWithBody = false, selectorRender) {
|
|
1306
1315
|
let updatingMessageId = messageId;
|
|
1307
1316
|
let updatingCardIndex = 0;
|
|
1308
1317
|
try {
|
|
@@ -1315,7 +1324,10 @@ Examples:
|
|
|
1315
1324
|
// Split elements into chunks based on Feishu Card 2.0 limits
|
|
1316
1325
|
const shell = this.activityShells.get(messageId);
|
|
1317
1326
|
const activityTail = shell && shell.finishedAt === undefined ? (0, ActivityProgress_1.createActivityElement)(shell.activity) : undefined;
|
|
1318
|
-
const
|
|
1327
|
+
const packed = this.splitElementsIntoChunks(elements, continuationHeaderElements, trailingElements, activityTail, keepCompletionWithBody);
|
|
1328
|
+
// Pack the expanded controls, but initially deliver the compact footer on the same page.
|
|
1329
|
+
const chunks = selectorRender ? packed.map(chunk => chunk.flatMap(element => element === selectorRender.expanded[0] ? selectorRender.collapsed
|
|
1330
|
+
: selectorRender.expanded.includes(element) ? [] : [element])) : packed;
|
|
1319
1331
|
const tailIndex = activityTail ? chunks.length - 1 : -1;
|
|
1320
1332
|
console.log(`[FeishuHandler] Need ${chunks.length} card(s), currently have ${chain.length} card(s)`);
|
|
1321
1333
|
let hashes = this.cardContentHashes.get(messageId);
|
|
@@ -1488,6 +1500,8 @@ Examples:
|
|
|
1488
1500
|
}
|
|
1489
1501
|
// Append thread switch buttons when at least one thread exists
|
|
1490
1502
|
let threadSwitchElements = [];
|
|
1503
|
+
let selector;
|
|
1504
|
+
let selectorRender;
|
|
1491
1505
|
// The reply's owner and the destination of new messages are independent.
|
|
1492
1506
|
const activeThreadId = (openId ? this.onResolveActiveThread?.(openId)?.threadId : undefined)
|
|
1493
1507
|
?? threads?.find(thread => thread.name === 'default')?.id;
|
|
@@ -1498,14 +1512,18 @@ Examples:
|
|
|
1498
1512
|
? [replyThreadName, replyWorkspace].filter(Boolean).join(' · ')
|
|
1499
1513
|
: undefined;
|
|
1500
1514
|
if (!bare && threads && threads.length >= 1) {
|
|
1501
|
-
|
|
1515
|
+
selector = { id: (0, uuid_1.v4)(), owner: openId ?? '', deviceId: this.onResolveThread?.(messageId)?.deviceId,
|
|
1516
|
+
rootId: messageId, replyThreadId, expanded: false };
|
|
1517
|
+
const state = { threads, activeThreadId, replyLabel, selector };
|
|
1518
|
+
threadSwitchElements = this.createThreadSelectorElements(state, true);
|
|
1519
|
+
selectorRender = { expanded: threadSwitchElements, collapsed: this.createThreadSelectorElements(state, false) };
|
|
1502
1520
|
finalElements.push(...threadSwitchElements);
|
|
1503
1521
|
}
|
|
1504
1522
|
// Reuse streaming update logic: only create cards, never delete.
|
|
1505
1523
|
// Repack changed previews and clear obsolete tool copies without retracting messages.
|
|
1506
1524
|
const trailingElements = !queueConfirmation ? [...footerElements, ...threadSwitchElements] : threadSwitchElements;
|
|
1507
1525
|
const keepCompletionWithBody = !bare && !queueConfirmation;
|
|
1508
|
-
const updated = await this._updateStreamingMessage(messageId, finalElements, openId, headerElements, trailingElements, keepCompletionWithBody);
|
|
1526
|
+
const updated = await this._updateStreamingMessage(messageId, finalElements, openId, headerElements, trailingElements, keepCompletionWithBody, selectorRender);
|
|
1509
1527
|
if (!updated) {
|
|
1510
1528
|
return false;
|
|
1511
1529
|
}
|
|
@@ -1529,6 +1547,7 @@ Examples:
|
|
|
1529
1547
|
threads,
|
|
1530
1548
|
activeThreadId,
|
|
1531
1549
|
replyLabel,
|
|
1550
|
+
selector,
|
|
1532
1551
|
createdAt: Date.now(),
|
|
1533
1552
|
});
|
|
1534
1553
|
}
|
|
@@ -1595,6 +1614,90 @@ Examples:
|
|
|
1595
1614
|
};
|
|
1596
1615
|
return [{ tag: 'hr' }, caption, ...rows];
|
|
1597
1616
|
}
|
|
1617
|
+
/** The source action never accepts a target from the callback payload. */
|
|
1618
|
+
createThreadSelectorElements(state, expanded) {
|
|
1619
|
+
const selector = state.selector;
|
|
1620
|
+
const button = (text, op, disabled = false) => ({ tag: 'column', width: 'auto', elements: [{
|
|
1621
|
+
tag: 'button', text: { tag: 'plain_text', content: text }, type: 'default', disabled,
|
|
1622
|
+
behaviors: [{ type: 'callback', value: { action: 'thread_selector', id: selector.id, op } }],
|
|
1623
|
+
}] });
|
|
1624
|
+
const controls = { tag: 'column_set', flex_mode: 'stretch', columns: [
|
|
1625
|
+
button('Switch to this thread', 'source', !selector.replyThreadId || !selector.owner || !selector.deviceId),
|
|
1626
|
+
button(expanded ? 'Hide threads' : 'Show threads', expanded ? 'hide' : 'show'),
|
|
1627
|
+
] };
|
|
1628
|
+
const full = this.createThreadSwitchElements(state.threads, state.activeThreadId, state.replyLabel);
|
|
1629
|
+
if (!expanded)
|
|
1630
|
+
return [...full.slice(0, 2), controls];
|
|
1631
|
+
for (const row of full.slice(2))
|
|
1632
|
+
for (const column of row.columns) {
|
|
1633
|
+
const action = column.elements[0].behaviors[0].value;
|
|
1634
|
+
column.elements[0].behaviors[0].value = action.action === 'new_thread'
|
|
1635
|
+
? { action: 'thread_selector', id: selector.id, op: 'new' }
|
|
1636
|
+
: { action: 'thread_selector', id: selector.id, op: 'select', offset: state.threads.findIndex(thread => thread.id === action.threadId) };
|
|
1637
|
+
}
|
|
1638
|
+
return [...full.slice(0, 2), controls, ...full.slice(2)];
|
|
1639
|
+
}
|
|
1640
|
+
/** Caller owns the root message lock. Commit UI state only after a successful patch. */
|
|
1641
|
+
async patchThreadSelector(cardId, state, expanded, activeThreadId = state.activeThreadId) {
|
|
1642
|
+
const next = { ...state, activeThreadId, selector: { ...state.selector, expanded } };
|
|
1643
|
+
const elements = [...state.baseElements, ...this.createThreadSelectorElements(next, expanded)];
|
|
1644
|
+
if (this.checkIfElementsNeedSplitting(elements))
|
|
1645
|
+
throw new Error('Thread controls exceed this card budget.');
|
|
1646
|
+
await this.sendCardRequest(JSON.stringify({ schema: '2.0', body: { elements } }), async (content) => {
|
|
1647
|
+
this.assertThreadSelectorBudget(content);
|
|
1648
|
+
const result = await this.client.im.message.patch({ path: { message_id: cardId }, data: { content } });
|
|
1649
|
+
if (!result?.code)
|
|
1650
|
+
this.workerContexts?.remember(cardId, next.selector.rootId, content);
|
|
1651
|
+
return result;
|
|
1652
|
+
});
|
|
1653
|
+
this.threadSwitchCardState.set(cardId, next);
|
|
1654
|
+
}
|
|
1655
|
+
assertThreadSelectorBudget(content) {
|
|
1656
|
+
if (this.countTaggedNodes(JSON.parse(content)) > this.CARD_ELEMENT_LIMIT) {
|
|
1657
|
+
throw new Error('Thread controls exceed this card budget after decoration.');
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
async handleThreadSelector(openId, cardId, action) {
|
|
1661
|
+
const error = (content) => ({ toast: { type: 'error', content } });
|
|
1662
|
+
if (typeof cardId !== 'string')
|
|
1663
|
+
return error('This thread selector is unavailable.');
|
|
1664
|
+
const rootId = this.threadSwitchCardState.get(cardId)?.selector?.rootId ?? cardId;
|
|
1665
|
+
return this.withMessageLock(rootId, async () => {
|
|
1666
|
+
const state = this.threadSwitchCardState.get(cardId);
|
|
1667
|
+
const selector = state?.selector;
|
|
1668
|
+
if (!state || !selector || selector.id !== action.id || selector.owner !== openId
|
|
1669
|
+
|| Date.now() - state.createdAt >= this.THREAD_SWITCH_STATE_TTL_MS)
|
|
1670
|
+
return error('This thread selector has expired or belongs to another card.');
|
|
1671
|
+
let switched;
|
|
1672
|
+
try {
|
|
1673
|
+
const device = await this.bindingManager.getActiveDevice(openId);
|
|
1674
|
+
if (!selector.deviceId || device?.deviceId !== selector.deviceId)
|
|
1675
|
+
return error('Select the original device before using this card.');
|
|
1676
|
+
if (action.op === 'show' || action.op === 'hide') {
|
|
1677
|
+
await this.patchThreadSelector(cardId, state, action.op === 'show', this.onResolveActiveThread?.(openId)?.threadId);
|
|
1678
|
+
return { toast: { type: 'info', content: action.op === 'show' ? 'Threads shown. Input target unchanged.' : 'Threads hidden. Input target unchanged.' } };
|
|
1679
|
+
}
|
|
1680
|
+
if (action.op === 'new') {
|
|
1681
|
+
if (!selector.expanded || state.threads.length >= types_1.MAX_THREADS || !this.onCardNewThread)
|
|
1682
|
+
return error('New thread is unavailable.');
|
|
1683
|
+
await this.onCardNewThread(openId);
|
|
1684
|
+
return { toast: { type: 'info', content: 'Creating new thread...' } };
|
|
1685
|
+
}
|
|
1686
|
+
const target = action.op === 'source' ? state.threads.find(thread => thread.id === selector.replyThreadId)
|
|
1687
|
+
: action.op === 'select' && selector.expanded && Number.isInteger(action.offset) && action.offset >= 0
|
|
1688
|
+
? state.threads[action.offset] : undefined;
|
|
1689
|
+
if (!target || !this.onCardThreadExists?.(selector.deviceId, target.id) || !this.onCardSwitchThread)
|
|
1690
|
+
return error('This thread is no longer available.');
|
|
1691
|
+
await this.onCardSwitchThread(openId, target.id, target.name);
|
|
1692
|
+
switched = target.name;
|
|
1693
|
+
await this.patchThreadSelector(cardId, state, false, target.id);
|
|
1694
|
+
return { toast: { type: 'success', content: `Input target: ${target.name}` } };
|
|
1695
|
+
}
|
|
1696
|
+
catch {
|
|
1697
|
+
return error(switched ? `Input target changed to ${switched}, but the card could not refresh. Try Hide threads again.` : 'Thread action failed. Please try again.');
|
|
1698
|
+
}
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1598
1701
|
threadButtonLabel(thread, active) {
|
|
1599
1702
|
const details = [
|
|
1600
1703
|
thread.workspaceName,
|
|
@@ -1690,13 +1793,17 @@ Examples:
|
|
|
1690
1793
|
* Re-patches the card with updated button states (new active thread highlighted).
|
|
1691
1794
|
*/
|
|
1692
1795
|
async refreshThreadSwitchButtons(cardMessageId, newActiveThreadId) {
|
|
1693
|
-
const rootId = this.workerContexts?.rootFor(cardMessageId) ?? cardMessageId;
|
|
1796
|
+
const rootId = this.threadSwitchCardState.get(cardMessageId)?.selector?.rootId ?? this.workerContexts?.rootFor(cardMessageId) ?? cardMessageId;
|
|
1694
1797
|
await this.withMessageLock(rootId, async () => {
|
|
1695
1798
|
const state = this.threadSwitchCardState.get(cardMessageId);
|
|
1696
1799
|
if (!state) {
|
|
1697
1800
|
console.warn(`[FeishuHandler] No thread switch state found for card ${cardMessageId}`);
|
|
1698
1801
|
return;
|
|
1699
1802
|
}
|
|
1803
|
+
if (state.selector) {
|
|
1804
|
+
await this.patchThreadSelector(cardMessageId, state, false, newActiveThreadId);
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1700
1807
|
const updatedElements = [
|
|
1701
1808
|
...state.baseElements,
|
|
1702
1809
|
...this.createThreadSwitchElements(state.threads, newActiveThreadId, state.replyLabel),
|
|
@@ -1716,6 +1823,8 @@ Examples:
|
|
|
1716
1823
|
if (!content)
|
|
1717
1824
|
return;
|
|
1718
1825
|
await this.sendCardRequest(content, async (body) => {
|
|
1826
|
+
if (this.threadSwitchCardState.get(cardId)?.selector)
|
|
1827
|
+
this.assertThreadSelectorBudget(body);
|
|
1719
1828
|
const result = await this.client.im.message.patch({ path: { message_id: cardId }, data: { content: body } });
|
|
1720
1829
|
if (!result?.code)
|
|
1721
1830
|
this.workerContexts?.remember(cardId, rootId, body);
|
|
@@ -1741,6 +1850,15 @@ Examples:
|
|
|
1741
1850
|
catch {
|
|
1742
1851
|
return;
|
|
1743
1852
|
}
|
|
1853
|
+
if (!parsed || typeof parsed !== 'object' || typeof parsed.action !== 'string')
|
|
1854
|
+
return;
|
|
1855
|
+
if (parsed.action === 'thread_selector')
|
|
1856
|
+
return this.handleThreadSelector(openId, data?.context?.open_message_id, parsed);
|
|
1857
|
+
// New cards must not fall through to the legacy unbound callback contract.
|
|
1858
|
+
if ((parsed.action === 'switch_thread' || parsed.action === 'new_thread')
|
|
1859
|
+
&& this.threadSwitchCardState.get(data?.context?.open_message_id)?.selector) {
|
|
1860
|
+
return { toast: { type: 'error', content: 'Use this card’s thread controls.' } };
|
|
1861
|
+
}
|
|
1744
1862
|
if (parsed.action === 'settings') {
|
|
1745
1863
|
const cardId = data?.context?.open_message_id;
|
|
1746
1864
|
if (typeof parsed.id !== 'string' || typeof cardId !== 'string' || !this.settingsCards) {
|
|
@@ -1790,6 +1908,25 @@ Examples:
|
|
|
1790
1908
|
return { toast: { type: 'error', content: error instanceof Error ? error.message : 'Approval failed.' } };
|
|
1791
1909
|
}
|
|
1792
1910
|
}
|
|
1911
|
+
// Legacy cards remain usable while their original state is present. A new Router
|
|
1912
|
+
// must not let expired/unknown cards bypass the bound selector via legacy actions.
|
|
1913
|
+
if ((parsed.action === 'switch_thread' || parsed.action === 'new_thread') && this.onCardThreadExists) {
|
|
1914
|
+
const cardId = data?.context?.open_message_id;
|
|
1915
|
+
const state = this.threadSwitchCardState.get(cardId);
|
|
1916
|
+
const route = typeof cardId === 'string' ? this.onResolveThread?.(cardId) : undefined;
|
|
1917
|
+
let device;
|
|
1918
|
+
try {
|
|
1919
|
+
device = await this.bindingManager.getActiveDevice(openId);
|
|
1920
|
+
}
|
|
1921
|
+
catch {
|
|
1922
|
+
return { toast: { type: 'error', content: 'Thread action failed. Please try again.' } };
|
|
1923
|
+
}
|
|
1924
|
+
if (!state || Date.now() - state.createdAt >= this.THREAD_SWITCH_STATE_TTL_MS || !route
|
|
1925
|
+
|| device?.deviceId !== route.deviceId || (parsed.action === 'switch_thread'
|
|
1926
|
+
&& (!state.threads.some(thread => thread.id === parsed.threadId) || !this.onCardThreadExists(route.deviceId, parsed.threadId)))) {
|
|
1927
|
+
return { toast: { type: 'error', content: 'This thread card is no longer available.' } };
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1793
1930
|
if (parsed.action === 'switch_thread' && parsed.threadId) {
|
|
1794
1931
|
const openMessageId = data?.context?.open_message_id;
|
|
1795
1932
|
try {
|
|
@@ -1894,15 +2031,17 @@ Examples:
|
|
|
1894
2031
|
/** Leave a historical queue receipt after output moves to a new card. */
|
|
1895
2032
|
async markQueueCardStarted(cardMessageId) {
|
|
1896
2033
|
await this.queueCardDecisions.get(cardMessageId);
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2034
|
+
const rootId = this.threadSwitchCardState.get(cardMessageId)?.selector?.rootId ?? cardMessageId;
|
|
2035
|
+
await this.withMessageLock(rootId, async () => {
|
|
2036
|
+
const result = await this.client.im.message.patch({
|
|
2037
|
+
path: { message_id: cardMessageId },
|
|
2038
|
+
data: { content: JSON.stringify({ schema: '2.0', body: { elements: [{ tag: 'markdown',
|
|
2039
|
+
content: '▶️ **Queued task started**\n\nFollow progress in the new execution card at the bottom of the chat.' }] } }) },
|
|
2040
|
+
});
|
|
2041
|
+
if (result?.code)
|
|
2042
|
+
throw result;
|
|
2043
|
+
this.threadSwitchCardState.delete(cardMessageId);
|
|
2044
|
+
});
|
|
1906
2045
|
}
|
|
1907
2046
|
removeExpiredQueueActionStates() {
|
|
1908
2047
|
const expiry = Date.now() - this.QUEUE_ACTION_STATE_TTL_MS;
|
|
@@ -1917,8 +2056,9 @@ Examples:
|
|
|
1917
2056
|
? '✅ **Added to queue**\n\nThis message has been accepted into the thread queue. Use /queue to check its status. If the queue is paused, use /queue continue to resume.'
|
|
1918
2057
|
: '❌ **Queue request cancelled**\n\nThis message was not added to the thread queue.';
|
|
1919
2058
|
try {
|
|
1920
|
-
|
|
1921
|
-
|
|
2059
|
+
const rootId = this.threadSwitchCardState.get(cardMessageId)?.selector?.rootId ?? cardMessageId;
|
|
2060
|
+
await this.withMessageLock(rootId, async () => {
|
|
2061
|
+
const result = await this.client.im.message.patch({
|
|
1922
2062
|
path: { message_id: cardMessageId },
|
|
1923
2063
|
data: {
|
|
1924
2064
|
content: JSON.stringify({
|
|
@@ -1927,6 +2067,9 @@ Examples:
|
|
|
1927
2067
|
}),
|
|
1928
2068
|
},
|
|
1929
2069
|
});
|
|
2070
|
+
if (result?.code)
|
|
2071
|
+
throw result;
|
|
2072
|
+
this.threadSwitchCardState.delete(cardMessageId);
|
|
1930
2073
|
});
|
|
1931
2074
|
}
|
|
1932
2075
|
catch (error) {
|