@xfxstudio/claworld 0.2.15 → 0.2.16

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.
@@ -79,17 +79,12 @@ export function normalizeChatRequestApprovalBlocks(value = {}) {
79
79
 
80
80
  export function normalizeChatRequestApprovalPolicy(
81
81
  value = {},
82
- { fallbackMode = DEFAULT_MODE, legacyAutoAccept = null } = {},
82
+ { fallbackMode = DEFAULT_MODE } = {},
83
83
  ) {
84
84
  const candidate = value && typeof value === 'object' && !Array.isArray(value) ? value : {};
85
- const normalizedLegacyAutoAccept = typeof legacyAutoAccept === 'boolean' ? legacyAutoAccept : null;
86
85
  const mode = normalizeText(candidate.mode, null)
87
86
  ? normalizeChatRequestApprovalMode(candidate.mode, fallbackMode)
88
- : normalizedLegacyAutoAccept === true
89
- ? 'open'
90
- : normalizedLegacyAutoAccept === false
91
- ? 'manual_review'
92
- : normalizeChatRequestApprovalMode(fallbackMode, DEFAULT_MODE);
87
+ : normalizeChatRequestApprovalMode(fallbackMode, DEFAULT_MODE);
93
88
 
94
89
  return {
95
90
  mode,
@@ -30,44 +30,6 @@ function normalizeBroadcastConfig(broadcast = {}) {
30
30
  };
31
31
  }
32
32
 
33
- function isEmptyProfileValue(value) {
34
- if (value == null) return true;
35
- if (typeof value === 'string') return value.trim() === '';
36
- if (Array.isArray(value)) return value.length === 0 || value.every((entry) => isEmptyProfileValue(entry));
37
- if (typeof value === 'object') {
38
- const entries = Object.values(value);
39
- return entries.length === 0 || entries.every((entry) => isEmptyProfileValue(entry));
40
- }
41
- return false;
42
- }
43
-
44
- function normalizeProfileValue(value) {
45
- if (typeof value === 'string') return value.trim();
46
- if (Array.isArray(value)) {
47
- return value
48
- .map((entry) => normalizeProfileValue(entry))
49
- .filter((entry) => entry !== undefined && !isEmptyProfileValue(entry));
50
- }
51
- if (value && typeof value === 'object') {
52
- return Object.fromEntries(
53
- Object.entries(value)
54
- .filter(([, entry]) => entry !== undefined)
55
- .map(([key, entry]) => [key, normalizeProfileValue(entry)]),
56
- );
57
- }
58
- return value;
59
- }
60
-
61
- export function normalizeProfile(profile = {}) {
62
- if (!profile || typeof profile !== 'object' || Array.isArray(profile)) return {};
63
-
64
- return Object.fromEntries(
65
- Object.entries(profile)
66
- .filter(([key, value]) => normalizeText(key, null) && value !== undefined)
67
- .map(([key, value]) => [normalizeText(key, null), normalizeProfileValue(value)]),
68
- );
69
- }
70
-
71
33
  function normalizeLookupText(value) {
72
34
  return normalizeText(value, '')?.toLowerCase() || '';
73
35
  }
@@ -297,33 +259,21 @@ function normalizeDeliveryReason(reason = {}) {
297
259
  };
298
260
  }
299
261
 
300
- function normalizeCandidateScoreBreakdown(entries = []) {
301
- if (!Array.isArray(entries)) return [];
302
-
303
- return entries.map((entry, index) => ({
304
- signalId: normalizeText(entry.signalId, `score_signal_${index + 1}`),
305
- label: normalizeText(entry.label, `Signal ${index + 1}`),
306
- weight: normalizeNumber(entry.weight, 0),
307
- sourceFieldIds: normalizeStringList(entry.sourceFieldIds),
308
- matched: entry.matched === true,
309
- requesterValue: entry.requesterValue ?? null,
310
- candidateValue: entry.candidateValue ?? null,
311
- sharedValues: Array.isArray(entry.sharedValues) ? normalizeStringList(entry.sharedValues) : [],
312
- overlapCount: normalizeInteger(entry.overlapCount, 0),
313
- contribution: normalizeNumber(entry.contribution, 0),
314
- }));
315
- }
316
-
317
262
  function normalizeCandidate(candidate = {}, index = 0) {
318
263
  const normalizedRank = normalizeNumber(candidate.rank, null);
319
- const targetAgentId = normalizeText(
320
- candidate.targetAgentId || candidate.requestChat?.targetAgentId,
264
+ const displayName = normalizeText(
265
+ candidate.displayName || candidate.profileSummary?.displayName || candidate.requestChat?.displayName,
321
266
  null,
322
267
  );
323
- const requestChat = targetAgentId
268
+ const agentCode = normalizeText(
269
+ candidate.agentCode || candidate.requestChat?.agentCode,
270
+ null,
271
+ )?.toUpperCase() || null;
272
+ const requestChat = displayName && agentCode
324
273
  ? {
325
274
  worldId: normalizeText(candidate.requestChat?.worldId, normalizeText(candidate.worldId, 'unknown-world')),
326
- targetAgentId,
275
+ displayName,
276
+ agentCode,
327
277
  }
328
278
  : null;
329
279
 
@@ -332,7 +282,8 @@ function normalizeCandidate(candidate = {}, index = 0) {
332
282
  worldId: normalizeText(candidate.worldId, 'unknown-world'),
333
283
  sourceMembershipId: normalizeText(candidate.sourceMembershipId, null),
334
284
  online: candidate.online === true,
335
- targetAgentId,
285
+ displayName,
286
+ agentCode,
336
287
  requestChat,
337
288
  profileSummary: normalizeCandidateProfileSummary(candidate.profileSummary),
338
289
  compatibilitySignals: Array.isArray(candidate.compatibilitySignals)
@@ -343,19 +294,16 @@ function normalizeCandidate(candidate = {}, index = 0) {
343
294
  joinedAt: normalizeText(candidate.joinedAt, null),
344
295
  rank: normalizedRank == null ? null : Math.max(1, Math.trunc(normalizedRank)),
345
296
  score: normalizeNumber(candidate.score, null),
346
- scoreBreakdown: normalizeCandidateScoreBreakdown(candidate.scoreBreakdown),
347
- scoringInputs: candidate.scoringInputs && typeof candidate.scoringInputs === 'object' ? candidate.scoringInputs : {},
348
297
  };
349
298
  }
350
299
 
351
- function normalizeCandidateFeedResponse(payload = {}, { worldId = null, agentId = null } = {}) {
300
+ function normalizeCandidateFeedResponse(payload = {}, { worldId = null } = {}) {
352
301
  const candidates = Array.isArray(payload.candidates)
353
302
  ? payload.candidates.map((candidate, index) => normalizeCandidate(candidate, index))
354
303
  : [];
355
304
 
356
305
  return {
357
306
  worldId: normalizeText(payload.worldId, worldId || 'unknown-world'),
358
- agentId: normalizeText(payload.agentId, agentId || null),
359
307
  viewerMembershipId: normalizeText(payload.viewerMembershipId, null),
360
308
  generatedAt: normalizeText(payload.generatedAt, null),
361
309
  expiresAt: normalizeText(payload.expiresAt, null),
@@ -652,7 +600,6 @@ export function buildCandidateDeliverySummary(candidateFeed = {}, { worldDetail
652
600
  const detail = worldDetail ? normalizeWorldDetail(worldDetail) : null;
653
601
  const normalizedFeed = normalizeCandidateFeedResponse(candidateFeed, {
654
602
  worldId: detail?.worldId || candidateFeed.worldId || null,
655
- agentId: candidateFeed.agentId || null,
656
603
  });
657
604
  const summaryLimit = Math.max(
658
605
  1,
@@ -662,9 +609,9 @@ export function buildCandidateDeliverySummary(candidateFeed = {}, { worldDetail
662
609
  const requestChatAction = {
663
610
  action: 'request_chat',
664
611
  worldId: normalizedFeed.worldId,
665
- requiredFields: ['worldId', 'targetAgentId'],
612
+ requiredFields: ['worldId', 'displayName', 'agentCode'],
666
613
  summary:
667
- 'After the user chooses a candidate, request_chat with this worldId and the candidate targetAgentId.',
614
+ 'After the user chooses a candidate, request_chat with this worldId, displayName, and agentCode.',
668
615
  };
669
616
  const candidateSummaries = normalizedFeed.candidates.slice(0, summaryLimit).map((candidate, index) => {
670
617
  const name = candidate.profileSummary.displayName || `Candidate ${index + 1}`;
@@ -692,7 +639,7 @@ export function buildCandidateDeliverySummary(candidateFeed = {}, { worldDetail
692
639
  candidateId: candidate.candidateId,
693
640
  sourceMembershipId: candidate.sourceMembershipId,
694
641
  online: candidate.online === true,
695
- targetAgentId: candidate.targetAgentId,
642
+ agentCode: candidate.agentCode,
696
643
  requestChat: candidate.requestChat,
697
644
  displayName: name,
698
645
  headline: candidate.profileSummary.headline,
@@ -722,7 +669,6 @@ export function buildCandidateDeliverySummary(candidateFeed = {}, { worldDetail
722
669
 
723
670
  return {
724
671
  worldId: normalizedFeed.worldId,
725
- agentId: normalizedFeed.agentId,
726
672
  status: deliveredCandidateCount > 0 ? 'candidate_summary_ready' : 'candidate_summary_pending',
727
673
  deliveredCandidateCount,
728
674
  totalCandidateCount,
@@ -740,8 +686,8 @@ export function buildCandidateDeliverySummary(candidateFeed = {}, { worldDetail
740
686
  user: [heading, promptBody].filter(Boolean).join('\n\n'),
741
687
  followUp: deliveredCandidateCount > 0
742
688
  ? (remainingCandidateCount > 0
743
- ? `Share these ${deliveredCandidateCount} candidate summaries first. If the user chooses someone now, continue with request_chat using that candidate's {worldId, targetAgentId}. If they want more options first, continue with the remaining ${remainingCandidateCount} candidate${remainingCandidateCount === 1 ? '' : 's'} from the same feed.`
744
- : 'Share these candidate summaries and, if the user chooses one, continue with request_chat using the attached {worldId, targetAgentId} payload for that candidate.')
689
+ ? `Share these ${deliveredCandidateCount} candidate summaries first. If the user chooses someone now, continue with request_chat using that candidate's {worldId, displayName, agentCode}. If they want more options first, continue with the remaining ${remainingCandidateCount} candidate${remainingCandidateCount === 1 ? '' : 's'} from the same feed.`
690
+ : 'Share these candidate summaries and, if the user chooses one, continue with request_chat using the attached {worldId, displayName, agentCode} payload for that candidate.')
745
691
  : 'Tell the user candidate delivery can be retried later through the same backend-authored world flow.',
746
692
  },
747
693
  };