@theokit/sdk 4.15.2 → 4.15.4

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/dist/index.cjs CHANGED
@@ -1793,19 +1793,55 @@ async function openConcrete(options) {
1793
1793
  await options.onOpen?.(db);
1794
1794
  return db;
1795
1795
  }
1796
+ function adaptNodeSqlite(db) {
1797
+ const pragma = (statement, options) => {
1798
+ const stmt = db.prepare(`PRAGMA ${statement}`);
1799
+ const row = stmt.get();
1800
+ if (options?.simple === true) {
1801
+ return row === void 0 ? void 0 : Object.values(row)[0];
1802
+ }
1803
+ return row === void 0 ? [] : [row];
1804
+ };
1805
+ return new Proxy(db, {
1806
+ get(target, prop, receiver) {
1807
+ if (prop === "pragma") return pragma;
1808
+ if (prop === "loadExtension" && typeof db.loadExtension !== "function") {
1809
+ return () => {
1810
+ throw new Error(
1811
+ "SQLite extension loading is unavailable on the node:sqlite fallback \u2014 install better-sqlite3 for sqlite-vec"
1812
+ );
1813
+ };
1814
+ }
1815
+ const value = Reflect.get(target, prop, receiver);
1816
+ return typeof value === "function" ? value.bind(target) : value;
1817
+ }
1818
+ });
1819
+ }
1796
1820
  async function loadDriver(filePath) {
1821
+ let betterSqliteCause;
1797
1822
  try {
1798
- const mod = await import('better-sqlite3');
1823
+ const mod = await (driverLoaderOverrides?.betterSqlite3?.() ?? import('better-sqlite3'));
1799
1824
  const Ctor = mod.default ?? mod;
1800
1825
  if (typeof Ctor !== "function") {
1801
1826
  throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
1802
1827
  }
1803
1828
  return new Ctor(filePath);
1804
1829
  } catch (cause) {
1805
- const message = cause instanceof Error ? cause.message : String(cause);
1830
+ betterSqliteCause = cause;
1831
+ }
1832
+ try {
1833
+ const mod = await (driverLoaderOverrides?.nodeSqlite?.() ?? Promise.resolve(
1834
+ process.getBuiltinModule?.("node:sqlite") ?? (() => {
1835
+ throw new Error("node:sqlite built-in unavailable (Node < 22.3)");
1836
+ })()
1837
+ ));
1838
+ return adaptNodeSqlite(new mod.DatabaseSync(filePath));
1839
+ } catch (nodeSqliteCause) {
1840
+ const b = betterSqliteCause instanceof Error ? betterSqliteCause.message : String(betterSqliteCause);
1841
+ const n = nodeSqliteCause instanceof Error ? nodeSqliteCause.message : String(nodeSqliteCause);
1806
1842
  throw new exports.ConfigurationError(
1807
- `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
1808
- { code: "sqlite_driver_unavailable", cause }
1843
+ `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. better-sqlite3: ${b}; node:sqlite: ${n}`,
1844
+ { code: "sqlite_driver_unavailable", cause: nodeSqliteCause }
1809
1845
  );
1810
1846
  }
1811
1847
  }
@@ -1824,6 +1860,7 @@ async function renameAside(filePath, label) {
1824
1860
  `
1825
1861
  );
1826
1862
  }
1863
+ var driverLoaderOverrides;
1827
1864
  var init_sqlite_open = __esm({
1828
1865
  "src/internal/persistence/sqlite-open.ts"() {
1829
1866
  init_errors();
@@ -18947,8 +18984,14 @@ var LocalAgentMemory = class {
18947
18984
  return this.toolsCache;
18948
18985
  } catch (cause) {
18949
18986
  const message = cause instanceof Error ? cause.message : String(cause);
18950
- process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
18987
+ const g = globalThis;
18988
+ const sym = /* @__PURE__ */ Symbol.for("theokit-sdk.memory.warned");
18989
+ const warned3 = g[sym] ??= /* @__PURE__ */ new Set();
18990
+ if (!warned3.has(message)) {
18991
+ warned3.add(message);
18992
+ process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
18951
18993
  `);
18994
+ }
18952
18995
  return void 0;
18953
18996
  }
18954
18997
  }