@ai-sdk/amazon-bedrock 3.0.118 → 3.0.119

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
@@ -8,7 +8,7 @@ import {
8
8
  } from "@ai-sdk/provider-utils";
9
9
 
10
10
  // src/version.ts
11
- var VERSION = true ? "3.0.118" : "0.0.0-test";
11
+ var VERSION = true ? "3.0.119" : "0.0.0-test";
12
12
 
13
13
  // src/bedrock-provider.ts
14
14
  import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
@@ -131,7 +131,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
131
131
  return body.pipeThrough(
132
132
  new TransformStream({
133
133
  async transform(chunk, controller) {
134
- var _a, _b;
134
+ var _a, _b, _c;
135
135
  const newBuffer = new Uint8Array(buffer.length + chunk.length);
136
136
  newBuffer.set(buffer);
137
137
  newBuffer.set(chunk, buffer.length);
@@ -150,8 +150,12 @@ function createBedrockEventStreamDecoder(body, processEvent) {
150
150
  buffer = buffer.slice(totalLength);
151
151
  const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
152
152
  const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
153
+ const exceptionType = (_c = decoded.headers[":exception-type"]) == null ? void 0 : _c.value;
153
154
  const data = textDecoder.decode(decoded.body);
154
- await processEvent({ messageType, eventType, data }, controller);
155
+ await processEvent(
156
+ { messageType, eventType, exceptionType, data },
157
+ controller
158
+ );
155
159
  }
156
160
  },
157
161
  flush() {
@@ -176,29 +180,31 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
176
180
  value: createBedrockEventStreamDecoder(
177
181
  response.body,
178
182
  async (event, controller) => {
179
- if (event.messageType === "event") {
180
- const parsedDataResult = await safeParseJSON({ text: event.data });
181
- if (!parsedDataResult.success) {
182
- controller.enqueue(parsedDataResult);
183
- return;
184
- }
185
- delete parsedDataResult.value.p;
186
- const wrappedData = {
187
- [event.eventType]: parsedDataResult.value
188
- };
189
- const validatedWrappedData = await safeValidateTypes({
190
- value: wrappedData,
191
- schema: chunkSchema
183
+ const payloadType = event.messageType === "event" ? event.eventType : event.messageType === "exception" ? event.exceptionType : void 0;
184
+ if (payloadType == null) {
185
+ return;
186
+ }
187
+ const parsedDataResult = await safeParseJSON({ text: event.data });
188
+ if (!parsedDataResult.success) {
189
+ controller.enqueue(parsedDataResult);
190
+ return;
191
+ }
192
+ delete parsedDataResult.value.p;
193
+ const wrappedData = {
194
+ [payloadType]: parsedDataResult.value
195
+ };
196
+ const validatedWrappedData = await safeValidateTypes({
197
+ value: wrappedData,
198
+ schema: chunkSchema
199
+ });
200
+ if (!validatedWrappedData.success) {
201
+ controller.enqueue(validatedWrappedData);
202
+ } else {
203
+ controller.enqueue({
204
+ success: true,
205
+ value: validatedWrappedData.value,
206
+ rawValue: wrappedData
192
207
  });
193
- if (!validatedWrappedData.success) {
194
- controller.enqueue(validatedWrappedData);
195
- } else {
196
- controller.enqueue({
197
- success: true,
198
- value: validatedWrappedData.value,
199
- rawValue: wrappedData
200
- });
201
- }
202
208
  }
203
209
  }
204
210
  )
@@ -1176,6 +1182,10 @@ var BedrockChatLanguageModel = class {
1176
1182
  enqueueError(value.modelStreamErrorException);
1177
1183
  return;
1178
1184
  }
1185
+ if (value.serviceUnavailableException) {
1186
+ enqueueError(value.serviceUnavailableException);
1187
+ return;
1188
+ }
1179
1189
  if (value.throttlingException) {
1180
1190
  enqueueError(value.throttlingException);
1181
1191
  return;
@@ -1545,6 +1555,7 @@ var BedrockStreamSchema = z4.object({
1545
1555
  }).nullish()
1546
1556
  }).nullish(),
1547
1557
  modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
1558
+ serviceUnavailableException: z4.record(z4.string(), z4.unknown()).nullish(),
1548
1559
  throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
1549
1560
  validationException: z4.record(z4.string(), z4.unknown()).nullish()
1550
1561
  });