@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,546 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom 配置向导 (Onboarding)
|
|
3
|
+
* 支持 Bot、Agent 和双模式同时启动的交互式配置流程
|
|
4
|
+
*/
|
|
5
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/routing";
|
|
6
|
+
import { listWecomAccountIds, resolveDefaultWecomAccountId, resolveWecomAccount, resolveWecomAccounts, } from "./config/index.js";
|
|
7
|
+
const channel = "wecom";
|
|
8
|
+
// ============================================================
|
|
9
|
+
// 辅助函数
|
|
10
|
+
// ============================================================
|
|
11
|
+
function getWecomConfig(cfg) {
|
|
12
|
+
return cfg.channels?.wecom;
|
|
13
|
+
}
|
|
14
|
+
function setWecomEnabled(cfg, enabled) {
|
|
15
|
+
return {
|
|
16
|
+
...cfg,
|
|
17
|
+
channels: {
|
|
18
|
+
...cfg.channels,
|
|
19
|
+
wecom: {
|
|
20
|
+
...(cfg.channels?.wecom ?? {}),
|
|
21
|
+
enabled,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function shouldUseAccountScopedConfig(wecom, accountId) {
|
|
27
|
+
void wecom;
|
|
28
|
+
void accountId;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
function ensureMatrixAccounts(wecom) {
|
|
32
|
+
const accounts = wecom.accounts ?? {};
|
|
33
|
+
if (Object.keys(accounts).length > 0) {
|
|
34
|
+
return wecom;
|
|
35
|
+
}
|
|
36
|
+
if (!wecom.bot && !wecom.agent) {
|
|
37
|
+
return wecom;
|
|
38
|
+
}
|
|
39
|
+
const { bot: legacyBot, agent: legacyAgent, ...rest } = wecom;
|
|
40
|
+
const defaultAccount = {
|
|
41
|
+
enabled: true,
|
|
42
|
+
...(legacyBot ? { bot: legacyBot } : {}),
|
|
43
|
+
...(legacyAgent ? { agent: legacyAgent } : {}),
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
...rest,
|
|
47
|
+
defaultAccount: rest.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
48
|
+
accounts: {
|
|
49
|
+
[DEFAULT_ACCOUNT_ID]: defaultAccount,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function accountWebhookPath(kind, accountId) {
|
|
54
|
+
const recommendedBase = kind === "bot" ? "/plugins/wecom/bot" : "/plugins/wecom/agent";
|
|
55
|
+
return `${recommendedBase}/${accountId}`;
|
|
56
|
+
}
|
|
57
|
+
function setWecomBotConfig(cfg, bot, accountId) {
|
|
58
|
+
const wecom = getWecomConfig(cfg) ?? {};
|
|
59
|
+
if (!shouldUseAccountScopedConfig(wecom, accountId)) {
|
|
60
|
+
return {
|
|
61
|
+
...cfg,
|
|
62
|
+
channels: {
|
|
63
|
+
...cfg.channels,
|
|
64
|
+
wecom: {
|
|
65
|
+
...wecom,
|
|
66
|
+
enabled: true,
|
|
67
|
+
bot: {
|
|
68
|
+
...wecom.bot,
|
|
69
|
+
...bot,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
76
|
+
const accounts = matrixWecom.accounts ?? {};
|
|
77
|
+
const existingAccount = accounts[accountId] ?? {};
|
|
78
|
+
const existingBot = existingAccount.bot;
|
|
79
|
+
return {
|
|
80
|
+
...cfg,
|
|
81
|
+
channels: {
|
|
82
|
+
...cfg.channels,
|
|
83
|
+
wecom: {
|
|
84
|
+
...matrixWecom,
|
|
85
|
+
enabled: true,
|
|
86
|
+
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
87
|
+
accounts: {
|
|
88
|
+
...accounts,
|
|
89
|
+
[accountId]: {
|
|
90
|
+
...existingAccount,
|
|
91
|
+
enabled: existingAccount.enabled ?? true,
|
|
92
|
+
bot: {
|
|
93
|
+
...existingBot,
|
|
94
|
+
...bot,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function setWecomAgentConfig(cfg, agent, accountId) {
|
|
103
|
+
const wecom = getWecomConfig(cfg) ?? {};
|
|
104
|
+
if (!shouldUseAccountScopedConfig(wecom, accountId)) {
|
|
105
|
+
return {
|
|
106
|
+
...cfg,
|
|
107
|
+
channels: {
|
|
108
|
+
...cfg.channels,
|
|
109
|
+
wecom: {
|
|
110
|
+
...wecom,
|
|
111
|
+
enabled: true,
|
|
112
|
+
agent,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
118
|
+
const accounts = matrixWecom.accounts ?? {};
|
|
119
|
+
const existingAccount = accounts[accountId] ?? {};
|
|
120
|
+
return {
|
|
121
|
+
...cfg,
|
|
122
|
+
channels: {
|
|
123
|
+
...cfg.channels,
|
|
124
|
+
wecom: {
|
|
125
|
+
...matrixWecom,
|
|
126
|
+
enabled: true,
|
|
127
|
+
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
128
|
+
accounts: {
|
|
129
|
+
...accounts,
|
|
130
|
+
[accountId]: {
|
|
131
|
+
...existingAccount,
|
|
132
|
+
enabled: existingAccount.enabled ?? true,
|
|
133
|
+
agent,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function setWecomDmPolicy(cfg, mode, dm, accountId) {
|
|
141
|
+
const wecom = getWecomConfig(cfg) ?? {};
|
|
142
|
+
if (shouldUseAccountScopedConfig(wecom, accountId)) {
|
|
143
|
+
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
144
|
+
const accounts = matrixWecom.accounts ?? {};
|
|
145
|
+
const existingAccount = accounts[accountId] ?? {};
|
|
146
|
+
const nextAccount = mode === "bot"
|
|
147
|
+
? {
|
|
148
|
+
...existingAccount,
|
|
149
|
+
bot: {
|
|
150
|
+
...existingAccount.bot,
|
|
151
|
+
dm,
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
: {
|
|
155
|
+
...existingAccount,
|
|
156
|
+
agent: {
|
|
157
|
+
...existingAccount.agent,
|
|
158
|
+
dm,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
...cfg,
|
|
163
|
+
channels: {
|
|
164
|
+
...cfg.channels,
|
|
165
|
+
wecom: {
|
|
166
|
+
...matrixWecom,
|
|
167
|
+
enabled: true,
|
|
168
|
+
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
169
|
+
accounts: {
|
|
170
|
+
...accounts,
|
|
171
|
+
[accountId]: {
|
|
172
|
+
...nextAccount,
|
|
173
|
+
enabled: nextAccount.enabled ?? true,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (mode === "bot") {
|
|
181
|
+
return {
|
|
182
|
+
...cfg,
|
|
183
|
+
channels: {
|
|
184
|
+
...cfg.channels,
|
|
185
|
+
wecom: {
|
|
186
|
+
...wecom,
|
|
187
|
+
bot: {
|
|
188
|
+
...wecom.bot,
|
|
189
|
+
dm,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
...cfg,
|
|
197
|
+
channels: {
|
|
198
|
+
...cfg.channels,
|
|
199
|
+
wecom: {
|
|
200
|
+
...wecom,
|
|
201
|
+
agent: {
|
|
202
|
+
...wecom.agent,
|
|
203
|
+
dm,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
async function resolveOnboardingAccountId(params) {
|
|
210
|
+
const defaultAccountId = resolveDefaultWecomAccountId(params.cfg);
|
|
211
|
+
const override = params.accountOverride?.trim();
|
|
212
|
+
let accountId = override ? normalizeAccountId(override) : defaultAccountId;
|
|
213
|
+
if (!override && params.shouldPromptAccountIds) {
|
|
214
|
+
const existingIds = listWecomAccountIds(params.cfg);
|
|
215
|
+
const selectableIds = existingIds.includes(DEFAULT_ACCOUNT_ID)
|
|
216
|
+
? existingIds
|
|
217
|
+
: [DEFAULT_ACCOUNT_ID, ...existingIds];
|
|
218
|
+
const choice = await params.prompter.select({
|
|
219
|
+
message: "请选择企业微信接入标识(英文):",
|
|
220
|
+
options: [
|
|
221
|
+
...selectableIds.map((id) => ({
|
|
222
|
+
value: id,
|
|
223
|
+
label: id === DEFAULT_ACCOUNT_ID ? "default(默认标识)" : id,
|
|
224
|
+
})),
|
|
225
|
+
{ value: "__new__", label: "新增接入标识" },
|
|
226
|
+
],
|
|
227
|
+
initialValue: accountId,
|
|
228
|
+
});
|
|
229
|
+
if (choice === "__new__") {
|
|
230
|
+
const entered = await params.prompter.text({
|
|
231
|
+
message: "请输入新的企业微信接入标识(英文):",
|
|
232
|
+
validate: (value) => (value?.trim() ? undefined : "接入标识不能为空"),
|
|
233
|
+
});
|
|
234
|
+
const normalized = normalizeAccountId(String(entered));
|
|
235
|
+
if (String(entered).trim() !== normalized) {
|
|
236
|
+
await params.prompter.note(`接入标识已规范化为:${normalized}`, "企业微信接入标识");
|
|
237
|
+
}
|
|
238
|
+
accountId = normalized;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
accountId = normalizeAccountId(choice);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return accountId.trim() || DEFAULT_ACCOUNT_ID;
|
|
245
|
+
}
|
|
246
|
+
// ============================================================
|
|
247
|
+
// 欢迎与引导
|
|
248
|
+
// ============================================================
|
|
249
|
+
async function showWelcome(prompter) {
|
|
250
|
+
await prompter.note([
|
|
251
|
+
"🚀 欢迎使用企业微信(WeCom)接入向导",
|
|
252
|
+
"YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,适合直接落生产环境。",
|
|
253
|
+
"默认就是 Bot WebSocket 模式,配置简单,无需域名,普通用户也能快速接入。",
|
|
254
|
+
"支持主动发消息,定时任务、异常提醒、工作流通知都可直接落地。",
|
|
255
|
+
"同时支持「智能体 Bot」与「自建应用 Agent」双模式并行。",
|
|
256
|
+
"--------------------------------------------------",
|
|
257
|
+
"👨💻 作者: YanHaidao (微信: YanHaidao)",
|
|
258
|
+
"💬 交流: 有任何问题或建议,欢迎添加微信进入交流群。",
|
|
259
|
+
"--------------------------------------------------",
|
|
260
|
+
].join("\n"), "WeCom (企业微信) 配置向导");
|
|
261
|
+
}
|
|
262
|
+
// ============================================================
|
|
263
|
+
// 模式选择
|
|
264
|
+
// ============================================================
|
|
265
|
+
async function promptMode(prompter) {
|
|
266
|
+
const choice = await prompter.select({
|
|
267
|
+
message: "请选择您要配置的接入模式:",
|
|
268
|
+
options: [
|
|
269
|
+
{
|
|
270
|
+
value: "bot",
|
|
271
|
+
label: "Bot 模式 (智能机器人)",
|
|
272
|
+
hint: "默认 WS,配置简单,无需域名,支持主动发消息和日常对话",
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
value: "agent",
|
|
276
|
+
label: "Agent 模式 (自建应用)",
|
|
277
|
+
hint: "功能最全,支持 API 主动推送、发送文件/视频、交互卡片",
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
value: "both",
|
|
281
|
+
label: "双模式 (Bot + Agent 同时启用)",
|
|
282
|
+
hint: "Bot 默认 WS 易上手,Agent 负责应用回调、主动推送和媒体发送",
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
initialValue: "bot",
|
|
286
|
+
});
|
|
287
|
+
return choice;
|
|
288
|
+
}
|
|
289
|
+
// ============================================================
|
|
290
|
+
// Bot 模式配置
|
|
291
|
+
// ============================================================
|
|
292
|
+
async function configureBotMode(cfg, prompter, accountId) {
|
|
293
|
+
const recommendedPath = accountWebhookPath("bot", accountId);
|
|
294
|
+
await prompter.note([
|
|
295
|
+
"正在配置 Bot 模式...",
|
|
296
|
+
"",
|
|
297
|
+
"✨ YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,能力完整。",
|
|
298
|
+
"✅ 默认就是 Bot WebSocket 模式,配置简单,无需域名。",
|
|
299
|
+
"✅ 支持主动发消息,定时任务、异常提醒、工作流通知都可满足。",
|
|
300
|
+
"",
|
|
301
|
+
"请在企微后台【管理工具 -> 智能机器人】开启 API 模式,并选择 WebSocket 接入。",
|
|
302
|
+
"如果您后续需要 Bot webhook,可在配置文件里手动补充 bot.webhook。",
|
|
303
|
+
`📎 如需手动启用 Bot webhook,推荐回调 URL: https://您的域名${recommendedPath}`,
|
|
304
|
+
].join("\n"), "Bot 模式配置");
|
|
305
|
+
const botId = String(await prompter.text({
|
|
306
|
+
message: "请输入 BotId(机器人 ID):",
|
|
307
|
+
validate: (value) => (value?.trim() ? undefined : "BotId 不能为空"),
|
|
308
|
+
})).trim();
|
|
309
|
+
const secret = String(await prompter.text({
|
|
310
|
+
message: "请输入 Secret(机器人密钥):",
|
|
311
|
+
validate: (value) => (value?.trim() ? undefined : "Secret 不能为空"),
|
|
312
|
+
})).trim();
|
|
313
|
+
const streamPlaceholder = await prompter.text({
|
|
314
|
+
message: "流式占位符 (可选):",
|
|
315
|
+
placeholder: "正在思考...",
|
|
316
|
+
initialValue: "正在思考...",
|
|
317
|
+
});
|
|
318
|
+
const welcomeText = await prompter.text({
|
|
319
|
+
message: "欢迎语 (可选):",
|
|
320
|
+
placeholder: "你好!我是 AI 助手",
|
|
321
|
+
initialValue: "你好!我是 AI 助手",
|
|
322
|
+
});
|
|
323
|
+
const botConfig = {
|
|
324
|
+
primaryTransport: "ws",
|
|
325
|
+
ws: {
|
|
326
|
+
botId,
|
|
327
|
+
secret,
|
|
328
|
+
},
|
|
329
|
+
streamPlaceholderContent: streamPlaceholder?.trim() || undefined,
|
|
330
|
+
welcomeText: welcomeText?.trim() || undefined,
|
|
331
|
+
};
|
|
332
|
+
return setWecomBotConfig(cfg, botConfig, accountId);
|
|
333
|
+
}
|
|
334
|
+
// ============================================================
|
|
335
|
+
// Agent 模式配置
|
|
336
|
+
// ============================================================
|
|
337
|
+
async function configureAgentMode(cfg, prompter, accountId) {
|
|
338
|
+
const recommendedPath = accountWebhookPath("agent", accountId);
|
|
339
|
+
await prompter.note([
|
|
340
|
+
"正在配置 Agent 模式...",
|
|
341
|
+
"",
|
|
342
|
+
"💡 操作指南: 请在企微后台【应用管理 -> 自建应用】创建应用。",
|
|
343
|
+
].join("\n"), "Agent 模式配置");
|
|
344
|
+
const corpId = String(await prompter.text({
|
|
345
|
+
message: "请输入 CorpID (企业ID):",
|
|
346
|
+
validate: (value) => (value?.trim() ? undefined : "CorpID 不能为空"),
|
|
347
|
+
})).trim();
|
|
348
|
+
const agentIdStr = String(await prompter.text({
|
|
349
|
+
message: "请输入 AgentID (应用ID):",
|
|
350
|
+
validate: (value) => {
|
|
351
|
+
const v = value?.trim() ?? "";
|
|
352
|
+
if (!v)
|
|
353
|
+
return "AgentID 不能为空";
|
|
354
|
+
if (!/^\d+$/.test(v))
|
|
355
|
+
return "AgentID 应为数字";
|
|
356
|
+
return undefined;
|
|
357
|
+
},
|
|
358
|
+
})).trim();
|
|
359
|
+
const agentId = Number(agentIdStr);
|
|
360
|
+
const agentSecret = String(await prompter.text({
|
|
361
|
+
message: "请输入应用 Secret:",
|
|
362
|
+
validate: (value) => (value?.trim() ? undefined : "应用 Secret 不能为空"),
|
|
363
|
+
})).trim();
|
|
364
|
+
await prompter.note([
|
|
365
|
+
"💡 操作指南: 请在自建应用详情页进入【接收消息 -> 设置API接收】。",
|
|
366
|
+
`🔗 回调 URL (推荐): https://您的域名${recommendedPath}`,
|
|
367
|
+
"🧭 说明: Agent 同时承担 Callback ingress 与 API egress;回调路径由系统派生。",
|
|
368
|
+
"",
|
|
369
|
+
"请先在后台填入回调 URL,然后获取以下信息。",
|
|
370
|
+
].join("\n"), "回调配置");
|
|
371
|
+
const token = String(await prompter.text({
|
|
372
|
+
message: "请输入 Token (回调令牌):",
|
|
373
|
+
validate: (value) => (value?.trim() ? undefined : "Token 不能为空"),
|
|
374
|
+
})).trim();
|
|
375
|
+
const encodingAESKey = String(await prompter.text({
|
|
376
|
+
message: "请输入 EncodingAESKey (回调加密密钥):",
|
|
377
|
+
validate: (value) => {
|
|
378
|
+
const v = value?.trim() ?? "";
|
|
379
|
+
if (!v)
|
|
380
|
+
return "EncodingAESKey 不能为空";
|
|
381
|
+
if (v.length !== 43)
|
|
382
|
+
return "EncodingAESKey 应为 43 个字符";
|
|
383
|
+
return undefined;
|
|
384
|
+
},
|
|
385
|
+
})).trim();
|
|
386
|
+
const welcomeText = await prompter.text({
|
|
387
|
+
message: "欢迎语 (可选):",
|
|
388
|
+
placeholder: "欢迎使用智能助手",
|
|
389
|
+
initialValue: "欢迎使用智能助手",
|
|
390
|
+
});
|
|
391
|
+
const agentConfig = {
|
|
392
|
+
corpId,
|
|
393
|
+
agentSecret,
|
|
394
|
+
agentId,
|
|
395
|
+
token,
|
|
396
|
+
encodingAESKey,
|
|
397
|
+
welcomeText: welcomeText?.trim() || undefined,
|
|
398
|
+
};
|
|
399
|
+
return setWecomAgentConfig(cfg, agentConfig, accountId);
|
|
400
|
+
}
|
|
401
|
+
// ============================================================
|
|
402
|
+
// DM 策略配置
|
|
403
|
+
// ============================================================
|
|
404
|
+
async function promptDmPolicy(cfg, prompter, modes, accountId) {
|
|
405
|
+
const policyChoice = await prompter.select({
|
|
406
|
+
message: "请选择私聊 (DM) 访问策略:",
|
|
407
|
+
options: [
|
|
408
|
+
{ value: "pairing", label: "配对模式", hint: "推荐:安全,未知用户需授权" },
|
|
409
|
+
{ value: "allowlist", label: "白名单模式", hint: "仅允许特定 UserID" },
|
|
410
|
+
{ value: "open", label: "开放模式", hint: "任何人可发起" },
|
|
411
|
+
{ value: "disabled", label: "禁用私聊", hint: "不接受私聊消息" },
|
|
412
|
+
],
|
|
413
|
+
initialValue: "open",
|
|
414
|
+
});
|
|
415
|
+
const policy = policyChoice;
|
|
416
|
+
let allowFrom;
|
|
417
|
+
if (policy === "allowlist") {
|
|
418
|
+
const allowFromStr = String(await prompter.text({
|
|
419
|
+
message: "请输入白名单 UserID (多个用逗号分隔):",
|
|
420
|
+
placeholder: "user1,user2",
|
|
421
|
+
validate: (value) => value?.trim() ? undefined : "请输入至少一个 UserID",
|
|
422
|
+
})).trim();
|
|
423
|
+
allowFrom = allowFromStr
|
|
424
|
+
.split(",")
|
|
425
|
+
.map((s) => s.trim())
|
|
426
|
+
.filter(Boolean);
|
|
427
|
+
}
|
|
428
|
+
const dm = { policy, allowFrom };
|
|
429
|
+
let result = cfg;
|
|
430
|
+
for (const mode of modes) {
|
|
431
|
+
result = setWecomDmPolicy(result, mode, dm, accountId);
|
|
432
|
+
}
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
435
|
+
// ============================================================
|
|
436
|
+
// 配置汇总
|
|
437
|
+
// ============================================================
|
|
438
|
+
async function showSummary(cfg, prompter, accountId) {
|
|
439
|
+
const account = resolveWecomAccount({ cfg, accountId });
|
|
440
|
+
const lines = ["✅ 配置已保存!", ""];
|
|
441
|
+
if (account.bot?.configured) {
|
|
442
|
+
lines.push("📱 Bot 模式: 已配置");
|
|
443
|
+
lines.push(` 接入方式: ${account.bot.primaryTransport === "ws" ? "WebSocket 长连接" : "Webhook 回调"}`);
|
|
444
|
+
if (account.bot.primaryTransport === "ws") {
|
|
445
|
+
lines.push(" WS 优势: 无需域名,长链接模式创建机器人门槛更低");
|
|
446
|
+
lines.push(" 主动消息: 支持定时任务、异常提醒等主动发消息场景");
|
|
447
|
+
if (account.bot.webhookConfigured) {
|
|
448
|
+
lines.push(` 可选回调模式: 已手动配置,推荐回调地址为 https://您的域名${accountWebhookPath("bot", accountId)}`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
lines.push(` 回调地址: https://您的域名${accountWebhookPath("bot", accountId)}`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (account.agent?.configured) {
|
|
456
|
+
lines.push("🏢 Agent 模式: 已配置");
|
|
457
|
+
lines.push(` 回调地址: https://您的域名${accountWebhookPath("agent", accountId)}`);
|
|
458
|
+
lines.push(" 出站能力: Agent API(主动发送 / 补送 / 媒体)");
|
|
459
|
+
}
|
|
460
|
+
lines.push(` 接入标识: ${accountId}`);
|
|
461
|
+
lines.push(" 运维检查: openclaw channels status --deep");
|
|
462
|
+
lines.push(" 关键日志: [wecom-runtime] [wecom-ws] [wecom-http] [wecom-agent-delivery]");
|
|
463
|
+
lines.push("");
|
|
464
|
+
if (account.agent?.configured) {
|
|
465
|
+
lines.push("⚠️ 请确保您已在企微后台填写了正确的 Agent 回调 URL,");
|
|
466
|
+
lines.push(" 并点击了后台的『保存』按钮完成验证。");
|
|
467
|
+
}
|
|
468
|
+
else if (account.bot?.primaryTransport === "webhook") {
|
|
469
|
+
lines.push("⚠️ 请确保您已在企微后台填写了正确的 Bot 回调 URL,");
|
|
470
|
+
lines.push(" 并点击了后台的『保存』按钮完成验证。");
|
|
471
|
+
}
|
|
472
|
+
await prompter.note(lines.join("\n"), "配置完成");
|
|
473
|
+
}
|
|
474
|
+
async function getWecomSetupStatus(cfg) {
|
|
475
|
+
const resolved = resolveWecomAccounts(cfg);
|
|
476
|
+
const accounts = Object.values(resolved.accounts).filter((account) => account.enabled !== false);
|
|
477
|
+
const botConfigured = accounts.some((account) => Boolean(account.bot?.configured));
|
|
478
|
+
const agentConfigured = accounts.some((account) => Boolean(account.agent?.configured));
|
|
479
|
+
const configured = accounts.some((account) => account.configured);
|
|
480
|
+
const statusParts = [];
|
|
481
|
+
if (botConfigured)
|
|
482
|
+
statusParts.push("Bot ✓");
|
|
483
|
+
if (agentConfigured)
|
|
484
|
+
statusParts.push("Agent ✓");
|
|
485
|
+
const accountSuffix = accounts.length > 1 ? ` · ${accounts.length} accounts` : "";
|
|
486
|
+
const statusSummary = statusParts.length > 0 ? statusParts.join(" + ") : "已配置";
|
|
487
|
+
return {
|
|
488
|
+
configured,
|
|
489
|
+
statusLines: [
|
|
490
|
+
`WeCom (企业微信): ${configured ? `${statusSummary}${accountSuffix}` : "需要配置"}`,
|
|
491
|
+
],
|
|
492
|
+
selectionHint: configured
|
|
493
|
+
? `configured · ${statusSummary}${accountSuffix}`
|
|
494
|
+
: "官方推荐 · 功能强大 · 上手简单",
|
|
495
|
+
quickstartScore: configured ? 1 : 8,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
async function runWecomSetupFlow(params) {
|
|
499
|
+
const mode = await promptMode(params.prompter);
|
|
500
|
+
let next = params.cfg;
|
|
501
|
+
const configuredModes = [];
|
|
502
|
+
if (mode === "bot" || mode === "both") {
|
|
503
|
+
next = await configureBotMode(next, params.prompter, params.accountId);
|
|
504
|
+
configuredModes.push("bot");
|
|
505
|
+
}
|
|
506
|
+
if (mode === "agent" || mode === "both") {
|
|
507
|
+
next = await configureAgentMode(next, params.prompter, params.accountId);
|
|
508
|
+
configuredModes.push("agent");
|
|
509
|
+
}
|
|
510
|
+
next = await promptDmPolicy(next, params.prompter, configuredModes, params.accountId);
|
|
511
|
+
next = setWecomEnabled(next, true);
|
|
512
|
+
await showSummary(next, params.prompter, params.accountId);
|
|
513
|
+
return next;
|
|
514
|
+
}
|
|
515
|
+
export const wecomSetupWizard = {
|
|
516
|
+
channel,
|
|
517
|
+
status: {
|
|
518
|
+
configuredLabel: "已配置",
|
|
519
|
+
unconfiguredLabel: "需要配置",
|
|
520
|
+
configuredHint: "configured",
|
|
521
|
+
unconfiguredHint: "官方推荐 · 功能强大 · 上手简单",
|
|
522
|
+
configuredScore: 1,
|
|
523
|
+
unconfiguredScore: 8,
|
|
524
|
+
resolveConfigured: async ({ cfg }) => (await getWecomSetupStatus(cfg)).configured,
|
|
525
|
+
resolveStatusLines: async ({ cfg }) => (await getWecomSetupStatus(cfg)).statusLines,
|
|
526
|
+
resolveSelectionHint: async ({ cfg }) => (await getWecomSetupStatus(cfg)).selectionHint,
|
|
527
|
+
resolveQuickstartScore: async ({ cfg }) => (await getWecomSetupStatus(cfg)).quickstartScore,
|
|
528
|
+
},
|
|
529
|
+
resolveAccountIdForConfigure: async ({ cfg, prompter, accountOverride, shouldPromptAccountIds, }) => {
|
|
530
|
+
await showWelcome(prompter);
|
|
531
|
+
return await resolveOnboardingAccountId({
|
|
532
|
+
cfg,
|
|
533
|
+
prompter,
|
|
534
|
+
accountOverride,
|
|
535
|
+
shouldPromptAccountIds,
|
|
536
|
+
});
|
|
537
|
+
},
|
|
538
|
+
credentials: [],
|
|
539
|
+
finalize: async ({ cfg, accountId, prompter }) => ({
|
|
540
|
+
cfg: await runWecomSetupFlow({
|
|
541
|
+
cfg,
|
|
542
|
+
prompter,
|
|
543
|
+
accountId,
|
|
544
|
+
}),
|
|
545
|
+
}),
|
|
546
|
+
};
|