@ai-sdk/amazon-bedrock 4.0.158 → 4.0.159

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
@@ -147,7 +147,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
147
147
  return body.pipeThrough(
148
148
  new TransformStream({
149
149
  async transform(chunk, controller) {
150
- var _a, _b;
150
+ var _a, _b, _c;
151
151
  const newBuffer = new Uint8Array(buffer.length + chunk.length);
152
152
  newBuffer.set(buffer);
153
153
  newBuffer.set(chunk, buffer.length);
@@ -166,8 +166,12 @@ function createBedrockEventStreamDecoder(body, processEvent) {
166
166
  buffer = buffer.slice(totalLength);
167
167
  const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
168
168
  const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
169
+ const exceptionType = (_c = decoded.headers[":exception-type"]) == null ? void 0 : _c.value;
169
170
  const data = textDecoder.decode(decoded.body);
170
- await processEvent({ messageType, eventType, data }, controller);
171
+ await processEvent(
172
+ { messageType, eventType, exceptionType, data },
173
+ controller
174
+ );
171
175
  }
172
176
  },
173
177
  flush() {
@@ -192,29 +196,31 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
192
196
  value: createBedrockEventStreamDecoder(
193
197
  response.body,
194
198
  async (event, controller) => {
195
- if (event.messageType === "event") {
196
- const parsedDataResult = await safeParseJSON({ text: event.data });
197
- if (!parsedDataResult.success) {
198
- controller.enqueue(parsedDataResult);
199
- return;
200
- }
201
- delete parsedDataResult.value.p;
202
- const wrappedData = {
203
- [event.eventType]: parsedDataResult.value
204
- };
205
- const validatedWrappedData = await safeValidateTypes({
206
- value: wrappedData,
207
- schema: chunkSchema
199
+ const payloadType = event.messageType === "event" ? event.eventType : event.messageType === "exception" ? event.exceptionType : void 0;
200
+ if (payloadType == null) {
201
+ return;
202
+ }
203
+ const parsedDataResult = await safeParseJSON({ text: event.data });
204
+ if (!parsedDataResult.success) {
205
+ controller.enqueue(parsedDataResult);
206
+ return;
207
+ }
208
+ delete parsedDataResult.value.p;
209
+ const wrappedData = {
210
+ [payloadType]: parsedDataResult.value
211
+ };
212
+ const validatedWrappedData = await safeValidateTypes({
213
+ value: wrappedData,
214
+ schema: chunkSchema
215
+ });
216
+ if (!validatedWrappedData.success) {
217
+ controller.enqueue(validatedWrappedData);
218
+ } else {
219
+ controller.enqueue({
220
+ success: true,
221
+ value: validatedWrappedData.value,
222
+ rawValue: wrappedData
208
223
  });
209
- if (!validatedWrappedData.success) {
210
- controller.enqueue(validatedWrappedData);
211
- } else {
212
- controller.enqueue({
213
- success: true,
214
- value: validatedWrappedData.value,
215
- rawValue: wrappedData
216
- });
217
- }
218
224
  }
219
225
  }
220
226
  )
@@ -1372,6 +1378,10 @@ var BedrockChatLanguageModel = class {
1372
1378
  enqueueError(value.modelStreamErrorException);
1373
1379
  return;
1374
1380
  }
1381
+ if (value.serviceUnavailableException) {
1382
+ enqueueError(value.serviceUnavailableException);
1383
+ return;
1384
+ }
1375
1385
  if (value.throttlingException) {
1376
1386
  enqueueError(value.throttlingException);
1377
1387
  return;
@@ -1815,6 +1825,7 @@ var BedrockStreamSchema = z4.object({
1815
1825
  }).nullish()
1816
1826
  }).nullish(),
1817
1827
  modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
1828
+ serviceUnavailableException: z4.record(z4.string(), z4.unknown()).nullish(),
1818
1829
  throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
1819
1830
  validationException: z4.record(z4.string(), z4.unknown()).nullish()
1820
1831
  });
@@ -2244,7 +2255,7 @@ import {
2244
2255
  import { AwsV4Signer } from "aws4fetch";
2245
2256
 
2246
2257
  // src/version.ts
2247
- var VERSION = true ? "4.0.158" : "0.0.0-test";
2258
+ var VERSION = true ? "4.0.159" : "0.0.0-test";
2248
2259
 
2249
2260
  // src/bedrock-sigv4-fetch.ts
2250
2261
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {