@yassirbenmoussa/aicommerce-sdk 1.8.0 → 1.9.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.
- package/dist/ai-commerce.min.js +390 -78
- package/dist/index.cjs +455 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +455 -55
- package/dist/index.mjs.map +1 -1
- package/dist/widget.min.js +382 -70
- package/dist/widget.min.js.map +1 -1
- package/package.json +1 -1
package/dist/ai-commerce.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var AICommerceSDK=(function(exports){'use strict';/*! AI Commerce SDK v1.0.0 | MIT License | https://aicommerce.dev */
|
|
2
|
-
var
|
|
2
|
+
var B=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var H=(o,r)=>()=>(o&&(r=o(o=0)),r);var G=(o,r)=>{for(var e in r)B(o,e,{get:r[e],enumerable:true});},ue=(o,r,e,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let h of le(r))!pe.call(o,h)&&h!==e&&B(o,h,{get:()=>r[h],enumerable:!(c=me(r,h))||c.enumerable});return o};var j=o=>ue(B({},"__esModule",{value:true}),o);var W={};G(W,{AICommerce:()=>exports.AICommerce,AICommerceError:()=>exports.AICommerceError});exports.AICommerce=void 0;exports.AICommerceError=void 0;var R=H(()=>{exports.AICommerce=class o{constructor(r){this.sessionToken=null;this.products={create:async r=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify(r)}),batchUpsert:async r=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify({products:r})}),list:async r=>{let e=new URLSearchParams;r?.page&&e.set("page",String(r.page)),r?.perPage&&e.set("perPage",String(r.perPage)),r?.search&&e.set("search",r.search),r?.categoryId&&e.set("categoryId",r.categoryId),r?.isActive!==void 0&&e.set("isActive",String(r.isActive));let c=e.toString();return this.request(`/api/v1/products${c?`?${c}`:""}`)},get:async r=>this.request(`/api/v1/products/${r}`),update:async(r,e)=>this.request(`/api/v1/products/${r}`,{method:"PUT",body:JSON.stringify(e)}),delete:async r=>this.request(`/api/v1/products/${r}`,{method:"DELETE"})};if(!r.apiKey)throw new Error("AICommerce: apiKey is required");this.apiKey=r.apiKey,this.storeId=r.storeId,this.baseUrl=this.normalizeUrl(r.baseUrl||this.detectBaseUrl()),this.timeout=r.timeout||3e4;}detectBaseUrl(){if(typeof window<"u"){let r=document.querySelector("script[data-aicommerce-url]");if(r)return r.getAttribute("data-aicommerce-url")||"https://api.aicommerce.dev"}return "https://api.aicommerce.dev"}normalizeUrl(r){return r.replace(/\/$/,"")}async request(r,e={}){let c=`${this.baseUrl}${r}`,h=new AbortController,s=setTimeout(()=>h.abort(),this.timeout);try{let g=await fetch(c,{...e,signal:h.signal,headers:{"Content-Type":"application/json","x-api-key":this.apiKey,...this.storeId&&{"x-store-id":this.storeId},...this.sessionToken&&{"X-Session-Token":this.sessionToken},...e.headers}});if(clearTimeout(s),!g.ok){let L=await g.json().catch(()=>({})),w={code:L.code||"UNKNOWN_ERROR",message:L.message||L.error||`HTTP ${g.status}`,status:g.status};throw new exports.AICommerceError(w.message,w.code,w.status)}return g.json()}catch(g){throw clearTimeout(s),g instanceof exports.AICommerceError?g:g instanceof Error&&g.name==="AbortError"?new exports.AICommerceError("Request timeout","TIMEOUT",408):new exports.AICommerceError(g instanceof Error?g.message:"Unknown error","NETWORK_ERROR",0)}}async chat(r,e){let c=typeof r=="string"?{message:r,context:e,sessionToken:this.sessionToken||void 0}:{...r,sessionToken:r.sessionToken||this.sessionToken||void 0},h=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(c)});return h.sessionToken&&(this.sessionToken=h.sessionToken),h}async chatWithAudio(r,e){let c=await r.arrayBuffer(),s={audioBase64:btoa(new Uint8Array(c).reduce((L,w)=>L+String.fromCharCode(w),"")),audioMimeType:r.type||"audio/webm",context:e,sessionToken:this.sessionToken||void 0},g=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(s)});return g.sessionToken&&(this.sessionToken=g.sessionToken),g}async createSession(){let r=await this.request("/api/v1/chat/session",{method:"POST"});return this.sessionToken=r.session.token,r.session}clearSession(){this.sessionToken=null;}getSessionToken(){return this.sessionToken}setSessionToken(r){this.sessionToken=r;}async upload(r,e){let c=new FormData;c.append("file",r),e?.folder&&c.append("folder",e.folder),e?.productId&&c.append("productId",e.productId),e?.isPrimary&&c.append("isPrimary","true");let h=`${this.baseUrl}/api/v1/upload`,s=await fetch(h,{method:"POST",headers:{"X-API-Key":this.apiKey},body:c});if(!s.ok){let g=await s.json().catch(()=>({}));throw new exports.AICommerceError(g.message||g.error||`HTTP ${s.status}`,g.code||"UPLOAD_ERROR",s.status)}return s.json()}static async quickChat(r){return new o({apiKey:r.apiKey,baseUrl:r.baseUrl}).chat(r.message,r.context)}},exports.AICommerceError=class o extends Error{constructor(r,e,c){super(r),this.name="AICommerceError",this.code=e,this.status=c,Object.setPrototypeOf(this,o.prototype);}};});function ge(o){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);return r?{r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)}:{r:99,g:102,b:241}}function z(o){let r=o.primaryColor,e=ge(r),c=o.position==="bottom-left";return `
|
|
3
3
|
/* AI Commerce Widget Styles */
|
|
4
4
|
#aicommerce-widget {
|
|
5
|
-
--aic-primary: ${
|
|
6
|
-
--aic-primary-rgb: ${
|
|
7
|
-
--aic-primary-light: rgba(${
|
|
8
|
-
--aic-primary-dark: rgba(${
|
|
5
|
+
--aic-primary: ${r};
|
|
6
|
+
--aic-primary-rgb: ${e.r}, ${e.g}, ${e.b};
|
|
7
|
+
--aic-primary-light: rgba(${e.r}, ${e.g}, ${e.b}, 0.1);
|
|
8
|
+
--aic-primary-dark: rgba(${e.r}, ${e.g}, ${e.b}, 0.9);
|
|
9
9
|
--aic-bg: #ffffff;
|
|
10
10
|
--aic-bg-secondary: #f8fafc;
|
|
11
11
|
--aic-text: #1e293b;
|
|
@@ -13,14 +13,14 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
13
13
|
--aic-border: #e2e8f0;
|
|
14
14
|
--aic-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
|
15
15
|
--aic-radius: 16px;
|
|
16
|
-
--aic-z-index: ${
|
|
16
|
+
--aic-z-index: ${o.zIndex};
|
|
17
17
|
|
|
18
18
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
|
19
19
|
font-size: 14px;
|
|
20
20
|
line-height: 1.5;
|
|
21
21
|
position: fixed;
|
|
22
22
|
bottom: 20px;
|
|
23
|
-
${
|
|
23
|
+
${c?"left: 20px;":"right: 20px;"}
|
|
24
24
|
z-index: var(--aic-z-index);
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -74,7 +74,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
74
74
|
.aicommerce-chat {
|
|
75
75
|
position: absolute;
|
|
76
76
|
bottom: 0;
|
|
77
|
-
${
|
|
77
|
+
${c?"left: 0;":"right: 0;"}
|
|
78
78
|
width: 380px;
|
|
79
79
|
max-width: calc(100vw - 40px);
|
|
80
80
|
height: 600px;
|
|
@@ -86,7 +86,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
86
86
|
flex-direction: column;
|
|
87
87
|
overflow: hidden;
|
|
88
88
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
89
|
-
transform-origin: bottom ${
|
|
89
|
+
transform-origin: bottom ${c?"left":"right"};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
.aicommerce-chat.aicommerce-closed {
|
|
@@ -515,7 +515,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
515
515
|
@media (max-width: 420px) {
|
|
516
516
|
#aicommerce-widget {
|
|
517
517
|
bottom: 16px;
|
|
518
|
-
${
|
|
518
|
+
${c?"left: 16px;":"right: 16px;"}
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
.aicommerce-chat {
|
|
@@ -549,17 +549,21 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
549
549
|
}
|
|
550
550
|
|
|
551
551
|
/* ============================================
|
|
552
|
-
Embedded Mode Styles
|
|
552
|
+
Embedded Mode Styles - ChatGPT Style
|
|
553
553
|
============================================ */
|
|
554
554
|
|
|
555
|
-
/* Embedded container -
|
|
555
|
+
/* Embedded container - fit content with max height */
|
|
556
556
|
#aicommerce-widget.aicommerce-embedded {
|
|
557
557
|
position: relative;
|
|
558
558
|
bottom: auto;
|
|
559
559
|
left: auto;
|
|
560
560
|
right: auto;
|
|
561
561
|
width: 100%;
|
|
562
|
-
height:
|
|
562
|
+
height: auto;
|
|
563
|
+
max-height: var(--aic-max-height, 600px);
|
|
564
|
+
display: flex;
|
|
565
|
+
flex-direction: column;
|
|
566
|
+
background: transparent;
|
|
563
567
|
}
|
|
564
568
|
|
|
565
569
|
/* Embedded mode: hide launcher button */
|
|
@@ -567,17 +571,30 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
567
571
|
display: none !important;
|
|
568
572
|
}
|
|
569
573
|
|
|
570
|
-
/* Embedded mode:
|
|
574
|
+
/* Embedded mode: hide the header completely */
|
|
575
|
+
.aicommerce-embedded .aicommerce-header {
|
|
576
|
+
display: none !important;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/* Embedded mode: hide close button */
|
|
580
|
+
.aicommerce-embedded .aicommerce-close {
|
|
581
|
+
display: none !important;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/* Embedded mode: chat fills container with transparent background */
|
|
571
585
|
.aicommerce-embedded .aicommerce-chat {
|
|
572
586
|
position: relative;
|
|
573
587
|
width: 100%;
|
|
574
|
-
height:
|
|
588
|
+
height: auto;
|
|
575
589
|
max-width: 100%;
|
|
576
|
-
|
|
577
|
-
|
|
590
|
+
border-radius: 0;
|
|
591
|
+
background: transparent;
|
|
592
|
+
box-shadow: none;
|
|
578
593
|
transform: none !important;
|
|
579
594
|
opacity: 1 !important;
|
|
580
595
|
pointer-events: auto !important;
|
|
596
|
+
display: flex;
|
|
597
|
+
flex-direction: column;
|
|
581
598
|
}
|
|
582
599
|
|
|
583
600
|
/* Embedded mode: no open/close animations */
|
|
@@ -587,62 +604,324 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
587
604
|
pointer-events: auto !important;
|
|
588
605
|
}
|
|
589
606
|
|
|
590
|
-
/* Embedded mode: messages area
|
|
607
|
+
/* Embedded mode: messages area - messages start from bottom, grow upward */
|
|
591
608
|
.aicommerce-embedded .aicommerce-messages {
|
|
609
|
+
display: flex;
|
|
610
|
+
flex-direction: column;
|
|
611
|
+
justify-content: flex-end;
|
|
612
|
+
overflow-y: auto;
|
|
613
|
+
max-height: calc(var(--aic-max-height, 600px) - 100px);
|
|
614
|
+
padding: 16px;
|
|
615
|
+
max-width: 700px;
|
|
616
|
+
margin: 0 auto;
|
|
617
|
+
width: 100%;
|
|
618
|
+
background: transparent;
|
|
619
|
+
gap: 12px;
|
|
620
|
+
scrollbar-width: thin;
|
|
621
|
+
scrollbar-color: var(--aic-border) transparent;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/* Embedded mode: custom scrollbar for webkit browsers */
|
|
625
|
+
.aicommerce-embedded .aicommerce-messages::-webkit-scrollbar {
|
|
626
|
+
width: 6px;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
.aicommerce-embedded .aicommerce-messages::-webkit-scrollbar-track {
|
|
630
|
+
background: transparent;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
.aicommerce-embedded .aicommerce-messages::-webkit-scrollbar-thumb {
|
|
634
|
+
background-color: var(--aic-border);
|
|
635
|
+
border-radius: 3px;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
.aicommerce-embedded .aicommerce-messages::-webkit-scrollbar-thumb:hover {
|
|
639
|
+
background-color: var(--aic-text-secondary);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/* Embedded mode: messages have different styling */
|
|
643
|
+
.aicommerce-embedded .aicommerce-message {
|
|
644
|
+
max-width: 100%;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.aicommerce-embedded .aicommerce-message-content {
|
|
648
|
+
background: var(--aic-bg);
|
|
649
|
+
border: 1px solid var(--aic-border);
|
|
650
|
+
border-radius: 12px;
|
|
651
|
+
padding: 12px 16px;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
.aicommerce-embedded .aicommerce-user .aicommerce-message-content {
|
|
655
|
+
background: var(--aic-primary);
|
|
656
|
+
color: white;
|
|
657
|
+
border-color: var(--aic-primary);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/* Embedded mode: input container wrapper - always at bottom */
|
|
661
|
+
.aicommerce-embedded .aicommerce-input-wrapper {
|
|
662
|
+
width: 100%;
|
|
663
|
+
display: flex;
|
|
664
|
+
flex-direction: column;
|
|
665
|
+
align-items: center;
|
|
666
|
+
padding: 16px;
|
|
667
|
+
flex-shrink: 0;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/* Embedded mode: input container styled like ChatGPT */
|
|
671
|
+
.aicommerce-embedded .aicommerce-input-container {
|
|
672
|
+
width: 100%;
|
|
673
|
+
max-width: 700px;
|
|
674
|
+
background: var(--aic-bg);
|
|
675
|
+
border: 1px solid var(--aic-border);
|
|
676
|
+
border-radius: 24px;
|
|
677
|
+
padding: 8px 12px;
|
|
678
|
+
display: flex;
|
|
679
|
+
align-items: flex-end;
|
|
680
|
+
gap: 8px;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/* Embedded mode: textarea field styling - auto-grow */
|
|
684
|
+
.aicommerce-embedded .aicommerce-input {
|
|
592
685
|
flex: 1;
|
|
593
|
-
min-
|
|
686
|
+
min-width: 0;
|
|
687
|
+
border: none;
|
|
688
|
+
background: transparent;
|
|
689
|
+
padding: 8px 4px;
|
|
690
|
+
font-size: 16px;
|
|
691
|
+
font-family: inherit;
|
|
692
|
+
color: var(--aic-text);
|
|
693
|
+
outline: none;
|
|
694
|
+
resize: none;
|
|
695
|
+
min-height: 24px;
|
|
696
|
+
max-height: 150px;
|
|
697
|
+
line-height: 1.5;
|
|
698
|
+
overflow-y: auto;
|
|
594
699
|
}
|
|
595
700
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
701
|
+
.aicommerce-embedded .aicommerce-input::placeholder {
|
|
702
|
+
color: var(--aic-text-secondary);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/* Embedded mode: buttons styling - smaller, no overflow */
|
|
706
|
+
.aicommerce-embedded .aicommerce-mic,
|
|
707
|
+
.aicommerce-embedded .aicommerce-send {
|
|
708
|
+
flex-shrink: 0;
|
|
709
|
+
width: 36px;
|
|
710
|
+
height: 36px;
|
|
711
|
+
min-width: 36px;
|
|
712
|
+
border-radius: 50%;
|
|
713
|
+
background: var(--aic-primary);
|
|
714
|
+
color: white;
|
|
715
|
+
border: none;
|
|
716
|
+
display: flex;
|
|
717
|
+
align-items: center;
|
|
718
|
+
justify-content: center;
|
|
719
|
+
cursor: pointer;
|
|
720
|
+
transition: all 0.2s ease;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
.aicommerce-embedded .aicommerce-mic:hover,
|
|
724
|
+
.aicommerce-embedded .aicommerce-send:hover {
|
|
725
|
+
opacity: 0.9;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
.aicommerce-embedded .aicommerce-mic {
|
|
729
|
+
background: transparent;
|
|
730
|
+
color: var(--aic-text-secondary);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
.aicommerce-embedded .aicommerce-mic:hover {
|
|
734
|
+
background: rgba(0, 0, 0, 0.05);
|
|
735
|
+
color: var(--aic-text);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/* Embedded mode: product cards styling */
|
|
739
|
+
.aicommerce-embedded .aicommerce-products {
|
|
740
|
+
display: flex;
|
|
741
|
+
flex-wrap: wrap;
|
|
742
|
+
gap: 12px;
|
|
743
|
+
margin-top: 12px;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
.aicommerce-embedded .aicommerce-product-card {
|
|
747
|
+
background: var(--aic-bg);
|
|
748
|
+
border: 1px solid var(--aic-border);
|
|
749
|
+
border-radius: 12px;
|
|
750
|
+
max-width: 180px;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/* Embedded mode: typing indicator */
|
|
754
|
+
.aicommerce-embedded .aicommerce-typing {
|
|
755
|
+
background: var(--aic-bg);
|
|
756
|
+
border: 1px solid var(--aic-border);
|
|
757
|
+
border-radius: 12px;
|
|
758
|
+
padding: 12px 16px;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/* Embedded mode responsive - mobile fixes */
|
|
762
|
+
@media (max-width: 640px) {
|
|
763
|
+
.aicommerce-embedded .aicommerce-input-container {
|
|
764
|
+
padding: 6px 10px;
|
|
765
|
+
gap: 6px;
|
|
766
|
+
border-radius: 20px;
|
|
600
767
|
}
|
|
601
768
|
|
|
602
|
-
.aicommerce-embedded .aicommerce-
|
|
603
|
-
|
|
769
|
+
.aicommerce-embedded .aicommerce-mic,
|
|
770
|
+
.aicommerce-embedded .aicommerce-send {
|
|
771
|
+
width: 32px;
|
|
772
|
+
height: 32px;
|
|
773
|
+
min-width: 32px;
|
|
604
774
|
}
|
|
775
|
+
|
|
776
|
+
.aicommerce-embedded .aicommerce-mic svg,
|
|
777
|
+
.aicommerce-embedded .aicommerce-send svg {
|
|
778
|
+
width: 16px;
|
|
779
|
+
height: 16px;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
.aicommerce-embedded .aicommerce-input {
|
|
783
|
+
font-size: 16px;
|
|
784
|
+
padding: 6px 4px;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
.aicommerce-embedded .aicommerce-messages {
|
|
788
|
+
padding: 12px;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
.aicommerce-embedded .aicommerce-input-wrapper {
|
|
792
|
+
padding: 12px;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/* ============================================
|
|
797
|
+
Add to Cart Button Styles
|
|
798
|
+
============================================ */
|
|
799
|
+
|
|
800
|
+
.aicommerce-add-to-cart {
|
|
801
|
+
width: 100%;
|
|
802
|
+
padding: 8px 12px;
|
|
803
|
+
background: var(--aic-primary);
|
|
804
|
+
color: white;
|
|
805
|
+
border: none;
|
|
806
|
+
border-radius: 6px;
|
|
807
|
+
font-size: 12px;
|
|
808
|
+
font-weight: 500;
|
|
809
|
+
cursor: pointer;
|
|
810
|
+
margin-top: 8px;
|
|
811
|
+
transition: all 0.2s;
|
|
812
|
+
display: flex;
|
|
813
|
+
align-items: center;
|
|
814
|
+
justify-content: center;
|
|
815
|
+
gap: 6px;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
.aicommerce-add-to-cart:hover {
|
|
819
|
+
opacity: 0.9;
|
|
820
|
+
transform: translateY(-1px);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
.aicommerce-add-to-cart:active {
|
|
824
|
+
transform: translateY(0);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
.aicommerce-add-to-cart:disabled {
|
|
828
|
+
opacity: 0.7;
|
|
829
|
+
cursor: not-allowed;
|
|
830
|
+
transform: none;
|
|
605
831
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
832
|
+
|
|
833
|
+
.aicommerce-add-to-cart svg {
|
|
834
|
+
flex-shrink: 0;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/* Spinner animation for loading state */
|
|
838
|
+
@keyframes aicommerce-spin {
|
|
839
|
+
to { transform: rotate(360deg); }
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
.aicommerce-spinner {
|
|
843
|
+
animation: aicommerce-spin 1s linear infinite;
|
|
844
|
+
}
|
|
845
|
+
`}function _(o){let r=document.createElement("style");r.id="aicommerce-widget-styles",r.textContent=o;let e=document.getElementById("aicommerce-widget-styles");return e&&e.remove(),document.head.appendChild(r),r}var Q=H(()=>{});var Z={};G(Z,{AICommerceWidget:()=>exports.AICommerceWidget,createWidget:()=>D});function D(o){if(!o.apiKey)throw new Error("AICommerceWidget: apiKey is required");let r=new exports.AICommerce({apiKey:o.apiKey,storeId:o.storeId,baseUrl:o.baseUrl}),e={isOpen:false,isLoading:true,isRecording:false,messages:[],storeConfig:null},c=null,h=[],s=null,w=null,m;async function ee(){try{let a=o.baseUrl||N(),i=await fetch(`${a}/api/v1/store`,{headers:{"x-api-key":o.apiKey}});return i.ok?(await i.json()).store:null}catch(a){return console.error("Failed to fetch store config:",a),null}}function N(){if(typeof window<"u"){let a=document.querySelector("script[data-aicommerce-url]");if(a)return a.getAttribute("data-aicommerce-url")||""}return "https://api.aicommerce.dev"}async function re(){e.storeConfig=await ee();let a=o.displayMode||"widget",i=a==="embedded";m={apiKey:o.apiKey,storeId:o.storeId,baseUrl:o.baseUrl||N(),displayMode:a,container:o.container,maxHeight:o.maxHeight||"600px",placeholder:o.placeholder||"Ask me anything about our products...",position:o.position||"bottom-right",theme:o.theme||"auto",primaryColor:o.primaryColor||e.storeConfig?.primaryColor||"#6366f1",welcomeMessage:o.welcomeMessage||e.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:o.botName||e.storeConfig?.chatBotName||"Shopping Assistant",zIndex:o.zIndex||9999,buttonText:o.buttonText||"\u{1F4AC}",hideLauncher:o.hideLauncher||false,addToCartText:o.addToCartText,onOpen:o.onOpen,onClose:o.onClose,onProductClick:o.onProductClick,onAddToCart:o.onAddToCart,onMessage:o.onMessage};let d=z(m);if(w=_(d),i){let b=null;if(typeof o.container=="string"?b=document.querySelector(o.container):o.container instanceof HTMLElement&&(b=o.container),!b){console.error("[AI Commerce] Embedded mode requires a valid container element or selector");return}s=document.createElement("div"),s.id="aicommerce-widget",s.className=`aicommerce-widget aicommerce-embedded aicommerce-theme-${m.theme}`,s.style.setProperty("--aic-max-height",m.maxHeight),b.appendChild(s),e.isOpen=true;}else s=document.createElement("div"),s.id="aicommerce-widget",s.className=`aicommerce-widget aicommerce-${m.position} aicommerce-theme-${m.theme}`,document.body.appendChild(s);k(),i||e.messages.push({role:"assistant",content:m.welcomeMessage}),e.isLoading=false,k();}async function te(a,i=1){if(!(await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a,quantity:i})})).ok)throw new Error("Failed to add to cart");document.dispatchEvent(new CustomEvent("cart:refresh"));}function k(){if(!s)return;let a=m.displayMode==="embedded",i=e.messages.some(l=>l.role==="user");a&&(s.classList.remove("aicommerce-no-messages","aicommerce-has-messages"),s.classList.add(i?"aicommerce-has-messages":"aicommerce-no-messages"));let d=m.placeholder||"Ask me anything about our products...",b=`
|
|
846
|
+
<div class="aicommerce-input-container">
|
|
847
|
+
${a?`
|
|
848
|
+
<textarea
|
|
849
|
+
class="aicommerce-input"
|
|
850
|
+
placeholder="${d}"
|
|
851
|
+
rows="1"
|
|
852
|
+
${e.isLoading||e.isRecording?"disabled":""}
|
|
853
|
+
></textarea>
|
|
854
|
+
`:`
|
|
855
|
+
<input
|
|
856
|
+
type="text"
|
|
857
|
+
class="aicommerce-input"
|
|
858
|
+
placeholder="${d}"
|
|
859
|
+
${e.isLoading||e.isRecording?"disabled":""}
|
|
860
|
+
/>
|
|
861
|
+
`}
|
|
862
|
+
<button class="aicommerce-mic ${e.isRecording?"aicommerce-recording":""}" ${e.isLoading?"disabled":""} aria-label="${e.isRecording?"Stop recording":"Voice input"}">
|
|
863
|
+
${e.isRecording?`
|
|
864
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
|
865
|
+
<rect x="6" y="6" width="12" height="12" rx="2"/>
|
|
866
|
+
</svg>
|
|
867
|
+
`:`
|
|
868
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
869
|
+
<path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>
|
|
870
|
+
<path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
|
|
871
|
+
<line x1="12" y1="19" x2="12" y2="23"/>
|
|
872
|
+
<line x1="8" y1="23" x2="16" y2="23"/>
|
|
873
|
+
</svg>
|
|
874
|
+
`}
|
|
875
|
+
</button>
|
|
876
|
+
<button class="aicommerce-send" ${e.isLoading||e.isRecording?"disabled":""} aria-label="Send message">
|
|
877
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
878
|
+
<path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"/>
|
|
879
|
+
</svg>
|
|
880
|
+
</button>
|
|
881
|
+
</div>
|
|
882
|
+
`,u=`
|
|
883
|
+
${!a&&!m.hideLauncher?`
|
|
884
|
+
<button class="aicommerce-launcher ${e.isOpen?"aicommerce-hidden":""}" aria-label="Open chat">
|
|
885
|
+
<span class="aicommerce-launcher-icon">${m.buttonText}</span>
|
|
610
886
|
</button>
|
|
611
887
|
`:""}
|
|
612
888
|
|
|
613
|
-
<div class="aicommerce-chat ${
|
|
889
|
+
<div class="aicommerce-chat ${e.isOpen?"aicommerce-open":"aicommerce-closed"}">
|
|
890
|
+
${a?"":`
|
|
614
891
|
<div class="aicommerce-header">
|
|
615
892
|
<div class="aicommerce-header-info">
|
|
616
893
|
<div class="aicommerce-avatar">
|
|
617
|
-
${
|
|
894
|
+
${e.storeConfig?.logo?`<img src="${e.storeConfig.logo}" alt="${m.botName}" />`:"<span>\u{1F916}</span>"}
|
|
618
895
|
</div>
|
|
619
896
|
<div class="aicommerce-header-text">
|
|
620
|
-
<span class="aicommerce-bot-name">${
|
|
897
|
+
<span class="aicommerce-bot-name">${m.botName}</span>
|
|
621
898
|
<span class="aicommerce-status">Online</span>
|
|
622
899
|
</div>
|
|
623
900
|
</div>
|
|
624
|
-
|
|
901
|
+
<button class="aicommerce-close" aria-label="Close chat">\u2715</button>
|
|
625
902
|
</div>
|
|
903
|
+
`}
|
|
626
904
|
|
|
905
|
+
${a&&i?`
|
|
627
906
|
<div class="aicommerce-messages">
|
|
628
|
-
${
|
|
629
|
-
<div class="aicommerce-message aicommerce-${
|
|
630
|
-
<div class="aicommerce-message-content ${
|
|
631
|
-
${
|
|
907
|
+
${e.messages.map((l,S)=>{let A=J(l.content),n=l.role==="user";return `
|
|
908
|
+
<div class="aicommerce-message aicommerce-${l.role}">
|
|
909
|
+
<div class="aicommerce-message-content ${A?"aicommerce-rtl":"aicommerce-ltr"}">
|
|
910
|
+
${l.audioUrl?Y(l,S,n):T(l.content)}
|
|
632
911
|
</div>
|
|
633
|
-
${
|
|
912
|
+
${l.products&&l.products.length>0?`
|
|
634
913
|
<div class="aicommerce-products">
|
|
635
|
-
${
|
|
636
|
-
<div class="aicommerce-product-card" data-product-id="${
|
|
637
|
-
${
|
|
638
|
-
<img src="${
|
|
914
|
+
${l.products.map(t=>`
|
|
915
|
+
<div class="aicommerce-product-card" data-product-id="${t.id}">
|
|
916
|
+
${t.image||t.imageUrl?`
|
|
917
|
+
<img src="${t.image||t.imageUrl}" alt="${T(t.name)}" class="aicommerce-product-image" />
|
|
639
918
|
`:`
|
|
640
919
|
<div class="aicommerce-product-placeholder">\u{1F4E6}</div>
|
|
641
920
|
`}
|
|
642
921
|
<div class="aicommerce-product-info">
|
|
643
|
-
<span class="aicommerce-product-name" title="${
|
|
644
|
-
${
|
|
645
|
-
<span class="aicommerce-product-price">${
|
|
922
|
+
<span class="aicommerce-product-name" title="${T(t.name)}">${T(t.name)}</span>
|
|
923
|
+
${t.description?`<p class="aicommerce-product-desc">${T(t.description)}</p>`:""}
|
|
924
|
+
<span class="aicommerce-product-price">${X(t.price,t.currency)}</span>
|
|
646
925
|
</div>
|
|
647
926
|
</div>
|
|
648
927
|
`).join("")}
|
|
@@ -650,7 +929,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
650
929
|
`:""}
|
|
651
930
|
</div>
|
|
652
931
|
`}).join("")}
|
|
653
|
-
${
|
|
932
|
+
${e.isLoading?`
|
|
654
933
|
<div class="aicommerce-message aicommerce-assistant">
|
|
655
934
|
<div class="aicommerce-typing">
|
|
656
935
|
<span></span><span></span><span></span>
|
|
@@ -658,52 +937,85 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
|
|
|
658
937
|
</div>
|
|
659
938
|
`:""}
|
|
660
939
|
</div>
|
|
940
|
+
`:""}
|
|
661
941
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
class="aicommerce-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
942
|
+
${a?"":`
|
|
943
|
+
<div class="aicommerce-messages">
|
|
944
|
+
${e.messages.map((l,S)=>{let A=J(l.content),n=l.role==="user";return `
|
|
945
|
+
<div class="aicommerce-message aicommerce-${l.role}">
|
|
946
|
+
<div class="aicommerce-message-content ${A?"aicommerce-rtl":"aicommerce-ltr"}">
|
|
947
|
+
${l.audioUrl?Y(l,S,n):T(l.content)}
|
|
948
|
+
</div>
|
|
949
|
+
${l.products&&l.products.length>0?`
|
|
950
|
+
<div class="aicommerce-products">
|
|
951
|
+
${l.products.map(t=>`
|
|
952
|
+
<div class="aicommerce-product-card" data-product-id="${t.id}" data-variant-id="${t.variantId||""}">
|
|
953
|
+
${t.image||t.imageUrl?`
|
|
954
|
+
<img src="${t.image||t.imageUrl}" alt="${T(t.name)}" class="aicommerce-product-image" />
|
|
955
|
+
`:`
|
|
956
|
+
<div class="aicommerce-product-placeholder">\u{1F4E6}</div>
|
|
957
|
+
`}
|
|
958
|
+
<div class="aicommerce-product-info">
|
|
959
|
+
<span class="aicommerce-product-name" title="${T(t.name)}">${T(t.name)}</span>
|
|
960
|
+
${t.description?`<p class="aicommerce-product-desc">${T(t.description)}</p>`:""}
|
|
961
|
+
<span class="aicommerce-product-price">${X(t.price,t.currency)}</span>
|
|
962
|
+
<button class="aicommerce-add-to-cart" data-product-id="${t.id}">
|
|
963
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
964
|
+
<circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
|
|
965
|
+
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
|
|
966
|
+
</svg>
|
|
967
|
+
${m.addToCartText||"Add to Cart"}
|
|
968
|
+
</button>
|
|
969
|
+
</div>
|
|
970
|
+
</div>
|
|
971
|
+
`).join("")}
|
|
972
|
+
</div>
|
|
973
|
+
`:""}
|
|
974
|
+
</div>
|
|
975
|
+
`}).join("")}
|
|
976
|
+
${e.isLoading?`
|
|
977
|
+
<div class="aicommerce-message aicommerce-assistant">
|
|
978
|
+
<div class="aicommerce-typing">
|
|
979
|
+
<span></span><span></span><span></span>
|
|
980
|
+
</div>
|
|
981
|
+
</div>
|
|
982
|
+
`:""}
|
|
688
983
|
</div>
|
|
984
|
+
`}
|
|
985
|
+
|
|
986
|
+
${a?`
|
|
987
|
+
<div class="aicommerce-input-wrapper">
|
|
988
|
+
${b}
|
|
989
|
+
</div>
|
|
990
|
+
`:b}
|
|
689
991
|
</div>
|
|
690
|
-
`;
|
|
992
|
+
`;s.innerHTML=u,oe();let E=s.querySelector(".aicommerce-messages");E&&(E.scrollTop=E.scrollHeight);}function Y(a,i,d){return `
|
|
691
993
|
<div class="aicommerce-audio-player" data-message-index="${i}">
|
|
692
994
|
<button class="aicommerce-audio-btn">
|
|
693
995
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
|
|
694
996
|
</button>
|
|
695
997
|
<div class="aicommerce-audio-waveform">
|
|
696
998
|
<div class="aicommerce-waveform-bars">
|
|
697
|
-
${(
|
|
698
|
-
<div class="aicommerce-waveform-bar" style="height: ${
|
|
999
|
+
${(a.waveformBars||Array(40).fill(10)).map(b=>`
|
|
1000
|
+
<div class="aicommerce-waveform-bar" style="height: ${b}%; background-color: ${d?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)"}"></div>
|
|
699
1001
|
`).join("")}
|
|
700
1002
|
</div>
|
|
701
1003
|
<div class="aicommerce-audio-time">
|
|
702
1004
|
<span class="aicommerce-current-time">0:00</span>
|
|
703
|
-
<span>${
|
|
1005
|
+
<span>${V(a.audioDuration||0)}</span>
|
|
704
1006
|
</div>
|
|
705
1007
|
</div>
|
|
706
|
-
<audio src="${
|
|
1008
|
+
<audio src="${a.audioUrl}" preload="metadata"></audio>
|
|
707
1009
|
</div>
|
|
708
|
-
`}function
|
|
1010
|
+
`}function oe(){if(!s)return;let a=s.querySelector(".aicommerce-launcher");a&&a.addEventListener("click",()=>q());let i=s.querySelector(".aicommerce-close");i&&i.addEventListener("click",()=>O());let d=s.querySelector(".aicommerce-input"),b=s.querySelector(".aicommerce-send");d&&(d.addEventListener("keydown",n=>{let t=n;if(t.key==="Enter"){let p=d instanceof HTMLTextAreaElement;if(p&&t.shiftKey)return;n.preventDefault();let f=d.value.trim();f&&(U(f),d.value="",p&&(d.style.height="auto"));}}),d instanceof HTMLTextAreaElement&&d.addEventListener("input",()=>{d.style.height="auto",d.style.height=Math.min(d.scrollHeight,150)+"px";})),b&&d&&b.addEventListener("click",()=>{let n=d.value.trim();n&&(U(n),d.value="",d instanceof HTMLTextAreaElement&&(d.style.height="auto"));});let u=s.querySelector(".aicommerce-mic");u&&u.addEventListener("click",()=>ae()),s.querySelectorAll(".aicommerce-product-card").forEach(n=>{n.addEventListener("click",t=>{if(t.target.closest(".aicommerce-add-to-cart"))return;let p=n.getAttribute("data-product-id"),f=e.messages.flatMap(y=>y.products||[]).find(y=>y.id===p);f&&(m.onProductClick?m.onProductClick(f):f.url&&window.open(f.url,"_blank","noopener,noreferrer"));});}),s.querySelectorAll(".aicommerce-add-to-cart").forEach(n=>{n.addEventListener("click",async t=>{t.stopPropagation();let p=n,f=p.closest(".aicommerce-product-card"),y=f?.getAttribute("data-product-id"),x=f?.getAttribute("data-variant-id"),C=e.messages.flatMap(P=>P.products||[]).find(P=>P.id===y);if(!C)return;let v=p.innerHTML;p.disabled=true,p.innerHTML=`
|
|
1011
|
+
<svg class="aicommerce-spinner" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1012
|
+
<circle cx="12" cy="12" r="10" stroke-dasharray="32" stroke-dashoffset="32"/>
|
|
1013
|
+
</svg>
|
|
1014
|
+
Adding...
|
|
1015
|
+
`;try{m.onAddToCart?await m.onAddToCart(C):x&&window.Shopify?await te(x):C.url&&window.open(C.url,"_blank","noopener,noreferrer"),p.innerHTML=`
|
|
1016
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1017
|
+
<polyline points="20 6 9 17 4 12"/>
|
|
1018
|
+
</svg>
|
|
1019
|
+
Added!
|
|
1020
|
+
`,setTimeout(()=>{p.innerHTML=v,p.disabled=!1;},2e3);}catch(P){console.error("[AI Commerce] Add to cart failed:",P),p.innerHTML=v,p.disabled=false;}});}),s.querySelectorAll(".aicommerce-products").forEach(n=>{let t=false,p=0,f=0;n.addEventListener("mousedown",y=>{t=true,n.style.cursor="grabbing",p=y.pageX-n.offsetLeft,f=n.scrollLeft;}),n.addEventListener("mouseleave",()=>{t=false,n.style.cursor="grab";}),n.addEventListener("mouseup",()=>{t=false,n.style.cursor="grab";}),n.addEventListener("mousemove",y=>{if(!t)return;y.preventDefault();let C=(y.pageX-n.offsetLeft-p)*2;n.scrollLeft=f-C;});}),s.querySelectorAll(".aicommerce-audio-player").forEach(n=>{let t=n.querySelector("audio"),p=n.querySelector(".aicommerce-audio-btn"),f=n.querySelectorAll(".aicommerce-waveform-bar"),y=n.querySelector(".aicommerce-current-time");if(!t||!p)return;p.addEventListener("click",()=>{!t.paused?(t.pause(),p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>'):(s?.querySelectorAll("audio").forEach(v=>{if(v!==t&&!v.paused){v.pause();let M=v.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");M&&(M.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>');}}),t.play(),p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><rect x="6" y="4" width="4" height="16"></rect><rect x="14" y="4" width="4" height="16"></rect></svg>');}),t.addEventListener("timeupdate",()=>{if(y&&(y.textContent=V(t.currentTime)),t.duration){let C=t.currentTime/t.duration*100;f.forEach((v,P)=>{P/f.length*100<=C?v.style.backgroundColor=n.closest(".aicommerce-user")?"rgba(255,255,255,1)":"var(--aic-primary)":v.style.backgroundColor=n.closest(".aicommerce-user")?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)";});}}),t.addEventListener("ended",()=>{p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>';});let x=n.querySelector(".aicommerce-waveform-bars");x&&x.addEventListener("click",C=>{let v=x.getBoundingClientRect(),M=(C.clientX-v.left)/v.width;t.duration&&(t.currentTime=M*t.duration);});});}async function ae(){if(e.isRecording)c&&c.state!=="inactive"&&c.stop();else try{let a=await navigator.mediaDevices.getUserMedia({audio:!0});h=[],c=new MediaRecorder(a,{mimeType:MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4"}),c.ondataavailable=i=>{i.data.size>0&&h.push(i.data);},c.onstop=async()=>{if(a.getTracks().forEach(i=>i.stop()),h.length>0){let i=new Blob(h,{type:c?.mimeType||"audio/webm"});await ie(i);}e.isRecording=!1,k();},c.start(),e.isRecording=!0,k();}catch(a){console.error("Failed to start recording:",a),e.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),k();}}async function ie(a){let i=URL.createObjectURL(a),d=Array(40).fill(10),b=0;try{d=await se(a);let u=new Audio(i);await new Promise(E=>{u.onloadedmetadata=()=>{b=u.duration,E();},u.onerror=()=>E();});}catch(u){console.error("Audio analysis failed",u);}e.messages.push({role:"user",content:"Voice message",audioUrl:i,audioDuration:b,waveformBars:d}),e.isLoading=true,k();try{let u=await r.chatWithAudio(a);return e.messages.push({role:"assistant",content:u.reply,products:u.products}),m.onMessage&&m.onMessage("Voice message",u),u}catch(u){throw e.messages.push({role:"assistant",content:"Sorry, I encountered an error processing your voice message. Please try again."}),u}finally{e.isLoading=false,k();}}function J(a){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(a)}function V(a){let i=Math.floor(a/60),d=Math.floor(a%60);return `${i}:${d.toString().padStart(2,"0")}`}async function se(a){try{let i=new(window.AudioContext||window.webkitAudioContext),d=await a.arrayBuffer(),u=(await i.decodeAudioData(d)).getChannelData(0),E=40,l=Math.floor(u.length/E),S=[];for(let A=0;A<E;A++){let n=A*l,t=n+l,p=0;for(let x=n;x<t;x++)u[x]&&(p+=u[x]*u[x]);let f=Math.sqrt(p/l),y=Math.min(100,Math.max(10,f*400));S.push(y);}return S}catch(i){return console.error("Analysis error",i),Array.from({length:40},()=>20+Math.random()*60)}}async function U(a){e.messages.push({role:"user",content:a}),e.isLoading=true,k();try{let i=await r.chat(a);return e.messages.push({role:"assistant",content:i.reply,products:i.products}),m.onMessage&&m.onMessage(a,i),i}catch(i){throw e.messages.push({role:"assistant",content:"Sorry, I encountered an error. Please try again."}),i}finally{e.isLoading=false,k();}}function q(){e.isOpen=true,k(),m.onOpen?.(),setTimeout(()=>{s?.querySelector(".aicommerce-input")?.focus();},100);}function O(){e.isOpen=false,k(),m.onClose?.();}function ne(){e.isOpen?O():q();}function ce(){s&&(s.remove(),s=null),w&&(w.remove(),w=null);}function de(a){if(Object.assign(m,a),a.primaryColor){let i=z(m);w&&(w.textContent=i);}k();}function T(a){let i=document.createElement("div");return i.textContent=a,i.innerHTML}function X(a,i){let b={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[i||"USD"]||i||"$";return `${a.toFixed(2)} ${b}`}return re(),{open:q,close:O,toggle:ne,destroy:ce,sendMessage:U,updateConfig:de}}exports.AICommerceWidget=void 0;var K=H(()=>{R();Q();exports.AICommerceWidget={init:D,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=exports.AICommerceWidget);});R();K();var xe="1.0.0";typeof window<"u"&&(window.AICommerce=(R(),j(W)).AICommerce,window.AICommerceError=(R(),j(W)).AICommerceError,window.AICommerceWidget=(K(),j(Z)).AICommerceWidget);exports.VERSION=xe;exports.createWidget=D;return exports;})({});//# sourceMappingURL=index.min.js.map
|
|
709
1021
|
//# sourceMappingURL=index.min.js.map
|