nttp 1.4.9 → 1.4.11
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/README.md +171 -297
- 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/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,sCAAsC;YACnD,oBAAoB,EAAE,KAAK;SAC5B;QACD,KAAK,EAAE;YACL,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;YACzB,WAAW,EAAE,mCAAmC;SACjD;QACD,MAAM,EAAE;YACN,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;YACvB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,WAAW,EAAE,mDAAmD;SACjE;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;YACxB,WAAW,EAAE,uDAAuD;SACrE;KACF;IACD,QAAQ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K,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.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAUvC;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,KAAK,GAAyB,IAAI,CAAC;IACnC,YAAY,GAAkC,IAAI,CAAC;IACnD,MAAM,CAAY;IAClB,SAAS,CA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