@ai-sdk/amazon-bedrock 4.0.165 → 4.0.167

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 4.0.167
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [85ba0b0]
8
+ - @ai-sdk/openai@3.0.106
9
+
10
+ ## 4.0.166
11
+
12
+ ### Patch Changes
13
+
14
+ - ada21b6: Omit assistant messages when only cache points remain after unsigned reasoning is filtered.
15
+ - fb9b783: feat(amazon-bedrock): add model family setting for embeddings to support ARN
16
+ - 6b88988: Accept citation deltas in Amazon Bedrock streaming responses.
17
+ - 06cc1cb: Enable Anthropic reasoning budgets for application inference profile ARNs.
18
+ - Updated dependencies [cc23556]
19
+ - @ai-sdk/provider-utils@4.0.50
20
+ - @ai-sdk/anthropic@3.0.115
21
+ - @ai-sdk/openai@3.0.105
22
+
3
23
  ## 4.0.165
4
24
 
5
25
  ### Patch Changes
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "4.0.165" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.167" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -24,7 +24,7 @@ import {
24
24
  import { AwsV4Signer } from "aws4fetch";
25
25
 
26
26
  // src/version.ts
27
- var VERSION = true ? "4.0.165" : "0.0.0-test";
27
+ var VERSION = true ? "4.0.167" : "0.0.0-test";
28
28
 
29
29
  // src/bedrock-sigv4-fetch.ts
30
30
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/dist/index.d.mts CHANGED
@@ -5,6 +5,15 @@ import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3, RerankingM
5
5
  import { FetchFunction } from '@ai-sdk/provider-utils';
6
6
 
7
7
  type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
8
+ type AmazonBedrockEmbeddingModelSettings = {
9
+ /**
10
+ * The embedding model family.
11
+ *
12
+ * Specify this when the model ID does not identify the underlying model,
13
+ * such as an application inference profile ARN.
14
+ */
15
+ modelFamily?: 'titan' | 'cohere' | 'nova';
16
+ };
8
17
  declare const amazonBedrockEmbeddingModelOptionsSchema: z.ZodObject<{
9
18
  dimensions: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<1024>, z.ZodLiteral<512>, z.ZodLiteral<256>]>>;
10
19
  normalize: z.ZodOptional<z.ZodBoolean>;
@@ -159,19 +168,19 @@ interface AmazonBedrockProvider extends ProviderV3 {
159
168
  /**
160
169
  * Creates a model for text embeddings.
161
170
  */
162
- embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
171
+ embedding(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
163
172
  /**
164
173
  * Creates a model for text embeddings.
165
174
  */
166
- embeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
175
+ embeddingModel(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
167
176
  /**
168
177
  * @deprecated Use `embedding` instead.
169
178
  */
170
- textEmbedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
179
+ textEmbedding(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
171
180
  /**
172
181
  * @deprecated Use `embeddingModel` instead.
173
182
  */
174
- textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
183
+ textEmbeddingModel(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
175
184
  /**
176
185
  * Creates a model for image generation.
177
186
  */
@@ -204,4 +213,4 @@ declare const bedrock: AmazonBedrockProvider;
204
213
 
205
214
  declare const VERSION: string;
206
215
 
207
- export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, bedrock, createAmazonBedrock };
216
+ export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockEmbeddingModelSettings, type AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, bedrock, createAmazonBedrock };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,15 @@ import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3, RerankingM
5
5
  import { FetchFunction } from '@ai-sdk/provider-utils';
6
6
 
7
7
  type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
8
+ type AmazonBedrockEmbeddingModelSettings = {
9
+ /**
10
+ * The embedding model family.
11
+ *
12
+ * Specify this when the model ID does not identify the underlying model,
13
+ * such as an application inference profile ARN.
14
+ */
15
+ modelFamily?: 'titan' | 'cohere' | 'nova';
16
+ };
8
17
  declare const amazonBedrockEmbeddingModelOptionsSchema: z.ZodObject<{
9
18
  dimensions: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<1024>, z.ZodLiteral<512>, z.ZodLiteral<256>]>>;
10
19
  normalize: z.ZodOptional<z.ZodBoolean>;
@@ -159,19 +168,19 @@ interface AmazonBedrockProvider extends ProviderV3 {
159
168
  /**
160
169
  * Creates a model for text embeddings.
161
170
  */
162
- embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
171
+ embedding(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
163
172
  /**
164
173
  * Creates a model for text embeddings.
165
174
  */
166
- embeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
175
+ embeddingModel(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
167
176
  /**
168
177
  * @deprecated Use `embedding` instead.
169
178
  */
170
- textEmbedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
179
+ textEmbedding(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
171
180
  /**
172
181
  * @deprecated Use `embeddingModel` instead.
173
182
  */
174
- textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
183
+ textEmbeddingModel(modelId: BedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV3;
175
184
  /**
176
185
  * Creates a model for image generation.
177
186
  */
@@ -204,4 +213,4 @@ declare const bedrock: AmazonBedrockProvider;
204
213
 
205
214
  declare const VERSION: string;
206
215
 
207
- export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, bedrock, createAmazonBedrock };
216
+ export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockEmbeddingModelSettings, type AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, bedrock, createAmazonBedrock };
package/dist/index.js CHANGED
@@ -802,7 +802,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
802
802
  }
803
803
  pushCachePoint(bedrockContent, message.providerOptions);
804
804
  }
805
- if (bedrockContent.length > 0) {
805
+ if (bedrockContent.some((block2) => !("cachePoint" in block2))) {
806
806
  messages.push({ role: "assistant", content: bedrockContent });
807
807
  }
808
808
  break;
@@ -941,7 +941,7 @@ var BedrockChatLanguageModel = class {
941
941
  toolChoice,
942
942
  providerOptions
943
943
  }) {
944
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
944
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
945
945
  const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
946
946
  provider: "bedrock",
947
947
  providerOptions,
@@ -993,11 +993,11 @@ var BedrockChatLanguageModel = class {
993
993
  details: "Only text and json response formats are supported."
994
994
  });
995
995
  }
996
- const isAnthropicModel = this.modelId.includes("anthropic");
997
- const openAIModelId = (_b = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _b[1];
996
+ const isAnthropicModel = this.modelId.includes("anthropic") || this.modelId.includes(":application-inference-profile/") && ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens) != null;
997
+ const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
998
998
  const isOpenAIModel = openAIModelId != null;
999
- const isOpenAIGptOssModel = (_c = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _c : false;
1000
- const isThinkingEnabled = ((_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type) === "enabled" || ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "adaptive";
999
+ const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
1000
+ const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
1001
1001
  const { supportsStructuredOutput: modelSupportsStructuredOutput } = (0, import_internal2.getModelCapabilities)(this.modelId);
1002
1002
  const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
1003
1003
  const useJsonInstructionForStructuredOutput = isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
@@ -1021,16 +1021,16 @@ var BedrockChatLanguageModel = class {
1021
1021
  };
1022
1022
  }
1023
1023
  if (betas.size > 0 || bedrockOptions.anthropicBeta) {
1024
- const existingBetas = (_f = bedrockOptions.anthropicBeta) != null ? _f : [];
1024
+ const existingBetas = (_g = bedrockOptions.anthropicBeta) != null ? _g : [];
1025
1025
  const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
1026
1026
  bedrockOptions.additionalModelRequestFields = {
1027
1027
  ...bedrockOptions.additionalModelRequestFields,
1028
1028
  anthropic_beta: mergedBetas
1029
1029
  };
1030
1030
  }
1031
- const thinkingType = (_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.type;
1032
- const thinkingBudget = thinkingType === "enabled" ? (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.budgetTokens : void 0;
1033
- const thinkingDisplay = thinkingType === "adaptive" ? (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.display : void 0;
1031
+ const thinkingType = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.type;
1032
+ const thinkingBudget = thinkingType === "enabled" ? (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens : void 0;
1033
+ const thinkingDisplay = thinkingType === "adaptive" ? (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.display : void 0;
1034
1034
  const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
1035
1035
  const inferenceConfig = {
1036
1036
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
@@ -1063,7 +1063,7 @@ var BedrockChatLanguageModel = class {
1063
1063
  };
1064
1064
  }
1065
1065
  } else if (!isAnthropicModel) {
1066
- if (((_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.budgetTokens) != null) {
1066
+ if (((_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens) != null) {
1067
1067
  warnings.push({
1068
1068
  type: "unsupported",
1069
1069
  feature: "budgetTokens",
@@ -1078,13 +1078,13 @@ var BedrockChatLanguageModel = class {
1078
1078
  });
1079
1079
  }
1080
1080
  }
1081
- const maxReasoningEffort = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.maxReasoningEffort;
1081
+ const maxReasoningEffort = (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.maxReasoningEffort;
1082
1082
  if (maxReasoningEffort != null) {
1083
1083
  if (isAnthropicModel) {
1084
1084
  bedrockOptions.additionalModelRequestFields = {
1085
1085
  ...bedrockOptions.additionalModelRequestFields,
1086
1086
  output_config: {
1087
- ...(_l = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _l.output_config,
1087
+ ...(_m = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _m.output_config,
1088
1088
  effort: maxReasoningEffort
1089
1089
  }
1090
1090
  };
@@ -1095,7 +1095,7 @@ var BedrockChatLanguageModel = class {
1095
1095
  } : {
1096
1096
  ...bedrockOptions.additionalModelRequestFields,
1097
1097
  reasoning: {
1098
- ...(_m = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _m.reasoning,
1098
+ ...(_n = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.reasoning,
1099
1099
  effort: maxReasoningEffort
1100
1100
  }
1101
1101
  };
@@ -1114,7 +1114,7 @@ var BedrockChatLanguageModel = class {
1114
1114
  bedrockOptions.additionalModelRequestFields = {
1115
1115
  ...bedrockOptions.additionalModelRequestFields,
1116
1116
  output_config: {
1117
- ...(_n = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.output_config,
1117
+ ...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
1118
1118
  format: {
1119
1119
  type: "json_schema",
1120
1120
  schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
@@ -1146,7 +1146,7 @@ var BedrockChatLanguageModel = class {
1146
1146
  details: "topK is not supported when thinking is enabled"
1147
1147
  });
1148
1148
  }
1149
- const hasAnyTools = ((_p = (_o = toolConfig.tools) == null ? void 0 : _o.length) != null ? _p : 0) > 0 || additionalTools;
1149
+ const hasAnyTools = ((_q = (_p = toolConfig.tools) == null ? void 0 : _p.length) != null ? _q : 0) > 0 || additionalTools;
1150
1150
  let filteredPrompt = prompt;
1151
1151
  if (!hasAnyTools) {
1152
1152
  const hasToolContent = prompt.some(
@@ -1829,6 +1829,9 @@ var BedrockStreamSchema = import_v44.z.object({
1829
1829
  contentBlockIndex: import_v44.z.number(),
1830
1830
  delta: import_v44.z.union([
1831
1831
  import_v44.z.object({ text: import_v44.z.string() }),
1832
+ import_v44.z.object({
1833
+ citation: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown())
1834
+ }),
1832
1835
  import_v44.z.object({ toolUse: import_v44.z.object({ input: import_v44.z.string() }) }),
1833
1836
  import_v44.z.object({
1834
1837
  reasoningContent: import_v44.z.object({ text: import_v44.z.string() })
@@ -1949,7 +1952,11 @@ var BedrockEmbeddingModel = class {
1949
1952
  this.supportsParallelCalls = true;
1950
1953
  }
1951
1954
  get maxEmbeddingsPerCall() {
1952
- return isCohereEmbeddingModel(this.modelId) ? 96 : 1;
1955
+ return this.modelFamily === "cohere" ? 96 : 1;
1956
+ }
1957
+ get modelFamily() {
1958
+ var _a;
1959
+ return (_a = this.config.modelFamily) != null ? _a : detectEmbeddingModelFamily(this.modelId);
1953
1960
  }
1954
1961
  getUrl(modelId) {
1955
1962
  const encodedModelId = encodeURIComponent(modelId);
@@ -1975,9 +1982,8 @@ var BedrockEmbeddingModel = class {
1975
1982
  providerOptions,
1976
1983
  schema: amazonBedrockEmbeddingModelOptionsSchema
1977
1984
  })) != null ? _a : {};
1978
- const isNovaModel = isNovaEmbeddingModel(this.modelId);
1979
- const isCohereModel = isCohereEmbeddingModel(this.modelId);
1980
- const args = isNovaModel ? {
1985
+ const modelFamily = this.modelFamily;
1986
+ const args = modelFamily === "nova" ? {
1981
1987
  taskType: "SINGLE_EMBEDDING",
1982
1988
  singleEmbeddingParams: {
1983
1989
  embeddingPurpose: (_b = bedrockOptions.embeddingPurpose) != null ? _b : "GENERIC_INDEX",
@@ -1987,7 +1993,7 @@ var BedrockEmbeddingModel = class {
1987
1993
  value: values[0]
1988
1994
  }
1989
1995
  }
1990
- } : isCohereModel ? {
1996
+ } : modelFamily === "cohere" ? {
1991
1997
  // Cohere embedding models on Bedrock require `input_type`.
1992
1998
  // Without it, the service attempts other schema branches and rejects the request.
1993
1999
  input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
@@ -2044,7 +2050,10 @@ function isCohereEmbeddingModel(modelId) {
2044
2050
  return modelId.includes("cohere.embed-");
2045
2051
  }
2046
2052
  function isNovaEmbeddingModel(modelId) {
2047
- return modelId.startsWith("amazon.nova-") && modelId.includes("embed");
2053
+ return modelId.includes("amazon.nova-") && modelId.includes("embed");
2054
+ }
2055
+ function detectEmbeddingModelFamily(modelId) {
2056
+ return isNovaEmbeddingModel(modelId) ? "nova" : isCohereEmbeddingModel(modelId) ? "cohere" : "titan";
2048
2057
  }
2049
2058
  var BedrockEmbeddingResponseSchema = import_v46.z.union([
2050
2059
  // Titan-style response
@@ -2286,7 +2295,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
2286
2295
  var import_aws4fetch = require("aws4fetch");
2287
2296
 
2288
2297
  // src/version.ts
2289
- var VERSION = true ? "4.0.165" : "0.0.0-test";
2298
+ var VERSION = true ? "4.0.167" : "0.0.0-test";
2290
2299
 
2291
2300
  // src/bedrock-sigv4-fetch.ts
2292
2301
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -2597,10 +2606,11 @@ Original error: ${errorMessage}`
2597
2606
  }
2598
2607
  return createChatModel(modelId);
2599
2608
  };
2600
- const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
2609
+ const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
2601
2610
  baseUrl: getBedrockRuntimeBaseUrl,
2602
2611
  headers: getHeaders,
2603
- fetch: fetchFunction
2612
+ fetch: fetchFunction,
2613
+ modelFamily: settings.modelFamily
2604
2614
  });
2605
2615
  const createImageModel = (modelId) => new BedrockImageModel(modelId, {
2606
2616
  baseUrl: getBedrockRuntimeBaseUrl,