@xfxstudio/claworld 2026.4.28-testing → 2026.4.28-testing.1

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.
@@ -125,14 +125,6 @@ function projectToolAction(action = null) {
125
125
  payloadTemplate: { ...payloadTemplate, action: 'get_world' },
126
126
  };
127
127
  }
128
- if (tool === 'claworld_search_world_members') {
129
- return {
130
- tool: 'claworld_search',
131
- summary: normalizeText(action.summary, null),
132
- payload: { ...payload, scope: 'world_members' },
133
- payloadTemplate: { ...payloadTemplate, scope: 'world_members' },
134
- };
135
- }
136
128
  return {
137
129
  tool,
138
130
  summary: normalizeText(action.summary, null),
@@ -201,55 +193,6 @@ function projectRequestChatAction(
201
193
  };
202
194
  }
203
195
 
204
- function projectToolCandidateDeliverySummary(
205
- candidateDelivery = {},
206
- {
207
- accountId = null,
208
- requestToolName = 'claworld_manage_conversations',
209
- } = {},
210
- ) {
211
- if (!candidateDelivery || typeof candidateDelivery !== 'object' || Array.isArray(candidateDelivery)) return null;
212
-
213
- const candidateSummaries = Array.isArray(candidateDelivery.candidateSummaries)
214
- ? candidateDelivery.candidateSummaries.map((summary) => ({
215
- candidateId: normalizeText(summary.candidateId, null),
216
- sourceMembershipId: normalizeText(summary.sourceMembershipId, null),
217
- displayName: normalizeText(summary.displayName, null),
218
- worldRole: projectWorldRole(summary.worldRole, null),
219
- headline: normalizeText(summary.headline, null),
220
- online: summary.online === true,
221
- rank: normalizeOptionalInteger(summary.rank, null),
222
- score: normalizeOptionalInteger(summary.score, null),
223
- agentCode: normalizeText(summary.agentCode, summary.requestChat?.agentCode || null)?.toUpperCase() || null,
224
- requestChat: projectRequestChatPayload(summary.requestChat, {
225
- accountId,
226
- requestToolName,
227
- }),
228
- requiredFieldSummary: normalizeStringList(summary.requiredFieldSummary),
229
- optionalFieldSummary: normalizeStringList(summary.optionalFieldSummary),
230
- compatibilitySummary: normalizeStringList(summary.compatibilitySummary),
231
- deliveryReasonSummary: normalizeText(summary.deliveryReasonSummary, null),
232
- expiresAt: normalizeText(summary.expiresAt, null),
233
- summary: normalizeText(summary.summary, null),
234
- }))
235
- : [];
236
-
237
- return {
238
- status: normalizeText(candidateDelivery.status, null),
239
- worldId: normalizeText(candidateDelivery.worldId, null),
240
- deliveredCandidateCount: normalizeInteger(candidateDelivery.deliveredCandidateCount, candidateSummaries.length),
241
- totalCandidateCount: normalizeInteger(candidateDelivery.totalCandidateCount, candidateSummaries.length),
242
- remainingCandidateCount: normalizeInteger(candidateDelivery.remainingCandidateCount, 0),
243
- nextAction: normalizeText(candidateDelivery.nextAction, null),
244
- requestChatAction: projectRequestChatAction(candidateDelivery.requestChatAction, {
245
- accountId,
246
- requestToolName,
247
- }),
248
- candidateSummaries,
249
- orchestration: projectOrchestration(candidateDelivery.orchestration),
250
- };
251
- }
252
-
253
196
  export function projectToolWorldList(worldDirectory = {}) {
254
197
  const worlds = Array.isArray(worldDirectory.items)
255
198
  ? worldDirectory.items.map((world) => ({
@@ -359,23 +302,7 @@ export function projectToolWorldDetail(worldDetail = {}, { accountId = null } =
359
302
  };
360
303
  }
361
304
 
362
- function projectToolCandidateSummary(summary = {}, index = 0) {
363
- return {
364
- candidateId: normalizeText(summary.candidateId, `candidate_${index + 1}`),
365
- displayName: normalizeText(summary.displayName, `Candidate ${index + 1}`),
366
- agentCode: normalizeText(summary.agentCode, null)?.toUpperCase() || null,
367
- worldRole: projectWorldRole(summary.worldRole, null),
368
- headline: normalizeText(summary.headline, null),
369
- online: summary.online === true,
370
- rank: normalizeInteger(summary.rank, 0) || null,
371
- score: normalizeInteger(summary.score, 0) || null,
372
- summary: normalizeText(summary.summary, null),
373
- expiresAt: normalizeText(summary.expiresAt, null),
374
- worldFeedbackSummary: projectWorldFeedbackSummary(summary.worldFeedbackSummary),
375
- };
376
- }
377
-
378
- function projectCandidateProfileSummary(summary = {}) {
305
+ function projectMemberProfileSummary(summary = {}) {
379
306
  return {
380
307
  displayName: normalizeText(summary.displayName, null),
381
308
  headline: normalizeText(summary.headline, null),
@@ -396,123 +323,6 @@ function projectCandidateProfileSummary(summary = {}) {
396
323
  };
397
324
  }
398
325
 
399
- function resolveCandidateProjectionPayload(payload = {}) {
400
- if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
401
- return {
402
- worldId: null,
403
- nextAction: null,
404
- candidateFeed: null,
405
- candidateDelivery: null,
406
- requestChatAction: null,
407
- };
408
- }
409
-
410
- const candidateFeed = payload.candidateFeed && typeof payload.candidateFeed === 'object' && !Array.isArray(payload.candidateFeed)
411
- ? payload.candidateFeed
412
- : Array.isArray(payload.candidates)
413
- ? payload
414
- : null;
415
- const candidateDelivery = payload.candidateDelivery && typeof payload.candidateDelivery === 'object' && !Array.isArray(payload.candidateDelivery)
416
- ? payload.candidateDelivery
417
- : candidateFeed?.candidateDelivery && typeof candidateFeed.candidateDelivery === 'object' && !Array.isArray(candidateFeed.candidateDelivery)
418
- ? candidateFeed.candidateDelivery
419
- : null;
420
- const candidateModelRequestChatAction = candidateFeed?.candidateModel && typeof candidateFeed.candidateModel === 'object' && !Array.isArray(candidateFeed.candidateModel)
421
- ? candidateFeed.candidateModel.requestChatAction
422
- : null;
423
-
424
- return {
425
- worldId: normalizeText(payload.worldId, normalizeText(candidateFeed?.worldId, normalizeText(candidateDelivery?.worldId, null))),
426
- nextAction: normalizeText(payload.nextAction, normalizeText(candidateFeed?.nextAction, normalizeText(candidateDelivery?.nextAction, null))),
427
- candidateFeed,
428
- candidateDelivery,
429
- requestChatAction: payload.requestChatAction && typeof payload.requestChatAction === 'object' && !Array.isArray(payload.requestChatAction)
430
- ? payload.requestChatAction
431
- : candidateDelivery?.requestChatAction && typeof candidateDelivery.requestChatAction === 'object' && !Array.isArray(candidateDelivery.requestChatAction)
432
- ? candidateDelivery.requestChatAction
433
- : candidateModelRequestChatAction && typeof candidateModelRequestChatAction === 'object' && !Array.isArray(candidateModelRequestChatAction)
434
- ? candidateModelRequestChatAction
435
- : null,
436
- };
437
- }
438
-
439
- function projectToolCandidateFeed(payload = {}) {
440
- const { candidateFeed, candidateDelivery } = resolveCandidateProjectionPayload(payload);
441
- const candidateSummaries = Array.isArray(candidateDelivery?.candidateSummaries)
442
- ? candidateDelivery.candidateSummaries.map((summary, index) => projectToolCandidateSummary(summary, index))
443
- : Array.isArray(candidateFeed?.candidates)
444
- ? candidateFeed.candidates.map((candidate, index) => projectToolCandidateSummary({
445
- candidateId: candidate.candidateId,
446
- displayName: candidate.profileSummary?.displayName,
447
- agentCode: normalizeText(candidate.agentCode, candidate.requestChat?.agentCode || null),
448
- worldRole: candidate.worldRole,
449
- headline: candidate.profileSummary?.headline,
450
- online: candidate.online === true,
451
- rank: candidate.rank,
452
- score: candidate.score,
453
- summary: normalizeText(candidate.deliveryReason?.summary, null),
454
- expiresAt: candidate.expiresAt,
455
- worldFeedbackSummary: candidate.worldFeedbackSummary,
456
- }, index))
457
- : [];
458
-
459
- return {
460
- status: normalizeText(
461
- candidateDelivery?.status,
462
- normalizeText(candidateFeed?.status, candidateSummaries.length > 0 ? 'candidate_summary_ready' : 'candidate_summary_pending'),
463
- ),
464
- nextAction: normalizeText(
465
- candidateDelivery?.nextAction,
466
- normalizeText(candidateFeed?.nextAction, candidateSummaries.length > 0 ? 'review_candidates_then_request_chat' : 'wait_for_more_candidates'),
467
- ),
468
- deliveredCandidateCount: normalizeInteger(candidateDelivery?.deliveredCandidateCount, candidateSummaries.length),
469
- totalCandidateCount: normalizeInteger(
470
- candidateDelivery?.totalCandidateCount,
471
- normalizeInteger(candidateFeed?.totalCandidates, candidateSummaries.length),
472
- ),
473
- remainingCandidateCount: normalizeInteger(candidateDelivery?.remainingCandidateCount, 0),
474
- candidates: candidateSummaries,
475
- };
476
- }
477
-
478
- function projectToolCandidateFlowResponse(payload = {}, { accountId = null } = {}) {
479
- const {
480
- worldId,
481
- nextAction,
482
- candidateFeed,
483
- candidateDelivery,
484
- requestChatAction,
485
- } = resolveCandidateProjectionPayload(payload);
486
- const projectedFeed = projectToolCandidateFeed({ candidateFeed, candidateDelivery });
487
- const projectedDelivery = projectToolCandidateDeliverySummary(candidateDelivery, { accountId });
488
- const projectedRequestChatAction = projectRequestChatAction(requestChatAction, { accountId });
489
-
490
- return {
491
- worldId: normalizeText(worldId, normalizeText(projectedDelivery?.worldId, null)),
492
- nextAction: normalizeText(nextAction, normalizeText(projectedFeed?.nextAction, normalizeText(projectedDelivery?.nextAction, null))),
493
- candidateFeed: projectedFeed,
494
- requestChatTool: 'claworld_manage_conversations',
495
- candidateDelivery: projectedDelivery,
496
- requestChatAction: projectedRequestChatAction,
497
- };
498
- }
499
-
500
- export function projectToolCandidateFeedResponse(candidateFeedPayload = {}, { accountId = null } = {}) {
501
- const candidateFlow = projectToolCandidateFlowResponse(candidateFeedPayload, { accountId });
502
-
503
- return {
504
- status: normalizeText(candidateFeedPayload.status, normalizeText(candidateFlow.candidateFeed?.status, 'no_candidates_ready')),
505
- worldId: candidateFlow.worldId,
506
- accountId: normalizeText(accountId, null),
507
- nextAction: candidateFlow.nextAction,
508
- candidateFeed: candidateFlow.candidateFeed,
509
- requestChatTool: candidateFlow.requestChatTool,
510
- candidateDelivery: candidateFlow.candidateDelivery,
511
- requestChatAction: candidateFlow.requestChatAction,
512
- };
513
- }
514
-
515
-
516
326
  function projectToolJoinAction(action = null, { accountId = null, requestToolName = null } = {}) {
517
327
  if (!action || typeof action !== 'object' || Array.isArray(action)) return null;
518
328
  const normalizedAccountId = normalizeText(accountId, null);
@@ -529,7 +339,7 @@ export function projectToolJoinWorldResponse(
529
339
  { accountId = null } = {},
530
340
  ) {
531
341
  return {
532
- status: joinResult.membershipStatus === 'active' ? 'joined' : 'accepted',
342
+ status: joinResult.membershipStatus === 'active' ? 'active' : 'accepted',
533
343
  worldId: normalizeText(joinResult.worldId, null),
534
344
  accountId: normalizeText(accountId, null),
535
345
  worldRole: projectWorldRole(joinResult.worldRole, null),
@@ -706,21 +516,22 @@ export function projectToolWorldMemberSearchResponse(payload = {}, { accountId =
706
516
  status: normalizeText(payload.status, 'no_matches'),
707
517
  worldId: normalizeText(payload.worldId, null),
708
518
  query: normalizeText(payload.query, null),
709
- sort: normalizeText(payload.sort, 'match'),
519
+ sort: normalizeText(payload.sort, 'relevance'),
710
520
  limit: normalizeInteger(payload.limit, 0),
711
521
  totalMatches: normalizeInteger(payload.totalMatches, Array.isArray(payload.items) ? payload.items.length : 0),
712
522
  nextAction: normalizeText(payload.nextAction, null),
713
523
  members: Array.isArray(payload.items)
714
524
  ? payload.items.map((item, index) => ({
715
- candidateId: normalizeText(item.membershipId, `candidate_${index + 1}`),
716
- displayName: normalizeText(item.displayName, `Candidate ${index + 1}`),
525
+ memberId: normalizeText(item.membershipId, `member_${index + 1}`),
526
+ membershipId: normalizeText(item.membershipId, null),
527
+ displayName: normalizeText(item.displayName, `Member ${index + 1}`),
717
528
  agentCode: normalizeText(item.agentCode, null)?.toUpperCase() || null,
718
529
  headline: normalizeText(item.headline, null),
719
530
  online: item.online === true,
720
531
  score: normalizeInteger(item.score, 0),
721
532
  matchedFieldIds: normalizeStringList(item.matchedFieldIds),
722
533
  reasonSummary: normalizeText(item.reasonSummary, null),
723
- profileSummary: projectCandidateProfileSummary(item.profileSummary || {}),
534
+ profileSummary: projectMemberProfileSummary(item.profileSummary || {}),
724
535
  worldFeedbackSummary: projectWorldFeedbackSummary(item.worldFeedbackSummary),
725
536
  requestChat: projectRequestChatPayload(item.requestChat, { accountId }),
726
537
  }))
@@ -17,16 +17,12 @@ export const CLAWORLD_CONVERSATION_TOOL_NAMES = Object.freeze([
17
17
  'claworld_manage_conversations',
18
18
  ]);
19
19
 
20
- export const CLAWORLD_FEEDBACK_TOOL_NAMES = Object.freeze([
21
- 'claworld_submit_feedback',
22
- ]);
23
20
 
24
21
  export const CLAWORLD_REGISTERED_TOOL_NAMES = Object.freeze([
25
22
  ...CLAWORLD_ACCOUNT_TOOL_NAMES,
26
23
  ...CLAWORLD_SEARCH_TOOL_NAMES,
27
24
  ...CLAWORLD_WORLD_TOOL_NAMES,
28
25
  ...CLAWORLD_CONVERSATION_TOOL_NAMES,
29
- ...CLAWORLD_FEEDBACK_TOOL_NAMES,
30
26
  ]);
31
27
 
32
28
  export const CLAWORLD_PUBLIC_TOOL_NAMES = Object.freeze([
@@ -34,17 +30,6 @@ export const CLAWORLD_PUBLIC_TOOL_NAMES = Object.freeze([
34
30
  ]);
35
31
 
36
32
  export const CLAWORLD_RETIRED_PUBLIC_TOOL_NAMES = Object.freeze([
37
- 'claworld_account',
38
- 'claworld_search_worlds',
39
- 'claworld_list_worlds',
40
- 'claworld_get_world_detail',
41
- 'claworld_join_world',
42
- 'claworld_search_world_members',
43
- 'claworld_get_candidate_feed',
44
- 'claworld_create_world',
45
- 'claworld_manage_world',
46
- 'claworld_request_chat',
47
- 'claworld_chat_inbox',
48
33
  ]);
49
34
 
50
35
  export const CLAWORLD_MINIMAL_OPENCLAW_TOOL_NAMES = Object.freeze([
@@ -602,7 +602,6 @@ function compactResultPayload(payload = {}) {
602
602
  'displayName',
603
603
  'chatRequestId',
604
604
  'conversationKey',
605
- 'candidateId',
606
605
  'feedbackId',
607
606
  'nextAction',
608
607
  'requiredAction',
@@ -632,7 +631,6 @@ export function buildClaworldToolMaintenanceEvent({
632
631
  worldId: params.worldId || payload.worldId,
633
632
  chatRequestId: params.chatRequestId || payload.chatRequestId,
634
633
  conversationKey: params.conversationKey || payload.conversationKey,
635
- candidateId: params.candidateId || payload.candidateId,
636
634
  agentCode: params.agentCode || payload.agentCode,
637
635
  };
638
636
  return buildClaworldMaintenanceEvent({
@@ -92,6 +92,34 @@ function normalizeWorldBroadcastConfig(broadcast = null) {
92
92
  };
93
93
  }
94
94
 
95
+ function normalizeWorldInvite(payload = {}) {
96
+ return {
97
+ status: normalizeText(payload.status, null),
98
+ worldId: normalizeText(payload.worldId, null),
99
+ displayName: normalizeText(payload.displayName, null),
100
+ targetAgentId: normalizeText(payload.targetAgentId, null),
101
+ targetIdentity: normalizeText(payload.targetIdentity, null),
102
+ invitedByAgentId: normalizeText(payload.invitedByAgentId, null),
103
+ membershipId: normalizeText(payload.membershipId, null),
104
+ membershipStatus: normalizeText(payload.membershipStatus, null),
105
+ created: normalizeOptionalBoolean(payload.created, null),
106
+ invitedAt: normalizeText(payload.invitedAt, null),
107
+ inviteMessage: normalizeText(payload.inviteMessage, null),
108
+ inviteRevokedAt: normalizeText(payload.inviteRevokedAt, null),
109
+ notificationId: normalizeText(payload.notificationId, null),
110
+ nextAction: normalizeText(payload.nextAction, null),
111
+ };
112
+ }
113
+
114
+ function normalizeWorldInviteList(payload = {}) {
115
+ return {
116
+ worldId: normalizeText(payload.worldId, null),
117
+ items: Array.isArray(payload.items) ? payload.items.map((item) => normalizeWorldInvite(item)) : [],
118
+ totalItems: normalizeOptionalInteger(payload.totalItems, 0),
119
+ nextAction: normalizeText(payload.nextAction, null),
120
+ };
121
+ }
122
+
95
123
  function normalizeManagedWorld(payload = {}) {
96
124
  return {
97
125
  worldId: normalizeText(payload.worldId, null),
@@ -101,6 +129,10 @@ function normalizeManagedWorld(payload = {}) {
101
129
  enabled: normalizeOptionalBoolean(payload.enabled, null),
102
130
  status: normalizeText(payload.status, null),
103
131
  worldRole: normalizeWorldRole(payload.worldRole, null),
132
+ visibility: normalizeText(payload.visibility, 'public'),
133
+ identityMode: normalizeText(payload.identityMode, 'imaginary'),
134
+ joinPolicy: normalizeText(payload.joinPolicy, 'open'),
135
+ approvalPolicy: normalizeText(payload.approvalPolicy, 'auto'),
104
136
  schemaVersion: normalizeOptionalInteger(payload.schemaVersion, null),
105
137
  createdAt: normalizeText(payload.createdAt, null),
106
138
  updatedAt: normalizeText(payload.updatedAt, null),
@@ -133,6 +165,10 @@ function normalizeOwnedWorldSummary(payload = {}) {
133
165
  enabled: normalizeOptionalBoolean(payload.enabled, null),
134
166
  status: normalizeText(payload.status, null),
135
167
  worldRole: normalizeWorldRole(payload.worldRole, null),
168
+ visibility: normalizeText(payload.visibility, 'public'),
169
+ identityMode: normalizeText(payload.identityMode, 'imaginary'),
170
+ joinPolicy: normalizeText(payload.joinPolicy, 'open'),
171
+ approvalPolicy: normalizeText(payload.approvalPolicy, 'auto'),
136
172
  createdAt: normalizeText(payload.createdAt, null),
137
173
  updatedAt: normalizeText(payload.updatedAt, null),
138
174
  broadcast: normalizeWorldBroadcastConfig(payload.broadcast),
@@ -273,6 +309,10 @@ export async function createModeratedWorld({
273
309
  worldContextText = null,
274
310
  participantContextText = null,
275
311
  enabled = true,
312
+ visibility = null,
313
+ identityMode = null,
314
+ joinPolicy = null,
315
+ approvalPolicy = null,
276
316
  fetchImpl,
277
317
  logger = console,
278
318
  } = {}) {
@@ -300,6 +340,10 @@ export async function createModeratedWorld({
300
340
  worldContextText,
301
341
  participantContextText: normalizeText(participantContextText, null),
302
342
  enabled,
343
+ ...(normalizeText(visibility, null) ? { visibility: normalizeText(visibility, null) } : {}),
344
+ ...(normalizeText(identityMode, null) ? { identityMode: normalizeText(identityMode, null) } : {}),
345
+ ...(normalizeText(joinPolicy, null) ? { joinPolicy: normalizeText(joinPolicy, null) } : {}),
346
+ ...(normalizeText(approvalPolicy, null) ? { approvalPolicy: normalizeText(approvalPolicy, null) } : {}),
303
347
  }),
304
348
  });
305
349
 
@@ -449,6 +493,170 @@ export async function manageModeratedWorld({
449
493
  return normalizeManagedWorld(result.body);
450
494
  }
451
495
 
496
+ export async function inviteModeratedWorldMember({
497
+ cfg = {},
498
+ accountId = null,
499
+ runtimeConfig = null,
500
+ agentId = null,
501
+ worldId = null,
502
+ targetAgentId = null,
503
+ identity = null,
504
+ inviteMessage = null,
505
+ fetchImpl,
506
+ logger = console,
507
+ } = {}) {
508
+ if (typeof fetchImpl !== 'function') {
509
+ throw new Error('fetch is unavailable for claworld world invite helper');
510
+ }
511
+
512
+ const resolvedAgentId = normalizeText(agentId, null);
513
+ if (!resolvedAgentId) {
514
+ throw new Error('claworld world invite helper requires agentId');
515
+ }
516
+ const resolvedWorldId = normalizeText(worldId, null);
517
+ if (!resolvedWorldId) {
518
+ throw new Error('claworld world invite helper requires worldId');
519
+ }
520
+ const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
521
+ const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
522
+ const result = await fetchJson(fetchImpl, `${baseUrl}/v1/moderation/worlds/${encodeURIComponent(resolvedWorldId)}/invitations`, {
523
+ method: 'POST',
524
+ headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
525
+ accept: 'application/json',
526
+ 'content-type': 'application/json',
527
+ ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
528
+ }),
529
+ body: JSON.stringify({
530
+ agentId: resolvedAgentId,
531
+ ...(normalizeText(targetAgentId, null) ? { targetAgentId: normalizeText(targetAgentId, null) } : {}),
532
+ ...(normalizeText(identity, null) ? { identity: normalizeText(identity, null) } : {}),
533
+ ...(normalizeText(inviteMessage, null) ? { inviteMessage: normalizeText(inviteMessage, null) } : {}),
534
+ }),
535
+ });
536
+
537
+ if (!result.ok) {
538
+ logger.error?.('[claworld:moderation] world invite failed', {
539
+ status: result.status,
540
+ worldId: resolvedWorldId,
541
+ accountId: resolvedRuntimeConfig.accountId || accountId || null,
542
+ body: result.body,
543
+ });
544
+ throw createModerationHttpError('invite_member', result, {
545
+ accountId: resolvedRuntimeConfig.accountId || accountId || null,
546
+ worldId: resolvedWorldId,
547
+ });
548
+ }
549
+
550
+ return normalizeWorldInvite(result.body);
551
+ }
552
+
553
+ export async function revokeModeratedWorldInvite({
554
+ cfg = {},
555
+ accountId = null,
556
+ runtimeConfig = null,
557
+ agentId = null,
558
+ worldId = null,
559
+ targetAgentId = null,
560
+ fetchImpl,
561
+ logger = console,
562
+ } = {}) {
563
+ if (typeof fetchImpl !== 'function') {
564
+ throw new Error('fetch is unavailable for claworld world invite revoke helper');
565
+ }
566
+
567
+ const resolvedAgentId = normalizeText(agentId, null);
568
+ if (!resolvedAgentId) {
569
+ throw new Error('claworld world invite revoke helper requires agentId');
570
+ }
571
+ const resolvedWorldId = normalizeText(worldId, null);
572
+ if (!resolvedWorldId) {
573
+ throw new Error('claworld world invite revoke helper requires worldId');
574
+ }
575
+ const resolvedTargetAgentId = normalizeText(targetAgentId, null);
576
+ if (!resolvedTargetAgentId) {
577
+ throw new Error('claworld world invite revoke helper requires targetAgentId');
578
+ }
579
+ const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
580
+ const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
581
+ const result = await fetchJson(fetchImpl, `${baseUrl}/v1/moderation/worlds/${encodeURIComponent(resolvedWorldId)}/invitations/revoke`, {
582
+ method: 'POST',
583
+ headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
584
+ accept: 'application/json',
585
+ 'content-type': 'application/json',
586
+ ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
587
+ }),
588
+ body: JSON.stringify({
589
+ agentId: resolvedAgentId,
590
+ targetAgentId: resolvedTargetAgentId,
591
+ }),
592
+ });
593
+
594
+ if (!result.ok) {
595
+ logger.error?.('[claworld:moderation] world invite revoke failed', {
596
+ status: result.status,
597
+ worldId: resolvedWorldId,
598
+ accountId: resolvedRuntimeConfig.accountId || accountId || null,
599
+ body: result.body,
600
+ });
601
+ throw createModerationHttpError('revoke_invite', result, {
602
+ accountId: resolvedRuntimeConfig.accountId || accountId || null,
603
+ worldId: resolvedWorldId,
604
+ });
605
+ }
606
+
607
+ return normalizeWorldInvite(result.body);
608
+ }
609
+
610
+ export async function fetchModeratedWorldInvites({
611
+ cfg = {},
612
+ accountId = null,
613
+ runtimeConfig = null,
614
+ agentId = null,
615
+ worldId = null,
616
+ status = 'invited',
617
+ fetchImpl,
618
+ logger = console,
619
+ } = {}) {
620
+ if (typeof fetchImpl !== 'function') {
621
+ throw new Error('fetch is unavailable for claworld world invites helper');
622
+ }
623
+
624
+ const resolvedAgentId = normalizeText(agentId, null);
625
+ if (!resolvedAgentId) {
626
+ throw new Error('claworld world invites helper requires agentId');
627
+ }
628
+ const resolvedWorldId = normalizeText(worldId, null);
629
+ if (!resolvedWorldId) {
630
+ throw new Error('claworld world invites helper requires worldId');
631
+ }
632
+ const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
633
+ const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
634
+ const requestUrl = new URL(`${baseUrl}/v1/moderation/worlds/${encodeURIComponent(resolvedWorldId)}/invitations`);
635
+ requestUrl.searchParams.set('agentId', resolvedAgentId);
636
+ if (normalizeText(status, null)) requestUrl.searchParams.set('status', normalizeText(status, null));
637
+ const result = await fetchJson(fetchImpl, requestUrl.toString(), {
638
+ headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
639
+ accept: 'application/json',
640
+ ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
641
+ }),
642
+ });
643
+
644
+ if (!result.ok) {
645
+ logger.error?.('[claworld:moderation] world invites fetch failed', {
646
+ status: result.status,
647
+ worldId: resolvedWorldId,
648
+ accountId: resolvedRuntimeConfig.accountId || accountId || null,
649
+ body: result.body,
650
+ });
651
+ throw createModerationHttpError('list_invites', result, {
652
+ accountId: resolvedRuntimeConfig.accountId || accountId || null,
653
+ worldId: resolvedWorldId,
654
+ });
655
+ }
656
+
657
+ return normalizeWorldInviteList(result.body);
658
+ }
659
+
452
660
  export async function broadcastModeratedWorld({
453
661
  cfg = {},
454
662
  accountId = null,