@xmanrui/dsh-im 5.9.1 → 5.10.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 (43) hide show
  1. package/PROACTIVE_DELIVERY.en.md +33 -9
  2. package/PROACTIVE_DELIVERY.md +33 -9
  3. package/README.en.md +3 -2
  4. package/README.md +4 -3
  5. package/lib/client.js +550 -125
  6. package/lib/index.js +323 -323
  7. package/package.json +1 -1
  8. package/plugin-src/client/delivery-settings.js +2 -0
  9. package/plugin-src/client/delivery-sync-settings.js +269 -0
  10. package/plugin-src/client/global-settings.js +45 -7
  11. package/plugin-src/client/i18n-ru.js +27 -0
  12. package/plugin-src/client/i18n.js +27 -0
  13. package/plugin-src/client/index.js +17 -1
  14. package/plugin-src/client/model-setting.js +6 -3
  15. package/plugin-src/client/styles.js +16 -0
  16. package/plugin-src/host/channels/feishu/production.mjs +11 -27
  17. package/plugin-src/host/channels/shared/workspace-rpc.mjs +1 -0
  18. package/plugin-src/host/delivery-adapter.mjs +35 -20
  19. package/plugin-src/host/delivery-service.mjs +100 -1
  20. package/plugin-src/host/delivery-suggestions.mjs +28 -0
  21. package/plugin-src/host/delivery-sync-rpc.mjs +100 -0
  22. package/plugin-src/host/host-language-rpc.mjs +16 -2
  23. package/plugin-src/host/host-language.mjs +29 -0
  24. package/plugin-src/host/index.mjs +22 -0
  25. package/plugin-src/host/session-sync-coordinator.mjs +288 -121
  26. package/plugin-src/host/session-sync-targets.mjs +71 -0
  27. package/scripts/verify-package.mjs +14 -5
  28. package/src/channels/qq/qq-bridge.mjs +9 -0
  29. package/src/channels/qq/state-store.mjs +42 -0
  30. package/src/channels/shared/action-card.mjs +83 -7
  31. package/src/channels/shared/bot-workspace-store.mjs +100 -8
  32. package/src/channels/shared/delivery-sync-settings-store.mjs +86 -0
  33. package/src/channels/shared/delivery-sync-settings.mjs +122 -0
  34. package/src/channels/shared/harness-client.mjs +148 -90
  35. package/src/channels/shared/i18n-en/diagnostics.mjs +1 -0
  36. package/src/channels/shared/i18n-en/shared-b.mjs +6 -0
  37. package/src/channels/shared/i18n-ru/diagnostics.mjs +1 -0
  38. package/src/channels/shared/i18n-ru/shared-b.mjs +5 -0
  39. package/src/channels/shared/interface-language-store.mjs +49 -10
  40. package/src/channels/shared/interface-language.mjs +19 -1
  41. package/src/channels/shared/model-setting.mjs +6 -3
  42. package/src/channels/shared/workspace-session.mjs +13 -1
  43. package/src/channels/telegram/telegram-api.mjs +19 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmanrui/dsh-im",
3
- "version": "5.9.1",
3
+ "version": "5.10.0",
4
4
  "icon": "./assets/logo-plugin-message-link-gradient.webp",
5
5
  "description": "把微信、飞书、企微、钉钉、QQ、Telegram、WhatsApp、Slack、Discord、Matrix接入DSH。 Connect Telegram, WhatsApp, Slack, Discord, Matrix, WeChat, Feishu, WeCom, DingTalk, and QQ to DSH.",
6
6
  "keywords": [
@@ -346,6 +346,8 @@ function TargetForm({
346
346
  return h('form', { className: 'dim-targetForm', onSubmit: submit },
347
347
  h('div', { className: 'dim-targetFormHeading' },
348
348
  h('h3', null, editing ? '编辑投递目标' : '新建投递目标'),
349
+ h('p', { style: { color: '#92400e', background: '#fffbeb', padding: '8px 10px', borderRadius: '6px', fontSize: '12px', lineHeight: 1.5 } },
350
+ '目标是细粒度设置:某个机器人一旦配置了目标(哪怕关闭会话同步),该机器人的投递就按目标走。如需使用「通用设置 → 投递」里的简单开关,请先删除该机器人的全部目标。'),
349
351
  editing
350
352
  ? initialValue?.sessionSync?.enabled
351
353
  ? h('p', null, '修改接收位置会关闭会话双向同步。')
@@ -0,0 +1,269 @@
1
+ import * as React from 'react';
2
+
3
+ import {
4
+ DEFAULT_DELIVERY_SYNC_SETTINGS,
5
+ normalizeDeliverySyncIcon,
6
+ normalizeDeliverySyncSettings,
7
+ } from '../../src/channels/shared/delivery-sync-settings.mjs';
8
+ import { h } from './i18n.js';
9
+
10
+ /**
11
+ * Delivery-sync settings: which turns the chat mirrors even though they did not
12
+ * start in the chat (a turn typed in the Web GUI, a turn started by a schedule
13
+ * reminder or a subagent notice), the two prefix icons, and the language the
14
+ * plugin's own chat messages are written in.
15
+ */
16
+ /**
17
+ * Management channel serving these endpoints. Separate from the loopback-only
18
+ * `/dsh-im-settings` so the page also works when the dashboard is opened
19
+ * through its own domain.
20
+ */
21
+ export const DELIVERY_SYNC_SETTINGS_RPC_CHANNEL = '/dsh-im-delivery-sync';
22
+
23
+ export const DELIVERY_SYNC_SETTINGS_ENDPOINTS = Object.freeze({
24
+ get: 'settings.delivery-sync.get',
25
+ set: 'settings.delivery-sync.set',
26
+ getLanguage: 'settings.language.get',
27
+ setLanguage: 'settings.language.set',
28
+ });
29
+
30
+ /** The languages the plugin ships chat-message dictionaries for, plus "follow DSH". */
31
+ export const MESSAGE_LANGUAGE_OPTIONS = Object.freeze([
32
+ { value: 'auto', label: '跟随 DSH 界面语言' },
33
+ { value: 'zh', label: '中文' },
34
+ { value: 'en', label: 'English' },
35
+ { value: 'ru', label: 'Русский' },
36
+ ]);
37
+
38
+ function unwrap(result) {
39
+ if (result?.ok === true) return result.value;
40
+ if (result?.ok === false) {
41
+ const error = new Error(result.error?.message || '无法读取或保存会话同步设置,请稍后重试。');
42
+ error.code = result.error?.code;
43
+ throw error;
44
+ }
45
+ return result;
46
+ }
47
+
48
+ /**
49
+ * The select shows the pinned language only while it is actually in force: a
50
+ * snapshot resolved by the operator's `language` option keeps reporting its own
51
+ * source, and the page must not claim that selection came from here.
52
+ */
53
+ export function messageLanguageFromSnapshot(snapshot) {
54
+ if (snapshot?.source !== 'explicit') return 'auto';
55
+ const language = snapshot.language;
56
+ return MESSAGE_LANGUAGE_OPTIONS.some((option) => option.value === language) ? language : 'auto';
57
+ }
58
+
59
+ export function DeliverySyncSettings({ rpcCall, languageRpcCall = null }) {
60
+ const [values, setValues] = React.useState(DEFAULT_DELIVERY_SYNC_SETTINGS);
61
+ const [language, setLanguage] = React.useState('auto');
62
+ const [savedLanguage, setSavedLanguage] = React.useState('auto');
63
+ const [phase, setPhase] = React.useState('loading');
64
+ const [error, setError] = React.useState(null);
65
+ const [saved, setSaved] = React.useState(false);
66
+ const mounted = React.useRef(false);
67
+ const busy = React.useRef(false);
68
+ const id = React.useId();
69
+ const languageAvailable = typeof languageRpcCall === 'function';
70
+
71
+ const load = React.useCallback(async (signal) => {
72
+ setPhase('loading');
73
+ setError(null);
74
+ setSaved(false);
75
+ try {
76
+ // There is no fallback channel: without the delivery-sync one the page
77
+ // says so instead of silently reading another document.
78
+ if (typeof rpcCall !== 'function') throw new Error('投递同步设置通道不可用。');
79
+ const settings = normalizeDeliverySyncSettings(
80
+ unwrap(await rpcCall(DELIVERY_SYNC_SETTINGS_ENDPOINTS.get, {}, signal)),
81
+ );
82
+ if (!settings) throw new Error('会话同步设置返回了无法识别的响应。');
83
+ const snapshot = languageAvailable
84
+ ? unwrap(await languageRpcCall(DELIVERY_SYNC_SETTINGS_ENDPOINTS.getLanguage, {}, signal))
85
+ : null;
86
+ if (signal?.aborted || !mounted.current) return;
87
+ setValues(settings);
88
+ const current = messageLanguageFromSnapshot(snapshot);
89
+ setLanguage(current);
90
+ setSavedLanguage(current);
91
+ setPhase('ready');
92
+ } catch (caught) {
93
+ if (signal?.aborted || !mounted.current) return;
94
+ setError(caught.message || '无法读取或保存会话同步设置,请稍后重试。');
95
+ setPhase('error');
96
+ }
97
+ }, [languageAvailable, languageRpcCall, rpcCall]);
98
+
99
+ React.useEffect(() => {
100
+ mounted.current = true;
101
+ const controller = new AbortController();
102
+ void load(controller.signal);
103
+ return () => { mounted.current = false; controller.abort(); };
104
+ }, [load]);
105
+
106
+ const edit = (patch) => {
107
+ setValues((current) => ({ ...current, ...patch }));
108
+ setSaved(false);
109
+ setError(null);
110
+ };
111
+
112
+ const save = async (event) => {
113
+ event.preventDefault();
114
+ if (busy.current || phase !== 'ready') return;
115
+ busy.current = true;
116
+ setPhase('saving');
117
+ setError(null);
118
+ setSaved(false);
119
+ try {
120
+ if (languageAvailable && language !== savedLanguage) {
121
+ unwrap(await languageRpcCall(
122
+ DELIVERY_SYNC_SETTINGS_ENDPOINTS.setLanguage,
123
+ { language },
124
+ ));
125
+ if (mounted.current) setSavedLanguage(language);
126
+ }
127
+ // Send the icons already trimmed: the Host normalizes them anyway, and
128
+ // the echoed document then matches the field the reader is looking at.
129
+ const settings = normalizeDeliverySyncSettings(unwrap(await rpcCall(
130
+ DELIVERY_SYNC_SETTINGS_ENDPOINTS.set,
131
+ {
132
+ ...values,
133
+ inputIcon: normalizeDeliverySyncIcon(values.inputIcon),
134
+ modelIcon: normalizeDeliverySyncIcon(values.modelIcon),
135
+ },
136
+ )));
137
+ if (!settings) throw new Error('会话同步设置返回了无法识别的响应。');
138
+ if (!mounted.current) return;
139
+ setValues(settings);
140
+ setSaved(true);
141
+ } catch (caught) {
142
+ if (mounted.current) setError(caught.message || '无法读取或保存会话同步设置,请稍后重试。');
143
+ } finally {
144
+ busy.current = false;
145
+ if (mounted.current) setPhase('ready');
146
+ }
147
+ };
148
+
149
+ const disabled = phase !== 'ready';
150
+ const iconHint = '最多 32 个字符;留空则不添加前缀。';
151
+ const rows = [
152
+ {
153
+ key: 'mirrorUserInput',
154
+ icon: 'inputIcon',
155
+ title: '镜像 Web 中输入的消息',
156
+ help: '在 Web GUI 中发送的消息会作为一条带前缀的消息转发到本聊天的会话同步目标。',
157
+ iconLabel: '输入前缀图标',
158
+ },
159
+ {
160
+ key: 'deliverModelAnswers',
161
+ icon: 'modelIcon',
162
+ title: '投递模型回答',
163
+ help: '其他回合(Web 输入、定时提醒、子代理通知等)的模型回答会发送到会话同步目标。',
164
+ iconLabel: '回答前缀图标',
165
+ },
166
+ ];
167
+
168
+ const helpId = `${id}-help`;
169
+
170
+ const head = h('div', { className: 'dim-globalHead' },
171
+ h('div', { className: 'dim-globalHeadTitle' },
172
+ h('h3', null, '会话同步'),
173
+ h('div', { className: 'dim-globalTtlHelp' },
174
+ h('button', {
175
+ type: 'button',
176
+ className: 'dim-channelHelpButton dim-globalTtlHelpButton',
177
+ 'aria-label': '查看会话同步说明',
178
+ 'aria-describedby': helpId,
179
+ }, h('span', { 'aria-hidden': 'true' }, '?')),
180
+ h('div', {
181
+ id: helpId,
182
+ className: 'dim-globalTtlTooltip dim-deliverySyncTooltip',
183
+ role: 'tooltip',
184
+ }, '只对已开启会话同步的目标生效:在 Web GUI 里输入的回合、定时提醒、子代理通知等“不是本聊天发起”的回合,其回答会转发到这些目标。消息语言同时影响机器人发送的命令菜单文本。'))));
185
+
186
+ const languageField = h('div', { className: 'dim-deliverySyncField' },
187
+ h('div', { className: 'dim-deliverySyncLabel' },
188
+ h('label', { htmlFor: `${id}-language` }, '插件消息语言'),
189
+ h('p', { className: 'dim-deliverySyncHelp', id: `${id}-language-help` },
190
+ languageAvailable
191
+ ? '默认跟随 DSH 界面语言;可以单独固定机器人消息的语言。'
192
+ : '语言设置暂不可用。')),
193
+ h('select', {
194
+ id: `${id}-language`,
195
+ className: 'dim-globalTtlInput dim-deliverySyncSelect',
196
+ value: language,
197
+ disabled: disabled || !languageAvailable,
198
+ 'aria-describedby': `${id}-language-help`,
199
+ onChange: (event) => { setLanguage(event.target.value); setSaved(false); setError(null); },
200
+ }, ...MESSAGE_LANGUAGE_OPTIONS.map((option) => h('option', {
201
+ key: option.value,
202
+ value: option.value,
203
+ }, option.label))));
204
+
205
+ const iconFields = rows.map((row) => h('div', { className: 'dim-deliverySyncField', key: row.key },
206
+ h('div', { className: 'dim-deliverySyncLabel' },
207
+ h('label', { className: 'dim-deliverySyncCheckLabel', htmlFor: `${id}-${row.key}` },
208
+ h('input', {
209
+ id: `${id}-${row.key}`,
210
+ type: 'checkbox',
211
+ checked: values[row.key] === true,
212
+ disabled,
213
+ 'aria-describedby': `${id}-${row.key}-help`,
214
+ onChange: (event) => edit({ [row.key]: event.target.checked }),
215
+ }),
216
+ h('span', null, row.title)),
217
+ h('p', { className: 'dim-deliverySyncHelp', id: `${id}-${row.key}-help` }, row.help)),
218
+ h('div', { className: 'dim-deliverySyncIcon' },
219
+ h('input', {
220
+ id: `${id}-${row.icon}`,
221
+ className: 'dim-globalTtlInput dim-deliverySyncIconInput',
222
+ type: 'text',
223
+ value: values[row.icon],
224
+ maxLength: 32,
225
+ autoComplete: 'off',
226
+ placeholder: '🔔',
227
+ 'aria-label': row.iconLabel,
228
+ 'aria-describedby': `${id}-${row.icon}-help`,
229
+ disabled,
230
+ onChange: (event) => edit({ [row.icon]: event.target.value }),
231
+ }),
232
+ h('p', { className: 'dim-deliverySyncHelp', id: `${id}-${row.icon}-help` }, iconHint))));
233
+
234
+ const actions = h('div', { className: 'dim-imageSettingsActions' },
235
+ h('button', {
236
+ type: 'submit',
237
+ className: 'dim-deliveryButton dim-globalSaveButton',
238
+ 'data-kind': 'primary',
239
+ disabled,
240
+ }, phase === 'saving' ? '保存中…' : '保存投递设置'),
241
+ phase === 'error'
242
+ ? h('button', {
243
+ type: 'button',
244
+ className: 'dim-deliveryButton dim-globalSaveButton',
245
+ onClick: () => void load(),
246
+ }, '重试')
247
+ : null);
248
+
249
+ return h('section', {
250
+ className: 'dim-globalSection dim-deliverySyncSettings',
251
+ 'aria-label': '会话同步',
252
+ 'aria-busy': phase === 'loading' || phase === 'saving',
253
+ },
254
+ head,
255
+ h('form', { onSubmit: save },
256
+ h('div', { className: 'dim-deliverySyncFields' }, languageField, ...iconFields),
257
+ actions),
258
+ error
259
+ ? h('p', {
260
+ className: 'dim-globalInline dim-deliverySyncFeedback',
261
+ 'data-tone': 'error',
262
+ role: 'alert',
263
+ }, error)
264
+ : null,
265
+ saved ? h('p', { className: 'dim-globalInline dim-deliverySyncFeedback', role: 'status' }, '已保存') : null,
266
+ phase === 'loading'
267
+ ? h('p', { className: 'dim-globalInline dim-deliverySyncFeedback', role: 'status' }, '正在读取投递设置…')
268
+ : null);
269
+ }
@@ -1,3 +1,4 @@
1
+ import { DeliverySyncSettings } from './delivery-sync-settings.js';
1
2
  import { GroupHistorySettings } from './group-history-settings.js';
2
3
  import { SidebarSettings } from './sidebar-settings.js';
3
4
  import * as React from 'react';
@@ -16,6 +17,14 @@ export const GLOBAL_SETTINGS_TAB_ID = 'global-settings';
16
17
 
17
18
  const ATTACHMENTS_TAB_ID = 'dim-general-settings-tab-attachments';
18
19
  const ATTACHMENTS_PANEL_ID = 'dim-general-settings-panel-attachments';
20
+ const DELIVERY_PANEL_ID = 'dim-general-settings-panel-delivery';
21
+
22
+ /** Tabs of the global settings page, in reading order. */
23
+ export const GLOBAL_SETTINGS_TABS = Object.freeze([
24
+ { key: 'general', label: '通用' },
25
+ { key: 'attachments', label: '附件' },
26
+ { key: 'delivery', label: '投递' },
27
+ ]);
19
28
 
20
29
  export const GLOBAL_SETTINGS_ENDPOINTS = Object.freeze({
21
30
  getTtl: 'settings.inbound-ttl.get',
@@ -418,9 +427,41 @@ function AttachmentSettingsPanel({ rpcCall }) {
418
427
  h(ImageInputSettings, { rpcCall }));
419
428
  }
420
429
 
421
- export function GlobalSettingsPanel({ rpcCall }) {
430
+ export function GlobalSettingsPanel({ rpcCall, deliverySyncRpcCall = null, languageRpcCall = null }) {
422
431
  const [tab, setTab] = React.useState('general');
423
- const tabs = [{ key: 'general', label: '通用' }, { key: 'attachments', label: '附件' }];
432
+ const tabs = GLOBAL_SETTINGS_TABS;
433
+ const selectTab = (next) => {
434
+ setTab(next);
435
+ globalThis.document?.getElementById(`dim-general-settings-tab-${next}`)?.focus();
436
+ };
437
+ const step = (key) => {
438
+ const at = tabs.findIndex((item) => item.key === tab);
439
+ if (key === 'Home') return tabs[0].key;
440
+ if (key === 'End') return tabs[tabs.length - 1].key;
441
+ const delta = key === 'ArrowLeft' ? -1 : 1;
442
+ return tabs[(at + delta + tabs.length) % tabs.length].key;
443
+ };
444
+ const panel = tab === 'attachments'
445
+ ? h(AttachmentSettingsPanel, { rpcCall })
446
+ : tab === 'delivery'
447
+ ? h('div', {
448
+ id: DELIVERY_PANEL_ID,
449
+ className: 'dim-generalSettingsTabPanel',
450
+ role: 'tabpanel',
451
+ 'aria-labelledby': `dim-general-settings-tab-delivery`,
452
+ }, h(DeliverySyncSettings, {
453
+ // This page has its own management channel: falling back to the
454
+ // loopback-only settings call would hide a missing channel behind a
455
+ // request the panel cannot actually use.
456
+ rpcCall: deliverySyncRpcCall,
457
+ languageRpcCall,
458
+ }))
459
+ : h('div', {
460
+ id: 'dim-general-settings-panel-general',
461
+ className: 'dim-generalSettingsTabPanel',
462
+ role: 'tabpanel',
463
+ 'aria-labelledby': 'dim-general-settings-tab-general',
464
+ }, h(SidebarSettings, { rpcCall }), h(GroupHistorySettings, { rpcCall }));
424
465
  return h('section', { className: 'dim-generalSettingsPage', 'aria-label': '通用设置' },
425
466
  h('header', { className: 'dim-generalSettingsHeader' }, h('h2', null, '通用设置')),
426
467
  h('div', { className: 'dim-generalSettingsTabsBar' },
@@ -432,11 +473,8 @@ export function GlobalSettingsPanel({ rpcCall }) {
432
473
  onClick: () => setTab(item.key), onKeyDown: (event) => {
433
474
  if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
434
475
  event.preventDefault();
435
- const next = event.key === 'Home' ? 'general' : event.key === 'End' ? 'attachments' : tab === 'general' ? 'attachments' : 'general';
436
- setTab(next); globalThis.document?.getElementById(`dim-general-settings-tab-${next}`)?.focus();
476
+ selectTab(step(event.key));
437
477
  },
438
478
  }, item.label)))),
439
- tab === 'general' ? h('div', { id: 'dim-general-settings-panel-general', className: 'dim-generalSettingsTabPanel', role: 'tabpanel',
440
- 'aria-labelledby': 'dim-general-settings-tab-general' }, h(SidebarSettings, { rpcCall }), h(GroupHistorySettings, { rpcCall }))
441
- : h(AttachmentSettingsPanel, { rpcCall }));
479
+ panel);
442
480
  }
@@ -647,6 +647,7 @@ const CLIENT = Object.freeze({
647
647
  '查看模型设置说明': 'Показать описание настроек модели',
648
648
  '跟随默认模型': 'Как модель по умолчанию',
649
649
  '模型修改失败,请重试。': 'Не удалось изменить модель. Повторите попытку.',
650
+ '无法读取所选模型的列表,模型设置未保存,请重试。': 'Не удалось загрузить список выбранного провайдера моделей. Настройка модели не сохранена. Повторите попытку.',
650
651
  '模型无效。': 'Некорректная модель.',
651
652
  '模型不存在或不可用。': 'Модель не существует или недоступна.',
652
653
  '当前模型已不可用,请选择其他模型或跟随默认模型。':
@@ -1249,6 +1250,7 @@ const CLIENT = Object.freeze({
1249
1250
  'Сначала напишите боту сообщение на платформе, затем обновите список.',
1250
1251
  '已添加': 'Добавлено',
1251
1252
  '手动填写(高级)': 'Ввести вручную (для опытных)',
1253
+ '目标是细粒度设置:某个机器人一旦配置了目标(哪怕关闭会话同步),该机器人的投递就按目标走。如需使用「通用设置 → 投递」里的简单开关,请先删除该机器人的全部目标。': 'Цели — тонкая настройка: как только у бота есть хотя бы одна цель (даже с выключенной синхронизацией), доставка этого бота идёт по целям. Чтобы использовать простые переключатели в «Общие настройки → Доставка», сначала удалите все цели этого бота.',
1252
1254
  '测试消息已发送,请到目标会话确认。': 'Тестовое сообщение отправлено. Проверьте его в целевой беседе.',
1253
1255
  '测试发送失败,请稍后重试。': 'Тестовая отправка не удалась. Попробуйте позже.',
1254
1256
  '已复制调用参数': 'Параметры вызова скопированы',
@@ -1637,6 +1639,31 @@ const CLIENT = Object.freeze({
1637
1639
  '已解除绑定,聊天记录保留。': 'Привязка снята, история чата сохранена.',
1638
1640
  '还没有 DS Bot,请先在 DS Bot 中创建机器人后刷新。':
1639
1641
  'DS Bot пока нет. Создайте бота в DS Bot и обновите страницу.',
1642
+ '投递': 'Доставка',
1643
+ '会话同步': 'Синхронизация сессий',
1644
+ '只对已开启会话同步的目标生效:在 Web GUI 里输入的回合、定时提醒、子代理通知等“不是本聊天发起”的回合,其回答会转发到这些目标。消息语言同时影响机器人发送的命令菜单文本。': 'Действует для целей с включённой синхронизацией сессии: ответы ходов, начатых не в этом чате (ввод из Web GUI, напоминания по расписанию, уведомления субагентов), отправляются этим целям. Язык сообщений также меняет текст меню команд, которые присылает бот.',
1645
+ '查看会话同步说明': 'Показать справку по синхронизации сессий',
1646
+ '插件消息语言': 'Язык сообщений плагина',
1647
+ '跟随 DSH 界面语言': 'Как в интерфейсе DSH',
1648
+ '中文': '中文',
1649
+ 'English': 'English',
1650
+ 'Русский': 'Русский',
1651
+ '镜像 Web 中输入的消息': 'Зеркалить сообщения, набранные в Web',
1652
+ '输入前缀图标': 'Иконка ввода',
1653
+ '投递模型回答': 'Доставлять ответы модели',
1654
+ '回答前缀图标': 'Иконка ответа',
1655
+ '最多 32 个字符;留空则不添加前缀。': 'До 32 символов; пустое поле — без префикса.',
1656
+ '保存投递设置': 'Сохранить настройки доставки',
1657
+ '正在读取投递设置…': 'Читаю настройки доставки…',
1658
+ '投递同步设置通道不可用。': 'Канал настроек синхронизации доставки недоступен.',
1659
+ '会话同步设置返回了无法识别的响应。': 'Настройки доставки вернули нераспознанный ответ.',
1660
+ '无法读取或保存会话同步设置,请稍后重试。': 'Не удалось прочитать или сохранить настройки доставки. Повторите попытку позже.',
1661
+ '无效的会话同步设置:开关必须是布尔值,图标是不超过 32 个字符的文本。': 'Неверные настройки доставки: переключатель должен быть логическим значением, а иконка — текстом не длиннее 32 символов.',
1662
+ '只对已开启会话同步的目标生效;消息语言同时影响机器人发送的命令菜单文本。': 'Действует для целей с включённой синхронизацией сессий; язык сообщений также меняет текст меню команд, которые присылает бот.',
1663
+ '默认跟随 DSH 界面语言;可以单独固定机器人消息的语言。': 'По умолчанию следует языку интерфейса DSH; язык сообщений бота можно зафиксировать отдельно.',
1664
+ '语言设置暂不可用。': 'Настройка языка недоступна.',
1665
+ '在 Web GUI 中发送的消息会作为一条带前缀的消息转发到本聊天的会话同步目标。': 'Сообщение, отправленное в Web GUI, пересылается цели синхронизации сессий этого чата с префиксом-иконкой.',
1666
+ '其他回合(Web 输入、定时提醒、子代理通知等)的模型回答会发送到会话同步目标。': 'Ответы модели в других ходах (ввод в Web, напоминания по расписанию, уведомления субагентов и т. п.) отправляются цели синхронизации сессий.',
1640
1667
  'DS Bot 暂不可用': 'DS Bot недоступен',
1641
1668
  });
1642
1669
 
@@ -644,6 +644,7 @@ const EN = Object.freeze({
644
644
  '查看模型设置说明': 'View model setting help',
645
645
  '跟随默认模型': 'Follow the default model',
646
646
  '模型修改失败,请重试。': 'Could not update the model. Try again.',
647
+ '无法读取所选模型的列表,模型设置未保存,请重试。': 'Could not load the selected model’s catalog. The model setting was not saved. Try again.',
647
648
  '模型无效。': 'The model is invalid.',
648
649
  '模型不存在或不可用。': 'The model does not exist or is unavailable.',
649
650
  '当前模型已不可用,请选择其他模型或跟随默认模型。': 'The current model is unavailable. Choose another model or follow the default.',
@@ -1131,6 +1132,7 @@ const EN = Object.freeze({
1131
1132
  '先在对应平台与机器人聊一条消息,再刷新。': 'Send the bot a message on the platform, then refresh.',
1132
1133
  '已添加': 'Added',
1133
1134
  '手动填写(高级)': 'Enter manually (advanced)',
1135
+ '目标是细粒度设置:某个机器人一旦配置了目标(哪怕关闭会话同步),该机器人的投递就按目标走。如需使用「通用设置 → 投递」里的简单开关,请先删除该机器人的全部目标。': 'Targets are a fine-grained setting: once a bot has any target (even with session sync off), delivery for that bot follows the targets. To use the simple switches under General settings → Delivery, delete all of that bot’s targets first.',
1134
1136
  '测试消息已发送,请到目标会话确认。': 'Test message sent. Confirm it in the target conversation.',
1135
1137
  '测试发送失败,请稍后重试。': 'Test delivery failed. Try again later.',
1136
1138
  '已复制调用参数': 'Call parameters copied',
@@ -1315,6 +1317,31 @@ const EN = Object.freeze({
1315
1317
  '由授权结果自动填入,无需手工填写。': 'Filled in from the authorization; no need to type it.',
1316
1318
  '刷新会话列表': 'Refresh the session list',
1317
1319
  '腾讯 Agent 邮箱需要微信扫码授权。点下面的按钮生成授权链接,在打开的页面里用微信扫码登录并确认。': 'The Tencent Agent mailbox authorizes with a WeChat QR code. Generate an authorization link, then scan it with WeChat on the page that opens and confirm.',
1320
+ '投递': 'Delivery',
1321
+ '会话同步': 'Session sync',
1322
+ '只对已开启会话同步的目标生效:在 Web GUI 里输入的回合、定时提醒、子代理通知等“不是本聊天发起”的回合,其回答会转发到这些目标。消息语言同时影响机器人发送的命令菜单文本。': 'Applies to targets with Session sync turned on: answers of turns this chat did not start (Web GUI input, schedule reminders, subagent notices) are forwarded to those targets. The message language also changes the command menus the bot sends.',
1323
+ '查看会话同步说明': 'Show Session sync help',
1324
+ '插件消息语言': 'Plugin message language',
1325
+ '跟随 DSH 界面语言': 'Same as the DSH interface',
1326
+ '中文': '中文',
1327
+ 'English': 'English',
1328
+ 'Русский': 'Русский',
1329
+ '镜像 Web 中输入的消息': 'Mirror messages typed in the Web UI',
1330
+ '输入前缀图标': 'Input prefix icon',
1331
+ '投递模型回答': 'Deliver model answers',
1332
+ '回答前缀图标': 'Answer prefix icon',
1333
+ '最多 32 个字符;留空则不添加前缀。': 'Up to 32 characters; leave it empty for no prefix.',
1334
+ '保存投递设置': 'Save delivery settings',
1335
+ '正在读取投递设置…': 'Loading delivery settings…',
1336
+ '投递同步设置通道不可用。': 'The delivery sync settings channel is unavailable.',
1337
+ '会话同步设置返回了无法识别的响应。': 'The delivery settings returned an unrecognized response.',
1338
+ '无法读取或保存会话同步设置,请稍后重试。': 'Could not load or save the delivery settings. Try again later.',
1339
+ '无效的会话同步设置:开关必须是布尔值,图标是不超过 32 个字符的文本。': 'Invalid delivery settings: a switch must be a boolean and an icon is text of at most 32 characters.',
1340
+ '只对已开启会话同步的目标生效;消息语言同时影响机器人发送的命令菜单文本。': 'Applies to targets with Session sync turned on; the message language also changes the command menus the bot sends.',
1341
+ '默认跟随 DSH 界面语言;可以单独固定机器人消息的语言。': 'Follows the DSH interface language by default; you can pin the language of the bot messages separately.',
1342
+ '语言设置暂不可用。': 'The language setting is unavailable.',
1343
+ '在 Web GUI 中发送的消息会作为一条带前缀的消息转发到本聊天的会话同步目标。': 'A message sent in the Web GUI is forwarded to the Session sync target of this chat, prefixed with the icon.',
1344
+ '其他回合(Web 输入、定时提醒、子代理通知等)的模型回答会发送到会话同步目标。': 'Model answers of other turns (Web input, schedule reminders, subagent notices and so on) are sent to the Session sync target.',
1318
1345
  '请求失败': 'The request failed',
1319
1346
  });
1320
1347
 
@@ -79,6 +79,7 @@ import {
79
79
  replacePageLocation,
80
80
  } from './loopback-recovery.js';
81
81
  import { installImStyles } from './styles.js';
82
+ import { DELIVERY_SYNC_SETTINGS_RPC_CHANNEL } from './delivery-sync-settings.js';
82
83
  import { installSessionChannelLogos } from './session-channel-logos.js';
83
84
  import { installDsBotSessionAvatars } from './ds-bot-session-avatars.js';
84
85
  import { UpdatePanel, UPDATE_RPC_CHANNEL } from './update-panel.js';
@@ -236,6 +237,8 @@ export function IMSettingsTab({
236
237
  updateRpcCall,
237
238
  deliveryRpcCall,
238
239
  globalSettingsRpcCall,
240
+ deliverySyncRpcCall,
241
+ languageRpcCall,
239
242
  workspaceDirectoryPicker,
240
243
  preferredSectionId,
241
244
  browserLocation = globalThis.location,
@@ -288,6 +291,8 @@ export function IMSettingsTab({
288
291
  updateRpcCall,
289
292
  deliveryRpcCall,
290
293
  globalSettingsRpcCall,
294
+ deliverySyncRpcCall,
295
+ languageRpcCall,
291
296
  imessageRpcCall,
292
297
  emailRpcCall,
293
298
  matrixRpcCall,
@@ -301,6 +306,7 @@ export function IMSettingsTab({
301
306
  deliveryRpcCall,
302
307
  feishuRpcCall,
303
308
  globalSettingsRpcCall,
309
+ deliverySyncRpcCall,
304
310
  imessageRpcCall,
305
311
  emailRpcCall,
306
312
  matrixRpcCall,
@@ -411,7 +417,11 @@ export function IMSettingsTab({
411
417
  : null,
412
418
  h(BotSettingsContext.Provider, { value: botSettingsContext },
413
419
  globalSettingsSelected
414
- ? h(GlobalSettingsPanel, { rpcCall: rpcCalls.globalSettingsRpcCall })
420
+ ? h(GlobalSettingsPanel, {
421
+ rpcCall: rpcCalls.globalSettingsRpcCall,
422
+ deliverySyncRpcCall: rpcCalls.deliverySyncRpcCall,
423
+ languageRpcCall: rpcCalls.languageRpcCall,
424
+ })
415
425
  : deliverySettings?.channel === active.id
416
426
  ? h(DeliveryTargetSettingsPage, {
417
427
  channel: active.id,
@@ -555,6 +565,10 @@ export function apply(ctx) {
555
565
  const globalSettingsRpcCall = (endpoint, payload, signal) =>
556
566
  managementRpc(ctx.connection, Object.values(SIDEBAR_SETTINGS_ENDPOINTS).includes(endpoint)
557
567
  ? SIDEBAR_SETTINGS_RPC_CHANNEL : GLOBAL_SETTINGS_RPC_CHANNEL, endpoint, payload, signal);
568
+ const deliverySyncRpcCall = (endpoint, payload, signal) =>
569
+ managementRpc(ctx.connection, DELIVERY_SYNC_SETTINGS_RPC_CHANNEL, endpoint, payload, signal);
570
+ const languageRpcCall = (endpoint, payload, signal) =>
571
+ managementRpc(ctx.connection, HOST_LANGUAGE_RPC_CHANNEL, endpoint, payload, signal);
558
572
  const workspaceDirectoryPicker = Object.freeze({
559
573
  listDirectory: (path, signal) =>
560
574
  callWorkspaceDirectoryApi(ctx, 'listDirectory', path, signal),
@@ -579,6 +593,8 @@ export function apply(ctx) {
579
593
  updateRpcCall,
580
594
  deliveryRpcCall,
581
595
  globalSettingsRpcCall,
596
+ languageRpcCall,
597
+ deliverySyncRpcCall,
582
598
  workspaceDirectoryPicker,
583
599
  };
584
600
  const subscribeLocale = (listener) => typeof ctx.on === 'function'
@@ -9,6 +9,7 @@ import {
9
9
  sameModelSelection,
10
10
  } from '../../src/channels/shared/model-setting.mjs';
11
11
  import { h, localizeText } from './i18n.js';
12
+ import { ConnectionError, normalizeConnectionError } from './connection-error.js';
12
13
 
13
14
  export const SET_MODEL_ENDPOINT = 'bot.model.set';
14
15
  export { EMPTY_MODEL_CATALOG, normalizeModelCatalog, normalizeModelSelection };
@@ -87,7 +88,8 @@ export function ModelEditor({ model = null, disabled = false, onSave }) {
87
88
  await onSave?.(next);
88
89
  close(true);
89
90
  } catch (cause) {
90
- setError(cause?.message ?? '模型修改失败,请重试。');
91
+ setError(normalizeConnectionError(cause, 'model-update-failed', '模型修改失败,请重试。'));
92
+ close(true);
91
93
  } finally {
92
94
  savingRef.current = false;
93
95
  setSaving(false);
@@ -146,6 +148,7 @@ export function ModelEditor({ model = null, disabled = false, onSave }) {
146
148
  '只影响新建会话;若当前聊天已有会话,先发送 /new,再发送普通消息生效。'))),
147
149
  saving ? h('span', { className: 'dim-presetStatus', role: 'status' }, '保存中…') : null),
148
150
  row('model', '模型', entry?.name ?? (current ? modelSelectionId(current) : localizeText('跟随默认模型'))),
151
+ error ? h('div', { role: 'alert' }, h(ConnectionError, { error })) : null,
149
152
  row('effort', '思考强度', effortLabel, effortDisabled),
150
153
  pane ? h('div', { ref: menuRef, id: `${id}-menu`, role: 'menu',
151
154
  'aria-label': pane === 'model' ? '模型' : '思考强度', 'aria-busy': saving,
@@ -167,6 +170,6 @@ export function ModelEditor({ model = null, disabled = false, onSave }) {
167
170
  ]) : null,
168
171
  effortHint && effortUnavailable ? h('p', { id: `${id}-hint`, className: 'dim-modelHint',
169
172
  role: 'status' }, effortHint) : null,
170
- error || !currentAvailable ? h('p', { className: 'dim-presetError', role: error ? 'alert' : 'status' },
171
- error ?? '当前模型已不可用,请选择其他模型或跟随默认模型。') : null);
173
+ !error && !currentAvailable ? h('p', { className: 'dim-presetError', role: 'status' },
174
+ '当前模型已不可用,请选择其他模型或跟随默认模型。') : null);
172
175
  }
@@ -822,6 +822,22 @@ const CSS = String.raw`
822
822
  .dim-directoryPickerSpinner { animation-duration: 1.8s; }
823
823
  .dim-collapsibleBody, .dim-collapsibleChevron { transition: none !important; }
824
824
  }
825
+ /* Delivery-sync settings (General settings -> Delivery tab) */
826
+ .dim-deliverySyncSettings { container-type: inline-size; }
827
+ .dim-deliverySyncSettings .dim-globalHead { position: relative; }
828
+ .dim-deliverySyncSettings .dim-globalTtlHelp { position: static; }
829
+ .dim-globalTtlTooltip.dim-deliverySyncTooltip { width: min(360px, 100%); max-width: none; color: var(--dsw-alias-label-secondary, #646a73); font-size: 11px; line-height: 17px; white-space: normal; overflow-wrap: anywhere; }
830
+ .dim-deliverySyncFields { min-width: 0; display: grid; gap: 16px; margin-top: 12px; }
831
+ .dim-deliverySyncField { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 200px); align-items: start; gap: 8px 16px; }
832
+ .dim-deliverySyncLabel { min-width: 0; display: grid; gap: 4px; }
833
+ .dim-deliverySyncLabel > label { color: var(--dsw-alias-label-primary, #1f2329); font-size: 14px; line-height: 22px; }
834
+ .dim-deliverySyncCheckLabel { display: flex; align-items: center; gap: 8px; }
835
+ .dim-deliverySyncCheckLabel input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--dsw-alias-state-business-primary, #3370ff); }
836
+ .dim-deliverySyncHelp { margin: 0; color: var(--dsw-alias-label-secondary, #646a73); font-size: 12px; line-height: 18px; overflow-wrap: anywhere; }
837
+ .dim-deliverySyncIcon { min-width: 0; display: grid; gap: 4px; }
838
+ .dim-deliverySyncFields .dim-globalTtlInput { width: 100%; min-width: 0; }
839
+ .dim-deliverySyncFeedback { margin: 10px 0 0; }
840
+ @container (max-width: 460px) { .dim-deliverySyncField { grid-template-columns: minmax(0, 1fr); } }
825
841
  `;
826
842
 
827
843
  export function installImStyles() {
@@ -32,7 +32,8 @@ import {
32
32
  import { prepareBotWorkspace } from '../../../../src/channels/shared/default-workspace.mjs';
33
33
  import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
34
34
  import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
35
- import { createDeliveryAdapter, configuredSessionSyncTargets, sessionSyncTarget } from '../../delivery-adapter.mjs';
35
+ import { createDeliveryAdapter } from '../../delivery-adapter.mjs';
36
+ import { createSessionSyncTargetsFor } from '../../session-sync-targets.mjs';
36
37
  import {
37
38
  accessPolicyProvider,
38
39
  initialAccessPolicyFor,
@@ -169,32 +170,15 @@ export async function createProductionController(ctx, config = {}, internals = {
169
170
  };
170
171
  // Session-sync mirror targets: which synced DMs (openId) belong to a
171
172
  // Session. Resolved lazily per turn start so rebinding a delivery target
172
- // takes effect without a restart.
173
- const sessionSyncTargetsFor = async (sessionId) => {
174
- if (typeof workspaces.listSessionSyncTargets !== 'function') return [];
175
- const matches = [];
176
- for (const entry of configuredSessionSyncTargets(workspaces)) {
177
- let state;
178
- try {
179
- state = await stateForBotId(entry.botId);
180
- } catch {
181
- continue;
182
- }
183
- let bound;
184
- try {
185
- bound = entry.dsBotId
186
- ? (await config.deliveryService?.dsBot?.resolve(entry.dsBotId))?.sessionId
187
- : state?.snapshot?.().sessions?.[entry.conversationKey];
188
- } catch {
189
- continue;
190
- }
191
- if (bound !== sessionId) continue;
192
- const target = sessionSyncTarget('feishu', workspaces, entry);
193
- const openId = target?.route?.openId;
194
- if (openId) matches.push({ openId, botId: entry.botId, targetId: entry.targetId });
195
- }
196
- return matches;
197
- };
173
+ // takes effect without a restart. The resolver also reads the global delivery
174
+ // switches, so the card mirror is silenced by the same predicate as the
175
+ // coordinator's target path.
176
+ const sessionSyncTargetsFor = createSessionSyncTargetsFor({
177
+ channel: 'feishu',
178
+ workspaces,
179
+ config,
180
+ stateForBotId,
181
+ });
198
182
  const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
199
183
  const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
200
184
  const inboundTtlService = inboundTtl?.service ?? inboundTtl;