@superatomai/sdk-web 0.0.8 → 0.0.10

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
@@ -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(),
@@ -550,6 +551,44 @@ zod.z.object({
550
551
  to: MessageParticipantSchema.optional(),
551
552
  payload: ReportsResponsePayloadSchema
552
553
  });
554
+ var BookmarkDataSchema = zod.z.object({
555
+ id: zod.z.number().optional(),
556
+ uiblock: zod.z.any(),
557
+ // JSON object
558
+ created_at: zod.z.string().optional(),
559
+ updated_at: zod.z.string().optional()
560
+ });
561
+ var BookmarksRequestPayloadSchema = zod.z.object({
562
+ operation: zod.z.enum(["create", "update", "delete", "getAll", "getOne"]),
563
+ data: zod.z.object({
564
+ id: zod.z.number().optional(),
565
+ uiblock: zod.z.any().optional()
566
+ }).optional()
567
+ });
568
+ var BookmarksRequestMessageSchema = zod.z.object({
569
+ id: zod.z.string(),
570
+ type: zod.z.literal("BOOKMARKS"),
571
+ from: MessageParticipantSchema,
572
+ to: MessageParticipantSchema.optional(),
573
+ payload: BookmarksRequestPayloadSchema
574
+ });
575
+ var BookmarksResponsePayloadSchema = zod.z.object({
576
+ success: zod.z.boolean(),
577
+ error: zod.z.string().optional(),
578
+ data: zod.z.union([
579
+ BookmarkDataSchema,
580
+ zod.z.array(BookmarkDataSchema)
581
+ ]).optional(),
582
+ count: zod.z.number().optional(),
583
+ message: zod.z.string().optional()
584
+ });
585
+ zod.z.object({
586
+ id: zod.z.string(),
587
+ type: zod.z.literal("BOOKMARKS_RES"),
588
+ from: MessageParticipantSchema,
589
+ to: MessageParticipantSchema.optional(),
590
+ payload: BookmarksResponsePayloadSchema
591
+ });
553
592
  var ClientConfigSchema = zod.z.object({
554
593
  userId: zod.z.string(),
555
594
  projectId: zod.z.string(),
@@ -572,16 +611,20 @@ __export(services_exports, {
572
611
  QuerySpecSchema: () => QuerySpecSchema,
573
612
  UIComponentSchema: () => UIComponentSchema,
574
613
  UIElementSchema: () => UIElementSchema,
614
+ createBookmark: () => createBookmark,
575
615
  createDashboard: () => createDashboard,
576
616
  createReport: () => createReport,
577
617
  createUser: () => createUser,
618
+ deleteBookmark: () => deleteBookmark,
578
619
  deleteDashboard: () => deleteDashboard,
579
620
  deleteReport: () => deleteReport,
580
621
  deleteUser: () => deleteUser,
581
622
  getActions: () => getActions,
623
+ getAllBookmarks: () => getAllBookmarks,
582
624
  getAllDashboards: () => getAllDashboards,
583
625
  getAllReports: () => getAllReports,
584
626
  getAllUsers: () => getAllUsers,
627
+ getBookmark: () => getBookmark,
585
628
  getComponentSuggestions: () => getComponentSuggestions,
586
629
  getDashboard: () => getDashboard,
587
630
  getReport: () => getReport,
@@ -593,6 +636,7 @@ __export(services_exports, {
593
636
  sendComponents: () => sendComponents,
594
637
  sendUserPromptRequest: () => sendUserPromptRequest,
595
638
  sendUserPromptSuggestionsRequest: () => sendUserPromptSuggestionsRequest,
639
+ updateBookmark: () => updateBookmark,
596
640
  updateDashboard: () => updateDashboard,
597
641
  updateReport: () => updateReport,
598
642
  updateUser: () => updateUser
@@ -638,8 +682,8 @@ async function sendAuthVerifyRequest(client, token, timeout) {
638
682
  }
639
683
 
640
684
  // src/services/userPrompt.ts
641
- async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, timeout) {
642
- const messageId = `msg_${Date.now()}`;
685
+ async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, responseMode, onStream, timeout) {
686
+ const messageId = `user_prompt_req_msg_${Date.now()}`;
643
687
  const message = UserPromptRequestMessageSchema.parse({
644
688
  id: messageId,
645
689
  type: "USER_PROMPT_REQ",
@@ -654,11 +698,29 @@ async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, timeou
654
698
  SA_RUNTIME: {
655
699
  threadId,
656
700
  uiBlockId
657
- }
701
+ },
702
+ responseMode
658
703
  }
659
704
  });
660
- const response = await client.sendWithResponse(message, timeout);
661
- return response;
705
+ let streamUnsubscribe = null;
706
+ if (responseMode === "text" && onStream) {
707
+ streamUnsubscribe = client.onMessage((msg) => {
708
+ if (msg.type === "USER_PROMPT_STREAM" && msg.id === `stream_${uiBlockId}`) {
709
+ const chunk = msg.payload?.chunk;
710
+ if (chunk) {
711
+ onStream(chunk);
712
+ }
713
+ }
714
+ });
715
+ }
716
+ try {
717
+ const response = await client.sendWithResponse(message, timeout);
718
+ return response;
719
+ } finally {
720
+ if (streamUnsubscribe) {
721
+ streamUnsubscribe();
722
+ }
723
+ }
662
724
  }
663
725
  async function sendUserPromptSuggestionsRequest(client, prompt, limit = 5, timeout) {
664
726
  if (!prompt || prompt.trim().length === 0) {
@@ -1160,6 +1222,122 @@ async function getReport(client, reportId, timeout) {
1160
1222
  };
1161
1223
  }
1162
1224
 
1225
+ // src/services/bookmarks/index.ts
1226
+ async function createBookmark(client, uiblock, timeout) {
1227
+ const messageId = `bookmarks_create_${Date.now()}`;
1228
+ const message = BookmarksRequestMessageSchema.parse({
1229
+ id: messageId,
1230
+ type: "BOOKMARKS",
1231
+ from: { type: client.type },
1232
+ to: { type: "data-agent" },
1233
+ payload: {
1234
+ operation: "create",
1235
+ data: {
1236
+ uiblock
1237
+ }
1238
+ }
1239
+ });
1240
+ const response = await client.sendWithResponse(message, timeout);
1241
+ const payload = response.payload;
1242
+ return {
1243
+ success: payload.success,
1244
+ error: payload.error,
1245
+ message: payload.message,
1246
+ data: Array.isArray(payload.data) ? payload.data[0] : payload.data
1247
+ };
1248
+ }
1249
+ async function updateBookmark(client, id, uiblock, timeout) {
1250
+ const messageId = `bookmarks_update_${Date.now()}`;
1251
+ const message = BookmarksRequestMessageSchema.parse({
1252
+ id: messageId,
1253
+ type: "BOOKMARKS",
1254
+ from: { type: client.type },
1255
+ to: { type: "data-agent" },
1256
+ payload: {
1257
+ operation: "update",
1258
+ data: {
1259
+ id,
1260
+ uiblock
1261
+ }
1262
+ }
1263
+ });
1264
+ const response = await client.sendWithResponse(message, timeout);
1265
+ const payload = response.payload;
1266
+ return {
1267
+ success: payload.success,
1268
+ error: payload.error,
1269
+ message: payload.message,
1270
+ data: Array.isArray(payload.data) ? payload.data[0] : payload.data
1271
+ };
1272
+ }
1273
+ async function deleteBookmark(client, id, timeout) {
1274
+ const messageId = `bookmarks_delete_${Date.now()}`;
1275
+ const message = BookmarksRequestMessageSchema.parse({
1276
+ id: messageId,
1277
+ type: "BOOKMARKS",
1278
+ from: { type: client.type },
1279
+ to: { type: "data-agent" },
1280
+ payload: {
1281
+ operation: "delete",
1282
+ data: {
1283
+ id
1284
+ }
1285
+ }
1286
+ });
1287
+ const response = await client.sendWithResponse(message, timeout);
1288
+ const payload = response.payload;
1289
+ return {
1290
+ success: payload.success,
1291
+ error: payload.error,
1292
+ message: payload.message,
1293
+ data: Array.isArray(payload.data) ? payload.data[0] : payload.data
1294
+ };
1295
+ }
1296
+ async function getAllBookmarks(client, timeout) {
1297
+ const messageId = `bookmarks_getall_${Date.now()}`;
1298
+ const message = BookmarksRequestMessageSchema.parse({
1299
+ id: messageId,
1300
+ type: "BOOKMARKS",
1301
+ from: { type: client.type },
1302
+ to: { type: "data-agent" },
1303
+ payload: {
1304
+ operation: "getAll"
1305
+ }
1306
+ });
1307
+ const response = await client.sendWithResponse(message, timeout);
1308
+ const payload = response.payload;
1309
+ return {
1310
+ success: payload.success,
1311
+ error: payload.error,
1312
+ data: Array.isArray(payload.data) ? payload.data : payload.data ? [payload.data] : [],
1313
+ count: payload.count,
1314
+ message: payload.message
1315
+ };
1316
+ }
1317
+ async function getBookmark(client, id, timeout) {
1318
+ const messageId = `bookmarks_getone_${Date.now()}`;
1319
+ const message = BookmarksRequestMessageSchema.parse({
1320
+ id: messageId,
1321
+ type: "BOOKMARKS",
1322
+ from: { type: client.type },
1323
+ to: { type: "data-agent" },
1324
+ payload: {
1325
+ operation: "getOne",
1326
+ data: {
1327
+ id
1328
+ }
1329
+ }
1330
+ });
1331
+ const response = await client.sendWithResponse(message, timeout);
1332
+ const payload = response.payload;
1333
+ return {
1334
+ success: payload.success,
1335
+ error: payload.error,
1336
+ data: Array.isArray(payload.data) ? payload.data[0] : payload.data,
1337
+ message: payload.message
1338
+ };
1339
+ }
1340
+
1163
1341
  // src/services/actions.ts
1164
1342
  async function getActions(client, options) {
1165
1343
  const messageId = `msg_${Date.now()}_${Math.random().toString(36).substring(7)}`;
@@ -1465,10 +1643,12 @@ var SuperatomClient = class {
1465
1643
  /**
1466
1644
  * Send a user prompt request
1467
1645
  * Delegates to user prompt service
1646
+ * @param responseMode - 'component' for component response (default), 'text' for text streaming
1647
+ * @param onStream - Optional callback for streaming text chunks (only for text mode)
1468
1648
  */
1469
- async sendUserPromptRequest(prompt, threadId, uiBlockId, timeout) {
1470
- this.log("info", "Sending user prompt request");
1471
- return sendUserPromptRequest(this, prompt, threadId, uiBlockId, timeout);
1649
+ async sendUserPromptRequest(prompt, threadId, uiBlockId, responseMode, onStream, timeout) {
1650
+ this.log("info", "Sending user prompt request with streaming support");
1651
+ return sendUserPromptRequest(this, prompt, threadId, uiBlockId, responseMode, onStream, timeout);
1472
1652
  }
1473
1653
  /**
1474
1654
  * Send a user prompt suggestions request
@@ -1598,6 +1778,48 @@ var SuperatomClient = class {
1598
1778
  this.log("info", "Fetching dashboard:", dashboardId);
1599
1779
  return getDashboard(this, dashboardId, timeout);
1600
1780
  }
1781
+ // ==================== Bookmark Management Methods ====================
1782
+ // These methods delegate to bookmark service for bookmark CRUD operations
1783
+ /**
1784
+ * Create a new bookmark
1785
+ * Delegates to bookmarks service
1786
+ */
1787
+ async createBookmark(uiblock, timeout) {
1788
+ this.log("info", "Creating bookmark");
1789
+ return createBookmark(this, uiblock, timeout);
1790
+ }
1791
+ /**
1792
+ * Update an existing bookmark
1793
+ * Delegates to bookmarks service
1794
+ */
1795
+ async updateBookmark(id, uiblock, timeout) {
1796
+ this.log("info", "Updating bookmark:", id);
1797
+ return updateBookmark(this, id, uiblock, timeout);
1798
+ }
1799
+ /**
1800
+ * Delete a bookmark
1801
+ * Delegates to bookmarks service
1802
+ */
1803
+ async deleteBookmark(id, timeout) {
1804
+ this.log("info", "Deleting bookmark:", id);
1805
+ return deleteBookmark(this, id, timeout);
1806
+ }
1807
+ /**
1808
+ * Get all bookmarks
1809
+ * Delegates to bookmarks service
1810
+ */
1811
+ async getAllBookmarks(timeout) {
1812
+ this.log("info", "Fetching all bookmarks");
1813
+ return getAllBookmarks(this, timeout);
1814
+ }
1815
+ /**
1816
+ * Get a specific bookmark by ID
1817
+ * Delegates to bookmarks service
1818
+ */
1819
+ async getBookmark(id, timeout) {
1820
+ this.log("info", "Fetching bookmark:", id);
1821
+ return getBookmark(this, id, timeout);
1822
+ }
1601
1823
  // ==================== Report Management Methods ====================
1602
1824
  // These methods delegate to report service for admin report CRUD operations
1603
1825
  /**