Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ai/core: add pipeAIStreamToResponse to streamText result. (#1404)
- Loading branch information
Showing
5 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'ai': patch | ||
--- | ||
|
||
ai/core: add pipeAIStreamToResponse() to streamText result. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ServerResponse } from 'node:http'; | ||
|
||
class MockServerResponse { | ||
writtenChunks: any[] = []; | ||
headers = {}; | ||
statusCode = 0; | ||
ended = false; | ||
|
||
write(chunk: any): void { | ||
this.writtenChunks.push(chunk); | ||
} | ||
|
||
end(): void { | ||
// You might want to mark the response as ended to simulate the real behavior | ||
this.ended = true; | ||
} | ||
|
||
writeHead(statusCode: number, headers: Record<string, string>): void { | ||
this.statusCode = statusCode; | ||
this.headers = headers; | ||
} | ||
|
||
get body() { | ||
// Combine all written chunks into a single string | ||
return this.writtenChunks.join(''); | ||
} | ||
} | ||
|
||
export function createMockServerResponse(): ServerResponse & | ||
MockServerResponse { | ||
return new MockServerResponse() as ServerResponse & MockServerResponse; | ||
} |