@yassirbenmoussa/aicommerce-sdk 1.1.0 → 1.3.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/index.cjs CHANGED
@@ -33,6 +33,68 @@ var init_client = __esm({
33
33
  exports.AICommerce = class _AICommerce {
34
34
  constructor(config) {
35
35
  this.sessionToken = null;
36
+ // ============================================
37
+ // Products API
38
+ // ============================================
39
+ /**
40
+ * Products API namespace
41
+ */
42
+ this.products = {
43
+ /**
44
+ * Create a new product
45
+ */
46
+ create: async (product) => {
47
+ return this.request("/api/v1/products", {
48
+ method: "POST",
49
+ body: JSON.stringify(product)
50
+ });
51
+ },
52
+ /**
53
+ * Batch upsert products (create or update)
54
+ */
55
+ batchUpsert: async (products) => {
56
+ return this.request("/api/v1/products", {
57
+ method: "POST",
58
+ body: JSON.stringify({ products })
59
+ });
60
+ },
61
+ /**
62
+ * List products with pagination
63
+ */
64
+ list: async (options) => {
65
+ const params = new URLSearchParams();
66
+ if (options?.page) params.set("page", String(options.page));
67
+ if (options?.perPage) params.set("perPage", String(options.perPage));
68
+ if (options?.search) params.set("search", options.search);
69
+ if (options?.categoryId) params.set("categoryId", options.categoryId);
70
+ if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
71
+ const query = params.toString();
72
+ return this.request(`/api/v1/products${query ? `?${query}` : ""}`);
73
+ },
74
+ /**
75
+ * Get a single product by ID
76
+ */
77
+ get: async (productId) => {
78
+ return this.request(`/api/v1/products/${productId}`);
79
+ },
80
+ /**
81
+ * Update a product
82
+ */
83
+ update: async (productId, data) => {
84
+ return this.request(`/api/v1/products/${productId}`, {
85
+ method: "PUT",
86
+ body: JSON.stringify(data)
87
+ });
88
+ },
89
+ /**
90
+ * Delete a product
91
+ */
92
+ delete: async (productId) => {
93
+ return this.request(`/api/v1/products/${productId}`, {
94
+ method: "DELETE"
95
+ });
96
+ }
97
+ };
36
98
  if (!config.apiKey) {
37
99
  throw new Error("AICommerce: apiKey is required");
38
100
  }
@@ -129,6 +191,49 @@ var init_client = __esm({
129
191
  }
130
192
  return response;
131
193
  }
194
+ /**
195
+ * Send an audio message and get product recommendations
196
+ *
197
+ * @param audioBlob - Audio blob (from MediaRecorder or file input)
198
+ * @param context - Optional context for better recommendations
199
+ * @returns Chat response with AI reply and products
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Record audio using MediaRecorder
204
+ * const mediaRecorder = new MediaRecorder(stream);
205
+ * const chunks: Blob[] = [];
206
+ * mediaRecorder.ondataavailable = (e) => chunks.push(e.data);
207
+ * mediaRecorder.onstop = async () => {
208
+ * const audioBlob = new Blob(chunks, { type: 'audio/webm' });
209
+ * const response = await client.chatWithAudio(audioBlob);
210
+ * console.log(response.reply);
211
+ * };
212
+ * ```
213
+ */
214
+ async chatWithAudio(audioBlob, context) {
215
+ const arrayBuffer = await audioBlob.arrayBuffer();
216
+ const base64 = btoa(
217
+ new Uint8Array(arrayBuffer).reduce(
218
+ (data, byte) => data + String.fromCharCode(byte),
219
+ ""
220
+ )
221
+ );
222
+ const request = {
223
+ audioBase64: base64,
224
+ audioMimeType: audioBlob.type || "audio/webm",
225
+ context,
226
+ sessionToken: this.sessionToken || void 0
227
+ };
228
+ const response = await this.request("/api/v1/chat", {
229
+ method: "POST",
230
+ body: JSON.stringify(request)
231
+ });
232
+ if (response.sessionToken) {
233
+ this.sessionToken = response.sessionToken;
234
+ }
235
+ return response;
236
+ }
132
237
  /**
133
238
  * Create a new chat session
134
239
  *
@@ -159,6 +264,47 @@ var init_client = __esm({
159
264
  setSessionToken(token) {
160
265
  this.sessionToken = token;
161
266
  }
267
+ // ============================================
268
+ // Upload API
269
+ // ============================================
270
+ /**
271
+ * Upload an image file
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * // Upload from File input
276
+ * const file = document.querySelector('input[type="file"]').files[0];
277
+ * const result = await client.upload(file);
278
+ * console.log(result.url);
279
+ *
280
+ * // Upload and associate with product
281
+ * const result = await client.upload(file, { productId: 'prod_123', isPrimary: true });
282
+ * ```
283
+ */
284
+ async upload(file, options) {
285
+ const formData = new FormData();
286
+ formData.append("file", file);
287
+ if (options?.folder) formData.append("folder", options.folder);
288
+ if (options?.productId) formData.append("productId", options.productId);
289
+ if (options?.isPrimary) formData.append("isPrimary", "true");
290
+ const url = `${this.baseUrl}/api/v1/upload`;
291
+ const response = await fetch(url, {
292
+ method: "POST",
293
+ headers: {
294
+ "X-API-Key": this.apiKey
295
+ },
296
+ body: formData
297
+ });
298
+ if (!response.ok) {
299
+ const errorData = await response.json().catch(() => ({}));
300
+ throw new exports.AICommerceError(
301
+ errorData.message || errorData.error || `HTTP ${response.status}`,
302
+ errorData.code || "UPLOAD_ERROR",
303
+ response.status
304
+ );
305
+ }
306
+ return response.json();
307
+ }
162
308
  /**
163
309
  * Static method for one-off chat requests
164
310
  *
@@ -190,14 +336,1152 @@ var init_client = __esm({
190
336
  }
191
337
  });
192
338
 
339
+ // src/widget-styles.ts
340
+ function hexToRgb(hex) {
341
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
342
+ return result ? {
343
+ r: parseInt(result[1], 16),
344
+ g: parseInt(result[2], 16),
345
+ b: parseInt(result[3], 16)
346
+ } : { r: 99, g: 102, b: 241 };
347
+ }
348
+ function createWidgetStyles(config) {
349
+ const primary = config.primaryColor;
350
+ const rgb = hexToRgb(primary);
351
+ const isLeft = config.position === "bottom-left";
352
+ return `
353
+ /* AI Commerce Widget Styles */
354
+ #aicommerce-widget {
355
+ --aic-primary: ${primary};
356
+ --aic-primary-rgb: ${rgb.r}, ${rgb.g}, ${rgb.b};
357
+ --aic-primary-light: rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.1);
358
+ --aic-primary-dark: rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.9);
359
+ --aic-bg: #ffffff;
360
+ --aic-bg-secondary: #f8fafc;
361
+ --aic-text: #1e293b;
362
+ --aic-text-secondary: #64748b;
363
+ --aic-border: #e2e8f0;
364
+ --aic-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
365
+ --aic-radius: 16px;
366
+ --aic-z-index: ${config.zIndex};
367
+
368
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
369
+ font-size: 14px;
370
+ line-height: 1.5;
371
+ position: fixed;
372
+ bottom: 20px;
373
+ ${isLeft ? "left: 20px;" : "right: 20px;"}
374
+ z-index: var(--aic-z-index);
375
+ }
376
+
377
+ /* Dark theme */
378
+ #aicommerce-widget.aicommerce-theme-dark,
379
+ @media (prefers-color-scheme: dark) {
380
+ #aicommerce-widget.aicommerce-theme-auto {
381
+ --aic-bg: #1e293b;
382
+ --aic-bg-secondary: #0f172a;
383
+ --aic-text: #f1f5f9;
384
+ --aic-text-secondary: #94a3b8;
385
+ --aic-border: #334155;
386
+ }
387
+ }
388
+
389
+ /* Launcher Button */
390
+ .aicommerce-launcher {
391
+ width: 60px;
392
+ height: 60px;
393
+ border-radius: 50%;
394
+ background: linear-gradient(135deg, var(--aic-primary), var(--aic-primary-dark));
395
+ border: none;
396
+ cursor: pointer;
397
+ box-shadow: 0 4px 20px rgba(var(--aic-primary-rgb), 0.4);
398
+ display: flex;
399
+ align-items: center;
400
+ justify-content: center;
401
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
402
+ animation: aic-pulse 2s infinite;
403
+ }
404
+
405
+ .aicommerce-launcher:hover {
406
+ transform: scale(1.1);
407
+ box-shadow: 0 6px 30px rgba(var(--aic-primary-rgb), 0.5);
408
+ }
409
+
410
+ .aicommerce-launcher-icon {
411
+ font-size: 24px;
412
+ }
413
+
414
+ .aicommerce-hidden {
415
+ display: none !important;
416
+ }
417
+
418
+ @keyframes aic-pulse {
419
+ 0%, 100% { box-shadow: 0 4px 20px rgba(var(--aic-primary-rgb), 0.4); }
420
+ 50% { box-shadow: 0 4px 30px rgba(var(--aic-primary-rgb), 0.6); }
421
+ }
422
+
423
+ /* Chat Window */
424
+ .aicommerce-chat {
425
+ position: absolute;
426
+ bottom: 0;
427
+ ${isLeft ? "left: 0;" : "right: 0;"}
428
+ width: 380px;
429
+ max-width: calc(100vw - 40px);
430
+ height: 600px;
431
+ max-height: calc(100vh - 100px);
432
+ background: var(--aic-bg);
433
+ border-radius: var(--aic-radius);
434
+ box-shadow: var(--aic-shadow);
435
+ display: flex;
436
+ flex-direction: column;
437
+ overflow: hidden;
438
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
439
+ transform-origin: bottom ${isLeft ? "left" : "right"};
440
+ }
441
+
442
+ .aicommerce-chat.aicommerce-closed {
443
+ opacity: 0;
444
+ transform: scale(0.9) translateY(20px);
445
+ pointer-events: none;
446
+ }
447
+
448
+ .aicommerce-chat.aicommerce-open {
449
+ opacity: 1;
450
+ transform: scale(1) translateY(0);
451
+ }
452
+
453
+ /* Header */
454
+ .aicommerce-header {
455
+ background: linear-gradient(135deg, var(--aic-primary), var(--aic-primary-dark));
456
+ color: white;
457
+ padding: 16px 20px;
458
+ display: flex;
459
+ align-items: center;
460
+ justify-content: space-between;
461
+ }
462
+
463
+ .aicommerce-header-info {
464
+ display: flex;
465
+ align-items: center;
466
+ gap: 12px;
467
+ }
468
+
469
+ .aicommerce-avatar {
470
+ width: 40px;
471
+ height: 40px;
472
+ border-radius: 50%;
473
+ background: rgba(255, 255, 255, 0.2);
474
+ display: flex;
475
+ align-items: center;
476
+ justify-content: center;
477
+ font-size: 20px;
478
+ overflow: hidden;
479
+ }
480
+
481
+ .aicommerce-avatar img {
482
+ width: 100%;
483
+ height: 100%;
484
+ object-fit: cover;
485
+ }
486
+
487
+ .aicommerce-header-text {
488
+ display: flex;
489
+ flex-direction: column;
490
+ }
491
+
492
+ .aicommerce-bot-name {
493
+ font-weight: 600;
494
+ font-size: 16px;
495
+ }
496
+
497
+ .aicommerce-status {
498
+ font-size: 12px;
499
+ opacity: 0.9;
500
+ }
501
+
502
+ .aicommerce-close {
503
+ width: 32px;
504
+ height: 32px;
505
+ border-radius: 50%;
506
+ background: rgba(255, 255, 255, 0.2);
507
+ border: none;
508
+ color: white;
509
+ cursor: pointer;
510
+ display: flex;
511
+ align-items: center;
512
+ justify-content: center;
513
+ font-size: 16px;
514
+ transition: background 0.2s;
515
+ }
516
+
517
+ .aicommerce-close:hover {
518
+ background: rgba(255, 255, 255, 0.3);
519
+ }
520
+
521
+ /* Messages */
522
+ .aicommerce-messages {
523
+ flex: 1;
524
+ overflow-y: auto;
525
+ padding: 20px;
526
+ display: flex;
527
+ flex-direction: column;
528
+ gap: 16px;
529
+ background: var(--aic-bg-secondary);
530
+ }
531
+
532
+ .aicommerce-message {
533
+ max-width: 85%;
534
+ animation: aic-slide-in 0.3s ease-out;
535
+ }
536
+
537
+ .aicommerce-message.aicommerce-user {
538
+ align-self: flex-end;
539
+ }
540
+
541
+ .aicommerce-message.aicommerce-assistant {
542
+ align-self: flex-start;
543
+ }
544
+
545
+ .aicommerce-message-content {
546
+ padding: 12px 16px;
547
+ border-radius: 16px;
548
+ line-height: 1.5;
549
+ }
550
+
551
+ .aicommerce-user .aicommerce-message-content {
552
+ background: var(--aic-primary);
553
+ color: white;
554
+ border-bottom-right-radius: 4px;
555
+ }
556
+
557
+ .aicommerce-assistant .aicommerce-message-content {
558
+ background: var(--aic-bg);
559
+ color: var(--aic-text);
560
+ border-bottom-left-radius: 4px;
561
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
562
+ }
563
+
564
+ @keyframes aic-slide-in {
565
+ from { opacity: 0; transform: translateY(10px); }
566
+ to { opacity: 1; transform: translateY(0); }
567
+ }
568
+
569
+ /* Typing Indicator */
570
+ .aicommerce-typing {
571
+ display: flex;
572
+ gap: 4px;
573
+ padding: 12px 16px;
574
+ background: var(--aic-bg);
575
+ border-radius: 16px;
576
+ width: fit-content;
577
+ }
578
+
579
+ .aicommerce-typing span {
580
+ width: 8px;
581
+ height: 8px;
582
+ background: var(--aic-text-secondary);
583
+ border-radius: 50%;
584
+ animation: aic-bounce 1.4s infinite ease-in-out;
585
+ }
586
+
587
+ .aicommerce-typing span:nth-child(1) { animation-delay: -0.32s; }
588
+ .aicommerce-typing span:nth-child(2) { animation-delay: -0.16s; }
589
+
590
+ @keyframes aic-bounce {
591
+ 0%, 80%, 100% { transform: scale(0); }
592
+ 40% { transform: scale(1); }
593
+ }
594
+
595
+ /* Product Cards */
596
+ .aicommerce-products {
597
+ display: flex;
598
+ gap: 16px;
599
+ margin-top: 12px;
600
+ overflow-x: auto;
601
+ padding-bottom: 16px;
602
+ width: 100%;
603
+ max-width: 100%;
604
+ cursor: grab;
605
+ user-select: none;
606
+ -webkit-user-select: none;
607
+ scrollbar-width: none; /* Firefox */
608
+ }
609
+ .aicommerce-products::-webkit-scrollbar {
610
+ display: none; /* Chrome/Safari */
611
+ }
612
+
613
+ .aicommerce-product-card {
614
+ flex-shrink: 0;
615
+ width: 280px;
616
+ background: var(--aic-bg);
617
+ border-radius: 12px;
618
+ overflow: hidden;
619
+ cursor: pointer;
620
+ transition: all 0.2s;
621
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
622
+ }
623
+
624
+ .aicommerce-product-card:hover {
625
+ transform: translateY(-2px);
626
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
627
+ }
628
+
629
+ .aicommerce-product-image {
630
+ width: 100%;
631
+ aspect-ratio: 16/9;
632
+ height: auto;
633
+ object-fit: cover;
634
+ }
635
+
636
+ .aicommerce-product-placeholder {
637
+ width: 100%;
638
+ aspect-ratio: 16/9;
639
+ height: auto;
640
+ background: var(--aic-bg-secondary);
641
+ display: flex;
642
+ align-items: center;
643
+ justify-content: center;
644
+ font-size: 32px;
645
+ }
646
+
647
+ .aicommerce-product-info {
648
+ padding: 10px;
649
+ display: flex;
650
+ flex-direction: column;
651
+ gap: 4px;
652
+ }
653
+
654
+ .aicommerce-product-name {
655
+ font-weight: 500;
656
+ font-size: 13px;
657
+ color: var(--aic-text);
658
+ white-space: nowrap;
659
+ overflow: hidden;
660
+ text-overflow: ellipsis;
661
+ }
662
+
663
+ .aicommerce-product-price {
664
+ font-weight: 600;
665
+ font-size: 14px;
666
+ color: var(--aic-primary);
667
+ }
668
+
669
+ .aicommerce-product-desc {
670
+ font-size: 12px;
671
+ color: var(--aic-text-secondary);
672
+ line-height: 1.4;
673
+ display: -webkit-box;
674
+ -webkit-line-clamp: 2;
675
+ -webkit-box-orient: vertical;
676
+ overflow: hidden;
677
+ margin-top: 4px;
678
+ }
679
+
680
+ /* Audio Player */
681
+ .aicommerce-audio-player {
682
+ display: flex;
683
+ align-items: center;
684
+ gap: 12px;
685
+ min-width: 240px;
686
+ padding: 4px 0;
687
+ }
688
+
689
+ .aicommerce-audio-btn {
690
+ width: 40px;
691
+ height: 40px;
692
+ border-radius: 50%;
693
+ display: flex;
694
+ align-items: center;
695
+ justify-content: center;
696
+ border: none;
697
+ cursor: pointer;
698
+ transition: all 0.2s;
699
+ background: rgba(255, 255, 255, 0.25);
700
+ color: white;
701
+ flex-shrink: 0;
702
+ padding: 0;
703
+ }
704
+
705
+ .aicommerce-audio-btn:hover {
706
+ background: rgba(255, 255, 255, 0.35);
707
+ transform: scale(1.05);
708
+ }
709
+
710
+ .aicommerce-audio-btn:active {
711
+ transform: scale(0.95);
712
+ }
713
+
714
+ /* Invert colors for assistant (since background is white/gray) */
715
+ .aicommerce-assistant .aicommerce-audio-btn {
716
+ background: var(--aic-primary);
717
+ color: white;
718
+ }
719
+ .aicommerce-assistant .aicommerce-audio-btn:hover {
720
+ background: var(--aic-primary-dark);
721
+ }
722
+
723
+ .aicommerce-audio-waveform {
724
+ flex: 1;
725
+ display: flex;
726
+ flex-direction: column;
727
+ gap: 6px;
728
+ min-width: 0; /* Prevent overflow */
729
+ }
730
+
731
+ .aicommerce-waveform-bars {
732
+ display: flex;
733
+ align-items: center;
734
+ gap: 2px;
735
+ height: 24px;
736
+ cursor: pointer;
737
+ width: 100%;
738
+ }
739
+
740
+ .aicommerce-waveform-bar {
741
+ width: 3px;
742
+ border-radius: 2px;
743
+ min-height: 3px;
744
+ transition: background-color 0.1s;
745
+ flex-shrink: 0;
746
+ }
747
+
748
+ .aicommerce-audio-time {
749
+ display: flex;
750
+ justify-content: space-between;
751
+ font-size: 11px;
752
+ font-weight: 500;
753
+ }
754
+
755
+ .aicommerce-user .aicommerce-audio-time {
756
+ color: rgba(255, 255, 255, 0.8);
757
+ }
758
+ .aicommerce-assistant .aicommerce-audio-time {
759
+ color: var(--aic-text-secondary);
760
+ }
761
+
762
+ /* RTL Support */
763
+ .aicommerce-rtl {
764
+ direction: rtl;
765
+ text-align: right;
766
+ }
767
+ .aicommerce-ltr {
768
+ direction: ltr;
769
+ text-align: left;
770
+ }
771
+
772
+ /* Input Area */
773
+ .aicommerce-input-container {
774
+ padding: 16px 20px;
775
+ background: var(--aic-bg);
776
+ border-top: 1px solid var(--aic-border);
777
+ display: flex;
778
+ gap: 12px;
779
+ }
780
+
781
+ .aicommerce-input {
782
+ flex: 1;
783
+ padding: 12px 16px;
784
+ border: 1px solid var(--aic-border);
785
+ border-radius: 24px;
786
+ background: var(--aic-bg-secondary);
787
+ color: var(--aic-text);
788
+ font-size: 14px;
789
+ outline: none;
790
+ transition: all 0.2s;
791
+ }
792
+
793
+ .aicommerce-input:focus {
794
+ border-color: var(--aic-primary);
795
+ box-shadow: 0 0 0 3px var(--aic-primary-light);
796
+ }
797
+
798
+ .aicommerce-input::placeholder {
799
+ color: var(--aic-text-secondary);
800
+ }
801
+
802
+ .aicommerce-send {
803
+ width: 44px;
804
+ height: 44px;
805
+ border-radius: 50%;
806
+ background: var(--aic-primary);
807
+ border: none;
808
+ color: white;
809
+ cursor: pointer;
810
+ display: flex;
811
+ align-items: center;
812
+ justify-content: center;
813
+ transition: all 0.2s;
814
+ }
815
+
816
+ .aicommerce-send:hover:not(:disabled) {
817
+ background: var(--aic-primary-dark);
818
+ transform: scale(1.05);
819
+ }
820
+
821
+ .aicommerce-send:disabled {
822
+ opacity: 0.6;
823
+ cursor: not-allowed;
824
+ }
825
+
826
+ /* Microphone Button */
827
+ .aicommerce-mic {
828
+ width: 44px;
829
+ height: 44px;
830
+ border-radius: 50%;
831
+ background: var(--aic-bg-secondary);
832
+ border: 1px solid var(--aic-border);
833
+ color: var(--aic-text-secondary);
834
+ cursor: pointer;
835
+ display: flex;
836
+ align-items: center;
837
+ justify-content: center;
838
+ transition: all 0.2s;
839
+ }
840
+
841
+ .aicommerce-mic:hover:not(:disabled) {
842
+ background: var(--aic-primary-light);
843
+ border-color: var(--aic-primary);
844
+ color: var(--aic-primary);
845
+ }
846
+
847
+ .aicommerce-mic.aicommerce-recording {
848
+ background: #ef4444;
849
+ border-color: #ef4444;
850
+ color: white;
851
+ animation: aic-recording-pulse 1s infinite;
852
+ }
853
+
854
+ .aicommerce-mic:disabled {
855
+ opacity: 0.6;
856
+ cursor: not-allowed;
857
+ }
858
+
859
+ @keyframes aic-recording-pulse {
860
+ 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
861
+ 50% { transform: scale(1.05); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
862
+ }
863
+
864
+ /* Mobile Responsive */
865
+ @media (max-width: 420px) {
866
+ #aicommerce-widget {
867
+ bottom: 16px;
868
+ ${isLeft ? "left: 16px;" : "right: 16px;"}
869
+ }
870
+
871
+ .aicommerce-chat {
872
+ width: calc(100vw - 32px);
873
+ height: calc(100vh - 100px);
874
+ border-radius: 12px;
875
+ }
876
+
877
+ .aicommerce-launcher {
878
+ width: 56px;
879
+ height: 56px;
880
+ }
881
+ }
882
+
883
+ /* Scrollbar */
884
+ .aicommerce-messages::-webkit-scrollbar {
885
+ width: 6px;
886
+ }
887
+
888
+ .aicommerce-messages::-webkit-scrollbar-track {
889
+ background: transparent;
890
+ }
891
+
892
+ .aicommerce-messages::-webkit-scrollbar-thumb {
893
+ background: var(--aic-border);
894
+ border-radius: 3px;
895
+ }
896
+
897
+ .aicommerce-messages::-webkit-scrollbar-thumb:hover {
898
+ background: var(--aic-text-secondary);
899
+ }
900
+ `;
901
+ }
902
+ function injectStyles(css) {
903
+ const style = document.createElement("style");
904
+ style.id = "aicommerce-widget-styles";
905
+ style.textContent = css;
906
+ const existing = document.getElementById("aicommerce-widget-styles");
907
+ if (existing) {
908
+ existing.remove();
909
+ }
910
+ document.head.appendChild(style);
911
+ return style;
912
+ }
913
+ var init_widget_styles = __esm({
914
+ "src/widget-styles.ts"() {
915
+ }
916
+ });
917
+
918
+ // src/widget.ts
919
+ var widget_exports = {};
920
+ __export(widget_exports, {
921
+ AICommerceWidget: () => exports.AICommerceWidget,
922
+ createWidget: () => createWidget
923
+ });
924
+ function createWidget(config) {
925
+ if (!config.apiKey) {
926
+ throw new Error("AICommerceWidget: apiKey is required");
927
+ }
928
+ const client = new exports.AICommerce({
929
+ apiKey: config.apiKey,
930
+ baseUrl: config.baseUrl
931
+ });
932
+ const state = {
933
+ isOpen: false,
934
+ isLoading: true,
935
+ isRecording: false,
936
+ messages: [],
937
+ storeConfig: null
938
+ };
939
+ let mediaRecorder = null;
940
+ let audioChunks = [];
941
+ let container = null;
942
+ let styleElement = null;
943
+ let resolvedConfig;
944
+ async function fetchStoreConfig() {
945
+ try {
946
+ const baseUrl = config.baseUrl || detectBaseUrl();
947
+ const response = await fetch(`${baseUrl}/api/v1/store`, {
948
+ headers: { "x-api-key": config.apiKey }
949
+ });
950
+ if (!response.ok) return null;
951
+ const data = await response.json();
952
+ return data.store;
953
+ } catch (error) {
954
+ console.error("Failed to fetch store config:", error);
955
+ return null;
956
+ }
957
+ }
958
+ function detectBaseUrl() {
959
+ if (typeof window !== "undefined") {
960
+ const script = document.querySelector("script[data-aicommerce-url]");
961
+ if (script) {
962
+ return script.getAttribute("data-aicommerce-url") || "";
963
+ }
964
+ }
965
+ return "https://api.aicommerce.dev";
966
+ }
967
+ async function initialize() {
968
+ state.storeConfig = await fetchStoreConfig();
969
+ resolvedConfig = {
970
+ apiKey: config.apiKey,
971
+ baseUrl: config.baseUrl || detectBaseUrl(),
972
+ position: config.position || "bottom-right",
973
+ theme: config.theme || "auto",
974
+ primaryColor: config.primaryColor || state.storeConfig?.primaryColor || "#6366f1",
975
+ welcomeMessage: config.welcomeMessage || state.storeConfig?.welcomeMessage || "Hi! How can I help you find the perfect product today?",
976
+ botName: config.botName || state.storeConfig?.chatBotName || "Shopping Assistant",
977
+ zIndex: config.zIndex || 9999,
978
+ buttonText: config.buttonText || "\u{1F4AC}",
979
+ hideLauncher: config.hideLauncher || false,
980
+ onOpen: config.onOpen,
981
+ onClose: config.onClose,
982
+ onProductClick: config.onProductClick,
983
+ onMessage: config.onMessage
984
+ };
985
+ const styles = createWidgetStyles(resolvedConfig);
986
+ styleElement = injectStyles(styles);
987
+ container = document.createElement("div");
988
+ container.id = "aicommerce-widget";
989
+ container.className = `aicommerce-widget aicommerce-${resolvedConfig.position} aicommerce-theme-${resolvedConfig.theme}`;
990
+ document.body.appendChild(container);
991
+ render();
992
+ state.messages.push({
993
+ role: "assistant",
994
+ content: resolvedConfig.welcomeMessage
995
+ });
996
+ state.isLoading = false;
997
+ render();
998
+ }
999
+ function render() {
1000
+ if (!container) return;
1001
+ const html = `
1002
+ ${!resolvedConfig.hideLauncher ? `
1003
+ <button class="aicommerce-launcher ${state.isOpen ? "aicommerce-hidden" : ""}" aria-label="Open chat">
1004
+ <span class="aicommerce-launcher-icon">${resolvedConfig.buttonText}</span>
1005
+ </button>
1006
+ ` : ""}
1007
+
1008
+ <div class="aicommerce-chat ${state.isOpen ? "aicommerce-open" : "aicommerce-closed"}">
1009
+ <div class="aicommerce-header">
1010
+ <div class="aicommerce-header-info">
1011
+ <div class="aicommerce-avatar">
1012
+ ${state.storeConfig?.logo ? `<img src="${state.storeConfig.logo}" alt="${resolvedConfig.botName}" />` : `<span>\u{1F916}</span>`}
1013
+ </div>
1014
+ <div class="aicommerce-header-text">
1015
+ <span class="aicommerce-bot-name">${resolvedConfig.botName}</span>
1016
+ <span class="aicommerce-status">Online</span>
1017
+ </div>
1018
+ </div>
1019
+ <button class="aicommerce-close" aria-label="Close chat">\u2715</button>
1020
+ </div>
1021
+
1022
+ <div class="aicommerce-messages">
1023
+ ${state.messages.map((msg, index) => {
1024
+ const isRtl = isArabic(msg.content);
1025
+ const isUser = msg.role === "user";
1026
+ return `
1027
+ <div class="aicommerce-message aicommerce-${msg.role}">
1028
+ <div class="aicommerce-message-content ${isRtl ? "aicommerce-rtl" : "aicommerce-ltr"}">
1029
+ ${msg.audioUrl ? renderAudioPlayer(msg, index, isUser) : escapeHtml(msg.content)}
1030
+ </div>
1031
+ ${msg.products && msg.products.length > 0 ? `
1032
+ <div class="aicommerce-products">
1033
+ ${msg.products.map((product) => `
1034
+ <div class="aicommerce-product-card" data-product-id="${product.id}">
1035
+ ${product.image || product.imageUrl ? `
1036
+ <img src="${product.image || product.imageUrl}" alt="${escapeHtml(product.name)}" class="aicommerce-product-image" />
1037
+ ` : `
1038
+ <div class="aicommerce-product-placeholder">\u{1F4E6}</div>
1039
+ `}
1040
+ <div class="aicommerce-product-info">
1041
+ <span class="aicommerce-product-name" title="${escapeHtml(product.name)}">${escapeHtml(product.name)}</span>
1042
+ ${product.description ? `<p class="aicommerce-product-desc">${escapeHtml(product.description)}</p>` : ""}
1043
+ <span class="aicommerce-product-price">${formatPrice(product.price, product.currency)}</span>
1044
+ </div>
1045
+ </div>
1046
+ `).join("")}
1047
+ </div>
1048
+ ` : ""}
1049
+ </div>
1050
+ `;
1051
+ }).join("")}
1052
+ ${state.isLoading ? `
1053
+ <div class="aicommerce-message aicommerce-assistant">
1054
+ <div class="aicommerce-typing">
1055
+ <span></span><span></span><span></span>
1056
+ </div>
1057
+ </div>
1058
+ ` : ""}
1059
+ </div>
1060
+
1061
+ <div class="aicommerce-input-container">
1062
+ <input
1063
+ type="text"
1064
+ class="aicommerce-input"
1065
+ placeholder="Type your message..."
1066
+ ${state.isLoading || state.isRecording ? "disabled" : ""}
1067
+ />
1068
+ <button class="aicommerce-mic ${state.isRecording ? "aicommerce-recording" : ""}" ${state.isLoading ? "disabled" : ""} aria-label="${state.isRecording ? "Stop recording" : "Voice input"}">
1069
+ ${state.isRecording ? `
1070
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
1071
+ <rect x="6" y="6" width="12" height="12" rx="2"/>
1072
+ </svg>
1073
+ ` : `
1074
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1075
+ <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>
1076
+ <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
1077
+ <line x1="12" y1="19" x2="12" y2="23"/>
1078
+ <line x1="8" y1="23" x2="16" y2="23"/>
1079
+ </svg>
1080
+ `}
1081
+ </button>
1082
+ <button class="aicommerce-send" ${state.isLoading || state.isRecording ? "disabled" : ""} aria-label="Send message">
1083
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1084
+ <path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"/>
1085
+ </svg>
1086
+ </button>
1087
+ </div>
1088
+ </div>
1089
+ `;
1090
+ container.innerHTML = html;
1091
+ attachEventListeners();
1092
+ const messagesEl = container.querySelector(".aicommerce-messages");
1093
+ if (messagesEl) {
1094
+ messagesEl.scrollTop = messagesEl.scrollHeight;
1095
+ }
1096
+ }
1097
+ function renderAudioPlayer(msg, index, isUser) {
1098
+ return `
1099
+ <div class="aicommerce-audio-player" data-message-index="${index}">
1100
+ <button class="aicommerce-audio-btn">
1101
+ <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>
1102
+ </button>
1103
+ <div class="aicommerce-audio-waveform">
1104
+ <div class="aicommerce-waveform-bars">
1105
+ ${(msg.waveformBars || Array(40).fill(10)).map((height) => `
1106
+ <div class="aicommerce-waveform-bar" style="height: ${height}%; background-color: ${isUser ? "rgba(255,255,255,0.4)" : "rgba(99,102,241,0.3)"}"></div>
1107
+ `).join("")}
1108
+ </div>
1109
+ <div class="aicommerce-audio-time">
1110
+ <span class="aicommerce-current-time">0:00</span>
1111
+ <span>${formatTime(msg.audioDuration || 0)}</span>
1112
+ </div>
1113
+ </div>
1114
+ <audio src="${msg.audioUrl}" preload="metadata"></audio>
1115
+ </div>
1116
+ `;
1117
+ }
1118
+ function attachEventListeners() {
1119
+ if (!container) return;
1120
+ const launcherEl = container.querySelector(".aicommerce-launcher");
1121
+ if (launcherEl) {
1122
+ launcherEl.addEventListener("click", () => open());
1123
+ }
1124
+ const closeEl = container.querySelector(".aicommerce-close");
1125
+ if (closeEl) {
1126
+ closeEl.addEventListener("click", () => close());
1127
+ }
1128
+ const inputEl = container.querySelector(".aicommerce-input");
1129
+ const sendEl = container.querySelector(".aicommerce-send");
1130
+ if (inputEl) {
1131
+ inputEl.addEventListener("keypress", (e) => {
1132
+ if (e.key === "Enter" && inputEl.value.trim()) {
1133
+ handleSend(inputEl.value.trim());
1134
+ inputEl.value = "";
1135
+ }
1136
+ });
1137
+ }
1138
+ if (sendEl && inputEl) {
1139
+ sendEl.addEventListener("click", () => {
1140
+ if (inputEl.value.trim()) {
1141
+ handleSend(inputEl.value.trim());
1142
+ inputEl.value = "";
1143
+ }
1144
+ });
1145
+ }
1146
+ const micEl = container.querySelector(".aicommerce-mic");
1147
+ if (micEl) {
1148
+ micEl.addEventListener("click", () => handleMicClick());
1149
+ }
1150
+ const productCards = container.querySelectorAll(".aicommerce-product-card");
1151
+ productCards.forEach((card) => {
1152
+ card.addEventListener("click", () => {
1153
+ const productId = card.getAttribute("data-product-id");
1154
+ const product = state.messages.flatMap((m) => m.products || []).find((p) => p.id === productId);
1155
+ if (product && resolvedConfig.onProductClick) {
1156
+ resolvedConfig.onProductClick(product);
1157
+ }
1158
+ });
1159
+ });
1160
+ const sliders = container.querySelectorAll(".aicommerce-products");
1161
+ sliders.forEach((slider) => {
1162
+ let isDown = false;
1163
+ let startX = 0;
1164
+ let scrollLeft = 0;
1165
+ slider.addEventListener("mousedown", (e) => {
1166
+ isDown = true;
1167
+ slider.style.cursor = "grabbing";
1168
+ startX = e.pageX - slider.offsetLeft;
1169
+ scrollLeft = slider.scrollLeft;
1170
+ });
1171
+ slider.addEventListener("mouseleave", () => {
1172
+ isDown = false;
1173
+ slider.style.cursor = "grab";
1174
+ });
1175
+ slider.addEventListener("mouseup", () => {
1176
+ isDown = false;
1177
+ slider.style.cursor = "grab";
1178
+ });
1179
+ slider.addEventListener("mousemove", (e) => {
1180
+ if (!isDown) return;
1181
+ e.preventDefault();
1182
+ const x = e.pageX - slider.offsetLeft;
1183
+ const walk = (x - startX) * 2;
1184
+ slider.scrollLeft = scrollLeft - walk;
1185
+ });
1186
+ });
1187
+ const audioPlayers = container.querySelectorAll(".aicommerce-audio-player");
1188
+ audioPlayers.forEach((player) => {
1189
+ const audio = player.querySelector("audio");
1190
+ const btn = player.querySelector(".aicommerce-audio-btn");
1191
+ const bars = player.querySelectorAll(".aicommerce-waveform-bar");
1192
+ const timeDisplay = player.querySelector(".aicommerce-current-time");
1193
+ if (!audio || !btn) return;
1194
+ btn.addEventListener("click", () => {
1195
+ const isPlaying = !audio.paused;
1196
+ if (!isPlaying) {
1197
+ container?.querySelectorAll("audio").forEach((a) => {
1198
+ if (a !== audio && !a.paused) {
1199
+ a.pause();
1200
+ const parent = a.closest(".aicommerce-audio-player");
1201
+ const otherBtn = parent?.querySelector(".aicommerce-audio-btn");
1202
+ if (otherBtn) otherBtn.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>`;
1203
+ }
1204
+ });
1205
+ audio.play();
1206
+ btn.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>`;
1207
+ } else {
1208
+ audio.pause();
1209
+ btn.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>`;
1210
+ }
1211
+ });
1212
+ audio.addEventListener("timeupdate", () => {
1213
+ if (timeDisplay) timeDisplay.textContent = formatTime(audio.currentTime);
1214
+ if (audio.duration) {
1215
+ const progress = audio.currentTime / audio.duration * 100;
1216
+ bars.forEach((bar, i) => {
1217
+ const barPos = i / bars.length * 100;
1218
+ if (barPos <= progress) {
1219
+ bar.style.backgroundColor = player.closest(".aicommerce-user") ? "rgba(255,255,255,1)" : "var(--aic-primary)";
1220
+ } else {
1221
+ bar.style.backgroundColor = player.closest(".aicommerce-user") ? "rgba(255,255,255,0.4)" : "rgba(99,102,241,0.3)";
1222
+ }
1223
+ });
1224
+ }
1225
+ });
1226
+ audio.addEventListener("ended", () => {
1227
+ btn.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>`;
1228
+ });
1229
+ const waveform = player.querySelector(".aicommerce-waveform-bars");
1230
+ if (waveform) {
1231
+ waveform.addEventListener("click", (e) => {
1232
+ const rect = waveform.getBoundingClientRect();
1233
+ const x = e.clientX - rect.left;
1234
+ const percent = x / rect.width;
1235
+ if (audio.duration) {
1236
+ audio.currentTime = percent * audio.duration;
1237
+ }
1238
+ });
1239
+ }
1240
+ });
1241
+ }
1242
+ async function handleMicClick() {
1243
+ if (state.isRecording) {
1244
+ if (mediaRecorder && mediaRecorder.state !== "inactive") {
1245
+ mediaRecorder.stop();
1246
+ }
1247
+ } else {
1248
+ try {
1249
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
1250
+ audioChunks = [];
1251
+ mediaRecorder = new MediaRecorder(stream, {
1252
+ mimeType: MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/mp4"
1253
+ });
1254
+ mediaRecorder.ondataavailable = (e) => {
1255
+ if (e.data.size > 0) {
1256
+ audioChunks.push(e.data);
1257
+ }
1258
+ };
1259
+ mediaRecorder.onstop = async () => {
1260
+ stream.getTracks().forEach((track) => track.stop());
1261
+ if (audioChunks.length > 0) {
1262
+ const audioBlob = new Blob(audioChunks, { type: mediaRecorder?.mimeType || "audio/webm" });
1263
+ await handleAudioSend(audioBlob);
1264
+ }
1265
+ state.isRecording = false;
1266
+ render();
1267
+ };
1268
+ mediaRecorder.start();
1269
+ state.isRecording = true;
1270
+ render();
1271
+ } catch (error) {
1272
+ console.error("Failed to start recording:", error);
1273
+ state.messages.push({
1274
+ role: "assistant",
1275
+ content: "Unable to access microphone. Please check your permissions."
1276
+ });
1277
+ render();
1278
+ }
1279
+ }
1280
+ }
1281
+ async function handleAudioSend(audioBlob) {
1282
+ const audioUrl = URL.createObjectURL(audioBlob);
1283
+ let waveformBars = Array(40).fill(10);
1284
+ let audioDuration = 0;
1285
+ try {
1286
+ waveformBars = await analyzeAudio(audioBlob);
1287
+ const audio = new Audio(audioUrl);
1288
+ await new Promise((resolve) => {
1289
+ audio.onloadedmetadata = () => {
1290
+ audioDuration = audio.duration;
1291
+ resolve();
1292
+ };
1293
+ audio.onerror = () => resolve();
1294
+ });
1295
+ } catch (e) {
1296
+ console.error("Audio analysis failed", e);
1297
+ }
1298
+ state.messages.push({
1299
+ role: "user",
1300
+ content: "Voice message",
1301
+ audioUrl,
1302
+ audioDuration,
1303
+ waveformBars
1304
+ });
1305
+ state.isLoading = true;
1306
+ render();
1307
+ try {
1308
+ const response = await client.chatWithAudio(audioBlob);
1309
+ state.messages.push({
1310
+ role: "assistant",
1311
+ content: response.reply,
1312
+ products: response.products
1313
+ });
1314
+ if (resolvedConfig.onMessage) {
1315
+ resolvedConfig.onMessage("Voice message", response);
1316
+ }
1317
+ return response;
1318
+ } catch (error) {
1319
+ state.messages.push({
1320
+ role: "assistant",
1321
+ content: "Sorry, I encountered an error processing your voice message. Please try again."
1322
+ });
1323
+ throw error;
1324
+ } finally {
1325
+ state.isLoading = false;
1326
+ render();
1327
+ }
1328
+ }
1329
+ function isArabic(text) {
1330
+ return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(text);
1331
+ }
1332
+ function formatTime(seconds) {
1333
+ const mins = Math.floor(seconds / 60);
1334
+ const secs = Math.floor(seconds % 60);
1335
+ return `${mins}:${secs.toString().padStart(2, "0")}`;
1336
+ }
1337
+ async function analyzeAudio(blob) {
1338
+ try {
1339
+ const audioContext = new (window.AudioContext || window.webkitAudioContext)();
1340
+ const arrayBuffer = await blob.arrayBuffer();
1341
+ const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
1342
+ const channelData = audioBuffer.getChannelData(0);
1343
+ const bars = 40;
1344
+ const step = Math.floor(channelData.length / bars);
1345
+ const calculatedBars = [];
1346
+ for (let i = 0; i < bars; i++) {
1347
+ const start = i * step;
1348
+ const end = start + step;
1349
+ let sum = 0;
1350
+ for (let j = start; j < end; j++) {
1351
+ if (channelData[j]) sum += channelData[j] * channelData[j];
1352
+ }
1353
+ const rms = Math.sqrt(sum / step);
1354
+ const height = Math.min(100, Math.max(10, rms * 400));
1355
+ calculatedBars.push(height);
1356
+ }
1357
+ return calculatedBars;
1358
+ } catch (e) {
1359
+ console.error("Analysis error", e);
1360
+ return Array.from({ length: 40 }, () => 20 + Math.random() * 60);
1361
+ }
1362
+ }
1363
+ async function handleSend(message) {
1364
+ state.messages.push({ role: "user", content: message });
1365
+ state.isLoading = true;
1366
+ render();
1367
+ try {
1368
+ const response = await client.chat(message);
1369
+ state.messages.push({
1370
+ role: "assistant",
1371
+ content: response.reply,
1372
+ products: response.products
1373
+ });
1374
+ if (resolvedConfig.onMessage) {
1375
+ resolvedConfig.onMessage(message, response);
1376
+ }
1377
+ return response;
1378
+ } catch (error) {
1379
+ state.messages.push({
1380
+ role: "assistant",
1381
+ content: "Sorry, I encountered an error. Please try again."
1382
+ });
1383
+ throw error;
1384
+ } finally {
1385
+ state.isLoading = false;
1386
+ render();
1387
+ }
1388
+ }
1389
+ function open() {
1390
+ state.isOpen = true;
1391
+ render();
1392
+ resolvedConfig.onOpen?.();
1393
+ setTimeout(() => {
1394
+ const input = container?.querySelector(".aicommerce-input");
1395
+ input?.focus();
1396
+ }, 100);
1397
+ }
1398
+ function close() {
1399
+ state.isOpen = false;
1400
+ render();
1401
+ resolvedConfig.onClose?.();
1402
+ }
1403
+ function toggle() {
1404
+ if (state.isOpen) {
1405
+ close();
1406
+ } else {
1407
+ open();
1408
+ }
1409
+ }
1410
+ function destroy() {
1411
+ if (container) {
1412
+ container.remove();
1413
+ container = null;
1414
+ }
1415
+ if (styleElement) {
1416
+ styleElement.remove();
1417
+ styleElement = null;
1418
+ }
1419
+ }
1420
+ function updateConfig(newConfig) {
1421
+ Object.assign(resolvedConfig, newConfig);
1422
+ if (newConfig.primaryColor) {
1423
+ const styles = createWidgetStyles(resolvedConfig);
1424
+ if (styleElement) {
1425
+ styleElement.textContent = styles;
1426
+ }
1427
+ }
1428
+ render();
1429
+ }
1430
+ function escapeHtml(text) {
1431
+ const div = document.createElement("div");
1432
+ div.textContent = text;
1433
+ return div.innerHTML;
1434
+ }
1435
+ function formatPrice(price, currency) {
1436
+ const symbols = {
1437
+ USD: "$",
1438
+ EUR: "\u20AC",
1439
+ GBP: "\xA3",
1440
+ MAD: "DH",
1441
+ SAR: "SAR",
1442
+ AED: "AED",
1443
+ JPY: "\xA5",
1444
+ CNY: "\xA5"
1445
+ };
1446
+ const symbol = symbols[currency || "USD"] || currency || "$";
1447
+ return `${price.toFixed(2)} ${symbol}`;
1448
+ }
1449
+ initialize();
1450
+ return {
1451
+ open,
1452
+ close,
1453
+ toggle,
1454
+ destroy,
1455
+ sendMessage: handleSend,
1456
+ updateConfig
1457
+ };
1458
+ }
1459
+ exports.AICommerceWidget = void 0;
1460
+ var init_widget = __esm({
1461
+ "src/widget.ts"() {
1462
+ init_client();
1463
+ init_widget_styles();
1464
+ exports.AICommerceWidget = {
1465
+ init: createWidget,
1466
+ VERSION: "1.0.0"
1467
+ };
1468
+ if (typeof window !== "undefined") {
1469
+ window.AICommerceWidget = exports.AICommerceWidget;
1470
+ }
1471
+ }
1472
+ });
1473
+
193
1474
  // src/index.ts
194
1475
  init_client();
1476
+ init_widget();
195
1477
  var VERSION = "1.0.0";
196
1478
  if (typeof window !== "undefined") {
197
1479
  window.AICommerce = (init_client(), __toCommonJS(client_exports)).AICommerce;
198
1480
  window.AICommerceError = (init_client(), __toCommonJS(client_exports)).AICommerceError;
1481
+ window.AICommerceWidget = (init_widget(), __toCommonJS(widget_exports)).AICommerceWidget;
199
1482
  }
200
1483
 
201
1484
  exports.VERSION = VERSION;
1485
+ exports.createWidget = createWidget;
202
1486
  //# sourceMappingURL=index.cjs.map
203
1487
  //# sourceMappingURL=index.cjs.map