@sunnoy/wecom 1.2.0 → 1.4.0
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/README.md +831 -147
- package/dynamic-agent.js +18 -4
- package/index.js +16 -1602
- package/package.json +8 -2
- package/wecom/accounts.js +258 -0
- package/wecom/agent-api.js +251 -0
- package/wecom/agent-inbound.js +441 -0
- package/wecom/allow-from.js +45 -0
- package/wecom/channel-plugin.js +732 -0
- package/wecom/commands.js +90 -0
- package/wecom/constants.js +58 -0
- package/wecom/http-handler.js +315 -0
- package/wecom/inbound-processor.js +531 -0
- package/wecom/media.js +118 -0
- package/wecom/outbound-delivery.js +484 -0
- package/wecom/response-url.js +33 -0
- package/wecom/state.js +84 -0
- package/wecom/stream-utils.js +124 -0
- package/wecom/target.js +57 -0
- package/wecom/webhook-bot.js +155 -0
- package/wecom/webhook-targets.js +28 -0
- package/wecom/workspace-template.js +165 -0
- package/wecom/xml-parser.js +126 -0
- package/README_ZH.md +0 -303
package/dynamic-agent.js
CHANGED
|
@@ -8,25 +8,39 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Build a deterministic agent id for dm/group contexts.
|
|
10
10
|
*
|
|
11
|
+
* When running in multi-account mode the accountId is embedded as a
|
|
12
|
+
* namespace segment so each account's conversations stay isolated:
|
|
13
|
+
* default → wecom-dm-{peerId} (backward compatible)
|
|
14
|
+
* "sales" → wecom-sales-dm-{peerId}
|
|
15
|
+
*
|
|
11
16
|
* @param {string} chatType - "dm" or "group"
|
|
12
17
|
* @param {string} peerId - user id or group id
|
|
18
|
+
* @param {string} [accountId] - optional account namespace ("default" is omitted)
|
|
13
19
|
* @returns {string} agentId
|
|
14
20
|
*/
|
|
15
|
-
export function generateAgentId(chatType, peerId) {
|
|
21
|
+
export function generateAgentId(chatType, peerId, accountId) {
|
|
16
22
|
const sanitizedId = String(peerId)
|
|
17
23
|
.toLowerCase()
|
|
18
24
|
.replace(/[^a-z0-9_-]/g, "_");
|
|
25
|
+
// Only embed the account prefix for non-default accounts so existing
|
|
26
|
+
// single-account deployments keep identical agent ids (zero breaking change).
|
|
27
|
+
const ns = accountId && accountId !== "default" ? `${accountId}-` : "";
|
|
19
28
|
if (chatType === "group") {
|
|
20
|
-
return `wecom
|
|
29
|
+
return `wecom-${ns}group-${sanitizedId}`;
|
|
21
30
|
}
|
|
22
|
-
return `wecom
|
|
31
|
+
return `wecom-${ns}dm-${sanitizedId}`;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
/**
|
|
26
35
|
* Resolve runtime dynamic-agent settings from config.
|
|
36
|
+
*
|
|
37
|
+
* Accepts either the full openclaw config (legacy) or a per-account wecom
|
|
38
|
+
* config block directly (multi-account). Detection: if the object has
|
|
39
|
+
* `channels.wecom`, unwrap it; otherwise treat the object itself as the
|
|
40
|
+
* wecom account config.
|
|
27
41
|
*/
|
|
28
42
|
export function getDynamicAgentConfig(config) {
|
|
29
|
-
const wecom = config?.channels?.wecom
|
|
43
|
+
const wecom = config?.channels?.wecom ?? config ?? {};
|
|
30
44
|
return {
|
|
31
45
|
enabled: wecom.dynamicAgents?.enabled !== false,
|
|
32
46
|
dmCreateAgent: wecom.dm?.createAgentOnFirstMessage !== false,
|