VercelDataProtocol
class VercelDataProtocol extends StreamProtocol
The Vercel AI SDK data stream protocol.
Properties
| protected bool | $started | from StreamProtocol | |
| protected bool | $errored | from StreamProtocol | |
| protected Throwable|null | $exception | from StreamProtocol | |
| protected string|null | $invocationId |
Methods
Get the protocol parts that represent the given response's events.
Get the protocol parts that terminate a stream interrupted by an exception.
Get the response headers for the protocol.
Create an HTTP response that represents the given response using the protocol.
Get the raw frame that terminates the stream.
Encode the given protocol part as a server-sent event line.
Encode the given value as JSON, substituting bytes a provider streamed as invalid UTF-8.
Create a Vercel data protocol formatter.
Get the given protocol part, preceded by a start part when one has not been sent yet.
Get the protocol part that represents the given tool result event.
Get the protocol part that represents the given provider tool event.
Details
at line 47
protected Generator
parts(StreamableAgentResponse $response)
Get the protocol parts that represent the given response's events.
at line 121
protected Generator
maskedErrorParts()
Get the protocol parts that terminate a stream interrupted by an exception.
at line 129
protected array
headers()
Get the response headers for the protocol.
in
StreamProtocol at line 49
Response
response(StreamableAgentResponse $response)
Create an HTTP response that represents the given response using the protocol.
at line 137
protected string|null
terminator()
Get the raw frame that terminates the stream.
in
StreamProtocol at line 98
protected string
encode(array $part)
Encode the given protocol part as a server-sent event line.
in
StreamProtocol at line 106
protected string
json(mixed $value)
Encode the given value as JSON, substituting bytes a provider streamed as invalid UTF-8.
at line 40
__construct(string|null $messageId = null)
Create a Vercel data protocol formatter.
at line 149
protected Generator
yieldPart(array $part)
Get the given protocol part, preceded by a start part when one has not been sent yet.
at line 174
protected array|null
mapEvent(StreamEvent $event)
Get the protocol part that represents the given event.
at line 229
protected array
toolResultPart(ToolResult $event)
Get the protocol part that represents the given tool result event.
at line 259
protected array
providerToolPart(ProviderToolEvent $event)
Get the protocol part that represents the given provider tool event.
at line 279
protected array|null
citationPart(Citation $event)
Get the protocol part that represents the given citation event.
at line 297
protected array
finishPart(string $reason, TextUsage $usage)
Get the protocol part that finishes the stream.