@xmanrui/dsh-im 5.5.0 → 5.6.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 (50) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +2 -2
  3. package/lib/client.js +309 -243
  4. package/lib/index.js +307 -307
  5. package/package.json +4 -4
  6. package/plugin-src/client/channels/dingtalk/index.js +12 -9
  7. package/plugin-src/client/channels/feishu/group-settings.js +5 -5
  8. package/plugin-src/client/channels/feishu/index.js +33 -25
  9. package/plugin-src/client/channels/qq/index.js +5 -5
  10. package/plugin-src/client/channels/shared/token-api.js +12 -7
  11. package/plugin-src/client/channels/shared/token-channel.js +18 -11
  12. package/plugin-src/client/channels/wecom/index.js +5 -5
  13. package/plugin-src/client/channels/wecom-app/index.js +3 -3
  14. package/plugin-src/client/channels/weixin/index.js +2 -2
  15. package/plugin-src/client/channels/whatsapp/index.js +6 -6
  16. package/plugin-src/client/credential-binding.js +3 -2
  17. package/plugin-src/client/delivery-settings.js +3 -3
  18. package/plugin-src/client/ds-bot-settings.js +3 -3
  19. package/plugin-src/client/global-settings.js +5 -2
  20. package/plugin-src/client/i18n-ru.js +56 -34
  21. package/plugin-src/client/i18n.js +210 -124
  22. package/scripts/verify-package.mjs +1 -1
  23. package/src/channels/dingtalk/dingtalk-bridge.mjs +1 -0
  24. package/src/channels/feishu/bridge.mjs +25 -3
  25. package/src/channels/feishu/feishu-cards.mjs +1 -45
  26. package/src/channels/feishu/slash-command-panel.mjs +2 -5
  27. package/src/channels/qq/qq-bridge.mjs +1 -0
  28. package/src/channels/shared/bot-workspace-store.mjs +1 -1
  29. package/src/channels/shared/command-catalog.mjs +8 -5
  30. package/src/channels/shared/delivery-failure-log.mjs +111 -0
  31. package/src/channels/shared/diagnostic-details.mjs +1 -0
  32. package/src/channels/shared/harness-client.mjs +12 -6
  33. package/src/channels/shared/i18n-en/shared-b.mjs +5 -0
  34. package/src/channels/shared/i18n-en/shared-c.mjs +3 -0
  35. package/src/channels/shared/i18n-en/telegram.mjs +6 -0
  36. package/src/channels/shared/i18n-ru/shared-b.mjs +5 -0
  37. package/src/channels/shared/i18n-ru/shared-c.mjs +3 -0
  38. package/src/channels/shared/i18n-ru/telegram.mjs +5 -0
  39. package/src/channels/shared/message-failure.mjs +5 -2
  40. package/src/channels/shared/session-error.mjs +8 -0
  41. package/src/channels/shared/text-harness-bridge.mjs +201 -3
  42. package/src/channels/shared/workspace-command.mjs +41 -16
  43. package/src/channels/shared/workspace-labels.mjs +65 -0
  44. package/src/channels/shared/workspace-session.mjs +24 -4
  45. package/src/channels/telegram/telegram-api.mjs +31 -2
  46. package/src/channels/telegram/telegram-bridge.mjs +58 -0
  47. package/src/channels/telegram/telegram-runtime.mjs +85 -3
  48. package/src/channels/wecom/wecom-bridge.mjs +1 -0
  49. package/src/channels/wecom-app/wecom-app-bridge.mjs +1 -0
  50. package/src/channels/weixin/weixin-bridge.mjs +1 -0
@@ -6,14 +6,69 @@ import * as React from 'react';
6
6
 
7
7
  export const IM_LOCALE_NAMESPACE = 'dsh-im';
8
8
 
9
+ // Sentences the settings UI composes itself: the dictionaries carry them as
10
+ // templates with `{name}` placeholders, looked up like any other key and filled in
11
+ // after translation (see localizeTemplate), so word order belongs to the target
12
+ // language instead of the Chinese sentence it was assembled from.
13
+ const COMPOSED = Object.freeze({
14
+ '使用 Bot Token 接入 {channel} 机器人': 'Connect a {channel} bot with a Bot Token',
15
+ '已接入的 {channel} 机器人': 'Connected {channel} bots',
16
+ '正在读取 {channel} 机器人状态…': 'Loading {channel} bot status…',
17
+ '无法读取 {channel} 机器人状态': 'Could not load {channel} bot status',
18
+ '尚未接入 {channel} 机器人': 'No {channel} bot connected yet',
19
+ '手动接入{channel}机器人': 'Connect {channel} bot manually',
20
+ '{channel} 设置': '{channel} settings',
21
+ '{name}机器人设置': '{name} bot settings',
22
+ '{channel}机器人': '{channel} bot',
23
+ '{channel} 服务返回了无法识别的响应': '{channel} service returned an unrecognized response',
24
+ '{channel} 操作失败': '{channel} operation failed',
25
+ '{channel}连接尚未就绪': '{channel} connection is not ready',
26
+ '{channel} 服务没有返回有效的机器人列表': '{channel} service did not return a valid bot list',
27
+ '{channel}操作失败,请稍后重试': '{channel} operation failed; try again later',
28
+ '{channel} 设置页缺少 RPC 连接': 'The {channel} settings are missing an RPC connection',
29
+ '{subject}运行正常': '{subject} is healthy',
30
+ '{connected} / {configured} 在线': '{connected}/{configured} online',
31
+ '已接入 {configured} 个机器人,其中 {connected} 个在线': '{connected} of {configured} bots online',
32
+ '从 DeepSeek Harness 移除“{name}”?': 'Remove “{name}” from DeepSeek Harness?',
33
+ '从 DeepSeek Harness 移除{name}': 'Remove {name} from DeepSeek Harness',
34
+ '移除{name}': 'Remove {name}',
35
+ '{bot}操作失败,请查看机器人状态。': '{bot} operation failed. Check the bot status.',
36
+ '这会停止消息连接,并删除本机保存的 {credentials}、机器人配置及会话映射。{platform}中的机器人不会被自动删除。': 'This stops the message connection and removes the locally stored {credentials}, bot configuration, and session mappings. The bot in {platform} is not deleted.',
37
+ '{bot}的飞书授权流程': 'Feishu authorization flow for {bot}',
38
+ '用于为{bot}补全权限与回调的一次性授权二维码': 'One-time QR code for completing permissions and the callback for {bot}',
39
+ '用于为{bot}开通群消息权限的一次性授权二维码': 'One-time QR code for granting group-message permission to {bot}',
40
+ '正在为「{bot}」补全权限与回调': 'Completing permissions and the callback for “{bot}”',
41
+ '正在为「{bot}」开通群消息权限': 'Granting group-message permission to “{bot}”',
42
+ '为{bot}补全权限与回调': 'Complete permissions and the callback for {bot}',
43
+ '{bot}的权限与回调已补全。': 'Permissions and the callback completed for {bot}.',
44
+ '{bot}的权限补全二维码已生成,请使用飞书扫码。': 'Permission-completion QR code generated for {bot}. Scan it with Feishu.',
45
+ '{bot}的群消息权限二维码已生成,请使用飞书确认。': 'Group-message permission QR code generated for {bot}. Confirm it with Feishu.',
46
+ '{bot}已开通群消息权限,并启用“响应所有群消息”。': '{bot} now has group-message permission and “Respond to all group messages” is enabled.',
47
+ '{bot}已连接,可以在飞书中开始聊天。': '{bot} is connected and ready to chat in Feishu.',
48
+ '{bot}连接检查完成。': '{bot} connection check completed.',
49
+ '{bot}已重新连接。': '{bot} reconnected.',
50
+ '{bot}已从此 DeepSeek Harness 移除;飞书开放平台中的应用未被删除。': '{bot} was removed from this DeepSeek Harness. The app in Feishu Open Platform was not deleted.',
51
+ '{bot}移除失败,请重试。': '{bot} could not be removed; try again.',
52
+ '检查连接{name}': 'Check connection {name}',
53
+ '重试连接{name}': 'Reconnect {name}',
54
+ '二维码剩余 {remaining}': 'QR code expires in {remaining}',
55
+ '连接检查失败:{error}(参考号:{reference})': 'Connection check failed: {error} (reference: {reference})',
56
+ '连接检查失败:{error}': 'Connection check failed: {error}',
57
+ '操作失败:{error}': 'Operation failed: {error}',
58
+ '状态刷新失败:{error}': 'Status refresh failed: {error}',
59
+ '状态自动刷新失败:{error}': 'Automatic status refresh failed: {error}',
60
+ '请输入 -1、0 或 1~{max} 之间的整数。': 'Enter -1, 0, or an integer from 1 to {max}.',
61
+ });
62
+
9
63
  const EN = Object.freeze({
64
+ ...COMPOSED,
10
65
  "私聊对象": "Private chat",
11
66
  "选择私聊对象": "Select a private chat",
12
67
  "仅支持已经建立会话的私聊,请先与机器人私聊后刷新。": "Only established private chats are supported. Message the bot privately, then refresh.",
13
68
  "选择 DS Bot 和私聊对象,直接使用 Bot 的会话。": "Choose a DS Bot and a private chat to use the Bot’s session.",
14
69
  "还没有可绑定的私聊。先给这个机器人发一条私聊消息,再点击刷新。": "No private chats yet. Send this bot a private message, then refresh.",
15
70
 
16
- "绑定bot": "Bind bot",
71
+ "绑定 DS Bot": "Bind DS Bot",
17
72
  "正在检测 DS Bot…": "Checking DS Bot…",
18
73
  "选择 DS Bot": "Select DS Bot",
19
74
  "暂无可选 DS Bot": "No available DS Bots",
@@ -26,7 +81,7 @@ const EN = Object.freeze({
26
81
  "DS Bot 尚未启用,请在 DSH 插件管理中启用后刷新。": "DS Bot is disabled. Enable it in DSH plugin management, then refresh.",
27
82
  "暂时无法读取 DS Bot,请检查插件是否正常运行后重试。": "Unable to read DS Bot. Check that the plugin is running, then retry.",
28
83
  "DS Bot 当前由其他 Host 管理,请在运行它的 Host 中绑定。": "DS Bot is managed by another Host. Bind it on that Host.",
29
- "绑定bot仅支持当前 Host 的会话,请先检查机器人的 Harness 连接设置。": "Bot binding requires the current Host. Check the bot’s Harness connection settings.",
84
+ "绑定 DS Bot 仅支持当前 Host 的会话,请先检查机器人的 Harness 连接设置。": "DS Bot binding requires the current Host. Check the bot’s Harness connection settings.",
30
85
  "所选 DS Bot 已不存在,请刷新后重新选择。": "The selected DS Bot no longer exists. Refresh and select another.",
31
86
  "绑定设置保存失败,请刷新后重试。": "Could not save the binding. Refresh and retry.",
32
87
  "绑定已保存。": "Binding saved.",
@@ -688,13 +743,6 @@ const EN = Object.freeze({
688
743
  '飞书服务返回的应用更新信息缺少 botId': 'Feishu app-update status is missing the bot ID',
689
744
  '飞书服务返回了不匹配的注册进度': 'Feishu returned registration progress for a different operation',
690
745
  '此机器人': 'this bot',
691
- '用于为${botName}开通群消息权限的一次性授权二维码': 'One-time QR code for granting group-message permission to ${botName}',
692
- '正在为「${botName}」开通群消息权限': 'Granting group-message permission to “${botName}”',
693
- '${botName ?? "机器人"}的权限补全二维码已生成,请使用飞书扫码。': 'Permission-completion QR code generated for ${botName ?? "bot"}. Scan it with Feishu.',
694
- '${botName ?? "机器人"}的群消息权限二维码已生成,请使用飞书确认。': 'Group-message permission QR code generated for ${botName ?? "bot"}. Confirm it with Feishu.',
695
- '${targetBotName}已开通群消息权限,并启用“响应所有群消息”。': '${targetBotName} now has group-message permission and “Respond to all group messages” is enabled.',
696
- '${targetBot.bot.name}已开通群消息权限,并启用“响应所有群消息”。': '${targetBot.bot.name} now has group-message permission and “Respond to all group messages” is enabled.',
697
- '${targetBot.bot.name}已连接,可以在飞书中开始聊天。': '${targetBot.bot.name} is connected and ready to chat in Feishu.',
698
746
  '已取消补全权限与回调。': 'Completing permissions and the callback was cancelled.',
699
747
  '已取消群消息权限授权。': 'Group-message permission authorization was cancelled.',
700
748
  '权限与回调已更新,但暂时无法确认机器人连接状态': 'Permissions and the callback were updated, but the bot connection could not be confirmed yet',
@@ -943,7 +991,6 @@ const EN = Object.freeze({
943
991
  '钉钉扫码服务没有返回有效的绑定任务': 'DingTalk did not return a valid setup attempt',
944
992
  '钉钉 Stream 长连接运行正常': 'DingTalk Stream connection is healthy',
945
993
  '钉钉服务没有返回有效的机器人列表': 'DingTalk did not return a valid bot list',
946
- '${totals.connected} / ${totals.configured} 在线': '${totals.connected} / ${totals.configured} online',
947
994
  '用于把钉钉机器人接入 DeepSeek Harness 的一次性二维码': 'One-time QR code for connecting a DingTalk bot to DeepSeek Harness',
948
995
  '二维码已过期\\n请重新生成': 'QR code expired\\nGenerate a new one',
949
996
  '机器人已创建,正在建立消息连接': 'Bot created. Starting the message connection',
@@ -959,18 +1006,13 @@ const EN = Object.freeze({
959
1006
  '飞书服务没有返回连接状态': 'Feishu did not return connection status',
960
1007
  '飞书服务没有返回创建进度': 'Feishu did not return creation progress',
961
1008
  '飞书服务返回了未知的创建状态': 'Feishu returned an unknown creation status',
962
- '已接入 ${totals.configured} 个机器人,其中 ${totals.connected} 个在线': '${totals.connected} of ${totals.configured} bots online',
963
1009
  '尚未接入机器人': 'No bot connected yet',
964
1010
  '用于新增 DeepSeek Harness 飞书机器人的一次性授权二维码': 'One-time authorization QR code for adding a Feishu bot to DeepSeek Harness',
965
1011
  '请刷新后重新扫码': 'Refresh and scan again',
966
- '${connected ? "检查连接" : "重试连接"}${bot.name}': '${connected ? "Check connection" : "Reconnect"} ${bot.name}',
967
1012
  '无法读取飞书机器人': 'Could not load Feishu bots',
968
1013
  '授权二维码已生成,请使用飞书扫码。': 'Authorization QR code generated. Scan it with Feishu.',
969
1014
  '飞书机器人凭据已绑定。': 'Feishu bot credentials connected.',
970
1015
  '已取消添加机器人。': 'Adding the bot was cancelled.',
971
- '${newBot.bot.name}已连接,可以在飞书中开始聊天。': '${newBot.bot.name} is connected and ready to chat in Feishu.',
972
- '${bot.name}操作失败,请查看机器人状态。': '${bot.name} operation failed. Check the bot status.',
973
- '${bot.name}已从此 DeepSeek Harness 移除;飞书开放平台中的应用未被删除。': '${bot.name} was removed from this DeepSeek Harness. The app in Feishu Open Platform was not deleted.',
974
1016
  '无法读取连接状态': 'Could not load connection status',
975
1017
  'QQ 服务没有返回扫码绑定进度': 'QQ did not return QR setup progress',
976
1018
  'QQ 扫码服务没有返回有效的绑定任务': 'QQ did not return a valid setup attempt',
@@ -981,10 +1023,6 @@ const EN = Object.freeze({
981
1023
  'QQ 服务没有返回有效的机器人列表': 'QQ did not return a valid bot list',
982
1024
  '尚未绑定 QQ 机器人': 'No QQ bot connected yet',
983
1025
  '用于绑定 QQ 机器人的一次性二维码': 'One-time QR code for connecting a QQ bot',
984
- '${channel}${connectionSummary}运行正常': '${channel}${connectionSummary} is healthy',
985
- '${channel} 服务没有返回有效的机器人列表': '${channel} did not return a valid bot list',
986
- '使用 Bot Token 接入 ${channel} 机器人': 'Connect a ${channel} bot with a Bot Token',
987
- '${model.totals.connected} / ${model.totals.configured} 在线': '${model.totals.connected}/${model.totals.configured} online',
988
1026
  ' Bot API 长轮询': ' Bot API long polling',
989
1027
  '企业微信服务没有返回扫码绑定进度': 'WeCom did not return QR setup progress',
990
1028
  '企业微信扫码服务没有返回有效的绑定任务': 'WeCom did not return a valid setup attempt',
@@ -1015,7 +1053,6 @@ const EN = Object.freeze({
1015
1053
  '用于把微信机器人绑定到 DeepSeek Harness 的一次性二维码': 'One-time QR code for connecting a WeChat bot to DeepSeek Harness',
1016
1054
  '保持本页打开,等待消息长轮询变为在线': 'Keep this page open until long polling is online',
1017
1055
  '微信二维码已生成,请使用手机微信扫描。': 'WeChat QR code generated. Scan it with WeChat on your phone.',
1018
- '移除失败:${presentError(error).message}': 'Removal failed: ${presentError(error).message}',
1019
1056
  '无法读取微信状态': 'Could not load WeChat status',
1020
1057
  'WhatsApp 服务没有返回扫码进度': 'WhatsApp did not return QR setup progress',
1021
1058
  'WhatsApp 服务没有返回有效的扫码任务': 'WhatsApp did not return a valid setup attempt',
@@ -1139,7 +1176,6 @@ const EN = Object.freeze({
1139
1176
  '永久保留,不会自动清理': 'Keep forever; nothing is removed automatically',
1140
1177
  '每 Turn 结束后立即清理': 'Cleaned up as soon as each turn ends',
1141
1178
  '小时后自动清理': 'hours until automatic cleanup',
1142
- '请输入 -1、0 或 1~${INBOUND_TTL_MAX_HOURS} 之间的整数。': 'Enter -1, 0, or an integer from 1 to ${INBOUND_TTL_MAX_HOURS}.',
1143
1179
  '设置保存失败,请稍后重试。': 'Could not save the setting. Try again later.',
1144
1180
  '已保存': 'Saved',
1145
1181
  '通用设置暂不可用。': 'General settings are unavailable.',
@@ -1340,121 +1376,171 @@ export function installImRussianLocale(locale) {
1340
1376
  };
1341
1377
  }
1342
1378
 
1343
- function channelName(value) {
1379
+ /**
1380
+ * Localise a channel name the way the settings UI writes it: "微信" becomes
1381
+ * "WeChat" in English and Russian alike, while a name that is already Latin
1382
+ * ("Telegram") is handed back unchanged.
1383
+ */
1384
+ export function channelName(value) {
1344
1385
  return localizeText(value);
1345
1386
  }
1346
1387
 
1347
- function translateDynamic(text) {
1348
- const configMessage = /^微信配置格式错误:(config\.json|workspaces\.json)。请查看诊断详情,修复后重启 DSH。$/.exec(text);
1349
- if (configMessage) return EN['微信配置格式错误:{file}。请查看诊断详情,修复后重启 DSH。'].replace('{file}', configMessage[1]);
1350
- const configHint = /^(.*?)请检查微信渠道数据目录中的 (config\.json|workspaces\.json),修复后重启 DSH;“重新读取”不会重新加载配置。\s*(字段位置中的序号从 0 开始,按文件中的条目顺序计数,不包含真实账号标识。)?$/.exec(text);
1351
- if (configHint) return [
1352
- localizeText(configHint[1].trim()),
1353
- EN['请检查微信渠道数据目录中的 {file},修复后重启 DSH;“重新读取”不会重新加载配置。'].replace('{file}', configHint[2]),
1354
- configHint[3] ? localizeText(configHint[3]) : '',
1388
+ // A broken WeChat configuration: the prefix, a `{file}` template sentence and an
1389
+ // optional counter sentence, each resolved in the active language.
1390
+ function configHint(match) {
1391
+ return [
1392
+ localizeText(match[1].trim()),
1393
+ translate('请检查微信渠道数据目录中的 {file},修复后重启 DSH;“重新读取”不会重新加载配置。').replace('{file}', match[2]),
1394
+ match[3] ? localizeText(match[3]) : '',
1355
1395
  ].filter(Boolean).join(' ');
1356
- const guidanceLimit = /^增强提示词不得超过 (\d+) 个字符。$/.exec(text);
1357
- if (guidanceLimit) return `Guidance must not exceed ${guidanceLimit[1]} characters.`;
1358
- let match = /^(\d+) \/ (\d+) 在线$/.exec(text);
1359
- if (match) return `${match[1]}/${match[2]} online`;
1360
- match = /^已接入 (\d+) 个机器人,其中 (\d+) 个在线$/.exec(text);
1361
- if (match) return `${match[2]} of ${match[1]} bots online`;
1362
- match = /^请输入 -1、0 或 1~(\d+) 之间的整数。$/.exec(text);
1363
- if (match) return `Enter -1, 0, or an integer from 1 to ${match[1]}.`;
1364
- match = /^正在读取\s*(.+?)\s*机器人状态…$/.exec(text);
1365
- if (match) return `Loading ${channelName(match[1])} bot status…`;
1366
- match = /^无法读取\s*(.+?)\s*机器人状态$/.exec(text);
1367
- if (match) return `Could not load ${channelName(match[1])} bot status`;
1368
- match = /^尚未接入\s*(.+?)\s*机器人$/.exec(text);
1369
- if (match) return `No ${channelName(match[1])} bot connected yet`;
1370
- match = /^已接入的\s*(.+?)\s*机器人$/.exec(text);
1371
- if (match) return `Connected ${channelName(match[1])} bots`;
1372
- match = /^手动接入(.+)机器人$/.exec(text);
1373
- if (match) return `Connect ${channelName(match[1])} bot manually`;
1374
- match = /^(.+) 设置$/.exec(text);
1375
- if (match) return `${channelName(match[1])} settings`;
1376
- match = /^从 DeepSeek Harness 移除“(.+)”?$/.exec(text);
1377
- if (match) return `Remove “${match[1]}” from DeepSeek Harness?`;
1378
- match = /^从 DeepSeek Harness 移除(.+)$/.exec(text);
1379
- if (match) return `Remove ${match[1]} from DeepSeek Harness`;
1380
- match = /^(.+)的飞书授权流程$/.exec(text);
1381
- if (match) return `Feishu authorization flow for ${match[1]}`;
1382
- match = /^用于为(.+)补全权限与回调的一次性授权二维码$/.exec(text);
1383
- if (match) return `One-time QR code for completing permissions and the callback for ${match[1]}`;
1384
- match = /^用于为(.+)开通群消息权限的一次性授权二维码$/.exec(text);
1385
- if (match) return `One-time QR code for granting group-message permission to ${match[1]}`;
1386
- match = /^正在为「(.+)」补全权限与回调$/.exec(text);
1387
- if (match) return `Completing permissions and the callback for “${match[1]}”`;
1388
- match = /^正在为「(.+)」开通群消息权限$/.exec(text);
1389
- if (match) return `Granting group-message permission to “${match[1]}”`;
1390
- match = /^为(.+)补全权限与回调$/.exec(text);
1391
- if (match) return `Complete permissions and the callback for ${match[1]}`;
1392
- match = /^(.+)的权限补全二维码已生成,请使用飞书扫码。$/.exec(text);
1393
- if (match) return `Permission-completion QR code generated for ${match[1]}. Scan it with Feishu.`;
1394
- match = /^(.+)的群消息权限二维码已生成,请使用飞书确认。$/.exec(text);
1395
- if (match) return `Group-message permission QR code generated for ${match[1]}. Confirm it with Feishu.`;
1396
- match = /^(.+)的权限与回调已补全。$/.exec(text);
1397
- if (match) return `Permissions and the callback completed for ${match[1]}.`;
1398
- match = /^(.+)已开通群消息权限,并启用“响应所有群消息”。$/.exec(text);
1399
- if (match) return `${match[1]} now has group-message permission and “Respond to all group messages” is enabled.`;
1400
- match = /^(检查连接|重试连接)(.+)$/.exec(text);
1401
- if (match) return `${localizeText(match[1])} ${match[2]}`;
1402
- match = /^移除(.+)$/.exec(text);
1403
- if (match) return `Remove ${match[1]}`;
1404
- match = /^这会停止消息连接,并删除本机保存的 (.+)、机器人配置及会话映射。(.+)中的机器人不会被自动删除。$/.exec(text);
1405
- if (match) {
1406
- return `This stops the message connection and removes the locally stored ${localizeText(match[1])}, bot configuration, and session mappings. The bot in ${localizeText(match[2])} is not deleted.`;
1407
- }
1408
- match = /^二维码剩余 (.+)$/.exec(text);
1409
- if (match) return `QR code expires in ${match[1]}`;
1410
- match = /^最近一条消息处理失败:(.+)$/.exec(text);
1411
- if (match) return `Latest message failed: ${localizeText(match[1])}`;
1412
- match = /^图片下载失败(HTTP (.+)),请重新发送后再试。$/.exec(text);
1413
- if (match) return `The image download failed (HTTP ${match[1]}). Send it again.`;
1414
- match = /^一次最多只能处理 (\d+) 张图片。$/.exec(text);
1415
- if (match) return `A message can contain at most ${match[1]} images.`;
1416
- match = /^状态刷新失败:(.+)$/.exec(text);
1417
- if (match) return `Status refresh failed: ${match[1]}`;
1418
- match = /^状态自动刷新失败:(.+)$/.exec(text);
1419
- if (match) return `Automatic status refresh failed: ${match[1]}`;
1420
- match = /^操作失败:(.+)$/.exec(text);
1421
- if (match) return `Operation failed: ${match[1]}`;
1422
- match = /^连接检查失败:(.+)(参考号:(.+))$/.exec(text);
1423
- if (match) return `Connection check failed: ${localizeText(match[1])} (reference: ${match[2]})`;
1424
- match = /^连接检查失败:(.+)$/.exec(text);
1425
- if (match) return `Connection check failed: ${match[1]}`;
1426
- match = /^移除失败:(.+)$/.exec(text);
1427
- if (match) return `Removal failed: ${match[1]}`;
1396
+ }
1397
+
1398
+ // Sentences composed outside the settings UI — a bot status or an RPC error that the
1399
+ // host, or an IM platform, has already assembled — arrive as one string with no key
1400
+ // to look up, so they are recognised by the Chinese shape they are built from. The
1401
+ // client's own sentences are not here: they are template keys in the dictionaries
1402
+ // (see COMPOSED and localizeTemplate), which keeps this table to the text that really
1403
+ // has no key. Every rule carries a rendering per locale; `en` and `ru` are both
1404
+ // mandatory, because a rule with an English column only is exactly what left a
1405
+ // Russian reader looking at Chinese. Chinese needs no column of its own.
1406
+ const DYNAMIC_RULES = Object.freeze([
1407
+ {
1408
+ pattern: /^微信配置格式错误:(config\.json|workspaces\.json)。请查看诊断详情,修复后重启 DSH。$/,
1409
+ // Both dictionaries already hold this sentence as a `{file}` template, so the
1410
+ // rendering goes through the lookup rather than restating the text here.
1411
+ en: (match) => EN['微信配置格式错误:{file}。请查看诊断详情,修复后重启 DSH。'].replace('{file}', match[1]),
1412
+ ru: (match) => translate('微信配置格式错误:{file}。请查看诊断详情,修复后重启 DSH。').replace('{file}', match[1]),
1413
+ },
1414
+ {
1415
+ pattern: /^(.*?)请检查微信渠道数据目录中的 (config\.json|workspaces\.json),修复后重启 DSH;“重新读取”不会重新加载配置。\s*(字段位置中的序号从 0 开始,按文件中的条目顺序计数,不包含真实账号标识。)?$/,
1416
+ en: (match) => configHint(match),
1417
+ ru: (match) => configHint(match),
1418
+ },
1419
+ {
1420
+ pattern: /^增强提示词不得超过 (\d+) 个字符。$/,
1421
+ en: (match) => `Guidance must not exceed ${match[1]} characters.`,
1422
+ ru: (match) => `Подсказка для контекста не должна превышать ${match[1]} символов.`,
1423
+ },
1424
+ {
1425
+ pattern: /^一次最多只能处理 (\d+) 张图片。$/,
1426
+ en: (match) => `A message can contain at most ${match[1]} images.`,
1427
+ ru: (match) => `В одном сообщении может быть не больше ${match[1]} изображений.`,
1428
+ },
1429
+ {
1430
+ pattern: /^图片下载失败(HTTP (.+)),请重新发送后再试。$/,
1431
+ en: (match) => `The image download failed (HTTP ${match[1]}). Send it again.`,
1432
+ ru: (match) => `Не удалось скачать изображение (HTTP ${match[1]}). Отправьте его заново.`,
1433
+ },
1434
+ ]);
1435
+
1436
+ // Chinese fragments that survive inside messages no rule above recognises. Each row
1437
+ // carries the source fragment and its rendering per locale, so the last-resort path
1438
+ // is a table too rather than an English-only swap list.
1439
+ const DYNAMIC_PHRASES = Object.freeze([
1440
+ ['企业微信', 'WeCom', 'WeCom'],
1441
+ ['DeepSeek Harness', 'DeepSeek Harness', 'DeepSeek Harness'],
1442
+ ['WhatsApp', 'WhatsApp', 'WhatsApp'],
1443
+ ['iMessage', 'iMessage', 'iMessage'],
1444
+ ['macOS Messages', 'macOS Messages', 'macOS Messages'],
1445
+ ['Telegram', 'Telegram', 'Telegram'],
1446
+ ['Discord', 'Discord', 'Discord'],
1447
+ ['Slack', 'Slack', 'Slack'],
1448
+ ['飞书', 'Feishu', 'Feishu'],
1449
+ ['钉钉', 'DingTalk', 'DingTalk'],
1450
+ ['微信', 'WeChat', 'WeChat'],
1451
+ ['机器人', 'bot', 'бот'],
1452
+ ['账号', 'account', 'аккаунт'],
1453
+ ['应用', 'app', 'приложение'],
1454
+ ['凭据', 'credentials', 'учётные данные'],
1455
+ ['服务返回了无法识别的响应', 'service returned an unrecognized response', 'сервис вернул нераспознанный ответ'],
1456
+ ['服务没有返回有效的机器人列表', 'service did not return a valid bot list', 'сервис не вернул список ботов'],
1457
+ ['操作失败,请稍后重试', 'operation failed; try again later', 'операция не удалась, попробуйте позже'],
1458
+ ['操作失败', 'operation failed', 'операция не удалась'],
1459
+ ['连接尚未就绪', 'connection is not ready', 'подключение ещё не готово'],
1460
+ ['没有接入完成', 'was not connected', 'подключить не удалось'],
1461
+ ['没有绑定完成', 'was not connected', 'подключить не удалось'],
1462
+ ['设置页缺少 RPC 连接', 'settings are missing an RPC connection', 'в настройках нет подключения RPC'],
1463
+ ['设置', 'settings', 'настройки'],
1464
+ ['连接检查完成', 'connection check completed', 'проверка подключения завершена'],
1465
+ ['仍未连接,插件会继续自动重试', 'is still offline; the plugin will keep retrying', 'всё ещё не подключён, плагин продолжит попытки'],
1466
+ ['已重新连接', 'reconnected', 'переподключено'],
1467
+ ['移除失败,请重试', 'could not be removed; try again', 'удалить не удалось, попробуйте снова'],
1468
+ ['已连接,可以开始聊天', 'is connected and ready to chat', 'подключён, можно начинать переписку'],
1469
+ ['已连接,可以开始发送消息', 'is connected and ready for messages', 'подключён и готов отправлять сообщения'],
1470
+ ['服务请求失败', 'service request failed', 'запрос к сервису не удался'],
1471
+ // Failure reasons the host embeds in a message: they arrive as a captured phrase
1472
+ // inside an already localised sentence, so they need a translation of their own.
1473
+ ['网络中断', 'network down', 'сеть недоступна'],
1474
+ ['请求超时', 'request timed out', 'истекло время ожидания'],
1475
+ ['超时', 'timed out', 'истекло время ожидания'],
1476
+ ['服务不可用', 'service unavailable', 'сервис недоступен'],
1477
+ ['连接被拒绝', 'connection refused', 'соединение отклонено'],
1478
+ ['未授权', 'unauthorized', 'нет авторизации'],
1479
+ ['响应格式错误', 'malformed response', 'неверный формат ответа'],
1480
+ ['连接遇到问题', 'connection encountered a problem', 'проблема с подключением'],
1481
+ ['正在读取', 'Loading ', 'Загружаем '],
1482
+ ['连接状态', 'connection status', 'состояние подключения'],
1483
+ ['二维码', 'QR code', 'QR-код'],
1484
+ ]);
1485
+
1486
+ // The rules and their renderings, exposed so a test can hold every pattern to the
1487
+ // same per-locale contract instead of trusting the order of the chain below.
1488
+ export const IM_DYNAMIC_RULES = DYNAMIC_RULES;
1489
+ export const IM_DYNAMIC_PHRASES = DYNAMIC_PHRASES;
1428
1490
 
1429
- const phrases = [
1430
- ['企业微信', 'WeCom'], ['DeepSeek Harness', 'DeepSeek Harness'],
1431
- ['WhatsApp', 'WhatsApp'], ['iMessage', 'iMessage'], ['macOS Messages', 'macOS Messages'],
1432
- ['Telegram', 'Telegram'], ['Discord', 'Discord'],
1433
- ['Slack', 'Slack'], ['飞书', 'Feishu'], ['钉钉', 'DingTalk'], ['微信', 'WeChat'],
1434
- ['机器人', 'bot'], ['账号', 'account'], ['应用', 'app'], ['凭据', 'credentials'],
1435
- ['服务返回了无法识别的响应', 'service returned an unrecognized response'],
1436
- ['服务没有返回有效的机器人列表', 'service did not return a valid bot list'],
1437
- ['操作失败,请稍后重试', 'operation failed; try again later'],
1438
- ['操作失败', 'operation failed'], ['连接尚未就绪', 'connection is not ready'],
1439
- ['没有接入完成', 'was not connected'], ['没有绑定完成', 'was not connected'],
1440
- ['设置页缺少 RPC 连接', 'settings are missing an RPC connection'],
1441
- ['设置', 'settings'], ['连接检查完成', 'connection check completed'],
1442
- ['仍未连接,插件会继续自动重试', 'is still offline; the plugin will keep retrying'],
1443
- ['已重新连接', 'reconnected'], ['移除失败,请重试', 'could not be removed; try again'],
1444
- ['已连接,可以开始聊天', 'is connected and ready to chat'],
1445
- ['已连接,可以开始发送消息', 'is connected and ready for messages'],
1446
- ['服务请求失败', 'service request failed'], ['连接遇到问题', 'connection encountered a problem'],
1447
- ['正在读取', 'Loading '], ['连接状态', 'connection status'], ['二维码', 'QR code'],
1448
- ];
1491
+ /**
1492
+ * Localise a sentence the UI composed at runtime, e.g. `已接入的 Telegram 机器人`.
1493
+ *
1494
+ * @param text - the composed sentence, in the language the patterns are written in.
1495
+ * @param locale - `'en'`, `'ru'` or `'zh'`; anything else is served English, and
1496
+ * Chinese is the identity language, so its text travels untouched.
1497
+ * @returns the sentence in the requested locale, or `text` when nothing matches.
1498
+ */
1499
+ export function translateDynamic(text, locale = imLocale()) {
1500
+ if (locale === 'zh') return text;
1501
+ const column = locale === 'ru' ? 'ru' : 'en';
1502
+ for (const rule of DYNAMIC_RULES) {
1503
+ const match = rule.pattern.exec(text);
1504
+ if (!match) continue;
1505
+ return (rule[column] ?? rule.en)(match);
1506
+ }
1507
+ const at = column === 'ru' ? 2 : 1;
1449
1508
  let output = text;
1450
- for (const [source, target] of phrases) output = output.replaceAll(source, target);
1509
+ for (const row of DYNAMIC_PHRASES) output = output.replaceAll(row[0], row[at]);
1451
1510
  return output;
1452
1511
  }
1453
1512
 
1513
+ const TEMPLATE_PLACEHOLDER = /\{(\w+)\}/gu;
1514
+
1515
+ /**
1516
+ * Localise a sentence the settings UI composes itself, from a template key both
1517
+ * dictionaries carry: `已接入的 {channel} 机器人`. The key is looked up like any other
1518
+ * string — so a Russian reader gets the Russian sentence — and the values are filled
1519
+ * in afterwards, which keeps the word order of the translation instead of the
1520
+ * Chinese one the sentence was assembled from. A key neither dictionary knows comes
1521
+ * back as the key with its placeholders still visible, the same identity the rest of
1522
+ * the module falls back to.
1523
+ *
1524
+ * @param key - the Chinese template, e.g. `尚未接入 {channel} 机器人`.
1525
+ * @param values - one value per placeholder; a missing one keeps its braces so the
1526
+ * gap is visible instead of silently empty.
1527
+ */
1528
+ export function localizeTemplate(key, values) {
1529
+ if (typeof key !== 'string') return key;
1530
+ const template = translate(key);
1531
+ if (values == null) return template;
1532
+ return template.replace(TEMPLATE_PLACEHOLDER, (placeholder, name) => (
1533
+ Object.hasOwn(values, name) ? String(values[name]) : placeholder
1534
+ ));
1535
+ }
1536
+
1454
1537
  export function localizeText(value) {
1455
1538
  if (typeof value !== 'string') return value;
1456
1539
  const exact = translate(value);
1457
- if (exact !== value || !isEnglish()) return exact;
1540
+ if (exact !== value) return exact;
1541
+ // A whole-string lookup missing means the UI composed the sentence at runtime.
1542
+ // Chinese is the identity language, so `translateDynamic` hands the text back in
1543
+ // its own language there and renders it in the active locale everywhere else.
1458
1544
  return translateDynamic(value);
1459
1545
  }
1460
1546
 
@@ -225,7 +225,7 @@ const directDependencies = {
225
225
  '@tencent-connect/qqbot-nodejs': '1.0.4',
226
226
  '@wecom/aibot-node-sdk': '1.0.7',
227
227
  qrcode: '1.5.4',
228
- undici: '7.29.1',
228
+ undici: '7.30.1',
229
229
  };
230
230
  for (const [name, version] of Object.entries(directDependencies)) {
231
231
  if (manifest.dependencies?.[name] !== version) {
@@ -1399,6 +1399,7 @@ export class DingtalkHarnessBridge {
1399
1399
  if (cardStarted) cardStartedAt = startedAt;
1400
1400
  }
1401
1401
  const { answer, artifacts = [] } = await askInWorkspaceSession({
1402
+ onNotice: (notice) => this.#send(sessionWebhook, notice, this.#atUsersFor(message)),
1402
1403
  deferredDelivery: () => ({ coordinator: this.#deferred, target: { ...cardTarget(message, sender), robotCode: this.#clientId } }),
1403
1404
  harness: this.#harness,
1404
1405
  state: this.#state,
@@ -145,6 +145,8 @@ const UNWATCH_COMMAND = /^\/unwatch(?:\s+([^\s]+))?$/i;
145
145
  const WATCHLIST_COMMAND = /^\/watchlist$/i;
146
146
  const SESSION_LIST_PREFIX = /^\/(?:sessionlist|sessions)(?:\s|$)/i;
147
147
  const WORKSPACE_LIST_COMMAND = /^\/(?:workspacelist|workspaces|wsl)$/i;
148
+ // After the merge a bare /workspace or /ws opens the same picker card.
149
+ const BARE_WORKSPACE_COMMAND = /^\/(?:workspace|ws)$/i;
148
150
  const NUMBER_REPLY = /^\d{1,2}$/;
149
151
  /** A displayed menu stays number-tappable for this long. */
150
152
  const MENU_TTL_MS = 10 * 60_000;
@@ -1894,7 +1896,7 @@ export class FeishuHarnessBridge {
1894
1896
  );
1895
1897
  return;
1896
1898
  }
1897
- if (WORKSPACE_LIST_COMMAND.test(commandText)) {
1899
+ if (BARE_WORKSPACE_COMMAND.test(commandText) || WORKSPACE_LIST_COMMAND.test(commandText)) {
1898
1900
  await this.#showWorkspaces({ chatId: event.message.chat_id, key, replyTo: event.message.message_id });
1899
1901
  return;
1900
1902
  }
@@ -2016,7 +2018,12 @@ export class FeishuHarnessBridge {
2016
2018
  }
2017
2019
  throw error;
2018
2020
  } finally {
2019
- await this.#cancelPendingInteraction(key);
2021
+ // Synced questions (including DS Bot's ask_user) outlive the turn that
2022
+ // presented them. Only turn-owned questions belong to this cleanup;
2023
+ // their failed-delivery/error paths must still resolve by cancellation.
2024
+ if (this.#pendingInteractions.get(key)?.lifecycle !== 'session-sync') {
2025
+ await this.#cancelPendingInteraction(key);
2026
+ }
2020
2027
  await this.#approvals.closeRoute(key);
2021
2028
  this.#voiceTurns.delete(key);
2022
2029
  }
@@ -5564,6 +5571,7 @@ export class FeishuHarnessBridge {
5564
5571
  let completed;
5565
5572
  try {
5566
5573
  completed = await askInWorkspaceSession({
5574
+ onNotice: (notice) => this.#send(chatId, notice, { replyTo: messageId }),
5567
5575
  deferredDelivery: () => ({ coordinator: this.#deferred, chatId, replyToMessageId: messageId }),
5568
5576
  harness: this.#harness,
5569
5577
  state: this.#state,
@@ -5814,6 +5822,7 @@ export class FeishuHarnessBridge {
5814
5822
  const { content, contextEnhanced } = prompt;
5815
5823
  if (!this.#channel?.stream) {
5816
5824
  const { sessionId, answer, artifacts = [] } = await askInWorkspaceSession({
5825
+ onNotice: (notice) => this.#send(chatId, notice, { replyTo: messageId }),
5817
5826
  deferredDelivery: () => ({ coordinator: this.#deferred, chatId, replyToMessageId: messageId }),
5818
5827
  harness: this.#harness,
5819
5828
  state: this.#state,
@@ -5897,6 +5906,7 @@ export class FeishuHarnessBridge {
5897
5906
  },
5898
5907
  };
5899
5908
  const completed = await askInWorkspaceSession({
5909
+ onNotice: (notice) => this.#send(chatId, notice, { replyTo: messageId }),
5900
5910
  deferredDelivery: () => ({ coordinator: this.#deferred, chatId, replyToMessageId: messageId }),
5901
5911
  harness: this.#harness,
5902
5912
  state: this.#state,
@@ -5972,6 +5982,7 @@ export class FeishuHarnessBridge {
5972
5982
 
5973
5983
  this.#logger.warn?.('[dsh-feishu] native stream unavailable; using text fallback:', error.message);
5974
5984
  const { sessionId, answer, artifacts = [] } = await askInWorkspaceSession({
5985
+ onNotice: (notice) => this.#send(chatId, notice, { replyTo: messageId }),
5975
5986
  deferredDelivery: () => ({ coordinator: this.#deferred, chatId, replyToMessageId: messageId }),
5976
5987
  harness: this.#harness,
5977
5988
  state: this.#state,
@@ -6322,7 +6333,9 @@ export class FeishuHarnessBridge {
6322
6333
  Promise.resolve(completion).then(finish, finish);
6323
6334
  try {
6324
6335
  await validate();
6325
- await this.#handleInteraction(interaction, { ...context, validate, onClear: cleanup });
6336
+ await this.#handleInteraction(interaction, {
6337
+ ...context, validate, onClear: cleanup, lifecycle: 'session-sync',
6338
+ });
6326
6339
  if (finished) finish(); // A completion during delivery must not leave a pending behind.
6327
6340
  const available = !finished && this.#pendingInteractions.get(context.key)?.interactionId === interaction.interactionId;
6328
6341
  if (!available) cleanup();
@@ -6342,6 +6355,7 @@ export class FeishuHarnessBridge {
6342
6355
  receiveIdType,
6343
6356
  validate,
6344
6357
  onClear,
6358
+ lifecycle = 'turn',
6345
6359
  }) {
6346
6360
  if (await this.#approvals.handleRequested(interaction, this.#approvalContext({
6347
6361
  key, actor, chatId, requiresMention, replyToMessageId,
@@ -6419,6 +6433,7 @@ export class FeishuHarnessBridge {
6419
6433
  receiveIdType,
6420
6434
  validate,
6421
6435
  onClear,
6436
+ lifecycle,
6422
6437
  queue: null,
6423
6438
  claimedReplyMessageId: null,
6424
6439
  submitting: false,
@@ -6568,6 +6583,13 @@ export class FeishuHarnessBridge {
6568
6583
  if (!pending || pending.kind !== 'question') return;
6569
6584
  this.#rememberResolvedInteraction(key, pending);
6570
6585
  try {
6586
+ // A synced question is owned by its upstream provider, not this IM turn.
6587
+ // Withdraw the IM route so the provider also releases its delivery state;
6588
+ // DS Bot's answer endpoint does not accept a Harness cancellation answer.
6589
+ if (pending.lifecycle === 'session-sync' && pending.interaction.withdraw) {
6590
+ await pending.interaction.withdraw();
6591
+ return;
6592
+ }
6571
6593
  await pending.interaction.respond({
6572
6594
  ok: false,
6573
6595
  error: {
@@ -14,8 +14,8 @@
14
14
  * without button callbacks.
15
15
  */
16
16
 
17
- import { posix, win32 } from 'node:path';
18
17
  import { t } from '../shared/i18n.mjs';
18
+ 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;
@@ -97,50 +97,6 @@ function safeTitle(value) {
97
97
  return cleanTitle(value) || t('暂无标题');
98
98
  }
99
99
 
100
- const WORKSPACE_LABEL_LENGTH = 22;
101
-
102
- /** Display labels only: paths and their snapshot order remain the callback identity. */
103
- function workspaceLabels(paths, titles = {}) {
104
- const entries = paths.map((path) => {
105
- const api = /^[a-z]:[\\/]|^\\\\/iu.test(path) ? win32 : posix;
106
- const normalized = api.normalize(path);
107
- const name = cleanTitle(api.basename(normalized) || api.parse(normalized).root);
108
- const base = (typeof titles[path] === 'string' && cleanTitle(titles[path])) || name;
109
- return {
110
- api, base, label: base, parent: api.dirname(normalized),
111
- context: base === name ? '' : api.basename(normalized),
112
- };
113
- });
114
- const counts = () => {
115
- const result = new Map();
116
- for (const { label } of entries) result.set(label, (result.get(label) ?? 0) + 1);
117
- return result;
118
- };
119
- // Grow only ambiguous path suffixes; stop at the root even if display text collides.
120
- for (;;) {
121
- const repeated = counts();
122
- let changed = false;
123
- for (const entry of entries) {
124
- if (repeated.get(entry.label) < 2 || entry.parent === null) continue;
125
- const { api, parent } = entry;
126
- entry.context = api.join(api.basename(parent) || parent, entry.context);
127
- entry.label = `${entry.base} · ${cleanTitle(entry.context)}`;
128
- const next = api.dirname(parent);
129
- entry.parent = next === parent ? null : next;
130
- changed = true;
131
- }
132
- if (!changed) break;
133
- }
134
- for (const entry of entries) {
135
- const chars = Array.from(entry.label);
136
- if (chars.length > WORKSPACE_LABEL_LENGTH) {
137
- entry.label = `${chars.slice(0, 11).join('')}…${chars.slice(-10).join('')}`;
138
- }
139
- }
140
- const repeated = counts();
141
- return entries.map(({ label }) => ({ label, numbered: repeated.get(label) > 1 }));
142
- }
143
-
144
100
  function cardWith(headerText, elements) {
145
101
  return JSON.stringify({
146
102
  schema: '2.0',