Skip to content

Commit

Permalink
chore(types): fix accidental exposure of Buffer type to cloudflare (#319
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stainless-bot committed Mar 6, 2024
1 parent 0147b46 commit a5e4462
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 12 additions & 1 deletion src/streaming.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 1 addition & 14 deletions 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', () => {
Expand Down

0 comments on commit a5e4462

Please sign in to comment.