vibezcheck 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +230 -273
- package/bin/vibezcheck.js +4 -4
- package/dist/ai-sdk/index.d.mts +28 -59
- package/dist/ai-sdk/index.d.ts +28 -59
- package/dist/ai-sdk/index.js +79 -32
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +79 -32
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/ai-sdk/middleware.d.mts +15 -0
- package/dist/ai-sdk/middleware.d.ts +15 -0
- package/dist/ai-sdk/middleware.js +1280 -0
- package/dist/ai-sdk/middleware.js.map +1 -0
- package/dist/ai-sdk/middleware.mjs +1243 -0
- package/dist/ai-sdk/middleware.mjs.map +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs.map +1 -1
- package/dist/billing/index.d.mts +90 -1
- package/dist/billing/index.d.ts +90 -1
- package/dist/billing/index.js +1391 -2
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +1386 -1
- package/dist/billing/index.mjs.map +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-ynfWcHX6.d.ts → client-CJ2Dj8ID.d.ts} +1 -1
- package/dist/{client-w_hWhQ6g.d.mts → client-Dmwb3hQt.d.mts} +1 -1
- package/dist/compat/stripe-meter.d.mts +21 -0
- package/dist/compat/stripe-meter.d.ts +21 -0
- package/dist/compat/stripe-meter.js +1281 -0
- package/dist/compat/stripe-meter.js.map +1 -0
- package/dist/compat/stripe-meter.mjs +1244 -0
- package/dist/compat/stripe-meter.mjs.map +1 -0
- package/dist/compat/stripe-provider.d.mts +54 -0
- package/dist/compat/stripe-provider.d.ts +54 -0
- package/dist/compat/stripe-provider.js +1304 -0
- package/dist/compat/stripe-provider.js.map +1 -0
- package/dist/compat/stripe-provider.mjs +1264 -0
- package/dist/compat/stripe-provider.mjs.map +1 -0
- package/dist/compat/token-meter.d.mts +16 -0
- package/dist/compat/token-meter.d.ts +16 -0
- package/dist/compat/token-meter.js +1095 -0
- package/dist/compat/token-meter.js.map +1 -0
- package/dist/compat/token-meter.mjs +1058 -0
- package/dist/compat/token-meter.mjs.map +1 -0
- package/dist/customers/index.d.mts +1 -1
- package/dist/customers/index.d.ts +1 -1
- package/dist/customers/index.js.map +1 -1
- package/dist/customers/index.mjs.map +1 -1
- package/dist/index.d.mts +22 -11
- package/dist/index.d.ts +22 -11
- package/dist/index.js +269 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -33
- package/dist/index.mjs.map +1 -1
- package/dist/meter/index.d.mts +2 -2
- package/dist/meter/index.d.ts +2 -2
- package/dist/meter/index.js +44 -22
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +44 -22
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +5 -2
- package/dist/pricing/index.d.ts +5 -2
- package/dist/pricing/index.js +43 -21
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +43 -21
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +46 -2
- package/dist/react/index.d.ts +46 -2
- package/dist/react/index.js +351 -21
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +349 -21
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-Mozk4-Mr.d.mts → types-BVGqbKnY.d.mts} +6 -0
- package/dist/{types-Mozk4-Mr.d.ts → types-BVGqbKnY.d.ts} +6 -0
- package/dist/with-billing-CDqKIAQ6.d.ts +47 -0
- package/dist/with-billing-mci2vtFS.d.mts +47 -0
- package/package.json +26 -1
package/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
|
-
#
|
|
2
|
-
|
|
3
|
-
> **
|
|
4
|
-
>
|
|
5
|
-
|
|
6
|
-
[](https://npmjs.org/package/vibezcheck)
|
|
7
|
-
[
|
|
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
|
+
[](https://npmjs.org/package/vibezcheck)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[]()
|
|
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');
|