dsh-message-gateway 0.1.9 → 0.1.10
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.en.md +5 -0
- package/README.es.md +1 -0
- package/README.md +5 -0
- package/lib/index.js +32 -2
- package/lib/index.js.map +3 -3
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -16,6 +16,7 @@ A message-platform gateway plugin for the DSH Web GUI: a "Message platforms" ent
|
|
|
16
16
|
- **WhatsApp**: fill in Token + Phone Number ID, configure the webhook (`/gateway/whatsapp/webhook`) in the Meta console, and users who message get auto replies
|
|
17
17
|
- **Email**: fill in IMAP (receiving, 993/143) + SMTP (replying, 465/587/25); messages are grouped into per-thread sessions and replies use Re: original subject
|
|
18
18
|
- **Credential management**: plaintext is persisted only to `~/.dsh/gateway.json` (mode 600, atomic write); `/gateway/list` never returns credential plaintext, only a `configured` flag
|
|
19
|
+
- **Secret redaction**: message content written to logs / console is automatically masked for likely secrets (`sk-` prefixed keys, GitHub tokens, `Bearer`, `password=` assignments, PEM private keys, and other common patterns), so secrets in bot conversations never leak into log files
|
|
19
20
|
- **Connection tests**: real per-platform checks — Telegram/Discord via Bot API, QQ via access_token, WeCom via gettoken, WeChat MP via cgi-bin/token, WhatsApp via Graph API, Email via IMAP TCP banner, WeCom AI bot via the official SDK long connection (authenticated = pass)
|
|
20
21
|
- **WeCom AI bot persistent bridge**: official SDK WebSocket long connection with exponential backoff reconnect; incoming text messages are injected into an isolated dedicated agent session that wakes the DSH driver; replies stream back as chunks and finalize via `response_url`
|
|
21
22
|
- **Group-chat @mention stripping**: the leading `@bot-name` is removed before the assistant sees the message
|
|
@@ -72,6 +73,10 @@ All options have defaults and the plugin works out of the box; tune them via `ds
|
|
|
72
73
|
- **Host half** (`lib/index.js`): `/gateway/*` routes (list / save / delete / test / wechat-status) + `BridgeManager` (agent session injection and event-stream polling) + `WecomBridge` (SDK long-connection lifecycle) + `gateway-store` (credential persistence)
|
|
73
74
|
- **Client half** (`lib/client.js`): sidebar button mount + full-screen platform manager (React, loaded via the `__ModuleLoader__` closure)
|
|
74
75
|
|
|
76
|
+
## Feedback
|
|
77
|
+
|
|
78
|
+
Found a bug or have a feature request? Open an issue on [GitHub Issues](https://github.com/a792883583/dsh-message-gateway/issues) — your feedback helps us make the plugin better.
|
|
79
|
+
|
|
75
80
|
## License
|
|
76
81
|
|
|
77
82
|
MIT
|
package/README.es.md
CHANGED
|
@@ -16,6 +16,7 @@ Un plugin de pasarela de mensajería para la GUI web de DSH: una entrada "Plataf
|
|
|
16
16
|
- **WhatsApp**: rellene Token + Phone Number ID, configure el webhook (`/gateway/whatsapp/webhook`) en la consola de Meta, y los usuarios que escriban reciben respuestas automáticas
|
|
17
17
|
- **Email**: rellene IMAP (recepción, 993/143) + SMTP (respuesta, 465/587/25); los mensajes se agrupan en sesiones por hilo y las respuestas usan Re: asunto original
|
|
18
18
|
- **Gestión de credenciales**: el texto plano se guarda solo en `~/.dsh/gateway.json` (modo 600, escritura atómica); `/gateway/list` nunca devuelve credenciales, solo un marcador `configured`
|
|
19
|
+
- **Redacción de secretos**: el contenido de los mensajes escrito en registros / consola se enmascara automáticamente ante posibles secretos (claves con prefijo `sk-`, tokens de GitHub, `Bearer`, asignaciones `password=`, claves PEM privadas y otros patrones comunes), de modo que los secretos de las conversaciones del bot nunca se filtran a los archivos de registro
|
|
19
20
|
- **Pruebas de conexión**: comprobaciones reales por plataforma — Telegram/Discord vía Bot API, QQ vía access_token, WeCom vía gettoken, cuenta oficial vía cgi-bin/token, WhatsApp vía Graph API, Email vía banner TCP de IMAP, Bot de IA de WeCom vía la conexión larga del SDK oficial (autenticado = correcto)
|
|
20
21
|
- **Puente persistente del Bot de IA de WeCom**: conexión larga WebSocket del SDK oficial con reconexión por retroceso exponencial; los mensajes de texto entrantes se inyectan en una sesión de agente dedicada y aislada que despierta al controlador de DSH; las respuestas se transmiten como fragmentos y finalizan vía `response_url`
|
|
21
22
|
- **Eliminación de menciones @ en grupos**: se quita el `@nombre-del-bot` inicial antes de que el asistente vea el mensaje
|
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ DSH Web GUI 的消息平台网关插件:在侧边栏「新会话」按钮下
|
|
|
16
16
|
- **WhatsApp**:填 Token + Phone Number ID,Meta 后台配置 Webhook(`/gateway/whatsapp/webhook`)后发消息即自动对话
|
|
17
17
|
- **Email**:填 IMAP(收件,993/143)+ SMTP(回复,465/587/25),按邮件线程自动归类会话,回复用 Re: 原主题
|
|
18
18
|
- **凭据管理**:明文只落盘 `~/.dsh/gateway.json`(权限 600,原子写入),`/gateway/list` 永不回传凭据明文,只返回 configured 标记
|
|
19
|
+
- **敏感信息脱敏**:写入日志 / 控制台的消息内容自动遮蔽疑似密钥(`sk-` 前缀、GitHub token、`Bearer`、`password=` 赋值、私钥 PEM 等通用模式),机器人对话里的机密不会泄露到日志文件
|
|
19
20
|
- **连接测试**:每个平台独立的真实连接测试——Telegram/Discord 走 Bot API、QQ 走 access_token、企微走 gettoken、微信公众号走 cgi-bin/token、WhatsApp 走 Graph API、Email 走 IMAP TCP banner、企微智能机器人走官方 SDK 长连接(认证成功即通过)
|
|
20
21
|
- **企业微信智能机器人常驻桥**:官方 SDK WebSocket 长连接,断线自动指数退避重连;收到文本消息 → 注入隔离的专用 agent 会话唤醒 DSH 驱动 → 回复按 chunk 流式回发,结束时经 response_url 定稿
|
|
21
22
|
- **群聊 @提及剥离**:去掉开头的 @机器人名后交给助手
|
|
@@ -75,6 +76,10 @@ dsh plugin --profile web add dsh-message-gateway
|
|
|
75
76
|
- **host 半区**(`lib/index.js`):`/gateway/*` 路由(list / save / delete / test / wechat-status)+ `BridgeManager`(agent 会话注入与事件流轮询)+ `WecomBridge`(SDK 长连接生命周期)+ `gateway-store`(凭据存储)
|
|
76
77
|
- **client 半区**(`lib/client.js`):侧边栏按钮挂载 + 全屏平台管理页(React,经 `__ModuleLoader__` 闭包加载)
|
|
77
78
|
|
|
79
|
+
## 反馈
|
|
80
|
+
|
|
81
|
+
使用中遇到问题或有功能建议?欢迎到 [GitHub Issues](https://github.com/a792883583/dsh-message-gateway/issues) 反馈,帮助我们把插件做得更好。
|
|
82
|
+
|
|
78
83
|
## License
|
|
79
84
|
|
|
80
85
|
MIT
|
package/lib/index.js
CHANGED
|
@@ -51,6 +51,36 @@ function botText(locale, key) {
|
|
|
51
51
|
return MSGS[locale][key] ?? MSGS.zh[key] ?? key;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// src/host/sanitize.ts
|
|
55
|
+
var REDACTED = "***";
|
|
56
|
+
var PATTERNS = [
|
|
57
|
+
// OpenAI / DeepSeek / 通用 sk- 前缀密钥(sk- 后接较长字符)。
|
|
58
|
+
{ name: "sk-key", re: /\bsk-[A-Za-z0-9_-]{16,}/g },
|
|
59
|
+
// GitHub PAT。
|
|
60
|
+
{ name: "github-pat", re: /\bgh[pousr]_[A-Za-z0-9_]{20,}/g },
|
|
61
|
+
// Bearer token(请求头形式)。
|
|
62
|
+
{ name: "bearer", re: /\bBearer\s+[A-Za-z0-9._~+\/-]{20,}={0,2}/gi },
|
|
63
|
+
// 赋值形式的密钥:key=value / "key": "value" / key: value。
|
|
64
|
+
{ name: "key-assign", re: /\b(?:api[_-]?key|secret|password|passwd|token|access[_-]?token|refresh[_-]?token|client[_-]?secret|app[_-]?secret)\b\s*[=:]\s*["']?[A-Za-z0-9._~+\/-]{12,}/gi },
|
|
65
|
+
// Authorization 头。
|
|
66
|
+
{ name: "authorization", re: /\bAuthorization\s*[:=]\s*["']?[A-Za-z0-9._~+\/-]{12,}/gi },
|
|
67
|
+
// 长 base64 / 高熵字符串(>= 32 字符连续字母数字)。
|
|
68
|
+
{ name: "high-entropy", re: /[A-Za-z0-9_-]{40,}/g },
|
|
69
|
+
// 私钥 PEM 块。
|
|
70
|
+
{ name: "private-key", re: /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/g }
|
|
71
|
+
];
|
|
72
|
+
function sanitizeSecrets(text) {
|
|
73
|
+
if (typeof text !== "string" || text === "") return text;
|
|
74
|
+
let out = text;
|
|
75
|
+
for (const { re } of PATTERNS) {
|
|
76
|
+
out = out.replace(re, (match) => {
|
|
77
|
+
const keep = match.length > 12 ? match.slice(0, 4) : "";
|
|
78
|
+
return `${keep}${REDACTED}`;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
54
84
|
// src/host/wecom-bridge.ts
|
|
55
85
|
import { WSClient } from "@wecom/aibot-node-sdk";
|
|
56
86
|
var WecomBridge = class {
|
|
@@ -1783,7 +1813,7 @@ var BridgeManager = class {
|
|
|
1783
1813
|
p.heartbeat.unref?.();
|
|
1784
1814
|
}
|
|
1785
1815
|
agent.send(message, "next-turn", true);
|
|
1786
|
-
console.log("[dsh-message-gateway] sent to agent", { key: id.key, text: text.slice(0, 60), baseSeq: p.cursor });
|
|
1816
|
+
console.log("[dsh-message-gateway] sent to agent", { key: id.key, text: sanitizeSecrets(text.slice(0, 60)), baseSeq: p.cursor });
|
|
1787
1817
|
p.timer = setInterval(() => {
|
|
1788
1818
|
if (this.pendingMap.get(id.key) !== p) return;
|
|
1789
1819
|
this.pollPending(id.key, p, session);
|
|
@@ -1845,7 +1875,7 @@ var BridgeManager = class {
|
|
|
1845
1875
|
this.awaiting = { resolve: (reply) => settle(true, reply) };
|
|
1846
1876
|
try {
|
|
1847
1877
|
agent.send(message, "next-turn", true);
|
|
1848
|
-
console.log("[dsh-message-gateway] webhook sent to agent", { text: text.slice(0, 60), baseSeq: cursor });
|
|
1878
|
+
console.log("[dsh-message-gateway] webhook sent to agent", { text: sanitizeSecrets(text.slice(0, 60)), baseSeq: cursor });
|
|
1849
1879
|
} catch (error) {
|
|
1850
1880
|
console.error("[dsh-message-gateway] webhook send failed", error);
|
|
1851
1881
|
settle(false, "send failed");
|