@xmanrui/dsh-im 5.7.0 → 5.9.0
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.en.md +42 -7
- package/README.md +53 -7
- package/docs/preset-workspaces.md +37 -0
- package/lib/client.js +375 -160
- package/lib/index.js +330 -325
- package/package.json +3 -1
- package/plugin-src/client/channels/feishu/api.js +5 -0
- package/plugin-src/client/channels/feishu/conversation-directory-settings.js +73 -0
- package/plugin-src/client/channels/feishu/index.js +1 -0
- package/plugin-src/client/connection-error.js +1 -1
- package/plugin-src/client/delivery-settings.js +4 -0
- package/plugin-src/client/i18n-ru.js +17 -0
- package/plugin-src/client/i18n.js +17 -0
- package/plugin-src/client/styles.js +6 -0
- package/plugin-src/client/workspace-editor.js +6 -5
- package/plugin-src/host/channels/dingtalk/production.mjs +2 -1
- package/plugin-src/host/channels/feishu/production.mjs +2 -1
- package/plugin-src/host/channels/feishu/rpc.mjs +25 -0
- package/plugin-src/host/channels/matrix/production.mjs +2 -1
- package/plugin-src/host/channels/qq/production.mjs +2 -1
- package/plugin-src/host/channels/shared/binding-events.mjs +130 -0
- package/plugin-src/host/channels/shared/production.mjs +32 -3
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +2 -0
- package/plugin-src/host/channels/slack/production.mjs +2 -1
- package/plugin-src/host/channels/wecom/production.mjs +2 -1
- package/plugin-src/host/channels/wecom-app/production.mjs +2 -1
- package/plugin-src/host/channels/weixin/production.mjs +2 -1
- package/plugin-src/host/channels/whatsapp/production.mjs +2 -1
- package/plugin-src/host/delivery-adapter.mjs +122 -1
- package/plugin-src/host/delivery-service.mjs +40 -0
- package/plugin-src/host/ds-bot-client.mjs +28 -2
- package/plugin-src/host/index.mjs +24 -1
- package/plugin-src/host/modern-harness-api.mjs +3 -0
- package/scripts/telegram-menu-scopes.mjs +57 -0
- package/scripts/verify-interface-language.mjs +60 -15
- package/scripts/verify-package.mjs +17 -6
- package/src/channels/dingtalk/dingtalk-bridge.mjs +2 -3
- package/src/channels/dingtalk/dingtalk-menu.mjs +4 -5
- package/src/channels/email/transports/imap-smtp.mjs +21 -11
- package/src/channels/feishu/bridge.mjs +75 -22
- package/src/channels/feishu/feishu-cards.mjs +96 -25
- package/src/channels/feishu/message-utils.mjs +1 -0
- package/src/channels/qq/qq-menu.mjs +3 -4
- package/src/channels/shared/action-card.mjs +331 -0
- package/src/channels/shared/bot-workspace-store.mjs +369 -6
- package/src/channels/shared/command-catalog.mjs +20 -5
- package/src/channels/shared/conversation/describe.mjs +116 -0
- package/src/channels/shared/conversation-directory-ensure.mjs +46 -0
- package/src/channels/shared/conversation-directory.mjs +29 -0
- package/src/channels/shared/conversation-state-store.mjs +62 -0
- package/src/channels/shared/diagnostic-details.mjs +38 -0
- package/src/channels/shared/harness-approval.mjs +58 -13
- package/src/channels/shared/harness-client.mjs +85 -2
- package/src/channels/shared/harness-session-binding.mjs +13 -1
- package/src/channels/shared/i18n-en/diagnostics.mjs +2 -0
- package/src/channels/shared/i18n-en/feishu.mjs +6 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +14 -0
- package/src/channels/shared/i18n-en/telegram.mjs +14 -0
- package/src/channels/shared/i18n-ru/diagnostics.mjs +2 -0
- package/src/channels/shared/i18n-ru/feishu.mjs +6 -0
- package/src/channels/shared/i18n-ru/shared-a.mjs +14 -0
- package/src/channels/shared/i18n-ru/telegram.mjs +14 -0
- package/src/channels/shared/message-failure.mjs +8 -0
- package/src/channels/shared/model-command.mjs +5 -0
- package/src/channels/shared/new-command.mjs +7 -0
- package/src/channels/shared/preset-workspaces.mjs +48 -0
- package/src/channels/shared/qr-encoding-error.mjs +8 -2
- package/src/channels/shared/semantic/reply-reference.mjs +25 -5
- package/src/channels/shared/status-command.mjs +159 -0
- package/src/channels/shared/text-harness-bridge.mjs +89 -6
- package/src/channels/shared/workspace-command.mjs +36 -15
- package/src/channels/shared/workspace-session.mjs +30 -5
- package/src/channels/telegram/approval-card.mjs +379 -0
- package/src/channels/telegram/telegram-api.mjs +10 -1
- package/src/channels/telegram/telegram-bridge.mjs +7 -0
- package/src/channels/telegram/telegram-runtime.mjs +125 -13
- package/src/channels/wecom/wecom-bridge.mjs +5 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { workspacePathSnapshot } from '../shared/workspace-command.mjs';
|
|
2
|
+
import { conversationSessionWorkspace, workspacePathSnapshot } from '../shared/workspace-command.mjs';
|
|
3
3
|
import { t } from '../shared/i18n.mjs';
|
|
4
4
|
|
|
5
5
|
export const DINGTALK_MENU_TEMPLATE_ID = '9ca31362-e5b3-409c-a694-6993706a6004.schema';
|
|
@@ -19,9 +19,8 @@ const presetCommand = (id) => `/preset ${/^\d+$/u.test(id) ? 'id:' : ''}${id}`;
|
|
|
19
19
|
// as a command supplied by the client or as a prompt for the model.
|
|
20
20
|
export async function dingtalkMenuSnapshot(harness, state, key, signal) {
|
|
21
21
|
const workspace = harness.currentWorkspace?.();
|
|
22
|
-
const currentSessionWorkspace = () =>
|
|
23
|
-
|
|
24
|
-
const sessionWorkspace = currentSessionWorkspace();
|
|
22
|
+
const currentSessionWorkspace = () => conversationSessionWorkspace(harness, key, { signal });
|
|
23
|
+
const sessionWorkspace = await currentSessionWorkspace();
|
|
25
24
|
const sessionId = state.sessionFor(key);
|
|
26
25
|
const options = { signal };
|
|
27
26
|
const results = await Promise.allSettled([
|
|
@@ -36,7 +35,7 @@ export async function dingtalkMenuSnapshot(harness, state, key, signal) {
|
|
|
36
35
|
]);
|
|
37
36
|
signal?.throwIfAborted();
|
|
38
37
|
if (harness.currentWorkspace?.() !== workspace
|
|
39
|
-
|| currentSessionWorkspace() !== sessionWorkspace || state.sessionFor(key) !== sessionId) {
|
|
38
|
+
|| await currentSessionWorkspace() !== sessionWorkspace || state.sessionFor(key) !== sessionId) {
|
|
40
39
|
throw new Error(t('会话或工作区已变化,请重新发送 /m。'));
|
|
41
40
|
}
|
|
42
41
|
const [paths, listed, catalog, settings] = results.map((r) => r.status === 'fulfilled' ? r.value : null);
|
|
@@ -34,7 +34,9 @@ export class ImapSmtpTransport {
|
|
|
34
34
|
|
|
35
35
|
/** Open the IMAP connection and select the monitored mailbox. */
|
|
36
36
|
async connect() {
|
|
37
|
-
if (this.#imap) return;
|
|
37
|
+
if (this.#imap?.usable) return;
|
|
38
|
+
this.#imap?.close();
|
|
39
|
+
this.#imap = null;
|
|
38
40
|
const client = new ImapFlow({
|
|
39
41
|
host: this.#config.imapHost,
|
|
40
42
|
port: this.#config.imapPort,
|
|
@@ -43,10 +45,20 @@ export class ImapSmtpTransport {
|
|
|
43
45
|
logger: false,
|
|
44
46
|
...(this.#config.rejectUnauthorized === false ? { tls: { rejectUnauthorized: false } } : {}),
|
|
45
47
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// The next poll reconnects after a socket closes. A late event from an
|
|
49
|
+
// old client must never discard its healthy replacement.
|
|
50
|
+
client.on('close', () => {
|
|
51
|
+
if (this.#imap === client) this.#imap = null;
|
|
52
|
+
});
|
|
53
|
+
client.on('error', () => client.close());
|
|
54
|
+
try {
|
|
55
|
+
await client.connect();
|
|
56
|
+
await client.mailboxOpen(this.#config.mailbox ?? 'INBOX');
|
|
57
|
+
this.#imap = client;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
client.close();
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
async disconnect() {
|
|
@@ -117,12 +129,10 @@ export class ImapSmtpTransport {
|
|
|
117
129
|
|
|
118
130
|
/** Read one message's RFC822 source by UID. */
|
|
119
131
|
async #fetchSource(uid) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
132
|
+
// A failed read must fail the poll, otherwise a later message could move
|
|
133
|
+
// the cursor past this unread mail. A vanished message still returns null.
|
|
134
|
+
const message = await this.#imap.fetchOne(String(uid), { source: true }, { uid: true });
|
|
135
|
+
return message?.source ?? null;
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
/** Send a reply inside the originating thread. */
|
|
@@ -5,6 +5,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
5
5
|
import { chunkMarkdownText } from '../shared/markdown-chunks.mjs';
|
|
6
6
|
import QRCode from 'qrcode';
|
|
7
7
|
import { waitForFeishuOperation } from './feishu-channel.mjs';
|
|
8
|
+
import { startNewConversation } from '../shared/new-command.mjs';
|
|
8
9
|
import {
|
|
9
10
|
conversationKey,
|
|
10
11
|
conversationScope,
|
|
@@ -95,6 +96,7 @@ import { isSharedLocalCommand } from '../shared/command-permission.mjs';
|
|
|
95
96
|
import {
|
|
96
97
|
MENU_PAGE_SIZE,
|
|
97
98
|
PRESET_FOLLOW_DEFAULT_SENTINEL,
|
|
99
|
+
REASONING_DEFAULT_SENTINEL,
|
|
98
100
|
STEER_CUSTOM_SENTINEL,
|
|
99
101
|
approvalCard,
|
|
100
102
|
completionCard,
|
|
@@ -144,7 +146,7 @@ const WATCH_COMMAND = /^\/watch(?:\s+([^\s]+))?$/i;
|
|
|
144
146
|
const UNWATCH_COMMAND = /^\/unwatch(?:\s+([^\s]+))?$/i;
|
|
145
147
|
const WATCHLIST_COMMAND = /^\/watchlist$/i;
|
|
146
148
|
const SESSION_LIST_PREFIX = /^\/(?:sessionlist|sessions)(?:\s|$)/i;
|
|
147
|
-
const WORKSPACE_LIST_COMMAND = /^\/(?:workspacelist|workspaces|wsl)
|
|
149
|
+
const WORKSPACE_LIST_COMMAND = /^\/(?:workspacelist|workspaces|wsl)(?:\s+all)?$/i;
|
|
148
150
|
// After the merge a bare /workspace or /ws opens the same picker card.
|
|
149
151
|
const BARE_WORKSPACE_COMMAND = /^\/(?:workspace|ws)$/i;
|
|
150
152
|
const NUMBER_REPLY = /^\d{1,2}$/;
|
|
@@ -1852,8 +1854,9 @@ export class FeishuHarnessBridge {
|
|
|
1852
1854
|
);
|
|
1853
1855
|
return;
|
|
1854
1856
|
}
|
|
1855
|
-
await this.#
|
|
1856
|
-
|
|
1857
|
+
await this.#send(event.message.chat_id, await startNewConversation({
|
|
1858
|
+
state: this.#state, harness: this.#harness, key,
|
|
1859
|
+
}), { replyTo: event.message.message_id });
|
|
1857
1860
|
await this.#sendMenuCard(key, event.message.chat_id, { replyTo: event.message.message_id });
|
|
1858
1861
|
return;
|
|
1859
1862
|
}
|
|
@@ -1896,8 +1899,12 @@ export class FeishuHarnessBridge {
|
|
|
1896
1899
|
);
|
|
1897
1900
|
return;
|
|
1898
1901
|
}
|
|
1902
|
+
if (BARE_WORKSPACE_COMMAND.test(commandText)
|
|
1903
|
+
&& this.#harness.conversationDirectoryConfig?.()?.enabled === true) return;
|
|
1899
1904
|
if (BARE_WORKSPACE_COMMAND.test(commandText) || WORKSPACE_LIST_COMMAND.test(commandText)) {
|
|
1900
|
-
await this.#showWorkspaces({ chatId: event.message.chat_id, key, replyTo: event.message.message_id }
|
|
1905
|
+
await this.#showWorkspaces({ chatId: event.message.chat_id, key, replyTo: event.message.message_id }, {
|
|
1906
|
+
includeConversationDirectories: /\s+all$/iu.test(commandText),
|
|
1907
|
+
});
|
|
1901
1908
|
return;
|
|
1902
1909
|
}
|
|
1903
1910
|
if (WATCH_COMMAND.test(commandText)) {
|
|
@@ -2423,7 +2430,9 @@ export class FeishuHarnessBridge {
|
|
|
2423
2430
|
? `preset:select:${option}`
|
|
2424
2431
|
: action === 'model_pick' && typeof option === 'string'
|
|
2425
2432
|
? `model:select:${option}`
|
|
2426
|
-
: action === '
|
|
2433
|
+
: action === 'reasoning_pick' && typeof option === 'string'
|
|
2434
|
+
? `reasoning:select:${option}`
|
|
2435
|
+
: action === 'archive_pick' && typeof option === 'string'
|
|
2427
2436
|
? `archive:${option}`
|
|
2428
2437
|
: action === 'steer_pick' && typeof option === 'string'
|
|
2429
2438
|
? `steer:${option}`
|
|
@@ -2432,6 +2441,7 @@ export class FeishuHarnessBridge {
|
|
|
2432
2441
|
?? nonEmptyString(event?.open_message_id)
|
|
2433
2442
|
?? nonEmptyString(event?.message_id);
|
|
2434
2443
|
const route = messageId ? this.#cardKeys.get(messageId) : null;
|
|
2444
|
+
const modelPage = route?.modelPage ?? 0;
|
|
2435
2445
|
if (!route) {
|
|
2436
2446
|
// A route is also the trusted direct/group scope for the unified policy.
|
|
2437
2447
|
// Without it, fail closed instead of producing an unauthorised side effect.
|
|
@@ -2473,7 +2483,7 @@ export class FeishuHarnessBridge {
|
|
|
2473
2483
|
this.#cardKeys.set(messageId, route);
|
|
2474
2484
|
const newSessionActionId = nonEmptyString(actionValue.newSessionActionId);
|
|
2475
2485
|
if (resolvedAction === 'new' && (!route.menuContext || !newSessionActionId)) return Promise.resolve();
|
|
2476
|
-
const entry = { ...route, messageId, selections: multiValues, operatorOpenId, newSessionActionId };
|
|
2486
|
+
const entry = { ...route, messageId, selections: multiValues, operatorOpenId, newSessionActionId, modelPage };
|
|
2477
2487
|
const source = nonEmptyString(actionValue.source);
|
|
2478
2488
|
const formText = nonEmptyString(formValue.steer_text);
|
|
2479
2489
|
const eventId = nonEmptyString(event?.event_id)
|
|
@@ -2682,6 +2692,7 @@ export class FeishuHarnessBridge {
|
|
|
2682
2692
|
sessionWorkspace = null,
|
|
2683
2693
|
sessionPage = 0,
|
|
2684
2694
|
sessionLimit = null,
|
|
2695
|
+
modelPage = 0,
|
|
2685
2696
|
selections = [],
|
|
2686
2697
|
actor = null,
|
|
2687
2698
|
menuContext = null,
|
|
@@ -2846,8 +2857,7 @@ export class FeishuHarnessBridge {
|
|
|
2846
2857
|
await reply(t('当前任务仍在运行,请先停止任务或等待任务完成后再开启新会话。'));
|
|
2847
2858
|
return;
|
|
2848
2859
|
}
|
|
2849
|
-
await this.#state
|
|
2850
|
-
await reply(t('已开启全新 Harness 会话。'));
|
|
2860
|
+
await reply(await startNewConversation({ state: this.#state, harness: this.#harness, key }));
|
|
2851
2861
|
await this.#sendMenuCard(key, chatId, { updateMessageId: messageId, replyTo: messageId });
|
|
2852
2862
|
return;
|
|
2853
2863
|
}
|
|
@@ -2903,8 +2913,9 @@ export class FeishuHarnessBridge {
|
|
|
2903
2913
|
await this.#showPresetCard(key, chatId, { updateMessageId: messageId });
|
|
2904
2914
|
return;
|
|
2905
2915
|
}
|
|
2906
|
-
if (action === 'models') {
|
|
2907
|
-
|
|
2916
|
+
if (action === 'models' || /^models:\d+$/.test(action)) {
|
|
2917
|
+
const page = action === 'models' ? 0 : Number(action.slice('models:'.length));
|
|
2918
|
+
await this.#showModelCard(key, chatId, { updateMessageId: messageId, page: Math.max(0, page) });
|
|
2908
2919
|
return;
|
|
2909
2920
|
}
|
|
2910
2921
|
if (action === 'status') {
|
|
@@ -2935,7 +2946,12 @@ export class FeishuHarnessBridge {
|
|
|
2935
2946
|
}
|
|
2936
2947
|
if (action.startsWith('model:select:')) {
|
|
2937
2948
|
const modelId = action.slice('model:select:'.length);
|
|
2938
|
-
await this.#handleModelSelect(key, chatId, modelId, { updateMessageId: messageId });
|
|
2949
|
+
await this.#handleModelSelect(key, chatId, modelId, { updateMessageId: messageId, page: modelPage });
|
|
2950
|
+
return;
|
|
2951
|
+
}
|
|
2952
|
+
if (action.startsWith('reasoning:select:')) {
|
|
2953
|
+
const effort = action.slice('reasoning:select:'.length);
|
|
2954
|
+
await this.#handleReasoningSelect(key, chatId, effort, { updateMessageId: messageId, page: modelPage });
|
|
2939
2955
|
return;
|
|
2940
2956
|
}
|
|
2941
2957
|
if (action.startsWith('use:')) {
|
|
@@ -3021,8 +3037,9 @@ export class FeishuHarnessBridge {
|
|
|
3021
3037
|
await this.#send(chatId, message, { replyTo: messageId });
|
|
3022
3038
|
return;
|
|
3023
3039
|
}
|
|
3040
|
+
let receipt;
|
|
3024
3041
|
try {
|
|
3025
|
-
await this.#state
|
|
3042
|
+
receipt = await startNewConversation({ state: this.#state, harness: this.#harness, key });
|
|
3026
3043
|
} catch (error) {
|
|
3027
3044
|
// A persistence error can still leave the in-memory binding cleared.
|
|
3028
3045
|
await finish('failed', safeErrorText(error));
|
|
@@ -3030,7 +3047,7 @@ export class FeishuHarnessBridge {
|
|
|
3030
3047
|
}
|
|
3031
3048
|
await finish('success');
|
|
3032
3049
|
// A receipt delivery failure must not turn a completed reset into a retry.
|
|
3033
|
-
await this.#send(chatId,
|
|
3050
|
+
await this.#send(chatId, receipt, { replyTo: messageId })
|
|
3034
3051
|
.catch((error) => this.#logger.warn?.('[dsh-feishu] new session receipt failed:', error?.message));
|
|
3035
3052
|
}
|
|
3036
3053
|
|
|
@@ -3183,11 +3200,11 @@ export class FeishuHarnessBridge {
|
|
|
3183
3200
|
}
|
|
3184
3201
|
}
|
|
3185
3202
|
|
|
3186
|
-
async #showWorkspaces({ chatId, key, replyTo = null }, { updateMessageId = null } = {}) {
|
|
3203
|
+
async #showWorkspaces({ chatId, key, replyTo = null }, { updateMessageId = null, includeConversationDirectories = false } = {}) {
|
|
3187
3204
|
try {
|
|
3188
3205
|
const { current, paths, titles } = await workspacePathSnapshot(
|
|
3189
3206
|
this.#harness,
|
|
3190
|
-
{ signal: this.#cardDataSignal(), includeTitles: true },
|
|
3207
|
+
{ signal: this.#cardDataSignal(), includeTitles: true, includeConversationDirectories },
|
|
3191
3208
|
);
|
|
3192
3209
|
this.#rememberMenu(key, { kind: 'workspaces', paths });
|
|
3193
3210
|
await this.#sendCard(
|
|
@@ -3246,6 +3263,9 @@ export class FeishuHarnessBridge {
|
|
|
3246
3263
|
sessionPage: Number.isSafeInteger(options.sessionPage) && options.sessionPage >= 0
|
|
3247
3264
|
? options.sessionPage
|
|
3248
3265
|
: 0,
|
|
3266
|
+
modelPage: Number.isSafeInteger(options.modelPage) && options.modelPage >= 0
|
|
3267
|
+
? options.modelPage
|
|
3268
|
+
: 0,
|
|
3249
3269
|
sessionLimit: Number.isSafeInteger(options.sessionLimit) && options.sessionLimit > 0
|
|
3250
3270
|
? options.sessionLimit
|
|
3251
3271
|
: null,
|
|
@@ -3526,7 +3546,7 @@ export class FeishuHarnessBridge {
|
|
|
3526
3546
|
/**
|
|
3527
3547
|
* Fetch the model catalog and show the model selection card.
|
|
3528
3548
|
*/
|
|
3529
|
-
async #showModelCard(key, chatId, { updateMessageId = null } = {}) {
|
|
3549
|
+
async #showModelCard(key, chatId, { updateMessageId = null, page = 0 } = {}) {
|
|
3530
3550
|
try {
|
|
3531
3551
|
const signal = this.#cardDataSignal();
|
|
3532
3552
|
await this.#harness.ensureRunning({ signal });
|
|
@@ -3542,7 +3562,7 @@ export class FeishuHarnessBridge {
|
|
|
3542
3562
|
if (!catalog) {
|
|
3543
3563
|
catalog = await this.#harness.listModels({ signal });
|
|
3544
3564
|
}
|
|
3545
|
-
await this.#sendCard(chatId, modelCard(catalog), { key, updateMessageId });
|
|
3565
|
+
await this.#sendCard(chatId, modelCard(catalog, { page }), { key, updateMessageId, modelPage: page });
|
|
3546
3566
|
} catch (error) {
|
|
3547
3567
|
await this.#sendFailure(chatId, error, { logLabel: 'model card', replyTo: updateMessageId });
|
|
3548
3568
|
}
|
|
@@ -3786,7 +3806,29 @@ export class FeishuHarnessBridge {
|
|
|
3786
3806
|
* catalog validation, busy checks, pending-interaction checks and the
|
|
3787
3807
|
* session binding lock stay in one place.
|
|
3788
3808
|
*/
|
|
3789
|
-
async #
|
|
3809
|
+
async #handleReasoningSelect(key, chatId, effort, { updateMessageId = null, replyTo = null, page = 0 } = {}) {
|
|
3810
|
+
try {
|
|
3811
|
+
const command = effort === REASONING_DEFAULT_SENTINEL ? '/reasoning --default' : `/reasoning ${effort}`;
|
|
3812
|
+
const result = await runModelCommand(command, this.#harness, this.#state, key, {
|
|
3813
|
+
signal: this.#signal,
|
|
3814
|
+
pendingInteraction: this.#hasPendingInteraction(key),
|
|
3815
|
+
control: { owner: this, key },
|
|
3816
|
+
});
|
|
3817
|
+
for (const reply of result?.messages ?? [result?.message]) {
|
|
3818
|
+
if (reply) await this.#send(chatId, reply, { replyTo });
|
|
3819
|
+
}
|
|
3820
|
+
} catch (error) {
|
|
3821
|
+
await this.#sendFailure(chatId, error, { logLabel: 'reasoning selection', replyTo: updateMessageId });
|
|
3822
|
+
return;
|
|
3823
|
+
}
|
|
3824
|
+
try {
|
|
3825
|
+
await this.#showModelCard(key, chatId, { updateMessageId, page });
|
|
3826
|
+
} catch (error) {
|
|
3827
|
+
this.#logger.warn?.('[dsh-feishu] model card refresh failed after reasoning select:', error.message);
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
|
|
3831
|
+
async #handleModelSelect(key, chatId, modelId, { updateMessageId = null, replyTo = null, page = 0 } = {}) {
|
|
3790
3832
|
try {
|
|
3791
3833
|
const result = await runModelCommand(
|
|
3792
3834
|
`/model ${modelId}`, this.#harness, this.#state, key, {
|
|
@@ -3803,9 +3845,9 @@ export class FeishuHarnessBridge {
|
|
|
3803
3845
|
return;
|
|
3804
3846
|
}
|
|
3805
3847
|
try {
|
|
3806
|
-
await this.#
|
|
3848
|
+
await this.#showModelCard(key, chatId, { updateMessageId, page });
|
|
3807
3849
|
} catch (error) {
|
|
3808
|
-
this.#logger.warn?.('[dsh-feishu]
|
|
3850
|
+
this.#logger.warn?.('[dsh-feishu] model card refresh failed after model select:', error.message);
|
|
3809
3851
|
}
|
|
3810
3852
|
}
|
|
3811
3853
|
|
|
@@ -5385,10 +5427,15 @@ export class FeishuHarnessBridge {
|
|
|
5385
5427
|
|
|
5386
5428
|
async #preparePrompt(event, key, message) {
|
|
5387
5429
|
const snapshot = this.#acceptedMessageIds.get(event.message.message_id);
|
|
5430
|
+
const originalFiles = Array.isArray(message.files) ? [...message.files] : [];
|
|
5388
5431
|
const build = async (input) => {
|
|
5389
5432
|
const rich = hasInboundImages(input) || hasReplyReference(input);
|
|
5390
5433
|
const original = rich
|
|
5391
|
-
? await promptContentForInboundMessage(input, {
|
|
5434
|
+
? await promptContentForInboundMessage(input, {
|
|
5435
|
+
signal: this.#signal,
|
|
5436
|
+
deferImages: true,
|
|
5437
|
+
originalFiles,
|
|
5438
|
+
})
|
|
5392
5439
|
: input.content;
|
|
5393
5440
|
const enhanced = enhanceContextContent(original, snapshot, () => ({
|
|
5394
5441
|
channel: 'feishu',
|
|
@@ -5410,7 +5457,12 @@ export class FeishuHarnessBridge {
|
|
|
5410
5457
|
&& (nonEmptyString(message.content) || hasInboundImages(message) || hasInboundFiles(message));
|
|
5411
5458
|
if (!topicAnchor) return build(message);
|
|
5412
5459
|
|
|
5413
|
-
|
|
5460
|
+
// Keep the temporary topic-root copy connected to the final request's
|
|
5461
|
+
// attachment array. Reply resolution may append lazy files to it.
|
|
5462
|
+
const withoutAnchor = {
|
|
5463
|
+
...message,
|
|
5464
|
+
files: Array.isArray(message.files) ? message.files : (message.files = []),
|
|
5465
|
+
};
|
|
5414
5466
|
delete withoutAnchor.replyTo;
|
|
5415
5467
|
const base = await build(withoutAnchor);
|
|
5416
5468
|
let preparedSessionId;
|
|
@@ -5426,6 +5478,7 @@ export class FeishuHarnessBridge {
|
|
|
5426
5478
|
}
|
|
5427
5479
|
const prepared = await build({
|
|
5428
5480
|
...message,
|
|
5481
|
+
files: message.files,
|
|
5429
5482
|
replyTo: {
|
|
5430
5483
|
...message.replyTo,
|
|
5431
5484
|
load: async (options) => {
|
|
@@ -19,9 +19,12 @@ import { workspaceLabels } from '../shared/workspace-labels.mjs';
|
|
|
19
19
|
import { normalizeFeishuStepCardPanels } from './step-push-mode.mjs';
|
|
20
20
|
|
|
21
21
|
export const MENU_PAGE_SIZE = 10;
|
|
22
|
+
export const MODEL_PAGE_SIZE = 20;
|
|
23
|
+
const MODEL_CARD_TEXT_LIMIT = 200;
|
|
22
24
|
|
|
23
25
|
/** 预设下拉中「跟随默认」(null) 的哨兵值,供 initial_index 命中与回调识别。 */
|
|
24
26
|
export const PRESET_FOLLOW_DEFAULT_SENTINEL = '__preset_follow_default__';
|
|
27
|
+
export const REASONING_DEFAULT_SENTINEL = '__reasoning_default__';
|
|
25
28
|
|
|
26
29
|
function plainText(content) {
|
|
27
30
|
return { tag: 'plain_text', content: String(content) };
|
|
@@ -240,10 +243,19 @@ export function menuCard(ctx) {
|
|
|
240
243
|
const curModelId = curModel ? `${curModel.provider}/${curModel.model}` : null;
|
|
241
244
|
const flat = [];
|
|
242
245
|
for (const group of groups) {
|
|
243
|
-
for (const model of (group.models || []))
|
|
246
|
+
for (const model of (group.models || [])) {
|
|
247
|
+
flat.push({
|
|
248
|
+
id: `${group.id}/${model.id}`,
|
|
249
|
+
name: `${group.name} - ${model.name}`,
|
|
250
|
+
reasoning: model.reasoning,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
244
253
|
}
|
|
245
254
|
let modelDropdown = null;
|
|
255
|
+
let reasoningDropdown = null;
|
|
246
256
|
if (flat.length > 1) {
|
|
257
|
+
// Keep the compact menu within Feishu select limits; the dedicated model
|
|
258
|
+
// card exposes the complete catalog.
|
|
247
259
|
const setModelOptions = flat.slice(0, 30).map((opt) => ({
|
|
248
260
|
text: { tag: 'plain_text', content: `${opt.id === curModelId ? '✓ ' : ''}${opt.name}` },
|
|
249
261
|
value: opt.id,
|
|
@@ -257,6 +269,28 @@ export function menuCard(ctx) {
|
|
|
257
269
|
behaviors: [{ type: 'callback', value: { action: 'model_pick' } }],
|
|
258
270
|
};
|
|
259
271
|
}
|
|
272
|
+
const selectedModel = flat.find((opt) => opt.id === curModelId);
|
|
273
|
+
const efforts = Array.isArray(selectedModel?.reasoning?.efforts)
|
|
274
|
+
? selectedModel.reasoning.efforts.filter((effort) => typeof effort?.id === 'string' && effort.id)
|
|
275
|
+
: [];
|
|
276
|
+
if (efforts.length > 0) {
|
|
277
|
+
const currentEffort = curModel?.reasoningEffort ?? selectedModel.reasoning.defaultEffort;
|
|
278
|
+
const effortOptions = [
|
|
279
|
+
{ id: REASONING_DEFAULT_SENTINEL, name: t('默认等级') },
|
|
280
|
+
...efforts.map((effort) => ({ id: effort.id, name: effort.name || effort.id })),
|
|
281
|
+
].map((effort) => ({
|
|
282
|
+
text: { tag: 'plain_text', content: `${effort.id === (currentEffort ?? REASONING_DEFAULT_SENTINEL) ? '✓ ' : ''}${effort.name}` },
|
|
283
|
+
value: effort.id,
|
|
284
|
+
}));
|
|
285
|
+
reasoningDropdown = {
|
|
286
|
+
tag: 'select_static',
|
|
287
|
+
name: 'reasoning_pick',
|
|
288
|
+
placeholder: { tag: 'plain_text', content: t('切换推理等级') },
|
|
289
|
+
initial_index: initialIndex(effortOptions, currentEffort ?? REASONING_DEFAULT_SENTINEL),
|
|
290
|
+
options: effortOptions,
|
|
291
|
+
behaviors: [{ type: 'callback', value: { action: 'reasoning_pick' } }],
|
|
292
|
+
};
|
|
293
|
+
}
|
|
260
294
|
|
|
261
295
|
// 渲染 2×2 网格:图标 + 下拉并列
|
|
262
296
|
// 每一行用 4 列 column_set:图标 | 下拉 | 图标 | 下拉
|
|
@@ -291,6 +325,12 @@ export function menuCard(ctx) {
|
|
|
291
325
|
tag: 'column_set', flex_mode: 'none',
|
|
292
326
|
columns: [iconCol('🤖'), dropdownCol(row2[0]), iconCol('🧠'), dropdownCol(row2[1])],
|
|
293
327
|
});
|
|
328
|
+
if (reasoningDropdown) {
|
|
329
|
+
elements.push({
|
|
330
|
+
tag: 'column_set', flex_mode: 'none',
|
|
331
|
+
columns: [iconCol('🧠'), dropdownCol(reasoningDropdown)],
|
|
332
|
+
});
|
|
333
|
+
}
|
|
294
334
|
|
|
295
335
|
// 新会话 + 全部会话按钮
|
|
296
336
|
const sessionButtons = buttonPair(newSessionLabel, 'new', t('📋 会话/关注'), 'sessions');
|
|
@@ -419,46 +459,52 @@ export function presetCard(catalog) {
|
|
|
419
459
|
* The catalog comes from `harness.listModels()` or `session.models()`.
|
|
420
460
|
* Groups are shown as text, then a flat dropdown for selection.
|
|
421
461
|
*/
|
|
422
|
-
export function modelCard(catalog) {
|
|
462
|
+
export function modelCard(catalog, { page = 0 } = {}) {
|
|
423
463
|
const { groups, current } = catalog;
|
|
424
464
|
const currentId = current ? `${current.provider}/${current.model}` : null;
|
|
465
|
+
const allModels = groups.flatMap((group) => group.models.map((model) => ({
|
|
466
|
+
group, model, id: `${group.id}/${model.id}`,
|
|
467
|
+
})));
|
|
468
|
+
const pages = Math.max(1, Math.ceil(allModels.length / MODEL_PAGE_SIZE));
|
|
469
|
+
const selectedPage = Number.isSafeInteger(page) && page >= 0 ? Math.min(page, pages - 1) : 0;
|
|
470
|
+
const currentOrdinal = currentId ? allModels.findIndex((entry) => entry.id === currentId) : -1;
|
|
471
|
+
const visibleModels = allModels.slice(selectedPage * MODEL_PAGE_SIZE, (selectedPage + 1) * MODEL_PAGE_SIZE);
|
|
425
472
|
|
|
426
473
|
const elements = [
|
|
427
474
|
{ tag: 'div', text: markdown(t('**当前模型**:{model}', { model: currentId || t('未设置') })) },
|
|
428
475
|
{ tag: 'hr' },
|
|
429
476
|
];
|
|
430
477
|
|
|
431
|
-
|
|
432
|
-
let total = 0;
|
|
433
|
-
for (const group of groups) total += group.models.length;
|
|
434
|
-
|
|
435
|
-
if (total === 0) {
|
|
478
|
+
if (allModels.length === 0) {
|
|
436
479
|
elements.push(
|
|
437
480
|
{ tag: 'div', text: markdown(t('当前没有可用模型。')) },
|
|
438
481
|
backButton(),
|
|
439
482
|
);
|
|
440
483
|
} else {
|
|
441
|
-
|
|
484
|
+
const currentUnavailable = currentId && currentOrdinal < 0;
|
|
485
|
+
elements.push({ tag: 'div', text: markdown(t('第 {page}/{pages} 页 · 共 {total} 个模型', {
|
|
486
|
+
page: selectedPage + 1, pages, total: allModels.length,
|
|
487
|
+
})) });
|
|
488
|
+
if (currentUnavailable) elements.push({ tag: 'div', text: markdown(t('当前模型不可用:{model}', { model: currentId })) });
|
|
489
|
+
// Bound the Markdown and the picker together, so a large catalog does not
|
|
490
|
+
// produce an oversized card or silently hide selectable entries.
|
|
442
491
|
for (const group of groups) {
|
|
443
|
-
const modelLines = group.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
elements.push(
|
|
492
|
+
const modelLines = visibleModels.filter((entry) => entry.group === group).map(({ id }) => (
|
|
493
|
+
`${id}${id === currentId ? ' ✓' : ''}`
|
|
494
|
+
));
|
|
495
|
+
if (modelLines.length) elements.push(
|
|
448
496
|
{ tag: 'div', text: markdown(`**${group.name}**\n${modelLines.join('\n')}`) },
|
|
449
497
|
);
|
|
450
498
|
}
|
|
451
499
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
}
|
|
500
|
+
const allOptions = visibleModels.map(({ group, model, id }) => ({
|
|
501
|
+
value: id,
|
|
502
|
+
text: { tag: 'plain_text', content: `${group.name} - ${model.name}`.slice(0, MODEL_CARD_TEXT_LIMIT) },
|
|
503
|
+
}));
|
|
504
|
+
const currentOption = allModels.find((entry) => entry.id === currentId)?.model;
|
|
505
|
+
const efforts = Array.isArray(currentOption?.reasoning?.efforts)
|
|
506
|
+
? currentOption.reasoning.efforts.filter((effort) => typeof effort?.id === 'string' && effort.id)
|
|
507
|
+
: [];
|
|
462
508
|
|
|
463
509
|
elements.push(
|
|
464
510
|
{ tag: 'hr' },
|
|
@@ -473,9 +519,34 @@ export function modelCard(catalog) {
|
|
|
473
519
|
})),
|
|
474
520
|
behaviors: [{ type: 'callback', value: { action: 'model_pick' } }],
|
|
475
521
|
},
|
|
476
|
-
{ tag: 'hr' },
|
|
477
|
-
backButton(),
|
|
478
522
|
);
|
|
523
|
+
if (efforts.length > 0) {
|
|
524
|
+
const currentEffort = current?.reasoningEffort ?? currentOption.reasoning.defaultEffort;
|
|
525
|
+
const effortOptions = [
|
|
526
|
+
{ id: REASONING_DEFAULT_SENTINEL, name: t('默认等级') },
|
|
527
|
+
...efforts.map((effort) => ({ id: effort.id, name: effort.name || effort.id })),
|
|
528
|
+
].map((effort) => ({
|
|
529
|
+
text: { tag: 'plain_text', content: `${effort.id === (currentEffort ?? REASONING_DEFAULT_SENTINEL) ? '✓ ' : ''}${effort.name}` },
|
|
530
|
+
value: effort.id,
|
|
531
|
+
}));
|
|
532
|
+
elements.push({
|
|
533
|
+
tag: 'select_static',
|
|
534
|
+
name: 'reasoning_pick',
|
|
535
|
+
placeholder: { tag: 'plain_text', content: t('切换推理等级') },
|
|
536
|
+
initial_index: initialIndex(effortOptions, currentEffort ?? REASONING_DEFAULT_SENTINEL),
|
|
537
|
+
options: effortOptions,
|
|
538
|
+
behaviors: [{ type: 'callback', value: { action: 'reasoning_pick' } }],
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
if (pages > 1) {
|
|
542
|
+
elements.push(buttonPair(
|
|
543
|
+
selectedPage > 0 ? t('◀ 上一页') : t('第一页'),
|
|
544
|
+
selectedPage > 0 ? `models:${selectedPage - 1}` : 'models:0',
|
|
545
|
+
selectedPage + 1 < pages ? t('下一页 ▶') : t('最后一页'),
|
|
546
|
+
selectedPage + 1 < pages ? `models:${selectedPage + 1}` : `models:${pages - 1}`,
|
|
547
|
+
));
|
|
548
|
+
}
|
|
549
|
+
elements.push({ tag: 'hr' }, backButton());
|
|
479
550
|
}
|
|
480
551
|
return cardWith(t('🧠 模型列表'), elements);
|
|
481
552
|
}
|
|
@@ -549,6 +549,7 @@ function feishuReplyReference(event, client) {
|
|
|
549
549
|
: {}),
|
|
550
550
|
...(content ? { content } : {}),
|
|
551
551
|
attachments,
|
|
552
|
+
...(quoted.files?.length ? { files: quoted.files } : {}),
|
|
552
553
|
...(messageType === 'interactive' && !content && attachments.length === 0
|
|
553
554
|
? { unavailableReason: 'unsupported' }
|
|
554
555
|
: {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
import { ApiError } from '@tencent-connect/qqbot-nodejs';
|
|
3
|
-
import { workspacePathSnapshot } from '../shared/workspace-command.mjs';
|
|
3
|
+
import { conversationSessionWorkspace, workspacePathSnapshot } from '../shared/workspace-command.mjs';
|
|
4
4
|
import { t } from '../shared/i18n.mjs';
|
|
5
5
|
|
|
6
6
|
export const QQ_MENU_TTL_MS = 15 * 60_000;
|
|
@@ -88,8 +88,7 @@ async function catalogFor(harness, sessionId, key, options) {
|
|
|
88
88
|
|
|
89
89
|
export async function qqMenuView(name, harness, state, key, { signal, busy = false } = {}) {
|
|
90
90
|
const workspace = harness.currentWorkspace?.();
|
|
91
|
-
const sessionWorkspace =
|
|
92
|
-
? harness.currentConversationWorkspace(key) : workspace;
|
|
91
|
+
const sessionWorkspace = await conversationSessionWorkspace(harness, key, { signal });
|
|
93
92
|
const sessionId = state.sessionFor(key);
|
|
94
93
|
const options = { signal };
|
|
95
94
|
const archived = state.includesArchivedSessions?.() === true;
|
|
@@ -97,7 +96,7 @@ export async function qqMenuView(name, harness, state, key, { signal, busy = fal
|
|
|
97
96
|
if (name === 'main' || name === 'status') {
|
|
98
97
|
if (name === 'status') await harness.ensureRunning(options);
|
|
99
98
|
const results = await Promise.allSettled([
|
|
100
|
-
harness.listWorkspaceSessions?.(
|
|
99
|
+
harness.listWorkspaceSessions?.(sessionWorkspace, options),
|
|
101
100
|
catalogFor(harness, sessionId, key, options),
|
|
102
101
|
harness.agentPresetSettings?.(options),
|
|
103
102
|
]);
|