vibezcheck 0.4.2 → 0.5.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.
Files changed (78) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +230 -273
  3. package/bin/vibezcheck.js +4 -4
  4. package/dist/ai-sdk/index.d.mts +28 -59
  5. package/dist/ai-sdk/index.d.ts +28 -59
  6. package/dist/ai-sdk/index.js +79 -32
  7. package/dist/ai-sdk/index.js.map +1 -1
  8. package/dist/ai-sdk/index.mjs +79 -32
  9. package/dist/ai-sdk/index.mjs.map +1 -1
  10. package/dist/ai-sdk/middleware.d.mts +15 -0
  11. package/dist/ai-sdk/middleware.d.ts +15 -0
  12. package/dist/ai-sdk/middleware.js +1280 -0
  13. package/dist/ai-sdk/middleware.js.map +1 -0
  14. package/dist/ai-sdk/middleware.mjs +1243 -0
  15. package/dist/ai-sdk/middleware.mjs.map +1 -0
  16. package/dist/auth/index.js.map +1 -1
  17. package/dist/auth/index.mjs.map +1 -1
  18. package/dist/billing/index.d.mts +90 -1
  19. package/dist/billing/index.d.ts +90 -1
  20. package/dist/billing/index.js +1391 -2
  21. package/dist/billing/index.js.map +1 -1
  22. package/dist/billing/index.mjs +1386 -1
  23. package/dist/billing/index.mjs.map +1 -1
  24. package/dist/cli/index.js.map +1 -1
  25. package/dist/cli/index.mjs.map +1 -1
  26. package/dist/{client-ynfWcHX6.d.ts → client-CJ2Dj8ID.d.ts} +1 -1
  27. package/dist/{client-w_hWhQ6g.d.mts → client-Dmwb3hQt.d.mts} +1 -1
  28. package/dist/compat/stripe-meter.d.mts +21 -0
  29. package/dist/compat/stripe-meter.d.ts +21 -0
  30. package/dist/compat/stripe-meter.js +1281 -0
  31. package/dist/compat/stripe-meter.js.map +1 -0
  32. package/dist/compat/stripe-meter.mjs +1244 -0
  33. package/dist/compat/stripe-meter.mjs.map +1 -0
  34. package/dist/compat/stripe-provider.d.mts +54 -0
  35. package/dist/compat/stripe-provider.d.ts +54 -0
  36. package/dist/compat/stripe-provider.js +1304 -0
  37. package/dist/compat/stripe-provider.js.map +1 -0
  38. package/dist/compat/stripe-provider.mjs +1264 -0
  39. package/dist/compat/stripe-provider.mjs.map +1 -0
  40. package/dist/compat/token-meter.d.mts +16 -0
  41. package/dist/compat/token-meter.d.ts +16 -0
  42. package/dist/compat/token-meter.js +1095 -0
  43. package/dist/compat/token-meter.js.map +1 -0
  44. package/dist/compat/token-meter.mjs +1058 -0
  45. package/dist/compat/token-meter.mjs.map +1 -0
  46. package/dist/customers/index.d.mts +1 -1
  47. package/dist/customers/index.d.ts +1 -1
  48. package/dist/customers/index.js.map +1 -1
  49. package/dist/customers/index.mjs.map +1 -1
  50. package/dist/index.d.mts +22 -11
  51. package/dist/index.d.ts +22 -11
  52. package/dist/index.js +269 -33
  53. package/dist/index.js.map +1 -1
  54. package/dist/index.mjs +265 -33
  55. package/dist/index.mjs.map +1 -1
  56. package/dist/meter/index.d.mts +2 -2
  57. package/dist/meter/index.d.ts +2 -2
  58. package/dist/meter/index.js +44 -22
  59. package/dist/meter/index.js.map +1 -1
  60. package/dist/meter/index.mjs +44 -22
  61. package/dist/meter/index.mjs.map +1 -1
  62. package/dist/pricing/index.d.mts +5 -2
  63. package/dist/pricing/index.d.ts +5 -2
  64. package/dist/pricing/index.js +43 -21
  65. package/dist/pricing/index.js.map +1 -1
  66. package/dist/pricing/index.mjs +43 -21
  67. package/dist/pricing/index.mjs.map +1 -1
  68. package/dist/react/index.d.mts +46 -2
  69. package/dist/react/index.d.ts +46 -2
  70. package/dist/react/index.js +351 -21
  71. package/dist/react/index.js.map +1 -1
  72. package/dist/react/index.mjs +349 -21
  73. package/dist/react/index.mjs.map +1 -1
  74. package/dist/{types-Mozk4-Mr.d.mts → types-BVGqbKnY.d.mts} +6 -0
  75. package/dist/{types-Mozk4-Mr.d.ts → types-BVGqbKnY.d.ts} +6 -0
  76. package/dist/with-billing-CDqKIAQ6.d.ts +47 -0
  77. package/dist/with-billing-mci2vtFS.d.mts +47 -0
  78. package/package.json +26 -1
@@ -569,35 +569,57 @@ function calculateCost(params) {
569
569
  } else {
570
570
  rates = getModelPricing(params.model);
571
571
  }
572
- const inputTokens = params.inputTokens ?? 0;
573
- const outputTokens = params.outputTokens ?? 0;
574
- const reasoningTokens = params.reasoningTokens ?? 0;
575
- const cachedTokens = params.cachedTokens ?? 0;
576
- const regularInputTokens = Math.max(0, inputTokens - cachedTokens);
577
- const regularInputCost = regularInputTokens / 1e6 * rates.inputPer1M;
578
- const cachedRate = rates.cachedInputPer1M ?? rates.inputPer1M * 0.15;
579
- const cachedInputCost = cachedTokens / 1e6 * cachedRate;
580
- const inputCostUSD = regularInputCost + cachedInputCost;
581
- const outputCostUSD = outputTokens / 1e6 * rates.outputPer1M;
582
- const reasoningRate = rates.reasoningPer1M ?? rates.outputPer1M;
583
- const reasoningCostUSD = reasoningTokens / 1e6 * reasoningRate;
584
- const standardCacheCost = cachedTokens / 1e6 * rates.inputPer1M;
585
- const cachedDiscountUSD = Math.max(0, standardCacheCost - cachedInputCost);
586
- let totalUSD = inputCostUSD + outputCostUSD;
572
+ const inputTokens = BigInt(Math.max(0, params.inputTokens ?? 0));
573
+ const outputTokens = BigInt(Math.max(0, params.outputTokens ?? 0));
574
+ const reasoningTokens = BigInt(Math.max(0, params.reasoningTokens ?? 0));
575
+ const cachedTokens = BigInt(Math.max(0, params.cachedTokens ?? 0));
576
+ const regularInputTokens = inputTokens > cachedTokens ? inputTokens - cachedTokens : 0n;
577
+ const rateInputNano = BigInt(Math.round(rates.inputPer1M * 1e3));
578
+ const cachedPer1M = rates.cachedInputPer1M ?? rates.inputPer1M * 0.15;
579
+ const rateCachedNano = BigInt(Math.round(cachedPer1M * 1e3));
580
+ const rateOutputNano = BigInt(Math.round(rates.outputPer1M * 1e3));
581
+ const reasoningPer1M = rates.reasoningPer1M ?? rates.outputPer1M;
582
+ const rateReasoningNano = BigInt(Math.round(reasoningPer1M * 1e3));
583
+ const regularInputCostNano = regularInputTokens * rateInputNano;
584
+ const cachedInputCostNano = cachedTokens * rateCachedNano;
585
+ const inputCostNano = regularInputCostNano + cachedInputCostNano;
586
+ const outputCostNano = outputTokens * rateOutputNano;
587
+ const reasoningCostNano = reasoningTokens * rateReasoningNano;
588
+ const standardCacheCostNano = cachedTokens * rateInputNano;
589
+ const cachedDiscountNano = standardCacheCostNano > cachedInputCostNano ? standardCacheCostNano - cachedInputCostNano : 0n;
590
+ const wholesaleNano = inputCostNano + outputCostNano;
587
591
  const markup = params.markupMultiplier ?? 1;
588
- let retailUSD = void 0;
592
+ let billedNano = wholesaleNano;
593
+ let hasRetail = false;
589
594
  if (markup !== 1 || params.minimumChargeUSD !== void 0) {
590
- retailUSD = totalUSD * markup;
591
- if (params.minimumChargeUSD !== void 0 && retailUSD < params.minimumChargeUSD) {
592
- retailUSD = params.minimumChargeUSD;
595
+ hasRetail = true;
596
+ const markupMultiplierNano = BigInt(Math.round(markup * 1e3));
597
+ billedNano = wholesaleNano * markupMultiplierNano / 1000n;
598
+ if (params.minimumChargeUSD !== void 0 && params.minimumChargeUSD > 0) {
599
+ const minChargeNano = BigInt(Math.round(params.minimumChargeUSD * 1e9));
600
+ if (billedNano < minChargeNano) {
601
+ billedNano = minChargeNano;
602
+ }
593
603
  }
594
604
  }
605
+ const inputCostUSD = Number(inputCostNano) / 1e9;
606
+ const outputCostUSD = Number(outputCostNano) / 1e9;
607
+ const reasoningCostUSD = Number(reasoningCostNano) / 1e9;
608
+ const cachedDiscountUSD = Number(cachedDiscountNano) / 1e9;
609
+ const totalUSD = Number(wholesaleNano) / 1e9;
610
+ const wholesaleTotalUSD = totalUSD;
611
+ const billedUSD = Number(billedNano) / 1e9;
612
+ const profitUSD = Math.max(0, billedUSD - wholesaleTotalUSD);
613
+ const retailUSD = hasRetail ? billedUSD : void 0;
595
614
  return {
596
615
  inputCostUSD: Number(inputCostUSD.toFixed(8)),
597
616
  outputCostUSD: Number(outputCostUSD.toFixed(8)),
598
- reasoningCostUSD: reasoningTokens > 0 ? Number(reasoningCostUSD.toFixed(8)) : void 0,
599
- cachedDiscountUSD: cachedTokens > 0 ? Number(cachedDiscountUSD.toFixed(8)) : void 0,
617
+ reasoningCostUSD: reasoningTokens > 0n ? Number(reasoningCostUSD.toFixed(8)) : void 0,
618
+ cachedDiscountUSD: cachedTokens > 0n ? Number(cachedDiscountUSD.toFixed(8)) : void 0,
600
619
  totalUSD: Number(totalUSD.toFixed(8)),
620
+ wholesaleTotalUSD: Number(wholesaleTotalUSD.toFixed(8)),
621
+ billedUSD: Number(billedUSD.toFixed(8)),
622
+ profitUSD: Number(profitUSD.toFixed(8)),
601
623
  retailUSD: retailUSD !== void 0 ? Number(retailUSD.toFixed(8)) : void 0,
602
624
  currency: rates.currency || "USD"
603
625
  };
@@ -825,7 +847,7 @@ var VibezMeter = class {
825
847
  this.stripeClient = new Stripe(key, {
826
848
  appInfo: {
827
849
  name: "vibezcheck",
828
- version: "0.4.2",
850
+ version: "0.5.0",
829
851
  url: "https://vibezcheck.xyz"
830
852
  }
831
853
  });
@@ -1220,23 +1242,48 @@ function createVibezModel(modelOrId, options = {}) {
1220
1242
  const parts = rawId.split("/");
1221
1243
  providerName = parts[0].toLowerCase();
1222
1244
  cleanModelId = parts.slice(1).join("/");
1245
+ } else if (rawId.startsWith("claude-")) {
1246
+ providerName = "anthropic";
1247
+ } else if (rawId.startsWith("gemini-")) {
1248
+ providerName = "google";
1223
1249
  }
1224
- const apiKey = options.apiKey || process.env.AI_GATEWAY_API_KEY || process.env.OPENAI_API_KEY || process.env.ANTHROPIC_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY;
1250
+ const apiKey = options.apiKey || process.env.AI_GATEWAY_API_KEY || (providerName === "anthropic" ? process.env.ANTHROPIC_API_KEY : void 0) || (providerName === "google" ? process.env.GOOGLE_GENERATIVE_AI_API_KEY : void 0) || process.env.OPENAI_API_KEY;
1225
1251
  const baseURL = options.baseURL || process.env.AI_GATEWAY_BASE_URL || (providerName === "openai" ? "https://api.openai.com/v1" : void 0);
1226
1252
  let baseModelInstance = null;
1227
1253
  try {
1228
1254
  if (providerName === "openai" || providerName === "gateway" || !providerName) {
1229
- const { createOpenAI } = __require("@ai-sdk/openai");
1230
- const openaiProvider = createOpenAI({ apiKey, baseURL });
1231
- baseModelInstance = openaiProvider(cleanModelId);
1255
+ const mod = __require("@ai-sdk/openai");
1256
+ const factory = mod.createOpenAI || mod.openai || mod.default?.createOpenAI || mod.default?.openai;
1257
+ if (typeof factory === "function") {
1258
+ if (mod.createOpenAI) {
1259
+ const provider = factory({ apiKey, baseURL });
1260
+ baseModelInstance = provider(cleanModelId);
1261
+ } else {
1262
+ baseModelInstance = factory(cleanModelId);
1263
+ }
1264
+ }
1232
1265
  } else if (providerName === "anthropic") {
1233
- const { createAnthropic } = __require("@ai-sdk/anthropic");
1234
- const anthropicProvider = createAnthropic({ apiKey, baseURL });
1235
- baseModelInstance = anthropicProvider(cleanModelId);
1266
+ const mod = __require("@ai-sdk/anthropic");
1267
+ const factory = mod.createAnthropic || mod.anthropic || mod.default?.createAnthropic || mod.default?.anthropic;
1268
+ if (typeof factory === "function") {
1269
+ if (mod.createAnthropic) {
1270
+ const provider = factory({ apiKey, baseURL });
1271
+ baseModelInstance = provider(cleanModelId);
1272
+ } else {
1273
+ baseModelInstance = factory(cleanModelId);
1274
+ }
1275
+ }
1236
1276
  } else if (providerName === "google") {
1237
- const { createGoogleGenerativeAI } = __require("@ai-sdk/google");
1238
- const googleProvider = createGoogleGenerativeAI({ apiKey, baseURL });
1239
- baseModelInstance = googleProvider(cleanModelId);
1277
+ const mod = __require("@ai-sdk/google");
1278
+ const factory = mod.createGoogleGenerativeAI || mod.google || mod.default?.createGoogleGenerativeAI || mod.default?.google;
1279
+ if (typeof factory === "function") {
1280
+ if (mod.createGoogleGenerativeAI) {
1281
+ const provider = factory({ apiKey, baseURL });
1282
+ baseModelInstance = provider(cleanModelId);
1283
+ } else {
1284
+ baseModelInstance = factory(cleanModelId);
1285
+ }
1286
+ }
1240
1287
  }
1241
1288
  } catch {
1242
1289
  baseModelInstance = {