@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.mjs CHANGED
@@ -4788,20 +4788,25 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4788
4788
  logCollector?.info("Generating text response with query execution capability...");
4789
4789
  const tools = [{
4790
4790
  name: "execute_query",
4791
- 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.",
4791
+ 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.",
4792
4792
  input_schema: {
4793
4793
  type: "object",
4794
4794
  properties: {
4795
- query: {
4795
+ sql: {
4796
4796
  type: "string",
4797
- description: "The SQL query to execute. Must be valid SQL syntax using table and column names from the schema."
4797
+ 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."
4798
+ },
4799
+ params: {
4800
+ type: "object",
4801
+ 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.',
4802
+ additionalProperties: true
4798
4803
  },
4799
4804
  reasoning: {
4800
4805
  type: "string",
4801
4806
  description: "Brief explanation of what this query does and why it answers the user's question."
4802
4807
  }
4803
4808
  },
4804
- required: ["query"],
4809
+ required: ["sql"],
4805
4810
  additionalProperties: false
4806
4811
  }
4807
4812
  }];
@@ -4896,14 +4901,18 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4896
4901
  } : void 0;
4897
4902
  const toolHandler = async (toolName, toolInput) => {
4898
4903
  if (toolName === "execute_query") {
4899
- let query = toolInput.query;
4904
+ let sql = toolInput.sql;
4905
+ const params = toolInput.params || {};
4900
4906
  const reasoning = toolInput.reasoning;
4901
4907
  const { ensureQueryLimit: ensureQueryLimit2 } = await Promise.resolve().then(() => (init_utils(), utils_exports));
4902
- query = ensureQueryLimit2(query, 32, 32);
4903
- const queryKey = query.toLowerCase().replace(/\s+/g, " ").trim();
4908
+ sql = ensureQueryLimit2(sql, 32, 32);
4909
+ const queryKey = sql.toLowerCase().replace(/\s+/g, " ").trim();
4904
4910
  const attempts = (queryAttempts.get(queryKey) || 0) + 1;
4905
4911
  queryAttempts.set(queryKey, attempts);
4906
- logger.info(`[${this.getProviderName()}] Executing query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS}): ${query.substring(0, 100)}...`);
4912
+ logger.info(`[${this.getProviderName()}] Executing query (attempt ${attempts}/${MAX_QUERY_ATTEMPTS}): ${sql.substring(0, 100)}...`);
4913
+ if (Object.keys(params).length > 0) {
4914
+ logger.info(`[${this.getProviderName()}] Query params: ${JSON.stringify(params)}`);
4915
+ }
4907
4916
  if (reasoning) {
4908
4917
  logCollector?.info(`Query reasoning: ${reasoning}`);
4909
4918
  }
@@ -4925,6 +4934,8 @@ Please try rephrasing your question or simplifying your request.
4925
4934
  }
4926
4935
  try {
4927
4936
  if (wrappedStreamCallback) {
4937
+ const paramsDisplay = Object.keys(params).length > 0 ? `
4938
+ **Parameters:** ${JSON.stringify(params)}` : "";
4928
4939
  if (attempts === 1) {
4929
4940
  wrappedStreamCallback(`
4930
4941
 
@@ -4938,8 +4949,8 @@ Please try rephrasing your question or simplifying your request.
4938
4949
  }
4939
4950
  wrappedStreamCallback(`\u{1F4DD} **Generated SQL Query:**
4940
4951
  \`\`\`sql
4941
- ${query}
4942
- \`\`\`
4952
+ ${sql}
4953
+ \`\`\`${paramsDisplay}
4943
4954
 
4944
4955
  `);
4945
4956
  wrappedStreamCallback(`\u26A1 **Executing query...**
@@ -4958,8 +4969,8 @@ ${query}
4958
4969
  }
4959
4970
  wrappedStreamCallback(`\u{1F4DD} **Corrected SQL Query:**
4960
4971
  \`\`\`sql
4961
- ${query}
4962
- \`\`\`
4972
+ ${sql}
4973
+ \`\`\`${paramsDisplay}
4963
4974
 
4964
4975
  `);
4965
4976
  wrappedStreamCallback(`\u26A1 **Executing query...**
@@ -4969,13 +4980,14 @@ ${query}
4969
4980
  }
4970
4981
  logCollector?.logQuery(
4971
4982
  `Executing SQL query (attempt ${attempts})`,
4972
- query,
4983
+ { sql, params },
4973
4984
  { reasoning, attempt: attempts }
4974
4985
  );
4975
4986
  if (!collections || !collections["database"] || !collections["database"]["execute"]) {
4976
4987
  throw new Error("Database collection not registered. Please register database.execute collection to execute queries.");
4977
4988
  }
4978
- const result2 = await collections["database"]["execute"]({ sql: query });
4989
+ const queryPayload = Object.keys(params).length > 0 ? { sql: JSON.stringify({ sql, values: params }) } : { sql };
4990
+ const result2 = await collections["database"]["execute"](queryPayload);
4979
4991
  const data = result2?.data || result2;
4980
4992
  const rowCount = result2?.count ?? (Array.isArray(data) ? data.length : "N/A");
4981
4993
  logger.info(`[${this.getProviderName()}] Query executed successfully, rows returned: ${rowCount}`);
@@ -7054,6 +7066,7 @@ async function handleGetAll(id, executeCollection, userManager, sendMessage, cli
7054
7066
  email: user.email,
7055
7067
  fullname: user.fullname,
7056
7068
  role: user.role,
7069
+ userInfo: user.userInfo,
7057
7070
  createdAt: user.createdAt,
7058
7071
  updatedAt: user.updatedAt
7059
7072
  }));
@@ -7107,6 +7120,7 @@ async function handleGetOne(id, numericId, username, executeCollection, userMana
7107
7120
  email: result.data?.email,
7108
7121
  fullname: result.data?.fullname,
7109
7122
  role: result.data?.role,
7123
+ userInfo: result.data?.userInfo,
7110
7124
  createdAt: result.data?.createdAt,
7111
7125
  updatedAt: result.data?.updatedAt
7112
7126
  };
@@ -7169,6 +7183,7 @@ async function handleQuery(id, filters, limit, sort, executeCollection, userMana
7169
7183
  email: user.email,
7170
7184
  fullname: user.fullname,
7171
7185
  role: user.role,
7186
+ userInfo: user.userInfo,
7172
7187
  createdAt: user.createdAt,
7173
7188
  updatedAt: user.updatedAt
7174
7189
  }));
@@ -7192,6 +7207,7 @@ async function handleQuery(id, filters, limit, sort, executeCollection, userMana
7192
7207
  email: user.email,
7193
7208
  fullname: user.fullname,
7194
7209
  role: user.role,
7210
+ userInfo: user.userInfo,
7195
7211
  wsIds: user.wsIds || []
7196
7212
  }));
7197
7213
  logger.info(`[FILE] Retrieved ${sanitizedUsers.length} users (all - no query filter)`);