@xmanrui/dsh-im 5.5.0 → 5.7.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 (59) hide show
  1. package/README.en.md +24 -8
  2. package/README.md +24 -8
  3. package/assets/sponsors/88api.jpg +0 -0
  4. package/lib/client.js +328 -243
  5. package/lib/index.js +317 -317
  6. package/package.json +4 -4
  7. package/plugin-src/client/channels/dingtalk/index.js +12 -9
  8. package/plugin-src/client/channels/feishu/group-settings.js +5 -5
  9. package/plugin-src/client/channels/feishu/index.js +33 -25
  10. package/plugin-src/client/channels/qq/index.js +5 -5
  11. package/plugin-src/client/channels/shared/token-api.js +12 -7
  12. package/plugin-src/client/channels/shared/token-channel.js +18 -11
  13. package/plugin-src/client/channels/wecom/index.js +5 -5
  14. package/plugin-src/client/channels/wecom-app/index.js +3 -3
  15. package/plugin-src/client/channels/weixin/index.js +2 -2
  16. package/plugin-src/client/channels/whatsapp/index.js +6 -6
  17. package/plugin-src/client/credential-binding.js +3 -2
  18. package/plugin-src/client/delivery-settings.js +12 -3
  19. package/plugin-src/client/ds-bot-settings.js +3 -3
  20. package/plugin-src/client/global-settings.js +5 -2
  21. package/plugin-src/client/i18n-ru.js +57 -34
  22. package/plugin-src/client/i18n.js +211 -124
  23. package/plugin-src/client/session-channel-logos.js +8 -0
  24. package/plugin-src/host/delivery-suggestions.mjs +2 -0
  25. package/plugin-src/host/update-service.mjs +44 -13
  26. package/scripts/verify-package.mjs +1 -1
  27. package/src/channels/dingtalk/dingtalk-bridge.mjs +1 -0
  28. package/src/channels/feishu/bridge.mjs +25 -3
  29. package/src/channels/feishu/feishu-cards.mjs +1 -45
  30. package/src/channels/feishu/feishu-runtime.mjs +13 -1
  31. package/src/channels/feishu/slash-command-panel.mjs +2 -5
  32. package/src/channels/qq/markdown-reply.mjs +5 -2
  33. package/src/channels/qq/qq-bridge.mjs +42 -2
  34. package/src/channels/shared/bot-workspace-store.mjs +1 -1
  35. package/src/channels/shared/command-catalog.mjs +8 -5
  36. package/src/channels/shared/delivery-failure-log.mjs +111 -0
  37. package/src/channels/shared/diagnostic-details.mjs +1 -0
  38. package/src/channels/shared/harness-client.mjs +12 -6
  39. package/src/channels/shared/i18n-en/shared-b.mjs +5 -0
  40. package/src/channels/shared/i18n-en/shared-c.mjs +3 -0
  41. package/src/channels/shared/i18n-en/telegram.mjs +6 -0
  42. package/src/channels/shared/i18n-ru/shared-b.mjs +5 -0
  43. package/src/channels/shared/i18n-ru/shared-c.mjs +3 -0
  44. package/src/channels/shared/i18n-ru/telegram.mjs +5 -0
  45. package/src/channels/shared/message-failure.mjs +5 -2
  46. package/src/channels/shared/session-error.mjs +8 -0
  47. package/src/channels/shared/text-harness-bridge.mjs +201 -3
  48. package/src/channels/shared/workspace-command.mjs +41 -16
  49. package/src/channels/shared/workspace-labels.mjs +65 -0
  50. package/src/channels/shared/workspace-session.mjs +24 -4
  51. package/src/channels/slack/slack-api.mjs +21 -5
  52. package/src/channels/slack/slack-runtime.mjs +69 -20
  53. package/src/channels/telegram/telegram-api.mjs +31 -2
  54. package/src/channels/telegram/telegram-bridge.mjs +58 -0
  55. package/src/channels/telegram/telegram-runtime.mjs +85 -3
  56. package/src/channels/wecom/wecom-bridge.mjs +1 -0
  57. package/src/channels/wecom/wecom-controller.mjs +89 -1
  58. package/src/channels/wecom-app/wecom-app-bridge.mjs +1 -0
  59. 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.',
@@ -1218,6 +1254,7 @@ const EN = Object.freeze({
1218
1254
  'DeepSeek Harness 会读取该邮箱的新邮件作为指令,并在同一邮件线程内回复处理结果。': 'DeepSeek Harness reads new mail in this mailbox as instructions and replies with the result inside the same mail thread.',
1219
1255
  '邮箱服务商': 'Mail provider',
1220
1256
  '邮箱地址': 'Email address',
1257
+ '收件人': 'Recipient',
1221
1258
  '应用密码 / 授权码': 'App password / authorization code',
1222
1259
  'IMAP/SMTP 授权码': 'IMAP/SMTP authorization code',
1223
1260
  '不是邮箱登录密码;请在邮箱设置中单独生成。': 'This is not your login password; generate it separately in your mailbox settings.',
@@ -1340,121 +1377,171 @@ export function installImRussianLocale(locale) {
1340
1377
  };
1341
1378
  }
1342
1379
 
1343
- function channelName(value) {
1380
+ /**
1381
+ * Localise a channel name the way the settings UI writes it: "微信" becomes
1382
+ * "WeChat" in English and Russian alike, while a name that is already Latin
1383
+ * ("Telegram") is handed back unchanged.
1384
+ */
1385
+ export function channelName(value) {
1344
1386
  return localizeText(value);
1345
1387
  }
1346
1388
 
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]) : '',
1389
+ // A broken WeChat configuration: the prefix, a `{file}` template sentence and an
1390
+ // optional counter sentence, each resolved in the active language.
1391
+ function configHint(match) {
1392
+ return [
1393
+ localizeText(match[1].trim()),
1394
+ translate('请检查微信渠道数据目录中的 {file},修复后重启 DSH;“重新读取”不会重新加载配置。').replace('{file}', match[2]),
1395
+ match[3] ? localizeText(match[3]) : '',
1355
1396
  ].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]}`;
1397
+ }
1398
+
1399
+ // Sentences composed outside the settings UI — a bot status or an RPC error that the
1400
+ // host, or an IM platform, has already assembled — arrive as one string with no key
1401
+ // to look up, so they are recognised by the Chinese shape they are built from. The
1402
+ // client's own sentences are not here: they are template keys in the dictionaries
1403
+ // (see COMPOSED and localizeTemplate), which keeps this table to the text that really
1404
+ // has no key. Every rule carries a rendering per locale; `en` and `ru` are both
1405
+ // mandatory, because a rule with an English column only is exactly what left a
1406
+ // Russian reader looking at Chinese. Chinese needs no column of its own.
1407
+ const DYNAMIC_RULES = Object.freeze([
1408
+ {
1409
+ pattern: /^微信配置格式错误:(config\.json|workspaces\.json)。请查看诊断详情,修复后重启 DSH。$/,
1410
+ // Both dictionaries already hold this sentence as a `{file}` template, so the
1411
+ // rendering goes through the lookup rather than restating the text here.
1412
+ en: (match) => EN['微信配置格式错误:{file}。请查看诊断详情,修复后重启 DSH。'].replace('{file}', match[1]),
1413
+ ru: (match) => translate('微信配置格式错误:{file}。请查看诊断详情,修复后重启 DSH。').replace('{file}', match[1]),
1414
+ },
1415
+ {
1416
+ pattern: /^(.*?)请检查微信渠道数据目录中的 (config\.json|workspaces\.json),修复后重启 DSH;“重新读取”不会重新加载配置。\s*(字段位置中的序号从 0 开始,按文件中的条目顺序计数,不包含真实账号标识。)?$/,
1417
+ en: (match) => configHint(match),
1418
+ ru: (match) => configHint(match),
1419
+ },
1420
+ {
1421
+ pattern: /^增强提示词不得超过 (\d+) 个字符。$/,
1422
+ en: (match) => `Guidance must not exceed ${match[1]} characters.`,
1423
+ ru: (match) => `Подсказка для контекста не должна превышать ${match[1]} символов.`,
1424
+ },
1425
+ {
1426
+ pattern: /^一次最多只能处理 (\d+) 张图片。$/,
1427
+ en: (match) => `A message can contain at most ${match[1]} images.`,
1428
+ ru: (match) => `В одном сообщении может быть не больше ${match[1]} изображений.`,
1429
+ },
1430
+ {
1431
+ pattern: /^图片下载失败(HTTP (.+)),请重新发送后再试。$/,
1432
+ en: (match) => `The image download failed (HTTP ${match[1]}). Send it again.`,
1433
+ ru: (match) => `Не удалось скачать изображение (HTTP ${match[1]}). Отправьте его заново.`,
1434
+ },
1435
+ ]);
1436
+
1437
+ // Chinese fragments that survive inside messages no rule above recognises. Each row
1438
+ // carries the source fragment and its rendering per locale, so the last-resort path
1439
+ // is a table too rather than an English-only swap list.
1440
+ const DYNAMIC_PHRASES = Object.freeze([
1441
+ ['企业微信', 'WeCom', 'WeCom'],
1442
+ ['DeepSeek Harness', 'DeepSeek Harness', 'DeepSeek Harness'],
1443
+ ['WhatsApp', 'WhatsApp', 'WhatsApp'],
1444
+ ['iMessage', 'iMessage', 'iMessage'],
1445
+ ['macOS Messages', 'macOS Messages', 'macOS Messages'],
1446
+ ['Telegram', 'Telegram', 'Telegram'],
1447
+ ['Discord', 'Discord', 'Discord'],
1448
+ ['Slack', 'Slack', 'Slack'],
1449
+ ['飞书', 'Feishu', 'Feishu'],
1450
+ ['钉钉', 'DingTalk', 'DingTalk'],
1451
+ ['微信', 'WeChat', 'WeChat'],
1452
+ ['机器人', 'bot', 'бот'],
1453
+ ['账号', 'account', 'аккаунт'],
1454
+ ['应用', 'app', 'приложение'],
1455
+ ['凭据', 'credentials', 'учётные данные'],
1456
+ ['服务返回了无法识别的响应', 'service returned an unrecognized response', 'сервис вернул нераспознанный ответ'],
1457
+ ['服务没有返回有效的机器人列表', 'service did not return a valid bot list', 'сервис не вернул список ботов'],
1458
+ ['操作失败,请稍后重试', 'operation failed; try again later', 'операция не удалась, попробуйте позже'],
1459
+ ['操作失败', 'operation failed', 'операция не удалась'],
1460
+ ['连接尚未就绪', 'connection is not ready', 'подключение ещё не готово'],
1461
+ ['没有接入完成', 'was not connected', 'подключить не удалось'],
1462
+ ['没有绑定完成', 'was not connected', 'подключить не удалось'],
1463
+ ['设置页缺少 RPC 连接', 'settings are missing an RPC connection', 'в настройках нет подключения RPC'],
1464
+ ['设置', 'settings', 'настройки'],
1465
+ ['连接检查完成', 'connection check completed', 'проверка подключения завершена'],
1466
+ ['仍未连接,插件会继续自动重试', 'is still offline; the plugin will keep retrying', 'всё ещё не подключён, плагин продолжит попытки'],
1467
+ ['已重新连接', 'reconnected', 'переподключено'],
1468
+ ['移除失败,请重试', 'could not be removed; try again', 'удалить не удалось, попробуйте снова'],
1469
+ ['已连接,可以开始聊天', 'is connected and ready to chat', 'подключён, можно начинать переписку'],
1470
+ ['已连接,可以开始发送消息', 'is connected and ready for messages', 'подключён и готов отправлять сообщения'],
1471
+ ['服务请求失败', 'service request failed', 'запрос к сервису не удался'],
1472
+ // Failure reasons the host embeds in a message: they arrive as a captured phrase
1473
+ // inside an already localised sentence, so they need a translation of their own.
1474
+ ['网络中断', 'network down', 'сеть недоступна'],
1475
+ ['请求超时', 'request timed out', 'истекло время ожидания'],
1476
+ ['超时', 'timed out', 'истекло время ожидания'],
1477
+ ['服务不可用', 'service unavailable', 'сервис недоступен'],
1478
+ ['连接被拒绝', 'connection refused', 'соединение отклонено'],
1479
+ ['未授权', 'unauthorized', 'нет авторизации'],
1480
+ ['响应格式错误', 'malformed response', 'неверный формат ответа'],
1481
+ ['连接遇到问题', 'connection encountered a problem', 'проблема с подключением'],
1482
+ ['正在读取', 'Loading ', 'Загружаем '],
1483
+ ['连接状态', 'connection status', 'состояние подключения'],
1484
+ ['二维码', 'QR code', 'QR-код'],
1485
+ ]);
1486
+
1487
+ // The rules and their renderings, exposed so a test can hold every pattern to the
1488
+ // same per-locale contract instead of trusting the order of the chain below.
1489
+ export const IM_DYNAMIC_RULES = DYNAMIC_RULES;
1490
+ export const IM_DYNAMIC_PHRASES = DYNAMIC_PHRASES;
1428
1491
 
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
- ];
1492
+ /**
1493
+ * Localise a sentence the UI composed at runtime, e.g. `已接入的 Telegram 机器人`.
1494
+ *
1495
+ * @param text - the composed sentence, in the language the patterns are written in.
1496
+ * @param locale - `'en'`, `'ru'` or `'zh'`; anything else is served English, and
1497
+ * Chinese is the identity language, so its text travels untouched.
1498
+ * @returns the sentence in the requested locale, or `text` when nothing matches.
1499
+ */
1500
+ export function translateDynamic(text, locale = imLocale()) {
1501
+ if (locale === 'zh') return text;
1502
+ const column = locale === 'ru' ? 'ru' : 'en';
1503
+ for (const rule of DYNAMIC_RULES) {
1504
+ const match = rule.pattern.exec(text);
1505
+ if (!match) continue;
1506
+ return (rule[column] ?? rule.en)(match);
1507
+ }
1508
+ const at = column === 'ru' ? 2 : 1;
1449
1509
  let output = text;
1450
- for (const [source, target] of phrases) output = output.replaceAll(source, target);
1510
+ for (const row of DYNAMIC_PHRASES) output = output.replaceAll(row[0], row[at]);
1451
1511
  return output;
1452
1512
  }
1453
1513
 
1514
+ const TEMPLATE_PLACEHOLDER = /\{(\w+)\}/gu;
1515
+
1516
+ /**
1517
+ * Localise a sentence the settings UI composes itself, from a template key both
1518
+ * dictionaries carry: `已接入的 {channel} 机器人`. The key is looked up like any other
1519
+ * string — so a Russian reader gets the Russian sentence — and the values are filled
1520
+ * in afterwards, which keeps the word order of the translation instead of the
1521
+ * Chinese one the sentence was assembled from. A key neither dictionary knows comes
1522
+ * back as the key with its placeholders still visible, the same identity the rest of
1523
+ * the module falls back to.
1524
+ *
1525
+ * @param key - the Chinese template, e.g. `尚未接入 {channel} 机器人`.
1526
+ * @param values - one value per placeholder; a missing one keeps its braces so the
1527
+ * gap is visible instead of silently empty.
1528
+ */
1529
+ export function localizeTemplate(key, values) {
1530
+ if (typeof key !== 'string') return key;
1531
+ const template = translate(key);
1532
+ if (values == null) return template;
1533
+ return template.replace(TEMPLATE_PLACEHOLDER, (placeholder, name) => (
1534
+ Object.hasOwn(values, name) ? String(values[name]) : placeholder
1535
+ ));
1536
+ }
1537
+
1454
1538
  export function localizeText(value) {
1455
1539
  if (typeof value !== 'string') return value;
1456
1540
  const exact = translate(value);
1457
- if (exact !== value || !isEnglish()) return exact;
1541
+ if (exact !== value) return exact;
1542
+ // A whole-string lookup missing means the UI composed the sentence at runtime.
1543
+ // Chinese is the identity language, so `translateDynamic` hands the text back in
1544
+ // its own language there and renders it in the active locale everywhere else.
1458
1545
  return translateDynamic(value);
1459
1546
  }
1460
1547
 
@@ -108,6 +108,14 @@ ${MARKED}[${TITLE_ATTR}]::after {
108
108
  text-overflow: ellipsis;
109
109
  pointer-events: none;
110
110
  }
111
+ /* The Host scrolls the original span and publishes these marquee fade hooks.
112
+ Let the replacement travel as complete text, not a pre-clipped viewport. */
113
+ ${MARKED}[${TITLE_ATTR}]:is([data-scrolled], [data-clipped])::after {
114
+ inset-inline-end: auto;
115
+ width: max-content;
116
+ overflow: visible;
117
+ text-overflow: clip;
118
+ }
111
119
  ${Object.entries(uris).map(([channel, uri]) => `[${CHANNEL_ATTR}="${channel}"] { --dsh-im-session-logo: url("${uri}"); }`).join('\n')}
112
120
  `;
113
121
  document.head.appendChild(style);
@@ -1,3 +1,5 @@
1
+ // Email conversation keys contain Message-IDs or bound Session IDs, not
2
+ // recipient addresses. Keep email targets explicit until a mapping is stored.
1
3
  const CHANNELS = new Set([
2
4
  'weixin',
3
5
  'feishu',
@@ -1,6 +1,7 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { mkdir, open, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';
3
- import { isAbsolute, join } from 'node:path';
3
+ import { isAbsolute, join, resolve } from 'node:path';
4
+ import { setTimeout as delay } from 'node:timers/promises';
4
5
  import semver from 'semver';
5
6
 
6
7
  import manifest from '../../package.json' with { type: 'json' };
@@ -12,6 +13,8 @@ const JOB_STATES = new Set([...ACTIVE_STATES, 'restart-required', 'completed', '
12
13
  const MAX_METADATA_BYTES = 256 * 1024;
13
14
  const SNAPSHOT_FILES = ['package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml'];
14
15
  const NO_LOCK = Symbol('no update lock');
16
+ // Shared across Host instances; keep network and installer work outside these transactions.
17
+ const stateIoQueue = {};
15
18
 
16
19
  export function updateError(code) {
17
20
  return Object.assign(new Error(code), { code });
@@ -76,7 +79,17 @@ function pathsFor(environment) {
76
79
  };
77
80
  }
78
81
 
79
- async function readJson(path, missing = null) {
82
+ function withStateIo(path, operation) {
83
+ const absolute = resolve(path);
84
+ const key = process.platform === 'win32' ? absolute.toLowerCase() : absolute;
85
+ return withSessionBindingLock(stateIoQueue, key, operation);
86
+ }
87
+
88
+ function readJson(path, missing = null) {
89
+ return withStateIo(path, () => readJsonUnlocked(path, missing));
90
+ }
91
+
92
+ async function readJsonUnlocked(path, missing = null) {
80
93
  try {
81
94
  if ((await stat(path)).size > 10 * 1024 * 1024) throw updateError('state-unavailable');
82
95
  return JSON.parse(await readFile(path, 'utf8'));
@@ -86,11 +99,25 @@ async function readJson(path, missing = null) {
86
99
  }
87
100
  }
88
101
 
89
- async function writeJson(path, value) {
102
+ function writeJson(path, value) {
103
+ return withStateIo(path, () => writeJsonUnlocked(path, value));
104
+ }
105
+
106
+ async function writeJsonUnlocked(path, value) {
90
107
  const temporary = `${path}.${randomUUID()}.tmp`;
91
108
  try {
92
109
  await writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
93
- await rename(temporary, path);
110
+ for (let retry = 0; ; retry++) {
111
+ try {
112
+ await rename(temporary, path);
113
+ break;
114
+ } catch (error) {
115
+ // Windows readers can temporarily deny replacement. Keep the old journal
116
+ // and retry the same atomic rename; never remove the destination first.
117
+ if (process.platform !== 'win32' || error.code !== 'EPERM' || retry >= 5) throw error;
118
+ await delay(10 * 2 ** retry);
119
+ }
120
+ }
94
121
  } catch {
95
122
  throw updateError('state-unavailable');
96
123
  } finally {
@@ -255,8 +282,10 @@ export function createUpdateService({
255
282
  }
256
283
 
257
284
  async function releaseLock(paths, id) {
258
- const lock = await readJson(paths.lock);
259
- if (lock?.id === id) await unlink(paths.lock);
285
+ await withStateIo(paths.lock, async () => {
286
+ const lock = await readJsonUnlocked(paths.lock);
287
+ if (lock?.id === id) await unlink(paths.lock);
288
+ });
260
289
  }
261
290
 
262
291
  async function backupProfile(environment, paths, job) {
@@ -348,13 +377,15 @@ export function createUpdateService({
348
377
  let locked = false;
349
378
  try {
350
379
  await mkdir(paths.directory, { recursive: true, mode: 0o700 });
351
- const lock = await open(paths.lock, 'wx', 0o600);
352
- locked = true;
353
- try {
354
- await lock.writeFile(JSON.stringify({ id: job.id, pid: process.pid, startedAt: now() }));
355
- } finally {
356
- await lock.close();
357
- }
380
+ await withStateIo(paths.lock, async () => {
381
+ const lock = await open(paths.lock, 'wx', 0o600);
382
+ locked = true;
383
+ try {
384
+ await lock.writeFile(JSON.stringify({ id: job.id, pid: process.pid, startedAt: now() }));
385
+ } finally {
386
+ await lock.close();
387
+ }
388
+ });
358
389
  const currentRelease = await fetchNpmRelease(fetchImpl, checkTimeoutMs);
359
390
  if (JSON.stringify(currentRelease) !== JSON.stringify(confirmation.release)) throw updateError('check-expired');
360
391
  environment = await runtime.inspect({ preflight: true });
@@ -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,