vibezcheck 0.3.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 +135 -145
- package/dist/ai-sdk/index.d.mts +47 -14
- package/dist/ai-sdk/index.d.ts +47 -14
- package/dist/ai-sdk/index.js +168 -14
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +166 -14
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/{client-C67DW_tR.d.mts → client--iq93FQg.d.mts} +1 -1
- package/dist/{client-S3qmTXTR.d.ts → client-kJN_Znan.d.ts} +1 -1
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +176 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -23
- 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 +28 -2
- package/dist/react/index.d.ts +28 -2
- package/dist/react/index.js +177 -61
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +176 -61
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-DCuzLVyc.d.mts → types-Zbzxg-Ka.d.mts} +59 -2
- package/dist/{types-DCuzLVyc.d.ts → types-Zbzxg-Ka.d.ts} +59 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,213 +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
|
-
*
|
|
19
|
-
*
|
|
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.
|
|
20
27
|
|
|
21
28
|
---
|
|
22
29
|
|
|
23
30
|
## 📦 Installation
|
|
24
31
|
|
|
25
32
|
```bash
|
|
26
|
-
npm install vibezcheck stripe
|
|
27
|
-
# or
|
|
28
|
-
pnpm add vibezcheck stripe
|
|
33
|
+
npm install vibezcheck ai @ai-sdk/openai stripe
|
|
29
34
|
```
|
|
30
35
|
|
|
31
36
|
---
|
|
32
37
|
|
|
33
|
-
## ⚡ 1.
|
|
34
|
-
|
|
35
|
-
`vibezcheck` wraps any model string or provider instance into a fully compliant Vercel AI SDK model:
|
|
36
|
-
|
|
37
|
-
### A. Single-Turn Generation (`generateText` & Server Actions)
|
|
38
|
-
```typescript
|
|
39
|
-
import { generateText } from "ai";
|
|
40
|
-
import { vibezcheck } from "vibezcheck";
|
|
41
|
-
|
|
42
|
-
const { text, usage } = await generateText({
|
|
43
|
-
model: vibezcheck("openai/gpt-4o-mini", {
|
|
44
|
-
customer: "alex@example.com", // Auto-creates or matches Stripe customer
|
|
45
|
-
}),
|
|
46
|
-
prompt: "What is love?",
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### B. Streaming AI Route (`streamText`)
|
|
51
|
-
```typescript
|
|
52
|
-
// app/api/chat/route.ts
|
|
53
|
-
import { streamText } from "ai";
|
|
54
|
-
import { vibezcheck } from "vibezcheck";
|
|
55
|
-
|
|
56
|
-
export async function POST(req: Request) {
|
|
57
|
-
const { messages } = await req.json();
|
|
58
|
-
|
|
59
|
-
return streamText({
|
|
60
|
-
model: vibezcheck("gpt-4o-mini", { customer: "alex@example.com" }),
|
|
61
|
-
messages,
|
|
62
|
-
}).toTextStreamResponse();
|
|
63
|
-
}
|
|
64
|
-
```
|
|
38
|
+
## ⚡ 1. The 60-Second Quickstart
|
|
65
39
|
|
|
66
|
-
###
|
|
67
|
-
You can pass custom OpenAI / Gateway instances directly into `vibezcheck()`:
|
|
40
|
+
### Backend API Route (`app/api/chat/route.ts`)
|
|
68
41
|
```typescript
|
|
69
|
-
import {
|
|
70
|
-
import {
|
|
71
|
-
import { vibezcheck } from "vibezcheck";
|
|
72
|
-
|
|
73
|
-
const openai = createOpenAI({
|
|
74
|
-
apiKey: process.env.AI_GATEWAY_API_KEY,
|
|
75
|
-
baseURL: "https://ai-gateway.vercel.sh/v1", // Vercel AI Gateway or Cloudflare
|
|
76
|
-
});
|
|
42
|
+
import { streamText } from 'ai';
|
|
43
|
+
import { vibezcheck } from 'vibezcheck';
|
|
77
44
|
|
|
78
45
|
export async function POST(req: Request) {
|
|
79
|
-
const { messages } = await req.json();
|
|
46
|
+
const { messages, userEmail = 'alex@company.com' } = await req.json();
|
|
80
47
|
|
|
81
48
|
return streamText({
|
|
82
|
-
|
|
49
|
+
// ⚡ 1 Line. All 6 sane defaults run automatically.
|
|
50
|
+
model: vibezcheck('openai/gpt-4o-mini', { customer: userEmail }),
|
|
83
51
|
messages,
|
|
84
|
-
}).
|
|
52
|
+
}).toDataStreamResponse();
|
|
85
53
|
}
|
|
86
54
|
```
|
|
87
55
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
## ⚛️ 2. Declarative React UI & Hooks (`vibezcheck/react`)
|
|
91
|
-
|
|
92
|
-
### A. 1-Line Streaming Chat Hook (`useVibezChat`)
|
|
93
|
-
Automatically connects to your API route and syncs tokens, reasoning thoughts, and costs with the session widget:
|
|
94
|
-
|
|
56
|
+
### Frontend Chat UI (`app/page.tsx`)
|
|
95
57
|
```tsx
|
|
96
58
|
'use client';
|
|
97
|
-
import { useVibezChat,
|
|
59
|
+
import { useVibezChat, VibezReceipt, VibezSessionWidget } from 'vibezcheck/react';
|
|
98
60
|
|
|
99
61
|
export default function ChatPage() {
|
|
100
|
-
const { messages, input, handleInputChange, handleSubmit
|
|
101
|
-
model: 'gpt-4o-mini',
|
|
102
|
-
customer: 'alex@example.com',
|
|
103
|
-
});
|
|
62
|
+
const { messages, input, handleInputChange, handleSubmit } = useVibezChat();
|
|
104
63
|
|
|
105
64
|
return (
|
|
106
|
-
<main className="
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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>
|
|
116
91
|
</form>
|
|
117
|
-
|
|
118
|
-
{/* Live Token & Dollar Tracker Widget */}
|
|
119
|
-
<VibezSessionWidget theme="light" position="bottom-right" />
|
|
120
92
|
</main>
|
|
121
93
|
);
|
|
122
94
|
}
|
|
123
95
|
```
|
|
124
96
|
|
|
125
|
-
|
|
126
|
-
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 🛠️ Real-World Implementation Patterns
|
|
127
100
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
testMode={true} // Supports Stripe Sandbox testing
|
|
140
|
-
/>
|
|
101
|
+
### Pattern A: 50% Profit Margin Engine
|
|
102
|
+
Turn wholesale provider costs into guaranteed net profit:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
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
|
+
})
|
|
141
112
|
```
|
|
142
113
|
|
|
143
114
|
---
|
|
144
115
|
|
|
145
|
-
|
|
116
|
+
### Pattern B: Prepaid Credit Wallets (Zero Debt Risk)
|
|
117
|
+
User pre-purchases $10; stream cleanly halts when balance hits $0 without invoice debt:
|
|
146
118
|
|
|
147
|
-
### A. Auto Customer Provisioning in 1 Line:
|
|
148
119
|
```typescript
|
|
149
|
-
|
|
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
|
+
})
|
|
128
|
+
```
|
|
150
129
|
|
|
151
|
-
|
|
130
|
+
---
|
|
152
131
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
email: "alex@company.com",
|
|
156
|
-
name: "Alex Rivera",
|
|
157
|
-
});
|
|
158
|
-
console.log(customer.id); // "cus_R3K7h9Qv..."
|
|
159
|
-
```
|
|
132
|
+
### Pattern C: Frontier Reasoning Models (Claude 3.7 & o3-mini)
|
|
133
|
+
Automatically extracts hidden thinking tokens and applies 85% prompt cache discounts:
|
|
160
134
|
|
|
161
|
-
### B. 1-Line Stripe Checkout Session:
|
|
162
135
|
```typescript
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
});
|
|
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
|
+
})
|
|
168
140
|
```
|
|
169
141
|
|
|
170
142
|
---
|
|
171
143
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
{
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
144
|
+
### Pattern D: Unified Agent Tool Call Metering
|
|
145
|
+
Bill external tools (web searches, scrapers, Python sandboxes) and LLM streams into one invoice:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
// app/api/agent/route.ts
|
|
149
|
+
import { generateText, tool } from 'ai';
|
|
150
|
+
import { vibezcheck } from 'vibezcheck';
|
|
151
|
+
import { z } from 'zod';
|
|
152
|
+
|
|
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
|
+
}),
|
|
171
|
+
},
|
|
172
|
+
prompt,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return Response.json(result);
|
|
194
176
|
}
|
|
195
177
|
```
|
|
196
178
|
|
|
197
179
|
---
|
|
198
180
|
|
|
199
|
-
|
|
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:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
model: vibezcheck('deepseek/deepseek-r2', {
|
|
186
|
+
rate: { in: 0.20, out: 0.80 }, // $0.20/M in, $0.80/M out
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 🎨 React UI Suite (`vibezcheck/react`)
|
|
200
193
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
| **Google** | `gemini-2.0-flash`, `gemini-1.5-pro` | ✅ | ✅ |
|
|
206
|
-
| **DeepSeek** | `deepseek-chat`, `deepseek-reasoner` | ✅ | ✅ |
|
|
207
|
-
| **Custom** | Register any custom model with `registerModelPricing()` | ✅ | ✅ |
|
|
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.
|
|
208
198
|
|
|
209
199
|
---
|
|
210
200
|
|
|
211
201
|
## 📄 License
|
|
212
202
|
|
|
213
|
-
MIT © [
|
|
203
|
+
MIT © [VibezCheck](https://vibezcheck.app)
|
package/dist/ai-sdk/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
5
|
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
@@ -7,6 +7,16 @@ interface WithBillingOptions extends CircuitBreakerOptions {
|
|
|
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) */
|
|
@@ -21,9 +31,11 @@ interface WithBillingOptions extends CircuitBreakerOptions {
|
|
|
21
31
|
/**
|
|
22
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
|
/**
|
|
@@ -37,6 +49,24 @@ interface VibezCheckModelOptions extends WithBillingOptions {
|
|
|
37
49
|
/** AI Gateway / OpenAI Base URL override */
|
|
38
50
|
baseURL?: string;
|
|
39
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
|
+
}
|
|
40
70
|
/**
|
|
41
71
|
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
42
72
|
*
|
|
@@ -53,18 +83,21 @@ interface VibezCheckModelOptions extends WithBillingOptions {
|
|
|
53
83
|
*
|
|
54
84
|
* // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
|
|
55
85
|
* const result = streamText({
|
|
56
|
-
* model: vibezcheck('gpt-4o', {
|
|
57
|
-
*
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* // 3. Wrap existing provider instances:
|
|
61
|
-
* import { openai } from '@ai-sdk/openai';
|
|
62
|
-
* const result = streamText({
|
|
63
|
-
* model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
|
|
86
|
+
* model: vibezcheck('gpt-4o', {
|
|
87
|
+
* customer: 'alex@example.com',
|
|
88
|
+
* pricing: { margin: 1.5 }, // 50% profit margin
|
|
89
|
+
* }),
|
|
64
90
|
* messages,
|
|
65
91
|
* });
|
|
66
92
|
* ```
|
|
67
93
|
*/
|
|
68
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
|
+
};
|
|
69
102
|
|
|
70
|
-
export { type VibezCheckModelOptions, type WithBillingOptions, createVibezModel, meteredModel, withBilling };
|
|
103
|
+
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, type WithBillingOptions, createVibezModel, createVibezSession, meteredModel, vibezcheck, withBilling };
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
5
|
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
@@ -7,6 +7,16 @@ interface WithBillingOptions extends CircuitBreakerOptions {
|
|
|
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) */
|
|
@@ -21,9 +31,11 @@ interface WithBillingOptions extends CircuitBreakerOptions {
|
|
|
21
31
|
/**
|
|
22
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
|
/**
|
|
@@ -37,6 +49,24 @@ interface VibezCheckModelOptions extends WithBillingOptions {
|
|
|
37
49
|
/** AI Gateway / OpenAI Base URL override */
|
|
38
50
|
baseURL?: string;
|
|
39
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
|
+
}
|
|
40
70
|
/**
|
|
41
71
|
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
42
72
|
*
|
|
@@ -53,18 +83,21 @@ interface VibezCheckModelOptions extends WithBillingOptions {
|
|
|
53
83
|
*
|
|
54
84
|
* // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
|
|
55
85
|
* const result = streamText({
|
|
56
|
-
* model: vibezcheck('gpt-4o', {
|
|
57
|
-
*
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* // 3. Wrap existing provider instances:
|
|
61
|
-
* import { openai } from '@ai-sdk/openai';
|
|
62
|
-
* const result = streamText({
|
|
63
|
-
* model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
|
|
86
|
+
* model: vibezcheck('gpt-4o', {
|
|
87
|
+
* customer: 'alex@example.com',
|
|
88
|
+
* pricing: { margin: 1.5 }, // 50% profit margin
|
|
89
|
+
* }),
|
|
64
90
|
* messages,
|
|
65
91
|
* });
|
|
66
92
|
* ```
|
|
67
93
|
*/
|
|
68
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
|
+
};
|
|
69
102
|
|
|
70
|
-
export { type VibezCheckModelOptions, type WithBillingOptions, createVibezModel, meteredModel, withBilling };
|
|
103
|
+
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, type WithBillingOptions, createVibezModel, createVibezSession, meteredModel, vibezcheck, withBilling };
|