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

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));
@@ -592,33 +607,36 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
592
607
  providerOptions: part.providerOptions,
593
608
  schema: bedrockReasoningMetadataSchema
594
609
  });
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
- }
610
+ if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
611
+ bedrockContent.push({
612
+ reasoningContent: {
613
+ reasoningText: {
614
+ text: part.text,
615
+ signature: reasoningMetadata.signature
611
616
  }
612
- });
613
- } else if (reasoningMetadata.redactedData != null) {
614
- bedrockContent.push({
615
- reasoningContent: {
616
- redactedReasoning: {
617
- data: reasoningMetadata.redactedData
618
- }
617
+ }
618
+ });
619
+ } else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
620
+ bedrockContent.push({
621
+ reasoningContent: {
622
+ redactedReasoning: {
623
+ data: reasoningMetadata.redactedData
619
624
  }
620
- });
621
- }
625
+ }
626
+ });
627
+ } else {
628
+ bedrockContent.push({
629
+ reasoningContent: {
630
+ reasoningText: {
631
+ text: trimIfLast(
632
+ isLastBlock,
633
+ isLastMessage,
634
+ isLastContentPart,
635
+ part.text
636
+ )
637
+ }
638
+ }
639
+ });
622
640
  }
623
641
  break;
624
642
  }
@@ -749,7 +767,7 @@ var BedrockChatLanguageModel = class {
749
767
  constructor(modelId, config) {
750
768
  this.modelId = modelId;
751
769
  this.config = config;
752
- this.specificationVersion = "v3";
770
+ this.specificationVersion = "v4";
753
771
  this.provider = "amazon-bedrock";
754
772
  this.supportedUrls = {
755
773
  // no supported urls for bedrock
@@ -768,10 +786,11 @@ var BedrockChatLanguageModel = class {
768
786
  seed,
769
787
  tools,
770
788
  toolChoice,
789
+ reasoning,
771
790
  providerOptions
772
791
  }) {
773
792
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
774
- const bedrockOptions = (_a = await parseProviderOptions2({
793
+ let bedrockOptions = (_a = await parseProviderOptions2({
775
794
  provider: "bedrock",
776
795
  providerOptions,
777
796
  schema: amazonBedrockLanguageModelOptions
@@ -818,6 +837,14 @@ var BedrockChatLanguageModel = class {
818
837
  });
819
838
  }
820
839
  const isAnthropicModel = this.modelId.includes("anthropic");
840
+ const isOpenAIModel = this.modelId.startsWith("openai.");
841
+ bedrockOptions = resolveBedrockReasoningConfig({
842
+ reasoning,
843
+ bedrockOptions,
844
+ warnings,
845
+ isAnthropicModel,
846
+ modelId: this.modelId
847
+ });
821
848
  const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
822
849
  const useNativeStructuredOutput = isAnthropicModel && isThinkingEnabled && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
823
850
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
@@ -895,7 +922,6 @@ var BedrockChatLanguageModel = class {
895
922
  }
896
923
  }
897
924
  const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
898
- const isOpenAIModel = this.modelId.startsWith("openai.");
899
925
  if (maxReasoningEffort != null) {
900
926
  if (isAnthropicModel) {
901
927
  bedrockOptions.additionalModelRequestFields = {
@@ -991,6 +1017,7 @@ var BedrockChatLanguageModel = class {
991
1017
  const {
992
1018
  reasoningConfig: _,
993
1019
  additionalModelRequestFields: __,
1020
+ serviceTier: ___,
994
1021
  ...filteredBedrockOptions
995
1022
  } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
996
1023
  const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
@@ -1005,6 +1032,11 @@ var BedrockChatLanguageModel = class {
1005
1032
  ...Object.keys(inferenceConfig).length > 0 && {
1006
1033
  inferenceConfig
1007
1034
  },
1035
+ ...bedrockOptions.serviceTier != null && {
1036
+ serviceTier: {
1037
+ type: bedrockOptions.serviceTier
1038
+ }
1039
+ },
1008
1040
  ...filteredBedrockOptions,
1009
1041
  ...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
1010
1042
  },
@@ -1554,6 +1586,62 @@ var bedrockReasoningMetadataSchema = z3.object({
1554
1586
  signature: z3.string().optional(),
1555
1587
  redactedData: z3.string().optional()
1556
1588
  });
1589
+ var bedrockReasoningEffortMap = {
1590
+ minimal: "low",
1591
+ low: "low",
1592
+ medium: "medium",
1593
+ high: "high",
1594
+ xhigh: "max"
1595
+ };
1596
+ function resolveBedrockReasoningConfig({
1597
+ reasoning,
1598
+ bedrockOptions,
1599
+ warnings,
1600
+ isAnthropicModel,
1601
+ modelId
1602
+ }) {
1603
+ if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
1604
+ return bedrockOptions;
1605
+ }
1606
+ const result = { ...bedrockOptions };
1607
+ if (isAnthropicModel) {
1608
+ const capabilities = getModelCapabilities(modelId);
1609
+ if (reasoning === "none") {
1610
+ result.reasoningConfig = { type: "disabled" };
1611
+ } else if (capabilities.supportsAdaptiveThinking) {
1612
+ const effort = mapReasoningToProviderEffort({
1613
+ reasoning,
1614
+ effortMap: bedrockReasoningEffortMap,
1615
+ warnings
1616
+ });
1617
+ result.reasoningConfig = {
1618
+ type: "adaptive",
1619
+ maxReasoningEffort: effort
1620
+ };
1621
+ } else {
1622
+ const budgetTokens = mapReasoningToProviderBudget({
1623
+ reasoning,
1624
+ maxOutputTokens: capabilities.maxOutputTokens,
1625
+ maxReasoningBudget: capabilities.maxOutputTokens,
1626
+ warnings
1627
+ });
1628
+ if (budgetTokens != null) {
1629
+ result.reasoningConfig = {
1630
+ type: "enabled",
1631
+ budgetTokens
1632
+ };
1633
+ }
1634
+ }
1635
+ } else if (reasoning !== "none") {
1636
+ const effort = mapReasoningToProviderEffort({
1637
+ reasoning,
1638
+ effortMap: bedrockReasoningEffortMap,
1639
+ warnings
1640
+ });
1641
+ result.reasoningConfig = { maxReasoningEffort: effort };
1642
+ }
1643
+ return result;
1644
+ }
1557
1645
 
1558
1646
  // src/bedrock-embedding-model.ts
1559
1647
  import {
@@ -1626,7 +1714,7 @@ var BedrockEmbeddingModel = class {
1626
1714
  constructor(modelId, config) {
1627
1715
  this.modelId = modelId;
1628
1716
  this.config = config;
1629
- this.specificationVersion = "v3";
1717
+ this.specificationVersion = "v4";
1630
1718
  this.provider = "amazon-bedrock";
1631
1719
  this.maxEmbeddingsPerCall = 1;
1632
1720
  this.supportsParallelCalls = true;
@@ -1766,7 +1854,7 @@ var BedrockImageModel = class {
1766
1854
  constructor(modelId, config) {
1767
1855
  this.modelId = modelId;
1768
1856
  this.config = config;
1769
- this.specificationVersion = "v3";
1857
+ this.specificationVersion = "v4";
1770
1858
  this.provider = "amazon-bedrock";
1771
1859
  }
1772
1860
  get maxImagesPerCall() {
@@ -1969,7 +2057,7 @@ import {
1969
2057
  import { AwsV4Signer } from "aws4fetch";
1970
2058
 
1971
2059
  // src/version.ts
1972
- var VERSION = true ? "5.0.0-beta.2" : "0.0.0-test";
2060
+ var VERSION = true ? "5.0.0-beta.20" : "0.0.0-test";
1973
2061
 
1974
2062
  // src/bedrock-sigv4-fetch.ts
1975
2063
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -2102,7 +2190,7 @@ var BedrockRerankingModel = class {
2102
2190
  constructor(modelId, config) {
2103
2191
  this.modelId = modelId;
2104
2192
  this.config = config;
2105
- this.specificationVersion = "v3";
2193
+ this.specificationVersion = "v4";
2106
2194
  this.provider = "amazon-bedrock";
2107
2195
  }
2108
2196
  async doRerank({
@@ -2306,7 +2394,7 @@ Original error: ${errorMessage}`
2306
2394
  headers: getHeaders,
2307
2395
  fetch: fetchFunction
2308
2396
  });
2309
- provider.specificationVersion = "v3";
2397
+ provider.specificationVersion = "v4";
2310
2398
  provider.languageModel = createChatModel;
2311
2399
  provider.embedding = createEmbeddingModel;
2312
2400
  provider.embeddingModel = createEmbeddingModel;