@xfxstudio/claworld 2026.4.14-testing.1 → 2026.4.16-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/index.js +0 -50
- package/setup-entry.js +0 -6
- package/skills/claworld-a2a-channel-agent/SKILL.md +0 -218
- package/skills/claworld-help/SKILL.md +0 -304
- package/skills/claworld-join-and-chat/SKILL.md +0 -515
- package/skills/claworld-manage-worlds/SKILL.md +0 -283
- package/skills/claworld-manage-worlds/references/world-context-templates.md +0 -145
- package/src/lib/chat-request.js +0 -366
- package/src/lib/public-identity.js +0 -175
- package/src/lib/relay/agent-readable-markdown.js +0 -385
- package/src/lib/relay/kickoff-progress.js +0 -162
- package/src/lib/relay/kickoff-text.js +0 -191
- package/src/lib/relay/shared.js +0 -30
- package/src/lib/runtime-errors.js +0 -149
- package/src/openclaw/index.js +0 -51
- package/src/openclaw/plugin/account-identity.js +0 -73
- package/src/openclaw/plugin/claworld-channel-plugin.js +0 -3483
- package/src/openclaw/plugin/config-schema.js +0 -392
- package/src/openclaw/plugin/lifecycle.js +0 -114
- package/src/openclaw/plugin/managed-config.js +0 -1054
- package/src/openclaw/plugin/onboarding.js +0 -312
- package/src/openclaw/plugin/register-tooling.js +0 -728
- package/src/openclaw/plugin/register.js +0 -1609
- package/src/openclaw/plugin/relay-client-shared.js +0 -146
- package/src/openclaw/plugin/relay-client.js +0 -1469
- package/src/openclaw/plugin/runtime-backup.js +0 -105
- package/src/openclaw/plugin/runtime.js +0 -12
- package/src/openclaw/plugin-version.js +0 -67
- package/src/openclaw/protocol/relay-event-protocol.js +0 -43
- package/src/openclaw/runtime/backend-error-context.js +0 -91
- package/src/openclaw/runtime/canonical-result-builder.js +0 -126
- package/src/openclaw/runtime/demo-session-bootstrap.js +0 -32
- package/src/openclaw/runtime/feedback-helper.js +0 -145
- package/src/openclaw/runtime/inbound-session-router.js +0 -44
- package/src/openclaw/runtime/outbound-session-bridge.js +0 -29
- package/src/openclaw/runtime/product-shell-helper.js +0 -931
- package/src/openclaw/runtime/runtime-path.js +0 -19
- package/src/openclaw/runtime/system-message-orchestrator.js +0 -1
- package/src/openclaw/runtime/tool-contracts.js +0 -939
- package/src/openclaw/runtime/tool-inventory.js +0 -83
- package/src/openclaw/runtime/world-membership-helper.js +0 -320
- package/src/openclaw/runtime/world-moderation-helper.js +0 -508
- package/src/product-shell/contracts/chat-request-approval-policy.js +0 -93
- package/src/product-shell/contracts/world-orchestration.js +0 -734
- package/src/product-shell/orchestration/world-conversation-text.js +0 -229
|
@@ -1,728 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
projectToolChatInboxResponse,
|
|
3
|
-
projectToolChatRequestMutationResponse,
|
|
4
|
-
projectToolManagedWorldResponse,
|
|
5
|
-
projectToolOwnedWorldsResponse,
|
|
6
|
-
projectToolWorldBroadcastResponse,
|
|
7
|
-
projectToolWorldMembershipListResponse,
|
|
8
|
-
projectToolWorldMembershipResponse,
|
|
9
|
-
} from '../runtime/tool-contracts.js';
|
|
10
|
-
import {
|
|
11
|
-
buildPublicErrorPayload,
|
|
12
|
-
createRuntimeBoundaryError,
|
|
13
|
-
logRuntimeBoundary,
|
|
14
|
-
normalizeRuntimeBoundaryError,
|
|
15
|
-
} from '../../lib/runtime-errors.js';
|
|
16
|
-
import {
|
|
17
|
-
normalizeBackendFieldError,
|
|
18
|
-
normalizeBackendMissingField,
|
|
19
|
-
normalizeBackendPublicIdentity,
|
|
20
|
-
} from '../runtime/backend-error-context.js';
|
|
21
|
-
|
|
22
|
-
export const INTERNAL_REQUESTER_SESSION_KEY_PARAM = '__claworldRequesterSessionKey';
|
|
23
|
-
|
|
24
|
-
export function normalizeText(value, fallback = null) {
|
|
25
|
-
if (value == null) return fallback;
|
|
26
|
-
const normalized = String(value).trim();
|
|
27
|
-
return normalized || fallback;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function normalizeObject(value, fallback = null) {
|
|
31
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) return fallback;
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function resolveRuntimeAppToken(runtimeConfig = {}) {
|
|
36
|
-
return normalizeText(
|
|
37
|
-
runtimeConfig?.appToken,
|
|
38
|
-
normalizeText(
|
|
39
|
-
runtimeConfig?.relay?.appToken,
|
|
40
|
-
normalizeText(runtimeConfig?.relay?.credentialToken, null),
|
|
41
|
-
),
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function buildPendingPublicIdentityError({
|
|
46
|
-
plugin,
|
|
47
|
-
cfg,
|
|
48
|
-
accountId,
|
|
49
|
-
runtimeConfig,
|
|
50
|
-
agentId = null,
|
|
51
|
-
capability,
|
|
52
|
-
} = {}) {
|
|
53
|
-
const getPublicIdentity = plugin?.runtime?.productShell?.profile?.getPublicIdentity;
|
|
54
|
-
const capabilityLabel = normalizeText(capability, 'this Claworld capability');
|
|
55
|
-
const fallbackMessage = `${capabilityLabel} requires a public Claworld identity`;
|
|
56
|
-
if (typeof getPublicIdentity !== 'function') {
|
|
57
|
-
return createRuntimeBoundaryError({
|
|
58
|
-
code: 'public_identity_incomplete',
|
|
59
|
-
category: 'conflict',
|
|
60
|
-
status: 409,
|
|
61
|
-
message: fallbackMessage,
|
|
62
|
-
publicMessage: fallbackMessage,
|
|
63
|
-
recoverable: true,
|
|
64
|
-
context: {
|
|
65
|
-
accountId: normalizeText(accountId, null),
|
|
66
|
-
agentId: normalizeText(agentId, null),
|
|
67
|
-
httpStatus: 409,
|
|
68
|
-
backendCode: 'public_identity_incomplete',
|
|
69
|
-
backendMessage: fallbackMessage,
|
|
70
|
-
requiredAction: 'set_public_identity',
|
|
71
|
-
nextAction: 'set_public_identity',
|
|
72
|
-
nextTool: 'claworld_account',
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const identityPayload = await getPublicIdentity({
|
|
78
|
-
cfg,
|
|
79
|
-
accountId,
|
|
80
|
-
runtimeConfig,
|
|
81
|
-
agentId: normalizeText(agentId, null),
|
|
82
|
-
generateShareCard: false,
|
|
83
|
-
expiresInSeconds: null,
|
|
84
|
-
});
|
|
85
|
-
const publicMessage = normalizeText(identityPayload?.message, fallbackMessage);
|
|
86
|
-
return createRuntimeBoundaryError({
|
|
87
|
-
code: 'public_identity_incomplete',
|
|
88
|
-
category: 'conflict',
|
|
89
|
-
status: 409,
|
|
90
|
-
message: publicMessage,
|
|
91
|
-
publicMessage,
|
|
92
|
-
recoverable: true,
|
|
93
|
-
context: {
|
|
94
|
-
accountId: normalizeText(accountId, null),
|
|
95
|
-
agentId: normalizeText(
|
|
96
|
-
agentId,
|
|
97
|
-
normalizeText(identityPayload?.agentId, null),
|
|
98
|
-
),
|
|
99
|
-
httpStatus: 409,
|
|
100
|
-
backendCode: 'public_identity_incomplete',
|
|
101
|
-
backendMessage: publicMessage,
|
|
102
|
-
requiredAction: normalizeText(identityPayload?.requiredAction, 'set_public_identity'),
|
|
103
|
-
nextAction: normalizeText(identityPayload?.nextAction, 'set_public_identity'),
|
|
104
|
-
nextTool: normalizeText(identityPayload?.nextTool, 'claworld_account'),
|
|
105
|
-
missingFields: Array.isArray(identityPayload?.missingFields) ? identityPayload.missingFields : [],
|
|
106
|
-
publicIdentity: normalizeObject(identityPayload?.publicIdentity, null),
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function normalizePublicFieldError(fieldError = {}) {
|
|
112
|
-
const fieldId = normalizeText(fieldError.fieldId, null);
|
|
113
|
-
const message = normalizeText(fieldError.message, null);
|
|
114
|
-
const code = normalizeText(fieldError.code, null);
|
|
115
|
-
if (!fieldId && !message && !code) return null;
|
|
116
|
-
return {
|
|
117
|
-
...(fieldId ? { fieldId } : {}),
|
|
118
|
-
...(message ? { message } : {}),
|
|
119
|
-
...(code ? { code } : {}),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function buildPublicToolErrorExtras(error) {
|
|
124
|
-
const context = normalizeObject(error?.context, null);
|
|
125
|
-
if (!context) return null;
|
|
126
|
-
|
|
127
|
-
const httpStatus = Number(context.httpStatus);
|
|
128
|
-
const backendCode = normalizeText(context.backendCode, null);
|
|
129
|
-
const backendMessage = normalizeText(context.backendMessage, null);
|
|
130
|
-
const fieldErrors = Array.isArray(context.fieldErrors)
|
|
131
|
-
? context.fieldErrors
|
|
132
|
-
.map((fieldError) => normalizeBackendFieldError(fieldError) || normalizePublicFieldError(fieldError))
|
|
133
|
-
.filter(Boolean)
|
|
134
|
-
: [];
|
|
135
|
-
const requiredAction = normalizeText(context.requiredAction, null);
|
|
136
|
-
const nextAction = normalizeText(context.nextAction, null);
|
|
137
|
-
const nextTool = normalizeText(context.nextTool, null);
|
|
138
|
-
const missingFields = Array.isArray(context.missingFields)
|
|
139
|
-
? context.missingFields
|
|
140
|
-
.map((field) => normalizeBackendMissingField(field))
|
|
141
|
-
.filter(Boolean)
|
|
142
|
-
: [];
|
|
143
|
-
const publicIdentity = normalizeBackendPublicIdentity(context.publicIdentity);
|
|
144
|
-
|
|
145
|
-
const extra = {
|
|
146
|
-
...(Number.isInteger(httpStatus) && httpStatus > 0 ? { httpStatus } : {}),
|
|
147
|
-
...(backendCode ? { backendCode } : {}),
|
|
148
|
-
...(backendMessage ? { backendMessage } : {}),
|
|
149
|
-
...(fieldErrors.length > 0 ? { fieldErrors } : {}),
|
|
150
|
-
...(requiredAction ? { requiredAction } : {}),
|
|
151
|
-
...(nextAction ? { nextAction } : {}),
|
|
152
|
-
...(nextTool ? { nextTool } : {}),
|
|
153
|
-
...(missingFields.length > 0 ? { missingFields } : {}),
|
|
154
|
-
...(publicIdentity ? { publicIdentity } : {}),
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
return Object.keys(extra).length > 0 ? extra : null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export async function loadCurrentConfig(api) {
|
|
161
|
-
if (api?.config && typeof api.config.loadConfig === 'function') {
|
|
162
|
-
return await api.config.loadConfig();
|
|
163
|
-
}
|
|
164
|
-
if (api?.runtime?.config && typeof api.runtime.config.loadConfig === 'function') {
|
|
165
|
-
return await api.runtime.config.loadConfig();
|
|
166
|
-
}
|
|
167
|
-
if (api?.config && typeof api.config === 'object') {
|
|
168
|
-
return api.config;
|
|
169
|
-
}
|
|
170
|
-
return {};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function buildToolResult(payload) {
|
|
174
|
-
return {
|
|
175
|
-
content: [
|
|
176
|
-
{
|
|
177
|
-
type: 'text',
|
|
178
|
-
text: JSON.stringify(payload, null, 2),
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function buildToolErrorResult(toolName, error) {
|
|
185
|
-
const normalized = normalizeRuntimeBoundaryError(error, {
|
|
186
|
-
code: 'claworld_tool_execution_failed',
|
|
187
|
-
category: 'runtime',
|
|
188
|
-
publicMessage: 'tool execution failed',
|
|
189
|
-
recoverable: true,
|
|
190
|
-
});
|
|
191
|
-
return buildToolResult({
|
|
192
|
-
status: 'error',
|
|
193
|
-
tool: toolName,
|
|
194
|
-
...buildPublicErrorPayload(normalized, {
|
|
195
|
-
errorType: 'claworld_tool_failed',
|
|
196
|
-
fallbackMessage: 'tool execution failed',
|
|
197
|
-
exposeMessage: normalized.status < 500 || Boolean(normalized.publicMessage),
|
|
198
|
-
extra: buildPublicToolErrorExtras(normalized),
|
|
199
|
-
}),
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function withToolErrorBoundary(toolName, execute) {
|
|
204
|
-
return async (toolCallId, params = {}) => {
|
|
205
|
-
try {
|
|
206
|
-
return await execute(toolCallId, params);
|
|
207
|
-
} catch (error) {
|
|
208
|
-
const normalized = logRuntimeBoundary(console, `[claworld:tool:${toolName}] execution failed`, error, {
|
|
209
|
-
tool: toolName,
|
|
210
|
-
}, {
|
|
211
|
-
includeStack: false,
|
|
212
|
-
fallback: {
|
|
213
|
-
code: 'claworld_tool_execution_failed',
|
|
214
|
-
category: 'runtime',
|
|
215
|
-
publicMessage: 'tool execution failed',
|
|
216
|
-
recoverable: true,
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
return buildToolErrorResult(toolName, normalized);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export async function resolveToolContext(
|
|
225
|
-
api,
|
|
226
|
-
plugin,
|
|
227
|
-
params = {},
|
|
228
|
-
{
|
|
229
|
-
bindRuntime = true,
|
|
230
|
-
requiredPublicIdentityCapability = null,
|
|
231
|
-
} = {},
|
|
232
|
-
) {
|
|
233
|
-
const cfg = await loadCurrentConfig(api);
|
|
234
|
-
const accountId = normalizeText(params.accountId, plugin.config.defaultAccountId(cfg) || null);
|
|
235
|
-
const runtimeConfig = plugin.config.resolveRuntimeConfig(cfg, accountId);
|
|
236
|
-
|
|
237
|
-
if (bindRuntime && typeof plugin.helpers?.resolveToolRuntimeContext === 'function') {
|
|
238
|
-
const resolvedContext = await plugin.helpers.resolveToolRuntimeContext({
|
|
239
|
-
cfg,
|
|
240
|
-
accountId,
|
|
241
|
-
runtimeConfig,
|
|
242
|
-
agentId: normalizeText(params.agentId, runtimeConfig.relay?.agentId || null),
|
|
243
|
-
requesterSessionKey: normalizeText(params[INTERNAL_REQUESTER_SESSION_KEY_PARAM], null),
|
|
244
|
-
});
|
|
245
|
-
if (
|
|
246
|
-
requiredPublicIdentityCapability
|
|
247
|
-
&& (
|
|
248
|
-
!normalizeText(resolvedContext?.agentId, null)
|
|
249
|
-
|| !resolveRuntimeAppToken(resolvedContext?.runtimeConfig || runtimeConfig)
|
|
250
|
-
)
|
|
251
|
-
) {
|
|
252
|
-
throw await buildPendingPublicIdentityError({
|
|
253
|
-
plugin,
|
|
254
|
-
cfg,
|
|
255
|
-
accountId: resolvedContext?.accountId || accountId,
|
|
256
|
-
runtimeConfig: resolvedContext?.runtimeConfig || runtimeConfig,
|
|
257
|
-
agentId: resolvedContext?.agentId || null,
|
|
258
|
-
capability: requiredPublicIdentityCapability,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
return resolvedContext;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const agentId = normalizeText(params.agentId, runtimeConfig.relay?.agentId || null);
|
|
265
|
-
if (
|
|
266
|
-
requiredPublicIdentityCapability
|
|
267
|
-
&& (!agentId || !resolveRuntimeAppToken(runtimeConfig))
|
|
268
|
-
) {
|
|
269
|
-
throw await buildPendingPublicIdentityError({
|
|
270
|
-
plugin,
|
|
271
|
-
cfg,
|
|
272
|
-
accountId,
|
|
273
|
-
runtimeConfig,
|
|
274
|
-
agentId,
|
|
275
|
-
capability: requiredPublicIdentityCapability,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
cfg,
|
|
280
|
-
accountId,
|
|
281
|
-
runtimeConfig,
|
|
282
|
-
agentId,
|
|
283
|
-
requesterSessionKey: normalizeText(params[INTERNAL_REQUESTER_SESSION_KEY_PARAM], null),
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export function cloneMetadataValue(value) {
|
|
288
|
-
return value == null ? value : JSON.parse(JSON.stringify(value));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export function stringParam({
|
|
292
|
-
description = null,
|
|
293
|
-
minLength = null,
|
|
294
|
-
enumValues = null,
|
|
295
|
-
pattern = null,
|
|
296
|
-
examples = [],
|
|
297
|
-
} = {}) {
|
|
298
|
-
return {
|
|
299
|
-
type: 'string',
|
|
300
|
-
...(description ? { description } : {}),
|
|
301
|
-
...(Number.isInteger(minLength) && minLength > 0 ? { minLength } : {}),
|
|
302
|
-
...(Array.isArray(enumValues) && enumValues.length > 0 ? { enum: enumValues } : {}),
|
|
303
|
-
...(pattern ? { pattern } : {}),
|
|
304
|
-
...(Array.isArray(examples) && examples.length > 0 ? { examples } : {}),
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export function integerParam({
|
|
309
|
-
description = null,
|
|
310
|
-
minimum = null,
|
|
311
|
-
maximum = null,
|
|
312
|
-
examples = [],
|
|
313
|
-
} = {}) {
|
|
314
|
-
return {
|
|
315
|
-
type: 'integer',
|
|
316
|
-
...(description ? { description } : {}),
|
|
317
|
-
...(Number.isInteger(minimum) ? { minimum } : {}),
|
|
318
|
-
...(Number.isInteger(maximum) ? { maximum } : {}),
|
|
319
|
-
...(Array.isArray(examples) && examples.length > 0 ? { examples } : {}),
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export function booleanParam({
|
|
324
|
-
description = null,
|
|
325
|
-
defaultValue = null,
|
|
326
|
-
} = {}) {
|
|
327
|
-
return {
|
|
328
|
-
type: 'boolean',
|
|
329
|
-
...(description ? { description } : {}),
|
|
330
|
-
...(typeof defaultValue === 'boolean' ? { default: defaultValue } : {}),
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export function objectParam({
|
|
335
|
-
description = null,
|
|
336
|
-
properties = {},
|
|
337
|
-
required = [],
|
|
338
|
-
additionalProperties = false,
|
|
339
|
-
examples = [],
|
|
340
|
-
} = {}) {
|
|
341
|
-
return {
|
|
342
|
-
type: 'object',
|
|
343
|
-
additionalProperties,
|
|
344
|
-
...(description ? { description } : {}),
|
|
345
|
-
...(Array.isArray(required) && required.length > 0 ? { required } : {}),
|
|
346
|
-
properties,
|
|
347
|
-
...(Array.isArray(examples) && examples.length > 0 ? { examples: examples.map(cloneMetadataValue) } : {}),
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
export function arrayParam({
|
|
352
|
-
description = null,
|
|
353
|
-
items = {},
|
|
354
|
-
maxItems = null,
|
|
355
|
-
examples = [],
|
|
356
|
-
} = {}) {
|
|
357
|
-
return {
|
|
358
|
-
type: 'array',
|
|
359
|
-
items,
|
|
360
|
-
...(description ? { description } : {}),
|
|
361
|
-
...(Number.isInteger(maxItems) ? { maxItems } : {}),
|
|
362
|
-
...(Array.isArray(examples) && examples.length > 0 ? { examples: examples.map(cloneMetadataValue) } : {}),
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
export function buildToolMetadata({
|
|
367
|
-
category,
|
|
368
|
-
usageNotes = [],
|
|
369
|
-
examples = [],
|
|
370
|
-
} = {}) {
|
|
371
|
-
return {
|
|
372
|
-
surface: 'canonical_public',
|
|
373
|
-
canonical: true,
|
|
374
|
-
category: normalizeText(category, 'general'),
|
|
375
|
-
usageNotes: Array.isArray(usageNotes) ? usageNotes.filter(Boolean) : [],
|
|
376
|
-
examples: Array.isArray(examples)
|
|
377
|
-
? examples.map((example) => cloneMetadataValue(example)).filter(Boolean)
|
|
378
|
-
: [],
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export const MANAGE_WORLD_ACTIONS = Object.freeze([
|
|
383
|
-
'list',
|
|
384
|
-
'get',
|
|
385
|
-
'broadcast',
|
|
386
|
-
'update_context',
|
|
387
|
-
'pause',
|
|
388
|
-
'close',
|
|
389
|
-
'resume',
|
|
390
|
-
'list_memberships',
|
|
391
|
-
'get_membership',
|
|
392
|
-
'update_profile',
|
|
393
|
-
'leave',
|
|
394
|
-
]);
|
|
395
|
-
|
|
396
|
-
export function normalizeManageWorldAction(value, fallback = null) {
|
|
397
|
-
const normalized = normalizeText(value, fallback);
|
|
398
|
-
return MANAGE_WORLD_ACTIONS.includes(normalized) ? normalized : fallback;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
export function inferManageWorldAction(params = {}) {
|
|
402
|
-
const explicitAction = normalizeManageWorldAction(params.action, null);
|
|
403
|
-
if (explicitAction) return explicitAction;
|
|
404
|
-
if (!normalizeText(params.worldId, null)) return 'list';
|
|
405
|
-
if (normalizeText(params.announcementText, null)) return 'broadcast';
|
|
406
|
-
if (normalizeText(params.participantContextText, null)) return 'update_profile';
|
|
407
|
-
if (
|
|
408
|
-
normalizeText(params.worldContextText, null)
|
|
409
|
-
|| normalizeText(params.displayName, null)
|
|
410
|
-
|| normalizeObject(params.broadcast, null)
|
|
411
|
-
) {
|
|
412
|
-
return 'update_context';
|
|
413
|
-
}
|
|
414
|
-
return 'get';
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export function requireManageWorldField(fieldId, message = `${fieldId} is required`) {
|
|
418
|
-
throw createRuntimeBoundaryError({
|
|
419
|
-
code: 'tool_input_invalid',
|
|
420
|
-
category: 'input',
|
|
421
|
-
status: 400,
|
|
422
|
-
message,
|
|
423
|
-
publicMessage: message,
|
|
424
|
-
recoverable: true,
|
|
425
|
-
context: { field: fieldId },
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
export function projectToolManageWorldActionResponse(payload = {}, { accountId = null, action = null } = {}) {
|
|
430
|
-
const resolvedAction = normalizeManageWorldAction(action, null) || 'get';
|
|
431
|
-
if (resolvedAction === 'list') {
|
|
432
|
-
return {
|
|
433
|
-
action: resolvedAction,
|
|
434
|
-
...projectToolOwnedWorldsResponse(payload, { accountId }),
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
if (resolvedAction === 'broadcast') {
|
|
438
|
-
return {
|
|
439
|
-
action: resolvedAction,
|
|
440
|
-
...projectToolWorldBroadcastResponse(payload, { accountId }),
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
if (resolvedAction === 'list_memberships') {
|
|
444
|
-
return {
|
|
445
|
-
action: resolvedAction,
|
|
446
|
-
...projectToolWorldMembershipListResponse(payload, { accountId }),
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
if (['get_membership', 'update_profile', 'leave'].includes(resolvedAction)) {
|
|
450
|
-
return {
|
|
451
|
-
action: resolvedAction,
|
|
452
|
-
...projectToolWorldMembershipResponse(payload, { accountId }),
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
return {
|
|
456
|
-
action: resolvedAction,
|
|
457
|
-
...projectToolManagedWorldResponse(payload, { accountId }),
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
export const CHAT_INBOX_ACTIONS = Object.freeze([
|
|
462
|
-
'list',
|
|
463
|
-
'accept',
|
|
464
|
-
'reject',
|
|
465
|
-
]);
|
|
466
|
-
|
|
467
|
-
function normalizeChatInboxAction(value, fallback = null) {
|
|
468
|
-
const normalized = normalizeText(value, fallback);
|
|
469
|
-
return CHAT_INBOX_ACTIONS.includes(normalized) ? normalized : fallback;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export function inferChatInboxAction(params = {}) {
|
|
473
|
-
return normalizeChatInboxAction(params.action, 'list');
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
export function projectToolChatInboxActionResponse(payload = {}, { accountId = null, action = 'list' } = {}) {
|
|
477
|
-
const resolvedAction = normalizeChatInboxAction(action, 'list');
|
|
478
|
-
if (resolvedAction === 'list') {
|
|
479
|
-
return {
|
|
480
|
-
action: resolvedAction,
|
|
481
|
-
...projectToolChatInboxResponse(payload, { accountId }),
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
return {
|
|
485
|
-
action: resolvedAction,
|
|
486
|
-
...projectToolChatRequestMutationResponse(payload, { accountId }),
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
export const ACCOUNT_ACTIONS = Object.freeze([
|
|
491
|
-
'view',
|
|
492
|
-
'update_identity',
|
|
493
|
-
'update_profile',
|
|
494
|
-
'update_chat_policy',
|
|
495
|
-
]);
|
|
496
|
-
|
|
497
|
-
function normalizeAccountAction(value, fallback = null) {
|
|
498
|
-
const normalized = normalizeText(value, fallback);
|
|
499
|
-
return ACCOUNT_ACTIONS.includes(normalized) ? normalized : fallback;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
export function inferAccountAction(params = {}) {
|
|
503
|
-
const explicitAction = normalizeAccountAction(params.action, null);
|
|
504
|
-
if (explicitAction) return explicitAction;
|
|
505
|
-
if (normalizeText(params.displayName, null)) return 'update_identity';
|
|
506
|
-
if (Object.prototype.hasOwnProperty.call(params, 'profile')) return 'update_profile';
|
|
507
|
-
if (normalizeObject(params.chatRequestApprovalPolicy, null)) return 'update_chat_policy';
|
|
508
|
-
return 'view';
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function projectToolPublicIdentity(payload = null) {
|
|
512
|
-
if (!payload || typeof payload !== 'object') return null;
|
|
513
|
-
return {
|
|
514
|
-
status: payload.status || null,
|
|
515
|
-
ready: payload.ready ?? null,
|
|
516
|
-
publicIdentity: payload.publicIdentity && typeof payload.publicIdentity === 'object'
|
|
517
|
-
? {
|
|
518
|
-
status: payload.publicIdentity.status || null,
|
|
519
|
-
displayIdentity: payload.publicIdentity.displayIdentity || null,
|
|
520
|
-
displayName: payload.publicIdentity.displayName || null,
|
|
521
|
-
code: payload.publicIdentity.code || null,
|
|
522
|
-
confirmedAt: payload.publicIdentity.confirmedAt || null,
|
|
523
|
-
updatedAt: payload.publicIdentity.updatedAt || null,
|
|
524
|
-
}
|
|
525
|
-
: null,
|
|
526
|
-
recommendedDisplayName: payload.recommendedDisplayName || null,
|
|
527
|
-
requiredAction: payload.requiredAction || null,
|
|
528
|
-
nextAction: payload.nextAction || null,
|
|
529
|
-
nextTool: payload.nextTool || null,
|
|
530
|
-
missingFields: Array.isArray(payload.missingFields) ? payload.missingFields : [],
|
|
531
|
-
feedbackSummary: payload.feedbackSummary && typeof payload.feedbackSummary === 'object'
|
|
532
|
-
? {
|
|
533
|
-
totalLikesReceived: Number(payload.feedbackSummary.totalLikesReceived || 0),
|
|
534
|
-
totalDislikesReceived: Number(payload.feedbackSummary.totalDislikesReceived || 0),
|
|
535
|
-
totalLikesGiven: Number(payload.feedbackSummary.totalLikesGiven || 0),
|
|
536
|
-
totalDislikesGiven: Number(payload.feedbackSummary.totalDislikesGiven || 0),
|
|
537
|
-
}
|
|
538
|
-
: null,
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function projectToolShareCard(payload = null) {
|
|
543
|
-
const imageUrl = normalizeText(payload?.imageUrl, null);
|
|
544
|
-
const downloadUrl = normalizeText(payload?.downloadUrl, imageUrl);
|
|
545
|
-
const templateId = normalizeText(payload?.templateId, null);
|
|
546
|
-
const expiresAt = normalizeText(payload?.expiresAt, null);
|
|
547
|
-
const description = normalizeText(payload?.description, null);
|
|
548
|
-
if (!imageUrl && !downloadUrl && !templateId && !expiresAt && !description) {
|
|
549
|
-
return {
|
|
550
|
-
status: normalizeText(payload?.status, 'unavailable'),
|
|
551
|
-
reason: normalizeText(payload?.reason, null),
|
|
552
|
-
message: normalizeText(payload?.message, null),
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
return {
|
|
556
|
-
status: normalizeText(payload?.status, 'ready'),
|
|
557
|
-
imageUrl,
|
|
558
|
-
downloadUrl,
|
|
559
|
-
templateId,
|
|
560
|
-
expiresAt,
|
|
561
|
-
description,
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function projectToolAccountIdentityFields(identityPayload = null) {
|
|
566
|
-
const projectedIdentity = projectToolPublicIdentity(identityPayload);
|
|
567
|
-
if (projectedIdentity) {
|
|
568
|
-
return {
|
|
569
|
-
publicIdentity: projectedIdentity.publicIdentity,
|
|
570
|
-
recommendedDisplayName: projectedIdentity.recommendedDisplayName,
|
|
571
|
-
requiredAction: projectedIdentity.requiredAction,
|
|
572
|
-
nextAction: projectedIdentity.nextAction,
|
|
573
|
-
nextTool: projectedIdentity.nextTool,
|
|
574
|
-
missingFields: projectedIdentity.missingFields,
|
|
575
|
-
feedbackSummary: projectedIdentity.feedbackSummary,
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
return {
|
|
579
|
-
publicIdentity: null,
|
|
580
|
-
recommendedDisplayName: null,
|
|
581
|
-
requiredAction: null,
|
|
582
|
-
nextAction: null,
|
|
583
|
-
nextTool: null,
|
|
584
|
-
missingFields: [],
|
|
585
|
-
feedbackSummary: null,
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
function projectToolAccountProfile(identityPayload = null) {
|
|
590
|
-
return normalizeText(identityPayload?.profile, null);
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
function projectToolChatRequestApprovalPolicy(payload = null) {
|
|
594
|
-
const policy = normalizeObject(payload, null);
|
|
595
|
-
if (!policy) return null;
|
|
596
|
-
return {
|
|
597
|
-
agentId: normalizeText(policy.agentId, null),
|
|
598
|
-
schemaVersion: Number.isInteger(policy.schemaVersion) ? policy.schemaVersion : null,
|
|
599
|
-
syncedAt: normalizeText(policy.syncedAt, null),
|
|
600
|
-
credentialId: normalizeText(policy.credentialId, null),
|
|
601
|
-
source: normalizeObject(policy.source, {})
|
|
602
|
-
? {
|
|
603
|
-
channel: normalizeText(policy.source?.channel, null),
|
|
604
|
-
integration: normalizeText(policy.source?.integration, null),
|
|
605
|
-
accountId: normalizeText(policy.source?.accountId, null),
|
|
606
|
-
}
|
|
607
|
-
: {},
|
|
608
|
-
policy: normalizeObject(policy.policy, {})
|
|
609
|
-
? {
|
|
610
|
-
mode: normalizeText(policy.policy?.mode, null),
|
|
611
|
-
blocks: {
|
|
612
|
-
originTypes: Array.isArray(policy.policy?.blocks?.originTypes) ? policy.policy.blocks.originTypes : [],
|
|
613
|
-
worldIds: Array.isArray(policy.policy?.blocks?.worldIds) ? policy.policy.blocks.worldIds : [],
|
|
614
|
-
},
|
|
615
|
-
}
|
|
616
|
-
: null,
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function projectToolPluginVersionStatus(payload = null) {
|
|
621
|
-
const versionStatus = normalizeObject(payload, null);
|
|
622
|
-
if (!versionStatus) return null;
|
|
623
|
-
|
|
624
|
-
const warning = normalizeObject(versionStatus.warning, null);
|
|
625
|
-
return {
|
|
626
|
-
reportedVersion: normalizeText(versionStatus.reportedVersion, null),
|
|
627
|
-
minSupportedVersion: normalizeText(versionStatus.minSupportedVersion, null),
|
|
628
|
-
latestVersion: normalizeText(versionStatus.latestVersion, null),
|
|
629
|
-
compatible: typeof versionStatus.compatible === 'boolean' ? versionStatus.compatible : null,
|
|
630
|
-
status: normalizeText(versionStatus.status, 'unknown'),
|
|
631
|
-
upgradeCommand: normalizeText(versionStatus.upgradeCommand, null),
|
|
632
|
-
message: normalizeText(versionStatus.message, null),
|
|
633
|
-
...(warning
|
|
634
|
-
? {
|
|
635
|
-
warning: {
|
|
636
|
-
level: normalizeText(warning.level, null),
|
|
637
|
-
code: normalizeText(warning.code, null),
|
|
638
|
-
message: normalizeText(warning.message, null),
|
|
639
|
-
},
|
|
640
|
-
}
|
|
641
|
-
: {}),
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
export function projectToolAccountViewResponse({
|
|
646
|
-
accountId = null,
|
|
647
|
-
pairingPayload = null,
|
|
648
|
-
identityPayload = null,
|
|
649
|
-
} = {}) {
|
|
650
|
-
const identityReady = identityPayload?.ready === true;
|
|
651
|
-
const ready = pairingPayload?.status === 'paired' && identityReady;
|
|
652
|
-
const resolvedShareCard = identityPayload && Object.prototype.hasOwnProperty.call(identityPayload, 'shareCard')
|
|
653
|
-
? projectToolShareCard(identityPayload.shareCard)
|
|
654
|
-
: undefined;
|
|
655
|
-
return {
|
|
656
|
-
action: 'view',
|
|
657
|
-
status: ready ? 'ready' : 'pending',
|
|
658
|
-
ready,
|
|
659
|
-
readiness: pairingPayload?.status === 'paired'
|
|
660
|
-
? (identityReady ? 'paired_and_ready' : 'paired_but_identity_pending')
|
|
661
|
-
: 'installed_unactivated',
|
|
662
|
-
accountId: normalizeText(pairingPayload?.runtimeConfig?.accountId, normalizeText(accountId, null)),
|
|
663
|
-
reason: normalizeText(pairingPayload?.reason, null),
|
|
664
|
-
bindingSource: normalizeText(pairingPayload?.bindingSource, null),
|
|
665
|
-
activation: {
|
|
666
|
-
status: pairingPayload?.status === 'paired' ? 'ready' : 'pending',
|
|
667
|
-
},
|
|
668
|
-
relay: {
|
|
669
|
-
agentId: normalizeText(
|
|
670
|
-
pairingPayload?.runtimeConfig?.relay?.agentId,
|
|
671
|
-
normalizeText(pairingPayload?.relayAgent?.agentId, null),
|
|
672
|
-
),
|
|
673
|
-
displayName: normalizeText(pairingPayload?.relayAgent?.displayName, null),
|
|
674
|
-
discoverable: pairingPayload?.relayAgent?.discoverable ?? null,
|
|
675
|
-
contactable: pairingPayload?.relayAgent?.contactable ?? null,
|
|
676
|
-
online: pairingPayload?.relayAgent?.online ?? null,
|
|
677
|
-
resolved: pairingPayload?.relayAgent?.resolved ?? null,
|
|
678
|
-
bindingStatus: pairingPayload?.status === 'paired' ? 'bound' : 'unactivated',
|
|
679
|
-
},
|
|
680
|
-
profile: projectToolAccountProfile(identityPayload),
|
|
681
|
-
...projectToolAccountIdentityFields(identityPayload),
|
|
682
|
-
pluginVersionStatus: projectToolPluginVersionStatus(identityPayload?.pluginVersionStatus),
|
|
683
|
-
chatRequestApprovalPolicy: projectToolChatRequestApprovalPolicy(identityPayload?.chatRequestApprovalPolicy),
|
|
684
|
-
...(resolvedShareCard !== undefined ? { shareCard: resolvedShareCard } : {}),
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
export function projectToolAccountMutationResponse({
|
|
689
|
-
action = 'update_identity',
|
|
690
|
-
accountId = null,
|
|
691
|
-
identityPayload = null,
|
|
692
|
-
shareCard = undefined,
|
|
693
|
-
runtimeActivation = null,
|
|
694
|
-
} = {}) {
|
|
695
|
-
const resolvedShareCard = shareCard !== undefined
|
|
696
|
-
? shareCard
|
|
697
|
-
: (identityPayload && Object.prototype.hasOwnProperty.call(identityPayload, 'shareCard')
|
|
698
|
-
? projectToolShareCard(identityPayload.shareCard)
|
|
699
|
-
: undefined);
|
|
700
|
-
const ready = identityPayload?.ready === true;
|
|
701
|
-
return {
|
|
702
|
-
action,
|
|
703
|
-
status: ready ? 'ready' : 'pending',
|
|
704
|
-
ready,
|
|
705
|
-
accountId: normalizeText(accountId, null),
|
|
706
|
-
profile: projectToolAccountProfile(identityPayload),
|
|
707
|
-
...projectToolAccountIdentityFields(identityPayload),
|
|
708
|
-
pluginVersionStatus: projectToolPluginVersionStatus(identityPayload?.pluginVersionStatus),
|
|
709
|
-
chatRequestApprovalPolicy: projectToolChatRequestApprovalPolicy(identityPayload?.chatRequestApprovalPolicy),
|
|
710
|
-
...(resolvedShareCard !== undefined ? { shareCard: resolvedShareCard } : {}),
|
|
711
|
-
...(runtimeActivation ? { runtimeActivation } : {}),
|
|
712
|
-
...(action === 'update_identity'
|
|
713
|
-
? {
|
|
714
|
-
updated: resolvedShareCard && resolvedShareCard.status === 'ready'
|
|
715
|
-
? ['publicIdentity', 'shareCard']
|
|
716
|
-
: ['publicIdentity'],
|
|
717
|
-
}
|
|
718
|
-
: action === 'update_profile'
|
|
719
|
-
? {
|
|
720
|
-
updated: ['profile'],
|
|
721
|
-
}
|
|
722
|
-
: action === 'update_chat_policy'
|
|
723
|
-
? {
|
|
724
|
-
updated: ['chatRequestApprovalPolicy'],
|
|
725
|
-
}
|
|
726
|
-
: {}),
|
|
727
|
-
};
|
|
728
|
-
}
|