@ai-sdk/amazon-bedrock 5.0.27 → 5.0.28
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 +9 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/index.js +58 -12
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/package.json +2 -2
- package/src/amazon-bedrock-api-types.ts +9 -3
- package/src/amazon-bedrock-chat-language-model.ts +1 -1
- package/src/convert-to-amazon-bedrock-chat-messages.ts +71 -10
package/dist/mantle/index.cjs
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 ? "5.0.
|
|
38
|
+
var VERSION = true ? "5.0.28" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "5.0.
|
|
26
|
+
var VERSION = true ? "5.0.28" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/amazon-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": "5.0.
|
|
3
|
+
"version": "5.0.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@smithy/util-utf8": "^4.3.3",
|
|
46
46
|
"aws4fetch": "^1.0.20",
|
|
47
47
|
"@ai-sdk/anthropic": "4.0.18",
|
|
48
|
-
"@ai-sdk/openai": "4.0.
|
|
48
|
+
"@ai-sdk/openai": "4.0.18",
|
|
49
49
|
"@ai-sdk/provider": "4.0.3",
|
|
50
50
|
"@ai-sdk/provider-utils": "5.0.12"
|
|
51
51
|
},
|
|
@@ -170,9 +170,15 @@ export interface AmazonBedrockGuardrailConverseContentBlock {
|
|
|
170
170
|
export interface AmazonBedrockImageBlock {
|
|
171
171
|
image: {
|
|
172
172
|
format: AmazonBedrockImageFormat;
|
|
173
|
-
source:
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
source:
|
|
174
|
+
| {
|
|
175
|
+
bytes: string;
|
|
176
|
+
}
|
|
177
|
+
| {
|
|
178
|
+
s3Location: {
|
|
179
|
+
uri: string;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
176
182
|
};
|
|
177
183
|
}
|
|
178
184
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UnsupportedFunctionalityError,
|
|
3
3
|
type JSONObject,
|
|
4
|
+
type LanguageModelV4FilePart,
|
|
4
5
|
type JSONValue,
|
|
5
6
|
type LanguageModelV4Message,
|
|
6
7
|
type LanguageModelV4Prompt,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
type AmazonBedrockCachePoint,
|
|
22
23
|
type AmazonBedrockDocumentFormat,
|
|
23
24
|
type AmazonBedrockDocumentMimeType,
|
|
25
|
+
type AmazonBedrockImageBlock,
|
|
24
26
|
type AmazonBedrockImageFormat,
|
|
25
27
|
type AmazonBedrockImageMimeType,
|
|
26
28
|
type AmazonBedrockMessages,
|
|
@@ -58,6 +60,32 @@ function pushCachePoint(
|
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
function sanitizeToolName(toolName: string): string {
|
|
64
|
+
return toolName.replace(/[^a-zA-Z0-9_-]/g, '') || '_';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getAmazonBedrockImageSource({
|
|
68
|
+
data,
|
|
69
|
+
functionality,
|
|
70
|
+
}: {
|
|
71
|
+
data: Extract<LanguageModelV4FilePart['data'], { type: 'data' | 'url' }>;
|
|
72
|
+
functionality: string;
|
|
73
|
+
}): AmazonBedrockImageBlock['image']['source'] {
|
|
74
|
+
switch (data.type) {
|
|
75
|
+
case 'data':
|
|
76
|
+
return { bytes: convertToBase64(data.data) };
|
|
77
|
+
case 'url':
|
|
78
|
+
if (data.url.protocol !== 's3:') {
|
|
79
|
+
throw new UnsupportedFunctionalityError({ functionality });
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
s3Location: {
|
|
83
|
+
uri: data.url.toString(),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
61
89
|
async function shouldEnableCitations(
|
|
62
90
|
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
63
91
|
): Promise<boolean> {
|
|
@@ -142,9 +170,30 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
142
170
|
});
|
|
143
171
|
}
|
|
144
172
|
case 'url': {
|
|
145
|
-
|
|
146
|
-
|
|
173
|
+
if (part.data.url.protocol !== 's3:') {
|
|
174
|
+
throw new UnsupportedFunctionalityError({
|
|
175
|
+
functionality: 'File URL data',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
180
|
+
|
|
181
|
+
if (getTopLevelMediaType(fullMediaType) !== 'image') {
|
|
182
|
+
throw new UnsupportedFunctionalityError({
|
|
183
|
+
functionality: 'File URL data',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
amazonBedrockContent.push({
|
|
188
|
+
image: {
|
|
189
|
+
format: getAmazonBedrockImageFormat(fullMediaType),
|
|
190
|
+
source: getAmazonBedrockImageSource({
|
|
191
|
+
data: part.data,
|
|
192
|
+
functionality: 'File URL data',
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
147
195
|
});
|
|
196
|
+
break;
|
|
148
197
|
}
|
|
149
198
|
case 'text': {
|
|
150
199
|
const textMediaType = isFullMediaType(part.mediaType)
|
|
@@ -181,9 +230,10 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
181
230
|
image: {
|
|
182
231
|
format:
|
|
183
232
|
getAmazonBedrockImageFormat(fullMediaType),
|
|
184
|
-
source: {
|
|
185
|
-
|
|
186
|
-
|
|
233
|
+
source: getAmazonBedrockImageSource({
|
|
234
|
+
data: part.data,
|
|
235
|
+
functionality: 'File URL data',
|
|
236
|
+
}),
|
|
187
237
|
},
|
|
188
238
|
});
|
|
189
239
|
} else {
|
|
@@ -236,7 +286,11 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
236
286
|
case 'text':
|
|
237
287
|
return { text: contentPart.text };
|
|
238
288
|
case 'file': {
|
|
239
|
-
if (
|
|
289
|
+
if (
|
|
290
|
+
contentPart.data.type !== 'data' &&
|
|
291
|
+
(contentPart.data.type !== 'url' ||
|
|
292
|
+
contentPart.data.url.protocol !== 's3:')
|
|
293
|
+
) {
|
|
240
294
|
throw new UnsupportedFunctionalityError({
|
|
241
295
|
functionality: `tool result file data of type "${contentPart.data.type}"`,
|
|
242
296
|
});
|
|
@@ -249,6 +303,12 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
249
303
|
if (
|
|
250
304
|
getTopLevelMediaType(fullMediaType) !== 'image'
|
|
251
305
|
) {
|
|
306
|
+
if (contentPart.data.type !== 'data') {
|
|
307
|
+
throw new UnsupportedFunctionalityError({
|
|
308
|
+
functionality: `tool result file data of type "${contentPart.data.type}"`,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
252
312
|
const enableCitations =
|
|
253
313
|
await shouldEnableCitations(
|
|
254
314
|
contentPart.providerOptions,
|
|
@@ -279,9 +339,10 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
279
339
|
image: {
|
|
280
340
|
format:
|
|
281
341
|
getAmazonBedrockImageFormat(fullMediaType),
|
|
282
|
-
source: {
|
|
283
|
-
|
|
284
|
-
|
|
342
|
+
source: getAmazonBedrockImageSource({
|
|
343
|
+
data: contentPart.data,
|
|
344
|
+
functionality: `tool result file data of type "${contentPart.data.type}"`,
|
|
345
|
+
}),
|
|
285
346
|
},
|
|
286
347
|
};
|
|
287
348
|
}
|
|
@@ -421,7 +482,7 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
421
482
|
amazonBedrockContent.push({
|
|
422
483
|
toolUse: {
|
|
423
484
|
toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
|
|
424
|
-
name: part.toolName,
|
|
485
|
+
name: sanitizeToolName(part.toolName),
|
|
425
486
|
input: toBedrockToolInput(part.input),
|
|
426
487
|
},
|
|
427
488
|
});
|