@goodandready/dsh-messenger-gateway 0.4.44 → 0.4.46
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.
- package/README.md +4 -0
- package/README.ru.md +2 -0
- package/README.zh.md +2 -0
- package/lib/adapters/telegram.js +25 -13
- package/lib/client.js +205 -23
- package/lib/config.js +30 -6
- package/lib/forum-mirror.js +3 -0
- package/lib/gateway.js +20 -0
- package/lib/index.js +171 -147
- package/lib/outbox.js +4 -1
- package/lib/pairing.js +35 -20
- package/lib/personas.js +27 -11
- package/lib/scheduler.js +30 -11
- package/lib/secret-guard.js +2 -0
- package/lib/settings-bridge.js +32 -4
- package/lib/storage-atomic.js +174 -8
- package/lib/voice-prefs.js +31 -21
- package/lib/webapp.js +8 -5
- package/lib/workspace.js +23 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,6 +162,10 @@ In addition to Telegram, outbound messages can be dispatched to Discord and Slac
|
|
|
162
162
|
- Note: turn replies to the user are streamed directly and are not covered by the outbox retry guarantee (by design — streaming edits cannot be replayed)
|
|
163
163
|
- Inline keyboard `replyMarkup` sent via `/messenger/send` is schema-validated (button text/actions, sizes) before delivery
|
|
164
164
|
- All state files (pairing, outbox, voice prefs) are written with `0600` permissions inside `0700` directories
|
|
165
|
+
- State persistence is durable and versioned: every write is fsynced before the rename (directory fsynced after), each save keeps a `.bak` of the previous good version, files carry a `schemaVersion` with migrations from legacy formats, and a corrupted file is preserved as `.corrupt-<ts>` and recovered from `.bak` — pairing never silently wipes access (fail-closed with an explicit error)
|
|
166
|
+
- Config sync is granular: changes that do not touch the transport slice (tokens, proxy, Bot API root, poll/webhook mode, adapter enablement, session scope) are applied live on the running gateway — active dialogs, streaming replies, pending asks and the Telegram polling offset survive a settings save; only transport changes recreate the gateway, and recreation is serialized (single-flight)
|
|
167
|
+
- `/mute` (per chat) stops ALL outbound delivery to that chat — notify bridge, `messenger.send`, HTTP sends, cron prompts and forum mirroring report `{ok, muted}` and skip delivery; the interactive turn conversation is unaffected, and the dashboard shows real outbox/DLQ counters
|
|
168
|
+
- The settings card is generated from the config schema: every setting is visible and editable (the advanced section covers allowlist mode, bot language, approval sensitivity, streaming, Mini App, cost footer, budget alerts, forum mirror and memory injection), secrets are only reported as configured-flags and never returned to the browser
|
|
165
169
|
- `sessionList`: `true` (default) — enables `/sessions` and `/resume` commands in chat
|
|
166
170
|
- `sessionTitleFromChat`: `false` (default) — name each new session after its originating chat (`TG · @user`, `TG · Group › topic N`) instead of generic generated titles
|
|
167
171
|
- `voiceMode`: `mirror` / `always` / `off` — when to speak replies (also `/voice`)
|
package/README.ru.md
CHANGED
|
@@ -100,6 +100,8 @@ graph LR
|
|
|
100
100
|
* Белые списки разрешенных ID (`allowedUserIds`);
|
|
101
101
|
* Команды `/get` и `/files` доступны только пользователям из белого списка и никогда не отдают скрытые файлы (dotfiles, например `.env`);
|
|
102
102
|
* Loopback-запросы доверяются только с закреплёнными Host (`localhost` / `127.0.0.1` / `[::1]`) — защита от DNS rebinding; для доверенного локального reverse-proxy есть явный флаг `security.trustProxy`.
|
|
103
|
+
* Живучесть состояния: записи состояния атомарны с fsync, версионированы (`schemaVersion` + миграции), каждая запись хранит `.bak` прошлой версии, повреждённый файл сохраняется как `.corrupt-*` и восстанавливается из `.bak` — доступ никогда не обнуляется молча (fail-closed + явная ошибка);
|
|
104
|
+
* Карточка настроек строится из схемы конфигурации: все настройки видимы и редактируемы (в расширенной секции — режим белого списка, язык бота, чувствительность подтверждений, стриминг, Mini App, футер стоимости, бюджетные алерты, зеркалирование в форумы и инъекция памяти), секреты отдаются только флагом «настроен» и никогда не возвращаются в браузер; `/mute` останавливает ВСЮ исходящую доставку в чат (notify bridge, messenger.send, HTTP, cron, зеркалирование), не затрагивая живой диалог;
|
|
103
105
|
|
|
104
106
|
### 6. 🤖 Команды бота (`commands.js`)
|
|
105
107
|
* `/start` — приветствие и запуск сопряжения;
|
package/README.zh.md
CHANGED
|
@@ -86,6 +86,8 @@ dsh plugin --profile web add @goodandready/dsh-messenger-gateway
|
|
|
86
86
|
- **默认关闭白名单模式(`allowlistMode: closed`,fail-closed)**:全新安装不会响应任何用户,直到管理员批准配对码;`open` 模式(空列表时放行所有人)必须显式开启,仅适用于公共助手机器人;
|
|
87
87
|
- `/get` 与 `/files` 命令仅对白名单用户可用,且永远不会返回隐藏文件(dotfiles,如 `.env`);
|
|
88
88
|
- 本地回环请求只接受固定的 Host(`localhost` / `127.0.0.1` / `[::1]`)— 防 DNS Rebinding;如需在受信任的本地反向代理后使用,可显式开启 `security.trustProxy`。
|
|
89
|
+
- 持久化状态:写入先 fsync 再原子重命名,文件带 `schemaVersion`(旧格式自动迁移),每次保存保留 `.bak`,损坏文件以 `.corrupt-*` 保留并可从 `.bak` 恢复——绝不静默清空访问(fail-closed + 显式错误);
|
|
90
|
+
- 设置卡片由配置 schema 生成:所有设置均可见可编辑(高级区含白名单模式、机器人语言、审批灵敏度、流式回复、Mini App、成本页脚、预算告警、论坛镜像与记忆注入);机密只以「已配置」标志形式报告,绝不返回浏览器;`/mute` 停止向该聊天的所有出站投递(notify bridge、messenger.send、HTTP、cron、论坛镜像),不影响实时对话;
|
|
89
91
|
|
|
90
92
|
---
|
|
91
93
|
|
package/lib/adapters/telegram.js
CHANGED
|
@@ -42,8 +42,6 @@ export class TelegramAdapter {
|
|
|
42
42
|
constructor(opts) {
|
|
43
43
|
this.name = 'telegram'
|
|
44
44
|
this.token = String(opts.botToken || '').trim()
|
|
45
|
-
this.allowedUserIds = (opts.allowedUserIds || []).map(Number).filter((n) => Number.isFinite(n))
|
|
46
|
-
this.allowlistMode = opts.allowlistMode === 'open' ? 'open' : 'closed'
|
|
47
45
|
this.timeoutSeconds = Number(opts.timeoutSeconds) || 50
|
|
48
46
|
this.pollIntervalMs = Number(opts.pollIntervalMs) || 500
|
|
49
47
|
this.media = opts.media || {}
|
|
@@ -53,17 +51,6 @@ export class TelegramAdapter {
|
|
|
53
51
|
this.onUnauthorized = opts.onUnauthorized
|
|
54
52
|
this.isUserAllowed = opts.isUserAllowed
|
|
55
53
|
this.logger = opts.logger
|
|
56
|
-
this.commands = normalizeTelegramCommands(opts.commands)
|
|
57
|
-
this.textFormat = opts.textFormat === 'plain' ? 'plain' : 'html'
|
|
58
|
-
this.groupsEnabled = opts.groupsEnabled !== false
|
|
59
|
-
this.groupRequireMention = opts.groupRequireMention !== false
|
|
60
|
-
this.reactionsEnabled = opts.reactionsEnabled !== false
|
|
61
|
-
this.quickActions = opts.quickActions === true
|
|
62
|
-
this.artifactPreviews = opts.artifactPreviews !== false
|
|
63
|
-
this.transport = opts.transport === 'webhook' ? 'webhook' : 'poll'
|
|
64
|
-
this.statusIndicator = opts.statusIndicator === true
|
|
65
|
-
this.statusOnline = String(opts.statusOnline || 'Online')
|
|
66
|
-
this.statusOffline = String(opts.statusOffline || 'Offline')
|
|
67
54
|
this.sendRetryMax = 2
|
|
68
55
|
this.sendRetryBaseMs = 400
|
|
69
56
|
this.pollingConflict = false
|
|
@@ -71,6 +58,7 @@ export class TelegramAdapter {
|
|
|
71
58
|
this.webhookUrl = String(opts.webhookUrl || '').trim()
|
|
72
59
|
this.webhookSecret = String(opts.webhookSecret || '').trim()
|
|
73
60
|
this.stopped = false
|
|
61
|
+
this.transport = opts.transport === 'webhook' ? 'webhook' : 'poll'
|
|
74
62
|
this.mediaGroups = new Map()
|
|
75
63
|
this.mediaGroupDebounceMs = Number(opts.mediaGroupDebounceMs) || 650
|
|
76
64
|
this.pollTimer = undefined
|
|
@@ -94,6 +82,30 @@ export class TelegramAdapter {
|
|
|
94
82
|
this.apiFetch = fetch
|
|
95
83
|
this.logger?.error?.(`dsh-messenger-gateway: telegram proxy is invalid, using direct connection: ${err.message}`)
|
|
96
84
|
}
|
|
85
|
+
// Non-transport options (#224) are snapshotted through the same helper a
|
|
86
|
+
// live config update uses, so constructor and applyLiveConfig cannot drift.
|
|
87
|
+
this.applyLiveConfig(opts)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Re-snapshot NON-transport options from a new telegram config section
|
|
92
|
+
* (#224). Transport-critical fields (token, proxy, apiRoot, transport,
|
|
93
|
+
* webhook URL/secret, poll intervals) require a gateway restart and are
|
|
94
|
+
* deliberately ignored here.
|
|
95
|
+
*/
|
|
96
|
+
applyLiveConfig(tg = {}) {
|
|
97
|
+
this.allowedUserIds = (tg.allowedUserIds || []).map(Number).filter((n) => Number.isFinite(n))
|
|
98
|
+
this.allowlistMode = tg.allowlistMode === 'open' ? 'open' : 'closed'
|
|
99
|
+
this.commands = normalizeTelegramCommands(tg.commands)
|
|
100
|
+
this.textFormat = tg.textFormat === 'plain' ? 'plain' : 'html'
|
|
101
|
+
this.groupsEnabled = tg.groupsEnabled !== false
|
|
102
|
+
this.groupRequireMention = tg.groupRequireMention !== false
|
|
103
|
+
this.reactionsEnabled = tg.reactionsEnabled !== false
|
|
104
|
+
this.quickActions = tg.quickActions === true
|
|
105
|
+
this.artifactPreviews = tg.artifactPreviews !== false
|
|
106
|
+
this.statusIndicator = tg.statusIndicator === true
|
|
107
|
+
this.statusOnline = String(tg.statusOnline || 'Online')
|
|
108
|
+
this.statusOffline = String(tg.statusOffline || 'Offline')
|
|
97
109
|
}
|
|
98
110
|
|
|
99
111
|
setAllowedUserIds(ids) {
|
package/lib/client.js
CHANGED
|
@@ -178,6 +178,31 @@ window.__ModuleLoader__.load({
|
|
|
178
178
|
// Cron badge
|
|
179
179
|
'badge.cron_count': 'Cron: {count}',
|
|
180
180
|
'badge.api_degraded': 'Telegram API degraded ({count})',
|
|
181
|
+
// Settings parity (issue 237): schema fields surfaced in the card
|
|
182
|
+
allowlistMode: 'Allowlist Mode',
|
|
183
|
+
allowlistModeHint: 'closed (default) refuses unknown users until paired; open admits everyone when the list is empty — for public bots only.',
|
|
184
|
+
allowlistClosed: 'closed (fail-closed)',
|
|
185
|
+
allowlistOpen: 'open (public)',
|
|
186
|
+
defaultLocale: 'Bot Language',
|
|
187
|
+
defaultLocaleHint: 'Language for bot service messages (en / zh).',
|
|
188
|
+
webAppEnabled: 'Mini App dashboard enabled',
|
|
189
|
+
webAppUrl: 'Mini App URL',
|
|
190
|
+
webAppUrlHint: 'Public HTTPS URL; empty = auto-detect from webhook origin.',
|
|
191
|
+
costFooter: 'Show cost footer under replies',
|
|
192
|
+
budgetAlert: 'Budget alert threshold (USD, 0 = off)',
|
|
193
|
+
forumMirrorEnable: 'Mirror replies into forum topics',
|
|
194
|
+
forumMirrorChat: 'Forum mirror chat ID',
|
|
195
|
+
memoryEnable: 'Inject agent memories (memory-brain)',
|
|
196
|
+
memoryBaseUrl: 'Memory service URL',
|
|
197
|
+
memoryBaseUrlHint: 'Default http://127.0.0.1:28080; empty = default.',
|
|
198
|
+
approvalsSensitivity: 'Approval Sensitivity',
|
|
199
|
+
approvalsSensitivityHint: 'Which tool calls require confirmation before execution.',
|
|
200
|
+
sensAll: 'all tool calls',
|
|
201
|
+
sensMutations: 'mutations only',
|
|
202
|
+
sensDisabled: 'disabled',
|
|
203
|
+
streamingEnable: 'Stream replies into one message',
|
|
204
|
+
streamEditInterval: 'Stream edit interval (ms)',
|
|
205
|
+
mediaGroupDebounce: 'Album grouping debounce (ms)',
|
|
181
206
|
}
|
|
182
207
|
|
|
183
208
|
const zh = {
|
|
@@ -332,6 +357,31 @@ window.__ModuleLoader__.load({
|
|
|
332
357
|
// Cron badge
|
|
333
358
|
'badge.cron_count': '定时任务: {count}',
|
|
334
359
|
'badge.api_degraded': 'Telegram API 异常 ({count} 次连续错误)',
|
|
360
|
+
// Settings parity (issue 237)
|
|
361
|
+
allowlistMode: '白名单模式',
|
|
362
|
+
allowlistModeHint: 'closed(默认)在配对通过前拒绝未知用户;open 在列表为空时放行所有人——仅适用于公共机器人。',
|
|
363
|
+
allowlistClosed: 'closed(默认拒绝)',
|
|
364
|
+
allowlistOpen: 'open(公共)',
|
|
365
|
+
defaultLocale: '机器人语言',
|
|
366
|
+
defaultLocaleHint: '机器人服务消息的语言(en / zh)。',
|
|
367
|
+
webAppEnabled: '启用 Mini App 面板',
|
|
368
|
+
webAppUrl: 'Mini App 地址',
|
|
369
|
+
webAppUrlHint: '公网 HTTPS 地址;留空则从 webhook 来源自动推断。',
|
|
370
|
+
costFooter: '在回复下方显示成本页脚',
|
|
371
|
+
budgetAlert: '预算告警阈值(USD,0 = 关闭)',
|
|
372
|
+
forumMirrorEnable: '将回复镜像到论坛话题',
|
|
373
|
+
forumMirrorChat: '论坛镜像 chat ID',
|
|
374
|
+
memoryEnable: '注入代理记忆(memory-brain)',
|
|
375
|
+
memoryBaseUrl: '记忆服务地址',
|
|
376
|
+
memoryBaseUrlHint: '默认 http://127.0.0.1:28080;留空使用默认值。',
|
|
377
|
+
approvalsSensitivity: '审批灵敏度',
|
|
378
|
+
approvalsSensitivityHint: '哪些工具调用需要先确认再执行。',
|
|
379
|
+
sensAll: '所有工具调用',
|
|
380
|
+
sensMutations: '仅修改型调用',
|
|
381
|
+
sensDisabled: '禁用',
|
|
382
|
+
streamingEnable: '将回复流式写入同一条消息',
|
|
383
|
+
streamEditInterval: '流式编辑间隔(毫秒)',
|
|
384
|
+
mediaGroupDebounce: '相册分组防抖(毫秒)',
|
|
335
385
|
}
|
|
336
386
|
|
|
337
387
|
|
|
@@ -476,7 +526,7 @@ window.__ModuleLoader__.load({
|
|
|
476
526
|
)
|
|
477
527
|
}
|
|
478
528
|
|
|
479
|
-
const SETTINGS_KEYS = ['enabled', 'telegram', 'discord', 'slack', 'agent', 'media', 'tts']
|
|
529
|
+
const SETTINGS_KEYS = ['enabled', 'defaultLocale', 'telegram', 'discord', 'slack', 'agent', 'media', 'tts', 'memory']
|
|
480
530
|
|
|
481
531
|
function draftFromStored(s) {
|
|
482
532
|
const src = (s && typeof s === 'object') ? s : {}
|
|
@@ -486,11 +536,14 @@ window.__ModuleLoader__.load({
|
|
|
486
536
|
const a = src.agent || {}
|
|
487
537
|
const m = src.media || {}
|
|
488
538
|
const tts = src.tts || {}
|
|
539
|
+
const mem = src.memory || {}
|
|
489
540
|
return {
|
|
490
541
|
enabled: src.enabled !== false,
|
|
542
|
+
defaultLocale: src.defaultLocale === 'zh' ? 'zh' : 'en',
|
|
491
543
|
telegram: {
|
|
492
544
|
enabled: t.enabled === true,
|
|
493
545
|
allowedUserIds: Array.isArray(t.allowedUserIds) ? t.allowedUserIds : [],
|
|
546
|
+
allowlistMode: t.allowlistMode === 'open' ? 'open' : 'closed',
|
|
494
547
|
pollTimeoutSeconds: Number(t.pollTimeoutSeconds) || 50,
|
|
495
548
|
pollIntervalMs: Number(t.pollIntervalMs) || 500,
|
|
496
549
|
commands: Array.isArray(t.commands) ? t.commands : [],
|
|
@@ -516,9 +569,20 @@ window.__ModuleLoader__.load({
|
|
|
516
569
|
transport: t.transport === 'webhook' ? 'webhook' : 'poll',
|
|
517
570
|
webhookUrl: t.webhookUrl || '',
|
|
518
571
|
webhookPath: t.webhookPath || '/dsh-messenger-gateway/telegram/webhook',
|
|
572
|
+
// Configured-flags come from the server projection (issue 237): the badge
|
|
573
|
+
// and placeholder must reflect the STORED secret, not the draft.
|
|
574
|
+
webhookSecretConfigured: t.webhookSecretConfigured === true,
|
|
575
|
+
botTokenConfigured: t.botTokenConfigured === true,
|
|
519
576
|
voiceMode: t.voiceMode || 'mirror',
|
|
520
577
|
quickActions: t.quickActions === true,
|
|
521
578
|
artifactPreviews: t.artifactPreviews !== false,
|
|
579
|
+
webAppEnabled: t.webAppEnabled !== false,
|
|
580
|
+
webAppUrl: t.webAppUrl || '',
|
|
581
|
+
costFooter: t.costFooter === true,
|
|
582
|
+
budgetAlertThresholdUsd: Number(t.budgetAlertThresholdUsd) || 0,
|
|
583
|
+
mediaGroupDebounceMs: Number(t.mediaGroupDebounceMs) || 650,
|
|
584
|
+
forumMirrorEnabled: t.forumMirrorEnabled === true,
|
|
585
|
+
forumMirrorChatId: t.forumMirrorChatId != null ? t.forumMirrorChatId : '',
|
|
522
586
|
notifyBridge: t.notifyBridge || { enabled: false, events: ['task_done', 'error'], home: 'default', excludeSessionPrefixes: ['msgw-'] },
|
|
523
587
|
alerts: t.alerts || { enabled: false, chatId: '', threadId: 0, home: '', events: ['error', 'pairing'] },
|
|
524
588
|
botToken: t.botToken || '',
|
|
@@ -530,13 +594,11 @@ window.__ModuleLoader__.load({
|
|
|
530
594
|
enabled: d.enabled === true,
|
|
531
595
|
botToken: d.botToken || '',
|
|
532
596
|
webhookUrl: d.webhookUrl || '',
|
|
533
|
-
allowedChannelIds: Array.isArray(d.allowedChannelIds) ? d.allowedChannelIds : [],
|
|
534
597
|
},
|
|
535
598
|
slack: {
|
|
536
599
|
enabled: sl.enabled === true,
|
|
537
600
|
botToken: sl.botToken || '',
|
|
538
601
|
webhookUrl: sl.webhookUrl || '',
|
|
539
|
-
defaultChannel: sl.defaultChannel || '',
|
|
540
602
|
},
|
|
541
603
|
agent: {
|
|
542
604
|
provider: a.provider || '',
|
|
@@ -559,6 +621,14 @@ window.__ModuleLoader__.load({
|
|
|
559
621
|
maxChars: Number(tts.maxChars) || 4000,
|
|
560
622
|
voiceSummary: tts.voiceSummary === true,
|
|
561
623
|
},
|
|
624
|
+
memory: {
|
|
625
|
+
enabled: mem.enabled !== false,
|
|
626
|
+
baseUrl: typeof mem.baseUrl === 'string' ? mem.baseUrl : '',
|
|
627
|
+
tokenEnv: mem.tokenEnv || 'MEMORY_BRAIN_TOKEN',
|
|
628
|
+
autoInject: mem.autoInject !== false,
|
|
629
|
+
budget: Number(mem.budget) || 2000,
|
|
630
|
+
timeoutMs: Number(mem.timeoutMs) || 3500,
|
|
631
|
+
},
|
|
562
632
|
}
|
|
563
633
|
}
|
|
564
634
|
|
|
@@ -571,7 +641,6 @@ window.__ModuleLoader__.load({
|
|
|
571
641
|
const [allowText, setAllowText] = React.useState('')
|
|
572
642
|
const [discordToken, setDiscordToken] = React.useState('')
|
|
573
643
|
const [slackToken, setSlackToken] = React.useState('')
|
|
574
|
-
const [discordChannelsText, setDiscordChannelsText] = React.useState('')
|
|
575
644
|
const [updateState, setUpdateState] = React.useState({
|
|
576
645
|
checking: false,
|
|
577
646
|
updating: false,
|
|
@@ -612,7 +681,6 @@ window.__ModuleLoader__.load({
|
|
|
612
681
|
if (snapStatus === 'ready' && cfg === null) {
|
|
613
682
|
setCfg(draftFromStored(stored))
|
|
614
683
|
setAllowText(idsToText(stored?.telegram?.allowedUserIds))
|
|
615
|
-
setDiscordChannelsText(idsToText(stored?.discord?.allowedChannelIds))
|
|
616
684
|
}
|
|
617
685
|
}, [snapStatus, stored, cfg])
|
|
618
686
|
|
|
@@ -752,7 +820,6 @@ window.__ModuleLoader__.load({
|
|
|
752
820
|
next.telegram.allowedUserIds = textToIds(allowText)
|
|
753
821
|
if (discordToken.trim()) next.discord = { ...next.discord, botToken: discordToken.trim() }
|
|
754
822
|
if (slackToken.trim()) next.slack = { ...next.slack, botToken: slackToken.trim() }
|
|
755
|
-
next.discord.allowedChannelIds = textToIds(discordChannelsText)
|
|
756
823
|
|
|
757
824
|
const broken = []
|
|
758
825
|
for (const key of SETTINGS_KEYS) {
|
|
@@ -1304,15 +1371,6 @@ window.__ModuleLoader__.load({
|
|
|
1304
1371
|
placeholder: 'https://discord.com/api/webhooks/...',
|
|
1305
1372
|
onChange: (e) => setCfg({ ...cfg, discord: { ...cfg.discord, webhookUrl: e.target.value } }),
|
|
1306
1373
|
})
|
|
1307
|
-
),
|
|
1308
|
-
React.createElement(Field, { label: t('discordChannels'), hint: t('discordChannelsHint') },
|
|
1309
|
-
React.createElement('textarea', {
|
|
1310
|
-
className: 'msgw-textarea',
|
|
1311
|
-
value: discordChannelsText,
|
|
1312
|
-
onChange: (e) => setDiscordChannelsText(e.target.value),
|
|
1313
|
-
rows: 2,
|
|
1314
|
-
placeholder: '123456789012345678, 987654321098765432',
|
|
1315
|
-
})
|
|
1316
1374
|
)
|
|
1317
1375
|
),
|
|
1318
1376
|
|
|
@@ -1352,14 +1410,6 @@ window.__ModuleLoader__.load({
|
|
|
1352
1410
|
placeholder: 'https://hooks.slack.com/services/...',
|
|
1353
1411
|
onChange: (e) => setCfg({ ...cfg, slack: { ...cfg.slack, webhookUrl: e.target.value } }),
|
|
1354
1412
|
})
|
|
1355
|
-
),
|
|
1356
|
-
React.createElement(Field, { label: t('slackDefaultChannel'), hint: t('slackDefaultChannelHint') },
|
|
1357
|
-
React.createElement('input', {
|
|
1358
|
-
className: 'msgw-input',
|
|
1359
|
-
value: cfg.slack?.defaultChannel || '',
|
|
1360
|
-
placeholder: '#general or C12345678',
|
|
1361
|
-
onChange: (e) => setCfg({ ...cfg, slack: { ...cfg.slack, defaultChannel: e.target.value } }),
|
|
1362
|
-
})
|
|
1363
1413
|
)
|
|
1364
1414
|
),
|
|
1365
1415
|
|
|
@@ -1570,6 +1620,138 @@ window.__ModuleLoader__.load({
|
|
|
1570
1620
|
value: Math.round((cfg.agent?.idleTimeoutMs ?? 3600000) / 1000),
|
|
1571
1621
|
onChange: (e) => setCfg({ ...cfg, agent: { ...cfg.agent, idleTimeoutMs: (Number(e.target.value) || 3600) * 1000 } }),
|
|
1572
1622
|
})
|
|
1623
|
+
),
|
|
1624
|
+
// Settings parity (issue 237): schema fields that had no UI surface.
|
|
1625
|
+
React.createElement(Field, { label: t('allowlistMode'), hint: t('allowlistModeHint') },
|
|
1626
|
+
React.createElement(
|
|
1627
|
+
'select',
|
|
1628
|
+
{
|
|
1629
|
+
className: 'msgw-select',
|
|
1630
|
+
value: cfg.telegram?.allowlistMode || 'closed',
|
|
1631
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, allowlistMode: e.target.value } }),
|
|
1632
|
+
},
|
|
1633
|
+
React.createElement('option', { value: 'closed' }, t('allowlistClosed')),
|
|
1634
|
+
React.createElement('option', { value: 'open' }, t('allowlistOpen'))
|
|
1635
|
+
)
|
|
1636
|
+
),
|
|
1637
|
+
React.createElement(Field, { label: t('defaultLocale'), hint: t('defaultLocaleHint') },
|
|
1638
|
+
React.createElement(
|
|
1639
|
+
'select',
|
|
1640
|
+
{
|
|
1641
|
+
className: 'msgw-select',
|
|
1642
|
+
value: cfg.defaultLocale || 'en',
|
|
1643
|
+
onChange: (e) => setCfg({ ...cfg, defaultLocale: e.target.value }),
|
|
1644
|
+
},
|
|
1645
|
+
React.createElement('option', { value: 'en' }, 'English'),
|
|
1646
|
+
React.createElement('option', { value: 'zh' }, '中文')
|
|
1647
|
+
)
|
|
1648
|
+
),
|
|
1649
|
+
React.createElement(Field, { label: t('approvalsSensitivity'), hint: t('approvalsSensitivityHint') },
|
|
1650
|
+
React.createElement(
|
|
1651
|
+
'select',
|
|
1652
|
+
{
|
|
1653
|
+
className: 'msgw-select',
|
|
1654
|
+
value: cfg.telegram?.approvalsSensitivity || 'mutations',
|
|
1655
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, approvalsSensitivity: e.target.value } }),
|
|
1656
|
+
},
|
|
1657
|
+
React.createElement('option', { value: 'all' }, t('sensAll')),
|
|
1658
|
+
React.createElement('option', { value: 'mutations' }, t('sensMutations')),
|
|
1659
|
+
React.createElement('option', { value: 'disabled' }, t('sensDisabled'))
|
|
1660
|
+
)
|
|
1661
|
+
),
|
|
1662
|
+
React.createElement('label', { className: 'msgw-check' },
|
|
1663
|
+
React.createElement('input', {
|
|
1664
|
+
type: 'checkbox',
|
|
1665
|
+
checked: cfg.telegram?.streaming === true,
|
|
1666
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, streaming: e.target.checked } }),
|
|
1667
|
+
}),
|
|
1668
|
+
t('streamingEnable')
|
|
1669
|
+
),
|
|
1670
|
+
React.createElement(Field, { label: t('streamEditInterval') },
|
|
1671
|
+
React.createElement('input', {
|
|
1672
|
+
type: 'number',
|
|
1673
|
+
className: 'msgw-input',
|
|
1674
|
+
min: 200,
|
|
1675
|
+
max: 10000,
|
|
1676
|
+
value: cfg.telegram?.streamEditIntervalMs ?? 1200,
|
|
1677
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, streamEditIntervalMs: Number(e.target.value) || 1200 } }),
|
|
1678
|
+
})
|
|
1679
|
+
),
|
|
1680
|
+
React.createElement(Field, { label: t('mediaGroupDebounce') },
|
|
1681
|
+
React.createElement('input', {
|
|
1682
|
+
type: 'number',
|
|
1683
|
+
className: 'msgw-input',
|
|
1684
|
+
min: 0,
|
|
1685
|
+
max: 5000,
|
|
1686
|
+
value: cfg.telegram?.mediaGroupDebounceMs ?? 650,
|
|
1687
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, mediaGroupDebounceMs: Number(e.target.value) || 650 } }),
|
|
1688
|
+
})
|
|
1689
|
+
),
|
|
1690
|
+
React.createElement('label', { className: 'msgw-check' },
|
|
1691
|
+
React.createElement('input', {
|
|
1692
|
+
type: 'checkbox',
|
|
1693
|
+
checked: cfg.telegram?.webAppEnabled !== false,
|
|
1694
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, webAppEnabled: e.target.checked } }),
|
|
1695
|
+
}),
|
|
1696
|
+
t('webAppEnabled')
|
|
1697
|
+
),
|
|
1698
|
+
React.createElement(Field, { label: t('webAppUrl'), hint: t('webAppUrlHint') },
|
|
1699
|
+
React.createElement('input', {
|
|
1700
|
+
className: 'msgw-input',
|
|
1701
|
+
value: cfg.telegram?.webAppUrl || '',
|
|
1702
|
+
placeholder: 'https://bot.example.com',
|
|
1703
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, webAppUrl: e.target.value } }),
|
|
1704
|
+
})
|
|
1705
|
+
),
|
|
1706
|
+
React.createElement('label', { className: 'msgw-check' },
|
|
1707
|
+
React.createElement('input', {
|
|
1708
|
+
type: 'checkbox',
|
|
1709
|
+
checked: cfg.telegram?.costFooter === true,
|
|
1710
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, costFooter: e.target.checked } }),
|
|
1711
|
+
}),
|
|
1712
|
+
t('costFooter')
|
|
1713
|
+
),
|
|
1714
|
+
React.createElement(Field, { label: t('budgetAlert') },
|
|
1715
|
+
React.createElement('input', {
|
|
1716
|
+
type: 'number',
|
|
1717
|
+
step: '0.5',
|
|
1718
|
+
min: 0,
|
|
1719
|
+
className: 'msgw-input',
|
|
1720
|
+
value: cfg.telegram?.budgetAlertThresholdUsd ?? 0,
|
|
1721
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, budgetAlertThresholdUsd: Number(e.target.value) || 0 } }),
|
|
1722
|
+
})
|
|
1723
|
+
),
|
|
1724
|
+
React.createElement('label', { className: 'msgw-check' },
|
|
1725
|
+
React.createElement('input', {
|
|
1726
|
+
type: 'checkbox',
|
|
1727
|
+
checked: cfg.telegram?.forumMirrorEnabled === true,
|
|
1728
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, forumMirrorEnabled: e.target.checked } }),
|
|
1729
|
+
}),
|
|
1730
|
+
t('forumMirrorEnable')
|
|
1731
|
+
),
|
|
1732
|
+
React.createElement(Field, { label: t('forumMirrorChat') },
|
|
1733
|
+
React.createElement('input', {
|
|
1734
|
+
className: 'msgw-input',
|
|
1735
|
+
value: cfg.telegram?.forumMirrorChatId || '',
|
|
1736
|
+
placeholder: '-1001234567890',
|
|
1737
|
+
onChange: (e) => setCfg({ ...cfg, telegram: { ...cfg.telegram, forumMirrorChatId: e.target.value } }),
|
|
1738
|
+
})
|
|
1739
|
+
),
|
|
1740
|
+
React.createElement('label', { className: 'msgw-check' },
|
|
1741
|
+
React.createElement('input', {
|
|
1742
|
+
type: 'checkbox',
|
|
1743
|
+
checked: cfg.memory?.enabled !== false,
|
|
1744
|
+
onChange: (e) => setCfg({ ...cfg, memory: { ...cfg.memory, enabled: e.target.checked } }),
|
|
1745
|
+
}),
|
|
1746
|
+
t('memoryEnable')
|
|
1747
|
+
),
|
|
1748
|
+
React.createElement(Field, { label: t('memoryBaseUrl'), hint: t('memoryBaseUrlHint') },
|
|
1749
|
+
React.createElement('input', {
|
|
1750
|
+
className: 'msgw-input',
|
|
1751
|
+
value: cfg.memory?.baseUrl || '',
|
|
1752
|
+
placeholder: 'http://127.0.0.1:28080',
|
|
1753
|
+
onChange: (e) => setCfg({ ...cfg, memory: { ...cfg.memory, baseUrl: e.target.value } }),
|
|
1754
|
+
})
|
|
1573
1755
|
)
|
|
1574
1756
|
) : null
|
|
1575
1757
|
),
|
package/lib/config.js
CHANGED
|
@@ -80,12 +80,8 @@ export const PluginConfig = z.object({
|
|
|
80
80
|
home: z.string().default(''),
|
|
81
81
|
events: z.array(z.string()).default(['error', 'pairing']),
|
|
82
82
|
}).default({ enabled: false }),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
chatId: z.union([z.number(), z.string()]).default(''),
|
|
86
|
-
}).default({ enabled: false }),
|
|
87
|
-
forumMirrorChatId: z.union([z.number(), z.string()]).default(''),
|
|
88
|
-
forumMirrorEnabled: z.boolean().default(false),
|
|
83
|
+
forumMirrorChatId: z.union([z.number(), z.string()]).default('').description('Mirror assistant replies of every session into this forum topic chat'),
|
|
84
|
+
forumMirrorEnabled: z.boolean().default(false).description('Mirror assistant replies into a dedicated forum topic per session'),
|
|
89
85
|
}).volatile(),
|
|
90
86
|
discord: z.object({
|
|
91
87
|
enabled: z.boolean().default(false),
|
|
@@ -141,6 +137,34 @@ export const PluginConfig = z.object({
|
|
|
141
137
|
|
|
142
138
|
export const Config = PluginConfig
|
|
143
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Transport-critical config slice (#224): adapters snapshot their options
|
|
142
|
+
* when the gateway starts, so a change in ANY of these fields requires a
|
|
143
|
+
* full gateway recreation. Everything else (tts, agent model/cwd, homes,
|
|
144
|
+
* allowlist, quick actions, security…) is applied live on the running
|
|
145
|
+
* gateway — an active dialog, streaming replies, pending asks and the
|
|
146
|
+
* Telegram polling offset are preserved.
|
|
147
|
+
*/
|
|
148
|
+
export function transportSignatureOf(cfg) {
|
|
149
|
+
return JSON.stringify({
|
|
150
|
+
enabled: cfg?.enabled,
|
|
151
|
+
sessionScope: cfg?.agent?.sessionScope,
|
|
152
|
+
telegram: {
|
|
153
|
+
enabled: cfg?.telegram?.enabled,
|
|
154
|
+
botToken: cfg?.telegram?.botToken,
|
|
155
|
+
proxyUrl: cfg?.telegram?.proxyUrl,
|
|
156
|
+
apiRoot: cfg?.telegram?.apiRoot,
|
|
157
|
+
transport: cfg?.telegram?.transport,
|
|
158
|
+
webhookUrl: cfg?.telegram?.webhookUrl,
|
|
159
|
+
webhookSecret: cfg?.telegram?.webhookSecret,
|
|
160
|
+
pollIntervalMs: cfg?.telegram?.pollIntervalMs,
|
|
161
|
+
timeoutSeconds: cfg?.telegram?.timeoutSeconds,
|
|
162
|
+
},
|
|
163
|
+
discord: { enabled: cfg?.discord?.enabled, botToken: cfg?.discord?.botToken, webhookUrl: cfg?.discord?.webhookUrl },
|
|
164
|
+
slack: { enabled: cfg?.slack?.enabled, botToken: cfg?.slack?.botToken, webhookUrl: cfg?.slack?.webhookUrl },
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
144
168
|
// Unwrap Volatile boxes before any caller reads a value. The Loader mutates the
|
|
145
169
|
// boxes in place and re-announces them with loader/volatile-update, so this must
|
|
146
170
|
// read the entry config lazily rather than caching the parsed result.
|
package/lib/forum-mirror.js
CHANGED
|
@@ -92,6 +92,7 @@ export async function mirrorSessionToForumTopic(gw, session) {
|
|
|
92
92
|
|
|
93
93
|
const tgCfg = gw.config.telegram || {}
|
|
94
94
|
if (!tgCfg.forumMirrorEnabled || !tgCfg.forumMirrorChatId) return
|
|
95
|
+
if (gw.isMuted?.(tgCfg.forumMirrorChatId)) return
|
|
95
96
|
|
|
96
97
|
const tgAdapter = gw.adapters.get('telegram')
|
|
97
98
|
if (!tgAdapter || typeof tgAdapter.createForumTopic !== 'function') return
|
|
@@ -121,6 +122,8 @@ export async function relayTurnToForumMirror(gw, session, _event) {
|
|
|
121
122
|
const threadInfo = gw.sessionToThread.get(sessionId)
|
|
122
123
|
if (!threadInfo) return
|
|
123
124
|
if (gw.pending.has(sessionId)) return
|
|
125
|
+
// Muted chat: no forum mirroring either (#231).
|
|
126
|
+
if (gw.isMuted?.(threadInfo.chatId)) return
|
|
124
127
|
|
|
125
128
|
const tgAdapter = gw.adapters.get('telegram')
|
|
126
129
|
if (!tgAdapter) return
|
package/lib/gateway.js
CHANGED
|
@@ -401,6 +401,20 @@ export class Gateway {
|
|
|
401
401
|
this.callbackIndex.clear()
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Live config swap without gateway recreation (#224). Callers (index.js
|
|
406
|
+
* sync) only route here when the transport-critical slice is unchanged, so
|
|
407
|
+
* polling, active chats and pending asks survive; adapters that snapshot
|
|
408
|
+
* safe options re-apply them from the matching config section.
|
|
409
|
+
*/
|
|
410
|
+
applyConfig(next) {
|
|
411
|
+
this.config = next
|
|
412
|
+
for (const adapter of this.adapterList) {
|
|
413
|
+
const section = next?.[adapter.name]
|
|
414
|
+
if (section && typeof adapter.applyLiveConfig === 'function') adapter.applyLiveConfig(section)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
404
418
|
getAdapter(platform) { return this.adapters.get(platform) }
|
|
405
419
|
|
|
406
420
|
async sendToMessenger(target, payload, opts = {}) {
|
|
@@ -421,6 +435,12 @@ export class Gateway {
|
|
|
421
435
|
if (!home) throw new Error('target.chatId required (or set telegram home channel)')
|
|
422
436
|
resolved = { ...home, ...resolved, chatId: home.chatId, threadId: resolved.threadId ?? home.threadId }
|
|
423
437
|
}
|
|
438
|
+
// /mute stops ALL outbound delivery to the chat (#231): notify bridge,
|
|
439
|
+
// messenger tool, HTTP sends and cron prompts all funnel through here.
|
|
440
|
+
// The interactive turn conversation (chat.reply) is unaffected.
|
|
441
|
+
if (resolved.chatId !== undefined && this.isMuted?.(resolved.chatId)) {
|
|
442
|
+
return { ok: true, muted: true }
|
|
443
|
+
}
|
|
424
444
|
const adapter = this.getAdapter(resolved.platform)
|
|
425
445
|
if (!adapter?.sendTo) throw new Error(`adapter ${resolved.platform} unavailable`)
|
|
426
446
|
try {
|