@jeik/dingtalk-connector 0.8.28 → 0.8.30
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/CHANGELOG.md +40 -30
- package/README.en.md +114 -130
- package/README.md +112 -131
- package/dist/{background-work-Cxb4b-91.mjs → background-work-DkaSDqWk.mjs} +12 -1
- package/dist/card-content-cache-C7-XHhHw.mjs +2 -0
- package/dist/{card-content-cache-bDQFz2u8.mjs → card-content-cache-DT_OYThh.mjs} +15 -1
- package/dist/chunk-upload-BKM1y4Ba.mjs +2 -0
- package/dist/{chunk-upload-BE71drPg.mjs → chunk-upload-CIU5G_ay.mjs} +1 -1
- package/dist/{common-BZiVgd3A.mjs → common-BfIYs1yC.mjs} +3 -3
- package/dist/{common-DgL28gCZ.mjs → common-C0Oaf0z-.mjs} +1 -1
- package/dist/{connection-CZ7ZoN5_.mjs → connection-obtrPkj4.mjs} +56 -65
- package/dist/entry-bundled.mjs +1 -1
- package/dist/{gateway-methods-kNX3qvqw.mjs → gateway-methods-BdcpfxEZ.mjs} +1 -1
- package/dist/gateway-methods-DQ6TwOAr.mjs +2 -0
- package/dist/index.mjs +2 -2
- package/dist/{logger-mZ9OSbmD.mjs → logger-CnBTcwyq.mjs} +16 -2
- package/dist/logger-D8H2IcYz.mjs +2 -0
- package/dist/{media-BqpUGCni.mjs → media-DDtX37T2.mjs} +1 -1
- package/dist/{media-DnQB2BrL.mjs → media-g8tJtpfU.mjs} +29 -20
- package/dist/{message-handler-B1usz1wb.mjs → message-handler-BeTQQCUe.mjs} +33 -30
- package/dist/{messaging-DVS3UKOp.mjs → messaging-CK0Wz3Ze.mjs} +18 -20
- package/dist/{runtime-A6G7WAWn.mjs → runtime-CjE4Z9G5.mjs} +6 -5
- package/dist/{utils-Bjh4r_qS.mjs → utils-Bwz2Fls_.mjs} +1 -1
- package/docs/RELEASE_NOTES_V0.8.28.md +4 -4
- package/docs/RELEASE_NOTES_V0.8.29.md +72 -0
- package/openclaw.plugin.json +9 -5
- package/package.json +1 -1
- package/src/config/schema.ts +2 -1
- package/src/core/connection.ts +90 -113
- package/src/core/message-handler.ts +24 -16
- package/src/reply-dispatcher.ts +33 -20
- package/src/services/media.ts +60 -27
- package/src/services/messaging/card-content-cache.ts +11 -6
- package/src/services/messaging.ts +52 -38
- package/src/utils/background-work.ts +3 -1
- package/src/utils/logger.ts +23 -2
- package/dist/card-content-cache-c4Ls96eJ.mjs +0 -2
- package/dist/chunk-upload-PwhogwfE.mjs +0 -2
- package/dist/gateway-methods-BkI1gKaC.mjs +0 -2
- package/dist/logger-BmJkQkm1.mjs +0 -2
package/src/services/media.ts
CHANGED
|
@@ -12,6 +12,7 @@ import FormData from 'form-data';
|
|
|
12
12
|
import type { DingtalkConfig } from '../types/index.ts';
|
|
13
13
|
import { DINGTALK_OAPI, getOapiAccessToken } from '../utils/index.ts';
|
|
14
14
|
import { dingtalkHttp, dingtalkOapiHttp } from '../utils/http-client.ts';
|
|
15
|
+
import { isDingtalkDebug } from '../utils/logger.ts';
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
/** 文本文件扩展名 */
|
|
@@ -109,9 +110,11 @@ export function stripNonImageOccurrencesOfTargets(
|
|
|
109
110
|
from = idx + variant.length;
|
|
110
111
|
continue;
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
if (isDingtalkDebug()) {
|
|
114
|
+
console.log(
|
|
115
|
+
`[DingTalk][MediaIdTrace] strip 非图重复 target | idx=${idx} remove=${variant.slice(0, 100)}`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
115
118
|
if (!stripped.includes(original)) stripped.push(original);
|
|
116
119
|
out = out.slice(0, idx) + out.slice(idx + variant.length);
|
|
117
120
|
// 清掉残留的空「下载链接:」类前缀行由调用方整理;此处只去 target
|
|
@@ -127,7 +130,7 @@ export function stripNonImageOccurrencesOfTargets(
|
|
|
127
130
|
.replace(/[::]\s*$/gm, "")
|
|
128
131
|
.trim();
|
|
129
132
|
|
|
130
|
-
if (stripped.length) {
|
|
133
|
+
if (stripped.length && isDingtalkDebug()) {
|
|
131
134
|
console.log(
|
|
132
135
|
`[DingTalk][MediaIdTrace] strip 完成 | stripped=${stripped.length} bodyLen=${out.length}`,
|
|
133
136
|
);
|
|
@@ -225,9 +228,8 @@ export interface UploadResult {
|
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* 决策路径(匹配/exists/上传成败/残留)务必 always-on,方便查灰图。
|
|
231
|
+
* 本地图诊断日志。
|
|
232
|
+
* 默认静默:无图/空扫描不再刷屏。仅在上传/失败/灰图风险,或 debug: true 时输出。
|
|
231
233
|
*/
|
|
232
234
|
function logLocalImage(log: any, step: string, detail?: string, verbose = false) {
|
|
233
235
|
const line = detail
|
|
@@ -241,6 +243,19 @@ function logLocalImage(log: any, step: string, detail?: string, verbose = false)
|
|
|
241
243
|
}
|
|
242
244
|
return;
|
|
243
245
|
}
|
|
246
|
+
const interesting =
|
|
247
|
+
isDingtalkDebug() ||
|
|
248
|
+
/失败|灰图|残留|上传成功|上传失败|下载成功|下载失败|重试|remote|Remote/i.test(
|
|
249
|
+
`${step} ${detail || ""}`,
|
|
250
|
+
);
|
|
251
|
+
if (!interesting) {
|
|
252
|
+
try {
|
|
253
|
+
log?.debug?.(line);
|
|
254
|
+
} catch {
|
|
255
|
+
// ignore
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
244
259
|
console.log(line);
|
|
245
260
|
}
|
|
246
261
|
|
|
@@ -282,11 +297,12 @@ export function logMediaIdTrace(
|
|
|
282
297
|
// sampleImageMsg 的 photoURL 就是裸 mediaId,不算异常
|
|
283
298
|
const isImageMsg = /type=image|sampleImage|photoURL/i.test(`${stage} ${extra || ""}`);
|
|
284
299
|
const suspiciousBare = isImageMsg ? [] : bareIds;
|
|
300
|
+
// 默认静默:仅 force、灰图风险(裸 mediaId / 残留本地路径)、或 debug: true
|
|
285
301
|
const always =
|
|
286
302
|
force ||
|
|
303
|
+
isDingtalkDebug() ||
|
|
287
304
|
suspiciousBare.length > 0 ||
|
|
288
|
-
residualLocal.length > 0
|
|
289
|
-
/API前|完成|:out|:in|after-process|processImages/i.test(stage);
|
|
305
|
+
residualLocal.length > 0;
|
|
290
306
|
if (!always) return;
|
|
291
307
|
|
|
292
308
|
const preview = text.replace(/\n/g, "\\n").slice(0, 200);
|
|
@@ -556,9 +572,11 @@ async function downloadRemoteUrlToTemp(url: string): Promise<string | null> {
|
|
|
556
572
|
`dingtalk-md-remote-${Date.now()}-${Math.random().toString(36).slice(2, 8)}${ext}`,
|
|
557
573
|
);
|
|
558
574
|
fs.writeFileSync(tmp, buf);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
575
|
+
if (isDingtalkDebug()) {
|
|
576
|
+
console.log(
|
|
577
|
+
`[DingTalk][MediaIdTrace] 远程图下载成功 | bytes=${buf.length} tmp=${tmp}`,
|
|
578
|
+
);
|
|
579
|
+
}
|
|
562
580
|
return tmp;
|
|
563
581
|
} catch (e: any) {
|
|
564
582
|
console.warn(`[DingTalk][MediaIdTrace] 远程图下载异常 | ${e?.message || e}`);
|
|
@@ -599,8 +617,8 @@ function replaceOutsideImageTargets(
|
|
|
599
617
|
* - 本地:正文重复的本地路径换成 down.dingtalk.com 可点链接(仍同一条消息)
|
|
600
618
|
* - **不再拆第二条 text 消息**
|
|
601
619
|
*
|
|
602
|
-
*
|
|
603
|
-
* -
|
|
620
|
+
* 日志约定(默认静默;配置 debug: true 全量):
|
|
621
|
+
* - 有图上传/失败/灰图残留才 console;无图路径不刷屏
|
|
604
622
|
*/
|
|
605
623
|
export async function processImagesForOutbound(
|
|
606
624
|
content: string,
|
|
@@ -613,16 +631,19 @@ export async function processImagesForOutbound(
|
|
|
613
631
|
`contentLen=${content?.length ?? 0} hasToken=${!!oapiToken}`,
|
|
614
632
|
);
|
|
615
633
|
if (!oapiToken) {
|
|
616
|
-
|
|
617
|
-
|
|
634
|
+
// 有 MD 图却无 token 才告警(否则无图路径全静默)
|
|
635
|
+
if (/!\[[^\]]*\]\([^)]+\)/.test(content || "")) {
|
|
636
|
+
logLocalImage(log, "processImagesForOutbound 跳过", "无 oapiToken(本地路径无法上传→必灰图)");
|
|
637
|
+
logMediaIdTrace("processImagesForOutbound:skip-no-token", content);
|
|
638
|
+
}
|
|
618
639
|
return { text: content || "", followUpUrls: [] };
|
|
619
640
|
}
|
|
620
641
|
if (!content || typeof content !== "string") {
|
|
621
|
-
logLocalImage(log, "processImagesForOutbound 跳过", "content 为空");
|
|
642
|
+
logLocalImage(log, "processImagesForOutbound 跳过", "content 为空", true);
|
|
622
643
|
return { text: content || "", followUpUrls: [] };
|
|
623
644
|
}
|
|
624
645
|
|
|
625
|
-
logMediaIdTrace("processImagesForOutbound:in", content
|
|
646
|
+
logMediaIdTrace("processImagesForOutbound:in", content);
|
|
626
647
|
|
|
627
648
|
const codeRanges = getMarkdownCodeRanges(content);
|
|
628
649
|
if (codeRanges.length > 0) {
|
|
@@ -795,14 +816,26 @@ export async function processImagesForOutbound(
|
|
|
795
816
|
})
|
|
796
817
|
.map((m) => (m[2] || "").trim());
|
|
797
818
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
?
|
|
804
|
-
: "
|
|
805
|
-
|
|
819
|
+
// 有实际上传/跳过/残留时记一行;纯文本无图完成则静默
|
|
820
|
+
if (uploadCount > 0 || localTried > 0 || remoteTried > 0 || residual.length > 0) {
|
|
821
|
+
logLocalImage(
|
|
822
|
+
log,
|
|
823
|
+
residual.length
|
|
824
|
+
? "processImagesForOutbound 完成(有残留)"
|
|
825
|
+
: "processImagesForOutbound 上传成功",
|
|
826
|
+
`uploads=${uploadCount} localTried=${localTried} remoteTried=${remoteTried} skippedCode=${skippedCode} skippedOther=${skippedOther} outLen=${result.length}` +
|
|
827
|
+
(residual.length
|
|
828
|
+
? ` ⚠️residualLocal=${residual.length}:${residual.slice(0, 3).join("|")}`
|
|
829
|
+
: " residualLocal=0"),
|
|
830
|
+
);
|
|
831
|
+
} else {
|
|
832
|
+
logLocalImage(
|
|
833
|
+
log,
|
|
834
|
+
"processImagesForOutbound 完成",
|
|
835
|
+
`uploads=0 outLen=${result.length}`,
|
|
836
|
+
true,
|
|
837
|
+
);
|
|
838
|
+
}
|
|
806
839
|
if (residual.length) {
|
|
807
840
|
logLocalImage(
|
|
808
841
|
log,
|
|
@@ -810,7 +843,7 @@ export async function processImagesForOutbound(
|
|
|
810
843
|
residual.join(" | "),
|
|
811
844
|
);
|
|
812
845
|
}
|
|
813
|
-
logMediaIdTrace("processImagesForOutbound:out", result
|
|
846
|
+
logMediaIdTrace("processImagesForOutbound:out", result);
|
|
814
847
|
|
|
815
848
|
return { text: result, followUpUrls: [] };
|
|
816
849
|
}
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* 内存 LRU + TTL,进程重启后清空(可接受)。
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { isDingtalkDebug } from "../../utils/logger.ts";
|
|
16
|
+
|
|
15
17
|
export type CardContentCacheEntry = {
|
|
16
18
|
text: string;
|
|
17
19
|
at: number;
|
|
@@ -83,12 +85,15 @@ export function rememberCardContent(params: {
|
|
|
83
85
|
byKey.set(normalizeKey("convRef", `${cid}|${ref}`), entry);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
// 成功写入默认静默;需要排查时设 debug: true
|
|
89
|
+
if (isDingtalkDebug()) {
|
|
90
|
+
try {
|
|
91
|
+
console.log(
|
|
92
|
+
`[DingTalk][CardCache] 已缓存 | outTrack=${params.outTrackId || "-"} conv=${params.conversationId || "-"} len=${text.length}`,
|
|
93
|
+
);
|
|
94
|
+
} catch {
|
|
95
|
+
// ignore
|
|
96
|
+
}
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
@@ -7,7 +7,7 @@ import type { DingtalkConfig } from "../types/index.ts";
|
|
|
7
7
|
import { DINGTALK_API, getAccessToken, getOapiAccessToken } from "../utils/index.ts";
|
|
8
8
|
import { dingtalkHttp, dingtalkOapiHttp } from "../utils/http-client.ts";
|
|
9
9
|
import { MEDIA_MSG_TYPES } from "../utils/constants.ts";
|
|
10
|
-
import { createLoggerFromConfig } from "../utils/logger.ts";
|
|
10
|
+
import { createLoggerFromConfig, isDingtalkDebug } from "../utils/logger.ts";
|
|
11
11
|
import {
|
|
12
12
|
processLocalImages,
|
|
13
13
|
processImagesForOutbound,
|
|
@@ -779,7 +779,9 @@ async function downloadRemoteMediaToTemp(
|
|
|
779
779
|
): Promise<string | null> {
|
|
780
780
|
const tag = "[DingTalk][RemoteMedia]";
|
|
781
781
|
try {
|
|
782
|
-
|
|
782
|
+
if (isDingtalkDebug()) {
|
|
783
|
+
console.log(`${tag} 开始下载 | ${url}`);
|
|
784
|
+
}
|
|
783
785
|
const res = await fetch(url, {
|
|
784
786
|
redirect: "follow",
|
|
785
787
|
signal: AbortSignal.timeout(60_000),
|
|
@@ -819,7 +821,9 @@ async function downloadRemoteMediaToTemp(
|
|
|
819
821
|
`dingtalk-remote-${Date.now()}-${Math.random().toString(36).slice(2, 8)}${ext}`,
|
|
820
822
|
);
|
|
821
823
|
writeFileSync(tmp, buf);
|
|
822
|
-
|
|
824
|
+
if (isDingtalkDebug()) {
|
|
825
|
+
console.log(`${tag} 下载成功 | bytes=${buf.length} ct=${ct || "-"} tmp=${tmp}`);
|
|
826
|
+
}
|
|
823
827
|
return tmp;
|
|
824
828
|
} catch (err: any) {
|
|
825
829
|
console.warn(`${tag} 下载异常 | ${err?.message || err}`);
|
|
@@ -883,26 +887,27 @@ export async function sendTextToDingTalk(params: {
|
|
|
883
887
|
|
|
884
888
|
const targetParam = resolveOutboundTarget(target);
|
|
885
889
|
|
|
886
|
-
console.log(
|
|
887
|
-
`[DingTalk][LocalImage] sendTextToDingTalk 入口 | target=${target} textLen=${text?.length ?? 0}`,
|
|
888
|
-
);
|
|
889
|
-
logMediaIdTrace("sendTextToDingTalk:in", text, `target=${target}`, true);
|
|
890
|
-
|
|
891
890
|
// 图片:![] 上传为 mediaId;下载链接原 URL 留在同一条 markdown(不拆消息)
|
|
891
|
+
// 无图路径全程静默;有 MD 图/失败才打日志(debug: true 可开全量)
|
|
892
892
|
const beforeLen = text?.length ?? 0;
|
|
893
|
+
const hasMdImg = /!\[[^\]]*\]\([^)]+\)/.test(text || "");
|
|
894
|
+
if (hasMdImg || isDingtalkDebug()) {
|
|
895
|
+
logMediaIdTrace("sendTextToDingTalk:in", text, `target=${target}`);
|
|
896
|
+
}
|
|
893
897
|
try {
|
|
894
898
|
const oapiToken = await getOapiAccessToken(config);
|
|
895
|
-
console.log(
|
|
896
|
-
`[DingTalk][LocalImage] sendTextToDingTalk 入口 | target=${target} textLen=${beforeLen} hasToken=${!!oapiToken}`,
|
|
897
|
-
);
|
|
898
899
|
if (oapiToken && text) {
|
|
899
900
|
const processed = await processImagesForOutbound(text, oapiToken, log);
|
|
900
901
|
text = processed.text;
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
902
|
+
if (beforeLen !== text.length && (hasMdImg || isDingtalkDebug())) {
|
|
903
|
+
console.log(
|
|
904
|
+
`[DingTalk][LocalImage] sendTextToDingTalk 处理后 | ${beforeLen}→${text.length} 字`,
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
if (hasMdImg || isDingtalkDebug()) {
|
|
908
|
+
logMediaIdTrace("sendTextToDingTalk:after-process", text);
|
|
909
|
+
}
|
|
910
|
+
} else if (!oapiToken && hasMdImg) {
|
|
906
911
|
console.warn(
|
|
907
912
|
`[DingTalk][LocalImage] sendTextToDingTalk 无 oapiToken,跳过图片上传(本地 MD 图会灰)`,
|
|
908
913
|
);
|
|
@@ -915,15 +920,13 @@ export async function sendTextToDingTalk(params: {
|
|
|
915
920
|
|
|
916
921
|
const msgType: DingTalkMsgType = shouldSendAsMarkdown(text) ? "markdown" : "text";
|
|
917
922
|
const cardOpts = messageToolProactiveCardOptions(config);
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
`[DingTalk][MessageCard] sendTextToDingTalk | messageAnswerCard=${isMessageAnswerCardEnabled(config)} useAICard=${cardOpts.useAICard} tpl=${cardOpts.cardTemplateId || "-"}`,
|
|
926
|
-
);
|
|
923
|
+
if (hasMdImg || isDingtalkDebug()) {
|
|
924
|
+
logMediaIdTrace(
|
|
925
|
+
"sendTextToDingTalk:API前",
|
|
926
|
+
text,
|
|
927
|
+
`msgType=${msgType} messageAnswerCard=${isMessageAnswerCardEnabled(config)} useAICard=${cardOpts.useAICard}`,
|
|
928
|
+
);
|
|
929
|
+
}
|
|
927
930
|
|
|
928
931
|
return sendProactive(config, targetParam, text, {
|
|
929
932
|
msgType,
|
|
@@ -1127,9 +1130,11 @@ export async function sendMediaToDingTalk(params: {
|
|
|
1127
1130
|
const mergeMd =
|
|
1128
1131
|
config.messageImageMd === true && caption.length > 0 && imgsInCaption >= 1;
|
|
1129
1132
|
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
+
if (isDingtalkDebug()) {
|
|
1134
|
+
console.log(
|
|
1135
|
+
`[DingTalk][LocalImage] sendMedia 图片策略 | messageImageMd=${config.messageImageMd === true} imgsInCaption=${imgsInCaption} mergeMd=${mergeMd} remote=${isRemoteHttpUrl(mediaUrl)}`,
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1133
1138
|
|
|
1134
1139
|
if (mergeMd) {
|
|
1135
1140
|
const combined = `${caption}\n\n`;
|
|
@@ -1250,7 +1255,9 @@ export async function sendMediaToDingTalk(params: {
|
|
|
1250
1255
|
if (cleanupTemp) {
|
|
1251
1256
|
try {
|
|
1252
1257
|
_fs.unlinkSync(cleanupTemp);
|
|
1253
|
-
|
|
1258
|
+
if (isDingtalkDebug()) {
|
|
1259
|
+
console.log(`[DingTalk][RemoteMedia] 已清理临时文件 | ${cleanupTemp}`);
|
|
1260
|
+
}
|
|
1254
1261
|
} catch {
|
|
1255
1262
|
// ignore
|
|
1256
1263
|
}
|
|
@@ -1392,9 +1399,11 @@ async function sendProactiveInternal(
|
|
|
1392
1399
|
undefined,
|
|
1393
1400
|
skipInputingWalk,
|
|
1394
1401
|
);
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1402
|
+
if (isDingtalkDebug()) {
|
|
1403
|
+
console.log(
|
|
1404
|
+
`[DingTalk][MessageCard] AI Card 发送成功 | outTrack=${card.cardInstanceId} tpl=${cardTemplateId || "default"} skipInputing=${skipInputingWalk}`,
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1398
1407
|
return {
|
|
1399
1408
|
ok: true,
|
|
1400
1409
|
cardInstanceId: card.cardInstanceId,
|
|
@@ -1455,12 +1464,17 @@ async function sendProactiveInternal(
|
|
|
1455
1464
|
return { ok: false, error: payload.error, usedAICard: false };
|
|
1456
1465
|
}
|
|
1457
1466
|
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
content
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1467
|
+
// 仅有 MD 图或调试时追踪(纯文本出站不再刷屏)
|
|
1468
|
+
if (
|
|
1469
|
+
/!\[[^\]]*\]\([^)]+\)/.test(content || "") ||
|
|
1470
|
+
isDingtalkDebug()
|
|
1471
|
+
) {
|
|
1472
|
+
logMediaIdTrace(
|
|
1473
|
+
"API出站",
|
|
1474
|
+
content,
|
|
1475
|
+
`msgKey=${payload.msgKey} type=${msgType}`,
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1464
1478
|
|
|
1465
1479
|
const body: any = {
|
|
1466
1480
|
robotCode: String(config.clientId),
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* connection 层订阅计数变化,在 count>0 时保持处理中 keepAlive。
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { isDingtalkDebug } from "./logger.ts";
|
|
13
|
+
|
|
12
14
|
type CountListener = (count: number) => void;
|
|
13
15
|
|
|
14
16
|
let activeCount = 0;
|
|
@@ -54,7 +56,7 @@ export function trackBackgroundWork(
|
|
|
54
56
|
notify();
|
|
55
57
|
};
|
|
56
58
|
void work.then(done, done);
|
|
57
|
-
if (label && typeof process !== "undefined" &&
|
|
59
|
+
if (label && typeof process !== "undefined" && isDingtalkDebug()) {
|
|
58
60
|
console.log(`[DingTalk][bgWork] +1 label=${label} count=${activeCount}`);
|
|
59
61
|
void work.finally(() => {
|
|
60
62
|
console.log(`[DingTalk][bgWork] -1 label=${label} count=${activeCount}`);
|
package/src/utils/logger.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 日志工具模块
|
|
3
|
-
*
|
|
3
|
+
* 根据配置里的 debug 控制日志输出(无需环境变量)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/** 任一账号/连接开启过 debug 后为 true;默认静默 */
|
|
7
|
+
let pluginDebugEnabled = false;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 设置插件全局 debug(由配置 `debug: true` 驱动)
|
|
11
|
+
* 仅在 true 时打开;避免多账号中未开 debug 的账号把开关关掉。
|
|
12
|
+
*/
|
|
13
|
+
export function setDingtalkDebug(enabled: boolean): void {
|
|
14
|
+
if (enabled) pluginDebugEnabled = true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 是否输出图片/引用/队列等详细诊断日志 */
|
|
18
|
+
export function isDingtalkDebug(): boolean {
|
|
19
|
+
return pluginDebugEnabled;
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
/**
|
|
7
23
|
* 创建日志记录器
|
|
8
24
|
* @param debug - 是否启用 debug 模式
|
|
@@ -10,6 +26,8 @@
|
|
|
10
26
|
* @returns 日志记录器对象
|
|
11
27
|
*/
|
|
12
28
|
export function createLogger(debug: boolean = false, prefix: string = '') {
|
|
29
|
+
if (debug) setDingtalkDebug(true);
|
|
30
|
+
|
|
13
31
|
const logger = {
|
|
14
32
|
/**
|
|
15
33
|
* 打印 info 级别日志
|
|
@@ -73,6 +91,9 @@ export function createLogger(debug: boolean = false, prefix: string = '') {
|
|
|
73
91
|
* @param prefix - 日志前缀
|
|
74
92
|
* @returns 日志记录器对象
|
|
75
93
|
*/
|
|
76
|
-
export function createLoggerFromConfig(
|
|
94
|
+
export function createLoggerFromConfig(
|
|
95
|
+
config: { debug?: boolean } | undefined | null,
|
|
96
|
+
prefix: string = '',
|
|
97
|
+
) {
|
|
77
98
|
return createLogger(!!config?.debug, prefix);
|
|
78
99
|
}
|
package/dist/logger-BmJkQkm1.mjs
DELETED