@ai-sdk/amazon-bedrock 5.0.0-beta.3 → 5.0.0-beta.30
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 +226 -4
- package/README.md +2 -0
- package/dist/anthropic/index.js +34 -6
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +31 -3
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +132 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -33
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +52 -6
- package/package.json +4 -6
- package/src/anthropic/bedrock-anthropic-fetch.ts +26 -0
- package/src/anthropic/bedrock-anthropic-provider.ts +11 -1
- package/src/bedrock-api-types.ts +3 -0
- package/src/bedrock-chat-language-model.ts +98 -4
- package/src/bedrock-chat-options.ts +10 -0
- package/src/bedrock-prepare-tools.ts +1 -0
- package/src/convert-to-bedrock-chat-messages.ts +45 -33
package/dist/index.mjs
CHANGED
|
@@ -13,10 +13,14 @@ import {
|
|
|
13
13
|
combineHeaders,
|
|
14
14
|
createJsonErrorResponseHandler,
|
|
15
15
|
createJsonResponseHandler,
|
|
16
|
+
isCustomReasoning,
|
|
17
|
+
mapReasoningToProviderBudget,
|
|
18
|
+
mapReasoningToProviderEffort,
|
|
16
19
|
parseProviderOptions as parseProviderOptions2,
|
|
17
20
|
postJsonToApi,
|
|
18
21
|
resolve
|
|
19
22
|
} from "@ai-sdk/provider-utils";
|
|
23
|
+
import { getModelCapabilities } from "@ai-sdk/anthropic/internal";
|
|
20
24
|
import { z as z3 } from "zod/v4";
|
|
21
25
|
|
|
22
26
|
// src/bedrock-api-types.ts
|
|
@@ -83,7 +87,17 @@ var amazonBedrockLanguageModelOptions = z.object({
|
|
|
83
87
|
/**
|
|
84
88
|
* Anthropic beta features to enable
|
|
85
89
|
*/
|
|
86
|
-
anthropicBeta: z.array(z.string()).optional()
|
|
90
|
+
anthropicBeta: z.array(z.string()).optional(),
|
|
91
|
+
/**
|
|
92
|
+
* Service tier for the request.
|
|
93
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
|
|
94
|
+
*
|
|
95
|
+
* - 'reserved': Uses provisioned throughput capacity
|
|
96
|
+
* - 'priority': Prioritizes low-latency inference when capacity is available
|
|
97
|
+
* - 'default': Standard on-demand tier
|
|
98
|
+
* - 'flex': Lower-cost tier for flexible latency workloads
|
|
99
|
+
*/
|
|
100
|
+
serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
87
101
|
});
|
|
88
102
|
|
|
89
103
|
// src/bedrock-error.ts
|
|
@@ -240,7 +254,8 @@ async function prepareTools({
|
|
|
240
254
|
} = await prepareAnthropicTools({
|
|
241
255
|
tools: ProviderTools,
|
|
242
256
|
toolChoice,
|
|
243
|
-
supportsStructuredOutput: false
|
|
257
|
+
supportsStructuredOutput: false,
|
|
258
|
+
supportsStrictTools: false
|
|
244
259
|
});
|
|
245
260
|
toolWarnings.push(...anthropicToolWarnings);
|
|
246
261
|
anthropicBetas.forEach((beta) => betas.add(beta));
|
|
@@ -365,6 +380,7 @@ import {
|
|
|
365
380
|
} from "@ai-sdk/provider";
|
|
366
381
|
import {
|
|
367
382
|
convertToBase64,
|
|
383
|
+
isProviderReference,
|
|
368
384
|
parseProviderOptions,
|
|
369
385
|
stripFileExtension
|
|
370
386
|
} from "@ai-sdk/provider-utils";
|
|
@@ -442,6 +458,11 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
442
458
|
break;
|
|
443
459
|
}
|
|
444
460
|
case "file": {
|
|
461
|
+
if (isProviderReference(part.data)) {
|
|
462
|
+
throw new UnsupportedFunctionalityError2({
|
|
463
|
+
functionality: "file parts with provider references"
|
|
464
|
+
});
|
|
465
|
+
}
|
|
445
466
|
if (part.data instanceof URL) {
|
|
446
467
|
throw new UnsupportedFunctionalityError2({
|
|
447
468
|
functionality: "File URL data"
|
|
@@ -563,12 +584,15 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
563
584
|
const message = block.messages[j];
|
|
564
585
|
const isLastMessage = j === block.messages.length - 1;
|
|
565
586
|
const { content } = message;
|
|
587
|
+
const hasReasoningBlocks = content.some(
|
|
588
|
+
(part) => part.type === "reasoning"
|
|
589
|
+
);
|
|
566
590
|
for (let k = 0; k < content.length; k++) {
|
|
567
591
|
const part = content[k];
|
|
568
592
|
const isLastContentPart = k === content.length - 1;
|
|
569
593
|
switch (part.type) {
|
|
570
594
|
case "text": {
|
|
571
|
-
if (!part.text.trim()) {
|
|
595
|
+
if (!part.text.trim() && !hasReasoningBlocks) {
|
|
572
596
|
break;
|
|
573
597
|
}
|
|
574
598
|
bedrockContent.push({
|
|
@@ -592,33 +616,36 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
592
616
|
providerOptions: part.providerOptions,
|
|
593
617
|
schema: bedrockReasoningMetadataSchema
|
|
594
618
|
});
|
|
595
|
-
if (reasoningMetadata != null) {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
// because Bedrock does not allow trailing whitespace
|
|
602
|
-
// in pre-filled assistant responses
|
|
603
|
-
text: trimIfLast(
|
|
604
|
-
isLastBlock,
|
|
605
|
-
isLastMessage,
|
|
606
|
-
isLastContentPart,
|
|
607
|
-
part.text
|
|
608
|
-
),
|
|
609
|
-
signature: reasoningMetadata.signature
|
|
610
|
-
}
|
|
619
|
+
if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
|
|
620
|
+
bedrockContent.push({
|
|
621
|
+
reasoningContent: {
|
|
622
|
+
reasoningText: {
|
|
623
|
+
text: part.text,
|
|
624
|
+
signature: reasoningMetadata.signature
|
|
611
625
|
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
629
|
+
bedrockContent.push({
|
|
630
|
+
reasoningContent: {
|
|
631
|
+
redactedReasoning: {
|
|
632
|
+
data: reasoningMetadata.redactedData
|
|
619
633
|
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
} else {
|
|
637
|
+
bedrockContent.push({
|
|
638
|
+
reasoningContent: {
|
|
639
|
+
reasoningText: {
|
|
640
|
+
text: trimIfLast(
|
|
641
|
+
isLastBlock,
|
|
642
|
+
isLastMessage,
|
|
643
|
+
isLastContentPart,
|
|
644
|
+
part.text
|
|
645
|
+
)
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
});
|
|
622
649
|
}
|
|
623
650
|
break;
|
|
624
651
|
}
|
|
@@ -768,10 +795,11 @@ var BedrockChatLanguageModel = class {
|
|
|
768
795
|
seed,
|
|
769
796
|
tools,
|
|
770
797
|
toolChoice,
|
|
798
|
+
reasoning,
|
|
771
799
|
providerOptions
|
|
772
800
|
}) {
|
|
773
801
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
774
|
-
|
|
802
|
+
let bedrockOptions = (_a = await parseProviderOptions2({
|
|
775
803
|
provider: "bedrock",
|
|
776
804
|
providerOptions,
|
|
777
805
|
schema: amazonBedrockLanguageModelOptions
|
|
@@ -818,8 +846,17 @@ var BedrockChatLanguageModel = class {
|
|
|
818
846
|
});
|
|
819
847
|
}
|
|
820
848
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
849
|
+
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
850
|
+
bedrockOptions = resolveBedrockReasoningConfig({
|
|
851
|
+
reasoning,
|
|
852
|
+
bedrockOptions,
|
|
853
|
+
warnings,
|
|
854
|
+
isAnthropicModel,
|
|
855
|
+
modelId: this.modelId
|
|
856
|
+
});
|
|
821
857
|
const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
|
|
822
|
-
const
|
|
858
|
+
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
859
|
+
const useNativeStructuredOutput = isAnthropicModel && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
823
860
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
824
861
|
type: "function",
|
|
825
862
|
name: "json",
|
|
@@ -895,7 +932,6 @@ var BedrockChatLanguageModel = class {
|
|
|
895
932
|
}
|
|
896
933
|
}
|
|
897
934
|
const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
|
|
898
|
-
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
899
935
|
if (maxReasoningEffort != null) {
|
|
900
936
|
if (isAnthropicModel) {
|
|
901
937
|
bedrockOptions.additionalModelRequestFields = {
|
|
@@ -991,6 +1027,7 @@ var BedrockChatLanguageModel = class {
|
|
|
991
1027
|
const {
|
|
992
1028
|
reasoningConfig: _,
|
|
993
1029
|
additionalModelRequestFields: __,
|
|
1030
|
+
serviceTier: ___,
|
|
994
1031
|
...filteredBedrockOptions
|
|
995
1032
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
996
1033
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -1005,6 +1042,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1005
1042
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
1006
1043
|
inferenceConfig
|
|
1007
1044
|
},
|
|
1045
|
+
...bedrockOptions.serviceTier != null && {
|
|
1046
|
+
serviceTier: {
|
|
1047
|
+
type: bedrockOptions.serviceTier
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1008
1050
|
...filteredBedrockOptions,
|
|
1009
1051
|
...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
|
|
1010
1052
|
},
|
|
@@ -1046,7 +1088,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1046
1088
|
const content = [];
|
|
1047
1089
|
let isJsonResponseFromTool = false;
|
|
1048
1090
|
for (const part of response.output.message.content) {
|
|
1049
|
-
if (part.text) {
|
|
1091
|
+
if (part.text != null) {
|
|
1050
1092
|
content.push({ type: "text", text: part.text });
|
|
1051
1093
|
}
|
|
1052
1094
|
if (part.reasoningContent) {
|
|
@@ -1554,6 +1596,62 @@ var bedrockReasoningMetadataSchema = z3.object({
|
|
|
1554
1596
|
signature: z3.string().optional(),
|
|
1555
1597
|
redactedData: z3.string().optional()
|
|
1556
1598
|
});
|
|
1599
|
+
var bedrockReasoningEffortMap = {
|
|
1600
|
+
minimal: "low",
|
|
1601
|
+
low: "low",
|
|
1602
|
+
medium: "medium",
|
|
1603
|
+
high: "high",
|
|
1604
|
+
xhigh: "max"
|
|
1605
|
+
};
|
|
1606
|
+
function resolveBedrockReasoningConfig({
|
|
1607
|
+
reasoning,
|
|
1608
|
+
bedrockOptions,
|
|
1609
|
+
warnings,
|
|
1610
|
+
isAnthropicModel,
|
|
1611
|
+
modelId
|
|
1612
|
+
}) {
|
|
1613
|
+
if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
|
|
1614
|
+
return bedrockOptions;
|
|
1615
|
+
}
|
|
1616
|
+
const result = { ...bedrockOptions };
|
|
1617
|
+
if (isAnthropicModel) {
|
|
1618
|
+
const capabilities = getModelCapabilities(modelId);
|
|
1619
|
+
if (reasoning === "none") {
|
|
1620
|
+
result.reasoningConfig = { type: "disabled" };
|
|
1621
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1622
|
+
const effort = mapReasoningToProviderEffort({
|
|
1623
|
+
reasoning,
|
|
1624
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1625
|
+
warnings
|
|
1626
|
+
});
|
|
1627
|
+
result.reasoningConfig = {
|
|
1628
|
+
type: "adaptive",
|
|
1629
|
+
maxReasoningEffort: effort
|
|
1630
|
+
};
|
|
1631
|
+
} else {
|
|
1632
|
+
const budgetTokens = mapReasoningToProviderBudget({
|
|
1633
|
+
reasoning,
|
|
1634
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1635
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1636
|
+
warnings
|
|
1637
|
+
});
|
|
1638
|
+
if (budgetTokens != null) {
|
|
1639
|
+
result.reasoningConfig = {
|
|
1640
|
+
type: "enabled",
|
|
1641
|
+
budgetTokens
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
} else if (reasoning !== "none") {
|
|
1646
|
+
const effort = mapReasoningToProviderEffort({
|
|
1647
|
+
reasoning,
|
|
1648
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1649
|
+
warnings
|
|
1650
|
+
});
|
|
1651
|
+
result.reasoningConfig = { maxReasoningEffort: effort };
|
|
1652
|
+
}
|
|
1653
|
+
return result;
|
|
1654
|
+
}
|
|
1557
1655
|
|
|
1558
1656
|
// src/bedrock-embedding-model.ts
|
|
1559
1657
|
import {
|
|
@@ -1969,7 +2067,7 @@ import {
|
|
|
1969
2067
|
import { AwsV4Signer } from "aws4fetch";
|
|
1970
2068
|
|
|
1971
2069
|
// src/version.ts
|
|
1972
|
-
var VERSION = true ? "5.0.0-beta.
|
|
2070
|
+
var VERSION = true ? "5.0.0-beta.30" : "0.0.0-test";
|
|
1973
2071
|
|
|
1974
2072
|
// src/bedrock-sigv4-fetch.ts
|
|
1975
2073
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|