@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 +27 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7057,11 +7057,12 @@ ${queryDisplay}
|
|
|
7057
7057
|
}
|
|
7058
7058
|
await streamDelay();
|
|
7059
7059
|
}
|
|
7060
|
+
let queryStartTime = Date.now();
|
|
7060
7061
|
try {
|
|
7061
7062
|
if (this.streamBuffer.hasCallback()) {
|
|
7062
7063
|
this.streamBuffer.write(`__QUERY_TIMER_START_Executing query__`);
|
|
7063
7064
|
}
|
|
7064
|
-
|
|
7065
|
+
queryStartTime = Date.now();
|
|
7065
7066
|
const result = await this.tool.fn(cappedInput);
|
|
7066
7067
|
if (this.streamBuffer.hasCallback()) {
|
|
7067
7068
|
const querySeconds = ((Date.now() - queryStartTime) / 1e3).toFixed(1);
|
|
@@ -7131,6 +7132,10 @@ ${formatted}`;
|
|
|
7131
7132
|
const errorMsg = execError instanceof Error ? execError.message : typeof execError === "object" && execError !== null ? execError.message || execError.error || JSON.stringify(execError) : String(execError);
|
|
7132
7133
|
logger.warn(`[SourceAgent:${this.tool.name}] Tool execution failed (attempt ${this.attempts}/${this.config.maxRetries}): ${errorMsg}`);
|
|
7133
7134
|
if (this.streamBuffer.hasCallback()) {
|
|
7135
|
+
const querySeconds = ((Date.now() - queryStartTime) / 1e3).toFixed(1);
|
|
7136
|
+
this.streamBuffer.write(`__QUERY_TIMER_DONE_${querySeconds}__
|
|
7137
|
+
|
|
7138
|
+
`);
|
|
7134
7139
|
this.streamBuffer.write(`\u274C **Query failed:** ${errorMsg}
|
|
7135
7140
|
|
|
7136
7141
|
`);
|
|
@@ -7141,10 +7146,11 @@ Analyze the error and try again with a corrected query.`;
|
|
|
7141
7146
|
}
|
|
7142
7147
|
};
|
|
7143
7148
|
const hasSchemaSearch = !!schemaSearchFn;
|
|
7144
|
-
const
|
|
7145
|
-
const
|
|
7146
|
-
const
|
|
7147
|
-
const
|
|
7149
|
+
const totalQueryAttempts = this.config.maxRetries + 2;
|
|
7150
|
+
const perQueryCost = hasSchemaSearch ? 2 : 1;
|
|
7151
|
+
const extraSearches = hasSchemaSearch ? 2 : 0;
|
|
7152
|
+
const responseIterations = 1;
|
|
7153
|
+
const maxIterations = totalQueryAttempts * perQueryCost + extraSearches + responseIterations;
|
|
7148
7154
|
await LLM.streamWithTools(
|
|
7149
7155
|
{ sys: prompts.system, user: prompts.user },
|
|
7150
7156
|
tools,
|
|
@@ -7243,12 +7249,18 @@ Analyze the error and try again with a corrected query.`;
|
|
|
7243
7249
|
if (hasSchemaSearch && schemaTier === "very_large") {
|
|
7244
7250
|
schemaSearchInstructions = `## Schema Search \u2014 REQUIRED
|
|
7245
7251
|
This source has a very large schema. The schema above shows only table names \u2014 no column details.
|
|
7246
|
-
**You MUST use search_schema BEFORE writing any query.** Do NOT guess column names.
|
|
7252
|
+
**You MUST use search_schema BEFORE writing any query.** Do NOT guess or fabricate column names.
|
|
7247
7253
|
1. FIRST: Call search_schema with keywords related to the requested data
|
|
7248
7254
|
2. Review the returned column details, types, and sample values carefully
|
|
7249
7255
|
3. THEN write your SQL query using the EXACT column names from the search results
|
|
7250
|
-
|
|
7251
|
-
**
|
|
7256
|
+
|
|
7257
|
+
**CRITICAL: Column names in this database may NOT follow predictable patterns.**
|
|
7258
|
+
- Do NOT assume column name prefixes based on table name abbreviations
|
|
7259
|
+
- Do NOT invent column names by combining a table alias with a guessed suffix
|
|
7260
|
+
- ONLY use column names that appeared in search_schema results \u2014 copy them exactly
|
|
7261
|
+
- If you need columns you haven't searched for, call search_schema again before writing the query
|
|
7262
|
+
|
|
7263
|
+
You may search multiple times with different keywords if the first search doesn't find what you need.`;
|
|
7252
7264
|
} else if (hasSchemaSearch) {
|
|
7253
7265
|
schemaSearchInstructions = `## Schema Search \u2014 REQUIRED
|
|
7254
7266
|
This source has a large schema. The top tables are shown in detail above, but not all tables have full column details.
|
|
@@ -7704,8 +7716,8 @@ var DEFAULT_AGENT_CONFIG = {
|
|
|
7704
7716
|
// will use the provider's default model
|
|
7705
7717
|
sourceAgentModel: "",
|
|
7706
7718
|
// will use the provider's default model
|
|
7707
|
-
maxRetries:
|
|
7708
|
-
//
|
|
7719
|
+
maxRetries: 2,
|
|
7720
|
+
// 2 retries = 3 total query attempts (1 initial + 2 retries for SQL errors)
|
|
7709
7721
|
maxIterations: 8
|
|
7710
7722
|
// schema search (2-3) + query attempts (2) + LLM responses + final
|
|
7711
7723
|
};
|
|
@@ -10388,7 +10400,8 @@ var get_agent_user_response = async (prompt, components, anthropicApiKey, groqAp
|
|
|
10388
10400
|
conversationHistory,
|
|
10389
10401
|
streamBuffer.hasCallback() ? (chunk) => streamBuffer.write(chunk) : void 0
|
|
10390
10402
|
);
|
|
10391
|
-
const
|
|
10403
|
+
const rawText = streamBuffer.getFullText() || agentResponse.text || "I apologize, but I was unable to generate a response.";
|
|
10404
|
+
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, "");
|
|
10392
10405
|
streamBuffer.flush();
|
|
10393
10406
|
const hasExecutedTools = agentResponse.executedTools.length > 0;
|
|
10394
10407
|
let matchedComponents = [];
|
|
@@ -10397,16 +10410,17 @@ var get_agent_user_response = async (prompt, components, anthropicApiKey, groqAp
|
|
|
10397
10410
|
let actions = [];
|
|
10398
10411
|
if (!hasExecutedTools) {
|
|
10399
10412
|
logger.info(`[AgentFlow] No tools executed \u2014 general question, wrapping in DynamicMarkdownBlock`);
|
|
10413
|
+
const mainAgentText = agentResponse.text || textResponse;
|
|
10400
10414
|
const nextQuestions = await llmInstance.generateNextQuestions(
|
|
10401
10415
|
prompt,
|
|
10402
10416
|
null,
|
|
10403
10417
|
void 0,
|
|
10404
10418
|
apiKey,
|
|
10405
10419
|
conversationHistory,
|
|
10406
|
-
|
|
10420
|
+
mainAgentText
|
|
10407
10421
|
);
|
|
10408
10422
|
actions = convertQuestionsToActions(nextQuestions);
|
|
10409
|
-
const markdownContent =
|
|
10423
|
+
const markdownContent = mainAgentText.replace(/<DashboardComponents>[\s\S]*?<\/DashboardComponents>/g, "").trim();
|
|
10410
10424
|
matchedComponents = [{
|
|
10411
10425
|
id: "dynamic-markdown-block",
|
|
10412
10426
|
name: "DynamicMarkdownBlock",
|