@ai-sdk/amazon-bedrock 5.0.57 → 5.0.59
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 +20 -0
- package/dist/anthropic/index.js +15 -12
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.js +79 -25
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/package.json +4 -4
- package/src/amazon-bedrock-api-types.ts +7 -0
- package/src/amazon-bedrock-chat-language-model.ts +61 -2
- package/src/amazon-bedrock-event-stream-decoder.ts +14 -12
- package/src/amazon-bedrock-reasoning-metadata.ts +1 -0
- package/src/convert-to-amazon-bedrock-chat-messages.ts +6 -0
package/dist/mantle/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "5.0.
|
|
38
|
+
var VERSION = true ? "5.0.59" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "5.0.
|
|
26
|
+
var VERSION = true ? "5.0.59" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
29
29
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.59",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
45
45
|
"@smithy/util-utf8": "^4.3.3",
|
|
46
46
|
"aws4fetch": "^1.0.20",
|
|
47
|
-
"@ai-sdk/anthropic": "4.0.
|
|
48
|
-
"@ai-sdk/openai": "4.0.
|
|
47
|
+
"@ai-sdk/anthropic": "4.0.40",
|
|
48
|
+
"@ai-sdk/openai": "4.0.44",
|
|
49
49
|
"@ai-sdk/provider": "4.0.7",
|
|
50
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
50
|
+
"@ai-sdk/provider-utils": "5.0.28"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "22.19.19",
|
|
@@ -258,6 +258,12 @@ export interface AmazonBedrockRedactedReasoningContentBlock {
|
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
export interface AmazonBedrockRedactedContentBlock {
|
|
262
|
+
reasoningContent: {
|
|
263
|
+
redactedContent: string;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
261
267
|
export type AmazonBedrockContentBlock =
|
|
262
268
|
| AmazonBedrockDocumentBlock
|
|
263
269
|
| AmazonBedrockGuardrailConverseContentBlock
|
|
@@ -268,4 +274,5 @@ export type AmazonBedrockContentBlock =
|
|
|
268
274
|
| AmazonBedrockToolUseBlock
|
|
269
275
|
| AmazonBedrockReasoningContentBlock
|
|
270
276
|
| AmazonBedrockRedactedReasoningContentBlock
|
|
277
|
+
| AmazonBedrockRedactedContentBlock
|
|
271
278
|
| AmazonBedrockCachePoint;
|
|
@@ -573,6 +573,18 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
573
573
|
bedrock: redactedPayload,
|
|
574
574
|
},
|
|
575
575
|
});
|
|
576
|
+
} else if ('redactedContent' in part.reasoningContent) {
|
|
577
|
+
const redactedPayload: AmazonBedrockReasoningMetadata = {
|
|
578
|
+
redactedContent: part.reasoningContent.redactedContent,
|
|
579
|
+
};
|
|
580
|
+
content.push({
|
|
581
|
+
type: 'reasoning',
|
|
582
|
+
text: '',
|
|
583
|
+
providerMetadata: {
|
|
584
|
+
amazonBedrock: redactedPayload,
|
|
585
|
+
bedrock: redactedPayload,
|
|
586
|
+
},
|
|
587
|
+
});
|
|
576
588
|
}
|
|
577
589
|
}
|
|
578
590
|
|
|
@@ -591,7 +603,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
591
603
|
} else {
|
|
592
604
|
const isMistral = isMistralModel(this.modelId);
|
|
593
605
|
const rawToolCallId =
|
|
594
|
-
part.toolUse?.toolUseId
|
|
606
|
+
part.toolUse?.toolUseId || this.config.generateId();
|
|
595
607
|
content.push({
|
|
596
608
|
type: 'tool-call' as const,
|
|
597
609
|
toolCallId: normalizeToolCallId(rawToolCallId, isMistral),
|
|
@@ -720,7 +732,8 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
720
732
|
jsonText: string;
|
|
721
733
|
isJsonResponseTool?: boolean;
|
|
722
734
|
}
|
|
723
|
-
| { type: 'text'
|
|
735
|
+
| { type: 'text' }
|
|
736
|
+
| { type: 'reasoning'; redactedContent?: string }
|
|
724
737
|
> = {};
|
|
725
738
|
|
|
726
739
|
return {
|
|
@@ -891,9 +904,21 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
891
904
|
|
|
892
905
|
if (contentBlock != null) {
|
|
893
906
|
if (contentBlock.type === 'reasoning') {
|
|
907
|
+
const redactedPayload: AmazonBedrockReasoningMetadata | null =
|
|
908
|
+
contentBlock.redactedContent != null
|
|
909
|
+
? { redactedContent: contentBlock.redactedContent }
|
|
910
|
+
: null;
|
|
894
911
|
controller.enqueue({
|
|
895
912
|
type: 'reasoning-end',
|
|
896
913
|
id: String(blockIndex),
|
|
914
|
+
...(redactedPayload != null
|
|
915
|
+
? {
|
|
916
|
+
providerMetadata: {
|
|
917
|
+
amazonBedrock: redactedPayload,
|
|
918
|
+
bedrock: redactedPayload,
|
|
919
|
+
},
|
|
920
|
+
}
|
|
921
|
+
: {}),
|
|
897
922
|
});
|
|
898
923
|
} else if (contentBlock.type === 'text') {
|
|
899
924
|
controller.enqueue({
|
|
@@ -1008,6 +1033,27 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
1008
1033
|
},
|
|
1009
1034
|
});
|
|
1010
1035
|
}
|
|
1036
|
+
} else if (
|
|
1037
|
+
'redactedContent' in reasoningContent &&
|
|
1038
|
+
reasoningContent.redactedContent
|
|
1039
|
+
) {
|
|
1040
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1041
|
+
contentBlocks[blockIndex] = { type: 'reasoning' };
|
|
1042
|
+
controller.enqueue({
|
|
1043
|
+
type: 'reasoning-start',
|
|
1044
|
+
id: String(blockIndex),
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
1049
|
+
if (contentBlock.type === 'reasoning') {
|
|
1050
|
+
// accumulate and attach once via reasoning-end: the merged
|
|
1051
|
+
// provider metadata of a reasoning part is last-write-wins,
|
|
1052
|
+
// so per-delta metadata would drop earlier chunks
|
|
1053
|
+
contentBlock.redactedContent =
|
|
1054
|
+
(contentBlock.redactedContent ?? '') +
|
|
1055
|
+
reasoningContent.redactedContent;
|
|
1056
|
+
}
|
|
1011
1057
|
}
|
|
1012
1058
|
}
|
|
1013
1059
|
|
|
@@ -1216,6 +1262,13 @@ const AmazonBedrockResponseSchema = z.object({
|
|
|
1216
1262
|
z.object({
|
|
1217
1263
|
redactedReasoning: AmazonBedrockRedactedReasoningSchema,
|
|
1218
1264
|
}),
|
|
1265
|
+
// `redactedContent` is a member of the documented
|
|
1266
|
+
// ReasoningContentBlock union. OpenAI models on Bedrock
|
|
1267
|
+
// (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
|
|
1268
|
+
// reasoning in this shape.
|
|
1269
|
+
z.object({
|
|
1270
|
+
redactedContent: z.string(),
|
|
1271
|
+
}),
|
|
1219
1272
|
])
|
|
1220
1273
|
.nullish(),
|
|
1221
1274
|
}),
|
|
@@ -1262,6 +1315,12 @@ const AmazonBedrockStreamSchema = z.object({
|
|
|
1262
1315
|
z.object({
|
|
1263
1316
|
reasoningContent: z.object({ data: z.string() }),
|
|
1264
1317
|
}),
|
|
1318
|
+
// `redactedContent` is a member of the documented
|
|
1319
|
+
// ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
|
|
1320
|
+
// their encrypted reasoning in this shape.
|
|
1321
|
+
z.object({
|
|
1322
|
+
reasoningContent: z.object({ redactedContent: z.string() }),
|
|
1323
|
+
}),
|
|
1265
1324
|
])
|
|
1266
1325
|
.nullish(),
|
|
1267
1326
|
})
|
|
@@ -37,21 +37,23 @@ export function createAmazonBedrockEventStreamDecoder<T>(
|
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const decoded = codec.decode(subView);
|
|
40
|
+
const subView = buffer.subarray(0, totalLength);
|
|
41
|
+
const decoded = codec.decode(subView);
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
buffer = buffer.slice(totalLength);
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const data = textDecoder.decode(decoded.body);
|
|
45
|
+
const messageType = decoded.headers[':message-type']?.value as string;
|
|
46
|
+
const eventType = decoded.headers[':event-type']?.value as string;
|
|
47
|
+
const data = textDecoder.decode(decoded.body);
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
await processEvent({ messageType, eventType, data }, controller);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
flush() {
|
|
53
|
+
if (buffer.length > 0) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Incomplete Amazon Bedrock event-stream frame: ${buffer.length} buffered bytes remain at end of stream.`,
|
|
56
|
+
);
|
|
55
57
|
}
|
|
56
58
|
},
|
|
57
59
|
}),
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod/v4';
|
|
|
3
3
|
export const amazonBedrockReasoningMetadataSchema = z.object({
|
|
4
4
|
signature: z.string().optional(),
|
|
5
5
|
redactedData: z.string().optional(),
|
|
6
|
+
redactedContent: z.string().optional(),
|
|
6
7
|
});
|
|
7
8
|
|
|
8
9
|
export type AmazonBedrockReasoningMetadata = z.infer<
|
|
@@ -520,6 +520,12 @@ export async function convertToAmazonBedrockChatMessages(
|
|
|
520
520
|
},
|
|
521
521
|
},
|
|
522
522
|
});
|
|
523
|
+
} else if (reasoningMetadata?.redactedContent != null) {
|
|
524
|
+
amazonBedrockContent.push({
|
|
525
|
+
reasoningContent: {
|
|
526
|
+
redactedContent: reasoningMetadata.redactedContent,
|
|
527
|
+
},
|
|
528
|
+
});
|
|
523
529
|
} else if (reasoningMetadata?.redactedData != null) {
|
|
524
530
|
amazonBedrockContent.push({
|
|
525
531
|
reasoningContent: {
|