vibezcheck 0.4.2 → 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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +249 -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 +307 -69
  7. package/dist/ai-sdk/index.js.map +1 -1
  8. package/dist/ai-sdk/index.mjs +307 -69
  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 +1433 -0
  13. package/dist/ai-sdk/middleware.js.map +1 -0
  14. package/dist/ai-sdk/middleware.mjs +1396 -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 +1542 -2
  21. package/dist/billing/index.js.map +1 -1
  22. package/dist/billing/index.mjs +1537 -1
  23. package/dist/billing/index.mjs.map +1 -1
  24. package/dist/cli/index.js +59 -7
  25. package/dist/cli/index.js.map +1 -1
  26. package/dist/cli/index.mjs +59 -7
  27. package/dist/cli/index.mjs.map +1 -1
  28. package/dist/{client-ynfWcHX6.d.ts → client-BORmJy8s.d.ts} +1 -1
  29. package/dist/{client-w_hWhQ6g.d.mts → client-CbuXmoXz.d.mts} +1 -1
  30. package/dist/compat/stripe-meter.d.mts +21 -0
  31. package/dist/compat/stripe-meter.d.ts +21 -0
  32. package/dist/compat/stripe-meter.js +1451 -0
  33. package/dist/compat/stripe-meter.js.map +1 -0
  34. package/dist/compat/stripe-meter.mjs +1414 -0
  35. package/dist/compat/stripe-meter.mjs.map +1 -0
  36. package/dist/compat/stripe-provider.d.mts +34 -0
  37. package/dist/compat/stripe-provider.d.ts +34 -0
  38. package/dist/compat/stripe-provider.js +1620 -0
  39. package/dist/compat/stripe-provider.js.map +1 -0
  40. package/dist/compat/stripe-provider.mjs +1587 -0
  41. package/dist/compat/stripe-provider.mjs.map +1 -0
  42. package/dist/compat/token-meter.d.mts +28 -0
  43. package/dist/compat/token-meter.d.ts +28 -0
  44. package/dist/compat/token-meter.js +1320 -0
  45. package/dist/compat/token-meter.js.map +1 -0
  46. package/dist/compat/token-meter.mjs +1283 -0
  47. package/dist/compat/token-meter.mjs.map +1 -0
  48. package/dist/customers/index.d.mts +1 -1
  49. package/dist/customers/index.d.ts +1 -1
  50. package/dist/customers/index.js.map +1 -1
  51. package/dist/customers/index.mjs.map +1 -1
  52. package/dist/index.d.mts +25 -11
  53. package/dist/index.d.ts +25 -11
  54. package/dist/index.js +810 -72
  55. package/dist/index.js.map +1 -1
  56. package/dist/index.mjs +798 -72
  57. package/dist/index.mjs.map +1 -1
  58. package/dist/meter/index.d.mts +2 -2
  59. package/dist/meter/index.d.ts +2 -2
  60. package/dist/meter/index.js +176 -42
  61. package/dist/meter/index.js.map +1 -1
  62. package/dist/meter/index.mjs +176 -42
  63. package/dist/meter/index.mjs.map +1 -1
  64. package/dist/pricing/index.d.mts +15 -4
  65. package/dist/pricing/index.d.ts +15 -4
  66. package/dist/pricing/index.js +165 -29
  67. package/dist/pricing/index.js.map +1 -1
  68. package/dist/pricing/index.mjs +164 -29
  69. package/dist/pricing/index.mjs.map +1 -1
  70. package/dist/react/index.d.mts +46 -2
  71. package/dist/react/index.d.ts +46 -2
  72. package/dist/react/index.js +471 -29
  73. package/dist/react/index.js.map +1 -1
  74. package/dist/react/index.mjs +469 -29
  75. package/dist/react/index.mjs.map +1 -1
  76. package/dist/{types-Mozk4-Mr.d.mts → types-6P71CXAD.d.mts} +16 -6
  77. package/dist/{types-Mozk4-Mr.d.ts → types-6P71CXAD.d.ts} +16 -6
  78. package/dist/with-billing-Bj6Ya_Iy.d.ts +49 -0
  79. package/dist/with-billing-DndWGxL8.d.mts +49 -0
  80. package/package.json +35 -10
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 VibezCheck <dev@vibezcheck.xyz> (https://vibezcheck.xyz)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VibezCheck <dev@vibezcheck.xyz> (https://vibezcheck.xyz)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,273 +1,249 @@
1
- # ⚡ vibezcheck
2
-
3
- > **Give your AI app a financial mind.**
4
- > The declarative 1-line Stripe Billing and Token Metering engine for LLMs. Measure tokens, compute real-time dollar costs, and bill customers with **0ms added latency**.
5
-
6
- [![npm version](https://img.shields.io/npm/v/vibezcheck.svg)](https://npmjs.org/package/vibezcheck)
7
- [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fseeyouin2x5x%2Fvibezcheck-sdk%2Ftree%2Fmain%2Fexamples%2Fnextjs-saas-starter&env=OPENAI_API_KEY,STRIPE_SECRET_KEY,NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY&envDescription=API%20Keys%20for%20OpenAI%20and%20Stripe&project-name=vibezcheck-ai-saas)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
- [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://www.typescriptlang.org/)
10
- [![Tests](https://img.shields.io/badge/Tests-50%20Passed-brightgreen.svg)]()
11
-
12
- ---
13
-
14
- > 🚀 **Want a ready-to-ship template?** Fork our [1-Click Next.js 15 AI SaaS Starter](https://github.com/seeyouin2x5x/vibezcheck-sdk/tree/main/examples/nextjs-saas-starter) with Stripe Checkout, `<VibezReceipt />`, and `<VibezSessionWidget />` pre-configured.
15
-
16
- ## 🍌 The Electric Meter for Artificial Intelligence
17
-
18
- When you turn on the lights in your bedroom, your electric meter spins. When users prompt your AI, **VibezCheck** is the smart meter that counts every word and hidden thought — converting it into pennies with Stripe so your app actually looks out for your margins.
19
-
20
- ### 🛡️ Sane Defaults (Zero Configuration Required)
21
- * **⚡ 0ms Added Latency**: Streams pass directly to your user's browser with zero intermediate proxy buffering.
22
- * **🛡️ Default $0.50 Fuse Box**: Automatically prevents runaway loops without requiring manual ceilings.
23
- * **🛟 In-Flight Abort Trapper**: Captures and bills partial tokens even if a user closes their browser tab mid-stream.
24
- * **🏷️ Automatic 85% Prompt Cache Discounts**: Detects cache hits on Claude 3.7, GPT-4o, and DeepSeek and passes real savings through.
25
- * **🚀 Serverless Lifecycle Protection**: Seamlessly keeps serverless containers alive until telemetry is acknowledged (`after()` / `waitUntil()`).
26
- * **💰 1-Line Profit Margins**: Turn wholesale provider costs into guaranteed net profit with `pricing: { margin: 1.5 }`.
27
- * **🏢 B2B Multi-Tenancy & Customer Metadata**: Pass structured customer profiles with `orgId`, `teamId`, `plan`, `tier`, `role`, and custom metadata.
28
- * **🗄️ Duck-Typed Database Sinks**: Direct auto-syncing to Supabase (`database: supabase`) with zero blast radius.
29
- * **💳 Pluggable Payment Gateways**: Works out of the box with Stripe, Polar (`provider: 'polar'`), or custom internal wallets.
30
- * **🧠 Reasoning Token Aware**: Captures hidden thinking tokens in o3-mini and Claude 3.7 Thinking.
31
- * **🆓 Free Vibe Mode**: Works 100% out of the box in local development with no Stripe account required.
32
-
33
- ---
34
-
35
- ## 📦 Installation
36
-
37
- ```bash
38
- npm install vibezcheck ai @ai-sdk/openai stripe
39
- ```
40
-
41
- ---
42
-
43
- ## ⚡ 1. The 60-Second Quickstart
44
-
45
- ### Backend API Route (`app/api/chat/route.ts`)
46
- ```typescript
47
- import { streamText } from 'ai';
48
- import { vibezcheck } from 'vibezcheck';
49
- import { supabase } from '@/lib/supabase';
50
-
51
- export async function POST(req: Request) {
52
- const { messages, user } = await req.json();
53
-
54
- return streamText({
55
- // ⚡ 1 Line. All 10 sane defaults run automatically.
56
- model: vibezcheck('openai/gpt-4o-mini', {
57
- customer: {
58
- id: user.stripeCustomerId,
59
- userId: user.id,
60
- email: user.email,
61
- orgId: user.organizationId,
62
- plan: 'pro',
63
- },
64
- pricing: { margin: 1.4 }, // 40% profit margin
65
- database: supabase, // Auto-persists token receipts with 0ms latency
66
- }),
67
- messages,
68
- }).toDataStreamResponse();
69
- }
70
- ```
71
-
72
- ### Frontend Chat UI (`app/page.tsx`)
73
- ```tsx
74
- 'use client';
75
- import { useVibezChat, VibezReceipt, VibezSessionWidget } from 'vibezcheck/react';
76
-
77
- export default function ChatPage() {
78
- const { messages, input, handleInputChange, handleSubmit } = useVibezChat();
79
-
80
- return (
81
- <main className="max-w-xl mx-auto py-10 px-4 space-y-6">
82
- {/* 1. Floating live token & dollar speedometer */}
83
- <VibezSessionWidget position="bottom-right" />
84
-
85
- {/* 2. Messages with micro-receipts */}
86
- <div className="space-y-4">
87
- {messages.map((m) => (
88
- <div key={m.id} className="p-4 rounded-2xl bg-white border border-slate-200">
89
- <p className="text-slate-900 text-sm">{m.content}</p>
90
-
91
- {/* Micro-Receipt under assistant answers */}
92
- {m.role === 'assistant' && <VibezReceipt message={m} />}
93
- </div>
94
- ))}
95
- </div>
96
-
97
- <form onSubmit={handleSubmit} className="flex gap-2">
98
- <input
99
- value={input}
100
- onChange={handleInputChange}
101
- placeholder="Ask a question..."
102
- className="flex-1 px-4 py-2 rounded-xl border border-slate-200 text-sm"
103
- />
104
- <button type="submit" className="px-5 py-2 rounded-xl bg-slate-950 text-white font-bold text-sm">
105
- Send
106
- </button>
107
- </form>
108
- </main>
109
- );
110
- }
111
- ```
112
-
113
- ---
114
-
115
- ## 🛠️ Real-World Implementation Patterns
116
-
117
- ### Pattern A: 50% Profit Margin Engine
118
- Turn wholesale provider costs into guaranteed net profit:
119
-
120
- ```typescript
121
- model: vibezcheck('openai/gpt-4o-mini', {
122
- customer: 'sarah@acme.com',
123
- pricing: {
124
- margin: 1.5, // 👈 Cost + 50% margin automatically billed to Stripe!
125
- minimumChargeUSD: 0.01, // 👈 Minimum charge 1 cent per question
126
- },
127
- })
128
- ```
129
-
130
- ---
131
-
132
- ### Pattern B: B2B Multi-Tenancy & Rich Customer Metadata
133
- Track usage by company, workspace, role, and subscription tier:
134
-
135
- ```typescript
136
- model: vibezcheck('openai/gpt-4o', {
137
- customer: {
138
- id: 'cus_stripe_888',
139
- userId: 'usr_123',
140
- email: 'alex@acme.corp',
141
- name: 'Alex Developer',
142
- orgId: 'org_acme_corp',
143
- teamId: 'team_ai_agents',
144
- role: 'admin',
145
- plan: 'enterprise',
146
- tier: 'unlimited',
147
- metadata: {
148
- cost_center: 90210,
149
- department: 'R&D',
150
- },
151
- },
152
- })
153
- ```
154
-
155
- ---
156
-
157
- ### Pattern C: Duck-Typed Database Sinks (Supabase / PostgreSQL)
158
- Save full usage events into your database with **Zero Blast Radius** (DB downtime never crashes the user's stream):
159
-
160
- ```typescript
161
- // Pass initialized Supabase client directly:
162
- model: vibezcheck('gpt-4o', {
163
- customer: user.id,
164
- database: supabase, // Inserts to `vibez_usage` table automatically
165
- })
166
-
167
- // Or specify custom table:
168
- model: vibezcheck('gpt-4o', {
169
- customer: user.id,
170
- database: { client: supabase, table: 'custom_ai_logs' },
171
- })
172
- ```
173
-
174
- ---
175
-
176
- ### Pattern D: Pluggable Payment Providers (Stripe, Polar, Custom)
177
- Switch billing gateways or connect custom internal wallets:
178
-
179
- ```typescript
180
- // Polar.sh provider
181
- model: vibezcheck('gpt-4o', {
182
- customer: user.id,
183
- billing: { provider: 'polar' },
184
- })
185
-
186
- // Custom in-house wallet / coin ledger
187
- model: vibezcheck('gpt-4o', {
188
- customer: user.id,
189
- billing: {
190
- charge: async (costUSD, event) => {
191
- await userWallet.deduct(event.customerId, costUSD);
192
- },
193
- },
194
- })
195
- ```
196
-
197
- ---
198
-
199
- ### Pattern E: Frontier Reasoning Models (Claude 3.7 & o3-mini)
200
- Automatically extracts hidden thinking tokens and applies 85% prompt cache discounts:
201
-
202
- ```typescript
203
- model: vibezcheck('anthropic/claude-3-7-sonnet', {
204
- customer: 'alex@company.com',
205
- maxCostPerCallUSD: 0.75, // Extended ceiling for multi-minute deep reasoning
206
- })
207
- ```
208
-
209
- ---
210
-
211
- ### Pattern F: Unified Agent Tool Call Metering
212
- Bill external tools (web searches, scrapers, Python sandboxes) and LLM streams into one customer invoice:
213
-
214
- ```typescript
215
- // app/api/agent/route.ts
216
- import { generateText, tool } from 'ai';
217
- import { vibezcheck } from 'vibezcheck';
218
- import { z } from 'zod';
219
-
220
- export async function POST(req: Request) {
221
- const { prompt, customer = 'alex@company.com' } = await req.json();
222
-
223
- // Create unified customer session
224
- const session = vibezcheck.session({ customer });
225
-
226
- const result = await generateText({
227
- model: session.model('openai/gpt-4o-mini'),
228
- tools: {
229
- searchGoogle: tool({
230
- description: 'Live Google Search',
231
- parameters: z.object({ query: z.string() }),
232
- execute: async ({ query }) => {
233
- // ⚡ Bill non-LLM tool execution ($0.01) into the same customer balance
234
- await session.trackTool('google_search', { costUSD: 0.01 });
235
- return `Search results for: ${query}`;
236
- },
237
- }),
238
- },
239
- prompt,
240
- });
241
-
242
- return Response.json(result);
243
- }
244
- ```
245
-
246
- ---
247
-
248
- ## 🎨 React UI Suite (`vibezcheck/react`)
249
-
250
- * **`useVibezChat`**: 1-hook drop-in chat streaming with live session cost sync.
251
- * **`<VibezReceipt />`**: Micro-badge rendered below assistant responses (*"⚡ gpt-4o-mini • 342 tokens • $0.0005 • Verified by VibezCheck"*).
252
- * **`<VibezSessionWidget />`**: Floating live token & dollar speedometer in the screen corner.
253
- * **`<VibezBillingModal />`**: Drop-in 1-click Stripe Checkout top-up modal.
254
-
255
- ---
256
-
257
- ## 🌿 Codebase Token Leak Scanner (`npx vibezcheck audit`)
258
-
259
- Audit your project in under 50ms for unmetered AI endpoints and missing runaway loop fuses:
260
-
261
- ```bash
262
- npx vibezcheck audit
263
- ```
264
-
265
- * **Kind & Minimalist**: Zero heavy AST dependencies; outputs calm clarity instead of intimidating lint errors.
266
- * **Safe `--fix`**: Automatically wraps raw provider calls in `vibezcheck()` with `.bak` backups.
267
- * **GitHub Actions Ready**: Run `npx vibezcheck audit --ci` to fail PRs that accidentally introduce unmetered routes.
268
-
269
- ---
270
-
271
- ## 📄 License
272
-
273
- MIT © [VibezCheck](https://vibezcheck.xyz)
1
+ # ✦ VibezCheck
2
+
3
+ > **The 1-Line Token Meter & Real-Time Billing Engine for AI.**
4
+ > Track tokens, compute real-time dollar costs, set profit margins, and bill customers with **0ms added latency**.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/vibezcheck.svg)](https://npmjs.org/package/vibezcheck)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://www.typescriptlang.org/)
9
+ [![Tests](https://img.shields.io/badge/Tests-62%20Passed-brightgreen.svg)]()
10
+
11
+ ---
12
+
13
+ ### The 2-Line Promise
14
+
15
+ ```typescript
16
+ // 1. Server: Wrap your model with automated billing
17
+ const model = vibezcheck('openai/gpt-4o', { customer: 'cus_alex' });
18
+
19
+ // 2. Client: Drop in the financial HUD
20
+ <VibezCheck messages={messages} />
21
+ ```
22
+
23
+ ---
24
+
25
+ ## 🚀 Features
26
+
27
+ * **⚡ 0ms Added Latency**: Direct transparent proxy stream; no external server redirects or buffering.
28
+ * **🛡️ Built-in $0.50 Circuit Breaker**: Prevents infinite loops and runaway bills automatically.
29
+ * **🛟 In-Flight Abort Trapper**: Catches and bills tokens even if the customer closes their tab mid-stream.
30
+ * **🪙 BigInt Nano-USD Precision**: Sub-cent financial math ($1 = $10^9$ Nano-USD) eliminating IEEE 754 float drift.
31
+ * **💰 1-Line Profit Margins**: Turn wholesale API costs into retail profits with `pricing: { margin: 1.5 }` (+50% profit).
32
+ * **🆓 Zero-DB Dev Mode**: Run locally on `localhost:3000` with NO database and NO Stripe keys required.
33
+ * **💳 Pluggable SaaS Billing**: Top-ups, checkout sessions, customer portal, and user API keys (`vz_live_...`).
34
+ * **🤖 Multi-Tool Agent Sessions**: Cumulative session budgets across models, Python sandboxes, and web scrapers.
35
+ * **🔄 100% Drop-In Polyfills**: Direct replacement for `@stripe/ai-sdk/meter`, `@stripe/ai-sdk/provider`, and `@stripe/token-meter`.
36
+
37
+ ---
38
+
39
+ ## 📦 Installation
40
+
41
+ ```bash
42
+ npm install vibezcheck ai @ai-sdk/openai @ai-sdk/react stripe
43
+ ```
44
+
45
+ ---
46
+
47
+ ## ⚡ Quickstart: Zero-DB Dev Mode to Production
48
+
49
+ ### 1. Next.js 15 API Route (`app/api/chat/route.ts`)
50
+
51
+ ```typescript
52
+ import { streamText } from 'ai';
53
+ import { openai } from '@ai-sdk/openai';
54
+ import { vibezcheck } from 'vibezcheck';
55
+
56
+ export async function POST(req: Request) {
57
+ const { messages } = await req.json();
58
+
59
+ const result = streamText({
60
+ // Wrap any AI SDK model or use string identifier
61
+ model: vibezcheck(openai('gpt-4o-mini'), {
62
+ customer: 'user_alex@example.com', // Stripe customer ID or user email
63
+ pricing: { margin: 1.3 }, // +30% profit margin
64
+ maxCostPerCallUSD: 0.50, // Safety fuse box
65
+ }),
66
+ messages,
67
+ });
68
+
69
+ return result.toDataStreamResponse();
70
+ }
71
+ ```
72
+
73
+ ### 2. Frontend React Client (`app/page.tsx`)
74
+
75
+ ```tsx
76
+ 'use client';
77
+
78
+ import { useChat } from '@ai-sdk/react';
79
+ import { useState } from 'react';
80
+ import { VibezCheck } from 'vibezcheck/ui';
81
+
82
+ export default function Chat() {
83
+ const [input, setInput] = useState('');
84
+ const { messages, sendMessage } = useChat();
85
+
86
+ return (
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
+ >
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"
109
+ value={input}
110
+ placeholder="Say something..."
111
+ onChange={e => setInput(e.currentTarget.value)}
112
+ />
113
+ </form>
114
+
115
+ {/* ✦ 1-Line Token Meter & Financial HUD: Works with zero database & zero Stripe in Dev Mode */}
116
+ <VibezCheck messages={messages} />
117
+ </div>
118
+ );
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## 💳 Commercial SaaS Use Cases
125
+
126
+ ### 1. Credit Wallet Top-Ups & Checkout (`BillingHelper`)
127
+
128
+ ```typescript
129
+ import { BillingHelper } from 'vibezcheck';
130
+
131
+ const billing = new BillingHelper({ apiKey: process.env.STRIPE_SECRET_KEY });
132
+
133
+ // Customer purchases $20 in AI usage credits
134
+ export async function POST(req: Request) {
135
+ const { customerId } = await req.json();
136
+
137
+ const checkoutUrl = await billing.createTopUpSession({
138
+ customerId,
139
+ amountCents: 2000, // $20.00
140
+ returnUrl: 'https://myapp.com/dashboard',
141
+ });
142
+
143
+ return Response.json({ url: checkoutUrl });
144
+ }
145
+ ```
146
+
147
+ ### 2. Customer API Keys (`ApiKeyAuth`)
148
+
149
+ Issue customer API keys (`vz_live_...`) backed by Stripe customer metadata—zero database required:
150
+
151
+ ```typescript
152
+ import { ApiKeyAuth } from 'vibezcheck';
153
+ import Stripe from 'stripe';
154
+
155
+ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
156
+ const auth = new ApiKeyAuth(stripe);
157
+
158
+ // 1. Generate key for customer
159
+ const { apiKey } = await auth.createKey({
160
+ customerId: 'cus_123',
161
+ name: 'Production Worker Key',
162
+ });
163
+ // => "vz_live_9f83b2..."
164
+
165
+ // 2. Authenticate API requests in middleware
166
+ export async function middleware(req: Request) {
167
+ const token = req.headers.get('Authorization')?.replace('Bearer ', '');
168
+ const verification = await auth.verifyKey(token);
169
+
170
+ if (!verification.valid) {
171
+ return new Response('Unauthorized', { status: 401 });
172
+ }
173
+
174
+ // verification.customerId is verified against Stripe!
175
+ }
176
+ ```
177
+
178
+ ### 3. Multi-Tool Agent Sessions (`AgentSession`)
179
+
180
+ Set a hard $1.00 session budget across multiple LLM steps and external tools:
181
+
182
+ ```typescript
183
+ import { AgentSession, wrapTool } from 'vibezcheck';
184
+ import { openai } from '@ai-sdk/openai';
185
+
186
+ const session = new AgentSession({
187
+ customer: 'cus_agent_user',
188
+ sessionBudgetUSD: 1.00, // Hard ceiling for entire session
189
+ });
190
+
191
+ // Wrap external tools with financial tracking
192
+ const webSearchTool = wrapTool({
193
+ name: 'web_search',
194
+ costUSD: 0.01,
195
+ execute: async ({ query }) => fetchSearch(query),
196
+ });
197
+
198
+ // Run LLM model bound to this session
199
+ const sessionModel = session.model(openai('gpt-4o'));
200
+ ```
201
+
202
+ ---
203
+
204
+ ## 🔄 100% Drop-In Compatibility with `@stripe/ai-sdk`
205
+
206
+ If you are migrating from `@stripe/ai-sdk` or `@stripe/token-meter`, swap your imports:
207
+
208
+ ```typescript
209
+ // Replace: import { meteredModel } from '@stripe/ai-sdk/meter';
210
+ import { meteredModel } from 'vibezcheck/stripe/meter';
211
+
212
+ // Replace: import { stripe } from '@stripe/ai-sdk/provider';
213
+ import { stripe } from 'vibezcheck/stripe/provider';
214
+
215
+ // Replace: import { createTokenMeter } from '@stripe/token-meter';
216
+ import { createTokenMeter } from 'vibezcheck/stripe/token-meter';
217
+ ```
218
+
219
+ ---
220
+
221
+ ## 🛡️ Route Auditor CLI
222
+
223
+ Audit your codebase to detect unmetered AI endpoints before shipping to production:
224
+
225
+ ```bash
226
+ npx vibezcheck audit
227
+ ```
228
+
229
+ ### CI/CD Mode
230
+ Fail the build if unmetered AI routes are detected:
231
+ ```bash
232
+ npx vibezcheck audit --ci
233
+ ```
234
+
235
+ ---
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
+
247
+ ## 📄 License
248
+
249
+ MIT © [VibezCheck](https://vibezcheck.xyz)
package/bin/vibezcheck.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
2
-
3
- // Forward execution to compiled CLI entrypoint
4
- require('../dist/cli/index.js');
1
+ #!/usr/bin/env node
2
+
3
+ // Forward execution to compiled CLI entrypoint
4
+ require('../dist/cli/index.js');