@ai-sdk/amazon-bedrock 3.0.27 → 3.0.29
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/CHANGELOG.md +13 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +45 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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.0.
|
|
11
|
+
var VERSION = true ? "3.0.29" : "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,6 +319,15 @@ 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) {
|
|
311
332
|
const blocks = groupIntoBlocks(prompt);
|
|
312
333
|
let system = [];
|
|
@@ -367,11 +388,17 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
367
388
|
message: "File mime type is required in user message part content"
|
|
368
389
|
});
|
|
369
390
|
}
|
|
391
|
+
const enableCitations = await shouldEnableCitations(
|
|
392
|
+
part.providerOptions
|
|
393
|
+
);
|
|
370
394
|
bedrockContent.push({
|
|
371
395
|
document: {
|
|
372
396
|
format: getBedrockDocumentFormat(part.mediaType),
|
|
373
397
|
name: generateDocumentName(),
|
|
374
|
-
source: { bytes: convertToBase64(part.data) }
|
|
398
|
+
source: { bytes: convertToBase64(part.data) },
|
|
399
|
+
...enableCitations && {
|
|
400
|
+
citations: { enabled: true }
|
|
401
|
+
}
|
|
375
402
|
}
|
|
376
403
|
});
|
|
377
404
|
}
|
|
@@ -1510,21 +1537,33 @@ import {
|
|
|
1510
1537
|
import { AwsV4Signer } from "aws4fetch";
|
|
1511
1538
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
1512
1539
|
return async (input, init) => {
|
|
1513
|
-
var _a;
|
|
1514
|
-
const
|
|
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
|
+
);
|
|
1515
1546
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
1516
1547
|
originalHeaders,
|
|
1517
1548
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1518
1549
|
getRuntimeEnvironmentUserAgent()
|
|
1519
1550
|
);
|
|
1520
|
-
|
|
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) {
|
|
1521
1560
|
return fetch(input, {
|
|
1522
1561
|
...init,
|
|
1523
1562
|
headers: headersWithUserAgent
|
|
1524
1563
|
});
|
|
1525
1564
|
}
|
|
1526
1565
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
1527
|
-
const body = prepareBodyString(
|
|
1566
|
+
const body = prepareBodyString(effectiveBody);
|
|
1528
1567
|
const credentials = await getCredentials();
|
|
1529
1568
|
const signer = new AwsV4Signer({
|
|
1530
1569
|
url,
|