@theokit/sdk 4.12.2 → 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 +6 -0
- package/dist/cron.cjs +164 -78
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.js +164 -78
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +164 -78
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +164 -78
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +178 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +178 -92
- 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/index.cjs
CHANGED
|
@@ -576,10 +576,10 @@ function buildToolPrompt(prompt) {
|
|
|
576
576
|
Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
|
|
577
577
|
}
|
|
578
578
|
function setupStructuredOutput(schema, maxRetries) {
|
|
579
|
-
const
|
|
579
|
+
const z13 = requireZod();
|
|
580
580
|
const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
|
|
581
581
|
return {
|
|
582
|
-
z:
|
|
582
|
+
z: z13,
|
|
583
583
|
jsonSchema,
|
|
584
584
|
maxRetries: maxRetries ?? 1,
|
|
585
585
|
initialUsage: { inputTokens: 0, outputTokens: 0 }
|
|
@@ -13086,6 +13086,158 @@ function applyToolResultGuard(parts, opts) {
|
|
|
13086
13086
|
)
|
|
13087
13087
|
);
|
|
13088
13088
|
}
|
|
13089
|
+
var MODALITIES = ["text", "audio", "image", "video", "pdf"];
|
|
13090
|
+
var costSchema = zod.z.object({
|
|
13091
|
+
/** USD per 1M tokens (models.dev convention). */
|
|
13092
|
+
input: zod.z.number().nonnegative(),
|
|
13093
|
+
output: zod.z.number().nonnegative(),
|
|
13094
|
+
cache_read: zod.z.number().nonnegative().optional(),
|
|
13095
|
+
cache_write: zod.z.number().nonnegative().optional()
|
|
13096
|
+
}).loose();
|
|
13097
|
+
var limitSchema = zod.z.object({
|
|
13098
|
+
context: zod.z.number().positive(),
|
|
13099
|
+
input: zod.z.number().positive().optional(),
|
|
13100
|
+
output: zod.z.number().positive().optional()
|
|
13101
|
+
}).loose();
|
|
13102
|
+
var modalitiesSchema = zod.z.object({
|
|
13103
|
+
input: zod.z.array(zod.z.enum(MODALITIES)).optional(),
|
|
13104
|
+
output: zod.z.array(zod.z.enum(MODALITIES)).optional()
|
|
13105
|
+
}).loose();
|
|
13106
|
+
var catalogModelSchema = zod.z.object({
|
|
13107
|
+
name: zod.z.string().optional(),
|
|
13108
|
+
release_date: zod.z.string().optional(),
|
|
13109
|
+
attachment: zod.z.boolean().optional(),
|
|
13110
|
+
reasoning: zod.z.boolean().optional(),
|
|
13111
|
+
temperature: zod.z.boolean().optional(),
|
|
13112
|
+
tool_call: zod.z.boolean().optional(),
|
|
13113
|
+
/** theokit extension — maps to ModelCapabilities.supportsStructuredOutput. */
|
|
13114
|
+
structured_output: zod.z.boolean().optional(),
|
|
13115
|
+
/** theokit extension — maps to ModelCapabilities.supportsCacheControl. */
|
|
13116
|
+
cache_control: zod.z.boolean().optional(),
|
|
13117
|
+
cost: costSchema.optional(),
|
|
13118
|
+
limit: limitSchema.optional(),
|
|
13119
|
+
modalities: modalitiesSchema.optional(),
|
|
13120
|
+
status: zod.z.enum(["alpha", "beta", "deprecated"]).optional()
|
|
13121
|
+
}).loose();
|
|
13122
|
+
|
|
13123
|
+
// src/internal/providers/registry.ts
|
|
13124
|
+
var REGISTRY = /* @__PURE__ */ new Map();
|
|
13125
|
+
var ALIASES = /* @__PURE__ */ new Map();
|
|
13126
|
+
function registerProvider(profile) {
|
|
13127
|
+
if (REGISTRY.has(profile.name)) {
|
|
13128
|
+
process.stderr.write(`[theokit-sdk] Provider "${profile.name}" overridden by user plugin.
|
|
13129
|
+
`);
|
|
13130
|
+
}
|
|
13131
|
+
REGISTRY.set(profile.name, profile);
|
|
13132
|
+
for (const alias of profile.aliases ?? []) {
|
|
13133
|
+
const previous = ALIASES.get(alias);
|
|
13134
|
+
if (previous !== void 0 && previous !== profile.name) {
|
|
13135
|
+
process.stderr.write(
|
|
13136
|
+
`[theokit-sdk] Alias "${alias}" collision: was "${previous}", now "${profile.name}".
|
|
13137
|
+
`
|
|
13138
|
+
);
|
|
13139
|
+
}
|
|
13140
|
+
ALIASES.set(alias, profile.name);
|
|
13141
|
+
}
|
|
13142
|
+
}
|
|
13143
|
+
function getProviderProfile(name) {
|
|
13144
|
+
const canonical = ALIASES.get(name) ?? name;
|
|
13145
|
+
return REGISTRY.get(canonical);
|
|
13146
|
+
}
|
|
13147
|
+
function listProviders() {
|
|
13148
|
+
return Array.from(REGISTRY.values());
|
|
13149
|
+
}
|
|
13150
|
+
|
|
13151
|
+
// src/internal/providers/catalog-loader.ts
|
|
13152
|
+
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('index.cjs', document.baseURI).href))));
|
|
13153
|
+
var modelInfoIndex = /* @__PURE__ */ new Map();
|
|
13154
|
+
function getCatalogModelInfo(key2) {
|
|
13155
|
+
ensureModelIndexLoaded();
|
|
13156
|
+
return modelInfoIndex.get(key2);
|
|
13157
|
+
}
|
|
13158
|
+
var _modelIndexLoaded = false;
|
|
13159
|
+
function ensureModelIndexLoaded() {
|
|
13160
|
+
if (_modelIndexLoaded) return;
|
|
13161
|
+
_modelIndexLoaded = true;
|
|
13162
|
+
const catalog = loadProviderCatalog();
|
|
13163
|
+
for (const entry of Object.values(catalog)) {
|
|
13164
|
+
indexEntryModels(entry);
|
|
13165
|
+
}
|
|
13166
|
+
}
|
|
13167
|
+
function indexEntryModels(entry) {
|
|
13168
|
+
if (entry.models === void 0 || typeof entry.models !== "object") return;
|
|
13169
|
+
for (const [modelId, raw] of Object.entries(entry.models)) {
|
|
13170
|
+
const parsed = catalogModelSchema.safeParse(raw);
|
|
13171
|
+
if (!parsed.success) {
|
|
13172
|
+
process.stderr.write(
|
|
13173
|
+
`[theokit-sdk] WARN: Skipping malformed catalog model "${entry.id}/${modelId}": ${parsed.error.issues[0]?.message ?? "invalid"}
|
|
13174
|
+
`
|
|
13175
|
+
);
|
|
13176
|
+
continue;
|
|
13177
|
+
}
|
|
13178
|
+
modelInfoIndex.set(`${entry.id}/${modelId}`, parsed.data);
|
|
13179
|
+
for (const alias of entry.aliases ?? []) {
|
|
13180
|
+
const key2 = `${alias}/${modelId}`;
|
|
13181
|
+
if (!modelInfoIndex.has(key2)) modelInfoIndex.set(key2, parsed.data);
|
|
13182
|
+
}
|
|
13183
|
+
}
|
|
13184
|
+
}
|
|
13185
|
+
function validateEntry(raw) {
|
|
13186
|
+
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") {
|
|
13187
|
+
return null;
|
|
13188
|
+
}
|
|
13189
|
+
return raw;
|
|
13190
|
+
}
|
|
13191
|
+
function loadProviderCatalog(opts) {
|
|
13192
|
+
const catalogPath = path.join(__dirname_resolved, "provider-catalog.json");
|
|
13193
|
+
const rawText = fs.readFileSync(catalogPath, "utf-8");
|
|
13194
|
+
let entries = JSON.parse(rawText);
|
|
13195
|
+
const result = {};
|
|
13196
|
+
for (const raw of entries) {
|
|
13197
|
+
const validated = validateEntry(raw);
|
|
13198
|
+
if (validated === null) {
|
|
13199
|
+
process.stderr.write(
|
|
13200
|
+
`[theokit-sdk] WARN: Skipping malformed catalog entry: ${JSON.stringify(raw).slice(0, 100)}
|
|
13201
|
+
`
|
|
13202
|
+
);
|
|
13203
|
+
continue;
|
|
13204
|
+
}
|
|
13205
|
+
result[validated.id] = validated;
|
|
13206
|
+
}
|
|
13207
|
+
return result;
|
|
13208
|
+
}
|
|
13209
|
+
var _capabilitiesCache = null;
|
|
13210
|
+
function getCatalogCapabilities(providerId) {
|
|
13211
|
+
if (_capabilitiesCache === null) {
|
|
13212
|
+
const catalog = loadProviderCatalog();
|
|
13213
|
+
_capabilitiesCache = {};
|
|
13214
|
+
for (const entry of Object.values(catalog)) {
|
|
13215
|
+
_capabilitiesCache[entry.id] = entry.capabilities;
|
|
13216
|
+
}
|
|
13217
|
+
}
|
|
13218
|
+
return _capabilitiesCache[providerId];
|
|
13219
|
+
}
|
|
13220
|
+
function registerCatalogProviders(opts) {
|
|
13221
|
+
const catalog = loadProviderCatalog();
|
|
13222
|
+
for (const entry of Object.values(catalog)) {
|
|
13223
|
+
if (getProviderProfile(entry.id) !== void 0) continue;
|
|
13224
|
+
if (entry.aliases?.some((a) => getProviderProfile(a) !== void 0)) continue;
|
|
13225
|
+
const profile = {
|
|
13226
|
+
name: entry.id,
|
|
13227
|
+
apiMode: entry.apiMode,
|
|
13228
|
+
authType: entry.authType,
|
|
13229
|
+
baseUrl: entry.baseUrl,
|
|
13230
|
+
envVars: entry.envVars,
|
|
13231
|
+
fallbackModels: entry.fallbackModels,
|
|
13232
|
+
displayName: entry.displayName,
|
|
13233
|
+
aliases: entry.aliases,
|
|
13234
|
+
modelsUrl: entry.modelsUrl,
|
|
13235
|
+
hostname: entry.hostname,
|
|
13236
|
+
extraHeaders: entry.extraHeaders
|
|
13237
|
+
};
|
|
13238
|
+
registerProvider(profile);
|
|
13239
|
+
}
|
|
13240
|
+
}
|
|
13089
13241
|
|
|
13090
13242
|
// src/internal/budget/pricing-data.json
|
|
13091
13243
|
var pricing_data_default = {
|
|
@@ -13178,9 +13330,9 @@ var pricing_data_default = {
|
|
|
13178
13330
|
cacheRead: 0.025
|
|
13179
13331
|
},
|
|
13180
13332
|
"openai/o3": {
|
|
13181
|
-
input:
|
|
13182
|
-
output:
|
|
13183
|
-
cacheRead:
|
|
13333
|
+
input: 2,
|
|
13334
|
+
output: 8,
|
|
13335
|
+
cacheRead: 0.5
|
|
13184
13336
|
},
|
|
13185
13337
|
"openai/o3-mini": {
|
|
13186
13338
|
input: 1.1,
|
|
@@ -13268,6 +13420,27 @@ function getPricingEntry(opts) {
|
|
|
13268
13420
|
if (found2 !== void 0) return buildEntry(stripped, found2);
|
|
13269
13421
|
}
|
|
13270
13422
|
}
|
|
13423
|
+
const catalogEntry = catalogCostFallback(opts.provider, cleaned);
|
|
13424
|
+
if (catalogEntry !== void 0) return catalogEntry;
|
|
13425
|
+
return void 0;
|
|
13426
|
+
}
|
|
13427
|
+
function catalogCostFallback(provider, cleanedModel) {
|
|
13428
|
+
const keys = [`${provider}/${cleanedModel}`, cleanedModel];
|
|
13429
|
+
for (const key2 of keys) {
|
|
13430
|
+
const info = getCatalogModelInfo(key2);
|
|
13431
|
+
const cost = info?.cost;
|
|
13432
|
+
if (cost === void 0) continue;
|
|
13433
|
+
const [prov, ...modelParts] = key2.split("/");
|
|
13434
|
+
return {
|
|
13435
|
+
provider: prov ?? provider,
|
|
13436
|
+
model: modelParts.join("/") || cleanedModel,
|
|
13437
|
+
inputCostPerMillion: cost.input,
|
|
13438
|
+
outputCostPerMillion: cost.output,
|
|
13439
|
+
...cost.cache_read !== void 0 ? { cacheReadCostPerMillion: cost.cache_read } : {},
|
|
13440
|
+
...cost.cache_write !== void 0 ? { cacheWriteCostPerMillion: cost.cache_write } : {},
|
|
13441
|
+
pricingVersion: "catalog-vendored"
|
|
13442
|
+
};
|
|
13443
|
+
}
|
|
13271
13444
|
return void 0;
|
|
13272
13445
|
}
|
|
13273
13446
|
|
|
@@ -13784,93 +13957,6 @@ function abortError(signal) {
|
|
|
13784
13957
|
// src/internal/llm/router.ts
|
|
13785
13958
|
init_errors();
|
|
13786
13959
|
|
|
13787
|
-
// src/internal/providers/registry.ts
|
|
13788
|
-
var REGISTRY = /* @__PURE__ */ new Map();
|
|
13789
|
-
var ALIASES = /* @__PURE__ */ new Map();
|
|
13790
|
-
function registerProvider(profile) {
|
|
13791
|
-
if (REGISTRY.has(profile.name)) {
|
|
13792
|
-
process.stderr.write(`[theokit-sdk] Provider "${profile.name}" overridden by user plugin.
|
|
13793
|
-
`);
|
|
13794
|
-
}
|
|
13795
|
-
REGISTRY.set(profile.name, profile);
|
|
13796
|
-
for (const alias of profile.aliases ?? []) {
|
|
13797
|
-
const previous = ALIASES.get(alias);
|
|
13798
|
-
if (previous !== void 0 && previous !== profile.name) {
|
|
13799
|
-
process.stderr.write(
|
|
13800
|
-
`[theokit-sdk] Alias "${alias}" collision: was "${previous}", now "${profile.name}".
|
|
13801
|
-
`
|
|
13802
|
-
);
|
|
13803
|
-
}
|
|
13804
|
-
ALIASES.set(alias, profile.name);
|
|
13805
|
-
}
|
|
13806
|
-
}
|
|
13807
|
-
function getProviderProfile(name) {
|
|
13808
|
-
const canonical = ALIASES.get(name) ?? name;
|
|
13809
|
-
return REGISTRY.get(canonical);
|
|
13810
|
-
}
|
|
13811
|
-
function listProviders() {
|
|
13812
|
-
return Array.from(REGISTRY.values());
|
|
13813
|
-
}
|
|
13814
|
-
|
|
13815
|
-
// src/internal/providers/catalog-loader.ts
|
|
13816
|
-
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('index.cjs', document.baseURI).href))));
|
|
13817
|
-
function validateEntry(raw) {
|
|
13818
|
-
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") {
|
|
13819
|
-
return null;
|
|
13820
|
-
}
|
|
13821
|
-
return raw;
|
|
13822
|
-
}
|
|
13823
|
-
function loadProviderCatalog(opts) {
|
|
13824
|
-
const catalogPath = path.join(__dirname_resolved, "provider-catalog.json");
|
|
13825
|
-
const rawText = fs.readFileSync(catalogPath, "utf-8");
|
|
13826
|
-
let entries = JSON.parse(rawText);
|
|
13827
|
-
const result = {};
|
|
13828
|
-
for (const raw of entries) {
|
|
13829
|
-
const validated = validateEntry(raw);
|
|
13830
|
-
if (validated === null) {
|
|
13831
|
-
process.stderr.write(
|
|
13832
|
-
`[theokit-sdk] WARN: Skipping malformed catalog entry: ${JSON.stringify(raw).slice(0, 100)}
|
|
13833
|
-
`
|
|
13834
|
-
);
|
|
13835
|
-
continue;
|
|
13836
|
-
}
|
|
13837
|
-
result[validated.id] = validated;
|
|
13838
|
-
}
|
|
13839
|
-
return result;
|
|
13840
|
-
}
|
|
13841
|
-
var _capabilitiesCache = null;
|
|
13842
|
-
function getCatalogCapabilities(providerId) {
|
|
13843
|
-
if (_capabilitiesCache === null) {
|
|
13844
|
-
const catalog = loadProviderCatalog();
|
|
13845
|
-
_capabilitiesCache = {};
|
|
13846
|
-
for (const entry of Object.values(catalog)) {
|
|
13847
|
-
_capabilitiesCache[entry.id] = entry.capabilities;
|
|
13848
|
-
}
|
|
13849
|
-
}
|
|
13850
|
-
return _capabilitiesCache[providerId];
|
|
13851
|
-
}
|
|
13852
|
-
function registerCatalogProviders(opts) {
|
|
13853
|
-
const catalog = loadProviderCatalog();
|
|
13854
|
-
for (const entry of Object.values(catalog)) {
|
|
13855
|
-
if (getProviderProfile(entry.id) !== void 0) continue;
|
|
13856
|
-
if (entry.aliases?.some((a) => getProviderProfile(a) !== void 0)) continue;
|
|
13857
|
-
const profile = {
|
|
13858
|
-
name: entry.id,
|
|
13859
|
-
apiMode: entry.apiMode,
|
|
13860
|
-
authType: entry.authType,
|
|
13861
|
-
baseUrl: entry.baseUrl,
|
|
13862
|
-
envVars: entry.envVars,
|
|
13863
|
-
fallbackModels: entry.fallbackModels,
|
|
13864
|
-
displayName: entry.displayName,
|
|
13865
|
-
aliases: entry.aliases,
|
|
13866
|
-
modelsUrl: entry.modelsUrl,
|
|
13867
|
-
hostname: entry.hostname,
|
|
13868
|
-
extraHeaders: entry.extraHeaders
|
|
13869
|
-
};
|
|
13870
|
-
registerProvider(profile);
|
|
13871
|
-
}
|
|
13872
|
-
}
|
|
13873
|
-
|
|
13874
13960
|
// src/internal/providers/builtin/anthropic.ts
|
|
13875
13961
|
var ANTHROPIC = {
|
|
13876
13962
|
name: "anthropic",
|