@anticeil/sdk 0.0.0-stage → 1.0.0

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/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @anticeil/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official TypeScript & JavaScript client library for **Anticeil Chat**, Voice, Activities, and Bot Platform.
4
+
5
+ ## Features
6
+ - **Real-time WebSocket Gateway:** Listen for incoming messages, typing notifications, and presence events.
7
+ - **REST API Client:** Channels, colonies, messages, reactions, permissions, and webhook dispatching.
8
+ - **Embedded Activities:** Programmatically trigger collaborative Excalidraw whiteboards, YouTube Watch Together, and Chess.
9
+ - **Strict TypeScript Types:** Complete typing for colonies, channels, messages, users, and payloads.
10
+
11
+ ## Installation
12
+ ```bash
13
+ npm install @anticeil/sdk
14
+ ```
15
+
16
+ ## Quick Start
17
+ ```typescript
18
+ import { AnticeilClient } from '@anticeil/sdk';
19
+
20
+ const client = new AnticeilClient({
21
+ baseUrl: 'https://app.anticeil.com',
22
+ apiKey: process.env.ANTICEIL_API_KEY,
23
+ autoConnect: true,
24
+ });
25
+
26
+ client.on('message', async (msg) => {
27
+ if (msg.content === '!ping') {
28
+ await client.sendMessage(msg.channelId, 'Pong! 🏓', { replyToId: msg.id });
29
+ }
30
+ });
31
+ ```
32
+
33
+ ## License
34
+ MIT
@@ -0,0 +1,181 @@
1
+ interface AnticeilConfig {
2
+ token?: string;
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ socketUrl?: string;
6
+ autoConnect?: boolean;
7
+ }
8
+ interface Colony {
9
+ id: string;
10
+ name: string;
11
+ icon?: string;
12
+ description?: string;
13
+ ownerId?: string;
14
+ visibility?: 'public' | 'private';
15
+ accessSettings?: ColonyAccessSettings;
16
+ memberCount?: number;
17
+ createdAt?: string;
18
+ }
19
+ interface ColonyAccessSettings {
20
+ joinMethod: 'invite_only' | 'apply' | 'discoverable';
21
+ ageRestricted?: boolean;
22
+ rulesEnabled?: boolean;
23
+ rules?: string[];
24
+ screeningQuestions?: Array<{
25
+ id: string;
26
+ question: string;
27
+ required?: boolean;
28
+ }>;
29
+ }
30
+ interface Channel {
31
+ id: string;
32
+ colonyId: string;
33
+ name: string;
34
+ type: 'text' | 'voice' | 'kanban' | 'activity';
35
+ topic?: string;
36
+ isPrivate?: boolean;
37
+ categoryId?: string;
38
+ position?: number;
39
+ }
40
+ interface User {
41
+ id: string;
42
+ name: string;
43
+ username?: string;
44
+ email?: string;
45
+ avatar?: string;
46
+ role?: string;
47
+ status?: 'online' | 'idle' | 'dnd' | 'offline';
48
+ isBot?: boolean;
49
+ }
50
+ interface Message {
51
+ id: string;
52
+ channelId: string;
53
+ colonyId?: string;
54
+ content: string;
55
+ senderId: string;
56
+ senderName: string;
57
+ senderAvatar?: string;
58
+ senderRole?: string;
59
+ attachments?: string[];
60
+ replyToId?: string;
61
+ createdAt: string;
62
+ }
63
+ interface SendMessageOptions {
64
+ content: string;
65
+ attachments?: string[];
66
+ replyToId?: string;
67
+ }
68
+ interface WebhookPayload {
69
+ username?: string;
70
+ avatar_url?: string;
71
+ content: string;
72
+ attachments?: string[];
73
+ }
74
+ interface ActivityLaunchOptions {
75
+ channelId: string;
76
+ activityId: 'watch-together' | 'chess' | 'whiteboard' | string;
77
+ data?: Record<string, any>;
78
+ }
79
+
80
+ type EventHandler<T = any> = (data: T) => void;
81
+ declare class AnticeilClient {
82
+ private config;
83
+ private socket;
84
+ private eventHandlers;
85
+ constructor(config?: AnticeilConfig);
86
+ /**
87
+ * Connect to the Anticeil WebSocket real-time gateway
88
+ */
89
+ connect(): void;
90
+ /**
91
+ * Disconnect from the WebSocket real-time gateway
92
+ */
93
+ disconnect(): void;
94
+ /**
95
+ * Register an event listener (e.g. 'message', 'typing', 'connect', 'disconnect')
96
+ */
97
+ on<T = any>(event: string, handler: EventHandler<T>): this;
98
+ /**
99
+ * Remove an event listener
100
+ */
101
+ off<T = any>(event: string, handler: EventHandler<T>): this;
102
+ private emitInternal;
103
+ /**
104
+ * Internal REST fetch helper
105
+ */
106
+ private request;
107
+ messages: {
108
+ /**
109
+ * Send a text message to a channel
110
+ */
111
+ send: (channelId: string, options: string | SendMessageOptions) => Promise<Message>;
112
+ /**
113
+ * Fetch recent messages from a channel
114
+ */
115
+ list: (channelId: string, limit?: number) => Promise<Message[]>;
116
+ /**
117
+ * Delete a message by ID
118
+ */
119
+ delete: (channelId: string, messageId: string) => Promise<{
120
+ success: boolean;
121
+ }>;
122
+ };
123
+ channels: {
124
+ /**
125
+ * Get details of a channel
126
+ */
127
+ get: (channelId: string) => Promise<Channel>;
128
+ /**
129
+ * List all channels within a colony
130
+ */
131
+ list: (colonyId: string) => Promise<Channel[]>;
132
+ /**
133
+ * Create a new channel
134
+ */
135
+ create: (colonyId: string, data: Partial<Channel>) => Promise<Channel>;
136
+ };
137
+ colonies: {
138
+ /**
139
+ * List colonies that the authenticated user/bot belongs to
140
+ */
141
+ list: () => Promise<Colony[]>;
142
+ /**
143
+ * Get details of a colony
144
+ */
145
+ get: (colonyId: string) => Promise<Colony>;
146
+ /**
147
+ * Update colony details or access mode
148
+ */
149
+ update: (colonyId: string, updates: Partial<Colony>) => Promise<Colony>;
150
+ /**
151
+ * Set Colony privacy mode ('invite_only' | 'apply' | 'discoverable')
152
+ */
153
+ setPrivacy: (colonyId: string, joinMethod: "invite_only" | "apply" | "discoverable", options?: {
154
+ rulesEnabled?: boolean;
155
+ screeningQuestions?: Array<{
156
+ id: string;
157
+ question: string;
158
+ required?: boolean;
159
+ }>;
160
+ }) => Promise<Colony>;
161
+ };
162
+ webhooks: {
163
+ /**
164
+ * Send a formatted payload to an incoming webhook URL
165
+ */
166
+ send: (webhookUrl: string, payload: WebhookPayload) => Promise<{
167
+ success: boolean;
168
+ }>;
169
+ };
170
+ activities: {
171
+ /**
172
+ * Launch a voice activity (YouTube Watch Together, Chess, Whiteboard)
173
+ */
174
+ launch: (options: ActivityLaunchOptions) => Promise<{
175
+ success: boolean;
176
+ activityUrl: string;
177
+ }>;
178
+ };
179
+ }
180
+
181
+ export { type ActivityLaunchOptions, AnticeilClient, type AnticeilConfig, type Channel, type Colony, type ColonyAccessSettings, type Message, type SendMessageOptions, type User, type WebhookPayload };
@@ -0,0 +1,181 @@
1
+ interface AnticeilConfig {
2
+ token?: string;
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ socketUrl?: string;
6
+ autoConnect?: boolean;
7
+ }
8
+ interface Colony {
9
+ id: string;
10
+ name: string;
11
+ icon?: string;
12
+ description?: string;
13
+ ownerId?: string;
14
+ visibility?: 'public' | 'private';
15
+ accessSettings?: ColonyAccessSettings;
16
+ memberCount?: number;
17
+ createdAt?: string;
18
+ }
19
+ interface ColonyAccessSettings {
20
+ joinMethod: 'invite_only' | 'apply' | 'discoverable';
21
+ ageRestricted?: boolean;
22
+ rulesEnabled?: boolean;
23
+ rules?: string[];
24
+ screeningQuestions?: Array<{
25
+ id: string;
26
+ question: string;
27
+ required?: boolean;
28
+ }>;
29
+ }
30
+ interface Channel {
31
+ id: string;
32
+ colonyId: string;
33
+ name: string;
34
+ type: 'text' | 'voice' | 'kanban' | 'activity';
35
+ topic?: string;
36
+ isPrivate?: boolean;
37
+ categoryId?: string;
38
+ position?: number;
39
+ }
40
+ interface User {
41
+ id: string;
42
+ name: string;
43
+ username?: string;
44
+ email?: string;
45
+ avatar?: string;
46
+ role?: string;
47
+ status?: 'online' | 'idle' | 'dnd' | 'offline';
48
+ isBot?: boolean;
49
+ }
50
+ interface Message {
51
+ id: string;
52
+ channelId: string;
53
+ colonyId?: string;
54
+ content: string;
55
+ senderId: string;
56
+ senderName: string;
57
+ senderAvatar?: string;
58
+ senderRole?: string;
59
+ attachments?: string[];
60
+ replyToId?: string;
61
+ createdAt: string;
62
+ }
63
+ interface SendMessageOptions {
64
+ content: string;
65
+ attachments?: string[];
66
+ replyToId?: string;
67
+ }
68
+ interface WebhookPayload {
69
+ username?: string;
70
+ avatar_url?: string;
71
+ content: string;
72
+ attachments?: string[];
73
+ }
74
+ interface ActivityLaunchOptions {
75
+ channelId: string;
76
+ activityId: 'watch-together' | 'chess' | 'whiteboard' | string;
77
+ data?: Record<string, any>;
78
+ }
79
+
80
+ type EventHandler<T = any> = (data: T) => void;
81
+ declare class AnticeilClient {
82
+ private config;
83
+ private socket;
84
+ private eventHandlers;
85
+ constructor(config?: AnticeilConfig);
86
+ /**
87
+ * Connect to the Anticeil WebSocket real-time gateway
88
+ */
89
+ connect(): void;
90
+ /**
91
+ * Disconnect from the WebSocket real-time gateway
92
+ */
93
+ disconnect(): void;
94
+ /**
95
+ * Register an event listener (e.g. 'message', 'typing', 'connect', 'disconnect')
96
+ */
97
+ on<T = any>(event: string, handler: EventHandler<T>): this;
98
+ /**
99
+ * Remove an event listener
100
+ */
101
+ off<T = any>(event: string, handler: EventHandler<T>): this;
102
+ private emitInternal;
103
+ /**
104
+ * Internal REST fetch helper
105
+ */
106
+ private request;
107
+ messages: {
108
+ /**
109
+ * Send a text message to a channel
110
+ */
111
+ send: (channelId: string, options: string | SendMessageOptions) => Promise<Message>;
112
+ /**
113
+ * Fetch recent messages from a channel
114
+ */
115
+ list: (channelId: string, limit?: number) => Promise<Message[]>;
116
+ /**
117
+ * Delete a message by ID
118
+ */
119
+ delete: (channelId: string, messageId: string) => Promise<{
120
+ success: boolean;
121
+ }>;
122
+ };
123
+ channels: {
124
+ /**
125
+ * Get details of a channel
126
+ */
127
+ get: (channelId: string) => Promise<Channel>;
128
+ /**
129
+ * List all channels within a colony
130
+ */
131
+ list: (colonyId: string) => Promise<Channel[]>;
132
+ /**
133
+ * Create a new channel
134
+ */
135
+ create: (colonyId: string, data: Partial<Channel>) => Promise<Channel>;
136
+ };
137
+ colonies: {
138
+ /**
139
+ * List colonies that the authenticated user/bot belongs to
140
+ */
141
+ list: () => Promise<Colony[]>;
142
+ /**
143
+ * Get details of a colony
144
+ */
145
+ get: (colonyId: string) => Promise<Colony>;
146
+ /**
147
+ * Update colony details or access mode
148
+ */
149
+ update: (colonyId: string, updates: Partial<Colony>) => Promise<Colony>;
150
+ /**
151
+ * Set Colony privacy mode ('invite_only' | 'apply' | 'discoverable')
152
+ */
153
+ setPrivacy: (colonyId: string, joinMethod: "invite_only" | "apply" | "discoverable", options?: {
154
+ rulesEnabled?: boolean;
155
+ screeningQuestions?: Array<{
156
+ id: string;
157
+ question: string;
158
+ required?: boolean;
159
+ }>;
160
+ }) => Promise<Colony>;
161
+ };
162
+ webhooks: {
163
+ /**
164
+ * Send a formatted payload to an incoming webhook URL
165
+ */
166
+ send: (webhookUrl: string, payload: WebhookPayload) => Promise<{
167
+ success: boolean;
168
+ }>;
169
+ };
170
+ activities: {
171
+ /**
172
+ * Launch a voice activity (YouTube Watch Together, Chess, Whiteboard)
173
+ */
174
+ launch: (options: ActivityLaunchOptions) => Promise<{
175
+ success: boolean;
176
+ activityUrl: string;
177
+ }>;
178
+ };
179
+ }
180
+
181
+ export { type ActivityLaunchOptions, AnticeilClient, type AnticeilConfig, type Channel, type Colony, type ColonyAccessSettings, type Message, type SendMessageOptions, type User, type WebhookPayload };
package/dist/index.js ADDED
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AnticeilClient: () => AnticeilClient
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/client.ts
28
+ var import_socket = require("socket.io-client");
29
+ var AnticeilClient = class {
30
+ config;
31
+ socket = null;
32
+ eventHandlers = /* @__PURE__ */ new Map();
33
+ constructor(config = {}) {
34
+ this.config = {
35
+ token: config.token || "",
36
+ apiKey: config.apiKey || "",
37
+ baseUrl: config.baseUrl || "https://app.anticeil.com",
38
+ socketUrl: config.socketUrl || "https://app.anticeil.com",
39
+ autoConnect: config.autoConnect ?? false
40
+ };
41
+ if (this.config.autoConnect) {
42
+ this.connect();
43
+ }
44
+ }
45
+ /**
46
+ * Connect to the Anticeil WebSocket real-time gateway
47
+ */
48
+ connect() {
49
+ if (this.socket?.connected) return;
50
+ this.socket = (0, import_socket.io)(this.config.socketUrl, {
51
+ path: "/api/socket.io",
52
+ transports: ["websocket"],
53
+ auth: {
54
+ token: this.config.token || this.config.apiKey
55
+ }
56
+ });
57
+ this.socket.on("connect", () => {
58
+ this.emitInternal("connect", { id: this.socket?.id });
59
+ });
60
+ this.socket.on("disconnect", (reason) => {
61
+ this.emitInternal("disconnect", { reason });
62
+ });
63
+ this.socket.on("message_created", (raw) => {
64
+ const msg = {
65
+ id: raw.id || `msg_${Date.now()}`,
66
+ channelId: raw.channelId,
67
+ colonyId: raw.colonyId,
68
+ content: raw.content || "",
69
+ senderId: raw.senderId || raw.userId,
70
+ senderName: raw.senderName || raw.userName || "Anonymous",
71
+ senderAvatar: raw.senderAvatar || raw.userAvatar,
72
+ senderRole: raw.senderRole,
73
+ attachments: raw.attachments || [],
74
+ replyToId: raw.replyToId,
75
+ createdAt: raw.createdAt || (/* @__PURE__ */ new Date()).toISOString()
76
+ };
77
+ this.emitInternal("message", msg);
78
+ });
79
+ this.socket.on("user_typing", (data) => {
80
+ this.emitInternal("typing", data);
81
+ });
82
+ this.socket.on("presence_update", (data) => {
83
+ this.emitInternal("presence", data);
84
+ });
85
+ }
86
+ /**
87
+ * Disconnect from the WebSocket real-time gateway
88
+ */
89
+ disconnect() {
90
+ if (this.socket) {
91
+ this.socket.disconnect();
92
+ this.socket = null;
93
+ }
94
+ }
95
+ /**
96
+ * Register an event listener (e.g. 'message', 'typing', 'connect', 'disconnect')
97
+ */
98
+ on(event, handler) {
99
+ if (!this.eventHandlers.has(event)) {
100
+ this.eventHandlers.set(event, /* @__PURE__ */ new Set());
101
+ }
102
+ this.eventHandlers.get(event).add(handler);
103
+ return this;
104
+ }
105
+ /**
106
+ * Remove an event listener
107
+ */
108
+ off(event, handler) {
109
+ this.eventHandlers.get(event)?.delete(handler);
110
+ return this;
111
+ }
112
+ emitInternal(event, data) {
113
+ this.eventHandlers.get(event)?.forEach((handler) => {
114
+ try {
115
+ handler(data);
116
+ } catch (err) {
117
+ console.error(`[AnticeilClient] Error in '${event}' event listener:`, err);
118
+ }
119
+ });
120
+ }
121
+ /**
122
+ * Internal REST fetch helper
123
+ */
124
+ async request(endpoint, options = {}) {
125
+ const url = `${this.config.baseUrl}${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
126
+ const headers = new Headers(options.headers);
127
+ if (this.config.token) {
128
+ headers.set("Authorization", `Bearer ${this.config.token}`);
129
+ } else if (this.config.apiKey) {
130
+ headers.set("X-Anticeil-Api-Key", this.config.apiKey);
131
+ }
132
+ headers.set("Content-Type", "application/json");
133
+ const res = await fetch(url, { ...options, headers });
134
+ if (!res.ok) {
135
+ const errorText = await res.text().catch(() => res.statusText);
136
+ throw new Error(`Anticeil API Error [${res.status}]: ${errorText}`);
137
+ }
138
+ return res.json();
139
+ }
140
+ // ==========================================
141
+ // MESSAGES API
142
+ // ==========================================
143
+ messages = {
144
+ /**
145
+ * Send a text message to a channel
146
+ */
147
+ send: async (channelId, options) => {
148
+ const payload = typeof options === "string" ? { content: options } : options;
149
+ if (this.socket?.connected) {
150
+ this.socket.emit("send_message", { channelId, ...payload });
151
+ }
152
+ return this.request(`/api/channels/${channelId}/messages`, {
153
+ method: "POST",
154
+ body: JSON.stringify(payload)
155
+ });
156
+ },
157
+ /**
158
+ * Fetch recent messages from a channel
159
+ */
160
+ list: async (channelId, limit = 50) => {
161
+ return this.request(`/api/channels/${channelId}/messages?limit=${limit}`);
162
+ },
163
+ /**
164
+ * Delete a message by ID
165
+ */
166
+ delete: async (channelId, messageId) => {
167
+ return this.request(`/api/channels/${channelId}/messages/${messageId}`, {
168
+ method: "DELETE"
169
+ });
170
+ }
171
+ };
172
+ // ==========================================
173
+ // CHANNELS API
174
+ // ==========================================
175
+ channels = {
176
+ /**
177
+ * Get details of a channel
178
+ */
179
+ get: async (channelId) => {
180
+ return this.request(`/api/channels/${channelId}`);
181
+ },
182
+ /**
183
+ * List all channels within a colony
184
+ */
185
+ list: async (colonyId) => {
186
+ return this.request(`/api/colonies/${colonyId}/channels`);
187
+ },
188
+ /**
189
+ * Create a new channel
190
+ */
191
+ create: async (colonyId, data) => {
192
+ return this.request(`/api/colonies/${colonyId}/channels`, {
193
+ method: "POST",
194
+ body: JSON.stringify(data)
195
+ });
196
+ }
197
+ };
198
+ // ==========================================
199
+ // COLONIES API
200
+ // ==========================================
201
+ colonies = {
202
+ /**
203
+ * List colonies that the authenticated user/bot belongs to
204
+ */
205
+ list: async () => {
206
+ return this.request("/api/colonies");
207
+ },
208
+ /**
209
+ * Get details of a colony
210
+ */
211
+ get: async (colonyId) => {
212
+ return this.request(`/api/colonies/${colonyId}`);
213
+ },
214
+ /**
215
+ * Update colony details or access mode
216
+ */
217
+ update: async (colonyId, updates) => {
218
+ return this.request(`/api/colonies/${colonyId}`, {
219
+ method: "PATCH",
220
+ body: JSON.stringify(updates)
221
+ });
222
+ },
223
+ /**
224
+ * Set Colony privacy mode ('invite_only' | 'apply' | 'discoverable')
225
+ */
226
+ setPrivacy: async (colonyId, joinMethod, options = {}) => {
227
+ return this.request(`/api/colonies/${colonyId}/access`, {
228
+ method: "PUT",
229
+ body: JSON.stringify({
230
+ joinMethod,
231
+ visibility: joinMethod === "discoverable" ? "public" : "private",
232
+ ...options
233
+ })
234
+ });
235
+ }
236
+ };
237
+ // ==========================================
238
+ // WEBHOOKS API
239
+ // ==========================================
240
+ webhooks = {
241
+ /**
242
+ * Send a formatted payload to an incoming webhook URL
243
+ */
244
+ send: async (webhookUrl, payload) => {
245
+ const res = await fetch(webhookUrl, {
246
+ method: "POST",
247
+ headers: { "Content-Type": "application/json" },
248
+ body: JSON.stringify(payload)
249
+ });
250
+ if (!res.ok) {
251
+ throw new Error(`Webhook Error [${res.status}]: ${await res.text()}`);
252
+ }
253
+ return { success: true };
254
+ }
255
+ };
256
+ // ==========================================
257
+ // ACTIVITIES API
258
+ // ==========================================
259
+ activities = {
260
+ /**
261
+ * Launch a voice activity (YouTube Watch Together, Chess, Whiteboard)
262
+ */
263
+ launch: async (options) => {
264
+ if (this.socket?.connected) {
265
+ this.socket.emit("launch_activity", options);
266
+ }
267
+ return this.request(
268
+ `/api/channels/${options.channelId}/activity`,
269
+ {
270
+ method: "POST",
271
+ body: JSON.stringify(options)
272
+ }
273
+ );
274
+ }
275
+ };
276
+ };
277
+ // Annotate the CommonJS export names for ESM import in node:
278
+ 0 && (module.exports = {
279
+ AnticeilClient
280
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,253 @@
1
+ // src/client.ts
2
+ import { io } from "socket.io-client";
3
+ var AnticeilClient = class {
4
+ config;
5
+ socket = null;
6
+ eventHandlers = /* @__PURE__ */ new Map();
7
+ constructor(config = {}) {
8
+ this.config = {
9
+ token: config.token || "",
10
+ apiKey: config.apiKey || "",
11
+ baseUrl: config.baseUrl || "https://app.anticeil.com",
12
+ socketUrl: config.socketUrl || "https://app.anticeil.com",
13
+ autoConnect: config.autoConnect ?? false
14
+ };
15
+ if (this.config.autoConnect) {
16
+ this.connect();
17
+ }
18
+ }
19
+ /**
20
+ * Connect to the Anticeil WebSocket real-time gateway
21
+ */
22
+ connect() {
23
+ if (this.socket?.connected) return;
24
+ this.socket = io(this.config.socketUrl, {
25
+ path: "/api/socket.io",
26
+ transports: ["websocket"],
27
+ auth: {
28
+ token: this.config.token || this.config.apiKey
29
+ }
30
+ });
31
+ this.socket.on("connect", () => {
32
+ this.emitInternal("connect", { id: this.socket?.id });
33
+ });
34
+ this.socket.on("disconnect", (reason) => {
35
+ this.emitInternal("disconnect", { reason });
36
+ });
37
+ this.socket.on("message_created", (raw) => {
38
+ const msg = {
39
+ id: raw.id || `msg_${Date.now()}`,
40
+ channelId: raw.channelId,
41
+ colonyId: raw.colonyId,
42
+ content: raw.content || "",
43
+ senderId: raw.senderId || raw.userId,
44
+ senderName: raw.senderName || raw.userName || "Anonymous",
45
+ senderAvatar: raw.senderAvatar || raw.userAvatar,
46
+ senderRole: raw.senderRole,
47
+ attachments: raw.attachments || [],
48
+ replyToId: raw.replyToId,
49
+ createdAt: raw.createdAt || (/* @__PURE__ */ new Date()).toISOString()
50
+ };
51
+ this.emitInternal("message", msg);
52
+ });
53
+ this.socket.on("user_typing", (data) => {
54
+ this.emitInternal("typing", data);
55
+ });
56
+ this.socket.on("presence_update", (data) => {
57
+ this.emitInternal("presence", data);
58
+ });
59
+ }
60
+ /**
61
+ * Disconnect from the WebSocket real-time gateway
62
+ */
63
+ disconnect() {
64
+ if (this.socket) {
65
+ this.socket.disconnect();
66
+ this.socket = null;
67
+ }
68
+ }
69
+ /**
70
+ * Register an event listener (e.g. 'message', 'typing', 'connect', 'disconnect')
71
+ */
72
+ on(event, handler) {
73
+ if (!this.eventHandlers.has(event)) {
74
+ this.eventHandlers.set(event, /* @__PURE__ */ new Set());
75
+ }
76
+ this.eventHandlers.get(event).add(handler);
77
+ return this;
78
+ }
79
+ /**
80
+ * Remove an event listener
81
+ */
82
+ off(event, handler) {
83
+ this.eventHandlers.get(event)?.delete(handler);
84
+ return this;
85
+ }
86
+ emitInternal(event, data) {
87
+ this.eventHandlers.get(event)?.forEach((handler) => {
88
+ try {
89
+ handler(data);
90
+ } catch (err) {
91
+ console.error(`[AnticeilClient] Error in '${event}' event listener:`, err);
92
+ }
93
+ });
94
+ }
95
+ /**
96
+ * Internal REST fetch helper
97
+ */
98
+ async request(endpoint, options = {}) {
99
+ const url = `${this.config.baseUrl}${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
100
+ const headers = new Headers(options.headers);
101
+ if (this.config.token) {
102
+ headers.set("Authorization", `Bearer ${this.config.token}`);
103
+ } else if (this.config.apiKey) {
104
+ headers.set("X-Anticeil-Api-Key", this.config.apiKey);
105
+ }
106
+ headers.set("Content-Type", "application/json");
107
+ const res = await fetch(url, { ...options, headers });
108
+ if (!res.ok) {
109
+ const errorText = await res.text().catch(() => res.statusText);
110
+ throw new Error(`Anticeil API Error [${res.status}]: ${errorText}`);
111
+ }
112
+ return res.json();
113
+ }
114
+ // ==========================================
115
+ // MESSAGES API
116
+ // ==========================================
117
+ messages = {
118
+ /**
119
+ * Send a text message to a channel
120
+ */
121
+ send: async (channelId, options) => {
122
+ const payload = typeof options === "string" ? { content: options } : options;
123
+ if (this.socket?.connected) {
124
+ this.socket.emit("send_message", { channelId, ...payload });
125
+ }
126
+ return this.request(`/api/channels/${channelId}/messages`, {
127
+ method: "POST",
128
+ body: JSON.stringify(payload)
129
+ });
130
+ },
131
+ /**
132
+ * Fetch recent messages from a channel
133
+ */
134
+ list: async (channelId, limit = 50) => {
135
+ return this.request(`/api/channels/${channelId}/messages?limit=${limit}`);
136
+ },
137
+ /**
138
+ * Delete a message by ID
139
+ */
140
+ delete: async (channelId, messageId) => {
141
+ return this.request(`/api/channels/${channelId}/messages/${messageId}`, {
142
+ method: "DELETE"
143
+ });
144
+ }
145
+ };
146
+ // ==========================================
147
+ // CHANNELS API
148
+ // ==========================================
149
+ channels = {
150
+ /**
151
+ * Get details of a channel
152
+ */
153
+ get: async (channelId) => {
154
+ return this.request(`/api/channels/${channelId}`);
155
+ },
156
+ /**
157
+ * List all channels within a colony
158
+ */
159
+ list: async (colonyId) => {
160
+ return this.request(`/api/colonies/${colonyId}/channels`);
161
+ },
162
+ /**
163
+ * Create a new channel
164
+ */
165
+ create: async (colonyId, data) => {
166
+ return this.request(`/api/colonies/${colonyId}/channels`, {
167
+ method: "POST",
168
+ body: JSON.stringify(data)
169
+ });
170
+ }
171
+ };
172
+ // ==========================================
173
+ // COLONIES API
174
+ // ==========================================
175
+ colonies = {
176
+ /**
177
+ * List colonies that the authenticated user/bot belongs to
178
+ */
179
+ list: async () => {
180
+ return this.request("/api/colonies");
181
+ },
182
+ /**
183
+ * Get details of a colony
184
+ */
185
+ get: async (colonyId) => {
186
+ return this.request(`/api/colonies/${colonyId}`);
187
+ },
188
+ /**
189
+ * Update colony details or access mode
190
+ */
191
+ update: async (colonyId, updates) => {
192
+ return this.request(`/api/colonies/${colonyId}`, {
193
+ method: "PATCH",
194
+ body: JSON.stringify(updates)
195
+ });
196
+ },
197
+ /**
198
+ * Set Colony privacy mode ('invite_only' | 'apply' | 'discoverable')
199
+ */
200
+ setPrivacy: async (colonyId, joinMethod, options = {}) => {
201
+ return this.request(`/api/colonies/${colonyId}/access`, {
202
+ method: "PUT",
203
+ body: JSON.stringify({
204
+ joinMethod,
205
+ visibility: joinMethod === "discoverable" ? "public" : "private",
206
+ ...options
207
+ })
208
+ });
209
+ }
210
+ };
211
+ // ==========================================
212
+ // WEBHOOKS API
213
+ // ==========================================
214
+ webhooks = {
215
+ /**
216
+ * Send a formatted payload to an incoming webhook URL
217
+ */
218
+ send: async (webhookUrl, payload) => {
219
+ const res = await fetch(webhookUrl, {
220
+ method: "POST",
221
+ headers: { "Content-Type": "application/json" },
222
+ body: JSON.stringify(payload)
223
+ });
224
+ if (!res.ok) {
225
+ throw new Error(`Webhook Error [${res.status}]: ${await res.text()}`);
226
+ }
227
+ return { success: true };
228
+ }
229
+ };
230
+ // ==========================================
231
+ // ACTIVITIES API
232
+ // ==========================================
233
+ activities = {
234
+ /**
235
+ * Launch a voice activity (YouTube Watch Together, Chess, Whiteboard)
236
+ */
237
+ launch: async (options) => {
238
+ if (this.socket?.connected) {
239
+ this.socket.emit("launch_activity", options);
240
+ }
241
+ return this.request(
242
+ `/api/channels/${options.channelId}/activity`,
243
+ {
244
+ method: "POST",
245
+ body: JSON.stringify(options)
246
+ }
247
+ );
248
+ }
249
+ };
250
+ };
251
+ export {
252
+ AnticeilClient
253
+ };
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@anticeil/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Official TypeScript & JavaScript SDK for Anticeil Chat, Voice, Activities, and Bot Platform",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "anticeil",
24
+ "chat",
25
+ "webrtc",
26
+ "bot",
27
+ "sdk",
28
+ "realtime",
29
+ "websocket"
30
+ ],
31
+ "author": "Anticeil Team <dev@anticeil.com>",
32
+ "license": "MIT",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "dependencies": {
37
+ "socket.io-client": "^4.8.1"
38
+ },
39
+ "devDependencies": {
40
+ "tsup": "^8.3.6",
41
+ "typescript": "^5.7.3"
42
+ }
43
+ }