vibezcheck 0.5.0 → 0.5.3

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 (74) hide show
  1. package/README.md +43 -24
  2. package/dist/ai-sdk/index.d.mts +4 -4
  3. package/dist/ai-sdk/index.d.ts +4 -4
  4. package/dist/ai-sdk/index.js +230 -39
  5. package/dist/ai-sdk/index.js.map +1 -1
  6. package/dist/ai-sdk/index.mjs +230 -39
  7. package/dist/ai-sdk/index.mjs.map +1 -1
  8. package/dist/ai-sdk/middleware.d.mts +3 -3
  9. package/dist/ai-sdk/middleware.d.ts +3 -3
  10. package/dist/ai-sdk/middleware.js +193 -40
  11. package/dist/ai-sdk/middleware.js.map +1 -1
  12. package/dist/ai-sdk/middleware.mjs +193 -40
  13. package/dist/ai-sdk/middleware.mjs.map +1 -1
  14. package/dist/billing/index.d.mts +3 -3
  15. package/dist/billing/index.d.ts +3 -3
  16. package/dist/billing/index.js +189 -38
  17. package/dist/billing/index.js.map +1 -1
  18. package/dist/billing/index.mjs +189 -38
  19. package/dist/billing/index.mjs.map +1 -1
  20. package/dist/cli/index.js +59 -7
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/cli/index.mjs +59 -7
  23. package/dist/cli/index.mjs.map +1 -1
  24. package/dist/{client-CJ2Dj8ID.d.ts → client-BORmJy8s.d.ts} +1 -1
  25. package/dist/{client-Dmwb3hQt.d.mts → client-CbuXmoXz.d.mts} +1 -1
  26. package/dist/compat/stripe-meter.d.mts +4 -4
  27. package/dist/compat/stripe-meter.d.ts +4 -4
  28. package/dist/compat/stripe-meter.js +213 -43
  29. package/dist/compat/stripe-meter.js.map +1 -1
  30. package/dist/compat/stripe-meter.mjs +213 -43
  31. package/dist/compat/stripe-meter.mjs.map +1 -1
  32. package/dist/compat/stripe-provider.d.mts +4 -24
  33. package/dist/compat/stripe-provider.d.ts +4 -24
  34. package/dist/compat/stripe-provider.js +371 -55
  35. package/dist/compat/stripe-provider.js.map +1 -1
  36. package/dist/compat/stripe-provider.mjs +378 -55
  37. package/dist/compat/stripe-provider.mjs.map +1 -1
  38. package/dist/compat/token-meter.d.mts +18 -6
  39. package/dist/compat/token-meter.d.ts +18 -6
  40. package/dist/compat/token-meter.js +256 -31
  41. package/dist/compat/token-meter.js.map +1 -1
  42. package/dist/compat/token-meter.mjs +256 -31
  43. package/dist/compat/token-meter.mjs.map +1 -1
  44. package/dist/customers/index.d.mts +1 -1
  45. package/dist/customers/index.d.ts +1 -1
  46. package/dist/index.d.mts +10 -7
  47. package/dist/index.d.ts +10 -7
  48. package/dist/index.js +545 -43
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.mjs +537 -43
  51. package/dist/index.mjs.map +1 -1
  52. package/dist/meter/index.d.mts +2 -2
  53. package/dist/meter/index.d.ts +2 -2
  54. package/dist/meter/index.js +133 -21
  55. package/dist/meter/index.js.map +1 -1
  56. package/dist/meter/index.mjs +133 -21
  57. package/dist/meter/index.mjs.map +1 -1
  58. package/dist/pricing/index.d.mts +11 -3
  59. package/dist/pricing/index.d.ts +11 -3
  60. package/dist/pricing/index.js +122 -8
  61. package/dist/pricing/index.js.map +1 -1
  62. package/dist/pricing/index.mjs +121 -8
  63. package/dist/pricing/index.mjs.map +1 -1
  64. package/dist/react/index.d.mts +1 -1
  65. package/dist/react/index.d.ts +1 -1
  66. package/dist/react/index.js +120 -8
  67. package/dist/react/index.js.map +1 -1
  68. package/dist/react/index.mjs +120 -8
  69. package/dist/react/index.mjs.map +1 -1
  70. package/dist/{types-BVGqbKnY.d.mts → types-6P71CXAD.d.mts} +10 -6
  71. package/dist/{types-BVGqbKnY.d.ts → types-6P71CXAD.d.ts} +10 -6
  72. package/dist/{with-billing-CDqKIAQ6.d.ts → with-billing-Bj6Ya_Iy.d.ts} +5 -3
  73. package/dist/{with-billing-mci2vtFS.d.mts → with-billing-DndWGxL8.d.mts} +5 -3
  74. package/package.json +10 -10
package/README.md CHANGED
@@ -39,7 +39,7 @@ const model = vibezcheck('openai/gpt-4o', { customer: 'cus_alex' });
39
39
  ## 📦 Installation
40
40
 
41
41
  ```bash
42
- npm install vibezcheck ai @ai-sdk/openai stripe
42
+ npm install vibezcheck ai @ai-sdk/openai @ai-sdk/react stripe
43
43
  ```
44
44
 
45
45
  ---
@@ -74,38 +74,47 @@ export async function POST(req: Request) {
74
74
 
75
75
  ```tsx
76
76
  'use client';
77
- import { useChat } from 'ai/react';
77
+
78
+ import { useChat } from '@ai-sdk/react';
79
+ import { useState } from 'react';
78
80
  import { VibezCheck } from 'vibezcheck/ui';
79
81
 
80
- export default function ChatPage() {
81
- const { messages, input, handleInputChange, handleSubmit } = useChat();
82
+ export default function Chat() {
83
+ const [input, setInput] = useState('');
84
+ const { messages, sendMessage } = useChat();
82
85
 
83
86
  return (
84
- <main className="max-w-2xl mx-auto p-6 space-y-4">
85
- <div className="space-y-3">
86
- {messages.map((m) => (
87
- <div key={m.id} className="p-3 rounded-lg bg-slate-100 dark:bg-slate-800">
88
- <strong>{m.role}: </strong>
89
- <span>{m.content}</span>
90
- </div>
91
- ))}
92
- </div>
93
-
94
- <form onSubmit={handleSubmit} className="flex gap-2">
87
+ <div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
88
+ {messages.map(message => (
89
+ <div key={message.id} className="whitespace-pre-wrap">
90
+ {message.role === 'user' ? 'User: ' : 'AI: '}
91
+ {message.parts.map((part, i) => {
92
+ switch (part.type) {
93
+ case 'text':
94
+ return <div key={`${message.id}-${i}`}>{part.text}</div>;
95
+ }
96
+ })}
97
+ </div>
98
+ ))}
99
+
100
+ <form
101
+ onSubmit={e => {
102
+ e.preventDefault();
103
+ sendMessage({ text: input });
104
+ setInput('');
105
+ }}
106
+ >
95
107
  <input
108
+ className="fixed dark:bg-zinc-900 bottom-0 w-full max-w-md p-2 mb-8 border border-zinc-300 dark:border-zinc-800 rounded shadow-xl"
96
109
  value={input}
97
- onChange={handleInputChange}
98
- placeholder="Ask anything..."
99
- className="flex-1 p-2 border rounded-lg"
110
+ placeholder="Say something..."
111
+ onChange={e => setInput(e.currentTarget.value)}
100
112
  />
101
- <button type="submit" className="px-4 py-2 bg-blue-600 text-white rounded-lg">
102
- Send
103
- </button>
104
113
  </form>
105
114
 
106
- {/* ✦ 1-Line HUD: Works with zero database & zero Stripe in Dev Mode */}
107
- <VibezCheck messages={messages} model="gpt-4o-mini" margin={1.3} />
108
- </main>
115
+ {/* ✦ 1-Line Token Meter & Financial HUD: Works with zero database & zero Stripe in Dev Mode */}
116
+ <VibezCheck messages={messages} />
117
+ </div>
109
118
  );
110
119
  }
111
120
  ```
@@ -225,6 +234,16 @@ npx vibezcheck audit --ci
225
234
 
226
235
  ---
227
236
 
237
+ ## 📂 Examples
238
+
239
+ * **[Next.js App Router + OpenAI](examples/nextjs-app-router-openai)**: Direct implementation of the official [AI SDK Next.js App Router Tutorial](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) with 1-line VibezCheck token metering.
240
+ * **[Next.js 15 AI SaaS Starter](examples/nextjs-saas-starter)**: Complete SaaS template with Stripe Checkout, Top-Up Modal, and `<VibezReceipt />`.
241
+ * **[Local Cost Meter](examples/01-local-cost-meter.ts)**: Offline micro-transaction calculations with BigInt Nano-USD precision.
242
+ * **[Native OpenAI Streaming](examples/03-native-openai-stream.ts)**: Zero-latency stream wrapper for the official `openai` Node SDK.
243
+ * **[Claude 3.7 Reasoning Tokens](examples/04-claude-thinking.ts)**: Tracking hidden thought tokens with Anthropic SDK.
244
+
245
+ ---
246
+
228
247
  ## 📄 License
229
248
 
230
249
  MIT © [VibezCheck](https://vibezcheck.xyz)
@@ -1,7 +1,7 @@
1
- import { W as WithBillingOptions } from '../with-billing-mci2vtFS.mjs';
2
- export { m as meteredModel, w as withBilling } from '../with-billing-mci2vtFS.mjs';
3
- import { C as CustomerParam } from '../types-BVGqbKnY.mjs';
4
- import { V as VibezMeter } from '../client-Dmwb3hQt.mjs';
1
+ import { W as WithBillingOptions } from '../with-billing-DndWGxL8.mjs';
2
+ export { m as meteredModel, w as withBilling } from '../with-billing-DndWGxL8.mjs';
3
+ import { C as CustomerParam } from '../types-6P71CXAD.mjs';
4
+ import { V as VibezMeter } from '../client-CbuXmoXz.mjs';
5
5
  import 'stripe';
6
6
 
7
7
  interface VibezCheckModelOptions extends WithBillingOptions {
@@ -1,7 +1,7 @@
1
- import { W as WithBillingOptions } from '../with-billing-CDqKIAQ6.js';
2
- export { m as meteredModel, w as withBilling } from '../with-billing-CDqKIAQ6.js';
3
- import { C as CustomerParam } from '../types-BVGqbKnY.js';
4
- import { V as VibezMeter } from '../client-CJ2Dj8ID.js';
1
+ import { W as WithBillingOptions } from '../with-billing-Bj6Ya_Iy.js';
2
+ export { m as meteredModel, w as withBilling } from '../with-billing-Bj6Ya_Iy.js';
3
+ import { C as CustomerParam } from '../types-6P71CXAD.js';
4
+ import { V as VibezMeter } from '../client-BORmJy8s.js';
5
5
  import 'stripe';
6
6
 
7
7
  interface VibezCheckModelOptions extends WithBillingOptions {
@@ -309,12 +309,12 @@ function extractOpenAIResponseUsage(response) {
309
309
  function inspectOpenAIStreamChunk(chunk) {
310
310
  if (!chunk || typeof chunk !== "object") return {};
311
311
  const model = chunk.model;
312
- if (chunk.usage) {
313
- const rawUsage = chunk.usage;
314
- const inputTokens = rawUsage.prompt_tokens ?? rawUsage.input_tokens ?? 0;
315
- const outputTokens = rawUsage.completion_tokens ?? rawUsage.output_tokens ?? 0;
316
- const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens ?? rawUsage.output_token_details?.reasoning_tokens ?? 0;
317
- const cachedTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.input_token_details?.cached_tokens ?? 0;
312
+ const rawUsage = chunk.usage || chunk.token_usage || chunk.x_groq?.usage || chunk.usageMetadata;
313
+ if (rawUsage) {
314
+ const inputTokens = rawUsage.prompt_tokens ?? rawUsage.input_tokens ?? rawUsage.promptTokens ?? rawUsage.inputTokens ?? rawUsage.promptTokenCount ?? 0;
315
+ const outputTokens = rawUsage.completion_tokens ?? rawUsage.output_tokens ?? rawUsage.completionTokens ?? rawUsage.outputTokens ?? rawUsage.candidatesTokenCount ?? 0;
316
+ const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens ?? rawUsage.output_token_details?.reasoning_tokens ?? rawUsage.reasoning_tokens ?? rawUsage.reasoningTokens ?? rawUsage.thoughtsTokenCount ?? 0;
317
+ const cachedTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.input_token_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? rawUsage.cachedTokens ?? rawUsage.cachedContentTokenCount ?? 0;
318
318
  return {
319
319
  model,
320
320
  usage: {
@@ -329,11 +329,11 @@ function inspectOpenAIStreamChunk(chunk) {
329
329
  }
330
330
  if (chunk.type === "response.completed" || chunk.type === "response.done") {
331
331
  if (chunk.response?.usage) {
332
- const rawUsage = chunk.response.usage;
333
- const inputTokens = rawUsage.input_tokens ?? 0;
334
- const outputTokens = rawUsage.output_tokens ?? 0;
335
- const reasoningTokens = rawUsage.output_token_details?.reasoning_tokens ?? 0;
336
- const cachedTokens = rawUsage.input_token_details?.cached_tokens ?? 0;
332
+ const rawUsage2 = chunk.response.usage;
333
+ const inputTokens = rawUsage2.input_tokens ?? 0;
334
+ const outputTokens = rawUsage2.output_tokens ?? 0;
335
+ const reasoningTokens = rawUsage2.output_token_details?.reasoning_tokens ?? 0;
336
+ const cachedTokens = rawUsage2.input_token_details?.cached_tokens ?? 0;
337
337
  return {
338
338
  model: chunk.response.model || model,
339
339
  usage: {
@@ -498,7 +498,7 @@ function detectAndExtractUsage(response, fallbackModel, fallbackProvider) {
498
498
 
499
499
  // src/pricing/table.ts
500
500
  var MODEL_PRICING_TABLE = {
501
- // --- OpenAI ---
501
+ // --- OpenAI (Modern & Reasoning) ---
502
502
  "gpt-5.6-sol": { inputPer1M: 4, outputPer1M: 20, cachedInputPer1M: 0.4 },
503
503
  "gpt-5.6-terra": { inputPer1M: 2, outputPer1M: 12, cachedInputPer1M: 0.2 },
504
504
  "gpt-5.6-luna": { inputPer1M: 0.2, outputPer1M: 1.2, cachedInputPer1M: 0.02 },
@@ -510,11 +510,22 @@ var MODEL_PRICING_TABLE = {
510
510
  "o3-mini": { inputPer1M: 1.1, outputPer1M: 4.4, cachedInputPer1M: 0.55 },
511
511
  "gpt-4o": { inputPer1M: 2.5, outputPer1M: 10, cachedInputPer1M: 1.25 },
512
512
  "gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6, cachedInputPer1M: 0.075 },
513
+ "gpt-4.5": { inputPer1M: 75, outputPer1M: 150, cachedInputPer1M: 37.5 },
514
+ "gpt-4.5-preview": { inputPer1M: 75, outputPer1M: 150, cachedInputPer1M: 37.5 },
515
+ "chatgpt-4o-latest": { inputPer1M: 5, outputPer1M: 15 },
513
516
  "gpt-4.1": { inputPer1M: 2, outputPer1M: 8, cachedInputPer1M: 1 },
514
517
  "gpt-4.1-nano": { inputPer1M: 0.1, outputPer1M: 0.4, cachedInputPer1M: 0.05 },
518
+ // --- OpenAI (Legacy & Backward Compatibility) ---
519
+ "gpt-4-turbo": { inputPer1M: 10, outputPer1M: 30, cachedInputPer1M: 5 },
520
+ "gpt-4-turbo-preview": { inputPer1M: 10, outputPer1M: 30, cachedInputPer1M: 5 },
521
+ "gpt-4": { inputPer1M: 30, outputPer1M: 60 },
522
+ "gpt-4-32k": { inputPer1M: 60, outputPer1M: 120 },
523
+ "gpt-3.5-turbo": { inputPer1M: 0.5, outputPer1M: 1.5 },
524
+ "gpt-3.5-turbo-16k": { inputPer1M: 3, outputPer1M: 4 },
515
525
  "text-embedding-3-small": { inputPer1M: 0.02, outputPer1M: 0 },
516
526
  "text-embedding-3-large": { inputPer1M: 0.13, outputPer1M: 0 },
517
- // --- Anthropic ---
527
+ "text-embedding-ada-002": { inputPer1M: 0.1, outputPer1M: 0 },
528
+ // --- Anthropic (Modern & Extended Thinking) ---
518
529
  "claude-3-7-sonnet": { inputPer1M: 0.59, outputPer1M: 2.93, cachedInputPer1M: 0.3 },
519
530
  "claude-sonnet-5": { inputPer1M: 2, outputPer1M: 10, cachedInputPer1M: 0.3 },
520
531
  "claude-3-5-sonnet": { inputPer1M: 3, outputPer1M: 15, cachedInputPer1M: 0.3 },
@@ -522,48 +533,145 @@ var MODEL_PRICING_TABLE = {
522
533
  "haiku-4.5": { inputPer1M: 1, outputPer1M: 5, cachedInputPer1M: 0.1 },
523
534
  "claude-opus-5": { inputPer1M: 5, outputPer1M: 25, cachedInputPer1M: 1.5 },
524
535
  "claude-3-opus": { inputPer1M: 15, outputPer1M: 75, cachedInputPer1M: 1.5 },
525
- // --- Google Gemini ---
536
+ // --- Anthropic (Legacy & Backward Compatibility) ---
537
+ "claude-3-sonnet": { inputPer1M: 3, outputPer1M: 15, cachedInputPer1M: 0.3 },
538
+ "claude-3-haiku": { inputPer1M: 0.25, outputPer1M: 1.25, cachedInputPer1M: 0.025 },
539
+ "claude-2.1": { inputPer1M: 8, outputPer1M: 24 },
540
+ "claude-2.0": { inputPer1M: 8, outputPer1M: 24 },
541
+ "claude-instant-1.2": { inputPer1M: 1.63, outputPer1M: 5.51 },
542
+ // --- Google Gemini (Modern & Thoughts) ---
526
543
  "gemini-3.7-flash": { inputPer1M: 0.75, outputPer1M: 3.75, cachedInputPer1M: 0.18 },
527
544
  "gemini-3.1-pro": { inputPer1M: 2, outputPer1M: 12, cachedInputPer1M: 0.5 },
528
545
  "gemini-3.5-flash": { inputPer1M: 1.5, outputPer1M: 9, cachedInputPer1M: 0.38 },
529
546
  "gemini-3.1-flash-lite": { inputPer1M: 0.25, outputPer1M: 1.5, cachedInputPer1M: 0.06 },
547
+ "gemini-2.5-pro": { inputPer1M: 1.25, outputPer1M: 5, cachedInputPer1M: 0.3125 },
548
+ "gemini-2.5-flash": { inputPer1M: 0.15, outputPer1M: 0.6, cachedInputPer1M: 0.0375 },
530
549
  "gemini-2.0-flash": { inputPer1M: 0.1, outputPer1M: 0.4, cachedInputPer1M: 0.025 },
550
+ "gemini-2.0-flash-lite": { inputPer1M: 0.075, outputPer1M: 0.3, cachedInputPer1M: 0.01875 },
551
+ "gemini-2.0-pro": { inputPer1M: 1.25, outputPer1M: 5, cachedInputPer1M: 0.3125 },
552
+ // --- Google Gemini (Legacy & Backward Compatibility) ---
531
553
  "gemini-1.5-pro": { inputPer1M: 1.25, outputPer1M: 5, cachedInputPer1M: 0.3125 },
532
554
  "gemini-1.5-flash": { inputPer1M: 0.075, outputPer1M: 0.3, cachedInputPer1M: 0.01875 },
555
+ "gemini-1.5-flash-8b": { inputPer1M: 0.0375, outputPer1M: 0.15, cachedInputPer1M: 9375e-6 },
556
+ "gemini-1.0-pro": { inputPer1M: 0.5, outputPer1M: 1.5 },
533
557
  // --- xAI Grok ---
534
558
  "grok-4.6": { inputPer1M: 3, outputPer1M: 15 },
559
+ "grok-3": { inputPer1M: 3, outputPer1M: 15 },
560
+ "grok-3-mini": { inputPer1M: 0.3, outputPer1M: 1.5 },
535
561
  "grok-2": { inputPer1M: 2, outputPer1M: 10 },
536
562
  "grok-2-vision": { inputPer1M: 2, outputPer1M: 10 },
537
563
  "grok-beta": { inputPer1M: 5, outputPer1M: 15 },
538
564
  // --- Mistral ---
539
565
  "mistral-large-3": { inputPer1M: 2, outputPer1M: 6 },
540
566
  "mistral-large-latest": { inputPer1M: 2, outputPer1M: 6 },
567
+ "mistral-large-2411": { inputPer1M: 2, outputPer1M: 6 },
541
568
  "codestral-latest": { inputPer1M: 0.3, outputPer1M: 0.9 },
569
+ "mistral-medium-latest": { inputPer1M: 2.7, outputPer1M: 8.1 },
542
570
  "mistral-small-latest": { inputPer1M: 0.2, outputPer1M: 0.6 },
543
571
  "ministral-8b-latest": { inputPer1M: 0.1, outputPer1M: 0.1 },
544
- // --- Groq LPUs ---
572
+ "ministral-3b-latest": { inputPer1M: 0.04, outputPer1M: 0.04 },
573
+ "open-mistral-7b": { inputPer1M: 0.2, outputPer1M: 0.2 },
574
+ "open-mixtral-8x7b": { inputPer1M: 0.7, outputPer1M: 0.7 },
575
+ "open-mixtral-8x22b": { inputPer1M: 2, outputPer1M: 6 },
576
+ // --- Groq & Meta Llama LPUs ---
545
577
  "llama-3.3-70b-versatile": { inputPer1M: 0.59, outputPer1M: 0.79 },
578
+ "llama-3.1-405b": { inputPer1M: 3, outputPer1M: 3 },
579
+ "llama-3.1-70b-versatile": { inputPer1M: 0.59, outputPer1M: 0.79 },
546
580
  "llama-3.1-8b-instant": { inputPer1M: 0.05, outputPer1M: 0.08 },
581
+ "llama-3.2-1b-preview": { inputPer1M: 0.04, outputPer1M: 0.04 },
582
+ "llama-3.2-3b-preview": { inputPer1M: 0.06, outputPer1M: 0.06 },
583
+ "llama-3.2-11b-vision": { inputPer1M: 0.18, outputPer1M: 0.18 },
584
+ "llama-3.2-90b-vision": { inputPer1M: 0.9, outputPer1M: 0.9 },
547
585
  "deepseek-r1-distill-llama-70b": { inputPer1M: 0.75, outputPer1M: 0.99 },
586
+ "deepseek-r1-distill-qwen-32b": { inputPer1M: 0.49, outputPer1M: 0.49 },
548
587
  "qwen-2.5-32b": { inputPer1M: 0.29, outputPer1M: 0.39 },
588
+ "qwen-2.5-72b": { inputPer1M: 0.35, outputPer1M: 0.4 },
589
+ "mixtral-8x7b-32768": { inputPer1M: 0.24, outputPer1M: 0.24 },
590
+ "gemma2-9b-it": { inputPer1M: 0.2, outputPer1M: 0.2 },
549
591
  // --- DeepSeek ---
550
592
  "deepseek-v4-pro": { inputPer1M: 0.66, outputPer1M: 1.98, cachedInputPer1M: 0.15 },
551
593
  "deepseek-v4-flash": { inputPer1M: 0.22, outputPer1M: 0.66, cachedInputPer1M: 0.05 },
552
- "deepseek-chat": { inputPer1M: 0.22, outputPer1M: 0.66, cachedInputPer1M: 0.05 },
553
- "deepseek-reasoner": { inputPer1M: 0.66, outputPer1M: 1.98, cachedInputPer1M: 0.15 },
594
+ "deepseek-v3": { inputPer1M: 0.14, outputPer1M: 0.28, cachedInputPer1M: 0.014 },
595
+ "deepseek-chat": { inputPer1M: 0.14, outputPer1M: 0.28, cachedInputPer1M: 0.014 },
596
+ "deepseek-r1": { inputPer1M: 0.55, outputPer1M: 2.19, cachedInputPer1M: 0.14 },
597
+ "deepseek-reasoner": { inputPer1M: 0.55, outputPer1M: 2.19, cachedInputPer1M: 0.14 },
554
598
  // --- Cohere ---
555
599
  "command-r-plus": { inputPer1M: 2.5, outputPer1M: 10 },
556
- "command-r": { inputPer1M: 0.15, outputPer1M: 0.6 }
600
+ "command-r": { inputPer1M: 0.15, outputPer1M: 0.6 },
601
+ "command": { inputPer1M: 1, outputPer1M: 2 },
602
+ "command-light": { inputPer1M: 0.3, outputPer1M: 0.6 },
603
+ "embed-english-v3.0": { inputPer1M: 0.1, outputPer1M: 0 },
604
+ // --- Perplexity ---
605
+ "sonar": { inputPer1M: 1, outputPer1M: 1 },
606
+ "sonar-pro": { inputPer1M: 3, outputPer1M: 15 },
607
+ "sonar-reasoning": { inputPer1M: 1, outputPer1M: 5 },
608
+ "sonar-reasoning-pro": { inputPer1M: 2, outputPer1M: 8 }
609
+ };
610
+ var MODEL_ALIASES = {
611
+ // OpenAI Shorthands & Aliases
612
+ "gpt4": "gpt-4",
613
+ "gpt4o": "gpt-4o",
614
+ "gpt-4-preview": "gpt-4-turbo",
615
+ "gpt-4-0125-preview": "gpt-4-turbo",
616
+ "gpt-4-1106-preview": "gpt-4-turbo",
617
+ "gpt-3.5": "gpt-3.5-turbo",
618
+ "gpt-3.5-turbo-0125": "gpt-3.5-turbo",
619
+ "gpt-3.5-turbo-1106": "gpt-3.5-turbo",
620
+ "gpt-3.5-turbo-16k-0613": "gpt-3.5-turbo-16k",
621
+ // Anthropic Shorthands
622
+ "sonnet": "claude-3-5-sonnet",
623
+ "sonnet-3.7": "claude-3-7-sonnet",
624
+ "sonnet-3.5": "claude-3-5-sonnet",
625
+ "haiku": "claude-3-5-haiku",
626
+ "haiku-3.5": "claude-3-5-haiku",
627
+ "opus": "claude-3-opus",
628
+ "claude-2": "claude-2.0",
629
+ "claude-instant": "claude-instant-1.2",
630
+ // DeepSeek Shorthands
631
+ "r1": "deepseek-r1",
632
+ "v3": "deepseek-v3",
633
+ // Gemini Shorthands
634
+ "flash": "gemini-2.0-flash",
635
+ "pro": "gemini-1.5-pro",
636
+ // Meta / Groq Shorthands
637
+ "llama-3.3-70b": "llama-3.3-70b-versatile",
638
+ "llama-3.1-70b": "llama-3.1-70b-versatile",
639
+ "llama-3.1-8b": "llama-3.1-8b-instant",
640
+ "llama-3-70b": "llama-3.1-70b-versatile",
641
+ "llama-3-8b": "llama-3.1-8b-instant",
642
+ // Mistral Shorthands
643
+ "codestral": "codestral-latest",
644
+ "mistral-large": "mistral-large-latest",
645
+ "mistral-small": "mistral-small-latest"
557
646
  };
558
647
  var customPricingRegistry = {};
559
648
  function normalizeModelKey(rawModel) {
560
649
  if (!rawModel) return "unknown";
561
650
  let model = rawModel.toLowerCase().trim();
651
+ model = model.replace(/^[a-z0-9_-]+\.(anthropic|meta|amazon|cohere|mistral|ai21)\./i, "");
652
+ model = model.replace(/^(anthropic|meta|amazon|cohere|mistral|ai21)\./i, "");
653
+ model = model.replace(/-v\d+(:\d+)?$/, "");
654
+ model = model.replace(/:\d+$/, "");
562
655
  if (model.includes("/")) {
563
- model = model.split("/")[1] || model;
656
+ model = model.split("/").slice(1).join("/");
564
657
  }
658
+ model = model.replace(/:(latest|free|beta)$/, "");
565
659
  model = model.replace(/-\d{8}$/, "");
566
660
  model = model.replace(/-\d{4}-\d{2}-\d{2}$/, "");
661
+ model = model.replace(/llama(\d+)-(\d+)-/g, "llama-$1.$2-");
662
+ model = model.replace(/llama(\d+)\.(\d+)-/g, "llama-$1.$2-");
663
+ if (MODEL_ALIASES[model]) {
664
+ return MODEL_ALIASES[model];
665
+ }
666
+ if (!MODEL_PRICING_TABLE[model]) {
667
+ const withoutInstruct = model.replace(/-(instruct|chat|preview)$/, "");
668
+ if (MODEL_PRICING_TABLE[withoutInstruct]) {
669
+ return withoutInstruct;
670
+ }
671
+ if (MODEL_ALIASES[withoutInstruct]) {
672
+ return MODEL_ALIASES[withoutInstruct];
673
+ }
674
+ }
567
675
  return model;
568
676
  }
569
677
  function getModelPricing(modelName) {
@@ -580,6 +688,10 @@ function getModelPricing(modelName) {
580
688
  if (MODEL_PRICING_TABLE[modelName]) {
581
689
  return MODEL_PRICING_TABLE[modelName];
582
690
  }
691
+ const alias = MODEL_ALIASES[modelName.toLowerCase().trim()];
692
+ if (alias && MODEL_PRICING_TABLE[alias]) {
693
+ return MODEL_PRICING_TABLE[alias];
694
+ }
583
695
  return {
584
696
  inputPer1M: 1,
585
697
  outputPer1M: 3,
@@ -858,7 +970,7 @@ function wrapUniversalStream(stream, options = {}, onComplete) {
858
970
  return wrapGeminiStream(stream, options, onComplete);
859
971
  }
860
972
  if (Symbol.asyncIterator in stream) {
861
- if (options.provider === "anthropic") {
973
+ if (options.provider === "anthropic" || options.model?.toLowerCase().includes("claude")) {
862
974
  return wrapAnthropicStream(stream, options, onComplete);
863
975
  }
864
976
  return wrapOpenAIStream(stream, options, onComplete);
@@ -880,7 +992,7 @@ var VibezMeter = class {
880
992
  this.stripeClient = new import_stripe.default(key, {
881
993
  appInfo: {
882
994
  name: "vibezcheck",
883
- version: "0.5.0",
995
+ version: "0.5.3",
884
996
  url: "https://vibezcheck.xyz"
885
997
  }
886
998
  });
@@ -987,10 +1099,20 @@ function createMeter(options = {}) {
987
1099
  }
988
1100
 
989
1101
  // src/ai-sdk/with-billing.ts
990
- function withBilling(model, options = {}) {
1102
+ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
991
1103
  if (!model || typeof model !== "object") {
992
1104
  return model;
993
1105
  }
1106
+ let options = {};
1107
+ if (typeof optionsOrCustomer === "string") {
1108
+ options = { ...extraOptions, customer: optionsOrCustomer };
1109
+ } else if (typeof optionsOrCustomer === "object" && optionsOrCustomer !== null) {
1110
+ if ("userId" in optionsOrCustomer || "email" in optionsOrCustomer || "id" in optionsOrCustomer) {
1111
+ options = { ...extraOptions, customer: optionsOrCustomer };
1112
+ } else {
1113
+ options = { ...optionsOrCustomer, ...extraOptions };
1114
+ }
1115
+ }
994
1116
  const meter = options.meter || createMeter({
995
1117
  apiKey: options.stripeApiKey,
996
1118
  eventName: options.eventName
@@ -1019,17 +1141,19 @@ function withBilling(model, options = {}) {
1019
1141
  };
1020
1142
  const handleUsage = (rawUsage, extraMeta) => {
1021
1143
  if (!rawUsage) return;
1022
- const inputTokens = rawUsage.promptTokens ?? rawUsage.inputTokens ?? 0;
1023
- const outputTokens = rawUsage.completionTokens ?? rawUsage.outputTokens ?? 0;
1024
- const reasoningTokens = rawUsage.reasoningTokens ?? rawUsage.completionTokensDetails?.reasoningTokens ?? rawUsage.outputTokenDetails?.reasoningTokens ?? 0;
1025
- const cachedTokens = rawUsage.promptTokensDetails?.cachedTokens ?? rawUsage.inputTokenDetails?.cachedTokens ?? 0;
1144
+ const inputTokens = rawUsage.promptTokens ?? rawUsage.inputTokens ?? rawUsage.prompt_tokens ?? rawUsage.input_tokens ?? rawUsage.promptTokenCount ?? 0;
1145
+ const outputTokens = rawUsage.completionTokens ?? rawUsage.outputTokens ?? rawUsage.completion_tokens ?? rawUsage.output_tokens ?? rawUsage.candidatesTokenCount ?? 0;
1146
+ const reasoningTokens = rawUsage.reasoningTokens ?? rawUsage.completionTokensDetails?.reasoningTokens ?? rawUsage.outputTokenDetails?.reasoningTokens ?? rawUsage.reasoning_tokens ?? rawUsage.completion_tokens_details?.reasoning_tokens ?? rawUsage.output_token_details?.reasoning_tokens ?? rawUsage.thoughtsTokenCount ?? 0;
1147
+ const cachedTokens = rawUsage.promptTokensDetails?.cachedTokens ?? rawUsage.inputTokenDetails?.cachedTokens ?? rawUsage.cachedTokens ?? rawUsage.cached_tokens ?? rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.input_token_details?.cached_tokens ?? rawUsage.cachedContentTokenCount ?? rawUsage.cache_read_input_tokens ?? 0;
1148
+ const cacheWriteTokens = rawUsage.cacheWriteTokens ?? rawUsage.cache_creation_input_tokens ?? rawUsage.cacheCreationTokens ?? 0;
1026
1149
  const usage = {
1027
1150
  inputTokens,
1028
1151
  outputTokens,
1029
1152
  totalTokens: inputTokens + outputTokens,
1030
1153
  reasoningTokens: reasoningTokens > 0 ? reasoningTokens : void 0,
1031
1154
  visibleOutputTokens: Math.max(0, outputTokens - reasoningTokens),
1032
- cachedTokens: cachedTokens > 0 ? cachedTokens : void 0
1155
+ cachedTokens: cachedTokens > 0 ? cachedTokens : void 0,
1156
+ cacheWriteTokens: cacheWriteTokens > 0 ? cacheWriteTokens : void 0
1033
1157
  };
1034
1158
  const cost = calculateUsageCost(modelId, usage, {
1035
1159
  markupMultiplier: options.pricing?.margin,
@@ -1130,7 +1254,9 @@ function withBilling(model, options = {}) {
1130
1254
  return;
1131
1255
  }
1132
1256
  } catch (err) {
1133
- console.warn(`[vibezcheck] Database record failed safely:`, err?.message || err);
1257
+ if (process.env.NODE_ENV !== "test" && !options.silent) {
1258
+ console.warn(`[vibezcheck] Database record failed safely:`, err?.message || err);
1259
+ }
1134
1260
  }
1135
1261
  };
1136
1262
  if (typeof globalThis !== "undefined" && typeof globalThis.after === "function") {
@@ -1146,7 +1272,9 @@ function withBilling(model, options = {}) {
1146
1272
  try {
1147
1273
  await chargeFn(cost.totalUSD, event);
1148
1274
  } catch (err) {
1149
- console.warn(`[vibezcheck] Custom charge handler failed safely:`, err?.message || err);
1275
+ if (process.env.NODE_ENV !== "test" && !options.silent) {
1276
+ console.warn(`[vibezcheck] Custom charge handler failed safely:`, err?.message || err);
1277
+ }
1150
1278
  }
1151
1279
  };
1152
1280
  if (typeof globalThis !== "undefined" && typeof globalThis.after === "function") {
@@ -1161,7 +1289,9 @@ function withBilling(model, options = {}) {
1161
1289
  try {
1162
1290
  await providerCharge(cost.totalUSD, event);
1163
1291
  } catch (err) {
1164
- console.warn(`[vibezcheck] Payment provider charge failed safely:`, err?.message || err);
1292
+ if (process.env.NODE_ENV !== "test" && !options.silent) {
1293
+ console.warn(`[vibezcheck] Payment provider charge failed safely:`, err?.message || err);
1294
+ }
1165
1295
  }
1166
1296
  };
1167
1297
  if (typeof globalThis !== "undefined" && typeof globalThis.after === "function") {
@@ -1216,14 +1346,19 @@ function withBilling(model, options = {}) {
1216
1346
  const transformStream = new TransformStream({
1217
1347
  transform(chunk, controller) {
1218
1348
  controller.enqueue(chunk);
1219
- if (chunk.type === "text-delta" && chunk.textDelta) {
1220
- accumulatedChars += chunk.textDelta.length;
1221
- } else if (chunk.type === "reasoning" && (chunk.textDelta || chunk.reasoning)) {
1222
- accumulatedChars += (chunk.textDelta || chunk.reasoning || "").length;
1349
+ const delta = chunk.textDelta || chunk.text || chunk.delta;
1350
+ if (delta && typeof delta === "string") {
1351
+ accumulatedChars += delta.length;
1352
+ } else if (chunk.type === "reasoning" || chunk.type === "reasoning-delta") {
1353
+ const reasoning = chunk.reasoning || chunk.textDelta || chunk.text || chunk.delta || "";
1354
+ if (typeof reasoning === "string") {
1355
+ accumulatedChars += reasoning.length;
1356
+ }
1223
1357
  }
1224
- if (chunk.type === "finish" && chunk.usage) {
1358
+ const chunkUsage = chunk.usage || chunk.token_usage || chunk.usageMetadata;
1359
+ if (chunkUsage) {
1225
1360
  streamCompleted = true;
1226
- handleUsage(chunk.usage);
1361
+ handleUsage(chunkUsage);
1227
1362
  }
1228
1363
  },
1229
1364
  flush() {
@@ -1249,13 +1384,29 @@ function withBilling(model, options = {}) {
1249
1384
  if (prop === "doGenerate" && typeof originalValue === "function") {
1250
1385
  return async function(...args) {
1251
1386
  const result = await originalValue.apply(target, args);
1252
- if (result && result.usage) {
1253
- handleUsage(result.usage);
1387
+ const usage = result?.usage || result?.tokenUsage || result?.usageMetadata;
1388
+ if (usage) {
1389
+ handleUsage(usage);
1254
1390
  }
1255
1391
  return result;
1256
1392
  };
1257
1393
  }
1258
1394
  return originalValue;
1395
+ },
1396
+ apply(target, thisArg, argArray) {
1397
+ if (typeof target === "function") {
1398
+ return Reflect.apply(target, thisArg, argArray);
1399
+ }
1400
+ return target;
1401
+ },
1402
+ has(target, prop) {
1403
+ return Reflect.has(target, prop);
1404
+ },
1405
+ ownKeys(target) {
1406
+ return Reflect.ownKeys(target);
1407
+ },
1408
+ getPrototypeOf(target) {
1409
+ return Reflect.getPrototypeOf(target);
1259
1410
  }
1260
1411
  };
1261
1412
  return new Proxy(model, handler);
@@ -1279,8 +1430,18 @@ function createVibezModel(modelOrId, options = {}) {
1279
1430
  providerName = "anthropic";
1280
1431
  } else if (rawId.startsWith("gemini-")) {
1281
1432
  providerName = "google";
1433
+ } else if (rawId.startsWith("deepseek-")) {
1434
+ providerName = "deepseek";
1435
+ } else if (rawId.startsWith("grok-")) {
1436
+ providerName = "xai";
1437
+ } else if (rawId.startsWith("mistral-") || rawId.startsWith("codestral-") || rawId.startsWith("ministral-") || rawId.startsWith("open-mistral") || rawId.startsWith("open-mixtral")) {
1438
+ providerName = "mistral";
1439
+ } else if (rawId.startsWith("llama-") || rawId.startsWith("mixtral-") || rawId.startsWith("gemma") || rawId.startsWith("qwen-")) {
1440
+ providerName = "groq";
1441
+ } else if (rawId.startsWith("command-")) {
1442
+ providerName = "cohere";
1282
1443
  }
1283
- 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;
1444
+ 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) || (providerName === "mistral" ? process.env.MISTRAL_API_KEY : void 0) || (providerName === "groq" ? process.env.GROQ_API_KEY : void 0) || (providerName === "deepseek" ? process.env.DEEPSEEK_API_KEY : void 0) || (providerName === "xai" ? process.env.XAI_API_KEY : void 0) || (providerName === "cohere" ? process.env.COHERE_API_KEY : void 0) || process.env.OPENAI_API_KEY;
1284
1445
  const baseURL = options.baseURL || process.env.AI_GATEWAY_BASE_URL || (providerName === "openai" ? "https://api.openai.com/v1" : void 0);
1285
1446
  let baseModelInstance = null;
1286
1447
  try {
@@ -1317,6 +1478,36 @@ function createVibezModel(modelOrId, options = {}) {
1317
1478
  baseModelInstance = factory(cleanModelId);
1318
1479
  }
1319
1480
  }
1481
+ } else if (providerName === "mistral") {
1482
+ const mod = require("@ai-sdk/mistral");
1483
+ const factory = mod.createMistral || mod.mistral || mod.default?.createMistral || mod.default?.mistral;
1484
+ if (typeof factory === "function") {
1485
+ baseModelInstance = mod.createMistral ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
1486
+ }
1487
+ } else if (providerName === "groq") {
1488
+ const mod = require("@ai-sdk/groq");
1489
+ const factory = mod.createGroq || mod.groq || mod.default?.createGroq || mod.default?.groq;
1490
+ if (typeof factory === "function") {
1491
+ baseModelInstance = mod.createGroq ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
1492
+ }
1493
+ } else if (providerName === "deepseek") {
1494
+ const mod = require("@ai-sdk/deepseek");
1495
+ const factory = mod.createDeepSeek || mod.deepseek || mod.default?.createDeepSeek || mod.default?.deepseek;
1496
+ if (typeof factory === "function") {
1497
+ baseModelInstance = mod.createDeepSeek ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
1498
+ }
1499
+ } else if (providerName === "xai") {
1500
+ const mod = require("@ai-sdk/xai");
1501
+ const factory = mod.createXai || mod.xai || mod.default?.createXai || mod.default?.xai;
1502
+ if (typeof factory === "function") {
1503
+ baseModelInstance = mod.createXai ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
1504
+ }
1505
+ } else if (providerName === "cohere") {
1506
+ const mod = require("@ai-sdk/cohere");
1507
+ const factory = mod.createCohere || mod.cohere || mod.default?.createCohere || mod.default?.cohere;
1508
+ if (typeof factory === "function") {
1509
+ baseModelInstance = mod.createCohere ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
1510
+ }
1320
1511
  }
1321
1512
  } catch {
1322
1513
  baseModelInstance = {