@xmanrui/dsh-im 5.10.0 → 5.11.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 (114) hide show
  1. package/README.en.md +39 -5
  2. package/README.md +42 -5
  3. package/bin/dsh-im.mjs +65 -0
  4. package/docs/client-integration.md +4 -0
  5. package/lib/client.js +1202 -95
  6. package/lib/index.js +365 -339
  7. package/package.json +7 -6
  8. package/plugin-src/client/access-policy-settings.js +210 -12
  9. package/plugin-src/client/bot-general-settings.js +44 -3
  10. package/plugin-src/client/i18n-ru.js +85 -0
  11. package/plugin-src/client/i18n.js +83 -0
  12. package/plugin-src/client/im-channels.js +419 -0
  13. package/plugin-src/client/index.js +33 -1
  14. package/plugin-src/client/styles.js +7 -7
  15. package/plugin-src/client/update-panel.js +2 -1
  16. package/plugin-src/host/channel-list-rpc.mjs +280 -0
  17. package/plugin-src/host/channels/dingtalk/production.mjs +28 -10
  18. package/plugin-src/host/channels/dingtalk/rpc.mjs +10 -1
  19. package/plugin-src/host/channels/feishu/production.mjs +39 -10
  20. package/plugin-src/host/channels/feishu/rpc.mjs +10 -1
  21. package/plugin-src/host/channels/matrix/production.mjs +28 -10
  22. package/plugin-src/host/channels/matrix/rpc.mjs +10 -0
  23. package/plugin-src/host/channels/qq/production.mjs +30 -11
  24. package/plugin-src/host/channels/qq/rpc.mjs +10 -1
  25. package/plugin-src/host/channels/shared/access-policy-production.mjs +9 -0
  26. package/plugin-src/host/channels/shared/binding-events.mjs +109 -0
  27. package/plugin-src/host/channels/shared/production.mjs +14 -1
  28. package/plugin-src/host/channels/shared/reply-content-rpc.mjs +17 -0
  29. package/plugin-src/host/channels/shared/rpc.mjs +9 -0
  30. package/plugin-src/host/channels/slack/production.mjs +28 -10
  31. package/plugin-src/host/channels/slack/rpc.mjs +10 -0
  32. package/plugin-src/host/channels/telegram/production.mjs +5 -0
  33. package/plugin-src/host/channels/wecom/production.mjs +28 -10
  34. package/plugin-src/host/channels/wecom/rpc.mjs +10 -1
  35. package/plugin-src/host/channels/wecom-app/production.mjs +28 -10
  36. package/plugin-src/host/channels/wecom-app/rpc.mjs +9 -0
  37. package/plugin-src/host/channels/weixin/production.mjs +28 -10
  38. package/plugin-src/host/channels/weixin/rpc.mjs +10 -1
  39. package/plugin-src/host/channels/whatsapp/production.mjs +28 -10
  40. package/plugin-src/host/channels/whatsapp/rpc.mjs +10 -1
  41. package/plugin-src/host/delivery-service.mjs +3 -4
  42. package/plugin-src/host/delivery-suggestions.mjs +3 -1
  43. package/plugin-src/host/harness-connection.mjs +2 -1
  44. package/plugin-src/host/harness-peer.mjs +3 -1
  45. package/plugin-src/host/index.mjs +8 -1
  46. package/plugin-src/host/modern-harness-api.mjs +5 -1
  47. package/plugin-src/host/root-scope.mjs +32 -0
  48. package/plugin-src/host/session-sync-coordinator.mjs +2 -1
  49. package/plugin-src/management-rpc.mjs +18 -2
  50. package/scripts/verify-package.mjs +36 -7
  51. package/src/channels/dingtalk/dingtalk-bridge.mjs +50 -6
  52. package/src/channels/dingtalk/state-store.mjs +56 -0
  53. package/src/channels/discord/discord-api.mjs +2 -1
  54. package/src/channels/feishu/bridge.mjs +154 -58
  55. package/src/channels/feishu/feishu-cards.mjs +10 -4
  56. package/src/channels/feishu/feishu-runtime.mjs +11 -3
  57. package/src/channels/feishu/message-utils.mjs +106 -30
  58. package/src/channels/feishu/slash-command-panel.mjs +26 -0
  59. package/src/channels/feishu/state-store.mjs +14 -0
  60. package/src/channels/matrix/matrix-api.mjs +2 -1
  61. package/src/channels/qq/qq-bridge.mjs +105 -14
  62. package/src/channels/qq/state-store.mjs +13 -1
  63. package/src/channels/shared/access-policy.mjs +60 -7
  64. package/src/channels/shared/bot-workspace-store.mjs +155 -3
  65. package/src/channels/shared/busy-message-dispatcher.mjs +2 -2
  66. package/src/channels/shared/channel-capabilities.mjs +44 -0
  67. package/src/channels/shared/command-catalog.mjs +68 -3
  68. package/src/channels/shared/command-permission.mjs +6 -2
  69. package/src/channels/shared/conversation-state-store.mjs +16 -0
  70. package/src/channels/shared/deferred-delivery-coordinator.mjs +6 -1
  71. package/src/channels/shared/deferred-delivery.mjs +4 -0
  72. package/src/channels/shared/diagnostic-details.mjs +6 -1
  73. package/src/channels/shared/failure-log-file.mjs +79 -0
  74. package/src/channels/shared/harness-client.mjs +111 -6
  75. package/src/channels/shared/i18n-en/feishu.mjs +2 -2
  76. package/src/channels/shared/i18n-en/shared-a.mjs +13 -2
  77. package/src/channels/shared/i18n-en/shared-b.mjs +67 -4
  78. package/src/channels/shared/i18n-en/shared-d.mjs +144 -0
  79. package/src/channels/shared/i18n-en/weixin.mjs +4 -0
  80. package/src/channels/shared/i18n-en.mjs +2 -0
  81. package/src/channels/shared/i18n-ru/feishu.mjs +2 -2
  82. package/src/channels/shared/i18n-ru/shared-a.mjs +13 -2
  83. package/src/channels/shared/i18n-ru/shared-b.mjs +67 -4
  84. package/src/channels/shared/i18n-ru/shared-d.mjs +144 -0
  85. package/src/channels/shared/i18n-ru/weixin.mjs +4 -0
  86. package/src/channels/shared/i18n-ru.mjs +2 -0
  87. package/src/channels/shared/inbound-access.mjs +10 -0
  88. package/src/channels/shared/markdown-chunks.mjs +5 -0
  89. package/src/channels/shared/message-failure.mjs +22 -1
  90. package/src/channels/shared/new-command.mjs +158 -4
  91. package/src/channels/shared/plan-goal-command.mjs +132 -0
  92. package/src/channels/shared/qrcode.mjs +5 -0
  93. package/src/channels/shared/reply-content.mjs +102 -0
  94. package/src/channels/shared/reset-command.mjs +46 -0
  95. package/src/channels/shared/semantic/artifact.mjs +133 -29
  96. package/src/channels/shared/semantic/reply-reference.mjs +18 -3
  97. package/src/channels/shared/session-nav-command.mjs +999 -0
  98. package/src/channels/shared/session-ring-support.mjs +184 -0
  99. package/src/channels/shared/session-ring.mjs +202 -0
  100. package/src/channels/shared/session-title.mjs +11 -0
  101. package/src/channels/shared/status-command.mjs +2 -1
  102. package/src/channels/shared/text-harness-bridge.mjs +166 -7
  103. package/src/channels/shared/workspace-command.mjs +567 -31
  104. package/src/channels/shared/workspace-session.mjs +39 -3
  105. package/src/channels/slack/slack-api.mjs +2 -1
  106. package/src/channels/telegram/config-store.mjs +10 -2
  107. package/src/channels/telegram/telegram-rich-message.mjs +17 -5
  108. package/src/channels/telegram/telegram-runtime.mjs +14 -1
  109. package/src/channels/wecom/state-store.mjs +13 -1
  110. package/src/channels/wecom/wecom-bridge.mjs +183 -26
  111. package/src/channels/wecom-app/state-store.mjs +13 -1
  112. package/src/channels/wecom-app/wecom-app-bridge.mjs +44 -4
  113. package/src/channels/weixin/state-store.mjs +13 -1
  114. package/src/channels/weixin/weixin-bridge.mjs +71 -4
@@ -0,0 +1,419 @@
1
+ // Read-only directory of every DSH-IM channel and its bound DSH sessions.
2
+ // Opened from the IM settings toolbar; it has no permanent sidebar entry.
3
+ import * as React from 'react';
4
+ import { callManagementRpc } from '../management-rpc.mjs';
5
+ import { h, IM_LOCALE_NAMESPACE, imLocale, localizeTemplate, localizeText } from './i18n.js';
6
+ import { IM_MAIN_PANEL_ID } from './plugin-page.js';
7
+ export const CHANNEL_LIST_RPC_CHANNEL = '/dsh-im-channels';
8
+ export const CHANNEL_SESSIONS_PANEL_ID = 'xmanrui-dsh-im-channels';
9
+
10
+ const CHANNEL_LABELS = Object.freeze({
11
+ matrix: 'Matrix',
12
+ telegram: 'Telegram',
13
+ whatsapp: 'WhatsApp',
14
+ wecom: '微信客服',
15
+ 'wecom-app': '企业微信',
16
+ feishu: '飞书',
17
+ dingtalk: '钉钉',
18
+ slack: 'Slack',
19
+ discord: 'Discord',
20
+ line: 'LINE',
21
+ qq: 'QQ',
22
+ });
23
+
24
+ const styles = Object.freeze({
25
+ header: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 16, marginBottom: 20 },
26
+ title: { margin: 0, fontSize: 22, fontWeight: 650 },
27
+ description: { margin: '6px 0 0', opacity: 0.68, lineHeight: 1.6 },
28
+ button: { border: '1px solid var(--dim-border, #444)', borderRadius: 6, background: 'transparent', color: 'inherit', padding: '6px 12px', cursor: 'pointer', whiteSpace: 'nowrap' },
29
+ group: { marginBottom: 22 },
30
+ groupTitle: { display: 'flex', alignItems: 'center', gap: 8, margin: '0 0 8px', fontSize: 16 },
31
+ count: { opacity: 0.58, fontSize: 12, fontWeight: 400 },
32
+ tableWrap: { overflowX: 'auto', border: '1px solid var(--dim-border, #444)', borderRadius: 8 },
33
+ table: { width: '100%', borderCollapse: 'collapse', fontSize: 13 },
34
+ th: { textAlign: 'left', padding: '10px 12px', borderBottom: '1px solid var(--dim-border, #444)', opacity: 0.65, fontWeight: 500 },
35
+ td: { padding: '10px 12px', borderBottom: '1px solid var(--dim-border, #333)', verticalAlign: 'top' },
36
+ code: { fontFamily: 'ui-monospace, SFMono-Regular, Consolas, monospace', fontSize: 12, overflowWrap: 'anywhere' },
37
+ secondary: { display: 'block', marginTop: 4, opacity: 0.55, fontSize: 11 },
38
+ muted: { opacity: 0.65, padding: '24px 0' },
39
+ error: { padding: 12, marginBottom: 16, borderRadius: 6, background: 'var(--dim-error-bg, rgba(220, 70, 70, .12))', color: 'var(--dim-error, #e17777)', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' },
40
+ actions: { display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' },
41
+ messageList: { display: 'flex', flexDirection: 'column', gap: 12, marginTop: 16 },
42
+ message: { maxWidth: 920, padding: '12px 14px', border: '1px solid var(--dim-border, #444)', borderRadius: 10, background: 'var(--dim-bg-secondary, rgba(127, 127, 127, .06))' },
43
+ userMessage: { borderColor: 'var(--dim-accent-border, rgba(80, 140, 220, .45))', background: 'var(--dim-accent-bg, rgba(80, 140, 220, .08))' },
44
+ messageMeta: { display: 'flex', justifyContent: 'space-between', gap: 12, marginBottom: 7, opacity: 0.62, fontSize: 12 },
45
+ messageText: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', lineHeight: 1.65, fontSize: 14 },
46
+ detailMeta: { margin: '8px 0 0', opacity: 0.68, lineHeight: 1.7, overflowWrap: 'anywhere' },
47
+ });
48
+
49
+ function formatTime(value) {
50
+ if (!Number.isFinite(value)) return '';
51
+ try {
52
+ const locale = imLocale();
53
+ const tag = locale === 'zh' ? 'zh-CN' : locale === 'ru' ? 'ru-RU' : 'en-US';
54
+ return new Date(value).toLocaleString(tag, { hour12: false });
55
+ } catch {
56
+ return '';
57
+ }
58
+ }
59
+
60
+ function text(value) {
61
+ return String(value == null ? '' : value);
62
+ }
63
+
64
+ function errorText(error) {
65
+ return error instanceof Error ? error.message : text(error);
66
+ }
67
+
68
+ async function copyText(value) {
69
+ if (globalThis.navigator?.clipboard?.writeText) {
70
+ await globalThis.navigator.clipboard.writeText(value);
71
+ return;
72
+ }
73
+ const area = document.createElement('textarea');
74
+ area.value = value;
75
+ area.style.position = 'fixed';
76
+ area.style.opacity = '0';
77
+ document.body.appendChild(area);
78
+ area.select();
79
+ const copied = document.execCommand('copy');
80
+ area.remove();
81
+ if (!copied) throw new Error('浏览器未允许访问剪贴板');
82
+ }
83
+
84
+ class ChannelListPage extends React.Component {
85
+ constructor(props) {
86
+ super(props);
87
+ this.state = {
88
+ channels: null, error: null, refreshing: false, copyStatus: null,
89
+ selected: null, detail: null, detailError: null, detailLoading: false, loadingEarlier: false,
90
+ };
91
+ this.reload = this.reload.bind(this);
92
+ this.openSession = this.openSession.bind(this);
93
+ this.backToList = this.backToList.bind(this);
94
+ this.loadEarlier = this.loadEarlier.bind(this);
95
+ this.copySession = this.copySession.bind(this);
96
+ this.unmounted = false;
97
+ this.request = null;
98
+ this.detailRequest = null;
99
+ this.copyTimer = null;
100
+ }
101
+
102
+ componentDidMount() {
103
+ void this.reload();
104
+ }
105
+
106
+ componentWillUnmount() {
107
+ this.unmounted = true;
108
+ this.request?.abort();
109
+ this.detailRequest?.abort();
110
+ if (this.copyTimer) clearTimeout(this.copyTimer);
111
+ }
112
+
113
+ rpc(method, payload, signal) {
114
+ const call = this.props.channelListRpcCall || ((endpoint, body, rpcSignal) =>
115
+ callManagementRpc(this.props.ctx.connection, CHANNEL_LIST_RPC_CHANNEL, endpoint, body, rpcSignal));
116
+ return call(method, payload, signal);
117
+ }
118
+
119
+ async reload() {
120
+ this.request?.abort();
121
+ const controller = new AbortController();
122
+ this.request = controller;
123
+ this.setState({ refreshing: true, error: null });
124
+ try {
125
+ const result = await this.rpc('list.channels', {}, controller.signal);
126
+ if (controller.signal.aborted) return;
127
+ if (!result || result.ok !== true) {
128
+ throw new Error(result?.error?.message || result?.error?.code || 'failed to list channels');
129
+ }
130
+ if (!Array.isArray(result.value?.channels)) {
131
+ throw new Error('宿主响应缺少 value.channels,请检查 dsh-im host 是否已重载');
132
+ }
133
+ if (!this.unmounted) this.setState({ channels: result.value.channels });
134
+ } catch (error) {
135
+ if (controller.signal.aborted || this.unmounted) return;
136
+ this.setState({ channels: null, error: errorText(error) });
137
+ } finally {
138
+ if (this.request === controller) {
139
+ this.request = null;
140
+ if (!this.unmounted) this.setState({ refreshing: false });
141
+ }
142
+ }
143
+ }
144
+
145
+ async openSession(group, row) {
146
+ const selected = {
147
+ channel: group.channel,
148
+ key: text(row.key),
149
+ botId: text(row.botId),
150
+ sessionId: text(row.sessionId),
151
+ };
152
+ this.detailRequest?.abort();
153
+ const controller = new AbortController();
154
+ this.detailRequest = controller;
155
+ this.setState({
156
+ selected, detail: null, detailError: null, detailLoading: true, loadingEarlier: false,
157
+ });
158
+ try {
159
+ const result = await this.rpc('session.read', selected, controller.signal);
160
+ if (controller.signal.aborted || this.detailRequest !== controller) return;
161
+ if (!result || result.ok !== true) {
162
+ throw new Error(result?.error?.message || result?.error?.code || 'failed to read session');
163
+ }
164
+ if (!Array.isArray(result.value?.messages)) {
165
+ throw new Error('宿主响应缺少 value.messages,请检查 dsh-im host 是否已重载');
166
+ }
167
+ this.setState({ detail: result.value, detailError: null });
168
+ } catch (error) {
169
+ if (controller.signal.aborted || this.unmounted || this.detailRequest !== controller) return;
170
+ this.setState({ detailError: errorText(error) });
171
+ } finally {
172
+ if (this.detailRequest === controller) {
173
+ this.detailRequest = null;
174
+ if (!this.unmounted) this.setState({ detailLoading: false });
175
+ }
176
+ }
177
+ }
178
+
179
+ backToList() {
180
+ this.detailRequest?.abort();
181
+ this.detailRequest = null;
182
+ this.setState({
183
+ selected: null, detail: null, detailError: null, detailLoading: false, loadingEarlier: false,
184
+ });
185
+ }
186
+
187
+ async loadEarlier() {
188
+ const { selected, detail } = this.state;
189
+ if (!selected || !detail?.hasMore || this.detailRequest) return;
190
+ const controller = new AbortController();
191
+ this.detailRequest = controller;
192
+ this.setState({ loadingEarlier: true, detailError: null });
193
+ try {
194
+ const result = await this.rpc('session.read', {
195
+ ...selected, offset: detail.nextOffset, limit: detail.limit,
196
+ }, controller.signal);
197
+ if (controller.signal.aborted || this.detailRequest !== controller) return;
198
+ if (!result || result.ok !== true) {
199
+ throw new Error(result?.error?.message || result?.error?.code || 'failed to read earlier messages');
200
+ }
201
+ if (!Array.isArray(result.value?.messages)) throw new Error('宿主响应缺少 value.messages');
202
+ const earlier = result.value;
203
+ this.setState(previous => {
204
+ if (!previous.detail) return null;
205
+ // The oldest page is still limit-sized. Keep only the part before the
206
+ // page already displayed, and retain the original snapshot's total.
207
+ const prependCount = Math.max(0, previous.detail.offset - earlier.offset);
208
+ return {
209
+ detail: {
210
+ ...previous.detail,
211
+ offset: earlier.offset,
212
+ hasMore: earlier.hasMore,
213
+ nextOffset: earlier.nextOffset,
214
+ messages: [
215
+ ...earlier.messages.slice(0, prependCount),
216
+ ...previous.detail.messages,
217
+ ],
218
+ },
219
+ };
220
+ });
221
+ } catch (error) {
222
+ if (controller.signal.aborted || this.unmounted || this.detailRequest !== controller) return;
223
+ this.setState({ detailError: errorText(error) });
224
+ } finally {
225
+ if (this.detailRequest === controller) {
226
+ this.detailRequest = null;
227
+ if (!this.unmounted) this.setState({ loadingEarlier: false });
228
+ }
229
+ }
230
+ }
231
+
232
+ async copySession(sessionId) {
233
+ try {
234
+ await copyText(sessionId);
235
+ if (!this.unmounted) this.setState({ copyStatus: { sessionId, ok: true } });
236
+ } catch {
237
+ if (!this.unmounted) this.setState({ copyStatus: { sessionId, ok: false } });
238
+ }
239
+ if (this.copyTimer) clearTimeout(this.copyTimer);
240
+ this.copyTimer = setTimeout(() => {
241
+ if (!this.unmounted) this.setState({ copyStatus: null });
242
+ }, 1800);
243
+ }
244
+
245
+ renderRow(group, row) {
246
+ const sessionId = text(row.sessionId);
247
+ const status = this.state.copyStatus?.sessionId === sessionId ? this.state.copyStatus : null;
248
+ return h('tr', { key: `${group.channel}:${row.botId}:${row.key}:${sessionId}` },
249
+ h('td', { style: styles.td },
250
+ h('code', { style: styles.code }, text(row.key)),
251
+ h('span', { style: styles.secondary }, `bot:${text(row.botId)}`)),
252
+ h('td', { style: styles.td },
253
+ h('button', {
254
+ type: 'button', style: { ...styles.button, ...styles.code, padding: '4px 6px', textAlign: 'left' },
255
+ className: 'im-channel-session-open', onClick: () => { void this.openSession(group, row); },
256
+ 'aria-label': localizeTemplate('查看会话 {sessionId}', { sessionId }), title: '查看该会话的用户与助手正文',
257
+ }, sessionId)),
258
+ h('td', { style: { ...styles.td, width: 88 } },
259
+ h('button', {
260
+ type: 'button', style: styles.button, className: 'im-channel-session-copy',
261
+ onClick: () => { void this.copySession(sessionId); },
262
+ 'aria-label': localizeTemplate('复制会话 ID {sessionId}', { sessionId }),
263
+ }, status ? (status.ok ? '已复制' : '复制失败') : '复制 ID')));
264
+ }
265
+
266
+ renderGroup(group) {
267
+ const label = CHANNEL_LABELS[group.channel] || group.channel;
268
+ const rows = Array.isArray(group.sessions) ? group.sessions : [];
269
+ return h('section', { key: group.channel, className: 'im-channel-group', style: styles.group },
270
+ h('h2', { style: styles.groupTitle }, label,
271
+ group.channel === label ? null : h('span', { style: styles.count }, group.channel),
272
+ h('span', { style: styles.count }, localizeTemplate('{count} 个会话', { count: rows.length }))),
273
+ h('div', { style: styles.tableWrap },
274
+ h('table', { style: styles.table },
275
+ h('thead', null, h('tr', null,
276
+ h('th', { style: styles.th }, '通道 / 会话键'),
277
+ h('th', { style: styles.th }, 'DSH 会话 ID'),
278
+ h('th', { style: styles.th }, '操作'))),
279
+ h('tbody', null, rows.map(row => this.renderRow(group, row))))));
280
+ }
281
+
282
+ renderMessage(message) {
283
+ const role = message.role === 'user' ? '用户' : '助手';
284
+ const time = formatTime(message.time);
285
+ return h('article', {
286
+ key: message.id || `${message.seq}:${message.role}`,
287
+ className: `im-channel-message im-channel-message-${message.role}`,
288
+ style: { ...styles.message, ...(message.role === 'user' ? styles.userMessage : null) },
289
+ },
290
+ h('div', { style: styles.messageMeta },
291
+ h('strong', null, role),
292
+ h('span', null, time || (Number.isInteger(message.seq)
293
+ ? localizeTemplate('事件 {seq}', { seq: message.seq }) : ''))),
294
+ h('div', { style: styles.messageText }, text(message.text)),
295
+ message.truncated ? h('div', { style: styles.secondary }, '本条消息过长,已截断。') : null);
296
+ }
297
+
298
+ renderDetail() {
299
+ const { selected, detail, detailError, detailLoading, loadingEarlier, copyStatus } = this.state;
300
+ const label = CHANNEL_LABELS[selected.channel] || selected.channel;
301
+ const copyState = copyStatus?.sessionId === selected.sessionId ? copyStatus : null;
302
+ let body;
303
+ if (detailLoading && !detail) {
304
+ body = h('p', { style: styles.muted }, '加载中…');
305
+ } else if (!detail) {
306
+ body = null;
307
+ } else if (detail.messages.length === 0) {
308
+ body = h('p', { style: styles.muted }, '没有可显示的用户或助手正文。');
309
+ } else {
310
+ body = h('div', { className: 'im-channel-message-list', style: styles.messageList },
311
+ detail.messages.map(message => this.renderMessage(message)));
312
+ }
313
+ return h(React.Fragment, null,
314
+ h('header', { style: { ...styles.header, flexWrap: 'wrap' } },
315
+ h('div', null,
316
+ h('h1', { style: styles.title }, '会话内容'),
317
+ h('p', { style: styles.detailMeta }, `${label} · ${selected.key}`),
318
+ h('code', { style: styles.code }, selected.sessionId),
319
+ h('p', { style: styles.description }, '只读显示用户与助手正文;系统提示、工具调用和内部推理不显示。')),
320
+ h('div', { style: styles.actions },
321
+ this.renderBackToIm(),
322
+ h('button', { type: 'button', className: 'im-channel-back', style: styles.button, onClick: this.backToList }, '返回列表'),
323
+ h('button', {
324
+ type: 'button', className: 'im-channel-detail-refresh', style: styles.button,
325
+ disabled: detailLoading || loadingEarlier,
326
+ onClick: () => { void this.openSession(selected, selected); },
327
+ }, detailLoading ? '刷新中…' : '刷新'),
328
+ h('button', {
329
+ type: 'button', className: 'im-channel-detail-copy', style: styles.button,
330
+ onClick: () => { void this.copySession(selected.sessionId); },
331
+ }, copyState ? (copyState.ok ? '已复制' : '复制失败') : '复制 ID'))),
332
+ detailError ? h('div', { role: 'alert', style: styles.error },
333
+ localizeTemplate('读取失败:{error}', { error: localizeText(detailError) })) : null,
334
+ detail ? h('div', { style: { marginBottom: 12 } },
335
+ h('p', { style: { ...styles.description, margin: '0 0 10px' } },
336
+ localizeTemplate('已显示 {shown} / {total} 条正文', {
337
+ shown: detail.messages.length, total: detail.total,
338
+ })),
339
+ detail.hasMore ? h('button', {
340
+ type: 'button', className: 'im-channel-load-earlier', style: styles.button,
341
+ onClick: this.loadEarlier, disabled: loadingEarlier,
342
+ }, loadingEarlier ? '加载中…' : '加载更早消息') : null) : null,
343
+ body);
344
+ }
345
+
346
+ renderBackToIm() {
347
+ return this.props.onBackToIm ? h('button', {
348
+ type: 'button', className: 'im-channel-back-to-im', style: styles.button,
349
+ onClick: this.props.onBackToIm,
350
+ }, '返回 IM机器人') : null;
351
+ }
352
+
353
+ render() {
354
+ const { channels, error, refreshing, selected } = this.state;
355
+ if (selected) {
356
+ return h('div', { className: 'dim-pluginPage im-channel-session-detail' },
357
+ h('div', { className: 'dim-pluginPageContent' }, this.renderDetail()));
358
+ }
359
+ let body;
360
+ if (error) {
361
+ body = h('div', { role: 'alert', style: styles.error },
362
+ localizeTemplate('加载失败:{error}', { error: localizeText(error) }));
363
+ } else if (!channels) {
364
+ body = h('p', { style: styles.muted }, '正在读取通道会话…');
365
+ } else if (channels.length === 0) {
366
+ body = h('p', { style: styles.muted }, '尚未发现已绑定 DSH 会话的通道。');
367
+ } else {
368
+ body = channels.map(group => this.renderGroup(group));
369
+ }
370
+ return h('div', { className: 'dim-pluginPage im-channel-sessions-page' },
371
+ h('div', { className: 'dim-pluginPageContent' },
372
+ h('header', { style: { ...styles.header, flexWrap: 'wrap' } },
373
+ h('div', null,
374
+ h('h1', { style: styles.title }, '会话记录'),
375
+ h('p', { style: styles.description }, '只读列出各 IM 通道当前绑定的 DSH 会话;点击会话 ID 查看正文,不会修改绑定。')),
376
+ h('div', { style: styles.actions },
377
+ this.renderBackToIm(),
378
+ h('button', { type: 'button', className: 'im-channel-refresh', style: styles.button, onClick: this.reload, disabled: refreshing },
379
+ refreshing ? '刷新中…' : '刷新'))),
380
+ body));
381
+ }
382
+ }
383
+
384
+ export function ChannelSessionsPanel(props) {
385
+ return h(ChannelListPage, props);
386
+ }
387
+
388
+ export function installChannelSessionsPage(ctx, { channelListRpcCall }) {
389
+ let navigate = null;
390
+ const listeners = new Set();
391
+ const publish = (value) => {
392
+ navigate = value;
393
+ for (const listener of listeners) listener();
394
+ };
395
+ // Only offer the toolbar action while both navigation and its target slot
396
+ // exist. Late services and plugin disposal must not leave a dead button.
397
+ const controller = {
398
+ available: () => navigate !== null,
399
+ open: () => navigate?.(),
400
+ subscribe(listener) {
401
+ listeners.add(listener);
402
+ return () => listeners.delete(listener);
403
+ },
404
+ };
405
+ if (typeof ctx.inject === 'function') {
406
+ ctx.inject(['layout'], pageCtx => pageCtx.slots.inject('main', () => {
407
+ const stopMain = pageCtx.slots.register({
408
+ name: 'main', key: CHANNEL_SESSIONS_PANEL_ID, locale: IM_LOCALE_NAMESPACE,
409
+ inject: () => ({
410
+ channelListRpcCall,
411
+ onBackToIm: () => pageCtx.layout.selectPanel(IM_MAIN_PANEL_ID),
412
+ }),
413
+ }, ChannelSessionsPanel);
414
+ publish(() => pageCtx.layout.selectPanel(CHANNEL_SESSIONS_PANEL_ID));
415
+ return () => { publish(null); stopMain(); };
416
+ }));
417
+ }
418
+ return controller;
419
+ }
@@ -88,6 +88,7 @@ import { IMPanelErrorBoundary } from './panel-error-boundary.js';
88
88
  import { installImPluginPage } from './plugin-page.js';
89
89
  import { installSidebarVisibilitySync, SIDEBAR_SETTINGS_ENDPOINTS, SIDEBAR_SETTINGS_RPC_CHANNEL } from './sidebar-settings.js';
90
90
 
91
+ import { installChannelSessionsPage, CHANNEL_LIST_RPC_CHANNEL } from './im-channels.js';
91
92
  export const name = 'im-settings';
92
93
  export const inject = ['slots', 'connection', 'locale', 'workspaces'];
93
94
  export const IM_PLUGIN_VERSION = manifest.version;
@@ -240,6 +241,7 @@ export function IMSettingsTab({
240
241
  deliverySyncRpcCall,
241
242
  languageRpcCall,
242
243
  workspaceDirectoryPicker,
244
+ onOpenSessionHistory,
243
245
  preferredSectionId,
244
246
  browserLocation = globalThis.location,
245
247
  navigateToRecoveryUrl = replacePageLocation,
@@ -261,6 +263,7 @@ export function IMSettingsTab({
261
263
  [emailEnabled],
262
264
  );
263
265
  const githubTooltipId = React.useId();
266
+ const sessionHistoryTooltipId = React.useId();
264
267
  const generalSettingsTooltipId = React.useId();
265
268
  const globalSettingsSelected = selected === GLOBAL_SETTINGS_TAB_ID;
266
269
  const active = visibleChannels.find((channel) => channel.id === selected) ?? visibleChannels[0];
@@ -362,6 +365,25 @@ export function IMSettingsTab({
362
365
  className: 'dim-githubTooltip',
363
366
  role: 'tooltip',
364
367
  }, '帮助与反馈 · 前往 GitHub')),
368
+ onOpenSessionHistory ? h('span', { className: 'dim-sessionHistoryAction' },
369
+ h('button', {
370
+ type: 'button',
371
+ className: 'dim-sessionHistoryButton',
372
+ 'aria-label': '会话记录',
373
+ 'aria-describedby': sessionHistoryTooltipId,
374
+ onClick: onOpenSessionHistory,
375
+ }, h('svg', {
376
+ width: 18, height: 18, viewBox: '0 0 24 24', fill: 'none',
377
+ stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
378
+ focusable: 'false', 'aria-hidden': 'true',
379
+ },
380
+ h('path', { d: 'M21 15a3 3 0 0 1-3 3H7l-4 3V6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3Z' }),
381
+ h('path', { d: 'M8 8h8M8 12h5' }))),
382
+ h('span', {
383
+ id: sessionHistoryTooltipId,
384
+ className: 'dim-sessionHistoryTooltip',
385
+ role: 'tooltip',
386
+ }, '会话记录')) : null,
365
387
  h('span', { className: 'dim-generalSettingsAction' },
366
388
  h('button', {
367
389
  type: 'button',
@@ -569,6 +591,8 @@ export function apply(ctx) {
569
591
  managementRpc(ctx.connection, DELIVERY_SYNC_SETTINGS_RPC_CHANNEL, endpoint, payload, signal);
570
592
  const languageRpcCall = (endpoint, payload, signal) =>
571
593
  managementRpc(ctx.connection, HOST_LANGUAGE_RPC_CHANNEL, endpoint, payload, signal);
594
+ const channelListRpcCall = (endpoint, payload, signal) =>
595
+ managementRpc(ctx.connection, CHANNEL_LIST_RPC_CHANNEL, endpoint, payload, signal);
572
596
  const workspaceDirectoryPicker = Object.freeze({
573
597
  listDirectory: (path, signal) =>
574
598
  callWorkspaceDirectoryApi(ctx, 'listDirectory', path, signal),
@@ -595,6 +619,7 @@ export function apply(ctx) {
595
619
  globalSettingsRpcCall,
596
620
  languageRpcCall,
597
621
  deliverySyncRpcCall,
622
+ channelListRpcCall,
598
623
  workspaceDirectoryPicker,
599
624
  };
600
625
  const subscribeLocale = (listener) => typeof ctx.on === 'function'
@@ -605,8 +630,14 @@ export function apply(ctx) {
605
630
  // new component type and reset the reader's selected tab or unsaved input.
606
631
  function IMPanel({ preferredSectionId }) {
607
632
  React.useSyncExternalStore(subscribeLocale, localeSnapshot, localeSnapshot);
633
+ const historyAvailable = React.useSyncExternalStore(
634
+ channelSessionsPage.subscribe, channelSessionsPage.available, channelSessionsPage.available,
635
+ );
608
636
  return h(IMPanelErrorBoundary, null,
609
- h(IMSettingsTab, { ...panelDependencies, preferredSectionId }));
637
+ h(IMSettingsTab, {
638
+ ...panelDependencies, preferredSectionId,
639
+ onOpenSessionHistory: historyAvailable ? channelSessionsPage.open : undefined,
640
+ }));
610
641
  }
611
642
  const buildPanelElement = (props = {}) => h(IMPanel, {
612
643
  preferredSectionId: props.preferredSectionId,
@@ -616,6 +647,7 @@ export function apply(ctx) {
616
647
  packageName: manifest.name,
617
648
  renderPanel: buildPanelElement,
618
649
  });
650
+ const channelSessionsPage = installChannelSessionsPage(ctx, { channelListRpcCall });
619
651
 
620
652
  ctx.effect(() => {
621
653
  sidebarSync = installSidebarVisibilitySync({
@@ -114,14 +114,14 @@ const CSS = String.raw`
114
114
  .dim-githubLink:focus-visible { outline: 2px solid color-mix(in srgb, var(--dim-blue) 70%, white); outline-offset: 2px; }
115
115
  .dim-updateTooltip, .dim-githubTooltip { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: max-content; max-width: min(220px, 80vw); padding: 6px 9px; border: 1px solid var(--dsw-alias-border-l2, #dfe1e5); border-radius: 7px; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-layer-3, #fff); box-shadow: 0 8px 24px rgb(31 35 41 / 14%); font-size: 11px; line-height: 16px; font-weight: 500; white-space: nowrap; opacity: 0; visibility: hidden; transform: translateY(-3px); pointer-events: none; transition: opacity .15s ease, transform .15s ease, visibility .15s ease; }
116
116
  .dim-updateAction:hover .dim-updateTooltip, .dim-updateTrigger:focus-visible + .dim-updateTooltip, .dim-githubAction:hover .dim-githubTooltip, .dim-githubAction:focus-within .dim-githubTooltip { opacity: 1; visibility: visible; transform: translateY(0); }
117
- .dim-generalSettingsAction { position: relative; display: inline-flex; flex: none; }
118
- .dim-generalSettingsButton { width: 30px; height: 30px; display: grid; place-items: center; flex: none; padding: 0; border: 1px solid var(--dsw-alias-border-l2, #dfe1e5); border-radius: 8px; color: var(--dsw-alias-label-secondary, #646a73); background: var(--dsw-alias-bg-layer-1, #fff); cursor: pointer; transition: border-color .15s ease, color .15s ease, background .15s ease, box-shadow .15s ease; }
119
- .dim-generalSettingsButton svg { display: block; }
120
- .dim-generalSettingsButton:hover { border-color: #aeb3bb; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-interactive-bg-hover, #f7f8fa); }
117
+ .dim-sessionHistoryAction, .dim-generalSettingsAction { position: relative; display: inline-flex; flex: none; }
118
+ .dim-sessionHistoryButton, .dim-generalSettingsButton { width: 30px; height: 30px; display: grid; place-items: center; flex: none; padding: 0; border: 1px solid var(--dsw-alias-border-l2, #dfe1e5); border-radius: 8px; color: var(--dsw-alias-label-secondary, #646a73); background: var(--dsw-alias-bg-layer-1, #fff); cursor: pointer; transition: border-color .15s ease, color .15s ease, background .15s ease, box-shadow .15s ease; }
119
+ .dim-sessionHistoryButton svg, .dim-generalSettingsButton svg { display: block; }
120
+ .dim-sessionHistoryButton:hover, .dim-generalSettingsButton:hover { border-color: #aeb3bb; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-interactive-bg-hover, #f7f8fa); }
121
121
  .dim-generalSettingsButton[aria-current="page"] { border-color: color-mix(in srgb, var(--dim-blue) 42%, var(--dsw-alias-border-l2, #dfe1e5)); color: var(--dim-blue); background: var(--dim-blue-soft); }
122
- .dim-generalSettingsButton:focus-visible { outline: 2px solid color-mix(in srgb, var(--dim-blue) 70%, white); outline-offset: 2px; }
123
- .dim-generalSettingsTooltip { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: max-content; padding: 6px 9px; border: 1px solid var(--dsw-alias-border-l2, #dfe1e5); border-radius: 7px; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-layer-3, #fff); box-shadow: 0 8px 24px rgb(31 35 41 / 14%); font-size: 11px; line-height: 16px; font-weight: 500; white-space: nowrap; opacity: 0; visibility: hidden; transform: translateY(-3px); pointer-events: none; transition: opacity .15s ease, transform .15s ease, visibility .15s ease; }
124
- .dim-generalSettingsAction:hover .dim-generalSettingsTooltip, .dim-generalSettingsButton:focus-visible + .dim-generalSettingsTooltip { opacity: 1; visibility: visible; transform: translateY(0); }
122
+ .dim-sessionHistoryButton:focus-visible, .dim-generalSettingsButton:focus-visible { outline: 2px solid color-mix(in srgb, var(--dim-blue) 70%, white); outline-offset: 2px; }
123
+ .dim-sessionHistoryTooltip, .dim-generalSettingsTooltip { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: max-content; padding: 6px 9px; border: 1px solid var(--dsw-alias-border-l2, #dfe1e5); border-radius: 7px; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-layer-3, #fff); box-shadow: 0 8px 24px rgb(31 35 41 / 14%); font-size: 11px; line-height: 16px; font-weight: 500; white-space: nowrap; opacity: 0; visibility: hidden; transform: translateY(-3px); pointer-events: none; transition: opacity .15s ease, transform .15s ease, visibility .15s ease; }
124
+ .dim-sessionHistoryAction:hover .dim-sessionHistoryTooltip, .dim-sessionHistoryButton:focus-visible + .dim-sessionHistoryTooltip, .dim-generalSettingsAction:hover .dim-generalSettingsTooltip, .dim-generalSettingsButton:focus-visible + .dim-generalSettingsTooltip { opacity: 1; visibility: visible; transform: translateY(0); }
125
125
  .dim-generalSettingsButton[aria-current="page"] + .dim-generalSettingsTooltip { opacity: 0; visibility: hidden; transform: translateY(-3px); }
126
126
  .dim-layout { display: grid; grid-template-columns: 174px 1px minmax(0, 1fr); gap: 24px; align-items: start; }
127
127
  .dim-rail { display: grid; align-content: start; gap: 8px; padding: 0 4px 1px 1px; }
@@ -471,7 +471,8 @@ export function UpdatePanel({ rpcCall, clientVersion, onStatus }) {
471
471
  h('strong', null, 'DSH 版本兼容说明'),
472
472
  h('p', { className: 'dim-updateManualHint' }, 'dsh-im 4.25.0 支持到 DSH v0.1.6-alpha.2。'),
473
473
  h('p', { className: 'dim-updateManualHint' }, 'dsh-im 4.39.0 仅支持 DSH 0.2.0-rc.2。'),
474
- h('p', { className: 'dim-updateManualHint' }, 'dsh-im 5.0.0 仅支持 DSH 0.2.1-rc.2。')),
474
+ h('p', { className: 'dim-updateManualHint' }, 'dsh-im 5.0.0 仅支持 DSH 0.2.1-rc.2。'),
475
+ h('p', { className: 'dim-updateManualHint' }, 'dsh-im 5.10.0 起支持 DSH 0.2.2-rc.5。')),
475
476
  h(ManualUpdateCommand, {
476
477
  key: manualCommand ?? 'unavailable', command: manualCommand,
477
478
  disabled: busyAction || activeJob || uncertainInstall,