vibezcheck 0.2.0 → 0.4.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/README.md +131 -197
- package/bin/vibezcheck.js +4 -0
- package/dist/ai-sdk/index.d.mts +78 -9
- package/dist/ai-sdk/index.d.ts +78 -9
- package/dist/ai-sdk/index.js +278 -64
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +282 -64
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +232 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +209 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/{client-MJ3tl7bz.d.mts → client--iq93FQg.d.mts} +1 -1
- package/dist/{client-txrE0D_D.d.ts → client-kJN_Znan.d.ts} +1 -1
- package/dist/index.d.mts +50 -26
- package/dist/index.d.ts +50 -26
- package/dist/index.js +299 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +303 -104
- 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 +28 -7
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +28 -7
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +8 -2
- package/dist/pricing/index.d.ts +8 -2
- package/dist/pricing/index.js +28 -7
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +28 -7
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +95 -17
- package/dist/react/index.d.ts +95 -17
- package/dist/react/index.js +468 -7
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +468 -10
- package/dist/react/index.mjs.map +1 -1
- package/dist/types-Zbzxg-Ka.d.mts +261 -0
- package/dist/types-Zbzxg-Ka.d.ts +261 -0
- package/package.json +6 -2
- package/dist/types-CSrSmsd1.d.mts +0 -159
- package/dist/types-CSrSmsd1.d.ts +0 -159
package/README.md
CHANGED
|
@@ -1,269 +1,203 @@
|
|
|
1
1
|
# ⚡ vibezcheck
|
|
2
2
|
|
|
3
|
-
> **
|
|
4
|
-
>
|
|
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
5
|
|
|
6
6
|
[](https://npmjs.org/package/vibezcheck)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
|
+
[]()
|
|
9
10
|
|
|
10
11
|
---
|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
+
## 🍌 The Electric Meter for Artificial Intelligence
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
### 🛡️ Sane Defaults (Zero Configuration Required)
|
|
18
|
+
* **⚡ 0ms Added Latency**: Streams pass directly to your user's browser with zero intermediate proxy buffering.
|
|
19
|
+
* **🛡️ Default $0.50 Fuse Box**: Automatically prevents runaway loops without requiring manual ceilings.
|
|
20
|
+
* **🛟 In-Flight Abort Trapper**: Captures and bills partial tokens even if a user closes their browser tab mid-stream.
|
|
21
|
+
* **🏷️ Automatic 85% Prompt Cache Discounts**: Detects cache hits on Claude 3.7, GPT-4o, and DeepSeek and passes real savings through.
|
|
22
|
+
* **🚀 Serverless Lifecycle Protection**: Seamlessly keeps serverless containers alive until telemetry is acknowledged.
|
|
23
|
+
* **💰 1-Line Profit Margins**: Turn wholesale provider costs into guaranteed net profit with `pricing: { margin: 1.5 }`.
|
|
24
|
+
* **💳 Prepaid & Postpaid**: Choose between monthly metered invoices or zero-debt credit wallets.
|
|
25
|
+
* **🧠 Reasoning Token Aware**: Captures hidden thinking tokens in o3-mini and Claude 3.7 Thinking.
|
|
26
|
+
* **🆓 Free Vibe Mode**: Works 100% out of the box in local development with no Stripe account required.
|
|
19
27
|
|
|
20
28
|
---
|
|
21
29
|
|
|
22
30
|
## 📦 Installation
|
|
23
31
|
|
|
24
32
|
```bash
|
|
25
|
-
npm install vibezcheck stripe
|
|
26
|
-
# or
|
|
27
|
-
pnpm add vibezcheck stripe
|
|
33
|
+
npm install vibezcheck ai @ai-sdk/openai stripe
|
|
28
34
|
```
|
|
29
35
|
|
|
30
36
|
---
|
|
31
37
|
|
|
32
|
-
##
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
### Feature 1: Local Token & Cost Tracking (Free / No Stripe Required)
|
|
38
|
+
## ⚡ 1. The 60-Second Quickstart
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
#### 💻 Code:
|
|
40
|
+
### Backend API Route (`app/api/chat/route.ts`)
|
|
41
41
|
```typescript
|
|
42
|
-
|
|
43
|
-
import {
|
|
44
|
-
import OpenAI from 'openai';
|
|
45
|
-
|
|
46
|
-
const openai = new OpenAI();
|
|
47
|
-
|
|
48
|
-
// 1. Create a meter (no Stripe key required!)
|
|
49
|
-
const meter = createMeter({
|
|
50
|
-
onUsage: (event) => {
|
|
51
|
-
console.log(`[vibezcheck] 📊 Model: ${event.model}`);
|
|
52
|
-
console.log(`Tokens: ${event.usage.totalTokens} (Input: ${event.usage.inputTokens}, Output: ${event.usage.outputTokens}, Reasoning: ${event.usage.reasoningTokens ?? 0})`);
|
|
53
|
-
console.log(`Inference Cost: $${event.cost.totalUSD.toFixed(6)} USD\n`);
|
|
54
|
-
},
|
|
55
|
-
});
|
|
42
|
+
import { streamText } from 'ai';
|
|
43
|
+
import { vibezcheck } from 'vibezcheck';
|
|
56
44
|
|
|
57
45
|
export async function POST(req: Request) {
|
|
58
|
-
const { messages } = await req.json();
|
|
46
|
+
const { messages, userEmail = 'alex@company.com' } = await req.json();
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
return streamText({
|
|
49
|
+
// ⚡ 1 Line. All 6 sane defaults run automatically.
|
|
50
|
+
model: vibezcheck('openai/gpt-4o-mini', { customer: userEmail }),
|
|
62
51
|
messages,
|
|
63
|
-
|
|
64
|
-
stream_options: { include_usage: true },
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// 2. Wrap stream - passes chunks directly to user with 0ms added delay
|
|
68
|
-
return new Response(meter.wrapStream(stream));
|
|
52
|
+
}).toDataStreamResponse();
|
|
69
53
|
}
|
|
70
54
|
```
|
|
71
55
|
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Transfer-Encoding: chunked
|
|
56
|
+
### Frontend Chat UI (`app/page.tsx`)
|
|
57
|
+
```tsx
|
|
58
|
+
'use client';
|
|
59
|
+
import { useVibezChat, VibezReceipt, VibezSessionWidget } from 'vibezcheck/react';
|
|
77
60
|
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
export default function ChatPage() {
|
|
62
|
+
const { messages, input, handleInputChange, handleSubmit } = useVibezChat();
|
|
80
63
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
return (
|
|
65
|
+
<main className="max-w-xl mx-auto py-10 px-4 space-y-6">
|
|
66
|
+
{/* 1. Floating live token & dollar counter */}
|
|
67
|
+
<VibezSessionWidget position="bottom-right" />
|
|
68
|
+
|
|
69
|
+
{/* 2. Messages with micro-receipts */}
|
|
70
|
+
<div className="space-y-4">
|
|
71
|
+
{messages.map((m) => (
|
|
72
|
+
<div key={m.id} className="p-4 rounded-2xl bg-white border border-slate-200">
|
|
73
|
+
<p className="text-slate-900 text-sm">{m.content}</p>
|
|
74
|
+
|
|
75
|
+
{/* Micro-Receipt under assistant answers */}
|
|
76
|
+
{m.role === 'assistant' && <VibezReceipt message={m} />}
|
|
77
|
+
</div>
|
|
78
|
+
))}
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<form onSubmit={handleSubmit} className="flex gap-2">
|
|
82
|
+
<input
|
|
83
|
+
value={input}
|
|
84
|
+
onChange={handleInputChange}
|
|
85
|
+
placeholder="Ask a question..."
|
|
86
|
+
className="flex-1 px-4 py-2 rounded-xl border border-slate-200 text-sm"
|
|
87
|
+
/>
|
|
88
|
+
<button type="submit" className="px-5 py-2 rounded-xl bg-slate-950 text-white font-bold text-sm">
|
|
89
|
+
Send
|
|
90
|
+
</button>
|
|
91
|
+
</form>
|
|
92
|
+
</main>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
86
95
|
```
|
|
87
96
|
|
|
88
97
|
---
|
|
89
98
|
|
|
90
|
-
|
|
99
|
+
## 🛠️ Real-World Implementation Patterns
|
|
91
100
|
|
|
92
|
-
|
|
101
|
+
### Pattern A: 50% Profit Margin Engine
|
|
102
|
+
Turn wholesale provider costs into guaranteed net profit:
|
|
93
103
|
|
|
94
|
-
#### 💻 Code:
|
|
95
104
|
```typescript
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// 1-line wrapper: extracts reasoning tokens & logs meter events to Stripe!
|
|
105
|
-
const result = streamText({
|
|
106
|
-
model: withBilling(openai('gpt-5.6-sol'), {
|
|
107
|
-
customer: userEmail, // e.g. "alex@example.com"
|
|
108
|
-
stripeApiKey: process.env.STRIPE_SECRET_KEY,
|
|
109
|
-
}),
|
|
110
|
-
messages,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
return result.toDataStreamResponse();
|
|
114
|
-
}
|
|
105
|
+
model: vibezcheck('openai/gpt-4o-mini', {
|
|
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
|
+
})
|
|
115
112
|
```
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
Compatible with Vercel's `useChat()` React hook:
|
|
119
|
-
```http
|
|
120
|
-
HTTP/1.1 200 OK
|
|
121
|
-
Content-Type: text/event-stream; charset=utf-8
|
|
122
|
-
x-vercel-ai-data-stream: v1
|
|
114
|
+
---
|
|
123
115
|
|
|
124
|
-
|
|
125
|
-
0
|
|
126
|
-
d:{"finishReason":"stop","usage":{"promptTokens":1200,"completionTokens":450,"reasoningTokens":350}}
|
|
127
|
-
```
|
|
116
|
+
### Pattern B: Prepaid Credit Wallets (Zero Debt Risk)
|
|
117
|
+
User pre-purchases $10; stream cleanly halts when balance hits $0 without invoice debt:
|
|
128
118
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
"value": "800",
|
|
139
|
-
"model": "openai/gpt-5.6-sol",
|
|
140
|
-
"token_type": "output",
|
|
141
|
-
"is_reasoning": "true"
|
|
142
|
-
}
|
|
143
|
-
}
|
|
119
|
+
```typescript
|
|
120
|
+
model: vibezcheck('openai/gpt-4o-mini', {
|
|
121
|
+
customer: 'alex@gmail.com',
|
|
122
|
+
billing: {
|
|
123
|
+
mode: 'prepaid', // 👈 Deducts from prepaid credit balance in real time
|
|
124
|
+
},
|
|
125
|
+
// Gracefully downshift when credits run low instead of crashing
|
|
126
|
+
fallbackModelOnBudget: 'openai/gpt-4o-mini',
|
|
127
|
+
})
|
|
144
128
|
```
|
|
145
|
-
3. **Invoice Updated**: Stripe increments Alex's monthly usage bill or deducts \$0.016 from their prepaid credit balance.
|
|
146
129
|
|
|
147
130
|
---
|
|
148
131
|
|
|
149
|
-
###
|
|
132
|
+
### Pattern C: Frontier Reasoning Models (Claude 3.7 & o3-mini)
|
|
133
|
+
Automatically extracts hidden thinking tokens and applies 85% prompt cache discounts:
|
|
150
134
|
|
|
151
135
|
```typescript
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const meter = createMeter({ apiKey: process.env.STRIPE_SECRET_KEY });
|
|
157
|
-
|
|
158
|
-
export async function handleThinkingPrompt(prompt: string, customerId: string) {
|
|
159
|
-
const stream = await anthropic.messages.create({
|
|
160
|
-
model: 'claude-3-7-sonnet-20250219',
|
|
161
|
-
max_tokens: 4000,
|
|
162
|
-
thinking: { type: 'enabled', budget_tokens: 2000 },
|
|
163
|
-
messages: [{ role: 'user', content: prompt }],
|
|
164
|
-
stream: true,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Automatically captures Claude 3.7 thinking tokens and sends to Stripe:
|
|
168
|
-
return meter.wrapStream(stream, { customerId });
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
#### 💳 Stripe Meter Event output for Thinking Tokens:
|
|
173
|
-
```json
|
|
174
|
-
{
|
|
175
|
-
"event_name": "token-billing-tokens",
|
|
176
|
-
"payload": {
|
|
177
|
-
"stripe_customer_id": "cus_Q871xyz",
|
|
178
|
-
"value": "1840",
|
|
179
|
-
"model": "anthropic/claude-3-7-sonnet",
|
|
180
|
-
"token_type": "output_thinking"
|
|
181
|
-
}
|
|
182
|
-
}
|
|
136
|
+
model: vibezcheck('anthropic/claude-3-7-sonnet', {
|
|
137
|
+
customer: 'alex@company.com',
|
|
138
|
+
maxCostPerCallUSD: 0.75, // Extended ceiling for multi-minute deep reasoning
|
|
139
|
+
})
|
|
183
140
|
```
|
|
184
141
|
|
|
185
142
|
---
|
|
186
143
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
Track live session tokens and dollar costs directly on the client side with **zero database required**:
|
|
144
|
+
### Pattern D: Unified Agent Tool Call Metering
|
|
145
|
+
Bill external tools (web searches, scrapers, Python sandboxes) and LLM streams into one invoice:
|
|
190
146
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
import {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return (
|
|
197
|
-
<VibezSessionProvider persist="sessionStorage">
|
|
198
|
-
<ChatInterface />
|
|
199
|
-
|
|
200
|
-
{/* Drop-in floating pill widget showing live session tokens & cost */}
|
|
201
|
-
<VibezSessionWidget position="bottom-right" showReasoning theme="dark" />
|
|
202
|
-
</VibezSessionProvider>
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### 2. Auto-hook into Vercel AI SDK (`useChat`):
|
|
208
|
-
```tsx
|
|
209
|
-
import { useChat } from 'ai/react';
|
|
210
|
-
import { useVibezSession, VibezSessionBadge } from 'vibezcheck/react';
|
|
211
|
-
|
|
212
|
-
export function ChatInterface() {
|
|
213
|
-
const { recordTurn, sessionUsage, sessionCost } = useVibezSession();
|
|
147
|
+
```typescript
|
|
148
|
+
// app/api/agent/route.ts
|
|
149
|
+
import { generateText, tool } from 'ai';
|
|
150
|
+
import { vibezcheck } from 'vibezcheck';
|
|
151
|
+
import { z } from 'zod';
|
|
214
152
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
153
|
+
export async function POST(req: Request) {
|
|
154
|
+
const { prompt, customer = 'alex@company.com' } = await req.json();
|
|
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
|
+
}),
|
|
219
171
|
},
|
|
172
|
+
prompt,
|
|
220
173
|
});
|
|
221
174
|
|
|
222
|
-
return (
|
|
223
|
-
<div>
|
|
224
|
-
<header className="flex justify-between items-center">
|
|
225
|
-
<h2>AI Assistant</h2>
|
|
226
|
-
<VibezSessionBadge showTokens showCost />
|
|
227
|
-
</header>
|
|
228
|
-
|
|
229
|
-
<MessagesList messages={messages} />
|
|
230
|
-
</div>
|
|
231
|
-
);
|
|
175
|
+
return Response.json(result);
|
|
232
176
|
}
|
|
233
177
|
```
|
|
234
178
|
|
|
235
179
|
---
|
|
236
180
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
`vibezcheck` ships with default rates for all active frontier models:
|
|
181
|
+
### Pattern E: Brand-New Model (1-Line Inline Rate Card)
|
|
182
|
+
Use newly released or fine-tuned models with zero wait for package updates:
|
|
240
183
|
|
|
241
184
|
```typescript
|
|
242
|
-
|
|
185
|
+
model: vibezcheck('deepseek/deepseek-r2', {
|
|
186
|
+
rate: { in: 0.20, out: 0.80 }, // $0.20/M in, $0.80/M out
|
|
187
|
+
})
|
|
188
|
+
```
|
|
243
189
|
|
|
244
|
-
|
|
245
|
-
model: 'claude-3-7-sonnet',
|
|
246
|
-
inputTokens: 2000,
|
|
247
|
-
outputTokens: 800,
|
|
248
|
-
reasoningTokens: 1200, // thinking tokens
|
|
249
|
-
});
|
|
190
|
+
---
|
|
250
191
|
|
|
251
|
-
|
|
252
|
-
```
|
|
192
|
+
## 🎨 React UI Suite (`vibezcheck/react`)
|
|
253
193
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
"outputCostUSD": 0.002344,
|
|
259
|
-
"reasoningCostUSD": 0.003516,
|
|
260
|
-
"totalCostUSD": 0.007040,
|
|
261
|
-
"currency": "USD"
|
|
262
|
-
}
|
|
263
|
-
```
|
|
194
|
+
* **`useVibezChat`**: 1-hook drop-in chat streaming with live session cost sync.
|
|
195
|
+
* **`<VibezReceipt />`**: Micro-badge rendered below assistant responses (*"⚡ gpt-4o-mini • 342 tokens • $0.0005 • Verified by VibezCheck"*).
|
|
196
|
+
* **`<VibezSessionWidget />`**: Floating live token & dollar speedometer in the screen corner.
|
|
197
|
+
* **`<VibezBillingModal />`**: Drop-in 1-click Stripe Checkout top-up modal.
|
|
264
198
|
|
|
265
199
|
---
|
|
266
200
|
|
|
267
201
|
## 📄 License
|
|
268
202
|
|
|
269
|
-
MIT © [
|
|
203
|
+
MIT © [VibezCheck](https://vibezcheck.app)
|
package/dist/ai-sdk/index.d.mts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { C as CustomerParam, U as UsageEvent } from '../types-
|
|
2
|
-
import { V as VibezMeter } from '../client
|
|
1
|
+
import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig, P as PricingConfig, d as InlineRateConfig, U as UsageEvent } from '../types-Zbzxg-Ka.mjs';
|
|
2
|
+
import { V as VibezMeter } from '../client--iq93FQg.mjs';
|
|
3
3
|
import 'stripe';
|
|
4
4
|
|
|
5
|
-
interface WithBillingOptions {
|
|
5
|
+
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
6
|
/** Customer email, user ID, or Stripe customer ID */
|
|
7
7
|
customer?: CustomerParam;
|
|
8
8
|
/** Direct Stripe customer ID */
|
|
9
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';
|
|
10
20
|
/** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
|
|
11
21
|
stripeApiKey?: string;
|
|
12
22
|
/** Existing VibezMeter instance (optional) */
|
|
@@ -19,16 +29,75 @@ interface WithBillingOptions {
|
|
|
19
29
|
metadata?: Record<string, string | number | boolean>;
|
|
20
30
|
}
|
|
21
31
|
/**
|
|
22
|
-
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing and
|
|
32
|
+
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
|
|
23
33
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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
|
|
27
39
|
*/
|
|
28
40
|
declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
|
|
29
41
|
/**
|
|
30
|
-
*
|
|
42
|
+
* Convenient alias for withBilling
|
|
31
43
|
*/
|
|
32
44
|
declare const meteredModel: typeof withBilling;
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
47
|
+
/** OpenAI / AI Gateway API Key override */
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
/** AI Gateway / OpenAI Base URL override */
|
|
50
|
+
baseURL?: string;
|
|
51
|
+
}
|
|
52
|
+
interface VibezSessionOptions {
|
|
53
|
+
customer?: CustomerParam;
|
|
54
|
+
stripeApiKey?: string;
|
|
55
|
+
pricing?: WithBillingOptions['pricing'];
|
|
56
|
+
billing?: WithBillingOptions['billing'];
|
|
57
|
+
metadata?: Record<string, string | number | boolean>;
|
|
58
|
+
}
|
|
59
|
+
interface VibezSession {
|
|
60
|
+
/** Creates a metered model bound to this session customer */
|
|
61
|
+
model: (modelOrId: any, options?: VibezCheckModelOptions) => any;
|
|
62
|
+
/** Tracks a non-LLM tool execution cost (e.g. search, scraper, image gen) */
|
|
63
|
+
trackTool: (name: string, options: {
|
|
64
|
+
costUSD: number;
|
|
65
|
+
metadata?: Record<string, any>;
|
|
66
|
+
}) => Promise<void>;
|
|
67
|
+
/** Underlying meter instance */
|
|
68
|
+
meter: VibezMeter;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { generateText, streamText } from 'ai';
|
|
76
|
+
* import { vibezcheck } from 'vibezcheck';
|
|
77
|
+
*
|
|
78
|
+
* // 1. Declarative string model identifier:
|
|
79
|
+
* const { text } = await generateText({
|
|
80
|
+
* model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
|
|
81
|
+
* prompt: 'What is love?',
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
|
|
85
|
+
* const result = streamText({
|
|
86
|
+
* model: vibezcheck('gpt-4o', {
|
|
87
|
+
* customer: 'alex@example.com',
|
|
88
|
+
* pricing: { margin: 1.5 }, // 50% profit margin
|
|
89
|
+
* }),
|
|
90
|
+
* messages,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptions): any;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a scoped session for unified multi-call and tool tracking.
|
|
97
|
+
*/
|
|
98
|
+
declare function createVibezSession(sessionOptions?: VibezSessionOptions): VibezSession;
|
|
99
|
+
declare const vibezcheck: typeof createVibezModel & {
|
|
100
|
+
session: typeof createVibezSession;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, type WithBillingOptions, createVibezModel, createVibezSession, meteredModel, vibezcheck, withBilling };
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { C as CustomerParam, U as UsageEvent } from '../types-
|
|
2
|
-
import { V as VibezMeter } from '../client-
|
|
1
|
+
import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig, P as PricingConfig, d as InlineRateConfig, U as UsageEvent } from '../types-Zbzxg-Ka.js';
|
|
2
|
+
import { V as VibezMeter } from '../client-kJN_Znan.js';
|
|
3
3
|
import 'stripe';
|
|
4
4
|
|
|
5
|
-
interface WithBillingOptions {
|
|
5
|
+
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
6
|
/** Customer email, user ID, or Stripe customer ID */
|
|
7
7
|
customer?: CustomerParam;
|
|
8
8
|
/** Direct Stripe customer ID */
|
|
9
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';
|
|
10
20
|
/** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
|
|
11
21
|
stripeApiKey?: string;
|
|
12
22
|
/** Existing VibezMeter instance (optional) */
|
|
@@ -19,16 +29,75 @@ interface WithBillingOptions {
|
|
|
19
29
|
metadata?: Record<string, string | number | boolean>;
|
|
20
30
|
}
|
|
21
31
|
/**
|
|
22
|
-
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing and
|
|
32
|
+
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
|
|
23
33
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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
|
|
27
39
|
*/
|
|
28
40
|
declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
|
|
29
41
|
/**
|
|
30
|
-
*
|
|
42
|
+
* Convenient alias for withBilling
|
|
31
43
|
*/
|
|
32
44
|
declare const meteredModel: typeof withBilling;
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
47
|
+
/** OpenAI / AI Gateway API Key override */
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
/** AI Gateway / OpenAI Base URL override */
|
|
50
|
+
baseURL?: string;
|
|
51
|
+
}
|
|
52
|
+
interface VibezSessionOptions {
|
|
53
|
+
customer?: CustomerParam;
|
|
54
|
+
stripeApiKey?: string;
|
|
55
|
+
pricing?: WithBillingOptions['pricing'];
|
|
56
|
+
billing?: WithBillingOptions['billing'];
|
|
57
|
+
metadata?: Record<string, string | number | boolean>;
|
|
58
|
+
}
|
|
59
|
+
interface VibezSession {
|
|
60
|
+
/** Creates a metered model bound to this session customer */
|
|
61
|
+
model: (modelOrId: any, options?: VibezCheckModelOptions) => any;
|
|
62
|
+
/** Tracks a non-LLM tool execution cost (e.g. search, scraper, image gen) */
|
|
63
|
+
trackTool: (name: string, options: {
|
|
64
|
+
costUSD: number;
|
|
65
|
+
metadata?: Record<string, any>;
|
|
66
|
+
}) => Promise<void>;
|
|
67
|
+
/** Underlying meter instance */
|
|
68
|
+
meter: VibezMeter;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { generateText, streamText } from 'ai';
|
|
76
|
+
* import { vibezcheck } from 'vibezcheck';
|
|
77
|
+
*
|
|
78
|
+
* // 1. Declarative string model identifier:
|
|
79
|
+
* const { text } = await generateText({
|
|
80
|
+
* model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
|
|
81
|
+
* prompt: 'What is love?',
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
|
|
85
|
+
* const result = streamText({
|
|
86
|
+
* model: vibezcheck('gpt-4o', {
|
|
87
|
+
* customer: 'alex@example.com',
|
|
88
|
+
* pricing: { margin: 1.5 }, // 50% profit margin
|
|
89
|
+
* }),
|
|
90
|
+
* messages,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptions): any;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a scoped session for unified multi-call and tool tracking.
|
|
97
|
+
*/
|
|
98
|
+
declare function createVibezSession(sessionOptions?: VibezSessionOptions): VibezSession;
|
|
99
|
+
declare const vibezcheck: typeof createVibezModel & {
|
|
100
|
+
session: typeof createVibezSession;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, type WithBillingOptions, createVibezModel, createVibezSession, meteredModel, vibezcheck, withBilling };
|