@ai-sdk/amazon-bedrock 5.0.59 → 5.0.61

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 ? "5.0.59" : "0.0.0-test";
38
+ var VERSION = true ? "5.0.61" : "0.0.0-test";
39
39
 
40
40
  // src/amazon-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 ? "5.0.59" : "0.0.0-test";
26
+ var VERSION = true ? "5.0.61" : "0.0.0-test";
27
27
 
28
28
  // src/amazon-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": "5.0.59",
3
+ "version": "5.0.61",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -44,10 +44,10 @@
44
44
  "@smithy/eventstream-codec": "^4.3.3",
45
45
  "@smithy/util-utf8": "^4.3.3",
46
46
  "aws4fetch": "^1.0.20",
47
- "@ai-sdk/anthropic": "4.0.40",
48
- "@ai-sdk/openai": "4.0.44",
47
+ "@ai-sdk/anthropic": "4.0.41",
48
+ "@ai-sdk/openai": "4.0.46",
49
49
  "@ai-sdk/provider": "4.0.7",
50
- "@ai-sdk/provider-utils": "5.0.28"
50
+ "@ai-sdk/provider-utils": "5.0.29"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "22.19.19",
@@ -783,6 +783,10 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
783
783
  enqueueError(value.modelStreamErrorException);
784
784
  return;
785
785
  }
786
+ if (value.serviceUnavailableException) {
787
+ enqueueError(value.serviceUnavailableException);
788
+ return;
789
+ }
786
790
  if (value.throttlingException) {
787
791
  enqueueError(value.throttlingException);
788
792
  return;
@@ -1367,6 +1371,7 @@ const AmazonBedrockStreamSchema = z.object({
1367
1371
  })
1368
1372
  .nullish(),
1369
1373
  modelStreamErrorException: z.record(z.string(), z.unknown()).nullish(),
1374
+ serviceUnavailableException: z.record(z.string(), z.unknown()).nullish(),
1370
1375
  throttlingException: z.record(z.string(), z.unknown()).nullish(),
1371
1376
  validationException: z.record(z.string(), z.unknown()).nullish(),
1372
1377
  });
@@ -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 createAmazonBedrockEventStreamDecoder<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 createAmazonBedrockEventStreamResponseHandler =
25
25
  value: createAmazonBedrockEventStreamDecoder<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
  ),