@ai-sdk/amazon-bedrock 4.0.157 → 4.0.159
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 +14 -0
- package/dist/anthropic/index.js +7 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +7 -3
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.js +89 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -30
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/package.json +2 -2
- package/src/bedrock-api-types.ts +7 -0
- package/src/bedrock-chat-language-model.ts +62 -1
- package/src/bedrock-event-stream-decoder.ts +12 -3
- package/src/bedrock-event-stream-response-handler.ts +31 -22
- package/src/bedrock-reasoning-metadata.ts +1 -0
- package/src/convert-to-bedrock-chat-messages.ts +6 -0
package/dist/mantle/index.js
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 ? "4.0.
|
|
38
|
+
var VERSION = true ? "4.0.159" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "4.0.
|
|
26
|
+
var VERSION = true ? "4.0.159" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/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": "4.0.
|
|
3
|
+
"version": "4.0.159",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@smithy/util-utf8": "^4.0.0",
|
|
46
46
|
"aws4fetch": "^1.0.20",
|
|
47
47
|
"@ai-sdk/anthropic": "3.0.111",
|
|
48
|
-
"@ai-sdk/openai": "3.0.
|
|
48
|
+
"@ai-sdk/openai": "3.0.99",
|
|
49
49
|
"@ai-sdk/provider": "3.0.15",
|
|
50
50
|
"@ai-sdk/provider-utils": "4.0.46"
|
|
51
51
|
},
|
package/src/bedrock-api-types.ts
CHANGED
|
@@ -213,6 +213,12 @@ export interface BedrockRedactedReasoningContentBlock {
|
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
export interface BedrockRedactedContentBlock {
|
|
217
|
+
reasoningContent: {
|
|
218
|
+
redactedContent: string;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
216
222
|
export type BedrockContentBlock =
|
|
217
223
|
| BedrockDocumentBlock
|
|
218
224
|
| BedrockGuardrailConverseContentBlock
|
|
@@ -222,4 +228,5 @@ export type BedrockContentBlock =
|
|
|
222
228
|
| BedrockToolUseBlock
|
|
223
229
|
| BedrockReasoningContentBlock
|
|
224
230
|
| BedrockRedactedReasoningContentBlock
|
|
231
|
+
| BedrockRedactedContentBlock
|
|
225
232
|
| BedrockCachePoint;
|
|
@@ -528,6 +528,16 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
528
528
|
} satisfies BedrockReasoningMetadata,
|
|
529
529
|
},
|
|
530
530
|
});
|
|
531
|
+
} else if ('redactedContent' in part.reasoningContent) {
|
|
532
|
+
content.push({
|
|
533
|
+
type: 'reasoning',
|
|
534
|
+
text: '',
|
|
535
|
+
providerMetadata: {
|
|
536
|
+
bedrock: {
|
|
537
|
+
redactedContent: part.reasoningContent.redactedContent,
|
|
538
|
+
} satisfies BedrockReasoningMetadata,
|
|
539
|
+
},
|
|
540
|
+
});
|
|
531
541
|
}
|
|
532
542
|
}
|
|
533
543
|
|
|
@@ -669,7 +679,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
669
679
|
jsonText: string;
|
|
670
680
|
isJsonResponseTool?: boolean;
|
|
671
681
|
}
|
|
672
|
-
| { type: 'text'
|
|
682
|
+
| { type: 'text' }
|
|
683
|
+
| { type: 'reasoning'; redactedContent?: string }
|
|
673
684
|
> = {};
|
|
674
685
|
|
|
675
686
|
return {
|
|
@@ -719,6 +730,10 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
719
730
|
enqueueError(value.modelStreamErrorException);
|
|
720
731
|
return;
|
|
721
732
|
}
|
|
733
|
+
if (value.serviceUnavailableException) {
|
|
734
|
+
enqueueError(value.serviceUnavailableException);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
722
737
|
if (value.throttlingException) {
|
|
723
738
|
enqueueError(value.throttlingException);
|
|
724
739
|
return;
|
|
@@ -838,9 +853,20 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
838
853
|
|
|
839
854
|
if (contentBlock != null) {
|
|
840
855
|
if (contentBlock.type === 'reasoning') {
|
|
856
|
+
const redactedPayload: BedrockReasoningMetadata | null =
|
|
857
|
+
contentBlock.redactedContent != null
|
|
858
|
+
? { redactedContent: contentBlock.redactedContent }
|
|
859
|
+
: null;
|
|
841
860
|
controller.enqueue({
|
|
842
861
|
type: 'reasoning-end',
|
|
843
862
|
id: String(blockIndex),
|
|
863
|
+
...(redactedPayload != null
|
|
864
|
+
? {
|
|
865
|
+
providerMetadata: {
|
|
866
|
+
bedrock: redactedPayload,
|
|
867
|
+
},
|
|
868
|
+
}
|
|
869
|
+
: {}),
|
|
844
870
|
});
|
|
845
871
|
} else if (contentBlock.type === 'text') {
|
|
846
872
|
controller.enqueue({
|
|
@@ -947,6 +973,27 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
947
973
|
} satisfies BedrockReasoningMetadata,
|
|
948
974
|
},
|
|
949
975
|
});
|
|
976
|
+
} else if (
|
|
977
|
+
'redactedContent' in reasoningContent &&
|
|
978
|
+
reasoningContent.redactedContent
|
|
979
|
+
) {
|
|
980
|
+
if (contentBlocks[blockIndex] == null) {
|
|
981
|
+
contentBlocks[blockIndex] = { type: 'reasoning' };
|
|
982
|
+
controller.enqueue({
|
|
983
|
+
type: 'reasoning-start',
|
|
984
|
+
id: String(blockIndex),
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
989
|
+
if (contentBlock.type === 'reasoning') {
|
|
990
|
+
// accumulate and attach once via reasoning-end: the merged
|
|
991
|
+
// provider metadata of a reasoning part is last-write-wins,
|
|
992
|
+
// so per-delta metadata would drop earlier chunks
|
|
993
|
+
contentBlock.redactedContent =
|
|
994
|
+
(contentBlock.redactedContent ?? '') +
|
|
995
|
+
reasoningContent.redactedContent;
|
|
996
|
+
}
|
|
950
997
|
}
|
|
951
998
|
}
|
|
952
999
|
|
|
@@ -1160,6 +1207,13 @@ const BedrockResponseSchema = z.object({
|
|
|
1160
1207
|
z.object({
|
|
1161
1208
|
redactedReasoning: BedrockRedactedReasoningSchema,
|
|
1162
1209
|
}),
|
|
1210
|
+
// `redactedContent` is a member of the documented
|
|
1211
|
+
// ReasoningContentBlock union. OpenAI models on Bedrock
|
|
1212
|
+
// (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
|
|
1213
|
+
// reasoning in this shape.
|
|
1214
|
+
z.object({
|
|
1215
|
+
redactedContent: z.string(),
|
|
1216
|
+
}),
|
|
1163
1217
|
])
|
|
1164
1218
|
.nullish(),
|
|
1165
1219
|
}),
|
|
@@ -1206,6 +1260,12 @@ const BedrockStreamSchema = z.object({
|
|
|
1206
1260
|
z.object({
|
|
1207
1261
|
reasoningContent: z.object({ data: z.string() }),
|
|
1208
1262
|
}),
|
|
1263
|
+
// `redactedContent` is a member of the documented
|
|
1264
|
+
// ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
|
|
1265
|
+
// their encrypted reasoning in this shape.
|
|
1266
|
+
z.object({
|
|
1267
|
+
reasoningContent: z.object({ redactedContent: z.string() }),
|
|
1268
|
+
}),
|
|
1209
1269
|
])
|
|
1210
1270
|
.nullish(),
|
|
1211
1271
|
})
|
|
@@ -1252,6 +1312,7 @@ const BedrockStreamSchema = z.object({
|
|
|
1252
1312
|
})
|
|
1253
1313
|
.nullish(),
|
|
1254
1314
|
modelStreamErrorException: z.record(z.string(), z.unknown()).nullish(),
|
|
1315
|
+
serviceUnavailableException: z.record(z.string(), z.unknown()).nullish(),
|
|
1255
1316
|
throttlingException: z.record(z.string(), z.unknown()).nullish(),
|
|
1256
1317
|
validationException: z.record(z.string(), z.unknown()).nullish(),
|
|
1257
1318
|
});
|
|
@@ -3,7 +3,8 @@ import { toUtf8, fromUtf8 } from '@smithy/util-utf8';
|
|
|
3
3
|
|
|
4
4
|
export interface DecodedEvent {
|
|
5
5
|
messageType: string;
|
|
6
|
-
eventType
|
|
6
|
+
eventType?: string;
|
|
7
|
+
exceptionType?: string;
|
|
7
8
|
data: string;
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -43,10 +44,18 @@ export function createBedrockEventStreamDecoder<T>(
|
|
|
43
44
|
buffer = buffer.slice(totalLength);
|
|
44
45
|
|
|
45
46
|
const messageType = decoded.headers[':message-type']?.value as string;
|
|
46
|
-
const eventType = decoded.headers[':event-type']?.value as
|
|
47
|
+
const eventType = decoded.headers[':event-type']?.value as
|
|
48
|
+
| string
|
|
49
|
+
| undefined;
|
|
50
|
+
const exceptionType = decoded.headers[':exception-type']?.value as
|
|
51
|
+
| string
|
|
52
|
+
| undefined;
|
|
47
53
|
const data = textDecoder.decode(decoded.body);
|
|
48
54
|
|
|
49
|
-
await processEvent(
|
|
55
|
+
await processEvent(
|
|
56
|
+
{ messageType, eventType, exceptionType, data },
|
|
57
|
+
controller,
|
|
58
|
+
);
|
|
50
59
|
}
|
|
51
60
|
},
|
|
52
61
|
flush() {
|
|
@@ -25,31 +25,40 @@ export const createBedrockEventStreamResponseHandler =
|
|
|
25
25
|
value: createBedrockEventStreamDecoder<ParseResult<T>>(
|
|
26
26
|
response.body,
|
|
27
27
|
async (event, controller) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const payloadType =
|
|
29
|
+
event.messageType === 'event'
|
|
30
|
+
? event.eventType
|
|
31
|
+
: event.messageType === 'exception'
|
|
32
|
+
? event.exceptionType
|
|
33
|
+
: undefined;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (payloadType == null) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const parsedDataResult = await safeParseJSON({ text: event.data });
|
|
40
|
+
if (!parsedDataResult.success) {
|
|
41
|
+
controller.enqueue(parsedDataResult);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
delete (parsedDataResult.value as any).p;
|
|
46
|
+
const wrappedData = {
|
|
47
|
+
[payloadType]: parsedDataResult.value,
|
|
48
|
+
};
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
const validatedWrappedData = await safeValidateTypes<T>({
|
|
51
|
+
value: wrappedData,
|
|
52
|
+
schema: chunkSchema,
|
|
53
|
+
});
|
|
54
|
+
if (!validatedWrappedData.success) {
|
|
55
|
+
controller.enqueue(validatedWrappedData);
|
|
56
|
+
} else {
|
|
57
|
+
controller.enqueue({
|
|
58
|
+
success: true,
|
|
59
|
+
value: validatedWrappedData.value,
|
|
60
|
+
rawValue: wrappedData,
|
|
43
61
|
});
|
|
44
|
-
if (!validatedWrappedData.success) {
|
|
45
|
-
controller.enqueue(validatedWrappedData);
|
|
46
|
-
} else {
|
|
47
|
-
controller.enqueue({
|
|
48
|
-
success: true,
|
|
49
|
-
value: validatedWrappedData.value,
|
|
50
|
-
rawValue: wrappedData,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
62
|
}
|
|
54
63
|
},
|
|
55
64
|
),
|
|
@@ -395,6 +395,12 @@ export async function convertToBedrockChatMessages(
|
|
|
395
395
|
},
|
|
396
396
|
},
|
|
397
397
|
});
|
|
398
|
+
} else if (reasoningMetadata?.redactedContent != null) {
|
|
399
|
+
bedrockContent.push({
|
|
400
|
+
reasoningContent: {
|
|
401
|
+
redactedContent: reasoningMetadata.redactedContent,
|
|
402
|
+
},
|
|
403
|
+
});
|
|
398
404
|
} else if (reasoningMetadata?.redactedData != null) {
|
|
399
405
|
bedrockContent.push({
|
|
400
406
|
reasoningContent: {
|