@superatomai/sdk-node 0.0.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/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # @superatomai/sdk
2
+
3
+ A TypeScript SDK for building applications with Superatom - a platform for creating data-driven, AI-powered applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @superatomai/sdk
9
+ ```
10
+
11
+ Or with pnpm:
12
+
13
+ ```bash
14
+ pnpm add @superatomai/sdk
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import { SuperatomSDK } from '@superatomai/sdk';
21
+
22
+ // Initialize the SDK
23
+ const sdk = new SuperatomSDK({
24
+ apiKey: 'your-api-key',
25
+ projectId: 'your-project-id',
26
+ userId: 'user-123', // optional, defaults to 'anonymous'
27
+ type: 'data-agent', // optional, defaults to 'data-agent'
28
+ });
29
+
30
+ // The SDK automatically connects to the Superatom WebSocket service
31
+ // Wait for connection before using
32
+ await sdk.connect();
33
+
34
+ // Register a collection handler for data operations
35
+ sdk.addCollection('users', 'list', async (params) => {
36
+ // Your custom logic to fetch users
37
+ return {
38
+ data: [
39
+ { id: 1, name: 'John Doe' },
40
+ { id: 2, name: 'Jane Smith' },
41
+ ],
42
+ };
43
+ });
44
+
45
+ // Listen to all incoming messages
46
+ sdk.onMessage((message) => {
47
+ console.log('Received message:', message);
48
+ });
49
+
50
+ // Send messages to the Superatom service
51
+ sdk.send({
52
+ type: 'custom_message',
53
+ data: { foo: 'bar' },
54
+ });
55
+
56
+ // Cleanup when done
57
+ await sdk.destroy();
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ ### SuperatomSDKConfig
63
+
64
+ ```typescript
65
+ interface SuperatomSDKConfig {
66
+ apiKey: string; // Required: Your Superatom API key
67
+ projectId: string; // Required: Your project ID
68
+ userId?: string; // Optional: User identifier (default: 'anonymous')
69
+ type?: string; // Optional: Agent type (default: 'data-agent')
70
+ bundleDir?: string; // Optional: Directory for bundle requests
71
+ url?: string; // Optional: Custom WebSocket URL
72
+ ANTHROPIC_API_KEY?: string; // Optional: Anthropic API key for LLM
73
+ GROQ_API_KEY?: string; // Optional: Groq API key for LLM
74
+ LLM_PROVIDERS?: LLMProvider[]; // Optional: Custom LLM providers
75
+ }
76
+ ```
77
+
78
+ Environment variables are also supported:
79
+ - `SA_WEBSOCKET_URL`: WebSocket URL (default: `wss://ws.superatom.ai/websocket`)
80
+ - `ANTHROPIC_API_KEY`: Anthropic API key
81
+ - `GROQ_API_KEY`: Groq API key
82
+
83
+ ## Key Features
84
+
85
+ ### Collection Handlers
86
+
87
+ Register handlers for data operations:
88
+
89
+ ```typescript
90
+ sdk.addCollection<ParamsType, ResultType>(
91
+ 'collection-name',
92
+ 'operation',
93
+ async (params) => {
94
+ // Your custom logic
95
+ return result;
96
+ }
97
+ );
98
+ ```
99
+
100
+ ### Message Handling
101
+
102
+ Listen to all messages:
103
+
104
+ ```typescript
105
+ const unsubscribe = sdk.onMessage((message) => {
106
+ console.log('Message received:', message);
107
+ });
108
+
109
+ // Unsubscribe when needed
110
+ unsubscribe();
111
+ ```
112
+
113
+ Listen to specific message types:
114
+
115
+ ```typescript
116
+ const unsubscribe = sdk.onMessageType('custom_type', (message) => {
117
+ console.log('Custom message:', message);
118
+ });
119
+ ```
120
+
121
+ ### User Management
122
+
123
+ ```typescript
124
+ const userManager = sdk.getUserManager();
125
+
126
+ // Create a user
127
+ await userManager.createUser({
128
+ id: 'user-123',
129
+ name: 'John Doe',
130
+ email: 'john@example.com',
131
+ });
132
+
133
+ // Get a user
134
+ const user = await userManager.getUser('user-123');
135
+
136
+ // Update a user
137
+ await userManager.updateUser('user-123', { name: 'John Updated' });
138
+
139
+ // Delete a user
140
+ await userManager.deleteUser('user-123');
141
+ ```
142
+
143
+ ### LLM Integration
144
+
145
+ ```typescript
146
+ import { LLM } from '@superatomai/sdk';
147
+
148
+ const llm = new LLM({
149
+ apiKey: 'your-anthropic-or-groq-api-key',
150
+ provider: 'anthropic', // or 'groq'
151
+ });
152
+
153
+ // Generate text
154
+ const response = await llm.text('What is the meaning of life?');
155
+
156
+ // Stream responses
157
+ for await (const chunk of llm.stream('Tell me a story')) {
158
+ process.stdout.write(chunk);
159
+ }
160
+ ```
161
+
162
+ ### Thread Management
163
+
164
+ ```typescript
165
+ import { Thread, UIBlock, ThreadManager } from '@superatomai/sdk';
166
+
167
+ const threadManager = new ThreadManager();
168
+
169
+ // Create a thread
170
+ const thread = threadManager.createThread({
171
+ userId: 'user-123',
172
+ metadata: { source: 'chat' },
173
+ });
174
+
175
+ // Add UI blocks to thread
176
+ thread.addBlock(
177
+ new UIBlock('block-1', 'text', { content: 'Hello, World!' })
178
+ );
179
+
180
+ // Get all threads
181
+ const threads = threadManager.getAllThreads();
182
+
183
+ // Cleanup old threads
184
+ await threadManager.cleanup();
185
+ ```
186
+
187
+ ### Cleanup Service
188
+
189
+ ```typescript
190
+ import { CleanupService } from '@superatomai/sdk';
191
+
192
+ const cleanupService = new CleanupService();
193
+
194
+ // Register cleanup tasks
195
+ cleanupService.registerTask('threads', async () => {
196
+ // Your cleanup logic
197
+ });
198
+
199
+ // Start periodic cleanup (every 5 minutes by default)
200
+ cleanupService.start();
201
+
202
+ // Stop cleanup
203
+ cleanupService.stop();
204
+ ```
205
+
206
+ ## API Reference
207
+
208
+ ### SuperatomSDK Methods
209
+
210
+ - `connect(): Promise<void>` - Connect to the WebSocket service
211
+ - `disconnect(): void` - Disconnect from the WebSocket service
212
+ - `destroy(): Promise<void>` - Cleanup and disconnect permanently
213
+ - `isConnected(): boolean` - Check connection status
214
+ - `send(message: Message): void` - Send a message to Superatom
215
+ - `onMessage(handler): () => void` - Register a message handler
216
+ - `onMessageType(type, handler): () => void` - Register a type-specific handler
217
+ - `addCollection(name, operation, handler): void` - Register a collection handler
218
+ - `getUserManager(): UserManager` - Get the user manager instance
219
+
220
+ ## TypeScript Support
221
+
222
+ This SDK is written in TypeScript and includes full type definitions. All exports are fully typed for the best development experience.
223
+
224
+ ## License
225
+
226
+ MIT
227
+
228
+ ## Support
229
+
230
+ For issues and questions:
231
+ - GitHub Issues: [Report an issue](https://github.com/superatomai/sdk-nodejs/issues)
232
+ - Email: ashish@superatom.ai