@cuadra-ai/uikit 0.4.0 → 0.4.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CuadraChat.d.ts","sourceRoot":"","sources":["../../src/components/CuadraChat.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAA6D,MAAM,gBAAgB,CAAC;AAEjH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjH,6CAA6C;IAC7C,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAGD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAmKxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,UAAU,8GAyBtB,CAAC"}
1
+ {"version":3,"file":"CuadraChat.d.ts","sourceRoot":"","sources":["../../src/components/CuadraChat.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAA6D,MAAM,gBAAgB,CAAC;AAEjH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjH,6CAA6C;IAC7C,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAGD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAuKxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,UAAU,8GAyBtB,CAAC"}
package/dist/index.cjs CHANGED
@@ -22,5 +22,5 @@
22
22
  100% { transform: rotate(1turn); }
23
23
  }
24
24
  `,We=({children:e,className:r="",paddingX:t="px-0",paddingY:a="py-0",borderSizePx:i=4,style:o,contentStyle:n,rotating:c=!1})=>u.jsxs(u.Fragment,{children:[u.jsx("style",{children:lo}),u.jsxs("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-xl cuadra-overflow-hidden ${r}`,style:{padding:i,...o},children:[u.jsx("div",{className:`cuadra-absolute md:cuadra-rounded-xl cuadra-textured-card-border ${c?"cuadra-textured-card-border-rotating":""}`,style:c?{left:"-100%",top:"-100%",width:"300%",height:"300%",backgroundRepeat:"no-repeat",backgroundSize:"cover",backgroundPosition:"center",animation:"rotate 4s linear infinite"}:{backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat",top:"0",left:"0",width:"100%",height:"100%"}}),u.jsx("div",{className:`cuadra-relative cuadra-bg-background cuadra-h-full cuadra-z-10 cuadra-flex cuadra-flex-col cuadra-overflow-hidden ${t} ${a}`,style:{borderRadius:"calc(0.75rem - 4px)",...n},children:e})]})]}),St=({currentModel:e,models:r,modelsLoading:t,modelsError:a,onModelChange:i,hideModelSelector:o=!1,showThemeToggle:n=!0,theme:c="system",onMobileMenuClick:s,showMobileMenuButton:d=!1,safeArea:f=!1})=>{const[l,p]=x.useState(!1),[g,h]=x.useState(!1),y=x.useRef(null);x.useEffect(()=>{const k=C=>{y.current&&!y.current.contains(C.target)&&p(!1)};return l&&document.addEventListener("mousedown",k),()=>{document.removeEventListener("mousedown",k)}},[l]);const b=r.find(k=>k.id===e),w=k=>{i(k),p(!1),h(!1)};return u.jsxs("div",{className:`cuadra-min-h-16 cuadra-px-4 cuadra-py-3 cuadra-flex cuadra-items-center cuadra-justify-between cuadra-bg-background ${f?"":"cuadra-border-b cuadra-border-border"}`,style:f?{paddingTop:"calc(env(safe-area-inset-top) + 0.75rem)"}:void 0,children:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[d&&u.jsx("button",{type:"button",onClick:s,className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-10 cuadra-w-10 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-transition-colors disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed md:cuadra-hidden",style:{backgroundColor:"hsl(var(--muted))"},"aria-label":"Toggle thread list",children:u.jsx(Zr,{className:"cuadra-h-5 cuadra-w-5 cuadra-text-foreground",strokeWidth:1.5})}),n&&u.jsx("div",{className:"cuadra-hidden md:cuadra-flex cuadra-items-center cuadra-gap-2",children:u.jsx(fr,{theme:c})})]}),u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 md:cuadra-ml-0 cuadra-ml-auto",children:[!o&&u.jsx("label",{className:"cuadra-hidden md:cuadra-inline cuadra-text-sm cuadra-text-muted-foreground cuadra-font-brand",children:"Model"}),o?null:t?u.jsx("div",{className:"cuadra-w-48 cuadra-rounded-md cuadra-border cuadra-border-border cuadra-px-3 cuadra-py-2 cuadra-bg-muted",children:u.jsx("span",{className:"cuadra-text-muted-foreground cuadra-text-sm cuadra-font-brand",children:"Loading..."})}):a?u.jsx("div",{className:"cuadra-w-48 cuadra-rounded-md cuadra-border cuadra-border-destructive cuadra-px-3 cuadra-py-2 cuadra-bg-destructive/10",children:u.jsx("span",{className:"cuadra-text-destructive cuadra-text-sm cuadra-font-brand",children:"Failed to load models"})}):u.jsxs(u.Fragment,{children:[u.jsxs("div",{ref:y,className:"cuadra-hidden md:cuadra-block cuadra-relative cuadra-w-48",children:[u.jsxs("button",{type:"button",onClick:()=>p(!l),disabled:t||r.length===0||!!a,className:"cuadra-flex cuadra-h-10 cuadra-w-full cuadra-items-center cuadra-justify-between cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-sm placeholder:cuadra-text-muted-foreground focus:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-font-brand",children:[u.jsx("span",{className:b?"cuadra-text-foreground":"cuadra-text-muted-foreground",children:b?.name||"Select model"}),u.jsx(Xe,{className:"cuadra-ml-2 cuadra-h-4 cuadra-w-4 cuadra-opacity-50"})]}),l&&r.length>0&&u.jsx("div",{className:"cuadra-absolute cuadra-z-50 cuadra-mt-1 cuadra-w-full cuadra-min-w-[8rem] cuadra-overflow-hidden cuadra-rounded-md glass-popover cuadra-text-popover-foreground cuadra-animate-in fade-in-80 cuadra-border cuadra-border-border cuadra-bg-popover cuadra-shadow-md",children:u.jsx("div",{className:"cuadra-p-1",children:r.map(k=>u.jsxs("button",{type:"button",onClick:()=>w(k.id),className:`cuadra-relative cuadra-flex cuadra-w-full cuadra-cursor-pointer cuadra-select-none cuadra-items-center cuadra-rounded-sm cuadra-py-1.5 cuadra-pl-8 cuadra-pr-2 cuadra-text-sm cuadra-outline-none focus:cuadra-bg-secondary focus:cuadra-text-secondary-foreground font-brand cuadra-transition-colors ${e===k.id?"cuadra-bg-secondary cuadra-text-secondary-foreground":"hover:cuadra-bg-secondary/50"}`,children:[e===k.id&&u.jsx("span",{className:"cuadra-absolute cuadra-left-2 cuadra-flex cuadra-h-3.5 cuadra-w-3.5 cuadra-items-center cuadra-justify-center",children:u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",fill:"none",viewBox:"0 0 16 16",children:u.jsx("path",{fill:"currentColor",fillRule:"evenodd",d:"M6.47 10.03a.75.75 0 0 1-1.06-1.06l2-2a.75.75 0 0 1 1.06 0l2 2a.75.75 0 1 1-1.06 1.06L8 9.06l-1.53 1.53Z",clipRule:"evenodd"})})}),u.jsx("span",{children:k.name})]},k.id))})})]}),u.jsxs("button",{type:"button",onClick:()=>h(!0),disabled:t||r.length===0||!!a,className:"cuadra-flex md:cuadra-hidden cuadra-h-10 cuadra-items-center cuadra-gap-1 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-px-4 cuadra-py-2 cuadra-text-base cuadra-font-medium focus:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-font-brand cuadra-transition-colors",style:{backgroundColor:"hsl(var(--muted))"},children:[u.jsx("span",{className:"cuadra-text-foreground",children:b?.name||"Select model"}),u.jsx(Xe,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"})]}),g&&typeof document<"u"&&He.createPortal(u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-bg-black/50 cuadra-z-50 md:cuadra-hidden",onClick:()=>h(!1)}),u.jsxs("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-50 cuadra-flex cuadra-flex-col cuadra-bg-background md:cuadra-hidden",children:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-border-b cuadra-border-border cuadra-px-4 cuadra-py-4",style:f?{paddingTop:"calc(env(safe-area-inset-top) + 1rem)"}:void 0,children:[u.jsx("h2",{className:"cuadra-text-lg cuadra-font-normal cuadra-text-foreground font-brand",children:"Select Model"}),u.jsx("button",{type:"button",onClick:()=>h(!1),className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-8 cuadra-w-8 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-transition-colors","aria-label":"Close",children:u.jsx(Ye,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-foreground"})})]}),u.jsx("div",{className:"cuadra-flex-1 cuadra-overflow-y-auto cuadra-p-4",children:t?u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-py-8",children:u.jsx("span",{className:"cuadra-text-muted-foreground cuadra-text-sm cuadra-font-brand",children:"Loading models..."})}):a?u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-py-8",children:u.jsx("span",{className:"cuadra-text-destructive cuadra-text-sm cuadra-font-brand",children:"Failed to load models"})}):r.length===0?u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-py-8",children:u.jsx("span",{className:"cuadra-text-muted-foreground cuadra-text-sm cuadra-font-brand",children:"No models available"})}):u.jsx("div",{className:"cuadra-space-y-2",children:r.map(k=>u.jsxs("button",{type:"button",onClick:()=>w(k.id),className:`cuadra-w-full cuadra-flex cuadra-items-center cuadra-justify-between cuadra-rounded-lg cuadra-border cuadra-px-4 cuadra-py-4 cuadra-text-left cuadra-transition-colors font-brand cuadra-bg-background cuadra-text-foreground cuadra-border-border hover:cuadra-bg-muted ${e===k.id?"cuadra-border-primary":""}`,children:[u.jsx("span",{className:"cuadra-text-base cuadra-font-normal",children:k.name}),e===k.id&&u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",fill:"none",viewBox:"0 0 20 20",className:"cuadra-text-primary",children:u.jsx("path",{fill:"currentColor",fillRule:"evenodd",d:"M16.707 5.293a1 1 0 0 1 0 1.414l-8 8a1 1 0 0 1-1.414 0l-4-4a1 1 0 0 1 1.414-1.414L8 12.586l7.293-7.293a1 1 0 0 1 1.414 0Z",clipRule:"evenodd"})})]},k.id))})})]})]}),document.body)]})]})]})},fo=x.createContext(void 0),qe=({children:e,value:r})=>u.jsx(fo.Provider,{value:r,children:e});function ho(){x.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const r=document.createElement("div");r.className="cuadra-flex",document.body.appendChild(r);const t=window.getComputedStyle(r).display==="flex";if(document.body.removeChild(r),t)return;const a=document.createElement("link");a.setAttribute("data-cuadra-uikit","true"),a.rel="stylesheet",a.type="text/css";const i=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:fe&&fe.tagName.toUpperCase()==="SCRIPT"&&fe.src||new URL("index.cjs",document.baseURI).href).href];let o=!1;for(const n of i)if(a.href=n,a.onload=()=>{o=!0},a.onerror=()=>{},document.head.appendChild(a),o)break},[])}const mo=x.forwardRef(function({config:r},t){ho();const a=x.useRef(null),i=x.useRef(!1),{baseUrl:o,proxyUrl:n,sessionToken:c,mode:s="multiChat",modelMode:d="fixed",modelId:f,onModelChange:l,ephemeral:p=!1,systemPrompt:g,enableReasoning:h=!1,initialThreadId:y,welcomeTitle:b,welcomeSubtitle:w,extraTopPadding:k,suggestions:C,inputPlaceholder:E,preMadeResponseDelay:P=1e3,streamingSpeed:I=50,showThemeToggle:M=!0,initialMessage:D,initialPreMadeQA:A,theme:m="system",onError:$,onChatCreated:z,onUserMessage:V,onThreadIdUpdate:H,onLogout:me,enableAttachments:ve=!1,onBeforeRequest:Q,mockResponseOnBlocked:v}=r;x.useImperativeHandle(t,()=>({sendMessage:j=>{a.current?.sendMessage(j)},sendPreMadeQA:(j,F,R)=>{a.current?.sendPreMadeQA(j,F,R)},clearChat:()=>{a.current?.clearChat()}}),[]),x.useEffect(()=>{if(i.current)return;const j=setTimeout(()=>{A?(i.current=!0,a.current?.sendPreMadeQA(A.question,A.answer,{delay:P,streamingSpeed:I})):D&&(i.current=!0,a.current?.sendMessage(D))},500);return()=>clearTimeout(j)},[D,A,P,I]);const[S,_]=x.useState(!1),[L,B]=x.useState(null),[N,O]=x.useState(null),[X,G]=x.useState(!1),oe=x.useRef(null),se=j=>{if(j<30)return!0;if(oe.current){const F=oe.current.getBoundingClientRect();if(j-F.left<30)return!0}return!1},re=j=>{const F=window.innerWidth;return j>F-80},Fe=j=>{const R=j.touches[0].clientX;if(S){re(R)&&(B(R),O(R),G(!0));return}se(R)&&(B(R),O(R),G(!0))},xr=j=>{if(L===null||!X)return;const F=j.touches[0];O(F.clientX)},br=()=>{if(L===null||N===null){G(!1),B(null),O(null);return}const j=N-L,F=Math.abs(j),R=50;if(F<10){B(null),O(null),G(!1);return}j>R&&!S&&L!==null?se(L)&&_(!0):j<-R&&S&&_(!1),B(null),O(null),G(!1)},yr=()=>{if(X&&L!==null&&N!==null){const j=N-L;if(S)return`translateX(${Math.min(0,j)}px)`;if(L!==null&&se(L))return`translateX(${Math.min(0,-320+j)}px)`}return S?"translateX(0)":"translateX(-100%)"},wr=()=>{if(!X||L===null||N===null)return S?.5:0;const F=N-L;return S?Math.max(0,Math.min(1,(320+F)/320))*.5:L!==null&&se(L)?Math.max(0,Math.min(1,(F+320)/320))*.5:0},je=n||o||"",Te=!!n,ot=x.useMemo(()=>new Dt(je,c||void 0,Te),[je,c,Te]),[ce,kr]=x.useState(null),[pe,st]=x.useState(!1),[ge,ct]=x.useState(null),[Cr,ut]=x.useState(!1);x.useEffect(()=>{s==="multiChat"&&ut(!0)},[s]);const ue=x.useCallback(async()=>{if(d==="selector"){st(!0),ct(null);try{const j=await ot.listModels();kr(j)}catch(j){ct(j instanceof Error?j:new Error("Failed to load models"))}finally{st(!1)}}},[ot,d]);x.useEffect(()=>{d==="selector"&&ue()},[d,ue]),x.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=ue),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[ue]);const[Y,lt]=x.useState(d==="fixed"&&f||null),dt=x.useRef(Y),xe=x.useCallback(j=>{const F=dt.current;lt(j),dt.current=j,l?.(j),F!==null&&F!==j&&s==="multiChat"&&setTimeout(()=>{const R=window.__cuadraThreadListRuntime;if(R?.threads?.switchToNewThread)try{R.threads.switchToNewThread()}catch{}else if(R?.threads?.createThread)try{R.threads.createThread()}catch{}else if(R?.switchToNewThread)try{R.switchToNewThread()}catch{}},100)},[l,s]);x.useEffect(()=>{if(d==="selector"&&ce?.items&&ce.items.length>0&&!Y){const j=ce.items[0];if(j?.id){const F=j.id;lt(F),l?.(F)}}},[d,ce?.items,Y,l]);const vr=d==="fixed"?!!f:!!Y,Me=x.useMemo(()=>(ce?.items||[]).filter(j=>j?.id&&j?.displayName).map(j=>({id:j.id,name:j.displayName})),[ce]),ze=x.useMemo(()=>({currentModelId:Y||"",models:Me,modelsLoading:pe,modelsError:ge,onModelChange:xe,refetchModels:ue}),[Y,Me,pe,ge,xe,ue]);return d==="selector"&&pe||s==="multiChat"&&Cr?u.jsx(qe,{value:ze,children:u.jsx(We,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",borderSizePx:r.borderless?0:4,children:u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:u.jsx(Pt,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):d==="selector"&&!vr&&ge?u.jsx(qe,{value:ze,children:u.jsx(We,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:u.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:u.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):u.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:u.jsx(qe,{value:ze,children:u.jsx(wa,{baseUrl:Te?je:o||je,sessionToken:c,isProxyMode:Te,mode:s,modelMode:d,modelId:Y||f||void 0,onModelChange:xe,ephemeral:p,systemPrompt:g,enableReasoning:h,initialThreadId:y,enableAttachments:ve,onError:$,onChatCreated:z,onUserMessage:V,onThreadIdUpdate:H,onBeforeRequest:Q,mockResponseOnBlocked:v,onChatsLoaded:()=>{s==="multiChat"&&ut(!1)},children:u.jsx(We,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${r.containerClass||""}`,borderSizePx:r.borderless?0:4,style:{height:"100%"},children:u.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},onTouchStart:Fe,onTouchMove:xr,onTouchEnd:br,children:s==="multiChat"?u.jsxs(u.Fragment,{children:[typeof document<"u"&&He.createPortal(u.jsx("div",{className:`cuadra-fixed cuadra-inset-0 cuadra-bg-black cuadra-z-40 md:cuadra-hidden cuadra-transition-opacity cuadra-duration-300 ${S||X?"":"cuadra-pointer-events-none"}`,style:{opacity:wr()},onClick:()=>_(!1)}),document.body),typeof document<"u"&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-hidden md:cuadra-block !cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-full cuadra-w-80 cuadra-relative",style:{borderRightWidth:"1px",height:"100%"},children:u.jsx(It,{onThreadSelect:()=>_(!1),showThemeToggle:M,theme:m,onLogout:me,safeArea:r.safeArea,orgName:r.orgName,primaryColor:r.primaryColor})}),typeof document<"u"&&He.createPortal(u.jsx("div",{className:`cuadra-block md:cuadra-hidden !cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-h-screen cuadra-w-80 cuadra-fixed cuadra-z-50 cuadra-top-0 cuadra-left-0 ${S||X?"":"cuadra-pointer-events-none"}`,style:{borderRightWidth:"1px",transform:yr(),transition:X?"none":"transform 0.3s ease-in-out"},children:u.jsx(It,{onThreadSelect:()=>_(!1),showThemeToggle:M,theme:m,onLogout:me,safeArea:r.safeArea,orgName:r.orgName,primaryColor:r.primaryColor})}),document.body)]}),u.jsxs("div",{ref:oe,className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:[d==="selector"&&u.jsx(St,{currentModel:Y||"",models:Me,modelsLoading:pe,modelsError:ge,onModelChange:xe,showThemeToggle:M,theme:m,onMobileMenuClick:()=>_(!S),showMobileMenuButton:s==="multiChat",safeArea:r.safeArea}),u.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0 cuadra-space-y-4 cuadra-p-4",children:u.jsx(At,{ref:a,welcomeTitle:b,welcomeSubtitle:w,extraTopPadding:k,suggestions:C,inputPlaceholder:E,enableAttachments:ve,preMadeResponseDelay:P,streamingSpeed:I,safeArea:r.safeArea})})]})]}):u.jsxs("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:[d==="selector"&&u.jsx(St,{currentModel:Y||"",models:Me,modelsLoading:pe,modelsError:ge,onModelChange:xe,showThemeToggle:M,theme:m,safeArea:r.safeArea}),u.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0 cuadra-space-y-4 cuadra-p-4",children:u.jsx(At,{ref:a,welcomeTitle:b,welcomeSubtitle:w,extraTopPadding:k,suggestions:C,inputPlaceholder:E,preMadeResponseDelay:P,streamingSpeed:I,safeArea:r.safeArea})})]})})})})})})});function hr(e,r=":root"){if(typeof document>"u")return;const t=document.documentElement;if(e.light&&go(e.light,t),e.dark){let a=document.getElementById("cuadra-theme-dark");a||(a=document.createElement("style"),a.id="cuadra-theme-dark",document.head.appendChild(a));const i=xo(e.dark);a.textContent=`.dark { ${i} }`}}const po={background:"background",foreground:"foreground",card:"card",cardForeground:"card-foreground",popover:"popover",popoverForeground:"popover-foreground",primary:"primary",primaryForeground:"primary-foreground",primaryLight:"primary-light",primaryLighter:"primary-lighter",secondary:"secondary",secondaryForeground:"secondary-foreground",muted:"muted",mutedForeground:"muted-foreground",accent:"accent",accentForeground:"accent-foreground",border:"border",input:"input",ring:"ring",destructive:"destructive",destructiveForeground:"destructive-foreground",success:"success",successForeground:"success-foreground",info:"info",infoForeground:"info-foreground",warning:"warning",warningForeground:"warning-foreground"};function mr(e){const r=po[e];return r?`--cuadra-${r}`:`--cuadra-${e.replace(/([A-Z])/g,"-$1").toLowerCase()}`}function go(e,r){Object.entries(e).forEach(([t,a])=>{if(a){const i=mr(t);r.style.setProperty(i,a)}})}function xo(e){return Object.entries(e).map(([r,t])=>t?`${mr(r)}: ${t};`:"").filter(Boolean).join(" ")}function bo(){if(typeof document>"u")return;const e=document.documentElement;Array.from(e.style).filter(a=>a.startsWith("--cuadra-")).forEach(a=>e.style.removeProperty(a));const t=document.getElementById("cuadra-theme-dark");t&&t.remove()}function yo({onReset:e,error:r}){return u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-h-full cuadra-p-6 cuadra-text-center",children:[u.jsx("div",{className:"cuadra-mb-4",children:u.jsx("svg",{className:"cuadra-w-12 cuadra-h-12 cuadra-text-destructive cuadra-mx-auto",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),u.jsx("h3",{className:"cuadra-text-lg cuadra-font-medium cuadra-text-foreground cuadra-mb-2",children:"Something went wrong"}),u.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-mb-4 cuadra-max-w-sm",children:r?.message||"An unexpected error occurred. Please try again."}),u.jsx("button",{onClick:e,className:"cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-medium cuadra-rounded-md cuadra-transition-colors",style:{backgroundColor:"var(--cuadra-primary)",color:"hsl(var(--cuadra-primary-foreground))"},children:"Try Again"})]})}class it extends x.Component{constructor(t){super(t);ae(this,"reset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,a){this.props.onError?.(t,a)}render(){if(this.state.hasError){const{fallback:t}=this.props,{error:a}=this.state;return typeof t=="function"?t(a,this.reset):t||u.jsx(yo,{error:a,onReset:this.reset})}return this.props.children}}function wo(e,r){const t=a=>u.jsx(it,{...r,children:u.jsx(e,{...a})});return t.displayName=`withErrorBoundary(${e.displayName||e.name||"Component"})`,t}const he=x.createContext(null);he.displayName="CuadraChatContext";function ko(){const e=x.useContext(he);if(e===null)throw new Error("useCuadraChat must be used within a CuadraChatProvider. Wrap your component tree with <CuadraChatProvider>...</CuadraChatProvider>");return{controls:e.controls,isReady:e.controls!==null}}function Co(){const e=x.useContext(he);return e===null?null:{controls:e.controls,isReady:e.controls!==null}}function vo({children:e}){const[r,t]=x.useState(null),a=x.useCallback(n=>{t(n)},[]),i=x.useCallback(()=>{t(null)},[]),o={controls:r,registerControls:a,unregisterControls:i};return u.jsx(he.Provider,{value:o,children:e})}function pr(e){return"connection"in e&&typeof e.connection=="object"}function gr(e){return pr(e)?jo(e):To(e)}function jo(e){return{connection:{baseUrl:e.connection.baseUrl||"",proxyUrl:e.connection.proxyUrl||"",sessionToken:e.connection.sessionToken??null},chat:{mode:e.chat?.mode??"multiChat",modelMode:e.chat?.modelMode??"fixed",modelId:e.chat?.modelId??"",systemPrompt:e.chat?.systemPrompt??"",ephemeral:e.chat?.ephemeral??!1,enableReasoning:e.chat?.enableReasoning??!1,enableAttachments:e.chat?.enableAttachments??!1,initialThreadId:e.chat?.initialThreadId},ui:{theme:e.ui?.theme??"system",customTheme:e.ui?.customTheme,showThemeToggle:e.ui?.showThemeToggle??!0,language:e.ui?.language,welcomeTitle:e.ui?.welcomeTitle??"Hi, how can I help you today?",welcomeSubtitle:e.ui?.welcomeSubtitle??"Start exploring our platform and discover what you can build.",suggestions:e.ui?.suggestions,inputPlaceholder:e.ui?.inputPlaceholder??"Type your message...",extraTopPadding:e.ui?.extraTopPadding,borderless:e.ui?.borderless,safeArea:e.ui?.safeArea,orgName:e.ui?.orgName,primaryColor:e.ui?.primaryColor},preMade:{responseDelay:e.preMade?.responseDelay??1e3,streamingSpeed:e.preMade?.streamingSpeed??50},initial:{message:e.initial?.message,preMadeQA:e.initial?.preMadeQA},interceptors:{onBeforeRequest:e.interceptors?.onBeforeRequest,mockResponseOnBlocked:e.interceptors?.mockResponseOnBlocked},callbacks:{onChatCreated:e.callbacks?.onChatCreated,onError:e.callbacks?.onError,onUserMessage:e.callbacks?.onUserMessage,onModelChange:e.callbacks?.onModelChange,onThreadIdUpdate:e.callbacks?.onThreadIdUpdate,onLogout:e.callbacks?.onLogout},className:e.className,errorFallback:e.errorFallback}}function To(e){return typeof process<"u"&&process.env?.NODE_ENV==="development"&&console.warn(`[CuadraUIKit] Using legacy flat props format. Consider migrating to grouped props for better organization.
25
- See: https://docs.cuadra.ai/guides/uikit-migration`),{connection:{baseUrl:e.baseUrl||"",proxyUrl:e.proxyUrl||"",sessionToken:e.sessionToken??null},chat:{mode:e.mode??"multiChat",modelMode:e.modelMode??"fixed",modelId:e.modelId??"",systemPrompt:e.systemPrompt??"",ephemeral:e.ephemeral??!1,enableReasoning:e.enableReasoning??!1,enableAttachments:e.enableAttachments??!1,initialThreadId:e.initialThreadId},ui:{theme:e.theme??"system",customTheme:e.customTheme,showThemeToggle:e.showThemeToggle??!0,language:e.language,welcomeTitle:e.welcomeTitle??"Hi, how can I help you today?",welcomeSubtitle:e.welcomeSubtitle??"Start exploring our platform and discover what you can build.",suggestions:e.suggestions,inputPlaceholder:e.inputPlaceholder??"Type your message...",extraTopPadding:e.extraTopPadding,borderless:!1,safeArea:!1,orgName:void 0,primaryColor:void 0},preMade:{responseDelay:e.preMadeResponseDelay??1e3,streamingSpeed:e.streamingSpeed??50},initial:{message:e.initialMessage,preMadeQA:e.initialPreMadeQA},interceptors:{onBeforeRequest:e.onBeforeRequest,mockResponseOnBlocked:e.mockResponseOnBlocked},callbacks:{onChatCreated:e.onChatCreated,onError:e.onError,onUserMessage:e.onUserMessage,onModelChange:e.onModelChange,onThreadIdUpdate:e.onThreadIdUpdate,onLogout:e.onLogout},className:e.className,errorFallback:e.errorFallback}}const Mo=x.forwardRef(function({config:r},t){const a=x.useRef(null),i=x.useContext(he);x.useEffect(()=>{r.ui.customTheme&&hr(r.ui.customTheme)},[r.ui.customTheme]),x.useEffect(()=>{if(r.ui.primaryColor&&typeof document<"u"){const c=document.documentElement,s=d=>{const f=d.replace("#",""),l=parseInt(f.slice(0,2),16)/255,p=parseInt(f.slice(2,4),16)/255,g=parseInt(f.slice(4,6),16)/255,h=Math.max(l,p,g),y=Math.min(l,p,g);let b=0,w=0;const k=(h+y)/2;if(h!==y){const C=h-y;switch(w=k>.5?C/(2-h-y):C/(h+y),h){case l:b=((p-g)/C+(p<g?6:0))/6;break;case p:b=((g-l)/C+2)/6;break;case g:b=((l-p)/C+4)/6;break}}return`${Math.round(b*360)} ${Math.round(w*100)}% ${Math.round(k*100)}%`};try{const d=s(r.ui.primaryColor);c.style.setProperty("--primary",d),c.style.setProperty("--cuadra-primary",d)}catch{}return()=>{c.style.removeProperty("--primary"),c.style.removeProperty("--cuadra-primary")}}},[r.ui.primaryColor]);const o={sendMessage:c=>a.current?.sendMessage(c),sendPreMadeQA:(c,s,d)=>a.current?.sendPreMadeQA(c,s,d),clearChat:()=>a.current?.clearChat()};x.useImperativeHandle(t,()=>o,[]),x.useEffect(()=>{if(i)return i.registerControls(o),()=>i.unregisterControls()},[i,o]),x.useEffect(()=>(typeof window<"u"&&(process.env.NODE_ENV==="development"&&console.warn("[CuadraUIKit] window.__cuadraChatControls is deprecated. Use CuadraChatProvider and useCuadraChat() hook instead. See: https://docs.cuadra.ai/guides/uikit-migration"),window.__cuadraChatControls=o),()=>{typeof window<"u"&&delete window.__cuadraChatControls}),[o]);const n={baseUrl:r.connection.baseUrl||void 0,proxyUrl:r.connection.proxyUrl||void 0,sessionToken:r.connection.sessionToken,mode:r.chat.mode,modelMode:r.chat.modelMode,modelId:r.chat.modelId||void 0,systemPrompt:r.chat.systemPrompt||void 0,ephemeral:r.chat.ephemeral,enableReasoning:r.chat.enableReasoning,enableAttachments:r.chat.enableAttachments,initialThreadId:r.chat.initialThreadId,theme:r.ui.theme,showThemeToggle:r.ui.showThemeToggle,language:r.ui.language,welcomeTitle:r.ui.welcomeTitle,welcomeSubtitle:r.ui.welcomeSubtitle,suggestions:r.ui.suggestions,inputPlaceholder:r.ui.inputPlaceholder,extraTopPadding:r.ui.extraTopPadding,containerClass:r.className,borderless:r.ui.borderless,safeArea:r.ui.safeArea,preMadeResponseDelay:r.preMade.responseDelay,streamingSpeed:r.preMade.streamingSpeed,initialMessage:r.initial.message,initialPreMadeQA:r.initial.preMadeQA,onBeforeRequest:r.interceptors.onBeforeRequest,mockResponseOnBlocked:r.interceptors.mockResponseOnBlocked,onChatCreated:r.callbacks.onChatCreated,onError:r.callbacks.onError,onUserMessage:r.callbacks.onUserMessage,onModelChange:r.callbacks.onModelChange,onThreadIdUpdate:r.callbacks.onThreadIdUpdate,onLogout:r.callbacks.onLogout};return u.jsx(mo,{ref:a,config:n})}),Ao=x.forwardRef(function(r,t){const a=gr(r),i=a.errorFallback;return u.jsx(it,{fallback:i,onError:(o,n)=>{a.callbacks.onError?.(o),process.env.NODE_ENV==="development"&&console.error("[CuadraChat] Error caught by boundary:",o,n)},children:u.jsx(Mo,{ref:t,config:a})})});exports.AttachmentValidationError=be;exports.Badge=nt;exports.CuadraChat=Ao;exports.CuadraChatContext=he;exports.CuadraChatProvider=vo;exports.CuadraErrorBoundary=it;exports.SourceCitations=dr;exports.applyTheme=hr;exports.createAttachmentAdapter=Ze;exports.escapeHtml=ca;exports.generateSecureUUID=Rt;exports.isV2Props=pr;exports.isValidUrl=ia;exports.normalizeCuadraChatProps=gr;exports.removeTheme=bo;exports.sanitizeSystemPrompt=na;exports.streamingMetadataStore=Z;exports.useCuadraChat=ko;exports.useCuadraChatOptional=Co;exports.validateBaseUrl=oa;exports.withErrorBoundary=wo;
25
+ See: https://docs.cuadra.ai/guides/uikit-migration`),{connection:{baseUrl:e.baseUrl||"",proxyUrl:e.proxyUrl||"",sessionToken:e.sessionToken??null},chat:{mode:e.mode??"multiChat",modelMode:e.modelMode??"fixed",modelId:e.modelId??"",systemPrompt:e.systemPrompt??"",ephemeral:e.ephemeral??!1,enableReasoning:e.enableReasoning??!1,enableAttachments:e.enableAttachments??!1,initialThreadId:e.initialThreadId},ui:{theme:e.theme??"system",customTheme:e.customTheme,showThemeToggle:e.showThemeToggle??!0,language:e.language,welcomeTitle:e.welcomeTitle??"Hi, how can I help you today?",welcomeSubtitle:e.welcomeSubtitle??"Start exploring our platform and discover what you can build.",suggestions:e.suggestions,inputPlaceholder:e.inputPlaceholder??"Type your message...",extraTopPadding:e.extraTopPadding,borderless:!1,safeArea:!1,orgName:void 0,primaryColor:void 0},preMade:{responseDelay:e.preMadeResponseDelay??1e3,streamingSpeed:e.streamingSpeed??50},initial:{message:e.initialMessage,preMadeQA:e.initialPreMadeQA},interceptors:{onBeforeRequest:e.onBeforeRequest,mockResponseOnBlocked:e.mockResponseOnBlocked},callbacks:{onChatCreated:e.onChatCreated,onError:e.onError,onUserMessage:e.onUserMessage,onModelChange:e.onModelChange,onThreadIdUpdate:e.onThreadIdUpdate,onLogout:e.onLogout},className:e.className,errorFallback:e.errorFallback}}const Mo=x.forwardRef(function({config:r},t){const a=x.useRef(null),i=x.useContext(he);x.useEffect(()=>{r.ui.customTheme&&hr(r.ui.customTheme)},[r.ui.customTheme]),x.useEffect(()=>{if(r.ui.primaryColor&&typeof document<"u"){const c=document.documentElement,s=d=>{const f=d.replace("#",""),l=parseInt(f.slice(0,2),16)/255,p=parseInt(f.slice(2,4),16)/255,g=parseInt(f.slice(4,6),16)/255,h=Math.max(l,p,g),y=Math.min(l,p,g);let b=0,w=0;const k=(h+y)/2;if(h!==y){const C=h-y;switch(w=k>.5?C/(2-h-y):C/(h+y),h){case l:b=((p-g)/C+(p<g?6:0))/6;break;case p:b=((g-l)/C+2)/6;break;case g:b=((l-p)/C+4)/6;break}}return`${Math.round(b*360)} ${Math.round(w*100)}% ${Math.round(k*100)}%`};try{const d=s(r.ui.primaryColor);c.style.setProperty("--primary",d),c.style.setProperty("--cuadra-primary",`hsl(${d})`)}catch{}return()=>{c.style.removeProperty("--primary"),c.style.removeProperty("--cuadra-primary")}}},[r.ui.primaryColor]);const o={sendMessage:c=>a.current?.sendMessage(c),sendPreMadeQA:(c,s,d)=>a.current?.sendPreMadeQA(c,s,d),clearChat:()=>a.current?.clearChat()};x.useImperativeHandle(t,()=>o,[]),x.useEffect(()=>{if(i)return i.registerControls(o),()=>i.unregisterControls()},[i,o]),x.useEffect(()=>(typeof window<"u"&&(process.env.NODE_ENV==="development"&&console.warn("[CuadraUIKit] window.__cuadraChatControls is deprecated. Use CuadraChatProvider and useCuadraChat() hook instead. See: https://docs.cuadra.ai/guides/uikit-migration"),window.__cuadraChatControls=o),()=>{typeof window<"u"&&delete window.__cuadraChatControls}),[o]);const n={baseUrl:r.connection.baseUrl||void 0,proxyUrl:r.connection.proxyUrl||void 0,sessionToken:r.connection.sessionToken,mode:r.chat.mode,modelMode:r.chat.modelMode,modelId:r.chat.modelId||void 0,systemPrompt:r.chat.systemPrompt||void 0,ephemeral:r.chat.ephemeral,enableReasoning:r.chat.enableReasoning,enableAttachments:r.chat.enableAttachments,initialThreadId:r.chat.initialThreadId,theme:r.ui.theme,showThemeToggle:r.ui.showThemeToggle,language:r.ui.language,welcomeTitle:r.ui.welcomeTitle,welcomeSubtitle:r.ui.welcomeSubtitle,suggestions:r.ui.suggestions,inputPlaceholder:r.ui.inputPlaceholder,extraTopPadding:r.ui.extraTopPadding,containerClass:r.className,borderless:r.ui.borderless,safeArea:r.ui.safeArea,orgName:r.ui.orgName,primaryColor:r.ui.primaryColor,preMadeResponseDelay:r.preMade.responseDelay,streamingSpeed:r.preMade.streamingSpeed,initialMessage:r.initial.message,initialPreMadeQA:r.initial.preMadeQA,onBeforeRequest:r.interceptors.onBeforeRequest,mockResponseOnBlocked:r.interceptors.mockResponseOnBlocked,onChatCreated:r.callbacks.onChatCreated,onError:r.callbacks.onError,onUserMessage:r.callbacks.onUserMessage,onModelChange:r.callbacks.onModelChange,onThreadIdUpdate:r.callbacks.onThreadIdUpdate,onLogout:r.callbacks.onLogout};return u.jsx(mo,{ref:a,config:n})}),Ao=x.forwardRef(function(r,t){const a=gr(r),i=a.errorFallback;return u.jsx(it,{fallback:i,onError:(o,n)=>{a.callbacks.onError?.(o),process.env.NODE_ENV==="development"&&console.error("[CuadraChat] Error caught by boundary:",o,n)},children:u.jsx(Mo,{ref:t,config:a})})});exports.AttachmentValidationError=be;exports.Badge=nt;exports.CuadraChat=Ao;exports.CuadraChatContext=he;exports.CuadraChatProvider=vo;exports.CuadraErrorBoundary=it;exports.SourceCitations=dr;exports.applyTheme=hr;exports.createAttachmentAdapter=Ze;exports.escapeHtml=ca;exports.generateSecureUUID=Rt;exports.isV2Props=pr;exports.isValidUrl=ia;exports.normalizeCuadraChatProps=gr;exports.removeTheme=bo;exports.sanitizeSystemPrompt=na;exports.streamingMetadataStore=Z;exports.useCuadraChat=ko;exports.useCuadraChatOptional=Co;exports.validateBaseUrl=oa;exports.withErrorBoundary=wo;
26
26
  //# sourceMappingURL=index.cjs.map