@ai-sdk/amazon-bedrock 4.0.138 → 4.0.139
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 +11 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +50 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -9
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/package.json +3 -3
- package/src/bedrock-api-types.ts +9 -3
- package/src/bedrock-chat-language-model.ts +1 -1
- package/src/convert-to-bedrock-chat-messages.ts +57 -9
package/dist/index.mjs
CHANGED
|
@@ -418,6 +418,32 @@ function pushCachePoint(content, providerMetadata) {
|
|
|
418
418
|
content.push(cachePoint);
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
|
+
function sanitizeToolName(toolName) {
|
|
422
|
+
return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
|
|
423
|
+
}
|
|
424
|
+
function getBedrockImageSource({
|
|
425
|
+
data,
|
|
426
|
+
functionality
|
|
427
|
+
}) {
|
|
428
|
+
if (data instanceof URL) {
|
|
429
|
+
if (data.protocol !== "s3:") {
|
|
430
|
+
throw new UnsupportedFunctionalityError2({ functionality });
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
s3Location: {
|
|
434
|
+
uri: data.toString()
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
return { bytes: convertToBase64(data) };
|
|
439
|
+
}
|
|
440
|
+
function getBedrockImageFormatFromUrl(url) {
|
|
441
|
+
var _a;
|
|
442
|
+
const extension = (_a = url.pathname.split(".").pop()) == null ? void 0 : _a.toLowerCase();
|
|
443
|
+
return getBedrockImageFormat(
|
|
444
|
+
`image/${extension === "jpg" ? "jpeg" : extension}`
|
|
445
|
+
);
|
|
446
|
+
}
|
|
421
447
|
async function shouldEnableCitations(providerMetadata) {
|
|
422
448
|
var _a, _b;
|
|
423
449
|
const bedrockOptions = await parseProviderOptions({
|
|
@@ -470,19 +496,22 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
470
496
|
break;
|
|
471
497
|
}
|
|
472
498
|
case "file": {
|
|
473
|
-
if (part.data instanceof URL) {
|
|
474
|
-
throw new UnsupportedFunctionalityError2({
|
|
475
|
-
functionality: "File URL data"
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
499
|
if (part.mediaType.startsWith("image/")) {
|
|
479
500
|
bedrockContent.push({
|
|
480
501
|
image: {
|
|
481
502
|
format: getBedrockImageFormat(part.mediaType),
|
|
482
|
-
source: {
|
|
503
|
+
source: getBedrockImageSource({
|
|
504
|
+
data: part.data,
|
|
505
|
+
functionality: "File URL data"
|
|
506
|
+
})
|
|
483
507
|
}
|
|
484
508
|
});
|
|
485
509
|
} else {
|
|
510
|
+
if (part.data instanceof URL) {
|
|
511
|
+
throw new UnsupportedFunctionalityError2({
|
|
512
|
+
functionality: "File URL data"
|
|
513
|
+
});
|
|
514
|
+
}
|
|
486
515
|
if (!part.mediaType) {
|
|
487
516
|
throw new UnsupportedFunctionalityError2({
|
|
488
517
|
functionality: "file without mime type",
|
|
@@ -536,6 +565,18 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
536
565
|
}
|
|
537
566
|
};
|
|
538
567
|
}
|
|
568
|
+
case "image-url": {
|
|
569
|
+
const url = new URL(contentPart.url);
|
|
570
|
+
return {
|
|
571
|
+
image: {
|
|
572
|
+
format: getBedrockImageFormatFromUrl(url),
|
|
573
|
+
source: getBedrockImageSource({
|
|
574
|
+
data: url,
|
|
575
|
+
functionality: `tool result image URL "${contentPart.url}"`
|
|
576
|
+
})
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
}
|
|
539
580
|
case "file-data": {
|
|
540
581
|
if (!contentPart.mediaType.startsWith("image/")) {
|
|
541
582
|
const enableCitations = await shouldEnableCitations(
|
|
@@ -676,7 +717,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
676
717
|
bedrockContent.push({
|
|
677
718
|
toolUse: {
|
|
678
719
|
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
679
|
-
name: part.toolName,
|
|
720
|
+
name: sanitizeToolName(part.toolName),
|
|
680
721
|
input: part.input
|
|
681
722
|
}
|
|
682
723
|
});
|
|
@@ -800,7 +841,7 @@ var BedrockChatLanguageModel = class {
|
|
|
800
841
|
this.specificationVersion = "v3";
|
|
801
842
|
this.provider = "amazon-bedrock";
|
|
802
843
|
this.supportedUrls = {
|
|
803
|
-
|
|
844
|
+
"image/*": [/^s3:\/\//]
|
|
804
845
|
};
|
|
805
846
|
}
|
|
806
847
|
async getArgs({
|
|
@@ -2123,7 +2164,7 @@ import {
|
|
|
2123
2164
|
import { AwsV4Signer } from "aws4fetch";
|
|
2124
2165
|
|
|
2125
2166
|
// src/version.ts
|
|
2126
|
-
var VERSION = true ? "4.0.
|
|
2167
|
+
var VERSION = true ? "4.0.139" : "0.0.0-test";
|
|
2127
2168
|
|
|
2128
2169
|
// src/bedrock-sigv4-fetch.ts
|
|
2129
2170
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|