@hsafa/ui-sdk 0.3.3 → 0.4.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 +133 -2
- package/dist/index.cjs +23 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +572 -20
- package/dist/index.d.ts +572 -20
- package/dist/index.js +23 -23
- package/dist/index.js.map +1 -1
- package/docs/CUSTOM_UI_EXAMPLES.md +309 -0
- package/docs/DYNAMIC_PAGE_SCHEMAS.md +261 -0
- package/docs/HEADLESS_QUICK_REFERENCE.md +426 -0
- package/docs/HEADLESS_USAGE.md +682 -0
- package/docs/MIGRATION_TO_HEADLESS.md +408 -0
- package/docs/README.md +43 -71
- package/docs/handbook/00-Overview.md +69 -0
- package/docs/handbook/01-Quickstart.md +133 -0
- package/docs/handbook/02-Architecture.md +75 -0
- package/docs/handbook/03-Components-and-Hooks.md +81 -0
- package/docs/handbook/04-Streaming-and-Transport.md +73 -0
- package/docs/handbook/05-Tools-and-UI.md +73 -0
- package/docs/handbook/06-Storage-and-History.md +63 -0
- package/docs/handbook/07-Dynamic-Pages.md +49 -0
- package/docs/handbook/08-Server-Integration.md +84 -0
- package/docs/handbook/09-Agent-Studio-Client.md +40 -0
- package/docs/handbook/10-Examples-and-Recipes.md +154 -0
- package/docs/handbook/11-API-Reference-Map.md +48 -0
- package/docs/handbook/README.md +24 -0
- package/examples/custom-tools-example.tsx +401 -0
- package/examples/custom-ui-customizations-example.tsx +543 -0
- package/examples/dynamic-page-example.tsx +380 -0
- package/examples/headless-chat-example.tsx +537 -0
- package/examples/minimal-headless-example.tsx +142 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ React SDK for building AI agent interfaces with custom actions and interactive c
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- 🤖 **AI Agent Chat**: Ready-to-use chat interface for AI agents
|
|
8
|
+
- 🎨 **Headless Mode**: Build completely custom UIs with powerful hooks
|
|
8
9
|
- ⚡ **Custom Actions**: Register functions that AI agents can call
|
|
9
10
|
- 🎨 **Dynamic Components**: Create UI components that agents can render
|
|
10
11
|
- 🔧 **TypeScript**: Full TypeScript support with comprehensive type definitions
|
|
@@ -23,7 +24,9 @@ pnpm add @hsafa/ui-sdk
|
|
|
23
24
|
|
|
24
25
|
## Quick Start
|
|
25
26
|
|
|
26
|
-
###
|
|
27
|
+
### Option 1: Pre-built UI Component
|
|
28
|
+
|
|
29
|
+
Use the ready-made chat interface:
|
|
27
30
|
|
|
28
31
|
```tsx
|
|
29
32
|
import { HsafaProvider, HsafaChat } from '@hsafa/ui-sdk';
|
|
@@ -42,6 +45,44 @@ function App() {
|
|
|
42
45
|
}
|
|
43
46
|
```
|
|
44
47
|
|
|
48
|
+
### Option 2: Headless Mode (Build Your Own UI)
|
|
49
|
+
|
|
50
|
+
Use the headless hooks to build a completely custom chat interface:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { useHsafaAgent } from '@hsafa/ui-sdk';
|
|
54
|
+
|
|
55
|
+
function MyCustomChat() {
|
|
56
|
+
const agent = useHsafaAgent({
|
|
57
|
+
agentId: 'my-agent',
|
|
58
|
+
baseUrl: 'https://your-hsafa-api.com',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div>
|
|
63
|
+
{/* Messages */}
|
|
64
|
+
<div>
|
|
65
|
+
{agent.messages.map(msg => (
|
|
66
|
+
<div key={msg.id}>
|
|
67
|
+
<strong>{msg.role}:</strong> {msg.content}
|
|
68
|
+
</div>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
{/* Input */}
|
|
73
|
+
<input
|
|
74
|
+
value={agent.input}
|
|
75
|
+
onChange={(e) => agent.setInput(e.target.value)}
|
|
76
|
+
onKeyPress={(e) => e.key === 'Enter' && agent.sendMessage()}
|
|
77
|
+
/>
|
|
78
|
+
<button onClick={() => agent.sendMessage()}>Send</button>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**📚 [Full Headless Documentation](./docs/HEADLESS_USAGE.md)** - Complete guide with examples
|
|
85
|
+
|
|
45
86
|
### Adding Custom Actions
|
|
46
87
|
|
|
47
88
|
```tsx
|
|
@@ -203,7 +244,97 @@ Provides context for agent communication.
|
|
|
203
244
|
| `baseUrl` | `string` | **Required** - Your HSAFA API endpoint |
|
|
204
245
|
| `children` | `ReactNode` | **Required** - App components |
|
|
205
246
|
|
|
206
|
-
### Hooks
|
|
247
|
+
### Headless Hooks
|
|
248
|
+
|
|
249
|
+
Build custom chat UIs with complete control over styling and layout.
|
|
250
|
+
|
|
251
|
+
#### useHsafaAgent
|
|
252
|
+
|
|
253
|
+
The main hook for headless agent integration. Provides all chat functionality without UI.
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
import { useHsafaAgent } from '@hsafa/ui-sdk';
|
|
257
|
+
|
|
258
|
+
const agent = useHsafaAgent({
|
|
259
|
+
agentId: 'my-agent',
|
|
260
|
+
baseUrl: 'https://your-hsafa-api.com',
|
|
261
|
+
tools: { /* custom tools */ },
|
|
262
|
+
uiComponents: { /* custom UI components */ },
|
|
263
|
+
onFinish: (message) => console.log('Done:', message),
|
|
264
|
+
onError: (error) => console.error('Error:', error),
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Available properties:
|
|
268
|
+
agent.input // Current input text
|
|
269
|
+
agent.setInput() // Update input
|
|
270
|
+
agent.messages // All messages
|
|
271
|
+
agent.isLoading // Loading state
|
|
272
|
+
agent.sendMessage() // Send message
|
|
273
|
+
agent.stop() // Stop generation
|
|
274
|
+
agent.newChat() // Start new chat
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### useChatStorage
|
|
278
|
+
|
|
279
|
+
Persist and manage chat history in localStorage.
|
|
280
|
+
|
|
281
|
+
```tsx
|
|
282
|
+
import { useHsafaAgent, useChatStorage } from '@hsafa/ui-sdk';
|
|
283
|
+
|
|
284
|
+
const agent = useHsafaAgent({ /* ... */ });
|
|
285
|
+
const storage = useChatStorage({
|
|
286
|
+
agentId: 'my-agent',
|
|
287
|
+
chatId: agent.chatId,
|
|
288
|
+
messages: agent.messages,
|
|
289
|
+
isLoading: agent.isLoading,
|
|
290
|
+
autoSave: true,
|
|
291
|
+
autoRestore: true,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Available properties:
|
|
295
|
+
storage.chatList // All saved chats
|
|
296
|
+
storage.loadChat(chatId) // Load specific chat
|
|
297
|
+
storage.deleteChat(chatId) // Delete chat
|
|
298
|
+
storage.switchToChat(chatId) // Switch to chat
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### useMessageEditor
|
|
302
|
+
|
|
303
|
+
Edit messages and regenerate responses.
|
|
304
|
+
|
|
305
|
+
```tsx
|
|
306
|
+
import { useMessageEditor } from '@hsafa/ui-sdk';
|
|
307
|
+
|
|
308
|
+
const editor = useMessageEditor({
|
|
309
|
+
messages: agent.messages,
|
|
310
|
+
isLoading: agent.isLoading,
|
|
311
|
+
sendMessage: agent.sendMessage,
|
|
312
|
+
setMessages: agent.setMessages,
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Available properties:
|
|
316
|
+
editor.startEdit(msgId, text) // Start editing
|
|
317
|
+
editor.saveEdit(msgId) // Save and regenerate
|
|
318
|
+
editor.cancelEdit() // Cancel editing
|
|
319
|
+
editor.isEditing(msgId) // Check if editing
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### useFileUpload
|
|
323
|
+
|
|
324
|
+
Handle file attachments for messages.
|
|
325
|
+
|
|
326
|
+
```tsx
|
|
327
|
+
import { useFileUpload } from '@hsafa/ui-sdk';
|
|
328
|
+
|
|
329
|
+
const fileUpload = useFileUpload('https://your-api.com');
|
|
330
|
+
|
|
331
|
+
// Available properties:
|
|
332
|
+
fileUpload.attachments // Current attachments
|
|
333
|
+
fileUpload.handleFileSelection() // Handle file input
|
|
334
|
+
fileUpload.clearAttachments() // Clear all
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Legacy Hooks
|
|
207
338
|
|
|
208
339
|
#### useHsafaAction
|
|
209
340
|
|