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