@superatomai/sdk-node 0.0.30 → 0.0.32

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
@@ -4832,20 +4832,25 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4832
4832
  logCollector?.info("Generating text response with query execution capability...");
4833
4833
  const tools = [{
4834
4834
  name: "execute_query",
4835
- description: "Executes a SQL query against the database and returns the results. Use this when the user asks for data. If the query fails, you will receive the error and can retry with a corrected query.",
4835
+ description: "Executes a parameterized SQL query against the database. CRITICAL: NEVER hardcode literal values in WHERE/HAVING conditions - ALWAYS use $paramName placeholders and pass actual values in params object.",
4836
4836
  input_schema: {
4837
4837
  type: "object",
4838
4838
  properties: {
4839
- query: {
4839
+ sql: {
4840
4840
  type: "string",
4841
- description: "The SQL query to execute. Must be valid SQL syntax using table and column names from the schema."
4841
+ description: "SQL query with $paramName placeholders for ALL literal values in WHERE/HAVING conditions. NEVER hardcode values like WHERE status = 'Delivered' - instead use WHERE status = $status. Table names, column names, and SQL keywords stay as-is."
4842
+ },
4843
+ params: {
4844
+ type: "object",
4845
+ description: 'REQUIRED when SQL has WHERE/HAVING conditions. Maps each $paramName placeholder (without $) to its actual value. Pattern: WHERE col = $name \u2192 params: { "name": "value" }. Every placeholder in SQL MUST have a corresponding entry here.',
4846
+ additionalProperties: true
4842
4847
  },
4843
4848
  reasoning: {
4844
4849
  type: "string",
4845
4850
  description: "Brief explanation of what this query does and why it answers the user's question."
4846
4851
  }
4847
4852
  },
4848
- required: ["query"],
4853
+ required: ["sql"],
4849
4854
  additionalProperties: false
4850
4855
  }
4851
4856
  }];
@@ -4940,14 +4945,18 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4940
4945
  } : void 0;
4941
4946
  const toolHandler = async (toolName, toolInput) => {
4942
4947
  if (toolName === "execute_query") {
4943
- let query = toolInput.query;
4948
+ let sql = toolInput.sql;
4949
+ const params = toolInput.params || {};
4944
4950
  const reasoning = toolInput.reasoning;
4945
4951
  const { ensureQueryLimit: ensureQueryLimit2 } = await Promise.resolve().then(() => (init_utils(), utils_exports));
4946
- query = ensureQueryLimit2(query, 32, 32);
4947
- const queryKey = query.toLowerCase().replace(/\s+/g, " ").trim();
4952
+ sql = ensureQueryLimit2(sql, 32, 32);
4953
+ const queryKey = sql.toLowerCase().replace(/\s+/g, " ").trim();
4948
4954
  const attempts = (queryAttempts.get(queryKey) || 0) + 1;
4949
4955
  queryAttempts.set(queryKey, attempts);
4950
- logger.info(`[${this.getProviderName()}] Executing query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS}): ${query.substring(0, 100)}...`);
4956
+ logger.info(`[${this.getProviderName()}] Executing query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS}): ${sql.substring(0, 100)}...`);
4957
+ if (Object.keys(params).length > 0) {
4958
+ logger.info(`[${this.getProviderName()}] Query params: ${JSON.stringify(params)}`);
4959
+ }
4951
4960
  if (reasoning) {
4952
4961
  logCollector?.info(`Query reasoning: ${reasoning}`);
4953
4962
  }
@@ -4969,6 +4978,8 @@ Please try rephrasing your question or simplifying your request.
4969
4978
  }
4970
4979
  try {
4971
4980
  if (wrappedStreamCallback) {
4981
+ const paramsDisplay = Object.keys(params).length > 0 ? `
4982
+ **Parameters:** ${JSON.stringify(params)}` : "";
4972
4983
  if (attempts === 1) {
4973
4984
  wrappedStreamCallback(`
4974
4985
 
@@ -4982,8 +4993,8 @@ Please try rephrasing your question or simplifying your request.
4982
4993
  }
4983
4994
  wrappedStreamCallback(`\u{1F4DD} **Generated SQL Query:**
4984
4995
  \`\`\`sql
4985
- ${query}
4986
- \`\`\`
4996
+ ${sql}
4997
+ \`\`\`${paramsDisplay}
4987
4998
 
4988
4999
  `);
4989
5000
  wrappedStreamCallback(`\u26A1 **Executing query...**
@@ -5002,8 +5013,8 @@ ${query}
5002
5013
  }
5003
5014
  wrappedStreamCallback(`\u{1F4DD} **Corrected SQL Query:**
5004
5015
  \`\`\`sql
5005
- ${query}
5006
- \`\`\`
5016
+ ${sql}
5017
+ \`\`\`${paramsDisplay}
5007
5018
 
5008
5019
  `);
5009
5020
  wrappedStreamCallback(`\u26A1 **Executing query...**
@@ -5013,13 +5024,14 @@ ${query}
5013
5024
  }
5014
5025
  logCollector?.logQuery(
5015
5026
  `Executing SQL query (attempt ${attempts})`,
5016
- query,
5027
+ { sql, params },
5017
5028
  { reasoning, attempt: attempts }
5018
5029
  );
5019
5030
  if (!collections || !collections["database"] || !collections["database"]["execute"]) {
5020
5031
  throw new Error("Database collection not registered. Please register database.execute collection to execute queries.");
5021
5032
  }
5022
- const result2 = await collections["database"]["execute"]({ sql: query });
5033
+ const queryPayload = Object.keys(params).length > 0 ? { sql: JSON.stringify({ sql, values: params }) } : { sql };
5034
+ const result2 = await collections["database"]["execute"](queryPayload);
5023
5035
  const data = result2?.data || result2;
5024
5036
  const rowCount = result2?.count ?? (Array.isArray(data) ? data.length : "N/A");
5025
5037
  logger.info(`[${this.getProviderName()}] Query executed successfully, rows returned: ${rowCount}`);
@@ -7098,6 +7110,7 @@ async function handleGetAll(id, executeCollection, userManager, sendMessage, cli
7098
7110
  email: user.email,
7099
7111
  fullname: user.fullname,
7100
7112
  role: user.role,
7113
+ userInfo: user.userInfo,
7101
7114
  createdAt: user.createdAt,
7102
7115
  updatedAt: user.updatedAt
7103
7116
  }));
@@ -7151,6 +7164,7 @@ async function handleGetOne(id, numericId, username, executeCollection, userMana
7151
7164
  email: result.data?.email,
7152
7165
  fullname: result.data?.fullname,
7153
7166
  role: result.data?.role,
7167
+ userInfo: result.data?.userInfo,
7154
7168
  createdAt: result.data?.createdAt,
7155
7169
  updatedAt: result.data?.updatedAt
7156
7170
  };
@@ -7213,6 +7227,7 @@ async function handleQuery(id, filters, limit, sort, executeCollection, userMana
7213
7227
  email: user.email,
7214
7228
  fullname: user.fullname,
7215
7229
  role: user.role,
7230
+ userInfo: user.userInfo,
7216
7231
  createdAt: user.createdAt,
7217
7232
  updatedAt: user.updatedAt
7218
7233
  }));
@@ -7236,6 +7251,7 @@ async function handleQuery(id, filters, limit, sort, executeCollection, userMana
7236
7251
  email: user.email,
7237
7252
  fullname: user.fullname,
7238
7253
  role: user.role,
7254
+ userInfo: user.userInfo,
7239
7255
  wsIds: user.wsIds || []
7240
7256
  }));
7241
7257
  logger.info(`[FILE] Retrieved ${sanitizedUsers.length} users (all - no query filter)`);