@deepagents/text2sql 7.5.2 → 7.7.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 (39) hide show
  1. package/README.md +7 -5
  2. package/dist/bin/sql.js +12 -10
  3. package/dist/index.js +38 -34
  4. package/dist/index.js.map +3 -3
  5. package/dist/lib/adapter-index.d.ts.map +1 -1
  6. package/dist/lib/adapters/bigquery/bigquery.d.ts.map +1 -1
  7. package/dist/lib/adapters/bigquery/index.js +4 -4
  8. package/dist/lib/adapters/bigquery/index.js.map +2 -2
  9. package/dist/lib/adapters/clickhouse/index.js +2 -2
  10. package/dist/lib/adapters/clickhouse/index.js.map +2 -2
  11. package/dist/lib/adapters/duckdb/index.js +2 -2
  12. package/dist/lib/adapters/duckdb/index.js.map +2 -2
  13. package/dist/lib/adapters/mysql/index.js +2 -2
  14. package/dist/lib/adapters/mysql/index.js.map +2 -2
  15. package/dist/lib/adapters/mysql/mysql.d.ts.map +1 -1
  16. package/dist/lib/adapters/postgres/index.js +3 -3
  17. package/dist/lib/adapters/postgres/index.js.map +2 -2
  18. package/dist/lib/adapters/postgres/postgres.d.ts.map +1 -1
  19. package/dist/lib/adapters/posthog/index.js +1 -1
  20. package/dist/lib/adapters/posthog/index.js.map +2 -2
  21. package/dist/lib/adapters/spreadsheet/index.js +6 -4
  22. package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
  23. package/dist/lib/adapters/spreadsheet/parser.d.ts.map +1 -1
  24. package/dist/lib/adapters/sqlite/constraint.sqlite.grounding.d.ts.map +1 -1
  25. package/dist/lib/adapters/sqlite/index.js +3 -8
  26. package/dist/lib/adapters/sqlite/index.js.map +2 -2
  27. package/dist/lib/adapters/sqlite/sqlite.d.ts.map +1 -1
  28. package/dist/lib/adapters/sqlserver/index.js +2 -2
  29. package/dist/lib/adapters/sqlserver/index.js.map +2 -2
  30. package/dist/lib/adapters/sqlserver/sqlserver.d.ts.map +1 -1
  31. package/dist/lib/agents/sql-transform-plugins.d.ts.map +1 -1
  32. package/dist/lib/agents/sql.agent.d.ts.map +1 -1
  33. package/dist/lib/checkpoint.d.ts +1 -1
  34. package/dist/lib/checkpoint.d.ts.map +1 -1
  35. package/dist/lib/sql-command.d.ts +1 -1
  36. package/dist/lib/sql-scope-error.d.ts.map +1 -1
  37. package/dist/lib/synthesis/index.js +2 -2
  38. package/dist/lib/synthesis/index.js.map +2 -2
  39. package/package.json +17 -17
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;
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,13 @@ 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
+ import { Lock } from "@zukhruf/async";
1372
1373
  import { durableWrite } from "@zukhruf/fs";
1373
- import { createHash as createHash2 } from "node:crypto";
1374
+ import { hash as hash2 } from "node:crypto";
1374
1375
  import { existsSync as existsSync2, readFileSync } from "node:fs";
1375
1376
  import pLimit from "p-limit";
1376
1377
  import z4 from "zod";
@@ -1392,7 +1393,7 @@ var Checkpoint = class _Checkpoint {
1392
1393
  path;
1393
1394
  configHash;
1394
1395
  #clock;
1395
- #writes = pLimit(1);
1396
+ #writes = new Lock();
1396
1397
  #changes = 0;
1397
1398
  #writtenChanges = 0;
1398
1399
  constructor(path6, configHash, clock, points) {
@@ -1499,22 +1500,25 @@ var Checkpoint = class _Checkpoint {
1499
1500
  */
1500
1501
  save() {
1501
1502
  this.#changes += 1;
1502
- return this.#writes(async () => {
1503
- const changes = this.#changes;
1504
- if (changes === this.#writtenChanges) return;
1505
- const file = {
1506
- configHash: this.configHash,
1507
- points: this.points
1508
- };
1509
- await durableWrite(this.path, JSON.stringify(file, null, 2), {
1510
- clock: this.#clock
1511
- });
1512
- this.#writtenChanges = changes;
1513
- });
1503
+ return this.#writes.run(
1504
+ async () => {
1505
+ const changes = this.#changes;
1506
+ if (changes === this.#writtenChanges) return;
1507
+ const file = {
1508
+ configHash: this.configHash,
1509
+ points: this.points
1510
+ };
1511
+ await durableWrite(this.path, JSON.stringify(file, null, 2), {
1512
+ clock: this.#clock
1513
+ });
1514
+ this.#writtenChanges = changes;
1515
+ },
1516
+ { signal: void 0 }
1517
+ );
1514
1518
  }
1515
1519
  };
1516
- function hash(value) {
1517
- return createHash2("md5").update(JSON.stringify(value)).digest("hex");
1520
+ function jsonDigest(value) {
1521
+ return hash2("md5", JSON.stringify(value));
1518
1522
  }
1519
1523
  var Point = class {
1520
1524
  #stored;
@@ -1533,7 +1537,7 @@ var Point = class {
1533
1537
  * executes, saves the encoded output, and returns the computed value.
1534
1538
  */
1535
1539
  async through(input, compute) {
1536
- const inputHash = hash(input);
1540
+ const inputHash = jsonDigest(input);
1537
1541
  if (this.#stored.has(inputHash)) {
1538
1542
  return this.codec.decode(this.#stored.get(inputHash));
1539
1543
  }
@@ -1559,7 +1563,7 @@ var Point = class {
1559
1563
  }
1560
1564
  };
1561
1565
  function hashConfig(config) {
1562
- return createHash2("md5").update(JSON.stringify(config)).digest("hex");
1566
+ return hash2("md5", JSON.stringify(config));
1563
1567
  }
1564
1568
 
1565
1569
  // packages/text2sql/src/lib/fs/sqlite/sqlite-fs.ts
@@ -2090,7 +2094,7 @@ var SqliteFs = class {
2090
2094
  const allEntries = z6.array(entryRow).parse(
2091
2095
  this.#sql.all`SELECT * FROM fs_entries WHERE path = ${srcPrefixed} OR path LIKE ${srcPrefixed} || '/%' ORDER BY path DESC`
2092
2096
  );
2093
- for (const entry of [...allEntries].reverse()) {
2097
+ for (const entry of allEntries.toReversed()) {
2094
2098
  const relativePath = path2.posix.relative(srcPrefixed, entry.path);
2095
2099
  const newPath = path2.posix.join(destPrefixed, relativePath);
2096
2100
  this.#sql.run`INSERT INTO fs_entries (path, type, mode, size, mtime, symlinkTarget)
@@ -3051,7 +3055,7 @@ var MssqlFs = class _MssqlFs {
3051
3055
  await destDeleteReq.query(
3052
3056
  `DELETE FROM ${this.#t("fs_entries")} WHERE path = @dp0 OR path LIKE @dp0 + '/%'`
3053
3057
  );
3054
- for (const entry of [...allEntries].reverse()) {
3058
+ for (const entry of allEntries.toReversed()) {
3055
3059
  const relativePath = path3.posix.relative(srcPrefixed, entry.path);
3056
3060
  const newPath = path3.posix.join(destPrefixed, relativePath);
3057
3061
  const insertReq = transaction2.request();
@@ -4028,7 +4032,7 @@ var PostgresFs = class _PostgresFs {
4028
4032
  `DELETE FROM ${this.#t("fs_entries")} WHERE path = $1 OR path LIKE $1 || '/%'`,
4029
4033
  [destPrefixed]
4030
4034
  );
4031
- for (const entry of [...allEntries].reverse()) {
4035
+ for (const entry of allEntries.toReversed()) {
4032
4036
  const relativePath = path4.posix.relative(srcPrefixed, entry.path);
4033
4037
  const newPath = path4.posix.join(destPrefixed, relativePath);
4034
4038
  await client.query(
@@ -4754,7 +4758,7 @@ import { BashTransformPipeline } from "just-bash";
4754
4758
 
4755
4759
  // packages/text2sql/src/lib/agents/sql-transform-plugins.ts
4756
4760
  import { parse as parse2, serialize } from "just-bash";
4757
- import { createHash as createHash3 } from "node:crypto";
4761
+ import { hash as hash3 } from "node:crypto";
4758
4762
  import * as path5 from "node:path";
4759
4763
  import {
4760
4764
  BashException,
@@ -5428,9 +5432,9 @@ function rewriteSqlCommand(cmd, ast) {
5428
5432
  const dbName = asStaticWordText2(cmd.args[1]);
5429
5433
  const sqlArgs = cmd.args.slice(2);
5430
5434
  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()}`;
5435
+ const digest = hash3("sha256", serialize(ast)).slice(0, 12);
5436
+ const sqlPath = `/tmp/sql-inline-${subcommand}-${digest}.sql`;
5437
+ const heredocTag = `SQL_${digest.toUpperCase()}`;
5434
5438
  const groupScript = [
5435
5439
  `{ cat > ${sqlPath} <<'${heredocTag}'`,
5436
5440
  unquotedSql,
@@ -5728,7 +5732,7 @@ function parseFlags(subcommand, args) {
5728
5732
  outDir: parsed.values["out-dir"]
5729
5733
  };
5730
5734
  } catch (error) {
5731
- const message = error instanceof Error ? error.message : String(error);
5735
+ const message = Error.isError(error) ? error.message : String(error);
5732
5736
  throw new SqlCommandError(subcommand, message);
5733
5737
  }
5734
5738
  }
@@ -5772,7 +5776,7 @@ async function runHandler(subcommand, fn) {
5772
5776
  if (Text2SqlValidationError.isInstance(error)) {
5773
5777
  return new SqlCommandError(subcommand, error.message).format();
5774
5778
  }
5775
- const message = error instanceof Error ? error.message : String(error);
5779
+ const message = Error.isError(error) ? error.message : String(error);
5776
5780
  return new SqlCommandError(subcommand, message).format();
5777
5781
  }
5778
5782
  }