@ai-sdk/amazon-bedrock 3.0.131 → 3.0.132
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 +7 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.d.mts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +116 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.132" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/bedrock-provider.ts
|
|
13
13
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
@@ -16,7 +16,7 @@ import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
|
16
16
|
import { sanitizeJsonSchema } from "@ai-sdk/anthropic/internal";
|
|
17
17
|
import {
|
|
18
18
|
combineHeaders,
|
|
19
|
-
createJsonErrorResponseHandler,
|
|
19
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
20
20
|
createJsonResponseHandler,
|
|
21
21
|
parseProviderOptions as parseProviderOptions2,
|
|
22
22
|
postJsonToApi,
|
|
@@ -113,12 +113,26 @@ var bedrockProviderOptions = z.object({
|
|
|
113
113
|
serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
// src/bedrock-anthropic-model-support.ts
|
|
117
|
+
function isAnthropicModel({
|
|
118
|
+
modelId,
|
|
119
|
+
modelFamily,
|
|
120
|
+
reasoningBudgetTokens
|
|
121
|
+
}) {
|
|
122
|
+
return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
|
|
123
|
+
}
|
|
124
|
+
|
|
116
125
|
// src/bedrock-error.ts
|
|
126
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
117
127
|
import { z as z2 } from "zod/v4";
|
|
118
128
|
var BedrockErrorSchema = z2.object({
|
|
119
129
|
message: z2.string(),
|
|
120
130
|
type: z2.string().nullish()
|
|
121
131
|
});
|
|
132
|
+
var bedrockFailedResponseHandler = createJsonErrorResponseHandler({
|
|
133
|
+
errorSchema: BedrockErrorSchema,
|
|
134
|
+
errorToMessage: (error) => error.type == null ? error.message : `${error.type}: ${error.message}`
|
|
135
|
+
});
|
|
122
136
|
|
|
123
137
|
// src/bedrock-event-stream-response-handler.ts
|
|
124
138
|
import { EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
@@ -231,6 +245,8 @@ async function prepareTools({
|
|
|
231
245
|
tools,
|
|
232
246
|
toolChoice,
|
|
233
247
|
modelId,
|
|
248
|
+
modelFamily,
|
|
249
|
+
reasoningBudgetTokens,
|
|
234
250
|
disableParallelToolUse
|
|
235
251
|
}) {
|
|
236
252
|
var _a;
|
|
@@ -263,14 +279,18 @@ async function prepareTools({
|
|
|
263
279
|
toolWarnings
|
|
264
280
|
};
|
|
265
281
|
}
|
|
266
|
-
const isAnthropicModel = modelId.includes("anthropic.");
|
|
267
282
|
const providerDefinedTools = supportedTools.filter(
|
|
268
283
|
(t) => t.type === "provider-defined"
|
|
269
284
|
);
|
|
285
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
286
|
+
modelId,
|
|
287
|
+
modelFamily,
|
|
288
|
+
reasoningBudgetTokens
|
|
289
|
+
});
|
|
270
290
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
271
291
|
let additionalTools = void 0;
|
|
272
292
|
const bedrockTools = [];
|
|
273
|
-
const usingAnthropicTools =
|
|
293
|
+
const usingAnthropicTools = isAnthropicModel2 && providerDefinedTools.length > 0;
|
|
274
294
|
if (usingAnthropicTools) {
|
|
275
295
|
if (functionTools.length > 0) {
|
|
276
296
|
toolWarnings.push({
|
|
@@ -330,7 +350,7 @@ async function prepareTools({
|
|
|
330
350
|
}
|
|
331
351
|
});
|
|
332
352
|
}
|
|
333
|
-
if (
|
|
353
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
334
354
|
additionalTools = {
|
|
335
355
|
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
336
356
|
type: "tool",
|
|
@@ -792,7 +812,7 @@ var BedrockChatLanguageModel = class {
|
|
|
792
812
|
toolChoice,
|
|
793
813
|
providerOptions
|
|
794
814
|
}) {
|
|
795
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
815
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
796
816
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
797
817
|
provider: "bedrock",
|
|
798
818
|
providerOptions,
|
|
@@ -844,12 +864,16 @@ var BedrockChatLanguageModel = class {
|
|
|
844
864
|
details: "Only text and json response formats are supported."
|
|
845
865
|
});
|
|
846
866
|
}
|
|
847
|
-
const
|
|
848
|
-
|
|
867
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
868
|
+
modelId: this.modelId,
|
|
869
|
+
modelFamily: this.config.modelFamily,
|
|
870
|
+
reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
|
|
871
|
+
});
|
|
872
|
+
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
849
873
|
const isOpenAIModel = openAIModelId != null;
|
|
850
|
-
const isOpenAIGptOssModel = (
|
|
851
|
-
const isThinkingRequested = ((
|
|
852
|
-
const structuredOutputMode = (
|
|
874
|
+
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
875
|
+
const isThinkingRequested = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
876
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
853
877
|
if (structuredOutputMode === "jsonTool") {
|
|
854
878
|
const additionalModelRequestFields = {
|
|
855
879
|
...bedrockOptions.additionalModelRequestFields
|
|
@@ -866,7 +890,8 @@ var BedrockChatLanguageModel = class {
|
|
|
866
890
|
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
867
891
|
}
|
|
868
892
|
}
|
|
869
|
-
const
|
|
893
|
+
const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
|
|
894
|
+
const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
870
895
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
871
896
|
type: "function",
|
|
872
897
|
name: "json",
|
|
@@ -877,6 +902,8 @@ var BedrockChatLanguageModel = class {
|
|
|
877
902
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
878
903
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
879
904
|
modelId: this.modelId,
|
|
905
|
+
modelFamily: this.config.modelFamily,
|
|
906
|
+
reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
|
|
880
907
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
881
908
|
});
|
|
882
909
|
warnings.push(...toolWarnings);
|
|
@@ -887,17 +914,17 @@ var BedrockChatLanguageModel = class {
|
|
|
887
914
|
};
|
|
888
915
|
}
|
|
889
916
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
890
|
-
const existingBetas = (
|
|
917
|
+
const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
|
|
891
918
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
892
919
|
bedrockOptions.additionalModelRequestFields = {
|
|
893
920
|
...bedrockOptions.additionalModelRequestFields,
|
|
894
921
|
anthropic_beta: mergedBetas
|
|
895
922
|
};
|
|
896
923
|
}
|
|
897
|
-
const thinkingType = (
|
|
898
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
899
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
900
|
-
const isAnthropicThinkingEnabled =
|
|
924
|
+
const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
|
|
925
|
+
const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
|
|
926
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
|
|
927
|
+
const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingRequested;
|
|
901
928
|
const inferenceConfig = {
|
|
902
929
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
903
930
|
...temperature != null && { temperature },
|
|
@@ -928,8 +955,8 @@ var BedrockChatLanguageModel = class {
|
|
|
928
955
|
}
|
|
929
956
|
};
|
|
930
957
|
}
|
|
931
|
-
} else if (!
|
|
932
|
-
if (((
|
|
958
|
+
} else if (!isAnthropicModel2) {
|
|
959
|
+
if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
|
|
933
960
|
warnings.push({
|
|
934
961
|
type: "unsupported-setting",
|
|
935
962
|
setting: "budgetTokens",
|
|
@@ -944,13 +971,13 @@ var BedrockChatLanguageModel = class {
|
|
|
944
971
|
});
|
|
945
972
|
}
|
|
946
973
|
}
|
|
947
|
-
const maxReasoningEffort = (
|
|
974
|
+
const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
|
|
948
975
|
if (maxReasoningEffort != null) {
|
|
949
|
-
if (
|
|
976
|
+
if (isAnthropicModel2) {
|
|
950
977
|
bedrockOptions.additionalModelRequestFields = {
|
|
951
978
|
...bedrockOptions.additionalModelRequestFields,
|
|
952
979
|
output_config: {
|
|
953
|
-
...(
|
|
980
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
954
981
|
effort: maxReasoningEffort
|
|
955
982
|
}
|
|
956
983
|
};
|
|
@@ -961,7 +988,7 @@ var BedrockChatLanguageModel = class {
|
|
|
961
988
|
} : {
|
|
962
989
|
...bedrockOptions.additionalModelRequestFields,
|
|
963
990
|
reasoning: {
|
|
964
|
-
...(
|
|
991
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
|
|
965
992
|
effort: maxReasoningEffort
|
|
966
993
|
}
|
|
967
994
|
};
|
|
@@ -969,7 +996,7 @@ var BedrockChatLanguageModel = class {
|
|
|
969
996
|
bedrockOptions.additionalModelRequestFields = {
|
|
970
997
|
...bedrockOptions.additionalModelRequestFields,
|
|
971
998
|
reasoningConfig: {
|
|
972
|
-
...((
|
|
999
|
+
...((_r = bedrockOptions.reasoningConfig) == null ? void 0 : _r.type) != null && {
|
|
973
1000
|
type: bedrockOptions.reasoningConfig.type
|
|
974
1001
|
},
|
|
975
1002
|
maxReasoningEffort
|
|
@@ -981,7 +1008,7 @@ var BedrockChatLanguageModel = class {
|
|
|
981
1008
|
bedrockOptions.additionalModelRequestFields = {
|
|
982
1009
|
...bedrockOptions.additionalModelRequestFields,
|
|
983
1010
|
output_config: {
|
|
984
|
-
...(
|
|
1011
|
+
...(_s = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _s.output_config,
|
|
985
1012
|
format: {
|
|
986
1013
|
type: "json_schema",
|
|
987
1014
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1013,7 +1040,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1013
1040
|
details: "topK is not supported when thinking is enabled"
|
|
1014
1041
|
});
|
|
1015
1042
|
}
|
|
1016
|
-
const hasAnyTools = ((
|
|
1043
|
+
const hasAnyTools = ((_u = (_t = toolConfig.tools) == null ? void 0 : _t.length) != null ? _u : 0) > 0 || additionalTools;
|
|
1017
1044
|
let filteredPrompt = prompt;
|
|
1018
1045
|
if (!hasAnyTools) {
|
|
1019
1046
|
const hasToolContent = prompt.some(
|
|
@@ -1047,7 +1074,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1047
1074
|
structuredOutputMode: ____,
|
|
1048
1075
|
...filteredBedrockOptions
|
|
1049
1076
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1050
|
-
const additionalModelResponseFieldPaths =
|
|
1077
|
+
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1051
1078
|
return {
|
|
1052
1079
|
command: {
|
|
1053
1080
|
system,
|
|
@@ -1089,7 +1116,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1089
1116
|
url,
|
|
1090
1117
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1091
1118
|
body: args,
|
|
1092
|
-
failedResponseHandler:
|
|
1119
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1093
1120
|
errorSchema: BedrockErrorSchema,
|
|
1094
1121
|
errorToMessage: (error) => {
|
|
1095
1122
|
var _a2;
|
|
@@ -1212,10 +1239,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1212
1239
|
url,
|
|
1213
1240
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1214
1241
|
body: args,
|
|
1215
|
-
failedResponseHandler:
|
|
1216
|
-
errorSchema: BedrockErrorSchema,
|
|
1217
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1218
|
-
}),
|
|
1242
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1219
1243
|
successfulResponseHandler: createBedrockEventStreamResponseHandler(BedrockStreamSchema),
|
|
1220
1244
|
abortSignal: options.abortSignal,
|
|
1221
1245
|
fetch: this.config.fetch
|
|
@@ -1662,7 +1686,6 @@ import {
|
|
|
1662
1686
|
} from "@ai-sdk/provider";
|
|
1663
1687
|
import {
|
|
1664
1688
|
combineHeaders as combineHeaders2,
|
|
1665
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1666
1689
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1667
1690
|
parseProviderOptions as parseProviderOptions3,
|
|
1668
1691
|
postJsonToApi as postJsonToApi2,
|
|
@@ -1731,10 +1754,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1731
1754
|
combineHeaders2(await resolve2(this.config.headers), headers)
|
|
1732
1755
|
),
|
|
1733
1756
|
body: args,
|
|
1734
|
-
failedResponseHandler:
|
|
1735
|
-
errorSchema: BedrockErrorSchema,
|
|
1736
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1737
|
-
}),
|
|
1757
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1738
1758
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
1739
1759
|
BedrockEmbeddingResponseSchema
|
|
1740
1760
|
),
|
|
@@ -1755,7 +1775,6 @@ var BedrockEmbeddingResponseSchema = z6.object({
|
|
|
1755
1775
|
// src/bedrock-image-model.ts
|
|
1756
1776
|
import {
|
|
1757
1777
|
combineHeaders as combineHeaders3,
|
|
1758
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
1759
1778
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1760
1779
|
postJsonToApi as postJsonToApi3,
|
|
1761
1780
|
resolve as resolve3
|
|
@@ -1830,10 +1849,7 @@ var BedrockImageModel = class {
|
|
|
1830
1849
|
combineHeaders3(await resolve3(this.config.headers), headers)
|
|
1831
1850
|
),
|
|
1832
1851
|
body: args,
|
|
1833
|
-
failedResponseHandler:
|
|
1834
|
-
errorSchema: BedrockErrorSchema,
|
|
1835
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1836
|
-
}),
|
|
1852
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1837
1853
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
1838
1854
|
bedrockImageResponseSchema
|
|
1839
1855
|
),
|
|
@@ -2065,19 +2081,20 @@ Original error: ${errorMessage}`
|
|
|
2065
2081
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2066
2082
|
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2067
2083
|
};
|
|
2068
|
-
const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
|
|
2084
|
+
const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
|
|
2069
2085
|
baseUrl: getBaseUrl,
|
|
2070
2086
|
headers: getHeaders,
|
|
2071
2087
|
fetch: fetchFunction,
|
|
2072
|
-
generateId
|
|
2088
|
+
generateId,
|
|
2089
|
+
modelFamily: settings.modelFamily
|
|
2073
2090
|
});
|
|
2074
|
-
const provider = function(modelId) {
|
|
2091
|
+
const provider = function(modelId, settings) {
|
|
2075
2092
|
if (new.target) {
|
|
2076
2093
|
throw new Error(
|
|
2077
2094
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
2078
2095
|
);
|
|
2079
2096
|
}
|
|
2080
|
-
return createChatModel(modelId);
|
|
2097
|
+
return createChatModel(modelId, settings);
|
|
2081
2098
|
};
|
|
2082
2099
|
const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
|
|
2083
2100
|
baseUrl: getBaseUrl,
|