@llmgateway/ai-sdk-provider 3.5.0 → 3.6.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 +3 -3
- package/dist/index.d.mts +11 -40
- package/dist/index.d.ts +11 -40
- package/dist/index.js +97 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -64
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +10 -39
- package/dist/internal/index.d.ts +10 -39
- package/dist/internal/index.js +97 -64
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +97 -64
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2219,16 +2219,16 @@ var llmgatewayFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
2219
2219
|
function mapLLMGatewayFinishReason(finishReason) {
|
|
2220
2220
|
switch (finishReason) {
|
|
2221
2221
|
case "stop":
|
|
2222
|
-
return "stop";
|
|
2222
|
+
return { unified: "stop", raw: finishReason };
|
|
2223
2223
|
case "length":
|
|
2224
|
-
return "length";
|
|
2224
|
+
return { unified: "length", raw: finishReason };
|
|
2225
2225
|
case "content_filter":
|
|
2226
|
-
return "content-filter";
|
|
2226
|
+
return { unified: "content-filter", raw: finishReason };
|
|
2227
2227
|
case "function_call":
|
|
2228
2228
|
case "tool_calls":
|
|
2229
|
-
return "tool-calls";
|
|
2229
|
+
return { unified: "tool-calls", raw: finishReason };
|
|
2230
2230
|
default:
|
|
2231
|
-
return "
|
|
2231
|
+
return { unified: "other", raw: finishReason != null ? finishReason : void 0 };
|
|
2232
2232
|
}
|
|
2233
2233
|
}
|
|
2234
2234
|
|
|
@@ -2431,6 +2431,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2431
2431
|
}
|
|
2432
2432
|
case "tool": {
|
|
2433
2433
|
for (const toolResponse of content) {
|
|
2434
|
+
if (toolResponse.type !== "tool-result") continue;
|
|
2434
2435
|
const content2 = getToolResultContent(toolResponse);
|
|
2435
2436
|
messages.push({
|
|
2436
2437
|
role: "tool",
|
|
@@ -2449,7 +2450,14 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2449
2450
|
return messages;
|
|
2450
2451
|
}
|
|
2451
2452
|
function getToolResultContent(input) {
|
|
2452
|
-
|
|
2453
|
+
switch (input.output.type) {
|
|
2454
|
+
case "text":
|
|
2455
|
+
return input.output.value;
|
|
2456
|
+
case "json":
|
|
2457
|
+
return JSON.stringify(input.output.value);
|
|
2458
|
+
default:
|
|
2459
|
+
return JSON.stringify(input.output);
|
|
2460
|
+
}
|
|
2453
2461
|
}
|
|
2454
2462
|
|
|
2455
2463
|
// src/chat/get-tool-choice.ts
|
|
@@ -2619,9 +2627,8 @@ var LLMGatewayStreamChatCompletionChunkSchema = z6.union([
|
|
|
2619
2627
|
// src/chat/index.ts
|
|
2620
2628
|
var LLMGatewayChatLanguageModel = class {
|
|
2621
2629
|
constructor(modelId, settings, config) {
|
|
2622
|
-
this.specificationVersion = "
|
|
2630
|
+
this.specificationVersion = "v3";
|
|
2623
2631
|
this.provider = "llmgateway";
|
|
2624
|
-
this.defaultObjectGenerationMode = "tool";
|
|
2625
2632
|
this.supportedUrls = {
|
|
2626
2633
|
"image/*": [
|
|
2627
2634
|
/^data:image\/[a-zA-Z]+;base64,/,
|
|
@@ -2710,7 +2717,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2710
2717
|
return baseArgs;
|
|
2711
2718
|
}
|
|
2712
2719
|
async doGenerate(options) {
|
|
2713
|
-
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
|
|
2720
|
+
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;
|
|
2714
2721
|
const providerOptions = options.providerOptions || {};
|
|
2715
2722
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
2716
2723
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -2734,19 +2741,31 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2734
2741
|
throw new Error("No choice in response");
|
|
2735
2742
|
}
|
|
2736
2743
|
const usageInfo = response.usage ? {
|
|
2737
|
-
inputTokens:
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2744
|
+
inputTokens: {
|
|
2745
|
+
total: (_b16 = response.usage.prompt_tokens) != null ? _b16 : void 0,
|
|
2746
|
+
noCache: void 0,
|
|
2747
|
+
cacheRead: (_d = (_c = response.usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : void 0,
|
|
2748
|
+
cacheWrite: void 0
|
|
2749
|
+
},
|
|
2750
|
+
outputTokens: {
|
|
2751
|
+
total: (_e = response.usage.completion_tokens) != null ? _e : void 0,
|
|
2752
|
+
text: void 0,
|
|
2753
|
+
reasoning: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0
|
|
2754
|
+
}
|
|
2742
2755
|
} : {
|
|
2743
|
-
inputTokens:
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2756
|
+
inputTokens: {
|
|
2757
|
+
total: void 0,
|
|
2758
|
+
noCache: void 0,
|
|
2759
|
+
cacheRead: void 0,
|
|
2760
|
+
cacheWrite: void 0
|
|
2761
|
+
},
|
|
2762
|
+
outputTokens: {
|
|
2763
|
+
total: void 0,
|
|
2764
|
+
text: void 0,
|
|
2765
|
+
reasoning: void 0
|
|
2766
|
+
}
|
|
2748
2767
|
};
|
|
2749
|
-
const reasoningDetails = (
|
|
2768
|
+
const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
|
|
2750
2769
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
2751
2770
|
switch (detail.type) {
|
|
2752
2771
|
case "reasoning.text" /* Text */: {
|
|
@@ -2802,7 +2821,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2802
2821
|
for (const toolCall of choice.message.tool_calls) {
|
|
2803
2822
|
content.push({
|
|
2804
2823
|
type: "tool-call",
|
|
2805
|
-
toolCallId: (
|
|
2824
|
+
toolCallId: (_i = toolCall.id) != null ? _i : generateId(),
|
|
2806
2825
|
toolName: toolCall.function.name,
|
|
2807
2826
|
input: toolCall.function.arguments
|
|
2808
2827
|
});
|
|
@@ -2843,18 +2862,18 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2843
2862
|
providerMetadata: includeUsageAccounting ? {
|
|
2844
2863
|
llmgateway: {
|
|
2845
2864
|
usage: {
|
|
2846
|
-
promptTokens: (
|
|
2847
|
-
completionTokens: (
|
|
2848
|
-
totalTokens: (
|
|
2849
|
-
cost: typeof ((
|
|
2865
|
+
promptTokens: (_j = usageInfo.inputTokens.total) != null ? _j : 0,
|
|
2866
|
+
completionTokens: (_k = usageInfo.outputTokens.total) != null ? _k : 0,
|
|
2867
|
+
totalTokens: ((_l = usageInfo.inputTokens.total) != null ? _l : 0) + ((_m = usageInfo.outputTokens.total) != null ? _m : 0),
|
|
2868
|
+
cost: typeof ((_n = response.usage) == null ? void 0 : _n.cost) === "number" ? response.usage.cost : (_p = (_o = response.usage) == null ? void 0 : _o.cost) == null ? void 0 : _p.total_cost,
|
|
2850
2869
|
promptTokensDetails: {
|
|
2851
|
-
cachedTokens: (
|
|
2870
|
+
cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
|
|
2852
2871
|
},
|
|
2853
2872
|
completionTokensDetails: {
|
|
2854
|
-
reasoningTokens: (
|
|
2873
|
+
reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
|
|
2855
2874
|
},
|
|
2856
2875
|
costDetails: {
|
|
2857
|
-
upstreamInferenceCost: (
|
|
2876
|
+
upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
|
|
2858
2877
|
}
|
|
2859
2878
|
}
|
|
2860
2879
|
}
|
|
@@ -2890,13 +2909,19 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2890
2909
|
fetch: this.config.fetch
|
|
2891
2910
|
});
|
|
2892
2911
|
const toolCalls = [];
|
|
2893
|
-
let finishReason = "other";
|
|
2912
|
+
let finishReason = { unified: "other", raw: void 0 };
|
|
2894
2913
|
const usage = {
|
|
2895
|
-
inputTokens:
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2914
|
+
inputTokens: {
|
|
2915
|
+
total: void 0,
|
|
2916
|
+
noCache: void 0,
|
|
2917
|
+
cacheRead: void 0,
|
|
2918
|
+
cacheWrite: void 0
|
|
2919
|
+
},
|
|
2920
|
+
outputTokens: {
|
|
2921
|
+
total: void 0,
|
|
2922
|
+
text: void 0,
|
|
2923
|
+
reasoning: void 0
|
|
2924
|
+
}
|
|
2900
2925
|
};
|
|
2901
2926
|
const llmgatewayUsage = {};
|
|
2902
2927
|
let textStarted = false;
|
|
@@ -2910,13 +2935,13 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2910
2935
|
transform(chunk, controller) {
|
|
2911
2936
|
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2912
2937
|
if (!chunk.success) {
|
|
2913
|
-
finishReason = "error";
|
|
2938
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
2914
2939
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2915
2940
|
return;
|
|
2916
2941
|
}
|
|
2917
2942
|
const value = chunk.value;
|
|
2918
2943
|
if ("error" in value) {
|
|
2919
|
-
finishReason = "error";
|
|
2944
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
2920
2945
|
controller.enqueue({ type: "error", error: value.error });
|
|
2921
2946
|
return;
|
|
2922
2947
|
}
|
|
@@ -2934,13 +2959,12 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2934
2959
|
});
|
|
2935
2960
|
}
|
|
2936
2961
|
if (value.usage != null) {
|
|
2937
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
2938
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
2939
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
2962
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
2963
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
2940
2964
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
2941
2965
|
if (value.usage.prompt_tokens_details) {
|
|
2942
2966
|
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
2943
|
-
usage.
|
|
2967
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
2944
2968
|
llmgatewayUsage.promptTokensDetails = {
|
|
2945
2969
|
cachedTokens: cachedInputTokens
|
|
2946
2970
|
};
|
|
@@ -2948,7 +2972,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2948
2972
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
2949
2973
|
if (value.usage.completion_tokens_details) {
|
|
2950
2974
|
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
2951
|
-
usage.
|
|
2975
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
2952
2976
|
llmgatewayUsage.completionTokensDetails = {
|
|
2953
2977
|
reasoningTokens
|
|
2954
2978
|
};
|
|
@@ -3131,7 +3155,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3131
3155
|
},
|
|
3132
3156
|
flush(controller) {
|
|
3133
3157
|
var _a16;
|
|
3134
|
-
if (finishReason === "tool-calls") {
|
|
3158
|
+
if (finishReason.unified === "tool-calls") {
|
|
3135
3159
|
for (const toolCall of toolCalls) {
|
|
3136
3160
|
if (toolCall && !toolCall.sent) {
|
|
3137
3161
|
controller.enqueue({
|
|
@@ -3170,7 +3194,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3170
3194
|
}
|
|
3171
3195
|
})
|
|
3172
3196
|
),
|
|
3173
|
-
warnings: [],
|
|
3174
3197
|
request: { body: args },
|
|
3175
3198
|
response: { headers: responseHeaders }
|
|
3176
3199
|
};
|
|
@@ -3322,7 +3345,7 @@ var LLMGatewayCompletionChunkSchema = z7.union([
|
|
|
3322
3345
|
// src/completion/index.ts
|
|
3323
3346
|
var LLMGatewayCompletionLanguageModel = class {
|
|
3324
3347
|
constructor(modelId, settings, config) {
|
|
3325
|
-
this.specificationVersion = "
|
|
3348
|
+
this.specificationVersion = "v3";
|
|
3326
3349
|
this.provider = "llmgateway";
|
|
3327
3350
|
this.supportedUrls = {
|
|
3328
3351
|
"image/*": [
|
|
@@ -3332,7 +3355,6 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3332
3355
|
"text/*": [/^data:text\//, /^https?:\/\/.+$/],
|
|
3333
3356
|
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
3334
3357
|
};
|
|
3335
|
-
this.defaultObjectGenerationMode = void 0;
|
|
3336
3358
|
this.modelId = modelId;
|
|
3337
3359
|
this.settings = settings;
|
|
3338
3360
|
this.config = config;
|
|
@@ -3392,7 +3414,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3392
3414
|
}, this.config.extraBody), this.settings.extraBody);
|
|
3393
3415
|
}
|
|
3394
3416
|
async doGenerate(options) {
|
|
3395
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
3417
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3396
3418
|
const providerOptions = options.providerOptions || {};
|
|
3397
3419
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
3398
3420
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -3426,11 +3448,17 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3426
3448
|
],
|
|
3427
3449
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
3428
3450
|
usage: {
|
|
3429
|
-
inputTokens:
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3451
|
+
inputTokens: {
|
|
3452
|
+
total: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : void 0,
|
|
3453
|
+
noCache: void 0,
|
|
3454
|
+
cacheRead: (_f = (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
|
|
3455
|
+
cacheWrite: void 0
|
|
3456
|
+
},
|
|
3457
|
+
outputTokens: {
|
|
3458
|
+
total: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
|
|
3459
|
+
text: void 0,
|
|
3460
|
+
reasoning: (_k = (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
|
|
3461
|
+
}
|
|
3434
3462
|
},
|
|
3435
3463
|
warnings: [],
|
|
3436
3464
|
response: {
|
|
@@ -3460,13 +3488,19 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3460
3488
|
abortSignal: options.abortSignal,
|
|
3461
3489
|
fetch: this.config.fetch
|
|
3462
3490
|
});
|
|
3463
|
-
let finishReason = "other";
|
|
3491
|
+
let finishReason = { unified: "other", raw: void 0 };
|
|
3464
3492
|
const usage = {
|
|
3465
|
-
inputTokens:
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3493
|
+
inputTokens: {
|
|
3494
|
+
total: void 0,
|
|
3495
|
+
noCache: void 0,
|
|
3496
|
+
cacheRead: void 0,
|
|
3497
|
+
cacheWrite: void 0
|
|
3498
|
+
},
|
|
3499
|
+
outputTokens: {
|
|
3500
|
+
total: void 0,
|
|
3501
|
+
text: void 0,
|
|
3502
|
+
reasoning: void 0
|
|
3503
|
+
}
|
|
3470
3504
|
};
|
|
3471
3505
|
const llmgatewayUsage = {};
|
|
3472
3506
|
return {
|
|
@@ -3475,24 +3509,23 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3475
3509
|
transform(chunk, controller) {
|
|
3476
3510
|
var _a16, _b16, _c;
|
|
3477
3511
|
if (!chunk.success) {
|
|
3478
|
-
finishReason = "error";
|
|
3512
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
3479
3513
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
3480
3514
|
return;
|
|
3481
3515
|
}
|
|
3482
3516
|
const value = chunk.value;
|
|
3483
3517
|
if ("error" in value) {
|
|
3484
|
-
finishReason = "error";
|
|
3518
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
3485
3519
|
controller.enqueue({ type: "error", error: value.error });
|
|
3486
3520
|
return;
|
|
3487
3521
|
}
|
|
3488
3522
|
if (value.usage != null) {
|
|
3489
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
3490
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
3491
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
3523
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
3524
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
3492
3525
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
3493
3526
|
if (value.usage.prompt_tokens_details) {
|
|
3494
3527
|
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
3495
|
-
usage.
|
|
3528
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
3496
3529
|
llmgatewayUsage.promptTokensDetails = {
|
|
3497
3530
|
cachedTokens: cachedInputTokens
|
|
3498
3531
|
};
|
|
@@ -3500,7 +3533,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3500
3533
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
3501
3534
|
if (value.usage.completion_tokens_details) {
|
|
3502
3535
|
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
3503
|
-
usage.
|
|
3536
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
3504
3537
|
llmgatewayUsage.completionTokensDetails = {
|
|
3505
3538
|
reasoningTokens
|
|
3506
3539
|
};
|