@ai-sdk/amazon-bedrock 5.0.61 → 5.0.65

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.
@@ -33,7 +33,11 @@ import {
33
33
  type AmazonBedrockVideoFormat,
34
34
  type AmazonBedrockVideoMimeType,
35
35
  } from './amazon-bedrock-api-types';
36
- import { amazonBedrockFilePartProviderOptions } from './amazon-bedrock-chat-language-model-options';
36
+ import {
37
+ amazonBedrockFilePartProviderOptions,
38
+ amazonBedrockImagePartProviderOptions,
39
+ amazonBedrockTextPartProviderOptions,
40
+ } from './amazon-bedrock-chat-language-model-options';
37
41
  import { amazonBedrockReasoningMetadataSchema } from './amazon-bedrock-reasoning-metadata';
38
42
  import { normalizeToolCallId } from './normalize-tool-call-id';
39
43
 
@@ -110,6 +114,40 @@ async function shouldEnableCitations(
110
114
  return amazonBedrockOptions?.citations?.enabled ?? false;
111
115
  }
112
116
 
117
+ async function getTextPartGuardContentOptions(
118
+ providerMetadata: SharedV4ProviderMetadata | undefined,
119
+ ) {
120
+ return (
121
+ (await parseProviderOptions({
122
+ provider: 'amazonBedrock',
123
+ providerOptions: providerMetadata,
124
+ schema: amazonBedrockTextPartProviderOptions,
125
+ })) ??
126
+ (await parseProviderOptions({
127
+ provider: 'bedrock',
128
+ providerOptions: providerMetadata,
129
+ schema: amazonBedrockTextPartProviderOptions,
130
+ }))
131
+ );
132
+ }
133
+
134
+ async function getImagePartGuardContentOptions(
135
+ providerMetadata: SharedV4ProviderMetadata | undefined,
136
+ ) {
137
+ return (
138
+ (await parseProviderOptions({
139
+ provider: 'amazonBedrock',
140
+ providerOptions: providerMetadata,
141
+ schema: amazonBedrockImagePartProviderOptions,
142
+ })) ??
143
+ (await parseProviderOptions({
144
+ provider: 'bedrock',
145
+ providerOptions: providerMetadata,
146
+ schema: amazonBedrockImagePartProviderOptions,
147
+ }))
148
+ );
149
+ }
150
+
113
151
  export async function convertToAmazonBedrockChatMessages(
114
152
  prompt: LanguageModelV4Prompt,
115
153
  isMistral: boolean = false,
@@ -162,9 +200,24 @@ export async function convertToAmazonBedrockChatMessages(
162
200
 
163
201
  switch (part.type) {
164
202
  case 'text': {
165
- amazonBedrockContent.push({
166
- text: part.text,
167
- });
203
+ const textOptions = await getTextPartGuardContentOptions(
204
+ part.providerOptions,
205
+ );
206
+
207
+ if (textOptions?.guardContent) {
208
+ amazonBedrockContent.push({
209
+ guardContent: {
210
+ text: {
211
+ text: part.text,
212
+ qualifiers: textOptions.guardContentQualifiers,
213
+ },
214
+ },
215
+ });
216
+ } else {
217
+ amazonBedrockContent.push({
218
+ text: part.text,
219
+ });
220
+ }
168
221
  break;
169
222
  }
170
223
 
@@ -251,7 +304,11 @@ export async function convertToAmazonBedrockChatMessages(
251
304
 
252
305
  switch (getTopLevelMediaType(fullMediaType)) {
253
306
  case 'image': {
254
- amazonBedrockContent.push({
307
+ const imageOptions =
308
+ await getImagePartGuardContentOptions(
309
+ part.providerOptions,
310
+ );
311
+ const imageBlock: AmazonBedrockImageBlock = {
255
312
  image: {
256
313
  format:
257
314
  getAmazonBedrockImageFormat(fullMediaType),
@@ -260,7 +317,15 @@ export async function convertToAmazonBedrockChatMessages(
260
317
  functionality: 'File URL data',
261
318
  }),
262
319
  },
263
- });
320
+ };
321
+
322
+ if (imageOptions?.guardContent) {
323
+ amazonBedrockContent.push({
324
+ guardContent: imageBlock,
325
+ });
326
+ } else {
327
+ amazonBedrockContent.push(imageBlock);
328
+ }
264
329
  break;
265
330
  }
266
331
  case 'video': {