@xfxstudio/claworld 0.2.24 → 2026.4.14-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.
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/skills/claworld-a2a-channel-agent/SKILL.md +218 -0
- package/skills/claworld-help/SKILL.md +77 -3
- package/skills/claworld-join-and-chat/SKILL.md +186 -43
- package/skills/claworld-manage-worlds/SKILL.md +57 -5
- package/src/lib/relay/agent-readable-markdown.js +385 -0
- package/src/lib/relay/kickoff-text.js +6 -217
- package/src/openclaw/index.js +6 -0
- package/src/openclaw/plugin/account-identity.js +11 -2
- package/src/openclaw/plugin/claworld-channel-plugin.js +221 -6
- package/src/openclaw/plugin/managed-config.js +19 -0
- package/src/openclaw/plugin/register-tooling.js +60 -1
- package/src/openclaw/plugin/register.js +442 -44
- package/src/openclaw/plugin/relay-client.js +2 -1
- package/src/openclaw/plugin-version.js +67 -0
- package/src/openclaw/runtime/product-shell-helper.js +220 -15
- package/src/openclaw/runtime/tool-contracts.js +327 -23
- package/src/openclaw/runtime/tool-inventory.js +3 -0
- package/src/openclaw/runtime/world-membership-helper.js +320 -0
- package/src/openclaw/runtime/world-moderation-helper.js +158 -1
- package/src/product-shell/contracts/world-orchestration.js +9 -0
|
@@ -2,6 +2,7 @@ import { EventEmitter } from 'events';
|
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
3
|
import { resolveClaworldRuntimeConfig } from './config-schema.js';
|
|
4
4
|
import { buildRuntimeAuthHeaders } from './account-identity.js';
|
|
5
|
+
import { buildClaworldRelayClientVersion } from '../plugin-version.js';
|
|
5
6
|
import { createRelayEventProtocol } from '../protocol/relay-event-protocol.js';
|
|
6
7
|
import { createInboundSessionRouter } from '../runtime/inbound-session-router.js';
|
|
7
8
|
import { createOutboundSessionBridge } from '../runtime/outbound-session-bridge.js';
|
|
@@ -486,7 +487,7 @@ export class ClaworldRelayClient extends EventEmitter {
|
|
|
486
487
|
config,
|
|
487
488
|
agentId,
|
|
488
489
|
credential = null,
|
|
489
|
-
clientVersion =
|
|
490
|
+
clientVersion = buildClaworldRelayClientVersion(),
|
|
490
491
|
sessionTarget,
|
|
491
492
|
fallbackTarget,
|
|
492
493
|
} = {}) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import repoPackageJson from '../../package.json' with { type: 'json' };
|
|
3
|
+
|
|
4
|
+
export const CLAWORLD_PLUGIN_PACKAGE_NAME = '@xfxstudio/claworld';
|
|
5
|
+
export const CLAWORLD_PLUGIN_VERSION_HEADER = 'x-claworld-plugin-version';
|
|
6
|
+
|
|
7
|
+
function normalizeText(value, fallback = null) {
|
|
8
|
+
if (value == null) return fallback;
|
|
9
|
+
const normalized = String(value).trim();
|
|
10
|
+
return normalized || fallback;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function normalizeHeaderValue(value) {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return normalizeHeaderValue(value[0]);
|
|
16
|
+
}
|
|
17
|
+
const normalized = normalizeText(value, null);
|
|
18
|
+
if (!normalized) return null;
|
|
19
|
+
return normalized.split(',')[0]?.trim() || null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function normalizeClaworldPluginVersion(value, fallback = null) {
|
|
23
|
+
const normalized = normalizeText(value, null);
|
|
24
|
+
if (!normalized) return fallback;
|
|
25
|
+
const withoutPrefix = normalized.replace(/^v/i, '');
|
|
26
|
+
if (!/^\d+(?:\.\d+)*(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(withoutPrefix)) {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
return withoutPrefix;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveCurrentPluginVersion() {
|
|
33
|
+
const repoVersion = normalizeClaworldPluginVersion(repoPackageJson?.version, null);
|
|
34
|
+
if (repoPackageJson?.name === CLAWORLD_PLUGIN_PACKAGE_NAME && repoVersion) {
|
|
35
|
+
return repoVersion;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const publishSurfaceSource = readFileSync(
|
|
40
|
+
new URL('../../packages/openclaw-plugin/package.json', import.meta.url),
|
|
41
|
+
'utf8',
|
|
42
|
+
);
|
|
43
|
+
const publishSurfacePackageJson = JSON.parse(publishSurfaceSource);
|
|
44
|
+
const publishSurfaceVersion = normalizeClaworldPluginVersion(publishSurfacePackageJson?.version, null);
|
|
45
|
+
if (publishSurfacePackageJson?.name === CLAWORLD_PLUGIN_PACKAGE_NAME && publishSurfaceVersion) {
|
|
46
|
+
return publishSurfaceVersion;
|
|
47
|
+
}
|
|
48
|
+
} catch {}
|
|
49
|
+
|
|
50
|
+
return repoVersion || '0.0.0';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const CLAWORLD_PLUGIN_CURRENT_VERSION = resolveCurrentPluginVersion();
|
|
54
|
+
|
|
55
|
+
export function readClaworldPluginVersionFromHeaders(headers = {}) {
|
|
56
|
+
const rawVersion = normalizeHeaderValue(headers?.[CLAWORLD_PLUGIN_VERSION_HEADER]);
|
|
57
|
+
return {
|
|
58
|
+
rawVersion,
|
|
59
|
+
reportedVersion: normalizeClaworldPluginVersion(rawVersion, rawVersion),
|
|
60
|
+
normalizedVersion: normalizeClaworldPluginVersion(rawVersion, null),
|
|
61
|
+
source: rawVersion ? CLAWORLD_PLUGIN_VERSION_HEADER : null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function buildClaworldRelayClientVersion(version = CLAWORLD_PLUGIN_CURRENT_VERSION) {
|
|
66
|
+
return `claworld-plugin/${normalizeClaworldPluginVersion(version, CLAWORLD_PLUGIN_CURRENT_VERSION)}`;
|
|
67
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveClaworldRuntimeConfig } from '../plugin/config-schema.js';
|
|
2
|
+
import { buildRuntimeAuthHeaders } from '../plugin/account-identity.js';
|
|
2
3
|
import { createRuntimeBoundaryError } from '../../lib/runtime-errors.js';
|
|
3
4
|
import { extractBackendErrorContext } from './backend-error-context.js';
|
|
4
5
|
import {
|
|
@@ -23,6 +24,11 @@ function normalizeStringList(values = []) {
|
|
|
23
24
|
return [...new Set(values.map((value) => normalizeText(value, null)).filter(Boolean))];
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
function normalizeWorldRole(worldRole, fallback = null) {
|
|
28
|
+
const normalized = normalizeText(worldRole, fallback);
|
|
29
|
+
return ['owner', 'member'].includes(normalized) ? normalized : fallback;
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
function sentenceCase(value, fallback = '') {
|
|
27
33
|
const normalized = normalizeText(value, fallback);
|
|
28
34
|
if (!normalized) return fallback;
|
|
@@ -48,9 +54,18 @@ function normalizeWorldSummary(world = {}) {
|
|
|
48
54
|
return {
|
|
49
55
|
worldId: normalizeText(rawWorldId, 'unknown-world'),
|
|
50
56
|
displayName: normalizeText(summary.displayName || world.displayName, normalizeText(rawWorldId, 'Unknown World')),
|
|
57
|
+
summary: normalizeText(summary.summary || world.summary, null),
|
|
51
58
|
worldContextText: normalizeText(summary.worldContextText || world.worldContextText, ''),
|
|
52
59
|
hotness: normalizeInteger(summary.hotness || world.hotness || world.activatedMemberCount, 0),
|
|
60
|
+
activatedMemberCount: normalizeInteger(summary.activatedMemberCount || world.activatedMemberCount || summary.hotness || world.hotness, 0),
|
|
61
|
+
tags: normalizeStringList(summary.tags || world.tags),
|
|
62
|
+
matchScore: normalizeInteger(summary.matchScore || world.matchScore, 0),
|
|
63
|
+
matchedFieldIds: normalizeStringList(summary.matchedFieldIds || world.matchedFieldIds),
|
|
64
|
+
matchedTerms: normalizeStringList(summary.matchedTerms || world.matchedTerms),
|
|
65
|
+
reasonSummary: normalizeText(summary.reasonSummary || world.reasonSummary, null),
|
|
53
66
|
requiredFieldCount: normalizeInteger(summary.requiredFieldCount || world.requiredFieldCount, 0),
|
|
67
|
+
detailAction: world.detailAction && typeof world.detailAction === 'object' ? world.detailAction : null,
|
|
68
|
+
joinAction: world.joinAction && typeof world.joinAction === 'object' ? world.joinAction : null,
|
|
54
69
|
};
|
|
55
70
|
}
|
|
56
71
|
|
|
@@ -129,6 +144,7 @@ function normalizeWorldDetail(payload = {}) {
|
|
|
129
144
|
displayName: normalizeText(payload.displayName, normalizedWorldId),
|
|
130
145
|
worldContextText: normalizeText(payload.worldContextText, ''),
|
|
131
146
|
ownerAgentId: normalizeText(payload.ownerAgentId, null),
|
|
147
|
+
worldRole: normalizeWorldRole(payload.worldRole, null),
|
|
132
148
|
enabled: typeof payload.enabled === 'boolean' ? payload.enabled : null,
|
|
133
149
|
requiredFieldCount: normalizeInteger(payload.requiredFieldCount, requiredFields.length) || requiredFields.length,
|
|
134
150
|
optionalFieldCount: normalizeInteger(payload.optionalFieldCount, optionalFields.length) || optionalFields.length,
|
|
@@ -168,6 +184,7 @@ function normalizeWorldDetail(payload = {}) {
|
|
|
168
184
|
displayName,
|
|
169
185
|
worldContextText: normalizeText(world.worldContextText || payload.worldContextText, ''),
|
|
170
186
|
ownerAgentId: normalizeText(management.ownerAgentId, null),
|
|
187
|
+
worldRole: normalizeWorldRole(payload.worldRole, null),
|
|
171
188
|
enabled: typeof management.enabled === 'boolean' ? management.enabled : null,
|
|
172
189
|
statusLabel: normalizeText(management.status, null),
|
|
173
190
|
requiredFieldCount: 1,
|
|
@@ -220,6 +237,22 @@ function normalizeCandidateProfileSummary(summary = {}) {
|
|
|
220
237
|
};
|
|
221
238
|
}
|
|
222
239
|
|
|
240
|
+
function normalizeSearchAction(action = null) {
|
|
241
|
+
if (!action || typeof action !== 'object' || Array.isArray(action)) return null;
|
|
242
|
+
const payload = action.payload && typeof action.payload === 'object' && !Array.isArray(action.payload)
|
|
243
|
+
? action.payload
|
|
244
|
+
: {};
|
|
245
|
+
const payloadTemplate = action.payloadTemplate && typeof action.payloadTemplate === 'object' && !Array.isArray(action.payloadTemplate)
|
|
246
|
+
? action.payloadTemplate
|
|
247
|
+
: {};
|
|
248
|
+
return {
|
|
249
|
+
tool: normalizeText(action.tool, null),
|
|
250
|
+
summary: normalizeText(action.summary, null),
|
|
251
|
+
payload,
|
|
252
|
+
payloadTemplate,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
223
256
|
function normalizeCompatibilitySignal(signal = {}, index = 0) {
|
|
224
257
|
return {
|
|
225
258
|
signalId: normalizeText(signal.signalId, `signal_${index + 1}`),
|
|
@@ -259,6 +292,7 @@ function normalizeCandidate(candidate = {}, index = 0) {
|
|
|
259
292
|
return {
|
|
260
293
|
candidateId: normalizeText(candidate.candidateId, `candidate_${index + 1}`),
|
|
261
294
|
worldId: normalizeText(candidate.worldId, 'unknown-world'),
|
|
295
|
+
worldRole: normalizeWorldRole(candidate.worldRole, null),
|
|
262
296
|
sourceMembershipId: normalizeText(candidate.sourceMembershipId, null),
|
|
263
297
|
online: candidate.online === true,
|
|
264
298
|
displayName,
|
|
@@ -314,7 +348,7 @@ function normalizeCandidateFeedResponse(payload = {}, { worldId = null, agentId
|
|
|
314
348
|
};
|
|
315
349
|
}
|
|
316
350
|
|
|
317
|
-
function normalizeWorldJoinResponse(payload = {}, { worldId = null, agentId = null } = {}) {
|
|
351
|
+
export function normalizeWorldJoinResponse(payload = {}, { worldId = null, agentId = null } = {}) {
|
|
318
352
|
const membership = payload.membership && typeof payload.membership === 'object' ? payload.membership : null;
|
|
319
353
|
const normalizedWorldId = normalizeText(payload.worldId, worldId || 'unknown-world');
|
|
320
354
|
const normalizedAgentId = normalizeText(payload.agentId || membership?.agentId, agentId || null);
|
|
@@ -330,6 +364,7 @@ function normalizeWorldJoinResponse(payload = {}, { worldId = null, agentId = nu
|
|
|
330
364
|
status: normalizeText(payload.status, membershipStatus === 'active' ? 'joined' : 'accepted'),
|
|
331
365
|
worldId: normalizedWorldId,
|
|
332
366
|
agentId: normalizedAgentId,
|
|
367
|
+
worldRole: normalizeWorldRole(payload.worldRole, null),
|
|
333
368
|
membershipStatus,
|
|
334
369
|
participantContextText: normalizeText(
|
|
335
370
|
payload.participantContextText,
|
|
@@ -388,7 +423,10 @@ export function buildWorldSelectionPrompt(worldDirectory = {}) {
|
|
|
388
423
|
: null;
|
|
389
424
|
}
|
|
390
425
|
|
|
391
|
-
export function buildPostSetupWorldDirectory(payload = {}, {
|
|
426
|
+
export function buildPostSetupWorldDirectory(payload = {}, {
|
|
427
|
+
accountId = null,
|
|
428
|
+
statusMode = 'directory',
|
|
429
|
+
} = {}) {
|
|
392
430
|
const items = Array.isArray(payload.items) ? payload.items.map((world) => normalizeWorldSummary(world)) : [];
|
|
393
431
|
const recommendedWorldId = items[0]?.worldId || null;
|
|
394
432
|
const pagination = payload.pagination && typeof payload.pagination === 'object'
|
|
@@ -402,23 +440,83 @@ export function buildPostSetupWorldDirectory(payload = {}, { accountId = null }
|
|
|
402
440
|
totalPages: items.length > 0 ? 1 : 0,
|
|
403
441
|
totalCount: items.length,
|
|
404
442
|
};
|
|
443
|
+
const mode = normalizeText(payload.mode, 'browse');
|
|
405
444
|
const sort = normalizeText(payload.sort, 'hot');
|
|
445
|
+
const statusFallback = items.length > 0
|
|
446
|
+
? (statusMode === 'search' ? 'search_ready' : 'ready')
|
|
447
|
+
: 'no_matches';
|
|
448
|
+
const normalizedStatus = normalizeText(
|
|
449
|
+
statusMode === 'directory' && mode === 'browse' && payload.status === 'search_ready'
|
|
450
|
+
? 'ready'
|
|
451
|
+
: payload.status,
|
|
452
|
+
statusFallback,
|
|
453
|
+
);
|
|
406
454
|
|
|
407
455
|
return {
|
|
408
|
-
status:
|
|
456
|
+
status: normalizedStatus,
|
|
409
457
|
source: 'product_shell',
|
|
410
458
|
accountId: normalizeText(accountId, null),
|
|
459
|
+
mode,
|
|
460
|
+
query: normalizeText(payload.query, null),
|
|
411
461
|
worldCount: pagination.totalCount,
|
|
412
462
|
recommendedWorldId,
|
|
413
463
|
items,
|
|
414
464
|
pagination,
|
|
415
465
|
sort,
|
|
466
|
+
nextAction: normalizeText(payload.nextAction, items.length > 0 ? 'inspect_world_detail_or_join_world' : 'broaden_world_search'),
|
|
416
467
|
orchestration: payload.orchestration && typeof payload.orchestration === 'object'
|
|
417
468
|
? payload.orchestration
|
|
418
469
|
: null,
|
|
419
470
|
};
|
|
420
471
|
}
|
|
421
472
|
|
|
473
|
+
function normalizeWorldMemberSearchItem(item = {}) {
|
|
474
|
+
return {
|
|
475
|
+
membershipId: normalizeText(item.membershipId, null),
|
|
476
|
+
worldId: normalizeText(item.worldId, null),
|
|
477
|
+
displayName: normalizeText(item.displayName, null),
|
|
478
|
+
agentCode: normalizeText(item.agentCode, null)?.toUpperCase() || null,
|
|
479
|
+
requestChat: item.requestChat && typeof item.requestChat === 'object' && !Array.isArray(item.requestChat)
|
|
480
|
+
? item.requestChat
|
|
481
|
+
: null,
|
|
482
|
+
headline: normalizeText(item.headline, null),
|
|
483
|
+
online: item.online === true,
|
|
484
|
+
score: normalizeInteger(item.score, 0),
|
|
485
|
+
matchedFieldIds: normalizeStringList(item.matchedFieldIds),
|
|
486
|
+
reasonSummary: normalizeText(item.reasonSummary, null),
|
|
487
|
+
joinedAt: normalizeText(item.joinedAt, null),
|
|
488
|
+
profileSummary: normalizeCandidateProfileSummary(item.profileSummary || {}),
|
|
489
|
+
worldFeedbackSummary: item.worldFeedbackSummary && typeof item.worldFeedbackSummary === 'object' && !Array.isArray(item.worldFeedbackSummary)
|
|
490
|
+
? {
|
|
491
|
+
likesReceived: normalizeInteger(item.worldFeedbackSummary.likesReceived, 0),
|
|
492
|
+
dislikesReceived: normalizeInteger(item.worldFeedbackSummary.dislikesReceived, 0),
|
|
493
|
+
}
|
|
494
|
+
: {
|
|
495
|
+
likesReceived: 0,
|
|
496
|
+
dislikesReceived: 0,
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function normalizeWorldMemberSearchResponse(payload = {}, { accountId = null } = {}) {
|
|
502
|
+
const items = Array.isArray(payload.items)
|
|
503
|
+
? payload.items.map((item) => normalizeWorldMemberSearchItem(item))
|
|
504
|
+
: [];
|
|
505
|
+
|
|
506
|
+
return {
|
|
507
|
+
status: normalizeText(payload.status, items.length > 0 ? 'search_ready' : 'no_matches'),
|
|
508
|
+
source: 'product_shell',
|
|
509
|
+
accountId: normalizeText(accountId, null),
|
|
510
|
+
worldId: normalizeText(payload.worldId, null),
|
|
511
|
+
query: normalizeText(payload.query, null),
|
|
512
|
+
sort: normalizeText(payload.sort, 'match'),
|
|
513
|
+
limit: normalizeInteger(payload.limit, items.length),
|
|
514
|
+
totalMatches: normalizeInteger(payload.totalMatches, items.length),
|
|
515
|
+
nextAction: normalizeText(payload.nextAction, items.length > 0 ? 'request_chat_with_selected_candidate' : 'broaden_search_or_refresh_candidate_feed'),
|
|
516
|
+
items,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
422
520
|
export function resolveWorldSelection(worldDirectory = {}, selection = null) {
|
|
423
521
|
return resolveBackendWorldSelection(worldDirectory, selection);
|
|
424
522
|
}
|
|
@@ -512,11 +610,10 @@ export async function fetchWorldDetail({
|
|
|
512
610
|
const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
|
|
513
611
|
const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
|
|
514
612
|
const detail = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds/${encodeURIComponent(resolvedWorldId)}`, {
|
|
515
|
-
headers: {
|
|
613
|
+
headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
|
|
516
614
|
accept: 'application/json',
|
|
517
615
|
...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
|
|
518
|
-
|
|
519
|
-
},
|
|
616
|
+
}),
|
|
520
617
|
});
|
|
521
618
|
|
|
522
619
|
if (!detail.ok) {
|
|
@@ -535,6 +632,55 @@ export async function fetchWorldDetail({
|
|
|
535
632
|
return normalizeWorldDetail(detail.body);
|
|
536
633
|
}
|
|
537
634
|
|
|
635
|
+
export async function searchWorlds({
|
|
636
|
+
cfg = {},
|
|
637
|
+
accountId = null,
|
|
638
|
+
runtimeConfig = null,
|
|
639
|
+
query = null,
|
|
640
|
+
limit = null,
|
|
641
|
+
sort = null,
|
|
642
|
+
page = null,
|
|
643
|
+
fetchImpl,
|
|
644
|
+
logger = console,
|
|
645
|
+
} = {}) {
|
|
646
|
+
if (typeof fetchImpl !== 'function') {
|
|
647
|
+
throw new Error('fetch is unavailable for claworld product-shell world search helper');
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
|
|
651
|
+
const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
|
|
652
|
+
const searchResult = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds/search`, {
|
|
653
|
+
method: 'POST',
|
|
654
|
+
headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
|
|
655
|
+
accept: 'application/json',
|
|
656
|
+
'content-type': 'application/json',
|
|
657
|
+
...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
|
|
658
|
+
}),
|
|
659
|
+
body: JSON.stringify({
|
|
660
|
+
query: normalizeText(query, null),
|
|
661
|
+
sort: normalizeText(sort, null),
|
|
662
|
+
limit: limit == null ? null : normalizeInteger(limit, 0),
|
|
663
|
+
page: page == null ? null : normalizeInteger(page, 0),
|
|
664
|
+
}),
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
if (!searchResult.ok) {
|
|
668
|
+
logger.error?.('[claworld:product-shell] world search failed', {
|
|
669
|
+
status: searchResult.status,
|
|
670
|
+
accountId: resolvedRuntimeConfig.accountId || accountId || null,
|
|
671
|
+
body: searchResult.body,
|
|
672
|
+
});
|
|
673
|
+
throw createProductShellHttpError('world_search', searchResult, {
|
|
674
|
+
accountId: resolvedRuntimeConfig.accountId || accountId || null,
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
return buildPostSetupWorldDirectory(searchResult.body, {
|
|
679
|
+
accountId: resolvedRuntimeConfig.accountId || accountId || null,
|
|
680
|
+
statusMode: 'search',
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
538
684
|
export async function joinWorld({
|
|
539
685
|
cfg = {},
|
|
540
686
|
accountId = null,
|
|
@@ -563,12 +709,11 @@ export async function joinWorld({
|
|
|
563
709
|
const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
|
|
564
710
|
const joinResult = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds/${encodeURIComponent(resolvedWorldId)}/join`, {
|
|
565
711
|
method: 'POST',
|
|
566
|
-
headers: {
|
|
712
|
+
headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
|
|
567
713
|
accept: 'application/json',
|
|
568
714
|
'content-type': 'application/json',
|
|
569
715
|
...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
|
|
570
|
-
|
|
571
|
-
},
|
|
716
|
+
}),
|
|
572
717
|
body: JSON.stringify({
|
|
573
718
|
agentId: resolvedAgentId,
|
|
574
719
|
participantContextText: normalizeText(participantContextText, null),
|
|
@@ -595,6 +740,68 @@ export async function joinWorld({
|
|
|
595
740
|
});
|
|
596
741
|
}
|
|
597
742
|
|
|
743
|
+
export async function searchWorldMembers({
|
|
744
|
+
cfg = {},
|
|
745
|
+
accountId = null,
|
|
746
|
+
runtimeConfig = null,
|
|
747
|
+
worldId = null,
|
|
748
|
+
agentId = null,
|
|
749
|
+
query = null,
|
|
750
|
+
sort = null,
|
|
751
|
+
limit = null,
|
|
752
|
+
fetchImpl,
|
|
753
|
+
logger = console,
|
|
754
|
+
} = {}) {
|
|
755
|
+
if (typeof fetchImpl !== 'function') {
|
|
756
|
+
throw new Error('fetch is unavailable for claworld product-shell member search helper');
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const resolvedWorldId = normalizeText(worldId, null);
|
|
760
|
+
if (!resolvedWorldId) {
|
|
761
|
+
throw new Error('claworld product-shell member search helper requires worldId');
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
const resolvedAgentId = normalizeText(agentId, null);
|
|
765
|
+
if (!resolvedAgentId) {
|
|
766
|
+
throw new Error('claworld product-shell member search helper requires agentId');
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
|
|
770
|
+
const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
|
|
771
|
+
const searchResult = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds/${encodeURIComponent(resolvedWorldId)}/search`, {
|
|
772
|
+
method: 'POST',
|
|
773
|
+
headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
|
|
774
|
+
accept: 'application/json',
|
|
775
|
+
'content-type': 'application/json',
|
|
776
|
+
...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
|
|
777
|
+
}),
|
|
778
|
+
body: JSON.stringify({
|
|
779
|
+
agentId: resolvedAgentId,
|
|
780
|
+
query: normalizeText(query, null),
|
|
781
|
+
sort: normalizeText(sort, null),
|
|
782
|
+
limit: limit == null ? null : normalizeInteger(limit, 0),
|
|
783
|
+
}),
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
if (!searchResult.ok) {
|
|
787
|
+
logger.error?.('[claworld:product-shell] world member search failed', {
|
|
788
|
+
status: searchResult.status,
|
|
789
|
+
worldId: resolvedWorldId,
|
|
790
|
+
agentId: resolvedAgentId,
|
|
791
|
+
accountId: resolvedRuntimeConfig.accountId || accountId || null,
|
|
792
|
+
body: searchResult.body,
|
|
793
|
+
});
|
|
794
|
+
throw createProductShellHttpError('world_member_search', searchResult, {
|
|
795
|
+
accountId: resolvedRuntimeConfig.accountId || accountId || null,
|
|
796
|
+
worldId: resolvedWorldId,
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return normalizeWorldMemberSearchResponse(searchResult.body, {
|
|
801
|
+
accountId: resolvedRuntimeConfig.accountId || accountId || null,
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
|
|
598
805
|
export async function fetchWorldCandidateFeed({
|
|
599
806
|
cfg = {},
|
|
600
807
|
accountId = null,
|
|
@@ -628,11 +835,10 @@ export async function fetchWorldCandidateFeed({
|
|
|
628
835
|
requestUrl.searchParams.set('limit', String(normalizedLimit));
|
|
629
836
|
}
|
|
630
837
|
const candidateFeed = await fetchJson(fetchImpl, requestUrl.toString(), {
|
|
631
|
-
headers: {
|
|
838
|
+
headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
|
|
632
839
|
accept: 'application/json',
|
|
633
840
|
...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
|
|
634
|
-
|
|
635
|
-
},
|
|
841
|
+
}),
|
|
636
842
|
});
|
|
637
843
|
|
|
638
844
|
if (!candidateFeed.ok) {
|
|
@@ -674,11 +880,10 @@ export async function resolveWorldSelectionFlow({
|
|
|
674
880
|
const resolvedRuntimeConfig = runtimeConfig || resolveClaworldRuntimeConfig(cfg, accountId);
|
|
675
881
|
const baseUrl = normalizeRelayHttpBaseUrl(resolvedRuntimeConfig.serverUrl);
|
|
676
882
|
const worlds = await fetchJson(fetchImpl, `${baseUrl}/v1/worlds`, {
|
|
677
|
-
headers: {
|
|
883
|
+
headers: buildRuntimeAuthHeaders(resolvedRuntimeConfig, {
|
|
678
884
|
accept: 'application/json',
|
|
679
885
|
...(resolvedRuntimeConfig.apiKey ? { 'x-api-key': resolvedRuntimeConfig.apiKey } : {}),
|
|
680
|
-
|
|
681
|
-
},
|
|
886
|
+
}),
|
|
682
887
|
});
|
|
683
888
|
|
|
684
889
|
if (!worlds.ok) {
|