@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.
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "4.0.158" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.159" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "4.0.158" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.159" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.158",
3
+ "version": "4.0.159",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "@smithy/util-utf8": "^4.0.0",
46
46
  "aws4fetch": "^1.0.20",
47
47
  "@ai-sdk/anthropic": "3.0.111",
48
- "@ai-sdk/openai": "3.0.98",
48
+ "@ai-sdk/openai": "3.0.99",
49
49
  "@ai-sdk/provider": "3.0.15",
50
50
  "@ai-sdk/provider-utils": "4.0.46"
51
51
  },
@@ -730,6 +730,10 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
730
730
  enqueueError(value.modelStreamErrorException);
731
731
  return;
732
732
  }
733
+ if (value.serviceUnavailableException) {
734
+ enqueueError(value.serviceUnavailableException);
735
+ return;
736
+ }
733
737
  if (value.throttlingException) {
734
738
  enqueueError(value.throttlingException);
735
739
  return;
@@ -1308,6 +1312,7 @@ const BedrockStreamSchema = z.object({
1308
1312
  })
1309
1313
  .nullish(),
1310
1314
  modelStreamErrorException: z.record(z.string(), z.unknown()).nullish(),
1315
+ serviceUnavailableException: z.record(z.string(), z.unknown()).nullish(),
1311
1316
  throttlingException: z.record(z.string(), z.unknown()).nullish(),
1312
1317
  validationException: z.record(z.string(), z.unknown()).nullish(),
1313
1318
  });
@@ -3,7 +3,8 @@ import { toUtf8, fromUtf8 } from '@smithy/util-utf8';
3
3
 
4
4
  export interface DecodedEvent {
5
5
  messageType: string;
6
- eventType: string;
6
+ eventType?: string;
7
+ exceptionType?: string;
7
8
  data: string;
8
9
  }
9
10
 
@@ -43,10 +44,18 @@ export function createBedrockEventStreamDecoder<T>(
43
44
  buffer = buffer.slice(totalLength);
44
45
 
45
46
  const messageType = decoded.headers[':message-type']?.value as string;
46
- const eventType = decoded.headers[':event-type']?.value as string;
47
+ const eventType = decoded.headers[':event-type']?.value as
48
+ | string
49
+ | undefined;
50
+ const exceptionType = decoded.headers[':exception-type']?.value as
51
+ | string
52
+ | undefined;
47
53
  const data = textDecoder.decode(decoded.body);
48
54
 
49
- await processEvent({ messageType, eventType, data }, controller);
55
+ await processEvent(
56
+ { messageType, eventType, exceptionType, data },
57
+ controller,
58
+ );
50
59
  }
51
60
  },
52
61
  flush() {
@@ -25,31 +25,40 @@ export const createBedrockEventStreamResponseHandler =
25
25
  value: createBedrockEventStreamDecoder<ParseResult<T>>(
26
26
  response.body,
27
27
  async (event, controller) => {
28
- if (event.messageType === 'event') {
29
- const parsedDataResult = await safeParseJSON({ text: event.data });
30
- if (!parsedDataResult.success) {
31
- controller.enqueue(parsedDataResult);
32
- return;
33
- }
28
+ const payloadType =
29
+ event.messageType === 'event'
30
+ ? event.eventType
31
+ : event.messageType === 'exception'
32
+ ? event.exceptionType
33
+ : undefined;
34
34
 
35
- delete (parsedDataResult.value as any).p;
36
- const wrappedData = {
37
- [event.eventType]: parsedDataResult.value,
38
- };
35
+ if (payloadType == null) {
36
+ return;
37
+ }
38
+
39
+ const parsedDataResult = await safeParseJSON({ text: event.data });
40
+ if (!parsedDataResult.success) {
41
+ controller.enqueue(parsedDataResult);
42
+ return;
43
+ }
44
+
45
+ delete (parsedDataResult.value as any).p;
46
+ const wrappedData = {
47
+ [payloadType]: parsedDataResult.value,
48
+ };
39
49
 
40
- const validatedWrappedData = await safeValidateTypes<T>({
41
- value: wrappedData,
42
- schema: chunkSchema,
50
+ const validatedWrappedData = await safeValidateTypes<T>({
51
+ value: wrappedData,
52
+ schema: chunkSchema,
53
+ });
54
+ if (!validatedWrappedData.success) {
55
+ controller.enqueue(validatedWrappedData);
56
+ } else {
57
+ controller.enqueue({
58
+ success: true,
59
+ value: validatedWrappedData.value,
60
+ rawValue: wrappedData,
43
61
  });
44
- if (!validatedWrappedData.success) {
45
- controller.enqueue(validatedWrappedData);
46
- } else {
47
- controller.enqueue({
48
- success: true,
49
- value: validatedWrappedData.value,
50
- rawValue: wrappedData,
51
- });
52
- }
53
62
  }
54
63
  },
55
64
  ),