@ai-sdk/amazon-bedrock 4.0.24 → 4.0.26

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/anthropic/index.js +1 -1
  3. package/dist/anthropic/index.mjs +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/docs/08-amazon-bedrock.mdx +1453 -0
  7. package/package.json +11 -6
  8. package/src/__fixtures__/bedrock-json-only-text-first.1.chunks.txt +7 -0
  9. package/src/__fixtures__/bedrock-json-other-tool.1.chunks.txt +6 -0
  10. package/src/__fixtures__/bedrock-json-other-tool.1.json +24 -0
  11. package/src/__fixtures__/bedrock-json-tool-text-then-weather-then-json.1.chunks.txt +12 -0
  12. package/src/__fixtures__/bedrock-json-tool-with-answer.1.json +29 -0
  13. package/src/__fixtures__/bedrock-json-tool.1.chunks.txt +4 -0
  14. package/src/__fixtures__/bedrock-json-tool.1.json +35 -0
  15. package/src/__fixtures__/bedrock-json-tool.2.chunks.txt +6 -0
  16. package/src/__fixtures__/bedrock-json-tool.2.json +28 -0
  17. package/src/__fixtures__/bedrock-json-tool.3.chunks.txt +7 -0
  18. package/src/__fixtures__/bedrock-json-tool.3.json +36 -0
  19. package/src/__fixtures__/bedrock-json-with-tool.1.chunks.txt +9 -0
  20. package/src/__fixtures__/bedrock-json-with-tool.1.json +41 -0
  21. package/src/__fixtures__/bedrock-json-with-tools.1.chunks.txt +12 -0
  22. package/src/__fixtures__/bedrock-json-with-tools.1.json +50 -0
  23. package/src/__fixtures__/bedrock-tool-call.1.chunks.txt +6 -0
  24. package/src/__fixtures__/bedrock-tool-call.1.json +24 -0
  25. package/src/__fixtures__/bedrock-tool-no-args.chunks.txt +8 -0
  26. package/src/__fixtures__/bedrock-tool-no-args.json +25 -0
  27. package/src/anthropic/bedrock-anthropic-fetch.test.ts +344 -0
  28. package/src/anthropic/bedrock-anthropic-fetch.ts +62 -0
  29. package/src/anthropic/bedrock-anthropic-options.ts +28 -0
  30. package/src/anthropic/bedrock-anthropic-provider.test.ts +456 -0
  31. package/src/anthropic/bedrock-anthropic-provider.ts +357 -0
  32. package/src/anthropic/index.ts +9 -0
  33. package/src/bedrock-api-types.ts +195 -0
  34. package/src/bedrock-chat-language-model.test.ts +4569 -0
  35. package/src/bedrock-chat-language-model.ts +1019 -0
  36. package/src/bedrock-chat-options.ts +114 -0
  37. package/src/bedrock-embedding-model.test.ts +148 -0
  38. package/src/bedrock-embedding-model.ts +104 -0
  39. package/src/bedrock-embedding-options.ts +24 -0
  40. package/src/bedrock-error.ts +6 -0
  41. package/src/bedrock-event-stream-decoder.ts +59 -0
  42. package/src/bedrock-event-stream-response-handler.test.ts +233 -0
  43. package/src/bedrock-event-stream-response-handler.ts +57 -0
  44. package/src/bedrock-image-model.test.ts +866 -0
  45. package/src/bedrock-image-model.ts +297 -0
  46. package/src/bedrock-image-settings.ts +6 -0
  47. package/src/bedrock-prepare-tools.ts +190 -0
  48. package/src/bedrock-provider.test.ts +457 -0
  49. package/src/bedrock-provider.ts +351 -0
  50. package/src/bedrock-sigv4-fetch.test.ts +675 -0
  51. package/src/bedrock-sigv4-fetch.ts +138 -0
  52. package/src/convert-bedrock-usage.test.ts +207 -0
  53. package/src/convert-bedrock-usage.ts +50 -0
  54. package/src/convert-to-bedrock-chat-messages.test.ts +1175 -0
  55. package/src/convert-to-bedrock-chat-messages.ts +452 -0
  56. package/src/index.ts +10 -0
  57. package/src/inject-fetch-headers.test.ts +135 -0
  58. package/src/inject-fetch-headers.ts +32 -0
  59. package/src/map-bedrock-finish-reason.ts +22 -0
  60. package/src/normalize-tool-call-id.test.ts +72 -0
  61. package/src/normalize-tool-call-id.ts +36 -0
  62. package/src/reranking/__fixtures__/bedrock-reranking.1.json +12 -0
  63. package/src/reranking/bedrock-reranking-api.ts +44 -0
  64. package/src/reranking/bedrock-reranking-model.test.ts +299 -0
  65. package/src/reranking/bedrock-reranking-model.ts +115 -0
  66. package/src/reranking/bedrock-reranking-options.ts +36 -0
  67. package/src/version.ts +6 -0
@@ -0,0 +1,357 @@
1
+ import {
2
+ LanguageModelV3,
3
+ NoSuchModelError,
4
+ ProviderV3,
5
+ } from '@ai-sdk/provider';
6
+ import {
7
+ FetchFunction,
8
+ loadOptionalSetting,
9
+ loadSetting,
10
+ Resolvable,
11
+ resolve,
12
+ withoutTrailingSlash,
13
+ withUserAgentSuffix,
14
+ } from '@ai-sdk/provider-utils';
15
+ import {
16
+ anthropicTools,
17
+ AnthropicMessagesLanguageModel,
18
+ } from '@ai-sdk/anthropic/internal';
19
+ import {
20
+ BedrockCredentials,
21
+ createApiKeyFetchFunction,
22
+ createSigV4FetchFunction,
23
+ } from '../bedrock-sigv4-fetch';
24
+ import { createBedrockAnthropicFetch } from './bedrock-anthropic-fetch';
25
+ import { BedrockAnthropicModelId } from './bedrock-anthropic-options';
26
+ import { VERSION } from '../version';
27
+
28
+ // Bedrock requires newer tool versions than the default Anthropic SDK versions
29
+ const BEDROCK_TOOL_VERSION_MAP = {
30
+ bash_20241022: 'bash_20250124',
31
+ text_editor_20241022: 'text_editor_20250728',
32
+ computer_20241022: 'computer_20250124',
33
+ } as const;
34
+
35
+ // Tool name mappings when upgrading versions (text_editor_20250728 requires different name)
36
+ const BEDROCK_TOOL_NAME_MAP: Record<string, string> = {
37
+ text_editor_20250728: 'str_replace_based_edit_tool',
38
+ };
39
+
40
+ // Map tool types to required anthropic_beta values for Bedrock
41
+ const BEDROCK_TOOL_BETA_MAP: Record<string, string> = {
42
+ bash_20250124: 'computer-use-2025-01-24',
43
+ bash_20241022: 'computer-use-2024-10-22',
44
+ text_editor_20250124: 'computer-use-2025-01-24',
45
+ text_editor_20241022: 'computer-use-2024-10-22',
46
+ text_editor_20250429: 'computer-use-2025-01-24',
47
+ text_editor_20250728: 'computer-use-2025-01-24',
48
+ computer_20250124: 'computer-use-2025-01-24',
49
+ computer_20241022: 'computer-use-2024-10-22',
50
+ };
51
+
52
+ export interface BedrockAnthropicProvider extends ProviderV3 {
53
+ /**
54
+ Creates a model for text generation.
55
+ */
56
+ (modelId: BedrockAnthropicModelId): LanguageModelV3;
57
+
58
+ /**
59
+ Creates a model for text generation.
60
+ */
61
+ languageModel(modelId: BedrockAnthropicModelId): LanguageModelV3;
62
+
63
+ /**
64
+ Anthropic-specific computer use tool.
65
+ */
66
+ tools: typeof anthropicTools;
67
+
68
+ /**
69
+ * @deprecated Use `embeddingModel` instead.
70
+ */
71
+ textEmbeddingModel(modelId: string): never;
72
+ }
73
+
74
+ export interface BedrockAnthropicProviderSettings {
75
+ /**
76
+ The AWS region to use for the Bedrock provider. Defaults to the value of the
77
+ `AWS_REGION` environment variable.
78
+ */
79
+ region?: string;
80
+
81
+ /**
82
+ API key for authenticating requests using Bearer token authentication.
83
+ When provided, this will be used instead of AWS SigV4 authentication.
84
+ Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
85
+ */
86
+ apiKey?: string;
87
+
88
+ /**
89
+ The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
90
+ `AWS_ACCESS_KEY_ID` environment variable.
91
+ */
92
+ accessKeyId?: string;
93
+
94
+ /**
95
+ The AWS secret access key to use for the Bedrock provider. Defaults to the value of the
96
+ `AWS_SECRET_ACCESS_KEY` environment variable.
97
+ */
98
+ secretAccessKey?: string;
99
+
100
+ /**
101
+ The AWS session token to use for the Bedrock provider. Defaults to the value of the
102
+ `AWS_SESSION_TOKEN` environment variable.
103
+ */
104
+ sessionToken?: string;
105
+
106
+ /**
107
+ Base URL for the Bedrock API calls.
108
+ */
109
+ baseURL?: string;
110
+
111
+ /**
112
+ Custom headers to include in the requests.
113
+ */
114
+ headers?: Resolvable<Record<string, string | undefined>>;
115
+
116
+ /**
117
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
118
+ or to provide a custom fetch implementation for e.g. testing.
119
+ */
120
+ fetch?: FetchFunction;
121
+
122
+ /**
123
+ The AWS credential provider to use for the Bedrock provider to get dynamic
124
+ credentials similar to the AWS SDK. Setting a provider here will cause its
125
+ credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
126
+ and `sessionToken` settings.
127
+ */
128
+ credentialProvider?: () => PromiseLike<Omit<BedrockCredentials, 'region'>>;
129
+ }
130
+
131
+ /**
132
+ Create an Amazon Bedrock Anthropic provider instance.
133
+ This provider uses the native Anthropic API through Bedrock's InvokeModel endpoint,
134
+ bypassing the Converse API for better feature compatibility.
135
+ */
136
+ export function createBedrockAnthropic(
137
+ options: BedrockAnthropicProviderSettings = {},
138
+ ): BedrockAnthropicProvider {
139
+ // Check for API key authentication first
140
+ const rawApiKey = loadOptionalSetting({
141
+ settingValue: options.apiKey,
142
+ environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',
143
+ });
144
+
145
+ // Only use API key if it's a non-empty, non-whitespace string
146
+ const apiKey =
147
+ rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;
148
+
149
+ // Use API key authentication if available, otherwise fall back to SigV4
150
+ const baseFetchFunction = apiKey
151
+ ? createApiKeyFetchFunction(apiKey, options.fetch)
152
+ : createSigV4FetchFunction(async () => {
153
+ const region = loadSetting({
154
+ settingValue: options.region,
155
+ settingName: 'region',
156
+ environmentVariableName: 'AWS_REGION',
157
+ description: 'AWS region',
158
+ });
159
+
160
+ // If a credential provider is provided, use it to get the credentials.
161
+ if (options.credentialProvider) {
162
+ try {
163
+ return {
164
+ ...(await options.credentialProvider()),
165
+ region,
166
+ };
167
+ } catch (error) {
168
+ const errorMessage =
169
+ error instanceof Error ? error.message : String(error);
170
+ throw new Error(
171
+ `AWS credential provider failed: ${errorMessage}. ` +
172
+ 'Please ensure your credential provider returns valid AWS credentials ' +
173
+ 'with accessKeyId and secretAccessKey properties.',
174
+ );
175
+ }
176
+ }
177
+
178
+ try {
179
+ return {
180
+ region,
181
+ accessKeyId: loadSetting({
182
+ settingValue: options.accessKeyId,
183
+ settingName: 'accessKeyId',
184
+ environmentVariableName: 'AWS_ACCESS_KEY_ID',
185
+ description: 'AWS access key ID',
186
+ }),
187
+ secretAccessKey: loadSetting({
188
+ settingValue: options.secretAccessKey,
189
+ settingName: 'secretAccessKey',
190
+ environmentVariableName: 'AWS_SECRET_ACCESS_KEY',
191
+ description: 'AWS secret access key',
192
+ }),
193
+ sessionToken: loadOptionalSetting({
194
+ settingValue: options.sessionToken,
195
+ environmentVariableName: 'AWS_SESSION_TOKEN',
196
+ }),
197
+ };
198
+ } catch (error) {
199
+ const errorMessage =
200
+ error instanceof Error ? error.message : String(error);
201
+ if (
202
+ errorMessage.includes('AWS_ACCESS_KEY_ID') ||
203
+ errorMessage.includes('accessKeyId')
204
+ ) {
205
+ throw new Error(
206
+ 'AWS SigV4 authentication requires AWS credentials. Please provide either:\n' +
207
+ '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\n' +
208
+ '2. Provide accessKeyId and secretAccessKey in options\n' +
209
+ '3. Use a credentialProvider function\n' +
210
+ '4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option\n' +
211
+ `Original error: ${errorMessage}`,
212
+ );
213
+ }
214
+ if (
215
+ errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||
216
+ errorMessage.includes('secretAccessKey')
217
+ ) {
218
+ throw new Error(
219
+ 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +
220
+ 'Please ensure both credentials are provided.\n' +
221
+ `Original error: ${errorMessage}`,
222
+ );
223
+ }
224
+ throw error;
225
+ }
226
+ }, options.fetch);
227
+
228
+ // Wrap with Bedrock event stream to SSE transformer for streaming support
229
+ const fetchFunction = createBedrockAnthropicFetch(baseFetchFunction);
230
+
231
+ const getBaseURL = (): string =>
232
+ withoutTrailingSlash(
233
+ options.baseURL ??
234
+ `https://bedrock-runtime.${loadSetting({
235
+ settingValue: options.region,
236
+ settingName: 'region',
237
+ environmentVariableName: 'AWS_REGION',
238
+ description: 'AWS region',
239
+ })}.amazonaws.com`,
240
+ ) ?? 'https://bedrock-runtime.us-east-1.amazonaws.com';
241
+
242
+ const getHeaders = async () => {
243
+ const baseHeaders = (await resolve(options.headers)) ?? {};
244
+ return withUserAgentSuffix(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
245
+ };
246
+
247
+ const createChatModel = (modelId: BedrockAnthropicModelId) =>
248
+ new AnthropicMessagesLanguageModel(modelId, {
249
+ provider: 'bedrock.anthropic.messages',
250
+ baseURL: getBaseURL(),
251
+ headers: getHeaders,
252
+ fetch: fetchFunction,
253
+
254
+ buildRequestUrl: (baseURL, isStreaming) =>
255
+ `${baseURL}/model/${encodeURIComponent(modelId)}/${
256
+ isStreaming ? 'invoke-with-response-stream' : 'invoke'
257
+ }`,
258
+
259
+ transformRequestBody: args => {
260
+ const { model, stream, tool_choice, tools, ...rest } = args;
261
+
262
+ const transformedToolChoice =
263
+ tool_choice != null
264
+ ? {
265
+ type: tool_choice.type,
266
+ ...(tool_choice.name != null ? { name: tool_choice.name } : {}),
267
+ }
268
+ : undefined;
269
+
270
+ const requiredBetas = new Set<string>();
271
+ const transformedTools = tools?.map((tool: Record<string, unknown>) => {
272
+ const toolType = tool.type as string | undefined;
273
+
274
+ if (toolType && toolType in BEDROCK_TOOL_VERSION_MAP) {
275
+ const newType =
276
+ BEDROCK_TOOL_VERSION_MAP[
277
+ toolType as keyof typeof BEDROCK_TOOL_VERSION_MAP
278
+ ];
279
+ if (newType in BEDROCK_TOOL_BETA_MAP) {
280
+ requiredBetas.add(BEDROCK_TOOL_BETA_MAP[newType]);
281
+ }
282
+ const newName =
283
+ newType in BEDROCK_TOOL_NAME_MAP
284
+ ? BEDROCK_TOOL_NAME_MAP[newType]
285
+ : tool.name;
286
+ return {
287
+ ...tool,
288
+ type: newType,
289
+ name: newName,
290
+ };
291
+ }
292
+
293
+ if (toolType && toolType in BEDROCK_TOOL_BETA_MAP) {
294
+ requiredBetas.add(BEDROCK_TOOL_BETA_MAP[toolType]);
295
+ }
296
+
297
+ if (toolType && toolType in BEDROCK_TOOL_NAME_MAP) {
298
+ return {
299
+ ...tool,
300
+ name: BEDROCK_TOOL_NAME_MAP[toolType],
301
+ };
302
+ }
303
+
304
+ return tool;
305
+ });
306
+
307
+ return {
308
+ ...rest,
309
+ ...(transformedTools != null ? { tools: transformedTools } : {}),
310
+ ...(transformedToolChoice != null
311
+ ? { tool_choice: transformedToolChoice }
312
+ : {}),
313
+ ...(requiredBetas.size > 0
314
+ ? { anthropic_beta: Array.from(requiredBetas) }
315
+ : {}),
316
+ anthropic_version: 'bedrock-2023-05-31',
317
+ };
318
+ },
319
+
320
+ // Bedrock Anthropic doesn't support URL sources, force download and base64 conversion
321
+ supportedUrls: () => ({}),
322
+ // force the use of JSON tool fallback for structured outputs since beta header isn't supported
323
+ supportsNativeStructuredOutput: false,
324
+ });
325
+
326
+ const provider = function (modelId: BedrockAnthropicModelId) {
327
+ if (new.target) {
328
+ throw new Error(
329
+ 'The Bedrock Anthropic model function cannot be called with the new keyword.',
330
+ );
331
+ }
332
+
333
+ return createChatModel(modelId);
334
+ };
335
+
336
+ provider.specificationVersion = 'v3' as const;
337
+ provider.languageModel = createChatModel;
338
+ provider.chat = createChatModel;
339
+ provider.messages = createChatModel;
340
+
341
+ provider.embeddingModel = (modelId: string) => {
342
+ throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
343
+ };
344
+ provider.textEmbeddingModel = provider.embeddingModel;
345
+ provider.imageModel = (modelId: string) => {
346
+ throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
347
+ };
348
+
349
+ provider.tools = anthropicTools;
350
+
351
+ return provider;
352
+ }
353
+
354
+ /**
355
+ Default Bedrock Anthropic provider instance.
356
+ */
357
+ export const bedrockAnthropic = createBedrockAnthropic();
@@ -0,0 +1,9 @@
1
+ export {
2
+ bedrockAnthropic,
3
+ createBedrockAnthropic,
4
+ } from './bedrock-anthropic-provider';
5
+ export type {
6
+ BedrockAnthropicProvider,
7
+ BedrockAnthropicProviderSettings,
8
+ } from './bedrock-anthropic-provider';
9
+ export type { BedrockAnthropicModelId } from './bedrock-anthropic-options';
@@ -0,0 +1,195 @@
1
+ import { JSONObject } from '@ai-sdk/provider';
2
+
3
+ export interface BedrockConverseInput {
4
+ system?: BedrockSystemMessages;
5
+ messages: BedrockMessages;
6
+ toolConfig?: BedrockToolConfiguration;
7
+ inferenceConfig?: {
8
+ maxOutputTokens?: number;
9
+ temperature?: number;
10
+ topP?: number;
11
+ topK?: number;
12
+ stopSequences?: string[];
13
+ };
14
+ additionalModelRequestFields?: Record<string, unknown>;
15
+ additionalModelResponseFieldPaths?: string[];
16
+ guardrailConfig?:
17
+ | BedrockGuardrailConfiguration
18
+ | BedrockGuardrailStreamConfiguration
19
+ | undefined;
20
+ }
21
+
22
+ export type BedrockSystemMessages = Array<BedrockSystemContentBlock>;
23
+
24
+ export type BedrockMessages = Array<
25
+ BedrockAssistantMessage | BedrockUserMessage
26
+ >;
27
+
28
+ export interface BedrockAssistantMessage {
29
+ role: 'assistant';
30
+ content: Array<BedrockContentBlock>;
31
+ }
32
+
33
+ export interface BedrockUserMessage {
34
+ role: 'user';
35
+ content: Array<BedrockContentBlock>;
36
+ }
37
+
38
+ export const BEDROCK_CACHE_POINT = {
39
+ cachePoint: { type: 'default' },
40
+ } as const;
41
+
42
+ export type BedrockCachePoint = { cachePoint: { type: 'default' } };
43
+ export type BedrockSystemContentBlock = { text: string } | BedrockCachePoint;
44
+
45
+ export interface BedrockGuardrailConfiguration {
46
+ guardrails?: Array<{
47
+ name: string;
48
+ description?: string;
49
+ parameters?: Record<string, unknown>;
50
+ }>;
51
+ }
52
+
53
+ export type BedrockGuardrailStreamConfiguration = BedrockGuardrailConfiguration;
54
+
55
+ export interface BedrockToolInputSchema {
56
+ json: Record<string, unknown>;
57
+ }
58
+
59
+ export interface BedrockTool {
60
+ toolSpec: {
61
+ name: string;
62
+ description?: string;
63
+ inputSchema: { json: JSONObject };
64
+ };
65
+ }
66
+
67
+ export interface BedrockToolConfiguration {
68
+ tools?: Array<BedrockTool | BedrockCachePoint>;
69
+ toolChoice?:
70
+ | { tool: { name: string } }
71
+ | { auto: {} }
72
+ | { any: {} }
73
+ | undefined;
74
+ }
75
+
76
+ export const BEDROCK_STOP_REASONS = [
77
+ 'stop',
78
+ 'stop_sequence',
79
+ 'end_turn',
80
+ 'length',
81
+ 'max_tokens',
82
+ 'content-filter',
83
+ 'content_filtered',
84
+ 'guardrail_intervened',
85
+ 'tool-calls',
86
+ 'tool_use',
87
+ ] as const;
88
+
89
+ export type BedrockStopReason = (typeof BEDROCK_STOP_REASONS)[number];
90
+
91
+ /**
92
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ImageBlock.html
93
+ */
94
+ export const BEDROCK_IMAGE_MIME_TYPES = {
95
+ 'image/jpeg': 'jpeg',
96
+ 'image/png': 'png',
97
+ 'image/gif': 'gif',
98
+ 'image/webp': 'webp',
99
+ } as const;
100
+ type BedrockImageFormats = typeof BEDROCK_IMAGE_MIME_TYPES;
101
+ export type BedrockImageFormat = BedrockImageFormats[keyof BedrockImageFormats];
102
+ export type BedrockImageMimeType = keyof BedrockImageFormats;
103
+
104
+ /**
105
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_DocumentBlock.html
106
+ */
107
+ export const BEDROCK_DOCUMENT_MIME_TYPES = {
108
+ 'application/pdf': 'pdf',
109
+ 'text/csv': 'csv',
110
+ 'application/msword': 'doc',
111
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
112
+ 'docx',
113
+ 'application/vnd.ms-excel': 'xls',
114
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
115
+ 'text/html': 'html',
116
+ 'text/plain': 'txt',
117
+ 'text/markdown': 'md',
118
+ } as const;
119
+ type BedrockDocumentFormats = typeof BEDROCK_DOCUMENT_MIME_TYPES;
120
+ export type BedrockDocumentFormat =
121
+ BedrockDocumentFormats[keyof BedrockDocumentFormats];
122
+ export type BedrockDocumentMimeType = keyof BedrockDocumentFormats;
123
+
124
+ export interface BedrockDocumentBlock {
125
+ document: {
126
+ format: BedrockDocumentFormat;
127
+ name: string;
128
+ source: {
129
+ bytes: string;
130
+ };
131
+ citations?: {
132
+ enabled: boolean;
133
+ };
134
+ };
135
+ }
136
+
137
+ export interface BedrockGuardrailConverseContentBlock {
138
+ guardContent: unknown;
139
+ }
140
+
141
+ export interface BedrockImageBlock {
142
+ image: {
143
+ format: BedrockImageFormat;
144
+ source: {
145
+ bytes: string;
146
+ };
147
+ };
148
+ }
149
+
150
+ export interface BedrockToolResultBlock {
151
+ toolResult: {
152
+ toolUseId: string;
153
+ content: Array<BedrockTextBlock | BedrockImageBlock>;
154
+ };
155
+ }
156
+
157
+ export interface BedrockToolUseBlock {
158
+ toolUse: {
159
+ toolUseId: string;
160
+ name: string;
161
+ input: Record<string, unknown>;
162
+ };
163
+ }
164
+
165
+ export interface BedrockTextBlock {
166
+ text: string;
167
+ }
168
+
169
+ export interface BedrockReasoningContentBlock {
170
+ reasoningContent: {
171
+ reasoningText: {
172
+ text: string;
173
+ signature?: string;
174
+ };
175
+ };
176
+ }
177
+
178
+ export interface BedrockRedactedReasoningContentBlock {
179
+ reasoningContent: {
180
+ redactedReasoning: {
181
+ data: string;
182
+ };
183
+ };
184
+ }
185
+
186
+ export type BedrockContentBlock =
187
+ | BedrockDocumentBlock
188
+ | BedrockGuardrailConverseContentBlock
189
+ | BedrockImageBlock
190
+ | BedrockTextBlock
191
+ | BedrockToolResultBlock
192
+ | BedrockToolUseBlock
193
+ | BedrockReasoningContentBlock
194
+ | BedrockRedactedReasoningContentBlock
195
+ | BedrockCachePoint;