01Install
Install the package with its core peer and React. The package also works with pnpm and yarn.
BASH
npm install @lov3kaizen/agentsea-react @lov3kaizen/agentsea-core react react-dom02Example
TSX
import type { AgentResponse as AgentResponseType } from '@lov3kaizen/agentsea-core';
import { AgentResponse } from '@lov3kaizen/agentsea-react';
function ChatMessage({ message }: { message: AgentResponseType }) {
return <AgentResponse response={message} />;
}03Key API
AgentResponseRenders a core AgentResponse as markdown. Props: response (required), className, showMetadata, theme, components.
StreamingResponseRenders a stream of events as it arrives. Props: stream (AsyncIterable of StreamEvent), className, showMetadata, theme, onComplete.
useFormattedContent(content, format?)Hook exported alongside AgentResponse. Returns the formatted content, or null while it is computed.
useStreamingContent()Hook exported alongside StreamingResponse. Returns content, isStreaming, metadata and consumeStream(stream).
04Caveats
- Peer dependencies: react and react-dom, versions 18 or 19.
- Requires Node.js 20 or later (engines field). The theme prop accepts light, dark or auto.
- Markdown rendering passes raw HTML through (rehype-raw). Sanitise untrusted model output before rendering. Formatted html content is set with dangerouslySetInnerHTML.
- The package also exports the useChat and useAgent hooks and connection adapters. They are covered in the React hooks guide.
05Streaming
StreamingResponse takes an async iterable of stream events from the core package. It shows the text as it arrives and calls onComplete with the final content.
TSX
import { StreamingResponse } from '@lov3kaizen/agentsea-react';
<StreamingResponse
stream={eventStream}
showMetadata
onComplete={(content) => console.log('Done', content.length)}
/>;