vibezcheck 0.5.11 → 0.5.13
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/ai-sdk/index.d.mts +5 -5
- package/dist/ai-sdk/index.d.ts +5 -5
- package/dist/ai-sdk/index.js +45 -5
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +45 -5
- 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 +37 -3
- package/dist/ai-sdk/middleware.js.map +1 -1
- package/dist/ai-sdk/middleware.mjs +37 -3
- package/dist/ai-sdk/middleware.mjs.map +1 -1
- package/dist/billing/index.d.mts +8 -6
- package/dist/billing/index.d.ts +8 -6
- package/dist/billing/index.js +312 -6
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +319 -6
- package/dist/billing/index.mjs.map +1 -1
- package/dist/cli/index.js +8 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +8 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-eXSwD_kI.d.ts → client-0CuOBECi.d.ts} +1 -1
- package/dist/{client-ttJwYM7x.d.mts → client-xP86Qg_b.d.mts} +1 -1
- package/dist/customers/index.d.mts +1 -1
- package/dist/customers/index.d.ts +1 -1
- package/dist/database/index.d.mts +1 -1
- package/dist/database/index.d.ts +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -6
- 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 +35 -2
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +35 -2
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +27 -3
- package/dist/pricing/index.d.ts +27 -3
- package/dist/pricing/index.js +34 -1
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +34 -1
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/{session-D9fdP255.d.mts → session-CueUIV77.d.mts} +10 -4
- package/dist/{session-CUnv_muf.d.ts → session-YF67Yij2.d.ts} +10 -4
- package/dist/{types-DHlsaLvI.d.mts → types-CqXTmCNv.d.mts} +2 -0
- package/dist/{types-DHlsaLvI.d.ts → types-CqXTmCNv.d.ts} +2 -0
- package/dist/{with-billing-DhHGWCAp.d.mts → with-billing-Df6izlJ4.d.mts} +4 -2
- package/dist/{with-billing-CVGxl3ot.d.ts → with-billing-DgQ380Zl.d.ts} +4 -2
- package/examples/nextjs-app-router-openai/package.json +1 -1
- package/examples/nextjs-saas-starter/package.json +1 -1
- package/manifest/pricing-v1.json +4904 -974
- package/package.json +2 -1
package/dist/billing/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as AgentSession } from '../session-
|
|
2
|
-
export { a as AgentSessionOptions, T as ToolTrackingOptions, c as createAgentSession } from '../session-
|
|
3
|
-
import { C as CustomerParam } from '../types-
|
|
4
|
-
import '../with-billing-
|
|
5
|
-
import '../client-
|
|
1
|
+
import { A as AgentSession } from '../session-CueUIV77.mjs';
|
|
2
|
+
export { a as AgentSessionOptions, T as ToolTrackingOptions, c as createAgentSession } from '../session-CueUIV77.mjs';
|
|
3
|
+
import { C as CustomerParam } from '../types-CqXTmCNv.mjs';
|
|
4
|
+
import '../with-billing-Df6izlJ4.mjs';
|
|
5
|
+
import '../client-xP86Qg_b.mjs';
|
|
6
6
|
|
|
7
7
|
interface ToolOptions {
|
|
8
8
|
name?: string;
|
|
@@ -33,7 +33,9 @@ declare function instrumentToolKit<T extends Record<string, any>>(tools: T, opti
|
|
|
33
33
|
costPerActionUSD?: number;
|
|
34
34
|
session?: AgentSession;
|
|
35
35
|
costs?: Record<string, number>;
|
|
36
|
-
}
|
|
36
|
+
} | Record<string, {
|
|
37
|
+
costUSD: number;
|
|
38
|
+
} | number | any>): {
|
|
37
39
|
[K in keyof T]: T[K] & {
|
|
38
40
|
costUSD: number;
|
|
39
41
|
};
|
package/dist/billing/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as AgentSession } from '../session-
|
|
2
|
-
export { a as AgentSessionOptions, T as ToolTrackingOptions, c as createAgentSession } from '../session-
|
|
3
|
-
import { C as CustomerParam } from '../types-
|
|
4
|
-
import '../with-billing-
|
|
5
|
-
import '../client-
|
|
1
|
+
import { A as AgentSession } from '../session-YF67Yij2.js';
|
|
2
|
+
export { a as AgentSessionOptions, T as ToolTrackingOptions, c as createAgentSession } from '../session-YF67Yij2.js';
|
|
3
|
+
import { C as CustomerParam } from '../types-CqXTmCNv.js';
|
|
4
|
+
import '../with-billing-DgQ380Zl.js';
|
|
5
|
+
import '../client-0CuOBECi.js';
|
|
6
6
|
|
|
7
7
|
interface ToolOptions {
|
|
8
8
|
name?: string;
|
|
@@ -33,7 +33,9 @@ declare function instrumentToolKit<T extends Record<string, any>>(tools: T, opti
|
|
|
33
33
|
costPerActionUSD?: number;
|
|
34
34
|
session?: AgentSession;
|
|
35
35
|
costs?: Record<string, number>;
|
|
36
|
-
}
|
|
36
|
+
} | Record<string, {
|
|
37
|
+
costUSD: number;
|
|
38
|
+
} | number | any>): {
|
|
37
39
|
[K in keyof T]: T[K] & {
|
|
38
40
|
costUSD: number;
|
|
39
41
|
};
|
package/dist/billing/index.js
CHANGED
|
@@ -600,6 +600,10 @@ var MODEL_PRICING_TABLE = {
|
|
|
600
600
|
"text-embedding-3-large": { inputPer1M: 0.13, outputPer1M: 0 },
|
|
601
601
|
"text-embedding-ada-002": { inputPer1M: 0.1, outputPer1M: 0 },
|
|
602
602
|
// --- Anthropic (Modern & Extended Thinking) ---
|
|
603
|
+
"claude-haiku-5.5": { inputPer1M: 0.1, outputPer1M: 0.5, cachedInputPer1M: 0.01 },
|
|
604
|
+
"claude-sonnet-5.5": { inputPer1M: 2, outputPer1M: 10, cachedInputPer1M: 0.1 },
|
|
605
|
+
"claude-opus-5.5": { inputPer1M: 4, outputPer1M: 20, cachedInputPer1M: 0.2 },
|
|
606
|
+
"claude-opus-5.5-fast": { inputPer1M: 8, outputPer1M: 40, cachedInputPer1M: 0.4 },
|
|
603
607
|
"claude-3-7-sonnet": { inputPer1M: 0.59, outputPer1M: 2.93, cachedInputPer1M: 0.3 },
|
|
604
608
|
"claude-sonnet-5": { inputPer1M: 2, outputPer1M: 10, cachedInputPer1M: 0.3 },
|
|
605
609
|
"claude-3-5-sonnet": { inputPer1M: 3, outputPer1M: 15, cachedInputPer1M: 0.3 },
|
|
@@ -614,6 +618,8 @@ var MODEL_PRICING_TABLE = {
|
|
|
614
618
|
"claude-2.0": { inputPer1M: 8, outputPer1M: 24 },
|
|
615
619
|
"claude-instant-1.2": { inputPer1M: 1.63, outputPer1M: 5.51 },
|
|
616
620
|
// --- Google Gemini (Modern & Thoughts) ---
|
|
621
|
+
"gemini-3.8-flash": { inputPer1M: 0.75, outputPer1M: 3.75, cachedInputPer1M: 0.075 },
|
|
622
|
+
"gemini-nano-banana-2.1": { inputPer1M: 1.5, outputPer1M: 7.5, cachedInputPer1M: 0.15 },
|
|
617
623
|
"gemini-3.7-flash": { inputPer1M: 0.75, outputPer1M: 3.75, cachedInputPer1M: 0.18 },
|
|
618
624
|
"gemini-3.1-pro": { inputPer1M: 2, outputPer1M: 12, cachedInputPer1M: 0.5 },
|
|
619
625
|
"gemini-3.5-flash": { inputPer1M: 1.5, outputPer1M: 9, cachedInputPer1M: 0.38 },
|
|
@@ -636,6 +642,7 @@ var MODEL_PRICING_TABLE = {
|
|
|
636
642
|
"grok-2-vision": { inputPer1M: 2, outputPer1M: 10 },
|
|
637
643
|
"grok-beta": { inputPer1M: 5, outputPer1M: 15 },
|
|
638
644
|
// --- Mistral ---
|
|
645
|
+
"mistral-large-4": { inputPer1M: 0.68, outputPer1M: 2.09, cachedInputPer1M: 0.07 },
|
|
639
646
|
"mistral-large-3": { inputPer1M: 2, outputPer1M: 6 },
|
|
640
647
|
"mistral-large-latest": { inputPer1M: 2, outputPer1M: 6 },
|
|
641
648
|
"mistral-large-2411": { inputPer1M: 2, outputPer1M: 6 },
|
|
@@ -717,6 +724,9 @@ var MODEL_ALIASES = {
|
|
|
717
724
|
"sonnet-3.5": "claude-3-5-sonnet",
|
|
718
725
|
"haiku": "claude-3-5-haiku",
|
|
719
726
|
"haiku-3.5": "claude-3-5-haiku",
|
|
727
|
+
"haiku-5.5": "claude-haiku-5.5",
|
|
728
|
+
"sonnet-5.5": "claude-sonnet-5.5",
|
|
729
|
+
"opus-5.5": "claude-opus-5.5",
|
|
720
730
|
"opus": "claude-3-opus",
|
|
721
731
|
"claude-2": "claude-2.0",
|
|
722
732
|
"claude-instant": "claude-instant-1.2",
|
|
@@ -726,6 +736,7 @@ var MODEL_ALIASES = {
|
|
|
726
736
|
// Gemini Shorthands
|
|
727
737
|
"flash": "gemini-2.0-flash",
|
|
728
738
|
"pro": "gemini-1.5-pro",
|
|
739
|
+
"gemini-banana": "gemini-nano-banana-2.1",
|
|
729
740
|
// Meta / Groq Shorthands
|
|
730
741
|
"llama-3.3-70b": "llama-3.3-70b-versatile",
|
|
731
742
|
"llama-3.1-70b": "llama-3.1-70b-versatile",
|
|
@@ -809,7 +820,29 @@ function getModelPricing(modelName) {
|
|
|
809
820
|
}
|
|
810
821
|
|
|
811
822
|
// src/pricing/calculator.ts
|
|
812
|
-
function calculateCost(
|
|
823
|
+
function calculateCost(modelOrParams, usage, optionsOrMarkup) {
|
|
824
|
+
let params;
|
|
825
|
+
if (typeof modelOrParams === "string") {
|
|
826
|
+
const opts = typeof optionsOrMarkup === "number" ? { markupMultiplier: optionsOrMarkup } : optionsOrMarkup || {};
|
|
827
|
+
params = {
|
|
828
|
+
model: modelOrParams,
|
|
829
|
+
inputTokens: usage?.inputTokens ?? usage?.promptTokens ?? 0,
|
|
830
|
+
outputTokens: usage?.outputTokens ?? usage?.completionTokens ?? 0,
|
|
831
|
+
reasoningTokens: usage?.reasoningTokens,
|
|
832
|
+
cachedTokens: usage?.cachedTokens,
|
|
833
|
+
cacheWriteTokens: usage?.cacheWriteTokens,
|
|
834
|
+
markupMultiplier: opts.markupMultiplier ?? opts.markup ?? opts.margin,
|
|
835
|
+
minimumChargeUSD: opts.minimumChargeUSD,
|
|
836
|
+
customRate: opts.customRate
|
|
837
|
+
};
|
|
838
|
+
} else {
|
|
839
|
+
params = {
|
|
840
|
+
...modelOrParams,
|
|
841
|
+
inputTokens: modelOrParams.inputTokens ?? modelOrParams.promptTokens ?? 0,
|
|
842
|
+
outputTokens: modelOrParams.outputTokens ?? modelOrParams.completionTokens ?? 0,
|
|
843
|
+
markupMultiplier: modelOrParams.markupMultiplier ?? modelOrParams.markup ?? modelOrParams.margin
|
|
844
|
+
};
|
|
845
|
+
}
|
|
813
846
|
let rates;
|
|
814
847
|
if (params.customRate) {
|
|
815
848
|
const outRate = params.customRate.out ?? params.customRate.output ?? 0;
|
|
@@ -1094,7 +1127,7 @@ var VibezMeter = class {
|
|
|
1094
1127
|
batcher;
|
|
1095
1128
|
markupMultiplier;
|
|
1096
1129
|
constructor(options = {}) {
|
|
1097
|
-
this.markupMultiplier = options.pricing?.margin ?? options.markupMultiplier;
|
|
1130
|
+
this.markupMultiplier = options.pricing?.margin ?? options.pricing?.markup ?? options.markupMultiplier;
|
|
1098
1131
|
this.batcher = new MeterBatcher(options);
|
|
1099
1132
|
}
|
|
1100
1133
|
/**
|
|
@@ -1286,7 +1319,7 @@ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
|
|
|
1286
1319
|
cacheWriteTokens: cacheWriteTokens > 0 ? cacheWriteTokens : void 0
|
|
1287
1320
|
};
|
|
1288
1321
|
const cost = calculateUsageCost(modelId, usage, {
|
|
1289
|
-
markupMultiplier: options.pricing?.margin,
|
|
1322
|
+
markupMultiplier: options.pricing?.margin ?? options.pricing?.markup,
|
|
1290
1323
|
minimumChargeUSD: options.pricing?.minimumChargeUSD,
|
|
1291
1324
|
customRate: options.rate
|
|
1292
1325
|
});
|
|
@@ -1325,6 +1358,7 @@ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
|
|
|
1325
1358
|
const mergedMetadata = {
|
|
1326
1359
|
...customerMetadata,
|
|
1327
1360
|
...options.metadata,
|
|
1361
|
+
...options.threadId ? { threadId: options.threadId } : {},
|
|
1328
1362
|
...extraMeta
|
|
1329
1363
|
};
|
|
1330
1364
|
const event = {
|
|
@@ -1536,6 +1570,266 @@ function withBilling(model, optionsOrCustomer, extraOptions = {}) {
|
|
|
1536
1570
|
return new Proxy(model, handler);
|
|
1537
1571
|
}
|
|
1538
1572
|
|
|
1573
|
+
// src/ai-sdk/to-response.ts
|
|
1574
|
+
function toResponse(result, options) {
|
|
1575
|
+
let baseResponse;
|
|
1576
|
+
if (typeof result?.toUIMessageStreamResponse === "function") {
|
|
1577
|
+
baseResponse = result.toUIMessageStreamResponse(options?.init);
|
|
1578
|
+
} else if (typeof result?.toDataStreamResponse === "function") {
|
|
1579
|
+
baseResponse = result.toDataStreamResponse(options?.init);
|
|
1580
|
+
} else if (typeof result?.toTextStreamResponse === "function") {
|
|
1581
|
+
baseResponse = result.toTextStreamResponse(options?.init);
|
|
1582
|
+
} else if (result instanceof Response) {
|
|
1583
|
+
baseResponse = result;
|
|
1584
|
+
} else if (result && typeof result === "object" && result.body && result.headers) {
|
|
1585
|
+
baseResponse = result;
|
|
1586
|
+
} else {
|
|
1587
|
+
baseResponse = new Response(result, options?.init);
|
|
1588
|
+
}
|
|
1589
|
+
if (!baseResponse.body) {
|
|
1590
|
+
return baseResponse;
|
|
1591
|
+
}
|
|
1592
|
+
const contentType = baseResponse.headers.get("content-type") || "";
|
|
1593
|
+
const isSSE = contentType.includes("text/event-stream") || baseResponse.headers.has("x-vercel-ai-ui-message-stream");
|
|
1594
|
+
const isDataStream = baseResponse.headers.has("x-vercel-ai-data-stream");
|
|
1595
|
+
const encoder = new TextEncoder();
|
|
1596
|
+
const decoder = new TextDecoder();
|
|
1597
|
+
let injected = false;
|
|
1598
|
+
const resolveTelemetry = async () => {
|
|
1599
|
+
if (options?.telemetry) return options.telemetry;
|
|
1600
|
+
if (result?.providerMetadata) {
|
|
1601
|
+
try {
|
|
1602
|
+
const meta = await Promise.race([
|
|
1603
|
+
result.providerMetadata,
|
|
1604
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 800))
|
|
1605
|
+
]);
|
|
1606
|
+
if (meta?.vibezcheck) {
|
|
1607
|
+
return meta.vibezcheck;
|
|
1608
|
+
}
|
|
1609
|
+
} catch {
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (result?.usage) {
|
|
1613
|
+
try {
|
|
1614
|
+
const u = await Promise.race([
|
|
1615
|
+
result.usage,
|
|
1616
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 800))
|
|
1617
|
+
]);
|
|
1618
|
+
if (u) {
|
|
1619
|
+
const inputTokens = u.promptTokens ?? u.inputTokens ?? 0;
|
|
1620
|
+
const outputTokens = u.completionTokens ?? u.outputTokens ?? 0;
|
|
1621
|
+
const reasoningTokens = u.reasoningTokens ?? u.completionTokensDetails?.reasoningTokens;
|
|
1622
|
+
return {
|
|
1623
|
+
type: "vibezcheck",
|
|
1624
|
+
usage: {
|
|
1625
|
+
inputTokens,
|
|
1626
|
+
outputTokens,
|
|
1627
|
+
totalTokens: inputTokens + outputTokens,
|
|
1628
|
+
reasoningTokens
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
} catch {
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return null;
|
|
1636
|
+
};
|
|
1637
|
+
const transformStream = new TransformStream({
|
|
1638
|
+
async transform(chunk, controller) {
|
|
1639
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
1640
|
+
if (isSSE && text.includes("[DONE]") && !injected) {
|
|
1641
|
+
injected = true;
|
|
1642
|
+
const telemetry = await resolveTelemetry();
|
|
1643
|
+
if (telemetry) {
|
|
1644
|
+
const ssePayload = `data: ${JSON.stringify({ type: "data-vibezcheck", data: telemetry })}
|
|
1645
|
+
|
|
1646
|
+
data: ${JSON.stringify({ type: "message-metadata", messageMetadata: { vibezcheck: telemetry } })}
|
|
1647
|
+
|
|
1648
|
+
`;
|
|
1649
|
+
const doneIndex = text.indexOf("data: [DONE]");
|
|
1650
|
+
if (doneIndex !== -1) {
|
|
1651
|
+
const before = text.slice(0, doneIndex);
|
|
1652
|
+
const after = text.slice(doneIndex);
|
|
1653
|
+
if (before) controller.enqueue(encoder.encode(before));
|
|
1654
|
+
controller.enqueue(encoder.encode(ssePayload));
|
|
1655
|
+
controller.enqueue(encoder.encode(after));
|
|
1656
|
+
return;
|
|
1657
|
+
} else {
|
|
1658
|
+
controller.enqueue(encoder.encode(ssePayload));
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
} else if (isDataStream && (text.includes("d:{") || text.includes("d: {")) && !injected) {
|
|
1662
|
+
injected = true;
|
|
1663
|
+
const telemetry = await resolveTelemetry();
|
|
1664
|
+
if (telemetry) {
|
|
1665
|
+
const annotationLine = `2:[${JSON.stringify(telemetry)}]
|
|
1666
|
+
`;
|
|
1667
|
+
controller.enqueue(encoder.encode(annotationLine));
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
controller.enqueue(chunk);
|
|
1671
|
+
},
|
|
1672
|
+
async flush(controller) {
|
|
1673
|
+
if (!injected) {
|
|
1674
|
+
injected = true;
|
|
1675
|
+
const telemetry = await resolveTelemetry();
|
|
1676
|
+
if (telemetry) {
|
|
1677
|
+
if (isSSE) {
|
|
1678
|
+
const ssePayload = `data: ${JSON.stringify({ type: "data-vibezcheck", data: telemetry })}
|
|
1679
|
+
|
|
1680
|
+
data: ${JSON.stringify({ type: "message-metadata", messageMetadata: { vibezcheck: telemetry } })}
|
|
1681
|
+
|
|
1682
|
+
`;
|
|
1683
|
+
controller.enqueue(encoder.encode(ssePayload));
|
|
1684
|
+
} else {
|
|
1685
|
+
const annotationLine = `2:[${JSON.stringify(telemetry)}]
|
|
1686
|
+
`;
|
|
1687
|
+
controller.enqueue(encoder.encode(annotationLine));
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
const mergedHeaders = new Headers(baseResponse.headers);
|
|
1694
|
+
if (options?.headers) {
|
|
1695
|
+
const extraHeaders = new Headers(options.headers);
|
|
1696
|
+
extraHeaders.forEach((value, key) => {
|
|
1697
|
+
mergedHeaders.set(key, value);
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
const status = options?.init?.status ?? baseResponse.status;
|
|
1701
|
+
const statusText = options?.init?.statusText ?? baseResponse.statusText;
|
|
1702
|
+
return new Response(baseResponse.body.pipeThrough(transformStream), {
|
|
1703
|
+
status,
|
|
1704
|
+
statusText,
|
|
1705
|
+
headers: mergedHeaders
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/ai-sdk/declarative.ts
|
|
1710
|
+
function createVibezModel(modelOrId, options = {}) {
|
|
1711
|
+
if (typeof modelOrId === "object" && modelOrId !== null) {
|
|
1712
|
+
return withBilling(modelOrId, options);
|
|
1713
|
+
}
|
|
1714
|
+
if (typeof modelOrId === "string") {
|
|
1715
|
+
const rawId = modelOrId;
|
|
1716
|
+
let providerName = "openai";
|
|
1717
|
+
let cleanModelId = rawId;
|
|
1718
|
+
if (rawId.includes("/")) {
|
|
1719
|
+
const parts = rawId.split("/");
|
|
1720
|
+
providerName = parts[0].toLowerCase();
|
|
1721
|
+
cleanModelId = parts.slice(1).join("/");
|
|
1722
|
+
} else if (rawId.startsWith("claude-")) {
|
|
1723
|
+
providerName = "anthropic";
|
|
1724
|
+
} else if (rawId.startsWith("gemini-")) {
|
|
1725
|
+
providerName = "google";
|
|
1726
|
+
} else if (rawId.startsWith("deepseek-")) {
|
|
1727
|
+
providerName = "deepseek";
|
|
1728
|
+
} else if (rawId.startsWith("grok-")) {
|
|
1729
|
+
providerName = "xai";
|
|
1730
|
+
} else if (rawId.startsWith("mistral-") || rawId.startsWith("codestral-") || rawId.startsWith("ministral-") || rawId.startsWith("magistral-") || rawId.startsWith("voxtral-") || rawId.startsWith("devstral-") || rawId.startsWith("open-mistral") || rawId.startsWith("open-mixtral")) {
|
|
1731
|
+
providerName = "mistral";
|
|
1732
|
+
} else if (rawId.startsWith("llama-") || rawId.startsWith("mixtral-") || rawId.startsWith("gemma") || rawId.startsWith("qwen-")) {
|
|
1733
|
+
providerName = "groq";
|
|
1734
|
+
} else if (rawId.startsWith("command-")) {
|
|
1735
|
+
providerName = "cohere";
|
|
1736
|
+
} else if (rawId.startsWith("mercury-") || rawId.startsWith("ling-")) {
|
|
1737
|
+
providerName = "gateway";
|
|
1738
|
+
} else if (rawId.startsWith("gpt-image-") || rawId.startsWith("gpt-6-")) {
|
|
1739
|
+
providerName = "openai";
|
|
1740
|
+
}
|
|
1741
|
+
const apiKey = options.apiKey || process.env.AI_GATEWAY_API_KEY || (providerName === "anthropic" ? process.env.ANTHROPIC_API_KEY : void 0) || (providerName === "google" ? process.env.GOOGLE_GENERATIVE_AI_API_KEY : void 0) || (providerName === "mistral" ? process.env.MISTRAL_API_KEY : void 0) || (providerName === "groq" ? process.env.GROQ_API_KEY : void 0) || (providerName === "deepseek" ? process.env.DEEPSEEK_API_KEY : void 0) || (providerName === "xai" ? process.env.XAI_API_KEY : void 0) || (providerName === "cohere" ? process.env.COHERE_API_KEY : void 0) || process.env.OPENAI_API_KEY;
|
|
1742
|
+
const baseURL = options.baseURL || process.env.AI_GATEWAY_BASE_URL || (providerName === "openai" ? "https://api.openai.com/v1" : void 0);
|
|
1743
|
+
let baseModelInstance = null;
|
|
1744
|
+
try {
|
|
1745
|
+
if (providerName === "openai" || providerName === "gateway" || !providerName) {
|
|
1746
|
+
const mod = require("@ai-sdk/openai");
|
|
1747
|
+
const factory = mod.createOpenAI || mod.openai || mod.default?.createOpenAI || mod.default?.openai;
|
|
1748
|
+
if (typeof factory === "function") {
|
|
1749
|
+
if (mod.createOpenAI) {
|
|
1750
|
+
const provider = factory({ apiKey, baseURL });
|
|
1751
|
+
baseModelInstance = provider(cleanModelId);
|
|
1752
|
+
} else {
|
|
1753
|
+
baseModelInstance = factory(cleanModelId);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
} else if (providerName === "anthropic") {
|
|
1757
|
+
const mod = require("@ai-sdk/anthropic");
|
|
1758
|
+
const factory = mod.createAnthropic || mod.anthropic || mod.default?.createAnthropic || mod.default?.anthropic;
|
|
1759
|
+
if (typeof factory === "function") {
|
|
1760
|
+
if (mod.createAnthropic) {
|
|
1761
|
+
const provider = factory({ apiKey, baseURL });
|
|
1762
|
+
baseModelInstance = provider(cleanModelId);
|
|
1763
|
+
} else {
|
|
1764
|
+
baseModelInstance = factory(cleanModelId);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
} else if (providerName === "google") {
|
|
1768
|
+
const mod = require("@ai-sdk/google");
|
|
1769
|
+
const factory = mod.createGoogleGenerativeAI || mod.google || mod.default?.createGoogleGenerativeAI || mod.default?.google;
|
|
1770
|
+
if (typeof factory === "function") {
|
|
1771
|
+
if (mod.createGoogleGenerativeAI) {
|
|
1772
|
+
const provider = factory({ apiKey, baseURL });
|
|
1773
|
+
baseModelInstance = provider(cleanModelId);
|
|
1774
|
+
} else {
|
|
1775
|
+
baseModelInstance = factory(cleanModelId);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
} else if (providerName === "mistral") {
|
|
1779
|
+
const mod = require("@ai-sdk/mistral");
|
|
1780
|
+
const factory = mod.createMistral || mod.mistral || mod.default?.createMistral || mod.default?.mistral;
|
|
1781
|
+
if (typeof factory === "function") {
|
|
1782
|
+
baseModelInstance = mod.createMistral ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
|
|
1783
|
+
}
|
|
1784
|
+
} else if (providerName === "groq") {
|
|
1785
|
+
const mod = require("@ai-sdk/groq");
|
|
1786
|
+
const factory = mod.createGroq || mod.groq || mod.default?.createGroq || mod.default?.groq;
|
|
1787
|
+
if (typeof factory === "function") {
|
|
1788
|
+
baseModelInstance = mod.createGroq ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
|
|
1789
|
+
}
|
|
1790
|
+
} else if (providerName === "deepseek") {
|
|
1791
|
+
const mod = require("@ai-sdk/deepseek");
|
|
1792
|
+
const factory = mod.createDeepSeek || mod.deepseek || mod.default?.createDeepSeek || mod.default?.deepseek;
|
|
1793
|
+
if (typeof factory === "function") {
|
|
1794
|
+
baseModelInstance = mod.createDeepSeek ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
|
|
1795
|
+
}
|
|
1796
|
+
} else if (providerName === "xai") {
|
|
1797
|
+
const mod = require("@ai-sdk/xai");
|
|
1798
|
+
const factory = mod.createXai || mod.xai || mod.default?.createXai || mod.default?.xai;
|
|
1799
|
+
if (typeof factory === "function") {
|
|
1800
|
+
baseModelInstance = mod.createXai ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
|
|
1801
|
+
}
|
|
1802
|
+
} else if (providerName === "cohere") {
|
|
1803
|
+
const mod = require("@ai-sdk/cohere");
|
|
1804
|
+
const factory = mod.createCohere || mod.cohere || mod.default?.createCohere || mod.default?.cohere;
|
|
1805
|
+
if (typeof factory === "function") {
|
|
1806
|
+
baseModelInstance = mod.createCohere ? factory({ apiKey, baseURL })(cleanModelId) : factory(cleanModelId);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
} catch {
|
|
1810
|
+
baseModelInstance = {
|
|
1811
|
+
specificationVersion: "v2",
|
|
1812
|
+
provider: providerName,
|
|
1813
|
+
modelId: cleanModelId
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
if (!baseModelInstance) {
|
|
1817
|
+
baseModelInstance = {
|
|
1818
|
+
specificationVersion: "v2",
|
|
1819
|
+
provider: providerName,
|
|
1820
|
+
modelId: cleanModelId
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
return withBilling(baseModelInstance, options);
|
|
1824
|
+
}
|
|
1825
|
+
return modelOrId;
|
|
1826
|
+
}
|
|
1827
|
+
var createVibezSession = createAgentSession;
|
|
1828
|
+
var vibezcheck = Object.assign(createVibezModel, {
|
|
1829
|
+
session: createVibezSession,
|
|
1830
|
+
toResponse
|
|
1831
|
+
});
|
|
1832
|
+
|
|
1539
1833
|
// src/billing/session.ts
|
|
1540
1834
|
var AgentSession = class {
|
|
1541
1835
|
sessionId;
|
|
@@ -1556,7 +1850,7 @@ var AgentSession = class {
|
|
|
1556
1850
|
*/
|
|
1557
1851
|
model(modelOrId, modelOptions = {}) {
|
|
1558
1852
|
const session = this;
|
|
1559
|
-
return
|
|
1853
|
+
return createVibezModel(modelOrId, {
|
|
1560
1854
|
...modelOptions,
|
|
1561
1855
|
customer: this.customer,
|
|
1562
1856
|
pricing: modelOptions.pricing || this.options.pricing,
|
|
@@ -1648,7 +1942,13 @@ var AgentSession = class {
|
|
|
1648
1942
|
const defaultCost = options.costPerActionUSD ?? 5e-3;
|
|
1649
1943
|
const instrumented = {};
|
|
1650
1944
|
for (const [name, toolDef] of Object.entries(toolsRecord)) {
|
|
1651
|
-
|
|
1945
|
+
let costUSD = defaultCost;
|
|
1946
|
+
if (options && "costs" in options && options.costs?.[name] !== void 0) {
|
|
1947
|
+
costUSD = options.costs[name];
|
|
1948
|
+
} else if (options && name in options) {
|
|
1949
|
+
const val = options[name];
|
|
1950
|
+
costUSD = typeof val === "number" ? val : val?.costUSD ?? defaultCost;
|
|
1951
|
+
}
|
|
1652
1952
|
instrumented[name] = this.wrapTool(toolDef, { name, costUSD });
|
|
1653
1953
|
}
|
|
1654
1954
|
return instrumented;
|
|
@@ -1739,7 +2039,13 @@ function instrumentToolKit(tools, options = {}) {
|
|
|
1739
2039
|
const instrumented = {};
|
|
1740
2040
|
const cost = options.costPerActionUSD ?? 5e-3;
|
|
1741
2041
|
for (const [toolName, toolDef] of Object.entries(tools)) {
|
|
1742
|
-
|
|
2042
|
+
let actionCost = cost;
|
|
2043
|
+
if (options && "costs" in options && options.costs?.[toolName] !== void 0) {
|
|
2044
|
+
actionCost = options.costs[toolName];
|
|
2045
|
+
} else if (options && toolName in options) {
|
|
2046
|
+
const val = options[toolName];
|
|
2047
|
+
actionCost = typeof val === "number" ? val : val?.costUSD ?? cost;
|
|
2048
|
+
}
|
|
1743
2049
|
instrumented[toolName] = wrapTool({
|
|
1744
2050
|
name: toolName,
|
|
1745
2051
|
costUSD: actionCost,
|