dsh-message-gateway 0.1.24 → 0.1.26
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/LICENSE +21 -21
- package/README.en.md +95 -95
- package/README.es.md +95 -95
- package/README.md +100 -100
- package/cordis.patch.yml +5 -5
- package/docs/architecture.md +130 -130
- package/docs/webhooks.md +80 -80
- package/docs/wechaty-gateway.md +65 -65
- package/lib/client.js.map +1 -1
- package/lib/index.js +39 -27
- package/lib/index.js.map +2 -2
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -1896,36 +1896,42 @@ var BridgeManager = class {
|
|
|
1896
1896
|
}
|
|
1897
1897
|
/** 轮询注入会话的事件流:chunk → 流式推送;assistant/message → 定稿 + HTTP。 */
|
|
1898
1898
|
pollPending(key, p, session) {
|
|
1899
|
+
if (!session || !Array.isArray(session.events)) return;
|
|
1899
1900
|
const events = session.events;
|
|
1900
|
-
|
|
1901
|
-
p.cursor
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
if (
|
|
1906
|
-
|
|
1907
|
-
|
|
1901
|
+
try {
|
|
1902
|
+
for (let i = p.cursor; i < events.length; i += 1) {
|
|
1903
|
+
p.cursor = i + 1;
|
|
1904
|
+
const event = events[i];
|
|
1905
|
+
if (!event) continue;
|
|
1906
|
+
if (event.type === "assistant/chunk") {
|
|
1907
|
+
const chunk = event.data?.chunk;
|
|
1908
|
+
if (chunk && chunk.type === "text-delta" && typeof chunk.text === "string") {
|
|
1909
|
+
p.buffer += chunk.text;
|
|
1910
|
+
this.scheduleStream(p);
|
|
1911
|
+
}
|
|
1912
|
+
continue;
|
|
1908
1913
|
}
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
const streamed = p.pushed;
|
|
1916
|
-
console.log("[dsh-message-gateway] assistant done", { key, seq: event.seq, len: p.buffer.length });
|
|
1917
|
-
void this.pushStream(p, true);
|
|
1918
|
-
void this.deliverHttp(p, streamed);
|
|
1919
|
-
this.finishPending(key);
|
|
1920
|
-
return;
|
|
1921
|
-
}
|
|
1922
|
-
if (event.type === "turn/end") {
|
|
1923
|
-
if (p.buffer !== "") {
|
|
1914
|
+
if (event.type === "assistant/message") {
|
|
1915
|
+
const text = extractText(event.data?.message);
|
|
1916
|
+
if (text === "" || isToolCallOnly(text)) continue;
|
|
1917
|
+
p.buffer = text;
|
|
1918
|
+
const streamed = p.pushed;
|
|
1919
|
+
console.log("[dsh-message-gateway] assistant done", { key, seq: event.seq, len: p.buffer.length });
|
|
1924
1920
|
void this.pushStream(p, true);
|
|
1921
|
+
void this.deliverHttp(p, streamed);
|
|
1925
1922
|
this.finishPending(key);
|
|
1926
1923
|
return;
|
|
1927
1924
|
}
|
|
1925
|
+
if (event.type === "turn/end") {
|
|
1926
|
+
if (p.buffer !== "") {
|
|
1927
|
+
void this.pushStream(p, true);
|
|
1928
|
+
this.finishPending(key);
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1928
1932
|
}
|
|
1933
|
+
} catch (err) {
|
|
1934
|
+
console.error("[dsh-message-gateway] pollPending error", err);
|
|
1929
1935
|
}
|
|
1930
1936
|
}
|
|
1931
1937
|
/** 流式推送:随轮询节奏(每 400ms 一次)全量更新,避免高频发送。 */
|
|
@@ -2161,8 +2167,12 @@ var BridgeManager = class {
|
|
|
2161
2167
|
agent.send(message, "next-turn", true);
|
|
2162
2168
|
console.log("[dsh-message-gateway] sent to agent", { key: id.key, text: sanitizeSecrets(text.slice(0, 60)), baseSeq: p.cursor });
|
|
2163
2169
|
p.timer = setInterval(() => {
|
|
2164
|
-
|
|
2165
|
-
|
|
2170
|
+
try {
|
|
2171
|
+
if (this.pendingMap.get(id.key) !== p) return;
|
|
2172
|
+
this.pollPending(id.key, p, session);
|
|
2173
|
+
} catch (pollErr) {
|
|
2174
|
+
console.error("[dsh-message-gateway] timer pollPending caught error", pollErr);
|
|
2175
|
+
}
|
|
2166
2176
|
}, 400);
|
|
2167
2177
|
p.fallback = setTimeout(() => {
|
|
2168
2178
|
if (this.pendingMap.get(id.key) === p) this.finishPending(id.key);
|
|
@@ -4002,10 +4012,12 @@ function apply(ctx, config = Config({})) {
|
|
|
4002
4012
|
if (!wecomCred || !wecomCred.secret && !wecomCred.corpId && !wecomCred.botId) {
|
|
4003
4013
|
return "\u9519\u8BEF\uFF1A\u672A\u5728\u6D88\u606F\u5E73\u53F0\u4E2D\u914D\u7F6E\u4F01\u4E1A\u5FAE\u4FE1\u51ED\u636E\uFF0C\u8BF7\u5148\u5728\u4FA7\u8FB9\u680F\u300C\u6D88\u606F\u5E73\u53F0\u300D\u4E2D\u914D\u7F6E\u4F01\u4E1A\u5FAE\u4FE1\u667A\u80FD\u673A\u5668\u4EBA\u6216\u81EA\u5EFA\u5E94\u7528\u51ED\u636E";
|
|
4004
4014
|
}
|
|
4015
|
+
if (!wecomCred.botId || !wecomCred.secret) {
|
|
4016
|
+
return "\u9519\u8BEF\uFF1A\u521B\u5EFA\u4F01\u4E1A\u5FAE\u4FE1\u667A\u80FD\u8868\u683C\u9700\u8981\u4F7F\u7528\u667A\u80FD\u673A\u5668\u4EBA\u51ED\u636E\uFF08botId + secret\uFF09\uFF0C\u5F53\u524D\u4EC5\u914D\u7F6E\u4E86\u81EA\u5EFA\u5E94\u7528\u51ED\u636E\uFF0C\u6682\u4E0D\u652F\u6301";
|
|
4017
|
+
}
|
|
4005
4018
|
const client = new WecomSmartsheetClient({
|
|
4006
4019
|
botId: wecomCred.botId,
|
|
4007
|
-
secret: wecomCred.secret
|
|
4008
|
-
corpId: wecomCred.corpId
|
|
4020
|
+
secret: wecomCred.secret
|
|
4009
4021
|
});
|
|
4010
4022
|
const res = await client.createSmartsheet({
|
|
4011
4023
|
title,
|