@luma-ai/react 0.1.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.
@@ -0,0 +1,3100 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { Fragment, createContext, memo, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
+ import { createRoot } from "react-dom/client";
5
+ import { z } from "zod";
6
+ import { createPortal } from "react-dom";
7
+ import { AlertCircle, ArrowDownIcon, Bot, Check, CornerDownLeft, ExternalLink, LoaderCircle, LoaderCircleIcon, LoaderIcon, LoaderPinwheelIcon, MessageCircle, Minus, MousePointerClick, Package, RefreshCw, SquarePen, X, Zap } from "lucide-react";
8
+ import { Slot } from "@radix-ui/react-slot";
9
+ import { cva } from "class-variance-authority";
10
+ import { clsx } from "clsx";
11
+ import { twMerge } from "tailwind-merge";
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ import { useChat } from "@ai-sdk/react";
14
+ import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
15
+ import ReactMarkdown from "react-markdown";
16
+ import remarkGfm from "remark-gfm";
17
+ import { DefaultChatTransport } from "ai";
18
+ //#region src/styles.css?inline
19
+ var styles_default = "/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n@layer properties {\n @supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {\n *, :before, :after, ::backdrop {\n --tw-translate-x: 0;\n --tw-translate-y: 0;\n --tw-translate-z: 0;\n --tw-scale-x: 1;\n --tw-scale-y: 1;\n --tw-scale-z: 1;\n --tw-rotate-x: initial;\n --tw-rotate-y: initial;\n --tw-rotate-z: initial;\n --tw-skew-x: initial;\n --tw-skew-y: initial;\n --tw-space-y-reverse: 0;\n --tw-border-style: solid;\n --tw-font-weight: initial;\n --tw-shadow: 0 0 #0000;\n --tw-shadow-color: initial;\n --tw-shadow-alpha: 100%;\n --tw-inset-shadow: 0 0 #0000;\n --tw-inset-shadow-color: initial;\n --tw-inset-shadow-alpha: 100%;\n --tw-ring-color: initial;\n --tw-ring-shadow: 0 0 #0000;\n --tw-inset-ring-color: initial;\n --tw-inset-ring-shadow: 0 0 #0000;\n --tw-ring-inset: initial;\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-outline-style: solid;\n --tw-backdrop-blur: initial;\n --tw-backdrop-brightness: initial;\n --tw-backdrop-contrast: initial;\n --tw-backdrop-grayscale: initial;\n --tw-backdrop-hue-rotate: initial;\n --tw-backdrop-invert: initial;\n --tw-backdrop-opacity: initial;\n --tw-backdrop-saturate: initial;\n --tw-backdrop-sepia: initial;\n --tw-duration: initial;\n --tw-ease: initial;\n --tw-animation-delay: 0s;\n --tw-animation-direction: normal;\n --tw-animation-duration: initial;\n --tw-animation-fill-mode: none;\n --tw-animation-iteration-count: 1;\n --tw-enter-blur: 0;\n --tw-enter-opacity: 1;\n --tw-enter-rotate: 0;\n --tw-enter-scale: 1;\n --tw-enter-translate-x: 0;\n --tw-enter-translate-y: 0;\n --tw-exit-blur: 0;\n --tw-exit-opacity: 1;\n --tw-exit-rotate: 0;\n --tw-exit-scale: 1;\n --tw-exit-translate-x: 0;\n --tw-exit-translate-y: 0;\n }\n }\n}\n\n@layer theme {\n :root, :host {\n --font-sans: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\",\n \"Noto Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\",\n \"Segoe UI Symbol\", \"Noto Color Emoji\";\n --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\",\n \"Courier New\", monospace;\n --color-red-500: oklch(63.7% .237 25.331);\n --color-orange-500: oklch(70.5% .213 47.604);\n --color-amber-500: oklch(76.9% .188 70.08);\n --color-emerald-300: oklch(84.5% .143 164.978);\n --color-emerald-500: oklch(69.6% .17 162.48);\n --color-emerald-700: oklch(50.8% .118 165.612);\n --color-blue-500: oklch(62.3% .214 259.815);\n --color-blue-600: oklch(54.6% .245 262.881);\n --color-indigo-500: oklch(58.5% .233 277.117);\n --color-purple-500: oklch(62.7% .265 303.9);\n --color-pink-500: oklch(65.6% .241 354.308);\n --color-neutral-950: oklch(14.5% 0 none);\n --color-black: #000;\n --color-white: #fff;\n --spacing: .25rem;\n --container-sm: 24rem;\n --container-md: 28rem;\n --container-lg: 32rem;\n --container-xl: 36rem;\n --text-xs: .75rem;\n --text-xs--line-height: calc(1 / .75);\n --text-sm: .875rem;\n --text-sm--line-height: calc(1.25 / .875);\n --text-base: 1rem;\n --text-base--line-height: calc(1.5 / 1);\n --text-lg: 1.125rem;\n --text-lg--line-height: calc(1.75 / 1.125);\n --text-xl: 1.25rem;\n --text-2xl: 1.5rem;\n --font-weight-medium: 500;\n --font-weight-semibold: 600;\n --ease-out: cubic-bezier(0, 0, .2, 1);\n --animate-spin: spin 1s linear infinite;\n --blur-xl: 24px;\n --default-transition-duration: .15s;\n --default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);\n --default-font-family: var(--font-sans);\n --default-mono-font-family: var(--font-mono);\n }\n}\n\n@layer base {\n *, :after, :before, ::backdrop {\n box-sizing: border-box;\n border: 0 solid;\n margin: 0;\n padding: 0;\n }\n\n ::file-selector-button {\n box-sizing: border-box;\n border: 0 solid;\n margin: 0;\n padding: 0;\n }\n\n html, :host {\n -webkit-text-size-adjust: 100%;\n tab-size: 4;\n line-height: 1.5;\n font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");\n font-feature-settings: var(--default-font-feature-settings, normal);\n font-variation-settings: var(--default-font-variation-settings, normal);\n -webkit-tap-highlight-color: transparent;\n }\n\n hr {\n height: 0;\n color: inherit;\n border-top-width: 1px;\n }\n\n abbr:where([title]) {\n -webkit-text-decoration: underline dotted;\n text-decoration: underline dotted;\n }\n\n h1, h2, h3, h4, h5, h6 {\n font-size: inherit;\n font-weight: inherit;\n }\n\n a {\n color: inherit;\n -webkit-text-decoration: inherit;\n -webkit-text-decoration: inherit;\n -webkit-text-decoration: inherit;\n text-decoration: inherit;\n }\n\n b, strong {\n font-weight: bolder;\n }\n\n code, kbd, samp, pre {\n font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);\n font-feature-settings: var(--default-mono-font-feature-settings, normal);\n font-variation-settings: var(--default-mono-font-variation-settings, normal);\n font-size: 1em;\n }\n\n small {\n font-size: 80%;\n }\n\n sub, sup {\n vertical-align: baseline;\n font-size: 75%;\n line-height: 0;\n position: relative;\n }\n\n sub {\n bottom: -.25em;\n }\n\n sup {\n top: -.5em;\n }\n\n table {\n text-indent: 0;\n border-color: inherit;\n border-collapse: collapse;\n }\n\n :-moz-focusring:where(:not(iframe)) {\n outline: auto;\n }\n\n progress {\n vertical-align: baseline;\n }\n\n summary {\n display: list-item;\n }\n\n ol, ul, menu {\n list-style: none;\n }\n\n img, svg, video, canvas, audio, iframe, embed, object {\n vertical-align: middle;\n display: block;\n }\n\n img, video {\n max-width: 100%;\n height: auto;\n }\n\n button, input, select, optgroup, textarea {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n opacity: 1;\n background-color: #0000;\n border-radius: 0;\n }\n\n ::file-selector-button {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n opacity: 1;\n background-color: #0000;\n border-radius: 0;\n }\n\n :where(select:is([multiple], [size])) optgroup {\n font-weight: bolder;\n }\n\n :where(select:is([multiple], [size])) optgroup option {\n padding-inline-start: 20px;\n }\n\n ::file-selector-button {\n margin-inline-end: 4px;\n }\n\n ::placeholder {\n opacity: 1;\n }\n\n @supports (not ((-webkit-appearance: -apple-pay-button))) or (contain-intrinsic-size: 1px) {\n ::placeholder {\n color: currentColor;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n ::placeholder {\n color: color-mix(in oklab, currentcolor 50%, transparent);\n }\n }\n }\n\n textarea {\n resize: vertical;\n }\n\n ::-webkit-search-decoration {\n -webkit-appearance: none;\n }\n\n ::-webkit-date-and-time-value {\n min-height: 1lh;\n text-align: inherit;\n }\n\n ::-webkit-datetime-edit {\n display: inline-flex;\n }\n\n ::-webkit-datetime-edit-fields-wrapper {\n padding: 0;\n }\n\n ::-webkit-datetime-edit {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-year-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-month-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-day-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-hour-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-minute-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-second-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-millisecond-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-meridiem-field {\n padding-block: 0;\n }\n\n ::-webkit-calendar-picker-indicator {\n line-height: 1;\n }\n\n :-moz-ui-invalid {\n box-shadow: none;\n }\n\n button, input:where([type=\"button\"], [type=\"reset\"], [type=\"submit\"]) {\n appearance: button;\n }\n\n ::file-selector-button {\n appearance: button;\n }\n\n ::-webkit-inner-spin-button {\n height: auto;\n }\n\n ::-webkit-outer-spin-button {\n height: auto;\n }\n\n [hidden]:where(:not([hidden=\"until-found\"])) {\n display: none !important;\n }\n\n .luma-assistant-widget-root {\n background-color: var(--background);\n color: var(--foreground);\n }\n\n .luma-assistant-widget-wrapper h1 {\n font-size: var(--text-2xl);\n }\n\n .luma-assistant-widget-wrapper h2 {\n font-size: var(--text-xl);\n }\n\n .luma-assistant-widget-wrapper h3 {\n font-size: var(--text-lg);\n }\n\n .luma-assistant-widget-wrapper a {\n color: var(--color-blue-600);\n text-decoration-line: underline;\n }\n\n .luma-assistant-widget-wrapper p, .luma-assistant-widget-wrapper li, .luma-assistant-widget-wrapper td, .luma-assistant-widget-wrapper th, .luma-assistant-widget-wrapper a, .luma-assistant-widget-wrapper span, .luma-assistant-widget-wrapper code, .luma-assistant-widget-wrapper pre, .luma-assistant-widget-wrapper blockquote, .luma-assistant-widget-wrapper hr, .luma-assistant-widget-wrapper img, .luma-assistant-widget-wrapper figure {\n font-size: var(--text-base);\n }\n}\n\n@layer components;\n\n@layer utilities {\n .pointer-events-auto {\n pointer-events: auto !important;\n }\n\n .pointer-events-none {\n pointer-events: none !important;\n }\n\n .invisible {\n visibility: hidden !important;\n }\n\n .visible {\n visibility: visible !important;\n }\n\n .absolute {\n position: absolute !important;\n }\n\n .fixed {\n position: fixed !important;\n }\n\n .relative {\n position: relative !important;\n }\n\n .inset-0 {\n inset: 0 !important;\n }\n\n .inset-auto {\n inset: auto !important;\n }\n\n .right-0 {\n right: 0 !important;\n }\n\n .right-4 {\n right: calc(var(--spacing) * 4) !important;\n }\n\n .bottom-4 {\n bottom: calc(var(--spacing) * 4) !important;\n }\n\n .bottom-\\[calc\\(100\\%\\+10px\\)\\] {\n bottom: calc(100% + 10px) !important;\n }\n\n .left-0 {\n left: 0 !important;\n }\n\n .left-\\[50\\%\\] {\n left: 50% !important;\n }\n\n .z-999999 {\n z-index: 999999 !important;\n }\n\n .container {\n width: 100% !important;\n }\n\n @media (min-width: 40rem) {\n .container {\n max-width: 40rem !important;\n }\n }\n\n @media (min-width: 48rem) {\n .container {\n max-width: 48rem !important;\n }\n }\n\n @media (min-width: 64rem) {\n .container {\n max-width: 64rem !important;\n }\n }\n\n @media (min-width: 80rem) {\n .container {\n max-width: 80rem !important;\n }\n }\n\n @media (min-width: 96rem) {\n .container {\n max-width: 96rem !important;\n }\n }\n\n .mx-2 {\n margin-inline: calc(var(--spacing) * 2) !important;\n }\n\n .ms-auto {\n margin-inline-start: auto !important;\n }\n\n .prose {\n color: var(--tw-prose-body) !important;\n max-width: 65ch !important;\n }\n\n .prose :where(p):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.25em !important;\n margin-bottom: 1.25em !important;\n }\n\n .prose :where([class~=\"lead\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-lead) !important;\n margin-top: 1.2em !important;\n margin-bottom: 1.2em !important;\n font-size: 1.25em !important;\n line-height: 1.6 !important;\n }\n\n .prose :where(a):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-links) !important;\n font-weight: 500 !important;\n text-decoration: underline !important;\n }\n\n .prose :where(strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-bold) !important;\n font-weight: 600 !important;\n }\n\n .prose :where(a strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(blockquote strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(thead th strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n }\n\n .prose :where(ol):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.25em !important;\n margin-bottom: 1.25em !important;\n padding-inline-start: 1.625em !important;\n list-style-type: decimal !important;\n }\n\n .prose :where(ol[type=\"A\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: upper-alpha !important;\n }\n\n .prose :where(ol[type=\"a\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: lower-alpha !important;\n }\n\n .prose :where(ol[type=\"A\" s]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: upper-alpha !important;\n }\n\n .prose :where(ol[type=\"a\" s]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: lower-alpha !important;\n }\n\n .prose :where(ol[type=\"I\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: upper-roman !important;\n }\n\n .prose :where(ol[type=\"i\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: lower-roman !important;\n }\n\n .prose :where(ol[type=\"I\" s]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: upper-roman !important;\n }\n\n .prose :where(ol[type=\"i\" s]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: lower-roman !important;\n }\n\n .prose :where(ol[type=\"1\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n list-style-type: decimal !important;\n }\n\n .prose :where(ul):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.25em !important;\n margin-bottom: 1.25em !important;\n padding-inline-start: 1.625em !important;\n list-style-type: disc !important;\n }\n\n .prose :where(ol > li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *))::marker {\n color: var(--tw-prose-counters) !important;\n font-weight: 400 !important;\n }\n\n .prose :where(ul > li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *))::marker {\n color: var(--tw-prose-bullets) !important;\n }\n\n .prose :where(dt):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-headings) !important;\n margin-top: 1.25em !important;\n font-weight: 600 !important;\n }\n\n .prose :where(hr):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n border-color: var(--tw-prose-hr) !important;\n border-top-width: 1px !important;\n margin-top: 3em !important;\n margin-bottom: 3em !important;\n }\n\n .prose :where(blockquote):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-quotes) !important;\n border-inline-start-width: .25rem !important;\n border-inline-start-color: var(--tw-prose-quote-borders) !important;\n quotes: \"“\"\"”\"\"‘\"\"’\" !important;\n margin-top: 1.6em !important;\n margin-bottom: 1.6em !important;\n padding-inline-start: 1em !important;\n font-style: italic !important;\n font-weight: 500 !important;\n }\n\n .prose :where(blockquote p:first-of-type):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)):before {\n content: open-quote !important;\n }\n\n .prose :where(blockquote p:last-of-type):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)):after {\n content: close-quote !important;\n }\n\n .prose :where(h1):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-headings) !important;\n margin-top: 0 !important;\n margin-bottom: .888889em !important;\n font-size: 2.25em !important;\n font-weight: 800 !important;\n line-height: 1.11111 !important;\n }\n\n .prose :where(h1 strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n font-weight: 900 !important;\n }\n\n .prose :where(h2):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-headings) !important;\n margin-top: 2em !important;\n margin-bottom: 1em !important;\n font-size: 1.5em !important;\n font-weight: 700 !important;\n line-height: 1.33333 !important;\n }\n\n .prose :where(h2 strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n font-weight: 800 !important;\n }\n\n .prose :where(h3):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-headings) !important;\n margin-top: 1.6em !important;\n margin-bottom: .6em !important;\n font-size: 1.25em !important;\n font-weight: 600 !important;\n line-height: 1.6 !important;\n }\n\n .prose :where(h3 strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n font-weight: 700 !important;\n }\n\n .prose :where(h4):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-headings) !important;\n margin-top: 1.5em !important;\n margin-bottom: .5em !important;\n font-weight: 600 !important;\n line-height: 1.5 !important;\n }\n\n .prose :where(h4 strong):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n font-weight: 700 !important;\n }\n\n .prose :where(img):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 2em !important;\n margin-bottom: 2em !important;\n }\n\n .prose :where(picture):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 2em !important;\n margin-bottom: 2em !important;\n display: block !important;\n }\n\n .prose :where(video):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 2em !important;\n margin-bottom: 2em !important;\n }\n\n .prose :where(kbd):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-kbd) !important;\n box-shadow: 0 0 0 1px var(--tw-prose-kbd-shadows), 0 3px 0 var(--tw-prose-kbd-shadows) !important;\n padding-top: .1875em !important;\n padding-inline-end: .375em !important;\n padding-bottom: .1875em !important;\n border-radius: .3125rem !important;\n padding-inline-start: .375em !important;\n font-family: inherit !important;\n font-size: .875em !important;\n font-weight: 500 !important;\n }\n\n .prose :where(code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-code) !important;\n font-size: .875em !important;\n font-weight: 600 !important;\n }\n\n .prose :where(code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)):before, .prose :where(code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)):after {\n content: \"`\" !important;\n }\n\n .prose :where(a code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(h1 code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n }\n\n .prose :where(h2 code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n font-size: .875em !important;\n }\n\n .prose :where(h3 code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n font-size: .9em !important;\n }\n\n .prose :where(h4 code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(blockquote code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(thead th code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: inherit !important;\n }\n\n .prose :where(pre):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-pre-code) !important;\n background-color: var(--tw-prose-pre-bg) !important;\n padding-top: .857143em !important;\n padding-inline-end: 1.14286em !important;\n padding-bottom: .857143em !important;\n border-radius: .375rem !important;\n margin-top: 1.71429em !important;\n margin-bottom: 1.71429em !important;\n padding-inline-start: 1.14286em !important;\n font-size: .875em !important;\n font-weight: 400 !important;\n line-height: 1.71429 !important;\n overflow-x: auto !important;\n }\n\n .prose :where(pre code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n font-weight: inherit !important;\n color: inherit !important;\n font-size: inherit !important;\n font-family: inherit !important;\n line-height: inherit !important;\n background-color: #0000 !important;\n border-width: 0 !important;\n border-radius: 0 !important;\n padding: 0 !important;\n }\n\n .prose :where(pre code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)):before, .prose :where(pre code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)):after {\n content: none !important;\n }\n\n .prose :where(table):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n table-layout: auto !important;\n width: 100% !important;\n margin-top: 2em !important;\n margin-bottom: 2em !important;\n font-size: .875em !important;\n line-height: 1.71429 !important;\n }\n\n .prose :where(thead):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n border-bottom-width: 1px !important;\n border-bottom-color: var(--tw-prose-th-borders) !important;\n }\n\n .prose :where(thead th):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-headings) !important;\n vertical-align: bottom !important;\n padding-inline-end: .571429em !important;\n padding-bottom: .571429em !important;\n padding-inline-start: .571429em !important;\n font-weight: 600 !important;\n }\n\n .prose :where(tbody tr):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n border-bottom-width: 1px !important;\n border-bottom-color: var(--tw-prose-td-borders) !important;\n }\n\n .prose :where(tbody tr:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n border-bottom-width: 0 !important;\n }\n\n .prose :where(tbody td):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n vertical-align: baseline !important;\n }\n\n .prose :where(tfoot):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n border-top-width: 1px !important;\n border-top-color: var(--tw-prose-th-borders) !important;\n }\n\n .prose :where(tfoot td):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n vertical-align: top !important;\n }\n\n .prose :where(th, td):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n text-align: start !important;\n }\n\n .prose :where(figure > *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n margin-bottom: 0 !important;\n }\n\n .prose :where(figcaption):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n color: var(--tw-prose-captions) !important;\n margin-top: .857143em !important;\n font-size: .875em !important;\n line-height: 1.42857 !important;\n }\n\n .prose {\n --tw-prose-body: oklch(37.3% .034 259.733) !important;\n --tw-prose-headings: oklch(21% .034 264.665) !important;\n --tw-prose-lead: oklch(44.6% .03 256.802) !important;\n --tw-prose-links: oklch(21% .034 264.665) !important;\n --tw-prose-bold: oklch(21% .034 264.665) !important;\n --tw-prose-counters: oklch(55.1% .027 264.364) !important;\n --tw-prose-bullets: oklch(87.2% .01 258.338) !important;\n --tw-prose-hr: oklch(92.8% .006 264.531) !important;\n --tw-prose-quotes: oklch(21% .034 264.665) !important;\n --tw-prose-quote-borders: oklch(92.8% .006 264.531) !important;\n --tw-prose-captions: oklch(55.1% .027 264.364) !important;\n --tw-prose-kbd: oklch(21% .034 264.665) !important;\n --tw-prose-kbd-shadows: oklab(21% -.00316127 -.0338527 / .1) !important;\n --tw-prose-code: oklch(21% .034 264.665) !important;\n --tw-prose-pre-code: oklch(92.8% .006 264.531) !important;\n --tw-prose-pre-bg: oklch(27.8% .033 256.848) !important;\n --tw-prose-th-borders: oklch(87.2% .01 258.338) !important;\n --tw-prose-td-borders: oklch(92.8% .006 264.531) !important;\n --tw-prose-invert-body: oklch(87.2% .01 258.338) !important;\n --tw-prose-invert-headings: #fff !important;\n --tw-prose-invert-lead: oklch(70.7% .022 261.325) !important;\n --tw-prose-invert-links: #fff !important;\n --tw-prose-invert-bold: #fff !important;\n --tw-prose-invert-counters: oklch(70.7% .022 261.325) !important;\n --tw-prose-invert-bullets: oklch(44.6% .03 256.802) !important;\n --tw-prose-invert-hr: oklch(37.3% .034 259.733) !important;\n --tw-prose-invert-quotes: oklch(96.7% .003 264.542) !important;\n --tw-prose-invert-quote-borders: oklch(37.3% .034 259.733) !important;\n --tw-prose-invert-captions: oklch(70.7% .022 261.325) !important;\n --tw-prose-invert-kbd: #fff !important;\n --tw-prose-invert-kbd-shadows: #ffffff1a !important;\n --tw-prose-invert-code: #fff !important;\n --tw-prose-invert-pre-code: oklch(87.2% .01 258.338) !important;\n --tw-prose-invert-pre-bg: #00000080 !important;\n --tw-prose-invert-th-borders: oklch(44.6% .03 256.802) !important;\n --tw-prose-invert-td-borders: oklch(37.3% .034 259.733) !important;\n font-size: 1rem !important;\n line-height: 1.75 !important;\n }\n\n .prose :where(picture > img):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n margin-bottom: 0 !important;\n }\n\n .prose :where(li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .5em !important;\n margin-bottom: .5em !important;\n }\n\n .prose :where(ol > li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(ul > li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-start: .375em !important;\n }\n\n .prose :where(.prose > ul > li p):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .75em !important;\n margin-bottom: .75em !important;\n }\n\n .prose :where(.prose > ul > li > p:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.25em !important;\n }\n\n .prose :where(.prose > ul > li > p:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-bottom: 1.25em !important;\n }\n\n .prose :where(.prose > ol > li > p:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.25em !important;\n }\n\n .prose :where(.prose > ol > li > p:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-bottom: 1.25em !important;\n }\n\n .prose :where(ul ul, ul ol, ol ul, ol ol):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .75em !important;\n margin-bottom: .75em !important;\n }\n\n .prose :where(dl):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.25em !important;\n margin-bottom: 1.25em !important;\n }\n\n .prose :where(dd):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .5em !important;\n padding-inline-start: 1.625em !important;\n }\n\n .prose :where(hr + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(h2 + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(h3 + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose :where(h4 + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n }\n\n .prose :where(thead th:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-start: 0 !important;\n }\n\n .prose :where(thead th:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-end: 0 !important;\n }\n\n .prose :where(tbody td, tfoot td):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-top: .571429em !important;\n padding-inline-end: .571429em !important;\n padding-bottom: .571429em !important;\n padding-inline-start: .571429em !important;\n }\n\n .prose :where(tbody td:first-child, tfoot td:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-start: 0 !important;\n }\n\n .prose :where(tbody td:last-child, tfoot td:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-end: 0 !important;\n }\n\n .prose :where(figure):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 2em !important;\n margin-bottom: 2em !important;\n }\n\n .prose :where(.prose > :first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n }\n\n .prose :where(.prose > :last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-bottom: 0 !important;\n }\n\n .prose-sm {\n font-size: .875rem !important;\n line-height: 1.71429 !important;\n }\n\n .prose-sm :where(p):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.14286em !important;\n margin-bottom: 1.14286em !important;\n }\n\n .prose-sm :where([class~=\"lead\"]):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .888889em !important;\n margin-bottom: .888889em !important;\n font-size: 1.28571em !important;\n line-height: 1.55556 !important;\n }\n\n .prose-sm :where(blockquote):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.33333em !important;\n margin-bottom: 1.33333em !important;\n padding-inline-start: 1.11111em !important;\n }\n\n .prose-sm :where(h1):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n margin-bottom: .8em !important;\n font-size: 2.14286em !important;\n line-height: 1.2 !important;\n }\n\n .prose-sm :where(h2):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.6em !important;\n margin-bottom: .8em !important;\n font-size: 1.42857em !important;\n line-height: 1.4 !important;\n }\n\n .prose-sm :where(h3):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.55556em !important;\n margin-bottom: .444444em !important;\n font-size: 1.28571em !important;\n line-height: 1.55556 !important;\n }\n\n .prose-sm :where(h4):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.42857em !important;\n margin-bottom: .571429em !important;\n line-height: 1.42857 !important;\n }\n\n .prose-sm :where(img):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose-sm :where(picture):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.71429em !important;\n margin-bottom: 1.71429em !important;\n }\n\n .prose-sm :where(picture > img):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n margin-bottom: 0 !important;\n }\n\n .prose-sm :where(video):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.71429em !important;\n margin-bottom: 1.71429em !important;\n }\n\n .prose-sm :where(kbd):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-top: .142857em !important;\n padding-inline-end: .357143em !important;\n padding-bottom: .142857em !important;\n border-radius: .3125rem !important;\n padding-inline-start: .357143em !important;\n font-size: .857143em !important;\n }\n\n .prose-sm :where(code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n font-size: .857143em !important;\n }\n\n .prose-sm :where(h2 code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n font-size: .9em !important;\n }\n\n .prose-sm :where(h3 code):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n font-size: .888889em !important;\n }\n\n .prose-sm :where(pre):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-top: .666667em !important;\n padding-inline-end: 1em !important;\n padding-bottom: .666667em !important;\n border-radius: .25rem !important;\n margin-top: 1.66667em !important;\n margin-bottom: 1.66667em !important;\n padding-inline-start: 1em !important;\n font-size: .857143em !important;\n line-height: 1.66667 !important;\n }\n\n .prose-sm :where(ol):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose-sm :where(ul):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.14286em !important;\n margin-bottom: 1.14286em !important;\n padding-inline-start: 1.57143em !important;\n }\n\n .prose-sm :where(li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .285714em !important;\n margin-bottom: .285714em !important;\n }\n\n .prose-sm :where(ol > li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose-sm :where(ul > li):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-start: .428571em !important;\n }\n\n .prose-sm :where(.prose-sm > ul > li p):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .571429em !important;\n margin-bottom: .571429em !important;\n }\n\n .prose-sm :where(.prose-sm > ul > li > p:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.14286em !important;\n }\n\n .prose-sm :where(.prose-sm > ul > li > p:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-bottom: 1.14286em !important;\n }\n\n .prose-sm :where(.prose-sm > ol > li > p:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.14286em !important;\n }\n\n .prose-sm :where(.prose-sm > ol > li > p:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-bottom: 1.14286em !important;\n }\n\n .prose-sm :where(ul ul, ul ol, ol ul, ol ol):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .571429em !important;\n margin-bottom: .571429em !important;\n }\n\n .prose-sm :where(dl):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.14286em !important;\n margin-bottom: 1.14286em !important;\n }\n\n .prose-sm :where(dt):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.14286em !important;\n }\n\n .prose-sm :where(dd):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .285714em !important;\n padding-inline-start: 1.57143em !important;\n }\n\n .prose-sm :where(hr):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 2.85714em !important;\n margin-bottom: 2.85714em !important;\n }\n\n .prose-sm :where(hr + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose-sm :where(h2 + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose-sm :where(h3 + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)), .prose-sm :where(h4 + *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n }\n\n .prose-sm :where(table):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n font-size: .857143em !important;\n line-height: 1.5 !important;\n }\n\n .prose-sm :where(thead th):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-end: 1em !important;\n padding-bottom: .666667em !important;\n padding-inline-start: 1em !important;\n }\n\n .prose-sm :where(thead th:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-start: 0 !important;\n }\n\n .prose-sm :where(thead th:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-end: 0 !important;\n }\n\n .prose-sm :where(tbody td, tfoot td):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-top: .666667em !important;\n padding-inline-end: 1em !important;\n padding-bottom: .666667em !important;\n padding-inline-start: 1em !important;\n }\n\n .prose-sm :where(tbody td:first-child, tfoot td:first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-start: 0 !important;\n }\n\n .prose-sm :where(tbody td:last-child, tfoot td:last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n padding-inline-end: 0 !important;\n }\n\n .prose-sm :where(figure):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 1.71429em !important;\n margin-bottom: 1.71429em !important;\n }\n\n .prose-sm :where(figure > *):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n margin-bottom: 0 !important;\n }\n\n .prose-sm :where(figcaption):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: .666667em !important;\n font-size: .857143em !important;\n line-height: 1.33333 !important;\n }\n\n .prose-sm :where(.prose-sm > :first-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-top: 0 !important;\n }\n\n .prose-sm :where(.prose-sm > :last-child):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)) {\n margin-bottom: 0 !important;\n }\n\n .mt-0 {\n margin-top: 0 !important;\n }\n\n .mt-0\\.5 {\n margin-top: calc(var(--spacing) * .5) !important;\n }\n\n .mt-1 {\n margin-top: var(--spacing) !important;\n }\n\n .mt-auto {\n margin-top: auto !important;\n }\n\n .mb-0 {\n margin-bottom: 0 !important;\n }\n\n .mb-2 {\n margin-bottom: calc(var(--spacing) * 2) !important;\n }\n\n .line-clamp-2 {\n -webkit-line-clamp: 2 !important;\n -webkit-box-orient: vertical !important;\n display: -webkit-box !important;\n overflow: hidden !important;\n }\n\n .block {\n display: block !important;\n }\n\n .contents {\n display: contents !important;\n }\n\n .flex {\n display: flex !important;\n }\n\n .hidden {\n display: none !important;\n }\n\n .inline {\n display: inline !important;\n }\n\n .inline-flex {\n display: inline-flex !important;\n }\n\n .field-sizing-content {\n field-sizing: content !important;\n }\n\n .aspect-square {\n aspect-ratio: 1 !important;\n }\n\n .size-3 {\n width: calc(var(--spacing) * 3) !important;\n height: calc(var(--spacing) * 3) !important;\n }\n\n .size-3\\.5 {\n width: calc(var(--spacing) * 3.5) !important;\n height: calc(var(--spacing) * 3.5) !important;\n }\n\n .size-4 {\n width: calc(var(--spacing) * 4) !important;\n height: calc(var(--spacing) * 4) !important;\n }\n\n .size-5 {\n width: calc(var(--spacing) * 5) !important;\n height: calc(var(--spacing) * 5) !important;\n }\n\n .size-6 {\n width: calc(var(--spacing) * 6) !important;\n height: calc(var(--spacing) * 6) !important;\n }\n\n .size-8 {\n width: calc(var(--spacing) * 8) !important;\n height: calc(var(--spacing) * 8) !important;\n }\n\n .size-9 {\n width: calc(var(--spacing) * 9) !important;\n height: calc(var(--spacing) * 9) !important;\n }\n\n .size-10 {\n width: calc(var(--spacing) * 10) !important;\n height: calc(var(--spacing) * 10) !important;\n }\n\n .size-14 {\n width: calc(var(--spacing) * 14) !important;\n height: calc(var(--spacing) * 14) !important;\n }\n\n .size-16 {\n width: calc(var(--spacing) * 16) !important;\n height: calc(var(--spacing) * 16) !important;\n }\n\n .size-18 {\n width: calc(var(--spacing) * 18) !important;\n height: calc(var(--spacing) * 18) !important;\n }\n\n .size-20 {\n width: calc(var(--spacing) * 20) !important;\n height: calc(var(--spacing) * 20) !important;\n }\n\n .size-full {\n width: 100% !important;\n height: 100% !important;\n }\n\n .h-5 {\n height: calc(var(--spacing) * 5) !important;\n }\n\n .h-6 {\n height: calc(var(--spacing) * 6) !important;\n }\n\n .h-7 {\n height: calc(var(--spacing) * 7) !important;\n }\n\n .h-8 {\n height: calc(var(--spacing) * 8) !important;\n }\n\n .h-9 {\n height: calc(var(--spacing) * 9) !important;\n }\n\n .h-10 {\n height: calc(var(--spacing) * 10) !important;\n }\n\n .h-16 {\n height: calc(var(--spacing) * 16) !important;\n }\n\n .h-\\[80vh\\] {\n height: 80vh !important;\n }\n\n .h-auto {\n height: auto !important;\n }\n\n .h-full {\n height: 100% !important;\n }\n\n .max-h-32 {\n max-height: calc(var(--spacing) * 32) !important;\n }\n\n .max-h-\\[500px\\] {\n max-height: 500px !important;\n }\n\n .max-h-\\[600px\\] {\n max-height: 600px !important;\n }\n\n .max-h-\\[700px\\] {\n max-height: 700px !important;\n }\n\n .max-h-\\[800px\\] {\n max-height: 800px !important;\n }\n\n .min-h-12 {\n min-height: calc(var(--spacing) * 12) !important;\n }\n\n .min-h-16 {\n min-height: calc(var(--spacing) * 16) !important;\n }\n\n .w-5 {\n width: calc(var(--spacing) * 5) !important;\n }\n\n .w-6 {\n width: calc(var(--spacing) * 6) !important;\n }\n\n .w-7 {\n width: calc(var(--spacing) * 7) !important;\n }\n\n .w-8 {\n width: calc(var(--spacing) * 8) !important;\n }\n\n .w-\\[90vw\\] {\n width: 90vw !important;\n }\n\n .w-full {\n width: 100% !important;\n }\n\n .max-w-\\[80\\%\\] {\n max-width: 80% !important;\n }\n\n .max-w-full {\n max-width: 100% !important;\n }\n\n .max-w-lg {\n max-width: var(--container-lg) !important;\n }\n\n .max-w-md {\n max-width: var(--container-md) !important;\n }\n\n .max-w-none {\n max-width: none !important;\n }\n\n .max-w-sm {\n max-width: var(--container-sm) !important;\n }\n\n .max-w-xl {\n max-width: var(--container-xl) !important;\n }\n\n .min-w-0 {\n min-width: 0 !important;\n }\n\n .flex-1 {\n flex: 1 !important;\n }\n\n .shrink-0 {\n flex-shrink: 0 !important;\n }\n\n .grow {\n flex-grow: 1 !important;\n }\n\n .translate-x-\\[-50\\%\\] {\n --tw-translate-x: -50% !important;\n translate: var(--tw-translate-x) var(--tw-translate-y) !important;\n }\n\n .translate-y-0 {\n --tw-translate-y: 0px !important;\n translate: var(--tw-translate-x) var(--tw-translate-y) !important;\n }\n\n .scale-100 {\n --tw-scale-x: 100% !important;\n --tw-scale-y: 100% !important;\n --tw-scale-z: 100% !important;\n scale: var(--tw-scale-x) var(--tw-scale-y) !important;\n }\n\n .rotate-180 {\n rotate: 180deg !important;\n }\n\n .transform {\n transform: var(--tw-rotate-x, ) var(--tw-rotate-y, ) var(--tw-rotate-z, ) var(--tw-skew-x, ) var(--tw-skew-y, ) !important;\n }\n\n .animate-spin {\n animation: var(--animate-spin) !important;\n }\n\n .resize {\n resize: both !important;\n }\n\n .resize-none {\n resize: none !important;\n }\n\n .flex-col {\n flex-direction: column !important;\n }\n\n .flex-row-reverse {\n flex-direction: row-reverse !important;\n }\n\n .flex-wrap {\n flex-wrap: wrap !important;\n }\n\n .items-center {\n align-items: center !important;\n }\n\n .items-end {\n align-items: flex-end !important;\n }\n\n .items-start {\n align-items: flex-start !important;\n }\n\n .justify-between {\n justify-content: space-between !important;\n }\n\n .justify-center {\n justify-content: center !important;\n }\n\n .justify-end {\n justify-content: flex-end !important;\n }\n\n .justify-start {\n justify-content: flex-start !important;\n }\n\n .gap-1 {\n gap: var(--spacing) !important;\n }\n\n .gap-1\\.5 {\n gap: calc(var(--spacing) * 1.5) !important;\n }\n\n .gap-2 {\n gap: calc(var(--spacing) * 2) !important;\n }\n\n .gap-3 {\n gap: calc(var(--spacing) * 3) !important;\n }\n\n :where(.space-y-1 > :not(:last-child)) {\n --tw-space-y-reverse: 0 !important;\n margin-block-start: calc(var(--spacing) * var(--tw-space-y-reverse)) !important;\n margin-block-end: calc(var(--spacing) * calc(1 - var(--tw-space-y-reverse))) !important;\n }\n\n .self-start {\n align-self: flex-start !important;\n }\n\n .truncate {\n text-overflow: ellipsis !important;\n white-space: nowrap !important;\n overflow: hidden !important;\n }\n\n .overflow-hidden {\n overflow: hidden !important;\n }\n\n .overflow-y-auto {\n overflow-y: auto !important;\n }\n\n .rounded-full {\n border-radius: 3.40282e38px !important;\n }\n\n .rounded-lg {\n border-radius: var(--radius) !important;\n }\n\n .rounded-md {\n border-radius: calc(var(--radius) - 2px) !important;\n }\n\n .border {\n border-style: var(--tw-border-style) !important;\n border-width: 1px !important;\n }\n\n .border-0 {\n border-style: var(--tw-border-style) !important;\n border-width: 0 !important;\n }\n\n .border-3 {\n border-style: var(--tw-border-style) !important;\n border-width: 3px !important;\n }\n\n .border-t {\n border-top-style: var(--tw-border-style) !important;\n border-top-width: 1px !important;\n }\n\n .border-b {\n border-bottom-style: var(--tw-border-style) !important;\n border-bottom-width: 1px !important;\n }\n\n .border-destructive\\/50 {\n border-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .border-destructive\\/50 {\n border-color: color-mix(in oklab, var(--destructive) 50%, transparent) !important;\n }\n }\n\n .border-input {\n border-color: var(--input) !important;\n }\n\n .border-primary {\n border-color: var(--primary) !important;\n }\n\n .bg-amber-500 {\n background-color: var(--color-amber-500) !important;\n }\n\n .bg-background, .bg-background\\/60 {\n background-color: var(--background) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-background\\/60 {\n background-color: color-mix(in oklab, var(--background) 60%, transparent) !important;\n }\n }\n\n .bg-background\\/90 {\n background-color: var(--background) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-background\\/90 {\n background-color: color-mix(in oklab, var(--background) 90%, transparent) !important;\n }\n }\n\n .bg-blue-500 {\n background-color: var(--color-blue-500) !important;\n }\n\n .bg-destructive, .bg-destructive\\/10 {\n background-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-destructive\\/10 {\n background-color: color-mix(in oklab, var(--destructive) 10%, transparent) !important;\n }\n }\n\n .bg-emerald-500 {\n background-color: var(--color-emerald-500) !important;\n }\n\n .bg-emerald-500\\/15 {\n background-color: #00bb7f26 !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-emerald-500\\/15 {\n background-color: color-mix(in oklab, var(--color-emerald-500) 15%, transparent) !important;\n }\n }\n\n .bg-indigo-500 {\n background-color: var(--color-indigo-500) !important;\n }\n\n .bg-input\\/30 {\n background-color: var(--input) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-input\\/30 {\n background-color: color-mix(in oklab, var(--input) 30%, transparent) !important;\n }\n }\n\n .bg-muted, .bg-muted\\/60 {\n background-color: var(--muted) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-muted\\/60 {\n background-color: color-mix(in oklab, var(--muted) 60%, transparent) !important;\n }\n }\n\n .bg-orange-500 {\n background-color: var(--color-orange-500) !important;\n }\n\n .bg-pink-500 {\n background-color: var(--color-pink-500) !important;\n }\n\n .bg-primary {\n background-color: var(--primary) !important;\n }\n\n .bg-purple-500 {\n background-color: var(--color-purple-500) !important;\n }\n\n .bg-red-500 {\n background-color: var(--color-red-500) !important;\n }\n\n .bg-secondary {\n background-color: var(--secondary) !important;\n }\n\n .bg-transparent {\n background-color: #0000 !important;\n }\n\n .bg-cover {\n background-size: cover !important;\n }\n\n .object-cover {\n object-fit: cover !important;\n }\n\n .p-0 {\n padding: 0 !important;\n }\n\n .p-1 {\n padding: var(--spacing) !important;\n }\n\n .p-2 {\n padding: calc(var(--spacing) * 2) !important;\n }\n\n .p-3 {\n padding: calc(var(--spacing) * 3) !important;\n }\n\n .p-4 {\n padding: calc(var(--spacing) * 4) !important;\n }\n\n .p-8 {\n padding: calc(var(--spacing) * 8) !important;\n }\n\n .px-2 {\n padding-inline: calc(var(--spacing) * 2) !important;\n }\n\n .px-3 {\n padding-inline: calc(var(--spacing) * 3) !important;\n }\n\n .px-4 {\n padding-inline: calc(var(--spacing) * 4) !important;\n }\n\n .px-6 {\n padding-inline: calc(var(--spacing) * 6) !important;\n }\n\n .py-1\\.5 {\n padding-block: calc(var(--spacing) * 1.5) !important;\n }\n\n .py-2 {\n padding-block: calc(var(--spacing) * 2) !important;\n }\n\n .py-3 {\n padding-block: calc(var(--spacing) * 3) !important;\n }\n\n .py-4 {\n padding-block: calc(var(--spacing) * 4) !important;\n }\n\n .py-6 {\n padding-block: calc(var(--spacing) * 6) !important;\n }\n\n .pt-2 {\n padding-top: calc(var(--spacing) * 2) !important;\n }\n\n .text-center {\n text-align: center !important;\n }\n\n .text-start {\n text-align: start !important;\n }\n\n .text-base {\n font-size: var(--text-base) !important;\n line-height: var(--tw-leading, var(--text-base--line-height)) !important;\n }\n\n .text-lg {\n font-size: var(--text-lg) !important;\n line-height: var(--tw-leading, var(--text-lg--line-height)) !important;\n }\n\n .text-sm {\n font-size: var(--text-sm) !important;\n line-height: var(--tw-leading, var(--text-sm--line-height)) !important;\n }\n\n .text-xs {\n font-size: var(--text-xs) !important;\n line-height: var(--tw-leading, var(--text-xs--line-height)) !important;\n }\n\n .font-medium {\n --tw-font-weight: var(--font-weight-medium) !important;\n font-weight: var(--font-weight-medium) !important;\n }\n\n .font-semibold {\n --tw-font-weight: var(--font-weight-semibold) !important;\n font-weight: var(--font-weight-semibold) !important;\n }\n\n .break-words {\n overflow-wrap: break-word !important;\n }\n\n .whitespace-normal {\n white-space: normal !important;\n }\n\n .whitespace-nowrap {\n white-space: nowrap !important;\n }\n\n .whitespace-pre-wrap {\n white-space: pre-wrap !important;\n }\n\n .text-destructive {\n color: var(--destructive) !important;\n }\n\n .text-emerald-700 {\n color: var(--color-emerald-700) !important;\n }\n\n .text-foreground {\n color: var(--foreground) !important;\n }\n\n .text-muted-foreground {\n color: var(--muted-foreground) !important;\n }\n\n .text-primary {\n color: var(--primary) !important;\n }\n\n .text-primary-foreground {\n color: var(--primary-foreground) !important;\n }\n\n .text-secondary-foreground {\n color: var(--secondary-foreground) !important;\n }\n\n .text-white {\n color: var(--color-white) !important;\n }\n\n .no-underline {\n text-decoration-line: none !important;\n }\n\n .underline {\n text-decoration-line: underline !important;\n }\n\n .underline-offset-4 {\n text-underline-offset: 4px !important;\n }\n\n .opacity-0 {\n opacity: 0 !important;\n }\n\n .opacity-20 {\n opacity: .2 !important;\n }\n\n .opacity-100 {\n opacity: 1 !important;\n }\n\n .shadow {\n --tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, #0000001a), 0 1px 2px -1px var(--tw-shadow-color, #0000001a) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .shadow-md {\n --tw-shadow: 0 4px 6px -1px var(--tw-shadow-color, #0000001a), 0 2px 4px -2px var(--tw-shadow-color, #0000001a) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .shadow-none {\n --tw-shadow: 0 0 #0000 !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .shadow-xs {\n --tw-shadow: 0 1px 2px 0 var(--tw-shadow-color, #0000000d) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .ring, .ring-1 {\n --tw-ring-shadow: var(--tw-ring-inset, ) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .ring-border {\n --tw-ring-color: var(--border) !important;\n }\n\n .outline {\n outline-style: var(--tw-outline-style) !important;\n outline-width: 1px !important;\n }\n\n .backdrop-blur-xl {\n --tw-backdrop-blur: blur(var(--blur-xl)) !important;\n -webkit-backdrop-filter: var(--tw-backdrop-blur, ) var(--tw-backdrop-brightness, ) var(--tw-backdrop-contrast, ) var(--tw-backdrop-grayscale, ) var(--tw-backdrop-hue-rotate, ) var(--tw-backdrop-invert, ) var(--tw-backdrop-opacity, ) var(--tw-backdrop-saturate, ) var(--tw-backdrop-sepia, ) !important;\n backdrop-filter: var(--tw-backdrop-blur, ) var(--tw-backdrop-brightness, ) var(--tw-backdrop-contrast, ) var(--tw-backdrop-grayscale, ) var(--tw-backdrop-hue-rotate, ) var(--tw-backdrop-invert, ) var(--tw-backdrop-opacity, ) var(--tw-backdrop-saturate, ) var(--tw-backdrop-sepia, ) !important;\n }\n\n .transition-\\[color\\,box-shadow\\] {\n transition-property: color, box-shadow !important;\n transition-timing-function: var(--tw-ease, var(--default-transition-timing-function)) !important;\n transition-duration: var(--tw-duration, var(--default-transition-duration)) !important;\n }\n\n .transition-all {\n transition-property: all !important;\n transition-timing-function: var(--tw-ease, var(--default-transition-timing-function)) !important;\n transition-duration: var(--tw-duration, var(--default-transition-duration)) !important;\n }\n\n .duration-250 {\n --tw-duration: .25s !important;\n transition-duration: .25s !important;\n }\n\n .duration-300 {\n --tw-duration: .3s !important;\n transition-duration: .3s !important;\n }\n\n .ease-out {\n --tw-ease: var(--ease-out) !important;\n transition-timing-function: var(--ease-out) !important;\n }\n\n .outline-none {\n --tw-outline-style: none !important;\n outline-style: none !important;\n }\n\n .running {\n animation-play-state: running !important;\n }\n\n .group-\\[\\.is-assistant\\]\\:bg-secondary:is(:where(.group).is-assistant *) {\n background-color: var(--secondary) !important;\n }\n\n .group-\\[\\.is-assistant\\]\\:text-foreground:is(:where(.group).is-assistant *) {\n color: var(--foreground) !important;\n }\n\n .group-\\[\\.is-user\\]\\:max-w-\\[80\\%\\]:is(:where(.group).is-user *) {\n max-width: 80% !important;\n }\n\n .group-\\[\\.is-user\\]\\:bg-primary:is(:where(.group).is-user *) {\n background-color: var(--primary) !important;\n }\n\n .group-\\[\\.is-user\\]\\:bg-secondary:is(:where(.group).is-user *) {\n background-color: var(--secondary) !important;\n }\n\n .group-\\[\\.is-user\\]\\:px-4:is(:where(.group).is-user *) {\n padding-inline: calc(var(--spacing) * 4) !important;\n }\n\n .group-\\[\\.is-user\\]\\:py-3:is(:where(.group).is-user *) {\n padding-block: calc(var(--spacing) * 3) !important;\n }\n\n .group-\\[\\.is-user\\]\\:text-foreground:is(:where(.group).is-user *) {\n color: var(--foreground) !important;\n }\n\n .group-\\[\\.is-user\\]\\:text-primary-foreground:is(:where(.group).is-user *) {\n color: var(--primary-foreground) !important;\n }\n\n .placeholder\\:text-muted-foreground::placeholder {\n color: var(--muted-foreground) !important;\n }\n\n .focus-within\\:ring-1:focus-within {\n --tw-ring-shadow: var(--tw-ring-inset, ) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .focus-within\\:ring-ring:focus-within {\n --tw-ring-color: var(--ring) !important;\n }\n\n @media (hover: hover) {\n .hover\\:bg-accent:hover {\n background-color: var(--accent) !important;\n }\n\n .hover\\:bg-destructive\\/90:hover {\n background-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .hover\\:bg-destructive\\/90:hover {\n background-color: color-mix(in oklab, var(--destructive) 90%, transparent) !important;\n }\n }\n\n .hover\\:bg-primary\\/90:hover {\n background-color: var(--primary) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .hover\\:bg-primary\\/90:hover {\n background-color: color-mix(in oklab, var(--primary) 90%, transparent) !important;\n }\n }\n\n .hover\\:bg-secondary\\/80:hover {\n background-color: var(--secondary) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .hover\\:bg-secondary\\/80:hover {\n background-color: color-mix(in oklab, var(--secondary) 80%, transparent) !important;\n }\n }\n\n .hover\\:text-accent-foreground:hover {\n color: var(--accent-foreground) !important;\n }\n\n .hover\\:underline:hover {\n text-decoration-line: underline !important;\n }\n\n .hover\\:shadow-lg:hover {\n --tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, #0000001a), 0 4px 6px -4px var(--tw-shadow-color, #0000001a) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .hover\\:shadow-black\\/30:hover {\n --tw-shadow-color: #0000004d !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .hover\\:shadow-black\\/30:hover {\n --tw-shadow-color: color-mix(in oklab, color-mix(in oklab, var(--color-black) 30%, transparent) var(--tw-shadow-alpha), transparent) !important;\n }\n }\n }\n\n .focus-visible\\:border-ring:focus-visible {\n border-color: var(--ring) !important;\n }\n\n .focus-visible\\:ring-0:focus-visible {\n --tw-ring-shadow: var(--tw-ring-inset, ) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .focus-visible\\:ring-\\[3px\\]:focus-visible {\n --tw-ring-shadow: var(--tw-ring-inset, ) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor) !important;\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow) !important;\n }\n\n .focus-visible\\:ring-destructive\\/20:focus-visible {\n --tw-ring-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .focus-visible\\:ring-destructive\\/20:focus-visible {\n --tw-ring-color: color-mix(in oklab, var(--destructive) 20%, transparent) !important;\n }\n }\n\n .focus-visible\\:ring-ring:focus-visible, .focus-visible\\:ring-ring\\/50:focus-visible {\n --tw-ring-color: var(--ring) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .focus-visible\\:ring-ring\\/50:focus-visible {\n --tw-ring-color: color-mix(in oklab, var(--ring) 50%, transparent) !important;\n }\n }\n\n .focus-visible\\:outline-none:focus-visible {\n --tw-outline-style: none !important;\n outline-style: none !important;\n }\n\n .disabled\\:pointer-events-none:disabled {\n pointer-events: none !important;\n }\n\n .disabled\\:cursor-not-allowed:disabled {\n cursor: not-allowed !important;\n }\n\n .disabled\\:opacity-50:disabled {\n opacity: .5 !important;\n }\n\n .has-\\[\\>svg\\]\\:px-2\\.5:has( > svg) {\n padding-inline: calc(var(--spacing) * 2.5) !important;\n }\n\n .has-\\[\\>svg\\]\\:px-3:has( > svg) {\n padding-inline: calc(var(--spacing) * 3) !important;\n }\n\n .has-\\[\\>svg\\]\\:px-4:has( > svg) {\n padding-inline: calc(var(--spacing) * 4) !important;\n }\n\n .aria-invalid\\:border-destructive[aria-invalid=\"true\"] {\n border-color: var(--destructive) !important;\n }\n\n .aria-invalid\\:ring-destructive\\/20[aria-invalid=\"true\"] {\n --tw-ring-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .aria-invalid\\:ring-destructive\\/20[aria-invalid=\"true\"] {\n --tw-ring-color: color-mix(in oklab, var(--destructive) 20%, transparent) !important;\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .motion-reduce\\:animate-none {\n animation: none !important;\n }\n }\n\n @media (min-width: 40rem) {\n .sm\\:absolute {\n position: absolute !important;\n }\n\n .sm\\:inset-auto {\n inset: auto !important;\n }\n\n .sm\\:right-0 {\n right: 0 !important;\n }\n\n .sm\\:bottom-\\[calc\\(100\\%\\+10px\\)\\] {\n bottom: calc(100% + 10px) !important;\n }\n\n .sm\\:left-0 {\n left: 0 !important;\n }\n\n .sm\\:h-\\[80vh\\] {\n height: 80vh !important;\n }\n\n .sm\\:h-full {\n height: 100% !important;\n }\n\n .sm\\:max-h-\\[500px\\] {\n max-height: 500px !important;\n }\n\n .sm\\:max-h-\\[600px\\] {\n max-height: 600px !important;\n }\n\n .sm\\:max-h-\\[700px\\] {\n max-height: 700px !important;\n }\n\n .sm\\:max-h-\\[800px\\] {\n max-height: 800px !important;\n }\n\n .sm\\:w-\\[90vw\\] {\n width: 90vw !important;\n }\n\n .sm\\:w-full {\n width: 100% !important;\n }\n\n .sm\\:max-w-lg {\n max-width: var(--container-lg) !important;\n }\n\n .sm\\:max-w-md {\n max-width: var(--container-md) !important;\n }\n\n .sm\\:max-w-sm {\n max-width: var(--container-sm) !important;\n }\n\n .sm\\:max-w-xl {\n max-width: var(--container-xl) !important;\n }\n\n .sm\\:translate-y-5 {\n --tw-translate-y: calc(var(--spacing) * 5) !important;\n translate: var(--tw-translate-x) var(--tw-translate-y) !important;\n }\n\n .sm\\:rounded-lg {\n border-radius: var(--radius) !important;\n }\n }\n\n @media (min-width: 48rem) {\n .md\\:text-sm {\n font-size: var(--text-sm) !important;\n line-height: var(--tw-leading, var(--text-sm--line-height)) !important;\n }\n }\n\n @media (prefers-color-scheme: dark) {\n .dark\\:border-input {\n border-color: var(--input) !important;\n }\n\n .dark\\:bg-destructive\\/60 {\n background-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .dark\\:bg-destructive\\/60 {\n background-color: color-mix(in oklab, var(--destructive) 60%, transparent) !important;\n }\n }\n\n .dark\\:bg-input\\/30 {\n background-color: var(--input) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .dark\\:bg-input\\/30 {\n background-color: color-mix(in oklab, var(--input) 30%, transparent) !important;\n }\n }\n\n .dark\\:bg-transparent {\n background-color: #0000 !important;\n }\n\n .dark\\:text-emerald-300 {\n color: var(--color-emerald-300) !important;\n }\n\n .dark\\:prose-invert {\n --tw-prose-body: var(--tw-prose-invert-body) !important;\n --tw-prose-headings: var(--tw-prose-invert-headings) !important;\n --tw-prose-lead: var(--tw-prose-invert-lead) !important;\n --tw-prose-links: var(--tw-prose-invert-links) !important;\n --tw-prose-bold: var(--tw-prose-invert-bold) !important;\n --tw-prose-counters: var(--tw-prose-invert-counters) !important;\n --tw-prose-bullets: var(--tw-prose-invert-bullets) !important;\n --tw-prose-hr: var(--tw-prose-invert-hr) !important;\n --tw-prose-quotes: var(--tw-prose-invert-quotes) !important;\n --tw-prose-quote-borders: var(--tw-prose-invert-quote-borders) !important;\n --tw-prose-captions: var(--tw-prose-invert-captions) !important;\n --tw-prose-kbd: var(--tw-prose-invert-kbd) !important;\n --tw-prose-kbd-shadows: var(--tw-prose-invert-kbd-shadows) !important;\n --tw-prose-code: var(--tw-prose-invert-code) !important;\n --tw-prose-pre-code: var(--tw-prose-invert-pre-code) !important;\n --tw-prose-pre-bg: var(--tw-prose-invert-pre-bg) !important;\n --tw-prose-th-borders: var(--tw-prose-invert-th-borders) !important;\n --tw-prose-td-borders: var(--tw-prose-invert-td-borders) !important;\n }\n\n @media (hover: hover) {\n .dark\\:hover\\:bg-accent\\/50:hover {\n background-color: var(--accent) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .dark\\:hover\\:bg-accent\\/50:hover {\n background-color: color-mix(in oklab, var(--accent) 50%, transparent) !important;\n }\n }\n\n .dark\\:hover\\:bg-input\\/50:hover {\n background-color: var(--input) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .dark\\:hover\\:bg-input\\/50:hover {\n background-color: color-mix(in oklab, var(--input) 50%, transparent) !important;\n }\n }\n }\n\n .dark\\:focus-visible\\:ring-destructive\\/40:focus-visible {\n --tw-ring-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .dark\\:focus-visible\\:ring-destructive\\/40:focus-visible {\n --tw-ring-color: color-mix(in oklab, var(--destructive) 40%, transparent) !important;\n }\n }\n\n .dark\\:aria-invalid\\:ring-destructive\\/40[aria-invalid=\"true\"] {\n --tw-ring-color: var(--destructive) !important;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .dark\\:aria-invalid\\:ring-destructive\\/40[aria-invalid=\"true\"] {\n --tw-ring-color: color-mix(in oklab, var(--destructive) 40%, transparent) !important;\n }\n }\n }\n\n .\\[\\&_svg\\]\\:pointer-events-none svg {\n pointer-events: none !important;\n }\n\n .\\[\\&_svg\\]\\:shrink-0 svg {\n flex-shrink: 0 !important;\n }\n\n .\\[\\&_svg\\:not\\(\\[class\\*\\=\\'size-\\'\\]\\)\\]\\:size-4 svg:not([class*=\"size-\"]) {\n width: calc(var(--spacing) * 4) !important;\n height: calc(var(--spacing) * 4) !important;\n }\n}\n\n@property --tw-animation-delay {\n syntax: \"*\";\n inherits: false;\n initial-value: 0s;\n}\n\n@property --tw-animation-direction {\n syntax: \"*\";\n inherits: false;\n initial-value: normal;\n}\n\n@property --tw-animation-duration {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-animation-fill-mode {\n syntax: \"*\";\n inherits: false;\n initial-value: none;\n}\n\n@property --tw-animation-iteration-count {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-enter-blur {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-enter-opacity {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-enter-rotate {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-enter-scale {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-enter-translate-x {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-enter-translate-y {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-exit-blur {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-exit-opacity {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-exit-rotate {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-exit-scale {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-exit-translate-x {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-exit-translate-y {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n:host {\n all: initial;\n box-sizing: border-box;\n direction: rtl;\n font-family: Tahoma, Arial, sans-serif;\n font-size: 16px;\n line-height: 1.5;\n display: block;\n}\n\n.luma-assistant-widget-root {\n background-color: var(--color-white);\n}\n\n@media (prefers-color-scheme: dark) {\n .luma-assistant-widget-root {\n background-color: var(--color-neutral-950);\n }\n}\n\n.luma-assistant-widget-root {\n font-family: Tahoma, Arial, sans-serif;\n}\n\n@media (prefers-color-scheme: dark) {\n .luma-assistant-widget-root {\n color-scheme: dark;\n }\n}\n\n.luma-assistant-widget-wrapper {\n color-scheme: light dark;\n font-synthesis: none;\n text-rendering: optimizelegibility;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n --radius: .625rem;\n --background: oklch(100% 0 0);\n --foreground: oklch(14.5% 0 0);\n --card: oklch(100% 0 0);\n --card-foreground: oklch(14.5% 0 0);\n --popover: oklch(100% 0 0);\n --popover-foreground: oklch(14.5% 0 0);\n --primary: oklch(20.5% 0 0);\n --primary-foreground: oklch(98.5% 0 0);\n --secondary: oklch(97% 0 0);\n --secondary-foreground: oklch(20.5% 0 0);\n --muted: oklch(97% 0 0);\n --muted-foreground: oklch(55.6% 0 0);\n --accent: oklch(97% 0 0);\n --accent-foreground: oklch(20.5% 0 0);\n --destructive: oklch(57.7% .245 27.325);\n --border: oklch(92.2% 0 0);\n --input: oklch(92.2% 0 0);\n --ring: oklch(70.8% 0 0);\n --chart-1: oklch(64.6% .222 41.116);\n --chart-2: oklch(60% .118 184.704);\n --chart-3: oklch(39.8% .07 227.392);\n --chart-4: oklch(82.8% .189 84.429);\n --chart-5: oklch(76.9% .188 70.08);\n --sidebar: oklch(98.5% 0 0);\n --sidebar-foreground: oklch(14.5% 0 0);\n --sidebar-primary: oklch(20.5% 0 0);\n --sidebar-primary-foreground: oklch(98.5% 0 0);\n --sidebar-accent: oklch(97% 0 0);\n --sidebar-accent-foreground: oklch(20.5% 0 0);\n --sidebar-border: oklch(92.2% 0 0);\n --sidebar-ring: oklch(70.8% 0 0);\n --spacing: 4px;\n --container-sm: 384px;\n --container-md: 448px;\n --container-lg: 512px;\n --container-xl: 576px;\n --text-xs: 12px;\n --text-xs--line-height: 16px;\n --text-sm: 14px;\n --text-sm--line-height: 20px;\n --text-base: 16px;\n --text-base--line-height: 24px;\n --text-lg: 18px;\n --text-lg--line-height: 28px;\n --text-xl: 20px;\n --text-xl--line-height: 28px;\n --text-2xl: 24px;\n --text-2xl--line-height: 32px;\n font-family: inherit;\n font-weight: 400;\n line-height: 1.5;\n}\n\n.dark {\n --background: oklch(14.5% 0 0);\n --foreground: oklch(98.5% 0 0);\n --card: oklch(20.5% 0 0);\n --card-foreground: oklch(98.5% 0 0);\n --popover: oklch(20.5% 0 0);\n --popover-foreground: oklch(98.5% 0 0);\n --primary: oklch(92.2% 0 0);\n --primary-foreground: oklch(20.5% 0 0);\n --secondary: oklch(26.9% 0 0);\n --secondary-foreground: oklch(98.5% 0 0);\n --muted: oklch(26.9% 0 0);\n --muted-foreground: oklch(70.8% 0 0);\n --accent: oklch(26.9% 0 0);\n --accent-foreground: oklch(98.5% 0 0);\n --destructive: oklch(70.4% .191 22.216);\n --border: oklch(100% 0 0 / .1);\n --input: oklch(100% 0 0 / .15);\n --ring: oklch(55.6% 0 0);\n --chart-1: oklch(48.8% .243 264.376);\n --chart-2: oklch(69.6% .17 162.48);\n --chart-3: oklch(76.9% .188 70.08);\n --chart-4: oklch(62.7% .265 303.9);\n --chart-5: oklch(64.5% .246 16.439);\n --sidebar: oklch(20.5% 0 0);\n --sidebar-foreground: oklch(98.5% 0 0);\n --sidebar-primary: oklch(48.8% .243 264.376);\n --sidebar-primary-foreground: oklch(98.5% 0 0);\n --sidebar-accent: oklch(26.9% 0 0);\n --sidebar-accent-foreground: oklch(98.5% 0 0);\n --sidebar-border: oklch(100% 0 0 / .1);\n --sidebar-ring: oklch(55.6% 0 0);\n}\n\n.luma-assistant-widget-wrapper *, .luma-assistant-widget-wrapper :before, .luma-assistant-widget-wrapper :after {\n border-color: var(--border) !important;\n outline-color: var(--ring) !important;\n}\n\n@supports (color: color-mix(in lab, red, red)) {\n .luma-assistant-widget-wrapper *, .luma-assistant-widget-wrapper :before, .luma-assistant-widget-wrapper :after {\n outline-color: color-mix(in oklch, var(--ring) 50%, transparent) !important;\n }\n}\n\n.luma-markdown pre {\n text-align: left;\n background: var(--muted);\n direction: ltr;\n border-radius: 6px;\n padding: 12px;\n overflow-x: auto;\n}\n\n.luma-markdown table {\n display: block;\n overflow-x: auto;\n}\n\n.luma-markdown td, .luma-markdown th {\n border: 1px solid var(--border);\n padding: 6px;\n}\n\n.luma-guide-layer {\n z-index: 2147483646;\n pointer-events: none;\n position: fixed;\n inset: 0;\n}\n\n.luma-guide-ring {\n border: 3px solid var(--primary);\n pointer-events: none;\n box-shadow: 0 0 0 4px var(--primary);\n border-radius: 8px;\n position: fixed;\n}\n\n@supports (color: color-mix(in lab, red, red)) {\n .luma-guide-ring {\n box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);\n }\n}\n\n.luma-guide-popover {\n border: 1px solid var(--border);\n background: var(--background);\n width: min(320px, 100vw - 32px);\n max-height: calc(100dvh - 32px);\n color: var(--foreground);\n pointer-events: auto;\n border-radius: 12px;\n flex-direction: column;\n gap: 12px;\n padding: 16px;\n display: flex;\n position: fixed;\n overflow: auto;\n box-shadow: 0 8px 30px #0003;\n}\n\n@property --tw-translate-x {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-translate-y {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-translate-z {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-scale-x {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-scale-y {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-scale-z {\n syntax: \"*\";\n inherits: false;\n initial-value: 1;\n}\n\n@property --tw-rotate-x {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-rotate-y {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-rotate-z {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-skew-x {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-skew-y {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-space-y-reverse {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-border-style {\n syntax: \"*\";\n inherits: false;\n initial-value: solid;\n}\n\n@property --tw-font-weight {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-shadow-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-shadow-alpha {\n syntax: \"<percentage>\";\n inherits: false;\n initial-value: 100%;\n}\n\n@property --tw-inset-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-inset-shadow-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-inset-shadow-alpha {\n syntax: \"<percentage>\";\n inherits: false;\n initial-value: 100%;\n}\n\n@property --tw-ring-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-ring-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-inset-ring-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-inset-ring-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-ring-inset {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-ring-offset-width {\n syntax: \"<length>\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-ring-offset-color {\n syntax: \"*\";\n inherits: false;\n initial-value: #fff;\n}\n\n@property --tw-ring-offset-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-outline-style {\n syntax: \"*\";\n inherits: false;\n initial-value: solid;\n}\n\n@property --tw-backdrop-blur {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-brightness {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-contrast {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-grayscale {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-hue-rotate {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-invert {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-opacity {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-saturate {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-backdrop-sepia {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-duration {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-ease {\n syntax: \"*\";\n inherits: false\n}\n\n@keyframes spin {\n to {\n transform: rotate(360deg);\n }\n}\n";
20
+ //#endregion
21
+ //#region ../assistant-contract/src/site.ts
22
+ var siteToolNames = [
23
+ "siteInfo",
24
+ "searchSite",
25
+ "searchProducts",
26
+ "getProduct",
27
+ "inspectPage",
28
+ "showGuide",
29
+ "navigate",
30
+ "runAction"
31
+ ];
32
+ var text = z.string().trim().max(300);
33
+ var guideStep = z.object({
34
+ targetId: text.min(1),
35
+ title: text.min(1),
36
+ description: z.string().trim().min(1).max(1200),
37
+ completion: z.enum([
38
+ "next",
39
+ "click",
40
+ "change",
41
+ "expanded"
42
+ ]),
43
+ expectedTargetId: text.nullable().optional().describe("Another observed element to verify, or null when no additional target is needed.")
44
+ });
45
+ var siteToolInputs = {
46
+ siteInfo: z.object({}),
47
+ searchSite: z.object({
48
+ query: text,
49
+ page: z.number().int().min(1).max(1e3).default(1)
50
+ }),
51
+ searchProducts: z.object({
52
+ query: text,
53
+ minPrice: z.number().nonnegative().nullable().optional().describe("Minimum price in store currency, or null when no minimum was requested."),
54
+ maxPrice: z.number().nonnegative().nullable().optional().describe("Maximum price in store currency, or null when no budget was requested. Zero means free products only."),
55
+ category: text.nullable().optional().describe("Known category slug, or null for all categories."),
56
+ inStock: z.boolean().default(true),
57
+ page: z.number().int().min(1).max(1e3).default(1)
58
+ }),
59
+ getProduct: z.object({ productId: z.union([z.number().int().positive(), text.min(1)]) }),
60
+ inspectPage: z.object({ query: text.default("") }),
61
+ showGuide: guideStep,
62
+ navigate: z.object({
63
+ destinationId: text.min(1),
64
+ explanation: z.string().trim().min(1).max(600)
65
+ }),
66
+ runAction: z.object({
67
+ action: text.min(1),
68
+ input: z.record(z.string(), z.unknown()),
69
+ explanation: z.string().trim().min(1).max(600)
70
+ })
71
+ };
72
+ var siteActionNamePattern = /^[A-Za-z][\w-]{0,63}$/;
73
+ var siteActionSchema = z.object({
74
+ name: z.string().regex(siteActionNamePattern),
75
+ description: z.string().trim().min(1).max(500),
76
+ input: z.record(z.string(), z.unknown()).refine((value) => JSON.stringify(value).length <= 4e3, "Schema too large"),
77
+ confirm: z.boolean()
78
+ });
79
+ var pageElementSchema = z.object({
80
+ id: text,
81
+ label: text,
82
+ role: text,
83
+ href: z.string().max(2048).optional(),
84
+ expanded: z.boolean().optional(),
85
+ options: z.array(text).max(30).optional()
86
+ });
87
+ z.object({
88
+ url: z.string().max(2048),
89
+ title: text,
90
+ revision: text,
91
+ elements: z.array(pageElementSchema).max(100),
92
+ restricted: z.boolean().optional(),
93
+ appContext: z.record(z.string(), z.unknown()).optional()
94
+ });
95
+ /** showGuide input for sites announcing the guideTour feature. */
96
+ var guideTourInput = z.object({ steps: z.array(guideStep).min(1).max(8).describe("Ordered steps shown in sequence on the current page without returning to you between them.") });
97
+ /** Accepts tour input and the single-step input of older servers. */
98
+ function guideSteps(input) {
99
+ const tour = guideTourInput.safeParse(input);
100
+ if (tour.success) return tour.data.steps;
101
+ const step = guideStep.safeParse(input);
102
+ return step.success ? [step.data] : null;
103
+ }
104
+ var siteFeatures = ["guideTour"];
105
+ var SITE_CONTEXT_MAX_LENGTH = 24e3;
106
+ var siteContextSchema = z.object({
107
+ version: z.literal(1),
108
+ origin: z.url().max(2048),
109
+ capabilities: z.array(z.enum(siteToolNames)).max(12),
110
+ features: z.array(z.enum(siteFeatures)).max(8).optional(),
111
+ actions: z.array(siteActionSchema).max(20).optional()
112
+ }).refine((value) => JSON.stringify(value).length <= SITE_CONTEXT_MAX_LENGTH, "Site context too large").refine((value) => new Set(value.actions?.map((action) => action.name)).size === (value.actions?.length ?? 0), "Duplicate action names");
113
+ var siteToolOutputSchema = z.object({
114
+ status: z.enum([
115
+ "ok",
116
+ "completed",
117
+ "cancelled",
118
+ "unavailable",
119
+ "navigated",
120
+ "error"
121
+ ]),
122
+ data: z.unknown().optional(),
123
+ message: z.string().max(1200).optional()
124
+ }).refine((value) => JSON.stringify(value).length <= 48e3, "Tool output too large");
125
+ z.object({
126
+ messageId: z.string().max(100),
127
+ results: z.array(z.object({
128
+ toolCallId: z.string().max(200),
129
+ output: siteToolOutputSchema
130
+ })).min(1).max(8)
131
+ });
132
+ //#endregion
133
+ //#region src/core/actions.ts
134
+ /**
135
+ * Define an action once and share it between the server handler (which declares it to the
136
+ * assistant) and the page component that runs it with useLumaAction.
137
+ */
138
+ function defineAction(definition) {
139
+ if (!siteActionNamePattern.test(definition.name)) throw new Error(`Invalid Luma action name "${definition.name}". Use letters, digits, "_" or "-", starting with a letter.`);
140
+ return {
141
+ ...definition,
142
+ confirm: definition.confirm ?? true
143
+ };
144
+ }
145
+ /** The serializable declaration the assistant receives. */
146
+ function actionContract(definition) {
147
+ const { $schema: _, ...input } = z.toJSONSchema(definition.input, { unrepresentable: "any" });
148
+ return siteActionSchema.parse({
149
+ name: definition.name,
150
+ description: definition.description,
151
+ input,
152
+ confirm: definition.confirm
153
+ });
154
+ }
155
+ //#endregion
156
+ //#region src/core/config.ts
157
+ var API_BASE_URLS = {
158
+ internal: "https://ir.lumai.ir/api",
159
+ direct: "https://dash.lumai.ir/api"
160
+ };
161
+ function parseSession(value) {
162
+ const raw = value && typeof value === "object" && "data" in value && !("sessionId" in value) ? value.data : value;
163
+ if (!raw || typeof raw !== "object" || !("sessionId" in raw) || typeof raw.sessionId !== "string" || !raw.sessionId.trim()) throw new Error("Invalid session response");
164
+ const data = raw;
165
+ const site = siteContextSchema.safeParse(data.siteContext);
166
+ return {
167
+ sessionId: raw.sessionId,
168
+ name: typeof data.name === "string" ? data.name : "دستیار هوشمند",
169
+ color: typeof data.color === "string" ? data.color : "blue",
170
+ avatar: typeof data.avatar === "string" && /^https?:\/\//.test(data.avatar) ? data.avatar : void 0,
171
+ ...typeof data.assistantId === "string" ? { assistantId: data.assistantId } : {},
172
+ ...typeof data.chatEndpoint === "string" && /^(https?:\/\/|\/)/.test(data.chatEndpoint) ? { chatEndpoint: data.chatEndpoint } : {},
173
+ ...site.success ? { siteContext: site.data } : {}
174
+ };
175
+ }
176
+ //#endregion
177
+ //#region src/core/diagnostics.ts
178
+ var docs = "https://dash.lumai.ir/docs/react/troubleshooting";
179
+ var reported = /* @__PURE__ */ new Set();
180
+ /**
181
+ * Logs a problem the site developer (or their coding agent) can fix, once per message.
182
+ * Codes are stable and documented on the troubleshooting page.
183
+ */
184
+ function report(code, message, level = "error") {
185
+ const text = `[@luma-ai/react] ${code}: ${message} See ${docs}#${code.toLowerCase()}`;
186
+ if (reported.has(text)) return;
187
+ reported.add(text);
188
+ console[level](text);
189
+ }
190
+ /** A failed session request, with the documented code that explains it. */
191
+ var SessionError = class extends Error {
192
+ code;
193
+ status;
194
+ constructor(code, status, message) {
195
+ super(message);
196
+ this.name = "SessionError";
197
+ this.code = code;
198
+ this.status = status;
199
+ }
200
+ };
201
+ var defaultPolicy = {
202
+ restrictedPaths: [],
203
+ blockedPaths: [/\/(?:logout|log-out|signout|sign-out)(?:\/|$)/i],
204
+ blockedParams: [
205
+ "token",
206
+ "access_token",
207
+ "password",
208
+ "nonce",
209
+ "logout",
210
+ "key"
211
+ ],
212
+ privateSelector: [
213
+ "[data-luma-widget]",
214
+ "[data-luma-private]",
215
+ "[hidden]",
216
+ "[inert]",
217
+ "[aria-hidden=\"true\"]",
218
+ "[contenteditable]:not([contenteditable=\"false\"])",
219
+ "textarea"
220
+ ].join(",")
221
+ };
222
+ /** A string matches that path and everything below it, e.g. "/admin". */
223
+ function pathPattern(value) {
224
+ if (value instanceof RegExp) return value;
225
+ const path = value.replace(/\/+$/, "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
226
+ return new RegExp(`^${path}(?:/|$)`, "i");
227
+ }
228
+ function extendPolicy(base, extra) {
229
+ return {
230
+ restrictedPaths: [...base.restrictedPaths, ...(extra.restrictedPaths ?? []).map(pathPattern)],
231
+ blockedPaths: [...base.blockedPaths, ...(extra.blockedPaths ?? []).map(pathPattern)],
232
+ blockedParams: [...base.blockedParams, ...extra.blockedParams ?? []],
233
+ privateSelector: [base.privateSelector, ...extra.privateSelectors ?? []].filter(Boolean).join(",")
234
+ };
235
+ }
236
+ function decodedPath(pathname) {
237
+ try {
238
+ return decodeURIComponent(pathname);
239
+ } catch {
240
+ return pathname;
241
+ }
242
+ }
243
+ function isRestrictedPath(pathname, policy) {
244
+ const path = decodedPath(pathname);
245
+ return policy.restrictedPaths.some((pattern) => pattern.test(path));
246
+ }
247
+ function safeDestination(raw, base = location.href, policy = defaultPolicy) {
248
+ try {
249
+ const url = new URL(raw, base), source = new URL(base);
250
+ const path = decodedPath(url.pathname);
251
+ if (!["http:", "https:"].includes(url.protocol) || url.origin !== source.origin || url.username || url.password || isRestrictedPath(url.pathname, policy) || policy.blockedPaths.some((pattern) => pattern.test(path)) || policy.blockedParams.some((key) => url.searchParams.has(key))) return null;
252
+ return url.href;
253
+ } catch {
254
+ return null;
255
+ }
256
+ }
257
+ //#endregion
258
+ //#region src/core/data-sources.ts
259
+ var pageSize = 12;
260
+ var normalizeText = (s) => s.replaceAll("ي", "ی").replaceAll("ك", "ک").replaceAll("‌", " ").toLocaleLowerCase();
261
+ /** Short stable IDs keep model context small while surviving reloads. */
262
+ function urlId(prefix, url) {
263
+ let hash = 2166136261;
264
+ for (let i = 0; i < url.length; i++) hash = Math.imul(hash ^ url.charCodeAt(i), 16777619);
265
+ return `${prefix}:${(hash >>> 0).toString(36)}`;
266
+ }
267
+ function links(value, policy) {
268
+ if (!Array.isArray(value)) return [];
269
+ return value.flatMap((item) => {
270
+ const url = item && typeof item.url === "string" ? safeDestination(item.url, location.href, policy) : null;
271
+ if (!url || typeof item.title !== "string") return [];
272
+ return [{
273
+ id: typeof item.id === "string" ? item.id.slice(0, 200) : urlId("page", url),
274
+ title: item.title.slice(0, 300),
275
+ url,
276
+ ...typeof item.description === "string" ? { description: item.description.slice(0, 600) } : {}
277
+ }];
278
+ });
279
+ }
280
+ function product(value, policy) {
281
+ if (!value || typeof value.productId !== "number" && typeof value.productId !== "string" || typeof value.title !== "string") return null;
282
+ const url = typeof value.url === "string" ? safeDestination(value.url, location.href, policy) : null;
283
+ return {
284
+ ...value,
285
+ id: value.id ?? `product:${value.productId}`,
286
+ title: value.title.slice(0, 300),
287
+ url: url ?? "",
288
+ image: typeof value.image === "string" ? new URL(value.image, location.href).href : null,
289
+ price: String(value.price ?? ""),
290
+ currency: value.currency ?? "",
291
+ inStock: value.inStock !== false,
292
+ type: value.type ?? "simple",
293
+ attributes: value.attributes ?? {}
294
+ };
295
+ }
296
+ /** Which lookup tools this site can serve. */
297
+ function sourceCapabilities(sources) {
298
+ const site = sources?.site;
299
+ const caps = [];
300
+ if (sources?.searchSite || typeof site === "function" || site && Array.isArray(site.pages) && site.pages.length) caps.push("searchSite");
301
+ if (sources?.searchProducts) caps.push("searchProducts");
302
+ if (sources?.getProduct) caps.push("getProduct");
303
+ return caps;
304
+ }
305
+ async function siteInfo(sources, context) {
306
+ return typeof sources.site === "function" ? await sources.site(context) : sources.site ?? {};
307
+ }
308
+ /** Run one read-only lookup and return bounded, link-safe data for the model. */
309
+ async function runDataSource(name, input, sources, context, policy, capabilities) {
310
+ const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
311
+ if (name === "siteInfo") {
312
+ const { menus, pages, ...info } = await siteInfo(sources, context);
313
+ const listing = pages;
314
+ const directory = Array.isArray(pages) ? links(pages, policy) : links(listing?.items, policy);
315
+ return {
316
+ ...info,
317
+ name: info.name ?? document.title,
318
+ language: info.language ?? document.documentElement.lang,
319
+ home: location.origin,
320
+ capabilities,
321
+ menus: links(menus, policy).slice(0, 60),
322
+ pages: {
323
+ items: directory.slice(0, pageSize),
324
+ page: 1,
325
+ hasMore: directory.length > pageSize || listing?.hasMore === true
326
+ },
327
+ commerce: info.commerce ?? (sources.searchProducts ? "custom" : null),
328
+ freshness: "live",
329
+ checkedAt
330
+ };
331
+ }
332
+ if (name === "searchSite") {
333
+ const { query, page } = input;
334
+ if (sources.searchSite) {
335
+ const { items, ...result } = await sources.searchSite({
336
+ query,
337
+ page
338
+ }, context);
339
+ return {
340
+ ...result,
341
+ items: links(items, policy).slice(0, pageSize),
342
+ page,
343
+ hasMore: Boolean(result.hasMore),
344
+ checkedAt
345
+ };
346
+ }
347
+ const info = await siteInfo(sources, context);
348
+ const words = normalizeText(query).split(/\s+/).filter(Boolean);
349
+ const ranked = links(info.pages, policy).map((item) => {
350
+ const text = normalizeText(`${item.title} ${item.description ?? ""} ${item.url}`);
351
+ return {
352
+ item,
353
+ score: words.filter((w) => text.includes(w)).length
354
+ };
355
+ }).filter(({ score }) => score > 0 || !words.length).sort((a, b) => b.score - a.score).map(({ item }) => item);
356
+ return {
357
+ items: ranked.slice((page - 1) * pageSize, page * pageSize),
358
+ page,
359
+ hasMore: ranked.length > page * pageSize,
360
+ checkedAt
361
+ };
362
+ }
363
+ if (name === "searchProducts") {
364
+ const { items, ...result } = await sources.searchProducts(input, context);
365
+ return {
366
+ ...result,
367
+ items: (items ?? []).slice(0, 8).map((item) => product(item, policy)).filter(Boolean),
368
+ page: input.page,
369
+ hasMore: Boolean(result.hasMore),
370
+ checkedAt
371
+ };
372
+ }
373
+ const found = await sources.getProduct(input, context);
374
+ const normalized = found && product(found, policy);
375
+ if (!normalized) throw new Error("Product unavailable");
376
+ return normalized;
377
+ }
378
+ //#endregion
379
+ //#region src/core/site-runtime.ts
380
+ function storageRead(key) {
381
+ try {
382
+ return JSON.parse(sessionStorage.getItem(key) ?? "null");
383
+ } catch {
384
+ return null;
385
+ }
386
+ }
387
+ function storageWrite(key, value) {
388
+ try {
389
+ sessionStorage.setItem(key, JSON.stringify(value));
390
+ } catch {}
391
+ }
392
+ function publicText(el, privateRegion) {
393
+ if (!el || el.closest(privateRegion) || el.matches("input,script,style")) return "";
394
+ for (let parent = el; parent; parent = parent.parentElement) {
395
+ const style = getComputedStyle(parent);
396
+ if (style.display === "none" || style.visibility === "hidden") return "";
397
+ }
398
+ return Array.from(el.childNodes, (node) => node instanceof Element ? publicText(node, privateRegion) : node.nodeType === Node.TEXT_NODE ? node.textContent ?? "" : "").join("");
399
+ }
400
+ var label = (el, privateRegion) => (el.getAttribute("data-luma-label") || el.getAttribute("aria-label") || (el.getAttribute("aria-labelledby") ?? "").split(/\s+/).map((id) => publicText(document.getElementById(id), privateRegion)).join(" ").trim() || (el instanceof HTMLInputElement || el instanceof HTMLSelectElement ? Array.from(el.labels ?? []).map((l) => publicText(l, privateRegion)).join(" ") : "") || (el instanceof HTMLInputElement ? el.getAttribute("placeholder") : publicText(el, privateRegion)) || el.getAttribute("title") || "").replace(/\s+/g, " ").trim().slice(0, 180);
401
+ function observable(el, privateRegion = defaultPolicy.privateSelector) {
402
+ if (!(el instanceof HTMLElement) || !el.isConnected || el.closest(privateRegion)) return false;
403
+ if (el.matches("input[type=\"hidden\"],textarea,[contenteditable=\"true\"]")) return false;
404
+ const style = getComputedStyle(el), rect = el.getBoundingClientRect();
405
+ return style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;
406
+ }
407
+ var APP_CONTEXT_MAX_LENGTH = 8e3;
408
+ var lookupTools = [
409
+ "siteInfo",
410
+ "searchSite",
411
+ "searchProducts",
412
+ "getProduct"
413
+ ];
414
+ var SiteRuntime = class {
415
+ elements = /* @__PURE__ */ new Map();
416
+ destinations = /* @__PURE__ */ new Map();
417
+ ids = /* @__PURE__ */ new WeakMap();
418
+ prefix = crypto.randomUUID().slice(0, 8);
419
+ count = 0;
420
+ policy;
421
+ options;
422
+ constructor(options) {
423
+ this.options = options;
424
+ this.policy = options.policy ?? defaultPolicy;
425
+ const stored = storageRead(`${options.key}:destinations`);
426
+ if (Array.isArray(stored)) {
427
+ for (const d of stored.slice(0, 100)) if (d && typeof d.id === "string" && typeof d.url === "string" && this.safe(d.url)) this.destinations.set(d.id, d);
428
+ }
429
+ }
430
+ /**
431
+ * Applies the app's current settings to an open conversation. A stricter policy also drops
432
+ * targets and links collected under the old one.
433
+ */
434
+ update({ policy = defaultPolicy, context, sources }) {
435
+ this.options.context = context;
436
+ this.options.sources = sources;
437
+ if (policy === this.policy) return;
438
+ this.policy = policy;
439
+ this.elements.clear();
440
+ for (const [id, d] of this.destinations) if (!this.safe(d.url)) this.destinations.delete(id);
441
+ storageWrite(`${this.options.key}:destinations`, Array.from(this.destinations.values()).slice(-100));
442
+ }
443
+ safe(url) {
444
+ return safeDestination(url, location.href, this.policy);
445
+ }
446
+ observable(el) {
447
+ return observable(el, this.policy.privateSelector);
448
+ }
449
+ appContext() {
450
+ const value = this.options.appContext?.();
451
+ if (!value || !Object.keys(value).length) return void 0;
452
+ const context = {};
453
+ for (const [name, entry] of Object.entries(value)) {
454
+ context[name] = entry;
455
+ if (JSON.stringify(context).length > APP_CONTEXT_MAX_LENGTH) {
456
+ delete context[name];
457
+ context._truncated = true;
458
+ break;
459
+ }
460
+ }
461
+ return context;
462
+ }
463
+ snapshot(query = "") {
464
+ this.elements.clear();
465
+ const privateRegion = this.policy.privateSelector;
466
+ if (this.options.restricted || isRestrictedPath(location.pathname, this.policy)) return {
467
+ url: location.origin,
468
+ title: "",
469
+ revision: crypto.randomUUID(),
470
+ elements: [],
471
+ restricted: true
472
+ };
473
+ for (const landmark of this.options.landmarks ?? []) {
474
+ if (landmark.path !== location.pathname) continue;
475
+ try {
476
+ const matches = document.querySelectorAll(landmark.selector);
477
+ if (matches.length === 1 && (matches[0].textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 120) === landmark.fingerprint) matches[0].setAttribute("data-luma-label", landmark.label);
478
+ } catch {}
479
+ }
480
+ const appContext = this.appContext();
481
+ const snapshot = {
482
+ url: location.origin + location.pathname,
483
+ title: document.title.slice(0, 300),
484
+ revision: crypto.randomUUID(),
485
+ elements: [],
486
+ ...appContext ? { appContext } : {}
487
+ };
488
+ const words = normalizeText(query).split(/\s+/).filter(Boolean);
489
+ const candidates = Array.from(document.querySelectorAll("h1,h2,h3,h4,summary,a[href],button,select,input:not([type=\"hidden\"]),[role=\"button\"],[role=\"tab\"],[aria-expanded],[data-luma-label]")).filter((el) => observable(el, privateRegion)).map((el) => ({
490
+ el,
491
+ text: label(el, privateRegion)
492
+ })).filter((item) => item.text).sort((a, b) => words.filter((w) => normalizeText(b.text).includes(w)).length - words.filter((w) => normalizeText(a.text).includes(w)).length).slice(0, 100);
493
+ for (const { el, text } of candidates) {
494
+ let id = this.ids.get(el);
495
+ if (!id) {
496
+ id = `el-${this.prefix}-${++this.count}`;
497
+ this.ids.set(el, id);
498
+ }
499
+ this.elements.set(id, el);
500
+ const href = el instanceof HTMLAnchorElement ? this.safe(el.href) : null;
501
+ if (href) this.destinations.set(id, {
502
+ id,
503
+ url: href,
504
+ title: text
505
+ });
506
+ snapshot.elements.push({
507
+ id,
508
+ label: text,
509
+ role: el.getAttribute("role") || el.tagName.toLowerCase(),
510
+ ...href ? { href } : {},
511
+ ...el.tagName === "SUMMARY" && el.parentElement instanceof HTMLDetailsElement ? { expanded: el.parentElement.open } : {},
512
+ ...el.hasAttribute("aria-expanded") ? { expanded: el.getAttribute("aria-expanded") === "true" } : {},
513
+ ...el instanceof HTMLSelectElement ? { options: Array.from(el.options).filter((option) => !option.closest(privateRegion)).slice(0, 30).map((o) => o.label.slice(0, 180)) } : {}
514
+ });
515
+ if (JSON.stringify(snapshot).length > 3e4) {
516
+ snapshot.elements.pop();
517
+ break;
518
+ }
519
+ }
520
+ return snapshot;
521
+ }
522
+ destination(id) {
523
+ const d = this.destinations.get(id);
524
+ return d && this.safe(d.url) ? d : null;
525
+ }
526
+ remember(value) {
527
+ if (!value || typeof value !== "object") return;
528
+ if (Array.isArray(value)) {
529
+ value.forEach((v) => this.remember(v));
530
+ return;
531
+ }
532
+ const data = value;
533
+ if (typeof data.id === "string" && typeof data.url === "string" && typeof data.title === "string" && this.safe(data.url)) this.destinations.set(data.id, data);
534
+ for (const key of [
535
+ "data",
536
+ "items",
537
+ "menus",
538
+ "pages"
539
+ ]) if (key in data) this.remember(data[key]);
540
+ storageWrite(`${this.options.key}:destinations`, Array.from(this.destinations.values()).slice(-100));
541
+ }
542
+ async execute(name, input) {
543
+ if (!this.options.context?.capabilities.includes(name)) return {
544
+ status: "unavailable",
545
+ message: "This capability is disabled."
546
+ };
547
+ const parsed = siteToolInputs[name].safeParse(input);
548
+ if (!parsed.success) return {
549
+ status: "error",
550
+ message: "Invalid tool input."
551
+ };
552
+ if (name === "inspectPage") return {
553
+ status: "ok",
554
+ data: this.snapshot(parsed.data.query)
555
+ };
556
+ const lookup = lookupTools.find((tool) => tool === name);
557
+ const sources = this.options.sources ?? {};
558
+ if (!lookup || lookup === "searchProducts" && !sources.searchProducts || lookup === "getProduct" && !sources.getProduct) return { status: "unavailable" };
559
+ const signal = AbortSignal.timeout(15e3);
560
+ try {
561
+ const data = await Promise.race([runDataSource(lookup, parsed.data, sources, {
562
+ sessionId: this.options.sessionId,
563
+ signal
564
+ }, this.policy, this.options.context.capabilities), new Promise((_, reject) => signal.addEventListener("abort", () => reject(signal.reason), { once: true }))]);
565
+ const result = siteToolOutputSchema.parse({
566
+ status: "ok",
567
+ data
568
+ });
569
+ this.remember(result);
570
+ return result;
571
+ } catch {
572
+ return {
573
+ status: "unavailable",
574
+ message: "Live site lookup unavailable. Do not invent prices, stock or links. Try again or offer general help."
575
+ };
576
+ }
577
+ }
578
+ };
579
+ //#endregion
580
+ //#region src/core/controller.ts
581
+ /**
582
+ * Shared between the app tree (hooks) and the widget, which renders in its own React root
583
+ * inside a Shadow DOM.
584
+ */
585
+ var LumaController = class {
586
+ state = {
587
+ isOpen: false,
588
+ status: "connecting"
589
+ };
590
+ listeners = /* @__PURE__ */ new Set();
591
+ storageKey;
592
+ chat;
593
+ pendingAsk;
594
+ contexts = /* @__PURE__ */ new Map();
595
+ actions = /* @__PURE__ */ new Map();
596
+ subscribe = (listener) => {
597
+ this.listeners.add(listener);
598
+ return () => this.listeners.delete(listener);
599
+ };
600
+ getSnapshot = () => this.state;
601
+ set(patch) {
602
+ if (Object.entries(patch).every(([k, v]) => this.state[k] === v)) return;
603
+ this.state = {
604
+ ...this.state,
605
+ ...patch
606
+ };
607
+ this.listeners.forEach((listener) => listener());
608
+ }
609
+ /** Called by the widget once the conversation scope is known. */
610
+ attach(storageKey) {
611
+ this.storageKey = storageKey;
612
+ this.set({ isOpen: storageRead(`${storageKey}:open`) ?? false });
613
+ }
614
+ setStatus(status) {
615
+ this.set({ status });
616
+ }
617
+ setOpen = (isOpen) => {
618
+ this.set({ isOpen });
619
+ if (this.storageKey) storageWrite(`${this.storageKey}:open`, isOpen);
620
+ };
621
+ open = () => this.setOpen(true);
622
+ close = () => this.setOpen(false);
623
+ toggle = () => this.setOpen(!this.state.isOpen);
624
+ bindChat(chat) {
625
+ this.chat = chat;
626
+ if (chat && this.pendingAsk) {
627
+ const text = this.pendingAsk;
628
+ this.pendingAsk = void 0;
629
+ chat.ask(text);
630
+ }
631
+ }
632
+ /** Open the chat and send a message. Queued until the session is ready. */
633
+ ask = (text) => {
634
+ const message = text.trim();
635
+ if (!message) return false;
636
+ this.open();
637
+ if (this.chat) return this.chat.ask(message);
638
+ this.pendingAsk = message;
639
+ return true;
640
+ };
641
+ newChat = () => this.chat?.newChat();
642
+ /** Actions the current session told the assistant about; unknown until a session exists. */
643
+ declared;
644
+ declareActions(names) {
645
+ this.declared = names && new Set(names);
646
+ for (const name of this.actions.keys()) this.checkDeclared(name);
647
+ }
648
+ checkDeclared(name) {
649
+ if (!this.declared || this.declared.has(name)) return;
650
+ report("LUMA_ACTION_NOT_DECLARED", `useLumaAction registered "${name}", but this session did not declare it, so the assistant cannot use it. Server mode: add it to createLumaSessionHandler({ actions }). Keyless mode: pass it in <LumaProvider actions>.`, "warn");
651
+ }
652
+ registerAction(definition, handler) {
653
+ this.checkDeclared(definition.name);
654
+ const entry = {
655
+ definition,
656
+ handler
657
+ };
658
+ this.actions.set(definition.name, entry);
659
+ return () => {
660
+ if (this.actions.get(definition.name) === entry) this.actions.delete(definition.name);
661
+ };
662
+ }
663
+ appContext = () => Object.fromEntries(this.contexts);
664
+ };
665
+ //#endregion
666
+ //#region src/core/context.ts
667
+ var LumaContext = createContext(null);
668
+ //#endregion
669
+ //#region src/core/navigation.ts
670
+ var documentNavigation = { navigate: (url) => location.assign(url) };
671
+ /** Path, query and hash of a same-origin URL, without a router base path. */
672
+ function routerPath(url, basePath = "") {
673
+ const target = new URL(url, location.href);
674
+ const base = basePath.replace(/\/+$/, "");
675
+ return (base && (target.pathname === base || target.pathname.startsWith(`${base}/`)) ? target.pathname.slice(base.length) || "/" : target.pathname) + target.search + target.hash;
676
+ }
677
+ function isCurrentLocation(url) {
678
+ const target = new URL(url, location.href);
679
+ return target.origin === location.origin && target.pathname === location.pathname && target.search === location.search;
680
+ }
681
+ /** Resolve once a client-side route has rendered: DOM quiet for 300 ms, at most 3 s. */
682
+ function settled(signal) {
683
+ return new Promise((resolve) => {
684
+ let quiet = 0;
685
+ const done = () => {
686
+ observer.disconnect();
687
+ clearTimeout(quiet);
688
+ clearTimeout(limit);
689
+ resolve();
690
+ };
691
+ const observer = new MutationObserver(() => {
692
+ clearTimeout(quiet);
693
+ quiet = window.setTimeout(done, 300);
694
+ });
695
+ observer.observe(document.body, {
696
+ subtree: true,
697
+ childList: true
698
+ });
699
+ quiet = window.setTimeout(done, 300);
700
+ const limit = window.setTimeout(done, 3e3);
701
+ signal?.addEventListener("abort", done, { once: true });
702
+ });
703
+ }
704
+ //#endregion
705
+ //#region src/core/conversation.ts
706
+ var conversationKey = (scope) => `luma:v2:${scope}`;
707
+ var HistoryUnavailable = class extends Error {
708
+ status;
709
+ constructor(status) {
710
+ super(`History unavailable (${status})`);
711
+ this.status = status;
712
+ }
713
+ };
714
+ function readConversation(key) {
715
+ const state = storageRead(key);
716
+ return state && typeof state.sessionId === "string" && Date.now() - state.updatedAt < 6048e5 && Array.isArray(state.messages) ? state : null;
717
+ }
718
+ /** Start an empty conversation in the same visitor session and drop per-chat page state. */
719
+ function resetConversation(key, sessionId) {
720
+ const state = {
721
+ sessionId,
722
+ chatId: null,
723
+ messages: [],
724
+ updatedAt: Date.now()
725
+ };
726
+ storageWrite(key, state);
727
+ storageWrite(`${key}:arrival`, null);
728
+ storageWrite(`${key}:destinations`, null);
729
+ storageWrite(`${key}:guide`, false);
730
+ return state;
731
+ }
732
+ async function loadHistory(session, chatId) {
733
+ const response = await fetch(`${session.chatEndpoint}/history`, {
734
+ method: "POST",
735
+ credentials: "omit",
736
+ cache: "no-store",
737
+ headers: {
738
+ "Content-Type": "application/json",
739
+ "x-session-id": session.sessionId
740
+ },
741
+ body: JSON.stringify({
742
+ assistantId: session.assistantId,
743
+ chatId
744
+ }),
745
+ signal: AbortSignal.timeout(2e4)
746
+ });
747
+ if (!response.ok) throw new HistoryUnavailable(response.status);
748
+ return await response.json();
749
+ }
750
+ function siteFor(request) {
751
+ return {
752
+ version: 1,
753
+ capabilities: request.capabilities,
754
+ ...request.capabilities.includes("showGuide") ? { features: ["guideTour"] } : {},
755
+ ...request.actions.length ? { actions: request.actions } : {}
756
+ };
757
+ }
758
+ /** Explain a rejected session request using the error code in its body. */
759
+ async function sessionError(connection, response) {
760
+ const body = await response.json().catch(() => null);
761
+ const code = typeof body?.code === "string" ? body.code : typeof body?.error === "string" && /^[A-Z_]+$/.test(body.error) ? body.error : void 0;
762
+ const where = connection.mode === "server" ? connection.sessionEndpoint : "Luma keyless session";
763
+ if (response.status === 429) return new SessionError("LUMA_RATE_LIMITED", 429, `${where} is rate limited. Try again shortly.`);
764
+ if (code === "PUBLIC_WIDGET_UNAVAILABLE") return new SessionError(code, response.status, `Keyless access is off for assistant ${connection.assistantId}, or ${location.origin} is not one of its allowed domains. In the Luma dashboard open the assistant's overview, turn on keyless access and add exactly "${location.origin}".`);
765
+ if (connection.mode === "server" && response.status === 404 && !code) return new SessionError("LUMA_SESSION_ENDPOINT_NOT_FOUND", 404, `POST ${where} returned 404. Create this route with createLumaSessionHandler from "@luma-ai/react/server" and export it as POST (Next.js) or action (React Router).`);
766
+ if (code?.startsWith("LUMA_")) return new SessionError(code, response.status, `${where} returned HTTP ${response.status}. Check the server log for details.`);
767
+ return new SessionError("LUMA_SESSION_FAILED", response.status, `${where} returned HTTP ${response.status}${code ? ` (${code})` : ""}.`);
768
+ }
769
+ async function requestSession(connection, request, resume, signal) {
770
+ const resumeHeader = resume ? { "x-session-id": resume } : {};
771
+ if (connection.mode === "server") return fetch(connection.sessionEndpoint, {
772
+ method: "POST",
773
+ cache: "no-store",
774
+ credentials: "same-origin",
775
+ signal,
776
+ headers: {
777
+ "Content-Type": "application/json",
778
+ ...resumeHeader
779
+ },
780
+ body: JSON.stringify(request)
781
+ });
782
+ return fetch(`${connection.apiBaseUrl}/assistant/${encodeURIComponent(connection.assistantId)}/public-session`, {
783
+ method: "POST",
784
+ cache: "no-store",
785
+ credentials: "omit",
786
+ signal,
787
+ headers: {
788
+ "Content-Type": "application/json",
789
+ ...resumeHeader
790
+ },
791
+ body: JSON.stringify({ site: siteFor(request) })
792
+ });
793
+ }
794
+ async function bootstrap(connection, request, signal) {
795
+ if (connection.mode === "public" && !connection.assistantId) throw new SessionError("LUMA_NO_CONNECTION", 0, "LumaProvider needs sessionEndpoint (server mode) or assistantId (keyless mode).");
796
+ const key = conversationKey(connection.scope), stored = readConversation(key);
797
+ const response = await requestSession(connection, request, stored?.sessionId, signal);
798
+ if (!response.ok) throw await sessionError(connection, response);
799
+ let data;
800
+ try {
801
+ data = parseSession(await response.json());
802
+ } catch {
803
+ throw new SessionError("LUMA_INVALID_SESSION_RESPONSE", response.status, connection.mode === "server" ? `${connection.sessionEndpoint} did not return a session (often an HTML login or 404 page). Return createLumaSessionHandler's response unchanged and exclude the route from auth middleware.` : "The Luma API returned an unexpected session response.");
804
+ }
805
+ const assistantId = data.assistantId ?? connection.assistantId;
806
+ if (!assistantId) throw new Error("Session has no assistant");
807
+ const session = {
808
+ ...data,
809
+ assistantId,
810
+ chatEndpoint: data.chatEndpoint ?? connection.chatEndpoint ?? `${connection.apiBaseUrl}/assistant/chat/widget`,
811
+ siteContext: connection.siteContext ?? data.siteContext ?? (connection.mode === "public" ? {
812
+ ...siteFor(request),
813
+ origin: location.origin
814
+ } : void 0)
815
+ };
816
+ let state = stored?.sessionId === session.sessionId ? stored : {
817
+ sessionId: session.sessionId,
818
+ chatId: null,
819
+ messages: [],
820
+ updatedAt: Date.now()
821
+ };
822
+ if (state.chatId && session.siteContext) try {
823
+ const history = await loadHistory(session, state.chatId);
824
+ state.messages = history.messages;
825
+ state.running = history.running;
826
+ } catch (error) {
827
+ if (!(error instanceof HistoryUnavailable) || ![403, 404].includes(error.status)) throw error;
828
+ state = resetConversation(key, session.sessionId);
829
+ }
830
+ storageWrite(key, state);
831
+ return {
832
+ session,
833
+ state
834
+ };
835
+ }
836
+ //#endregion
837
+ //#region src/core/use-mobile.ts
838
+ var query = "(max-width: 639px)";
839
+ function subscribe(callback) {
840
+ const media = window.matchMedia(query);
841
+ media.addEventListener("change", callback);
842
+ return () => media.removeEventListener("change", callback);
843
+ }
844
+ function useIsMobile() {
845
+ return useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => false);
846
+ }
847
+ //#endregion
848
+ //#region src/core/color-themes.ts
849
+ var colorThemes = {
850
+ amber: {
851
+ light: {
852
+ primary: "oklch(0.75 0.18 75)",
853
+ primaryForeground: "oklch(0.15 0.03 75)",
854
+ accent: "oklch(0.92 0.08 75)",
855
+ accentForeground: "oklch(0.25 0.05 75)",
856
+ ring: "oklch(0.75 0.18 75)"
857
+ },
858
+ dark: {
859
+ primary: "oklch(0.8 0.16 75)",
860
+ primaryForeground: "oklch(0.15 0.03 75)",
861
+ accent: "oklch(0.3 0.06 75)",
862
+ accentForeground: "oklch(0.95 0.02 75)",
863
+ ring: "oklch(0.7 0.14 75)"
864
+ }
865
+ },
866
+ emerald: {
867
+ light: {
868
+ primary: "oklch(0.65 0.17 160)",
869
+ primaryForeground: "oklch(0.98 0.01 160)",
870
+ accent: "oklch(0.92 0.06 160)",
871
+ accentForeground: "oklch(0.25 0.06 160)",
872
+ ring: "oklch(0.65 0.17 160)"
873
+ },
874
+ dark: {
875
+ primary: "oklch(0.7 0.15 160)",
876
+ primaryForeground: "oklch(0.15 0.03 160)",
877
+ accent: "oklch(0.3 0.06 160)",
878
+ accentForeground: "oklch(0.95 0.02 160)",
879
+ ring: "oklch(0.6 0.13 160)"
880
+ }
881
+ },
882
+ blue: {
883
+ light: {
884
+ primary: "oklch(0.55 0.2 250)",
885
+ primaryForeground: "oklch(0.98 0.01 250)",
886
+ accent: "oklch(0.92 0.05 250)",
887
+ accentForeground: "oklch(0.25 0.08 250)",
888
+ ring: "oklch(0.55 0.2 250)"
889
+ },
890
+ dark: {
891
+ primary: "oklch(0.65 0.2 250)",
892
+ primaryForeground: "oklch(0.98 0.01 250)",
893
+ accent: "oklch(0.3 0.08 250)",
894
+ accentForeground: "oklch(0.95 0.02 250)",
895
+ ring: "oklch(0.55 0.18 250)"
896
+ }
897
+ },
898
+ indigo: {
899
+ light: {
900
+ primary: "oklch(0.5 0.22 270)",
901
+ primaryForeground: "oklch(0.98 0.01 270)",
902
+ accent: "oklch(0.92 0.05 270)",
903
+ accentForeground: "oklch(0.25 0.1 270)",
904
+ ring: "oklch(0.5 0.22 270)"
905
+ },
906
+ dark: {
907
+ primary: "oklch(0.6 0.2 270)",
908
+ primaryForeground: "oklch(0.98 0.01 270)",
909
+ accent: "oklch(0.3 0.1 270)",
910
+ accentForeground: "oklch(0.95 0.02 270)",
911
+ ring: "oklch(0.5 0.18 270)"
912
+ }
913
+ },
914
+ purple: {
915
+ light: {
916
+ primary: "oklch(0.55 0.25 300)",
917
+ primaryForeground: "oklch(0.98 0.01 300)",
918
+ accent: "oklch(0.92 0.06 300)",
919
+ accentForeground: "oklch(0.25 0.1 300)",
920
+ ring: "oklch(0.55 0.25 300)"
921
+ },
922
+ dark: {
923
+ primary: "oklch(0.65 0.22 300)",
924
+ primaryForeground: "oklch(0.98 0.01 300)",
925
+ accent: "oklch(0.3 0.1 300)",
926
+ accentForeground: "oklch(0.95 0.02 300)",
927
+ ring: "oklch(0.55 0.2 300)"
928
+ }
929
+ },
930
+ pink: {
931
+ light: {
932
+ primary: "oklch(0.65 0.22 350)",
933
+ primaryForeground: "oklch(0.98 0.01 350)",
934
+ accent: "oklch(0.92 0.06 350)",
935
+ accentForeground: "oklch(0.25 0.08 350)",
936
+ ring: "oklch(0.65 0.22 350)"
937
+ },
938
+ dark: {
939
+ primary: "oklch(0.7 0.2 350)",
940
+ primaryForeground: "oklch(0.15 0.03 350)",
941
+ accent: "oklch(0.3 0.08 350)",
942
+ accentForeground: "oklch(0.95 0.02 350)",
943
+ ring: "oklch(0.6 0.18 350)"
944
+ }
945
+ },
946
+ red: {
947
+ light: {
948
+ primary: "oklch(0.55 0.22 25)",
949
+ primaryForeground: "oklch(0.98 0.01 25)",
950
+ accent: "oklch(0.92 0.06 25)",
951
+ accentForeground: "oklch(0.25 0.08 25)",
952
+ ring: "oklch(0.55 0.22 25)"
953
+ },
954
+ dark: {
955
+ primary: "oklch(0.65 0.2 25)",
956
+ primaryForeground: "oklch(0.98 0.01 25)",
957
+ accent: "oklch(0.3 0.08 25)",
958
+ accentForeground: "oklch(0.95 0.02 25)",
959
+ ring: "oklch(0.55 0.18 25)"
960
+ }
961
+ },
962
+ orange: {
963
+ light: {
964
+ primary: "oklch(0.65 0.2 50)",
965
+ primaryForeground: "oklch(0.15 0.03 50)",
966
+ accent: "oklch(0.92 0.07 50)",
967
+ accentForeground: "oklch(0.25 0.06 50)",
968
+ ring: "oklch(0.65 0.2 50)"
969
+ },
970
+ dark: {
971
+ primary: "oklch(0.7 0.18 50)",
972
+ primaryForeground: "oklch(0.15 0.03 50)",
973
+ accent: "oklch(0.3 0.07 50)",
974
+ accentForeground: "oklch(0.95 0.02 50)",
975
+ ring: "oklch(0.6 0.16 50)"
976
+ }
977
+ }
978
+ };
979
+ /**
980
+ * Apply color theme CSS variables to an element
981
+ * @param element - The element to apply the theme to
982
+ * @param color - The theme color name
983
+ * @param isDark - Whether to use dark mode theme (optional, auto-detects if not provided)
984
+ */
985
+ function applyColorTheme(element, color, isDark) {
986
+ const theme = colorThemes[color];
987
+ if (!theme) {
988
+ console.warn(`Unknown color theme: ${color}, falling back to blue`);
989
+ applyColorTheme(element, "blue", isDark);
990
+ return;
991
+ }
992
+ const useDark = isDark ?? window.matchMedia("(prefers-color-scheme: dark)").matches;
993
+ const colors = useDark ? theme.dark : theme.light;
994
+ element.classList.toggle("dark", useDark);
995
+ element.style.setProperty("--primary", colors.primary);
996
+ element.style.setProperty("--primary-foreground", colors.primaryForeground);
997
+ element.style.setProperty("--accent", colors.accent);
998
+ element.style.setProperty("--accent-foreground", colors.accentForeground);
999
+ element.style.setProperty("--ring", colors.ring);
1000
+ element.style.setProperty("--sidebar-primary", colors.primary);
1001
+ element.style.setProperty("--sidebar-primary-foreground", colors.primaryForeground);
1002
+ element.style.setProperty("--sidebar-accent", colors.accent);
1003
+ element.style.setProperty("--sidebar-accent-foreground", colors.accentForeground);
1004
+ element.style.setProperty("--sidebar-ring", colors.ring);
1005
+ }
1006
+ /**
1007
+ * Setup theme listener to handle system dark mode changes
1008
+ * @param element - The element to apply the theme to
1009
+ * @param color - The theme color name
1010
+ * @returns Cleanup function to remove the listener
1011
+ */
1012
+ function setupThemeListener(element, color) {
1013
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
1014
+ const handleChange = (e) => {
1015
+ applyColorTheme(element, color, e.matches);
1016
+ };
1017
+ handleChange(mediaQuery);
1018
+ mediaQuery.addEventListener("change", handleChange);
1019
+ return () => mediaQuery.removeEventListener("change", handleChange);
1020
+ }
1021
+ //#endregion
1022
+ //#region ../assistant-contract/src/schemas.ts
1023
+ var ASSISTANT_MESSAGE_MAX_LENGTH = 2e3;
1024
+ z.object({
1025
+ assistantId: z.uuid(),
1026
+ chatId: z.uuid().nullable()
1027
+ });
1028
+ z.object({
1029
+ role: z.literal("user"),
1030
+ parts: z.tuple([z.object({
1031
+ type: z.literal("text"),
1032
+ text: z.string().max(ASSISTANT_MESSAGE_MAX_LENGTH).trim().min(1)
1033
+ })])
1034
+ });
1035
+ z.array(z.unknown()).min(1).max(100);
1036
+ z.object({
1037
+ sessionId: z.string().trim().min(1),
1038
+ name: z.string(),
1039
+ color: z.string(),
1040
+ avatar: z.string().nullable()
1041
+ });
1042
+ //#endregion
1043
+ //#region src/ui/widget-env.tsx
1044
+ var WidgetEnvContext = createContext({
1045
+ policy: defaultPolicy,
1046
+ navigation: documentNavigation,
1047
+ beforeNavigate: () => {}
1048
+ });
1049
+ var useWidgetEnv = () => useContext(WidgetEnvContext);
1050
+ /** Anchor props: safe site links stay in this tab (client-side when routed), others open a new tab. */
1051
+ function useSiteLink() {
1052
+ const { policy, navigation, beforeNavigate } = useWidgetEnv();
1053
+ return (href) => {
1054
+ const url = href ? safeDestination(href, location.href, policy) : null;
1055
+ if (!url) return {
1056
+ href,
1057
+ target: "_blank",
1058
+ rel: "noopener noreferrer"
1059
+ };
1060
+ return {
1061
+ href: url,
1062
+ onClick: (event) => {
1063
+ beforeNavigate();
1064
+ if (!navigation.client || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
1065
+ event.preventDefault();
1066
+ navigation.navigate(url);
1067
+ }
1068
+ };
1069
+ };
1070
+ }
1071
+ //#endregion
1072
+ //#region src/core/utils.ts
1073
+ function cn(...inputs) {
1074
+ return twMerge(clsx(inputs));
1075
+ }
1076
+ //#endregion
1077
+ //#region src/ui/base/button.tsx
1078
+ var buttonVariants = cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", {
1079
+ variants: {
1080
+ variant: {
1081
+ default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
1082
+ destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
1083
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
1084
+ secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
1085
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
1086
+ link: "text-primary underline-offset-4 hover:underline"
1087
+ },
1088
+ size: {
1089
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
1090
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
1091
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
1092
+ icon: "size-9"
1093
+ }
1094
+ },
1095
+ defaultVariants: {
1096
+ variant: "default",
1097
+ size: "default"
1098
+ }
1099
+ });
1100
+ function Button({ className, variant, size, asChild = false, ...props }) {
1101
+ return /* @__PURE__ */ jsx(asChild ? Slot : "button", {
1102
+ "data-slot": "button",
1103
+ className: cn(buttonVariants({
1104
+ variant,
1105
+ size,
1106
+ className
1107
+ })),
1108
+ ...props
1109
+ });
1110
+ }
1111
+ //#endregion
1112
+ //#region src/ui/site-actions.tsx
1113
+ var progress = {
1114
+ siteInfo: "در حال بررسی ساختار سایت…",
1115
+ searchSite: "در حال جستجو در صفحات سایت…",
1116
+ searchProducts: "در حال جستجوی محصولات…",
1117
+ getProduct: "در حال بررسی جزئیات محصول…",
1118
+ inspectPage: "در حال بررسی این صفحه…",
1119
+ runAction: "در حال آماده‌سازی درخواست…"
1120
+ };
1121
+ var outcomes = {
1122
+ navigate: {
1123
+ navigated: "صفحه باز شد",
1124
+ cancelled: "باز کردن صفحه لغو شد"
1125
+ },
1126
+ showGuide: {
1127
+ completed: "مرحله راهنما انجام شد",
1128
+ cancelled: "راهنما متوقف شد"
1129
+ },
1130
+ runAction: {
1131
+ completed: "درخواست انجام شد",
1132
+ cancelled: "درخواست لغو شد"
1133
+ }
1134
+ };
1135
+ function readablePath(url) {
1136
+ const { pathname, search, hash } = new URL(url);
1137
+ try {
1138
+ return decodeURI(pathname + search + hash);
1139
+ } catch {
1140
+ return pathname + search + hash;
1141
+ }
1142
+ }
1143
+ var count = (value) => value.toLocaleString("fa-IR");
1144
+ /** The model only hears back once a tour ends, so stops report how far the visitor got. */
1145
+ function tourOutput(output, step, total) {
1146
+ if (total === 1) return output;
1147
+ const progress = output.status === "completed" ? `Visitor completed all ${total} steps.` : `Tour stopped at step ${step + 1} of ${total}; steps before it were completed.`;
1148
+ return {
1149
+ ...output,
1150
+ message: [progress, output.message].filter(Boolean).join(" ")
1151
+ };
1152
+ }
1153
+ function GuideOverlay({ input, step, total, runtime, container, done, arrival }) {
1154
+ const target = runtime.elements.get(input.targetId);
1155
+ const [rect, setRect] = useState(null);
1156
+ const [position, setPosition] = useState({
1157
+ top: 16,
1158
+ left: 16
1159
+ });
1160
+ const popup = useRef(null);
1161
+ const finish = useRef(done);
1162
+ useEffect(() => {
1163
+ finish.current = done;
1164
+ }, [done]);
1165
+ const arrive = useRef(arrival);
1166
+ useEffect(() => {
1167
+ arrive.current = arrival;
1168
+ }, [arrival]);
1169
+ useEffect(() => {
1170
+ if (!target || !runtime.observable(target)) {
1171
+ finish.current({
1172
+ status: "unavailable",
1173
+ message: "Target is missing or stale. Inspect the current page again."
1174
+ });
1175
+ return;
1176
+ }
1177
+ const previousFocus = document.activeElement;
1178
+ const rtl = getComputedStyle(target).direction === "rtl";
1179
+ target.scrollIntoView({
1180
+ block: "center",
1181
+ behavior: matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth"
1182
+ });
1183
+ let completed = false;
1184
+ const complete = (status, message) => {
1185
+ if (completed) return;
1186
+ completed = true;
1187
+ finish.current({
1188
+ status,
1189
+ message,
1190
+ data: runtime.snapshot()
1191
+ });
1192
+ };
1193
+ const update = () => {
1194
+ if (!target.isConnected || !runtime.observable(target)) {
1195
+ complete("unavailable", "The target disappeared. Observe again.");
1196
+ return;
1197
+ }
1198
+ const box = target.getBoundingClientRect();
1199
+ setRect(box);
1200
+ const height = popup.current?.offsetHeight ?? 180;
1201
+ const width = Math.min(320, window.innerWidth - 32);
1202
+ const below = box.bottom + 12;
1203
+ const start = rtl ? box.right - width : box.left;
1204
+ setPosition({
1205
+ left: Math.max(16, Math.min(window.innerWidth - width - 16, start)),
1206
+ top: Math.max(16, Math.min(window.innerHeight - height - 16, below + height < window.innerHeight ? below : box.top - height - 12))
1207
+ });
1208
+ };
1209
+ let frame = 0;
1210
+ const schedule = () => {
1211
+ cancelAnimationFrame(frame);
1212
+ frame = requestAnimationFrame(update);
1213
+ };
1214
+ const checkExpected = () => {
1215
+ const expected = input.expectedTargetId ? runtime.elements.get(input.expectedTargetId) : null;
1216
+ return !input.expectedTargetId || Boolean(expected && runtime.observable(expected));
1217
+ };
1218
+ let clicked = false;
1219
+ const interact = (event) => {
1220
+ if (!event.isTrusted) return;
1221
+ if (event.type === "click") {
1222
+ const anchor = event.target.closest("a[href]");
1223
+ if (anchor instanceof HTMLAnchorElement && anchor.target !== "_blank" && runtime.safe(anchor.href) && new URL(anchor.href).pathname !== location.pathname) {
1224
+ arrive.current(anchor.href);
1225
+ return;
1226
+ }
1227
+ clicked = true;
1228
+ }
1229
+ if ((input.completion === "click" && clicked || input.completion === "change" && event.type === "change") && checkExpected()) window.setTimeout(() => complete("completed", "Visitor interacted with the highlighted control; verify the resulting page state."), 350);
1230
+ };
1231
+ const observer = new MutationObserver(() => {
1232
+ if ((input.completion === "expanded" && (target.getAttribute("aria-expanded") === "true" || target.tagName === "SUMMARY" && target.parentElement instanceof HTMLDetailsElement && target.parentElement.open) || input.completion === "click" && clicked) && checkExpected()) complete("completed");
1233
+ else schedule();
1234
+ });
1235
+ observer.observe(document.body, {
1236
+ subtree: true,
1237
+ childList: true,
1238
+ attributes: true,
1239
+ attributeFilter: [
1240
+ "aria-expanded",
1241
+ "open",
1242
+ "hidden",
1243
+ "class",
1244
+ "style"
1245
+ ]
1246
+ });
1247
+ const resize = new ResizeObserver(schedule);
1248
+ resize.observe(target);
1249
+ target.addEventListener("click", interact, true);
1250
+ target.addEventListener("change", interact, true);
1251
+ window.addEventListener("scroll", schedule, true);
1252
+ window.addEventListener("resize", schedule);
1253
+ const escape = (e) => {
1254
+ if (e.key === "Escape") {
1255
+ e.stopPropagation();
1256
+ complete("cancelled");
1257
+ }
1258
+ };
1259
+ window.addEventListener("keydown", escape, true);
1260
+ const timeout = window.setTimeout(() => complete("cancelled", "Guide timed out."), 18e4);
1261
+ update();
1262
+ popup.current?.focus();
1263
+ return () => {
1264
+ completed = true;
1265
+ clearTimeout(timeout);
1266
+ cancelAnimationFrame(frame);
1267
+ observer.disconnect();
1268
+ resize.disconnect();
1269
+ target.removeEventListener("click", interact, true);
1270
+ target.removeEventListener("change", interact, true);
1271
+ window.removeEventListener("scroll", schedule, true);
1272
+ window.removeEventListener("resize", schedule);
1273
+ window.removeEventListener("keydown", escape, true);
1274
+ if (previousFocus?.isConnected) previousFocus.focus({ preventScroll: true });
1275
+ };
1276
+ }, [
1277
+ target,
1278
+ input,
1279
+ runtime
1280
+ ]);
1281
+ return createPortal(/* @__PURE__ */ jsxs("div", {
1282
+ className: "luma-guide-layer",
1283
+ dir: "auto",
1284
+ children: [rect ? /* @__PURE__ */ jsx("div", {
1285
+ className: "luma-guide-ring",
1286
+ style: {
1287
+ top: rect.top - 4,
1288
+ left: rect.left - 4,
1289
+ width: rect.width + 8,
1290
+ height: rect.height + 8
1291
+ }
1292
+ }) : null, /* @__PURE__ */ jsxs("div", {
1293
+ ref: popup,
1294
+ tabIndex: -1,
1295
+ role: "dialog",
1296
+ "aria-modal": "false",
1297
+ "aria-label": input.title,
1298
+ className: "luma-guide-popover",
1299
+ style: position,
1300
+ children: [
1301
+ total > 1 ? /* @__PURE__ */ jsxs("p", {
1302
+ className: "text-xs text-muted-foreground",
1303
+ children: [
1304
+ "مرحله ",
1305
+ count(step + 1),
1306
+ " از ",
1307
+ count(total)
1308
+ ]
1309
+ }) : null,
1310
+ /* @__PURE__ */ jsx("p", {
1311
+ className: "font-semibold",
1312
+ children: input.title
1313
+ }),
1314
+ /* @__PURE__ */ jsx("p", {
1315
+ className: "text-sm",
1316
+ children: input.description
1317
+ }),
1318
+ /* @__PURE__ */ jsxs("div", {
1319
+ className: "flex gap-2",
1320
+ children: [input.completion === "next" ? /* @__PURE__ */ jsx(Button, {
1321
+ size: "sm",
1322
+ onClick: () => done({
1323
+ status: "completed",
1324
+ data: runtime.snapshot()
1325
+ }),
1326
+ children: total > 1 && step + 1 === total ? "متوجه شدم" : "بعدی"
1327
+ }) : /* @__PURE__ */ jsx("span", {
1328
+ className: "text-xs text-muted-foreground",
1329
+ children: "با بخش مشخص‌شده کار کنید تا راهنما ادامه یابد."
1330
+ }), /* @__PURE__ */ jsx(Button, {
1331
+ size: "sm",
1332
+ variant: "outline",
1333
+ onClick: () => done({ status: "cancelled" }),
1334
+ children: "پایان راهنما"
1335
+ })]
1336
+ })
1337
+ ]
1338
+ })]
1339
+ }), container);
1340
+ }
1341
+ function GuideTour({ steps, runtime, container, ready, visible, start, done, arrival }) {
1342
+ const [step, setStep] = useState(0);
1343
+ const current = steps[Math.min(step, steps.length - 1)];
1344
+ const advance = (output) => {
1345
+ if (output.status === "completed" && step + 1 < steps.length) setStep(step + 1);
1346
+ else done(tourOutput(output, step, steps.length));
1347
+ };
1348
+ return /* @__PURE__ */ jsxs("div", {
1349
+ className: "flex flex-col gap-2 rounded-lg border bg-background/60 p-3",
1350
+ children: [
1351
+ /* @__PURE__ */ jsxs("p", {
1352
+ className: "flex items-center gap-1.5 font-medium",
1353
+ children: [/* @__PURE__ */ jsx(MousePointerClick, { className: "size-4 shrink-0 text-primary" }), current.title]
1354
+ }),
1355
+ /* @__PURE__ */ jsx("p", {
1356
+ className: "text-sm text-muted-foreground",
1357
+ children: steps.length > 1 ? `راهنمای ${count(steps.length)} مرحله‌ای · مرحله ${count(step + 1)}` : current.description
1358
+ }),
1359
+ visible ? /* @__PURE__ */ jsx(GuideOverlay, {
1360
+ input: current,
1361
+ step,
1362
+ total: steps.length,
1363
+ runtime,
1364
+ container,
1365
+ done: advance,
1366
+ arrival
1367
+ }, step) : null,
1368
+ /* @__PURE__ */ jsxs("div", {
1369
+ className: "flex gap-2",
1370
+ children: [/* @__PURE__ */ jsx(Button, {
1371
+ size: "sm",
1372
+ disabled: !ready,
1373
+ onClick: start,
1374
+ children: "نمایش راهنما"
1375
+ }), /* @__PURE__ */ jsx(Button, {
1376
+ size: "sm",
1377
+ variant: "outline",
1378
+ disabled: !ready,
1379
+ onClick: () => done(tourOutput({ status: "cancelled" }, step, steps.length)),
1380
+ children: "انصراف"
1381
+ })]
1382
+ })
1383
+ ]
1384
+ });
1385
+ }
1386
+ function issues(error) {
1387
+ return error.issues.map((issue) => `${issue.path.map(String).join(".") || "input"}: ${issue.message}`).join("; ").slice(0, 1e3);
1388
+ }
1389
+ /** Only JSON survives the trip to the model; oversized results keep just their status. */
1390
+ function actionOutput(result) {
1391
+ let data;
1392
+ try {
1393
+ data = result === void 0 ? void 0 : JSON.parse(JSON.stringify(result));
1394
+ } catch {
1395
+ data = void 0;
1396
+ }
1397
+ const output = {
1398
+ status: "completed",
1399
+ ...data === void 0 ? {} : { data }
1400
+ };
1401
+ return siteToolOutputSchema.safeParse(output).success ? output : {
1402
+ status: "completed",
1403
+ message: "Result omitted because it is too large."
1404
+ };
1405
+ }
1406
+ /** An app action proposed by the assistant. It runs only through a handler the page registered. */
1407
+ function ActionRequest({ input, ready, done }) {
1408
+ const { controller } = useWidgetEnv();
1409
+ const request = siteToolInputs.runAction.safeParse(input);
1410
+ const entry = request.success ? controller?.actions.get(request.data.action) : void 0;
1411
+ const args = entry && request.success ? entry.definition.input.safeParse(request.data.input) : void 0;
1412
+ const [running, setRunning] = useState(false);
1413
+ const started = useRef(false);
1414
+ const finish = useRef(done);
1415
+ useEffect(() => {
1416
+ finish.current = done;
1417
+ }, [done]);
1418
+ const run = useCallback(async () => {
1419
+ if (!request.success || started.current) return;
1420
+ started.current = true;
1421
+ const current = controller?.actions.get(request.data.action);
1422
+ const checked = current?.definition.input.safeParse(request.data.input);
1423
+ if (!current || !checked?.success) {
1424
+ finish.current(!current ? {
1425
+ status: "unavailable",
1426
+ message: `Action "${request.data.action}" is not available on this page.`
1427
+ } : {
1428
+ status: "error",
1429
+ message: `Invalid action input. ${issues(checked.error)}`
1430
+ });
1431
+ return;
1432
+ }
1433
+ try {
1434
+ finish.current(actionOutput(await current.handler.current(checked.data)));
1435
+ } catch (error) {
1436
+ finish.current({
1437
+ status: "error",
1438
+ message: (error instanceof Error ? error.message : "Action failed.").slice(0, 1e3)
1439
+ });
1440
+ }
1441
+ }, [controller, request]);
1442
+ const automatic = !request.success || !entry || !args?.success || !entry.definition.confirm;
1443
+ useEffect(() => {
1444
+ if (!ready || !automatic || started.current) return;
1445
+ if (!request.success || !entry || !args?.success) {
1446
+ started.current = true;
1447
+ finish.current(!request.success ? {
1448
+ status: "error",
1449
+ message: "Invalid action request."
1450
+ } : !entry ? {
1451
+ status: "unavailable",
1452
+ message: `Action "${request.data.action}" is not available on this page.`
1453
+ } : {
1454
+ status: "error",
1455
+ message: `Invalid action input. ${issues(args.error)}`
1456
+ });
1457
+ } else run();
1458
+ }, [
1459
+ ready,
1460
+ automatic,
1461
+ request,
1462
+ entry,
1463
+ args,
1464
+ run
1465
+ ]);
1466
+ if (automatic || running) return /* @__PURE__ */ jsxs("p", {
1467
+ role: "status",
1468
+ className: "flex items-center gap-1.5 text-sm text-muted-foreground",
1469
+ children: [/* @__PURE__ */ jsx(LoaderCircle, { className: "size-3.5 animate-spin motion-reduce:animate-none" }), running ? "در حال انجام درخواست…" : progress.runAction]
1470
+ });
1471
+ return /* @__PURE__ */ jsxs("div", {
1472
+ className: "flex flex-col gap-2 rounded-lg border bg-background/60 p-3",
1473
+ children: [
1474
+ /* @__PURE__ */ jsxs("p", {
1475
+ className: "flex items-center gap-1.5 font-medium",
1476
+ children: [/* @__PURE__ */ jsx(Zap, { className: "size-4 shrink-0 text-primary" }), entry.definition.title ?? entry.definition.name]
1477
+ }),
1478
+ /* @__PURE__ */ jsx("p", {
1479
+ className: "text-sm",
1480
+ children: request.data.explanation
1481
+ }),
1482
+ /* @__PURE__ */ jsxs("div", {
1483
+ className: "flex gap-2",
1484
+ children: [/* @__PURE__ */ jsx(Button, {
1485
+ size: "sm",
1486
+ disabled: !ready,
1487
+ onClick: () => {
1488
+ setRunning(true);
1489
+ run();
1490
+ },
1491
+ children: "انجام شود"
1492
+ }), /* @__PURE__ */ jsx(Button, {
1493
+ size: "sm",
1494
+ variant: "outline",
1495
+ disabled: !ready,
1496
+ onClick: () => {
1497
+ started.current = true;
1498
+ done({
1499
+ status: "cancelled",
1500
+ message: "Visitor declined the action."
1501
+ });
1502
+ },
1503
+ children: "انصراف"
1504
+ })]
1505
+ })
1506
+ ]
1507
+ });
1508
+ }
1509
+ function SiteAction({ part, messageId, runtime, container, active, ready, complete, beforeNavigate, onArrival, guideAllowed, allowGuide }) {
1510
+ const { navigation } = useWidgetEnv();
1511
+ const name = part.type.slice(5);
1512
+ const ran = useRef(false);
1513
+ const [show, setShow] = useState(false);
1514
+ const pending = active && part.state === "input-available";
1515
+ const done = (output) => {
1516
+ if (output.status === "cancelled") allowGuide(false);
1517
+ setShow(false);
1518
+ complete(name, part.toolCallId, output);
1519
+ };
1520
+ useEffect(() => {
1521
+ if (!pending) {
1522
+ ran.current = false;
1523
+ return;
1524
+ }
1525
+ if (!pending || !ready || ran.current || name === "navigate" || name === "showGuide" || name === "runAction") return;
1526
+ ran.current = true;
1527
+ runtime.execute(name, part.input).then((output) => complete(name, part.toolCallId, output));
1528
+ }, [
1529
+ pending,
1530
+ ready,
1531
+ name,
1532
+ runtime,
1533
+ part.input,
1534
+ part.toolCallId,
1535
+ complete
1536
+ ]);
1537
+ useEffect(() => {
1538
+ if (part.output) runtime.remember(part.output);
1539
+ }, [part.output, runtime]);
1540
+ const arrival = (url) => {
1541
+ beforeNavigate();
1542
+ const receipt = {
1543
+ messageId,
1544
+ toolCallId: part.toolCallId,
1545
+ tool: name,
1546
+ url,
1547
+ at: Date.now()
1548
+ };
1549
+ storageWrite(`${runtime.options.key}:arrival`, receipt);
1550
+ onArrival();
1551
+ };
1552
+ if (pending && name === "navigate") {
1553
+ const parsed = siteToolInputs.navigate.safeParse(part.input);
1554
+ const destination = parsed.success ? runtime.destination(parsed.data.destinationId) : null;
1555
+ return /* @__PURE__ */ jsxs("div", {
1556
+ className: "flex flex-col gap-2 rounded-lg border bg-background/60 p-3",
1557
+ children: [
1558
+ /* @__PURE__ */ jsx("p", { children: parsed.success ? parsed.data.explanation : "مقصد نامعتبر است." }),
1559
+ destination ? /* @__PURE__ */ jsxs("div", {
1560
+ className: "flex min-w-0 items-center gap-2 rounded-md bg-muted/60 px-2 py-1.5",
1561
+ children: [/* @__PURE__ */ jsx(ExternalLink, { className: "size-4 shrink-0 text-muted-foreground" }), /* @__PURE__ */ jsxs("div", {
1562
+ className: "min-w-0",
1563
+ children: [/* @__PURE__ */ jsx("p", {
1564
+ className: "truncate text-sm font-medium",
1565
+ children: destination.title
1566
+ }), /* @__PURE__ */ jsx("p", {
1567
+ dir: "ltr",
1568
+ className: "truncate text-start text-xs text-muted-foreground",
1569
+ children: readablePath(destination.url)
1570
+ })]
1571
+ })]
1572
+ }) : /* @__PURE__ */ jsx("p", {
1573
+ className: "text-sm text-muted-foreground",
1574
+ children: "این مقصد در دسترس نیست."
1575
+ }),
1576
+ /* @__PURE__ */ jsxs("div", {
1577
+ className: "flex gap-2",
1578
+ children: [/* @__PURE__ */ jsx(Button, {
1579
+ size: "sm",
1580
+ disabled: !ready || !destination,
1581
+ onClick: () => {
1582
+ if (destination) {
1583
+ const target = new URL(destination.url);
1584
+ if (target.pathname === location.pathname && target.search === location.search) {
1585
+ if (target.hash !== location.hash) location.hash = target.hash;
1586
+ done({
1587
+ status: "navigated",
1588
+ data: runtime.snapshot()
1589
+ });
1590
+ return;
1591
+ }
1592
+ arrival(destination.url);
1593
+ navigation.navigate(destination.url);
1594
+ }
1595
+ },
1596
+ children: "باز کردن صفحه"
1597
+ }), /* @__PURE__ */ jsx(Button, {
1598
+ size: "sm",
1599
+ variant: "outline",
1600
+ disabled: !ready,
1601
+ onClick: () => done({ status: destination ? "cancelled" : "unavailable" }),
1602
+ children: "انصراف"
1603
+ })]
1604
+ })
1605
+ ]
1606
+ });
1607
+ }
1608
+ if (pending && name === "showGuide") {
1609
+ const steps = guideSteps(part.input);
1610
+ if (!steps) return /* @__PURE__ */ jsx(Button, {
1611
+ disabled: !ready,
1612
+ onClick: () => done({
1613
+ status: "unavailable",
1614
+ message: "Invalid guide input."
1615
+ }),
1616
+ children: "ادامه گفتگو"
1617
+ });
1618
+ return /* @__PURE__ */ jsx(GuideTour, {
1619
+ steps,
1620
+ runtime,
1621
+ container,
1622
+ ready,
1623
+ visible: ready && (show || guideAllowed),
1624
+ start: () => {
1625
+ allowGuide(true);
1626
+ setShow(true);
1627
+ },
1628
+ done,
1629
+ arrival
1630
+ });
1631
+ }
1632
+ if (pending && name === "runAction") return /* @__PURE__ */ jsx(ActionRequest, {
1633
+ input: part.input,
1634
+ ready,
1635
+ done
1636
+ });
1637
+ if (part.output?.status === "unavailable" || part.output?.status === "error") return /* @__PURE__ */ jsx("p", {
1638
+ className: "text-sm text-muted-foreground",
1639
+ children: "این بخش اکنون در دسترس نیست؛ دستیار راه دیگری پیشنهاد می‌کند."
1640
+ });
1641
+ const outcome = part.output && outcomes[name]?.[part.output.status];
1642
+ if (outcome) return /* @__PURE__ */ jsxs("p", {
1643
+ className: "flex items-center gap-1 text-xs text-muted-foreground",
1644
+ children: [part.output?.status === "cancelled" ? /* @__PURE__ */ jsx(X, { className: "size-3" }) : /* @__PURE__ */ jsx(Check, { className: "size-3" }), outcome]
1645
+ });
1646
+ return pending ? /* @__PURE__ */ jsxs("p", {
1647
+ role: "status",
1648
+ className: "flex items-center gap-1.5 text-sm text-muted-foreground",
1649
+ children: [/* @__PURE__ */ jsx(LoaderCircle, { className: "size-3.5 animate-spin motion-reduce:animate-none" }), progress[name] ?? "در حال بررسی سایت…"]
1650
+ }) : null;
1651
+ }
1652
+ function ProductCards({ products, searched }) {
1653
+ const link = useSiteLink();
1654
+ if (!products.length) return searched ? /* @__PURE__ */ jsx("p", {
1655
+ className: "text-sm text-muted-foreground",
1656
+ children: "محصولی با این شرایط پیدا نشد."
1657
+ }) : null;
1658
+ return /* @__PURE__ */ jsx("ul", {
1659
+ "aria-label": "محصولات پیشنهادی",
1660
+ className: "flex flex-col gap-2",
1661
+ children: products.map((p) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("article", {
1662
+ className: "flex gap-3 rounded-lg border bg-background/60 p-2",
1663
+ children: [p.image && /^https?:\/\//.test(p.image) ? /* @__PURE__ */ jsx("img", {
1664
+ src: p.image,
1665
+ alt: "",
1666
+ loading: "lazy",
1667
+ className: "size-18 shrink-0 rounded-md object-cover"
1668
+ }) : /* @__PURE__ */ jsx("div", {
1669
+ className: "flex size-18 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground",
1670
+ children: /* @__PURE__ */ jsx(Package, { className: "size-6" })
1671
+ }), /* @__PURE__ */ jsxs("div", {
1672
+ className: "flex min-w-0 flex-1 flex-col gap-1",
1673
+ children: [
1674
+ /* @__PURE__ */ jsx("p", {
1675
+ className: "line-clamp-2 font-semibold",
1676
+ children: p.title
1677
+ }),
1678
+ /* @__PURE__ */ jsxs("div", {
1679
+ className: "flex flex-wrap items-center gap-2",
1680
+ children: [/* @__PURE__ */ jsx("span", {
1681
+ className: "text-sm",
1682
+ children: p.price
1683
+ }), /* @__PURE__ */ jsx("span", {
1684
+ className: p.inStock ? "rounded-full bg-emerald-500/15 px-2 text-xs text-emerald-700 dark:text-emerald-300" : "rounded-full bg-muted px-2 text-xs text-muted-foreground",
1685
+ children: p.inStock ? "موجود" : "ناموجود"
1686
+ })]
1687
+ }),
1688
+ p.url && link(p.url).onClick ? /* @__PURE__ */ jsx(Button, {
1689
+ asChild: true,
1690
+ size: "sm",
1691
+ variant: "outline",
1692
+ className: "mt-auto self-start text-foreground no-underline",
1693
+ children: /* @__PURE__ */ jsx("a", {
1694
+ ...link(p.url),
1695
+ children: "مشاهده محصول"
1696
+ })
1697
+ }) : null
1698
+ ]
1699
+ })]
1700
+ }) }, p.productId))
1701
+ });
1702
+ }
1703
+ //#endregion
1704
+ //#region src/core/site-parts.ts
1705
+ function toolPart(part) {
1706
+ return part.type.startsWith("tool-") && "toolCallId" in part && siteToolNames.includes(part.type.slice(5)) ? part : null;
1707
+ }
1708
+ var productTools = ["tool-searchProducts", "tool-getProduct"];
1709
+ var isProductPart = (part) => productTools.includes(part.type);
1710
+ /**
1711
+ * A reply commonly searches and then verifies the same products with getProduct.
1712
+ * Show each product once, in first-seen order, with its most detailed data.
1713
+ */
1714
+ function replyProducts(parts) {
1715
+ const products = /* @__PURE__ */ new Map();
1716
+ let searched = false;
1717
+ for (const part of parts) {
1718
+ const tool = toolPart(part);
1719
+ if (!tool || !isProductPart(tool) || tool.output?.status !== "ok") continue;
1720
+ searched = true;
1721
+ const data = tool.output.data;
1722
+ const items = data && "items" in data ? data.items ?? [] : data && "productId" in data ? [data] : [];
1723
+ for (const item of items) if (item && (typeof item.productId === "number" || typeof item.productId === "string")) products.set(item.productId, {
1724
+ ...products.get(item.productId),
1725
+ ...item
1726
+ });
1727
+ }
1728
+ return {
1729
+ products: [...products.values()],
1730
+ searched
1731
+ };
1732
+ }
1733
+ //#endregion
1734
+ //#region ../assistant-contract/src/protocol.ts
1735
+ var WIDGET_SESSION_HEADER = "x-session-id";
1736
+ //#endregion
1737
+ //#region src/ui/ai-elements/conversation.tsx
1738
+ var Conversation = ({ className, ...props }) => /* @__PURE__ */ jsx(StickToBottom, {
1739
+ className: cn("relative flex-1 overflow-y-auto", className),
1740
+ initial: "smooth",
1741
+ resize: "smooth",
1742
+ role: "log",
1743
+ ...props
1744
+ });
1745
+ var ConversationContent = ({ className, ...props }) => /* @__PURE__ */ jsx(StickToBottom.Content, {
1746
+ className: cn("p-4", className),
1747
+ ...props
1748
+ });
1749
+ var ConversationScrollButton = ({ className, ...props }) => {
1750
+ const { isAtBottom, scrollToBottom } = useStickToBottomContext();
1751
+ const handleScrollToBottom = useCallback(() => {
1752
+ scrollToBottom();
1753
+ }, [scrollToBottom]);
1754
+ return !isAtBottom && /* @__PURE__ */ jsx(Button, {
1755
+ className: cn("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full", className),
1756
+ "aria-label": "رفتن به آخرین پیام",
1757
+ onClick: handleScrollToBottom,
1758
+ size: "icon",
1759
+ type: "button",
1760
+ variant: "outline",
1761
+ ...props,
1762
+ children: /* @__PURE__ */ jsx(ArrowDownIcon, { className: "size-4" })
1763
+ });
1764
+ };
1765
+ //#endregion
1766
+ //#region src/ui/ai-elements/message.tsx
1767
+ var Message = ({ className, from, ...props }) => /* @__PURE__ */ jsx("div", {
1768
+ className: cn("group flex w-full items-end justify-end gap-2 py-4", from === "user" ? "is-user" : "is-assistant flex-row-reverse justify-end", className),
1769
+ ...props
1770
+ });
1771
+ var messageContentVariants = cva("is-user:dark flex flex-col gap-2 overflow-hidden rounded-lg text-sm", {
1772
+ variants: { variant: {
1773
+ contained: [
1774
+ "max-w-[80%] px-4 py-3",
1775
+ "group-[.is-user]:bg-primary group-[.is-user]:text-primary-foreground",
1776
+ "group-[.is-assistant]:bg-secondary group-[.is-assistant]:text-foreground"
1777
+ ],
1778
+ flat: ["group-[.is-user]:max-w-[80%] group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground", "group-[.is-assistant]:text-foreground"]
1779
+ } },
1780
+ defaultVariants: { variant: "contained" }
1781
+ });
1782
+ var MessageContent = ({ children, className, variant, ...props }) => /* @__PURE__ */ jsx("div", {
1783
+ className: cn(messageContentVariants({
1784
+ variant,
1785
+ className
1786
+ })),
1787
+ ...props,
1788
+ children
1789
+ });
1790
+ //#endregion
1791
+ //#region src/ui/ai-elements/response.tsx
1792
+ var Response = memo(function Response({ children, className }) {
1793
+ const link = useSiteLink();
1794
+ return /* @__PURE__ */ jsx("div", {
1795
+ className: cn("luma-markdown prose prose-sm dark:prose-invert max-w-none break-words", className),
1796
+ children: /* @__PURE__ */ jsx(ReactMarkdown, {
1797
+ remarkPlugins: [remarkGfm],
1798
+ components: {
1799
+ a: ({ children, href, node: _node, ...props }) => /* @__PURE__ */ jsx("a", {
1800
+ ...props,
1801
+ ...link(href),
1802
+ children
1803
+ }),
1804
+ img: ({ alt }) => /* @__PURE__ */ jsx("span", { children: alt })
1805
+ },
1806
+ children
1807
+ })
1808
+ });
1809
+ });
1810
+ //#endregion
1811
+ //#region src/ui/base/textarea.tsx
1812
+ function Textarea({ className, ...props }) {
1813
+ return /* @__PURE__ */ jsx("textarea", {
1814
+ "data-slot": "textarea",
1815
+ className: cn("border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", className),
1816
+ ...props
1817
+ });
1818
+ }
1819
+ //#endregion
1820
+ //#region src/ui/base/chat/chat-input.tsx
1821
+ var ChatInput = React.forwardRef(({ className, onSubmit, onKeyDown, disabledEnter, ...props }, ref) => {
1822
+ const isMobile = useIsMobile();
1823
+ const handleKeyDown = (e) => {
1824
+ onKeyDown?.(e);
1825
+ if (e.key === "Enter" && !isMobile && !e.nativeEvent.isComposing && !e.defaultPrevented) {
1826
+ if (e.shiftKey) return;
1827
+ else {
1828
+ e.preventDefault();
1829
+ if (disabledEnter) return;
1830
+ onSubmit?.();
1831
+ }
1832
+ }
1833
+ };
1834
+ return /* @__PURE__ */ jsx(Textarea, {
1835
+ autoComplete: "off",
1836
+ ref,
1837
+ name: "message",
1838
+ onKeyDown: handleKeyDown,
1839
+ className: cn(`flex h-16 max-h-32 w-full resize-none items-center rounded-md bg-background px-4 py-3
1840
+ text-sm placeholder:text-muted-foreground focus-visible:ring-ring
1841
+ focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`, className),
1842
+ ...props
1843
+ });
1844
+ });
1845
+ ChatInput.displayName = "ChatInput";
1846
+ //#endregion
1847
+ //#region src/ui/base/chat/expandable-chat.tsx
1848
+ var chatConfig = {
1849
+ dimensions: {
1850
+ sm: "sm:max-w-sm sm:max-h-[500px]",
1851
+ md: "sm:max-w-md sm:max-h-[600px]",
1852
+ lg: "sm:max-w-lg sm:max-h-[700px]",
1853
+ xl: "sm:max-w-xl sm:max-h-[800px]",
1854
+ full: "sm:w-full sm:h-full"
1855
+ },
1856
+ mobileDimensions: {
1857
+ sm: "max-w-sm max-h-[500px]",
1858
+ md: "max-w-md max-h-[600px]",
1859
+ lg: "max-w-lg max-h-[700px]",
1860
+ xl: "max-w-xl max-h-[800px]",
1861
+ full: "w-full h-full"
1862
+ },
1863
+ iconSizes: {
1864
+ sm: {
1865
+ button: "size-10",
1866
+ icon: "h-5 w-5"
1867
+ },
1868
+ md: {
1869
+ button: "size-14",
1870
+ icon: "h-6 w-6"
1871
+ },
1872
+ lg: {
1873
+ button: "size-16",
1874
+ icon: "h-7 w-7"
1875
+ },
1876
+ xl: {
1877
+ button: "size-20",
1878
+ icon: "h-8 w-8"
1879
+ }
1880
+ },
1881
+ states: {
1882
+ open: "pointer-events-auto opacity-100 visible scale-100 translate-y-0",
1883
+ closed: "pointer-events-none opacity-0 invisible scale-100 sm:translate-y-5"
1884
+ }
1885
+ };
1886
+ var CloseContext = createContext(() => {});
1887
+ var ExpandableChat = ({ className, open: isOpen, onOpenChange: changeOpen, guideActive = false, position = "bottom-right", size = "md", icon, children, toggleClassName, paddingBottom = 20, paddingSide = 20, iconSize = "md", mobileEnabled = true, mobileSize = "sm", mobilePaddingBottom = 10, mobilePaddingSide = 10, mobileIconSize = "md", ...props }) => {
1888
+ const panelId = useId();
1889
+ const toggleRef = useRef(null);
1890
+ const isMobile = useIsMobile();
1891
+ const toggleChat = () => changeOpen(!isOpen);
1892
+ const panelOpen = isOpen && !guideActive;
1893
+ if (isMobile && !mobileEnabled) return null;
1894
+ const currentPaddingBottom = isMobile ? mobilePaddingBottom : paddingBottom;
1895
+ const currentPaddingSide = isMobile ? mobilePaddingSide : paddingSide;
1896
+ const currentIconSize = isMobile ? mobileIconSize : iconSize;
1897
+ const positionStyle = {
1898
+ bottom: `${currentPaddingBottom}px`,
1899
+ ...position === "bottom-right" ? { right: `${currentPaddingSide}px` } : { left: `${currentPaddingSide}px` }
1900
+ };
1901
+ const chatPositionClass = position === "bottom-right" ? cn(mobileSize === "full" ? "sm:bottom-[calc(100%+10px)] sm:right-0" : "bottom-[calc(100%+10px)] right-0") : cn(mobileSize === "full" ? "sm:bottom-[calc(100%+10px)] sm:left-0" : "bottom-[calc(100%+10px)] left-0");
1902
+ return /* @__PURE__ */ jsxs("div", {
1903
+ className: cn("fixed z-999999", className),
1904
+ style: positionStyle,
1905
+ onKeyDown: (event) => {
1906
+ if (event.key === "Escape" && isOpen) {
1907
+ changeOpen(false);
1908
+ toggleRef.current?.focus();
1909
+ }
1910
+ },
1911
+ ...props,
1912
+ children: [/* @__PURE__ */ jsx("div", {
1913
+ id: panelId,
1914
+ role: "region",
1915
+ "aria-label": "گفتگو با دستیار",
1916
+ inert: !panelOpen,
1917
+ style: isMobile && mobileSize === "full" ? { height: "100dvh" } : {
1918
+ width: `min(90vw, calc(100vw - ${currentPaddingSide * 2}px))`,
1919
+ height: `min(80dvh, calc(100dvh - ${currentPaddingBottom + {
1920
+ sm: 40,
1921
+ md: 56,
1922
+ lg: 64,
1923
+ xl: 80
1924
+ }[currentIconSize] + 20}px))`
1925
+ },
1926
+ className: cn("fixed inset-0 flex h-full w-full flex-col overflow-hidden border bg-background/90 shadow-md backdrop-blur-xl transition-all duration-250 ease-out", mobileSize === "full" ? "sm:absolute sm:inset-auto sm:h-[80vh] sm:w-[90vw] sm:rounded-lg" : "absolute inset-auto h-[80vh] w-[90vw] rounded-lg", chatPositionClass, isMobile ? chatConfig.mobileDimensions[mobileSize] : chatConfig.dimensions[size], panelOpen ? chatConfig.states.open : chatConfig.states.closed, className),
1927
+ children: /* @__PURE__ */ jsx(CloseContext, {
1928
+ value: () => {
1929
+ changeOpen(false);
1930
+ toggleRef.current?.focus();
1931
+ },
1932
+ children
1933
+ })
1934
+ }), /* @__PURE__ */ jsx(ExpandableChatToggle, {
1935
+ className: toggleClassName,
1936
+ icon,
1937
+ isOpen,
1938
+ toggleChat,
1939
+ iconSize: currentIconSize,
1940
+ ref: toggleRef,
1941
+ "aria-controls": panelId
1942
+ })]
1943
+ });
1944
+ };
1945
+ ExpandableChat.displayName = "ExpandableChat";
1946
+ var ExpandableChatHeader = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
1947
+ className: cn("flex items-center justify-between gap-2 border-b p-3", className),
1948
+ ...props
1949
+ });
1950
+ ExpandableChatHeader.displayName = "ExpandableChatHeader";
1951
+ /** Minimizes the panel; the conversation stays intact. */
1952
+ var ExpandableChatClose = () => /* @__PURE__ */ jsx(Button, {
1953
+ variant: "ghost",
1954
+ size: "icon",
1955
+ className: "size-8",
1956
+ "aria-label": "کوچک کردن گفتگو",
1957
+ title: "کوچک کردن",
1958
+ onClick: useContext(CloseContext),
1959
+ children: /* @__PURE__ */ jsx(Minus, { className: "size-4" })
1960
+ });
1961
+ var ExpandableChatBody = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
1962
+ className: cn("grow overflow-y-auto", className),
1963
+ ...props
1964
+ });
1965
+ ExpandableChatBody.displayName = "ExpandableChatBody";
1966
+ var ExpandableChatFooter = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
1967
+ className: cn("border-t p-4", className),
1968
+ ...props
1969
+ });
1970
+ ExpandableChatFooter.displayName = "ExpandableChatFooter";
1971
+ var ExpandableChatToggle = ({ className, icon, isOpen, toggleChat, iconSize = "md", ...props }) => {
1972
+ const sizeConfig = chatConfig.iconSizes[iconSize];
1973
+ return /* @__PURE__ */ jsx(Button, {
1974
+ variant: "default",
1975
+ "aria-label": isOpen ? "بستن گفتگو" : "باز کردن گفتگو",
1976
+ "aria-expanded": isOpen,
1977
+ onClick: toggleChat,
1978
+ className: cn("flex items-center justify-center rounded-full shadow-md transition-all duration-300 hover:shadow-lg hover:shadow-black/30 overflow-hidden", sizeConfig.button, className, icon && "p-0 border-3 border-primary"),
1979
+ ...props,
1980
+ children: isOpen ? /* @__PURE__ */ jsx(X, { className: sizeConfig.icon }) : icon || /* @__PURE__ */ jsx(MessageCircle, { className: sizeConfig.icon })
1981
+ });
1982
+ };
1983
+ ExpandableChatToggle.displayName = "ExpandableChatToggle";
1984
+ //#endregion
1985
+ //#region src/ui/base/kibo-ui/spinner/index.tsx
1986
+ var Default = ({ className, ...props }) => /* @__PURE__ */ jsx(LoaderIcon, {
1987
+ className: cn("animate-spin", className),
1988
+ ...props
1989
+ });
1990
+ var Circle = ({ className, ...props }) => /* @__PURE__ */ jsx(LoaderCircleIcon, {
1991
+ className: cn("animate-spin", className),
1992
+ ...props
1993
+ });
1994
+ var Pinwheel = ({ className, ...props }) => /* @__PURE__ */ jsx(LoaderPinwheelIcon, {
1995
+ className: cn("animate-spin", className),
1996
+ ...props
1997
+ });
1998
+ var CircleFilled = ({ className, size = 24, ...props }) => /* @__PURE__ */ jsxs("div", {
1999
+ className: "relative",
2000
+ style: {
2001
+ width: size,
2002
+ height: size
2003
+ },
2004
+ children: [/* @__PURE__ */ jsx("div", {
2005
+ className: "absolute inset-0 rotate-180",
2006
+ children: /* @__PURE__ */ jsx(LoaderCircleIcon, {
2007
+ className: cn("animate-spin", className, "text-foreground opacity-20"),
2008
+ size,
2009
+ ...props
2010
+ })
2011
+ }), /* @__PURE__ */ jsx(LoaderCircleIcon, {
2012
+ className: cn("relative animate-spin", className),
2013
+ size,
2014
+ ...props
2015
+ })]
2016
+ });
2017
+ var Ellipsis = ({ size = 24, ...props }) => {
2018
+ return /* @__PURE__ */ jsxs("svg", {
2019
+ height: size,
2020
+ viewBox: "0 0 24 24",
2021
+ width: size,
2022
+ xmlns: "http://www.w3.org/2000/svg",
2023
+ ...props,
2024
+ children: [
2025
+ /* @__PURE__ */ jsx("title", { children: "Loading..." }),
2026
+ /* @__PURE__ */ jsx("circle", {
2027
+ cx: "4",
2028
+ cy: "12",
2029
+ fill: "currentColor",
2030
+ r: "2",
2031
+ children: /* @__PURE__ */ jsx("animate", {
2032
+ attributeName: "cy",
2033
+ begin: "0;ellipsis3.end+0.25s",
2034
+ calcMode: "spline",
2035
+ dur: "0.6s",
2036
+ id: "ellipsis1",
2037
+ keySplines: ".33,.66,.66,1;.33,0,.66,.33",
2038
+ values: "12;6;12"
2039
+ })
2040
+ }),
2041
+ /* @__PURE__ */ jsx("circle", {
2042
+ cx: "12",
2043
+ cy: "12",
2044
+ fill: "currentColor",
2045
+ r: "2",
2046
+ children: /* @__PURE__ */ jsx("animate", {
2047
+ attributeName: "cy",
2048
+ begin: "ellipsis1.begin+0.1s",
2049
+ calcMode: "spline",
2050
+ dur: "0.6s",
2051
+ keySplines: ".33,.66,.66,1;.33,0,.66,.33",
2052
+ values: "12;6;12"
2053
+ })
2054
+ }),
2055
+ /* @__PURE__ */ jsx("circle", {
2056
+ cx: "20",
2057
+ cy: "12",
2058
+ fill: "currentColor",
2059
+ r: "2",
2060
+ children: /* @__PURE__ */ jsx("animate", {
2061
+ attributeName: "cy",
2062
+ begin: "ellipsis1.begin+0.2s",
2063
+ calcMode: "spline",
2064
+ dur: "0.6s",
2065
+ id: "ellipsis3",
2066
+ keySplines: ".33,.66,.66,1;.33,0,.66,.33",
2067
+ values: "12;6;12"
2068
+ })
2069
+ })
2070
+ ]
2071
+ });
2072
+ };
2073
+ var Ring = ({ size = 24, ...props }) => /* @__PURE__ */ jsxs("svg", {
2074
+ height: size,
2075
+ stroke: "currentColor",
2076
+ viewBox: "0 0 44 44",
2077
+ width: size,
2078
+ xmlns: "http://www.w3.org/2000/svg",
2079
+ ...props,
2080
+ children: [/* @__PURE__ */ jsx("title", { children: "Loading..." }), /* @__PURE__ */ jsxs("g", {
2081
+ fill: "none",
2082
+ fillRule: "evenodd",
2083
+ strokeWidth: "2",
2084
+ children: [/* @__PURE__ */ jsxs("circle", {
2085
+ cx: "22",
2086
+ cy: "22",
2087
+ r: "1",
2088
+ children: [/* @__PURE__ */ jsx("animate", {
2089
+ attributeName: "r",
2090
+ begin: "0s",
2091
+ calcMode: "spline",
2092
+ dur: "1.8s",
2093
+ keySplines: "0.165, 0.84, 0.44, 1",
2094
+ keyTimes: "0; 1",
2095
+ repeatCount: "indefinite",
2096
+ values: "1; 20"
2097
+ }), /* @__PURE__ */ jsx("animate", {
2098
+ attributeName: "stroke-opacity",
2099
+ begin: "0s",
2100
+ calcMode: "spline",
2101
+ dur: "1.8s",
2102
+ keySplines: "0.3, 0.61, 0.355, 1",
2103
+ keyTimes: "0; 1",
2104
+ repeatCount: "indefinite",
2105
+ values: "1; 0"
2106
+ })]
2107
+ }), /* @__PURE__ */ jsxs("circle", {
2108
+ cx: "22",
2109
+ cy: "22",
2110
+ r: "1",
2111
+ children: [/* @__PURE__ */ jsx("animate", {
2112
+ attributeName: "r",
2113
+ begin: "-0.9s",
2114
+ calcMode: "spline",
2115
+ dur: "1.8s",
2116
+ keySplines: "0.165, 0.84, 0.44, 1",
2117
+ keyTimes: "0; 1",
2118
+ repeatCount: "indefinite",
2119
+ values: "1; 20"
2120
+ }), /* @__PURE__ */ jsx("animate", {
2121
+ attributeName: "stroke-opacity",
2122
+ begin: "-0.9s",
2123
+ calcMode: "spline",
2124
+ dur: "1.8s",
2125
+ keySplines: "0.3, 0.61, 0.355, 1",
2126
+ keyTimes: "0; 1",
2127
+ repeatCount: "indefinite",
2128
+ values: "1; 0"
2129
+ })]
2130
+ })]
2131
+ })]
2132
+ });
2133
+ var Bars = ({ size = 24, ...props }) => /* @__PURE__ */ jsxs("svg", {
2134
+ height: size,
2135
+ viewBox: "0 0 24 24",
2136
+ width: size,
2137
+ xmlns: "http://www.w3.org/2000/svg",
2138
+ ...props,
2139
+ children: [
2140
+ /* @__PURE__ */ jsx("title", { children: "Loading..." }),
2141
+ /* @__PURE__ */ jsx("style", { children: `
2142
+ .spinner-bar {
2143
+ animation: spinner-bars-animation .8s linear infinite;
2144
+ animation-delay: -.8s;
2145
+ }
2146
+ .spinner-bars-2 {
2147
+ animation-delay: -.65s;
2148
+ }
2149
+ .spinner-bars-3 {
2150
+ animation-delay: -0.5s;
2151
+ }
2152
+ @keyframes spinner-bars-animation {
2153
+ 0% {
2154
+ y: 1px;
2155
+ height: 22px;
2156
+ }
2157
+ 93.75% {
2158
+ y: 5px;
2159
+ height: 14px;
2160
+ opacity: 0.2;
2161
+ }
2162
+ }
2163
+ ` }),
2164
+ /* @__PURE__ */ jsx("rect", {
2165
+ className: "spinner-bar",
2166
+ fill: "currentColor",
2167
+ height: "22",
2168
+ width: "6",
2169
+ x: "1",
2170
+ y: "1"
2171
+ }),
2172
+ /* @__PURE__ */ jsx("rect", {
2173
+ className: "spinner-bar spinner-bars-2",
2174
+ fill: "currentColor",
2175
+ height: "22",
2176
+ width: "6",
2177
+ x: "9",
2178
+ y: "1"
2179
+ }),
2180
+ /* @__PURE__ */ jsx("rect", {
2181
+ className: "spinner-bar spinner-bars-3",
2182
+ fill: "currentColor",
2183
+ height: "22",
2184
+ width: "6",
2185
+ x: "17",
2186
+ y: "1"
2187
+ })
2188
+ ]
2189
+ });
2190
+ var Infinite = ({ size = 24, ...props }) => /* @__PURE__ */ jsxs("svg", {
2191
+ height: size,
2192
+ preserveAspectRatio: "xMidYMid",
2193
+ viewBox: "0 0 100 100",
2194
+ width: size,
2195
+ xmlns: "http://www.w3.org/2000/svg",
2196
+ ...props,
2197
+ children: [/* @__PURE__ */ jsx("title", { children: "Loading..." }), /* @__PURE__ */ jsx("path", {
2198
+ d: "M24.3 30C11.4 30 5 43.3 5 50s6.4 20 19.3 20c19.3 0 32.1-40 51.4-40 C88.6 30 95 43.3 95 50s-6.4 20-19.3 20C56.4 70 43.6 30 24.3 30z",
2199
+ fill: "none",
2200
+ stroke: "currentColor",
2201
+ strokeDasharray: "205.271142578125 51.317785644531256",
2202
+ strokeLinecap: "round",
2203
+ strokeWidth: "10",
2204
+ style: {
2205
+ transform: "scale(0.8)",
2206
+ transformOrigin: "50px 50px"
2207
+ },
2208
+ children: /* @__PURE__ */ jsx("animate", {
2209
+ attributeName: "stroke-dashoffset",
2210
+ dur: "2s",
2211
+ keyTimes: "0;1",
2212
+ repeatCount: "indefinite",
2213
+ values: "0;256.58892822265625"
2214
+ })
2215
+ })]
2216
+ });
2217
+ var Spinner = ({ variant, ...props }) => {
2218
+ switch (variant) {
2219
+ case "circle": return /* @__PURE__ */ jsx(Circle, { ...props });
2220
+ case "pinwheel": return /* @__PURE__ */ jsx(Pinwheel, { ...props });
2221
+ case "circle-filled": return /* @__PURE__ */ jsx(CircleFilled, { ...props });
2222
+ case "ellipsis": return /* @__PURE__ */ jsx(Ellipsis, { ...props });
2223
+ case "ring": return /* @__PURE__ */ jsx(Ring, { ...props });
2224
+ case "bars": return /* @__PURE__ */ jsx(Bars, { ...props });
2225
+ case "infinite": return /* @__PURE__ */ jsx(Infinite, { ...props });
2226
+ default: return /* @__PURE__ */ jsx(Default, { ...props });
2227
+ }
2228
+ };
2229
+ //#endregion
2230
+ //#region src/core/transport.ts
2231
+ /** Map server error details to a user-facing Farsi message. */
2232
+ function getErrorMessage(status, errorCode) {
2233
+ if (status === 401) return "نشست شما منقضی شده است. لطفاً صفحه را رفرش کنید.";
2234
+ if (status === 404) return "دستیار مورد نظر یافت نشد.";
2235
+ if (errorCode === "INSUFFICIENT_CREDITS" || errorCode === "MESSAGE_CREDIT_LIMIT_EXCEEDED") return "اعتبار پیام به پایان رسیده است.";
2236
+ if (errorCode === "NO_SUBSCRIPTION") return "اشتراک فعالی یافت نشد.";
2237
+ if (errorCode === "MODEL_NOT_ALLOWED") return "مدل انتخاب شده برای اشتراک شما فعال نیست.";
2238
+ return "خطایی رخ داد. لطفاً دوباره تلاش کنید.";
2239
+ }
2240
+ function createWidgetTransport(options) {
2241
+ let chatId = options.initialChatId ?? null;
2242
+ let continuation;
2243
+ return {
2244
+ setChatId(value) {
2245
+ chatId = value;
2246
+ options.onChatId?.(value);
2247
+ },
2248
+ getChatId() {
2249
+ return chatId;
2250
+ },
2251
+ setContinuation(value) {
2252
+ continuation = value;
2253
+ },
2254
+ transport: new DefaultChatTransport({
2255
+ api: options.chatEndpoint,
2256
+ body: () => ({
2257
+ assistantId: options.assistantId,
2258
+ chatId,
2259
+ ...continuation ? { continuation } : {}
2260
+ }),
2261
+ headers: { [WIDGET_SESSION_HEADER]: options.sessionId },
2262
+ credentials: "omit",
2263
+ prepareSendMessagesRequest: ({ body, messages }) => ({ body: {
2264
+ ...body,
2265
+ messages: continuation ? [] : messages.filter((m) => m.role === "user").slice(-1)
2266
+ } }),
2267
+ fetch: async (input, init) => {
2268
+ let response = await globalThis.fetch(input, init);
2269
+ for (let attempt = 0; response.status === 409 && continuation && attempt < 8; attempt++) {
2270
+ await response.body?.cancel();
2271
+ await new Promise((resolve) => setTimeout(resolve, 300 * (attempt + 1)));
2272
+ response = await globalThis.fetch(input, init);
2273
+ }
2274
+ if (!response.ok) {
2275
+ const body = await response.json().catch(() => null);
2276
+ const code = body?.errorCode ?? body?.error ?? "";
2277
+ options.onHttpError(response.status, typeof code === "string" ? code : "");
2278
+ throw new Error("Assistant request failed");
2279
+ }
2280
+ return response;
2281
+ }
2282
+ })
2283
+ };
2284
+ }
2285
+ //#endregion
2286
+ //#region src/ui/chat-widget.tsx
2287
+ var colorMap = {
2288
+ amber: "bg-amber-500",
2289
+ emerald: "bg-emerald-500",
2290
+ blue: "bg-blue-500",
2291
+ indigo: "bg-indigo-500",
2292
+ purple: "bg-purple-500",
2293
+ pink: "bg-pink-500",
2294
+ red: "bg-red-500",
2295
+ orange: "bg-orange-500"
2296
+ };
2297
+ /** Starter prompts only advertise capabilities this site actually enabled. */
2298
+ function suggestions(capabilities = []) {
2299
+ return [
2300
+ capabilities.includes("searchProducts") && "چه محصولاتی پیشنهاد می‌کنید؟",
2301
+ capabilities.includes("showGuide") && "بخش‌های مهم همین صفحه را با راهنما نشانم بده",
2302
+ capabilities.includes("searchSite") && "برای پیدا کردن یک صفحه در سایت کمکم کن",
2303
+ "چه کمکی از شما برمی‌آید؟"
2304
+ ].filter((value) => Boolean(value));
2305
+ }
2306
+ function ChatWidget({ initialState, onNewChat, autoFocus = false, storageKey: key, session, container, sources, landmarks, restricted, position = "bottom-right", size = "md", title = session.name || "دستیار هوشمند لوما ✨", subtitle = "در مورد هر چیزی که می‌خواهید بپرسید", placeholder = "پیام خود را وارد کنید...", paddingBottom = 20, paddingSide = 20, iconSize = "md", mobileEnabled = true, mobileSize = "sm", mobilePaddingBottom = 10, mobilePaddingSide = 10, mobileIconSize = "md" }) {
2307
+ const [errorDetail, setErrorDetail] = useState(null);
2308
+ const { assistantId, sessionId, chatEndpoint, avatar, color } = session;
2309
+ const siteContext = session.siteContext;
2310
+ const env = useWidgetEnv();
2311
+ const { policy, navigation, controller } = env;
2312
+ const stateRef = useRef(initialState);
2313
+ const [recovering, setRecovering] = useState(Boolean(initialState.running));
2314
+ const [guideAllowed, setGuideAllowed] = useState(() => storageRead(`${key}:guide`) ?? false);
2315
+ const allowGuide = useCallback((value) => {
2316
+ setGuideAllowed(value);
2317
+ storageWrite(`${key}:guide`, value);
2318
+ }, [key]);
2319
+ const [runtime] = useState(() => new SiteRuntime({
2320
+ key,
2321
+ sessionId,
2322
+ context: siteContext,
2323
+ restricted,
2324
+ policy,
2325
+ sources,
2326
+ landmarks,
2327
+ appContext: controller?.appContext
2328
+ }));
2329
+ useLayoutEffect(() => runtime.update({
2330
+ policy,
2331
+ context: siteContext,
2332
+ sources
2333
+ }), [
2334
+ runtime,
2335
+ policy,
2336
+ siteContext,
2337
+ sources
2338
+ ]);
2339
+ const [connection] = useState(() => createWidgetTransport({
2340
+ assistantId,
2341
+ sessionId,
2342
+ chatEndpoint,
2343
+ initialChatId: initialState.chatId,
2344
+ onHttpError: (status, code) => {
2345
+ if (code === "PUBLIC_WIDGET_UNAVAILABLE") report(code, `Keyless access for this assistant was turned off, or ${location.origin} was removed from its allowed domains.`);
2346
+ setErrorDetail({
2347
+ message: getErrorMessage(status, code),
2348
+ isSessionExpired: status === 401
2349
+ });
2350
+ }
2351
+ }));
2352
+ const { messages, status, error, sendMessage, regenerate, stop, setMessages, addToolOutput, clearError: clearChatError } = useChat({
2353
+ messages: initialState.messages,
2354
+ transport: connection.transport,
2355
+ onData: (part) => {
2356
+ if (part.type === "data-chat-id" && typeof part.data === "string") connection.setChatId(part.data);
2357
+ }
2358
+ });
2359
+ const save = useCallback(() => {
2360
+ stateRef.current = {
2361
+ sessionId,
2362
+ chatId: connection.getChatId(),
2363
+ messages,
2364
+ running: status === "streaming" || status === "submitted",
2365
+ updatedAt: Date.now()
2366
+ };
2367
+ storageWrite(key, stateRef.current);
2368
+ }, [
2369
+ sessionId,
2370
+ connection,
2371
+ messages,
2372
+ status,
2373
+ key
2374
+ ]);
2375
+ useEffect(save, [save]);
2376
+ useEffect(() => {
2377
+ window.addEventListener("pagehide", save);
2378
+ return () => window.removeEventListener("pagehide", save);
2379
+ }, [save]);
2380
+ const submitted = useRef(/* @__PURE__ */ new Set());
2381
+ const sentCalls = useRef(new Set(initialState.messages.flatMap((m) => m.parts.map(toolPart).filter((p) => p?.state === "output-available").map((p) => p.toolCallId))));
2382
+ const complete = useCallback((name, id, output) => {
2383
+ addToolOutput({
2384
+ tool: name,
2385
+ toolCallId: id,
2386
+ output
2387
+ });
2388
+ }, [addToolOutput]);
2389
+ useEffect(() => {
2390
+ const chatId = connection.getChatId();
2391
+ if (!recovering || !chatId) return;
2392
+ let cancelled = false;
2393
+ const poll = async () => {
2394
+ try {
2395
+ const history = await loadHistory(session, chatId);
2396
+ if (cancelled) return;
2397
+ if (!history.running) {
2398
+ submitted.current.clear();
2399
+ history.messages.flatMap((m) => m.parts.map(toolPart)).forEach((p) => {
2400
+ if (p?.state === "output-available") sentCalls.current.add(p.toolCallId);
2401
+ else if (p) sentCalls.current.delete(p.toolCallId);
2402
+ });
2403
+ setMessages(history.messages);
2404
+ clearChatError();
2405
+ setErrorDetail(null);
2406
+ setRecovering(false);
2407
+ }
2408
+ } catch {
2409
+ if (!cancelled) {
2410
+ setRecovering(false);
2411
+ setErrorDetail({
2412
+ message: "بازیابی گفتگو انجام نشد. صفحه را دوباره باز کنید.",
2413
+ isSessionExpired: false
2414
+ });
2415
+ }
2416
+ }
2417
+ };
2418
+ poll();
2419
+ const timer = window.setInterval(() => void poll(), 1500);
2420
+ return () => {
2421
+ cancelled = true;
2422
+ clearInterval(timer);
2423
+ };
2424
+ }, [
2425
+ recovering,
2426
+ connection,
2427
+ session,
2428
+ setMessages,
2429
+ clearChatError
2430
+ ]);
2431
+ const [arrivalTick, setArrivalTick] = useState(0);
2432
+ const watchArrival = useCallback(() => setArrivalTick((n) => n + 1), []);
2433
+ useEffect(() => {
2434
+ if (recovering || status !== "ready") return;
2435
+ const receipt = storageRead(`${key}:arrival`);
2436
+ if (!receipt || Date.now() - receipt.at > 18e4) return;
2437
+ const part = messages.find((m) => m.id === receipt.messageId)?.parts.map(toolPart).find((p) => p?.toolCallId === receipt.toolCallId);
2438
+ if (!part || part.state !== "input-available") {
2439
+ storageWrite(`${key}:arrival`, null);
2440
+ return;
2441
+ }
2442
+ const abort = new AbortController();
2443
+ const finish = async (arrived) => {
2444
+ if (arrived) await settled(abort.signal);
2445
+ if (abort.signal.aborted) return;
2446
+ storageWrite(`${key}:arrival`, null);
2447
+ complete(receipt.tool, receipt.toolCallId, {
2448
+ status: arrived ? "navigated" : "unavailable",
2449
+ data: runtime.snapshot()
2450
+ });
2451
+ };
2452
+ if (isCurrentLocation(receipt.url) || !navigation.client) {
2453
+ finish(isCurrentLocation(receipt.url));
2454
+ return () => abort.abort();
2455
+ }
2456
+ const started = Date.now();
2457
+ const timer = window.setInterval(() => {
2458
+ if (isCurrentLocation(receipt.url)) {
2459
+ clearInterval(timer);
2460
+ finish(true);
2461
+ } else if (Date.now() - started > 1e4) {
2462
+ clearInterval(timer);
2463
+ finish(false);
2464
+ }
2465
+ }, 100);
2466
+ return () => {
2467
+ clearInterval(timer);
2468
+ abort.abort();
2469
+ };
2470
+ }, [
2471
+ messages,
2472
+ status,
2473
+ recovering,
2474
+ key,
2475
+ complete,
2476
+ runtime,
2477
+ navigation.client,
2478
+ arrivalTick
2479
+ ]);
2480
+ useEffect(() => {
2481
+ if (status !== "ready" || recovering || !siteContext) return;
2482
+ const last = messages.at(-1);
2483
+ if (last?.role !== "assistant") return;
2484
+ const parts = last.parts.map(toolPart).filter((p) => p !== null);
2485
+ if (!parts.length || parts.some((p) => p.state !== "output-available" || !p.output)) return;
2486
+ const fresh = parts.filter((p) => !sentCalls.current.has(p.toolCallId));
2487
+ if (!fresh.length) return;
2488
+ const signature = last.id + fresh.map((p) => p.toolCallId).join(":");
2489
+ if (submitted.current.has(signature)) return;
2490
+ submitted.current.add(signature);
2491
+ fresh.forEach((p) => sentCalls.current.add(p.toolCallId));
2492
+ connection.setContinuation({
2493
+ messageId: last.id,
2494
+ results: fresh.map((p) => ({
2495
+ toolCallId: p.toolCallId,
2496
+ output: p.output
2497
+ }))
2498
+ });
2499
+ sendMessage();
2500
+ }, [
2501
+ messages,
2502
+ status,
2503
+ recovering,
2504
+ siteContext,
2505
+ connection,
2506
+ sendMessage
2507
+ ]);
2508
+ const [input, setInput] = useState(() => storageRead(`${key}:draft`) ?? "");
2509
+ useEffect(() => storageWrite(`${key}:draft`, input), [input, key]);
2510
+ const isSessionExpired = errorDetail?.isSessionExpired ?? false;
2511
+ const displayError = errorDetail?.message ?? (error ? getErrorMessage(0, "") : null);
2512
+ const clearError = () => setErrorDetail(null);
2513
+ const busy = recovering || status === "submitted" || status === "streaming";
2514
+ const lookingUp = messages.at(-1)?.role === "assistant" && messages.at(-1).parts.map(toolPart).some((p) => p?.state === "input-available" && p.type !== "tool-navigate" && p.type !== "tool-showGuide" && p.type !== "tool-runAction");
2515
+ const canSend = !busy && input.trim().length > 0 && input.length <= 2e3 && !isSessionExpired;
2516
+ const send = (text) => {
2517
+ if (text.length > 2e3) return;
2518
+ clearError();
2519
+ allowGuide(false);
2520
+ connection.setContinuation();
2521
+ sendMessage({ text });
2522
+ };
2523
+ useEffect(() => {
2524
+ const declared = siteContext?.capabilities.includes("runAction") ? (siteContext.actions ?? []).map((action) => action.name) : [];
2525
+ controller?.declareActions(declared);
2526
+ return () => controller?.declareActions(void 0);
2527
+ }, [controller, siteContext]);
2528
+ const sendRef = useRef(send);
2529
+ const canAsk = !busy && !isSessionExpired;
2530
+ const canAskRef = useRef(canAsk);
2531
+ const newChatRef = useRef(() => {});
2532
+ useEffect(() => {
2533
+ controller?.bindChat({
2534
+ ask: (text) => {
2535
+ if (!canAskRef.current || text.length > 2e3) return false;
2536
+ sendRef.current(text);
2537
+ return true;
2538
+ },
2539
+ newChat: () => newChatRef.current()
2540
+ });
2541
+ return () => controller?.bindChat(void 0);
2542
+ }, [controller]);
2543
+ useEffect(() => {
2544
+ controller?.setStatus(busy || lookingUp ? "busy" : "ready");
2545
+ }, [
2546
+ controller,
2547
+ busy,
2548
+ lookingUp,
2549
+ session
2550
+ ]);
2551
+ const submitMessage = () => {
2552
+ if (!canSend) return;
2553
+ send(input.trim());
2554
+ setInput("");
2555
+ };
2556
+ const handleSubmit = (e) => {
2557
+ e.preventDefault();
2558
+ submitMessage();
2559
+ };
2560
+ const handleRetry = () => {
2561
+ clearError();
2562
+ if (busy) return;
2563
+ if (siteContext && connection.getChatId()) setRecovering(true);
2564
+ else regenerate();
2565
+ };
2566
+ const requestServerStop = async (chatId) => {
2567
+ if (!(await fetch(`${chatEndpoint}/stop`, {
2568
+ method: "POST",
2569
+ credentials: "omit",
2570
+ headers: {
2571
+ "Content-Type": "application/json",
2572
+ "x-session-id": sessionId
2573
+ },
2574
+ body: JSON.stringify({
2575
+ assistantId,
2576
+ chatId
2577
+ }),
2578
+ signal: AbortSignal.timeout(1e4)
2579
+ })).ok) throw new Error("Stop failed");
2580
+ };
2581
+ const stopResponse = async () => {
2582
+ const chatId = connection.getChatId();
2583
+ allowGuide(false);
2584
+ if (siteContext && chatId) try {
2585
+ await requestServerStop(chatId);
2586
+ await stop();
2587
+ setRecovering(true);
2588
+ } catch {
2589
+ setErrorDetail({
2590
+ message: "توقف پاسخ انجام نشد. دوباره تلاش کنید.",
2591
+ isSessionExpired: false
2592
+ });
2593
+ }
2594
+ else await stop();
2595
+ };
2596
+ const startNewChat = () => {
2597
+ const chatId = connection.getChatId();
2598
+ if (busy) {
2599
+ if (siteContext && chatId) requestServerStop(chatId).catch(() => {});
2600
+ stop();
2601
+ }
2602
+ onNewChat();
2603
+ };
2604
+ useEffect(() => {
2605
+ sendRef.current = send;
2606
+ canAskRef.current = canAsk;
2607
+ newChatRef.current = startNewChat;
2608
+ });
2609
+ const noopSubscribe = useCallback(() => () => {}, []);
2610
+ const closedState = useCallback(() => ({ isOpen: false }), []);
2611
+ const { isOpen } = useSyncExternalStore(controller?.subscribe ?? noopSubscribe, controller?.getSnapshot ?? closedState);
2612
+ const isAwaitingResponse = status === "submitted" || status === "streaming" && messages.length > 0 && (messages.at(-1)?.role === "user" || messages.at(-1)?.role === "assistant" && !messages.at(-1)?.parts.find((part) => part.type === "text"));
2613
+ if (!assistantId) return null;
2614
+ return /* @__PURE__ */ jsx(WidgetEnvContext, {
2615
+ value: {
2616
+ ...env,
2617
+ beforeNavigate: save
2618
+ },
2619
+ children: /* @__PURE__ */ jsxs(ExpandableChat, {
2620
+ open: isOpen,
2621
+ onOpenChange: (value) => controller?.setOpen(value),
2622
+ guideActive: guideAllowed && messages.at(-1)?.parts.some((p) => p.type === "tool-showGuide" && "state" in p && p.state === "input-available") === true && !busy,
2623
+ toggleClassName: cn(colorMap[color] ?? ""),
2624
+ size,
2625
+ position,
2626
+ paddingBottom,
2627
+ paddingSide,
2628
+ iconSize,
2629
+ mobileEnabled,
2630
+ mobileSize,
2631
+ mobilePaddingBottom,
2632
+ mobilePaddingSide,
2633
+ mobileIconSize,
2634
+ icon: avatar ? /* @__PURE__ */ jsx("img", {
2635
+ alt: "",
2636
+ src: avatar,
2637
+ className: cn("rounded-full bg-cover")
2638
+ }) : /* @__PURE__ */ jsx(Bot, { className: "h-6 w-6" }),
2639
+ children: [
2640
+ /* @__PURE__ */ jsxs(ExpandableChatHeader, { children: [/* @__PURE__ */ jsxs("div", {
2641
+ className: "flex min-w-0 items-center gap-3",
2642
+ children: [/* @__PURE__ */ jsx("div", {
2643
+ className: "flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-primary text-primary-foreground",
2644
+ children: avatar ? /* @__PURE__ */ jsx("img", {
2645
+ alt: "",
2646
+ src: avatar,
2647
+ className: "size-full object-cover"
2648
+ }) : /* @__PURE__ */ jsx(Bot, { className: "size-5" })
2649
+ }), /* @__PURE__ */ jsxs("div", {
2650
+ className: "min-w-0",
2651
+ children: [/* @__PURE__ */ jsx("p", {
2652
+ className: "truncate font-semibold",
2653
+ children: title
2654
+ }), /* @__PURE__ */ jsx("p", {
2655
+ className: "truncate text-xs text-muted-foreground",
2656
+ "aria-live": "polite",
2657
+ children: busy || lookingUp ? "در حال پاسخ…" : subtitle
2658
+ })]
2659
+ })]
2660
+ }), /* @__PURE__ */ jsxs("div", {
2661
+ className: "flex shrink-0 items-center gap-1",
2662
+ children: [messages.length > 0 && /* @__PURE__ */ jsx(Button, {
2663
+ type: "button",
2664
+ variant: "ghost",
2665
+ size: "icon",
2666
+ className: "size-8",
2667
+ "aria-label": "گفتگوی جدید",
2668
+ title: "گفتگوی جدید",
2669
+ onClick: startNewChat,
2670
+ children: /* @__PURE__ */ jsx(SquarePen, { className: "size-4" })
2671
+ }), /* @__PURE__ */ jsx(ExpandableChatClose, {})]
2672
+ })] }),
2673
+ /* @__PURE__ */ jsx(ExpandableChatBody, { children: /* @__PURE__ */ jsxs(Conversation, {
2674
+ className: "relative size-full flex-1 overflow-y-auto rounded-lg border",
2675
+ children: [/* @__PURE__ */ jsxs(ConversationContent, { children: [
2676
+ !messages.length && !busy && /* @__PURE__ */ jsxs("div", {
2677
+ className: "flex flex-col items-center gap-3 px-2 py-6 text-center",
2678
+ children: [
2679
+ /* @__PURE__ */ jsx("p", {
2680
+ className: "text-lg font-semibold",
2681
+ children: "سلام! چطور می‌توانم کمک کنم؟"
2682
+ }),
2683
+ /* @__PURE__ */ jsx("p", {
2684
+ className: "text-sm text-muted-foreground",
2685
+ children: subtitle
2686
+ }),
2687
+ /* @__PURE__ */ jsx("div", {
2688
+ className: "flex flex-wrap justify-center gap-2 pt-2",
2689
+ children: suggestions(siteContext?.capabilities).map((text) => /* @__PURE__ */ jsx(Button, {
2690
+ type: "button",
2691
+ variant: "outline",
2692
+ size: "sm",
2693
+ className: "h-auto rounded-full py-1.5 whitespace-normal",
2694
+ disabled: isSessionExpired,
2695
+ onClick: () => send(text),
2696
+ children: text
2697
+ }, text))
2698
+ })
2699
+ ]
2700
+ }),
2701
+ messages.map((message) => /* @__PURE__ */ jsx(Fragment, { children: message.role === "user" ? /* @__PURE__ */ jsx(Message, {
2702
+ className: "justify-start whitespace-pre-wrap",
2703
+ from: message.role,
2704
+ children: /* @__PURE__ */ jsx(MessageContent, {
2705
+ className: "",
2706
+ children: message.parts.map((part, index) => {
2707
+ if (part.type === "text") return /* @__PURE__ */ jsx("span", { children: part.text }, `${message.id}-${index}`);
2708
+ return null;
2709
+ })
2710
+ })
2711
+ }, message.id) : /* @__PURE__ */ jsxs(MessageContent, {
2712
+ className: "text-base max-w-full",
2713
+ children: [message.parts.map((part, index) => {
2714
+ if (part.type === "text") return /* @__PURE__ */ jsx(Response, { children: part.text }, `${message.id}-${index}`);
2715
+ const tool = toolPart(part);
2716
+ if (tool && isProductPart(tool) && tool.output?.status === "ok") return null;
2717
+ if (tool && siteContext) return /* @__PURE__ */ jsx(SiteAction, {
2718
+ part: tool,
2719
+ messageId: message.id,
2720
+ runtime,
2721
+ container,
2722
+ active: message.id === messages.at(-1)?.id,
2723
+ ready: !busy,
2724
+ complete,
2725
+ beforeNavigate: save,
2726
+ onArrival: watchArrival,
2727
+ guideAllowed,
2728
+ allowGuide
2729
+ }, tool.toolCallId);
2730
+ return null;
2731
+ }), siteContext && /* @__PURE__ */ jsx(ProductCards, { ...replyProducts(message.parts) })]
2732
+ }) }, `${message.role}-${message.id}`)),
2733
+ (isAwaitingResponse || recovering) && /* @__PURE__ */ jsx("div", {
2734
+ className: "flex justify-end",
2735
+ children: /* @__PURE__ */ jsx(Spinner, { variant: "ellipsis" })
2736
+ }),
2737
+ displayError && /* @__PURE__ */ jsxs("div", {
2738
+ role: "alert",
2739
+ className: "mx-2 mb-2 flex items-start gap-2 rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",
2740
+ children: [/* @__PURE__ */ jsx(AlertCircle, { className: "mt-0.5 size-4 shrink-0" }), /* @__PURE__ */ jsxs("div", {
2741
+ className: "flex-1",
2742
+ children: [/* @__PURE__ */ jsx("p", { children: displayError }), isSessionExpired ? /* @__PURE__ */ jsxs(Button, {
2743
+ type: "button",
2744
+ className: "mt-1 inline-flex items-center gap-1 text-xs underline",
2745
+ onClick: () => window.location.reload(),
2746
+ children: [/* @__PURE__ */ jsx(RefreshCw, { className: "size-3" }), "رفرش صفحه"]
2747
+ }) : /* @__PURE__ */ jsxs(Button, {
2748
+ type: "button",
2749
+ className: "mt-1 inline-flex items-center gap-1 text-xs underline",
2750
+ disabled: busy,
2751
+ onClick: handleRetry,
2752
+ children: [/* @__PURE__ */ jsx(RefreshCw, { className: "size-3" }), "تلاش مجدد"]
2753
+ })]
2754
+ })]
2755
+ })
2756
+ ] }), /* @__PURE__ */ jsx(ConversationScrollButton, {})]
2757
+ }) }),
2758
+ /* @__PURE__ */ jsxs(ExpandableChatFooter, { children: [/* @__PURE__ */ jsxs("form", {
2759
+ className: "relative flex rounded-lg border bg-input/30 p-1 focus-within:ring-1 focus-within:ring-ring",
2760
+ onSubmit: handleSubmit,
2761
+ children: [/* @__PURE__ */ jsx(ChatInput, {
2762
+ maxLength: ASSISTANT_MESSAGE_MAX_LENGTH,
2763
+ "aria-label": "پیام شما",
2764
+ className: "min-h-12 resize-none rounded-lg border-0 bg-transparent p-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
2765
+ onChange: (e) => setInput(e.target.value),
2766
+ disabledEnter: !canSend,
2767
+ onSubmit: submitMessage,
2768
+ placeholder: isSessionExpired ? "لطفاً صفحه را رفرش کنید..." : placeholder,
2769
+ value: input,
2770
+ autoFocus,
2771
+ disabled: isSessionExpired
2772
+ }), /* @__PURE__ */ jsxs("div", {
2773
+ className: "flex items-end justify-between p-1",
2774
+ children: [busy && /* @__PURE__ */ jsx(Button, {
2775
+ type: "button",
2776
+ size: "sm",
2777
+ variant: "outline",
2778
+ onClick: () => void stopResponse(),
2779
+ children: "توقف"
2780
+ }), /* @__PURE__ */ jsxs(Button, {
2781
+ className: "ms-auto gap-1.5",
2782
+ disabled: !canSend,
2783
+ size: "sm",
2784
+ type: "submit",
2785
+ children: ["ارسال", /* @__PURE__ */ jsx(CornerDownLeft, { className: "size-3.5" })]
2786
+ })]
2787
+ })]
2788
+ }), /* @__PURE__ */ jsxs("p", {
2789
+ className: "mt-1 text-xs text-muted-foreground",
2790
+ dir: "ltr",
2791
+ children: [
2792
+ input.length,
2793
+ "/",
2794
+ ASSISTANT_MESSAGE_MAX_LENGTH
2795
+ ]
2796
+ })] })
2797
+ ]
2798
+ })
2799
+ });
2800
+ }
2801
+ //#endregion
2802
+ //#region src/ui/widget-app.tsx
2803
+ /** Session lifecycle, retries and theme for one connection. Rendered in the widget's own root. */
2804
+ function WidgetApp({ appearance, connection, request, sources, landmarks, restricted, env, container }) {
2805
+ const hiddenOnMobile = useIsMobile() && appearance.mobileEnabled === false;
2806
+ const [session, setSession] = useState(null);
2807
+ const [conversation, setConversation] = useState(null);
2808
+ const [failed, setFailed] = useState(false);
2809
+ const [attempt, setAttempt] = useState(0);
2810
+ const [chatCount, setChatCount] = useState(0);
2811
+ const key = conversationKey(connection.scope);
2812
+ const { controller } = env;
2813
+ useEffect(() => {
2814
+ if (hiddenOnMobile) return;
2815
+ controller?.attach(key);
2816
+ controller?.setStatus("connecting");
2817
+ const controller_ = new AbortController();
2818
+ const timeout = window.setTimeout(() => controller_.abort(), 2e4);
2819
+ let active = true;
2820
+ bootstrap(connection, request, controller_.signal).then(({ session: data, state }) => {
2821
+ if (active) {
2822
+ setConversation(state);
2823
+ setSession(data);
2824
+ }
2825
+ }).catch((error) => {
2826
+ if (active) {
2827
+ if (error instanceof SessionError) report(error.code, error.message);
2828
+ else if (controller_.signal.aborted) report("LUMA_SESSION_FAILED", "The session request timed out after 20 seconds.");
2829
+ else report("LUMA_SESSION_FAILED", `The session request failed: ${error instanceof Error ? error.message : String(error)}.`);
2830
+ setFailed(true);
2831
+ controller?.setStatus("error");
2832
+ }
2833
+ }).finally(() => window.clearTimeout(timeout));
2834
+ return () => {
2835
+ active = false;
2836
+ window.clearTimeout(timeout);
2837
+ controller_.abort();
2838
+ };
2839
+ }, [
2840
+ connection,
2841
+ request,
2842
+ attempt,
2843
+ hiddenOnMobile,
2844
+ key,
2845
+ controller
2846
+ ]);
2847
+ useEffect(() => setupThemeListener(container, session?.color ?? "blue"), [container, session?.color]);
2848
+ if (hiddenOnMobile) return null;
2849
+ return /* @__PURE__ */ jsx(WidgetEnvContext, {
2850
+ value: env,
2851
+ children: /* @__PURE__ */ jsx("div", {
2852
+ dir: "rtl",
2853
+ className: "luma-assistant-widget-root",
2854
+ children: failed ? /* @__PURE__ */ jsx("button", {
2855
+ type: "button",
2856
+ className: "fixed bottom-4 right-4 rounded-lg border bg-background p-3 text-foreground shadow",
2857
+ onClick: () => {
2858
+ setFailed(false);
2859
+ setAttempt((value) => value + 1);
2860
+ },
2861
+ children: "ارتباط با دستیار برقرار نشد. تلاش مجدد"
2862
+ }) : session && conversation ? /* @__PURE__ */ jsx(ChatWidget, {
2863
+ onNewChat: () => {
2864
+ setConversation(resetConversation(key, session.sessionId));
2865
+ setChatCount((value) => value + 1);
2866
+ },
2867
+ autoFocus: chatCount > 0,
2868
+ ...appearance,
2869
+ storageKey: key,
2870
+ session,
2871
+ initialState: conversation,
2872
+ container,
2873
+ sources,
2874
+ landmarks,
2875
+ restricted
2876
+ }, `${session.sessionId}:${chatCount}`) : null
2877
+ })
2878
+ });
2879
+ }
2880
+ //#endregion
2881
+ //#region src/provider.tsx
2882
+ var appearanceKeys = [
2883
+ "position",
2884
+ "size",
2885
+ "title",
2886
+ "subtitle",
2887
+ "placeholder",
2888
+ "paddingBottom",
2889
+ "paddingSide",
2890
+ "iconSize",
2891
+ "mobileEnabled",
2892
+ "mobileSize",
2893
+ "mobilePaddingBottom",
2894
+ "mobilePaddingSide",
2895
+ "mobileIconSize"
2896
+ ];
2897
+ var styleText = `${styles_default}\n*,::before,::after{${Array.from(styles_default.matchAll(/@property\s+(--[\w-]+)\s*\{([^}]+)\}/g)).flatMap(([, name, body]) => {
2898
+ const initial = body.match(/initial-value:\s*([^;}]*)/);
2899
+ return initial ? [`${name}:${initial[1]};`] : [];
2900
+ }).join("")}}`;
2901
+ /**
2902
+ * Adds the Luma assistant to every page below it and enables useLuma, useLumaContext and
2903
+ * useLumaAction. Place it once, near the root of your app.
2904
+ */
2905
+ function LumaProvider(props) {
2906
+ const [controller] = useState(() => new LumaController());
2907
+ useEffect(() => {
2908
+ if (props.disabled) controller.setStatus("disabled");
2909
+ }, [controller, props.disabled]);
2910
+ return /* @__PURE__ */ jsxs(LumaContext, {
2911
+ value: controller,
2912
+ children: [props.children, props.disabled ? null : /* @__PURE__ */ jsx(LumaWidgetHost, {
2913
+ ...props,
2914
+ controller
2915
+ })]
2916
+ });
2917
+ }
2918
+ function LumaWidgetHost({ controller, ...props }) {
2919
+ const host = props.host;
2920
+ const apiBaseUrl = (props.apiBaseUrl ?? API_BASE_URLS[props.server ?? "internal"]).replace(/\/+$/, "");
2921
+ const mode = props.sessionEndpoint ? "server" : "public";
2922
+ const siteContextKey = JSON.stringify(host?.siteContext ?? null);
2923
+ const connection = useMemo(() => ({
2924
+ mode,
2925
+ sessionEndpoint: props.sessionEndpoint,
2926
+ assistantId: props.assistantId,
2927
+ chatEndpoint: host?.chatEndpoint,
2928
+ apiBaseUrl,
2929
+ siteContext: host?.siteContext,
2930
+ scope: host?.storageScope ?? (mode === "server" ? `server:${props.sessionEndpoint}` : `${props.assistantId}:${apiBaseUrl}`)
2931
+ }), [
2932
+ mode,
2933
+ props.sessionEndpoint,
2934
+ props.assistantId,
2935
+ apiBaseUrl,
2936
+ host?.chatEndpoint,
2937
+ siteContextKey,
2938
+ host?.storageScope
2939
+ ]);
2940
+ const navigation = props.features?.navigation !== false;
2941
+ const guides = props.features?.guides !== false;
2942
+ const sources = props.dataSources;
2943
+ const actions = props.actions;
2944
+ const capabilityKey = [
2945
+ navigation,
2946
+ guides,
2947
+ ...sourceCapabilities(sources),
2948
+ actions?.map((action) => action.name).join(",")
2949
+ ].join("|");
2950
+ const request = useMemo(() => {
2951
+ const capabilities = ["siteInfo"];
2952
+ for (const name of sourceCapabilities(sources)) if (name !== "searchSite" || navigation) capabilities.push(name);
2953
+ if (navigation) capabilities.push("navigate");
2954
+ if (guides) capabilities.push("inspectPage", "showGuide");
2955
+ if (mode === "server" || actions?.length) capabilities.push("runAction");
2956
+ return {
2957
+ capabilities,
2958
+ actions: mode === "public" ? (actions ?? []).map(actionContract) : []
2959
+ };
2960
+ }, [capabilityKey, mode]);
2961
+ const policyKey = JSON.stringify([
2962
+ props.restrictedPaths?.map(String),
2963
+ props.blockedPaths?.map(String),
2964
+ props.blockedParams,
2965
+ props.privateSelectors
2966
+ ]);
2967
+ const policy = useMemo(() => host?.policy ?? extendPolicy(defaultPolicy, {
2968
+ restrictedPaths: props.restrictedPaths,
2969
+ blockedPaths: props.blockedPaths,
2970
+ blockedParams: props.blockedParams,
2971
+ privateSelectors: props.privateSelectors
2972
+ }), [policyKey, host?.policy]);
2973
+ const navigator = props.navigator ?? documentNavigation;
2974
+ const env = useMemo(() => ({
2975
+ policy,
2976
+ navigation: navigator,
2977
+ controller,
2978
+ beforeNavigate: () => {}
2979
+ }), [
2980
+ policy,
2981
+ navigator,
2982
+ controller
2983
+ ]);
2984
+ const appearance = {};
2985
+ for (const name of appearanceKeys) if (props[name] !== void 0) appearance[name] = props[name];
2986
+ const hostRef = useRef(null);
2987
+ const rootRef = useRef(null);
2988
+ useEffect(() => {
2989
+ const element = hostRef.current;
2990
+ const shadow = element.shadowRoot ?? element.attachShadow({ mode: "open" });
2991
+ shadow.replaceChildren();
2992
+ const style = document.createElement("style");
2993
+ style.textContent = styleText;
2994
+ const container = document.createElement("div");
2995
+ container.className = "luma-assistant-widget-wrapper";
2996
+ shadow.append(style, container);
2997
+ const root = createRoot(container);
2998
+ rootRef.current = {
2999
+ root,
3000
+ container
3001
+ };
3002
+ return () => {
3003
+ rootRef.current = null;
3004
+ window.setTimeout(() => root.unmount());
3005
+ };
3006
+ }, []);
3007
+ useEffect(() => {
3008
+ const current = rootRef.current;
3009
+ current?.root.render(/* @__PURE__ */ jsx(WidgetApp, {
3010
+ appearance,
3011
+ connection,
3012
+ request,
3013
+ sources,
3014
+ landmarks: host?.landmarks,
3015
+ restricted: host?.restricted,
3016
+ env,
3017
+ container: current.container
3018
+ }));
3019
+ });
3020
+ return /* @__PURE__ */ jsx("div", {
3021
+ ref: hostRef,
3022
+ "data-luma-widget": ""
3023
+ });
3024
+ }
3025
+ //#endregion
3026
+ //#region src/hooks.ts
3027
+ function useController(hook) {
3028
+ const controller = useContext(LumaContext);
3029
+ if (!controller) throw new Error(`${hook} must be used inside <LumaProvider>.`);
3030
+ return controller;
3031
+ }
3032
+ /** Control the assistant from your own UI, e.g. an "Ask about this product" button. */
3033
+ function useLuma() {
3034
+ const controller = useController("useLuma");
3035
+ const state = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
3036
+ return useMemo(() => ({
3037
+ ...state,
3038
+ open: controller.open,
3039
+ close: controller.close,
3040
+ toggle: controller.toggle,
3041
+ /** Opens the chat and sends text. Returns false while a reply is in progress. */
3042
+ ask: controller.ask,
3043
+ newChat: controller.newChat
3044
+ }), [state, controller]);
3045
+ }
3046
+ /**
3047
+ * Share structured state of the current page with the assistant (included when it inspects
3048
+ * the page). Keep it small and free of secrets; it leaves the browser.
3049
+ */
3050
+ function useLumaContext(name, value) {
3051
+ const controller = useController("useLumaContext");
3052
+ const json = value === void 0 ? void 0 : JSON.stringify(value);
3053
+ useEffect(() => {
3054
+ if (json === void 0) return;
3055
+ controller.contexts.set(name, JSON.parse(json));
3056
+ return () => {
3057
+ controller.contexts.delete(name);
3058
+ };
3059
+ }, [
3060
+ controller,
3061
+ name,
3062
+ json
3063
+ ]);
3064
+ }
3065
+ /**
3066
+ * Let the assistant run an action on this page. The handler receives validated input; its
3067
+ * JSON-serializable return value is reported to the assistant. Define the action at module
3068
+ * level with defineAction so its identity is stable.
3069
+ */
3070
+ function useLumaAction(definition, handler) {
3071
+ const controller = useController("useLumaAction");
3072
+ const ref = useRef(handler);
3073
+ useEffect(() => {
3074
+ ref.current = handler;
3075
+ });
3076
+ useEffect(() => controller.registerAction(definition, ref), [controller, definition]);
3077
+ }
3078
+ //#endregion
3079
+ //#region src/markers.tsx
3080
+ /** Content inside is invisible to the assistant: never read, never targeted by guides. */
3081
+ function LumaPrivate(props) {
3082
+ return /* @__PURE__ */ jsx("div", {
3083
+ ...props,
3084
+ "data-luma-private": "",
3085
+ style: {
3086
+ display: "contents",
3087
+ ...props.style
3088
+ }
3089
+ });
3090
+ }
3091
+ //#endregion
3092
+ //#region src/core/markers.ts
3093
+ /** Name an unlabeled section so the assistant can find it and guide visitors to it. */
3094
+ var lumaLabel = (label) => ({ "data-luma-label": label });
3095
+ /** Spread on an element whose content the assistant must never read. */
3096
+ var lumaPrivate = () => ({ "data-luma-private": "" });
3097
+ //#endregion
3098
+ export { useLumaAction as a, routerPath as c, useLuma as i, defineAction as l, lumaPrivate as n, useLumaContext as o, LumaPrivate as r, LumaProvider as s, lumaLabel as t };
3099
+
3100
+ //# sourceMappingURL=src-dnp1waFV.js.map