@superatomai/sdk-web 0.0.8 → 0.0.9
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 +128 -3
- package/dist/index.cjs +30 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +30 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,13 +8,14 @@ SuperAtom Web SDK - TypeScript SDK for browser-based WebSocket communication wit
|
|
|
8
8
|
- 🔒 Type-safe message validation using Zod v4
|
|
9
9
|
- 🎯 Request/response pattern with timeout support
|
|
10
10
|
- 📦 Bundle management with chunked transfer
|
|
11
|
-
- 🧩 Component registration system
|
|
11
|
+
- 🧩 Component registration and communication system
|
|
12
12
|
- 🔐 Authentication (login and token verification)
|
|
13
13
|
- 👥 User management (CRUD operations)
|
|
14
14
|
- 📊 Dashboard management (CRUD operations)
|
|
15
15
|
- 📈 Report management (CRUD operations)
|
|
16
|
-
- 🤖 AI component suggestions
|
|
16
|
+
- 🤖 AI component suggestions with text streaming support
|
|
17
17
|
- 💾 Data collection queries
|
|
18
|
+
- ⚡ Actions API for runtime operations
|
|
18
19
|
- 📝 UI logging support
|
|
19
20
|
|
|
20
21
|
## Installation
|
|
@@ -226,11 +227,25 @@ const result = await client.getReport(reportId, timeout);
|
|
|
226
227
|
#### User Prompts & AI Suggestions
|
|
227
228
|
|
|
228
229
|
```typescript
|
|
229
|
-
// Send a user prompt request
|
|
230
|
+
// Send a user prompt request (component mode - default)
|
|
230
231
|
const response = await client.sendUserPromptRequest(
|
|
231
232
|
prompt,
|
|
232
233
|
threadId,
|
|
233
234
|
uiBlockId,
|
|
235
|
+
'component', // responseMode: 'component' (default) or 'text'
|
|
236
|
+
undefined, // onStream callback (only used for text mode)
|
|
237
|
+
timeout
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// Send a user prompt request with text streaming
|
|
241
|
+
const response = await client.sendUserPromptRequest(
|
|
242
|
+
prompt,
|
|
243
|
+
threadId,
|
|
244
|
+
uiBlockId,
|
|
245
|
+
'text', // responseMode: 'text' for streaming
|
|
246
|
+
(chunk) => { // onStream callback receives text chunks
|
|
247
|
+
console.log('Stream chunk:', chunk);
|
|
248
|
+
},
|
|
234
249
|
timeout
|
|
235
250
|
);
|
|
236
251
|
|
|
@@ -263,6 +278,36 @@ const result = await client.requestData({
|
|
|
263
278
|
// Returns: { data?, error? }
|
|
264
279
|
```
|
|
265
280
|
|
|
281
|
+
#### Actions API
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
// Get available actions for the current context
|
|
285
|
+
const result = await client.getActions({
|
|
286
|
+
SA_RUNTIME: {
|
|
287
|
+
threadId: 'thread_123',
|
|
288
|
+
uiBlockId: 'block_456'
|
|
289
|
+
},
|
|
290
|
+
timeout: 10000
|
|
291
|
+
});
|
|
292
|
+
// Returns: { success, data?, error? }
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### Component Management
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
// Send component list to server
|
|
299
|
+
await client.sendComponents([
|
|
300
|
+
{
|
|
301
|
+
id: 'comp_1',
|
|
302
|
+
name: 'MyComponent',
|
|
303
|
+
type: 'custom',
|
|
304
|
+
description: 'A custom component',
|
|
305
|
+
props: { /* ... */ }
|
|
306
|
+
},
|
|
307
|
+
// ... more components
|
|
308
|
+
]);
|
|
309
|
+
```
|
|
310
|
+
|
|
266
311
|
### Component Setup
|
|
267
312
|
|
|
268
313
|
Register your components with SuperAtom for dynamic rendering.
|
|
@@ -297,6 +342,7 @@ The SDK supports the following message types (all validated with Zod schemas):
|
|
|
297
342
|
|
|
298
343
|
**User Prompts & AI**
|
|
299
344
|
- `USER_PROMPT_REQ` / `USER_PROMPT_RES` - User prompt processing
|
|
345
|
+
- `USER_PROMPT_STREAM` - Real-time text streaming from AI responses
|
|
300
346
|
- `USER_PROMPT_SUGGESTIONS_REQ` / `USER_PROMPT_SUGGESTIONS_RES` - Component suggestions
|
|
301
347
|
|
|
302
348
|
**Bundle & Data**
|
|
@@ -308,6 +354,10 @@ The SDK supports the following message types (all validated with Zod schemas):
|
|
|
308
354
|
- `DASHBOARDS` / `DASHBOARDS_RES` - Dashboard CRUD operations
|
|
309
355
|
- `REPORTS` / `REPORTS_RES` - Report CRUD operations
|
|
310
356
|
|
|
357
|
+
**Actions & Components**
|
|
358
|
+
- `ACTIONS` / `ACTIONS_RES` - Runtime actions API
|
|
359
|
+
- `COMPONENT_LIST_RES` - Send component list to server
|
|
360
|
+
|
|
311
361
|
**Logging**
|
|
312
362
|
- `UI_LOGS` - UI logging messages
|
|
313
363
|
|
|
@@ -577,6 +627,81 @@ if (!result.error && result.data) {
|
|
|
577
627
|
}
|
|
578
628
|
```
|
|
579
629
|
|
|
630
|
+
### Text Streaming Example
|
|
631
|
+
|
|
632
|
+
```typescript
|
|
633
|
+
import { SuperatomClient } from '@superatomai/sdk-web';
|
|
634
|
+
|
|
635
|
+
const client = new SuperatomClient({
|
|
636
|
+
userId: 'user_123',
|
|
637
|
+
projectId: 'project_456',
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
await client.connect();
|
|
641
|
+
|
|
642
|
+
// Use text streaming for real-time AI responses
|
|
643
|
+
let streamedText = '';
|
|
644
|
+
|
|
645
|
+
const response = await client.sendUserPromptRequest(
|
|
646
|
+
'Explain how photosynthesis works',
|
|
647
|
+
'thread_123',
|
|
648
|
+
'block_456',
|
|
649
|
+
'text', // Enable text streaming mode
|
|
650
|
+
(chunk) => {
|
|
651
|
+
// Receive text chunks in real-time
|
|
652
|
+
streamedText += chunk;
|
|
653
|
+
console.log('Received chunk:', chunk);
|
|
654
|
+
// Update UI with streaming text
|
|
655
|
+
updateUIWithText(streamedText);
|
|
656
|
+
},
|
|
657
|
+
30000
|
|
658
|
+
);
|
|
659
|
+
|
|
660
|
+
console.log('Streaming complete. Final response:', response);
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
### Actions API Example
|
|
664
|
+
|
|
665
|
+
```typescript
|
|
666
|
+
import { SuperatomClient } from '@superatomai/sdk-web';
|
|
667
|
+
|
|
668
|
+
const client = new SuperatomClient({
|
|
669
|
+
userId: 'user_123',
|
|
670
|
+
projectId: 'project_456',
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
await client.connect();
|
|
674
|
+
|
|
675
|
+
// Get available actions for the current runtime context
|
|
676
|
+
const result = await client.getActions({
|
|
677
|
+
SA_RUNTIME: {
|
|
678
|
+
threadId: 'thread_123',
|
|
679
|
+
uiBlockId: 'block_456'
|
|
680
|
+
},
|
|
681
|
+
timeout: 10000
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
if (result.success && result.data) {
|
|
685
|
+
console.log('Available actions:', result.data);
|
|
686
|
+
} else {
|
|
687
|
+
console.error('Error:', result.error);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// Send component list to server
|
|
691
|
+
await client.sendComponents([
|
|
692
|
+
{
|
|
693
|
+
id: 'my_component_1',
|
|
694
|
+
name: 'DataTable',
|
|
695
|
+
type: 'table',
|
|
696
|
+
description: 'Display data in table format',
|
|
697
|
+
props: {
|
|
698
|
+
columns: ['name', 'email', 'status'],
|
|
699
|
+
data: []
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
]);
|
|
703
|
+
```
|
|
704
|
+
|
|
580
705
|
## Advanced Usage
|
|
581
706
|
|
|
582
707
|
### Direct Service Access
|
package/dist/index.cjs
CHANGED
|
@@ -252,7 +252,8 @@ var UserPromptRequestPayloadSchema = zod.z.object({
|
|
|
252
252
|
SA_RUNTIME: zod.z.object({
|
|
253
253
|
threadId: zod.z.string(),
|
|
254
254
|
uiBlockId: zod.z.string()
|
|
255
|
-
}).optional()
|
|
255
|
+
}).optional(),
|
|
256
|
+
responseMode: zod.z.enum(["component", "text"]).optional()
|
|
256
257
|
});
|
|
257
258
|
var UserPromptRequestMessageSchema = zod.z.object({
|
|
258
259
|
id: zod.z.string(),
|
|
@@ -638,8 +639,8 @@ async function sendAuthVerifyRequest(client, token, timeout) {
|
|
|
638
639
|
}
|
|
639
640
|
|
|
640
641
|
// src/services/userPrompt.ts
|
|
641
|
-
async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, timeout) {
|
|
642
|
-
const messageId = `
|
|
642
|
+
async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, responseMode, onStream, timeout) {
|
|
643
|
+
const messageId = `user_prompt_req_msg_${Date.now()}`;
|
|
643
644
|
const message = UserPromptRequestMessageSchema.parse({
|
|
644
645
|
id: messageId,
|
|
645
646
|
type: "USER_PROMPT_REQ",
|
|
@@ -654,11 +655,29 @@ async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, timeou
|
|
|
654
655
|
SA_RUNTIME: {
|
|
655
656
|
threadId,
|
|
656
657
|
uiBlockId
|
|
657
|
-
}
|
|
658
|
+
},
|
|
659
|
+
responseMode
|
|
658
660
|
}
|
|
659
661
|
});
|
|
660
|
-
|
|
661
|
-
|
|
662
|
+
let streamUnsubscribe = null;
|
|
663
|
+
if (responseMode === "text" && onStream) {
|
|
664
|
+
streamUnsubscribe = client.onMessage((msg) => {
|
|
665
|
+
if (msg.type === "USER_PROMPT_STREAM" && msg.id === `stream_${uiBlockId}`) {
|
|
666
|
+
const chunk = msg.payload?.chunk;
|
|
667
|
+
if (chunk) {
|
|
668
|
+
onStream(chunk);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
try {
|
|
674
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
675
|
+
return response;
|
|
676
|
+
} finally {
|
|
677
|
+
if (streamUnsubscribe) {
|
|
678
|
+
streamUnsubscribe();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
662
681
|
}
|
|
663
682
|
async function sendUserPromptSuggestionsRequest(client, prompt, limit = 5, timeout) {
|
|
664
683
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -1465,10 +1484,12 @@ var SuperatomClient = class {
|
|
|
1465
1484
|
/**
|
|
1466
1485
|
* Send a user prompt request
|
|
1467
1486
|
* Delegates to user prompt service
|
|
1487
|
+
* @param responseMode - 'component' for component response (default), 'text' for text streaming
|
|
1488
|
+
* @param onStream - Optional callback for streaming text chunks (only for text mode)
|
|
1468
1489
|
*/
|
|
1469
|
-
async sendUserPromptRequest(prompt, threadId, uiBlockId, timeout) {
|
|
1470
|
-
this.log("info", "Sending user prompt request");
|
|
1471
|
-
return sendUserPromptRequest(this, prompt, threadId, uiBlockId, timeout);
|
|
1490
|
+
async sendUserPromptRequest(prompt, threadId, uiBlockId, responseMode, onStream, timeout) {
|
|
1491
|
+
this.log("info", "Sending user prompt request with streaming support");
|
|
1492
|
+
return sendUserPromptRequest(this, prompt, threadId, uiBlockId, responseMode, onStream, timeout);
|
|
1472
1493
|
}
|
|
1473
1494
|
/**
|
|
1474
1495
|
* Send a user prompt suggestions request
|