@shadowob/sdk 0.4.0 → 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.
@@ -0,0 +1,1085 @@
1
+ import { Socket } from 'socket.io-client';
2
+ export { CLIENT_EVENTS, ClientEvent, SERVER_EVENTS, ServerEvent } from '@shadowob/shared';
3
+
4
+ /** Message returned by the Shadow REST API and Socket.IO broadcasts */
5
+ interface ShadowMessage {
6
+ id: string;
7
+ content: string;
8
+ channelId: string;
9
+ authorId: string;
10
+ threadId?: string | null;
11
+ replyToId?: string | null;
12
+ isPinned?: boolean;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ author?: {
16
+ id: string;
17
+ username: string;
18
+ displayName?: string | null;
19
+ avatarUrl?: string | null;
20
+ isBot?: boolean;
21
+ };
22
+ attachments?: ShadowAttachment[];
23
+ }
24
+ interface ShadowAttachment {
25
+ id: string;
26
+ filename: string;
27
+ url: string;
28
+ contentType: string;
29
+ size: number;
30
+ width?: number | null;
31
+ height?: number | null;
32
+ }
33
+ interface ShadowChannel {
34
+ id: string;
35
+ name: string;
36
+ type: string;
37
+ serverId: string;
38
+ description?: string | null;
39
+ position?: number;
40
+ }
41
+ interface ShadowDmChannel {
42
+ id: string;
43
+ user1Id: string;
44
+ user2Id: string;
45
+ createdAt: string;
46
+ }
47
+ interface ShadowThread {
48
+ id: string;
49
+ name: string;
50
+ channelId: string;
51
+ parentMessageId: string;
52
+ createdAt: string;
53
+ }
54
+ interface ShadowMember {
55
+ userId: string;
56
+ serverId: string;
57
+ role: string;
58
+ user?: ShadowUser;
59
+ }
60
+ interface ShadowInviteCode {
61
+ id: string;
62
+ code: string;
63
+ createdBy: string;
64
+ usedBy?: string | null;
65
+ usedAt?: string | null;
66
+ isActive: boolean;
67
+ note?: string | null;
68
+ createdAt: string;
69
+ }
70
+ interface ShadowServer {
71
+ id: string;
72
+ name: string;
73
+ slug: string;
74
+ description: string | null;
75
+ iconUrl: string | null;
76
+ bannerUrl: string | null;
77
+ homepageHtml: string | null;
78
+ isPublic: boolean;
79
+ }
80
+ interface ShadowUser {
81
+ id: string;
82
+ username: string;
83
+ displayName?: string;
84
+ avatarUrl?: string;
85
+ isBot?: boolean;
86
+ agentId?: string;
87
+ }
88
+ interface ShadowNotification {
89
+ id: string;
90
+ userId: string;
91
+ type: string;
92
+ title: string;
93
+ body: string;
94
+ referenceId?: string;
95
+ referenceType?: string;
96
+ isRead: boolean;
97
+ createdAt: string;
98
+ }
99
+ interface ShadowChannelPolicy {
100
+ listen: boolean;
101
+ reply: boolean;
102
+ mentionOnly: boolean;
103
+ config: Record<string, unknown>;
104
+ }
105
+ interface ShadowRemoteChannel {
106
+ id: string;
107
+ name: string;
108
+ type: string;
109
+ policy: ShadowChannelPolicy;
110
+ }
111
+ interface ShadowRemoteServer {
112
+ id: string;
113
+ name: string;
114
+ slug?: string;
115
+ iconUrl?: string | null;
116
+ defaultPolicy: ShadowChannelPolicy;
117
+ channels: ShadowRemoteChannel[];
118
+ }
119
+ interface ShadowRemoteConfig {
120
+ agentId: string;
121
+ botUserId: string;
122
+ servers: ShadowRemoteServer[];
123
+ }
124
+ interface TypingPayload {
125
+ channelId: string;
126
+ userId: string;
127
+ username: string;
128
+ }
129
+ interface PresenceChangePayload {
130
+ userId: string;
131
+ status: 'online' | 'idle' | 'dnd' | 'offline';
132
+ }
133
+ interface PresenceActivityPayload {
134
+ userId: string;
135
+ activity: string | null;
136
+ channelId: string;
137
+ }
138
+ interface MemberJoinPayload {
139
+ channelId: string;
140
+ userId: string;
141
+ }
142
+ interface MemberLeavePayload {
143
+ channelId: string;
144
+ userId: string;
145
+ }
146
+ interface ReactionPayload {
147
+ messageId: string;
148
+ userId: string;
149
+ emoji: string;
150
+ }
151
+ interface MessageDeletedPayload {
152
+ id: string;
153
+ channelId: string;
154
+ }
155
+ interface ChannelCreatedPayload {
156
+ id: string;
157
+ name: string;
158
+ type: string;
159
+ serverId: string;
160
+ }
161
+ interface ChannelMemberAddedPayload {
162
+ channelId: string;
163
+ userId: string;
164
+ }
165
+ interface ChannelMemberRemovedPayload {
166
+ channelId: string;
167
+ userId: string;
168
+ }
169
+ interface ServerJoinedPayload {
170
+ serverId: string;
171
+ serverName: string;
172
+ }
173
+ interface PolicyChangedPayload {
174
+ agentId: string;
175
+ serverId: string;
176
+ channelId?: string | null;
177
+ }
178
+ interface DmMessage {
179
+ id: string;
180
+ content: string;
181
+ senderId: string;
182
+ receiverId: string;
183
+ dmChannelId: string;
184
+ channelId: string;
185
+ authorId: string;
186
+ author?: {
187
+ id: string;
188
+ username: string;
189
+ displayName?: string;
190
+ avatarUrl?: string;
191
+ isBot?: boolean;
192
+ };
193
+ createdAt: string;
194
+ }
195
+ interface ShadowFriendship {
196
+ id: string;
197
+ userId: string;
198
+ friendId: string;
199
+ status: 'pending' | 'accepted' | 'rejected';
200
+ createdAt: string;
201
+ user?: ShadowUser;
202
+ friend?: ShadowUser;
203
+ }
204
+ interface ShadowOAuthApp {
205
+ id: string;
206
+ name: string;
207
+ clientId: string;
208
+ clientSecret?: string;
209
+ redirectUris: string[];
210
+ scopes: string[];
211
+ createdAt: string;
212
+ }
213
+ interface ShadowOAuthConsent {
214
+ id: string;
215
+ appId: string;
216
+ appName: string;
217
+ scopes: string[];
218
+ createdAt: string;
219
+ }
220
+ interface ShadowOAuthToken {
221
+ access_token: string;
222
+ token_type: string;
223
+ expires_in: number;
224
+ refresh_token?: string;
225
+ scope: string;
226
+ }
227
+ interface ShadowListing {
228
+ id: string;
229
+ agentId: string;
230
+ title: string;
231
+ description: string;
232
+ pricePerHour: number;
233
+ currency: string;
234
+ tags: string[];
235
+ isActive: boolean;
236
+ createdAt: string;
237
+ agent?: {
238
+ id: string;
239
+ name: string;
240
+ status: string;
241
+ };
242
+ }
243
+ interface ShadowContract {
244
+ id: string;
245
+ listingId: string;
246
+ tenantId: string;
247
+ ownerId: string;
248
+ status: string;
249
+ startedAt: string;
250
+ expiresAt: string;
251
+ totalCost: number;
252
+ createdAt: string;
253
+ }
254
+ interface ShadowShop {
255
+ id: string;
256
+ serverId: string;
257
+ name: string;
258
+ description?: string | null;
259
+ isEnabled: boolean;
260
+ }
261
+ interface ShadowCategory {
262
+ id: string;
263
+ shopId: string;
264
+ name: string;
265
+ description?: string | null;
266
+ position: number;
267
+ }
268
+ interface ShadowProduct {
269
+ id: string;
270
+ shopId: string;
271
+ categoryId?: string | null;
272
+ name: string;
273
+ description?: string | null;
274
+ price: number;
275
+ currency: string;
276
+ stock: number;
277
+ status: string;
278
+ images: string[];
279
+ createdAt: string;
280
+ }
281
+ interface ShadowCartItem {
282
+ id: string;
283
+ productId: string;
284
+ quantity: number;
285
+ product?: ShadowProduct;
286
+ }
287
+ interface ShadowOrder {
288
+ id: string;
289
+ shopId: string;
290
+ buyerId: string;
291
+ status: string;
292
+ totalAmount: number;
293
+ currency: string;
294
+ items: {
295
+ productId: string;
296
+ quantity: number;
297
+ price: number;
298
+ }[];
299
+ createdAt: string;
300
+ }
301
+ interface ShadowReview {
302
+ id: string;
303
+ orderId: string;
304
+ productId: string;
305
+ userId: string;
306
+ rating: number;
307
+ content: string;
308
+ reply?: string | null;
309
+ createdAt: string;
310
+ }
311
+ interface ShadowWallet {
312
+ id: string;
313
+ userId: string;
314
+ balance: number;
315
+ currency: string;
316
+ }
317
+ interface ShadowTransaction {
318
+ id: string;
319
+ walletId: string;
320
+ type: string;
321
+ amount: number;
322
+ description?: string | null;
323
+ createdAt: string;
324
+ }
325
+ interface ShadowTask {
326
+ key: string;
327
+ title: string;
328
+ description: string;
329
+ reward: number;
330
+ status: string;
331
+ claimedAt?: string | null;
332
+ }
333
+ interface ShadowApp {
334
+ id: string;
335
+ serverId: string;
336
+ name: string;
337
+ slug: string;
338
+ type: string;
339
+ url?: string | null;
340
+ status: string;
341
+ createdAt: string;
342
+ }
343
+ interface ShadowNotificationPreferences {
344
+ strategy: 'all' | 'mention_only' | 'none';
345
+ mutedServerIds: string[];
346
+ mutedChannelIds: string[];
347
+ }
348
+ /** Events the server pushes to the client */
349
+ interface ServerEventMap {
350
+ 'message:new': (message: ShadowMessage) => void;
351
+ 'message:updated': (message: ShadowMessage) => void;
352
+ 'message:deleted': (payload: MessageDeletedPayload) => void;
353
+ 'member:typing': (payload: TypingPayload) => void;
354
+ 'member:join': (payload: MemberJoinPayload) => void;
355
+ 'member:leave': (payload: MemberLeavePayload) => void;
356
+ 'presence:change': (payload: PresenceChangePayload) => void;
357
+ 'presence:activity': (payload: PresenceActivityPayload) => void;
358
+ 'reaction:add': (payload: ReactionPayload) => void;
359
+ 'reaction:remove': (payload: ReactionPayload) => void;
360
+ 'notification:new': (notification: ShadowNotification) => void;
361
+ 'dm:message:new': (message: DmMessage) => void;
362
+ 'channel:created': (payload: ChannelCreatedPayload) => void;
363
+ 'channel:member-added': (payload: ChannelMemberAddedPayload) => void;
364
+ 'channel:member-removed': (payload: ChannelMemberRemovedPayload) => void;
365
+ 'server:joined': (payload: ServerJoinedPayload) => void;
366
+ 'agent:policy-changed': (payload: PolicyChangedPayload) => void;
367
+ error: (payload: {
368
+ message: string;
369
+ }) => void;
370
+ }
371
+ /** Events the client sends to the server */
372
+ interface ClientEventMap {
373
+ 'channel:join': (data: {
374
+ channelId: string;
375
+ }, ack?: (res: {
376
+ ok: boolean;
377
+ }) => void) => void;
378
+ 'channel:leave': (data: {
379
+ channelId: string;
380
+ }) => void;
381
+ 'message:send': (data: {
382
+ channelId: string;
383
+ content: string;
384
+ threadId?: string;
385
+ replyToId?: string;
386
+ }) => void;
387
+ 'message:typing': (data: {
388
+ channelId: string;
389
+ }) => void;
390
+ 'presence:update': (data: {
391
+ status: 'online' | 'idle' | 'dnd' | 'offline';
392
+ }) => void;
393
+ 'presence:activity': (data: {
394
+ channelId: string;
395
+ activity: string | null;
396
+ }) => void;
397
+ }
398
+
399
+ /**
400
+ * Shadow REST API client.
401
+ *
402
+ * Provides typed HTTP methods for interacting with the Shadow server API.
403
+ */
404
+ declare class ShadowClient {
405
+ private token;
406
+ private baseUrl;
407
+ constructor(baseUrl: string, token: string);
408
+ private request;
409
+ private requestRaw;
410
+ register(data: {
411
+ email: string;
412
+ password: string;
413
+ username: string;
414
+ displayName?: string;
415
+ inviteCode: string;
416
+ }): Promise<{
417
+ token: string;
418
+ user: ShadowUser;
419
+ }>;
420
+ login(data: {
421
+ email: string;
422
+ password: string;
423
+ }): Promise<{
424
+ token: string;
425
+ user: ShadowUser;
426
+ }>;
427
+ refreshToken(): Promise<{
428
+ token: string;
429
+ }>;
430
+ getMe(): Promise<ShadowUser>;
431
+ updateProfile(data: {
432
+ displayName?: string;
433
+ avatarUrl?: string | null;
434
+ }): Promise<ShadowUser>;
435
+ disconnect(): Promise<{
436
+ success: boolean;
437
+ }>;
438
+ listAgents(): Promise<{
439
+ id: string;
440
+ name: string;
441
+ status: string;
442
+ }[]>;
443
+ createAgent(data: {
444
+ name: string;
445
+ displayName?: string;
446
+ avatarUrl?: string | null;
447
+ }): Promise<{
448
+ id: string;
449
+ token: string;
450
+ userId: string;
451
+ }>;
452
+ getAgent(agentId: string): Promise<{
453
+ id: string;
454
+ name: string;
455
+ status: string;
456
+ userId: string;
457
+ }>;
458
+ updateAgent(agentId: string, data: {
459
+ name?: string;
460
+ displayName?: string;
461
+ avatarUrl?: string | null;
462
+ }): Promise<{
463
+ id: string;
464
+ name: string;
465
+ }>;
466
+ deleteAgent(agentId: string): Promise<{
467
+ success: boolean;
468
+ }>;
469
+ generateAgentToken(agentId: string): Promise<{
470
+ token: string;
471
+ }>;
472
+ startAgent(agentId: string): Promise<{
473
+ ok: boolean;
474
+ }>;
475
+ stopAgent(agentId: string): Promise<{
476
+ ok: boolean;
477
+ }>;
478
+ sendHeartbeat(agentId: string): Promise<{
479
+ ok: boolean;
480
+ }>;
481
+ getAgentConfig(agentId: string): Promise<ShadowRemoteConfig>;
482
+ listPolicies(agentId: string, serverId: string): Promise<{
483
+ channelId: string | null;
484
+ mentionOnly: boolean;
485
+ reply: boolean;
486
+ config: Record<string, unknown>;
487
+ }[]>;
488
+ upsertPolicy(agentId: string, serverId: string, data: {
489
+ channelId?: string | null;
490
+ mentionOnly?: boolean;
491
+ reply?: boolean;
492
+ config?: Record<string, unknown>;
493
+ }): Promise<{
494
+ channelId: string | null;
495
+ mentionOnly: boolean;
496
+ reply: boolean;
497
+ }>;
498
+ deletePolicy(agentId: string, serverId: string, channelId: string): Promise<{
499
+ success: boolean;
500
+ }>;
501
+ discoverServers(): Promise<ShadowServer[]>;
502
+ getServerByInvite(inviteCode: string): Promise<ShadowServer>;
503
+ createServer(data: {
504
+ name: string;
505
+ slug?: string;
506
+ description?: string;
507
+ isPublic?: boolean;
508
+ }): Promise<ShadowServer>;
509
+ listServers(): Promise<ShadowServer[]>;
510
+ getServer(serverIdOrSlug: string): Promise<ShadowServer>;
511
+ updateServer(serverIdOrSlug: string, data: {
512
+ name?: string;
513
+ description?: string | null;
514
+ slug?: string | null;
515
+ homepageHtml?: string | null;
516
+ isPublic?: boolean;
517
+ }): Promise<ShadowServer>;
518
+ updateServerHomepage(serverIdOrSlug: string, homepageHtml: string | null): Promise<ShadowServer>;
519
+ deleteServer(serverId: string): Promise<{
520
+ success: boolean;
521
+ }>;
522
+ joinServer(serverId: string, inviteCode?: string): Promise<{
523
+ success: boolean;
524
+ }>;
525
+ leaveServer(serverId: string): Promise<{
526
+ success: boolean;
527
+ }>;
528
+ getMembers(serverId: string): Promise<ShadowMember[]>;
529
+ updateMember(serverId: string, userId: string, data: {
530
+ role?: string;
531
+ }): Promise<ShadowMember>;
532
+ kickMember(serverId: string, userId: string): Promise<{
533
+ success: boolean;
534
+ }>;
535
+ regenerateInviteCode(serverId: string): Promise<{
536
+ inviteCode: string;
537
+ }>;
538
+ addAgentsToServer(serverId: string, agentIds: string[]): Promise<{
539
+ added: string[];
540
+ }>;
541
+ getServerChannels(serverId: string): Promise<ShadowChannel[]>;
542
+ createChannel(serverId: string, data: {
543
+ name: string;
544
+ type?: string;
545
+ description?: string;
546
+ }): Promise<ShadowChannel>;
547
+ getChannel(channelId: string): Promise<ShadowChannel>;
548
+ getChannelMembers(channelId: string): Promise<ShadowMember[]>;
549
+ updateChannel(channelId: string, data: {
550
+ name?: string;
551
+ description?: string | null;
552
+ }): Promise<ShadowChannel>;
553
+ deleteChannel(channelId: string): Promise<{
554
+ success: boolean;
555
+ }>;
556
+ reorderChannels(serverId: string, channelIds: string[]): Promise<{
557
+ success: boolean;
558
+ }>;
559
+ addChannelMember(channelId: string, userId: string): Promise<{
560
+ success: boolean;
561
+ }>;
562
+ removeChannelMember(channelId: string, userId: string): Promise<{
563
+ success: boolean;
564
+ }>;
565
+ setBuddyPolicy(channelId: string, data: {
566
+ buddyUserId: string;
567
+ mentionOnly?: boolean;
568
+ reply?: boolean;
569
+ }): Promise<{
570
+ success: boolean;
571
+ }>;
572
+ getBuddyPolicy(channelId: string): Promise<{
573
+ buddyUserId: string | null;
574
+ mentionOnly: boolean;
575
+ reply: boolean;
576
+ } | null>;
577
+ sendMessage(channelId: string, content: string, opts?: {
578
+ threadId?: string;
579
+ replyToId?: string;
580
+ metadata?: Record<string, unknown>;
581
+ }): Promise<ShadowMessage>;
582
+ getMessages(channelId: string, limit?: number, cursor?: string): Promise<{
583
+ messages: ShadowMessage[];
584
+ hasMore: boolean;
585
+ }>;
586
+ getMessage(messageId: string): Promise<ShadowMessage>;
587
+ editMessage(messageId: string, content: string): Promise<ShadowMessage>;
588
+ deleteMessage(messageId: string): Promise<void>;
589
+ pinMessage(messageId: string, channelId?: string): Promise<{
590
+ success: boolean;
591
+ }>;
592
+ unpinMessage(messageId: string, channelId?: string): Promise<{
593
+ success: boolean;
594
+ }>;
595
+ getPinnedMessages(channelId: string): Promise<ShadowMessage[]>;
596
+ addReaction(messageId: string, emoji: string): Promise<void>;
597
+ removeReaction(messageId: string, emoji: string): Promise<void>;
598
+ getReactions(messageId: string): Promise<{
599
+ emoji: string;
600
+ count: number;
601
+ users: string[];
602
+ }[]>;
603
+ listThreads(channelId: string): Promise<ShadowThread[]>;
604
+ createThread(channelId: string, name: string, parentMessageId: string): Promise<{
605
+ id: string;
606
+ name: string;
607
+ }>;
608
+ getThread(threadId: string): Promise<ShadowThread>;
609
+ updateThread(threadId: string, data: {
610
+ name?: string;
611
+ }): Promise<ShadowThread>;
612
+ deleteThread(threadId: string): Promise<{
613
+ success: boolean;
614
+ }>;
615
+ getThreadMessages(threadId: string, limit?: number, cursor?: string): Promise<ShadowMessage[]>;
616
+ sendToThread(threadId: string, content: string): Promise<ShadowMessage>;
617
+ createDmChannel(userId: string): Promise<ShadowDmChannel>;
618
+ listDmChannels(): Promise<ShadowDmChannel[]>;
619
+ getDmMessages(channelId: string, limit?: number, cursor?: string): Promise<ShadowMessage[]>;
620
+ sendDmMessage(channelId: string, content: string, options?: {
621
+ replyToId?: string;
622
+ metadata?: Record<string, unknown>;
623
+ }): Promise<ShadowMessage>;
624
+ listNotifications(limit?: number, offset?: number): Promise<ShadowNotification[]>;
625
+ markNotificationRead(notificationId: string): Promise<{
626
+ success: boolean;
627
+ }>;
628
+ markAllNotificationsRead(): Promise<{
629
+ success: boolean;
630
+ }>;
631
+ getUnreadCount(): Promise<{
632
+ count: number;
633
+ }>;
634
+ searchMessages(query: {
635
+ q: string;
636
+ serverId?: string;
637
+ channelId?: string;
638
+ authorId?: string;
639
+ limit?: number;
640
+ offset?: number;
641
+ }): Promise<{
642
+ messages: ShadowMessage[];
643
+ total: number;
644
+ }>;
645
+ listInvites(): Promise<ShadowInviteCode[]>;
646
+ createInvites(count: number, note?: string): Promise<ShadowInviteCode[]>;
647
+ deactivateInvite(inviteId: string): Promise<ShadowInviteCode>;
648
+ deleteInvite(inviteId: string): Promise<{
649
+ success: boolean;
650
+ }>;
651
+ uploadMedia(file: Blob | ArrayBuffer, filename: string, contentType: string, messageId?: string): Promise<{
652
+ url: string;
653
+ key: string;
654
+ size: number;
655
+ }>;
656
+ /**
657
+ * Download a file from a URL and upload it to the Shadow media service.
658
+ * Supports local filesystem paths, file:// URLs, tilde paths, and HTTP(S) URLs.
659
+ */
660
+ uploadMediaFromUrl(mediaUrl: string, messageId?: string): Promise<{
661
+ url: string;
662
+ key: string;
663
+ size: number;
664
+ }>;
665
+ downloadFile(fileUrl: string): Promise<{
666
+ buffer: ArrayBuffer;
667
+ contentType: string;
668
+ filename: string;
669
+ }>;
670
+ getWorkspace(serverId: string): Promise<Record<string, unknown>>;
671
+ updateWorkspace(serverId: string, data: {
672
+ name?: string;
673
+ description?: string | null;
674
+ }): Promise<Record<string, unknown>>;
675
+ getWorkspaceTree(serverId: string): Promise<Record<string, unknown>>;
676
+ getWorkspaceStats(serverId: string): Promise<Record<string, unknown>>;
677
+ getWorkspaceChildren(serverId: string, parentId?: string | null): Promise<Record<string, unknown>[]>;
678
+ batchWorkspaceChildren(serverId: string, parentIds: (string | null)[]): Promise<Record<string, Record<string, unknown>[]>>;
679
+ createWorkspaceFolder(serverId: string, data: {
680
+ parentId?: string | null;
681
+ name: string;
682
+ }): Promise<Record<string, unknown>>;
683
+ updateWorkspaceFolder(serverId: string, folderId: string, data: {
684
+ name?: string;
685
+ parentId?: string | null;
686
+ pos?: number;
687
+ }): Promise<Record<string, unknown>>;
688
+ deleteWorkspaceFolder(serverId: string, folderId: string): Promise<{
689
+ success: boolean;
690
+ }>;
691
+ searchWorkspaceFolders(serverId: string, query: {
692
+ searchText?: string;
693
+ limit?: number;
694
+ }): Promise<Record<string, unknown>[]>;
695
+ createWorkspaceFile(serverId: string, data: {
696
+ parentId?: string | null;
697
+ name: string;
698
+ ext?: string | null;
699
+ mime?: string | null;
700
+ sizeBytes?: number | null;
701
+ contentRef?: string | null;
702
+ previewUrl?: string | null;
703
+ metadata?: Record<string, unknown> | null;
704
+ }): Promise<Record<string, unknown>>;
705
+ searchWorkspaceFiles(serverId: string, query: {
706
+ parentId?: string;
707
+ searchText?: string;
708
+ ext?: string;
709
+ limit?: number;
710
+ offset?: number;
711
+ }): Promise<Record<string, unknown>[]>;
712
+ getWorkspaceFile(serverId: string, fileId: string): Promise<Record<string, unknown>>;
713
+ updateWorkspaceFile(serverId: string, fileId: string, data: {
714
+ name?: string;
715
+ parentId?: string | null;
716
+ pos?: number;
717
+ ext?: string | null;
718
+ mime?: string | null;
719
+ sizeBytes?: number | null;
720
+ contentRef?: string | null;
721
+ previewUrl?: string | null;
722
+ metadata?: Record<string, unknown> | null;
723
+ }): Promise<Record<string, unknown>>;
724
+ deleteWorkspaceFile(serverId: string, fileId: string): Promise<{
725
+ success: boolean;
726
+ }>;
727
+ cloneWorkspaceFile(serverId: string, fileId: string): Promise<Record<string, unknown>>;
728
+ pasteWorkspaceNodes(serverId: string, data: {
729
+ sourceWorkspaceId: string;
730
+ targetParentId?: string | null;
731
+ nodeIds: string[];
732
+ mode: 'copy' | 'cut';
733
+ }): Promise<Record<string, unknown>>;
734
+ executeWorkspaceCommands(serverId: string, commands: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
735
+ uploadWorkspaceFile(serverId: string, file: Blob, filename: string, parentId?: string): Promise<Record<string, unknown>>;
736
+ downloadWorkspace(serverId: string): Promise<ArrayBuffer>;
737
+ downloadWorkspaceFolder(serverId: string, folderId: string): Promise<ArrayBuffer>;
738
+ getUserProfile(userId: string): Promise<ShadowUser>;
739
+ listOAuthAccounts(): Promise<{
740
+ id: string;
741
+ provider: string;
742
+ providerAccountId: string;
743
+ }[]>;
744
+ unlinkOAuthAccount(accountId: string): Promise<{
745
+ success: boolean;
746
+ }>;
747
+ sendFriendRequest(username: string): Promise<ShadowFriendship>;
748
+ acceptFriendRequest(requestId: string): Promise<ShadowFriendship>;
749
+ rejectFriendRequest(requestId: string): Promise<ShadowFriendship>;
750
+ removeFriend(friendshipId: string): Promise<{
751
+ success: boolean;
752
+ }>;
753
+ listFriends(): Promise<ShadowFriendship[]>;
754
+ listPendingFriendRequests(): Promise<ShadowFriendship[]>;
755
+ listSentFriendRequests(): Promise<ShadowFriendship[]>;
756
+ markScopeRead(scope: {
757
+ serverId?: string;
758
+ channelId?: string;
759
+ }): Promise<{
760
+ success: boolean;
761
+ }>;
762
+ getScopedUnread(): Promise<Record<string, number>>;
763
+ getNotificationPreferences(): Promise<ShadowNotificationPreferences>;
764
+ updateNotificationPreferences(data: Partial<ShadowNotificationPreferences>): Promise<ShadowNotificationPreferences>;
765
+ createOAuthApp(data: {
766
+ name: string;
767
+ redirectUris: string[];
768
+ scopes?: string[];
769
+ }): Promise<ShadowOAuthApp>;
770
+ listOAuthApps(): Promise<ShadowOAuthApp[]>;
771
+ updateOAuthApp(appId: string, data: {
772
+ name?: string;
773
+ redirectUris?: string[];
774
+ scopes?: string[];
775
+ }): Promise<ShadowOAuthApp>;
776
+ deleteOAuthApp(appId: string): Promise<{
777
+ success: boolean;
778
+ }>;
779
+ resetOAuthAppSecret(appId: string): Promise<{
780
+ clientSecret: string;
781
+ }>;
782
+ getOAuthAuthorization(params: {
783
+ client_id: string;
784
+ redirect_uri: string;
785
+ scope?: string;
786
+ state?: string;
787
+ }): Promise<{
788
+ app: ShadowOAuthApp;
789
+ }>;
790
+ approveOAuthAuthorization(data: {
791
+ client_id: string;
792
+ redirect_uri: string;
793
+ scope?: string;
794
+ state?: string;
795
+ }): Promise<{
796
+ redirectUrl: string;
797
+ }>;
798
+ exchangeOAuthToken(data: {
799
+ grant_type: 'authorization_code' | 'refresh_token';
800
+ code?: string;
801
+ refresh_token?: string;
802
+ client_id: string;
803
+ client_secret: string;
804
+ redirect_uri?: string;
805
+ }): Promise<ShadowOAuthToken>;
806
+ listOAuthConsents(): Promise<ShadowOAuthConsent[]>;
807
+ revokeOAuthConsent(appId: string): Promise<{
808
+ success: boolean;
809
+ }>;
810
+ browseListings(params?: {
811
+ search?: string;
812
+ tags?: string[];
813
+ minPrice?: number;
814
+ maxPrice?: number;
815
+ limit?: number;
816
+ offset?: number;
817
+ }): Promise<{
818
+ listings: ShadowListing[];
819
+ total: number;
820
+ }>;
821
+ getListing(listingId: string): Promise<ShadowListing>;
822
+ estimateRentalCost(listingId: string, hours: number): Promise<{
823
+ totalCost: number;
824
+ currency: string;
825
+ }>;
826
+ listMyListings(): Promise<ShadowListing[]>;
827
+ createListing(data: {
828
+ agentId: string;
829
+ title: string;
830
+ description: string;
831
+ pricePerHour: number;
832
+ currency?: string;
833
+ tags?: string[];
834
+ }): Promise<ShadowListing>;
835
+ updateListing(listingId: string, data: Partial<{
836
+ title: string;
837
+ description: string;
838
+ pricePerHour: number;
839
+ tags: string[];
840
+ }>): Promise<ShadowListing>;
841
+ toggleListing(listingId: string): Promise<ShadowListing>;
842
+ deleteListing(listingId: string): Promise<{
843
+ success: boolean;
844
+ }>;
845
+ signContract(data: {
846
+ listingId: string;
847
+ hours: number;
848
+ }): Promise<ShadowContract>;
849
+ listContracts(params?: {
850
+ role?: 'tenant' | 'owner';
851
+ status?: string;
852
+ }): Promise<ShadowContract[]>;
853
+ getContract(contractId: string): Promise<ShadowContract>;
854
+ terminateContract(contractId: string): Promise<ShadowContract>;
855
+ recordUsageSession(contractId: string, data: {
856
+ durationMinutes: number;
857
+ description?: string;
858
+ }): Promise<{
859
+ success: boolean;
860
+ }>;
861
+ reportViolation(contractId: string, data: {
862
+ reason: string;
863
+ }): Promise<{
864
+ success: boolean;
865
+ }>;
866
+ getShop(serverId: string): Promise<ShadowShop>;
867
+ updateShop(serverId: string, data: Partial<{
868
+ name: string;
869
+ description: string | null;
870
+ isEnabled: boolean;
871
+ }>): Promise<ShadowShop>;
872
+ listCategories(serverId: string): Promise<ShadowCategory[]>;
873
+ createCategory(serverId: string, data: {
874
+ name: string;
875
+ description?: string;
876
+ }): Promise<ShadowCategory>;
877
+ updateCategory(serverId: string, categoryId: string, data: Partial<{
878
+ name: string;
879
+ description: string | null;
880
+ position: number;
881
+ }>): Promise<ShadowCategory>;
882
+ deleteCategory(serverId: string, categoryId: string): Promise<{
883
+ success: boolean;
884
+ }>;
885
+ listProducts(serverId: string, params?: {
886
+ status?: string;
887
+ categoryId?: string;
888
+ keyword?: string;
889
+ limit?: number;
890
+ offset?: number;
891
+ }): Promise<{
892
+ products: ShadowProduct[];
893
+ total: number;
894
+ }>;
895
+ getProduct(serverId: string, productId: string): Promise<ShadowProduct>;
896
+ createProduct(serverId: string, data: {
897
+ name: string;
898
+ description?: string;
899
+ price: number;
900
+ currency?: string;
901
+ stock: number;
902
+ categoryId?: string;
903
+ images?: string[];
904
+ }): Promise<ShadowProduct>;
905
+ updateProduct(serverId: string, productId: string, data: Partial<{
906
+ name: string;
907
+ description: string | null;
908
+ price: number;
909
+ stock: number;
910
+ status: string;
911
+ categoryId: string | null;
912
+ images: string[];
913
+ }>): Promise<ShadowProduct>;
914
+ deleteProduct(serverId: string, productId: string): Promise<{
915
+ success: boolean;
916
+ }>;
917
+ getCart(serverId: string): Promise<ShadowCartItem[]>;
918
+ addToCart(serverId: string, data: {
919
+ productId: string;
920
+ quantity: number;
921
+ }): Promise<ShadowCartItem>;
922
+ updateCartItem(serverId: string, itemId: string, quantity: number): Promise<ShadowCartItem>;
923
+ removeCartItem(serverId: string, itemId: string): Promise<{
924
+ success: boolean;
925
+ }>;
926
+ createOrder(serverId: string, data?: {
927
+ items?: {
928
+ productId: string;
929
+ quantity: number;
930
+ }[];
931
+ }): Promise<ShadowOrder>;
932
+ listOrders(serverId: string): Promise<ShadowOrder[]>;
933
+ listShopOrders(serverId: string): Promise<ShadowOrder[]>;
934
+ getOrder(serverId: string, orderId: string): Promise<ShadowOrder>;
935
+ updateOrderStatus(serverId: string, orderId: string, status: string): Promise<ShadowOrder>;
936
+ cancelOrder(serverId: string, orderId: string): Promise<ShadowOrder>;
937
+ getProductReviews(serverId: string, productId: string): Promise<ShadowReview[]>;
938
+ createReview(serverId: string, orderId: string, data: {
939
+ productId: string;
940
+ rating: number;
941
+ content: string;
942
+ }): Promise<ShadowReview>;
943
+ replyToReview(serverId: string, reviewId: string, reply: string): Promise<ShadowReview>;
944
+ getWallet(): Promise<ShadowWallet>;
945
+ topUpWallet(amount: number): Promise<ShadowWallet>;
946
+ getWalletTransactions(): Promise<ShadowTransaction[]>;
947
+ getEntitlements(serverId: string): Promise<Record<string, unknown>[]>;
948
+ getTaskCenter(): Promise<{
949
+ tasks: ShadowTask[];
950
+ }>;
951
+ claimTask(taskKey: string): Promise<{
952
+ success: boolean;
953
+ reward: number;
954
+ }>;
955
+ getReferralSummary(): Promise<{
956
+ count: number;
957
+ rewards: number;
958
+ }>;
959
+ getRewardHistory(): Promise<{
960
+ rewards: {
961
+ amount: number;
962
+ reason: string;
963
+ createdAt: string;
964
+ }[];
965
+ }>;
966
+ listApps(serverId: string, params?: {
967
+ status?: string;
968
+ limit?: number;
969
+ offset?: number;
970
+ }): Promise<{
971
+ apps: ShadowApp[];
972
+ total: number;
973
+ }>;
974
+ getHomepageApp(serverId: string): Promise<ShadowApp | null>;
975
+ getApp(serverId: string, appId: string): Promise<ShadowApp>;
976
+ createApp(serverId: string, data: {
977
+ name: string;
978
+ slug: string;
979
+ type: string;
980
+ url?: string;
981
+ }): Promise<ShadowApp>;
982
+ updateApp(serverId: string, appId: string, data: Partial<{
983
+ name: string;
984
+ slug: string;
985
+ type: string;
986
+ url: string;
987
+ status: string;
988
+ }>): Promise<ShadowApp>;
989
+ deleteApp(serverId: string, appId: string): Promise<{
990
+ success: boolean;
991
+ }>;
992
+ publishApp(serverId: string, data: {
993
+ name: string;
994
+ slug: string;
995
+ }): Promise<ShadowApp>;
996
+ }
997
+
998
+ /** Build a Socket.IO room name for a channel */
999
+ declare const channelRoom: (channelId: string) => `channel:${string}`;
1000
+ /** Build a Socket.IO room name for a thread */
1001
+ declare const threadRoom: (threadId: string) => `thread:${string}`;
1002
+ /** Build a Socket.IO room name for user-level notifications */
1003
+ declare const userRoom: (userId: string) => `user:${string}`;
1004
+
1005
+ interface ShadowSocketOptions {
1006
+ /** Shadow server base URL (e.g. "https://shadowob.shadowob.com") */
1007
+ serverUrl: string;
1008
+ /** JWT token for authentication */
1009
+ token: string;
1010
+ /** Socket.IO transports (default: ['websocket']) */
1011
+ transports?: string[];
1012
+ /** Auto-reconnect on disconnect (default: true) */
1013
+ autoReconnect?: boolean;
1014
+ /** Reconnection delay in ms (default: 1000) */
1015
+ reconnectionDelay?: number;
1016
+ }
1017
+ type ServerEventName = keyof ServerEventMap;
1018
+ type ServerEventHandler<E extends ServerEventName> = ServerEventMap[E];
1019
+ /**
1020
+ * Shadow real-time event listener.
1021
+ *
1022
+ * Wraps Socket.IO with strongly-typed events that match the Shadow server
1023
+ * gateway broadcasts. Provides channel/thread room management and
1024
+ * convenience methods for sending messages and typing indicators.
1025
+ */
1026
+ declare class ShadowSocket {
1027
+ private socket;
1028
+ private _connected;
1029
+ constructor(options: ShadowSocketOptions);
1030
+ /** Whether the socket is currently connected */
1031
+ get connected(): boolean;
1032
+ /** The underlying Socket.IO socket instance */
1033
+ get raw(): Socket;
1034
+ /** Connect to the Shadow server */
1035
+ connect(): void;
1036
+ /** Disconnect from the Shadow server */
1037
+ disconnect(): void;
1038
+ /** Wait until the socket is connected (resolves immediately if already connected) */
1039
+ waitForConnect(timeoutMs?: number): Promise<void>;
1040
+ /** Listen for a server event */
1041
+ on<E extends ServerEventName>(event: E, handler: ServerEventHandler<E>): this;
1042
+ /** Listen for a server event (one-time) */
1043
+ once<E extends ServerEventName>(event: E, handler: ServerEventHandler<E>): this;
1044
+ /** Remove a specific event listener */
1045
+ off<E extends ServerEventName>(event: E, handler: ServerEventHandler<E>): this;
1046
+ /** Remove all listeners for an event or all events */
1047
+ removeAllListeners(event?: ServerEventName): this;
1048
+ /** Listen for raw connection events (connect, disconnect, connect_error) */
1049
+ onConnect(handler: () => void): this;
1050
+ onDisconnect(handler: (reason: string) => void): this;
1051
+ onConnectError(handler: (error: Error) => void): this;
1052
+ /** Join a channel room to receive its messages and events */
1053
+ joinChannel(channelId: string): Promise<{
1054
+ ok: boolean;
1055
+ }>;
1056
+ /** Leave a channel room */
1057
+ leaveChannel(channelId: string): void;
1058
+ /** Send a message via WebSocket (text-only; for file attachments use REST) */
1059
+ sendMessage(data: {
1060
+ channelId: string;
1061
+ content: string;
1062
+ threadId?: string;
1063
+ replyToId?: string;
1064
+ }): void;
1065
+ /** Send a typing indicator */
1066
+ sendTyping(channelId: string): void;
1067
+ /** Update user presence status */
1068
+ updatePresence(status: 'online' | 'idle' | 'dnd' | 'offline'): void;
1069
+ /** Update activity status in a channel (e.g. 'thinking', 'working', null) */
1070
+ updateActivity(channelId: string, activity: string | null): void;
1071
+ /** Join a DM channel room */
1072
+ joinDmChannel(dmChannelId: string): void;
1073
+ /** Leave a DM channel room */
1074
+ leaveDmChannel(dmChannelId: string): void;
1075
+ /** Send a DM message via WebSocket */
1076
+ sendDmMessage(data: {
1077
+ dmChannelId: string;
1078
+ content: string;
1079
+ replyToId?: string;
1080
+ }): void;
1081
+ /** Send a DM typing indicator */
1082
+ sendDmTyping(dmChannelId: string): void;
1083
+ }
1084
+
1085
+ export { type ChannelCreatedPayload, type ChannelMemberAddedPayload, type ChannelMemberRemovedPayload, type ClientEventMap, type DmMessage, type MemberJoinPayload, type MemberLeavePayload, type MessageDeletedPayload, type PolicyChangedPayload, type PresenceActivityPayload, type PresenceChangePayload, type ReactionPayload, type ServerEventMap, type ServerJoinedPayload, type ShadowApp, type ShadowAttachment, type ShadowCartItem, type ShadowCategory, type ShadowChannel, type ShadowChannelPolicy, ShadowClient, type ShadowContract, type ShadowDmChannel, type ShadowFriendship, type ShadowInviteCode, type ShadowListing, type ShadowMember, type ShadowMessage, type ShadowNotification, type ShadowNotificationPreferences, type ShadowOAuthApp, type ShadowOAuthConsent, type ShadowOAuthToken, type ShadowOrder, type ShadowProduct, type ShadowRemoteChannel, type ShadowRemoteConfig, type ShadowRemoteServer, type ShadowReview, type ShadowServer, type ShadowShop, ShadowSocket, type ShadowSocketOptions, type ShadowTask, type ShadowThread, type ShadowTransaction, type ShadowUser, type ShadowWallet, type TypingPayload, channelRoom, threadRoom, userRoom };