@superatomai/sdk-node 0.0.48 → 0.0.50

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
@@ -5670,24 +5670,22 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
5670
5670
  if (executedTools && executedTools.length > 0) {
5671
5671
  logger.info(`[${this.getProviderName()}] Passing ${executedTools.length} executed tools to component matching`);
5672
5672
  executedToolsText = "The following external tools were executed to fetch data.\n**IMPORTANT: For components displaying this data, use externalTool prop instead of query.**\n**IMPORTANT: Use the outputSchema fields to set correct config keys (xAxisKey, yAxisKey, valueKey, nameKey, etc.)**\n**IMPORTANT: Use the result data to populate deferred tool parameters when applicable.**\n\n" + executedTools.map((tool, idx) => {
5673
- let resultPreview = "No result data";
5674
- if (tool.result) {
5675
- const resultStr = typeof tool.result === "string" ? tool.result : JSON.stringify(tool.result, null, 2);
5676
- resultPreview = resultStr.length > 2e3 ? resultStr.substring(0, 2e3) + "\n... (truncated)" : resultStr;
5677
- }
5678
5673
  let outputSchemaText = "Not available";
5674
+ let recordCount = "unknown";
5679
5675
  if (tool.outputSchema) {
5680
5676
  const fields = tool.outputSchema.fields || [];
5677
+ recordCount = tool.result?._recordCount || (Array.isArray(tool.result) ? tool.result.length : "unknown");
5681
5678
  outputSchemaText = `${tool.outputSchema.description}
5682
- Fields (use these exact names for component config):
5679
+ Fields in EACH ROW (per-row values, NOT aggregates):
5683
5680
  ${fields.map((f) => ` - ${f.name} (${f.type}): ${f.description}`).join("\n")}`;
5684
5681
  }
5685
5682
  return `${idx + 1}. **${tool.name}**
5686
5683
  toolId: "${tool.id}" (USE THIS EXACT VALUE for externalTool.toolId)
5687
5684
  toolName: "${tool.name}" (USE THIS EXACT VALUE for externalTool.toolName)
5688
5685
  parameters: ${JSON.stringify(tool.params || {})} (USE THESE for externalTool.parameters)
5686
+ recordCount: ${recordCount} rows returned
5689
5687
  outputSchema: ${outputSchemaText}
5690
- result preview: ${resultPreview}`;
5688
+ \u26A0\uFE0F DO NOT embed this tool's data in SQL - use externalTool prop OR query database tables`;
5691
5689
  }).join("\n\n");
5692
5690
  }
5693
5691
  const schemaDoc = schema.generateSchemaDocumentation();
@@ -5800,23 +5798,9 @@ ${fields.map((f) => ` - ${f.name} (${f.type}): ${f.description}`).join("\n")
5800
5798
  true
5801
5799
  // Parse as JSON
5802
5800
  );
5803
- logger.debug(`[${this.getProviderName()}] Component matching response parsed successfully`);
5804
- const componentSuggestionPattern = /c\d+:(\w+)\s*:\s*(.+)/g;
5805
- const suggestedComponents = [];
5806
- let match;
5807
- while ((match = componentSuggestionPattern.exec(analysisContent)) !== null) {
5808
- suggestedComponents.push({
5809
- type: match[1],
5810
- reasoning: match[2].trim()
5811
- });
5812
- }
5813
5801
  const matchedComponents = result.matchedComponents || [];
5814
5802
  const layoutTitle = result.layoutTitle || "Dashboard";
5815
5803
  const layoutDescription = result.layoutDescription || "Multi-component dashboard";
5816
- logger.info(`[${this.getProviderName()}] \u{1F4CA} Component Suggestions from Text Analysis: ${suggestedComponents.length}`);
5817
- suggestedComponents.forEach((comp, idx) => {
5818
- logger.info(`[${this.getProviderName()}] c${idx + 1}: ${comp.type} - ${comp.reasoning}`);
5819
- });
5820
5804
  logger.info(`[${this.getProviderName()}] \u{1F4E6} Matched Components from LLM: ${matchedComponents.length}`);
5821
5805
  matchedComponents.forEach((comp, idx) => {
5822
5806
  logger.info(`[${this.getProviderName()}] ${idx + 1}. ${comp.componentType} (${comp.componentName}) - ${comp.originalSuggestion || "N/A"}`);
@@ -5824,22 +5808,7 @@ ${fields.map((f) => ` - ${f.name} (${f.type}): ${f.description}`).join("\n")
5824
5808
  logger.file("\n=============================\nFull LLM response:", JSON.stringify(result, null, 2));
5825
5809
  const rawActions = result.actions || [];
5826
5810
  const actions = convertQuestionsToActions(rawActions);
5827
- logger.info(`[${this.getProviderName()}] Matched ${matchedComponents.length} components from text response`);
5828
- logger.info(`[${this.getProviderName()}] Layout title: "${layoutTitle}"`);
5829
- logger.info(`[${this.getProviderName()}] Layout description: "${layoutDescription}"`);
5830
- logger.info(`[${this.getProviderName()}] Generated ${actions.length} follow-up actions`);
5831
- if (suggestedComponents.length > 0) {
5832
- logCollector?.info(`\u{1F4DD} Text Analysis suggested ${suggestedComponents.length} dashboard components:`);
5833
- suggestedComponents.forEach((comp, idx) => {
5834
- logCollector?.info(` c${idx + 1}: ${comp.type} - ${comp.reasoning}`);
5835
- });
5836
- }
5837
5811
  if (matchedComponents.length > 0) {
5838
- logCollector?.info(`\u{1F4E6} Matched ${matchedComponents.length} components for dashboard`);
5839
- if (suggestedComponents.length !== matchedComponents.length) {
5840
- logCollector?.warn(`\u26A0\uFE0F Component count mismatch: Suggested ${suggestedComponents.length}, but matched ${matchedComponents.length}`);
5841
- }
5842
- logCollector?.info(`Dashboard: "${layoutTitle}"`);
5843
5812
  matchedComponents.forEach((comp, idx) => {
5844
5813
  logCollector?.info(` ${idx + 1}. ${comp.componentName} (${comp.componentType}): ${comp.reasoning}`);
5845
5814
  if (comp.props?.query) {
@@ -5851,23 +5820,37 @@ ${fields.map((f) => ` - ${f.name} (${f.type}): ${f.description}`).join("\n")
5851
5820
  }
5852
5821
  });
5853
5822
  }
5854
- if (actions.length > 0) {
5855
- logCollector?.info(`Generated ${actions.length} follow-up questions`);
5856
- actions.forEach((action, idx) => {
5857
- logCollector?.info(` ${idx + 1}. ${action.name}`);
5858
- });
5859
- }
5860
5823
  const finalComponents = matchedComponents.map((mc) => {
5861
5824
  const originalComponent = components.find((c) => c.id === mc.componentId);
5862
5825
  if (!originalComponent) {
5863
5826
  logger.warn(`[${this.getProviderName()}] Component ${mc.componentId} not found in available components`);
5864
5827
  return null;
5865
5828
  }
5829
+ let cleanedProps = { ...mc.props };
5830
+ if (cleanedProps.externalTool) {
5831
+ const toolId = cleanedProps.externalTool.toolId;
5832
+ const validToolIds = (executedTools || []).map((t) => t.id);
5833
+ const isValidTool = toolId && typeof toolId === "string" && validToolIds.includes(toolId);
5834
+ if (!isValidTool) {
5835
+ logger.warn(`[${this.getProviderName()}] externalTool.toolId "${toolId}" not found in executed tools [${validToolIds.join(", ")}], setting to null`);
5836
+ cleanedProps.externalTool = null;
5837
+ }
5838
+ }
5839
+ if (cleanedProps.query) {
5840
+ const queryStr = typeof cleanedProps.query === "string" ? cleanedProps.query : cleanedProps.query?.sql || "";
5841
+ if (queryStr.includes("OPENJSON") || queryStr.includes("JSON_VALUE")) {
5842
+ logger.warn(`[${this.getProviderName()}] Query contains OPENJSON/JSON_VALUE (invalid - cannot parse tool result), setting query to null`);
5843
+ cleanedProps.query = null;
5844
+ }
5845
+ }
5846
+ if (cleanedProps.query && cleanedProps.externalTool) {
5847
+ logger.info(`[${this.getProviderName()}] Both query and externalTool exist, keeping both - frontend will decide`);
5848
+ }
5866
5849
  return {
5867
5850
  ...originalComponent,
5868
5851
  props: {
5869
5852
  ...originalComponent.props,
5870
- ...mc.props
5853
+ ...cleanedProps
5871
5854
  }
5872
5855
  };
5873
5856
  }).filter(Boolean);