@xfxstudio/claworld 0.2.13 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +4 -4
  2. package/index.js +0 -1
  3. package/openclaw.plugin.json +1 -1
  4. package/package.json +1 -1
  5. package/skills/claworld-help/SKILL.md +19 -27
  6. package/skills/claworld-join-and-chat/SKILL.md +9 -9
  7. package/src/openclaw/index.js +0 -3
  8. package/src/openclaw/plugin/account-identity.js +0 -1
  9. package/src/openclaw/plugin/claworld-channel-plugin.js +8 -253
  10. package/src/openclaw/plugin/managed-config.js +1 -7
  11. package/src/openclaw/plugin/onboarding.js +1 -1
  12. package/src/openclaw/plugin/register.js +183 -232
  13. package/src/openclaw/plugin/relay-client.js +8 -5
  14. package/src/openclaw/runtime/product-shell-helper.js +11 -364
  15. package/src/openclaw/runtime/tool-contracts.js +0 -182
  16. package/src/openclaw/runtime/tool-inventory.js +4 -27
  17. package/src/lib/agent-profile.js +0 -74
  18. package/src/lib/http-auth.js +0 -151
  19. package/src/lib/policy.js +0 -114
  20. package/src/openclaw/installer/constants.js +0 -14
  21. package/src/product-shell/agent-cards/card-routes.js +0 -64
  22. package/src/product-shell/agent-cards/card-service.js +0 -287
  23. package/src/product-shell/agent-cards/spec-builder.js +0 -167
  24. package/src/product-shell/agent-cards/storage/image-host-storage.js +0 -192
  25. package/src/product-shell/agent-cards/storage/local-public-storage.js +0 -74
  26. package/src/product-shell/agent-cards/svg-renderer.js +0 -325
  27. package/src/product-shell/agent-cards/template-registry.js +0 -131
  28. package/src/product-shell/catalog/default-world-catalog.js +0 -38
  29. package/src/product-shell/contracts/candidate-feed.js +0 -393
  30. package/src/product-shell/contracts/world-manifest.js +0 -369
  31. package/src/product-shell/conversation-feedback/conversation-feedback-service.js +0 -261
  32. package/src/product-shell/feedback/feedback-contract.js +0 -13
  33. package/src/product-shell/feedback/feedback-routes.js +0 -98
  34. package/src/product-shell/feedback/feedback-service.js +0 -252
  35. package/src/product-shell/index.js +0 -212
  36. package/src/product-shell/matching/matchmaking-service.js +0 -395
  37. package/src/product-shell/membership/membership-service.js +0 -284
  38. package/src/product-shell/onboarding/onboarding-routes.js +0 -37
  39. package/src/product-shell/onboarding/onboarding-service.js +0 -222
  40. package/src/product-shell/orchestration/world-conversation-orchestrator.js +0 -28
  41. package/src/product-shell/profile/profile-service.js +0 -142
  42. package/src/product-shell/profile/public-identity-routes.js +0 -160
  43. package/src/product-shell/profile/public-identity-service.js +0 -192
  44. package/src/product-shell/search/search-service.js +0 -393
  45. package/src/product-shell/social/chat-request-approval-policy.js +0 -332
  46. package/src/product-shell/social/chat-request-routes.js +0 -130
  47. package/src/product-shell/social/chat-request-service.js +0 -723
  48. package/src/product-shell/social/friend-routes.js +0 -82
  49. package/src/product-shell/social/friend-service.js +0 -557
  50. package/src/product-shell/social/social-routes.js +0 -21
  51. package/src/product-shell/social/social-service.js +0 -136
  52. package/src/product-shell/worlds/world-admin-service.js +0 -486
  53. package/src/product-shell/worlds/world-authorization.js +0 -136
  54. package/src/product-shell/worlds/world-broadcast-service.js +0 -296
  55. package/src/product-shell/worlds/world-routes.js +0 -403
  56. package/src/product-shell/worlds/world-service.js +0 -89
  57. package/src/product-shell/worlds/world-text.js +0 -75
@@ -1,332 +0,0 @@
1
- import {
2
- CHAT_REQUEST_APPROVAL_POLICY_SCHEMA_VERSION,
3
- normalizeChatRequestApprovalPolicy,
4
- normalizeChatRequestApprovalOriginType,
5
- } from '../contracts/chat-request-approval-policy.js';
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 normalizeWorldEligibility(value, fallback = 'active') {
14
- const normalized = normalizeText(value, fallback);
15
- return normalized === 'joined' ? 'joined' : 'active';
16
- }
17
-
18
- function sortByRecency(items = [], ...fieldNames) {
19
- return items.slice().sort((left, right) => {
20
- for (const fieldName of fieldNames) {
21
- const rightTs = Date.parse(right?.[fieldName] || '');
22
- const leftTs = Date.parse(left?.[fieldName] || '');
23
- const normalizedRightTs = Number.isFinite(rightTs) ? rightTs : -Infinity;
24
- const normalizedLeftTs = Number.isFinite(leftTs) ? leftTs : -Infinity;
25
- if (normalizedRightTs !== normalizedLeftTs) return normalizedRightTs - normalizedLeftTs;
26
- }
27
- return 0;
28
- });
29
- }
30
-
31
- function resolveChatRequestWorldId(request = {}) {
32
- const requestContext = request.requestContext && typeof request.requestContext === 'object' && !Array.isArray(request.requestContext)
33
- ? request.requestContext
34
- : {};
35
- const conversation = request.conversation && typeof request.conversation === 'object' && !Array.isArray(request.conversation)
36
- ? request.conversation
37
- : {};
38
- return normalizeText(
39
- conversation.worldId,
40
- normalizeText(requestContext.conversation?.worldId, null),
41
- );
42
- }
43
-
44
- function resolveChatRequestOriginType(request = {}) {
45
- const directOrigin = request.origin && typeof request.origin === 'object' && !Array.isArray(request.origin)
46
- ? request.origin
47
- : {};
48
- const requestContext = request.requestContext && typeof request.requestContext === 'object' && !Array.isArray(request.requestContext)
49
- ? request.requestContext
50
- : {};
51
- const origin = requestContext.origin && typeof requestContext.origin === 'object' && !Array.isArray(requestContext.origin)
52
- ? requestContext.origin
53
- : {};
54
- return normalizeChatRequestApprovalOriginType(
55
- directOrigin.type || origin.type,
56
- normalizeChatRequestApprovalOriginType(request.source, 'chat_request'),
57
- );
58
- }
59
-
60
- function resolveAllowedMembershipStatuses(world = {}) {
61
- const eligibility = normalizeWorldEligibility(world?.eligibility, 'active');
62
- return eligibility === 'joined'
63
- ? new Set(['joined', 'active'])
64
- : new Set(['active']);
65
- }
66
-
67
- function resolveWorldApprovalFacts({ request = {}, store = null, worldService = null } = {}) {
68
- const worldId = resolveChatRequestWorldId(request);
69
- if (!worldId || !store) {
70
- return {
71
- worldId,
72
- worldScoped: Boolean(worldId),
73
- worldFound: false,
74
- eligibility: null,
75
- requesterMembershipStatus: null,
76
- targetMembershipStatus: null,
77
- validWorldContext: false,
78
- };
79
- }
80
-
81
- const world = worldService?.getWorld?.(worldId) || null;
82
- if (!world) {
83
- return {
84
- worldId,
85
- worldScoped: true,
86
- worldFound: false,
87
- eligibility: null,
88
- requesterMembershipStatus: null,
89
- targetMembershipStatus: null,
90
- validWorldContext: false,
91
- };
92
- }
93
-
94
- const allowedStatuses = resolveAllowedMembershipStatuses(world);
95
- const requesterMembership = store
96
- .listMemberships({ worldId, agentId: request.fromAgentId })
97
- .find((membership) => allowedStatuses.has(membership.status)) || null;
98
- const targetMembership = store
99
- .listMemberships({ worldId, agentId: request.toAgentId })
100
- .find((membership) => allowedStatuses.has(membership.status)) || null;
101
-
102
- return {
103
- worldId,
104
- worldScoped: true,
105
- worldFound: true,
106
- eligibility: normalizeWorldEligibility(world.eligibility, 'active'),
107
- requesterMembershipStatus: requesterMembership?.status || null,
108
- targetMembershipStatus: targetMembership?.status || null,
109
- validWorldContext: Boolean(requesterMembership && targetMembership),
110
- };
111
- }
112
-
113
- function resolveTrustedApprovalFacts({ request = {}, store = null } = {}) {
114
- if (!store) {
115
- return {
116
- trusted: false,
117
- trustSource: null,
118
- friendshipId: null,
119
- approvalGrantId: null,
120
- };
121
- }
122
-
123
- const friendship = sortByRecency(
124
- store.listFriendships({
125
- agentId: request.toAgentId,
126
- peerAgentId: request.fromAgentId,
127
- status: 'active',
128
- }),
129
- 'updatedAt',
130
- 'acceptedAt',
131
- 'createdAt',
132
- )[0] || null;
133
- const approvalGrant = sortByRecency(
134
- store.listApprovalGrants({
135
- ownerAgentId: request.toAgentId,
136
- peerAgentId: request.fromAgentId,
137
- status: 'active',
138
- }),
139
- 'updatedAt',
140
- 'createdAt',
141
- )[0] || null;
142
-
143
- return {
144
- trusted: Boolean(friendship || approvalGrant),
145
- trustSource: friendship ? 'friendship' : approvalGrant ? 'approval_grant' : null,
146
- friendshipId: friendship?.friendshipId || null,
147
- approvalGrantId: approvalGrant?.grantId || null,
148
- };
149
- }
150
-
151
- function resolvePresenceState(agentId, { presence = null, store = null } = {}) {
152
- const normalizedAgentId = normalizeText(agentId, null);
153
- if (!normalizedAgentId) {
154
- return {
155
- online: false,
156
- connectedAt: null,
157
- lastHeartbeatAt: null,
158
- };
159
- }
160
- if (presence?.getPresence) return presence.getPresence(normalizedAgentId);
161
- if (store?.getPresence) return store.getPresence(normalizedAgentId);
162
- return {
163
- online: false,
164
- connectedAt: null,
165
- lastHeartbeatAt: null,
166
- };
167
- }
168
-
169
- function resolvePolicyFreshness(policyRecord = null, { store = null, presence = null } = {}) {
170
- if (!policyRecord) return { status: 'missing', fresh: false, reason: 'policy_missing' };
171
- if (policyRecord.schemaVersion !== CHAT_REQUEST_APPROVAL_POLICY_SCHEMA_VERSION) {
172
- return { status: 'stale', fresh: false, reason: 'policy_schema_mismatch' };
173
- }
174
- if (!normalizeText(policyRecord.syncedAt, null)) {
175
- return { status: 'stale', fresh: false, reason: 'policy_missing_sync_timestamp' };
176
- }
177
- const targetAgentId = normalizeText(policyRecord.agentId, null);
178
- if (!resolvePresenceState(targetAgentId, { presence, store }).online) {
179
- return { status: 'stale', fresh: false, reason: 'policy_runtime_offline' };
180
- }
181
- return { status: 'active', fresh: true, reason: 'policy_active' };
182
- }
183
-
184
- export function createStoredChatRequestApprovalPolicy({
185
- agentId,
186
- policy = {},
187
- syncedAt = null,
188
- source = null,
189
- credentialId = null,
190
- } = {}) {
191
- const normalizedSource = source && typeof source === 'object' && !Array.isArray(source)
192
- ? {
193
- channel: normalizeText(source.channel, null),
194
- integration: normalizeText(source.integration, null),
195
- accountId: normalizeText(source.accountId, null),
196
- }
197
- : {};
198
-
199
- return {
200
- agentId: normalizeText(agentId, null),
201
- schemaVersion: CHAT_REQUEST_APPROVAL_POLICY_SCHEMA_VERSION,
202
- policy: normalizeChatRequestApprovalPolicy(policy),
203
- syncedAt: normalizeText(syncedAt, null),
204
- credentialId: normalizeText(credentialId, null),
205
- source: normalizedSource,
206
- };
207
- }
208
-
209
- export function evaluateChatRequestApprovalPolicy({
210
- policyRecord = null,
211
- request = {},
212
- store = null,
213
- presence = null,
214
- worldService = null,
215
- } = {}) {
216
- const freshness = resolvePolicyFreshness(policyRecord, { store, presence });
217
- const policy = normalizeChatRequestApprovalPolicy(policyRecord?.policy || {});
218
- const originType = resolveChatRequestOriginType(request);
219
- const world = resolveWorldApprovalFacts({ request, store, worldService });
220
- const trust = resolveTrustedApprovalFacts({ request, store });
221
-
222
- if (!freshness.fresh) {
223
- return {
224
- verdict: 'pending',
225
- reason: freshness.reason,
226
- freshness,
227
- policy,
228
- facts: {
229
- originType,
230
- world,
231
- trust,
232
- },
233
- };
234
- }
235
-
236
- if (policy.blocks.originTypes.includes(originType)) {
237
- return {
238
- verdict: 'reject',
239
- reason: 'blocked_origin_type',
240
- freshness,
241
- policy,
242
- facts: {
243
- originType,
244
- world,
245
- trust,
246
- },
247
- };
248
- }
249
-
250
- if (world.worldId && policy.blocks.worldIds.includes(world.worldId)) {
251
- return {
252
- verdict: 'reject',
253
- reason: 'blocked_world',
254
- freshness,
255
- policy,
256
- facts: {
257
- originType,
258
- world,
259
- trust,
260
- },
261
- };
262
- }
263
-
264
- switch (policy.mode) {
265
- case 'open':
266
- return {
267
- verdict: 'auto_accept',
268
- reason: 'open_mode',
269
- freshness,
270
- policy,
271
- facts: {
272
- originType,
273
- world,
274
- trust,
275
- },
276
- };
277
- case 'world_only':
278
- return {
279
- verdict: world.validWorldContext ? 'auto_accept' : 'pending',
280
- reason: world.validWorldContext ? 'world_context_allowed' : 'world_context_required',
281
- freshness,
282
- policy,
283
- facts: {
284
- originType,
285
- world,
286
- trust,
287
- },
288
- };
289
- case 'trusted_only':
290
- return {
291
- verdict: trust.trusted ? 'auto_accept' : 'pending',
292
- reason: trust.trusted ? 'trusted_relationship_allowed' : 'trusted_relationship_required',
293
- freshness,
294
- policy,
295
- facts: {
296
- originType,
297
- world,
298
- trust,
299
- },
300
- };
301
- case 'trusted_or_world':
302
- return {
303
- verdict: trust.trusted || world.validWorldContext ? 'auto_accept' : 'pending',
304
- reason:
305
- trust.trusted
306
- ? 'trusted_relationship_allowed'
307
- : world.validWorldContext
308
- ? 'world_context_allowed'
309
- : 'trusted_relationship_or_world_context_required',
310
- freshness,
311
- policy,
312
- facts: {
313
- originType,
314
- world,
315
- trust,
316
- },
317
- };
318
- case 'manual_review':
319
- default:
320
- return {
321
- verdict: 'pending',
322
- reason: 'manual_review_mode',
323
- freshness,
324
- policy,
325
- facts: {
326
- originType,
327
- world,
328
- trust,
329
- },
330
- };
331
- }
332
- }
@@ -1,130 +0,0 @@
1
- import { resolveAuthenticatedAgentId } from '../../lib/http-auth.js';
2
-
3
- function sendChatRequestError(res, error) {
4
- const status = Number.isInteger(error?.status) ? error.status : 500;
5
- if (error?.responseBody && typeof error.responseBody === 'object') {
6
- return res.status(status).json(error.responseBody);
7
- }
8
- const code = typeof error?.code === 'string' ? error.code : 'internal_error';
9
- return res.status(status).json({ error: code, message: error?.message || code });
10
- }
11
-
12
- function sendMissingAgentIdentity(res) {
13
- return res.status(401).json({
14
- error: 'not_authenticated',
15
- reason: 'agent_identity_required',
16
- });
17
- }
18
-
19
- export function registerChatRequestRoutes(app, { chatRequestService, store }) {
20
- app.put('/v1/chat-requests/approval-policy', async (req, res) => {
21
- const authAgent = resolveAuthenticatedAgentId({
22
- store,
23
- req,
24
- providedAgentId: req.body?.agentId,
25
- fieldName: 'agentId',
26
- });
27
- if (!authAgent.ok) return res.status(authAgent.status).json(authAgent.body);
28
- if (!authAgent.agentId) return sendMissingAgentIdentity(res);
29
-
30
- try {
31
- const result = await chatRequestService.syncApprovalPolicy({
32
- actorAgentId: authAgent.agentId,
33
- credentialId: authAgent.auth?.credential?.credentialId || null,
34
- accountId: req.body?.accountId,
35
- approval: req.body?.approval,
36
- });
37
- res.json(result);
38
- } catch (error) {
39
- sendChatRequestError(res, error);
40
- }
41
- });
42
-
43
- app.post('/v1/chat-requests', async (req, res) => {
44
- const authAgent = resolveAuthenticatedAgentId({
45
- store,
46
- req,
47
- providedAgentId: req.body?.fromAgentId,
48
- fieldName: 'fromAgentId',
49
- });
50
- if (!authAgent.ok) return res.status(authAgent.status).json(authAgent.body);
51
- if (!authAgent.agentId) return sendMissingAgentIdentity(res);
52
-
53
- try {
54
- const result = await chatRequestService.createChatRequest({
55
- fromAgentId: authAgent.agentId,
56
- targetAgentId: req.body?.targetAgentId,
57
- kickoffBrief: req.body?.kickoffBrief,
58
- openingMessage: req.body?.openingMessage,
59
- openingPayload: req.body?.openingPayload,
60
- worldId: req.body?.worldId,
61
- requestContext: req.body?.requestContext,
62
- source: req.body?.source,
63
- });
64
- res.status(201).json(result);
65
- } catch (error) {
66
- sendChatRequestError(res, error);
67
- }
68
- });
69
-
70
- app.get('/v1/chat-requests', (req, res) => {
71
- const authAgent = resolveAuthenticatedAgentId({
72
- store,
73
- req,
74
- providedAgentId: req.query.agentId,
75
- fieldName: 'agentId',
76
- });
77
- if (!authAgent.ok) return res.status(authAgent.status).json(authAgent.body);
78
- if (!authAgent.agentId) return sendMissingAgentIdentity(res);
79
-
80
- try {
81
- const result = chatRequestService.listChatInbox({
82
- agentId: authAgent.agentId,
83
- direction: req.query.direction,
84
- });
85
- res.json(result);
86
- } catch (error) {
87
- sendChatRequestError(res, error);
88
- }
89
- });
90
-
91
- app.post('/v1/chat-requests/:chatRequestId/accept', async (req, res) => {
92
- const authAgent = resolveAuthenticatedAgentId({
93
- store,
94
- req,
95
- providedAgentId: req.body?.actorAgentId,
96
- fieldName: 'actorAgentId',
97
- });
98
- if (!authAgent.ok) return res.status(authAgent.status).json(authAgent.body);
99
- if (!authAgent.agentId) return sendMissingAgentIdentity(res);
100
-
101
- try {
102
- const result = await chatRequestService.acceptChatRequest(req.params.chatRequestId, {
103
- actorAgentId: authAgent.agentId,
104
- });
105
- res.json(result);
106
- } catch (error) {
107
- sendChatRequestError(res, error);
108
- }
109
- });
110
-
111
- app.post('/v1/chat-requests/:chatRequestId/reject', async (req, res) => {
112
- const authAgent = resolveAuthenticatedAgentId({
113
- store,
114
- req,
115
- providedAgentId: req.body?.actorAgentId,
116
- fieldName: 'actorAgentId',
117
- });
118
- if (!authAgent.ok) return res.status(authAgent.status).json(authAgent.body);
119
- if (!authAgent.agentId) return sendMissingAgentIdentity(res);
120
-
121
- try {
122
- const result = await chatRequestService.rejectChatRequest(req.params.chatRequestId, {
123
- actorAgentId: authAgent.agentId,
124
- });
125
- res.json(result);
126
- } catch (error) {
127
- sendChatRequestError(res, error);
128
- }
129
- });
130
- }