@ai-sdk/amazon-bedrock 5.0.0-beta.13 → 5.0.0-beta.15
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 +12 -0
- package/dist/anthropic/index.js +19 -1
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +19 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.js +29 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -26
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +6 -6
- package/package.json +3 -3
- package/src/anthropic/bedrock-anthropic-fetch.ts +26 -0
- package/src/convert-to-bedrock-chat-messages.ts +33 -25
|
@@ -1443,7 +1443,7 @@ They are available via the `tools` property of the provider instance.
|
|
|
1443
1443
|
|
|
1444
1444
|
```ts
|
|
1445
1445
|
import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
|
|
1446
|
-
import { generateText,
|
|
1446
|
+
import { generateText, isStepCount } from 'ai';
|
|
1447
1447
|
|
|
1448
1448
|
const result = await generateText({
|
|
1449
1449
|
model: bedrockAnthropic('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
|
|
@@ -1456,7 +1456,7 @@ const result = await generateText({
|
|
|
1456
1456
|
}),
|
|
1457
1457
|
},
|
|
1458
1458
|
prompt: 'List the files in my directory.',
|
|
1459
|
-
stopWhen:
|
|
1459
|
+
stopWhen: isStepCount(2),
|
|
1460
1460
|
});
|
|
1461
1461
|
```
|
|
1462
1462
|
|
|
@@ -1464,7 +1464,7 @@ const result = await generateText({
|
|
|
1464
1464
|
|
|
1465
1465
|
```ts
|
|
1466
1466
|
import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
|
|
1467
|
-
import { generateText,
|
|
1467
|
+
import { generateText, isStepCount } from 'ai';
|
|
1468
1468
|
|
|
1469
1469
|
const result = await generateText({
|
|
1470
1470
|
model: bedrockAnthropic('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
|
|
@@ -1477,7 +1477,7 @@ const result = await generateText({
|
|
|
1477
1477
|
}),
|
|
1478
1478
|
},
|
|
1479
1479
|
prompt: 'Update my README file.',
|
|
1480
|
-
stopWhen:
|
|
1480
|
+
stopWhen: isStepCount(5),
|
|
1481
1481
|
});
|
|
1482
1482
|
```
|
|
1483
1483
|
|
|
@@ -1485,7 +1485,7 @@ const result = await generateText({
|
|
|
1485
1485
|
|
|
1486
1486
|
```ts
|
|
1487
1487
|
import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
|
|
1488
|
-
import { generateText,
|
|
1488
|
+
import { generateText, isStepCount } from 'ai';
|
|
1489
1489
|
import fs from 'fs';
|
|
1490
1490
|
|
|
1491
1491
|
const result = await generateText({
|
|
@@ -1520,7 +1520,7 @@ const result = await generateText({
|
|
|
1520
1520
|
}),
|
|
1521
1521
|
},
|
|
1522
1522
|
prompt: 'Take a screenshot.',
|
|
1523
|
-
stopWhen:
|
|
1523
|
+
stopWhen: isStepCount(3),
|
|
1524
1524
|
});
|
|
1525
1525
|
```
|
|
1526
1526
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.15",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@smithy/util-utf8": "^4.0.0",
|
|
40
40
|
"aws4fetch": "^1.0.20",
|
|
41
41
|
"@ai-sdk/anthropic": "4.0.0-beta.12",
|
|
42
|
-
"@ai-sdk/provider": "
|
|
43
|
-
"@ai-sdk/provider
|
|
42
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.7",
|
|
43
|
+
"@ai-sdk/provider": "4.0.0-beta.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "20.17.24",
|
|
@@ -3,14 +3,40 @@ import {
|
|
|
3
3
|
FetchFunction,
|
|
4
4
|
safeParseJSON,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
6
7
|
import { createBedrockEventStreamDecoder } from '../bedrock-event-stream-decoder';
|
|
7
8
|
|
|
9
|
+
const bedrockErrorSchema = z.looseObject({
|
|
10
|
+
message: z.string().optional(),
|
|
11
|
+
});
|
|
12
|
+
|
|
8
13
|
export function createBedrockAnthropicFetch(
|
|
9
14
|
baseFetch: FetchFunction,
|
|
10
15
|
): FetchFunction {
|
|
11
16
|
return async (url, options) => {
|
|
12
17
|
const response = await baseFetch(url, options);
|
|
13
18
|
|
|
19
|
+
// Transform Bedrock error responses into Anthropic error format
|
|
20
|
+
// so that anthropicFailedResponseHandler can extract the message.
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
const parsed = await safeParseJSON({ text, schema: bedrockErrorSchema });
|
|
24
|
+
|
|
25
|
+
const message =
|
|
26
|
+
parsed.success && parsed.value.message ? parsed.value.message : text;
|
|
27
|
+
|
|
28
|
+
const anthropicError = JSON.stringify({
|
|
29
|
+
type: 'error',
|
|
30
|
+
error: { type: 'error', message },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return new Response(anthropicError, {
|
|
34
|
+
status: response.status,
|
|
35
|
+
statusText: response.statusText,
|
|
36
|
+
headers: response.headers,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
14
40
|
const contentType = response.headers.get('content-type');
|
|
15
41
|
if (
|
|
16
42
|
contentType?.includes('application/vnd.amazon.eventstream') &&
|
|
@@ -287,33 +287,41 @@ export async function convertToBedrockChatMessages(
|
|
|
287
287
|
schema: bedrockReasoningMetadataSchema,
|
|
288
288
|
});
|
|
289
289
|
|
|
290
|
-
if (reasoningMetadata != null) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
text: trimIfLast(
|
|
299
|
-
isLastBlock,
|
|
300
|
-
isLastMessage,
|
|
301
|
-
isLastContentPart,
|
|
302
|
-
part.text,
|
|
303
|
-
),
|
|
304
|
-
signature: reasoningMetadata.signature,
|
|
305
|
-
},
|
|
290
|
+
if (reasoningMetadata?.signature != null) {
|
|
291
|
+
// do not trim reasoning text when a signature is present:
|
|
292
|
+
// the signature validates the exact original bytes
|
|
293
|
+
bedrockContent.push({
|
|
294
|
+
reasoningContent: {
|
|
295
|
+
reasoningText: {
|
|
296
|
+
text: part.text,
|
|
297
|
+
signature: reasoningMetadata.signature,
|
|
306
298
|
},
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
} else if (reasoningMetadata?.redactedData != null) {
|
|
302
|
+
bedrockContent.push({
|
|
303
|
+
reasoningContent: {
|
|
304
|
+
redactedReasoning: {
|
|
305
|
+
data: reasoningMetadata.redactedData,
|
|
314
306
|
},
|
|
315
|
-
}
|
|
316
|
-
}
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
} else {
|
|
310
|
+
// trim the last text part if it's the last message in the block
|
|
311
|
+
// because Bedrock does not allow trailing whitespace
|
|
312
|
+
// in pre-filled assistant responses
|
|
313
|
+
bedrockContent.push({
|
|
314
|
+
reasoningContent: {
|
|
315
|
+
reasoningText: {
|
|
316
|
+
text: trimIfLast(
|
|
317
|
+
isLastBlock,
|
|
318
|
+
isLastMessage,
|
|
319
|
+
isLastContentPart,
|
|
320
|
+
part.text,
|
|
321
|
+
),
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
});
|
|
317
325
|
}
|
|
318
326
|
|
|
319
327
|
break;
|