vibezcheck 0.2.0 → 0.3.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/dist/index.d.mts CHANGED
@@ -1,16 +1,17 @@
1
- import { M as MeterOptions, S as StreamWrapOptions, C as CustomerParam, U as UsageEvent, a as UsageSummary } from './types-CSrSmsd1.mjs';
2
- export { I as InferenceCost, b as ModelPricingRates, R as RecordUsageOptions, T as TokenUsage } from './types-CSrSmsd1.mjs';
3
- import { V as VibezMeter } from './client-MJ3tl7bz.mjs';
4
- export { c as createMeter } from './client-MJ3tl7bz.mjs';
1
+ export { AnthropicStreamAccumulator, ExtractedUsage, MeterBatcher, UsageDispatchedCallback, detectAndExtractUsage, extractAnthropicResponseUsage, extractGeminiResponseUsage, extractGenericResponseUsage, extractOpenAIResponseUsage, inspectOpenAIStreamChunk, trackTokens, wrapAnthropicStream, wrapGeminiStream, wrapOpenAIStream, wrapStream, wrapUniversalStream } from './meter/index.mjs';
2
+ import { VibezCheckModelOptions, withBilling } from './ai-sdk/index.mjs';
3
+ export { WithBillingOptions, createVibezModel, meteredModel } from './ai-sdk/index.mjs';
4
+ import { calculateCost, getModelPricing, registerModelPricing } from './pricing/index.mjs';
5
+ export { CalculateCostParams, MODEL_PRICING_TABLE, calculateUsageCost, normalizeModelKey } from './pricing/index.mjs';
6
+ import { M as MeterOptions, S as StreamWrapOptions, C as CustomerParam, U as UsageEvent, a as UsageSummary } from './types-DCuzLVyc.mjs';
7
+ export { B as BudgetExceededEvent, b as CircuitBreakerOptions, I as InferenceCost, K as KnownModel, c as ModelPricingRates, R as RecordUsageOptions, d as SupportedAnthropicModel, e as SupportedDeepSeekModel, f as SupportedGoogleModel, g as SupportedModel, h as SupportedOpenAIModel, T as TokenUsage, V as VibezCircuitBreakerError } from './types-DCuzLVyc.mjs';
8
+ import { V as VibezMeter, c as createMeter } from './client-C67DW_tR.mjs';
5
9
  import { CustomerManager } from './customers/index.mjs';
6
10
  export { CustomerCache, CustomerManagerOptions, GetOrCreateCustomerParams, createCustomerManager } from './customers/index.mjs';
7
11
  import { ApiKeyAuth } from './auth/index.mjs';
8
12
  export { ApiKeyRecord, CreateApiKeyParams, VerifyAuthResult, createApiKeyAuth, extractAuthToken } from './auth/index.mjs';
9
13
  import { BillingHelper } from './billing/index.mjs';
10
14
  export { CreateCheckoutSessionParams, CreatePortalSessionParams, CreateTopUpSessionParams, createBillingHelper } from './billing/index.mjs';
11
- export { AnthropicStreamAccumulator, ExtractedUsage, MeterBatcher, UsageDispatchedCallback, detectAndExtractUsage, extractAnthropicResponseUsage, extractGeminiResponseUsage, extractGenericResponseUsage, extractOpenAIResponseUsage, inspectOpenAIStreamChunk, trackTokens, wrapAnthropicStream, wrapGeminiStream, wrapOpenAIStream, wrapStream, wrapUniversalStream } from './meter/index.mjs';
12
- export { CalculateCostParams, MODEL_PRICING_TABLE, calculateCost, calculateUsageCost, getModelPricing, normalizeModelKey, registerModelPricing } from './pricing/index.mjs';
13
- export { WithBillingOptions, meteredModel, withBilling } from './ai-sdk/index.mjs';
14
15
  import 'stripe';
15
16
 
16
17
  /**
@@ -48,17 +49,9 @@ declare class VibezCheckClient {
48
49
  customer?: CustomerParam;
49
50
  }): T;
50
51
  /**
51
- * 1-Line Universal Stream Responder for API Routes (Next.js, Express, Hono)
52
+ * Declarative model resolver for Vercel AI SDK
52
53
  */
53
- stream(params: {
54
- model: string;
55
- messages: Array<{
56
- role: string;
57
- content: string;
58
- }>;
59
- customer?: CustomerParam;
60
- temperature?: number;
61
- }): Promise<Response>;
54
+ model(modelOrId: any, options?: VibezCheckModelOptions): any;
62
55
  /**
63
56
  * Flush pending meter events (vital for serverless runtimes)
64
57
  */
@@ -73,20 +66,50 @@ declare class VibezCheckClient {
73
66
  */
74
67
  declare function createVibezCheck(config?: VibezCheckConfig): VibezCheckClient;
75
68
  /**
76
- * vibezcheck factory alias
69
+ * Declarative 1-line factory & model resolver for Vercel AI SDK
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * import { generateText, streamText } from 'ai';
74
+ * import { vibezcheck } from 'vibezcheck';
75
+ *
76
+ * // 1. Use string model identifier:
77
+ * const { text } = await generateText({
78
+ * model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
79
+ * prompt: 'What is love?',
80
+ * });
81
+ *
82
+ * // 2. Use with streamText:
83
+ * const result = streamText({
84
+ * model: vibezcheck('gpt-4o-mini', { customer: 'alex@example.com' }),
85
+ * messages,
86
+ * });
87
+ *
88
+ * // 3. Wrap existing model instance:
89
+ * const result = streamText({
90
+ * model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
91
+ * messages,
92
+ * });
93
+ * ```
77
94
  */
78
- declare const vibezcheck: typeof createVibezCheck;
79
- /**
80
- * vibescheck alias (tolerates spelling difference)
81
- */
82
- declare const vibescheck: typeof createVibezCheck;
95
+ declare function vibezcheck(modelOrId: any, options?: VibezCheckModelOptions): any;
96
+ declare function vibezcheck(config?: VibezCheckConfig): VibezCheckClient;
97
+ declare namespace vibezcheck {
98
+ var calculateCost: typeof calculateCost;
99
+ var getModelPricing: typeof getModelPricing;
100
+ var registerModelPricing: typeof registerModelPricing;
101
+ var create: typeof createVibezCheck;
102
+ var withBilling: typeof withBilling;
103
+ var createMeter: typeof createMeter;
104
+ }
83
105
  /**
84
- * Singleton instance initialized with process.env
106
+ * Singleton client instance
85
107
  */
86
108
  declare const vibez: VibezCheckClient;
87
109
  /**
88
- * Singleton alias
110
+ * Aliases for developer typing convenience
89
111
  */
112
+ declare const vibescheck: typeof vibezcheck;
90
113
  declare const vibes: VibezCheckClient;
91
114
 
92
- export { ApiKeyAuth, BillingHelper, CustomerManager, CustomerParam, MeterOptions, StreamWrapOptions, UsageEvent, UsageSummary, VibezCheckClient, type VibezCheckConfig, VibezMeter, createVibezCheck, vibes, vibescheck, vibez, vibezcheck };
115
+ export { ApiKeyAuth, BillingHelper, CustomerManager, CustomerParam, MeterOptions, StreamWrapOptions, UsageEvent, UsageSummary, VibezCheckClient, type VibezCheckConfig, VibezCheckModelOptions, VibezMeter, calculateCost, createMeter, createVibezCheck, getModelPricing, registerModelPricing, vibes, vibescheck, vibez, vibezcheck, withBilling };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,17 @@
1
- import { M as MeterOptions, S as StreamWrapOptions, C as CustomerParam, U as UsageEvent, a as UsageSummary } from './types-CSrSmsd1.js';
2
- export { I as InferenceCost, b as ModelPricingRates, R as RecordUsageOptions, T as TokenUsage } from './types-CSrSmsd1.js';
3
- import { V as VibezMeter } from './client-txrE0D_D.js';
4
- export { c as createMeter } from './client-txrE0D_D.js';
1
+ export { AnthropicStreamAccumulator, ExtractedUsage, MeterBatcher, UsageDispatchedCallback, detectAndExtractUsage, extractAnthropicResponseUsage, extractGeminiResponseUsage, extractGenericResponseUsage, extractOpenAIResponseUsage, inspectOpenAIStreamChunk, trackTokens, wrapAnthropicStream, wrapGeminiStream, wrapOpenAIStream, wrapStream, wrapUniversalStream } from './meter/index.js';
2
+ import { VibezCheckModelOptions, withBilling } from './ai-sdk/index.js';
3
+ export { WithBillingOptions, createVibezModel, meteredModel } from './ai-sdk/index.js';
4
+ import { calculateCost, getModelPricing, registerModelPricing } from './pricing/index.js';
5
+ export { CalculateCostParams, MODEL_PRICING_TABLE, calculateUsageCost, normalizeModelKey } from './pricing/index.js';
6
+ import { M as MeterOptions, S as StreamWrapOptions, C as CustomerParam, U as UsageEvent, a as UsageSummary } from './types-DCuzLVyc.js';
7
+ export { B as BudgetExceededEvent, b as CircuitBreakerOptions, I as InferenceCost, K as KnownModel, c as ModelPricingRates, R as RecordUsageOptions, d as SupportedAnthropicModel, e as SupportedDeepSeekModel, f as SupportedGoogleModel, g as SupportedModel, h as SupportedOpenAIModel, T as TokenUsage, V as VibezCircuitBreakerError } from './types-DCuzLVyc.js';
8
+ import { V as VibezMeter, c as createMeter } from './client-S3qmTXTR.js';
5
9
  import { CustomerManager } from './customers/index.js';
6
10
  export { CustomerCache, CustomerManagerOptions, GetOrCreateCustomerParams, createCustomerManager } from './customers/index.js';
7
11
  import { ApiKeyAuth } from './auth/index.js';
8
12
  export { ApiKeyRecord, CreateApiKeyParams, VerifyAuthResult, createApiKeyAuth, extractAuthToken } from './auth/index.js';
9
13
  import { BillingHelper } from './billing/index.js';
10
14
  export { CreateCheckoutSessionParams, CreatePortalSessionParams, CreateTopUpSessionParams, createBillingHelper } from './billing/index.js';
11
- export { AnthropicStreamAccumulator, ExtractedUsage, MeterBatcher, UsageDispatchedCallback, detectAndExtractUsage, extractAnthropicResponseUsage, extractGeminiResponseUsage, extractGenericResponseUsage, extractOpenAIResponseUsage, inspectOpenAIStreamChunk, trackTokens, wrapAnthropicStream, wrapGeminiStream, wrapOpenAIStream, wrapStream, wrapUniversalStream } from './meter/index.js';
12
- export { CalculateCostParams, MODEL_PRICING_TABLE, calculateCost, calculateUsageCost, getModelPricing, normalizeModelKey, registerModelPricing } from './pricing/index.js';
13
- export { WithBillingOptions, meteredModel, withBilling } from './ai-sdk/index.js';
14
15
  import 'stripe';
15
16
 
16
17
  /**
@@ -48,17 +49,9 @@ declare class VibezCheckClient {
48
49
  customer?: CustomerParam;
49
50
  }): T;
50
51
  /**
51
- * 1-Line Universal Stream Responder for API Routes (Next.js, Express, Hono)
52
+ * Declarative model resolver for Vercel AI SDK
52
53
  */
53
- stream(params: {
54
- model: string;
55
- messages: Array<{
56
- role: string;
57
- content: string;
58
- }>;
59
- customer?: CustomerParam;
60
- temperature?: number;
61
- }): Promise<Response>;
54
+ model(modelOrId: any, options?: VibezCheckModelOptions): any;
62
55
  /**
63
56
  * Flush pending meter events (vital for serverless runtimes)
64
57
  */
@@ -73,20 +66,50 @@ declare class VibezCheckClient {
73
66
  */
74
67
  declare function createVibezCheck(config?: VibezCheckConfig): VibezCheckClient;
75
68
  /**
76
- * vibezcheck factory alias
69
+ * Declarative 1-line factory & model resolver for Vercel AI SDK
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * import { generateText, streamText } from 'ai';
74
+ * import { vibezcheck } from 'vibezcheck';
75
+ *
76
+ * // 1. Use string model identifier:
77
+ * const { text } = await generateText({
78
+ * model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
79
+ * prompt: 'What is love?',
80
+ * });
81
+ *
82
+ * // 2. Use with streamText:
83
+ * const result = streamText({
84
+ * model: vibezcheck('gpt-4o-mini', { customer: 'alex@example.com' }),
85
+ * messages,
86
+ * });
87
+ *
88
+ * // 3. Wrap existing model instance:
89
+ * const result = streamText({
90
+ * model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
91
+ * messages,
92
+ * });
93
+ * ```
77
94
  */
78
- declare const vibezcheck: typeof createVibezCheck;
79
- /**
80
- * vibescheck alias (tolerates spelling difference)
81
- */
82
- declare const vibescheck: typeof createVibezCheck;
95
+ declare function vibezcheck(modelOrId: any, options?: VibezCheckModelOptions): any;
96
+ declare function vibezcheck(config?: VibezCheckConfig): VibezCheckClient;
97
+ declare namespace vibezcheck {
98
+ var calculateCost: typeof calculateCost;
99
+ var getModelPricing: typeof getModelPricing;
100
+ var registerModelPricing: typeof registerModelPricing;
101
+ var create: typeof createVibezCheck;
102
+ var withBilling: typeof withBilling;
103
+ var createMeter: typeof createMeter;
104
+ }
83
105
  /**
84
- * Singleton instance initialized with process.env
106
+ * Singleton client instance
85
107
  */
86
108
  declare const vibez: VibezCheckClient;
87
109
  /**
88
- * Singleton alias
110
+ * Aliases for developer typing convenience
89
111
  */
112
+ declare const vibescheck: typeof vibezcheck;
90
113
  declare const vibes: VibezCheckClient;
91
114
 
92
- export { ApiKeyAuth, BillingHelper, CustomerManager, CustomerParam, MeterOptions, StreamWrapOptions, UsageEvent, UsageSummary, VibezCheckClient, type VibezCheckConfig, VibezMeter, createVibezCheck, vibes, vibescheck, vibez, vibezcheck };
115
+ export { ApiKeyAuth, BillingHelper, CustomerManager, CustomerParam, MeterOptions, StreamWrapOptions, UsageEvent, UsageSummary, VibezCheckClient, type VibezCheckConfig, VibezCheckModelOptions, VibezMeter, calculateCost, createMeter, createVibezCheck, getModelPricing, registerModelPricing, vibes, vibescheck, vibez, vibezcheck, withBilling };
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ __export(src_exports, {
38
38
  MODEL_PRICING_TABLE: () => MODEL_PRICING_TABLE,
39
39
  MeterBatcher: () => MeterBatcher,
40
40
  VibezCheckClient: () => VibezCheckClient,
41
+ VibezCircuitBreakerError: () => VibezCircuitBreakerError,
41
42
  VibezMeter: () => VibezMeter,
42
43
  calculateCost: () => calculateCost,
43
44
  calculateUsageCost: () => calculateUsageCost,
@@ -46,6 +47,7 @@ __export(src_exports, {
46
47
  createCustomerManager: () => createCustomerManager,
47
48
  createMeter: () => createMeter,
48
49
  createVibezCheck: () => createVibezCheck,
50
+ createVibezModel: () => createVibezModel,
49
51
  detectAndExtractUsage: () => detectAndExtractUsage,
50
52
  extractAnthropicResponseUsage: () => extractAnthropicResponseUsage,
51
53
  extractAuthToken: () => extractAuthToken,
@@ -893,6 +895,16 @@ function createMeter(options = {}) {
893
895
  return new VibezMeter(options);
894
896
  }
895
897
 
898
+ // src/types.ts
899
+ var VibezCircuitBreakerError = class extends Error {
900
+ event;
901
+ constructor(event) {
902
+ super(event.message);
903
+ this.name = "VibezCircuitBreakerError";
904
+ this.event = event;
905
+ }
906
+ };
907
+
896
908
  // src/ai-sdk/with-billing.ts
897
909
  function withBilling(model, options = {}) {
898
910
  if (!model || typeof model !== "object") {
@@ -920,6 +932,38 @@ function withBilling(model, options = {}) {
920
932
  cachedTokens: cachedTokens > 0 ? cachedTokens : void 0
921
933
  };
922
934
  const cost = calculateUsageCost(modelId, usage);
935
+ if (options.maxCostPerCallUSD && cost.totalUSD > options.maxCostPerCallUSD) {
936
+ const budgetEvent = {
937
+ reason: "cost_per_call_exceeded",
938
+ limit: options.maxCostPerCallUSD,
939
+ current: cost.totalUSD,
940
+ model: modelId,
941
+ customerId,
942
+ message: `[vibezcheck] Circuit Breaker tripped: Call cost ($${cost.totalUSD.toFixed(4)}) exceeded maxCostPerCallUSD threshold ($${options.maxCostPerCallUSD.toFixed(4)}).`
943
+ };
944
+ if (options.onBudgetExceeded) {
945
+ options.onBudgetExceeded(budgetEvent);
946
+ }
947
+ if (options.throwOnBudgetExceeded) {
948
+ throw new VibezCircuitBreakerError(budgetEvent);
949
+ }
950
+ }
951
+ if (options.maxTokensPerCall && usage.totalTokens > options.maxTokensPerCall) {
952
+ const budgetEvent = {
953
+ reason: "max_tokens_exceeded",
954
+ limit: options.maxTokensPerCall,
955
+ current: usage.totalTokens,
956
+ model: modelId,
957
+ customerId,
958
+ message: `[vibezcheck] Circuit Breaker tripped: Token count (${usage.totalTokens}) exceeded maxTokensPerCall limit (${options.maxTokensPerCall}).`
959
+ };
960
+ if (options.onBudgetExceeded) {
961
+ options.onBudgetExceeded(budgetEvent);
962
+ }
963
+ if (options.throwOnBudgetExceeded) {
964
+ throw new VibezCircuitBreakerError(budgetEvent);
965
+ }
966
+ }
923
967
  const event = {
924
968
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
925
969
  model: modelId,
@@ -943,18 +987,9 @@ function withBilling(model, options = {}) {
943
987
  options.onUsage(event);
944
988
  }
945
989
  };
946
- return new Proxy(model, {
990
+ const handler = {
947
991
  get(target, prop, receiver) {
948
992
  const originalValue = Reflect.get(target, prop, receiver);
949
- if (prop === "doGenerate" && typeof originalValue === "function") {
950
- return async function(...args) {
951
- const result = await originalValue.apply(target, args);
952
- if (result && result.usage) {
953
- handleUsage(result.usage);
954
- }
955
- return result;
956
- };
957
- }
958
993
  if (prop === "doStream" && typeof originalValue === "function") {
959
994
  return async function(...args) {
960
995
  const result = await originalValue.apply(target, args);
@@ -962,61 +997,86 @@ function withBilling(model, options = {}) {
962
997
  return result;
963
998
  }
964
999
  const originalStream = result.stream;
965
- if (typeof originalStream.getReader === "function") {
966
- const reader = originalStream.getReader();
967
- const transformedStream = new ReadableStream({
968
- async start(controller) {
969
- try {
970
- while (true) {
971
- const { done, value } = await reader.read();
972
- if (done) {
973
- controller.close();
974
- break;
975
- }
976
- if (value && typeof value === "object") {
977
- if (value.type === "finish" && value.usage) {
978
- handleUsage(value.usage);
979
- }
980
- }
981
- controller.enqueue(value);
982
- }
983
- } catch (err) {
984
- controller.error(err);
985
- }
986
- }
987
- });
988
- return {
989
- ...result,
990
- stream: transformedStream
991
- };
992
- }
993
- if (Symbol.asyncIterator in originalStream) {
994
- const wrappedAsyncIterable = {
995
- async *[Symbol.asyncIterator]() {
996
- for await (const chunk of originalStream) {
997
- if (chunk && typeof chunk === "object") {
998
- if (chunk.type === "finish" && chunk.usage) {
999
- handleUsage(chunk.usage);
1000
- }
1001
- }
1002
- yield chunk;
1003
- }
1000
+ const transformStream = new TransformStream({
1001
+ transform(chunk, controller) {
1002
+ controller.enqueue(chunk);
1003
+ if (chunk.type === "finish" && chunk.usage) {
1004
+ handleUsage(chunk.usage);
1004
1005
  }
1005
- };
1006
- return {
1007
- ...result,
1008
- stream: wrappedAsyncIterable
1009
- };
1006
+ }
1007
+ });
1008
+ return {
1009
+ ...result,
1010
+ stream: originalStream.pipeThrough(transformStream)
1011
+ };
1012
+ };
1013
+ }
1014
+ if (prop === "doGenerate" && typeof originalValue === "function") {
1015
+ return async function(...args) {
1016
+ const result = await originalValue.apply(target, args);
1017
+ if (result && result.usage) {
1018
+ handleUsage(result.usage);
1010
1019
  }
1011
1020
  return result;
1012
1021
  };
1013
1022
  }
1014
1023
  return originalValue;
1015
1024
  }
1016
- });
1025
+ };
1026
+ return new Proxy(model, handler);
1017
1027
  }
1018
1028
  var meteredModel = withBilling;
1019
1029
 
1030
+ // src/ai-sdk/declarative.ts
1031
+ function createVibezModel(modelOrId, options = {}) {
1032
+ if (typeof modelOrId === "object" && modelOrId !== null) {
1033
+ return withBilling(modelOrId, options);
1034
+ }
1035
+ if (typeof modelOrId === "string") {
1036
+ const rawId = modelOrId;
1037
+ let providerName = "openai";
1038
+ let cleanModelId = rawId;
1039
+ if (rawId.includes("/")) {
1040
+ const parts = rawId.split("/");
1041
+ providerName = parts[0].toLowerCase();
1042
+ cleanModelId = parts.slice(1).join("/");
1043
+ }
1044
+ const apiKey = options.apiKey || process.env.AI_GATEWAY_API_KEY || process.env.OPENAI_API_KEY || process.env.ANTHROPIC_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY;
1045
+ const baseURL = options.baseURL || process.env.AI_GATEWAY_BASE_URL || (providerName === "openai" ? "https://api.openai.com/v1" : void 0);
1046
+ let baseModelInstance = null;
1047
+ try {
1048
+ if (providerName === "openai" || providerName === "gateway" || !providerName) {
1049
+ const { createOpenAI } = require("@ai-sdk/openai");
1050
+ const openaiProvider = createOpenAI({ apiKey, baseURL });
1051
+ baseModelInstance = openaiProvider(cleanModelId);
1052
+ } else if (providerName === "anthropic") {
1053
+ const { createAnthropic } = require("@ai-sdk/anthropic");
1054
+ const anthropicProvider = createAnthropic({ apiKey, baseURL });
1055
+ baseModelInstance = anthropicProvider(cleanModelId);
1056
+ } else if (providerName === "google") {
1057
+ const { createGoogleGenerativeAI } = require("@ai-sdk/google");
1058
+ const googleProvider = createGoogleGenerativeAI({ apiKey, baseURL });
1059
+ baseModelInstance = googleProvider(cleanModelId);
1060
+ }
1061
+ } catch {
1062
+ baseModelInstance = {
1063
+ specificationVersion: "v2",
1064
+ provider: providerName,
1065
+ modelId: cleanModelId
1066
+ };
1067
+ }
1068
+ if (!baseModelInstance) {
1069
+ baseModelInstance = {
1070
+ specificationVersion: "v2",
1071
+ provider: providerName,
1072
+ modelId: cleanModelId
1073
+ };
1074
+ }
1075
+ return withBilling(baseModelInstance, options);
1076
+ }
1077
+ return modelOrId;
1078
+ }
1079
+
1020
1080
  // src/customers/manager.ts
1021
1081
  var import_stripe2 = __toESM(require("stripe"));
1022
1082
 
@@ -1355,43 +1415,12 @@ var VibezCheckClient = class {
1355
1415
  });
1356
1416
  }
1357
1417
  /**
1358
- * 1-Line Universal Stream Responder for API Routes (Next.js, Express, Hono)
1418
+ * Declarative model resolver for Vercel AI SDK
1359
1419
  */
1360
- async stream(params) {
1361
- const OpenAI = (await import("openai")).default;
1362
- const openai = new OpenAI();
1363
- const responseStream = await openai.chat.completions.create({
1364
- model: params.model,
1365
- messages: params.messages,
1366
- stream: true,
1367
- stream_options: { include_usage: true },
1368
- temperature: params.temperature
1369
- });
1370
- const meteredStream = this.wrapStream(responseStream, {
1371
- customer: params.customer,
1372
- model: params.model
1373
- });
1374
- const encoder = new TextEncoder();
1375
- const readable = new ReadableStream({
1376
- async start(controller) {
1377
- try {
1378
- for await (const chunk of meteredStream) {
1379
- const text = chunk.choices?.[0]?.delta?.content || "";
1380
- if (text) {
1381
- controller.enqueue(encoder.encode(text));
1382
- }
1383
- }
1384
- controller.close();
1385
- } catch (err) {
1386
- controller.error(err);
1387
- }
1388
- }
1389
- });
1390
- return new Response(readable, {
1391
- headers: {
1392
- "Content-Type": "text/plain; charset=utf-8",
1393
- "Transfer-Encoding": "chunked"
1394
- }
1420
+ model(modelOrId, options) {
1421
+ return createVibezModel(modelOrId, {
1422
+ ...options,
1423
+ meter: this.meter
1395
1424
  });
1396
1425
  }
1397
1426
  /**
@@ -1410,9 +1439,20 @@ var VibezCheckClient = class {
1410
1439
  function createVibezCheck(config = {}) {
1411
1440
  return new VibezCheckClient(config);
1412
1441
  }
1413
- var vibezcheck = createVibezCheck;
1414
- var vibescheck = createVibezCheck;
1415
- var vibez = createVibezCheck();
1442
+ function vibezcheck(firstArg, secondArg) {
1443
+ if (typeof firstArg === "string" || firstArg && (firstArg.specificationVersion || firstArg.doGenerate || firstArg.doStream)) {
1444
+ return createVibezModel(firstArg, secondArg);
1445
+ }
1446
+ return new VibezCheckClient(firstArg || {});
1447
+ }
1448
+ vibezcheck.calculateCost = calculateCost;
1449
+ vibezcheck.getModelPricing = getModelPricing;
1450
+ vibezcheck.registerModelPricing = registerModelPricing;
1451
+ vibezcheck.create = createVibezCheck;
1452
+ vibezcheck.withBilling = withBilling;
1453
+ vibezcheck.createMeter = createMeter;
1454
+ var vibez = new VibezCheckClient();
1455
+ var vibescheck = vibezcheck;
1416
1456
  var vibes = vibez;
1417
1457
  // Annotate the CommonJS export names for ESM import in node:
1418
1458
  0 && (module.exports = {
@@ -1424,6 +1464,7 @@ var vibes = vibez;
1424
1464
  MODEL_PRICING_TABLE,
1425
1465
  MeterBatcher,
1426
1466
  VibezCheckClient,
1467
+ VibezCircuitBreakerError,
1427
1468
  VibezMeter,
1428
1469
  calculateCost,
1429
1470
  calculateUsageCost,
@@ -1432,6 +1473,7 @@ var vibes = vibez;
1432
1473
  createCustomerManager,
1433
1474
  createMeter,
1434
1475
  createVibezCheck,
1476
+ createVibezModel,
1435
1477
  detectAndExtractUsage,
1436
1478
  extractAnthropicResponseUsage,
1437
1479
  extractAuthToken,