dinesh-ai-chat-widget 1.0.14 → 1.0.15

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,10 +1,10 @@
1
1
  # Floating AI Chat Widget
2
2
 
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.
3
+ A floating, customizable chat widget for React and Next.js. Includes demo replies out of the box—just add your API key and backend URL to connect your own AI for real conversations.
4
4
 
5
5
  ## Installation
6
6
 
7
- Install the widget package and its peer dependency:
7
+ Install the package and its peer dependency:
8
8
 
9
9
  ```bash
10
10
  npm install dinesh-ai-chat-widget lucide-react
@@ -12,7 +12,7 @@ npm install dinesh-ai-chat-widget lucide-react
12
12
 
13
13
  ## Basic Usage (Next.js Example)
14
14
 
15
- Place the widget in your `app/layout.tsx`:
15
+ Add the widget to your layout, just before the closing `</body>` tag (e.g., in `app/layout.tsx`):
16
16
 
17
17
  ```tsx
18
18
  import { ChatWidget } from "dinesh-ai-chat-widget";
@@ -27,7 +27,8 @@ export default function RootLayout({
27
27
  <body>
28
28
  {children}
29
29
  <ChatWidget
30
- key="YOUR-API-KEY"
30
+ apiKey="YOUR-API-KEY"
31
+ apiUrl="YOUR-API-URL"
31
32
  title="Support Assistant"
32
33
  subtitle="Online · Ask us anything"
33
34
  primaryColor="#2563eb"
@@ -40,11 +41,21 @@ export default function RootLayout({
40
41
 
41
42
  ## Configuration Options
42
43
 
43
- You can configure the widget with these optional props:
44
+ The widget accepts the following props:
44
45
 
46
+ | Prop | Type | Default | Description |
47
+ |----------------|----------|-----------------|-------------------------------------------------------|
48
+ | `apiKey` | string | — | **Required** to enable the chat widget |
49
+ | `apiUrl` | string | http://localhost:8000 | API endpoint URL for your backend |
50
+ | `title` | string | "AI Assistant" | Widget header title |
51
+ | `subtitle` | string | "Online · Ready to help" | Widget header subtitle |
52
+ | `primaryColor` | string | "#2563eb" | Primary theme color (hex, rgb, etc.) |
53
+
54
+ **Example:**
45
55
  ```tsx
46
56
  <ChatWidget
47
- key="YOUR-API-KEY"
57
+ apiKey="YOUR-API-KEY"
58
+ apiUrl="YOUR-API-URL"
48
59
  title="Support Assistant"
49
60
  subtitle="Online · Ask us anything"
50
61
  primaryColor="#2563eb"
@@ -55,19 +66,24 @@ You can configure the widget with these optional props:
55
66
 
56
67
  ## API Integration
57
68
 
58
- When the user sends a message, the widget issues a `POST` request formatted like this:
69
+ When a user sends a message, the widget makes a `POST` request to your backend like:
59
70
 
60
71
  ```json
61
72
  {
62
- "message": "Hello",
73
+ "title": "Hello",
63
74
  "key": "YOUR-API-KEY"
64
75
  }
65
76
  ```
66
77
 
67
- Your backend should return a JSON response with a reply:
78
+ Your backend should respond with a JSON object containing a reply. Example:
68
79
 
69
80
  ```json
70
81
  {
71
82
  "reply": "Hello! How can I help?"
72
83
  }
73
84
  ```
85
+
86
+ - The widget also accepts `"response"` or `"message"` if `"reply"` is missing.
87
+ - To use demo replies, omit the `apiKey` prop.
88
+
89
+ For more details and advanced integration, please refer to the [documentation](#).
@@ -1,9 +1,9 @@
1
1
  export type ChatWidgetProps = {
2
- key?: string;
2
+ apiKey?: string;
3
3
  apiUrl?: string;
4
4
  title?: string;
5
5
  subtitle?: string;
6
6
  primaryColor?: string;
7
7
  };
8
- export default function ChatWidget({ key, apiUrl, title, subtitle, primaryColor, }: ChatWidgetProps): import('react').JSX.Element;
8
+ export default function ChatWidget({ apiKey, apiUrl, title, subtitle, primaryColor, }: ChatWidgetProps): import('react').JSX.Element | null;
9
9
  //# sourceMappingURL=ChatWidget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChatWidget.d.ts","sourceRoot":"","sources":["../src/ChatWidget.tsx"],"names":[],"mappings":"AAMA,OAAO,eAAe,CAAC;AASvB,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,CAAC,EAAC,MAAM,CAAC;IACZ,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAmCF,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,GAAG,EACH,MAAgC,EAChC,KAAsB,EACtB,QAAmC,EACnC,YAAwB,GACzB,EAAE,eAAe,+BA6LjB"}
1
+ {"version":3,"file":"ChatWidget.d.ts","sourceRoot":"","sources":["../src/ChatWidget.tsx"],"names":[],"mappings":"AAMA,OAAO,eAAe,CAAC;AASvB,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAmCF,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,MAAM,EACN,MAAgC,EAChC,KAAsB,EACtB,QAAmC,EACnC,YAAwB,GACzB,EAAE,eAAe,sCAiMjB"}
package/dist/index.cjs CHANGED
@@ -1,9 +1,3 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let l=require("react"),u=require("react/jsx-runtime");var d=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),f=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),p=e=>{let t=f(e);return t.charAt(0).toUpperCase()+t.slice(1)},m=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),h=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0},g={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},_=(0,l.forwardRef)(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>(0,l.createElement)(`svg`,{ref:c,...g,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:m(`lucide`,i),...!a&&!h(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>(0,l.createElement)(e,t)),...Array.isArray(a)?a:[a]])),v=(e,t)=>{let n=(0,l.forwardRef)(({className:n,...r},i)=>(0,l.createElement)(_,{ref:i,iconNode:t,className:m(`lucide-${d(p(e))}`,`lucide-${e}`,n),...r}));return n.displayName=p(e),n},y=v(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),b=v(`message-circle`,[[`path`,{d:`M7.9 20A9 9 0 1 0 4 16.1L2 22Z`,key:`vv11sd`}]]),x=v(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),S=v(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),C=v(`sparkles`,[[`path`,{d:`M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z`,key:`4pj2yx`}],[`path`,{d:`M20 3v4`,key:`1olli1`}],[`path`,{d:`M22 5h-4`,key:`1gvqau`}],[`path`,{d:`M4 17v2`,key:`vumght`}],[`path`,{d:`M5 18H3`,key:`zchphs`}]]),w=v(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),T=v(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=c(o(((e,t,n)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self).dayjs=r()})(n,(function(){"use strict";var e=1e3,t=6e4,n=36e5,r=`millisecond`,i=`second`,a=`minute`,o=`hour`,s=`day`,c=`week`,l=`month`,u=`quarter`,d=`year`,f=`date`,p=`Invalid Date`,m=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,h=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:`en`,weekdays:`Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday`.split(`_`),months:`January_February_March_April_May_June_July_August_September_October_November_December`.split(`_`),ordinal:function(e){var t=[`th`,`st`,`nd`,`rd`],n=e%100;return`[`+e+(t[(n-20)%10]||t[n]||t[0])+`]`}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:``+Array(t+1-r.length).join(n)+e},v={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?`+`:`-`)+_(r,2,`0`)+`:`+_(i,2,`0`)},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),a=n-i<0,o=t.clone().add(r+(a?-1:1),l);return+(-(r+(n-i)/(a?i-o:o-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:d,w:c,d:s,D:f,h:o,m:a,s:i,ms:r,Q:u}[e]||String(e||``).toLowerCase().replace(/s$/,``)},u:function(e){return e===void 0}},y=`en`,b={};b[y]=g;var x=`$isDayjsObject`,S=function(e){return e instanceof E||!(!e||!e[x])},C=function e(t,n,r){var i;if(!t)return y;if(typeof t==`string`){var a=t.toLowerCase();b[a]&&(i=a),n&&(b[a]=n,i=a);var o=t.split(`-`);if(!i&&o.length>1)return e(o[0])}else{var s=t.name;b[s]=t,i=s}return!r&&i&&(y=i),i||!r&&y},w=function(e,t){if(S(e))return e.clone();var n=typeof t==`object`?t:{};return n.date=e,n.args=arguments,new E(n)},T=v;T.l=C,T.i=S,T.w=function(e,t){return w(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var E=function(){function g(e){this.$L=C(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[x]=!0}var _=g.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(t===null)return new Date(NaN);if(T.u(t))return new Date;if(t instanceof Date)return new Date(t);if(typeof t==`string`&&!/Z$/i.test(t)){var r=t.match(m);if(r){var i=r[2]-1||0,a=(r[7]||`0`).substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return T},_.isValid=function(){return this.$d.toString()!==p},_.isSame=function(e,t){var n=w(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return w(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<w(e)},_.$g=function(e,t,n){return T.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!T.u(t)||t,u=T.p(e),p=function(e,t){var i=T.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(s)},m=function(e,t){return T.w(n.toDate()[e].apply(n.toDate(`s`),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},h=this.$W,g=this.$M,_=this.$D,v=`set`+(this.$u?`UTC`:``);switch(u){case d:return r?p(1,0):p(31,11);case l:return r?p(1,g):p(0,g+1);case c:var y=this.$locale().weekStart||0,b=(h<y?h+7:h)-y;return p(r?_-b:_+(6-b),g);case s:case f:return m(v+`Hours`,0);case o:return m(v+`Minutes`,1);case a:return m(v+`Seconds`,2);case i:return m(v+`Milliseconds`,3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,c=T.p(e),u=`set`+(this.$u?`UTC`:``),p=(n={},n[s]=u+`Date`,n[f]=u+`Date`,n[l]=u+`Month`,n[d]=u+`FullYear`,n[o]=u+`Hours`,n[a]=u+`Minutes`,n[i]=u+`Seconds`,n[r]=u+`Milliseconds`,n)[c],m=c===s?this.$D+(t-this.$W):t;if(c===l||c===d){var h=this.clone().set(f,1);h.$d[p](m),h.init(),this.$d=h.set(f,Math.min(this.$D,h.daysInMonth())).$d}else p&&this.$d[p](m);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[T.p(e)]()},_.add=function(r,u){var f,p=this;r=Number(r);var m=T.p(u),h=function(e){var t=w(p);return T.w(t.date(t.date()+Math.round(e*r)),p)};if(m===l)return this.set(l,this.$M+r);if(m===d)return this.set(d,this.$y+r);if(m===s)return h(1);if(m===c)return h(7);var g=(f={},f[a]=t,f[o]=n,f[i]=e,f)[m]||1,_=this.$d.getTime()+r*g;return T.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||p;var r=e||`YYYY-MM-DDTHH:mm:ssZ`,i=T.z(this),a=this.$H,o=this.$m,s=this.$M,c=n.weekdays,l=n.months,u=n.meridiem,d=function(e,n,i,a){return e&&(e[n]||e(t,r))||i[n].slice(0,a)},f=function(e){return T.s(a%12||12,e,`0`)},m=u||function(e,t,n){var r=e<12?`AM`:`PM`;return n?r.toLowerCase():r};return r.replace(h,(function(e,r){return r||function(e){switch(e){case`YY`:return String(t.$y).slice(-2);case`YYYY`:return T.s(t.$y,4,`0`);case`M`:return s+1;case`MM`:return T.s(s+1,2,`0`);case`MMM`:return d(n.monthsShort,s,l,3);case`MMMM`:return d(l,s);case`D`:return t.$D;case`DD`:return T.s(t.$D,2,`0`);case`d`:return String(t.$W);case`dd`:return d(n.weekdaysMin,t.$W,c,2);case`ddd`:return d(n.weekdaysShort,t.$W,c,3);case`dddd`:return c[t.$W];case`H`:return String(a);case`HH`:return T.s(a,2,`0`);case`h`:return f(1);case`hh`:return f(2);case`a`:return m(a,o,!0);case`A`:return m(a,o,!1);case`m`:return String(o);case`mm`:return T.s(o,2,`0`);case`s`:return String(t.$s);case`ss`:return T.s(t.$s,2,`0`);case`SSS`:return T.s(t.$ms,3,`0`);case`Z`:return i}return null}(e)||i.replace(`:`,``)}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,p){var m,h=this,g=T.p(f),_=w(r),v=(_.utcOffset()-this.utcOffset())*t,y=this-_,b=function(){return T.m(h,_)};switch(g){case d:m=b()/12;break;case l:m=b();break;case u:m=b()/3;break;case c:m=(y-v)/6048e5;break;case s:m=(y-v)/864e5;break;case o:m=y/n;break;case a:m=y/t;break;case i:m=y/e;break;default:m=y}return p?m:T.a(m)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return b[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=C(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return T.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},g}(),D=E.prototype;return w.prototype=D,[[`$ms`,r],[`$s`,i],[`$m`,a],[`$H`,o],[`$W`,s],[`$M`,l],[`$y`,d],[`$D`,f]].forEach((function(e){D[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),w.extend=function(e,t){return e.$i||=(e(t,E,w),!0),w},w.locale=C,w.isDayjs=S,w.unix=function(e){return w(1e3*e)},w.en=b[y],w.Ls=b,w.p={},w}))}))()),D=[`Check vehicle status`,`Schedule maintenance`,`Pricing information`],O=[{id:1,role:`assistant`,text:`Hello! 👋 I'm your AI assistant. How can I help you today?`,time:`Just now`}];function k(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 A({key:e,apiUrl:t=`http://localhost:8000`,title:n=`AI Assistant`,subtitle:r=`Online · Ready to help`,primaryColor:i=`#2563eb`}){console.log(`in`,`dinesh1`);let[a,o]=(0,l.useState)(!1),[s,c]=(0,l.useState)(!1),[d,f]=(0,l.useState)(``),[p,m]=(0,l.useState)(!1),[h,g]=(0,l.useState)(O),_=(0,l.useRef)(null),v=(0,l.useRef)(null),[A,j]=(0,l.useState)(null);(0,l.useEffect)(()=>{_.current?.scrollIntoView({behavior:`smooth`})},[h,p,a,s]),(0,l.useEffect)(()=>{a&&!s&&v.current?.focus()},[a,s]),console.log(t,`dinesh1`);async function M(n=d){let r=n.trim();if(!r||p)return;let i=(0,E.default)().format(`HH:mm`);g(e=>[...e,{id:Date.now(),role:`user`,text:r,time:i}]),f(``),m(!0),j(null);try{let n;if(t){let i;try{i=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:r,key:e})})}catch(e){throw j(`Failed to fetch.
2
-
3
- Possible Reasons:
4
-
5
- - CORS
6
- - Network Failure
7
- - URL scheme must be "http" or "https" for CORS request.`),e}if(!i.ok)throw j(`Failed to fetch.\n\nPossible Reasons:\n\n- CORS\n- Network Failure\n- URL scheme must be "http" or "https" for CORS request.\n\nChat API returned ${i.status}`),Error(`Chat API returned ${i.status}`);let a=await i.json();n=a.reply??a.response??a.message??`I received a response, but it did not include a reply field.`}else await new Promise(e=>setTimeout(e,700)),n=k(r);g(e=>[...e,{id:Date.now()+1,role:`assistant`,text:n,time:(0,E.default)().format(`HH:mm`)}])}catch{g(e=>[...e,{id:Date.now()+1,role:`assistant`,text:A||`Sorry, I couldn't reach the chat service. Please try again.`,time:(0,E.default)().format(`HH:mm`)}])}finally{m(!1)}}return(0,u.jsxs)(`div`,{className:`acw-root`,style:{"--acw-primary":i},children:[a&&(0,u.jsxs)(`section`,{className:`acw-panel ${s?`acw-minimized`:``}`,"aria-label":`AI chat assistant`,children:[(0,u.jsxs)(`header`,{className:`acw-header`,children:[(0,u.jsx)(`div`,{className:`acw-brand-icon`,children:(0,u.jsx)(y,{size:23})}),(0,u.jsxs)(`div`,{className:`acw-heading`,children:[(0,u.jsx)(`h2`,{children:n}),(0,u.jsxs)(`p`,{children:[(0,u.jsx)(`span`,{className:`acw-online-dot`}),r]})]}),(0,u.jsx)(`button`,{className:`acw-header-button`,onClick:()=>c(!s),"aria-label":`Minimize chat`,children:(0,u.jsx)(x,{size:17})}),(0,u.jsx)(`button`,{className:`acw-header-button`,onClick:()=>o(!1),"aria-label":`Close chat`,children:(0,u.jsx)(T,{size:19})})]}),!s&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`div`,{className:`acw-messages`,children:[h.map((e,t)=>(0,u.jsxs)(`div`,{className:`acw-message-row ${e.role===`user`?`acw-user-row`:``}`,children:[e.role===`assistant`&&(0,u.jsx)(`div`,{className:`acw-avatar acw-bot-avatar`,children:(0,u.jsx)(y,{size:17})}),(0,u.jsxs)(`div`,{className:`acw-message-content`,children:[(0,u.jsx)(`div`,{className:`acw-bubble ${e.role===`user`?`acw-user-bubble`:`acw-assistant-bubble`}`,children:e.text.split(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let l=require("react"),u=require("react/jsx-runtime");var d=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),f=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),p=e=>{let t=f(e);return t.charAt(0).toUpperCase()+t.slice(1)},m=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),h=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0},g={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},_=(0,l.forwardRef)(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>(0,l.createElement)(`svg`,{ref:c,...g,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:m(`lucide`,i),...!a&&!h(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>(0,l.createElement)(e,t)),...Array.isArray(a)?a:[a]])),v=(e,t)=>{let n=(0,l.forwardRef)(({className:n,...r},i)=>(0,l.createElement)(_,{ref:i,iconNode:t,className:m(`lucide-${d(p(e))}`,`lucide-${e}`,n),...r}));return n.displayName=p(e),n},y=v(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),b=v(`message-circle`,[[`path`,{d:`M7.9 20A9 9 0 1 0 4 16.1L2 22Z`,key:`vv11sd`}]]),x=v(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),S=v(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),C=v(`sparkles`,[[`path`,{d:`M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z`,key:`4pj2yx`}],[`path`,{d:`M20 3v4`,key:`1olli1`}],[`path`,{d:`M22 5h-4`,key:`1gvqau`}],[`path`,{d:`M4 17v2`,key:`vumght`}],[`path`,{d:`M5 18H3`,key:`zchphs`}]]),w=v(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),T=v(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=c(o(((e,t,n)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self).dayjs=r()})(n,(function(){"use strict";var e=1e3,t=6e4,n=36e5,r=`millisecond`,i=`second`,a=`minute`,o=`hour`,s=`day`,c=`week`,l=`month`,u=`quarter`,d=`year`,f=`date`,p=`Invalid Date`,m=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,h=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:`en`,weekdays:`Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday`.split(`_`),months:`January_February_March_April_May_June_July_August_September_October_November_December`.split(`_`),ordinal:function(e){var t=[`th`,`st`,`nd`,`rd`],n=e%100;return`[`+e+(t[(n-20)%10]||t[n]||t[0])+`]`}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:``+Array(t+1-r.length).join(n)+e},v={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?`+`:`-`)+_(r,2,`0`)+`:`+_(i,2,`0`)},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),a=n-i<0,o=t.clone().add(r+(a?-1:1),l);return+(-(r+(n-i)/(a?i-o:o-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:d,w:c,d:s,D:f,h:o,m:a,s:i,ms:r,Q:u}[e]||String(e||``).toLowerCase().replace(/s$/,``)},u:function(e){return e===void 0}},y=`en`,b={};b[y]=g;var x=`$isDayjsObject`,S=function(e){return e instanceof E||!(!e||!e[x])},C=function e(t,n,r){var i;if(!t)return y;if(typeof t==`string`){var a=t.toLowerCase();b[a]&&(i=a),n&&(b[a]=n,i=a);var o=t.split(`-`);if(!i&&o.length>1)return e(o[0])}else{var s=t.name;b[s]=t,i=s}return!r&&i&&(y=i),i||!r&&y},w=function(e,t){if(S(e))return e.clone();var n=typeof t==`object`?t:{};return n.date=e,n.args=arguments,new E(n)},T=v;T.l=C,T.i=S,T.w=function(e,t){return w(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var E=function(){function g(e){this.$L=C(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[x]=!0}var _=g.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(t===null)return new Date(NaN);if(T.u(t))return new Date;if(t instanceof Date)return new Date(t);if(typeof t==`string`&&!/Z$/i.test(t)){var r=t.match(m);if(r){var i=r[2]-1||0,a=(r[7]||`0`).substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return T},_.isValid=function(){return this.$d.toString()!==p},_.isSame=function(e,t){var n=w(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return w(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<w(e)},_.$g=function(e,t,n){return T.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!T.u(t)||t,u=T.p(e),p=function(e,t){var i=T.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(s)},m=function(e,t){return T.w(n.toDate()[e].apply(n.toDate(`s`),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},h=this.$W,g=this.$M,_=this.$D,v=`set`+(this.$u?`UTC`:``);switch(u){case d:return r?p(1,0):p(31,11);case l:return r?p(1,g):p(0,g+1);case c:var y=this.$locale().weekStart||0,b=(h<y?h+7:h)-y;return p(r?_-b:_+(6-b),g);case s:case f:return m(v+`Hours`,0);case o:return m(v+`Minutes`,1);case a:return m(v+`Seconds`,2);case i:return m(v+`Milliseconds`,3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,c=T.p(e),u=`set`+(this.$u?`UTC`:``),p=(n={},n[s]=u+`Date`,n[f]=u+`Date`,n[l]=u+`Month`,n[d]=u+`FullYear`,n[o]=u+`Hours`,n[a]=u+`Minutes`,n[i]=u+`Seconds`,n[r]=u+`Milliseconds`,n)[c],m=c===s?this.$D+(t-this.$W):t;if(c===l||c===d){var h=this.clone().set(f,1);h.$d[p](m),h.init(),this.$d=h.set(f,Math.min(this.$D,h.daysInMonth())).$d}else p&&this.$d[p](m);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[T.p(e)]()},_.add=function(r,u){var f,p=this;r=Number(r);var m=T.p(u),h=function(e){var t=w(p);return T.w(t.date(t.date()+Math.round(e*r)),p)};if(m===l)return this.set(l,this.$M+r);if(m===d)return this.set(d,this.$y+r);if(m===s)return h(1);if(m===c)return h(7);var g=(f={},f[a]=t,f[o]=n,f[i]=e,f)[m]||1,_=this.$d.getTime()+r*g;return T.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||p;var r=e||`YYYY-MM-DDTHH:mm:ssZ`,i=T.z(this),a=this.$H,o=this.$m,s=this.$M,c=n.weekdays,l=n.months,u=n.meridiem,d=function(e,n,i,a){return e&&(e[n]||e(t,r))||i[n].slice(0,a)},f=function(e){return T.s(a%12||12,e,`0`)},m=u||function(e,t,n){var r=e<12?`AM`:`PM`;return n?r.toLowerCase():r};return r.replace(h,(function(e,r){return r||function(e){switch(e){case`YY`:return String(t.$y).slice(-2);case`YYYY`:return T.s(t.$y,4,`0`);case`M`:return s+1;case`MM`:return T.s(s+1,2,`0`);case`MMM`:return d(n.monthsShort,s,l,3);case`MMMM`:return d(l,s);case`D`:return t.$D;case`DD`:return T.s(t.$D,2,`0`);case`d`:return String(t.$W);case`dd`:return d(n.weekdaysMin,t.$W,c,2);case`ddd`:return d(n.weekdaysShort,t.$W,c,3);case`dddd`:return c[t.$W];case`H`:return String(a);case`HH`:return T.s(a,2,`0`);case`h`:return f(1);case`hh`:return f(2);case`a`:return m(a,o,!0);case`A`:return m(a,o,!1);case`m`:return String(o);case`mm`:return T.s(o,2,`0`);case`s`:return String(t.$s);case`ss`:return T.s(t.$s,2,`0`);case`SSS`:return T.s(t.$ms,3,`0`);case`Z`:return i}return null}(e)||i.replace(`:`,``)}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,p){var m,h=this,g=T.p(f),_=w(r),v=(_.utcOffset()-this.utcOffset())*t,y=this-_,b=function(){return T.m(h,_)};switch(g){case d:m=b()/12;break;case l:m=b();break;case u:m=b()/3;break;case c:m=(y-v)/6048e5;break;case s:m=(y-v)/864e5;break;case o:m=y/n;break;case a:m=y/t;break;case i:m=y/e;break;default:m=y}return p?m:T.a(m)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return b[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=C(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return T.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},g}(),D=E.prototype;return w.prototype=D,[[`$ms`,r],[`$s`,i],[`$m`,a],[`$H`,o],[`$W`,s],[`$M`,l],[`$y`,d],[`$D`,f]].forEach((function(e){D[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),w.extend=function(e,t){return e.$i||=(e(t,E,w),!0),w},w.locale=C,w.isDayjs=S,w.unix=function(e){return w(1e3*e)},w.en=b[y],w.Ls=b,w.p={},w}))}))()),D=[`Check vehicle status`,`Schedule maintenance`,`Pricing information`],O=[{id:1,role:`assistant`,text:`Hello! 👋 I'm your AI assistant. How can I help you today?`,time:`Just now`}];function k(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 A({apiKey:e,apiUrl:t=`http://localhost:8000`,title:n=`AI Assistant`,subtitle:r=`Online · Ready to help`,primaryColor:i=`#2563eb`}){let[a,o]=(0,l.useState)(!1),[s,c]=(0,l.useState)(!1),[d,f]=(0,l.useState)(``),[p,m]=(0,l.useState)(!1),[h,g]=(0,l.useState)(O),_=(0,l.useRef)(null),v=(0,l.useRef)(null),[A,j]=(0,l.useState)(null);if((0,l.useEffect)(()=>{_.current?.scrollIntoView({behavior:`smooth`})},[h,p,a,s]),(0,l.useEffect)(()=>{a&&!s&&v.current?.focus()},[a,s]),console.log(t,e,`dinesh1`),!e)return null;async function M(n=d){let r=n.trim();if(!r||p)return;let i=(0,E.default)().format(`HH:mm`);g(e=>[...e,{id:Date.now(),role:`user`,text:r,time:i}]),f(``),m(!0),j(null);try{let n;if(t){let i;try{i=await fetch(t+`/chats`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r,key:e})})}catch(e){throw j(`Failed to fetch.\n\nPossible Reasons:\n\n- CORS\n- Network Failure\n- URL scheme must be "http" or "https" for CORS request.\n\nError: ${e instanceof Error?e.message:String(e)}`),e}if(!i.ok)throw j(`Failed to fetch.\n\nPossible Reasons:\n\n- CORS\n- Network Failure\n- URL scheme must be "http" or "https" for CORS request.\n\nChat API returned ${i.status}`),Error(`Chat API returned ${i.status}`);let a=await i.json();n=a.reply??a.response??a.message??`I received a response, but it did not include a reply field.`}else await new Promise(e=>setTimeout(e,700)),n=k(r);g(e=>[...e,{id:Date.now()+1,role:`assistant`,text:n,time:(0,E.default)().format(`HH:mm`)}])}catch{g(e=>[...e,{id:Date.now()+1,role:`assistant`,text:A||`Sorry, I couldn't reach the chat service. Please try again.`,time:(0,E.default)().format(`HH:mm`)}])}finally{m(!1)}}return(0,u.jsxs)(`div`,{className:`acw-root`,style:{"--acw-primary":i},children:[a&&(0,u.jsxs)(`section`,{className:`acw-panel ${s?`acw-minimized`:``}`,"aria-label":`AI chat assistant`,children:[(0,u.jsxs)(`header`,{className:`acw-header`,children:[(0,u.jsx)(`div`,{className:`acw-brand-icon`,children:(0,u.jsx)(y,{size:23})}),(0,u.jsxs)(`div`,{className:`acw-heading`,children:[(0,u.jsx)(`h2`,{children:n}),(0,u.jsxs)(`p`,{children:[(0,u.jsx)(`span`,{className:`acw-online-dot`}),r]})]}),(0,u.jsx)(`button`,{className:`acw-header-button`,onClick:()=>c(!s),"aria-label":`Minimize chat`,children:(0,u.jsx)(x,{size:17})}),(0,u.jsx)(`button`,{className:`acw-header-button`,onClick:()=>o(!1),"aria-label":`Close chat`,children:(0,u.jsx)(T,{size:19})})]}),!s&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`div`,{className:`acw-messages`,children:[h.map((e,t)=>(0,u.jsxs)(`div`,{className:`acw-message-row ${e.role===`user`?`acw-user-row`:``}`,children:[e.role===`assistant`&&(0,u.jsx)(`div`,{className:`acw-avatar acw-bot-avatar`,children:(0,u.jsx)(y,{size:17})}),(0,u.jsxs)(`div`,{className:`acw-message-content`,children:[(0,u.jsx)(`div`,{className:`acw-bubble ${e.role===`user`?`acw-user-bubble`:`acw-assistant-bubble`}`,children:e.text.split(`
8
2
  `).map((t,n)=>(0,u.jsxs)(`span`,{children:[t,n<e.text.split(`
9
3
  `).length-1&&(0,u.jsx)(`br`,{})]},n))}),(0,u.jsx)(`span`,{className:`acw-time`,children:e.time})]}),e.role===`user`&&(0,u.jsx)(`div`,{className:`acw-avatar acw-user-avatar`,children:(0,u.jsx)(w,{size:17})})]},e.id)),p&&(0,u.jsxs)(`div`,{className:`acw-message-row`,children:[(0,u.jsx)(`div`,{className:`acw-avatar acw-bot-avatar`,children:(0,u.jsx)(y,{size:17})}),(0,u.jsxs)(`div`,{className:`acw-typing`,"aria-label":`Assistant is typing`,children:[(0,u.jsx)(`span`,{}),(0,u.jsx)(`span`,{}),(0,u.jsx)(`span`,{})]})]}),(0,u.jsx)(`div`,{ref:_})]}),h.length===1&&(0,u.jsxs)(`div`,{className:`acw-suggestions`,children:[(0,u.jsxs)(`p`,{children:[(0,u.jsx)(C,{size:13}),` Suggested questions`]}),(0,u.jsx)(`div`,{className:`acw-suggestion-list`,children:D.map(e=>(0,u.jsx)(`button`,{onClick:()=>void M(e),children:e},e))})]}),(0,u.jsxs)(`form`,{className:`acw-composer`,onSubmit:e=>{e.preventDefault(),M()},children:[(0,u.jsx)(`input`,{ref:v,value:d,onChange:e=>f(e.target.value),placeholder:`Type your message...`,"aria-label":`Type your message`}),(0,u.jsx)(`button`,{type:`submit`,disabled:!d.trim()||p,"aria-label":`Send message`,children:(0,u.jsx)(S,{size:18})})]}),(0,u.jsx)(`p`,{className:`acw-footer`,children:t?`Powered by your AI service`:`Demo mode · Connect your AI API`})]})]}),(0,u.jsxs)(`button`,{className:`acw-launcher`,onClick:()=>{o(!a),c(!1)},"aria-label":a?`Close chat widget`:`Open chat widget`,"aria-expanded":a,children:[!a&&(0,u.jsx)(`span`,{className:`acw-notification-dot`}),a?(0,u.jsx)(T,{size:25}):(0,u.jsx)(b,{size:26})]})]})}exports.ChatWidget=A;
package/dist/index.js CHANGED
@@ -441,10 +441,9 @@ function F(e) {
441
441
  let t = e.toLowerCase();
442
442
  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.`;
443
443
  }
444
- function I({ key: e, apiUrl: t = "http://localhost:8000", title: c = "AI Assistant", subtitle: l = "Online · Ready to help", primaryColor: u = "#2563eb" }) {
445
- console.log("in", "dinesh1");
444
+ function I({ apiKey: e, apiUrl: t = "http://localhost:8000", title: c = "AI Assistant", subtitle: l = "Online · Ready to help", primaryColor: u = "#2563eb" }) {
446
445
  let [d, f] = i(!1), [p, m] = i(!1), [h, g] = i(""), [_, v] = i(!1), [y, b] = i(P), x = r(null), S = r(null), [C, w] = i(null);
447
- n(() => {
446
+ if (n(() => {
448
447
  x.current?.scrollIntoView({ behavior: "smooth" });
449
448
  }, [
450
449
  y,
@@ -453,7 +452,7 @@ function I({ key: e, apiUrl: t = "http://localhost:8000", title: c = "AI Assista
453
452
  p
454
453
  ]), n(() => {
455
454
  d && !p && S.current?.focus();
456
- }, [d, p]), console.log(t, "dinesh1");
455
+ }, [d, p]), console.log(t, e, "dinesh1"), !e) return null;
457
456
  async function I(n = h) {
458
457
  let r = n.trim();
459
458
  if (!r || _) return;
@@ -469,16 +468,16 @@ function I({ key: e, apiUrl: t = "http://localhost:8000", title: c = "AI Assista
469
468
  if (t) {
470
469
  let i;
471
470
  try {
472
- i = await fetch(t, {
471
+ i = await fetch(t + "/chats", {
473
472
  method: "POST",
474
473
  headers: { "Content-Type": "application/json" },
475
474
  body: JSON.stringify({
476
- message: r,
475
+ title: r,
477
476
  key: e
478
477
  })
479
478
  });
480
479
  } catch (e) {
481
- throw w("Failed to fetch.\n\nPossible Reasons:\n\n- CORS\n- Network Failure\n- URL scheme must be \"http\" or \"https\" for CORS request."), e;
480
+ throw w(`Failed to fetch.\n\nPossible Reasons:\n\n- CORS\n- Network Failure\n- URL scheme must be "http" or "https" for CORS request.\n\nError: ${e instanceof Error ? e.message : String(e)}`), e;
482
481
  }
483
482
  if (!i.ok) throw w(`Failed to fetch.\n\nPossible Reasons:\n\n- CORS\n- Network Failure\n- URL scheme must be "http" or "https" for CORS request.\n\nChat API returned ${i.status}`), Error(`Chat API returned ${i.status}`);
484
483
  let a = await i.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinesh-ai-chat-widget",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Reusable floating AI chat widget for React and Next.js",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",