@ai-sdk/amazon-bedrock 5.0.0-beta.44 → 5.0.0-beta.46

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 (38) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/anthropic/index.d.ts +10 -10
  3. package/dist/anthropic/index.js +58 -46
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/index.d.ts +25 -23
  6. package/dist/index.js +496 -436
  7. package/dist/index.js.map +1 -1
  8. package/docs/08-amazon-bedrock.mdx +80 -82
  9. package/package.json +5 -5
  10. package/src/amazon-bedrock-api-types.ts +224 -0
  11. package/src/{bedrock-chat-options.ts → amazon-bedrock-chat-language-model-options.ts} +7 -7
  12. package/src/{bedrock-chat-language-model.ts → amazon-bedrock-chat-language-model.ts} +217 -196
  13. package/src/{bedrock-embedding-options.ts → amazon-bedrock-embedding-model-options.ts} +1 -1
  14. package/src/{bedrock-embedding-model.ts → amazon-bedrock-embedding-model.ts} +34 -27
  15. package/src/{bedrock-error.ts → amazon-bedrock-error.ts} +1 -1
  16. package/src/{bedrock-event-stream-decoder.ts → amazon-bedrock-event-stream-decoder.ts} +1 -1
  17. package/src/{bedrock-event-stream-response-handler.ts → amazon-bedrock-event-stream-response-handler.ts} +6 -6
  18. package/src/{bedrock-image-model.ts → amazon-bedrock-image-model.ts} +43 -39
  19. package/src/amazon-bedrock-image-settings.ts +9 -0
  20. package/src/{bedrock-prepare-tools.ts → amazon-bedrock-prepare-tools.ts} +22 -18
  21. package/src/{bedrock-provider.ts → amazon-bedrock-provider.ts} +53 -46
  22. package/src/amazon-bedrock-reasoning-metadata.ts +10 -0
  23. package/src/{bedrock-sigv4-fetch.ts → amazon-bedrock-sigv4-fetch.ts} +5 -3
  24. package/src/anthropic/amazon-bedrock-anthropic-fetch.ts +104 -0
  25. package/src/anthropic/{bedrock-anthropic-options.ts → amazon-bedrock-anthropic-options.ts} +1 -1
  26. package/src/anthropic/{bedrock-anthropic-provider.ts → amazon-bedrock-anthropic-provider.ts} +22 -20
  27. package/src/anthropic/index.ts +19 -7
  28. package/src/{convert-bedrock-usage.ts → convert-amazon-bedrock-usage.ts} +4 -4
  29. package/src/{convert-to-bedrock-chat-messages.ts → convert-to-amazon-bedrock-chat-messages.ts} +146 -103
  30. package/src/index.ts +15 -8
  31. package/src/inject-fetch-headers.ts +1 -1
  32. package/src/{map-bedrock-finish-reason.ts → map-amazon-bedrock-finish-reason.ts} +4 -4
  33. package/src/reranking/{bedrock-reranking-api.ts → amazon-bedrock-reranking-api.ts} +3 -3
  34. package/src/reranking/{bedrock-reranking-options.ts → amazon-bedrock-reranking-model-options.ts} +1 -1
  35. package/src/reranking/{bedrock-reranking-model.ts → amazon-bedrock-reranking-model.ts} +32 -25
  36. package/src/anthropic/bedrock-anthropic-fetch.ts +0 -94
  37. package/src/bedrock-api-types.ts +0 -219
  38. package/src/bedrock-image-settings.ts +0 -6
@@ -0,0 +1,224 @@
1
+ import type { JSONObject } from '@ai-sdk/provider';
2
+
3
+ export interface AmazonBedrockConverseInput {
4
+ system?: AmazonBedrockSystemMessages;
5
+ messages: AmazonBedrockMessages;
6
+ toolConfig?: AmazonBedrockToolConfiguration;
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
+ serviceTier?: {
17
+ type: string;
18
+ };
19
+ guardrailConfig?:
20
+ | AmazonBedrockGuardrailConfiguration
21
+ | AmazonBedrockGuardrailStreamConfiguration
22
+ | undefined;
23
+ }
24
+
25
+ export type AmazonBedrockSystemMessages =
26
+ Array<AmazonBedrockSystemContentBlock>;
27
+
28
+ export type AmazonBedrockMessages = Array<
29
+ AmazonBedrockAssistantMessage | AmazonBedrockUserMessage
30
+ >;
31
+
32
+ export interface AmazonBedrockAssistantMessage {
33
+ role: 'assistant';
34
+ content: Array<AmazonBedrockContentBlock>;
35
+ }
36
+
37
+ export interface AmazonBedrockUserMessage {
38
+ role: 'user';
39
+ content: Array<AmazonBedrockContentBlock>;
40
+ }
41
+
42
+ /**
43
+ * Cache TTL options for Bedrock prompt caching.
44
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
45
+ *
46
+ * - '5m': 5-minute TTL (default, supported by all models)
47
+ * - '1h': 1-hour TTL (supported by Claude Opus 4.5, Claude Haiku 4.5, Claude Sonnet 4.5)
48
+ */
49
+ export type AmazonBedrockCacheTTL = '5m' | '1h';
50
+
51
+ export type AmazonBedrockCachePoint = {
52
+ cachePoint: { type: 'default'; ttl?: AmazonBedrockCacheTTL };
53
+ };
54
+
55
+ /**
56
+ * Creates a cache point with an optional TTL.
57
+ * @param ttl - Cache TTL ('5m' or '1h'). If not provided, uses the default 5-minute TTL.
58
+ */
59
+ export function createAmazonBedrockCachePoint(
60
+ ttl?: AmazonBedrockCacheTTL,
61
+ ): AmazonBedrockCachePoint {
62
+ return {
63
+ cachePoint: { type: 'default', ttl },
64
+ };
65
+ }
66
+
67
+ export type AmazonBedrockSystemContentBlock =
68
+ | { text: string }
69
+ | AmazonBedrockCachePoint;
70
+
71
+ export interface AmazonBedrockGuardrailConfiguration {
72
+ guardrails?: Array<{
73
+ name: string;
74
+ description?: string;
75
+ parameters?: Record<string, unknown>;
76
+ }>;
77
+ }
78
+
79
+ export type AmazonBedrockGuardrailStreamConfiguration =
80
+ AmazonBedrockGuardrailConfiguration;
81
+
82
+ export interface AmazonBedrockToolInputSchema {
83
+ json: Record<string, unknown>;
84
+ }
85
+
86
+ export interface AmazonBedrockTool {
87
+ toolSpec: {
88
+ name: string;
89
+ description?: string;
90
+ strict?: boolean;
91
+ inputSchema: { json: JSONObject };
92
+ };
93
+ }
94
+
95
+ export interface AmazonBedrockToolConfiguration {
96
+ tools?: Array<AmazonBedrockTool | AmazonBedrockCachePoint>;
97
+ toolChoice?:
98
+ | { tool: { name: string } }
99
+ | { auto: {} }
100
+ | { any: {} }
101
+ | undefined;
102
+ }
103
+
104
+ export const BEDROCK_STOP_REASONS = [
105
+ 'stop',
106
+ 'stop_sequence',
107
+ 'end_turn',
108
+ 'length',
109
+ 'max_tokens',
110
+ 'content-filter',
111
+ 'content_filtered',
112
+ 'guardrail_intervened',
113
+ 'tool-calls',
114
+ 'tool_use',
115
+ ] as const;
116
+
117
+ export type AmazonBedrockStopReason = (typeof BEDROCK_STOP_REASONS)[number];
118
+
119
+ /**
120
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ImageBlock.html
121
+ */
122
+ export const BEDROCK_IMAGE_MIME_TYPES = {
123
+ 'image/jpeg': 'jpeg',
124
+ 'image/png': 'png',
125
+ 'image/gif': 'gif',
126
+ 'image/webp': 'webp',
127
+ } as const;
128
+ type AmazonBedrockImageFormats = typeof BEDROCK_IMAGE_MIME_TYPES;
129
+ export type AmazonBedrockImageFormat =
130
+ AmazonBedrockImageFormats[keyof AmazonBedrockImageFormats];
131
+ export type AmazonBedrockImageMimeType = keyof AmazonBedrockImageFormats;
132
+
133
+ /**
134
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_DocumentBlock.html
135
+ */
136
+ export const BEDROCK_DOCUMENT_MIME_TYPES = {
137
+ 'application/pdf': 'pdf',
138
+ 'text/csv': 'csv',
139
+ 'application/msword': 'doc',
140
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
141
+ 'docx',
142
+ 'application/vnd.ms-excel': 'xls',
143
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
144
+ 'text/html': 'html',
145
+ 'text/plain': 'txt',
146
+ 'text/markdown': 'md',
147
+ } as const;
148
+ type AmazonBedrockDocumentFormats = typeof BEDROCK_DOCUMENT_MIME_TYPES;
149
+ export type AmazonBedrockDocumentFormat =
150
+ AmazonBedrockDocumentFormats[keyof AmazonBedrockDocumentFormats];
151
+ export type AmazonBedrockDocumentMimeType = keyof AmazonBedrockDocumentFormats;
152
+
153
+ export interface AmazonBedrockDocumentBlock {
154
+ document: {
155
+ format: AmazonBedrockDocumentFormat;
156
+ name: string;
157
+ source: {
158
+ bytes: string;
159
+ };
160
+ citations?: {
161
+ enabled: boolean;
162
+ };
163
+ };
164
+ }
165
+
166
+ export interface AmazonBedrockGuardrailConverseContentBlock {
167
+ guardContent: unknown;
168
+ }
169
+
170
+ export interface AmazonBedrockImageBlock {
171
+ image: {
172
+ format: AmazonBedrockImageFormat;
173
+ source: {
174
+ bytes: string;
175
+ };
176
+ };
177
+ }
178
+
179
+ export interface AmazonBedrockToolResultBlock {
180
+ toolResult: {
181
+ toolUseId: string;
182
+ content: Array<AmazonBedrockTextBlock | AmazonBedrockImageBlock>;
183
+ };
184
+ }
185
+
186
+ export interface AmazonBedrockToolUseBlock {
187
+ toolUse: {
188
+ toolUseId: string;
189
+ name: string;
190
+ input: Record<string, unknown>;
191
+ };
192
+ }
193
+
194
+ export interface AmazonBedrockTextBlock {
195
+ text: string;
196
+ }
197
+
198
+ export interface AmazonBedrockReasoningContentBlock {
199
+ reasoningContent: {
200
+ reasoningText: {
201
+ text: string;
202
+ signature?: string;
203
+ };
204
+ };
205
+ }
206
+
207
+ export interface AmazonBedrockRedactedReasoningContentBlock {
208
+ reasoningContent: {
209
+ redactedReasoning: {
210
+ data: string;
211
+ };
212
+ };
213
+ }
214
+
215
+ export type AmazonBedrockContentBlock =
216
+ | AmazonBedrockDocumentBlock
217
+ | AmazonBedrockGuardrailConverseContentBlock
218
+ | AmazonBedrockImageBlock
219
+ | AmazonBedrockTextBlock
220
+ | AmazonBedrockToolResultBlock
221
+ | AmazonBedrockToolUseBlock
222
+ | AmazonBedrockReasoningContentBlock
223
+ | AmazonBedrockRedactedReasoningContentBlock
224
+ | AmazonBedrockCachePoint;
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod/v4';
2
2
 
3
3
  // https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html
4
- export type BedrockChatModelId =
4
+ export type AmazonBedrockChatModelId =
5
5
  | 'amazon.titan-tg1-large'
6
6
  | 'amazon.titan-text-express-v1'
7
7
  | 'anthropic.claude-v2'
@@ -81,7 +81,7 @@ export type BedrockChatModelId =
81
81
  * Bedrock file part provider options for document-specific features.
82
82
  * These options apply to individual file parts (documents).
83
83
  */
84
- export const bedrockFilePartProviderOptions = z.object({
84
+ export const amazonBedrockFilePartProviderOptions = z.object({
85
85
  /**
86
86
  * Citation configuration for this document.
87
87
  * When enabled, this document will generate citations in the response.
@@ -96,11 +96,11 @@ export const bedrockFilePartProviderOptions = z.object({
96
96
  .optional(),
97
97
  });
98
98
 
99
- export type BedrockFilePartProviderOptions = z.infer<
100
- typeof bedrockFilePartProviderOptions
99
+ export type AmazonBedrockFilePartProviderOptions = z.infer<
100
+ typeof amazonBedrockFilePartProviderOptions
101
101
  >;
102
102
 
103
- export const amazonBedrockLanguageModelOptions = z.object({
103
+ export const amazonBedrockLanguageModelChatOptions = z.object({
104
104
  /**
105
105
  * Additional inference parameters that the model supports,
106
106
  * beyond the base set of inference parameters that Converse
@@ -139,6 +139,6 @@ export const amazonBedrockLanguageModelOptions = z.object({
139
139
  serviceTier: z.enum(['reserved', 'priority', 'default', 'flex']).optional(),
140
140
  });
141
141
 
142
- export type AmazonBedrockLanguageModelOptions = z.infer<
143
- typeof amazonBedrockLanguageModelOptions
142
+ export type AmazonBedrockLanguageModelChatOptions = z.infer<
143
+ typeof amazonBedrockLanguageModelChatOptions
144
144
  >;