@deepagents/text2sql 0.32.0 → 0.33.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 (41) hide show
  1. package/dist/index.js +69 -11
  2. package/dist/index.js.map +3 -3
  3. package/dist/lib/adapters/adapter.d.ts.map +1 -1
  4. package/dist/lib/adapters/bigquery/index.d.ts +0 -3
  5. package/dist/lib/adapters/bigquery/index.d.ts.map +1 -1
  6. package/dist/lib/adapters/bigquery/index.js +0 -108
  7. package/dist/lib/adapters/bigquery/index.js.map +4 -4
  8. package/dist/lib/adapters/groundings/context.d.ts +0 -2
  9. package/dist/lib/adapters/groundings/context.d.ts.map +1 -1
  10. package/dist/lib/adapters/groundings/index.d.ts +0 -1
  11. package/dist/lib/adapters/groundings/index.d.ts.map +1 -1
  12. package/dist/lib/adapters/groundings/index.js +0 -101
  13. package/dist/lib/adapters/groundings/index.js.map +3 -3
  14. package/dist/lib/adapters/mysql/index.d.ts +0 -3
  15. package/dist/lib/adapters/mysql/index.d.ts.map +1 -1
  16. package/dist/lib/adapters/mysql/index.js +0 -108
  17. package/dist/lib/adapters/mysql/index.js.map +4 -4
  18. package/dist/lib/adapters/postgres/index.d.ts +2 -5
  19. package/dist/lib/adapters/postgres/index.d.ts.map +1 -1
  20. package/dist/lib/adapters/postgres/index.js +142 -250
  21. package/dist/lib/adapters/postgres/index.js.map +4 -4
  22. package/dist/lib/adapters/spreadsheet/index.js +34 -52
  23. package/dist/lib/adapters/spreadsheet/index.js.map +3 -3
  24. package/dist/lib/adapters/sqlite/index.d.ts +2 -5
  25. package/dist/lib/adapters/sqlite/index.d.ts.map +1 -1
  26. package/dist/lib/adapters/sqlite/index.js +101 -209
  27. package/dist/lib/adapters/sqlite/index.js.map +4 -4
  28. package/dist/lib/adapters/sqlserver/index.d.ts +2 -5
  29. package/dist/lib/adapters/sqlserver/index.d.ts.map +1 -1
  30. package/dist/lib/adapters/sqlserver/index.js +100 -208
  31. package/dist/lib/adapters/sqlserver/index.js.map +4 -4
  32. package/dist/lib/agents/result-tools.d.ts.map +1 -1
  33. package/dist/lib/synthesis/decorators/deduplicated-producer.d.ts +1 -0
  34. package/dist/lib/synthesis/decorators/deduplicated-producer.d.ts.map +1 -1
  35. package/dist/lib/synthesis/decorators/filtered-producer.d.ts +3 -0
  36. package/dist/lib/synthesis/decorators/filtered-producer.d.ts.map +1 -1
  37. package/dist/lib/synthesis/index.js +31 -6
  38. package/dist/lib/synthesis/index.js.map +4 -4
  39. package/package.json +4 -4
  40. package/dist/lib/adapters/groundings/report.grounding.d.ts +0 -38
  41. package/dist/lib/adapters/groundings/report.grounding.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -346,9 +346,6 @@ var Adapter = class {
346
346
  this.#relationshipToFragment(rel, sourceTable, targetTable)
347
347
  );
348
348
  }
349
- if (ctx.report) {
350
- fragments.push({ name: "businessContext", data: ctx.report });
351
- }
352
349
  return fragments;
353
350
  }
354
351
  /**
@@ -677,7 +674,8 @@ import {
677
674
  Bash,
678
675
  MountableFs,
679
676
  OverlayFs,
680
- defineCommand
677
+ defineCommand,
678
+ parse as parse2
681
679
  } from "just-bash";
682
680
  import { AsyncLocalStorage } from "node:async_hooks";
683
681
  import * as path2 from "node:path";
@@ -1483,6 +1481,37 @@ ${usageLines}`,
1483
1481
  };
1484
1482
  });
1485
1483
  }
1484
+ function escapeRegExp(s) {
1485
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1486
+ }
1487
+ function buildRepair(name, subcommands) {
1488
+ const subNames = Object.keys(subcommands).map(escapeRegExp).join("|");
1489
+ const pattern = new RegExp(
1490
+ `^(\\s*${escapeRegExp(name)}\\s+(?:${subNames}))\\s+([\\s\\S]+)$`
1491
+ );
1492
+ return function repair(raw) {
1493
+ const match = raw.match(pattern);
1494
+ if (!match) return raw;
1495
+ try {
1496
+ parse2(raw);
1497
+ return raw;
1498
+ } catch {
1499
+ }
1500
+ const [, prefix, argsPart] = match;
1501
+ const sub = prefix.trim().split(/\s+/).pop();
1502
+ const repairFn = subcommands[sub]?.repair;
1503
+ if (!repairFn) return raw;
1504
+ const repairedArgs = repairFn(argsPart);
1505
+ if (repairedArgs == null) return raw;
1506
+ const repaired = `${prefix} ${repairedArgs}`;
1507
+ try {
1508
+ parse2(repaired);
1509
+ return repaired;
1510
+ } catch {
1511
+ return raw;
1512
+ }
1513
+ };
1514
+ }
1486
1515
  function validateReadOnly(query) {
1487
1516
  const upper = query.toUpperCase().trim();
1488
1517
  if (!upper.startsWith("SELECT") && !upper.startsWith("WITH")) {
@@ -1491,17 +1520,38 @@ function validateReadOnly(query) {
1491
1520
  return { valid: true };
1492
1521
  }
1493
1522
  var SQL_VALIDATE_REMINDER = "Always run `sql validate` before `sql run` to catch syntax errors early.";
1523
+ function normalizeShellArtifacts(raw) {
1524
+ return raw.replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\([().*])/g, "$1").replace(/\\(?=$)/gm, "");
1525
+ }
1526
+ function stripQuoteArtifacts(raw) {
1527
+ let sql = raw.trim();
1528
+ if (sql.startsWith('"')) {
1529
+ sql = sql.slice(1);
1530
+ if (sql.endsWith('"')) sql = sql.slice(0, -1);
1531
+ } else if (sql.startsWith("'")) {
1532
+ sql = sql.slice(1);
1533
+ if (sql.endsWith("'")) sql = sql.slice(0, -1);
1534
+ }
1535
+ return sql.trim();
1536
+ }
1537
+ function repairSqlArgs(rawArgs) {
1538
+ const sql = stripQuoteArtifacts(rawArgs);
1539
+ if (!sql) return null;
1540
+ const escaped = sql.replace(/'/g, "'\\''");
1541
+ return `'${escaped}'`;
1542
+ }
1494
1543
  function createSqlCommand(adapter, metaStore) {
1495
- return createCommand("sql", {
1544
+ const subcommands = {
1496
1545
  run: {
1497
1546
  usage: 'run "SELECT ..."',
1498
1547
  description: "Execute query and store results",
1548
+ repair: repairSqlArgs,
1499
1549
  handler: async (args, ctx) => {
1500
1550
  const store = metaStore.getStore();
1501
1551
  if (store) {
1502
1552
  store.value = { ...store.value, reminder: SQL_VALIDATE_REMINDER };
1503
1553
  }
1504
- const rawQuery = args.join(" ").trim().replace(/\\n/g, "\n").replace(/\\t/g, " ");
1554
+ const rawQuery = normalizeShellArtifacts(args.join(" ").trim());
1505
1555
  if (!rawQuery) {
1506
1556
  return {
1507
1557
  stdout: "",
@@ -1559,8 +1609,9 @@ function createSqlCommand(adapter, metaStore) {
1559
1609
  validate: {
1560
1610
  usage: 'validate "SELECT ..."',
1561
1611
  description: "Validate query syntax",
1612
+ repair: repairSqlArgs,
1562
1613
  handler: async (args) => {
1563
- const rawQuery = args.join(" ").trim().replace(/\\n/g, "\n").replace(/\\t/g, " ");
1614
+ const rawQuery = normalizeShellArtifacts(args.join(" ").trim());
1564
1615
  if (!rawQuery) {
1565
1616
  return {
1566
1617
  stdout: "",
@@ -1594,7 +1645,10 @@ function createSqlCommand(adapter, metaStore) {
1594
1645
  };
1595
1646
  }
1596
1647
  }
1597
- });
1648
+ };
1649
+ const command = createCommand("sql", subcommands);
1650
+ const repair = buildRepair("sql", subcommands);
1651
+ return { command, repair };
1598
1652
  }
1599
1653
  function toViolationResult(error) {
1600
1654
  if (error instanceof SqlProxyViolationError) {
@@ -1606,7 +1660,10 @@ function toViolationResult(error) {
1606
1660
  async function createResultTools(options) {
1607
1661
  const { adapter, skillMounts, filesystem: baseFs } = options;
1608
1662
  const metaStore = new AsyncLocalStorage();
1609
- const sqlCommand = createSqlCommand(adapter, metaStore);
1663
+ const { command: sqlCommand, repair: repairCommand } = createSqlCommand(
1664
+ adapter,
1665
+ metaStore
1666
+ );
1610
1667
  const fsMounts = skillMounts.map(({ host, sandbox: sandbox2 }) => ({
1611
1668
  mountPoint: path2.dirname(sandbox2),
1612
1669
  filesystem: new OverlayFs({
@@ -1630,8 +1687,9 @@ async function createResultTools(options) {
1630
1687
  destination: "/",
1631
1688
  extraInstructions: 'Every bash tool call must include a brief non-empty "reasoning" input explaining why the command is needed.',
1632
1689
  onBeforeBashCall: ({ command }) => {
1633
- console.log(chalk.cyan(`[onBeforeBashCall]: ${command}`));
1634
- return { command };
1690
+ const repaired = repairCommand(command);
1691
+ console.log(chalk.cyan(`[onBeforeBashCall]: ${repaired}`));
1692
+ return { command: repaired };
1635
1693
  },
1636
1694
  onAfterBashCall: ({ result }) => {
1637
1695
  if (result.exitCode !== 0) {