MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / tee

Method tee

packages/baseai/src/dev/utils/stream/stream.ts:157–181  ·  view source on GitHub ↗

* Splits the stream into two streams which can be * independently read from at different speeds.

()

Source from the content-addressed store, hash-verified

155 * independently read from at different speeds.
156 */
157 tee(): [Stream<Item>, Stream<Item>] {
158 const left: Array<Promise<IteratorResult<Item>>> = [];
159 const right: Array<Promise<IteratorResult<Item>>> = [];
160 const iterator = this.iterator();
161
162 const teeIterator = (
163 queue: Array<Promise<IteratorResult<Item>>>
164 ): AsyncIterator<Item> => {
165 return {
166 next: () => {
167 if (queue.length === 0) {
168 const result = iterator.next();
169 left.push(result);
170 right.push(result);
171 }
172 return queue.shift()!;
173 }
174 };
175 };
176
177 return [
178 new Stream(() => teeIterator(left), this.controller),
179 new Stream(() => teeIterator(right), this.controller)
180 ];
181 }
182
183 /**
184 * Converts this stream to a newline-separated ReadableStream of

Callers 1

handleStreamingResponseFunction · 0.45

Calls 1

iteratorMethod · 0.95

Tested by

no test coverage detected