@theokit/sdk 4.12.1 → 4.13.0
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 +165 -79
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.js +165 -79
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +165 -79
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +165 -79
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +179 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +179 -93
- package/dist/index.js.map +1 -1
- package/dist/internal/providers/catalog-loader.d.ts +8 -0
- package/dist/internal/providers/catalog-schema.d.ts +53 -0
- package/dist/internal/providers/catalog-source-models-dev.d.ts +33 -0
- package/dist/models.cjs +332 -257
- package/dist/models.cjs.map +1 -1
- package/dist/models.d.cts +2 -0
- package/dist/models.d.ts +2 -0
- package/dist/models.js +330 -258
- package/dist/models.js.map +1 -1
- package/dist/provider-catalog.json +571 -5
- package/package.json +1 -1
package/dist/eval.cjs
CHANGED
|
@@ -569,10 +569,10 @@ function buildToolPrompt(prompt) {
|
|
|
569
569
|
Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
|
|
570
570
|
}
|
|
571
571
|
function setupStructuredOutput(schema, maxRetries) {
|
|
572
|
-
const
|
|
572
|
+
const z11 = requireZod();
|
|
573
573
|
const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
|
|
574
574
|
return {
|
|
575
|
-
z:
|
|
575
|
+
z: z11,
|
|
576
576
|
jsonSchema,
|
|
577
577
|
maxRetries: maxRetries ?? 1,
|
|
578
578
|
initialUsage: { inputTokens: 0, outputTokens: 0 }
|
|
@@ -10499,6 +10499,144 @@ function applyToolResultGuard(parts, opts) {
|
|
|
10499
10499
|
)
|
|
10500
10500
|
);
|
|
10501
10501
|
}
|
|
10502
|
+
var MODALITIES = ["text", "audio", "image", "video", "pdf"];
|
|
10503
|
+
var costSchema = zod.z.object({
|
|
10504
|
+
/** USD per 1M tokens (models.dev convention). */
|
|
10505
|
+
input: zod.z.number().nonnegative(),
|
|
10506
|
+
output: zod.z.number().nonnegative(),
|
|
10507
|
+
cache_read: zod.z.number().nonnegative().optional(),
|
|
10508
|
+
cache_write: zod.z.number().nonnegative().optional()
|
|
10509
|
+
}).loose();
|
|
10510
|
+
var limitSchema = zod.z.object({
|
|
10511
|
+
context: zod.z.number().positive(),
|
|
10512
|
+
input: zod.z.number().positive().optional(),
|
|
10513
|
+
output: zod.z.number().positive().optional()
|
|
10514
|
+
}).loose();
|
|
10515
|
+
var modalitiesSchema = zod.z.object({
|
|
10516
|
+
input: zod.z.array(zod.z.enum(MODALITIES)).optional(),
|
|
10517
|
+
output: zod.z.array(zod.z.enum(MODALITIES)).optional()
|
|
10518
|
+
}).loose();
|
|
10519
|
+
var catalogModelSchema = zod.z.object({
|
|
10520
|
+
name: zod.z.string().optional(),
|
|
10521
|
+
release_date: zod.z.string().optional(),
|
|
10522
|
+
attachment: zod.z.boolean().optional(),
|
|
10523
|
+
reasoning: zod.z.boolean().optional(),
|
|
10524
|
+
temperature: zod.z.boolean().optional(),
|
|
10525
|
+
tool_call: zod.z.boolean().optional(),
|
|
10526
|
+
/** theokit extension — maps to ModelCapabilities.supportsStructuredOutput. */
|
|
10527
|
+
structured_output: zod.z.boolean().optional(),
|
|
10528
|
+
/** theokit extension — maps to ModelCapabilities.supportsCacheControl. */
|
|
10529
|
+
cache_control: zod.z.boolean().optional(),
|
|
10530
|
+
cost: costSchema.optional(),
|
|
10531
|
+
limit: limitSchema.optional(),
|
|
10532
|
+
modalities: modalitiesSchema.optional(),
|
|
10533
|
+
status: zod.z.enum(["alpha", "beta", "deprecated"]).optional()
|
|
10534
|
+
}).loose();
|
|
10535
|
+
|
|
10536
|
+
// src/internal/providers/registry.ts
|
|
10537
|
+
var REGISTRY = /* @__PURE__ */ new Map();
|
|
10538
|
+
var ALIASES = /* @__PURE__ */ new Map();
|
|
10539
|
+
function registerProvider(profile) {
|
|
10540
|
+
if (REGISTRY.has(profile.name)) {
|
|
10541
|
+
process.stderr.write(`[theokit-sdk] Provider "${profile.name}" overridden by user plugin.
|
|
10542
|
+
`);
|
|
10543
|
+
}
|
|
10544
|
+
REGISTRY.set(profile.name, profile);
|
|
10545
|
+
for (const alias of profile.aliases ?? []) {
|
|
10546
|
+
const previous = ALIASES.get(alias);
|
|
10547
|
+
if (previous !== void 0 && previous !== profile.name) {
|
|
10548
|
+
process.stderr.write(
|
|
10549
|
+
`[theokit-sdk] Alias "${alias}" collision: was "${previous}", now "${profile.name}".
|
|
10550
|
+
`
|
|
10551
|
+
);
|
|
10552
|
+
}
|
|
10553
|
+
ALIASES.set(alias, profile.name);
|
|
10554
|
+
}
|
|
10555
|
+
}
|
|
10556
|
+
function getProviderProfile(name) {
|
|
10557
|
+
const canonical = ALIASES.get(name) ?? name;
|
|
10558
|
+
return REGISTRY.get(canonical);
|
|
10559
|
+
}
|
|
10560
|
+
|
|
10561
|
+
// src/internal/providers/catalog-loader.ts
|
|
10562
|
+
var __dirname_resolved = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('eval.cjs', document.baseURI).href))));
|
|
10563
|
+
var modelInfoIndex = /* @__PURE__ */ new Map();
|
|
10564
|
+
function getCatalogModelInfo(key) {
|
|
10565
|
+
ensureModelIndexLoaded();
|
|
10566
|
+
return modelInfoIndex.get(key);
|
|
10567
|
+
}
|
|
10568
|
+
var _modelIndexLoaded = false;
|
|
10569
|
+
function ensureModelIndexLoaded() {
|
|
10570
|
+
if (_modelIndexLoaded) return;
|
|
10571
|
+
_modelIndexLoaded = true;
|
|
10572
|
+
const catalog = loadProviderCatalog();
|
|
10573
|
+
for (const entry of Object.values(catalog)) {
|
|
10574
|
+
indexEntryModels(entry);
|
|
10575
|
+
}
|
|
10576
|
+
}
|
|
10577
|
+
function indexEntryModels(entry) {
|
|
10578
|
+
if (entry.models === void 0 || typeof entry.models !== "object") return;
|
|
10579
|
+
for (const [modelId, raw] of Object.entries(entry.models)) {
|
|
10580
|
+
const parsed = catalogModelSchema.safeParse(raw);
|
|
10581
|
+
if (!parsed.success) {
|
|
10582
|
+
process.stderr.write(
|
|
10583
|
+
`[theokit-sdk] WARN: Skipping malformed catalog model "${entry.id}/${modelId}": ${parsed.error.issues[0]?.message ?? "invalid"}
|
|
10584
|
+
`
|
|
10585
|
+
);
|
|
10586
|
+
continue;
|
|
10587
|
+
}
|
|
10588
|
+
modelInfoIndex.set(`${entry.id}/${modelId}`, parsed.data);
|
|
10589
|
+
for (const alias of entry.aliases ?? []) {
|
|
10590
|
+
const key = `${alias}/${modelId}`;
|
|
10591
|
+
if (!modelInfoIndex.has(key)) modelInfoIndex.set(key, parsed.data);
|
|
10592
|
+
}
|
|
10593
|
+
}
|
|
10594
|
+
}
|
|
10595
|
+
function validateEntry(raw) {
|
|
10596
|
+
if (typeof raw.id !== "string" || typeof raw.displayName !== "string" || typeof raw.apiMode !== "string" || typeof raw.authType !== "string" || typeof raw.baseUrl !== "string" || !Array.isArray(raw.envVars) || !Array.isArray(raw.fallbackModels) || raw.capabilities == null || typeof raw.capabilities !== "object") {
|
|
10597
|
+
return null;
|
|
10598
|
+
}
|
|
10599
|
+
return raw;
|
|
10600
|
+
}
|
|
10601
|
+
function loadProviderCatalog(opts) {
|
|
10602
|
+
const catalogPath = path.join(__dirname_resolved, "provider-catalog.json");
|
|
10603
|
+
const rawText = fs.readFileSync(catalogPath, "utf-8");
|
|
10604
|
+
let entries = JSON.parse(rawText);
|
|
10605
|
+
const result = {};
|
|
10606
|
+
for (const raw of entries) {
|
|
10607
|
+
const validated = validateEntry(raw);
|
|
10608
|
+
if (validated === null) {
|
|
10609
|
+
process.stderr.write(
|
|
10610
|
+
`[theokit-sdk] WARN: Skipping malformed catalog entry: ${JSON.stringify(raw).slice(0, 100)}
|
|
10611
|
+
`
|
|
10612
|
+
);
|
|
10613
|
+
continue;
|
|
10614
|
+
}
|
|
10615
|
+
result[validated.id] = validated;
|
|
10616
|
+
}
|
|
10617
|
+
return result;
|
|
10618
|
+
}
|
|
10619
|
+
function registerCatalogProviders(opts) {
|
|
10620
|
+
const catalog = loadProviderCatalog();
|
|
10621
|
+
for (const entry of Object.values(catalog)) {
|
|
10622
|
+
if (getProviderProfile(entry.id) !== void 0) continue;
|
|
10623
|
+
if (entry.aliases?.some((a) => getProviderProfile(a) !== void 0)) continue;
|
|
10624
|
+
const profile = {
|
|
10625
|
+
name: entry.id,
|
|
10626
|
+
apiMode: entry.apiMode,
|
|
10627
|
+
authType: entry.authType,
|
|
10628
|
+
baseUrl: entry.baseUrl,
|
|
10629
|
+
envVars: entry.envVars,
|
|
10630
|
+
fallbackModels: entry.fallbackModels,
|
|
10631
|
+
displayName: entry.displayName,
|
|
10632
|
+
aliases: entry.aliases,
|
|
10633
|
+
modelsUrl: entry.modelsUrl,
|
|
10634
|
+
hostname: entry.hostname,
|
|
10635
|
+
extraHeaders: entry.extraHeaders
|
|
10636
|
+
};
|
|
10637
|
+
registerProvider(profile);
|
|
10638
|
+
}
|
|
10639
|
+
}
|
|
10502
10640
|
|
|
10503
10641
|
// src/internal/budget/pricing-data.json
|
|
10504
10642
|
var pricing_data_default = {
|
|
@@ -10591,9 +10729,9 @@ var pricing_data_default = {
|
|
|
10591
10729
|
cacheRead: 0.025
|
|
10592
10730
|
},
|
|
10593
10731
|
"openai/o3": {
|
|
10594
|
-
input:
|
|
10595
|
-
output:
|
|
10596
|
-
cacheRead:
|
|
10732
|
+
input: 2,
|
|
10733
|
+
output: 8,
|
|
10734
|
+
cacheRead: 0.5
|
|
10597
10735
|
},
|
|
10598
10736
|
"openai/o3-mini": {
|
|
10599
10737
|
input: 1.1,
|
|
@@ -10681,6 +10819,27 @@ function getPricingEntry(opts) {
|
|
|
10681
10819
|
if (found2 !== void 0) return buildEntry(stripped, found2);
|
|
10682
10820
|
}
|
|
10683
10821
|
}
|
|
10822
|
+
const catalogEntry = catalogCostFallback(opts.provider, cleaned);
|
|
10823
|
+
if (catalogEntry !== void 0) return catalogEntry;
|
|
10824
|
+
return void 0;
|
|
10825
|
+
}
|
|
10826
|
+
function catalogCostFallback(provider, cleanedModel) {
|
|
10827
|
+
const keys = [`${provider}/${cleanedModel}`, cleanedModel];
|
|
10828
|
+
for (const key of keys) {
|
|
10829
|
+
const info = getCatalogModelInfo(key);
|
|
10830
|
+
const cost = info?.cost;
|
|
10831
|
+
if (cost === void 0) continue;
|
|
10832
|
+
const [prov, ...modelParts] = key.split("/");
|
|
10833
|
+
return {
|
|
10834
|
+
provider: prov ?? provider,
|
|
10835
|
+
model: modelParts.join("/") || cleanedModel,
|
|
10836
|
+
inputCostPerMillion: cost.input,
|
|
10837
|
+
outputCostPerMillion: cost.output,
|
|
10838
|
+
...cost.cache_read !== void 0 ? { cacheReadCostPerMillion: cost.cache_read } : {},
|
|
10839
|
+
...cost.cache_write !== void 0 ? { cacheWriteCostPerMillion: cost.cache_write } : {},
|
|
10840
|
+
pricingVersion: "catalog-vendored"
|
|
10841
|
+
};
|
|
10842
|
+
}
|
|
10684
10843
|
return void 0;
|
|
10685
10844
|
}
|
|
10686
10845
|
|
|
@@ -11197,79 +11356,6 @@ function abortError(signal) {
|
|
|
11197
11356
|
// src/internal/llm/router.ts
|
|
11198
11357
|
init_errors();
|
|
11199
11358
|
|
|
11200
|
-
// src/internal/providers/registry.ts
|
|
11201
|
-
var REGISTRY = /* @__PURE__ */ new Map();
|
|
11202
|
-
var ALIASES = /* @__PURE__ */ new Map();
|
|
11203
|
-
function registerProvider(profile) {
|
|
11204
|
-
if (REGISTRY.has(profile.name)) {
|
|
11205
|
-
process.stderr.write(`[theokit-sdk] Provider "${profile.name}" overridden by user plugin.
|
|
11206
|
-
`);
|
|
11207
|
-
}
|
|
11208
|
-
REGISTRY.set(profile.name, profile);
|
|
11209
|
-
for (const alias of profile.aliases ?? []) {
|
|
11210
|
-
const previous = ALIASES.get(alias);
|
|
11211
|
-
if (previous !== void 0 && previous !== profile.name) {
|
|
11212
|
-
process.stderr.write(
|
|
11213
|
-
`[theokit-sdk] Alias "${alias}" collision: was "${previous}", now "${profile.name}".
|
|
11214
|
-
`
|
|
11215
|
-
);
|
|
11216
|
-
}
|
|
11217
|
-
ALIASES.set(alias, profile.name);
|
|
11218
|
-
}
|
|
11219
|
-
}
|
|
11220
|
-
function getProviderProfile(name) {
|
|
11221
|
-
const canonical = ALIASES.get(name) ?? name;
|
|
11222
|
-
return REGISTRY.get(canonical);
|
|
11223
|
-
}
|
|
11224
|
-
|
|
11225
|
-
// src/internal/providers/catalog-loader.ts
|
|
11226
|
-
var __dirname_resolved = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('eval.cjs', document.baseURI).href))));
|
|
11227
|
-
function validateEntry(raw) {
|
|
11228
|
-
if (typeof raw.id !== "string" || typeof raw.displayName !== "string" || typeof raw.apiMode !== "string" || typeof raw.authType !== "string" || typeof raw.baseUrl !== "string" || !Array.isArray(raw.envVars) || !Array.isArray(raw.fallbackModels) || raw.capabilities == null || typeof raw.capabilities !== "object") {
|
|
11229
|
-
return null;
|
|
11230
|
-
}
|
|
11231
|
-
return raw;
|
|
11232
|
-
}
|
|
11233
|
-
function loadProviderCatalog(opts) {
|
|
11234
|
-
const catalogPath = path.join(__dirname_resolved, "provider-catalog.json");
|
|
11235
|
-
const rawText = fs.readFileSync(catalogPath, "utf-8");
|
|
11236
|
-
let entries = JSON.parse(rawText);
|
|
11237
|
-
const result = {};
|
|
11238
|
-
for (const raw of entries) {
|
|
11239
|
-
const validated = validateEntry(raw);
|
|
11240
|
-
if (validated === null) {
|
|
11241
|
-
process.stderr.write(
|
|
11242
|
-
`[theokit-sdk] WARN: Skipping malformed catalog entry: ${JSON.stringify(raw).slice(0, 100)}
|
|
11243
|
-
`
|
|
11244
|
-
);
|
|
11245
|
-
continue;
|
|
11246
|
-
}
|
|
11247
|
-
result[validated.id] = validated;
|
|
11248
|
-
}
|
|
11249
|
-
return result;
|
|
11250
|
-
}
|
|
11251
|
-
function registerCatalogProviders(opts) {
|
|
11252
|
-
const catalog = loadProviderCatalog();
|
|
11253
|
-
for (const entry of Object.values(catalog)) {
|
|
11254
|
-
if (getProviderProfile(entry.id) !== void 0) continue;
|
|
11255
|
-
if (entry.aliases?.some((a) => getProviderProfile(a) !== void 0)) continue;
|
|
11256
|
-
const profile = {
|
|
11257
|
-
name: entry.id,
|
|
11258
|
-
apiMode: entry.apiMode,
|
|
11259
|
-
authType: entry.authType,
|
|
11260
|
-
baseUrl: entry.baseUrl,
|
|
11261
|
-
envVars: entry.envVars,
|
|
11262
|
-
fallbackModels: entry.fallbackModels,
|
|
11263
|
-
displayName: entry.displayName,
|
|
11264
|
-
aliases: entry.aliases,
|
|
11265
|
-
modelsUrl: entry.modelsUrl,
|
|
11266
|
-
hostname: entry.hostname,
|
|
11267
|
-
extraHeaders: entry.extraHeaders
|
|
11268
|
-
};
|
|
11269
|
-
registerProvider(profile);
|
|
11270
|
-
}
|
|
11271
|
-
}
|
|
11272
|
-
|
|
11273
11359
|
// src/internal/providers/builtin/anthropic.ts
|
|
11274
11360
|
var ANTHROPIC = {
|
|
11275
11361
|
name: "anthropic",
|
|
@@ -11678,7 +11764,7 @@ var DEFAULT_STORE = {
|
|
|
11678
11764
|
home: os.homedir(),
|
|
11679
11765
|
dirName: ".theokit",
|
|
11680
11766
|
fileName: "auth.json",
|
|
11681
|
-
homeEnvVar: "
|
|
11767
|
+
homeEnvVar: "THEOKIT_AUTH_HOME"
|
|
11682
11768
|
};
|
|
11683
11769
|
var OPENAI_OAUTH_CONFIG = {
|
|
11684
11770
|
provider: "openai",
|