@deepagents/text2sql 7.1.0 → 7.1.2

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 (69) hide show
  1. package/README.md +61 -76
  2. package/dist/bin/sql.js +42 -584
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +170 -265
  6. package/dist/index.js.map +4 -4
  7. package/dist/lib/adapter-index.d.ts +0 -2
  8. package/dist/lib/adapter-index.d.ts.map +1 -1
  9. package/dist/lib/adapters/bigquery/constraint.bigquery.grounding.d.ts.map +1 -1
  10. package/dist/lib/adapters/bigquery/index.js +14 -17
  11. package/dist/lib/adapters/bigquery/index.js.map +2 -2
  12. package/dist/lib/adapters/bigquery/table.bigquery.grounding.d.ts +2 -2
  13. package/dist/lib/adapters/bigquery/table.bigquery.grounding.d.ts.map +1 -1
  14. package/dist/lib/adapters/clickhouse/clickhouse.sql-policy.d.ts.map +1 -1
  15. package/dist/lib/adapters/clickhouse/index.js +13 -9
  16. package/dist/lib/adapters/clickhouse/index.js.map +3 -3
  17. package/dist/lib/adapters/duckdb/duckdb.d.ts.map +1 -1
  18. package/dist/lib/adapters/duckdb/duckdb.sql-policy.d.ts.map +1 -1
  19. package/dist/lib/adapters/duckdb/index.js +12 -4
  20. package/dist/lib/adapters/duckdb/index.js.map +4 -4
  21. package/dist/lib/adapters/groundings/index.js +2 -2
  22. package/dist/lib/adapters/groundings/index.js.map +2 -2
  23. package/dist/lib/adapters/groundings/table.grounding.d.ts +2 -2
  24. package/dist/lib/adapters/groundings/table.grounding.d.ts.map +1 -1
  25. package/dist/lib/adapters/mysql/index.js +2 -2
  26. package/dist/lib/adapters/mysql/index.js.map +2 -2
  27. package/dist/lib/adapters/postgres/column-values.postgres.grounding.d.ts.map +1 -1
  28. package/dist/lib/adapters/postgres/index.js +17 -17
  29. package/dist/lib/adapters/postgres/index.js.map +2 -2
  30. package/dist/lib/adapters/posthog/index.js.map +2 -2
  31. package/dist/lib/adapters/posthog/posthog.d.ts.map +1 -1
  32. package/dist/lib/adapters/posthog/schema.posthog.grounding.d.ts.map +1 -1
  33. package/dist/lib/adapters/spreadsheet/index.js +9 -7
  34. package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
  35. package/dist/lib/adapters/spreadsheet/spreadsheet.d.ts.map +1 -1
  36. package/dist/lib/adapters/sqlite/index.js +2 -5
  37. package/dist/lib/adapters/sqlite/index.js.map +2 -2
  38. package/dist/lib/adapters/sqlite/sqlite.d.ts.map +1 -1
  39. package/dist/lib/adapters/sqlserver/index.js +45 -61
  40. package/dist/lib/adapters/sqlserver/index.js.map +2 -2
  41. package/dist/lib/adapters/sqlserver/table.sqlserver.grounding.d.ts +1 -1
  42. package/dist/lib/adapters/sqlserver/table.sqlserver.grounding.d.ts.map +1 -1
  43. package/dist/lib/agents/question.agent.d.ts.map +1 -1
  44. package/dist/lib/agents/suggestions.agents.d.ts.map +1 -1
  45. package/dist/lib/fs/mssql/mssql-fs.d.ts +3 -2
  46. package/dist/lib/fs/mssql/mssql-fs.d.ts.map +1 -1
  47. package/dist/lib/fs/postgres/postgres-fs.d.ts +3 -2
  48. package/dist/lib/fs/postgres/postgres-fs.d.ts.map +1 -1
  49. package/dist/lib/fs/sqlite/sqlite-fs.d.ts.map +1 -1
  50. package/dist/lib/index-cache.d.ts +2 -3
  51. package/dist/lib/index-cache.d.ts.map +1 -1
  52. package/dist/lib/sql-command.d.ts +1 -4
  53. package/dist/lib/sql-command.d.ts.map +1 -1
  54. package/dist/lib/sql.d.ts +0 -5
  55. package/dist/lib/sql.d.ts.map +1 -1
  56. package/dist/lib/synthesis/decorators/filtered-producer.d.ts.map +1 -1
  57. package/dist/lib/synthesis/extractors/base-contextual-extractor.d.ts.map +1 -1
  58. package/dist/lib/synthesis/extractors/segmented-context-extractor.d.ts.map +1 -1
  59. package/dist/lib/synthesis/extractors/sql-extractor.d.ts.map +1 -1
  60. package/dist/lib/synthesis/index.js +3 -3
  61. package/dist/lib/synthesis/index.js.map +2 -2
  62. package/dist/lib/synthesis/synthesizers/breadth-evolver.d.ts.map +1 -1
  63. package/dist/lib/synthesis/synthesizers/depth-evolver.d.ts.map +1 -1
  64. package/dist/lib/synthesis/synthesizers/persona-generator.d.ts.map +1 -1
  65. package/package.json +18 -7
  66. package/dist/lib/index-lock.d.ts +0 -60
  67. package/dist/lib/index-lock.d.ts.map +0 -1
  68. package/dist/lib/prompt.d.ts +0 -2
  69. package/dist/lib/prompt.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -486,15 +486,15 @@ SQL: ${sql.trim()}`,
486
486
  */
487
487
  rowsFrom(result, paths) {
488
488
  if (Array.isArray(result)) return result;
489
- for (const path7 of paths) {
490
- const rows = path7.split(".").reduce(
489
+ for (const path6 of paths) {
490
+ const rows = path6.split(".").reduce(
491
491
  (value, key) => typeof value === "object" && value !== null ? Reflect.get(value, key) : void 0,
492
492
  result
493
493
  );
494
494
  if (Array.isArray(rows)) return rows;
495
495
  }
496
496
  throw new Error(
497
- `${this.constructor.name} execute() must return an array of rows or an object holding one at ${paths.map((path7) => `result.${path7}`).join(", ")}.`
497
+ `${this.constructor.name} execute() must return an array of rows or an object holding one at ${paths.map((path6) => `result.${path6}`).join(", ")}.`
498
498
  );
499
499
  }
500
500
  /**
@@ -1203,51 +1203,6 @@ function isFragmentList(value) {
1203
1203
  return Array.isArray(value) && value.every((item) => isFragment(item) && isFragmentData(item));
1204
1204
  }
1205
1205
 
1206
- // packages/text2sql/src/lib/index-lock.ts
1207
- import { createHash as createHash2 } from "node:crypto";
1208
- import { mkdir as mkdir2 } from "node:fs/promises";
1209
- import { tmpdir as tmpdir2 } from "node:os";
1210
- import * as path2 from "node:path";
1211
- import { lock as acquireLock } from "proper-lockfile";
1212
- var DEFAULT_STALE_MS = 3e4;
1213
- var DEFAULT_RETRIES = {
1214
- retries: 10,
1215
- factor: 2,
1216
- minTimeout: 100,
1217
- maxTimeout: 2e3
1218
- };
1219
- var FileIndexLock = class {
1220
- #dir;
1221
- #namespace;
1222
- #stale;
1223
- #retries;
1224
- constructor(options = {}) {
1225
- this.#dir = options.dir ?? tmpdir2();
1226
- this.#namespace = options.namespace;
1227
- this.#stale = options.stale ?? DEFAULT_STALE_MS;
1228
- this.#retries = options.retries ?? DEFAULT_RETRIES;
1229
- }
1230
- async run(key, fn) {
1231
- await mkdir2(this.#dir, { recursive: true });
1232
- const release = await acquireLock(this.#lockPathFor(key), {
1233
- realpath: false,
1234
- stale: this.#stale,
1235
- retries: this.#retries
1236
- });
1237
- try {
1238
- return await fn();
1239
- } finally {
1240
- await release().catch(() => {
1241
- });
1242
- }
1243
- }
1244
- #lockPathFor(key) {
1245
- const watermark = this.#namespace ? `${this.#namespace}-${key}` : key;
1246
- const hash2 = createHash2("md5").update(watermark).digest("hex");
1247
- return path2.join(this.#dir, `text2sql-lock-${hash2}`);
1248
- }
1249
- };
1250
-
1251
1206
  // packages/text2sql/src/lib/adapter-index.ts
1252
1207
  var TEXT2SQL_INDEX_PROGRESS_CHUNK = "data-text2sql-index-progress";
1253
1208
  var noopProgressHandler = () => {
@@ -1267,7 +1222,6 @@ function databaseNameFragment(name) {
1267
1222
  var AdapterIndexer = class {
1268
1223
  #adapters;
1269
1224
  #cache;
1270
- #lock;
1271
1225
  constructor(options) {
1272
1226
  const adapterNames = Object.keys(options.adapters);
1273
1227
  if (adapterNames.length === 0) {
@@ -1276,7 +1230,6 @@ var AdapterIndexer = class {
1276
1230
  validateAdapterNames(adapterNames);
1277
1231
  this.#adapters = options.adapters;
1278
1232
  this.#cache = options.cache;
1279
- this.#lock = options.lock;
1280
1233
  }
1281
1234
  async index(options = {}) {
1282
1235
  const progress = timestampProgressHandler(options.onProgress);
@@ -1334,41 +1287,15 @@ var AdapterIndexer = class {
1334
1287
  message: `Indexing adapter "${name}"...`
1335
1288
  });
1336
1289
  const cache = this.#cache;
1337
- const key = name;
1338
- const emitCacheHit = () => progress({
1339
- type: "adapter:cache-hit",
1340
- adapter: name,
1341
- message: `Using cached index for adapter "${name}".`,
1342
- cached: true
1343
- });
1344
- const emitCacheMiss = () => progress({
1345
- type: "adapter:cache-miss",
1346
- adapter: name,
1347
- message: `No cached index for adapter "${name}".`,
1348
- cached: false
1349
- });
1350
- const introspect = async () => {
1351
- const ctx = createGroundingContext({
1352
- onProgress: (event) => progress(adapterProgressEvent(name, event))
1353
- });
1354
- const fragments = await adapter.introspect(ctx);
1355
- await cache?.write(key, fragments);
1356
- return fragments;
1357
- };
1358
- let servedFromCache = false;
1359
- const populate = async () => {
1360
- const recheck = await cache?.read(key);
1361
- if (recheck) {
1362
- servedFromCache = true;
1363
- return recheck;
1364
- }
1365
- if (cache) emitCacheMiss();
1366
- return introspect();
1367
- };
1368
1290
  try {
1369
- const cached = await cache?.read(key);
1291
+ const cached = await cache?.read(name);
1370
1292
  if (cached) {
1371
- emitCacheHit();
1293
+ progress({
1294
+ type: "adapter:cache-hit",
1295
+ adapter: name,
1296
+ message: `Using cached index for adapter "${name}".`,
1297
+ cached: true
1298
+ });
1372
1299
  progress({
1373
1300
  type: "adapter:end",
1374
1301
  adapter: name,
@@ -1377,13 +1304,24 @@ var AdapterIndexer = class {
1377
1304
  });
1378
1305
  return cached;
1379
1306
  }
1380
- const fragments = await this.#lock.run(key, populate);
1381
- if (servedFromCache) emitCacheHit();
1307
+ if (cache) {
1308
+ progress({
1309
+ type: "adapter:cache-miss",
1310
+ adapter: name,
1311
+ message: `No cached index for adapter "${name}".`,
1312
+ cached: false
1313
+ });
1314
+ }
1315
+ const ctx = createGroundingContext({
1316
+ onProgress: (event) => progress(adapterProgressEvent(name, event))
1317
+ });
1318
+ const fragments = await adapter.introspect(ctx);
1319
+ await cache?.write(name, fragments);
1382
1320
  progress({
1383
1321
  type: "adapter:end",
1384
1322
  adapter: name,
1385
1323
  message: `Finished indexing adapter "${name}".`,
1386
- cached: servedFromCache
1324
+ cached: false
1387
1325
  });
1388
1326
  return fragments;
1389
1327
  } catch (error) {
@@ -1429,7 +1367,7 @@ function errorMessage(error) {
1429
1367
  }
1430
1368
 
1431
1369
  // packages/text2sql/src/lib/checkpoint.ts
1432
- import { createHash as createHash3 } from "node:crypto";
1370
+ import { createHash as createHash2 } from "node:crypto";
1433
1371
  import { existsSync as existsSync2, readFileSync, renameSync, writeFileSync } from "node:fs";
1434
1372
  import pLimit from "p-limit";
1435
1373
  import z4 from "zod";
@@ -1450,9 +1388,9 @@ var Checkpoint = class _Checkpoint {
1450
1388
  points;
1451
1389
  path;
1452
1390
  configHash;
1453
- constructor(path7, configHash, points) {
1391
+ constructor(path6, configHash, points) {
1454
1392
  this.points = points;
1455
- this.path = path7;
1393
+ this.path = path6;
1456
1394
  this.configHash = configHash;
1457
1395
  }
1458
1396
  /**
@@ -1460,14 +1398,14 @@ var Checkpoint = class _Checkpoint {
1460
1398
  * Handles corrupted files and config changes gracefully.
1461
1399
  */
1462
1400
  static async load(options) {
1463
- const { path: path7, configHash } = options;
1464
- if (existsSync2(path7)) {
1401
+ const { path: path6, configHash } = options;
1402
+ if (existsSync2(path6)) {
1465
1403
  try {
1466
- const content = readFileSync(path7, "utf-8");
1404
+ const content = readFileSync(path6, "utf-8");
1467
1405
  const file = checkpointFile.parse(JSON.parse(content));
1468
1406
  if (configHash && file.configHash && file.configHash !== configHash) {
1469
1407
  console.log("\u26A0 Config changed, starting fresh");
1470
- return new _Checkpoint(path7, configHash, {});
1408
+ return new _Checkpoint(path6, configHash, {});
1471
1409
  }
1472
1410
  const points = file.points;
1473
1411
  const totalEntries = Object.values(points).reduce(
@@ -1475,14 +1413,14 @@ var Checkpoint = class _Checkpoint {
1475
1413
  0
1476
1414
  );
1477
1415
  console.log(`\u2713 Resuming from checkpoint (${totalEntries} entries)`);
1478
- return new _Checkpoint(path7, configHash, points);
1416
+ return new _Checkpoint(path6, configHash, points);
1479
1417
  } catch {
1480
1418
  console.log("\u26A0 Checkpoint corrupted, starting fresh");
1481
- return new _Checkpoint(path7, configHash, {});
1419
+ return new _Checkpoint(path6, configHash, {});
1482
1420
  }
1483
1421
  }
1484
1422
  console.log("Starting new checkpoint");
1485
- return new _Checkpoint(path7, configHash, {});
1423
+ return new _Checkpoint(path6, configHash, {});
1486
1424
  }
1487
1425
  /**
1488
1426
  * Run a single computation with checkpointing.
@@ -1558,7 +1496,7 @@ var Checkpoint = class _Checkpoint {
1558
1496
  }
1559
1497
  };
1560
1498
  function hash(value) {
1561
- return createHash3("md5").update(JSON.stringify(value)).digest("hex");
1499
+ return createHash2("md5").update(JSON.stringify(value)).digest("hex");
1562
1500
  }
1563
1501
  var Point = class {
1564
1502
  #stored;
@@ -1603,11 +1541,11 @@ var Point = class {
1603
1541
  }
1604
1542
  };
1605
1543
  function hashConfig(config) {
1606
- return createHash3("md5").update(JSON.stringify(config)).digest("hex");
1544
+ return createHash2("md5").update(JSON.stringify(config)).digest("hex");
1607
1545
  }
1608
1546
 
1609
1547
  // packages/text2sql/src/lib/fs/sqlite/sqlite-fs.ts
1610
- import * as path3 from "node:path";
1548
+ import * as path2 from "node:path";
1611
1549
  import { DatabaseSync } from "node:sqlite";
1612
1550
  import z6 from "zod";
1613
1551
 
@@ -1684,7 +1622,7 @@ var SqliteFs = class {
1684
1622
  const segments = p.split("/").filter(Boolean);
1685
1623
  let currentPath = "/";
1686
1624
  for (let i = 0; i < segments.length - 1; i++) {
1687
- currentPath = path3.posix.join(currentPath, segments[i]);
1625
+ currentPath = path2.posix.join(currentPath, segments[i]);
1688
1626
  const exists = this.#stmt("SELECT 1 FROM fs_entries WHERE path = ?").get(
1689
1627
  currentPath
1690
1628
  );
@@ -1705,7 +1643,7 @@ var SqliteFs = class {
1705
1643
  return stmt;
1706
1644
  }
1707
1645
  #normalizeRoot(root) {
1708
- return path3.posix.resolve("/", root.trim());
1646
+ return path2.posix.resolve("/", root.trim());
1709
1647
  }
1710
1648
  #prefixPath(p) {
1711
1649
  if (!this.#root) {
@@ -1714,7 +1652,7 @@ var SqliteFs = class {
1714
1652
  if (p === "/") {
1715
1653
  return this.#root;
1716
1654
  }
1717
- return path3.posix.join(this.#root, p);
1655
+ return path2.posix.join(this.#root, p);
1718
1656
  }
1719
1657
  #unprefixPath(p) {
1720
1658
  if (!this.#root) {
@@ -1735,15 +1673,18 @@ var SqliteFs = class {
1735
1673
  this.#db.exec("COMMIT");
1736
1674
  return result;
1737
1675
  } catch (error) {
1738
- this.#db.exec("ROLLBACK");
1676
+ try {
1677
+ this.#db.exec("ROLLBACK");
1678
+ } catch {
1679
+ }
1739
1680
  throw error;
1740
1681
  }
1741
1682
  }
1742
1683
  #normalizePath(p) {
1743
- return path3.posix.resolve("/", p);
1684
+ return path2.posix.resolve("/", p);
1744
1685
  }
1745
1686
  #dirname(p) {
1746
- const dir = path3.posix.dirname(p);
1687
+ const dir = path2.posix.dirname(p);
1747
1688
  return dir === "" ? "/" : dir;
1748
1689
  }
1749
1690
  #ensureParentExists(filePath) {
@@ -1817,7 +1758,7 @@ var SqliteFs = class {
1817
1758
  }
1818
1759
  seen.add(p);
1819
1760
  const target = this.#normalizePath(
1820
- path3.posix.resolve(this.#dirname(p), entry.symlinkTarget)
1761
+ path2.posix.resolve(this.#dirname(p), entry.symlinkTarget)
1821
1762
  );
1822
1763
  return this.#resolveSymlink(target, seen);
1823
1764
  }
@@ -1970,11 +1911,11 @@ var SqliteFs = class {
1970
1911
  this.#useTransaction(() => {
1971
1912
  if (options?.recursive) {
1972
1913
  const rootPath = this.#root || "/";
1973
- const relativePath = path3.posix.relative(rootPath, prefixed);
1914
+ const relativePath = path2.posix.relative(rootPath, prefixed);
1974
1915
  const segments = relativePath.split("/").filter(Boolean);
1975
1916
  let currentPath = rootPath;
1976
1917
  for (const segment of segments) {
1977
- currentPath = path3.posix.join(currentPath, segment);
1918
+ currentPath = path2.posix.join(currentPath, segment);
1978
1919
  const exists = typeRow.optional().parse(
1979
1920
  this.#stmt("SELECT type FROM fs_entries WHERE path = ?").get(
1980
1921
  currentPath
@@ -2031,7 +1972,7 @@ var SqliteFs = class {
2031
1972
  AND path NOT LIKE ? || '%/%'`
2032
1973
  ).all(prefix, resolved, prefix)
2033
1974
  );
2034
- return rows.map((row) => path3.posix.basename(row.path));
1975
+ return rows.map((row) => path2.posix.basename(row.path));
2035
1976
  }
2036
1977
  async readdirWithFileTypes(dirPath) {
2037
1978
  const normalized = this.#normalizePath(dirPath);
@@ -2056,7 +1997,7 @@ var SqliteFs = class {
2056
1997
  ).all(prefix, resolved, prefix)
2057
1998
  );
2058
1999
  return rows.map((row) => ({
2059
- name: path3.posix.basename(row.path),
2000
+ name: path2.posix.basename(row.path),
2060
2001
  isFile: row.type === "file",
2061
2002
  isDirectory: row.type === "directory",
2062
2003
  isSymbolicLink: row.type === "symlink"
@@ -2113,8 +2054,8 @@ var SqliteFs = class {
2113
2054
  ).all(srcPrefixed, srcPrefixed)
2114
2055
  );
2115
2056
  for (const entry of allEntries) {
2116
- const relativePath = path3.posix.relative(srcPrefixed, entry.path);
2117
- const newPath = path3.posix.join(destPrefixed, relativePath);
2057
+ const relativePath = path2.posix.relative(srcPrefixed, entry.path);
2058
+ const newPath = path2.posix.join(destPrefixed, relativePath);
2118
2059
  this.#stmt(
2119
2060
  `INSERT OR REPLACE INTO fs_entries (path, type, mode, size, mtime, symlinkTarget)
2120
2061
  VALUES (?, ?, ?, ?, ?, ?)`
@@ -2179,8 +2120,8 @@ var SqliteFs = class {
2179
2120
  ).all(srcPrefixed, srcPrefixed)
2180
2121
  );
2181
2122
  for (const entry of [...allEntries].reverse()) {
2182
- const relativePath = path3.posix.relative(srcPrefixed, entry.path);
2183
- const newPath = path3.posix.join(destPrefixed, relativePath);
2123
+ const relativePath = path2.posix.relative(srcPrefixed, entry.path);
2124
+ const newPath = path2.posix.join(destPrefixed, relativePath);
2184
2125
  this.#stmt(
2185
2126
  `INSERT INTO fs_entries (path, type, mode, size, mtime, symlinkTarget)
2186
2127
  VALUES (?, ?, ?, ?, ?, ?)`
@@ -2229,7 +2170,7 @@ var SqliteFs = class {
2229
2170
  });
2230
2171
  }
2231
2172
  resolvePath(base, relativePath) {
2232
- return path3.posix.resolve(base, relativePath);
2173
+ return path2.posix.resolve(base, relativePath);
2233
2174
  }
2234
2175
  getAllPaths() {
2235
2176
  const rows = z6.array(pathRow).parse(this.#stmt("SELECT path FROM fs_entries ORDER BY path").all());
@@ -2339,7 +2280,7 @@ var SqliteFs = class {
2339
2280
 
2340
2281
  // packages/text2sql/src/lib/fs/mssql/mssql-fs.ts
2341
2282
  import { createRequire } from "node:module";
2342
- import * as path4 from "node:path";
2283
+ import * as path3 from "node:path";
2343
2284
  import z7 from "zod";
2344
2285
 
2345
2286
  // packages/text2sql/src/lib/fs/mssql/ddl.mssql-fs.ts
@@ -2406,7 +2347,6 @@ var MssqlFs = class _MssqlFs {
2406
2347
  #root;
2407
2348
  #schema;
2408
2349
  #ownsPool;
2409
- #isInitialized = false;
2410
2350
  constructor(options) {
2411
2351
  this.#chunkSize = options.chunkSize ?? 1024 * 1024;
2412
2352
  const schema = options.schema ?? "dbo";
@@ -2438,7 +2378,18 @@ var MssqlFs = class _MssqlFs {
2438
2378
  #t(name) {
2439
2379
  return `[${this.#schema}].[${name}]`;
2440
2380
  }
2441
- async initialize() {
2381
+ /** Opens the file system: creates its tables and its root directories. */
2382
+ static async create(options) {
2383
+ const fs = new _MssqlFs(options);
2384
+ try {
2385
+ await fs.#initialize();
2386
+ } catch (error) {
2387
+ await fs.close();
2388
+ throw error;
2389
+ }
2390
+ return fs;
2391
+ }
2392
+ async #initialize() {
2442
2393
  if (this.#ownsPool) {
2443
2394
  await this.#pool.connect();
2444
2395
  }
@@ -2460,12 +2411,12 @@ var MssqlFs = class _MssqlFs {
2460
2411
  }
2461
2412
  const rootSlashExists = rowsOf(
2462
2413
  existsRow,
2463
- await this.#rawQuery(
2414
+ await this.#query(
2464
2415
  `SELECT CASE WHEN EXISTS(SELECT 1 FROM ${this.#t("fs_entries")} WHERE path = '/') THEN 1 ELSE 0 END as [exists]`
2465
2416
  )
2466
2417
  );
2467
2418
  if (rootSlashExists[0].exists === 0) {
2468
- await this.#rawExec(
2419
+ await this.#exec(
2469
2420
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime) VALUES ('/', 'directory', 493, 0, @p0)`,
2470
2421
  [Date.now()]
2471
2422
  );
@@ -2474,55 +2425,47 @@ var MssqlFs = class _MssqlFs {
2474
2425
  await this.#createParentDirs(this.#root);
2475
2426
  const rootExists = rowsOf(
2476
2427
  existsRow,
2477
- await this.#rawQuery(
2428
+ await this.#query(
2478
2429
  `SELECT CASE WHEN EXISTS(SELECT 1 FROM ${this.#t("fs_entries")} WHERE path = @p0) THEN 1 ELSE 0 END as [exists]`,
2479
2430
  [this.#root]
2480
2431
  )
2481
2432
  );
2482
2433
  if (rootExists[0].exists === 0) {
2483
- await this.#rawExec(
2434
+ await this.#exec(
2484
2435
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime) VALUES (@p0, 'directory', 493, 0, @p1)`,
2485
2436
  [this.#root, Date.now()]
2486
2437
  );
2487
2438
  }
2488
2439
  }
2489
- this.#isInitialized = true;
2490
- }
2491
- #ensureInitialized() {
2492
- if (!this.#isInitialized) {
2493
- throw new Error(
2494
- "MssqlFs not initialized. Call await fs.initialize() after construction."
2495
- );
2496
- }
2497
2440
  }
2498
2441
  async #createParentDirs(p) {
2499
2442
  const segments = p.split("/").filter(Boolean);
2500
2443
  let currentPath = "/";
2501
2444
  for (let i = 0; i < segments.length - 1; i++) {
2502
- currentPath = path4.posix.join(currentPath, segments[i]);
2445
+ currentPath = path3.posix.join(currentPath, segments[i]);
2503
2446
  const exists = rowsOf(
2504
2447
  existsRow,
2505
- await this.#rawQuery(
2448
+ await this.#query(
2506
2449
  `SELECT CASE WHEN EXISTS(SELECT 1 FROM ${this.#t("fs_entries")} WHERE path = @p0) THEN 1 ELSE 0 END as [exists]`,
2507
2450
  [currentPath]
2508
2451
  )
2509
2452
  );
2510
2453
  if (exists[0].exists === 0) {
2511
- await this.#rawExec(
2454
+ await this.#exec(
2512
2455
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime) VALUES (@p0, 'directory', 493, 0, @p1)`,
2513
2456
  [currentPath, Date.now()]
2514
2457
  );
2515
2458
  }
2516
2459
  }
2517
2460
  }
2518
- #rawQuery(sql, params) {
2461
+ #query(sql, params) {
2519
2462
  const request = this.#pool.request();
2520
2463
  params?.forEach((value, index2) => {
2521
2464
  request.input(`p${index2}`, value);
2522
2465
  });
2523
2466
  return request.query(sql);
2524
2467
  }
2525
- async #rawExec(sql, params) {
2468
+ async #exec(sql, params) {
2526
2469
  const request = this.#pool.request();
2527
2470
  params?.forEach((value, index2) => {
2528
2471
  request.input(`p${index2}`, value);
@@ -2530,16 +2473,7 @@ var MssqlFs = class _MssqlFs {
2530
2473
  const result = await request.query(sql);
2531
2474
  return result.rowsAffected[0] ?? 0;
2532
2475
  }
2533
- async #query(sql, params) {
2534
- this.#ensureInitialized();
2535
- return this.#rawQuery(sql, params);
2536
- }
2537
- async #exec(sql, params) {
2538
- this.#ensureInitialized();
2539
- return this.#rawExec(sql, params);
2540
- }
2541
2476
  async #useTransaction(fn) {
2542
- this.#ensureInitialized();
2543
2477
  const mssql = _MssqlFs.#requireMssql();
2544
2478
  const transaction = new mssql.Transaction(this.#pool);
2545
2479
  try {
@@ -2553,7 +2487,7 @@ var MssqlFs = class _MssqlFs {
2553
2487
  }
2554
2488
  }
2555
2489
  #normalizeRoot(root) {
2556
- return path4.posix.resolve("/", root.trim());
2490
+ return path3.posix.resolve("/", root.trim());
2557
2491
  }
2558
2492
  #prefixPath(p) {
2559
2493
  if (!this.#root) {
@@ -2562,7 +2496,7 @@ var MssqlFs = class _MssqlFs {
2562
2496
  if (p === "/") {
2563
2497
  return this.#root;
2564
2498
  }
2565
- return path4.posix.join(this.#root, p);
2499
+ return path3.posix.join(this.#root, p);
2566
2500
  }
2567
2501
  #unprefixPath(p) {
2568
2502
  if (!this.#root) {
@@ -2577,10 +2511,10 @@ var MssqlFs = class _MssqlFs {
2577
2511
  return p;
2578
2512
  }
2579
2513
  #normalizePath(p) {
2580
- return path4.posix.resolve("/", p);
2514
+ return path3.posix.resolve("/", p);
2581
2515
  }
2582
2516
  #dirname(p) {
2583
- const dir = path4.posix.dirname(p);
2517
+ const dir = path3.posix.dirname(p);
2584
2518
  return dir === "" ? "/" : dir;
2585
2519
  }
2586
2520
  async #ensureParentExists(filePath, transaction) {
@@ -2664,7 +2598,7 @@ var MssqlFs = class _MssqlFs {
2664
2598
  }
2665
2599
  seen.add(p);
2666
2600
  const target = this.#normalizePath(
2667
- path4.posix.resolve(this.#dirname(p), entry.symlinkTarget)
2601
+ path3.posix.resolve(this.#dirname(p), entry.symlinkTarget)
2668
2602
  );
2669
2603
  return this.#resolveSymlink(target, seen);
2670
2604
  }
@@ -2861,11 +2795,11 @@ var MssqlFs = class _MssqlFs {
2861
2795
  await this.#useTransaction(async (transaction) => {
2862
2796
  if (options?.recursive) {
2863
2797
  const rootPath = this.#root || "/";
2864
- const relativePath = path4.posix.relative(rootPath, prefixed);
2798
+ const relativePath = path3.posix.relative(rootPath, prefixed);
2865
2799
  const segments = relativePath.split("/").filter(Boolean);
2866
2800
  let currentPath = rootPath;
2867
2801
  for (const segment of segments) {
2868
- currentPath = path4.posix.join(currentPath, segment);
2802
+ currentPath = path3.posix.join(currentPath, segment);
2869
2803
  const checkReq = transaction.request();
2870
2804
  checkReq.input("p0", currentPath);
2871
2805
  const [exists] = rowsOf(
@@ -2938,7 +2872,7 @@ var MssqlFs = class _MssqlFs {
2938
2872
  [prefix, resolved]
2939
2873
  )
2940
2874
  );
2941
- return rows.map((row) => path4.posix.basename(row.path));
2875
+ return rows.map((row) => path3.posix.basename(row.path));
2942
2876
  }
2943
2877
  async readdirWithFileTypes(dirPath) {
2944
2878
  const normalized = this.#normalizePath(dirPath);
@@ -2969,7 +2903,7 @@ var MssqlFs = class _MssqlFs {
2969
2903
  )
2970
2904
  );
2971
2905
  return rows.map((row) => ({
2972
- name: path4.posix.basename(row.path),
2906
+ name: path3.posix.basename(row.path),
2973
2907
  isFile: row.type === "file",
2974
2908
  isDirectory: row.type === "directory",
2975
2909
  isSymbolicLink: row.type === "symlink"
@@ -3048,8 +2982,8 @@ var MssqlFs = class _MssqlFs {
3048
2982
  )
3049
2983
  );
3050
2984
  for (const entry of allEntries) {
3051
- const relativePath = path4.posix.relative(srcPrefixed, entry.path);
3052
- const newPath = path4.posix.join(destPrefixed, relativePath);
2985
+ const relativePath = path3.posix.relative(srcPrefixed, entry.path);
2986
+ const newPath = path3.posix.join(destPrefixed, relativePath);
3053
2987
  const insertReq = transaction.request();
3054
2988
  insertReq.input("p0", newPath);
3055
2989
  insertReq.input("p1", entry.type);
@@ -3169,8 +3103,8 @@ var MssqlFs = class _MssqlFs {
3169
3103
  `DELETE FROM ${this.#t("fs_entries")} WHERE path = @dp0 OR path LIKE @dp0 + '/%'`
3170
3104
  );
3171
3105
  for (const entry of [...allEntries].reverse()) {
3172
- const relativePath = path4.posix.relative(srcPrefixed, entry.path);
3173
- const newPath = path4.posix.join(destPrefixed, relativePath);
3106
+ const relativePath = path3.posix.relative(srcPrefixed, entry.path);
3107
+ const newPath = path3.posix.join(destPrefixed, relativePath);
3174
3108
  const insertReq = transaction.request();
3175
3109
  insertReq.input("p0", newPath);
3176
3110
  insertReq.input("p1", entry.type);
@@ -3269,7 +3203,7 @@ var MssqlFs = class _MssqlFs {
3269
3203
  });
3270
3204
  }
3271
3205
  resolvePath(base, relativePath) {
3272
- return path4.posix.resolve(base, relativePath);
3206
+ return path3.posix.resolve(base, relativePath);
3273
3207
  }
3274
3208
  getAllPaths() {
3275
3209
  throw new Error(
@@ -3429,7 +3363,7 @@ var MssqlFs = class _MssqlFs {
3429
3363
 
3430
3364
  // packages/text2sql/src/lib/fs/postgres/postgres-fs.ts
3431
3365
  import { createRequire as createRequire2 } from "node:module";
3432
- import * as path5 from "node:path";
3366
+ import * as path4 from "node:path";
3433
3367
  import z8 from "zod";
3434
3368
 
3435
3369
  // packages/text2sql/src/lib/fs/postgres/ddl.postgres-fs.ts
@@ -3492,7 +3426,6 @@ var PostgresFs = class _PostgresFs {
3492
3426
  #root;
3493
3427
  #schema;
3494
3428
  #ownsPool;
3495
- #isInitialized = false;
3496
3429
  constructor(options) {
3497
3430
  this.#chunkSize = options.chunkSize ?? 1024 * 1024;
3498
3431
  const schema = options.schema ?? "public";
@@ -3524,17 +3457,28 @@ var PostgresFs = class _PostgresFs {
3524
3457
  #t(name) {
3525
3458
  return `"${this.#schema}"."${name}"`;
3526
3459
  }
3527
- async initialize() {
3460
+ /** Opens the file system: creates its tables and its root directories. */
3461
+ static async create(options) {
3462
+ const fs = new _PostgresFs(options);
3463
+ try {
3464
+ await fs.#initialize();
3465
+ } catch (error) {
3466
+ await fs.close();
3467
+ throw error;
3468
+ }
3469
+ return fs;
3470
+ }
3471
+ async #initialize() {
3528
3472
  const ddl = postgresFsDDL(this.#schema);
3529
3473
  await this.#pool.query(ddl);
3530
3474
  const rootSlashExists = rowsOf2(
3531
3475
  existsRow2,
3532
- await this.#rawQuery(
3476
+ await this.#query(
3533
3477
  `SELECT EXISTS(SELECT 1 FROM ${this.#t("fs_entries")} WHERE path = '/') AS exists`
3534
3478
  )
3535
3479
  );
3536
3480
  if (!rootSlashExists[0].exists) {
3537
- await this.#rawExec(
3481
+ await this.#exec(
3538
3482
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime) VALUES ('/', 'directory', 493, 0, $1)`,
3539
3483
  [Date.now()]
3540
3484
  );
@@ -3543,64 +3487,47 @@ var PostgresFs = class _PostgresFs {
3543
3487
  await this.#createParentDirs(this.#root);
3544
3488
  const rootExists = rowsOf2(
3545
3489
  existsRow2,
3546
- await this.#rawQuery(
3490
+ await this.#query(
3547
3491
  `SELECT EXISTS(SELECT 1 FROM ${this.#t("fs_entries")} WHERE path = $1) AS exists`,
3548
3492
  [this.#root]
3549
3493
  )
3550
3494
  );
3551
3495
  if (!rootExists[0].exists) {
3552
- await this.#rawExec(
3496
+ await this.#exec(
3553
3497
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime) VALUES ($1, 'directory', 493, 0, $2)`,
3554
3498
  [this.#root, Date.now()]
3555
3499
  );
3556
3500
  }
3557
3501
  }
3558
- this.#isInitialized = true;
3559
- }
3560
- #ensureInitialized() {
3561
- if (!this.#isInitialized) {
3562
- throw new Error(
3563
- "PostgresFs not initialized. Call await fs.initialize() after construction."
3564
- );
3565
- }
3566
3502
  }
3567
3503
  async #createParentDirs(p) {
3568
3504
  const segments = p.split("/").filter(Boolean);
3569
3505
  let currentPath = "/";
3570
3506
  for (let i = 0; i < segments.length - 1; i++) {
3571
- currentPath = path5.posix.join(currentPath, segments[i]);
3507
+ currentPath = path4.posix.join(currentPath, segments[i]);
3572
3508
  const exists = rowsOf2(
3573
3509
  existsRow2,
3574
- await this.#rawQuery(
3510
+ await this.#query(
3575
3511
  `SELECT EXISTS(SELECT 1 FROM ${this.#t("fs_entries")} WHERE path = $1) AS exists`,
3576
3512
  [currentPath]
3577
3513
  )
3578
3514
  );
3579
3515
  if (!exists[0].exists) {
3580
- await this.#rawExec(
3516
+ await this.#exec(
3581
3517
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime) VALUES ($1, 'directory', 493, 0, $2)`,
3582
3518
  [currentPath, Date.now()]
3583
3519
  );
3584
3520
  }
3585
3521
  }
3586
3522
  }
3587
- #rawQuery(sql, params) {
3523
+ #query(sql, params) {
3588
3524
  return this.#pool.query(sql, params);
3589
3525
  }
3590
- async #rawExec(sql, params) {
3526
+ async #exec(sql, params) {
3591
3527
  const result = await this.#pool.query(sql, params);
3592
3528
  return result.rowCount ?? 0;
3593
3529
  }
3594
- async #query(sql, params) {
3595
- this.#ensureInitialized();
3596
- return this.#rawQuery(sql, params);
3597
- }
3598
- async #exec(sql, params) {
3599
- this.#ensureInitialized();
3600
- return this.#rawExec(sql, params);
3601
- }
3602
3530
  async #useTransaction(fn) {
3603
- this.#ensureInitialized();
3604
3531
  const client = await this.#pool.connect();
3605
3532
  try {
3606
3533
  await client.query("BEGIN");
@@ -3615,7 +3542,7 @@ var PostgresFs = class _PostgresFs {
3615
3542
  }
3616
3543
  }
3617
3544
  #normalizeRoot(root) {
3618
- return path5.posix.resolve("/", root.trim());
3545
+ return path4.posix.resolve("/", root.trim());
3619
3546
  }
3620
3547
  #prefixPath(p) {
3621
3548
  if (!this.#root) {
@@ -3624,7 +3551,7 @@ var PostgresFs = class _PostgresFs {
3624
3551
  if (p === "/") {
3625
3552
  return this.#root;
3626
3553
  }
3627
- return path5.posix.join(this.#root, p);
3554
+ return path4.posix.join(this.#root, p);
3628
3555
  }
3629
3556
  #unprefixPath(p) {
3630
3557
  if (!this.#root) {
@@ -3639,10 +3566,10 @@ var PostgresFs = class _PostgresFs {
3639
3566
  return p;
3640
3567
  }
3641
3568
  #normalizePath(p) {
3642
- return path5.posix.resolve("/", p);
3569
+ return path4.posix.resolve("/", p);
3643
3570
  }
3644
3571
  #dirname(p) {
3645
- const dir = path5.posix.dirname(p);
3572
+ const dir = path4.posix.dirname(p);
3646
3573
  return dir === "" ? "/" : dir;
3647
3574
  }
3648
3575
  async #ensureParentExists(filePath, client) {
@@ -3718,7 +3645,7 @@ var PostgresFs = class _PostgresFs {
3718
3645
  }
3719
3646
  seen.add(p);
3720
3647
  const target = this.#normalizePath(
3721
- path5.posix.resolve(this.#dirname(p), entry.symlink_target)
3648
+ path4.posix.resolve(this.#dirname(p), entry.symlink_target)
3722
3649
  );
3723
3650
  return this.#resolveSymlink(target, seen);
3724
3651
  }
@@ -3898,11 +3825,11 @@ var PostgresFs = class _PostgresFs {
3898
3825
  await this.#useTransaction(async (client) => {
3899
3826
  if (options?.recursive) {
3900
3827
  const rootPath = this.#root || "/";
3901
- const relativePath = path5.posix.relative(rootPath, prefixed);
3828
+ const relativePath = path4.posix.relative(rootPath, prefixed);
3902
3829
  const segments = relativePath.split("/").filter(Boolean);
3903
3830
  let currentPath = rootPath;
3904
3831
  for (const segment of segments) {
3905
- currentPath = path5.posix.join(currentPath, segment);
3832
+ currentPath = path4.posix.join(currentPath, segment);
3906
3833
  const [exists] = rowsOf2(
3907
3834
  typeRow3,
3908
3835
  await client.query(
@@ -3969,7 +3896,7 @@ var PostgresFs = class _PostgresFs {
3969
3896
  [prefix, resolved]
3970
3897
  )
3971
3898
  );
3972
- return rows.map((row) => path5.posix.basename(row.path));
3899
+ return rows.map((row) => path4.posix.basename(row.path));
3973
3900
  }
3974
3901
  async readdirWithFileTypes(dirPath) {
3975
3902
  const normalized = this.#normalizePath(dirPath);
@@ -4000,7 +3927,7 @@ var PostgresFs = class _PostgresFs {
4000
3927
  )
4001
3928
  );
4002
3929
  return rows.map((row) => ({
4003
- name: path5.posix.basename(row.path),
3930
+ name: path4.posix.basename(row.path),
4004
3931
  isFile: row.type === "file",
4005
3932
  isDirectory: row.type === "directory",
4006
3933
  isSymbolicLink: row.type === "symlink"
@@ -4075,8 +4002,8 @@ var PostgresFs = class _PostgresFs {
4075
4002
  )
4076
4003
  );
4077
4004
  for (const entry of allEntries) {
4078
- const relativePath = path5.posix.relative(srcPrefixed, entry.path);
4079
- const newPath = path5.posix.join(destPrefixed, relativePath);
4005
+ const relativePath = path4.posix.relative(srcPrefixed, entry.path);
4006
+ const newPath = path4.posix.join(destPrefixed, relativePath);
4080
4007
  await client.query(
4081
4008
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime, symlink_target)
4082
4009
  VALUES ($1, $2, $3, $4, $5, $6)
@@ -4176,8 +4103,8 @@ var PostgresFs = class _PostgresFs {
4176
4103
  [destPrefixed]
4177
4104
  );
4178
4105
  for (const entry of [...allEntries].reverse()) {
4179
- const relativePath = path5.posix.relative(srcPrefixed, entry.path);
4180
- const newPath = path5.posix.join(destPrefixed, relativePath);
4106
+ const relativePath = path4.posix.relative(srcPrefixed, entry.path);
4107
+ const newPath = path4.posix.join(destPrefixed, relativePath);
4181
4108
  await client.query(
4182
4109
  `INSERT INTO ${this.#t("fs_entries")} (path, type, mode, size, mtime, symlink_target)
4183
4110
  VALUES ($1, $2, $3, $4, $5, $6)
@@ -4256,7 +4183,7 @@ var PostgresFs = class _PostgresFs {
4256
4183
  });
4257
4184
  }
4258
4185
  resolvePath(base, relativePath) {
4259
- return path5.posix.resolve(base, relativePath);
4186
+ return path4.posix.resolve(base, relativePath);
4260
4187
  }
4261
4188
  getAllPaths() {
4262
4189
  throw new Error(
@@ -4411,29 +4338,29 @@ var ScopedFs = class {
4411
4338
  this.#base = options.base;
4412
4339
  this.#prefix = options.prefix.replace(/\/$/, "");
4413
4340
  }
4414
- #scope(path7) {
4415
- return `${this.#prefix}${path7}`;
4341
+ #scope(path6) {
4342
+ return `${this.#prefix}${path6}`;
4416
4343
  }
4417
- #unscope(path7) {
4418
- if (path7 === this.#prefix) {
4344
+ #unscope(path6) {
4345
+ if (path6 === this.#prefix) {
4419
4346
  return "/";
4420
4347
  }
4421
- if (path7.startsWith(this.#prefix + "/")) {
4422
- return path7.slice(this.#prefix.length) || "/";
4348
+ if (path6.startsWith(this.#prefix + "/")) {
4349
+ return path6.slice(this.#prefix.length) || "/";
4423
4350
  }
4424
- return path7;
4351
+ return path6;
4425
4352
  }
4426
- async writeFile(path7, content, options) {
4427
- await this.#base.writeFile(this.#scope(path7), content, options);
4353
+ async writeFile(path6, content, options) {
4354
+ await this.#base.writeFile(this.#scope(path6), content, options);
4428
4355
  }
4429
- async appendFile(path7, content, options) {
4430
- await this.#base.appendFile(this.#scope(path7), content, options);
4356
+ async appendFile(path6, content, options) {
4357
+ await this.#base.appendFile(this.#scope(path6), content, options);
4431
4358
  }
4432
- async mkdir(path7, options) {
4433
- return this.#base.mkdir(this.#scope(path7), options);
4359
+ async mkdir(path6, options) {
4360
+ return this.#base.mkdir(this.#scope(path6), options);
4434
4361
  }
4435
- async rm(path7, options) {
4436
- await this.#base.rm(this.#scope(path7), options);
4362
+ async rm(path6, options) {
4363
+ await this.#base.rm(this.#scope(path6), options);
4437
4364
  }
4438
4365
  async cp(src, dest, options) {
4439
4366
  await this.#base.cp(this.#scope(src), this.#scope(dest), options);
@@ -4441,8 +4368,8 @@ var ScopedFs = class {
4441
4368
  async mv(src, dest) {
4442
4369
  await this.#base.mv(this.#scope(src), this.#scope(dest));
4443
4370
  }
4444
- async chmod(path7, mode) {
4445
- return this.#base.chmod(this.#scope(path7), mode);
4371
+ async chmod(path6, mode) {
4372
+ return this.#base.chmod(this.#scope(path6), mode);
4446
4373
  }
4447
4374
  async symlink(target, linkPath) {
4448
4375
  await this.#base.symlink(target, this.#scope(linkPath));
@@ -4450,35 +4377,35 @@ var ScopedFs = class {
4450
4377
  async link(existingPath, newPath) {
4451
4378
  await this.#base.link(this.#scope(existingPath), this.#scope(newPath));
4452
4379
  }
4453
- readFile(path7, options) {
4454
- return this.#base.readFile(this.#scope(path7), options);
4380
+ readFile(path6, options) {
4381
+ return this.#base.readFile(this.#scope(path6), options);
4455
4382
  }
4456
- readFileBuffer(path7) {
4457
- return this.#base.readFileBuffer(this.#scope(path7));
4383
+ readFileBuffer(path6) {
4384
+ return this.#base.readFileBuffer(this.#scope(path6));
4458
4385
  }
4459
- stat(path7) {
4460
- return this.#base.stat(this.#scope(path7));
4386
+ stat(path6) {
4387
+ return this.#base.stat(this.#scope(path6));
4461
4388
  }
4462
- lstat(path7) {
4463
- return this.#base.lstat(this.#scope(path7));
4389
+ lstat(path6) {
4390
+ return this.#base.lstat(this.#scope(path6));
4464
4391
  }
4465
- readdir(path7) {
4466
- return this.#base.readdir(this.#scope(path7));
4392
+ readdir(path6) {
4393
+ return this.#base.readdir(this.#scope(path6));
4467
4394
  }
4468
- readdirWithFileTypes(path7) {
4469
- return this.#base.readdirWithFileTypes(this.#scope(path7));
4395
+ readdirWithFileTypes(path6) {
4396
+ return this.#base.readdirWithFileTypes(this.#scope(path6));
4470
4397
  }
4471
- exists(path7) {
4472
- return this.#base.exists(this.#scope(path7));
4398
+ exists(path6) {
4399
+ return this.#base.exists(this.#scope(path6));
4473
4400
  }
4474
- readlink(path7) {
4475
- return this.#base.readlink(this.#scope(path7));
4401
+ readlink(path6) {
4402
+ return this.#base.readlink(this.#scope(path6));
4476
4403
  }
4477
- realpath(path7) {
4478
- return this.#base.realpath(this.#scope(path7)).then((p) => this.#unscope(p));
4404
+ realpath(path6) {
4405
+ return this.#base.realpath(this.#scope(path6)).then((p) => this.#unscope(p));
4479
4406
  }
4480
- utimes(path7, atime, mtime) {
4481
- return this.#base.utimes(this.#scope(path7), atime, mtime);
4407
+ utimes(path6, atime, mtime) {
4408
+ return this.#base.utimes(this.#scope(path6), atime, mtime);
4482
4409
  }
4483
4410
  resolvePath(base, relativePath) {
4484
4411
  return this.#base.resolvePath(base, relativePath);
@@ -4901,8 +4828,8 @@ import { BashTransformPipeline } from "just-bash";
4901
4828
 
4902
4829
  // packages/text2sql/src/lib/agents/sql-transform-plugins.ts
4903
4830
  import { parse as parse2, serialize } from "just-bash";
4904
- import { createHash as createHash4 } from "node:crypto";
4905
- import * as path6 from "node:path";
4831
+ import { createHash as createHash3 } from "node:crypto";
4832
+ import * as path5 from "node:path";
4906
4833
  import {
4907
4834
  BashException,
4908
4835
  asStaticWordText as asStaticWordText2
@@ -5397,7 +5324,7 @@ function isBlockedSimpleCommand(command, context, mode, options) {
5397
5324
  if (!commandName) {
5398
5325
  return false;
5399
5326
  }
5400
- const normalizedName = path6.posix.basename(commandName).toLowerCase();
5327
+ const normalizedName = path5.posix.basename(commandName).toLowerCase();
5401
5328
  if (BLOCKED_DB_CLIENT_COMMANDS.has(normalizedName)) {
5402
5329
  return true;
5403
5330
  }
@@ -5575,7 +5502,7 @@ function rewriteSqlCommand(cmd, ast) {
5575
5502
  const dbName = asStaticWordText2(cmd.args[1]);
5576
5503
  const sqlArgs = cmd.args.slice(2);
5577
5504
  const unquotedSql = extractSqlText(sqlArgs);
5578
- const hash2 = createHash4("sha256").update(serialize(ast)).digest("hex").slice(0, 12);
5505
+ const hash2 = createHash3("sha256").update(serialize(ast)).digest("hex").slice(0, 12);
5579
5506
  const sqlPath = `/tmp/sql-inline-${subcommand}-${hash2}.sql`;
5580
5507
  const heredocTag = `SQL_${hash2.toUpperCase()}`;
5581
5508
  const groupScript = [
@@ -5687,7 +5614,6 @@ import {
5687
5614
  } from "@deepagents/context";
5688
5615
 
5689
5616
  // packages/text2sql/src/lib/sql.ts
5690
- import "@deepagents/agent";
5691
5617
  var text2SqlValidationMarker = /* @__PURE__ */ Symbol("Text2SqlValidationError");
5692
5618
  var text2SqlUnknownAdapterMarker = /* @__PURE__ */ Symbol("Text2SqlUnknownAdapterError");
5693
5619
  var Text2SqlValidationError = class _Text2SqlValidationError extends Error {
@@ -5748,8 +5674,7 @@ var Text2Sql = class {
5748
5674
  this.#config = config;
5749
5675
  this.#indexer = new AdapterIndexer({
5750
5676
  adapters: config.adapters,
5751
- cache: config.cache,
5752
- lock: config.lock
5677
+ cache: config.cache
5753
5678
  });
5754
5679
  }
5755
5680
  #requireAdapter(name) {
@@ -5759,13 +5684,6 @@ var Text2Sql = class {
5759
5684
  }
5760
5685
  return adapter;
5761
5686
  }
5762
- #requireModel(op) {
5763
- const model = this.#config.model;
5764
- if (!model) {
5765
- throw new Error(`Text2Sql.${op}() requires a model in Text2SqlConfig`);
5766
- }
5767
- return model;
5768
- }
5769
5687
  adapterNames() {
5770
5688
  return Object.keys(this.#config.adapters);
5771
5689
  }
@@ -5824,18 +5742,6 @@ var Text2Sql = class {
5824
5742
  onProgress: options.onProgress
5825
5743
  });
5826
5744
  }
5827
- async toSql(input, adapterName) {
5828
- const adapter = this.#requireAdapter(adapterName);
5829
- const model = this.#requireModel("toSql");
5830
- const fragments = await this.#indexer.indexAdapter(adapterName);
5831
- const result = await toSql({
5832
- input,
5833
- adapter,
5834
- fragments,
5835
- model
5836
- });
5837
- return result.sql;
5838
- }
5839
5745
  async toPairs(adapterName, factory) {
5840
5746
  const adapter = this.#requireAdapter(adapterName);
5841
5747
  const producer = factory(adapter);
@@ -6011,7 +5917,6 @@ export {
6011
5917
  Checkpoint,
6012
5918
  FileCache,
6013
5919
  FileIndexCache,
6014
- FileIndexLock,
6015
5920
  JsonCache,
6016
5921
  MssqlFs,
6017
5922
  Point,