vibezcheck 0.4.1 → 0.4.2
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/README.md +273 -203
- package/dist/ai-sdk/index.d.mts +6 -4
- package/dist/ai-sdk/index.d.ts +6 -4
- package/dist/ai-sdk/index.js +184 -22
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +184 -22
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-kJN_Znan.d.ts → client-w_hWhQ6g.d.mts} +4 -2
- package/dist/{client--iq93FQg.d.mts → client-ynfWcHX6.d.ts} +4 -2
- package/dist/customers/index.d.mts +30 -4
- package/dist/customers/index.d.ts +30 -4
- package/dist/customers/index.js +108 -8
- package/dist/customers/index.js.map +1 -1
- package/dist/customers/index.mjs +106 -7
- package/dist/customers/index.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +238 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +237 -28
- 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 +95 -16
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +95 -16
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +1 -1
- package/dist/pricing/index.d.ts +1 -1
- package/dist/react/index.d.mts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/{types-Zbzxg-Ka.d.mts → types-Mozk4-Mr.d.mts} +70 -12
- package/dist/{types-Zbzxg-Ka.d.ts → types-Mozk4-Mr.d.ts} +70 -12
- package/package.json +161 -153
package/README.md
CHANGED
|
@@ -1,203 +1,273 @@
|
|
|
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
|
-
[](https://npmjs.org/package/vibezcheck)
|
|
7
|
-
[](https://npmjs.org/package/vibezcheck)
|
|
7
|
+
[](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
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
[]()
|
|
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)
|
package/dist/ai-sdk/index.d.mts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig,
|
|
2
|
-
import { V as VibezMeter } from '../client
|
|
1
|
+
import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig, g as PricingConfig, e as InlineRateConfig, U as UsageEvent } from '../types-Mozk4-Mr.mjs';
|
|
2
|
+
import { V as VibezMeter } from '../client-w_hWhQ6g.mjs';
|
|
3
3
|
import 'stripe';
|
|
4
4
|
|
|
5
5
|
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
|
-
/** Customer email, user ID, or
|
|
6
|
+
/** Customer email, user ID, or rich customer object with metadata */
|
|
7
7
|
customer?: CustomerParam;
|
|
8
8
|
/** Direct Stripe customer ID */
|
|
9
9
|
customerId?: string;
|
|
10
|
-
/** Billing mode configuration (postpaid vs prepaid) */
|
|
10
|
+
/** Billing mode configuration (Universal Auto-Debit, postpaid vs prepaid, pluggable providers) */
|
|
11
11
|
billing?: BillingConfig;
|
|
12
12
|
/** Profit margin & minimum charge configuration */
|
|
13
13
|
pricing?: PricingConfig;
|
|
14
14
|
/** 1-line inline pricing rate card */
|
|
15
15
|
rate?: InlineRateConfig;
|
|
16
|
+
/** Pluggable Database Sink (Supabase, Postgres, Firebase, or 1-line callback) */
|
|
17
|
+
database?: any | ((event: UsageEvent) => void | Promise<void>);
|
|
16
18
|
/** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
|
|
17
19
|
captureOnAbort?: boolean;
|
|
18
20
|
/** Execution runtime environment (default: 'auto') */
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig,
|
|
2
|
-
import { V as VibezMeter } from '../client-
|
|
1
|
+
import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig, g as PricingConfig, e as InlineRateConfig, U as UsageEvent } from '../types-Mozk4-Mr.js';
|
|
2
|
+
import { V as VibezMeter } from '../client-ynfWcHX6.js';
|
|
3
3
|
import 'stripe';
|
|
4
4
|
|
|
5
5
|
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
|
-
/** Customer email, user ID, or
|
|
6
|
+
/** Customer email, user ID, or rich customer object with metadata */
|
|
7
7
|
customer?: CustomerParam;
|
|
8
8
|
/** Direct Stripe customer ID */
|
|
9
9
|
customerId?: string;
|
|
10
|
-
/** Billing mode configuration (postpaid vs prepaid) */
|
|
10
|
+
/** Billing mode configuration (Universal Auto-Debit, postpaid vs prepaid, pluggable providers) */
|
|
11
11
|
billing?: BillingConfig;
|
|
12
12
|
/** Profit margin & minimum charge configuration */
|
|
13
13
|
pricing?: PricingConfig;
|
|
14
14
|
/** 1-line inline pricing rate card */
|
|
15
15
|
rate?: InlineRateConfig;
|
|
16
|
+
/** Pluggable Database Sink (Supabase, Postgres, Firebase, or 1-line callback) */
|
|
17
|
+
database?: any | ((event: UsageEvent) => void | Promise<void>);
|
|
16
18
|
/** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
|
|
17
19
|
captureOnAbort?: boolean;
|
|
18
20
|
/** Execution runtime environment (default: 'auto') */
|