@ai-sdk/amazon-bedrock 3.1.0-beta.8 → 4.0.0-beta.17

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
@@ -8,7 +8,7 @@ import {
8
8
  } from "@ai-sdk/provider-utils";
9
9
 
10
10
  // src/version.ts
11
- var VERSION = true ? "3.1.0-beta.8" : "0.0.0-test";
11
+ var VERSION = true ? "4.0.0-beta.17" : "0.0.0-test";
12
12
 
13
13
  // src/bedrock-provider.ts
14
14
  import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
@@ -60,6 +60,18 @@ var BEDROCK_DOCUMENT_MIME_TYPES = {
60
60
 
61
61
  // src/bedrock-chat-options.ts
62
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
+ });
63
75
  var bedrockProviderOptions = z.object({
64
76
  /**
65
77
  * Additional inference parameters that the model supports,
@@ -307,7 +319,17 @@ function getCachePoint(providerMetadata) {
307
319
  var _a;
308
320
  return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
309
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
+ }
310
331
  async function convertToBedrockChatMessages(prompt) {
332
+ var _a, _b;
311
333
  const blocks = groupIntoBlocks(prompt);
312
334
  let system = [];
313
335
  const messages = [];
@@ -367,11 +389,17 @@ async function convertToBedrockChatMessages(prompt) {
367
389
  message: "File mime type is required in user message part content"
368
390
  });
369
391
  }
392
+ const enableCitations = await shouldEnableCitations(
393
+ part.providerOptions
394
+ );
370
395
  bedrockContent.push({
371
396
  document: {
372
397
  format: getBedrockDocumentFormat(part.mediaType),
373
- name: generateDocumentName(),
374
- source: { bytes: convertToBase64(part.data) }
398
+ name: (_a = part.filename) != null ? _a : generateDocumentName(),
399
+ source: { bytes: convertToBase64(part.data) },
400
+ ...enableCitations && {
401
+ citations: { enabled: true }
402
+ }
375
403
  }
376
404
  });
377
405
  }
@@ -414,6 +442,11 @@ async function convertToBedrockChatMessages(prompt) {
414
442
  case "error-text":
415
443
  toolResultContent = [{ text: output.value }];
416
444
  break;
445
+ case "execution-denied":
446
+ toolResultContent = [
447
+ { text: (_b = output.reason) != null ? _b : "Tool execution denied." }
448
+ ];
449
+ break;
417
450
  case "json":
418
451
  case "error-json":
419
452
  default:
@@ -1510,21 +1543,33 @@ import {
1510
1543
  import { AwsV4Signer } from "aws4fetch";
1511
1544
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1512
1545
  return async (input, init) => {
1513
- var _a;
1514
- const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
1546
+ var _a, _b;
1547
+ const request = input instanceof Request ? input : void 0;
1548
+ const originalHeaders = combineHeaders4(
1549
+ extractHeaders(request == null ? void 0 : request.headers),
1550
+ extractHeaders(init == null ? void 0 : init.headers)
1551
+ );
1515
1552
  const headersWithUserAgent = withUserAgentSuffix(
1516
1553
  originalHeaders,
1517
1554
  `ai-sdk/amazon-bedrock/${VERSION}`,
1518
1555
  getRuntimeEnvironmentUserAgent()
1519
1556
  );
1520
- if (((_a = init == null ? void 0 : init.method) == null ? void 0 : _a.toUpperCase()) !== "POST" || !(init == null ? void 0 : init.body)) {
1557
+ let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
1558
+ if (effectiveBody === void 0 && request && request.body !== null) {
1559
+ try {
1560
+ effectiveBody = await request.clone().text();
1561
+ } catch (e) {
1562
+ }
1563
+ }
1564
+ const effectiveMethod = (_b = init == null ? void 0 : init.method) != null ? _b : request == null ? void 0 : request.method;
1565
+ if ((effectiveMethod == null ? void 0 : effectiveMethod.toUpperCase()) !== "POST" || !effectiveBody) {
1521
1566
  return fetch(input, {
1522
1567
  ...init,
1523
1568
  headers: headersWithUserAgent
1524
1569
  });
1525
1570
  }
1526
1571
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
1527
- const body = prepareBodyString(init.body);
1572
+ const body = prepareBodyString(effectiveBody);
1528
1573
  const credentials = await getCredentials();
1529
1574
  const signer = new AwsV4Signer({
1530
1575
  url,