From a5e4462bcf054e8324cbcaa31d1b85ffc58113fd Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 6 Mar 2024 19:12:59 +0100 Subject: [PATCH] chore(types): fix accidental exposure of Buffer type to cloudflare (#319) --- src/streaming.ts | 13 ++++++++++++- tests/streaming.test.ts | 15 +-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/streaming.ts b/src/streaming.ts index 2e1cbbb..e525a57 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -282,7 +282,7 @@ class SSEDecoder { * * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258 */ -export class LineDecoder { +class LineDecoder { // prettier-ignore static NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']); static NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g; @@ -387,6 +387,17 @@ export class LineDecoder { } } +/** This is an internal helper function that's just used for testing */ +export function _decodeChunks(chunks: string[]): string[] { + const decoder = new LineDecoder(); + const lines = []; + for (const chunk of chunks) { + lines.push(...decoder.decode(chunk)); + } + + return lines; +} + function partition(str: string, delimiter: string): [string, string, string] { const index = str.indexOf(delimiter); if (index !== -1) { diff --git a/tests/streaming.test.ts b/tests/streaming.test.ts index 9b106b8..ead469e 100644 --- a/tests/streaming.test.ts +++ b/tests/streaming.test.ts @@ -1,17 +1,4 @@ -import { LineDecoder } from '@anthropic-ai/sdk/streaming'; - -function decodeChunks(chunks: string[], decoder?: LineDecoder): string[] { - if (!decoder) { - decoder = new LineDecoder(); - } - - const lines = []; - for (const chunk of chunks) { - lines.push(...decoder.decode(chunk)); - } - - return lines; -} +import { _decodeChunks as decodeChunks } from '@anthropic-ai/sdk/streaming'; describe('line decoder', () => { test('basic', () => {