@superatomai/sdk-node 0.0.25 → 0.0.27

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/dist/index.mjs CHANGED
@@ -341,6 +341,7 @@ var UserSchema = z3.object({
341
341
  password: z3.string().min(1, "Password is required"),
342
342
  fullname: z3.string().optional(),
343
343
  role: z3.string().optional(),
344
+ userInfo: z3.record(z3.unknown()).optional(),
344
345
  wsIds: z3.array(z3.string()).optional()
345
346
  // Only in memory, not persisted to file
346
347
  });
@@ -470,6 +471,7 @@ var UsersRequestPayloadSchema = z3.object({
470
471
  password: z3.string().optional(),
471
472
  fullname: z3.string().optional(),
472
473
  role: z3.string().optional(),
474
+ userInfo: z3.record(z3.unknown()).optional(),
473
475
  // Query operation fields
474
476
  filters: UserQueryFiltersSchema.optional(),
475
477
  limit: z3.number().optional(),
@@ -515,7 +517,8 @@ var DashboardQueryFiltersSchema = z3.object({
515
517
  projectId: z3.string().optional(),
516
518
  createdBy: z3.number().optional(),
517
519
  updatedBy: z3.number().optional(),
518
- name: z3.string().optional()
520
+ name: z3.string().optional(),
521
+ published: z3.boolean().optional()
519
522
  });
520
523
  var DashboardsRequestPayloadSchema = z3.object({
521
524
  operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
@@ -525,6 +528,7 @@ var DashboardsRequestPayloadSchema = z3.object({
525
528
  projectId: z3.string().optional(),
526
529
  name: z3.string().optional(),
527
530
  description: z3.string().optional(),
531
+ published: z3.boolean().optional(),
528
532
  createdBy: z3.number().optional(),
529
533
  updatedBy: z3.number().optional(),
530
534
  dashboard: DSLRendererPropsSchema.optional(),
@@ -545,7 +549,8 @@ var ReportQueryFiltersSchema = z3.object({
545
549
  projectId: z3.string().optional(),
546
550
  createdBy: z3.number().optional(),
547
551
  updatedBy: z3.number().optional(),
548
- name: z3.string().optional()
552
+ name: z3.string().optional(),
553
+ published: z3.boolean().optional()
549
554
  });
550
555
  var ReportsRequestPayloadSchema = z3.object({
551
556
  operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
@@ -555,6 +560,7 @@ var ReportsRequestPayloadSchema = z3.object({
555
560
  projectId: z3.string().optional(),
556
561
  name: z3.string().optional(),
557
562
  description: z3.string().optional(),
563
+ published: z3.boolean().optional(),
558
564
  createdBy: z3.number().optional(),
559
565
  updatedBy: z3.number().optional(),
560
566
  report: DSLRendererPropsSchema2.optional(),
@@ -796,18 +802,22 @@ var STORAGE_CONFIG = {
796
802
  */
797
803
  MAX_ROWS_PER_BLOCK: 10,
798
804
  /**
799
- * Maximum size in bytes per UIBlock (1MB)
805
+ * Maximum size in bytes per UIBlock (500KB - reduced to save memory)
800
806
  */
801
- MAX_SIZE_PER_BLOCK_BYTES: 1 * 1024 * 1024,
802
- // 1MB
807
+ MAX_SIZE_PER_BLOCK_BYTES: 500 * 1024,
808
+ // 500KB
803
809
  /**
804
810
  * Number of days to keep threads before cleanup
811
+ * Note: This is for in-memory storage. Conversations are also persisted to database.
805
812
  */
806
- THREAD_RETENTION_DAYS: 7,
813
+ THREAD_RETENTION_DAYS: 2,
814
+ // Reduced from 7 to 1 day for memory efficiency
807
815
  /**
808
816
  * Number of days to keep UIBlocks before cleanup
817
+ * Note: This is for in-memory storage. Data is also persisted to database.
809
818
  */
810
- UIBLOCK_RETENTION_DAYS: 7
819
+ UIBLOCK_RETENTION_DAYS: 2
820
+ // Reduced from 7 to 1 day for memory efficiency
811
821
  };
812
822
 
813
823
  // src/threads/uiblock.ts
@@ -1327,8 +1337,15 @@ async function handleDataRequest(data, collections, sendMessage) {
1327
1337
  }
1328
1338
  }
1329
1339
  if (uiBlock) {
1330
- uiBlock.setComponentData(result || {});
1331
- logger.info(`Updated UIBlock ${uiBlockId} with component data from ${collection}.${op}`);
1340
+ const dataSummary = {
1341
+ _dataReceived: true,
1342
+ _timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1343
+ _collection: collection,
1344
+ _operation: op,
1345
+ _recordCount: Array.isArray(result) ? result.length : result?.data?.length || result?.contacts?.length || result?.salesorders?.length || "unknown"
1346
+ };
1347
+ uiBlock.setComponentData(dataSummary);
1348
+ logger.info(`Updated UIBlock ${uiBlockId} with data summary from ${collection}.${op} (full data not stored to save memory)`);
1332
1349
  } else {
1333
1350
  logger.warn(`UIBlock ${uiBlockId} not found in threads`);
1334
1351
  }
@@ -3335,10 +3352,15 @@ var LLM = class {
3335
3352
  for (const toolUse of toolUses) {
3336
3353
  try {
3337
3354
  const result = await toolHandler(toolUse.name, toolUse.input);
3355
+ let resultContent = typeof result === "string" ? result : JSON.stringify(result);
3356
+ const MAX_RESULT_LENGTH = 5e4;
3357
+ if (resultContent.length > MAX_RESULT_LENGTH) {
3358
+ resultContent = resultContent.substring(0, MAX_RESULT_LENGTH) + "\n\n... [Result truncated - showing first 50000 characters of " + resultContent.length + " total]";
3359
+ }
3338
3360
  toolResults.content.push({
3339
3361
  type: "tool_result",
3340
3362
  tool_use_id: toolUse.id,
3341
- content: typeof result === "string" ? result : JSON.stringify(result)
3363
+ content: resultContent
3342
3364
  });
3343
3365
  } catch (error) {
3344
3366
  toolResults.content.push({
@@ -3517,9 +3539,14 @@ var LLM = class {
3517
3539
  for (const fc of functionCalls) {
3518
3540
  try {
3519
3541
  const result2 = await toolHandler(fc.name, fc.args);
3542
+ let resultContent = typeof result2 === "string" ? result2 : JSON.stringify(result2);
3543
+ const MAX_RESULT_LENGTH = 5e4;
3544
+ if (resultContent.length > MAX_RESULT_LENGTH) {
3545
+ resultContent = resultContent.substring(0, MAX_RESULT_LENGTH) + "\n\n... [Result truncated - showing first 50000 characters of " + resultContent.length + " total]";
3546
+ }
3520
3547
  functionResponses.push({
3521
3548
  name: fc.name,
3522
- response: { result: typeof result2 === "string" ? result2 : JSON.stringify(result2) }
3549
+ response: { result: resultContent }
3523
3550
  });
3524
3551
  } catch (error) {
3525
3552
  functionResponses.push({
@@ -3685,6 +3712,10 @@ var LLM = class {
3685
3712
  const args = JSON.parse(tc.arguments);
3686
3713
  const toolResult = await toolHandler(tc.name, args);
3687
3714
  result = typeof toolResult === "string" ? toolResult : JSON.stringify(toolResult);
3715
+ const MAX_RESULT_LENGTH = 5e4;
3716
+ if (result.length > MAX_RESULT_LENGTH) {
3717
+ result = result.substring(0, MAX_RESULT_LENGTH) + "\n\n... [Result truncated - showing first 50000 characters of " + result.length + " total]";
3718
+ }
3688
3719
  } catch (error) {
3689
3720
  result = JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
3690
3721
  }
@@ -4367,6 +4398,7 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4367
4398
  */
4368
4399
  async classifyQuestionCategory(userPrompt, apiKey, logCollector, conversationHistory, externalTools) {
4369
4400
  try {
4401
+ const schemaDoc = schema.generateSchemaDocumentation();
4370
4402
  const availableToolsDoc = externalTools && externalTools.length > 0 ? externalTools.map((tool) => {
4371
4403
  const paramsStr = Object.entries(tool.params || {}).map(([key, type]) => `${key}: ${type}`).join(", ");
4372
4404
  return `- **${tool.name}** (id: ${tool.id})
@@ -4376,7 +4408,8 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4376
4408
  const prompts = await promptLoader.loadPrompts("category-classification", {
4377
4409
  USER_PROMPT: userPrompt,
4378
4410
  CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
4379
- AVAILABLE_TOOLS: availableToolsDoc
4411
+ AVAILABLE_TOOLS: availableToolsDoc,
4412
+ SCHEMA_DOC: schemaDoc || "No database schema available"
4380
4413
  });
4381
4414
  const result = await LLM.stream(
4382
4415
  {
@@ -4857,13 +4890,26 @@ Please try rephrasing your request or contact support.
4857
4890
  logger.info(`[${this.getProviderName()}] External tool ${externalTool.name} executed successfully`);
4858
4891
  logCollector?.info(`\u2713 ${externalTool.name} executed successfully`);
4859
4892
  if (!executedToolsList.find((t) => t.id === externalTool.id)) {
4893
+ let resultSummary = null;
4894
+ if (result2) {
4895
+ const resultStr = typeof result2 === "string" ? result2 : JSON.stringify(result2);
4896
+ if (resultStr.length > 1e3) {
4897
+ resultSummary = {
4898
+ _preview: resultStr.substring(0, 1e3) + "... (truncated)",
4899
+ _totalLength: resultStr.length,
4900
+ _recordCount: Array.isArray(result2) ? result2.length : result2?.data?.length || result2?.contacts?.length || result2?.salesorders?.length || "unknown"
4901
+ };
4902
+ } else {
4903
+ resultSummary = result2;
4904
+ }
4905
+ }
4860
4906
  executedToolsList.push({
4861
4907
  id: externalTool.id,
4862
4908
  name: externalTool.name,
4863
4909
  params: toolInput,
4864
4910
  // The actual parameters used in this execution
4865
- result: result2
4866
- // Store the actual result data for populating deferred tool params
4911
+ result: resultSummary
4912
+ // Store summary instead of full result to save memory
4867
4913
  });
4868
4914
  logger.info(`[${this.getProviderName()}] Tracked executed tool: ${externalTool.name} with params: ${JSON.stringify(toolInput)}`);
4869
4915
  }
@@ -4971,8 +5017,6 @@ ${errorMsg}
4971
5017
  if (deferredTools.length > 0) {
4972
5018
  logger.info(`[${this.getProviderName()}] Passing ${deferredTools.length} deferred tools for Form generation`);
4973
5019
  }
4974
- logger.info(`[${this.getProviderName()}] passing deferred tools to the matching function: ${JSON.stringify(deferredTools, null, 2)}`);
4975
- logger.info(`[${this.getProviderName()}] passing executed tools to the matching function: ${JSON.stringify(executedToolsList, null, 2)}`);
4976
5020
  const matchResult = await this.matchComponentsFromAnalysis(
4977
5021
  textResponse,
4978
5022
  components,
@@ -6491,6 +6535,7 @@ async function handleUsersRequest(data, collections, sendMessage) {
6491
6535
  const password = requestData?.password;
6492
6536
  const fullname = requestData?.fullname;
6493
6537
  const role = requestData?.role;
6538
+ const userInfo = requestData?.userInfo;
6494
6539
  const filters = requestData?.filters;
6495
6540
  const limit = requestData?.limit;
6496
6541
  const sort = requestData?.sort;
@@ -6505,10 +6550,10 @@ async function handleUsersRequest(data, collections, sendMessage) {
6505
6550
  const userManager = getUserManager();
6506
6551
  switch (operation) {
6507
6552
  case "create":
6508
- await handleCreate(id, { username, email, password, fullname, role }, executeCollection, userManager, sendMessage, from.id);
6553
+ await handleCreate(id, { username, email, password, fullname, role, userInfo }, executeCollection, userManager, sendMessage, from.id);
6509
6554
  break;
6510
6555
  case "update":
6511
- await handleUpdate(id, numericId, { username, email, password, fullname, role }, executeCollection, userManager, sendMessage, from.id);
6556
+ await handleUpdate(id, numericId, { username, email, password, fullname, role, userInfo }, executeCollection, userManager, sendMessage, from.id);
6512
6557
  break;
6513
6558
  case "delete":
6514
6559
  await handleDelete(id, numericId, username, executeCollection, userManager, sendMessage, from.id);
@@ -6537,7 +6582,7 @@ async function handleUsersRequest(data, collections, sendMessage) {
6537
6582
  }
6538
6583
  }
6539
6584
  async function handleCreate(id, userData, executeCollection, userManager, sendMessage, clientId) {
6540
- const { username, email, password, fullname, role } = userData;
6585
+ const { username, email, password, fullname, role, userInfo } = userData;
6541
6586
  if (!username || username.trim().length === 0) {
6542
6587
  sendResponse3(id, {
6543
6588
  success: false,
@@ -6568,7 +6613,8 @@ async function handleCreate(id, userData, executeCollection, userManager, sendMe
6568
6613
  email: email || void 0,
6569
6614
  password,
6570
6615
  fullname: fullname || void 0,
6571
- role: role || void 0
6616
+ role: role || void 0,
6617
+ userInfo: userInfo || void 0
6572
6618
  });
6573
6619
  if (result && result.success) {
6574
6620
  logger.info(`[DB] User created successfully: ${username}`);
@@ -6636,7 +6682,7 @@ async function handleCreate(id, userData, executeCollection, userManager, sendMe
6636
6682
  }
6637
6683
  }
6638
6684
  async function handleUpdate(id, numericId, userData, executeCollection, userManager, sendMessage, clientId) {
6639
- const { username, email, password, fullname, role } = userData;
6685
+ const { username, email, password, fullname, role, userInfo } = userData;
6640
6686
  if (!numericId && !username) {
6641
6687
  sendResponse3(id, {
6642
6688
  success: false,
@@ -6652,7 +6698,8 @@ async function handleUpdate(id, numericId, userData, executeCollection, userMana
6652
6698
  email,
6653
6699
  password,
6654
6700
  fullname,
6655
- role
6701
+ role,
6702
+ userInfo
6656
6703
  });
6657
6704
  if (result && result.success) {
6658
6705
  logger.info(`[DB] User updated successfully, ID: ${numericId}`);
@@ -7012,6 +7059,7 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
7012
7059
  const projectId = requestData?.projectId;
7013
7060
  const name = requestData?.name;
7014
7061
  const description = requestData?.description;
7062
+ const published = requestData?.published;
7015
7063
  const createdBy = requestData?.createdBy;
7016
7064
  const updatedBy = requestData?.updatedBy;
7017
7065
  const numericId = requestData?.id;
@@ -7029,10 +7077,10 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
7029
7077
  const dashboardManager2 = getDashboardManager();
7030
7078
  switch (operation) {
7031
7079
  case "create":
7032
- await handleCreate2(id, dashboardId, dashboard, projectId, name, description, createdBy, executeCollection, dashboardManager2, sendMessage, from.id);
7080
+ await handleCreate2(id, dashboardId, dashboard, projectId, name, description, published, createdBy, executeCollection, dashboardManager2, sendMessage, from.id);
7033
7081
  break;
7034
7082
  case "update":
7035
- await handleUpdate2(id, numericId, dashboardId, dashboard, name, description, updatedBy, executeCollection, dashboardManager2, sendMessage, from.id);
7083
+ await handleUpdate2(id, numericId, dashboardId, dashboard, name, description, published, updatedBy, executeCollection, dashboardManager2, sendMessage, from.id);
7036
7084
  break;
7037
7085
  case "delete":
7038
7086
  await handleDelete2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, from.id);
@@ -7060,7 +7108,7 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
7060
7108
  }, sendMessage);
7061
7109
  }
7062
7110
  }
7063
- async function handleCreate2(id, dashboardId, dashboard, projectId, name, description, createdBy, executeCollection, dashboardManager2, sendMessage, clientId) {
7111
+ async function handleCreate2(id, dashboardId, dashboard, projectId, name, description, published, createdBy, executeCollection, dashboardManager2, sendMessage, clientId) {
7064
7112
  if (!dashboardId || dashboardId.trim().length === 0) {
7065
7113
  sendResponse4(id, {
7066
7114
  success: false,
@@ -7082,6 +7130,7 @@ async function handleCreate2(id, dashboardId, dashboard, projectId, name, descri
7082
7130
  name: name || "",
7083
7131
  description,
7084
7132
  dashboard,
7133
+ published,
7085
7134
  createdBy
7086
7135
  });
7087
7136
  if (result && result.success) {
@@ -7121,7 +7170,7 @@ async function handleCreate2(id, dashboardId, dashboard, projectId, name, descri
7121
7170
  }, sendMessage, clientId);
7122
7171
  }
7123
7172
  }
7124
- async function handleUpdate2(id, numericId, dashboardId, dashboard, name, description, updatedBy, executeCollection, dashboardManager2, sendMessage, clientId) {
7173
+ async function handleUpdate2(id, numericId, dashboardId, dashboard, name, description, published, updatedBy, executeCollection, dashboardManager2, sendMessage, clientId) {
7125
7174
  if (!numericId) {
7126
7175
  sendResponse4(id, {
7127
7176
  success: false,
@@ -7135,6 +7184,7 @@ async function handleUpdate2(id, numericId, dashboardId, dashboard, name, descri
7135
7184
  name,
7136
7185
  description,
7137
7186
  dashboard,
7187
+ published,
7138
7188
  updatedBy
7139
7189
  });
7140
7190
  if (result && result.success) {
@@ -7377,6 +7427,7 @@ async function handleReportsRequest(data, collections, sendMessage) {
7377
7427
  const projectId = requestData?.projectId;
7378
7428
  const name = requestData?.name;
7379
7429
  const description = requestData?.description;
7430
+ const published = requestData?.published;
7380
7431
  const createdBy = requestData?.createdBy;
7381
7432
  const updatedBy = requestData?.updatedBy;
7382
7433
  const numericId = requestData?.id;
@@ -7394,10 +7445,10 @@ async function handleReportsRequest(data, collections, sendMessage) {
7394
7445
  const reportManager2 = getReportManager();
7395
7446
  switch (operation) {
7396
7447
  case "create":
7397
- await handleCreate3(id, reportId, report, projectId, name, description, createdBy, executeCollection, reportManager2, sendMessage, from.id);
7448
+ await handleCreate3(id, reportId, report, projectId, name, description, published, createdBy, executeCollection, reportManager2, sendMessage, from.id);
7398
7449
  break;
7399
7450
  case "update":
7400
- await handleUpdate3(id, numericId, reportId, report, name, description, updatedBy, executeCollection, reportManager2, sendMessage, from.id);
7451
+ await handleUpdate3(id, numericId, reportId, report, name, description, published, updatedBy, executeCollection, reportManager2, sendMessage, from.id);
7401
7452
  break;
7402
7453
  case "delete":
7403
7454
  await handleDelete3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, from.id);
@@ -7425,7 +7476,7 @@ async function handleReportsRequest(data, collections, sendMessage) {
7425
7476
  }, sendMessage);
7426
7477
  }
7427
7478
  }
7428
- async function handleCreate3(id, reportId, report, projectId, name, description, createdBy, executeCollection, reportManager2, sendMessage, clientId) {
7479
+ async function handleCreate3(id, reportId, report, projectId, name, description, published, createdBy, executeCollection, reportManager2, sendMessage, clientId) {
7429
7480
  if (!reportId || reportId.trim().length === 0) {
7430
7481
  sendResponse5(id, {
7431
7482
  success: false,
@@ -7447,6 +7498,7 @@ async function handleCreate3(id, reportId, report, projectId, name, description,
7447
7498
  name: name || "",
7448
7499
  description,
7449
7500
  report,
7501
+ published,
7450
7502
  createdBy
7451
7503
  });
7452
7504
  if (result && result.success) {
@@ -7486,7 +7538,7 @@ async function handleCreate3(id, reportId, report, projectId, name, description,
7486
7538
  }, sendMessage, clientId);
7487
7539
  }
7488
7540
  }
7489
- async function handleUpdate3(id, numericId, reportId, report, name, description, updatedBy, executeCollection, reportManager2, sendMessage, clientId) {
7541
+ async function handleUpdate3(id, numericId, reportId, report, name, description, published, updatedBy, executeCollection, reportManager2, sendMessage, clientId) {
7490
7542
  if (!numericId) {
7491
7543
  sendResponse5(id, {
7492
7544
  success: false,
@@ -7500,6 +7552,7 @@ async function handleUpdate3(id, numericId, reportId, report, name, description,
7500
7552
  name,
7501
7553
  description,
7502
7554
  report,
7555
+ published,
7503
7556
  updatedBy
7504
7557
  });
7505
7558
  if (result && result.success) {