@deepagents/text2sql 2.1.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 +46 -4
- package/dist/bin/sql.js +674 -116
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +344 -24
- 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 +4 -4
package/README.md
CHANGED
|
@@ -106,7 +106,8 @@ import {
|
|
|
106
106
|
InMemoryContextStore,
|
|
107
107
|
agent,
|
|
108
108
|
chat,
|
|
109
|
-
|
|
109
|
+
createBashTool,
|
|
110
|
+
createDockerSandbox,
|
|
110
111
|
errorRecoveryGuardrail,
|
|
111
112
|
npm,
|
|
112
113
|
user,
|
|
@@ -120,7 +121,7 @@ const context = new ContextEngine({
|
|
|
120
121
|
userId: 'user-456',
|
|
121
122
|
});
|
|
122
123
|
|
|
123
|
-
const
|
|
124
|
+
const backend = await createDockerSandbox({
|
|
124
125
|
installers: [npm('@deepagents/text2sql', { ensureRuntime: true })],
|
|
125
126
|
volumes: [
|
|
126
127
|
{
|
|
@@ -133,6 +134,9 @@ const sandbox = await createContainerTool({
|
|
|
133
134
|
env: {
|
|
134
135
|
TEXT2SQL_ADAPTERS: '/workspace/text2sql-adapters.ts',
|
|
135
136
|
},
|
|
137
|
+
});
|
|
138
|
+
const sandbox = await createBashTool({
|
|
139
|
+
sandbox: backend,
|
|
136
140
|
...createSqlCommandHooks({ adapters: { main: adapter } }),
|
|
137
141
|
});
|
|
138
142
|
|
|
@@ -193,8 +197,42 @@ sandbox was not prepared correctly.
|
|
|
193
197
|
Set `TEXT2SQL_INDEX_VERSION` to manage cache invalidation across runs. Cache
|
|
194
198
|
keys are `index-<version>-<adapter>`, so bump the version when schema changes.
|
|
195
199
|
|
|
196
|
-
|
|
197
|
-
`
|
|
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
|
|
198
236
|
the old virtual-command tolerance for common LLM quote mistakes, rewrites SQL
|
|
199
237
|
identifier backticks so bash does not run them as command substitutions, and
|
|
200
238
|
blocks raw database access so read-only and scope checks stay behind
|
|
@@ -202,6 +240,10 @@ blocks raw database access so read-only and scope checks stay behind
|
|
|
202
240
|
metadata from the host adapter map without putting that concern into the real
|
|
203
241
|
CLI.
|
|
204
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
|
+
|
|
205
247
|
## Fragments
|
|
206
248
|
|
|
207
249
|
Inject domain knowledge by setting fragments on the `ContextEngine` you build
|