@superatomai/sdk-node 0.0.70 → 0.0.72
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.mts +89 -42
- package/dist/index.d.ts +89 -42
- package/dist/index.js +1391 -826
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1391 -826
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2025,6 +2025,94 @@ declare function rerankConversationResults<T extends {
|
|
|
2025
2025
|
bm25Score: number;
|
|
2026
2026
|
}>;
|
|
2027
2027
|
|
|
2028
|
+
/**
|
|
2029
|
+
* QueryExecutionService - Handles all query execution, validation, and retry logic
|
|
2030
|
+
* Extracted from BaseLLM for better separation of concerns
|
|
2031
|
+
*/
|
|
2032
|
+
|
|
2033
|
+
/**
|
|
2034
|
+
* Context for component when requesting query fix
|
|
2035
|
+
*/
|
|
2036
|
+
interface ComponentContext {
|
|
2037
|
+
name: string;
|
|
2038
|
+
type: string;
|
|
2039
|
+
title?: string;
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Result of query validation
|
|
2043
|
+
*/
|
|
2044
|
+
interface QueryValidationResult {
|
|
2045
|
+
component: Component | null;
|
|
2046
|
+
queryKey: string;
|
|
2047
|
+
result: any;
|
|
2048
|
+
validated: boolean;
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Result of batch query validation
|
|
2052
|
+
*/
|
|
2053
|
+
interface BatchValidationResult {
|
|
2054
|
+
components: Component[];
|
|
2055
|
+
queryResults: Map<string, any>;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Configuration for QueryExecutionService
|
|
2059
|
+
*/
|
|
2060
|
+
interface QueryExecutionServiceConfig {
|
|
2061
|
+
defaultLimit: number;
|
|
2062
|
+
getModelForTask: (taskType: 'simple' | 'complex') => string;
|
|
2063
|
+
getApiKey: (apiKey?: string) => string | undefined;
|
|
2064
|
+
providerName: string;
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* QueryExecutionService handles all query-related operations
|
|
2068
|
+
*/
|
|
2069
|
+
declare class QueryExecutionService {
|
|
2070
|
+
private config;
|
|
2071
|
+
constructor(config: QueryExecutionServiceConfig);
|
|
2072
|
+
/**
|
|
2073
|
+
* Get the cache key for a query
|
|
2074
|
+
* This ensures the cache key matches what the frontend will send
|
|
2075
|
+
*/
|
|
2076
|
+
getQueryCacheKey(query: any): string;
|
|
2077
|
+
/**
|
|
2078
|
+
* Execute a query against the database
|
|
2079
|
+
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2080
|
+
* @param collections - Collections object containing database execute function
|
|
2081
|
+
* @returns Object with result data and cache key
|
|
2082
|
+
*/
|
|
2083
|
+
executeQuery(query: any, collections: any): Promise<{
|
|
2084
|
+
result: any;
|
|
2085
|
+
cacheKey: string;
|
|
2086
|
+
}>;
|
|
2087
|
+
/**
|
|
2088
|
+
* Request the LLM to fix a failed SQL query
|
|
2089
|
+
* @param failedQuery - The query that failed execution
|
|
2090
|
+
* @param errorMessage - The error message from the failed execution
|
|
2091
|
+
* @param componentContext - Context about the component
|
|
2092
|
+
* @param apiKey - Optional API key
|
|
2093
|
+
* @returns Fixed query string
|
|
2094
|
+
*/
|
|
2095
|
+
requestQueryFix(failedQuery: string, errorMessage: string, componentContext: ComponentContext, apiKey?: string): Promise<string>;
|
|
2096
|
+
/**
|
|
2097
|
+
* Validate a single component's query with retry logic
|
|
2098
|
+
* @param component - The component to validate
|
|
2099
|
+
* @param collections - Collections object containing database execute function
|
|
2100
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2101
|
+
* @param logCollector - Optional log collector for logging
|
|
2102
|
+
* @returns Validation result with component, query key, and result
|
|
2103
|
+
*/
|
|
2104
|
+
validateSingleQuery(component: Component, collections: any, apiKey?: string, logCollector?: any): Promise<QueryValidationResult>;
|
|
2105
|
+
/**
|
|
2106
|
+
* Validate multiple component queries in parallel
|
|
2107
|
+
* @param components - Array of components with potential queries
|
|
2108
|
+
* @param collections - Collections object containing database execute function
|
|
2109
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2110
|
+
* @param logCollector - Optional log collector for logging
|
|
2111
|
+
* @returns Object with validated components and query results map
|
|
2112
|
+
*/
|
|
2113
|
+
validateComponentQueries(components: Component[], collections: any, apiKey?: string, logCollector?: any): Promise<BatchValidationResult>;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2028
2116
|
/**
|
|
2029
2117
|
* Task types for model selection
|
|
2030
2118
|
* - 'complex': Text generation, component matching, parameter adaptation (uses best model in balanced mode)
|
|
@@ -2056,6 +2144,7 @@ declare abstract class BaseLLM {
|
|
|
2056
2144
|
protected apiKey?: string;
|
|
2057
2145
|
protected modelStrategy: ModelStrategy;
|
|
2058
2146
|
protected conversationSimilarityThreshold: number;
|
|
2147
|
+
protected queryService: QueryExecutionService;
|
|
2059
2148
|
constructor(config?: BaseLLMConfig);
|
|
2060
2149
|
/**
|
|
2061
2150
|
* Get the appropriate model based on task type and model strategy
|
|
@@ -2110,29 +2199,6 @@ declare abstract class BaseLLM {
|
|
|
2110
2199
|
* This checks both single Form components and Forms inside MultiComponentContainer
|
|
2111
2200
|
*/
|
|
2112
2201
|
protected containsFormComponent(component: any): boolean;
|
|
2113
|
-
/**
|
|
2114
|
-
* Get the cache key for a query (the exact sql param that would be sent to execute)
|
|
2115
|
-
* This ensures the cache key matches what the frontend will send
|
|
2116
|
-
* Used for both caching and internal deduplication
|
|
2117
|
-
*/
|
|
2118
|
-
private getQueryCacheKey;
|
|
2119
|
-
/**
|
|
2120
|
-
* Execute a query against the database for validation and caching
|
|
2121
|
-
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2122
|
-
* @param collections - Collections object containing database execute function
|
|
2123
|
-
* @returns Object with result data and cache key
|
|
2124
|
-
* @throws Error if query execution fails
|
|
2125
|
-
*/
|
|
2126
|
-
private executeQueryForValidation;
|
|
2127
|
-
/**
|
|
2128
|
-
* Request the LLM to fix a failed SQL query
|
|
2129
|
-
* @param failedQuery - The query that failed execution
|
|
2130
|
-
* @param errorMessage - The error message from the failed execution
|
|
2131
|
-
* @param componentContext - Context about the component (name, type, title)
|
|
2132
|
-
* @param apiKey - Optional API key
|
|
2133
|
-
* @returns Fixed query string
|
|
2134
|
-
*/
|
|
2135
|
-
private requestQueryFix;
|
|
2136
2202
|
/**
|
|
2137
2203
|
* Match components from text response suggestions and generate follow-up questions
|
|
2138
2204
|
* Takes a text response with component suggestions (c1:type format) and matches with available components
|
|
@@ -2151,25 +2217,6 @@ declare abstract class BaseLLM {
|
|
|
2151
2217
|
layoutDescription: string;
|
|
2152
2218
|
actions: Action[];
|
|
2153
2219
|
}>;
|
|
2154
|
-
/**
|
|
2155
|
-
* Validate a single component's query with retry logic
|
|
2156
|
-
* @param component - The component to validate
|
|
2157
|
-
* @param collections - Collections object containing database execute function
|
|
2158
|
-
* @param apiKey - Optional API key for LLM calls
|
|
2159
|
-
* @param logCollector - Optional log collector for logging
|
|
2160
|
-
* @returns Object with validated component (or null if failed) and query result
|
|
2161
|
-
*/
|
|
2162
|
-
private validateSingleComponentQuery;
|
|
2163
|
-
/**
|
|
2164
|
-
* Validate component queries against the database and retry with LLM fixes if they fail
|
|
2165
|
-
* Uses parallel execution for faster validation
|
|
2166
|
-
* @param components - Array of components with potential queries
|
|
2167
|
-
* @param collections - Collections object containing database execute function
|
|
2168
|
-
* @param apiKey - Optional API key for LLM calls
|
|
2169
|
-
* @param logCollector - Optional log collector for logging
|
|
2170
|
-
* @returns Object with validated components and a map of query results
|
|
2171
|
-
*/
|
|
2172
|
-
private validateAndRetryComponentQueries;
|
|
2173
2220
|
/**
|
|
2174
2221
|
* Classify user question into category and detect external tools needed
|
|
2175
2222
|
* Determines if question is for data analysis, requires external tools, or needs text response
|
package/dist/index.d.ts
CHANGED
|
@@ -2025,6 +2025,94 @@ declare function rerankConversationResults<T extends {
|
|
|
2025
2025
|
bm25Score: number;
|
|
2026
2026
|
}>;
|
|
2027
2027
|
|
|
2028
|
+
/**
|
|
2029
|
+
* QueryExecutionService - Handles all query execution, validation, and retry logic
|
|
2030
|
+
* Extracted from BaseLLM for better separation of concerns
|
|
2031
|
+
*/
|
|
2032
|
+
|
|
2033
|
+
/**
|
|
2034
|
+
* Context for component when requesting query fix
|
|
2035
|
+
*/
|
|
2036
|
+
interface ComponentContext {
|
|
2037
|
+
name: string;
|
|
2038
|
+
type: string;
|
|
2039
|
+
title?: string;
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Result of query validation
|
|
2043
|
+
*/
|
|
2044
|
+
interface QueryValidationResult {
|
|
2045
|
+
component: Component | null;
|
|
2046
|
+
queryKey: string;
|
|
2047
|
+
result: any;
|
|
2048
|
+
validated: boolean;
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Result of batch query validation
|
|
2052
|
+
*/
|
|
2053
|
+
interface BatchValidationResult {
|
|
2054
|
+
components: Component[];
|
|
2055
|
+
queryResults: Map<string, any>;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Configuration for QueryExecutionService
|
|
2059
|
+
*/
|
|
2060
|
+
interface QueryExecutionServiceConfig {
|
|
2061
|
+
defaultLimit: number;
|
|
2062
|
+
getModelForTask: (taskType: 'simple' | 'complex') => string;
|
|
2063
|
+
getApiKey: (apiKey?: string) => string | undefined;
|
|
2064
|
+
providerName: string;
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* QueryExecutionService handles all query-related operations
|
|
2068
|
+
*/
|
|
2069
|
+
declare class QueryExecutionService {
|
|
2070
|
+
private config;
|
|
2071
|
+
constructor(config: QueryExecutionServiceConfig);
|
|
2072
|
+
/**
|
|
2073
|
+
* Get the cache key for a query
|
|
2074
|
+
* This ensures the cache key matches what the frontend will send
|
|
2075
|
+
*/
|
|
2076
|
+
getQueryCacheKey(query: any): string;
|
|
2077
|
+
/**
|
|
2078
|
+
* Execute a query against the database
|
|
2079
|
+
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2080
|
+
* @param collections - Collections object containing database execute function
|
|
2081
|
+
* @returns Object with result data and cache key
|
|
2082
|
+
*/
|
|
2083
|
+
executeQuery(query: any, collections: any): Promise<{
|
|
2084
|
+
result: any;
|
|
2085
|
+
cacheKey: string;
|
|
2086
|
+
}>;
|
|
2087
|
+
/**
|
|
2088
|
+
* Request the LLM to fix a failed SQL query
|
|
2089
|
+
* @param failedQuery - The query that failed execution
|
|
2090
|
+
* @param errorMessage - The error message from the failed execution
|
|
2091
|
+
* @param componentContext - Context about the component
|
|
2092
|
+
* @param apiKey - Optional API key
|
|
2093
|
+
* @returns Fixed query string
|
|
2094
|
+
*/
|
|
2095
|
+
requestQueryFix(failedQuery: string, errorMessage: string, componentContext: ComponentContext, apiKey?: string): Promise<string>;
|
|
2096
|
+
/**
|
|
2097
|
+
* Validate a single component's query with retry logic
|
|
2098
|
+
* @param component - The component to validate
|
|
2099
|
+
* @param collections - Collections object containing database execute function
|
|
2100
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2101
|
+
* @param logCollector - Optional log collector for logging
|
|
2102
|
+
* @returns Validation result with component, query key, and result
|
|
2103
|
+
*/
|
|
2104
|
+
validateSingleQuery(component: Component, collections: any, apiKey?: string, logCollector?: any): Promise<QueryValidationResult>;
|
|
2105
|
+
/**
|
|
2106
|
+
* Validate multiple component queries in parallel
|
|
2107
|
+
* @param components - Array of components with potential queries
|
|
2108
|
+
* @param collections - Collections object containing database execute function
|
|
2109
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2110
|
+
* @param logCollector - Optional log collector for logging
|
|
2111
|
+
* @returns Object with validated components and query results map
|
|
2112
|
+
*/
|
|
2113
|
+
validateComponentQueries(components: Component[], collections: any, apiKey?: string, logCollector?: any): Promise<BatchValidationResult>;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2028
2116
|
/**
|
|
2029
2117
|
* Task types for model selection
|
|
2030
2118
|
* - 'complex': Text generation, component matching, parameter adaptation (uses best model in balanced mode)
|
|
@@ -2056,6 +2144,7 @@ declare abstract class BaseLLM {
|
|
|
2056
2144
|
protected apiKey?: string;
|
|
2057
2145
|
protected modelStrategy: ModelStrategy;
|
|
2058
2146
|
protected conversationSimilarityThreshold: number;
|
|
2147
|
+
protected queryService: QueryExecutionService;
|
|
2059
2148
|
constructor(config?: BaseLLMConfig);
|
|
2060
2149
|
/**
|
|
2061
2150
|
* Get the appropriate model based on task type and model strategy
|
|
@@ -2110,29 +2199,6 @@ declare abstract class BaseLLM {
|
|
|
2110
2199
|
* This checks both single Form components and Forms inside MultiComponentContainer
|
|
2111
2200
|
*/
|
|
2112
2201
|
protected containsFormComponent(component: any): boolean;
|
|
2113
|
-
/**
|
|
2114
|
-
* Get the cache key for a query (the exact sql param that would be sent to execute)
|
|
2115
|
-
* This ensures the cache key matches what the frontend will send
|
|
2116
|
-
* Used for both caching and internal deduplication
|
|
2117
|
-
*/
|
|
2118
|
-
private getQueryCacheKey;
|
|
2119
|
-
/**
|
|
2120
|
-
* Execute a query against the database for validation and caching
|
|
2121
|
-
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2122
|
-
* @param collections - Collections object containing database execute function
|
|
2123
|
-
* @returns Object with result data and cache key
|
|
2124
|
-
* @throws Error if query execution fails
|
|
2125
|
-
*/
|
|
2126
|
-
private executeQueryForValidation;
|
|
2127
|
-
/**
|
|
2128
|
-
* Request the LLM to fix a failed SQL query
|
|
2129
|
-
* @param failedQuery - The query that failed execution
|
|
2130
|
-
* @param errorMessage - The error message from the failed execution
|
|
2131
|
-
* @param componentContext - Context about the component (name, type, title)
|
|
2132
|
-
* @param apiKey - Optional API key
|
|
2133
|
-
* @returns Fixed query string
|
|
2134
|
-
*/
|
|
2135
|
-
private requestQueryFix;
|
|
2136
2202
|
/**
|
|
2137
2203
|
* Match components from text response suggestions and generate follow-up questions
|
|
2138
2204
|
* Takes a text response with component suggestions (c1:type format) and matches with available components
|
|
@@ -2151,25 +2217,6 @@ declare abstract class BaseLLM {
|
|
|
2151
2217
|
layoutDescription: string;
|
|
2152
2218
|
actions: Action[];
|
|
2153
2219
|
}>;
|
|
2154
|
-
/**
|
|
2155
|
-
* Validate a single component's query with retry logic
|
|
2156
|
-
* @param component - The component to validate
|
|
2157
|
-
* @param collections - Collections object containing database execute function
|
|
2158
|
-
* @param apiKey - Optional API key for LLM calls
|
|
2159
|
-
* @param logCollector - Optional log collector for logging
|
|
2160
|
-
* @returns Object with validated component (or null if failed) and query result
|
|
2161
|
-
*/
|
|
2162
|
-
private validateSingleComponentQuery;
|
|
2163
|
-
/**
|
|
2164
|
-
* Validate component queries against the database and retry with LLM fixes if they fail
|
|
2165
|
-
* Uses parallel execution for faster validation
|
|
2166
|
-
* @param components - Array of components with potential queries
|
|
2167
|
-
* @param collections - Collections object containing database execute function
|
|
2168
|
-
* @param apiKey - Optional API key for LLM calls
|
|
2169
|
-
* @param logCollector - Optional log collector for logging
|
|
2170
|
-
* @returns Object with validated components and a map of query results
|
|
2171
|
-
*/
|
|
2172
|
-
private validateAndRetryComponentQueries;
|
|
2173
2220
|
/**
|
|
2174
2221
|
* Classify user question into category and detect external tools needed
|
|
2175
2222
|
* Determines if question is for data analysis, requires external tools, or needs text response
|