nttp 1.4.9 → 1.4.10
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/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/errors.d.ts +99 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +173 -11
- package/dist/errors.js.map +1 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +73 -12
- package/dist/executor.js.map +1 -1
- package/dist/intent.d.ts.map +1 -1
- package/dist/intent.js +125 -17
- package/dist/intent.js.map +1 -1
- package/dist/llm.d.ts +25 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +25 -0
- package/dist/llm.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ const program = new Command();
|
|
|
11
11
|
program
|
|
12
12
|
.name('nttp')
|
|
13
13
|
.description('Query databases with natural language')
|
|
14
|
-
.version('1.4.
|
|
14
|
+
.version('1.4.10');
|
|
15
15
|
program
|
|
16
16
|
.command('setup')
|
|
17
17
|
.description('Interactive setup wizard (or use --non-interactive for agents)')
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,MAAM,CAAC;KACZ,WAAW,CAAC,uCAAuC,CAAC;KACpD,OAAO,CAAC,
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AC;KACvB,WAAW,CAAC,kCAAkC,CAAC;KAC/C,MAAM,CAAC,qBAAqB,EAAE,4BAA4B,EAAE,OAAO,CAAC;KACpE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,cAAc,CAAC;KACvB,WAAW,CAAC,mDAAmD,CAAC;KAChE,MAAM,CAAC,sBAAsB,EAAE,gCAAgC,CAAC;KAChE,MAAM,CAAC,OAAO,CAAC,CAAC;AAEnB,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,35 +1,128 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Custom error classes for NTTP application.
|
|
3
|
-
*
|
|
3
|
+
* Enhanced with Claude 4.x best practices: clear explanations and actionable suggestions.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Error thrown when intent parsing fails.
|
|
7
|
+
*
|
|
8
|
+
* This error occurs when the LLM cannot understand the natural language query
|
|
9
|
+
* or cannot map it to a valid database operation.
|
|
10
|
+
*
|
|
11
|
+
* Common causes:
|
|
12
|
+
* - Query references unknown tables or fields
|
|
13
|
+
* - Query is too ambiguous or vague
|
|
14
|
+
* - LLM API is unavailable or quota exceeded
|
|
15
|
+
*
|
|
16
|
+
* Suggested fixes:
|
|
17
|
+
* - Simplify your query (e.g., "show users" instead of complex phrasing)
|
|
18
|
+
* - Ensure table/field names match your database schema
|
|
19
|
+
* - Check LLM API key and quota
|
|
20
|
+
* - Try a more explicit query (e.g., "list all products" instead of "products")
|
|
7
21
|
*/
|
|
8
22
|
export declare class IntentParseError extends Error {
|
|
9
|
-
|
|
23
|
+
readonly suggestions: string[];
|
|
24
|
+
constructor(message: string, suggestions?: string[]);
|
|
25
|
+
private static formatMessage;
|
|
26
|
+
private static getDefaultSuggestions;
|
|
10
27
|
}
|
|
11
28
|
/**
|
|
12
29
|
* Error thrown when SQL generation fails.
|
|
30
|
+
*
|
|
31
|
+
* This error occurs when the LLM cannot generate valid SQL from the parsed intent,
|
|
32
|
+
* or when the generated SQL fails safety validation.
|
|
33
|
+
*
|
|
34
|
+
* Common causes:
|
|
35
|
+
* - Complex query requires table relationships not in schema
|
|
36
|
+
* - Generated SQL violates safety rules (e.g., attempted UPDATE/DELETE)
|
|
37
|
+
* - Schema description is incomplete or incorrect
|
|
38
|
+
* - LLM hallucinated invalid SQL syntax
|
|
39
|
+
*
|
|
40
|
+
* Suggested fixes:
|
|
41
|
+
* - Ensure your database schema is complete and accurate
|
|
42
|
+
* - Try a simpler query with fewer joins
|
|
43
|
+
* - Check that the LLM model supports structured outputs
|
|
44
|
+
* - Verify the intent was parsed correctly (use explain() method)
|
|
13
45
|
*/
|
|
14
46
|
export declare class SQLGenerationError extends Error {
|
|
15
|
-
|
|
47
|
+
readonly suggestions: string[];
|
|
48
|
+
constructor(message: string, suggestions?: string[]);
|
|
49
|
+
private static formatMessage;
|
|
50
|
+
private static getDefaultSuggestions;
|
|
16
51
|
}
|
|
17
52
|
/**
|
|
18
53
|
* Error thrown when SQL execution fails.
|
|
54
|
+
*
|
|
55
|
+
* This error occurs when the database rejects the generated SQL query.
|
|
56
|
+
*
|
|
57
|
+
* Common causes:
|
|
58
|
+
* - Database connection issues
|
|
59
|
+
* - Table or column doesn't exist (schema mismatch)
|
|
60
|
+
* - Type mismatch in WHERE clause (e.g., string vs integer)
|
|
61
|
+
* - Database permissions insufficient for SELECT
|
|
62
|
+
* - Syntax error in generated SQL
|
|
63
|
+
*
|
|
64
|
+
* Suggested fixes:
|
|
65
|
+
* - Verify database connection is active
|
|
66
|
+
* - Ensure schema matches actual database structure
|
|
67
|
+
* - Check database user has SELECT permissions
|
|
68
|
+
* - Examine the generated SQL for syntax errors
|
|
69
|
+
* - Try regenerating with forceNewSchema option
|
|
19
70
|
*/
|
|
20
71
|
export declare class SQLExecutionError extends Error {
|
|
21
|
-
|
|
72
|
+
readonly sql?: string;
|
|
73
|
+
readonly suggestions: string[];
|
|
74
|
+
constructor(message: string, sql?: string, suggestions?: string[]);
|
|
75
|
+
private static formatMessage;
|
|
76
|
+
private static getDefaultSuggestions;
|
|
22
77
|
}
|
|
23
78
|
/**
|
|
24
79
|
* Error thrown when LLM API calls fail.
|
|
80
|
+
*
|
|
81
|
+
* This error occurs when communication with the LLM provider fails.
|
|
82
|
+
*
|
|
83
|
+
* Common causes:
|
|
84
|
+
* - Invalid or expired API key
|
|
85
|
+
* - Rate limit or quota exceeded
|
|
86
|
+
* - Network connectivity issues
|
|
87
|
+
* - LLM provider service outage
|
|
88
|
+
* - Request timeout
|
|
89
|
+
*
|
|
90
|
+
* Suggested fixes:
|
|
91
|
+
* - Verify API key is correct and active
|
|
92
|
+
* - Check API quota and rate limits with provider
|
|
93
|
+
* - Ensure network connectivity to LLM provider
|
|
94
|
+
* - Wait and retry (automatic retry with backoff is already applied)
|
|
95
|
+
* - Check LLM provider status page for outages
|
|
25
96
|
*/
|
|
26
97
|
export declare class LLMError extends Error {
|
|
27
|
-
|
|
98
|
+
readonly suggestions: string[];
|
|
99
|
+
constructor(message: string, suggestions?: string[]);
|
|
100
|
+
private static formatMessage;
|
|
101
|
+
private static getDefaultSuggestions;
|
|
28
102
|
}
|
|
29
103
|
/**
|
|
30
104
|
* Error thrown when cache operations fail.
|
|
105
|
+
*
|
|
106
|
+
* This error occurs when the caching system encounters an issue.
|
|
107
|
+
*
|
|
108
|
+
* Common causes:
|
|
109
|
+
* - Redis connection failed (if using Redis L1 cache)
|
|
110
|
+
* - Redis authentication error
|
|
111
|
+
* - Network issues with Redis server
|
|
112
|
+
* - Embedding API failure (if using L2 semantic cache)
|
|
113
|
+
* - Out of memory for in-memory caches
|
|
114
|
+
*
|
|
115
|
+
* Suggested fixes:
|
|
116
|
+
* - Verify Redis server is running (if using Redis)
|
|
117
|
+
* - Check REDIS_URL format: redis://host:port
|
|
118
|
+
* - Ensure Redis authentication credentials are correct
|
|
119
|
+
* - Check OpenAI API key for embeddings (if L2 enabled)
|
|
120
|
+
* - Reduce cache size limits if memory is constrained
|
|
31
121
|
*/
|
|
32
122
|
export declare class CacheError extends Error {
|
|
33
|
-
|
|
123
|
+
readonly suggestions: string[];
|
|
124
|
+
constructor(message: string, suggestions?: string[]);
|
|
125
|
+
private static formatMessage;
|
|
126
|
+
private static getDefaultSuggestions;
|
|
34
127
|
}
|
|
35
128
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IAQnD,OAAO,CAAC,MAAM,CAAC,aAAa;IAK5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAQrC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IAQnD,OAAO,CAAC,MAAM,CAAC,aAAa;IAK5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAQrC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,SAAgB,GAAG,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IASjE,OAAO,CAAC,MAAM,CAAC,aAAa;IAU5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CASrC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IAQnD,OAAO,CAAC,MAAM,CAAC,aAAa;IAK5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CASrC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IAQnD,OAAO,CAAC,MAAM,CAAC,aAAa;IAK5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CASrC"}
|
package/dist/errors.js
CHANGED
|
@@ -1,55 +1,217 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Custom error classes for NTTP application.
|
|
3
|
-
*
|
|
3
|
+
* Enhanced with Claude 4.x best practices: clear explanations and actionable suggestions.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Error thrown when intent parsing fails.
|
|
7
|
+
*
|
|
8
|
+
* This error occurs when the LLM cannot understand the natural language query
|
|
9
|
+
* or cannot map it to a valid database operation.
|
|
10
|
+
*
|
|
11
|
+
* Common causes:
|
|
12
|
+
* - Query references unknown tables or fields
|
|
13
|
+
* - Query is too ambiguous or vague
|
|
14
|
+
* - LLM API is unavailable or quota exceeded
|
|
15
|
+
*
|
|
16
|
+
* Suggested fixes:
|
|
17
|
+
* - Simplify your query (e.g., "show users" instead of complex phrasing)
|
|
18
|
+
* - Ensure table/field names match your database schema
|
|
19
|
+
* - Check LLM API key and quota
|
|
20
|
+
* - Try a more explicit query (e.g., "list all products" instead of "products")
|
|
7
21
|
*/
|
|
8
22
|
export class IntentParseError extends Error {
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
suggestions;
|
|
24
|
+
constructor(message, suggestions) {
|
|
25
|
+
const enhancedMessage = IntentParseError.formatMessage(message, suggestions);
|
|
26
|
+
super(enhancedMessage);
|
|
11
27
|
this.name = 'IntentParseError';
|
|
28
|
+
this.suggestions = suggestions || IntentParseError.getDefaultSuggestions();
|
|
12
29
|
Object.setPrototypeOf(this, IntentParseError.prototype);
|
|
13
30
|
}
|
|
31
|
+
static formatMessage(message, suggestions) {
|
|
32
|
+
const suggestionList = suggestions || IntentParseError.getDefaultSuggestions();
|
|
33
|
+
return `${message}\n\nSuggested fixes:\n${suggestionList.map(s => ` • ${s}`).join('\n')}`;
|
|
34
|
+
}
|
|
35
|
+
static getDefaultSuggestions() {
|
|
36
|
+
return [
|
|
37
|
+
'Simplify your query (e.g., "show users" instead of complex phrasing)',
|
|
38
|
+
'Ensure table/field names match your database schema',
|
|
39
|
+
'Try a more explicit query (e.g., "list all products")',
|
|
40
|
+
'Check if LLM API key is valid and has quota available',
|
|
41
|
+
];
|
|
42
|
+
}
|
|
14
43
|
}
|
|
15
44
|
/**
|
|
16
45
|
* Error thrown when SQL generation fails.
|
|
46
|
+
*
|
|
47
|
+
* This error occurs when the LLM cannot generate valid SQL from the parsed intent,
|
|
48
|
+
* or when the generated SQL fails safety validation.
|
|
49
|
+
*
|
|
50
|
+
* Common causes:
|
|
51
|
+
* - Complex query requires table relationships not in schema
|
|
52
|
+
* - Generated SQL violates safety rules (e.g., attempted UPDATE/DELETE)
|
|
53
|
+
* - Schema description is incomplete or incorrect
|
|
54
|
+
* - LLM hallucinated invalid SQL syntax
|
|
55
|
+
*
|
|
56
|
+
* Suggested fixes:
|
|
57
|
+
* - Ensure your database schema is complete and accurate
|
|
58
|
+
* - Try a simpler query with fewer joins
|
|
59
|
+
* - Check that the LLM model supports structured outputs
|
|
60
|
+
* - Verify the intent was parsed correctly (use explain() method)
|
|
17
61
|
*/
|
|
18
62
|
export class SQLGenerationError extends Error {
|
|
19
|
-
|
|
20
|
-
|
|
63
|
+
suggestions;
|
|
64
|
+
constructor(message, suggestions) {
|
|
65
|
+
const enhancedMessage = SQLGenerationError.formatMessage(message, suggestions);
|
|
66
|
+
super(enhancedMessage);
|
|
21
67
|
this.name = 'SQLGenerationError';
|
|
68
|
+
this.suggestions = suggestions || SQLGenerationError.getDefaultSuggestions();
|
|
22
69
|
Object.setPrototypeOf(this, SQLGenerationError.prototype);
|
|
23
70
|
}
|
|
71
|
+
static formatMessage(message, suggestions) {
|
|
72
|
+
const suggestionList = suggestions || SQLGenerationError.getDefaultSuggestions();
|
|
73
|
+
return `${message}\n\nSuggested fixes:\n${suggestionList.map(s => ` • ${s}`).join('\n')}`;
|
|
74
|
+
}
|
|
75
|
+
static getDefaultSuggestions() {
|
|
76
|
+
return [
|
|
77
|
+
'Ensure your database schema is complete and accurate',
|
|
78
|
+
'Try a simpler query with fewer joins or filters',
|
|
79
|
+
'Verify the intent was parsed correctly (use explain() method)',
|
|
80
|
+
'Check that the LLM model supports your database dialect',
|
|
81
|
+
];
|
|
82
|
+
}
|
|
24
83
|
}
|
|
25
84
|
/**
|
|
26
85
|
* Error thrown when SQL execution fails.
|
|
86
|
+
*
|
|
87
|
+
* This error occurs when the database rejects the generated SQL query.
|
|
88
|
+
*
|
|
89
|
+
* Common causes:
|
|
90
|
+
* - Database connection issues
|
|
91
|
+
* - Table or column doesn't exist (schema mismatch)
|
|
92
|
+
* - Type mismatch in WHERE clause (e.g., string vs integer)
|
|
93
|
+
* - Database permissions insufficient for SELECT
|
|
94
|
+
* - Syntax error in generated SQL
|
|
95
|
+
*
|
|
96
|
+
* Suggested fixes:
|
|
97
|
+
* - Verify database connection is active
|
|
98
|
+
* - Ensure schema matches actual database structure
|
|
99
|
+
* - Check database user has SELECT permissions
|
|
100
|
+
* - Examine the generated SQL for syntax errors
|
|
101
|
+
* - Try regenerating with forceNewSchema option
|
|
27
102
|
*/
|
|
28
103
|
export class SQLExecutionError extends Error {
|
|
29
|
-
|
|
30
|
-
|
|
104
|
+
sql;
|
|
105
|
+
suggestions;
|
|
106
|
+
constructor(message, sql, suggestions) {
|
|
107
|
+
const enhancedMessage = SQLExecutionError.formatMessage(message, sql, suggestions);
|
|
108
|
+
super(enhancedMessage);
|
|
31
109
|
this.name = 'SQLExecutionError';
|
|
110
|
+
this.sql = sql;
|
|
111
|
+
this.suggestions = suggestions || SQLExecutionError.getDefaultSuggestions();
|
|
32
112
|
Object.setPrototypeOf(this, SQLExecutionError.prototype);
|
|
33
113
|
}
|
|
114
|
+
static formatMessage(message, sql, suggestions) {
|
|
115
|
+
let formatted = message;
|
|
116
|
+
if (sql) {
|
|
117
|
+
formatted += `\n\nGenerated SQL:\n${sql}`;
|
|
118
|
+
}
|
|
119
|
+
const suggestionList = suggestions || SQLExecutionError.getDefaultSuggestions();
|
|
120
|
+
formatted += `\n\nSuggested fixes:\n${suggestionList.map(s => ` • ${s}`).join('\n')}`;
|
|
121
|
+
return formatted;
|
|
122
|
+
}
|
|
123
|
+
static getDefaultSuggestions() {
|
|
124
|
+
return [
|
|
125
|
+
'Verify database connection is active (check DATABASE_URL)',
|
|
126
|
+
'Ensure schema matches actual database structure',
|
|
127
|
+
'Check database user has SELECT permissions on the table',
|
|
128
|
+
'Examine the generated SQL for syntax errors',
|
|
129
|
+
'Try regenerating with forceNewSchema: true option',
|
|
130
|
+
];
|
|
131
|
+
}
|
|
34
132
|
}
|
|
35
133
|
/**
|
|
36
134
|
* Error thrown when LLM API calls fail.
|
|
135
|
+
*
|
|
136
|
+
* This error occurs when communication with the LLM provider fails.
|
|
137
|
+
*
|
|
138
|
+
* Common causes:
|
|
139
|
+
* - Invalid or expired API key
|
|
140
|
+
* - Rate limit or quota exceeded
|
|
141
|
+
* - Network connectivity issues
|
|
142
|
+
* - LLM provider service outage
|
|
143
|
+
* - Request timeout
|
|
144
|
+
*
|
|
145
|
+
* Suggested fixes:
|
|
146
|
+
* - Verify API key is correct and active
|
|
147
|
+
* - Check API quota and rate limits with provider
|
|
148
|
+
* - Ensure network connectivity to LLM provider
|
|
149
|
+
* - Wait and retry (automatic retry with backoff is already applied)
|
|
150
|
+
* - Check LLM provider status page for outages
|
|
37
151
|
*/
|
|
38
152
|
export class LLMError extends Error {
|
|
39
|
-
|
|
40
|
-
|
|
153
|
+
suggestions;
|
|
154
|
+
constructor(message, suggestions) {
|
|
155
|
+
const enhancedMessage = LLMError.formatMessage(message, suggestions);
|
|
156
|
+
super(enhancedMessage);
|
|
41
157
|
this.name = 'LLMError';
|
|
158
|
+
this.suggestions = suggestions || LLMError.getDefaultSuggestions();
|
|
42
159
|
Object.setPrototypeOf(this, LLMError.prototype);
|
|
43
160
|
}
|
|
161
|
+
static formatMessage(message, suggestions) {
|
|
162
|
+
const suggestionList = suggestions || LLMError.getDefaultSuggestions();
|
|
163
|
+
return `${message}\n\nSuggested fixes:\n${suggestionList.map(s => ` • ${s}`).join('\n')}`;
|
|
164
|
+
}
|
|
165
|
+
static getDefaultSuggestions() {
|
|
166
|
+
return [
|
|
167
|
+
'Verify API key is correct (check ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.)',
|
|
168
|
+
'Check API quota and rate limits with your provider',
|
|
169
|
+
'Ensure network connectivity to the LLM provider',
|
|
170
|
+
'Wait a moment and retry (automatic backoff already applied)',
|
|
171
|
+
'Check provider status page for service outages',
|
|
172
|
+
];
|
|
173
|
+
}
|
|
44
174
|
}
|
|
45
175
|
/**
|
|
46
176
|
* Error thrown when cache operations fail.
|
|
177
|
+
*
|
|
178
|
+
* This error occurs when the caching system encounters an issue.
|
|
179
|
+
*
|
|
180
|
+
* Common causes:
|
|
181
|
+
* - Redis connection failed (if using Redis L1 cache)
|
|
182
|
+
* - Redis authentication error
|
|
183
|
+
* - Network issues with Redis server
|
|
184
|
+
* - Embedding API failure (if using L2 semantic cache)
|
|
185
|
+
* - Out of memory for in-memory caches
|
|
186
|
+
*
|
|
187
|
+
* Suggested fixes:
|
|
188
|
+
* - Verify Redis server is running (if using Redis)
|
|
189
|
+
* - Check REDIS_URL format: redis://host:port
|
|
190
|
+
* - Ensure Redis authentication credentials are correct
|
|
191
|
+
* - Check OpenAI API key for embeddings (if L2 enabled)
|
|
192
|
+
* - Reduce cache size limits if memory is constrained
|
|
47
193
|
*/
|
|
48
194
|
export class CacheError extends Error {
|
|
49
|
-
|
|
50
|
-
|
|
195
|
+
suggestions;
|
|
196
|
+
constructor(message, suggestions) {
|
|
197
|
+
const enhancedMessage = CacheError.formatMessage(message, suggestions);
|
|
198
|
+
super(enhancedMessage);
|
|
51
199
|
this.name = 'CacheError';
|
|
200
|
+
this.suggestions = suggestions || CacheError.getDefaultSuggestions();
|
|
52
201
|
Object.setPrototypeOf(this, CacheError.prototype);
|
|
53
202
|
}
|
|
203
|
+
static formatMessage(message, suggestions) {
|
|
204
|
+
const suggestionList = suggestions || CacheError.getDefaultSuggestions();
|
|
205
|
+
return `${message}\n\nSuggested fixes:\n${suggestionList.map(s => ` • ${s}`).join('\n')}`;
|
|
206
|
+
}
|
|
207
|
+
static getDefaultSuggestions() {
|
|
208
|
+
return [
|
|
209
|
+
'Verify Redis server is running (if using Redis)',
|
|
210
|
+
'Check REDIS_URL format: redis://host:port',
|
|
211
|
+
'Ensure Redis authentication credentials are correct',
|
|
212
|
+
'Verify OpenAI API key for embeddings (if L2 cache enabled)',
|
|
213
|
+
'Try disabling cache temporarily to isolate the issue',
|
|
214
|
+
];
|
|
215
|
+
}
|
|
54
216
|
}
|
|
55
217
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,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zB,EAAE,EAAE,IAAI,EACR,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,GAAE,UAAU,GAAG,eAAe,aAAA,EACtC,OAAO,CAAC,EAAE,aAAa,YAAA;IAGjC;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA4I9D;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAkEhE;;OAEG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC;IAwChD;;OAEG;YACW,UAAU;IAqBxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAuBzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAiB9B;;OAEG;IACH,OAAO,CAAC,cAAc;IAkBtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAOzB"}
|
package/dist/executor.js
CHANGED
|
@@ -26,33 +26,94 @@ const SQL_GENERATION_JSON_SCHEMA = {
|
|
|
26
26
|
additionalProperties: false,
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
-
* System prompt for SQL generation.
|
|
29
|
+
* System prompt for SQL generation with Claude 4.x best practices.
|
|
30
|
+
* Enhanced with context, safety reasoning, and model self-knowledge.
|
|
30
31
|
*/
|
|
31
|
-
const SQL_GENERATION_SYSTEM_PROMPT = `You are an expert SQL generator.
|
|
32
|
-
|
|
32
|
+
const SQL_GENERATION_SYSTEM_PROMPT = `You are an expert SQL generator specializing in safe, read-only database queries. Your role is critical for security: you translate user intents into SQL while preventing any data modification or security vulnerabilities.
|
|
33
|
+
|
|
34
|
+
WHY THIS MATTERS:
|
|
35
|
+
- User data protection: Generated queries must never modify, delete, or corrupt data
|
|
36
|
+
- Security: Parameterized queries prevent SQL injection attacks
|
|
37
|
+
- Performance: Proper limits prevent resource exhaustion
|
|
38
|
+
- Reliability: Type-safe queries ensure consistent results
|
|
33
39
|
|
|
34
40
|
{schema}
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
+
CORE REQUIREMENTS (all must be satisfied):
|
|
43
|
+
|
|
44
|
+
1. SAFETY - Generate ONLY read-only SELECT queries
|
|
45
|
+
WHY: Write operations could corrupt user data or violate security policies
|
|
46
|
+
- ✅ Allowed: SELECT, WITH (for CTEs)
|
|
47
|
+
- ❌ Forbidden: UPDATE, DELETE, DROP, ALTER, INSERT, CREATE, TRUNCATE
|
|
48
|
+
- Rationale: Even accidental data modification could cause irreversible damage
|
|
49
|
+
|
|
50
|
+
2. PARAMETERIZATION - Use ? placeholders for ALL dynamic values
|
|
51
|
+
WHY: Prevents SQL injection attacks that could expose or delete all data
|
|
52
|
+
- ✅ Correct: "WHERE status = ?" with params: ["active"]
|
|
53
|
+
- ❌ Dangerous: "WHERE status = 'active'" (vulnerable to injection)
|
|
54
|
+
- Rationale: Parameterized queries ensure values are safely escaped
|
|
55
|
+
|
|
56
|
+
3. LIMITS - Always include LIMIT clause (max 1000)
|
|
57
|
+
WHY: Prevents accidental full table scans that could crash the database
|
|
58
|
+
- Default: Use intent.limit if provided, otherwise 100
|
|
59
|
+
- Maximum: Never exceed 1000 rows
|
|
60
|
+
- Rationale: Large result sets consume excessive memory and network bandwidth
|
|
61
|
+
|
|
62
|
+
4. JOINS - Use explicit JOINs for table relationships
|
|
63
|
+
WHY: Explicit joins are more readable and prevent accidental cross joins
|
|
64
|
+
- Prefer: INNER JOIN, LEFT JOIN with ON conditions
|
|
65
|
+
- Avoid: Implicit joins via WHERE (e.g., FROM a, b WHERE a.id = b.id)
|
|
42
66
|
|
|
43
|
-
|
|
67
|
+
5. TYPE SAFETY - Match filter types to schema column types
|
|
68
|
+
WHY: Type mismatches cause query failures or unexpected results
|
|
69
|
+
- Integers: Use numeric literals, not strings
|
|
70
|
+
- Dates: Use proper date formats
|
|
71
|
+
- Booleans: Use TRUE/FALSE or 1/0 based on database
|
|
72
|
+
|
|
73
|
+
RESPONSE FORMAT:
|
|
74
|
+
Return valid JSON with exactly these fields:
|
|
44
75
|
{
|
|
45
76
|
"sql": "SELECT ... FROM ... WHERE ... LIMIT ?",
|
|
46
77
|
"params": [value1, value2, ...]
|
|
47
78
|
}
|
|
48
79
|
|
|
49
|
-
|
|
80
|
+
EXAMPLES WITH REASONING:
|
|
81
|
+
|
|
82
|
+
Example 1 - Simple list query:
|
|
50
83
|
Intent: {"entity": "users", "operation": "list", "filters": {"status": "active"}, "limit": 10}
|
|
84
|
+
Thought process:
|
|
85
|
+
- Entity is "users" → SELECT FROM users
|
|
86
|
+
- Filter on status → WHERE status = ? (parameterized)
|
|
87
|
+
- Limit specified → LIMIT ?
|
|
88
|
+
- Both values go in params array
|
|
51
89
|
Response: {"sql": "SELECT * FROM users WHERE status = ? LIMIT ?", "params": ["active", 10]}
|
|
52
90
|
|
|
91
|
+
Example 2 - Count with filter:
|
|
53
92
|
Intent: {"entity": "orders", "operation": "count", "filters": {"status": "pending"}}
|
|
93
|
+
Thought process:
|
|
94
|
+
- Count operation → SELECT COUNT(*) as count
|
|
95
|
+
- Filter on status → WHERE status = ? (parameterized)
|
|
96
|
+
- No limit specified, but COUNT returns single row (limit not needed)
|
|
54
97
|
Response: {"sql": "SELECT COUNT(*) as count FROM orders WHERE status = ?", "params": ["pending"]}
|
|
55
|
-
|
|
98
|
+
|
|
99
|
+
Example 3 - Join with sort:
|
|
100
|
+
Intent: {"entity": "orders", "operation": "list", "filters": {}, "limit": 20, "sort": "created_at:desc"}
|
|
101
|
+
Thought process:
|
|
102
|
+
- Entity is orders → SELECT FROM orders
|
|
103
|
+
- No filters → No WHERE clause
|
|
104
|
+
- Sort specified → ORDER BY created_at DESC
|
|
105
|
+
- Limit specified → LIMIT ?
|
|
106
|
+
Response: {"sql": "SELECT * FROM orders ORDER BY created_at DESC LIMIT ?", "params": [20]}
|
|
107
|
+
|
|
108
|
+
Example 4 - Specific fields:
|
|
109
|
+
Intent: {"entity": "users", "operation": "list", "filters": {}, "fields": ["id", "email", "name"], "limit": 50}
|
|
110
|
+
Thought process:
|
|
111
|
+
- Specific fields requested → SELECT id, email, name (not *)
|
|
112
|
+
- No filters → No WHERE clause
|
|
113
|
+
- Limit specified → LIMIT ?
|
|
114
|
+
Response: {"sql": "SELECT id, email, name FROM users LIMIT ?", "params": [50]}
|
|
115
|
+
|
|
116
|
+
Your expertise ensures users can query their data safely and efficiently.`;
|
|
56
117
|
/**
|
|
57
118
|
* Service for executing queries and managing SQL generation.
|
|
58
119
|
*/
|
package/dist/executor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAU5B,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,GACR,MAAM,aAAa,CAAC;AAOrB;;GAEG;AACH,MAAM,0BAA0B,GAAG;IACjC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,GAAG,EAAE;YACH,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,0BAA0B;SACxC;QACD,MAAM,EAAE;YACN,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;aACzD;YACD,WAAW,EAAE,8BAA8B;SAC5C;KACF;IACD,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;IAC3B,oBAAoB,EAAE,KAAK;CAC5B,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;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Root":"","sources":["../src/intent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAyB,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAyCpF;;GAEG;AACH,UAAU,SAAS;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CACvB;AA8ID;;GAEG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,UAAU;IAEnC;;;;;;;OAOG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4CtE;;;;;;;;OAQG;IACH,mBAAmB,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM;IAkDlD;;;;;;;;OAQG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAKzC"}
|
package/dist/intent.js
CHANGED
|
@@ -41,14 +41,28 @@ const INTENT_JSON_SCHEMA = {
|
|
|
41
41
|
additionalProperties: false,
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
|
-
* System prompt for intent parsing.
|
|
44
|
+
* System prompt for intent parsing with Claude 4.x best practices.
|
|
45
|
+
* Enhanced with context, reasoning guidance, and model self-knowledge.
|
|
45
46
|
*/
|
|
46
|
-
const INTENT_PARSE_SYSTEM_PROMPT = `You are an expert
|
|
47
|
-
|
|
47
|
+
const INTENT_PARSE_SYSTEM_PROMPT = `You are an expert natural language understanding system specializing in database query intent extraction. Your role is to bridge human communication and database operations by accurately interpreting user requests.
|
|
48
|
+
|
|
49
|
+
WHY THIS MATTERS:
|
|
50
|
+
- Accuracy: Incorrect intent parsing leads to wrong results or failed queries
|
|
51
|
+
- User trust: Users rely on you to understand their natural phrasing
|
|
52
|
+
- Efficiency: Proper normalization enables intelligent caching
|
|
53
|
+
- Data safety: Correct entity identification prevents accessing wrong tables
|
|
48
54
|
|
|
49
55
|
{schema}
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
YOUR TASK:
|
|
58
|
+
Parse natural language queries into structured intents that can be safely converted to SQL. You excel at:
|
|
59
|
+
- Understanding implicit information (e.g., "active users" implies status filter)
|
|
60
|
+
- Normalizing different phrasings to the same intent (e.g., "get users" = "show users")
|
|
61
|
+
- Extracting numeric limits and sorting preferences
|
|
62
|
+
- Identifying aggregation operations (count, sum, average)
|
|
63
|
+
|
|
64
|
+
RESPONSE STRUCTURE:
|
|
65
|
+
Return JSON matching this exact schema:
|
|
52
66
|
{
|
|
53
67
|
"entity": "<table_name>",
|
|
54
68
|
"operation": "<list|count|aggregate|filter>",
|
|
@@ -58,19 +72,113 @@ Return JSON with this exact structure:
|
|
|
58
72
|
"sort": "<field:asc|desc>" or null
|
|
59
73
|
}
|
|
60
74
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- "
|
|
72
|
-
- "count
|
|
73
|
-
|
|
75
|
+
FIELD REQUIREMENTS:
|
|
76
|
+
|
|
77
|
+
1. entity (string, required)
|
|
78
|
+
WHY: Determines which database table to query
|
|
79
|
+
- Must be a valid table name from the schema above
|
|
80
|
+
- Use singular or plural form as defined in schema
|
|
81
|
+
- Common variations: users/user, products/product, orders/order
|
|
82
|
+
|
|
83
|
+
2. operation (string, required)
|
|
84
|
+
WHY: Determines the type of SQL query to generate
|
|
85
|
+
- "list": Retrieve rows (SELECT * FROM ...)
|
|
86
|
+
- "count": Count rows (SELECT COUNT(*) FROM ...)
|
|
87
|
+
- "aggregate": Sum, average, min, max operations
|
|
88
|
+
- "filter": Same as list, but emphasizes filtering focus
|
|
89
|
+
|
|
90
|
+
3. filters (object, optional, default: {})
|
|
91
|
+
WHY: Extracts conditions to narrow results
|
|
92
|
+
- Key: field name from schema
|
|
93
|
+
- Value: expected value (as string)
|
|
94
|
+
- Implicit filters: "active users" → {"status": "active"}
|
|
95
|
+
- Explicit filters: "users from California" → {"state": "California"}
|
|
96
|
+
- Multiple filters: "active users from NY" → {"status": "active", "state": "NY"}
|
|
97
|
+
|
|
98
|
+
4. limit (integer or null, optional)
|
|
99
|
+
WHY: Controls result set size for performance
|
|
100
|
+
- Extract explicit numbers: "5 users", "top 10 products"
|
|
101
|
+
- Common phrases: "top N" = N, "first N" = N
|
|
102
|
+
- null if not specified (system will apply default)
|
|
103
|
+
|
|
104
|
+
5. fields (array of strings or null, optional)
|
|
105
|
+
WHY: Allows selecting specific columns instead of all
|
|
106
|
+
- null means "all fields" (SELECT *)
|
|
107
|
+
- Array means specific fields (SELECT field1, field2)
|
|
108
|
+
- Example: "show user emails" → ["email"]
|
|
109
|
+
|
|
110
|
+
6. sort (string or null, optional)
|
|
111
|
+
WHY: Specifies result ordering
|
|
112
|
+
- Format: "field:direction" where direction is "asc" or "desc"
|
|
113
|
+
- Extract from phrases: "newest first" → "created_at:desc"
|
|
114
|
+
- "highest price" → "price:desc", "alphabetically" → "name:asc"
|
|
115
|
+
- null if not mentioned
|
|
116
|
+
|
|
117
|
+
EXAMPLES WITH REASONING:
|
|
118
|
+
|
|
119
|
+
Example 1 - Simple with implicit filter:
|
|
120
|
+
Query: "get all active users"
|
|
121
|
+
Reasoning:
|
|
122
|
+
- "users" → entity: "users"
|
|
123
|
+
- "get all" → operation: "list" (retrieve rows)
|
|
124
|
+
- "active" → implicit filter on status field
|
|
125
|
+
- No limit mentioned → limit: null
|
|
126
|
+
- No specific fields → fields: null
|
|
127
|
+
- No sorting → sort: null
|
|
128
|
+
Result: {"entity": "users", "operation": "list", "filters": {"status": "active"}, "limit": null, "fields": null, "sort": null}
|
|
129
|
+
|
|
130
|
+
Example 2 - With explicit limit:
|
|
131
|
+
Query: "show me 10 products"
|
|
132
|
+
Reasoning:
|
|
133
|
+
- "products" → entity: "products"
|
|
134
|
+
- "show me" → operation: "list"
|
|
135
|
+
- "10" → explicit limit
|
|
136
|
+
- No filters → filters: {}
|
|
137
|
+
Result: {"entity": "products", "operation": "list", "filters": {}, "limit": 10, "fields": null, "sort": null}
|
|
138
|
+
|
|
139
|
+
Example 3 - Count operation:
|
|
140
|
+
Query: "count pending orders"
|
|
141
|
+
Reasoning:
|
|
142
|
+
- "orders" → entity: "orders"
|
|
143
|
+
- "count" → operation: "count" (aggregation)
|
|
144
|
+
- "pending" → implicit filter on status
|
|
145
|
+
- Count operations don't need limit
|
|
146
|
+
Result: {"entity": "orders", "operation": "count", "filters": {"status": "pending"}, "limit": null, "fields": null, "sort": null}
|
|
147
|
+
|
|
148
|
+
Example 4 - Sorting and limit:
|
|
149
|
+
Query: "top 5 most expensive products"
|
|
150
|
+
Reasoning:
|
|
151
|
+
- "products" → entity: "products"
|
|
152
|
+
- "top 5" → limit: 5
|
|
153
|
+
- "most expensive" → sort by price descending
|
|
154
|
+
- operation: "list" (retrieving rows)
|
|
155
|
+
Result: {"entity": "products", "operation": "list", "filters": {}, "limit": 5, "fields": null, "sort": "price:desc"}
|
|
156
|
+
|
|
157
|
+
Example 5 - Specific fields:
|
|
158
|
+
Query: "show user emails and names"
|
|
159
|
+
Reasoning:
|
|
160
|
+
- "user" → entity: "users"
|
|
161
|
+
- "show" → operation: "list"
|
|
162
|
+
- "emails and names" → specific fields requested
|
|
163
|
+
Result: {"entity": "users", "operation": "list", "filters": {}, "limit": null, "fields": ["email", "name"], "sort": null}
|
|
164
|
+
|
|
165
|
+
Example 6 - Complex with multiple filters:
|
|
166
|
+
Query: "active premium users from California"
|
|
167
|
+
Reasoning:
|
|
168
|
+
- "users" → entity: "users"
|
|
169
|
+
- "active" → filter: status = "active"
|
|
170
|
+
- "premium" → filter: tier = "premium" (or subscription_type)
|
|
171
|
+
- "from California" → filter: state = "California"
|
|
172
|
+
Result: {"entity": "users", "operation": "list", "filters": {"status": "active", "tier": "premium", "state": "California"}, "limit": null, "fields": null, "sort": null}
|
|
173
|
+
|
|
174
|
+
IMPORTANT GUIDELINES:
|
|
175
|
+
- When uncertain about a filter field name, use the most obvious choice from schema
|
|
176
|
+
- Normalize different phrasings: "get", "show", "list", "retrieve" all mean operation: "list"
|
|
177
|
+
- Be generous with implicit filters: common adjectives often map to status fields
|
|
178
|
+
- Always return valid JSON with all required fields
|
|
179
|
+
- Use null for optional fields when not specified, don't omit them
|
|
180
|
+
|
|
181
|
+
Your expertise in natural language understanding makes database queries accessible to everyone.`;
|
|
74
182
|
/**
|
|
75
183
|
* Service for parsing natural language into structured intents.
|
|
76
184
|
*/
|
package/dist/intent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../src/intent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIzD;;GAEG;AACH,MAAM,kBAAkB,GAAG;IACzB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,6DAA6D;SAChE;QACD,SAAS,EAAE;YACT,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC;YAC9C,WAAW,EAAE,gBAAgB;SAC9B;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,sC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I,EAAE,CAAC;YACT,KAAK,CAAC,IAAI,CAAC,QAAQ,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;;;;;;;OAQG;IACH,gBAAgB,CAAC,MAAc;QAC7B,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,CAAC;QAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/llm.d.ts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LLM integration layer using AI SDK for provider-agnostic support.
|
|
3
3
|
* Implements structured outputs for guaranteed schema compliance.
|
|
4
|
+
*
|
|
5
|
+
* MODEL SELECTION GUIDE (based on Claude 4.x capabilities):
|
|
6
|
+
*
|
|
7
|
+
* Anthropic Claude:
|
|
8
|
+
* - claude-sonnet-4-5: Best for SQL generation - excellent instruction following,
|
|
9
|
+
* strong reasoning, reliable structured outputs. Recommended default.
|
|
10
|
+
* - claude-opus-4-5: Most capable but slower - use for complex multi-table queries
|
|
11
|
+
* - claude-haiku-4: Fastest but less capable - use for simple lookups
|
|
12
|
+
*
|
|
13
|
+
* OpenAI:
|
|
14
|
+
* - gpt-4o: Fast and reliable for structured outputs
|
|
15
|
+
* - gpt-4-turbo: Good balance of speed and quality
|
|
16
|
+
* - gpt-3.5-turbo: Fastest but may struggle with complex schemas
|
|
17
|
+
*
|
|
18
|
+
* Cohere:
|
|
19
|
+
* - command-r-plus: Strong for enterprise use cases
|
|
20
|
+
* - command-r: Good balance of cost and performance
|
|
21
|
+
*
|
|
22
|
+
* Mistral:
|
|
23
|
+
* - mistral-large-latest: Competitive with GPT-4
|
|
24
|
+
* - mistral-medium: Good for simple queries
|
|
25
|
+
*
|
|
26
|
+
* Google Gemini:
|
|
27
|
+
* - gemini-pro: Solid general-purpose model
|
|
28
|
+
* - gemini-ultra: Most capable for complex reasoning
|
|
4
29
|
*/
|
|
5
30
|
import type { JsonValue, JsonObject } from './utils.js';
|
|
6
31
|
export interface LLMConfig {
|
package/dist/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,YAAY,CAAuC;IAC3D,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,SAAS;IAK7B;;;OAGG;YACW,eAAe;IAa7B;;OAEG;YACW,SAAS;IAwDvB;;;;;;;;;;;;;;;;OAgBG;IACG,cAAc,CAAC,CAAC,SAAS,SAAS,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,WAAW,GAAE,MAAY,EACzB,UAAU,GAAE,MAAU,GACrB,OAAO,CAAC,CAAC,CAAC;IAsCb;;;;;;;;;OASG;IACG,IAAI,CACR,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,WAAW,GAAE,MAAY,EACzB,UAAU,GAAE,MAAU,GACrB,OAAO,CAAC,MAAM,CAAC;CA6BnB"}
|
package/dist/llm.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LLM integration layer using AI SDK for provider-agnostic support.
|
|
3
3
|
* Implements structured outputs for guaranteed schema compliance.
|
|
4
|
+
*
|
|
5
|
+
* MODEL SELECTION GUIDE (based on Claude 4.x capabilities):
|
|
6
|
+
*
|
|
7
|
+
* Anthropic Claude:
|
|
8
|
+
* - claude-sonnet-4-5: Best for SQL generation - excellent instruction following,
|
|
9
|
+
* strong reasoning, reliable structured outputs. Recommended default.
|
|
10
|
+
* - claude-opus-4-5: Most capable but slower - use for complex multi-table queries
|
|
11
|
+
* - claude-haiku-4: Fastest but less capable - use for simple lookups
|
|
12
|
+
*
|
|
13
|
+
* OpenAI:
|
|
14
|
+
* - gpt-4o: Fast and reliable for structured outputs
|
|
15
|
+
* - gpt-4-turbo: Good balance of speed and quality
|
|
16
|
+
* - gpt-3.5-turbo: Fastest but may struggle with complex schemas
|
|
17
|
+
*
|
|
18
|
+
* Cohere:
|
|
19
|
+
* - command-r-plus: Strong for enterprise use cases
|
|
20
|
+
* - command-r: Good balance of cost and performance
|
|
21
|
+
*
|
|
22
|
+
* Mistral:
|
|
23
|
+
* - mistral-large-latest: Competitive with GPT-4
|
|
24
|
+
* - mistral-medium: Good for simple queries
|
|
25
|
+
*
|
|
26
|
+
* Google Gemini:
|
|
27
|
+
* - gemini-pro: Solid general-purpose model
|
|
28
|
+
* - gemini-ultra: Most capable for complex reasoning
|
|
4
29
|
*/
|
|
5
30
|
import { generateText } from 'ai';
|
|
6
31
|
import { LLMError } from './errors.js';
|
package/dist/llm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm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