totem-llm 0.3.2 → 0.3.4

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,3 +1,3 @@
1
1
  import{R as h,r as u,g as pe,B as Dn,E as Hn,j as e,u as K,G as Xt,K as en,z as Fe,M as ye,k as oe,t as ne,c as he,l as De,bg as $n,bh as We,W as Y,bi as yt,bj as St,h as Bn,bk as Ge,bl as Un,bm as Ye,a7 as G,bn as Wn,aS as Kn,aT as tn,a as fe,b9 as Ce,a4 as Te,at as jt,v as nn,p as rn,b4 as ae,bo as qn,ae as Et,aN as At,aK as Gn,x as He,I as et,bp as Me,s as Oe,aI as an,bq as Yn,Q as Qn,aH as Qe,ab as Jn,br as Xn,bs as er,V as tr,bt as nr,q as Ve,n as rr,aE as ar,bu as sr,i as ir,A as ge,m as xe,D as or}from"../index.js";import{I as lr,F as cr,c as ur,d as dr,e as hr,f as mr,h as pr,i as fr,j as gr,M as Nt,g as xr,b as br,a as vr,H as wr}from"./mcpServers-1686e782.js";import{u as yr,b as kt}from"./index-6bd7928a.js";import{A as we}from"./admin-04b020fe.js";import{A as Ct}from"./agentFlows-e4124dd3.js";import{P as Sr}from"./index-3cb59d82.js";import{C as jr}from"./WarningCircle-27467274.js";const Er=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M208.49,120.49a12,12,0,0,1-17,0L140,69V216a12,12,0,0,1-24,0V69L64.49,120.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,120.49Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M200,112H56l72-72Z",opacity:"0.2"}),h.createElement("path",{d:"M205.66,106.34l-72-72a8,8,0,0,0-11.32,0l-72,72A8,8,0,0,0,56,120h64v96a8,8,0,0,0,16,0V120h64a8,8,0,0,0,5.66-13.66ZM75.31,104,128,51.31,180.69,104Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M207.39,115.06A8,8,0,0,1,200,120H136v96a8,8,0,0,1-16,0V120H56a8,8,0,0,1-5.66-13.66l72-72a8,8,0,0,1,11.32,0l72,72A8,8,0,0,1,207.39,115.06Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M204.24,116.24a6,6,0,0,1-8.48,0L134,54.49V216a6,6,0,0,1-12,0V54.49L60.24,116.24a6,6,0,0,1-8.48-8.48l72-72a6,6,0,0,1,8.48,0l72,72A6,6,0,0,1,204.24,116.24Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M205.66,117.66a8,8,0,0,1-11.32,0L136,59.31V216a8,8,0,0,1-16,0V59.31L61.66,117.66a8,8,0,0,1-11.32-11.32l72-72a8,8,0,0,1,11.32,0l72,72A8,8,0,0,1,205.66,117.66Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M202.83,114.83a4,4,0,0,1-5.66,0L132,49.66V216a4,4,0,0,1-8,0V49.66L58.83,114.83a4,4,0,0,1-5.66-5.66l72-72a4,4,0,0,1,5.66,0l72,72A4,4,0,0,1,202.83,114.83Z"}))]]);var Ar=Object.defineProperty,Nr=Object.defineProperties,kr=Object.getOwnPropertyDescriptors,Mt=Object.getOwnPropertySymbols,Cr=Object.prototype.hasOwnProperty,Mr=Object.prototype.propertyIsEnumerable,Tt=(n,t,r)=>t in n?Ar(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,Tr=(n,t)=>{for(var r in t||(t={}))Cr.call(t,r)&&Tt(n,r,t[r]);if(Mt)for(var r of Mt(t))Mr.call(t,r)&&Tt(n,r,t[r]);return n},_r=(n,t)=>Nr(n,kr(t));const sn=u.forwardRef((n,t)=>h.createElement(pe,_r(Tr({ref:t},n),{weights:Er})));sn.displayName="ArrowUp";const Lr=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,20a108,108,0,0,0,0,216c22.27,0,45.69-6.73,62.64-18a12,12,0,1,0-13.29-20c-13,8.63-31.89,14-49.35,14a84,84,0,1,1,84-84c0,9.29-1.67,17.08-4.69,21.95-2.64,4.24-6,6.05-11.31,6.05s-8.67-1.81-11.31-6.05c-3-4.87-4.69-12.66-4.69-21.95V88a12,12,0,0,0-23.49-3.46,52,52,0,1,0,8.86,79.57C172.3,174.3,182.81,180,196,180c24.67,0,40-19.92,40-52A108.12,108.12,0,0,0,128,20Zm0,136a28,28,0,1,1,28-28A28,28,0,0,1,128,156Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M224,128a96,96,0,1,1-96-96A96,96,0,0,1,224,128Z",opacity:"0.2"}),h.createElement("path",{d:"M128,24a104,104,0,0,0,0,208c21.51,0,44.1-6.48,60.43-17.33a8,8,0,0,0-8.86-13.33C166,210.38,146.21,216,128,216a88,88,0,1,1,88-88c0,26.45-10.88,32-20,32s-20-5.55-20-32V88a8,8,0,0,0-16,0v4.26a48,48,0,1,0,5.93,65.1c6,12,16.35,18.64,30.07,18.64,22.54,0,36-17.94,36-48A104.11,104.11,0,0,0,128,24Zm0,136a32,32,0,1,1,32-32A32,32,0,0,1,128,160Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M232,128c0,.51,0,1,0,1.52-.34,14.26-5.63,30.48-28,30.48-23.14,0-28-17.4-28-32V88a8,8,0,0,0-8.53-8A8.17,8.17,0,0,0,160,88.27v4a48,48,0,1,0,6.73,64.05,40.19,40.19,0,0,0,3.38,5C175.48,168,185.71,176,204,176a54.81,54.81,0,0,0,9.22-.75,4,4,0,0,1,4.09,6A104.05,104.05,0,0,1,125.91,232C71.13,230.9,26.2,186.86,24.08,132.11A104,104,0,1,1,232,128ZM96,128a32,32,0,1,0,32-32A32,32,0,0,0,96,128Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,26a102,102,0,0,0,0,204c21.13,0,43.31-6.35,59.32-17a6,6,0,0,0-6.65-10c-13.9,9.25-34.09,15-52.67,15a90,90,0,1,1,90-90c0,29.58-13.78,34-22,34s-22-4.42-22-34V88a6,6,0,0,0-12,0v9a46,46,0,1,0,4.34,56.32C171.76,166.6,182,174,196,174c21.29,0,34-17.2,34-46A102.12,102.12,0,0,0,128,26Zm0,136a34,34,0,1,1,34-34A34,34,0,0,1,128,162Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,24a104,104,0,0,0,0,208c21.51,0,44.1-6.48,60.43-17.33a8,8,0,0,0-8.86-13.33C166,210.38,146.21,216,128,216a88,88,0,1,1,88-88c0,26.45-10.88,32-20,32s-20-5.55-20-32V88a8,8,0,0,0-16,0v4.26a48,48,0,1,0,5.93,65.1c6,12,16.35,18.64,30.07,18.64,22.54,0,36-17.94,36-48A104.11,104.11,0,0,0,128,24Zm0,136a32,32,0,1,1,32-32A32,32,0,0,1,128,160Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,28a100,100,0,0,0,0,200c20.76,0,42.52-6.23,58.21-16.66a4,4,0,1,0-4.43-6.67C167.35,214.27,147.24,220,128,220a92,92,0,1,1,92-92c0,31.32-15,36-24,36s-24-4.68-24-36V88a4,4,0,0,0-8,0v14.75a44,44,0,1,0,2.82,45.94C171.46,163.58,181.66,172,196,172c20,0,32-16.45,32-44A100.11,100.11,0,0,0,128,28Zm0,136a36,36,0,1,1,36-36A36,36,0,0,1,128,164Z"}))]]);var Pr=Object.defineProperty,Rr=Object.defineProperties,zr=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertySymbols,Vr=Object.prototype.hasOwnProperty,Or=Object.prototype.propertyIsEnumerable,Lt=(n,t,r)=>t in n?Pr(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,Ir=(n,t)=>{for(var r in t||(t={}))Vr.call(t,r)&&Lt(n,r,t[r]);if(_t)for(var r of _t(t))Or.call(t,r)&&Lt(n,r,t[r]);return n},Zr=(n,t)=>Rr(n,zr(t));const on=u.forwardRef((n,t)=>h.createElement(pe,Zr(Ir({ref:t},n),{weights:Lr})));on.displayName="At";const Fr=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M180.49,143.51a12,12,0,0,1,0,17l-24,24a12,12,0,0,1-17-17L155,152l-15.52-15.51a12,12,0,1,1,17-17Zm-64-24a12,12,0,0,0-17,0l-24,24a12,12,0,0,0,0,17l24,24a12,12,0,0,0,17-17L101,152l15.52-15.51A12,12,0,0,0,116.49,119.51ZM220,88V216a20,20,0,0,1-20,20H56a20,20,0,0,1-20-20V40A20,20,0,0,1,56,20h96a12,12,0,0,1,8.49,3.52l56,56A12,12,0,0,1,220,88ZM160,57V80h23Zm36,155V104H148a12,12,0,0,1-12-12V44H60V212Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M208,88H152V32Z",opacity:"0.2"}),h.createElement("path",{d:"M181.66,146.34a8,8,0,0,1,0,11.32l-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32Zm-72-24a8,8,0,0,0-11.32,0l-24,24a8,8,0,0,0,0,11.32l24,24a8,8,0,0,0,11.32-11.32L91.31,152l18.35-18.34A8,8,0,0,0,109.66,122.34ZM216,88V216a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-56-8h28.69L160,51.31Zm40,136V96H152a8,8,0,0,1-8-8V40H56V216H200Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34Zm-104,88a8,8,0,0,1-11.32,11.32l-24-24a8,8,0,0,1,0-11.32l24-24a8,8,0,0,1,11.32,11.32L91.31,152Zm72-12.68-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32l24,24A8,8,0,0,1,181.66,157.66ZM152,88V44l44,44Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M180.24,147.76a6,6,0,0,1,0,8.48l-24,24a6,6,0,0,1-8.48-8.48L167.51,152l-19.75-19.76a6,6,0,1,1,8.48-8.48Zm-72-24a6,6,0,0,0-8.48,0l-24,24a6,6,0,0,0,0,8.48l24,24a6,6,0,1,0,8.48-8.48L88.49,152l19.75-19.76A6,6,0,0,0,108.24,123.76ZM214,88V216a14,14,0,0,1-14,14H56a14,14,0,0,1-14-14V40A14,14,0,0,1,56,26h96a6,6,0,0,1,4.25,1.76l56,56A6,6,0,0,1,214,88Zm-56-6h35.52L158,46.48Zm44,134V94H152a6,6,0,0,1-6-6V38H56a2,2,0,0,0-2,2V216a2,2,0,0,0,2,2H200A2,2,0,0,0,202,216Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M181.66,146.34a8,8,0,0,1,0,11.32l-24,24a8,8,0,0,1-11.32-11.32L164.69,152l-18.35-18.34a8,8,0,0,1,11.32-11.32Zm-72-24a8,8,0,0,0-11.32,0l-24,24a8,8,0,0,0,0,11.32l24,24a8,8,0,0,0,11.32-11.32L91.31,152l18.35-18.34A8,8,0,0,0,109.66,122.34ZM216,88V216a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-56-8h28.69L160,51.31Zm40,136V96H152a8,8,0,0,1-8-8V40H56V216H200Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M178.83,149.17a4,4,0,0,1,0,5.66l-24,24a4,4,0,0,1-5.66-5.66L170.34,152l-21.17-21.17a4,4,0,1,1,5.66-5.66Zm-72-24a4,4,0,0,0-5.66,0l-24,24a4,4,0,0,0,0,5.66l24,24a4,4,0,1,0,5.66-5.66L85.66,152l21.17-21.17A4,4,0,0,0,106.83,125.17ZM212,88V216a12,12,0,0,1-12,12H56a12,12,0,0,1-12-12V40A12,12,0,0,1,56,28h96a4,4,0,0,1,2.83,1.17l56,56A4,4,0,0,1,212,88Zm-56-4h42.34L156,41.65Zm48,132V92H152a4,4,0,0,1-4-4V36H56a4,4,0,0,0-4,4V216a4,4,0,0,0,4,4H200A4,4,0,0,0,204,216Z"}))]]);var Dr=Object.defineProperty,Hr=Object.defineProperties,$r=Object.getOwnPropertyDescriptors,Pt=Object.getOwnPropertySymbols,Br=Object.prototype.hasOwnProperty,Ur=Object.prototype.propertyIsEnumerable,Rt=(n,t,r)=>t in n?Dr(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,Wr=(n,t)=>{for(var r in t||(t={}))Br.call(t,r)&&Rt(n,r,t[r]);if(Pt)for(var r of Pt(t))Ur.call(t,r)&&Rt(n,r,t[r]);return n},Kr=(n,t)=>Hr(n,$r(t));const ln=u.forwardRef((n,t)=>h.createElement(pe,Kr(Wr({ref:t},n),{weights:Fr})));ln.displayName="FileCode";const qr=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M48,180c0,8.67,5.49,16,12,16a10.27,10.27,0,0,0,7.33-3.43,12,12,0,1,1,17.34,16.6A34,34,0,0,1,60,220C40.15,220,24,202,24,180s16.15-40,36-40a34,34,0,0,1,24.67,10.83,12,12,0,1,1-17.34,16.6A10.27,10.27,0,0,0,60,164C53.49,164,48,171.31,48,180Zm97.51-5.71c-5.13-3.45-11.33-5.24-16.8-6.82a79.5,79.5,0,0,1-7.91-2.59c2.45-1.18,9.71-1.3,16.07.33A12,12,0,0,0,143,142a69.24,69.24,0,0,0-12-1.86c-9.93-.66-18,1.08-24.1,5.17a24.45,24.45,0,0,0-10.69,17.76c-1.1,8.74,2.48,16.27,10.11,21.19,4.78,3.09,10.36,4.7,15.75,6.26,3,.89,7.94,2.3,9.88,3.53a2,2,0,0,1-.22.71c-1.36,1.55-9.57,1.79-16.39-.06a12,12,0,0,0-6.45,23.11A63.73,63.73,0,0,0,125.09,220c6.47,0,13.74-1.17,19.74-5.15a24.73,24.73,0,0,0,10.95-18C157,187.53,153.32,179.53,145.51,174.27ZM216,140.68A12,12,0,0,0,200.7,148L192,172.3,183.3,148A12,12,0,1,0,160.7,156l20,56a12,12,0,0,0,22.6,0l20-56A12,12,0,0,0,216,140.68ZM36,108V40A20,20,0,0,1,56,20h96a12,12,0,0,1,8.49,3.51l56,56A12,12,0,0,1,220,88v20a12,12,0,1,1-24,0v-4H148a12,12,0,0,1-12-12V44H60v64a12,12,0,1,1-24,0ZM160,80h23L160,57Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M208,88H152V32Z",opacity:"0.2"}),h.createElement("path",{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.83-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40v76a4,4,0,0,0,4,4H212a4,4,0,0,0,4-4V88A8,8,0,0,0,213.66,82.34ZM152,88V44l44,44ZM48,180c0,11,7.18,20,16,20a14.18,14.18,0,0,0,10.06-4.5,8.21,8.21,0,0,1,10.9-.91,8,8,0,0,1,.82,11.81A30.06,30.06,0,0,1,64,216c-17.64,0-32-16.15-32-36s14.36-36,32-36a30,30,0,0,1,21.39,9.19,8.26,8.26,0,0,1,.73,11.09,8,8,0,0,1-11.9.38A14.17,14.17,0,0,0,64,160C55.18,160,48,169,48,180Zm103.81,16.31a20.82,20.82,0,0,1-9.19,15.23C137.43,215,131,216,125.13,216A61.14,61.14,0,0,1,110,214a8,8,0,1,1,4.3-15.41c4.38,1.2,14.95,2.7,19.55-.36.88-.59,1.83-1.52,2.14-3.93.35-2.67-.71-4.1-12.78-7.59-9.35-2.7-25-7.23-23-23.11a20.56,20.56,0,0,1,9-14.95c11.84-8,30.71-3.31,32.83-2.76a8,8,0,0,1-4.07,15.48c-4.49-1.17-15.23-2.56-19.83.56a4.54,4.54,0,0,0-2,3.67c-.12.9-.14,1.09,1.11,1.9,2.31,1.49,6.45,2.68,10.45,3.84C137.49,174.17,154.05,179,151.81,196.31ZM215.42,155l-19.89,55.68a8,8,0,0,1-15.06,0L160.58,155a8.21,8.21,0,0,1,4.5-10.45,8,8,0,0,1,10.45,4.76L188,184.21l12.47-34.9a8,8,0,0,1,10.45-4.76A8.23,8.23,0,0,1,215.42,155Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M46,180c0,12.13,8.07,22,18,22a16.24,16.24,0,0,0,11.67-5.28,6,6,0,0,1,8.66,8.3A28.06,28.06,0,0,1,64,214c-16.54,0-30-15.25-30-34s13.46-34,30-34a28.06,28.06,0,0,1,20.33,9,6,6,0,0,1-8.66,8.3A16.23,16.23,0,0,0,64,158C54.07,158,46,167.86,46,180Zm81.05-6.77c-10.86-3.13-13.41-4.69-13-7.91a6.59,6.59,0,0,1,2.88-5.08c5.6-3.79,17.66-1.82,21.45-.84a6,6,0,0,0,3.06-11.6c-2-.53-20.1-5-31.21,2.48a18.61,18.61,0,0,0-8.08,13.54c-1.8,14.19,12.26,18.25,21.57,20.94,12.12,3.5,14.78,5.33,14.2,9.76a6.85,6.85,0,0,1-3,5.34c-5.61,3.73-17.48,1.64-21.19.62A6,6,0,0,0,110.48,212a59.41,59.41,0,0,0,14.68,2c5.49,0,11.54-.95,16.36-4.14a18.89,18.89,0,0,0,8.31-13.81C151.84,180.39,136.92,176.08,127.05,173.22Zm83-26.88a6,6,0,0,0-7.67,3.63L188,190.15,173.65,150a6,6,0,1,0-11.3,4l20,56a6,6,0,0,0,11.3,0l20-56A6,6,0,0,0,210,146.34ZM214,88v24a6,6,0,1,1-12,0V94H152a6,6,0,0,1-6-6V38H56a2,2,0,0,0-2,2v72a6,6,0,1,1-12,0V40A14,14,0,0,1,56,26h96a6,6,0,0,1,4.24,1.76l56,56A6,6,0,0,1,214,88Zm-20.49-6L158,46.48V82Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M44,180c0,13.23,9,24,20,24a18.15,18.15,0,0,0,13.11-5.9,4,4,0,1,1,5.78,5.54A26.11,26.11,0,0,1,64,212c-15.44,0-28-14.36-28-32s12.56-32,28-32a26.11,26.11,0,0,1,18.89,8.36,4,4,0,1,1-5.78,5.54A18.15,18.15,0,0,0,64,156C53,156,44,166.77,44,180Zm82.49-4.85c-10.53-3-15.08-4.91-14.42-10.08a8.51,8.51,0,0,1,3.75-6.49c6.25-4.23,18.77-2.24,23.06-1.11a4,4,0,0,0,2-7.74,61.11,61.11,0,0,0-10.47-1.61c-8.12-.54-14.54.75-19.1,3.82a16.66,16.66,0,0,0-7.22,12.13c-1.58,12.49,10.46,16,20.14,18.77,11.26,3.25,16.47,5.49,15.64,11.94a8.94,8.94,0,0,1-3.91,6.75c-6.27,4.17-18.61,2.05-22.83.88a4,4,0,1,0-2.15,7.7A57.89,57.89,0,0,0,125.19,212c5.18,0,10.83-.86,15.22-3.77a17,17,0,0,0,7.43-12.41C149.64,181.84,136.26,178,126.49,175.15Zm82.85-26.92a4,4,0,0,0-5.11,2.42L188,196.11l-16.23-45.46a4,4,0,1,0-7.54,2.7l20,56a4,4,0,0,0,7.54,0l20-56A4,4,0,0,0,209.34,148.23ZM212,88v24a4,4,0,0,1-8,0V92H152a4,4,0,0,1-4-4V36H56a4,4,0,0,0-4,4v72a4,4,0,0,1-8,0V40A12,12,0,0,1,56,28h96a4,4,0,0,1,2.83,1.17l56,56A4,4,0,0,1,212,88Zm-13.66-4L156,41.65V84Z"}))]]);var Gr=Object.defineProperty,Yr=Object.defineProperties,Qr=Object.getOwnPropertyDescriptors,zt=Object.getOwnPropertySymbols,Jr=Object.prototype.hasOwnProperty,Xr=Object.prototype.propertyIsEnumerable,Vt=(n,t,r)=>t in n?Gr(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,ea=(n,t)=>{for(var r in t||(t={}))Jr.call(t,r)&&Vt(n,r,t[r]);if(zt)for(var r of zt(t))Xr.call(t,r)&&Vt(n,r,t[r]);return n},ta=(n,t)=>Yr(n,Qr(t));const cn=u.forwardRef((n,t)=>h.createElement(pe,ta(ea({ref:t},n),{weights:qr})));cn.displayName="FileCsv";const na=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M48,128a12,12,0,0,0,12-12V44h76V92a12,12,0,0,0,12,12h48v12a12,12,0,0,0,24,0V88a12,12,0,0,0-3.51-8.49l-56-56A12,12,0,0,0,152,20H56A20,20,0,0,0,36,40v76A12,12,0,0,0,48,128ZM183,80H160V57ZM68,160v48a12,12,0,0,1-24,0V196H32v12a12,12,0,0,1-24,0V160a12,12,0,0,1,24,0v12H44V160a12,12,0,0,1,24,0Zm60,0a12,12,0,0,1-12,12h-4v36a12,12,0,0,1-24,0V172H84a12,12,0,0,1,0-24h32A12,12,0,0,1,128,160Zm72,0v48a12,12,0,0,1-24,0v-9.36l-.11.16a12,12,0,0,1-19.78,0l-.11-.16V208a12,12,0,0,1-24,0V160a12,12,0,0,1,21.89-6.8L166,170.82l12.11-17.62A12,12,0,0,1,200,160Zm56,48a12,12,0,0,1-12,12H220a12,12,0,0,1-12-12V160a12,12,0,0,1,24,0v36h12A12,12,0,0,1,256,208Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M208,88H152V32Z",opacity:"0.2"}),h.createElement("path",{d:"M216,120V88a8,8,0,0,0-2.34-5.66l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40v80a8,8,0,0,0,16,0V40h88V88a8,8,0,0,0,8,8h48v24a8,8,0,0,0,16,0ZM160,51.31,188.69,80H160ZM68,160v48a8,8,0,0,1-16,0V192H32v16a8,8,0,0,1-16,0V160a8,8,0,0,1,16,0v16H52V160a8,8,0,0,1,16,0Zm56,0a8,8,0,0,1-8,8h-8v40a8,8,0,0,1-16,0V168H84a8,8,0,0,1,0-16h32A8,8,0,0,1,124,160Zm72,0v48a8,8,0,0,1-16,0V184l-9.6,12.8a8,8,0,0,1-12.8,0L148,184v24a8,8,0,0,1-16,0V160a8,8,0,0,1,14.4-4.8L164,178.67l17.6-23.47A8,8,0,0,1,196,160Zm56,48a8,8,0,0,1-8,8H216a8,8,0,0,1-8-8V160a8,8,0,0,1,16,0v40h20A8,8,0,0,1,252,208Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M44,128H212a4,4,0,0,0,4-4V88a8,8,0,0,0-2.34-5.66l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40v84A4,4,0,0,0,44,128ZM152,44l44,44H152ZM68,160v48a8,8,0,0,1-16,0V192H32v16a8,8,0,0,1-16,0V160a8,8,0,0,1,16,0v16H52V160a8,8,0,0,1,16,0Zm56,0a8,8,0,0,1-8,8h-8v40a8,8,0,0,1-16,0V168H84a8,8,0,0,1,0-16h32A8,8,0,0,1,124,160Zm72,0v48a8,8,0,0,1-16,0V184l-9.6,12.8a8,8,0,0,1-12.8,0L148,184v24a8,8,0,0,1-16,0V160a8,8,0,0,1,14.4-4.8L164,178.67l17.6-23.47A8,8,0,0,1,196,160Zm56,48a8,8,0,0,1-8,8H216a8,8,0,0,1-8-8V160a8,8,0,0,1,16,0v40h20A8,8,0,0,1,252,208Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M214,120V88a6,6,0,0,0-1.76-4.24l-56-56A6,6,0,0,0,152,26H56A14,14,0,0,0,42,40v80a6,6,0,0,0,12,0V40a2,2,0,0,1,2-2h90V88a6,6,0,0,0,6,6h50v26a6,6,0,0,0,12,0ZM158,46.48,193.52,82H158ZM66,160v48a6,6,0,0,1-12,0V190H30v18a6,6,0,0,1-12,0V160a6,6,0,0,1,12,0v18H54V160a6,6,0,0,1,12,0Zm56,0a6,6,0,0,1-6,6H106v42a6,6,0,0,1-12,0V166H84a6,6,0,0,1,0-12h32A6,6,0,0,1,122,160Zm72,0v48a6,6,0,0,1-12,0V178l-13.2,17.6a6,6,0,0,1-9.6,0L146,178v30a6,6,0,0,1-12,0V160a6,6,0,0,1,10.8-3.6L164,182l19.2-25.6A6,6,0,0,1,194,160Zm56,48a6,6,0,0,1-6,6H216a6,6,0,0,1-6-6V160a6,6,0,0,1,12,0v42h22A6,6,0,0,1,250,208Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M216,120V88a8,8,0,0,0-2.34-5.66l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40v80a8,8,0,0,0,16,0V40h88V88a8,8,0,0,0,8,8h48v24a8,8,0,0,0,16,0ZM160,51.31,188.69,80H160ZM68,160v48a8,8,0,0,1-16,0V192H32v16a8,8,0,0,1-16,0V160a8,8,0,0,1,16,0v16H52V160a8,8,0,0,1,16,0Zm56,0a8,8,0,0,1-8,8h-8v40a8,8,0,0,1-16,0V168H84a8,8,0,0,1,0-16h32A8,8,0,0,1,124,160Zm72,0v48a8,8,0,0,1-16,0V184l-9.6,12.8a8,8,0,0,1-12.8,0L148,184v24a8,8,0,0,1-16,0V160a8,8,0,0,1,14.4-4.8L164,178.67l17.6-23.47A8,8,0,0,1,196,160Zm56,48a8,8,0,0,1-8,8H216a8,8,0,0,1-8-8V160a8,8,0,0,1,16,0v40h20A8,8,0,0,1,252,208Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M212,88a4,4,0,0,0-1.17-2.83l-2-2h0l-54-54A4,4,0,0,0,152,28H56A12,12,0,0,0,44,40v80a4,4,0,0,0,8,0V40a4,4,0,0,1,4-4h92V88a4,4,0,0,0,4,4h52v28a4,4,0,0,0,8,0ZM156,41.65,198.34,84H156ZM64,160v48a4,4,0,0,1-8,0V188H28v20a4,4,0,0,1-8,0V160a4,4,0,0,1,8,0v20H56V160a4,4,0,0,1,8,0Zm56,0a4,4,0,0,1-4,4H104v44a4,4,0,0,1-8,0V164H84a4,4,0,0,1,0-8h32A4,4,0,0,1,120,160Zm72,0v48a4,4,0,0,1-8,0V172l-16.8,22.4a4,4,0,0,1-6.4,0L144,172v36a4,4,0,0,1-8,0V160a4,4,0,0,1,7.2-2.4L164,185.33l20.8-27.73A4,4,0,0,1,192,160Zm56,48a4,4,0,0,1-4,4H216a4,4,0,0,1-4-4V160a4,4,0,0,1,8,0v44h24A4,4,0,0,1,248,208Z"}))]]);var ra=Object.defineProperty,aa=Object.defineProperties,sa=Object.getOwnPropertyDescriptors,Ot=Object.getOwnPropertySymbols,ia=Object.prototype.hasOwnProperty,oa=Object.prototype.propertyIsEnumerable,It=(n,t,r)=>t in n?ra(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,la=(n,t)=>{for(var r in t||(t={}))ia.call(t,r)&&It(n,r,t[r]);if(Ot)for(var r of Ot(t))oa.call(t,r)&&It(n,r,t[r]);return n},ca=(n,t)=>aa(n,sa(t));const un=u.forwardRef((n,t)=>h.createElement(pe,ca(la({ref:t},n),{weights:na})));un.displayName="FileHtml";const ua=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M114,145.34a12,12,0,0,0-20,0L79,167.82,72.3,157.73a12,12,0,0,0-20.07.17L13.91,217.51A12,12,0,0,0,24,236H152a12,12,0,0,0,10-18.66ZM46,212,62.5,186.3l6.55,9.81a12,12,0,0,0,20,0l15-22.48L129.58,212ZM216.49,79.51l-56-56A12,12,0,0,0,152,20H56A20,20,0,0,0,36,40v84a12,12,0,0,0,24,0V44h76V92a12,12,0,0,0,12,12h48V212a12,12,0,0,0,0,24h4a20,20,0,0,0,20-20V88A12,12,0,0,0,216.49,79.51ZM160,57l23,23H160Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M104,152l48,72H24l36-56,16.36,25.45ZM152,32V88h56Z",opacity:"0.2"}),h.createElement("path",{d:"M110.66,147.56a8,8,0,0,0-13.32,0L76.49,178.85l-9.76-15.18a8,8,0,0,0-13.46,0l-36,56A8,8,0,0,0,24,232H152a8,8,0,0,0,6.66-12.44ZM38.65,216,60,182.79l9.63,15a8,8,0,0,0,13.39.11l21-31.47L137.05,216Zm175-133.66-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40v88a8,8,0,0,0,16,0V40h88V88a8,8,0,0,0,8,8h48V216h-8a8,8,0,0,0,0,16h8a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34ZM160,51.31,188.69,80H160Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M158.66,219.56A8,8,0,0,1,152,232H24a8,8,0,0,1-6.73-12.33l36-56a8,8,0,0,1,13.46,0l9.76,15.18,20.85-31.29a8,8,0,0,1,13.32,0ZM216,88V216a16,16,0,0,1-16,16h-8a8,8,0,0,1,0-16h8V96H152a8,8,0,0,1-8-8V40H56v88a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-56-8h28.69L160,51.31Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M109,148.67a6,6,0,0,0-10,0L76.46,182.5,65.05,164.76a6,6,0,0,0-10.1,0l-36,56A6,6,0,0,0,24,230H152a6,6,0,0,0,5-9.33ZM35,218l25-38.9,11.32,17.6a6,6,0,0,0,10,.08l22.64-34L140.79,218ZM212.24,83.76l-56-56A6,6,0,0,0,152,26H56A14,14,0,0,0,42,40v88a6,6,0,0,0,12,0V40a2,2,0,0,1,2-2h90V88a6,6,0,0,0,6,6h50V216a2,2,0,0,1-2,2h-8a6,6,0,0,0,0,12h8a14,14,0,0,0,14-14V88A6,6,0,0,0,212.24,83.76ZM158,46.48,193.52,82H158Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M110.66,147.56a8,8,0,0,0-13.32,0L76.49,178.85l-9.76-15.18a8,8,0,0,0-13.46,0l-36,56A8,8,0,0,0,24,232H152a8,8,0,0,0,6.66-12.44ZM38.65,216,60,182.79l9.63,15a8,8,0,0,0,13.39.11l21-31.47L137.05,216Zm175-133.66-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40v88a8,8,0,0,0,16,0V40h88V88a8,8,0,0,0,8,8h48V216h-8a8,8,0,0,0,0,16h8a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34ZM160,51.31,188.69,80H160Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M107.33,149.78a4,4,0,0,0-6.66,0L76.42,186.15,63.36,165.84a4,4,0,0,0-6.72,0l-36,56A4,4,0,0,0,24,228H152a4,4,0,0,0,3.33-6.22ZM31.33,220,60,175.4l13,20.22a4,4,0,0,0,3.33,1.83,3.93,3.93,0,0,0,3.36-1.78L104,159.21,144.53,220ZM210.83,85.17l-56-56A4,4,0,0,0,152,28H56A12,12,0,0,0,44,40v88a4,4,0,0,0,8,0V40a4,4,0,0,1,4-4h92V88a4,4,0,0,0,4,4h52V216a4,4,0,0,1-4,4h-8a4,4,0,0,0,0,8h8a12,12,0,0,0,12-12V88A4,4,0,0,0,210.83,85.17ZM156,41.65,198.34,84H156Z"}))]]);var da=Object.defineProperty,ha=Object.defineProperties,ma=Object.getOwnPropertyDescriptors,Zt=Object.getOwnPropertySymbols,pa=Object.prototype.hasOwnProperty,fa=Object.prototype.propertyIsEnumerable,Ft=(n,t,r)=>t in n?da(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,ga=(n,t)=>{for(var r in t||(t={}))pa.call(t,r)&&Ft(n,r,t[r]);if(Zt)for(var r of Zt(t))fa.call(t,r)&&Ft(n,r,t[r]);return n},xa=(n,t)=>ha(n,ma(t));const dn=u.forwardRef((n,t)=>h.createElement(pe,xa(ga({ref:t},n),{weights:ua})));dn.displayName="FileImage";const ba=new Map([["bold",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,180a52.06,52.06,0,0,0,52-52V64A52,52,0,0,0,76,64v64A52.06,52.06,0,0,0,128,180ZM100,64a28,28,0,0,1,56,0v64a28,28,0,0,1-56,0Zm40,155.22V240a12,12,0,0,1-24,0V219.22A92.14,92.14,0,0,1,36,128a12,12,0,0,1,24,0,68,68,0,0,0,136,0,12,12,0,0,1,24,0A92.14,92.14,0,0,1,140,219.22Z"}))],["duotone",h.createElement(h.Fragment,null,h.createElement("path",{d:"M168,64v64a40,40,0,0,1-40,40h0a40,40,0,0,1-40-40V64a40,40,0,0,1,40-40h0A40,40,0,0,1,168,64Z",opacity:"0.2"}),h.createElement("path",{d:"M128,176a48.05,48.05,0,0,0,48-48V64a48,48,0,0,0-96,0v64A48.05,48.05,0,0,0,128,176ZM96,64a32,32,0,0,1,64,0v64a32,32,0,0,1-64,0Zm40,143.6V240a8,8,0,0,1-16,0V207.6A80.11,80.11,0,0,1,48,128a8,8,0,0,1,16,0,64,64,0,0,0,128,0,8,8,0,0,1,16,0A80.11,80.11,0,0,1,136,207.6Z"}))],["fill",h.createElement(h.Fragment,null,h.createElement("path",{d:"M80,128V64a48,48,0,0,1,96,0v64a48,48,0,0,1-96,0Zm128,0a8,8,0,0,0-16,0,64,64,0,0,1-128,0,8,8,0,0,0-16,0,80.11,80.11,0,0,0,72,79.6V240a8,8,0,0,0,16,0V207.6A80.11,80.11,0,0,0,208,128Z"}))],["light",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,174a46.06,46.06,0,0,0,46-46V64a46,46,0,0,0-92,0v64A46.06,46.06,0,0,0,128,174ZM94,64a34,34,0,0,1,68,0v64a34,34,0,0,1-68,0Zm40,141.75V240a6,6,0,0,1-12,0V205.75A78.09,78.09,0,0,1,50,128a6,6,0,0,1,12,0,66,66,0,0,0,132,0,6,6,0,0,1,12,0A78.09,78.09,0,0,1,134,205.75Z"}))],["regular",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,176a48.05,48.05,0,0,0,48-48V64a48,48,0,0,0-96,0v64A48.05,48.05,0,0,0,128,176ZM96,64a32,32,0,0,1,64,0v64a32,32,0,0,1-64,0Zm40,143.6V240a8,8,0,0,1-16,0V207.6A80.11,80.11,0,0,1,48,128a8,8,0,0,1,16,0,64,64,0,0,0,128,0,8,8,0,0,1,16,0A80.11,80.11,0,0,1,136,207.6Z"}))],["thin",h.createElement(h.Fragment,null,h.createElement("path",{d:"M128,172a44.05,44.05,0,0,0,44-44V64a44,44,0,0,0-88,0v64A44.05,44.05,0,0,0,128,172ZM92,64a36,36,0,0,1,72,0v64a36,36,0,0,1-72,0Zm40,139.89V240a4,4,0,0,1-8,0V203.89A76.09,76.09,0,0,1,52,128a4,4,0,0,1,8,0,68,68,0,0,0,136,0,4,4,0,0,1,8,0A76.09,76.09,0,0,1,132,203.89Z"}))]]);var va=Object.defineProperty,wa=Object.defineProperties,ya=Object.getOwnPropertyDescriptors,Dt=Object.getOwnPropertySymbols,Sa=Object.prototype.hasOwnProperty,ja=Object.prototype.propertyIsEnumerable,Ht=(n,t,r)=>t in n?va(n,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[t]=r,Ea=(n,t)=>{for(var r in t||(t={}))Sa.call(t,r)&&Ht(n,r,t[r]);if(Dt)for(var r of Dt(t))ja.call(t,r)&&Ht(n,r,t[r]);return n},Aa=(n,t)=>wa(n,ya(t));const hn=u.forwardRef((n,t)=>h.createElement(pe,Aa(Ea({ref:t},n),{weights:ba})));hn.displayName="Microphone";function Na({provider:n,setHasChanges:t,selectedLLMModel:r,setSelectedLLMModel:a}){const{defaultModels:o,customModels:i,loading:s}=Dn(n);return Hn.includes(n)?null:s?e.jsx("select",{required:!0,disabled:!0,className:"bg-zinc-900 light:bg-white text-white light:text-slate-900 text-sm rounded-lg h-8 w-full px-2.5 outline-none border border-zinc-900 light:border-slate-400 cursor-not-allowed",children:e.jsx("option",{disabled:!0,selected:!0,children:"-- waiting for models --"})}):e.jsxs("select",{id:"workspace-llm-model-select",required:!0,value:r,onChange:c=>{t(!0),a(c.target.value)},className:"bg-zinc-900 light:bg-white text-white light:text-slate-900 text-sm rounded-lg h-8 w-full px-2.5 outline-none border border-zinc-900 light:border-slate-400 cursor-pointer",children:[o.length>0&&e.jsx("optgroup",{label:"General models",children:o.map(c=>e.jsx("option",{value:c,selected:r===c,children:c},c))}),Array.isArray(i)&&i.length>0&&e.jsx("optgroup",{label:"Discovered models",children:i.map(c=>e.jsx("option",{value:c.id,selected:r===c.id,children:c.name||c.id},c.id))}),!Array.isArray(i)&&Object.keys(i).length>0&&e.jsx(e.Fragment,{children:Object.entries(i).map(([c,d])=>e.jsx("optgroup",{label:c,children:d.map(g=>e.jsx("option",{value:g.id,selected:r===g.id,children:g.name},g.id))},c))})]})}function ka({selectedRouterId:n,setSelectedRouterId:t,setHasChanges:r}){const{t:a}=K(),[o,i]=u.useState([]),[s,c]=u.useState(!0);return u.useEffect(()=>{async function d(){const g=await Xt.getAll();i(g),c(!1)}d()},[]),s?e.jsx("select",{disabled:!0,className:"bg-zinc-900 light:bg-white text-white light:text-slate-900 text-sm rounded-lg h-8 w-full px-2.5 outline-none border border-zinc-900 light:border-slate-400 cursor-not-allowed",children:e.jsx("option",{children:a("model-router.router-selection.loading-routers")})}):o.length===0?e.jsx("p",{className:"text-xs text-zinc-400 light:text-slate-500",children:a("model-router.router-selection.no-routers-chat")}):e.jsxs("select",{value:n||"",onChange:d=>{t(Number(d.target.value)),r(!0)},className:"bg-zinc-900 light:bg-white text-white light:text-slate-900 text-sm rounded-lg h-8 w-full px-2.5 outline-none border border-zinc-900 light:border-slate-400 cursor-pointer",children:[e.jsx("option",{value:"",children:a("model-router.router-selection.select-router")}),o.map(d=>e.jsxs("option",{value:d.id,children:[d.name,d.ruleCount!=null?` ${a("model-router.router-selection.rule-count",{count:d.ruleCount})}`:""]},d.id))]})}function Ca({availableProviders:n,selectedLLMProvider:t,onSearchChange:r,onProviderClick:a}){const{t:o}=K();return e.jsxs("div",{className:"w-[40%] h-full flex flex-col gap-4 p-2 border-r border-zinc-700 light:border-slate-300",children:[e.jsxs("div",{className:"relative shrink-0 mx-2",children:[e.jsx(en,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-zinc-400 light:text-slate-400",weight:"bold"}),e.jsx("input",{id:"llm-search-input",type:"search",placeholder:o("chat_window.workspace_llm_manager.search"),onChange:r,className:"bg-zinc-900 light:bg-white text-white light:text-slate-900 placeholder:text-zinc-500 light:placeholder:text-slate-400 text-sm rounded-lg pl-8 pr-2.5 h-8 w-full outline-none border border-zinc-900 light:border-slate-400"})]}),e.jsx("div",{className:"flex flex-col gap-0 overflow-y-auto min-h-0 flex-1",children:n.map(i=>e.jsxs("button",{type:"button","data-llm-value":i.value,className:`border-none cursor-pointer flex gap-2 items-center px-2.5 py-1.5 rounded-md transition-colors ${t===i.value?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700/50 light:hover:bg-slate-100 bg-transparent"}`,onClick:()=>a(i.value),children:[e.jsx("img",{src:i.logo,alt:`${i.name} logo`,className:"w-6 h-6 rounded"}),e.jsx("span",{className:"text-sm text-white light:text-slate-900",children:i.name})]},i.value))})]})}function Ma({isOpen:n,closeModal:t,postSubmit:r,settings:a,llmProvider:o}){if(!n)return null;async function i(s){s.preventDefault(),s.stopPropagation();const c={},d=new FormData(s.target);for(var[g,w]of d.entries())c[g]=w;const{error:m}=await ne.updateSystem(c);if(m){he(`Failed to save ${o.name} settings: ${m}`,"error");return}return t(),r(),!1}return Fe.createPortal(e.jsx(ye,{isOpen:n,children:e.jsx("div",{className:"fixed inset-0 z-50 overflow-auto bg-black bg-opacity-50 flex items-center justify-center",children:e.jsxs("div",{className:"relative w-full max-w-2xl bg-theme-bg-secondary rounded-lg shadow border-2 border-theme-modal-border",children:[e.jsxs("div",{className:"relative p-6 border-b rounded-t border-theme-modal-border",children:[e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsxs("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:[o.name," Settings"]})}),e.jsx("button",{onClick:t,type:"button",className:"absolute top-4 right-4 transition-all duration-300 bg-transparent rounded-lg text-sm p-1 inline-flex items-center hover:bg-theme-modal-border hover:border-theme-modal-border hover:border-opacity-50 border-transparent border",children:e.jsx(oe,{size:24,weight:"bold",className:"text-white"})})]}),e.jsxs("form",{id:"provider-form",onSubmit:i,children:[e.jsx("div",{className:"px-7 py-6",children:e.jsxs("div",{className:"space-y-6 max-h-[60vh] overflow-y-auto p-1",children:[e.jsxs("p",{className:"text-sm text-white/60",children:["To use ",o.name," as this workspace's LLM you need to set it up first."]}),e.jsx("div",{children:o.options(a,{credentialsOnly:!0})})]})}),e.jsxs("div",{className:"flex justify-between items-center mt-6 pt-6 border-t border-theme-modal-border px-7 pb-6",children:[e.jsx("button",{type:"button",onClick:t,className:"transition-all duration-300 text-white hover:bg-zinc-700 px-4 py-2 rounded-lg text-sm",children:"Cancel"}),e.jsx("button",{type:"submit",form:"provider-form",className:"transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Save settings"})]})]})]})})}),document.body)}function Ta({showing:n,onSetupClick:t}){const{t:r}=K();return n?e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(jr,{size:16,className:"text-white light:text-slate-800 shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-[13px] text-white light:text-slate-800 leading-5",children:[r("chat_window.workspace_llm_manager.missing_credentials")," ",e.jsx("span",{onClick:t,className:"text-sky-400 font-semibold cursor-pointer hover:underline",role:"button",children:r("chat_window.workspace_llm_manager.missing_credentials_description")})]})]}):null}function _a({workspaceSlug:n=null,initialProvider:t=null}){var C,S;const{slug:r}=De(),a=r??n,{t:o}=K(),i=$n(),s=((C=i.llmProviders)==null?void 0:C.allowlist)??null,c=We.filter(E=>{var N;return!(E.requiredFeature&&!((N=i[E.requiredFeature])!=null&&N.enabled)||s&&!s.includes(E.value))}),[d,g]=u.useState(!1),[w,m]=u.useState(null),[v,f]=u.useState(null),[b,L]=u.useState(""),[M,P]=u.useState(null),[z,D]=u.useState(c),[k,T]=u.useState(!1),[_,I]=u.useState(!1),[Z,B]=u.useState(!1);u.useEffect(()=>{a&&(g(!0),Promise.all([Y.bySlug(a),ne.keys()]).then(([E,N])=>{const O=E.chatProvider??N.LLMProvider,p=E.chatModel??N.LLMModel,l=t??O;m(N),f(l),yt(l),L(p),P(E.router_id||(N==null?void 0:N.ModelRouterId)||null),t&&t!==O&&(T(!0),B(St(N,t)))}).finally(()=>g(!1)))},[a]);function U(E){const N=E.target.value.toLowerCase(),O=c.filter(p=>p.name.toLowerCase().includes(N));D(O)}function H(E){f(E),D(c),yt(E,50),document.getElementById("llm-search-input").value="",T(!0),B(St(w,E))}async function j(){I(!0);try{T(!1);const E=v==="anythingllm-router";if(E&&!M)throw new Error(o("model-router.chat.select-router-error"));const N=E?{chatProvider:v,router_id:M}:{chatProvider:v,chatModel:Un(b)};if(!E&&!N.chatModel)throw new Error(o("model-router.chat.invalid-model"));const{message:O}=await Y.update(a,N);if(O)throw new Error(O);window.dispatchEvent(new Event(Ye))}catch(E){console.error(E),he(E.message,"error",{clear:!0})}finally{I(!1)}}const y=((S=We.find(E=>E.value===v))==null?void 0:S.name)||v;return d?e.jsxs("div",{id:"llm-selector-modal",className:"w-full h-[388px] flex flex-col items-center justify-center gap-2",children:[e.jsx(Bn,{size:12}),e.jsx("p",{className:"text-zinc-400 light:text-slate-500 text-sm",children:o("chat_window.workspace_llm_manager.loading_workspace_settings")})]}):e.jsxs("div",{id:"llm-selector-modal",className:"w-full h-[388px] flex",children:[e.jsx(Ca,{availableProviders:z,selectedLLMProvider:v,onSearchChange:U,onProviderClick:H}),e.jsxs("div",{className:"w-[60%] h-full p-[18px] flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-[15px]",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm font-medium text-white light:text-slate-800",children:o("chat_window.workspace_llm_manager.available_models",{provider:y})}),e.jsx("p",{className:"text-xs font-medium text-zinc-400 light:text-slate-500",children:o("chat_window.workspace_llm_manager.available_models_description")})]}),!Z&&(v==="anythingllm-router"?e.jsx(ka,{selectedRouterId:M,setSelectedRouterId:P,setHasChanges:T}):e.jsx(Na,{provider:v,setHasChanges:T,selectedLLMModel:b,setSelectedLLMModel:L}))]}),e.jsx(Ta,{showing:Z,onSetupClick:()=>{window.dispatchEvent(new CustomEvent(Ge,{detail:{provider:We.find(E=>E.value===v),settings:w}}))}}),k&&!Z&&e.jsx("button",{type:"button",disabled:_,onClick:j,className:"border-none text-xs px-4 py-1.5 font-semibold rounded-lg bg-white text-zinc-900 hover:bg-zinc-200 light:bg-slate-800 light:text-white light:hover:bg-slate-700 h-8 w-full cursor-pointer transition-colors mt-auto",children:o(_?"chat_window.workspace_llm_manager.saving":"chat_window.workspace_llm_manager.save")})]})]})}function La(){const{t:n}=K();function t(){window.dispatchEvent(new CustomEvent(Wn))}return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:t,"data-tooltip-id":"stop-generation-button","data-tooltip-content":n("chat_window.stop_generating"),className:"border-none inline-flex justify-center items-center rounded-full cursor-pointer w-8 h-8 bg-white light:bg-slate-800 hover:opacity-80 transition-opacity","aria-label":"Stop generating",children:e.jsx("div",{className:"w-3.5 h-3.5 rounded-[4px] bg-zinc-800 light:bg-white"})}),e.jsx(G,{id:"stop-generation-button",place:"bottom",delayShow:300,className:"tooltip !text-xs z-99"})]})}var Pa={exports:{}};(function(n){var t=function(r){var a=Object.prototype,o=a.hasOwnProperty,i=Object.defineProperty||function(p,l,x){p[l]=x.value},s,c=typeof Symbol=="function"?Symbol:{},d=c.iterator||"@@iterator",g=c.asyncIterator||"@@asyncIterator",w=c.toStringTag||"@@toStringTag";function m(p,l,x){return Object.defineProperty(p,l,{value:x,enumerable:!0,configurable:!0,writable:!0}),p[l]}try{m({},"")}catch{m=function(l,x,A){return l[x]=A}}function v(p,l,x,A){var V=l&&l.prototype instanceof D?l:D,R=Object.create(V.prototype),F=new E(A||[]);return i(R,"_invoke",{value:j(p,x,F)}),R}r.wrap=v;function f(p,l,x){try{return{type:"normal",arg:p.call(l,x)}}catch(A){return{type:"throw",arg:A}}}var b="suspendedStart",L="suspendedYield",M="executing",P="completed",z={};function D(){}function k(){}function T(){}var _={};m(_,d,function(){return this});var I=Object.getPrototypeOf,Z=I&&I(I(N([])));Z&&Z!==a&&o.call(Z,d)&&(_=Z);var B=T.prototype=D.prototype=Object.create(_);k.prototype=T,i(B,"constructor",{value:T,configurable:!0}),i(T,"constructor",{value:k,configurable:!0}),k.displayName=m(T,w,"GeneratorFunction");function U(p){["next","throw","return"].forEach(function(l){m(p,l,function(x){return this._invoke(l,x)})})}r.isGeneratorFunction=function(p){var l=typeof p=="function"&&p.constructor;return l?l===k||(l.displayName||l.name)==="GeneratorFunction":!1},r.mark=function(p){return Object.setPrototypeOf?Object.setPrototypeOf(p,T):(p.__proto__=T,m(p,w,"GeneratorFunction")),p.prototype=Object.create(B),p},r.awrap=function(p){return{__await:p}};function H(p,l){function x(R,F,$,W){var q=f(p[R],p,F);if(q.type==="throw")W(q.arg);else{var re=q.arg,Q=re.value;return Q&&typeof Q=="object"&&o.call(Q,"__await")?l.resolve(Q.__await).then(function(J){x("next",J,$,W)},function(J){x("throw",J,$,W)}):l.resolve(Q).then(function(J){re.value=J,$(re)},function(J){return x("throw",J,$,W)})}}var A;function V(R,F){function $(){return new l(function(W,q){x(R,F,W,q)})}return A=A?A.then($,$):$()}i(this,"_invoke",{value:V})}U(H.prototype),m(H.prototype,g,function(){return this}),r.AsyncIterator=H,r.async=function(p,l,x,A,V){V===void 0&&(V=Promise);var R=new H(v(p,l,x,A),V);return r.isGeneratorFunction(l)?R:R.next().then(function(F){return F.done?F.value:R.next()})};function j(p,l,x){var A=b;return function(R,F){if(A===M)throw new Error("Generator is already running");if(A===P){if(R==="throw")throw F;return O()}for(x.method=R,x.arg=F;;){var $=x.delegate;if($){var W=y($,x);if(W){if(W===z)continue;return W}}if(x.method==="next")x.sent=x._sent=x.arg;else if(x.method==="throw"){if(A===b)throw A=P,x.arg;x.dispatchException(x.arg)}else x.method==="return"&&x.abrupt("return",x.arg);A=M;var q=f(p,l,x);if(q.type==="normal"){if(A=x.done?P:L,q.arg===z)continue;return{value:q.arg,done:x.done}}else q.type==="throw"&&(A=P,x.method="throw",x.arg=q.arg)}}}function y(p,l){var x=l.method,A=p.iterator[x];if(A===s)return l.delegate=null,x==="throw"&&p.iterator.return&&(l.method="return",l.arg=s,y(p,l),l.method==="throw")||x!=="return"&&(l.method="throw",l.arg=new TypeError("The iterator does not provide a '"+x+"' method")),z;var V=f(A,p.iterator,l.arg);if(V.type==="throw")return l.method="throw",l.arg=V.arg,l.delegate=null,z;var R=V.arg;if(!R)return l.method="throw",l.arg=new TypeError("iterator result is not an object"),l.delegate=null,z;if(R.done)l[p.resultName]=R.value,l.next=p.nextLoc,l.method!=="return"&&(l.method="next",l.arg=s);else return R;return l.delegate=null,z}U(B),m(B,w,"Generator"),m(B,d,function(){return this}),m(B,"toString",function(){return"[object Generator]"});function C(p){var l={tryLoc:p[0]};1 in p&&(l.catchLoc=p[1]),2 in p&&(l.finallyLoc=p[2],l.afterLoc=p[3]),this.tryEntries.push(l)}function S(p){var l=p.completion||{};l.type="normal",delete l.arg,p.completion=l}function E(p){this.tryEntries=[{tryLoc:"root"}],p.forEach(C,this),this.reset(!0)}r.keys=function(p){var l=Object(p),x=[];for(var A in l)x.push(A);return x.reverse(),function V(){for(;x.length;){var R=x.pop();if(R in l)return V.value=R,V.done=!1,V}return V.done=!0,V}};function N(p){if(p!=null){var l=p[d];if(l)return l.call(p);if(typeof p.next=="function")return p;if(!isNaN(p.length)){var x=-1,A=function V(){for(;++x<p.length;)if(o.call(p,x))return V.value=p[x],V.done=!1,V;return V.value=s,V.done=!0,V};return A.next=A}}throw new TypeError(typeof p+" is not iterable")}r.values=N;function O(){return{value:s,done:!0}}return E.prototype={constructor:E,reset:function(p){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(S),!p)for(var l in this)l.charAt(0)==="t"&&o.call(this,l)&&!isNaN(+l.slice(1))&&(this[l]=s)},stop:function(){this.done=!0;var p=this.tryEntries[0],l=p.completion;if(l.type==="throw")throw l.arg;return this.rval},dispatchException:function(p){if(this.done)throw p;var l=this;function x(W,q){return R.type="throw",R.arg=p,l.next=W,q&&(l.method="next",l.arg=s),!!q}for(var A=this.tryEntries.length-1;A>=0;--A){var V=this.tryEntries[A],R=V.completion;if(V.tryLoc==="root")return x("end");if(V.tryLoc<=this.prev){var F=o.call(V,"catchLoc"),$=o.call(V,"finallyLoc");if(F&&$){if(this.prev<V.catchLoc)return x(V.catchLoc,!0);if(this.prev<V.finallyLoc)return x(V.finallyLoc)}else if(F){if(this.prev<V.catchLoc)return x(V.catchLoc,!0)}else if($){if(this.prev<V.finallyLoc)return x(V.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(p,l){for(var x=this.tryEntries.length-1;x>=0;--x){var A=this.tryEntries[x];if(A.tryLoc<=this.prev&&o.call(A,"finallyLoc")&&this.prev<A.finallyLoc){var V=A;break}}V&&(p==="break"||p==="continue")&&V.tryLoc<=l&&l<=V.finallyLoc&&(V=null);var R=V?V.completion:{};return R.type=p,R.arg=l,V?(this.method="next",this.next=V.finallyLoc,z):this.complete(R)},complete:function(p,l){if(p.type==="throw")throw p.arg;return p.type==="break"||p.type==="continue"?this.next=p.arg:p.type==="return"?(this.rval=this.arg=p.arg,this.method="return",this.next="end"):p.type==="normal"&&l&&(this.next=l),z},finish:function(p){for(var l=this.tryEntries.length-1;l>=0;--l){var x=this.tryEntries[l];if(x.finallyLoc===p)return this.complete(x.completion,x.afterLoc),S(x),z}},catch:function(p){for(var l=this.tryEntries.length-1;l>=0;--l){var x=this.tryEntries[l];if(x.tryLoc===p){var A=x.completion;if(A.type==="throw"){var V=A.arg;S(x)}return V}}throw new Error("illegal catch attempt")},delegateYield:function(p,l,x){return this.delegate={iterator:N(p),resultName:l,nextLoc:x},this.method==="next"&&(this.arg=s),z}},r}(n.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(Pa);var tt={},mn={},ee={};Object.defineProperty(ee,"__esModule",{value:!0});ee.browserSupportsPolyfills=ee.compareTwoStringsUsingDiceCoefficient=ee.commandToRegExp=ee.concatTranscripts=ee.debounce=void 0;var Ra=function(t,r,a){var o;return function(){var i=this,s=arguments,c=function(){o=null,a||t.apply(i,s)},d=a&&!o;clearTimeout(o),o=setTimeout(c,r),d&&t.apply(i,s)}};ee.debounce=Ra;var za=function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];return r.map(function(o){return o.trim()}).join(" ").trim()};ee.concatTranscripts=za;var Va=/\s*\((.*?)\)\s*/g,Oa=/(\(\?:[^)]+\))\?/g,Ia=/(\(\?)?:\w+/g,Za=/\*/g,Fa=/[-{}[\]+?.,\\^$|#]/g,Da=function(t){return t instanceof RegExp?new RegExp(t.source,"i"):(t=t.replace(Fa,"\\$&").replace(Va,"(?:$1)?").replace(Ia,function(r,a){return a?r:"([^\\s]+)"}).replace(Za,"(.*?)").replace(Oa,"\\s*$1?\\s*"),new RegExp("^"+t+"$","i"))};ee.commandToRegExp=Da;var Ha=function(t,r){if(t=t.replace(/\s+/g,"").toLowerCase(),r=r.replace(/\s+/g,"").toLowerCase(),!t.length&&!r.length)return 1;if(!t.length||!r.length)return 0;if(t===r)return 1;if(t.length===1&&r.length===1||t.length<2||r.length<2)return 0;for(var a=new Map,o=0;o<t.length-1;o++){var i=t.substring(o,o+2),s=a.has(i)?a.get(i)+1:1;a.set(i,s)}for(var c=0,d=0;d<r.length-1;d++){var g=r.substring(d,d+2),w=a.has(g)?a.get(g):0;w>0&&(a.set(g,w-1),c++)}return 2*c/(t.length+r.length-2)};ee.compareTwoStringsUsingDiceCoefficient=Ha;var $a=function(){return typeof window<"u"&&window.navigator!==void 0&&window.navigator.mediaDevices!==void 0&&window.navigator.mediaDevices.getUserMedia!==void 0&&(window.AudioContext!==void 0||window.webkitAudioContext!==void 0)};ee.browserSupportsPolyfills=$a;var Se={},me={};Object.defineProperty(me,"__esModule",{value:!0});me.APPEND_TRANSCRIPT=me.CLEAR_TRANSCRIPT=void 0;var Ba="CLEAR_TRANSCRIPT";me.CLEAR_TRANSCRIPT=Ba;var Ua="APPEND_TRANSCRIPT";me.APPEND_TRANSCRIPT=Ua;Object.defineProperty(Se,"__esModule",{value:!0});Se.appendTranscript=Se.clearTranscript=void 0;var pn=me,Wa=function(){return{type:pn.CLEAR_TRANSCRIPT}};Se.clearTranscript=Wa;var Ka=function(t,r){return{type:pn.APPEND_TRANSCRIPT,payload:{interimTranscript:t,finalTranscript:r}}};Se.appendTranscript=Ka;var $e={};Object.defineProperty($e,"__esModule",{value:!0});$e.transcriptReducer=void 0;var $t=me,qa=ee,Ga=function(t,r){switch(r.type){case $t.CLEAR_TRANSCRIPT:return{interimTranscript:"",finalTranscript:""};case $t.APPEND_TRANSCRIPT:return{interimTranscript:r.payload.interimTranscript,finalTranscript:(0,qa.concatTranscripts)(t.finalTranscript,r.payload.finalTranscript)};default:throw new Error}};$e.transcriptReducer=Ga;var fn={},nt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var t=function(){return/(android)/i.test(typeof navigator<"u"?navigator.userAgent:"")};n.default=t})(nt);var rt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=n.isNative=void 0;var t=typeof window<"u"&&(window.SpeechRecognition||window.webkitSpeechRecognition||window.mozSpeechRecognition||window.msSpeechRecognition||window.oSpeechRecognition),r=function(i){return i===t};n.isNative=r;var a=t;n.default=a})(rt);(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var t=o(nt),r=ee,a=rt;function o(m){return m&&m.__esModule?m:{default:m}}function i(m,v,f,b,L,M,P){try{var z=m[M](P),D=z.value}catch(k){f(k);return}z.done?v(D):Promise.resolve(D).then(b,L)}function s(m){return function(){var v=this,f=arguments;return new Promise(function(b,L){var M=m.apply(v,f);function P(D){i(M,b,L,P,z,"next",D)}function z(D){i(M,b,L,P,z,"throw",D)}P(void 0)})}}function c(m,v){if(!(m instanceof v))throw new TypeError("Cannot call a class as a function")}function d(m,v){for(var f=0;f<v.length;f++){var b=v[f];b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(m,b.key,b)}}function g(m,v,f){return v&&d(m.prototype,v),f&&d(m,f),m}var w=function(){function m(v){c(this,m),this.recognition=null,this.pauseAfterDisconnect=!1,this.interimTranscript="",this.finalTranscript="",this.listening=!1,this.isMicrophoneAvailable=!0,this.subscribers={},this.onStopListening=function(){},this.previousResultWasFinalOnly=!1,this.resetTranscript=this.resetTranscript.bind(this),this.startListening=this.startListening.bind(this),this.stopListening=this.stopListening.bind(this),this.abortListening=this.abortListening.bind(this),this.setSpeechRecognition=this.setSpeechRecognition.bind(this),this.disableRecognition=this.disableRecognition.bind(this),this.setSpeechRecognition(v),(0,t.default)()&&(this.updateFinalTranscript=(0,r.debounce)(this.updateFinalTranscript,250,!0))}return g(m,[{key:"setSpeechRecognition",value:function(f){var b=!!f&&((0,a.isNative)(f)||(0,r.browserSupportsPolyfills)());b&&(this.disableRecognition(),this.recognition=new f,this.recognition.continuous=!1,this.recognition.interimResults=!0,this.recognition.onresult=this.updateTranscript.bind(this),this.recognition.onend=this.onRecognitionDisconnect.bind(this),this.recognition.onerror=this.onError.bind(this)),this.emitBrowserSupportsSpeechRecognitionChange(b)}},{key:"subscribe",value:function(f,b){this.subscribers[f]=b}},{key:"unsubscribe",value:function(f){delete this.subscribers[f]}},{key:"emitListeningChange",value:function(f){var b=this;this.listening=f,Object.keys(this.subscribers).forEach(function(L){var M=b.subscribers[L].onListeningChange;M(f)})}},{key:"emitMicrophoneAvailabilityChange",value:function(f){var b=this;this.isMicrophoneAvailable=f,Object.keys(this.subscribers).forEach(function(L){var M=b.subscribers[L].onMicrophoneAvailabilityChange;M(f)})}},{key:"emitTranscriptChange",value:function(f,b){var L=this;Object.keys(this.subscribers).forEach(function(M){var P=L.subscribers[M].onTranscriptChange;P(f,b)})}},{key:"emitClearTranscript",value:function(){var f=this;Object.keys(this.subscribers).forEach(function(b){var L=f.subscribers[b].onClearTranscript;L()})}},{key:"emitBrowserSupportsSpeechRecognitionChange",value:function(f){var b=this;Object.keys(this.subscribers).forEach(function(L){var M=b.subscribers[L],P=M.onBrowserSupportsSpeechRecognitionChange,z=M.onBrowserSupportsContinuousListeningChange;P(f),z(f)})}},{key:"disconnect",value:function(f){if(this.recognition&&this.listening)switch(f){case"ABORT":this.pauseAfterDisconnect=!0,this.abort();break;case"RESET":this.pauseAfterDisconnect=!1,this.abort();break;case"STOP":default:this.pauseAfterDisconnect=!0,this.stop()}}},{key:"disableRecognition",value:function(){this.recognition&&(this.recognition.onresult=function(){},this.recognition.onend=function(){},this.recognition.onerror=function(){},this.listening&&this.stopListening())}},{key:"onError",value:function(f){f&&f.error&&f.error==="not-allowed"&&(this.emitMicrophoneAvailabilityChange(!1),this.disableRecognition())}},{key:"onRecognitionDisconnect",value:function(){this.onStopListening(),this.listening=!1,this.pauseAfterDisconnect?this.emitListeningChange(!1):this.recognition&&(this.recognition.continuous?this.startListening({continuous:this.recognition.continuous}):this.emitListeningChange(!1)),this.pauseAfterDisconnect=!1}},{key:"updateTranscript",value:function(f){var b=f.results,L=f.resultIndex,M=L===void 0?b.length-1:L;this.interimTranscript="",this.finalTranscript="";for(var P=M;P<b.length;++P)b[P].isFinal&&(!(0,t.default)()||b[P][0].confidence>0)?this.updateFinalTranscript(b[P][0].transcript):this.interimTranscript=(0,r.concatTranscripts)(this.interimTranscript,b[P][0].transcript);var z=!1;this.interimTranscript===""&&this.finalTranscript!==""?(this.previousResultWasFinalOnly&&(z=!0),this.previousResultWasFinalOnly=!0):this.previousResultWasFinalOnly=!1,z||this.emitTranscriptChange(this.interimTranscript,this.finalTranscript)}},{key:"updateFinalTranscript",value:function(f){this.finalTranscript=(0,r.concatTranscripts)(this.finalTranscript,f)}},{key:"resetTranscript",value:function(){this.disconnect("RESET")}},{key:"startListening",value:function(){var v=s(regeneratorRuntime.mark(function b(){var L,M,P,z,D,k,T=arguments;return regeneratorRuntime.wrap(function(I){for(;;)switch(I.prev=I.next){case 0:if(L=T.length>0&&T[0]!==void 0?T[0]:{},M=L.continuous,P=M===void 0?!1:M,z=L.language,this.recognition){I.next=3;break}return I.abrupt("return");case 3:if(D=P!==this.recognition.continuous,k=z&&z!==this.recognition.lang,!(D||k)){I.next=11;break}if(!this.listening){I.next=9;break}return I.next=9,this.stopListening();case 9:this.recognition.continuous=D?P:this.recognition.continuous,this.recognition.lang=k?z:this.recognition.lang;case 11:if(this.listening){I.next=22;break}return this.recognition.continuous||(this.resetTranscript(),this.emitClearTranscript()),I.prev=13,I.next=16,this.start();case 16:this.emitListeningChange(!0),I.next=22;break;case 19:I.prev=19,I.t0=I.catch(13),I.t0 instanceof DOMException||this.emitMicrophoneAvailabilityChange(!1);case 22:case"end":return I.stop()}},b,this,[[13,19]])}));function f(){return v.apply(this,arguments)}return f}()},{key:"abortListening",value:function(){var v=s(regeneratorRuntime.mark(function b(){var L=this;return regeneratorRuntime.wrap(function(P){for(;;)switch(P.prev=P.next){case 0:return this.disconnect("ABORT"),this.emitListeningChange(!1),P.next=4,new Promise(function(z){L.onStopListening=z});case 4:case"end":return P.stop()}},b,this)}));function f(){return v.apply(this,arguments)}return f}()},{key:"stopListening",value:function(){var v=s(regeneratorRuntime.mark(function b(){var L=this;return regeneratorRuntime.wrap(function(P){for(;;)switch(P.prev=P.next){case 0:return this.disconnect("STOP"),this.emitListeningChange(!1),P.next=4,new Promise(function(z){L.onStopListening=z});case 4:case"end":return P.stop()}},b,this)}));function f(){return v.apply(this,arguments)}return f}()},{key:"getRecognition",value:function(){return this.recognition}},{key:"start",value:function(){var v=s(regeneratorRuntime.mark(function b(){return regeneratorRuntime.wrap(function(M){for(;;)switch(M.prev=M.next){case 0:if(!(this.recognition&&!this.listening)){M.next=4;break}return M.next=3,this.recognition.start();case 3:this.listening=!0;case 4:case"end":return M.stop()}},b,this)}));function f(){return v.apply(this,arguments)}return f}()},{key:"stop",value:function(){this.recognition&&this.listening&&(this.recognition.stop(),this.listening=!1)}},{key:"abort",value:function(){this.recognition&&this.listening&&(this.recognition.abort(),this.listening=!1)}}]),m}();n.default=w})(fn);(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=n.useSpeechRecognition=void 0;var t=u,r=ee,a=Se,o=$e,i=d(fn),s=d(nt),c=d(rt);function d(j){return j&&j.__esModule?j:{default:j}}function g(j,y,C,S,E,N,O){try{var p=j[N](O),l=p.value}catch(x){C(x);return}p.done?y(l):Promise.resolve(l).then(S,E)}function w(j){return function(){var y=this,C=arguments;return new Promise(function(S,E){var N=j.apply(y,C);function O(l){g(N,S,E,O,p,"next",l)}function p(l){g(N,S,E,O,p,"throw",l)}O(void 0)})}}function m(j){return b(j)||f(j)||z(j)||v()}function v(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
2
2
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function f(j){if(typeof Symbol<"u"&&Symbol.iterator in Object(j))return Array.from(j)}function b(j){if(Array.isArray(j))return D(j)}function L(j){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?L=function(C){return typeof C}:L=function(C){return C&&typeof Symbol=="function"&&C.constructor===Symbol&&C!==Symbol.prototype?"symbol":typeof C},L(j)}function M(j,y){return T(j)||k(j,y)||z(j,y)||P()}function P(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
3
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function z(j,y){if(j){if(typeof j=="string")return D(j,y);var C=Object.prototype.toString.call(j).slice(8,-1);if(C==="Object"&&j.constructor&&(C=j.constructor.name),C==="Map"||C==="Set")return Array.from(j);if(C==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(C))return D(j,y)}}function D(j,y){(y==null||y>j.length)&&(y=j.length);for(var C=0,S=new Array(y);C<y;C++)S[C]=j[C];return S}function k(j,y){if(!(typeof Symbol>"u"||!(Symbol.iterator in Object(j)))){var C=[],S=!0,E=!1,N=void 0;try{for(var O=j[Symbol.iterator](),p;!(S=(p=O.next()).done)&&(C.push(p.value),!(y&&C.length===y));S=!0);}catch(l){E=!0,N=l}finally{try{!S&&O.return!=null&&O.return()}finally{if(E)throw N}}return C}}function T(j){if(Array.isArray(j))return j}var _=!!c.default,I=_&&!(0,s.default)(),Z,B=function(){var y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},C=y.transcribing,S=C===void 0?!0:C,E=y.clearTranscriptOnListen,N=E===void 0?!0:E,O=y.commands,p=O===void 0?[]:O,l=(0,t.useState)(U.getRecognitionManager()),x=M(l,1),A=x[0],V=(0,t.useState)(_),R=M(V,2),F=R[0],$=R[1],W=(0,t.useState)(I),q=M(W,2),re=q[0],Q=q[1],J=(0,t.useReducer)(o.transcriptReducer,{interimTranscript:A.interimTranscript,finalTranscript:""}),st=M(J,2),it=st[0],ot=it.interimTranscript,lt=it.finalTranscript,ct=st[1],Sn=(0,t.useState)(A.listening),ut=M(Sn,2),jn=ut[0],En=ut[1],An=(0,t.useState)(A.isMicrophoneAvailable),dt=M(An,2),Nn=dt[0],kn=dt[1],ht=(0,t.useRef)(p);ht.current=p;var mt=function(){ct((0,a.clearTranscript)())},Ae=(0,t.useCallback)(function(){A.resetTranscript(),mt()},[A]),Cn=function(X,ie,ue){var le=L(X)==="object"?X.toString():X,Ne=le.replace(/[&/\\#,+()!$~%.'":*?<>{}]/g,"").replace(/ +/g," ").trim(),Pe=(0,r.compareTwoStringsUsingDiceCoefficient)(Ne,ie);return Pe>=ue?{command:X,commandWithoutSpecials:Ne,howSimilar:Pe,isFuzzyMatch:!0}:null},Mn=function(X,ie){var ue=(0,r.commandToRegExp)(X),le=ue.exec(ie);return le?{command:X,parameters:le.slice(1)}:null},pt=(0,t.useCallback)(function(se,X){ht.current.forEach(function(ie){var ue=ie.command,le=ie.callback,Ne=ie.matchInterim,Pe=Ne===void 0?!1:Ne,xt=ie.isFuzzyMatch,bt=xt===void 0?!1:xt,vt=ie.fuzzyMatchingThreshold,_n=vt===void 0?.8:vt,wt=ie.bestMatchOnly,Ln=wt===void 0?!1:wt,Re=!X&&Pe?se.trim():X.trim(),Pn=Array.isArray(ue)?ue:[ue],ze=Pn.map(function(te){return bt?Cn(te,Re,_n):Mn(te,Re)}).filter(function(te){return te});if(bt&&Ln&&ze.length>=2){ze.sort(function(te,Ue){return Ue.howSimilar-te.howSimilar});var Be=ze[0],Rn=Be.command,zn=Be.commandWithoutSpecials,Vn=Be.howSimilar;le(zn,Re,Vn,{command:Rn,resetTranscript:Ae})}else ze.forEach(function(te){if(te.isFuzzyMatch){var Ue=te.command,On=te.commandWithoutSpecials,In=te.howSimilar;le(On,Re,In,{command:Ue,resetTranscript:Ae})}else{var Zn=te.command,Fn=te.parameters;le.apply(void 0,m(Fn).concat([{command:Zn,resetTranscript:Ae}]))}})})},[Ae]),ft=(0,t.useCallback)(function(se,X){S&&ct((0,a.appendTranscript)(se,X)),pt(se,X)},[pt,S]),gt=(0,t.useCallback)(function(){N&&mt()},[N]);(0,t.useEffect)(function(){var se=U.counter;U.counter+=1;var X={onListeningChange:En,onMicrophoneAvailabilityChange:kn,onTranscriptChange:ft,onClearTranscript:gt,onBrowserSupportsSpeechRecognitionChange:$,onBrowserSupportsContinuousListeningChange:Q};return A.subscribe(se,X),function(){A.unsubscribe(se)}},[S,N,A,ft,gt]);var Tn=(0,r.concatTranscripts)(lt,ot);return{transcript:Tn,interimTranscript:ot,finalTranscript:lt,listening:jn,isMicrophoneAvailable:Nn,resetTranscript:Ae,browserSupportsSpeechRecognition:F,browserSupportsContinuousListening:re}};n.useSpeechRecognition=B;var U={counter:0,applyPolyfill:function(y){Z?Z.setSpeechRecognition(y):Z=new i.default(y);var C=!!y&&(0,r.browserSupportsPolyfills)();_=C,I=C},removePolyfill:function(){Z?Z.setSpeechRecognition(c.default):Z=new i.default(c.default),_=!!c.default,I=_&&!(0,s.default)()},getRecognitionManager:function(){return Z||(Z=new i.default(c.default)),Z},getRecognition:function(){var y=U.getRecognitionManager();return y.getRecognition()},startListening:function(){var j=w(regeneratorRuntime.mark(function C(){var S,E,N,O,p=arguments;return regeneratorRuntime.wrap(function(x){for(;;)switch(x.prev=x.next){case 0:return S=p.length>0&&p[0]!==void 0?p[0]:{},E=S.continuous,N=S.language,O=U.getRecognitionManager(),x.next=4,O.startListening({continuous:E,language:N});case 4:case"end":return x.stop()}},C)}));function y(){return j.apply(this,arguments)}return y}(),stopListening:function(){var j=w(regeneratorRuntime.mark(function C(){var S;return regeneratorRuntime.wrap(function(N){for(;;)switch(N.prev=N.next){case 0:return S=U.getRecognitionManager(),N.next=3,S.stopListening();case 3:case"end":return N.stop()}},C)}));function y(){return j.apply(this,arguments)}return y}(),abortListening:function(){var j=w(regeneratorRuntime.mark(function C(){var S;return regeneratorRuntime.wrap(function(N){for(;;)switch(N.prev=N.next){case 0:return S=U.getRecognitionManager(),N.next=3,S.abortListening();case 3:case"end":return N.stop()}},C)}));function y(){return j.apply(this,arguments)}return y}(),browserSupportsSpeechRecognition:function(){return _},browserSupportsContinuousListening:function(){return I}},H=U;n.default=H})(mn);(function(n){function t(s){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?t=function(d){return typeof d}:t=function(d){return d&&typeof Symbol=="function"&&d.constructor===Symbol&&d!==Symbol.prototype?"symbol":typeof d},t(s)}Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"useSpeechRecognition",{enumerable:!0,get:function(){return r.useSpeechRecognition}}),n.default=void 0;var r=o(mn);function a(){if(typeof WeakMap!="function")return null;var s=new WeakMap;return a=function(){return s},s}function o(s){if(s&&s.__esModule)return s;if(s===null||t(s)!=="object"&&typeof s!="function")return{default:s};var c=a();if(c&&c.has(s))return c.get(s);var d={},g=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var w in s)if(Object.prototype.hasOwnProperty.call(s,w)){var m=g?Object.getOwnPropertyDescriptor(s,w):null;m&&(m.get||m.set)?Object.defineProperty(d,w,m):d[w]=s[w]}return d.default=s,c&&c.set(s,d),d}var i=r.default;n.default=i})(tt);const Bt=Kn(tt);let ke;const Ya=3200;function Qa({sendCommand:n}){const t=u.useRef(""),{transcript:r,listening:a,resetTranscript:o,browserSupportsSpeechRecognition:i,browserSupportsContinuousListening:s,isMicrophoneAvailable:c}=tt.useSpeechRecognition({clearTranscriptOnListen:!0}),{t:d}=K();function g(){var f;if(!c){alert("AnythingLLM does not have access to microphone. Please enable for this site to use this feature.");return}o(),t.current="",Bt.startListening({continuous:s,language:((f=window==null?void 0:window.navigator)==null?void 0:f.language)??"en-US"})}function w(){Bt.stopListening(),tn.get("autoSubmitSttInput")&&n({text:"",autoSubmit:!0,writeMode:"append"}),o(),t.current="",clearTimeout(ke)}const m=u.useCallback(f=>{f.ctrlKey&&f.keyCode===77&&(a?w():g())},[a,w,g]);function v(f){!(f!=null&&f.detail)&&ke&&(w(),clearTimeout(ke))}return u.useEffect(()=>(document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m)}),[m]),u.useEffect(()=>(window&&window.addEventListener(Le,v),()=>window==null?void 0:window.removeEventListener(Le,v)),[]),u.useEffect(()=>{if((r==null?void 0:r.length)>0&&a){const f=t.current,b=r.slice(f.length);b.length>0&&n({text:b,writeMode:"append"}),t.current=r,clearTimeout(ke),ke=setTimeout(()=>{w()},Ya)}},[r,a]),i?e.jsxs("div",{"data-tooltip-id":"tooltip-microphone-btn","data-tooltip-content":`${d("chat_window.microphone")} (CTRL + M)`,"aria-label":d("chat_window.microphone"),onClick:a?w:g,className:`group border-none relative flex justify-center items-center cursor-pointer w-8 h-8 rounded-full hover:bg-zinc-700 light:hover:bg-slate-200 ${a?"bg-zinc-700 light:bg-slate-200":""}`,children:[e.jsx(hn,{weight:"regular",size:18,className:`pointer-events-none text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-600 shrink-0 ${a?"animate-pulse-glow !text-white light:!text-slate-800":""}`}),e.jsx(G,{id:"tooltip-microphone-btn",place:"top",delayShow:300,className:"tooltip !text-xs z-99"})]}):null}const Ja="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABFCAYAAAD3upAqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAoZSURBVHgB3VxtbBTHGX4d3LrYwjGJaQJ3tg/zEZ/lCBOISVuFmMSoqpQUDv+J0oJNpUqRoIGmcgRWIoyIAJWqxWCkVpVqG6tRf9QxaSpVDSYYolaYtML9UZ8jNc3h4BAVUOBOserWiLzP7MwyPvZ8t7N7ZzuPNLe7t+vz3rPP+zEz71we5RB37twp4U0tt1VyG5KNtC0Q43ZTtn9w+0huh/Ly8m5SDpBHWQaTUc+bp7jVy+YVA9xOcXuLSYpRlpAVYqQydnHbTJYyBBKJBP1zOErRkREajo7Q2NiYaPF4guKJuP33xQuKKRhcQgt4Wx2uokAgQOGqKnpiXV3yvxridpQsknxVkq/EaITs5oZ9Qcbv3+yj0/1nKMpk6AS4BQgLM1GNkc2CJBAmEePWxa3bLxX5QowTIRcGL9KxjhM0ePEiZQuNkQhtkSRJxLh1MTn7ySM8EyN9SCdJ59nL6ug82cPqiFKuEGTlvLRzBzVuiai3Yty2M0EDZAhjYqRK9pGlkpwoJB3W1dXRkcMHdRNrM1WPETFMSog3Z7mF4EOOHu+gru6TNFvw0s6dtOtHO9QhHHTEre9xTQyTgigDUkoQUV7Y2kRXeDvbAPN6o6dbqSfGbYMbcu4jF2BSmkiS0vvmKXp205ZZSQpwRT40adohbpfkQ80IGStGktKF/WPHT1B7RwfNFbzaupe2N23DLnIdKGco3d9kRIxk+hL25xopCprfATmr05lVWlOSjrYP+3OVFOAY33dvn/gaiKZn5fdKiWkVI0MylBLq5Kjz+sFDNNcBh4ywzhhg1WxIdV06xSBPCSH6QC1fBry4Y6fonzHq+cH/ItV1KRXDf9TMm07kKc9uisza6GMCdEzfPtWnDjc4ZciOitGyWpG85YqUYGAJ5QLo2bcft31lp9M1jophYkBKGz7guc0R8hsYTtjY8DR9gzt/VVVhHmIIcM95gX0+zipFXwsPBL1ytGzg/Lv9KgHcz6pp08/dQ4z01hgxo6eebvBVLevqHhcdvY0NDVOISAcQdbq/n5/yCeUffLqfOuGMyQrhS/UxHSdTasMLesl+kQKFvMZJ1hs9J8VQgRtSAFyPv8MTRrKGz/MDyIplZgzXsVs/N0Ux2VALVPLTw4dE38UvqHR/zJf7c1ZNsmLq8eKXWpCGQyV+kgLg8/7IUWVjwzPkFUmqaVbvJxMjIlFv3ynyCpAC2WcLxcUL6JcnOoSJeUXn3SGTTWrHNiU5EncW8lzPZuQFMB8oJRfAQPoL25o8jRiC5PPvnmHfJXwfzCmmKwYj+vSOx9CI8AefkitYyjnuySGD3HdO96tDwYNODOZ+POcM6MH67VPSAf/vB01byQtOn7G/tzAnQYyaIQRzXsZsoRZTm8fUCjqpppGmuanJk2q0710LPpRi6q2b8zayr42zukbL3lbhBA8Y9uBhUl5UA1EM80QgWdEppIgRQ34XZkgtQCIelzdoPiHnVTXRYVsYtYqYVeJEdIRM8QRHopkGVIOesymiI/b3t4kRs4fok5jCj2TLD3i5Dy2ptU0phBcvKXYgGKTZAC+K0YipmEKMl25AdZX5DfmJgIdUIRG3LabE1bxSKuQ6b5kOft2LL8S4BTqpaJkAITzTa71Ct5h8yjEGefL/Fc5ZrBv5ZNrc55U9rWrKg9bxaF+2lYmopqAU46kayY1vCofDdq6BuZ72FLMPOilu/EY8bh5ZFy58wN6fQkxl5TIyRabk4KlgYGg6cpJJwfWZqsVL9r6otFTtxqYQs3LFSjIFTCRTIKQmk6OIHbz4vjEpwPCIeZK6cuUjaveWIgalovToozV8s/eTCaIubyiZnGSYkAK4eUA6iovvpxXLV6hDWzFi9j9UXk6LFn2dTKCeshukIseUFCSo2vCBKwQCZVRRUaYObWJieCkvLxPEmKgGTg9THG6RTI4pKcAFD2pBq6goV28NKWIG8BKSjAWDZWSCzu4eMoEiBxWYpqQAqAE0QWXlciosLGSLsb43pmzvkztwvkM4Ga56RLC3cOGD5BYY7DFNxkDOEQ/TLCg6MOnSPPzwYioo+BqnEbbjHcCLnvmew8vja1aLg2XLlos/cIvXDx3ydbYwE+D/dRoURxYUFLDpWuaz9jG7Cu0tvOjEiDmT9U9+UxzMm5cvJOYW8DUte1opV0A1BibfTCrOw+Eays+3kv/qu4oRPNjEyFKImDInACYFb+0WMKlcFRm17NlrZELwo8oiIAaZ3A2oErTkTqSYq2yMfFf7ALMQnu0KLCgFGbLJrAZIUSYErH/yW2q3S+0kE4OVHDchq9K76TGHsaXstYvILUAOykj89jlWffE2o9wJD1knBdZRbVlIjNXSrd6fQoyMTu3Yb4w8Z78Pf1NdXWNEDmps4AP8GjoA2agvHjYYnwYplZUrprynfCpJa1Fwqo/B+C8qHkoOHDzCqf4H9rnbtyfpww//RZ99doNM4LAYIiOopT0oyzcdZXQiZc1jq+knu8WwR4ySKsdTVVS18WbfcPQDDr9H7jl/+fK/6dNPr5IpikVF1TNijhvDEGXBgJo3FgARH18ZsysRBgff97TOKdmnKLT//LByuj9mUo7q51IRY5ex9vz2d/SnP9+b6l+9+gmNjn5EfgKK8rOCC6G4vHypY/BAgJFBBr5lafJ5x6FN6Wu2qw/QHbHC4sVLqLZ2rVESmAp+koL+Xk3NKkdSSksf1COvY61vyjFfmde0I6+BHWKbDGSOtbVrRK7jJ0FeAJUgiiJYON0TSHmttUUd7k9VOp9xZfi59/5Kv/r1b1JeOzExwU98lK5f+w/NBEDIQw8t5r7PEjubdcKre1tUloulyqtTXZd2kYWsywM5Jb19fyC06aAIwlz0xMR/KdvIlBBg6/eep+98WxRFxSjN+iU3q0+sdUoZkKNwjdWDlkjcIj8BAubPLxLRBrlVOkIAzdlmtPrEzXqlZpJV1G7IASYnJwU5t+K3aPzzcddEKSIKiwrpAR4OyZQMhRd/uF2l/f6uV1LQyYHPQSgfHx8nE4yPfy4Im/jfBN2evM37/7fP5ed/heblz6OCrxYIB2/q2BEwXt61Q/mUjEkBTNdEIr8PXbt+nQ4c/Bld5+1sQwWPxr3M0VQmcDGyFoxmRArgeRUtFAOzckoCZwqaPwFys4pWQYbyNrJW6NNsUA96ytu+/7xQi0Q7E7KbDODHSv1mkgu+cHzuvb+wgt7OKUEgBArRRuFiNFMr9XVI9eDJ7FPv/e3vl4R56b1zv+FAiBg2SV5iYwK/fw0kRJZ5Nan3YGLopZ/nKOaVJEQZmMlaHrDHOErR3W6KGkc66tfPpWTr92NCZJXI2iamAJIuj37MbZSTvxtM3A0R8vWwrzqtmOcqLJzPZJQLQjBTWDS1zzZA1uB1d95s/v0YJ8jw3kxWZWg9eccAWVM9XXlz7ReHUiHFb1SVyBbSLo3JLULtTbnN6W9UfQFOlEd2UKiS/gAAAABJRU5ErkJggg==";function Xa({show:n,onClose:t,onContinue:r,onEmbed:a,tokenCount:o,maxTokens:i,fileCount:s=1,isEmbedding:c=!1,embedProgress:d=0}){const{user:g}=fe(),w=!g||g.role!=="default";return n?c?e.jsx(ye,{isOpen:n,children:e.jsx("div",{className:"relative max-w-[600px] bg-theme-bg-primary rounded-lg shadow border border-theme-modal-border",children:e.jsxs("div",{className:"p-6 flex flex-col items-center justify-center",children:[e.jsxs("p",{className:"text-white text-lg font-semibold mb-4",children:["Embedding ",d+1," of ",s," ",Ce("file",s)]}),e.jsx(Te,{size:32,className:"animate-spin text-white"}),e.jsx("p",{className:"text-white/60 text-sm mt-2",children:"Please wait while we embed your files..."})]})})}):e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"relative max-w-[600px] bg-theme-bg-primary rounded-lg shadow border border-theme-modal-border",children:[e.jsx("div",{className:"relative p-6 border-b border-theme-modal-border",children:e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsx("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:"Context Window Warning"})})}),e.jsxs("div",{className:"py-7 px-9 space-y-4",children:[e.jsxs("p",{className:"text-theme-text-primary text-sm",children:["Your workspace is using ",jt(o)," of"," ",jt(i)," available tokens. We recommend keeping usage below ",(Y.maxContextWindowLimit*100).toFixed(0),"% to ensure the best chat experience. Adding ",s," more"," ",Ce("file",s)," would exceed this limit."," ",e.jsx(nn,{target:"_blank",to:rn.documentation.contextWindows(),className:"text-theme-text-secondary text-sm underline",children:"Learn more about context windows →"})]}),e.jsx("p",{className:"text-theme-text-primary text-sm",children:"Choose how you would like to proceed with these uploads."})]}),e.jsxs("div",{className:"flex w-full justify-between items-center p-6 space-x-2 border-t border-theme-modal-border rounded-b",children:[e.jsx("button",{onClick:t,type:"button",className:"border-none transition-all duration-300 bg-theme-modal-border text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Cancel"}),e.jsxs("div",{className:"flex w-full justify-end items-center space-x-2",children:[e.jsx("button",{onClick:r,type:"button",className:"border-none transition-all duration-300 bg-theme-modal-border text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Continue Anyway"}),w&&e.jsxs("button",{onClick:a,disabled:c||!w,type:"button",className:"border-none transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:["Embed ",Ce("File",s)]})]})]})]})}):null}const gn=u.createContext(),_e="ATTACHMENT_REMOVE",Ut="ATTACHMENT_CLEAR",Ie="ATTACHMENT_PASTED",Je="ATTACHMENTS_PROCESSING",de="ATTACHMENTS_PROCESSED",Xe="PARSED_FILE_ATTACHMENT_REMOVED";function oi({workspace:n,threadSlug:t=null,children:r}){const[a,o]=u.useState([]),[i,s]=u.useState(!1),[c,d]=u.useState(!1),[g,w]=u.useState(!1),[m,v]=u.useState(!1),[f,b]=u.useState(0),[L,M]=u.useState([]),[P,z]=u.useState(0),[D,k]=u.useState(Number.POSITIVE_INFINITY);u.useEffect(()=>{ne.checkDocumentProcessorOnline().then(S=>s(S))},[]),u.useEffect(()=>(window.addEventListener(_e,_),window.addEventListener(Ut,I),window.addEventListener(Ie,B),window.addEventListener(Xe,T),()=>{window.removeEventListener(_e,_),window.removeEventListener(Ut,I),window.removeEventListener(Xe,T),window.removeEventListener(Ie,B)}),[]);async function T(S){const{document:E}=S.detail;o(N=>N.filter(O=>O.document.id!==E.id))}async function _(S){const{uid:E,document:N}=S.detail;o(O=>O.filter(p=>p.uid!==E)),N!=null&&N.location&&await Y.deleteAndUnembedFile(n.slug,N.location)}function I(){o([])}function Z(){var S;return((S=a==null?void 0:a.filter(E=>E.type==="attachment"))==null?void 0:S.map(E=>({name:E.file.name,mime:E.file.type,contentString:E.contentString})))||[]}async function B(S){const{files:E=[]}=S.detail;if(!E.length)return;const N=[];for(const O of E)O.type.startsWith("image/")?N.push({uid:ae(),file:O,contentString:await Wt(O),status:"success",error:null,type:"attachment"}):N.push({uid:ae(),file:O,contentString:null,status:"in_progress",error:null,type:"upload"});o(O=>[...O,...N]),H(N)}async function U(S,E){d(!1);const N=[];for(const O of S)O.type.startsWith("image/")?N.push({uid:ae(),file:O,contentString:await Wt(O),status:"success",error:null,type:"attachment"}):N.push({uid:ae(),file:O,contentString:null,status:"in_progress",error:null,type:"upload"});o(O=>[...O,...N]),H(N)}async function H(S=[]){window.dispatchEvent(new CustomEvent(Je));const E=[],{currentContextTokenCount:N,contextWindow:O}=await Y.getParsedFiles(n.slug,t),p=O?Math.floor(O*Y.maxContextWindowLimit):Number.POSITIVE_INFINITY;k(p);let l=N,x=[];for(const A of S){if(A.type==="attachment")continue;const V=new FormData;V.append("file",A.file,A.file.name),V.append("threadSlug",t||null),E.push(Y.parseFile(n.slug,V).then(async({response:R,data:F})=>{if(!R.ok){const re={status:"failed",error:(F==null?void 0:F.error)??null};o(Q=>Q.map(J=>J.uid!==A.uid?J:{...J,...re}));return}const $=F.files[0];if(l+=$.tokenCountEstimate,x.push({attachment:A,parsedFileId:$.id,tokenCount:$.tokenCountEstimate}),l>p){z(l),M(x),w(!0);return}const W={success:!0,document:$},q={status:"added_context",error:W.error??null,document:W.document};o(re=>re.map(Q=>Q.uid!==A.uid?Q:{...Q,...q}))}))}Promise.all(E).finally(()=>window.dispatchEvent(new CustomEvent(de)))}const j=async()=>{L.length&&(await Y.deleteParsedFiles(n.slug,L.map(S=>S.parsedFileId)),o(S=>S.filter(E=>!L.some(N=>N.attachment.uid===E.uid))),w(!1),M([]),z(0),window.dispatchEvent(new CustomEvent(de)))},y=async()=>{if(!L.length)return;const S=L.map(N=>({success:!0,document:{id:N.parsedFileId}})),E=L.map((N,O)=>({uid:N.attachment.uid,updates:{status:S[O].success?"success":"failed",error:S[O].error??null,document:S[O].document}}));o(N=>N.map(O=>{const p=E.find(l=>l.uid===O.uid);return p?{...O,...p.updates}:O})),w(!1),M([]),z(0)},C=async()=>{if(!L.length)return;v(!0),b(0);let S=0;const E=await Promise.all(L.map(O=>Y.embedParsedFile(n.slug,O.parsedFileId).then(p=>(S++,b(S),p)))),N=L.map((O,p)=>{var l,x;return{uid:O.attachment.uid,updates:{status:E[p].response.ok?"embedded":"failed",error:((l=E[p].data)==null?void 0:l.error)??null,document:(x=E[p].data)==null?void 0:x.document}}});o(O=>O.map(p=>{const l=N.find(x=>x.uid===p.uid);return l?{...p,...l.updates}:p})),w(!1),M([]),z(0),v(!1),window.dispatchEvent(new CustomEvent(de)),he(`${L.length} ${Ce("file",L.length)} embedded successfully`,"success")};return e.jsxs(gn.Provider,{value:{files:a,ready:i,dragging:c,setDragging:d,onDrop:U,parseAttachments:Z},children:[e.jsx(Xa,{show:g,onClose:j,onContinue:y,onEmbed:C,tokenCount:P,maxTokens:D,fileCount:L.length,isEmbedding:m,embedProgress:f}),r]})}function li({children:n}){const{onDrop:t,ready:r,dragging:a,setDragging:o}=u.useContext(gn),{getRootProps:i,getInputProps:s}=yr({onDrop:t,disabled:!r,noClick:!0,noKeyboard:!0,onDragEnter:()=>o(!0),onDragLeave:()=>o(!1)});return e.jsxs("div",{className:"relative flex flex-col h-full w-full md:mt-0 mt-[40px] p-[1px]",...i(),children:[e.jsx("div",{hidden:!a,className:"absolute top-0 w-full h-full bg-dark-text/90 light:bg-[#C2E7FE]/90 rounded-2xl border-[4px] border-white z-[9999]",children:e.jsx("div",{className:"w-full h-full flex justify-center items-center rounded-xl",children:e.jsxs("div",{className:"flex flex-col gap-y-[14px] justify-center items-center",children:[e.jsx("img",{src:Ja,width:69,height:69,alt:"Drag and drop icon"}),e.jsx("p",{className:"text-white text-[24px] font-semibold",children:"Add anything"}),e.jsxs("p",{className:"text-white text-[16px] text-center",children:["Drop a file or image here to attach it to your ",e.jsx("br",{}),"workspace auto-magically."]})]})})}),e.jsx("input",{id:"dnd-chat-file-uploader",...s()}),n]})}async function Wt(n){return new Promise((t,r)=>{const a=new FileReader;a.onload=()=>{const o=a.result.split(",")[1];t(`data:${n.type};base64,${o}`)},a.onerror=o=>r(o),a.readAsDataURL(n)})}function es({attachments:n}){if(n.length===0)return null;function t(r){const a=n.filter(i=>i.type==="attachment"&&i.contentString).map(i=>({contentString:i.contentString,name:i.file.name})),o=a.findIndex(i=>{var s;return i.name===((s=r.file)==null?void 0:s.name)});o!==-1&&qn(a,o)}return e.jsx("div",{className:"flex flex-wrap gap-2 mt-2 mb-4",children:n.map(r=>e.jsx(ts,{attachment:r,onImageClick:()=>t(r)},r.uid))})}function ts({attachment:n,onImageClick:t}){const{uid:r,file:a,status:o,error:i,document:s,type:c,contentString:d}=n,{iconBgColor:g,Icon:w}=ns(a);function m(){window.dispatchEvent(new CustomEvent(_e,{detail:{uid:r,document:s}}))}return o==="in_progress"?e.jsxs("div",{className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-bg border-none w-[180px] group",children:[e.jsx("div",{className:"bg-theme-attachment-icon-spinner-bg rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1",children:e.jsx(Te,{size:18,weight:"bold",className:"text-theme-attachment-icon-spinner animate-spin"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-theme-attachment-text text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium",children:"Uploading..."})]})]}):o==="failed"?e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":i,className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-error-bg border-none w-[180px] group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("div",{className:"bg-error rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1",children:e.jsx(lr,{size:24,className:"text-theme-attachment-icon"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-theme-attachment-text text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium truncate",children:i??"File not embedded!"})]})]}):c==="attachment"?d?e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":`${a.name} will be attached to this prompt. It will not be embedded into the workspace permanently.`,className:"relative flex items-center gap-x-1 rounded-lg border-none group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("button",{type:"button",onClick:t,className:"p-0 border-none bg-transparent cursor-pointer",children:e.jsx("img",{alt:`Preview of ${a.name}`,src:d,style:{objectFit:"cover",objectPosition:"center"},className:`${g} w-[40px] h-[40px] rounded-lg flex items-center justify-center`})})]}):e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":`${a.name} will be attached to this prompt. It will not be embedded into the workspace permanently.`,className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-success-bg border-none w-[180px] group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("div",{className:`${g} rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1`,children:e.jsx(w,{size:24,className:"text-theme-attachment-icon"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-theme-attachment-text text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium",children:"Image attached!"})]})]}):e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":o==="embedded"?`${a.name} was uploaded and embedded into this workspace. It will be available for RAG chat now.`:`${a.name} will be used as context for this chat only.`,className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-bg border-none w-[180px] group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("div",{className:`${g} rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1`,children:e.jsx(w,{size:24,weight:"light",className:"text-theme-attachment-icon"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-white text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium",children:o==="embedded"?"File embedded!":"Added as context!"})]})]})}function ns(n){var r,a,o;switch(((o=(a=(r=n==null?void 0:n.name)==null?void 0:r.split("."))==null?void 0:a.pop())==null?void 0:o.toLowerCase())??"txt"){case"pdf":return{iconBgColor:"bg-magenta",Icon:dr};case"doc":case"docx":return{iconBgColor:"bg-royalblue",Icon:ur};case"html":return{iconBgColor:"bg-purple",Icon:un};case"csv":case"xlsx":return{iconBgColor:"bg-success",Icon:cn};case"json":case"sql":case"js":case"jsx":case"cpp":case"c":return{iconBgColor:"bg-warn",Icon:ln};case"png":case"jpg":case"jpeg":return{iconBgColor:"bg-royalblue",Icon:dn};default:return{iconBgColor:"bg-royalblue",Icon:cr}}}function rs({onEmbeddingChange:n,tooltipRef:t,files:r,setFiles:a,currentTokens:o,setCurrentTokens:i,contextWindow:s,isLoading:c,workspaceSlug:d,threadSlug:g=null}){const{user:w}=fe(),m=!w||w.role!=="default",v=s&&o>=s*Y.maxContextWindowLimit,[f,b]=u.useState(!1),[L,M]=u.useState(1),[P,z]=u.useState(v);async function D(T,_){if(T.preventDefault(),T.stopPropagation(),!(_!=null&&_.id)||!await Y.deleteParsedFiles(d,[_.id]))return;a(U=>U.filter(H=>H.id!==_.id)),window.dispatchEvent(new CustomEvent(Xe,{detail:{document:_}}));const{currentContextTokenCount:Z}=await Y.getParsedFiles(d,g),B=s&&Z>=s*Y.maxContextWindowLimit;i(Z),z(B)}async function k(){var T;if(r.length){b(!0),n==null||n(!0),M(1);try{let _=0;await Promise.all(r.map(Z=>Y.embedParsedFile(d,Z.id).then(()=>{_++,M(_+1)}))),a([]);const{currentContextTokenCount:I}=await Y.getParsedFiles(d,g);i(I),z(I>=s*Y.maxContextWindowLimit),he(`${r.length} ${Ce("file",r.length)} embedded successfully`,"success"),(T=t==null?void 0:t.current)==null||T.close()}catch(_){console.error("Failed to embed files:",_),he("Failed to embed files","error")}b(!1),n==null||n(!1),M(1)}}return e.jsxs("div",{className:"flex flex-col gap-2 p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm font-medium text-theme-text-primary",children:["Current Context (",r.length," files)"]}),e.jsxs("div",{...P&&!m&&{"data-tooltip-id":"context-window-limit-exceeded","data-tooltip-content":"You have exceeded the context window limit. Some files may be truncated or excluded from chat responses. Responses may hallucinate or lack relevant information."},className:`flex items-center gap-x-1 ${P&&!m?"cursor-pointer":""}`,children:[P&&e.jsx(Et,{size:14,className:"text-orange-600"}),e.jsxs("div",{className:`text-xs ${P?"text-orange-600":"text-theme-text-secondary"}`,children:[At(o)," /"," ",s?At(s):"--"," tokens"]})]})]}),P&&m&&e.jsxs("div",{className:"flex flex-col gap-2 p-2 bg-theme-bg-secondary light:bg-theme-bg-primary rounded",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Et,{className:"flex-shrink-0 mt-1 text-yellow-500 light:text-yellow-600",size:16}),e.jsx("div",{className:"text-xs text-theme-text-primary",children:"Your context window is getting full. Some files may be truncated or excluded from chat responses. We recommend embedding these files directly into your workspace for better results."})]}),e.jsx("button",{onClick:k,disabled:f,className:"border-none disabled:opacity-50 flex items-center justify-center gap-2 px-3 py-2 text-xs bg-primary-button hover:bg-theme-button-primary-hover text-white font-medium rounded transition-colors shadow-sm",children:f?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"animate-spin"}),"Embedding ",L," of ",r.length," files..."]}):"Embed Files into Workspace"})]}),e.jsxs("div",{className:"flex flex-col gap-1 max-h-[300px] overflow-y-auto",children:[r.length>0&&r.map((T,_)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 p-2 text-xs bg-theme-bg-secondary rounded",children:[e.jsx("div",{className:"truncate flex-1 text-theme-text-primary",children:T.title}),e.jsx("button",{onClick:I=>D(I,T),className:"border-none text-theme-text-secondary hover:text-theme-text-primary",disabled:f,children:e.jsx(oe,{size:16})})]},_)),c&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-theme-text-secondary text-center py-2",children:[e.jsx(Te,{size:16,className:"animate-spin"}),"Loading..."]}),!c&&r.length===0&&e.jsx("div",{className:"text-xs text-theme-text-secondary text-center py-2",children:"No files found"})]})]})}function as({workspaceSlug:n=null,workspaceThreadSlug:t=null}){const{t:r}=K(),{theme:a}=Gn(),{enabled:o}=He("agentMode"),i=De(),s=n||i.slug,c=t??i.threadSlug??null;if(!o)return null;const d=u.useRef(null),[g,w]=u.useState(!1),[m,v]=u.useState([]),[f,b]=u.useState(0),[L,M]=u.useState(1/0),[P,z]=u.useState(!1),[D,k]=u.useState(!0),T=()=>{s&&(g||(k(!0),Y.getParsedFiles(s,c).then(({files:Z,contextWindow:B,currentContextTokenCount:U})=>{v(Z),z(Z.length>0),M(B),b(U)}).finally(()=>{k(!1)})))};async function _(Z){const{document:B}=Z.detail;await Y.deleteParsedFiles(s,[B.id]),T()}function I(Z){var B,U;(B=Z==null?void 0:Z.target)==null||B.blur(),(U=document==null?void 0:document.getElementById("dnd-chat-file-uploader"))==null||U.click()}return u.useEffect(()=>(T(),window.addEventListener(de,T),window.addEventListener(_e,_),()=>{window.removeEventListener(de,T),window.removeEventListener(_e,_)}),[s,c]),e.jsxs(e.Fragment,{children:[e.jsx("button",{id:"attach-item-btn","data-tooltip-id":P?"tooltip-attach-item-btn":"attach-item-btn","data-tooltip-content":P?void 0:r("chat_window.attach_file"),"aria-label":r("chat_window.attach_file"),type:"button",onClick:I,onPointerEnter:T,className:"group border-none relative flex justify-center items-center cursor-pointer w-6 h-6 rounded-full hover:bg-zinc-700 light:hover:bg-slate-200",children:e.jsxs("div",{className:"relative",children:[e.jsx(et,{size:18,className:"pointer-events-none text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-600 shrink-0",weight:"bold"}),m.length>0&&e.jsx("div",{className:"absolute -top-2.5 -right-2 bg-white text-black light:invert text-[8px] rounded-full px-1 flex items-center justify-center",children:m.length})]})}),P&&e.jsx(G,{ref:d,id:"tooltip-attach-item-btn",place:"top",opacity:1,clickable:!g,delayShow:300,delayHide:g?999999:800,arrowColor:a==="light"?"var(--theme-modal-border)":"var(--theme-bg-primary)",className:"z-99 !w-[400px] !bg-theme-bg-primary !px-[5px] !rounded-lg !pointer-events-auto light:border-2 light:border-theme-modal-border",children:e.jsx(rs,{onEmbeddingChange:w,tooltipRef:d,isLoading:D,files:m,setFiles:v,currentTokens:f,setCurrentTokens:b,contextWindow:L,workspaceSlug:s,threadSlug:c})})]})}function ss(){const[n,t]=u.useState("normal"),[r,a]=u.useState("text-[14px]"),o=i=>{switch(i){case"small":return"text-[12px]";case"large":return"text-[18px]";default:return"text-[14px]"}};return u.useEffect(()=>{const i=window.localStorage.getItem("anythingllm_text_size");i&&(t(i),a(o(i)));const s=c=>{const d=c.detail;t(d),a(o(d))};return window.addEventListener("textSizeChange",s),()=>{window.removeEventListener("textSizeChange",s)}},[]),{textSize:n,textSizeClass:r}}function ci(n){try{const t=Oe(localStorage.getItem(Me),{});t[n]="",localStorage.setItem(Me,JSON.stringify(t))}catch{}}function is({promptInput:n,setPromptInput:t}){const{threadSlug:r=null,slug:a}=De();u.useEffect(()=>{const i=localStorage.getItem(Me)||"{}",c=Oe(i,{})[r??a];c&&t(c)},[]);const o=u.useMemo(()=>an((i,s)=>{const c=localStorage.getItem(Me)||"{}",d=Oe(c,{});d[s]=i,localStorage.setItem(Me,JSON.stringify(d))},500),[]);u.useEffect(()=>(o(n,r??a),()=>{o.cancel()}),[n,r,a,o])}function xn({items:n,highlightedIndex:t,onSelect:r,registerItemCount:a}){u.useEffect(()=>{a==null||a(n.length)},[n.length,a]),u.useEffect(()=>{if(t<0||t>=n.length)return;function o(i){i.detail.key==="Enter"&&r(n[t])}return window.addEventListener(je,o),()=>window.removeEventListener(je,o)},[t,n,r])}function Ke(n){return Object.values(n).flatMap(t=>t.skills)}const Ee={"create-files-agent":{preferenceKey:"disabled_create_files_skills",getSubSkills:n=>hr(n)},"filesystem-agent":{preferenceKey:"disabled_filesystem_skills",getSubSkills:n=>mr(n)},"gmail-agent":{preferenceKey:"disabled_gmail_skills",getSubSkills:n=>Ke(pr(n)),isMultiUserSupported:!1},"google-calendar-agent":{preferenceKey:"disabled_google_calendar_skills",getSubSkills:n=>Ke(fr(n)),isMultiUserSupported:!1},"outlook-agent":{preferenceKey:"disabled_outlook_skills",getSubSkills:n=>Ke(gr(n)),isMultiUserSupported:!1}};function os(){return Object.values(Ee).map(n=>n.preferenceKey)}function ls(n,t){const r=Ee[n];return r?r.getSubSkills(t):null}function Kt(n){var t;return((t=Ee[n])==null?void 0:t.preferenceKey)??null}function cs(n){return n in Ee}function us(n){var t;return((t=Ee[n])==null?void 0:t.isMultiUserSupported)!==!1}function ds(){const[n,t]=u.useState({}),r=u.useCallback(i=>{if(!i)return;const s={};for(const[,c]of Object.entries(Ee)){const d=i[c.preferenceKey];s[c.preferenceKey]=d??[]}t(s)},[]),a=u.useCallback((i,s)=>{const c=Kt(i);return c?!(n[c]??[]).includes(s):!0},[n]),o=u.useCallback(async(i,s)=>{const c=Kt(i);if(!c)return;const d=n[c]??[],g=d.includes(s)?d.filter(w=>w!==s):[...d,s];t(w=>({...w,[c]:g})),await we.updateSystemPreferences({[c]:g.join(",")})},[n]);return{loadFromSettings:r,isSubSkillEnabled:a,toggleSubSkill:o,disabledSubSkills:n}}function hs(n){const[t,r]=u.useState(!1),[a,o]=u.useState(!1),[i,s]=u.useState([]),[c,d]=u.useState([]),[g,w]=u.useState([]),[m,v]=u.useState([]),[f,b]=u.useState([]),[L,M]=u.useState(!0),[P,z]=u.useState(!0),D=ds();u.useEffect(()=>{k(),T()},[]);async function k(){try{const H=os(),[j,y,C,S]=await Promise.all([we.systemPreferencesByFields(["disabled_agent_skills","default_agent_skills","imported_agent_skills",...H]),Ct.listFlows(),ne.isFileSystemAgentAvailable(),ne.isMultiUserMode()]);j!=null&&j.settings&&(s(j.settings.disabled_agent_skills??[]),d(j.settings.default_agent_skills??[]),w(j.settings.imported_agent_skills??[]),D.loadFromSettings(j.settings)),y!=null&&y.flows&&v(y.flows),r(C),o(!!S)}catch(H){console.error(H)}finally{M(!1)}}async function T(){try{const{servers:H=[]}=await Nt.listServers();b(H)}catch(H){console.error(H)}finally{z(!1)}}const _=u.useCallback(H=>H in n?!i.includes(H):c.includes(H),[n,i,c]),I=u.useCallback(async H=>{const j=(C,S)=>C.includes(S)?C.filter(E=>E!==S):[...C,S];if(H in n){const C=j(i,H);s(C),await we.updateSystemPreferences({disabled_agent_skills:C.join(","),default_agent_skills:c.join(",")});return}const y=j(c,H);d(y),await we.updateSystemPreferences({disabled_agent_skills:i.join(","),default_agent_skills:y.join(",")})},[n,i,c]),Z=u.useCallback(async H=>{const j=!H.active;w(y=>y.map(C=>C.hubId===H.hubId?{...C,active:j}:C)),await Yn.toggleFeature(H.hubId,j)},[]),B=u.useCallback(async H=>{const j=!H.active;v(y=>y.map(C=>C.uuid===H.uuid?{...C,active:j}:C)),await Ct.toggleFlow(H.uuid,j)},[]),U=u.useCallback(async(H,j,y)=>{const C=!y;b(S=>S.map(E=>{var p,l,x;if(E.name!==H)return E;const N=((l=(p=E.config)==null?void 0:p.anythingllm)==null?void 0:l.suppressedTools)||[],O=C?N.filter(A=>A!==j):[...N,j];return{...E,config:{...E.config,anythingllm:{...(x=E.config)==null?void 0:x.anythingllm,suppressedTools:O}}}})),await Nt.toggleTool(H,j,C)},[]);return{fileSystemAgentAvailable:t,isMultiUser:a,disabledDefaults:i,enabledConfigurable:c,importedSkills:g,flows:m,mcpServers:f,loading:L,mcpLoading:P,isSkillEnabled:_,toggleSkill:I,toggleImportedSkill:Z,toggleFlow:B,toggleMcpTool:U,isSubSkillEnabled:D.isSubSkillEnabled,toggleSubSkill:D.toggleSubSkill,disabledSubSkills:D.disabledSubSkills}}function qt({key:n,title:t,isEnabled:r,onToggle:a,t:o,isSubSkillEnabled:i,toggleSubSkill:s}){const c=ls(n,o),d=r(n);return{id:n,name:t,enabled:d,onToggle:()=>a(n),hasSubSkills:cs(n),subSkills:c?c.map(g=>({id:`${n}::${g.name}`,name:g.title,enabled:d&&i(n,g.name),onToggle:()=>s(n,g.name),parentEnabled:d})):null}}function ms({t:n,defaultSkills:t,configurableSkills:r,appIntegrationSkills:a,importedSkills:o,flows:i,mcpServers:s,isMultiUser:c,isSkillEnabled:d,toggleSkill:g,isSubSkillEnabled:w,toggleSubSkill:m,toggleImportedSkill:v,toggleFlow:f,toggleMcpTool:b,disabledSubSkills:L}){return u.useMemo(()=>{var D,k;const M=[],P=[];for(const[T,{title:_}]of Object.entries({...t,...r}))P.push(qt({key:T,title:_,isEnabled:d,onToggle:g,t:n,isSubSkillEnabled:w,toggleSubSkill:m}));P.length>0&&M.push({id:"agent-skills",name:n("chat_window.agent_skills"),items:P,enabledCount:P.filter(T=>T.enabled).length});const z=[];for(const[T,{title:_}]of Object.entries(a))c&&!us(T)||z.push(qt({key:T,title:_,isEnabled:d,onToggle:g,t:n,isSubSkillEnabled:w,toggleSubSkill:m}));if(z.length>0&&M.push({id:"app-integrations",name:n("chat_window.app_integrations"),items:z,enabledCount:z.filter(T=>T.enabled).length}),o.length>0){const T=o.map(_=>({id:_.hubId,name:_.name,enabled:_.active,onToggle:()=>v(_)}));M.push({id:"custom-skills",name:n("chat_window.custom_skills"),items:T,enabledCount:T.filter(_=>_.enabled).length})}if(i.length>0){const T=i.map(_=>({id:_.uuid,name:_.name,enabled:_.active,onToggle:()=>f(_)}));M.push({id:"agent-flows",name:n("chat_window.agent_flows"),items:T,enabledCount:T.filter(_=>_.enabled).length})}for(const T of s){if(!T.running||T.tools.length===0)continue;const _=((k=(D=T.config)==null?void 0:D.anythingllm)==null?void 0:k.suppressedTools)||[],I=T.tools.map(Z=>({id:`mcp::${T.name}::${Z.name}`,name:Z.name,enabled:!_.includes(Z.name),onToggle:()=>b(T.name,Z.name,!_.includes(Z.name))}));M.push({id:`mcp-${T.name}`,name:Qn(T.name.replace(/[_-]/g," ")),isMcp:!0,items:I,enabledCount:I.filter(Z=>Z.enabled).length})}return M},[n,t,r,a,o,i,s,c,d,g,w,m,v,f,b,L])}function Gt({name:n,enabled:t,onToggle:r,highlighted:a=!1,disabled:o=!1}){const i=u.useRef(null);u.useEffect(()=>{var c;a&&((c=i.current)==null||c.scrollIntoView({block:"nearest"}))},[a]);let s="border-none bg-transparent w-full flex items-center justify-between px-2 py-1 rounded";return a?s+=" bg-zinc-700/50 light:bg-slate-100":s+=" hover:bg-zinc-700/50 light:hover:bg-slate-100",o?s+=" opacity-60 cursor-not-allowed":s+=" cursor-pointer",e.jsxs("button",{ref:i,type:"button",className:s,onClick:()=>!o&&r(),"data-tooltip-id":o?"agent-skill-disabled-tooltip":void 0,children:[e.jsx("span",{className:"text-xs text-white light:text-slate-900",children:n}),e.jsx("div",{className:"pointer-events-none","aria-hidden":"true",children:e.jsx(Qe,{size:"sm",enabled:t})})]})}function Yt({name:n,expanded:t,onToggle:r,enabledCount:a,totalCount:o,isMcp:i=!1,indented:s=!1,highlighted:c=!1,children:d}){const g=u.useRef(null);u.useEffect(()=>{var m;c&&((m=g.current)==null||m.scrollIntoView({block:"nearest"}))},[c]);let w="border-none bg-transparent w-full flex items-center justify-between px-2 py-1 rounded cursor-pointer";return c?w+=" bg-zinc-700/50 light:bg-slate-100":w+=" hover:bg-zinc-700/30 light:hover:bg-slate-50",e.jsxs("div",{className:s?"ml-3":"",children:[e.jsxs("button",{ref:g,type:"button",className:w,onClick:r,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Jn,{size:10,weight:"bold",className:`text-zinc-400 light:text-slate-500 transition-transform duration-150 ${t?"":"-rotate-90"}`}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-zinc-400 light:text-slate-500",children:n}),i&&e.jsx("span",{className:"text-[8px] px-1 py-px rounded bg-zinc-600/50 light:bg-slate-200 text-zinc-300 light:text-slate-500 font-medium leading-tight",children:"MCP"})]}),e.jsxs("span",{className:"text-[10px] text-zinc-500 light:text-slate-400 tabular-nums",children:[a,"/",o]})]}),t&&e.jsx("div",{className:"pl-3",children:d})]})}const ps="agentSessionStart",fs="agentSessionEnd",gs=["statusResponse","fileDownloadCard","awaitingFeedback","wssFailure","rechartVisualize","toolApprovalRequest","clarificationRequest","reportStreamEvent"];function ui(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${new URL("http://localhost:3001/api").host}`}function di(n,t,r){var o,i;const a=Oe(t.data,null);if(a!==null){if(a.type==="rename_thread"){const{slug:s,name:c}=a.content||{};s&&c&&window.dispatchEvent(new CustomEvent(Xn,{detail:{threadSlug:s,newName:c}}));return}if(!a.hasOwnProperty("type")&&!n.supportsAgentStreaming)return r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]);if(a.type==="toolApprovalRequest"){if(!a.requestId||!a.skillName)return}else if(a.type==="clarificationRequest"){if(!a.requestId||!Array.isArray(a.questions))return}else if(!gs.includes(a.type)||!a.content)return;return a.type==="reportStreamEvent"?(n.supportsAgentStreaming=!0,((o=a.content)==null?void 0:o.type)==="chatId"&&((i=a.content)!=null&&i.chatId)&&er(a.content.chatId),r(s=>{if(a.content.type==="removeStatusResponse")return[...s.filter(d=>d.uuid!==a.content.uuid)];if(a.content.type==="modelRouteNotification")return a.content.routedTo?[...s.filter(d=>!(d.role==="assistant"&&d.pending&&!d.content)),{uuid:a.content.uuid,type:"modelRouteNotification",content:"modelRouteNotification",routedTo:a.content.routedTo}]:s;if(a.content.uuid?s.find(d=>d.uuid===a.content.uuid):null){const{type:d,content:g,uuid:w}=a.content;if(d==="toolCallInvocation"){const m=s.find(v=>v.uuid===w);return m?[...s.filter(v=>v.uuid!==w),{...m,content:g}]:[...s,{uuid:w,type:"toolCallInvocation",content:g}]}return d==="usageMetrics"?a.content.metrics?s.map(m=>m.uuid===w?{...m,metrics:a.content.metrics}:m):s:d==="citations"?a.content.citations?s.map(m=>m.uuid===w?{...m,sources:[...m.sources||[],...a.content.citations]}:m):s:d==="chatId"?a.content.chatId?s.map(m=>m.uuid===w?{...m,chatId:a.content.chatId}:m):s:d==="textResponseChunk"?s.map(m=>m.uuid===w?{...m,type:"textResponse",content:m.content+g}:m!=null&&m.content?m:null).filter(m=>!!m):s.map(m=>m.uuid===a.content.uuid?{...m,content:m.content+a.content.content}:m)}else return a.content.type==="fullTextResponse"?[...s.filter(d=>!!d.content),{uuid:a.content.uuid,type:"textResponse",content:a.content.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]:a.content.type==="textResponseChunk"?a.content.content.trim()===""?s:[...s.filter(d=>!!d.content),{uuid:a.content.uuid,type:"textResponse",content:a.content.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]:[...s.filter(d=>!!d.content),{uuid:a.content.uuid,type:"statusResponse",content:a.content.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]})):a.type==="fileDownloadCard"?r(s=>[...s.filter(c=>!!c.content),{type:"fileDownloadCard",uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:a.metrics||{}}]):a.type==="rechartVisualize"?r(s=>[...s.filter(c=>!!c.content),{type:"rechartVisualize",uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:a.metrics||{}}]):a.type==="wssFailure"?r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:a.content,animate:!1,pending:!1,metrics:{}}]):a.type==="toolApprovalRequest"?r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),type:"toolApprovalRequest",requestId:a.requestId,skillName:a.skillName,payload:a.payload,description:a.description,timeoutMs:a.timeoutMs,content:`Approval requested for ${a.skillName}`,role:"assistant",sources:[],closed:!1,error:null,animate:!1,pending:!0,metrics:{}}]):a.type==="clarificationRequest"?r(s=>{var c,d;return[...s.filter(g=>!!g.content),{uuid:ae(),type:"clarifyingQuestion",requestId:a.requestId,questions:a.questions||[],allowSkip:a.allowSkip!==!1,timeoutMs:a.timeoutMs,content:`Agent has ${((c=a.questions)==null?void 0:c.length)||0} question${(((d=a.questions)==null?void 0:d.length)||0)===1?"":"s"}`,role:"assistant",sources:[],closed:!1,error:null,animate:!1,pending:!0,metrics:{}}]}):r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),type:a.type,content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:(a==null?void 0:a.animate)||!1,pending:!1,metrics:a.metrics||{}}])}}let bn=!1;function hi(n){bn=n}function xs(){return bn}function vn(){const[n,t]=u.useState(()=>!!xs());return u.useEffect(()=>{function r(){window&&(window.addEventListener(ps,()=>t(!0)),window.addEventListener(fs,()=>t(!1)))}r()},[]),n}const bs=10;function vs({highlightedIndex:n=-1,registerItemCount:t,workspace:r}){const{t:a}=K(),{showAgentCommand:o=!0}=r??{},i=vn(),s=xr(a),c=br(a),{fileSystemAgentAvailable:d,importedSkills:g,flows:w,mcpServers:m,loading:v,mcpLoading:f,isSkillEnabled:b,toggleSkill:L,toggleImportedSkill:M,toggleFlow:P,toggleMcpTool:z,isMultiUser:D,isSubSkillEnabled:k,toggleSubSkill:T,disabledSubSkills:_}=hs(s),I=vr(a,{fileSystemAgentAvailable:d}),[Z,B]=u.useState({}),[U,H]=u.useState({}),[j,y]=u.useState(""),C=o&&!i,S=ms({t:a,defaultSkills:s,configurableSkills:I,appIntegrationSkills:c,importedSkills:g,flows:w,mcpServers:m,isMultiUser:D,isSkillEnabled:b,toggleSkill:L,isSubSkillEnabled:k,toggleSubSkill:T,toggleImportedSkill:M,toggleFlow:P,toggleMcpTool:z,disabledSubSkills:_});function E(R){return!!(j.trim()||Z[R])}function N(R){B(F=>({...F,[R]:!F[R]}))}function O(R){return!!(j.trim()||U[R])}function p(R){H(F=>({...F,[R]:!F[R]}))}const l=u.useMemo(()=>{if(!j.trim())return S;const R=j.toLowerCase();return S.map(F=>{const $=F.items.filter(W=>{var Q;const q=W.name.toLowerCase().includes(R),re=((Q=W.subSkills)==null?void 0:Q.some(J=>J.name.toLowerCase().includes(R)))??!1;return q||re});return{...F,items:$,enabledCount:$.filter(W=>W.enabled).length}}).filter(F=>F.items.length>0)},[S,j]),{flatItems:x,flatIndexMap:A}=u.useMemo(()=>{const R=[],F={};for(const $ of l)if(F[$.id]=R.length,R.push({type:"header",id:$.id,onToggle:()=>N($.id)}),E($.id)){for(const W of $.items)if(F[W.id]=R.length,R.push(W),W.hasSubSkills&&W.subSkills&&(F[`subsection-${W.id}`]=R.length,R.push({type:"subheader",id:`subsection-${W.id}`,parentId:W.id,onToggle:()=>p(W.id)}),O(W.id)))for(const q of W.subSkills)F[q.id]=R.length,R.push(q)}return{flatItems:R,flatIndexMap:F}},[l,Z,U,j]),V=S.reduce((R,F)=>R+F.items.length,0);return xn({items:x,highlightedIndex:n,onSelect:R=>{if(R.type==="header")return R.onToggle();i||R.onToggle()},registerItemCount:t}),v?null:e.jsxs(e.Fragment,{children:[C&&e.jsx("p",{className:"text-xs text-theme-text-secondary text-center py-1",children:a("chat_window.use_agent_session_to_use_tools")}),V>=bs&&e.jsx(ws,{value:j,onChange:y,placeholder:a("common.search")}),l.map(R=>e.jsx(Yt,{name:R.name,expanded:E(R.id),onToggle:()=>N(R.id),enabledCount:R.enabledCount,totalCount:R.items.length,isMcp:R.isMcp,highlighted:n===A[R.id],children:R.items.map(F=>e.jsxs("div",{children:[e.jsx(Gt,{name:F.name,enabled:F.enabled,onToggle:F.onToggle,highlighted:n===A[F.id],disabled:i}),F.hasSubSkills&&F.subSkills&&F.enabled&&e.jsx(Yt,{name:a("chat_window.sub_skills"),expanded:O(F.id),onToggle:()=>p(F.id),enabledCount:F.subSkills.filter($=>$.enabled).length,totalCount:F.subSkills.length,highlighted:n===A[`subsection-${F.id}`],indented:!0,children:F.subSkills.map($=>e.jsx(Gt,{name:$.name,enabled:$.enabled,onToggle:$.onToggle,highlighted:n===A[$.id],disabled:i||!$.parentEnabled},$.id))})]},F.id))},R.id)),f&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:[e.jsx(Te,{size:12,className:"text-zinc-500 light:text-slate-400 animate-spin",weight:"bold"}),e.jsx("span",{className:"text-[10px] text-zinc-500 light:text-slate-400",children:a("chat_window.loading_mcp_servers")})]}),l.length===0&&!f&&j.trim()&&e.jsx("p",{className:"text-xs text-zinc-500 light:text-slate-400 text-center py-2",children:a("chat_window.no_tools_found")}),e.jsx(nn,{to:rn.settings.agentSkills(),children:e.jsxs("button",{className:"border-none flex items-center gap-1.5 px-2 h-6 rounded cursor-pointer hover:bg-zinc-700/50 light:hover:bg-slate-100 text-theme-text-primary",children:[e.jsx(tr,{size:12,className:"text-theme-text-primary"}),e.jsx("span",{className:"text-xs text-theme-text-primary",children:a("chat_window.manage_agent_skills")})]})})]})}function ws({value:n,onChange:t,placeholder:r}){return e.jsxs("div",{className:"relative shrink-0",children:[e.jsx(en,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-zinc-400 light:text-slate-400",weight:"bold"}),e.jsx("input",{type:"text",placeholder:r,value:n,onChange:a=>t(a.target.value),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.key==="Escape"&&(t(""),a.target.blur()),a.key==="Enter"&&a.preventDefault()},className:"w-full pl-7 pr-2 py-1 text-xs bg-zinc-700/50 light:bg-slate-100 border border-zinc-600 light:border-slate-300 rounded text-white light:text-slate-900 placeholder:text-zinc-500 light:placeholder:text-slate-400 outline-none focus:border-zinc-500 light:focus:border-slate-400"})]})}const Ze=/[^a-zA-Z0-9_-]/g;function ys({isOpen:n,onClose:t,onSave:r}){const[a,o]=u.useState(""),{t:i}=K(),s=async d=>{d.preventDefault();const g=new FormData(d.target),w=a.replace(Ze,"");await r({command:`/${w}`,prompt:g.get("prompt"),description:g.get("description")})&&o("")},c=d=>{const g=d.target.value.replace(Ze,"");o(g)};return e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"w-full max-w-2xl bg-theme-bg-secondary rounded-lg shadow border-2 border-theme-modal-border overflow-hidden",children:[e.jsxs("div",{className:"relative p-6 border-b rounded-t border-theme-modal-border",children:[e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsx("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:i("chat_window.add_new_preset")})}),e.jsx("button",{onClick:t,type:"button",className:"absolute top-4 right-4 transition-all duration-300 bg-transparent rounded-lg text-sm p-1 inline-flex items-center hover:bg-theme-modal-border hover:border-theme-modal-border hover:border-opacity-50 border-transparent border",children:e.jsx(oe,{size:24,weight:"bold",className:"text-white"})})]}),e.jsx("div",{className:"h-full w-full overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:e.jsxs("form",{onSubmit:s,children:[e.jsx("div",{className:"py-7 px-9 space-y-2 flex-col",children:e.jsxs("div",{className:"w-full flex flex-col gap-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"command",className:"block mb-2 text-sm font-medium text-white",children:i("chat_window.command")}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-white text-sm mr-2 font-bold",children:"/"}),e.jsx("input",{name:"command",type:"text",id:"command",placeholder:i("chat_window.your_command"),value:a,onChange:c,maxLength:25,autoComplete:"off",required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"prompt",className:"block mb-2 text-sm font-medium text-white",children:"Prompt"}),e.jsx("textarea",{name:"prompt",id:"prompt",autoComplete:"off",placeholder:i("chat_window.placeholder_prompt"),required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"description",className:"block mb-2 text-sm font-medium text-white",children:i("chat_window.description")}),e.jsx("input",{type:"text",name:"description",id:"description",placeholder:i("chat_window.placeholder_description"),maxLength:80,autoComplete:"off",required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]})}),e.jsxs("div",{className:"flex w-full justify-end items-center p-6 space-x-2 border-t border-theme-modal-border rounded-b",children:[e.jsx("button",{onClick:t,type:"button",className:"transition-all duration-300 bg-transparent text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:i("chat_window.cancel")}),e.jsx("button",{type:"submit",className:"transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:i("chat_window.save")})]})]})})]})})}function Ss({isOpen:n,onClose:t,onSave:r,onDelete:a,preset:o}){const[i,s]=u.useState(""),[c,d]=u.useState(!1);u.useEffect(()=>{var v;o&&n&&s(((v=o.command)==null?void 0:v.slice(1))||"")},[o,n]);const g=v=>{v.preventDefault();const f=new FormData(v.target),b=i.replace(Ze,"");r({id:o.id,command:`/${b}`,prompt:f.get("prompt"),description:f.get("description")})},w=v=>{const f=v.target.value.replace(Ze,"");s(f)},m=async()=>{window.confirm("Are you sure you want to delete this preset?")&&(d(!0),await a(o.id),d(!1),t())};return e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"w-full max-w-2xl bg-theme-bg-secondary rounded-lg shadow border-2 border-theme-modal-border overflow-hidden",children:[e.jsxs("div",{className:"relative p-6 border-b rounded-t border-theme-modal-border",children:[e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsx("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:"Edit Preset"})}),e.jsx("button",{onClick:t,type:"button",className:"absolute top-4 right-4 transition-all duration-300 bg-transparent rounded-lg text-sm p-1 inline-flex items-center hover:bg-theme-modal-border hover:border-theme-modal-border hover:border-opacity-50 border-transparent border",children:e.jsx(oe,{size:24,weight:"bold",className:"text-white"})})]}),e.jsx("div",{className:"h-full w-full overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:e.jsxs("form",{onSubmit:g,children:[e.jsx("div",{className:"py-7 px-9 space-y-2 flex-col",children:e.jsxs("div",{className:"w-full flex flex-col gap-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"command",className:"block mb-2 text-sm font-medium text-white",children:"Command"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-white text-sm mr-2 font-bold",children:"/"}),e.jsx("input",{type:"text",name:"command",placeholder:"your-command",value:i,onChange:w,required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"prompt",className:"block mb-2 text-sm font-medium text-white",children:"Prompt"}),e.jsx("textarea",{name:"prompt",placeholder:"This is a test prompt. Please respond with a poem about LLMs.",defaultValue:o.prompt,required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"description",className:"block mb-2 text-sm font-medium text-white",children:"Description"}),e.jsx("input",{type:"text",name:"description",defaultValue:o.description,placeholder:"Responds with a poem about LLMs.",required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]})}),e.jsxs("div",{className:"flex w-full justify-between items-center p-6 space-x-2 border-t border-theme-modal-border rounded-b",children:[e.jsx("button",{disabled:c,onClick:m,type:"button",className:"border-none transition-all duration-300 bg-transparent text-red-500 hover:bg-red-500/25 px-4 py-2 rounded-lg text-sm disabled:opacity-50",children:c?"Deleting...":"Delete Preset"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{onClick:t,type:"button",className:"border-none transition-all duration-300 bg-transparent text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Cancel"}),e.jsx("button",{type:"submit",className:"transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Save"})]})]})]})})]})})}function js({command:n,description:t,onClick:r,onEdit:a,onPublish:o,showMenu:i=!1,highlighted:s=!1}){const{t:c}=K(),[d,g]=u.useState(!1),[w,m]=u.useState({top:0,left:0}),v=u.useRef(null),f=u.useRef(null);return u.useEffect(()=>{if(!d)return;function b(L){v.current&&!v.current.contains(L.target)&&f.current&&!f.current.contains(L.target)&&g(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[d]),u.useEffect(()=>{if(d&&f.current){const b=f.current.getBoundingClientRect();m({top:b.bottom+window.scrollY,left:b.right+window.scrollX-120})}},[d]),e.jsxs("div",{onClick:r,className:`flex items-center justify-between px-2 py-1 rounded cursor-pointer group relative ${s?"bg-zinc-700/50 light:bg-slate-100":"hover:bg-zinc-700/50 light:hover:bg-slate-100"}`,children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-xs min-w-0 flex-1",children:[e.jsx("span",{className:"text-white light:text-slate-900 shrink-0",children:n}),e.jsx("span",{className:"text-zinc-400 light:text-slate-500 italic truncate",children:t})]}),i&&e.jsxs("div",{className:"relative shrink-0 ml-1",children:[e.jsx("button",{ref:f,type:"button",onClick:b=>{b.stopPropagation(),g(!d)},className:"border-none cursor-pointer text-zinc-400 light:text-slate-500 p-0.5 hover:text-white light:hover:text-slate-900 rounded opacity-0 group-hover:opacity-100",children:e.jsx(nr,{size:16,weight:"bold"})}),d&&Fe.createPortal(e.jsxs("div",{ref:v,style:{position:"fixed",top:w.top,left:w.left},className:"z-[9999] bg-zinc-800 light:bg-white border border-zinc-700 light:border-slate-300 rounded-lg shadow-lg min-w-[120px] flex flex-col overflow-hidden",children:[e.jsx("button",{type:"button",className:"border-none px-3 py-1.5 text-xs text-white light:text-slate-900 hover:bg-zinc-700 light:hover:bg-slate-100 cursor-pointer text-left",onClick:b=>{b.stopPropagation(),g(!1),a==null||a()},children:c("chat_window.edit")}),e.jsx("button",{type:"button",className:"border-none px-3 py-1.5 text-xs text-white light:text-slate-900 hover:bg-zinc-700 light:hover:bg-slate-100 cursor-pointer text-left",onClick:b=>{b.stopPropagation(),g(!1),o==null||o()},children:c("chat_window.publish")})]}),document.body)]})]})}function Es({sendCommand:n,setShowing:t,promptRef:r,highlightedIndex:a=-1,registerItemCount:o}){const{t:i}=K(),{isOpen:s,openModal:c,closeModal:d}=Ve(),{isOpen:g,openModal:w,closeModal:m}=Ve(),{isOpen:v,openModal:f,closeModal:b}=Ve(),[L,M]=u.useState([]),[P,z]=u.useState(null),[D,k]=u.useState(null);u.useEffect(()=>{T()},[]);const T=async()=>{const y=await ne.getSlashCommandPresets();M(y)},_=u.useMemo(()=>[{command:"/reset",description:i("chat_window.preset_reset_description"),autoSubmit:!0},...L.map(y=>({command:y.command,description:y.description,autoSubmit:!1,preset:y}))],[L,i]),I=u.useCallback((y,C=!1)=>{var A;if(t(!1),C){n({text:y,autoSubmit:!0}),(A=r==null?void 0:r.current)==null||A.focus();return}const S=r==null?void 0:r.current;if(!S)return;const E=S.selectionStart,N=S.value,p=(E>0?N[E-1]:"")==="/"?E-1:E,l=N.slice(0,p)+y+N.slice(E);window.dispatchEvent(new CustomEvent(Le,{detail:{messageContent:l}})),S.focus();const x=p+y.length;setTimeout(()=>S.setSelectionRange(x,x),0)},[n,t,r]);xn({items:_,highlightedIndex:a,onSelect:y=>{const C=y.preset?`${y.command} `:y.command;I(C,y.autoSubmit)},registerItemCount:o});const Z=async y=>{const{error:C}=await ne.createSlashCommandPreset(y);return C?(he(C,"error"),!1):(T(),d(),!0)},B=y=>{z(y),w()},U=async y=>{const{error:C}=await ne.updateSlashCommandPreset(y.id,y);if(C){he(C,"error");return}T(),m(),z(null)},H=async y=>{await ne.deleteSlashCommandPreset(y),T(),m(),z(null)},j=y=>{k({name:y.command.slice(1),description:y.description,command:y.command,prompt:y.prompt}),f()};return e.jsxs(e.Fragment,{children:[_.map((y,C)=>{var S;return e.jsx(js,{command:y.command,description:y.description,onClick:()=>I(y.preset?`${y.command} `:y.command,y.autoSubmit),onEdit:y.preset?()=>B(y.preset):void 0,onPublish:y.preset?()=>j(y.preset):void 0,showMenu:!!y.preset,highlighted:a===C},((S=y.preset)==null?void 0:S.id)??y.command)}),e.jsxs("div",{onClick:c,className:"flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer hover:bg-zinc-700/50 light:hover:bg-slate-100",children:[e.jsx(et,{size:12,weight:"bold",className:"text-white light:text-slate-900"}),e.jsx("span",{className:"text-xs text-white light:text-slate-900",children:i("chat_window.add_new")})]}),e.jsx(ys,{isOpen:s,onClose:d,onSave:Z}),P&&e.jsx(Ss,{isOpen:g,onClose:()=>{m(),z(null)},onSave:U,onDelete:H,preset:P}),e.jsx(Sr,{show:v,onClose:b,entityType:"slash-command",entity:D})]})}const je="tools-menu-keyboard";function As(n,t){const r=[{key:"slash-commands",label:n("chat_window.slash_commands"),component:Es}];return(!(t!=null&&t.hasOwnProperty("role"))||t.role==="admin")&&r.push({key:"agent-skills",label:n("chat_window.agent_skills"),component:vs}),r}function Ns({workspace:n,showing:t,setShowing:r,sendCommand:a,promptRef:o,centered:i=!1,highlightedIndexRef:s}){const{t:c}=K(),{user:d}=fe(),g=u.useMemo(()=>As(c,d),[c,d]),[w,m]=u.useState(g[0].key),[v,f]=u.useState(-1),[b,L]=u.useState(360),M=u.useRef(0),P=u.useRef(null);u.useEffect(()=>{t&&m(g[0].key)},[t]),u.useEffect(()=>{f(-1)},[w,t]),u.useLayoutEffect(()=>{if(!t)return;const k=()=>{const T=P.current;if(!T)return;const _=T.getBoundingClientRect(),I=i?window.innerHeight-_.top-16:_.bottom-16;L(Math.max(0,Math.min(360,I)))};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[t,i]),u.useEffect(()=>{s&&(s.current=v)},[v]);const z=u.useCallback(k=>{M.current=k},[]);if(u.useEffect(()=>{if(!t)return;function k(T){const{key:_}=T.detail;if(_==="ArrowLeft"||_==="ArrowRight"){const I=g.findIndex(B=>B.key===w),Z=_==="ArrowLeft"?(I-1+g.length)%g.length:(I+1)%g.length;m(g[Z].key);return}if(_==="ArrowUp"||_==="ArrowDown"){const I=M.current;if(I===0)return;f(Z=>_==="ArrowDown"?Z<I-1?Z+1:0:Z>0?Z-1:I-1);return}}return window.addEventListener(je,k),()=>window.removeEventListener(je,k)},[t,w]),!t)return null;const{component:D}=g.find(k=>k.key===w);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onMouseDown:k=>k.preventDefault(),onClick:()=>r(!1)}),e.jsxs("div",{ref:P,onMouseDown:k=>{k.currentTarget.contains(k.target)&&k.preventDefault()},style:{maxHeight:b},className:`absolute left-2 right-2 md:left-14 md:right-auto md:w-[400px] z-50 bg-zinc-800 light:bg-white border border-zinc-700 light:border-slate-300 rounded-lg p-3 flex flex-col gap-2.5 shadow-lg overflow-hidden ${i?"top-full mt-2":"bottom-full mb-2"}`,children:[e.jsx("div",{className:"flex shrink-0 gap-2.5 items-center",children:g.map(k=>e.jsx(ks,{active:w===k.key,onClick:()=>m(k.key),children:k.label},k.key))}),e.jsx("div",{className:"flex flex-col gap-1 overflow-y-auto no-scroll min-h-0",children:e.jsx(D,{sendCommand:a,setShowing:r,promptRef:o,highlightedIndex:v,registerItemCount:z,workspace:n})})]})]})}function ks({active:n,onClick:t,children:r}){return e.jsx("button",{type:"button",onClick:t,className:`border-none cursor-pointer hover:bg-zinc-700/50 light:hover:bg-slate-100 px-1.5 py-0.5 rounded text-[10px] font-medium text-center whitespace-nowrap ${n?"bg-zinc-700 text-white light:bg-slate-200 light:text-slate-800":"text-zinc-400 light:text-slate-800"}`,children:r})}const Cs="primary-prompt-input",Le="set_prompt_input",Ms=100;function mi({workspace:n={},submit:t,isStreaming:r,sendCommand:a,attachments:o=[],centered:i=!1,workspaceSlug:s=null,threadSlug:c=null}){const{t:d}=K(),{showAgentCommand:g=!0}=n??{},{isDisabled:w}=Ps(),{enabled:m}=He("agentMode"),v=vn(),[f,b]=u.useState(""),[L,M]=u.useState(!1),P=u.useRef(!1),z=u.useRef(-1),D=u.useRef(null),k=u.useRef(null),[T,_]=u.useState(!1),I=u.useRef([]),Z=u.useRef([]),{textSizeClass:B}=ss(),[U]=rr();is({promptInput:f,setPromptInput:b}),u.useEffect(()=>{var l;U.get("action")==="set-agent-chat"&&(a({text:"@agent "}),(l=k.current)==null||l.focus())},[k.current]);function H(l){const{messageContent:x,writeMode:A="replace"}=(l==null?void 0:l.detail)??{};b(A==="append"?V=>V+x:A==="prepend"?V=>x+" "+V:x??"")}u.useEffect(()=>(window&&window.addEventListener(Le,H),()=>window==null?void 0:window.removeEventListener(Le,H)),[]),u.useEffect(()=>{!r&&k.current&&k.current.focus(),S()},[r]);function j(l=0){I.current.length>=Ms&&I.current.shift(),I.current.push({value:f,cursorPositionStart:k.current.selectionStart+l,cursorPositionEnd:k.current.selectionEnd+l})}const y=an(j,250);function C(l){l.target===l.currentTarget&&(_(!1),M(!1),t(l))}function S(){k.current&&(k.current.style.height="auto")}function E(l){var x;if(L){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(l.key)){l.preventDefault(),window.dispatchEvent(new CustomEvent(je,{detail:{key:l.key}}));return}if(l.key==="Enter"&&z.current>=0){l.preventDefault(),window.dispatchEvent(new CustomEvent(je,{detail:{key:"Enter"}}));return}if(l.key==="Escape"){l.preventDefault(),M(!1),(x=k.current)==null||x.focus();return}}if(l.key==="/"&&!l.ctrlKey&&!l.metaKey&&f.trim()===""){M(A=>(P.current=!A,!A));return}if(l.keyCode===13&&!l.shiftKey)return l.preventDefault(),r||w?void 0:(M(!1),t(l));if((l.ctrlKey||l.metaKey)&&l.key==="z"&&l.shiftKey){if(l.preventDefault(),Z.current.length===0)return;const A=Z.current.pop();if(!A)return;I.current.push({value:f,cursorPositionStart:k.current.selectionStart,cursorPositionEnd:k.current.selectionEnd}),b(A.value),setTimeout(()=>{k.current.setSelectionRange(A.cursorPositionStart,A.cursorPositionEnd)},0)}if((l.ctrlKey||l.metaKey)&&l.key==="z"&&!l.shiftKey){if(I.current.length===0)return;const A=I.current.pop();if(!A)return;Z.current.push({value:f,cursorPositionStart:k.current.selectionStart,cursorPositionEnd:k.current.selectionEnd}),b(A.value),setTimeout(()=>{k.current.setSelectionRange(A.cursorPositionStart,A.cursorPositionEnd)},0)}}function N(l){const x=l.target;x.style.height="auto",x.style.height=`${x.scrollHeight}px`}function O(l){if(l.preventDefault(),l.clipboardData.items.length===0)return!1;for(const A of l.clipboardData.items){if(A.type.startsWith("image/")){const V=A.getAsFile();window.dispatchEvent(new CustomEvent(Ie,{detail:{files:[V]}}));continue}if(A.kind==="file"){const V=A.getAsFile();window.dispatchEvent(new CustomEvent(Ie,{detail:{files:[V]}}));continue}}const x=l.clipboardData.getData("text/plain");if(x){const A=k.current,V=A.selectionStart,R=A.selectionEnd,F=f.substring(0,V)+x+f.substring(R);b(F),setTimeout(()=>{A.selectionStart=A.selectionEnd=V+x.length,N({target:A})},0)}}function p(l){y(-1),N(l);const x=l.target.value;b(x),P.current&&L&&x!=="/"&&(M(!1),P.current=!1)}return e.jsx("div",{id:"prompt-input-wrapper",className:i?"w-full relative flex justify-center items-center":"w-full fixed md:absolute bottom-0 left-0 z-10 flex justify-center items-center pwa:pb-5",children:e.jsx("form",{onSubmit:C,className:i?"flex flex-col gap-y-1 rounded-t-lg w-full items-center":"flex flex-col gap-y-1 rounded-t-lg md:w-full w-full mx-auto max-w-[750px] items-center",children:e.jsx("div",{className:`flex items-center rounded-lg md:w-full ${i?"mb-0":"mb-4"}`,children:e.jsxs("div",{className:"relative w-[95vw] md:w-[750px]",children:[e.jsx(Ns,{workspace:n,showing:L,setShowing:M,sendCommand:a,promptRef:k,centered:i,highlightedIndexRef:z}),e.jsxs("div",{className:"bg-zinc-800 light:bg-white light:border light:border-slate-300 rounded-[20px] pwa:rounded-3xl flex flex-col px-5 overflow-hidden",children:[e.jsx(es,{attachments:o}),e.jsx("div",{className:"flex items-center",children:e.jsx("textarea",{id:Cs,ref:k,onChange:p,onKeyDown:E,onPaste:l=>{j(),O(l)},required:!0,onFocus:()=>_(!0),onBlur:l=>{_(!1),N(l)},value:f,spellCheck:tn.get("enableSpellCheck"),className:`border-none cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] pt-[20px] w-full leading-5 text-white light:text-slate-600 bg-transparent placeholder:text-white/60 light:placeholder:text-slate-400 resize-none active:outline-none focus:outline-none flex-grow pwa:!text-[16px] ${B}`,placeholder:d("chat_window.send_message")})}),e.jsxs("div",{className:"flex justify-between items-center pt-3.5 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-x-0.25",children:[e.jsxs("div",{className:"flex items-center gap-x-1",children:[e.jsx(as,{workspaceSlug:s,workspaceThreadSlug:c}),e.jsx(Ts,{sendCommand:a,promptInput:f,textareaRef:k,visible:m&&!v&&g})]}),e.jsx(_s,{showTools:L,setShowTools:M,textareaRef:k,autoOpenedToolsRef:P,visible:m})]}),e.jsxs("div",{className:"flex gap-x-2 items-center",children:[e.jsx(Qa,{sendCommand:a}),r?e.jsx(La,{}):e.jsx(Ls,{formRef:D,promptInput:f,isDisabled:w})]})]})]})]})})})})}function Ts({sendCommand:n,promptInput:t,textareaRef:r,visible:a=!0}){const{t:o}=K();if(!a)return null;function i(){var s,c;try{if((s=t==null?void 0:t.trim())!=null&&s.startsWith("@agent"))return;n({text:"@agent",writeMode:"prepend"})}finally{(c=r==null?void 0:r.current)==null||c.focus()}}return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:i,"data-tooltip-id":"agent-session","data-tooltip-content":o("chat_window.start_agent_session"),"aria-label":o("chat_window.start_agent_session"),className:"group border-none relative flex justify-center items-center cursor-pointer w-6 h-6 rounded-full hover:bg-zinc-700 light:hover:bg-slate-200",children:e.jsx(on,{size:18,className:"pointer-events-none text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-600 shrink-0"})}),e.jsx(G,{id:"agent-session",place:"bottom",delayShow:300,className:"tooltip !text-xs z-99"})]})}function _s({showTools:n,setShowTools:t,textareaRef:r,autoOpenedToolsRef:a,visible:o=!0}){const{t:i}=K();return o?e.jsx("button",{id:"tools-btn",type:"button",onClick:()=>{var s;a.current=!1,t(!n),(s=r.current)==null||s.focus()},className:`group border-none cursor-pointer flex items-center justify-center h-6 px-2 rounded-full ${n?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:e.jsx("span",{className:`text-sm font-medium ${n?"text-white light:text-slate-800":"text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-800"}`,children:i("chat_window.tools")})}):null}function Ls({formRef:n,promptInput:t,isDisabled:r}){const{t:a}=K();return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:n,type:"submit",disabled:r||!t.trim().length,className:`border-none flex justify-center items-center rounded-full w-8 h-8 transition-all ${t.trim().length&&!r?"cursor-pointer bg-white hover:bg-zinc-200 light:bg-slate-800 light:hover:bg-slate-600":"cursor-not-allowed bg-zinc-600 light:bg-slate-400"}`,"data-tooltip-id":"send-prompt","data-tooltip-content":a(r?"chat_window.attachments_processing":"chat_window.send"),"aria-label":a("chat_window.send"),children:[e.jsx(sn,{className:"w-[18px] h-[18px] pointer-events-none text-zinc-800 light:text-white",weight:"bold"}),e.jsx("span",{className:"sr-only",children:a("chat_window.send")})]}),e.jsx(G,{id:"send-prompt",place:"bottom",delayShow:300,className:"tooltip !text-xs z-99"})]})}function Ps(){const[n,t]=u.useState(!1);return u.useEffect(()=>{if(!window)return;const r=()=>t(!0),a=()=>t(!1);return window.addEventListener(Je,r),window.addEventListener(de,a),()=>{window.removeEventListener(Je,r),window.removeEventListener(de,a)}},[]),{isDisabled:n}}function pi({hasAvailableWorkspace:n,onCreateAgent:t,onEditWorkspace:r,onUploadDocument:a}){const{t:o}=K(),{user:i}=fe();return e.jsx("div",{className:"flex flex-wrap justify-center gap-2 mt-6",children:e.jsx(Rs,{label:o("main-page.quickActions.editWorkspace"),onClick:r,show:n&&(!i||["admin","manager"].includes(i==null?void 0:i.role))})})}function Rs({label:n,onClick:t,show:r=!0}){return r?e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 rounded-full bg-theme-bg-chat-input text-white/80 text-sm font-normal leading-5 hover:bg-zinc-700 light:hover:bg-black/20 transition-colors light:text-theme-text-primary",children:n}):null}function fi({suggestedMessages:n=[],sendCommand:t}){return n!=null&&n.length?e.jsx("div",{className:"flex flex-col w-full max-w-[650px] mt-6 px-4",children:n.map((r,a)=>{var i,s,c;const o=(i=r.heading)!=null&&i.trim()?`${r.heading.trim()} ${((s=r.message)==null?void 0:s.trim())||""}`:((c=r.message)==null?void 0:c.trim())||"";return o?e.jsxs("div",{children:[a>0&&e.jsx("div",{className:"border-t border-zinc-800 light:border-theme-chat-input-border"}),e.jsx("button",{type:"button",onClick:()=>t({text:o,autoSubmit:!0}),className:"w-full text-left py-3 px-3 text-white/80 text-sm font-normal leading-5 hover:text-white transition-colors light:text-theme-text-primary light:hover:text-theme-text-primary/80 hover:bg-zinc-800 light:hover:bg-black/20 rounded-lg",children:o})]},a):null})}):null}function zs(n){return[{key:"small",label:n("chat_window.small")},{key:"normal",label:n("chat_window.normal")},{key:"large",label:n("chat_window.large")}]}function Vs(){const{t:n}=K(),[t,r]=u.useState(!1),[a,o]=u.useState(window.localStorage.getItem("anythingllm_text_size")||"normal");function i(s){o(s),window.localStorage.setItem("anythingllm_text_size",s),window.dispatchEvent(new CustomEvent("textSizeChange",{detail:s}))}return e.jsxs("div",{className:"relative",onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[e.jsxs("div",{className:`flex items-center justify-between px-2 py-1 rounded cursor-pointer ${t?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:[e.jsx("span",{className:"text-sm font-normal text-zinc-50 light:text-slate-800",children:n("chat_window.text_size_label")}),e.jsx(ar,{size:14,weight:"bold",className:"text-zinc-50 light:text-slate-800"})]}),t&&e.jsx(Os,{selectedSize:a,onSizeChange:i})]})}function Os({selectedSize:n,onSizeChange:t}){const{t:r}=K(),a=zs(r);return e.jsx("div",{className:"absolute right-full top-0 -mr-2 pr-2 pt-0",children:e.jsx("div",{className:"bg-zinc-800 light:bg-slate-50 border border-zinc-700 light:border-slate-300 rounded-lg p-3.5 w-[98px] flex flex-col gap-1.5 shadow-lg",children:a.map(({key:o,label:i})=>e.jsx("div",{onClick:()=>t(o),className:`px-2 py-1 rounded cursor-pointer text-sm font-normal text-white light:text-slate-800 ${n===o?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700/50 light:hover:bg-slate-100"}`,children:i},o))})})}const at=u.createContext();function gi({children:n}){const[t,r]=u.useState(null),[a,o]=u.useState(null);function i(d,g=null){r(d),o(g)}function s(){r(null),o(null)}function c(d,g=null){t===d?s():i(d,g)}return e.jsx(at.Provider,{value:{activeSidebar:t,sidebarData:a,openSidebar:i,closeSidebar:s,toggleSidebar:c},children:n})}function Is(){const{activeSidebar:n,sidebarData:t,openSidebar:r,closeSidebar:a}=u.useContext(at);return{sidebarOpen:n==="sources",sources:n==="sources"?t:[],openSidebar:o=>r("sources",o),closeSidebar:a}}function wn(){const{activeSidebar:n,toggleSidebar:t,closeSidebar:r}=u.useContext(at);return{sidebarOpen:n==="memories",toggleSidebar:()=>t("memories"),closeSidebar:r}}function Zs({isOpen:n,children:t}){return e.jsx("div",{className:"h-full overflow-hidden transition-all duration-500 flex-shrink-0",style:{width:n?"366px":"0px"},children:t})}function Fs({onClose:n}){const{t}=K(),{user:r}=fe(),{toggleSidebar:a}=wn(),{closeSidebar:o}=Is(),[i,s]=u.useState(null),c=He("memories");!r||(r==null||r.role),u.useEffect(()=>{ne.keys().then(g=>{s(!!(g!=null&&g.MemoryEnabled))})},[]);function d(){o(),a(),n()}return i===null||!i||!c.enabled?null:e.jsx("div",{onClick:d,className:"flex items-center px-2 py-1 rounded cursor-pointer hover:bg-zinc-700 light:hover:bg-slate-200",children:e.jsx("span",{className:"text-sm font-normal text-white light:text-slate-800",children:t("chat_window.memories.title")})})}function xi(){const n=sr(),[t,r]=u.useState(!1),a=u.useRef(null),o=u.useRef(null);u.useEffect(()=>{if(!t)return;function s(c){a.current&&!a.current.contains(c.target)&&o.current&&!o.current.contains(c.target)&&r(!1)}return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[t]);const i=n!==null;return e.jsxs("div",{className:`absolute top-3 md:top-5 z-30 ${i?"right-[55px] md:right-[67px]":"right-4 md:right-6"}`,children:[e.jsx("button",{ref:o,type:"button",onClick:()=>r(!t),className:`group border-none cursor-pointer flex items-center justify-center w-[35px] h-[35px] rounded-full transition-all ${t?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:e.jsx(wr,{size:18,className:t?"text-white light:text-slate-800":"text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-800"})}),t&&e.jsxs("div",{ref:a,className:"absolute right-0 top-[42px] bg-zinc-800 light:bg-slate-50 border border-zinc-700 light:border-slate-300 rounded-lg p-3.5 w-[226px] flex flex-col gap-1.5 shadow-lg",children:[e.jsx(Vs,{}),e.jsx(Fs,{onClose:()=>r(!1)})]})]})}async function Ds(n,t,r){if((n.chatProvider??(t==null?void 0:t.LLMProvider))!=="anythingllm-router")return n.chatModel??(t==null?void 0:t.LLMModel)??"";const o=n.router_id||(t==null?void 0:t.ModelRouterId);if(!o)return r("model-router.metrics.model-router-default");const{router:i}=await Xt.get(o);return i!=null&&i.name?i.name:r("model-router.metrics.model-router-default")}async function Qt(n,t,r){if(!n)return;const[a,o]=await Promise.all([Y.bySlug(n),ne.keys()]);t(await Ds(a,o,r))}function bi({workspaceSlug:n=null}){var z;const{t}=K(),{slug:r}=De(),a=r??n,{user:o}=fe(),[i,s]=u.useState(!1),[c,d]=u.useState(""),{isOpen:g,openModal:w,closeModal:m}=Ve(),[v,f]=u.useState({settings:{},provider:null}),[b,L]=u.useState(0),[M,P]=u.useState(()=>window.localStorage.getItem("anythingllm_sidebar_toggle")!=="closed");return u.useEffect(()=>{const D=k=>P(k.detail.open);return window.addEventListener(kt,D),()=>window.removeEventListener(kt,D)},[]),u.useEffect(()=>{Qt(a,d,t)},[a]),u.useEffect(()=>{function D(){s(!1),Qt(a,d,t)}return window.addEventListener(Ye,D),()=>window.removeEventListener(Ye,D)},[a]),u.useEffect(()=>{function D(k){const{provider:T,settings:_}=k.detail;f({settings:_,provider:T}),setTimeout(()=>w(),300)}return window.addEventListener(Ge,D),()=>window.removeEventListener(Ge,D)},[]),o&&o.role!=="admin"||!a||ir?null:e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>s(!1)}),e.jsxs("div",{className:`hidden md:block absolute top-2 z-30 transition-all duration-500 ${M?"left-3":"left-11"}`,children:[e.jsx("button",{type:"button",onClick:()=>s(!i),className:`group border-none cursor-pointer px-2.5 py-1 flex items-center rounded-full transition-all ${i?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:e.jsx("span",{className:`text-xs ${i?"text-white light:text-slate-800":"text-zinc-500 light:text-slate-500 group-hover:text-white light:group-hover:text-slate-800"}`,children:c||t("chat_window.select_model")})}),i&&e.jsx("div",{className:"absolute left-0 top-full mt-1 bg-zinc-800 light:bg-white border border-zinc-700 light:border-slate-300 rounded-xl shadow-lg w-[620px] overflow-hidden",children:e.jsx(_a,{workspaceSlug:a,initialProvider:(z=v.provider)==null?void 0:z.value},b)})]}),e.jsx(Ma,{isOpen:g,closeModal:m,postSubmit:()=>{m(),L(D=>D+1)},settings:v.settings,llmProvider:v.provider})]})}function vi(){const{t:n}=K();return e.jsxs(e.Fragment,{children:[e.jsx(G,{id:"message-to-speech",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"regenerate-assistant-text",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"copy-assistant-text",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"feedback-button",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"action-menu",place:"top",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"edit-input-text",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"metrics-visibility",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"routing-details",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"expand-cot",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"cot-thinking",place:"bottom",delayShow:500,className:"tooltip !text-xs"}),e.jsx(G,{id:"query-refusal-info",place:"top",delayShow:500,className:"tooltip !text-xs max-w-[350px]"}),e.jsx(G,{id:"context-window-limit-exceeded",place:"top",delayShow:500,className:"tooltip !text-xs max-w-[350px]"}),e.jsx(G,{id:"attachment-status-tooltip",place:"top",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"attach-item-btn",place:"top",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"agent-skill-disabled-tooltip",place:"top",delayShow:300,className:"tooltip !text-xs z-99",content:n("chat_window.agent_skills_disabled_in_session")}),e.jsx(Hs,{})]})}function Hs(){return Fe.createPortal(e.jsx(e.Fragment,{children:e.jsx(G,{id:"similarity-score",place:"top",delayShow:100,className:"tooltip !text-xs z-[100]"})}),document.body)}const be={forWorkspace:async function(n){return await fetch(`${ge}/workspaces/${n}/memories`,{method:"GET",headers:xe()}).then(t=>t.json()).then(t=>(t==null?void 0:t.memories)||{global:[],workspace:[]}).catch(()=>({global:[],workspace:[]}))},create:async function(n,{content:t,scope:r="workspace"}){return await fetch(`${ge}/workspaces/${n}/memories`,{method:"POST",headers:xe(),body:JSON.stringify({content:t,scope:r})}).then(a=>a.json()).catch(a=>({memory:null,error:a.message}))},update:async function(n,{content:t}){return await fetch(`${ge}/memories/${n}`,{method:"PUT",headers:xe(),body:JSON.stringify({content:t})}).then(r=>r.json()).catch(r=>({memory:null,error:r.message}))},delete:async function(n){return await fetch(`${ge}/memories/${n}`,{method:"DELETE",headers:xe()}).then(t=>t.json()).catch(t=>({success:!1,error:t.message}))},promoteToGlobal:async function(n){return await fetch(`${ge}/memories/${n}/promote`,{method:"POST",headers:xe()}).then(t=>t.json()).catch(t=>({memory:null,error:t.message}))},demoteToWorkspace:async function(n,t){return await fetch(`${ge}/memories/${n}/demote/${t}`,{method:"POST",headers:xe()}).then(r=>r.json()).catch(r=>({memory:null,error:r.message}))}},ve={workspace:20,global:5},yn=u.createContext(null);function ce(){const n=u.useContext(yn);if(!n)throw new Error("useMemoriesContext must be used within MemoriesProvider");return n}function $s({workspace:n,children:t}){const{sidebarOpen:r,closeSidebar:a}=wn(),{user:o}=fe(),i=!o||(o==null?void 0:o.role)==="admin",[s,c]=u.useState({global:[],workspace:[]}),[d,g]=u.useState("workspace"),[w,m]=u.useState({open:!1,mode:"create"}),[v,f]=u.useState(null),[b,L]=u.useState(!1),[M,P]=u.useState(!0),[z,D]=u.useState(!0);u.useEffect(()=>{r&&ne.keys().then(S=>{L(!!(S!=null&&S.MemoryEnabled)),P((S==null?void 0:S.MemoryAutoExtraction)!==!1),D(!1)})},[r]);async function k(){if(!(n!=null&&n.slug))return;const S=await be.forWorkspace(n.slug);c(S)}u.useEffect(()=>{r&&b&&k()},[r,n==null?void 0:n.slug,b]);async function T(S){const{memory:E}=await be.create(n.slug,{content:S,scope:d});E&&k()}async function _(S){await be.delete(S),k()}async function I(S,E){const{memory:N}=await be.update(S,{content:E});N&&k()}async function Z(S){const{memory:E}=await be.promoteToGlobal(S);E&&k()}async function B(S){if(!(n!=null&&n.slug))return;const{memory:E}=await be.demoteToWorkspace(S,n.slug);E&&k()}function U(){f(null),m({open:!0,mode:"create"})}function H(S){f(S),m({open:!0,mode:"edit"})}function j(){m({open:!1,mode:"create"}),f(null)}const y=d==="workspace"?s.workspace:s.global,C={workspace:n,sidebarOpen:r,closeSidebar:a,canToggle:i,memories:s,activeTab:d,setActiveTab:g,activeMemories:y,enabled:b,setEnabled:L,autoExtraction:M,setAutoExtraction:P,loadingEnabled:z,modalState:w,editingMemory:v,openCreateModal:U,openEditModal:H,closeModal:j,handleCreate:T,handleDelete:_,handleUpdate:I,handlePromote:Z,handleDemote:B};return e.jsx(yn.Provider,{value:C,children:t})}function Bs(){const{canToggle:n,enabled:t,setEnabled:r,autoExtraction:a,setAutoExtraction:o,loadingEnabled:i}=ce(),{t:s}=K();async function c(g){const w=g?"true":"false",{success:m}=await we.updateSystemPreferences({memory_enabled:w});m&&r(g)}async function d(g){const w=g?"true":"false",{success:m}=await we.updateSystemPreferences({memory_auto_extraction:w});m&&o(g)}return!n||i?null:e.jsxs("div",{className:"shrink-0 bg-zinc-900 light:bg-white light:border light:border-slate-300 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-zinc-50 light:text-slate-900",children:s("chat_window.memories.toggle.label")}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500",children:s("chat_window.memories.toggle.description")})]}),e.jsx(Qe,{size:"md",enabled:t,onChange:c})]}),t&&e.jsxs("div",{className:"flex items-start gap-3 pt-2 border-t border-zinc-800 light:border-slate-200",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-zinc-50 light:text-slate-900",children:s("chat_window.memories.auto_extraction.label")}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500",children:s("chat_window.memories.auto_extraction.description")})]}),e.jsx(Qe,{size:"md",enabled:a,onChange:d})]})]})}function Jt(){const{workspace:n,activeTab:t,setActiveTab:r,memories:a,openCreateModal:o}=ce(),{t:i}=K(),s=(n==null?void 0:n.name)||i("chat_window.memories.tab_workspace"),c=a.workspace.length,d=a.global.length,g=t==="workspace"?c>=ve.workspace:d>=ve.global;return e.jsxs("div",{className:"flex items-center justify-between shrink-0 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>r("workspace"),"data-tooltip-id":"memories-workspace-pill","data-tooltip-content":s,className:`flex items-center gap-0.5 h-6 px-3 rounded-full border-none cursor-pointer text-xs font-medium uppercase tracking-[1.2px] whitespace-nowrap transition-colors min-w-0 shrink ${t==="workspace"?"bg-zinc-800 light:bg-slate-300":"bg-transparent hover:bg-zinc-800/50 light:hover:bg-slate-200"}`,children:[e.jsx("span",{className:"text-zinc-200 light:text-slate-800 truncate max-w-[140px]",children:s}),e.jsxs("span",{className:"text-zinc-400 light:text-slate-600 font-normal",children:["(",c,"/",ve.workspace,")"]})]}),e.jsxs("button",{type:"button",onClick:()=>r("global"),className:`flex items-center gap-0.5 h-6 px-3 rounded-full border-none cursor-pointer text-xs font-medium uppercase tracking-[1.2px] whitespace-nowrap transition-colors shrink-0 ${t==="global"?"bg-zinc-800 light:bg-slate-300":"bg-transparent hover:bg-zinc-800/50 light:hover:bg-slate-200"}`,children:[e.jsx("span",{className:"text-zinc-200 light:text-slate-800",children:i("chat_window.memories.tab_global")}),e.jsxs("span",{className:"text-zinc-400 light:text-slate-600 font-normal",children:["(",d,"/",ve.global,")"]})]})]}),e.jsx("button",{type:"button",onClick:o,disabled:g,className:"-mr-1 flex items-center justify-center size-6 rounded-lg border-none bg-transparent cursor-pointer text-zinc-50 light:text-slate-900 hover:bg-zinc-800 light:hover:bg-slate-200 transition-colors disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:e.jsx(et,{size:16,weight:"bold"})}),e.jsx(G,{id:"memories-workspace-pill",place:"bottom",delayShow:800,className:"tooltip !text-xs z-99"})]})}function Us({menuRef:n,buttonRef:t,isWorkspace:r,canMove:a,onEdit:o,onMove:i,onDelete:s}){const{t:c}=K(),[d,g]=u.useState({top:0,left:0});return u.useEffect(()=>{if(!t.current)return;const w=t.current.getBoundingClientRect();g({top:w.bottom+4,left:w.right-200})},[]),Fe.createPortal(e.jsxs("div",{ref:n,className:"fixed z-[9999] bg-zinc-800 light:bg-slate-50 border border-zinc-700 light:border-slate-300 rounded-lg py-3 px-2 flex flex-col shadow-lg w-[175px]",style:{top:d.top,left:d.left},children:[e.jsx(qe,{label:c("chat_window.memories.menu.edit"),onClick:o}),a&&e.jsx(qe,{label:c(r?"chat_window.memories.menu.move_to_global":"chat_window.memories.menu.move_to_workspace"),onClick:i}),e.jsx(qe,{label:c("chat_window.memories.menu.delete"),onClick:s})]}),document.body)}function qe({label:n,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:"w-full text-left text-sm font-medium text-zinc-50 light:text-slate-800 border-none bg-transparent cursor-pointer hover:bg-zinc-700 light:hover:bg-slate-200 rounded px-2.5 py-1 transition-colors",children:n})}function Ws({memory:n}){const{activeTab:t,memories:r,handleDelete:a,openEditModal:o,handlePromote:i,handleDemote:s}=ce(),[c,d]=u.useState(!1),g=u.useRef(null),w=u.useRef(null);u.useEffect(()=>{if(!c)return;function f(b){g.current&&!g.current.contains(b.target)&&w.current&&!w.current.contains(b.target)&&d(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[c]);const m=t==="workspace",v=m?r.global.length<ve.global:r.workspace.length<ve.workspace;return e.jsxs("div",{className:"relative shrink-0 bg-zinc-900 light:bg-white light:border light:border-slate-300 rounded-lg p-3 flex gap-0.5 items-start",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm leading-5 text-zinc-50 light:text-slate-900",children:n.content}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500 mt-1.5",children:new Date(n.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})]}),e.jsx("button",{ref:w,type:"button",onClick:()=>d(!c),className:"shrink-0 border-none bg-transparent cursor-pointer text-zinc-400 light:text-slate-400 hover:text-zinc-50 light:hover:text-slate-900 transition-colors p-0",children:e.jsx(or,{size:20,weight:"bold"})}),c&&e.jsx(Us,{menuRef:g,buttonRef:w,isWorkspace:m,canMove:v,onEdit:()=>{d(!1),o(n)},onMove:()=>{d(!1),m?i(n.id):s(n.id)},onDelete:()=>{d(!1),a(n.id)}})]})}function Ks({isOpen:n,onClose:t,onSubmit:r,initialContent:a="",mode:o="create"}){const{t:i}=K(),[s,c]=u.useState(a),d=o==="create",[g,w,m]=u.useMemo(()=>d?[i("chat_window.memories.modal.create_title"),i("chat_window.memories.modal.create"),i("chat_window.memories.modal.create_description")]:[i("chat_window.memories.modal.edit_title"),i("chat_window.memories.modal.save"),i("chat_window.memories.modal.edit_description")],[d,i]);u.useEffect(()=>{n&&c(a)},[n,a]);function v(){s.trim()&&(r(s.trim()),t())}return e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"bg-zinc-900 light:bg-white border border-zinc-800 light:border-slate-300 rounded-lg p-6 w-[400px] flex flex-col gap-5",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("p",{className:"font-semibold text-base leading-6 text-zinc-50 light:text-slate-800",children:g}),e.jsx("button",{onClick:t,type:"button",className:"text-zinc-400 light:text-slate-400 hover:text-zinc-50 light:hover:text-slate-900 transition-colors border-none bg-transparent cursor-pointer",children:e.jsx(oe,{size:16,weight:"bold"})})]}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500",children:m})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-zinc-200 light:text-slate-700",children:i("chat_window.memories.modal.label")}),e.jsx("textarea",{autoFocus:!0,onFocus:f=>{const b=f.currentTarget.value.length;f.currentTarget.setSelectionRange(b,b)},value:s,onChange:f=>c(f.target.value),placeholder:i("chat_window.memories.modal.placeholder"),rows:4,className:"w-full bg-zinc-800 light:bg-white text-zinc-50 light:border light:border-slate-300 light:text-slate-700 placeholder:text-zinc-500 light:placeholder:text-slate-400 text-sm rounded-lg p-3 resize-none outline-none focus:border-zinc-500 light:focus:border-slate-400"})]}),e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("button",{type:"button",onClick:t,className:"h-9 px-5 rounded-lg border border-zinc-500 light:border-slate-600 bg-transparent text-zinc-50 light:text-slate-900 text-sm font-medium cursor-pointer hover:bg-zinc-700 light:hover:bg-slate-100 transition-colors",children:i("chat_window.memories.modal.cancel")}),e.jsx("button",{type:"button",onClick:v,disabled:!s.trim(),className:"h-9 px-5 rounded-lg border-none bg-zinc-50 light:bg-slate-900 text-zinc-900 light:text-white text-sm font-medium cursor-pointer hover:bg-white light:hover:bg-slate-800 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:w})]})]})})}function wi({workspace:n}){return e.jsx($s,{workspace:n,children:e.jsx(qs,{})})}function qs(){const{sidebarOpen:n,canToggle:t,enabled:r}=ce(),a=He("memories");return!t&&!r||!a.enabled?null:e.jsxs(e.Fragment,{children:[e.jsx(Zs,{isOpen:n,children:e.jsxs(Gs,{children:[e.jsx(Js,{}),e.jsx(Bs,{}),e.jsx(Ys,{})]})}),e.jsx(Qs,{})]})}function Gs({children:n}){return e.jsx("div",{className:"w-[366px] flex-shrink-0 flex flex-col gap-5 mt-[72px] px-5 overflow-y-auto no-scroll",style:{maxHeight:"calc(100% - 88px)"},children:n})}function Ys(){const{enabled:n,activeMemories:t}=ce();return n?t.length===0?e.jsxs(e.Fragment,{children:[e.jsx(Jt,{}),e.jsx(Xs,{})]}):e.jsxs(e.Fragment,{children:[e.jsx(Jt,{}),e.jsx("div",{className:"flex flex-col gap-1.5 pb-4",children:t.map(r=>e.jsx(Ws,{memory:r},r.id))})]}):null}function Qs(){const{enabled:n,modalState:t,editingMemory:r,closeModal:a,handleCreate:o,handleUpdate:i}=ce();return n?e.jsx(Ks,{isOpen:t.open,mode:t.mode,initialContent:(r==null?void 0:r.content)||"",onClose:a,onSubmit:s=>{t.mode==="edit"&&r?i(r.id,s):o(s)}}):null}function Js(){const{t:n}=K(),{closeSidebar:t}=ce();return e.jsxs("div",{className:"flex items-start justify-between shrink-0",children:[e.jsx("p",{className:"font-medium text-base leading-6 text-zinc-50 light:text-slate-900",children:n("chat_window.memories.title")}),e.jsx("button",{onClick:t,type:"button",className:"text-zinc-50 light:text-slate-900 hover:text-white light:hover:text-slate-400 transition-colors border-none bg-transparent cursor-pointer",children:e.jsx(oe,{size:16,weight:"bold"})})]})}function Xs(){const{t:n}=K(),{openCreateModal:t}=ce();return e.jsxs("p",{className:"text-sm leading-5 text-zinc-400 light:text-slate-600 text-center",children:[n("chat_window.memories.empty")," ",e.jsx("button",{type:"button",onClick:t,className:"text-zinc-50 light:text-slate-900 underline border-none bg-transparent cursor-pointer p-0 text-sm leading-5 font-normal",children:n("chat_window.memories.empty_cta")})]})}export{fs as A,gi as C,oi as D,wi as M,Ie as P,pi as Q,fi as S,bi as W,gn as a,Le as b,xi as c,li as d,mi as e,vi as f,Cs as g,ss as h,Zs as i,ci as j,Bt as k,tt as l,Ut as m,di as n,ps as o,hi as s,Is as u,ui as w};
3
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function z(j,y){if(j){if(typeof j=="string")return D(j,y);var C=Object.prototype.toString.call(j).slice(8,-1);if(C==="Object"&&j.constructor&&(C=j.constructor.name),C==="Map"||C==="Set")return Array.from(j);if(C==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(C))return D(j,y)}}function D(j,y){(y==null||y>j.length)&&(y=j.length);for(var C=0,S=new Array(y);C<y;C++)S[C]=j[C];return S}function k(j,y){if(!(typeof Symbol>"u"||!(Symbol.iterator in Object(j)))){var C=[],S=!0,E=!1,N=void 0;try{for(var O=j[Symbol.iterator](),p;!(S=(p=O.next()).done)&&(C.push(p.value),!(y&&C.length===y));S=!0);}catch(l){E=!0,N=l}finally{try{!S&&O.return!=null&&O.return()}finally{if(E)throw N}}return C}}function T(j){if(Array.isArray(j))return j}var _=!!c.default,I=_&&!(0,s.default)(),Z,B=function(){var y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},C=y.transcribing,S=C===void 0?!0:C,E=y.clearTranscriptOnListen,N=E===void 0?!0:E,O=y.commands,p=O===void 0?[]:O,l=(0,t.useState)(U.getRecognitionManager()),x=M(l,1),A=x[0],V=(0,t.useState)(_),R=M(V,2),F=R[0],$=R[1],W=(0,t.useState)(I),q=M(W,2),re=q[0],Q=q[1],J=(0,t.useReducer)(o.transcriptReducer,{interimTranscript:A.interimTranscript,finalTranscript:""}),st=M(J,2),it=st[0],ot=it.interimTranscript,lt=it.finalTranscript,ct=st[1],Sn=(0,t.useState)(A.listening),ut=M(Sn,2),jn=ut[0],En=ut[1],An=(0,t.useState)(A.isMicrophoneAvailable),dt=M(An,2),Nn=dt[0],kn=dt[1],ht=(0,t.useRef)(p);ht.current=p;var mt=function(){ct((0,a.clearTranscript)())},Ae=(0,t.useCallback)(function(){A.resetTranscript(),mt()},[A]),Cn=function(X,ie,ue){var le=L(X)==="object"?X.toString():X,Ne=le.replace(/[&/\\#,+()!$~%.'":*?<>{}]/g,"").replace(/ +/g," ").trim(),Pe=(0,r.compareTwoStringsUsingDiceCoefficient)(Ne,ie);return Pe>=ue?{command:X,commandWithoutSpecials:Ne,howSimilar:Pe,isFuzzyMatch:!0}:null},Mn=function(X,ie){var ue=(0,r.commandToRegExp)(X),le=ue.exec(ie);return le?{command:X,parameters:le.slice(1)}:null},pt=(0,t.useCallback)(function(se,X){ht.current.forEach(function(ie){var ue=ie.command,le=ie.callback,Ne=ie.matchInterim,Pe=Ne===void 0?!1:Ne,xt=ie.isFuzzyMatch,bt=xt===void 0?!1:xt,vt=ie.fuzzyMatchingThreshold,_n=vt===void 0?.8:vt,wt=ie.bestMatchOnly,Ln=wt===void 0?!1:wt,Re=!X&&Pe?se.trim():X.trim(),Pn=Array.isArray(ue)?ue:[ue],ze=Pn.map(function(te){return bt?Cn(te,Re,_n):Mn(te,Re)}).filter(function(te){return te});if(bt&&Ln&&ze.length>=2){ze.sort(function(te,Ue){return Ue.howSimilar-te.howSimilar});var Be=ze[0],Rn=Be.command,zn=Be.commandWithoutSpecials,Vn=Be.howSimilar;le(zn,Re,Vn,{command:Rn,resetTranscript:Ae})}else ze.forEach(function(te){if(te.isFuzzyMatch){var Ue=te.command,On=te.commandWithoutSpecials,In=te.howSimilar;le(On,Re,In,{command:Ue,resetTranscript:Ae})}else{var Zn=te.command,Fn=te.parameters;le.apply(void 0,m(Fn).concat([{command:Zn,resetTranscript:Ae}]))}})})},[Ae]),ft=(0,t.useCallback)(function(se,X){S&&ct((0,a.appendTranscript)(se,X)),pt(se,X)},[pt,S]),gt=(0,t.useCallback)(function(){N&&mt()},[N]);(0,t.useEffect)(function(){var se=U.counter;U.counter+=1;var X={onListeningChange:En,onMicrophoneAvailabilityChange:kn,onTranscriptChange:ft,onClearTranscript:gt,onBrowserSupportsSpeechRecognitionChange:$,onBrowserSupportsContinuousListeningChange:Q};return A.subscribe(se,X),function(){A.unsubscribe(se)}},[S,N,A,ft,gt]);var Tn=(0,r.concatTranscripts)(lt,ot);return{transcript:Tn,interimTranscript:ot,finalTranscript:lt,listening:jn,isMicrophoneAvailable:Nn,resetTranscript:Ae,browserSupportsSpeechRecognition:F,browserSupportsContinuousListening:re}};n.useSpeechRecognition=B;var U={counter:0,applyPolyfill:function(y){Z?Z.setSpeechRecognition(y):Z=new i.default(y);var C=!!y&&(0,r.browserSupportsPolyfills)();_=C,I=C},removePolyfill:function(){Z?Z.setSpeechRecognition(c.default):Z=new i.default(c.default),_=!!c.default,I=_&&!(0,s.default)()},getRecognitionManager:function(){return Z||(Z=new i.default(c.default)),Z},getRecognition:function(){var y=U.getRecognitionManager();return y.getRecognition()},startListening:function(){var j=w(regeneratorRuntime.mark(function C(){var S,E,N,O,p=arguments;return regeneratorRuntime.wrap(function(x){for(;;)switch(x.prev=x.next){case 0:return S=p.length>0&&p[0]!==void 0?p[0]:{},E=S.continuous,N=S.language,O=U.getRecognitionManager(),x.next=4,O.startListening({continuous:E,language:N});case 4:case"end":return x.stop()}},C)}));function y(){return j.apply(this,arguments)}return y}(),stopListening:function(){var j=w(regeneratorRuntime.mark(function C(){var S;return regeneratorRuntime.wrap(function(N){for(;;)switch(N.prev=N.next){case 0:return S=U.getRecognitionManager(),N.next=3,S.stopListening();case 3:case"end":return N.stop()}},C)}));function y(){return j.apply(this,arguments)}return y}(),abortListening:function(){var j=w(regeneratorRuntime.mark(function C(){var S;return regeneratorRuntime.wrap(function(N){for(;;)switch(N.prev=N.next){case 0:return S=U.getRecognitionManager(),N.next=3,S.abortListening();case 3:case"end":return N.stop()}},C)}));function y(){return j.apply(this,arguments)}return y}(),browserSupportsSpeechRecognition:function(){return _},browserSupportsContinuousListening:function(){return I}},H=U;n.default=H})(mn);(function(n){function t(s){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?t=function(d){return typeof d}:t=function(d){return d&&typeof Symbol=="function"&&d.constructor===Symbol&&d!==Symbol.prototype?"symbol":typeof d},t(s)}Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"useSpeechRecognition",{enumerable:!0,get:function(){return r.useSpeechRecognition}}),n.default=void 0;var r=o(mn);function a(){if(typeof WeakMap!="function")return null;var s=new WeakMap;return a=function(){return s},s}function o(s){if(s&&s.__esModule)return s;if(s===null||t(s)!=="object"&&typeof s!="function")return{default:s};var c=a();if(c&&c.has(s))return c.get(s);var d={},g=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var w in s)if(Object.prototype.hasOwnProperty.call(s,w)){var m=g?Object.getOwnPropertyDescriptor(s,w):null;m&&(m.get||m.set)?Object.defineProperty(d,w,m):d[w]=s[w]}return d.default=s,c&&c.set(s,d),d}var i=r.default;n.default=i})(tt);const Bt=Kn(tt);let ke;const Ya=3200;function Qa({sendCommand:n}){const t=u.useRef(""),{transcript:r,listening:a,resetTranscript:o,browserSupportsSpeechRecognition:i,browserSupportsContinuousListening:s,isMicrophoneAvailable:c}=tt.useSpeechRecognition({clearTranscriptOnListen:!0}),{t:d}=K();function g(){var f;if(!c){alert("AnythingLLM does not have access to microphone. Please enable for this site to use this feature.");return}o(),t.current="",Bt.startListening({continuous:s,language:((f=window==null?void 0:window.navigator)==null?void 0:f.language)??"en-US"})}function w(){Bt.stopListening(),tn.get("autoSubmitSttInput")&&n({text:"",autoSubmit:!0,writeMode:"append"}),o(),t.current="",clearTimeout(ke)}const m=u.useCallback(f=>{f.ctrlKey&&f.keyCode===77&&(a?w():g())},[a,w,g]);function v(f){!(f!=null&&f.detail)&&ke&&(w(),clearTimeout(ke))}return u.useEffect(()=>(document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m)}),[m]),u.useEffect(()=>(window&&window.addEventListener(Le,v),()=>window==null?void 0:window.removeEventListener(Le,v)),[]),u.useEffect(()=>{if((r==null?void 0:r.length)>0&&a){const f=t.current,b=r.slice(f.length);b.length>0&&n({text:b,writeMode:"append"}),t.current=r,clearTimeout(ke),ke=setTimeout(()=>{w()},Ya)}},[r,a]),i?e.jsxs("div",{"data-tooltip-id":"tooltip-microphone-btn","data-tooltip-content":`${d("chat_window.microphone")} (CTRL + M)`,"aria-label":d("chat_window.microphone"),onClick:a?w:g,className:`group border-none relative flex justify-center items-center cursor-pointer w-8 h-8 rounded-full hover:bg-zinc-700 light:hover:bg-slate-200 ${a?"bg-zinc-700 light:bg-slate-200":""}`,children:[e.jsx(hn,{weight:"regular",size:18,className:`pointer-events-none text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-600 shrink-0 ${a?"animate-pulse-glow !text-white light:!text-slate-800":""}`}),e.jsx(G,{id:"tooltip-microphone-btn",place:"top",delayShow:300,className:"tooltip !text-xs z-99"})]}):null}const Ja="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABFCAYAAAD3upAqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAoZSURBVHgB3VxtbBTHGX4d3LrYwjGJaQJ3tg/zEZ/lCBOISVuFmMSoqpQUDv+J0oJNpUqRoIGmcgRWIoyIAJWqxWCkVpVqG6tRf9QxaSpVDSYYolaYtML9UZ8jNc3h4BAVUOBOserWiLzP7MwyPvZ8t7N7ZzuPNLe7t+vz3rPP+zEz71we5RB37twp4U0tt1VyG5KNtC0Q43ZTtn9w+0huh/Ly8m5SDpBHWQaTUc+bp7jVy+YVA9xOcXuLSYpRlpAVYqQydnHbTJYyBBKJBP1zOErRkREajo7Q2NiYaPF4guKJuP33xQuKKRhcQgt4Wx2uokAgQOGqKnpiXV3yvxridpQsknxVkq/EaITs5oZ9Qcbv3+yj0/1nKMpk6AS4BQgLM1GNkc2CJBAmEePWxa3bLxX5QowTIRcGL9KxjhM0ePEiZQuNkQhtkSRJxLh1MTn7ySM8EyN9SCdJ59nL6ug82cPqiFKuEGTlvLRzBzVuiai3Yty2M0EDZAhjYqRK9pGlkpwoJB3W1dXRkcMHdRNrM1WPETFMSog3Z7mF4EOOHu+gru6TNFvw0s6dtOtHO9QhHHTEre9xTQyTgigDUkoQUV7Y2kRXeDvbAPN6o6dbqSfGbYMbcu4jF2BSmkiS0vvmKXp205ZZSQpwRT40adohbpfkQ80IGStGktKF/WPHT1B7RwfNFbzaupe2N23DLnIdKGco3d9kRIxk+hL25xopCprfATmr05lVWlOSjrYP+3OVFOAY33dvn/gaiKZn5fdKiWkVI0MylBLq5Kjz+sFDNNcBh4ywzhhg1WxIdV06xSBPCSH6QC1fBry4Y6fonzHq+cH/ItV1KRXDf9TMm07kKc9uisza6GMCdEzfPtWnDjc4ZciOitGyWpG85YqUYGAJ5QLo2bcft31lp9M1jophYkBKGz7guc0R8hsYTtjY8DR9gzt/VVVhHmIIcM95gX0+zipFXwsPBL1ytGzg/Lv9KgHcz6pp08/dQ4z01hgxo6eebvBVLevqHhcdvY0NDVOISAcQdbq/n5/yCeUffLqfOuGMyQrhS/UxHSdTasMLesl+kQKFvMZJ1hs9J8VQgRtSAFyPv8MTRrKGz/MDyIplZgzXsVs/N0Ux2VALVPLTw4dE38UvqHR/zJf7c1ZNsmLq8eKXWpCGQyV+kgLg8/7IUWVjwzPkFUmqaVbvJxMjIlFv3ynyCpAC2WcLxcUL6JcnOoSJeUXn3SGTTWrHNiU5EncW8lzPZuQFMB8oJRfAQPoL25o8jRiC5PPvnmHfJXwfzCmmKwYj+vSOx9CI8AefkitYyjnuySGD3HdO96tDwYNODOZ+POcM6MH67VPSAf/vB01byQtOn7G/tzAnQYyaIQRzXsZsoRZTm8fUCjqpppGmuanJk2q0710LPpRi6q2b8zayr42zukbL3lbhBA8Y9uBhUl5UA1EM80QgWdEppIgRQ34XZkgtQCIelzdoPiHnVTXRYVsYtYqYVeJEdIRM8QRHopkGVIOesymiI/b3t4kRs4fok5jCj2TLD3i5Dy2ptU0phBcvKXYgGKTZAC+K0YipmEKMl25AdZX5DfmJgIdUIRG3LabE1bxSKuQ6b5kOft2LL8S4BTqpaJkAITzTa71Ct5h8yjEGefL/Fc5ZrBv5ZNrc55U9rWrKg9bxaF+2lYmopqAU46kayY1vCofDdq6BuZ72FLMPOilu/EY8bh5ZFy58wN6fQkxl5TIyRabk4KlgYGg6cpJJwfWZqsVL9r6otFTtxqYQs3LFSjIFTCRTIKQmk6OIHbz4vjEpwPCIeZK6cuUjaveWIgalovToozV8s/eTCaIubyiZnGSYkAK4eUA6iovvpxXLV6hDWzFi9j9UXk6LFn2dTKCeshukIseUFCSo2vCBKwQCZVRRUaYObWJieCkvLxPEmKgGTg9THG6RTI4pKcAFD2pBq6goV28NKWIG8BKSjAWDZWSCzu4eMoEiBxWYpqQAqAE0QWXlciosLGSLsb43pmzvkztwvkM4Ga56RLC3cOGD5BYY7DFNxkDOEQ/TLCg6MOnSPPzwYioo+BqnEbbjHcCLnvmew8vja1aLg2XLlos/cIvXDx3ydbYwE+D/dRoURxYUFLDpWuaz9jG7Cu0tvOjEiDmT9U9+UxzMm5cvJOYW8DUte1opV0A1BibfTCrOw+Eays+3kv/qu4oRPNjEyFKImDInACYFb+0WMKlcFRm17NlrZELwo8oiIAaZ3A2oErTkTqSYq2yMfFf7ALMQnu0KLCgFGbLJrAZIUSYErH/yW2q3S+0kE4OVHDchq9K76TGHsaXstYvILUAOykj89jlWffE2o9wJD1knBdZRbVlIjNXSrd6fQoyMTu3Yb4w8Z78Pf1NdXWNEDmps4AP8GjoA2agvHjYYnwYplZUrprynfCpJa1Fwqo/B+C8qHkoOHDzCqf4H9rnbtyfpww//RZ99doNM4LAYIiOopT0oyzcdZXQiZc1jq+knu8WwR4ySKsdTVVS18WbfcPQDDr9H7jl/+fK/6dNPr5IpikVF1TNijhvDEGXBgJo3FgARH18ZsysRBgff97TOKdmnKLT//LByuj9mUo7q51IRY5ex9vz2d/SnP9+b6l+9+gmNjn5EfgKK8rOCC6G4vHypY/BAgJFBBr5lafJ5x6FN6Wu2qw/QHbHC4sVLqLZ2rVESmAp+koL+Xk3NKkdSSksf1COvY61vyjFfmde0I6+BHWKbDGSOtbVrRK7jJ0FeAJUgiiJYON0TSHmttUUd7k9VOp9xZfi59/5Kv/r1b1JeOzExwU98lK5f+w/NBEDIQw8t5r7PEjubdcKre1tUloulyqtTXZd2kYWsywM5Jb19fyC06aAIwlz0xMR/KdvIlBBg6/eep+98WxRFxSjN+iU3q0+sdUoZkKNwjdWDlkjcIj8BAubPLxLRBrlVOkIAzdlmtPrEzXqlZpJV1G7IASYnJwU5t+K3aPzzcddEKSIKiwrpAR4OyZQMhRd/uF2l/f6uV1LQyYHPQSgfHx8nE4yPfy4Im/jfBN2evM37/7fP5ed/heblz6OCrxYIB2/q2BEwXt61Q/mUjEkBTNdEIr8PXbt+nQ4c/Bld5+1sQwWPxr3M0VQmcDGyFoxmRArgeRUtFAOzckoCZwqaPwFys4pWQYbyNrJW6NNsUA96ytu+/7xQi0Q7E7KbDODHSv1mkgu+cHzuvb+wgt7OKUEgBArRRuFiNFMr9XVI9eDJ7FPv/e3vl4R56b1zv+FAiBg2SV5iYwK/fw0kRJZ5Nan3YGLopZ/nKOaVJEQZmMlaHrDHOErR3W6KGkc66tfPpWTr92NCZJXI2iamAJIuj37MbZSTvxtM3A0R8vWwrzqtmOcqLJzPZJQLQjBTWDS1zzZA1uB1d95s/v0YJ8jw3kxWZWg9eccAWVM9XXlz7ReHUiHFb1SVyBbSLo3JLULtTbnN6W9UfQFOlEd2UKiS/gAAAABJRU5ErkJggg==";function Xa({show:n,onClose:t,onContinue:r,onEmbed:a,tokenCount:o,maxTokens:i,fileCount:s=1,isEmbedding:c=!1,embedProgress:d=0}){const{user:g}=fe(),w=!g||g.role!=="default";return n?c?e.jsx(ye,{isOpen:n,children:e.jsx("div",{className:"relative max-w-[600px] bg-theme-bg-primary rounded-lg shadow border border-theme-modal-border",children:e.jsxs("div",{className:"p-6 flex flex-col items-center justify-center",children:[e.jsxs("p",{className:"text-white text-lg font-semibold mb-4",children:["Embedding ",d+1," of ",s," ",Ce("file",s)]}),e.jsx(Te,{size:32,className:"animate-spin text-white"}),e.jsx("p",{className:"text-white/60 text-sm mt-2",children:"Please wait while we embed your files..."})]})})}):e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"relative max-w-[600px] bg-theme-bg-primary rounded-lg shadow border border-theme-modal-border",children:[e.jsx("div",{className:"relative p-6 border-b border-theme-modal-border",children:e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsx("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:"Context Window Warning"})})}),e.jsxs("div",{className:"py-7 px-9 space-y-4",children:[e.jsxs("p",{className:"text-theme-text-primary text-sm",children:["Your workspace is using ",jt(o)," of"," ",jt(i)," available tokens. We recommend keeping usage below ",(Y.maxContextWindowLimit*100).toFixed(0),"% to ensure the best chat experience. Adding ",s," more"," ",Ce("file",s)," would exceed this limit."," ",e.jsx(nn,{target:"_blank",to:rn.documentation.contextWindows(),className:"text-theme-text-secondary text-sm underline",children:"Learn more about context windows →"})]}),e.jsx("p",{className:"text-theme-text-primary text-sm",children:"Choose how you would like to proceed with these uploads."})]}),e.jsxs("div",{className:"flex w-full justify-between items-center p-6 space-x-2 border-t border-theme-modal-border rounded-b",children:[e.jsx("button",{onClick:t,type:"button",className:"border-none transition-all duration-300 bg-theme-modal-border text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Cancel"}),e.jsxs("div",{className:"flex w-full justify-end items-center space-x-2",children:[e.jsx("button",{onClick:r,type:"button",className:"border-none transition-all duration-300 bg-theme-modal-border text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Continue Anyway"}),w&&e.jsxs("button",{onClick:a,disabled:c||!w,type:"button",className:"border-none transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:["Embed ",Ce("File",s)]})]})]})]})}):null}const gn=u.createContext(),_e="ATTACHMENT_REMOVE",Ut="ATTACHMENT_CLEAR",Ie="ATTACHMENT_PASTED",Je="ATTACHMENTS_PROCESSING",de="ATTACHMENTS_PROCESSED",Xe="PARSED_FILE_ATTACHMENT_REMOVED";function oi({workspace:n,threadSlug:t=null,children:r}){const[a,o]=u.useState([]),[i,s]=u.useState(!1),[c,d]=u.useState(!1),[g,w]=u.useState(!1),[m,v]=u.useState(!1),[f,b]=u.useState(0),[L,M]=u.useState([]),[P,z]=u.useState(0),[D,k]=u.useState(Number.POSITIVE_INFINITY);u.useEffect(()=>{ne.checkDocumentProcessorOnline().then(S=>s(S))},[]),u.useEffect(()=>(window.addEventListener(_e,_),window.addEventListener(Ut,I),window.addEventListener(Ie,B),window.addEventListener(Xe,T),()=>{window.removeEventListener(_e,_),window.removeEventListener(Ut,I),window.removeEventListener(Xe,T),window.removeEventListener(Ie,B)}),[]);async function T(S){const{document:E}=S.detail;o(N=>N.filter(O=>O.document.id!==E.id))}async function _(S){const{uid:E,document:N}=S.detail;o(O=>O.filter(p=>p.uid!==E)),N!=null&&N.location&&await Y.deleteAndUnembedFile(n.slug,N.location)}function I(){o([])}function Z(){var S;return((S=a==null?void 0:a.filter(E=>E.type==="attachment"))==null?void 0:S.map(E=>({name:E.file.name,mime:E.file.type,contentString:E.contentString})))||[]}async function B(S){const{files:E=[]}=S.detail;if(!E.length)return;const N=[];for(const O of E)O.type.startsWith("image/")?N.push({uid:ae(),file:O,contentString:await Wt(O),status:"success",error:null,type:"attachment"}):N.push({uid:ae(),file:O,contentString:null,status:"in_progress",error:null,type:"upload"});o(O=>[...O,...N]),H(N)}async function U(S,E){d(!1);const N=[];for(const O of S)O.type.startsWith("image/")?N.push({uid:ae(),file:O,contentString:await Wt(O),status:"success",error:null,type:"attachment"}):N.push({uid:ae(),file:O,contentString:null,status:"in_progress",error:null,type:"upload"});o(O=>[...O,...N]),H(N)}async function H(S=[]){window.dispatchEvent(new CustomEvent(Je));const E=[],{currentContextTokenCount:N,contextWindow:O}=await Y.getParsedFiles(n.slug,t),p=O?Math.floor(O*Y.maxContextWindowLimit):Number.POSITIVE_INFINITY;k(p);let l=N,x=[];for(const A of S){if(A.type==="attachment")continue;const V=new FormData;V.append("file",A.file,A.file.name),V.append("threadSlug",t||null),E.push(Y.parseFile(n.slug,V).then(async({response:R,data:F})=>{if(!R.ok){const re={status:"failed",error:(F==null?void 0:F.error)??null};o(Q=>Q.map(J=>J.uid!==A.uid?J:{...J,...re}));return}const $=F.files[0];if(l+=$.tokenCountEstimate,x.push({attachment:A,parsedFileId:$.id,tokenCount:$.tokenCountEstimate}),l>p){z(l),M(x),w(!0);return}const W={success:!0,document:$},q={status:"added_context",error:W.error??null,document:W.document};o(re=>re.map(Q=>Q.uid!==A.uid?Q:{...Q,...q}))}))}Promise.all(E).finally(()=>window.dispatchEvent(new CustomEvent(de)))}const j=async()=>{L.length&&(await Y.deleteParsedFiles(n.slug,L.map(S=>S.parsedFileId)),o(S=>S.filter(E=>!L.some(N=>N.attachment.uid===E.uid))),w(!1),M([]),z(0),window.dispatchEvent(new CustomEvent(de)))},y=async()=>{if(!L.length)return;const S=L.map(N=>({success:!0,document:{id:N.parsedFileId}})),E=L.map((N,O)=>({uid:N.attachment.uid,updates:{status:S[O].success?"success":"failed",error:S[O].error??null,document:S[O].document}}));o(N=>N.map(O=>{const p=E.find(l=>l.uid===O.uid);return p?{...O,...p.updates}:O})),w(!1),M([]),z(0)},C=async()=>{if(!L.length)return;v(!0),b(0);let S=0;const E=await Promise.all(L.map(O=>Y.embedParsedFile(n.slug,O.parsedFileId).then(p=>(S++,b(S),p)))),N=L.map((O,p)=>{var l,x;return{uid:O.attachment.uid,updates:{status:E[p].response.ok?"embedded":"failed",error:((l=E[p].data)==null?void 0:l.error)??null,document:(x=E[p].data)==null?void 0:x.document}}});o(O=>O.map(p=>{const l=N.find(x=>x.uid===p.uid);return l?{...p,...l.updates}:p})),w(!1),M([]),z(0),v(!1),window.dispatchEvent(new CustomEvent(de)),he(`${L.length} ${Ce("file",L.length)} embedded successfully`,"success")};return e.jsxs(gn.Provider,{value:{files:a,ready:i,dragging:c,setDragging:d,onDrop:U,parseAttachments:Z},children:[e.jsx(Xa,{show:g,onClose:j,onContinue:y,onEmbed:C,tokenCount:P,maxTokens:D,fileCount:L.length,isEmbedding:m,embedProgress:f}),r]})}function li({children:n}){const{onDrop:t,ready:r,dragging:a,setDragging:o}=u.useContext(gn),{getRootProps:i,getInputProps:s}=yr({onDrop:t,disabled:!r,noClick:!0,noKeyboard:!0,onDragEnter:()=>o(!0),onDragLeave:()=>o(!1)});return e.jsxs("div",{className:"relative flex flex-col h-full w-full md:mt-0 mt-[40px] p-[1px]",...i(),children:[e.jsx("div",{hidden:!a,className:"absolute top-0 w-full h-full bg-dark-text/90 light:bg-[#C2E7FE]/90 rounded-2xl border-[4px] border-white z-[9999]",children:e.jsx("div",{className:"w-full h-full flex justify-center items-center rounded-xl",children:e.jsxs("div",{className:"flex flex-col gap-y-[14px] justify-center items-center",children:[e.jsx("img",{src:Ja,width:69,height:69,alt:"Drag and drop icon"}),e.jsx("p",{className:"text-white text-[24px] font-semibold",children:"Add anything"}),e.jsxs("p",{className:"text-white text-[16px] text-center",children:["Drop a file or image here to attach it to your ",e.jsx("br",{}),"workspace auto-magically."]})]})})}),e.jsx("input",{id:"dnd-chat-file-uploader",...s()}),n]})}async function Wt(n){return new Promise((t,r)=>{const a=new FileReader;a.onload=()=>{const o=a.result.split(",")[1];t(`data:${n.type};base64,${o}`)},a.onerror=o=>r(o),a.readAsDataURL(n)})}function es({attachments:n}){if(n.length===0)return null;function t(r){const a=n.filter(i=>i.type==="attachment"&&i.contentString).map(i=>({contentString:i.contentString,name:i.file.name})),o=a.findIndex(i=>{var s;return i.name===((s=r.file)==null?void 0:s.name)});o!==-1&&qn(a,o)}return e.jsx("div",{className:"flex flex-wrap gap-2 mt-2 mb-4",children:n.map(r=>e.jsx(ts,{attachment:r,onImageClick:()=>t(r)},r.uid))})}function ts({attachment:n,onImageClick:t}){const{uid:r,file:a,status:o,error:i,document:s,type:c,contentString:d}=n,{iconBgColor:g,Icon:w}=ns(a);function m(){window.dispatchEvent(new CustomEvent(_e,{detail:{uid:r,document:s}}))}return o==="in_progress"?e.jsxs("div",{className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-bg border-none w-[180px] group",children:[e.jsx("div",{className:"bg-theme-attachment-icon-spinner-bg rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1",children:e.jsx(Te,{size:18,weight:"bold",className:"text-theme-attachment-icon-spinner animate-spin"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-theme-attachment-text text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium",children:"Uploading..."})]})]}):o==="failed"?e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":i,className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-error-bg border-none w-[180px] group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("div",{className:"bg-error rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1",children:e.jsx(lr,{size:24,className:"text-theme-attachment-icon"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-theme-attachment-text text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium truncate",children:i??"File not embedded!"})]})]}):c==="attachment"?d?e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":`${a.name} will be attached to this prompt. It will not be embedded into the workspace permanently.`,className:"relative flex items-center gap-x-1 rounded-lg border-none group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("button",{type:"button",onClick:t,className:"p-0 border-none bg-transparent cursor-pointer",children:e.jsx("img",{alt:`Preview of ${a.name}`,src:d,style:{objectFit:"cover",objectPosition:"center"},className:`${g} w-[40px] h-[40px] rounded-lg flex items-center justify-center`})})]}):e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":`${a.name} will be attached to this prompt. It will not be embedded into the workspace permanently.`,className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-success-bg border-none w-[180px] group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("div",{className:`${g} rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1`,children:e.jsx(w,{size:24,className:"text-theme-attachment-icon"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-theme-attachment-text text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium",children:"Image attached!"})]})]}):e.jsxs("div",{"data-tooltip-id":"attachment-status-tooltip","data-tooltip-content":o==="embedded"?`${a.name} was uploaded and embedded into this workspace. It will be available for RAG chat now.`:`${a.name} will be used as context for this chat only.`,className:"relative flex items-center gap-x-1 rounded-lg bg-theme-attachment-bg border-none w-[180px] group",children:[e.jsx("div",{className:"invisible group-hover:visible absolute -top-[5px] -right-[5px] w-fit h-fit z-[10]",children:e.jsx("button",{onClick:m,type:"button",className:"bg-white hover:bg-error hover:text-theme-attachment-text rounded-full p-1 flex items-center justify-center hover:border-transparent border border-theme-attachment-bg",children:e.jsx(oe,{size:10,className:"flex-shrink-0"})})}),e.jsx("div",{className:`${g} rounded-md flex items-center justify-center flex-shrink-0 h-[32px] w-[32px] m-1`,children:e.jsx(w,{size:24,weight:"light",className:"text-theme-attachment-icon"})}),e.jsxs("div",{className:"flex flex-col w-[125px]",children:[e.jsx("p",{className:"text-white text-xs font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-theme-attachment-text-secondary text-[10px] leading-[14px] font-medium",children:o==="embedded"?"File embedded!":"Added as context!"})]})]})}function ns(n){var r,a,o;switch(((o=(a=(r=n==null?void 0:n.name)==null?void 0:r.split("."))==null?void 0:a.pop())==null?void 0:o.toLowerCase())??"txt"){case"pdf":return{iconBgColor:"bg-magenta",Icon:dr};case"doc":case"docx":return{iconBgColor:"bg-royalblue",Icon:ur};case"html":return{iconBgColor:"bg-purple",Icon:un};case"csv":case"xlsx":return{iconBgColor:"bg-success",Icon:cn};case"json":case"sql":case"js":case"jsx":case"cpp":case"c":return{iconBgColor:"bg-warn",Icon:ln};case"png":case"jpg":case"jpeg":return{iconBgColor:"bg-royalblue",Icon:dn};default:return{iconBgColor:"bg-royalblue",Icon:cr}}}function rs({onEmbeddingChange:n,tooltipRef:t,files:r,setFiles:a,currentTokens:o,setCurrentTokens:i,contextWindow:s,isLoading:c,workspaceSlug:d,threadSlug:g=null}){const{user:w}=fe(),m=!w||w.role!=="default",v=s&&o>=s*Y.maxContextWindowLimit,[f,b]=u.useState(!1),[L,M]=u.useState(1),[P,z]=u.useState(v);async function D(T,_){if(T.preventDefault(),T.stopPropagation(),!(_!=null&&_.id)||!await Y.deleteParsedFiles(d,[_.id]))return;a(U=>U.filter(H=>H.id!==_.id)),window.dispatchEvent(new CustomEvent(Xe,{detail:{document:_}}));const{currentContextTokenCount:Z}=await Y.getParsedFiles(d,g),B=s&&Z>=s*Y.maxContextWindowLimit;i(Z),z(B)}async function k(){var T;if(r.length){b(!0),n==null||n(!0),M(1);try{let _=0;await Promise.all(r.map(Z=>Y.embedParsedFile(d,Z.id).then(()=>{_++,M(_+1)}))),a([]);const{currentContextTokenCount:I}=await Y.getParsedFiles(d,g);i(I),z(I>=s*Y.maxContextWindowLimit),he(`${r.length} ${Ce("file",r.length)} embedded successfully`,"success"),(T=t==null?void 0:t.current)==null||T.close()}catch(_){console.error("Failed to embed files:",_),he("Failed to embed files","error")}b(!1),n==null||n(!1),M(1)}}return e.jsxs("div",{className:"flex flex-col gap-2 p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm font-medium text-theme-text-primary",children:["Current Context (",r.length," files)"]}),e.jsxs("div",{...P&&!m&&{"data-tooltip-id":"context-window-limit-exceeded","data-tooltip-content":"You have exceeded the context window limit. Some files may be truncated or excluded from chat responses. Responses may hallucinate or lack relevant information."},className:`flex items-center gap-x-1 ${P&&!m?"cursor-pointer":""}`,children:[P&&e.jsx(Et,{size:14,className:"text-orange-600"}),e.jsxs("div",{className:`text-xs ${P?"text-orange-600":"text-theme-text-secondary"}`,children:[At(o)," /"," ",s?At(s):"--"," tokens"]})]})]}),P&&m&&e.jsxs("div",{className:"flex flex-col gap-2 p-2 bg-theme-bg-secondary light:bg-theme-bg-primary rounded",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Et,{className:"flex-shrink-0 mt-1 text-yellow-500 light:text-yellow-600",size:16}),e.jsx("div",{className:"text-xs text-theme-text-primary",children:"Your context window is getting full. Some files may be truncated or excluded from chat responses. We recommend embedding these files directly into your workspace for better results."})]}),e.jsx("button",{onClick:k,disabled:f,className:"border-none disabled:opacity-50 flex items-center justify-center gap-2 px-3 py-2 text-xs bg-primary-button hover:bg-theme-button-primary-hover text-white font-medium rounded transition-colors shadow-sm",children:f?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"animate-spin"}),"Embedding ",L," of ",r.length," files..."]}):"Embed Files into Workspace"})]}),e.jsxs("div",{className:"flex flex-col gap-1 max-h-[300px] overflow-y-auto",children:[r.length>0&&r.map((T,_)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 p-2 text-xs bg-theme-bg-secondary rounded",children:[e.jsx("div",{className:"truncate flex-1 text-theme-text-primary",children:T.title}),e.jsx("button",{onClick:I=>D(I,T),className:"border-none text-theme-text-secondary hover:text-theme-text-primary",disabled:f,children:e.jsx(oe,{size:16})})]},_)),c&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-theme-text-secondary text-center py-2",children:[e.jsx(Te,{size:16,className:"animate-spin"}),"Loading..."]}),!c&&r.length===0&&e.jsx("div",{className:"text-xs text-theme-text-secondary text-center py-2",children:"No files found"})]})]})}function as({workspaceSlug:n=null,workspaceThreadSlug:t=null}){const{t:r}=K(),{theme:a}=Gn(),{enabled:o}=He("agentMode"),i=De(),s=n||i.slug,c=t??i.threadSlug??null;if(!o)return null;const d=u.useRef(null),[g,w]=u.useState(!1),[m,v]=u.useState([]),[f,b]=u.useState(0),[L,M]=u.useState(1/0),[P,z]=u.useState(!1),[D,k]=u.useState(!0),T=()=>{s&&(g||(k(!0),Y.getParsedFiles(s,c).then(({files:Z,contextWindow:B,currentContextTokenCount:U})=>{v(Z),z(Z.length>0),M(B),b(U)}).finally(()=>{k(!1)})))};async function _(Z){const{document:B}=Z.detail;await Y.deleteParsedFiles(s,[B.id]),T()}function I(Z){var B,U;(B=Z==null?void 0:Z.target)==null||B.blur(),(U=document==null?void 0:document.getElementById("dnd-chat-file-uploader"))==null||U.click()}return u.useEffect(()=>(T(),window.addEventListener(de,T),window.addEventListener(_e,_),()=>{window.removeEventListener(de,T),window.removeEventListener(_e,_)}),[s,c]),e.jsxs(e.Fragment,{children:[e.jsx("button",{id:"attach-item-btn","data-tooltip-id":P?"tooltip-attach-item-btn":"attach-item-btn","data-tooltip-content":P?void 0:r("chat_window.attach_file"),"aria-label":r("chat_window.attach_file"),type:"button",onClick:I,onPointerEnter:T,className:"group border-none relative flex justify-center items-center cursor-pointer w-6 h-6 rounded-full hover:bg-zinc-700 light:hover:bg-slate-200",children:e.jsxs("div",{className:"relative",children:[e.jsx(et,{size:18,className:"pointer-events-none text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-600 shrink-0",weight:"bold"}),m.length>0&&e.jsx("div",{className:"absolute -top-2.5 -right-2 bg-white text-black light:invert text-[8px] rounded-full px-1 flex items-center justify-center",children:m.length})]})}),P&&e.jsx(G,{ref:d,id:"tooltip-attach-item-btn",place:"top",opacity:1,clickable:!g,delayShow:300,delayHide:g?999999:800,arrowColor:a==="light"?"var(--theme-modal-border)":"var(--theme-bg-primary)",className:"z-99 !w-[400px] !bg-theme-bg-primary !px-[5px] !rounded-lg !pointer-events-auto light:border-2 light:border-theme-modal-border",children:e.jsx(rs,{onEmbeddingChange:w,tooltipRef:d,isLoading:D,files:m,setFiles:v,currentTokens:f,setCurrentTokens:b,contextWindow:L,workspaceSlug:s,threadSlug:c})})]})}function ss(){const[n,t]=u.useState("normal"),[r,a]=u.useState("text-[14px]"),o=i=>{switch(i){case"small":return"text-[12px]";case"large":return"text-[18px]";default:return"text-[14px]"}};return u.useEffect(()=>{const i=window.localStorage.getItem("anythingllm_text_size");i&&(t(i),a(o(i)));const s=c=>{const d=c.detail;t(d),a(o(d))};return window.addEventListener("textSizeChange",s),()=>{window.removeEventListener("textSizeChange",s)}},[]),{textSize:n,textSizeClass:r}}function ci(n){try{const t=Oe(localStorage.getItem(Me),{});t[n]="",localStorage.setItem(Me,JSON.stringify(t))}catch{}}function is({promptInput:n,setPromptInput:t}){const{threadSlug:r=null,slug:a}=De();u.useEffect(()=>{const i=localStorage.getItem(Me)||"{}",c=Oe(i,{})[r??a];c&&t(c)},[]);const o=u.useMemo(()=>an((i,s)=>{const c=localStorage.getItem(Me)||"{}",d=Oe(c,{});d[s]=i,localStorage.setItem(Me,JSON.stringify(d))},500),[]);u.useEffect(()=>(o(n,r??a),()=>{o.cancel()}),[n,r,a,o])}function xn({items:n,highlightedIndex:t,onSelect:r,registerItemCount:a}){u.useEffect(()=>{a==null||a(n.length)},[n.length,a]),u.useEffect(()=>{if(t<0||t>=n.length)return;function o(i){i.detail.key==="Enter"&&r(n[t])}return window.addEventListener(je,o),()=>window.removeEventListener(je,o)},[t,n,r])}function Ke(n){return Object.values(n).flatMap(t=>t.skills)}const Ee={"create-files-agent":{preferenceKey:"disabled_create_files_skills",getSubSkills:n=>hr(n)},"filesystem-agent":{preferenceKey:"disabled_filesystem_skills",getSubSkills:n=>mr(n)},"gmail-agent":{preferenceKey:"disabled_gmail_skills",getSubSkills:n=>Ke(pr(n)),isMultiUserSupported:!1},"google-calendar-agent":{preferenceKey:"disabled_google_calendar_skills",getSubSkills:n=>Ke(fr(n)),isMultiUserSupported:!1},"outlook-agent":{preferenceKey:"disabled_outlook_skills",getSubSkills:n=>Ke(gr(n)),isMultiUserSupported:!1}};function os(){return Object.values(Ee).map(n=>n.preferenceKey)}function ls(n,t){const r=Ee[n];return r?r.getSubSkills(t):null}function Kt(n){var t;return((t=Ee[n])==null?void 0:t.preferenceKey)??null}function cs(n){return n in Ee}function us(n){var t;return((t=Ee[n])==null?void 0:t.isMultiUserSupported)!==!1}function ds(){const[n,t]=u.useState({}),r=u.useCallback(i=>{if(!i)return;const s={};for(const[,c]of Object.entries(Ee)){const d=i[c.preferenceKey];s[c.preferenceKey]=d??[]}t(s)},[]),a=u.useCallback((i,s)=>{const c=Kt(i);return c?!(n[c]??[]).includes(s):!0},[n]),o=u.useCallback(async(i,s)=>{const c=Kt(i);if(!c)return;const d=n[c]??[],g=d.includes(s)?d.filter(w=>w!==s):[...d,s];t(w=>({...w,[c]:g})),await we.updateSystemPreferences({[c]:g.join(",")})},[n]);return{loadFromSettings:r,isSubSkillEnabled:a,toggleSubSkill:o,disabledSubSkills:n}}function hs(n){const[t,r]=u.useState(!1),[a,o]=u.useState(!1),[i,s]=u.useState([]),[c,d]=u.useState([]),[g,w]=u.useState([]),[m,v]=u.useState([]),[f,b]=u.useState([]),[L,M]=u.useState(!0),[P,z]=u.useState(!0),D=ds();u.useEffect(()=>{k(),T()},[]);async function k(){try{const H=os(),[j,y,C,S]=await Promise.all([we.systemPreferencesByFields(["disabled_agent_skills","default_agent_skills","imported_agent_skills",...H]),Ct.listFlows(),ne.isFileSystemAgentAvailable(),ne.isMultiUserMode()]);j!=null&&j.settings&&(s(j.settings.disabled_agent_skills??[]),d(j.settings.default_agent_skills??[]),w(j.settings.imported_agent_skills??[]),D.loadFromSettings(j.settings)),y!=null&&y.flows&&v(y.flows),r(C),o(!!S)}catch(H){console.error(H)}finally{M(!1)}}async function T(){try{const{servers:H=[]}=await Nt.listServers();b(H)}catch(H){console.error(H)}finally{z(!1)}}const _=u.useCallback(H=>H in n?!i.includes(H):c.includes(H),[n,i,c]),I=u.useCallback(async H=>{const j=(C,S)=>C.includes(S)?C.filter(E=>E!==S):[...C,S];if(H in n){const C=j(i,H);s(C),await we.updateSystemPreferences({disabled_agent_skills:C.join(","),default_agent_skills:c.join(",")});return}const y=j(c,H);d(y),await we.updateSystemPreferences({disabled_agent_skills:i.join(","),default_agent_skills:y.join(",")})},[n,i,c]),Z=u.useCallback(async H=>{const j=!H.active;w(y=>y.map(C=>C.hubId===H.hubId?{...C,active:j}:C)),await Yn.toggleFeature(H.hubId,j)},[]),B=u.useCallback(async H=>{const j=!H.active;v(y=>y.map(C=>C.uuid===H.uuid?{...C,active:j}:C)),await Ct.toggleFlow(H.uuid,j)},[]),U=u.useCallback(async(H,j,y)=>{const C=!y;b(S=>S.map(E=>{var p,l,x;if(E.name!==H)return E;const N=((l=(p=E.config)==null?void 0:p.anythingllm)==null?void 0:l.suppressedTools)||[],O=C?N.filter(A=>A!==j):[...N,j];return{...E,config:{...E.config,anythingllm:{...(x=E.config)==null?void 0:x.anythingllm,suppressedTools:O}}}})),await Nt.toggleTool(H,j,C)},[]);return{fileSystemAgentAvailable:t,isMultiUser:a,disabledDefaults:i,enabledConfigurable:c,importedSkills:g,flows:m,mcpServers:f,loading:L,mcpLoading:P,isSkillEnabled:_,toggleSkill:I,toggleImportedSkill:Z,toggleFlow:B,toggleMcpTool:U,isSubSkillEnabled:D.isSubSkillEnabled,toggleSubSkill:D.toggleSubSkill,disabledSubSkills:D.disabledSubSkills}}function qt({key:n,title:t,isEnabled:r,onToggle:a,t:o,isSubSkillEnabled:i,toggleSubSkill:s}){const c=ls(n,o),d=r(n);return{id:n,name:t,enabled:d,onToggle:()=>a(n),hasSubSkills:cs(n),subSkills:c?c.map(g=>({id:`${n}::${g.name}`,name:g.title,enabled:d&&i(n,g.name),onToggle:()=>s(n,g.name),parentEnabled:d})):null}}function ms({t:n,defaultSkills:t,configurableSkills:r,appIntegrationSkills:a,importedSkills:o,flows:i,mcpServers:s,isMultiUser:c,isSkillEnabled:d,toggleSkill:g,isSubSkillEnabled:w,toggleSubSkill:m,toggleImportedSkill:v,toggleFlow:f,toggleMcpTool:b,disabledSubSkills:L}){return u.useMemo(()=>{var D,k;const M=[],P=[];for(const[T,{title:_}]of Object.entries({...t,...r}))P.push(qt({key:T,title:_,isEnabled:d,onToggle:g,t:n,isSubSkillEnabled:w,toggleSubSkill:m}));P.length>0&&M.push({id:"agent-skills",name:n("chat_window.agent_skills"),items:P,enabledCount:P.filter(T=>T.enabled).length});const z=[];for(const[T,{title:_}]of Object.entries(a))c&&!us(T)||z.push(qt({key:T,title:_,isEnabled:d,onToggle:g,t:n,isSubSkillEnabled:w,toggleSubSkill:m}));if(z.length>0&&M.push({id:"app-integrations",name:n("chat_window.app_integrations"),items:z,enabledCount:z.filter(T=>T.enabled).length}),o.length>0){const T=o.map(_=>({id:_.hubId,name:_.name,enabled:_.active,onToggle:()=>v(_)}));M.push({id:"custom-skills",name:n("chat_window.custom_skills"),items:T,enabledCount:T.filter(_=>_.enabled).length})}if(i.length>0){const T=i.map(_=>({id:_.uuid,name:_.name,enabled:_.active,onToggle:()=>f(_)}));M.push({id:"agent-flows",name:n("chat_window.agent_flows"),items:T,enabledCount:T.filter(_=>_.enabled).length})}for(const T of s){if(!T.running||T.tools.length===0)continue;const _=((k=(D=T.config)==null?void 0:D.anythingllm)==null?void 0:k.suppressedTools)||[],I=T.tools.map(Z=>({id:`mcp::${T.name}::${Z.name}`,name:Z.name,enabled:!_.includes(Z.name),onToggle:()=>b(T.name,Z.name,!_.includes(Z.name))}));M.push({id:`mcp-${T.name}`,name:Qn(T.name.replace(/[_-]/g," ")),isMcp:!0,items:I,enabledCount:I.filter(Z=>Z.enabled).length})}return M},[n,t,r,a,o,i,s,c,d,g,w,m,v,f,b,L])}function Gt({name:n,enabled:t,onToggle:r,highlighted:a=!1,disabled:o=!1}){const i=u.useRef(null);u.useEffect(()=>{var c;a&&((c=i.current)==null||c.scrollIntoView({block:"nearest"}))},[a]);let s="border-none bg-transparent w-full flex items-center justify-between px-2 py-1 rounded";return a?s+=" bg-zinc-700/50 light:bg-slate-100":s+=" hover:bg-zinc-700/50 light:hover:bg-slate-100",o?s+=" opacity-60 cursor-not-allowed":s+=" cursor-pointer",e.jsxs("button",{ref:i,type:"button",className:s,onClick:()=>!o&&r(),"data-tooltip-id":o?"agent-skill-disabled-tooltip":void 0,children:[e.jsx("span",{className:"text-xs text-white light:text-slate-900",children:n}),e.jsx("div",{className:"pointer-events-none","aria-hidden":"true",children:e.jsx(Qe,{size:"sm",enabled:t})})]})}function Yt({name:n,expanded:t,onToggle:r,enabledCount:a,totalCount:o,isMcp:i=!1,indented:s=!1,highlighted:c=!1,children:d}){const g=u.useRef(null);u.useEffect(()=>{var m;c&&((m=g.current)==null||m.scrollIntoView({block:"nearest"}))},[c]);let w="border-none bg-transparent w-full flex items-center justify-between px-2 py-1 rounded cursor-pointer";return c?w+=" bg-zinc-700/50 light:bg-slate-100":w+=" hover:bg-zinc-700/30 light:hover:bg-slate-50",e.jsxs("div",{className:s?"ml-3":"",children:[e.jsxs("button",{ref:g,type:"button",className:w,onClick:r,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Jn,{size:10,weight:"bold",className:`text-zinc-400 light:text-slate-500 transition-transform duration-150 ${t?"":"-rotate-90"}`}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-zinc-400 light:text-slate-500",children:n}),i&&e.jsx("span",{className:"text-[8px] px-1 py-px rounded bg-zinc-600/50 light:bg-slate-200 text-zinc-300 light:text-slate-500 font-medium leading-tight",children:"MCP"})]}),e.jsxs("span",{className:"text-[10px] text-zinc-500 light:text-slate-400 tabular-nums",children:[a,"/",o]})]}),t&&e.jsx("div",{className:"pl-3",children:d})]})}const ps="agentSessionStart",fs="agentSessionEnd",gs=["statusResponse","fileDownloadCard","awaitingFeedback","wssFailure","rechartVisualize","toolApprovalRequest","clarificationRequest","reportStreamEvent"];function ui(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${new URL("http://localhost:8686/api").host}`}function di(n,t,r){var o,i;const a=Oe(t.data,null);if(a!==null){if(a.type==="rename_thread"){const{slug:s,name:c}=a.content||{};s&&c&&window.dispatchEvent(new CustomEvent(Xn,{detail:{threadSlug:s,newName:c}}));return}if(!a.hasOwnProperty("type")&&!n.supportsAgentStreaming)return r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]);if(a.type==="toolApprovalRequest"){if(!a.requestId||!a.skillName)return}else if(a.type==="clarificationRequest"){if(!a.requestId||!Array.isArray(a.questions))return}else if(!gs.includes(a.type)||!a.content)return;return a.type==="reportStreamEvent"?(n.supportsAgentStreaming=!0,((o=a.content)==null?void 0:o.type)==="chatId"&&((i=a.content)!=null&&i.chatId)&&er(a.content.chatId),r(s=>{if(a.content.type==="removeStatusResponse")return[...s.filter(d=>d.uuid!==a.content.uuid)];if(a.content.type==="modelRouteNotification")return a.content.routedTo?[...s.filter(d=>!(d.role==="assistant"&&d.pending&&!d.content)),{uuid:a.content.uuid,type:"modelRouteNotification",content:"modelRouteNotification",routedTo:a.content.routedTo}]:s;if(a.content.uuid?s.find(d=>d.uuid===a.content.uuid):null){const{type:d,content:g,uuid:w}=a.content;if(d==="toolCallInvocation"){const m=s.find(v=>v.uuid===w);return m?[...s.filter(v=>v.uuid!==w),{...m,content:g}]:[...s,{uuid:w,type:"toolCallInvocation",content:g}]}return d==="usageMetrics"?a.content.metrics?s.map(m=>m.uuid===w?{...m,metrics:a.content.metrics}:m):s:d==="citations"?a.content.citations?s.map(m=>m.uuid===w?{...m,sources:[...m.sources||[],...a.content.citations]}:m):s:d==="chatId"?a.content.chatId?s.map(m=>m.uuid===w?{...m,chatId:a.content.chatId}:m):s:d==="textResponseChunk"?s.map(m=>m.uuid===w?{...m,type:"textResponse",content:m.content+g}:m!=null&&m.content?m:null).filter(m=>!!m):s.map(m=>m.uuid===a.content.uuid?{...m,content:m.content+a.content.content}:m)}else return a.content.type==="fullTextResponse"?[...s.filter(d=>!!d.content),{uuid:a.content.uuid,type:"textResponse",content:a.content.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]:a.content.type==="textResponseChunk"?a.content.content.trim()===""?s:[...s.filter(d=>!!d.content),{uuid:a.content.uuid,type:"textResponse",content:a.content.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]:[...s.filter(d=>!!d.content),{uuid:a.content.uuid,type:"statusResponse",content:a.content.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:{}}]})):a.type==="fileDownloadCard"?r(s=>[...s.filter(c=>!!c.content),{type:"fileDownloadCard",uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:a.metrics||{}}]):a.type==="rechartVisualize"?r(s=>[...s.filter(c=>!!c.content),{type:"rechartVisualize",uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:!1,pending:!1,metrics:a.metrics||{}}]):a.type==="wssFailure"?r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),content:a.content,role:"assistant",sources:[],closed:!0,error:a.content,animate:!1,pending:!1,metrics:{}}]):a.type==="toolApprovalRequest"?r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),type:"toolApprovalRequest",requestId:a.requestId,skillName:a.skillName,payload:a.payload,description:a.description,timeoutMs:a.timeoutMs,content:`Approval requested for ${a.skillName}`,role:"assistant",sources:[],closed:!1,error:null,animate:!1,pending:!0,metrics:{}}]):a.type==="clarificationRequest"?r(s=>{var c,d;return[...s.filter(g=>!!g.content),{uuid:ae(),type:"clarifyingQuestion",requestId:a.requestId,questions:a.questions||[],allowSkip:a.allowSkip!==!1,timeoutMs:a.timeoutMs,content:`Agent has ${((c=a.questions)==null?void 0:c.length)||0} question${(((d=a.questions)==null?void 0:d.length)||0)===1?"":"s"}`,role:"assistant",sources:[],closed:!1,error:null,animate:!1,pending:!0,metrics:{}}]}):r(s=>[...s.filter(c=>!!c.content),{uuid:ae(),type:a.type,content:a.content,role:"assistant",sources:[],closed:!0,error:null,animate:(a==null?void 0:a.animate)||!1,pending:!1,metrics:a.metrics||{}}])}}let bn=!1;function hi(n){bn=n}function xs(){return bn}function vn(){const[n,t]=u.useState(()=>!!xs());return u.useEffect(()=>{function r(){window&&(window.addEventListener(ps,()=>t(!0)),window.addEventListener(fs,()=>t(!1)))}r()},[]),n}const bs=10;function vs({highlightedIndex:n=-1,registerItemCount:t,workspace:r}){const{t:a}=K(),{showAgentCommand:o=!0}=r??{},i=vn(),s=xr(a),c=br(a),{fileSystemAgentAvailable:d,importedSkills:g,flows:w,mcpServers:m,loading:v,mcpLoading:f,isSkillEnabled:b,toggleSkill:L,toggleImportedSkill:M,toggleFlow:P,toggleMcpTool:z,isMultiUser:D,isSubSkillEnabled:k,toggleSubSkill:T,disabledSubSkills:_}=hs(s),I=vr(a,{fileSystemAgentAvailable:d}),[Z,B]=u.useState({}),[U,H]=u.useState({}),[j,y]=u.useState(""),C=o&&!i,S=ms({t:a,defaultSkills:s,configurableSkills:I,appIntegrationSkills:c,importedSkills:g,flows:w,mcpServers:m,isMultiUser:D,isSkillEnabled:b,toggleSkill:L,isSubSkillEnabled:k,toggleSubSkill:T,toggleImportedSkill:M,toggleFlow:P,toggleMcpTool:z,disabledSubSkills:_});function E(R){return!!(j.trim()||Z[R])}function N(R){B(F=>({...F,[R]:!F[R]}))}function O(R){return!!(j.trim()||U[R])}function p(R){H(F=>({...F,[R]:!F[R]}))}const l=u.useMemo(()=>{if(!j.trim())return S;const R=j.toLowerCase();return S.map(F=>{const $=F.items.filter(W=>{var Q;const q=W.name.toLowerCase().includes(R),re=((Q=W.subSkills)==null?void 0:Q.some(J=>J.name.toLowerCase().includes(R)))??!1;return q||re});return{...F,items:$,enabledCount:$.filter(W=>W.enabled).length}}).filter(F=>F.items.length>0)},[S,j]),{flatItems:x,flatIndexMap:A}=u.useMemo(()=>{const R=[],F={};for(const $ of l)if(F[$.id]=R.length,R.push({type:"header",id:$.id,onToggle:()=>N($.id)}),E($.id)){for(const W of $.items)if(F[W.id]=R.length,R.push(W),W.hasSubSkills&&W.subSkills&&(F[`subsection-${W.id}`]=R.length,R.push({type:"subheader",id:`subsection-${W.id}`,parentId:W.id,onToggle:()=>p(W.id)}),O(W.id)))for(const q of W.subSkills)F[q.id]=R.length,R.push(q)}return{flatItems:R,flatIndexMap:F}},[l,Z,U,j]),V=S.reduce((R,F)=>R+F.items.length,0);return xn({items:x,highlightedIndex:n,onSelect:R=>{if(R.type==="header")return R.onToggle();i||R.onToggle()},registerItemCount:t}),v?null:e.jsxs(e.Fragment,{children:[C&&e.jsx("p",{className:"text-xs text-theme-text-secondary text-center py-1",children:a("chat_window.use_agent_session_to_use_tools")}),V>=bs&&e.jsx(ws,{value:j,onChange:y,placeholder:a("common.search")}),l.map(R=>e.jsx(Yt,{name:R.name,expanded:E(R.id),onToggle:()=>N(R.id),enabledCount:R.enabledCount,totalCount:R.items.length,isMcp:R.isMcp,highlighted:n===A[R.id],children:R.items.map(F=>e.jsxs("div",{children:[e.jsx(Gt,{name:F.name,enabled:F.enabled,onToggle:F.onToggle,highlighted:n===A[F.id],disabled:i}),F.hasSubSkills&&F.subSkills&&F.enabled&&e.jsx(Yt,{name:a("chat_window.sub_skills"),expanded:O(F.id),onToggle:()=>p(F.id),enabledCount:F.subSkills.filter($=>$.enabled).length,totalCount:F.subSkills.length,highlighted:n===A[`subsection-${F.id}`],indented:!0,children:F.subSkills.map($=>e.jsx(Gt,{name:$.name,enabled:$.enabled,onToggle:$.onToggle,highlighted:n===A[$.id],disabled:i||!$.parentEnabled},$.id))})]},F.id))},R.id)),f&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:[e.jsx(Te,{size:12,className:"text-zinc-500 light:text-slate-400 animate-spin",weight:"bold"}),e.jsx("span",{className:"text-[10px] text-zinc-500 light:text-slate-400",children:a("chat_window.loading_mcp_servers")})]}),l.length===0&&!f&&j.trim()&&e.jsx("p",{className:"text-xs text-zinc-500 light:text-slate-400 text-center py-2",children:a("chat_window.no_tools_found")}),e.jsx(nn,{to:rn.settings.agentSkills(),children:e.jsxs("button",{className:"border-none flex items-center gap-1.5 px-2 h-6 rounded cursor-pointer hover:bg-zinc-700/50 light:hover:bg-slate-100 text-theme-text-primary",children:[e.jsx(tr,{size:12,className:"text-theme-text-primary"}),e.jsx("span",{className:"text-xs text-theme-text-primary",children:a("chat_window.manage_agent_skills")})]})})]})}function ws({value:n,onChange:t,placeholder:r}){return e.jsxs("div",{className:"relative shrink-0",children:[e.jsx(en,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-zinc-400 light:text-slate-400",weight:"bold"}),e.jsx("input",{type:"text",placeholder:r,value:n,onChange:a=>t(a.target.value),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.key==="Escape"&&(t(""),a.target.blur()),a.key==="Enter"&&a.preventDefault()},className:"w-full pl-7 pr-2 py-1 text-xs bg-zinc-700/50 light:bg-slate-100 border border-zinc-600 light:border-slate-300 rounded text-white light:text-slate-900 placeholder:text-zinc-500 light:placeholder:text-slate-400 outline-none focus:border-zinc-500 light:focus:border-slate-400"})]})}const Ze=/[^a-zA-Z0-9_-]/g;function ys({isOpen:n,onClose:t,onSave:r}){const[a,o]=u.useState(""),{t:i}=K(),s=async d=>{d.preventDefault();const g=new FormData(d.target),w=a.replace(Ze,"");await r({command:`/${w}`,prompt:g.get("prompt"),description:g.get("description")})&&o("")},c=d=>{const g=d.target.value.replace(Ze,"");o(g)};return e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"w-full max-w-2xl bg-theme-bg-secondary rounded-lg shadow border-2 border-theme-modal-border overflow-hidden",children:[e.jsxs("div",{className:"relative p-6 border-b rounded-t border-theme-modal-border",children:[e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsx("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:i("chat_window.add_new_preset")})}),e.jsx("button",{onClick:t,type:"button",className:"absolute top-4 right-4 transition-all duration-300 bg-transparent rounded-lg text-sm p-1 inline-flex items-center hover:bg-theme-modal-border hover:border-theme-modal-border hover:border-opacity-50 border-transparent border",children:e.jsx(oe,{size:24,weight:"bold",className:"text-white"})})]}),e.jsx("div",{className:"h-full w-full overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:e.jsxs("form",{onSubmit:s,children:[e.jsx("div",{className:"py-7 px-9 space-y-2 flex-col",children:e.jsxs("div",{className:"w-full flex flex-col gap-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"command",className:"block mb-2 text-sm font-medium text-white",children:i("chat_window.command")}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-white text-sm mr-2 font-bold",children:"/"}),e.jsx("input",{name:"command",type:"text",id:"command",placeholder:i("chat_window.your_command"),value:a,onChange:c,maxLength:25,autoComplete:"off",required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"prompt",className:"block mb-2 text-sm font-medium text-white",children:"Prompt"}),e.jsx("textarea",{name:"prompt",id:"prompt",autoComplete:"off",placeholder:i("chat_window.placeholder_prompt"),required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"description",className:"block mb-2 text-sm font-medium text-white",children:i("chat_window.description")}),e.jsx("input",{type:"text",name:"description",id:"description",placeholder:i("chat_window.placeholder_description"),maxLength:80,autoComplete:"off",required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]})}),e.jsxs("div",{className:"flex w-full justify-end items-center p-6 space-x-2 border-t border-theme-modal-border rounded-b",children:[e.jsx("button",{onClick:t,type:"button",className:"transition-all duration-300 bg-transparent text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:i("chat_window.cancel")}),e.jsx("button",{type:"submit",className:"transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:i("chat_window.save")})]})]})})]})})}function Ss({isOpen:n,onClose:t,onSave:r,onDelete:a,preset:o}){const[i,s]=u.useState(""),[c,d]=u.useState(!1);u.useEffect(()=>{var v;o&&n&&s(((v=o.command)==null?void 0:v.slice(1))||"")},[o,n]);const g=v=>{v.preventDefault();const f=new FormData(v.target),b=i.replace(Ze,"");r({id:o.id,command:`/${b}`,prompt:f.get("prompt"),description:f.get("description")})},w=v=>{const f=v.target.value.replace(Ze,"");s(f)},m=async()=>{window.confirm("Are you sure you want to delete this preset?")&&(d(!0),await a(o.id),d(!1),t())};return e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"w-full max-w-2xl bg-theme-bg-secondary rounded-lg shadow border-2 border-theme-modal-border overflow-hidden",children:[e.jsxs("div",{className:"relative p-6 border-b rounded-t border-theme-modal-border",children:[e.jsx("div",{className:"w-full flex gap-x-2 items-center",children:e.jsx("h3",{className:"text-xl font-semibold text-white overflow-hidden overflow-ellipsis whitespace-nowrap",children:"Edit Preset"})}),e.jsx("button",{onClick:t,type:"button",className:"absolute top-4 right-4 transition-all duration-300 bg-transparent rounded-lg text-sm p-1 inline-flex items-center hover:bg-theme-modal-border hover:border-theme-modal-border hover:border-opacity-50 border-transparent border",children:e.jsx(oe,{size:24,weight:"bold",className:"text-white"})})]}),e.jsx("div",{className:"h-full w-full overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:e.jsxs("form",{onSubmit:g,children:[e.jsx("div",{className:"py-7 px-9 space-y-2 flex-col",children:e.jsxs("div",{className:"w-full flex flex-col gap-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"command",className:"block mb-2 text-sm font-medium text-white",children:"Command"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-white text-sm mr-2 font-bold",children:"/"}),e.jsx("input",{type:"text",name:"command",placeholder:"your-command",value:i,onChange:w,required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"prompt",className:"block mb-2 text-sm font-medium text-white",children:"Prompt"}),e.jsx("textarea",{name:"prompt",placeholder:"This is a test prompt. Please respond with a poem about LLMs.",defaultValue:o.prompt,required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"description",className:"block mb-2 text-sm font-medium text-white",children:"Description"}),e.jsx("input",{type:"text",name:"description",defaultValue:o.description,placeholder:"Responds with a poem about LLMs.",required:!0,className:"border-none bg-theme-settings-input-bg w-full text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"})]})]})}),e.jsxs("div",{className:"flex w-full justify-between items-center p-6 space-x-2 border-t border-theme-modal-border rounded-b",children:[e.jsx("button",{disabled:c,onClick:m,type:"button",className:"border-none transition-all duration-300 bg-transparent text-red-500 hover:bg-red-500/25 px-4 py-2 rounded-lg text-sm disabled:opacity-50",children:c?"Deleting...":"Delete Preset"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{onClick:t,type:"button",className:"border-none transition-all duration-300 bg-transparent text-white hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Cancel"}),e.jsx("button",{type:"submit",className:"transition-all duration-300 bg-white text-black hover:opacity-60 px-4 py-2 rounded-lg text-sm",children:"Save"})]})]})]})})]})})}function js({command:n,description:t,onClick:r,onEdit:a,onPublish:o,showMenu:i=!1,highlighted:s=!1}){const{t:c}=K(),[d,g]=u.useState(!1),[w,m]=u.useState({top:0,left:0}),v=u.useRef(null),f=u.useRef(null);return u.useEffect(()=>{if(!d)return;function b(L){v.current&&!v.current.contains(L.target)&&f.current&&!f.current.contains(L.target)&&g(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[d]),u.useEffect(()=>{if(d&&f.current){const b=f.current.getBoundingClientRect();m({top:b.bottom+window.scrollY,left:b.right+window.scrollX-120})}},[d]),e.jsxs("div",{onClick:r,className:`flex items-center justify-between px-2 py-1 rounded cursor-pointer group relative ${s?"bg-zinc-700/50 light:bg-slate-100":"hover:bg-zinc-700/50 light:hover:bg-slate-100"}`,children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-xs min-w-0 flex-1",children:[e.jsx("span",{className:"text-white light:text-slate-900 shrink-0",children:n}),e.jsx("span",{className:"text-zinc-400 light:text-slate-500 italic truncate",children:t})]}),i&&e.jsxs("div",{className:"relative shrink-0 ml-1",children:[e.jsx("button",{ref:f,type:"button",onClick:b=>{b.stopPropagation(),g(!d)},className:"border-none cursor-pointer text-zinc-400 light:text-slate-500 p-0.5 hover:text-white light:hover:text-slate-900 rounded opacity-0 group-hover:opacity-100",children:e.jsx(nr,{size:16,weight:"bold"})}),d&&Fe.createPortal(e.jsxs("div",{ref:v,style:{position:"fixed",top:w.top,left:w.left},className:"z-[9999] bg-zinc-800 light:bg-white border border-zinc-700 light:border-slate-300 rounded-lg shadow-lg min-w-[120px] flex flex-col overflow-hidden",children:[e.jsx("button",{type:"button",className:"border-none px-3 py-1.5 text-xs text-white light:text-slate-900 hover:bg-zinc-700 light:hover:bg-slate-100 cursor-pointer text-left",onClick:b=>{b.stopPropagation(),g(!1),a==null||a()},children:c("chat_window.edit")}),e.jsx("button",{type:"button",className:"border-none px-3 py-1.5 text-xs text-white light:text-slate-900 hover:bg-zinc-700 light:hover:bg-slate-100 cursor-pointer text-left",onClick:b=>{b.stopPropagation(),g(!1),o==null||o()},children:c("chat_window.publish")})]}),document.body)]})]})}function Es({sendCommand:n,setShowing:t,promptRef:r,highlightedIndex:a=-1,registerItemCount:o}){const{t:i}=K(),{isOpen:s,openModal:c,closeModal:d}=Ve(),{isOpen:g,openModal:w,closeModal:m}=Ve(),{isOpen:v,openModal:f,closeModal:b}=Ve(),[L,M]=u.useState([]),[P,z]=u.useState(null),[D,k]=u.useState(null);u.useEffect(()=>{T()},[]);const T=async()=>{const y=await ne.getSlashCommandPresets();M(y)},_=u.useMemo(()=>[{command:"/reset",description:i("chat_window.preset_reset_description"),autoSubmit:!0},...L.map(y=>({command:y.command,description:y.description,autoSubmit:!1,preset:y}))],[L,i]),I=u.useCallback((y,C=!1)=>{var A;if(t(!1),C){n({text:y,autoSubmit:!0}),(A=r==null?void 0:r.current)==null||A.focus();return}const S=r==null?void 0:r.current;if(!S)return;const E=S.selectionStart,N=S.value,p=(E>0?N[E-1]:"")==="/"?E-1:E,l=N.slice(0,p)+y+N.slice(E);window.dispatchEvent(new CustomEvent(Le,{detail:{messageContent:l}})),S.focus();const x=p+y.length;setTimeout(()=>S.setSelectionRange(x,x),0)},[n,t,r]);xn({items:_,highlightedIndex:a,onSelect:y=>{const C=y.preset?`${y.command} `:y.command;I(C,y.autoSubmit)},registerItemCount:o});const Z=async y=>{const{error:C}=await ne.createSlashCommandPreset(y);return C?(he(C,"error"),!1):(T(),d(),!0)},B=y=>{z(y),w()},U=async y=>{const{error:C}=await ne.updateSlashCommandPreset(y.id,y);if(C){he(C,"error");return}T(),m(),z(null)},H=async y=>{await ne.deleteSlashCommandPreset(y),T(),m(),z(null)},j=y=>{k({name:y.command.slice(1),description:y.description,command:y.command,prompt:y.prompt}),f()};return e.jsxs(e.Fragment,{children:[_.map((y,C)=>{var S;return e.jsx(js,{command:y.command,description:y.description,onClick:()=>I(y.preset?`${y.command} `:y.command,y.autoSubmit),onEdit:y.preset?()=>B(y.preset):void 0,onPublish:y.preset?()=>j(y.preset):void 0,showMenu:!!y.preset,highlighted:a===C},((S=y.preset)==null?void 0:S.id)??y.command)}),e.jsxs("div",{onClick:c,className:"flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer hover:bg-zinc-700/50 light:hover:bg-slate-100",children:[e.jsx(et,{size:12,weight:"bold",className:"text-white light:text-slate-900"}),e.jsx("span",{className:"text-xs text-white light:text-slate-900",children:i("chat_window.add_new")})]}),e.jsx(ys,{isOpen:s,onClose:d,onSave:Z}),P&&e.jsx(Ss,{isOpen:g,onClose:()=>{m(),z(null)},onSave:U,onDelete:H,preset:P}),e.jsx(Sr,{show:v,onClose:b,entityType:"slash-command",entity:D})]})}const je="tools-menu-keyboard";function As(n,t){const r=[{key:"slash-commands",label:n("chat_window.slash_commands"),component:Es}];return(!(t!=null&&t.hasOwnProperty("role"))||t.role==="admin")&&r.push({key:"agent-skills",label:n("chat_window.agent_skills"),component:vs}),r}function Ns({workspace:n,showing:t,setShowing:r,sendCommand:a,promptRef:o,centered:i=!1,highlightedIndexRef:s}){const{t:c}=K(),{user:d}=fe(),g=u.useMemo(()=>As(c,d),[c,d]),[w,m]=u.useState(g[0].key),[v,f]=u.useState(-1),[b,L]=u.useState(360),M=u.useRef(0),P=u.useRef(null);u.useEffect(()=>{t&&m(g[0].key)},[t]),u.useEffect(()=>{f(-1)},[w,t]),u.useLayoutEffect(()=>{if(!t)return;const k=()=>{const T=P.current;if(!T)return;const _=T.getBoundingClientRect(),I=i?window.innerHeight-_.top-16:_.bottom-16;L(Math.max(0,Math.min(360,I)))};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[t,i]),u.useEffect(()=>{s&&(s.current=v)},[v]);const z=u.useCallback(k=>{M.current=k},[]);if(u.useEffect(()=>{if(!t)return;function k(T){const{key:_}=T.detail;if(_==="ArrowLeft"||_==="ArrowRight"){const I=g.findIndex(B=>B.key===w),Z=_==="ArrowLeft"?(I-1+g.length)%g.length:(I+1)%g.length;m(g[Z].key);return}if(_==="ArrowUp"||_==="ArrowDown"){const I=M.current;if(I===0)return;f(Z=>_==="ArrowDown"?Z<I-1?Z+1:0:Z>0?Z-1:I-1);return}}return window.addEventListener(je,k),()=>window.removeEventListener(je,k)},[t,w]),!t)return null;const{component:D}=g.find(k=>k.key===w);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onMouseDown:k=>k.preventDefault(),onClick:()=>r(!1)}),e.jsxs("div",{ref:P,onMouseDown:k=>{k.currentTarget.contains(k.target)&&k.preventDefault()},style:{maxHeight:b},className:`absolute left-2 right-2 md:left-14 md:right-auto md:w-[400px] z-50 bg-zinc-800 light:bg-white border border-zinc-700 light:border-slate-300 rounded-lg p-3 flex flex-col gap-2.5 shadow-lg overflow-hidden ${i?"top-full mt-2":"bottom-full mb-2"}`,children:[e.jsx("div",{className:"flex shrink-0 gap-2.5 items-center",children:g.map(k=>e.jsx(ks,{active:w===k.key,onClick:()=>m(k.key),children:k.label},k.key))}),e.jsx("div",{className:"flex flex-col gap-1 overflow-y-auto no-scroll min-h-0",children:e.jsx(D,{sendCommand:a,setShowing:r,promptRef:o,highlightedIndex:v,registerItemCount:z,workspace:n})})]})]})}function ks({active:n,onClick:t,children:r}){return e.jsx("button",{type:"button",onClick:t,className:`border-none cursor-pointer hover:bg-zinc-700/50 light:hover:bg-slate-100 px-1.5 py-0.5 rounded text-[10px] font-medium text-center whitespace-nowrap ${n?"bg-zinc-700 text-white light:bg-slate-200 light:text-slate-800":"text-zinc-400 light:text-slate-800"}`,children:r})}const Cs="primary-prompt-input",Le="set_prompt_input",Ms=100;function mi({workspace:n={},submit:t,isStreaming:r,sendCommand:a,attachments:o=[],centered:i=!1,workspaceSlug:s=null,threadSlug:c=null}){const{t:d}=K(),{showAgentCommand:g=!0}=n??{},{isDisabled:w}=Ps(),{enabled:m}=He("agentMode"),v=vn(),[f,b]=u.useState(""),[L,M]=u.useState(!1),P=u.useRef(!1),z=u.useRef(-1),D=u.useRef(null),k=u.useRef(null),[T,_]=u.useState(!1),I=u.useRef([]),Z=u.useRef([]),{textSizeClass:B}=ss(),[U]=rr();is({promptInput:f,setPromptInput:b}),u.useEffect(()=>{var l;U.get("action")==="set-agent-chat"&&(a({text:"@agent "}),(l=k.current)==null||l.focus())},[k.current]);function H(l){const{messageContent:x,writeMode:A="replace"}=(l==null?void 0:l.detail)??{};b(A==="append"?V=>V+x:A==="prepend"?V=>x+" "+V:x??"")}u.useEffect(()=>(window&&window.addEventListener(Le,H),()=>window==null?void 0:window.removeEventListener(Le,H)),[]),u.useEffect(()=>{!r&&k.current&&k.current.focus(),S()},[r]);function j(l=0){I.current.length>=Ms&&I.current.shift(),I.current.push({value:f,cursorPositionStart:k.current.selectionStart+l,cursorPositionEnd:k.current.selectionEnd+l})}const y=an(j,250);function C(l){l.target===l.currentTarget&&(_(!1),M(!1),t(l))}function S(){k.current&&(k.current.style.height="auto")}function E(l){var x;if(L){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(l.key)){l.preventDefault(),window.dispatchEvent(new CustomEvent(je,{detail:{key:l.key}}));return}if(l.key==="Enter"&&z.current>=0){l.preventDefault(),window.dispatchEvent(new CustomEvent(je,{detail:{key:"Enter"}}));return}if(l.key==="Escape"){l.preventDefault(),M(!1),(x=k.current)==null||x.focus();return}}if(l.key==="/"&&!l.ctrlKey&&!l.metaKey&&f.trim()===""){M(A=>(P.current=!A,!A));return}if(l.keyCode===13&&!l.shiftKey)return l.preventDefault(),r||w?void 0:(M(!1),t(l));if((l.ctrlKey||l.metaKey)&&l.key==="z"&&l.shiftKey){if(l.preventDefault(),Z.current.length===0)return;const A=Z.current.pop();if(!A)return;I.current.push({value:f,cursorPositionStart:k.current.selectionStart,cursorPositionEnd:k.current.selectionEnd}),b(A.value),setTimeout(()=>{k.current.setSelectionRange(A.cursorPositionStart,A.cursorPositionEnd)},0)}if((l.ctrlKey||l.metaKey)&&l.key==="z"&&!l.shiftKey){if(I.current.length===0)return;const A=I.current.pop();if(!A)return;Z.current.push({value:f,cursorPositionStart:k.current.selectionStart,cursorPositionEnd:k.current.selectionEnd}),b(A.value),setTimeout(()=>{k.current.setSelectionRange(A.cursorPositionStart,A.cursorPositionEnd)},0)}}function N(l){const x=l.target;x.style.height="auto",x.style.height=`${x.scrollHeight}px`}function O(l){if(l.preventDefault(),l.clipboardData.items.length===0)return!1;for(const A of l.clipboardData.items){if(A.type.startsWith("image/")){const V=A.getAsFile();window.dispatchEvent(new CustomEvent(Ie,{detail:{files:[V]}}));continue}if(A.kind==="file"){const V=A.getAsFile();window.dispatchEvent(new CustomEvent(Ie,{detail:{files:[V]}}));continue}}const x=l.clipboardData.getData("text/plain");if(x){const A=k.current,V=A.selectionStart,R=A.selectionEnd,F=f.substring(0,V)+x+f.substring(R);b(F),setTimeout(()=>{A.selectionStart=A.selectionEnd=V+x.length,N({target:A})},0)}}function p(l){y(-1),N(l);const x=l.target.value;b(x),P.current&&L&&x!=="/"&&(M(!1),P.current=!1)}return e.jsx("div",{id:"prompt-input-wrapper",className:i?"w-full relative flex justify-center items-center":"w-full fixed md:absolute bottom-0 left-0 z-10 flex justify-center items-center pwa:pb-5",children:e.jsx("form",{onSubmit:C,className:i?"flex flex-col gap-y-1 rounded-t-lg w-full items-center":"flex flex-col gap-y-1 rounded-t-lg md:w-full w-full mx-auto max-w-[750px] items-center",children:e.jsx("div",{className:`flex items-center rounded-lg md:w-full ${i?"mb-0":"mb-4"}`,children:e.jsxs("div",{className:"relative w-[95vw] md:w-[750px]",children:[e.jsx(Ns,{workspace:n,showing:L,setShowing:M,sendCommand:a,promptRef:k,centered:i,highlightedIndexRef:z}),e.jsxs("div",{className:"bg-zinc-800 light:bg-white light:border light:border-slate-300 rounded-[20px] pwa:rounded-3xl flex flex-col px-5 overflow-hidden",children:[e.jsx(es,{attachments:o}),e.jsx("div",{className:"flex items-center",children:e.jsx("textarea",{id:Cs,ref:k,onChange:p,onKeyDown:E,onPaste:l=>{j(),O(l)},required:!0,onFocus:()=>_(!0),onBlur:l=>{_(!1),N(l)},value:f,spellCheck:tn.get("enableSpellCheck"),className:`border-none cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] pt-[20px] w-full leading-5 text-white light:text-slate-600 bg-transparent placeholder:text-white/60 light:placeholder:text-slate-400 resize-none active:outline-none focus:outline-none flex-grow pwa:!text-[16px] ${B}`,placeholder:d("chat_window.send_message")})}),e.jsxs("div",{className:"flex justify-between items-center pt-3.5 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-x-0.25",children:[e.jsxs("div",{className:"flex items-center gap-x-1",children:[e.jsx(as,{workspaceSlug:s,workspaceThreadSlug:c}),e.jsx(Ts,{sendCommand:a,promptInput:f,textareaRef:k,visible:m&&!v&&g})]}),e.jsx(_s,{showTools:L,setShowTools:M,textareaRef:k,autoOpenedToolsRef:P,visible:m})]}),e.jsxs("div",{className:"flex gap-x-2 items-center",children:[e.jsx(Qa,{sendCommand:a}),r?e.jsx(La,{}):e.jsx(Ls,{formRef:D,promptInput:f,isDisabled:w})]})]})]})]})})})})}function Ts({sendCommand:n,promptInput:t,textareaRef:r,visible:a=!0}){const{t:o}=K();if(!a)return null;function i(){var s,c;try{if((s=t==null?void 0:t.trim())!=null&&s.startsWith("@agent"))return;n({text:"@agent",writeMode:"prepend"})}finally{(c=r==null?void 0:r.current)==null||c.focus()}}return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:i,"data-tooltip-id":"agent-session","data-tooltip-content":o("chat_window.start_agent_session"),"aria-label":o("chat_window.start_agent_session"),className:"group border-none relative flex justify-center items-center cursor-pointer w-6 h-6 rounded-full hover:bg-zinc-700 light:hover:bg-slate-200",children:e.jsx(on,{size:18,className:"pointer-events-none text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-600 shrink-0"})}),e.jsx(G,{id:"agent-session",place:"bottom",delayShow:300,className:"tooltip !text-xs z-99"})]})}function _s({showTools:n,setShowTools:t,textareaRef:r,autoOpenedToolsRef:a,visible:o=!0}){const{t:i}=K();return o?e.jsx("button",{id:"tools-btn",type:"button",onClick:()=>{var s;a.current=!1,t(!n),(s=r.current)==null||s.focus()},className:`group border-none cursor-pointer flex items-center justify-center h-6 px-2 rounded-full ${n?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:e.jsx("span",{className:`text-sm font-medium ${n?"text-white light:text-slate-800":"text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-800"}`,children:i("chat_window.tools")})}):null}function Ls({formRef:n,promptInput:t,isDisabled:r}){const{t:a}=K();return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:n,type:"submit",disabled:r||!t.trim().length,className:`border-none flex justify-center items-center rounded-full w-8 h-8 transition-all ${t.trim().length&&!r?"cursor-pointer bg-white hover:bg-zinc-200 light:bg-slate-800 light:hover:bg-slate-600":"cursor-not-allowed bg-zinc-600 light:bg-slate-400"}`,"data-tooltip-id":"send-prompt","data-tooltip-content":a(r?"chat_window.attachments_processing":"chat_window.send"),"aria-label":a("chat_window.send"),children:[e.jsx(sn,{className:"w-[18px] h-[18px] pointer-events-none text-zinc-800 light:text-white",weight:"bold"}),e.jsx("span",{className:"sr-only",children:a("chat_window.send")})]}),e.jsx(G,{id:"send-prompt",place:"bottom",delayShow:300,className:"tooltip !text-xs z-99"})]})}function Ps(){const[n,t]=u.useState(!1);return u.useEffect(()=>{if(!window)return;const r=()=>t(!0),a=()=>t(!1);return window.addEventListener(Je,r),window.addEventListener(de,a),()=>{window.removeEventListener(Je,r),window.removeEventListener(de,a)}},[]),{isDisabled:n}}function pi({hasAvailableWorkspace:n,onCreateAgent:t,onEditWorkspace:r,onUploadDocument:a}){const{t:o}=K(),{user:i}=fe();return e.jsx("div",{className:"flex flex-wrap justify-center gap-2 mt-6",children:e.jsx(Rs,{label:o("main-page.quickActions.editWorkspace"),onClick:r,show:n&&(!i||["admin","manager"].includes(i==null?void 0:i.role))})})}function Rs({label:n,onClick:t,show:r=!0}){return r?e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 rounded-full bg-theme-bg-chat-input text-white/80 text-sm font-normal leading-5 hover:bg-zinc-700 light:hover:bg-black/20 transition-colors light:text-theme-text-primary",children:n}):null}function fi({suggestedMessages:n=[],sendCommand:t}){return n!=null&&n.length?e.jsx("div",{className:"flex flex-col w-full max-w-[650px] mt-6 px-4",children:n.map((r,a)=>{var i,s,c;const o=(i=r.heading)!=null&&i.trim()?`${r.heading.trim()} ${((s=r.message)==null?void 0:s.trim())||""}`:((c=r.message)==null?void 0:c.trim())||"";return o?e.jsxs("div",{children:[a>0&&e.jsx("div",{className:"border-t border-zinc-800 light:border-theme-chat-input-border"}),e.jsx("button",{type:"button",onClick:()=>t({text:o,autoSubmit:!0}),className:"w-full text-left py-3 px-3 text-white/80 text-sm font-normal leading-5 hover:text-white transition-colors light:text-theme-text-primary light:hover:text-theme-text-primary/80 hover:bg-zinc-800 light:hover:bg-black/20 rounded-lg",children:o})]},a):null})}):null}function zs(n){return[{key:"small",label:n("chat_window.small")},{key:"normal",label:n("chat_window.normal")},{key:"large",label:n("chat_window.large")}]}function Vs(){const{t:n}=K(),[t,r]=u.useState(!1),[a,o]=u.useState(window.localStorage.getItem("anythingllm_text_size")||"normal");function i(s){o(s),window.localStorage.setItem("anythingllm_text_size",s),window.dispatchEvent(new CustomEvent("textSizeChange",{detail:s}))}return e.jsxs("div",{className:"relative",onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[e.jsxs("div",{className:`flex items-center justify-between px-2 py-1 rounded cursor-pointer ${t?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:[e.jsx("span",{className:"text-sm font-normal text-zinc-50 light:text-slate-800",children:n("chat_window.text_size_label")}),e.jsx(ar,{size:14,weight:"bold",className:"text-zinc-50 light:text-slate-800"})]}),t&&e.jsx(Os,{selectedSize:a,onSizeChange:i})]})}function Os({selectedSize:n,onSizeChange:t}){const{t:r}=K(),a=zs(r);return e.jsx("div",{className:"absolute right-full top-0 -mr-2 pr-2 pt-0",children:e.jsx("div",{className:"bg-zinc-800 light:bg-slate-50 border border-zinc-700 light:border-slate-300 rounded-lg p-3.5 w-[98px] flex flex-col gap-1.5 shadow-lg",children:a.map(({key:o,label:i})=>e.jsx("div",{onClick:()=>t(o),className:`px-2 py-1 rounded cursor-pointer text-sm font-normal text-white light:text-slate-800 ${n===o?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700/50 light:hover:bg-slate-100"}`,children:i},o))})})}const at=u.createContext();function gi({children:n}){const[t,r]=u.useState(null),[a,o]=u.useState(null);function i(d,g=null){r(d),o(g)}function s(){r(null),o(null)}function c(d,g=null){t===d?s():i(d,g)}return e.jsx(at.Provider,{value:{activeSidebar:t,sidebarData:a,openSidebar:i,closeSidebar:s,toggleSidebar:c},children:n})}function Is(){const{activeSidebar:n,sidebarData:t,openSidebar:r,closeSidebar:a}=u.useContext(at);return{sidebarOpen:n==="sources",sources:n==="sources"?t:[],openSidebar:o=>r("sources",o),closeSidebar:a}}function wn(){const{activeSidebar:n,toggleSidebar:t,closeSidebar:r}=u.useContext(at);return{sidebarOpen:n==="memories",toggleSidebar:()=>t("memories"),closeSidebar:r}}function Zs({isOpen:n,children:t}){return e.jsx("div",{className:"h-full overflow-hidden transition-all duration-500 flex-shrink-0",style:{width:n?"366px":"0px"},children:t})}function Fs({onClose:n}){const{t}=K(),{user:r}=fe(),{toggleSidebar:a}=wn(),{closeSidebar:o}=Is(),[i,s]=u.useState(null),c=He("memories");!r||(r==null||r.role),u.useEffect(()=>{ne.keys().then(g=>{s(!!(g!=null&&g.MemoryEnabled))})},[]);function d(){o(),a(),n()}return i===null||!i||!c.enabled?null:e.jsx("div",{onClick:d,className:"flex items-center px-2 py-1 rounded cursor-pointer hover:bg-zinc-700 light:hover:bg-slate-200",children:e.jsx("span",{className:"text-sm font-normal text-white light:text-slate-800",children:t("chat_window.memories.title")})})}function xi(){const n=sr(),[t,r]=u.useState(!1),a=u.useRef(null),o=u.useRef(null);u.useEffect(()=>{if(!t)return;function s(c){a.current&&!a.current.contains(c.target)&&o.current&&!o.current.contains(c.target)&&r(!1)}return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[t]);const i=n!==null;return e.jsxs("div",{className:`absolute top-3 md:top-5 z-30 ${i?"right-[55px] md:right-[67px]":"right-4 md:right-6"}`,children:[e.jsx("button",{ref:o,type:"button",onClick:()=>r(!t),className:`group border-none cursor-pointer flex items-center justify-center w-[35px] h-[35px] rounded-full transition-all ${t?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:e.jsx(wr,{size:18,className:t?"text-white light:text-slate-800":"text-zinc-300 light:text-slate-600 group-hover:text-white light:group-hover:text-slate-800"})}),t&&e.jsxs("div",{ref:a,className:"absolute right-0 top-[42px] bg-zinc-800 light:bg-slate-50 border border-zinc-700 light:border-slate-300 rounded-lg p-3.5 w-[226px] flex flex-col gap-1.5 shadow-lg",children:[e.jsx(Vs,{}),e.jsx(Fs,{onClose:()=>r(!1)})]})]})}async function Ds(n,t,r){if((n.chatProvider??(t==null?void 0:t.LLMProvider))!=="anythingllm-router")return n.chatModel??(t==null?void 0:t.LLMModel)??"";const o=n.router_id||(t==null?void 0:t.ModelRouterId);if(!o)return r("model-router.metrics.model-router-default");const{router:i}=await Xt.get(o);return i!=null&&i.name?i.name:r("model-router.metrics.model-router-default")}async function Qt(n,t,r){if(!n)return;const[a,o]=await Promise.all([Y.bySlug(n),ne.keys()]);t(await Ds(a,o,r))}function bi({workspaceSlug:n=null}){var z;const{t}=K(),{slug:r}=De(),a=r??n,{user:o}=fe(),[i,s]=u.useState(!1),[c,d]=u.useState(""),{isOpen:g,openModal:w,closeModal:m}=Ve(),[v,f]=u.useState({settings:{},provider:null}),[b,L]=u.useState(0),[M,P]=u.useState(()=>window.localStorage.getItem("anythingllm_sidebar_toggle")!=="closed");return u.useEffect(()=>{const D=k=>P(k.detail.open);return window.addEventListener(kt,D),()=>window.removeEventListener(kt,D)},[]),u.useEffect(()=>{Qt(a,d,t)},[a]),u.useEffect(()=>{function D(){s(!1),Qt(a,d,t)}return window.addEventListener(Ye,D),()=>window.removeEventListener(Ye,D)},[a]),u.useEffect(()=>{function D(k){const{provider:T,settings:_}=k.detail;f({settings:_,provider:T}),setTimeout(()=>w(),300)}return window.addEventListener(Ge,D),()=>window.removeEventListener(Ge,D)},[]),o&&o.role!=="admin"||!a||ir?null:e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>s(!1)}),e.jsxs("div",{className:`hidden md:block absolute top-2 z-30 transition-all duration-500 ${M?"left-3":"left-11"}`,children:[e.jsx("button",{type:"button",onClick:()=>s(!i),className:`group border-none cursor-pointer px-2.5 py-1 flex items-center rounded-full transition-all ${i?"bg-zinc-700 light:bg-slate-200":"hover:bg-zinc-700 light:hover:bg-slate-200"}`,children:e.jsx("span",{className:`text-xs ${i?"text-white light:text-slate-800":"text-zinc-500 light:text-slate-500 group-hover:text-white light:group-hover:text-slate-800"}`,children:c||t("chat_window.select_model")})}),i&&e.jsx("div",{className:"absolute left-0 top-full mt-1 bg-zinc-800 light:bg-white border border-zinc-700 light:border-slate-300 rounded-xl shadow-lg w-[620px] overflow-hidden",children:e.jsx(_a,{workspaceSlug:a,initialProvider:(z=v.provider)==null?void 0:z.value},b)})]}),e.jsx(Ma,{isOpen:g,closeModal:m,postSubmit:()=>{m(),L(D=>D+1)},settings:v.settings,llmProvider:v.provider})]})}function vi(){const{t:n}=K();return e.jsxs(e.Fragment,{children:[e.jsx(G,{id:"message-to-speech",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"regenerate-assistant-text",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"copy-assistant-text",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"feedback-button",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"action-menu",place:"top",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"edit-input-text",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"metrics-visibility",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"routing-details",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"expand-cot",place:"bottom",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"cot-thinking",place:"bottom",delayShow:500,className:"tooltip !text-xs"}),e.jsx(G,{id:"query-refusal-info",place:"top",delayShow:500,className:"tooltip !text-xs max-w-[350px]"}),e.jsx(G,{id:"context-window-limit-exceeded",place:"top",delayShow:500,className:"tooltip !text-xs max-w-[350px]"}),e.jsx(G,{id:"attachment-status-tooltip",place:"top",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"attach-item-btn",place:"top",delayShow:300,className:"tooltip !text-xs"}),e.jsx(G,{id:"agent-skill-disabled-tooltip",place:"top",delayShow:300,className:"tooltip !text-xs z-99",content:n("chat_window.agent_skills_disabled_in_session")}),e.jsx(Hs,{})]})}function Hs(){return Fe.createPortal(e.jsx(e.Fragment,{children:e.jsx(G,{id:"similarity-score",place:"top",delayShow:100,className:"tooltip !text-xs z-[100]"})}),document.body)}const be={forWorkspace:async function(n){return await fetch(`${ge}/workspaces/${n}/memories`,{method:"GET",headers:xe()}).then(t=>t.json()).then(t=>(t==null?void 0:t.memories)||{global:[],workspace:[]}).catch(()=>({global:[],workspace:[]}))},create:async function(n,{content:t,scope:r="workspace"}){return await fetch(`${ge}/workspaces/${n}/memories`,{method:"POST",headers:xe(),body:JSON.stringify({content:t,scope:r})}).then(a=>a.json()).catch(a=>({memory:null,error:a.message}))},update:async function(n,{content:t}){return await fetch(`${ge}/memories/${n}`,{method:"PUT",headers:xe(),body:JSON.stringify({content:t})}).then(r=>r.json()).catch(r=>({memory:null,error:r.message}))},delete:async function(n){return await fetch(`${ge}/memories/${n}`,{method:"DELETE",headers:xe()}).then(t=>t.json()).catch(t=>({success:!1,error:t.message}))},promoteToGlobal:async function(n){return await fetch(`${ge}/memories/${n}/promote`,{method:"POST",headers:xe()}).then(t=>t.json()).catch(t=>({memory:null,error:t.message}))},demoteToWorkspace:async function(n,t){return await fetch(`${ge}/memories/${n}/demote/${t}`,{method:"POST",headers:xe()}).then(r=>r.json()).catch(r=>({memory:null,error:r.message}))}},ve={workspace:20,global:5},yn=u.createContext(null);function ce(){const n=u.useContext(yn);if(!n)throw new Error("useMemoriesContext must be used within MemoriesProvider");return n}function $s({workspace:n,children:t}){const{sidebarOpen:r,closeSidebar:a}=wn(),{user:o}=fe(),i=!o||(o==null?void 0:o.role)==="admin",[s,c]=u.useState({global:[],workspace:[]}),[d,g]=u.useState("workspace"),[w,m]=u.useState({open:!1,mode:"create"}),[v,f]=u.useState(null),[b,L]=u.useState(!1),[M,P]=u.useState(!0),[z,D]=u.useState(!0);u.useEffect(()=>{r&&ne.keys().then(S=>{L(!!(S!=null&&S.MemoryEnabled)),P((S==null?void 0:S.MemoryAutoExtraction)!==!1),D(!1)})},[r]);async function k(){if(!(n!=null&&n.slug))return;const S=await be.forWorkspace(n.slug);c(S)}u.useEffect(()=>{r&&b&&k()},[r,n==null?void 0:n.slug,b]);async function T(S){const{memory:E}=await be.create(n.slug,{content:S,scope:d});E&&k()}async function _(S){await be.delete(S),k()}async function I(S,E){const{memory:N}=await be.update(S,{content:E});N&&k()}async function Z(S){const{memory:E}=await be.promoteToGlobal(S);E&&k()}async function B(S){if(!(n!=null&&n.slug))return;const{memory:E}=await be.demoteToWorkspace(S,n.slug);E&&k()}function U(){f(null),m({open:!0,mode:"create"})}function H(S){f(S),m({open:!0,mode:"edit"})}function j(){m({open:!1,mode:"create"}),f(null)}const y=d==="workspace"?s.workspace:s.global,C={workspace:n,sidebarOpen:r,closeSidebar:a,canToggle:i,memories:s,activeTab:d,setActiveTab:g,activeMemories:y,enabled:b,setEnabled:L,autoExtraction:M,setAutoExtraction:P,loadingEnabled:z,modalState:w,editingMemory:v,openCreateModal:U,openEditModal:H,closeModal:j,handleCreate:T,handleDelete:_,handleUpdate:I,handlePromote:Z,handleDemote:B};return e.jsx(yn.Provider,{value:C,children:t})}function Bs(){const{canToggle:n,enabled:t,setEnabled:r,autoExtraction:a,setAutoExtraction:o,loadingEnabled:i}=ce(),{t:s}=K();async function c(g){const w=g?"true":"false",{success:m}=await we.updateSystemPreferences({memory_enabled:w});m&&r(g)}async function d(g){const w=g?"true":"false",{success:m}=await we.updateSystemPreferences({memory_auto_extraction:w});m&&o(g)}return!n||i?null:e.jsxs("div",{className:"shrink-0 bg-zinc-900 light:bg-white light:border light:border-slate-300 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-zinc-50 light:text-slate-900",children:s("chat_window.memories.toggle.label")}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500",children:s("chat_window.memories.toggle.description")})]}),e.jsx(Qe,{size:"md",enabled:t,onChange:c})]}),t&&e.jsxs("div",{className:"flex items-start gap-3 pt-2 border-t border-zinc-800 light:border-slate-200",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-zinc-50 light:text-slate-900",children:s("chat_window.memories.auto_extraction.label")}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500",children:s("chat_window.memories.auto_extraction.description")})]}),e.jsx(Qe,{size:"md",enabled:a,onChange:d})]})]})}function Jt(){const{workspace:n,activeTab:t,setActiveTab:r,memories:a,openCreateModal:o}=ce(),{t:i}=K(),s=(n==null?void 0:n.name)||i("chat_window.memories.tab_workspace"),c=a.workspace.length,d=a.global.length,g=t==="workspace"?c>=ve.workspace:d>=ve.global;return e.jsxs("div",{className:"flex items-center justify-between shrink-0 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>r("workspace"),"data-tooltip-id":"memories-workspace-pill","data-tooltip-content":s,className:`flex items-center gap-0.5 h-6 px-3 rounded-full border-none cursor-pointer text-xs font-medium uppercase tracking-[1.2px] whitespace-nowrap transition-colors min-w-0 shrink ${t==="workspace"?"bg-zinc-800 light:bg-slate-300":"bg-transparent hover:bg-zinc-800/50 light:hover:bg-slate-200"}`,children:[e.jsx("span",{className:"text-zinc-200 light:text-slate-800 truncate max-w-[140px]",children:s}),e.jsxs("span",{className:"text-zinc-400 light:text-slate-600 font-normal",children:["(",c,"/",ve.workspace,")"]})]}),e.jsxs("button",{type:"button",onClick:()=>r("global"),className:`flex items-center gap-0.5 h-6 px-3 rounded-full border-none cursor-pointer text-xs font-medium uppercase tracking-[1.2px] whitespace-nowrap transition-colors shrink-0 ${t==="global"?"bg-zinc-800 light:bg-slate-300":"bg-transparent hover:bg-zinc-800/50 light:hover:bg-slate-200"}`,children:[e.jsx("span",{className:"text-zinc-200 light:text-slate-800",children:i("chat_window.memories.tab_global")}),e.jsxs("span",{className:"text-zinc-400 light:text-slate-600 font-normal",children:["(",d,"/",ve.global,")"]})]})]}),e.jsx("button",{type:"button",onClick:o,disabled:g,className:"-mr-1 flex items-center justify-center size-6 rounded-lg border-none bg-transparent cursor-pointer text-zinc-50 light:text-slate-900 hover:bg-zinc-800 light:hover:bg-slate-200 transition-colors disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:e.jsx(et,{size:16,weight:"bold"})}),e.jsx(G,{id:"memories-workspace-pill",place:"bottom",delayShow:800,className:"tooltip !text-xs z-99"})]})}function Us({menuRef:n,buttonRef:t,isWorkspace:r,canMove:a,onEdit:o,onMove:i,onDelete:s}){const{t:c}=K(),[d,g]=u.useState({top:0,left:0});return u.useEffect(()=>{if(!t.current)return;const w=t.current.getBoundingClientRect();g({top:w.bottom+4,left:w.right-200})},[]),Fe.createPortal(e.jsxs("div",{ref:n,className:"fixed z-[9999] bg-zinc-800 light:bg-slate-50 border border-zinc-700 light:border-slate-300 rounded-lg py-3 px-2 flex flex-col shadow-lg w-[175px]",style:{top:d.top,left:d.left},children:[e.jsx(qe,{label:c("chat_window.memories.menu.edit"),onClick:o}),a&&e.jsx(qe,{label:c(r?"chat_window.memories.menu.move_to_global":"chat_window.memories.menu.move_to_workspace"),onClick:i}),e.jsx(qe,{label:c("chat_window.memories.menu.delete"),onClick:s})]}),document.body)}function qe({label:n,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:"w-full text-left text-sm font-medium text-zinc-50 light:text-slate-800 border-none bg-transparent cursor-pointer hover:bg-zinc-700 light:hover:bg-slate-200 rounded px-2.5 py-1 transition-colors",children:n})}function Ws({memory:n}){const{activeTab:t,memories:r,handleDelete:a,openEditModal:o,handlePromote:i,handleDemote:s}=ce(),[c,d]=u.useState(!1),g=u.useRef(null),w=u.useRef(null);u.useEffect(()=>{if(!c)return;function f(b){g.current&&!g.current.contains(b.target)&&w.current&&!w.current.contains(b.target)&&d(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[c]);const m=t==="workspace",v=m?r.global.length<ve.global:r.workspace.length<ve.workspace;return e.jsxs("div",{className:"relative shrink-0 bg-zinc-900 light:bg-white light:border light:border-slate-300 rounded-lg p-3 flex gap-0.5 items-start",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm leading-5 text-zinc-50 light:text-slate-900",children:n.content}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500 mt-1.5",children:new Date(n.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})]}),e.jsx("button",{ref:w,type:"button",onClick:()=>d(!c),className:"shrink-0 border-none bg-transparent cursor-pointer text-zinc-400 light:text-slate-400 hover:text-zinc-50 light:hover:text-slate-900 transition-colors p-0",children:e.jsx(or,{size:20,weight:"bold"})}),c&&e.jsx(Us,{menuRef:g,buttonRef:w,isWorkspace:m,canMove:v,onEdit:()=>{d(!1),o(n)},onMove:()=>{d(!1),m?i(n.id):s(n.id)},onDelete:()=>{d(!1),a(n.id)}})]})}function Ks({isOpen:n,onClose:t,onSubmit:r,initialContent:a="",mode:o="create"}){const{t:i}=K(),[s,c]=u.useState(a),d=o==="create",[g,w,m]=u.useMemo(()=>d?[i("chat_window.memories.modal.create_title"),i("chat_window.memories.modal.create"),i("chat_window.memories.modal.create_description")]:[i("chat_window.memories.modal.edit_title"),i("chat_window.memories.modal.save"),i("chat_window.memories.modal.edit_description")],[d,i]);u.useEffect(()=>{n&&c(a)},[n,a]);function v(){s.trim()&&(r(s.trim()),t())}return e.jsx(ye,{isOpen:n,children:e.jsxs("div",{className:"bg-zinc-900 light:bg-white border border-zinc-800 light:border-slate-300 rounded-lg p-6 w-[400px] flex flex-col gap-5",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("p",{className:"font-semibold text-base leading-6 text-zinc-50 light:text-slate-800",children:g}),e.jsx("button",{onClick:t,type:"button",className:"text-zinc-400 light:text-slate-400 hover:text-zinc-50 light:hover:text-slate-900 transition-colors border-none bg-transparent cursor-pointer",children:e.jsx(oe,{size:16,weight:"bold"})})]}),e.jsx("p",{className:"text-xs leading-4 text-zinc-400 light:text-slate-500",children:m})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-zinc-200 light:text-slate-700",children:i("chat_window.memories.modal.label")}),e.jsx("textarea",{autoFocus:!0,onFocus:f=>{const b=f.currentTarget.value.length;f.currentTarget.setSelectionRange(b,b)},value:s,onChange:f=>c(f.target.value),placeholder:i("chat_window.memories.modal.placeholder"),rows:4,className:"w-full bg-zinc-800 light:bg-white text-zinc-50 light:border light:border-slate-300 light:text-slate-700 placeholder:text-zinc-500 light:placeholder:text-slate-400 text-sm rounded-lg p-3 resize-none outline-none focus:border-zinc-500 light:focus:border-slate-400"})]}),e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("button",{type:"button",onClick:t,className:"h-9 px-5 rounded-lg border border-zinc-500 light:border-slate-600 bg-transparent text-zinc-50 light:text-slate-900 text-sm font-medium cursor-pointer hover:bg-zinc-700 light:hover:bg-slate-100 transition-colors",children:i("chat_window.memories.modal.cancel")}),e.jsx("button",{type:"button",onClick:v,disabled:!s.trim(),className:"h-9 px-5 rounded-lg border-none bg-zinc-50 light:bg-slate-900 text-zinc-900 light:text-white text-sm font-medium cursor-pointer hover:bg-white light:hover:bg-slate-800 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:w})]})]})})}function wi({workspace:n}){return e.jsx($s,{workspace:n,children:e.jsx(qs,{})})}function qs(){const{sidebarOpen:n,canToggle:t,enabled:r}=ce(),a=He("memories");return!t&&!r||!a.enabled?null:e.jsxs(e.Fragment,{children:[e.jsx(Zs,{isOpen:n,children:e.jsxs(Gs,{children:[e.jsx(Js,{}),e.jsx(Bs,{}),e.jsx(Ys,{})]})}),e.jsx(Qs,{})]})}function Gs({children:n}){return e.jsx("div",{className:"w-[366px] flex-shrink-0 flex flex-col gap-5 mt-[72px] px-5 overflow-y-auto no-scroll",style:{maxHeight:"calc(100% - 88px)"},children:n})}function Ys(){const{enabled:n,activeMemories:t}=ce();return n?t.length===0?e.jsxs(e.Fragment,{children:[e.jsx(Jt,{}),e.jsx(Xs,{})]}):e.jsxs(e.Fragment,{children:[e.jsx(Jt,{}),e.jsx("div",{className:"flex flex-col gap-1.5 pb-4",children:t.map(r=>e.jsx(Ws,{memory:r},r.id))})]}):null}function Qs(){const{enabled:n,modalState:t,editingMemory:r,closeModal:a,handleCreate:o,handleUpdate:i}=ce();return n?e.jsx(Ks,{isOpen:t.open,mode:t.mode,initialContent:(r==null?void 0:r.content)||"",onClose:a,onSubmit:s=>{t.mode==="edit"&&r?i(r.id,s):o(s)}}):null}function Js(){const{t:n}=K(),{closeSidebar:t}=ce();return e.jsxs("div",{className:"flex items-start justify-between shrink-0",children:[e.jsx("p",{className:"font-medium text-base leading-6 text-zinc-50 light:text-slate-900",children:n("chat_window.memories.title")}),e.jsx("button",{onClick:t,type:"button",className:"text-zinc-50 light:text-slate-900 hover:text-white light:hover:text-slate-400 transition-colors border-none bg-transparent cursor-pointer",children:e.jsx(oe,{size:16,weight:"bold"})})]})}function Xs(){const{t:n}=K(),{openCreateModal:t}=ce();return e.jsxs("p",{className:"text-sm leading-5 text-zinc-400 light:text-slate-600 text-center",children:[n("chat_window.memories.empty")," ",e.jsx("button",{type:"button",onClick:t,className:"text-zinc-50 light:text-slate-900 underline border-none bg-transparent cursor-pointer p-0 text-sm leading-5 font-normal",children:n("chat_window.memories.empty_cta")})]})}export{fs as A,gi as C,oi as D,wi as M,Ie as P,pi as Q,fi as S,bi as W,gn as a,Le as b,xi as c,li as d,mi as e,vi as f,Cs as g,ss as h,Zs as i,ci as j,Bt as k,tt as l,Ut as m,di as n,ps as o,hi as s,Is as u,ui as w};