@ai-sdk/amazon-bedrock 5.0.0-beta.45 → 5.0.0-beta.47
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 +21 -0
- package/dist/anthropic/index.d.ts +10 -10
- package/dist/anthropic/index.js +65 -51
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.js +338 -298
- package/dist/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +66 -66
- package/package.json +3 -3
- package/src/{bedrock-api-types.ts → amazon-bedrock-api-types.ts} +60 -55
- package/src/{bedrock-chat-options.ts → amazon-bedrock-chat-language-model-options.ts} +7 -7
- package/src/{bedrock-chat-language-model.ts → amazon-bedrock-chat-language-model.ts} +211 -190
- package/src/{bedrock-embedding-options.ts → amazon-bedrock-embedding-model-options.ts} +1 -1
- package/src/{bedrock-embedding-model.ts → amazon-bedrock-embedding-model.ts} +31 -24
- package/src/{bedrock-error.ts → amazon-bedrock-error.ts} +1 -1
- package/src/{bedrock-event-stream-decoder.ts → amazon-bedrock-event-stream-decoder.ts} +1 -1
- package/src/{bedrock-event-stream-response-handler.ts → amazon-bedrock-event-stream-response-handler.ts} +3 -3
- package/src/{bedrock-image-model.ts → amazon-bedrock-image-model.ts} +40 -36
- package/src/amazon-bedrock-image-settings.ts +9 -0
- package/src/{bedrock-prepare-tools.ts → amazon-bedrock-prepare-tools.ts} +18 -17
- package/src/{bedrock-provider.ts → amazon-bedrock-provider.ts} +40 -38
- package/src/amazon-bedrock-reasoning-metadata.ts +10 -0
- package/src/{bedrock-sigv4-fetch.ts → amazon-bedrock-sigv4-fetch.ts} +13 -7
- package/src/anthropic/amazon-bedrock-anthropic-fetch.ts +104 -0
- package/src/anthropic/{bedrock-anthropic-options.ts → amazon-bedrock-anthropic-options.ts} +1 -1
- package/src/anthropic/{bedrock-anthropic-provider.ts → amazon-bedrock-anthropic-provider.ts} +18 -16
- package/src/anthropic/index.ts +19 -7
- package/src/{convert-bedrock-usage.ts → convert-amazon-bedrock-usage.ts} +3 -3
- package/src/{convert-to-bedrock-chat-messages.ts → convert-to-amazon-bedrock-chat-messages.ts} +92 -59
- package/src/index.ts +15 -8
- package/src/{map-bedrock-finish-reason.ts → map-amazon-bedrock-finish-reason.ts} +3 -3
- package/src/reranking/{bedrock-reranking-api.ts → amazon-bedrock-reranking-api.ts} +3 -3
- package/src/reranking/{bedrock-reranking-options.ts → amazon-bedrock-reranking-model-options.ts} +1 -1
- package/src/reranking/{bedrock-reranking-model.ts → amazon-bedrock-reranking-model.ts} +29 -21
- package/src/anthropic/bedrock-anthropic-fetch.ts +0 -94
- package/src/bedrock-image-settings.ts +0 -6
- package/src/bedrock-reasoning-metadata.ts +0 -10
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { JSONObject } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
|
-
export interface
|
|
4
|
-
system?:
|
|
5
|
-
messages:
|
|
6
|
-
toolConfig?:
|
|
3
|
+
export interface AmazonBedrockConverseInput {
|
|
4
|
+
system?: AmazonBedrockSystemMessages;
|
|
5
|
+
messages: AmazonBedrockMessages;
|
|
6
|
+
toolConfig?: AmazonBedrockToolConfiguration;
|
|
7
7
|
inferenceConfig?: {
|
|
8
8
|
maxOutputTokens?: number;
|
|
9
9
|
temperature?: number;
|
|
@@ -17,25 +17,26 @@ export interface BedrockConverseInput {
|
|
|
17
17
|
type: string;
|
|
18
18
|
};
|
|
19
19
|
guardrailConfig?:
|
|
20
|
-
|
|
|
21
|
-
|
|
|
20
|
+
| AmazonBedrockGuardrailConfiguration
|
|
21
|
+
| AmazonBedrockGuardrailStreamConfiguration
|
|
22
22
|
| undefined;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type
|
|
25
|
+
export type AmazonBedrockSystemMessages =
|
|
26
|
+
Array<AmazonBedrockSystemContentBlock>;
|
|
26
27
|
|
|
27
|
-
export type
|
|
28
|
-
|
|
28
|
+
export type AmazonBedrockMessages = Array<
|
|
29
|
+
AmazonBedrockAssistantMessage | AmazonBedrockUserMessage
|
|
29
30
|
>;
|
|
30
31
|
|
|
31
|
-
export interface
|
|
32
|
+
export interface AmazonBedrockAssistantMessage {
|
|
32
33
|
role: 'assistant';
|
|
33
|
-
content: Array<
|
|
34
|
+
content: Array<AmazonBedrockContentBlock>;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export interface
|
|
37
|
+
export interface AmazonBedrockUserMessage {
|
|
37
38
|
role: 'user';
|
|
38
|
-
content: Array<
|
|
39
|
+
content: Array<AmazonBedrockContentBlock>;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -45,27 +46,29 @@ export interface BedrockUserMessage {
|
|
|
45
46
|
* - '5m': 5-minute TTL (default, supported by all models)
|
|
46
47
|
* - '1h': 1-hour TTL (supported by Claude Opus 4.5, Claude Haiku 4.5, Claude Sonnet 4.5)
|
|
47
48
|
*/
|
|
48
|
-
export type
|
|
49
|
+
export type AmazonBedrockCacheTTL = '5m' | '1h';
|
|
49
50
|
|
|
50
|
-
export type
|
|
51
|
-
cachePoint: { type: 'default'; ttl?:
|
|
51
|
+
export type AmazonBedrockCachePoint = {
|
|
52
|
+
cachePoint: { type: 'default'; ttl?: AmazonBedrockCacheTTL };
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Creates a cache point with an optional TTL.
|
|
56
57
|
* @param ttl - Cache TTL ('5m' or '1h'). If not provided, uses the default 5-minute TTL.
|
|
57
58
|
*/
|
|
58
|
-
export function
|
|
59
|
-
ttl?:
|
|
60
|
-
):
|
|
59
|
+
export function createAmazonBedrockCachePoint(
|
|
60
|
+
ttl?: AmazonBedrockCacheTTL,
|
|
61
|
+
): AmazonBedrockCachePoint {
|
|
61
62
|
return {
|
|
62
63
|
cachePoint: { type: 'default', ttl },
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
export type
|
|
67
|
+
export type AmazonBedrockSystemContentBlock =
|
|
68
|
+
| { text: string }
|
|
69
|
+
| AmazonBedrockCachePoint;
|
|
67
70
|
|
|
68
|
-
export interface
|
|
71
|
+
export interface AmazonBedrockGuardrailConfiguration {
|
|
69
72
|
guardrails?: Array<{
|
|
70
73
|
name: string;
|
|
71
74
|
description?: string;
|
|
@@ -73,13 +76,14 @@ export interface BedrockGuardrailConfiguration {
|
|
|
73
76
|
}>;
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
export type
|
|
79
|
+
export type AmazonBedrockGuardrailStreamConfiguration =
|
|
80
|
+
AmazonBedrockGuardrailConfiguration;
|
|
77
81
|
|
|
78
|
-
export interface
|
|
82
|
+
export interface AmazonBedrockToolInputSchema {
|
|
79
83
|
json: Record<string, unknown>;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
export interface
|
|
86
|
+
export interface AmazonBedrockTool {
|
|
83
87
|
toolSpec: {
|
|
84
88
|
name: string;
|
|
85
89
|
description?: string;
|
|
@@ -88,8 +92,8 @@ export interface BedrockTool {
|
|
|
88
92
|
};
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
export interface
|
|
92
|
-
tools?: Array<
|
|
95
|
+
export interface AmazonBedrockToolConfiguration {
|
|
96
|
+
tools?: Array<AmazonBedrockTool | AmazonBedrockCachePoint>;
|
|
93
97
|
toolChoice?:
|
|
94
98
|
| { tool: { name: string } }
|
|
95
99
|
| { auto: {} }
|
|
@@ -110,7 +114,7 @@ export const BEDROCK_STOP_REASONS = [
|
|
|
110
114
|
'tool_use',
|
|
111
115
|
] as const;
|
|
112
116
|
|
|
113
|
-
export type
|
|
117
|
+
export type AmazonBedrockStopReason = (typeof BEDROCK_STOP_REASONS)[number];
|
|
114
118
|
|
|
115
119
|
/**
|
|
116
120
|
* @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ImageBlock.html
|
|
@@ -121,9 +125,10 @@ export const BEDROCK_IMAGE_MIME_TYPES = {
|
|
|
121
125
|
'image/gif': 'gif',
|
|
122
126
|
'image/webp': 'webp',
|
|
123
127
|
} as const;
|
|
124
|
-
type
|
|
125
|
-
export type
|
|
126
|
-
|
|
128
|
+
type AmazonBedrockImageFormats = typeof BEDROCK_IMAGE_MIME_TYPES;
|
|
129
|
+
export type AmazonBedrockImageFormat =
|
|
130
|
+
AmazonBedrockImageFormats[keyof AmazonBedrockImageFormats];
|
|
131
|
+
export type AmazonBedrockImageMimeType = keyof AmazonBedrockImageFormats;
|
|
127
132
|
|
|
128
133
|
/**
|
|
129
134
|
* @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_DocumentBlock.html
|
|
@@ -140,14 +145,14 @@ export const BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
|
140
145
|
'text/plain': 'txt',
|
|
141
146
|
'text/markdown': 'md',
|
|
142
147
|
} as const;
|
|
143
|
-
type
|
|
144
|
-
export type
|
|
145
|
-
|
|
146
|
-
export type
|
|
148
|
+
type AmazonBedrockDocumentFormats = typeof BEDROCK_DOCUMENT_MIME_TYPES;
|
|
149
|
+
export type AmazonBedrockDocumentFormat =
|
|
150
|
+
AmazonBedrockDocumentFormats[keyof AmazonBedrockDocumentFormats];
|
|
151
|
+
export type AmazonBedrockDocumentMimeType = keyof AmazonBedrockDocumentFormats;
|
|
147
152
|
|
|
148
|
-
export interface
|
|
153
|
+
export interface AmazonBedrockDocumentBlock {
|
|
149
154
|
document: {
|
|
150
|
-
format:
|
|
155
|
+
format: AmazonBedrockDocumentFormat;
|
|
151
156
|
name: string;
|
|
152
157
|
source: {
|
|
153
158
|
bytes: string;
|
|
@@ -158,27 +163,27 @@ export interface BedrockDocumentBlock {
|
|
|
158
163
|
};
|
|
159
164
|
}
|
|
160
165
|
|
|
161
|
-
export interface
|
|
166
|
+
export interface AmazonBedrockGuardrailConverseContentBlock {
|
|
162
167
|
guardContent: unknown;
|
|
163
168
|
}
|
|
164
169
|
|
|
165
|
-
export interface
|
|
170
|
+
export interface AmazonBedrockImageBlock {
|
|
166
171
|
image: {
|
|
167
|
-
format:
|
|
172
|
+
format: AmazonBedrockImageFormat;
|
|
168
173
|
source: {
|
|
169
174
|
bytes: string;
|
|
170
175
|
};
|
|
171
176
|
};
|
|
172
177
|
}
|
|
173
178
|
|
|
174
|
-
export interface
|
|
179
|
+
export interface AmazonBedrockToolResultBlock {
|
|
175
180
|
toolResult: {
|
|
176
181
|
toolUseId: string;
|
|
177
|
-
content: Array<
|
|
182
|
+
content: Array<AmazonBedrockTextBlock | AmazonBedrockImageBlock>;
|
|
178
183
|
};
|
|
179
184
|
}
|
|
180
185
|
|
|
181
|
-
export interface
|
|
186
|
+
export interface AmazonBedrockToolUseBlock {
|
|
182
187
|
toolUse: {
|
|
183
188
|
toolUseId: string;
|
|
184
189
|
name: string;
|
|
@@ -186,11 +191,11 @@ export interface BedrockToolUseBlock {
|
|
|
186
191
|
};
|
|
187
192
|
}
|
|
188
193
|
|
|
189
|
-
export interface
|
|
194
|
+
export interface AmazonBedrockTextBlock {
|
|
190
195
|
text: string;
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
export interface
|
|
198
|
+
export interface AmazonBedrockReasoningContentBlock {
|
|
194
199
|
reasoningContent: {
|
|
195
200
|
reasoningText: {
|
|
196
201
|
text: string;
|
|
@@ -199,7 +204,7 @@ export interface BedrockReasoningContentBlock {
|
|
|
199
204
|
};
|
|
200
205
|
}
|
|
201
206
|
|
|
202
|
-
export interface
|
|
207
|
+
export interface AmazonBedrockRedactedReasoningContentBlock {
|
|
203
208
|
reasoningContent: {
|
|
204
209
|
redactedReasoning: {
|
|
205
210
|
data: string;
|
|
@@ -207,13 +212,13 @@ export interface BedrockRedactedReasoningContentBlock {
|
|
|
207
212
|
};
|
|
208
213
|
}
|
|
209
214
|
|
|
210
|
-
export type
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
|
216
|
-
|
|
|
217
|
-
|
|
|
218
|
-
|
|
|
219
|
-
|
|
|
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
|
|
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
|
|
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
|
|
100
|
-
typeof
|
|
99
|
+
export type AmazonBedrockFilePartProviderOptions = z.infer<
|
|
100
|
+
typeof amazonBedrockFilePartProviderOptions
|
|
101
101
|
>;
|
|
102
102
|
|
|
103
|
-
export const
|
|
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
|
|
143
|
-
typeof
|
|
142
|
+
export type AmazonBedrockLanguageModelChatOptions = z.infer<
|
|
143
|
+
typeof amazonBedrockLanguageModelChatOptions
|
|
144
144
|
>;
|