@luma-ai/react 2.0.2 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # تغییرات @luma-ai/react
2
2
 
3
+ ## 2.0.3
4
+
5
+ ### تازه‌ها
6
+
7
+ - **آیکون جایگزین لوگو**: وقتی دستیار لوگو ندارد یا لوگو هنوز بارگذاری نشده (یا بارگذاری نمی‌شود)، ویجت به‌جای حرف اول نام دستیار آیکونی نشان می‌دهد که در تنظیمات ظاهر داشبورد انتخاب می‌شود: پشتیبانی (پیش‌فرض)، ربات، حباب گفتگو، ستاره یا آدمک.
8
+
9
+ ### رفع اشکال
10
+
11
+ - **خطای CORS در کنسول سایت**: ویجت نشانی لوگو روی میزبان فایل‌ها را دیگر با `fetch` نمی‌خواند (آن میزبان سرآیند CORS نمی‌فرستد و مرورگر خطا ثبت می‌کرد)؛ فقط نشانی لوگو روی سرور لوما خوانده می‌شود و نشانی میزبان فایل‌ها، اگر لازم شود، مثل یک تصویر ساده بارگذاری می‌شود.
12
+ - **افزونه وردپرس**: پاسخ نشست افزونه حالا `avatarPath` را هم می‌فرستد، مثل `createLumaSessionHandler`، تا لوگو از سرور لوما بیاید حتی وقتی تنظیمات ظاهر بارگذاری نشده باشد.
13
+
3
14
  ## 2.0.2
4
15
 
5
16
  ### رفع اشکال
@@ -2,7 +2,7 @@
2
2
  import * as React from "react";
3
3
  import { Fragment, createContext, memo, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { z } from "zod";
5
- import { AlertCircle, ArrowDownIcon, Bot, Check, CheckCircle2, ClipboardList, CornerDownLeft, ExternalLink, Eye, Loader2, LoaderCircle, LoaderCircleIcon, LoaderIcon, LoaderPinwheelIcon, MessageCircle, Mic, Minus, MousePointer2, MousePointerClick, Package, Phone, RefreshCw, Sparkles, Square, SquarePen, Star, UserRound, Volume2, WifiOff, X, Zap } from "lucide-react";
5
+ import { AlertCircle, ArrowDownIcon, Bot, Check, CheckCircle2, ClipboardList, CornerDownLeft, ExternalLink, Eye, Headset, Loader2, LoaderCircle, LoaderCircleIcon, LoaderIcon, LoaderPinwheelIcon, MessageCircle, Mic, Minus, MousePointer2, MousePointerClick, Package, Phone, RefreshCw, Sparkles, Square, SquarePen, Star, UserRound, Volume2, WifiOff, X, Zap } from "lucide-react";
6
6
  import { createPortal } from "react-dom";
7
7
  import { Slot } from "@radix-ui/react-slot";
8
8
  import { cva } from "class-variance-authority";
@@ -899,6 +899,17 @@ var WIDGET_LAUNCHER_ICONS = [
899
899
  "chat",
900
900
  "sparkles"
901
901
  ];
902
+ /**
903
+ * The icon a widget shows in the logo's place: for an assistant without a
904
+ * logo, and while its logo loads or cannot load.
905
+ */
906
+ var WIDGET_AVATAR_FALLBACKS = [
907
+ "support",
908
+ "bot",
909
+ "chat",
910
+ "sparkles",
911
+ "user"
912
+ ];
902
913
  var WIDGET_LAUNCHER_SIZES = [
903
914
  "sm",
904
915
  "md",
@@ -962,6 +973,7 @@ var widgetThemeSchema = z.object({
962
973
  position: z.enum(WIDGET_POSITIONS).optional(),
963
974
  size: z.enum(WIDGET_SIZES).optional(),
964
975
  launcherIcon: z.enum(WIDGET_LAUNCHER_ICONS).optional(),
976
+ avatarFallback: z.enum(WIDGET_AVATAR_FALLBACKS).optional(),
965
977
  launcherLabel: plainText(WIDGET_TEXT_LIMITS.launcherLabel).optional(),
966
978
  launcherSize: z.enum(WIDGET_LAUNCHER_SIZES).optional(),
967
979
  offsetBottom: offset("desktop").optional(),
@@ -988,6 +1000,7 @@ var WIDGET_THEME_DEFAULTS = {
988
1000
  position: "bottom-right",
989
1001
  size: "md",
990
1002
  launcherIcon: "avatar",
1003
+ avatarFallback: "support",
991
1004
  launcherLabel: "",
992
1005
  launcherSize: "md",
993
1006
  offsetBottom: 20,
@@ -4735,7 +4748,7 @@ function callNoteText(note, lang) {
4735
4748
  * (an alias in apps/assistant-widget/vite.config.ts): their call module is
4736
4749
  * a script beside the build (`call.js`, `/build/call-<hash>.js`).
4737
4750
  */
4738
- var importCallModule = () => import("./visitor-call-DY8tUjuJ.js").then((module) => ({
4751
+ var importCallModule = () => import("./visitor-call-BtS7EaEX.js").then((module) => ({
4739
4752
  api: 1,
4740
4753
  mountVisitorCall: module.mountVisitorCall
4741
4754
  }));
@@ -4975,7 +4988,7 @@ function placeInViewport(point, viewport, margin = 16) {
4975
4988
  * (an alias in apps/assistant-widget/vite.config.ts): their module is a
4976
4989
  * script beside the build (`cobrowse.js`, `/build/cobrowse-<hash>.js`).
4977
4990
  */
4978
- var importCobrowseModule = () => import("./visitor-cobrowse-ctLeCxdW.js").then((module) => ({
4991
+ var importCobrowseModule = () => import("./visitor-cobrowse-DitGnzHK.js").then((module) => ({
4979
4992
  api: 1,
4980
4993
  startCobrowse: module.startCobrowse
4981
4994
  }));
@@ -5810,11 +5823,18 @@ function Cobrowse({ session, visitorKey, tabId, chatId, takenOver, supportKnown,
5810
5823
  ] });
5811
5824
  }
5812
5825
  // src/ui/assistant-logo.tsx
5826
+ var FALLBACK_ICONS = {
5827
+ support: Headset,
5828
+ bot: Bot,
5829
+ chat: MessageCircle,
5830
+ sparkles: Sparkles,
5831
+ user: UserRound
5832
+ };
5813
5833
  /**
5814
- * The logo, or while it loads (or fails) the name's first letter; the
5815
- * default icon only for an assistant with no logo.
5834
+ * The logo, or the icon the owner chose in its place (support by default):
5835
+ * for an assistant with no logo, and while its logo loads or fails.
5816
5836
  */
5817
- function AssistantLogo({ view, name, onBroken, className, iconClassName }) {
5837
+ function AssistantLogo({ view, fallback, onBroken, className, iconClassName }) {
5818
5838
  if (view.state === "ready") return /* @__PURE__ */ jsx("img", {
5819
5839
  alt: "",
5820
5840
  src: view.src,
@@ -5822,15 +5842,13 @@ function AssistantLogo({ view, name, onBroken, className, iconClassName }) {
5822
5842
  "data-luma-logo": "ready",
5823
5843
  onError: onBroken
5824
5844
  });
5825
- if (view.state === "none") return /* @__PURE__ */ jsx(Bot, {
5826
- className: iconClassName,
5827
- "data-luma-logo": "none"
5828
- });
5829
- return /* @__PURE__ */ jsx("span", {
5845
+ const icon = fallback && fallback in FALLBACK_ICONS ? fallback : "support";
5846
+ const Icon = FALLBACK_ICONS[icon];
5847
+ return /* @__PURE__ */ jsx(Icon, {
5830
5848
  "aria-hidden": "true",
5831
- className: cn("flex size-full items-center justify-center font-semibold", className),
5832
- "data-luma-logo": "loading",
5833
- children: Array.from(name.trim())[0] ?? ""
5849
+ className: iconClassName,
5850
+ "data-luma-logo": view.state,
5851
+ "data-luma-logo-icon": icon
5834
5852
  });
5835
5853
  }
5836
5854
  // src/ui/chat-widget.tsx
@@ -6642,9 +6660,9 @@ function ChatWidget({ initialState, onNewChat, autoFocus = false, storageKey: ke
6642
6660
  mobileIconSize,
6643
6661
  icon: theme.launcherIcon !== "avatar" ? LAUNCHER_ICONS[theme.launcherIcon] : /* @__PURE__ */ jsx(AssistantLogo, {
6644
6662
  view: logo,
6645
- name: title,
6663
+ fallback: theme.avatarFallback,
6646
6664
  onBroken: onLogoBroken,
6647
- className: "size-full rounded-full object-cover text-lg",
6665
+ className: "size-full rounded-full object-cover",
6648
6666
  iconClassName: "h-6 w-6"
6649
6667
  }),
6650
6668
  children: [
@@ -6654,7 +6672,7 @@ function ChatWidget({ initialState, onNewChat, autoFocus = false, storageKey: ke
6654
6672
  className: "flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-primary text-primary-foreground",
6655
6673
  children: /* @__PURE__ */ jsx(AssistantLogo, {
6656
6674
  view: logo,
6657
- name: title,
6675
+ fallback: theme.avatarFallback,
6658
6676
  onBroken: onLogoBroken,
6659
6677
  className: "size-full object-cover",
6660
6678
  iconClassName: "size-5"
@@ -7117,13 +7135,26 @@ function asDataUrl(blob) {
7117
7135
  });
7118
7136
  }
7119
7137
  /**
7120
- * Loads a logo in the browser: fetched (the API serves it to any site), and
7121
- * kept as a data URL when small; an address that cannot be fetched (a
7122
- * storage host without CORS) is loaded as a plain image instead.
7138
+ * Whether an address is the logo on the Luma API
7139
+ * (`…/assistant/<id>/avatar/<name>`), which answers any site's `fetch`. The
7140
+ * storage host (`…/assistant/avatars/<id>/<name>`) sends no CORS headers.
7141
+ */
7142
+ function isApiLogo(url) {
7143
+ try {
7144
+ return /\/assistant\/[^/]+\/avatar\/[^/]+$/.test(new URL(url, "http://local").pathname);
7145
+ } catch {
7146
+ return false;
7147
+ }
7148
+ }
7149
+ /**
7150
+ * Loads a logo in the browser. The API's address is fetched, and kept as a
7151
+ * data URL when small; any other address (the storage host, which sends no
7152
+ * CORS headers) is loaded as a plain image only, since fetching it is
7153
+ * refused and logs a CORS error in the site's console.
7123
7154
  */
7124
7155
  var browserLogoLoader = async (url, signal) => {
7125
7156
  let fetched = null;
7126
- try {
7157
+ if (isApiLogo(url)) try {
7127
7158
  const response = await fetch(url, {
7128
7159
  credentials: "omit",
7129
7160
  signal: AbortSignal.any([signal, AbortSignal.timeout(15e3)])
@@ -7645,4 +7676,4 @@ var lumaLabel = (label) => ({ "data-luma-label": label });
7645
7676
  var lumaPrivate = () => ({ "data-luma-private": "" });
7646
7677
  export { useLumaAction as a, COBROWSE_LIMITS as c, CALL_FAILURE_TEXT as d, CALL_TIMING as f, defineAction as h, useLuma as i, placeInViewport as l, routerPath as m, lumaPrivate as n, useLumaContext as o, callDuration as p, LumaPrivate as r, LumaProvider as s, lumaLabel as t, pointOf as u };
7647
7678
 
7648
- //# sourceMappingURL=src-BuzOHEps.js.map
7679
+ //# sourceMappingURL=src-BLo_tGKW.js.map