Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

866 B
Raw Blame
async function filterStream(originalStream: ReadableStream) {
    const reader = originalStream.getReader();
    const filteredStream = new ReadableStream({
        async start(controller) {
            while (true) {
                const { done, value } = await reader.read();
                if (done) {
                    controller.close();
                    break;
                }
                try {
                    const chunk = JSON.parse(value); 
                    if (chunk.type !== "step-finish") {
                        controller.enqueue(value);
                    }
                } catch (error) {
                    if (!(value.type==='step-finish')) {
                        controller.enqueue(value);
                    }
                }
            }
        }
    });

    return filteredStream;
}

export { filterStream };