@ai-sdk/amazon-bedrock 3.0.0-canary.7 → 3.0.0-canary.9

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,26 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 3.0.0-canary.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 92c0b4b: chore(providers/bedrock): update embedding model to use providerOptions
8
+ - Updated dependencies [95857aa]
9
+ - Updated dependencies [7ea4132]
10
+ - @ai-sdk/provider@2.0.0-canary.8
11
+ - @ai-sdk/provider-utils@3.0.0-canary.9
12
+
13
+ ## 3.0.0-canary.8
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [5d142ab]
18
+ - Updated dependencies [b6b43c7]
19
+ - Updated dependencies [8aa9e20]
20
+ - Updated dependencies [3795467]
21
+ - @ai-sdk/provider-utils@3.0.0-canary.8
22
+ - @ai-sdk/provider@2.0.0-canary.7
23
+
3
24
  ## 3.0.0-canary.7
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -36,18 +36,6 @@ declare const bedrockProviderOptions: z.ZodObject<{
36
36
  type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
37
37
 
38
38
  type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
39
- interface BedrockEmbeddingSettings {
40
- /**
41
- The number of dimensions the resulting output embeddings should have (defaults to 1024).
42
- Only supported in amazon.titan-embed-text-v2:0.
43
- */
44
- dimensions?: 1024 | 512 | 256;
45
- /**
46
- Flag indicating whether or not to normalize the output embeddings. Defaults to true
47
- Only supported in amazon.titan-embed-text-v2:0.
48
- */
49
- normalize?: boolean;
50
- }
51
39
 
52
40
  type BedrockImageModelId = 'amazon.nova-canvas-v1:0' | (string & {});
53
41
  interface BedrockImageSettings {
@@ -111,7 +99,7 @@ interface AmazonBedrockProviderSettings {
111
99
  interface AmazonBedrockProvider extends ProviderV2 {
112
100
  (modelId: BedrockChatModelId): LanguageModelV2;
113
101
  languageModel(modelId: BedrockChatModelId): LanguageModelV2;
114
- embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV2<string>;
102
+ embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV2<string>;
115
103
  image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
116
104
  imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
117
105
  }
package/dist/index.d.ts CHANGED
@@ -36,18 +36,6 @@ declare const bedrockProviderOptions: z.ZodObject<{
36
36
  type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
37
37
 
38
38
  type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
39
- interface BedrockEmbeddingSettings {
40
- /**
41
- The number of dimensions the resulting output embeddings should have (defaults to 1024).
42
- Only supported in amazon.titan-embed-text-v2:0.
43
- */
44
- dimensions?: 1024 | 512 | 256;
45
- /**
46
- Flag indicating whether or not to normalize the output embeddings. Defaults to true
47
- Only supported in amazon.titan-embed-text-v2:0.
48
- */
49
- normalize?: boolean;
50
- }
51
39
 
52
40
  type BedrockImageModelId = 'amazon.nova-canvas-v1:0' | (string & {});
53
41
  interface BedrockImageSettings {
@@ -111,7 +99,7 @@ interface AmazonBedrockProviderSettings {
111
99
  interface AmazonBedrockProvider extends ProviderV2 {
112
100
  (modelId: BedrockChatModelId): LanguageModelV2;
113
101
  languageModel(modelId: BedrockChatModelId): LanguageModelV2;
114
- embedding(modelId: BedrockEmbeddingModelId, settings?: BedrockEmbeddingSettings): EmbeddingModelV2<string>;
102
+ embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV2<string>;
115
103
  image(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
116
104
  imageModel(modelId: BedrockImageModelId, settings?: BedrockImageSettings): ImageModelV1;
117
105
  }
package/dist/index.js CHANGED
@@ -502,8 +502,6 @@ var BedrockChatLanguageModel = class {
502
502
  this.config = config;
503
503
  this.specificationVersion = "v2";
504
504
  this.provider = "amazon-bedrock";
505
- this.defaultObjectGenerationMode = "tool";
506
- this.supportsImageUrls = false;
507
505
  }
508
506
  getArgs({
509
507
  prompt,
@@ -612,8 +610,13 @@ var BedrockChatLanguageModel = class {
612
610
  warnings: [...warnings, ...toolWarnings]
613
611
  };
614
612
  }
613
+ async getSupportedUrls() {
614
+ return {
615
+ // no supported urls for bedrock
616
+ };
617
+ }
615
618
  async doGenerate(options) {
616
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
619
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
617
620
  const { command: args, warnings } = this.getArgs(options);
618
621
  const url = `${this.getUrl(this.modelId)}/converse`;
619
622
  const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
@@ -636,71 +639,68 @@ var BedrockChatLanguageModel = class {
636
639
  abortSignal: options.abortSignal,
637
640
  fetch: this.config.fetch
638
641
  });
639
- const providerMetadata = response.trace || response.usage ? {
640
- bedrock: {
641
- ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
642
- ...response.usage && {
643
- usage: {
644
- cacheReadInputTokens: (_b = (_a = response.usage) == null ? void 0 : _a.cacheReadInputTokens) != null ? _b : Number.NaN,
645
- cacheWriteInputTokens: (_d = (_c = response.usage) == null ? void 0 : _c.cacheWriteInputTokens) != null ? _d : Number.NaN
646
- }
647
- }
642
+ const content = [];
643
+ for (const part of response.output.message.content) {
644
+ if (part.text) {
645
+ content.push({ type: "text", text: part.text });
648
646
  }
649
- } : void 0;
650
- const reasoning = [];
651
- for (const content of response.output.message.content) {
652
- if (content.reasoningContent) {
653
- if ("reasoningText" in content.reasoningContent) {
654
- reasoning.push({
647
+ if (part.reasoningContent) {
648
+ if ("reasoningText" in part.reasoningContent) {
649
+ content.push({
655
650
  type: "reasoning",
656
651
  reasoningType: "text",
657
- text: content.reasoningContent.reasoningText.text
652
+ text: part.reasoningContent.reasoningText.text
658
653
  });
659
- if (content.reasoningContent.reasoningText.signature) {
660
- reasoning.push({
654
+ if (part.reasoningContent.reasoningText.signature) {
655
+ content.push({
661
656
  type: "reasoning",
662
657
  reasoningType: "signature",
663
- signature: content.reasoningContent.reasoningText.signature
658
+ signature: part.reasoningContent.reasoningText.signature
664
659
  });
665
660
  }
666
- } else if ("redactedReasoning" in content.reasoningContent) {
667
- reasoning.push({
661
+ } else if ("redactedReasoning" in part.reasoningContent) {
662
+ content.push({
668
663
  type: "reasoning",
669
664
  reasoningType: "redacted",
670
- data: (_e = content.reasoningContent.redactedReasoning.data) != null ? _e : ""
665
+ data: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
671
666
  });
672
667
  }
673
668
  }
674
- }
675
- const text = (_h = (_g = (_f = response.output) == null ? void 0 : _f.message) == null ? void 0 : _g.content) == null ? void 0 : _h.map((part) => {
676
- var _a2;
677
- return (_a2 = part.text) != null ? _a2 : "";
678
- }).join("");
679
- return {
680
- text: text != null ? { type: "text", text } : void 0,
681
- toolCalls: (_l = (_k = (_j = (_i = response.output) == null ? void 0 : _i.message) == null ? void 0 : _j.content) == null ? void 0 : _k.filter((part) => !!part.toolUse)) == null ? void 0 : _l.map((part) => {
682
- var _a2, _b2, _c2, _d2, _e2, _f2;
683
- return {
669
+ if (part.toolUse) {
670
+ content.push({
684
671
  type: "tool-call",
685
672
  toolCallType: "function",
686
- toolCallId: (_b2 = (_a2 = part.toolUse) == null ? void 0 : _a2.toolUseId) != null ? _b2 : this.config.generateId(),
687
- toolName: (_d2 = (_c2 = part.toolUse) == null ? void 0 : _c2.name) != null ? _d2 : `tool-${this.config.generateId()}`,
688
- args: JSON.stringify((_f2 = (_e2 = part.toolUse) == null ? void 0 : _e2.input) != null ? _f2 : "")
689
- };
690
- }),
673
+ toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
674
+ toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
675
+ args: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
676
+ });
677
+ }
678
+ }
679
+ const providerMetadata = response.trace || response.usage ? {
680
+ bedrock: {
681
+ ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
682
+ ...response.usage && {
683
+ usage: {
684
+ cacheReadInputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.cacheReadInputTokens) != null ? _i : Number.NaN,
685
+ cacheWriteInputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null ? _k : Number.NaN
686
+ }
687
+ }
688
+ }
689
+ } : void 0;
690
+ return {
691
+ content,
691
692
  finishReason: mapBedrockFinishReason(
692
693
  response.stopReason
693
694
  ),
694
695
  usage: {
695
- inputTokens: (_m = response.usage) == null ? void 0 : _m.inputTokens,
696
- outputTokens: (_n = response.usage) == null ? void 0 : _n.outputTokens
696
+ inputTokens: (_l = response.usage) == null ? void 0 : _l.inputTokens,
697
+ outputTokens: (_m = response.usage) == null ? void 0 : _m.outputTokens
697
698
  },
698
699
  response: {
699
700
  // TODO add id, timestamp, etc
700
701
  headers: responseHeaders
701
702
  },
702
703
  warnings,
703
- reasoning: reasoning.length > 0 ? reasoning : void 0,
704
704
  ...providerMetadata && { providerMetadata }
705
705
  };
706
706
  }
@@ -732,6 +732,9 @@ var BedrockChatLanguageModel = class {
732
732
  return {
733
733
  stream: response.pipeThrough(
734
734
  new TransformStream({
735
+ start(controller) {
736
+ controller.enqueue({ type: "stream-start", warnings });
737
+ },
735
738
  transform(chunk, controller) {
736
739
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
737
740
  function enqueueError(bedrockError) {
@@ -861,8 +864,8 @@ var BedrockChatLanguageModel = class {
861
864
  }
862
865
  })
863
866
  ),
864
- response: { headers: responseHeaders },
865
- warnings
867
+ // TODO request?
868
+ response: { headers: responseHeaders }
866
869
  };
867
870
  }
868
871
  getUrl(modelId) {
@@ -968,11 +971,27 @@ var BedrockStreamSchema = import_zod3.z.object({
968
971
 
969
972
  // src/bedrock-embedding-model.ts
970
973
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
974
+
975
+ // src/bedrock-embedding-options.ts
971
976
  var import_zod4 = require("zod");
977
+ var bedrockEmbeddingProviderOptions = import_zod4.z.object({
978
+ /**
979
+ The number of dimensions the resulting output embeddings should have (defaults to 1024).
980
+ Only supported in amazon.titan-embed-text-v2:0.
981
+ */
982
+ dimensions: import_zod4.z.union([import_zod4.z.literal(1024), import_zod4.z.literal(512), import_zod4.z.literal(256)]).optional(),
983
+ /**
984
+ Flag indicating whether or not to normalize the output embeddings. Defaults to true
985
+ Only supported in amazon.titan-embed-text-v2:0.
986
+ */
987
+ normalize: import_zod4.z.boolean().optional()
988
+ });
989
+
990
+ // src/bedrock-embedding-model.ts
991
+ var import_zod5 = require("zod");
972
992
  var BedrockEmbeddingModel = class {
973
- constructor(modelId, settings, config) {
993
+ constructor(modelId, config) {
974
994
  this.modelId = modelId;
975
- this.settings = settings;
976
995
  this.config = config;
977
996
  this.specificationVersion = "v2";
978
997
  this.provider = "amazon-bedrock";
@@ -986,13 +1005,20 @@ var BedrockEmbeddingModel = class {
986
1005
  async doEmbed({
987
1006
  values,
988
1007
  headers,
989
- abortSignal
1008
+ abortSignal,
1009
+ providerOptions
990
1010
  }) {
1011
+ var _a;
1012
+ const bedrockOptions = (_a = (0, import_provider_utils4.parseProviderOptions)({
1013
+ provider: "bedrock",
1014
+ providerOptions,
1015
+ schema: bedrockEmbeddingProviderOptions
1016
+ })) != null ? _a : {};
991
1017
  const embedSingleText = async (inputText) => {
992
1018
  const args = {
993
1019
  inputText,
994
- dimensions: this.settings.dimensions,
995
- normalize: this.settings.normalize
1020
+ dimensions: bedrockOptions.dimensions,
1021
+ normalize: bedrockOptions.normalize
996
1022
  };
997
1023
  const url = this.getUrl(this.modelId);
998
1024
  const { value: response } = await (0, import_provider_utils4.postJsonToApi)({
@@ -1027,9 +1053,9 @@ var BedrockEmbeddingModel = class {
1027
1053
  );
1028
1054
  }
1029
1055
  };
1030
- var BedrockEmbeddingResponseSchema = import_zod4.z.object({
1031
- embedding: import_zod4.z.array(import_zod4.z.number()),
1032
- inputTextTokenCount: import_zod4.z.number()
1056
+ var BedrockEmbeddingResponseSchema = import_zod5.z.object({
1057
+ embedding: import_zod5.z.array(import_zod5.z.number()),
1058
+ inputTextTokenCount: import_zod5.z.number()
1033
1059
  });
1034
1060
 
1035
1061
  // src/bedrock-image-model.ts
@@ -1041,7 +1067,7 @@ var modelMaxImagesPerCall = {
1041
1067
  };
1042
1068
 
1043
1069
  // src/bedrock-image-model.ts
1044
- var import_zod5 = require("zod");
1070
+ var import_zod6 = require("zod");
1045
1071
  var BedrockImageModel = class {
1046
1072
  constructor(modelId, settings, config) {
1047
1073
  this.modelId = modelId;
@@ -1123,8 +1149,8 @@ var BedrockImageModel = class {
1123
1149
  };
1124
1150
  }
1125
1151
  };
1126
- var bedrockImageResponseSchema = import_zod5.z.object({
1127
- images: import_zod5.z.array(import_zod5.z.string())
1152
+ var bedrockImageResponseSchema = import_zod6.z.object({
1153
+ images: import_zod6.z.array(import_zod6.z.string())
1128
1154
  });
1129
1155
 
1130
1156
  // src/headers-utils.ts
@@ -1263,9 +1289,9 @@ function createAmazonBedrock(options = {}) {
1263
1289
  }
1264
1290
  return createChatModel(modelId);
1265
1291
  };
1266
- const createEmbeddingModel = (modelId, settings = {}) => {
1292
+ const createEmbeddingModel = (modelId) => {
1267
1293
  var _a;
1268
- return new BedrockEmbeddingModel(modelId, settings, {
1294
+ return new BedrockEmbeddingModel(modelId, {
1269
1295
  baseUrl: getBaseUrl,
1270
1296
  headers: (_a = options.headers) != null ? _a : {},
1271
1297
  fetch: sigv4Fetch