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