@xfxstudio/claworld 0.2.12 → 0.2.14

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.
Files changed (62) hide show
  1. package/README.md +45 -19
  2. package/index.js +0 -1
  3. package/openclaw.plugin.json +1 -1
  4. package/package.json +1 -5
  5. package/skills/claworld-help/SKILL.md +84 -91
  6. package/skills/claworld-join-and-chat/SKILL.md +9 -9
  7. package/src/openclaw/index.js +0 -3
  8. package/src/openclaw/plugin/account-identity.js +0 -1
  9. package/src/openclaw/plugin/claworld-channel-plugin.js +8 -253
  10. package/src/openclaw/plugin/managed-config.js +1 -7
  11. package/src/openclaw/plugin/onboarding.js +128 -103
  12. package/src/openclaw/plugin/register.js +183 -232
  13. package/src/openclaw/plugin/relay-client.js +8 -5
  14. package/src/openclaw/runtime/product-shell-helper.js +11 -364
  15. package/src/openclaw/runtime/tool-contracts.js +0 -182
  16. package/src/openclaw/runtime/tool-inventory.js +4 -27
  17. package/bin/claworld.mjs +0 -9
  18. package/src/lib/agent-profile.js +0 -74
  19. package/src/lib/http-auth.js +0 -151
  20. package/src/lib/policy.js +0 -114
  21. package/src/openclaw/installer/cli.js +0 -406
  22. package/src/openclaw/installer/constants.js +0 -14
  23. package/src/openclaw/installer/core.js +0 -2122
  24. package/src/openclaw/installer/doctor.js +0 -876
  25. package/src/openclaw/installer/workspace-contract.js +0 -427
  26. package/src/product-shell/agent-cards/card-routes.js +0 -64
  27. package/src/product-shell/agent-cards/card-service.js +0 -287
  28. package/src/product-shell/agent-cards/spec-builder.js +0 -167
  29. package/src/product-shell/agent-cards/storage/image-host-storage.js +0 -192
  30. package/src/product-shell/agent-cards/storage/local-public-storage.js +0 -74
  31. package/src/product-shell/agent-cards/svg-renderer.js +0 -325
  32. package/src/product-shell/agent-cards/template-registry.js +0 -131
  33. package/src/product-shell/catalog/default-world-catalog.js +0 -38
  34. package/src/product-shell/contracts/candidate-feed.js +0 -393
  35. package/src/product-shell/contracts/world-manifest.js +0 -369
  36. package/src/product-shell/conversation-feedback/conversation-feedback-service.js +0 -261
  37. package/src/product-shell/feedback/feedback-contract.js +0 -13
  38. package/src/product-shell/feedback/feedback-routes.js +0 -98
  39. package/src/product-shell/feedback/feedback-service.js +0 -252
  40. package/src/product-shell/index.js +0 -212
  41. package/src/product-shell/matching/matchmaking-service.js +0 -395
  42. package/src/product-shell/membership/membership-service.js +0 -284
  43. package/src/product-shell/onboarding/onboarding-routes.js +0 -37
  44. package/src/product-shell/onboarding/onboarding-service.js +0 -220
  45. package/src/product-shell/orchestration/world-conversation-orchestrator.js +0 -28
  46. package/src/product-shell/profile/profile-service.js +0 -142
  47. package/src/product-shell/profile/public-identity-routes.js +0 -160
  48. package/src/product-shell/profile/public-identity-service.js +0 -192
  49. package/src/product-shell/search/search-service.js +0 -393
  50. package/src/product-shell/social/chat-request-approval-policy.js +0 -332
  51. package/src/product-shell/social/chat-request-routes.js +0 -130
  52. package/src/product-shell/social/chat-request-service.js +0 -723
  53. package/src/product-shell/social/friend-routes.js +0 -82
  54. package/src/product-shell/social/friend-service.js +0 -557
  55. package/src/product-shell/social/social-routes.js +0 -21
  56. package/src/product-shell/social/social-service.js +0 -136
  57. package/src/product-shell/worlds/world-admin-service.js +0 -486
  58. package/src/product-shell/worlds/world-authorization.js +0 -136
  59. package/src/product-shell/worlds/world-broadcast-service.js +0 -296
  60. package/src/product-shell/worlds/world-routes.js +0 -403
  61. package/src/product-shell/worlds/world-service.js +0 -89
  62. package/src/product-shell/worlds/world-text.js +0 -75
@@ -1,10 +1,8 @@
1
1
  import { resolveClaworldRuntimeConfig } from '../plugin/config-schema.js';
2
- import { buildRuntimeAuthHeaders } from '../plugin/account-identity.js';
3
2
  import { createRuntimeBoundaryError } from '../../lib/runtime-errors.js';
4
3
  import { extractBackendErrorContext } from './backend-error-context.js';
5
4
  import {
6
5
  buildCandidateDeliverySummary as buildBackendCandidateDeliverySummary,
7
- buildWorldSelectionPrompt as buildBackendWorldSelectionPrompt,
8
6
  resolveWorldSelection as resolveBackendWorldSelection,
9
7
  } from '../../product-shell/contracts/world-orchestration.js';
10
8
 
@@ -25,15 +23,6 @@ function normalizeStringList(values = []) {
25
23
  return [...new Set(values.map((value) => normalizeText(value, null)).filter(Boolean))];
26
24
  }
27
25
 
28
- function normalizeBroadcastConfig(broadcast = {}) {
29
- return {
30
- enabled: broadcast.enabled === true,
31
- audience: normalizeText(broadcast.audience, 'members'),
32
- replyPolicy: normalizeText(broadcast.replyPolicy, 'zero'),
33
- excludeSelf: broadcast.excludeSelf !== false,
34
- };
35
- }
36
-
37
26
  function isEmptyProfileValue(value) {
38
27
  if (value == null) return true;
39
28
  if (typeof value === 'string') return value.trim() === '';
@@ -416,88 +405,15 @@ function normalizeWorldJoinResponse(payload = {}, { worldId = null, agentId = nu
416
405
  ? payload.nextStageSummary
417
406
  : {},
418
407
  candidateFeed,
419
- candidateDelivery:
420
- payload.candidateDelivery && typeof payload.candidateDelivery === 'object'
421
- ? payload.candidateDelivery
422
- : (candidateFeed ? buildCandidateDeliverySummary(candidateFeed) : null),
408
+ candidateDelivery: payload.candidateDelivery && typeof payload.candidateDelivery === 'object'
409
+ ? payload.candidateDelivery
410
+ : null,
423
411
  orchestration: payload.orchestration && typeof payload.orchestration === 'object'
424
412
  ? payload.orchestration
425
413
  : null,
426
414
  };
427
415
  }
428
416
 
429
- function normalizeSearchMatchedField(field = {}, index = 0) {
430
- return {
431
- fieldId: normalizeText(field.fieldId, `field_${index + 1}`),
432
- label: normalizeText(field.label, `Field ${index + 1}`),
433
- matchType: normalizeText(field.matchType, 'exact'),
434
- queryValue: field.queryValue ?? null,
435
- candidateValue: field.candidateValue ?? null,
436
- sharedValues: Array.isArray(field.sharedValues) ? normalizeStringList(field.sharedValues) : [],
437
- contribution: normalizeNumber(field.contribution, 0),
438
- };
439
- }
440
-
441
- function normalizeWorldSearchItem(item = {}, index = 0) {
442
- const resolvedAgentId = normalizeText(item.agentId, normalizeText(item.playerId, `agent_${index + 1}`));
443
- return {
444
- agentId: resolvedAgentId,
445
- playerId: normalizeText(item.playerId, resolvedAgentId),
446
- membershipId: normalizeText(item.membershipId, null),
447
- worldId: normalizeText(item.worldId, 'unknown-world'),
448
- displayName: normalizeText(item.displayName, `Player ${index + 1}`),
449
- headline: normalizeText(item.headline, null),
450
- online: item.online === true,
451
- connectedAt: normalizeText(item.connectedAt, null),
452
- lastHeartbeatAt: normalizeText(item.lastHeartbeatAt, null),
453
- score: normalizeNumber(item.score, 0),
454
- matchedFieldIds: normalizeStringList(item.matchedFieldIds),
455
- matchedFields: Array.isArray(item.matchedFields)
456
- ? item.matchedFields.map((field, fieldIndex) => normalizeSearchMatchedField(field, fieldIndex))
457
- : [],
458
- resultType: normalizeText(item.resultType, 'matched'),
459
- reasonSummary: normalizeText(item.reasonSummary, ''),
460
- joinedAt: normalizeText(item.joinedAt, null),
461
- profileSummary: normalizeCandidateProfileSummary(item.profileSummary),
462
- worldFeedbackSummary: item.worldFeedbackSummary && typeof item.worldFeedbackSummary === 'object'
463
- ? {
464
- likesReceived: normalizeInteger(item.worldFeedbackSummary.likesReceived, 0),
465
- dislikesReceived: normalizeInteger(item.worldFeedbackSummary.dislikesReceived, 0),
466
- }
467
- : {
468
- likesReceived: 0,
469
- dislikesReceived: 0,
470
- },
471
- };
472
- }
473
-
474
- function normalizeWorldSearchResponse(payload = {}, { worldId = null, agentId = null } = {}) {
475
- const items = Array.isArray(payload.items)
476
- ? payload.items.map((item, index) => normalizeWorldSearchItem(item, index))
477
- : [];
478
-
479
- return {
480
- worldId: normalizeText(payload.worldId, worldId || 'unknown-world'),
481
- agentId: normalizeText(payload.agentId, agentId || null),
482
- viewerMembershipId: normalizeText(payload.viewerMembershipId, null),
483
- searchModel: normalizeSearchSchema(payload.searchModel || {}, {
484
- worldId: normalizeText(payload.worldId, worldId || 'unknown-world'),
485
- fallbackFields: [],
486
- }),
487
- searchInput: normalizeProfile(payload.searchInput && typeof payload.searchInput === 'object' ? payload.searchInput : {}),
488
- onlineOnly: payload.onlineOnly !== false,
489
- candidateSource: normalizeText(payload.candidateSource, 'active_memberships_online'),
490
- limit: normalizeInteger(payload.limit, items.length),
491
- totalMatches: normalizeInteger(payload.totalMatches, items.length),
492
- status: normalizeText(payload.status, items.length > 0 ? 'search_ready' : 'no_matches'),
493
- nextAction: normalizeText(
494
- payload.nextAction,
495
- items.length > 0 ? 'request_chat_with_selected_candidate' : 'broaden_search_or_wait',
496
- ),
497
- items,
498
- };
499
- }
500
-
501
417
  function summarizeProfileValue(value) {
502
418
  if (Array.isArray(value)) return joinAsNaturalLanguage(value.map((entry) => String(entry).trim()).filter(Boolean));
503
419
  return normalizeText(value, '');
@@ -524,8 +440,6 @@ export function buildCandidateDeliverySummary(candidateFeed = {}, { worldDetail
524
440
  if (worldDetail?.candidateDelivery && typeof worldDetail.candidateDelivery === 'object') {
525
441
  return worldDetail.candidateDelivery;
526
442
  }
527
- // Older responses may still omit candidateDelivery; keep the shared builder as
528
- // a compatibility fallback, not the canonical orchestration owner.
529
443
  return buildBackendCandidateDeliverySummary(candidateFeed, { worldDetail, limit });
530
444
  }
531
445
 
@@ -597,12 +511,9 @@ function buildSelectionRetryContract(status, selection, items = [], matches = []
597
511
  }
598
512
 
599
513
  export function buildWorldSelectionPrompt(worldDirectory = {}) {
600
- if (worldDirectory?.orchestration && typeof worldDirectory.orchestration === 'object') {
601
- return worldDirectory.orchestration;
602
- }
603
- // Compatibility fallback for older directory payloads that predate
604
- // backend-authored orchestration.
605
- return buildBackendWorldSelectionPrompt(worldDirectory);
514
+ return worldDirectory?.orchestration && typeof worldDirectory.orchestration === 'object'
515
+ ? worldDirectory.orchestration
516
+ : null;
606
517
  }
607
518
 
608
519
  export function buildPostSetupWorldDirectory(payload = {}, { accountId = null } = {}) {
@@ -632,7 +543,7 @@ export function buildPostSetupWorldDirectory(payload = {}, { accountId = null }
632
543
  sort,
633
544
  orchestration: payload.orchestration && typeof payload.orchestration === 'object'
634
545
  ? payload.orchestration
635
- : buildWorldSelectionPrompt({ items, recommendedWorldId }),
546
+ : null,
636
547
  };
637
548
  }
638
549
 
@@ -709,56 +620,6 @@ function createProductShellHttpError(action, response, { accountId = null, world
709
620
  });
710
621
  }
711
622
 
712
- function normalizeBroadcastRequestPayload(payload = {}, { message = null } = {}) {
713
- const normalizedPayload = payload && typeof payload === 'object' && !Array.isArray(payload)
714
- ? { ...payload }
715
- : {};
716
- const normalizedMessage = normalizeText(message, null);
717
- if (!normalizedMessage) return normalizedPayload;
718
- return {
719
- ...normalizedPayload,
720
- ...(normalizedPayload.text == null ? { text: normalizedMessage } : {}),
721
- };
722
- }
723
-
724
- function normalizeBroadcastResult(payload = {}) {
725
- const requests = Array.isArray(payload.requests)
726
- ? payload.requests.map((request) => ({
727
- agentId: normalizeText(request.agentId, null),
728
- status: normalizeText(request.status, 'created'),
729
- chatRequest: request.chatRequest && typeof request.chatRequest === 'object' && !Array.isArray(request.chatRequest)
730
- ? request.chatRequest
731
- : null,
732
- }))
733
- : [];
734
- const failures = Array.isArray(payload.failures)
735
- ? payload.failures.map((failure) => ({
736
- agentId: normalizeText(failure.agentId, null),
737
- status: normalizeText(failure.status, 'failed'),
738
- httpStatus: normalizeInteger(failure.httpStatus, 0),
739
- error: normalizeText(failure.error, null),
740
- reason: normalizeText(failure.reason, null),
741
- message: normalizeText(failure.message, null),
742
- }))
743
- : [];
744
- return {
745
- status: normalizeText(payload.status, 'requests_created'),
746
- worldId: normalizeText(payload.worldId, null),
747
- senderAgentId: normalizeText(payload.senderAgentId, null),
748
- senderRole: normalizeText(payload.senderRole, 'none'),
749
- audience: normalizeText(payload.audience, 'members'),
750
- excludeSelf: payload.excludeSelf !== false,
751
- eligibility: normalizeText(payload.eligibility, 'active'),
752
- broadcastId: normalizeText(payload.broadcastId, null),
753
- totalTargets: normalizeInteger(payload.totalTargets, 0),
754
- createdCount: normalizeInteger(payload.createdCount, requests.length),
755
- failedCount: normalizeInteger(payload.failedCount, failures.length),
756
- nextAction: normalizeText(payload.nextAction, 'recipients_review_pending_requests'),
757
- requests,
758
- failures,
759
- };
760
- }
761
-
762
623
  export async function fetchWorldDetail({
763
624
  cfg = {},
764
625
  accountId = null,
@@ -782,7 +643,7 @@ export async function fetchWorldDetail({
782
643
  headers: {
783
644
  accept: 'application/json',
784
645
  ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
785
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
646
+ ...(resolvedRuntimeConfig.relay?.credentialToken ? { authorization: `Bearer ${resolvedRuntimeConfig.relay.credentialToken}` } : {}),
786
647
  },
787
648
  });
788
649
 
@@ -834,7 +695,7 @@ export async function joinWorld({
834
695
  accept: 'application/json',
835
696
  'content-type': 'application/json',
836
697
  ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
837
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
698
+ ...(resolvedRuntimeConfig.relay?.credentialToken ? { authorization: `Bearer ${resolvedRuntimeConfig.relay.credentialToken}` } : {}),
838
699
  },
839
700
  body: JSON.stringify({
840
701
  agentId: resolvedAgentId,
@@ -862,220 +723,6 @@ export async function joinWorld({
862
723
  });
863
724
  }
864
725
 
865
- export async function fetchWorldSearch({
866
- cfg = {},
867
- accountId = null,
868
- runtimeConfig = null,
869
- worldId = null,
870
- agentId = null,
871
- query = {},
872
- limit = null,
873
- fetchImpl,
874
- logger = console,
875
- } = {}) {
876
- if (typeof fetchImpl !== 'function') {
877
- throw new Error('fetch is unavailable for claworld product-shell world search helper');
878
- }
879
-
880
- const resolvedWorldId = normalizeText(worldId, null);
881
- if (!resolvedWorldId) {
882
- throw new Error('claworld product-shell world search helper requires worldId');
883
- }
884
-
885
- const resolvedAgentId = normalizeText(agentId, null);
886
- if (!resolvedAgentId) {
887
- throw new Error('claworld product-shell world search helper requires agentId');
888
- }
889
-
890
- const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
891
- const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
892
- const normalizedQuery = normalizeProfile(query);
893
- const searchResult = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds/${encodeURIComponent(resolvedWorldId)}/search`, {
894
- method: 'POST',
895
- headers: {
896
- accept: 'application/json',
897
- 'content-type': 'application/json',
898
- ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
899
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
900
- },
901
- body: JSON.stringify({
902
- agentId: resolvedAgentId,
903
- query: normalizedQuery,
904
- ...(limit != null ? { limit } : {}),
905
- }),
906
- });
907
-
908
- if (!searchResult.ok) {
909
- logger.error?.('[claworld:product-shell] world search failed', {
910
- status: searchResult.status,
911
- worldId: resolvedWorldId,
912
- agentId: resolvedAgentId,
913
- accountId: resolvedRuntimeConfig.accountId || accountId || null,
914
- body: searchResult.body,
915
- });
916
- throw createProductShellHttpError('world_search', searchResult, {
917
- accountId: resolvedRuntimeConfig.accountId || accountId || null,
918
- worldId: resolvedWorldId,
919
- });
920
- }
921
-
922
- return normalizeWorldSearchResponse(searchResult.body, {
923
- worldId: resolvedWorldId,
924
- agentId: resolvedAgentId,
925
- });
926
- }
927
-
928
- export async function submitWorldSearch({
929
- cfg = {},
930
- accountId = null,
931
- runtimeConfig = null,
932
- worldId = null,
933
- agentId = null,
934
- query = {},
935
- limit = null,
936
- fetchImpl,
937
- logger = console,
938
- } = {}) {
939
- if (typeof fetchImpl !== 'function') {
940
- throw new Error('fetch is unavailable for claworld product-shell world search helper');
941
- }
942
-
943
- const resolvedWorldId = normalizeText(worldId, null);
944
- if (!resolvedWorldId) {
945
- throw new Error('claworld product-shell world search helper requires worldId');
946
- }
947
-
948
- const resolvedAgentId = normalizeText(agentId, null);
949
- if (!resolvedAgentId) {
950
- throw new Error('claworld product-shell world search helper requires agentId');
951
- }
952
-
953
- const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
954
- const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
955
- const normalizedQuery = normalizeProfile(query);
956
- const searchResult = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds/${encodeURIComponent(resolvedWorldId)}/search`, {
957
- method: 'POST',
958
- headers: {
959
- accept: 'application/json',
960
- 'content-type': 'application/json',
961
- ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
962
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
963
- },
964
- body: JSON.stringify({
965
- agentId: resolvedAgentId,
966
- query: normalizedQuery,
967
- ...(limit != null ? { limit } : {}),
968
- }),
969
- });
970
-
971
- if (!searchResult.ok && searchResult.status !== 409) {
972
- logger.error?.('[claworld:product-shell] world search failed', {
973
- status: searchResult.status,
974
- worldId: resolvedWorldId,
975
- agentId: resolvedAgentId,
976
- accountId: resolvedRuntimeConfig.accountId || accountId || null,
977
- body: searchResult.body,
978
- });
979
- throw createProductShellHttpError('world_search', searchResult, {
980
- accountId: resolvedRuntimeConfig.accountId || accountId || null,
981
- worldId: resolvedWorldId,
982
- });
983
- }
984
-
985
- if (searchResult.status === 409) {
986
- return {
987
- status: 'not_joined',
988
- worldId: resolvedWorldId,
989
- agentId: resolvedAgentId,
990
- searchEnabled: false,
991
- results: [],
992
- query: normalizedQuery,
993
- limit: normalizeInteger(limit, 10),
994
- message: 'Join the world successfully before using world search.',
995
- };
996
- }
997
-
998
- const normalizedSearch = normalizeWorldSearchResponse(searchResult.body, {
999
- worldId: resolvedWorldId,
1000
- agentId: resolvedAgentId,
1001
- });
1002
-
1003
- return {
1004
- ...normalizedSearch,
1005
- status: normalizedSearch.items.length > 0 ? 'ready' : 'empty',
1006
- searchEnabled: true,
1007
- results: normalizedSearch.items,
1008
- query: normalizedSearch.searchInput,
1009
- };
1010
- }
1011
-
1012
- export async function broadcastWorld({
1013
- cfg = {},
1014
- accountId = null,
1015
- runtimeConfig = null,
1016
- worldId = null,
1017
- agentId = null,
1018
- message = null,
1019
- payload = {},
1020
- audience = null,
1021
- excludeSelf = null,
1022
- fetchImpl,
1023
- logger = console,
1024
- } = {}) {
1025
- if (typeof fetchImpl !== 'function') {
1026
- throw new Error('fetch is unavailable for claworld product-shell world broadcast helper');
1027
- }
1028
-
1029
- const resolvedWorldId = normalizeText(worldId, null);
1030
- if (!resolvedWorldId) {
1031
- throw new Error('claworld product-shell world broadcast helper requires worldId');
1032
- }
1033
-
1034
- const resolvedAgentId = normalizeText(agentId, null);
1035
- if (!resolvedAgentId) {
1036
- throw new Error('claworld product-shell world broadcast helper requires agentId');
1037
- }
1038
-
1039
- const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
1040
- const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
1041
- const requestBody = {
1042
- agentId: resolvedAgentId,
1043
- payload: normalizeBroadcastRequestPayload(payload, { message }),
1044
- ...(audience ? { audience } : {}),
1045
- ...(excludeSelf == null ? {} : { excludeSelf: excludeSelf === true }),
1046
- };
1047
- const broadcastResult = await fetchJson(
1048
- fetchImpl,
1049
- `${baseUrl}/v1/worlds/${encodeURIComponent(resolvedWorldId)}/broadcast`,
1050
- {
1051
- method: 'POST',
1052
- headers: {
1053
- accept: 'application/json',
1054
- 'content-type': 'application/json',
1055
- ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
1056
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
1057
- },
1058
- body: JSON.stringify(requestBody),
1059
- },
1060
- );
1061
-
1062
- if (!broadcastResult.ok) {
1063
- logger.error?.('[claworld:product-shell] world broadcast failed', {
1064
- status: broadcastResult.status,
1065
- worldId: resolvedWorldId,
1066
- agentId: resolvedAgentId,
1067
- accountId: resolvedRuntimeConfig.accountId || accountId || null,
1068
- body: broadcastResult.body,
1069
- });
1070
- throw createProductShellHttpError('world_broadcast', broadcastResult, {
1071
- accountId: resolvedRuntimeConfig.accountId || accountId || null,
1072
- worldId: resolvedWorldId,
1073
- });
1074
- }
1075
-
1076
- return normalizeBroadcastResult(broadcastResult.body);
1077
- }
1078
-
1079
726
  export async function fetchWorldCandidateFeed({
1080
727
  cfg = {},
1081
728
  accountId = null,
@@ -1112,7 +759,7 @@ export async function fetchWorldCandidateFeed({
1112
759
  headers: {
1113
760
  accept: 'application/json',
1114
761
  ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
1115
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
762
+ ...(resolvedRuntimeConfig.relay?.credentialToken ? { authorization: `Bearer ${resolvedRuntimeConfig.relay.credentialToken}` } : {}),
1116
763
  },
1117
764
  });
1118
765
 
@@ -1158,7 +805,7 @@ export async function resolveWorldSelectionFlow({
1158
805
  headers: {
1159
806
  accept: 'application/json',
1160
807
  ...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
1161
- ...(resolvedRuntimeConfig.relay?.credentialToken ? { 'x-relay-token': resolvedRuntimeConfig.relay.credentialToken } : {}),
808
+ ...(resolvedRuntimeConfig.relay?.credentialToken ? { authorization: `Bearer ${resolvedRuntimeConfig.relay.credentialToken}` } : {}),
1162
809
  },
1163
810
  });
1164
811
 
@@ -34,37 +34,6 @@ function normalizeStringList(values = []) {
34
34
  .filter(Boolean);
35
35
  }
36
36
 
37
- function summarizeProfileSnippet(profileSummary = {}) {
38
- const headline = normalizeText(profileSummary.headline, null);
39
- if (headline) return headline;
40
-
41
- const required = Array.isArray(profileSummary.requiredFields) ? profileSummary.requiredFields : [];
42
- const optional = Array.isArray(profileSummary.optionalFields) ? profileSummary.optionalFields : [];
43
- const allFields = [...required, ...optional]
44
- .map((field) => {
45
- const label = normalizeText(field.label, field.fieldId || 'Field');
46
- const value = Array.isArray(field.value) ? field.value.join(', ') : normalizeText(field.value, null);
47
- if (!value) return null;
48
- return `${label}: ${value}`;
49
- })
50
- .filter(Boolean);
51
-
52
- return allFields[0] || null;
53
- }
54
-
55
- function projectSearchMatchReasons(item = {}) {
56
- if (Array.isArray(item.matchedFields) && item.matchedFields.length > 0) {
57
- return item.matchedFields.map((field) => {
58
- if (field.matchType === 'overlap' && Array.isArray(field.sharedValues) && field.sharedValues.length > 0) {
59
- return `${field.label}: ${field.sharedValues.join(', ')}`;
60
- }
61
- return `${field.label} matches`;
62
- });
63
- }
64
-
65
- return [normalizeText(item.reasonSummary, 'Recently active online world member.')];
66
- }
67
-
68
37
  function projectParticipantContextField(field = null) {
69
38
  if (!field || typeof field !== 'object' || Array.isArray(field)) return null;
70
39
  return {
@@ -347,52 +316,6 @@ export function projectToolJoinWorldResponse(
347
316
  };
348
317
  }
349
318
 
350
- export function projectToolSearchWorldResponse(searchResult = {}, { accountId = null } = {}) {
351
- const compatibilityMessage = 'Compatibility-only manual world search. Candidate feed review is the canonical path before request_chat.';
352
- if (searchResult.status === 'not_joined') {
353
- return {
354
- status: 'not_joined',
355
- worldId: searchResult.worldId,
356
- accountId: normalizeText(accountId, null),
357
- discoveryMode: 'compatibility_search',
358
- canonicalDiscoveryMode: 'candidate_feed',
359
- query: searchResult.query || {},
360
- limit: normalizeInteger(searchResult.limit, 10),
361
- results: [],
362
- message: normalizeText(
363
- searchResult.message,
364
- 'Join the world first. Candidate feed review is the canonical path before request_chat; search remains compatibility-only.',
365
- ),
366
- };
367
- }
368
-
369
- const results = Array.isArray(searchResult.results)
370
- ? searchResult.results.map((item) => ({
371
- agentId: normalizeText(item.agentId, normalizeText(item.playerId, null)),
372
- playerId: normalizeText(item.playerId, normalizeText(item.agentId, null)),
373
- displayName: item.displayName,
374
- headline: item.headline || null,
375
- score: normalizeInteger(item.score, 0),
376
- matchReasons: projectSearchMatchReasons(item),
377
- profileSnippet: summarizeProfileSnippet(item.profileSummary),
378
- online: item.online === true,
379
- worldFeedbackSummary: projectWorldFeedbackSummary(item.worldFeedbackSummary),
380
- }))
381
- : [];
382
-
383
- return {
384
- status: results.length > 0 ? 'ready' : 'empty',
385
- worldId: searchResult.worldId,
386
- accountId: normalizeText(accountId, null),
387
- discoveryMode: 'compatibility_search',
388
- canonicalDiscoveryMode: 'candidate_feed',
389
- query: searchResult.query || {},
390
- limit: normalizeInteger(searchResult.limit, results.length || 10),
391
- message: compatibilityMessage,
392
- results,
393
- };
394
- }
395
-
396
319
  export function projectToolCreateWorldResponse(world = {}, { accountId = null } = {}) {
397
320
  return {
398
321
  worldId: world.worldId,
@@ -448,47 +371,6 @@ export function projectToolManagedWorldResponse(world = {}, { accountId = null }
448
371
  };
449
372
  }
450
373
 
451
- export function projectToolBroadcastWorldResponse(result = {}, { accountId = null } = {}) {
452
- const requests = Array.isArray(result.requests)
453
- ? result.requests.map((request) => ({
454
- agentId: normalizeText(
455
- request.agentId,
456
- request.chatRequest?.toAgent?.agentId || request.chatRequest?.counterparty?.agentId || null,
457
- ),
458
- status: normalizeText(request.status, 'created'),
459
- chatRequest: projectChatRequestItem(request.chatRequest),
460
- }))
461
- : [];
462
- const failures = Array.isArray(result.failures)
463
- ? result.failures.map((failure) => ({
464
- agentId: normalizeText(failure.agentId, null),
465
- status: normalizeText(failure.status, 'failed'),
466
- httpStatus: normalizeInteger(failure.httpStatus, 0),
467
- error: normalizeText(failure.error, null),
468
- reason: normalizeText(failure.reason, null),
469
- message: normalizeText(failure.message, null),
470
- }))
471
- : [];
472
-
473
- return {
474
- status: normalizeText(result.status, null),
475
- accountId: normalizeText(accountId, null),
476
- worldId: normalizeText(result.worldId, null),
477
- senderAgentId: normalizeText(result.senderAgentId, null),
478
- senderRole: normalizeText(result.senderRole, null),
479
- audience: normalizeText(result.audience, null),
480
- excludeSelf: normalizeOptionalBoolean(result.excludeSelf, null),
481
- eligibility: normalizeText(result.eligibility, null),
482
- broadcastId: normalizeText(result.broadcastId, null),
483
- totalTargets: normalizeInteger(result.totalTargets, requests.length + failures.length),
484
- createdCount: normalizeInteger(result.createdCount, requests.length),
485
- failedCount: normalizeInteger(result.failedCount, failures.length),
486
- nextAction: normalizeText(result.nextAction, null),
487
- requests,
488
- failures,
489
- };
490
- }
491
-
492
374
  export function projectToolFeedbackSubmissionResponse(result = {}) {
493
375
  const feedback = result.feedback && typeof result.feedback === 'object' ? result.feedback : {};
494
376
  const reporter = feedback.reporter && typeof feedback.reporter === 'object' ? feedback.reporter : {};
@@ -534,18 +416,6 @@ function projectToolAgentSummary(agent = {}) {
534
416
  };
535
417
  }
536
418
 
537
- function projectFriendshipSummary(friendship = {}) {
538
- if (!friendship || typeof friendship !== 'object') return null;
539
- return {
540
- friendshipId: normalizeText(friendship.friendshipId, null),
541
- status: normalizeText(friendship.status, null),
542
- peerAgentId: normalizeText(friendship.peerAgentId, null),
543
- peerAgent: projectToolAgentSummary(friendship.peerAgent),
544
- acceptedAt: normalizeText(friendship.acceptedAt, null),
545
- updatedAt: normalizeText(friendship.updatedAt, null),
546
- };
547
- }
548
-
549
419
  function projectToolWorldSummary(world = {}) {
550
420
  if (!world || typeof world !== 'object') return null;
551
421
  return {
@@ -566,20 +436,6 @@ function normalizeConversationScopeDetails(input = {}) {
566
436
  };
567
437
  }
568
438
 
569
- function projectFriendRequestItem(request = {}) {
570
- if (!request || typeof request !== 'object') return null;
571
- return {
572
- friendRequestId: normalizeText(request.friendRequestId, null),
573
- status: normalizeText(request.status, 'pending'),
574
- direction: normalizeText(request.direction, null),
575
- message: normalizeText(request.message, null),
576
- createdAt: normalizeText(request.createdAt, null),
577
- respondedAt: normalizeText(request.respondedAt, null),
578
- fromAgent: projectToolAgentSummary(request.fromAgent),
579
- toAgent: projectToolAgentSummary(request.toAgent),
580
- };
581
- }
582
-
583
439
  function projectChatRequestKickoff(kickoff = {}) {
584
440
  if (!kickoff || typeof kickoff !== 'object') return null;
585
441
  return {
@@ -661,34 +517,6 @@ function projectChatInboxChatItem(chat = {}) {
661
517
  };
662
518
  }
663
519
 
664
- export function projectToolFriendRequestMutationResponse(result = {}, { accountId = null } = {}) {
665
- return {
666
- status: result.alreadyFriends === true
667
- ? 'already_friends'
668
- : normalizeText(result.request?.status, 'pending'),
669
- accountId: normalizeText(accountId, null),
670
- created: result.created === true,
671
- alreadyFriends: result.alreadyFriends === true,
672
- request: projectFriendRequestItem(result.request),
673
- friendship: projectFriendshipSummary(result.friendship),
674
- nextAction: result.alreadyFriends === true
675
- ? 'friendship_active'
676
- : normalizeText(result.request?.status, 'pending') === 'pending'
677
- ? 'wait_for_peer_friend_request_decision'
678
- : 'friendship_active',
679
- };
680
- }
681
-
682
- export function projectToolFriendRequestListResponse(result = {}, { accountId = null } = {}) {
683
- const items = Array.isArray(result.items)
684
- ? result.items.map((request) => projectFriendRequestItem(request)).filter(Boolean)
685
- : [];
686
- return {
687
- accountId: normalizeText(accountId, null),
688
- items,
689
- };
690
- }
691
-
692
520
  export function projectToolChatRequestMutationResponse(result = {}, { accountId = null } = {}) {
693
521
  const request = result.chatRequest && typeof result.chatRequest === 'object'
694
522
  ? result.chatRequest
@@ -720,16 +548,6 @@ export function projectToolChatRequestMutationResponse(result = {}, { accountId
720
548
  };
721
549
  }
722
550
 
723
- export function projectToolChatRequestListResponse(result = {}, { accountId = null } = {}) {
724
- const items = Array.isArray(result.items)
725
- ? result.items.map((request) => projectChatRequestItem(request)).filter(Boolean)
726
- : [];
727
- return {
728
- accountId: normalizeText(accountId, null),
729
- items,
730
- };
731
- }
732
-
733
551
  export function projectToolChatInboxResponse(result = {}, { accountId = null } = {}) {
734
552
  const pendingRequests = Array.isArray(result.pendingRequests)
735
553
  ? result.pendingRequests.map((request) => projectChatRequestItem(request)).filter(Boolean)