@ai-sdk/amazon-bedrock 5.0.0-beta.4 → 5.0.0-beta.40
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 +312 -4
- package/README.md +2 -0
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +88 -69
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +469 -300
- package/dist/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +49 -6
- package/package.json +10 -12
- package/src/anthropic/bedrock-anthropic-fetch.ts +26 -0
- package/src/anthropic/bedrock-anthropic-options.ts +2 -0
- package/src/anthropic/bedrock-anthropic-provider.ts +11 -1
- package/src/bedrock-api-types.ts +3 -0
- package/src/bedrock-chat-language-model.ts +120 -6
- package/src/bedrock-chat-options.ts +12 -0
- package/src/bedrock-embedding-model.ts +22 -2
- package/src/bedrock-image-model.ts +22 -2
- package/src/convert-to-bedrock-chat-messages.ts +46 -34
- package/dist/anthropic/index.d.mts +0 -91
- package/dist/anthropic/index.mjs +0 -397
- package/dist/anthropic/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -194
- package/dist/index.mjs +0 -2329
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,313 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.40
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [eea8d98]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.0-beta.25
|
|
9
|
+
- @ai-sdk/anthropic@4.0.0-beta.36
|
|
10
|
+
|
|
11
|
+
## 5.0.0-beta.39
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [f807e45]
|
|
16
|
+
- @ai-sdk/provider-utils@5.0.0-beta.24
|
|
17
|
+
- @ai-sdk/anthropic@4.0.0-beta.35
|
|
18
|
+
|
|
19
|
+
## 5.0.0-beta.38
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [350ea38]
|
|
24
|
+
- @ai-sdk/provider-utils@5.0.0-beta.23
|
|
25
|
+
- @ai-sdk/anthropic@4.0.0-beta.34
|
|
26
|
+
|
|
27
|
+
## 5.0.0-beta.37
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [832f86f]
|
|
32
|
+
- @ai-sdk/anthropic@4.0.0-beta.33
|
|
33
|
+
|
|
34
|
+
## 5.0.0-beta.36
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [ad0b376]
|
|
39
|
+
- @ai-sdk/anthropic@4.0.0-beta.32
|
|
40
|
+
|
|
41
|
+
## 5.0.0-beta.35
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies [083947b]
|
|
46
|
+
- @ai-sdk/provider-utils@5.0.0-beta.22
|
|
47
|
+
- @ai-sdk/anthropic@4.0.0-beta.31
|
|
48
|
+
|
|
49
|
+
## 5.0.0-beta.34
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- 0d8f107: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
|
|
54
|
+
- Updated dependencies [0d8f107]
|
|
55
|
+
- @ai-sdk/anthropic@4.0.0-beta.30
|
|
56
|
+
|
|
57
|
+
## 5.0.0-beta.33
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [add1126]
|
|
62
|
+
- @ai-sdk/provider-utils@5.0.0-beta.21
|
|
63
|
+
- @ai-sdk/anthropic@4.0.0-beta.29
|
|
64
|
+
|
|
65
|
+
## 5.0.0-beta.32
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- b3976a2: Add workflow serialization support to all provider models.
|
|
70
|
+
|
|
71
|
+
**`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
|
|
72
|
+
|
|
73
|
+
**All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
|
|
74
|
+
|
|
75
|
+
All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
|
|
76
|
+
|
|
77
|
+
- ff5eba1: feat: roll `image-*` tool output types into their equivalent `file-*` types
|
|
78
|
+
- Updated dependencies [b3976a2]
|
|
79
|
+
- Updated dependencies [ff5eba1]
|
|
80
|
+
- @ai-sdk/provider-utils@5.0.0-beta.20
|
|
81
|
+
- @ai-sdk/anthropic@4.0.0-beta.28
|
|
82
|
+
- @ai-sdk/provider@4.0.0-beta.12
|
|
83
|
+
|
|
84
|
+
## 5.0.0-beta.31
|
|
85
|
+
|
|
86
|
+
### Major Changes
|
|
87
|
+
|
|
88
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
89
|
+
|
|
90
|
+
### Patch Changes
|
|
91
|
+
|
|
92
|
+
- Updated dependencies [ef992f8]
|
|
93
|
+
- @ai-sdk/anthropic@4.0.0-beta.27
|
|
94
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
95
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
96
|
+
|
|
97
|
+
## 5.0.0-beta.30
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
|
|
102
|
+
- Updated dependencies [90e2d8a]
|
|
103
|
+
- @ai-sdk/provider-utils@5.0.0-beta.18
|
|
104
|
+
- @ai-sdk/anthropic@4.0.0-beta.26
|
|
105
|
+
|
|
106
|
+
## 5.0.0-beta.29
|
|
107
|
+
|
|
108
|
+
### Patch Changes
|
|
109
|
+
|
|
110
|
+
- Updated dependencies [09bd27b]
|
|
111
|
+
- @ai-sdk/anthropic@4.0.0-beta.25
|
|
112
|
+
|
|
113
|
+
## 5.0.0-beta.28
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- Updated dependencies [3ae1786]
|
|
118
|
+
- @ai-sdk/provider-utils@5.0.0-beta.17
|
|
119
|
+
- @ai-sdk/anthropic@4.0.0-beta.24
|
|
120
|
+
|
|
121
|
+
## 5.0.0-beta.27
|
|
122
|
+
|
|
123
|
+
### Patch Changes
|
|
124
|
+
|
|
125
|
+
- Updated dependencies [176466a]
|
|
126
|
+
- @ai-sdk/provider@4.0.0-beta.10
|
|
127
|
+
- @ai-sdk/anthropic@4.0.0-beta.23
|
|
128
|
+
- @ai-sdk/provider-utils@5.0.0-beta.16
|
|
129
|
+
|
|
130
|
+
## 5.0.0-beta.26
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- Updated dependencies [e311194]
|
|
135
|
+
- @ai-sdk/provider@4.0.0-beta.9
|
|
136
|
+
- @ai-sdk/anthropic@4.0.0-beta.22
|
|
137
|
+
- @ai-sdk/provider-utils@5.0.0-beta.15
|
|
138
|
+
|
|
139
|
+
## 5.0.0-beta.25
|
|
140
|
+
|
|
141
|
+
### Patch Changes
|
|
142
|
+
|
|
143
|
+
- 24ac76f: fix(amazon-bedrock): preserve empty text blocks when reasoning content is present
|
|
144
|
+
- cdc15f3: feat(bedrock): support native structured output for anthropic models without reasoning
|
|
145
|
+
- Updated dependencies [34bd95d]
|
|
146
|
+
- Updated dependencies [008271d]
|
|
147
|
+
- @ai-sdk/anthropic@4.0.0-beta.21
|
|
148
|
+
- @ai-sdk/provider@4.0.0-beta.8
|
|
149
|
+
- @ai-sdk/provider-utils@5.0.0-beta.14
|
|
150
|
+
|
|
151
|
+
## 5.0.0-beta.24
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- Updated dependencies [b0c2869]
|
|
156
|
+
- Updated dependencies [7e26e81]
|
|
157
|
+
- @ai-sdk/provider-utils@5.0.0-beta.13
|
|
158
|
+
- @ai-sdk/anthropic@4.0.0-beta.20
|
|
159
|
+
|
|
160
|
+
## 5.0.0-beta.23
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- Updated dependencies [46d1149]
|
|
165
|
+
- @ai-sdk/provider-utils@5.0.0-beta.12
|
|
166
|
+
- @ai-sdk/anthropic@4.0.0-beta.19
|
|
167
|
+
|
|
168
|
+
## 5.0.0-beta.22
|
|
169
|
+
|
|
170
|
+
### Patch Changes
|
|
171
|
+
|
|
172
|
+
- Updated dependencies [6fd51c0]
|
|
173
|
+
- @ai-sdk/provider-utils@5.0.0-beta.11
|
|
174
|
+
- @ai-sdk/provider@4.0.0-beta.7
|
|
175
|
+
- @ai-sdk/anthropic@4.0.0-beta.18
|
|
176
|
+
|
|
177
|
+
## 5.0.0-beta.21
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
|
|
182
|
+
- Updated dependencies [c29a26f]
|
|
183
|
+
- @ai-sdk/provider-utils@5.0.0-beta.10
|
|
184
|
+
- @ai-sdk/anthropic@4.0.0-beta.17
|
|
185
|
+
- @ai-sdk/provider@4.0.0-beta.6
|
|
186
|
+
|
|
187
|
+
## 5.0.0-beta.20
|
|
188
|
+
|
|
189
|
+
### Patch Changes
|
|
190
|
+
|
|
191
|
+
- 38fc777: Add AI Gateway hint to provider READMEs
|
|
192
|
+
- Updated dependencies [38fc777]
|
|
193
|
+
- @ai-sdk/anthropic@4.0.0-beta.16
|
|
194
|
+
|
|
195
|
+
## 5.0.0-beta.19
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- Updated dependencies [f57c702]
|
|
200
|
+
- @ai-sdk/anthropic@4.0.0-beta.15
|
|
201
|
+
|
|
202
|
+
## 5.0.0-beta.18
|
|
203
|
+
|
|
204
|
+
### Patch Changes
|
|
205
|
+
|
|
206
|
+
- Updated dependencies [2e17091]
|
|
207
|
+
- @ai-sdk/provider-utils@5.0.0-beta.9
|
|
208
|
+
- @ai-sdk/anthropic@4.0.0-beta.14
|
|
209
|
+
|
|
210
|
+
## 5.0.0-beta.17
|
|
211
|
+
|
|
212
|
+
### Patch Changes
|
|
213
|
+
|
|
214
|
+
- Updated dependencies [986c6fd]
|
|
215
|
+
- Updated dependencies [493295c]
|
|
216
|
+
- @ai-sdk/provider-utils@5.0.0-beta.8
|
|
217
|
+
- @ai-sdk/anthropic@4.0.0-beta.13
|
|
218
|
+
|
|
219
|
+
## 5.0.0-beta.16
|
|
220
|
+
|
|
221
|
+
### Patch Changes
|
|
222
|
+
|
|
223
|
+
- 6d8716c: feat(bedrock): add support for service tier for model inference
|
|
224
|
+
|
|
225
|
+
## 5.0.0-beta.15
|
|
226
|
+
|
|
227
|
+
### Patch Changes
|
|
228
|
+
|
|
229
|
+
- 4b20a5d: fix(provider/amazon-bedrock): transform bedrock/anthropic error responses to anthropic format
|
|
230
|
+
|
|
231
|
+
## 5.0.0-beta.14
|
|
232
|
+
|
|
233
|
+
### Patch Changes
|
|
234
|
+
|
|
235
|
+
- b0c59e8: fix(amazon-bedrock): preserve reasoning text when signature is present
|
|
236
|
+
|
|
237
|
+
## 5.0.0-beta.13
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- 1921625: fix(provider/amazon-bedrock): add tool search beta for Anthropic
|
|
242
|
+
|
|
243
|
+
## 5.0.0-beta.12
|
|
244
|
+
|
|
245
|
+
### Patch Changes
|
|
246
|
+
|
|
247
|
+
- Updated dependencies [1f509d4]
|
|
248
|
+
- @ai-sdk/provider-utils@5.0.0-beta.7
|
|
249
|
+
- @ai-sdk/provider@4.0.0-beta.5
|
|
250
|
+
- @ai-sdk/anthropic@4.0.0-beta.12
|
|
251
|
+
|
|
252
|
+
## 5.0.0-beta.11
|
|
253
|
+
|
|
254
|
+
### Patch Changes
|
|
255
|
+
|
|
256
|
+
- Updated dependencies [0ee8aec]
|
|
257
|
+
- @ai-sdk/anthropic@4.0.0-beta.11
|
|
258
|
+
|
|
259
|
+
## 5.0.0-beta.10
|
|
260
|
+
|
|
261
|
+
### Patch Changes
|
|
262
|
+
|
|
263
|
+
- 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
|
|
264
|
+
- Updated dependencies [3887c70]
|
|
265
|
+
- @ai-sdk/provider-utils@5.0.0-beta.6
|
|
266
|
+
- @ai-sdk/anthropic@4.0.0-beta.10
|
|
267
|
+
- @ai-sdk/provider@4.0.0-beta.4
|
|
268
|
+
|
|
269
|
+
## 5.0.0-beta.9
|
|
270
|
+
|
|
271
|
+
### Patch Changes
|
|
272
|
+
|
|
273
|
+
- Updated dependencies [776b617]
|
|
274
|
+
- @ai-sdk/provider-utils@5.0.0-beta.5
|
|
275
|
+
- @ai-sdk/provider@4.0.0-beta.3
|
|
276
|
+
- @ai-sdk/anthropic@4.0.0-beta.9
|
|
277
|
+
|
|
278
|
+
## 5.0.0-beta.8
|
|
279
|
+
|
|
280
|
+
### Patch Changes
|
|
281
|
+
|
|
282
|
+
- Updated dependencies [61753c3]
|
|
283
|
+
- @ai-sdk/provider-utils@5.0.0-beta.4
|
|
284
|
+
- @ai-sdk/anthropic@4.0.0-beta.8
|
|
285
|
+
|
|
286
|
+
## 5.0.0-beta.7
|
|
287
|
+
|
|
288
|
+
### Patch Changes
|
|
289
|
+
|
|
290
|
+
- Updated dependencies [f7d4f01]
|
|
291
|
+
- @ai-sdk/provider-utils@5.0.0-beta.3
|
|
292
|
+
- @ai-sdk/provider@4.0.0-beta.2
|
|
293
|
+
- @ai-sdk/anthropic@4.0.0-beta.7
|
|
294
|
+
|
|
295
|
+
## 5.0.0-beta.6
|
|
296
|
+
|
|
297
|
+
### Patch Changes
|
|
298
|
+
|
|
299
|
+
- Updated dependencies [21d1ee3]
|
|
300
|
+
- @ai-sdk/anthropic@4.0.0-beta.6
|
|
301
|
+
|
|
302
|
+
## 5.0.0-beta.5
|
|
303
|
+
|
|
304
|
+
### Patch Changes
|
|
305
|
+
|
|
306
|
+
- Updated dependencies [5c2a5a2]
|
|
307
|
+
- @ai-sdk/provider@4.0.0-beta.1
|
|
308
|
+
- @ai-sdk/anthropic@4.0.0-beta.5
|
|
309
|
+
- @ai-sdk/provider-utils@5.0.0-beta.2
|
|
310
|
+
|
|
3
311
|
## 5.0.0-beta.4
|
|
4
312
|
|
|
5
313
|
### Patch Changes
|
|
@@ -635,13 +943,13 @@
|
|
|
635
943
|
Before
|
|
636
944
|
|
|
637
945
|
```ts
|
|
638
|
-
model.textEmbeddingModel(
|
|
946
|
+
model.textEmbeddingModel("my-model-id");
|
|
639
947
|
```
|
|
640
948
|
|
|
641
949
|
After
|
|
642
950
|
|
|
643
951
|
```ts
|
|
644
|
-
model.embeddingModel(
|
|
952
|
+
model.embeddingModel("my-model-id");
|
|
645
953
|
```
|
|
646
954
|
|
|
647
955
|
- 2625a04: feat(openai); update spec for mcp approval
|
|
@@ -1033,13 +1341,13 @@
|
|
|
1033
1341
|
Before
|
|
1034
1342
|
|
|
1035
1343
|
```ts
|
|
1036
|
-
model.textEmbeddingModel(
|
|
1344
|
+
model.textEmbeddingModel("my-model-id");
|
|
1037
1345
|
```
|
|
1038
1346
|
|
|
1039
1347
|
After
|
|
1040
1348
|
|
|
1041
1349
|
```ts
|
|
1042
|
-
model.embeddingModel(
|
|
1350
|
+
model.embeddingModel("my-model-id");
|
|
1043
1351
|
```
|
|
1044
1352
|
|
|
1045
1353
|
- Updated dependencies [8d9e8ad]
|
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
The **[Amazon Bedrock provider](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock)** for the [AI SDK](https://ai-sdk.dev/docs)
|
|
4
4
|
contains language model support for the Amazon Bedrock [converse API](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html).
|
|
5
5
|
|
|
6
|
+
> **Deploying to Vercel?** With Vercel's AI Gateway you can access Amazon Bedrock (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
7
|
+
|
|
6
8
|
## Setup
|
|
7
9
|
|
|
8
10
|
The Amazon Bedrock provider is available in the `@ai-sdk/amazon-bedrock` module. You can install it with
|
|
@@ -9,7 +9,7 @@ interface BedrockCredentials {
|
|
|
9
9
|
sessionToken?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
type BedrockAnthropicModelId = 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-sonnet-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-sonnet-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
|
|
12
|
+
type BedrockAnthropicModelId = 'anthropic.claude-opus-4-7' | 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-sonnet-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-7' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-sonnet-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
|
|
13
13
|
|
|
14
14
|
interface BedrockAnthropicProvider extends ProviderV4 {
|
|
15
15
|
/**
|
package/dist/anthropic/index.js
CHANGED
|
@@ -1,55 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/anthropic/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
bedrockAnthropic: () => bedrockAnthropic,
|
|
24
|
-
createBedrockAnthropic: () => createBedrockAnthropic
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
1
|
// src/anthropic/bedrock-anthropic-provider.ts
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadOptionalSetting,
|
|
7
|
+
loadSetting,
|
|
8
|
+
resolve,
|
|
9
|
+
withoutTrailingSlash,
|
|
10
|
+
withUserAgentSuffix as withUserAgentSuffix2
|
|
11
|
+
} from "@ai-sdk/provider-utils";
|
|
12
|
+
import {
|
|
13
|
+
anthropicTools,
|
|
14
|
+
AnthropicMessagesLanguageModel
|
|
15
|
+
} from "@ai-sdk/anthropic/internal";
|
|
32
16
|
|
|
33
17
|
// src/bedrock-sigv4-fetch.ts
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
import {
|
|
19
|
+
combineHeaders,
|
|
20
|
+
normalizeHeaders,
|
|
21
|
+
withUserAgentSuffix,
|
|
22
|
+
getRuntimeEnvironmentUserAgent
|
|
23
|
+
} from "@ai-sdk/provider-utils";
|
|
24
|
+
import { AwsV4Signer } from "aws4fetch";
|
|
36
25
|
|
|
37
26
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "5.0.0-beta.
|
|
27
|
+
var VERSION = true ? "5.0.0-beta.40" : "0.0.0-test";
|
|
39
28
|
|
|
40
29
|
// src/bedrock-sigv4-fetch.ts
|
|
41
30
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
42
31
|
return async (input, init) => {
|
|
43
32
|
var _a, _b;
|
|
44
33
|
const request = input instanceof Request ? input : void 0;
|
|
45
|
-
const originalHeaders =
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
const originalHeaders = combineHeaders(
|
|
35
|
+
normalizeHeaders(request == null ? void 0 : request.headers),
|
|
36
|
+
normalizeHeaders(init == null ? void 0 : init.headers)
|
|
48
37
|
);
|
|
49
|
-
const headersWithUserAgent =
|
|
38
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
50
39
|
originalHeaders,
|
|
51
40
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
52
|
-
|
|
41
|
+
getRuntimeEnvironmentUserAgent()
|
|
53
42
|
);
|
|
54
43
|
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
55
44
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
@@ -68,7 +57,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
68
57
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
69
58
|
const body = prepareBodyString(effectiveBody);
|
|
70
59
|
const credentials = await getCredentials();
|
|
71
|
-
const signer = new
|
|
60
|
+
const signer = new AwsV4Signer({
|
|
72
61
|
url,
|
|
73
62
|
method: "POST",
|
|
74
63
|
headers: Object.entries(headersWithUserAgent),
|
|
@@ -80,8 +69,8 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
80
69
|
service: "bedrock"
|
|
81
70
|
});
|
|
82
71
|
const signingResult = await signer.sign();
|
|
83
|
-
const signedHeaders =
|
|
84
|
-
const combinedHeaders =
|
|
72
|
+
const signedHeaders = normalizeHeaders(signingResult.headers);
|
|
73
|
+
const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
|
|
85
74
|
return fetch(input, {
|
|
86
75
|
...init,
|
|
87
76
|
body,
|
|
@@ -102,13 +91,13 @@ function prepareBodyString(body) {
|
|
|
102
91
|
}
|
|
103
92
|
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
104
93
|
return async (input, init) => {
|
|
105
|
-
const originalHeaders =
|
|
106
|
-
const headersWithUserAgent =
|
|
94
|
+
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
95
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
107
96
|
originalHeaders,
|
|
108
97
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
109
|
-
|
|
98
|
+
getRuntimeEnvironmentUserAgent()
|
|
110
99
|
);
|
|
111
|
-
const finalHeaders =
|
|
100
|
+
const finalHeaders = combineHeaders(headersWithUserAgent, {
|
|
112
101
|
Authorization: `Bearer ${apiKey}`
|
|
113
102
|
});
|
|
114
103
|
return fetch(input, {
|
|
@@ -119,13 +108,17 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
|
119
108
|
}
|
|
120
109
|
|
|
121
110
|
// src/anthropic/bedrock-anthropic-fetch.ts
|
|
122
|
-
|
|
111
|
+
import {
|
|
112
|
+
convertBase64ToUint8Array,
|
|
113
|
+
safeParseJSON
|
|
114
|
+
} from "@ai-sdk/provider-utils";
|
|
115
|
+
import { z } from "zod/v4";
|
|
123
116
|
|
|
124
117
|
// src/bedrock-event-stream-decoder.ts
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
119
|
+
import { toUtf8, fromUtf8 } from "@smithy/util-utf8";
|
|
127
120
|
function createBedrockEventStreamDecoder(body, processEvent) {
|
|
128
|
-
const codec = new
|
|
121
|
+
const codec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
129
122
|
let buffer = new Uint8Array(0);
|
|
130
123
|
const textDecoder = new TextDecoder();
|
|
131
124
|
return body.pipeThrough(
|
|
@@ -163,9 +156,26 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
163
156
|
}
|
|
164
157
|
|
|
165
158
|
// src/anthropic/bedrock-anthropic-fetch.ts
|
|
159
|
+
var bedrockErrorSchema = z.looseObject({
|
|
160
|
+
message: z.string().optional()
|
|
161
|
+
});
|
|
166
162
|
function createBedrockAnthropicFetch(baseFetch) {
|
|
167
163
|
return async (url, options) => {
|
|
168
164
|
const response = await baseFetch(url, options);
|
|
165
|
+
if (!response.ok) {
|
|
166
|
+
const text = await response.text();
|
|
167
|
+
const parsed = await safeParseJSON({ text, schema: bedrockErrorSchema });
|
|
168
|
+
const message = parsed.success && parsed.value.message ? parsed.value.message : text;
|
|
169
|
+
const anthropicError = JSON.stringify({
|
|
170
|
+
type: "error",
|
|
171
|
+
error: { type: "error", message }
|
|
172
|
+
});
|
|
173
|
+
return new Response(anthropicError, {
|
|
174
|
+
status: response.status,
|
|
175
|
+
statusText: response.statusText,
|
|
176
|
+
headers: response.headers
|
|
177
|
+
});
|
|
178
|
+
}
|
|
169
179
|
const contentType = response.headers.get("content-type");
|
|
170
180
|
if ((contentType == null ? void 0 : contentType.includes("application/vnd.amazon.eventstream")) && response.body != null) {
|
|
171
181
|
const transformedBody = transformBedrockEventStreamToSSE(response.body);
|
|
@@ -186,7 +196,7 @@ function transformBedrockEventStreamToSSE(body) {
|
|
|
186
196
|
return createBedrockEventStreamDecoder(body, async (event, controller) => {
|
|
187
197
|
if (event.messageType === "event") {
|
|
188
198
|
if (event.eventType === "chunk") {
|
|
189
|
-
const parsed = await
|
|
199
|
+
const parsed = await safeParseJSON({ text: event.data });
|
|
190
200
|
if (!parsed.success) {
|
|
191
201
|
controller.enqueue(textEncoder.encode(`data: ${event.data}
|
|
192
202
|
|
|
@@ -196,7 +206,7 @@ function transformBedrockEventStreamToSSE(body) {
|
|
|
196
206
|
const bytes = parsed.value.bytes;
|
|
197
207
|
if (bytes) {
|
|
198
208
|
const anthropicEvent = new TextDecoder().decode(
|
|
199
|
-
|
|
209
|
+
convertBase64ToUint8Array(bytes)
|
|
200
210
|
);
|
|
201
211
|
controller.enqueue(textEncoder.encode(`data: ${anthropicEvent}
|
|
202
212
|
|
|
@@ -238,16 +248,20 @@ var BEDROCK_TOOL_BETA_MAP = {
|
|
|
238
248
|
text_editor_20250429: "computer-use-2025-01-24",
|
|
239
249
|
text_editor_20250728: "computer-use-2025-01-24",
|
|
240
250
|
computer_20250124: "computer-use-2025-01-24",
|
|
241
|
-
computer_20241022: "computer-use-2024-10-22"
|
|
251
|
+
computer_20241022: "computer-use-2024-10-22",
|
|
252
|
+
tool_search_tool_regex_20251119: "tool-search-tool-2025-10-19",
|
|
253
|
+
// BM25 is not currently supported on Bedrock, but including the beta flag
|
|
254
|
+
// so that Bedrock returns a more useful error message if it's used.
|
|
255
|
+
tool_search_tool_bm25_20251119: "tool-search-tool-2025-10-19"
|
|
242
256
|
};
|
|
243
257
|
function createBedrockAnthropic(options = {}) {
|
|
244
|
-
const rawApiKey =
|
|
258
|
+
const rawApiKey = loadOptionalSetting({
|
|
245
259
|
settingValue: options.apiKey,
|
|
246
260
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
247
261
|
});
|
|
248
262
|
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
249
263
|
const baseFetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
250
|
-
const region =
|
|
264
|
+
const region = loadSetting({
|
|
251
265
|
settingValue: options.region,
|
|
252
266
|
settingName: "region",
|
|
253
267
|
environmentVariableName: "AWS_REGION",
|
|
@@ -269,19 +283,19 @@ function createBedrockAnthropic(options = {}) {
|
|
|
269
283
|
try {
|
|
270
284
|
return {
|
|
271
285
|
region,
|
|
272
|
-
accessKeyId:
|
|
286
|
+
accessKeyId: loadSetting({
|
|
273
287
|
settingValue: options.accessKeyId,
|
|
274
288
|
settingName: "accessKeyId",
|
|
275
289
|
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
276
290
|
description: "AWS access key ID"
|
|
277
291
|
}),
|
|
278
|
-
secretAccessKey:
|
|
292
|
+
secretAccessKey: loadSetting({
|
|
279
293
|
settingValue: options.secretAccessKey,
|
|
280
294
|
settingName: "secretAccessKey",
|
|
281
295
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
282
296
|
description: "AWS secret access key"
|
|
283
297
|
}),
|
|
284
|
-
sessionToken:
|
|
298
|
+
sessionToken: loadOptionalSetting({
|
|
285
299
|
settingValue: options.sessionToken,
|
|
286
300
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
287
301
|
})
|
|
@@ -310,8 +324,8 @@ Original error: ${errorMessage}`
|
|
|
310
324
|
const fetchFunction = createBedrockAnthropicFetch(baseFetchFunction);
|
|
311
325
|
const getBaseURL = () => {
|
|
312
326
|
var _a, _b;
|
|
313
|
-
return (_b =
|
|
314
|
-
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${
|
|
327
|
+
return (_b = withoutTrailingSlash(
|
|
328
|
+
(_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${loadSetting({
|
|
315
329
|
settingValue: options.region,
|
|
316
330
|
settingName: "region",
|
|
317
331
|
environmentVariableName: "AWS_REGION",
|
|
@@ -321,17 +335,23 @@ Original error: ${errorMessage}`
|
|
|
321
335
|
};
|
|
322
336
|
const getHeaders = async () => {
|
|
323
337
|
var _a;
|
|
324
|
-
const baseHeaders = (_a = await
|
|
325
|
-
return (
|
|
338
|
+
const baseHeaders = (_a = await resolve(options.headers)) != null ? _a : {};
|
|
339
|
+
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
326
340
|
};
|
|
327
|
-
const createChatModel = (modelId) => new
|
|
341
|
+
const createChatModel = (modelId) => new AnthropicMessagesLanguageModel(modelId, {
|
|
328
342
|
provider: "bedrock.anthropic.messages",
|
|
329
343
|
baseURL: getBaseURL(),
|
|
330
344
|
headers: getHeaders,
|
|
331
345
|
fetch: fetchFunction,
|
|
332
346
|
buildRequestUrl: (baseURL, isStreaming) => `${baseURL}/model/${encodeURIComponent(modelId)}/${isStreaming ? "invoke-with-response-stream" : "invoke"}`,
|
|
333
347
|
transformRequestBody: (args, betas) => {
|
|
334
|
-
const {
|
|
348
|
+
const {
|
|
349
|
+
model: _model,
|
|
350
|
+
stream: _stream,
|
|
351
|
+
tool_choice,
|
|
352
|
+
tools,
|
|
353
|
+
...rest
|
|
354
|
+
} = args;
|
|
335
355
|
const transformedToolChoice = tool_choice != null ? {
|
|
336
356
|
type: tool_choice.type,
|
|
337
357
|
...tool_choice.name != null ? { name: tool_choice.name } : {}
|
|
@@ -388,19 +408,18 @@ Original error: ${errorMessage}`
|
|
|
388
408
|
provider.chat = createChatModel;
|
|
389
409
|
provider.messages = createChatModel;
|
|
390
410
|
provider.embeddingModel = (modelId) => {
|
|
391
|
-
throw new
|
|
411
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
392
412
|
};
|
|
393
413
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
394
414
|
provider.imageModel = (modelId) => {
|
|
395
|
-
throw new
|
|
415
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
396
416
|
};
|
|
397
|
-
provider.tools =
|
|
417
|
+
provider.tools = anthropicTools;
|
|
398
418
|
return provider;
|
|
399
419
|
}
|
|
400
420
|
var bedrockAnthropic = createBedrockAnthropic();
|
|
401
|
-
|
|
402
|
-
0 && (module.exports = {
|
|
421
|
+
export {
|
|
403
422
|
bedrockAnthropic,
|
|
404
423
|
createBedrockAnthropic
|
|
405
|
-
}
|
|
424
|
+
};
|
|
406
425
|
//# sourceMappingURL=index.js.map
|