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
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,230 @@
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 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
+ import { useChat } from 'ai/react';
78
+ import { VibezCheck } from 'vibezcheck/ui';
79
+
80
+ export default function ChatPage() {
81
+ const { messages, input, handleInputChange, handleSubmit } = useChat();
82
+
83
+ 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">
95
+ <input
96
+ value={input}
97
+ onChange={handleInputChange}
98
+ placeholder="Ask anything..."
99
+ className="flex-1 p-2 border rounded-lg"
100
+ />
101
+ <button type="submit" className="px-4 py-2 bg-blue-600 text-white rounded-lg">
102
+ Send
103
+ </button>
104
+ </form>
105
+
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>
109
+ );
110
+ }
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 💳 Commercial SaaS Use Cases
116
+
117
+ ### 1. Credit Wallet Top-Ups & Checkout (`BillingHelper`)
118
+
119
+ ```typescript
120
+ import { BillingHelper } from 'vibezcheck';
121
+
122
+ const billing = new BillingHelper({ apiKey: process.env.STRIPE_SECRET_KEY });
123
+
124
+ // Customer purchases $20 in AI usage credits
125
+ export async function POST(req: Request) {
126
+ const { customerId } = await req.json();
127
+
128
+ const checkoutUrl = await billing.createTopUpSession({
129
+ customerId,
130
+ amountCents: 2000, // $20.00
131
+ returnUrl: 'https://myapp.com/dashboard',
132
+ });
133
+
134
+ return Response.json({ url: checkoutUrl });
135
+ }
136
+ ```
137
+
138
+ ### 2. Customer API Keys (`ApiKeyAuth`)
139
+
140
+ Issue customer API keys (`vz_live_...`) backed by Stripe customer metadata—zero database required:
141
+
142
+ ```typescript
143
+ import { ApiKeyAuth } from 'vibezcheck';
144
+ import Stripe from 'stripe';
145
+
146
+ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
147
+ const auth = new ApiKeyAuth(stripe);
148
+
149
+ // 1. Generate key for customer
150
+ const { apiKey } = await auth.createKey({
151
+ customerId: 'cus_123',
152
+ name: 'Production Worker Key',
153
+ });
154
+ // => "vz_live_9f83b2..."
155
+
156
+ // 2. Authenticate API requests in middleware
157
+ export async function middleware(req: Request) {
158
+ const token = req.headers.get('Authorization')?.replace('Bearer ', '');
159
+ const verification = await auth.verifyKey(token);
160
+
161
+ if (!verification.valid) {
162
+ return new Response('Unauthorized', { status: 401 });
163
+ }
164
+
165
+ // verification.customerId is verified against Stripe!
166
+ }
167
+ ```
168
+
169
+ ### 3. Multi-Tool Agent Sessions (`AgentSession`)
170
+
171
+ Set a hard $1.00 session budget across multiple LLM steps and external tools:
172
+
173
+ ```typescript
174
+ import { AgentSession, wrapTool } from 'vibezcheck';
175
+ import { openai } from '@ai-sdk/openai';
176
+
177
+ const session = new AgentSession({
178
+ customer: 'cus_agent_user',
179
+ sessionBudgetUSD: 1.00, // Hard ceiling for entire session
180
+ });
181
+
182
+ // Wrap external tools with financial tracking
183
+ const webSearchTool = wrapTool({
184
+ name: 'web_search',
185
+ costUSD: 0.01,
186
+ execute: async ({ query }) => fetchSearch(query),
187
+ });
188
+
189
+ // Run LLM model bound to this session
190
+ const sessionModel = session.model(openai('gpt-4o'));
191
+ ```
192
+
193
+ ---
194
+
195
+ ## 🔄 100% Drop-In Compatibility with `@stripe/ai-sdk`
196
+
197
+ If you are migrating from `@stripe/ai-sdk` or `@stripe/token-meter`, swap your imports:
198
+
199
+ ```typescript
200
+ // Replace: import { meteredModel } from '@stripe/ai-sdk/meter';
201
+ import { meteredModel } from 'vibezcheck/stripe/meter';
202
+
203
+ // Replace: import { stripe } from '@stripe/ai-sdk/provider';
204
+ import { stripe } from 'vibezcheck/stripe/provider';
205
+
206
+ // Replace: import { createTokenMeter } from '@stripe/token-meter';
207
+ import { createTokenMeter } from 'vibezcheck/stripe/token-meter';
208
+ ```
209
+
210
+ ---
211
+
212
+ ## 🛡️ Route Auditor CLI
213
+
214
+ Audit your codebase to detect unmetered AI endpoints before shipping to production:
215
+
216
+ ```bash
217
+ npx vibezcheck audit
218
+ ```
219
+
220
+ ### CI/CD Mode
221
+ Fail the build if unmetered AI routes are detected:
222
+ ```bash
223
+ npx vibezcheck audit --ci
224
+ ```
225
+
226
+ ---
227
+
228
+ ## 📄 License
229
+
230
+ 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');