@theokit/sdk 4.12.2 → 4.13.1

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/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 z12 = requireZod();
579
+ const z13 = requireZod();
580
580
  const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
581
581
  return {
582
- z: z12,
582
+ z: z13,
583
583
  jsonSchema,
584
584
  maxRetries: maxRetries ?? 1,
585
585
  initialUsage: { inputTokens: 0, outputTokens: 0 }
@@ -13086,6 +13086,192 @@ 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
+ function globalSingleton(key2, create) {
13125
+ const g = globalThis;
13126
+ const sym = Symbol.for(key2);
13127
+ if (g[sym] === void 0) g[sym] = create();
13128
+ return g[sym];
13129
+ }
13130
+ var REGISTRY = globalSingleton(
13131
+ "theokit-sdk.providers.registry",
13132
+ () => /* @__PURE__ */ new Map()
13133
+ );
13134
+ var ALIASES = globalSingleton("theokit-sdk.providers.aliases", () => /* @__PURE__ */ new Map());
13135
+ function registerProvider(profile) {
13136
+ if (REGISTRY.has(profile.name)) {
13137
+ process.stderr.write(`[theokit-sdk] Provider "${profile.name}" overridden by user plugin.
13138
+ `);
13139
+ }
13140
+ REGISTRY.set(profile.name, profile);
13141
+ for (const alias of profile.aliases ?? []) {
13142
+ const previous = ALIASES.get(alias);
13143
+ if (previous !== void 0 && previous !== profile.name) {
13144
+ process.stderr.write(
13145
+ `[theokit-sdk] Alias "${alias}" collision: was "${previous}", now "${profile.name}".
13146
+ `
13147
+ );
13148
+ }
13149
+ ALIASES.set(alias, profile.name);
13150
+ }
13151
+ }
13152
+ function getProviderProfile(name) {
13153
+ const canonical = ALIASES.get(name) ?? name;
13154
+ return REGISTRY.get(canonical);
13155
+ }
13156
+ function listProviders() {
13157
+ return Array.from(REGISTRY.values());
13158
+ }
13159
+
13160
+ // src/internal/providers/catalog-loader.ts
13161
+ 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))));
13162
+ function globalSingleton2(key2, create) {
13163
+ const g = globalThis;
13164
+ const sym = Symbol.for(key2);
13165
+ if (g[sym] === void 0) g[sym] = create();
13166
+ return g[sym];
13167
+ }
13168
+ var modelInfoIndex = globalSingleton2(
13169
+ "theokit-sdk.providers.model-info-index",
13170
+ () => /* @__PURE__ */ new Map()
13171
+ );
13172
+ var patchedModelKeys = globalSingleton2(
13173
+ "theokit-sdk.providers.model-info-patched",
13174
+ () => /* @__PURE__ */ new Set()
13175
+ );
13176
+ var indexState = globalSingleton2("theokit-sdk.providers.model-info-loaded", () => ({
13177
+ loaded: false
13178
+ }));
13179
+ function getCatalogModelInfo(key2) {
13180
+ ensureModelIndexLoaded();
13181
+ return modelInfoIndex.get(key2);
13182
+ }
13183
+ function isPatchedModelKey(key2) {
13184
+ return patchedModelKeys.has(key2);
13185
+ }
13186
+ function ensureModelIndexLoaded() {
13187
+ if (indexState.loaded) return;
13188
+ indexState.loaded = true;
13189
+ try {
13190
+ const catalog = loadProviderCatalog();
13191
+ for (const entry of Object.values(catalog)) {
13192
+ indexEntryModels(entry);
13193
+ }
13194
+ } catch (err) {
13195
+ process.stderr.write(
13196
+ `[theokit-sdk] WARN: provider catalog unavailable (${err.message}) \u2014 per-model data disabled
13197
+ `
13198
+ );
13199
+ }
13200
+ }
13201
+ function indexEntryModels(entry) {
13202
+ if (entry.models === void 0 || typeof entry.models !== "object") return;
13203
+ for (const [modelId, raw] of Object.entries(entry.models)) {
13204
+ const parsed = catalogModelSchema.safeParse(raw);
13205
+ if (!parsed.success) {
13206
+ process.stderr.write(
13207
+ `[theokit-sdk] WARN: Skipping malformed catalog model "${entry.id}/${modelId}": ${parsed.error.issues[0]?.message ?? "invalid"}
13208
+ `
13209
+ );
13210
+ continue;
13211
+ }
13212
+ modelInfoIndex.set(`${entry.id}/${modelId}`, parsed.data);
13213
+ for (const alias of entry.aliases ?? []) {
13214
+ const key2 = `${alias}/${modelId}`;
13215
+ if (!modelInfoIndex.has(key2)) modelInfoIndex.set(key2, parsed.data);
13216
+ }
13217
+ }
13218
+ }
13219
+ function validateEntry(raw) {
13220
+ 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") {
13221
+ return null;
13222
+ }
13223
+ return raw;
13224
+ }
13225
+ function loadProviderCatalog(opts) {
13226
+ const catalogPath = path.join(__dirname_resolved, "provider-catalog.json");
13227
+ const rawText = fs.readFileSync(catalogPath, "utf-8");
13228
+ let entries = JSON.parse(rawText);
13229
+ const result = {};
13230
+ for (const raw of entries) {
13231
+ const validated = validateEntry(raw);
13232
+ if (validated === null) {
13233
+ process.stderr.write(
13234
+ `[theokit-sdk] WARN: Skipping malformed catalog entry: ${JSON.stringify(raw).slice(0, 100)}
13235
+ `
13236
+ );
13237
+ continue;
13238
+ }
13239
+ result[validated.id] = validated;
13240
+ }
13241
+ return result;
13242
+ }
13243
+ var _capabilitiesCache = null;
13244
+ function getCatalogCapabilities(providerId) {
13245
+ if (_capabilitiesCache === null) {
13246
+ const catalog = loadProviderCatalog();
13247
+ _capabilitiesCache = {};
13248
+ for (const entry of Object.values(catalog)) {
13249
+ _capabilitiesCache[entry.id] = entry.capabilities;
13250
+ }
13251
+ }
13252
+ return _capabilitiesCache[providerId];
13253
+ }
13254
+ function registerCatalogProviders(opts) {
13255
+ const catalog = loadProviderCatalog();
13256
+ for (const entry of Object.values(catalog)) {
13257
+ if (getProviderProfile(entry.id) !== void 0) continue;
13258
+ if (entry.aliases?.some((a) => getProviderProfile(a) !== void 0)) continue;
13259
+ const profile = {
13260
+ name: entry.id,
13261
+ apiMode: entry.apiMode,
13262
+ authType: entry.authType,
13263
+ baseUrl: entry.baseUrl,
13264
+ envVars: entry.envVars,
13265
+ fallbackModels: entry.fallbackModels,
13266
+ displayName: entry.displayName,
13267
+ aliases: entry.aliases,
13268
+ modelsUrl: entry.modelsUrl,
13269
+ hostname: entry.hostname,
13270
+ extraHeaders: entry.extraHeaders
13271
+ };
13272
+ registerProvider(profile);
13273
+ }
13274
+ }
13089
13275
 
13090
13276
  // src/internal/budget/pricing-data.json
13091
13277
  var pricing_data_default = {
@@ -13178,9 +13364,9 @@ var pricing_data_default = {
13178
13364
  cacheRead: 0.025
13179
13365
  },
13180
13366
  "openai/o3": {
13181
- input: 10,
13182
- output: 40,
13183
- cacheRead: 2.5
13367
+ input: 2,
13368
+ output: 8,
13369
+ cacheRead: 0.5
13184
13370
  },
13185
13371
  "openai/o3-mini": {
13186
13372
  input: 1.1,
@@ -13268,6 +13454,30 @@ function getPricingEntry(opts) {
13268
13454
  if (found2 !== void 0) return buildEntry(stripped, found2);
13269
13455
  }
13270
13456
  }
13457
+ const catalogEntry = catalogCostFallback(opts.provider, cleaned);
13458
+ if (catalogEntry !== void 0) return catalogEntry;
13459
+ return void 0;
13460
+ }
13461
+ function catalogCostFallback(provider, cleanedModel) {
13462
+ const stripped = stripDateSuffix(cleanedModel);
13463
+ const candidates = [`${provider}/${cleanedModel}`, cleanedModel];
13464
+ if (stripped !== cleanedModel) candidates.push(`${provider}/${stripped}`, stripped);
13465
+ for (const key2 of candidates) {
13466
+ const info = getCatalogModelInfo(key2);
13467
+ const cost = info?.cost;
13468
+ if (cost === void 0) continue;
13469
+ const [prov, ...modelParts] = key2.split("/");
13470
+ return {
13471
+ provider: prov ?? provider,
13472
+ model: modelParts.join("/") || cleanedModel,
13473
+ inputCostPerMillion: cost.input,
13474
+ outputCostPerMillion: cost.output,
13475
+ ...cost.cache_read !== void 0 ? { cacheReadCostPerMillion: cost.cache_read } : {},
13476
+ ...cost.cache_write !== void 0 ? { cacheWriteCostPerMillion: cost.cache_write } : {},
13477
+ // M44 M5 fix — honest provenance: a key patched by the LIVE models-dev source is not "vendored".
13478
+ pricingVersion: isPatchedModelKey(key2) ? "catalog-models-dev" : "catalog-vendored"
13479
+ };
13480
+ }
13271
13481
  return void 0;
13272
13482
  }
13273
13483
 
@@ -13784,93 +13994,6 @@ function abortError(signal) {
13784
13994
  // src/internal/llm/router.ts
13785
13995
  init_errors();
13786
13996
 
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
13997
  // src/internal/providers/builtin/anthropic.ts
13875
13998
  var ANTHROPIC = {
13876
13999
  name: "anthropic",