@shadowob/sdk 0.3.4 → 0.4.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/dist/index.cjs ADDED
@@ -0,0 +1,1195 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ CLIENT_EVENTS: () => import_shared.CLIENT_EVENTS,
34
+ SERVER_EVENTS: () => import_shared.SERVER_EVENTS,
35
+ ShadowClient: () => ShadowClient,
36
+ ShadowSocket: () => ShadowSocket,
37
+ channelRoom: () => channelRoom,
38
+ threadRoom: () => threadRoom,
39
+ userRoom: () => userRoom
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/client.ts
44
+ var ShadowClient = class {
45
+ constructor(baseUrl, token) {
46
+ this.token = token;
47
+ this.baseUrl = baseUrl.replace(/\/api\/?$/, "");
48
+ }
49
+ baseUrl;
50
+ async request(path, init) {
51
+ const url = `${this.baseUrl}${path}`;
52
+ const controller = new AbortController();
53
+ const timeout = setTimeout(() => controller.abort(), 6e4);
54
+ try {
55
+ const res = await fetch(url, {
56
+ ...init,
57
+ signal: init?.signal ?? controller.signal,
58
+ headers: {
59
+ "Content-Type": "application/json",
60
+ Authorization: `Bearer ${this.token}`,
61
+ ...init?.headers
62
+ }
63
+ });
64
+ if (!res.ok) {
65
+ const body = await res.text().catch(() => "");
66
+ throw new Error(
67
+ `Shadow API ${init?.method ?? "GET"} ${path} failed (${res.status}): ${body}`
68
+ );
69
+ }
70
+ return res.json();
71
+ } finally {
72
+ clearTimeout(timeout);
73
+ }
74
+ }
75
+ async requestRaw(path, init) {
76
+ const url = `${this.baseUrl}${path}`;
77
+ const res = await fetch(url, {
78
+ ...init,
79
+ headers: {
80
+ Authorization: `Bearer ${this.token}`,
81
+ ...init?.headers
82
+ }
83
+ });
84
+ if (!res.ok) {
85
+ const body = await res.text().catch(() => "");
86
+ throw new Error(`Shadow API ${init?.method ?? "GET"} ${path} failed (${res.status}): ${body}`);
87
+ }
88
+ return res;
89
+ }
90
+ // ── Auth ──────────────────────────────────────────────────────────────
91
+ async register(data) {
92
+ return this.request("/api/auth/register", {
93
+ method: "POST",
94
+ body: JSON.stringify(data)
95
+ });
96
+ }
97
+ async login(data) {
98
+ return this.request("/api/auth/login", {
99
+ method: "POST",
100
+ body: JSON.stringify(data)
101
+ });
102
+ }
103
+ async refreshToken() {
104
+ return this.request("/api/auth/refresh", { method: "POST" });
105
+ }
106
+ async getMe() {
107
+ return this.request("/api/auth/me");
108
+ }
109
+ async updateProfile(data) {
110
+ return this.request("/api/auth/me", {
111
+ method: "PATCH",
112
+ body: JSON.stringify(data)
113
+ });
114
+ }
115
+ async disconnect() {
116
+ return this.request("/api/auth/disconnect", { method: "POST" });
117
+ }
118
+ // ── Agents ────────────────────────────────────────────────────────────
119
+ async listAgents() {
120
+ return this.request("/api/agents");
121
+ }
122
+ async createAgent(data) {
123
+ return this.request("/api/agents", {
124
+ method: "POST",
125
+ body: JSON.stringify(data)
126
+ });
127
+ }
128
+ async getAgent(agentId) {
129
+ return this.request(`/api/agents/${agentId}`);
130
+ }
131
+ async updateAgent(agentId, data) {
132
+ return this.request(`/api/agents/${agentId}`, {
133
+ method: "PATCH",
134
+ body: JSON.stringify(data)
135
+ });
136
+ }
137
+ async deleteAgent(agentId) {
138
+ return this.request(`/api/agents/${agentId}`, { method: "DELETE" });
139
+ }
140
+ async generateAgentToken(agentId) {
141
+ return this.request(`/api/agents/${agentId}/token`, { method: "POST" });
142
+ }
143
+ async startAgent(agentId) {
144
+ return this.request(`/api/agents/${agentId}/start`, { method: "POST" });
145
+ }
146
+ async stopAgent(agentId) {
147
+ return this.request(`/api/agents/${agentId}/stop`, { method: "POST" });
148
+ }
149
+ async sendHeartbeat(agentId) {
150
+ return this.request(`/api/agents/${agentId}/heartbeat`, {
151
+ method: "POST",
152
+ body: JSON.stringify({})
153
+ });
154
+ }
155
+ async getAgentConfig(agentId) {
156
+ return this.request(`/api/agents/${agentId}/config`);
157
+ }
158
+ // ── Agent Policies ────────────────────────────────────────────────────
159
+ async listPolicies(agentId, serverId) {
160
+ return this.request(`/api/agents/${agentId}/servers/${serverId}/policies`);
161
+ }
162
+ async upsertPolicy(agentId, serverId, data) {
163
+ return this.request(`/api/agents/${agentId}/servers/${serverId}/policies`, {
164
+ method: "PUT",
165
+ body: JSON.stringify(data)
166
+ });
167
+ }
168
+ async deletePolicy(agentId, serverId, channelId) {
169
+ return this.request(`/api/agents/${agentId}/servers/${serverId}/policies/${channelId}`, {
170
+ method: "DELETE"
171
+ });
172
+ }
173
+ // ── Servers ───────────────────────────────────────────────────────────
174
+ async discoverServers() {
175
+ return this.request("/api/servers/discover");
176
+ }
177
+ async getServerByInvite(inviteCode) {
178
+ return this.request(`/api/servers/invite/${encodeURIComponent(inviteCode)}`);
179
+ }
180
+ async createServer(data) {
181
+ return this.request("/api/servers", {
182
+ method: "POST",
183
+ body: JSON.stringify(data)
184
+ });
185
+ }
186
+ async listServers() {
187
+ return this.request("/api/servers");
188
+ }
189
+ async getServer(serverIdOrSlug) {
190
+ return this.request(`/api/servers/${serverIdOrSlug}`);
191
+ }
192
+ async updateServer(serverIdOrSlug, data) {
193
+ return this.request(`/api/servers/${serverIdOrSlug}`, {
194
+ method: "PATCH",
195
+ body: JSON.stringify(data)
196
+ });
197
+ }
198
+ async updateServerHomepage(serverIdOrSlug, homepageHtml) {
199
+ return this.updateServer(serverIdOrSlug, { homepageHtml });
200
+ }
201
+ async deleteServer(serverId) {
202
+ return this.request(`/api/servers/${serverId}`, { method: "DELETE" });
203
+ }
204
+ async joinServer(serverId, inviteCode) {
205
+ return this.request(`/api/servers/${serverId}/join`, {
206
+ method: "POST",
207
+ body: JSON.stringify(inviteCode ? { inviteCode } : {})
208
+ });
209
+ }
210
+ async leaveServer(serverId) {
211
+ return this.request(`/api/servers/${serverId}/leave`, { method: "POST" });
212
+ }
213
+ async getMembers(serverId) {
214
+ return this.request(`/api/servers/${serverId}/members`);
215
+ }
216
+ async updateMember(serverId, userId, data) {
217
+ return this.request(`/api/servers/${serverId}/members/${userId}`, {
218
+ method: "PATCH",
219
+ body: JSON.stringify(data)
220
+ });
221
+ }
222
+ async kickMember(serverId, userId) {
223
+ return this.request(`/api/servers/${serverId}/members/${userId}`, { method: "DELETE" });
224
+ }
225
+ async regenerateInviteCode(serverId) {
226
+ return this.request(`/api/servers/${serverId}/invite`, { method: "POST" });
227
+ }
228
+ async addAgentsToServer(serverId, agentIds) {
229
+ return this.request(`/api/servers/${serverId}/agents`, {
230
+ method: "POST",
231
+ body: JSON.stringify({ agentIds })
232
+ });
233
+ }
234
+ // ── Channels ──────────────────────────────────────────────────────────
235
+ async getServerChannels(serverId) {
236
+ return this.request(`/api/servers/${serverId}/channels`);
237
+ }
238
+ async createChannel(serverId, data) {
239
+ const { description, ...rest } = data;
240
+ const body = { ...rest, ...description !== void 0 ? { topic: description } : {} };
241
+ const ch = await this.request(`/api/servers/${serverId}/channels`, {
242
+ method: "POST",
243
+ body: JSON.stringify(body)
244
+ });
245
+ return { ...ch, description: ch.topic };
246
+ }
247
+ async getChannel(channelId) {
248
+ const ch = await this.request(`/api/channels/${channelId}`);
249
+ return { ...ch, description: ch.topic };
250
+ }
251
+ async getChannelMembers(channelId) {
252
+ return this.request(`/api/channels/${channelId}/members`);
253
+ }
254
+ async updateChannel(channelId, data) {
255
+ const { description, ...rest } = data;
256
+ const body = { ...rest, ...description !== void 0 ? { topic: description } : {} };
257
+ const ch = await this.request(`/api/channels/${channelId}`, {
258
+ method: "PATCH",
259
+ body: JSON.stringify(body)
260
+ });
261
+ return { ...ch, description: ch.topic };
262
+ }
263
+ async deleteChannel(channelId) {
264
+ return this.request(`/api/channels/${channelId}`, { method: "DELETE" });
265
+ }
266
+ async reorderChannels(serverId, channelIds) {
267
+ return this.request(`/api/servers/${serverId}/channels/reorder`, {
268
+ method: "PUT",
269
+ body: JSON.stringify({ channelIds })
270
+ });
271
+ }
272
+ async addChannelMember(channelId, userId) {
273
+ return this.request(`/api/channels/${channelId}/members`, {
274
+ method: "POST",
275
+ body: JSON.stringify({ userId })
276
+ });
277
+ }
278
+ async removeChannelMember(channelId, userId) {
279
+ return this.request(`/api/channels/${channelId}/members/${userId}`, { method: "DELETE" });
280
+ }
281
+ // ── Channel Buddy Policy ─────────────────────────────────────────────
282
+ async setBuddyPolicy(channelId, data) {
283
+ return this.request(`/api/channels/${channelId}/buddy-policy`, {
284
+ method: "PUT",
285
+ body: JSON.stringify(data)
286
+ });
287
+ }
288
+ async getBuddyPolicy(channelId) {
289
+ return this.request(`/api/channels/${channelId}/buddy-policy`);
290
+ }
291
+ // ── Messages ──────────────────────────────────────────────────────────
292
+ async sendMessage(channelId, content, opts) {
293
+ return this.request(`/api/channels/${channelId}/messages`, {
294
+ method: "POST",
295
+ body: JSON.stringify({
296
+ content,
297
+ ...opts?.threadId ? { threadId: opts.threadId } : {},
298
+ ...opts?.replyToId ? { replyToId: opts.replyToId } : {},
299
+ ...opts?.metadata ? { metadata: opts.metadata } : {}
300
+ })
301
+ });
302
+ }
303
+ async getMessages(channelId, limit = 50, cursor) {
304
+ const params = new URLSearchParams({ limit: String(limit) });
305
+ if (cursor) params.set("cursor", cursor);
306
+ return this.request(
307
+ `/api/channels/${channelId}/messages?${params}`
308
+ );
309
+ }
310
+ async getMessage(messageId) {
311
+ return this.request(`/api/messages/${messageId}`);
312
+ }
313
+ async editMessage(messageId, content) {
314
+ return this.request(`/api/messages/${messageId}`, {
315
+ method: "PATCH",
316
+ body: JSON.stringify({ content })
317
+ });
318
+ }
319
+ async deleteMessage(messageId) {
320
+ await this.request(`/api/messages/${messageId}`, {
321
+ method: "DELETE"
322
+ });
323
+ }
324
+ // ── Pins ──────────────────────────────────────────────────────────────
325
+ async pinMessage(messageId, channelId) {
326
+ if (channelId) {
327
+ return this.request(`/api/channels/${channelId}/pins/${messageId}`, { method: "PUT" });
328
+ }
329
+ return this.request(`/api/messages/${messageId}/pin`, { method: "POST" });
330
+ }
331
+ async unpinMessage(messageId, channelId) {
332
+ if (channelId) {
333
+ return this.request(`/api/channels/${channelId}/pins/${messageId}`, { method: "DELETE" });
334
+ }
335
+ return this.request(`/api/messages/${messageId}/pin`, { method: "DELETE" });
336
+ }
337
+ async getPinnedMessages(channelId) {
338
+ return this.request(`/api/channels/${channelId}/pins`);
339
+ }
340
+ // ── Reactions ─────────────────────────────────────────────────────────
341
+ async addReaction(messageId, emoji) {
342
+ await this.request(`/api/messages/${messageId}/reactions`, {
343
+ method: "POST",
344
+ body: JSON.stringify({ emoji })
345
+ });
346
+ }
347
+ async removeReaction(messageId, emoji) {
348
+ await this.request(`/api/messages/${messageId}/reactions/${encodeURIComponent(emoji)}`, {
349
+ method: "DELETE"
350
+ });
351
+ }
352
+ async getReactions(messageId) {
353
+ return this.request(`/api/messages/${messageId}/reactions`);
354
+ }
355
+ // ── Threads ───────────────────────────────────────────────────────────
356
+ async listThreads(channelId) {
357
+ return this.request(`/api/channels/${channelId}/threads`);
358
+ }
359
+ async createThread(channelId, name, parentMessageId) {
360
+ return this.request(`/api/channels/${channelId}/threads`, {
361
+ method: "POST",
362
+ body: JSON.stringify({ name, parentMessageId })
363
+ });
364
+ }
365
+ async getThread(threadId) {
366
+ return this.request(`/api/threads/${threadId}`);
367
+ }
368
+ async updateThread(threadId, data) {
369
+ return this.request(`/api/threads/${threadId}`, {
370
+ method: "PATCH",
371
+ body: JSON.stringify(data)
372
+ });
373
+ }
374
+ async deleteThread(threadId) {
375
+ return this.request(`/api/threads/${threadId}`, { method: "DELETE" });
376
+ }
377
+ async getThreadMessages(threadId, limit = 50, cursor) {
378
+ const params = new URLSearchParams({ limit: String(limit) });
379
+ if (cursor) params.set("cursor", cursor);
380
+ return this.request(`/api/threads/${threadId}/messages?${params}`);
381
+ }
382
+ async sendToThread(threadId, content) {
383
+ return this.request(`/api/threads/${threadId}/messages`, {
384
+ method: "POST",
385
+ body: JSON.stringify({ content })
386
+ });
387
+ }
388
+ // ── DMs ───────────────────────────────────────────────────────────────
389
+ async createDmChannel(userId) {
390
+ return this.request("/api/dm/channels", {
391
+ method: "POST",
392
+ body: JSON.stringify({ userId })
393
+ });
394
+ }
395
+ async listDmChannels() {
396
+ return this.request("/api/dm/channels");
397
+ }
398
+ async getDmMessages(channelId, limit = 50, cursor) {
399
+ const params = new URLSearchParams({ limit: String(limit) });
400
+ if (cursor) params.set("cursor", cursor);
401
+ return this.request(`/api/dm/channels/${channelId}/messages?${params}`);
402
+ }
403
+ async sendDmMessage(channelId, content, options) {
404
+ return this.request(`/api/dm/channels/${channelId}/messages`, {
405
+ method: "POST",
406
+ body: JSON.stringify({
407
+ content,
408
+ replyToId: options?.replyToId,
409
+ ...options?.metadata ? { metadata: options.metadata } : {}
410
+ })
411
+ });
412
+ }
413
+ // ── Notifications ─────────────────────────────────────────────────────
414
+ async listNotifications(limit = 50, offset = 0) {
415
+ const params = new URLSearchParams({ limit: String(limit), offset: String(offset) });
416
+ return this.request(`/api/notifications?${params}`);
417
+ }
418
+ async markNotificationRead(notificationId) {
419
+ return this.request(`/api/notifications/${notificationId}/read`, { method: "PATCH" });
420
+ }
421
+ async markAllNotificationsRead() {
422
+ return this.request("/api/notifications/read-all", { method: "POST" });
423
+ }
424
+ async getUnreadCount() {
425
+ return this.request("/api/notifications/unread-count");
426
+ }
427
+ // ── Search ────────────────────────────────────────────────────────────
428
+ async searchMessages(query) {
429
+ const params = new URLSearchParams({ query: query.q });
430
+ if (query.serverId) params.set("serverId", query.serverId);
431
+ if (query.channelId) params.set("channelId", query.channelId);
432
+ if (query.authorId) params.set("from", query.authorId);
433
+ if (query.limit) params.set("limit", String(query.limit));
434
+ if (query.offset) params.set("offset", String(query.offset));
435
+ const result = await this.request(`/api/search/messages?${params}`);
436
+ if (Array.isArray(result)) {
437
+ return { messages: result, total: result.length };
438
+ }
439
+ return result;
440
+ }
441
+ // ── Invites ───────────────────────────────────────────────────────────
442
+ async listInvites() {
443
+ return this.request("/api/invite-codes");
444
+ }
445
+ async createInvites(count, note) {
446
+ return this.request("/api/invite-codes", {
447
+ method: "POST",
448
+ body: JSON.stringify({ count, ...note ? { note } : {} })
449
+ });
450
+ }
451
+ async deactivateInvite(inviteId) {
452
+ return this.request(`/api/invite-codes/${inviteId}/deactivate`, { method: "PATCH" });
453
+ }
454
+ async deleteInvite(inviteId) {
455
+ return this.request(`/api/invite-codes/${inviteId}`, { method: "DELETE" });
456
+ }
457
+ // ── Media ─────────────────────────────────────────────────────────────
458
+ async uploadMedia(file, filename, contentType, messageId) {
459
+ const formData = new FormData();
460
+ const blob = file instanceof Blob ? file : new Blob([file], { type: contentType });
461
+ formData.append("file", blob, filename);
462
+ if (messageId) {
463
+ formData.append("messageId", messageId);
464
+ }
465
+ const url = `${this.baseUrl}/api/media/upload`;
466
+ const res = await fetch(url, {
467
+ method: "POST",
468
+ headers: {
469
+ Authorization: `Bearer ${this.token}`
470
+ },
471
+ body: formData
472
+ });
473
+ if (!res.ok) {
474
+ const body = await res.text().catch(() => "");
475
+ throw new Error(`Shadow API POST /api/media/upload failed (${res.status}): ${body}`);
476
+ }
477
+ return res.json();
478
+ }
479
+ /**
480
+ * Download a file from a URL and upload it to the Shadow media service.
481
+ * Supports local filesystem paths, file:// URLs, tilde paths, and HTTP(S) URLs.
482
+ */
483
+ async uploadMediaFromUrl(mediaUrl, messageId) {
484
+ const { readFile } = await import("fs/promises");
485
+ const { basename } = await import("path");
486
+ const { homedir } = await import("os");
487
+ let normalizedUrl = mediaUrl.replace(/^\s*MEDIA\s*:\s*/i, "");
488
+ if (normalizedUrl.startsWith("file://")) {
489
+ normalizedUrl = normalizedUrl.replace(/^file:\/\//, "");
490
+ }
491
+ if (normalizedUrl.startsWith("~")) {
492
+ normalizedUrl = normalizedUrl.replace(/^~/, homedir());
493
+ }
494
+ if (!normalizedUrl.startsWith("/") && !normalizedUrl.startsWith("http://") && !normalizedUrl.startsWith("https://") && !normalizedUrl.startsWith("//")) {
495
+ const { existsSync } = await import("fs");
496
+ const { resolve } = await import("path");
497
+ const cwd = globalThis.process ? globalThis.process.cwd() : "/";
498
+ const roots = [resolve(homedir(), ".openclaw", "workspace"), cwd];
499
+ let resolved = false;
500
+ for (const root of roots) {
501
+ const candidate = resolve(root, normalizedUrl);
502
+ if (existsSync(candidate)) {
503
+ normalizedUrl = candidate;
504
+ resolved = true;
505
+ break;
506
+ }
507
+ }
508
+ if (!resolved) {
509
+ normalizedUrl = resolve(cwd, normalizedUrl);
510
+ }
511
+ }
512
+ if (normalizedUrl.startsWith("/") && !normalizedUrl.startsWith("//")) {
513
+ const fileBuffer = await readFile(normalizedUrl);
514
+ const bytes = new Uint8Array(fileBuffer);
515
+ const filename2 = basename(normalizedUrl);
516
+ const ext = filename2.split(".").pop()?.toLowerCase() ?? "";
517
+ const mimeMap = {
518
+ jpg: "image/jpeg",
519
+ jpeg: "image/jpeg",
520
+ png: "image/png",
521
+ gif: "image/gif",
522
+ webp: "image/webp",
523
+ svg: "image/svg+xml",
524
+ mp4: "video/mp4",
525
+ webm: "video/webm",
526
+ mp3: "audio/mpeg",
527
+ wav: "audio/wav",
528
+ ogg: "audio/ogg",
529
+ pdf: "application/pdf",
530
+ txt: "text/plain",
531
+ csv: "text/csv",
532
+ json: "application/json",
533
+ html: "text/html",
534
+ xml: "application/xml",
535
+ zip: "application/zip"
536
+ };
537
+ const contentType2 = mimeMap[ext] ?? "application/octet-stream";
538
+ return this.uploadMedia(
539
+ new Blob([bytes], { type: contentType2 }),
540
+ filename2,
541
+ contentType2,
542
+ messageId
543
+ );
544
+ }
545
+ const res = await fetch(normalizedUrl);
546
+ if (!res.ok) {
547
+ throw new Error(`Failed to download media from ${normalizedUrl}: ${res.status}`);
548
+ }
549
+ const blob = await res.blob();
550
+ const urlPath = new URL(normalizedUrl).pathname;
551
+ const filename = urlPath.split("/").pop() ?? "file";
552
+ const contentType = blob.type || "application/octet-stream";
553
+ return this.uploadMedia(blob, filename, contentType, messageId);
554
+ }
555
+ async downloadFile(fileUrl) {
556
+ const headers = {};
557
+ if (fileUrl.startsWith(this.baseUrl) || fileUrl.startsWith("/")) {
558
+ headers.Authorization = `Bearer ${this.token}`;
559
+ }
560
+ const fullUrl = fileUrl.startsWith("/") ? `${this.baseUrl}${fileUrl}` : fileUrl;
561
+ const res = await fetch(fullUrl, { headers, redirect: "follow" });
562
+ if (!res.ok) {
563
+ throw new Error(`Failed to download file from ${fullUrl}: ${res.status}`);
564
+ }
565
+ const buffer = await res.arrayBuffer();
566
+ const contentType = res.headers.get("content-type") ?? "application/octet-stream";
567
+ const urlPath = new URL(fullUrl).pathname;
568
+ const filename = decodeURIComponent(urlPath.split("/").pop() ?? "file");
569
+ return { buffer, contentType, filename };
570
+ }
571
+ // ── Workspace ─────────────────────────────────────────────────────────
572
+ async getWorkspace(serverId) {
573
+ return this.request(`/api/servers/${serverId}/workspace`);
574
+ }
575
+ async updateWorkspace(serverId, data) {
576
+ return this.request(`/api/servers/${serverId}/workspace`, {
577
+ method: "PATCH",
578
+ body: JSON.stringify(data)
579
+ });
580
+ }
581
+ async getWorkspaceTree(serverId) {
582
+ return this.request(`/api/servers/${serverId}/workspace/tree`);
583
+ }
584
+ async getWorkspaceStats(serverId) {
585
+ return this.request(`/api/servers/${serverId}/workspace/stats`);
586
+ }
587
+ async getWorkspaceChildren(serverId, parentId) {
588
+ const params = new URLSearchParams();
589
+ if (parentId !== void 0 && parentId !== null) params.set("parentId", parentId);
590
+ const qs = params.toString();
591
+ return this.request(`/api/servers/${serverId}/workspace/children${qs ? `?${qs}` : ""}`);
592
+ }
593
+ async batchWorkspaceChildren(serverId, parentIds) {
594
+ return this.request(`/api/servers/${serverId}/workspace/children/batch`, {
595
+ method: "POST",
596
+ body: JSON.stringify({ parentIds })
597
+ });
598
+ }
599
+ async createWorkspaceFolder(serverId, data) {
600
+ return this.request(`/api/servers/${serverId}/workspace/folders`, {
601
+ method: "POST",
602
+ body: JSON.stringify(data)
603
+ });
604
+ }
605
+ async updateWorkspaceFolder(serverId, folderId, data) {
606
+ return this.request(`/api/servers/${serverId}/workspace/folders/${folderId}`, {
607
+ method: "PATCH",
608
+ body: JSON.stringify(data)
609
+ });
610
+ }
611
+ async deleteWorkspaceFolder(serverId, folderId) {
612
+ return this.request(`/api/servers/${serverId}/workspace/folders/${folderId}`, {
613
+ method: "DELETE"
614
+ });
615
+ }
616
+ async searchWorkspaceFolders(serverId, query) {
617
+ const params = new URLSearchParams();
618
+ if (query.searchText) params.set("searchText", query.searchText);
619
+ if (query.limit) params.set("limit", String(query.limit));
620
+ return this.request(`/api/servers/${serverId}/workspace/folders/search?${params}`);
621
+ }
622
+ async createWorkspaceFile(serverId, data) {
623
+ return this.request(`/api/servers/${serverId}/workspace/files`, {
624
+ method: "POST",
625
+ body: JSON.stringify(data)
626
+ });
627
+ }
628
+ async searchWorkspaceFiles(serverId, query) {
629
+ const params = new URLSearchParams();
630
+ if (query.parentId) params.set("parentId", query.parentId);
631
+ if (query.searchText) params.set("searchText", query.searchText);
632
+ if (query.ext) params.set("ext", query.ext);
633
+ if (query.limit) params.set("limit", String(query.limit));
634
+ if (query.offset) params.set("offset", String(query.offset));
635
+ return this.request(`/api/servers/${serverId}/workspace/files/search?${params}`);
636
+ }
637
+ async getWorkspaceFile(serverId, fileId) {
638
+ return this.request(`/api/servers/${serverId}/workspace/files/${fileId}`);
639
+ }
640
+ async updateWorkspaceFile(serverId, fileId, data) {
641
+ return this.request(`/api/servers/${serverId}/workspace/files/${fileId}`, {
642
+ method: "PATCH",
643
+ body: JSON.stringify(data)
644
+ });
645
+ }
646
+ async deleteWorkspaceFile(serverId, fileId) {
647
+ return this.request(`/api/servers/${serverId}/workspace/files/${fileId}`, { method: "DELETE" });
648
+ }
649
+ async cloneWorkspaceFile(serverId, fileId) {
650
+ return this.request(`/api/servers/${serverId}/workspace/files/${fileId}/clone`, {
651
+ method: "POST"
652
+ });
653
+ }
654
+ async pasteWorkspaceNodes(serverId, data) {
655
+ return this.request(`/api/servers/${serverId}/workspace/nodes/paste`, {
656
+ method: "POST",
657
+ body: JSON.stringify(data)
658
+ });
659
+ }
660
+ async executeWorkspaceCommands(serverId, commands) {
661
+ return this.request(`/api/servers/${serverId}/workspace/commands`, {
662
+ method: "POST",
663
+ body: JSON.stringify({ commands })
664
+ });
665
+ }
666
+ async uploadWorkspaceFile(serverId, file, filename, parentId) {
667
+ const formData = new FormData();
668
+ formData.append("file", file, filename);
669
+ if (parentId) formData.append("parentId", parentId);
670
+ const res = await this.requestRaw(`/api/servers/${serverId}/workspace/upload`, {
671
+ method: "POST",
672
+ body: formData
673
+ });
674
+ return res.json();
675
+ }
676
+ async downloadWorkspace(serverId) {
677
+ const res = await this.requestRaw(`/api/servers/${serverId}/workspace/download`);
678
+ return res.arrayBuffer();
679
+ }
680
+ async downloadWorkspaceFolder(serverId, folderId) {
681
+ const res = await this.requestRaw(
682
+ `/api/servers/${serverId}/workspace/folders/${folderId}/download`
683
+ );
684
+ return res.arrayBuffer();
685
+ }
686
+ // ── Auth (extended) ───────────────────────────────────────────────────
687
+ async getUserProfile(userId) {
688
+ return this.request(`/api/auth/users/${userId}`);
689
+ }
690
+ async listOAuthAccounts() {
691
+ return this.request("/api/auth/oauth/accounts");
692
+ }
693
+ async unlinkOAuthAccount(accountId) {
694
+ return this.request(`/api/auth/oauth/accounts/${accountId}`, { method: "DELETE" });
695
+ }
696
+ // ── Friendships ───────────────────────────────────────────────────────
697
+ async sendFriendRequest(username) {
698
+ return this.request("/api/friends/request", {
699
+ method: "POST",
700
+ body: JSON.stringify({ username })
701
+ });
702
+ }
703
+ async acceptFriendRequest(requestId) {
704
+ return this.request(`/api/friends/${requestId}/accept`, { method: "POST" });
705
+ }
706
+ async rejectFriendRequest(requestId) {
707
+ return this.request(`/api/friends/${requestId}/reject`, { method: "POST" });
708
+ }
709
+ async removeFriend(friendshipId) {
710
+ return this.request(`/api/friends/${friendshipId}`, { method: "DELETE" });
711
+ }
712
+ async listFriends() {
713
+ return this.request("/api/friends");
714
+ }
715
+ async listPendingFriendRequests() {
716
+ return this.request("/api/friends/pending");
717
+ }
718
+ async listSentFriendRequests() {
719
+ return this.request("/api/friends/sent");
720
+ }
721
+ // ── Notifications (extended) ──────────────────────────────────────────
722
+ async markScopeRead(scope) {
723
+ return this.request("/api/notifications/read-scope", {
724
+ method: "POST",
725
+ body: JSON.stringify(scope)
726
+ });
727
+ }
728
+ async getScopedUnread() {
729
+ return this.request("/api/notifications/scoped-unread");
730
+ }
731
+ async getNotificationPreferences() {
732
+ return this.request("/api/notifications/preferences");
733
+ }
734
+ async updateNotificationPreferences(data) {
735
+ return this.request("/api/notifications/preferences", {
736
+ method: "PATCH",
737
+ body: JSON.stringify(data)
738
+ });
739
+ }
740
+ // ── OAuth Apps ────────────────────────────────────────────────────────
741
+ async createOAuthApp(data) {
742
+ return this.request("/api/oauth/apps", {
743
+ method: "POST",
744
+ body: JSON.stringify(data)
745
+ });
746
+ }
747
+ async listOAuthApps() {
748
+ return this.request("/api/oauth/apps");
749
+ }
750
+ async updateOAuthApp(appId, data) {
751
+ return this.request(`/api/oauth/apps/${appId}`, {
752
+ method: "PATCH",
753
+ body: JSON.stringify(data)
754
+ });
755
+ }
756
+ async deleteOAuthApp(appId) {
757
+ return this.request(`/api/oauth/apps/${appId}`, { method: "DELETE" });
758
+ }
759
+ async resetOAuthAppSecret(appId) {
760
+ return this.request(`/api/oauth/apps/${appId}/reset-secret`, { method: "POST" });
761
+ }
762
+ async getOAuthAuthorization(params) {
763
+ const qs = new URLSearchParams(params);
764
+ return this.request(`/api/oauth/authorize?${qs}`);
765
+ }
766
+ async approveOAuthAuthorization(data) {
767
+ return this.request("/api/oauth/authorize", {
768
+ method: "POST",
769
+ body: JSON.stringify(data)
770
+ });
771
+ }
772
+ async exchangeOAuthToken(data) {
773
+ return this.request("/api/oauth/token", {
774
+ method: "POST",
775
+ body: JSON.stringify(data)
776
+ });
777
+ }
778
+ async listOAuthConsents() {
779
+ return this.request("/api/oauth/consents");
780
+ }
781
+ async revokeOAuthConsent(appId) {
782
+ return this.request("/api/oauth/revoke", {
783
+ method: "POST",
784
+ body: JSON.stringify({ appId })
785
+ });
786
+ }
787
+ // ── Marketplace / Rentals ─────────────────────────────────────────────
788
+ async browseListings(params) {
789
+ const qs = new URLSearchParams();
790
+ if (params?.search) qs.set("search", params.search);
791
+ if (params?.tags) for (const t of params.tags) qs.append("tags", t);
792
+ if (params?.minPrice != null) qs.set("minPrice", String(params.minPrice));
793
+ if (params?.maxPrice != null) qs.set("maxPrice", String(params.maxPrice));
794
+ if (params?.limit) qs.set("limit", String(params.limit));
795
+ if (params?.offset) qs.set("offset", String(params.offset));
796
+ return this.request(`/api/marketplace/listings?${qs}`);
797
+ }
798
+ async getListing(listingId) {
799
+ return this.request(`/api/marketplace/listings/${listingId}`);
800
+ }
801
+ async estimateRentalCost(listingId, hours) {
802
+ const qs = new URLSearchParams({ hours: String(hours) });
803
+ return this.request(`/api/marketplace/listings/${listingId}/estimate?${qs}`);
804
+ }
805
+ async listMyListings() {
806
+ return this.request("/api/marketplace/my-listings");
807
+ }
808
+ async createListing(data) {
809
+ return this.request("/api/marketplace/listings", {
810
+ method: "POST",
811
+ body: JSON.stringify(data)
812
+ });
813
+ }
814
+ async updateListing(listingId, data) {
815
+ return this.request(`/api/marketplace/listings/${listingId}`, {
816
+ method: "PUT",
817
+ body: JSON.stringify(data)
818
+ });
819
+ }
820
+ async toggleListing(listingId) {
821
+ return this.request(`/api/marketplace/listings/${listingId}/toggle`, { method: "PUT" });
822
+ }
823
+ async deleteListing(listingId) {
824
+ return this.request(`/api/marketplace/listings/${listingId}`, { method: "DELETE" });
825
+ }
826
+ async signContract(data) {
827
+ return this.request("/api/marketplace/contracts", {
828
+ method: "POST",
829
+ body: JSON.stringify(data)
830
+ });
831
+ }
832
+ async listContracts(params) {
833
+ const qs = new URLSearchParams();
834
+ if (params?.role) qs.set("role", params.role);
835
+ if (params?.status) qs.set("status", params.status);
836
+ return this.request(`/api/marketplace/contracts?${qs}`);
837
+ }
838
+ async getContract(contractId) {
839
+ return this.request(`/api/marketplace/contracts/${contractId}`);
840
+ }
841
+ async terminateContract(contractId) {
842
+ return this.request(`/api/marketplace/contracts/${contractId}/terminate`, { method: "POST" });
843
+ }
844
+ async recordUsageSession(contractId, data) {
845
+ return this.request(`/api/marketplace/contracts/${contractId}/usage`, {
846
+ method: "POST",
847
+ body: JSON.stringify(data)
848
+ });
849
+ }
850
+ async reportViolation(contractId, data) {
851
+ return this.request(`/api/marketplace/contracts/${contractId}/violate`, {
852
+ method: "POST",
853
+ body: JSON.stringify(data)
854
+ });
855
+ }
856
+ // ── Shop ──────────────────────────────────────────────────────────────
857
+ async getShop(serverId) {
858
+ return this.request(`/api/servers/${serverId}/shop`);
859
+ }
860
+ async updateShop(serverId, data) {
861
+ return this.request(`/api/servers/${serverId}/shop`, {
862
+ method: "PUT",
863
+ body: JSON.stringify(data)
864
+ });
865
+ }
866
+ async listCategories(serverId) {
867
+ return this.request(`/api/servers/${serverId}/shop/categories`);
868
+ }
869
+ async createCategory(serverId, data) {
870
+ return this.request(`/api/servers/${serverId}/shop/categories`, {
871
+ method: "POST",
872
+ body: JSON.stringify(data)
873
+ });
874
+ }
875
+ async updateCategory(serverId, categoryId, data) {
876
+ return this.request(`/api/servers/${serverId}/shop/categories/${categoryId}`, {
877
+ method: "PUT",
878
+ body: JSON.stringify(data)
879
+ });
880
+ }
881
+ async deleteCategory(serverId, categoryId) {
882
+ return this.request(`/api/servers/${serverId}/shop/categories/${categoryId}`, {
883
+ method: "DELETE"
884
+ });
885
+ }
886
+ async listProducts(serverId, params) {
887
+ const qs = new URLSearchParams();
888
+ if (params?.status) qs.set("status", params.status);
889
+ if (params?.categoryId) qs.set("categoryId", params.categoryId);
890
+ if (params?.keyword) qs.set("keyword", params.keyword);
891
+ if (params?.limit) qs.set("limit", String(params.limit));
892
+ if (params?.offset) qs.set("offset", String(params.offset));
893
+ return this.request(`/api/servers/${serverId}/shop/products?${qs}`);
894
+ }
895
+ async getProduct(serverId, productId) {
896
+ return this.request(`/api/servers/${serverId}/shop/products/${productId}`);
897
+ }
898
+ async createProduct(serverId, data) {
899
+ return this.request(`/api/servers/${serverId}/shop/products`, {
900
+ method: "POST",
901
+ body: JSON.stringify(data)
902
+ });
903
+ }
904
+ async updateProduct(serverId, productId, data) {
905
+ return this.request(`/api/servers/${serverId}/shop/products/${productId}`, {
906
+ method: "PUT",
907
+ body: JSON.stringify(data)
908
+ });
909
+ }
910
+ async deleteProduct(serverId, productId) {
911
+ return this.request(`/api/servers/${serverId}/shop/products/${productId}`, { method: "DELETE" });
912
+ }
913
+ async getCart(serverId) {
914
+ return this.request(`/api/servers/${serverId}/shop/cart`);
915
+ }
916
+ async addToCart(serverId, data) {
917
+ return this.request(`/api/servers/${serverId}/shop/cart`, {
918
+ method: "POST",
919
+ body: JSON.stringify(data)
920
+ });
921
+ }
922
+ async updateCartItem(serverId, itemId, quantity) {
923
+ return this.request(`/api/servers/${serverId}/shop/cart/${itemId}`, {
924
+ method: "PUT",
925
+ body: JSON.stringify({ quantity })
926
+ });
927
+ }
928
+ async removeCartItem(serverId, itemId) {
929
+ return this.request(`/api/servers/${serverId}/shop/cart/${itemId}`, { method: "DELETE" });
930
+ }
931
+ async createOrder(serverId, data) {
932
+ return this.request(`/api/servers/${serverId}/shop/orders`, {
933
+ method: "POST",
934
+ body: JSON.stringify(data ?? {})
935
+ });
936
+ }
937
+ async listOrders(serverId) {
938
+ return this.request(`/api/servers/${serverId}/shop/orders`);
939
+ }
940
+ async listShopOrders(serverId) {
941
+ return this.request(`/api/servers/${serverId}/shop/orders/manage`);
942
+ }
943
+ async getOrder(serverId, orderId) {
944
+ return this.request(`/api/servers/${serverId}/shop/orders/${orderId}`);
945
+ }
946
+ async updateOrderStatus(serverId, orderId, status) {
947
+ return this.request(`/api/servers/${serverId}/shop/orders/${orderId}/status`, {
948
+ method: "PUT",
949
+ body: JSON.stringify({ status })
950
+ });
951
+ }
952
+ async cancelOrder(serverId, orderId) {
953
+ return this.request(`/api/servers/${serverId}/shop/orders/${orderId}/cancel`, {
954
+ method: "POST"
955
+ });
956
+ }
957
+ async getProductReviews(serverId, productId) {
958
+ return this.request(`/api/servers/${serverId}/shop/products/${productId}/reviews`);
959
+ }
960
+ async createReview(serverId, orderId, data) {
961
+ return this.request(`/api/servers/${serverId}/shop/orders/${orderId}/review`, {
962
+ method: "POST",
963
+ body: JSON.stringify(data)
964
+ });
965
+ }
966
+ async replyToReview(serverId, reviewId, reply) {
967
+ return this.request(`/api/servers/${serverId}/shop/reviews/${reviewId}/reply`, {
968
+ method: "PUT",
969
+ body: JSON.stringify({ reply })
970
+ });
971
+ }
972
+ async getWallet() {
973
+ return this.request("/api/wallet");
974
+ }
975
+ async topUpWallet(amount) {
976
+ return this.request("/api/wallet/topup", {
977
+ method: "POST",
978
+ body: JSON.stringify({ amount })
979
+ });
980
+ }
981
+ async getWalletTransactions() {
982
+ return this.request("/api/wallet/transactions");
983
+ }
984
+ async getEntitlements(serverId) {
985
+ return this.request(`/api/servers/${serverId}/shop/entitlements`);
986
+ }
987
+ // ── Task Center ───────────────────────────────────────────────────────
988
+ async getTaskCenter() {
989
+ return this.request("/api/tasks");
990
+ }
991
+ async claimTask(taskKey) {
992
+ return this.request(`/api/tasks/${taskKey}/claim`, { method: "POST" });
993
+ }
994
+ async getReferralSummary() {
995
+ return this.request("/api/tasks/referral-summary");
996
+ }
997
+ async getRewardHistory() {
998
+ return this.request("/api/tasks/rewards");
999
+ }
1000
+ // ── Server Apps ───────────────────────────────────────────────────────
1001
+ async listApps(serverId, params) {
1002
+ const qs = new URLSearchParams();
1003
+ if (params?.status) qs.set("status", params.status);
1004
+ if (params?.limit) qs.set("limit", String(params.limit));
1005
+ if (params?.offset) qs.set("offset", String(params.offset));
1006
+ return this.request(`/api/servers/${serverId}/apps?${qs}`);
1007
+ }
1008
+ async getHomepageApp(serverId) {
1009
+ return this.request(`/api/servers/${serverId}/apps/homepage`);
1010
+ }
1011
+ async getApp(serverId, appId) {
1012
+ return this.request(`/api/servers/${serverId}/apps/${appId}`);
1013
+ }
1014
+ async createApp(serverId, data) {
1015
+ return this.request(`/api/servers/${serverId}/apps`, {
1016
+ method: "POST",
1017
+ body: JSON.stringify(data)
1018
+ });
1019
+ }
1020
+ async updateApp(serverId, appId, data) {
1021
+ return this.request(`/api/servers/${serverId}/apps/${appId}`, {
1022
+ method: "PATCH",
1023
+ body: JSON.stringify(data)
1024
+ });
1025
+ }
1026
+ async deleteApp(serverId, appId) {
1027
+ return this.request(`/api/servers/${serverId}/apps/${appId}`, { method: "DELETE" });
1028
+ }
1029
+ async publishApp(serverId, data) {
1030
+ return this.request(`/api/servers/${serverId}/apps/publish`, {
1031
+ method: "POST",
1032
+ body: JSON.stringify(data)
1033
+ });
1034
+ }
1035
+ };
1036
+
1037
+ // src/constants.ts
1038
+ var import_shared = require("@shadowob/shared");
1039
+ var channelRoom = (channelId) => `channel:${channelId}`;
1040
+ var threadRoom = (threadId) => `thread:${threadId}`;
1041
+ var userRoom = (userId) => `user:${userId}`;
1042
+
1043
+ // src/socket.ts
1044
+ var import_socket = require("socket.io-client");
1045
+ var ShadowSocket = class {
1046
+ socket;
1047
+ _connected = false;
1048
+ constructor(options) {
1049
+ this.socket = (0, import_socket.io)(options.serverUrl, {
1050
+ auth: { token: options.token },
1051
+ transports: options.transports ?? ["websocket"],
1052
+ autoConnect: false,
1053
+ reconnection: options.autoReconnect ?? true,
1054
+ reconnectionDelay: options.reconnectionDelay ?? 1e3
1055
+ });
1056
+ this.socket.on("connect", () => {
1057
+ this._connected = true;
1058
+ });
1059
+ this.socket.on("disconnect", () => {
1060
+ this._connected = false;
1061
+ });
1062
+ }
1063
+ /** Whether the socket is currently connected */
1064
+ get connected() {
1065
+ return this._connected;
1066
+ }
1067
+ /** The underlying Socket.IO socket instance */
1068
+ get raw() {
1069
+ return this.socket;
1070
+ }
1071
+ // ── Connection lifecycle ──────────────────────────────────────────────
1072
+ /** Connect to the Shadow server */
1073
+ connect() {
1074
+ if (!this.socket.connected) {
1075
+ this.socket.connect();
1076
+ }
1077
+ }
1078
+ /** Disconnect from the Shadow server */
1079
+ disconnect() {
1080
+ this.socket.disconnect();
1081
+ }
1082
+ /** Wait until the socket is connected (resolves immediately if already connected) */
1083
+ waitForConnect(timeoutMs = 5e3) {
1084
+ if (this.socket.connected) return Promise.resolve();
1085
+ return new Promise((resolve, reject) => {
1086
+ const timer = setTimeout(() => {
1087
+ reject(new Error(`Socket connect timeout after ${timeoutMs}ms`));
1088
+ }, timeoutMs);
1089
+ this.socket.once("connect", () => {
1090
+ clearTimeout(timer);
1091
+ resolve();
1092
+ });
1093
+ });
1094
+ }
1095
+ // ── Typed event listeners ─────────────────────────────────────────────
1096
+ /** Listen for a server event */
1097
+ on(event, handler) {
1098
+ this.socket.on(event, handler);
1099
+ return this;
1100
+ }
1101
+ /** Listen for a server event (one-time) */
1102
+ once(event, handler) {
1103
+ this.socket.once(event, handler);
1104
+ return this;
1105
+ }
1106
+ /** Remove a specific event listener */
1107
+ off(event, handler) {
1108
+ this.socket.off(event, handler);
1109
+ return this;
1110
+ }
1111
+ /** Remove all listeners for an event or all events */
1112
+ removeAllListeners(event) {
1113
+ if (event) {
1114
+ this.socket.removeAllListeners(event);
1115
+ } else {
1116
+ this.socket.removeAllListeners();
1117
+ }
1118
+ return this;
1119
+ }
1120
+ // ── Connection event listeners ────────────────────────────────────────
1121
+ /** Listen for raw connection events (connect, disconnect, connect_error) */
1122
+ onConnect(handler) {
1123
+ this.socket.on("connect", handler);
1124
+ return this;
1125
+ }
1126
+ onDisconnect(handler) {
1127
+ this.socket.on("disconnect", handler);
1128
+ return this;
1129
+ }
1130
+ onConnectError(handler) {
1131
+ this.socket.on("connect_error", handler);
1132
+ return this;
1133
+ }
1134
+ // ── Room management ───────────────────────────────────────────────────
1135
+ /** Join a channel room to receive its messages and events */
1136
+ joinChannel(channelId) {
1137
+ return new Promise((resolve) => {
1138
+ this.socket.emit(
1139
+ "channel:join",
1140
+ { channelId },
1141
+ (res) => {
1142
+ resolve(res ?? { ok: true });
1143
+ }
1144
+ );
1145
+ });
1146
+ }
1147
+ /** Leave a channel room */
1148
+ leaveChannel(channelId) {
1149
+ this.socket.emit("channel:leave", { channelId });
1150
+ }
1151
+ // ── Client actions ────────────────────────────────────────────────────
1152
+ /** Send a message via WebSocket (text-only; for file attachments use REST) */
1153
+ sendMessage(data) {
1154
+ this.socket.emit("message:send", data);
1155
+ }
1156
+ /** Send a typing indicator */
1157
+ sendTyping(channelId) {
1158
+ this.socket.emit("message:typing", { channelId });
1159
+ }
1160
+ /** Update user presence status */
1161
+ updatePresence(status) {
1162
+ this.socket.emit("presence:update", { status });
1163
+ }
1164
+ /** Update activity status in a channel (e.g. 'thinking', 'working', null) */
1165
+ updateActivity(channelId, activity) {
1166
+ this.socket.emit("presence:activity", { channelId, activity });
1167
+ }
1168
+ // ── DM actions ────────────────────────────────────────────────────────
1169
+ /** Join a DM channel room */
1170
+ joinDmChannel(dmChannelId) {
1171
+ this.socket.emit("dm:join", { dmChannelId });
1172
+ }
1173
+ /** Leave a DM channel room */
1174
+ leaveDmChannel(dmChannelId) {
1175
+ this.socket.emit("dm:leave", { dmChannelId });
1176
+ }
1177
+ /** Send a DM message via WebSocket */
1178
+ sendDmMessage(data) {
1179
+ this.socket.emit("dm:send", data);
1180
+ }
1181
+ /** Send a DM typing indicator */
1182
+ sendDmTyping(dmChannelId) {
1183
+ this.socket.emit("dm:typing", { dmChannelId });
1184
+ }
1185
+ };
1186
+ // Annotate the CommonJS export names for ESM import in node:
1187
+ 0 && (module.exports = {
1188
+ CLIENT_EVENTS,
1189
+ SERVER_EVENTS,
1190
+ ShadowClient,
1191
+ ShadowSocket,
1192
+ channelRoom,
1193
+ threadRoom,
1194
+ userRoom
1195
+ });