@xmoxmo/bncr 0.6.4 → 0.6.6

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.
@@ -0,0 +1,33 @@
1
+ import type { BncrInboundConfig } from './contracts.ts';
2
+
3
+ /**
4
+ * Inject a sender into cfg.commands.ownerAllowFrom without mutating cfg.
5
+ * The sender is only added when the caller may be treated as an owner for
6
+ * OpenClaw native command dispatch.
7
+ */
8
+ export function mergeBncrOwnerAllowFromIntoConfig(args: {
9
+ cfg: BncrInboundConfig;
10
+ senderIdForContext: string;
11
+ }): BncrInboundConfig {
12
+ const { cfg, senderIdForContext } = args;
13
+ const senderId = String(senderIdForContext || '').trim();
14
+ if (!senderId) return cfg;
15
+
16
+ const rawCommands = cfg.commands;
17
+ const currentCommands: { ownerAllowFrom?: string[] } =
18
+ rawCommands !== null && typeof rawCommands === 'object' && !Array.isArray(rawCommands)
19
+ ? (rawCommands as { ownerAllowFrom?: string[] })
20
+ : {};
21
+ const currentOwnerAllowFrom = Array.isArray(currentCommands.ownerAllowFrom)
22
+ ? currentCommands.ownerAllowFrom
23
+ : [];
24
+ if (currentOwnerAllowFrom.includes(senderId)) return cfg;
25
+
26
+ return {
27
+ ...cfg,
28
+ commands: {
29
+ ...currentCommands,
30
+ ownerAllowFrom: [...currentOwnerAllowFrom, senderId],
31
+ },
32
+ } satisfies BncrInboundConfig;
33
+ }