dinesh-ai-chat-widget 1.0.7 โ 1.0.9
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 +20 -34
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# Floating AI Chat Widget
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A floating, customizable chat widget for React and Next.js. Demo replies are built-in. Easily connect your own backend API for custom AI-driven conversations.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the widget package and its peer dependency:
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
npm install dinesh-ai-chat-widget lucide-react
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
## Usage
|
|
13
|
+
## Basic Usage (Next.js Example)
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Place the widget in your `app/layout.tsx`:
|
|
14
16
|
|
|
15
17
|
```tsx
|
|
16
18
|
import { ChatWidget } from "dinesh-ai-chat-widget";
|
|
17
|
-
|
|
18
|
-
export default function RootLayout({
|
|
19
|
-
children,
|
|
20
|
-
}: Readonly<{ children: React.ReactNode }>) {
|
|
19
|
+
|
|
20
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
21
21
|
return (
|
|
22
22
|
<html lang="en">
|
|
23
23
|
<body>
|
|
@@ -29,50 +29,36 @@ export default function RootLayout({
|
|
|
29
29
|
}
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Configuration Options
|
|
33
|
+
|
|
34
|
+
You can configure the widget with these optional props:
|
|
33
35
|
|
|
34
36
|
```tsx
|
|
35
37
|
<ChatWidget
|
|
38
|
+
key="YOUR-API-KEY"
|
|
36
39
|
title="Support Assistant"
|
|
37
40
|
subtitle="Online ยท Ask us anything"
|
|
38
41
|
primaryColor="#2563eb"
|
|
39
|
-
projectId="your-public-project-id"
|
|
40
42
|
/>
|
|
41
43
|
```
|
|
42
|
-
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## API Integration
|
|
48
|
+
|
|
49
|
+
When the user sends a message, the widget issues a `POST` request formatted like this:
|
|
45
50
|
|
|
46
51
|
```json
|
|
47
52
|
{
|
|
48
53
|
"message": "Hello",
|
|
49
|
-
"
|
|
54
|
+
"key": "YOUR-API-KEY"
|
|
50
55
|
}
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
Your
|
|
58
|
+
Your backend should return a JSON response with a reply:
|
|
54
59
|
|
|
55
60
|
```json
|
|
56
61
|
{
|
|
57
62
|
"reply": "Hello! How can I help?"
|
|
58
63
|
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
The `projectId` is an identifier, not a secret. Never pass provider API keys to this browser component. Store provider keys securely on your backend and validate allowed websites, authentication, rate limits, and usage there. Configure CORS on your API for the websites that will use the widget.
|
|
62
|
-
|
|
63
|
-
## Build locally
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
npm install
|
|
67
|
-
npm run build
|
|
68
|
-
npm pack
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Publish
|
|
72
|
-
|
|
73
|
-
1. Change `name` in `package.json` to a unique npm package name.
|
|
74
|
-
2. Run `npm login`.
|
|
75
|
-
3. Run `npm publish` (for an unscoped public package).
|
|
76
|
-
4. Install it in your website using `npm install your-package-name`.
|
|
77
|
-
|
|
78
|
-
This starter is a UI package; it does not include a production AI backend or admin dashboard.
|
|
64
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,o,p,m,p),R[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require("react"),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.view_transition`),k=Symbol.for(`react.client.reference`),A=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,j=Object.prototype.hasOwnProperty,M=Array.isArray,N=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var P,F={},I=m.react_stack_bottom_frame.bind(m,o)(),L=N(i(o)),R={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>A.recentlyCreatedOwnerStacks++;if(r){var a=Error.stackTraceLimit;Error.stackTraceLimit=10;var o=Error(`react-stack-top-frame`);Error.stackTraceLimit=a}else o=I;return d(e,t,n,!1,o,r?N(i(e)):L)},e.jsxs=function(e,t,n){var r=1e4>A.recentlyCreatedOwnerStacks++;if(r){var a=Error.stackTraceLimit;Error.stackTraceLimit=10;var o=Error(`react-stack-top-frame`);Error.stackTraceLimit=a}else o=I;return d(e,t,n,!0,o,r?N(i(e)):L)}})()})),O=o(((e,t)=>{t.exports=process.env.NODE_ENV===`production`?E():D()})),k=c(T()),A=O(),j=[`Check vehicle status`,`Schedule maintenance`,`Pricing information`],M=[{id:1,role:`assistant`,text:`Hello! ๐ I'm your AI assistant. How can I help you today?`,time:`Just now`}];function N(e){let t=e.toLowerCase();return t.includes(`vehicle`)||t.includes(`status`)?`I can help check vehicle status. Please provide the vehicle number plate, such as VDR6117.`:t.includes(`maintenance`)||t.includes(`repair`)?`I can help with maintenance! Please describe the vehicle issue, and I'll suggest the next steps.`:t.includes(`price`)||t.includes(`cost`)?`Pricing depends on your requirements. Tell me which service you're interested in, and I'll help estimate the cost.`:t.includes(`hello`)||t.includes(`hi`)?`Hello! ๐ What would you like help with today?`:`Thanks for your message: "${e}". This is a demo response. Configure apiUrl to connect your AI backend.`}function P({key:e,title:t=`AI Assistant`,subtitle:n=`Online ยท Ready to help`,primaryColor:r=`#2563eb`}){let[i,a]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(``),[d,f]=(0,l.useState)(!1),[p,m]=(0,l.useState)(M),h=(0,l.useRef)(null),g=(0,l.useRef)(null),[_,T]=(0,l.useState)(null);(0,l.useEffect)(()=>{h.current?.scrollIntoView({behavior:`smooth`})},[p,d,i,o]),(0,l.useEffect)(()=>{i&&!o&&g.current?.focus()},[i,o]);let E=
|
|
6
|
+
<%s key={someKey} {...props} />`,o,p,m,p),R[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require("react"),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.view_transition`),k=Symbol.for(`react.client.reference`),A=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,j=Object.prototype.hasOwnProperty,M=Array.isArray,N=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var P,F={},I=m.react_stack_bottom_frame.bind(m,o)(),L=N(i(o)),R={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>A.recentlyCreatedOwnerStacks++;if(r){var a=Error.stackTraceLimit;Error.stackTraceLimit=10;var o=Error(`react-stack-top-frame`);Error.stackTraceLimit=a}else o=I;return d(e,t,n,!1,o,r?N(i(e)):L)},e.jsxs=function(e,t,n){var r=1e4>A.recentlyCreatedOwnerStacks++;if(r){var a=Error.stackTraceLimit;Error.stackTraceLimit=10;var o=Error(`react-stack-top-frame`);Error.stackTraceLimit=a}else o=I;return d(e,t,n,!0,o,r?N(i(e)):L)}})()})),O=o(((e,t)=>{t.exports=process.env.NODE_ENV===`production`?E():D()})),k=c(T()),A=O(),j=[`Check vehicle status`,`Schedule maintenance`,`Pricing information`],M=[{id:1,role:`assistant`,text:`Hello! ๐ I'm your AI assistant. How can I help you today?`,time:`Just now`}];function N(e){let t=e.toLowerCase();return t.includes(`vehicle`)||t.includes(`status`)?`I can help check vehicle status. Please provide the vehicle number plate, such as VDR6117.`:t.includes(`maintenance`)||t.includes(`repair`)?`I can help with maintenance! Please describe the vehicle issue, and I'll suggest the next steps.`:t.includes(`price`)||t.includes(`cost`)?`Pricing depends on your requirements. Tell me which service you're interested in, and I'll help estimate the cost.`:t.includes(`hello`)||t.includes(`hi`)?`Hello! ๐ What would you like help with today?`:`Thanks for your message: "${e}". This is a demo response. Configure apiUrl to connect your AI backend.`}function P({key:e,title:t=`AI Assistant`,subtitle:n=`Online ยท Ready to help`,primaryColor:r=`#2563eb`}){let[i,a]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(``),[d,f]=(0,l.useState)(!1),[p,m]=(0,l.useState)(M),h=(0,l.useRef)(null),g=(0,l.useRef)(null),[_,T]=(0,l.useState)(null);(0,l.useEffect)(()=>{h.current?.scrollIntoView({behavior:`smooth`})},[p,d,i,o]),(0,l.useEffect)(()=>{i&&!o&&g.current?.focus()},[i,o]);let E=process.env.NEXT_PUBLIC_API_URL;if(!E||!e)return``;async function D(t=c){let n=t.trim();if(!n||d)return;let r=(0,k.default)().format(`HH:mm`);m(e=>[...e,{id:Date.now(),role:`user`,text:n,time:r}]),u(``),f(!0),T(null);try{let t;if(E){let r;try{r=await fetch(E,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:n,key:e})})}catch(e){throw T(`Failed to fetch.
|
|
7
7
|
|
|
8
8
|
Possible Reasons:
|
|
9
9
|
|
package/dist/index.js
CHANGED
|
@@ -646,7 +646,7 @@ function z({ key: e, title: t = "AI Assistant", subtitle: a = "Online ยท Ready t
|
|
|
646
646
|
]), n(() => {
|
|
647
647
|
s && !l && v.current?.focus();
|
|
648
648
|
}, [s, l]);
|
|
649
|
-
let x =
|
|
649
|
+
let x = process.env.NEXT_PUBLIC_API_URL;
|
|
650
650
|
if (!x || !e) return "";
|
|
651
651
|
async function S(t = d) {
|
|
652
652
|
let n = t.trim();
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dinesh-ai-chat-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Reusable floating AI chat widget for React and Next.js",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"main": "./dist/index.
|
|
7
|
-
"module": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.
|
|
13
|
-
"require": "./dist/index.
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
14
|
},
|
|
15
|
-
"./styles.css": "./dist/
|
|
15
|
+
"./styles.css": "./dist/styles.css"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|