@jeik/dingtalk-connector 0.8.26 → 0.8.27
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/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as initDingtalkPluginConfigSchema, i as dingtalkPlugin, n as setDingtalkRuntime } from "./runtime-
|
|
1
|
+
import { a as initDingtalkPluginConfigSchema, i as dingtalkPlugin, n as setDingtalkRuntime } from "./runtime-DzZo6Gvk.mjs";
|
|
2
2
|
import { t as registerGatewayMethods } from "./gateway-methods--aKsyMs-.mjs";
|
|
3
3
|
//#region index.ts
|
|
4
4
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as resolveDingtalkAccount } from "./accounts-BAzdqkAV.mjs";
|
|
2
|
-
import { r as CHANNEL_ID, t as getDingtalkRuntime } from "./runtime-
|
|
2
|
+
import { r as CHANNEL_ID, t as getDingtalkRuntime } from "./runtime-DzZo6Gvk.mjs";
|
|
3
3
|
import { n as createLoggerFromConfig } from "./logger-mZ9OSbmD.mjs";
|
|
4
4
|
import { t as dingtalkHttp } from "./http-client-DFWZgO1n.mjs";
|
|
5
5
|
import { i as getOapiAccessToken } from "./utils-CIfI_3Jh.mjs";
|
|
@@ -2265,11 +2265,17 @@ async function handleDingTalkMessageInternal(params) {
|
|
|
2265
2265
|
}
|
|
2266
2266
|
} catch (err) {
|
|
2267
2267
|
log?.error?.(`SDK dispatch 失败: ${err.message}`);
|
|
2268
|
-
|
|
2268
|
+
const errorText = matchModelErrorText(err.message, { includeCatchAll: true }) ?? `⚠️ 抱歉,处理请求时出错: ${err.message}`;
|
|
2269
|
+
if (earlyCard) try {
|
|
2270
|
+
await streamAICard(earlyCard, errorText, true, config, log);
|
|
2271
|
+
} catch (cardErr) {
|
|
2272
|
+
log?.error?.(`更新错误卡片失败: ${cardErr.message}`);
|
|
2273
|
+
}
|
|
2274
|
+
else try {
|
|
2269
2275
|
const token = await getAccessToken(config);
|
|
2270
2276
|
const body = {
|
|
2271
2277
|
msgtype: "text",
|
|
2272
|
-
text: { content:
|
|
2278
|
+
text: { content: errorText }
|
|
2273
2279
|
};
|
|
2274
2280
|
if (!isDirect) body.at = {
|
|
2275
2281
|
atUserIds: [senderId],
|
|
@@ -955,7 +955,7 @@ async function monitorDingtalkProvider(opts = {}) {
|
|
|
955
955
|
const log = createLogger(cfg.channels?.["dingtalk-connector"]?.debug ?? false);
|
|
956
956
|
const [accountsModule, monitorAccountModule, monitorSingleModule] = await Promise.all([
|
|
957
957
|
import("./accounts-BQptOmgB.mjs"),
|
|
958
|
-
import("./message-handler-
|
|
958
|
+
import("./message-handler-DQZiKx3i.mjs"),
|
|
959
959
|
import("./connection-fc6B4z4G.mjs")
|
|
960
960
|
]);
|
|
961
961
|
const { resolveDingtalkAccount, listEnabledDingtalkAccounts } = accountsModule;
|
package/package.json
CHANGED
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
lookupCardContent,
|
|
63
63
|
} from "../services/messaging/card-content-cache.ts";
|
|
64
64
|
import { QUEUE_BUSY_ACK_PHRASES } from "../utils/constants.ts";
|
|
65
|
-
import { createDingtalkReplyDispatcher } from "../reply-dispatcher.ts";
|
|
65
|
+
import { createDingtalkReplyDispatcher, matchModelErrorText } from "../reply-dispatcher.ts";
|
|
66
66
|
import { normalizeSlashCommand } from "../utils/session.ts";
|
|
67
67
|
import { getDingtalkRuntime } from "../runtime.ts";
|
|
68
68
|
import { dingtalkHttp } from '../utils/http-client.ts';
|
|
@@ -1906,20 +1906,32 @@ export async function handleDingTalkMessageInternal(params: HandleMessageParams)
|
|
|
1906
1906
|
} catch (err: any) {
|
|
1907
1907
|
log?.error?.(`SDK dispatch 失败: ${err.message}`);
|
|
1908
1908
|
|
|
1909
|
-
//
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1909
|
+
// 解析上游错误文本(例如 503 No available channel),匹配中文提示文案
|
|
1910
|
+
const errorText = matchModelErrorText(err.message, { includeCatchAll: true }) ?? `⚠️ 抱歉,处理请求时出错: ${err.message}`;
|
|
1911
|
+
|
|
1912
|
+
// 如果已经建了 AI Card,则更新报错状态到 Card,避免停留在"正在召唤大模型"
|
|
1913
|
+
if (earlyCard) {
|
|
1914
|
+
try {
|
|
1915
|
+
await streamAICard(earlyCard, errorText, true, config, log);
|
|
1916
|
+
} catch (cardErr: any) {
|
|
1917
|
+
log?.error?.(`更新错误卡片失败: ${cardErr.message}`);
|
|
1918
|
+
}
|
|
1919
|
+
} else {
|
|
1920
|
+
// 降级:发送错误文本消息
|
|
1921
|
+
try {
|
|
1922
|
+
const token = await getAccessToken(config);
|
|
1923
|
+
const body: any = {
|
|
1924
|
+
msgtype: 'text',
|
|
1925
|
+
text: { content: errorText }
|
|
1926
|
+
};
|
|
1927
|
+
if (!isDirect) body.at = { atUserIds: [senderId], isAtAll: false };
|
|
1928
|
+
|
|
1929
|
+
await dingtalkHttp.post(sessionWebhook, body, {
|
|
1930
|
+
headers: { 'x-acs-dingtalk-access-token': token, 'Content-Type': 'application/json' },
|
|
1931
|
+
});
|
|
1932
|
+
} catch (fallbackErr: any) {
|
|
1933
|
+
log?.error?.(`错误消息发送也失败: ${fallbackErr.message}`);
|
|
1934
|
+
}
|
|
1923
1935
|
}
|
|
1924
1936
|
}
|
|
1925
1937
|
|
package/src/reply-dispatcher.ts
CHANGED
|
@@ -239,7 +239,7 @@ const MODEL_ERROR_CATCH_ALL: [RegExp, string] = [/.{20,}/, MODEL_ERROR_GENERIC];
|
|
|
239
239
|
* @param opts.includeCatchAll 为 true 时启用万能兜底
|
|
240
240
|
* @returns 命中则返回中文提示,未命中返回 null
|
|
241
241
|
*/
|
|
242
|
-
function matchModelErrorText(
|
|
242
|
+
export function matchModelErrorText(
|
|
243
243
|
source: string,
|
|
244
244
|
opts?: { includeCatchAll?: boolean },
|
|
245
245
|
): string | null {
|