@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 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**, including automatic rendering for **Server‑Driven UI (SDUI)** (`event.ui`).
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 { MelonyClientProvider, Thread } from "@melony/react";
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
- <MelonyClientProvider client={client}>
25
- <Thread />
26
- </MelonyClientProvider>
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", role: "user", data: { content: "Hello!" } })
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
- - **`MelonyClientProvider`** + **`useMelony()`**
63
- - wraps a `MelonyClient` from `melony/client`
64
- - exposes `events`, `messages`, `isLoading`, `error`, and `sendEvent()`
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
- ## SDUI (Server‑Driven UI)
54
+ ## Event Stream & UI
74
55
 
75
- If the backend yields events with `event.ui`, Melony React renders them automatically inside assistant messages.
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
- Backend example:
78
-
79
- ```ts
80
- import { ui } from "melony";
81
-
82
- yield {
83
- type: "ui",
84
- ui: ui.card({
85
- title: "Weather",
86
- children: [ui.text("72°F and sunny")],
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