Skip to main content

SessionEvent

Every message from Copilot is a Revolution\Copilot\Types\SessionEvent class. Because this is the class you use most often, Laravel-native conveniences are added on top.

content()

Get the most important response message from the AI.
Implicit conversion via __toString() also returns the message content.

Checking the event type

isAssistantMessage(), isUserMessage(), isIdle(), and isAssistantMessageDelta() are available. Additional helpers may be added for commonly used event types. Use is() to check for any EventType.
type() returns the string value of the SessionEventType enum.

failed() / successful()

When the event type is SESSION_ERROR, failed() returns true. successful() is the opposite. Renamed from isError() to match Laravel’s naming.

throw()

Just like Laravel’s HTTP or Process API, errors are retained and can be raised via throw(). If there’s no error it does nothing, so you can write:
If the event type is SESSION_ERROR, Revolution\Copilot\Exceptions\SessionErrorException is thrown. On timeout, Revolution\Copilot\Exceptions\SessionTimeoutException is thrown. For JSON-RPC errors, Revolution\Copilot\Exceptions\JsonRpcException is thrown.

Conditionable

when() and unless() are available.

Dumpable

dump() and dd() are available.

Tappable

tap() is available.

InteractsWithData

This feature applies only to SessionEvent’s $data property. Familiar helpers such as all(), has(), only(), and collect() are available. See InteractsWithData for details. Because SessionEvent’s $data shape differs per EventType, this is handy for accessing event-specific values. content() also uses InteractsWithData under the hood.

toArray() / toJson()

You can convert the entire SessionEvent to an array or JSON.
There is no top-level collect() method for the event as a whole, since InteractsWithData already provides collect() for $data. To perform collection operations on the whole event, use Laravel’s collect() helper.

broadcast() / broadcastNow()

You can broadcast with the same interface as the Laravel AI SDK’s StreamEvent. The AI SDK uses it during streaming, but for SessionEvent you can use it with any EventType.
broadcastNow() broadcasts immediately without going through a queue.
Streaming example:
For the latest updates, see the GitHub repository.
Last modified on August 2, 2026