embedWidget(), and the on() method on the widget instance.
Quick Start
Event Reference
Thread Events
threadChanged
Fires when the active conversation thread changes — for example, when the user selects a different thread from the thread list, or a new thread is created after the first message is sent.
newThread
Fires when the user clicks “New Chat” to start a fresh conversation. At this point no thread has been created on the backend yet — the thread is created once the first message is sent (which then fires threadChanged).
Message Events
userMessageSent
Fires when the user sends a message to the agent.
generationStarted
Fires when the agent begins generating a response.
generationEnded
Fires when the agent finishes generating a response. The messageId is the persisted backend ID that you can use with the Thesys API to fetch the message content. When your parent origin is allowlisted, message contains the full persisted assistant message so you can render the response live in another panel without an additional API call.
All three arguments are
undefined unless the embedding page’s origin is on the playground’s Allowed Parent Origins list. See Receiving Message Data.AssistantMessage shape
Tool Execution Events
These events fire when the agent uses a tool (web search, image search, artifact builder, etc.) during response generation. Internal tools used by the system are excluded — only user-facing tools trigger these events.toolExecutionStarted
Fires when the agent starts executing a tool.
toolExecutionEnded
Fires when a tool finishes executing. If the tool failed, the error parameter contains the error message.
Error Events
agentError
Fires when an error occurs during message processing or response streaming.
identityTokenError
Fires when a BYOI identity token is invalid or cannot be refreshed. This is separate from the normal token refresh flow — it indicates a persistent authentication failure.
Inline Callbacks
All events can also be passed as callbacks directly toembedWidget(). Callback names use the on prefix with PascalCase:
on() listeners fire for the same event — you can use either or both.
widget.on(event, callback)
Subscribe to events dynamically after the widget is created. Returns an unsubscribe function.
on() returns its own independent unsubscribe function.
Receiving Message Data
For security, the published agent does not broadcast conversation data (assistant messages, thread IDs, user messages, tool names, error details) to arbitrary embedders. Without explicit opt-in, every data event still fires — but with its payload stripped to just the event type:message for live rendering — add your parent page’s origin to the playground’s Allowed Parent Origins list:
- Open your playground in the Thesys Console.
- Click Deploy, expand the Embed on your website section.
- Under Allowed parent origins, add each origin that should receive full event payloads (for example,
https://app.example.comorhttp://localhost:3000). - Republish the playground.
APP_READY, widget open/close/toggle, identity-token refresh) are unaffected and always work.
What counts as a “data event”?
Typical Event Flow
Here’s the sequence of events during a normal conversation turn:Direct Iframe Integration
If you’re embedding the agent via a direct iframe instead of the embed widget npm package, you can listen for the same events using the browser’spostMessage API. Each event is sent as a message with a type field prefixed with THESYS_.