@xmanrui/dsh-im 5.8.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.
Files changed (58) hide show
  1. package/README.en.md +42 -7
  2. package/README.md +53 -7
  3. package/docs/preset-workspaces.md +37 -0
  4. package/lib/client.js +34 -2
  5. package/lib/index.js +329 -326
  6. package/package.json +3 -1
  7. package/plugin-src/client/connection-error.js +1 -1
  8. package/plugin-src/host/channels/dingtalk/production.mjs +2 -1
  9. package/plugin-src/host/channels/feishu/production.mjs +2 -1
  10. package/plugin-src/host/channels/matrix/production.mjs +2 -1
  11. package/plugin-src/host/channels/qq/production.mjs +2 -1
  12. package/plugin-src/host/channels/shared/binding-events.mjs +130 -0
  13. package/plugin-src/host/channels/shared/production.mjs +32 -3
  14. package/plugin-src/host/channels/slack/production.mjs +2 -1
  15. package/plugin-src/host/channels/wecom/production.mjs +2 -1
  16. package/plugin-src/host/channels/wecom-app/production.mjs +2 -1
  17. package/plugin-src/host/channels/weixin/production.mjs +2 -1
  18. package/plugin-src/host/channels/whatsapp/production.mjs +2 -1
  19. package/plugin-src/host/delivery-adapter.mjs +122 -1
  20. package/plugin-src/host/delivery-service.mjs +40 -0
  21. package/plugin-src/host/ds-bot-client.mjs +28 -2
  22. package/plugin-src/host/index.mjs +24 -1
  23. package/plugin-src/host/modern-harness-api.mjs +3 -0
  24. package/scripts/telegram-menu-scopes.mjs +57 -0
  25. package/scripts/verify-interface-language.mjs +60 -15
  26. package/src/channels/dingtalk/dingtalk-bridge.mjs +2 -3
  27. package/src/channels/dingtalk/dingtalk-menu.mjs +4 -5
  28. package/src/channels/email/transports/imap-smtp.mjs +21 -11
  29. package/src/channels/feishu/bridge.mjs +46 -10
  30. package/src/channels/feishu/feishu-cards.mjs +96 -25
  31. package/src/channels/qq/qq-menu.mjs +3 -4
  32. package/src/channels/shared/action-card.mjs +331 -0
  33. package/src/channels/shared/bot-workspace-store.mjs +123 -8
  34. package/src/channels/shared/command-catalog.mjs +20 -5
  35. package/src/channels/shared/conversation/describe.mjs +116 -0
  36. package/src/channels/shared/conversation-state-store.mjs +62 -0
  37. package/src/channels/shared/diagnostic-details.mjs +38 -0
  38. package/src/channels/shared/harness-approval.mjs +58 -13
  39. package/src/channels/shared/harness-client.mjs +13 -0
  40. package/src/channels/shared/harness-session-binding.mjs +13 -1
  41. package/src/channels/shared/i18n-en/feishu.mjs +6 -0
  42. package/src/channels/shared/i18n-en/shared-a.mjs +9 -0
  43. package/src/channels/shared/i18n-en/telegram.mjs +14 -0
  44. package/src/channels/shared/i18n-ru/feishu.mjs +6 -0
  45. package/src/channels/shared/i18n-ru/shared-a.mjs +9 -0
  46. package/src/channels/shared/i18n-ru/telegram.mjs +14 -0
  47. package/src/channels/shared/model-command.mjs +5 -0
  48. package/src/channels/shared/preset-workspaces.mjs +48 -0
  49. package/src/channels/shared/qr-encoding-error.mjs +8 -2
  50. package/src/channels/shared/status-command.mjs +159 -0
  51. package/src/channels/shared/text-harness-bridge.mjs +86 -4
  52. package/src/channels/shared/workspace-command.mjs +20 -12
  53. package/src/channels/shared/workspace-session.mjs +30 -5
  54. package/src/channels/telegram/approval-card.mjs +379 -0
  55. package/src/channels/telegram/telegram-api.mjs +10 -1
  56. package/src/channels/telegram/telegram-bridge.mjs +7 -0
  57. package/src/channels/telegram/telegram-runtime.mjs +125 -13
  58. package/src/channels/wecom/wecom-bridge.mjs +5 -3
@@ -36,7 +36,11 @@ export const inject = [
36
36
  ];
37
37
 
38
38
  function channelConfig(config, name, deliveryService) {
39
- const channel = { ...(config.dshHome ? { dshHome: config.dshHome } : {}), ...config[name] };
39
+ const channel = {
40
+ ...(config.dshHome ? { dshHome: config.dshHome } : {}),
41
+ ...(config.groupByAgentPreset === undefined ? {} : { groupByAgentPreset: config.groupByAgentPreset }),
42
+ ...config[name],
43
+ };
40
44
  const withAuthority = config.rpcAuthority === undefined
41
45
  ? channel
42
46
  : { ...channel, rpcAuthority: config.rpcAuthority };
@@ -97,6 +101,21 @@ export function createImHostPlugin(internals = {}) {
97
101
  unavailableSessionSyncChannels: unavailableSessionSyncChannels.map((channel) => channel === 'wecomApp' ? 'wecom-app' : channel),
98
102
  dsBot: createDsBotClient(ctx),
99
103
  });
104
+ /** Sessions already reported, so the log stays one line per session. */
105
+ const describedSessions = new Set();
106
+ const describeConversationLogged = async (sessionId) => {
107
+ const described = await deliveryService.describeConversation(sessionId);
108
+ if (described && !describedSessions.has(sessionId)) {
109
+ describedSessions.add(sessionId);
110
+ const log = typeof ctx?.logger === 'function' ? ctx.logger(name) : (ctx?.logger ?? console);
111
+ try {
112
+ log?.info?.(`describeConversation session=${sessionId} chat=${described.conversationKey} sender=${described.senderId ?? '-'}`);
113
+ } catch {
114
+ // Logging must never break the lookup.
115
+ }
116
+ }
117
+ return described;
118
+ };
100
119
  if (typeof ctx?.provide === 'function') {
101
120
  ctx.provide('dshIm', Object.freeze({
102
121
  contractVersion: 1,
@@ -105,6 +124,10 @@ export function createImHostPlugin(internals = {}) {
105
124
  consumeInbound: (botId, options) => deliveryService.consumeInbound(botId, options),
106
125
  historyChecked: (botId, route, query, options) => deliveryService.historyChecked(botId, route, query, options),
107
126
  replyChecked: (botId, route, text, options) => deliveryService.replyChecked(botId, route, text, options),
127
+ describeConversation: (sessionId) => describeConversationLogged(sessionId),
128
+ // Prompt assembly is synchronous, so a caller that needs the identity
129
+ // before the first step cannot await the async variant.
130
+ describeConversationSync: (sessionId) => deliveryService.describeConversationSync(sessionId),
108
131
  describeBot: (botId) => deliveryService.describeBot(botId),
109
132
  sendChecked: (botId, targetId, text, options) => deliveryService.sendChecked(botId, targetId, text, options),
110
133
  send: (botId, targetId, text, options) => (
@@ -225,6 +225,9 @@ class ModernHarnessApi {
225
225
  describe: (request) => rpcResult(request, () => ({ ready: true, transport: 'typert' })),
226
226
  });
227
227
  this.workspace = Object.freeze({
228
+ rename: (request, signal) => rpcResult(request, () => this.#invoke(
229
+ 'workspace', 'rename', { request: request.payload }, signal,
230
+ )),
228
231
  list: (request, signal) => rpcResult(request, () => this.#workspaceList(signal)),
229
232
  create: (request, signal) => rpcResult(request, () => this.#invoke(
230
233
  'workspace', 'create', { request: request.payload }, signal,
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Scoped Telegram command-menu bookkeeping for the live acceptance script.
3
+ *
4
+ * The bot registers commands per BotCommandScope (see
5
+ * src/channels/telegram/telegram-runtime.mjs). An acceptance script that saved,
6
+ * polled and restored only the default scope would (a) never see the menu the
7
+ * plugin now writes into `all_private_chats`, and (b) restore an old default
8
+ * list that the plugin had already cleared. Both the save and the restore must
9
+ * therefore cover all three scopes.
10
+ *
11
+ * The helpers are pure wrappers around a `callTelegram(method, payload)`
12
+ * function so they can be unit-tested without any network access.
13
+ */
14
+ import { TELEGRAM_COMMAND_MENU_SCOPES } from '../src/channels/telegram/telegram-runtime.mjs';
15
+
16
+ export const DEFAULT_COMMAND_SCOPE = null;
17
+ export const PRIVATE_COMMAND_SCOPE = TELEGRAM_COMMAND_MENU_SCOPES.private;
18
+ export const GROUP_COMMAND_SCOPE = TELEGRAM_COMMAND_MENU_SCOPES.group;
19
+
20
+ /** Every scope the plugin may write, in registration order. */
21
+ export const VERIFY_COMMAND_SCOPES = Object.freeze([
22
+ Object.freeze({ name: 'default', scope: DEFAULT_COMMAND_SCOPE }),
23
+ Object.freeze({ name: 'private', scope: PRIVATE_COMMAND_SCOPE }),
24
+ Object.freeze({ name: 'group', scope: GROUP_COMMAND_SCOPE }),
25
+ ]);
26
+
27
+ export function commandPayloadFor(scope) {
28
+ return scope ? { scope } : {};
29
+ }
30
+
31
+ /** Snapshot every scope the plugin can touch, so the original state can be restored. */
32
+ export async function saveScopedMenus(callTelegram) {
33
+ const saved = new Map();
34
+ for (const { name, scope } of VERIFY_COMMAND_SCOPES) {
35
+ saved.set(name, await callTelegram('getMyCommands', commandPayloadFor(scope)));
36
+ }
37
+ return saved;
38
+ }
39
+
40
+ /**
41
+ * Restore a snapshot. Scoped lists go first and the default scope goes last:
42
+ * if a restore fails midway, a leftover scoped menu still wins over a partially
43
+ * restored default scope, which is the safer failure direction.
44
+ */
45
+ export async function restoreScopedMenus(callTelegram, saved) {
46
+ for (const { name, scope } of [...VERIFY_COMMAND_SCOPES].reverse()) {
47
+ const commands = saved.get(name) ?? [];
48
+ if (commands.length > 0) {
49
+ await callTelegram('setMyCommands', {
50
+ commands,
51
+ ...commandPayloadFor(scope),
52
+ });
53
+ } else {
54
+ await callTelegram('deleteMyCommands', commandPayloadFor(scope));
55
+ }
56
+ }
57
+ }
@@ -8,8 +8,13 @@
8
8
  * user-settings document.
9
9
  *
10
10
  * Set DSH_IM_TELEGRAM_TOKEN to additionally bind a real bot and assert the
11
- * command menu Telegram itself stores. That step is skipped without a token,
12
- * and it restores the bot's original menu when it finishes.
11
+ * command menu Telegram itself stores. That step is skipped without a token.
12
+ * The plugin registers its menu per BotCommandScope, so the live check saves,
13
+ * polls and restores all three scopes (default, all_private_chats,
14
+ * all_group_chats); polling only the default scope would wait forever.
15
+ *
16
+ * Offline: `node scripts/verify-interface-language.mjs --check-scopes` prints
17
+ * the scope plan and exits without a Harness checkout, network or token.
13
18
  */
14
19
  import assert from 'node:assert/strict';
15
20
  import { spawn } from 'node:child_process';
@@ -18,11 +23,34 @@ import { request as httpRequest } from 'node:http';
18
23
  import { tmpdir } from 'node:os';
19
24
  import { dirname, join, resolve } from 'node:path';
20
25
 
26
+ import {
27
+ GROUP_COMMAND_SCOPE,
28
+ PRIVATE_COMMAND_SCOPE,
29
+ VERIFY_COMMAND_SCOPES,
30
+ restoreScopedMenus,
31
+ saveScopedMenus,
32
+ } from './telegram-menu-scopes.mjs';
33
+
21
34
  const harnessRoot = process.argv[2];
22
- if (!harnessRoot || process.argv.includes('--help')) {
35
+ if (process.argv.includes('--help')) {
23
36
  console.log('Usage: node scripts/verify-interface-language.mjs /path/to/built/deepseek-harness');
37
+ console.log(' node scripts/verify-interface-language.mjs --check-scopes (offline scope self-check)');
24
38
  console.log(' DSH_IM_TELEGRAM_TOKEN=<token> node scripts/verify-interface-language.mjs ... (adds the live menu check)');
25
- process.exit(harnessRoot ? 0 : 1);
39
+ process.exit(0);
40
+ }
41
+ if (process.argv.includes('--check-scopes')) {
42
+ console.table(VERIFY_COMMAND_SCOPES.map(({ name, scope }) => ({
43
+ scope: name,
44
+ payload: JSON.stringify(scope ? { scope } : {}),
45
+ })));
46
+ console.log(`Offline self-check passed: ${VERIFY_COMMAND_SCOPES.length} Telegram command scopes`
47
+ + ' (default/private/group) are saved, polled and restored.');
48
+ process.exit(0);
49
+ }
50
+ if (!harnessRoot) {
51
+ console.log('Usage: node scripts/verify-interface-language.mjs /path/to/built/deepseek-harness');
52
+ console.log(' node scripts/verify-interface-language.mjs --check-scopes (offline scope self-check)');
53
+ process.exit(1);
26
54
  }
27
55
  const pluginRoot = resolve(import.meta.dirname, '..');
28
56
  await access(join(pluginRoot, 'lib/index.js'));
@@ -56,7 +84,7 @@ async function resolveHarness(root) {
56
84
  const harness = await resolveHarness(harnessRoot);
57
85
  const cli = harness.cli;
58
86
  const botToken = process.env.DSH_IM_TELEGRAM_TOKEN;
59
- let telegramMenu;
87
+ let savedMenus;
60
88
  const directory = await mkdtemp(join(tmpdir(), 'dsh-im-language-test-'));
61
89
  const home = join(directory, 'home');
62
90
  const profile = join(home, 'profiles/web');
@@ -264,7 +292,9 @@ try {
264
292
  record('the language route refuses malformed payloads', '4 cases');
265
293
 
266
294
  if (botToken) {
267
- telegramMenu = await telegram('getMyCommands');
295
+ // The plugin writes per scope; save every scope it may touch before binding
296
+ // so the original state can be restored exactly.
297
+ savedMenus = await saveScopedMenus(telegram);
268
298
  const bound = await rpc(browser, 'telegram', 'bot.bind-credentials', { token: botToken });
269
299
  assert.equal(bound.ok, true, 'the bot must bind');
270
300
  const botId = bound.value.bots.at(-1).botId;
@@ -272,16 +302,32 @@ try {
272
302
  const status = await rpc(browser, 'telegram', 'connection.status');
273
303
  return status.value?.bots?.find(item => item.botId === botId)?.connected ? true : null;
274
304
  });
275
- const english = await waitFor('Telegram stores the English menu', async () => {
276
- const commands = await telegram('getMyCommands');
305
+ const english = await waitFor('Telegram stores the English menu in the private-chat scope', async () => {
306
+ const commands = await telegram('getMyCommands', { scope: PRIVATE_COMMAND_SCOPE });
277
307
  const help = commands.find(item => item.command === 'help');
278
308
  return help && !HAN.test(help.description) ? commands : null;
279
309
  });
280
- record('Telegram stores the English command menu while DSH is English', `${english.length} commands`);
310
+ record('Telegram stores the English command menu in the private-chat scope',
311
+ `${english.length} commands`);
312
+
313
+ await waitFor('the legacy default-scope menu is cleared', async () => {
314
+ const commands = await telegram('getMyCommands');
315
+ return commands.length === 0 ? true : null;
316
+ });
317
+ record('the scoped registration clears the legacy default-scope menu', 'default scope empty');
318
+
319
+ const groupCommands = await telegram('getMyCommands', { scope: GROUP_COMMAND_SCOPE });
320
+ for (const directOnly of ['history', 'batch', 'send', 'cancel']) {
321
+ assert.equal(groupCommands.some(item => item.command === directOnly), false,
322
+ `the group menu must not advertise /${directOnly}`);
323
+ }
324
+ assert.equal(groupCommands.length, english.length - 4,
325
+ 'the group menu is the private menu without the four direct-chat-only commands');
326
+ record('the group scope omits direct-chat-only commands', `${groupCommands.length} commands`);
281
327
 
282
328
  await selectInterfaceLanguage('zh');
283
329
  const chinese = await waitFor('Telegram stores the Chinese menu after the switch', async () => {
284
- const commands = await telegram('getMyCommands');
330
+ const commands = await telegram('getMyCommands', { scope: PRIVATE_COMMAND_SCOPE });
285
331
  const help = commands.find(item => item.command === 'help');
286
332
  return help && HAN.test(help.description) ? commands : null;
287
333
  });
@@ -316,17 +362,16 @@ try {
316
362
  console.table(results);
317
363
  console.log(`Passed ${results.length} real HTTP checks against an unmodified DSH CLI (${harness.kind} layout).`);
318
364
  console.log(botToken
319
- ? 'The live Telegram menu was exercised and the bot\'s original menu was restored.'
365
+ ? 'The live Telegram menu was exercised; the bot\'s original menus were restored in all three scopes.'
320
366
  : 'Set DSH_IM_TELEGRAM_TOKEN to additionally assert the menu Telegram itself stores.');
321
367
  console.log('The temporary home contains no bot credentials and is removed after the server stops.');
322
368
  } finally {
323
369
  await stop();
324
- if (botToken && telegramMenu !== undefined) {
370
+ if (botToken && savedMenus !== undefined) {
325
371
  try {
326
- if (telegramMenu.length > 0) await telegram('setMyCommands', { commands: telegramMenu });
327
- else await telegram('deleteMyCommands');
372
+ await restoreScopedMenus(telegram, savedMenus);
328
373
  } catch {
329
- console.error('could not restore the bot\'s original command menu');
374
+ console.error('could not restore the bot\'s original command menus');
330
375
  }
331
376
  }
332
377
  await rm(directory, { recursive: true, force: true });
@@ -30,7 +30,7 @@ import {
30
30
  isPresetCommand,
31
31
  runPresetCommand,
32
32
  } from '../shared/preset-command.mjs';
33
- import { runWorkspaceCommand } from '../shared/workspace-command.mjs';
33
+ import { conversationSessionWorkspace, runWorkspaceCommand } from '../shared/workspace-command.mjs';
34
34
  import { askInWorkspaceSession } from '../shared/workspace-session.mjs';
35
35
  import {
36
36
  captureContextEnhancement,
@@ -940,8 +940,7 @@ export class DingtalkHarnessBridge {
940
940
  });
941
941
  return;
942
942
  }
943
- const sessionWorkspace = typeof this.#harness.currentConversationWorkspace === 'function'
944
- ? this.#harness.currentConversationWorkspace(key) : this.#harness.currentWorkspace?.();
943
+ const sessionWorkspace = await conversationSessionWorkspace(this.#harness, key, { signal: this.#signal });
945
944
  if (entry.workspace !== this.#harness.currentWorkspace?.()
946
945
  || entry.sessionWorkspace !== sessionWorkspace
947
946
  || entry.sessionId !== this.#state.sessionFor(key)) {
@@ -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 = () => typeof harness.currentConversationWorkspace === 'function'
23
- ? harness.currentConversationWorkspace(key) : harness.currentWorkspace?.();
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
- client.on('error', () => { /* surfaced by the caller's poll/connection state */ });
47
- await client.connect();
48
- await client.mailboxOpen(this.#config.mailbox ?? 'INBOX');
49
- this.#imap = client;
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
- try {
121
- const message = await this.#imap.fetchOne(String(uid), { source: true }, { uid: true });
122
- return message?.source ?? null;
123
- } catch {
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. */
@@ -96,6 +96,7 @@ import { isSharedLocalCommand } from '../shared/command-permission.mjs';
96
96
  import {
97
97
  MENU_PAGE_SIZE,
98
98
  PRESET_FOLLOW_DEFAULT_SENTINEL,
99
+ REASONING_DEFAULT_SENTINEL,
99
100
  STEER_CUSTOM_SENTINEL,
100
101
  approvalCard,
101
102
  completionCard,
@@ -2429,7 +2430,9 @@ export class FeishuHarnessBridge {
2429
2430
  ? `preset:select:${option}`
2430
2431
  : action === 'model_pick' && typeof option === 'string'
2431
2432
  ? `model:select:${option}`
2432
- : action === 'archive_pick' && typeof option === 'string'
2433
+ : action === 'reasoning_pick' && typeof option === 'string'
2434
+ ? `reasoning:select:${option}`
2435
+ : action === 'archive_pick' && typeof option === 'string'
2433
2436
  ? `archive:${option}`
2434
2437
  : action === 'steer_pick' && typeof option === 'string'
2435
2438
  ? `steer:${option}`
@@ -2438,6 +2441,7 @@ export class FeishuHarnessBridge {
2438
2441
  ?? nonEmptyString(event?.open_message_id)
2439
2442
  ?? nonEmptyString(event?.message_id);
2440
2443
  const route = messageId ? this.#cardKeys.get(messageId) : null;
2444
+ const modelPage = route?.modelPage ?? 0;
2441
2445
  if (!route) {
2442
2446
  // A route is also the trusted direct/group scope for the unified policy.
2443
2447
  // Without it, fail closed instead of producing an unauthorised side effect.
@@ -2479,7 +2483,7 @@ export class FeishuHarnessBridge {
2479
2483
  this.#cardKeys.set(messageId, route);
2480
2484
  const newSessionActionId = nonEmptyString(actionValue.newSessionActionId);
2481
2485
  if (resolvedAction === 'new' && (!route.menuContext || !newSessionActionId)) return Promise.resolve();
2482
- const entry = { ...route, messageId, selections: multiValues, operatorOpenId, newSessionActionId };
2486
+ const entry = { ...route, messageId, selections: multiValues, operatorOpenId, newSessionActionId, modelPage };
2483
2487
  const source = nonEmptyString(actionValue.source);
2484
2488
  const formText = nonEmptyString(formValue.steer_text);
2485
2489
  const eventId = nonEmptyString(event?.event_id)
@@ -2688,6 +2692,7 @@ export class FeishuHarnessBridge {
2688
2692
  sessionWorkspace = null,
2689
2693
  sessionPage = 0,
2690
2694
  sessionLimit = null,
2695
+ modelPage = 0,
2691
2696
  selections = [],
2692
2697
  actor = null,
2693
2698
  menuContext = null,
@@ -2908,8 +2913,9 @@ export class FeishuHarnessBridge {
2908
2913
  await this.#showPresetCard(key, chatId, { updateMessageId: messageId });
2909
2914
  return;
2910
2915
  }
2911
- if (action === 'models') {
2912
- await this.#showModelCard(key, chatId, { updateMessageId: messageId });
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) });
2913
2919
  return;
2914
2920
  }
2915
2921
  if (action === 'status') {
@@ -2940,7 +2946,12 @@ export class FeishuHarnessBridge {
2940
2946
  }
2941
2947
  if (action.startsWith('model:select:')) {
2942
2948
  const modelId = action.slice('model:select:'.length);
2943
- 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 });
2944
2955
  return;
2945
2956
  }
2946
2957
  if (action.startsWith('use:')) {
@@ -3252,6 +3263,9 @@ export class FeishuHarnessBridge {
3252
3263
  sessionPage: Number.isSafeInteger(options.sessionPage) && options.sessionPage >= 0
3253
3264
  ? options.sessionPage
3254
3265
  : 0,
3266
+ modelPage: Number.isSafeInteger(options.modelPage) && options.modelPage >= 0
3267
+ ? options.modelPage
3268
+ : 0,
3255
3269
  sessionLimit: Number.isSafeInteger(options.sessionLimit) && options.sessionLimit > 0
3256
3270
  ? options.sessionLimit
3257
3271
  : null,
@@ -3532,7 +3546,7 @@ export class FeishuHarnessBridge {
3532
3546
  /**
3533
3547
  * Fetch the model catalog and show the model selection card.
3534
3548
  */
3535
- async #showModelCard(key, chatId, { updateMessageId = null } = {}) {
3549
+ async #showModelCard(key, chatId, { updateMessageId = null, page = 0 } = {}) {
3536
3550
  try {
3537
3551
  const signal = this.#cardDataSignal();
3538
3552
  await this.#harness.ensureRunning({ signal });
@@ -3548,7 +3562,7 @@ export class FeishuHarnessBridge {
3548
3562
  if (!catalog) {
3549
3563
  catalog = await this.#harness.listModels({ signal });
3550
3564
  }
3551
- await this.#sendCard(chatId, modelCard(catalog), { key, updateMessageId });
3565
+ await this.#sendCard(chatId, modelCard(catalog, { page }), { key, updateMessageId, modelPage: page });
3552
3566
  } catch (error) {
3553
3567
  await this.#sendFailure(chatId, error, { logLabel: 'model card', replyTo: updateMessageId });
3554
3568
  }
@@ -3792,7 +3806,29 @@ export class FeishuHarnessBridge {
3792
3806
  * catalog validation, busy checks, pending-interaction checks and the
3793
3807
  * session binding lock stay in one place.
3794
3808
  */
3795
- async #handleModelSelect(key, chatId, modelId, { updateMessageId = null, replyTo = null } = {}) {
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 } = {}) {
3796
3832
  try {
3797
3833
  const result = await runModelCommand(
3798
3834
  `/model ${modelId}`, this.#harness, this.#state, key, {
@@ -3809,9 +3845,9 @@ export class FeishuHarnessBridge {
3809
3845
  return;
3810
3846
  }
3811
3847
  try {
3812
- await this.#sendMenuCard(key, chatId, { updateMessageId, replyTo });
3848
+ await this.#showModelCard(key, chatId, { updateMessageId, page });
3813
3849
  } catch (error) {
3814
- this.#logger.warn?.('[dsh-feishu] menu refresh failed after model select:', error.message);
3850
+ this.#logger.warn?.('[dsh-feishu] model card refresh failed after model select:', error.message);
3815
3851
  }
3816
3852
  }
3817
3853