@deepagents/text2sql 7.5.1 → 7.6.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.
Files changed (42) hide show
  1. package/README.md +7 -5
  2. package/dist/bin/sql.js +12 -10
  3. package/dist/finetune/run-finetune.d.ts +0 -21
  4. package/dist/finetune/run-finetune.d.ts.map +1 -1
  5. package/dist/finetune/run-mlx.d.ts +0 -20
  6. package/dist/finetune/run-mlx.d.ts.map +1 -1
  7. package/dist/index.js +21 -21
  8. package/dist/index.js.map +3 -3
  9. package/dist/lib/adapter-index.d.ts.map +1 -1
  10. package/dist/lib/adapters/bigquery/bigquery.d.ts.map +1 -1
  11. package/dist/lib/adapters/bigquery/index.js +4 -4
  12. package/dist/lib/adapters/bigquery/index.js.map +2 -2
  13. package/dist/lib/adapters/clickhouse/index.js +2 -2
  14. package/dist/lib/adapters/clickhouse/index.js.map +2 -2
  15. package/dist/lib/adapters/duckdb/index.js +2 -2
  16. package/dist/lib/adapters/duckdb/index.js.map +2 -2
  17. package/dist/lib/adapters/mysql/index.js +2 -2
  18. package/dist/lib/adapters/mysql/index.js.map +2 -2
  19. package/dist/lib/adapters/mysql/mysql.d.ts.map +1 -1
  20. package/dist/lib/adapters/postgres/index.js +3 -3
  21. package/dist/lib/adapters/postgres/index.js.map +2 -2
  22. package/dist/lib/adapters/postgres/postgres.d.ts.map +1 -1
  23. package/dist/lib/adapters/posthog/index.js +1 -1
  24. package/dist/lib/adapters/posthog/index.js.map +2 -2
  25. package/dist/lib/adapters/spreadsheet/index.js +6 -4
  26. package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
  27. package/dist/lib/adapters/spreadsheet/parser.d.ts.map +1 -1
  28. package/dist/lib/adapters/sqlite/constraint.sqlite.grounding.d.ts.map +1 -1
  29. package/dist/lib/adapters/sqlite/index.js +3 -8
  30. package/dist/lib/adapters/sqlite/index.js.map +2 -2
  31. package/dist/lib/adapters/sqlite/sqlite.d.ts.map +1 -1
  32. package/dist/lib/adapters/sqlserver/index.js +2 -2
  33. package/dist/lib/adapters/sqlserver/index.js.map +2 -2
  34. package/dist/lib/adapters/sqlserver/sqlserver.d.ts.map +1 -1
  35. package/dist/lib/agents/sql-transform-plugins.d.ts.map +1 -1
  36. package/dist/lib/agents/sql.agent.d.ts.map +1 -1
  37. package/dist/lib/fragments/schema.d.ts.map +1 -1
  38. package/dist/lib/sql-scope-error.d.ts.map +1 -1
  39. package/dist/lib/synthesis/extractors/windowed-context-extractor.d.ts.map +1 -1
  40. package/dist/lib/synthesis/index.js +2 -2
  41. package/dist/lib/synthesis/index.js.map +2 -2
  42. package/package.json +16 -16
package/README.md CHANGED
@@ -167,12 +167,14 @@ const sandbox = await createBashTool({
167
167
  ...createSqlCommandHooks({ adapters: { main: adapter } }),
168
168
  });
169
169
 
170
- const indexResult = await sandbox.sandbox.executeCommand('sql index');
170
+ const indexResult = await sandbox.sandbox.run({ command: 'sql index' });
171
171
  if (indexResult.exitCode !== 0) throw new Error(indexResult.stderr);
172
172
  const manifest = JSON.parse(indexResult.stdout) as { fragmentsPath: string };
173
- const fragments = JSON.parse(
174
- await sandbox.sandbox.readFile(manifest.fragmentsPath),
175
- ) as ContextFragment[];
173
+ const fragmentsText = await sandbox.sandbox.readTextFile({
174
+ path: manifest.fragmentsPath,
175
+ });
176
+ if (fragmentsText === null) throw new Error('sql index wrote no fragments');
177
+ const fragments = JSON.parse(fragmentsText) as ContextFragment[];
176
178
  context.set(...instructions(), ...fragments);
177
179
  context.set(sqlValidateReminder());
178
180
 
@@ -278,7 +280,7 @@ const sandbox = await createVirtualSandbox({
278
280
  customCommands: [sqlCommand.command],
279
281
  });
280
282
 
281
- await sandbox.executeCommand('sql validate main "SELECT 1"');
283
+ await sandbox.run({ command: 'sql validate main "SELECT 1"' });
282
284
  ```
283
285
 
284
286
  `CreateSqlCommandOptions` configures command defaults (currently `outputDir`).
package/dist/bin/sql.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
 
12
12
  // packages/text2sql/src/lib/file-cache.ts
13
13
  import { atomicWrite } from "@zukhruf/fs";
14
- import { createHash } from "node:crypto";
14
+ import { hash } from "node:crypto";
15
15
  import { existsSync } from "node:fs";
16
16
  import { mkdir, readFile } from "node:fs/promises";
17
17
  import { tmpdir } from "node:os";
@@ -20,8 +20,8 @@ var FileCache = class {
20
20
  path;
21
21
  #clock;
22
22
  constructor(watermark, { clock, extension = ".txt", baseDir = tmpdir() }) {
23
- const hash = createHash("md5").update(watermark).digest("hex");
24
- this.path = path.join(baseDir, `text2sql-${hash}${extension}`);
23
+ const digest = hash("md5", watermark);
24
+ this.path = path.join(baseDir, `text2sql-${digest}${extension}`);
25
25
  this.#clock = clock;
26
26
  }
27
27
  async get() {
@@ -242,7 +242,7 @@ var AdapterIndexer = class {
242
242
  if (failed) {
243
243
  progress({
244
244
  type: "index:error",
245
- message: failed.reason instanceof Error ? failed.reason.message : String(failed.reason)
245
+ message: Error.isError(failed.reason) ? failed.reason.message : String(failed.reason)
246
246
  });
247
247
  throw failed.reason;
248
248
  }
@@ -355,7 +355,7 @@ function adapterProgressEvent(adapter, progress) {
355
355
  };
356
356
  }
357
357
  function errorMessage(error) {
358
- return error instanceof Error ? error.message : String(error);
358
+ return Error.isError(error) ? error.message : String(error);
359
359
  }
360
360
 
361
361
  // packages/text2sql/src/lib/sql.ts
@@ -523,7 +523,7 @@ function renderCommandError(error, stderr) {
523
523
  `);
524
524
  }
525
525
  function errorMessage2(error) {
526
- return error instanceof Error ? error.message : String(error);
526
+ return Error.isError(error) ? error.message : String(error);
527
527
  }
528
528
  var SqlCommand = class {
529
529
  options = [];
@@ -716,7 +716,7 @@ async function probeFifoWriter(eventsPath, stderr) {
716
716
  }
717
717
  }
718
718
  function hasErrorCode(error, code) {
719
- return error instanceof Error && "code" in error && error.code === code;
719
+ return Error.isError(error) && "code" in error && error.code === code;
720
720
  }
721
721
  function waitForOpen(stream) {
722
722
  return new Promise((resolve4, reject) => {
@@ -830,7 +830,9 @@ async function loadAdapters() {
830
830
  try {
831
831
  validateAdapterNames(entries.map(([name]) => name));
832
832
  } catch (cause) {
833
- throw new Error(`TEXT2SQL_ADAPTERS=${target}: ${errorMessage2(cause)}`);
833
+ throw new Error(`TEXT2SQL_ADAPTERS=${target}: ${errorMessage2(cause)}`, {
834
+ cause
835
+ });
834
836
  }
835
837
  return adapters;
836
838
  }
@@ -936,7 +938,7 @@ function rewriteCommandsHelp(body) {
936
938
  }, body);
937
939
  }
938
940
  function writeCliError(error) {
939
- if (error instanceof Error && error.name === "CACError") {
941
+ if (Error.isError(error) && error.name === "CACError") {
940
942
  process.stderr.write(`sql: ${error.message}
941
943
  `);
942
944
  cli.outputHelp();
@@ -947,7 +949,7 @@ function writeCliError(error) {
947
949
  return error.exitCode;
948
950
  }
949
951
  process.stderr.write(
950
- `sql: unexpected error: ${error instanceof Error ? error.stack ?? error.message : String(error)}
952
+ `sql: unexpected error: ${Error.isError(error) ? error.stack ?? error.message : String(error)}
951
953
  `
952
954
  );
953
955
  return 1;
@@ -1,23 +1,2 @@
1
- /**
2
- * TypeScript runner for the Python fine-tuning script.
3
- * Uses an isolated virtual environment - no global Python pollution.
4
- *
5
- * Usage:
6
- * npx tsx packages/text2sql/src/finetune/run-finetune.ts [options]
7
- *
8
- * Options:
9
- * --epochs <n> Number of training epochs (default: 3)
10
- * --batch-size <n> Per-device batch size (default: 4)
11
- * --lr <rate> Learning rate (default: 1e-4)
12
- * --output-dir <dir> Output directory (default: ./.finetune/qwen3-sql)
13
- * --max-samples <n> Limit training samples
14
- * --use-hf Use HuggingFace dataset instead of local
15
- * --model <name> Base model (default: Qwen/Qwen3-0.6B)
16
- * --no-gguf Disable automatic GGUF conversion
17
- * --gguf-type <type> GGUF quantization type (default: q8_0)
18
- *
19
- * Prerequisites:
20
- * brew install llama.cpp # Required for GGUF conversion
21
- */
22
1
  export {};
23
2
  //# sourceMappingURL=run-finetune.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-finetune.d.ts","sourceRoot":"","sources":["../../src/finetune/run-finetune.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG"}
1
+ {"version":3,"file":"run-finetune.d.ts","sourceRoot":"","sources":["../../src/finetune/run-finetune.ts"],"names":[],"mappings":""}
@@ -1,22 +1,2 @@
1
- /**
2
- * TypeScript runner for the MLX fine-tuning script.
3
- * Uses an isolated virtual environment - no global Python pollution.
4
- *
5
- * Native Apple Silicon support (M1/M2/M3/M4).
6
- *
7
- * Usage:
8
- * node packages/text2sql/src/finetune/run-mlx.ts [options]
9
- *
10
- * Options:
11
- * --iters <n> Number of training iterations (default: 1000)
12
- * --batch-size <n> Batch size (default: 4)
13
- * --lr <rate> Learning rate (default: 1e-5)
14
- * --output-dir <dir> Output directory (default: ./qwen3-sql-mlx)
15
- * --max-samples <n> Limit training samples
16
- * --use-hf Use HuggingFace dataset instead of local
17
- * --model <name> Base model (default: Qwen/Qwen3-0.5B)
18
- * --num-layers <n> Number of LoRA layers (default: 16)
19
- * --no-gguf Disable GGUF export
20
- */
21
1
  export {};
22
2
  //# sourceMappingURL=run-mlx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-mlx.d.ts","sourceRoot":"","sources":["../../src/finetune/run-mlx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
1
+ {"version":3,"file":"run-mlx.d.ts","sourceRoot":"","sources":["../../src/finetune/run-mlx.ts"],"names":[],"mappings":""}
package/dist/index.js CHANGED
@@ -645,7 +645,7 @@ import {
645
645
 
646
646
  // packages/text2sql/src/lib/sql-scope-error.ts
647
647
  function buildScopeParseErrorPayload(sql, parserDialect, error) {
648
- const parserError = error instanceof Error ? error.message : String(error ?? "Unknown error");
648
+ const parserError = Error.isError(error) ? error.message : String(error ?? "Unknown error");
649
649
  return {
650
650
  error: `SQL scope analysis failed before validation/execution: ${parserError}`,
651
651
  error_type: "SQL_SCOPE_PARSE_ERROR",
@@ -910,7 +910,7 @@ Question: ${options.input}
910
910
  `)
911
911
  );
912
912
  }
913
- const temperature = RETRY_TEMPERATURES[attemptNumber - 1] ?? RETRY_TEMPERATURES[RETRY_TEMPERATURES.length - 1];
913
+ const temperature = RETRY_TEMPERATURES[attemptNumber - 1] ?? RETRY_TEMPERATURES.at(-1);
914
914
  const baseModel = options.model ?? groq("openai/gpt-oss-20b");
915
915
  const model = wrapLanguageModel({
916
916
  model: baseModel,
@@ -1126,7 +1126,7 @@ import {
1126
1126
 
1127
1127
  // packages/text2sql/src/lib/file-cache.ts
1128
1128
  import { atomicWrite } from "@zukhruf/fs";
1129
- import { createHash } from "node:crypto";
1129
+ import { hash } from "node:crypto";
1130
1130
  import { existsSync } from "node:fs";
1131
1131
  import { mkdir, readFile } from "node:fs/promises";
1132
1132
  import { tmpdir } from "node:os";
@@ -1135,8 +1135,8 @@ var FileCache = class {
1135
1135
  path;
1136
1136
  #clock;
1137
1137
  constructor(watermark, { clock, extension = ".txt", baseDir = tmpdir() }) {
1138
- const hash2 = createHash("md5").update(watermark).digest("hex");
1139
- this.path = path.join(baseDir, `text2sql-${hash2}${extension}`);
1138
+ const digest = hash("md5", watermark);
1139
+ this.path = path.join(baseDir, `text2sql-${digest}${extension}`);
1140
1140
  this.#clock = clock;
1141
1141
  }
1142
1142
  async get() {
@@ -1252,7 +1252,7 @@ var AdapterIndexer = class {
1252
1252
  if (failed) {
1253
1253
  progress({
1254
1254
  type: "index:error",
1255
- message: failed.reason instanceof Error ? failed.reason.message : String(failed.reason)
1255
+ message: Error.isError(failed.reason) ? failed.reason.message : String(failed.reason)
1256
1256
  });
1257
1257
  throw failed.reason;
1258
1258
  }
@@ -1365,12 +1365,12 @@ function adapterProgressEvent(adapter, progress) {
1365
1365
  };
1366
1366
  }
1367
1367
  function errorMessage(error) {
1368
- return error instanceof Error ? error.message : String(error);
1368
+ return Error.isError(error) ? error.message : String(error);
1369
1369
  }
1370
1370
 
1371
1371
  // packages/text2sql/src/lib/checkpoint.ts
1372
1372
  import { durableWrite } from "@zukhruf/fs";
1373
- import { createHash as createHash2 } from "node:crypto";
1373
+ import { hash as hash2 } from "node:crypto";
1374
1374
  import { existsSync as existsSync2, readFileSync } from "node:fs";
1375
1375
  import pLimit from "p-limit";
1376
1376
  import z4 from "zod";
@@ -1513,8 +1513,8 @@ var Checkpoint = class _Checkpoint {
1513
1513
  });
1514
1514
  }
1515
1515
  };
1516
- function hash(value) {
1517
- return createHash2("md5").update(JSON.stringify(value)).digest("hex");
1516
+ function jsonDigest(value) {
1517
+ return hash2("md5", JSON.stringify(value));
1518
1518
  }
1519
1519
  var Point = class {
1520
1520
  #stored;
@@ -1533,7 +1533,7 @@ var Point = class {
1533
1533
  * executes, saves the encoded output, and returns the computed value.
1534
1534
  */
1535
1535
  async through(input, compute) {
1536
- const inputHash = hash(input);
1536
+ const inputHash = jsonDigest(input);
1537
1537
  if (this.#stored.has(inputHash)) {
1538
1538
  return this.codec.decode(this.#stored.get(inputHash));
1539
1539
  }
@@ -1559,7 +1559,7 @@ var Point = class {
1559
1559
  }
1560
1560
  };
1561
1561
  function hashConfig(config) {
1562
- return createHash2("md5").update(JSON.stringify(config)).digest("hex");
1562
+ return hash2("md5", JSON.stringify(config));
1563
1563
  }
1564
1564
 
1565
1565
  // packages/text2sql/src/lib/fs/sqlite/sqlite-fs.ts
@@ -2090,7 +2090,7 @@ var SqliteFs = class {
2090
2090
  const allEntries = z6.array(entryRow).parse(
2091
2091
  this.#sql.all`SELECT * FROM fs_entries WHERE path = ${srcPrefixed} OR path LIKE ${srcPrefixed} || '/%' ORDER BY path DESC`
2092
2092
  );
2093
- for (const entry of [...allEntries].reverse()) {
2093
+ for (const entry of allEntries.toReversed()) {
2094
2094
  const relativePath = path2.posix.relative(srcPrefixed, entry.path);
2095
2095
  const newPath = path2.posix.join(destPrefixed, relativePath);
2096
2096
  this.#sql.run`INSERT INTO fs_entries (path, type, mode, size, mtime, symlinkTarget)
@@ -3051,7 +3051,7 @@ var MssqlFs = class _MssqlFs {
3051
3051
  await destDeleteReq.query(
3052
3052
  `DELETE FROM ${this.#t("fs_entries")} WHERE path = @dp0 OR path LIKE @dp0 + '/%'`
3053
3053
  );
3054
- for (const entry of [...allEntries].reverse()) {
3054
+ for (const entry of allEntries.toReversed()) {
3055
3055
  const relativePath = path3.posix.relative(srcPrefixed, entry.path);
3056
3056
  const newPath = path3.posix.join(destPrefixed, relativePath);
3057
3057
  const insertReq = transaction2.request();
@@ -4028,7 +4028,7 @@ var PostgresFs = class _PostgresFs {
4028
4028
  `DELETE FROM ${this.#t("fs_entries")} WHERE path = $1 OR path LIKE $1 || '/%'`,
4029
4029
  [destPrefixed]
4030
4030
  );
4031
- for (const entry of [...allEntries].reverse()) {
4031
+ for (const entry of allEntries.toReversed()) {
4032
4032
  const relativePath = path4.posix.relative(srcPrefixed, entry.path);
4033
4033
  const newPath = path4.posix.join(destPrefixed, relativePath);
4034
4034
  await client.query(
@@ -4754,7 +4754,7 @@ import { BashTransformPipeline } from "just-bash";
4754
4754
 
4755
4755
  // packages/text2sql/src/lib/agents/sql-transform-plugins.ts
4756
4756
  import { parse as parse2, serialize } from "just-bash";
4757
- import { createHash as createHash3 } from "node:crypto";
4757
+ import { hash as hash3 } from "node:crypto";
4758
4758
  import * as path5 from "node:path";
4759
4759
  import {
4760
4760
  BashException,
@@ -5428,9 +5428,9 @@ function rewriteSqlCommand(cmd, ast) {
5428
5428
  const dbName = asStaticWordText2(cmd.args[1]);
5429
5429
  const sqlArgs = cmd.args.slice(2);
5430
5430
  const unquotedSql = extractSqlText(sqlArgs);
5431
- const hash2 = createHash3("sha256").update(serialize(ast)).digest("hex").slice(0, 12);
5432
- const sqlPath = `/tmp/sql-inline-${subcommand}-${hash2}.sql`;
5433
- const heredocTag = `SQL_${hash2.toUpperCase()}`;
5431
+ const digest = hash3("sha256", serialize(ast)).slice(0, 12);
5432
+ const sqlPath = `/tmp/sql-inline-${subcommand}-${digest}.sql`;
5433
+ const heredocTag = `SQL_${digest.toUpperCase()}`;
5434
5434
  const groupScript = [
5435
5435
  `{ cat > ${sqlPath} <<'${heredocTag}'`,
5436
5436
  unquotedSql,
@@ -5728,7 +5728,7 @@ function parseFlags(subcommand, args) {
5728
5728
  outDir: parsed.values["out-dir"]
5729
5729
  };
5730
5730
  } catch (error) {
5731
- const message = error instanceof Error ? error.message : String(error);
5731
+ const message = Error.isError(error) ? error.message : String(error);
5732
5732
  throw new SqlCommandError(subcommand, message);
5733
5733
  }
5734
5734
  }
@@ -5772,7 +5772,7 @@ async function runHandler(subcommand, fn) {
5772
5772
  if (Text2SqlValidationError.isInstance(error)) {
5773
5773
  return new SqlCommandError(subcommand, error.message).format();
5774
5774
  }
5775
- const message = error instanceof Error ? error.message : String(error);
5775
+ const message = Error.isError(error) ? error.message : String(error);
5776
5776
  return new SqlCommandError(subcommand, message).format();
5777
5777
  }
5778
5778
  }