langgraph-ui-components 0.0.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 +240 -0
- package/dist/index.es.js +27100 -0
- package/dist/index.es.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +81 -0
- package/src/App.tsx +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Agentic Chat Components
|
|
2
|
+
|
|
3
|
+
A React component library for building AI chat interfaces with LangChain/LangGraph integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **Pre-styled chat UI components** - Sidebar, message bubbles, input fields, markdown rendering
|
|
8
|
+
- 🔄 **Streaming support** - Real-time AI response streaming
|
|
9
|
+
- 📎 **File uploads** - Built-in file handling and metadata
|
|
10
|
+
- 🎭 **Custom components** - Inject your own React components into chat messages
|
|
11
|
+
- 🧩 **Provider-based architecture** - Flexible state management with React Context
|
|
12
|
+
- 📝 **TypeScript** - Full type definitions included
|
|
13
|
+
- 🎨 **Tailwind CSS** - Pre-built styles, easy to customize
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install agentic-chat-ui-components
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Peer dependencies** (install these separately):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install react react-dom @langchain/core @langchain/langgraph @langchain/langgraph-sdk framer-motion lucide-react react-markdown react-spinners rehype-highlight remark-gfm sonner @radix-ui/react-label
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import {
|
|
31
|
+
Sidebar,
|
|
32
|
+
ChatProvider
|
|
33
|
+
} from 'agentic-chat-ui-components';
|
|
34
|
+
import 'agentic-chat-ui-components/styles.css';
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
return (
|
|
38
|
+
<ChatProvider
|
|
39
|
+
apiUrl="your-api-url"
|
|
40
|
+
assistantId="your-assistant-id"
|
|
41
|
+
identity={{ user_id: "user123", org_id: "org456" }}
|
|
42
|
+
>
|
|
43
|
+
<Sidebar />
|
|
44
|
+
</ChatProvider>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Exported Components
|
|
50
|
+
|
|
51
|
+
- `Sidebar` - Main chat UI with sidebar navigation
|
|
52
|
+
|
|
53
|
+
## Exported Providers
|
|
54
|
+
|
|
55
|
+
- `ChatProvider` - Core chat state management
|
|
56
|
+
- `ChatRuntimeProvider` - Runtime configuration
|
|
57
|
+
- `ThreadProvider` - Conversation thread management
|
|
58
|
+
- `StreamProvider` - AI streaming responses
|
|
59
|
+
- `FileProvider` - File upload handling
|
|
60
|
+
- `CustomComponentProvider` - Custom component rendering
|
|
61
|
+
|
|
62
|
+
## Exported Hooks
|
|
63
|
+
|
|
64
|
+
- `useThread()` - Access thread state
|
|
65
|
+
- `useStreamContext()` - Access streaming state
|
|
66
|
+
- `useChatRuntime()` - Access runtime config
|
|
67
|
+
- `useFileProvider()` - Access file state
|
|
68
|
+
- `useCustomComponents()` - Register custom components
|
|
69
|
+
- `useChatSuggestions()` - Display contextual chat suggestions
|
|
70
|
+
|
|
71
|
+
## useChatSuggestions Hook
|
|
72
|
+
|
|
73
|
+
The `useChatSuggestions` hook enables intelligent, opt-in chat suggestions for your application. It acts as a configuration hook that **doesn't return anything** but internally registers suggestion settings. The built-in `Suggestion` component (included in `Sidebar`) automatically picks up this configuration and displays suggestions only when the hook is used.
|
|
74
|
+
|
|
75
|
+
### Key Features
|
|
76
|
+
|
|
77
|
+
- **Opt-in by default** - Suggestions only appear when you call this hook
|
|
78
|
+
- **No return value** - Simply call it to enable suggestions
|
|
79
|
+
- **Context-aware** - Pass dependencies for dynamic, contextual suggestions
|
|
80
|
+
- **Agent integration** - Automatically uses agent-provided suggestions when available
|
|
81
|
+
|
|
82
|
+
### Basic Usage
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { useChatSuggestions } from 'agentic-chat-ui-components';
|
|
86
|
+
|
|
87
|
+
function MyComponent() {
|
|
88
|
+
// Simply call the hook - it registers configuration internally
|
|
89
|
+
useChatSuggestions({
|
|
90
|
+
instructions: "Suggest helpful next actions",
|
|
91
|
+
minSuggestions: 1,
|
|
92
|
+
maxSuggestions: 2,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return <div>Your component content</div>;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Without the Hook
|
|
100
|
+
|
|
101
|
+
If you **don't call** `useChatSuggestions` anywhere in your component tree, **no suggestions will be generated or displayed**. This makes the feature completely opt-in.
|
|
102
|
+
|
|
103
|
+
### Options
|
|
104
|
+
|
|
105
|
+
- `instructions` (string, optional): Guidance text for suggestion generation. Default: `"Suggest relevant next actions."`
|
|
106
|
+
- `minSuggestions` (number, optional): Minimum number of suggestions to display. Default: `2`
|
|
107
|
+
- `maxSuggestions` (number, optional): Maximum number of suggestions to display. Default: `4`
|
|
108
|
+
|
|
109
|
+
**Note:** The hook returns `void` - it doesn't provide any return values. The internal `Suggestion` component handles display and interaction.
|
|
110
|
+
|
|
111
|
+
### Agent Integration
|
|
112
|
+
|
|
113
|
+
When your agent returns suggestions in the response (via the `suggestions` field in state), they're automatically used instead of generating defaults:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"messages": [...],
|
|
118
|
+
"suggestions": ["Show part details", "Update configuration", "Get pricing"]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The system seamlessly switches between agent-provided suggestions and fallback suggestions based on availability.
|
|
123
|
+
|
|
124
|
+
### Context-Aware Suggestions
|
|
125
|
+
|
|
126
|
+
Pass dependencies as the second argument to generate context-aware suggestions:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
function ChatInterface() {
|
|
130
|
+
const [lastMessage, setLastMessage] = useState('');
|
|
131
|
+
|
|
132
|
+
useChatSuggestions(
|
|
133
|
+
{
|
|
134
|
+
instructions: "Suggest based on conversation context",
|
|
135
|
+
maxSuggestions: 3,
|
|
136
|
+
},
|
|
137
|
+
[lastMessage] // Dependencies trigger context-aware generation
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return <div>...</div>;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
When dependencies change, suggestions are regenerated to match the new context.
|
|
145
|
+
|
|
146
|
+
## sendMessage Function
|
|
147
|
+
|
|
148
|
+
The `sendMessage` function is available through the `useStreamContext()` hook and allows you to send messages programmatically to the AI agent.
|
|
149
|
+
|
|
150
|
+
### Parameters
|
|
151
|
+
|
|
152
|
+
- `message` (Message | string): The message content. Can be a string for simple text messages or a full Message object for more control.
|
|
153
|
+
- `options` (optional object):
|
|
154
|
+
- `type` (Message["type"], optional): The message type to use when sending a string message. Defaults to "human" for user messages. Use "system" for agent-only messages.
|
|
155
|
+
- `config` (any, optional): Additional configuration to pass to the agent.
|
|
156
|
+
|
|
157
|
+
### Usage Example
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
import { useStreamContext } from 'agentic-chat-ui-components';
|
|
161
|
+
|
|
162
|
+
function MyComponent() {
|
|
163
|
+
const { sendMessage } = useStreamContext();
|
|
164
|
+
|
|
165
|
+
const handleSend = async () => {
|
|
166
|
+
await sendMessage("Hello, AI!", { isAIMessage: false });
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return <button onClick={handleSend}>Send Message</button>;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
This will send a user-visible message "Hello, AI!" to the agent.
|
|
174
|
+
|
|
175
|
+
For agent-only messages:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
await sendMessage("Internal event occurred", { type: "system" });
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Custom Components
|
|
182
|
+
|
|
183
|
+
You can inject custom React components into chat messages using the `CustomComponentProvider`. Components are registered by name and can be referenced in message content.
|
|
184
|
+
|
|
185
|
+
### Registering Components via Props
|
|
186
|
+
|
|
187
|
+
Pass initial components as the `initialComponents` prop to `CustomComponentProvider`:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { CustomComponentProvider } from 'agentic-chat-ui-components';
|
|
191
|
+
|
|
192
|
+
const MyCustomButton = ({ text }) => <button>{text}</button>;
|
|
193
|
+
|
|
194
|
+
function App() {
|
|
195
|
+
return (
|
|
196
|
+
<CustomComponentProvider
|
|
197
|
+
initialComponents={{
|
|
198
|
+
'my-button': MyCustomButton,
|
|
199
|
+
}}
|
|
200
|
+
>
|
|
201
|
+
{/* Your app */}
|
|
202
|
+
</CustomComponentProvider>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Registering Components Programmatically
|
|
208
|
+
|
|
209
|
+
Use the `registerComponent` method from the `useCustomComponents` hook:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
import { useCustomComponents } from 'agentic-chat-ui-components';
|
|
213
|
+
|
|
214
|
+
function RegisterComponent() {
|
|
215
|
+
const { registerComponent } = useCustomComponents();
|
|
216
|
+
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
registerComponent('my-button', ({ text }) => <button>{text}</button>);
|
|
219
|
+
}, [registerComponent]);
|
|
220
|
+
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Additional Methods
|
|
226
|
+
|
|
227
|
+
- `registerComponents(components)`: Register multiple components at once.
|
|
228
|
+
- `unregisterComponent(name)`: Remove a registered component.
|
|
229
|
+
|
|
230
|
+
## Types
|
|
231
|
+
|
|
232
|
+
Full TypeScript definitions available for:
|
|
233
|
+
- `ChatIdentity`
|
|
234
|
+
- `ChatRuntimeContextValue`
|
|
235
|
+
- `FileInfo`
|
|
236
|
+
- `SuggestionsOptions`
|
|
237
|
+
|
|
238
|
+
## Development Notes
|
|
239
|
+
|
|
240
|
+
This library is designed to work with LangChain/LangGraph for AI agent interactions. All heavy dependencies are peer dependencies to keep the bundle size small (~50-200 KB).
|