@melony/react 0.1.54 → 0.2.0
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 +16 -34
- 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
|
@@ -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,41 +45,28 @@ 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`, `messages`, `isLoading`, `error`, and `sendEvent()`.
|
|
72
53
|
|
|
73
54
|
## SDUI (Server‑Driven UI)
|
|
74
55
|
|
|
75
|
-
If the backend yields events with `
|
|
56
|
+
If the backend yields events with `type: "ui"`, Melony React renders them automatically inside assistant messages.
|
|
76
57
|
|
|
77
58
|
Backend example:
|
|
78
59
|
|
|
79
60
|
```ts
|
|
80
|
-
import { ui } from "melony";
|
|
81
|
-
|
|
82
61
|
yield {
|
|
83
62
|
type: "ui",
|
|
84
|
-
|
|
63
|
+
data: {
|
|
64
|
+
type: "card",
|
|
85
65
|
title: "Weather",
|
|
86
|
-
children: [
|
|
87
|
-
|
|
66
|
+
children: [
|
|
67
|
+
{ type: "text", value: "72°F and sunny" }
|
|
68
|
+
],
|
|
69
|
+
},
|
|
88
70
|
};
|
|
89
71
|
```
|
|
90
72
|
|