@reminix/react
v0.0.8
Published
Reminix React SDK - hooks and components for React applications
Maintainers
Readme
@reminix/react
React SDK for Reminix - hooks and components for React applications.
Installation
npm install @reminix/reactNote: @reminix/client is included as a dependency.
Quick Start
import { ReminixProvider, useChatAgent } from '@reminix/react';
function App() {
return (
<ReminixProvider clientToken="your-client-token">
<ChatComponent />
</ReminixProvider>
);
}
function ChatComponent() {
const { chat, data, isLoading, error } = useChatAgent('my-agent');
const handleSend = async () => {
await chat({
messages: [{ role: 'user', content: 'Hello!' }],
});
};
return (
<div>
{isLoading && <p>Loading...</p>}
{error && <p>Error: {error.message}</p>}
{data && <p>{data.messages[0]?.content}</p>}
<button onClick={handleSend}>Send</button>
</div>
);
}Streaming
function StreamingChat() {
const { chatStream, isLoading } = useChatAgent('my-agent');
const [text, setText] = useState('');
const handleStream = async () => {
setText('');
await chatStream(
{ messages: [{ role: 'user', content: 'Tell me a story' }] },
(chunk) => setText((prev) => prev + chunk.chunk)
);
};
return (
<div>
<pre>{text}</pre>
<button onClick={handleStream} disabled={isLoading}>
{isLoading ? 'Streaming...' : 'Start Stream'}
</button>
</div>
);
}API
Provider
ReminixProvider
Wrap your app with this provider to use Reminix hooks.
<ReminixProvider clientToken="..." baseUrl="...">
{children}
</ReminixProvider>Hooks
useReminixClient()
Returns the raw ReminixClient instance for advanced usage.
useChatAgent(agentName)
Hook for chatting with an agent.
Returns:
chat(request)- Send a chat message (non-streaming)chatStream(request, onChunk)- Send a streaming chat messagedata- Latest responseerror- Error if request failedisLoading- Loading statereset()- Reset state
useInvokeAgent(agentName)
Hook for invoking an agent.
Returns:
invoke(request)- Invoke agent (non-streaming)invokeStream(request, onChunk)- Invoke with streamingdata- Latest responseerror- Error if request failedisLoading- Loading statereset()- Reset state
License
Apache-2.0
