cclawd 1.0.6 → 1.0.8
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/build-info.json +3 -3
- package/dist/plugin-sdk/active-listener-CN-tMEvN.js +35 -0
- package/dist/plugin-sdk/api-key-rotation-CimGYMBc.js +176 -0
- package/dist/plugin-sdk/audio-preflight-C-xXBoE2.js +51 -0
- package/dist/plugin-sdk/audio-transcription-runner-CTIHpebA.js +2173 -0
- package/dist/plugin-sdk/audit-membership-runtime-BFatB2LJ.js +58 -0
- package/dist/plugin-sdk/channel-activity-DO0FEzyj.js +95 -0
- package/dist/plugin-sdk/channel-web-Da-__nUF.js +2238 -0
- package/dist/plugin-sdk/commands-registry-6no2NNrY.js +1118 -0
- package/dist/plugin-sdk/compact.runtime-CCoclu5e.js +35 -0
- package/dist/plugin-sdk/compat.js +35 -35
- package/dist/plugin-sdk/config-B9ODwgpz.js +37426 -0
- package/dist/plugin-sdk/deliver-B1fFpKjV.js +1757 -0
- package/dist/plugin-sdk/deliver-runtime-DB-VRMe1.js +15 -0
- package/dist/plugin-sdk/deps-send-discord.runtime-DklqycYG.js +15 -0
- package/dist/plugin-sdk/deps-send-imessage.runtime-Chs8zeon.js +14 -0
- package/dist/plugin-sdk/deps-send-signal.runtime-clW9aSJP.js +13 -0
- package/dist/plugin-sdk/deps-send-slack.runtime-BUx0LYY1.js +13 -0
- package/dist/plugin-sdk/deps-send-telegram.runtime-LECSHgMG.js +16 -0
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-D2d65fw0.js +40 -0
- package/dist/plugin-sdk/diagnostic-CxIvS-C2.js +315 -0
- package/dist/plugin-sdk/dispatch-BqlR4dPx.js +105863 -0
- package/dist/plugin-sdk/env-b9k1PHMI.js +34 -0
- package/dist/plugin-sdk/fetch-PoxzAANT.js +326 -0
- package/dist/plugin-sdk/fetch-guard-4UVSZ0uS.js +164 -0
- package/dist/plugin-sdk/image-Ch6M4tnJ.js +2420 -0
- package/dist/plugin-sdk/image-runtime-CSh2o5wY.js +8 -0
- package/dist/plugin-sdk/ir-CugsqGH8.js +1312 -0
- package/dist/plugin-sdk/local-roots-adnEg9zb.js +217 -0
- package/dist/plugin-sdk/logger-D6zRubj0.js +1164 -0
- package/dist/plugin-sdk/login-CYvkQ0At.js +54 -0
- package/dist/plugin-sdk/login-qr-ll4NtaT5.js +316 -0
- package/dist/plugin-sdk/manager-CHy8IclH.js +3959 -0
- package/dist/plugin-sdk/manager-runtime-C70EkEr7.js +11 -0
- package/dist/plugin-sdk/outbound-Wzs2iN7X.js +216 -0
- package/dist/plugin-sdk/outbound-attachment-khXJwucX.js +17 -0
- package/dist/plugin-sdk/paths-BtVqCdw4.js +3063 -0
- package/dist/plugin-sdk/pi-model-discovery-Dh4ziodY.js +131 -0
- package/dist/plugin-sdk/pi-model-discovery-runtime-b83Xe-HT.js +8 -0
- package/dist/plugin-sdk/pi-tools.before-tool-call.runtime-C1z5CDBF.js +349 -0
- package/dist/plugin-sdk/proxy-fetch-CJEmoBxi.js +54 -0
- package/dist/plugin-sdk/pw-ai-Dj3Cvlzl.js +1990 -0
- package/dist/plugin-sdk/qmd-manager-egHUAseQ.js +1581 -0
- package/dist/plugin-sdk/resolve-outbound-target-BiICvIKs.js +38 -0
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-DNApufzW.js +9 -0
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-CBmtfIQ8.js +13 -0
- package/dist/plugin-sdk/send-CScblaI4.js +532 -0
- package/dist/plugin-sdk/send-CeHhnld6.js +407 -0
- package/dist/plugin-sdk/send-DP_c8JfR.js +3277 -0
- package/dist/plugin-sdk/send-Dc5fI6e8.js +495 -0
- package/dist/plugin-sdk/send-l-77_s1_.js +2507 -0
- package/dist/plugin-sdk/session-CkOKZaqa.js +166 -0
- package/dist/plugin-sdk/skill-commands-BohYCgkq.js +336 -0
- package/dist/plugin-sdk/slash-commands.runtime-DpLfVTM6.js +8 -0
- package/dist/plugin-sdk/slash-dispatch.runtime-CASMHwpm.js +35 -0
- package/dist/plugin-sdk/slash-skill-commands.runtime-D7rrJEci.js +9 -0
- package/dist/plugin-sdk/sqlite-CJE3X7Mv.js +1005 -0
- package/dist/plugin-sdk/subagent-registry-runtime-B1oo5bih.js +35 -0
- package/dist/plugin-sdk/tables-D5VgpTmm.js +53 -0
- package/dist/plugin-sdk/target-errors-C6zZ_OpA.js +191 -0
- package/dist/plugin-sdk/tokens-DUnJnpMS.js +50 -0
- package/dist/plugin-sdk/web-TfUM1nSi.js +39 -0
- package/dist/plugin-sdk/whatsapp-actions-DuWJ0j1r.js +71 -0
- package/extensions/cclawd-mfa-auth/README.md +118 -0
- package/extensions/cclawd-mfa-auth/index.ts +382 -0
- package/extensions/cclawd-mfa-auth/openclaw.plugin.json +34 -0
- package/extensions/cclawd-mfa-auth/package.json +27 -0
- package/extensions/cclawd-mfa-auth/src/auth-manager.ts +536 -0
- package/extensions/cclawd-mfa-auth/src/config.ts +82 -0
- package/extensions/cclawd-mfa-auth/src/dabby-client.ts +200 -0
- package/extensions/cclawd-mfa-auth/src/notification-service.ts +417 -0
- package/extensions/cclawd-mfa-auth/src/polling-manager.ts +232 -0
- package/extensions/cclawd-mfa-auth/src/providers/base.ts +25 -0
- package/extensions/cclawd-mfa-auth/src/providers/qr-code.ts +98 -0
- package/extensions/cclawd-mfa-auth/src/sensitive-detector.ts +159 -0
- package/extensions/cclawd-mfa-auth/src/session-resolver.ts +159 -0
- package/extensions/cclawd-mfa-auth/src/types.ts +156 -0
- package/extensions/mfa-auth/node_modules/.package-lock.json +21 -0
- package/extensions/mfa-auth/node_modules/ws/LICENSE +20 -0
- package/extensions/mfa-auth/node_modules/ws/README.md +548 -0
- package/extensions/mfa-auth/node_modules/ws/browser.js +8 -0
- package/extensions/mfa-auth/node_modules/ws/index.js +13 -0
- package/extensions/mfa-auth/node_modules/ws/lib/buffer-util.js +131 -0
- package/extensions/mfa-auth/node_modules/ws/lib/constants.js +19 -0
- package/extensions/mfa-auth/node_modules/ws/lib/event-target.js +292 -0
- package/extensions/mfa-auth/node_modules/ws/lib/extension.js +203 -0
- package/extensions/mfa-auth/node_modules/ws/lib/limiter.js +55 -0
- package/extensions/mfa-auth/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/extensions/mfa-auth/node_modules/ws/lib/receiver.js +706 -0
- package/extensions/mfa-auth/node_modules/ws/lib/sender.js +602 -0
- package/extensions/mfa-auth/node_modules/ws/lib/stream.js +161 -0
- package/extensions/mfa-auth/node_modules/ws/lib/subprotocol.js +62 -0
- package/extensions/mfa-auth/node_modules/ws/lib/validation.js +152 -0
- package/extensions/mfa-auth/node_modules/ws/lib/websocket-server.js +554 -0
- package/extensions/mfa-auth/node_modules/ws/lib/websocket.js +1393 -0
- package/extensions/mfa-auth/node_modules/ws/package.json +69 -0
- package/extensions/mfa-auth/node_modules/ws/wrapper.mjs +8 -0
- package/extensions/mfa-auth/package-lock.json +23 -1
- package/package.json +453 -453
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./paths-eFexkPEh.js";
|
|
4
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
5
|
+
import "./logger-D6zRubj0.js";
|
|
6
|
+
import "./env-b9k1PHMI.js";
|
|
7
|
+
import "./fetch-BSKpf2dM.js";
|
|
8
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
9
|
+
import "./local-roots-adnEg9zb.js";
|
|
10
|
+
import "./ir-CugsqGH8.js";
|
|
11
|
+
import { t as deliverOutboundPayloads } from "./deliver-B1fFpKjV.js";
|
|
12
|
+
import "./tokens-DUnJnpMS.js";
|
|
13
|
+
import "./send-CScblaI4.js";
|
|
14
|
+
import "./outbound-attachment-khXJwucX.js";
|
|
15
|
+
export { deliverOutboundPayloads };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./paths-eFexkPEh.js";
|
|
4
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
5
|
+
import "./logger-D6zRubj0.js";
|
|
6
|
+
import "./env-b9k1PHMI.js";
|
|
7
|
+
import { h as sendMessageDiscord } from "./send-DP_c8JfR.js";
|
|
8
|
+
import "./fetch-BSKpf2dM.js";
|
|
9
|
+
import "./channel-activity-DO0FEzyj.js";
|
|
10
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
11
|
+
import "./local-roots-adnEg9zb.js";
|
|
12
|
+
import "./ir-CugsqGH8.js";
|
|
13
|
+
import "./render-CKf6NJ1M.js";
|
|
14
|
+
import "./tables-D5VgpTmm.js";
|
|
15
|
+
export { sendMessageDiscord };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./paths-eFexkPEh.js";
|
|
4
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
5
|
+
import "./logger-D6zRubj0.js";
|
|
6
|
+
import "./env-b9k1PHMI.js";
|
|
7
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
8
|
+
import "./local-roots-adnEg9zb.js";
|
|
9
|
+
import "./ir-CugsqGH8.js";
|
|
10
|
+
import "./render-CKf6NJ1M.js";
|
|
11
|
+
import "./tables-D5VgpTmm.js";
|
|
12
|
+
import "./outbound-attachment-khXJwucX.js";
|
|
13
|
+
import { t as sendMessageIMessage } from "./send-Dc5fI6e8.js";
|
|
14
|
+
export { sendMessageIMessage };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./paths-eFexkPEh.js";
|
|
4
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
5
|
+
import "./logger-D6zRubj0.js";
|
|
6
|
+
import "./env-b9k1PHMI.js";
|
|
7
|
+
import "./fetch-BSKpf2dM.js";
|
|
8
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
9
|
+
import "./local-roots-adnEg9zb.js";
|
|
10
|
+
import "./ir-CugsqGH8.js";
|
|
11
|
+
import { t as sendMessageSignal } from "./send-CScblaI4.js";
|
|
12
|
+
import "./outbound-attachment-khXJwucX.js";
|
|
13
|
+
export { sendMessageSignal };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./paths-eFexkPEh.js";
|
|
4
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
5
|
+
import "./logger-D6zRubj0.js";
|
|
6
|
+
import "./env-b9k1PHMI.js";
|
|
7
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
8
|
+
import "./local-roots-adnEg9zb.js";
|
|
9
|
+
import "./ir-CugsqGH8.js";
|
|
10
|
+
import "./render-CKf6NJ1M.js";
|
|
11
|
+
import { t as sendMessageSlack } from "./send-CeHhnld6.js";
|
|
12
|
+
import "./tokens-DUnJnpMS.js";
|
|
13
|
+
export { sendMessageSlack };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./paths-eFexkPEh.js";
|
|
4
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
5
|
+
import "./logger-D6zRubj0.js";
|
|
6
|
+
import "./env-b9k1PHMI.js";
|
|
7
|
+
import "./fetch-BSKpf2dM.js";
|
|
8
|
+
import "./channel-activity-DO0FEzyj.js";
|
|
9
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
10
|
+
import "./local-roots-adnEg9zb.js";
|
|
11
|
+
import "./ir-CugsqGH8.js";
|
|
12
|
+
import "./render-CKf6NJ1M.js";
|
|
13
|
+
import { s as sendMessageTelegram } from "./send-l-77_s1_.js";
|
|
14
|
+
import "./proxy-fetch-CJEmoBxi.js";
|
|
15
|
+
import "./fetch-PoxzAANT.js";
|
|
16
|
+
export { sendMessageTelegram };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import "./paths-BtVqCdw4.js";
|
|
2
|
+
import "./config-B9ODwgpz.js";
|
|
3
|
+
import "./dispatch-BqlR4dPx.js";
|
|
4
|
+
import "./paths-eFexkPEh.js";
|
|
5
|
+
import "./github-copilot-token-Cxf8QYZb.js";
|
|
6
|
+
import "./logger-D6zRubj0.js";
|
|
7
|
+
import "./env-b9k1PHMI.js";
|
|
8
|
+
import "./send-DP_c8JfR.js";
|
|
9
|
+
import "./fetch-BSKpf2dM.js";
|
|
10
|
+
import "./channel-activity-DO0FEzyj.js";
|
|
11
|
+
import "./fetch-guard-4UVSZ0uS.js";
|
|
12
|
+
import "./local-roots-adnEg9zb.js";
|
|
13
|
+
import "./ir-CugsqGH8.js";
|
|
14
|
+
import "./render-CKf6NJ1M.js";
|
|
15
|
+
import "./tables-D5VgpTmm.js";
|
|
16
|
+
import "./send-l-77_s1_.js";
|
|
17
|
+
import "./target-errors-C6zZ_OpA.js";
|
|
18
|
+
import "./send-CeHhnld6.js";
|
|
19
|
+
import "./deliver-B1fFpKjV.js";
|
|
20
|
+
import "./diagnostic-CxIvS-C2.js";
|
|
21
|
+
import "./pi-model-discovery-Dh4ziodY.js";
|
|
22
|
+
import "./audio-transcription-runner-CTIHpebA.js";
|
|
23
|
+
import "./image-Ch6M4tnJ.js";
|
|
24
|
+
import "./api-key-rotation-CimGYMBc.js";
|
|
25
|
+
import "./proxy-fetch-CJEmoBxi.js";
|
|
26
|
+
import "./tokens-DUnJnpMS.js";
|
|
27
|
+
import "./commands-registry-6no2NNrY.js";
|
|
28
|
+
import "./skill-commands-BohYCgkq.js";
|
|
29
|
+
import "./send-CScblaI4.js";
|
|
30
|
+
import "./outbound-attachment-khXJwucX.js";
|
|
31
|
+
import "./send-Dc5fI6e8.js";
|
|
32
|
+
import "./sqlite-CJE3X7Mv.js";
|
|
33
|
+
import "./fetch-PoxzAANT.js";
|
|
34
|
+
import "./manager-CHy8IclH.js";
|
|
35
|
+
import "./channel-web-Da-__nUF.js";
|
|
36
|
+
import { t as sendMessageWhatsApp } from "./outbound-Wzs2iN7X.js";
|
|
37
|
+
import "./session-CkOKZaqa.js";
|
|
38
|
+
import "./login-CYvkQ0At.js";
|
|
39
|
+
import "./web-TfUM1nSi.js";
|
|
40
|
+
export { sendMessageWhatsApp };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { r as loadConfig } from "./config-B9ODwgpz.js";
|
|
2
|
+
import { a as createSubsystemLogger } from "./logger-D6zRubj0.js";
|
|
3
|
+
//#region src/infra/diagnostic-events.ts
|
|
4
|
+
function getDiagnosticEventsState() {
|
|
5
|
+
const globalStore = globalThis;
|
|
6
|
+
if (!globalStore.__openclawDiagnosticEventsState) globalStore.__openclawDiagnosticEventsState = {
|
|
7
|
+
seq: 0,
|
|
8
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
9
|
+
dispatchDepth: 0
|
|
10
|
+
};
|
|
11
|
+
return globalStore.__openclawDiagnosticEventsState;
|
|
12
|
+
}
|
|
13
|
+
function isDiagnosticsEnabled(config) {
|
|
14
|
+
return config?.diagnostics?.enabled === true;
|
|
15
|
+
}
|
|
16
|
+
function emitDiagnosticEvent(event) {
|
|
17
|
+
const state = getDiagnosticEventsState();
|
|
18
|
+
if (state.dispatchDepth > 100) {
|
|
19
|
+
console.error(`[diagnostic-events] recursion guard tripped at depth=${state.dispatchDepth}, dropping type=${event.type}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const enriched = {
|
|
23
|
+
...event,
|
|
24
|
+
seq: state.seq += 1,
|
|
25
|
+
ts: Date.now()
|
|
26
|
+
};
|
|
27
|
+
state.dispatchDepth += 1;
|
|
28
|
+
for (const listener of state.listeners) try {
|
|
29
|
+
listener(enriched);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const errorMessage = err instanceof Error ? err.stack ?? err.message : typeof err === "string" ? err : String(err);
|
|
32
|
+
console.error(`[diagnostic-events] listener error type=${enriched.type} seq=${enriched.seq}: ${errorMessage}`);
|
|
33
|
+
}
|
|
34
|
+
state.dispatchDepth -= 1;
|
|
35
|
+
}
|
|
36
|
+
function onDiagnosticEvent(listener) {
|
|
37
|
+
const state = getDiagnosticEventsState();
|
|
38
|
+
state.listeners.add(listener);
|
|
39
|
+
return () => {
|
|
40
|
+
state.listeners.delete(listener);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/logging/diagnostic-session-state.ts
|
|
45
|
+
const diagnosticSessionStates = /* @__PURE__ */ new Map();
|
|
46
|
+
const SESSION_STATE_TTL_MS = 1800 * 1e3;
|
|
47
|
+
const SESSION_STATE_PRUNE_INTERVAL_MS = 60 * 1e3;
|
|
48
|
+
const SESSION_STATE_MAX_ENTRIES = 2e3;
|
|
49
|
+
let lastSessionPruneAt = 0;
|
|
50
|
+
function pruneDiagnosticSessionStates(now = Date.now(), force = false) {
|
|
51
|
+
const shouldPruneForSize = diagnosticSessionStates.size > SESSION_STATE_MAX_ENTRIES;
|
|
52
|
+
if (!force && !shouldPruneForSize && now - lastSessionPruneAt < SESSION_STATE_PRUNE_INTERVAL_MS) return;
|
|
53
|
+
lastSessionPruneAt = now;
|
|
54
|
+
for (const [key, state] of diagnosticSessionStates.entries()) {
|
|
55
|
+
const ageMs = now - state.lastActivity;
|
|
56
|
+
if (state.state === "idle" && state.queueDepth <= 0 && ageMs > SESSION_STATE_TTL_MS) diagnosticSessionStates.delete(key);
|
|
57
|
+
}
|
|
58
|
+
if (diagnosticSessionStates.size <= SESSION_STATE_MAX_ENTRIES) return;
|
|
59
|
+
const excess = diagnosticSessionStates.size - SESSION_STATE_MAX_ENTRIES;
|
|
60
|
+
const ordered = Array.from(diagnosticSessionStates.entries()).toSorted((a, b) => a[1].lastActivity - b[1].lastActivity);
|
|
61
|
+
for (let i = 0; i < excess; i += 1) {
|
|
62
|
+
const key = ordered[i]?.[0];
|
|
63
|
+
if (!key) break;
|
|
64
|
+
diagnosticSessionStates.delete(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function resolveSessionKey({ sessionKey, sessionId }) {
|
|
68
|
+
return sessionKey ?? sessionId ?? "unknown";
|
|
69
|
+
}
|
|
70
|
+
function findStateBySessionId(sessionId) {
|
|
71
|
+
for (const state of diagnosticSessionStates.values()) if (state.sessionId === sessionId) return state;
|
|
72
|
+
}
|
|
73
|
+
function getDiagnosticSessionState(ref) {
|
|
74
|
+
pruneDiagnosticSessionStates();
|
|
75
|
+
const key = resolveSessionKey(ref);
|
|
76
|
+
const existing = diagnosticSessionStates.get(key) ?? (ref.sessionId && findStateBySessionId(ref.sessionId));
|
|
77
|
+
if (existing) {
|
|
78
|
+
if (ref.sessionId) existing.sessionId = ref.sessionId;
|
|
79
|
+
if (ref.sessionKey) existing.sessionKey = ref.sessionKey;
|
|
80
|
+
return existing;
|
|
81
|
+
}
|
|
82
|
+
const created = {
|
|
83
|
+
sessionId: ref.sessionId,
|
|
84
|
+
sessionKey: ref.sessionKey,
|
|
85
|
+
lastActivity: Date.now(),
|
|
86
|
+
state: "idle",
|
|
87
|
+
queueDepth: 0
|
|
88
|
+
};
|
|
89
|
+
diagnosticSessionStates.set(key, created);
|
|
90
|
+
pruneDiagnosticSessionStates(Date.now(), true);
|
|
91
|
+
return created;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/logging/diagnostic.ts
|
|
95
|
+
const diag = createSubsystemLogger("diagnostic");
|
|
96
|
+
const webhookStats = {
|
|
97
|
+
received: 0,
|
|
98
|
+
processed: 0,
|
|
99
|
+
errors: 0,
|
|
100
|
+
lastReceived: 0
|
|
101
|
+
};
|
|
102
|
+
let lastActivityAt = 0;
|
|
103
|
+
const DEFAULT_STUCK_SESSION_WARN_MS = 12e4;
|
|
104
|
+
const MIN_STUCK_SESSION_WARN_MS = 1e3;
|
|
105
|
+
const MAX_STUCK_SESSION_WARN_MS = 1440 * 60 * 1e3;
|
|
106
|
+
let commandPollBackoffRuntimePromise = null;
|
|
107
|
+
function loadCommandPollBackoffRuntime() {
|
|
108
|
+
commandPollBackoffRuntimePromise ??= import("./command-poll-backoff.runtime-DSESnhU1.js");
|
|
109
|
+
return commandPollBackoffRuntimePromise;
|
|
110
|
+
}
|
|
111
|
+
function markActivity() {
|
|
112
|
+
lastActivityAt = Date.now();
|
|
113
|
+
}
|
|
114
|
+
function resolveStuckSessionWarnMs(config) {
|
|
115
|
+
const raw = config?.diagnostics?.stuckSessionWarnMs;
|
|
116
|
+
if (typeof raw !== "number" || !Number.isFinite(raw)) return DEFAULT_STUCK_SESSION_WARN_MS;
|
|
117
|
+
const rounded = Math.floor(raw);
|
|
118
|
+
if (rounded < MIN_STUCK_SESSION_WARN_MS || rounded > MAX_STUCK_SESSION_WARN_MS) return DEFAULT_STUCK_SESSION_WARN_MS;
|
|
119
|
+
return rounded;
|
|
120
|
+
}
|
|
121
|
+
function logWebhookReceived(params) {
|
|
122
|
+
webhookStats.received += 1;
|
|
123
|
+
webhookStats.lastReceived = Date.now();
|
|
124
|
+
if (diag.isEnabled("debug")) diag.debug(`webhook received: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${params.chatId ?? "unknown"} total=${webhookStats.received}`);
|
|
125
|
+
emitDiagnosticEvent({
|
|
126
|
+
type: "webhook.received",
|
|
127
|
+
channel: params.channel,
|
|
128
|
+
updateType: params.updateType,
|
|
129
|
+
chatId: params.chatId
|
|
130
|
+
});
|
|
131
|
+
markActivity();
|
|
132
|
+
}
|
|
133
|
+
function logWebhookProcessed(params) {
|
|
134
|
+
webhookStats.processed += 1;
|
|
135
|
+
if (diag.isEnabled("debug")) diag.debug(`webhook processed: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${params.chatId ?? "unknown"} duration=${params.durationMs ?? 0}ms processed=${webhookStats.processed}`);
|
|
136
|
+
emitDiagnosticEvent({
|
|
137
|
+
type: "webhook.processed",
|
|
138
|
+
channel: params.channel,
|
|
139
|
+
updateType: params.updateType,
|
|
140
|
+
chatId: params.chatId,
|
|
141
|
+
durationMs: params.durationMs
|
|
142
|
+
});
|
|
143
|
+
markActivity();
|
|
144
|
+
}
|
|
145
|
+
function logWebhookError(params) {
|
|
146
|
+
webhookStats.errors += 1;
|
|
147
|
+
diag.error(`webhook error: channel=${params.channel} type=${params.updateType ?? "unknown"} chatId=${params.chatId ?? "unknown"} error="${params.error}" errors=${webhookStats.errors}`);
|
|
148
|
+
emitDiagnosticEvent({
|
|
149
|
+
type: "webhook.error",
|
|
150
|
+
channel: params.channel,
|
|
151
|
+
updateType: params.updateType,
|
|
152
|
+
chatId: params.chatId,
|
|
153
|
+
error: params.error
|
|
154
|
+
});
|
|
155
|
+
markActivity();
|
|
156
|
+
}
|
|
157
|
+
function logMessageQueued(params) {
|
|
158
|
+
const state = getDiagnosticSessionState(params);
|
|
159
|
+
state.queueDepth += 1;
|
|
160
|
+
state.lastActivity = Date.now();
|
|
161
|
+
if (diag.isEnabled("debug")) diag.debug(`message queued: sessionId=${state.sessionId ?? "unknown"} sessionKey=${state.sessionKey ?? "unknown"} source=${params.source} queueDepth=${state.queueDepth} sessionState=${state.state}`);
|
|
162
|
+
emitDiagnosticEvent({
|
|
163
|
+
type: "message.queued",
|
|
164
|
+
sessionId: state.sessionId,
|
|
165
|
+
sessionKey: state.sessionKey,
|
|
166
|
+
channel: params.channel,
|
|
167
|
+
source: params.source,
|
|
168
|
+
queueDepth: state.queueDepth
|
|
169
|
+
});
|
|
170
|
+
markActivity();
|
|
171
|
+
}
|
|
172
|
+
function logMessageProcessed(params) {
|
|
173
|
+
if (params.outcome === "error" ? diag.isEnabled("error") : diag.isEnabled("debug")) {
|
|
174
|
+
const payload = `message processed: channel=${params.channel} chatId=${params.chatId ?? "unknown"} messageId=${params.messageId ?? "unknown"} sessionId=${params.sessionId ?? "unknown"} sessionKey=${params.sessionKey ?? "unknown"} outcome=${params.outcome} duration=${params.durationMs ?? 0}ms${params.reason ? ` reason=${params.reason}` : ""}${params.error ? ` error="${params.error}"` : ""}`;
|
|
175
|
+
if (params.outcome === "error") diag.error(payload);
|
|
176
|
+
else diag.debug(payload);
|
|
177
|
+
}
|
|
178
|
+
emitDiagnosticEvent({
|
|
179
|
+
type: "message.processed",
|
|
180
|
+
channel: params.channel,
|
|
181
|
+
chatId: params.chatId,
|
|
182
|
+
messageId: params.messageId,
|
|
183
|
+
sessionId: params.sessionId,
|
|
184
|
+
sessionKey: params.sessionKey,
|
|
185
|
+
durationMs: params.durationMs,
|
|
186
|
+
outcome: params.outcome,
|
|
187
|
+
reason: params.reason,
|
|
188
|
+
error: params.error
|
|
189
|
+
});
|
|
190
|
+
markActivity();
|
|
191
|
+
}
|
|
192
|
+
function logSessionStateChange(params) {
|
|
193
|
+
const state = getDiagnosticSessionState(params);
|
|
194
|
+
const isProbeSession = state.sessionId?.startsWith("probe-") ?? false;
|
|
195
|
+
const prevState = state.state;
|
|
196
|
+
state.state = params.state;
|
|
197
|
+
state.lastActivity = Date.now();
|
|
198
|
+
if (params.state === "idle") state.queueDepth = Math.max(0, state.queueDepth - 1);
|
|
199
|
+
if (!isProbeSession && diag.isEnabled("debug")) diag.debug(`session state: sessionId=${state.sessionId ?? "unknown"} sessionKey=${state.sessionKey ?? "unknown"} prev=${prevState} new=${params.state} reason="${params.reason ?? ""}" queueDepth=${state.queueDepth}`);
|
|
200
|
+
emitDiagnosticEvent({
|
|
201
|
+
type: "session.state",
|
|
202
|
+
sessionId: state.sessionId,
|
|
203
|
+
sessionKey: state.sessionKey,
|
|
204
|
+
prevState,
|
|
205
|
+
state: params.state,
|
|
206
|
+
reason: params.reason,
|
|
207
|
+
queueDepth: state.queueDepth
|
|
208
|
+
});
|
|
209
|
+
markActivity();
|
|
210
|
+
}
|
|
211
|
+
function logSessionStuck(params) {
|
|
212
|
+
const state = getDiagnosticSessionState(params);
|
|
213
|
+
diag.warn(`stuck session: sessionId=${state.sessionId ?? "unknown"} sessionKey=${state.sessionKey ?? "unknown"} state=${params.state} age=${Math.round(params.ageMs / 1e3)}s queueDepth=${state.queueDepth}`);
|
|
214
|
+
emitDiagnosticEvent({
|
|
215
|
+
type: "session.stuck",
|
|
216
|
+
sessionId: state.sessionId,
|
|
217
|
+
sessionKey: state.sessionKey,
|
|
218
|
+
state: params.state,
|
|
219
|
+
ageMs: params.ageMs,
|
|
220
|
+
queueDepth: state.queueDepth
|
|
221
|
+
});
|
|
222
|
+
markActivity();
|
|
223
|
+
}
|
|
224
|
+
function logLaneEnqueue(lane, queueSize) {
|
|
225
|
+
diag.debug(`lane enqueue: lane=${lane} queueSize=${queueSize}`);
|
|
226
|
+
emitDiagnosticEvent({
|
|
227
|
+
type: "queue.lane.enqueue",
|
|
228
|
+
lane,
|
|
229
|
+
queueSize
|
|
230
|
+
});
|
|
231
|
+
markActivity();
|
|
232
|
+
}
|
|
233
|
+
function logLaneDequeue(lane, waitMs, queueSize) {
|
|
234
|
+
diag.debug(`lane dequeue: lane=${lane} waitMs=${waitMs} queueSize=${queueSize}`);
|
|
235
|
+
emitDiagnosticEvent({
|
|
236
|
+
type: "queue.lane.dequeue",
|
|
237
|
+
lane,
|
|
238
|
+
queueSize,
|
|
239
|
+
waitMs
|
|
240
|
+
});
|
|
241
|
+
markActivity();
|
|
242
|
+
}
|
|
243
|
+
function logToolLoopAction(params) {
|
|
244
|
+
const payload = `tool loop: sessionId=${params.sessionId ?? "unknown"} sessionKey=${params.sessionKey ?? "unknown"} tool=${params.toolName} level=${params.level} action=${params.action} detector=${params.detector} count=${params.count}${params.pairedToolName ? ` pairedTool=${params.pairedToolName}` : ""} message="${params.message}"`;
|
|
245
|
+
if (params.level === "critical") diag.error(payload);
|
|
246
|
+
else diag.warn(payload);
|
|
247
|
+
emitDiagnosticEvent({
|
|
248
|
+
type: "tool.loop",
|
|
249
|
+
sessionId: params.sessionId,
|
|
250
|
+
sessionKey: params.sessionKey,
|
|
251
|
+
toolName: params.toolName,
|
|
252
|
+
level: params.level,
|
|
253
|
+
action: params.action,
|
|
254
|
+
detector: params.detector,
|
|
255
|
+
count: params.count,
|
|
256
|
+
message: params.message,
|
|
257
|
+
pairedToolName: params.pairedToolName
|
|
258
|
+
});
|
|
259
|
+
markActivity();
|
|
260
|
+
}
|
|
261
|
+
let heartbeatInterval = null;
|
|
262
|
+
function startDiagnosticHeartbeat(config) {
|
|
263
|
+
if (heartbeatInterval) return;
|
|
264
|
+
heartbeatInterval = setInterval(() => {
|
|
265
|
+
let heartbeatConfig = config;
|
|
266
|
+
if (!heartbeatConfig) try {
|
|
267
|
+
heartbeatConfig = loadConfig();
|
|
268
|
+
} catch {
|
|
269
|
+
heartbeatConfig = void 0;
|
|
270
|
+
}
|
|
271
|
+
const stuckSessionWarnMs = resolveStuckSessionWarnMs(heartbeatConfig);
|
|
272
|
+
const now = Date.now();
|
|
273
|
+
pruneDiagnosticSessionStates(now, true);
|
|
274
|
+
const activeCount = Array.from(diagnosticSessionStates.values()).filter((s) => s.state === "processing").length;
|
|
275
|
+
const waitingCount = Array.from(diagnosticSessionStates.values()).filter((s) => s.state === "waiting").length;
|
|
276
|
+
const totalQueued = Array.from(diagnosticSessionStates.values()).reduce((sum, s) => sum + s.queueDepth, 0);
|
|
277
|
+
if (!(lastActivityAt > 0 || webhookStats.received > 0 || activeCount > 0 || waitingCount > 0 || totalQueued > 0)) return;
|
|
278
|
+
if (now - lastActivityAt > 12e4 && activeCount === 0 && waitingCount === 0) return;
|
|
279
|
+
diag.debug(`heartbeat: webhooks=${webhookStats.received}/${webhookStats.processed}/${webhookStats.errors} active=${activeCount} waiting=${waitingCount} queued=${totalQueued}`);
|
|
280
|
+
emitDiagnosticEvent({
|
|
281
|
+
type: "diagnostic.heartbeat",
|
|
282
|
+
webhooks: {
|
|
283
|
+
received: webhookStats.received,
|
|
284
|
+
processed: webhookStats.processed,
|
|
285
|
+
errors: webhookStats.errors
|
|
286
|
+
},
|
|
287
|
+
active: activeCount,
|
|
288
|
+
waiting: waitingCount,
|
|
289
|
+
queued: totalQueued
|
|
290
|
+
});
|
|
291
|
+
loadCommandPollBackoffRuntime().then(({ pruneStaleCommandPolls }) => {
|
|
292
|
+
for (const [, state] of diagnosticSessionStates) pruneStaleCommandPolls(state);
|
|
293
|
+
}).catch((err) => {
|
|
294
|
+
diag.debug(`command-poll-backoff prune failed: ${String(err)}`);
|
|
295
|
+
});
|
|
296
|
+
for (const [, state] of diagnosticSessionStates) {
|
|
297
|
+
const ageMs = now - state.lastActivity;
|
|
298
|
+
if (state.state === "processing" && ageMs > stuckSessionWarnMs) logSessionStuck({
|
|
299
|
+
sessionId: state.sessionId,
|
|
300
|
+
sessionKey: state.sessionKey,
|
|
301
|
+
state: state.state,
|
|
302
|
+
ageMs
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}, 3e4);
|
|
306
|
+
heartbeatInterval.unref?.();
|
|
307
|
+
}
|
|
308
|
+
function stopDiagnosticHeartbeat() {
|
|
309
|
+
if (heartbeatInterval) {
|
|
310
|
+
clearInterval(heartbeatInterval);
|
|
311
|
+
heartbeatInterval = null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
export { logMessageQueued as a, logWebhookError as c, startDiagnosticHeartbeat as d, stopDiagnosticHeartbeat as f, onDiagnosticEvent as g, isDiagnosticsEnabled as h, logMessageProcessed as i, logWebhookProcessed as l, emitDiagnosticEvent as m, logLaneDequeue as n, logSessionStateChange as o, getDiagnosticSessionState as p, logLaneEnqueue as r, logToolLoopAction as s, diag as t, logWebhookReceived as u };
|