@ai-sdk/amazon-bedrock 3.1.0-beta.1 → 3.1.0-beta.10

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
@@ -3,8 +3,14 @@ import {
3
3
  generateId,
4
4
  loadOptionalSetting,
5
5
  loadSetting,
6
- withoutTrailingSlash
6
+ withoutTrailingSlash,
7
+ withUserAgentSuffix as withUserAgentSuffix2
7
8
  } from "@ai-sdk/provider-utils";
9
+
10
+ // src/version.ts
11
+ var VERSION = true ? "3.1.0-beta.10" : "0.0.0-test";
12
+
13
+ // src/bedrock-provider.ts
8
14
  import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
9
15
 
10
16
  // src/bedrock-chat-language-model.ts
@@ -54,6 +60,18 @@ var BEDROCK_DOCUMENT_MIME_TYPES = {
54
60
 
55
61
  // src/bedrock-chat-options.ts
56
62
  import { z } from "zod/v4";
63
+ var bedrockFilePartProviderOptions = z.object({
64
+ /**
65
+ * Citation configuration for this document.
66
+ * When enabled, this document will generate citations in the response.
67
+ */
68
+ citations: z.object({
69
+ /**
70
+ * Enable citations for this document
71
+ */
72
+ enabled: z.boolean()
73
+ }).optional()
74
+ });
57
75
  var bedrockProviderOptions = z.object({
58
76
  /**
59
77
  * Additional inference parameters that the model supports,
@@ -301,6 +319,15 @@ function getCachePoint(providerMetadata) {
301
319
  var _a;
302
320
  return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
303
321
  }
322
+ async function shouldEnableCitations(providerMetadata) {
323
+ var _a, _b;
324
+ const bedrockOptions = await parseProviderOptions({
325
+ provider: "bedrock",
326
+ providerOptions: providerMetadata,
327
+ schema: bedrockFilePartProviderOptions
328
+ });
329
+ return (_b = (_a = bedrockOptions == null ? void 0 : bedrockOptions.citations) == null ? void 0 : _a.enabled) != null ? _b : false;
330
+ }
304
331
  async function convertToBedrockChatMessages(prompt) {
305
332
  const blocks = groupIntoBlocks(prompt);
306
333
  let system = [];
@@ -361,11 +388,17 @@ async function convertToBedrockChatMessages(prompt) {
361
388
  message: "File mime type is required in user message part content"
362
389
  });
363
390
  }
391
+ const enableCitations = await shouldEnableCitations(
392
+ part.providerOptions
393
+ );
364
394
  bedrockContent.push({
365
395
  document: {
366
396
  format: getBedrockDocumentFormat(part.mediaType),
367
397
  name: generateDocumentName(),
368
- source: { bytes: convertToBase64(part.data) }
398
+ source: { bytes: convertToBase64(part.data) },
399
+ ...enableCitations && {
400
+ citations: { enabled: true }
401
+ }
369
402
  }
370
403
  });
371
404
  }
@@ -628,7 +661,7 @@ var BedrockChatLanguageModel = class {
628
661
  constructor(modelId, config) {
629
662
  this.modelId = modelId;
630
663
  this.config = config;
631
- this.specificationVersion = "v2";
664
+ this.specificationVersion = "v3";
632
665
  this.provider = "amazon-bedrock";
633
666
  this.supportedUrls = {
634
667
  // no supported urls for bedrock
@@ -1308,7 +1341,7 @@ var BedrockEmbeddingModel = class {
1308
1341
  constructor(modelId, config) {
1309
1342
  this.modelId = modelId;
1310
1343
  this.config = config;
1311
- this.specificationVersion = "v2";
1344
+ this.specificationVersion = "v3";
1312
1345
  this.provider = "amazon-bedrock";
1313
1346
  this.maxEmbeddingsPerCall = 1;
1314
1347
  this.supportsParallelCalls = true;
@@ -1390,7 +1423,7 @@ var BedrockImageModel = class {
1390
1423
  constructor(modelId, config) {
1391
1424
  this.modelId = modelId;
1392
1425
  this.config = config;
1393
- this.specificationVersion = "v2";
1426
+ this.specificationVersion = "v3";
1394
1427
  this.provider = "amazon-bedrock";
1395
1428
  }
1396
1429
  get maxImagesPerCall() {
@@ -1502,28 +1535,35 @@ import {
1502
1535
  getRuntimeEnvironmentUserAgent
1503
1536
  } from "@ai-sdk/provider-utils";
1504
1537
  import { AwsV4Signer } from "aws4fetch";
1505
-
1506
- // src/version.ts
1507
- var VERSION = true ? "3.1.0-beta.1" : "0.0.0-test";
1508
-
1509
- // src/bedrock-sigv4-fetch.ts
1510
1538
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1511
1539
  return async (input, init) => {
1512
- var _a;
1513
- const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
1540
+ var _a, _b;
1541
+ const request = input instanceof Request ? input : void 0;
1542
+ const originalHeaders = combineHeaders4(
1543
+ extractHeaders(request == null ? void 0 : request.headers),
1544
+ extractHeaders(init == null ? void 0 : init.headers)
1545
+ );
1514
1546
  const headersWithUserAgent = withUserAgentSuffix(
1515
1547
  originalHeaders,
1516
1548
  `ai-sdk/amazon-bedrock/${VERSION}`,
1517
1549
  getRuntimeEnvironmentUserAgent()
1518
1550
  );
1519
- if (((_a = init == null ? void 0 : init.method) == null ? void 0 : _a.toUpperCase()) !== "POST" || !(init == null ? void 0 : init.body)) {
1551
+ let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
1552
+ if (effectiveBody === void 0 && request && request.body !== null) {
1553
+ try {
1554
+ effectiveBody = await request.clone().text();
1555
+ } catch (e) {
1556
+ }
1557
+ }
1558
+ const effectiveMethod = (_b = init == null ? void 0 : init.method) != null ? _b : request == null ? void 0 : request.method;
1559
+ if ((effectiveMethod == null ? void 0 : effectiveMethod.toUpperCase()) !== "POST" || !effectiveBody) {
1520
1560
  return fetch(input, {
1521
1561
  ...init,
1522
1562
  headers: headersWithUserAgent
1523
1563
  });
1524
1564
  }
1525
1565
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
1526
- const body = prepareBodyString(init.body);
1566
+ const body = prepareBodyString(effectiveBody);
1527
1567
  const credentials = await getCredentials();
1528
1568
  const signer = new AwsV4Signer({
1529
1569
  url,
@@ -1654,15 +1694,17 @@ Original error: ${errorMessage}`
1654
1694
  })}.amazonaws.com`
1655
1695
  )) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
1656
1696
  };
1657
- const createChatModel = (modelId) => {
1697
+ const getHeaders = () => {
1658
1698
  var _a;
1659
- return new BedrockChatLanguageModel(modelId, {
1660
- baseUrl: getBaseUrl,
1661
- headers: (_a = options.headers) != null ? _a : {},
1662
- fetch: fetchFunction,
1663
- generateId
1664
- });
1699
+ const baseHeaders = (_a = options.headers) != null ? _a : {};
1700
+ return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
1665
1701
  };
1702
+ const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
1703
+ baseUrl: getBaseUrl,
1704
+ headers: getHeaders,
1705
+ fetch: fetchFunction,
1706
+ generateId
1707
+ });
1666
1708
  const provider = function(modelId) {
1667
1709
  if (new.target) {
1668
1710
  throw new Error(
@@ -1671,22 +1713,16 @@ Original error: ${errorMessage}`
1671
1713
  }
1672
1714
  return createChatModel(modelId);
1673
1715
  };
1674
- const createEmbeddingModel = (modelId) => {
1675
- var _a;
1676
- return new BedrockEmbeddingModel(modelId, {
1677
- baseUrl: getBaseUrl,
1678
- headers: (_a = options.headers) != null ? _a : {},
1679
- fetch: fetchFunction
1680
- });
1681
- };
1682
- const createImageModel = (modelId) => {
1683
- var _a;
1684
- return new BedrockImageModel(modelId, {
1685
- baseUrl: getBaseUrl,
1686
- headers: (_a = options.headers) != null ? _a : {},
1687
- fetch: fetchFunction
1688
- });
1689
- };
1716
+ const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
1717
+ baseUrl: getBaseUrl,
1718
+ headers: getHeaders,
1719
+ fetch: fetchFunction
1720
+ });
1721
+ const createImageModel = (modelId) => new BedrockImageModel(modelId, {
1722
+ baseUrl: getBaseUrl,
1723
+ headers: getHeaders,
1724
+ fetch: fetchFunction
1725
+ });
1690
1726
  provider.languageModel = createChatModel;
1691
1727
  provider.embedding = createEmbeddingModel;
1692
1728
  provider.textEmbedding = createEmbeddingModel;