@ai-sdk/amazon-bedrock 4.0.2 → 4.0.4

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,21 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 4.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 863d34f: fix: trigger release to update `@latest`
8
+ - Updated dependencies [863d34f]
9
+ - @ai-sdk/anthropic@3.0.2
10
+ - @ai-sdk/provider@3.0.1
11
+ - @ai-sdk/provider-utils@4.0.2
12
+
13
+ ## 4.0.3
14
+
15
+ ### Patch Changes
16
+
17
+ - afe9730: Fix bedrock ConverseStream using /delta/stop_sequence
18
+
3
19
  ## 4.0.2
4
20
 
5
21
  ### Patch Changes
package/dist/index.js CHANGED
@@ -917,12 +917,15 @@ var BedrockChatLanguageModel = class {
917
917
  additionalModelRequestFields: __,
918
918
  ...filteredBedrockOptions
919
919
  } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
920
+ const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
920
921
  return {
921
922
  command: {
922
923
  system,
923
924
  messages,
924
925
  additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
925
- additionalModelResponseFieldPaths: ["/stop_sequence"],
926
+ ...additionalModelResponseFieldPaths && {
927
+ additionalModelResponseFieldPaths
928
+ },
926
929
  ...Object.keys(inferenceConfig).length > 0 && {
927
930
  inferenceConfig
928
931
  },
@@ -940,7 +943,7 @@ var BedrockChatLanguageModel = class {
940
943
  return (0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers);
941
944
  }
942
945
  async doGenerate(options) {
943
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
946
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
944
947
  const {
945
948
  command: args,
946
949
  warnings,
@@ -1014,11 +1017,11 @@ var BedrockChatLanguageModel = class {
1014
1017
  }
1015
1018
  }
1016
1019
  }
1017
- const stopSequence = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.stop_sequence) != null ? _i : null;
1020
+ const stopSequence = (_j = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.delta) == null ? void 0 : _i.stop_sequence) != null ? _j : null;
1018
1021
  const providerMetadata = response.trace || response.usage || isJsonResponseFromTool || stopSequence ? {
1019
1022
  bedrock: {
1020
1023
  ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
1021
- ...((_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null && {
1024
+ ...((_k = response.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null && {
1022
1025
  usage: {
1023
1026
  cacheWriteInputTokens: response.usage.cacheWriteInputTokens
1024
1027
  }
@@ -1034,7 +1037,7 @@ var BedrockChatLanguageModel = class {
1034
1037
  response.stopReason,
1035
1038
  isJsonResponseFromTool
1036
1039
  ),
1037
- raw: (_k = response.stopReason) != null ? _k : void 0
1040
+ raw: (_l = response.stopReason) != null ? _l : void 0
1038
1041
  },
1039
1042
  usage: convertBedrockUsage(response.usage),
1040
1043
  response: {
@@ -1080,7 +1083,7 @@ var BedrockChatLanguageModel = class {
1080
1083
  controller.enqueue({ type: "stream-start", warnings });
1081
1084
  },
1082
1085
  transform(chunk, controller) {
1083
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1086
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1084
1087
  function enqueueError(bedrockError) {
1085
1088
  finishReason = { unified: "error", raw: void 0 };
1086
1089
  controller.enqueue({ type: "error", error: bedrockError });
@@ -1117,13 +1120,13 @@ var BedrockChatLanguageModel = class {
1117
1120
  ),
1118
1121
  raw: (_a = value.messageStop.stopReason) != null ? _a : void 0
1119
1122
  };
1120
- stopSequence = (_c = (_b = value.messageStop.additionalModelResponseFields) == null ? void 0 : _b.stop_sequence) != null ? _c : null;
1123
+ stopSequence = (_d = (_c = (_b = value.messageStop.additionalModelResponseFields) == null ? void 0 : _b.delta) == null ? void 0 : _c.stop_sequence) != null ? _d : null;
1121
1124
  }
1122
1125
  if (value.metadata) {
1123
1126
  if (value.metadata.usage) {
1124
1127
  usage = value.metadata.usage;
1125
1128
  }
1126
- const cacheUsage = ((_d = value.metadata.usage) == null ? void 0 : _d.cacheWriteInputTokens) != null ? {
1129
+ const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheWriteInputTokens) != null ? {
1127
1130
  usage: {
1128
1131
  cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
1129
1132
  }
@@ -1140,7 +1143,7 @@ var BedrockChatLanguageModel = class {
1140
1143
  };
1141
1144
  }
1142
1145
  }
1143
- if (((_e = value.contentBlockStart) == null ? void 0 : _e.contentBlockIndex) != null && !((_g = (_f = value.contentBlockStart) == null ? void 0 : _f.start) == null ? void 0 : _g.toolUse)) {
1146
+ if (((_f = value.contentBlockStart) == null ? void 0 : _f.contentBlockIndex) != null && !((_h = (_g = value.contentBlockStart) == null ? void 0 : _g.start) == null ? void 0 : _h.toolUse)) {
1144
1147
  const blockIndex = value.contentBlockStart.contentBlockIndex;
1145
1148
  contentBlocks[blockIndex] = { type: "text" };
1146
1149
  controller.enqueue({
@@ -1148,7 +1151,7 @@ var BedrockChatLanguageModel = class {
1148
1151
  id: String(blockIndex)
1149
1152
  });
1150
1153
  }
1151
- if (((_h = value.contentBlockDelta) == null ? void 0 : _h.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1154
+ if (((_i = value.contentBlockDelta) == null ? void 0 : _i.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1152
1155
  const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1153
1156
  if (contentBlocks[blockIndex] == null) {
1154
1157
  contentBlocks[blockIndex] = { type: "text" };
@@ -1163,7 +1166,7 @@ var BedrockChatLanguageModel = class {
1163
1166
  delta: value.contentBlockDelta.delta.text
1164
1167
  });
1165
1168
  }
1166
- if (((_i = value.contentBlockStop) == null ? void 0 : _i.contentBlockIndex) != null) {
1169
+ if (((_j = value.contentBlockStop) == null ? void 0 : _j.contentBlockIndex) != null) {
1167
1170
  const blockIndex = value.contentBlockStop.contentBlockIndex;
1168
1171
  const contentBlock = contentBlocks[blockIndex];
1169
1172
  if (contentBlock != null) {
@@ -1209,7 +1212,7 @@ var BedrockChatLanguageModel = class {
1209
1212
  delete contentBlocks[blockIndex];
1210
1213
  }
1211
1214
  }
1212
- if (((_j = value.contentBlockDelta) == null ? void 0 : _j.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1215
+ if (((_k = value.contentBlockDelta) == null ? void 0 : _k.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1213
1216
  const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1214
1217
  const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
1215
1218
  if ("text" in reasoningContent && reasoningContent.text) {
@@ -1250,7 +1253,7 @@ var BedrockChatLanguageModel = class {
1250
1253
  }
1251
1254
  }
1252
1255
  const contentBlockStart = value.contentBlockStart;
1253
- if (((_k = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _k.toolUse) != null) {
1256
+ if (((_l = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _l.toolUse) != null) {
1254
1257
  const toolUse = contentBlockStart.start.toolUse;
1255
1258
  const blockIndex = contentBlockStart.contentBlockIndex;
1256
1259
  const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
@@ -1274,7 +1277,7 @@ var BedrockChatLanguageModel = class {
1274
1277
  const blockIndex = contentBlockDelta.contentBlockIndex;
1275
1278
  const contentBlock = contentBlocks[blockIndex];
1276
1279
  if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
1277
- const delta = (_l = contentBlockDelta.delta.toolUse.input) != null ? _l : "";
1280
+ const delta = (_m = contentBlockDelta.delta.toolUse.input) != null ? _m : "";
1278
1281
  if (!contentBlock.isJsonResponseTool) {
1279
1282
  controller.enqueue({
1280
1283
  type: "tool-input-delta",
@@ -1330,7 +1333,9 @@ var BedrockStopReasonSchema = import_v43.z.union([
1330
1333
  import_v43.z.string()
1331
1334
  ]);
1332
1335
  var BedrockAdditionalModelResponseFieldsSchema = import_v43.z.object({
1333
- stop_sequence: import_v43.z.string().nullish()
1336
+ delta: import_v43.z.object({
1337
+ stop_sequence: import_v43.z.string().nullish()
1338
+ }).nullish()
1334
1339
  }).catchall(import_v43.z.unknown());
1335
1340
  var BedrockToolUseSchema = import_v43.z.object({
1336
1341
  toolUseId: import_v43.z.string(),
@@ -1729,7 +1734,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1729
1734
  var import_aws4fetch = require("aws4fetch");
1730
1735
 
1731
1736
  // src/version.ts
1732
- var VERSION = true ? "4.0.2" : "0.0.0-test";
1737
+ var VERSION = true ? "4.0.4" : "0.0.0-test";
1733
1738
 
1734
1739
  // src/bedrock-sigv4-fetch.ts
1735
1740
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {