@theokit/sdk 4.15.0 → 4.15.2
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/CHANGELOG.md +12 -0
- package/dist/cron.cjs +107 -8
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.js +110 -11
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +107 -8
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +110 -11
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +108 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +109 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
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,
|
|
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;
|
|
@@ -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
|
|
8936
|
-
const entries = await readWorkspaceDir(
|
|
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(
|
|
8941
|
-
const jsonPath = join(
|
|
8942
|
-
const metadata = existsSync(mdPath) ? await loadPluginManifestFromMarkdown(
|
|
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(
|
|
9022
|
-
const mdPath = join(
|
|
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(
|
|
9032
|
+
const fakeDir = join(pluginsRoot2, folderName);
|
|
9033
9033
|
const entities = await loadMarkdownEntities({
|
|
9034
9034
|
dir: fakeDir,
|
|
9035
9035
|
schema: PluginFrontmatterSchema,
|
|
@@ -12028,6 +12028,103 @@ function registerBuiltins() {
|
|
|
12028
12028
|
registerProvider(CEREBRAS);
|
|
12029
12029
|
registerCatalogProviders();
|
|
12030
12030
|
}
|
|
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
|
+
}));
|
|
12040
|
+
function pluginsRoot() {
|
|
12041
|
+
return join(homedir(), ".theokit", "plugins", "model-providers");
|
|
12042
|
+
}
|
|
12043
|
+
function trustFilePath() {
|
|
12044
|
+
return join(homedir(), ".theokit", "plugins", "trusted-providers.json");
|
|
12045
|
+
}
|
|
12046
|
+
function loadTrustedNames() {
|
|
12047
|
+
const trusted = /* @__PURE__ */ new Set();
|
|
12048
|
+
const path = trustFilePath();
|
|
12049
|
+
if (existsSync(path)) {
|
|
12050
|
+
try {
|
|
12051
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
12052
|
+
if (Array.isArray(parsed)) {
|
|
12053
|
+
let discarded = 0;
|
|
12054
|
+
for (const name of parsed) {
|
|
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
|
+
);
|
|
12063
|
+
}
|
|
12064
|
+
} else {
|
|
12065
|
+
process.stderr.write(
|
|
12066
|
+
`[theokit-sdk] WARN: ${path} is not a JSON array \u2014 trusting NO provider plugins (fail-closed)
|
|
12067
|
+
`
|
|
12068
|
+
);
|
|
12069
|
+
}
|
|
12070
|
+
} catch {
|
|
12071
|
+
process.stderr.write(
|
|
12072
|
+
`[theokit-sdk] WARN: ${path} is not valid JSON \u2014 trusting NO provider plugins (fail-closed)
|
|
12073
|
+
`
|
|
12074
|
+
);
|
|
12075
|
+
}
|
|
12076
|
+
}
|
|
12077
|
+
for (const name of (process.env.THEOKIT_TRUSTED_PROVIDERS ?? "").split(",")) {
|
|
12078
|
+
const trimmed = name.trim();
|
|
12079
|
+
if (trimmed.length > 0) trusted.add(trimmed);
|
|
12080
|
+
}
|
|
12081
|
+
return trusted;
|
|
12082
|
+
}
|
|
12083
|
+
async function discoverProviderPlugins() {
|
|
12084
|
+
if (discoveryState.done) return;
|
|
12085
|
+
discoveryState.done = true;
|
|
12086
|
+
const root = pluginsRoot();
|
|
12087
|
+
if (!existsSync(root)) return;
|
|
12088
|
+
let entries;
|
|
12089
|
+
try {
|
|
12090
|
+
entries = await readdir(root);
|
|
12091
|
+
} catch {
|
|
12092
|
+
return;
|
|
12093
|
+
}
|
|
12094
|
+
const trusted = loadTrustedNames();
|
|
12095
|
+
for (const entry of entries) {
|
|
12096
|
+
if (!trusted.has(entry)) {
|
|
12097
|
+
process.stderr.write(
|
|
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.
|
|
12099
|
+
`
|
|
12100
|
+
);
|
|
12101
|
+
continue;
|
|
12102
|
+
}
|
|
12103
|
+
await loadOne(join(root, entry), entry);
|
|
12104
|
+
}
|
|
12105
|
+
}
|
|
12106
|
+
async function loadOne(dir, entryName) {
|
|
12107
|
+
for (const ext of ["index.mjs", "index.js"]) {
|
|
12108
|
+
const indexPath = join(dir, ext);
|
|
12109
|
+
if (!existsSync(indexPath)) continue;
|
|
12110
|
+
try {
|
|
12111
|
+
const mod = await import(pathToFileURL(indexPath).href);
|
|
12112
|
+
const plugin = mod.default ?? mod[entryName] ?? mod;
|
|
12113
|
+
if (plugin !== null && typeof plugin === "object" && plugin.kind === "model-provider") {
|
|
12114
|
+
const profile = plugin.profile;
|
|
12115
|
+
if (profile !== void 0 && typeof profile === "object") {
|
|
12116
|
+
registerProvider(profile);
|
|
12117
|
+
}
|
|
12118
|
+
}
|
|
12119
|
+
return;
|
|
12120
|
+
} catch (err) {
|
|
12121
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
12122
|
+
process.stderr.write(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
|
|
12123
|
+
`);
|
|
12124
|
+
return;
|
|
12125
|
+
}
|
|
12126
|
+
}
|
|
12127
|
+
}
|
|
12031
12128
|
|
|
12032
12129
|
// src/internal/llm/anthropic.ts
|
|
12033
12130
|
init_errors();
|
|
@@ -18576,6 +18673,7 @@ function resolveAgentPersistenceCwd(options) {
|
|
|
18576
18673
|
return process.cwd();
|
|
18577
18674
|
}
|
|
18578
18675
|
async function rehydrateExistingAgent(agentId, existing, options) {
|
|
18676
|
+
await discoverProviderPlugins();
|
|
18579
18677
|
await validateRehydratedAgent(agentId, existing);
|
|
18580
18678
|
const mergedLocal = options.local !== void 0 && existing.options.local !== void 0 ? { ...existing.options.local, ...options.local } : options.local ?? existing.options.local;
|
|
18581
18679
|
const mergedOptions = {
|
|
@@ -18705,6 +18803,7 @@ var Agent = class _Agent {
|
|
|
18705
18803
|
pluginCount: enabledPluginNames(options.plugins).length
|
|
18706
18804
|
});
|
|
18707
18805
|
try {
|
|
18806
|
+
await discoverProviderPlugins();
|
|
18708
18807
|
const agent = await runCreateUnderSpan(options, span);
|
|
18709
18808
|
return agent;
|
|
18710
18809
|
} catch (err) {
|