Toon Agent Bridge provides React components for visualizing agent state and events.
npm install @programsmagic/toon-frontend
The main component for visualizing agent events.
import { AgentVisualizer } from '@programsmagic/toon-frontend';
import '@programsmagic/toon-frontend/styles';
function App() {
return (
<AgentVisualizer
url="http://localhost:3000/events"
protocol="sse"
autoConnect={true}
/>
);
}
url (string, required): URL for SSE or WebSocket connectionprotocol (‘sse’ |
‘websocket’, default: ‘sse’): Connection protocol |
autoConnect (boolean, default: true): Automatically connect on mountshowTimeline (boolean, default: true): Show event timelineshowFlowDiagram (boolean, default: false): Show flow diagramflows (array, optional): Flow definitions for diagramonEvent (function, optional): Callback for each eventonError (function, optional): Error callbackonConnect (function, optional): Connection callbackonDisconnect (function, optional): Disconnection callbackCustom hook for connecting to agent event streams.
import { useAgentStream } from '@programsmagic/toon-frontend';
function MyComponent() {
const { events, isConnected, connect, disconnect } = useAgentStream({
url: 'http://localhost:3000/events',
protocol: 'sse',
onEvent: (event) => {
console.log('Event received:', event);
},
});
return (
<div>
<button onClick={connect}>Connect</button>
<button onClick={disconnect}>Disconnect</button>
<div>Events: {events.length}</div>
</div>
);
}
Component for displaying a timeline of events.
import { EventTimeline } from '@programsmagic/toon-frontend';
<EventTimeline
events={events}
onEventClick={(event) => console.log(event)}
maxEvents={100}
/>
Component for displaying individual action events.
import { ActionCard } from '@programsmagic/toon-frontend';
<ActionCard
event={event}
index={0}
onClick={(event) => console.log(event)}
/>
Component for visualizing agent flows.
import { FlowDiagram } from '@programsmagic/toon-frontend';
const flows = [
{
id: 'flow1',
name: 'My Flow',
steps: [
{ actionId: 'action1' },
{ actionId: 'action2' },
],
},
];
<FlowDiagram events={events} flows={flows} />
The package includes a default “toon” theme with animated, colorful styling. Import it:
import '@programsmagic/toon-frontend/styles';
You can override CSS variables:
:root {
--toon-primary: #your-color;
--toon-secondary: #your-color;
--toon-bg: #your-color;
/* ... */
}
Events follow the CopilotKit AG-UI protocol:
TEXT_MESSAGE_CONTENT: Text messagesTOOL_CALL_START: Tool call startedTOOL_CALL_END: Tool call completedACTION_START: Action startedACTION_END: Action completedFLOW_START: Flow startedFLOW_END: Flow completedSTATE_UPDATE: State updatedERROR: Error occurredHEARTBEAT: Keep-alive heartbeat