@fluid-topics/public-api 1.0.98 → 1.0.100-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +0,0 @@
1
- export interface GenAIChunk {
2
- id?: string;
3
- message?: string;
4
- error?: {
5
- code: number;
6
- name: string;
7
- message: string;
8
- };
9
- }
10
- export declare class GenAIChunkReader {
11
- private readonly reader;
12
- private decoder;
13
- private partialChunk;
14
- constructor(reader: ReadableStreamDefaultReader<Uint8Array>);
15
- read(): AsyncGenerator<GenAIChunk>;
16
- private readRemainingChunks;
17
- private readChunksFromValue;
18
- private parseLine;
19
- }
@@ -1,37 +0,0 @@
1
- export class GenAIChunkReader {
2
- reader;
3
- decoder = new TextDecoder();
4
- partialChunk = "";
5
- constructor(reader) {
6
- this.reader = reader;
7
- }
8
- async *read() {
9
- while (true) {
10
- const { done, value } = await this.reader.read();
11
- if (done) {
12
- yield* this.readRemainingChunks();
13
- return;
14
- }
15
- else {
16
- yield* this.readChunksFromValue(value);
17
- }
18
- }
19
- }
20
- *readRemainingChunks() {
21
- yield* this.parseLine(this.partialChunk);
22
- }
23
- *readChunksFromValue(value) {
24
- const text = this.partialChunk + this.decoder.decode(value);
25
- const lines = text.split("\n");
26
- this.partialChunk = lines.pop();
27
- for (let line of lines) {
28
- yield* this.parseLine(line);
29
- }
30
- }
31
- *parseLine(line) {
32
- const [type, content] = line.split(/:(.*)/);
33
- if (type == "data" && content.length > 0) {
34
- yield JSON.parse(content);
35
- }
36
- }
37
- }