Skip to content

Commit

Permalink
fix type error on Vercel.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonStudio committed Aug 1, 2024
1 parent b452d30 commit ab12718
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libs/agent-runtime/cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ function getModelTokens(model: any): number | undefined {

class CloudflareStreamTransformer {
private textDecoder = new TextDecoder();
private textEncoder = new TextEncoder();
private buffer: string = '';

private parseChunk(chunk: string, controller: TransformStreamDefaultController) {
const dataPrefix = /^data: /;
const json = chunk.replace(dataPrefix, '');
const parsedChunk = JSON.parse(json);
controller.enqueue(`event: text\n`);
controller.enqueue(`data: ${JSON.stringify(parsedChunk.response)}\n\n`);
controller.enqueue(this.textEncoder.encode(`event: text\n`));
controller.enqueue(this.textEncoder.encode(`data: ${parsedChunk.response}\n\n`));
}

public async transform(chunk: Uint8Array, controller: TransformStreamDefaultController) {
Expand Down

0 comments on commit ab12718

Please sign in to comment.