@xfxstudio/claworld 2026.5.27-testing.1 → 2026.5.28-testing.2

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.
@@ -0,0 +1,224 @@
1
+ export const SEARCH_ITEM_ENVELOPE_TYPES = Object.freeze([
2
+ 'world',
3
+ 'world_member',
4
+ 'person',
5
+ ]);
6
+
7
+ export const SEARCH_TOOL_SCOPES = Object.freeze([
8
+ 'worlds',
9
+ 'world_members',
10
+ 'people',
11
+ 'mixed',
12
+ ]);
13
+
14
+ export const TERMINAL_PUBLIC_TOOLS = Object.freeze([
15
+ 'claworld_search',
16
+ 'claworld_get_public_profile',
17
+ 'claworld_manage_account',
18
+ 'claworld_manage_worlds',
19
+ 'claworld_manage_conversations',
20
+ ]);
21
+
22
+ export const PUBLIC_TOOL_ACTION_CATALOG = Object.freeze({
23
+ claworld_search: Object.freeze([
24
+ 'worlds',
25
+ 'world_members',
26
+ 'people',
27
+ 'mixed',
28
+ ]),
29
+ claworld_get_public_profile: Object.freeze([
30
+ 'get_profile',
31
+ 'lookup_profile',
32
+ ]),
33
+ claworld_manage_account: Object.freeze([
34
+ 'view_account',
35
+ 'activate_account',
36
+ 'update_display_name',
37
+ 'update_human_profile',
38
+ 'update_agent_profile',
39
+ 'set_discoverability',
40
+ 'set_contactability',
41
+ 'set_chat_policy',
42
+ 'set_proactivity',
43
+ 'subscribe_person',
44
+ 'unsubscribe_person',
45
+ ]),
46
+ claworld_manage_worlds: Object.freeze([
47
+ 'list_owned_worlds',
48
+ 'list_joined_worlds',
49
+ 'get_world',
50
+ 'create_world',
51
+ 'update_world',
52
+ 'join_world',
53
+ 'update_world_profile',
54
+ 'leave_world',
55
+ 'subscribe_world',
56
+ 'unsubscribe_world',
57
+ 'set_world_broadcast_preference',
58
+ 'publish_broadcast',
59
+ 'list_world_activity',
60
+ 'list_broadcast_history',
61
+ 'manage_members',
62
+ 'list_invites',
63
+ 'invite_member',
64
+ 'revoke_invite',
65
+ ]),
66
+ claworld_manage_conversations: Object.freeze([
67
+ 'request',
68
+ 'accept',
69
+ 'reject',
70
+ 'close',
71
+ 'get_state',
72
+ 'list_related',
73
+ ]),
74
+ });
75
+
76
+ export const SEARCH_RESULT_ACTIONS = Object.freeze({
77
+ world: Object.freeze([
78
+ 'open_world_context',
79
+ 'join_world',
80
+ 'subscribe_world',
81
+ ]),
82
+ world_member: Object.freeze([
83
+ 'open_public_profile',
84
+ 'subscribe_person',
85
+ 'request_chat',
86
+ ]),
87
+ person: Object.freeze([
88
+ 'open_public_profile',
89
+ 'subscribe_person',
90
+ 'request_chat',
91
+ ]),
92
+ });
93
+
94
+ export const MODULE_OWNERSHIP_MAP = Object.freeze({
95
+ AccountSurface: Object.freeze({
96
+ ownerTool: 'claworld_manage_account',
97
+ modules: Object.freeze([
98
+ 'src/product-shell/profile/*',
99
+ 'src/lib/agent-profile.js',
100
+ 'src/lib/public-identity.js',
101
+ ]),
102
+ }),
103
+ PublicProfileSurface: Object.freeze({
104
+ ownerTool: 'claworld_get_public_profile',
105
+ modules: Object.freeze([
106
+ 'src/product-shell/profile/public-profile-service.js',
107
+ 'src/product-shell/profile/public-profile-routes.js',
108
+ ]),
109
+ }),
110
+ SearchSurface: Object.freeze({
111
+ ownerTool: 'claworld_search',
112
+ modules: Object.freeze([
113
+ 'src/product-shell/search/*',
114
+ 'src/lib/search/*',
115
+ 'src/lib/store/*',
116
+ 'src/product-shell/contracts/search-item.js',
117
+ ]),
118
+ }),
119
+ WorldSurface: Object.freeze({
120
+ ownerTool: 'claworld_manage_worlds',
121
+ modules: Object.freeze([
122
+ 'src/product-shell/worlds/*',
123
+ 'src/product-shell/membership/*',
124
+ 'src/product-shell/contracts/world-manifest.js',
125
+ ]),
126
+ }),
127
+ ConversationSurface: Object.freeze({
128
+ ownerTool: 'claworld_manage_conversations',
129
+ modules: Object.freeze([
130
+ 'src/product-shell/social/chat-request-service.js',
131
+ 'src/lib/relay/*',
132
+ ]),
133
+ }),
134
+ });
135
+
136
+ function normalizeText(value, fallback = null) {
137
+ if (value == null) return fallback;
138
+ const normalized = String(value).trim();
139
+ return normalized || fallback;
140
+ }
141
+
142
+ function normalizeNumber(value, fallback = 0) {
143
+ const parsed = Number(value);
144
+ return Number.isFinite(parsed) ? parsed : fallback;
145
+ }
146
+
147
+ function normalizeList(values = []) {
148
+ return Array.isArray(values) ? values.filter((value) => normalizeText(value, null)) : [];
149
+ }
150
+
151
+ function isKnownSearchType(type) {
152
+ return SEARCH_ITEM_ENVELOPE_TYPES.includes(type);
153
+ }
154
+
155
+ function assertKnownAction(type, actionName) {
156
+ const allowedActions = SEARCH_RESULT_ACTIONS[type] || [];
157
+ if (!allowedActions.includes(actionName)) {
158
+ throw new Error(`unsupported_search_item_action:${type}:${actionName}`);
159
+ }
160
+ }
161
+
162
+ export function buildSearchItemAction({ name, tool, action = null, scope = null, payload = null } = {}) {
163
+ const normalizedName = normalizeText(name, null);
164
+ const normalizedTool = normalizeText(tool, null);
165
+ if (!normalizedName) throw new Error('search_item_action_name_required');
166
+ if (!TERMINAL_PUBLIC_TOOLS.includes(normalizedTool)) throw new Error(`unsupported_public_tool:${normalizedTool}`);
167
+ if (normalizedTool === 'claworld_search') {
168
+ if (!SEARCH_TOOL_SCOPES.includes(scope)) throw new Error(`unsupported_search_scope:${scope}`);
169
+ return {
170
+ name: normalizedName,
171
+ tool: normalizedTool,
172
+ scope,
173
+ payload: payload && typeof payload === 'object' && !Array.isArray(payload) ? { scope, ...payload } : { scope },
174
+ };
175
+ }
176
+ const normalizedAction = normalizeText(action, null);
177
+ if (!PUBLIC_TOOL_ACTION_CATALOG[normalizedTool]?.includes(normalizedAction)) {
178
+ throw new Error(`unsupported_public_tool_action:${normalizedTool}:${normalizedAction}`);
179
+ }
180
+ return {
181
+ name: normalizedName,
182
+ tool: normalizedTool,
183
+ action: normalizedAction,
184
+ payload: payload && typeof payload === 'object' && !Array.isArray(payload) ? { ...payload } : {},
185
+ };
186
+ }
187
+
188
+ export function buildSearchItemEnvelope({
189
+ type,
190
+ id,
191
+ title,
192
+ subtitle = null,
193
+ summary = null,
194
+ score = 0,
195
+ matchedFieldIds = [],
196
+ visibility = null,
197
+ actions = {},
198
+ subject = null,
199
+ source = null,
200
+ extra = {},
201
+ } = {}) {
202
+ const normalizedType = normalizeText(type, null);
203
+ if (!isKnownSearchType(normalizedType)) throw new Error(`unsupported_search_item_type:${normalizedType}`);
204
+ const normalizedId = normalizeText(id, null);
205
+ if (!normalizedId) throw new Error('search_item_id_required');
206
+ const normalizedTitle = normalizeText(title, normalizedId);
207
+ Object.keys(actions || {}).forEach((actionName) => assertKnownAction(normalizedType, actionName));
208
+ return {
209
+ type: normalizedType,
210
+ itemType: normalizedType,
211
+ resultType: normalizedType,
212
+ id: normalizedId,
213
+ title: normalizedTitle,
214
+ subtitle: normalizeText(subtitle, null),
215
+ summary: normalizeText(summary, null),
216
+ score: normalizeNumber(score, 0),
217
+ matchedFieldIds: normalizeList(matchedFieldIds),
218
+ visibility: visibility && typeof visibility === 'object' && !Array.isArray(visibility) ? { ...visibility } : null,
219
+ actions: { ...actions },
220
+ subject: subject && typeof subject === 'object' && !Array.isArray(subject) ? { ...subject } : null,
221
+ source: source ?? null,
222
+ ...extra,
223
+ };
224
+ }