@ai-sdk/amazon-bedrock 4.0.97 → 4.0.99

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
@@ -17,7 +17,7 @@ import {
17
17
  postJsonToApi,
18
18
  resolve
19
19
  } from "@ai-sdk/provider-utils";
20
- import { z as z3 } from "zod/v4";
20
+ import { z as z4 } from "zod/v4";
21
21
 
22
22
  // src/bedrock-api-types.ts
23
23
  var BEDROCK_STOP_REASONS = [
@@ -381,6 +381,13 @@ import {
381
381
  stripFileExtension
382
382
  } from "@ai-sdk/provider-utils";
383
383
 
384
+ // src/bedrock-reasoning-metadata.ts
385
+ import { z as z3 } from "zod/v4";
386
+ var bedrockReasoningMetadataSchema = z3.object({
387
+ signature: z3.string().optional(),
388
+ redactedData: z3.string().optional()
389
+ });
390
+
384
391
  // src/normalize-tool-call-id.ts
385
392
  function isMistralModel(modelId) {
386
393
  return modelId.includes("mistral.");
@@ -624,7 +631,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
624
631
  }
625
632
  }
626
633
  });
627
- } else {
634
+ } else if (part.providerOptions == null || Object.keys(part.providerOptions).every(
635
+ (k2) => k2 === "bedrock" || k2 === "amazonBedrock"
636
+ )) {
628
637
  bedrockContent.push({
629
638
  reasoningContent: {
630
639
  reasoningText: {
@@ -1483,116 +1492,112 @@ var BedrockChatLanguageModel = class {
1483
1492
  return `${this.config.baseUrl()}/model/${encodedModelId}`;
1484
1493
  }
1485
1494
  };
1486
- var BedrockStopReasonSchema = z3.union([
1487
- z3.enum(BEDROCK_STOP_REASONS),
1488
- z3.string()
1495
+ var BedrockStopReasonSchema = z4.union([
1496
+ z4.enum(BEDROCK_STOP_REASONS),
1497
+ z4.string()
1489
1498
  ]);
1490
- var BedrockAdditionalModelResponseFieldsSchema = z3.object({
1491
- delta: z3.object({
1492
- stop_sequence: z3.string().nullish()
1499
+ var BedrockAdditionalModelResponseFieldsSchema = z4.object({
1500
+ delta: z4.object({
1501
+ stop_sequence: z4.string().nullish()
1493
1502
  }).nullish()
1494
- }).catchall(z3.unknown());
1495
- var BedrockToolUseSchema = z3.object({
1496
- toolUseId: z3.string(),
1497
- name: z3.string(),
1498
- input: z3.unknown()
1503
+ }).catchall(z4.unknown());
1504
+ var BedrockToolUseSchema = z4.object({
1505
+ toolUseId: z4.string(),
1506
+ name: z4.string(),
1507
+ input: z4.unknown()
1499
1508
  });
1500
- var BedrockReasoningTextSchema = z3.object({
1501
- signature: z3.string().nullish(),
1502
- text: z3.string()
1509
+ var BedrockReasoningTextSchema = z4.object({
1510
+ signature: z4.string().nullish(),
1511
+ text: z4.string()
1503
1512
  });
1504
- var BedrockRedactedReasoningSchema = z3.object({
1505
- data: z3.string()
1513
+ var BedrockRedactedReasoningSchema = z4.object({
1514
+ data: z4.string()
1506
1515
  });
1507
- var BedrockResponseSchema = z3.object({
1508
- metrics: z3.object({
1509
- latencyMs: z3.number()
1516
+ var BedrockResponseSchema = z4.object({
1517
+ metrics: z4.object({
1518
+ latencyMs: z4.number()
1510
1519
  }).nullish(),
1511
- output: z3.object({
1512
- message: z3.object({
1513
- content: z3.array(
1514
- z3.object({
1515
- text: z3.string().nullish(),
1520
+ output: z4.object({
1521
+ message: z4.object({
1522
+ content: z4.array(
1523
+ z4.object({
1524
+ text: z4.string().nullish(),
1516
1525
  toolUse: BedrockToolUseSchema.nullish(),
1517
- reasoningContent: z3.union([
1518
- z3.object({
1526
+ reasoningContent: z4.union([
1527
+ z4.object({
1519
1528
  reasoningText: BedrockReasoningTextSchema
1520
1529
  }),
1521
- z3.object({
1530
+ z4.object({
1522
1531
  redactedReasoning: BedrockRedactedReasoningSchema
1523
1532
  })
1524
1533
  ]).nullish()
1525
1534
  })
1526
1535
  ),
1527
- role: z3.string()
1536
+ role: z4.string()
1528
1537
  })
1529
1538
  }),
1530
1539
  stopReason: BedrockStopReasonSchema,
1531
1540
  additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
1532
- trace: z3.unknown().nullish(),
1533
- performanceConfig: z3.object({ latency: z3.string() }).nullish(),
1534
- serviceTier: z3.object({ type: z3.string() }).nullish(),
1535
- usage: z3.object({
1536
- inputTokens: z3.number(),
1537
- outputTokens: z3.number(),
1538
- totalTokens: z3.number(),
1539
- cacheReadInputTokens: z3.number().nullish(),
1540
- cacheWriteInputTokens: z3.number().nullish(),
1541
- cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish()
1541
+ trace: z4.unknown().nullish(),
1542
+ performanceConfig: z4.object({ latency: z4.string() }).nullish(),
1543
+ serviceTier: z4.object({ type: z4.string() }).nullish(),
1544
+ usage: z4.object({
1545
+ inputTokens: z4.number(),
1546
+ outputTokens: z4.number(),
1547
+ totalTokens: z4.number(),
1548
+ cacheReadInputTokens: z4.number().nullish(),
1549
+ cacheWriteInputTokens: z4.number().nullish(),
1550
+ cacheDetails: z4.array(z4.object({ inputTokens: z4.number(), ttl: z4.string() })).nullish()
1542
1551
  })
1543
1552
  });
1544
- var BedrockStreamSchema = z3.object({
1545
- contentBlockDelta: z3.object({
1546
- contentBlockIndex: z3.number(),
1547
- delta: z3.union([
1548
- z3.object({ text: z3.string() }),
1549
- z3.object({ toolUse: z3.object({ input: z3.string() }) }),
1550
- z3.object({
1551
- reasoningContent: z3.object({ text: z3.string() })
1553
+ var BedrockStreamSchema = z4.object({
1554
+ contentBlockDelta: z4.object({
1555
+ contentBlockIndex: z4.number(),
1556
+ delta: z4.union([
1557
+ z4.object({ text: z4.string() }),
1558
+ z4.object({ toolUse: z4.object({ input: z4.string() }) }),
1559
+ z4.object({
1560
+ reasoningContent: z4.object({ text: z4.string() })
1552
1561
  }),
1553
- z3.object({
1554
- reasoningContent: z3.object({
1555
- signature: z3.string()
1562
+ z4.object({
1563
+ reasoningContent: z4.object({
1564
+ signature: z4.string()
1556
1565
  })
1557
1566
  }),
1558
- z3.object({
1559
- reasoningContent: z3.object({ data: z3.string() })
1567
+ z4.object({
1568
+ reasoningContent: z4.object({ data: z4.string() })
1560
1569
  })
1561
1570
  ]).nullish()
1562
1571
  }).nullish(),
1563
- contentBlockStart: z3.object({
1564
- contentBlockIndex: z3.number(),
1565
- start: z3.object({
1572
+ contentBlockStart: z4.object({
1573
+ contentBlockIndex: z4.number(),
1574
+ start: z4.object({
1566
1575
  toolUse: BedrockToolUseSchema.nullish()
1567
1576
  }).nullish()
1568
1577
  }).nullish(),
1569
- contentBlockStop: z3.object({
1570
- contentBlockIndex: z3.number()
1578
+ contentBlockStop: z4.object({
1579
+ contentBlockIndex: z4.number()
1571
1580
  }).nullish(),
1572
- internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
1573
- messageStop: z3.object({
1581
+ internalServerException: z4.record(z4.string(), z4.unknown()).nullish(),
1582
+ messageStop: z4.object({
1574
1583
  additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
1575
1584
  stopReason: BedrockStopReasonSchema
1576
1585
  }).nullish(),
1577
- metadata: z3.object({
1578
- trace: z3.unknown().nullish(),
1579
- performanceConfig: z3.object({ latency: z3.string() }).nullish(),
1580
- serviceTier: z3.object({ type: z3.string() }).nullish(),
1581
- usage: z3.object({
1582
- cacheReadInputTokens: z3.number().nullish(),
1583
- cacheWriteInputTokens: z3.number().nullish(),
1584
- cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish(),
1585
- inputTokens: z3.number(),
1586
- outputTokens: z3.number()
1586
+ metadata: z4.object({
1587
+ trace: z4.unknown().nullish(),
1588
+ performanceConfig: z4.object({ latency: z4.string() }).nullish(),
1589
+ serviceTier: z4.object({ type: z4.string() }).nullish(),
1590
+ usage: z4.object({
1591
+ cacheReadInputTokens: z4.number().nullish(),
1592
+ cacheWriteInputTokens: z4.number().nullish(),
1593
+ cacheDetails: z4.array(z4.object({ inputTokens: z4.number(), ttl: z4.string() })).nullish(),
1594
+ inputTokens: z4.number(),
1595
+ outputTokens: z4.number()
1587
1596
  }).nullish()
1588
1597
  }).nullish(),
1589
- modelStreamErrorException: z3.record(z3.string(), z3.unknown()).nullish(),
1590
- throttlingException: z3.record(z3.string(), z3.unknown()).nullish(),
1591
- validationException: z3.record(z3.string(), z3.unknown()).nullish()
1592
- });
1593
- var bedrockReasoningMetadataSchema = z3.object({
1594
- signature: z3.string().optional(),
1595
- redactedData: z3.string().optional()
1598
+ modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
1599
+ throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
1600
+ validationException: z4.record(z4.string(), z4.unknown()).nullish()
1596
1601
  });
1597
1602
 
1598
1603
  // src/bedrock-embedding-model.ts
@@ -1609,29 +1614,29 @@ import {
1609
1614
  } from "@ai-sdk/provider-utils";
1610
1615
 
1611
1616
  // src/bedrock-embedding-options.ts
1612
- import { z as z4 } from "zod/v4";
1613
- var amazonBedrockEmbeddingModelOptionsSchema = z4.object({
1617
+ import { z as z5 } from "zod/v4";
1618
+ var amazonBedrockEmbeddingModelOptionsSchema = z5.object({
1614
1619
  /**
1615
1620
  * The number of dimensions the resulting output embeddings should have (defaults to 1024).
1616
1621
  * Only supported in amazon.titan-embed-text-v2:0.
1617
1622
  */
1618
- dimensions: z4.union([z4.literal(1024), z4.literal(512), z4.literal(256)]).optional(),
1623
+ dimensions: z5.union([z5.literal(1024), z5.literal(512), z5.literal(256)]).optional(),
1619
1624
  /**
1620
1625
  * Flag indicating whether or not to normalize the output embeddings. Defaults to true.
1621
1626
  * Only supported in amazon.titan-embed-text-v2:0.
1622
1627
  */
1623
- normalize: z4.boolean().optional(),
1628
+ normalize: z5.boolean().optional(),
1624
1629
  /**
1625
1630
  * The number of dimensions for Nova embedding models (defaults to 1024).
1626
1631
  * Supported values: 256, 384, 1024, 3072.
1627
1632
  * Only supported in amazon.nova-* embedding models.
1628
1633
  */
1629
- embeddingDimension: z4.union([z4.literal(256), z4.literal(384), z4.literal(1024), z4.literal(3072)]).optional(),
1634
+ embeddingDimension: z5.union([z5.literal(256), z5.literal(384), z5.literal(1024), z5.literal(3072)]).optional(),
1630
1635
  /**
1631
1636
  * The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
1632
1637
  * Only supported in amazon.nova-* embedding models.
1633
1638
  */
1634
- embeddingPurpose: z4.enum([
1639
+ embeddingPurpose: z5.enum([
1635
1640
  "GENERIC_INDEX",
1636
1641
  "TEXT_RETRIEVAL",
1637
1642
  "IMAGE_RETRIEVAL",
@@ -1647,21 +1652,21 @@ var amazonBedrockEmbeddingModelOptionsSchema = z4.object({
1647
1652
  * Common values: `search_document`, `search_query`, `classification`, `clustering`.
1648
1653
  * If not set, the provider defaults to `search_query`.
1649
1654
  */
1650
- inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
1655
+ inputType: z5.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
1651
1656
  /**
1652
1657
  * Truncation behavior when input exceeds the model's context length.
1653
1658
  * Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
1654
1659
  */
1655
- truncate: z4.enum(["NONE", "START", "END"]).optional(),
1660
+ truncate: z5.enum(["NONE", "START", "END"]).optional(),
1656
1661
  /**
1657
1662
  * The number of dimensions the resulting output embeddings should have (defaults to 1536).
1658
1663
  * Only supported in cohere.embed-v4:0 and newer Cohere embedding models.
1659
1664
  */
1660
- outputDimension: z4.union([z4.literal(256), z4.literal(512), z4.literal(1024), z4.literal(1536)]).optional()
1665
+ outputDimension: z5.union([z5.literal(256), z5.literal(512), z5.literal(1024), z5.literal(1536)]).optional()
1661
1666
  });
1662
1667
 
1663
1668
  // src/bedrock-embedding-model.ts
1664
- import { z as z5 } from "zod/v4";
1669
+ import { z as z6 } from "zod/v4";
1665
1670
  var BedrockEmbeddingModel = class {
1666
1671
  constructor(modelId, config) {
1667
1672
  this.modelId = modelId;
@@ -1757,30 +1762,30 @@ var BedrockEmbeddingModel = class {
1757
1762
  };
1758
1763
  }
1759
1764
  };
1760
- var BedrockEmbeddingResponseSchema = z5.union([
1765
+ var BedrockEmbeddingResponseSchema = z6.union([
1761
1766
  // Titan-style response
1762
- z5.object({
1763
- embedding: z5.array(z5.number()),
1764
- inputTextTokenCount: z5.number()
1767
+ z6.object({
1768
+ embedding: z6.array(z6.number()),
1769
+ inputTextTokenCount: z6.number()
1765
1770
  }),
1766
1771
  // Nova-style response
1767
- z5.object({
1768
- embeddings: z5.array(
1769
- z5.object({
1770
- embeddingType: z5.string(),
1771
- embedding: z5.array(z5.number())
1772
+ z6.object({
1773
+ embeddings: z6.array(
1774
+ z6.object({
1775
+ embeddingType: z6.string(),
1776
+ embedding: z6.array(z6.number())
1772
1777
  })
1773
1778
  ),
1774
- inputTokenCount: z5.number().optional()
1779
+ inputTokenCount: z6.number().optional()
1775
1780
  }),
1776
1781
  // Cohere v3-style response
1777
- z5.object({
1778
- embeddings: z5.array(z5.array(z5.number()))
1782
+ z6.object({
1783
+ embeddings: z6.array(z6.array(z6.number()))
1779
1784
  }),
1780
1785
  // Cohere v4-style response
1781
- z5.object({
1782
- embeddings: z5.object({
1783
- float: z5.array(z5.array(z5.number()))
1786
+ z6.object({
1787
+ embeddings: z6.object({
1788
+ float: z6.array(z6.array(z6.number()))
1784
1789
  })
1785
1790
  })
1786
1791
  ]);
@@ -1801,7 +1806,7 @@ var modelMaxImagesPerCall = {
1801
1806
  };
1802
1807
 
1803
1808
  // src/bedrock-image-model.ts
1804
- import { z as z6 } from "zod/v4";
1809
+ import { z as z7 } from "zod/v4";
1805
1810
  var BedrockImageModel = class {
1806
1811
  constructor(modelId, config) {
1807
1812
  this.modelId = modelId;
@@ -1987,16 +1992,16 @@ function getBase64Data(file) {
1987
1992
  }
1988
1993
  return file.data;
1989
1994
  }
1990
- var bedrockImageResponseSchema = z6.object({
1995
+ var bedrockImageResponseSchema = z7.object({
1991
1996
  // Normal successful response
1992
- images: z6.array(z6.string()).optional(),
1997
+ images: z7.array(z7.string()).optional(),
1993
1998
  // Moderation response fields
1994
- id: z6.string().optional(),
1995
- status: z6.string().optional(),
1996
- result: z6.unknown().optional(),
1997
- progress: z6.unknown().optional(),
1998
- details: z6.record(z6.string(), z6.unknown()).optional(),
1999
- preview: z6.unknown().optional()
1999
+ id: z7.string().optional(),
2000
+ status: z7.string().optional(),
2001
+ result: z7.unknown().optional(),
2002
+ progress: z7.unknown().optional(),
2003
+ details: z7.record(z7.string(), z7.unknown()).optional(),
2004
+ preview: z7.unknown().optional()
2000
2005
  });
2001
2006
 
2002
2007
  // src/bedrock-sigv4-fetch.ts
@@ -2009,7 +2014,7 @@ import {
2009
2014
  import { AwsV4Signer } from "aws4fetch";
2010
2015
 
2011
2016
  // src/version.ts
2012
- var VERSION = true ? "4.0.97" : "0.0.0-test";
2017
+ var VERSION = true ? "4.0.99" : "0.0.0-test";
2013
2018
 
2014
2019
  // src/bedrock-sigv4-fetch.ts
2015
2020
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -2104,35 +2109,35 @@ import {
2104
2109
 
2105
2110
  // src/reranking/bedrock-reranking-api.ts
2106
2111
  import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
2107
- import { z as z7 } from "zod/v4";
2112
+ import { z as z8 } from "zod/v4";
2108
2113
  var bedrockRerankingResponseSchema = lazySchema(
2109
2114
  () => zodSchema(
2110
- z7.object({
2111
- results: z7.array(
2112
- z7.object({
2113
- index: z7.number(),
2114
- relevanceScore: z7.number()
2115
+ z8.object({
2116
+ results: z8.array(
2117
+ z8.object({
2118
+ index: z8.number(),
2119
+ relevanceScore: z8.number()
2115
2120
  })
2116
2121
  ),
2117
- nextToken: z7.string().optional()
2122
+ nextToken: z8.string().optional()
2118
2123
  })
2119
2124
  )
2120
2125
  );
2121
2126
 
2122
2127
  // src/reranking/bedrock-reranking-options.ts
2123
2128
  import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
2124
- import { z as z8 } from "zod/v4";
2129
+ import { z as z9 } from "zod/v4";
2125
2130
  var amazonBedrockRerankingModelOptionsSchema = lazySchema2(
2126
2131
  () => zodSchema2(
2127
- z8.object({
2132
+ z9.object({
2128
2133
  /**
2129
2134
  * If the total number of results was greater than could fit in a response, a token is returned in the nextToken field. You can enter that token in this field to return the next batch of results.
2130
2135
  */
2131
- nextToken: z8.string().optional(),
2136
+ nextToken: z9.string().optional(),
2132
2137
  /**
2133
2138
  * Additional model request fields to pass to the model.
2134
2139
  */
2135
- additionalModelRequestFields: z8.record(z8.string(), z8.any()).optional()
2140
+ additionalModelRequestFields: z9.record(z9.string(), z9.any()).optional()
2136
2141
  })
2137
2142
  )
2138
2143
  );
@@ -2258,7 +2263,7 @@ function createAmazonBedrock(options = {}) {
2258
2263
  environmentVariableName: "AWS_SECRET_ACCESS_KEY",
2259
2264
  description: "AWS secret access key"
2260
2265
  }),
2261
- sessionToken: loadOptionalSetting({
2266
+ sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : loadOptionalSetting({
2262
2267
  settingValue: options.sessionToken,
2263
2268
  environmentVariableName: "AWS_SESSION_TOKEN"
2264
2269
  })