@llmgateway/ai-sdk-provider 3.1.0 → 3.2.1
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.js +29 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -23
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +29 -23
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +29 -23
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -2548,7 +2548,10 @@ var LLMGatewayChatCompletionBaseResponseSchema = import_v45.z.object({
|
|
|
2548
2548
|
reasoning_tokens: import_v45.z.number()
|
|
2549
2549
|
}).nullish(),
|
|
2550
2550
|
total_tokens: import_v45.z.number(),
|
|
2551
|
-
cost: import_v45.z.
|
|
2551
|
+
cost: import_v45.z.union([
|
|
2552
|
+
import_v45.z.number(),
|
|
2553
|
+
import_v45.z.object({ total_cost: import_v45.z.number() }).passthrough()
|
|
2554
|
+
]).optional(),
|
|
2552
2555
|
cost_details: import_v45.z.object({
|
|
2553
2556
|
upstream_inference_cost: import_v45.z.number().nullish()
|
|
2554
2557
|
}).nullish()
|
|
@@ -2731,8 +2734,8 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2731
2734
|
type: "function",
|
|
2732
2735
|
function: {
|
|
2733
2736
|
name: tool.name,
|
|
2734
|
-
description: tool.
|
|
2735
|
-
|
|
2737
|
+
description: tool.description,
|
|
2738
|
+
parameters: tool.inputSchema
|
|
2736
2739
|
}
|
|
2737
2740
|
}));
|
|
2738
2741
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -2743,7 +2746,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2743
2746
|
return baseArgs;
|
|
2744
2747
|
}
|
|
2745
2748
|
async doGenerate(options) {
|
|
2746
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
2749
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
2747
2750
|
const providerOptions = options.providerOptions || {};
|
|
2748
2751
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
2749
2752
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -2879,15 +2882,15 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2879
2882
|
promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
|
|
2880
2883
|
completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
|
|
2881
2884
|
totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
|
|
2882
|
-
cost: (_o = response.usage) == null ? void 0 : _o.cost,
|
|
2885
|
+
cost: typeof ((_o = response.usage) == null ? void 0 : _o.cost) === "number" ? response.usage.cost : (_q = (_p = response.usage) == null ? void 0 : _p.cost) == null ? void 0 : _q.total_cost,
|
|
2883
2886
|
promptTokensDetails: {
|
|
2884
|
-
cachedTokens: (
|
|
2887
|
+
cachedTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? _t : 0
|
|
2885
2888
|
},
|
|
2886
2889
|
completionTokensDetails: {
|
|
2887
|
-
reasoningTokens: (
|
|
2890
|
+
reasoningTokens: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.completion_tokens_details) == null ? void 0 : _v.reasoning_tokens) != null ? _w : 0
|
|
2888
2891
|
},
|
|
2889
2892
|
costDetails: {
|
|
2890
|
-
upstreamInferenceCost: (
|
|
2893
|
+
upstreamInferenceCost: (_z = (_y = (_x = response.usage) == null ? void 0 : _x.cost_details) == null ? void 0 : _y.upstream_inference_cost) != null ? _z : 0
|
|
2891
2894
|
}
|
|
2892
2895
|
}
|
|
2893
2896
|
}
|
|
@@ -2941,7 +2944,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2941
2944
|
stream: response.pipeThrough(
|
|
2942
2945
|
new TransformStream({
|
|
2943
2946
|
transform(chunk, controller) {
|
|
2944
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2947
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2945
2948
|
if (!chunk.success) {
|
|
2946
2949
|
finishReason = "error";
|
|
2947
2950
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2986,7 +2989,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2986
2989
|
reasoningTokens
|
|
2987
2990
|
};
|
|
2988
2991
|
}
|
|
2989
|
-
llmgatewayUsage.cost = value.usage.cost;
|
|
2992
|
+
llmgatewayUsage.cost = typeof value.usage.cost === "number" ? value.usage.cost : (_c = value.usage.cost) == null ? void 0 : _c.total_cost;
|
|
2990
2993
|
llmgatewayUsage.totalTokens = value.usage.total_tokens;
|
|
2991
2994
|
}
|
|
2992
2995
|
const choice = value.choices[0];
|
|
@@ -3041,7 +3044,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3041
3044
|
}
|
|
3042
3045
|
} else if (delta.reasoningText != null || "reasoning" in delta && typeof delta.reasoning === "string") {
|
|
3043
3046
|
emitReasoningChunk(
|
|
3044
|
-
(
|
|
3047
|
+
(_e = (_d = delta.reasoningText) != null ? _d : "reasoning" in delta && typeof delta.reasoning === "string" ? delta.reasoning : void 0) != null ? _e : ""
|
|
3045
3048
|
);
|
|
3046
3049
|
}
|
|
3047
3050
|
if (delta.content != null) {
|
|
@@ -3061,7 +3064,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3061
3064
|
}
|
|
3062
3065
|
if (delta.tool_calls != null) {
|
|
3063
3066
|
for (const toolCallDelta of delta.tool_calls) {
|
|
3064
|
-
const index = (
|
|
3067
|
+
const index = (_f = toolCallDelta.index) != null ? _f : toolCalls.length - 1;
|
|
3065
3068
|
if (toolCalls[index] == null) {
|
|
3066
3069
|
if (toolCallDelta.type !== "function") {
|
|
3067
3070
|
throw new InvalidResponseDataError({
|
|
@@ -3075,7 +3078,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3075
3078
|
message: `Expected 'id' to be a string.`
|
|
3076
3079
|
});
|
|
3077
3080
|
}
|
|
3078
|
-
if (((
|
|
3081
|
+
if (((_g = toolCallDelta.function) == null ? void 0 : _g.name) == null) {
|
|
3079
3082
|
throw new InvalidResponseDataError({
|
|
3080
3083
|
data: toolCallDelta,
|
|
3081
3084
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -3086,7 +3089,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3086
3089
|
type: "function",
|
|
3087
3090
|
function: {
|
|
3088
3091
|
name: toolCallDelta.function.name,
|
|
3089
|
-
arguments: (
|
|
3092
|
+
arguments: (_h = toolCallDelta.function.arguments) != null ? _h : ""
|
|
3090
3093
|
},
|
|
3091
3094
|
inputStarted: false,
|
|
3092
3095
|
sent: false
|
|
@@ -3095,7 +3098,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3095
3098
|
if (toolCall2 == null) {
|
|
3096
3099
|
throw new Error("Tool call is missing");
|
|
3097
3100
|
}
|
|
3098
|
-
if (((
|
|
3101
|
+
if (((_i = toolCall2.function) == null ? void 0 : _i.name) != null && ((_j = toolCall2.function) == null ? void 0 : _j.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
3099
3102
|
toolCall2.inputStarted = true;
|
|
3100
3103
|
controller.enqueue({
|
|
3101
3104
|
type: "tool-input-start",
|
|
@@ -3133,18 +3136,18 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3133
3136
|
toolName: toolCall.function.name
|
|
3134
3137
|
});
|
|
3135
3138
|
}
|
|
3136
|
-
if (((
|
|
3137
|
-
toolCall.function.arguments += (
|
|
3139
|
+
if (((_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null) {
|
|
3140
|
+
toolCall.function.arguments += (_m = (_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null ? _m : "";
|
|
3138
3141
|
}
|
|
3139
3142
|
controller.enqueue({
|
|
3140
3143
|
type: "tool-input-delta",
|
|
3141
3144
|
id: toolCall.id,
|
|
3142
|
-
delta: (
|
|
3145
|
+
delta: (_n = toolCallDelta.function.arguments) != null ? _n : ""
|
|
3143
3146
|
});
|
|
3144
|
-
if (((
|
|
3147
|
+
if (((_o = toolCall.function) == null ? void 0 : _o.name) != null && ((_p = toolCall.function) == null ? void 0 : _p.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
3145
3148
|
controller.enqueue({
|
|
3146
3149
|
type: "tool-call",
|
|
3147
|
-
toolCallId: (
|
|
3150
|
+
toolCallId: (_q = toolCall.id) != null ? _q : generateId(),
|
|
3148
3151
|
toolName: toolCall.function.name,
|
|
3149
3152
|
input: toolCall.function.arguments
|
|
3150
3153
|
});
|
|
@@ -3343,7 +3346,10 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
|
3343
3346
|
reasoning_tokens: import_v46.z.number()
|
|
3344
3347
|
}).nullish(),
|
|
3345
3348
|
total_tokens: import_v46.z.number(),
|
|
3346
|
-
cost: import_v46.z.
|
|
3349
|
+
cost: import_v46.z.union([
|
|
3350
|
+
import_v46.z.number(),
|
|
3351
|
+
import_v46.z.object({ total_cost: import_v46.z.number() }).passthrough()
|
|
3352
|
+
]).optional()
|
|
3347
3353
|
}).nullish()
|
|
3348
3354
|
}),
|
|
3349
3355
|
LLMGatewayErrorResponseSchema
|
|
@@ -3503,7 +3509,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3503
3509
|
stream: response.pipeThrough(
|
|
3504
3510
|
new TransformStream({
|
|
3505
3511
|
transform(chunk, controller) {
|
|
3506
|
-
var _a16, _b16;
|
|
3512
|
+
var _a16, _b16, _c;
|
|
3507
3513
|
if (!chunk.success) {
|
|
3508
3514
|
finishReason = "error";
|
|
3509
3515
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -3535,7 +3541,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3535
3541
|
reasoningTokens
|
|
3536
3542
|
};
|
|
3537
3543
|
}
|
|
3538
|
-
llmgatewayUsage.cost = value.usage.cost;
|
|
3544
|
+
llmgatewayUsage.cost = typeof value.usage.cost === "number" ? value.usage.cost : (_c = value.usage.cost) == null ? void 0 : _c.total_cost;
|
|
3539
3545
|
llmgatewayUsage.totalTokens = value.usage.total_tokens;
|
|
3540
3546
|
}
|
|
3541
3547
|
const choice = value.choices[0];
|