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