class VercelDataProtocol extends StreamProtocol

The Vercel AI SDK data stream protocol.

See: https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol

Properties

protected bool $started from  StreamProtocol
protected bool $errored from  StreamProtocol
protected Throwable|null $exception from  StreamProtocol
protected string|null $invocationId

Methods

parts(StreamableAgentResponse $response)

Get the protocol parts that represent the given response's events.

maskedErrorParts()

Get the protocol parts that terminate a stream interrupted by an exception.

array
headers()

Get the response headers for the protocol.

Response
response(StreamableAgentResponse $response)

Create an HTTP response that represents the given response using the protocol.

string|null
terminator()

Get the raw frame that terminates the stream.

string
encode(array $part)

Encode the given protocol part as a server-sent event line.

string
json(mixed $value)

Encode the given value as JSON, substituting bytes a provider streamed as invalid UTF-8.

__construct(string|null $messageId = null)

Create a Vercel data protocol formatter.

yieldPart(array $part)

Get the given protocol part, preceded by a start part when one has not been sent yet.

array|null
mapEvent(StreamEvent $event)

Get the protocol part that represents the given event.

array
toolResultPart(ToolResult $event)

Get the protocol part that represents the given tool result event.

array
providerToolPart(ProviderToolEvent $event)

Get the protocol part that represents the given provider tool event.

array|null
citationPart(Citation $event)

Get the protocol part that represents the given citation event.

array
finishPart(string $reason, TextUsage $usage)

Get the protocol part that finishes the stream.

Details

at line 47
protected Generator parts(StreamableAgentResponse $response)

Get the protocol parts that represent the given response's events.

Parameters

StreamableAgentResponse $response

Return Value

Generator

at line 121
protected Generator maskedErrorParts()

Get the protocol parts that terminate a stream interrupted by an exception.

Return Value

Generator

at line 129
protected array headers()

Get the response headers for the protocol.

Return Value

array

in StreamProtocol at line 49
Response response(StreamableAgentResponse $response)

Create an HTTP response that represents the given response using the protocol.

Parameters

StreamableAgentResponse $response

Return Value

Response

at line 137
protected string|null terminator()

Get the raw frame that terminates the stream.

Return Value

string|null

in StreamProtocol at line 98
protected string encode(array $part)

Encode the given protocol part as a server-sent event line.

Parameters

array $part

Return Value

string

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.

Parameters

mixed $value

Return Value

string

at line 40
__construct(string|null $messageId = null)

Create a Vercel data protocol formatter.

Parameters

string|null $messageId

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.

Parameters

array $part

Return Value

Generator

at line 174
protected array|null mapEvent(StreamEvent $event)

Get the protocol part that represents the given event.

Parameters

StreamEvent $event

Return Value

array|null

at line 229
protected array toolResultPart(ToolResult $event)

Get the protocol part that represents the given tool result event.

Parameters

ToolResult $event

Return Value

array

at line 259
protected array providerToolPart(ProviderToolEvent $event)

Get the protocol part that represents the given provider tool event.

Parameters

ProviderToolEvent $event

Return Value

array

at line 279
protected array|null citationPart(Citation $event)

Get the protocol part that represents the given citation event.

Parameters

Citation $event

Return Value

array|null

at line 297
protected array finishPart(string $reason, TextUsage $usage)

Get the protocol part that finishes the stream.

Parameters

string $reason
TextUsage $usage

Return Value

array