@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,939 +0,0 @@
|
|
|
1
|
-
import { normalizeAcceptedChatKickoffRecord } from '../../lib/relay/kickoff-progress.js';
|
|
2
|
-
|
|
3
|
-
function normalizeText(value, fallback = null) {
|
|
4
|
-
if (value == null) return fallback;
|
|
5
|
-
const normalized = String(value).trim();
|
|
6
|
-
return normalized || fallback;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function normalizeInteger(value, fallback = 0) {
|
|
10
|
-
const parsed = Number(value);
|
|
11
|
-
if (!Number.isFinite(parsed)) return fallback;
|
|
12
|
-
return Math.max(0, Math.trunc(parsed));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function normalizePositiveInteger(value, fallback = null) {
|
|
16
|
-
const parsed = Number(value);
|
|
17
|
-
if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
|
|
18
|
-
return Math.max(1, Math.trunc(parsed));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function normalizeOptionalBoolean(value, fallback = null) {
|
|
22
|
-
if (typeof value === 'boolean') return value;
|
|
23
|
-
return fallback;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function normalizeOptionalInteger(value, fallback = null) {
|
|
27
|
-
const parsed = Number(value);
|
|
28
|
-
if (!Number.isFinite(parsed)) return fallback;
|
|
29
|
-
return Math.trunc(parsed);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function normalizeStringList(values = []) {
|
|
33
|
-
if (!Array.isArray(values)) return [];
|
|
34
|
-
return values
|
|
35
|
-
.map((value) => normalizeText(value, null))
|
|
36
|
-
.filter(Boolean);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function projectParticipantContextField(field = null) {
|
|
40
|
-
if (!field || typeof field !== 'object' || Array.isArray(field)) return null;
|
|
41
|
-
return {
|
|
42
|
-
fieldId: normalizeText(field.fieldId, null),
|
|
43
|
-
label: normalizeText(field.label, normalizeText(field.fieldId, 'Entry Profile')),
|
|
44
|
-
description: normalizeText(field.description, null),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function projectWorldRole(worldRole, fallback = null) {
|
|
49
|
-
const normalized = normalizeText(worldRole, fallback);
|
|
50
|
-
return ['owner', 'member'].includes(normalized) ? normalized : fallback;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function projectWorldStats(stats = null) {
|
|
54
|
-
if (!stats || typeof stats !== 'object' || Array.isArray(stats)) return null;
|
|
55
|
-
return {
|
|
56
|
-
totalParticipants: normalizeOptionalInteger(stats.totalParticipants, null),
|
|
57
|
-
activeParticipants: normalizeOptionalInteger(stats.activeParticipants, null),
|
|
58
|
-
totalConversationCount: normalizeOptionalInteger(stats.totalConversationCount, null),
|
|
59
|
-
totalLikes: normalizeOptionalInteger(stats.totalLikes, null),
|
|
60
|
-
totalDislikes: normalizeOptionalInteger(stats.totalDislikes, null),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function projectToolBroadcastConfig(broadcast = null) {
|
|
65
|
-
if (!broadcast || typeof broadcast !== 'object' || Array.isArray(broadcast)) return null;
|
|
66
|
-
return {
|
|
67
|
-
enabled: normalizeOptionalBoolean(broadcast.enabled, null),
|
|
68
|
-
audience: normalizeText(broadcast.audience, null),
|
|
69
|
-
replyPolicy: normalizeText(broadcast.replyPolicy, null),
|
|
70
|
-
excludeSelf: normalizeOptionalBoolean(broadcast.excludeSelf, null),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function projectWorldFeedbackSummary(summary = null) {
|
|
75
|
-
if (!summary || typeof summary !== 'object' || Array.isArray(summary)) return null;
|
|
76
|
-
return {
|
|
77
|
-
likesReceived: normalizeInteger(summary.likesReceived, 0),
|
|
78
|
-
dislikesReceived: normalizeInteger(summary.dislikesReceived, 0),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function projectConversationFeedbackSummary(summary = null) {
|
|
83
|
-
if (!summary || typeof summary !== 'object' || Array.isArray(summary)) return null;
|
|
84
|
-
return {
|
|
85
|
-
likeCount: normalizeInteger(summary.likeCount, 0),
|
|
86
|
-
dislikeCount: normalizeInteger(summary.dislikeCount, 0),
|
|
87
|
-
viewerGave: normalizeText(summary.viewerGave, null),
|
|
88
|
-
viewerReceived: normalizeText(summary.viewerReceived, null),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function projectOrchestration(orchestration = null) {
|
|
93
|
-
if (!orchestration || typeof orchestration !== 'object' || Array.isArray(orchestration)) return null;
|
|
94
|
-
return {
|
|
95
|
-
stage: normalizeText(orchestration.stage, null),
|
|
96
|
-
system: normalizeText(orchestration.system, null),
|
|
97
|
-
confirmation: normalizeText(orchestration.confirmation, null),
|
|
98
|
-
user: normalizeText(orchestration.user, null),
|
|
99
|
-
followUp: normalizeText(orchestration.followUp, null),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function projectToolAction(action = null) {
|
|
104
|
-
if (!action || typeof action !== 'object' || Array.isArray(action)) return null;
|
|
105
|
-
return {
|
|
106
|
-
tool: normalizeText(action.tool, null),
|
|
107
|
-
summary: normalizeText(action.summary, null),
|
|
108
|
-
payload: action.payload && typeof action.payload === 'object' && !Array.isArray(action.payload)
|
|
109
|
-
? action.payload
|
|
110
|
-
: {},
|
|
111
|
-
payloadTemplate: action.payloadTemplate && typeof action.payloadTemplate === 'object' && !Array.isArray(action.payloadTemplate)
|
|
112
|
-
? action.payloadTemplate
|
|
113
|
-
: {},
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function projectRequestChatPayload(
|
|
118
|
-
requestChat = null,
|
|
119
|
-
{
|
|
120
|
-
accountId = null,
|
|
121
|
-
requestToolName = 'claworld_request_chat',
|
|
122
|
-
} = {},
|
|
123
|
-
) {
|
|
124
|
-
if (!requestChat || typeof requestChat !== 'object' || Array.isArray(requestChat)) return null;
|
|
125
|
-
const worldId = normalizeText(requestChat.worldId, null);
|
|
126
|
-
const displayName = normalizeText(requestChat.displayName, null);
|
|
127
|
-
const agentCode = normalizeText(requestChat.agentCode, null)?.toUpperCase() || null;
|
|
128
|
-
if (!worldId || !displayName || !agentCode) return null;
|
|
129
|
-
|
|
130
|
-
const normalizedAccountId = normalizeText(accountId, null);
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
worldId,
|
|
134
|
-
displayName,
|
|
135
|
-
agentCode,
|
|
136
|
-
requestTool: normalizeText(requestToolName, null),
|
|
137
|
-
requestPayload: {
|
|
138
|
-
...(normalizedAccountId ? { accountId: normalizedAccountId } : {}),
|
|
139
|
-
worldId,
|
|
140
|
-
displayName,
|
|
141
|
-
agentCode,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function projectRequestChatAction(
|
|
147
|
-
requestChatAction = null,
|
|
148
|
-
{
|
|
149
|
-
accountId = null,
|
|
150
|
-
requestToolName = 'claworld_request_chat',
|
|
151
|
-
} = {},
|
|
152
|
-
) {
|
|
153
|
-
if (!requestChatAction || typeof requestChatAction !== 'object' || Array.isArray(requestChatAction)) return null;
|
|
154
|
-
const worldId = normalizeText(requestChatAction.worldId, null);
|
|
155
|
-
if (!worldId) return null;
|
|
156
|
-
|
|
157
|
-
const normalizedAccountId = normalizeText(accountId, null);
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
action: normalizeText(requestChatAction.action, 'request_chat'),
|
|
161
|
-
worldId,
|
|
162
|
-
requiredFields: normalizeStringList(requestChatAction.requiredFields),
|
|
163
|
-
requestTool: normalizeText(requestToolName, null),
|
|
164
|
-
requestPayloadTemplate: {
|
|
165
|
-
...(normalizedAccountId ? { accountId: normalizedAccountId } : {}),
|
|
166
|
-
worldId,
|
|
167
|
-
displayName: ':displayName',
|
|
168
|
-
agentCode: ':agentCode',
|
|
169
|
-
},
|
|
170
|
-
summary: normalizeText(requestChatAction.summary, null),
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function projectToolCandidateDeliverySummary(
|
|
175
|
-
candidateDelivery = {},
|
|
176
|
-
{
|
|
177
|
-
accountId = null,
|
|
178
|
-
requestToolName = 'claworld_request_chat',
|
|
179
|
-
} = {},
|
|
180
|
-
) {
|
|
181
|
-
if (!candidateDelivery || typeof candidateDelivery !== 'object' || Array.isArray(candidateDelivery)) return null;
|
|
182
|
-
|
|
183
|
-
const candidateSummaries = Array.isArray(candidateDelivery.candidateSummaries)
|
|
184
|
-
? candidateDelivery.candidateSummaries.map((summary) => ({
|
|
185
|
-
candidateId: normalizeText(summary.candidateId, null),
|
|
186
|
-
sourceMembershipId: normalizeText(summary.sourceMembershipId, null),
|
|
187
|
-
displayName: normalizeText(summary.displayName, null),
|
|
188
|
-
worldRole: projectWorldRole(summary.worldRole, null),
|
|
189
|
-
headline: normalizeText(summary.headline, null),
|
|
190
|
-
online: summary.online === true,
|
|
191
|
-
rank: normalizeOptionalInteger(summary.rank, null),
|
|
192
|
-
score: normalizeOptionalInteger(summary.score, null),
|
|
193
|
-
agentCode: normalizeText(summary.agentCode, summary.requestChat?.agentCode || null)?.toUpperCase() || null,
|
|
194
|
-
requestChat: projectRequestChatPayload(summary.requestChat, {
|
|
195
|
-
accountId,
|
|
196
|
-
requestToolName,
|
|
197
|
-
}),
|
|
198
|
-
requiredFieldSummary: normalizeStringList(summary.requiredFieldSummary),
|
|
199
|
-
optionalFieldSummary: normalizeStringList(summary.optionalFieldSummary),
|
|
200
|
-
compatibilitySummary: normalizeStringList(summary.compatibilitySummary),
|
|
201
|
-
deliveryReasonSummary: normalizeText(summary.deliveryReasonSummary, null),
|
|
202
|
-
expiresAt: normalizeText(summary.expiresAt, null),
|
|
203
|
-
summary: normalizeText(summary.summary, null),
|
|
204
|
-
}))
|
|
205
|
-
: [];
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
status: normalizeText(candidateDelivery.status, null),
|
|
209
|
-
worldId: normalizeText(candidateDelivery.worldId, null),
|
|
210
|
-
deliveredCandidateCount: normalizeInteger(candidateDelivery.deliveredCandidateCount, candidateSummaries.length),
|
|
211
|
-
totalCandidateCount: normalizeInteger(candidateDelivery.totalCandidateCount, candidateSummaries.length),
|
|
212
|
-
remainingCandidateCount: normalizeInteger(candidateDelivery.remainingCandidateCount, 0),
|
|
213
|
-
nextAction: normalizeText(candidateDelivery.nextAction, null),
|
|
214
|
-
requestChatAction: projectRequestChatAction(candidateDelivery.requestChatAction, {
|
|
215
|
-
accountId,
|
|
216
|
-
requestToolName,
|
|
217
|
-
}),
|
|
218
|
-
candidateSummaries,
|
|
219
|
-
orchestration: projectOrchestration(candidateDelivery.orchestration),
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function projectToolWorldList(worldDirectory = {}) {
|
|
224
|
-
const worlds = Array.isArray(worldDirectory.items)
|
|
225
|
-
? worldDirectory.items.map((world) => ({
|
|
226
|
-
worldId: world.worldId,
|
|
227
|
-
displayName: world.displayName,
|
|
228
|
-
summary: normalizeText(world.summary, null),
|
|
229
|
-
worldContextText: normalizeText(world.worldContextText, null),
|
|
230
|
-
tags: normalizeStringList(world.tags),
|
|
231
|
-
hotness: normalizeInteger(world.hotness, 0),
|
|
232
|
-
activatedMemberCount: normalizeInteger(world.activatedMemberCount, normalizeInteger(world.hotness, 0)),
|
|
233
|
-
reasonSummary: normalizeText(world.reasonSummary, null),
|
|
234
|
-
detailAction: projectToolAction(world.detailAction),
|
|
235
|
-
joinAction: projectToolAction(world.joinAction),
|
|
236
|
-
}))
|
|
237
|
-
: [];
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
worlds,
|
|
241
|
-
mode: normalizeText(worldDirectory.mode, 'browse'),
|
|
242
|
-
query: normalizeText(worldDirectory.query, null),
|
|
243
|
-
sort: normalizeText(worldDirectory.sort, 'hot'),
|
|
244
|
-
nextAction: normalizeText(worldDirectory.nextAction, 'inspect_world_detail_or_join_world'),
|
|
245
|
-
pagination: worldDirectory.pagination && typeof worldDirectory.pagination === 'object'
|
|
246
|
-
? {
|
|
247
|
-
page: normalizeInteger(worldDirectory.pagination.page, 1),
|
|
248
|
-
totalPages: normalizeInteger(worldDirectory.pagination.totalPages, 0),
|
|
249
|
-
totalCount: normalizeInteger(worldDirectory.pagination.totalCount, worlds.length),
|
|
250
|
-
}
|
|
251
|
-
: {
|
|
252
|
-
page: 1,
|
|
253
|
-
totalPages: worlds.length > 0 ? 1 : 0,
|
|
254
|
-
totalCount: worlds.length,
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export function projectToolWorldSearchResponse(worldDirectory = {}, { accountId = null } = {}) {
|
|
260
|
-
const worlds = Array.isArray(worldDirectory.items)
|
|
261
|
-
? worldDirectory.items.map((world) => ({
|
|
262
|
-
worldId: world.worldId,
|
|
263
|
-
displayName: world.displayName,
|
|
264
|
-
summary: normalizeText(world.summary, null),
|
|
265
|
-
worldContextText: normalizeText(world.worldContextText, null),
|
|
266
|
-
tags: normalizeStringList(world.tags),
|
|
267
|
-
hotness: normalizeInteger(world.hotness, 0),
|
|
268
|
-
activatedMemberCount: normalizeInteger(world.activatedMemberCount, normalizeInteger(world.hotness, 0)),
|
|
269
|
-
matchScore: normalizeInteger(world.matchScore, 0),
|
|
270
|
-
matchedFieldIds: normalizeStringList(world.matchedFieldIds),
|
|
271
|
-
matchedTerms: normalizeStringList(world.matchedTerms),
|
|
272
|
-
reasonSummary: normalizeText(world.reasonSummary, null),
|
|
273
|
-
detailAction: projectToolAction(world.detailAction),
|
|
274
|
-
joinAction: projectToolAction(world.joinAction),
|
|
275
|
-
}))
|
|
276
|
-
: [];
|
|
277
|
-
|
|
278
|
-
return {
|
|
279
|
-
accountId: normalizeText(accountId, null),
|
|
280
|
-
status: normalizeText(worldDirectory.status, worlds.length > 0 ? 'search_ready' : 'no_matches'),
|
|
281
|
-
mode: normalizeText(worldDirectory.mode, 'browse'),
|
|
282
|
-
query: normalizeText(worldDirectory.query, null),
|
|
283
|
-
sort: normalizeText(worldDirectory.sort, 'match'),
|
|
284
|
-
nextAction: normalizeText(worldDirectory.nextAction, worlds.length > 0 ? 'inspect_world_detail_or_join_world' : 'broaden_world_search'),
|
|
285
|
-
worlds,
|
|
286
|
-
pagination: worldDirectory.pagination && typeof worldDirectory.pagination === 'object'
|
|
287
|
-
? {
|
|
288
|
-
page: normalizeInteger(worldDirectory.pagination.page, 1),
|
|
289
|
-
totalPages: normalizeInteger(worldDirectory.pagination.totalPages, 0),
|
|
290
|
-
totalCount: normalizeInteger(worldDirectory.pagination.totalCount, worlds.length),
|
|
291
|
-
}
|
|
292
|
-
: {
|
|
293
|
-
page: 1,
|
|
294
|
-
totalPages: worlds.length > 0 ? 1 : 0,
|
|
295
|
-
totalCount: worlds.length,
|
|
296
|
-
},
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export function projectToolWorldDetail(worldDetail = {}, { accountId = null } = {}) {
|
|
301
|
-
return {
|
|
302
|
-
worldId: worldDetail.worldId,
|
|
303
|
-
displayName: normalizeText(worldDetail.world?.displayName, worldDetail.displayName || ''),
|
|
304
|
-
worldContextText: normalizeText(
|
|
305
|
-
worldDetail.world?.worldContextText,
|
|
306
|
-
worldDetail.worldContextText || '',
|
|
307
|
-
),
|
|
308
|
-
ownerAgentId: normalizeText(
|
|
309
|
-
worldDetail.management?.ownerAgentId,
|
|
310
|
-
normalizeText(worldDetail.ownerAgentId, null),
|
|
311
|
-
),
|
|
312
|
-
worldRole: projectWorldRole(worldDetail.worldRole, null),
|
|
313
|
-
enabled: normalizeOptionalBoolean(worldDetail.management?.enabled, normalizeOptionalBoolean(worldDetail.enabled, null)),
|
|
314
|
-
status: normalizeText(worldDetail.management?.status, normalizeText(worldDetail.statusLabel, null)),
|
|
315
|
-
participantContextField: projectParticipantContextField(worldDetail.participantContextField),
|
|
316
|
-
memberSearchAction: {
|
|
317
|
-
tool: 'claworld_search_world_members',
|
|
318
|
-
summary: 'After joining this world, search joined members by profile match or likes.',
|
|
319
|
-
payloadTemplate: {
|
|
320
|
-
...(normalizeText(accountId, null) ? { accountId: normalizeText(accountId, null) } : {}),
|
|
321
|
-
worldId: worldDetail.worldId,
|
|
322
|
-
query: ':query',
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function projectToolCandidateSummary(summary = {}, index = 0) {
|
|
329
|
-
return {
|
|
330
|
-
candidateId: normalizeText(summary.candidateId, `candidate_${index + 1}`),
|
|
331
|
-
displayName: normalizeText(summary.displayName, `Candidate ${index + 1}`),
|
|
332
|
-
agentCode: normalizeText(summary.agentCode, null)?.toUpperCase() || null,
|
|
333
|
-
worldRole: projectWorldRole(summary.worldRole, null),
|
|
334
|
-
headline: normalizeText(summary.headline, null),
|
|
335
|
-
online: summary.online === true,
|
|
336
|
-
rank: normalizeInteger(summary.rank, 0) || null,
|
|
337
|
-
score: normalizeInteger(summary.score, 0) || null,
|
|
338
|
-
summary: normalizeText(summary.summary, null),
|
|
339
|
-
expiresAt: normalizeText(summary.expiresAt, null),
|
|
340
|
-
worldFeedbackSummary: projectWorldFeedbackSummary(summary.worldFeedbackSummary),
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function projectCandidateProfileSummary(summary = {}) {
|
|
345
|
-
return {
|
|
346
|
-
displayName: normalizeText(summary.displayName, null),
|
|
347
|
-
headline: normalizeText(summary.headline, null),
|
|
348
|
-
requiredFields: Array.isArray(summary.requiredFields)
|
|
349
|
-
? summary.requiredFields.map((field) => ({
|
|
350
|
-
fieldId: normalizeText(field.fieldId, null),
|
|
351
|
-
label: normalizeText(field.label, normalizeText(field.fieldId, null)),
|
|
352
|
-
value: Array.isArray(field.value) ? normalizeStringList(field.value) : normalizeText(field.value, null),
|
|
353
|
-
}))
|
|
354
|
-
: [],
|
|
355
|
-
optionalFields: Array.isArray(summary.optionalFields)
|
|
356
|
-
? summary.optionalFields.map((field) => ({
|
|
357
|
-
fieldId: normalizeText(field.fieldId, null),
|
|
358
|
-
label: normalizeText(field.label, normalizeText(field.fieldId, null)),
|
|
359
|
-
value: Array.isArray(field.value) ? normalizeStringList(field.value) : normalizeText(field.value, null),
|
|
360
|
-
}))
|
|
361
|
-
: [],
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function resolveCandidateProjectionPayload(payload = {}) {
|
|
366
|
-
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
367
|
-
return {
|
|
368
|
-
worldId: null,
|
|
369
|
-
nextAction: null,
|
|
370
|
-
candidateFeed: null,
|
|
371
|
-
candidateDelivery: null,
|
|
372
|
-
requestChatAction: null,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const candidateFeed = payload.candidateFeed && typeof payload.candidateFeed === 'object' && !Array.isArray(payload.candidateFeed)
|
|
377
|
-
? payload.candidateFeed
|
|
378
|
-
: Array.isArray(payload.candidates)
|
|
379
|
-
? payload
|
|
380
|
-
: null;
|
|
381
|
-
const candidateDelivery = payload.candidateDelivery && typeof payload.candidateDelivery === 'object' && !Array.isArray(payload.candidateDelivery)
|
|
382
|
-
? payload.candidateDelivery
|
|
383
|
-
: candidateFeed?.candidateDelivery && typeof candidateFeed.candidateDelivery === 'object' && !Array.isArray(candidateFeed.candidateDelivery)
|
|
384
|
-
? candidateFeed.candidateDelivery
|
|
385
|
-
: null;
|
|
386
|
-
const candidateModelRequestChatAction = candidateFeed?.candidateModel && typeof candidateFeed.candidateModel === 'object' && !Array.isArray(candidateFeed.candidateModel)
|
|
387
|
-
? candidateFeed.candidateModel.requestChatAction
|
|
388
|
-
: null;
|
|
389
|
-
|
|
390
|
-
return {
|
|
391
|
-
worldId: normalizeText(payload.worldId, normalizeText(candidateFeed?.worldId, normalizeText(candidateDelivery?.worldId, null))),
|
|
392
|
-
nextAction: normalizeText(payload.nextAction, normalizeText(candidateFeed?.nextAction, normalizeText(candidateDelivery?.nextAction, null))),
|
|
393
|
-
candidateFeed,
|
|
394
|
-
candidateDelivery,
|
|
395
|
-
requestChatAction: payload.requestChatAction && typeof payload.requestChatAction === 'object' && !Array.isArray(payload.requestChatAction)
|
|
396
|
-
? payload.requestChatAction
|
|
397
|
-
: candidateDelivery?.requestChatAction && typeof candidateDelivery.requestChatAction === 'object' && !Array.isArray(candidateDelivery.requestChatAction)
|
|
398
|
-
? candidateDelivery.requestChatAction
|
|
399
|
-
: candidateModelRequestChatAction && typeof candidateModelRequestChatAction === 'object' && !Array.isArray(candidateModelRequestChatAction)
|
|
400
|
-
? candidateModelRequestChatAction
|
|
401
|
-
: null,
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
function projectToolCandidateFeed(payload = {}) {
|
|
406
|
-
const { candidateFeed, candidateDelivery } = resolveCandidateProjectionPayload(payload);
|
|
407
|
-
const candidateSummaries = Array.isArray(candidateDelivery?.candidateSummaries)
|
|
408
|
-
? candidateDelivery.candidateSummaries.map((summary, index) => projectToolCandidateSummary(summary, index))
|
|
409
|
-
: Array.isArray(candidateFeed?.candidates)
|
|
410
|
-
? candidateFeed.candidates.map((candidate, index) => projectToolCandidateSummary({
|
|
411
|
-
candidateId: candidate.candidateId,
|
|
412
|
-
displayName: candidate.profileSummary?.displayName,
|
|
413
|
-
agentCode: normalizeText(candidate.agentCode, candidate.requestChat?.agentCode || null),
|
|
414
|
-
worldRole: candidate.worldRole,
|
|
415
|
-
headline: candidate.profileSummary?.headline,
|
|
416
|
-
online: candidate.online === true,
|
|
417
|
-
rank: candidate.rank,
|
|
418
|
-
score: candidate.score,
|
|
419
|
-
summary: normalizeText(candidate.deliveryReason?.summary, null),
|
|
420
|
-
expiresAt: candidate.expiresAt,
|
|
421
|
-
worldFeedbackSummary: candidate.worldFeedbackSummary,
|
|
422
|
-
}, index))
|
|
423
|
-
: [];
|
|
424
|
-
|
|
425
|
-
return {
|
|
426
|
-
status: normalizeText(
|
|
427
|
-
candidateDelivery?.status,
|
|
428
|
-
normalizeText(candidateFeed?.status, candidateSummaries.length > 0 ? 'candidate_summary_ready' : 'candidate_summary_pending'),
|
|
429
|
-
),
|
|
430
|
-
nextAction: normalizeText(
|
|
431
|
-
candidateDelivery?.nextAction,
|
|
432
|
-
normalizeText(candidateFeed?.nextAction, candidateSummaries.length > 0 ? 'review_candidates_then_request_chat' : 'wait_for_more_candidates'),
|
|
433
|
-
),
|
|
434
|
-
deliveredCandidateCount: normalizeInteger(candidateDelivery?.deliveredCandidateCount, candidateSummaries.length),
|
|
435
|
-
totalCandidateCount: normalizeInteger(
|
|
436
|
-
candidateDelivery?.totalCandidateCount,
|
|
437
|
-
normalizeInteger(candidateFeed?.totalCandidates, candidateSummaries.length),
|
|
438
|
-
),
|
|
439
|
-
remainingCandidateCount: normalizeInteger(candidateDelivery?.remainingCandidateCount, 0),
|
|
440
|
-
candidates: candidateSummaries,
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
function projectToolCandidateFlowResponse(payload = {}, { accountId = null } = {}) {
|
|
445
|
-
const {
|
|
446
|
-
worldId,
|
|
447
|
-
nextAction,
|
|
448
|
-
candidateFeed,
|
|
449
|
-
candidateDelivery,
|
|
450
|
-
requestChatAction,
|
|
451
|
-
} = resolveCandidateProjectionPayload(payload);
|
|
452
|
-
const projectedFeed = projectToolCandidateFeed({ candidateFeed, candidateDelivery });
|
|
453
|
-
const projectedDelivery = projectToolCandidateDeliverySummary(candidateDelivery, { accountId });
|
|
454
|
-
const projectedRequestChatAction = projectRequestChatAction(requestChatAction, { accountId });
|
|
455
|
-
|
|
456
|
-
return {
|
|
457
|
-
worldId: normalizeText(worldId, normalizeText(projectedDelivery?.worldId, null)),
|
|
458
|
-
nextAction: normalizeText(nextAction, normalizeText(projectedFeed?.nextAction, normalizeText(projectedDelivery?.nextAction, null))),
|
|
459
|
-
candidateFeed: projectedFeed,
|
|
460
|
-
requestChatTool: 'claworld_request_chat',
|
|
461
|
-
candidateDelivery: projectedDelivery,
|
|
462
|
-
requestChatAction: projectedRequestChatAction,
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
export function projectToolCandidateFeedResponse(candidateFeedPayload = {}, { accountId = null } = {}) {
|
|
467
|
-
const candidateFlow = projectToolCandidateFlowResponse(candidateFeedPayload, { accountId });
|
|
468
|
-
|
|
469
|
-
return {
|
|
470
|
-
status: normalizeText(candidateFeedPayload.status, normalizeText(candidateFlow.candidateFeed?.status, 'no_candidates_ready')),
|
|
471
|
-
worldId: candidateFlow.worldId,
|
|
472
|
-
accountId: normalizeText(accountId, null),
|
|
473
|
-
nextAction: candidateFlow.nextAction,
|
|
474
|
-
candidateFeed: candidateFlow.candidateFeed,
|
|
475
|
-
requestChatTool: candidateFlow.requestChatTool,
|
|
476
|
-
candidateDelivery: candidateFlow.candidateDelivery,
|
|
477
|
-
requestChatAction: candidateFlow.requestChatAction,
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
export function projectToolJoinWorldResponse(
|
|
482
|
-
joinResult = {},
|
|
483
|
-
{ accountId = null } = {},
|
|
484
|
-
) {
|
|
485
|
-
const candidateFlow = projectToolCandidateFlowResponse(joinResult, { accountId });
|
|
486
|
-
|
|
487
|
-
return {
|
|
488
|
-
status: joinResult.membershipStatus === 'active' ? 'joined' : 'accepted',
|
|
489
|
-
worldId: normalizeText(joinResult.worldId, candidateFlow.worldId),
|
|
490
|
-
accountId: normalizeText(accountId, null),
|
|
491
|
-
worldRole: projectWorldRole(joinResult.worldRole, null),
|
|
492
|
-
membershipStatus: joinResult.membershipStatus || 'unknown',
|
|
493
|
-
participantContextText: normalizeText(
|
|
494
|
-
joinResult.participantContextText,
|
|
495
|
-
joinResult.membership?.participantContextText || null,
|
|
496
|
-
),
|
|
497
|
-
nextAction: normalizeText(joinResult.nextAction, 'review_candidate_feed'),
|
|
498
|
-
candidateFeed: candidateFlow.candidateFeed,
|
|
499
|
-
requestChatTool: candidateFlow.requestChatTool,
|
|
500
|
-
candidateDelivery: candidateFlow.candidateDelivery,
|
|
501
|
-
requestChatAction: candidateFlow.requestChatAction,
|
|
502
|
-
orchestration: projectOrchestration(joinResult.orchestration),
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
export function projectToolCreateWorldResponse(world = {}, { accountId = null } = {}) {
|
|
507
|
-
return {
|
|
508
|
-
worldId: world.worldId,
|
|
509
|
-
accountId: normalizeText(accountId, null),
|
|
510
|
-
displayName: normalizeText(world.displayName, null),
|
|
511
|
-
worldContextText: normalizeText(world.worldContextText, null),
|
|
512
|
-
participantContextField: projectParticipantContextField(world.participantContextField),
|
|
513
|
-
ownerAgentId: normalizeText(world.ownerAgentId, null),
|
|
514
|
-
status: normalizeText(world.status, null),
|
|
515
|
-
enabled: normalizeOptionalBoolean(world.enabled, null),
|
|
516
|
-
worldRole: projectWorldRole(world.worldRole, null),
|
|
517
|
-
ownerJoin:
|
|
518
|
-
world.ownerJoin && typeof world.ownerJoin === 'object'
|
|
519
|
-
? projectToolJoinWorldResponse(world.ownerJoin, { accountId })
|
|
520
|
-
: null,
|
|
521
|
-
schemaVersion: normalizeOptionalInteger(world.schemaVersion, null),
|
|
522
|
-
createdAt: normalizeText(world.createdAt, null),
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
export function projectToolOwnedWorldsResponse(payload = {}, { accountId = null } = {}) {
|
|
527
|
-
const worlds = Array.isArray(payload.items)
|
|
528
|
-
? payload.items.map((world) => ({
|
|
529
|
-
worldId: world.worldId,
|
|
530
|
-
displayName: world.displayName,
|
|
531
|
-
worldContextText: normalizeText(world.worldContextText, null),
|
|
532
|
-
enabled: normalizeOptionalBoolean(world.enabled, null),
|
|
533
|
-
status: normalizeText(world.status, null),
|
|
534
|
-
worldRole: projectWorldRole(world.worldRole, null),
|
|
535
|
-
createdAt: normalizeText(world.createdAt, null),
|
|
536
|
-
updatedAt: normalizeText(world.updatedAt, null),
|
|
537
|
-
broadcast: projectToolBroadcastConfig(world.broadcast),
|
|
538
|
-
stats: projectWorldStats(world.stats),
|
|
539
|
-
}))
|
|
540
|
-
: [];
|
|
541
|
-
|
|
542
|
-
return {
|
|
543
|
-
accountId: normalizeText(accountId, null),
|
|
544
|
-
worlds,
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
export function projectToolManagedWorldResponse(world = {}, { accountId = null } = {}) {
|
|
549
|
-
return {
|
|
550
|
-
worldId: world.worldId,
|
|
551
|
-
accountId: normalizeText(accountId, null),
|
|
552
|
-
displayName: world.displayName,
|
|
553
|
-
worldContextText: normalizeText(world.worldContextText, null),
|
|
554
|
-
ownerAgentId: normalizeText(world.ownerAgentId, null),
|
|
555
|
-
enabled: normalizeOptionalBoolean(world.enabled, null),
|
|
556
|
-
status: normalizeText(world.status, null),
|
|
557
|
-
worldRole: projectWorldRole(world.worldRole, null),
|
|
558
|
-
schemaVersion: normalizeOptionalInteger(world.schemaVersion, null),
|
|
559
|
-
createdAt: normalizeText(world.createdAt, null),
|
|
560
|
-
updatedAt: normalizeText(world.updatedAt, null),
|
|
561
|
-
participantContextField: projectParticipantContextField(world.participantContextField),
|
|
562
|
-
broadcast: projectToolBroadcastConfig(world.broadcast),
|
|
563
|
-
stats: projectWorldStats(world.stats),
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function projectToolWorldBroadcastRequestItem(item = {}) {
|
|
568
|
-
return {
|
|
569
|
-
agentId: normalizeText(item.agentId, null),
|
|
570
|
-
status: normalizeText(item.status, null),
|
|
571
|
-
verdict: normalizeText(item.verdict, null),
|
|
572
|
-
chatRequest: projectChatRequestItem(item.chatRequest),
|
|
573
|
-
kickoff: projectChatRequestKickoff(item.kickoff),
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
function projectToolWorldBroadcastFailureItem(item = {}) {
|
|
578
|
-
return {
|
|
579
|
-
agentId: normalizeText(item.agentId, null),
|
|
580
|
-
status: normalizeText(item.status, 'failed'),
|
|
581
|
-
httpStatus: normalizeOptionalInteger(item.httpStatus, null),
|
|
582
|
-
error: normalizeText(item.error, null),
|
|
583
|
-
reason: normalizeText(item.reason, null),
|
|
584
|
-
message: normalizeText(item.message, null),
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
export function projectToolWorldBroadcastResponse(payload = {}, { accountId = null } = {}) {
|
|
589
|
-
return {
|
|
590
|
-
accountId: normalizeText(accountId, null),
|
|
591
|
-
status: normalizeText(payload.status, null),
|
|
592
|
-
worldId: normalizeText(payload.worldId, null),
|
|
593
|
-
senderAgentId: normalizeText(payload.senderAgentId, null),
|
|
594
|
-
senderRole: projectWorldRole(payload.senderRole, null),
|
|
595
|
-
audience: normalizeText(payload.audience, null),
|
|
596
|
-
excludeSelf: normalizeOptionalBoolean(payload.excludeSelf, null),
|
|
597
|
-
eligibility: normalizeText(payload.eligibility, null),
|
|
598
|
-
broadcastId: normalizeText(payload.broadcastId, null),
|
|
599
|
-
totalTargets: normalizeOptionalInteger(payload.totalTargets, null),
|
|
600
|
-
createdCount: normalizeOptionalInteger(payload.createdCount, null),
|
|
601
|
-
failedCount: normalizeOptionalInteger(payload.failedCount, null),
|
|
602
|
-
pendingCount: normalizeOptionalInteger(payload.pendingCount, null),
|
|
603
|
-
autoAcceptedCount: normalizeOptionalInteger(payload.autoAcceptedCount, null),
|
|
604
|
-
rejectedCount: normalizeOptionalInteger(payload.rejectedCount, null),
|
|
605
|
-
nextAction: normalizeText(payload.nextAction, null),
|
|
606
|
-
requests: Array.isArray(payload.requests)
|
|
607
|
-
? payload.requests.map((item) => projectToolWorldBroadcastRequestItem(item))
|
|
608
|
-
: [],
|
|
609
|
-
failures: Array.isArray(payload.failures)
|
|
610
|
-
? payload.failures.map((item) => projectToolWorldBroadcastFailureItem(item))
|
|
611
|
-
: [],
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function projectToolWorldMembershipSummary(membership = {}) {
|
|
616
|
-
return {
|
|
617
|
-
membershipId: normalizeText(membership.membershipId, null),
|
|
618
|
-
worldId: normalizeText(membership.worldId, null),
|
|
619
|
-
displayName: normalizeText(membership.displayName, null),
|
|
620
|
-
worldContextText: normalizeText(membership.worldContextText, null),
|
|
621
|
-
ownerAgentId: normalizeText(membership.ownerAgentId, null),
|
|
622
|
-
enabled: normalizeOptionalBoolean(membership.enabled, null),
|
|
623
|
-
worldStatus: normalizeText(membership.worldStatus, null),
|
|
624
|
-
worldRole: projectWorldRole(membership.worldRole, null),
|
|
625
|
-
membershipStatus: normalizeText(membership.membershipStatus, null),
|
|
626
|
-
participantContextText: normalizeText(membership.participantContextText, null),
|
|
627
|
-
joinedAt: normalizeText(membership.joinedAt, null),
|
|
628
|
-
updatedAt: normalizeText(membership.updatedAt, null),
|
|
629
|
-
nextAction: normalizeText(membership.nextAction, null),
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
export function projectToolWorldMembershipListResponse(payload = {}, { accountId = null } = {}) {
|
|
634
|
-
return {
|
|
635
|
-
accountId: normalizeText(accountId, null),
|
|
636
|
-
memberships: Array.isArray(payload.items)
|
|
637
|
-
? payload.items.map((membership) => projectToolWorldMembershipSummary(membership))
|
|
638
|
-
: [],
|
|
639
|
-
nextAction: normalizeText(payload.nextAction, null),
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
export function projectToolWorldMembershipResponse(payload = {}, { accountId = null } = {}) {
|
|
644
|
-
return {
|
|
645
|
-
accountId: normalizeText(accountId, null),
|
|
646
|
-
...projectToolWorldMembershipSummary(payload),
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
export function projectToolWorldMemberSearchResponse(payload = {}, { accountId = null } = {}) {
|
|
651
|
-
return {
|
|
652
|
-
accountId: normalizeText(accountId, null),
|
|
653
|
-
status: normalizeText(payload.status, 'no_matches'),
|
|
654
|
-
worldId: normalizeText(payload.worldId, null),
|
|
655
|
-
query: normalizeText(payload.query, null),
|
|
656
|
-
sort: normalizeText(payload.sort, 'match'),
|
|
657
|
-
limit: normalizeInteger(payload.limit, 0),
|
|
658
|
-
totalMatches: normalizeInteger(payload.totalMatches, Array.isArray(payload.items) ? payload.items.length : 0),
|
|
659
|
-
nextAction: normalizeText(payload.nextAction, null),
|
|
660
|
-
members: Array.isArray(payload.items)
|
|
661
|
-
? payload.items.map((item, index) => ({
|
|
662
|
-
candidateId: normalizeText(item.membershipId, `candidate_${index + 1}`),
|
|
663
|
-
displayName: normalizeText(item.displayName, `Candidate ${index + 1}`),
|
|
664
|
-
agentCode: normalizeText(item.agentCode, null)?.toUpperCase() || null,
|
|
665
|
-
headline: normalizeText(item.headline, null),
|
|
666
|
-
online: item.online === true,
|
|
667
|
-
score: normalizeInteger(item.score, 0),
|
|
668
|
-
matchedFieldIds: normalizeStringList(item.matchedFieldIds),
|
|
669
|
-
reasonSummary: normalizeText(item.reasonSummary, null),
|
|
670
|
-
profileSummary: projectCandidateProfileSummary(item.profileSummary || {}),
|
|
671
|
-
worldFeedbackSummary: projectWorldFeedbackSummary(item.worldFeedbackSummary),
|
|
672
|
-
requestChat: projectRequestChatPayload(item.requestChat, { accountId }),
|
|
673
|
-
}))
|
|
674
|
-
: [],
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
export function projectToolFeedbackSubmissionResponse(result = {}) {
|
|
679
|
-
const feedback = result.feedback && typeof result.feedback === 'object' ? result.feedback : {};
|
|
680
|
-
const reporter = feedback.reporter && typeof feedback.reporter === 'object' ? feedback.reporter : {};
|
|
681
|
-
const context = feedback.context && typeof feedback.context === 'object' ? feedback.context : {};
|
|
682
|
-
const runtimeContext = feedback.runtimeContext && typeof feedback.runtimeContext === 'object'
|
|
683
|
-
? feedback.runtimeContext
|
|
684
|
-
: {};
|
|
685
|
-
|
|
686
|
-
return {
|
|
687
|
-
status: normalizeText(result.status, 'recorded'),
|
|
688
|
-
feedbackId: normalizeText(feedback.feedbackId, null),
|
|
689
|
-
category: normalizeText(feedback.category, null),
|
|
690
|
-
impact: normalizeText(feedback.impact, 'medium'),
|
|
691
|
-
title: normalizeText(feedback.title, null),
|
|
692
|
-
accountId: normalizeText(feedback.accountId, null),
|
|
693
|
-
reporterAgentId: normalizeText(reporter.agentId, null),
|
|
694
|
-
reporterIdentity: normalizeText(reporter.publicIdentity?.displayIdentity, null),
|
|
695
|
-
worldId: normalizeText(context.worldId, null),
|
|
696
|
-
conversationKey: normalizeText(context.conversationKey, null),
|
|
697
|
-
turnId: normalizeText(context.turnId, null),
|
|
698
|
-
deliveryId: normalizeText(context.deliveryId, null),
|
|
699
|
-
tags: normalizeStringList(context.tags),
|
|
700
|
-
createdAt: normalizeText(feedback.createdAt, null),
|
|
701
|
-
runtime: {
|
|
702
|
-
channelId: normalizeText(runtimeContext.channelId, null),
|
|
703
|
-
toolName: normalizeText(runtimeContext.toolName, null),
|
|
704
|
-
toolCallId: normalizeText(runtimeContext.toolCallId, null),
|
|
705
|
-
pluginVersion: normalizeText(runtimeContext.pluginVersion, null),
|
|
706
|
-
},
|
|
707
|
-
nextAction: 'keep_feedback_id_for_follow_up',
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
function projectToolAgentSummary(agent = {}) {
|
|
712
|
-
if (!agent || typeof agent !== 'object') return null;
|
|
713
|
-
return {
|
|
714
|
-
agentId: normalizeText(agent.agentId, null),
|
|
715
|
-
displayName: normalizeText(agent.displayName, null),
|
|
716
|
-
identity: normalizeText(agent.publicIdentity?.displayIdentity, null),
|
|
717
|
-
online: agent.online === true,
|
|
718
|
-
discoverable: typeof agent.discoverable === 'boolean' ? agent.discoverable : null,
|
|
719
|
-
contactable: typeof agent.contactable === 'boolean' ? agent.contactable : null,
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
function projectToolWorldSummary(world = {}) {
|
|
724
|
-
if (!world || typeof world !== 'object') return null;
|
|
725
|
-
return {
|
|
726
|
-
worldId: normalizeText(world.worldId, null),
|
|
727
|
-
slug: normalizeText(world.slug, null),
|
|
728
|
-
displayName: normalizeText(world.displayName, null),
|
|
729
|
-
summary: normalizeText(world.summary, null),
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
function normalizeConversationScopeDetails(input = {}) {
|
|
734
|
-
const conversation = input && typeof input === 'object' && !Array.isArray(input) ? input : {};
|
|
735
|
-
const worldId = normalizeText(conversation.worldId, null);
|
|
736
|
-
return {
|
|
737
|
-
mode: worldId ? 'world' : 'direct',
|
|
738
|
-
worldId,
|
|
739
|
-
world: projectToolWorldSummary(conversation.world),
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
function projectChatRequestKickoff(kickoff = {}) {
|
|
744
|
-
const normalizedKickoff = normalizeAcceptedChatKickoffRecord(kickoff, { fallbackStatus: 'skipped' });
|
|
745
|
-
if (!normalizedKickoff) return null;
|
|
746
|
-
return {
|
|
747
|
-
status: normalizeText(normalizedKickoff.status, 'skipped'),
|
|
748
|
-
deliveredAt: normalizeText(normalizedKickoff.deliveredAt, null),
|
|
749
|
-
senderKickoffDeliveredAt: normalizeText(
|
|
750
|
-
normalizedKickoff.senderKickoffDeliveredAt,
|
|
751
|
-
normalizeText(normalizedKickoff.deliveredAt, null),
|
|
752
|
-
),
|
|
753
|
-
openerAcceptedAt: normalizeText(normalizedKickoff.openerAcceptedAt, null),
|
|
754
|
-
openerDeliveredAt: normalizeText(normalizedKickoff.openerDeliveredAt, null),
|
|
755
|
-
liveChatEstablishedAt: normalizeText(normalizedKickoff.liveChatEstablishedAt, null),
|
|
756
|
-
conversationKey: normalizeText(normalizedKickoff.conversationKey, null),
|
|
757
|
-
localSessionKey: normalizeText(
|
|
758
|
-
normalizedKickoff.localSessionKey,
|
|
759
|
-
normalizeText(normalizedKickoff.sessionKey, null),
|
|
760
|
-
),
|
|
761
|
-
turnId: normalizeText(normalizedKickoff.turnId, null),
|
|
762
|
-
deliveryId: normalizeText(normalizedKickoff.deliveryId, null),
|
|
763
|
-
created: typeof normalizedKickoff.created === 'boolean' ? normalizedKickoff.created : null,
|
|
764
|
-
reason: normalizeText(normalizedKickoff.reason, null),
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function projectChatRequestOrigin(origin = {}) {
|
|
769
|
-
if (!origin || typeof origin !== 'object' || Array.isArray(origin)) return null;
|
|
770
|
-
return {
|
|
771
|
-
type: normalizeText(origin.type, 'chat_request'),
|
|
772
|
-
broadcastId: normalizeText(origin.broadcastId, null),
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
function projectChatRequestItem(request = {}) {
|
|
777
|
-
if (!request || typeof request !== 'object') return null;
|
|
778
|
-
const requestContext = request.requestContext && typeof request.requestContext === 'object' && !Array.isArray(request.requestContext)
|
|
779
|
-
? request.requestContext
|
|
780
|
-
: {};
|
|
781
|
-
const kickoffBrief = request.kickoffBrief && typeof request.kickoffBrief === 'object' && !Array.isArray(request.kickoffBrief)
|
|
782
|
-
? request.kickoffBrief
|
|
783
|
-
: requestContext.kickoffBrief && typeof requestContext.kickoffBrief === 'object' && !Array.isArray(requestContext.kickoffBrief)
|
|
784
|
-
? requestContext.kickoffBrief
|
|
785
|
-
: null;
|
|
786
|
-
const conversation = normalizeConversationScopeDetails(
|
|
787
|
-
request.conversation && typeof request.conversation === 'object' && !Array.isArray(request.conversation)
|
|
788
|
-
? request.conversation
|
|
789
|
-
: requestContext.conversation,
|
|
790
|
-
);
|
|
791
|
-
return {
|
|
792
|
-
chatRequestId: normalizeText(request.chatRequestId || request.requestId, null),
|
|
793
|
-
status: normalizeText(request.status, 'pending'),
|
|
794
|
-
direction: normalizeText(request.direction, null),
|
|
795
|
-
openingMessage: normalizeText(
|
|
796
|
-
request.openingMessage,
|
|
797
|
-
normalizeText(kickoffBrief?.text, normalizeText(requestContext.openingPayload?.text, normalizeText(requestContext.message, null))),
|
|
798
|
-
),
|
|
799
|
-
kickoffBrief: kickoffBrief
|
|
800
|
-
? {
|
|
801
|
-
text: normalizeText(kickoffBrief.text, null),
|
|
802
|
-
payload: kickoffBrief.payload && typeof kickoffBrief.payload === 'object' && !Array.isArray(kickoffBrief.payload)
|
|
803
|
-
? kickoffBrief.payload
|
|
804
|
-
: null,
|
|
805
|
-
source: normalizeText(kickoffBrief.source, 'chat_request_brief'),
|
|
806
|
-
}
|
|
807
|
-
: null,
|
|
808
|
-
createdAt: normalizeText(request.createdAt, null),
|
|
809
|
-
respondedAt: normalizeText(request.respondedAt, null),
|
|
810
|
-
expiresAt: normalizeText(request.expiresAt, null),
|
|
811
|
-
origin: projectChatRequestOrigin(request.origin),
|
|
812
|
-
fromAgent: projectToolAgentSummary(request.fromAgent),
|
|
813
|
-
toAgent: projectToolAgentSummary(request.toAgent),
|
|
814
|
-
counterparty: projectToolAgentSummary(request.counterparty),
|
|
815
|
-
conversation,
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
function projectChatInboxChatItem(chat = {}) {
|
|
820
|
-
if (!chat || typeof chat !== 'object' || Array.isArray(chat)) return null;
|
|
821
|
-
return {
|
|
822
|
-
chatRequestId: normalizeText(chat.chatRequestId, null),
|
|
823
|
-
status: normalizeText(chat.status, null),
|
|
824
|
-
direction: normalizeText(chat.direction, null),
|
|
825
|
-
createdAt: normalizeText(chat.createdAt, null),
|
|
826
|
-
updatedAt: normalizeText(chat.updatedAt, null),
|
|
827
|
-
lastTurnAt: normalizeText(chat.lastTurnAt, null),
|
|
828
|
-
conversationKey: normalizeText(chat.conversationKey, null),
|
|
829
|
-
localSessionKey: normalizeText(chat.localSessionKey, normalizeText(chat.sessionKey, null)),
|
|
830
|
-
turnCount: normalizeInteger(chat.turnCount, null),
|
|
831
|
-
counterparty: projectToolAgentSummary(chat.counterparty),
|
|
832
|
-
conversation: normalizeConversationScopeDetails(chat.conversation),
|
|
833
|
-
feedbackSummary: projectConversationFeedbackSummary(chat.feedbackSummary),
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
function projectChatInboxFilters(filters = {}) {
|
|
838
|
-
if (!filters || typeof filters !== 'object' || Array.isArray(filters)) return {};
|
|
839
|
-
const projected = {
|
|
840
|
-
direction: normalizeText(filters.direction, null),
|
|
841
|
-
mode: normalizeText(filters.mode, null),
|
|
842
|
-
status: normalizeText(filters.status, null),
|
|
843
|
-
worldId: normalizeText(filters.worldId, null),
|
|
844
|
-
chatRequestId: normalizeText(filters.chatRequestId, null),
|
|
845
|
-
conversationKey: normalizeText(filters.conversationKey, null),
|
|
846
|
-
localSessionKey: normalizeText(filters.localSessionKey, null),
|
|
847
|
-
counterpartyAgentId: normalizeText(filters.counterpartyAgentId, null),
|
|
848
|
-
};
|
|
849
|
-
return Object.fromEntries(
|
|
850
|
-
Object.entries(projected).filter(([, value]) => value != null),
|
|
851
|
-
);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
function projectChatInboxCountBlock(counts = {}, fallback = {}) {
|
|
855
|
-
return {
|
|
856
|
-
pendingRequestCount: normalizeInteger(counts.pendingRequestCount, fallback.pendingRequestCount ?? 0),
|
|
857
|
-
chatCount: normalizeInteger(counts.chatCount, fallback.chatCount ?? 0),
|
|
858
|
-
chatStatusCounts: counts.chatStatusCounts && typeof counts.chatStatusCounts === 'object' && !Array.isArray(counts.chatStatusCounts)
|
|
859
|
-
? {
|
|
860
|
-
opening: normalizeInteger(counts.chatStatusCounts.opening, 0),
|
|
861
|
-
ending: normalizeInteger(counts.chatStatusCounts.ending, 0),
|
|
862
|
-
active: normalizeInteger(counts.chatStatusCounts.active, 0),
|
|
863
|
-
silent: normalizeInteger(counts.chatStatusCounts.silent, 0),
|
|
864
|
-
kickoff_failed: normalizeInteger(counts.chatStatusCounts.kickoff_failed, 0),
|
|
865
|
-
ended: normalizeInteger(counts.chatStatusCounts.ended, 0),
|
|
866
|
-
}
|
|
867
|
-
: {
|
|
868
|
-
opening: 0,
|
|
869
|
-
ending: 0,
|
|
870
|
-
active: 0,
|
|
871
|
-
silent: 0,
|
|
872
|
-
kickoff_failed: 0,
|
|
873
|
-
ended: 0,
|
|
874
|
-
},
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
export function projectToolChatRequestMutationResponse(result = {}, { accountId = null } = {}) {
|
|
879
|
-
const request = result.chatRequest && typeof result.chatRequest === 'object'
|
|
880
|
-
? result.chatRequest
|
|
881
|
-
: result.request && typeof result.request === 'object'
|
|
882
|
-
? result.request
|
|
883
|
-
: result;
|
|
884
|
-
const projectedRequest = projectChatRequestItem(request);
|
|
885
|
-
const kickoff = projectChatRequestKickoff(result.kickoff || result.request?.kickoff);
|
|
886
|
-
const projectedChat = projectChatInboxChatItem(result.chat);
|
|
887
|
-
const normalizedStatus = normalizeText(result.status, projectedRequest?.status || 'pending');
|
|
888
|
-
return {
|
|
889
|
-
status: normalizedStatus,
|
|
890
|
-
accountId: normalizeText(accountId, null),
|
|
891
|
-
chatRequest: projectedRequest,
|
|
892
|
-
...(projectedChat ? { chat: projectedChat } : {}),
|
|
893
|
-
kickoff,
|
|
894
|
-
nextAction: normalizeText(
|
|
895
|
-
result.nextAction,
|
|
896
|
-
normalizedStatus === 'accepted'
|
|
897
|
-
? kickoff?.status === 'established'
|
|
898
|
-
? 'runtime_owns_live_conversation'
|
|
899
|
-
: kickoff?.status === 'sent'
|
|
900
|
-
? 'wait_for_sender_opener_delivery'
|
|
901
|
-
: kickoff?.status === 'queued'
|
|
902
|
-
? 'wait_for_sender_runtime_availability'
|
|
903
|
-
: kickoff?.status === 'failed'
|
|
904
|
-
? 'backend_kickoff_failed'
|
|
905
|
-
: 'chat_request_accepted_without_opening_message'
|
|
906
|
-
: normalizedStatus === 'pending'
|
|
907
|
-
? 'wait_for_peer_acceptance'
|
|
908
|
-
: 'chat_request_closed',
|
|
909
|
-
),
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
export function projectToolChatInboxResponse(result = {}, { accountId = null } = {}) {
|
|
914
|
-
const pendingRequests = Array.isArray(result.pendingRequests)
|
|
915
|
-
? result.pendingRequests.map((request) => projectChatRequestItem(request)).filter(Boolean)
|
|
916
|
-
: [];
|
|
917
|
-
const chats = Array.isArray(result.chats)
|
|
918
|
-
? result.chats.map((chat) => projectChatInboxChatItem(chat)).filter(Boolean)
|
|
919
|
-
: [];
|
|
920
|
-
const projectedFilters = projectChatInboxFilters(result.filters);
|
|
921
|
-
const globalCounts = projectChatInboxCountBlock(result.counts?.global, {
|
|
922
|
-
pendingRequestCount: pendingRequests.length,
|
|
923
|
-
chatCount: chats.length,
|
|
924
|
-
});
|
|
925
|
-
const filteredCounts = projectChatInboxCountBlock(result.counts?.filtered, {
|
|
926
|
-
pendingRequestCount: pendingRequests.length,
|
|
927
|
-
chatCount: chats.length,
|
|
928
|
-
});
|
|
929
|
-
return {
|
|
930
|
-
accountId: normalizeText(accountId, null),
|
|
931
|
-
filters: projectedFilters,
|
|
932
|
-
counts: {
|
|
933
|
-
global: globalCounts,
|
|
934
|
-
filtered: filteredCounts,
|
|
935
|
-
},
|
|
936
|
-
pendingRequests,
|
|
937
|
-
chats,
|
|
938
|
-
};
|
|
939
|
-
}
|