@ai-sdk/amazon-bedrock 5.0.0-beta.2 → 5.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -13,10 +13,14 @@ import {
13
13
  combineHeaders,
14
14
  createJsonErrorResponseHandler,
15
15
  createJsonResponseHandler,
16
+ isCustomReasoning,
17
+ mapReasoningToProviderBudget,
18
+ mapReasoningToProviderEffort,
16
19
  parseProviderOptions as parseProviderOptions2,
17
20
  postJsonToApi,
18
21
  resolve
19
22
  } from "@ai-sdk/provider-utils";
23
+ import { getModelCapabilities } from "@ai-sdk/anthropic/internal";
20
24
  import { z as z3 } from "zod/v4";
21
25
 
22
26
  // src/bedrock-api-types.ts
@@ -83,7 +87,17 @@ var amazonBedrockLanguageModelOptions = z.object({
83
87
  /**
84
88
  * Anthropic beta features to enable
85
89
  */
86
- anthropicBeta: z.array(z.string()).optional()
90
+ anthropicBeta: z.array(z.string()).optional(),
91
+ /**
92
+ * Service tier for the request.
93
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
94
+ *
95
+ * - 'reserved': Uses provisioned throughput capacity
96
+ * - 'priority': Prioritizes low-latency inference when capacity is available
97
+ * - 'default': Standard on-demand tier
98
+ * - 'flex': Lower-cost tier for flexible latency workloads
99
+ */
100
+ serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
87
101
  });
88
102
 
89
103
  // src/bedrock-error.ts
@@ -240,7 +254,8 @@ async function prepareTools({
240
254
  } = await prepareAnthropicTools({
241
255
  tools: ProviderTools,
242
256
  toolChoice,
243
- supportsStructuredOutput: false
257
+ supportsStructuredOutput: false,
258
+ supportsStrictTools: false
244
259
  });
245
260
  toolWarnings.push(...anthropicToolWarnings);
246
261
  anthropicBetas.forEach((beta) => betas.add(beta));
@@ -365,6 +380,7 @@ import {
365
380
  } from "@ai-sdk/provider";
366
381
  import {
367
382
  convertToBase64,
383
+ isProviderReference,
368
384
  parseProviderOptions,
369
385
  stripFileExtension
370
386
  } from "@ai-sdk/provider-utils";
@@ -442,6 +458,11 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
442
458
  break;
443
459
  }
444
460
  case "file": {
461
+ if (isProviderReference(part.data)) {
462
+ throw new UnsupportedFunctionalityError2({
463
+ functionality: "file parts with provider references"
464
+ });
465
+ }
445
466
  if (part.data instanceof URL) {
446
467
  throw new UnsupportedFunctionalityError2({
447
468
  functionality: "File URL data"
@@ -592,33 +613,36 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
592
613
  providerOptions: part.providerOptions,
593
614
  schema: bedrockReasoningMetadataSchema
594
615
  });
595
- if (reasoningMetadata != null) {
596
- if (reasoningMetadata.signature != null) {
597
- bedrockContent.push({
598
- reasoningContent: {
599
- reasoningText: {
600
- // trim the last text part if it's the last message in the block
601
- // because Bedrock does not allow trailing whitespace
602
- // in pre-filled assistant responses
603
- text: trimIfLast(
604
- isLastBlock,
605
- isLastMessage,
606
- isLastContentPart,
607
- part.text
608
- ),
609
- signature: reasoningMetadata.signature
610
- }
616
+ if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
617
+ bedrockContent.push({
618
+ reasoningContent: {
619
+ reasoningText: {
620
+ text: part.text,
621
+ signature: reasoningMetadata.signature
611
622
  }
612
- });
613
- } else if (reasoningMetadata.redactedData != null) {
614
- bedrockContent.push({
615
- reasoningContent: {
616
- redactedReasoning: {
617
- data: reasoningMetadata.redactedData
618
- }
623
+ }
624
+ });
625
+ } else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
626
+ bedrockContent.push({
627
+ reasoningContent: {
628
+ redactedReasoning: {
629
+ data: reasoningMetadata.redactedData
619
630
  }
620
- });
621
- }
631
+ }
632
+ });
633
+ } else {
634
+ bedrockContent.push({
635
+ reasoningContent: {
636
+ reasoningText: {
637
+ text: trimIfLast(
638
+ isLastBlock,
639
+ isLastMessage,
640
+ isLastContentPart,
641
+ part.text
642
+ )
643
+ }
644
+ }
645
+ });
622
646
  }
623
647
  break;
624
648
  }
@@ -749,7 +773,7 @@ var BedrockChatLanguageModel = class {
749
773
  constructor(modelId, config) {
750
774
  this.modelId = modelId;
751
775
  this.config = config;
752
- this.specificationVersion = "v3";
776
+ this.specificationVersion = "v4";
753
777
  this.provider = "amazon-bedrock";
754
778
  this.supportedUrls = {
755
779
  // no supported urls for bedrock
@@ -768,10 +792,11 @@ var BedrockChatLanguageModel = class {
768
792
  seed,
769
793
  tools,
770
794
  toolChoice,
795
+ reasoning,
771
796
  providerOptions
772
797
  }) {
773
798
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
774
- const bedrockOptions = (_a = await parseProviderOptions2({
799
+ let bedrockOptions = (_a = await parseProviderOptions2({
775
800
  provider: "bedrock",
776
801
  providerOptions,
777
802
  schema: amazonBedrockLanguageModelOptions
@@ -818,6 +843,14 @@ var BedrockChatLanguageModel = class {
818
843
  });
819
844
  }
820
845
  const isAnthropicModel = this.modelId.includes("anthropic");
846
+ const isOpenAIModel = this.modelId.startsWith("openai.");
847
+ bedrockOptions = resolveBedrockReasoningConfig({
848
+ reasoning,
849
+ bedrockOptions,
850
+ warnings,
851
+ isAnthropicModel,
852
+ modelId: this.modelId
853
+ });
821
854
  const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
822
855
  const useNativeStructuredOutput = isAnthropicModel && isThinkingEnabled && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
823
856
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
@@ -895,7 +928,6 @@ var BedrockChatLanguageModel = class {
895
928
  }
896
929
  }
897
930
  const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
898
- const isOpenAIModel = this.modelId.startsWith("openai.");
899
931
  if (maxReasoningEffort != null) {
900
932
  if (isAnthropicModel) {
901
933
  bedrockOptions.additionalModelRequestFields = {
@@ -991,6 +1023,7 @@ var BedrockChatLanguageModel = class {
991
1023
  const {
992
1024
  reasoningConfig: _,
993
1025
  additionalModelRequestFields: __,
1026
+ serviceTier: ___,
994
1027
  ...filteredBedrockOptions
995
1028
  } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
996
1029
  const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
@@ -1005,6 +1038,11 @@ var BedrockChatLanguageModel = class {
1005
1038
  ...Object.keys(inferenceConfig).length > 0 && {
1006
1039
  inferenceConfig
1007
1040
  },
1041
+ ...bedrockOptions.serviceTier != null && {
1042
+ serviceTier: {
1043
+ type: bedrockOptions.serviceTier
1044
+ }
1045
+ },
1008
1046
  ...filteredBedrockOptions,
1009
1047
  ...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
1010
1048
  },
@@ -1554,6 +1592,62 @@ var bedrockReasoningMetadataSchema = z3.object({
1554
1592
  signature: z3.string().optional(),
1555
1593
  redactedData: z3.string().optional()
1556
1594
  });
1595
+ var bedrockReasoningEffortMap = {
1596
+ minimal: "low",
1597
+ low: "low",
1598
+ medium: "medium",
1599
+ high: "high",
1600
+ xhigh: "max"
1601
+ };
1602
+ function resolveBedrockReasoningConfig({
1603
+ reasoning,
1604
+ bedrockOptions,
1605
+ warnings,
1606
+ isAnthropicModel,
1607
+ modelId
1608
+ }) {
1609
+ if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
1610
+ return bedrockOptions;
1611
+ }
1612
+ const result = { ...bedrockOptions };
1613
+ if (isAnthropicModel) {
1614
+ const capabilities = getModelCapabilities(modelId);
1615
+ if (reasoning === "none") {
1616
+ result.reasoningConfig = { type: "disabled" };
1617
+ } else if (capabilities.supportsAdaptiveThinking) {
1618
+ const effort = mapReasoningToProviderEffort({
1619
+ reasoning,
1620
+ effortMap: bedrockReasoningEffortMap,
1621
+ warnings
1622
+ });
1623
+ result.reasoningConfig = {
1624
+ type: "adaptive",
1625
+ maxReasoningEffort: effort
1626
+ };
1627
+ } else {
1628
+ const budgetTokens = mapReasoningToProviderBudget({
1629
+ reasoning,
1630
+ maxOutputTokens: capabilities.maxOutputTokens,
1631
+ maxReasoningBudget: capabilities.maxOutputTokens,
1632
+ warnings
1633
+ });
1634
+ if (budgetTokens != null) {
1635
+ result.reasoningConfig = {
1636
+ type: "enabled",
1637
+ budgetTokens
1638
+ };
1639
+ }
1640
+ }
1641
+ } else if (reasoning !== "none") {
1642
+ const effort = mapReasoningToProviderEffort({
1643
+ reasoning,
1644
+ effortMap: bedrockReasoningEffortMap,
1645
+ warnings
1646
+ });
1647
+ result.reasoningConfig = { maxReasoningEffort: effort };
1648
+ }
1649
+ return result;
1650
+ }
1557
1651
 
1558
1652
  // src/bedrock-embedding-model.ts
1559
1653
  import {
@@ -1626,7 +1720,7 @@ var BedrockEmbeddingModel = class {
1626
1720
  constructor(modelId, config) {
1627
1721
  this.modelId = modelId;
1628
1722
  this.config = config;
1629
- this.specificationVersion = "v3";
1723
+ this.specificationVersion = "v4";
1630
1724
  this.provider = "amazon-bedrock";
1631
1725
  this.maxEmbeddingsPerCall = 1;
1632
1726
  this.supportsParallelCalls = true;
@@ -1766,7 +1860,7 @@ var BedrockImageModel = class {
1766
1860
  constructor(modelId, config) {
1767
1861
  this.modelId = modelId;
1768
1862
  this.config = config;
1769
- this.specificationVersion = "v3";
1863
+ this.specificationVersion = "v4";
1770
1864
  this.provider = "amazon-bedrock";
1771
1865
  }
1772
1866
  get maxImagesPerCall() {
@@ -1969,7 +2063,7 @@ import {
1969
2063
  import { AwsV4Signer } from "aws4fetch";
1970
2064
 
1971
2065
  // src/version.ts
1972
- var VERSION = true ? "5.0.0-beta.2" : "0.0.0-test";
2066
+ var VERSION = true ? "5.0.0-beta.21" : "0.0.0-test";
1973
2067
 
1974
2068
  // src/bedrock-sigv4-fetch.ts
1975
2069
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -2102,7 +2196,7 @@ var BedrockRerankingModel = class {
2102
2196
  constructor(modelId, config) {
2103
2197
  this.modelId = modelId;
2104
2198
  this.config = config;
2105
- this.specificationVersion = "v3";
2199
+ this.specificationVersion = "v4";
2106
2200
  this.provider = "amazon-bedrock";
2107
2201
  }
2108
2202
  async doRerank({
@@ -2306,7 +2400,7 @@ Original error: ${errorMessage}`
2306
2400
  headers: getHeaders,
2307
2401
  fetch: fetchFunction
2308
2402
  });
2309
- provider.specificationVersion = "v3";
2403
+ provider.specificationVersion = "v4";
2310
2404
  provider.languageModel = createChatModel;
2311
2405
  provider.embedding = createEmbeddingModel;
2312
2406
  provider.embeddingModel = createEmbeddingModel;