@ai-sdk/amazon-bedrock 3.0.125 → 3.0.127
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 +17 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +56 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@ai-sdk/provider-utils";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "3.0.
|
|
11
|
+
var VERSION = true ? "3.0.127" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/bedrock-provider.ts
|
|
14
14
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
@@ -74,6 +74,14 @@ var bedrockFilePartProviderOptions = z.object({
|
|
|
74
74
|
}).optional()
|
|
75
75
|
});
|
|
76
76
|
var bedrockProviderOptions = z.object({
|
|
77
|
+
/**
|
|
78
|
+
* Determines how structured outputs are generated for Anthropic models.
|
|
79
|
+
*
|
|
80
|
+
* - `outputFormat`: Use the native `output_config.format` parameter.
|
|
81
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
82
|
+
* - `auto`: Use `outputFormat` when supported, otherwise use `jsonTool` (default).
|
|
83
|
+
*/
|
|
84
|
+
structuredOutputMode: z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
77
85
|
/**
|
|
78
86
|
* Additional inference parameters that the model supports,
|
|
79
87
|
* beyond the base set of inference parameters that Converse
|
|
@@ -645,7 +653,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
645
653
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
646
654
|
}
|
|
647
655
|
}
|
|
648
|
-
if (bedrockContent.
|
|
656
|
+
if (bedrockContent.some((block2) => !("cachePoint" in block2))) {
|
|
649
657
|
messages.push({ role: "assistant", content: bedrockContent });
|
|
650
658
|
}
|
|
651
659
|
break;
|
|
@@ -757,7 +765,8 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
757
765
|
|
|
758
766
|
// src/bedrock-chat-language-model.ts
|
|
759
767
|
var anthropicProviderOptions = z4.object({
|
|
760
|
-
disableParallelToolUse: z4.boolean().optional()
|
|
768
|
+
disableParallelToolUse: z4.boolean().optional(),
|
|
769
|
+
structuredOutputMode: z4.enum(["outputFormat", "jsonTool", "auto"]).optional()
|
|
761
770
|
});
|
|
762
771
|
var BedrockChatLanguageModel = class {
|
|
763
772
|
constructor(modelId, config) {
|
|
@@ -784,7 +793,7 @@ var BedrockChatLanguageModel = class {
|
|
|
784
793
|
toolChoice,
|
|
785
794
|
providerOptions
|
|
786
795
|
}) {
|
|
787
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
796
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
788
797
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
789
798
|
provider: "bedrock",
|
|
790
799
|
providerOptions,
|
|
@@ -841,7 +850,24 @@ var BedrockChatLanguageModel = class {
|
|
|
841
850
|
const isOpenAIModel = openAIModelId != null;
|
|
842
851
|
const isOpenAIGptOssModel = (_c = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _c : false;
|
|
843
852
|
const isThinkingRequested = ((_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type) === "enabled" || ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "adaptive";
|
|
844
|
-
const
|
|
853
|
+
const structuredOutputMode = (_g = (_f = bedrockOptions.structuredOutputMode) != null ? _f : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _g : "auto";
|
|
854
|
+
if (structuredOutputMode === "jsonTool") {
|
|
855
|
+
const additionalModelRequestFields = {
|
|
856
|
+
...bedrockOptions.additionalModelRequestFields
|
|
857
|
+
};
|
|
858
|
+
const outputConfig = additionalModelRequestFields.output_config;
|
|
859
|
+
if (outputConfig != null && typeof outputConfig === "object" && !Array.isArray(outputConfig)) {
|
|
860
|
+
const outputConfigWithoutFormat = { ...outputConfig };
|
|
861
|
+
delete outputConfigWithoutFormat.format;
|
|
862
|
+
if (Object.keys(outputConfigWithoutFormat).length > 0) {
|
|
863
|
+
additionalModelRequestFields.output_config = outputConfigWithoutFormat;
|
|
864
|
+
} else {
|
|
865
|
+
delete additionalModelRequestFields.output_config;
|
|
866
|
+
}
|
|
867
|
+
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && supportsNativeStructuredOutput(this.modelId) && isThinkingRequested);
|
|
845
871
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
846
872
|
type: "function",
|
|
847
873
|
name: "json",
|
|
@@ -862,16 +888,16 @@ var BedrockChatLanguageModel = class {
|
|
|
862
888
|
};
|
|
863
889
|
}
|
|
864
890
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
865
|
-
const existingBetas = (
|
|
891
|
+
const existingBetas = (_h = bedrockOptions.anthropicBeta) != null ? _h : [];
|
|
866
892
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
867
893
|
bedrockOptions.additionalModelRequestFields = {
|
|
868
894
|
...bedrockOptions.additionalModelRequestFields,
|
|
869
895
|
anthropic_beta: mergedBetas
|
|
870
896
|
};
|
|
871
897
|
}
|
|
872
|
-
const thinkingType = (
|
|
873
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
874
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
898
|
+
const thinkingType = (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.type;
|
|
899
|
+
const thinkingBudget = thinkingType === "enabled" ? (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.budgetTokens : void 0;
|
|
900
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.display : void 0;
|
|
875
901
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
|
|
876
902
|
const inferenceConfig = {
|
|
877
903
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -904,7 +930,7 @@ var BedrockChatLanguageModel = class {
|
|
|
904
930
|
};
|
|
905
931
|
}
|
|
906
932
|
} else if (!isAnthropicModel) {
|
|
907
|
-
if (((
|
|
933
|
+
if (((_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens) != null) {
|
|
908
934
|
warnings.push({
|
|
909
935
|
type: "unsupported-setting",
|
|
910
936
|
setting: "budgetTokens",
|
|
@@ -919,13 +945,13 @@ var BedrockChatLanguageModel = class {
|
|
|
919
945
|
});
|
|
920
946
|
}
|
|
921
947
|
}
|
|
922
|
-
const maxReasoningEffort = (
|
|
948
|
+
const maxReasoningEffort = (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.maxReasoningEffort;
|
|
923
949
|
if (maxReasoningEffort != null) {
|
|
924
950
|
if (isAnthropicModel) {
|
|
925
951
|
bedrockOptions.additionalModelRequestFields = {
|
|
926
952
|
...bedrockOptions.additionalModelRequestFields,
|
|
927
953
|
output_config: {
|
|
928
|
-
...(
|
|
954
|
+
...(_n = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.output_config,
|
|
929
955
|
effort: maxReasoningEffort
|
|
930
956
|
}
|
|
931
957
|
};
|
|
@@ -936,7 +962,7 @@ var BedrockChatLanguageModel = class {
|
|
|
936
962
|
} : {
|
|
937
963
|
...bedrockOptions.additionalModelRequestFields,
|
|
938
964
|
reasoning: {
|
|
939
|
-
...(
|
|
965
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.reasoning,
|
|
940
966
|
effort: maxReasoningEffort
|
|
941
967
|
}
|
|
942
968
|
};
|
|
@@ -944,7 +970,7 @@ var BedrockChatLanguageModel = class {
|
|
|
944
970
|
bedrockOptions.additionalModelRequestFields = {
|
|
945
971
|
...bedrockOptions.additionalModelRequestFields,
|
|
946
972
|
reasoningConfig: {
|
|
947
|
-
...((
|
|
973
|
+
...((_p = bedrockOptions.reasoningConfig) == null ? void 0 : _p.type) != null && {
|
|
948
974
|
type: bedrockOptions.reasoningConfig.type
|
|
949
975
|
},
|
|
950
976
|
maxReasoningEffort
|
|
@@ -956,7 +982,7 @@ var BedrockChatLanguageModel = class {
|
|
|
956
982
|
bedrockOptions.additionalModelRequestFields = {
|
|
957
983
|
...bedrockOptions.additionalModelRequestFields,
|
|
958
984
|
output_config: {
|
|
959
|
-
...(
|
|
985
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
|
|
960
986
|
format: {
|
|
961
987
|
type: "json_schema",
|
|
962
988
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -988,7 +1014,7 @@ var BedrockChatLanguageModel = class {
|
|
|
988
1014
|
details: "topK is not supported when thinking is enabled"
|
|
989
1015
|
});
|
|
990
1016
|
}
|
|
991
|
-
const hasAnyTools = ((
|
|
1017
|
+
const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
|
|
992
1018
|
let filteredPrompt = prompt;
|
|
993
1019
|
if (!hasAnyTools) {
|
|
994
1020
|
const hasToolContent = prompt.some(
|
|
@@ -1019,6 +1045,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1019
1045
|
reasoningConfig: _,
|
|
1020
1046
|
additionalModelRequestFields: __,
|
|
1021
1047
|
serviceTier: ___,
|
|
1048
|
+
structuredOutputMode: ____,
|
|
1022
1049
|
...filteredBedrockOptions
|
|
1023
1050
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1024
1051
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -1485,8 +1512,17 @@ var BedrockChatLanguageModel = class {
|
|
|
1485
1512
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
1486
1513
|
}
|
|
1487
1514
|
};
|
|
1515
|
+
var MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT = [
|
|
1516
|
+
"anthropic.claude-sonnet-4-6",
|
|
1517
|
+
"anthropic.claude-haiku-4-5"
|
|
1518
|
+
];
|
|
1488
1519
|
function supportsNativeStructuredOutput(modelId) {
|
|
1489
|
-
|
|
1520
|
+
if (MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT.some(
|
|
1521
|
+
(model) => modelId.includes(model)
|
|
1522
|
+
)) {
|
|
1523
|
+
return false;
|
|
1524
|
+
}
|
|
1525
|
+
return modelId.includes("anthropic.claude-sonnet-4-5") || modelId.includes("anthropic.claude-opus-4-5") || modelId.includes("anthropic.claude-opus-4-6");
|
|
1490
1526
|
}
|
|
1491
1527
|
var BedrockStopReasonSchema = z4.union([
|
|
1492
1528
|
z4.enum(BEDROCK_STOP_REASONS),
|
|
@@ -1555,6 +1591,9 @@ var BedrockStreamSchema = z4.object({
|
|
|
1555
1591
|
contentBlockIndex: z4.number(),
|
|
1556
1592
|
delta: z4.union([
|
|
1557
1593
|
z4.object({ text: z4.string() }),
|
|
1594
|
+
z4.object({
|
|
1595
|
+
citation: z4.record(z4.string(), z4.unknown())
|
|
1596
|
+
}),
|
|
1558
1597
|
z4.object({ toolUse: z4.object({ input: z4.string() }) }),
|
|
1559
1598
|
z4.object({
|
|
1560
1599
|
reasoningContent: z4.object({ text: z4.string() })
|