@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9301f86: refactor (image-model): rename `ImageModelV1` to `ImageModelV2`
|
|
8
|
+
- Updated dependencies [66962ed]
|
|
9
|
+
- Updated dependencies [9301f86]
|
|
10
|
+
- Updated dependencies [a3f768e]
|
|
11
|
+
- @ai-sdk/provider-utils@3.0.0-canary.11
|
|
12
|
+
- @ai-sdk/provider@2.0.0-canary.10
|
|
13
|
+
|
|
3
14
|
## 3.0.0-canary.10
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2, EmbeddingModelV2,
|
|
1
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -100,8 +100,8 @@ interface AmazonBedrockProvider extends ProviderV2 {
|
|
|
100
100
|
(modelId: BedrockChatModelId): LanguageModelV2;
|
|
101
101
|
languageModel(modelId: BedrockChatModelId): LanguageModelV2;
|
|
102
102
|
embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV2<string>;
|
|
103
|
-
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings):
|
|
104
|
-
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings):
|
|
103
|
+
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV2;
|
|
104
|
+
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV2;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
Create an Amazon Bedrock provider instance.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2, EmbeddingModelV2,
|
|
1
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -100,8 +100,8 @@ interface AmazonBedrockProvider extends ProviderV2 {
|
|
|
100
100
|
(modelId: BedrockChatModelId): LanguageModelV2;
|
|
101
101
|
languageModel(modelId: BedrockChatModelId): LanguageModelV2;
|
|
102
102
|
embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV2<string>;
|
|
103
|
-
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings):
|
|
104
|
-
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings):
|
|
103
|
+
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV2;
|
|
104
|
+
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV2;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
Create an Amazon Bedrock provider instance.
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
88
88
|
responseHeaders,
|
|
89
89
|
value: response.body.pipeThrough(
|
|
90
90
|
new TransformStream({
|
|
91
|
-
transform(chunk, controller) {
|
|
91
|
+
async transform(chunk, controller) {
|
|
92
92
|
var _a, _b;
|
|
93
93
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
94
94
|
newBuffer.set(buffer);
|
|
@@ -109,7 +109,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
109
109
|
buffer = buffer.slice(totalLength);
|
|
110
110
|
if (((_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value) === "event") {
|
|
111
111
|
const data = textDecoder.decode(decoded.body);
|
|
112
|
-
const parsedDataResult = (0, import_provider_utils.safeParseJSON)({ text: data });
|
|
112
|
+
const parsedDataResult = await (0, import_provider_utils.safeParseJSON)({ text: data });
|
|
113
113
|
if (!parsedDataResult.success) {
|
|
114
114
|
controller.enqueue(parsedDataResult);
|
|
115
115
|
break;
|
|
@@ -118,7 +118,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
118
118
|
let wrappedData = {
|
|
119
119
|
[(_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value]: parsedDataResult.value
|
|
120
120
|
};
|
|
121
|
-
const validatedWrappedData = (0, import_provider_utils.safeValidateTypes)({
|
|
121
|
+
const validatedWrappedData = await (0, import_provider_utils.safeValidateTypes)({
|
|
122
122
|
value: wrappedData,
|
|
123
123
|
schema: chunkSchema
|
|
124
124
|
});
|
|
@@ -220,7 +220,7 @@ function getCachePoint(providerMetadata) {
|
|
|
220
220
|
var _a;
|
|
221
221
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
222
222
|
}
|
|
223
|
-
function convertToBedrockChatMessages(prompt) {
|
|
223
|
+
async function convertToBedrockChatMessages(prompt) {
|
|
224
224
|
var _a, _b, _c, _d;
|
|
225
225
|
const blocks = groupIntoBlocks(prompt);
|
|
226
226
|
let system = [];
|
|
@@ -369,32 +369,39 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
369
369
|
break;
|
|
370
370
|
}
|
|
371
371
|
case "reasoning": {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// because Bedrock does not allow trailing whitespace
|
|
377
|
-
// in pre-filled assistant responses
|
|
378
|
-
text: trimIfLast(
|
|
379
|
-
isLastBlock,
|
|
380
|
-
isLastMessage,
|
|
381
|
-
isLastContentPart,
|
|
382
|
-
part.text
|
|
383
|
-
),
|
|
384
|
-
signature: part.signature
|
|
385
|
-
}
|
|
386
|
-
}
|
|
372
|
+
const reasoningMetadata = await (0, import_provider_utils2.parseProviderOptions)({
|
|
373
|
+
provider: "bedrock",
|
|
374
|
+
providerOptions: part.providerOptions,
|
|
375
|
+
schema: bedrockReasoningMetadataSchema
|
|
387
376
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
377
|
+
if (reasoningMetadata != null) {
|
|
378
|
+
if (reasoningMetadata.signature != null) {
|
|
379
|
+
bedrockContent.push({
|
|
380
|
+
reasoningContent: {
|
|
381
|
+
reasoningText: {
|
|
382
|
+
// trim the last text part if it's the last message in the block
|
|
383
|
+
// because Bedrock does not allow trailing whitespace
|
|
384
|
+
// in pre-filled assistant responses
|
|
385
|
+
text: trimIfLast(
|
|
386
|
+
isLastBlock,
|
|
387
|
+
isLastMessage,
|
|
388
|
+
isLastContentPart,
|
|
389
|
+
part.text
|
|
390
|
+
),
|
|
391
|
+
signature: reasoningMetadata.signature
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
396
|
+
bedrockContent.push({
|
|
397
|
+
reasoningContent: {
|
|
398
|
+
redactedReasoning: {
|
|
399
|
+
data: reasoningMetadata.redactedData
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
});
|
|
396
403
|
}
|
|
397
|
-
}
|
|
404
|
+
}
|
|
398
405
|
break;
|
|
399
406
|
}
|
|
400
407
|
case "tool-call": {
|
|
@@ -503,7 +510,7 @@ var BedrockChatLanguageModel = class {
|
|
|
503
510
|
this.specificationVersion = "v2";
|
|
504
511
|
this.provider = "amazon-bedrock";
|
|
505
512
|
}
|
|
506
|
-
getArgs({
|
|
513
|
+
async getArgs({
|
|
507
514
|
prompt,
|
|
508
515
|
maxOutputTokens,
|
|
509
516
|
temperature,
|
|
@@ -519,7 +526,7 @@ var BedrockChatLanguageModel = class {
|
|
|
519
526
|
providerOptions
|
|
520
527
|
}) {
|
|
521
528
|
var _a, _b, _c, _d, _e;
|
|
522
|
-
const bedrockOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
|
|
529
|
+
const bedrockOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
523
530
|
provider: "bedrock",
|
|
524
531
|
providerOptions,
|
|
525
532
|
schema: bedrockProviderOptions
|
|
@@ -556,7 +563,7 @@ var BedrockChatLanguageModel = class {
|
|
|
556
563
|
details: "JSON response format is not supported."
|
|
557
564
|
});
|
|
558
565
|
}
|
|
559
|
-
const { system, messages } = convertToBedrockChatMessages(prompt);
|
|
566
|
+
const { system, messages } = await convertToBedrockChatMessages(prompt);
|
|
560
567
|
const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
|
|
561
568
|
const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
|
|
562
569
|
const inferenceConfig = {
|
|
@@ -617,7 +624,7 @@ var BedrockChatLanguageModel = class {
|
|
|
617
624
|
}
|
|
618
625
|
async doGenerate(options) {
|
|
619
626
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
620
|
-
const { command: args, warnings } = this.getArgs(options);
|
|
627
|
+
const { command: args, warnings } = await this.getArgs(options);
|
|
621
628
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
622
629
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
623
630
|
url,
|
|
@@ -646,23 +653,27 @@ var BedrockChatLanguageModel = class {
|
|
|
646
653
|
}
|
|
647
654
|
if (part.reasoningContent) {
|
|
648
655
|
if ("reasoningText" in part.reasoningContent) {
|
|
649
|
-
|
|
656
|
+
const reasoning = {
|
|
650
657
|
type: "reasoning",
|
|
651
|
-
reasoningType: "text",
|
|
652
658
|
text: part.reasoningContent.reasoningText.text
|
|
653
|
-
}
|
|
659
|
+
};
|
|
654
660
|
if (part.reasoningContent.reasoningText.signature) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
}
|
|
661
|
+
reasoning.providerMetadata = {
|
|
662
|
+
bedrock: {
|
|
663
|
+
signature: part.reasoningContent.reasoningText.signature
|
|
664
|
+
}
|
|
665
|
+
};
|
|
660
666
|
}
|
|
667
|
+
content.push(reasoning);
|
|
661
668
|
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
662
669
|
content.push({
|
|
663
670
|
type: "reasoning",
|
|
664
|
-
|
|
665
|
-
|
|
671
|
+
text: "",
|
|
672
|
+
providerMetadata: {
|
|
673
|
+
bedrock: {
|
|
674
|
+
redactedData: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
|
|
675
|
+
}
|
|
676
|
+
}
|
|
666
677
|
});
|
|
667
678
|
}
|
|
668
679
|
}
|
|
@@ -705,7 +716,7 @@ var BedrockChatLanguageModel = class {
|
|
|
705
716
|
};
|
|
706
717
|
}
|
|
707
718
|
async doStream(options) {
|
|
708
|
-
const { command: args, warnings } = this.getArgs(options);
|
|
719
|
+
const { command: args, warnings } = await this.getArgs(options);
|
|
709
720
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
710
721
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
711
722
|
url,
|
|
@@ -799,21 +810,30 @@ var BedrockChatLanguageModel = class {
|
|
|
799
810
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
800
811
|
controller.enqueue({
|
|
801
812
|
type: "reasoning",
|
|
802
|
-
reasoningType: "text",
|
|
803
813
|
text: reasoningContent.text
|
|
804
814
|
});
|
|
805
815
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
806
816
|
controller.enqueue({
|
|
807
817
|
type: "reasoning",
|
|
808
|
-
|
|
809
|
-
|
|
818
|
+
text: "",
|
|
819
|
+
providerMetadata: {
|
|
820
|
+
bedrock: {
|
|
821
|
+
signature: reasoningContent.signature
|
|
822
|
+
}
|
|
823
|
+
}
|
|
810
824
|
});
|
|
825
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
811
826
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
812
827
|
controller.enqueue({
|
|
813
828
|
type: "reasoning",
|
|
814
|
-
|
|
815
|
-
|
|
829
|
+
text: "",
|
|
830
|
+
providerMetadata: {
|
|
831
|
+
bedrock: {
|
|
832
|
+
redactedData: reasoningContent.data
|
|
833
|
+
}
|
|
834
|
+
}
|
|
816
835
|
});
|
|
836
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
817
837
|
}
|
|
818
838
|
}
|
|
819
839
|
const contentBlockStart = value.contentBlockStart;
|
|
@@ -968,6 +988,10 @@ var BedrockStreamSchema = import_zod3.z.object({
|
|
|
968
988
|
throttlingException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
969
989
|
validationException: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
970
990
|
});
|
|
991
|
+
var bedrockReasoningMetadataSchema = import_zod3.z.object({
|
|
992
|
+
signature: import_zod3.z.string().optional(),
|
|
993
|
+
redactedData: import_zod3.z.string().optional()
|
|
994
|
+
});
|
|
971
995
|
|
|
972
996
|
// src/bedrock-embedding-model.ts
|
|
973
997
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
@@ -1009,7 +1033,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1009
1033
|
providerOptions
|
|
1010
1034
|
}) {
|
|
1011
1035
|
var _a;
|
|
1012
|
-
const bedrockOptions = (_a = (0, import_provider_utils4.parseProviderOptions)({
|
|
1036
|
+
const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
1013
1037
|
provider: "bedrock",
|
|
1014
1038
|
providerOptions,
|
|
1015
1039
|
schema: bedrockEmbeddingProviderOptions
|