@deepagents/text2sql 0.38.1 → 1.0.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.
- package/README.md +166 -72
- package/dist/bin/sql.js +699 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1989 -1898
- package/dist/index.js.map +4 -4
- package/dist/lib/adapter-index.d.ts +35 -0
- package/dist/lib/adapter-index.d.ts.map +1 -0
- package/dist/lib/adapters/adapter.d.ts +1 -0
- package/dist/lib/adapters/adapter.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.js +24 -13
- package/dist/lib/adapters/bigquery/index.js.map +2 -2
- package/dist/lib/adapters/groundings/context.d.ts +2 -2
- package/dist/lib/adapters/groundings/context.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/index.js +20 -9
- package/dist/lib/adapters/groundings/index.js.map +2 -2
- package/dist/lib/adapters/mysql/index.js +23 -12
- package/dist/lib/adapters/mysql/index.js.map +2 -2
- package/dist/lib/adapters/postgres/index.js +31 -18
- package/dist/lib/adapters/postgres/index.js.map +3 -3
- package/dist/lib/adapters/postgres/postgres.d.ts.map +1 -1
- package/dist/lib/adapters/spreadsheet/index.js +20 -9
- package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
- package/dist/lib/adapters/sqlite/index.js +23 -12
- package/dist/lib/adapters/sqlite/index.js.map +2 -2
- package/dist/lib/adapters/sqlserver/index.js +31 -18
- package/dist/lib/adapters/sqlserver/index.js.map +3 -3
- package/dist/lib/adapters/sqlserver/sqlserver.d.ts.map +1 -1
- package/dist/lib/agents/question.agent.d.ts.map +1 -1
- package/dist/lib/agents/sql-transform-plugins.d.ts +3 -3
- package/dist/lib/agents/sql-transform-plugins.d.ts.map +1 -1
- package/dist/lib/agents/sql.agent.d.ts.map +1 -1
- package/dist/lib/instructions.d.ts +1 -1
- package/dist/lib/instructions.d.ts.map +1 -1
- package/dist/lib/sql-hooks.d.ts +15 -0
- package/dist/lib/sql-hooks.d.ts.map +1 -0
- package/dist/lib/sql-meta-hook.d.ts +20 -0
- package/dist/lib/sql-meta-hook.d.ts.map +1 -0
- package/dist/lib/sql-repair.d.ts +2 -0
- package/dist/lib/sql-repair.d.ts.map +1 -0
- package/dist/lib/sql-transform.d.ts +2 -0
- package/dist/lib/sql-transform.d.ts.map +1 -0
- package/dist/lib/sql.d.ts +5 -37
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/base-contextual-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/segmented-context-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/sql-extractor.d.ts.map +1 -1
- package/dist/lib/synthesis/index.js +59 -2
- package/dist/lib/synthesis/index.js.map +4 -4
- package/dist/lib/synthesis/synthesizers/breadth-evolver.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/depth-evolver.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/persona-generator.d.ts.map +1 -1
- package/package.json +13 -9
- package/dist/lib/agents/sql-command.d.ts +0 -11
- package/dist/lib/agents/sql-command.d.ts.map +0 -1
- package/dist/lib/demo.d.ts +0 -2
- package/dist/lib/demo.d.ts.map +0 -1
- package/dist/lib/sandbox.d.ts +0 -21
- package/dist/lib/sandbox.d.ts.map +0 -1
|
@@ -33,8 +33,8 @@ export interface GroundingContext {
|
|
|
33
33
|
info?: AdapterInfo;
|
|
34
34
|
/** Shared cache for cross-grounding deduplication. Keyed by `type:key`. */
|
|
35
35
|
cache: Map<string, unknown>;
|
|
36
|
-
/**
|
|
37
|
-
onProgress
|
|
36
|
+
/** Progress sink for long-running introspection work. */
|
|
37
|
+
onProgress: OnProgress;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Create a new empty grounding context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/groundings/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,EACZ,KAAK,EACN,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,wCAAwC;IACxC,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd,iDAAiD;IACjD,aAAa,EAAE,YAAY,EAAE,CAAC;IAE9B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,2EAA2E;IAC3E,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5B,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/groundings/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,EACZ,KAAK,EACN,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,wCAAwC;IACxC,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd,iDAAiD;IACjD,aAAa,EAAE,YAAY,EAAE,CAAC;IAE9B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,2EAA2E;IAC3E,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5B,yDAAyD;IACzD,UAAU,EAAE,UAAU,CAAC;CACxB;AAcD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,UAAU,CAAA;CAAO,GACxC,gBAAgB,CASlB"}
|
|
@@ -40,7 +40,7 @@ var ColumnStatsGrounding = class extends AbstractGrounding {
|
|
|
40
40
|
const total = allContainers.length;
|
|
41
41
|
for (let i = 0; i < allContainers.length; i++) {
|
|
42
42
|
const container = allContainers[i];
|
|
43
|
-
ctx.onProgress
|
|
43
|
+
ctx.onProgress({
|
|
44
44
|
type: "phase:progress",
|
|
45
45
|
phase: "column_stats",
|
|
46
46
|
table: container.name,
|
|
@@ -158,7 +158,7 @@ var ColumnValuesGrounding = class extends AbstractGrounding {
|
|
|
158
158
|
const total = allContainers.length;
|
|
159
159
|
for (let i = 0; i < allContainers.length; i++) {
|
|
160
160
|
const container = allContainers[i];
|
|
161
|
-
ctx.onProgress
|
|
161
|
+
ctx.onProgress({
|
|
162
162
|
type: "phase:progress",
|
|
163
163
|
phase: "column_values",
|
|
164
164
|
table: container.name,
|
|
@@ -229,7 +229,7 @@ var ConstraintGrounding = class extends AbstractGrounding {
|
|
|
229
229
|
const total = ctx.tables.length;
|
|
230
230
|
for (let i = 0; i < ctx.tables.length; i++) {
|
|
231
231
|
const table = ctx.tables[i];
|
|
232
|
-
ctx.onProgress
|
|
232
|
+
ctx.onProgress({
|
|
233
233
|
type: "phase:progress",
|
|
234
234
|
phase: "constraints",
|
|
235
235
|
table: table.name,
|
|
@@ -247,6 +247,17 @@ var ConstraintGrounding = class extends AbstractGrounding {
|
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
// packages/text2sql/src/lib/adapters/groundings/context.ts
|
|
250
|
+
var noopProgress = () => {
|
|
251
|
+
};
|
|
252
|
+
function timestampProgress(onProgress) {
|
|
253
|
+
if (!onProgress) return noopProgress;
|
|
254
|
+
return (progress) => {
|
|
255
|
+
onProgress({
|
|
256
|
+
...progress,
|
|
257
|
+
timestampMs: progress.timestampMs ?? Date.now()
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
}
|
|
250
261
|
function createGroundingContext(options = {}) {
|
|
251
262
|
return {
|
|
252
263
|
tables: [],
|
|
@@ -254,7 +265,7 @@ function createGroundingContext(options = {}) {
|
|
|
254
265
|
relationships: [],
|
|
255
266
|
info: void 0,
|
|
256
267
|
cache: /* @__PURE__ */ new Map(),
|
|
257
|
-
onProgress: options.onProgress
|
|
268
|
+
onProgress: timestampProgress(options.onProgress)
|
|
258
269
|
};
|
|
259
270
|
}
|
|
260
271
|
|
|
@@ -285,7 +296,7 @@ var RowCountGrounding = class extends AbstractGrounding {
|
|
|
285
296
|
const total = ctx.tables.length;
|
|
286
297
|
for (let i = 0; i < ctx.tables.length; i++) {
|
|
287
298
|
const table = ctx.tables[i];
|
|
288
|
-
ctx.onProgress
|
|
299
|
+
ctx.onProgress({
|
|
289
300
|
type: "phase:progress",
|
|
290
301
|
phase: "row_counts",
|
|
291
302
|
table: table.name,
|
|
@@ -336,7 +347,7 @@ var TableGrounding = class extends AbstractGrounding {
|
|
|
336
347
|
if (!forward && !backward) {
|
|
337
348
|
const tables2 = await Promise.all(
|
|
338
349
|
seedTables.map(async (name, index) => {
|
|
339
|
-
ctx.onProgress
|
|
350
|
+
ctx.onProgress({
|
|
340
351
|
type: "phase:progress",
|
|
341
352
|
phase: "tables",
|
|
342
353
|
table: name,
|
|
@@ -371,7 +382,7 @@ var TableGrounding = class extends AbstractGrounding {
|
|
|
371
382
|
forwardVisited.add(name);
|
|
372
383
|
if (!tables[name]) {
|
|
373
384
|
loadedCount++;
|
|
374
|
-
ctx.onProgress
|
|
385
|
+
ctx.onProgress({
|
|
375
386
|
type: "phase:progress",
|
|
376
387
|
phase: "tables",
|
|
377
388
|
table: name,
|
|
@@ -403,7 +414,7 @@ var TableGrounding = class extends AbstractGrounding {
|
|
|
403
414
|
backwardVisited.add(name);
|
|
404
415
|
if (!tables[name]) {
|
|
405
416
|
loadedCount++;
|
|
406
|
-
ctx.onProgress
|
|
417
|
+
ctx.onProgress({
|
|
407
418
|
type: "phase:progress",
|
|
408
419
|
phase: "tables",
|
|
409
420
|
table: name,
|
|
@@ -489,7 +500,7 @@ var ViewGrounding = class extends AbstractGrounding {
|
|
|
489
500
|
const viewNames = await this.applyFilter();
|
|
490
501
|
const views = await Promise.all(
|
|
491
502
|
viewNames.map(async (name, index) => {
|
|
492
|
-
ctx.onProgress
|
|
503
|
+
ctx.onProgress({
|
|
493
504
|
type: "phase:progress",
|
|
494
505
|
phase: "views",
|
|
495
506
|
table: name,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/adapters/groundings/abstract.grounding.ts", "../../../../src/lib/adapters/groundings/column-stats.grounding.ts", "../../../../src/lib/adapters/groundings/column-values.grounding.ts", "../../../../src/lib/adapters/groundings/constraint.grounding.ts", "../../../../src/lib/adapters/groundings/context.ts", "../../../../src/lib/adapters/groundings/info.grounding.ts", "../../../../src/lib/adapters/groundings/row-count.grounding.ts", "../../../../src/lib/adapters/groundings/table.grounding.ts", "../../../../src/lib/adapters/groundings/view.grounding.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FragmentObject } from '@deepagents/context';\n\nimport type { Adapter, IntrospectionPhase } from '../adapter.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Filter type for table names.\n * - string[]: explicit list of table names\n * - RegExp: pattern to match table names\n * - function: predicate to filter table names\n */\nexport type Filter = string[] | RegExp | ((tableName: string) => boolean);\n\n/**\n * Per-entity column filter.\n * Maps entity name (table or view) to a Filter that selects which columns to keep.\n * Entities not listed in the record keep all their columns.\n */\nexport type ColumnsFilter = Record<string, Filter>;\n\n/**\n * Filter a columns array using a Filter.\n * Keeps columns whose name matches the filter.\n */\nexport function filterColumns<T extends { name: string }>(\n columns: T[],\n filter: Filter,\n): T[] {\n if (Array.isArray(filter)) {\n return columns.filter((col) => filter.includes(col.name));\n }\n if (filter instanceof RegExp) {\n return columns.filter((col) => filter.test(col.name));\n }\n return columns.filter((col) => filter(col.name));\n}\n\n/**\n * Apply per-entity column filtering.\n * Returns the entity unchanged if no filter matches its name.\n */\nexport function applyColumnFilter<\n T extends { name: string; columns: { name: string }[] },\n>(entity: T, columnsConfig?: ColumnsFilter): T {\n if (!columnsConfig) return entity;\n const filter = columnsConfig[entity.name];\n if (!filter) return entity;\n return { ...entity, columns: filterColumns(entity.columns, filter) } as T;\n}\n\nexport interface AdapterInfo {\n dialect: string;\n version?: string;\n database?: string;\n details?: FragmentObject;\n}\nexport type AdapterInfoProvider =\n | AdapterInfo\n | (() => Promise<AdapterInfo> | AdapterInfo);\n\n/**\n * Abstract base class for database schema groundings.\n *\n * Groundings collect schema metadata into the shared GroundingContext.\n * Fragment generation is centralized in Adapter.introspect().\n */\nexport abstract class AbstractGrounding {\n /**\n * Grounding identifier for debugging/logging.\n */\n name: string;\n phase?: IntrospectionPhase;\n\n constructor(name: string, phase?: IntrospectionPhase) {\n this.name = name;\n this.phase = phase;\n }\n\n /**\n * Execute grounding to populate the shared context.\n * Groundings mutate ctx to add their collected data (tables, views, indexes, etc).\n * Fragment generation happens centrally in Adapter after all groundings complete.\n *\n * @param ctx - Shared context for accumulating schema data\n */\n abstract execute(ctx: GroundingContext): Promise<void>;\n}\n\nclass SampleDataGrounding {\n // this will fetch sample data for tables matching the filter\n}\n\nclass FunctionGrounding {\n #filter: Filter;\n #adapter: Adapter;\n constructor(adapter: Adapter, filter: Filter) {\n this.#filter = filter;\n this.#adapter = adapter;\n }\n}\n", "import type { ColumnStats } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { Column, ColumnContainer, GroundingContext } from './context.ts';\n\n/**\n * Configuration for ColumnStatsGrounding.\n */\nexport interface ColumnStatsGroundingConfig {\n // Future: filter which tables/columns to collect stats for\n}\n\n/**\n * Abstract base class for column statistics grounding.\n *\n * Reads tables and views from the context and annotates their columns\n * with statistics (min, max, nullFraction).\n *\n * Subclasses implement database-specific hooks:\n * - `collectStats()` - collect min/max/nullFraction for a column\n */\nexport abstract class ColumnStatsGrounding extends AbstractGrounding {\n constructor(config: ColumnStatsGroundingConfig = {}) {\n super('columnStats', 'column_stats');\n }\n\n /**\n * Collect min/max/nullFraction statistics for a column.\n * Return undefined to skip this column.\n */\n protected abstract collectStats(\n tableName: string,\n column: Column,\n ): Promise<ColumnStats | undefined>;\n\n /**\n * Execute the grounding process.\n * Annotates columns in ctx.tables and ctx.views with statistics.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n // Process both tables and views\n const allContainers: ColumnContainer[] = [...ctx.tables, ...ctx.views];\n const total = allContainers.length;\n for (let i = 0; i < allContainers.length; i++) {\n const container = allContainers[i];\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'column_stats',\n table: container.name,\n message: `Collecting stats for ${container.name}...`,\n current: i + 1,\n total,\n });\n for (const column of container.columns) {\n // Collect min/max/nullFraction\n try {\n const stats = await this.collectStats(container.name, column);\n if (stats) {\n column.stats = stats;\n }\n } catch (error) {\n // Skip on error\n console.warn(\n 'Error collecting stats for',\n container.name,\n column.name,\n error,\n );\n }\n }\n }\n }\n}\n", "import type { Table, TableConstraint } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { Column, ColumnContainer, GroundingContext } from './context.ts';\n\nexport type { Column, ColumnContainer };\n\n/**\n * Result of column value detection.\n */\nexport type ColumnValuesResult = {\n kind: 'Enum' | 'LowCardinality';\n values: string[];\n};\n\n/**\n * Configuration for ColumnValuesGrounding.\n */\nexport interface ColumnValuesGroundingConfig {\n /** Maximum number of distinct values to consider low cardinality (default: 20) */\n lowCardinalityLimit?: number;\n /** Maximum character length for individual values. Columns with any value exceeding this are skipped entirely (default: 100) */\n maxValueLength?: number;\n}\n\n/**\n * Abstract base class for column values grounding.\n *\n * Discovers possible values for columns from three sources (in priority order):\n * 1. Native ENUM types (PostgreSQL, MySQL) \u2192 kind: 'Enum'\n * 2. CHECK constraints with IN clauses \u2192 kind: 'Enum'\n * 3. Low cardinality data scan \u2192 kind: 'LowCardinality'\n *\n * Subclasses implement database-specific hooks:\n * - `collectEnumValues()` - get values for native ENUM columns\n * - `collectLowCardinality()` - collect distinct values via data scan\n */\nexport abstract class ColumnValuesGrounding extends AbstractGrounding {\n protected lowCardinalityLimit: number;\n protected maxValueLength: number;\n\n constructor(config: ColumnValuesGroundingConfig = {}) {\n super('columnValues', 'column_values');\n this.lowCardinalityLimit = config.lowCardinalityLimit ?? 20;\n this.maxValueLength = config.maxValueLength ?? 100;\n }\n\n /**\n * Get values for native ENUM type columns.\n * Return undefined if column is not an ENUM type.\n * Default implementation returns undefined (no native ENUM support).\n */\n protected async collectEnumValues(\n _tableName: string,\n _column: Column,\n ): Promise<string[] | undefined> {\n return undefined;\n }\n\n /**\n * Collect distinct values for low cardinality columns via data scan.\n * Return undefined if column has too many distinct values.\n */\n protected abstract collectLowCardinality(\n tableName: string,\n column: Column,\n ): Promise<string[] | undefined>;\n\n /**\n * Parse CHECK constraint for enum-like IN clause.\n * Extracts values from patterns like:\n * - CHECK (status IN ('active', 'inactive'))\n * - CHECK ((status)::text = ANY (ARRAY['a'::text, 'b'::text]))\n * - CHECK (status = 'active' OR status = 'inactive')\n */\n protected parseCheckConstraint(\n constraint: TableConstraint,\n columnName: string,\n ): string[] | undefined {\n if (constraint.type !== 'CHECK' || !constraint.definition) {\n return undefined;\n }\n\n // Check if constraint applies to this column\n if (constraint.columns && !constraint.columns.includes(columnName)) {\n return undefined;\n }\n\n const def = constraint.definition;\n const escapedCol = this.escapeRegex(columnName);\n\n // Column pattern: matches column name with optional parens and type cast\n // e.g., \"status\", \"(status)\", \"((status)::text)\"\n const colPattern = `(?:\\\\(?\\\\(?${escapedCol}\\\\)?(?:::(?:text|varchar|character varying))?\\\\)?)`;\n\n // Pattern 1: column IN ('val1', 'val2', ...)\n const inMatch = def.match(\n new RegExp(`${colPattern}\\\\s+IN\\\\s*\\\\(([^)]+)\\\\)`, 'i'),\n );\n if (inMatch) {\n return this.extractStringValues(inMatch[1]);\n }\n\n // Pattern 2: PostgreSQL ANY(ARRAY[...])\n const anyMatch = def.match(\n new RegExp(\n `${colPattern}\\\\s*=\\\\s*ANY\\\\s*\\\\(\\\\s*(?:ARRAY)?\\\\s*\\\\[([^\\\\]]+)\\\\]`,\n 'i',\n ),\n );\n if (anyMatch) {\n return this.extractStringValues(anyMatch[1]);\n }\n\n // Pattern 3: column = 'val1' OR column = 'val2' ...\n const orPattern = new RegExp(\n `\\\\b${this.escapeRegex(columnName)}\\\\b\\\\s*=\\\\s*'([^']*)'`,\n 'gi',\n );\n const orMatches = [...def.matchAll(orPattern)];\n if (orMatches.length >= 2) {\n return orMatches.map((m) => m[1]);\n }\n\n return undefined;\n }\n\n /**\n * Extract string values from a comma-separated list.\n */\n private extractStringValues(input: string): string[] | undefined {\n const values: string[] = [];\n // Match quoted strings: 'value' or 'value'::type\n const matches = input.matchAll(/'([^']*)'/g);\n for (const match of matches) {\n values.push(match[1]);\n }\n return values.length > 0 ? values : undefined;\n }\n\n /**\n * Escape special regex characters in a string.\n */\n private escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n }\n\n /**\n * Get the table from context by name.\n */\n private getTable(ctx: GroundingContext, name: string): Table | undefined {\n return ctx.tables.find((t) => t.name === name);\n }\n\n /**\n * Execute the grounding process.\n * Annotates columns in ctx.tables and ctx.views with values.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n // Process both tables and views\n const allContainers: ColumnContainer[] = [...ctx.tables, ...ctx.views];\n\n const total = allContainers.length;\n for (let i = 0; i < allContainers.length; i++) {\n const container = allContainers[i];\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'column_values',\n table: container.name,\n message: `Collecting column values for ${container.name}...`,\n current: i + 1,\n total,\n });\n const table = this.getTable(ctx, container.name);\n\n for (const column of container.columns) {\n try {\n const result = await this.resolveColumnValues(\n container.name,\n column,\n table?.constraints,\n );\n if (result) {\n column.kind = result.kind;\n column.values = result.values;\n }\n } catch (error) {\n console.warn(\n 'Error collecting column values for',\n container.name,\n column.name,\n error,\n );\n }\n }\n }\n }\n\n private exceedsMaxValueLength(values: string[]): boolean {\n return values.some((v) => v.length > this.maxValueLength);\n }\n\n /**\n * Resolve column values from all sources in priority order.\n */\n private async resolveColumnValues(\n tableName: string,\n column: Column,\n constraints?: TableConstraint[],\n ): Promise<ColumnValuesResult | undefined> {\n // Priority 1: Native ENUM type\n const enumValues = await this.collectEnumValues(tableName, column);\n if (enumValues?.length && !this.exceedsMaxValueLength(enumValues)) {\n return { kind: 'Enum', values: enumValues };\n }\n\n // Priority 2: CHECK constraint with IN clause\n if (constraints) {\n for (const constraint of constraints) {\n const checkValues = this.parseCheckConstraint(constraint, column.name);\n if (checkValues?.length && !this.exceedsMaxValueLength(checkValues)) {\n return { kind: 'Enum', values: checkValues };\n }\n }\n }\n\n // Priority 3: Low cardinality data scan\n const lowCardValues = await this.collectLowCardinality(tableName, column);\n if (lowCardValues?.length && !this.exceedsMaxValueLength(lowCardValues)) {\n return { kind: 'LowCardinality', values: lowCardValues };\n }\n\n return undefined;\n }\n}\n", "import type { TableConstraint } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for ConstraintGrounding.\n */\nexport interface ConstraintGroundingConfig {\n // Future: filter which tables/constraint types to collect\n}\n\n/**\n * Abstract base class for constraint grounding.\n *\n * Reads tables from the context and annotates them with constraints\n * (CHECK, UNIQUE, NOT_NULL, DEFAULT).\n * This grounding must run AFTER TableGrounding since it reads from ctx.tables.\n *\n * Subclasses implement the database-specific hook:\n * - `getConstraints()` - fetch constraints for a table\n */\nexport abstract class ConstraintGrounding extends AbstractGrounding {\n constructor(config: ConstraintGroundingConfig = {}) {\n super('constraint', 'constraints');\n }\n\n /**\n * Fetch constraints for a specific table.\n */\n protected abstract getConstraints(\n tableName: string,\n ): Promise<TableConstraint[]>;\n\n /**\n * Execute the grounding process.\n * Annotates tables in ctx.tables with their constraints.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const total = ctx.tables.length;\n for (let i = 0; i < ctx.tables.length; i++) {\n const table = ctx.tables[i];\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'constraints',\n table: table.name,\n message: `Loading constraints for ${table.name}...`,\n current: i + 1,\n total,\n });\n try {\n table.constraints = await this.getConstraints(table.name);\n } catch (error) {\n // Skip on error - table might not exist or be inaccessible\n console.warn('Error collecting constraints for', table.name, error);\n }\n }\n }\n}\n", "import type {\n AdapterInfo,\n ColumnStats,\n OnProgress,\n Relationship,\n Table,\n} from '../adapter.ts';\nimport type { View } from './view.grounding.ts';\n\n/**\n * Column type for grounding operations.\n * Common interface between Table.columns and View.columns.\n */\nexport interface Column {\n name: string;\n type: string;\n kind?: 'LowCardinality' | 'Enum';\n values?: string[];\n stats?: ColumnStats;\n}\n\n/**\n * Entity with columns (Table or View).\n */\nexport interface ColumnContainer {\n name: string;\n columns: Column[];\n}\n\n/**\n * Shared context object passed to all groundings.\n * Groundings read from and write to this context.\n */\nexport interface GroundingContext {\n /** Tables discovered by TableGrounding */\n tables: Table[];\n\n /** Views discovered by ViewGrounding */\n views: View[];\n\n /** Relationships discovered by TableGrounding */\n relationships: Relationship[];\n\n /** Database info collected by InfoGrounding */\n info?: AdapterInfo;\n\n /** Shared cache for cross-grounding deduplication. Keyed by `type:key`. */\n cache: Map<string, unknown>;\n\n /** Optional progress sink for long-running introspection work. */\n onProgress?: OnProgress;\n}\n\n/**\n * Create a new empty grounding context.\n */\nexport function createGroundingContext(\n options: { onProgress?: OnProgress } = {},\n): GroundingContext {\n return {\n tables: [],\n views: [],\n relationships: [],\n info: undefined,\n cache: new Map(),\n onProgress: options.onProgress,\n };\n}\n", "import type { AdapterInfo } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for InfoGrounding.\n */\nexport interface InfoGroundingConfig {\n // Future: options to control what info to collect\n}\n\n/**\n * Abstract base class for database info grounding.\n *\n * Collects database dialect, version, and connection info.\n *\n * Subclasses implement the database-specific hook:\n * - `collectInfo()` - collect database info\n */\nexport abstract class InfoGrounding extends AbstractGrounding {\n constructor(config: InfoGroundingConfig = {}) {\n super('dialectInfo', 'info');\n }\n\n /**\n * Collect database dialect, version, and other info.\n */\n protected abstract collectInfo(): Promise<AdapterInfo>;\n\n /**\n * Execute the grounding process.\n * Writes database info to ctx.info.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n ctx.info = await this.collectInfo();\n }\n}\n", "import type { Table } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for RowCountGrounding.\n */\nexport interface RowCountGroundingConfig {\n // Future: filter which tables to count\n}\n\n/**\n * Abstract base class for row count grounding.\n *\n * Reads tables from the context and annotates them with row counts and size hints.\n * This grounding must run AFTER TableGrounding since it reads from ctx.tables.\n *\n * Subclasses implement the database-specific hook:\n * - `getRowCount()` - get row count for a table\n */\nexport abstract class RowCountGrounding extends AbstractGrounding {\n constructor(config: RowCountGroundingConfig = {}) {\n super('rowCount', 'row_counts');\n }\n\n /**\n * Get row count for a specific table.\n */\n protected abstract getRowCount(\n tableName: string,\n ): Promise<number | undefined>;\n\n /**\n * Execute the grounding process.\n * Annotates tables in ctx.tables with row counts and size hints.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const total = ctx.tables.length;\n for (let i = 0; i < ctx.tables.length; i++) {\n const table = ctx.tables[i];\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'row_counts',\n table: table.name,\n message: `Counting rows in ${table.name}...`,\n current: i + 1,\n total,\n });\n const count = await this.getRowCount(table.name);\n if (count != null) {\n table.rowCount = count;\n table.sizeHint = this.#classifyRowCount(count);\n }\n }\n }\n\n /**\n * Classify row count into a size hint category.\n */\n #classifyRowCount(count: number): Table['sizeHint'] {\n if (count < 100) return 'tiny';\n if (count < 1000) return 'small';\n if (count < 10000) return 'medium';\n if (count < 100000) return 'large';\n return 'huge';\n }\n}\n", "import type { Filter, Relationship, Table } from '../adapter.ts';\nimport {\n AbstractGrounding,\n type ColumnsFilter,\n applyColumnFilter,\n filterColumns,\n} from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for TableGrounding.\n */\nexport interface TableGroundingConfig {\n /** Filter to select seed tables */\n filter?: Filter;\n /**\n * Per-table column filter.\n * Maps table name to a Filter that selects which columns to keep.\n * Tables not listed keep all their columns.\n */\n columns?: ColumnsFilter;\n /**\n * Traverse forward (child\u2192parent) following FK direction.\n * - true: unlimited depth\n * - number: maximum depth\n * - false/undefined: no forward traversal\n */\n forward?: boolean | number;\n /**\n * Traverse backward (parent\u2192child) finding tables that reference us.\n * - true: unlimited depth\n * - number: maximum depth\n * - false/undefined: no backward traversal\n */\n backward?: boolean | number;\n}\n\n/**\n * Abstract base class for table grounding.\n *\n * The `execute()` method implements a BFS traversal algorithm that discovers\n * tables and relationships. Subclasses implement the database-specific hooks:\n * - `getAllTableNames()` - list all tables\n * - `getTable()` - get table metadata\n * - `findOutgoingRelations()` - find FKs FROM a table\n * - `findIncomingRelations()` - find FKs TO a table\n */\nexport abstract class TableGrounding extends AbstractGrounding {\n #filter?: Filter;\n #columns?: ColumnsFilter;\n #forward?: boolean | number;\n #backward?: boolean | number;\n\n constructor(config: TableGroundingConfig = {}) {\n super('table', 'tables');\n this.#filter = config.filter;\n this.#columns = config.columns;\n this.#forward = config.forward;\n this.#backward = config.backward;\n }\n\n /** Get all table names in the database */\n protected abstract getAllTableNames(): Promise<string[]>;\n\n /** Get full table metadata for a single table */\n protected abstract getTable(tableName: string): Promise<Table>;\n\n /** Find FKs FROM this table (outgoing relationships) */\n protected abstract findOutgoingRelations(\n tableName: string,\n ): Promise<Relationship[]>;\n\n /** Find FKs TO this table (incoming relationships) */\n protected abstract findIncomingRelations(\n tableName: string,\n ): Promise<Relationship[]>;\n\n /**\n * Execute the grounding process.\n * Writes discovered tables and relationships to the context.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const seedTables = await this.applyFilter();\n const forward = this.#forward;\n const backward = this.#backward;\n\n // No traversal at all - just add the seed tables\n if (!forward && !backward) {\n const tables = await Promise.all(\n seedTables.map(async (name, index) => {\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'tables',\n table: name,\n message: `Loading table ${name}...`,\n current: index + 1,\n total: seedTables.length,\n });\n return applyColumnFilter(await this.getTable(name), this.#columns);\n }),\n );\n ctx.tables.push(...tables);\n return;\n }\n\n const tables: Record<string, Table> = {};\n const allRelationships: Relationship[] = [];\n const seenRelationships = new Set<string>();\n\n // Track depth separately for forward/backward using BFS\n const forwardQueue: Array<{ name: string; depth: number }> = [];\n const backwardQueue: Array<{ name: string; depth: number }> = [];\n const forwardVisited = new Set<string>();\n const backwardVisited = new Set<string>();\n let loadedCount = 0;\n\n // Initialize queues with seed tables at depth 0\n for (const name of seedTables) {\n if (forward) forwardQueue.push({ name, depth: 0 });\n if (backward) backwardQueue.push({ name, depth: 0 });\n }\n\n // Process forward (child\u2192parent)\n const forwardLimit = forward === true ? Infinity : forward || 0;\n while (forwardQueue.length > 0) {\n const item = forwardQueue.shift();\n if (!item) break;\n const { name, depth } = item;\n\n if (forwardVisited.has(name)) continue;\n forwardVisited.add(name);\n\n if (!tables[name]) {\n loadedCount++;\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'tables',\n table: name,\n message: `Loading table ${name}...`,\n current: loadedCount,\n });\n tables[name] = applyColumnFilter(\n await this.getTable(name),\n this.#columns,\n );\n }\n\n if (depth < forwardLimit) {\n const rels = await this.findOutgoingRelations(name);\n for (const rel of rels) {\n if (!this.isRelationshipVisible(rel)) continue;\n this.addRelationship(rel, allRelationships, seenRelationships);\n if (!forwardVisited.has(rel.referenced_table)) {\n forwardQueue.push({ name: rel.referenced_table, depth: depth + 1 });\n }\n }\n }\n }\n\n // Process backward (parent\u2192child)\n const backwardLimit = backward === true ? Infinity : backward || 0;\n while (backwardQueue.length > 0) {\n const item = backwardQueue.shift();\n if (!item) break;\n const { name, depth } = item;\n\n if (backwardVisited.has(name)) continue;\n backwardVisited.add(name);\n\n if (!tables[name]) {\n loadedCount++;\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'tables',\n table: name,\n message: `Loading table ${name}...`,\n current: loadedCount,\n });\n tables[name] = applyColumnFilter(\n await this.getTable(name),\n this.#columns,\n );\n }\n\n if (depth < backwardLimit) {\n const rels = await this.findIncomingRelations(name);\n for (const rel of rels) {\n if (!this.isRelationshipVisible(rel)) continue;\n this.addRelationship(rel, allRelationships, seenRelationships);\n if (!backwardVisited.has(rel.table)) {\n backwardQueue.push({ name: rel.table, depth: depth + 1 });\n }\n }\n }\n }\n\n // Write to context\n const tablesList = Object.values(tables);\n ctx.tables.push(...tablesList);\n ctx.relationships.push(...allRelationships);\n }\n\n /**\n * Apply the filter to get seed table names.\n * If filter is an explicit array, skip querying all table names.\n */\n protected async applyFilter(): Promise<string[]> {\n const filter = this.#filter;\n if (Array.isArray(filter)) {\n return filter;\n }\n const names = await this.getAllTableNames();\n if (!filter) {\n return names;\n }\n if (filter instanceof RegExp) {\n return names.filter((name) => filter.test(name));\n }\n return names.filter(filter);\n }\n\n /**\n * Add a relationship to the collection, deduplicating by key.\n */\n protected addRelationship(\n rel: Relationship,\n all: Relationship[],\n seen: Set<string>,\n ): void {\n const key = `${rel.table}:${rel.from.join(',')}:${rel.referenced_table}:${rel.to.join(',')}`;\n if (!seen.has(key)) {\n seen.add(key);\n all.push(rel);\n }\n }\n\n protected isRelationshipVisible(rel: Relationship): boolean {\n return (\n this.areColumnsVisible(rel.from, this.#columns?.[rel.table]) &&\n this.areColumnsVisible(rel.to, this.#columns?.[rel.referenced_table])\n );\n }\n\n protected areColumnsVisible(names: string[], filter?: Filter): boolean {\n if (!filter) return true;\n return (\n filterColumns(\n names.map((name) => ({ name })),\n filter,\n ).length === names.length\n );\n }\n}\n", "import type { ColumnStats, Filter } from '../adapter.ts';\nimport {\n AbstractGrounding,\n type ColumnsFilter,\n applyColumnFilter,\n} from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Represents a database view with its metadata.\n */\nexport interface View {\n name: string;\n schema?: string;\n rawName?: string;\n /** The SQL definition of the view (CREATE VIEW statement or query) */\n definition?: string;\n columns: {\n name: string;\n type: string;\n /** Low cardinality marker */\n kind?: 'LowCardinality';\n /** Distinct values for low cardinality columns */\n values?: string[];\n /** Column statistics (min, max, nullFraction) */\n stats?: ColumnStats;\n }[];\n}\n\n/**\n * Configuration for ViewGrounding.\n */\nexport interface ViewGroundingConfig {\n /** Filter to select views */\n filter?: Filter;\n /**\n * Per-view column filter.\n * Maps view name to a Filter that selects which columns to keep.\n * Views not listed keep all their columns.\n */\n columns?: ColumnsFilter;\n /** Whether to fetch the SQL definition of each view (default: true) */\n includeDefinition?: boolean;\n}\n\n/**\n * Abstract base class for view grounding\n *\n * The `execute()` method implements the algorithm that discovers views.\n * Subclasses implement the database-specific hooks:\n * - `getAllViewNames()` - list all views\n * - `getView()` - get view metadata\n */\nexport abstract class ViewGrounding extends AbstractGrounding {\n #filter?: Filter;\n #columns?: ColumnsFilter;\n protected includeDefinition: boolean;\n\n constructor(config: ViewGroundingConfig = {}) {\n super('view', 'views');\n this.#filter = config.filter;\n this.#columns = config.columns;\n this.includeDefinition = config.includeDefinition ?? true;\n }\n\n /** Get all view names in the database */\n protected abstract getAllViewNames(): Promise<string[]>;\n\n /** Get full view metadata for a single view */\n protected abstract getView(viewName: string): Promise<View>;\n\n /**\n * Execute the grounding process.\n * Writes discovered views to the context.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const viewNames = await this.applyFilter();\n const views = await Promise.all(\n viewNames.map(async (name, index) => {\n ctx.onProgress?.({\n type: 'phase:progress',\n phase: 'views',\n table: name,\n message: `Loading view ${name}...`,\n current: index + 1,\n total: viewNames.length,\n });\n return applyColumnFilter(await this.getView(name), this.#columns);\n }),\n );\n ctx.views.push(...views);\n }\n\n /**\n * Apply the filter to get view names.\n * If filter is an explicit array, skip querying all view names.\n */\n protected async applyFilter(): Promise<string[]> {\n const filter = this.#filter;\n if (Array.isArray(filter)) {\n return filter;\n }\n const names = await this.getAllViewNames();\n if (!filter) {\n return names;\n }\n if (filter instanceof RegExp) {\n return names.filter((name) => filter.test(name));\n }\n return names.filter(filter);\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAwBO,SAAS,cACd,SACA,QACK;AACL,MAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,WAAO,QAAQ,OAAO,CAAC,QAAQ,OAAO,SAAS,IAAI,IAAI,CAAC;AAAA,EAC1D;AACA,MAAI,kBAAkB,QAAQ;AAC5B,WAAO,QAAQ,OAAO,CAAC,QAAQ,OAAO,KAAK,IAAI,IAAI,CAAC;AAAA,EACtD;AACA,SAAO,QAAQ,OAAO,CAAC,QAAQ,OAAO,IAAI,IAAI,CAAC;AACjD;AAMO,SAAS,kBAEd,QAAW,eAAkC;AAC7C,M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AI,MAAM,QAAQ,MAAM,GAAG;AACzB,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,MAAM,KAAK,gBAAgB;AACzC,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ;AAC5B,aAAO,MAAM,OAAO,CAAC,SAAS,OAAO,KAAK,IAAI,CAAC;AAAA,IACjD;AACA,WAAO,MAAM,OAAO,MAAM;AAAA,EAC5B;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { FragmentObject } from '@deepagents/context';\n\nimport type { Adapter, IntrospectionPhase } from '../adapter.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Filter type for table names.\n * - string[]: explicit list of table names\n * - RegExp: pattern to match table names\n * - function: predicate to filter table names\n */\nexport type Filter = string[] | RegExp | ((tableName: string) => boolean);\n\n/**\n * Per-entity column filter.\n * Maps entity name (table or view) to a Filter that selects which columns to keep.\n * Entities not listed in the record keep all their columns.\n */\nexport type ColumnsFilter = Record<string, Filter>;\n\n/**\n * Filter a columns array using a Filter.\n * Keeps columns whose name matches the filter.\n */\nexport function filterColumns<T extends { name: string }>(\n columns: T[],\n filter: Filter,\n): T[] {\n if (Array.isArray(filter)) {\n return columns.filter((col) => filter.includes(col.name));\n }\n if (filter instanceof RegExp) {\n return columns.filter((col) => filter.test(col.name));\n }\n return columns.filter((col) => filter(col.name));\n}\n\n/**\n * Apply per-entity column filtering.\n * Returns the entity unchanged if no filter matches its name.\n */\nexport function applyColumnFilter<\n T extends { name: string; columns: { name: string }[] },\n>(entity: T, columnsConfig?: ColumnsFilter): T {\n if (!columnsConfig) return entity;\n const filter = columnsConfig[entity.name];\n if (!filter) return entity;\n return { ...entity, columns: filterColumns(entity.columns, filter) } as T;\n}\n\nexport interface AdapterInfo {\n dialect: string;\n version?: string;\n database?: string;\n details?: FragmentObject;\n}\nexport type AdapterInfoProvider =\n | AdapterInfo\n | (() => Promise<AdapterInfo> | AdapterInfo);\n\n/**\n * Abstract base class for database schema groundings.\n *\n * Groundings collect schema metadata into the shared GroundingContext.\n * Fragment generation is centralized in Adapter.introspect().\n */\nexport abstract class AbstractGrounding {\n /**\n * Grounding identifier for debugging/logging.\n */\n name: string;\n phase?: IntrospectionPhase;\n\n constructor(name: string, phase?: IntrospectionPhase) {\n this.name = name;\n this.phase = phase;\n }\n\n /**\n * Execute grounding to populate the shared context.\n * Groundings mutate ctx to add their collected data (tables, views, indexes, etc).\n * Fragment generation happens centrally in Adapter after all groundings complete.\n *\n * @param ctx - Shared context for accumulating schema data\n */\n abstract execute(ctx: GroundingContext): Promise<void>;\n}\n\nclass SampleDataGrounding {\n // this will fetch sample data for tables matching the filter\n}\n\nclass FunctionGrounding {\n #filter: Filter;\n #adapter: Adapter;\n constructor(adapter: Adapter, filter: Filter) {\n this.#filter = filter;\n this.#adapter = adapter;\n }\n}\n", "import type { ColumnStats } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { Column, ColumnContainer, GroundingContext } from './context.ts';\n\n/**\n * Configuration for ColumnStatsGrounding.\n */\nexport interface ColumnStatsGroundingConfig {\n // Future: filter which tables/columns to collect stats for\n}\n\n/**\n * Abstract base class for column statistics grounding.\n *\n * Reads tables and views from the context and annotates their columns\n * with statistics (min, max, nullFraction).\n *\n * Subclasses implement database-specific hooks:\n * - `collectStats()` - collect min/max/nullFraction for a column\n */\nexport abstract class ColumnStatsGrounding extends AbstractGrounding {\n constructor(config: ColumnStatsGroundingConfig = {}) {\n super('columnStats', 'column_stats');\n }\n\n /**\n * Collect min/max/nullFraction statistics for a column.\n * Return undefined to skip this column.\n */\n protected abstract collectStats(\n tableName: string,\n column: Column,\n ): Promise<ColumnStats | undefined>;\n\n /**\n * Execute the grounding process.\n * Annotates columns in ctx.tables and ctx.views with statistics.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n // Process both tables and views\n const allContainers: ColumnContainer[] = [...ctx.tables, ...ctx.views];\n const total = allContainers.length;\n for (let i = 0; i < allContainers.length; i++) {\n const container = allContainers[i];\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'column_stats',\n table: container.name,\n message: `Collecting stats for ${container.name}...`,\n current: i + 1,\n total,\n });\n for (const column of container.columns) {\n // Collect min/max/nullFraction\n try {\n const stats = await this.collectStats(container.name, column);\n if (stats) {\n column.stats = stats;\n }\n } catch (error) {\n // Skip on error\n console.warn(\n 'Error collecting stats for',\n container.name,\n column.name,\n error,\n );\n }\n }\n }\n }\n}\n", "import type { Table, TableConstraint } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { Column, ColumnContainer, GroundingContext } from './context.ts';\n\nexport type { Column, ColumnContainer };\n\n/**\n * Result of column value detection.\n */\nexport type ColumnValuesResult = {\n kind: 'Enum' | 'LowCardinality';\n values: string[];\n};\n\n/**\n * Configuration for ColumnValuesGrounding.\n */\nexport interface ColumnValuesGroundingConfig {\n /** Maximum number of distinct values to consider low cardinality (default: 20) */\n lowCardinalityLimit?: number;\n /** Maximum character length for individual values. Columns with any value exceeding this are skipped entirely (default: 100) */\n maxValueLength?: number;\n}\n\n/**\n * Abstract base class for column values grounding.\n *\n * Discovers possible values for columns from three sources (in priority order):\n * 1. Native ENUM types (PostgreSQL, MySQL) \u2192 kind: 'Enum'\n * 2. CHECK constraints with IN clauses \u2192 kind: 'Enum'\n * 3. Low cardinality data scan \u2192 kind: 'LowCardinality'\n *\n * Subclasses implement database-specific hooks:\n * - `collectEnumValues()` - get values for native ENUM columns\n * - `collectLowCardinality()` - collect distinct values via data scan\n */\nexport abstract class ColumnValuesGrounding extends AbstractGrounding {\n protected lowCardinalityLimit: number;\n protected maxValueLength: number;\n\n constructor(config: ColumnValuesGroundingConfig = {}) {\n super('columnValues', 'column_values');\n this.lowCardinalityLimit = config.lowCardinalityLimit ?? 20;\n this.maxValueLength = config.maxValueLength ?? 100;\n }\n\n /**\n * Get values for native ENUM type columns.\n * Return undefined if column is not an ENUM type.\n * Default implementation returns undefined (no native ENUM support).\n */\n protected async collectEnumValues(\n _tableName: string,\n _column: Column,\n ): Promise<string[] | undefined> {\n return undefined;\n }\n\n /**\n * Collect distinct values for low cardinality columns via data scan.\n * Return undefined if column has too many distinct values.\n */\n protected abstract collectLowCardinality(\n tableName: string,\n column: Column,\n ): Promise<string[] | undefined>;\n\n /**\n * Parse CHECK constraint for enum-like IN clause.\n * Extracts values from patterns like:\n * - CHECK (status IN ('active', 'inactive'))\n * - CHECK ((status)::text = ANY (ARRAY['a'::text, 'b'::text]))\n * - CHECK (status = 'active' OR status = 'inactive')\n */\n protected parseCheckConstraint(\n constraint: TableConstraint,\n columnName: string,\n ): string[] | undefined {\n if (constraint.type !== 'CHECK' || !constraint.definition) {\n return undefined;\n }\n\n // Check if constraint applies to this column\n if (constraint.columns && !constraint.columns.includes(columnName)) {\n return undefined;\n }\n\n const def = constraint.definition;\n const escapedCol = this.escapeRegex(columnName);\n\n // Column pattern: matches column name with optional parens and type cast\n // e.g., \"status\", \"(status)\", \"((status)::text)\"\n const colPattern = `(?:\\\\(?\\\\(?${escapedCol}\\\\)?(?:::(?:text|varchar|character varying))?\\\\)?)`;\n\n // Pattern 1: column IN ('val1', 'val2', ...)\n const inMatch = def.match(\n new RegExp(`${colPattern}\\\\s+IN\\\\s*\\\\(([^)]+)\\\\)`, 'i'),\n );\n if (inMatch) {\n return this.extractStringValues(inMatch[1]);\n }\n\n // Pattern 2: PostgreSQL ANY(ARRAY[...])\n const anyMatch = def.match(\n new RegExp(\n `${colPattern}\\\\s*=\\\\s*ANY\\\\s*\\\\(\\\\s*(?:ARRAY)?\\\\s*\\\\[([^\\\\]]+)\\\\]`,\n 'i',\n ),\n );\n if (anyMatch) {\n return this.extractStringValues(anyMatch[1]);\n }\n\n // Pattern 3: column = 'val1' OR column = 'val2' ...\n const orPattern = new RegExp(\n `\\\\b${this.escapeRegex(columnName)}\\\\b\\\\s*=\\\\s*'([^']*)'`,\n 'gi',\n );\n const orMatches = [...def.matchAll(orPattern)];\n if (orMatches.length >= 2) {\n return orMatches.map((m) => m[1]);\n }\n\n return undefined;\n }\n\n /**\n * Extract string values from a comma-separated list.\n */\n private extractStringValues(input: string): string[] | undefined {\n const values: string[] = [];\n // Match quoted strings: 'value' or 'value'::type\n const matches = input.matchAll(/'([^']*)'/g);\n for (const match of matches) {\n values.push(match[1]);\n }\n return values.length > 0 ? values : undefined;\n }\n\n /**\n * Escape special regex characters in a string.\n */\n private escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n }\n\n /**\n * Get the table from context by name.\n */\n private getTable(ctx: GroundingContext, name: string): Table | undefined {\n return ctx.tables.find((t) => t.name === name);\n }\n\n /**\n * Execute the grounding process.\n * Annotates columns in ctx.tables and ctx.views with values.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n // Process both tables and views\n const allContainers: ColumnContainer[] = [...ctx.tables, ...ctx.views];\n\n const total = allContainers.length;\n for (let i = 0; i < allContainers.length; i++) {\n const container = allContainers[i];\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'column_values',\n table: container.name,\n message: `Collecting column values for ${container.name}...`,\n current: i + 1,\n total,\n });\n const table = this.getTable(ctx, container.name);\n\n for (const column of container.columns) {\n try {\n const result = await this.resolveColumnValues(\n container.name,\n column,\n table?.constraints,\n );\n if (result) {\n column.kind = result.kind;\n column.values = result.values;\n }\n } catch (error) {\n console.warn(\n 'Error collecting column values for',\n container.name,\n column.name,\n error,\n );\n }\n }\n }\n }\n\n private exceedsMaxValueLength(values: string[]): boolean {\n return values.some((v) => v.length > this.maxValueLength);\n }\n\n /**\n * Resolve column values from all sources in priority order.\n */\n private async resolveColumnValues(\n tableName: string,\n column: Column,\n constraints?: TableConstraint[],\n ): Promise<ColumnValuesResult | undefined> {\n // Priority 1: Native ENUM type\n const enumValues = await this.collectEnumValues(tableName, column);\n if (enumValues?.length && !this.exceedsMaxValueLength(enumValues)) {\n return { kind: 'Enum', values: enumValues };\n }\n\n // Priority 2: CHECK constraint with IN clause\n if (constraints) {\n for (const constraint of constraints) {\n const checkValues = this.parseCheckConstraint(constraint, column.name);\n if (checkValues?.length && !this.exceedsMaxValueLength(checkValues)) {\n return { kind: 'Enum', values: checkValues };\n }\n }\n }\n\n // Priority 3: Low cardinality data scan\n const lowCardValues = await this.collectLowCardinality(tableName, column);\n if (lowCardValues?.length && !this.exceedsMaxValueLength(lowCardValues)) {\n return { kind: 'LowCardinality', values: lowCardValues };\n }\n\n return undefined;\n }\n}\n", "import type { TableConstraint } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for ConstraintGrounding.\n */\nexport interface ConstraintGroundingConfig {\n // Future: filter which tables/constraint types to collect\n}\n\n/**\n * Abstract base class for constraint grounding.\n *\n * Reads tables from the context and annotates them with constraints\n * (CHECK, UNIQUE, NOT_NULL, DEFAULT).\n * This grounding must run AFTER TableGrounding since it reads from ctx.tables.\n *\n * Subclasses implement the database-specific hook:\n * - `getConstraints()` - fetch constraints for a table\n */\nexport abstract class ConstraintGrounding extends AbstractGrounding {\n constructor(config: ConstraintGroundingConfig = {}) {\n super('constraint', 'constraints');\n }\n\n /**\n * Fetch constraints for a specific table.\n */\n protected abstract getConstraints(\n tableName: string,\n ): Promise<TableConstraint[]>;\n\n /**\n * Execute the grounding process.\n * Annotates tables in ctx.tables with their constraints.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const total = ctx.tables.length;\n for (let i = 0; i < ctx.tables.length; i++) {\n const table = ctx.tables[i];\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'constraints',\n table: table.name,\n message: `Loading constraints for ${table.name}...`,\n current: i + 1,\n total,\n });\n try {\n table.constraints = await this.getConstraints(table.name);\n } catch (error) {\n // Skip on error - table might not exist or be inaccessible\n console.warn('Error collecting constraints for', table.name, error);\n }\n }\n }\n}\n", "import type {\n AdapterInfo,\n ColumnStats,\n OnProgress,\n Relationship,\n Table,\n} from '../adapter.ts';\nimport type { View } from './view.grounding.ts';\n\n/**\n * Column type for grounding operations.\n * Common interface between Table.columns and View.columns.\n */\nexport interface Column {\n name: string;\n type: string;\n kind?: 'LowCardinality' | 'Enum';\n values?: string[];\n stats?: ColumnStats;\n}\n\n/**\n * Entity with columns (Table or View).\n */\nexport interface ColumnContainer {\n name: string;\n columns: Column[];\n}\n\n/**\n * Shared context object passed to all groundings.\n * Groundings read from and write to this context.\n */\nexport interface GroundingContext {\n /** Tables discovered by TableGrounding */\n tables: Table[];\n\n /** Views discovered by ViewGrounding */\n views: View[];\n\n /** Relationships discovered by TableGrounding */\n relationships: Relationship[];\n\n /** Database info collected by InfoGrounding */\n info?: AdapterInfo;\n\n /** Shared cache for cross-grounding deduplication. Keyed by `type:key`. */\n cache: Map<string, unknown>;\n\n /** Progress sink for long-running introspection work. */\n onProgress: OnProgress;\n}\n\nconst noopProgress: OnProgress = () => {};\n\nfunction timestampProgress(onProgress?: OnProgress): OnProgress {\n if (!onProgress) return noopProgress;\n return (progress) => {\n onProgress({\n ...progress,\n timestampMs: progress.timestampMs ?? Date.now(),\n });\n };\n}\n\n/**\n * Create a new empty grounding context.\n */\nexport function createGroundingContext(\n options: { onProgress?: OnProgress } = {},\n): GroundingContext {\n return {\n tables: [],\n views: [],\n relationships: [],\n info: undefined,\n cache: new Map(),\n onProgress: timestampProgress(options.onProgress),\n };\n}\n", "import type { AdapterInfo } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for InfoGrounding.\n */\nexport interface InfoGroundingConfig {\n // Future: options to control what info to collect\n}\n\n/**\n * Abstract base class for database info grounding.\n *\n * Collects database dialect, version, and connection info.\n *\n * Subclasses implement the database-specific hook:\n * - `collectInfo()` - collect database info\n */\nexport abstract class InfoGrounding extends AbstractGrounding {\n constructor(config: InfoGroundingConfig = {}) {\n super('dialectInfo', 'info');\n }\n\n /**\n * Collect database dialect, version, and other info.\n */\n protected abstract collectInfo(): Promise<AdapterInfo>;\n\n /**\n * Execute the grounding process.\n * Writes database info to ctx.info.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n ctx.info = await this.collectInfo();\n }\n}\n", "import type { Table } from '../adapter.ts';\nimport { AbstractGrounding } from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for RowCountGrounding.\n */\nexport interface RowCountGroundingConfig {\n // Future: filter which tables to count\n}\n\n/**\n * Abstract base class for row count grounding.\n *\n * Reads tables from the context and annotates them with row counts and size hints.\n * This grounding must run AFTER TableGrounding since it reads from ctx.tables.\n *\n * Subclasses implement the database-specific hook:\n * - `getRowCount()` - get row count for a table\n */\nexport abstract class RowCountGrounding extends AbstractGrounding {\n constructor(config: RowCountGroundingConfig = {}) {\n super('rowCount', 'row_counts');\n }\n\n /**\n * Get row count for a specific table.\n */\n protected abstract getRowCount(\n tableName: string,\n ): Promise<number | undefined>;\n\n /**\n * Execute the grounding process.\n * Annotates tables in ctx.tables with row counts and size hints.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const total = ctx.tables.length;\n for (let i = 0; i < ctx.tables.length; i++) {\n const table = ctx.tables[i];\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'row_counts',\n table: table.name,\n message: `Counting rows in ${table.name}...`,\n current: i + 1,\n total,\n });\n const count = await this.getRowCount(table.name);\n if (count != null) {\n table.rowCount = count;\n table.sizeHint = this.#classifyRowCount(count);\n }\n }\n }\n\n /**\n * Classify row count into a size hint category.\n */\n #classifyRowCount(count: number): Table['sizeHint'] {\n if (count < 100) return 'tiny';\n if (count < 1000) return 'small';\n if (count < 10000) return 'medium';\n if (count < 100000) return 'large';\n return 'huge';\n }\n}\n", "import type { Filter, Relationship, Table } from '../adapter.ts';\nimport {\n AbstractGrounding,\n type ColumnsFilter,\n applyColumnFilter,\n filterColumns,\n} from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Configuration for TableGrounding.\n */\nexport interface TableGroundingConfig {\n /** Filter to select seed tables */\n filter?: Filter;\n /**\n * Per-table column filter.\n * Maps table name to a Filter that selects which columns to keep.\n * Tables not listed keep all their columns.\n */\n columns?: ColumnsFilter;\n /**\n * Traverse forward (child\u2192parent) following FK direction.\n * - true: unlimited depth\n * - number: maximum depth\n * - false/undefined: no forward traversal\n */\n forward?: boolean | number;\n /**\n * Traverse backward (parent\u2192child) finding tables that reference us.\n * - true: unlimited depth\n * - number: maximum depth\n * - false/undefined: no backward traversal\n */\n backward?: boolean | number;\n}\n\n/**\n * Abstract base class for table grounding.\n *\n * The `execute()` method implements a BFS traversal algorithm that discovers\n * tables and relationships. Subclasses implement the database-specific hooks:\n * - `getAllTableNames()` - list all tables\n * - `getTable()` - get table metadata\n * - `findOutgoingRelations()` - find FKs FROM a table\n * - `findIncomingRelations()` - find FKs TO a table\n */\nexport abstract class TableGrounding extends AbstractGrounding {\n #filter?: Filter;\n #columns?: ColumnsFilter;\n #forward?: boolean | number;\n #backward?: boolean | number;\n\n constructor(config: TableGroundingConfig = {}) {\n super('table', 'tables');\n this.#filter = config.filter;\n this.#columns = config.columns;\n this.#forward = config.forward;\n this.#backward = config.backward;\n }\n\n /** Get all table names in the database */\n protected abstract getAllTableNames(): Promise<string[]>;\n\n /** Get full table metadata for a single table */\n protected abstract getTable(tableName: string): Promise<Table>;\n\n /** Find FKs FROM this table (outgoing relationships) */\n protected abstract findOutgoingRelations(\n tableName: string,\n ): Promise<Relationship[]>;\n\n /** Find FKs TO this table (incoming relationships) */\n protected abstract findIncomingRelations(\n tableName: string,\n ): Promise<Relationship[]>;\n\n /**\n * Execute the grounding process.\n * Writes discovered tables and relationships to the context.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const seedTables = await this.applyFilter();\n const forward = this.#forward;\n const backward = this.#backward;\n\n // No traversal at all - just add the seed tables\n if (!forward && !backward) {\n const tables = await Promise.all(\n seedTables.map(async (name, index) => {\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'tables',\n table: name,\n message: `Loading table ${name}...`,\n current: index + 1,\n total: seedTables.length,\n });\n return applyColumnFilter(await this.getTable(name), this.#columns);\n }),\n );\n ctx.tables.push(...tables);\n return;\n }\n\n const tables: Record<string, Table> = {};\n const allRelationships: Relationship[] = [];\n const seenRelationships = new Set<string>();\n\n // Track depth separately for forward/backward using BFS\n const forwardQueue: Array<{ name: string; depth: number }> = [];\n const backwardQueue: Array<{ name: string; depth: number }> = [];\n const forwardVisited = new Set<string>();\n const backwardVisited = new Set<string>();\n let loadedCount = 0;\n\n // Initialize queues with seed tables at depth 0\n for (const name of seedTables) {\n if (forward) forwardQueue.push({ name, depth: 0 });\n if (backward) backwardQueue.push({ name, depth: 0 });\n }\n\n // Process forward (child\u2192parent)\n const forwardLimit = forward === true ? Infinity : forward || 0;\n while (forwardQueue.length > 0) {\n const item = forwardQueue.shift();\n if (!item) break;\n const { name, depth } = item;\n\n if (forwardVisited.has(name)) continue;\n forwardVisited.add(name);\n\n if (!tables[name]) {\n loadedCount++;\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'tables',\n table: name,\n message: `Loading table ${name}...`,\n current: loadedCount,\n });\n tables[name] = applyColumnFilter(\n await this.getTable(name),\n this.#columns,\n );\n }\n\n if (depth < forwardLimit) {\n const rels = await this.findOutgoingRelations(name);\n for (const rel of rels) {\n if (!this.isRelationshipVisible(rel)) continue;\n this.addRelationship(rel, allRelationships, seenRelationships);\n if (!forwardVisited.has(rel.referenced_table)) {\n forwardQueue.push({ name: rel.referenced_table, depth: depth + 1 });\n }\n }\n }\n }\n\n // Process backward (parent\u2192child)\n const backwardLimit = backward === true ? Infinity : backward || 0;\n while (backwardQueue.length > 0) {\n const item = backwardQueue.shift();\n if (!item) break;\n const { name, depth } = item;\n\n if (backwardVisited.has(name)) continue;\n backwardVisited.add(name);\n\n if (!tables[name]) {\n loadedCount++;\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'tables',\n table: name,\n message: `Loading table ${name}...`,\n current: loadedCount,\n });\n tables[name] = applyColumnFilter(\n await this.getTable(name),\n this.#columns,\n );\n }\n\n if (depth < backwardLimit) {\n const rels = await this.findIncomingRelations(name);\n for (const rel of rels) {\n if (!this.isRelationshipVisible(rel)) continue;\n this.addRelationship(rel, allRelationships, seenRelationships);\n if (!backwardVisited.has(rel.table)) {\n backwardQueue.push({ name: rel.table, depth: depth + 1 });\n }\n }\n }\n }\n\n // Write to context\n const tablesList = Object.values(tables);\n ctx.tables.push(...tablesList);\n ctx.relationships.push(...allRelationships);\n }\n\n /**\n * Apply the filter to get seed table names.\n * If filter is an explicit array, skip querying all table names.\n */\n protected async applyFilter(): Promise<string[]> {\n const filter = this.#filter;\n if (Array.isArray(filter)) {\n return filter;\n }\n const names = await this.getAllTableNames();\n if (!filter) {\n return names;\n }\n if (filter instanceof RegExp) {\n return names.filter((name) => filter.test(name));\n }\n return names.filter(filter);\n }\n\n /**\n * Add a relationship to the collection, deduplicating by key.\n */\n protected addRelationship(\n rel: Relationship,\n all: Relationship[],\n seen: Set<string>,\n ): void {\n const key = `${rel.table}:${rel.from.join(',')}:${rel.referenced_table}:${rel.to.join(',')}`;\n if (!seen.has(key)) {\n seen.add(key);\n all.push(rel);\n }\n }\n\n protected isRelationshipVisible(rel: Relationship): boolean {\n return (\n this.areColumnsVisible(rel.from, this.#columns?.[rel.table]) &&\n this.areColumnsVisible(rel.to, this.#columns?.[rel.referenced_table])\n );\n }\n\n protected areColumnsVisible(names: string[], filter?: Filter): boolean {\n if (!filter) return true;\n return (\n filterColumns(\n names.map((name) => ({ name })),\n filter,\n ).length === names.length\n );\n }\n}\n", "import type { ColumnStats, Filter } from '../adapter.ts';\nimport {\n AbstractGrounding,\n type ColumnsFilter,\n applyColumnFilter,\n} from './abstract.grounding.ts';\nimport type { GroundingContext } from './context.ts';\n\n/**\n * Represents a database view with its metadata.\n */\nexport interface View {\n name: string;\n schema?: string;\n rawName?: string;\n /** The SQL definition of the view (CREATE VIEW statement or query) */\n definition?: string;\n columns: {\n name: string;\n type: string;\n /** Low cardinality marker */\n kind?: 'LowCardinality';\n /** Distinct values for low cardinality columns */\n values?: string[];\n /** Column statistics (min, max, nullFraction) */\n stats?: ColumnStats;\n }[];\n}\n\n/**\n * Configuration for ViewGrounding.\n */\nexport interface ViewGroundingConfig {\n /** Filter to select views */\n filter?: Filter;\n /**\n * Per-view column filter.\n * Maps view name to a Filter that selects which columns to keep.\n * Views not listed keep all their columns.\n */\n columns?: ColumnsFilter;\n /** Whether to fetch the SQL definition of each view (default: true) */\n includeDefinition?: boolean;\n}\n\n/**\n * Abstract base class for view grounding\n *\n * The `execute()` method implements the algorithm that discovers views.\n * Subclasses implement the database-specific hooks:\n * - `getAllViewNames()` - list all views\n * - `getView()` - get view metadata\n */\nexport abstract class ViewGrounding extends AbstractGrounding {\n #filter?: Filter;\n #columns?: ColumnsFilter;\n protected includeDefinition: boolean;\n\n constructor(config: ViewGroundingConfig = {}) {\n super('view', 'views');\n this.#filter = config.filter;\n this.#columns = config.columns;\n this.includeDefinition = config.includeDefinition ?? true;\n }\n\n /** Get all view names in the database */\n protected abstract getAllViewNames(): Promise<string[]>;\n\n /** Get full view metadata for a single view */\n protected abstract getView(viewName: string): Promise<View>;\n\n /**\n * Execute the grounding process.\n * Writes discovered views to the context.\n */\n async execute(ctx: GroundingContext): Promise<void> {\n const viewNames = await this.applyFilter();\n const views = await Promise.all(\n viewNames.map(async (name, index) => {\n ctx.onProgress({\n type: 'phase:progress',\n phase: 'views',\n table: name,\n message: `Loading view ${name}...`,\n current: index + 1,\n total: viewNames.length,\n });\n return applyColumnFilter(await this.getView(name), this.#columns);\n }),\n );\n ctx.views.push(...views);\n }\n\n /**\n * Apply the filter to get view names.\n * If filter is an explicit array, skip querying all view names.\n */\n protected async applyFilter(): Promise<string[]> {\n const filter = this.#filter;\n if (Array.isArray(filter)) {\n return filter;\n }\n const names = await this.getAllViewNames();\n if (!filter) {\n return names;\n }\n if (filter instanceof RegExp) {\n return names.filter((name) => filter.test(name));\n }\n return names.filter(filter);\n }\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AAK,WAAW,OAAO;AACvB,SAAK,oBAAoB,OAAO,qBAAqB;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,QAAQ,KAAsC;AAClD,UAAM,YAAY,MAAM,KAAK,YAAY;AACzC,UAAM,QAAQ,MAAM,QAAQ;AAAA,MAC1B,UAAU,IAAI,OAAO,MAAM,UAAU;AACnC,YAAI,WAAW;AAAA,UACb,MAAM;AAAA,UACN,OAAO;AAAA,UACP,OAAO;AAAA,UACP,SAAS,gBAAgB,IAAI;AAAA,UAC7B,SAAS,QAAQ;AAAA,UACjB,OAAO,UAAU;AAAA,QACnB,CAAC;AACD,eAAO,kBAAkB,MAAM,KAAK,QAAQ,IAAI,GAAG,KAAK,QAAQ;AAAA,MAClE,CAAC;AAAA,IACH;AACA,QAAI,MAAM,KAAK,GAAG,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAgB,cAAiC;AAC/C,UAAM,SAAS,KAAK;AACpB,QAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,MAAM,KAAK,gBAAgB;AACzC,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ;AAC5B,aAAO,MAAM,OAAO,CAAC,SAAS,OAAO,KAAK,IAAI,CAAC;AAAA,IACjD;AACA,WAAO,MAAM,OAAO,MAAM;AAAA,EAC5B;AACF;",
|
|
6
6
|
"names": ["tables"]
|
|
7
7
|
}
|
|
@@ -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,
|
|
@@ -1837,7 +1848,7 @@ var ViewGrounding = class extends AbstractGrounding {
|
|
|
1837
1848
|
const viewNames = await this.applyFilter();
|
|
1838
1849
|
const views2 = await Promise.all(
|
|
1839
1850
|
viewNames.map(async (name, index2) => {
|
|
1840
|
-
ctx.onProgress
|
|
1851
|
+
ctx.onProgress({
|
|
1841
1852
|
type: "phase:progress",
|
|
1842
1853
|
phase: "views",
|
|
1843
1854
|
table: name,
|