@xfxstudio/claworld 2026.4.22-testing.5 → 2026.4.22-testing.7

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,109 @@
1
+ import os from 'os';
2
+ import path from 'path';
3
+
4
+ function normalizeText(value, fallback = null) {
5
+ if (value == null) return fallback;
6
+ const normalized = String(value).trim();
7
+ return normalized || fallback;
8
+ }
9
+
10
+ function expandUserPath(inputPath, homeDir = os.homedir()) {
11
+ const text = normalizeText(inputPath, null);
12
+ if (!text) return null;
13
+ if (text === '~') return homeDir;
14
+ if (text.startsWith('~/') || text.startsWith('~\\')) {
15
+ return path.join(homeDir, text.slice(2));
16
+ }
17
+ return text;
18
+ }
19
+
20
+ function isObject(value) {
21
+ return value && typeof value === 'object' && !Array.isArray(value);
22
+ }
23
+
24
+ export function firstWorkspaceCandidate(...sources) {
25
+ for (const source of sources) {
26
+ if (!isObject(source)) continue;
27
+ const candidates = [
28
+ source.workspaceRoot,
29
+ source.workspaceDir,
30
+ source.workspacePath,
31
+ source.workspace,
32
+ source.cwd,
33
+ source.agent?.workspaceRoot,
34
+ source.agent?.workspaceDir,
35
+ source.agent?.workspace,
36
+ source.context?.workspaceRoot,
37
+ source.context?.workspaceDir,
38
+ source.context?.workspace,
39
+ source.session?.workspaceRoot,
40
+ source.session?.workspaceDir,
41
+ source.session?.workspace,
42
+ ];
43
+ for (const candidate of candidates) {
44
+ const normalized = normalizeText(candidate, null);
45
+ if (normalized) return normalized;
46
+ }
47
+ }
48
+ return null;
49
+ }
50
+
51
+ export function resolveOpenClawAgentId(...sources) {
52
+ for (const source of sources) {
53
+ if (!isObject(source)) continue;
54
+ const candidates = [
55
+ source.agentId,
56
+ source.localAgentId,
57
+ source.agent?.id,
58
+ source.agent?.agentId,
59
+ source.context?.agentId,
60
+ source.context?.localAgentId,
61
+ source.session?.agentId,
62
+ source.session?.localAgentId,
63
+ ];
64
+ for (const candidate of candidates) {
65
+ const normalized = normalizeText(candidate, null);
66
+ if (normalized) return normalized;
67
+ }
68
+ }
69
+ return null;
70
+ }
71
+
72
+ export function resolveAgentConfigEntry(config = {}, agentId = null) {
73
+ const normalizedAgentId = normalizeText(agentId, null);
74
+ if (!normalizedAgentId || !isObject(config?.agents)) return null;
75
+
76
+ const list = config.agents.list;
77
+ if (Array.isArray(list)) {
78
+ const arrayEntry = list.find((entry) => (
79
+ isObject(entry)
80
+ && normalizeText(entry.id ?? entry.agentId ?? entry.name, null) === normalizedAgentId
81
+ ));
82
+ if (arrayEntry) return arrayEntry;
83
+ } else if (isObject(list) && isObject(list[normalizedAgentId])) {
84
+ return list[normalizedAgentId];
85
+ }
86
+
87
+ const directEntry = config.agents[normalizedAgentId];
88
+ return isObject(directEntry) ? directEntry : null;
89
+ }
90
+
91
+ export function resolveOpenClawWorkspaceCandidate({
92
+ sources = [],
93
+ config = {},
94
+ agentId = null,
95
+ } = {}) {
96
+ const sourceList = Array.isArray(sources) ? sources : [sources];
97
+ const directCandidate = firstWorkspaceCandidate(...sourceList);
98
+ if (directCandidate) return directCandidate;
99
+
100
+ const resolvedAgentId = normalizeText(agentId, null) || resolveOpenClawAgentId(...sourceList);
101
+ const agentEntry = resolveAgentConfigEntry(config, resolvedAgentId);
102
+ return firstWorkspaceCandidate(agentEntry, config?.agents?.defaults);
103
+ }
104
+
105
+ export function resolveOpenClawWorkspaceRoot(input = {}, homeDir = os.homedir()) {
106
+ const candidate = resolveOpenClawWorkspaceCandidate(input);
107
+ const expanded = expandUserPath(candidate, homeDir);
108
+ return expanded ? path.resolve(expanded) : null;
109
+ }
@@ -167,7 +167,12 @@ function normalizeWorldBroadcastFailureItem(item = {}) {
167
167
 
168
168
  function normalizeWorldBroadcastResponse(payload = {}) {
169
169
  return {
170
+ accepted: payload.accepted === true,
170
171
  status: normalizeText(payload.status, null),
172
+ commandId: normalizeText(payload.commandId, null),
173
+ command: payload.command && typeof payload.command === 'object' && !Array.isArray(payload.command)
174
+ ? payload.command
175
+ : null,
171
176
  worldId: normalizeText(payload.worldId, null),
172
177
  senderAgentId: normalizeText(payload.senderAgentId, null),
173
178
  senderRole: normalizeWorldRole(payload.senderRole, null),
@@ -175,6 +180,7 @@ function normalizeWorldBroadcastResponse(payload = {}) {
175
180
  excludeSelf: normalizeOptionalBoolean(payload.excludeSelf, null),
176
181
  eligibility: normalizeText(payload.eligibility, null),
177
182
  broadcastId: normalizeText(payload.broadcastId, null),
183
+ fanoutStatus: normalizeText(payload.fanoutStatus, null),
178
184
  totalTargets: normalizeOptionalInteger(payload.totalTargets, null),
179
185
  createdCount: normalizeOptionalInteger(payload.createdCount, null),
180
186
  failedCount: normalizeOptionalInteger(payload.failedCount, null),
@@ -504,5 +510,9 @@ export async function broadcastModeratedWorld({
504
510
  });
505
511
  }
506
512
 
507
- return normalizeWorldBroadcastResponse(result.body);
513
+ return normalizeWorldBroadcastResponse({
514
+ ...result.body,
515
+ worldId: resolvedWorldId,
516
+ senderAgentId: resolvedAgentId,
517
+ });
508
518
  }
@@ -22,11 +22,14 @@ function normalizeStringList(values = []) {
22
22
  }
23
23
 
24
24
  function normalizeBroadcastConfig(broadcast = {}) {
25
+ const normalized = broadcast && typeof broadcast === 'object' && !Array.isArray(broadcast)
26
+ ? broadcast
27
+ : {};
25
28
  return {
26
- enabled: broadcast.enabled === true,
27
- audience: normalizeText(broadcast.audience, 'members'),
28
- replyPolicy: normalizeText(broadcast.replyPolicy, 'zero'),
29
- excludeSelf: broadcast.excludeSelf !== false,
29
+ enabled: normalized.enabled === true,
30
+ audience: normalizeText(normalized.audience, 'members'),
31
+ replyPolicy: normalizeText(normalized.replyPolicy, 'zero'),
32
+ excludeSelf: normalized.excludeSelf !== false,
30
33
  };
31
34
  }
32
35