@ai-sdk/amazon-bedrock 3.0.21 → 3.0.22
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 +6 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1498,23 +1498,37 @@ function convertHeadersToRecord(headers) {
|
|
|
1498
1498
|
// src/bedrock-sigv4-fetch.ts
|
|
1499
1499
|
import {
|
|
1500
1500
|
combineHeaders as combineHeaders4,
|
|
1501
|
-
|
|
1501
|
+
withUserAgentSuffix,
|
|
1502
|
+
getRuntimeEnvironmentUserAgent
|
|
1502
1503
|
} from "@ai-sdk/provider-utils";
|
|
1503
1504
|
import { AwsV4Signer } from "aws4fetch";
|
|
1505
|
+
|
|
1506
|
+
// src/version.ts
|
|
1507
|
+
var VERSION = true ? "3.0.22" : "0.0.0-test";
|
|
1508
|
+
|
|
1509
|
+
// src/bedrock-sigv4-fetch.ts
|
|
1504
1510
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
1505
1511
|
return async (input, init) => {
|
|
1506
1512
|
var _a;
|
|
1513
|
+
const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
|
|
1514
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
1515
|
+
originalHeaders,
|
|
1516
|
+
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1517
|
+
getRuntimeEnvironmentUserAgent()
|
|
1518
|
+
);
|
|
1507
1519
|
if (((_a = init == null ? void 0 : init.method) == null ? void 0 : _a.toUpperCase()) !== "POST" || !(init == null ? void 0 : init.body)) {
|
|
1508
|
-
return fetch(input,
|
|
1520
|
+
return fetch(input, {
|
|
1521
|
+
...init,
|
|
1522
|
+
headers: headersWithUserAgent
|
|
1523
|
+
});
|
|
1509
1524
|
}
|
|
1510
1525
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
1511
|
-
const originalHeaders = extractHeaders(init.headers);
|
|
1512
1526
|
const body = prepareBodyString(init.body);
|
|
1513
1527
|
const credentials = await getCredentials();
|
|
1514
1528
|
const signer = new AwsV4Signer({
|
|
1515
1529
|
url,
|
|
1516
1530
|
method: "POST",
|
|
1517
|
-
headers: Object.entries(
|
|
1531
|
+
headers: Object.entries(headersWithUserAgent),
|
|
1518
1532
|
body,
|
|
1519
1533
|
region: credentials.region,
|
|
1520
1534
|
accessKeyId: credentials.accessKeyId,
|
|
@@ -1524,12 +1538,11 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1524
1538
|
});
|
|
1525
1539
|
const signingResult = await signer.sign();
|
|
1526
1540
|
const signedHeaders = convertHeadersToRecord(signingResult.headers);
|
|
1541
|
+
const combinedHeaders = combineHeaders4(headersWithUserAgent, signedHeaders);
|
|
1527
1542
|
return fetch(input, {
|
|
1528
1543
|
...init,
|
|
1529
1544
|
body,
|
|
1530
|
-
headers:
|
|
1531
|
-
combineHeaders4(originalHeaders, signedHeaders)
|
|
1532
|
-
)
|
|
1545
|
+
headers: combinedHeaders
|
|
1533
1546
|
});
|
|
1534
1547
|
};
|
|
1535
1548
|
}
|
|
@@ -1547,13 +1560,17 @@ function prepareBodyString(body) {
|
|
|
1547
1560
|
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
1548
1561
|
return async (input, init) => {
|
|
1549
1562
|
const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
|
|
1563
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
1564
|
+
originalHeaders,
|
|
1565
|
+
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1566
|
+
getRuntimeEnvironmentUserAgent()
|
|
1567
|
+
);
|
|
1568
|
+
const finalHeaders = combineHeaders4(headersWithUserAgent, {
|
|
1569
|
+
Authorization: `Bearer ${apiKey}`
|
|
1570
|
+
});
|
|
1550
1571
|
return fetch(input, {
|
|
1551
1572
|
...init,
|
|
1552
|
-
headers:
|
|
1553
|
-
combineHeaders4(originalHeaders, {
|
|
1554
|
-
Authorization: `Bearer ${apiKey}`
|
|
1555
|
-
})
|
|
1556
|
-
)
|
|
1573
|
+
headers: finalHeaders
|
|
1557
1574
|
});
|
|
1558
1575
|
};
|
|
1559
1576
|
}
|
|
@@ -1681,6 +1698,7 @@ Original error: ${errorMessage}`
|
|
|
1681
1698
|
}
|
|
1682
1699
|
var bedrock = createAmazonBedrock();
|
|
1683
1700
|
export {
|
|
1701
|
+
VERSION,
|
|
1684
1702
|
bedrock,
|
|
1685
1703
|
createAmazonBedrock
|
|
1686
1704
|
};
|