@deepagents/text2sql 0.35.0 → 0.37.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 +121 -40
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +404 -727
- package/dist/index.js.map +4 -4
- package/dist/lib/adapter-name.d.ts +4 -0
- package/dist/lib/adapter-name.d.ts.map +1 -0
- package/dist/lib/adapters/adapter.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.js +35 -6
- package/dist/lib/adapters/bigquery/index.js.map +2 -2
- package/dist/lib/adapters/mysql/index.js +35 -6
- package/dist/lib/adapters/mysql/index.js.map +2 -2
- package/dist/lib/adapters/postgres/index.js +35 -6
- package/dist/lib/adapters/postgres/index.js.map +2 -2
- package/dist/lib/adapters/spreadsheet/index.js +35 -6
- package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
- package/dist/lib/adapters/sqlite/index.js +35 -6
- package/dist/lib/adapters/sqlite/index.js.map +2 -2
- package/dist/lib/adapters/sqlserver/index.js +35 -6
- package/dist/lib/adapters/sqlserver/index.js.map +2 -2
- package/dist/lib/agents/exceptions.d.ts +9 -0
- package/dist/lib/agents/exceptions.d.ts.map +1 -1
- package/dist/lib/agents/sql-command.d.ts +11 -0
- package/dist/lib/agents/sql-command.d.ts.map +1 -0
- package/dist/lib/agents/sql-transform-plugins.d.ts +4 -1
- package/dist/lib/agents/sql-transform-plugins.d.ts.map +1 -1
- package/dist/lib/demo.d.ts +2 -0
- package/dist/lib/demo.d.ts.map +1 -0
- package/dist/lib/fs/index.d.ts +0 -1
- package/dist/lib/fs/index.d.ts.map +1 -1
- package/dist/lib/instructions.d.ts.map +1 -1
- package/dist/lib/sandbox.d.ts +21 -0
- package/dist/lib/sandbox.d.ts.map +1 -0
- package/dist/lib/sql.d.ts +23 -37
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/index.js +12 -0
- package/dist/lib/synthesis/index.js.map +2 -2
- package/package.json +8 -8
- package/dist/lib/agents/explainer.agent.d.ts +0 -7
- package/dist/lib/agents/explainer.agent.d.ts.map +0 -1
- package/dist/lib/agents/result-tools.d.ts +0 -69
- package/dist/lib/agents/result-tools.d.ts.map +0 -1
- package/dist/lib/fs/tracked-fs.d.ts +0 -42
- package/dist/lib/fs/tracked-fs.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -23,16 +23,24 @@ Requires Node.js LTS (20+).
|
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
import { groq } from '@ai-sdk/groq';
|
|
26
|
+
import { InMemoryFs } from 'just-bash';
|
|
26
27
|
import pg from 'pg';
|
|
27
28
|
|
|
28
|
-
import {
|
|
29
|
-
|
|
29
|
+
import {
|
|
30
|
+
ContextEngine,
|
|
31
|
+
InMemoryContextStore,
|
|
32
|
+
createBashTool,
|
|
33
|
+
createRoutingSandbox,
|
|
34
|
+
createVirtualSandbox,
|
|
35
|
+
} from '@deepagents/context';
|
|
36
|
+
import { Text2Sql, sqlSandboxExtension } from '@deepagents/text2sql';
|
|
30
37
|
import {
|
|
31
38
|
Postgres,
|
|
32
39
|
columnValues,
|
|
33
40
|
constraints,
|
|
34
41
|
indexes,
|
|
35
42
|
info,
|
|
43
|
+
rowCount,
|
|
36
44
|
tables,
|
|
37
45
|
views,
|
|
38
46
|
} from '@deepagents/text2sql/postgres';
|
|
@@ -41,45 +49,97 @@ const pool = new pg.Pool({
|
|
|
41
49
|
connectionString: process.env.DATABASE_URL,
|
|
42
50
|
});
|
|
43
51
|
|
|
52
|
+
const store = new InMemoryContextStore();
|
|
53
|
+
const adapter = new Postgres({
|
|
54
|
+
execute: async (sql) => {
|
|
55
|
+
const result = await pool.query(sql);
|
|
56
|
+
return result.rows;
|
|
57
|
+
},
|
|
58
|
+
grounding: [
|
|
59
|
+
tables(),
|
|
60
|
+
views(),
|
|
61
|
+
info(),
|
|
62
|
+
indexes(),
|
|
63
|
+
constraints(),
|
|
64
|
+
rowCount(),
|
|
65
|
+
columnValues(),
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
const sandbox = await createBashTool({
|
|
69
|
+
sandbox: await createRoutingSandbox({
|
|
70
|
+
backend: await createVirtualSandbox({ fs: new InMemoryFs() }),
|
|
71
|
+
hostExtensions: [sqlSandboxExtension({ main: adapter })],
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
|
|
44
75
|
const text2sql = new Text2Sql({
|
|
45
76
|
version: 'v1',
|
|
46
|
-
model: groq('gpt-oss-20b'),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
columnValues(),
|
|
59
|
-
],
|
|
60
|
-
}),
|
|
61
|
-
store: new InMemoryContextStore(),
|
|
77
|
+
model: groq('openai/gpt-oss-20b'),
|
|
78
|
+
sandbox,
|
|
79
|
+
adapters: { main: adapter },
|
|
80
|
+
context: (...fragments) => {
|
|
81
|
+
const engine = new ContextEngine({
|
|
82
|
+
store,
|
|
83
|
+
chatId: 'chat-123',
|
|
84
|
+
userId: 'user-456',
|
|
85
|
+
});
|
|
86
|
+
engine.set(...fragments);
|
|
87
|
+
return engine;
|
|
88
|
+
},
|
|
62
89
|
});
|
|
63
90
|
|
|
64
91
|
// Generate SQL
|
|
65
|
-
const sql = await text2sql.toSql(
|
|
92
|
+
const sql = await text2sql.toSql(
|
|
93
|
+
'Show me the top 10 customers by revenue',
|
|
94
|
+
'main',
|
|
95
|
+
);
|
|
66
96
|
console.log(sql);
|
|
67
97
|
```
|
|
68
98
|
|
|
99
|
+
The adapter-map key (`main` here) is the adapter name. Reuse that same key in
|
|
100
|
+
`text2sql.toSql(..., 'main')` and in any `sql validate <db> "..."` /
|
|
101
|
+
`sql run <db> "..."` sandbox calls.
|
|
102
|
+
|
|
69
103
|
## AI Model Providers
|
|
70
104
|
|
|
71
105
|
Text2SQL works with any model provider supported by the [Vercel AI SDK](https://sdk.vercel.ai/docs), including OpenAI, Anthropic, Google, Groq, and more.
|
|
72
106
|
|
|
107
|
+
## Advanced: Composing Sandbox Extensions
|
|
108
|
+
|
|
109
|
+
`Text2Sql` takes a caller-owned `sandbox`. `sqlSandboxExtension(adaptersMap)`
|
|
110
|
+
returns a `SandboxExtension` that bundles the `sql` subcommand, transform
|
|
111
|
+
plugins, and arg-repair hook. In the simplest case, that map is
|
|
112
|
+
`{ main: adapter }`. Compose it (alongside any of your own extensions) via
|
|
113
|
+
`createBashTool` + `createRoutingSandbox` + `createVirtualSandbox`.
|
|
114
|
+
See [sqlv3.md](./sqlv3.md) for composition patterns.
|
|
115
|
+
|
|
73
116
|
## Fragments
|
|
74
117
|
|
|
75
|
-
Inject domain knowledge using fragments from `@deepagents/context`
|
|
118
|
+
Inject domain knowledge using fragments from `@deepagents/context` inside the
|
|
119
|
+
`context` factory you pass to `Text2Sql`. Those fragments affect `chat()`
|
|
120
|
+
sessions. If you need direct SQL generation with extra fragments, use the
|
|
121
|
+
lower-level `toSql({ fragments })` helper exported from `@deepagents/text2sql`.
|
|
76
122
|
|
|
77
123
|
```typescript
|
|
78
|
-
import {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
124
|
+
import {
|
|
125
|
+
ContextEngine,
|
|
126
|
+
InMemoryContextStore,
|
|
127
|
+
example,
|
|
128
|
+
guardrail,
|
|
129
|
+
hint,
|
|
130
|
+
term,
|
|
131
|
+
} from '@deepagents/context';
|
|
132
|
+
|
|
133
|
+
const store = new InMemoryContextStore();
|
|
134
|
+
|
|
135
|
+
const context = (...fragments) => {
|
|
136
|
+
const engine = new ContextEngine({
|
|
137
|
+
store,
|
|
138
|
+
chatId: 'chat-123',
|
|
139
|
+
userId: 'user-456',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
engine.set(
|
|
83
143
|
term('MRR', 'monthly recurring revenue'),
|
|
84
144
|
hint('Always exclude test accounts with email ending in @test.com'),
|
|
85
145
|
guardrail({
|
|
@@ -91,8 +151,11 @@ const text2sql = new Text2Sql({
|
|
|
91
151
|
question: 'show me churned customers',
|
|
92
152
|
answer: `SELECT * FROM customers WHERE status = 'churned' ORDER BY churned_at DESC`,
|
|
93
153
|
}),
|
|
94
|
-
|
|
95
|
-
|
|
154
|
+
...fragments,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return engine;
|
|
158
|
+
};
|
|
96
159
|
```
|
|
97
160
|
|
|
98
161
|
**Domain fragments** (11 types): `term`, `hint`, `guardrail`, `example`, `explain`, `clarification`, `workflow`, `quirk`, `styleGuide`, `analogy`, `glossary`.
|
|
@@ -118,26 +181,43 @@ Control what schema metadata the AI receives:
|
|
|
118
181
|
|
|
119
182
|
## Conversations
|
|
120
183
|
|
|
121
|
-
|
|
184
|
+
`chat()` persists history through the `ContextEngine` returned by your `context` factory. Reuse the same store, `chatId`, and `userId` to continue the same thread:
|
|
122
185
|
|
|
123
186
|
```typescript
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const stream = await text2sql.chat(
|
|
128
|
-
[{ role: 'user', content: 'Show me orders from last month' }],
|
|
129
|
-
{ chatId, userId },
|
|
130
|
-
);
|
|
187
|
+
const stream = await text2sql.chat([
|
|
188
|
+
{ role: 'user', content: 'Show me orders from last month' },
|
|
189
|
+
]);
|
|
131
190
|
|
|
132
191
|
for await (const chunk of stream) {
|
|
133
192
|
// handle streaming response
|
|
134
193
|
}
|
|
135
194
|
|
|
136
|
-
// Continue the
|
|
137
|
-
const followUp = await text2sql.chat(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
195
|
+
// Continue the same conversation
|
|
196
|
+
const followUp = await text2sql.chat([
|
|
197
|
+
{ role: 'user', content: 'Now filter to only completed ones' },
|
|
198
|
+
]);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`toSql()` is stateless. It reads the current schema fragments, but it does not
|
|
202
|
+
write messages, titles, or usage into your context store.
|
|
203
|
+
|
|
204
|
+
## Direct SQL Generation with Extra Fragments
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { term } from '@deepagents/context';
|
|
208
|
+
import { toSql } from '@deepagents/text2sql';
|
|
209
|
+
|
|
210
|
+
const result = await toSql({
|
|
211
|
+
input: 'Show ARR by plan',
|
|
212
|
+
adapter,
|
|
213
|
+
model: groq('openai/gpt-oss-20b'),
|
|
214
|
+
fragments: [
|
|
215
|
+
...(await adapter.introspect()),
|
|
216
|
+
term('ARR', 'annual recurring revenue'),
|
|
217
|
+
],
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
console.log(result.sql);
|
|
141
221
|
```
|
|
142
222
|
|
|
143
223
|
## Documentation
|
|
@@ -146,6 +226,7 @@ Full documentation available at [januarylabs.github.io/deepagents](https://janua
|
|
|
146
226
|
|
|
147
227
|
- [Getting Started](https://januarylabs.github.io/deepagents/docs/text2sql/getting-started)
|
|
148
228
|
- [Generate SQL](https://januarylabs.github.io/deepagents/docs/text2sql/to-sql)
|
|
229
|
+
- [Caller-Owned Sandbox](https://januarylabs.github.io/deepagents/docs/text2sql/sqlv3)
|
|
149
230
|
- [Teach the System](https://januarylabs.github.io/deepagents/docs/text2sql/teach-the-system)
|
|
150
231
|
- [Build Conversations](https://januarylabs.github.io/deepagents/docs/text2sql/build-conversations)
|
|
151
232
|
- [Grounding](https://januarylabs.github.io/deepagents/docs/text2sql/grounding)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export { isValidAdapterName, validateAdapterNames, } from './lib/adapter-name.ts';
|
|
1
2
|
export * from './lib/adapters/adapter.ts';
|
|
2
3
|
export * from './lib/agents/exceptions.ts';
|
|
3
|
-
export * from './lib/agents/
|
|
4
|
+
export * from './lib/agents/sql-command.ts';
|
|
5
|
+
export * from './lib/agents/sql-transform-plugins.ts';
|
|
4
6
|
export * from './lib/agents/sql.agent.ts';
|
|
5
7
|
export * from './lib/agents/suggestions.agents.ts';
|
|
6
8
|
export * from './lib/checkpoint.ts';
|
|
@@ -8,5 +10,6 @@ export * from './lib/file-cache.ts';
|
|
|
8
10
|
export * from './lib/fragments/schema.ts';
|
|
9
11
|
export * from './lib/fs/index.ts';
|
|
10
12
|
export * from './lib/instructions.ts';
|
|
13
|
+
export * from './lib/sandbox.ts';
|
|
11
14
|
export * from './lib/sql.ts';
|
|
12
15
|
//# 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,4BAA4B,CAAC;AAC3C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uCAAuC,CAAC;AACtD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|