File size: 819 Bytes
a9e27c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Explicit provider packets for tests whose fixtures are serialized text frames."""

from collections.abc import AsyncIterator

from free_claude_code.core.async_iterators import try_close_async_iterator
from free_claude_code.core.stream_output import StreamOutput


class PacketFixtureStream(AsyncIterator[StreamOutput]):
    def __init__(self, source: AsyncIterator[str]) -> None:
        self.source = source

    def __aiter__(self):
        return self

    async def __anext__(self) -> StreamOutput:
        return StreamOutput((await anext(self.source),))

    async def aclose(self) -> None:
        error = await try_close_async_iterator(self.source)
        if error is not None:
            raise error


def packets(source: AsyncIterator[str]) -> PacketFixtureStream:
    return PacketFixtureStream(source)