@ai-sdk/amazon-bedrock 4.0.108 → 4.0.110

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.108",
3
+ "version": "4.0.110",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "@smithy/eventstream-codec": "^4.0.1",
39
39
  "@smithy/util-utf8": "^4.0.0",
40
40
  "aws4fetch": "^1.0.20",
41
- "@ai-sdk/anthropic": "3.0.79",
41
+ "@ai-sdk/anthropic": "3.0.80",
42
42
  "@ai-sdk/provider": "3.0.10",
43
43
  "@ai-sdk/provider-utils": "4.0.27"
44
44
  },
@@ -174,7 +174,7 @@ export interface BedrockImageBlock {
174
174
  export interface BedrockToolResultBlock {
175
175
  toolResult: {
176
176
  toolUseId: string;
177
- content: Array<BedrockTextBlock | BedrockImageBlock>;
177
+ content: Array<BedrockTextBlock | BedrockImageBlock | BedrockDocumentBlock>;
178
178
  };
179
179
  }
180
180
 
@@ -182,34 +182,69 @@ export async function convertToBedrockChatMessages(
182
182
  const output = part.output;
183
183
  switch (output.type) {
184
184
  case 'content': {
185
- toolResultContent = output.value.map(contentPart => {
186
- switch (contentPart.type) {
187
- case 'text':
188
- return { text: contentPart.text };
189
- case 'image-data':
190
- if (!contentPart.mediaType.startsWith('image/')) {
185
+ toolResultContent = await Promise.all(
186
+ output.value.map(async contentPart => {
187
+ switch (contentPart.type) {
188
+ case 'text':
189
+ return { text: contentPart.text };
190
+ case 'image-data': {
191
+ return {
192
+ image: {
193
+ format: getBedrockImageFormat(
194
+ contentPart.mediaType,
195
+ ),
196
+ source: {
197
+ bytes: convertToBase64(contentPart.data),
198
+ },
199
+ },
200
+ };
201
+ }
202
+ case 'file-data': {
203
+ if (!contentPart.mediaType.startsWith('image/')) {
204
+ const enableCitations =
205
+ await shouldEnableCitations(
206
+ contentPart.providerOptions,
207
+ );
208
+
209
+ return {
210
+ document: {
211
+ format: getBedrockDocumentFormat(
212
+ contentPart.mediaType,
213
+ ),
214
+ name:
215
+ 'filename' in contentPart &&
216
+ contentPart.filename
217
+ ? stripFileExtension(contentPart.filename)
218
+ : generateDocumentName(),
219
+ source: {
220
+ bytes: convertToBase64(contentPart.data),
221
+ },
222
+ ...(enableCitations && {
223
+ citations: { enabled: true },
224
+ }),
225
+ },
226
+ };
227
+ }
228
+
229
+ return {
230
+ image: {
231
+ format: getBedrockImageFormat(
232
+ contentPart.mediaType,
233
+ ),
234
+ source: {
235
+ bytes: convertToBase64(contentPart.data),
236
+ },
237
+ },
238
+ };
239
+ }
240
+ default: {
191
241
  throw new UnsupportedFunctionalityError({
192
- functionality: `media type: ${contentPart.mediaType}`,
242
+ functionality: `unsupported tool content part type: ${contentPart.type}`,
193
243
  });
194
244
  }
195
-
196
- const format = getBedrockImageFormat(
197
- contentPart.mediaType,
198
- );
199
-
200
- return {
201
- image: {
202
- format,
203
- source: { bytes: contentPart.data },
204
- },
205
- };
206
- default: {
207
- throw new UnsupportedFunctionalityError({
208
- functionality: `unsupported tool content part type: ${contentPart.type}`,
209
- });
210
245
  }
211
- }
212
- });
246
+ }),
247
+ );
213
248
  break;
214
249
  }
215
250
  case 'text':