vibezcheck 0.1.0 → 0.2.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 +50 -0
- package/dist/react/index.d.mts +154 -0
- package/dist/react/index.d.ts +154 -0
- package/dist/react/index.js +674 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +642 -0
- package/dist/react/index.mjs.map +1 -0
- package/package.json +19 -1
package/README.md
CHANGED
|
@@ -184,6 +184,56 @@ export async function handleThinkingPrompt(prompt: string, customerId: string) {
|
|
|
184
184
|
|
|
185
185
|
---
|
|
186
186
|
|
|
187
|
+
## ⚛️ React & React Native Session Tracking (`vibezcheck/react`)
|
|
188
|
+
|
|
189
|
+
Track live session tokens and dollar costs directly on the client side with **zero database required**:
|
|
190
|
+
|
|
191
|
+
### 1. Wrap your chat app with `<VibezSessionProvider>`:
|
|
192
|
+
```tsx
|
|
193
|
+
import { VibezSessionProvider, VibezSessionWidget } from 'vibezcheck/react';
|
|
194
|
+
|
|
195
|
+
export default function App() {
|
|
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();
|
|
214
|
+
|
|
215
|
+
const { messages, input, handleSubmit } = useChat({
|
|
216
|
+
onFinish: (message, { usage }) => {
|
|
217
|
+
// 1 line: accumulates tokens & calculates real-time USD costs in React state
|
|
218
|
+
recordTurn({ model: 'gpt-5.6-sol', usage });
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
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
|
+
);
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
187
237
|
## 💰 Built-in Model Pricing Registry
|
|
188
238
|
|
|
189
239
|
`vibezcheck` ships with default rates for all active frontier models:
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { T as TokenUsage, I as InferenceCost } from '../types-CSrSmsd1.mjs';
|
|
2
|
+
import React$1 from 'react';
|
|
3
|
+
import 'stripe';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Record of a single message/completion turn in an active chat session
|
|
7
|
+
*/
|
|
8
|
+
interface SessionTurnRecord {
|
|
9
|
+
id: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
model: string;
|
|
12
|
+
usage: TokenUsage;
|
|
13
|
+
cost: InferenceCost;
|
|
14
|
+
metadata?: Record<string, string | number | boolean>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Aggregated live session state
|
|
18
|
+
*/
|
|
19
|
+
interface SessionState {
|
|
20
|
+
/** Unique session ID (e.g. chat conversation ID) */
|
|
21
|
+
sessionId: string;
|
|
22
|
+
/** Total number of interaction turns in this session */
|
|
23
|
+
turnCount: number;
|
|
24
|
+
/** Total tokens accumulated across all turns in this session */
|
|
25
|
+
sessionUsage: TokenUsage;
|
|
26
|
+
/** Total cost accumulated in this session */
|
|
27
|
+
sessionCost: InferenceCost;
|
|
28
|
+
/** Model-by-model breakdown of tokens and costs in this session */
|
|
29
|
+
byModel: Record<string, {
|
|
30
|
+
turns: number;
|
|
31
|
+
usage: TokenUsage;
|
|
32
|
+
cost: InferenceCost;
|
|
33
|
+
}>;
|
|
34
|
+
/** Complete turn history for this session */
|
|
35
|
+
history: SessionTurnRecord[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Storage adapter options for client-side persistence
|
|
39
|
+
*/
|
|
40
|
+
type SessionPersistenceMode = 'memory' | 'sessionStorage' | 'localStorage' | 'custom';
|
|
41
|
+
interface CustomStorageAdapter {
|
|
42
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
43
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
44
|
+
removeItem: (key: string) => void | Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration options for VibezSessionProvider
|
|
48
|
+
*/
|
|
49
|
+
interface VibezSessionProviderProps {
|
|
50
|
+
children: React.ReactNode;
|
|
51
|
+
/** Session ID (defaults to auto-generated UUID/timestamp) */
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
/** Client-side persistence mode (default: 'memory') */
|
|
54
|
+
persist?: SessionPersistenceMode;
|
|
55
|
+
/** Custom storage adapter (e.g. AsyncStorage for React Native) */
|
|
56
|
+
storage?: CustomStorageAdapter;
|
|
57
|
+
/** Storage key prefix (default: 'vibez_session_') */
|
|
58
|
+
storageKey?: string;
|
|
59
|
+
/** Markup multiplier for client retail cost displays (e.g. 1.3 for 30% margin) */
|
|
60
|
+
markupMultiplier?: number;
|
|
61
|
+
/** Callback fired whenever a turn is recorded */
|
|
62
|
+
onTurnRecorded?: (turn: SessionTurnRecord, sessionState: SessionState) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface returned by useVibezSession hook
|
|
66
|
+
*/
|
|
67
|
+
interface VibezSessionContextValue extends SessionState {
|
|
68
|
+
/** Record a completed turn from useChat, streamText, or native API */
|
|
69
|
+
recordTurn: (params: {
|
|
70
|
+
model: string;
|
|
71
|
+
usage: {
|
|
72
|
+
promptTokens?: number;
|
|
73
|
+
completionTokens?: number;
|
|
74
|
+
inputTokens?: number;
|
|
75
|
+
outputTokens?: number;
|
|
76
|
+
totalTokens?: number;
|
|
77
|
+
reasoningTokens?: number;
|
|
78
|
+
cachedTokens?: number;
|
|
79
|
+
cacheWriteTokens?: number;
|
|
80
|
+
completionTokensDetails?: {
|
|
81
|
+
reasoning_tokens?: number;
|
|
82
|
+
};
|
|
83
|
+
promptTokensDetails?: {
|
|
84
|
+
cached_tokens?: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
metadata?: Record<string, string | number | boolean>;
|
|
88
|
+
}) => SessionTurnRecord;
|
|
89
|
+
/** Reset session state (e.g. when user clicks "New Chat") */
|
|
90
|
+
resetSession: (newSessionId?: string) => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Props for the drop-in <VibezSessionWidget />
|
|
94
|
+
*/
|
|
95
|
+
interface VibezSessionWidgetProps {
|
|
96
|
+
/** Screen position for floating placement */
|
|
97
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'inline';
|
|
98
|
+
/** Show USD dollar cost (default: true) */
|
|
99
|
+
showCost?: boolean;
|
|
100
|
+
/** Show token counts (default: true) */
|
|
101
|
+
showTokens?: boolean;
|
|
102
|
+
/** Show reasoning/thinking tokens breakdown (default: true) */
|
|
103
|
+
showReasoning?: boolean;
|
|
104
|
+
/** Color theme (default: 'auto') */
|
|
105
|
+
theme?: 'dark' | 'light' | 'auto';
|
|
106
|
+
/** Custom container CSS class (for Web) */
|
|
107
|
+
className?: string;
|
|
108
|
+
/** Custom inline styles */
|
|
109
|
+
style?: React.CSSProperties;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Props for the compact <VibezSessionBadge />
|
|
113
|
+
*/
|
|
114
|
+
interface VibezSessionBadgeProps {
|
|
115
|
+
/** Show USD dollar cost (default: true) */
|
|
116
|
+
showCost?: boolean;
|
|
117
|
+
/** Show token count (default: true) */
|
|
118
|
+
showTokens?: boolean;
|
|
119
|
+
/** Custom CSS class */
|
|
120
|
+
className?: string;
|
|
121
|
+
/** Custom inline styles */
|
|
122
|
+
style?: React.CSSProperties;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare const VibezSessionContext: React$1.Context<VibezSessionContextValue | null>;
|
|
126
|
+
declare const VibezSessionProvider: React$1.FC<VibezSessionProviderProps>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Hook to access live session usage, cost totals, and turn recorder
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* const { sessionUsage, sessionCost, recordTurn, resetSession } = useVibezSession();
|
|
134
|
+
*
|
|
135
|
+
* // Inside useChat onFinish:
|
|
136
|
+
* onFinish: (message, { usage }) => {
|
|
137
|
+
* recordTurn({ model: 'gpt-5.6-sol', usage });
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
declare function useVibezSession(): VibezSessionContextValue;
|
|
142
|
+
/**
|
|
143
|
+
* Convenient alias
|
|
144
|
+
*/
|
|
145
|
+
declare const useVibez: typeof useVibezSession;
|
|
146
|
+
|
|
147
|
+
declare const VibezSessionWidget: React$1.FC<VibezSessionWidgetProps>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Compact inline badge for chat input bars, headers, or navbars
|
|
151
|
+
*/
|
|
152
|
+
declare const VibezSessionBadge: React$1.FC<VibezSessionBadgeProps>;
|
|
153
|
+
|
|
154
|
+
export { type CustomStorageAdapter, type SessionPersistenceMode, type SessionState, type SessionTurnRecord, VibezSessionBadge, type VibezSessionBadgeProps, VibezSessionContext, type VibezSessionContextValue, VibezSessionProvider, type VibezSessionProviderProps, VibezSessionWidget, type VibezSessionWidgetProps, useVibez, useVibezSession };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { T as TokenUsage, I as InferenceCost } from '../types-CSrSmsd1.js';
|
|
2
|
+
import React$1 from 'react';
|
|
3
|
+
import 'stripe';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Record of a single message/completion turn in an active chat session
|
|
7
|
+
*/
|
|
8
|
+
interface SessionTurnRecord {
|
|
9
|
+
id: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
model: string;
|
|
12
|
+
usage: TokenUsage;
|
|
13
|
+
cost: InferenceCost;
|
|
14
|
+
metadata?: Record<string, string | number | boolean>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Aggregated live session state
|
|
18
|
+
*/
|
|
19
|
+
interface SessionState {
|
|
20
|
+
/** Unique session ID (e.g. chat conversation ID) */
|
|
21
|
+
sessionId: string;
|
|
22
|
+
/** Total number of interaction turns in this session */
|
|
23
|
+
turnCount: number;
|
|
24
|
+
/** Total tokens accumulated across all turns in this session */
|
|
25
|
+
sessionUsage: TokenUsage;
|
|
26
|
+
/** Total cost accumulated in this session */
|
|
27
|
+
sessionCost: InferenceCost;
|
|
28
|
+
/** Model-by-model breakdown of tokens and costs in this session */
|
|
29
|
+
byModel: Record<string, {
|
|
30
|
+
turns: number;
|
|
31
|
+
usage: TokenUsage;
|
|
32
|
+
cost: InferenceCost;
|
|
33
|
+
}>;
|
|
34
|
+
/** Complete turn history for this session */
|
|
35
|
+
history: SessionTurnRecord[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Storage adapter options for client-side persistence
|
|
39
|
+
*/
|
|
40
|
+
type SessionPersistenceMode = 'memory' | 'sessionStorage' | 'localStorage' | 'custom';
|
|
41
|
+
interface CustomStorageAdapter {
|
|
42
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
43
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
44
|
+
removeItem: (key: string) => void | Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration options for VibezSessionProvider
|
|
48
|
+
*/
|
|
49
|
+
interface VibezSessionProviderProps {
|
|
50
|
+
children: React.ReactNode;
|
|
51
|
+
/** Session ID (defaults to auto-generated UUID/timestamp) */
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
/** Client-side persistence mode (default: 'memory') */
|
|
54
|
+
persist?: SessionPersistenceMode;
|
|
55
|
+
/** Custom storage adapter (e.g. AsyncStorage for React Native) */
|
|
56
|
+
storage?: CustomStorageAdapter;
|
|
57
|
+
/** Storage key prefix (default: 'vibez_session_') */
|
|
58
|
+
storageKey?: string;
|
|
59
|
+
/** Markup multiplier for client retail cost displays (e.g. 1.3 for 30% margin) */
|
|
60
|
+
markupMultiplier?: number;
|
|
61
|
+
/** Callback fired whenever a turn is recorded */
|
|
62
|
+
onTurnRecorded?: (turn: SessionTurnRecord, sessionState: SessionState) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface returned by useVibezSession hook
|
|
66
|
+
*/
|
|
67
|
+
interface VibezSessionContextValue extends SessionState {
|
|
68
|
+
/** Record a completed turn from useChat, streamText, or native API */
|
|
69
|
+
recordTurn: (params: {
|
|
70
|
+
model: string;
|
|
71
|
+
usage: {
|
|
72
|
+
promptTokens?: number;
|
|
73
|
+
completionTokens?: number;
|
|
74
|
+
inputTokens?: number;
|
|
75
|
+
outputTokens?: number;
|
|
76
|
+
totalTokens?: number;
|
|
77
|
+
reasoningTokens?: number;
|
|
78
|
+
cachedTokens?: number;
|
|
79
|
+
cacheWriteTokens?: number;
|
|
80
|
+
completionTokensDetails?: {
|
|
81
|
+
reasoning_tokens?: number;
|
|
82
|
+
};
|
|
83
|
+
promptTokensDetails?: {
|
|
84
|
+
cached_tokens?: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
metadata?: Record<string, string | number | boolean>;
|
|
88
|
+
}) => SessionTurnRecord;
|
|
89
|
+
/** Reset session state (e.g. when user clicks "New Chat") */
|
|
90
|
+
resetSession: (newSessionId?: string) => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Props for the drop-in <VibezSessionWidget />
|
|
94
|
+
*/
|
|
95
|
+
interface VibezSessionWidgetProps {
|
|
96
|
+
/** Screen position for floating placement */
|
|
97
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'inline';
|
|
98
|
+
/** Show USD dollar cost (default: true) */
|
|
99
|
+
showCost?: boolean;
|
|
100
|
+
/** Show token counts (default: true) */
|
|
101
|
+
showTokens?: boolean;
|
|
102
|
+
/** Show reasoning/thinking tokens breakdown (default: true) */
|
|
103
|
+
showReasoning?: boolean;
|
|
104
|
+
/** Color theme (default: 'auto') */
|
|
105
|
+
theme?: 'dark' | 'light' | 'auto';
|
|
106
|
+
/** Custom container CSS class (for Web) */
|
|
107
|
+
className?: string;
|
|
108
|
+
/** Custom inline styles */
|
|
109
|
+
style?: React.CSSProperties;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Props for the compact <VibezSessionBadge />
|
|
113
|
+
*/
|
|
114
|
+
interface VibezSessionBadgeProps {
|
|
115
|
+
/** Show USD dollar cost (default: true) */
|
|
116
|
+
showCost?: boolean;
|
|
117
|
+
/** Show token count (default: true) */
|
|
118
|
+
showTokens?: boolean;
|
|
119
|
+
/** Custom CSS class */
|
|
120
|
+
className?: string;
|
|
121
|
+
/** Custom inline styles */
|
|
122
|
+
style?: React.CSSProperties;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare const VibezSessionContext: React$1.Context<VibezSessionContextValue | null>;
|
|
126
|
+
declare const VibezSessionProvider: React$1.FC<VibezSessionProviderProps>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Hook to access live session usage, cost totals, and turn recorder
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* const { sessionUsage, sessionCost, recordTurn, resetSession } = useVibezSession();
|
|
134
|
+
*
|
|
135
|
+
* // Inside useChat onFinish:
|
|
136
|
+
* onFinish: (message, { usage }) => {
|
|
137
|
+
* recordTurn({ model: 'gpt-5.6-sol', usage });
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
declare function useVibezSession(): VibezSessionContextValue;
|
|
142
|
+
/**
|
|
143
|
+
* Convenient alias
|
|
144
|
+
*/
|
|
145
|
+
declare const useVibez: typeof useVibezSession;
|
|
146
|
+
|
|
147
|
+
declare const VibezSessionWidget: React$1.FC<VibezSessionWidgetProps>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Compact inline badge for chat input bars, headers, or navbars
|
|
151
|
+
*/
|
|
152
|
+
declare const VibezSessionBadge: React$1.FC<VibezSessionBadgeProps>;
|
|
153
|
+
|
|
154
|
+
export { type CustomStorageAdapter, type SessionPersistenceMode, type SessionState, type SessionTurnRecord, VibezSessionBadge, type VibezSessionBadgeProps, VibezSessionContext, type VibezSessionContextValue, VibezSessionProvider, type VibezSessionProviderProps, VibezSessionWidget, type VibezSessionWidgetProps, useVibez, useVibezSession };
|