koishi-plugin-dify-ai 0.1.14 → 0.1.15
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/lib/config.d.ts +1 -0
- package/lib/index.js +23 -5
- package/lib/locales/en-US.d.ts +3 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/utils/errors.d.ts +2 -0
- package/package.json +1 -1
package/lib/config.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -34,6 +34,9 @@ var zh_CN_default = {
|
|
|
34
34
|
commands: {
|
|
35
35
|
"conv-empty": "当前频道没有 Dify 会话绑定。",
|
|
36
36
|
"conv-reset": "已重置 {0} 条会话绑定。"
|
|
37
|
+
},
|
|
38
|
+
errors: {
|
|
39
|
+
"request-failed": "Dify 请求失败:{0}"
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
};
|
|
@@ -44,6 +47,9 @@ var en_US_default = {
|
|
|
44
47
|
commands: {
|
|
45
48
|
"conv-empty": "No Dify conversation bindings in this channel.",
|
|
46
49
|
"conv-reset": "Reset {0} conversation binding(s)."
|
|
50
|
+
},
|
|
51
|
+
errors: {
|
|
52
|
+
"request-failed": "Dify request failed: {0}"
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
};
|
|
@@ -250,6 +256,7 @@ var Config = import_koishi.Schema.intersect([
|
|
|
250
256
|
requestTimeout: import_koishi.Schema.natural().role("ms").default(3e5).description("请求超时"),
|
|
251
257
|
historyLimit: import_koishi.Schema.natural().default(20).min(1).description("历史消息条数"),
|
|
252
258
|
sendErrors: import_koishi.Schema.boolean().default(false).description("失败时提示错误"),
|
|
259
|
+
debugLogging: import_koishi.Schema.boolean().default(false).description("输出错误调试日志"),
|
|
253
260
|
cooldown: cooldownSchema.default({ mode: "off" }).description("触发后冷却")
|
|
254
261
|
}).description("运行参数")
|
|
255
262
|
]);
|
|
@@ -1262,6 +1269,7 @@ var TriggerEngine = class {
|
|
|
1262
1269
|
this.cooldown.begin(channelKey, ruleName, lane, Date.now());
|
|
1263
1270
|
}
|
|
1264
1271
|
fireMessage(rule, session, condition, entry) {
|
|
1272
|
+
const queryText = entry ? formatHistoryEntry(entry) : "";
|
|
1265
1273
|
if (entry) entry.replied = true;
|
|
1266
1274
|
this.beginCooldown(channelKeyOf(session.platform, session.channelId), rule.name, "message");
|
|
1267
1275
|
this.run({
|
|
@@ -1270,7 +1278,7 @@ var TriggerEngine = class {
|
|
|
1270
1278
|
triggerType: condition.type,
|
|
1271
1279
|
rule,
|
|
1272
1280
|
// query 为该条消息的统一格式单行;纯 @ / 纯引用等无文本消息 entry 为空,由请求器占位兜底
|
|
1273
|
-
queryText
|
|
1281
|
+
queryText,
|
|
1274
1282
|
contentText: condition.contentText
|
|
1275
1283
|
});
|
|
1276
1284
|
}
|
|
@@ -1286,12 +1294,12 @@ var TriggerEngine = class {
|
|
|
1286
1294
|
}
|
|
1287
1295
|
/** 冷却到期:把缓冲内的触发消息合并为一次触发,session 取首条(供投递与文件上传) */
|
|
1288
1296
|
fireMerged(rule, buffer) {
|
|
1297
|
+
const queryText = joinNonEmpty(buffer.map((item) => item.entry ? formatHistoryEntry(item.entry) : ""));
|
|
1298
|
+
const contentText = joinNonEmpty(buffer.map((item) => item.contentText));
|
|
1289
1299
|
for (const item of buffer) {
|
|
1290
1300
|
if (item.entry) item.entry.replied = true;
|
|
1291
1301
|
}
|
|
1292
1302
|
const first = buffer[0];
|
|
1293
|
-
const queryText = joinNonEmpty(buffer.map((item) => item.entry ? formatHistoryEntry(item.entry) : ""));
|
|
1294
|
-
const contentText = joinNonEmpty(buffer.map((item) => item.contentText));
|
|
1295
1303
|
this.beginCooldown(channelKeyOf(first.session.platform, first.session.channelId), rule.name, "message");
|
|
1296
1304
|
this.run({
|
|
1297
1305
|
session: first.session,
|
|
@@ -1743,6 +1751,13 @@ function errorMessage(error) {
|
|
|
1743
1751
|
return message || String(error);
|
|
1744
1752
|
}
|
|
1745
1753
|
__name(errorMessage, "errorMessage");
|
|
1754
|
+
function errorDetail(error) {
|
|
1755
|
+
if (error instanceof DifyApiError) {
|
|
1756
|
+
return `status=${error.status}${error.code ? ` code=${error.code}` : ""} ${error.stack ?? error.message}`;
|
|
1757
|
+
}
|
|
1758
|
+
return error instanceof Error ? error.stack ?? error.message : String(error);
|
|
1759
|
+
}
|
|
1760
|
+
__name(errorDetail, "errorDetail");
|
|
1746
1761
|
|
|
1747
1762
|
// src/requester/runner.ts
|
|
1748
1763
|
var FALLBACK_QUERY = "(本次触发无文本内容,请参考变量中的上下文)";
|
|
@@ -1822,9 +1837,12 @@ var RequestRunner = class {
|
|
|
1822
1837
|
try {
|
|
1823
1838
|
reply = await this.dispatch(app, client, fireCtx, requestCtx);
|
|
1824
1839
|
} catch (error) {
|
|
1825
|
-
this.
|
|
1840
|
+
if (this.config.debugLogging) {
|
|
1841
|
+
this.ctx.logger.debug("规则 %s 请求失败详情:%s", rule.name, errorDetail(error));
|
|
1842
|
+
}
|
|
1843
|
+
this.ctx.logger.warn("规则 %s 请求失败:%s", rule.name, errorMessage(error));
|
|
1826
1844
|
if (this.config.sendErrors && fireCtx.session) {
|
|
1827
|
-
await fireCtx.session.send(
|
|
1845
|
+
await fireCtx.session.send(fireCtx.session.text("dify-ai.errors.request-failed", [errorMessage(error)])).catch(() => {
|
|
1828
1846
|
});
|
|
1829
1847
|
}
|
|
1830
1848
|
return;
|
package/lib/locales/en-US.d.ts
CHANGED
package/lib/locales/zh-CN.d.ts
CHANGED
package/lib/utils/errors.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-dify-ai",
|
|
3
3
|
"description": "Invoke Dify apps (chatflow / workflow / completion) in Koishi with triggers and conversation bindings",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.15",
|
|
5
5
|
"author": "PinkElysia",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/PinkElysiaDev/dify-ai-plugin-for-Koishi#readme",
|