@ai-sdk/amazon-bedrock 4.0.137 → 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 +21 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +55 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -12
- 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 +4 -6
- package/src/convert-to-bedrock-chat-messages.ts +57 -9
package/dist/mantle/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "4.0.
|
|
38
|
+
var VERSION = true ? "4.0.139" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "4.0.
|
|
26
|
+
var VERSION = true ? "4.0.139" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/bedrock-sigv4-fetch.ts
|
|
29
29
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.139",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@smithy/eventstream-codec": "^4.0.1",
|
|
45
45
|
"@smithy/util-utf8": "^4.0.0",
|
|
46
46
|
"aws4fetch": "^1.0.20",
|
|
47
|
-
"@ai-sdk/anthropic": "3.0.
|
|
48
|
-
"@ai-sdk/openai": "3.0.
|
|
47
|
+
"@ai-sdk/anthropic": "3.0.100",
|
|
48
|
+
"@ai-sdk/openai": "3.0.87",
|
|
49
49
|
"@ai-sdk/provider": "3.0.14",
|
|
50
50
|
"@ai-sdk/provider-utils": "4.0.40"
|
|
51
51
|
},
|
package/src/bedrock-api-types.ts
CHANGED
|
@@ -165,9 +165,15 @@ export interface BedrockGuardrailConverseContentBlock {
|
|
|
165
165
|
export interface BedrockImageBlock {
|
|
166
166
|
image: {
|
|
167
167
|
format: BedrockImageFormat;
|
|
168
|
-
source:
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
source:
|
|
169
|
+
| {
|
|
170
|
+
bytes: string;
|
|
171
|
+
}
|
|
172
|
+
| {
|
|
173
|
+
s3Location: {
|
|
174
|
+
uri: string;
|
|
175
|
+
};
|
|
176
|
+
};
|
|
171
177
|
};
|
|
172
178
|
}
|
|
173
179
|
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type ParseResult,
|
|
25
25
|
type Resolvable,
|
|
26
26
|
} from '@ai-sdk/provider-utils';
|
|
27
|
+
import { sanitizeJsonSchema } from '@ai-sdk/anthropic/internal';
|
|
27
28
|
import { z } from 'zod/v4';
|
|
28
29
|
import {
|
|
29
30
|
BEDROCK_STOP_REASONS,
|
|
@@ -316,7 +317,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
316
317
|
...bedrockOptions.additionalModelRequestFields?.output_config,
|
|
317
318
|
format: {
|
|
318
319
|
type: 'json_schema',
|
|
319
|
-
schema: responseFormat!.schema,
|
|
320
|
+
schema: sanitizeJsonSchema(responseFormat!.schema!),
|
|
320
321
|
},
|
|
321
322
|
},
|
|
322
323
|
};
|
|
@@ -446,7 +447,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
446
447
|
}
|
|
447
448
|
|
|
448
449
|
readonly supportedUrls: Record<string, RegExp[]> = {
|
|
449
|
-
|
|
450
|
+
'image/*': [/^s3:\/\//],
|
|
450
451
|
};
|
|
451
452
|
|
|
452
453
|
private async getHeaders({
|
|
@@ -1041,10 +1042,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
1041
1042
|
}
|
|
1042
1043
|
|
|
1043
1044
|
private getUrl(modelId: string) {
|
|
1044
|
-
|
|
1045
|
-
? encodeURIComponent(modelId).replace(/%3A/g, ':').replace(/%2F/g, '/')
|
|
1046
|
-
: encodeURIComponent(modelId);
|
|
1047
|
-
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
1045
|
+
return `${this.config.baseUrl()}/model/${encodeURIComponent(modelId)}`;
|
|
1048
1046
|
}
|
|
1049
1047
|
}
|
|
1050
1048
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UnsupportedFunctionalityError,
|
|
3
3
|
type JSONObject,
|
|
4
|
+
type LanguageModelV3FilePart,
|
|
4
5
|
type LanguageModelV3Message,
|
|
5
6
|
type LanguageModelV3Prompt,
|
|
6
7
|
type SharedV3ProviderMetadata,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
type BedrockCachePoint,
|
|
18
19
|
type BedrockDocumentFormat,
|
|
19
20
|
type BedrockDocumentMimeType,
|
|
21
|
+
type BedrockImageBlock,
|
|
20
22
|
type BedrockImageFormat,
|
|
21
23
|
type BedrockImageMimeType,
|
|
22
24
|
type BedrockMessages,
|
|
@@ -51,6 +53,38 @@ function pushCachePoint(
|
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
56
|
+
function sanitizeToolName(toolName: string): string {
|
|
57
|
+
return toolName.replace(/[^a-zA-Z0-9_-]/g, '') || '_';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getBedrockImageSource({
|
|
61
|
+
data,
|
|
62
|
+
functionality,
|
|
63
|
+
}: {
|
|
64
|
+
data: LanguageModelV3FilePart['data'];
|
|
65
|
+
functionality: string;
|
|
66
|
+
}): BedrockImageBlock['image']['source'] {
|
|
67
|
+
if (data instanceof URL) {
|
|
68
|
+
if (data.protocol !== 's3:') {
|
|
69
|
+
throw new UnsupportedFunctionalityError({ functionality });
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
s3Location: {
|
|
73
|
+
uri: data.toString(),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { bytes: convertToBase64(data) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getBedrockImageFormatFromUrl(url: URL): BedrockImageFormat {
|
|
82
|
+
const extension = url.pathname.split('.').pop()?.toLowerCase();
|
|
83
|
+
return getBedrockImageFormat(
|
|
84
|
+
`image/${extension === 'jpg' ? 'jpeg' : extension}`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
54
88
|
async function shouldEnableCitations(
|
|
55
89
|
providerMetadata: SharedV3ProviderMetadata | undefined,
|
|
56
90
|
): Promise<boolean> {
|
|
@@ -122,21 +156,23 @@ export async function convertToBedrockChatMessages(
|
|
|
122
156
|
}
|
|
123
157
|
|
|
124
158
|
case 'file': {
|
|
125
|
-
if (part.data instanceof URL) {
|
|
126
|
-
// The AI SDK automatically downloads files for user file parts with URLs
|
|
127
|
-
throw new UnsupportedFunctionalityError({
|
|
128
|
-
functionality: 'File URL data',
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
159
|
if (part.mediaType.startsWith('image/')) {
|
|
133
160
|
bedrockContent.push({
|
|
134
161
|
image: {
|
|
135
162
|
format: getBedrockImageFormat(part.mediaType),
|
|
136
|
-
source: {
|
|
163
|
+
source: getBedrockImageSource({
|
|
164
|
+
data: part.data,
|
|
165
|
+
functionality: 'File URL data',
|
|
166
|
+
}),
|
|
137
167
|
},
|
|
138
168
|
});
|
|
139
169
|
} else {
|
|
170
|
+
if (part.data instanceof URL) {
|
|
171
|
+
throw new UnsupportedFunctionalityError({
|
|
172
|
+
functionality: 'File URL data',
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
140
176
|
if (!part.mediaType) {
|
|
141
177
|
throw new UnsupportedFunctionalityError({
|
|
142
178
|
functionality: 'file without mime type',
|
|
@@ -199,6 +235,18 @@ export async function convertToBedrockChatMessages(
|
|
|
199
235
|
},
|
|
200
236
|
};
|
|
201
237
|
}
|
|
238
|
+
case 'image-url': {
|
|
239
|
+
const url = new URL(contentPart.url);
|
|
240
|
+
return {
|
|
241
|
+
image: {
|
|
242
|
+
format: getBedrockImageFormatFromUrl(url),
|
|
243
|
+
source: getBedrockImageSource({
|
|
244
|
+
data: url,
|
|
245
|
+
functionality: `tool result image URL "${contentPart.url}"`,
|
|
246
|
+
}),
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
202
250
|
case 'file-data': {
|
|
203
251
|
if (!contentPart.mediaType.startsWith('image/')) {
|
|
204
252
|
const enableCitations =
|
|
@@ -366,7 +414,7 @@ export async function convertToBedrockChatMessages(
|
|
|
366
414
|
bedrockContent.push({
|
|
367
415
|
toolUse: {
|
|
368
416
|
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
369
|
-
name: part.toolName,
|
|
417
|
+
name: sanitizeToolName(part.toolName),
|
|
370
418
|
input: part.input as JSONObject,
|
|
371
419
|
},
|
|
372
420
|
});
|