@yanhaidao/wecom 2.4.160 → 2.5.110
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.js +68 -0
- package/dist/src/accounts.js +20 -0
- package/dist/src/agent/handler.js +895 -0
- package/dist/src/agent/index.js +5 -0
- package/dist/src/app/account-runtime.js +216 -0
- package/dist/src/app/bootstrap.js +19 -0
- package/dist/src/app/index.js +118 -0
- package/dist/src/capability/agent/delivery-service.js +63 -0
- package/dist/src/capability/agent/fallback-policy.js +6 -0
- package/dist/src/capability/agent/ingress-service.js +33 -0
- package/dist/src/capability/agent/upstream-delivery-service.js +71 -0
- package/dist/src/capability/bot/dispatch-config.js +45 -0
- package/dist/src/capability/bot/fallback-delivery.js +147 -0
- package/dist/src/capability/bot/local-path-delivery.js +178 -0
- package/dist/src/capability/bot/sandbox-media.js +138 -0
- package/dist/src/capability/bot/service.js +49 -0
- package/dist/src/capability/bot/stream-delivery.js +321 -0
- package/dist/src/capability/bot/stream-finalizer.js +81 -0
- package/dist/src/capability/bot/stream-orchestrator.js +318 -0
- package/dist/src/capability/bot/types.js +1 -0
- package/{src/capability/calendar/client.ts → dist/src/capability/calendar/client.js} +118 -241
- package/{src/capability/calendar/schema.ts → dist/src/capability/calendar/schema.js} +0 -38
- package/dist/src/capability/calendar/tool.js +365 -0
- package/dist/src/capability/calendar/types.js +12 -0
- package/{src/capability/doc/client.ts → dist/src/capability/doc/client.js} +370 -605
- package/{src/capability/doc/schema.ts → dist/src/capability/doc/schema.js} +345 -394
- package/dist/src/capability/doc/tool.js +1556 -0
- package/dist/src/capability/doc/types.js +113 -0
- package/dist/src/capability/mcp/index.js +3 -0
- package/dist/src/capability/mcp/schema.js +102 -0
- package/dist/src/capability/mcp/tool.js +146 -0
- package/dist/src/capability/mcp/transport.js +293 -0
- package/dist/src/channel.js +224 -0
- package/dist/src/config/accounts.js +236 -0
- package/dist/src/config/derived-paths.js +31 -0
- package/dist/src/config/index.js +7 -0
- package/dist/src/config/media.js +110 -0
- package/dist/src/config/network.js +32 -0
- package/dist/src/config/routing.js +20 -0
- package/dist/src/config/runtime-config.js +25 -0
- package/dist/src/config/schema.js +4 -0
- package/{src/config-schema.ts → dist/src/config-schema.js} +1 -1
- package/dist/src/context-store.js +219 -0
- package/{src/crypto/aes.ts → dist/src/crypto/aes.js} +11 -28
- package/dist/src/crypto/index.js +9 -0
- package/{src/crypto/signature.ts → dist/src/crypto/signature.js} +3 -18
- package/{src/crypto/xml.ts → dist/src/crypto/xml.js} +3 -11
- package/dist/src/crypto.js +145 -0
- package/dist/src/domain/models.js +1 -0
- package/dist/src/domain/policies.js +32 -0
- package/{src/dynamic-agent.ts → dist/src/dynamic-agent.js} +36 -73
- package/dist/src/gateway-monitor.js +139 -0
- package/dist/src/http.js +114 -0
- package/{src/media.ts → dist/src/media.js} +21 -40
- package/dist/src/monitor/limits.js +7 -0
- package/dist/src/monitor/state.js +28 -0
- package/dist/src/monitor.js +84 -0
- package/dist/src/observability/audit-log.js +30 -0
- package/dist/src/observability/legacy-operational-event-store.js +22 -0
- package/dist/src/observability/raw-envelope-log.js +24 -0
- package/dist/src/observability/status-registry.js +9 -0
- package/dist/src/observability/transport-session-view.js +14 -0
- package/dist/src/onboarding.js +546 -0
- package/dist/src/outbound.js +557 -0
- package/dist/src/runtime/dispatcher.js +57 -0
- package/{src/runtime/index.ts → dist/src/runtime/index.js} +0 -1
- package/dist/src/runtime/outbound-intent.js +1 -0
- package/dist/src/runtime/reply-orchestrator.js +38 -0
- package/dist/src/runtime/routing-bridge.js +26 -0
- package/dist/src/runtime/session-manager.js +112 -0
- package/dist/src/runtime/source-registry.js +174 -0
- package/dist/src/runtime.js +1 -0
- package/dist/src/shared/command-auth.js +57 -0
- package/{src/shared/index.ts → dist/src/shared/index.js} +0 -1
- package/dist/src/shared/media-asset.js +65 -0
- package/dist/src/shared/media-service.js +59 -0
- package/dist/src/shared/media-types.js +1 -0
- package/{src/shared/xml-parser.ts → dist/src/shared/xml-parser.js} +72 -63
- package/dist/src/store/active-reply-store.js +41 -0
- package/dist/src/store/interfaces.js +1 -0
- package/dist/src/store/memory-store.js +33 -0
- package/dist/src/store/stream-batch-store.js +319 -0
- package/{src/target.ts → dist/src/target.js} +15 -48
- package/dist/src/transport/agent-api/client.js +168 -0
- package/dist/src/transport/agent-api/core.js +337 -0
- package/dist/src/transport/agent-api/delivery.js +28 -0
- package/dist/src/transport/agent-api/media-upload.js +4 -0
- package/dist/src/transport/agent-api/reply.js +24 -0
- package/dist/src/transport/agent-api/upstream-delivery.js +30 -0
- package/dist/src/transport/agent-api/upstream-media-upload.js +46 -0
- package/dist/src/transport/agent-api/upstream-reply.js +26 -0
- package/dist/src/transport/agent-callback/http-handler.js +30 -0
- package/dist/src/transport/agent-callback/inbound.js +4 -0
- package/dist/src/transport/agent-callback/reply.js +8 -0
- package/dist/src/transport/agent-callback/request-handler.js +189 -0
- package/dist/src/transport/agent-callback/session.js +15 -0
- package/dist/src/transport/bot-webhook/active-reply.js +27 -0
- package/dist/src/transport/bot-webhook/http-handler.js +31 -0
- package/dist/src/transport/bot-webhook/inbound-normalizer.js +496 -0
- package/dist/src/transport/bot-webhook/inbound.js +4 -0
- package/dist/src/transport/bot-webhook/message-shape.js +98 -0
- package/dist/src/transport/bot-webhook/protocol.js +124 -0
- package/dist/src/transport/bot-webhook/reply.js +9 -0
- package/dist/src/transport/bot-webhook/request-handler.js +285 -0
- package/dist/src/transport/bot-webhook/session.js +15 -0
- package/dist/src/transport/bot-ws/inbound.js +147 -0
- package/dist/src/transport/bot-ws/media.js +236 -0
- package/dist/src/transport/bot-ws/reply.js +310 -0
- package/dist/src/transport/bot-ws/sdk-adapter.js +257 -0
- package/dist/src/transport/bot-ws/session.js +15 -0
- package/dist/src/transport/http/common.js +78 -0
- package/dist/src/transport/http/registry.js +71 -0
- package/dist/src/transport/http/request-handler.js +51 -0
- package/{src/transport/index.ts → dist/src/transport/index.js} +2 -10
- package/dist/src/types/account.js +1 -0
- package/dist/src/types/config.js +1 -0
- package/dist/src/types/constants.js +28 -0
- package/dist/src/types/events.js +1 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/types/legacy-stream.js +1 -0
- package/dist/src/types/message.js +5 -0
- package/dist/src/types/runtime-context.js +1 -0
- package/dist/src/types/runtime.js +1 -0
- package/dist/src/types.js +1 -0
- package/dist/src/upstream/index.js +111 -0
- package/dist/src/wecom_msg_adapter/markdown_adapter.js +280 -0
- package/openclaw.plugin.json +15 -0
- package/package.json +18 -1
- package/.github/workflows/release.yml +0 -143
- package/GOVERNANCE.md +0 -26
- package/SKILLS_CAL.md +0 -895
- package/SKILLS_DOC.md +0 -2288
- package/UPSTREAM_CONFIG.md +0 -170
- package/UPSTREAM_PLAN.md +0 -175
- package/assets/01.bot-add.png +0 -0
- package/assets/01.bot-setp2.png +0 -0
- package/assets/01.image.jpg +0 -0
- package/assets/02.agent.add.png +0 -0
- package/assets/02.agent.api-set.png +0 -0
- package/assets/02.image.jpg +0 -0
- package/assets/03.agent.page.png +0 -0
- package/assets/03.bot.page.png +0 -0
- package/assets/link-me.jpg +0 -0
- package/assets/register.png +0 -0
- package/changelog/v2.2.28.md +0 -70
- package/changelog/v2.3.10.md +0 -17
- package/changelog/v2.3.11.md +0 -19
- package/changelog/v2.3.12.md +0 -25
- package/changelog/v2.3.13.md +0 -19
- package/changelog/v2.3.14.md +0 -48
- package/changelog/v2.3.15.md +0 -15
- package/changelog/v2.3.16.md +0 -11
- package/changelog/v2.3.18.md +0 -22
- package/changelog/v2.3.19.md +0 -73
- package/changelog/v2.3.2.md +0 -28
- package/changelog/v2.3.26.md +0 -21
- package/changelog/v2.3.27.md +0 -33
- package/changelog/v2.3.4.md +0 -20
- package/changelog/v2.3.9.md +0 -22
- package/changelog/v2.4.12.md +0 -37
- package/changelog/v2.4.16.md +0 -19
- package/compat-single-account.md +0 -148
- package/index.test.ts +0 -38
- package/scripts/test-proxy.ts +0 -70
- package/src/accounts.ts +0 -34
- package/src/agent/api-client.upload.test.ts +0 -109
- package/src/agent/handler.event-filter.test.ts +0 -100
- package/src/agent/handler.ts +0 -1105
- package/src/agent/index.ts +0 -12
- package/src/app/account-runtime.ts +0 -276
- package/src/app/bootstrap.ts +0 -29
- package/src/app/index.ts +0 -192
- package/src/capability/agent/delivery-service.ts +0 -87
- package/src/capability/agent/fallback-policy.ts +0 -13
- package/src/capability/agent/ingress-service.ts +0 -38
- package/src/capability/agent/upstream-delivery-service.ts +0 -96
- package/src/capability/bot/dispatch-config.ts +0 -47
- package/src/capability/bot/fallback-delivery.ts +0 -178
- package/src/capability/bot/local-path-delivery.ts +0 -215
- package/src/capability/bot/sandbox-media.test.ts +0 -221
- package/src/capability/bot/sandbox-media.ts +0 -176
- package/src/capability/bot/service.ts +0 -56
- package/src/capability/bot/stream-delivery.ts +0 -379
- package/src/capability/bot/stream-finalizer.ts +0 -120
- package/src/capability/bot/stream-orchestrator.ts +0 -371
- package/src/capability/bot/types.ts +0 -8
- package/src/capability/calendar/SKILLS_CHECKLIST.md +0 -251
- package/src/capability/calendar/tool.ts +0 -417
- package/src/capability/calendar/types.ts +0 -309
- package/src/capability/doc/tool.ts +0 -1629
- package/src/capability/doc/types.ts +0 -792
- package/src/capability/mcp/index.ts +0 -10
- package/src/capability/mcp/schema.ts +0 -107
- package/src/capability/mcp/tool.ts +0 -174
- package/src/capability/mcp/transport.ts +0 -394
- package/src/channel.config.test.ts +0 -147
- package/src/channel.lifecycle.test.ts +0 -255
- package/src/channel.meta.test.ts +0 -26
- package/src/channel.ts +0 -256
- package/src/config/accounts.resolve.test.ts +0 -75
- package/src/config/accounts.ts +0 -296
- package/src/config/derived-paths.test.ts +0 -111
- package/src/config/derived-paths.ts +0 -41
- package/src/config/index.ts +0 -26
- package/src/config/media.test.ts +0 -113
- package/src/config/media.ts +0 -139
- package/src/config/network.ts +0 -53
- package/src/config/routing.test.ts +0 -88
- package/src/config/routing.ts +0 -26
- package/src/config/runtime-config.ts +0 -46
- package/src/config/schema.ts +0 -90
- package/src/context-store.ts +0 -297
- package/src/crypto/index.ts +0 -24
- package/src/crypto.test.ts +0 -32
- package/src/crypto.ts +0 -176
- package/src/domain/models.ts +0 -7
- package/src/domain/policies.ts +0 -36
- package/src/dynamic-agent.account-scope.test.ts +0 -17
- package/src/gateway-monitor.ts +0 -181
- package/src/http.ts +0 -145
- package/src/media.test.ts +0 -82
- package/src/monitor/limits.ts +0 -7
- package/src/monitor/state.queue.test.ts +0 -185
- package/src/monitor/state.ts +0 -34
- package/src/monitor.active.test.ts +0 -245
- package/src/monitor.inbound-filter.test.ts +0 -63
- package/src/monitor.integration.test.ts +0 -208
- package/src/monitor.ts +0 -121
- package/src/monitor.webhook.test.ts +0 -774
- package/src/observability/audit-log.ts +0 -48
- package/src/observability/legacy-operational-event-store.ts +0 -36
- package/src/observability/raw-envelope-log.ts +0 -28
- package/src/observability/status-registry.ts +0 -13
- package/src/observability/transport-session-view.ts +0 -14
- package/src/onboarding.test.ts +0 -336
- package/src/onboarding.ts +0 -704
- package/src/outbound.test.ts +0 -1271
- package/src/outbound.ts +0 -746
- package/src/runtime/dispatcher.ts +0 -71
- package/src/runtime/outbound-intent.ts +0 -4
- package/src/runtime/reply-orchestrator.test.ts +0 -71
- package/src/runtime/reply-orchestrator.ts +0 -67
- package/src/runtime/routing-bridge.test.ts +0 -115
- package/src/runtime/routing-bridge.ts +0 -44
- package/src/runtime/session-manager.test.ts +0 -174
- package/src/runtime/session-manager.ts +0 -139
- package/src/runtime/source-registry.ts +0 -249
- package/src/runtime.ts +0 -14
- package/src/shared/command-auth.ts +0 -87
- package/src/shared/media-asset.ts +0 -78
- package/src/shared/media-service.test.ts +0 -111
- package/src/shared/media-service.ts +0 -84
- package/src/shared/media-types.ts +0 -5
- package/src/shared/xml-parser.test.ts +0 -50
- package/src/store/active-reply-store.ts +0 -42
- package/src/store/interfaces.ts +0 -11
- package/src/store/memory-store.ts +0 -43
- package/src/store/stream-batch-store.ts +0 -350
- package/src/transport/agent-api/client.ts +0 -277
- package/src/transport/agent-api/core.ts +0 -463
- package/src/transport/agent-api/delivery.ts +0 -41
- package/src/transport/agent-api/media-upload.ts +0 -11
- package/src/transport/agent-api/reply.ts +0 -39
- package/src/transport/agent-api/upstream-delivery.ts +0 -45
- package/src/transport/agent-api/upstream-media-upload.ts +0 -70
- package/src/transport/agent-api/upstream-reply.ts +0 -43
- package/src/transport/agent-callback/http-handler.ts +0 -47
- package/src/transport/agent-callback/inbound.ts +0 -5
- package/src/transport/agent-callback/reply.ts +0 -13
- package/src/transport/agent-callback/request-handler.ts +0 -244
- package/src/transport/agent-callback/session.ts +0 -23
- package/src/transport/bot-webhook/active-reply.ts +0 -39
- package/src/transport/bot-webhook/http-handler.ts +0 -48
- package/src/transport/bot-webhook/inbound-normalizer.test.ts +0 -433
- package/src/transport/bot-webhook/inbound-normalizer.ts +0 -558
- package/src/transport/bot-webhook/inbound.ts +0 -5
- package/src/transport/bot-webhook/message-shape.ts +0 -92
- package/src/transport/bot-webhook/protocol.ts +0 -148
- package/src/transport/bot-webhook/reply.ts +0 -15
- package/src/transport/bot-webhook/request-handler.ts +0 -394
- package/src/transport/bot-webhook/session.ts +0 -23
- package/src/transport/bot-ws/inbound.test.ts +0 -290
- package/src/transport/bot-ws/inbound.ts +0 -163
- package/src/transport/bot-ws/media.test.ts +0 -44
- package/src/transport/bot-ws/media.ts +0 -321
- package/src/transport/bot-ws/reply.test.ts +0 -450
- package/src/transport/bot-ws/reply.ts +0 -365
- package/src/transport/bot-ws/sdk-adapter.test.ts +0 -187
- package/src/transport/bot-ws/sdk-adapter.ts +0 -314
- package/src/transport/bot-ws/session.ts +0 -28
- package/src/transport/http/common.ts +0 -109
- package/src/transport/http/registry.ts +0 -92
- package/src/transport/http/request-handler.ts +0 -84
- package/src/types/account.ts +0 -70
- package/src/types/config.ts +0 -114
- package/src/types/constants.ts +0 -31
- package/src/types/events.ts +0 -21
- package/src/types/global.d.ts +0 -9
- package/src/types/index.ts +0 -17
- package/src/types/legacy-stream.ts +0 -50
- package/src/types/message.ts +0 -189
- package/src/types/runtime-context.ts +0 -28
- package/src/types/runtime.ts +0 -165
- package/src/types.ts +0 -41
- package/src/upstream/index.ts +0 -150
- package/src/upstream.test.ts +0 -84
- package/src/wecom_msg_adapter/markdown_adapter.ts +0 -331
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -26
- /package/{src/capability/agent/index.ts → dist/src/capability/agent/index.js} +0 -0
- /package/{src/capability/bot/index.ts → dist/src/capability/bot/index.js} +0 -0
- /package/{src/capability/calendar/index.ts → dist/src/capability/calendar/index.js} +0 -0
- /package/{src/capability/index.ts → dist/src/capability/index.js} +0 -0
package/src/config/media.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
4
|
-
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/infra-runtime";
|
|
5
|
-
import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/media-runtime";
|
|
6
|
-
|
|
7
|
-
// 默认给一个相对“够用”的上限(80MB),避免视频/较大文件频繁触发失败。
|
|
8
|
-
// 仍保留上限以防止恶意大文件把进程内存打爆(下载实现会读入内存再保存)。
|
|
9
|
-
export const DEFAULT_WECOM_MEDIA_MAX_BYTES = 80 * 1024 * 1024;
|
|
10
|
-
|
|
11
|
-
function parsePositiveNumber(value: unknown): number | undefined {
|
|
12
|
-
const parsed = typeof value === "number" ? value : Number(value);
|
|
13
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
return parsed;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function resolveStateDirForWecomMedia(): string {
|
|
20
|
-
const stateOverride =
|
|
21
|
-
process.env.OPENCLAW_STATE_DIR?.trim() || process.env.CLAWDBOT_STATE_DIR?.trim();
|
|
22
|
-
if (stateOverride) {
|
|
23
|
-
return stateOverride;
|
|
24
|
-
}
|
|
25
|
-
return path.join(os.homedir(), ".openclaw");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function normalizeWecomLocalRoot(root: string): string | undefined {
|
|
29
|
-
const trimmed = root.trim();
|
|
30
|
-
if (!trimmed) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return path.resolve(trimmed.replace(/^~(?=\/|$)/, os.homedir()));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getWecomCommonUserMediaLocalRoots(): readonly string[] {
|
|
37
|
-
const home = os.homedir();
|
|
38
|
-
return [
|
|
39
|
-
path.join(home, "Desktop"),
|
|
40
|
-
path.join(home, "Documents"),
|
|
41
|
-
path.join(home, "Downloads"),
|
|
42
|
-
path.join(home, "Movies"),
|
|
43
|
-
path.join(home, "Pictures"),
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getWecomDefaultMediaLocalRoots(): readonly string[] {
|
|
48
|
-
const stateDir = path.resolve(resolveStateDirForWecomMedia());
|
|
49
|
-
return [
|
|
50
|
-
path.resolve(resolvePreferredOpenClawTmpDir()),
|
|
51
|
-
stateDir,
|
|
52
|
-
path.join(stateDir, "media"),
|
|
53
|
-
path.join(stateDir, "agents"),
|
|
54
|
-
path.join(stateDir, "workspace"),
|
|
55
|
-
path.join(stateDir, "sandboxes"),
|
|
56
|
-
...getWecomCommonUserMediaLocalRoots(),
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function resolveWecomConfiguredMediaLocalRoots(cfg: OpenClawConfig): readonly string[] {
|
|
61
|
-
const rawWecom = cfg.channels?.wecom as
|
|
62
|
-
| {
|
|
63
|
-
media?: { localRoots?: unknown };
|
|
64
|
-
mediaLocalRoots?: unknown;
|
|
65
|
-
}
|
|
66
|
-
| undefined;
|
|
67
|
-
const configured = Array.isArray(rawWecom?.media?.localRoots)
|
|
68
|
-
? rawWecom.media.localRoots
|
|
69
|
-
: Array.isArray(rawWecom?.mediaLocalRoots)
|
|
70
|
-
? rawWecom.mediaLocalRoots
|
|
71
|
-
: [];
|
|
72
|
-
return configured
|
|
73
|
-
.filter((root): root is string => typeof root === "string")
|
|
74
|
-
.map(normalizeWecomLocalRoot)
|
|
75
|
-
.filter((root): root is string => Boolean(root));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function resolveWecomMergedMediaLocalRoots(params: {
|
|
79
|
-
cfg: OpenClawConfig;
|
|
80
|
-
baseRoots?: readonly string[];
|
|
81
|
-
}): readonly string[] {
|
|
82
|
-
const merged: string[] = [];
|
|
83
|
-
const seen = new Set<string>();
|
|
84
|
-
const pushRoot = (root: string) => {
|
|
85
|
-
const normalized = normalizeWecomLocalRoot(root);
|
|
86
|
-
if (!normalized || seen.has(normalized)) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
seen.add(normalized);
|
|
90
|
-
merged.push(normalized);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
for (const root of getWecomDefaultMediaLocalRoots()) {
|
|
94
|
-
pushRoot(root);
|
|
95
|
-
}
|
|
96
|
-
for (const root of params.baseRoots ?? []) {
|
|
97
|
-
pushRoot(root);
|
|
98
|
-
}
|
|
99
|
-
for (const root of resolveWecomConfiguredMediaLocalRoots(params.cfg)) {
|
|
100
|
-
pushRoot(root);
|
|
101
|
-
}
|
|
102
|
-
return merged;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function resolveLegacyWecomMediaMaxBytes(cfg: OpenClawConfig): number | undefined {
|
|
106
|
-
const raw = (cfg.channels?.wecom as any)?.media?.maxBytes;
|
|
107
|
-
const bytes = parsePositiveNumber(raw);
|
|
108
|
-
if (bytes) {
|
|
109
|
-
return Math.floor(bytes);
|
|
110
|
-
}
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function resolveWecomMediaMaxBytes(
|
|
115
|
-
cfg: OpenClawConfig,
|
|
116
|
-
accountId?: string | null,
|
|
117
|
-
): number {
|
|
118
|
-
const mediaMaxBytes = resolveChannelMediaMaxBytes({
|
|
119
|
-
cfg,
|
|
120
|
-
accountId,
|
|
121
|
-
resolveChannelLimitMb: ({ cfg, accountId }) => {
|
|
122
|
-
const wecom = cfg.channels?.wecom as
|
|
123
|
-
| {
|
|
124
|
-
mediaMaxMb?: unknown;
|
|
125
|
-
accounts?: Record<string, { mediaMaxMb?: unknown }>;
|
|
126
|
-
}
|
|
127
|
-
| undefined;
|
|
128
|
-
const accountLimitMb = parsePositiveNumber(wecom?.accounts?.[accountId]?.mediaMaxMb);
|
|
129
|
-
if (accountLimitMb) {
|
|
130
|
-
return accountLimitMb;
|
|
131
|
-
}
|
|
132
|
-
return parsePositiveNumber(wecom?.mediaMaxMb);
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
if (mediaMaxBytes) {
|
|
136
|
-
return mediaMaxBytes;
|
|
137
|
-
}
|
|
138
|
-
return resolveLegacyWecomMediaMaxBytes(cfg) ?? DEFAULT_WECOM_MEDIA_MAX_BYTES;
|
|
139
|
-
}
|
package/src/config/network.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
|
-
|
|
3
|
-
import type { WecomConfig, WecomNetworkConfig } from "../types/index.js";
|
|
4
|
-
|
|
5
|
-
const DEFAULT_WECOM_MEDIA_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
6
|
-
|
|
7
|
-
function parsePositiveInt(value: unknown): number | undefined {
|
|
8
|
-
const parsed = typeof value === "number" ? value : Number(value);
|
|
9
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return Math.floor(parsed);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function resolveWecomEgressProxyUrlFromNetwork(network?: WecomNetworkConfig): string | undefined {
|
|
16
|
-
const proxyUrl = network?.egressProxyUrl ??
|
|
17
|
-
process.env.OPENCLAW_WECOM_EGRESS_PROXY_URL ??
|
|
18
|
-
process.env.WECOM_EGRESS_PROXY_URL ??
|
|
19
|
-
process.env.HTTPS_PROXY ??
|
|
20
|
-
process.env.ALL_PROXY ??
|
|
21
|
-
process.env.HTTP_PROXY ??
|
|
22
|
-
"";
|
|
23
|
-
|
|
24
|
-
return proxyUrl.trim() || undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function resolveWecomEgressProxyUrl(cfg: OpenClawConfig): string | undefined {
|
|
28
|
-
const wecom = cfg.channels?.wecom as WecomConfig | undefined;
|
|
29
|
-
return resolveWecomEgressProxyUrlFromNetwork(wecom?.network);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function resolveWecomMediaDownloadTimeoutMs(cfg: OpenClawConfig): number {
|
|
33
|
-
const wecom = cfg.channels?.wecom as
|
|
34
|
-
| {
|
|
35
|
-
media?: { downloadTimeoutMs?: unknown };
|
|
36
|
-
mediaDownloadTimeoutMs?: unknown;
|
|
37
|
-
network?: {
|
|
38
|
-
mediaDownloadTimeoutMs?: unknown;
|
|
39
|
-
timeoutMs?: unknown;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
| undefined;
|
|
43
|
-
|
|
44
|
-
const timeoutMs =
|
|
45
|
-
parsePositiveInt(wecom?.media?.downloadTimeoutMs) ??
|
|
46
|
-
parsePositiveInt(wecom?.mediaDownloadTimeoutMs) ??
|
|
47
|
-
parsePositiveInt(wecom?.network?.mediaDownloadTimeoutMs) ??
|
|
48
|
-
parsePositiveInt(wecom?.network?.timeoutMs) ??
|
|
49
|
-
parsePositiveInt(process.env.OPENCLAW_WECOM_MEDIA_TIMEOUT_MS) ??
|
|
50
|
-
parsePositiveInt(process.env.WECOM_MEDIA_TIMEOUT_MS);
|
|
51
|
-
|
|
52
|
-
return timeoutMs ?? DEFAULT_WECOM_MEDIA_DOWNLOAD_TIMEOUT_MS;
|
|
53
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
3
|
-
|
|
4
|
-
import { resolveWecomFailClosedOnDefaultRoute, shouldRejectWecomDefaultRoute } from "./routing.js";
|
|
5
|
-
|
|
6
|
-
describe("resolveWecomFailClosedOnDefaultRoute", () => {
|
|
7
|
-
it("defaults to true in matrix mode", () => {
|
|
8
|
-
const cfg: OpenClawConfig = {
|
|
9
|
-
channels: {
|
|
10
|
-
wecom: {
|
|
11
|
-
enabled: true,
|
|
12
|
-
accounts: {
|
|
13
|
-
a: { enabled: true, bot: { token: "t1", encodingAESKey: "k1" } },
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
} as OpenClawConfig;
|
|
18
|
-
expect(resolveWecomFailClosedOnDefaultRoute(cfg)).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("defaults to false in legacy mode", () => {
|
|
22
|
-
const cfg: OpenClawConfig = {
|
|
23
|
-
channels: {
|
|
24
|
-
wecom: {
|
|
25
|
-
enabled: true,
|
|
26
|
-
bot: { token: "t1", encodingAESKey: "k1" },
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
} as OpenClawConfig;
|
|
30
|
-
expect(resolveWecomFailClosedOnDefaultRoute(cfg)).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("respects explicit override", () => {
|
|
34
|
-
const cfg: OpenClawConfig = {
|
|
35
|
-
channels: {
|
|
36
|
-
wecom: {
|
|
37
|
-
enabled: true,
|
|
38
|
-
bot: { token: "t1", encodingAESKey: "k1" },
|
|
39
|
-
routing: { failClosedOnDefaultRoute: true },
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
} as OpenClawConfig;
|
|
43
|
-
expect(resolveWecomFailClosedOnDefaultRoute(cfg)).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("shouldRejectWecomDefaultRoute", () => {
|
|
48
|
-
const matrixCfg = {
|
|
49
|
-
channels: {
|
|
50
|
-
wecom: {
|
|
51
|
-
enabled: true,
|
|
52
|
-
accounts: {
|
|
53
|
-
a: { enabled: true, bot: { token: "t1", encodingAESKey: "k1" } },
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
} as OpenClawConfig;
|
|
58
|
-
|
|
59
|
-
it("rejects default route in matrix mode when dynamic agent is disabled", () => {
|
|
60
|
-
expect(
|
|
61
|
-
shouldRejectWecomDefaultRoute({
|
|
62
|
-
cfg: matrixCfg,
|
|
63
|
-
matchedBy: "default",
|
|
64
|
-
useDynamicAgent: false,
|
|
65
|
-
}),
|
|
66
|
-
).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("does not reject when route already matched a binding", () => {
|
|
70
|
-
expect(
|
|
71
|
-
shouldRejectWecomDefaultRoute({
|
|
72
|
-
cfg: matrixCfg,
|
|
73
|
-
matchedBy: "binding.account",
|
|
74
|
-
useDynamicAgent: false,
|
|
75
|
-
}),
|
|
76
|
-
).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("does not reject when dynamic agent routing is enabled", () => {
|
|
80
|
-
expect(
|
|
81
|
-
shouldRejectWecomDefaultRoute({
|
|
82
|
-
cfg: matrixCfg,
|
|
83
|
-
matchedBy: "default",
|
|
84
|
-
useDynamicAgent: true,
|
|
85
|
-
}),
|
|
86
|
-
).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
});
|
package/src/config/routing.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
|
-
|
|
3
|
-
import type { WecomConfig } from "../types/index.js";
|
|
4
|
-
import { detectMode } from "./accounts.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 默认策略:
|
|
8
|
-
* - matrix(多账号): 开启 fail-closed,防止未绑定账号回退到 main
|
|
9
|
-
* - legacy(单账号兼容): 维持历史行为,不强制拦截
|
|
10
|
-
*/
|
|
11
|
-
export function resolveWecomFailClosedOnDefaultRoute(cfg: OpenClawConfig): boolean {
|
|
12
|
-
const wecom = cfg.channels?.wecom as WecomConfig | undefined;
|
|
13
|
-
const explicit = wecom?.routing?.failClosedOnDefaultRoute;
|
|
14
|
-
if (typeof explicit === "boolean") return explicit;
|
|
15
|
-
return detectMode(wecom) === "matrix";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function shouldRejectWecomDefaultRoute(params: {
|
|
19
|
-
cfg: OpenClawConfig;
|
|
20
|
-
matchedBy: string;
|
|
21
|
-
useDynamicAgent: boolean;
|
|
22
|
-
}): boolean {
|
|
23
|
-
if (params.matchedBy !== "default") return false;
|
|
24
|
-
if (params.useDynamicAgent) return false;
|
|
25
|
-
return resolveWecomFailClosedOnDefaultRoute(params.cfg);
|
|
26
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
|
-
|
|
3
|
-
import { resolveDerivedPathSummary } from "./derived-paths.js";
|
|
4
|
-
import { DEFAULT_ACCOUNT_ID, resolveWecomAccount, resolveWecomAccounts } from "./accounts.js";
|
|
5
|
-
import type { ResolvedWecomAccount, WecomConfig } from "../types/index.js";
|
|
6
|
-
|
|
7
|
-
export type ResolvedRuntimeAccount = {
|
|
8
|
-
account: ResolvedWecomAccount;
|
|
9
|
-
derivedPaths: ReturnType<typeof resolveDerivedPathSummary>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type ResolvedRuntimeConfig = {
|
|
13
|
-
raw: WecomConfig | undefined;
|
|
14
|
-
defaultAccountId: string;
|
|
15
|
-
accounts: Record<string, ResolvedRuntimeAccount>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function resolveWecomRuntimeConfig(cfg: OpenClawConfig): ResolvedRuntimeConfig {
|
|
19
|
-
const raw = cfg.channels?.wecom as WecomConfig | undefined;
|
|
20
|
-
const resolved = resolveWecomAccounts(cfg);
|
|
21
|
-
const accounts = Object.fromEntries(
|
|
22
|
-
Object.entries(resolved.accounts).map(([accountId, account]) => [
|
|
23
|
-
accountId,
|
|
24
|
-
{
|
|
25
|
-
account,
|
|
26
|
-
derivedPaths: resolveDerivedPathSummary(accountId),
|
|
27
|
-
},
|
|
28
|
-
]),
|
|
29
|
-
);
|
|
30
|
-
return {
|
|
31
|
-
raw,
|
|
32
|
-
defaultAccountId: resolved.defaultAccountId || DEFAULT_ACCOUNT_ID,
|
|
33
|
-
accounts,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function resolveWecomRuntimeAccount(params: {
|
|
38
|
-
cfg: OpenClawConfig;
|
|
39
|
-
accountId?: string | null;
|
|
40
|
-
}): ResolvedRuntimeAccount {
|
|
41
|
-
const account = resolveWecomAccount(params);
|
|
42
|
-
return {
|
|
43
|
-
account,
|
|
44
|
-
derivedPaths: resolveDerivedPathSummary(account.accountId),
|
|
45
|
-
};
|
|
46
|
-
}
|
package/src/config/schema.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
export interface DmConfig {
|
|
2
|
-
policy?: "pairing" | "allowlist" | "open" | "disabled";
|
|
3
|
-
allowFrom?: (string | number)[];
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface MediaConfig {
|
|
7
|
-
tempDir?: string;
|
|
8
|
-
retentionHours?: number;
|
|
9
|
-
cleanupOnStart?: boolean;
|
|
10
|
-
maxBytes?: number;
|
|
11
|
-
downloadTimeoutMs?: number;
|
|
12
|
-
localRoots?: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface NetworkConfig {
|
|
16
|
-
egressProxyUrl?: string;
|
|
17
|
-
timeoutMs?: number;
|
|
18
|
-
mediaDownloadTimeoutMs?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface RoutingConfig {
|
|
22
|
-
failClosedOnDefaultRoute?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface BotWsConfig {
|
|
26
|
-
botId: string;
|
|
27
|
-
secret: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface BotWebhookConfig {
|
|
31
|
-
token: string;
|
|
32
|
-
encodingAESKey: string;
|
|
33
|
-
receiveId?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface BotConfig {
|
|
37
|
-
primaryTransport?: "ws" | "webhook";
|
|
38
|
-
streamPlaceholderContent?: string;
|
|
39
|
-
welcomeText?: string;
|
|
40
|
-
dm?: DmConfig;
|
|
41
|
-
aibotid?: string;
|
|
42
|
-
botIds?: string[];
|
|
43
|
-
ws?: BotWsConfig;
|
|
44
|
-
webhook?: BotWebhookConfig;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface AgentConfig {
|
|
48
|
-
corpId: string;
|
|
49
|
-
agentSecret?: string;
|
|
50
|
-
corpSecret?: string;
|
|
51
|
-
agentId?: number | string;
|
|
52
|
-
token: string;
|
|
53
|
-
encodingAESKey: string;
|
|
54
|
-
welcomeText?: string;
|
|
55
|
-
dm?: DmConfig;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface DynamicAgentsConfig {
|
|
59
|
-
enabled?: boolean;
|
|
60
|
-
dmCreateAgent?: boolean;
|
|
61
|
-
groupEnabled?: boolean;
|
|
62
|
-
adminUsers?: string[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface AccountConfig {
|
|
66
|
-
enabled?: boolean;
|
|
67
|
-
name?: string;
|
|
68
|
-
mediaMaxMb?: number;
|
|
69
|
-
bot?: BotConfig;
|
|
70
|
-
agent?: AgentConfig;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface WecomConfigInput {
|
|
74
|
-
enabled?: boolean;
|
|
75
|
-
mediaMaxMb?: number;
|
|
76
|
-
mediaDownloadTimeoutMs?: number;
|
|
77
|
-
bot?: BotConfig;
|
|
78
|
-
agent?: AgentConfig;
|
|
79
|
-
accounts?: Record<string, AccountConfig>;
|
|
80
|
-
defaultAccount?: string;
|
|
81
|
-
media?: MediaConfig;
|
|
82
|
-
network?: NetworkConfig;
|
|
83
|
-
routing?: RoutingConfig;
|
|
84
|
-
dynamicAgents?: DynamicAgentsConfig;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @deprecated No longer a Zod schema. Kept as a type-only export for backward compatibility.
|
|
89
|
-
*/
|
|
90
|
-
export const WecomConfigSchema = undefined;
|