@theokit/sdk 4.14.1 → 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/index.js CHANGED
@@ -7,7 +7,7 @@ import { existsSync, rmSync, mkdirSync, renameSync, readFileSync, realpathSync,
7
7
  import { AsyncLocalStorage } from 'async_hooks';
8
8
  import { homedir } from 'os';
9
9
  import { spawn } from 'child_process';
10
- import { fileURLToPath } from 'url';
10
+ import { fileURLToPath, pathToFileURL } from 'url';
11
11
  import { Cron as Cron$1 } from 'croner';
12
12
 
13
13
  var __defProp = Object.defineProperty;
@@ -9723,7 +9723,7 @@ var SkillsManager = class {
9723
9723
  }
9724
9724
  async refresh() {
9725
9725
  const skillsRoot = this.skillsDir ?? join(this.cwd, ".theokit", "skills");
9726
- const discovered = await discoverSkills(skillsRoot, {
9726
+ const discovered2 = await discoverSkills(skillsRoot, {
9727
9727
  onInvalidSkill: (info) => {
9728
9728
  process.stderr.write(
9729
9729
  `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
@@ -9731,13 +9731,13 @@ var SkillsManager = class {
9731
9731
  );
9732
9732
  }
9733
9733
  });
9734
- this.skills = this.mergeInline(discovered);
9734
+ this.skills = this.mergeInline(discovered2);
9735
9735
  }
9736
9736
  /** M22 — merge inline skills over discovered ones; inline wins on a name conflict. */
9737
- mergeInline(discovered) {
9738
- if (this.inline === void 0 || this.inline.length === 0) return discovered;
9737
+ mergeInline(discovered2) {
9738
+ if (this.inline === void 0 || this.inline.length === 0) return discovered2;
9739
9739
  const inlineNames = new Set(this.inline.map((s) => s.name));
9740
- return [...discovered.filter((s) => !inlineNames.has(s.name)), ...this.inline];
9740
+ return [...discovered2.filter((s) => !inlineNames.has(s.name)), ...this.inline];
9741
9741
  }
9742
9742
  list() {
9743
9743
  return Promise.resolve(this.skills);
@@ -11298,7 +11298,7 @@ var FileContextManager = class {
11298
11298
  const legacy = await loadSources(config, this.cwd);
11299
11299
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
11300
11300
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
11301
- const discovered = await runDiscovery({
11301
+ const discovered2 = await runDiscovery({
11302
11302
  cwd: this.cwd,
11303
11303
  maxBytesPerFile,
11304
11304
  touchedFiles
@@ -11311,7 +11311,7 @@ var FileContextManager = class {
11311
11311
  // matches DEFAULT_DISCOVERY_SPECS theokit-context
11312
11312
  truncated: false
11313
11313
  }));
11314
- const { kept } = applyAggregateCap([...discovered, ...legacyAsAggregator], maxBytesTotal);
11314
+ const { kept } = applyAggregateCap([...discovered2, ...legacyAsAggregator], maxBytesTotal);
11315
11315
  const loadedSources = kept.map((s) => ({
11316
11316
  name: s.id,
11317
11317
  path: s.source,
@@ -11519,14 +11519,14 @@ var PluginsManager = class {
11519
11519
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: MD-first + JSON fallback + both-present detection per plugin folder — branch table is clearer inlined.
11520
11520
  async refresh() {
11521
11521
  this.plugins = [];
11522
- const pluginsRoot = join(this.cwd, ".theokit", "plugins");
11523
- const entries = await readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
11522
+ const pluginsRoot2 = join(this.cwd, ".theokit", "plugins");
11523
+ const entries = await readWorkspaceDir(pluginsRoot2, "plugins_read_error", "plugins directory");
11524
11524
  for (const entry of entries) {
11525
11525
  if (!entry.isDirectory()) continue;
11526
11526
  const folderName = entry.name;
11527
- const mdPath = join(pluginsRoot, folderName, "PLUGIN.md");
11528
- const jsonPath = join(pluginsRoot, folderName, "plugin.json");
11529
- const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
11527
+ const mdPath = join(pluginsRoot2, folderName, "PLUGIN.md");
11528
+ const jsonPath = join(pluginsRoot2, folderName, "plugin.json");
11529
+ const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot2, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
11530
11530
  if (existsSync(mdPath) && existsSync(jsonPath)) {
11531
11531
  warnOnce(
11532
11532
  `plugin-${folderName}-both`,
@@ -11605,8 +11605,8 @@ async function loadPluginManifestFromJson(manifestPath, folderName) {
11605
11605
  if (typeof record.entry === "string") metadata.entry = record.entry;
11606
11606
  return metadata;
11607
11607
  }
11608
- async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
11609
- const mdPath = join(pluginsRoot, folderName, "PLUGIN.md");
11608
+ async function loadPluginManifestFromMarkdown(pluginsRoot2, folderName) {
11609
+ const mdPath = join(pluginsRoot2, folderName, "PLUGIN.md");
11610
11610
  let raw;
11611
11611
  try {
11612
11612
  raw = await readFile(mdPath, "utf8");
@@ -11616,7 +11616,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
11616
11616
  cause
11617
11617
  });
11618
11618
  }
11619
- const fakeDir = join(pluginsRoot, folderName);
11619
+ const fakeDir = join(pluginsRoot2, folderName);
11620
11620
  const entities = await loadMarkdownEntities({
11621
11621
  dir: fakeDir,
11622
11622
  schema: PluginFrontmatterSchema,
@@ -14632,6 +14632,87 @@ function registerBuiltins() {
14632
14632
  registerProvider(CEREBRAS);
14633
14633
  registerCatalogProviders();
14634
14634
  }
14635
+ var discovered = false;
14636
+ function pluginsRoot() {
14637
+ return join(homedir(), ".theokit", "plugins", "model-providers");
14638
+ }
14639
+ function trustFilePath() {
14640
+ return join(homedir(), ".theokit", "plugins", "trusted-providers.json");
14641
+ }
14642
+ function loadTrustedNames() {
14643
+ const trusted = /* @__PURE__ */ new Set();
14644
+ const path = trustFilePath();
14645
+ if (existsSync(path)) {
14646
+ try {
14647
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
14648
+ if (Array.isArray(parsed)) {
14649
+ for (const name of parsed) {
14650
+ if (typeof name === "string" && name.length > 0) trusted.add(name);
14651
+ }
14652
+ } else {
14653
+ process.stderr.write(
14654
+ `[theokit-sdk] WARN: ${path} is not a JSON array \u2014 trusting NO provider plugins (fail-closed)
14655
+ `
14656
+ );
14657
+ }
14658
+ } catch {
14659
+ process.stderr.write(
14660
+ `[theokit-sdk] WARN: ${path} is not valid JSON \u2014 trusting NO provider plugins (fail-closed)
14661
+ `
14662
+ );
14663
+ }
14664
+ }
14665
+ for (const name of (process.env.THEOKIT_TRUSTED_PROVIDERS ?? "").split(",")) {
14666
+ const trimmed = name.trim();
14667
+ if (trimmed.length > 0) trusted.add(trimmed);
14668
+ }
14669
+ return trusted;
14670
+ }
14671
+ async function discoverProviderPlugins() {
14672
+ if (discovered) return;
14673
+ discovered = true;
14674
+ const root = pluginsRoot();
14675
+ if (!existsSync(root)) return;
14676
+ let entries;
14677
+ try {
14678
+ entries = await readdir(root);
14679
+ } catch {
14680
+ return;
14681
+ }
14682
+ const trusted = loadTrustedNames();
14683
+ for (const entry of entries) {
14684
+ if (!trusted.has(entry)) {
14685
+ process.stderr.write(
14686
+ `[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.
14687
+ `
14688
+ );
14689
+ continue;
14690
+ }
14691
+ await loadOne(join(root, entry), entry);
14692
+ }
14693
+ }
14694
+ async function loadOne(dir, entryName) {
14695
+ for (const ext of ["index.mjs", "index.js"]) {
14696
+ const indexPath = join(dir, ext);
14697
+ if (!existsSync(indexPath)) continue;
14698
+ try {
14699
+ const mod = await import(pathToFileURL(indexPath).href);
14700
+ const plugin = mod.default ?? mod[entryName] ?? mod;
14701
+ if (plugin !== null && typeof plugin === "object" && plugin.kind === "model-provider") {
14702
+ const profile = plugin.profile;
14703
+ if (profile !== void 0 && typeof profile === "object") {
14704
+ registerProvider(profile);
14705
+ }
14706
+ }
14707
+ return;
14708
+ } catch (err) {
14709
+ const msg = err instanceof Error ? err.message : String(err);
14710
+ process.stderr.write(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
14711
+ `);
14712
+ return;
14713
+ }
14714
+ }
14715
+ }
14635
14716
 
14636
14717
  // src/internal/llm/anthropic.ts
14637
14718
  init_errors();
@@ -20363,6 +20444,7 @@ var Agent = class _Agent {
20363
20444
  pluginCount: enabledPluginNames(options.plugins).length
20364
20445
  });
20365
20446
  try {
20447
+ await discoverProviderPlugins();
20366
20448
  const agent = await runCreateUnderSpan(options, span);
20367
20449
  return agent;
20368
20450
  } catch (err) {