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.
- package/LICENSE +21 -21
- package/README.md +230 -273
- package/bin/vibezcheck.js +4 -4
- package/dist/ai-sdk/index.d.mts +28 -59
- package/dist/ai-sdk/index.d.ts +28 -59
- package/dist/ai-sdk/index.js +79 -32
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +79 -32
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/ai-sdk/middleware.d.mts +15 -0
- package/dist/ai-sdk/middleware.d.ts +15 -0
- package/dist/ai-sdk/middleware.js +1280 -0
- package/dist/ai-sdk/middleware.js.map +1 -0
- package/dist/ai-sdk/middleware.mjs +1243 -0
- package/dist/ai-sdk/middleware.mjs.map +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs.map +1 -1
- package/dist/billing/index.d.mts +90 -1
- package/dist/billing/index.d.ts +90 -1
- package/dist/billing/index.js +1391 -2
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +1386 -1
- package/dist/billing/index.mjs.map +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-ynfWcHX6.d.ts → client-CJ2Dj8ID.d.ts} +1 -1
- package/dist/{client-w_hWhQ6g.d.mts → client-Dmwb3hQt.d.mts} +1 -1
- package/dist/compat/stripe-meter.d.mts +21 -0
- package/dist/compat/stripe-meter.d.ts +21 -0
- package/dist/compat/stripe-meter.js +1281 -0
- package/dist/compat/stripe-meter.js.map +1 -0
- package/dist/compat/stripe-meter.mjs +1244 -0
- package/dist/compat/stripe-meter.mjs.map +1 -0
- package/dist/compat/stripe-provider.d.mts +54 -0
- package/dist/compat/stripe-provider.d.ts +54 -0
- package/dist/compat/stripe-provider.js +1304 -0
- package/dist/compat/stripe-provider.js.map +1 -0
- package/dist/compat/stripe-provider.mjs +1264 -0
- package/dist/compat/stripe-provider.mjs.map +1 -0
- package/dist/compat/token-meter.d.mts +16 -0
- package/dist/compat/token-meter.d.ts +16 -0
- package/dist/compat/token-meter.js +1095 -0
- package/dist/compat/token-meter.js.map +1 -0
- package/dist/compat/token-meter.mjs +1058 -0
- package/dist/compat/token-meter.mjs.map +1 -0
- package/dist/customers/index.d.mts +1 -1
- package/dist/customers/index.d.ts +1 -1
- package/dist/customers/index.js.map +1 -1
- package/dist/customers/index.mjs.map +1 -1
- package/dist/index.d.mts +22 -11
- package/dist/index.d.ts +22 -11
- package/dist/index.js +269 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -33
- package/dist/index.mjs.map +1 -1
- package/dist/meter/index.d.mts +2 -2
- package/dist/meter/index.d.ts +2 -2
- package/dist/meter/index.js +44 -22
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +44 -22
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +5 -2
- package/dist/pricing/index.d.ts +5 -2
- package/dist/pricing/index.js +43 -21
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +43 -21
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +46 -2
- package/dist/react/index.d.ts +46 -2
- package/dist/react/index.js +351 -21
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +349 -21
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-Mozk4-Mr.d.mts → types-BVGqbKnY.d.mts} +6 -0
- package/dist/{types-Mozk4-Mr.d.ts → types-BVGqbKnY.d.ts} +6 -0
- package/dist/with-billing-CDqKIAQ6.d.ts +47 -0
- package/dist/with-billing-mci2vtFS.d.mts +47 -0
- package/package.json +26 -1
package/dist/ai-sdk/index.mjs
CHANGED
|
@@ -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 =
|
|
577
|
-
const
|
|
578
|
-
const
|
|
579
|
-
const
|
|
580
|
-
const
|
|
581
|
-
const
|
|
582
|
-
const
|
|
583
|
-
const
|
|
584
|
-
const
|
|
585
|
-
const
|
|
586
|
-
|
|
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
|
|
592
|
+
let billedNano = wholesaleNano;
|
|
593
|
+
let hasRetail = false;
|
|
589
594
|
if (markup !== 1 || params.minimumChargeUSD !== void 0) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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 >
|
|
599
|
-
cachedDiscountUSD: cachedTokens >
|
|
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.
|
|
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.
|
|
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
|
|
1230
|
-
const
|
|
1231
|
-
|
|
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
|
|
1234
|
-
const
|
|
1235
|
-
|
|
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
|
|
1238
|
-
const
|
|
1239
|
-
|
|
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 = {
|