@poe-platform/safe-bash 0.1.824 → 0.1.826

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 (44) hide show
  1. package/dist/safe-bash/command-chunks/{chunk-PLVFJ6FF.js → chunk-4EA7WI3L.js} +9 -1
  2. package/dist/safe-bash/command-chunks/{chunk-IKBTII7C.js → chunk-BKQWFABY.js} +314 -13
  3. package/dist/safe-bash/command-chunks/{chunk-3EBQOZET.js → chunk-DV7TCGJR.js} +22 -4
  4. package/dist/safe-bash/command-chunks/{chunk-3UDJYSAF.js → chunk-IX3B4HCD.js} +34 -2
  5. package/dist/safe-bash/command-chunks/chunk-NXZJJM4J.js +111 -0
  6. package/dist/safe-bash/command-chunks/{chunk-AVSINNZ6.js → chunk-P66Q5F6K.js} +4 -4
  7. package/dist/safe-bash/command-chunks/{chunk-OLXMWQJ5.js → chunk-Q2ACHUTY.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-HNEWGADJ.js → chunk-RUXOFW5G.js} +7 -6
  9. package/dist/safe-bash/command-chunks/{chunk-NW3S6T6R.js → chunk-T7RT2BNL.js} +1 -1
  10. package/dist/safe-bash/command-chunks/chunk-TGSNVLFZ.js +105 -0
  11. package/dist/safe-bash/command-chunks/{chunk-NNGWTDVJ.js → chunk-VKTM2SOL.js} +24 -81
  12. package/dist/safe-bash/commands/llm/collections.browser.js +4 -2
  13. package/dist/safe-bash/commands/llm/collections.js +1 -1
  14. package/dist/safe-bash-command-llm/collections.d.ts +2 -0
  15. package/dist/safe-bash-command-llm/collections.js +146 -22
  16. package/dist/safe-bash-command-llm/command.js +1 -1
  17. package/dist/safe-bash-command-llm/import-sql.d.ts +9 -0
  18. package/dist/safe-bash-command-llm/index.js +1 -1
  19. package/dist/safe-bash-command-python/build-wheel.d.ts +11 -2
  20. package/dist/safe-bash-command-python/executor.js +5 -5
  21. package/dist/safe-bash-command-python/index.js +5 -5
  22. package/dist/safe-bash-command-python/jspi.js +2 -2
  23. package/dist/safe-bash-command-python/provisioning.d.ts +1 -1
  24. package/dist/safe-bash-command-python/provisioning.js +1 -1
  25. package/dist/safe-bash-command-python/worker.js +1 -1
  26. package/dist/safe-bash-csv-engine/index.js +5 -5
  27. package/dist/safe-bash-csv-engine/python-codepages.js +2 -2
  28. package/dist/safe-bash-csv-engine/python-file-codepages.js +2 -2
  29. package/dist/safe-bash-csv-engine/python-utf16.js +3 -3
  30. package/dist/safe-bash-csv-engine/text-decoder.js +5 -5
  31. package/dist/safe-bash-sqlite-engine/safe-fs.d.ts +6 -0
  32. package/dist/safe-bash-sqlite-engine/safe-fs.js +1 -1
  33. package/dist/safe-bash-sqlite-engine/sqlite-attachments.d.ts +5 -0
  34. package/dist/safe-bash-sqlite-engine/sqlite-input-snapshots.d.ts +20 -0
  35. package/dist/safe-bash-sqlite-engine/sqlite-query-records.d.ts +9 -0
  36. package/dist/safe-bash-sqlite-engine/sqlite-read-session.d.ts +3 -16
  37. package/dist/safe-bash-sqlite-engine/sqlite-session.d.ts +4 -0
  38. package/dist/safe-bash-sqlite-engine/sqlite-statement.d.ts +4 -0
  39. package/dist/safe-bash-sqlite-engine/storage.d.ts +2 -0
  40. package/dist/safe-bash-sqlite-engine/storage.js +324 -31
  41. package/dist/safe-bash-sqlite-engine/types.d.ts +1 -0
  42. package/package.json +2 -2
  43. package/dist/safe-bash/command-chunks/chunk-OOYVZAWL.js +0 -90
  44. package/dist/safe-bash/command-chunks/chunk-WIUEM7HP.js +0 -58
@@ -32,7 +32,7 @@ import {
32
32
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
33
33
 
34
34
  // packages/safe-bash-command-llm/src/collections.ts
35
- import { FsError as FsError12 } from "../safe-bash-contracts/index.js";
35
+ import { FsError as FsError13 } from "../safe-bash-contracts/index.js";
36
36
  import { transactSqlite, withSqliteStatement as withSqliteStatement8 } from "../safe-bash-sqlite-engine/storage.js";
37
37
 
38
38
  // packages/safe-bash-command-llm/src/collections-migrations.ts
@@ -615,7 +615,7 @@ async function similarCollection(editor, options) {
615
615
  }
616
616
 
617
617
  // packages/safe-bash-command-llm/src/collections-command.ts
618
- import { FsError as FsError11 } from "../safe-bash-contracts/index.js";
618
+ import { FsError as FsError12 } from "../safe-bash-contracts/index.js";
619
619
  import { pathOf as pathOf3 } from "../safe-bash-contracts/path.js";
620
620
 
621
621
  // packages/safe-bash-command-llm/src/similar-command.ts
@@ -794,7 +794,7 @@ async function similarCommand(invocation, limits) {
794
794
 
795
795
  // packages/safe-bash-command-llm/src/embed-multi-command.ts
796
796
  import { pathOf as pathOf2 } from "../safe-bash-contracts/path.js";
797
- import { FsError as FsError10 } from "../safe-bash-contracts/index.js";
797
+ import { FsError as FsError11 } from "../safe-bash-contracts/index.js";
798
798
 
799
799
  // packages/safe-bash-command-llm/src/import-csv.ts
800
800
  import { FsError as FsError6 } from "../safe-bash-contracts/index.js";
@@ -1294,8 +1294,108 @@ async function withEmbeddingFileGlob(options, source, operation) {
1294
1294
  }
1295
1295
  }
1296
1296
 
1297
- // packages/safe-bash-command-llm/src/import-files.ts
1297
+ // packages/safe-bash-command-llm/src/import-sql.ts
1298
1298
  import { FsError as FsError9 } from "../safe-bash-contracts/index.js";
1299
+ import { withSqliteQueryRecords } from "../safe-bash-sqlite-engine/storage.js";
1300
+ async function withSqlEmbeddingEntries(options, operation) {
1301
+ const { signal } = options, encoder = new TextEncoder();
1302
+ return withSqliteQueryRecords(options, async (rows, columns) => {
1303
+ const positions = /* @__PURE__ */ new Map();
1304
+ for (let index = 0; index < columns.length; index++) positions.set(columns[index], index);
1305
+ const selected = [...positions.values()];
1306
+ const id = async (value) => {
1307
+ if (value === null) return "None";
1308
+ if (typeof value === "bigint") return String(value);
1309
+ if (typeof value === "number") return Number.isFinite(value) ? floatText(value) : value > 0 ? "inf" : "-inf";
1310
+ if (value.size > 65536) throw new RangeError("Embedding ID exceeds SQLite control byte limit");
1311
+ if (value.type === "text") {
1312
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
1313
+ let text2 = "";
1314
+ for await (const bytes2 of value.bytes) text2 += decoder.decode(bytes2, { stream: true });
1315
+ return text2 + decoder.decode();
1316
+ }
1317
+ const bytes = new Uint8Array(value.size);
1318
+ let offset = 0;
1319
+ for await (const part of value.bytes) {
1320
+ bytes.set(part, offset);
1321
+ offset += part.length;
1322
+ }
1323
+ const quote = bytes.includes(39) && !bytes.includes(34) ? 34 : 39;
1324
+ let text = "b" + String.fromCharCode(quote);
1325
+ for (const byte of bytes) {
1326
+ text += byte === quote || byte === 92 ? "\\" + String.fromCharCode(byte) : byte === 9 ? "\\t" : byte === 10 ? "\\n" : byte === 13 ? "\\r" : byte >= 32 && byte < 127 ? String.fromCharCode(byte) : "\\x" + byte.toString(16).padStart(2, "0");
1327
+ if (text.length > 65536) throw new RangeError("Embedding ID exceeds SQLite control byte limit");
1328
+ }
1329
+ return text + String.fromCharCode(quote);
1330
+ };
1331
+ const entries = async function* () {
1332
+ for await (const row of rows) {
1333
+ const values = selected.map((index) => row[index]);
1334
+ if (!values.length) throw new RangeError("list index out of range");
1335
+ const identifier = (options.prefix ?? "") + await id(values[0]);
1336
+ if (encoder.encode(identifier).length > 65536) throw new RangeError("Embedding ID exceeds SQLite control byte limit");
1337
+ const fields = values.slice(1);
1338
+ for (let index = 0; index < fields.length; index++) {
1339
+ const field = fields[index];
1340
+ if (field === null || field === 0n || field === 0 || typeof field === "object" && field.size === 0) continue;
1341
+ if (typeof field !== "object" || field.type !== "text") throw new TypeError("sequence item " + index + ": expected str instance, " + (typeof field === "bigint" ? "int" : typeof field === "number" ? "float" : "bytes") + " found");
1342
+ const decoder = new TextDecoder("utf-8", { fatal: true });
1343
+ for await (const bytes of field.bytes) decoder.decode(bytes, { stream: true });
1344
+ decoder.decode();
1345
+ }
1346
+ let active = true, consumed = false;
1347
+ try {
1348
+ yield { id: identifier, input: { async dispose() {
1349
+ active = false;
1350
+ }, bytes: { async *[Symbol.asyncIterator]() {
1351
+ const check = () => {
1352
+ signal.throwIfAborted();
1353
+ if (!active) throw new FsError9("EBADF", { message: "SQL row lease is closed" });
1354
+ };
1355
+ check();
1356
+ if (consumed) throw new FsError9("EBADF", { message: "SQL row lease is closed" });
1357
+ consumed = true;
1358
+ const prefix = options.prepend ?? "";
1359
+ for (let offset = 0; offset < prefix.length; ) {
1360
+ check();
1361
+ let end = Math.min(offset + 4096, prefix.length);
1362
+ const last = prefix.charCodeAt(end - 1);
1363
+ if (end < prefix.length && last >= 55296 && last <= 56319) end--;
1364
+ const bytes = encoder.encode(prefix.slice(offset, end));
1365
+ options.admit?.(bytes.length);
1366
+ yield bytes;
1367
+ offset = end;
1368
+ }
1369
+ for (let index = 0; index < fields.length; index++) {
1370
+ check();
1371
+ if (index) {
1372
+ options.admit?.(1);
1373
+ yield Uint8Array.of(32);
1374
+ }
1375
+ const field = fields[index];
1376
+ if (field && typeof field === "object") for await (const bytes of field.bytes) {
1377
+ check();
1378
+ options.admit?.(bytes.length);
1379
+ yield bytes;
1380
+ }
1381
+ }
1382
+ } } } };
1383
+ } finally {
1384
+ active = false;
1385
+ }
1386
+ }
1387
+ };
1388
+ const iterator = entries();
1389
+ try {
1390
+ return await operation({ [Symbol.asyncIterator]: () => iterator });
1391
+ } finally {
1392
+ await iterator.return(void 0);
1393
+ }
1394
+ });
1395
+ }
1396
+
1397
+ // packages/safe-bash-command-llm/src/import-files.ts
1398
+ import { FsError as FsError10 } from "../safe-bash-contracts/index.js";
1299
1399
  import { PythonTextDecoder, PythonTextDecodeError, PythonIso2022PendingError, PythonUtf7EncodingError } from "../safe-bash-csv-engine/text-decoder.js";
1300
1400
  async function withFileEmbeddingEntries(options, files, operation) {
1301
1401
  const { fs, directory, signal } = options, maxBytes = options.maxInputBytes ?? Infinity;
@@ -1374,11 +1474,11 @@ async function withFileEmbeddingEntries(options, files, operation) {
1374
1474
  closed = true;
1375
1475
  await retained.close();
1376
1476
  }, bytes: { async *[Symbol.asyncIterator]() {
1377
- if (closed || consumed) throw new FsError9("EBADF", { message: "File embedding lease is closed" });
1477
+ if (closed || consumed) throw new FsError10("EBADF", { message: "File embedding lease is closed" });
1378
1478
  consumed = true;
1379
1479
  if (!binary && options.prepend) for (let offset = 0; offset < options.prepend.length; ) {
1380
1480
  signal.throwIfAborted();
1381
- if (closed) throw new FsError9("EBADF", { message: "File embedding lease is closed" });
1481
+ if (closed) throw new FsError10("EBADF", { message: "File embedding lease is closed" });
1382
1482
  let end = Math.min(offset + 4096, options.prepend.length);
1383
1483
  const last = options.prepend.charCodeAt(end - 1);
1384
1484
  if (end < options.prepend.length && last >= 55296 && last <= 56319) end--;
@@ -1386,7 +1486,7 @@ async function withFileEmbeddingEntries(options, files, operation) {
1386
1486
  offset = end;
1387
1487
  }
1388
1488
  for await (const bytes of retained.replay()) {
1389
- if (closed) throw new FsError9("EBADF", { message: "File embedding lease is closed" });
1489
+ if (closed) throw new FsError10("EBADF", { message: "File embedding lease is closed" });
1390
1490
  yield bytes;
1391
1491
  }
1392
1492
  } } } };
@@ -1516,7 +1616,7 @@ async function embedMultiCommand(invocation, limits) {
1516
1616
  `);
1517
1617
  return code;
1518
1618
  };
1519
- const values = {}, operands = [], encodings = [], files = [];
1619
+ const values = {}, operands = [], encodings = [], attachments = [], files = [];
1520
1620
  let store = false, binary = false, ended = false, help3 = false;
1521
1621
  for (let index = 0; index < tokens.length; index++) {
1522
1622
  await step();
@@ -1548,6 +1648,12 @@ async function embedMultiCommand(invocation, limits) {
1548
1648
  binary = true;
1549
1649
  break;
1550
1650
  }
1651
+ if (flag === "--attach") {
1652
+ const alias = (equals < 0 ? void 0 : token.slice(equals + 1)) ?? tokens[++index], path = tokens[++index];
1653
+ if (alias === void 0 || path === void 0) return fail("Option '--attach' requires 2 arguments.");
1654
+ attachments.push({ alias, path: pathOf2(context, path), originalPath: path });
1655
+ break;
1656
+ }
1551
1657
  if (flag === "--files") {
1552
1658
  const directory = (equals < 0 ? void 0 : token.slice(equals + 1)) ?? tokens[++index], pattern = tokens[++index];
1553
1659
  if (directory === void 0 || pattern === void 0) return fail("Option '--files' requires 2 arguments.");
@@ -1555,7 +1661,7 @@ async function embedMultiCommand(invocation, limits) {
1555
1661
  files.push({ originalDirectory: directory, directory: pathOf2(context, directory), pattern, displayDirectory: (directory.startsWith("/") ? "/" : "") + normalized });
1556
1662
  break;
1557
1663
  }
1558
- const name2 = { "--encoding": "encoding", "--format": "format", "--batch-size": "batchSize", "--prefix": "prefix", "--prepend": "prepend", "-m": "model", "--model": "model", "-d": "database", "--database": "database" }[flag];
1664
+ const name2 = { "--sql": "sql", "--encoding": "encoding", "--format": "format", "--batch-size": "batchSize", "--prefix": "prefix", "--prepend": "prepend", "-m": "model", "--model": "model", "-d": "database", "--database": "database" }[flag];
1559
1665
  if (!name2) return fail(`No such option: ${flag}`);
1560
1666
  const value = (long ? equals < 0 ? void 0 : token.slice(equals + 1) : token.slice(cursor + 1) || void 0) ?? tokens[++index];
1561
1667
  if (value === void 0) return fail(`Option '${flag}' requires an argument.`);
@@ -1565,21 +1671,28 @@ async function embedMultiCommand(invocation, limits) {
1565
1671
  }
1566
1672
  }
1567
1673
  if (help3) {
1568
- await invocation.write(new TextEncoder().encode(usage2 + "\n Store embeddings from files or CSV, TSV, JSON or JSONL input. Use - to read stdin.\n\nOptions:\n --files DIRECTORY GLOB Files to embed (repeatable)\n --encoding TEXT File encoding (repeatable)\n --binary Embed files as binary data\n --format [json|csv|tsv|nl] Input format (auto-detected by default)\n --batch-size INTEGER Batch size to use when running embeddings\n --prefix TEXT Prefix to add to the IDs\n -m, --model TEXT Embedding model to use\n --prepend TEXT Prepend this string to all content\n --store Store the text itself in the database\n -d, --database FILE Path to embeddings database\n -h, --help Show this message and exit.\n"));
1674
+ await invocation.write(new TextEncoder().encode(usage2 + "\n Store embeddings from files or CSV, TSV, JSON or JSONL input. Use - to read stdin.\n\nOptions:\n --sql TEXT Read input using this SQL query\n --attach TEXT FILE Additional databases to attach (repeatable)\n --files DIRECTORY GLOB Files to embed (repeatable)\n --encoding TEXT File encoding (repeatable)\n --binary Embed files as binary data\n --format [json|csv|tsv|nl] Input format (auto-detected by default)\n --batch-size INTEGER Batch size to use when running embeddings\n --prefix TEXT Prefix to add to the IDs\n -m, --model TEXT Embedding model to use\n --prepend TEXT Prepend this string to all content\n --store Store the text itself in the database\n -d, --database FILE Path to embeddings database\n -h, --help Show this message and exit.\n"));
1569
1675
  return 0;
1570
1676
  }
1571
1677
  if (!operands.length) return fail("Missing argument 'COLLECTION'.");
1572
1678
  if (operands.length > 2) return fail(`Got unexpected extra argument${operands.length === 3 ? "" : "s"} (${operands.slice(2).join(" ")})`);
1679
+ for (const input2 of attachments) {
1680
+ try {
1681
+ if ((await context.fs.stat(input2.path, { signal: context.signal })).type === "directory") return fail(`Invalid value for '--attach': File '${input2.originalPath}' is a directory.`);
1682
+ } catch (error) {
1683
+ if (!(error instanceof FsError11) || error.code !== "ENOENT") throw error;
1684
+ }
1685
+ }
1573
1686
  if (binary && !files.length) return fail("--binary must be used with --files");
1574
1687
  if (binary && encodings.length) return fail("--binary cannot be used with --encoding");
1575
- if (!operands[1] && !files.length) return fail("Either --sql or input path or --files is required");
1576
- if (files.length && (operands[1] || values.format)) return fail("Cannot use --files with --sql, input path or --format");
1688
+ if (!operands[1] && !files.length && !values.sql) return fail("Either --sql or input path or --files is required");
1689
+ if (files.length && (operands[1] || values.sql || values.format)) return fail("Cannot use --files with --sql, input path or --format");
1577
1690
  if (operands[1] && operands[1] !== "-") {
1578
1691
  try {
1579
1692
  const stat = await context.fs.stat(pathOf2(context, operands[1]), { signal: context.signal });
1580
1693
  if (stat.type === "directory") return fail(`Invalid value for '[INPUT_PATH]': File '${operands[1]}' is a directory.`);
1581
1694
  } catch (error) {
1582
- if (error instanceof FsError10 && error.code === "ENOENT") return fail(`Invalid value for '[INPUT_PATH]': File '${operands[1]}' does not exist.`);
1695
+ if (error instanceof FsError11 && error.code === "ENOENT") return fail(`Invalid value for '[INPUT_PATH]': File '${operands[1]}' does not exist.`);
1583
1696
  throw error;
1584
1697
  }
1585
1698
  }
@@ -1591,6 +1704,7 @@ async function embedMultiCommand(invocation, limits) {
1591
1704
  const config = createLlmConfiguration(context, maxConfigurationBytes), database = values.database || context.env.LLM_EMBEDDINGS_DB;
1592
1705
  if (!database) await context.fs.mkdir(config.directory, { recursive: true, signal: context.signal });
1593
1706
  const options = { ...limits, fs: context.fs, path: pathOf2(context, database || config.directory + "/embeddings.db"), signal: context.signal };
1707
+ await prepareSqliteAttachments({ ...options, directory: context.cwd, attachments });
1594
1708
  const name = operands[0];
1595
1709
  let model = "";
1596
1710
  let missingModel = false;
@@ -1658,7 +1772,7 @@ async function embedMultiCommand(invocation, limits) {
1658
1772
  valid = (await context.fs.stat(file.directory, { signal: context.signal })).type === "directory";
1659
1773
  } catch (error) {
1660
1774
  context.signal.throwIfAborted();
1661
- if (!(error instanceof FsError10) || !["ENOENT", "ENOTDIR"].includes(error.code)) throw error;
1775
+ if (!(error instanceof FsError11) || !["ENOENT", "ENOTDIR"].includes(error.code)) throw error;
1662
1776
  }
1663
1777
  if (!valid) throw new InvalidFileDirectory(file.originalDirectory);
1664
1778
  yield file;
@@ -1674,6 +1788,13 @@ async function embedMultiCommand(invocation, limits) {
1674
1788
  }
1675
1789
  return 0;
1676
1790
  }
1791
+ if (values.sql) {
1792
+ await withSqlEmbeddingEntries({ ...csvOptions, sql: values.sql, attachments, admit: invocation.admit }, async (entries) => {
1793
+ await invocation.write(new TextEncoder().encode("Embedding\n"));
1794
+ await consume(entries);
1795
+ });
1796
+ return 0;
1797
+ }
1677
1798
  if (operands[1] !== "-") {
1678
1799
  const input2 = await acquire();
1679
1800
  try {
@@ -1797,7 +1918,7 @@ Try 'llm collections ${command} -h' for help.
1797
1918
  const stat = await context.fs.stat(path, { signal: context.signal });
1798
1919
  if (stat.type === "directory") return fail(`Invalid value for '-d' / '--database': File '${display}' is a directory.`, 2, true);
1799
1920
  } catch (error) {
1800
- if (!(error instanceof FsError11 && error.code === "ENOENT")) throw error;
1921
+ if (!(error instanceof FsError12 && error.code === "ENOENT")) throw error;
1801
1922
  return fail(command === "list" ? `No collections table found in ${display}` : "Collection does not exist");
1802
1923
  }
1803
1924
  try {
@@ -1834,13 +1955,14 @@ Try 'llm collections ${command} -h' for help.
1834
1955
  } catch (error) {
1835
1956
  context.signal.throwIfAborted();
1836
1957
  if (error instanceof LlmCollectionDoesNotExist) return fail("Collection does not exist");
1837
- if (error instanceof FsError11 && error.code === "ENOENT") return fail(command === "list" ? `No collections table found in ${display}` : "Collection does not exist");
1958
+ if (error instanceof FsError12 && error.code === "ENOENT") return fail(command === "list" ? `No collections table found in ${display}` : "Collection does not exist");
1838
1959
  throw error;
1839
1960
  }
1840
1961
  } };
1841
1962
  }
1842
1963
 
1843
1964
  // packages/safe-bash-command-llm/src/collections.ts
1965
+ import { prepareSqliteAttachments } from "../safe-bash-sqlite-engine/storage.js";
1844
1966
  var migrations = ["m001_create_tables", "m002_foreign_key", "m003_add_updated", "m004_store_content_hash", "m005_add_content_blob"];
1845
1967
  var schema = [
1846
1968
  "CREATE TABLE [_sqlite_migrations] ([migration_set] TEXT,[name] TEXT,[applied_at] TEXT,PRIMARY KEY ([migration_set],[name]))",
@@ -1855,7 +1977,7 @@ async function initialize(session, signal, now, create) {
1855
1977
  for await (const [name] of query.rows([], ["text"])) tables.push(name);
1856
1978
  });
1857
1979
  if (!tables.length) {
1858
- if (!create) throw new FsError12("ENOENT", { message: "Embedding collection database does not exist" });
1980
+ if (!create) throw new FsError13("ENOENT", { message: "Embedding collection database does not exist" });
1859
1981
  await session.execute(schema[0].replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS"));
1860
1982
  for (const statement of schema.slice(1)) await session.execute(statement);
1861
1983
  const timestamp = now().toISOString().replace("T", " ").replace("Z", "000+00:00");
@@ -1877,10 +1999,10 @@ async function withLlmCollections(options, operation) {
1877
1999
  const execute = async (editor) => {
1878
2000
  let active = true, pending, failed = false, failure;
1879
2001
  const run = (action) => {
1880
- if (!active) return Promise.reject(new FsError12("EBADF", { message: "Collection catalog is closed" }));
2002
+ if (!active) return Promise.reject(new FsError13("EBADF", { message: "Collection catalog is closed" }));
1881
2003
  if (pending) {
1882
2004
  failed = true;
1883
- failure = new FsError12("EBUSY", { message: "Collection operations must be serialized" });
2005
+ failure = new FsError13("EBUSY", { message: "Collection operations must be serialized" });
1884
2006
  return Promise.reject(failure);
1885
2007
  }
1886
2008
  if (failed) return Promise.reject(failure);
@@ -1994,14 +2116,14 @@ async function withLlmCollections(options, operation) {
1994
2116
  if (settings.maxInputBytes !== Infinity && (!Number.isSafeInteger(settings.maxInputBytes) || settings.maxInputBytes < 0)) throw new RangeError("Invalid embedding input byte limit");
1995
2117
  let borrowed = true;
1996
2118
  const input = { dispose, bytes: { async *[Symbol.asyncIterator]() {
1997
- if (!borrowed || closing) throw new FsError12("EBADF", { message: "Similarity source lease is closed" });
2119
+ if (!borrowed || closing) throw new FsError13("EBADF", { message: "Similarity source lease is closed" });
1998
2120
  const decoder = settings.binary ? void 0 : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
1999
2121
  let size = 0;
2000
2122
  for await (const chunk of sourceBytes(settings.input.bytes, signal)) {
2001
2123
  if (chunk.length > settings.maxInputBytes - size) throw new RangeError("Embedding input byte limit exceeded");
2002
2124
  size += chunk.length;
2003
2125
  for (let offset = 0; offset < chunk.length; offset += 16384) {
2004
- if (!borrowed || closing) throw new FsError12("EBADF", { message: "Similarity source lease is closed" });
2126
+ if (!borrowed || closing) throw new FsError13("EBADF", { message: "Similarity source lease is closed" });
2005
2127
  const bytes = chunk.subarray(offset, offset + 16384);
2006
2128
  decoder?.decode(bytes, { stream: true });
2007
2129
  yield bytes;
@@ -2058,10 +2180,12 @@ async function withLlmCollections(options, operation) {
2058
2180
  export {
2059
2181
  LlmCollectionDoesNotExist,
2060
2182
  createLlmCollectionCommands,
2183
+ prepareSqliteAttachments,
2061
2184
  withCsvEmbeddingEntries,
2062
2185
  withEmbeddingFileGlob,
2063
2186
  withFileEmbeddingEntries,
2064
2187
  withJsonEmbeddingEntries,
2065
2188
  withJsonLinesEmbeddingEntries,
2066
- withLlmCollections
2189
+ withLlmCollections,
2190
+ withSqlEmbeddingEntries
2067
2191
  };
@@ -3,7 +3,7 @@ import {
3
3
  createLlmCommands,
4
4
  llmCommands,
5
5
  llmReferenceVersion
6
- } from "../safe-bash/command-chunks/chunk-PLVFJ6FF.js";
6
+ } from "../safe-bash/command-chunks/chunk-4EA7WI3L.js";
7
7
  import "../safe-bash/command-chunks/chunk-EWECMOQ5.js";
8
8
  import "../safe-bash/command-chunks/chunk-7ZQVMPSB.js";
9
9
  import "../safe-bash/command-chunks/chunk-E5CDHXFA.js";
@@ -0,0 +1,9 @@
1
+ import { withSqliteQueryRecords } from "../safe-bash-sqlite-engine/storage.js";
2
+ import type { LlmCollectionBatchEntry } from './collections-batch.js';
3
+ /** SQL rows preserve Python dictionary column ordering. Payloads remain borrowed
4
+ * caller-backed field streams; only the bounded collection ID is materialized. */
5
+ export declare function withSqlEmbeddingEntries<T>(options: Parameters<typeof withSqliteQueryRecords>[0] & {
6
+ prefix?: string;
7
+ prepend?: string;
8
+ admit?: (bytes: number) => void;
9
+ }, operation: (entries: AsyncIterable<LlmCollectionBatchEntry>) => Promise<T>): Promise<T>;
@@ -44,7 +44,7 @@ import {
44
44
  serializeLlmTokenUsage,
45
45
  streamLlmToolChain,
46
46
  validateLlmTemplateParameters
47
- } from "../safe-bash/command-chunks/chunk-PLVFJ6FF.js";
47
+ } from "../safe-bash/command-chunks/chunk-4EA7WI3L.js";
48
48
  import "../safe-bash/command-chunks/chunk-EWECMOQ5.js";
49
49
  import {
50
50
  createLlmConfiguration
@@ -4,5 +4,14 @@ export interface PythonBuiltWheel {
4
4
  readonly digest: string;
5
5
  readonly size: number;
6
6
  }
7
- /** Publish a build result in caller-owned storage, independently of build cleanup. */
8
- export declare function publishPythonBuildWheel(source: string, directory: string, maxBytes: number, context: PythonPackageContext): Promise<PythonBuiltWheel>;
7
+ export interface PythonWheelArtifact {
8
+ readonly key: string;
9
+ readonly size: number;
10
+ read(offset: number, length: number): Uint8Array | Promise<Uint8Array>;
11
+ close?(): Promise<void>;
12
+ }
13
+ /** Consume a retained wheel (or open a build result) and publish caller-owned bytes. */
14
+ export declare function publishPythonBuildWheel(source: string | {
15
+ filename: string;
16
+ artifact: PythonWheelArtifact;
17
+ }, directory: string, maxBytes: number, context: PythonPackageContext): Promise<PythonBuiltWheel>;
@@ -12,17 +12,17 @@ import {
12
12
  createPythonSourcePackageEnvironment,
13
13
  createPythonSourceSnapshot,
14
14
  installPythonLlmPackages,
15
- publishPythonBuildWheel,
16
15
  pythonExecutorCommands,
17
16
  pythonLlmPackages
18
- } from "../safe-bash/command-chunks/chunk-NNGWTDVJ.js";
17
+ } from "../safe-bash/command-chunks/chunk-VKTM2SOL.js";
19
18
  import {
20
19
  PythonPackageConflictError,
21
20
  createPythonPackageCache,
22
21
  createPythonPackageEnvironment,
23
22
  createPythonPackageManifestStore,
23
+ publishPythonBuildWheel,
24
24
  pythonDocumentPackages
25
- } from "../safe-bash/command-chunks/chunk-IKBTII7C.js";
25
+ } from "../safe-bash/command-chunks/chunk-BKQWFABY.js";
26
26
  import {
27
27
  createPythonShellCapability
28
28
  } from "../safe-bash/command-chunks/chunk-NHAG4DWL.js";
@@ -32,9 +32,9 @@ import {
32
32
  } from "../safe-bash/command-chunks/chunk-IOZTDDNT.js";
33
33
  import {
34
34
  createPythonJspiExecutor
35
- } from "../safe-bash/command-chunks/chunk-NW3S6T6R.js";
35
+ } from "../safe-bash/command-chunks/chunk-T7RT2BNL.js";
36
36
  import "../safe-bash/command-chunks/chunk-FXWKMNX2.js";
37
- import "../safe-bash/command-chunks/chunk-3EBQOZET.js";
37
+ import "../safe-bash/command-chunks/chunk-DV7TCGJR.js";
38
38
  import {
39
39
  createPythonJspiNativeCall,
40
40
  createPythonJspiStatResult,
@@ -12,17 +12,17 @@ import {
12
12
  createPythonSourcePackageEnvironment,
13
13
  createPythonSourceSnapshot,
14
14
  installPythonLlmPackages,
15
- publishPythonBuildWheel,
16
15
  pythonExecutorCommands,
17
16
  pythonLlmPackages
18
- } from "../safe-bash/command-chunks/chunk-NNGWTDVJ.js";
17
+ } from "../safe-bash/command-chunks/chunk-VKTM2SOL.js";
19
18
  import {
20
19
  PythonPackageConflictError,
21
20
  createPythonPackageCache,
22
21
  createPythonPackageEnvironment,
23
22
  createPythonPackageManifestStore,
23
+ publishPythonBuildWheel,
24
24
  pythonDocumentPackages
25
- } from "../safe-bash/command-chunks/chunk-IKBTII7C.js";
25
+ } from "../safe-bash/command-chunks/chunk-BKQWFABY.js";
26
26
  import {
27
27
  createPythonShellCapability
28
28
  } from "../safe-bash/command-chunks/chunk-NHAG4DWL.js";
@@ -32,9 +32,9 @@ import {
32
32
  } from "../safe-bash/command-chunks/chunk-IOZTDDNT.js";
33
33
  import {
34
34
  createPythonJspiExecutor
35
- } from "../safe-bash/command-chunks/chunk-NW3S6T6R.js";
35
+ } from "../safe-bash/command-chunks/chunk-T7RT2BNL.js";
36
36
  import "../safe-bash/command-chunks/chunk-FXWKMNX2.js";
37
- import "../safe-bash/command-chunks/chunk-3EBQOZET.js";
37
+ import "../safe-bash/command-chunks/chunk-DV7TCGJR.js";
38
38
  import {
39
39
  createPythonJspiNativeCall,
40
40
  createPythonJspiStatResult,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createPythonJspiExecutor
3
- } from "../safe-bash/command-chunks/chunk-NW3S6T6R.js";
3
+ } from "../safe-bash/command-chunks/chunk-T7RT2BNL.js";
4
4
  import "../safe-bash/command-chunks/chunk-FXWKMNX2.js";
5
- import "../safe-bash/command-chunks/chunk-3EBQOZET.js";
5
+ import "../safe-bash/command-chunks/chunk-DV7TCGJR.js";
6
6
  import "../safe-bash/command-chunks/chunk-P56KGNW7.js";
7
7
  import "../safe-bash/command-chunks/chunk-NK3FRG5O.js";
8
8
  import "../safe-bash/command-chunks/chunk-XNJGNDFW.js";
@@ -33,7 +33,7 @@ export interface PythonPackageOptions extends PythonPackageInstallOptions {
33
33
  readonly cache?: PythonPackageCache;
34
34
  readonly manifestStore?: PythonPackageManifestStore;
35
35
  readonly scope?: string;
36
- /** Canonical filesystem directory, scoped to this package environment. */
36
+ /** Canonical cache directory. Network artifacts otherwise use caller cwd/.python-packages/cache; explicit buffered caches keep their own storage. */
37
37
  readonly cacheDirectory?: string;
38
38
  readonly maxDownloadBytes?: number;
39
39
  readonly maxManifestBytes?: number;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createPythonPackageEnvironment,
3
3
  pythonDocumentPackages
4
- } from "../safe-bash/command-chunks/chunk-IKBTII7C.js";
4
+ } from "../safe-bash/command-chunks/chunk-BKQWFABY.js";
5
5
  import "../safe-bash/command-chunks/chunk-NXCJNPL3.js";
6
6
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
7
7
  export {
@@ -8,7 +8,7 @@ import {
8
8
  pythonRuntimeRelocation,
9
9
  pythonStatProjection,
10
10
  pythonTreeCleanup
11
- } from "../safe-bash/command-chunks/chunk-3EBQOZET.js";
11
+ } from "../safe-bash/command-chunks/chunk-DV7TCGJR.js";
12
12
  import {
13
13
  PythonFailure
14
14
  } from "../safe-bash/command-chunks/chunk-TO6UNFEF.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  PythonTextDecoder
3
- } from "../safe-bash/command-chunks/chunk-AVSINNZ6.js";
4
- import "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
- import "../safe-bash/command-chunks/chunk-OOYVZAWL.js";
3
+ } from "../safe-bash/command-chunks/chunk-P66Q5F6K.js";
4
+ import "../safe-bash/command-chunks/chunk-Q2ACHUTY.js";
5
+ import "../safe-bash/command-chunks/chunk-NXZJJM4J.js";
6
6
  import "../safe-bash/command-chunks/chunk-ZERCTWUI.js";
7
- import "../safe-bash/command-chunks/chunk-WIUEM7HP.js";
8
- import "../safe-bash/command-chunks/chunk-HNEWGADJ.js";
7
+ import "../safe-bash/command-chunks/chunk-TGSNVLFZ.js";
8
+ import "../safe-bash/command-chunks/chunk-RUXOFW5G.js";
9
9
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
10
10
 
11
11
  // packages/safe-bash-csv-engine/src/index.ts
@@ -3,9 +3,9 @@ import {
3
3
  dbfCodepages,
4
4
  decodePythonSingleByte,
5
5
  pythonSingleByteCodepages
6
- } from "../safe-bash/command-chunks/chunk-OOYVZAWL.js";
6
+ } from "../safe-bash/command-chunks/chunk-NXZJJM4J.js";
7
7
  import "../safe-bash/command-chunks/chunk-ZERCTWUI.js";
8
- import "../safe-bash/command-chunks/chunk-HNEWGADJ.js";
8
+ import "../safe-bash/command-chunks/chunk-RUXOFW5G.js";
9
9
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
10
10
  export {
11
11
  PythonTextDecodeError,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  pythonFileCodepages
3
- } from "../safe-bash/command-chunks/chunk-WIUEM7HP.js";
4
- import "../safe-bash/command-chunks/chunk-HNEWGADJ.js";
3
+ } from "../safe-bash/command-chunks/chunk-TGSNVLFZ.js";
4
+ import "../safe-bash/command-chunks/chunk-RUXOFW5G.js";
5
5
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
6
6
  export {
7
7
  pythonFileCodepages
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  PythonTextEncodingError,
3
3
  PythonUtf16Decoder
4
- } from "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
- import "../safe-bash/command-chunks/chunk-OOYVZAWL.js";
4
+ } from "../safe-bash/command-chunks/chunk-Q2ACHUTY.js";
5
+ import "../safe-bash/command-chunks/chunk-NXZJJM4J.js";
6
6
  import "../safe-bash/command-chunks/chunk-ZERCTWUI.js";
7
- import "../safe-bash/command-chunks/chunk-HNEWGADJ.js";
7
+ import "../safe-bash/command-chunks/chunk-RUXOFW5G.js";
8
8
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
9
9
  export {
10
10
  PythonTextEncodingError,
@@ -2,14 +2,14 @@ import {
2
2
  PythonIso2022PendingError,
3
3
  PythonTextDecoder,
4
4
  PythonUtf7EncodingError
5
- } from "../safe-bash/command-chunks/chunk-AVSINNZ6.js";
6
- import "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
+ } from "../safe-bash/command-chunks/chunk-P66Q5F6K.js";
6
+ import "../safe-bash/command-chunks/chunk-Q2ACHUTY.js";
7
7
  import {
8
8
  PythonTextDecodeError
9
- } from "../safe-bash/command-chunks/chunk-OOYVZAWL.js";
9
+ } from "../safe-bash/command-chunks/chunk-NXZJJM4J.js";
10
10
  import "../safe-bash/command-chunks/chunk-ZERCTWUI.js";
11
- import "../safe-bash/command-chunks/chunk-WIUEM7HP.js";
12
- import "../safe-bash/command-chunks/chunk-HNEWGADJ.js";
11
+ import "../safe-bash/command-chunks/chunk-TGSNVLFZ.js";
12
+ import "../safe-bash/command-chunks/chunk-RUXOFW5G.js";
13
13
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
14
14
  export {
15
15
  PythonIso2022PendingError,
@@ -10,7 +10,13 @@ export declare function createSqliteVfs(options: {
10
10
  signal: AbortSignal;
11
11
  maxOpenFiles: number;
12
12
  maxFileBytes: number;
13
+ /** Caller-visible database names backed only by these owned private files. */
14
+ filenames?: readonly {
15
+ path: string;
16
+ name: string;
17
+ }[];
13
18
  }): {
19
+ jFullPathname(name: string, out: Uint8Array): number;
14
20
  jOpen(name: string | null, id: number, flags: number, out: DataView): Promise<number>;
15
21
  jClose(id: number): Promise<number>;
16
22
  jRead(id: number, bytes: Uint8Array, position: number | bigint): Promise<number>;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSqliteVfs
3
- } from "../safe-bash/command-chunks/chunk-3UDJYSAF.js";
3
+ } from "../safe-bash/command-chunks/chunk-IX3B4HCD.js";
4
4
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
5
5
  export {
6
6
  createSqliteVfs
@@ -0,0 +1,5 @@
1
+ import { type SqliteInputSnapshotsOptions } from './sqlite-input-snapshots.js';
2
+ /** Prepare sqlite-utils attachments in order, before collection migrations.
3
+ * Missing canonical files are created empty. Existing data is only read through
4
+ * owned snapshots; aliases and database contents are validated by SQLite. */
5
+ export declare function prepareSqliteAttachments(options: SqliteInputSnapshotsOptions): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import type { FileSystem } from "../safe-bash-contracts/index.js";
2
+ import { createPrivateSqliteStorage } from './sqlite-private.js';
3
+ export interface SqliteInputSnapshotsOptions {
4
+ fs: FileSystem;
5
+ path: string;
6
+ directory: string;
7
+ signal: AbortSignal;
8
+ maxFileBytes: number;
9
+ maxIndexBytes: number;
10
+ maxOpenFiles: number;
11
+ attachments?: readonly {
12
+ alias: string;
13
+ path: string;
14
+ }[];
15
+ }
16
+ /** Own immutable copies and their private cleanup for read/query operations. */
17
+ export declare function withSqliteInputSnapshots<T>(options: SqliteInputSnapshotsOptions, operation: (storage: Awaited<ReturnType<typeof createPrivateSqliteStorage>>, inputs: readonly {
18
+ path: string;
19
+ alias: string;
20
+ }[]) => Promise<T>): Promise<T>;
@@ -0,0 +1,9 @@
1
+ import { type SqliteInputSnapshotsOptions } from './sqlite-input-snapshots.js';
2
+ import { type SqliteRecordValue } from './sqlite-record.js';
3
+ /** Stage native SELECT results as framed SQLite records in caller storage.
4
+ * The spool is never attached to the source connection. Native expression
5
+ * evaluation still owns complete field values; JavaScript transfers are bounded.
6
+ * Streams are borrowed for the callback lifetime. Canonical inputs stay intact. */
7
+ export declare function withSqliteQueryRecords<T>(options: SqliteInputSnapshotsOptions & {
8
+ sql: string;
9
+ }, operation: (rows: AsyncIterable<SqliteRecordValue[]>, columns: readonly string[]) => Promise<T>): Promise<T>;