@hsafa/ui-sdk 0.1.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.
@@ -0,0 +1,351 @@
1
+ **@hsafa/ui-sdk API Documentation**
2
+
3
+ ***
4
+
5
+ # @hsafa/ui-sdk
6
+
7
+ React SDK for building AI agent interfaces with custom actions and interactive components.
8
+
9
+ ## Features
10
+
11
+ - 🤖 **AI Agent Chat**: Ready-to-use chat interface for AI agents
12
+ - âš¡ **Custom Actions**: Register functions that AI agents can call
13
+ - 🎨 **Dynamic Components**: Create UI components that agents can render
14
+ - 🔧 **TypeScript**: Full TypeScript support with comprehensive type definitions
15
+ - 📦 **Lightweight**: Tree-shakable with minimal dependencies
16
+ - 🎯 **Agent-Focused**: Built specifically for AI agent interactions
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @hsafa/ui-sdk
22
+ # or
23
+ yarn add @hsafa/ui-sdk
24
+ # or
25
+ pnpm add @hsafa/ui-sdk
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ### Basic AI Agent Chat
31
+
32
+ ```tsx
33
+ import { HsafaProvider, HsafaChat } from '@hsafa/ui-sdk';
34
+
35
+ function App() {
36
+ return (
37
+ <HsafaProvider baseUrl="https://your-hsafa-api.com">
38
+ <HsafaChat
39
+ agentId="your-agent-id"
40
+ width={400}
41
+ height={600}
42
+ placeholder="Ask your AI agent anything..."
43
+ />
44
+ </HsafaProvider>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ### Adding Custom Actions
50
+
51
+ ```tsx
52
+ import { HsafaProvider, HsafaChat, useHsafaAction } from '@hsafa/ui-sdk';
53
+
54
+ function MyApp() {
55
+ return (
56
+ <HsafaProvider baseUrl="https://your-hsafa-api.com">
57
+ <ActionProviders />
58
+ <HsafaChat agentId="your-agent-id" />
59
+ </HsafaProvider>
60
+ );
61
+ }
62
+
63
+ function ActionProviders() {
64
+ // Register an action that your AI agent can call
65
+ useHsafaAction('getUserData', async (params) => {
66
+ const { userId } = params;
67
+ // Fetch user data from your database
68
+ return {
69
+ name: 'John Doe',
70
+ email: 'john@example.com',
71
+ status: 'active'
72
+ };
73
+ });
74
+
75
+ useHsafaAction('createTask', async (params) => {
76
+ const { title, description } = params;
77
+ // Create task in your system
78
+ return { taskId: '123', status: 'created' };
79
+ });
80
+
81
+ return null;
82
+ }
83
+ ```
84
+
85
+ ### Custom UI Components
86
+
87
+ ```tsx
88
+ import { useHsafaComponent } from '@hsafa/ui-sdk';
89
+
90
+ function ComponentProviders() {
91
+ // Register UI components that agents can render
92
+ useHsafaComponent('ProductCard', ({ product }) => (
93
+ <div className="border rounded-lg p-4">
94
+ <img src={product.image} alt={product.name} />
95
+ <h3>{product.name}</h3>
96
+ <p>${product.price}</p>
97
+ <button>Add to Cart</button>
98
+ </div>
99
+ ));
100
+
101
+ useHsafaComponent('StatusChart', ({ data }) => (
102
+ <div className="chart-container">
103
+ {/* Your chart implementation */}
104
+ <h4>Status Overview</h4>
105
+ {data.map(item => (
106
+ <div key={item.id}>{item.label}: {item.value}</div>
107
+ ))}
108
+ </div>
109
+ ));
110
+
111
+ return null;
112
+ }
113
+ ```
114
+
115
+ ## Components
116
+
117
+ ### Button
118
+
119
+ A versatile button component with multiple variants and states.
120
+
121
+ ```tsx
122
+ import { Button } from '@hsafa/ui-sdk';
123
+
124
+ // Basic usage
125
+ <Button>Click me</Button>
126
+
127
+ // With variants
128
+ <Button variant="primary">Primary</Button>
129
+ <Button variant="secondary">Secondary</Button>
130
+ <Button variant="outline">Outline</Button>
131
+ <Button variant="ghost">Ghost</Button>
132
+
133
+ // With sizes
134
+ <Button size="sm">Small</Button>
135
+ <Button size="md">Medium</Button>
136
+ <Button size="lg">Large</Button>
137
+
138
+ // With loading state
139
+ <Button loading>Loading...</Button>
140
+
141
+ // Disabled
142
+ <Button disabled>Disabled</Button>
143
+ ```
144
+
145
+ #### Props
146
+
147
+ | Prop | Type | Default | Description |
148
+ |------|------|---------|-------------|
149
+ | `variant` | `'primary' \| 'secondary' \| 'outline' \| 'ghost'` | `'primary'` | Button style variant |
150
+ | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Button size |
151
+ | `loading` | `boolean` | `false` | Show loading spinner |
152
+ | `disabled` | `boolean` | `false` | Disable the button |
153
+ | `children` | `ReactNode` | - | Button content |
154
+
155
+ ## Core Concepts
156
+
157
+ ### AI Agent Integration
158
+
159
+ The SDK connects to your HSAFA AI Agent Studio, allowing your agents to:
160
+ - **Execute Actions**: Call functions in your application
161
+ - **Render Components**: Display custom UI elements in chat
162
+ - **Access Data**: Interact with your backend systems
163
+
164
+ ### How It Works
165
+
166
+ 1. **Agent Calls Action**: Your AI agent (built in HSAFA Studio) decides to call a registered action
167
+ 2. **SDK Executes**: The action runs in your React app with the provided parameters
168
+ 3. **Return Data**: Results are sent back to the agent to continue the conversation
169
+ 4. **Render UI**: Agent can display custom components based on the data
170
+
171
+ ## API Reference
172
+
173
+ ### Components
174
+
175
+ #### HsafaChat
176
+
177
+ Chat interface for your AI agents built in HSAFA Studio.
178
+
179
+ ```tsx
180
+ <HsafaChat
181
+ agentId="your-agent-id"
182
+ width={400}
183
+ height={600}
184
+ />
185
+ ```
186
+
187
+ | Prop | Type | Description |
188
+ |------|------|-------------|
189
+ | `agentId` | `string` | **Required** - ID of your agent from HSAFA Studio |
190
+ | `width` | `number` | Chat panel width (default: 400) |
191
+ | `height` | `number` | Chat panel height (default: 600) |
192
+ | `placeholder` | `string` | Input placeholder text |
193
+ | `primaryColor` | `string` | Primary theme color |
194
+
195
+ #### HsafaProvider
196
+
197
+ Provides context for agent communication.
198
+
199
+ ```tsx
200
+ <HsafaProvider baseUrl="https://your-hsafa-api.com">
201
+ {/* Your app */}
202
+ </HsafaProvider>
203
+ ```
204
+
205
+ | Prop | Type | Description |
206
+ |------|------|-------------|
207
+ | `baseUrl` | `string` | **Required** - Your HSAFA API endpoint |
208
+ | `children` | `ReactNode` | **Required** - App components |
209
+
210
+ ### Hooks
211
+
212
+ #### useHsafaAction
213
+
214
+ Register functions that your AI agent can call. Perfect for connecting agents to your business logic.
215
+
216
+ ```tsx
217
+ import { useHsafaAction } from '@hsafa/ui-sdk';
218
+
219
+ function MyApp() {
220
+ // Register actions your agent can use
221
+ useHsafaAction('getUserProfile', async ({ userId }) => {
222
+ const user = await fetchUserFromDatabase(userId);
223
+ return { name: user.name, email: user.email };
224
+ });
225
+
226
+ useHsafaAction('placeOrder', async ({ productId, quantity }) => {
227
+ const order = await createOrder(productId, quantity);
228
+ return { orderId: order.id, total: order.total };
229
+ });
230
+
231
+ return <YourApp />;
232
+ }
233
+ ```
234
+
235
+ #### useHsafaComponent
236
+
237
+ Register UI components that agents can render in chat. Great for displaying data visually.
238
+
239
+ ```tsx
240
+ import { useHsafaComponent } from '@hsafa/ui-sdk';
241
+
242
+ function MyApp() {
243
+ // Register components your agent can display
244
+ useHsafaComponent('OrderSummary', ({ order }) => (
245
+ <div className="order-card">
246
+ <h3>Order #{order.id}</h3>
247
+ <p>Total: ${order.total}</p>
248
+ <p>Status: {order.status}</p>
249
+ </div>
250
+ ));
251
+
252
+ useHsafaComponent('ProductList', ({ products }) => (
253
+ <div className="grid">
254
+ {products.map(product => (
255
+ <div key={product.id} className="product-card">
256
+ <img src={product.image} alt={product.name} />
257
+ <h4>{product.name}</h4>
258
+ <p>${product.price}</p>
259
+ </div>
260
+ ))}
261
+ </div>
262
+ ));
263
+
264
+ return <YourApp />;
265
+ }
266
+ ```
267
+
268
+ #### useHsafa
269
+
270
+ Advanced hook for manual registration and context access.
271
+
272
+ ```tsx
273
+ import { useHsafa } from '@hsafa/ui-sdk';
274
+
275
+ function MyComponent() {
276
+ const { registerAction, registerComponent } = useHsafa();
277
+
278
+ // Manual registration with cleanup
279
+ useEffect(() => {
280
+ const cleanup1 = registerAction('customAction', handler);
281
+ const cleanup2 = registerComponent('CustomComponent', Component);
282
+
283
+ return () => {
284
+ cleanup1();
285
+ cleanup2();
286
+ };
287
+ }, []);
288
+ }
289
+ ```
290
+
291
+ ## Development
292
+
293
+ ### Prerequisites
294
+
295
+ - Node.js 18+
296
+ - pnpm (recommended)
297
+
298
+ ### Setup
299
+
300
+ ```bash
301
+ # Clone the repository
302
+ git clone https://github.com/husamabusafa/hsafa.git
303
+ cd hsafa/sdk
304
+
305
+ # Install dependencies
306
+ pnpm install
307
+
308
+ # Start development
309
+ pnpm dev
310
+
311
+ # Run tests
312
+ pnpm test
313
+
314
+ # Start Storybook
315
+ pnpm storybook
316
+ ```
317
+
318
+ ### Scripts
319
+
320
+ - `pnpm build` - Build the library for production
321
+ - `pnpm dev` - Build in watch mode
322
+ - `pnpm test` - Run tests
323
+ - `pnpm test:ui` - Run tests with UI
324
+ - `pnpm storybook` - Start Storybook development server
325
+ - `pnpm build:storybook` - Build Storybook for production
326
+ - `pnpm lint` - Run ESLint
327
+ - `pnpm type-check` - Run TypeScript type checking
328
+
329
+ ## Publishing
330
+
331
+ ```bash
332
+ # Build the library
333
+ pnpm build
334
+
335
+ # Publish to npm
336
+ npm publish --access public
337
+ ```
338
+
339
+ ## License
340
+
341
+ MIT © [Husam Abu Safa](https://github.com/husamabusafa)
342
+
343
+ ## Contributing
344
+
345
+ Contributions are welcome! Please feel free to submit a Pull Request.
346
+
347
+ 1. Fork the repository
348
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
349
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
350
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
351
+ 5. Open a Pull Request
@@ -0,0 +1,21 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / HsafaChat
6
+
7
+ # Function: HsafaChat()
8
+
9
+ > **HsafaChat**(`__namedParameters`): `Element`
10
+
11
+ Defined in: [components/HsafaChat.tsx:129](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/HsafaChat.tsx#L129)
12
+
13
+ ## Parameters
14
+
15
+ ### \_\_namedParameters
16
+
17
+ `HsafaChatProps`
18
+
19
+ ## Returns
20
+
21
+ `Element`
@@ -0,0 +1,32 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / HsafaProvider
6
+
7
+ # Function: HsafaProvider()
8
+
9
+ > **HsafaProvider**(`__namedParameters`): `Element`
10
+
11
+ Defined in: [providers/HsafaProvider.tsx:66](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/providers/HsafaProvider.tsx#L66)
12
+
13
+ Provider component that sets up the Hsafa context for the SDK.
14
+ Wrap your app or chat components with this provider to enable Hsafa functionality.
15
+
16
+ ## Parameters
17
+
18
+ ### \_\_namedParameters
19
+
20
+ `HsafaProviderProps`
21
+
22
+ ## Returns
23
+
24
+ `Element`
25
+
26
+ ## Example
27
+
28
+ ```tsx
29
+ <HsafaProvider baseUrl="https://api.example.com">
30
+ <HsafaChat agentId="my-agent" />
31
+ </HsafaProvider>
32
+ ```
@@ -0,0 +1,21 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / useAutoScroll
6
+
7
+ # Function: useAutoScroll()
8
+
9
+ > **useAutoScroll**\<`T`\>(): `MutableRefObject`\<`null` \| `T`\>
10
+
11
+ Defined in: [hooks/useAutoScroll.ts:3](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useAutoScroll.ts#L3)
12
+
13
+ ## Type Parameters
14
+
15
+ ### T
16
+
17
+ `T` *extends* `HTMLElement`
18
+
19
+ ## Returns
20
+
21
+ `MutableRefObject`\<`null` \| `T`\>
@@ -0,0 +1,39 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / useHsafa
6
+
7
+ # Function: useHsafa()
8
+
9
+ > **useHsafa**(): `HsafaContextValue`
10
+
11
+ Defined in: [providers/HsafaProvider.tsx:161](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/providers/HsafaProvider.tsx#L161)
12
+
13
+ Hook to access the Hsafa context.
14
+ Must be used within a HsafaProvider.
15
+
16
+ ## Returns
17
+
18
+ `HsafaContextValue`
19
+
20
+ The Hsafa context value with actions, components, and configuration
21
+
22
+ ## Example
23
+
24
+ ```tsx
25
+ function MyComponent() {
26
+ const { registerAction, baseUrl } = useHsafa();
27
+
28
+ useEffect(() => {
29
+ const unregister = registerAction('myAction', async (params) => {
30
+ console.log('Action called with:', params);
31
+ return { success: true };
32
+ });
33
+
34
+ return unregister;
35
+ }, [registerAction]);
36
+
37
+ return <div>My Component</div>;
38
+ }
39
+ ```
@@ -0,0 +1,28 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / useHsafaAction
6
+
7
+ # Function: useHsafaAction()
8
+
9
+ > **useHsafaAction**(`name`, `handler`): `void`
10
+
11
+ Defined in: [hooks/useHsafaAction.ts:9](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useHsafaAction.ts#L9)
12
+
13
+ Register an action handler by name within the nearest HsafaProvider.
14
+ The handler will be automatically unregistered on unmount.
15
+
16
+ ## Parameters
17
+
18
+ ### name
19
+
20
+ `string`
21
+
22
+ ### handler
23
+
24
+ `HsafaActionHandler`
25
+
26
+ ## Returns
27
+
28
+ `void`
@@ -0,0 +1,28 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / useHsafaComponent
6
+
7
+ # Function: useHsafaComponent()
8
+
9
+ > **useHsafaComponent**(`name`, `component`): `void`
10
+
11
+ Defined in: [hooks/useHsafaComponent.ts:9](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useHsafaComponent.ts#L9)
12
+
13
+ Register a UI component by name within the nearest HsafaProvider.
14
+ The component will be automatically unregistered on unmount.
15
+
16
+ ## Parameters
17
+
18
+ ### name
19
+
20
+ `string`
21
+
22
+ ### component
23
+
24
+ `ComponentType`\<`any`\>
25
+
26
+ ## Returns
27
+
28
+ `void`
@@ -0,0 +1,27 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / useToggle
6
+
7
+ # Function: useToggle()
8
+
9
+ > **useToggle**(`initial`): [`UseToggleReturn`](../interfaces/UseToggleReturn.md)
10
+
11
+ Defined in: [hooks/useToggle.ts:21](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L21)
12
+
13
+ A hook for managing boolean toggle state
14
+
15
+ ## Parameters
16
+
17
+ ### initial
18
+
19
+ `boolean` = `false`
20
+
21
+ Initial state value (default: false)
22
+
23
+ ## Returns
24
+
25
+ [`UseToggleReturn`](../interfaces/UseToggleReturn.md)
26
+
27
+ Object with toggle state and control functions
@@ -0,0 +1,24 @@
1
+ [**@hsafa/ui-sdk API Documentation**](README.md)
2
+
3
+ ***
4
+
5
+ # @hsafa/ui-sdk API Documentation
6
+
7
+ ## Interfaces
8
+
9
+ - [ButtonProps](interfaces/ButtonProps.md)
10
+ - [UseToggleReturn](interfaces/UseToggleReturn.md)
11
+
12
+ ## Variables
13
+
14
+ - [Button](variables/Button.md)
15
+
16
+ ## Functions
17
+
18
+ - [HsafaChat](functions/HsafaChat.md)
19
+ - [useAutoScroll](functions/useAutoScroll.md)
20
+ - [useHsafaAction](functions/useHsafaAction.md)
21
+ - [useHsafaComponent](functions/useHsafaComponent.md)
22
+ - [useToggle](functions/useToggle.md)
23
+ - [HsafaProvider](functions/HsafaProvider.md)
24
+ - [useHsafa](functions/useHsafa.md)
@@ -0,0 +1,59 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / ButtonProps
6
+
7
+ # Interface: ButtonProps
8
+
9
+ Defined in: [components/Button.tsx:7](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/Button.tsx#L7)
10
+
11
+ Props for the Button component
12
+
13
+ ## Extends
14
+
15
+ - `ButtonHTMLAttributes`\<`HTMLButtonElement`\>
16
+
17
+ ## Properties
18
+
19
+ ### variant?
20
+
21
+ > `optional` **variant**: `"primary"` \| `"secondary"` \| `"outline"` \| `"ghost"`
22
+
23
+ Defined in: [components/Button.tsx:9](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/Button.tsx#L9)
24
+
25
+ Visual style variant of the button
26
+
27
+ ***
28
+
29
+ ### size?
30
+
31
+ > `optional` **size**: `"sm"` \| `"md"` \| `"lg"`
32
+
33
+ Defined in: [components/Button.tsx:11](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/Button.tsx#L11)
34
+
35
+ Size of the button
36
+
37
+ ***
38
+
39
+ ### loading?
40
+
41
+ > `optional` **loading**: `boolean`
42
+
43
+ Defined in: [components/Button.tsx:13](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/Button.tsx#L13)
44
+
45
+ Whether the button is in a loading state
46
+
47
+ ***
48
+
49
+ ### children
50
+
51
+ > **children**: `ReactNode`
52
+
53
+ Defined in: [components/Button.tsx:15](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/Button.tsx#L15)
54
+
55
+ Content to be displayed inside the button
56
+
57
+ #### Overrides
58
+
59
+ `React.ButtonHTMLAttributes.children`