Skip to content

AsyncGenerator of a text/event-stream returns the data only #2641

@jscarle

Description

@jscarle

Description

I have a problem with the AsyncGenerator of a text/event-stream returning the data and not the event. The typescript is typed to the event, but it's the data that comes back.

The endpoint returns as stream like this:

event: created
data: {"conversationId":"conv_d6a3363ed00b45fe952c5e7e46195f88"}
id: 00000000

event: output-item-added
data: {"itemId":"rs_015a1b95e8d45cba0068c5ff508ed08194ae8e1bfd49ae531e","outputIndex":0}
id: 00000002

event: output-item-done
data: {"itemId":"rs_015a1b95e8d45cba0068c5ff508ed08194ae8e1bfd49ae531e","outputIndex":0}
id: 00000003

event: output-item-added
data: {"itemId":"msg_015a1b95e8d45cba0068c5ff52cc908194b709e372eed353df","outputIndex":1}
id: 00000004

event: content-part-added
data: {"contentIndex":0}
id: 00000005

event: output-text-delta-update
data: {"delta":"Bonjour"}
id: 00000006

But doing the following:

const result = await streamConversation();
for await (const item of result.stream) {
}

Typescript types it as:

export type SseItemOfChatResponse = {
  data?: ChatResponse
  eventType?: string | null
  eventId?: string | null
  reconnectionInterval?: string | null
}

But item is actually equal to ChatResponse, thus eventType and eventId are unaccessible.

The relevant OpenAPI parts:

"/conversations/stream": {
  "post": {
    "operationId": "StreamConversation",
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "text/event-stream": {
            "schema": {
              "$ref": "#/components/schemas/SseItemOfChatResponse"
            }
          }
        }
      }
    }
  }
}
"SseItemOfChatResponse": {
  "type": "object",
  "properties": {
    "data": {
      "$ref": "#/components/schemas/ChatResponse"
    },
    "eventType": {
      "type": [
        "null",
        "string"
      ]
    },
    "eventId": {
      "type": [
        "null",
        "string"
      ]
    },
    "reconnectionInterval": {
      "pattern": "^-?(\\d+\\.)?\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,7})?$",
      "type": [
        "null",
        "string"
      ]
    }
  }
}

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't workingclientClient package related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions