@deepagents/text2sql 7.1.4 → 7.3.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 +2 -1
- package/dist/bin/sql.js +8 -9
- package/dist/finetune/convert-to-gguf.d.ts +0 -16
- package/dist/finetune/convert-to-gguf.d.ts.map +1 -1
- package/dist/index.js +70 -29
- package/dist/index.js.map +4 -4
- package/dist/lib/checkpoint.d.ts +6 -0
- package/dist/lib/checkpoint.d.ts.map +1 -1
- package/dist/lib/file-cache.d.ts.map +1 -1
- package/dist/lib/fs/sqlite/ddl.sqlite-fs.d.ts +3 -0
- package/dist/lib/fs/sqlite/ddl.sqlite-fs.d.ts.map +1 -0
- package/dist/lib/fs/sqlite/sqlite-fs.d.ts.map +1 -1
- package/package.json +17 -12
package/README.md
CHANGED
|
@@ -438,7 +438,8 @@ To let only one caller introspect, acquire a key around `index()`. This example
|
|
|
438
438
|
uses [`@zukhruf/mutex`](https://www.npmjs.com/package/@zukhruf/mutex):
|
|
439
439
|
|
|
440
440
|
```typescript
|
|
441
|
-
import { Mutex
|
|
441
|
+
import { Mutex } from '@zukhruf/mutex';
|
|
442
|
+
import { SqliteStore } from '@zukhruf/mutex/sqlite';
|
|
442
443
|
|
|
443
444
|
const mutex = new Mutex(new SqliteStore('/var/lib/my-app/locks'));
|
|
444
445
|
|
package/dist/bin/sql.js
CHANGED
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
} from "@deepagents/context";
|
|
11
11
|
|
|
12
12
|
// packages/text2sql/src/lib/file-cache.ts
|
|
13
|
-
import {
|
|
13
|
+
import { atomicWrite } from "@zukhruf/fs";
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
14
15
|
import { existsSync } from "node:fs";
|
|
15
|
-
import { mkdir, readFile
|
|
16
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
16
17
|
import { tmpdir } from "node:os";
|
|
17
18
|
import path from "node:path";
|
|
18
19
|
var FileCache = class {
|
|
@@ -29,9 +30,7 @@ var FileCache = class {
|
|
|
29
30
|
}
|
|
30
31
|
async set(content) {
|
|
31
32
|
await mkdir(path.dirname(this.path), { recursive: true });
|
|
32
|
-
|
|
33
|
-
await writeFile(tempPath, content, "utf-8");
|
|
34
|
-
await rename(tempPath, this.path);
|
|
33
|
+
await atomicWrite(this.path, content);
|
|
35
34
|
}
|
|
36
35
|
};
|
|
37
36
|
var JsonCache = class extends FileCache {
|
|
@@ -555,7 +554,7 @@ import {
|
|
|
555
554
|
mkdir as mkdir2,
|
|
556
555
|
open,
|
|
557
556
|
stat,
|
|
558
|
-
writeFile
|
|
557
|
+
writeFile
|
|
559
558
|
} from "node:fs/promises";
|
|
560
559
|
import * as path3 from "node:path";
|
|
561
560
|
import { finished } from "node:stream/promises";
|
|
@@ -621,7 +620,7 @@ var IndexCommand = class extends SqlCommand {
|
|
|
621
620
|
names,
|
|
622
621
|
onProgress: createProgressHandler(eventsStream, verbose, ctx.stderr)
|
|
623
622
|
});
|
|
624
|
-
await
|
|
623
|
+
await writeFile(fragmentsPath, JSON.stringify(fragments, null, 2));
|
|
625
624
|
const manifest = {
|
|
626
625
|
fragmentsPath,
|
|
627
626
|
eventsPath,
|
|
@@ -734,7 +733,7 @@ function dedupe(values) {
|
|
|
734
733
|
}
|
|
735
734
|
|
|
736
735
|
// packages/text2sql/src/bin/commands/run.ts
|
|
737
|
-
import { mkdir as mkdir3, writeFile as
|
|
736
|
+
import { mkdir as mkdir3, writeFile as writeFile2 } from "node:fs/promises";
|
|
738
737
|
import * as path4 from "node:path";
|
|
739
738
|
import { v7 as v72 } from "uuid";
|
|
740
739
|
var RunCommand = class extends SqlQueryCommand {
|
|
@@ -749,7 +748,7 @@ var RunCommand = class extends SqlQueryCommand {
|
|
|
749
748
|
const outPath = path4.join(outputDir, `${v72()}.json`);
|
|
750
749
|
try {
|
|
751
750
|
await mkdir3(outputDir, { recursive: true });
|
|
752
|
-
await
|
|
751
|
+
await writeFile2(outPath, JSON.stringify(rows, null, 2));
|
|
753
752
|
} catch (error) {
|
|
754
753
|
this.fail(errorMessage2(error));
|
|
755
754
|
}
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert HuggingFace model to GGUF format using Docker
|
|
3
|
-
* Uses the official llama.cpp image - no local installation needed
|
|
4
|
-
*
|
|
5
|
-
* Usage: node convert-to-gguf.ts <model_dir> <output.gguf> [quantization]
|
|
6
|
-
*
|
|
7
|
-
* Arguments:
|
|
8
|
-
* model_dir Path to HuggingFace model directory (contains model.safetensors)
|
|
9
|
-
* output.gguf Output path for the GGUF file
|
|
10
|
-
* quantization Quantization type (default: q8_0)
|
|
11
|
-
* Options: f32, f16, bf16, q8_0, q4_0, q4_1, q5_0, q5_1
|
|
12
|
-
*
|
|
13
|
-
* Examples:
|
|
14
|
-
* node convert-to-gguf.ts ./qwen3-sql-final ./qwen3-sql.gguf
|
|
15
|
-
* node convert-to-gguf.ts ./qwen3-sql-final ./qwen3-sql-q4.gguf q4_0
|
|
16
|
-
*/
|
|
17
1
|
export {};
|
|
18
2
|
//# sourceMappingURL=convert-to-gguf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-to-gguf.d.ts","sourceRoot":"","sources":["../../src/finetune/convert-to-gguf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert-to-gguf.d.ts","sourceRoot":"","sources":["../../src/finetune/convert-to-gguf.ts"],"names":[],"mappings":""}
|
package/dist/index.js
CHANGED
|
@@ -548,9 +548,9 @@ SQL: ${sql.trim()}`,
|
|
|
548
548
|
return "";
|
|
549
549
|
}
|
|
550
550
|
};
|
|
551
|
-
function filterTablesByName(
|
|
552
|
-
if (!filter) return
|
|
553
|
-
return
|
|
551
|
+
function filterTablesByName(tables2, filter) {
|
|
552
|
+
if (!filter) return tables2;
|
|
553
|
+
return tables2.filter((table2) => matchesFilter(table2.name, filter));
|
|
554
554
|
}
|
|
555
555
|
function filterRelationshipsByTables(relationships, tableNames) {
|
|
556
556
|
if (tableNames === void 0) {
|
|
@@ -563,15 +563,15 @@ function filterRelationshipsByTables(relationships, tableNames) {
|
|
|
563
563
|
(it) => tableNames.has(it.table) || tableNames.has(it.referenced_table)
|
|
564
564
|
);
|
|
565
565
|
}
|
|
566
|
-
function applyTablesFilter(
|
|
566
|
+
function applyTablesFilter(tables2, relationships, filter) {
|
|
567
567
|
if (!filter) {
|
|
568
|
-
return { tables, relationships };
|
|
568
|
+
return { tables: tables2, relationships };
|
|
569
569
|
}
|
|
570
570
|
const allowedNames = new Set(
|
|
571
|
-
getTablesWithRelated(
|
|
571
|
+
getTablesWithRelated(tables2, relationships, filter)
|
|
572
572
|
);
|
|
573
573
|
return {
|
|
574
|
-
tables:
|
|
574
|
+
tables: tables2.filter((table2) => allowedNames.has(table2.name)),
|
|
575
575
|
relationships: filterRelationshipsByTables(relationships, allowedNames)
|
|
576
576
|
};
|
|
577
577
|
}
|
|
@@ -1129,9 +1129,10 @@ import {
|
|
|
1129
1129
|
} from "@deepagents/context";
|
|
1130
1130
|
|
|
1131
1131
|
// packages/text2sql/src/lib/file-cache.ts
|
|
1132
|
-
import {
|
|
1132
|
+
import { atomicWrite } from "@zukhruf/fs";
|
|
1133
|
+
import { createHash } from "node:crypto";
|
|
1133
1134
|
import { existsSync } from "node:fs";
|
|
1134
|
-
import { mkdir, readFile
|
|
1135
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
1135
1136
|
import { tmpdir } from "node:os";
|
|
1136
1137
|
import path from "node:path";
|
|
1137
1138
|
var FileCache = class {
|
|
@@ -1148,9 +1149,7 @@ var FileCache = class {
|
|
|
1148
1149
|
}
|
|
1149
1150
|
async set(content) {
|
|
1150
1151
|
await mkdir(path.dirname(this.path), { recursive: true });
|
|
1151
|
-
|
|
1152
|
-
await writeFile(tempPath, content, "utf-8");
|
|
1153
|
-
await rename(tempPath, this.path);
|
|
1152
|
+
await atomicWrite(this.path, content);
|
|
1154
1153
|
}
|
|
1155
1154
|
};
|
|
1156
1155
|
var JsonCache = class extends FileCache {
|
|
@@ -1367,8 +1366,9 @@ function errorMessage(error) {
|
|
|
1367
1366
|
}
|
|
1368
1367
|
|
|
1369
1368
|
// packages/text2sql/src/lib/checkpoint.ts
|
|
1369
|
+
import { durableWrite } from "@zukhruf/fs";
|
|
1370
1370
|
import { createHash as createHash2 } from "node:crypto";
|
|
1371
|
-
import { existsSync as existsSync2, readFileSync
|
|
1371
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
1372
1372
|
import pLimit from "p-limit";
|
|
1373
1373
|
import z4 from "zod";
|
|
1374
1374
|
function jsonCodec(schema) {
|
|
@@ -1388,6 +1388,9 @@ var Checkpoint = class _Checkpoint {
|
|
|
1388
1388
|
points;
|
|
1389
1389
|
path;
|
|
1390
1390
|
configHash;
|
|
1391
|
+
#writes = pLimit(1);
|
|
1392
|
+
#changes = 0;
|
|
1393
|
+
#writtenChanges = 0;
|
|
1391
1394
|
constructor(path6, configHash, points) {
|
|
1392
1395
|
this.points = points;
|
|
1393
1396
|
this.path = path6;
|
|
@@ -1484,15 +1487,23 @@ var Checkpoint = class _Checkpoint {
|
|
|
1484
1487
|
getPath() {
|
|
1485
1488
|
return this.path;
|
|
1486
1489
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1490
|
+
/**
|
|
1491
|
+
* Writes one snapshot at a time, so an older snapshot never lands after a
|
|
1492
|
+
* newer one. Each write takes the snapshot when it starts, so a save that
|
|
1493
|
+
* waited behind a write that already holds its change writes nothing.
|
|
1494
|
+
*/
|
|
1495
|
+
save() {
|
|
1496
|
+
this.#changes += 1;
|
|
1497
|
+
return this.#writes(async () => {
|
|
1498
|
+
const changes = this.#changes;
|
|
1499
|
+
if (changes === this.#writtenChanges) return;
|
|
1500
|
+
const file = {
|
|
1501
|
+
configHash: this.configHash,
|
|
1502
|
+
points: this.points
|
|
1503
|
+
};
|
|
1504
|
+
await durableWrite(this.path, JSON.stringify(file, null, 2));
|
|
1505
|
+
this.#writtenChanges = changes;
|
|
1506
|
+
});
|
|
1496
1507
|
}
|
|
1497
1508
|
};
|
|
1498
1509
|
function hash(value) {
|
|
@@ -1545,6 +1556,7 @@ function hashConfig(config) {
|
|
|
1545
1556
|
}
|
|
1546
1557
|
|
|
1547
1558
|
// packages/text2sql/src/lib/fs/sqlite/sqlite-fs.ts
|
|
1559
|
+
import { Declaration } from "@zukhruf/sqlite-drift";
|
|
1548
1560
|
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
1549
1561
|
import * as path2 from "node:path";
|
|
1550
1562
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -1555,10 +1567,38 @@ import z5 from "zod";
|
|
|
1555
1567
|
var entryType = z5.enum(["file", "directory", "symlink"]);
|
|
1556
1568
|
var bigintColumn = z5.union([z5.number(), z5.string().regex(/^-?\d+$/)]).transform(Number);
|
|
1557
1569
|
|
|
1558
|
-
// packages/text2sql/src/lib/fs/sqlite/ddl.sqlite-fs.
|
|
1559
|
-
var
|
|
1570
|
+
// packages/text2sql/src/lib/fs/sqlite/ddl.sqlite-fs.ts
|
|
1571
|
+
var SETUP = `
|
|
1572
|
+
PRAGMA journal_mode = WAL;
|
|
1573
|
+
PRAGMA synchronous = NORMAL;
|
|
1574
|
+
PRAGMA cache_size = -64000;
|
|
1575
|
+
PRAGMA temp_store = MEMORY;
|
|
1576
|
+
PRAGMA mmap_size = 268435456;
|
|
1577
|
+
`;
|
|
1578
|
+
var statements = [
|
|
1579
|
+
// Filesystem entries table (files, directories, symlinks)
|
|
1580
|
+
`CREATE TABLE fs_entries (
|
|
1581
|
+
path TEXT PRIMARY KEY, -- Normalized absolute path (e.g., '/results/uuid.json')
|
|
1582
|
+
type TEXT NOT NULL, -- 'file' | 'directory' | 'symlink'
|
|
1583
|
+
mode INTEGER NOT NULL, -- Unix permissions (e.g., 0o644 = 420)
|
|
1584
|
+
size INTEGER NOT NULL, -- File size in bytes (0 for directories)
|
|
1585
|
+
mtime INTEGER NOT NULL, -- Modified time (milliseconds since epoch)
|
|
1586
|
+
symlinkTarget TEXT -- Target path for symlinks (NULL for files/dirs)
|
|
1587
|
+
)`,
|
|
1588
|
+
`CREATE INDEX idx_fs_entries_type ON fs_entries(type)`,
|
|
1589
|
+
// File content chunks table (for handling large files)
|
|
1590
|
+
// Files are split into 1MB chunks to avoid SQLite BLOB performance issues
|
|
1591
|
+
`CREATE TABLE fs_chunks (
|
|
1592
|
+
path TEXT NOT NULL, -- Reference to fs_entries.path
|
|
1593
|
+
chunkIndex INTEGER NOT NULL, -- 0-based chunk sequence
|
|
1594
|
+
data BLOB NOT NULL, -- Chunk content (up to 1MB default)
|
|
1595
|
+
PRIMARY KEY (path, chunkIndex),
|
|
1596
|
+
FOREIGN KEY (path) REFERENCES fs_entries(path) ON DELETE CASCADE ON UPDATE CASCADE
|
|
1597
|
+
)`
|
|
1598
|
+
];
|
|
1560
1599
|
|
|
1561
1600
|
// packages/text2sql/src/lib/fs/sqlite/sqlite-fs.ts
|
|
1601
|
+
var tables = new Declaration(statements, { rows: "keep" });
|
|
1562
1602
|
var entryRow = z6.object({
|
|
1563
1603
|
path: z6.string(),
|
|
1564
1604
|
type: entryType,
|
|
@@ -1592,7 +1632,8 @@ var SqliteFs = class {
|
|
|
1592
1632
|
const normalizedRoot = this.#normalizeRoot(options.root);
|
|
1593
1633
|
this.#root = normalizedRoot === "/" ? "" : normalizedRoot;
|
|
1594
1634
|
this.#db = new DatabaseSync(options.dbPath);
|
|
1595
|
-
this.#db.exec(
|
|
1635
|
+
this.#db.exec(SETUP);
|
|
1636
|
+
tables.apply(this.#db);
|
|
1596
1637
|
this.#sql = this.#db.createTagStore();
|
|
1597
1638
|
const rootSlashExists = this.#sql.get`SELECT 1 FROM fs_entries WHERE path = '/'`;
|
|
1598
1639
|
if (!rootSlashExists) {
|
|
@@ -4760,8 +4801,8 @@ function cloneInspectionContext(context) {
|
|
|
4760
4801
|
function scriptContainsBlockedCommand(script, context, mode = "blocked-only") {
|
|
4761
4802
|
return statementsContainBlockedCommand(script.statements, context, mode);
|
|
4762
4803
|
}
|
|
4763
|
-
function statementsContainBlockedCommand(
|
|
4764
|
-
for (const statement of
|
|
4804
|
+
function statementsContainBlockedCommand(statements2, context, mode) {
|
|
4805
|
+
for (const statement of statements2) {
|
|
4765
4806
|
if (statementContainsBlockedCommand(statement, context, mode)) {
|
|
4766
4807
|
return true;
|
|
4767
4808
|
}
|
|
@@ -5426,9 +5467,9 @@ function rewriteSqlCommandsInList(commands, ast) {
|
|
|
5426
5467
|
}
|
|
5427
5468
|
return rewritten;
|
|
5428
5469
|
}
|
|
5429
|
-
function rewriteSqlCommandsInStatements(
|
|
5470
|
+
function rewriteSqlCommandsInStatements(statements2, ast) {
|
|
5430
5471
|
let rewritten = false;
|
|
5431
|
-
for (const statement of
|
|
5472
|
+
for (const statement of statements2) {
|
|
5432
5473
|
for (const pipeline of statement.pipelines) {
|
|
5433
5474
|
if (rewriteSqlCommandsInList(pipeline.commands, ast)) {
|
|
5434
5475
|
rewritten = true;
|