@superatomai/sdk-node 0.0.26 → 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
@@ -802,18 +802,22 @@ var STORAGE_CONFIG = {
802
802
  */
803
803
  MAX_ROWS_PER_BLOCK: 10,
804
804
  /**
805
- * Maximum size in bytes per UIBlock (1MB)
805
+ * Maximum size in bytes per UIBlock (500KB - reduced to save memory)
806
806
  */
807
- MAX_SIZE_PER_BLOCK_BYTES: 1 * 1024 * 1024,
808
- // 1MB
807
+ MAX_SIZE_PER_BLOCK_BYTES: 500 * 1024,
808
+ // 500KB
809
809
  /**
810
810
  * Number of days to keep threads before cleanup
811
+ * Note: This is for in-memory storage. Conversations are also persisted to database.
811
812
  */
812
- THREAD_RETENTION_DAYS: 7,
813
+ THREAD_RETENTION_DAYS: 2,
814
+ // Reduced from 7 to 1 day for memory efficiency
813
815
  /**
814
816
  * Number of days to keep UIBlocks before cleanup
817
+ * Note: This is for in-memory storage. Data is also persisted to database.
815
818
  */
816
- UIBLOCK_RETENTION_DAYS: 7
819
+ UIBLOCK_RETENTION_DAYS: 2
820
+ // Reduced from 7 to 1 day for memory efficiency
817
821
  };
818
822
 
819
823
  // src/threads/uiblock.ts
@@ -1333,8 +1337,15 @@ async function handleDataRequest(data, collections, sendMessage) {
1333
1337
  }
1334
1338
  }
1335
1339
  if (uiBlock) {
1336
- uiBlock.setComponentData(result || {});
1337
- 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)`);
1338
1349
  } else {
1339
1350
  logger.warn(`UIBlock ${uiBlockId} not found in threads`);
1340
1351
  }
@@ -3341,10 +3352,15 @@ var LLM = class {
3341
3352
  for (const toolUse of toolUses) {
3342
3353
  try {
3343
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
+ }
3344
3360
  toolResults.content.push({
3345
3361
  type: "tool_result",
3346
3362
  tool_use_id: toolUse.id,
3347
- content: typeof result === "string" ? result : JSON.stringify(result)
3363
+ content: resultContent
3348
3364
  });
3349
3365
  } catch (error) {
3350
3366
  toolResults.content.push({
@@ -3523,9 +3539,14 @@ var LLM = class {
3523
3539
  for (const fc of functionCalls) {
3524
3540
  try {
3525
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
+ }
3526
3547
  functionResponses.push({
3527
3548
  name: fc.name,
3528
- response: { result: typeof result2 === "string" ? result2 : JSON.stringify(result2) }
3549
+ response: { result: resultContent }
3529
3550
  });
3530
3551
  } catch (error) {
3531
3552
  functionResponses.push({
@@ -3691,6 +3712,10 @@ var LLM = class {
3691
3712
  const args = JSON.parse(tc.arguments);
3692
3713
  const toolResult = await toolHandler(tc.name, args);
3693
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
+ }
3694
3719
  } catch (error) {
3695
3720
  result = JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
3696
3721
  }
@@ -4865,13 +4890,26 @@ Please try rephrasing your request or contact support.
4865
4890
  logger.info(`[${this.getProviderName()}] External tool ${externalTool.name} executed successfully`);
4866
4891
  logCollector?.info(`\u2713 ${externalTool.name} executed successfully`);
4867
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
+ }
4868
4906
  executedToolsList.push({
4869
4907
  id: externalTool.id,
4870
4908
  name: externalTool.name,
4871
4909
  params: toolInput,
4872
4910
  // The actual parameters used in this execution
4873
- result: result2
4874
- // Store the actual result data for populating deferred tool params
4911
+ result: resultSummary
4912
+ // Store summary instead of full result to save memory
4875
4913
  });
4876
4914
  logger.info(`[${this.getProviderName()}] Tracked executed tool: ${externalTool.name} with params: ${JSON.stringify(toolInput)}`);
4877
4915
  }
@@ -4979,8 +5017,6 @@ ${errorMsg}
4979
5017
  if (deferredTools.length > 0) {
4980
5018
  logger.info(`[${this.getProviderName()}] Passing ${deferredTools.length} deferred tools for Form generation`);
4981
5019
  }
4982
- logger.info(`[${this.getProviderName()}] passing deferred tools to the matching function: ${JSON.stringify(deferredTools, null, 2)}`);
4983
- logger.info(`[${this.getProviderName()}] passing executed tools to the matching function: ${JSON.stringify(executedToolsList, null, 2)}`);
4984
5020
  const matchResult = await this.matchComponentsFromAnalysis(
4985
5021
  textResponse,
4986
5022
  components,