@superatomai/sdk-node 0.0.25-mds → 0.0.26-mds

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.js CHANGED
@@ -7117,11 +7117,12 @@ ${queryDisplay}
7117
7117
  }
7118
7118
  await streamDelay();
7119
7119
  }
7120
+ let queryStartTime = Date.now();
7120
7121
  try {
7121
7122
  if (this.streamBuffer.hasCallback()) {
7122
7123
  this.streamBuffer.write(`__QUERY_TIMER_START_Executing query__`);
7123
7124
  }
7124
- const queryStartTime = Date.now();
7125
+ queryStartTime = Date.now();
7125
7126
  const result = await this.tool.fn(cappedInput);
7126
7127
  if (this.streamBuffer.hasCallback()) {
7127
7128
  const querySeconds = ((Date.now() - queryStartTime) / 1e3).toFixed(1);
@@ -7191,6 +7192,10 @@ ${formatted}`;
7191
7192
  const errorMsg = execError instanceof Error ? execError.message : typeof execError === "object" && execError !== null ? execError.message || execError.error || JSON.stringify(execError) : String(execError);
7192
7193
  logger.warn(`[SourceAgent:${this.tool.name}] Tool execution failed (attempt ${this.attempts}/${this.config.maxRetries}): ${errorMsg}`);
7193
7194
  if (this.streamBuffer.hasCallback()) {
7195
+ const querySeconds = ((Date.now() - queryStartTime) / 1e3).toFixed(1);
7196
+ this.streamBuffer.write(`__QUERY_TIMER_DONE_${querySeconds}__
7197
+
7198
+ `);
7194
7199
  this.streamBuffer.write(`\u274C **Query failed:** ${errorMsg}
7195
7200
 
7196
7201
  `);
@@ -7201,10 +7206,11 @@ Analyze the error and try again with a corrected query.`;
7201
7206
  }
7202
7207
  };
7203
7208
  const hasSchemaSearch = !!schemaSearchFn;
7204
- const queryIterations = this.config.maxRetries + 1;
7205
- const schemaIterations = hasSchemaSearch ? 3 : 0;
7206
- const responseIterations = 2;
7207
- const maxIterations = queryIterations + schemaIterations + responseIterations;
7209
+ const totalQueryAttempts = this.config.maxRetries + 2;
7210
+ const perQueryCost = hasSchemaSearch ? 2 : 1;
7211
+ const extraSearches = hasSchemaSearch ? 2 : 0;
7212
+ const responseIterations = 1;
7213
+ const maxIterations = totalQueryAttempts * perQueryCost + extraSearches + responseIterations;
7208
7214
  await LLM.streamWithTools(
7209
7215
  { sys: prompts.system, user: prompts.user },
7210
7216
  tools,
@@ -7303,12 +7309,18 @@ Analyze the error and try again with a corrected query.`;
7303
7309
  if (hasSchemaSearch && schemaTier === "very_large") {
7304
7310
  schemaSearchInstructions = `## Schema Search \u2014 REQUIRED
7305
7311
  This source has a very large schema. The schema above shows only table names \u2014 no column details.
7306
- **You MUST use search_schema BEFORE writing any query.** Do NOT guess column names.
7312
+ **You MUST use search_schema BEFORE writing any query.** Do NOT guess or fabricate column names.
7307
7313
  1. FIRST: Call search_schema with keywords related to the requested data
7308
7314
  2. Review the returned column details, types, and sample values carefully
7309
7315
  3. THEN write your SQL query using the EXACT column names from the search results
7310
- You may search multiple times with different keywords if the first search doesn't find what you need.
7311
- **Never write a query without searching first \u2014 guessing column names wastes time on failed queries.**`;
7316
+
7317
+ **CRITICAL: Column names in this database may NOT follow predictable patterns.**
7318
+ - Do NOT assume column name prefixes based on table name abbreviations
7319
+ - Do NOT invent column names by combining a table alias with a guessed suffix
7320
+ - ONLY use column names that appeared in search_schema results \u2014 copy them exactly
7321
+ - If you need columns you haven't searched for, call search_schema again before writing the query
7322
+
7323
+ You may search multiple times with different keywords if the first search doesn't find what you need.`;
7312
7324
  } else if (hasSchemaSearch) {
7313
7325
  schemaSearchInstructions = `## Schema Search \u2014 REQUIRED
7314
7326
  This source has a large schema. The top tables are shown in detail above, but not all tables have full column details.
@@ -7764,8 +7776,8 @@ var DEFAULT_AGENT_CONFIG = {
7764
7776
  // will use the provider's default model
7765
7777
  sourceAgentModel: "",
7766
7778
  // will use the provider's default model
7767
- maxRetries: 1,
7768
- // 1 retry = 2 total query attempts (1 initial + 1 retry for SQL errors)
7779
+ maxRetries: 2,
7780
+ // 2 retries = 3 total query attempts (1 initial + 2 retries for SQL errors)
7769
7781
  maxIterations: 8
7770
7782
  // schema search (2-3) + query attempts (2) + LLM responses + final
7771
7783
  };
@@ -10448,7 +10460,8 @@ var get_agent_user_response = async (prompt, components, anthropicApiKey, groqAp
10448
10460
  conversationHistory,
10449
10461
  streamBuffer.hasCallback() ? (chunk) => streamBuffer.write(chunk) : void 0
10450
10462
  );
10451
- const textResponse = streamBuffer.getFullText() || agentResponse.text || "I apologize, but I was unable to generate a response.";
10463
+ const rawText = streamBuffer.getFullText() || agentResponse.text || "I apologize, but I was unable to generate a response.";
10464
+ const textResponse = rawText.replace(/__SB_\w+_(?:START|MSG)__/g, "").replace(/__SB_END__/g, "").replace(/__QUERY_TIMER_START_[^_]*__/g, "").replace(/__QUERY_TIMER_DONE_[\d.]+__/g, "").replace(/__TEXT_COMPLETE__COMPONENT_GENERATION_START__/g, "");
10452
10465
  streamBuffer.flush();
10453
10466
  const hasExecutedTools = agentResponse.executedTools.length > 0;
10454
10467
  let matchedComponents = [];
@@ -10457,16 +10470,17 @@ var get_agent_user_response = async (prompt, components, anthropicApiKey, groqAp
10457
10470
  let actions = [];
10458
10471
  if (!hasExecutedTools) {
10459
10472
  logger.info(`[AgentFlow] No tools executed \u2014 general question, wrapping in DynamicMarkdownBlock`);
10473
+ const mainAgentText = agentResponse.text || textResponse;
10460
10474
  const nextQuestions = await llmInstance.generateNextQuestions(
10461
10475
  prompt,
10462
10476
  null,
10463
10477
  void 0,
10464
10478
  apiKey,
10465
10479
  conversationHistory,
10466
- textResponse
10480
+ mainAgentText
10467
10481
  );
10468
10482
  actions = convertQuestionsToActions(nextQuestions);
10469
- const markdownContent = textResponse.replace(/<DashboardComponents>[\s\S]*?<\/DashboardComponents>/g, "").trim();
10483
+ const markdownContent = mainAgentText.replace(/<DashboardComponents>[\s\S]*?<\/DashboardComponents>/g, "").trim();
10470
10484
  matchedComponents = [{
10471
10485
  id: "dynamic-markdown-block",
10472
10486
  name: "DynamicMarkdownBlock",