@deepagents/text2sql 7.0.2 → 7.1.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 +3 -2
- package/dist/bin/sql.js +57 -32
- package/dist/index.js +793 -498
- package/dist/index.js.map +4 -4
- package/dist/lib/adapters/adapter.d.ts +23 -1
- package/dist/lib/adapters/adapter.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/bigquery-fk.d.ts +0 -11
- package/dist/lib/adapters/bigquery/bigquery-fk.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/bigquery-rows.d.ts +22 -0
- package/dist/lib/adapters/bigquery/bigquery-rows.d.ts.map +1 -0
- package/dist/lib/adapters/bigquery/bigquery.d.ts +1 -1
- package/dist/lib/adapters/bigquery/bigquery.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/constraint.bigquery.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.d.ts +6 -13
- package/dist/lib/adapters/bigquery/index.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.js +244 -51
- package/dist/lib/adapters/bigquery/index.js.map +4 -4
- package/dist/lib/adapters/bigquery/indexes.bigquery.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/row-count.bigquery.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/table.bigquery.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/view.bigquery.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/clickhouse-rows.d.ts +7 -0
- package/dist/lib/adapters/clickhouse/clickhouse-rows.d.ts.map +1 -0
- package/dist/lib/adapters/clickhouse/clickhouse.d.ts +1 -1
- package/dist/lib/adapters/clickhouse/clickhouse.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/constraint.clickhouse.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/index.js +133 -44
- package/dist/lib/adapters/clickhouse/index.js.map +4 -4
- package/dist/lib/adapters/clickhouse/indexes.clickhouse.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/info.clickhouse.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/row-count.clickhouse.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/table.clickhouse.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/clickhouse/view.clickhouse.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/duckdb/duckdb.d.ts +1 -1
- package/dist/lib/adapters/duckdb/duckdb.d.ts.map +1 -1
- package/dist/lib/adapters/duckdb/duckdb.groundings.d.ts.map +1 -1
- package/dist/lib/adapters/duckdb/index.d.ts +8 -10
- package/dist/lib/adapters/duckdb/index.d.ts.map +1 -1
- package/dist/lib/adapters/duckdb/index.js +1549 -1412
- package/dist/lib/adapters/duckdb/index.js.map +4 -4
- package/dist/lib/adapters/groundings/index.js.map +1 -1
- package/dist/lib/adapters/groundings/rows.d.ts +32 -0
- package/dist/lib/adapters/groundings/rows.d.ts.map +1 -0
- package/dist/lib/adapters/mysql/column-stats.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/column-values.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/constraint.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/index.d.ts +2 -4
- package/dist/lib/adapters/mysql/index.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/index.js +230 -76
- package/dist/lib/adapters/mysql/index.js.map +4 -4
- package/dist/lib/adapters/mysql/indexes.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/info.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/mysql-rows.d.ts +11 -0
- package/dist/lib/adapters/mysql/mysql-rows.d.ts.map +1 -0
- package/dist/lib/adapters/mysql/mysql.d.ts +1 -1
- package/dist/lib/adapters/mysql/mysql.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/row-count.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/table.mysql.grounding.d.ts +3 -2
- package/dist/lib/adapters/mysql/table.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/view.mysql.grounding.d.ts +2 -2
- package/dist/lib/adapters/mysql/view.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/column-stats.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/column-values.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/constraint.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/index.d.ts +2 -4
- package/dist/lib/adapters/postgres/index.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/index.js +266 -487
- package/dist/lib/adapters/postgres/index.js.map +4 -4
- package/dist/lib/adapters/postgres/indexes.postgres.grounding.d.ts +1 -5
- package/dist/lib/adapters/postgres/indexes.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/info.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/postgres-rows.d.ts +7 -0
- package/dist/lib/adapters/postgres/postgres-rows.d.ts.map +1 -0
- package/dist/lib/adapters/postgres/postgres.d.ts +6 -1
- package/dist/lib/adapters/postgres/postgres.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/row-count.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/table.postgres.grounding.d.ts +5 -4
- package/dist/lib/adapters/postgres/table.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/view.postgres.grounding.d.ts +3 -3
- package/dist/lib/adapters/postgres/view.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/definitions.posthog.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/index.d.ts +4 -5
- package/dist/lib/adapters/posthog/index.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/index.js +349 -287
- package/dist/lib/adapters/posthog/index.js.map +4 -4
- package/dist/lib/adapters/posthog/posthog.d.ts +2 -2
- package/dist/lib/adapters/posthog/posthog.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/posthog.sql-policy.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/schema.posthog.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/transport.d.ts.map +1 -1
- package/dist/lib/adapters/posthog/types.d.ts +16 -6
- package/dist/lib/adapters/posthog/types.d.ts.map +1 -1
- package/dist/lib/adapters/spreadsheet/index.js +113 -34
- package/dist/lib/adapters/spreadsheet/index.js.map +4 -4
- package/dist/lib/adapters/sqlite/column-stats.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/column-values.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/constraint.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/index.js +136 -49
- package/dist/lib/adapters/sqlite/index.js.map +4 -4
- package/dist/lib/adapters/sqlite/indexes.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/info.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/row-count.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/sqlite-rows.d.ts +41 -0
- package/dist/lib/adapters/sqlite/sqlite-rows.d.ts.map +1 -0
- package/dist/lib/adapters/sqlite/sqlite.d.ts +1 -1
- package/dist/lib/adapters/sqlite/sqlite.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/table.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/view.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/column-stats.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/column-values.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/constraint.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/index.d.ts +2 -4
- package/dist/lib/adapters/sqlserver/index.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/index.js +223 -455
- package/dist/lib/adapters/sqlserver/index.js.map +4 -4
- package/dist/lib/adapters/sqlserver/indexes.sqlserver.grounding.d.ts +1 -5
- package/dist/lib/adapters/sqlserver/indexes.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/info.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/row-count.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/sqlserver-rows.d.ts +7 -0
- package/dist/lib/adapters/sqlserver/sqlserver-rows.d.ts.map +1 -0
- package/dist/lib/adapters/sqlserver/sqlserver.d.ts +6 -1
- package/dist/lib/adapters/sqlserver/sqlserver.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/table.sqlserver.grounding.d.ts +4 -3
- package/dist/lib/adapters/sqlserver/table.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/view.sqlserver.grounding.d.ts +3 -3
- package/dist/lib/adapters/sqlserver/view.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/agents/sql-transform-plugins.d.ts.map +1 -1
- package/dist/lib/checkpoint.d.ts +34 -21
- package/dist/lib/checkpoint.d.ts.map +1 -1
- package/dist/lib/file-cache.d.ts +6 -1
- package/dist/lib/file-cache.d.ts.map +1 -1
- package/dist/lib/fs/columns.d.ts +14 -0
- package/dist/lib/fs/columns.d.ts.map +1 -0
- package/dist/lib/fs/mssql/mssql-fs.d.ts +4 -4
- package/dist/lib/fs/mssql/mssql-fs.d.ts.map +1 -1
- package/dist/lib/fs/postgres/postgres-fs.d.ts +4 -4
- package/dist/lib/fs/postgres/postgres-fs.d.ts.map +1 -1
- package/dist/lib/fs/sqlite/sqlite-fs.d.ts +4 -4
- package/dist/lib/fs/sqlite/sqlite-fs.d.ts.map +1 -1
- package/dist/lib/index-cache.d.ts +4 -3
- package/dist/lib/index-cache.d.ts.map +1 -1
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/decorators/deduplicated-producer.d.ts +1 -2
- package/dist/lib/synthesis/decorators/deduplicated-producer.d.ts.map +1 -1
- package/dist/lib/synthesis/decorators/filtered-producer.d.ts +0 -2
- package/dist/lib/synthesis/decorators/filtered-producer.d.ts.map +1 -1
- package/dist/lib/synthesis/decorators/validated-producer.d.ts +1 -3
- package/dist/lib/synthesis/decorators/validated-producer.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/base-contextual-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/message-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/tool-input.d.ts +6 -0
- package/dist/lib/synthesis/extractors/tool-input.d.ts.map +1 -0
- package/dist/lib/synthesis/index.js +124 -114
- package/dist/lib/synthesis/index.js.map +4 -4
- package/dist/lib/synthesis/synthesizers/breadth-evolver.d.ts +0 -2
- package/dist/lib/synthesis/synthesizers/breadth-evolver.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/depth-evolver.d.ts +0 -3
- package/dist/lib/synthesis/synthesizers/depth-evolver.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/schema-synthesizer.d.ts +0 -2
- package/dist/lib/synthesis/synthesizers/schema-synthesizer.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -24,31 +24,31 @@ async function toPairs(producer) {
|
|
|
24
24
|
var { Parser } = nodeSqlParser;
|
|
25
25
|
var parser = new Parser();
|
|
26
26
|
var FilteredProducer = class extends PairProducer {
|
|
27
|
+
#producer;
|
|
28
|
+
#options;
|
|
27
29
|
/**
|
|
28
30
|
* @param producer - Source producer to filter
|
|
29
31
|
* @param options - Filter configuration
|
|
30
32
|
*/
|
|
31
33
|
constructor(producer, options = {}) {
|
|
32
34
|
super();
|
|
33
|
-
this
|
|
34
|
-
this
|
|
35
|
+
this.#producer = producer;
|
|
36
|
+
this.#options = options;
|
|
35
37
|
}
|
|
36
|
-
producer;
|
|
37
|
-
options;
|
|
38
38
|
/**
|
|
39
39
|
* Produces pairs filtered by success status, table usage, and custom predicates.
|
|
40
40
|
* @returns Pairs matching all configured filter criteria
|
|
41
41
|
*/
|
|
42
42
|
async *produce() {
|
|
43
|
-
for await (const chunk of this
|
|
43
|
+
for await (const chunk of this.#producer.produce()) {
|
|
44
44
|
const filtered = chunk.filter((pair) => {
|
|
45
|
-
if (this
|
|
45
|
+
if (this.#options.successOnly !== false && !pair.success) {
|
|
46
46
|
return false;
|
|
47
47
|
}
|
|
48
|
-
if (this
|
|
49
|
-
if (!this.matchesTables(pair.sql, this
|
|
48
|
+
if (this.#options.tables?.length) {
|
|
49
|
+
if (!this.matchesTables(pair.sql, this.#options.tables)) return false;
|
|
50
50
|
}
|
|
51
|
-
if (this
|
|
51
|
+
if (this.#options.filter && !this.#options.filter(pair)) {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
54
|
return true;
|
|
@@ -65,7 +65,7 @@ var FilteredProducer = class extends PairProducer {
|
|
|
65
65
|
const filterNames = this.#filterNames;
|
|
66
66
|
try {
|
|
67
67
|
const refs = parser.tableList(sql, {
|
|
68
|
-
database: this
|
|
68
|
+
database: this.#options.dialect
|
|
69
69
|
});
|
|
70
70
|
const sqlNames = refs.map((r) => r.split("::").pop().toLowerCase());
|
|
71
71
|
return sqlNames.some((t) => filterNames.has(t));
|
|
@@ -81,25 +81,25 @@ import nodeSqlParser2 from "node-sql-parser";
|
|
|
81
81
|
var { Parser: Parser2 } = nodeSqlParser2;
|
|
82
82
|
var parser2 = new Parser2();
|
|
83
83
|
var DeduplicatedProducer = class extends PairProducer {
|
|
84
|
+
#producer;
|
|
85
|
+
#options;
|
|
84
86
|
/**
|
|
85
87
|
* @param producer - Source producer to deduplicate
|
|
86
88
|
* @param options - Deduplication configuration
|
|
87
89
|
*/
|
|
88
90
|
constructor(producer, options = {}) {
|
|
89
91
|
super();
|
|
90
|
-
this
|
|
91
|
-
this
|
|
92
|
+
this.#producer = producer;
|
|
93
|
+
this.#options = options;
|
|
92
94
|
}
|
|
93
|
-
producer;
|
|
94
|
-
options;
|
|
95
95
|
/**
|
|
96
96
|
* Produces pairs with duplicates removed based on the configured strategy.
|
|
97
97
|
* @returns Unique pairs after deduplication
|
|
98
98
|
*/
|
|
99
99
|
async *produce() {
|
|
100
|
-
const { strategy = "exact" } = this
|
|
100
|
+
const { strategy = "exact" } = this.#options;
|
|
101
101
|
const seen = /* @__PURE__ */ new Set();
|
|
102
|
-
for await (const chunk of this
|
|
102
|
+
for await (const chunk of this.#producer.produce()) {
|
|
103
103
|
const unique = [];
|
|
104
104
|
for (const pair of chunk) {
|
|
105
105
|
let key;
|
|
@@ -126,8 +126,8 @@ var DeduplicatedProducer = class extends PairProducer {
|
|
|
126
126
|
}
|
|
127
127
|
normalizeSQL(sql) {
|
|
128
128
|
try {
|
|
129
|
-
const ast = parser2.astify(sql, { database: this
|
|
130
|
-
return parser2.sqlify(ast, { database: this
|
|
129
|
+
const ast = parser2.astify(sql, { database: this.#options.dialect });
|
|
130
|
+
return parser2.sqlify(ast, { database: this.#options.dialect }).toLowerCase();
|
|
131
131
|
} catch {
|
|
132
132
|
return sql.toLowerCase().replace(/\s+/g, " ").trim();
|
|
133
133
|
}
|
|
@@ -136,6 +136,9 @@ var DeduplicatedProducer = class extends PairProducer {
|
|
|
136
136
|
|
|
137
137
|
// packages/text2sql/src/lib/synthesis/decorators/validated-producer.ts
|
|
138
138
|
var ValidatedProducer = class extends PairProducer {
|
|
139
|
+
#producer;
|
|
140
|
+
#adapter;
|
|
141
|
+
#options;
|
|
139
142
|
/**
|
|
140
143
|
* @param producer - Source producer to validate
|
|
141
144
|
* @param adapter - Database adapter for SQL validation
|
|
@@ -143,24 +146,21 @@ var ValidatedProducer = class extends PairProducer {
|
|
|
143
146
|
*/
|
|
144
147
|
constructor(producer, adapter, options = {}) {
|
|
145
148
|
super();
|
|
146
|
-
this
|
|
147
|
-
this
|
|
148
|
-
this
|
|
149
|
+
this.#producer = producer;
|
|
150
|
+
this.#adapter = adapter;
|
|
151
|
+
this.#options = options;
|
|
149
152
|
}
|
|
150
|
-
producer;
|
|
151
|
-
adapter;
|
|
152
|
-
options;
|
|
153
153
|
/**
|
|
154
154
|
* Produces pairs with SQL validation applied, optionally executing queries.
|
|
155
155
|
* @returns Validated pairs with error/rowCount metadata attached
|
|
156
156
|
*/
|
|
157
157
|
async *produce() {
|
|
158
|
-
for await (const chunk of this
|
|
158
|
+
for await (const chunk of this.#producer.produce()) {
|
|
159
159
|
const validated = [];
|
|
160
160
|
for (const pair of chunk) {
|
|
161
|
-
const error = await this
|
|
161
|
+
const error = await this.#adapter.validate(pair.sql);
|
|
162
162
|
if (error) {
|
|
163
|
-
if (!this
|
|
163
|
+
if (!this.#options.removeInvalid) {
|
|
164
164
|
validated.push({
|
|
165
165
|
...pair,
|
|
166
166
|
success: false,
|
|
@@ -170,9 +170,9 @@ var ValidatedProducer = class extends PairProducer {
|
|
|
170
170
|
continue;
|
|
171
171
|
}
|
|
172
172
|
let rowCount;
|
|
173
|
-
if (this
|
|
173
|
+
if (this.#options.execute) {
|
|
174
174
|
try {
|
|
175
|
-
const result = await this
|
|
175
|
+
const result = await this.#adapter.execute(pair.sql);
|
|
176
176
|
rowCount = Array.isArray(result) ? result.length : void 0;
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
@@ -197,7 +197,7 @@ import { getToolName as getToolName2, isToolUIPart as isToolUIPart2 } from "ai";
|
|
|
197
197
|
import { groq } from "@ai-sdk/groq";
|
|
198
198
|
import { getToolName, isTextUIPart, isToolUIPart } from "ai";
|
|
199
199
|
import dedent from "dedent";
|
|
200
|
-
import
|
|
200
|
+
import z2 from "zod";
|
|
201
201
|
import {
|
|
202
202
|
ContextEngine,
|
|
203
203
|
InMemoryContextStore,
|
|
@@ -206,8 +206,18 @@ import {
|
|
|
206
206
|
structuredOutput,
|
|
207
207
|
user
|
|
208
208
|
} from "@deepagents/context";
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
|
|
210
|
+
// packages/text2sql/src/lib/synthesis/extractors/tool-input.ts
|
|
211
|
+
import z from "zod";
|
|
212
|
+
var sqlToolInput = z.object({ sql: z.string() });
|
|
213
|
+
function toolInputSql(input) {
|
|
214
|
+
const parsed = sqlToolInput.safeParse(input);
|
|
215
|
+
return parsed.success ? parsed.data.sql : void 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// packages/text2sql/src/lib/synthesis/extractors/base-contextual-extractor.ts
|
|
219
|
+
var contextResolverSchema = z2.object({
|
|
220
|
+
question: z2.string().describe(
|
|
211
221
|
"A standalone natural language question that the SQL query answers"
|
|
212
222
|
)
|
|
213
223
|
});
|
|
@@ -320,8 +330,8 @@ var BaseContextualExtractor = class extends PairProducer {
|
|
|
320
330
|
if (getToolName(part) !== toolName) {
|
|
321
331
|
continue;
|
|
322
332
|
}
|
|
323
|
-
const
|
|
324
|
-
if (!
|
|
333
|
+
const sql = toolInputSql("input" in part ? part.input : void 0);
|
|
334
|
+
if (!sql) {
|
|
325
335
|
continue;
|
|
326
336
|
}
|
|
327
337
|
const success = part.state === "output-available";
|
|
@@ -337,7 +347,7 @@ var BaseContextualExtractor = class extends PairProducer {
|
|
|
337
347
|
continue;
|
|
338
348
|
}
|
|
339
349
|
this.results.push({
|
|
340
|
-
sql
|
|
350
|
+
sql,
|
|
341
351
|
success,
|
|
342
352
|
conversationContext: snapshot
|
|
343
353
|
});
|
|
@@ -402,8 +412,8 @@ var MessageExtractor = class extends PairProducer {
|
|
|
402
412
|
if (getToolName2(part) !== toolName) {
|
|
403
413
|
continue;
|
|
404
414
|
}
|
|
405
|
-
const
|
|
406
|
-
if (!
|
|
415
|
+
const sql = toolInputSql("input" in part ? part.input : void 0);
|
|
416
|
+
if (!sql) {
|
|
407
417
|
continue;
|
|
408
418
|
}
|
|
409
419
|
const success = part.state === "output-available";
|
|
@@ -421,7 +431,7 @@ var MessageExtractor = class extends PairProducer {
|
|
|
421
431
|
yield [
|
|
422
432
|
{
|
|
423
433
|
question,
|
|
424
|
-
sql
|
|
434
|
+
sql,
|
|
425
435
|
success
|
|
426
436
|
}
|
|
427
437
|
];
|
|
@@ -434,7 +444,7 @@ var MessageExtractor = class extends PairProducer {
|
|
|
434
444
|
// packages/text2sql/src/lib/synthesis/extractors/sql-extractor.ts
|
|
435
445
|
import { groq as groq2 } from "@ai-sdk/groq";
|
|
436
446
|
import dedent2 from "dedent";
|
|
437
|
-
import
|
|
447
|
+
import z3 from "zod";
|
|
438
448
|
import {
|
|
439
449
|
ContextEngine as ContextEngine2,
|
|
440
450
|
InMemoryContextStore as InMemoryContextStore2,
|
|
@@ -443,8 +453,8 @@ import {
|
|
|
443
453
|
structuredOutput as structuredOutput2,
|
|
444
454
|
user as user2
|
|
445
455
|
} from "@deepagents/context";
|
|
446
|
-
var outputSchema =
|
|
447
|
-
question:
|
|
456
|
+
var outputSchema = z3.object({
|
|
457
|
+
question: z3.string().describe("A natural language question that the SQL query answers")
|
|
448
458
|
});
|
|
449
459
|
var SqlExtractor = class extends PairProducer {
|
|
450
460
|
#sqls;
|
|
@@ -579,7 +589,7 @@ var WindowedContextExtractor = class extends BaseContextualExtractor {
|
|
|
579
589
|
// packages/text2sql/src/lib/synthesis/extractors/segmented-context-extractor.ts
|
|
580
590
|
import { groq as groq3 } from "@ai-sdk/groq";
|
|
581
591
|
import dedent3 from "dedent";
|
|
582
|
-
import
|
|
592
|
+
import z4 from "zod";
|
|
583
593
|
import {
|
|
584
594
|
ContextEngine as ContextEngine3,
|
|
585
595
|
InMemoryContextStore as InMemoryContextStore3,
|
|
@@ -588,9 +598,9 @@ import {
|
|
|
588
598
|
structuredOutput as structuredOutput3,
|
|
589
599
|
user as user3
|
|
590
600
|
} from "@deepagents/context";
|
|
591
|
-
var topicChangeSchema =
|
|
592
|
-
isTopicChange:
|
|
593
|
-
reason:
|
|
601
|
+
var topicChangeSchema = z4.object({
|
|
602
|
+
isTopicChange: z4.boolean().describe("Whether the new message represents a topic change"),
|
|
603
|
+
reason: z4.string().describe("Brief explanation for the decision")
|
|
594
604
|
});
|
|
595
605
|
async function detectTopicChange(params) {
|
|
596
606
|
const context = new ContextEngine3({
|
|
@@ -740,7 +750,7 @@ var LastQueryExtractor = class extends BaseContextualExtractor {
|
|
|
740
750
|
import { groq as groq4 } from "@ai-sdk/groq";
|
|
741
751
|
import dedent4 from "dedent";
|
|
742
752
|
import pLimit from "p-limit";
|
|
743
|
-
import
|
|
753
|
+
import z5 from "zod";
|
|
744
754
|
import "@deepagents/agent";
|
|
745
755
|
import {
|
|
746
756
|
ContextEngine as ContextEngine4,
|
|
@@ -786,9 +796,9 @@ var styleInstructions = {
|
|
|
786
796
|
};
|
|
787
797
|
|
|
788
798
|
// packages/text2sql/src/lib/synthesis/synthesizers/breadth-evolver.ts
|
|
789
|
-
var paraphraserOutputSchema =
|
|
790
|
-
paraphrases:
|
|
791
|
-
|
|
799
|
+
var paraphraserOutputSchema = z5.object({
|
|
800
|
+
paraphrases: z5.array(
|
|
801
|
+
z5.string().describe("A paraphrased version of the original question")
|
|
792
802
|
).min(1).describe("List of paraphrased questions that would produce the same SQL")
|
|
793
803
|
});
|
|
794
804
|
async function paraphraseQuestion(params) {
|
|
@@ -865,33 +875,33 @@ async function paraphraseQuestion(params) {
|
|
|
865
875
|
return paraphraserOutput.generate();
|
|
866
876
|
}
|
|
867
877
|
var BreadthEvolver = class extends PairProducer {
|
|
878
|
+
#source;
|
|
879
|
+
#options;
|
|
880
|
+
#limit;
|
|
868
881
|
/**
|
|
869
882
|
* @param source - Source pairs or producer to evolve
|
|
870
883
|
* @param options - Evolution options including count, persona, and concurrency
|
|
871
884
|
*/
|
|
872
885
|
constructor(source, options) {
|
|
873
886
|
super();
|
|
874
|
-
this
|
|
875
|
-
this
|
|
876
|
-
this.#limit = pLimit(this
|
|
887
|
+
this.#source = source;
|
|
888
|
+
this.#options = options;
|
|
889
|
+
this.#limit = pLimit(this.#options.concurrency ?? 4);
|
|
877
890
|
}
|
|
878
|
-
source;
|
|
879
|
-
options;
|
|
880
|
-
#limit;
|
|
881
891
|
/**
|
|
882
892
|
* Batch pairs within each chunk for concurrent processing.
|
|
883
893
|
* Uses pLimit for concurrency control, yields results per pair after chunk completes.
|
|
884
894
|
*/
|
|
885
895
|
async *produce() {
|
|
886
|
-
for await (const chunk of this.from(this
|
|
896
|
+
for await (const chunk of this.from(this.#source)) {
|
|
887
897
|
const tasks = chunk.map(
|
|
888
898
|
(pair) => this.#limit(async () => {
|
|
889
899
|
const result = await paraphraseQuestion({
|
|
890
900
|
question: pair.question,
|
|
891
901
|
sql: pair.sql,
|
|
892
|
-
count: this
|
|
893
|
-
persona: this
|
|
894
|
-
model: this
|
|
902
|
+
count: this.#options.count,
|
|
903
|
+
persona: this.#options.persona,
|
|
904
|
+
model: this.#options.model
|
|
895
905
|
});
|
|
896
906
|
return result.paraphrases.map((paraphrase) => ({
|
|
897
907
|
question: paraphrase,
|
|
@@ -913,7 +923,7 @@ import { NoObjectGeneratedError as NoObjectGeneratedError2, NoOutputGeneratedErr
|
|
|
913
923
|
import dedent6 from "dedent";
|
|
914
924
|
import pLimit2 from "p-limit";
|
|
915
925
|
import pRetry2 from "p-retry";
|
|
916
|
-
import
|
|
926
|
+
import z7 from "zod";
|
|
917
927
|
import "@deepagents/agent";
|
|
918
928
|
import {
|
|
919
929
|
ContextEngine as ContextEngine6,
|
|
@@ -993,7 +1003,7 @@ import {
|
|
|
993
1003
|
} from "ai";
|
|
994
1004
|
import dedent5 from "dedent";
|
|
995
1005
|
import pRetry from "p-retry";
|
|
996
|
-
import
|
|
1006
|
+
import z6 from "zod";
|
|
997
1007
|
import "@deepagents/agent";
|
|
998
1008
|
import {
|
|
999
1009
|
ContextEngine as ContextEngine5,
|
|
@@ -1285,14 +1295,14 @@ Question: ${options.input}
|
|
|
1285
1295
|
const sqlOutput = structuredOutput5({
|
|
1286
1296
|
model,
|
|
1287
1297
|
context,
|
|
1288
|
-
schema:
|
|
1289
|
-
result:
|
|
1290
|
-
|
|
1291
|
-
sql:
|
|
1292
|
-
reasoning:
|
|
1298
|
+
schema: z6.object({
|
|
1299
|
+
result: z6.union([
|
|
1300
|
+
z6.object({
|
|
1301
|
+
sql: z6.string().describe("The SQL query that answers the question"),
|
|
1302
|
+
reasoning: z6.string().describe("The reasoning steps taken to generate the SQL")
|
|
1293
1303
|
}),
|
|
1294
|
-
|
|
1295
|
-
error:
|
|
1304
|
+
z6.object({
|
|
1305
|
+
error: z6.string().describe(
|
|
1296
1306
|
"Error message explaining why the question cannot be answered with the given schema"
|
|
1297
1307
|
)
|
|
1298
1308
|
})
|
|
@@ -1343,11 +1353,11 @@ Question: ${options.input}
|
|
|
1343
1353
|
const forcedSqlOutput = structuredOutput5({
|
|
1344
1354
|
model,
|
|
1345
1355
|
context,
|
|
1346
|
-
schema:
|
|
1347
|
-
sql:
|
|
1356
|
+
schema: z6.object({
|
|
1357
|
+
sql: z6.string().describe(
|
|
1348
1358
|
"Best-effort SQL query that answers the core intent using only available schema entities."
|
|
1349
1359
|
),
|
|
1350
|
-
reasoning:
|
|
1360
|
+
reasoning: z6.string().describe("Reasoning steps for best-effort schema mapping.")
|
|
1351
1361
|
})
|
|
1352
1362
|
});
|
|
1353
1363
|
try {
|
|
@@ -1472,8 +1482,8 @@ var techniqueInstructions = {
|
|
|
1472
1482
|
- "Get costs" → "What would be the impact of a 10% discount on profit margins?"
|
|
1473
1483
|
`
|
|
1474
1484
|
};
|
|
1475
|
-
var evolverOutputSchema =
|
|
1476
|
-
evolvedQuestion:
|
|
1485
|
+
var evolverOutputSchema = z7.object({
|
|
1486
|
+
evolvedQuestion: z7.string().describe("The evolved, more complex version of the original question")
|
|
1477
1487
|
});
|
|
1478
1488
|
async function evolveQuestion(params) {
|
|
1479
1489
|
const context = new ContextEngine6({
|
|
@@ -1542,6 +1552,10 @@ var ALL_TECHNIQUES = [
|
|
|
1542
1552
|
"hypothetical"
|
|
1543
1553
|
];
|
|
1544
1554
|
var DepthEvolver = class extends PairProducer {
|
|
1555
|
+
#source;
|
|
1556
|
+
#adapter;
|
|
1557
|
+
#options;
|
|
1558
|
+
#limit;
|
|
1545
1559
|
/**
|
|
1546
1560
|
* @param source - Source pairs or producer to evolve
|
|
1547
1561
|
* @param adapter - Database adapter for SQL generation
|
|
@@ -1549,28 +1563,24 @@ var DepthEvolver = class extends PairProducer {
|
|
|
1549
1563
|
*/
|
|
1550
1564
|
constructor(source, adapter, options) {
|
|
1551
1565
|
super();
|
|
1552
|
-
this
|
|
1553
|
-
this
|
|
1554
|
-
this
|
|
1555
|
-
this.#limit = pLimit2(this
|
|
1566
|
+
this.#source = source;
|
|
1567
|
+
this.#adapter = adapter;
|
|
1568
|
+
this.#options = options;
|
|
1569
|
+
this.#limit = pLimit2(this.#options?.concurrency ?? 4);
|
|
1556
1570
|
}
|
|
1557
|
-
source;
|
|
1558
|
-
adapter;
|
|
1559
|
-
options;
|
|
1560
|
-
#limit;
|
|
1561
1571
|
/**
|
|
1562
1572
|
* Yields evolved pairs as each completes (streaming pattern).
|
|
1563
1573
|
* Removes batch barrier - no longer waits for all evolutions before yielding.
|
|
1564
1574
|
*/
|
|
1565
1575
|
async *produce() {
|
|
1566
1576
|
const introspection = "";
|
|
1567
|
-
const count = this
|
|
1568
|
-
const techniques = this
|
|
1577
|
+
const count = this.#options?.count ?? 1;
|
|
1578
|
+
const techniques = this.#options?.techniques ?? ALL_TECHNIQUES;
|
|
1569
1579
|
let pairIndex = 0;
|
|
1570
|
-
for await (const chunk of this.from(this
|
|
1580
|
+
for await (const chunk of this.from(this.#source)) {
|
|
1571
1581
|
for (const pair of chunk) {
|
|
1572
1582
|
const tasks = Array.from({ length: count }, (_, i) => {
|
|
1573
|
-
const technique = this
|
|
1583
|
+
const technique = this.#options?.techniques ? techniques[i % techniques.length] : techniques[(pairIndex * count + i) % techniques.length];
|
|
1574
1584
|
return this.#limit(
|
|
1575
1585
|
() => this.#processTask(pair, technique, introspection)
|
|
1576
1586
|
);
|
|
@@ -1589,16 +1599,16 @@ var DepthEvolver = class extends PairProducer {
|
|
|
1589
1599
|
schema: introspection,
|
|
1590
1600
|
technique,
|
|
1591
1601
|
techniqueInstruction: techniqueInstructions[technique],
|
|
1592
|
-
model: this
|
|
1602
|
+
model: this.#options?.model
|
|
1593
1603
|
})
|
|
1594
1604
|
);
|
|
1595
1605
|
const evolvedQuestion = output.evolvedQuestion;
|
|
1596
1606
|
try {
|
|
1597
1607
|
const sqlResult = await toSql({
|
|
1598
1608
|
input: evolvedQuestion,
|
|
1599
|
-
adapter: this
|
|
1609
|
+
adapter: this.#adapter,
|
|
1600
1610
|
fragments: [],
|
|
1601
|
-
model: this
|
|
1611
|
+
model: this.#options?.model
|
|
1602
1612
|
});
|
|
1603
1613
|
return {
|
|
1604
1614
|
question: evolvedQuestion,
|
|
@@ -1648,7 +1658,7 @@ async function withRetry2(computation) {
|
|
|
1648
1658
|
// packages/text2sql/src/lib/synthesis/synthesizers/persona-generator.ts
|
|
1649
1659
|
import { groq as groq7 } from "@ai-sdk/groq";
|
|
1650
1660
|
import dedent7 from "dedent";
|
|
1651
|
-
import
|
|
1661
|
+
import z8 from "zod";
|
|
1652
1662
|
import "@deepagents/agent";
|
|
1653
1663
|
import {
|
|
1654
1664
|
ContextEngine as ContextEngine7,
|
|
@@ -1660,14 +1670,14 @@ import {
|
|
|
1660
1670
|
structuredOutput as structuredOutput7,
|
|
1661
1671
|
user as user7
|
|
1662
1672
|
} from "@deepagents/context";
|
|
1663
|
-
var outputSchema2 =
|
|
1664
|
-
personas:
|
|
1665
|
-
|
|
1666
|
-
role:
|
|
1667
|
-
perspective:
|
|
1673
|
+
var outputSchema2 = z8.object({
|
|
1674
|
+
personas: z8.array(
|
|
1675
|
+
z8.object({
|
|
1676
|
+
role: z8.string().describe("The job title or role of this persona"),
|
|
1677
|
+
perspective: z8.string().describe(
|
|
1668
1678
|
"Rich description of what this persona cares about when querying the database"
|
|
1669
1679
|
),
|
|
1670
|
-
styles:
|
|
1680
|
+
styles: z8.array(z8.enum(ALL_STYLES)).min(1).max(3).describe(
|
|
1671
1681
|
"Typical communication styles for this persona (1-3 styles)"
|
|
1672
1682
|
)
|
|
1673
1683
|
})
|
|
@@ -1767,7 +1777,7 @@ import pLimit3 from "p-limit";
|
|
|
1767
1777
|
// packages/text2sql/src/lib/agents/question.agent.ts
|
|
1768
1778
|
import { groq as groq8 } from "@ai-sdk/groq";
|
|
1769
1779
|
import dedent8 from "dedent";
|
|
1770
|
-
import
|
|
1780
|
+
import z9 from "zod";
|
|
1771
1781
|
import "@deepagents/agent";
|
|
1772
1782
|
import {
|
|
1773
1783
|
ContextEngine as ContextEngine8,
|
|
@@ -1816,8 +1826,8 @@ var complexityInstructions = {
|
|
|
1816
1826
|
Examples: "What is the running total of sales per month?", "Rank customers by their purchase frequency within each region"
|
|
1817
1827
|
`
|
|
1818
1828
|
};
|
|
1819
|
-
var outputSchema3 =
|
|
1820
|
-
questions:
|
|
1829
|
+
var outputSchema3 = z9.object({
|
|
1830
|
+
questions: z9.array(z9.string().describe("A natural language question about the data")).min(1).describe("List of natural language questions a user might ask")
|
|
1821
1831
|
});
|
|
1822
1832
|
async function generateQuestions(params) {
|
|
1823
1833
|
const { introspection, complexity, count, prompt, model } = params;
|
|
@@ -1878,23 +1888,23 @@ async function generateQuestions(params) {
|
|
|
1878
1888
|
|
|
1879
1889
|
// packages/text2sql/src/lib/synthesis/synthesizers/schema-synthesizer.ts
|
|
1880
1890
|
var SchemaSynthesizer = class extends PairProducer {
|
|
1891
|
+
#adapter;
|
|
1892
|
+
#options;
|
|
1893
|
+
#complexities = [];
|
|
1894
|
+
#personas = [];
|
|
1895
|
+
#limit;
|
|
1881
1896
|
/**
|
|
1882
1897
|
* @param adapter - Database adapter for schema introspection and SQL validation
|
|
1883
1898
|
* @param options - Synthesis configuration including count, complexity, and concurrency
|
|
1884
1899
|
*/
|
|
1885
1900
|
constructor(adapter, options) {
|
|
1886
1901
|
super();
|
|
1887
|
-
this
|
|
1888
|
-
this
|
|
1889
|
-
this.#complexities = Array.isArray(this
|
|
1890
|
-
this.#personas = this
|
|
1891
|
-
this.#limit = pLimit3(this
|
|
1902
|
+
this.#adapter = adapter;
|
|
1903
|
+
this.#options = options;
|
|
1904
|
+
this.#complexities = Array.isArray(this.#options.complexity) ? this.#options.complexity : [this.#options.complexity ?? "moderate"];
|
|
1905
|
+
this.#personas = this.#options.personas ?? [void 0];
|
|
1906
|
+
this.#limit = pLimit3(this.#options.concurrency ?? 5);
|
|
1892
1907
|
}
|
|
1893
|
-
adapter;
|
|
1894
|
-
options;
|
|
1895
|
-
#complexities = [];
|
|
1896
|
-
#personas = [];
|
|
1897
|
-
#limit;
|
|
1898
1908
|
/**
|
|
1899
1909
|
* Generates question-SQL pairs by iterating through all persona × complexity combinations.
|
|
1900
1910
|
* Uses parallel processing bounded by the configured concurrency limit.
|
|
@@ -1927,14 +1937,14 @@ var SchemaSynthesizer = class extends PairProducer {
|
|
|
1927
1937
|
Generate questions this persona would ask.` : void 0;
|
|
1928
1938
|
const prompt = personaContext ? `${personaContext}
|
|
1929
1939
|
|
|
1930
|
-
Generate ${this
|
|
1940
|
+
Generate ${this.#options.count} questions at ${complexity} complexity.` : void 0;
|
|
1931
1941
|
const { questions } = await this.#limit(
|
|
1932
1942
|
() => generateQuestions({
|
|
1933
1943
|
introspection,
|
|
1934
1944
|
complexity,
|
|
1935
|
-
count: this
|
|
1945
|
+
count: this.#options.count,
|
|
1936
1946
|
prompt,
|
|
1937
|
-
model: this
|
|
1947
|
+
model: this.#options.model
|
|
1938
1948
|
})
|
|
1939
1949
|
);
|
|
1940
1950
|
const pairs = await Promise.all(
|
|
@@ -1943,9 +1953,9 @@ Generate ${this.options.count} questions at ${complexity} complexity.` : void 0;
|
|
|
1943
1953
|
try {
|
|
1944
1954
|
return await toSql({
|
|
1945
1955
|
input: question,
|
|
1946
|
-
adapter: this
|
|
1947
|
-
fragments: this
|
|
1948
|
-
model: this
|
|
1956
|
+
adapter: this.#adapter,
|
|
1957
|
+
fragments: this.#options.teachings ?? [],
|
|
1958
|
+
model: this.#options.model
|
|
1949
1959
|
});
|
|
1950
1960
|
} catch (error) {
|
|
1951
1961
|
if (UnanswerableSQLError.isInstance(error)) {
|