@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
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { deleteAccountFromConfigSection, setAccountEnabledInConfigSection, } from "openclaw/plugin-sdk/core";
|
|
2
|
+
import { DEFAULT_ACCOUNT_ID, listWecomAccountIds, resolveDerivedPathSummary, resolveDefaultWecomAccountId, resolveWecomAccount, resolveWecomAccountConflict, } from "./config/index.js";
|
|
3
|
+
import { monitorWecomProvider } from "./gateway-monitor.js";
|
|
4
|
+
import { wecomSetupWizard } from "./onboarding.js";
|
|
5
|
+
import { wecomOutbound } from "./outbound.js";
|
|
6
|
+
const meta = {
|
|
7
|
+
id: "wecom",
|
|
8
|
+
label: "WeCom (企业微信)",
|
|
9
|
+
selectionLabel: "WeCom (企业微信)",
|
|
10
|
+
docsPath: "/channels/wecom",
|
|
11
|
+
docsLabel: "企业微信",
|
|
12
|
+
blurb: "企业微信官方推荐三方插件,默认 Bot WS 配置简单,支持主动发消息与 Agent 全能力。",
|
|
13
|
+
selectionDocsPrefix: "文档:",
|
|
14
|
+
aliases: ["wechatwork", "wework", "qywx", "企微", "企业微信"],
|
|
15
|
+
order: 85,
|
|
16
|
+
quickstartAllowFrom: true,
|
|
17
|
+
};
|
|
18
|
+
function resolveAccountInboundPath(account) {
|
|
19
|
+
const derivedPaths = resolveDerivedPathSummary(account.accountId);
|
|
20
|
+
if (account.bot?.primaryTransport === "webhook" && account.bot.webhookConfigured) {
|
|
21
|
+
return derivedPaths.botWebhook[0];
|
|
22
|
+
}
|
|
23
|
+
if (account.agent?.callbackConfigured) {
|
|
24
|
+
return derivedPaths.agentCallback[0];
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function normalizeWecomMessagingTarget(raw) {
|
|
29
|
+
const trimmed = raw.trim();
|
|
30
|
+
if (!trimmed)
|
|
31
|
+
return undefined;
|
|
32
|
+
if (/^wecom-agent(?:-upstream)?:/i.test(trimmed)) {
|
|
33
|
+
return trimmed;
|
|
34
|
+
}
|
|
35
|
+
if (/^(wecom|wechatwork|wework|qywx):(user|group|chat|party|dept|tag|context):/i.test(trimmed)) {
|
|
36
|
+
return trimmed;
|
|
37
|
+
}
|
|
38
|
+
return trimmed.replace(/^(wecom|wechatwork|wework|qywx):/i, "").trim() || undefined;
|
|
39
|
+
}
|
|
40
|
+
export const wecomPlugin = {
|
|
41
|
+
id: "wecom",
|
|
42
|
+
meta,
|
|
43
|
+
setupWizard: wecomSetupWizard,
|
|
44
|
+
capabilities: {
|
|
45
|
+
chatTypes: ["direct", "group"],
|
|
46
|
+
media: true,
|
|
47
|
+
reactions: false,
|
|
48
|
+
threads: false,
|
|
49
|
+
polls: false,
|
|
50
|
+
nativeCommands: false,
|
|
51
|
+
blockStreaming: false,
|
|
52
|
+
},
|
|
53
|
+
reload: { configPrefixes: ["channels.wecom"] },
|
|
54
|
+
// A permissive schema keeps config UX working while preventing startup failures.
|
|
55
|
+
configSchema: {
|
|
56
|
+
schema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
additionalProperties: true,
|
|
59
|
+
properties: {},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
config: {
|
|
63
|
+
listAccountIds: (cfg) => listWecomAccountIds(cfg),
|
|
64
|
+
resolveAccount: (cfg, accountId) => resolveWecomAccount({ cfg: cfg, accountId }),
|
|
65
|
+
defaultAccountId: (cfg) => resolveDefaultWecomAccountId(cfg),
|
|
66
|
+
setAccountEnabled: ({ cfg, accountId, enabled }) => setAccountEnabledInConfigSection({
|
|
67
|
+
cfg: cfg,
|
|
68
|
+
sectionKey: "wecom",
|
|
69
|
+
accountId,
|
|
70
|
+
enabled,
|
|
71
|
+
allowTopLevel: true,
|
|
72
|
+
}),
|
|
73
|
+
deleteAccount: ({ cfg, accountId }) => deleteAccountFromConfigSection({
|
|
74
|
+
cfg: cfg,
|
|
75
|
+
sectionKey: "wecom",
|
|
76
|
+
accountId,
|
|
77
|
+
clearBaseFields: ["bot", "agent"],
|
|
78
|
+
}),
|
|
79
|
+
isConfigured: (account, cfg) => {
|
|
80
|
+
if (!account.configured) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return !resolveWecomAccountConflict({
|
|
84
|
+
cfg: cfg,
|
|
85
|
+
accountId: account.accountId,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
unconfiguredReason: (account, cfg) => resolveWecomAccountConflict({
|
|
89
|
+
cfg: cfg,
|
|
90
|
+
accountId: account.accountId,
|
|
91
|
+
})?.message ?? "not configured",
|
|
92
|
+
describeAccount: (account, cfg) => {
|
|
93
|
+
const conflict = resolveWecomAccountConflict({
|
|
94
|
+
cfg: cfg,
|
|
95
|
+
accountId: account.accountId,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
accountId: account.accountId,
|
|
99
|
+
name: account.name,
|
|
100
|
+
enabled: account.enabled,
|
|
101
|
+
configured: account.configured && !conflict,
|
|
102
|
+
webhookPath: resolveAccountInboundPath(account),
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
resolveAllowFrom: ({ cfg, accountId }) => {
|
|
106
|
+
const account = resolveWecomAccount({
|
|
107
|
+
cfg: cfg,
|
|
108
|
+
accountId,
|
|
109
|
+
});
|
|
110
|
+
// 与其他渠道保持一致:直接返回 allowFrom,空则允许所有人
|
|
111
|
+
const allowFrom = account.agent?.config.dm?.allowFrom ?? account.bot?.config.dm?.allowFrom ?? [];
|
|
112
|
+
return allowFrom.map((entry) => String(entry));
|
|
113
|
+
},
|
|
114
|
+
formatAllowFrom: ({ allowFrom }) => allowFrom
|
|
115
|
+
.map((entry) => String(entry).trim())
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.map((entry) => entry.toLowerCase()),
|
|
118
|
+
},
|
|
119
|
+
// security 配置在 WeCom 中不需要,框架会通过 resolveAllowFrom 自动判断
|
|
120
|
+
groups: {
|
|
121
|
+
// WeCom bots are usually mention-gated by the platform in groups already.
|
|
122
|
+
resolveRequireMention: () => true,
|
|
123
|
+
},
|
|
124
|
+
threading: {
|
|
125
|
+
resolveReplyToMode: () => "off",
|
|
126
|
+
},
|
|
127
|
+
messaging: {
|
|
128
|
+
normalizeTarget: normalizeWecomMessagingTarget,
|
|
129
|
+
targetResolver: {
|
|
130
|
+
looksLikeId: (raw) => Boolean(raw.trim()),
|
|
131
|
+
hint: "<userid|chatid>",
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
outbound: {
|
|
135
|
+
...wecomOutbound,
|
|
136
|
+
},
|
|
137
|
+
status: {
|
|
138
|
+
defaultRuntime: {
|
|
139
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
140
|
+
running: false,
|
|
141
|
+
lastStartAt: null,
|
|
142
|
+
lastStopAt: null,
|
|
143
|
+
lastError: null,
|
|
144
|
+
},
|
|
145
|
+
buildChannelSummary: ({ snapshot }) => ({
|
|
146
|
+
configured: snapshot.configured ?? false,
|
|
147
|
+
running: snapshot.running ?? false,
|
|
148
|
+
webhookPath: snapshot.webhookPath ?? null,
|
|
149
|
+
transport: snapshot.transport ?? null,
|
|
150
|
+
ownerId: snapshot.ownerId ?? null,
|
|
151
|
+
health: snapshot.health ?? "idle",
|
|
152
|
+
ownerDriftAt: snapshot.ownerDriftAt ?? null,
|
|
153
|
+
connected: snapshot.connected,
|
|
154
|
+
authenticated: snapshot.authenticated,
|
|
155
|
+
lastStartAt: snapshot.lastStartAt ?? null,
|
|
156
|
+
lastStopAt: snapshot.lastStopAt ?? null,
|
|
157
|
+
lastError: snapshot.lastError ?? null,
|
|
158
|
+
lastErrorAt: snapshot.lastErrorAt ?? null,
|
|
159
|
+
lastInboundAt: snapshot.lastInboundAt ?? null,
|
|
160
|
+
lastOutboundAt: snapshot.lastOutboundAt ?? null,
|
|
161
|
+
recentInboundSummary: snapshot.recentInboundSummary ?? null,
|
|
162
|
+
recentOutboundSummary: snapshot.recentOutboundSummary ?? null,
|
|
163
|
+
recentIssueCategory: snapshot.recentIssueCategory ?? null,
|
|
164
|
+
recentIssueSummary: snapshot.recentIssueSummary ?? null,
|
|
165
|
+
transportSessions: snapshot.transportSessions ?? [],
|
|
166
|
+
probe: snapshot.probe,
|
|
167
|
+
lastProbeAt: snapshot.lastProbeAt ?? null,
|
|
168
|
+
}),
|
|
169
|
+
probeAccount: async () => ({ ok: true }),
|
|
170
|
+
buildAccountSnapshot: ({ account, runtime, cfg }) => {
|
|
171
|
+
const conflict = resolveWecomAccountConflict({
|
|
172
|
+
cfg: cfg,
|
|
173
|
+
accountId: account.accountId,
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
accountId: account.accountId,
|
|
177
|
+
name: account.name,
|
|
178
|
+
enabled: account.enabled,
|
|
179
|
+
configured: account.configured && !conflict,
|
|
180
|
+
webhookPath: resolveAccountInboundPath(account),
|
|
181
|
+
primaryTransport: account.bot?.primaryTransport ?? (account.agent ? "agent-callback" : null),
|
|
182
|
+
transport: runtime?.transport ?? null,
|
|
183
|
+
ownerId: runtime?.ownerId ?? null,
|
|
184
|
+
health: runtime?.health ?? "idle",
|
|
185
|
+
ownerDriftAt: runtime?.ownerDriftAt ?? null,
|
|
186
|
+
connected: runtime?.connected,
|
|
187
|
+
authenticated: runtime?.authenticated,
|
|
188
|
+
running: runtime?.running ?? false,
|
|
189
|
+
lastStartAt: runtime?.lastStartAt ?? null,
|
|
190
|
+
lastStopAt: runtime?.lastStopAt ?? null,
|
|
191
|
+
lastError: runtime?.lastError ?? conflict?.message ?? null,
|
|
192
|
+
lastErrorAt: runtime?.lastErrorAt ?? null,
|
|
193
|
+
lastInboundAt: runtime?.lastInboundAt ?? null,
|
|
194
|
+
lastOutboundAt: runtime?.lastOutboundAt ?? null,
|
|
195
|
+
recentInboundSummary: runtime?.recentInboundSummary ??
|
|
196
|
+
null,
|
|
197
|
+
recentOutboundSummary: runtime
|
|
198
|
+
?.recentOutboundSummary ?? null,
|
|
199
|
+
recentIssueCategory: runtime?.recentIssueCategory ??
|
|
200
|
+
null,
|
|
201
|
+
recentIssueSummary: runtime?.recentIssueSummary ??
|
|
202
|
+
null,
|
|
203
|
+
transportSessions: runtime?.transportSessions ?? [],
|
|
204
|
+
dmPolicy: account.bot?.config.dm?.policy ?? "pairing",
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
gateway: {
|
|
209
|
+
/**
|
|
210
|
+
* **startAccount (启动账号)**
|
|
211
|
+
*
|
|
212
|
+
* WeCom lifecycle is long-running: keep webhook targets active until
|
|
213
|
+
* gateway stop/reload aborts the account.
|
|
214
|
+
*/
|
|
215
|
+
startAccount: monitorWecomProvider,
|
|
216
|
+
stopAccount: async (ctx) => {
|
|
217
|
+
ctx.setStatus({
|
|
218
|
+
accountId: ctx.account.accountId,
|
|
219
|
+
running: false,
|
|
220
|
+
lastStopAt: Date.now(),
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
export const DEFAULT_ACCOUNT_ID = "default";
|
|
2
|
+
function toNumber(value) {
|
|
3
|
+
if (value == null)
|
|
4
|
+
return undefined;
|
|
5
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
6
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
7
|
+
}
|
|
8
|
+
function resolveBotAccount(accountId, config, network) {
|
|
9
|
+
const primaryTransport = config.primaryTransport ?? (config.ws ? "ws" : "webhook");
|
|
10
|
+
const wsConfigured = Boolean(config.ws?.botId && config.ws?.secret);
|
|
11
|
+
const webhookConfigured = Boolean(config.webhook?.token && config.webhook?.encodingAESKey);
|
|
12
|
+
const configured = primaryTransport === "ws" ? wsConfigured : webhookConfigured;
|
|
13
|
+
return {
|
|
14
|
+
accountId,
|
|
15
|
+
configured,
|
|
16
|
+
primaryTransport,
|
|
17
|
+
wsConfigured,
|
|
18
|
+
webhookConfigured,
|
|
19
|
+
config,
|
|
20
|
+
network,
|
|
21
|
+
ws: config.ws
|
|
22
|
+
? {
|
|
23
|
+
botId: config.ws.botId,
|
|
24
|
+
secret: config.ws.secret,
|
|
25
|
+
}
|
|
26
|
+
: undefined,
|
|
27
|
+
webhook: config.webhook
|
|
28
|
+
? {
|
|
29
|
+
token: config.webhook.token,
|
|
30
|
+
encodingAESKey: config.webhook.encodingAESKey,
|
|
31
|
+
receiveId: config.webhook.receiveId?.trim() ?? "",
|
|
32
|
+
}
|
|
33
|
+
: undefined,
|
|
34
|
+
token: config.webhook?.token ?? "",
|
|
35
|
+
encodingAESKey: config.webhook?.encodingAESKey ?? "",
|
|
36
|
+
receiveId: config.webhook?.receiveId?.trim() ?? "",
|
|
37
|
+
botId: config.ws?.botId ?? "",
|
|
38
|
+
secret: config.ws?.secret ?? "",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function resolveAgentAccount(accountId, config, network) {
|
|
42
|
+
const agentId = toNumber(config.agentId);
|
|
43
|
+
const callbackConfigured = Boolean(config.token && config.encodingAESKey);
|
|
44
|
+
const normalizedAgentSecret = config.agentSecret?.trim() || config.corpSecret?.trim() || "";
|
|
45
|
+
const apiConfigured = Boolean(config.corpId && normalizedAgentSecret && agentId);
|
|
46
|
+
return {
|
|
47
|
+
accountId,
|
|
48
|
+
configured: callbackConfigured || apiConfigured,
|
|
49
|
+
callbackConfigured,
|
|
50
|
+
apiConfigured,
|
|
51
|
+
corpId: config.corpId,
|
|
52
|
+
corpSecret: normalizedAgentSecret,
|
|
53
|
+
agentId,
|
|
54
|
+
token: config.token,
|
|
55
|
+
encodingAESKey: config.encodingAESKey,
|
|
56
|
+
config,
|
|
57
|
+
network,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function toResolvedAccount(params) {
|
|
61
|
+
const bot = params.config.bot
|
|
62
|
+
? resolveBotAccount(params.accountId, params.config.bot, params.network)
|
|
63
|
+
: undefined;
|
|
64
|
+
const agent = params.config.agent
|
|
65
|
+
? resolveAgentAccount(params.accountId, params.config.agent, params.network)
|
|
66
|
+
: undefined;
|
|
67
|
+
return {
|
|
68
|
+
accountId: params.accountId,
|
|
69
|
+
name: params.name,
|
|
70
|
+
enabled: params.enabled,
|
|
71
|
+
configured: Boolean(bot?.configured || agent?.configured),
|
|
72
|
+
config: params.config,
|
|
73
|
+
bot,
|
|
74
|
+
agent,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createMissingResolvedAccount(accountId) {
|
|
78
|
+
return {
|
|
79
|
+
accountId,
|
|
80
|
+
enabled: false,
|
|
81
|
+
configured: false,
|
|
82
|
+
config: {},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function detectMode(config) {
|
|
86
|
+
if (!config || config.enabled === false)
|
|
87
|
+
return "disabled";
|
|
88
|
+
if (config.accounts && Object.keys(config.accounts).length > 0) {
|
|
89
|
+
return "matrix";
|
|
90
|
+
}
|
|
91
|
+
if (config.bot || config.agent) {
|
|
92
|
+
return "legacy";
|
|
93
|
+
}
|
|
94
|
+
return "disabled";
|
|
95
|
+
}
|
|
96
|
+
function resolveMatrixAccounts(wecom) {
|
|
97
|
+
const resolved = {};
|
|
98
|
+
for (const [rawId, entry] of Object.entries(wecom.accounts ?? {})) {
|
|
99
|
+
const accountId = rawId.trim();
|
|
100
|
+
if (!accountId || !entry)
|
|
101
|
+
continue;
|
|
102
|
+
resolved[accountId] = toResolvedAccount({
|
|
103
|
+
accountId,
|
|
104
|
+
enabled: wecom.enabled !== false && entry.enabled !== false,
|
|
105
|
+
name: entry.name,
|
|
106
|
+
config: entry,
|
|
107
|
+
network: wecom.network,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return resolved;
|
|
111
|
+
}
|
|
112
|
+
function resolveLegacyAccounts(wecom) {
|
|
113
|
+
const config = {
|
|
114
|
+
bot: wecom.bot,
|
|
115
|
+
agent: wecom.agent,
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
[DEFAULT_ACCOUNT_ID]: toResolvedAccount({
|
|
119
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
120
|
+
enabled: wecom.enabled !== false,
|
|
121
|
+
config,
|
|
122
|
+
network: wecom.network,
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function normalizeKey(value) {
|
|
127
|
+
return value.trim().toLowerCase();
|
|
128
|
+
}
|
|
129
|
+
function collectWecomAccountConflicts(cfg) {
|
|
130
|
+
const resolved = resolveWecomAccounts(cfg);
|
|
131
|
+
const conflicts = new Map();
|
|
132
|
+
const botOwners = new Map();
|
|
133
|
+
const agentOwners = new Map();
|
|
134
|
+
for (const accountId of Object.keys(resolved.accounts).sort((a, b) => a.localeCompare(b))) {
|
|
135
|
+
const account = resolved.accounts[accountId];
|
|
136
|
+
if (!account || account.enabled === false)
|
|
137
|
+
continue;
|
|
138
|
+
const botId = account.bot?.botId?.trim();
|
|
139
|
+
if (botId) {
|
|
140
|
+
const key = normalizeKey(botId);
|
|
141
|
+
const owner = botOwners.get(key);
|
|
142
|
+
if (owner && owner !== accountId) {
|
|
143
|
+
conflicts.set(accountId, {
|
|
144
|
+
type: "duplicate_bot_id",
|
|
145
|
+
accountId,
|
|
146
|
+
ownerAccountId: owner,
|
|
147
|
+
message: `Duplicate WeCom botId: account "${accountId}" shares botId with account "${owner}". ` +
|
|
148
|
+
"Keep one owner account per botId.",
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
botOwners.set(key, accountId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const corpId = account.agent?.corpId?.trim();
|
|
156
|
+
const agentId = account.agent?.agentId;
|
|
157
|
+
if (corpId && typeof agentId === "number") {
|
|
158
|
+
const key = `${normalizeKey(corpId)}:${agentId}`;
|
|
159
|
+
const owner = agentOwners.get(key);
|
|
160
|
+
if (owner && owner !== accountId) {
|
|
161
|
+
conflicts.set(accountId, {
|
|
162
|
+
type: "duplicate_agent_id",
|
|
163
|
+
accountId,
|
|
164
|
+
ownerAccountId: owner,
|
|
165
|
+
message: `Duplicate WeCom agent identity: account "${accountId}" shares corpId/agentId (${corpId}/${agentId}) with account "${owner}". ` +
|
|
166
|
+
"Keep one owner account per corpId/agentId pair.",
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
agentOwners.set(key, accountId);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return conflicts;
|
|
175
|
+
}
|
|
176
|
+
export function resolveWecomAccountConflict(params) {
|
|
177
|
+
return collectWecomAccountConflicts(params.cfg).get(params.accountId);
|
|
178
|
+
}
|
|
179
|
+
export function listWecomAccountIds(cfg) {
|
|
180
|
+
const wecom = cfg.channels?.wecom;
|
|
181
|
+
const mode = detectMode(wecom);
|
|
182
|
+
if (mode === "matrix") {
|
|
183
|
+
return Object.keys(wecom?.accounts ?? {})
|
|
184
|
+
.map((value) => value.trim())
|
|
185
|
+
.filter(Boolean)
|
|
186
|
+
.sort((a, b) => a.localeCompare(b));
|
|
187
|
+
}
|
|
188
|
+
if (mode === "legacy") {
|
|
189
|
+
return [DEFAULT_ACCOUNT_ID];
|
|
190
|
+
}
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
export function resolveDefaultWecomAccountId(cfg) {
|
|
194
|
+
const wecom = cfg.channels?.wecom;
|
|
195
|
+
const ids = listWecomAccountIds(cfg);
|
|
196
|
+
if (wecom?.defaultAccount && ids.includes(wecom.defaultAccount)) {
|
|
197
|
+
return wecom.defaultAccount;
|
|
198
|
+
}
|
|
199
|
+
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
200
|
+
}
|
|
201
|
+
export function resolveWecomAccounts(cfg) {
|
|
202
|
+
const wecom = cfg.channels?.wecom ?? {};
|
|
203
|
+
const mode = detectMode(wecom);
|
|
204
|
+
const accounts = mode === "matrix" ? resolveMatrixAccounts(wecom) : mode === "legacy" ? resolveLegacyAccounts(wecom) : {};
|
|
205
|
+
const defaultAccountId = resolveDefaultWecomAccountId(cfg);
|
|
206
|
+
return {
|
|
207
|
+
mode,
|
|
208
|
+
defaultAccountId,
|
|
209
|
+
accounts,
|
|
210
|
+
bot: accounts[defaultAccountId]?.bot,
|
|
211
|
+
agent: accounts[defaultAccountId]?.agent,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function resolveWecomAccount(params) {
|
|
215
|
+
const resolved = resolveWecomAccounts(params.cfg);
|
|
216
|
+
const explicitAccountId = params.accountId?.trim();
|
|
217
|
+
const accountId = explicitAccountId || resolved.defaultAccountId;
|
|
218
|
+
const direct = resolved.accounts[accountId];
|
|
219
|
+
if (direct) {
|
|
220
|
+
return direct;
|
|
221
|
+
}
|
|
222
|
+
// Treat the literal "default" as an alias for the configured default account.
|
|
223
|
+
// This keeps generic onboarding flows working even when the first WeCom account
|
|
224
|
+
// was created under a custom id like "haidao" instead of a literal "default".
|
|
225
|
+
if (explicitAccountId === DEFAULT_ACCOUNT_ID) {
|
|
226
|
+
const fallback = resolved.accounts[resolved.defaultAccountId];
|
|
227
|
+
if (fallback) {
|
|
228
|
+
return fallback;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return createMissingResolvedAccount(accountId);
|
|
232
|
+
}
|
|
233
|
+
export function isWecomEnabled(cfg) {
|
|
234
|
+
const resolved = resolveWecomAccounts(cfg);
|
|
235
|
+
return Object.values(resolved.accounts).some((account) => account.enabled && account.configured);
|
|
236
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNT_ID } from "./accounts.js";
|
|
2
|
+
import { WEBHOOK_PATHS } from "../types/constants.js";
|
|
3
|
+
export function resolveDerivedPath(params) {
|
|
4
|
+
const accountId = params.accountId.trim() || DEFAULT_ACCOUNT_ID;
|
|
5
|
+
const isDefault = accountId === DEFAULT_ACCOUNT_ID;
|
|
6
|
+
if (params.transport === "bot-webhook") {
|
|
7
|
+
return isDefault
|
|
8
|
+
? [
|
|
9
|
+
`${WEBHOOK_PATHS.BOT_PLUGIN}/${accountId}`,
|
|
10
|
+
`${WEBHOOK_PATHS.BOT}/${accountId}`,
|
|
11
|
+
WEBHOOK_PATHS.BOT_PLUGIN,
|
|
12
|
+
WEBHOOK_PATHS.BOT_ALT,
|
|
13
|
+
WEBHOOK_PATHS.BOT,
|
|
14
|
+
]
|
|
15
|
+
: [`${WEBHOOK_PATHS.BOT_PLUGIN}/${accountId}`];
|
|
16
|
+
}
|
|
17
|
+
return isDefault
|
|
18
|
+
? [
|
|
19
|
+
`${WEBHOOK_PATHS.AGENT_PLUGIN}/${accountId}`,
|
|
20
|
+
`${WEBHOOK_PATHS.AGENT}/${accountId}`,
|
|
21
|
+
WEBHOOK_PATHS.AGENT_PLUGIN,
|
|
22
|
+
WEBHOOK_PATHS.AGENT,
|
|
23
|
+
]
|
|
24
|
+
: [`${WEBHOOK_PATHS.AGENT_PLUGIN}/${accountId}`];
|
|
25
|
+
}
|
|
26
|
+
export function resolveDerivedPathSummary(accountId) {
|
|
27
|
+
return {
|
|
28
|
+
botWebhook: resolveDerivedPath({ accountId, transport: "bot-webhook" }),
|
|
29
|
+
agentCallback: resolveDerivedPath({ accountId, transport: "agent-callback" }),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { WecomConfigSchema } from "./schema.js";
|
|
2
|
+
export { DEFAULT_ACCOUNT_ID, detectMode, listWecomAccountIds, resolveDefaultWecomAccountId, resolveWecomAccount, resolveWecomAccountConflict, resolveWecomAccounts, isWecomEnabled, } from "./accounts.js";
|
|
3
|
+
export { resolveWecomRuntimeAccount, resolveWecomRuntimeConfig } from "./runtime-config.js";
|
|
4
|
+
export { resolveDerivedPath, resolveDerivedPathSummary } from "./derived-paths.js";
|
|
5
|
+
export { resolveWecomEgressProxyUrl, resolveWecomEgressProxyUrlFromNetwork, resolveWecomMediaDownloadTimeoutMs, } from "./network.js";
|
|
6
|
+
export { DEFAULT_WECOM_MEDIA_MAX_BYTES, getWecomDefaultMediaLocalRoots, resolveWecomConfiguredMediaLocalRoots, resolveWecomMediaMaxBytes, resolveWecomMergedMediaLocalRoots, } from "./media.js";
|
|
7
|
+
export { resolveWecomFailClosedOnDefaultRoute, shouldRejectWecomDefaultRoute } from "./routing.js";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/infra-runtime";
|
|
4
|
+
import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/media-runtime";
|
|
5
|
+
// 默认给一个相对“够用”的上限(80MB),避免视频/较大文件频繁触发失败。
|
|
6
|
+
// 仍保留上限以防止恶意大文件把进程内存打爆(下载实现会读入内存再保存)。
|
|
7
|
+
export const DEFAULT_WECOM_MEDIA_MAX_BYTES = 80 * 1024 * 1024;
|
|
8
|
+
function parsePositiveNumber(value) {
|
|
9
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
10
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return parsed;
|
|
14
|
+
}
|
|
15
|
+
function resolveStateDirForWecomMedia() {
|
|
16
|
+
const stateOverride = process.env.OPENCLAW_STATE_DIR?.trim() || process.env.CLAWDBOT_STATE_DIR?.trim();
|
|
17
|
+
if (stateOverride) {
|
|
18
|
+
return stateOverride;
|
|
19
|
+
}
|
|
20
|
+
return path.join(os.homedir(), ".openclaw");
|
|
21
|
+
}
|
|
22
|
+
function normalizeWecomLocalRoot(root) {
|
|
23
|
+
const trimmed = root.trim();
|
|
24
|
+
if (!trimmed) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return path.resolve(trimmed.replace(/^~(?=\/|$)/, os.homedir()));
|
|
28
|
+
}
|
|
29
|
+
function getWecomCommonUserMediaLocalRoots() {
|
|
30
|
+
const home = os.homedir();
|
|
31
|
+
return [
|
|
32
|
+
path.join(home, "Desktop"),
|
|
33
|
+
path.join(home, "Documents"),
|
|
34
|
+
path.join(home, "Downloads"),
|
|
35
|
+
path.join(home, "Movies"),
|
|
36
|
+
path.join(home, "Pictures"),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
export function getWecomDefaultMediaLocalRoots() {
|
|
40
|
+
const stateDir = path.resolve(resolveStateDirForWecomMedia());
|
|
41
|
+
return [
|
|
42
|
+
path.resolve(resolvePreferredOpenClawTmpDir()),
|
|
43
|
+
stateDir,
|
|
44
|
+
path.join(stateDir, "media"),
|
|
45
|
+
path.join(stateDir, "agents"),
|
|
46
|
+
path.join(stateDir, "workspace"),
|
|
47
|
+
path.join(stateDir, "sandboxes"),
|
|
48
|
+
...getWecomCommonUserMediaLocalRoots(),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
export function resolveWecomConfiguredMediaLocalRoots(cfg) {
|
|
52
|
+
const rawWecom = cfg.channels?.wecom;
|
|
53
|
+
const configured = Array.isArray(rawWecom?.media?.localRoots)
|
|
54
|
+
? rawWecom.media.localRoots
|
|
55
|
+
: Array.isArray(rawWecom?.mediaLocalRoots)
|
|
56
|
+
? rawWecom.mediaLocalRoots
|
|
57
|
+
: [];
|
|
58
|
+
return configured
|
|
59
|
+
.filter((root) => typeof root === "string")
|
|
60
|
+
.map(normalizeWecomLocalRoot)
|
|
61
|
+
.filter((root) => Boolean(root));
|
|
62
|
+
}
|
|
63
|
+
export function resolveWecomMergedMediaLocalRoots(params) {
|
|
64
|
+
const merged = [];
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
const pushRoot = (root) => {
|
|
67
|
+
const normalized = normalizeWecomLocalRoot(root);
|
|
68
|
+
if (!normalized || seen.has(normalized)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
seen.add(normalized);
|
|
72
|
+
merged.push(normalized);
|
|
73
|
+
};
|
|
74
|
+
for (const root of getWecomDefaultMediaLocalRoots()) {
|
|
75
|
+
pushRoot(root);
|
|
76
|
+
}
|
|
77
|
+
for (const root of params.baseRoots ?? []) {
|
|
78
|
+
pushRoot(root);
|
|
79
|
+
}
|
|
80
|
+
for (const root of resolveWecomConfiguredMediaLocalRoots(params.cfg)) {
|
|
81
|
+
pushRoot(root);
|
|
82
|
+
}
|
|
83
|
+
return merged;
|
|
84
|
+
}
|
|
85
|
+
function resolveLegacyWecomMediaMaxBytes(cfg) {
|
|
86
|
+
const raw = cfg.channels?.wecom?.media?.maxBytes;
|
|
87
|
+
const bytes = parsePositiveNumber(raw);
|
|
88
|
+
if (bytes) {
|
|
89
|
+
return Math.floor(bytes);
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
export function resolveWecomMediaMaxBytes(cfg, accountId) {
|
|
94
|
+
const mediaMaxBytes = resolveChannelMediaMaxBytes({
|
|
95
|
+
cfg,
|
|
96
|
+
accountId,
|
|
97
|
+
resolveChannelLimitMb: ({ cfg, accountId }) => {
|
|
98
|
+
const wecom = cfg.channels?.wecom;
|
|
99
|
+
const accountLimitMb = parsePositiveNumber(wecom?.accounts?.[accountId]?.mediaMaxMb);
|
|
100
|
+
if (accountLimitMb) {
|
|
101
|
+
return accountLimitMb;
|
|
102
|
+
}
|
|
103
|
+
return parsePositiveNumber(wecom?.mediaMaxMb);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
if (mediaMaxBytes) {
|
|
107
|
+
return mediaMaxBytes;
|
|
108
|
+
}
|
|
109
|
+
return resolveLegacyWecomMediaMaxBytes(cfg) ?? DEFAULT_WECOM_MEDIA_MAX_BYTES;
|
|
110
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const DEFAULT_WECOM_MEDIA_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
2
|
+
function parsePositiveInt(value) {
|
|
3
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
4
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return Math.floor(parsed);
|
|
8
|
+
}
|
|
9
|
+
export function resolveWecomEgressProxyUrlFromNetwork(network) {
|
|
10
|
+
const proxyUrl = network?.egressProxyUrl ??
|
|
11
|
+
process.env.OPENCLAW_WECOM_EGRESS_PROXY_URL ??
|
|
12
|
+
process.env.WECOM_EGRESS_PROXY_URL ??
|
|
13
|
+
process.env.HTTPS_PROXY ??
|
|
14
|
+
process.env.ALL_PROXY ??
|
|
15
|
+
process.env.HTTP_PROXY ??
|
|
16
|
+
"";
|
|
17
|
+
return proxyUrl.trim() || undefined;
|
|
18
|
+
}
|
|
19
|
+
export function resolveWecomEgressProxyUrl(cfg) {
|
|
20
|
+
const wecom = cfg.channels?.wecom;
|
|
21
|
+
return resolveWecomEgressProxyUrlFromNetwork(wecom?.network);
|
|
22
|
+
}
|
|
23
|
+
export function resolveWecomMediaDownloadTimeoutMs(cfg) {
|
|
24
|
+
const wecom = cfg.channels?.wecom;
|
|
25
|
+
const timeoutMs = parsePositiveInt(wecom?.media?.downloadTimeoutMs) ??
|
|
26
|
+
parsePositiveInt(wecom?.mediaDownloadTimeoutMs) ??
|
|
27
|
+
parsePositiveInt(wecom?.network?.mediaDownloadTimeoutMs) ??
|
|
28
|
+
parsePositiveInt(wecom?.network?.timeoutMs) ??
|
|
29
|
+
parsePositiveInt(process.env.OPENCLAW_WECOM_MEDIA_TIMEOUT_MS) ??
|
|
30
|
+
parsePositiveInt(process.env.WECOM_MEDIA_TIMEOUT_MS);
|
|
31
|
+
return timeoutMs ?? DEFAULT_WECOM_MEDIA_DOWNLOAD_TIMEOUT_MS;
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { detectMode } from "./accounts.js";
|
|
2
|
+
/**
|
|
3
|
+
* 默认策略:
|
|
4
|
+
* - matrix(多账号): 开启 fail-closed,防止未绑定账号回退到 main
|
|
5
|
+
* - legacy(单账号兼容): 维持历史行为,不强制拦截
|
|
6
|
+
*/
|
|
7
|
+
export function resolveWecomFailClosedOnDefaultRoute(cfg) {
|
|
8
|
+
const wecom = cfg.channels?.wecom;
|
|
9
|
+
const explicit = wecom?.routing?.failClosedOnDefaultRoute;
|
|
10
|
+
if (typeof explicit === "boolean")
|
|
11
|
+
return explicit;
|
|
12
|
+
return detectMode(wecom) === "matrix";
|
|
13
|
+
}
|
|
14
|
+
export function shouldRejectWecomDefaultRoute(params) {
|
|
15
|
+
if (params.matchedBy !== "default")
|
|
16
|
+
return false;
|
|
17
|
+
if (params.useDynamicAgent)
|
|
18
|
+
return false;
|
|
19
|
+
return resolveWecomFailClosedOnDefaultRoute(params.cfg);
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolveDerivedPathSummary } from "./derived-paths.js";
|
|
2
|
+
import { DEFAULT_ACCOUNT_ID, resolveWecomAccount, resolveWecomAccounts } from "./accounts.js";
|
|
3
|
+
export function resolveWecomRuntimeConfig(cfg) {
|
|
4
|
+
const raw = cfg.channels?.wecom;
|
|
5
|
+
const resolved = resolveWecomAccounts(cfg);
|
|
6
|
+
const accounts = Object.fromEntries(Object.entries(resolved.accounts).map(([accountId, account]) => [
|
|
7
|
+
accountId,
|
|
8
|
+
{
|
|
9
|
+
account,
|
|
10
|
+
derivedPaths: resolveDerivedPathSummary(accountId),
|
|
11
|
+
},
|
|
12
|
+
]));
|
|
13
|
+
return {
|
|
14
|
+
raw,
|
|
15
|
+
defaultAccountId: resolved.defaultAccountId || DEFAULT_ACCOUNT_ID,
|
|
16
|
+
accounts,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function resolveWecomRuntimeAccount(params) {
|
|
20
|
+
const account = resolveWecomAccount(params);
|
|
21
|
+
return {
|
|
22
|
+
account,
|
|
23
|
+
derivedPaths: resolveDerivedPathSummary(account.accountId),
|
|
24
|
+
};
|
|
25
|
+
}
|