@ai-sdk/amazon-bedrock 3.0.0-canary.10 → 3.0.0-canary.11
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 +11 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +73 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
combineHeaders,
|
|
12
12
|
createJsonErrorResponseHandler,
|
|
13
13
|
createJsonResponseHandler,
|
|
14
|
-
parseProviderOptions,
|
|
14
|
+
parseProviderOptions as parseProviderOptions2,
|
|
15
15
|
postJsonToApi,
|
|
16
16
|
resolve
|
|
17
17
|
} from "@ai-sdk/provider-utils";
|
|
@@ -77,7 +77,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
77
77
|
responseHeaders,
|
|
78
78
|
value: response.body.pipeThrough(
|
|
79
79
|
new TransformStream({
|
|
80
|
-
transform(chunk, controller) {
|
|
80
|
+
async transform(chunk, controller) {
|
|
81
81
|
var _a, _b;
|
|
82
82
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
83
83
|
newBuffer.set(buffer);
|
|
@@ -98,7 +98,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
98
98
|
buffer = buffer.slice(totalLength);
|
|
99
99
|
if (((_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value) === "event") {
|
|
100
100
|
const data = textDecoder.decode(decoded.body);
|
|
101
|
-
const parsedDataResult = safeParseJSON({ text: data });
|
|
101
|
+
const parsedDataResult = await safeParseJSON({ text: data });
|
|
102
102
|
if (!parsedDataResult.success) {
|
|
103
103
|
controller.enqueue(parsedDataResult);
|
|
104
104
|
break;
|
|
@@ -107,7 +107,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
107
107
|
let wrappedData = {
|
|
108
108
|
[(_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value]: parsedDataResult.value
|
|
109
109
|
};
|
|
110
|
-
const validatedWrappedData = safeValidateTypes({
|
|
110
|
+
const validatedWrappedData = await safeValidateTypes({
|
|
111
111
|
value: wrappedData,
|
|
112
112
|
schema: chunkSchema
|
|
113
113
|
});
|
|
@@ -207,13 +207,17 @@ function prepareTools({
|
|
|
207
207
|
import {
|
|
208
208
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
209
209
|
} from "@ai-sdk/provider";
|
|
210
|
-
import {
|
|
210
|
+
import {
|
|
211
|
+
convertToBase64,
|
|
212
|
+
createIdGenerator,
|
|
213
|
+
parseProviderOptions
|
|
214
|
+
} from "@ai-sdk/provider-utils";
|
|
211
215
|
var generateFileId = createIdGenerator({ prefix: "file", size: 16 });
|
|
212
216
|
function getCachePoint(providerMetadata) {
|
|
213
217
|
var _a;
|
|
214
218
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
215
219
|
}
|
|
216
|
-
function convertToBedrockChatMessages(prompt) {
|
|
220
|
+
async function convertToBedrockChatMessages(prompt) {
|
|
217
221
|
var _a, _b, _c, _d;
|
|
218
222
|
const blocks = groupIntoBlocks(prompt);
|
|
219
223
|
let system = [];
|
|
@@ -362,32 +366,39 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
362
366
|
break;
|
|
363
367
|
}
|
|
364
368
|
case "reasoning": {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
// because Bedrock does not allow trailing whitespace
|
|
370
|
-
// in pre-filled assistant responses
|
|
371
|
-
text: trimIfLast(
|
|
372
|
-
isLastBlock,
|
|
373
|
-
isLastMessage,
|
|
374
|
-
isLastContentPart,
|
|
375
|
-
part.text
|
|
376
|
-
),
|
|
377
|
-
signature: part.signature
|
|
378
|
-
}
|
|
379
|
-
}
|
|
369
|
+
const reasoningMetadata = await parseProviderOptions({
|
|
370
|
+
provider: "bedrock",
|
|
371
|
+
providerOptions: part.providerOptions,
|
|
372
|
+
schema: bedrockReasoningMetadataSchema
|
|
380
373
|
});
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
374
|
+
if (reasoningMetadata != null) {
|
|
375
|
+
if (reasoningMetadata.signature != null) {
|
|
376
|
+
bedrockContent.push({
|
|
377
|
+
reasoningContent: {
|
|
378
|
+
reasoningText: {
|
|
379
|
+
// trim the last text part if it's the last message in the block
|
|
380
|
+
// because Bedrock does not allow trailing whitespace
|
|
381
|
+
// in pre-filled assistant responses
|
|
382
|
+
text: trimIfLast(
|
|
383
|
+
isLastBlock,
|
|
384
|
+
isLastMessage,
|
|
385
|
+
isLastContentPart,
|
|
386
|
+
part.text
|
|
387
|
+
),
|
|
388
|
+
signature: reasoningMetadata.signature
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
393
|
+
bedrockContent.push({
|
|
394
|
+
reasoningContent: {
|
|
395
|
+
redactedReasoning: {
|
|
396
|
+
data: reasoningMetadata.redactedData
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
389
400
|
}
|
|
390
|
-
}
|
|
401
|
+
}
|
|
391
402
|
break;
|
|
392
403
|
}
|
|
393
404
|
case "tool-call": {
|
|
@@ -496,7 +507,7 @@ var BedrockChatLanguageModel = class {
|
|
|
496
507
|
this.specificationVersion = "v2";
|
|
497
508
|
this.provider = "amazon-bedrock";
|
|
498
509
|
}
|
|
499
|
-
getArgs({
|
|
510
|
+
async getArgs({
|
|
500
511
|
prompt,
|
|
501
512
|
maxOutputTokens,
|
|
502
513
|
temperature,
|
|
@@ -512,7 +523,7 @@ var BedrockChatLanguageModel = class {
|
|
|
512
523
|
providerOptions
|
|
513
524
|
}) {
|
|
514
525
|
var _a, _b, _c, _d, _e;
|
|
515
|
-
const bedrockOptions = (_a =
|
|
526
|
+
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
516
527
|
provider: "bedrock",
|
|
517
528
|
providerOptions,
|
|
518
529
|
schema: bedrockProviderOptions
|
|
@@ -549,7 +560,7 @@ var BedrockChatLanguageModel = class {
|
|
|
549
560
|
details: "JSON response format is not supported."
|
|
550
561
|
});
|
|
551
562
|
}
|
|
552
|
-
const { system, messages } = convertToBedrockChatMessages(prompt);
|
|
563
|
+
const { system, messages } = await convertToBedrockChatMessages(prompt);
|
|
553
564
|
const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
|
|
554
565
|
const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
|
|
555
566
|
const inferenceConfig = {
|
|
@@ -610,7 +621,7 @@ var BedrockChatLanguageModel = class {
|
|
|
610
621
|
}
|
|
611
622
|
async doGenerate(options) {
|
|
612
623
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
613
|
-
const { command: args, warnings } = this.getArgs(options);
|
|
624
|
+
const { command: args, warnings } = await this.getArgs(options);
|
|
614
625
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
615
626
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
616
627
|
url,
|
|
@@ -639,23 +650,27 @@ var BedrockChatLanguageModel = class {
|
|
|
639
650
|
}
|
|
640
651
|
if (part.reasoningContent) {
|
|
641
652
|
if ("reasoningText" in part.reasoningContent) {
|
|
642
|
-
|
|
653
|
+
const reasoning = {
|
|
643
654
|
type: "reasoning",
|
|
644
|
-
reasoningType: "text",
|
|
645
655
|
text: part.reasoningContent.reasoningText.text
|
|
646
|
-
}
|
|
656
|
+
};
|
|
647
657
|
if (part.reasoningContent.reasoningText.signature) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
658
|
+
reasoning.providerMetadata = {
|
|
659
|
+
bedrock: {
|
|
660
|
+
signature: part.reasoningContent.reasoningText.signature
|
|
661
|
+
}
|
|
662
|
+
};
|
|
653
663
|
}
|
|
664
|
+
content.push(reasoning);
|
|
654
665
|
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
655
666
|
content.push({
|
|
656
667
|
type: "reasoning",
|
|
657
|
-
|
|
658
|
-
|
|
668
|
+
text: "",
|
|
669
|
+
providerMetadata: {
|
|
670
|
+
bedrock: {
|
|
671
|
+
redactedData: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
|
|
672
|
+
}
|
|
673
|
+
}
|
|
659
674
|
});
|
|
660
675
|
}
|
|
661
676
|
}
|
|
@@ -698,7 +713,7 @@ var BedrockChatLanguageModel = class {
|
|
|
698
713
|
};
|
|
699
714
|
}
|
|
700
715
|
async doStream(options) {
|
|
701
|
-
const { command: args, warnings } = this.getArgs(options);
|
|
716
|
+
const { command: args, warnings } = await this.getArgs(options);
|
|
702
717
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
703
718
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
704
719
|
url,
|
|
@@ -792,21 +807,30 @@ var BedrockChatLanguageModel = class {
|
|
|
792
807
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
793
808
|
controller.enqueue({
|
|
794
809
|
type: "reasoning",
|
|
795
|
-
reasoningType: "text",
|
|
796
810
|
text: reasoningContent.text
|
|
797
811
|
});
|
|
798
812
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
799
813
|
controller.enqueue({
|
|
800
814
|
type: "reasoning",
|
|
801
|
-
|
|
802
|
-
|
|
815
|
+
text: "",
|
|
816
|
+
providerMetadata: {
|
|
817
|
+
bedrock: {
|
|
818
|
+
signature: reasoningContent.signature
|
|
819
|
+
}
|
|
820
|
+
}
|
|
803
821
|
});
|
|
822
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
804
823
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
805
824
|
controller.enqueue({
|
|
806
825
|
type: "reasoning",
|
|
807
|
-
|
|
808
|
-
|
|
826
|
+
text: "",
|
|
827
|
+
providerMetadata: {
|
|
828
|
+
bedrock: {
|
|
829
|
+
redactedData: reasoningContent.data
|
|
830
|
+
}
|
|
831
|
+
}
|
|
809
832
|
});
|
|
833
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
810
834
|
}
|
|
811
835
|
}
|
|
812
836
|
const contentBlockStart = value.contentBlockStart;
|
|
@@ -961,13 +985,17 @@ var BedrockStreamSchema = z3.object({
|
|
|
961
985
|
throttlingException: z3.record(z3.unknown()).nullish(),
|
|
962
986
|
validationException: z3.record(z3.unknown()).nullish()
|
|
963
987
|
});
|
|
988
|
+
var bedrockReasoningMetadataSchema = z3.object({
|
|
989
|
+
signature: z3.string().optional(),
|
|
990
|
+
redactedData: z3.string().optional()
|
|
991
|
+
});
|
|
964
992
|
|
|
965
993
|
// src/bedrock-embedding-model.ts
|
|
966
994
|
import {
|
|
967
995
|
combineHeaders as combineHeaders2,
|
|
968
996
|
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
969
997
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
970
|
-
parseProviderOptions as
|
|
998
|
+
parseProviderOptions as parseProviderOptions3,
|
|
971
999
|
postJsonToApi as postJsonToApi2,
|
|
972
1000
|
resolve as resolve2
|
|
973
1001
|
} from "@ai-sdk/provider-utils";
|
|
@@ -1009,7 +1037,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1009
1037
|
providerOptions
|
|
1010
1038
|
}) {
|
|
1011
1039
|
var _a;
|
|
1012
|
-
const bedrockOptions = (_a =
|
|
1040
|
+
const bedrockOptions = (_a = await parseProviderOptions3({
|
|
1013
1041
|
provider: "bedrock",
|
|
1014
1042
|
providerOptions,
|
|
1015
1043
|
schema: bedrockEmbeddingProviderOptions
|