@deepagents/text2sql 0.37.1 → 0.38.1

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 (38) hide show
  1. package/README.md +10 -1
  2. package/dist/index.js +165 -44
  3. package/dist/index.js.map +2 -2
  4. package/dist/lib/adapters/adapter.d.ts +4 -4
  5. package/dist/lib/adapters/adapter.d.ts.map +1 -1
  6. package/dist/lib/adapters/bigquery/constraint.bigquery.grounding.d.ts.map +1 -1
  7. package/dist/lib/adapters/bigquery/index.js +160 -31
  8. package/dist/lib/adapters/bigquery/index.js.map +3 -3
  9. package/dist/lib/adapters/bigquery/indexes.bigquery.grounding.d.ts.map +1 -1
  10. package/dist/lib/adapters/bigquery/row-count.bigquery.grounding.d.ts.map +1 -1
  11. package/dist/lib/adapters/groundings/abstract.grounding.d.ts +3 -1
  12. package/dist/lib/adapters/groundings/abstract.grounding.d.ts.map +1 -1
  13. package/dist/lib/adapters/groundings/column-stats.grounding.d.ts.map +1 -1
  14. package/dist/lib/adapters/groundings/column-values.grounding.d.ts.map +1 -1
  15. package/dist/lib/adapters/groundings/constraint.grounding.d.ts.map +1 -1
  16. package/dist/lib/adapters/groundings/context.d.ts +6 -2
  17. package/dist/lib/adapters/groundings/context.d.ts.map +1 -1
  18. package/dist/lib/adapters/groundings/index.js +96 -20
  19. package/dist/lib/adapters/groundings/index.js.map +2 -2
  20. package/dist/lib/adapters/groundings/indexes.grounding.d.ts.map +1 -1
  21. package/dist/lib/adapters/groundings/row-count.grounding.d.ts.map +1 -1
  22. package/dist/lib/adapters/groundings/table.grounding.d.ts.map +1 -1
  23. package/dist/lib/adapters/groundings/view.grounding.d.ts.map +1 -1
  24. package/dist/lib/adapters/mysql/index.js +145 -35
  25. package/dist/lib/adapters/mysql/index.js.map +3 -3
  26. package/dist/lib/adapters/postgres/index.js +151 -35
  27. package/dist/lib/adapters/postgres/index.js.map +3 -3
  28. package/dist/lib/adapters/postgres/postgres.d.ts.map +1 -1
  29. package/dist/lib/adapters/spreadsheet/index.js +109 -27
  30. package/dist/lib/adapters/spreadsheet/index.js.map +3 -3
  31. package/dist/lib/adapters/sqlite/index.js +145 -35
  32. package/dist/lib/adapters/sqlite/index.js.map +3 -3
  33. package/dist/lib/adapters/sqlserver/index.js +151 -35
  34. package/dist/lib/adapters/sqlserver/index.js.map +3 -3
  35. package/dist/lib/adapters/sqlserver/sqlserver.d.ts.map +1 -1
  36. package/dist/lib/sql.d.ts +22 -5
  37. package/dist/lib/sql.d.ts.map +1 -1
  38. package/package.json +6 -5
@@ -66,17 +66,17 @@ export interface AdapterInfo {
66
66
  details?: FragmentObject;
67
67
  }
68
68
  export type AdapterInfoProvider = AdapterInfo | (() => Promise<AdapterInfo> | AdapterInfo);
69
- export type IntrospectionPhase = 'tables' | 'row_counts' | 'primary_keys' | 'indexes' | 'column_stats' | 'low_cardinality' | 'relationships';
69
+ export type IntrospectionPhase = 'info' | 'tables' | 'views' | 'row_counts' | 'constraints' | 'indexes' | 'column_stats' | 'column_values' | 'low_cardinality' | 'relationships';
70
+ export type IntrospectionProgressType = 'phase:start' | 'phase:progress' | 'phase:end';
70
71
  export interface IntrospectionProgress {
72
+ type: IntrospectionProgressType;
71
73
  phase: IntrospectionPhase;
72
74
  message: string;
75
+ table?: string;
73
76
  current?: number;
74
77
  total?: number;
75
78
  }
76
79
  export type OnProgress = (progress: IntrospectionProgress) => void;
77
- export interface IntrospectOptions {
78
- onProgress?: OnProgress;
79
- }
80
80
  export type GroundingFn = (adapter: Adapter) => AbstractGrounding;
81
81
  export type ExecuteFunction = (sql: string) => Promise<any> | any;
82
82
  export type ValidateFunction = (sql: string) => Promise<string | void> | string | void;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/adapters/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,eAAe,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAA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G;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;IAc5C;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAQ/D;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC;;;;OAIG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM;CAezE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAC3D,MAAM,EAAE,CAAC,EAAE,EACX,MAAM,EAAE,YAAY,GAAG,SAAS,GAC/B,CAAC,EAAE,CAGL;AAED,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,YAAY,EAAE,EAC7B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,GAClC,YAAY,EAAE,CAUhB;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,KAAK,EAAE,EACf,aAAa,EAAE,YAAY,EAAE,EAC7B,MAAM,EAAE,YAAY,GAAG,SAAS,GAC/B;IAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAAC,aAAa,EAAE,YAAY,EAAE,CAAA;CAAE,CAapD;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,GACnB,OAAO,CAKT;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,KAAK,EAAE,EAClB,aAAa,EAAE,YAAY,EAAE,EAC7B,MAAM,EAAE,YAAY,GACnB,MAAM,EAAE,CA0CV"}
@@ -1 +1 @@
1
- {"version":3,"file":"constraint.bigquery.grounding.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/bigquery/constraint.bigquery.grounding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC/B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAkB9C,MAAM,WAAW,iCAAkC,SAAQ,yBAAyB;CAAG;AAEvF,qBAAa,2BAA4B,SAAQ,mBAAmB;;gBAKhE,OAAO,EAAE,QAAQ,EACjB,MAAM,GAAE,iCAAsC;IAMjC,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;cAyKnC,cAAc,CACrC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC;CAG9B"}
1
+ {"version":3,"file":"constraint.bigquery.grounding.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/bigquery/constraint.bigquery.grounding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC/B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAkB9C,MAAM,WAAW,iCAAkC,SAAQ,yBAAyB;CAAG;AAEvF,qBAAa,2BAA4B,SAAQ,mBAAmB;;gBAKhE,OAAO,EAAE,QAAQ,EACjB,MAAM,GAAE,iCAAsC;IAMjC,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;cAsLnC,cAAc,CACrC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC;CAG9B"}
@@ -148,13 +148,14 @@ function relationship(input) {
148
148
  }
149
149
 
150
150
  // packages/text2sql/src/lib/adapters/groundings/context.ts
151
- function createGroundingContext() {
151
+ function createGroundingContext(options = {}) {
152
152
  return {
153
153
  tables: [],
154
154
  views: [],
155
155
  relationships: [],
156
156
  info: void 0,
157
- cache: /* @__PURE__ */ new Map()
157
+ cache: /* @__PURE__ */ new Map(),
158
+ onProgress: options.onProgress
158
159
  };
159
160
  }
160
161
 
@@ -300,7 +301,24 @@ var Adapter = class {
300
301
  async introspect(ctx = createGroundingContext()) {
301
302
  for (const fn of this.grounding) {
302
303
  const grounding = fn(this);
303
- await grounding.execute(ctx);
304
+ if (grounding.phase) {
305
+ ctx.onProgress?.({
306
+ type: "phase:start",
307
+ phase: grounding.phase,
308
+ message: `Starting ${grounding.name} introspection...`
309
+ });
310
+ }
311
+ try {
312
+ await grounding.execute(ctx);
313
+ } finally {
314
+ if (grounding.phase) {
315
+ ctx.onProgress?.({
316
+ type: "phase:end",
317
+ phase: grounding.phase,
318
+ message: `Finished ${grounding.name} introspection.`
319
+ });
320
+ }
321
+ }
304
322
  }
305
323
  return this.#toSchemaFragments(ctx);
306
324
  }
@@ -506,26 +524,33 @@ var Adapter = class {
506
524
  async #checkScope(sql, allowedEntities) {
507
525
  const dialect = this.formatterLanguage;
508
526
  const scopeDialects = {
509
- sqlite: "mysql",
510
- postgresql: "postgresql",
511
- bigquery: "bigquery",
512
- transactsql: "transactsql",
513
- mysql: "mysql"
527
+ sqlite: ["sqlite", "mysql"],
528
+ postgresql: ["postgresql"],
529
+ bigquery: ["bigquery"],
530
+ transactsql: ["transactsql"],
531
+ mysql: ["mysql"]
514
532
  };
515
- const scopeDialect = scopeDialects[dialect];
516
- if (!scopeDialect) {
533
+ const candidates = scopeDialects[dialect];
534
+ if (!candidates) {
517
535
  throw new TypeError(
518
536
  `No scope dialect mapping for formatter language "${dialect}". Add it to the scopeDialects map in Adapter.#checkScope.`
519
537
  );
520
538
  }
521
- let references;
522
- try {
523
- references = extractBaseEntityReferences(sql, scopeDialect);
524
- } catch (error) {
539
+ let references = null;
540
+ let lastError;
541
+ for (const candidate of candidates) {
542
+ try {
543
+ references = extractBaseEntityReferences(sql, candidate);
544
+ break;
545
+ } catch (error) {
546
+ lastError = error;
547
+ }
548
+ }
549
+ if (references === null) {
525
550
  return buildScopeParseErrorPayload(
526
551
  sql,
527
552
  dialect,
528
- error
553
+ lastError
529
554
  );
530
555
  }
531
556
  if (references.length === 0) return null;
@@ -648,22 +673,34 @@ var AbstractGrounding = class {
648
673
  * Grounding identifier for debugging/logging.
649
674
  */
650
675
  name;
651
- constructor(name) {
676
+ phase;
677
+ constructor(name, phase) {
652
678
  this.name = name;
679
+ this.phase = phase;
653
680
  }
654
681
  };
655
682
 
656
683
  // packages/text2sql/src/lib/adapters/groundings/constraint.grounding.ts
657
684
  var ConstraintGrounding = class extends AbstractGrounding {
658
685
  constructor(config = {}) {
659
- super("constraint");
686
+ super("constraint", "constraints");
660
687
  }
661
688
  /**
662
689
  * Execute the grounding process.
663
690
  * Annotates tables in ctx.tables with their constraints.
664
691
  */
665
692
  async execute(ctx) {
666
- for (const table2 of ctx.tables) {
693
+ const total = ctx.tables.length;
694
+ for (let i = 0; i < ctx.tables.length; i++) {
695
+ const table2 = ctx.tables[i];
696
+ ctx.onProgress?.({
697
+ type: "phase:progress",
698
+ phase: "constraints",
699
+ table: table2.name,
700
+ message: `Loading constraints for ${table2.name}...`,
701
+ current: i + 1,
702
+ total
703
+ });
667
704
  try {
668
705
  table2.constraints = await this.getConstraints(table2.name);
669
706
  } catch (error) {
@@ -676,14 +713,24 @@ var ConstraintGrounding = class extends AbstractGrounding {
676
713
  // packages/text2sql/src/lib/adapters/groundings/indexes.grounding.ts
677
714
  var IndexesGrounding = class extends AbstractGrounding {
678
715
  constructor(config = {}) {
679
- super("index");
716
+ super("index", "indexes");
680
717
  }
681
718
  /**
682
719
  * Execute the grounding process.
683
720
  * Annotates tables in ctx.tables with their indexes and marks indexed columns.
684
721
  */
685
722
  async execute(ctx) {
686
- for (const table2 of ctx.tables) {
723
+ const total = ctx.tables.length;
724
+ for (let i = 0; i < ctx.tables.length; i++) {
725
+ const table2 = ctx.tables[i];
726
+ ctx.onProgress?.({
727
+ type: "phase:progress",
728
+ phase: "indexes",
729
+ table: table2.name,
730
+ message: `Loading indexes for ${table2.name}...`,
731
+ current: i + 1,
732
+ total
733
+ });
687
734
  table2.indexes = await this.getIndexes(table2.name);
688
735
  for (const index2 of table2.indexes ?? []) {
689
736
  for (const colName of index2.columns) {
@@ -700,7 +747,7 @@ var IndexesGrounding = class extends AbstractGrounding {
700
747
  // packages/text2sql/src/lib/adapters/groundings/info.grounding.ts
701
748
  var InfoGrounding = class extends AbstractGrounding {
702
749
  constructor(config = {}) {
703
- super("dialectInfo");
750
+ super("dialectInfo", "info");
704
751
  }
705
752
  /**
706
753
  * Execute the grounding process.
@@ -714,14 +761,24 @@ var InfoGrounding = class extends AbstractGrounding {
714
761
  // packages/text2sql/src/lib/adapters/groundings/row-count.grounding.ts
715
762
  var RowCountGrounding = class extends AbstractGrounding {
716
763
  constructor(config = {}) {
717
- super("rowCount");
764
+ super("rowCount", "row_counts");
718
765
  }
719
766
  /**
720
767
  * Execute the grounding process.
721
768
  * Annotates tables in ctx.tables with row counts and size hints.
722
769
  */
723
770
  async execute(ctx) {
724
- for (const table2 of ctx.tables) {
771
+ const total = ctx.tables.length;
772
+ for (let i = 0; i < ctx.tables.length; i++) {
773
+ const table2 = ctx.tables[i];
774
+ ctx.onProgress?.({
775
+ type: "phase:progress",
776
+ phase: "row_counts",
777
+ table: table2.name,
778
+ message: `Counting rows in ${table2.name}...`,
779
+ current: i + 1,
780
+ total
781
+ });
725
782
  const count = await this.getRowCount(table2.name);
726
783
  if (count != null) {
727
784
  table2.rowCount = count;
@@ -748,7 +805,7 @@ var TableGrounding = class extends AbstractGrounding {
748
805
  #forward;
749
806
  #backward;
750
807
  constructor(config = {}) {
751
- super("table");
808
+ super("table", "tables");
752
809
  this.#filter = config.filter;
753
810
  this.#columns = config.columns;
754
811
  this.#forward = config.forward;
@@ -764,9 +821,17 @@ var TableGrounding = class extends AbstractGrounding {
764
821
  const backward = this.#backward;
765
822
  if (!forward && !backward) {
766
823
  const tables3 = await Promise.all(
767
- seedTables.map(
768
- async (name) => applyColumnFilter(await this.getTable(name), this.#columns)
769
- )
824
+ seedTables.map(async (name, index2) => {
825
+ ctx.onProgress?.({
826
+ type: "phase:progress",
827
+ phase: "tables",
828
+ table: name,
829
+ message: `Loading table ${name}...`,
830
+ current: index2 + 1,
831
+ total: seedTables.length
832
+ });
833
+ return applyColumnFilter(await this.getTable(name), this.#columns);
834
+ })
770
835
  );
771
836
  ctx.tables.push(...tables3);
772
837
  return;
@@ -778,6 +843,7 @@ var TableGrounding = class extends AbstractGrounding {
778
843
  const backwardQueue = [];
779
844
  const forwardVisited = /* @__PURE__ */ new Set();
780
845
  const backwardVisited = /* @__PURE__ */ new Set();
846
+ let loadedCount = 0;
781
847
  for (const name of seedTables) {
782
848
  if (forward) forwardQueue.push({ name, depth: 0 });
783
849
  if (backward) backwardQueue.push({ name, depth: 0 });
@@ -790,6 +856,14 @@ var TableGrounding = class extends AbstractGrounding {
790
856
  if (forwardVisited.has(name)) continue;
791
857
  forwardVisited.add(name);
792
858
  if (!tables2[name]) {
859
+ loadedCount++;
860
+ ctx.onProgress?.({
861
+ type: "phase:progress",
862
+ phase: "tables",
863
+ table: name,
864
+ message: `Loading table ${name}...`,
865
+ current: loadedCount
866
+ });
793
867
  tables2[name] = applyColumnFilter(
794
868
  await this.getTable(name),
795
869
  this.#columns
@@ -814,6 +888,14 @@ var TableGrounding = class extends AbstractGrounding {
814
888
  if (backwardVisited.has(name)) continue;
815
889
  backwardVisited.add(name);
816
890
  if (!tables2[name]) {
891
+ loadedCount++;
892
+ ctx.onProgress?.({
893
+ type: "phase:progress",
894
+ phase: "tables",
895
+ table: name,
896
+ message: `Loading table ${name}...`,
897
+ current: loadedCount
898
+ });
817
899
  tables2[name] = applyColumnFilter(
818
900
  await this.getTable(name),
819
901
  this.#columns
@@ -1060,7 +1142,20 @@ var BigQueryConstraintGrounding = class extends ConstraintGrounding {
1060
1142
  list.push(table2);
1061
1143
  byDataset.set(dataset, list);
1062
1144
  }
1145
+ let current = 0;
1146
+ const total = ctx.tables.length;
1063
1147
  for (const [dataset, tables2] of byDataset) {
1148
+ for (const table2 of tables2) {
1149
+ current++;
1150
+ ctx.onProgress?.({
1151
+ type: "phase:progress",
1152
+ phase: "constraints",
1153
+ table: table2.name,
1154
+ message: `Loading constraints for ${table2.name}...`,
1155
+ current,
1156
+ total
1157
+ });
1158
+ }
1064
1159
  try {
1065
1160
  await this.#batchConstraints(dataset, tables2);
1066
1161
  } catch (error) {
@@ -1213,7 +1308,20 @@ var BigQueryIndexesGrounding = class extends IndexesGrounding {
1213
1308
  list.push(table2);
1214
1309
  byDataset.set(dataset, list);
1215
1310
  }
1311
+ let current = 0;
1312
+ const total = ctx.tables.length;
1216
1313
  for (const [dataset, tables2] of byDataset) {
1314
+ for (const table2 of tables2) {
1315
+ current++;
1316
+ ctx.onProgress?.({
1317
+ type: "phase:progress",
1318
+ phase: "indexes",
1319
+ table: table2.name,
1320
+ message: `Loading indexes for ${table2.name}...`,
1321
+ current,
1322
+ total
1323
+ });
1324
+ }
1217
1325
  try {
1218
1326
  await this.#batchIndexes(dataset, tables2);
1219
1327
  } catch {
@@ -1326,7 +1434,20 @@ var BigQueryRowCountGrounding = class extends RowCountGrounding {
1326
1434
  list.push(table2);
1327
1435
  byDataset.set(dataset, list);
1328
1436
  }
1437
+ let current = 0;
1438
+ const total = ctx.tables.length;
1329
1439
  for (const [dataset, tables2] of byDataset) {
1440
+ for (const table2 of tables2) {
1441
+ current++;
1442
+ ctx.onProgress?.({
1443
+ type: "phase:progress",
1444
+ phase: "row_counts",
1445
+ table: table2.name,
1446
+ message: `Counting rows in ${table2.name}...`,
1447
+ current,
1448
+ total
1449
+ });
1450
+ }
1330
1451
  const tableNames = tables2.map(
1331
1452
  (t) => this.#adapter.parseTableName(t.name).table
1332
1453
  );
@@ -1586,7 +1707,7 @@ var ViewGrounding = class extends AbstractGrounding {
1586
1707
  #columns;
1587
1708
  includeDefinition;
1588
1709
  constructor(config = {}) {
1589
- super("view");
1710
+ super("view", "views");
1590
1711
  this.#filter = config.filter;
1591
1712
  this.#columns = config.columns;
1592
1713
  this.includeDefinition = config.includeDefinition ?? true;
@@ -1598,9 +1719,17 @@ var ViewGrounding = class extends AbstractGrounding {
1598
1719
  async execute(ctx) {
1599
1720
  const viewNames = await this.applyFilter();
1600
1721
  const views2 = await Promise.all(
1601
- viewNames.map(
1602
- async (name) => applyColumnFilter(await this.getView(name), this.#columns)
1603
- )
1722
+ viewNames.map(async (name, index2) => {
1723
+ ctx.onProgress?.({
1724
+ type: "phase:progress",
1725
+ phase: "views",
1726
+ table: name,
1727
+ message: `Loading view ${name}...`,
1728
+ current: index2 + 1,
1729
+ total: viewNames.length
1730
+ });
1731
+ return applyColumnFilter(await this.getView(name), this.#columns);
1732
+ })
1604
1733
  );
1605
1734
  ctx.views.push(...views2);
1606
1735
  }