@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/cron.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 { stat, readFile, rename, mkdir, readdir, open, unlink, statfs, access } from 'fs/promises';
4
+ import { readdir, stat, readFile, rename, mkdir, open, unlink, statfs, access } from 'fs/promises';
5
5
  import { join, dirname, resolve, sep, relative, isAbsolute } from 'path';
6
- import { existsSync, realpathSync, mkdirSync, lstatSync, readlinkSync, readFileSync, readdirSync, statSync, chmodSync, openSync, writeFileSync, fsyncSync, closeSync, renameSync, unlinkSync } from 'fs';
6
+ import { existsSync, readFileSync, realpathSync, mkdirSync, 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 { 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;
@@ -7145,7 +7145,7 @@ var SkillsManager = class {
7145
7145
  }
7146
7146
  async refresh() {
7147
7147
  const skillsRoot = this.skillsDir ?? join(this.cwd, ".theokit", "skills");
7148
- const discovered = await discoverSkills(skillsRoot, {
7148
+ const discovered2 = await discoverSkills(skillsRoot, {
7149
7149
  onInvalidSkill: (info) => {
7150
7150
  process.stderr.write(
7151
7151
  `[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
@@ -7153,13 +7153,13 @@ var SkillsManager = class {
7153
7153
  );
7154
7154
  }
7155
7155
  });
7156
- this.skills = this.mergeInline(discovered);
7156
+ this.skills = this.mergeInline(discovered2);
7157
7157
  }
7158
7158
  /** M22 — merge inline skills over discovered ones; inline wins on a name conflict. */
7159
- mergeInline(discovered) {
7160
- if (this.inline === void 0 || this.inline.length === 0) return discovered;
7159
+ mergeInline(discovered2) {
7160
+ if (this.inline === void 0 || this.inline.length === 0) return discovered2;
7161
7161
  const inlineNames = new Set(this.inline.map((s) => s.name));
7162
- return [...discovered.filter((s) => !inlineNames.has(s.name)), ...this.inline];
7162
+ return [...discovered2.filter((s) => !inlineNames.has(s.name)), ...this.inline];
7163
7163
  }
7164
7164
  list() {
7165
7165
  return Promise.resolve(this.skills);
@@ -8717,7 +8717,7 @@ var FileContextManager = class {
8717
8717
  const legacy = await loadSources(config, this.cwd);
8718
8718
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
8719
8719
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
8720
- const discovered = await runDiscovery({
8720
+ const discovered2 = await runDiscovery({
8721
8721
  cwd: this.cwd,
8722
8722
  maxBytesPerFile,
8723
8723
  touchedFiles
@@ -8730,7 +8730,7 @@ var FileContextManager = class {
8730
8730
  // matches DEFAULT_DISCOVERY_SPECS theokit-context
8731
8731
  truncated: false
8732
8732
  }));
8733
- const { kept } = applyAggregateCap([...discovered, ...legacyAsAggregator], maxBytesTotal);
8733
+ const { kept } = applyAggregateCap([...discovered2, ...legacyAsAggregator], maxBytesTotal);
8734
8734
  const loadedSources = kept.map((s) => ({
8735
8735
  name: s.id,
8736
8736
  path: s.source,
@@ -8937,14 +8937,14 @@ var PluginsManager = class {
8937
8937
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: MD-first + JSON fallback + both-present detection per plugin folder — branch table is clearer inlined.
8938
8938
  async refresh() {
8939
8939
  this.plugins = [];
8940
- const pluginsRoot = join(this.cwd, ".theokit", "plugins");
8941
- const entries = await readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
8940
+ const pluginsRoot2 = join(this.cwd, ".theokit", "plugins");
8941
+ const entries = await readWorkspaceDir(pluginsRoot2, "plugins_read_error", "plugins directory");
8942
8942
  for (const entry of entries) {
8943
8943
  if (!entry.isDirectory()) continue;
8944
8944
  const folderName = entry.name;
8945
- const mdPath = join(pluginsRoot, folderName, "PLUGIN.md");
8946
- const jsonPath = join(pluginsRoot, folderName, "plugin.json");
8947
- const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
8945
+ const mdPath = join(pluginsRoot2, folderName, "PLUGIN.md");
8946
+ const jsonPath = join(pluginsRoot2, folderName, "plugin.json");
8947
+ const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(pluginsRoot2, folderName) : await loadPluginManifestFromJson(jsonPath, folderName);
8948
8948
  if (existsSync(mdPath) && existsSync(jsonPath)) {
8949
8949
  warnOnce(
8950
8950
  `plugin-${folderName}-both`,
@@ -9023,8 +9023,8 @@ async function loadPluginManifestFromJson(manifestPath, folderName) {
9023
9023
  if (typeof record.entry === "string") metadata.entry = record.entry;
9024
9024
  return metadata;
9025
9025
  }
9026
- async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
9027
- const mdPath = join(pluginsRoot, folderName, "PLUGIN.md");
9026
+ async function loadPluginManifestFromMarkdown(pluginsRoot2, folderName) {
9027
+ const mdPath = join(pluginsRoot2, folderName, "PLUGIN.md");
9028
9028
  let raw;
9029
9029
  try {
9030
9030
  raw = await readFile(mdPath, "utf8");
@@ -9034,7 +9034,7 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
9034
9034
  cause
9035
9035
  });
9036
9036
  }
9037
- const fakeDir = join(pluginsRoot, folderName);
9037
+ const fakeDir = join(pluginsRoot2, folderName);
9038
9038
  const entities = await loadMarkdownEntities({
9039
9039
  dir: fakeDir,
9040
9040
  schema: PluginFrontmatterSchema,
@@ -12033,6 +12033,87 @@ function registerBuiltins() {
12033
12033
  registerProvider(CEREBRAS);
12034
12034
  registerCatalogProviders();
12035
12035
  }
12036
+ var discovered = false;
12037
+ function pluginsRoot() {
12038
+ return join(homedir(), ".theokit", "plugins", "model-providers");
12039
+ }
12040
+ function trustFilePath() {
12041
+ return join(homedir(), ".theokit", "plugins", "trusted-providers.json");
12042
+ }
12043
+ function loadTrustedNames() {
12044
+ const trusted = /* @__PURE__ */ new Set();
12045
+ const path = trustFilePath();
12046
+ if (existsSync(path)) {
12047
+ try {
12048
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
12049
+ if (Array.isArray(parsed)) {
12050
+ for (const name of parsed) {
12051
+ if (typeof name === "string" && name.length > 0) trusted.add(name);
12052
+ }
12053
+ } else {
12054
+ process.stderr.write(
12055
+ `[theokit-sdk] WARN: ${path} is not a JSON array \u2014 trusting NO provider plugins (fail-closed)
12056
+ `
12057
+ );
12058
+ }
12059
+ } catch {
12060
+ process.stderr.write(
12061
+ `[theokit-sdk] WARN: ${path} is not valid JSON \u2014 trusting NO provider plugins (fail-closed)
12062
+ `
12063
+ );
12064
+ }
12065
+ }
12066
+ for (const name of (process.env.THEOKIT_TRUSTED_PROVIDERS ?? "").split(",")) {
12067
+ const trimmed = name.trim();
12068
+ if (trimmed.length > 0) trusted.add(trimmed);
12069
+ }
12070
+ return trusted;
12071
+ }
12072
+ async function discoverProviderPlugins() {
12073
+ if (discovered) return;
12074
+ discovered = true;
12075
+ const root = pluginsRoot();
12076
+ if (!existsSync(root)) return;
12077
+ let entries;
12078
+ try {
12079
+ entries = await readdir(root);
12080
+ } catch {
12081
+ return;
12082
+ }
12083
+ const trusted = loadTrustedNames();
12084
+ for (const entry of entries) {
12085
+ if (!trusted.has(entry)) {
12086
+ process.stderr.write(
12087
+ `[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.
12088
+ `
12089
+ );
12090
+ continue;
12091
+ }
12092
+ await loadOne(join(root, entry), entry);
12093
+ }
12094
+ }
12095
+ async function loadOne(dir, entryName) {
12096
+ for (const ext of ["index.mjs", "index.js"]) {
12097
+ const indexPath = join(dir, ext);
12098
+ if (!existsSync(indexPath)) continue;
12099
+ try {
12100
+ const mod = await import(pathToFileURL(indexPath).href);
12101
+ const plugin = mod.default ?? mod[entryName] ?? mod;
12102
+ if (plugin !== null && typeof plugin === "object" && plugin.kind === "model-provider") {
12103
+ const profile = plugin.profile;
12104
+ if (profile !== void 0 && typeof profile === "object") {
12105
+ registerProvider(profile);
12106
+ }
12107
+ }
12108
+ return;
12109
+ } catch (err) {
12110
+ const msg = err instanceof Error ? err.message : String(err);
12111
+ process.stderr.write(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
12112
+ `);
12113
+ return;
12114
+ }
12115
+ }
12116
+ }
12036
12117
 
12037
12118
  // src/internal/llm/anthropic.ts
12038
12119
  init_errors();
@@ -18710,6 +18791,7 @@ var Agent = class _Agent {
18710
18791
  pluginCount: enabledPluginNames(options.plugins).length
18711
18792
  });
18712
18793
  try {
18794
+ await discoverProviderPlugins();
18713
18795
  const agent = await runCreateUnderSpan(options, span);
18714
18796
  return agent;
18715
18797
  } catch (err) {