melony
TypeScript‑first, headless React toolkit for building AI chat UIs with streaming support.
npm version
License
TypeScript
The core idea
- • MelonyProvider manages streaming chat state and handles server communication.
- • Hooks give you fine-grained access to messages, parts, status, and sending.
- • Flexible parts system supports any message structure with custom mappers.
- • TypeScript-first with full type safety and extensibility.
30‑second quickstart
Basic chat component with streaming support:
"use client";
import {
MelonyProvider,
useMelonyMessages,
useMelonySend,
useMelonyStatus,
} from "melony";
function ChatMessages() {
const messages = useMelonyMessages();
const send = useMelonySend();
const status = useMelonyStatus();
return (
<div>
{messages.map((message) => (
<div key={message.id}>
<strong>{message.role}:</strong>
{message.parts.map((part, i) => (
<div key={i}>{part.type === "text" && part.text}</div>
))}
</div>
))}
<button onClick={() => send("Hello!")} disabled={status === "streaming"}>
{status === "streaming" ? "Sending..." : "Send"}
</button>
</div>
);
}
export default function Chat() {
return (
<MelonyProvider endpoint="/api/chat">
<ChatMessages />
</MelonyProvider>
);
}
Key Features
Streaming Support
Built-in support for streaming responses with automatic text delta handling for smooth user experience.
TypeScript First
Full type safety with custom message types and extensible part system for any use case.
Headless Design
Complete control over UI with flexible hooks and components that work with any design system.
Easy Integration
Works seamlessly with AI SDK and other streaming libraries. Simple server setup required.