vibezcheck 0.5.4 → 0.5.6
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/bin/examples.js +8 -0
- package/bin/vibezcheck.js +0 -0
- package/dist/ai-sdk/index.d.mts +45 -5
- package/dist/ai-sdk/index.d.ts +45 -5
- package/dist/ai-sdk/index.js +161 -4
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +160 -4
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/ai-sdk/middleware.d.mts +3 -3
- package/dist/ai-sdk/middleware.d.ts +3 -3
- package/dist/ai-sdk/middleware.js +21 -3
- package/dist/ai-sdk/middleware.js.map +1 -1
- package/dist/ai-sdk/middleware.mjs +21 -3
- package/dist/ai-sdk/middleware.mjs.map +1 -1
- package/dist/billing/index.d.mts +3 -3
- package/dist/billing/index.d.ts +3 -3
- package/dist/billing/index.js +21 -3
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +21 -3
- package/dist/billing/index.mjs.map +1 -1
- package/dist/cli/index.js +231 -24
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +255 -41
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-CbuXmoXz.d.mts → client-BzwEHQlC.d.mts} +1 -1
- package/dist/{client-BORmJy8s.d.ts → client-CbO6vLUe.d.ts} +1 -1
- package/dist/compat/stripe-meter.d.mts +3 -3
- package/dist/compat/stripe-meter.d.ts +3 -3
- package/dist/compat/stripe-meter.js +21 -3
- package/dist/compat/stripe-meter.js.map +1 -1
- package/dist/compat/stripe-meter.mjs +21 -3
- package/dist/compat/stripe-meter.mjs.map +1 -1
- package/dist/compat/stripe-provider.js +159 -4
- package/dist/compat/stripe-provider.js.map +1 -1
- package/dist/compat/stripe-provider.mjs +159 -4
- package/dist/compat/stripe-provider.mjs.map +1 -1
- package/dist/compat/token-meter.js +4 -2
- package/dist/compat/token-meter.js.map +1 -1
- package/dist/compat/token-meter.mjs +4 -2
- package/dist/compat/token-meter.mjs.map +1 -1
- package/dist/customers/index.d.mts +1 -1
- package/dist/customers/index.d.ts +1 -1
- package/dist/index.d.mts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +162 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -4
- 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 +4 -2
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +4 -2
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +1 -1
- package/dist/pricing/index.d.ts +1 -1
- package/dist/pricing/index.js +2 -0
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +2 -0
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +10 -3
- package/dist/react/index.d.ts +10 -3
- package/dist/react/index.js +219 -69
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +220 -70
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-6P71CXAD.d.mts → types-Btf2OhIr.d.mts} +6 -0
- package/dist/{types-6P71CXAD.d.ts → types-Btf2OhIr.d.ts} +6 -0
- package/dist/{with-billing-DndWGxL8.d.mts → with-billing-BEqiJtCR.d.mts} +2 -2
- package/dist/{with-billing-Bj6Ya_Iy.d.ts → with-billing-D7QRoNHM.d.ts} +2 -2
- package/examples/01-local-cost-meter.ts +63 -0
- package/examples/02-vercel-ai-sdk.ts +43 -0
- package/examples/03-native-openai-stream.ts +40 -0
- package/examples/04-claude-thinking.ts +41 -0
- package/examples/05-reasoning-agent-stream.ts +54 -0
- package/examples/nextjs-app-router-openai/.env.example +5 -0
- package/examples/nextjs-app-router-openai/README.md +29 -0
- package/examples/nextjs-app-router-openai/app/api/chat/route.ts +22 -0
- package/examples/nextjs-app-router-openai/app/globals.css +21 -0
- package/examples/nextjs-app-router-openai/app/layout.tsx +21 -0
- package/examples/nextjs-app-router-openai/app/page.tsx +43 -0
- package/examples/nextjs-app-router-openai/next.config.mjs +7 -0
- package/examples/nextjs-app-router-openai/package.json +31 -0
- package/examples/nextjs-app-router-openai/postcss.config.mjs +9 -0
- package/examples/nextjs-app-router-openai/tailwind.config.ts +13 -0
- package/examples/nextjs-app-router-openai/tsconfig.json +27 -0
- package/examples/nextjs-saas-starter/README.md +29 -0
- package/examples/nextjs-saas-starter/app/api/chat/route.ts +65 -0
- package/examples/nextjs-saas-starter/app/api/checkout/route.ts +51 -0
- package/examples/nextjs-saas-starter/app/globals.css +14 -0
- package/examples/nextjs-saas-starter/app/layout.tsx +24 -0
- package/examples/nextjs-saas-starter/app/page.tsx +326 -0
- package/examples/nextjs-saas-starter/next.config.mjs +7 -0
- package/examples/nextjs-saas-starter/package.json +34 -0
- package/examples/nextjs-saas-starter/postcss.config.mjs +9 -0
- package/examples/nextjs-saas-starter/tailwind.config.ts +20 -0
- package/examples/nextjs-saas-starter/tsconfig.json +27 -0
- package/package.json +188 -186
package/bin/examples.js
ADDED
package/bin/vibezcheck.js
CHANGED
|
File without changes
|
package/dist/ai-sdk/index.d.mts
CHANGED
|
@@ -1,9 +1,48 @@
|
|
|
1
|
-
import { W as WithBillingOptions } from '../with-billing-
|
|
2
|
-
export { m as meteredModel, w as withBilling } from '../with-billing-
|
|
3
|
-
import { C as CustomerParam } from '../types-
|
|
4
|
-
import { V as VibezMeter } from '../client-
|
|
1
|
+
import { W as WithBillingOptions } from '../with-billing-BEqiJtCR.mjs';
|
|
2
|
+
export { m as meteredModel, w as withBilling } from '../with-billing-BEqiJtCR.mjs';
|
|
3
|
+
import { C as CustomerParam } from '../types-Btf2OhIr.mjs';
|
|
4
|
+
import { V as VibezMeter } from '../client-BzwEHQlC.mjs';
|
|
5
5
|
import 'stripe';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* ✦ VibezCheck Universal Telemetry Response Stream Injector
|
|
9
|
+
*
|
|
10
|
+
* Transmits real-time verified token counts, exact dollar costs, profit margins,
|
|
11
|
+
* and model telemetry from the server into AI SDK useChat() across all versions:
|
|
12
|
+
* - AI SDK v5/v6/v7 (UI Message Stream): Injects `data-vibezcheck` and `message-metadata` SSE events
|
|
13
|
+
* - AI SDK v4 (Data Stream Protocol): Injects `2:[{"type":"vibezcheck", ...}]` message annotation lines
|
|
14
|
+
* - Custom / Text Streams: Injects clean telemetry without breaking stream parsers
|
|
15
|
+
*/
|
|
16
|
+
interface ToResponseOptions {
|
|
17
|
+
/** Custom ResponseInit (status, statusText, headers) */
|
|
18
|
+
init?: ResponseInit;
|
|
19
|
+
/** Additional HTTP headers */
|
|
20
|
+
headers?: HeadersInit;
|
|
21
|
+
/** Explicit telemetry payload override */
|
|
22
|
+
telemetry?: any;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Transforms an AI SDK stream result (or standard Response) into a client-ready HTTP Response
|
|
26
|
+
* that transmits both AI completion chunks and verified VibezCheck telemetry.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { streamText } from 'ai';
|
|
31
|
+
* import { openai } from '@ai-sdk/openai';
|
|
32
|
+
* import { vibezcheck } from 'vibezcheck';
|
|
33
|
+
*
|
|
34
|
+
* export async function POST(req: Request) {
|
|
35
|
+
* const { messages } = await req.json();
|
|
36
|
+
* const result = streamText({
|
|
37
|
+
* model: vibezcheck(openai('gpt-4o'), { customer: 'cus_123' }),
|
|
38
|
+
* messages,
|
|
39
|
+
* });
|
|
40
|
+
* return vibezcheck.toResponse(result);
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function toResponse(result: any, options?: ToResponseOptions): Response;
|
|
45
|
+
|
|
7
46
|
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
8
47
|
/** OpenAI / Anthropic / AI Gateway API Key override */
|
|
9
48
|
apiKey?: string;
|
|
@@ -69,6 +108,7 @@ declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptio
|
|
|
69
108
|
declare function createVibezSession(sessionOptions?: VibezSessionOptions): VibezSession;
|
|
70
109
|
declare const vibezcheck: typeof createVibezModel & {
|
|
71
110
|
session: typeof createVibezSession;
|
|
111
|
+
toResponse: typeof toResponse;
|
|
72
112
|
};
|
|
73
113
|
|
|
74
|
-
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, WithBillingOptions, createVibezModel, createVibezSession, vibezcheck };
|
|
114
|
+
export { type ToResponseOptions, type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, WithBillingOptions, createVibezModel, createVibezSession, toResponse, vibezcheck };
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,9 +1,48 @@
|
|
|
1
|
-
import { W as WithBillingOptions } from '../with-billing-
|
|
2
|
-
export { m as meteredModel, w as withBilling } from '../with-billing-
|
|
3
|
-
import { C as CustomerParam } from '../types-
|
|
4
|
-
import { V as VibezMeter } from '../client-
|
|
1
|
+
import { W as WithBillingOptions } from '../with-billing-D7QRoNHM.js';
|
|
2
|
+
export { m as meteredModel, w as withBilling } from '../with-billing-D7QRoNHM.js';
|
|
3
|
+
import { C as CustomerParam } from '../types-Btf2OhIr.js';
|
|
4
|
+
import { V as VibezMeter } from '../client-CbO6vLUe.js';
|
|
5
5
|
import 'stripe';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* ✦ VibezCheck Universal Telemetry Response Stream Injector
|
|
9
|
+
*
|
|
10
|
+
* Transmits real-time verified token counts, exact dollar costs, profit margins,
|
|
11
|
+
* and model telemetry from the server into AI SDK useChat() across all versions:
|
|
12
|
+
* - AI SDK v5/v6/v7 (UI Message Stream): Injects `data-vibezcheck` and `message-metadata` SSE events
|
|
13
|
+
* - AI SDK v4 (Data Stream Protocol): Injects `2:[{"type":"vibezcheck", ...}]` message annotation lines
|
|
14
|
+
* - Custom / Text Streams: Injects clean telemetry without breaking stream parsers
|
|
15
|
+
*/
|
|
16
|
+
interface ToResponseOptions {
|
|
17
|
+
/** Custom ResponseInit (status, statusText, headers) */
|
|
18
|
+
init?: ResponseInit;
|
|
19
|
+
/** Additional HTTP headers */
|
|
20
|
+
headers?: HeadersInit;
|
|
21
|
+
/** Explicit telemetry payload override */
|
|
22
|
+
telemetry?: any;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Transforms an AI SDK stream result (or standard Response) into a client-ready HTTP Response
|
|
26
|
+
* that transmits both AI completion chunks and verified VibezCheck telemetry.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { streamText } from 'ai';
|
|
31
|
+
* import { openai } from '@ai-sdk/openai';
|
|
32
|
+
* import { vibezcheck } from 'vibezcheck';
|
|
33
|
+
*
|
|
34
|
+
* export async function POST(req: Request) {
|
|
35
|
+
* const { messages } = await req.json();
|
|
36
|
+
* const result = streamText({
|
|
37
|
+
* model: vibezcheck(openai('gpt-4o'), { customer: 'cus_123' }),
|
|
38
|
+
* messages,
|
|
39
|
+
* });
|
|
40
|
+
* return vibezcheck.toResponse(result);
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function toResponse(result: any, options?: ToResponseOptions): Response;
|
|
45
|
+
|
|
7
46
|
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
8
47
|
/** OpenAI / Anthropic / AI Gateway API Key override */
|
|
9
48
|
apiKey?: string;
|
|
@@ -69,6 +108,7 @@ declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptio
|
|
|
69
108
|
declare function createVibezSession(sessionOptions?: VibezSessionOptions): VibezSession;
|
|
70
109
|
declare const vibezcheck: typeof createVibezModel & {
|
|
71
110
|
session: typeof createVibezSession;
|
|
111
|
+
toResponse: typeof toResponse;
|
|
72
112
|
};
|
|
73
113
|
|
|
74
|
-
export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, WithBillingOptions, createVibezModel, createVibezSession, vibezcheck };
|
|
114
|
+
export { type ToResponseOptions, type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, WithBillingOptions, createVibezModel, createVibezSession, toResponse, vibezcheck };
|
package/dist/ai-sdk/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(ai_sdk_exports, {
|
|
|
33
33
|
createVibezModel: () => createVibezModel,
|
|
34
34
|
createVibezSession: () => createVibezSession,
|
|
35
35
|
meteredModel: () => meteredModel,
|
|
36
|
+
toResponse: () => toResponse,
|
|
36
37
|
vibezcheck: () => vibezcheck,
|
|
37
38
|
withBilling: () => withBilling
|
|
38
39
|
});
|
|
@@ -844,8 +845,10 @@ function calculateCost(params) {
|
|
|
844
845
|
outputCostUSD: Number(outputCostUSD.toFixed(8)),
|
|
845
846
|
reasoningCostUSD: reasoningTokens > 0n ? Number(reasoningCostUSD.toFixed(8)) : void 0,
|
|
846
847
|
cachedDiscountUSD: cachedTokens > 0n ? Number(cachedDiscountUSD.toFixed(8)) : void 0,
|
|
848
|
+
savingsUSD: cachedTokens > 0n ? Number(cachedDiscountUSD.toFixed(8)) : void 0,
|
|
847
849
|
totalUSD: Number(totalUSD.toFixed(8)),
|
|
848
850
|
wholesaleTotalUSD: Number(wholesaleTotalUSD.toFixed(8)),
|
|
851
|
+
wholesaleUSD: Number(wholesaleTotalUSD.toFixed(8)),
|
|
849
852
|
billedUSD: Number(billedUSD.toFixed(8)),
|
|
850
853
|
profitUSD: Number(profitUSD.toFixed(8)),
|
|
851
854
|
retailUSD: retailUSD !== void 0 ? Number(retailUSD.toFixed(8)) : void 0,
|
|
@@ -1067,7 +1070,7 @@ var VibezMeter = class {
|
|
|
1067
1070
|
stripeClient;
|
|
1068
1071
|
markupMultiplier;
|
|
1069
1072
|
constructor(options = {}) {
|
|
1070
|
-
this.markupMultiplier = options.markupMultiplier;
|
|
1073
|
+
this.markupMultiplier = options.pricing?.margin ?? options.markupMultiplier;
|
|
1071
1074
|
if (options.stripe) {
|
|
1072
1075
|
this.stripeClient = options.stripe;
|
|
1073
1076
|
} else if (options.apiKey || process.env.STRIPE_SECRET_KEY) {
|
|
@@ -1075,7 +1078,7 @@ var VibezMeter = class {
|
|
|
1075
1078
|
this.stripeClient = new import_stripe.default(key, {
|
|
1076
1079
|
appInfo: {
|
|
1077
1080
|
name: "vibezcheck",
|
|
1078
|
-
version: "0.5.
|
|
1081
|
+
version: "0.5.5",
|
|
1079
1082
|
url: "https://vibezcheck.xyz"
|
|
1080
1083
|
}
|
|
1081
1084
|
});
|
|
@@ -1415,6 +1418,7 @@ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
|
|
|
1415
1418
|
}
|
|
1416
1419
|
}
|
|
1417
1420
|
scheduleFlush();
|
|
1421
|
+
return event;
|
|
1418
1422
|
};
|
|
1419
1423
|
const handler = {
|
|
1420
1424
|
get(target, prop, receiver) {
|
|
@@ -1477,7 +1481,22 @@ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
|
|
|
1477
1481
|
const chunkUsage = (chunk.type === "finish" ? chunk.usage : null) || chunk.usage || chunk.token_usage || chunk.usageMetadata;
|
|
1478
1482
|
if (chunkUsage) {
|
|
1479
1483
|
streamCompleted = true;
|
|
1480
|
-
handleUsage(chunkUsage);
|
|
1484
|
+
const event = handleUsage(chunkUsage);
|
|
1485
|
+
if (chunk.type === "finish" && event) {
|
|
1486
|
+
chunk.providerMetadata = {
|
|
1487
|
+
...chunk.providerMetadata,
|
|
1488
|
+
vibezcheck: {
|
|
1489
|
+
type: "vibezcheck",
|
|
1490
|
+
cost: event.cost,
|
|
1491
|
+
usage: event.usage,
|
|
1492
|
+
model: modelId,
|
|
1493
|
+
provider,
|
|
1494
|
+
customerId,
|
|
1495
|
+
customerEmail,
|
|
1496
|
+
timestamp: event.timestamp
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1481
1500
|
}
|
|
1482
1501
|
},
|
|
1483
1502
|
flush() {
|
|
@@ -1532,6 +1551,142 @@ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
|
|
|
1532
1551
|
}
|
|
1533
1552
|
var meteredModel = withBilling;
|
|
1534
1553
|
|
|
1554
|
+
// src/ai-sdk/to-response.ts
|
|
1555
|
+
function toResponse(result, options) {
|
|
1556
|
+
let baseResponse;
|
|
1557
|
+
if (typeof result?.toUIMessageStreamResponse === "function") {
|
|
1558
|
+
baseResponse = result.toUIMessageStreamResponse(options?.init);
|
|
1559
|
+
} else if (typeof result?.toDataStreamResponse === "function") {
|
|
1560
|
+
baseResponse = result.toDataStreamResponse(options?.init);
|
|
1561
|
+
} else if (typeof result?.toTextStreamResponse === "function") {
|
|
1562
|
+
baseResponse = result.toTextStreamResponse(options?.init);
|
|
1563
|
+
} else if (result instanceof Response) {
|
|
1564
|
+
baseResponse = result;
|
|
1565
|
+
} else if (result && typeof result === "object" && result.body && result.headers) {
|
|
1566
|
+
baseResponse = result;
|
|
1567
|
+
} else {
|
|
1568
|
+
baseResponse = new Response(result, options?.init);
|
|
1569
|
+
}
|
|
1570
|
+
if (!baseResponse.body) {
|
|
1571
|
+
return baseResponse;
|
|
1572
|
+
}
|
|
1573
|
+
const contentType = baseResponse.headers.get("content-type") || "";
|
|
1574
|
+
const isSSE = contentType.includes("text/event-stream") || baseResponse.headers.has("x-vercel-ai-ui-message-stream");
|
|
1575
|
+
const isDataStream = baseResponse.headers.has("x-vercel-ai-data-stream");
|
|
1576
|
+
const encoder = new TextEncoder();
|
|
1577
|
+
const decoder = new TextDecoder();
|
|
1578
|
+
let injected = false;
|
|
1579
|
+
const resolveTelemetry = async () => {
|
|
1580
|
+
if (options?.telemetry) return options.telemetry;
|
|
1581
|
+
if (result?.providerMetadata) {
|
|
1582
|
+
try {
|
|
1583
|
+
const meta = await Promise.race([
|
|
1584
|
+
result.providerMetadata,
|
|
1585
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 800))
|
|
1586
|
+
]);
|
|
1587
|
+
if (meta?.vibezcheck) {
|
|
1588
|
+
return meta.vibezcheck;
|
|
1589
|
+
}
|
|
1590
|
+
} catch {
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
if (result?.usage) {
|
|
1594
|
+
try {
|
|
1595
|
+
const u = await Promise.race([
|
|
1596
|
+
result.usage,
|
|
1597
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 800))
|
|
1598
|
+
]);
|
|
1599
|
+
if (u) {
|
|
1600
|
+
const inputTokens = u.promptTokens ?? u.inputTokens ?? 0;
|
|
1601
|
+
const outputTokens = u.completionTokens ?? u.outputTokens ?? 0;
|
|
1602
|
+
const reasoningTokens = u.reasoningTokens ?? u.completionTokensDetails?.reasoningTokens;
|
|
1603
|
+
return {
|
|
1604
|
+
type: "vibezcheck",
|
|
1605
|
+
usage: {
|
|
1606
|
+
inputTokens,
|
|
1607
|
+
outputTokens,
|
|
1608
|
+
totalTokens: inputTokens + outputTokens,
|
|
1609
|
+
reasoningTokens
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
} catch {
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
return null;
|
|
1617
|
+
};
|
|
1618
|
+
const transformStream = new TransformStream({
|
|
1619
|
+
async transform(chunk, controller) {
|
|
1620
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
1621
|
+
if (isSSE && text.includes("[DONE]") && !injected) {
|
|
1622
|
+
injected = true;
|
|
1623
|
+
const telemetry = await resolveTelemetry();
|
|
1624
|
+
if (telemetry) {
|
|
1625
|
+
const ssePayload = `data: ${JSON.stringify({ type: "data-vibezcheck", data: telemetry })}
|
|
1626
|
+
|
|
1627
|
+
data: ${JSON.stringify({ type: "message-metadata", messageMetadata: { vibezcheck: telemetry } })}
|
|
1628
|
+
|
|
1629
|
+
`;
|
|
1630
|
+
const doneIndex = text.indexOf("data: [DONE]");
|
|
1631
|
+
if (doneIndex !== -1) {
|
|
1632
|
+
const before = text.slice(0, doneIndex);
|
|
1633
|
+
const after = text.slice(doneIndex);
|
|
1634
|
+
if (before) controller.enqueue(encoder.encode(before));
|
|
1635
|
+
controller.enqueue(encoder.encode(ssePayload));
|
|
1636
|
+
controller.enqueue(encoder.encode(after));
|
|
1637
|
+
return;
|
|
1638
|
+
} else {
|
|
1639
|
+
controller.enqueue(encoder.encode(ssePayload));
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
} else if (isDataStream && (text.includes("d:{") || text.includes("d: {")) && !injected) {
|
|
1643
|
+
injected = true;
|
|
1644
|
+
const telemetry = await resolveTelemetry();
|
|
1645
|
+
if (telemetry) {
|
|
1646
|
+
const annotationLine = `2:[${JSON.stringify(telemetry)}]
|
|
1647
|
+
`;
|
|
1648
|
+
controller.enqueue(encoder.encode(annotationLine));
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
controller.enqueue(chunk);
|
|
1652
|
+
},
|
|
1653
|
+
async flush(controller) {
|
|
1654
|
+
if (!injected) {
|
|
1655
|
+
injected = true;
|
|
1656
|
+
const telemetry = await resolveTelemetry();
|
|
1657
|
+
if (telemetry) {
|
|
1658
|
+
if (isSSE) {
|
|
1659
|
+
const ssePayload = `data: ${JSON.stringify({ type: "data-vibezcheck", data: telemetry })}
|
|
1660
|
+
|
|
1661
|
+
data: ${JSON.stringify({ type: "message-metadata", messageMetadata: { vibezcheck: telemetry } })}
|
|
1662
|
+
|
|
1663
|
+
`;
|
|
1664
|
+
controller.enqueue(encoder.encode(ssePayload));
|
|
1665
|
+
} else {
|
|
1666
|
+
const annotationLine = `2:[${JSON.stringify(telemetry)}]
|
|
1667
|
+
`;
|
|
1668
|
+
controller.enqueue(encoder.encode(annotationLine));
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
const mergedHeaders = new Headers(baseResponse.headers);
|
|
1675
|
+
if (options?.headers) {
|
|
1676
|
+
const extraHeaders = new Headers(options.headers);
|
|
1677
|
+
extraHeaders.forEach((value, key) => {
|
|
1678
|
+
mergedHeaders.set(key, value);
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
const status = options?.init?.status ?? baseResponse.status;
|
|
1682
|
+
const statusText = options?.init?.statusText ?? baseResponse.statusText;
|
|
1683
|
+
return new Response(baseResponse.body.pipeThrough(transformStream), {
|
|
1684
|
+
status,
|
|
1685
|
+
statusText,
|
|
1686
|
+
headers: mergedHeaders
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1535
1690
|
// src/ai-sdk/declarative.ts
|
|
1536
1691
|
function createVibezModel(modelOrId, options = {}) {
|
|
1537
1692
|
if (typeof modelOrId === "object" && modelOrId !== null) {
|
|
@@ -1706,13 +1861,15 @@ function createVibezSession(sessionOptions = {}) {
|
|
|
1706
1861
|
};
|
|
1707
1862
|
}
|
|
1708
1863
|
var vibezcheck = Object.assign(createVibezModel, {
|
|
1709
|
-
session: createVibezSession
|
|
1864
|
+
session: createVibezSession,
|
|
1865
|
+
toResponse
|
|
1710
1866
|
});
|
|
1711
1867
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1712
1868
|
0 && (module.exports = {
|
|
1713
1869
|
createVibezModel,
|
|
1714
1870
|
createVibezSession,
|
|
1715
1871
|
meteredModel,
|
|
1872
|
+
toResponse,
|
|
1716
1873
|
vibezcheck,
|
|
1717
1874
|
withBilling
|
|
1718
1875
|
});
|