@ai-sdk/amazon-bedrock 3.0.0-canary.14 → 3.0.0-canary.16
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/README.md +2 -2
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +55 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [87b828f]
|
|
8
|
+
- @ai-sdk/provider-utils@3.0.0-canary.16
|
|
9
|
+
|
|
10
|
+
## 3.0.0-canary.15
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a8c8bd5: feat(embed-many): respect supportsParallelCalls & concurrency
|
|
15
|
+
- 6f231db: fix(providers): always use optional instead of mix of nullish for providerOptions
|
|
16
|
+
- Updated dependencies [a571d6e]
|
|
17
|
+
- Updated dependencies [a8c8bd5]
|
|
18
|
+
- Updated dependencies [7979f7f]
|
|
19
|
+
- Updated dependencies [41fa418]
|
|
20
|
+
- @ai-sdk/provider-utils@3.0.0-canary.15
|
|
21
|
+
- @ai-sdk/provider@2.0.0-canary.14
|
|
22
|
+
|
|
3
23
|
## 3.0.0-canary.14
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AI SDK - Amazon Bedrock Provider
|
|
2
2
|
|
|
3
|
-
The **[Amazon Bedrock provider](https://sdk.
|
|
3
|
+
The **[Amazon Bedrock provider](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock)** for the [AI SDK](https://ai-sdk.dev/docs)
|
|
4
4
|
contains language model support for the Amazon Bedrock [converse API](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html).
|
|
5
5
|
|
|
6
6
|
## Setup
|
|
@@ -33,4 +33,4 @@ const { text } = await generateText({
|
|
|
33
33
|
|
|
34
34
|
## Documentation
|
|
35
35
|
|
|
36
|
-
Please check out the **[Amazon Bedrock provider documentation](https://sdk.
|
|
36
|
+
Please check out the **[Amazon Bedrock provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock)** for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -10,28 +10,28 @@ declare const bedrockProviderOptions: z.ZodObject<{
|
|
|
10
10
|
* supports in the inferenceConfig field
|
|
11
11
|
*/
|
|
12
12
|
additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
|
-
reasoningConfig: z.ZodOptional<z.
|
|
14
|
-
type: z.ZodOptional<z.
|
|
15
|
-
budgetTokens: z.ZodOptional<z.
|
|
13
|
+
reasoningConfig: z.ZodOptional<z.ZodObject<{
|
|
14
|
+
type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
|
|
15
|
+
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
|
-
type?: "enabled" | "disabled" |
|
|
18
|
-
budgetTokens?: number |
|
|
17
|
+
type?: "enabled" | "disabled" | undefined;
|
|
18
|
+
budgetTokens?: number | undefined;
|
|
19
19
|
}, {
|
|
20
|
-
type?: "enabled" | "disabled" |
|
|
21
|
-
budgetTokens?: number |
|
|
22
|
-
}
|
|
20
|
+
type?: "enabled" | "disabled" | undefined;
|
|
21
|
+
budgetTokens?: number | undefined;
|
|
22
|
+
}>>;
|
|
23
23
|
}, "strip", z.ZodTypeAny, {
|
|
24
24
|
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
25
25
|
reasoningConfig?: {
|
|
26
|
-
type?: "enabled" | "disabled" |
|
|
27
|
-
budgetTokens?: number |
|
|
28
|
-
} |
|
|
26
|
+
type?: "enabled" | "disabled" | undefined;
|
|
27
|
+
budgetTokens?: number | undefined;
|
|
28
|
+
} | undefined;
|
|
29
29
|
}, {
|
|
30
30
|
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
31
31
|
reasoningConfig?: {
|
|
32
|
-
type?: "enabled" | "disabled" |
|
|
33
|
-
budgetTokens?: number |
|
|
34
|
-
} |
|
|
32
|
+
type?: "enabled" | "disabled" | undefined;
|
|
33
|
+
budgetTokens?: number | undefined;
|
|
34
|
+
} | undefined;
|
|
35
35
|
}>;
|
|
36
36
|
type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
|
|
37
37
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,28 +10,28 @@ declare const bedrockProviderOptions: z.ZodObject<{
|
|
|
10
10
|
* supports in the inferenceConfig field
|
|
11
11
|
*/
|
|
12
12
|
additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
|
-
reasoningConfig: z.ZodOptional<z.
|
|
14
|
-
type: z.ZodOptional<z.
|
|
15
|
-
budgetTokens: z.ZodOptional<z.
|
|
13
|
+
reasoningConfig: z.ZodOptional<z.ZodObject<{
|
|
14
|
+
type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
|
|
15
|
+
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
|
-
type?: "enabled" | "disabled" |
|
|
18
|
-
budgetTokens?: number |
|
|
17
|
+
type?: "enabled" | "disabled" | undefined;
|
|
18
|
+
budgetTokens?: number | undefined;
|
|
19
19
|
}, {
|
|
20
|
-
type?: "enabled" | "disabled" |
|
|
21
|
-
budgetTokens?: number |
|
|
22
|
-
}
|
|
20
|
+
type?: "enabled" | "disabled" | undefined;
|
|
21
|
+
budgetTokens?: number | undefined;
|
|
22
|
+
}>>;
|
|
23
23
|
}, "strip", z.ZodTypeAny, {
|
|
24
24
|
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
25
25
|
reasoningConfig?: {
|
|
26
|
-
type?: "enabled" | "disabled" |
|
|
27
|
-
budgetTokens?: number |
|
|
28
|
-
} |
|
|
26
|
+
type?: "enabled" | "disabled" | undefined;
|
|
27
|
+
budgetTokens?: number | undefined;
|
|
28
|
+
} | undefined;
|
|
29
29
|
}, {
|
|
30
30
|
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
31
31
|
reasoningConfig?: {
|
|
32
|
-
type?: "enabled" | "disabled" |
|
|
33
|
-
budgetTokens?: number |
|
|
34
|
-
} |
|
|
32
|
+
type?: "enabled" | "disabled" | undefined;
|
|
33
|
+
budgetTokens?: number | undefined;
|
|
34
|
+
} | undefined;
|
|
35
35
|
}>;
|
|
36
36
|
type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
|
|
37
37
|
|
package/dist/index.js
CHANGED
|
@@ -59,9 +59,9 @@ var bedrockProviderOptions = import_zod.z.object({
|
|
|
59
59
|
*/
|
|
60
60
|
additionalModelRequestFields: import_zod.z.record(import_zod.z.any()).optional(),
|
|
61
61
|
reasoningConfig: import_zod.z.object({
|
|
62
|
-
type: import_zod.z.union([import_zod.z.literal("enabled"), import_zod.z.literal("disabled")]).
|
|
63
|
-
budgetTokens: import_zod.z.number().
|
|
64
|
-
}).
|
|
62
|
+
type: import_zod.z.union([import_zod.z.literal("enabled"), import_zod.z.literal("disabled")]).optional(),
|
|
63
|
+
budgetTokens: import_zod.z.number().optional()
|
|
64
|
+
}).optional()
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
// src/bedrock-error.ts
|
|
@@ -621,7 +621,7 @@ var BedrockChatLanguageModel = class {
|
|
|
621
621
|
};
|
|
622
622
|
}
|
|
623
623
|
async doGenerate(options) {
|
|
624
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
624
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
625
625
|
const { command: args, warnings } = await this.getArgs(options);
|
|
626
626
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
627
627
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
@@ -688,10 +688,9 @@ var BedrockChatLanguageModel = class {
|
|
|
688
688
|
const providerMetadata = response.trace || response.usage ? {
|
|
689
689
|
bedrock: {
|
|
690
690
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
691
|
-
...response.usage && {
|
|
691
|
+
...((_h = response.usage) == null ? void 0 : _h.cacheWriteInputTokens) != null && {
|
|
692
692
|
usage: {
|
|
693
|
-
|
|
694
|
-
cacheWriteInputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null ? _k : Number.NaN
|
|
693
|
+
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
695
694
|
}
|
|
696
695
|
}
|
|
697
696
|
}
|
|
@@ -702,8 +701,10 @@ var BedrockChatLanguageModel = class {
|
|
|
702
701
|
response.stopReason
|
|
703
702
|
),
|
|
704
703
|
usage: {
|
|
705
|
-
inputTokens: (
|
|
706
|
-
outputTokens: (
|
|
704
|
+
inputTokens: (_i = response.usage) == null ? void 0 : _i.inputTokens,
|
|
705
|
+
outputTokens: (_j = response.usage) == null ? void 0 : _j.outputTokens,
|
|
706
|
+
totalTokens: ((_k = response.usage) == null ? void 0 : _k.inputTokens) + ((_l = response.usage) == null ? void 0 : _l.outputTokens),
|
|
707
|
+
cachedInputTokens: (_n = (_m = response.usage) == null ? void 0 : _m.cacheReadInputTokens) != null ? _n : void 0
|
|
707
708
|
},
|
|
708
709
|
response: {
|
|
709
710
|
// TODO add id, timestamp, etc
|
|
@@ -734,7 +735,8 @@ var BedrockChatLanguageModel = class {
|
|
|
734
735
|
let finishReason = "unknown";
|
|
735
736
|
const usage = {
|
|
736
737
|
inputTokens: void 0,
|
|
737
|
-
outputTokens: void 0
|
|
738
|
+
outputTokens: void 0,
|
|
739
|
+
totalTokens: void 0
|
|
738
740
|
};
|
|
739
741
|
let providerMetadata = void 0;
|
|
740
742
|
const toolCallContentBlocks = {};
|
|
@@ -745,7 +747,7 @@ var BedrockChatLanguageModel = class {
|
|
|
745
747
|
controller.enqueue({ type: "stream-start", warnings });
|
|
746
748
|
},
|
|
747
749
|
transform(chunk, controller) {
|
|
748
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
750
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
749
751
|
function enqueueError(bedrockError) {
|
|
750
752
|
finishReason = "error";
|
|
751
753
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -779,10 +781,11 @@ var BedrockChatLanguageModel = class {
|
|
|
779
781
|
if (value.metadata) {
|
|
780
782
|
usage.inputTokens = (_b = (_a = value.metadata.usage) == null ? void 0 : _a.inputTokens) != null ? _b : usage.inputTokens;
|
|
781
783
|
usage.outputTokens = (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : usage.outputTokens;
|
|
782
|
-
|
|
784
|
+
usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = usage.outputTokens) != null ? _f : 0);
|
|
785
|
+
usage.cachedInputTokens = (_h = (_g = value.metadata.usage) == null ? void 0 : _g.cacheReadInputTokens) != null ? _h : usage.cachedInputTokens;
|
|
786
|
+
const cacheUsage = ((_i = value.metadata.usage) == null ? void 0 : _i.cacheWriteInputTokens) != null ? {
|
|
783
787
|
usage: {
|
|
784
|
-
|
|
785
|
-
cacheWriteInputTokens: (_j = (_i = value.metadata.usage) == null ? void 0 : _i.cacheWriteInputTokens) != null ? _j : Number.NaN
|
|
788
|
+
cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
|
|
786
789
|
}
|
|
787
790
|
} : void 0;
|
|
788
791
|
const trace = value.metadata.trace ? {
|
|
@@ -797,13 +800,13 @@ var BedrockChatLanguageModel = class {
|
|
|
797
800
|
};
|
|
798
801
|
}
|
|
799
802
|
}
|
|
800
|
-
if (((
|
|
803
|
+
if (((_j = value.contentBlockDelta) == null ? void 0 : _j.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
801
804
|
controller.enqueue({
|
|
802
805
|
type: "text",
|
|
803
806
|
text: value.contentBlockDelta.delta.text
|
|
804
807
|
});
|
|
805
808
|
}
|
|
806
|
-
if (((
|
|
809
|
+
if (((_k = value.contentBlockDelta) == null ? void 0 : _k.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
807
810
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
808
811
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
809
812
|
controller.enqueue({
|
|
@@ -835,7 +838,7 @@ var BedrockChatLanguageModel = class {
|
|
|
835
838
|
}
|
|
836
839
|
}
|
|
837
840
|
const contentBlockStart = value.contentBlockStart;
|
|
838
|
-
if (((
|
|
841
|
+
if (((_l = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _l.toolUse) != null) {
|
|
839
842
|
const toolUse = contentBlockStart.start.toolUse;
|
|
840
843
|
toolCallContentBlocks[contentBlockStart.contentBlockIndex] = {
|
|
841
844
|
toolCallId: toolUse.toolUseId,
|
|
@@ -846,7 +849,7 @@ var BedrockChatLanguageModel = class {
|
|
|
846
849
|
const contentBlockDelta = value.contentBlockDelta;
|
|
847
850
|
if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
848
851
|
const contentBlock = toolCallContentBlocks[contentBlockDelta.contentBlockIndex];
|
|
849
|
-
const delta = (
|
|
852
|
+
const delta = (_m = contentBlockDelta.delta.toolUse.input) != null ? _m : "";
|
|
850
853
|
controller.enqueue({
|
|
851
854
|
type: "tool-call-delta",
|
|
852
855
|
toolCallType: "function",
|
|
@@ -992,6 +995,7 @@ var bedrockReasoningMetadataSchema = import_zod3.z.object({
|
|
|
992
995
|
});
|
|
993
996
|
|
|
994
997
|
// src/bedrock-embedding-model.ts
|
|
998
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
995
999
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
996
1000
|
|
|
997
1001
|
// src/bedrock-embedding-options.ts
|
|
@@ -1031,48 +1035,45 @@ var BedrockEmbeddingModel = class {
|
|
|
1031
1035
|
providerOptions
|
|
1032
1036
|
}) {
|
|
1033
1037
|
var _a;
|
|
1038
|
+
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1039
|
+
throw new import_provider4.TooManyEmbeddingValuesForCallError({
|
|
1040
|
+
provider: this.provider,
|
|
1041
|
+
modelId: this.modelId,
|
|
1042
|
+
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1043
|
+
values
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1034
1046
|
const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
1035
1047
|
provider: "bedrock",
|
|
1036
1048
|
providerOptions,
|
|
1037
1049
|
schema: bedrockEmbeddingProviderOptions
|
|
1038
1050
|
})) != null ? _a : {};
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
inputTextTokenCount: response.inputTextTokenCount
|
|
1065
|
-
};
|
|
1051
|
+
const args = {
|
|
1052
|
+
inputText: values[0],
|
|
1053
|
+
dimensions: bedrockOptions.dimensions,
|
|
1054
|
+
normalize: bedrockOptions.normalize
|
|
1055
|
+
};
|
|
1056
|
+
const url = this.getUrl(this.modelId);
|
|
1057
|
+
const { value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1058
|
+
url,
|
|
1059
|
+
headers: await (0, import_provider_utils4.resolve)(
|
|
1060
|
+
(0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers)
|
|
1061
|
+
),
|
|
1062
|
+
body: args,
|
|
1063
|
+
failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
|
|
1064
|
+
errorSchema: BedrockErrorSchema,
|
|
1065
|
+
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1066
|
+
}),
|
|
1067
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
1068
|
+
BedrockEmbeddingResponseSchema
|
|
1069
|
+
),
|
|
1070
|
+
fetch: this.config.fetch,
|
|
1071
|
+
abortSignal
|
|
1072
|
+
});
|
|
1073
|
+
return {
|
|
1074
|
+
embeddings: [response.embedding],
|
|
1075
|
+
usage: { tokens: response.inputTextTokenCount }
|
|
1066
1076
|
};
|
|
1067
|
-
const responses = await Promise.all(values.map(embedSingleText));
|
|
1068
|
-
return responses.reduce(
|
|
1069
|
-
(accumulated, response) => {
|
|
1070
|
-
accumulated.embeddings.push(response.embedding);
|
|
1071
|
-
accumulated.usage.tokens += response.inputTextTokenCount;
|
|
1072
|
-
return accumulated;
|
|
1073
|
-
},
|
|
1074
|
-
{ embeddings: [], usage: { tokens: 0 } }
|
|
1075
|
-
);
|
|
1076
1077
|
}
|
|
1077
1078
|
};
|
|
1078
1079
|
var BedrockEmbeddingResponseSchema = import_zod5.z.object({
|