@xmanrui/dsh-im 5.3.0 → 5.5.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 (112) hide show
  1. package/PROACTIVE_DELIVERY.en.md +15 -0
  2. package/PROACTIVE_DELIVERY.md +15 -0
  3. package/README.en.md +44 -3
  4. package/README.md +44 -3
  5. package/THIRD_PARTY_NOTICES.md +209 -0
  6. package/docs/client-integration.md +2 -2
  7. package/lib/client.js +3737 -433
  8. package/lib/index.js +415 -344
  9. package/package.json +1 -1
  10. package/plugin-src/client/channel-card-meta.js +6 -2
  11. package/plugin-src/client/channels/shared/token-api.js +13 -0
  12. package/plugin-src/client/channels/telegram/group-triggers-settings.js +393 -0
  13. package/plugin-src/client/channels/telegram/styles.js +4 -0
  14. package/plugin-src/client/channels/telegram/thinking-traces.js +138 -5
  15. package/plugin-src/client/delivery-settings.js +23 -3
  16. package/plugin-src/client/ds-bot-avatar-data.js +537 -0
  17. package/plugin-src/client/ds-bot-avatar.js +55 -0
  18. package/plugin-src/client/ds-bot-session-avatars.js +77 -0
  19. package/plugin-src/client/ds-bot-settings.js +194 -0
  20. package/plugin-src/client/i18n-ru.js +1615 -0
  21. package/plugin-src/client/i18n.js +130 -1
  22. package/plugin-src/client/index.js +20 -2
  23. package/plugin-src/client/plugin-page.js +3 -8
  24. package/plugin-src/client/styles.js +25 -5
  25. package/plugin-src/host/channels/dingtalk/production.mjs +2 -1
  26. package/plugin-src/host/channels/feishu/production.mjs +13 -5
  27. package/plugin-src/host/channels/qq/production.mjs +2 -1
  28. package/plugin-src/host/channels/shared/group-triggers-rpc.mjs +110 -0
  29. package/plugin-src/host/channels/shared/production.mjs +12 -1
  30. package/plugin-src/host/channels/shared/rpc.mjs +21 -0
  31. package/plugin-src/host/channels/shared/send-limit-rpc.mjs +13 -0
  32. package/plugin-src/host/channels/shared/thinking-cadence-rpc.mjs +16 -0
  33. package/plugin-src/host/channels/slack/production.mjs +2 -1
  34. package/plugin-src/host/channels/telegram/index.mjs +1 -0
  35. package/plugin-src/host/channels/telegram/production.mjs +9 -0
  36. package/plugin-src/host/channels/telegram/rpc.mjs +17 -2
  37. package/plugin-src/host/channels/wecom/production.mjs +4 -1
  38. package/plugin-src/host/channels/wecom-app/production.mjs +2 -1
  39. package/plugin-src/host/channels/weixin/production.mjs +2 -1
  40. package/plugin-src/host/channels/whatsapp/production.mjs +2 -1
  41. package/plugin-src/host/delivery-adapter.mjs +129 -41
  42. package/plugin-src/host/delivery-rpc.mjs +33 -1
  43. package/plugin-src/host/delivery-service.mjs +112 -1
  44. package/plugin-src/host/delivery-suggestions.mjs +11 -0
  45. package/plugin-src/host/ds-bot-client.mjs +87 -0
  46. package/plugin-src/host/ds-bot-question-sync.mjs +78 -0
  47. package/plugin-src/host/index.mjs +8 -1
  48. package/plugin-src/host/modern-harness-api.mjs +53 -8
  49. package/plugin-src/host/session-sync-coordinator.mjs +5 -5
  50. package/scripts/verify-package.mjs +17 -5
  51. package/src/channels/feishu/bridge.mjs +83 -5
  52. package/src/channels/feishu/feishu-cards.mjs +11 -7
  53. package/src/channels/feishu/feishu-runtime.mjs +10 -0
  54. package/src/channels/feishu/multi-bot-controller.mjs +12 -0
  55. package/src/channels/shared/AGENTS.md +19 -0
  56. package/src/channels/shared/bot-workspace-store.mjs +136 -7
  57. package/src/channels/shared/clear-command.mjs +2 -1
  58. package/src/channels/shared/compact-command.mjs +2 -1
  59. package/src/channels/shared/conversation-queue.mjs +49 -0
  60. package/src/channels/shared/deferred-delivery-coordinator.mjs +2 -1
  61. package/src/channels/shared/group-history-store.mjs +26 -0
  62. package/src/channels/shared/harness-client.mjs +5 -4
  63. package/src/channels/shared/history-command.mjs +2 -1
  64. package/src/channels/shared/i18n-en/feishu.mjs +1 -0
  65. package/src/channels/shared/i18n-en/shared-a.mjs +2 -2
  66. package/src/channels/shared/i18n-en/shared-b.mjs +2 -2
  67. package/src/channels/shared/i18n-en/shared-c.mjs +3 -2
  68. package/src/channels/shared/i18n-en/wecom.mjs +4 -0
  69. package/src/channels/shared/i18n-ru/diagnostics.mjs +104 -0
  70. package/src/channels/shared/i18n-ru/dingtalk.mjs +96 -0
  71. package/src/channels/shared/i18n-ru/discord.mjs +10 -0
  72. package/src/channels/shared/i18n-ru/email.mjs +23 -0
  73. package/src/channels/shared/i18n-ru/feishu.mjs +374 -0
  74. package/src/channels/shared/i18n-ru/image-input.mjs +25 -0
  75. package/src/channels/shared/i18n-ru/matrix.mjs +73 -0
  76. package/src/channels/shared/i18n-ru/office.mjs +27 -0
  77. package/src/channels/shared/i18n-ru/permission.mjs +45 -0
  78. package/src/channels/shared/i18n-ru/qq.mjs +88 -0
  79. package/src/channels/shared/i18n-ru/shared-a.mjs +236 -0
  80. package/src/channels/shared/i18n-ru/shared-b.mjs +257 -0
  81. package/src/channels/shared/i18n-ru/shared-c.mjs +173 -0
  82. package/src/channels/shared/i18n-ru/slack.mjs +22 -0
  83. package/src/channels/shared/i18n-ru/telegram.mjs +25 -0
  84. package/src/channels/shared/i18n-ru/wecom-app.mjs +43 -0
  85. package/src/channels/shared/i18n-ru/wecom.mjs +79 -0
  86. package/src/channels/shared/i18n-ru/weixin.mjs +275 -0
  87. package/src/channels/shared/i18n-ru/whatsapp.mjs +18 -0
  88. package/src/channels/shared/i18n-ru.mjs +48 -0
  89. package/src/channels/shared/i18n.mjs +47 -12
  90. package/src/channels/shared/inbound-access.mjs +1 -1
  91. package/src/channels/shared/interface-language.mjs +3 -3
  92. package/src/channels/shared/message-failure.mjs +3 -2
  93. package/src/channels/shared/model-command.mjs +2 -1
  94. package/src/channels/shared/permission-command.mjs +2 -1
  95. package/src/channels/shared/send-limit.mjs +38 -0
  96. package/src/channels/shared/session-binding-lock.mjs +2 -0
  97. package/src/channels/shared/session-error.mjs +3 -0
  98. package/src/channels/shared/status-reaction.mjs +2 -0
  99. package/src/channels/shared/text-harness-bridge.mjs +4 -0
  100. package/src/channels/shared/thinking-cadence.mjs +36 -0
  101. package/src/channels/shared/workspace-command.mjs +2 -1
  102. package/src/channels/shared/workspace-session.mjs +5 -1
  103. package/src/channels/telegram/config-store.mjs +38 -1
  104. package/src/channels/telegram/group-triggers.mjs +229 -0
  105. package/src/channels/telegram/telegram-api.mjs +223 -32
  106. package/src/channels/telegram/telegram-bridge.mjs +4 -1
  107. package/src/channels/telegram/telegram-controller.mjs +139 -1
  108. package/src/channels/telegram/telegram-runtime.mjs +522 -178
  109. package/src/channels/telegram/voice.mjs +250 -0
  110. package/src/channels/wecom/stream-supervisor.mjs +184 -0
  111. package/src/channels/wecom/wecom-bridge.mjs +25 -11
  112. package/src/channels/wecom/wecom-runtime.mjs +12 -1
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+ import { DsBotAvatar } from './ds-bot-avatar.js';
3
+
4
+ export const DS_BOT_SESSIONS_ENDPOINT = 'ds-bot.sessions.list';
5
+
6
+ /** Use the Host's leading-icon slot, before the existing channel/title display.
7
+ * One shared read covers every row; no title matching or per-row requests. */
8
+ export function installDsBotSessionAvatars(ctx, {
9
+ rpcCall, setTimeoutFn = globalThis.setTimeout, clearTimeoutFn = globalThis.clearTimeout,
10
+ document = globalThis.document, window = globalThis.window,
11
+ }) {
12
+ let refresh = () => {};
13
+ const stop = ctx.slots.inject('sidebar.session.row.leading', () => {
14
+ const abort = new AbortController();
15
+ const listeners = new Set();
16
+ let bots = new Map();
17
+ let signature = '';
18
+ let timer;
19
+ let running = false;
20
+ let revision = 0;
21
+ const publish = (entries) => {
22
+ const next = JSON.stringify(entries);
23
+ if (next === signature) return;
24
+ signature = next;
25
+ bots = new Map(entries.map(({ sessionId, bot }) => [sessionId, bot]));
26
+ for (const listener of listeners) listener();
27
+ };
28
+ const subscribe = (listener) => {
29
+ listeners.add(listener);
30
+ return () => listeners.delete(listener);
31
+ };
32
+ function SessionAvatar({ sessionId }) {
33
+ const bot = React.useSyncExternalStore(subscribe, () => bots.get(sessionId) ?? null);
34
+ return bot ? React.createElement(DsBotAvatar, { bot, size: 16 }) : null;
35
+ }
36
+ const schedule = () => {
37
+ clearTimeoutFn(timer);
38
+ if (!abort.signal.aborted) timer = setTimeoutFn(load, 0);
39
+ };
40
+ const load = async () => {
41
+ if (abort.signal.aborted || running) return;
42
+ running = true;
43
+ const current = revision;
44
+ try {
45
+ const result = await rpcCall(DS_BOT_SESSIONS_ENDPOINT, {}, abort.signal);
46
+ if (result?.ok !== true || !Array.isArray(result.value)) throw new Error('Unavailable');
47
+ if (!abort.signal.aborted && current === revision) publish(result.value);
48
+ } catch {
49
+ if (!abort.signal.aborted && current === revision) publish([]);
50
+ } finally {
51
+ running = false;
52
+ if (current !== revision) schedule();
53
+ }
54
+ };
55
+ refresh = () => {
56
+ revision++;
57
+ if (!running) schedule();
58
+ };
59
+ const wake = () => { if (!document?.hidden) refresh(); };
60
+ window?.addEventListener('focus', wake);
61
+ document?.addEventListener('visibilitychange', wake);
62
+ const unregister = ctx.slots.register({
63
+ name: 'sidebar.session.row.leading', id: 'dsh-im-ds-bot-avatar', order: 0,
64
+ }, SessionAvatar);
65
+ void load();
66
+ return () => {
67
+ abort.abort();
68
+ clearTimeoutFn(timer);
69
+ window?.removeEventListener('focus', wake);
70
+ document?.removeEventListener('visibilitychange', wake);
71
+ refresh = () => {};
72
+ unregister();
73
+ listeners.clear();
74
+ };
75
+ });
76
+ return { refresh: () => refresh(), dispose: stop };
77
+ }
@@ -0,0 +1,194 @@
1
+ import * as React from 'react';
2
+ import { h } from './i18n.js';
3
+ import { DsBotAvatar } from './ds-bot-avatar.js';
4
+
5
+ export const DS_BOT_MESSAGES = Object.freeze({
6
+ missing: '未安装 DS Bot,请先在 DSH 插件管理中安装 ds-bot,然后刷新。',
7
+ disabled: 'DS Bot 尚未启用,请在 DSH 插件管理中启用后刷新。',
8
+ unavailable: '暂时无法读取 DS Bot,请检查插件是否正常运行后重试。',
9
+ readonly: 'DS Bot 当前由其他 Host 管理,请在运行它的 Host 中绑定。',
10
+ remote: '绑定bot仅支持当前 Host 的会话,请先检查机器人的 Harness 连接设置。',
11
+ });
12
+
13
+ export function dsBotErrorMessage(error) {
14
+ return {
15
+ 'ds-bot-unavailable': DS_BOT_MESSAGES.unavailable,
16
+ 'ds-bot-not-found': '所选 DS Bot 已不存在,请刷新后重新选择。',
17
+ 'ds-bot-private-required': '仅支持已经建立会话的私聊,请先与机器人私聊后刷新。',
18
+ 'ds-bot-binding-conflict': '所选 DS Bot 或私聊对象已绑定,请刷新后重新选择。',
19
+ }[error?.code] ?? '绑定设置保存失败,请刷新后重试。';
20
+ }
21
+
22
+ export function DsBotPicker({ bots, value, onChange, disabled }) {
23
+ const [open, setOpen] = React.useState(false);
24
+ const [active, setActive] = React.useState(0);
25
+ const root = React.useRef(null);
26
+ const trigger = React.useRef(null);
27
+ const listId = React.useId();
28
+ const selected = bots.find((bot) => bot.id === value);
29
+ const isOpen = open && !disabled && bots.length > 0;
30
+ React.useEffect(() => {
31
+ const dismiss = (event) => { if (!root.current?.contains(event.target)) setOpen(false); };
32
+ if (open) globalThis.document?.addEventListener('pointerdown', dismiss);
33
+ return () => globalThis.document?.removeEventListener('pointerdown', dismiss);
34
+ }, [open]);
35
+ const choose = (bot) => { onChange(bot.id); setOpen(false); trigger.current?.focus(); };
36
+ const optionId = (index) => `${listId}-${index}`;
37
+ return h('div', { className: 'dim-dsBotPicker', ref: root },
38
+ h('button', {
39
+ type: 'button', role: 'combobox', ref: trigger, className: 'dim-dsBotPickerTrigger',
40
+ disabled: disabled || !bots.length, 'aria-label': 'DS Bot', 'aria-expanded': isOpen, 'aria-controls': listId,
41
+ 'aria-haspopup': 'listbox', 'aria-activedescendant': isOpen ? optionId(active) : undefined,
42
+ onClick: () => { setActive(Math.max(0, bots.findIndex((bot) => bot.id === value))); setOpen(!open); },
43
+ onKeyDown: (event) => {
44
+ if (disabled || !bots.length) return;
45
+ if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {
46
+ event.preventDefault();
47
+ const index = event.key === 'Home' ? 0 : event.key === 'End' ? bots.length - 1
48
+ : open ? (active + (event.key === 'ArrowDown' ? 1 : -1) + bots.length) % bots.length
49
+ : Math.max(0, bots.findIndex((bot) => bot.id === value));
50
+ setActive(index); setOpen(true);
51
+ } else if (open && ['Enter', ' '].includes(event.key)) {
52
+ event.preventDefault(); if (bots[active]) choose(bots[active]);
53
+ } else if (event.key === 'Escape' || event.key === 'Tab') setOpen(false);
54
+ },
55
+ },
56
+ selected ? h(DsBotAvatar, { bot: selected }) : null,
57
+ selected ? React.createElement('span', { className: 'dim-dsBotPickerName' }, selected.name)
58
+ : h('span', { className: 'dim-dsBotPickerName' }, bots.length ? '选择 DS Bot' : '暂无可选 DS Bot'),
59
+ h('svg', { width: 14, height: 14, viewBox: '0 0 16 16', 'aria-hidden': true },
60
+ h('path', { d: 'm4 6 4 4 4-4', fill: 'none', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' }))),
61
+ isOpen ? h('div', { id: listId, role: 'listbox', 'aria-label': 'DS Bot', className: 'dim-dsBotOptions' },
62
+ bots.map((bot, index) => h('button', {
63
+ key: bot.id, id: optionId(index), type: 'button', role: 'option', tabIndex: -1,
64
+ 'aria-selected': value === bot.id, 'data-active': active === index,
65
+ onMouseDown: (event) => event.preventDefault(), onMouseEnter: () => setActive(index), onClick: () => choose(bot),
66
+ }, h(DsBotAvatar, { bot }),
67
+ React.createElement('span', { className: 'dim-dsBotPickerName' }, bot.name),
68
+ value === bot.id ? h('span', { 'aria-hidden': true }, '✓') : null))) : null);
69
+ }
70
+
71
+ function conversationLabel(conversation) {
72
+ if (conversation.name) return conversation.name;
73
+ const value = conversation.address;
74
+ return value.length > 24 ? `${value.slice(0, 10)}…${value.slice(-8)}` : value;
75
+ }
76
+
77
+ export function DsBotSettingsPage({ botId, rpcCall }) {
78
+ const [status, setStatus] = React.useState(null);
79
+ const [dsBotId, setDsBotId] = React.useState('');
80
+ const [conversationKey, setConversationKey] = React.useState('');
81
+ const [loading, setLoading] = React.useState(true);
82
+ const [busy, setBusy] = React.useState(false);
83
+ const [feedback, setFeedback] = React.useState(null);
84
+ const [feedbackTone, setFeedbackTone] = React.useState('success');
85
+ const requests = React.useRef({ revision: 0, busy: false, controller: null });
86
+ const refresh = React.useCallback(async (signal = requests.current.controller?.signal) => {
87
+ const state = requests.current;
88
+ if (signal?.aborted) return;
89
+ const revision = ++state.revision;
90
+ const current = () => !signal?.aborted && revision === state.revision;
91
+ setLoading(true);
92
+ try {
93
+ const value = await rpcCall('ds-bot.status', { botId }, signal);
94
+ if (current()) setStatus(value);
95
+ } catch {
96
+ if (current()) setStatus((previous) => ({ ...previous, state: 'unavailable' }));
97
+ } finally {
98
+ if (current()) setLoading(false);
99
+ }
100
+ }, [botId, rpcCall]);
101
+ React.useEffect(() => {
102
+ const controller = new AbortController();
103
+ requests.current.controller = controller;
104
+ void refresh(controller.signal);
105
+ return () => {
106
+ controller.abort();
107
+ requests.current.revision++;
108
+ };
109
+ }, [refresh]);
110
+ const conversations = status?.conversations ?? [];
111
+ const bots = status?.bots ?? [];
112
+ const bindings = conversations.filter((conversation) => conversation.dsBotId);
113
+ const usedBotIds = new Set(bindings.map((binding) => binding.dsBotId));
114
+ const availableBots = bots.filter((bot) => !usedBotIds.has(bot.id));
115
+ const availableConversations = conversations.filter((conversation) => !conversation.dsBotId);
116
+ const canSave = !busy && !loading && status?.state === 'ready'
117
+ && availableBots.some((bot) => bot.id === dsBotId)
118
+ && availableConversations.some((conversation) => conversation.conversationKey === conversationKey);
119
+ React.useEffect(() => {
120
+ setDsBotId((value) => availableBots.some((bot) => bot.id === value) ? value : '');
121
+ setConversationKey((value) => availableConversations.some((conversation) => conversation.conversationKey === value) ? value : '');
122
+ }, [status]);
123
+ const save = async (event) => {
124
+ event.preventDefault();
125
+ if (!canSave || requests.current.busy) return;
126
+ requests.current.busy = true;
127
+ requests.current.revision++;
128
+ setBusy(true); setFeedback(null);
129
+ try {
130
+ await rpcCall('ds-bot.bind', { botId, conversationKey, dsBotId });
131
+ setDsBotId(''); setConversationKey('');
132
+ await refresh();
133
+ setFeedbackTone('success'); setFeedback('绑定已保存。');
134
+ } catch (error) {
135
+ if (error?.code === 'ds-bot-binding-conflict') await refresh();
136
+ setFeedbackTone('error'); setFeedback(dsBotErrorMessage(error));
137
+ } finally { requests.current.busy = false; setBusy(false); }
138
+ };
139
+ const unbind = async (key) => {
140
+ if (requests.current.busy) return;
141
+ requests.current.busy = true;
142
+ requests.current.revision++;
143
+ setBusy(true); setFeedback(null);
144
+ try {
145
+ await rpcCall('ds-bot.unbind', { botId, conversationKey: key });
146
+ await refresh();
147
+ setFeedbackTone('success'); setFeedback('已解除绑定,聊天记录保留。');
148
+ } catch (error) {
149
+ setFeedbackTone('error'); setFeedback(dsBotErrorMessage(error));
150
+ } finally { requests.current.busy = false; setBusy(false); }
151
+ };
152
+ return h('section', { className: 'dim-deliveryTargets dim-dsBotSettings', 'aria-label': '绑定bot' },
153
+ h('div', { className: 'dim-deliverySectionHeading' },
154
+ h('div', null, h('h3', null, '绑定bot'), h('p', null, '选择 DS Bot 和私聊对象,直接使用 Bot 的会话。')),
155
+ h('button', { className: 'dim-deliveryButton', type: 'button', disabled: busy || loading, onClick: () => void refresh() }, '刷新')),
156
+ !status ? h('p', { className: 'dim-dsBotNotice', role: 'status' }, '正在检测 DS Bot…')
157
+ : status.state !== 'ready' ? h('p', { className: 'dim-dsBotNotice', role: 'status' }, DS_BOT_MESSAGES[status.state] ?? DS_BOT_MESSAGES.unavailable)
158
+ : !bots.length ? h('p', { className: 'dim-dsBotNotice' }, '还没有 DS Bot,请先在 DS Bot 中创建机器人后刷新。')
159
+ : !conversations.length ? h('p', { className: 'dim-dsBotNotice' }, '还没有可绑定的私聊。先给这个机器人发一条私聊消息,再点击刷新。')
160
+ : h('form', { className: 'dim-dsBotForm', onSubmit: save },
161
+ h('div', { className: 'dim-targetFormGrid' },
162
+ h('div', { className: 'dim-targetField' }, h('span', null, 'DS Bot'),
163
+ h(DsBotPicker, { bots: availableBots, value: dsBotId, onChange: setDsBotId, disabled: busy || loading })),
164
+ h('label', { className: 'dim-targetField' }, h('span', null, '私聊对象'),
165
+ h('select', {
166
+ value: conversationKey, required: true, disabled: busy || loading || !availableConversations.length,
167
+ onChange: (event) => setConversationKey(event.target.value),
168
+ }, h('option', { value: '' }, availableConversations.length ? '选择私聊对象' : '暂无可选私聊对象'),
169
+ availableConversations.map((conversation) => React.createElement('option', {
170
+ key: conversation.conversationKey, value: conversation.conversationKey,
171
+ }, conversationLabel(conversation)))))),
172
+ !availableBots.length || !availableConversations.length
173
+ ? h('p', { className: 'dim-dsBotNotice' }, '已绑定的 DS Bot 和私聊对象不可重复选择,解除绑定后可重新选择。')
174
+ : null,
175
+ h('div', { className: 'dim-targetFormActions' },
176
+ h('button', { type: 'submit', className: 'dim-deliveryButton', 'data-kind': 'primary',
177
+ disabled: !canSave,
178
+ }, busy ? '正在保存…' : '保存绑定'))),
179
+ bindings.length ? h('ul', { className: 'dim-targetList' }, bindings.map((conversation) => {
180
+ const bot = bots.find((entry) => entry.id === conversation.dsBotId);
181
+ return h('li', { className: 'dim-targetRow dim-dsBotBinding', key: conversation.conversationKey },
182
+ h('div', { className: 'dim-dsBotBoundIdentity' },
183
+ h(DsBotAvatar, { bot: bot ?? { id: conversation.dsBotId }, size: 32 }),
184
+ h('div', { className: 'dim-targetSummary' },
185
+ h('div', { className: 'dim-targetTitle' },
186
+ bot ? React.createElement('strong', null, bot.name) : h('strong', null, 'DS Bot 暂不可用'),
187
+ h('span', null, '已绑定')),
188
+ React.createElement('p', { className: 'dim-dsBotDestination' }, conversationLabel(conversation)))),
189
+ h('button', { type: 'button', className: 'dim-deliveryButton', 'data-kind': 'danger', disabled: busy || loading,
190
+ onClick: () => void unbind(conversation.conversationKey),
191
+ }, '解除绑定'));
192
+ })) : null,
193
+ feedback ? h('p', { role: 'status', className: 'dim-targetFeedback', 'data-tone': feedbackTone }, feedback) : null);
194
+ }