@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,81 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / UseToggleReturn
6
+
7
+ # Interface: UseToggleReturn
8
+
9
+ Defined in: [hooks/useToggle.ts:3](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L3)
10
+
11
+ ## Properties
12
+
13
+ ### on
14
+
15
+ > **on**: `boolean`
16
+
17
+ Defined in: [hooks/useToggle.ts:5](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L5)
18
+
19
+ Current toggle state
20
+
21
+ ***
22
+
23
+ ### toggle()
24
+
25
+ > **toggle**: () => `void`
26
+
27
+ Defined in: [hooks/useToggle.ts:7](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L7)
28
+
29
+ Toggle the state
30
+
31
+ #### Returns
32
+
33
+ `void`
34
+
35
+ ***
36
+
37
+ ### setOn()
38
+
39
+ > **setOn**: (`value`) => `void`
40
+
41
+ Defined in: [hooks/useToggle.ts:9](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L9)
42
+
43
+ Set the state directly
44
+
45
+ #### Parameters
46
+
47
+ ##### value
48
+
49
+ `boolean` | (`prev`) => `boolean`
50
+
51
+ #### Returns
52
+
53
+ `void`
54
+
55
+ ***
56
+
57
+ ### setTrue()
58
+
59
+ > **setTrue**: () => `void`
60
+
61
+ Defined in: [hooks/useToggle.ts:11](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L11)
62
+
63
+ Set state to true
64
+
65
+ #### Returns
66
+
67
+ `void`
68
+
69
+ ***
70
+
71
+ ### setFalse()
72
+
73
+ > **setFalse**: () => `void`
74
+
75
+ Defined in: [hooks/useToggle.ts:13](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/hooks/useToggle.ts#L13)
76
+
77
+ Set state to false
78
+
79
+ #### Returns
80
+
81
+ `void`
@@ -0,0 +1,29 @@
1
+ [**@hsafa/ui-sdk API Documentation**](../README.md)
2
+
3
+ ***
4
+
5
+ [@hsafa/ui-sdk API Documentation](../globals.md) / Button
6
+
7
+ # Variable: Button
8
+
9
+ > `const` **Button**: `React.FC`\<[`ButtonProps`](../interfaces/ButtonProps.md)\>
10
+
11
+ Defined in: [components/Button.tsx:36](https://github.com/husamabusafa/hsafa/blob/1bcff44fada407a2574b2306f2d974ade919aebf/sdk/src/components/Button.tsx#L36)
12
+
13
+ A versatile button component with multiple variants, sizes, and states.
14
+
15
+ ## Example
16
+
17
+ ```tsx
18
+ // Basic usage
19
+ <Button>Click me</Button>
20
+
21
+ // With variant and size
22
+ <Button variant="secondary" size="lg">Large Secondary Button</Button>
23
+
24
+ // Loading state
25
+ <Button loading>Processing...</Button>
26
+
27
+ // With click handler
28
+ <Button onClick={() => console.log('Clicked!')}>Click me</Button>
29
+ ```
@@ -0,0 +1,229 @@
1
+ /**
2
+ * E-commerce AI Agent Example
3
+ *
4
+ * This example shows how to integrate the HSAFA SDK with an e-commerce application.
5
+ * The AI agent can search products, show product details, and process orders.
6
+ */
7
+
8
+ import React from 'react';
9
+ import {
10
+ HsafaProvider,
11
+ HsafaChat,
12
+ useHsafaAction,
13
+ useHsafaComponent
14
+ } from '@hsafa/ui-sdk';
15
+
16
+ // Mock data
17
+ const products = [
18
+ { id: 1, name: 'Wireless Headphones', price: 99.99, image: '/headphones.jpg', stock: 15 },
19
+ { id: 2, name: 'Smart Watch', price: 199.99, image: '/watch.jpg', stock: 8 },
20
+ { id: 3, name: 'Bluetooth Speaker', price: 79.99, image: '/speaker.jpg', stock: 22 },
21
+ ];
22
+
23
+ const orders = new Map();
24
+
25
+ // Product Card Component
26
+ function ProductCard({ product, onAddToCart }: { product: any; onAddToCart: (id: number) => void }) {
27
+ return (
28
+ <div className="border rounded-lg p-4 bg-white shadow-sm">
29
+ <img
30
+ src={product.image}
31
+ alt={product.name}
32
+ className="w-full h-32 object-cover rounded mb-2"
33
+ onError={(e) => { e.currentTarget.src = '/placeholder.png'; }}
34
+ />
35
+ <h3 className="font-semibold text-lg">{product.name}</h3>
36
+ <p className="text-gray-600">${product.price}</p>
37
+ <p className="text-sm text-gray-500">Stock: {product.stock}</p>
38
+ <button
39
+ onClick={() => onAddToCart(product.id)}
40
+ className="mt-2 w-full bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600"
41
+ disabled={product.stock === 0}
42
+ >
43
+ {product.stock === 0 ? 'Out of Stock' : 'Add to Cart'}
44
+ </button>
45
+ </div>
46
+ );
47
+ }
48
+
49
+ // Order Summary Component
50
+ function OrderSummary({ order }: { order: any }) {
51
+ return (
52
+ <div className="border rounded-lg p-4 bg-green-50 border-green-200">
53
+ <h3 className="font-semibold text-lg text-green-800">Order Confirmed!</h3>
54
+ <div className="mt-2 space-y-1">
55
+ <p><strong>Order ID:</strong> {order.id}</p>
56
+ <p><strong>Total:</strong> ${order.total}</p>
57
+ <p><strong>Status:</strong> {order.status}</p>
58
+ <p><strong>Estimated Delivery:</strong> {order.estimatedDelivery}</p>
59
+ </div>
60
+ </div>
61
+ );
62
+ }
63
+
64
+ // Component that provides actions and components to the AI agent
65
+ function EcommerceActionProvider() {
66
+ // Action: Search for products
67
+ useHsafaAction('searchProducts', async (params) => {
68
+ const { query } = params;
69
+ console.log('🔍 Searching products:', query);
70
+
71
+ // Simple search implementation
72
+ const results = products.filter(product =>
73
+ product.name.toLowerCase().includes(query.toLowerCase())
74
+ );
75
+
76
+ return {
77
+ success: true,
78
+ products: results,
79
+ total: results.length
80
+ };
81
+ });
82
+
83
+ // Action: Get product details
84
+ useHsafaAction('getProduct', async (params) => {
85
+ const { productId } = params;
86
+ console.log('📦 Getting product:', productId);
87
+
88
+ const product = products.find(p => p.id === parseInt(productId));
89
+
90
+ if (!product) {
91
+ return { success: false, error: 'Product not found' };
92
+ }
93
+
94
+ return {
95
+ success: true,
96
+ product
97
+ };
98
+ });
99
+
100
+ // Action: Create order
101
+ useHsafaAction('createOrder', async (params) => {
102
+ const { productId, quantity = 1, customerInfo } = params;
103
+ console.log('🛒 Creating order:', { productId, quantity, customerInfo });
104
+
105
+ const product = products.find(p => p.id === parseInt(productId));
106
+
107
+ if (!product) {
108
+ return { success: false, error: 'Product not found' };
109
+ }
110
+
111
+ if (product.stock < quantity) {
112
+ return { success: false, error: 'Insufficient stock' };
113
+ }
114
+
115
+ // Create order
116
+ const orderId = `ORD-${Date.now()}`;
117
+ const order = {
118
+ id: orderId,
119
+ productId: product.id,
120
+ productName: product.name,
121
+ quantity,
122
+ unitPrice: product.price,
123
+ total: (product.price * quantity).toFixed(2),
124
+ status: 'confirmed',
125
+ customerInfo,
126
+ estimatedDelivery: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toLocaleDateString()
127
+ };
128
+
129
+ orders.set(orderId, order);
130
+
131
+ // Update stock
132
+ product.stock -= quantity;
133
+
134
+ return {
135
+ success: true,
136
+ order
137
+ };
138
+ });
139
+
140
+ // Action: Check order status
141
+ useHsafaAction('checkOrder', async (params) => {
142
+ const { orderId } = params;
143
+ console.log('📋 Checking order:', orderId);
144
+
145
+ const order = orders.get(orderId);
146
+
147
+ if (!order) {
148
+ return { success: false, error: 'Order not found' };
149
+ }
150
+
151
+ return {
152
+ success: true,
153
+ order
154
+ };
155
+ });
156
+
157
+ // Component: Product grid
158
+ useHsafaComponent('ProductGrid', ({ products: productList }) => (
159
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 p-4">
160
+ {productList.map((product: any) => (
161
+ <ProductCard
162
+ key={product.id}
163
+ product={product}
164
+ onAddToCart={(id) => console.log('Add to cart clicked:', id)}
165
+ />
166
+ ))}
167
+ </div>
168
+ ));
169
+
170
+ // Component: Single product display
171
+ useHsafaComponent('ProductDisplay', ({ product }) => (
172
+ <ProductCard
173
+ product={product}
174
+ onAddToCart={(id) => console.log('Add to cart clicked:', id)}
175
+ />
176
+ ));
177
+
178
+ // Component: Order confirmation
179
+ useHsafaComponent('OrderConfirmation', ({ order }) => (
180
+ <OrderSummary order={order} />
181
+ ));
182
+
183
+ return null;
184
+ }
185
+
186
+ // Main E-commerce AI Agent App
187
+ export function EcommerceAgentExample() {
188
+ return (
189
+ <div className="min-h-screen bg-gray-50 p-4">
190
+ <div className="max-w-4xl mx-auto">
191
+ <h1 className="text-3xl font-bold text-center mb-6">
192
+ E-commerce AI Assistant
193
+ </h1>
194
+
195
+ <div className="bg-white rounded-lg shadow-lg p-6">
196
+ <HsafaProvider baseUrl="http://localhost:3900">
197
+ <EcommerceActionProvider />
198
+
199
+ <div className="flex justify-center">
200
+ <HsafaChat
201
+ agentId="ecommerce-agent"
202
+ width={500}
203
+ height={600}
204
+ placeholder="Ask me about products, orders, or anything else!"
205
+ welcomeMessage="Hello! I'm your shopping assistant. I can help you find products, check prices, and place orders. What are you looking for today?"
206
+ primaryColor="#3b82f6"
207
+ backgroundColor="#ffffff"
208
+ />
209
+ </div>
210
+
211
+ {/* Instructions */}
212
+ <div className="mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg">
213
+ <h3 className="font-semibold text-blue-800 mb-2">Try asking:</h3>
214
+ <ul className="text-sm text-blue-700 space-y-1">
215
+ <li>• "Show me all products"</li>
216
+ <li>• "Search for headphones"</li>
217
+ <li>• "I want to buy a smart watch"</li>
218
+ <li>• "Check my order status"</li>
219
+ <li>• "What's the price of the bluetooth speaker?"</li>
220
+ </ul>
221
+ </div>
222
+ </HsafaProvider>
223
+ </div>
224
+ </div>
225
+ </div>
226
+ );
227
+ }
228
+
229
+ export default EcommerceAgentExample;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Getting Started Example
3
+ *
4
+ * Simple example showing how to set up an AI agent with basic actions.
5
+ */
6
+
7
+ import React from 'react';
8
+ import { HsafaProvider, HsafaChat, useHsafaAction, useHsafaComponent } from '@hsafa/ui-sdk';
9
+
10
+ // Simple action providers
11
+ function BasicActionProviders() {
12
+ // Register a simple greeting action
13
+ useHsafaAction('getGreeting', async (params) => {
14
+ const { name } = params;
15
+ return {
16
+ message: `Hello ${name}! Welcome to HSAFA AI Agent Studio!`,
17
+ timestamp: new Date().toLocaleTimeString()
18
+ };
19
+ });
20
+
21
+ // Register a simple calculation action
22
+ useHsafaAction('calculate', async (params) => {
23
+ const { operation, a, b } = params;
24
+
25
+ let result;
26
+ switch (operation) {
27
+ case 'add': result = a + b; break;
28
+ case 'subtract': result = a - b; break;
29
+ case 'multiply': result = a * b; break;
30
+ case 'divide': result = b !== 0 ? a / b : 'Cannot divide by zero'; break;
31
+ default: result = 'Unknown operation';
32
+ }
33
+
34
+ return {
35
+ operation,
36
+ operands: [a, b],
37
+ result
38
+ };
39
+ });
40
+
41
+ // Register a simple info card component
42
+ useHsafaComponent('InfoCard', ({ title, content, type = 'info' }) => {
43
+ const colors = {
44
+ info: 'bg-blue-50 border-blue-200 text-blue-800',
45
+ success: 'bg-green-50 border-green-200 text-green-800',
46
+ warning: 'bg-yellow-50 border-yellow-200 text-yellow-800'
47
+ };
48
+
49
+ return (
50
+ <div className={`p-4 border rounded-lg ${colors[type as keyof typeof colors]}`}>
51
+ <h3 className="font-semibold mb-2">{title}</h3>
52
+ <p>{content}</p>
53
+ </div>
54
+ );
55
+ });
56
+
57
+ return null;
58
+ }
59
+
60
+ export function GettingStartedExample() {
61
+ return (
62
+ <div className="min-h-screen bg-gray-50 p-8">
63
+ <div className="max-w-2xl mx-auto">
64
+ <h1 className="text-3xl font-bold text-center mb-6">
65
+ Getting Started with HSAFA AI Agent SDK
66
+ </h1>
67
+
68
+ <div className="bg-white rounded-lg shadow-lg p-6">
69
+ <HsafaProvider baseUrl="http://localhost:3900">
70
+ <BasicActionProviders />
71
+
72
+ <HsafaChat
73
+ agentId="demo-agent"
74
+ width={600}
75
+ height={500}
76
+ placeholder="Try asking me to greet you or do some math!"
77
+ welcomeMessage="Hi! I'm your AI assistant. I can greet people and do simple calculations. Try asking me something!"
78
+ />
79
+
80
+ <div className="mt-4 p-3 bg-gray-50 rounded text-sm text-gray-600">
81
+ <strong>Try these examples:</strong>
82
+ <ul className="mt-1 space-y-1">
83
+ <li>• "Greet me, my name is John"</li>
84
+ <li>• "Calculate 15 + 25"</li>
85
+ <li>• "What's 100 divided by 4?"</li>
86
+ <li>• "Show me an info card about AI"</li>
87
+ </ul>
88
+ </div>
89
+ </HsafaProvider>
90
+ </div>
91
+ </div>
92
+ </div>
93
+ );
94
+ }
95
+
96
+ export default GettingStartedExample;
package/package.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "name": "@hsafa/ui-sdk",
3
+ "version": "0.1.0",
4
+ "description": "React SDK for integrating AI agents built with HSAFA AI Agent Studio",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "examples",
9
+ "docs",
10
+ "DOCUMENTATION.md"
11
+ ],
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "sideEffects": [
23
+ "**/*.css"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "dev": "tsup --watch",
31
+ "test": "vitest",
32
+ "test:ui": "vitest --ui",
33
+ "storybook": "storybook dev -p 6006",
34
+ "build-storybook": "storybook build",
35
+ "lint": "eslint src --ext .ts,.tsx",
36
+ "type-check": "tsc --noEmit",
37
+ "docs:api": "typedoc",
38
+ "docs:dev": "pnpm storybook",
39
+ "docs:build": "pnpm build-storybook && pnpm docs:api",
40
+ "prepublishOnly": "pnpm build && pnpm test",
41
+ "publish:npm": "npm publish --access public"
42
+ },
43
+ "peerDependencies": {
44
+ "@tabler/icons-react": ">=3",
45
+ "react": ">=18",
46
+ "react-dom": ">=18"
47
+ },
48
+ "devDependencies": {
49
+ "@eslint/js": "^9.35.0",
50
+ "@storybook/addon-essentials": "^8.6.14",
51
+ "@storybook/addon-interactions": "^8.6.14",
52
+ "@storybook/addon-links": "^8.6.14",
53
+ "@storybook/react": "^8.6.14",
54
+ "@storybook/react-vite": "^8.6.14",
55
+ "@swc/core": "^1.3.0",
56
+ "@tabler/icons-react": "^3.21.0",
57
+ "@testing-library/jest-dom": "^6.1.5",
58
+ "@testing-library/react": "^14.1.2",
59
+ "@testing-library/user-event": "^14.5.1",
60
+ "@types/react": "^18.2.45",
61
+ "@types/react-dom": "^18.2.18",
62
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
63
+ "@typescript-eslint/parser": "^8.43.0",
64
+ "@vitejs/plugin-react": "^4.2.1",
65
+ "autoprefixer": "^10.4.16",
66
+ "eslint": "^9.35.0",
67
+ "eslint-plugin-react-hooks": "^5.2.0",
68
+ "eslint-plugin-react-refresh": "^0.4.20",
69
+ "globals": "^15.15.0",
70
+ "jsdom": "^23.0.1",
71
+ "postcss": "^8.4.32",
72
+ "react": "^18.2.0",
73
+ "react-dom": "^18.2.0",
74
+ "storybook": "^8.6.14",
75
+ "tailwindcss": "^3.3.6",
76
+ "tsup": "^8.0.1",
77
+ "typedoc": "^0.28.12",
78
+ "typedoc-plugin-markdown": "^4.8.1",
79
+ "typescript": "^5.3.3",
80
+ "vite": "^5.0.0",
81
+ "vitest": "^1.1.0"
82
+ },
83
+ "keywords": [
84
+ "react",
85
+ "ui",
86
+ "components",
87
+ "typescript",
88
+ "sdk",
89
+ "hsafa",
90
+ "chat",
91
+ "ai",
92
+ "frontend",
93
+ "library",
94
+ "hooks",
95
+ "tailwind",
96
+ "modern"
97
+ ],
98
+ "author": "Husam Abu Safa",
99
+ "license": "MIT",
100
+ "repository": {
101
+ "type": "git",
102
+ "url": "git+https://github.com/husamabusafa/hsafa.git",
103
+ "directory": "sdk"
104
+ },
105
+ "homepage": "https://github.com/husamabusafa/hsafa/tree/main/sdk#readme",
106
+ "bugs": {
107
+ "url": "https://github.com/husamabusafa/hsafa/issues"
108
+ }
109
+ }