@ai-sdk/amazon-bedrock 4.0.0-beta.99 → 4.0.0

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/dist/index.mjs CHANGED
@@ -92,45 +92,6 @@ var BedrockErrorSchema = z2.object({
92
92
  type: z2.string().nullish()
93
93
  });
94
94
 
95
- // src/convert-bedrock-usage.ts
96
- function convertBedrockUsage(usage) {
97
- var _a, _b;
98
- if (usage == null) {
99
- return {
100
- inputTokens: {
101
- total: void 0,
102
- noCache: void 0,
103
- cacheRead: void 0,
104
- cacheWrite: void 0
105
- },
106
- outputTokens: {
107
- total: void 0,
108
- text: void 0,
109
- reasoning: void 0
110
- },
111
- raw: void 0
112
- };
113
- }
114
- const inputTokens = usage.inputTokens;
115
- const outputTokens = usage.outputTokens;
116
- const cacheReadTokens = (_a = usage.cacheReadInputTokens) != null ? _a : 0;
117
- const cacheWriteTokens = (_b = usage.cacheWriteInputTokens) != null ? _b : 0;
118
- return {
119
- inputTokens: {
120
- total: inputTokens,
121
- noCache: inputTokens - cacheReadTokens,
122
- cacheRead: cacheReadTokens,
123
- cacheWrite: cacheWriteTokens
124
- },
125
- outputTokens: {
126
- total: outputTokens,
127
- text: outputTokens,
128
- reasoning: void 0
129
- },
130
- raw: usage
131
- };
132
- }
133
-
134
95
  // src/bedrock-event-stream-response-handler.ts
135
96
  import { EmptyResponseBodyError } from "@ai-sdk/provider";
136
97
  import {
@@ -349,6 +310,45 @@ async function prepareTools({
349
310
  };
350
311
  }
351
312
 
313
+ // src/convert-bedrock-usage.ts
314
+ function convertBedrockUsage(usage) {
315
+ var _a, _b;
316
+ if (usage == null) {
317
+ return {
318
+ inputTokens: {
319
+ total: void 0,
320
+ noCache: void 0,
321
+ cacheRead: void 0,
322
+ cacheWrite: void 0
323
+ },
324
+ outputTokens: {
325
+ total: void 0,
326
+ text: void 0,
327
+ reasoning: void 0
328
+ },
329
+ raw: void 0
330
+ };
331
+ }
332
+ const inputTokens = usage.inputTokens;
333
+ const outputTokens = usage.outputTokens;
334
+ const cacheReadTokens = (_a = usage.cacheReadInputTokens) != null ? _a : 0;
335
+ const cacheWriteTokens = (_b = usage.cacheWriteInputTokens) != null ? _b : 0;
336
+ return {
337
+ inputTokens: {
338
+ total: inputTokens,
339
+ noCache: inputTokens - cacheReadTokens,
340
+ cacheRead: cacheReadTokens,
341
+ cacheWrite: cacheWriteTokens
342
+ },
343
+ outputTokens: {
344
+ total: outputTokens,
345
+ text: outputTokens,
346
+ reasoning: void 0
347
+ },
348
+ raw: usage
349
+ };
350
+ }
351
+
352
352
  // src/convert-to-bedrock-chat-messages.ts
353
353
  import {
354
354
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
@@ -450,6 +450,9 @@ async function convertToBedrockChatMessages(prompt) {
450
450
  }
451
451
  case "tool": {
452
452
  for (const part of content) {
453
+ if (part.type === "tool-approval-response") {
454
+ continue;
455
+ }
453
456
  let toolResultContent;
454
457
  const output = part.output;
455
458
  switch (output.type) {
@@ -702,7 +705,7 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
702
705
  case "tool_use":
703
706
  return isJsonResponseFromTool ? "stop" : "tool-calls";
704
707
  default:
705
- return "unknown";
708
+ return "other";
706
709
  }
707
710
  }
708
711
 
@@ -915,6 +918,7 @@ var BedrockChatLanguageModel = class {
915
918
  system,
916
919
  messages,
917
920
  additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
921
+ additionalModelResponseFieldPaths: ["/stop_sequence"],
918
922
  ...Object.keys(inferenceConfig).length > 0 && {
919
923
  inferenceConfig
920
924
  },
@@ -932,7 +936,7 @@ var BedrockChatLanguageModel = class {
932
936
  return combineHeaders(await resolve(this.config.headers), headers);
933
937
  }
934
938
  async doGenerate(options) {
935
- var _a, _b, _c, _d, _e, _f, _g, _h;
939
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
936
940
  const {
937
941
  command: args,
938
942
  warnings,
@@ -1006,23 +1010,28 @@ var BedrockChatLanguageModel = class {
1006
1010
  }
1007
1011
  }
1008
1012
  }
1009
- const providerMetadata = response.trace || response.usage || isJsonResponseFromTool ? {
1013
+ const stopSequence = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.stop_sequence) != null ? _i : null;
1014
+ const providerMetadata = response.trace || response.usage || isJsonResponseFromTool || stopSequence ? {
1010
1015
  bedrock: {
1011
1016
  ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
1012
- ...((_h = response.usage) == null ? void 0 : _h.cacheWriteInputTokens) != null && {
1017
+ ...((_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null && {
1013
1018
  usage: {
1014
1019
  cacheWriteInputTokens: response.usage.cacheWriteInputTokens
1015
1020
  }
1016
1021
  },
1017
- ...isJsonResponseFromTool && { isJsonResponseFromTool: true }
1022
+ ...isJsonResponseFromTool && { isJsonResponseFromTool: true },
1023
+ stopSequence
1018
1024
  }
1019
1025
  } : void 0;
1020
1026
  return {
1021
1027
  content,
1022
- finishReason: mapBedrockFinishReason(
1023
- response.stopReason,
1024
- isJsonResponseFromTool
1025
- ),
1028
+ finishReason: {
1029
+ unified: mapBedrockFinishReason(
1030
+ response.stopReason,
1031
+ isJsonResponseFromTool
1032
+ ),
1033
+ raw: (_k = response.stopReason) != null ? _k : void 0
1034
+ },
1026
1035
  usage: convertBedrockUsage(response.usage),
1027
1036
  response: {
1028
1037
  // TODO add id, timestamp, etc
@@ -1051,10 +1060,14 @@ var BedrockChatLanguageModel = class {
1051
1060
  abortSignal: options.abortSignal,
1052
1061
  fetch: this.config.fetch
1053
1062
  });
1054
- let finishReason = "unknown";
1063
+ let finishReason = {
1064
+ unified: "other",
1065
+ raw: void 0
1066
+ };
1055
1067
  let usage = void 0;
1056
1068
  let providerMetadata = void 0;
1057
1069
  let isJsonResponseFromTool = false;
1070
+ let stopSequence = null;
1058
1071
  const contentBlocks = {};
1059
1072
  return {
1060
1073
  stream: response.pipeThrough(
@@ -1063,9 +1076,9 @@ var BedrockChatLanguageModel = class {
1063
1076
  controller.enqueue({ type: "stream-start", warnings });
1064
1077
  },
1065
1078
  transform(chunk, controller) {
1066
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1079
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1067
1080
  function enqueueError(bedrockError) {
1068
- finishReason = "error";
1081
+ finishReason = { unified: "error", raw: void 0 };
1069
1082
  controller.enqueue({ type: "error", error: bedrockError });
1070
1083
  }
1071
1084
  if (options.includeRawChunks) {
@@ -1093,16 +1106,20 @@ var BedrockChatLanguageModel = class {
1093
1106
  return;
1094
1107
  }
1095
1108
  if (value.messageStop) {
1096
- finishReason = mapBedrockFinishReason(
1097
- value.messageStop.stopReason,
1098
- isJsonResponseFromTool
1099
- );
1109
+ finishReason = {
1110
+ unified: mapBedrockFinishReason(
1111
+ value.messageStop.stopReason,
1112
+ isJsonResponseFromTool
1113
+ ),
1114
+ raw: (_a = value.messageStop.stopReason) != null ? _a : void 0
1115
+ };
1116
+ stopSequence = (_c = (_b = value.messageStop.additionalModelResponseFields) == null ? void 0 : _b.stop_sequence) != null ? _c : null;
1100
1117
  }
1101
1118
  if (value.metadata) {
1102
1119
  if (value.metadata.usage) {
1103
1120
  usage = value.metadata.usage;
1104
1121
  }
1105
- const cacheUsage = ((_a = value.metadata.usage) == null ? void 0 : _a.cacheWriteInputTokens) != null ? {
1122
+ const cacheUsage = ((_d = value.metadata.usage) == null ? void 0 : _d.cacheWriteInputTokens) != null ? {
1106
1123
  usage: {
1107
1124
  cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
1108
1125
  }
@@ -1119,7 +1136,7 @@ var BedrockChatLanguageModel = class {
1119
1136
  };
1120
1137
  }
1121
1138
  }
1122
- if (((_b = value.contentBlockStart) == null ? void 0 : _b.contentBlockIndex) != null && !((_d = (_c = value.contentBlockStart) == null ? void 0 : _c.start) == null ? void 0 : _d.toolUse)) {
1139
+ if (((_e = value.contentBlockStart) == null ? void 0 : _e.contentBlockIndex) != null && !((_g = (_f = value.contentBlockStart) == null ? void 0 : _f.start) == null ? void 0 : _g.toolUse)) {
1123
1140
  const blockIndex = value.contentBlockStart.contentBlockIndex;
1124
1141
  contentBlocks[blockIndex] = { type: "text" };
1125
1142
  controller.enqueue({
@@ -1127,7 +1144,7 @@ var BedrockChatLanguageModel = class {
1127
1144
  id: String(blockIndex)
1128
1145
  });
1129
1146
  }
1130
- if (((_e = value.contentBlockDelta) == null ? void 0 : _e.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1147
+ if (((_h = value.contentBlockDelta) == null ? void 0 : _h.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1131
1148
  const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1132
1149
  if (contentBlocks[blockIndex] == null) {
1133
1150
  contentBlocks[blockIndex] = { type: "text" };
@@ -1142,7 +1159,7 @@ var BedrockChatLanguageModel = class {
1142
1159
  delta: value.contentBlockDelta.delta.text
1143
1160
  });
1144
1161
  }
1145
- if (((_f = value.contentBlockStop) == null ? void 0 : _f.contentBlockIndex) != null) {
1162
+ if (((_i = value.contentBlockStop) == null ? void 0 : _i.contentBlockIndex) != null) {
1146
1163
  const blockIndex = value.contentBlockStop.contentBlockIndex;
1147
1164
  const contentBlock = contentBlocks[blockIndex];
1148
1165
  if (contentBlock != null) {
@@ -1188,7 +1205,7 @@ var BedrockChatLanguageModel = class {
1188
1205
  delete contentBlocks[blockIndex];
1189
1206
  }
1190
1207
  }
1191
- if (((_g = value.contentBlockDelta) == null ? void 0 : _g.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1208
+ if (((_j = value.contentBlockDelta) == null ? void 0 : _j.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1192
1209
  const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1193
1210
  const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
1194
1211
  if ("text" in reasoningContent && reasoningContent.text) {
@@ -1229,7 +1246,7 @@ var BedrockChatLanguageModel = class {
1229
1246
  }
1230
1247
  }
1231
1248
  const contentBlockStart = value.contentBlockStart;
1232
- if (((_h = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _h.toolUse) != null) {
1249
+ if (((_k = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _k.toolUse) != null) {
1233
1250
  const toolUse = contentBlockStart.start.toolUse;
1234
1251
  const blockIndex = contentBlockStart.contentBlockIndex;
1235
1252
  const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
@@ -1253,7 +1270,7 @@ var BedrockChatLanguageModel = class {
1253
1270
  const blockIndex = contentBlockDelta.contentBlockIndex;
1254
1271
  const contentBlock = contentBlocks[blockIndex];
1255
1272
  if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
1256
- const delta = (_i = contentBlockDelta.delta.toolUse.input) != null ? _i : "";
1273
+ const delta = (_l = contentBlockDelta.delta.toolUse.input) != null ? _l : "";
1257
1274
  if (!contentBlock.isJsonResponseTool) {
1258
1275
  controller.enqueue({
1259
1276
  type: "tool-input-delta",
@@ -1266,16 +1283,22 @@ var BedrockChatLanguageModel = class {
1266
1283
  }
1267
1284
  },
1268
1285
  flush(controller) {
1269
- if (isJsonResponseFromTool) {
1286
+ if (isJsonResponseFromTool || stopSequence != null) {
1270
1287
  if (providerMetadata) {
1271
1288
  providerMetadata.bedrock = {
1272
1289
  ...providerMetadata.bedrock,
1273
- isJsonResponseFromTool: true
1290
+ ...isJsonResponseFromTool && {
1291
+ isJsonResponseFromTool: true
1292
+ },
1293
+ stopSequence
1274
1294
  };
1275
1295
  } else {
1276
1296
  providerMetadata = {
1277
1297
  bedrock: {
1278
- isJsonResponseFromTool: true
1298
+ ...isJsonResponseFromTool && {
1299
+ isJsonResponseFromTool: true
1300
+ },
1301
+ stopSequence
1279
1302
  }
1280
1303
  };
1281
1304
  }
@@ -1302,6 +1325,9 @@ var BedrockStopReasonSchema = z3.union([
1302
1325
  z3.enum(BEDROCK_STOP_REASONS),
1303
1326
  z3.string()
1304
1327
  ]);
1328
+ var BedrockAdditionalModelResponseFieldsSchema = z3.object({
1329
+ stop_sequence: z3.string().optional()
1330
+ }).catchall(z3.unknown());
1305
1331
  var BedrockToolUseSchema = z3.object({
1306
1332
  toolUseId: z3.string(),
1307
1333
  name: z3.string(),
@@ -1338,6 +1364,7 @@ var BedrockResponseSchema = z3.object({
1338
1364
  })
1339
1365
  }),
1340
1366
  stopReason: BedrockStopReasonSchema,
1367
+ additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
1341
1368
  trace: z3.unknown().nullish(),
1342
1369
  usage: z3.object({
1343
1370
  inputTokens: z3.number(),
@@ -1377,7 +1404,7 @@ var BedrockStreamSchema = z3.object({
1377
1404
  }).nullish(),
1378
1405
  internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
1379
1406
  messageStop: z3.object({
1380
- additionalModelResponseFields: z3.record(z3.string(), z3.unknown()).nullish(),
1407
+ additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
1381
1408
  stopReason: BedrockStopReasonSchema
1382
1409
  }).nullish(),
1383
1410
  metadata: z3.object({
@@ -1498,6 +1525,7 @@ var BedrockEmbeddingResponseSchema = z5.object({
1498
1525
  // src/bedrock-image-model.ts
1499
1526
  import {
1500
1527
  combineHeaders as combineHeaders3,
1528
+ convertUint8ArrayToBase64,
1501
1529
  createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
1502
1530
  createJsonResponseHandler as createJsonResponseHandler3,
1503
1531
  postJsonToApi as postJsonToApi3,
@@ -1534,31 +1562,110 @@ var BedrockImageModel = class {
1534
1562
  seed,
1535
1563
  providerOptions,
1536
1564
  headers,
1537
- abortSignal
1565
+ abortSignal,
1566
+ files,
1567
+ mask
1538
1568
  }) {
1539
- var _a, _b, _c, _d, _e, _f, _g;
1569
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1540
1570
  const warnings = [];
1541
1571
  const [width, height] = size ? size.split("x").map(Number) : [];
1542
- const args = {
1543
- taskType: "TEXT_IMAGE",
1544
- textToImageParams: {
1545
- text: prompt,
1546
- ...((_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.negativeText) ? {
1547
- negativeText: providerOptions.bedrock.negativeText
1548
- } : {},
1549
- ...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.style) ? {
1550
- style: providerOptions.bedrock.style
1551
- } : {}
1552
- },
1553
- imageGenerationConfig: {
1554
- ...width ? { width } : {},
1555
- ...height ? { height } : {},
1556
- ...seed ? { seed } : {},
1557
- ...n ? { numberOfImages: n } : {},
1558
- ...((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.quality) ? { quality: providerOptions.bedrock.quality } : {},
1559
- ...((_d = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _d.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
1560
- }
1572
+ const hasFiles = files != null && files.length > 0;
1573
+ const imageGenerationConfig = {
1574
+ ...width ? { width } : {},
1575
+ ...height ? { height } : {},
1576
+ ...seed ? { seed } : {},
1577
+ ...n ? { numberOfImages: n } : {},
1578
+ ...((_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.quality) ? { quality: providerOptions.bedrock.quality } : {},
1579
+ ...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
1561
1580
  };
1581
+ let args;
1582
+ if (hasFiles) {
1583
+ const hasMask = (mask == null ? void 0 : mask.type) != null;
1584
+ const hasMaskPrompt = ((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.maskPrompt) != null;
1585
+ const taskType = (_e = (_d = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _d.taskType) != null ? _e : hasMask || hasMaskPrompt ? "INPAINTING" : "IMAGE_VARIATION";
1586
+ const sourceImageBase64 = getBase64Data(files[0]);
1587
+ switch (taskType) {
1588
+ case "INPAINTING": {
1589
+ const inPaintingParams = {
1590
+ image: sourceImageBase64,
1591
+ ...prompt ? { text: prompt } : {},
1592
+ ...((_f = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _f.negativeText) ? { negativeText: providerOptions.bedrock.negativeText } : {}
1593
+ };
1594
+ if (hasMask) {
1595
+ inPaintingParams.maskImage = getBase64Data(mask);
1596
+ } else if (hasMaskPrompt) {
1597
+ inPaintingParams.maskPrompt = providerOptions.bedrock.maskPrompt;
1598
+ }
1599
+ args = {
1600
+ taskType: "INPAINTING",
1601
+ inPaintingParams,
1602
+ imageGenerationConfig
1603
+ };
1604
+ break;
1605
+ }
1606
+ case "OUTPAINTING": {
1607
+ const outPaintingParams = {
1608
+ image: sourceImageBase64,
1609
+ ...prompt ? { text: prompt } : {},
1610
+ ...((_g = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _g.negativeText) ? { negativeText: providerOptions.bedrock.negativeText } : {},
1611
+ ...((_h = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _h.outPaintingMode) ? { outPaintingMode: providerOptions.bedrock.outPaintingMode } : {}
1612
+ };
1613
+ if (hasMask) {
1614
+ outPaintingParams.maskImage = getBase64Data(mask);
1615
+ } else if (hasMaskPrompt) {
1616
+ outPaintingParams.maskPrompt = providerOptions.bedrock.maskPrompt;
1617
+ }
1618
+ args = {
1619
+ taskType: "OUTPAINTING",
1620
+ outPaintingParams,
1621
+ imageGenerationConfig
1622
+ };
1623
+ break;
1624
+ }
1625
+ case "BACKGROUND_REMOVAL": {
1626
+ args = {
1627
+ taskType: "BACKGROUND_REMOVAL",
1628
+ backgroundRemovalParams: {
1629
+ image: sourceImageBase64
1630
+ }
1631
+ };
1632
+ break;
1633
+ }
1634
+ case "IMAGE_VARIATION": {
1635
+ const images = files.map((file) => getBase64Data(file));
1636
+ const imageVariationParams = {
1637
+ images,
1638
+ ...prompt ? { text: prompt } : {},
1639
+ ...((_i = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _i.negativeText) ? { negativeText: providerOptions.bedrock.negativeText } : {},
1640
+ ...((_j = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _j.similarityStrength) != null ? {
1641
+ similarityStrength: providerOptions.bedrock.similarityStrength
1642
+ } : {}
1643
+ };
1644
+ args = {
1645
+ taskType: "IMAGE_VARIATION",
1646
+ imageVariationParams,
1647
+ imageGenerationConfig
1648
+ };
1649
+ break;
1650
+ }
1651
+ default:
1652
+ throw new Error(`Unsupported task type: ${taskType}`);
1653
+ }
1654
+ } else {
1655
+ args = {
1656
+ taskType: "TEXT_IMAGE",
1657
+ textToImageParams: {
1658
+ text: prompt,
1659
+ ...((_k = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _k.negativeText) ? {
1660
+ negativeText: providerOptions.bedrock.negativeText
1661
+ } : {},
1662
+ ...((_l = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _l.style) ? {
1663
+ style: providerOptions.bedrock.style
1664
+ } : {}
1665
+ },
1666
+ imageGenerationConfig
1667
+ };
1668
+ }
1562
1669
  if (aspectRatio != void 0) {
1563
1670
  warnings.push({
1564
1671
  type: "unsupported",
@@ -1566,7 +1673,7 @@ var BedrockImageModel = class {
1566
1673
  details: "This model does not support aspect ratio. Use `size` instead."
1567
1674
  });
1568
1675
  }
1569
- const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
1676
+ const currentDate = (_o = (_n = (_m = this.config._internal) == null ? void 0 : _m.currentDate) == null ? void 0 : _n.call(_m)) != null ? _o : /* @__PURE__ */ new Date();
1570
1677
  const { value: response, responseHeaders } = await postJsonToApi3({
1571
1678
  url: this.getUrl(this.modelId),
1572
1679
  headers: await resolve3(
@@ -1583,6 +1690,18 @@ var BedrockImageModel = class {
1583
1690
  abortSignal,
1584
1691
  fetch: this.config.fetch
1585
1692
  });
1693
+ if (response.status === "Request Moderated") {
1694
+ const moderationReasons = (_p = response.details) == null ? void 0 : _p["Moderation Reasons"];
1695
+ const reasons = Array.isArray(moderationReasons) ? moderationReasons : ["Unknown"];
1696
+ throw new Error(
1697
+ `Amazon Bedrock request was moderated: ${reasons.join(", ")}`
1698
+ );
1699
+ }
1700
+ if (!response.images || response.images.length === 0) {
1701
+ throw new Error(
1702
+ "Amazon Bedrock returned no images. " + (response.status ? `Status: ${response.status}` : "")
1703
+ );
1704
+ }
1586
1705
  return {
1587
1706
  images: response.images,
1588
1707
  warnings,
@@ -1594,8 +1713,27 @@ var BedrockImageModel = class {
1594
1713
  };
1595
1714
  }
1596
1715
  };
1716
+ function getBase64Data(file) {
1717
+ if (file.type === "url") {
1718
+ throw new Error(
1719
+ "URL-based images are not supported for Amazon Bedrock image editing. Please provide the image data directly."
1720
+ );
1721
+ }
1722
+ if (file.data instanceof Uint8Array) {
1723
+ return convertUint8ArrayToBase64(file.data);
1724
+ }
1725
+ return file.data;
1726
+ }
1597
1727
  var bedrockImageResponseSchema = z6.object({
1598
- images: z6.array(z6.string())
1728
+ // Normal successful response
1729
+ images: z6.array(z6.string()).optional(),
1730
+ // Moderation response fields
1731
+ id: z6.string().optional(),
1732
+ status: z6.string().optional(),
1733
+ result: z6.unknown().optional(),
1734
+ progress: z6.unknown().optional(),
1735
+ details: z6.record(z6.string(), z6.unknown()).optional(),
1736
+ preview: z6.unknown().optional()
1599
1737
  });
1600
1738
 
1601
1739
  // src/bedrock-sigv4-fetch.ts
@@ -1608,7 +1746,7 @@ import {
1608
1746
  import { AwsV4Signer } from "aws4fetch";
1609
1747
 
1610
1748
  // src/version.ts
1611
- var VERSION = true ? "4.0.0-beta.99" : "0.0.0-test";
1749
+ var VERSION = true ? "4.0.0" : "0.0.0-test";
1612
1750
 
1613
1751
  // src/bedrock-sigv4-fetch.ts
1614
1752
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -1949,6 +2087,8 @@ Original error: ${errorMessage}`
1949
2087
  provider.languageModel = createChatModel;
1950
2088
  provider.embedding = createEmbeddingModel;
1951
2089
  provider.embeddingModel = createEmbeddingModel;
2090
+ provider.textEmbedding = createEmbeddingModel;
2091
+ provider.textEmbeddingModel = createEmbeddingModel;
1952
2092
  provider.image = createImageModel;
1953
2093
  provider.imageModel = createImageModel;
1954
2094
  provider.reranking = createRerankingModel;