vibezcheck 0.4.1 → 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 +140 -113
- package/bin/vibezcheck.js +4 -4
- package/dist/ai-sdk/index.d.mts +28 -57
- package/dist/ai-sdk/index.d.ts +28 -57
- package/dist/ai-sdk/index.js +262 -53
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +262 -53
- 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 +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--iq93FQg.d.mts → client-CJ2Dj8ID.d.ts} +4 -2
- package/dist/{client-kJN_Znan.d.ts → client-Dmwb3hQt.d.mts} +4 -2
- 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 +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 +23 -12
- package/dist/index.d.ts +23 -12
- package/dist/index.js +506 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +501 -60
- 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 +138 -37
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +138 -37
- 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-Zbzxg-Ka.d.mts → types-BVGqbKnY.d.mts} +76 -12
- package/dist/{types-Zbzxg-Ka.d.ts → types-BVGqbKnY.d.ts} +76 -12
- package/dist/with-billing-CDqKIAQ6.d.ts +47 -0
- package/dist/with-billing-mci2vtFS.d.mts +47 -0
- package/package.json +186 -153
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,29 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ✦ VibezCheck
|
|
2
2
|
|
|
3
|
-
> **
|
|
4
|
-
>
|
|
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
5
|
|
|
6
6
|
[](https://npmjs.org/package/vibezcheck)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
|
-
[]()
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### The 2-Line Promise
|
|
14
14
|
|
|
15
|
-
|
|
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
|
|
16
26
|
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* **🆓 Free Vibe Mode**: Works 100% out of the box in local development with no Stripe account required.
|
|
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`.
|
|
27
36
|
|
|
28
37
|
---
|
|
29
38
|
|
|
@@ -35,45 +44,49 @@ npm install vibezcheck ai @ai-sdk/openai stripe
|
|
|
35
44
|
|
|
36
45
|
---
|
|
37
46
|
|
|
38
|
-
## ⚡
|
|
47
|
+
## ⚡ Quickstart: Zero-DB Dev Mode to Production
|
|
48
|
+
|
|
49
|
+
### 1. Next.js 15 API Route (`app/api/chat/route.ts`)
|
|
39
50
|
|
|
40
|
-
### Backend API Route (`app/api/chat/route.ts`)
|
|
41
51
|
```typescript
|
|
42
52
|
import { streamText } from 'ai';
|
|
53
|
+
import { openai } from '@ai-sdk/openai';
|
|
43
54
|
import { vibezcheck } from 'vibezcheck';
|
|
44
55
|
|
|
45
56
|
export async function POST(req: Request) {
|
|
46
|
-
const { messages
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
model: vibezcheck('
|
|
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
|
+
}),
|
|
51
66
|
messages,
|
|
52
|
-
})
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return result.toDataStreamResponse();
|
|
53
70
|
}
|
|
54
71
|
```
|
|
55
72
|
|
|
56
|
-
### Frontend
|
|
73
|
+
### 2. Frontend React Client (`app/page.tsx`)
|
|
74
|
+
|
|
57
75
|
```tsx
|
|
58
76
|
'use client';
|
|
59
|
-
import {
|
|
77
|
+
import { useChat } from 'ai/react';
|
|
78
|
+
import { VibezCheck } from 'vibezcheck/ui';
|
|
60
79
|
|
|
61
80
|
export default function ChatPage() {
|
|
62
|
-
const { messages, input, handleInputChange, handleSubmit } =
|
|
81
|
+
const { messages, input, handleInputChange, handleSubmit } = useChat();
|
|
63
82
|
|
|
64
83
|
return (
|
|
65
|
-
<main className="max-w-
|
|
66
|
-
|
|
67
|
-
<VibezSessionWidget position="bottom-right" />
|
|
68
|
-
|
|
69
|
-
{/* 2. Messages with micro-receipts */}
|
|
70
|
-
<div className="space-y-4">
|
|
84
|
+
<main className="max-w-2xl mx-auto p-6 space-y-4">
|
|
85
|
+
<div className="space-y-3">
|
|
71
86
|
{messages.map((m) => (
|
|
72
|
-
<div key={m.id} className="p-
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
{/* Micro-Receipt under assistant answers */}
|
|
76
|
-
{m.role === 'assistant' && <VibezReceipt message={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>
|
|
77
90
|
</div>
|
|
78
91
|
))}
|
|
79
92
|
</div>
|
|
@@ -82,13 +95,16 @@ export default function ChatPage() {
|
|
|
82
95
|
<input
|
|
83
96
|
value={input}
|
|
84
97
|
onChange={handleInputChange}
|
|
85
|
-
placeholder="Ask
|
|
86
|
-
className="flex-1
|
|
98
|
+
placeholder="Ask anything..."
|
|
99
|
+
className="flex-1 p-2 border rounded-lg"
|
|
87
100
|
/>
|
|
88
|
-
<button type="submit" className="px-
|
|
101
|
+
<button type="submit" className="px-4 py-2 bg-blue-600 text-white rounded-lg">
|
|
89
102
|
Send
|
|
90
103
|
</button>
|
|
91
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} />
|
|
92
108
|
</main>
|
|
93
109
|
);
|
|
94
110
|
}
|
|
@@ -96,108 +112,119 @@ export default function ChatPage() {
|
|
|
96
112
|
|
|
97
113
|
---
|
|
98
114
|
|
|
99
|
-
##
|
|
115
|
+
## 💳 Commercial SaaS Use Cases
|
|
100
116
|
|
|
101
|
-
###
|
|
102
|
-
Turn wholesale provider costs into guaranteed net profit:
|
|
117
|
+
### 1. Credit Wallet Top-Ups & Checkout (`BillingHelper`)
|
|
103
118
|
|
|
104
119
|
```typescript
|
|
105
|
-
|
|
106
|
-
customer: 'sarah@acme.com',
|
|
107
|
-
pricing: {
|
|
108
|
-
margin: 1.5, // 👈 Cost + 50% margin automatically billed to Stripe!
|
|
109
|
-
minimumChargeUSD: 0.01, // 👈 Minimum charge 1 cent per question
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
```
|
|
120
|
+
import { BillingHelper } from 'vibezcheck';
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
const billing = new BillingHelper({ apiKey: process.env.STRIPE_SECRET_KEY });
|
|
115
123
|
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
// Customer purchases $20 in AI usage credits
|
|
125
|
+
export async function POST(req: Request) {
|
|
126
|
+
const { customerId } = await req.json();
|
|
118
127
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
}
|
|
128
136
|
```
|
|
129
137
|
|
|
130
|
-
|
|
138
|
+
### 2. Customer API Keys (`ApiKeyAuth`)
|
|
131
139
|
|
|
132
|
-
|
|
133
|
-
Automatically extracts hidden thinking tokens and applies 85% prompt cache discounts:
|
|
140
|
+
Issue customer API keys (`vz_live_...`) backed by Stripe customer metadata—zero database required:
|
|
134
141
|
|
|
135
142
|
```typescript
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
maxCostPerCallUSD: 0.75, // Extended ceiling for multi-minute deep reasoning
|
|
139
|
-
})
|
|
140
|
-
```
|
|
143
|
+
import { ApiKeyAuth } from 'vibezcheck';
|
|
144
|
+
import Stripe from 'stripe';
|
|
141
145
|
|
|
142
|
-
|
|
146
|
+
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
|
|
147
|
+
const auth = new ApiKeyAuth(stripe);
|
|
143
148
|
|
|
144
|
-
|
|
145
|
-
|
|
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..."
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
import { z } from 'zod';
|
|
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);
|
|
152
160
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// Create unified customer session
|
|
157
|
-
const session = vibezcheck.session({ customer });
|
|
158
|
-
|
|
159
|
-
const result = await generateText({
|
|
160
|
-
model: session.model('openai/gpt-4o-mini'),
|
|
161
|
-
tools: {
|
|
162
|
-
searchGoogle: tool({
|
|
163
|
-
description: 'Live Google Search',
|
|
164
|
-
parameters: z.object({ query: z.string() }),
|
|
165
|
-
execute: async ({ query }) => {
|
|
166
|
-
// ⚡ Bill non-LLM tool execution ($0.01) into the same customer balance
|
|
167
|
-
await session.trackTool('google_search', { costUSD: 0.01 });
|
|
168
|
-
return `Search results for: ${query}`;
|
|
169
|
-
},
|
|
170
|
-
}),
|
|
171
|
-
},
|
|
172
|
-
prompt,
|
|
173
|
-
});
|
|
161
|
+
if (!verification.valid) {
|
|
162
|
+
return new Response('Unauthorized', { status: 401 });
|
|
163
|
+
}
|
|
174
164
|
|
|
175
|
-
|
|
165
|
+
// verification.customerId is verified against Stripe!
|
|
176
166
|
}
|
|
177
167
|
```
|
|
178
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
|
+
|
|
179
193
|
---
|
|
180
194
|
|
|
181
|
-
|
|
182
|
-
|
|
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:
|
|
183
198
|
|
|
184
199
|
```typescript
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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';
|
|
188
208
|
```
|
|
189
209
|
|
|
190
210
|
---
|
|
191
211
|
|
|
192
|
-
##
|
|
212
|
+
## 🛡️ Route Auditor CLI
|
|
213
|
+
|
|
214
|
+
Audit your codebase to detect unmetered AI endpoints before shipping to production:
|
|
193
215
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
```
|
|
198
225
|
|
|
199
226
|
---
|
|
200
227
|
|
|
201
228
|
## 📄 License
|
|
202
229
|
|
|
203
|
-
MIT © [VibezCheck](https://vibezcheck.
|
|
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');
|
package/dist/ai-sdk/index.d.mts
CHANGED
|
@@ -1,52 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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';
|
|
3
5
|
import 'stripe';
|
|
4
6
|
|
|
5
|
-
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
|
-
/** Customer email, user ID, or Stripe customer ID */
|
|
7
|
-
customer?: CustomerParam;
|
|
8
|
-
/** Direct Stripe customer ID */
|
|
9
|
-
customerId?: string;
|
|
10
|
-
/** Billing mode configuration (postpaid vs prepaid) */
|
|
11
|
-
billing?: BillingConfig;
|
|
12
|
-
/** Profit margin & minimum charge configuration */
|
|
13
|
-
pricing?: PricingConfig;
|
|
14
|
-
/** 1-line inline pricing rate card */
|
|
15
|
-
rate?: InlineRateConfig;
|
|
16
|
-
/** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
|
|
17
|
-
captureOnAbort?: boolean;
|
|
18
|
-
/** Execution runtime environment (default: 'auto') */
|
|
19
|
-
runtime?: 'auto' | 'serverless' | 'edge' | 'node';
|
|
20
|
-
/** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
|
|
21
|
-
stripeApiKey?: string;
|
|
22
|
-
/** Existing VibezMeter instance (optional) */
|
|
23
|
-
meter?: VibezMeter;
|
|
24
|
-
/** Custom meter event name */
|
|
25
|
-
eventName?: string;
|
|
26
|
-
/** Usage callback fired upon generation/stream completion */
|
|
27
|
-
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
28
|
-
/** Custom developer metadata */
|
|
29
|
-
metadata?: Record<string, string | number | boolean>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
|
|
33
|
-
*
|
|
34
|
-
* Sane Defaults Built-In:
|
|
35
|
-
* - $0.50 safety ceiling per call (overridable)
|
|
36
|
-
* - Automatic in-flight token capture on abort
|
|
37
|
-
* - Automatic prompt caching discount parsing
|
|
38
|
-
* - Serverless lifecycle preservation
|
|
39
|
-
*/
|
|
40
|
-
declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
|
|
41
|
-
/**
|
|
42
|
-
* Convenient alias for withBilling
|
|
43
|
-
*/
|
|
44
|
-
declare const meteredModel: typeof withBilling;
|
|
45
|
-
|
|
46
7
|
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
47
|
-
/** OpenAI / AI Gateway API Key override */
|
|
8
|
+
/** OpenAI / Anthropic / AI Gateway API Key override */
|
|
48
9
|
apiKey?: string;
|
|
49
|
-
/** AI Gateway /
|
|
10
|
+
/** AI Gateway / Provider Base URL override */
|
|
50
11
|
baseURL?: string;
|
|
51
12
|
}
|
|
52
13
|
interface VibezSessionOptions {
|
|
@@ -70,23 +31,33 @@ interface VibezSession {
|
|
|
70
31
|
/**
|
|
71
32
|
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
72
33
|
*
|
|
34
|
+
* Supports:
|
|
35
|
+
* - Direct instances: `vibezcheck(openai('gpt-4o'))`, `vibezcheck(anthropic('claude-3-7-sonnet'))`
|
|
36
|
+
* - String identifiers: `vibezcheck('openai/gpt-4o-mini')`, `vibezcheck('anthropic/claude-3-5-sonnet')`, `vibezcheck('gpt-4o')`
|
|
37
|
+
* - Vercel AI SDK primitives: `generateText`, `streamText`, `generateObject`, `streamObject`
|
|
38
|
+
*
|
|
73
39
|
* @example
|
|
74
40
|
* ```typescript
|
|
75
|
-
* import {
|
|
41
|
+
* import { streamText } from 'ai';
|
|
42
|
+
* import { openai } from '@ai-sdk/openai';
|
|
43
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
76
44
|
* import { vibezcheck } from 'vibezcheck';
|
|
77
45
|
*
|
|
78
|
-
* // 1.
|
|
79
|
-
* const
|
|
80
|
-
* model: vibezcheck('
|
|
81
|
-
*
|
|
46
|
+
* // 1. Pass wrapped OpenAI instance:
|
|
47
|
+
* const result = streamText({
|
|
48
|
+
* model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
|
|
49
|
+
* messages,
|
|
82
50
|
* });
|
|
83
51
|
*
|
|
84
|
-
* // 2.
|
|
85
|
-
* const
|
|
86
|
-
* model: vibezcheck('
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
52
|
+
* // 2. Pass wrapped Anthropic instance:
|
|
53
|
+
* const result2 = streamText({
|
|
54
|
+
* model: vibezcheck(anthropic('claude-3-7-sonnet'), { customer: 'alex@example.com' }),
|
|
55
|
+
* messages,
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // 3. Use 1-line string identifier:
|
|
59
|
+
* const result3 = streamText({
|
|
60
|
+
* model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
|
|
90
61
|
* messages,
|
|
91
62
|
* });
|
|
92
63
|
* ```
|
|
@@ -100,4 +71,4 @@ declare const vibezcheck: typeof createVibezModel & {
|
|
|
100
71
|
session: typeof createVibezSession;
|
|
101
72
|
};
|
|
102
73
|
|
|
103
|
-
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions,
|
|
74
|
+
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, WithBillingOptions, createVibezModel, createVibezSession, vibezcheck };
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,52 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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';
|
|
3
5
|
import 'stripe';
|
|
4
6
|
|
|
5
|
-
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
|
-
/** Customer email, user ID, or Stripe customer ID */
|
|
7
|
-
customer?: CustomerParam;
|
|
8
|
-
/** Direct Stripe customer ID */
|
|
9
|
-
customerId?: string;
|
|
10
|
-
/** Billing mode configuration (postpaid vs prepaid) */
|
|
11
|
-
billing?: BillingConfig;
|
|
12
|
-
/** Profit margin & minimum charge configuration */
|
|
13
|
-
pricing?: PricingConfig;
|
|
14
|
-
/** 1-line inline pricing rate card */
|
|
15
|
-
rate?: InlineRateConfig;
|
|
16
|
-
/** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
|
|
17
|
-
captureOnAbort?: boolean;
|
|
18
|
-
/** Execution runtime environment (default: 'auto') */
|
|
19
|
-
runtime?: 'auto' | 'serverless' | 'edge' | 'node';
|
|
20
|
-
/** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
|
|
21
|
-
stripeApiKey?: string;
|
|
22
|
-
/** Existing VibezMeter instance (optional) */
|
|
23
|
-
meter?: VibezMeter;
|
|
24
|
-
/** Custom meter event name */
|
|
25
|
-
eventName?: string;
|
|
26
|
-
/** Usage callback fired upon generation/stream completion */
|
|
27
|
-
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
28
|
-
/** Custom developer metadata */
|
|
29
|
-
metadata?: Record<string, string | number | boolean>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
|
|
33
|
-
*
|
|
34
|
-
* Sane Defaults Built-In:
|
|
35
|
-
* - $0.50 safety ceiling per call (overridable)
|
|
36
|
-
* - Automatic in-flight token capture on abort
|
|
37
|
-
* - Automatic prompt caching discount parsing
|
|
38
|
-
* - Serverless lifecycle preservation
|
|
39
|
-
*/
|
|
40
|
-
declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
|
|
41
|
-
/**
|
|
42
|
-
* Convenient alias for withBilling
|
|
43
|
-
*/
|
|
44
|
-
declare const meteredModel: typeof withBilling;
|
|
45
|
-
|
|
46
7
|
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
47
|
-
/** OpenAI / AI Gateway API Key override */
|
|
8
|
+
/** OpenAI / Anthropic / AI Gateway API Key override */
|
|
48
9
|
apiKey?: string;
|
|
49
|
-
/** AI Gateway /
|
|
10
|
+
/** AI Gateway / Provider Base URL override */
|
|
50
11
|
baseURL?: string;
|
|
51
12
|
}
|
|
52
13
|
interface VibezSessionOptions {
|
|
@@ -70,23 +31,33 @@ interface VibezSession {
|
|
|
70
31
|
/**
|
|
71
32
|
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
72
33
|
*
|
|
34
|
+
* Supports:
|
|
35
|
+
* - Direct instances: `vibezcheck(openai('gpt-4o'))`, `vibezcheck(anthropic('claude-3-7-sonnet'))`
|
|
36
|
+
* - String identifiers: `vibezcheck('openai/gpt-4o-mini')`, `vibezcheck('anthropic/claude-3-5-sonnet')`, `vibezcheck('gpt-4o')`
|
|
37
|
+
* - Vercel AI SDK primitives: `generateText`, `streamText`, `generateObject`, `streamObject`
|
|
38
|
+
*
|
|
73
39
|
* @example
|
|
74
40
|
* ```typescript
|
|
75
|
-
* import {
|
|
41
|
+
* import { streamText } from 'ai';
|
|
42
|
+
* import { openai } from '@ai-sdk/openai';
|
|
43
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
76
44
|
* import { vibezcheck } from 'vibezcheck';
|
|
77
45
|
*
|
|
78
|
-
* // 1.
|
|
79
|
-
* const
|
|
80
|
-
* model: vibezcheck('
|
|
81
|
-
*
|
|
46
|
+
* // 1. Pass wrapped OpenAI instance:
|
|
47
|
+
* const result = streamText({
|
|
48
|
+
* model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
|
|
49
|
+
* messages,
|
|
82
50
|
* });
|
|
83
51
|
*
|
|
84
|
-
* // 2.
|
|
85
|
-
* const
|
|
86
|
-
* model: vibezcheck('
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
52
|
+
* // 2. Pass wrapped Anthropic instance:
|
|
53
|
+
* const result2 = streamText({
|
|
54
|
+
* model: vibezcheck(anthropic('claude-3-7-sonnet'), { customer: 'alex@example.com' }),
|
|
55
|
+
* messages,
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // 3. Use 1-line string identifier:
|
|
59
|
+
* const result3 = streamText({
|
|
60
|
+
* model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
|
|
90
61
|
* messages,
|
|
91
62
|
* });
|
|
92
63
|
* ```
|
|
@@ -100,4 +71,4 @@ declare const vibezcheck: typeof createVibezModel & {
|
|
|
100
71
|
session: typeof createVibezSession;
|
|
101
72
|
};
|
|
102
73
|
|
|
103
|
-
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions,
|
|
74
|
+
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, WithBillingOptions, createVibezModel, createVibezSession, vibezcheck };
|