@llmgateway/ai-sdk-provider 1.0.0 → 1.0.2
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 +8 -147
- package/dist/index.js +183 -175
- package/dist/index.js.map +1 -1
- package/dist/{index.cjs → index.mjs} +176 -184
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.js +176 -169
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/{index.cjs → index.mjs} +170 -177
- package/dist/internal/index.mjs.map +1 -0
- package/package.json +1 -2
- package/dist/index.cjs.map +0 -1
- package/dist/internal/index.cjs.map +0 -1
- /package/dist/{index.d.cts → index.d.mts} +0 -0
- /package/dist/internal/{index.d.cts → index.d.mts} +0 -0
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -32,61 +29,50 @@ var __objRest = (source, exclude) => {
|
|
|
32
29
|
}
|
|
33
30
|
return target;
|
|
34
31
|
};
|
|
35
|
-
var __export = (target, all) => {
|
|
36
|
-
for (var name in all)
|
|
37
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
-
};
|
|
39
|
-
var __copyProps = (to, from, except, desc) => {
|
|
40
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
-
for (let key of __getOwnPropNames(from))
|
|
42
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
-
}
|
|
45
|
-
return to;
|
|
46
|
-
};
|
|
47
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
-
|
|
49
|
-
// src/internal/index.ts
|
|
50
|
-
var index_exports = {};
|
|
51
|
-
__export(index_exports, {
|
|
52
|
-
LLMGatewayChatLanguageModel: () => LLMGatewayChatLanguageModel,
|
|
53
|
-
LLMGatewayCompletionLanguageModel: () => LLMGatewayCompletionLanguageModel
|
|
54
|
-
});
|
|
55
|
-
module.exports = __toCommonJS(index_exports);
|
|
56
32
|
|
|
57
33
|
// src/schemas/reasoning-details.ts
|
|
58
|
-
|
|
59
|
-
var ReasoningDetailSummarySchema =
|
|
60
|
-
type:
|
|
61
|
-
summary:
|
|
34
|
+
import { z } from "zod";
|
|
35
|
+
var ReasoningDetailSummarySchema = z.object({
|
|
36
|
+
type: z.literal("reasoning.summary" /* Summary */),
|
|
37
|
+
summary: z.string()
|
|
62
38
|
});
|
|
63
|
-
var ReasoningDetailEncryptedSchema =
|
|
64
|
-
type:
|
|
65
|
-
data:
|
|
39
|
+
var ReasoningDetailEncryptedSchema = z.object({
|
|
40
|
+
type: z.literal("reasoning.encrypted" /* Encrypted */),
|
|
41
|
+
data: z.string()
|
|
66
42
|
});
|
|
67
|
-
var ReasoningDetailTextSchema =
|
|
68
|
-
type:
|
|
69
|
-
text:
|
|
70
|
-
signature:
|
|
43
|
+
var ReasoningDetailTextSchema = z.object({
|
|
44
|
+
type: z.literal("reasoning.text" /* Text */),
|
|
45
|
+
text: z.string().nullish(),
|
|
46
|
+
signature: z.string().nullish()
|
|
71
47
|
});
|
|
72
|
-
var ReasoningDetailUnionSchema =
|
|
48
|
+
var ReasoningDetailUnionSchema = z.union([
|
|
73
49
|
ReasoningDetailSummarySchema,
|
|
74
50
|
ReasoningDetailEncryptedSchema,
|
|
75
51
|
ReasoningDetailTextSchema
|
|
76
52
|
]);
|
|
77
|
-
var ReasoningDetailsWithUnknownSchema =
|
|
53
|
+
var ReasoningDetailsWithUnknownSchema = z.union([
|
|
78
54
|
ReasoningDetailUnionSchema,
|
|
79
|
-
|
|
55
|
+
z.unknown().transform(() => null)
|
|
80
56
|
]);
|
|
81
|
-
var ReasoningDetailArraySchema =
|
|
57
|
+
var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
82
58
|
|
|
83
59
|
// src/llmgateway-chat-language-model.ts
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
60
|
+
import {
|
|
61
|
+
InvalidResponseDataError,
|
|
62
|
+
UnsupportedFunctionalityError
|
|
63
|
+
} from "@ai-sdk/provider";
|
|
64
|
+
import {
|
|
65
|
+
combineHeaders,
|
|
66
|
+
createEventSourceResponseHandler,
|
|
67
|
+
createJsonResponseHandler,
|
|
68
|
+
generateId,
|
|
69
|
+
isParsableJson,
|
|
70
|
+
postJsonToApi
|
|
71
|
+
} from "@ai-sdk/provider-utils";
|
|
72
|
+
import { z as z3 } from "zod";
|
|
87
73
|
|
|
88
74
|
// src/convert-to-llmgateway-chat-messages.ts
|
|
89
|
-
|
|
75
|
+
import { convertUint8ArrayToBase64 } from "@ai-sdk/provider-utils";
|
|
90
76
|
function getCacheControl(providerMetadata) {
|
|
91
77
|
var _a, _b, _c;
|
|
92
78
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
@@ -132,7 +118,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
132
118
|
return {
|
|
133
119
|
type: "image_url",
|
|
134
120
|
image_url: {
|
|
135
|
-
url: part.image instanceof URL ? part.image.toString() : `data:${(_b2 = part.mimeType) != null ? _b2 : "image/jpeg"};base64,${
|
|
121
|
+
url: part.image instanceof URL ? part.image.toString() : `data:${(_b2 = part.mimeType) != null ? _b2 : "image/jpeg"};base64,${convertUint8ArrayToBase64(
|
|
136
122
|
part.image
|
|
137
123
|
)}`
|
|
138
124
|
},
|
|
@@ -146,7 +132,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
146
132
|
filename: String(
|
|
147
133
|
(_d = (_c2 = part.providerMetadata) == null ? void 0 : _c2.llmgateway) == null ? void 0 : _d.filename
|
|
148
134
|
),
|
|
149
|
-
file_data: part.data instanceof Uint8Array ? `data:${part.mimeType};base64,${
|
|
135
|
+
file_data: part.data instanceof Uint8Array ? `data:${part.mimeType};base64,${convertUint8ArrayToBase64(part.data)}` : `data:${part.mimeType};base64,${part.data}`
|
|
150
136
|
},
|
|
151
137
|
cache_control: cacheControl
|
|
152
138
|
};
|
|
@@ -272,17 +258,17 @@ function mapLLMGatewayFinishReason(finishReason) {
|
|
|
272
258
|
}
|
|
273
259
|
|
|
274
260
|
// src/llmgateway-error.ts
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var LLMGatewayErrorResponseSchema =
|
|
278
|
-
error:
|
|
279
|
-
message:
|
|
280
|
-
type:
|
|
281
|
-
param:
|
|
282
|
-
code:
|
|
261
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
262
|
+
import { z as z2 } from "zod";
|
|
263
|
+
var LLMGatewayErrorResponseSchema = z2.object({
|
|
264
|
+
error: z2.object({
|
|
265
|
+
message: z2.string(),
|
|
266
|
+
type: z2.string(),
|
|
267
|
+
param: z2.any().nullable(),
|
|
268
|
+
code: z2.string().nullable()
|
|
283
269
|
})
|
|
284
270
|
});
|
|
285
|
-
var llmgatewayFailedResponseHandler =
|
|
271
|
+
var llmgatewayFailedResponseHandler = createJsonErrorResponseHandler({
|
|
286
272
|
errorSchema: LLMGatewayErrorResponseSchema,
|
|
287
273
|
errorToMessage: (data) => data.error.message
|
|
288
274
|
});
|
|
@@ -373,7 +359,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
373
359
|
// Handle all non-text types with a single default case
|
|
374
360
|
default: {
|
|
375
361
|
const _exhaustiveCheck = type;
|
|
376
|
-
throw new
|
|
362
|
+
throw new UnsupportedFunctionalityError({
|
|
377
363
|
functionality: `${_exhaustiveCheck} mode`
|
|
378
364
|
});
|
|
379
365
|
}
|
|
@@ -382,15 +368,15 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
382
368
|
async doGenerate(options) {
|
|
383
369
|
var _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
384
370
|
const args = this.getArgs(options);
|
|
385
|
-
const { responseHeaders, value: response } = await
|
|
371
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
386
372
|
url: this.config.url({
|
|
387
373
|
path: "/chat/completions",
|
|
388
374
|
modelId: this.modelId
|
|
389
375
|
}),
|
|
390
|
-
headers:
|
|
376
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
391
377
|
body: args,
|
|
392
378
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
393
|
-
successfulResponseHandler:
|
|
379
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
394
380
|
LLMGatewayNonStreamChatCompletionResponseSchema
|
|
395
381
|
),
|
|
396
382
|
abortSignal: options.abortSignal,
|
|
@@ -480,7 +466,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
480
466
|
var _a2;
|
|
481
467
|
return {
|
|
482
468
|
toolCallType: "function",
|
|
483
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 :
|
|
469
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
484
470
|
toolName: toolCall.function.name,
|
|
485
471
|
args: toolCall.function.arguments
|
|
486
472
|
};
|
|
@@ -496,12 +482,12 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
496
482
|
async doStream(options) {
|
|
497
483
|
var _a, _c;
|
|
498
484
|
const args = this.getArgs(options);
|
|
499
|
-
const { responseHeaders, value: response } = await
|
|
485
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
500
486
|
url: this.config.url({
|
|
501
487
|
path: "/chat/completions",
|
|
502
488
|
modelId: this.modelId
|
|
503
489
|
}),
|
|
504
|
-
headers:
|
|
490
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
505
491
|
body: __spreadProps(__spreadValues({}, args), {
|
|
506
492
|
stream: true,
|
|
507
493
|
// only include stream_options when in strict compatibility mode:
|
|
@@ -510,7 +496,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
510
496
|
}, ((_a = this.settings.usage) == null ? void 0 : _a.include) ? { include_usage: true } : {}) : void 0
|
|
511
497
|
}),
|
|
512
498
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
513
|
-
successfulResponseHandler:
|
|
499
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
514
500
|
LLMGatewayStreamChatCompletionChunkSchema
|
|
515
501
|
),
|
|
516
502
|
abortSignal: options.abortSignal,
|
|
@@ -651,19 +637,19 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
651
637
|
const index = toolCallDelta.index;
|
|
652
638
|
if (toolCalls[index] == null) {
|
|
653
639
|
if (toolCallDelta.type !== "function") {
|
|
654
|
-
throw new
|
|
640
|
+
throw new InvalidResponseDataError({
|
|
655
641
|
data: toolCallDelta,
|
|
656
642
|
message: `Expected 'function' type.`
|
|
657
643
|
});
|
|
658
644
|
}
|
|
659
645
|
if (toolCallDelta.id == null) {
|
|
660
|
-
throw new
|
|
646
|
+
throw new InvalidResponseDataError({
|
|
661
647
|
data: toolCallDelta,
|
|
662
648
|
message: `Expected 'id' to be a string.`
|
|
663
649
|
});
|
|
664
650
|
}
|
|
665
651
|
if (((_c2 = toolCallDelta.function) == null ? void 0 : _c2.name) == null) {
|
|
666
|
-
throw new
|
|
652
|
+
throw new InvalidResponseDataError({
|
|
667
653
|
data: toolCallDelta,
|
|
668
654
|
message: `Expected 'function.name' to be a string.`
|
|
669
655
|
});
|
|
@@ -681,7 +667,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
681
667
|
if (toolCall2 == null) {
|
|
682
668
|
throw new Error("Tool call is missing");
|
|
683
669
|
}
|
|
684
|
-
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null &&
|
|
670
|
+
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
685
671
|
controller.enqueue({
|
|
686
672
|
type: "tool-call-delta",
|
|
687
673
|
toolCallType: "function",
|
|
@@ -692,7 +678,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
692
678
|
controller.enqueue({
|
|
693
679
|
type: "tool-call",
|
|
694
680
|
toolCallType: "function",
|
|
695
|
-
toolCallId: (_g = toolCall2.id) != null ? _g :
|
|
681
|
+
toolCallId: (_g = toolCall2.id) != null ? _g : generateId(),
|
|
696
682
|
toolName: toolCall2.function.name,
|
|
697
683
|
args: toolCall2.function.arguments
|
|
698
684
|
});
|
|
@@ -714,11 +700,11 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
714
700
|
toolName: toolCall.function.name,
|
|
715
701
|
argsTextDelta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
716
702
|
});
|
|
717
|
-
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null &&
|
|
703
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
718
704
|
controller.enqueue({
|
|
719
705
|
type: "tool-call",
|
|
720
706
|
toolCallType: "function",
|
|
721
|
-
toolCallId: (_n = toolCall.id) != null ? _n :
|
|
707
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
722
708
|
toolName: toolCall.function.name,
|
|
723
709
|
args: toolCall.function.arguments
|
|
724
710
|
});
|
|
@@ -735,10 +721,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
735
721
|
controller.enqueue({
|
|
736
722
|
type: "tool-call",
|
|
737
723
|
toolCallType: "function",
|
|
738
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 :
|
|
724
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
739
725
|
toolName: toolCall.function.name,
|
|
740
726
|
// Coerce invalid arguments to an empty JSON object
|
|
741
|
-
args:
|
|
727
|
+
args: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
742
728
|
});
|
|
743
729
|
toolCall.sent = true;
|
|
744
730
|
}
|
|
@@ -766,97 +752,97 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
766
752
|
};
|
|
767
753
|
}
|
|
768
754
|
};
|
|
769
|
-
var LLMGatewayChatCompletionBaseResponseSchema =
|
|
770
|
-
id:
|
|
771
|
-
model:
|
|
772
|
-
usage:
|
|
773
|
-
prompt_tokens:
|
|
774
|
-
prompt_tokens_details:
|
|
775
|
-
cached_tokens:
|
|
755
|
+
var LLMGatewayChatCompletionBaseResponseSchema = z3.object({
|
|
756
|
+
id: z3.string().optional(),
|
|
757
|
+
model: z3.string().optional(),
|
|
758
|
+
usage: z3.object({
|
|
759
|
+
prompt_tokens: z3.number(),
|
|
760
|
+
prompt_tokens_details: z3.object({
|
|
761
|
+
cached_tokens: z3.number()
|
|
776
762
|
}).nullish(),
|
|
777
|
-
completion_tokens:
|
|
778
|
-
completion_tokens_details:
|
|
779
|
-
reasoning_tokens:
|
|
763
|
+
completion_tokens: z3.number(),
|
|
764
|
+
completion_tokens_details: z3.object({
|
|
765
|
+
reasoning_tokens: z3.number()
|
|
780
766
|
}).nullish(),
|
|
781
|
-
total_tokens:
|
|
782
|
-
cost:
|
|
767
|
+
total_tokens: z3.number(),
|
|
768
|
+
cost: z3.number().optional()
|
|
783
769
|
}).nullish()
|
|
784
770
|
});
|
|
785
771
|
var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
786
|
-
choices:
|
|
787
|
-
|
|
788
|
-
message:
|
|
789
|
-
role:
|
|
790
|
-
content:
|
|
791
|
-
reasoning:
|
|
772
|
+
choices: z3.array(
|
|
773
|
+
z3.object({
|
|
774
|
+
message: z3.object({
|
|
775
|
+
role: z3.literal("assistant"),
|
|
776
|
+
content: z3.string().nullable().optional(),
|
|
777
|
+
reasoning: z3.string().nullable().optional(),
|
|
792
778
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
793
|
-
tool_calls:
|
|
794
|
-
|
|
795
|
-
id:
|
|
796
|
-
type:
|
|
797
|
-
function:
|
|
798
|
-
name:
|
|
799
|
-
arguments:
|
|
779
|
+
tool_calls: z3.array(
|
|
780
|
+
z3.object({
|
|
781
|
+
id: z3.string().optional().nullable(),
|
|
782
|
+
type: z3.literal("function"),
|
|
783
|
+
function: z3.object({
|
|
784
|
+
name: z3.string(),
|
|
785
|
+
arguments: z3.string()
|
|
800
786
|
})
|
|
801
787
|
})
|
|
802
788
|
).optional()
|
|
803
789
|
}),
|
|
804
|
-
index:
|
|
805
|
-
logprobs:
|
|
806
|
-
content:
|
|
807
|
-
|
|
808
|
-
token:
|
|
809
|
-
logprob:
|
|
810
|
-
top_logprobs:
|
|
811
|
-
|
|
812
|
-
token:
|
|
813
|
-
logprob:
|
|
790
|
+
index: z3.number(),
|
|
791
|
+
logprobs: z3.object({
|
|
792
|
+
content: z3.array(
|
|
793
|
+
z3.object({
|
|
794
|
+
token: z3.string(),
|
|
795
|
+
logprob: z3.number(),
|
|
796
|
+
top_logprobs: z3.array(
|
|
797
|
+
z3.object({
|
|
798
|
+
token: z3.string(),
|
|
799
|
+
logprob: z3.number()
|
|
814
800
|
})
|
|
815
801
|
)
|
|
816
802
|
})
|
|
817
803
|
).nullable()
|
|
818
804
|
}).nullable().optional(),
|
|
819
|
-
finish_reason:
|
|
805
|
+
finish_reason: z3.string().optional().nullable()
|
|
820
806
|
})
|
|
821
807
|
)
|
|
822
808
|
});
|
|
823
|
-
var LLMGatewayStreamChatCompletionChunkSchema =
|
|
809
|
+
var LLMGatewayStreamChatCompletionChunkSchema = z3.union([
|
|
824
810
|
LLMGatewayChatCompletionBaseResponseSchema.extend({
|
|
825
|
-
choices:
|
|
826
|
-
|
|
827
|
-
delta:
|
|
828
|
-
role:
|
|
829
|
-
content:
|
|
830
|
-
reasoning:
|
|
811
|
+
choices: z3.array(
|
|
812
|
+
z3.object({
|
|
813
|
+
delta: z3.object({
|
|
814
|
+
role: z3.enum(["assistant"]).optional(),
|
|
815
|
+
content: z3.string().nullish(),
|
|
816
|
+
reasoning: z3.string().nullish().optional(),
|
|
831
817
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
832
|
-
tool_calls:
|
|
833
|
-
|
|
834
|
-
index:
|
|
835
|
-
id:
|
|
836
|
-
type:
|
|
837
|
-
function:
|
|
838
|
-
name:
|
|
839
|
-
arguments:
|
|
818
|
+
tool_calls: z3.array(
|
|
819
|
+
z3.object({
|
|
820
|
+
index: z3.number(),
|
|
821
|
+
id: z3.string().nullish(),
|
|
822
|
+
type: z3.literal("function").optional(),
|
|
823
|
+
function: z3.object({
|
|
824
|
+
name: z3.string().nullish(),
|
|
825
|
+
arguments: z3.string().nullish()
|
|
840
826
|
})
|
|
841
827
|
})
|
|
842
828
|
).nullish()
|
|
843
829
|
}).nullish(),
|
|
844
|
-
logprobs:
|
|
845
|
-
content:
|
|
846
|
-
|
|
847
|
-
token:
|
|
848
|
-
logprob:
|
|
849
|
-
top_logprobs:
|
|
850
|
-
|
|
851
|
-
token:
|
|
852
|
-
logprob:
|
|
830
|
+
logprobs: z3.object({
|
|
831
|
+
content: z3.array(
|
|
832
|
+
z3.object({
|
|
833
|
+
token: z3.string(),
|
|
834
|
+
logprob: z3.number(),
|
|
835
|
+
top_logprobs: z3.array(
|
|
836
|
+
z3.object({
|
|
837
|
+
token: z3.string(),
|
|
838
|
+
logprob: z3.number()
|
|
853
839
|
})
|
|
854
840
|
)
|
|
855
841
|
})
|
|
856
842
|
).nullable()
|
|
857
843
|
}).nullish(),
|
|
858
|
-
finish_reason:
|
|
859
|
-
index:
|
|
844
|
+
finish_reason: z3.string().nullable().optional(),
|
|
845
|
+
index: z3.number()
|
|
860
846
|
})
|
|
861
847
|
)
|
|
862
848
|
}),
|
|
@@ -914,12 +900,20 @@ function prepareToolsAndToolChoice(mode) {
|
|
|
914
900
|
}
|
|
915
901
|
|
|
916
902
|
// src/llmgateway-completion-language-model.ts
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
903
|
+
import { UnsupportedFunctionalityError as UnsupportedFunctionalityError3 } from "@ai-sdk/provider";
|
|
904
|
+
import {
|
|
905
|
+
combineHeaders as combineHeaders2,
|
|
906
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
907
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
908
|
+
postJsonToApi as postJsonToApi2
|
|
909
|
+
} from "@ai-sdk/provider-utils";
|
|
910
|
+
import { z as z4 } from "zod";
|
|
920
911
|
|
|
921
912
|
// src/convert-to-llmgateway-completion-prompt.ts
|
|
922
|
-
|
|
913
|
+
import {
|
|
914
|
+
InvalidPromptError,
|
|
915
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
916
|
+
} from "@ai-sdk/provider";
|
|
923
917
|
function convertToLLMGatewayCompletionPrompt({
|
|
924
918
|
prompt,
|
|
925
919
|
inputFormat,
|
|
@@ -939,7 +933,7 @@ function convertToLLMGatewayCompletionPrompt({
|
|
|
939
933
|
for (const { role, content } of prompt) {
|
|
940
934
|
switch (role) {
|
|
941
935
|
case "system": {
|
|
942
|
-
throw new
|
|
936
|
+
throw new InvalidPromptError({
|
|
943
937
|
message: "Unexpected system message in prompt: ${content}",
|
|
944
938
|
prompt
|
|
945
939
|
});
|
|
@@ -951,12 +945,12 @@ function convertToLLMGatewayCompletionPrompt({
|
|
|
951
945
|
return part.text;
|
|
952
946
|
}
|
|
953
947
|
case "image": {
|
|
954
|
-
throw new
|
|
948
|
+
throw new UnsupportedFunctionalityError2({
|
|
955
949
|
functionality: "images"
|
|
956
950
|
});
|
|
957
951
|
}
|
|
958
952
|
case "file": {
|
|
959
|
-
throw new
|
|
953
|
+
throw new UnsupportedFunctionalityError2({
|
|
960
954
|
functionality: "file attachments"
|
|
961
955
|
});
|
|
962
956
|
}
|
|
@@ -981,22 +975,22 @@ ${userMessage}
|
|
|
981
975
|
return part.text;
|
|
982
976
|
}
|
|
983
977
|
case "tool-call": {
|
|
984
|
-
throw new
|
|
978
|
+
throw new UnsupportedFunctionalityError2({
|
|
985
979
|
functionality: "tool-call messages"
|
|
986
980
|
});
|
|
987
981
|
}
|
|
988
982
|
case "reasoning": {
|
|
989
|
-
throw new
|
|
983
|
+
throw new UnsupportedFunctionalityError2({
|
|
990
984
|
functionality: "reasoning messages"
|
|
991
985
|
});
|
|
992
986
|
}
|
|
993
987
|
case "redacted-reasoning": {
|
|
994
|
-
throw new
|
|
988
|
+
throw new UnsupportedFunctionalityError2({
|
|
995
989
|
functionality: "redacted reasoning messages"
|
|
996
990
|
});
|
|
997
991
|
}
|
|
998
992
|
case "file": {
|
|
999
|
-
throw new
|
|
993
|
+
throw new UnsupportedFunctionalityError2({
|
|
1000
994
|
functionality: "file attachments"
|
|
1001
995
|
});
|
|
1002
996
|
}
|
|
@@ -1015,7 +1009,7 @@ ${assistantMessage}
|
|
|
1015
1009
|
break;
|
|
1016
1010
|
}
|
|
1017
1011
|
case "tool": {
|
|
1018
|
-
throw new
|
|
1012
|
+
throw new UnsupportedFunctionalityError2({
|
|
1019
1013
|
functionality: "tool messages"
|
|
1020
1014
|
});
|
|
1021
1015
|
}
|
|
@@ -1108,31 +1102,31 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
1108
1102
|
switch (type) {
|
|
1109
1103
|
case "regular": {
|
|
1110
1104
|
if ((_b = mode.tools) == null ? void 0 : _b.length) {
|
|
1111
|
-
throw new
|
|
1105
|
+
throw new UnsupportedFunctionalityError3({
|
|
1112
1106
|
functionality: "tools"
|
|
1113
1107
|
});
|
|
1114
1108
|
}
|
|
1115
1109
|
if (mode.toolChoice) {
|
|
1116
|
-
throw new
|
|
1110
|
+
throw new UnsupportedFunctionalityError3({
|
|
1117
1111
|
functionality: "toolChoice"
|
|
1118
1112
|
});
|
|
1119
1113
|
}
|
|
1120
1114
|
return baseArgs;
|
|
1121
1115
|
}
|
|
1122
1116
|
case "object-json": {
|
|
1123
|
-
throw new
|
|
1117
|
+
throw new UnsupportedFunctionalityError3({
|
|
1124
1118
|
functionality: "object-json mode"
|
|
1125
1119
|
});
|
|
1126
1120
|
}
|
|
1127
1121
|
case "object-tool": {
|
|
1128
|
-
throw new
|
|
1122
|
+
throw new UnsupportedFunctionalityError3({
|
|
1129
1123
|
functionality: "object-tool mode"
|
|
1130
1124
|
});
|
|
1131
1125
|
}
|
|
1132
1126
|
// Handle all non-text types with a single default case
|
|
1133
1127
|
default: {
|
|
1134
1128
|
const _exhaustiveCheck = type;
|
|
1135
|
-
throw new
|
|
1129
|
+
throw new UnsupportedFunctionalityError3({
|
|
1136
1130
|
functionality: `${_exhaustiveCheck} mode`
|
|
1137
1131
|
});
|
|
1138
1132
|
}
|
|
@@ -1141,15 +1135,15 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
1141
1135
|
async doGenerate(options) {
|
|
1142
1136
|
var _b, _c, _d, _e, _f;
|
|
1143
1137
|
const args = this.getArgs(options);
|
|
1144
|
-
const { responseHeaders, value: response } = await (
|
|
1138
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1145
1139
|
url: this.config.url({
|
|
1146
1140
|
path: "/completions",
|
|
1147
1141
|
modelId: this.modelId
|
|
1148
1142
|
}),
|
|
1149
|
-
headers: (
|
|
1143
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
1150
1144
|
body: args,
|
|
1151
1145
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
1152
|
-
successfulResponseHandler: (
|
|
1146
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
1153
1147
|
LLMGatewayCompletionChunkSchema
|
|
1154
1148
|
),
|
|
1155
1149
|
abortSignal: options.abortSignal,
|
|
@@ -1183,19 +1177,19 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
1183
1177
|
}
|
|
1184
1178
|
async doStream(options) {
|
|
1185
1179
|
const args = this.getArgs(options);
|
|
1186
|
-
const { responseHeaders, value: response } = await (
|
|
1180
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1187
1181
|
url: this.config.url({
|
|
1188
1182
|
path: "/completions",
|
|
1189
1183
|
modelId: this.modelId
|
|
1190
1184
|
}),
|
|
1191
|
-
headers: (
|
|
1185
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
1192
1186
|
body: __spreadProps(__spreadValues({}, this.getArgs(options)), {
|
|
1193
1187
|
stream: true,
|
|
1194
1188
|
// only include stream_options when in strict compatibility mode:
|
|
1195
1189
|
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1196
1190
|
}),
|
|
1197
1191
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
1198
|
-
successfulResponseHandler: (
|
|
1192
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
1199
1193
|
LLMGatewayCompletionChunkSchema
|
|
1200
1194
|
),
|
|
1201
1195
|
abortSignal: options.abortSignal,
|
|
@@ -1265,34 +1259,33 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
1265
1259
|
};
|
|
1266
1260
|
}
|
|
1267
1261
|
};
|
|
1268
|
-
var LLMGatewayCompletionChunkSchema =
|
|
1269
|
-
|
|
1270
|
-
id:
|
|
1271
|
-
model:
|
|
1272
|
-
choices:
|
|
1273
|
-
|
|
1274
|
-
text:
|
|
1275
|
-
reasoning:
|
|
1262
|
+
var LLMGatewayCompletionChunkSchema = z4.union([
|
|
1263
|
+
z4.object({
|
|
1264
|
+
id: z4.string().optional(),
|
|
1265
|
+
model: z4.string().optional(),
|
|
1266
|
+
choices: z4.array(
|
|
1267
|
+
z4.object({
|
|
1268
|
+
text: z4.string(),
|
|
1269
|
+
reasoning: z4.string().nullish().optional(),
|
|
1276
1270
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1277
|
-
finish_reason:
|
|
1278
|
-
index:
|
|
1279
|
-
logprobs:
|
|
1280
|
-
tokens:
|
|
1281
|
-
token_logprobs:
|
|
1282
|
-
top_logprobs:
|
|
1271
|
+
finish_reason: z4.string().nullish(),
|
|
1272
|
+
index: z4.number(),
|
|
1273
|
+
logprobs: z4.object({
|
|
1274
|
+
tokens: z4.array(z4.string()),
|
|
1275
|
+
token_logprobs: z4.array(z4.number()),
|
|
1276
|
+
top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
|
|
1283
1277
|
}).nullable().optional()
|
|
1284
1278
|
})
|
|
1285
1279
|
),
|
|
1286
|
-
usage:
|
|
1287
|
-
prompt_tokens:
|
|
1288
|
-
completion_tokens:
|
|
1280
|
+
usage: z4.object({
|
|
1281
|
+
prompt_tokens: z4.number(),
|
|
1282
|
+
completion_tokens: z4.number()
|
|
1289
1283
|
}).optional().nullable()
|
|
1290
1284
|
}),
|
|
1291
1285
|
LLMGatewayErrorResponseSchema
|
|
1292
1286
|
]);
|
|
1293
|
-
|
|
1294
|
-
0 && (module.exports = {
|
|
1287
|
+
export {
|
|
1295
1288
|
LLMGatewayChatLanguageModel,
|
|
1296
1289
|
LLMGatewayCompletionLanguageModel
|
|
1297
|
-
}
|
|
1298
|
-
//# sourceMappingURL=index.
|
|
1290
|
+
};
|
|
1291
|
+
//# sourceMappingURL=index.mjs.map
|