@theokit/sdk 4.15.0 → 4.15.1

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
@@ -1,13 +1,13 @@
1
1
  import { z, toJSONSchema } from 'zod';
2
2
  import { createRequire } from 'module';
3
3
  import { randomUUID, createHash, randomBytes } from 'crypto';
4
- import { mkdir, writeFile, stat, readFile, rename, readdir, open, unlink, statfs, access } from 'fs/promises';
4
+ import { mkdir, writeFile, readdir, stat, readFile, rename, open, unlink, statfs, access } from 'fs/promises';
5
5
  import { join, dirname, resolve, sep, relative, isAbsolute } from 'path';
6
- import { readFileSync, mkdirSync, appendFileSync, existsSync, realpathSync, lstatSync, readlinkSync, readdirSync, statSync, chmodSync, openSync, writeFileSync, fsyncSync, closeSync, renameSync, unlinkSync } from 'fs';
6
+ import { readFileSync, existsSync, mkdirSync, appendFileSync, realpathSync, lstatSync, readlinkSync, statSync, chmodSync, openSync, writeFileSync, fsyncSync, closeSync, renameSync, unlinkSync, readdirSync } from 'fs';
7
7
  import { AsyncLocalStorage } from 'async_hooks';
8
8
  import { homedir } from 'os';
9
9
  import { execFile, spawn } from 'child_process';
10
- import { fileURLToPath } from 'url';
10
+ import { fileURLToPath, pathToFileURL } from 'url';
11
11
 
12
12
  var __defProp = Object.defineProperty;
13
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -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 discovered = await discoverSkills(skillsRoot, {
7143
+ const discovered2 = 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(discovered);
7151
+ this.skills = this.mergeInline(discovered2);
7152
7152
  }
7153
7153
  /** M22 — merge inline skills over discovered ones; inline wins on a name conflict. */
7154
- mergeInline(discovered) {
7155
- if (this.inline === void 0 || this.inline.length === 0) return discovered;
7154
+ mergeInline(discovered2) {
7155
+ if (this.inline === void 0 || this.inline.length === 0) return discovered2;
7156
7156
  const inlineNames = new Set(this.inline.map((s) => s.name));
7157
- return [...discovered.filter((s) => !inlineNames.has(s.name)), ...this.inline];
7157
+ return [...discovered2.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 discovered = await runDiscovery({
8715
+ const discovered2 = 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([...discovered, ...legacyAsAggregator], maxBytesTotal);
8728
+ const { kept } = applyAggregateCap([...discovered2, ...legacyAsAggregator], maxBytesTotal);
8729
8729
  const loadedSources = kept.map((s) => ({
8730
8730
  name: s.id,
8731
8731
  path: s.source,
@@ -8932,14 +8932,14 @@ var PluginsManager = class {
8932
8932
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: MD-first + JSON fallback + both-present detection per plugin folder — branch table is clearer inlined.
8933
8933
  async refresh() {
8934
8934
  this.plugins = [];
8935
- const pluginsRoot = join(this.cwd, ".theokit", "plugins");
8936
- const entries = await readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
8935
+ const pluginsRoot2 = join(this.cwd, ".theokit", "plugins");
8936
+ const entries = await readWorkspaceDir(pluginsRoot2, "plugins_read_error", "plugins directory");
8937
8937
  for (const entry of entries) {
8938
8938
  if (!entry.isDirectory()) continue;
8939
8939
  const folderName = entry.name;
8940
- const mdPath = join(pluginsRoot, folderName, "PLUGIN.md");
8941
- const jsonPath = join(pluginsRoot, folderName, "plugin.json");
8942
- const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
8940
+ const mdPath = join(pluginsRoot2, folderName, "PLUGIN.md");
8941
+ const jsonPath = join(pluginsRoot2, folderName, "plugin.json");
8942
+ const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot2, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
8943
8943
  if (existsSync(mdPath) && existsSync(jsonPath)) {
8944
8944
  warnOnce(
8945
8945
  `plugin-${folderName}-both`,
@@ -9018,8 +9018,8 @@ async function loadPluginManifestFromJson(manifestPath, folderName) {
9018
9018
  if (typeof record.entry === "string") metadata.entry = record.entry;
9019
9019
  return metadata;
9020
9020
  }
9021
- async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
9022
- const mdPath = join(pluginsRoot, folderName, "PLUGIN.md");
9021
+ async function loadPluginManifestFromMarkdown(pluginsRoot2, folderName) {
9022
+ const mdPath = join(pluginsRoot2, folderName, "PLUGIN.md");
9023
9023
  let raw;
9024
9024
  try {
9025
9025
  raw = await readFile(mdPath, "utf8");
@@ -9029,7 +9029,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
9029
9029
  cause
9030
9030
  });
9031
9031
  }
9032
- const fakeDir = join(pluginsRoot, folderName);
9032
+ const fakeDir = join(pluginsRoot2, folderName);
9033
9033
  const entities = await loadMarkdownEntities({
9034
9034
  dir: fakeDir,
9035
9035
  schema: PluginFrontmatterSchema,
@@ -12028,6 +12028,87 @@ function registerBuiltins() {
12028
12028
  registerProvider(CEREBRAS);
12029
12029
  registerCatalogProviders();
12030
12030
  }
12031
+ var discovered = false;
12032
+ function pluginsRoot() {
12033
+ return join(homedir(), ".theokit", "plugins", "model-providers");
12034
+ }
12035
+ function trustFilePath() {
12036
+ return join(homedir(), ".theokit", "plugins", "trusted-providers.json");
12037
+ }
12038
+ function loadTrustedNames() {
12039
+ const trusted = /* @__PURE__ */ new Set();
12040
+ const path = trustFilePath();
12041
+ if (existsSync(path)) {
12042
+ try {
12043
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
12044
+ if (Array.isArray(parsed)) {
12045
+ for (const name of parsed) {
12046
+ if (typeof name === "string" && name.length > 0) trusted.add(name);
12047
+ }
12048
+ } else {
12049
+ process.stderr.write(
12050
+ `[theokit-sdk] WARN: ${path} is not a JSON array \u2014 trusting NO provider plugins (fail-closed)
12051
+ `
12052
+ );
12053
+ }
12054
+ } catch {
12055
+ process.stderr.write(
12056
+ `[theokit-sdk] WARN: ${path} is not valid JSON \u2014 trusting NO provider plugins (fail-closed)
12057
+ `
12058
+ );
12059
+ }
12060
+ }
12061
+ for (const name of (process.env.THEOKIT_TRUSTED_PROVIDERS ?? "").split(",")) {
12062
+ const trimmed = name.trim();
12063
+ if (trimmed.length > 0) trusted.add(trimmed);
12064
+ }
12065
+ return trusted;
12066
+ }
12067
+ async function discoverProviderPlugins() {
12068
+ if (discovered) return;
12069
+ discovered = true;
12070
+ const root = pluginsRoot();
12071
+ if (!existsSync(root)) return;
12072
+ let entries;
12073
+ try {
12074
+ entries = await readdir(root);
12075
+ } catch {
12076
+ return;
12077
+ }
12078
+ const trusted = loadTrustedNames();
12079
+ for (const entry of entries) {
12080
+ if (!trusted.has(entry)) {
12081
+ 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.
12083
+ `
12084
+ );
12085
+ continue;
12086
+ }
12087
+ await loadOne(join(root, entry), entry);
12088
+ }
12089
+ }
12090
+ async function loadOne(dir, entryName) {
12091
+ for (const ext of ["index.mjs", "index.js"]) {
12092
+ const indexPath = join(dir, ext);
12093
+ if (!existsSync(indexPath)) continue;
12094
+ try {
12095
+ const mod = await import(pathToFileURL(indexPath).href);
12096
+ const plugin = mod.default ?? mod[entryName] ?? mod;
12097
+ if (plugin !== null && typeof plugin === "object" && plugin.kind === "model-provider") {
12098
+ const profile = plugin.profile;
12099
+ if (profile !== void 0 && typeof profile === "object") {
12100
+ registerProvider(profile);
12101
+ }
12102
+ }
12103
+ return;
12104
+ } catch (err) {
12105
+ const msg = err instanceof Error ? err.message : String(err);
12106
+ process.stderr.write(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
12107
+ `);
12108
+ return;
12109
+ }
12110
+ }
12111
+ }
12031
12112
 
12032
12113
  // src/internal/llm/anthropic.ts
12033
12114
  init_errors();
@@ -18705,6 +18786,7 @@ var Agent = class _Agent {
18705
18786
  pluginCount: enabledPluginNames(options.plugins).length
18706
18787
  });
18707
18788
  try {
18789
+ await discoverProviderPlugins();
18708
18790
  const agent = await runCreateUnderSpan(options, span);
18709
18791
  return agent;
18710
18792
  } catch (err) {