EventSourceParser
Namespace: Vercel.AI.ProviderUtils
public sealed class EventSourceParserIncremental Server-Sent Events parser. A UTF-8 BOM is ignored at the start of the
stream. A trailing carriage return is held until the next chunk so it can form
a \r\n line ending. [DONE] is ordinary data.
Inheritance: object
Methods
Section titled “Methods”Feed(string?, Action<EventSourceMessage>, Action<int>?, Action<string>?, Action<string>?)
Section titled “Feed(string?, Action<EventSourceMessage>, Action<int>?, Action<string>?, Action<string>?)”public void Feed(string? chunk, Action<EventSourceMessage> onEvent, Action<int>? onRetry = null, Action<string>? onComment = null, Action<string>? onError = null)Feeds the next text chunk. Callbacks run for events completed by this chunk.
Parameters
| Name | Type | Description |
|---|---|---|
chunk |
string | |
onEvent |
Action<EventSourceMessage> | |
onRetry |
Action<int> | |
onComment |
Action<string> | |
onError |
Action<string> |
Reset(bool, Action<int>?, Action<string>?, Action<string>?)
Section titled “Reset(bool, Action<int>?, Action<string>?, Action<string>?)”public void Reset(bool consume = false, Action<int>? onRetry = null, Action<string>? onComment = null, Action<string>? onError = null)Clears parser state. When <code class=“paramref”>consume</code> is true, an incomplete
line is parsed first. That can report retry, comments, and errors.
It does not dispatch a data event.
Parameters
| Name | Type | Description |
|---|---|---|
consume |
bool | |
onRetry |
Action<int> | |
onComment |
Action<string> | |
onError |
Action<string> |
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product