@superatomai/sdk-node 0.0.47 → 0.0.49

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
@@ -2043,12 +2043,27 @@ var ComponentListResponseMessageSchema = z3.object({
2043
2043
  type: z3.literal("COMPONENT_LIST_RES"),
2044
2044
  payload: ComponentListResponsePayloadSchema
2045
2045
  });
2046
+ var OutputFieldSchema = z3.object({
2047
+ name: z3.string(),
2048
+ // Field name (column name in the result)
2049
+ type: z3.enum(["string", "number", "boolean", "date"]),
2050
+ description: z3.string()
2051
+ // What this field contains
2052
+ });
2053
+ var OutputSchema = z3.object({
2054
+ description: z3.string(),
2055
+ // Brief description of what the output represents
2056
+ fields: z3.array(OutputFieldSchema)
2057
+ // List of fields in each record (like columns in a table)
2058
+ });
2046
2059
  var ToolSchema = z3.object({
2047
2060
  id: z3.string(),
2048
2061
  name: z3.string(),
2049
2062
  description: z3.string(),
2050
2063
  params: z3.record(z3.string()),
2051
- fn: z3.function().args(z3.any()).returns(z3.any())
2064
+ fn: z3.function().args(z3.any()).returns(z3.any()),
2065
+ outputSchema: OutputSchema.optional()
2066
+ // Optional: describes the data structure returned by this tool
2052
2067
  });
2053
2068
  var UserQueryFiltersSchema = z3.object({
2054
2069
  username: z3.string().optional(),
@@ -5654,17 +5669,27 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
5654
5669
  let executedToolsText = "No external tools were executed for data fetching.";
5655
5670
  if (executedTools && executedTools.length > 0) {
5656
5671
  logger.info(`[${this.getProviderName()}] Passing ${executedTools.length} executed tools to component matching`);
5657
- 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 result data to populate deferred tool parameters when applicable.**\n\n" + executedTools.map((tool, idx) => {
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) => {
5658
5673
  let resultPreview = "No result data";
5659
5674
  if (tool.result) {
5660
5675
  const resultStr = typeof tool.result === "string" ? tool.result : JSON.stringify(tool.result, null, 2);
5661
5676
  resultPreview = resultStr.length > 2e3 ? resultStr.substring(0, 2e3) + "\n... (truncated)" : resultStr;
5662
5677
  }
5678
+ let outputSchemaText = "Not available";
5679
+ if (tool.outputSchema) {
5680
+ const fields = tool.outputSchema.fields || [];
5681
+ const recordCount = tool.result?._recordCount || (Array.isArray(tool.result) ? tool.result.length : "unknown");
5682
+ outputSchemaText = `Returns ARRAY of ${recordCount} records. ${tool.outputSchema.description}
5683
+ Fields in EACH ROW (these are per-row values, NOT aggregates):
5684
+ ${fields.map((f) => ` - ${f.name} (${f.type}): ${f.description}`).join("\n")}
5685
+ NOTE: For aggregate values (SUM, COUNT, AVG across all rows), write SQL query instead.`;
5686
+ }
5663
5687
  return `${idx + 1}. **${tool.name}**
5664
5688
  toolId: "${tool.id}" (USE THIS EXACT VALUE for externalTool.toolId)
5665
5689
  toolName: "${tool.name}" (USE THIS EXACT VALUE for externalTool.toolName)
5666
5690
  parameters: ${JSON.stringify(tool.params || {})} (USE THESE for externalTool.parameters)
5667
- result: ${resultPreview}`;
5691
+ outputSchema: ${outputSchemaText}
5692
+ result preview: ${resultPreview}`;
5668
5693
  }).join("\n\n");
5669
5694
  }
5670
5695
  const schemaDoc = schema.generateSchemaDocumentation();
@@ -5777,23 +5802,9 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
5777
5802
  true
5778
5803
  // Parse as JSON
5779
5804
  );
5780
- logger.debug(`[${this.getProviderName()}] Component matching response parsed successfully`);
5781
- const componentSuggestionPattern = /c\d+:(\w+)\s*:\s*(.+)/g;
5782
- const suggestedComponents = [];
5783
- let match;
5784
- while ((match = componentSuggestionPattern.exec(analysisContent)) !== null) {
5785
- suggestedComponents.push({
5786
- type: match[1],
5787
- reasoning: match[2].trim()
5788
- });
5789
- }
5790
5805
  const matchedComponents = result.matchedComponents || [];
5791
5806
  const layoutTitle = result.layoutTitle || "Dashboard";
5792
5807
  const layoutDescription = result.layoutDescription || "Multi-component dashboard";
5793
- logger.info(`[${this.getProviderName()}] \u{1F4CA} Component Suggestions from Text Analysis: ${suggestedComponents.length}`);
5794
- suggestedComponents.forEach((comp, idx) => {
5795
- logger.info(`[${this.getProviderName()}] c${idx + 1}: ${comp.type} - ${comp.reasoning}`);
5796
- });
5797
5808
  logger.info(`[${this.getProviderName()}] \u{1F4E6} Matched Components from LLM: ${matchedComponents.length}`);
5798
5809
  matchedComponents.forEach((comp, idx) => {
5799
5810
  logger.info(`[${this.getProviderName()}] ${idx + 1}. ${comp.componentType} (${comp.componentName}) - ${comp.originalSuggestion || "N/A"}`);
@@ -5801,22 +5812,7 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
5801
5812
  logger.file("\n=============================\nFull LLM response:", JSON.stringify(result, null, 2));
5802
5813
  const rawActions = result.actions || [];
5803
5814
  const actions = convertQuestionsToActions(rawActions);
5804
- logger.info(`[${this.getProviderName()}] Matched ${matchedComponents.length} components from text response`);
5805
- logger.info(`[${this.getProviderName()}] Layout title: "${layoutTitle}"`);
5806
- logger.info(`[${this.getProviderName()}] Layout description: "${layoutDescription}"`);
5807
- logger.info(`[${this.getProviderName()}] Generated ${actions.length} follow-up actions`);
5808
- if (suggestedComponents.length > 0) {
5809
- logCollector?.info(`\u{1F4DD} Text Analysis suggested ${suggestedComponents.length} dashboard components:`);
5810
- suggestedComponents.forEach((comp, idx) => {
5811
- logCollector?.info(` c${idx + 1}: ${comp.type} - ${comp.reasoning}`);
5812
- });
5813
- }
5814
5815
  if (matchedComponents.length > 0) {
5815
- logCollector?.info(`\u{1F4E6} Matched ${matchedComponents.length} components for dashboard`);
5816
- if (suggestedComponents.length !== matchedComponents.length) {
5817
- logCollector?.warn(`\u26A0\uFE0F Component count mismatch: Suggested ${suggestedComponents.length}, but matched ${matchedComponents.length}`);
5818
- }
5819
- logCollector?.info(`Dashboard: "${layoutTitle}"`);
5820
5816
  matchedComponents.forEach((comp, idx) => {
5821
5817
  logCollector?.info(` ${idx + 1}. ${comp.componentName} (${comp.componentType}): ${comp.reasoning}`);
5822
5818
  if (comp.props?.query) {
@@ -5828,12 +5824,6 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
5828
5824
  }
5829
5825
  });
5830
5826
  }
5831
- if (actions.length > 0) {
5832
- logCollector?.info(`Generated ${actions.length} follow-up questions`);
5833
- actions.forEach((action, idx) => {
5834
- logCollector?.info(` ${idx + 1}. ${action.name}`);
5835
- });
5836
- }
5837
5827
  const finalComponents = matchedComponents.map((mc) => {
5838
5828
  const originalComponent = components.find((c) => c.id === mc.componentId);
5839
5829
  if (!originalComponent) {
@@ -6402,8 +6392,10 @@ Please try rephrasing your request or contact support.
6402
6392
  name: externalTool.name,
6403
6393
  params: toolInput,
6404
6394
  // The actual parameters used in this execution
6405
- result: resultSummary
6395
+ result: resultSummary,
6406
6396
  // Store summary instead of full result to save memory
6397
+ outputSchema: externalTool.outputSchema
6398
+ // Include output schema for component config generation
6407
6399
  });
6408
6400
  logger.info(`[${this.getProviderName()}] Tracked executed tool: ${externalTool.name} with params: ${JSON.stringify(toolInput)}`);
6409
6401
  }