dsh-message-gateway 0.1.27 → 0.1.29
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 +87 -15
- 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) {
|
|
@@ -1904,10 +1927,21 @@ var BridgeManager = class {
|
|
|
1904
1927
|
p.cursor = i + 1;
|
|
1905
1928
|
const event = events[i];
|
|
1906
1929
|
if (!event) continue;
|
|
1930
|
+
if (p.fallback !== null) {
|
|
1931
|
+
clearTimeout(p.fallback);
|
|
1932
|
+
p.fallback = setTimeout(() => {
|
|
1933
|
+
if (this.pendingMap.get(key) === p) {
|
|
1934
|
+
console.warn("[dsh-message-gateway] idle timeout (no events for 90s)", { key });
|
|
1935
|
+
this.finishPending(key);
|
|
1936
|
+
}
|
|
1937
|
+
}, 90 * 1e3);
|
|
1938
|
+
p.fallback.unref?.();
|
|
1939
|
+
}
|
|
1907
1940
|
if (event.type === "assistant/chunk") {
|
|
1908
1941
|
const chunk = event.data?.chunk;
|
|
1909
1942
|
if (chunk && chunk.type === "text-delta" && typeof chunk.text === "string") {
|
|
1910
|
-
p.
|
|
1943
|
+
p.currentStepBuffer += chunk.text;
|
|
1944
|
+
p.buffer = [...p.stepMessages, p.currentStepBuffer].filter(Boolean).join("\n\n");
|
|
1911
1945
|
this.scheduleStream(p);
|
|
1912
1946
|
}
|
|
1913
1947
|
continue;
|
|
@@ -1915,17 +1949,26 @@ var BridgeManager = class {
|
|
|
1915
1949
|
if (event.type === "assistant/message") {
|
|
1916
1950
|
const text = extractText(event.data?.message);
|
|
1917
1951
|
if (text === "" || isToolCallOnly(text)) continue;
|
|
1918
|
-
p.
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
this.
|
|
1924
|
-
|
|
1952
|
+
if (!p.stepMessages.includes(text)) {
|
|
1953
|
+
p.stepMessages.push(text);
|
|
1954
|
+
}
|
|
1955
|
+
p.currentStepBuffer = "";
|
|
1956
|
+
p.buffer = p.stepMessages.join("\n\n");
|
|
1957
|
+
this.scheduleStream(p);
|
|
1958
|
+
continue;
|
|
1925
1959
|
}
|
|
1926
1960
|
if (event.type === "turn/end") {
|
|
1961
|
+
if (p.currentStepBuffer.trim()) {
|
|
1962
|
+
if (!p.stepMessages.includes(p.currentStepBuffer.trim())) {
|
|
1963
|
+
p.stepMessages.push(p.currentStepBuffer.trim());
|
|
1964
|
+
}
|
|
1965
|
+
p.currentStepBuffer = "";
|
|
1966
|
+
}
|
|
1967
|
+
p.buffer = p.stepMessages.filter(Boolean).join("\n\n");
|
|
1927
1968
|
if (p.buffer !== "") {
|
|
1969
|
+
console.log("[dsh-message-gateway] turn fully ended", { key, steps: p.stepMessages.length, totalLen: p.buffer.length });
|
|
1928
1970
|
void this.pushStream(p, true);
|
|
1971
|
+
void this.deliverHttp(p, p.pushed);
|
|
1929
1972
|
this.finishPending(key);
|
|
1930
1973
|
return;
|
|
1931
1974
|
}
|
|
@@ -1945,8 +1988,15 @@ var BridgeManager = class {
|
|
|
1945
1988
|
if (!finish && p.lastPush !== 0 && now - p.lastPush < STREAM_PUSH_INTERVAL) return;
|
|
1946
1989
|
p.lastPush = now;
|
|
1947
1990
|
p.pushed = true;
|
|
1948
|
-
|
|
1949
|
-
|
|
1991
|
+
let outputText = p.buffer;
|
|
1992
|
+
if (!finish && p.buffer !== "") {
|
|
1993
|
+
const loadingHint = this.t("stepLoading");
|
|
1994
|
+
outputText = `${p.buffer}
|
|
1995
|
+
|
|
1996
|
+
*${loadingHint}*`;
|
|
1997
|
+
}
|
|
1998
|
+
console.log("[dsh-message-gateway] stream push", { finish, len: outputText.length });
|
|
1999
|
+
p.sink.stream(p.frame, p.streamId, outputText, finish);
|
|
1950
2000
|
}
|
|
1951
2001
|
/** 经平台 HTTP 定稿通道发送完整回复(幂等;流式已投递时不重复发)。 */
|
|
1952
2002
|
async deliverHttp(p, streamed) {
|
|
@@ -2053,6 +2103,11 @@ var BridgeManager = class {
|
|
|
2053
2103
|
}
|
|
2054
2104
|
});
|
|
2055
2105
|
this.agents.set(sessionKey, { agent: handle.agent, dispose: () => handle.dispose() });
|
|
2106
|
+
try {
|
|
2107
|
+
handle.agent.session.append("approval/policy", { policy: "never" });
|
|
2108
|
+
} catch (e) {
|
|
2109
|
+
console.warn("[dsh-message-gateway] set approval policy failed", e);
|
|
2110
|
+
}
|
|
2056
2111
|
console.log("[dsh-message-gateway] dedicated agent ready", { key: sessionKey, session: handle.agent.session.id, provider, model, preset: route?.agentPreset ?? "(default)", skill: route?.skill ?? void 0 });
|
|
2057
2112
|
return handle.agent;
|
|
2058
2113
|
} catch (error) {
|
|
@@ -2144,6 +2199,8 @@ var BridgeManager = class {
|
|
|
2144
2199
|
sink: id.sink,
|
|
2145
2200
|
streamId: `gw-${Date.now().toString(36)}`,
|
|
2146
2201
|
buffer: "",
|
|
2202
|
+
stepMessages: [],
|
|
2203
|
+
currentStepBuffer: "",
|
|
2147
2204
|
cursor: session.seq,
|
|
2148
2205
|
timer: null,
|
|
2149
2206
|
fallback: null,
|
|
@@ -2176,8 +2233,11 @@ var BridgeManager = class {
|
|
|
2176
2233
|
}
|
|
2177
2234
|
}, 400);
|
|
2178
2235
|
p.fallback = setTimeout(() => {
|
|
2179
|
-
if (this.pendingMap.get(id.key) === p)
|
|
2180
|
-
|
|
2236
|
+
if (this.pendingMap.get(id.key) === p) {
|
|
2237
|
+
console.warn("[dsh-message-gateway] initial idle timeout (90s silent)", { key: id.key });
|
|
2238
|
+
this.finishPending(id.key);
|
|
2239
|
+
}
|
|
2240
|
+
}, 90 * 1e3);
|
|
2181
2241
|
p.fallback.unref?.();
|
|
2182
2242
|
} catch (error) {
|
|
2183
2243
|
console.error("[dsh-message-gateway] handleExternalMessage failed", error);
|
|
@@ -3833,7 +3893,7 @@ function registerGatewayRoutes(ctx, manager) {
|
|
|
3833
3893
|
// src/core/config.ts
|
|
3834
3894
|
import Schema from "@deepseek-ai/schemastery";
|
|
3835
3895
|
var Config = Schema.object({
|
|
3836
|
-
botLocale: Schema.union(["zh", "en"]).default("zh").description("\u673A\u5668\u4EBA\u56DE\u590D\u8BED\u8A00\uFF08zh \u4E2D\u6587 / en English\uFF09"),
|
|
3896
|
+
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"),
|
|
3837
3897
|
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"),
|
|
3838
3898
|
botModel: Schema.object({
|
|
3839
3899
|
provider: Schema.string().required().description("\u6A21\u578B\u4F9B\u5E94\u5546\uFF08\u5982 pipio / opencode-go\uFF09"),
|
|
@@ -4039,7 +4099,19 @@ function apply(ctx, config = Config({})) {
|
|
|
4039
4099
|
disposeSmartsheet();
|
|
4040
4100
|
};
|
|
4041
4101
|
}
|
|
4102
|
+
const onShutdown = () => {
|
|
4103
|
+
try {
|
|
4104
|
+
void manager.dispose();
|
|
4105
|
+
} catch {
|
|
4106
|
+
}
|
|
4107
|
+
};
|
|
4108
|
+
process.once("SIGTERM", onShutdown);
|
|
4109
|
+
process.once("SIGINT", onShutdown);
|
|
4110
|
+
process.once("beforeExit", onShutdown);
|
|
4042
4111
|
return () => {
|
|
4112
|
+
process.off("SIGTERM", onShutdown);
|
|
4113
|
+
process.off("SIGINT", onShutdown);
|
|
4114
|
+
process.off("beforeExit", onShutdown);
|
|
4043
4115
|
disposeTools?.();
|
|
4044
4116
|
disposeRoutes();
|
|
4045
4117
|
void manager.dispose();
|