@ai-sdk/amazon-bedrock 4.0.165 → 4.0.166
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 +13 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.d.mts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +35 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -25
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/docs/08-amazon-bedrock.mdx +24 -0
- package/package.json +4 -4
- package/src/bedrock-chat-language-model.ts +9 -1
- package/src/bedrock-embedding-model.ts +46 -30
- package/src/bedrock-embedding-options.ts +10 -0
- package/src/bedrock-provider.ts +25 -6
- package/src/convert-to-bedrock-chat-messages.ts +1 -1
- package/src/index.ts +4 -1
package/dist/index.mjs
CHANGED
|
@@ -806,7 +806,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
806
806
|
}
|
|
807
807
|
pushCachePoint(bedrockContent, message.providerOptions);
|
|
808
808
|
}
|
|
809
|
-
if (bedrockContent.
|
|
809
|
+
if (bedrockContent.some((block2) => !("cachePoint" in block2))) {
|
|
810
810
|
messages.push({ role: "assistant", content: bedrockContent });
|
|
811
811
|
}
|
|
812
812
|
break;
|
|
@@ -945,7 +945,7 @@ var BedrockChatLanguageModel = class {
|
|
|
945
945
|
toolChoice,
|
|
946
946
|
providerOptions
|
|
947
947
|
}) {
|
|
948
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
948
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
949
949
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
950
950
|
provider: "bedrock",
|
|
951
951
|
providerOptions,
|
|
@@ -997,11 +997,11 @@ var BedrockChatLanguageModel = class {
|
|
|
997
997
|
details: "Only text and json response formats are supported."
|
|
998
998
|
});
|
|
999
999
|
}
|
|
1000
|
-
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
1001
|
-
const openAIModelId = (
|
|
1000
|
+
const isAnthropicModel = this.modelId.includes("anthropic") || this.modelId.includes(":application-inference-profile/") && ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens) != null;
|
|
1001
|
+
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
1002
1002
|
const isOpenAIModel = openAIModelId != null;
|
|
1003
|
-
const isOpenAIGptOssModel = (
|
|
1004
|
-
const isThinkingEnabled = ((
|
|
1003
|
+
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
1004
|
+
const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
1005
1005
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
1006
1006
|
const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
1007
1007
|
const useJsonInstructionForStructuredOutput = isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
|
|
@@ -1025,16 +1025,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1025
1025
|
};
|
|
1026
1026
|
}
|
|
1027
1027
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1028
|
-
const existingBetas = (
|
|
1028
|
+
const existingBetas = (_g = bedrockOptions.anthropicBeta) != null ? _g : [];
|
|
1029
1029
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1030
1030
|
bedrockOptions.additionalModelRequestFields = {
|
|
1031
1031
|
...bedrockOptions.additionalModelRequestFields,
|
|
1032
1032
|
anthropic_beta: mergedBetas
|
|
1033
1033
|
};
|
|
1034
1034
|
}
|
|
1035
|
-
const thinkingType = (
|
|
1036
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1037
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1035
|
+
const thinkingType = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.type;
|
|
1036
|
+
const thinkingBudget = thinkingType === "enabled" ? (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens : void 0;
|
|
1037
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.display : void 0;
|
|
1038
1038
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
1039
1039
|
const inferenceConfig = {
|
|
1040
1040
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -1067,7 +1067,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1067
1067
|
};
|
|
1068
1068
|
}
|
|
1069
1069
|
} else if (!isAnthropicModel) {
|
|
1070
|
-
if (((
|
|
1070
|
+
if (((_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens) != null) {
|
|
1071
1071
|
warnings.push({
|
|
1072
1072
|
type: "unsupported",
|
|
1073
1073
|
feature: "budgetTokens",
|
|
@@ -1082,13 +1082,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1082
1082
|
});
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
|
-
const maxReasoningEffort = (
|
|
1085
|
+
const maxReasoningEffort = (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.maxReasoningEffort;
|
|
1086
1086
|
if (maxReasoningEffort != null) {
|
|
1087
1087
|
if (isAnthropicModel) {
|
|
1088
1088
|
bedrockOptions.additionalModelRequestFields = {
|
|
1089
1089
|
...bedrockOptions.additionalModelRequestFields,
|
|
1090
1090
|
output_config: {
|
|
1091
|
-
...(
|
|
1091
|
+
...(_m = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _m.output_config,
|
|
1092
1092
|
effort: maxReasoningEffort
|
|
1093
1093
|
}
|
|
1094
1094
|
};
|
|
@@ -1099,7 +1099,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1099
1099
|
} : {
|
|
1100
1100
|
...bedrockOptions.additionalModelRequestFields,
|
|
1101
1101
|
reasoning: {
|
|
1102
|
-
...(
|
|
1102
|
+
...(_n = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.reasoning,
|
|
1103
1103
|
effort: maxReasoningEffort
|
|
1104
1104
|
}
|
|
1105
1105
|
};
|
|
@@ -1118,7 +1118,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1118
1118
|
bedrockOptions.additionalModelRequestFields = {
|
|
1119
1119
|
...bedrockOptions.additionalModelRequestFields,
|
|
1120
1120
|
output_config: {
|
|
1121
|
-
...(
|
|
1121
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
|
|
1122
1122
|
format: {
|
|
1123
1123
|
type: "json_schema",
|
|
1124
1124
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1150,7 +1150,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1150
1150
|
details: "topK is not supported when thinking is enabled"
|
|
1151
1151
|
});
|
|
1152
1152
|
}
|
|
1153
|
-
const hasAnyTools = ((
|
|
1153
|
+
const hasAnyTools = ((_q = (_p = toolConfig.tools) == null ? void 0 : _p.length) != null ? _q : 0) > 0 || additionalTools;
|
|
1154
1154
|
let filteredPrompt = prompt;
|
|
1155
1155
|
if (!hasAnyTools) {
|
|
1156
1156
|
const hasToolContent = prompt.some(
|
|
@@ -1833,6 +1833,9 @@ var BedrockStreamSchema = z4.object({
|
|
|
1833
1833
|
contentBlockIndex: z4.number(),
|
|
1834
1834
|
delta: z4.union([
|
|
1835
1835
|
z4.object({ text: z4.string() }),
|
|
1836
|
+
z4.object({
|
|
1837
|
+
citation: z4.record(z4.string(), z4.unknown())
|
|
1838
|
+
}),
|
|
1836
1839
|
z4.object({ toolUse: z4.object({ input: z4.string() }) }),
|
|
1837
1840
|
z4.object({
|
|
1838
1841
|
reasoningContent: z4.object({ text: z4.string() })
|
|
@@ -1962,7 +1965,11 @@ var BedrockEmbeddingModel = class {
|
|
|
1962
1965
|
this.supportsParallelCalls = true;
|
|
1963
1966
|
}
|
|
1964
1967
|
get maxEmbeddingsPerCall() {
|
|
1965
|
-
return
|
|
1968
|
+
return this.modelFamily === "cohere" ? 96 : 1;
|
|
1969
|
+
}
|
|
1970
|
+
get modelFamily() {
|
|
1971
|
+
var _a;
|
|
1972
|
+
return (_a = this.config.modelFamily) != null ? _a : detectEmbeddingModelFamily(this.modelId);
|
|
1966
1973
|
}
|
|
1967
1974
|
getUrl(modelId) {
|
|
1968
1975
|
const encodedModelId = encodeURIComponent(modelId);
|
|
@@ -1988,9 +1995,8 @@ var BedrockEmbeddingModel = class {
|
|
|
1988
1995
|
providerOptions,
|
|
1989
1996
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
1990
1997
|
})) != null ? _a : {};
|
|
1991
|
-
const
|
|
1992
|
-
const
|
|
1993
|
-
const args = isNovaModel ? {
|
|
1998
|
+
const modelFamily = this.modelFamily;
|
|
1999
|
+
const args = modelFamily === "nova" ? {
|
|
1994
2000
|
taskType: "SINGLE_EMBEDDING",
|
|
1995
2001
|
singleEmbeddingParams: {
|
|
1996
2002
|
embeddingPurpose: (_b = bedrockOptions.embeddingPurpose) != null ? _b : "GENERIC_INDEX",
|
|
@@ -2000,7 +2006,7 @@ var BedrockEmbeddingModel = class {
|
|
|
2000
2006
|
value: values[0]
|
|
2001
2007
|
}
|
|
2002
2008
|
}
|
|
2003
|
-
} :
|
|
2009
|
+
} : modelFamily === "cohere" ? {
|
|
2004
2010
|
// Cohere embedding models on Bedrock require `input_type`.
|
|
2005
2011
|
// Without it, the service attempts other schema branches and rejects the request.
|
|
2006
2012
|
input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
|
|
@@ -2057,7 +2063,10 @@ function isCohereEmbeddingModel(modelId) {
|
|
|
2057
2063
|
return modelId.includes("cohere.embed-");
|
|
2058
2064
|
}
|
|
2059
2065
|
function isNovaEmbeddingModel(modelId) {
|
|
2060
|
-
return modelId.
|
|
2066
|
+
return modelId.includes("amazon.nova-") && modelId.includes("embed");
|
|
2067
|
+
}
|
|
2068
|
+
function detectEmbeddingModelFamily(modelId) {
|
|
2069
|
+
return isNovaEmbeddingModel(modelId) ? "nova" : isCohereEmbeddingModel(modelId) ? "cohere" : "titan";
|
|
2061
2070
|
}
|
|
2062
2071
|
var BedrockEmbeddingResponseSchema = z6.union([
|
|
2063
2072
|
// Titan-style response
|
|
@@ -2311,7 +2320,7 @@ import {
|
|
|
2311
2320
|
import { AwsV4Signer } from "aws4fetch";
|
|
2312
2321
|
|
|
2313
2322
|
// src/version.ts
|
|
2314
|
-
var VERSION = true ? "4.0.
|
|
2323
|
+
var VERSION = true ? "4.0.166" : "0.0.0-test";
|
|
2315
2324
|
|
|
2316
2325
|
// src/bedrock-sigv4-fetch.ts
|
|
2317
2326
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -2629,10 +2638,11 @@ Original error: ${errorMessage}`
|
|
|
2629
2638
|
}
|
|
2630
2639
|
return createChatModel(modelId);
|
|
2631
2640
|
};
|
|
2632
|
-
const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
|
|
2641
|
+
const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
|
|
2633
2642
|
baseUrl: getBedrockRuntimeBaseUrl,
|
|
2634
2643
|
headers: getHeaders,
|
|
2635
|
-
fetch: fetchFunction
|
|
2644
|
+
fetch: fetchFunction,
|
|
2645
|
+
modelFamily: settings.modelFamily
|
|
2636
2646
|
});
|
|
2637
2647
|
const createImageModel = (modelId) => new BedrockImageModel(modelId, {
|
|
2638
2648
|
baseUrl: getBedrockRuntimeBaseUrl,
|