@superatomai/sdk-node 0.0.21-mds → 0.0.22-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
@@ -14597,7 +14597,7 @@ Fixed SQL query:`;
14597
14597
  }
14598
14598
 
14599
14599
  // src/dashComp/create-filter.ts
14600
- async function createFilterWithLLM(prompt, components, existingComponents, anthropicApiKey, groqApiKey, geminiApiKey, openaiApiKey, llmProviders, tools, dashCompModels) {
14600
+ async function createFilterWithLLM(prompt, components, existingComponents, anthropicApiKey, groqApiKey, geminiApiKey, openaiApiKey, llmProviders, tools, dashCompModels, collections) {
14601
14601
  const errors = [];
14602
14602
  try {
14603
14603
  const filterComponents = components.filter((c) => c.type.startsWith("Filter"));
@@ -14723,11 +14723,50 @@ async function createFilterWithLLM(prompt, components, existingComponents, anthr
14723
14723
  if (executedTools.length > 0) {
14724
14724
  logger.info(`[DASH_COMP_REQ:FILTER] Executed ${executedTools.length} external tool(s): ${executedTools.map((t) => t.name).join(", ")}`);
14725
14725
  }
14726
+ const updatedComponents = result.updatedComponents || [];
14727
+ for (const comp of updatedComponents) {
14728
+ const extTool = comp.props?.externalTool;
14729
+ if (!extTool?.parameters?.sql || !extTool?.toolId) continue;
14730
+ let sql = extTool.parameters.sql;
14731
+ const defaultParams = extTool.parameters.params || {};
14732
+ const toolId = extTool.toolId;
14733
+ const toolName = extTool.toolName;
14734
+ sql = ensureQueryLimit(sql, DEFAULT_QUERY_LIMIT, MAX_COMPONENT_QUERY_LIMIT, getDbTypeFromToolId(toolId));
14735
+ extTool.parameters.sql = sql;
14736
+ if (collections?.["external-tools"]?.["execute"]) {
14737
+ try {
14738
+ const valResult = await collections["external-tools"]["execute"]({
14739
+ toolId,
14740
+ toolName,
14741
+ sql,
14742
+ ...defaultParams,
14743
+ data: {}
14744
+ });
14745
+ if (valResult?.success === false || valResult?.error) {
14746
+ const errMsg = valResult?.error || "Unknown error";
14747
+ logger.warn(`[DASH_COMP_REQ:FILTER] SQL validation failed for component ${comp.id}: ${typeof errMsg === "string" ? errMsg : JSON.stringify(errMsg)}`);
14748
+ continue;
14749
+ }
14750
+ const cacheKey2 = `${toolId}:${sql}`;
14751
+ queryCache.set(cacheKey2, valResult?.data ?? valResult);
14752
+ logger.info(`[DASH_COMP_REQ:FILTER] SQL validated and cached for component: ${comp.id}`);
14753
+ } catch (err) {
14754
+ const errMsg = err instanceof Error ? err.message : String(err);
14755
+ logger.warn(`[DASH_COMP_REQ:FILTER] SQL validation error for component ${comp.id}: ${errMsg}`);
14756
+ }
14757
+ }
14758
+ const { sql: _sql, ...restParams } = extTool.parameters;
14759
+ const cacheKey = `${toolId}:${sql}`;
14760
+ const cachedData = queryCache.get(cacheKey);
14761
+ const queryId = queryCache.storeQuery(sql, cachedData);
14762
+ extTool.parameters = { queryId, ...restParams };
14763
+ logger.info(`[DASH_COMP_REQ:FILTER] Replaced SQL with queryId: ${queryId} for component: ${comp.id}`);
14764
+ }
14726
14765
  return {
14727
14766
  success: true,
14728
14767
  data: {
14729
14768
  filterComponent: result.filterComponent,
14730
- updatedComponents: result.updatedComponents || [],
14769
+ updatedComponents,
14731
14770
  filterBindings: result.filterBindings || {},
14732
14771
  reasoning: result.reasoning || "Filter created based on user prompt",
14733
14772
  executedTools: executedTools.length > 0 ? executedTools : void 0
@@ -14923,7 +14962,8 @@ var processDashCompRequest = async (data, components, _sendMessage, anthropicApi
14923
14962
  openaiApiKey,
14924
14963
  llmProviders,
14925
14964
  tools,
14926
- dashCompModels
14965
+ dashCompModels,
14966
+ collections
14927
14967
  );
14928
14968
  } else {
14929
14969
  llmResponse = await pickComponentWithLLM(