@ai-sdk/amazon-bedrock 4.0.96 → 4.0.98

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