@deepagents/text2sql 0.38.0 → 0.39.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.
@@ -148,6 +148,17 @@ function relationship(input) {
148
148
  }
149
149
 
150
150
  // packages/text2sql/src/lib/adapters/groundings/context.ts
151
+ var noopProgress = () => {
152
+ };
153
+ function timestampProgress(onProgress) {
154
+ if (!onProgress) return noopProgress;
155
+ return (progress) => {
156
+ onProgress({
157
+ ...progress,
158
+ timestampMs: progress.timestampMs ?? Date.now()
159
+ });
160
+ };
161
+ }
151
162
  function createGroundingContext(options = {}) {
152
163
  return {
153
164
  tables: [],
@@ -155,7 +166,7 @@ function createGroundingContext(options = {}) {
155
166
  relationships: [],
156
167
  info: void 0,
157
168
  cache: /* @__PURE__ */ new Map(),
158
- onProgress: options.onProgress
169
+ onProgress: timestampProgress(options.onProgress)
159
170
  };
160
171
  }
161
172
 
@@ -302,7 +313,7 @@ var Adapter = class {
302
313
  for (const fn of this.grounding) {
303
314
  const grounding = fn(this);
304
315
  if (grounding.phase) {
305
- ctx.onProgress?.({
316
+ ctx.onProgress({
306
317
  type: "phase:start",
307
318
  phase: grounding.phase,
308
319
  message: `Starting ${grounding.name} introspection...`
@@ -312,7 +323,7 @@ var Adapter = class {
312
323
  await grounding.execute(ctx);
313
324
  } finally {
314
325
  if (grounding.phase) {
315
- ctx.onProgress?.({
326
+ ctx.onProgress({
316
327
  type: "phase:end",
317
328
  phase: grounding.phase,
318
329
  message: `Finished ${grounding.name} introspection.`
@@ -694,7 +705,7 @@ var ColumnStatsGrounding = class extends AbstractGrounding {
694
705
  const total = allContainers.length;
695
706
  for (let i = 0; i < allContainers.length; i++) {
696
707
  const container = allContainers[i];
697
- ctx.onProgress?.({
708
+ ctx.onProgress({
698
709
  type: "phase:progress",
699
710
  phase: "column_stats",
700
711
  table: container.name,
@@ -812,7 +823,7 @@ var ColumnValuesGrounding = class extends AbstractGrounding {
812
823
  const total = allContainers.length;
813
824
  for (let i = 0; i < allContainers.length; i++) {
814
825
  const container = allContainers[i];
815
- ctx.onProgress?.({
826
+ ctx.onProgress({
816
827
  type: "phase:progress",
817
828
  phase: "column_values",
818
829
  table: container.name,
@@ -883,7 +894,7 @@ var ConstraintGrounding = class extends AbstractGrounding {
883
894
  const total = ctx.tables.length;
884
895
  for (let i = 0; i < ctx.tables.length; i++) {
885
896
  const table2 = ctx.tables[i];
886
- ctx.onProgress?.({
897
+ ctx.onProgress({
887
898
  type: "phase:progress",
888
899
  phase: "constraints",
889
900
  table: table2.name,
@@ -913,7 +924,7 @@ var IndexesGrounding = class extends AbstractGrounding {
913
924
  const total = ctx.tables.length;
914
925
  for (let i = 0; i < ctx.tables.length; i++) {
915
926
  const table2 = ctx.tables[i];
916
- ctx.onProgress?.({
927
+ ctx.onProgress({
917
928
  type: "phase:progress",
918
929
  phase: "indexes",
919
930
  table: table2.name,
@@ -961,7 +972,7 @@ var RowCountGrounding = class extends AbstractGrounding {
961
972
  const total = ctx.tables.length;
962
973
  for (let i = 0; i < ctx.tables.length; i++) {
963
974
  const table2 = ctx.tables[i];
964
- ctx.onProgress?.({
975
+ ctx.onProgress({
965
976
  type: "phase:progress",
966
977
  phase: "row_counts",
967
978
  table: table2.name,
@@ -1012,7 +1023,7 @@ var TableGrounding = class extends AbstractGrounding {
1012
1023
  if (!forward && !backward) {
1013
1024
  const tables3 = await Promise.all(
1014
1025
  seedTables.map(async (name, index2) => {
1015
- ctx.onProgress?.({
1026
+ ctx.onProgress({
1016
1027
  type: "phase:progress",
1017
1028
  phase: "tables",
1018
1029
  table: name,
@@ -1047,7 +1058,7 @@ var TableGrounding = class extends AbstractGrounding {
1047
1058
  forwardVisited.add(name);
1048
1059
  if (!tables2[name]) {
1049
1060
  loadedCount++;
1050
- ctx.onProgress?.({
1061
+ ctx.onProgress({
1051
1062
  type: "phase:progress",
1052
1063
  phase: "tables",
1053
1064
  table: name,
@@ -1079,7 +1090,7 @@ var TableGrounding = class extends AbstractGrounding {
1079
1090
  backwardVisited.add(name);
1080
1091
  if (!tables2[name]) {
1081
1092
  loadedCount++;
1082
- ctx.onProgress?.({
1093
+ ctx.onProgress({
1083
1094
  type: "phase:progress",
1084
1095
  phase: "tables",
1085
1096
  table: name,
@@ -1599,6 +1610,8 @@ var POSTGRES_ERROR_MAP = {
1599
1610
  }
1600
1611
  };
1601
1612
  var LOW_CARDINALITY_LIMIT = 20;
1613
+ var noopProgress2 = () => {
1614
+ };
1602
1615
  function isPostgresError(error) {
1603
1616
  return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string";
1604
1617
  }
@@ -1747,12 +1760,12 @@ var Postgres = class extends Adapter {
1747
1760
  }
1748
1761
  return Array.from(relationships.values());
1749
1762
  }
1750
- async #annotateRowCounts(tables2, onProgress) {
1763
+ async #annotateRowCounts(tables2, onProgress = noopProgress2) {
1751
1764
  const total = tables2.length;
1752
1765
  for (let i = 0; i < tables2.length; i++) {
1753
1766
  const table2 = tables2[i];
1754
1767
  const tableIdentifier = this.#formatQualifiedTableName(table2);
1755
- onProgress?.({
1768
+ onProgress({
1756
1769
  type: "phase:progress",
1757
1770
  phase: "row_counts",
1758
1771
  table: table2.name,
@@ -1835,7 +1848,7 @@ var Postgres = class extends Adapter {
1835
1848
  }
1836
1849
  }
1837
1850
  }
1838
- async #annotateColumnStats(tables2, onProgress) {
1851
+ async #annotateColumnStats(tables2, onProgress = noopProgress2) {
1839
1852
  if (!tables2.length) {
1840
1853
  return;
1841
1854
  }
@@ -1843,7 +1856,7 @@ var Postgres = class extends Adapter {
1843
1856
  for (let i = 0; i < tables2.length; i++) {
1844
1857
  const table2 = tables2[i];
1845
1858
  const tableIdentifier = this.#formatQualifiedTableName(table2);
1846
- onProgress?.({
1859
+ onProgress({
1847
1860
  type: "phase:progress",
1848
1861
  phase: "column_stats",
1849
1862
  table: table2.name,
@@ -1884,12 +1897,12 @@ var Postgres = class extends Adapter {
1884
1897
  }
1885
1898
  }
1886
1899
  }
1887
- async #annotateLowCardinalityColumns(tables2, onProgress) {
1900
+ async #annotateLowCardinalityColumns(tables2, onProgress = noopProgress2) {
1888
1901
  const total = tables2.length;
1889
1902
  for (let i = 0; i < tables2.length; i++) {
1890
1903
  const table2 = tables2[i];
1891
1904
  const tableIdentifier = this.#formatQualifiedTableName(table2);
1892
- onProgress?.({
1905
+ onProgress({
1893
1906
  type: "phase:progress",
1894
1907
  phase: "low_cardinality",
1895
1908
  table: table2.name,
@@ -2222,7 +2235,7 @@ var ViewGrounding = class extends AbstractGrounding {
2222
2235
  const viewNames = await this.applyFilter();
2223
2236
  const views2 = await Promise.all(
2224
2237
  viewNames.map(async (name, index2) => {
2225
- ctx.onProgress?.({
2238
+ ctx.onProgress({
2226
2239
  type: "phase:progress",
2227
2240
  phase: "views",
2228
2241
  table: name,