@@ -4,10 +4,11 @@ import { streamCollector } from '@smithy/fetch-http-handler';
4
4
import { EventStreamSerdeContext , SerdeContext } from '@smithy/types' ;
5
5
import { Stream as CoreStream , ServerSentEvent } from '@anthropic-ai/sdk/streaming' ;
6
6
import { AnthropicError } from '@anthropic-ai/sdk/error' ;
7
- import { APIError } from '@anthropic-ai/sdk' ;
7
+ import { APIError , BaseAnthropic } from '@anthropic-ai/sdk' ;
8
8
import { de_ResponseStream } from '../AWS_restJson1' ;
9
9
import { ReadableStreamToAsyncIterable } from '../internal/shims' ;
10
10
import { safeJSON } from '../internal/utils/values' ;
11
+ import { loggerFor } from '../internal/utils/log' ;
11
12
12
13
type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined ;
13
14
@@ -30,8 +31,13 @@ export const getMinimalSerdeContext = (): SerdeContext & EventStreamSerdeContext
30
31
} ;
31
32
32
33
export class Stream < Item > extends CoreStream < Item > {
33
- static override fromSSEResponse < Item > ( response : Response , controller : AbortController ) {
34
+ static override fromSSEResponse < Item > (
35
+ response : Response ,
36
+ controller : AbortController ,
37
+ client ?: BaseAnthropic ,
38
+ ) {
34
39
let consumed = false ;
40
+ const logger = client ? loggerFor ( client ) : console ;
35
41
36
42
async function * iterMessages ( ) : AsyncGenerator < ServerSentEvent , void , unknown > {
37
43
if ( ! response . body ) {
@@ -70,8 +76,8 @@ export class Stream<Item> extends CoreStream<Item> {
70
76
try {
71
77
yield JSON . parse ( sse . data ) ;
72
78
} catch ( e ) {
73
- console . error ( `Could not parse message into JSON:` , sse . data ) ;
74
- console . error ( `From chunk:` , sse . raw ) ;
79
+ logger . error ( `Could not parse message into JSON:` , sse . data ) ;
80
+ logger . error ( `From chunk:` , sse . raw ) ;
75
81
throw e ;
76
82
}
77
83
}
0 commit comments