dsh-message-gateway 0.1.26 → 0.1.28
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 +2 -0
- package/README.es.md +2 -0
- package/README.md +2 -0
- package/lib/index.js +65 -16
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -38,6 +38,8 @@ A message-platform gateway plugin for the DSH Web GUI: a "Message platforms" ent
|
|
|
38
38
|
- **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
|
|
39
39
|
- **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)
|
|
40
40
|
- **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`
|
|
41
|
+
- **Multi-step stream accumulation without overwrite**: in multi-step/complex agent tasks, earlier reasoning paragraphs are accumulated cleanly without being overwritten by later outputs; intermediate pauses display a dynamic status hint (`⏳ Processing, please wait…`) which is stripped upon completion
|
|
42
|
+
- **Graceful shutdown & instant reconnect**: catches process termination signals to perform proper handshake disconnects across all platforms, eliminating 30-second zombie connection timeouts and allowing re-connections in 1–2 seconds
|
|
41
43
|
- **Group-chat @mention stripping**: the leading `@bot-name` is removed before the assistant sees the message
|
|
42
44
|
- **Slash commands**: `/help` / `/time` / `/status` / `/stats` (Chinese aliases: 帮助/菜单/时间/状态/统计)
|
|
43
45
|
- **Enter-chat welcome**: optional configuration (`welcomeReply`, defaults to `false` for zero disturbance; when set to `true`, auto-replies a greeting when a user enters single chat for the first time that day)
|
package/README.es.md
CHANGED
|
@@ -38,6 +38,8 @@ Un plugin de pasarela de mensajería para la GUI web de DSH: una entrada "Plataf
|
|
|
38
38
|
- **Redacción de secretos**: el contenido de los mensajes escrito en registros / consola se enmascara automáticamente ante posibles secretos
|
|
39
39
|
- **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
|
|
40
40
|
- **Puente persistente del Bot de IA de WeCom**: conexión larga WebSocket del SDK oficial con reconexión por retroceso exponencial
|
|
41
|
+
- **Acumulación de flujo multietapa sin sobrescritura**: en tareas complejas de múltiples pasos, las conclusiones y pensamientos anteriores se conservan limpiamente sin ser reemplazados; las pausas muestran un indicador de estado dinámico (`⏳ Procesando, por favor espere…`) que se retira al finalizar
|
|
42
|
+
- **Cierre ordenado y reconexión inmediata**: captura las señales de apagado del sistema para cerrar las conexiones formalmente, eliminando los bloqueos por espera de 30 segundos y reconectando en 1–2 segundos
|
|
41
43
|
- **Eliminación de menciones @ en grupos**
|
|
42
44
|
- **Comandos de barra**: `/help` / `/time` / `/status` / `/stats`
|
|
43
45
|
- **Mensaje de bienvenida opcional**
|
package/README.md
CHANGED
|
@@ -38,6 +38,8 @@ DSH Web GUI 的消息平台网关插件:在侧边栏「新会话」按钮下
|
|
|
38
38
|
- **敏感信息脱敏**:写入日志 / 控制台的消息内容自动遮蔽疑似密钥(`sk-` 前缀、GitHub token、`Bearer`、`password=` 赋值、私钥 PEM 等通用模式),机器人对话里的机密不会泄露到日志文件
|
|
39
39
|
- **连接测试**:每个平台独立的真实连接测试——Telegram/Discord 走 Bot API、QQ 走 access_token、企微走 gettoken、微信公众号走 cgi-bin/token、WhatsApp 走 Graph API、Email 走 IMAP TCP banner、企微智能机器人走官方 SDK 长连接(认证成功即通过)
|
|
40
40
|
- **企业微信智能机器人常驻桥**:官方 SDK WebSocket 长连接,断线自动指数退避重连;收到文本消息 → 注入隔离的专用 agent 会话唤醒 DSH 驱动 → 回复按 chunk 流式回发,结束时经 response_url 定稿
|
|
41
|
+
- **多步骤流式聚合与防覆盖**:在多步骤/复杂工具调用任务中,自动按步骤段落累加保留历史思考与分析过程,绝不冲刷覆盖前文;中间步骤停顿时智能呈现三语动态处理提示(`⏳ 正在处理中,请稍候…`),定稿收官时自动无痕剥离
|
|
42
|
+
- **全平台优雅关机与秒速重连**:系统级监听退出信号并主动向远端服务发送断开握手,杜绝 30 秒连接排队超时锁,服务重启后 1~2 秒内秒速上线
|
|
41
43
|
- **群聊 @提及剥离**:去掉开头的 @机器人名后交给助手
|
|
42
44
|
- **斜杠命令**:`/help` / `/time` / `/status`(含中文别名:帮助/菜单/时间/状态)
|
|
43
45
|
- **进入会话欢迎语**:可选配置(配置项 `welcomeReply`,默认 `false` 保持免打扰,开启后用户当天首次进入单聊自动回复欢迎词)
|
package/lib/index.js
CHANGED
|
@@ -73,7 +73,8 @@ var MSGS = {
|
|
|
73
73
|
statusTime: "\u65F6\u95F4",
|
|
74
74
|
statusAvailable: "\u53EF\u7528",
|
|
75
75
|
statusUnavailable: "\u4E0D\u53EF\u7528",
|
|
76
|
-
timePrefix: "\u{1F550}"
|
|
76
|
+
timePrefix: "\u{1F550}",
|
|
77
|
+
stepLoading: "\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019\u2026"
|
|
77
78
|
},
|
|
78
79
|
en: {
|
|
79
80
|
ack: "Processing\u2026",
|
|
@@ -93,7 +94,29 @@ var MSGS = {
|
|
|
93
94
|
statusTime: "Time",
|
|
94
95
|
statusAvailable: "available",
|
|
95
96
|
statusUnavailable: "unavailable",
|
|
96
|
-
timePrefix: "\u{1F550}"
|
|
97
|
+
timePrefix: "\u{1F550}",
|
|
98
|
+
stepLoading: "\u23F3 Processing, please wait\u2026"
|
|
99
|
+
},
|
|
100
|
+
es: {
|
|
101
|
+
ack: "Procesando\u2026",
|
|
102
|
+
busy: "\u23F3 Todav\xEDa se est\xE1 procesando su mensaje anterior, por favor espere",
|
|
103
|
+
noAgent: "\u26A0\uFE0F El asistente de DSH no est\xE1 disponible en este momento",
|
|
104
|
+
welcome: "\xA1Hola! Soy su asistente de IA \u{1F916}\n\n- Chatea conmigo directamente\n- Cada chat tiene su propia sesi\xF3n con compresi\xF3n autom\xE1tica\n- Escriba /help para ver los comandos",
|
|
105
|
+
help: "\u{1F916} **Comandos del Asistente**\n- Enviar mensaje \u2192 Chat con IA\n- `/new` o `/clear` \u2192 Iniciar nueva sesi\xF3n\n- `/time` \u2192 Hora actual\n- `/status` \u2192 Estado del bot\n- `/help` \u2192 Ayuda",
|
|
106
|
+
newOk: "\u2705 Nueva sesi\xF3n iniciada, contexto anterior borrado",
|
|
107
|
+
newIdle: "\u2139\uFE0F Este chat ya tiene una sesi\xF3n limpia",
|
|
108
|
+
timeout: "\u26A0\uFE0F Se agot\xF3 el tiempo de espera, intente de nuevo",
|
|
109
|
+
statusTitle: "\u{1F4E1} **Estado del Bot**",
|
|
110
|
+
statusOnline: "\u2705 En l\xEDnea",
|
|
111
|
+
statusOffline: "\u274C Desconectado",
|
|
112
|
+
statusBotId: "ID del Bot",
|
|
113
|
+
statusChats: "Chats activos",
|
|
114
|
+
statusAgent: "Asistente DSH",
|
|
115
|
+
statusTime: "Hora",
|
|
116
|
+
statusAvailable: "disponible",
|
|
117
|
+
statusUnavailable: "no disponible",
|
|
118
|
+
timePrefix: "\u{1F550}",
|
|
119
|
+
stepLoading: "\u23F3 Procesando, por favor espere\u2026"
|
|
97
120
|
}
|
|
98
121
|
};
|
|
99
122
|
function botText(locale, key) {
|
|
@@ -1896,8 +1919,9 @@ var BridgeManager = class {
|
|
|
1896
1919
|
}
|
|
1897
1920
|
/** 轮询注入会话的事件流:chunk → 流式推送;assistant/message → 定稿 + HTTP。 */
|
|
1898
1921
|
pollPending(key, p, session) {
|
|
1899
|
-
if (!session
|
|
1900
|
-
const events = session.events;
|
|
1922
|
+
if (!session) return;
|
|
1923
|
+
const events = typeof session.snapshotEvents === "function" ? session.snapshotEvents() : Array.isArray(session.events) ? session.events : [];
|
|
1924
|
+
if (!Array.isArray(events)) return;
|
|
1901
1925
|
try {
|
|
1902
1926
|
for (let i = p.cursor; i < events.length; i += 1) {
|
|
1903
1927
|
p.cursor = i + 1;
|
|
@@ -1906,7 +1930,8 @@ var BridgeManager = class {
|
|
|
1906
1930
|
if (event.type === "assistant/chunk") {
|
|
1907
1931
|
const chunk = event.data?.chunk;
|
|
1908
1932
|
if (chunk && chunk.type === "text-delta" && typeof chunk.text === "string") {
|
|
1909
|
-
p.
|
|
1933
|
+
p.currentStepBuffer += chunk.text;
|
|
1934
|
+
p.buffer = [...p.stepMessages, p.currentStepBuffer].filter(Boolean).join("\n\n");
|
|
1910
1935
|
this.scheduleStream(p);
|
|
1911
1936
|
}
|
|
1912
1937
|
continue;
|
|
@@ -1914,17 +1939,20 @@ var BridgeManager = class {
|
|
|
1914
1939
|
if (event.type === "assistant/message") {
|
|
1915
1940
|
const text = extractText(event.data?.message);
|
|
1916
1941
|
if (text === "" || isToolCallOnly(text)) continue;
|
|
1917
|
-
p.
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
this.
|
|
1923
|
-
|
|
1942
|
+
if (!p.stepMessages.includes(text)) {
|
|
1943
|
+
p.stepMessages.push(text);
|
|
1944
|
+
}
|
|
1945
|
+
p.currentStepBuffer = "";
|
|
1946
|
+
p.buffer = p.stepMessages.join("\n\n");
|
|
1947
|
+
this.scheduleStream(p);
|
|
1948
|
+
continue;
|
|
1924
1949
|
}
|
|
1925
1950
|
if (event.type === "turn/end") {
|
|
1951
|
+
p.buffer = [...p.stepMessages, p.currentStepBuffer].filter(Boolean).join("\n\n");
|
|
1926
1952
|
if (p.buffer !== "") {
|
|
1953
|
+
console.log("[dsh-message-gateway] turn fully ended", { key, steps: p.stepMessages.length, totalLen: p.buffer.length });
|
|
1927
1954
|
void this.pushStream(p, true);
|
|
1955
|
+
void this.deliverHttp(p, p.pushed);
|
|
1928
1956
|
this.finishPending(key);
|
|
1929
1957
|
return;
|
|
1930
1958
|
}
|
|
@@ -1944,8 +1972,15 @@ var BridgeManager = class {
|
|
|
1944
1972
|
if (!finish && p.lastPush !== 0 && now - p.lastPush < STREAM_PUSH_INTERVAL) return;
|
|
1945
1973
|
p.lastPush = now;
|
|
1946
1974
|
p.pushed = true;
|
|
1947
|
-
|
|
1948
|
-
|
|
1975
|
+
let outputText = p.buffer;
|
|
1976
|
+
if (!finish && p.buffer !== "") {
|
|
1977
|
+
const loadingHint = this.t("stepLoading");
|
|
1978
|
+
outputText = `${p.buffer}
|
|
1979
|
+
|
|
1980
|
+
*${loadingHint}*`;
|
|
1981
|
+
}
|
|
1982
|
+
console.log("[dsh-message-gateway] stream push", { finish, len: outputText.length });
|
|
1983
|
+
p.sink.stream(p.frame, p.streamId, outputText, finish);
|
|
1949
1984
|
}
|
|
1950
1985
|
/** 经平台 HTTP 定稿通道发送完整回复(幂等;流式已投递时不重复发)。 */
|
|
1951
1986
|
async deliverHttp(p, streamed) {
|
|
@@ -2143,6 +2178,8 @@ var BridgeManager = class {
|
|
|
2143
2178
|
sink: id.sink,
|
|
2144
2179
|
streamId: `gw-${Date.now().toString(36)}`,
|
|
2145
2180
|
buffer: "",
|
|
2181
|
+
stepMessages: [],
|
|
2182
|
+
currentStepBuffer: "",
|
|
2146
2183
|
cursor: session.seq,
|
|
2147
2184
|
timer: null,
|
|
2148
2185
|
fallback: null,
|
|
@@ -2216,7 +2253,7 @@ var BridgeManager = class {
|
|
|
2216
2253
|
clearInterval(poll);
|
|
2217
2254
|
return;
|
|
2218
2255
|
}
|
|
2219
|
-
const events = session.events;
|
|
2256
|
+
const events = typeof session.snapshotEvents === "function" ? session.snapshotEvents() : Array.isArray(session.events) ? session.events : [];
|
|
2220
2257
|
for (let i = cursor; i < events.length; i += 1) {
|
|
2221
2258
|
const event = events[i];
|
|
2222
2259
|
if (event.type === "assistant/message") {
|
|
@@ -3832,7 +3869,7 @@ function registerGatewayRoutes(ctx, manager) {
|
|
|
3832
3869
|
// src/core/config.ts
|
|
3833
3870
|
import Schema from "@deepseek-ai/schemastery";
|
|
3834
3871
|
var Config = Schema.object({
|
|
3835
|
-
botLocale: Schema.union(["zh", "en"]).default("zh").description("\u673A\u5668\u4EBA\u56DE\u590D\u8BED\u8A00\uFF08zh \u4E2D\u6587 / en English\uFF09"),
|
|
3872
|
+
botLocale: Schema.union(["zh", "en", "es"]).default("zh").description("\u673A\u5668\u4EBA\u56DE\u590D\u8BED\u8A00\uFF08zh \u4E2D\u6587 / en English / es Espa\xF1ol\uFF09"),
|
|
3836
3873
|
maxChatAgents: Schema.natural().min(1).max(200).default(40).description("\u6BCF\u4E2A\u673A\u5668\u4EBA\u6700\u591A\u4FDD\u7559\u7684\u804A\u5929\u4F1A\u8BDD\u6570\uFF0C\u8D85\u51FA\u81EA\u52A8\u6DD8\u6C70\u6700\u65E7\u4F1A\u8BDD"),
|
|
3837
3874
|
botModel: Schema.object({
|
|
3838
3875
|
provider: Schema.string().required().description("\u6A21\u578B\u4F9B\u5E94\u5546\uFF08\u5982 pipio / opencode-go\uFF09"),
|
|
@@ -4038,7 +4075,19 @@ function apply(ctx, config = Config({})) {
|
|
|
4038
4075
|
disposeSmartsheet();
|
|
4039
4076
|
};
|
|
4040
4077
|
}
|
|
4078
|
+
const onShutdown = () => {
|
|
4079
|
+
try {
|
|
4080
|
+
void manager.dispose();
|
|
4081
|
+
} catch {
|
|
4082
|
+
}
|
|
4083
|
+
};
|
|
4084
|
+
process.once("SIGTERM", onShutdown);
|
|
4085
|
+
process.once("SIGINT", onShutdown);
|
|
4086
|
+
process.once("beforeExit", onShutdown);
|
|
4041
4087
|
return () => {
|
|
4088
|
+
process.off("SIGTERM", onShutdown);
|
|
4089
|
+
process.off("SIGINT", onShutdown);
|
|
4090
|
+
process.off("beforeExit", onShutdown);
|
|
4042
4091
|
disposeTools?.();
|
|
4043
4092
|
disposeRoutes();
|
|
4044
4093
|
void manager.dispose();
|