mehdi-akbari-ai-assistant-free 0.9.6 → 0.9.8

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,50 +1,93 @@
1
+
1
2
  AI Assistant - React Component
3
+
2
4
  Author: Mehdi Akbari
5
+
3
6
  Gmail: mehdiakbarideveloper@gmail.com
7
+
4
8
  Telegram: @MehdiAkbariDev
9
+
5
10
  ![alt text](https://img.shields.io/npm/v/mehdi-akbari-ai-assistant-free.svg)
6
11
 
12
+
7
13
  ![alt text](https://img.shields.io/npm/l/mehdi-akbari-ai-assistant-free.svg)
14
+
8
15
  ⚠️ Note: This project is currently under active development.
16
+
9
17
  Features may change, and new updates are being added regularly. Contributions and feedback are welcome!
18
+
10
19
  ⚠️ توجه: این پروژه در حال حاضر در حال توسعه فعال است.
20
+
11
21
  ویژگی‌ها ممکن است تغییر کنند و به‌روزرسانی‌های جدید به طور مرتب اضافه می‌شوند. از مشارکت و بازخورد شما استقبال می‌شود!
22
+
12
23
  English
24
+
13
25
  A professional, beautiful, and ready-to-use AI chatbot component for your React projects. This package provides a floating, engaging UI, allowing you to easily integrate a smart assistant into your website. It's built with pure CSS, inspired by Tailwind's aesthetics, to ensure it works out-of-the-box in any project without extra configuration.
26
+
14
27
  ![alt text](https://your-image-host.com/demo.gif)
15
28
 
16
29
  (Recommendation: Record a GIF of the component in action and replace this link)
30
+
17
31
  ✨ Key Features
32
+
18
33
  Easy Setup: Just install the package, import the CSS, and drop the component into your app.
34
+
19
35
  Floating Action Button (FAB): A floating button with a Lottie animation that opens and closes the chat window, accessible on all pages.
36
+
20
37
  Fullscreen Mode: With a single click, the chat window expands to fill the entire screen for an immersive chat experience.
38
+
21
39
  Customizable Lottie Animation: Easily replace the default FAB animation with your own Lottie animation.
40
+
22
41
  Dynamic Text Input: A textarea that automatically resizes as the user types, perfect for comfortable multi-line messages.
42
+
23
43
  CSS Variable Theming: Customize the component's colors and appearance to match your brand by simply overriding CSS variables.
44
+
24
45
  Backend Agnostic: The component connects to any API endpoint you provide.
46
+
25
47
  🚀 Installation
48
+
26
49
  Install the package in your project using npm or yarn:
50
+
27
51
  code
28
52
  Bash
53
+ download
54
+ content_copy
55
+ expand_less
29
56
  npm install mehdi-akbari-ai-assistant-free
57
+
30
58
  or
59
+
31
60
  code
32
61
  Bash
62
+ download
63
+ content_copy
64
+ expand_less
33
65
  yarn add mehdi-akbari-ai-assistant-free
34
66
  📋 Usage
35
67
  Step 1: Import the Styles
68
+
36
69
  The most important step is to import the package's CSS file into your main application file. This makes all the necessary styles globally available.
70
+
37
71
  In your layout.js/layout.tsx (Next.js) or App.js (Create React App), add the following line:
72
+
38
73
  code
39
74
  JavaScript
75
+ download
76
+ content_copy
77
+ expand_less
40
78
  import 'mehdi-akbari-ai-assistant-free/styles.css';
41
79
  Step 2: Use the Component
42
- Import the AiAssistant component and place it in your desired page. The only required prop is apiEndpoint.
80
+
81
+ Import the AiAssistant component and place it in your desired page.
82
+
43
83
  code
44
84
  JavaScript
85
+ download
86
+ content_copy
87
+ expand_less
45
88
  import { AiAssistant } from "mehdi-akbari-ai-assistant-free/react";
46
89
 
47
- export default function HomePage() {
90
+ export default function HomePage() {
48
91
  return (
49
92
  <div>
50
93
  <h1>Welcome to my website</h1>
@@ -52,8 +95,62 @@ export default function HomePage() {
52
95
 
53
96
  <AiAssistant apiEndpoint="/api/chat" />
54
97
  </div>
55
- );
98
+ );
99
+ }
100
+ Step 3: Create the API Endpoint
101
+
102
+ The AiAssistant component is a frontend-only tool. It needs a backend API route to securely communicate with the AI service. Here’s how to create the /api/chat endpoint using Next.js App Router.
103
+
104
+ Create the route file: In your Next.js project, create a new file at app/api/chat/route.ts (or .js).
105
+
106
+ Add the following code: This code uses the AiRobot class from this package to handle the server-side logic.
107
+
108
+ code
109
+ TypeScript
110
+ download
111
+ content_copy
112
+ expand_less
113
+ // app/api/chat/route.ts
114
+ import { NextResponse } from 'next/server';
115
+ import { AiRobot, Message } from 'mehdi-akbari-ai-assistant-free';
116
+
117
+ export async function POST(req: Request) {
118
+ try {
119
+ const { messages }: { messages: Message[] } = await req.json();
120
+
121
+ if (!messages) {
122
+ return NextResponse.json({ error: 'Messages are required' }, { status: 400 });
123
+ }
124
+
125
+ // Read the API key from environment variables for security
126
+ const apiKey = process.env.GROQ_API_KEY;
127
+ if (!apiKey) {
128
+ return NextResponse.json({ error: 'AI provider API key is not configured' }, { status: 500 });
129
+ }
130
+
131
+ // Initialize the robot with your API key
132
+ const robot = new AiRobot({ apiKey });
133
+
134
+ // Get the response from the AI
135
+ const content = await robot.chat(messages);
136
+
137
+ // Send the response back to the client
138
+ return NextResponse.json({ content });
139
+
140
+ } catch (error) {
141
+ console.error('API Route Error:', error);
142
+ return NextResponse.json({ error: 'An internal server error occurred' }, { status: 500 });
143
+ }
56
144
  }
145
+
146
+ Set up Environment Variables: Create a file named .env.local in the root of your project and add your Groq API key:
147
+
148
+ code
149
+ Code
150
+ download
151
+ content_copy
152
+ expand_less
153
+ GROQ_API_KEY="YOUR_GROQ_API_KEY_HERE"
57
154
  ⚙️ Props (API Reference)
58
155
  Prop Type Required Default Description
59
156
  apiEndpoint string Yes - The URL of your API endpoint that handles chat requests.
@@ -61,60 +158,98 @@ title string No "AI Assistant" The title displayed in the chat window header.
61
158
  welcomeMessage string No "Hello! How can I help you?" The initial message displayed by the bot when the window opens.
62
159
  lottieAnimationData any No A default robot animation The Lottie animation data. Can be a URL (string) or an imported JSON object.
63
160
  🎨 Customization (Theming)
64
- You can easily customize the component's appearance by overriding the following CSS variables in your project's main CSS file (e.g., globals.css).
161
+
162
+ Override the following CSS variables in your project's main CSS file (e.g., globals.css) to match your brand identity.
163
+
65
164
  code
66
165
  CSS
166
+ download
167
+ content_copy
168
+ expand_less
67
169
  :root {
68
- --ai-primary: #007BFF; /* Primary color (e.g., blue) */
69
- --ai-primary-fg: #FFFFFF; /* Text color on primary background (e.g., white) */
170
+ --ai-primary: #007BFF; /* Primary color (e.g., blue) */
171
+ --ai-primary-fg: #FFFFFF; /* Text color on primary background (e.g., white) */
70
172
 
71
- --ai-bg: #FFFFFF; /* Main background of the chat window */
72
- --ai-border: #DDDDDD; /* Border color */
173
+ --ai-bg: #FFFFFF; /* Main background of the chat window */
174
+ --ai-border: #DDDDDD; /* Border color */
73
175
 
74
- --ai-text: #333333; /* Main text color */
75
- --ai-text-secondary: #777777; /* Secondary text color (like placeholders) */
176
+ --ai-text: #333333; /* Main text color */
177
+ --ai-text-secondary: #777777; /* Secondary text color (like placeholders) */
76
178
 
77
- --ai-bot-bg: #F1F1F1; /* Bot message bubble background */
78
- --ai-user-bg: #E1F0FF; /* User message bubble background */
79
- --ai-user-text: #0052D4; /* User message text color */
179
+ --ai-bot-bg: #F1F1F1; /* Bot message bubble background */
180
+ --ai-user-bg: #E1F0FF; /* User message bubble background */
181
+ --ai-user-text: #0052D4; /* User message text color */
80
182
  }
81
183
  <br>
184
+
82
185
  فارسی
186
+
83
187
  یک کامپوننت چت‌بات هوش مصنوعی حرفه‌ای، زیبا و کاملاً آماده برای استفاده در پروژه‌های React شما. این پکیج با ارائه یک رابط کاربری شناور و جذاب، به شما اجازه می‌دهد تا به سادگی یک دستیار هوشمند را به وب‌سایت خود اضافه کنید. این کامپوننت با الهام از زیبایی‌شناسی Tailwind CSS و با استفاده از CSS خالص ساخته شده تا بدون نیاز به هیچ‌گونه تنظیمات اضافی، در هر پروژه‌ای قابل استفاده باشد.
188
+
84
189
  ![alt text](https://your-image-host.com/demo.gif)
85
190
 
86
191
  (توصیه: یک فایل GIF از عملکرد کامپوننت ضبط کرده و این لینک را جایگزین کنید)
192
+
87
193
  ✨ ویژگی‌های کلیدی
194
+
88
195
  نصب و استفاده آسان: فقط پکیج را نصب کرده، فایل CSS را وارد کنید و کامپوننت را در برنامه خود قرار دهید.
196
+
89
197
  رابط کاربری شناور (FAB): یک دکمه شناور با انیمیشن Lottie که پنجره چت را باز و بسته می‌کند و در تمام صفحات در دسترس است.
198
+
90
199
  حالت تمام‌صفحه: با یک کلیک، پنجره چت کل صفحه را می‌پوشاند تا کاربر یک تجربه چت فراگیر داشته باشد.
200
+
91
201
  انیمیشن Lottie قابل شخصی‌سازی: انیمیشن دکمه شناور را به سادگی با انیمیشن Lottie دلخواه خود جایگزین کنید.
202
+
92
203
  ورودی متن داینامیک: textarea با قابلیت افزایش خودکار ارتفاع برای نوشتن پیام‌های چندخطی راحت.
204
+
93
205
  شخصی‌سازی با متغیرهای CSS: رنگ‌ها و ظاهر کامپوننت را به سادگی با override کردن متغیرهای CSS مطابق با برند خود تغییر دهید.
206
+
94
207
  مستقل از Backend: کامپوننت به سادگی به هر API Endpointی که شما مشخص کنید، متصل می‌شود.
208
+
95
209
  🚀 نصب
210
+
96
211
  برای نصب پکیج، از دستور زیر در پروژه خود استفاده کنید:
212
+
97
213
  code
98
214
  Bash
215
+ download
216
+ content_copy
217
+ expand_less
99
218
  npm install mehdi-akbari-ai-assistant-free
219
+
100
220
  یا با استفاده از yarn:
221
+
101
222
  code
102
223
  Bash
224
+ download
225
+ content_copy
226
+ expand_less
103
227
  yarn add mehdi-akbari-ai-assistant-free
104
228
  📋 نحوه استفاده
105
229
  مرحله ۱: وارد کردن استایل‌ها
230
+
106
231
  مهم‌ترین قدم، وارد کردن فایل CSS پکیج در فایل اصلی برنامه شماست. این کار باعث می‌شود تمام استایل‌های لازم در کل پروژه شما در دسترس باشند.
232
+
107
233
  در فایل layout.js/layout.tsx (در Next.js) یا App.js (در Create React App)، خط زیر را اضافه کنید:
234
+
108
235
  code
109
236
  JavaScript
237
+ download
238
+ content_copy
239
+ expand_less
110
240
  import 'mehdi-akbari-ai-assistant-free/styles.css';
111
241
  مرحله ۲: استفاده از کامپوننت
112
- کامپوننت AiAssistant را وارد کرده و آن را در صفحه مورد نظر خود قرار دهید. تنها پراپ ضروری، apiEndpoint است.
242
+
243
+ کامپوننت AiAssistant را وارد کرده و آن را در صفحه مورد نظر خود قرار دهید.
244
+
113
245
  code
114
246
  JavaScript
247
+ download
248
+ content_copy
249
+ expand_less
115
250
  import { AiAssistant } from "mehdi-akbari-ai-assistant-free/react";
116
251
 
117
- export default function HomePage() {
252
+ export default function HomePage() {
118
253
  return (
119
254
  <div>
120
255
  <h1>به وب‌سایت من خوش آمدید</h1>
@@ -122,8 +257,59 @@ export default function HomePage() {
122
257
 
123
258
  <AiAssistant apiEndpoint="/api/chat" />
124
259
  </div>
125
- );
260
+ );
261
+ }
262
+ مرحله ۳: ساخت API Endpoint
263
+
264
+ کامپوننت AiAssistant یک ابزار سمت کاربر (Frontend) است و برای ارتباط امن با سرویس هوش مصنوعی، به یک API در سمت سرور (Backend) نیاز دارد. در اینجا نحوه ساخت اندپوینت /api/chat با استفاده از Next.js App Router توضیح داده شده است.
265
+
266
+ ۱. ایجاد فایل route: در پروژه Next.js خود، یک فایل جدید در مسیر app/api/chat/route.ts (یا .js) ایجاد کنید.
267
+
268
+ ۲. اضافه کردن کد زیر: این کد از کلاس AiRobot که در همین پکیج قرار دارد برای مدیریت منطق سمت سرور استفاده می‌کند.
269
+
270
+ code
271
+ Code
272
+ download
273
+ content_copy
274
+ expand_less
275
+ ```typescript
276
+ // app/api/chat/route.ts
277
+ import { NextResponse } from 'next/server';
278
+ import { AiRobot, Message } from 'mehdi-akbari-ai-assistant-free';
279
+
280
+ export async function POST(req: Request) {
281
+ try {
282
+ const { messages }: { messages: Message[] } = await req.json();
283
+
284
+ if (!messages) {
285
+ return NextResponse.json({ error: 'آرایه پیام‌ها ضروری است' }, { status: 400 });
286
+ }
287
+
288
+ // برای امنیت، کلید API را از متغیرهای محیطی بخوانید
289
+ const apiKey = process.env.GROQ_API_KEY;
290
+ if (!apiKey) {
291
+ return NextResponse.json({ error: 'کلید API برای سرویس هوش مصنوعی تنظیم نشده است' }, { status: 500 });
292
+ }
293
+
294
+ // یک نمونه از ربات را با کلید API خود بسازید
295
+ const robot = new AiRobot({ apiKey });
296
+
297
+ // پاسخ را از هوش مصنوعی دریافت کنید
298
+ const content = await robot.chat(messages);
299
+
300
+ // پاسخ را به کلاینت برگردانید
301
+ return NextResponse.json({ content });
302
+
303
+ } catch (error) {
304
+ console.error('خطا در API Route:', error);
305
+ return NextResponse.json({ error: 'خطایی در سرور رخ داده است' }, { status: 500 });
306
+ }
126
307
  }
308
+ ```
309
+
310
+ ۳. تنظیم متغیرهای محیطی: یک فایل با نام .env.local در ریشه اصلی پروژه خود ایجاد کرده و کلید API سرویس Groq را در آن قرار دهید:
311
+ GROQ_API_KEY="کلید_API_سرویس_GROQ_شما"
312
+
127
313
  ⚙️ پراپ‌ها (API Reference)
128
314
  پراپ نوع ضروری پیش‌فرض توضیحات
129
315
  apiEndpoint string بله - آدرس API Endpoint شما که درخواست‌های چت به آن ارسال می‌شود.
@@ -131,22 +317,29 @@ title string خیر "AI Assistant" عنوانی که در هدر پنجره چت
131
317
  welcomeMessage string خیر "سلام! چطور می‌توانم کمکتان کنم؟" اولین پیامی که ربات پس از باز شدن پنجره نمایش می‌دهد.
132
318
  lottieAnimationData any خیر یک انیمیشن ربات پیش‌فرض داده‌های انیمیشن Lottie. می‌توانید یک URL (رشته) یا یک آبجکت JSON وارد شده به آن بدهید.
133
319
  🎨 شخصی‌سازی (Theming)
320
+
134
321
  شما می‌توانید به راحتی ظاهر کامپوننت را با override کردن متغیرهای CSS زیر در فایل CSS اصلی پروژه خود (مانند globals.css)، شخصی‌سازی کنید.
322
+
135
323
  code
136
324
  CSS
325
+ download
326
+ content_copy
327
+ expand_less
137
328
  :root {
138
- --ai-primary: #007BFF; /* رنگ اصلی (مثلا آبی) */
139
- --ai-primary-fg: #FFFFFF; /* رنگ متن روی رنگ اصلی (مثلا سفید) */
329
+ --ai-primary: #007BFF; /* رنگ اصلی (مثلا آبی) */
330
+ --ai-primary-fg: #FFFFFF; /* رنگ متن روی رنگ اصلی (مثلا سفید) */
140
331
 
141
- --ai-bg: #FFFFFF; /* پس‌زمینه اصلی پنجره چت */
142
- --ai-border: #DDDDDD; /* رنگ حاشیه‌ها */
332
+ --ai-bg: #FFFFFF; /* پس‌زمینه اصلی پنجره چت */
333
+ --ai-border: #DDDDDD; /* رنگ حاشیه‌ها */
143
334
 
144
- --ai-text: #333333; /* رنگ متن اصلی */
145
- --ai-text-secondary: #777777; /* رنگ متن ثانویه (مانند placeholder) */
335
+ --ai-text: #333333; /* رنگ متن اصلی */
336
+ --ai-text-secondary: #777777; /* رنگ متن ثانویه (مانند placeholder) */
146
337
 
147
- --ai-bot-bg: #F1F1F1; /* پس‌زمینه حباب پیام ربات */
148
- --ai-user-bg: #E1F0FF; /* پس‌زمینه حباب پیام کاربر */
149
- --ai-user-text: #0052D4; /* رنگ متن پیام کاربر */
150
- }
151
- 📜 لایسنس
152
- این پروژه تحت لایسنس MIT منتشر شده است. برای اطلاعات بیشتر فایل LICENSE را مطالعه کنید.
338
+ --ai-bot-bg: #F1F1F1; /* پس‌زمینه حباب پیام ربات */
339
+ --ai-user-bg: #E1F0FF; /* پس‌زمینه حباب پیام کاربر */
340
+ --ai-user-text: #0052D4; /* رنگ متن پیام کاربر */
341
+ }```
342
+
343
+ ## 📜 لایسنس
344
+
345
+ این پروژه تحت لایسنس MIT منتشر شده است. برای اطلاعات بیشتر فایل `LICENSE` را مطالعه کنید.
package/dist/react.js CHANGED
@@ -144,7 +144,7 @@ var ChatWindow = ({
144
144
  }) => {
145
145
  const [messages, setMessages] = (0, import_react3.useState)([]);
146
146
  const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
147
- const version = "0.9.6";
147
+ const version = "0.9.8";
148
148
  (0, import_react3.useEffect)(() => {
149
149
  if (welcomeMessage && messages.length === 0) {
150
150
  setMessages([{ role: "assistant", content: welcomeMessage }]);
package/dist/react.mjs CHANGED
@@ -108,7 +108,7 @@ var ChatWindow = ({
108
108
  }) => {
109
109
  const [messages, setMessages] = useState2([]);
110
110
  const [isLoading, setIsLoading] = useState2(false);
111
- const version = "0.9.6";
111
+ const version = "0.9.8";
112
112
  useEffect3(() => {
113
113
  if (welcomeMessage && messages.length === 0) {
114
114
  setMessages([{ role: "assistant", content: welcomeMessage }]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mehdi-akbari-ai-assistant-free",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "Professional AI Chatbot Library with self-contained CSS styles",
5
5
  "homepage": "https://github.com/MehdiAkbariF/mehdi-akbari-ai-assistant-free#readme",
6
6
  "repository": {