@deepagents/text2sql 1.0.0 → 2.2.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 +83 -15
- package/dist/bin/sql.js +823 -169
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +345 -25
- package/dist/index.js.map +4 -4
- package/dist/lib/adapters/adapter.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.js +68 -21
- package/dist/lib/adapters/bigquery/index.js.map +2 -2
- package/dist/lib/adapters/mysql/index.js +68 -21
- package/dist/lib/adapters/mysql/index.js.map +2 -2
- package/dist/lib/adapters/postgres/index.js +68 -21
- package/dist/lib/adapters/postgres/index.js.map +2 -2
- package/dist/lib/adapters/runtime-scope.d.ts +2 -0
- package/dist/lib/adapters/runtime-scope.d.ts.map +1 -1
- package/dist/lib/adapters/spreadsheet/index.js +68 -21
- package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
- package/dist/lib/adapters/sqlite/index.js +68 -21
- package/dist/lib/adapters/sqlite/index.js.map +2 -2
- package/dist/lib/adapters/sqlserver/index.js +68 -21
- package/dist/lib/adapters/sqlserver/index.js.map +2 -2
- package/dist/lib/sql-command.d.ts +32 -0
- package/dist/lib/sql-command.d.ts.map +1 -0
- package/dist/lib/sql.d.ts +32 -8
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/index.js.map +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ npm install mysql2 # MySQL / MariaDB
|
|
|
26
26
|
npm install @google-cloud/bigquery # BigQuery
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Requires Node.js LTS
|
|
29
|
+
Requires Node.js LTS
|
|
30
30
|
|
|
31
31
|
## Quick Start
|
|
32
32
|
|
|
@@ -95,10 +95,9 @@ Text2SQL works with any model provider supported by the [Vercel AI SDK](https://
|
|
|
95
95
|
|
|
96
96
|
## Building a Conversational Agent
|
|
97
97
|
|
|
98
|
-
`Text2Sql`
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
`@deepagents/context`:
|
|
98
|
+
`Text2Sql` owns SQL generation and schema indexing, but you own the chat loop.
|
|
99
|
+
Build the agent by composing a `ContextEngine`, a sandbox, and `agent` +
|
|
100
|
+
`chat` from `@deepagents/context`:
|
|
102
101
|
|
|
103
102
|
```typescript
|
|
104
103
|
import {
|
|
@@ -107,7 +106,8 @@ import {
|
|
|
107
106
|
InMemoryContextStore,
|
|
108
107
|
agent,
|
|
109
108
|
chat,
|
|
110
|
-
|
|
109
|
+
createBashTool,
|
|
110
|
+
createDockerSandbox,
|
|
111
111
|
errorRecoveryGuardrail,
|
|
112
112
|
npm,
|
|
113
113
|
user,
|
|
@@ -121,11 +121,22 @@ const context = new ContextEngine({
|
|
|
121
121
|
userId: 'user-456',
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
const
|
|
124
|
+
const backend = await createDockerSandbox({
|
|
125
125
|
installers: [npm('@deepagents/text2sql', { ensureRuntime: true })],
|
|
126
|
+
volumes: [
|
|
127
|
+
{
|
|
128
|
+
type: 'bind',
|
|
129
|
+
hostPath: process.cwd(),
|
|
130
|
+
containerPath: '/workspace',
|
|
131
|
+
readOnly: true,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
126
134
|
env: {
|
|
127
135
|
TEXT2SQL_ADAPTERS: '/workspace/text2sql-adapters.ts',
|
|
128
136
|
},
|
|
137
|
+
});
|
|
138
|
+
const sandbox = await createBashTool({
|
|
139
|
+
sandbox: backend,
|
|
129
140
|
...createSqlCommandHooks({ adapters: { main: adapter } }),
|
|
130
141
|
});
|
|
131
142
|
|
|
@@ -154,6 +165,10 @@ for await (const chunk of stream) {
|
|
|
154
165
|
}
|
|
155
166
|
```
|
|
156
167
|
|
|
168
|
+
The `/workspace/text2sql-adapters.ts` module must exist in the sandbox and
|
|
169
|
+
default-export your adapter map. Mount your project into `/workspace` (as above)
|
|
170
|
+
or upload/write that module before you call `sql index` or `chat()`.
|
|
171
|
+
|
|
157
172
|
`instructions()` returns the SQL-flavored system fragments (policies, workflows,
|
|
158
173
|
clarifications, style guides) — spread them into `context.set()` alongside the
|
|
159
174
|
schema fragments returned by `sql index`. Add or replace them with your
|
|
@@ -162,14 +177,62 @@ own domain fragments as needed.
|
|
|
162
177
|
## Advanced: SQL CLI in Sandboxes
|
|
163
178
|
|
|
164
179
|
`sql validate <db> "..."` and `sql run <db> "..."` are real commands from the
|
|
165
|
-
`@deepagents/text2sql` package. `sql index
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
`@deepagents/text2sql` package. `sql index` writes schema fragments plus
|
|
181
|
+
progress events for chat setup, indexing all configured adapters by default
|
|
182
|
+
(same as `--all`) unless adapter names are provided.
|
|
183
|
+
|
|
184
|
+
Install the package inside the sandbox and set `TEXT2SQL_ADAPTERS` to a module
|
|
185
|
+
whose default export is `Record<string, Adapter>`. Missing `sql` means the
|
|
186
|
+
sandbox was not prepared correctly.
|
|
187
|
+
|
|
188
|
+
`sql index` output details:
|
|
189
|
+
|
|
190
|
+
- `stdout`: JSON manifest with `fragmentsPath`, `eventsPath`, adapters, and
|
|
191
|
+
fragment count.
|
|
192
|
+
- `--verbose pretty` or `--verbose json`: mirrors progress events to `stderr`
|
|
193
|
+
while keeping `stdout` as the manifest.
|
|
194
|
+
- `--out-dir <path>`: writes artifacts under that path (default:
|
|
195
|
+
`$TEXT2SQL_OUT_DIR` or `./sql`).
|
|
196
|
+
|
|
197
|
+
Set `TEXT2SQL_INDEX_VERSION` to manage cache invalidation across runs. Cache
|
|
198
|
+
keys are `index-<version>-<adapter>`, so bump the version when schema changes.
|
|
199
|
+
|
|
200
|
+
For in-process or virtual-sandbox usage (without installing the package CLI),
|
|
201
|
+
wrap an existing `Text2Sql` instance as a just-bash custom command:
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import {
|
|
205
|
+
Text2Sql,
|
|
206
|
+
createSqlCommand,
|
|
207
|
+
type CreateSqlCommandOptions,
|
|
208
|
+
type CreateSqlCommandResult,
|
|
209
|
+
} from '@deepagents/text2sql';
|
|
210
|
+
import { InMemoryFs, createVirtualSandbox } from '@deepagents/context';
|
|
211
|
+
|
|
212
|
+
const text2sql = new Text2Sql({ model, adapters: { main: adapter } });
|
|
213
|
+
|
|
214
|
+
const commandOptions: CreateSqlCommandOptions = {
|
|
215
|
+
outputDir: '/sql-artifacts',
|
|
216
|
+
};
|
|
217
|
+
const sqlCommand: CreateSqlCommandResult = createSqlCommand(
|
|
218
|
+
text2sql,
|
|
219
|
+
commandOptions,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const sandbox = await createVirtualSandbox({
|
|
223
|
+
fs: new InMemoryFs(),
|
|
224
|
+
customCommands: [sqlCommand.command],
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
await sandbox.executeCommand('sql validate main "SELECT 1"');
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`CreateSqlCommandOptions` configures command defaults (currently `outputDir`).
|
|
231
|
+
`CreateSqlCommandResult` returns the command plus a `repair(raw)` helper for
|
|
232
|
+
normalizing model-generated argv before execution.
|
|
233
|
+
|
|
234
|
+
Spread `createSqlCommandHooks({ adapters })` into `createBashTool()` for
|
|
235
|
+
model-driven bash calls. The before hook preserves
|
|
173
236
|
the old virtual-command tolerance for common LLM quote mistakes, rewrites SQL
|
|
174
237
|
identifier backticks so bash does not run them as command substitutions, and
|
|
175
238
|
blocks raw database access so read-only and scope checks stay behind
|
|
@@ -177,6 +240,10 @@ blocks raw database access so read-only and scope checks stay behind
|
|
|
177
240
|
metadata from the host adapter map without putting that concern into the real
|
|
178
241
|
CLI.
|
|
179
242
|
|
|
243
|
+
Read-only enforcement accepts a single `SELECT`/`WITH` statement even when it
|
|
244
|
+
starts with whitespace or SQL comments (`-- ...`, `/* ... */`). It still
|
|
245
|
+
rejects comment-only input, multi-statement batches, and write operations.
|
|
246
|
+
|
|
180
247
|
## Fragments
|
|
181
248
|
|
|
182
249
|
Inject domain knowledge by setting fragments on the `ContextEngine` you build
|
|
@@ -339,6 +406,7 @@ Full documentation available at [januarylabs.github.io/deepagents](https://janua
|
|
|
339
406
|
|
|
340
407
|
- [Getting Started](https://januarylabs.github.io/deepagents/docs/text2sql/getting-started)
|
|
341
408
|
- [Generate SQL](https://januarylabs.github.io/deepagents/docs/text2sql/to-sql)
|
|
409
|
+
- [Agent + SQLite Store Recipe](https://januarylabs.github.io/deepagents/docs/text2sql/recipes/agent-sqlite-store)
|
|
342
410
|
- [Teach the System](https://januarylabs.github.io/deepagents/docs/text2sql/teach-the-system)
|
|
343
411
|
- [Build Conversations](https://januarylabs.github.io/deepagents/docs/text2sql/build-conversations)
|
|
344
412
|
- [Grounding](https://januarylabs.github.io/deepagents/docs/text2sql/grounding)
|