@superatomai/sdk-node 0.0.54 → 0.0.56

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
@@ -5355,6 +5355,19 @@ var LLM = class {
5355
5355
  // src/userResponse/base-llm.ts
5356
5356
  init_logger();
5357
5357
 
5358
+ // src/utils/datetime.ts
5359
+ function getCurrentDateTimeForPrompt() {
5360
+ return (/* @__PURE__ */ new Date()).toLocaleString("en-US", {
5361
+ weekday: "long",
5362
+ year: "numeric",
5363
+ month: "long",
5364
+ day: "numeric",
5365
+ hour: "2-digit",
5366
+ minute: "2-digit",
5367
+ timeZoneName: "short"
5368
+ });
5369
+ }
5370
+
5358
5371
  // src/userResponse/knowledge-base.ts
5359
5372
  init_logger();
5360
5373
  var getKnowledgeBase = async ({
@@ -5835,7 +5848,8 @@ ${fieldsText}`;
5835
5848
  SCHEMA_DOC: schemaDoc,
5836
5849
  DATABASE_RULES: databaseRules,
5837
5850
  DEFERRED_TOOLS: deferredToolsText,
5838
- EXECUTED_TOOLS: executedToolsText
5851
+ EXECUTED_TOOLS: executedToolsText,
5852
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
5839
5853
  });
5840
5854
  logger.debug(`[${this.getProviderName()}] Loaded match-text-components prompts`);
5841
5855
  const systemPromptStr = Array.isArray(prompts.system) ? prompts.system.join("\n") : prompts.system;
@@ -6110,7 +6124,8 @@ ${executedToolsText}`);
6110
6124
  USER_PROMPT: userPrompt,
6111
6125
  CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
6112
6126
  AVAILABLE_TOOLS: availableToolsDoc,
6113
- SCHEMA_DOC: schemaDoc || "No database schema available"
6127
+ SCHEMA_DOC: schemaDoc || "No database schema available",
6128
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
6114
6129
  });
6115
6130
  const systemPrompt = Array.isArray(prompts.system) ? prompts.system.join("\n") : prompts.system;
6116
6131
  const userPromptText = Array.isArray(prompts.user) ? prompts.user.join("\n") : prompts.user;
@@ -6177,7 +6192,8 @@ ${executedToolsText}`);
6177
6192
  COMPONENT_PROPS: JSON.stringify(component.props, null, 2),
6178
6193
  CACHED_TEXT_RESPONSE: cachedTextResponse || "No cached text response available",
6179
6194
  SCHEMA_DOC: schemaDoc || "No schema available",
6180
- DATABASE_RULES: databaseRules
6195
+ DATABASE_RULES: databaseRules,
6196
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
6181
6197
  });
6182
6198
  const result = await LLM.stream(
6183
6199
  {
@@ -6309,7 +6325,8 @@ ${executedToolsText}`);
6309
6325
  SCHEMA_DOC: schemaDoc,
6310
6326
  DATABASE_RULES: databaseRules,
6311
6327
  KNOWLEDGE_BASE_CONTEXT: knowledgeBaseContext || "No additional knowledge base context available.",
6312
- AVAILABLE_EXTERNAL_TOOLS: availableToolsDoc
6328
+ AVAILABLE_EXTERNAL_TOOLS: availableToolsDoc,
6329
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
6313
6330
  });
6314
6331
  const sysPrompt = Array.isArray(prompts.system) ? prompts.system.join("\n") : prompts.system;
6315
6332
  const usrPrompt = Array.isArray(prompts.user) ? prompts.user.join("\n") : prompts.user;
@@ -6431,6 +6448,32 @@ ${executedToolsText}`);
6431
6448
  fullStreamedText += chunk;
6432
6449
  streamCallback(chunk);
6433
6450
  } : void 0;
6451
+ const withProgressHeartbeat = async (operation, progressMessage, intervalMs = 1e3) => {
6452
+ if (!wrappedStreamCallback) {
6453
+ return operation();
6454
+ }
6455
+ const startTime = Date.now();
6456
+ let dotCount = 0;
6457
+ const maxDots = 3;
6458
+ wrappedStreamCallback(`\u23F3 ${progressMessage}`);
6459
+ const heartbeatInterval = setInterval(() => {
6460
+ const elapsedSeconds = Math.floor((Date.now() - startTime) / 1e3);
6461
+ dotCount = (dotCount + 1) % (maxDots + 1);
6462
+ const dots = ".".repeat(dotCount || 1);
6463
+ if (elapsedSeconds >= 2) {
6464
+ wrappedStreamCallback(`${dots} (${elapsedSeconds}s)`);
6465
+ } else {
6466
+ wrappedStreamCallback(dots);
6467
+ }
6468
+ }, intervalMs);
6469
+ try {
6470
+ const result2 = await operation();
6471
+ return result2;
6472
+ } finally {
6473
+ clearInterval(heartbeatInterval);
6474
+ wrappedStreamCallback("\n\n");
6475
+ }
6476
+ };
6434
6477
  const toolHandler = async (toolName, toolInput) => {
6435
6478
  if (toolName === "execute_query") {
6436
6479
  let sql = toolInput.sql;
@@ -6484,9 +6527,6 @@ Please try rephrasing your question or simplifying your request.
6484
6527
  ${sql}
6485
6528
  \`\`\`${paramsDisplay}
6486
6529
 
6487
- `);
6488
- wrappedStreamCallback(`\u26A1 **Executing query...**
6489
-
6490
6530
  `);
6491
6531
  } else {
6492
6532
  wrappedStreamCallback(`
@@ -6504,9 +6544,6 @@ ${sql}
6504
6544
  ${sql}
6505
6545
  \`\`\`${paramsDisplay}
6506
6546
 
6507
- `);
6508
- wrappedStreamCallback(`\u26A1 **Executing query...**
6509
-
6510
6547
  `);
6511
6548
  }
6512
6549
  }
@@ -6519,13 +6556,19 @@ ${sql}
6519
6556
  throw new Error("Database collection not registered. Please register database.execute collection to execute queries.");
6520
6557
  }
6521
6558
  const queryPayload = Object.keys(params).length > 0 ? { sql: JSON.stringify({ sql, values: params }) } : { sql };
6522
- const result2 = await collections["database"]["execute"](queryPayload);
6559
+ const result2 = await withProgressHeartbeat(
6560
+ () => collections["database"]["execute"](queryPayload),
6561
+ "Executing database query",
6562
+ 800
6563
+ // Send heartbeat every 800ms for responsive feedback
6564
+ );
6523
6565
  const data = result2?.data || result2;
6524
6566
  const rowCount = result2?.count ?? (Array.isArray(data) ? data.length : "N/A");
6525
6567
  logger.info(`[${this.getProviderName()}] Query executed successfully, rows returned: ${rowCount}`);
6526
6568
  logCollector?.info(`Query successful, returned ${rowCount} rows`);
6527
6569
  if (wrappedStreamCallback) {
6528
- wrappedStreamCallback(`\u2705 **Query executed successfully!**
6570
+ wrappedStreamCallback(`
6571
+ \u2705 **Query executed successfully!**
6529
6572
 
6530
6573
  `);
6531
6574
  if (Array.isArray(data) && data.length > 0) {
@@ -6612,7 +6655,12 @@ Please try rephrasing your request or contact support.
6612
6655
  `);
6613
6656
  }
6614
6657
  }
6615
- const result2 = await externalTool.fn(toolInput);
6658
+ const result2 = await withProgressHeartbeat(
6659
+ () => externalTool.fn(toolInput),
6660
+ `Running ${externalTool.name}`,
6661
+ 800
6662
+ // Send heartbeat every 800ms
6663
+ );
6616
6664
  logger.info(`[${this.getProviderName()}] External tool ${externalTool.name} executed successfully`);
6617
6665
  logCollector?.info(`\u2713 ${externalTool.name} executed successfully`);
6618
6666
  if (!executedToolsList.find((t) => t.id === externalTool.id)) {
@@ -6714,6 +6762,7 @@ ${errorMsg}
6714
6762
  }
6715
6763
  );
6716
6764
  if (wrappedStreamCallback && components && components.length > 0 && category !== "general") {
6765
+ wrappedStreamCallback("\n\n\u{1F4CA} **Generating visualization components...**\n\n");
6717
6766
  wrappedStreamCallback("__TEXT_COMPLETE__COMPONENT_GENERATION_START__");
6718
6767
  }
6719
6768
  let matchedComponents = [];
@@ -7080,7 +7129,8 @@ ${errorMsg}
7080
7129
  ORIGINAL_USER_PROMPT: originalUserPrompt,
7081
7130
  COMPONENT_INFO: component_info,
7082
7131
  COMPONENT_DATA: component_data,
7083
- CONVERSATION_HISTORY: conversationHistory || "No previous conversation"
7132
+ CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
7133
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
7084
7134
  });
7085
7135
  const result = await LLM.stream(
7086
7136
  {
@@ -10983,7 +11033,8 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
10983
11033
  AVAILABLE_COMPONENTS: availableComponentsText,
10984
11034
  SCHEMA_DOC: schemaDoc || "No database schema available",
10985
11035
  DATABASE_RULES: databaseRules,
10986
- AVAILABLE_TOOLS: availableToolsText
11036
+ AVAILABLE_TOOLS: availableToolsText,
11037
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
10987
11038
  });
10988
11039
  logger.debug("[DASH_COMP_REQ] Loaded dash-comp-picker prompts with schema and tools");
10989
11040
  const { apiKey, model } = getApiKeyAndModel(
@@ -11132,7 +11183,8 @@ async function createFilterWithLLM(prompt, components, existingComponents, anthr
11132
11183
  EXISTING_COMPONENTS: formatExistingComponentsForPrompt(existingComponents),
11133
11184
  SCHEMA_DOC: schemaDoc || "No database schema available",
11134
11185
  DATABASE_RULES: databaseRules,
11135
- AVAILABLE_TOOLS: formatToolsForPrompt(tools)
11186
+ AVAILABLE_TOOLS: formatToolsForPrompt(tools),
11187
+ CURRENT_DATETIME: getCurrentDateTimeForPrompt()
11136
11188
  });
11137
11189
  logger.debug("[DASH_COMP_REQ:FILTER] Loaded dash-filter-picker prompts");
11138
11190
  const { apiKey, model } = getApiKeyAndModel(