@superatomai/sdk-node 0.0.40 → 0.0.42

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.d.ts CHANGED
@@ -615,6 +615,72 @@ declare const IncomingMessageSchema: z.ZodObject<{
615
615
  payload?: unknown;
616
616
  }>;
617
617
  type IncomingMessage = z.infer<typeof IncomingMessageSchema>;
618
+ declare const ComponentSchema: z.ZodObject<{
619
+ id: z.ZodString;
620
+ name: z.ZodString;
621
+ displayName: z.ZodOptional<z.ZodString>;
622
+ isDisplayComp: z.ZodOptional<z.ZodBoolean>;
623
+ type: z.ZodString;
624
+ description: z.ZodString;
625
+ props: z.ZodObject<{
626
+ query: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>;
627
+ title: z.ZodOptional<z.ZodString>;
628
+ description: z.ZodOptional<z.ZodString>;
629
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
630
+ actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
631
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
632
+ query: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>;
633
+ title: z.ZodOptional<z.ZodString>;
634
+ description: z.ZodOptional<z.ZodString>;
635
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
636
+ actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
637
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
638
+ query: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>;
639
+ title: z.ZodOptional<z.ZodString>;
640
+ description: z.ZodOptional<z.ZodString>;
641
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
642
+ actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
643
+ }, z.ZodTypeAny, "passthrough">>;
644
+ category: z.ZodOptional<z.ZodString>;
645
+ keywords: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
646
+ }, "strip", z.ZodTypeAny, {
647
+ id: string;
648
+ type: string;
649
+ name: string;
650
+ description: string;
651
+ props: {
652
+ description?: string | undefined;
653
+ query?: string | {} | undefined;
654
+ title?: string | undefined;
655
+ config?: Record<string, unknown> | undefined;
656
+ actions?: any[] | undefined;
657
+ } & {
658
+ [k: string]: unknown;
659
+ };
660
+ displayName?: string | undefined;
661
+ isDisplayComp?: boolean | undefined;
662
+ category?: string | undefined;
663
+ keywords?: string[] | undefined;
664
+ }, {
665
+ id: string;
666
+ type: string;
667
+ name: string;
668
+ description: string;
669
+ props: {
670
+ description?: string | undefined;
671
+ query?: string | {} | undefined;
672
+ title?: string | undefined;
673
+ config?: Record<string, unknown> | undefined;
674
+ actions?: any[] | undefined;
675
+ } & {
676
+ [k: string]: unknown;
677
+ };
678
+ displayName?: string | undefined;
679
+ isDisplayComp?: boolean | undefined;
680
+ category?: string | undefined;
681
+ keywords?: string[] | undefined;
682
+ }>;
683
+ type Component = z.infer<typeof ComponentSchema>;
618
684
  declare const ToolSchema: z.ZodObject<{
619
685
  id: z.ZodString;
620
686
  name: z.ZodString;
@@ -640,6 +706,29 @@ type CollectionHandler<TParams = any, TResult = any> = (params: TParams) => Prom
640
706
  type LLMProvider = 'anthropic' | 'groq' | 'gemini' | 'openai';
641
707
 
642
708
  type DatabaseType = 'postgresql' | 'mssql' | 'snowflake' | 'mysql';
709
+ /**
710
+ * Model strategy for controlling which models are used for different tasks
711
+ * - 'best': Use the best model (e.g., Sonnet) for all tasks - highest quality, higher cost
712
+ * - 'fast': Use the fast model (e.g., Haiku) for all tasks - lower quality, lower cost
713
+ * - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
714
+ */
715
+ type ModelStrategy = 'best' | 'fast' | 'balanced';
716
+ /**
717
+ * Model configuration for DASH_COMP flow (dashboard component picking)
718
+ * Allows separate control of models used for component selection
719
+ */
720
+ interface DashCompModelConfig {
721
+ /**
722
+ * Primary model for DASH_COMP requests
723
+ * Format: "provider/model-name" (e.g., "anthropic/claude-sonnet-4-5-20250929")
724
+ */
725
+ model?: string;
726
+ /**
727
+ * Fast model for simpler DASH_COMP tasks (optional)
728
+ * Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
729
+ */
730
+ fastModel?: string;
731
+ }
643
732
  interface SuperatomSDKConfig {
644
733
  url?: string;
645
734
  apiKey?: string;
@@ -655,6 +744,18 @@ interface SuperatomSDKConfig {
655
744
  OPENAI_API_KEY?: string;
656
745
  LLM_PROVIDERS?: LLMProvider[];
657
746
  logLevel?: LogLevel;
747
+ /**
748
+ * Model selection strategy for LLM API calls:
749
+ * - 'best': Use best model for all tasks (highest quality, higher cost)
750
+ * - 'fast': Use fast model for all tasks (lower quality, lower cost)
751
+ * - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
752
+ */
753
+ modelStrategy?: ModelStrategy;
754
+ /**
755
+ * Separate model configuration for DASH_COMP flow (dashboard component picking)
756
+ * If not provided, falls back to provider-based model selection
757
+ */
758
+ dashCompModels?: DashCompModelConfig;
658
759
  }
659
760
 
660
761
  declare const KbNodesQueryFiltersSchema: z.ZodObject<{
@@ -785,6 +886,11 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
785
886
  } | undefined;
786
887
  }>;
787
888
  type KbNodesRequestPayload = z.infer<typeof KbNodesRequestPayloadSchema>;
889
+ interface T_RESPONSE {
890
+ success: boolean;
891
+ data?: any;
892
+ errors: string[];
893
+ }
788
894
 
789
895
  /**
790
896
  * UserManager class to handle CRUD operations on users with file persistence
@@ -1790,6 +1896,216 @@ declare function rerankConversationResults<T extends {
1790
1896
  bm25Score: number;
1791
1897
  }>;
1792
1898
 
1899
+ /**
1900
+ * Task types for model selection
1901
+ * - 'complex': Text generation, component matching, parameter adaptation (uses best model in balanced mode)
1902
+ * - 'simple': Classification, action generation (uses fast model in balanced mode)
1903
+ */
1904
+ type TaskType = 'complex' | 'simple';
1905
+ interface BaseLLMConfig {
1906
+ model?: string;
1907
+ fastModel?: string;
1908
+ defaultLimit?: number;
1909
+ apiKey?: string;
1910
+ /**
1911
+ * Model selection strategy:
1912
+ * - 'best': Use best model for all tasks (highest quality, higher cost)
1913
+ * - 'fast': Use fast model for all tasks (lower quality, lower cost)
1914
+ * - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
1915
+ */
1916
+ modelStrategy?: ModelStrategy;
1917
+ }
1918
+ /**
1919
+ * BaseLLM abstract class for AI-powered component generation and matching
1920
+ * Provides common functionality for all LLM providers
1921
+ */
1922
+ declare abstract class BaseLLM {
1923
+ protected model: string;
1924
+ protected fastModel: string;
1925
+ protected defaultLimit: number;
1926
+ protected apiKey?: string;
1927
+ protected modelStrategy: ModelStrategy;
1928
+ constructor(config?: BaseLLMConfig);
1929
+ /**
1930
+ * Get the appropriate model based on task type and model strategy
1931
+ * @param taskType - 'complex' for text generation/matching, 'simple' for classification/actions
1932
+ * @returns The model string to use for this task
1933
+ */
1934
+ protected getModelForTask(taskType: TaskType): string;
1935
+ /**
1936
+ * Set the model strategy at runtime
1937
+ * @param strategy - 'best', 'fast', or 'balanced'
1938
+ */
1939
+ setModelStrategy(strategy: ModelStrategy): void;
1940
+ /**
1941
+ * Get the current model strategy
1942
+ * @returns The current model strategy
1943
+ */
1944
+ getModelStrategy(): ModelStrategy;
1945
+ /**
1946
+ * Get the default model for this provider (used for complex tasks like text generation)
1947
+ */
1948
+ protected abstract getDefaultModel(): string;
1949
+ /**
1950
+ * Get the default fast model for this provider (used for simple tasks: classification, matching, actions)
1951
+ * Should return a cheaper/faster model like Haiku for Anthropic
1952
+ */
1953
+ protected abstract getDefaultFastModel(): string;
1954
+ /**
1955
+ * Get the default API key from environment
1956
+ */
1957
+ protected abstract getDefaultApiKey(): string | undefined;
1958
+ /**
1959
+ * Get the provider name (for logging)
1960
+ */
1961
+ protected abstract getProviderName(): string;
1962
+ /**
1963
+ * Get the API key (from instance, parameter, or environment)
1964
+ */
1965
+ protected getApiKey(apiKey?: string): string | undefined;
1966
+ /**
1967
+ * Check if a component contains a Form (data_modification component)
1968
+ * Forms have hardcoded defaultValues that become stale when cached
1969
+ * This checks both single Form components and Forms inside MultiComponentContainer
1970
+ */
1971
+ protected containsFormComponent(component: any): boolean;
1972
+ /**
1973
+ * Match components from text response suggestions and generate follow-up questions
1974
+ * Takes a text response with component suggestions (c1:type format) and matches with available components
1975
+ * Also generates title, description, and intelligent follow-up questions (actions) based on the analysis
1976
+ * All components are placed in a default MultiComponentContainer layout
1977
+ * @param analysisContent - The text response containing component suggestions
1978
+ * @param components - List of available components
1979
+ * @param apiKey - Optional API key
1980
+ * @param logCollector - Optional log collector
1981
+ * @param componentStreamCallback - Optional callback to stream primary KPI component as soon as it's identified
1982
+ * @returns Object containing matched components, layout title/description, and follow-up actions
1983
+ */
1984
+ matchComponentsFromAnalysis(analysisContent: string, components: Component[], apiKey?: string, logCollector?: any, componentStreamCallback?: (component: Component) => void, deferredTools?: any[], executedTools?: any[]): Promise<{
1985
+ components: Component[];
1986
+ layoutTitle: string;
1987
+ layoutDescription: string;
1988
+ actions: Action[];
1989
+ }>;
1990
+ /**
1991
+ * Classify user question into category and detect external tools needed
1992
+ * Determines if question is for data analysis, requires external tools, or needs text response
1993
+ */
1994
+ classifyQuestionCategory(userPrompt: string, apiKey?: string, logCollector?: any, conversationHistory?: string, externalTools?: any[]): Promise<{
1995
+ category: 'data_analysis' | 'data_modification' | 'general';
1996
+ externalTools: Array<{
1997
+ type: string;
1998
+ name: string;
1999
+ description: string;
2000
+ parameters: Record<string, any>;
2001
+ }>;
2002
+ dataAnalysisType?: 'visualization' | 'calculation' | 'comparison' | 'trend';
2003
+ reasoning: string;
2004
+ confidence: number;
2005
+ }>;
2006
+ /**
2007
+ * Adapt UI block parameters based on current user question
2008
+ * Takes a matched UI block from semantic search and modifies its props to answer the new question
2009
+ */
2010
+ adaptUIBlockParameters(currentUserPrompt: string, originalUserPrompt: string, matchedUIBlock: any, apiKey?: string, logCollector?: any): Promise<{
2011
+ success: boolean;
2012
+ adaptedComponent?: Component;
2013
+ parametersChanged?: Array<{
2014
+ field: string;
2015
+ reason: string;
2016
+ }>;
2017
+ explanation: string;
2018
+ }>;
2019
+ /**
2020
+ * Generate text-based response for user question
2021
+ * This provides conversational text responses instead of component generation
2022
+ * Supports tool calling for query execution with automatic retry on errors (max 3 attempts)
2023
+ * After generating text response, if components are provided, matches suggested components
2024
+ * @param streamCallback - Optional callback function to receive text chunks as they stream
2025
+ * @param collections - Collection registry for executing database queries via database.execute
2026
+ * @param components - Optional list of available components for matching suggestions
2027
+ * @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called
2028
+ * @param category - Question category ('data_analysis' | 'data_modification' | 'general'). For data_modification, answer component streaming is skipped. For general, component generation is skipped entirely.
2029
+ */
2030
+ generateTextResponse(userPrompt: string, apiKey?: string, logCollector?: any, conversationHistory?: string, streamCallback?: (chunk: string) => void, collections?: any, components?: Component[], externalTools?: any[], category?: 'data_analysis' | 'data_modification' | 'general'): Promise<T_RESPONSE>;
2031
+ /**
2032
+ * Main orchestration function with semantic search and multi-step classification
2033
+ * NEW FLOW (Recommended):
2034
+ * 1. Semantic search: Check previous conversations (>60% match)
2035
+ * - If match found → Adapt UI block parameters and return
2036
+ * 2. Category classification: Determine if data_analysis, requires_external_tools, or text_response
2037
+ * 3. Route appropriately based on category and response mode
2038
+ *
2039
+ * @param responseMode - 'component' for component generation (default), 'text' for text responses
2040
+ * @param streamCallback - Optional callback function to receive text chunks as they stream (only for text mode)
2041
+ * @param collections - Collection registry for executing database queries (required for text mode)
2042
+ * @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called (only for text mode)
2043
+ */
2044
+ handleUserRequest(userPrompt: string, components: Component[], apiKey?: string, logCollector?: any, conversationHistory?: string, responseMode?: 'component' | 'text', streamCallback?: (chunk: string) => void, collections?: any, externalTools?: any[], userId?: string): Promise<T_RESPONSE>;
2045
+ /**
2046
+ * Generate next questions that the user might ask based on the original prompt and generated component
2047
+ * This helps provide intelligent suggestions for follow-up queries
2048
+ * For general/conversational questions without components, pass textResponse instead
2049
+ */
2050
+ generateNextQuestions(originalUserPrompt: string, component?: Component | null, componentData?: Record<string, unknown>, apiKey?: string, logCollector?: any, conversationHistory?: string, textResponse?: string): Promise<string[]>;
2051
+ }
2052
+
2053
+ interface AnthropicLLMConfig extends BaseLLMConfig {
2054
+ }
2055
+ /**
2056
+ * AnthropicLLM class for handling AI-powered component generation and matching using Anthropic Claude
2057
+ */
2058
+ declare class AnthropicLLM extends BaseLLM {
2059
+ constructor(config?: AnthropicLLMConfig);
2060
+ protected getDefaultModel(): string;
2061
+ protected getDefaultFastModel(): string;
2062
+ protected getDefaultApiKey(): string | undefined;
2063
+ protected getProviderName(): string;
2064
+ }
2065
+ declare const anthropicLLM: AnthropicLLM;
2066
+
2067
+ interface GroqLLMConfig extends BaseLLMConfig {
2068
+ }
2069
+ /**
2070
+ * GroqLLM class for handling AI-powered component generation and matching using Groq
2071
+ */
2072
+ declare class GroqLLM extends BaseLLM {
2073
+ constructor(config?: GroqLLMConfig);
2074
+ protected getDefaultModel(): string;
2075
+ protected getDefaultFastModel(): string;
2076
+ protected getDefaultApiKey(): string | undefined;
2077
+ protected getProviderName(): string;
2078
+ }
2079
+ declare const groqLLM: GroqLLM;
2080
+
2081
+ interface GeminiLLMConfig extends BaseLLMConfig {
2082
+ }
2083
+ /**
2084
+ * GeminiLLM class for handling AI-powered component generation and matching using Google Gemini
2085
+ */
2086
+ declare class GeminiLLM extends BaseLLM {
2087
+ constructor(config?: GeminiLLMConfig);
2088
+ protected getDefaultModel(): string;
2089
+ protected getDefaultFastModel(): string;
2090
+ protected getDefaultApiKey(): string | undefined;
2091
+ protected getProviderName(): string;
2092
+ }
2093
+ declare const geminiLLM: GeminiLLM;
2094
+
2095
+ interface OpenAILLMConfig extends BaseLLMConfig {
2096
+ }
2097
+ /**
2098
+ * OpenAILLM class for handling AI-powered component generation and matching using OpenAI GPT models
2099
+ */
2100
+ declare class OpenAILLM extends BaseLLM {
2101
+ constructor(config?: OpenAILLMConfig);
2102
+ protected getDefaultModel(): string;
2103
+ protected getDefaultFastModel(): string;
2104
+ protected getDefaultApiKey(): string | undefined;
2105
+ protected getProviderName(): string;
2106
+ }
2107
+ declare const openaiLLM: OpenAILLM;
2108
+
1793
2109
  declare const SDK_VERSION = "0.0.8";
1794
2110
  type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
1795
2111
  declare class SuperatomSDK {
@@ -1814,6 +2130,7 @@ declare class SuperatomSDK {
1814
2130
  private openaiApiKey;
1815
2131
  private llmProviders;
1816
2132
  private databaseType;
2133
+ private modelStrategy;
1817
2134
  private userManager;
1818
2135
  private dashboardManager;
1819
2136
  private reportManager;
@@ -1910,6 +2227,20 @@ declare class SuperatomSDK {
1910
2227
  * Get the stored tools
1911
2228
  */
1912
2229
  getTools(): Tool$1[];
2230
+ /**
2231
+ * Apply model strategy to all LLM provider singletons
2232
+ * @param strategy - 'best', 'fast', or 'balanced'
2233
+ */
2234
+ private applyModelStrategy;
2235
+ /**
2236
+ * Set model strategy at runtime
2237
+ * @param strategy - 'best', 'fast', or 'balanced'
2238
+ */
2239
+ setModelStrategy(strategy: ModelStrategy): void;
2240
+ /**
2241
+ * Get current model strategy
2242
+ */
2243
+ getModelStrategy(): ModelStrategy;
1913
2244
  }
1914
2245
 
1915
- export { type Action, BM25L, type BM25LOptions, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, type Message, type RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, llmUsageLogger, logger, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };
2246
+ export { type Action, BM25L, type BM25LOptions, type BaseLLMConfig, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, type Message, type ModelStrategy, type RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, anthropicLLM, geminiLLM, groqLLM, hybridRerank, llmUsageLogger, logger, openaiLLM, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };