Skip to content

Commit f183bc9

Browse files
committed
fix(bedrock): fix bedrock logger
1 parent 760be6b commit f183bc9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/bedrock-sdk/src/core/streaming.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { streamCollector } from '@smithy/fetch-http-handler';
44
import { EventStreamSerdeContext, SerdeContext } from '@smithy/types';
55
import { Stream as CoreStream, ServerSentEvent } from '@anthropic-ai/sdk/streaming';
66
import { AnthropicError } from '@anthropic-ai/sdk/error';
7-
import { APIError } from '@anthropic-ai/sdk';
7+
import { APIError, BaseAnthropic } from '@anthropic-ai/sdk';
88
import { de_ResponseStream } from '../AWS_restJson1';
99
import { ReadableStreamToAsyncIterable } from '../internal/shims';
1010
import { safeJSON } from '../internal/utils/values';
11+
import { loggerFor } from '../internal/utils/log';
1112

1213
type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
1314

@@ -30,8 +31,13 @@ export const getMinimalSerdeContext = (): SerdeContext & EventStreamSerdeContext
3031
};
3132

3233
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+
) {
3439
let consumed = false;
40+
const logger = client ? loggerFor(client) : console;
3541

3642
async function* iterMessages(): AsyncGenerator<ServerSentEvent, void, unknown> {
3743
if (!response.body) {
@@ -70,8 +76,8 @@ export class Stream<Item> extends CoreStream<Item> {
7076
try {
7177
yield JSON.parse(sse.data);
7278
} 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);
7581
throw e;
7682
}
7783
}

0 commit comments

Comments
 (0)