@melony/react 0.1.54 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -45
- package/dist/index.cjs +22 -4096
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -426
- package/dist/index.d.ts +6 -426
- package/dist/index.js +20 -4015
- package/dist/index.js.map +1 -1
- package/package.json +2 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @melony/react
|
|
2
2
|
|
|
3
|
-
React UI + providers/hooks for building chat experiences on top of **Melony’s event stream
|
|
3
|
+
React UI + providers/hooks for building chat experiences on top of **Melony’s event stream**.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -11,27 +11,22 @@ npm install @melony/react melony react
|
|
|
11
11
|
## Quick start
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
|
-
import React from "react";
|
|
15
14
|
import { MelonyClient } from "melony/client";
|
|
16
|
-
import {
|
|
15
|
+
import { MelonyProvider } from "@melony/react";
|
|
17
16
|
|
|
18
|
-
const client = new MelonyClient({
|
|
19
|
-
url: "/api/chat",
|
|
20
|
-
});
|
|
17
|
+
const client = new MelonyClient({ url: "/api/chat" });
|
|
21
18
|
|
|
22
19
|
export default function App() {
|
|
23
20
|
return (
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
</
|
|
21
|
+
<MelonyProvider client={client}>
|
|
22
|
+
{/* Your components */}
|
|
23
|
+
</MelonyProvider>
|
|
27
24
|
);
|
|
28
25
|
}
|
|
29
26
|
```
|
|
30
27
|
|
|
31
28
|
### Send a message from UI
|
|
32
29
|
|
|
33
|
-
`Thread` already wires this up, but if you want manual control:
|
|
34
|
-
|
|
35
30
|
```tsx
|
|
36
31
|
import { useMelony } from "@melony/react";
|
|
37
32
|
|
|
@@ -41,7 +36,7 @@ function Controls() {
|
|
|
41
36
|
<button
|
|
42
37
|
disabled={isLoading}
|
|
43
38
|
onClick={() =>
|
|
44
|
-
sendEvent({ type: "text",
|
|
39
|
+
sendEvent({ type: "text", data: { content: "Hello!" } })
|
|
45
40
|
}
|
|
46
41
|
>
|
|
47
42
|
Send
|
|
@@ -50,46 +45,30 @@ function Controls() {
|
|
|
50
45
|
}
|
|
51
46
|
```
|
|
52
47
|
|
|
53
|
-
## Components
|
|
54
|
-
|
|
55
|
-
- **`Thread`**: a full chat thread (composer + message list + streaming).
|
|
56
|
-
- **`ChatSidebar`**: a sidebar-style chat UI container.
|
|
57
|
-
- **`ChatFull` / `ChatPopup`**: ready-to-embed layouts (see exports).
|
|
58
|
-
- **`UIRenderer`**: renders SDUI `UINode` trees from `melony`.
|
|
59
|
-
|
|
60
48
|
## Providers & hooks
|
|
61
49
|
|
|
62
|
-
- **`
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
- **`ThreadProvider`** + **`useThreads()`** (optional)
|
|
67
|
-
- adds “thread list / active thread” state
|
|
68
|
-
- you bring a `ThreadService` (load threads, load events, delete thread, etc.)
|
|
69
|
-
|
|
70
|
-
- **`AuthProvider`** + **`useAuth()`** (optional)
|
|
71
|
-
- plug in an `AuthService` (login/logout/me/token) for authenticated apps
|
|
50
|
+
- **`MelonyProvider`** + **`useMelony()`**
|
|
51
|
+
- Connects to a Melony runtime endpoint.
|
|
52
|
+
- Exposes `events`, `isLoading`, `error`, and `sendEvent()`.
|
|
72
53
|
|
|
73
|
-
##
|
|
54
|
+
## Event Stream & UI
|
|
74
55
|
|
|
75
|
-
|
|
56
|
+
Melony React provides the foundation for building interactive agent UIs. You can listen to the event stream via `useMelony()` and render your own components based on the event types.
|
|
76
57
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
58
|
+
```tsx
|
|
59
|
+
const { events } = useMelony();
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div>
|
|
63
|
+
{events.map(event => {
|
|
64
|
+
if (event.type === "text") return <Text key={event.id} content={event.data.content} />;
|
|
65
|
+
if (event.type === "custom-ui") return <MyCustomUI key={event.id} {...event.data} />;
|
|
66
|
+
return null;
|
|
67
|
+
})}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
89
70
|
```
|
|
90
71
|
|
|
91
|
-
Frontend: no extra work — it shows up in the message stream.
|
|
92
|
-
|
|
93
72
|
## Development
|
|
94
73
|
|
|
95
74
|
```bash
|