@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.
@@ -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
- var import_zod = require("zod");
59
- var ReasoningDetailSummarySchema = import_zod.z.object({
60
- type: import_zod.z.literal("reasoning.summary" /* Summary */),
61
- summary: import_zod.z.string()
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 = import_zod.z.object({
64
- type: import_zod.z.literal("reasoning.encrypted" /* Encrypted */),
65
- data: import_zod.z.string()
39
+ var ReasoningDetailEncryptedSchema = z.object({
40
+ type: z.literal("reasoning.encrypted" /* Encrypted */),
41
+ data: z.string()
66
42
  });
67
- var ReasoningDetailTextSchema = import_zod.z.object({
68
- type: import_zod.z.literal("reasoning.text" /* Text */),
69
- text: import_zod.z.string().nullish(),
70
- signature: import_zod.z.string().nullish()
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 = import_zod.z.union([
48
+ var ReasoningDetailUnionSchema = z.union([
73
49
  ReasoningDetailSummarySchema,
74
50
  ReasoningDetailEncryptedSchema,
75
51
  ReasoningDetailTextSchema
76
52
  ]);
77
- var ReasoningDetailsWithUnknownSchema = import_zod.z.union([
53
+ var ReasoningDetailsWithUnknownSchema = z.union([
78
54
  ReasoningDetailUnionSchema,
79
- import_zod.z.unknown().transform(() => null)
55
+ z.unknown().transform(() => null)
80
56
  ]);
81
- var ReasoningDetailArraySchema = import_zod.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
57
+ var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
82
58
 
83
59
  // src/llmgateway-chat-language-model.ts
84
- var import_provider = require("@ai-sdk/provider");
85
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
86
- var import_zod3 = require("zod");
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
- var import_provider_utils = require("@ai-sdk/provider-utils");
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,${(0, import_provider_utils.convertUint8ArrayToBase64)(
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,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.data)}` : `data:${part.mimeType};base64,${part.data}`
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
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
276
- var import_zod2 = require("zod");
277
- var LLMGatewayErrorResponseSchema = import_zod2.z.object({
278
- error: import_zod2.z.object({
279
- message: import_zod2.z.string(),
280
- type: import_zod2.z.string(),
281
- param: import_zod2.z.any().nullable(),
282
- code: import_zod2.z.string().nullable()
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 = (0, import_provider_utils2.createJsonErrorResponseHandler)({
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 import_provider.UnsupportedFunctionalityError({
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 (0, import_provider_utils3.postJsonToApi)({
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: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
376
+ headers: combineHeaders(this.config.headers(), options.headers),
391
377
  body: args,
392
378
  failedResponseHandler: llmgatewayFailedResponseHandler,
393
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
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 : (0, import_provider_utils3.generateId)(),
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 (0, import_provider_utils3.postJsonToApi)({
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: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.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: (0, import_provider_utils3.createEventSourceResponseHandler)(
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 import_provider.InvalidResponseDataError({
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 import_provider.InvalidResponseDataError({
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 import_provider.InvalidResponseDataError({
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 && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
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 : (0, import_provider_utils3.generateId)(),
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 && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
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 : (0, import_provider_utils3.generateId)(),
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 : (0, import_provider_utils3.generateId)(),
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: (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
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 = import_zod3.z.object({
770
- id: import_zod3.z.string().optional(),
771
- model: import_zod3.z.string().optional(),
772
- usage: import_zod3.z.object({
773
- prompt_tokens: import_zod3.z.number(),
774
- prompt_tokens_details: import_zod3.z.object({
775
- cached_tokens: import_zod3.z.number()
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: import_zod3.z.number(),
778
- completion_tokens_details: import_zod3.z.object({
779
- reasoning_tokens: import_zod3.z.number()
763
+ completion_tokens: z3.number(),
764
+ completion_tokens_details: z3.object({
765
+ reasoning_tokens: z3.number()
780
766
  }).nullish(),
781
- total_tokens: import_zod3.z.number(),
782
- cost: import_zod3.z.number().optional()
767
+ total_tokens: z3.number(),
768
+ cost: z3.number().optional()
783
769
  }).nullish()
784
770
  });
785
771
  var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBaseResponseSchema.extend({
786
- choices: import_zod3.z.array(
787
- import_zod3.z.object({
788
- message: import_zod3.z.object({
789
- role: import_zod3.z.literal("assistant"),
790
- content: import_zod3.z.string().nullable().optional(),
791
- reasoning: import_zod3.z.string().nullable().optional(),
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: import_zod3.z.array(
794
- import_zod3.z.object({
795
- id: import_zod3.z.string().optional().nullable(),
796
- type: import_zod3.z.literal("function"),
797
- function: import_zod3.z.object({
798
- name: import_zod3.z.string(),
799
- arguments: import_zod3.z.string()
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: import_zod3.z.number(),
805
- logprobs: import_zod3.z.object({
806
- content: import_zod3.z.array(
807
- import_zod3.z.object({
808
- token: import_zod3.z.string(),
809
- logprob: import_zod3.z.number(),
810
- top_logprobs: import_zod3.z.array(
811
- import_zod3.z.object({
812
- token: import_zod3.z.string(),
813
- logprob: import_zod3.z.number()
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: import_zod3.z.string().optional().nullable()
805
+ finish_reason: z3.string().optional().nullable()
820
806
  })
821
807
  )
822
808
  });
823
- var LLMGatewayStreamChatCompletionChunkSchema = import_zod3.z.union([
809
+ var LLMGatewayStreamChatCompletionChunkSchema = z3.union([
824
810
  LLMGatewayChatCompletionBaseResponseSchema.extend({
825
- choices: import_zod3.z.array(
826
- import_zod3.z.object({
827
- delta: import_zod3.z.object({
828
- role: import_zod3.z.enum(["assistant"]).optional(),
829
- content: import_zod3.z.string().nullish(),
830
- reasoning: import_zod3.z.string().nullish().optional(),
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: import_zod3.z.array(
833
- import_zod3.z.object({
834
- index: import_zod3.z.number(),
835
- id: import_zod3.z.string().nullish(),
836
- type: import_zod3.z.literal("function").optional(),
837
- function: import_zod3.z.object({
838
- name: import_zod3.z.string().nullish(),
839
- arguments: import_zod3.z.string().nullish()
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: import_zod3.z.object({
845
- content: import_zod3.z.array(
846
- import_zod3.z.object({
847
- token: import_zod3.z.string(),
848
- logprob: import_zod3.z.number(),
849
- top_logprobs: import_zod3.z.array(
850
- import_zod3.z.object({
851
- token: import_zod3.z.string(),
852
- logprob: import_zod3.z.number()
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: import_zod3.z.string().nullable().optional(),
859
- index: import_zod3.z.number()
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
- var import_provider3 = require("@ai-sdk/provider");
918
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
919
- var import_zod4 = require("zod");
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
- var import_provider2 = require("@ai-sdk/provider");
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 import_provider2.InvalidPromptError({
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 import_provider2.UnsupportedFunctionalityError({
948
+ throw new UnsupportedFunctionalityError2({
955
949
  functionality: "images"
956
950
  });
957
951
  }
958
952
  case "file": {
959
- throw new import_provider2.UnsupportedFunctionalityError({
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 import_provider2.UnsupportedFunctionalityError({
978
+ throw new UnsupportedFunctionalityError2({
985
979
  functionality: "tool-call messages"
986
980
  });
987
981
  }
988
982
  case "reasoning": {
989
- throw new import_provider2.UnsupportedFunctionalityError({
983
+ throw new UnsupportedFunctionalityError2({
990
984
  functionality: "reasoning messages"
991
985
  });
992
986
  }
993
987
  case "redacted-reasoning": {
994
- throw new import_provider2.UnsupportedFunctionalityError({
988
+ throw new UnsupportedFunctionalityError2({
995
989
  functionality: "redacted reasoning messages"
996
990
  });
997
991
  }
998
992
  case "file": {
999
- throw new import_provider2.UnsupportedFunctionalityError({
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 import_provider2.UnsupportedFunctionalityError({
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 import_provider3.UnsupportedFunctionalityError({
1105
+ throw new UnsupportedFunctionalityError3({
1112
1106
  functionality: "tools"
1113
1107
  });
1114
1108
  }
1115
1109
  if (mode.toolChoice) {
1116
- throw new import_provider3.UnsupportedFunctionalityError({
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 import_provider3.UnsupportedFunctionalityError({
1117
+ throw new UnsupportedFunctionalityError3({
1124
1118
  functionality: "object-json mode"
1125
1119
  });
1126
1120
  }
1127
1121
  case "object-tool": {
1128
- throw new import_provider3.UnsupportedFunctionalityError({
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 import_provider3.UnsupportedFunctionalityError({
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 (0, import_provider_utils4.postJsonToApi)({
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: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
1143
+ headers: combineHeaders2(this.config.headers(), options.headers),
1150
1144
  body: args,
1151
1145
  failedResponseHandler: llmgatewayFailedResponseHandler,
1152
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
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 (0, import_provider_utils4.postJsonToApi)({
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: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.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: (0, import_provider_utils4.createEventSourceResponseHandler)(
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 = import_zod4.z.union([
1269
- import_zod4.z.object({
1270
- id: import_zod4.z.string().optional(),
1271
- model: import_zod4.z.string().optional(),
1272
- choices: import_zod4.z.array(
1273
- import_zod4.z.object({
1274
- text: import_zod4.z.string(),
1275
- reasoning: import_zod4.z.string().nullish().optional(),
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: import_zod4.z.string().nullish(),
1278
- index: import_zod4.z.number(),
1279
- logprobs: import_zod4.z.object({
1280
- tokens: import_zod4.z.array(import_zod4.z.string()),
1281
- token_logprobs: import_zod4.z.array(import_zod4.z.number()),
1282
- top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
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: import_zod4.z.object({
1287
- prompt_tokens: import_zod4.z.number(),
1288
- completion_tokens: import_zod4.z.number()
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
- // Annotate the CommonJS export names for ESM import in node:
1294
- 0 && (module.exports = {
1287
+ export {
1295
1288
  LLMGatewayChatLanguageModel,
1296
1289
  LLMGatewayCompletionLanguageModel
1297
- });
1298
- //# sourceMappingURL=index.cjs.map
1290
+ };
1291
+ //# sourceMappingURL=index.mjs.map