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