lukeed / fetch-event-stream

A tiny (736b) utility for Server Sent Event (SSE) streaming via `fetch` and Web Streams API
MIT License
376 stars 2 forks source link

TypeError: r is not async iterable #3

Closed JohnRSim closed 7 months ago

JohnRSim commented 7 months ago

"fetch-event-stream": "^0.1.3",

image

Getting this error in chrome and edge windows latest stable - (v123.0.2420.65)

On chrome canary 125.0.6384.0 works fine no errors.

    const response = await fetch(`${PUBLIC_BASE_PATH}/api/ai`, { 
        method: 'POST',
                headers:{
                    'fb_api_key':PUBLIC_AI_KEY
                },
                body: JSON.stringify({
                    message:msg,
                    userId:$page.data.session.user.email,
                    aiType:PUBLIC_AI_TYPE,
                    conversationId:chatID || createConversationID(),
                    promptId:'default'
                })
            });

            if (response.ok) {
                console.log('response',response);
                let stream = events(response);
                for await (let event of stream) {
                    console.log('<<', event.data);
                    try {
                        const jsonData = JSON.parse(event.data);
                    } catch (error) {
                        sRes.addStreamRes(PUBLIC_AI_CONFIG, chatID, `${event.data} `);
                    }

                }
            }
JohnRSim commented 7 months ago

image

JohnRSim commented 7 months ago

Here is the response image

lukeed commented 7 months ago

Ah, shoot. Sorry about this. Didn't realize that @@asyncIterator for ReadableStreams was experimental & not-well supported in browsers.

I'll change that, either via #1 or through the linked commit (incoming). Do you mind testing it out locally for me, to verify it works for you?

lukeed commented 7 months ago

Fixed published in 0.1.4

JohnRSim commented 7 months ago

@lukeed this is great thanks @lukeed tested with .5 works well.