@theokit/sdk 4.15.1 → 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/eval.js CHANGED
@@ -7140,7 +7140,7 @@ var SkillsManager = class {
7140
7140
  }
7141
7141
  async refresh() {
7142
7142
  const skillsRoot = this.skillsDir ?? join(this.cwd, ".theokit", "skills");
7143
- const discovered2 = await discoverSkills(skillsRoot, {
7143
+ const discovered = await discoverSkills(skillsRoot, {
7144
7144
  onInvalidSkill: (info) => {
7145
7145
  process.stderr.write(
7146
7146
  `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
@@ -7148,13 +7148,13 @@ var SkillsManager = class {
7148
7148
  );
7149
7149
  }
7150
7150
  });
7151
- this.skills = this.mergeInline(discovered2);
7151
+ this.skills = this.mergeInline(discovered);
7152
7152
  }
7153
7153
  /** M22 — merge inline skills over discovered ones; inline wins on a name conflict. */
7154
- mergeInline(discovered2) {
7155
- if (this.inline === void 0 || this.inline.length === 0) return discovered2;
7154
+ mergeInline(discovered) {
7155
+ if (this.inline === void 0 || this.inline.length === 0) return discovered;
7156
7156
  const inlineNames = new Set(this.inline.map((s) => s.name));
7157
- return [...discovered2.filter((s) => !inlineNames.has(s.name)), ...this.inline];
7157
+ return [...discovered.filter((s) => !inlineNames.has(s.name)), ...this.inline];
7158
7158
  }
7159
7159
  list() {
7160
7160
  return Promise.resolve(this.skills);
@@ -8712,7 +8712,7 @@ var FileContextManager = class {
8712
8712
  const legacy = await loadSources(config, this.cwd);
8713
8713
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
8714
8714
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
8715
- const discovered2 = await runDiscovery({
8715
+ const discovered = await runDiscovery({
8716
8716
  cwd: this.cwd,
8717
8717
  maxBytesPerFile,
8718
8718
  touchedFiles
@@ -8725,7 +8725,7 @@ var FileContextManager = class {
8725
8725
  // matches DEFAULT_DISCOVERY_SPECS theokit-context
8726
8726
  truncated: false
8727
8727
  }));
8728
- const { kept } = applyAggregateCap([...discovered2, ...legacyAsAggregator], maxBytesTotal);
8728
+ const { kept } = applyAggregateCap([...discovered, ...legacyAsAggregator], maxBytesTotal);
8729
8729
  const loadedSources = kept.map((s) => ({
8730
8730
  name: s.id,
8731
8731
  path: s.source,
@@ -12028,7 +12028,15 @@ function registerBuiltins() {
12028
12028
  registerProvider(CEREBRAS);
12029
12029
  registerCatalogProviders();
12030
12030
  }
12031
- var discovered = false;
12031
+ function globalSingleton3(key, create) {
12032
+ const g = globalThis;
12033
+ const sym = Symbol.for(key);
12034
+ if (g[sym] === void 0) g[sym] = create();
12035
+ return g[sym];
12036
+ }
12037
+ var discoveryState = globalSingleton3("theokit-sdk.providers.discovered", () => ({
12038
+ done: false
12039
+ }));
12032
12040
  function pluginsRoot() {
12033
12041
  return join(homedir(), ".theokit", "plugins", "model-providers");
12034
12042
  }
@@ -12042,8 +12050,16 @@ function loadTrustedNames() {
12042
12050
  try {
12043
12051
  const parsed = JSON.parse(readFileSync(path, "utf-8"));
12044
12052
  if (Array.isArray(parsed)) {
12053
+ let discarded = 0;
12045
12054
  for (const name of parsed) {
12046
12055
  if (typeof name === "string" && name.length > 0) trusted.add(name);
12056
+ else discarded += 1;
12057
+ }
12058
+ if (discarded > 0) {
12059
+ process.stderr.write(
12060
+ `[theokit-sdk] WARN: ${path} contains ${discarded} non-string entr${discarded === 1 ? "y" : "ies"} \u2014 discarded (entries must be plugin-name strings)
12061
+ `
12062
+ );
12047
12063
  }
12048
12064
  } else {
12049
12065
  process.stderr.write(
@@ -12065,8 +12081,8 @@ function loadTrustedNames() {
12065
12081
  return trusted;
12066
12082
  }
12067
12083
  async function discoverProviderPlugins() {
12068
- if (discovered) return;
12069
- discovered = true;
12084
+ if (discoveryState.done) return;
12085
+ discoveryState.done = true;
12070
12086
  const root = pluginsRoot();
12071
12087
  if (!existsSync(root)) return;
12072
12088
  let entries;
@@ -12079,7 +12095,7 @@ async function discoverProviderPlugins() {
12079
12095
  for (const entry of entries) {
12080
12096
  if (!trusted.has(entry)) {
12081
12097
  process.stderr.write(
12082
- `[theokit-sdk] WARN: provider plugin "${entry}" is present but NOT trusted \u2014 skipped. To trust it, add "${entry}" to ${trustFilePath()} (JSON array) or THEOKIT_TRUSTED_PROVIDERS.
12098
+ `[theokit-sdk] WARN: provider plugin "${entry}" is present but NOT trusted \u2014 skipped. To trust it, add "${entry}" to ${trustFilePath()} (JSON array of names) or THEOKIT_TRUSTED_PROVIDERS (comma-separated), then restart the process.
12083
12099
  `
12084
12100
  );
12085
12101
  continue;
@@ -16222,19 +16238,52 @@ async function openConcrete(options) {
16222
16238
  await options.onOpen?.(db);
16223
16239
  return db;
16224
16240
  }
16241
+ var driverLoaderOverrides;
16242
+ function adaptNodeSqlite(db) {
16243
+ const pragma = (statement, options) => {
16244
+ const stmt = db.prepare(`PRAGMA ${statement}`);
16245
+ const row = stmt.get();
16246
+ if (options?.simple === true) {
16247
+ return row === void 0 ? void 0 : Object.values(row)[0];
16248
+ }
16249
+ return row === void 0 ? [] : [row];
16250
+ };
16251
+ return new Proxy(db, {
16252
+ get(target, prop, receiver) {
16253
+ if (prop === "pragma") return pragma;
16254
+ if (prop === "loadExtension" && typeof db.loadExtension !== "function") {
16255
+ return () => {
16256
+ throw new Error(
16257
+ "SQLite extension loading is unavailable on the node:sqlite fallback \u2014 install better-sqlite3 for sqlite-vec"
16258
+ );
16259
+ };
16260
+ }
16261
+ const value = Reflect.get(target, prop, receiver);
16262
+ return typeof value === "function" ? value.bind(target) : value;
16263
+ }
16264
+ });
16265
+ }
16225
16266
  async function loadDriver(filePath) {
16267
+ let betterSqliteCause;
16226
16268
  try {
16227
- const mod = await import('better-sqlite3');
16269
+ const mod = await (driverLoaderOverrides?.betterSqlite3?.() ?? import('better-sqlite3'));
16228
16270
  const Ctor = mod.default ?? mod;
16229
16271
  if (typeof Ctor !== "function") {
16230
16272
  throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
16231
16273
  }
16232
16274
  return new Ctor(filePath);
16233
16275
  } catch (cause) {
16234
- const message = cause instanceof Error ? cause.message : String(cause);
16276
+ betterSqliteCause = cause;
16277
+ }
16278
+ try {
16279
+ const mod = await (driverLoaderOverrides?.nodeSqlite?.() ?? import('sqlite'));
16280
+ return adaptNodeSqlite(new mod.DatabaseSync(filePath));
16281
+ } catch (nodeSqliteCause) {
16282
+ const b = betterSqliteCause instanceof Error ? betterSqliteCause.message : String(betterSqliteCause);
16283
+ const n = nodeSqliteCause instanceof Error ? nodeSqliteCause.message : String(nodeSqliteCause);
16235
16284
  throw new ConfigurationError(
16236
- `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
16237
- { code: "sqlite_driver_unavailable", cause }
16285
+ `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}`,
16286
+ { code: "sqlite_driver_unavailable", cause: nodeSqliteCause }
16238
16287
  );
16239
16288
  }
16240
16289
  }
@@ -17271,8 +17320,14 @@ var LocalAgentMemory = class {
17271
17320
  return this.toolsCache;
17272
17321
  } catch (cause) {
17273
17322
  const message = cause instanceof Error ? cause.message : String(cause);
17274
- process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
17323
+ const g = globalThis;
17324
+ const sym = /* @__PURE__ */ Symbol.for("theokit-sdk.memory.warned");
17325
+ const warned3 = g[sym] ??= /* @__PURE__ */ new Set();
17326
+ if (!warned3.has(message)) {
17327
+ warned3.add(message);
17328
+ process.stderr.write(`[theokit-sdk] memory tools unavailable: ${message}
17275
17329
  `);
17330
+ }
17276
17331
  return void 0;
17277
17332
  }
17278
17333
  }
@@ -18657,6 +18712,7 @@ function resolveAgentPersistenceCwd(options) {
18657
18712
  return process.cwd();
18658
18713
  }
18659
18714
  async function rehydrateExistingAgent(agentId, existing, options) {
18715
+ await discoverProviderPlugins();
18660
18716
  await validateRehydratedAgent(agentId, existing);
18661
18717
  const mergedLocal = options.local !== void 0 && existing.options.local !== void 0 ? { ...existing.options.local, ...options.local } : options.local ?? existing.options.local;
18662
18718
  const mergedOptions = {