@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/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-group-${sanitizedId}`;
29
+ return `wecom-${ns}group-${sanitizedId}`;
21
30
  }
22
- return `wecom-dm-${sanitizedId}`;
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,