@theokit/sdk 4.15.2 → 4.15.3

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,51 @@ 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?.() ?? import('sqlite'));
1834
+ return adaptNodeSqlite(new mod.DatabaseSync(filePath));
1835
+ } catch (nodeSqliteCause) {
1836
+ const b = betterSqliteCause instanceof Error ? betterSqliteCause.message : String(betterSqliteCause);
1837
+ const n = nodeSqliteCause instanceof Error ? nodeSqliteCause.message : String(nodeSqliteCause);
1806
1838
  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 }
1839
+ `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}`,
1840
+ { code: "sqlite_driver_unavailable", cause: nodeSqliteCause }
1809
1841
  );
1810
1842
  }
1811
1843
  }
@@ -1824,6 +1856,7 @@ async function renameAside(filePath, label) {
1824
1856
  `
1825
1857
  );
1826
1858
  }
1859
+ var driverLoaderOverrides;
1827
1860
  var init_sqlite_open = __esm({
1828
1861
  "src/internal/persistence/sqlite-open.ts"() {
1829
1862
  init_errors();
@@ -18947,8 +18980,14 @@ var LocalAgentMemory = class {
18947
18980
  return this.toolsCache;
18948
18981
  } catch (cause) {
18949
18982
  const message = cause instanceof Error ? cause.message : String(cause);
18950
- process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
18983
+ const g = globalThis;
18984
+ const sym = /* @__PURE__ */ Symbol.for("theokit-sdk.memory.warned");
18985
+ const warned3 = g[sym] ??= /* @__PURE__ */ new Set();
18986
+ if (!warned3.has(message)) {
18987
+ warned3.add(message);
18988
+ process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
18951
18989
  `);
18990
+ }
18952
18991
  return void 0;
18953
18992
  }
18954
18993
  }