@deepagents/text2sql 0.10.2 → 0.11.0
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 +32 -41
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2338 -2398
- package/dist/index.js.map +4 -4
- package/dist/lib/adapters/adapter.d.ts +13 -1
- package/dist/lib/adapters/adapter.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/abstract.grounding.d.ts +19 -3
- package/dist/lib/adapters/groundings/abstract.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/column-stats.grounding.d.ts +1 -2
- package/dist/lib/adapters/groundings/column-stats.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/column-values.grounding.d.ts +1 -2
- package/dist/lib/adapters/groundings/column-values.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/constraint.grounding.d.ts +1 -1
- package/dist/lib/adapters/groundings/constraint.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/index.js +15 -222
- package/dist/lib/adapters/groundings/index.js.map +3 -3
- package/dist/lib/adapters/groundings/indexes.grounding.d.ts +1 -1
- package/dist/lib/adapters/groundings/indexes.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/info.grounding.d.ts +1 -1
- package/dist/lib/adapters/groundings/info.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/report.grounding.d.ts +1 -1
- package/dist/lib/adapters/groundings/report.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/row-count.grounding.d.ts +1 -1
- package/dist/lib/adapters/groundings/row-count.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/table.grounding.d.ts +3 -3
- package/dist/lib/adapters/groundings/table.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/view.grounding.d.ts +1 -1
- package/dist/lib/adapters/groundings/view.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/index.js +343 -315
- package/dist/lib/adapters/mysql/index.js.map +4 -4
- package/dist/lib/adapters/postgres/index.js +385 -357
- package/dist/lib/adapters/postgres/index.js.map +4 -4
- package/dist/lib/adapters/spreadsheet/index.js +290 -223
- package/dist/lib/adapters/spreadsheet/index.js.map +4 -4
- package/dist/lib/adapters/sqlite/index.js +307 -279
- package/dist/lib/adapters/sqlite/index.js.map +4 -4
- package/dist/lib/adapters/sqlserver/index.js +383 -355
- package/dist/lib/adapters/sqlserver/index.js.map +4 -4
- package/dist/lib/agents/developer.agent.d.ts +33 -23
- package/dist/lib/agents/developer.agent.d.ts.map +1 -1
- package/dist/lib/agents/sql.agent.d.ts +4 -4
- package/dist/lib/agents/sql.agent.d.ts.map +1 -1
- package/dist/lib/agents/teachables.agent.d.ts +2 -2
- package/dist/lib/agents/teachables.agent.d.ts.map +1 -1
- package/dist/lib/agents/text2sql.agent.d.ts +18 -71
- package/dist/lib/agents/text2sql.agent.d.ts.map +1 -1
- package/dist/lib/fragments/schema.d.ts +214 -0
- package/dist/lib/fragments/schema.d.ts.map +1 -0
- package/dist/lib/instructions.d.ts +29 -2
- package/dist/lib/instructions.d.ts.map +1 -1
- package/dist/lib/instructions.js +336 -319
- package/dist/lib/instructions.js.map +4 -4
- package/dist/lib/sql.d.ts +13 -103
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/base-contextual-extractor.d.ts +2 -2
- package/dist/lib/synthesis/extractors/base-contextual-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/message-extractor.d.ts +1 -2
- package/dist/lib/synthesis/extractors/message-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/sql-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/index.js +1794 -572
- package/dist/lib/synthesis/index.js.map +4 -4
- package/dist/lib/synthesis/synthesizers/depth-evolver.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/persona-generator.d.ts +7 -17
- package/dist/lib/synthesis/synthesizers/persona-generator.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/schema-synthesizer.d.ts +2 -2
- package/dist/lib/synthesis/synthesizers/schema-synthesizer.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/teachings-generator.d.ts +8 -20
- package/dist/lib/synthesis/synthesizers/teachings-generator.d.ts.map +1 -1
- package/dist/lib/teach/teachings.d.ts +2 -2
- package/dist/lib/teach/teachings.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/lib/agents/chat1.agent.d.ts +0 -50
- package/dist/lib/agents/chat1.agent.d.ts.map +0 -1
- package/dist/lib/agents/chat2.agent.d.ts +0 -68
- package/dist/lib/agents/chat2.agent.d.ts.map +0 -1
- package/dist/lib/agents/chat3.agent.d.ts +0 -80
- package/dist/lib/agents/chat3.agent.d.ts.map +0 -1
- package/dist/lib/agents/chat4.agent.d.ts +0 -88
- package/dist/lib/agents/chat4.agent.d.ts.map +0 -1
- package/dist/lib/history/history.d.ts +0 -41
- package/dist/lib/history/history.d.ts.map +0 -1
- package/dist/lib/history/memory.history.d.ts +0 -5
- package/dist/lib/history/memory.history.d.ts.map +0 -1
- package/dist/lib/history/sqlite.history.d.ts +0 -15
- package/dist/lib/history/sqlite.history.d.ts.map +0 -1
- package/dist/lib/memory/memory.prompt.d.ts +0 -3
- package/dist/lib/memory/memory.prompt.d.ts.map +0 -1
- package/dist/lib/memory/memory.store.d.ts +0 -5
- package/dist/lib/memory/memory.store.d.ts.map +0 -1
- package/dist/lib/memory/sqlite.store.d.ts +0 -14
- package/dist/lib/memory/sqlite.store.d.ts.map +0 -1
- package/dist/lib/memory/store.d.ts +0 -40
- package/dist/lib/memory/store.d.ts.map +0 -1
- package/dist/lib/teach/teachables.d.ts +0 -648
- package/dist/lib/teach/teachables.d.ts.map +0 -1
- package/dist/lib/teach/xml.d.ts +0 -6
- package/dist/lib/teach/xml.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -7,9 +7,8 @@ AI-powered natural language to SQL. Ask questions in plain English, get executab
|
|
|
7
7
|
- **Natural Language to SQL** - Convert questions to validated, executable queries
|
|
8
8
|
- **Multi-Database Support** - PostgreSQL, SQLite, and SQL Server adapters
|
|
9
9
|
- **Schema-Aware** - Automatic introspection of tables, relationships, indexes, and constraints
|
|
10
|
-
- **Domain Knowledge** -
|
|
11
|
-
- **Conversational** - Multi-turn conversations with
|
|
12
|
-
- **Explainable** - Convert SQL back to plain English explanations
|
|
10
|
+
- **Domain Knowledge** - Inject business terms, guardrails, and query patterns via fragments
|
|
11
|
+
- **Conversational** - Multi-turn conversations with context persistence
|
|
13
12
|
- **Safe by Default** - Read-only queries, validation, and configurable guardrails
|
|
14
13
|
|
|
15
14
|
## Installation
|
|
@@ -23,9 +22,11 @@ Requires Node.js LTS (20+).
|
|
|
23
22
|
## Quick Start
|
|
24
23
|
|
|
25
24
|
```typescript
|
|
25
|
+
import { groq } from '@ai-sdk/groq';
|
|
26
26
|
import pg from 'pg';
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import { InMemoryContextStore } from '@deepagents/context';
|
|
29
|
+
import { Text2Sql } from '@deepagents/text2sql';
|
|
29
30
|
import {
|
|
30
31
|
Postgres,
|
|
31
32
|
constraints,
|
|
@@ -42,6 +43,7 @@ const pool = new pg.Pool({
|
|
|
42
43
|
|
|
43
44
|
const text2sql = new Text2Sql({
|
|
44
45
|
version: 'v1',
|
|
46
|
+
model: groq('gpt-oss-20b'),
|
|
45
47
|
adapter: new Postgres({
|
|
46
48
|
execute: async (sql) => {
|
|
47
49
|
const result = await pool.query(sql);
|
|
@@ -56,7 +58,7 @@ const text2sql = new Text2Sql({
|
|
|
56
58
|
lowCardinality(),
|
|
57
59
|
],
|
|
58
60
|
}),
|
|
59
|
-
|
|
61
|
+
store: new InMemoryContextStore(),
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
// Generate SQL
|
|
@@ -68,34 +70,36 @@ console.log(sql);
|
|
|
68
70
|
|
|
69
71
|
Text2SQL works with any model provider supported by the [Vercel AI SDK](https://sdk.vercel.ai/docs), including OpenAI, Anthropic, Google, Groq, and more.
|
|
70
72
|
|
|
71
|
-
##
|
|
73
|
+
## Fragments
|
|
72
74
|
|
|
73
|
-
Inject domain knowledge to improve query accuracy:
|
|
75
|
+
Inject domain knowledge using fragments from `@deepagents/context` to improve query accuracy. Pass instructions via the constructor:
|
|
74
76
|
|
|
75
77
|
```typescript
|
|
76
|
-
import {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
78
|
+
import { example, guardrail, hint, term } from '@deepagents/context';
|
|
79
|
+
|
|
80
|
+
const text2sql = new Text2Sql({
|
|
81
|
+
// ... other config
|
|
82
|
+
instructions: [
|
|
83
|
+
term('MRR', 'monthly recurring revenue'),
|
|
84
|
+
hint('Always exclude test accounts with email ending in @test.com'),
|
|
85
|
+
guardrail({
|
|
86
|
+
rule: 'Never expose individual salaries',
|
|
87
|
+
reason: 'Confidential HR data',
|
|
88
|
+
action: 'Aggregate by department instead',
|
|
89
|
+
}),
|
|
90
|
+
example({
|
|
91
|
+
question: 'show me churned customers',
|
|
92
|
+
answer: `SELECT * FROM customers WHERE status = 'churned' ORDER BY churned_at DESC`,
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
**Domain fragments** (11 types): `term`, `hint`, `guardrail`, `example`, `explain`, `clarification`, `workflow`, `quirk`, `styleGuide`, `analogy`, `glossary`.
|
|
99
|
+
|
|
100
|
+
**User fragments** (6 types): `identity`, `persona`, `alias`, `preference`, `userContext`, `correction`.
|
|
101
|
+
|
|
102
|
+
See [@deepagents/context](../context/README.md) for full fragment documentation.
|
|
99
103
|
|
|
100
104
|
## Grounding
|
|
101
105
|
|
|
@@ -136,19 +140,6 @@ const followUp = await text2sql.chat(
|
|
|
136
140
|
);
|
|
137
141
|
```
|
|
138
142
|
|
|
139
|
-
## Explain Queries
|
|
140
|
-
|
|
141
|
-
Convert SQL to plain English:
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
const explanation = await text2sql.explain(`
|
|
145
|
-
SELECT department, AVG(salary)
|
|
146
|
-
FROM employees
|
|
147
|
-
GROUP BY department
|
|
148
|
-
`);
|
|
149
|
-
// "This query calculates the average salary for each department..."
|
|
150
|
-
```
|
|
151
|
-
|
|
152
143
|
## Documentation
|
|
153
144
|
|
|
154
145
|
Full documentation available at [januarylabs.github.io/deepagents](https://januarylabs.github.io/deepagents/docs/text2sql):
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,7 @@ export * from './lib/agents/suggestions.agents.ts';
|
|
|
4
4
|
export * from './lib/agents/text2sql.agent.ts';
|
|
5
5
|
export * from './lib/checkpoint.ts';
|
|
6
6
|
export * from './lib/file-cache.ts';
|
|
7
|
-
export * from './lib/
|
|
8
|
-
export * from './lib/history/memory.history.ts';
|
|
9
|
-
export * from './lib/history/sqlite.history.ts';
|
|
10
|
-
export * from './lib/memory/memory.store.ts';
|
|
11
|
-
export * from './lib/memory/sqlite.store.ts';
|
|
12
|
-
export * from './lib/memory/store.ts';
|
|
7
|
+
export * from './lib/fragments/schema.ts';
|
|
13
8
|
export * from './lib/sql.ts';
|
|
14
9
|
export * from './lib/teach/teachings.ts';
|
|
15
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
|