@ai-sdk/amazon-bedrock 3.0.0-canary.6 → 3.0.0-canary.8
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 +32 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +57 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5d142ab]
|
|
8
|
+
- Updated dependencies [b6b43c7]
|
|
9
|
+
- Updated dependencies [8aa9e20]
|
|
10
|
+
- Updated dependencies [3795467]
|
|
11
|
+
- @ai-sdk/provider-utils@3.0.0-canary.8
|
|
12
|
+
- @ai-sdk/provider@2.0.0-canary.7
|
|
13
|
+
|
|
14
|
+
## 3.0.0-canary.7
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- fa49207: feat(providers/openai-compatible): convert to providerOptions
|
|
19
|
+
- 26735b5: chore(embedding-model): add v2 interface
|
|
20
|
+
- Updated dependencies [26735b5]
|
|
21
|
+
- Updated dependencies [443d8ec]
|
|
22
|
+
- Updated dependencies [14c9410]
|
|
23
|
+
- Updated dependencies [d9c98f4]
|
|
24
|
+
- Updated dependencies [c4a2fec]
|
|
25
|
+
- Updated dependencies [0054544]
|
|
26
|
+
- Updated dependencies [9e9c809]
|
|
27
|
+
- Updated dependencies [32831c6]
|
|
28
|
+
- Updated dependencies [d0f9495]
|
|
29
|
+
- Updated dependencies [fd65bc6]
|
|
30
|
+
- Updated dependencies [393138b]
|
|
31
|
+
- Updated dependencies [7182d14]
|
|
32
|
+
- @ai-sdk/provider@2.0.0-canary.6
|
|
33
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
|
34
|
+
|
|
3
35
|
## 3.0.0-canary.6
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2,
|
|
1
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2, ImageModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -73,6 +73,7 @@ interface AmazonBedrockProviderSettings {
|
|
|
73
73
|
region?: string;
|
|
74
74
|
/**
|
|
75
75
|
The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
76
|
+
`AWS_ACCESS_KEY_ID` environment variable.
|
|
76
77
|
*/
|
|
77
78
|
accessKeyId?: string;
|
|
78
79
|
/**
|
|
@@ -110,7 +111,7 @@ interface AmazonBedrockProviderSettings {
|
|
|
110
111
|
interface AmazonBedrockProvider extends ProviderV2 {
|
|
111
112
|
(modelId: BedrockChatModelId): LanguageModelV2;
|
|
112
113
|
languageModel(modelId: BedrockChatModelId): LanguageModelV2;
|
|
113
|
-
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings):
|
|
114
|
+
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV2<string>;
|
|
114
115
|
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
115
116
|
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
116
117
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2,
|
|
1
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2, ImageModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -73,6 +73,7 @@ interface AmazonBedrockProviderSettings {
|
|
|
73
73
|
region?: string;
|
|
74
74
|
/**
|
|
75
75
|
The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
76
|
+
`AWS_ACCESS_KEY_ID` environment variable.
|
|
76
77
|
*/
|
|
77
78
|
accessKeyId?: string;
|
|
78
79
|
/**
|
|
@@ -110,7 +111,7 @@ interface AmazonBedrockProviderSettings {
|
|
|
110
111
|
interface AmazonBedrockProvider extends ProviderV2 {
|
|
111
112
|
(modelId: BedrockChatModelId): LanguageModelV2;
|
|
112
113
|
languageModel(modelId: BedrockChatModelId): LanguageModelV2;
|
|
113
|
-
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings):
|
|
114
|
+
embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV2<string>;
|
|
114
115
|
image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
115
116
|
imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
|
|
116
117
|
}
|
package/dist/index.js
CHANGED
|
@@ -613,7 +613,7 @@ var BedrockChatLanguageModel = class {
|
|
|
613
613
|
};
|
|
614
614
|
}
|
|
615
615
|
async doGenerate(options) {
|
|
616
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
616
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
617
617
|
const { command: args, warnings } = this.getArgs(options);
|
|
618
618
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
619
619
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
@@ -636,63 +636,68 @@ var BedrockChatLanguageModel = class {
|
|
|
636
636
|
abortSignal: options.abortSignal,
|
|
637
637
|
fetch: this.config.fetch
|
|
638
638
|
});
|
|
639
|
+
const content = [];
|
|
640
|
+
for (const part of response.output.message.content) {
|
|
641
|
+
if (part.text) {
|
|
642
|
+
content.push({ type: "text", text: part.text });
|
|
643
|
+
}
|
|
644
|
+
if (part.reasoningContent) {
|
|
645
|
+
if ("reasoningText" in part.reasoningContent) {
|
|
646
|
+
content.push({
|
|
647
|
+
type: "reasoning",
|
|
648
|
+
reasoningType: "text",
|
|
649
|
+
text: part.reasoningContent.reasoningText.text
|
|
650
|
+
});
|
|
651
|
+
if (part.reasoningContent.reasoningText.signature) {
|
|
652
|
+
content.push({
|
|
653
|
+
type: "reasoning",
|
|
654
|
+
reasoningType: "signature",
|
|
655
|
+
signature: part.reasoningContent.reasoningText.signature
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
659
|
+
content.push({
|
|
660
|
+
type: "reasoning",
|
|
661
|
+
reasoningType: "redacted",
|
|
662
|
+
data: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
if (part.toolUse) {
|
|
667
|
+
content.push({
|
|
668
|
+
type: "tool-call",
|
|
669
|
+
toolCallType: "function",
|
|
670
|
+
toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
|
|
671
|
+
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
672
|
+
args: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
639
676
|
const providerMetadata = response.trace || response.usage ? {
|
|
640
677
|
bedrock: {
|
|
641
678
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
642
679
|
...response.usage && {
|
|
643
680
|
usage: {
|
|
644
|
-
cacheReadInputTokens: (
|
|
645
|
-
cacheWriteInputTokens: (
|
|
681
|
+
cacheReadInputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.cacheReadInputTokens) != null ? _i : Number.NaN,
|
|
682
|
+
cacheWriteInputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null ? _k : Number.NaN
|
|
646
683
|
}
|
|
647
684
|
}
|
|
648
685
|
}
|
|
649
686
|
} : void 0;
|
|
650
|
-
const reasoning = response.output.message.content.filter((content) => content.reasoningContent).map((content) => {
|
|
651
|
-
var _a2;
|
|
652
|
-
if (content.reasoningContent && "reasoningText" in content.reasoningContent) {
|
|
653
|
-
return {
|
|
654
|
-
type: "text",
|
|
655
|
-
text: content.reasoningContent.reasoningText.text,
|
|
656
|
-
...content.reasoningContent.reasoningText.signature && {
|
|
657
|
-
signature: content.reasoningContent.reasoningText.signature
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
} else if (content.reasoningContent && "redactedReasoning" in content.reasoningContent) {
|
|
661
|
-
return {
|
|
662
|
-
type: "redacted",
|
|
663
|
-
data: (_a2 = content.reasoningContent.redactedReasoning.data) != null ? _a2 : ""
|
|
664
|
-
};
|
|
665
|
-
} else {
|
|
666
|
-
return void 0;
|
|
667
|
-
}
|
|
668
|
-
}).filter((item) => item !== void 0);
|
|
669
687
|
return {
|
|
670
|
-
|
|
671
|
-
var _a2;
|
|
672
|
-
return (_a2 = part.text) != null ? _a2 : "";
|
|
673
|
-
}).join("")) != null ? _h : void 0,
|
|
674
|
-
toolCalls: (_l = (_k = (_j = (_i = response.output) == null ? void 0 : _i.message) == null ? void 0 : _j.content) == null ? void 0 : _k.filter((part) => !!part.toolUse)) == null ? void 0 : _l.map((part) => {
|
|
675
|
-
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
676
|
-
return {
|
|
677
|
-
toolCallType: "function",
|
|
678
|
-
toolCallId: (_b2 = (_a2 = part.toolUse) == null ? void 0 : _a2.toolUseId) != null ? _b2 : this.config.generateId(),
|
|
679
|
-
toolName: (_d2 = (_c2 = part.toolUse) == null ? void 0 : _c2.name) != null ? _d2 : `tool-${this.config.generateId()}`,
|
|
680
|
-
args: JSON.stringify((_f2 = (_e2 = part.toolUse) == null ? void 0 : _e2.input) != null ? _f2 : "")
|
|
681
|
-
};
|
|
682
|
-
}),
|
|
688
|
+
content,
|
|
683
689
|
finishReason: mapBedrockFinishReason(
|
|
684
690
|
response.stopReason
|
|
685
691
|
),
|
|
686
692
|
usage: {
|
|
687
|
-
inputTokens: (
|
|
688
|
-
outputTokens: (
|
|
693
|
+
inputTokens: (_l = response.usage) == null ? void 0 : _l.inputTokens,
|
|
694
|
+
outputTokens: (_m = response.usage) == null ? void 0 : _m.outputTokens
|
|
689
695
|
},
|
|
690
696
|
response: {
|
|
691
697
|
// TODO add id, timestamp, etc
|
|
692
698
|
headers: responseHeaders
|
|
693
699
|
},
|
|
694
700
|
warnings,
|
|
695
|
-
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
696
701
|
...providerMetadata && { providerMetadata }
|
|
697
702
|
};
|
|
698
703
|
}
|
|
@@ -724,6 +729,9 @@ var BedrockChatLanguageModel = class {
|
|
|
724
729
|
return {
|
|
725
730
|
stream: response.pipeThrough(
|
|
726
731
|
new TransformStream({
|
|
732
|
+
start(controller) {
|
|
733
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
734
|
+
},
|
|
727
735
|
transform(chunk, controller) {
|
|
728
736
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
729
737
|
function enqueueError(bedrockError) {
|
|
@@ -779,8 +787,8 @@ var BedrockChatLanguageModel = class {
|
|
|
779
787
|
}
|
|
780
788
|
if (((_k = value.contentBlockDelta) == null ? void 0 : _k.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
781
789
|
controller.enqueue({
|
|
782
|
-
type: "text
|
|
783
|
-
|
|
790
|
+
type: "text",
|
|
791
|
+
text: value.contentBlockDelta.delta.text
|
|
784
792
|
});
|
|
785
793
|
}
|
|
786
794
|
if (((_l = value.contentBlockDelta) == null ? void 0 : _l.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
@@ -788,16 +796,19 @@ var BedrockChatLanguageModel = class {
|
|
|
788
796
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
789
797
|
controller.enqueue({
|
|
790
798
|
type: "reasoning",
|
|
791
|
-
|
|
799
|
+
reasoningType: "text",
|
|
800
|
+
text: reasoningContent.text
|
|
792
801
|
});
|
|
793
802
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
794
803
|
controller.enqueue({
|
|
795
|
-
type: "reasoning
|
|
804
|
+
type: "reasoning",
|
|
805
|
+
reasoningType: "signature",
|
|
796
806
|
signature: reasoningContent.signature
|
|
797
807
|
});
|
|
798
808
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
799
809
|
controller.enqueue({
|
|
800
|
-
type: "
|
|
810
|
+
type: "reasoning",
|
|
811
|
+
reasoningType: "redacted",
|
|
801
812
|
data: reasoningContent.data
|
|
802
813
|
});
|
|
803
814
|
}
|
|
@@ -850,8 +861,8 @@ var BedrockChatLanguageModel = class {
|
|
|
850
861
|
}
|
|
851
862
|
})
|
|
852
863
|
),
|
|
853
|
-
|
|
854
|
-
|
|
864
|
+
// TODO request?
|
|
865
|
+
response: { headers: responseHeaders }
|
|
855
866
|
};
|
|
856
867
|
}
|
|
857
868
|
getUrl(modelId) {
|
|
@@ -963,7 +974,7 @@ var BedrockEmbeddingModel = class {
|
|
|
963
974
|
this.modelId = modelId;
|
|
964
975
|
this.settings = settings;
|
|
965
976
|
this.config = config;
|
|
966
|
-
this.specificationVersion = "
|
|
977
|
+
this.specificationVersion = "v2";
|
|
967
978
|
this.provider = "amazon-bedrock";
|
|
968
979
|
this.maxEmbeddingsPerCall = void 0;
|
|
969
980
|
this.supportsParallelCalls = true;
|