teodor-new-chat-ui 3.0.80 → 3.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -7090,7 +7090,7 @@ function qr({ content: e, className: t = "", fallback: n = /* @__PURE__ */ l.jsx
7090
7090
  return p.forEach((v) => m.observe(v)), () => {
7091
7091
  x = !0, m.disconnect();
7092
7092
  };
7093
- }, [c]), c ? /* @__PURE__ */ l.jsx("div", { ref: d, className: D("markdown prose max-w-none break-words dark:prose-invert", t), dangerouslySetInnerHTML: { __html: c } }) : r && o ? /* @__PURE__ */ l.jsx("div", { className: D("markdown prose max-w-none break-words dark:prose-invert", t) }) : /* @__PURE__ */ l.jsx("div", { className: D("markdown prose max-w-none break-words dark:prose-invert", t), children: n });
7093
+ }, [c]), c ? /* @__PURE__ */ l.jsx("div", { ref: d, className: D("markdown prose max-w-none break-words dark:prose-invert", t), dangerouslySetInnerHTML: { __html: c } }) : r && o ? null : /* @__PURE__ */ l.jsx("div", { className: D("markdown prose max-w-none break-words dark:prose-invert", t), children: n });
7094
7094
  }
7095
7095
  async function Ou(e, t) {
7096
7096
  return await _t(e, {
@@ -8597,7 +8597,7 @@ const jw = K.memo(function({
8597
8597
  if (z && C && !d) {
8598
8598
  const xe = Hw(t.content);
8599
8599
  if (xe && kw(xe))
8600
- return /* @__PURE__ */ l.jsx(qr, { content: xe.trim() });
8600
+ return /* @__PURE__ */ l.jsx(qr, { content: xe.trim(), hideFallbackDuringStreaming: !0 });
8601
8601
  const $ = zn(t.content);
8602
8602
  return /* @__PURE__ */ l.jsx("div", { className: "font-mono text-sm text-current", children: /* @__PURE__ */ l.jsx("pre", { className: D("whitespace-pre-wrap break-words text-current", O && "text-xs"), children: $ }) });
8603
8603
  }
package/dist/index.umd.js CHANGED
@@ -30,7 +30,7 @@ Check the top-level render call using <`+ue+">.")}return J}}function Hu(A,J){{if
30
30
  `+i):r.stack=i}catch{}}throw r}}_request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=Mn(this.defaults,n);const{transitional:r,paramsSerializer:a,headers:i}=n;r!==void 0&&Ea.assertOptions(r,{silentJSONParsing:jt.transitional(jt.boolean),forcedJSONParsing:jt.transitional(jt.boolean),clarifyTimeoutError:jt.transitional(jt.boolean)},!1),a!=null&&(B.isFunction(a)?n.paramsSerializer={serialize:a}:Ea.assertOptions(a,{encode:jt.function,serialize:jt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Ea.assertOptions(n,{baseUrl:jt.spelling("baseURL"),withXsrfToken:jt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=i&&B.merge(i.common,i[n.method]);i&&B.forEach(["delete","get","head","post","put","patch","common"],E=>{delete i[E]}),n.headers=Rt.concat(o,i);const s=[];let l=!0;this.interceptors.request.forEach(function(f){typeof f.runWhen=="function"&&f.runWhen(n)===!1||(l=l&&f.synchronous,s.unshift(f.fulfilled,f.rejected))});const c=[];this.interceptors.response.forEach(function(f){c.push(f.fulfilled,f.rejected)});let d,_=0,p;if(!l){const E=[D_.bind(this),void 0];for(E.unshift(...s),E.push(...c),p=E.length,d=Promise.resolve(n);_<p;)d=d.then(E[_++],E[_++]);return d}p=s.length;let m=n;for(;_<p;){const E=s[_++],f=s[_++];try{m=E(m)}catch(g){f.call(this,g);break}}try{d=D_.call(this,m)}catch(E){return Promise.reject(E)}for(_=0,p=c.length;_<p;)d=d.then(c[_++],c[_++]);return d}getUri(e){e=Mn(this.defaults,e);const n=T_(e.baseURL,e.url,e.allowAbsoluteUrls);return u_(n,e.params,e.paramsSerializer)}};B.forEach(["delete","get","head","options"],function(e){Ln.prototype[e]=function(n,r){return this.request(Mn(r||{},{method:e,url:n,data:(r||{}).data}))}}),B.forEach(["post","put","patch"],function(e){function n(r){return function(i,o,s){return this.request(Mn(s||{},{method:e,headers:r?{"Content-Type":"multipart/form-data"}:{},url:i,data:o}))}}Ln.prototype[e]=n(),Ln.prototype[e+"Form"]=n(!0)});let Ov=class tC{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(i){n=i});const r=this;this.promise.then(a=>{if(!r._listeners)return;let i=r._listeners.length;for(;i-- >0;)r._listeners[i](a);r._listeners=null}),this.promise.then=a=>{let i;const o=new Promise(s=>{r.subscribe(s),i=s}).then(a);return o.cancel=function(){r.unsubscribe(i)},o},e(function(i,o,s){r.reason||(r.reason=new Zn(i,o,s),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const e=new AbortController,n=r=>{e.abort(r)};return this.subscribe(n),e.signal.unsubscribe=()=>this.unsubscribe(n),e.signal}static source(){let e;return{token:new tC(function(a){e=a}),cancel:e}}};function yv(t){return function(n){return t.apply(null,n)}}function Iv(t){return B.isObject(t)&&t.isAxiosError===!0}const io={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(io).forEach(([t,e])=>{io[e]=t});function L_(t){const e=new Ln(t),n=ju(Ln.prototype.request,e);return B.extend(n,Ln.prototype,e,{allOwnKeys:!0}),B.extend(n,e,null,{allOwnKeys:!0}),n.create=function(a){return L_(Mn(t,a))},n}const st=L_(Nr);st.Axios=Ln,st.CanceledError=Zn,st.CancelToken=Ov,st.isCancel=E_,st.VERSION=w_,st.toFormData=ua,st.AxiosError=De,st.Cancel=st.CanceledError,st.all=function(e){return Promise.all(e)},st.spread=yv,st.isAxiosError=Iv,st.mergeConfig=Mn,st.AxiosHeaders=Rt,st.formToJSON=t=>m_(B.isHTMLForm(t)?new FormData(t):t),st.getAdapter=x_.getAdapter,st.HttpStatusCode=io,st.default=st;const{Axios:M0,AxiosError:L0,CanceledError:P0,isCancel:k0,CancelToken:U0,VERSION:F0,all:B0,Cancel:G0,isAxiosError:Y0,spread:H0,toFormData:q0,AxiosHeaders:V0,HttpStatusCode:z0,formToJSON:$0,getAdapter:W0,mergeConfig:K0}=st,P_=typeof window<"u"?window.__API_BASE_URL__:void 0,oo=P_?P_.replace(/\/+$/,""):void 0;!oo&&typeof window<"u"&&console.warn("API base URL is not configured. The API client will need to be configured via apiConfig prop or window.__API_BASE_URL__.");let fa=null;const so=new Set;function k_(){return fa}function lo(t){fa=t,so.forEach(e=>e(t))}function U_(t){return so.add(t),()=>so.delete(t)}const wt=st.create({...oo?{baseURL:oo}:{},timeout:3e4,withCredentials:!0});wt.interceptors.request.use(t=>(fa&&(t.headers.Authorization=`Bearer ${fa}`),t)),wt.interceptors.response.use(t=>t,t=>Promise.reject(t));async function Mt(t,e){return wt.defaults.baseURL?(await wt.get(t,e)).data:Promise.reject(new Error("API base URL is not configured"))}async function F_(t,e,n){return wt.defaults.baseURL?(await wt.post(t,e,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function B_(t,e,n){return wt.defaults.baseURL?(await wt.put(t,e,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function G_(t,e){return wt.defaults.baseURL?(await wt.delete(t,e)).data:Promise.reject(new Error("API base URL is not configured"))}function Lt(t){return t&&typeof t=="object"&&"data"in t?t.data:t}class Sa{get baseUrl(){const e=wt.defaults.baseURL||"";return String(e).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(e){e.baseUrl&&(wt.defaults.baseURL=String(e.baseUrl).replace(/\/+$/g,"")),e.authToken!==void 0&&lo(e.authToken)}getAuthToken(){return k_()}setAuthToken(e){lo(e)}onTokenChange(e){return U_(e)}async listThreads(){const e=await Mt("/chat/threads"),n=Lt(e);return(n==null?void 0:n.items)??(e==null?void 0:e.items)??[]}async createThread(e){const r=await F_("/chat/threads",e?{title:e}:void 0);return Lt(r)}async updateThread(e,n){const r=await B_(`/chat/threads/${e}`,{title:n});return Lt(r)}async deleteThread(e){const n=await G_(`/chat/threads/${e}`);return Lt(n)}async threadInfo(e){const n=await Mt(`/chat/threads/${e}/info`);return Lt(n)}async listAgents(){const e=await Mt("/chat/agents"),n=Lt(e);return(n==null?void 0:n.items)??[]}async getAgent(e){const n=await Mt(`/chat/agents/${e}`);return Lt(n)}async getAgentSchema(e){const n=await Mt(`/chat/agents/${e}/schema`);return Lt(n)}async getMessages(e){const n=await Mt(`/chat/threads/${e.threadId}/messages`,{params:{thread_id:e.threadId,checkpoint_id:e.checkpointId,checkpoint_ns:e.checkpointNs,limit:e.limit,before_id:e.beforeId??void 0}});return Lt(n)}async getState(e){const n=await Mt(`/chat/threads/${e.threadId}/state`,{params:{thread_id:e.threadId,checkpoint_id:e.checkpointId,checkpoint_ns:e.checkpointNs}});return Lt(n)}async getStateHistory(e){const n=await Mt(`/chat/threads/${e.threadId}/state/history`,{params:{thread_id:e.threadId,checkpoint_id:e.checkpointId,checkpoint_ns:e.checkpointNs}});return Lt(n)}async listCheckpoints(e){const n=await Mt(`/chat/threads/${e}/checkpoints`,{params:{thread_id:e}});return Lt(n)}}const cn=new Sa;function Y_(t={}){const e=t.baseUrl??"/api/chat",n=t.streamPath??"/runs/stream",[r,a]=y.useState(t.token??null),i=y.useRef(t.headers??{}),[o,s]=y.useState(!1),[l,c]=y.useState(null),[d,_]=y.useState(""),[p,m]=y.useState(null),E=y.useRef(null),f=y.useCallback(h=>{a(h)},[]),g=y.useCallback(()=>{var h;(h=E.current)==null||h.abort(),E.current=null,s(!1)},[]),S=y.useCallback(()=>{_(""),m(null),c(null)},[]),b=y.useCallback((h,N,R)=>{E.current&&(E.current.abort(),E.current=null),s(!0),c(null),t.autoAppendAssistant!==!1&&_("");const C=new AbortController;return E.current=C,(async()=>{var x,w,L,H,z;const v=(()=>{var P;try{return typeof window<"u"&&((P=window.localStorage)==null?void 0:P.getItem("chat-debug"))==="1"}catch{return!1}})(),O=P=>{var G;try{const I=JSON.parse(JSON.stringify(P));return(G=I==null?void 0:I.payload)!=null&&G.files_info&&Array.isArray(I.payload.files_info)&&(I.payload.files_info=I.payload.files_info.map(U=>({...U,data:U!=null&&U.data?`<base64 ${String(U.data).length} chars>`:U==null?void 0:U.data}))),I}catch{return P}};try{let P={};try{if(r)P={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Y=window.__AUTH_TOKEN__,W=((x=window.localStorage)==null?void 0:x.getItem("authToken"))||null;let re=null;try{const X=(w=window.localStorage)==null?void 0:w.getItem("chat-settings");X&&(re=((L=JSON.parse(X))==null?void 0:L.apiKey)||null)}catch{}const q=Y||W||re||null;q&&(P={Authorization:`Bearer ${q}`})}}catch{}v&&console.debug("[use-chat] POST",e+n,O(h));const G=await fetch(e+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...P,...i.current},body:JSON.stringify(h),signal:C.signal});if(!G.ok||!G.body){const k=await G.text().catch(()=>"");throw v&&console.debug("[use-chat] non-OK response",G.status,k==null?void 0:k.slice(0,500)),new Error(`stream ${G.status}${k?": "+k:""}`)}try{const k=G.headers.get("X-Thread-Id")||G.headers.get("x-thread-id"),Y=G.headers.get("X-Thread-Created")||G.headers.get("x-thread-created"),W=k??null,re=String(Y??"").toLowerCase()==="true";try{(H=R==null?void 0:R.onOpen)==null||H.call(R,{threadId:W,created:re})}catch(q){v&&console.debug("[use-chat] onOpen handler threw:",q)}}catch(k){v&&console.debug("[use-chat] failed to read headers:",k)}const I=G.body.getReader(),U=new TextDecoder;let M="";for(;;){const{value:k,done:Y}=await I.read();if(Y)break;M+=U.decode(k,{stream:!0});let W;for(;(W=M.indexOf(`
31
31
 
32
32
  `))>=0;){const re=M.slice(0,W);M=M.slice(W+2);const q=xv(re);if(!q)continue;let X;try{X=JSON.parse(q)}catch{v&&console.debug("[use-chat] skip malformed SSE data:",q==null?void 0:q.slice(0,200));continue}const ce=Av(X)?X.data:X;if(v&&console.debug("[use-chat] event:",ce==null?void 0:ce.type,ce),N==null||N(ce),ce.type==="token")t.autoAppendAssistant!==!1&&_(ge=>ge+ce.content);else if(ce.type==="message_delta"){const ge=ce.delta.filter(V=>V.type==="text").map(V=>V.text).join("");ge&&t.autoAppendAssistant!==!1&&_(V=>V+ge)}else ce.type==="checkpoint"?m(ce.checkpointId):ce.type==="error"&&c(ce.message)}}}catch(P){if((P==null?void 0:P.name)==="AbortError")return;const G=(P==null?void 0:P.message)||String(P);v&&console.debug("[use-chat] error:",G),c(G),(z=R==null?void 0:R.onError)==null||z.call(R,G)}finally{s(!1),E.current=null}})(),{close:()=>C.abort()}},[e,r,t.autoAppendAssistant]);return y.useEffect(()=>()=>{var h;return(h=E.current)==null?void 0:h.abort()},[]),{isStreaming:o,error:l,assistantText:d,lastCheckpointId:p,stream:b,stop:g,clear:S,setToken:f}}function Av(t){return!!t&&typeof t=="object"&&t.protocolVersion==="v1"&&"data"in t}function xv(t){const e=t.split(/\r?\n/),n=[];for(const r of e)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const a=r.slice(5);n.push(a.startsWith(" ")?a.slice(1):a)}return n.length===0?null:n.join(`
33
- `)}const Dv={messages:[],assemblingId:null,lastCheckpointId:null,toolIndex:{},lastBranch:null};function wv(t,e){var n;switch(e.type){case"reset":return{messages:co(((n=e.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,toolIndex:{},lastBranch:null};case"seed":return{...t,messages:co(e.payload.messages)};case"prepend":{const r=co(e.payload.messages);if(!r.length)return t;const a=new Set(t.messages.map(o=>o.id)),i=r.filter(o=>!a.has(o.id));return i.length?{...t,messages:[...i,...t.messages]}:t}case"user_message":{const r=e.payload.message;if(t.assemblingId){const a=t.messages.findIndex(i=>i.id===t.assemblingId&&i.role==="assistant");if(a>=0){const i=t.messages.slice(0,a),o=t.messages.slice(a);return{...t,messages:[...i,r,...o]}}}return{...t,messages:[...t.messages,r]}}case"event":return q_(t,e.payload.ev);case"batch":{const{events:r}=e.payload;return r.length?r.reduce((a,i)=>q_(a,i),t):t}default:return t}}function H_(t=[]){const[e,n]=y.useReducer(wv,{...Dv,messages:t}),r=y.useRef([]),a=y.useRef(null),i=y.useRef(null),o=y.useCallback(()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),a.current=null,i.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),s=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?a.current===null&&(a.current=window.requestAnimationFrame(()=>o())):i.current===null&&(i.current=setTimeout(o,16))},[o]),l=y.useCallback(d=>{r.current.push(d),s()},[s]);y.useEffect(()=>()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),r.current=[]},[]);const c=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:d=>n({type:"seed",payload:{messages:d}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:e,dispatch:n,...c}}function q_(t,e){var n;if(e.type==="message_start"&&e.role==="assistant"){const r=e.id,a=kv(e.model),i={id:r,role:"assistant",name:a||void 0,model:e.model,createdAt:new Date().toISOString(),content:[]};return{...t,assemblingId:r,messages:[...t.messages,i]}}if(e.type==="token"){const r=t.assemblingId??uo(t.messages);return r?{...t,messages:Mv(t.messages,r,e.content)}:t}if(e.type==="message_delta"){const r=t.assemblingId??uo(t.messages);return r?{...t,messages:V_(t.messages,r,e.delta)}:t}if(e.type==="message_end"){const r=t.assemblingId??uo(t.messages);if(!r)return{...t,assemblingId:null};const a=t.messages,i=a.findIndex(o=>o.id===r&&o.role==="assistant");if(i>=0&&!((n=a[i].content)==null?void 0:n.some(l=>{var c;return(l==null?void 0:l.type)==="text"&&((c=l.text)==null?void 0:c.trim())}))){const l=[...a.slice(0,i),...a.slice(i+1)];return{...t,assemblingId:null,messages:l}}return{...t,assemblingId:null}}if(e.type==="tool_start"){const r=`tool-${e.id}`,a={type:"tool_call",id:e.id,name:e.name,args:e.args},i={id:r,role:"tool",name:e.name,createdAt:new Date().toISOString(),content:[a]};return{...t,messages:[...t.messages,i],toolIndex:{...t.toolIndex,[e.id]:r}}}if(e.type==="tool_result"){const r=t.toolIndex[e.id]??`tool-${e.id}`,a={type:"tool_result",toolCallId:e.id,output:e.output,error:e.error},i=t.messages.find(l=>l.id===r),o={id:r,role:"tool",content:[a],createdAt:new Date().toISOString()},s=i?V_(t.messages,r,[a]):[...t.messages,o];return{...t,messages:s}}if(e.type==="checkpoint"){const r=Pv(t.messages,e.checkpointId);return{...t,lastCheckpointId:e.checkpointId,messages:r}}if(e.type==="branch"){const r=e.checkpointId??t.lastCheckpointId;return{...t,lastBranch:e,lastCheckpointId:r??null}}if(e.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${e.message}`}],createdAt:new Date().toISOString()};return{...t,messages:[...t.messages,r]}}return t}function co(t){return t.filter(e=>{if(e.role!=="assistant")return!0;const n=(e.content||[]).some(a=>{var i;return a&&a.type==="text"&&((i=a.text)==null?void 0:i.trim())}),r=(e.content||[]).some(a=>a&&a.type==="image_url");return!!(n||r)})}function uo(t){for(let e=t.length-1;e>=0;e--)if(t[e].role==="assistant")return t[e].id;return null}function Mv(t,e,n){return t.map(r=>{if(r.id!==e)return r;const a=r.content.slice(),i=a[a.length-1];return i&&i.type==="text"?i.text+=n:a.push({type:"text",text:n}),{...r,content:a}})}function V_(t,e,n){return t.map(r=>r.id===e?{...r,content:Lv(r.content,n)}:r)}function Lv(t,e){const n=t.slice();for(const r of e)if(r.type==="text"){const a=n[n.length-1];(a==null?void 0:a.type)==="text"?a.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Pv(t,e){for(let n=t.length-1;n>=0;n--)if(t[n].role==="assistant"){const a={...t[n],checkpointId:e};return[...t.slice(0,n),a,...t.slice(n+1)]}return t}function kv(t){if(!t)return null;const e=t.split("/");return e[e.length-1]||null}function Uv(t,e){const n=t==null?void 0:t.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],a=o=>o&&typeof o=="object"&&typeof o.checkpointId=="string"&&typeof o.createdAt=="string",i=r.filter(a).map(o=>({checkpointId:o.checkpointId,checkpointNs:o.checkpointNs??"",createdAt:o.createdAt,messagesLen:o.messagesLen??0,preview:o.preview??"",role:o.role??null,parentId:o.parentId??null,editedMessageId:o.editedMessageId??null,branchLabel:o.branchLabel??null}));return{threadId:(t==null?void 0:t.threadId)??e??null,checkpoints:i}}async function _o(t){return await new Promise((e,n)=>{const r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=a=>n(a),r.readAsDataURL(t)})}async function Fv(t){return await new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{try{const a=r.result,i=new Uint8Array(a);let o="";const s=i.byteLength;for(let l=0;l<s;l++)o+=String.fromCharCode(i[l]);e(btoa(o))}catch(a){n(a)}},r.onerror=a=>n(a),r.readAsArrayBuffer(t)})}async function Bv(t,e,n){try{return await _o(e)}catch{return null}}async function Gv(t,e=[],n,r,a,i){const o=[],s=[];for(const l of e){let c=null;try{c=await Bv(t,l,i)}catch{c=null}if(l.type&&l.type.startsWith("image/"))if(c){const d={type:"image_url",url:c,mimeType:l.type,alt:l.name};o.push(d)}else try{const d=await _o(l),_={type:"image_url",url:String(d),mimeType:l.type,alt:l.name};o.push(_)}catch{}else if(c){const d={type:"file",url:c,mimeType:l.type||void 0,name:l.name,size:l.size,sourceType:"base64"};o.push(d)}else try{const d=await _o(l),_={type:"file",url:String(d),mimeType:l.type||void 0,name:l.name,size:l.size,sourceType:"base64"};o.push(_)}catch{}try{const d=await Fv(l);s.push({filename:l.name,data:d,mime_type:l.type||"application/octet-stream"})}catch{}}return{contentParts:o,filesInfo:s}}const z_=y.createContext(null);function yr({children:t,apiConfig:e,onError:n,onThreadChange:r,initialThreadId:a=null,historyPageSize:i,autoLoadInitial:o=!0,enableFileAgentRouting:s=!1,fileAgentId:l="invoice_reader"}){const c=cn;y.useEffect(()=>{e&&c.updateConfig({baseUrl:e.baseUrl,authToken:e.apiKey})},[c,e]);const{isStreaming:d,error:_,stream:p,stop:m,setToken:E}=Y_({baseUrl:c.baseUrl,token:null,headers:e==null?void 0:e.headers,streamPath:"/chat/runs/stream"}),[f,g]=y.useState(()=>typeof c.getAuthToken=="function"?c.getAuthToken():null);y.useEffect(()=>{E(typeof c.getAuthToken=="function"?c.getAuthToken():null);const Q=c.onTokenChange(ae=>{g(ae),E(ae)});return()=>{Q()}},[c,E]);const S=y.useCallback(Q=>{c.setAuthToken(Q)},[c]),{state:b,seed:h,prepend:N,pushUser:R,onEvent:C,reset:v}=H_(),O=i&&i>0?i:6,[x,w]=y.useState(!1),[L,H]=y.useState(!1),[z,P]=y.useState(null),[G,I]=y.useState(void 0),U=y.useCallback((Q,ae)=>{const be=Array.isArray(Q==null?void 0:Q.messages)?Q.messages:[];ae==="replace"?h(be):ae==="prepend"&&be.length&&N(be),P((Q==null?void 0:Q.nextCursor)??null),w(!!(Q!=null&&Q.hasMore)),I(Je=>(Q==null?void 0:Q.checkpointId)??Je??void 0)},[h,N]),[M,k]=y.useState([]),[Y,W]=y.useState(null),re=y.useCallback(async()=>{const Q=await c.listThreads();k(Q)},[c]),[q,X]=y.useState(!1),ce=y.useCallback(async Q=>{const ae=(Q==null?void 0:Q.maxAttempts)??5,be=(Q==null?void 0:Q.baseDelayMs)??500,Je=(Q==null?void 0:Q.timeoutMs)??2e3;if(!c.baseUrl)return!1;const Qe=c.baseUrl.replace(/\/+$/,""),at=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],Ke=async se=>{try{const Ee=new AbortController,he=setTimeout(()=>Ee.abort(),Je),Ue=await fetch(se,{method:"GET",signal:Ee.signal});return clearTimeout(he),Ue.ok}catch{return!1}},Z=async se=>{try{const Ee=new AbortController,he=setTimeout(()=>Ee.abort(),Je),Ue=await fetch(se,{method:"HEAD",signal:Ee.signal});return clearTimeout(he),Ue.ok}catch{return!1}};for(let se=0;se<ae;se++){console.debug(`[ChatProvider] health-check attempt ${se+1}/${ae}`);for(const he of at){let Ue=he;Qe.endsWith("/api")&&he.startsWith("/api")&&(Ue=he.replace(/^\/api/,"")||"/");const rt=Ue==="/"?Qe+"/":Qe+Ue;if(console.debug(`[ChatProvider] checking ${rt}`),await Ke(rt)||he==="/"&&await Z(Qe+"/"))return X(!0),!0}const Ee=be*Math.pow(2,se);await new Promise(he=>setTimeout(he,Ee))}return X(!1),!1},[c.baseUrl]);y.useEffect(()=>{let Q=!0;if(!c.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const ae=await ce();if(!Q)return;ae?re().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{Q=!1}},[re,c.baseUrl,ce]),y.useEffect(()=>{r==null||r(Y)},[Y,r]);const ge=y.useRef(null);y.useEffect(()=>{if(a&&o){if(!c.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!q){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}ge.current!==a&&(ge.current=a,F(a).catch(()=>{}))}},[a,o,c.baseUrl,q]);const V=y.useRef(null),F=y.useCallback(async(Q,ae,be)=>{if(!c.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(V.current!==Q){V.current=Q;try{w(!1),P(null),I(void 0);const Je=await c.getMessages({threadId:Q,checkpointId:ae,checkpointNs:be,limit:O});W(Q),U(Je,"replace")}finally{V.current=null}}},[c,U]),K=y.useCallback(async Q=>{const ae=await c.listCheckpoints(Q);return Uv(ae,Q)},[c]),te=y.useCallback(async Q=>{if(!Y)throw new Error("No active thread");w(!1),P(null),I(void 0);const ae=await c.getMessages({threadId:Y,checkpointId:Q,limit:O});U(ae,"replace")},[c,Y,U,O]),le=y.useCallback(async()=>{if(!Y)throw new Error("No active thread");await F(Y)},[Y,F]),oe=y.useRef(!1);y.useEffect(()=>{const Q=oe.current;if(oe.current=d,Q&&!d&&Y){const ae=b.lastCheckpointId??void 0;(async()=>{try{const be=await c.getMessages({threadId:Y,checkpointId:ae,limit:O});U(be,"replace")}catch{}try{await re()}catch{}})()}},[d,Y,b.lastCheckpointId,c,U,re]);const Ae=y.useCallback(async Q=>{const ae=await c.createThread(Q);return await re(),await F(ae.threadId),ae.threadId},[c,re,F]),qe=y.useCallback(async Q=>{await c.deleteThread(Q),await re(),Y===Q&&(W(null),v([]),w(!1),P(null),I(void 0))},[c,re,Y,v]),Me=y.useCallback(async(Q,ae)=>{await c.updateThread(Q,ae),await re()},[c,re]),Se=y.useCallback(async(Q,ae)=>{var Qt;const be=(ae==null?void 0:ae.attachments)||[],{contentParts:Je,filesInfo:Qe}=await Gv(c,be,e==null?void 0:e.uploadPath,s,l,Y),at=[];Q&&at.push({type:"text",text:Q});for(const ie of Je)at.push(ie);const Ke={id:((Qt=crypto.randomUUID)==null?void 0:Qt.call(crypto))||`user-${Date.now()}`,role:"user",content:at,createdAt:new Date().toISOString(),checkpointId:(ae==null?void 0:ae.checkpointId)??b.lastCheckpointId??void 0};R(Ke);const Z={...Ke,content:Ke.content.filter(ie=>ie.type==="text"||ie.type==="image_url"||ie.type==="file")},se={...(ae==null?void 0:ae.payloadExtras)??{}},Ee=!!se.edit,he=se.originalMessageId,Ue=typeof he=="string"?he:void 0,rt=be&&be.length>0,xt={...Y?{threadId:Y}:{},payload:{messages:[Z],attachments:Ke.content.filter(ie=>ie.type==="file").map(ie=>({type:"file",url:ie.url,mimeType:ie.mimeType,name:ie.name,size:ie.size})),files_info:Qe,...s&&rt&&l?{active_agent:l}:{},...se},checkpointId:(ae==null?void 0:ae.checkpointId)??b.lastCheckpointId??void 0,checkpointNs:ae==null?void 0:ae.checkpointNs,nodeFilter:ae==null?void 0:ae.nodeFilter,config:ae==null?void 0:ae.config,edit:Ee,originalMessageId:Ue};p(xt,ie=>C(ie),{onError:ie=>console.warn("stream error",ie),onOpen:({threadId:ie,created:Te})=>{!Y&&ie&&(W(ie),Te&&re().catch(()=>{}))}})},[Y,R,p,C,b.lastCheckpointId,c,e==null?void 0:e.uploadPath,re,W,s,l]),Be=y.useCallback(async Q=>{if(!Y)throw new Error("No active thread");if(L||!x)return;const ae=z;if(ae){H(!0);try{const be=await c.getMessages({threadId:Y,checkpointId:G,limit:(Q==null?void 0:Q.limit)??O,beforeId:ae});U(be,"prepend")}finally{H(!1)}}},[c,Y,G,z,x,L,U]),ee={baseUrl:c.baseUrl,token:f,setToken:S,api:c,threads:M,currentThreadId:Y,setCurrentThreadId:W,messages:b.messages,isStreaming:d,error:_,lastCheckpointId:b.lastCheckpointId,streamingAssistantId:b.assemblingId,hasMoreHistory:x,isLoadingHistory:L,loadOlderMessages:Be,historyPageSize:O,listCheckpoints:K,navigateToCheckpoint:te,returnToLatest:le,refreshThreads:re,createThread:Ae,deleteThread:qe,renameThread:Me,loadThread:F,send:Se,stop:m};return u.jsx(z_.Provider,{value:ee,children:t})}function ba(){const t=y.useContext(z_);if(!t)throw new Error("useChat must be used within ChatProvider");return t}function $(...t){return rC.twMerge(nC.clsx(t))}const Yv=br.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ve=T.forwardRef(({className:t,variant:e,size:n,asChild:r=!1,...a},i)=>{const o=r?Nt.Slot:"button";return u.jsx(o,{className:$(Yv({variant:e,size:n,className:t})),ref:i,...a})});Ve.displayName="Button";const $_=T.forwardRef(({className:t,...e},n)=>u.jsx("textarea",{className:$("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),ref:n,...e}));$_.displayName="Textarea";function Hv({initialValue:t="",editingMessageId:e=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:a=!1,maxLength:i=2e4,onSend:o,onCancelEdit:s,onStop:l,className:c="",textareaClassName:d="",allowEmptySend:_=!1}){const[p,m]=y.useState(t),[E,f]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(t??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[t,e]);const S=y.useCallback(()=>{const O=g.current;O&&(O.style.height="auto",O.style.height=`${O.scrollHeight}px`)},[]);y.useEffect(()=>{S()},[S]);const b=y.useCallback(async O=>{O&&O.preventDefault();const x=(p??"").trim();!x&&!_||f(()=>{try{const w=o(x);w&&typeof w.then=="function"?w.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[p,o,_]),h=y.useCallback(O=>{m(O.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),N=y.useCallback(O=>{O.key==="Enter"&&!O.shiftKey?(O.preventDefault(),b()):O.key==="Escape"&&e&&(O.preventDefault(),s==null||s())},[b,e,s]),v=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${e?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return u.jsx("form",{onSubmit:O=>void b(O),className:`w-full ${c}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx($_,{ref:g,value:p,onChange:h,onKeyDown:N,placeholder:e?"Edit your message...":n,className:v,disabled:a,maxLength:i,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Ve,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:a||!l,children:u.jsx(pe.Square,{size:16})}):u.jsx(Ve,{type:"submit",size:"icon",className:"shrink-0",title:e?"Save changes":"Send message",disabled:a||!p.trim()&&!_||E,children:u.jsx(pe.Send,{size:16})})})]})})}const qv=y.memo(Hv),Ta=0,Sn=1,Jn=2,W_=4;function K_(t){return()=>t}function Vv(t){t()}function Q_(t,e){return n=>t(e(n))}function j_(t,e){return()=>t(e)}function zv(t,e){return n=>t(e,n)}function po(t){return t!==void 0}function $v(...t){return()=>{t.map(Vv)}}function er(){}function ha(t,e){return e(t),t}function Wv(t,e){return e(t)}function et(...t){return t}function We(t,e){return t(Sn,e)}function we(t,e){t(Ta,e)}function mo(t){t(Jn)}function lt(t){return t(W_)}function fe(t,e){return We(t,zv(e,Ta))}function Yt(t,e){const n=t(Sn,r=>{n(),e(r)});return n}function X_(t){let e,n;return r=>a=>{e=a,n&&clearTimeout(n),n=setTimeout(()=>{r(e)},t)}}function Z_(t,e){return t===e}function tt(t=Z_){let e;return n=>r=>{t(e,r)||(e=r,n(r))}}function Oe(t){return e=>n=>{t(n)&&e(n)}}function _e(t){return e=>Q_(e,t)}function Xt(t){return e=>()=>{e(t)}}function j(t,...e){const n=Kv(...e);return(r,a)=>{switch(r){case Jn:mo(t);return;case Sn:return We(t,n(a))}}}function Zt(t,e){return n=>r=>{n(e=t(e,r))}}function Pn(t){return e=>n=>{t>0?t--:e(n)}}function dn(t){let e=null,n;return r=>a=>{e=a,!n&&(n=setTimeout(()=>{n=void 0,r(e)},t))}}function Le(...t){const e=new Array(t.length);let n=0,r=null;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);We(i,l=>{const c=n;n=n|s,e[o]=l,c!==a&&n===a&&r&&(r(),r=null)})}),i=>o=>{const s=()=>{i([o].concat(e))};n===a?s():r=s}}function Kv(...t){return e=>t.reduceRight(Wv,e)}function Qv(t){let e,n;const r=()=>e==null?void 0:e();return function(a,i){switch(a){case Sn:return i?n===i?void 0:(r(),n=i,e=We(t,i),e):(r(),er);case Jn:r(),n=null;return}}}function ne(t){let e=t;const n=Ge();return(r,a)=>{switch(r){case Ta:e=a;break;case Sn:{a(e);break}case W_:return e}return n(r,a)}}function gt(t,e){return ha(ne(e),n=>fe(t,n))}function Ge(){const t=[];return(e,n)=>{switch(e){case Ta:t.slice().forEach(r=>{r(n)});return;case Jn:t.splice(0,t.length);return;case Sn:return t.push(n),()=>{const r=t.indexOf(n);r>-1&&t.splice(r,1)}}}}function Ot(t){return ha(Ge(),e=>fe(t,e))}function He(t,e=[],{singleton:n}={singleton:!0}){return{constructor:t,dependencies:e,id:jv(),singleton:n}}const jv=()=>Symbol();function Xv(t){const e=new Map,n=({constructor:r,dependencies:a,id:i,singleton:o})=>{if(o&&e.has(i))return e.get(i);const s=r(a.map(l=>n(l)));return o&&e.set(i,s),s};return n(t)}function dt(...t){const e=Ge(),n=new Array(t.length);let r=0;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);We(i,l=>{n[o]=l,r=r|s,r===a&&we(e,n)})}),function(i,o){switch(i){case Jn:{mo(e);return}case Sn:return r===a&&o(n),We(e,o)}}}function Ne(t,e=Z_){return j(t,tt(e))}function go(...t){return function(e,n){switch(e){case Jn:return;case Sn:return $v(...t.map(r=>We(r,n)))}}}var Ct=(t=>(t[t.DEBUG=0]="DEBUG",t[t.INFO=1]="INFO",t[t.WARN=2]="WARN",t[t.ERROR=3]="ERROR",t))(Ct||{});const Zv={0:"debug",3:"error",1:"log",2:"warn"},Jv=()=>typeof globalThis>"u"?window:globalThis,bn=He(()=>{const t=ne(3);return{log:ne((e,n,r=1)=>{var a;const i=(a=Jv().VIRTUOSO_LOG_LEVEL)!=null?a:lt(t);r>=i&&console[Zv[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",e,n)}),logLevel:t}},[],{singleton:!0});function kn(t,e,n){return Eo(t,e,n).callbackRef}function Eo(t,e,n){const r=y.useRef(null);let a=o=>{};const i=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(o=>{const s=()=>{const l=o[0].target;l.offsetParent!==null&&t(l)};n?s():requestAnimationFrame(s)}):null,[t,n]);return a=o=>{o&&e?(i==null||i.observe(o),r.current=o):(r.current&&(i==null||i.unobserve(r.current)),r.current=null)},{callbackRef:a,ref:r}}function eN(t,e,n,r,a,i,o,s,l){const c=y.useCallback(d=>{const _=tN(d.children,e,s?"offsetWidth":"offsetHeight",a);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const m=p.lastElementChild.dataset.viewportType==="window";let E;m&&(E=p.ownerDocument.defaultView);const f=o?s?o.scrollLeft:o.scrollTop:m?s?E.scrollX||E.document.documentElement.scrollLeft:E.scrollY||E.document.documentElement.scrollTop:s?p.scrollLeft:p.scrollTop,g=o?s?o.scrollWidth:o.scrollHeight:m?s?E.document.documentElement.scrollWidth:E.document.documentElement.scrollHeight:s?p.scrollWidth:p.scrollHeight,S=o?s?o.offsetWidth:o.offsetHeight:m?s?E.innerWidth:E.innerHeight:s?p.offsetWidth:p.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(f,0),viewportHeight:S}),i==null||i(s?J_("column-gap",getComputedStyle(d).columnGap,a):J_("row-gap",getComputedStyle(d).rowGap,a)),_!==null&&t(_)},[t,e,a,i,o,r,s]);return Eo(c,n,l)}function tN(t,e,n,r){const a=t.length;if(a===0)return null;const i=[];for(let o=0;o<a;o++){const s=t.item(o);if(s.dataset.index===void 0)continue;const l=parseInt(s.dataset.index),c=parseFloat(s.dataset.knownSize),d=e(s,n);if(d===0&&r("Zero-sized element, this should not happen",{child:s},Ct.ERROR),d===c)continue;const _=i[i.length-1];i.length===0||_.size!==d||_.endIndex!==l-1?i.push({endIndex:l,size:d,startIndex:l}):i[i.length-1].endIndex++}return i}function J_(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,Ct.WARN),e==="normal"?0:parseInt(e??"0",10)}function ep(t,e,n){const r=y.useRef(null),a=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let _,p;if(e){const m=e.getBoundingClientRect(),E=c.top-m.top;p=m.height-Math.max(0,E),_=E+e.scrollTop}else{const m=o.current.ownerDocument.defaultView;p=m.innerHeight-Math.max(0,c.top),_=c.top+m.scrollY}r.current={offsetTop:_,visibleHeight:p,visibleWidth:d},t(r.current)},[t,e]),{callbackRef:i,ref:o}=Eo(a,!0,n),s=y.useCallback(()=>{a(o.current)},[a,o]);return y.useEffect(()=>{var l;if(e){e.addEventListener("scroll",s);const c=new ResizeObserver(()=>{requestAnimationFrame(s)});return c.observe(e),()=>{e.removeEventListener("scroll",s),c.unobserve(e)}}else{const c=(l=o.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",s),c==null||c.addEventListener("resize",s),()=>{c==null||c.removeEventListener("scroll",s),c==null||c.removeEventListener("resize",s)}}},[s,e,o]),i}const bt=He(()=>{const t=Ge(),e=Ge(),n=ne(0),r=Ge(),a=ne(0),i=Ge(),o=Ge(),s=ne(0),l=ne(0),c=ne(0),d=ne(0),_=Ge(),p=Ge(),m=ne(!1),E=ne(!1),f=ne(!1);return fe(j(t,_e(({scrollTop:g})=>g)),e),fe(j(t,_e(({scrollHeight:g})=>g)),o),fe(e,a),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:s,horizontalDirection:E,scrollBy:p,scrollContainerState:t,scrollHeight:o,scrollingInProgress:m,scrollTo:_,scrollTop:e,skipAnimationFrameInResizeObserver:f,smoothScrollTargetReached:r,statefulScrollTop:a,viewportHeight:i}},[],{singleton:!0}),Ir={lvl:0};function tp(t,e){const n=t.length;if(n===0)return[];let{index:r,value:a}=e(t[0]);const i=[];for(let o=1;o<n;o++){const{index:s,value:l}=e(t[o]);i.push({end:s-1,start:r,value:a}),r=s,a=l}return i.push({end:1/0,start:r,value:a}),i}function Xe(t){return t===Ir}function Ar(t,e){if(!Xe(t))return e===t.k?t.v:e<t.k?Ar(t.l,e):Ar(t.r,e)}function Ht(t,e,n="k"){if(Xe(t))return[-1/0,void 0];if(Number(t[n])===e)return[t.k,t.v];if(Number(t[n])<e){const r=Ht(t.r,e,n);return r[0]===-1/0?[t.k,t.v]:r}return Ht(t.l,e,n)}function yt(t,e,n){return Xe(t)?ap(e,n,1):e===t.k?ut(t,{k:e,v:n}):e<t.k?ip(ut(t,{l:yt(t.l,e,n)})):ip(ut(t,{r:yt(t.r,e,n)}))}function tr(){return Ir}function Ra(t,e,n){if(Xe(t))return[];const r=Ht(t,e)[0];return nN(So(t,r,n))}function fo(t,e){if(Xe(t))return Ir;const{k:n,l:r,r:a}=t;if(e===n){if(Xe(r))return a;if(Xe(a))return r;{const[i,o]=rp(r);return Ca(ut(t,{k:i,l:np(r),v:o}))}}else return e<n?Ca(ut(t,{l:fo(r,e)})):Ca(ut(t,{r:fo(a,e)}))}function Un(t){return Xe(t)?[]:[...Un(t.l),{k:t.k,v:t.v},...Un(t.r)]}function So(t,e,n){if(Xe(t))return[];const{k:r,l:a,r:i,v:o}=t;let s=[];return r>e&&(s=s.concat(So(a,e,n))),r>=e&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(So(i,e,n))),s}function Ca(t){const{l:e,lvl:n,r}=t;if(r.lvl>=n-1&&e.lvl>=n-1)return t;if(n>r.lvl+1){if(bo(e))return op(ut(t,{lvl:n-1}));if(!Xe(e)&&!Xe(e.r))return ut(e.r,{l:ut(e,{r:e.r.l}),lvl:n,r:ut(t,{l:e.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(bo(t))return To(ut(t,{lvl:n-1}));if(!Xe(r)&&!Xe(r.l)){const a=r.l,i=bo(a)?r.lvl-1:r.lvl;return ut(a,{l:ut(t,{lvl:n-1,r:a.l}),lvl:a.lvl+1,r:To(ut(r,{l:a.r,lvl:i}))})}else throw new Error("Unexpected empty nodes")}}function ut(t,e){return ap(e.k!==void 0?e.k:t.k,e.v!==void 0?e.v:t.v,e.lvl!==void 0?e.lvl:t.lvl,e.l!==void 0?e.l:t.l,e.r!==void 0?e.r:t.r)}function np(t){return Xe(t.r)?t.l:Ca(ut(t,{r:np(t.r)}))}function bo(t){return Xe(t)||t.lvl>t.r.lvl}function rp(t){return Xe(t.r)?[t.k,t.v]:rp(t.r)}function ap(t,e,n,r=Ir,a=Ir){return{k:t,l:r,lvl:n,r:a,v:e}}function ip(t){return To(op(t))}function op(t){const{l:e}=t;return!Xe(e)&&e.lvl===t.lvl?ut(e,{r:ut(t,{l:e.r})}):t}function To(t){const{lvl:e,r:n}=t;return!Xe(n)&&!Xe(n.r)&&n.lvl===e&&n.r.lvl===e?ut(n,{l:ut(t,{r:n.l}),lvl:e+1}):t}function nN(t){return tp(t,({k:e,v:n})=>({index:e,value:n}))}function sp(t,e){return!!(t&&t.startIndex===e.startIndex&&t.endIndex===e.endIndex)}function xr(t,e){return!!(t&&t[0]===e[0]&&t[1]===e[1])}const ho=He(()=>({recalcInProgress:ne(!1)}),[],{singleton:!0});function lp(t,e,n){return t[va(t,e,n)]}function va(t,e,n,r=0){let a=t.length-1;for(;r<=a;){const i=Math.floor((r+a)/2),o=t[i],s=n(o,e);if(s===0)return i;if(s===-1){if(a-r<2)return i-1;a=i-1}else{if(a===r)return i;r=i+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${e}`)}function rN(t,e,n,r){const a=va(t,e,r),i=va(t,n,r,a);return t.slice(a,i+1)}function Tn(t,e){return Math.round(t.getBoundingClientRect()[e])}function Na(t){return!Xe(t.groupOffsetTree)}function Ro({index:t},e){return e===t?0:e<t?-1:1}function aN(){return{groupIndices:[],groupOffsetTree:tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:tr()}}function iN(t,e){let n=Xe(t)?0:1/0;for(const r of e){const{endIndex:a,size:i,startIndex:o}=r;if(n=Math.min(n,o),Xe(t)){t=yt(t,0,i);continue}const s=Ra(t,o-1,a+1);if(s.some(_N(r)))continue;let l=!1,c=!1;for(const{end:d,start:_,value:p}of s)l?(a>=_||i===p)&&(t=fo(t,_)):(c=p!==i,l=!0),d>a&&a>=_&&p!==i&&(t=yt(t,a+1,p));c&&(t=yt(t,o,i))}return[t,n]}function oN(t){return typeof t.groupIndex<"u"}function sN({offset:t},e){return e===t?0:e<t?-1:1}function Dr(t,e,n){if(e.length===0)return 0;const{index:r,offset:a,size:i}=lp(e,t,Ro),o=t-r,s=i*o+(o-1)*n+a;return s>0?s+n:s}function cp(t,e){if(!Na(e))return t;let n=0;for(;e.groupIndices[n]<=t+n;)n++;return t+n}function dp(t,e,n){if(oN(t))return e.groupIndices[t.groupIndex]+1;{const r=t.index==="LAST"?n:t.index;let a=cp(r,e);return a=Math.max(0,a,Math.min(n,a)),a}}function lN(t,e,n,r=0){return r>0&&(e=Math.max(e,lp(t,r,Ro).offset)),tp(rN(t,e,n,sN),uN)}function cN(t,[e,n,r,a]){e.length>0&&r("received item sizes",e,Ct.DEBUG);const i=t.sizeTree;let o=i,s=0;if(n.length>0&&Xe(i)&&e.length===2){const p=e[0].size,m=e[1].size;o=n.reduce((E,f)=>yt(yt(E,f,p),f+1,m),o)}else[o,s]=iN(o,e);if(o===i)return t;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_}=Co(t.offsetTree,s,o,a);return{groupIndices:n,groupOffsetTree:n.reduce((p,m)=>yt(p,m,Dr(m,_,a)),tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_,sizeTree:o}}function dN(t){return Un(t).map(({k:e,v:n},r,a)=>{const i=a[r+1];return{endIndex:i?i.k-1:1/0,size:n,startIndex:e}})}function up(t,e){let n=0,r=0;for(;n<t;)n+=e[r+1]-e[r]-1,r++;return r-(n===t?0:1)}function Co(t,e,n,r){let a=t,i=0,o=0,s=0,l=0;if(e!==0){l=va(a,e-1,Ro),s=a[l].offset;const c=Ht(n,e-1);i=c[0],o=c[1],a.length&&a[l].size===Ht(n,e)[1]&&(l-=1),a=a.slice(0,l+1)}else a=[];for(const{start:c,value:d}of Ra(n,e,1/0)){const _=c-i,p=_*o+s+_*r;a.push({index:c,offset:p,size:d}),i=c,s=p,o=d}return{lastIndex:i,lastOffset:s,lastSize:o,offsetTree:a}}function uN(t){return{index:t.index,value:t}}function _N(t){const{endIndex:e,size:n,startIndex:r}=t;return a=>a.start===r&&(a.end===e||a.end===1/0)&&a.value===n}const pN={offsetHeight:"height",offsetWidth:"width"},Jt=He(([{log:t},{recalcInProgress:e}])=>{const n=Ge(),r=Ge(),a=gt(r,0),i=Ge(),o=Ge(),s=ne(0),l=ne([]),c=ne(void 0),d=ne(void 0),_=ne((R,C)=>Tn(R,pN[C])),p=ne(void 0),m=ne(0),E=aN(),f=gt(j(n,Le(l,t,m),Zt(cN,E),tt()),E),g=gt(j(l,tt(),Zt((R,C)=>({current:C,prev:R.current}),{current:[],prev:[]}),_e(({prev:R})=>R)),[]);fe(j(l,Oe(R=>R.length>0),Le(f,m),_e(([R,C,v])=>{const O=R.reduce((x,w,L)=>yt(x,w,Dr(w,C.offsetTree,v)||L),tr());return{...C,groupIndices:R,groupOffsetTree:O}})),f),fe(j(r,Le(f),Oe(([R,{lastIndex:C}])=>R<C),_e(([R,{lastIndex:C,lastSize:v}])=>[{endIndex:C,size:v,startIndex:R}])),n),fe(c,d);const S=gt(j(c,_e(R=>R===void 0)),!0);fe(j(d,Oe(R=>R!==void 0&&Xe(lt(f).sizeTree)),_e(R=>[{endIndex:0,size:R,startIndex:0}])),n);const b=Ot(j(n,Le(f),Zt(({sizes:R},[C,v])=>({changed:v!==R,sizes:v}),{changed:!1,sizes:E}),_e(R=>R.changed)));We(j(s,Zt((R,C)=>({diff:R.prev-C,prev:C}),{diff:0,prev:0}),_e(R=>R.diff)),R=>{const{groupIndices:C}=lt(f);if(R>0)we(e,!0),we(i,R+up(R,C));else if(R<0){const v=lt(g);v.length>0&&(R-=up(-R,v)),we(o,R)}}),We(j(s,Le(t)),([R,C])=>{R<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},Ct.ERROR)});const h=Ot(i);fe(j(i,Le(f),_e(([R,C])=>{const v=C.groupIndices.length>0,O=[],x=C.lastSize;if(v){const w=Ar(C.sizeTree,0);let L=0,H=0;for(;L<R;){const P=C.groupIndices[H],G=C.groupIndices.length===H+1?1/0:C.groupIndices[H+1]-P-1;O.push({endIndex:P,size:w,startIndex:P}),O.push({endIndex:P+1+G-1,size:x,startIndex:P+1}),H++,L+=G+1}const z=Un(C.sizeTree);return L!==R&&z.shift(),z.reduce((P,{k:G,v:I})=>{let U=P.ranges;return P.prevSize!==0&&(U=[...P.ranges,{endIndex:G+R-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:G+R,prevSize:I,ranges:U}},{prevIndex:R,prevSize:0,ranges:O}).ranges}return Un(C.sizeTree).reduce((w,{k:L,v:H})=>({prevIndex:L+R,prevSize:H,ranges:[...w.ranges,{endIndex:L+R-1,size:w.prevSize,startIndex:w.prevIndex}]}),{prevIndex:0,prevSize:x,ranges:[]}).ranges})),n);const N=Ot(j(o,Le(f,m),_e(([R,{offsetTree:C},v])=>{const O=-R;return Dr(O,C,v)})));return fe(j(o,Le(f,m),_e(([R,C,v])=>{if(C.groupIndices.length>0){if(Xe(C.sizeTree))return C;let O=tr();const x=lt(g);let w=0,L=0,H=0;for(;w<-R;){H=x[L];const z=x[L+1]-H-1;L++,w+=z+1}if(O=Un(C.sizeTree).reduce((z,{k:P,v:G})=>yt(z,Math.max(0,P+R),G),O),w!==-R){const z=Ar(C.sizeTree,H);O=yt(O,0,z);const P=Ht(C.sizeTree,-R+1)[1];O=yt(O,1,P)}return{...C,sizeTree:O,...Co(C.offsetTree,0,O,v)}}else{const O=Un(C.sizeTree).reduce((x,{k:w,v:L})=>yt(x,Math.max(0,w+R),L),tr());return{...C,sizeTree:O,...Co(C.offsetTree,0,O,v)}}})),f),{beforeUnshiftWith:h,data:p,defaultItemSize:d,firstItemIndex:s,fixedItemSize:c,gap:m,groupIndices:l,itemSize:_,listRefresh:b,shiftWith:o,shiftWithOffset:N,sizeRanges:n,sizes:f,statefulTotalCount:a,totalCount:r,trackItemSizes:S,unshiftWith:i}},et(bn,ho),{singleton:!0});function mN(t){return t.reduce((e,n)=>(e.groupIndices.push(e.totalCount),e.totalCount+=n+1,e),{groupIndices:[],totalCount:0})}const _p=He(([{groupIndices:t,sizes:e,totalCount:n},{headerHeight:r,scrollTop:a}])=>{const i=Ge(),o=Ge(),s=Ot(j(i,_e(mN)));return fe(j(s,_e(l=>l.totalCount)),n),fe(j(s,_e(l=>l.groupIndices)),t),fe(j(dt(a,e,r),Oe(([l,c])=>Na(c)),_e(([l,c,d])=>Ht(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),tt(),_e(l=>[l])),o),{groupCounts:i,topItemsIndexes:o}},et(Jt,bt)),hn=He(([{log:t}])=>{const e=ne(!1),n=Ot(j(e,Oe(r=>r),tt()));return We(e,r=>{r&&lt(t)("props updated",{},Ct.DEBUG)}),{didMount:n,propsReady:e}},et(bn),{singleton:!0}),gN=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function pp(t){const e=typeof t=="number"?{index:t}:t;return e.align||(e.align="start"),(!e.behavior||!gN)&&(e.behavior="auto"),e.offset||(e.offset=0),e}const wr=He(([{gap:t,listRefresh:e,sizes:n,totalCount:r},{fixedFooterHeight:a,fixedHeaderHeight:i,footerHeight:o,headerHeight:s,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:_},{log:p}])=>{const m=Ge(),E=Ge(),f=ne(0);let g=null,S=null,b=null;function h(){g&&(g(),g=null),b&&(b(),b=null),S&&(clearTimeout(S),S=null),we(l,!1)}return fe(j(m,Le(n,_,r,f,s,o,p),Le(t,i,a),_e(([[N,R,C,v,O,x,w,L],H,z,P])=>{const G=pp(N),{align:I,behavior:U,offset:M}=G,k=v-1,Y=dp(G,R,k);let W=Dr(Y,R.offsetTree,H)+x;I==="end"?(W+=z+Ht(R.sizeTree,Y)[1]-C+P,Y===k&&(W+=w)):I==="center"?W+=(z+Ht(R.sizeTree,Y)[1]-C+P)/2:W-=O,M&&(W+=M);const re=q=>{h(),q?(L("retrying to scroll to",{location:N},Ct.DEBUG),we(m,N)):(we(E,!0),L("list did not change, scroll successful",{},Ct.DEBUG))};if(h(),U==="smooth"){let q=!1;b=We(e,X=>{q=q||X}),g=Yt(d,()=>{re(q)})}else g=Yt(j(e,EN(150)),re);return S=setTimeout(()=>{h()},1200),we(l,!0),L("scrolling from index to",{behavior:U,index:Y,top:W},Ct.DEBUG),{behavior:U,top:W}})),c),{scrollTargetReached:E,scrollToIndex:m,topListHeight:f}},et(Jt,bt,bn),{singleton:!0});function EN(t){return e=>{const n=setTimeout(()=>{e(!1)},t);return r=>{r&&(e(!0),clearTimeout(n))}}}function vo(t,e){t==0?e():requestAnimationFrame(()=>{vo(t-1,e)})}function No(t,e){const n=e-1;return typeof t=="number"?t:t.index==="LAST"?n:t.index}const Mr=He(([{defaultItemSize:t,listRefresh:e,sizes:n},{scrollTop:r},{scrollTargetReached:a,scrollToIndex:i},{didMount:o}])=>{const s=ne(!0),l=ne(0),c=ne(!0);return fe(j(o,Le(l),Oe(([d,_])=>!!_),Xt(!1)),s),fe(j(o,Le(l),Oe(([d,_])=>!!_),Xt(!1)),c),We(j(dt(e,o),Le(s,n,t,c),Oe(([[,d],_,{sizeTree:p},m,E])=>d&&(!Xe(p)||po(m))&&!_&&!E),Le(l)),([,d])=>{Yt(a,()=>{we(c,!0)}),vo(4,()=>{Yt(r,()=>{we(s,!0)}),we(i,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:s}},et(Jt,bt,wr,hn),{singleton:!0});function mp(t,e){return Math.abs(t-e)<1.01}const Lr="up",Pr="down",fN="none",SN={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},bN=0,kr=He(([{footerHeight:t,headerHeight:e,scrollBy:n,scrollContainerState:r,scrollTop:a,viewportHeight:i}])=>{const o=ne(!1),s=ne(!0),l=Ge(),c=Ge(),d=ne(4),_=ne(bN),p=gt(j(go(j(Ne(a),Pn(1),Xt(!0)),j(Ne(a),Pn(1),Xt(!1),X_(100))),tt()),!1),m=gt(j(go(j(n,Xt(!0)),j(n,Xt(!1),X_(200))),tt()),!1);fe(j(dt(Ne(a),Ne(_)),_e(([b,h])=>b<=h),tt()),s),fe(j(s,dn(50)),c);const E=Ot(j(dt(r,Ne(i),Ne(e),Ne(t),Ne(d)),Zt((b,[{scrollHeight:h,scrollTop:N},R,C,v,O])=>{const x=N+R-h>-O,w={scrollHeight:h,scrollTop:N,viewportHeight:R};if(x){let H,z;return N>b.state.scrollTop?(H="SCROLLED_DOWN",z=b.state.scrollTop-N):(H="SIZE_DECREASED",z=b.state.scrollTop-N||b.scrollTopDelta),{atBottom:!0,atBottomBecause:H,scrollTopDelta:z,state:w}}let L;return w.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":R<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":N<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:w}},SN),tt((b,h)=>b&&b.atBottom===h.atBottom))),f=gt(j(r,Zt((b,{scrollHeight:h,scrollTop:N,viewportHeight:R})=>{if(mp(b.scrollHeight,h))return{changed:!1,jump:0,scrollHeight:h,scrollTop:N};{const C=h-(N+R)<1;return b.scrollTop!==N&&C?{changed:!0,jump:b.scrollTop-N,scrollHeight:h,scrollTop:N}:{changed:!0,jump:0,scrollHeight:h,scrollTop:N}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Oe(b=>b.changed),_e(b=>b.jump)),0);fe(j(E,_e(b=>b.atBottom)),o),fe(j(o,dn(50)),l);const g=ne(Pr);fe(j(r,_e(({scrollTop:b})=>b),tt(),Zt((b,h)=>lt(m)?{direction:b.direction,prevScrollTop:h}:{direction:h<b.prevScrollTop?Lr:Pr,prevScrollTop:h},{direction:Pr,prevScrollTop:0}),_e(b=>b.direction)),g),fe(j(r,dn(50),Xt(fN)),g);const S=ne(0);return fe(j(p,Oe(b=>!b),Xt(0)),S),fe(j(a,dn(100),Le(p),Oe(([b,h])=>!!h),Zt(([b,h],[N])=>[h,N],[0,0]),_e(([b,h])=>h-b)),S),{atBottomState:E,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:_,isAtBottom:o,isAtTop:s,isScrolling:p,lastJumpDueToItemResize:f,scrollDirection:g,scrollVelocity:S}},et(bt)),Oa="top",ya="bottom",gp="none";function Ep(t,e,n){return typeof t=="number"?n===Lr&&e===Oa||n===Pr&&e===ya?t:0:n===Lr?e===Oa?t.main:t.reverse:e===ya?t.main:t.reverse}function fp(t,e){var n;return typeof t=="number"?t:(n=t[e])!=null?n:0}const Oo=He(([{deviation:t,fixedHeaderHeight:e,headerHeight:n,scrollTop:r,viewportHeight:a}])=>{const i=Ge(),o=ne(0),s=ne(0),l=ne(0),c=gt(j(dt(Ne(r),Ne(a),Ne(n),Ne(i,xr),Ne(l),Ne(o),Ne(e),Ne(t),Ne(s)),_e(([d,_,p,[m,E],f,g,S,b,h])=>{const N=d-b,R=g+S,C=Math.max(p-N,0);let v=gp;const O=fp(h,Oa),x=fp(h,ya);return m-=b,m+=p+S,E+=p+S,E-=b,m>d+R-O&&(v=Lr),E<d-C+_+x&&(v=Pr),v!==gp?[Math.max(N-p-Ep(f,Oa,v)-O,0),N-C-S+_+Ep(f,ya,v)+x]:null}),Oe(d=>d!=null),tt(xr)),[0,0]);return{increaseViewportBy:s,listBoundary:i,overscan:l,topListHeight:o,visibleRange:c}},et(bt),{singleton:!0});function TN(t,e,n){if(Na(e)){const r=cp(t,e);return[{index:Ht(e.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:t,offset:0,size:0}]}const yo={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ia(t,e,n,r,a,i){const{lastIndex:o,lastOffset:s,lastSize:l}=a;let c=0,d=0;if(t.length>0){c=t[0].offset;const f=t[t.length-1];d=f.offset+f.size}const _=n-o,p=s+_*l+(_-1)*r,m=c,E=p-d;return{bottom:d,firstItemIndex:i,items:bp(t,a,i),offsetBottom:E,offsetTop:c,top:m,topItems:bp(e,a,i),topListHeight:e.reduce((f,g)=>g.size+f,0),totalCount:n}}function Sp(t,e,n,r,a,i){let o=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-o>=t)break;o++}const s=t+o,l=No(e,s),c=Array.from({length:s}).map((d,_)=>({data:i[_+l],index:_+l,offset:0,size:0}));return Ia(c,[],s,a,n,r)}function bp(t,e,n){if(t.length===0)return[];if(!Na(e))return t.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=t[0].index,a=t[t.length-1].index,i=[],o=Ra(e.groupOffsetTree,r,a);let s,l=0;for(const c of t){(!s||s.end<c.index)&&(s=o.shift(),l=e.groupIndices.indexOf(s.start));let d;c.index===s.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},i.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return i}const Fn=He(([{data:t,firstItemIndex:e,gap:n,sizes:r,totalCount:a},i,{listBoundary:o,topListHeight:s,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:_},p,{didMount:m},{recalcInProgress:E}])=>{const f=ne([]),g=ne(0),S=Ge();fe(i.topItemsIndexes,f);const b=gt(j(dt(m,E,Ne(l,xr),Ne(a),Ne(r),Ne(c),d,Ne(f),Ne(e),Ne(n),t),Oe(([C,v,,O,,,,,,,x])=>{const w=x&&x.length!==O;return C&&!v&&!w}),_e(([,,[C,v],O,x,w,L,H,z,P,G])=>{const I=x,{offsetTree:U,sizeTree:M}=I,k=lt(g);if(O===0)return{...yo,totalCount:O};if(C===0&&v===0)return k===0?{...yo,totalCount:O}:Sp(k,w,x,z,P,G||[]);if(Xe(M))return k>0?null:Ia(TN(No(w,O),I,G),[],O,P,I,z);const Y=[];if(H.length>0){const ce=H[0],ge=H[H.length-1];let V=0;for(const F of Ra(M,ce,ge)){const K=F.value,te=Math.max(F.start,ce),le=Math.min(F.end,ge);for(let oe=te;oe<=le;oe++)Y.push({data:G==null?void 0:G[oe],index:oe,offset:V,size:K}),V+=K}}if(!L)return Ia([],Y,O,P,I,z);const W=H.length>0?H[H.length-1]+1:0,re=lN(U,C,v,W);if(re.length===0)return null;const q=O-1,X=ha([],ce=>{for(const ge of re){const V=ge.value;let F=V.offset,K=ge.start;const te=V.size;if(V.offset<C){K+=Math.floor((C-V.offset+P)/(te+P));const oe=K-ge.start;F+=oe*te+oe*P}K<W&&(F+=(W-K)*te,K=W);const le=Math.min(ge.end,q);for(let oe=K;oe<=le&&!(F>=v);oe++)ce.push({data:G==null?void 0:G[oe],index:oe,offset:F,size:te}),F+=te+P}});return Ia(X,Y,O,P,I,z)}),Oe(C=>C!==null),tt()),yo);fe(j(t,Oe(po),_e(C=>C==null?void 0:C.length)),a),fe(j(b,_e(C=>C.topListHeight)),_),fe(_,s),fe(j(b,_e(C=>[C.top,C.bottom])),o),fe(j(b,_e(C=>C.items)),S);const h=Ot(j(b,Oe(({items:C})=>C.length>0),Le(a,t),Oe(([{items:C},v])=>C[C.length-1].originalIndex===v-1),_e(([,C,v])=>[C-1,v]),tt(xr),_e(([C])=>C))),N=Ot(j(b,dn(200),Oe(({items:C,topItems:v})=>C.length>0&&C[0].originalIndex===v.length),_e(({items:C})=>C[0].index),tt())),R=Ot(j(b,Oe(({items:C})=>C.length>0),_e(({items:C})=>{let v=0,O=C.length-1;for(;C[v].type==="group"&&v<O;)v++;for(;C[O].type==="group"&&O>v;)O--;return{endIndex:C[O].index,startIndex:C[v].index}}),tt(sp)));return{endReached:h,initialItemCount:g,itemsRendered:S,listState:b,rangeChanged:R,startReached:N,topItemsIndexes:f,...p}},et(Jt,_p,Oo,Mr,wr,kr,hn,ho),{singleton:!0}),Tp=He(([{fixedFooterHeight:t,fixedHeaderHeight:e,footerHeight:n,headerHeight:r},{listState:a}])=>{const i=Ge(),o=gt(j(dt(n,t,r,e,a),_e(([s,l,c,d,_])=>s+l+c+d+_.offsetBottom+_.bottom)),0);return fe(Ne(o),i),{totalListHeight:o,totalListHeightChanged:i}},et(bt,Fn),{singleton:!0}),hN=He(([{viewportHeight:t},{totalListHeight:e}])=>{const n=ne(!1),r=gt(j(dt(n,t,e),Oe(([a])=>a),_e(([,a,i])=>Math.max(0,a-i)),dn(0),tt()),0);return{alignToBottom:n,paddingTopAddition:r}},et(bt,Tp),{singleton:!0}),hp=He(()=>({context:ne(null)})),RN=({itemBottom:t,itemTop:e,locationParams:{align:n,behavior:r,...a},viewportBottom:i,viewportTop:o})=>e<o?{...a,align:n??"start",behavior:r}:t>i?{...a,align:n??"end",behavior:r}:null,Rp=He(([{gap:t,sizes:e,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:a,headerHeight:i,scrollingInProgress:o,scrollTop:s,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ge();return fe(j(d,Le(e,l,n,i,a,r,s),Le(t),_e(([[_,p,m,E,f,g,S,b],h])=>{const{align:N,behavior:R,calculateViewLocation:C=RN,done:v,...O}=_,x=dp(_,p,E-1),w=Dr(x,p.offsetTree,h)+f+g,L=w+Ht(p.sizeTree,x)[1],H=b+g,z=b+m-S,P=C({itemBottom:L,itemTop:w,locationParams:{align:N,behavior:R,...O},viewportBottom:z,viewportTop:H});return P?v&&Yt(j(o,Oe(G=>!G),Pn(lt(o)?1:2)),v):v&&v(),P}),Oe(_=>_!==null)),c),{scrollIntoView:d}},et(Jt,bt,wr,Fn,bn),{singleton:!0});function Cp(t){return t?t==="smooth"?"smooth":"auto":!1}const CN=(t,e)=>typeof t=="function"?Cp(t(e)):e&&Cp(t),vN=He(([{listRefresh:t,totalCount:e,fixedItemSize:n,data:r},{atBottomState:a,isAtBottom:i},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:_},{context:p},{scrollIntoView:m}])=>{const E=ne(!1),f=Ge();let g=null;function S(R){we(o,{align:"end",behavior:R,index:"LAST"})}We(j(dt(j(Ne(e),Pn(1)),l),Le(Ne(E),i,s,_),_e(([[R,C],v,O,x,w])=>{let L=C&&x,H="auto";return L&&(H=CN(v,O||w),L=L&&!!H),{followOutputBehavior:H,shouldFollow:L,totalCount:R}}),Oe(({shouldFollow:R})=>R)),({followOutputBehavior:R,totalCount:C})=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("following output to ",{totalCount:C},Ct.DEBUG),S(R)}):g=Yt(t,()=>{lt(d)("following output to ",{totalCount:C},Ct.DEBUG),S(R),g=null})});function b(R){const C=Yt(a,v=>{R&&!v.atBottom&&v.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(lt(d)("scrolling to bottom due to increased size",{},Ct.DEBUG),S("auto"))});setTimeout(C,100)}We(j(dt(Ne(E),e,c),Oe(([R,,C])=>R&&C),Zt(({value:R},[,C])=>({refreshed:R===C,value:C}),{refreshed:!1,value:0}),Oe(({refreshed:R})=>R),Le(E,e)),([,R])=>{lt(s)&&b(R!==!1)}),We(f,()=>{b(lt(E)!==!1)}),We(dt(Ne(E),a),([R,C])=>{R&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&S("auto")});const h=ne(null),N=Ge();return fe(go(j(Ne(r),_e(R=>{var C;return(C=R==null?void 0:R.length)!=null?C:0})),j(Ne(e))),N),We(j(dt(j(N,Pn(1)),l),Le(Ne(h),s,_,p),_e(([[R,C],v,O,x,w])=>C&&O&&(v==null?void 0:v({context:w,totalCount:R,scrollingInProgress:x}))),Oe(R=>!!R),dn(0)),R=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("scrolling into view",{}),we(m,R)}):g=Yt(t,()=>{lt(d)("scrolling into view",{}),we(m,R),g=null})}),{autoscrollToBottom:f,followOutput:E,scrollIntoViewOnChange:h}},et(Jt,kr,wr,Mr,hn,bn,bt,hp,Rp)),NN=He(([{data:t,firstItemIndex:e,gap:n,sizes:r},{initialTopMostItemIndex:a},{initialItemCount:i,listState:o},{didMount:s}])=>(fe(j(s,Le(i),Oe(([,l])=>l!==0),Le(a,r,e,n,t),_e(([[,l],c,d,_,p,m=[]])=>Sp(l,c,d,_,p,m))),o),{}),et(Jt,Mr,Fn,hn),{singleton:!0}),ON=He(([{didMount:t},{scrollTo:e},{listState:n}])=>{const r=ne(0);return We(j(t,Le(r),Oe(([,a])=>a!==0),_e(([,a])=>({top:a}))),a=>{Yt(j(n,Pn(1),Oe(i=>i.items.length>1)),()=>{requestAnimationFrame(()=>{we(e,a)})})}),{initialScrollTop:r}},et(hn,bt,Fn),{singleton:!0}),vp=He(([{scrollVelocity:t}])=>{const e=ne(!1),n=Ge(),r=ne(!1);return fe(j(t,Le(r,e,n),Oe(([a,i])=>!!i),_e(([a,i,o,s])=>{const{enter:l,exit:c}=i;if(o){if(c(a,s))return!1}else if(l(a,s))return!0;return o}),tt()),e),We(j(dt(e,t,n),Le(r)),([[a,i,o],s])=>{a&&s&&s.change&&s.change(i,o)}),{isSeeking:e,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:t}},et(kr),{singleton:!0}),Io=He(([{scrollContainerState:t,scrollTo:e}])=>{const n=Ge(),r=Ge(),a=Ge(),i=ne(!1),o=ne(void 0);return fe(j(dt(n,r),_e(([{scrollHeight:s,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:s,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),fe(j(e,Le(r),_e(([s,{offsetTop:l}])=>({...s,top:s.top+l}))),a),{customScrollParent:o,useWindowScroll:i,windowScrollContainerState:n,windowScrollTo:a,windowViewportRect:r}},et(bt)),yN=He(([{sizeRanges:t,sizes:e},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:a},{didMount:i},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:l}])=>{const c=Ge(),d=ne(void 0),_=ne(null),p=ne(null);return fe(s,_),fe(l,p),We(j(c,Le(e,r,o,_,p,n)),([m,E,f,g,S,b,h])=>{const N=dN(E.sizeTree);g&&S!==null&&b!==null&&(f=S.scrollTop-b.offsetTop),f-=h,m({ranges:N,scrollTop:f})}),fe(j(d,Oe(po),_e(IN)),a),fe(j(i,Le(d),Oe(([,m])=>m!==void 0),tt(),_e(([,m])=>m.ranges)),t),{getState:c,restoreStateFrom:d}},et(Jt,bt,Mr,hn,Io));function IN(t){return{align:"start",index:0,offset:t.scrollTop}}const AN=He(([{topItemsIndexes:t}])=>{const e=ne(0);return fe(j(e,Oe(n=>n>=0),_e(n=>Array.from({length:n}).map((r,a)=>a))),t),{topItemCount:e}},et(Fn));function Np(t){let e=!1,n;return()=>(e||(e=!0,n=t()),n)}const xN=Np(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),DN=He(([{deviation:t,scrollBy:e,scrollingInProgress:n,scrollTop:r},{isAtBottom:a,isScrolling:i,lastJumpDueToItemResize:o,scrollDirection:s},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:_,sizes:p},{log:m},{recalcInProgress:E}])=>{const f=Ot(j(l,Le(o),Zt(([,S,b,h],[{bottom:N,items:R,offsetBottom:C,totalCount:v},O])=>{const x=N+C;let w=0;return b===v&&S.length>0&&R.length>0&&(R[0].originalIndex===0&&S[0].originalIndex===0||(w=x-h,w!==0&&(w+=O))),[w,R,v,x]},[0,[],0,0]),Oe(([S])=>S!==0),Le(r,s,n,a,m,E),Oe(([,S,b,h,,,N])=>!N&&!h&&S!==0&&b===Lr),_e(([[S],,,,,b])=>(b("Upward scrolling compensation",{amount:S},Ct.DEBUG),S))));function g(S){S>0?(we(e,{behavior:"auto",top:-S}),we(t,0)):(we(t,0),we(e,{behavior:"auto",top:-S}))}return We(j(f,Le(t,i)),([S,b,h])=>{h&&xN()?we(t,b-S):g(-S)}),We(j(dt(gt(i,!1),t,E),Oe(([S,b,h])=>!S&&!h&&b!==0),_e(([S,b])=>b),dn(1)),g),fe(j(_,_e(S=>({top:-S}))),e),We(j(c,Le(p,d),_e(([S,{groupIndices:b,lastSize:h,sizeTree:N},R])=>{function C(v){return v*(h+R)}if(b.length===0)return C(S);{let v=0;const O=Ar(N,0);let x=0,w=0;for(;x<S;){x++,v+=O;let L=b.length===w+1?1/0:b[w+1]-b[w]-1;x+L>S&&(v-=O,L=S-x+1),x+=L,v+=C(L),w++}return v}})),S=>{we(t,S),requestAnimationFrame(()=>{we(e,{top:S}),requestAnimationFrame(()=>{we(t,0),we(E,!1)})})}),{deviation:t}},et(bt,kr,Fn,Jt,bn,ho)),wN=He(([t,e,n,r,a,i,o,s,l,c,d])=>({...t,...e,...n,...r,...a,...i,...o,...s,...l,...c,...d}),et(Oo,NN,hn,vp,Tp,ON,hN,Io,Rp,bn,hp)),Op=He(([{data:t,defaultItemSize:e,firstItemIndex:n,fixedItemSize:r,gap:a,groupIndices:i,itemSize:o,sizeRanges:s,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:_},{initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E},f,g,S,{listState:b,topItemsIndexes:h,...N},{scrollToIndex:R},C,{topItemCount:v},{groupCounts:O},x])=>(fe(N.rangeChanged,x.scrollSeekRangeChanged),fe(j(x.windowViewportRect,_e(w=>w.visibleHeight)),f.viewportHeight),{data:t,defaultItemHeight:e,firstItemIndex:n,fixedItemHeight:r,gap:a,groupCounts:O,initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E,sizeRanges:s,topItemCount:v,topItemsIndexes:h,totalCount:d,...S,groupIndices:i,itemSize:o,listState:b,scrollToIndex:R,statefulTotalCount:c,trackItemSizes:_,...N,...x,...f,sizes:l,...g}),et(Jt,Mr,bt,yN,vN,Fn,wr,DN,AN,_p,wN));function MN(t,e){const n={},r={};let a=0;const i=t.length;for(;a<i;)r[t[a]]=1,a+=1;for(const o in e)Object.hasOwn(r,o)||(n[o]=e[o]);return n}const Aa=typeof document<"u"?y.useLayoutEffect:y.useEffect;function yp(t,e,n){const r=Object.keys(e.required||{}),a=Object.keys(e.optional||{}),i=Object.keys(e.methods||{}),o=Object.keys(e.events||{}),s=y.createContext({});function l(g,S){g.propsReady&&we(g.propsReady,!1);for(const b of r){const h=g[e.required[b]];we(h,S[b])}for(const b of a)if(b in S){const h=g[e.optional[b]];we(h,S[b])}g.propsReady&&we(g.propsReady,!0)}function c(g){return i.reduce((S,b)=>(S[b]=h=>{const N=g[e.methods[b]];we(N,h)},S),{})}function d(g){return o.reduce((S,b)=>(S[b]=Qv(g[e.events[b]]),S),{})}const _=y.forwardRef((g,S)=>{const{children:b,...h}=g,[N]=y.useState(()=>ha(Xv(t),v=>{l(v,h)})),[R]=y.useState(j_(d,N));Aa(()=>{for(const v of o)v in h&&We(R[v],h[v]);return()=>{Object.values(R).map(mo)}},[h,R,N]),Aa(()=>{l(N,h)}),y.useImperativeHandle(S,K_(c(N)));const C=n;return u.jsx(s.Provider,{value:N,children:n?u.jsx(C,{...MN([...r,...a,...o],h),children:b}):b})}),p=g=>{const S=y.useContext(s);return y.useCallback(b=>{we(S[g],b)},[S,g])},m=g=>{const S=y.useContext(s)[g],b=y.useCallback(h=>We(S,h),[S]);return y.useSyncExternalStore(b,()=>lt(S),()=>lt(S))},E=g=>{const S=y.useContext(s)[g],[b,h]=y.useState(j_(lt,S));return Aa(()=>We(S,N=>{N!==b&&h(K_(N))}),[S,b]),b},f=y.version.startsWith("18")?m:E;return{Component:_,useEmitter:(g,S)=>{const b=y.useContext(s)[g];Aa(()=>We(b,S),[S,b])},useEmitterValue:f,usePublisher:p}}const Ip=y.createContext(void 0),Ap=y.createContext(void 0),xp=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Ao(t){return"self"in t}function LN(t){return"body"in t}function Dp(t,e,n,r=er,a,i){const o=y.useRef(null),s=y.useRef(null),l=y.useRef(null),c=y.useCallback(p=>{let m,E,f;const g=p.target;if(LN(g)||Ao(g)){const b=Ao(g)?g:g.defaultView;f=i?b.scrollX:b.scrollY,m=i?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,E=i?b.innerWidth:b.innerHeight}else f=i?g.scrollLeft:g.scrollTop,m=i?g.scrollWidth:g.scrollHeight,E=i?g.offsetWidth:g.offsetHeight;const S=()=>{t({scrollHeight:m,scrollTop:Math.max(f,0),viewportHeight:E})};p.suppressFlushSync?S():$i.flushSync(S),s.current!==null&&(f===s.current||f<=0||f===m-E)&&(s.current=null,e(!0),l.current&&(clearTimeout(l.current),l.current=null))},[t,e,i]);y.useEffect(()=>{const p=a||o.current;return r(a||o.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[o,c,n,r,a]);function d(p){const m=o.current;if(!m||(i?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const E=p.behavior==="smooth";let f,g,S;Ao(m)?(g=Math.max(Tn(m.document.documentElement,i?"width":"height"),i?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),f=i?m.innerWidth:m.innerHeight,S=i?window.scrollX:window.scrollY):(g=m[i?"scrollWidth":"scrollHeight"],f=Tn(m,i?"width":"height"),S=m[i?"scrollLeft":"scrollTop"]);const b=g-f;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),mp(f,g)||p.top===S){t({scrollHeight:g,scrollTop:S,viewportHeight:f}),E&&e(!0);return}E?(s.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,s.current=null,e(!0)},1e3)):s.current=null,i&&(p={behavior:p.behavior,left:p.top}),m.scrollTo(p)}function _(p){i&&(p={behavior:p.behavior,left:p.top}),o.current.scrollBy(p)}return{scrollByCallback:_,scrollerRef:o,scrollToCallback:d}}const xo="-webkit-sticky",wp="sticky",Do=Np(()=>{if(typeof document>"u")return wp;const t=document.createElement("div");return t.style.position=xo,t.style.position===xo?xo:wp});function wo(t){return t}const PN=He(()=>{const t=ne(s=>`Item ${s}`),e=ne(s=>`Group ${s}`),n=ne({}),r=ne(wo),a=ne("div"),i=ne(er),o=(s,l=null)=>gt(j(n,_e(c=>c[s]),tt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:o("EmptyPlaceholder"),FooterComponent:o("Footer"),GroupComponent:o("Group","div"),groupContent:e,HeaderComponent:o("Header"),HeaderFooterTag:a,ItemComponent:o("Item","div"),itemContent:t,ListComponent:o("List","div"),ScrollerComponent:o("Scroller","div"),scrollerRef:i,ScrollSeekPlaceholder:o("ScrollSeekPlaceholder"),TopItemListComponent:o("TopItemList")}}),kN=He(([t,e])=>({...t,...e}),et(Op,PN)),UN=({height:t})=>u.jsx("div",{style:{height:t}}),FN={overflowAnchor:"none",position:Do(),zIndex:1},Mp={overflowAnchor:"none"},BN={...Mp,display:"inline-block",height:"100%"},Lp=y.memo(function({showTopList:t=!1}){const e=xe("listState"),n=Pt("sizeRanges"),r=xe("useWindowScroll"),a=xe("customScrollParent"),i=Pt("windowScrollContainerState"),o=Pt("scrollContainerState"),s=a||r?i:o,l=xe("itemContent"),c=xe("context"),d=xe("groupContent"),_=xe("trackItemSizes"),p=xe("itemSize"),m=xe("log"),E=Pt("gap"),f=xe("horizontalDirection"),{callbackRef:g}=eN(n,p,_,t?er:s,m,E,a,f,xe("skipAnimationFrameInResizeObserver")),[S,b]=y.useState(0);Mo("deviation",P=>{S!==P&&b(P)});const h=xe("EmptyPlaceholder"),N=xe("ScrollSeekPlaceholder")||UN,R=xe("ListComponent"),C=xe("ItemComponent"),v=xe("GroupComponent"),O=xe("computeItemKey"),x=xe("isSeeking"),w=xe("groupIndices").length>0,L=xe("alignToBottom"),H=xe("initialItemFinalLocationReached"),z=t?{}:{boxSizing:"border-box",...f?{display:"inline-block",height:"100%",marginLeft:S!==0?S:L?"auto":0,paddingLeft:e.offsetTop,paddingRight:e.offsetBottom,whiteSpace:"nowrap"}:{marginTop:S!==0?S:L?"auto":0,paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},...H?{}:{visibility:"hidden"}};return!t&&e.totalCount===0&&h?u.jsx(h,{...Et(h,c)}):u.jsx(R,{...Et(R,c),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:z,children:(t?e.topItems:e.items).map(P=>{const G=P.originalIndex,I=O(G+e.firstItemIndex,P.data,c);return x?y.createElement(N,{...Et(N,c),height:P.size,index:P.index,key:I,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?y.createElement(v,{...Et(v,c),"data-index":G,"data-item-index":P.index,"data-known-size":P.size,key:I,style:FN},d(P.index,c)):y.createElement(C,{...Et(C,c),...qN(C,P.data),"data-index":G,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:I,style:f?BN:Mp},w?l(P.index,P.groupIndex,P.data,c):l(P.index,P.data,c))})})}),GN={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},YN={outline:"none",overflowX:"auto",position:"relative"},xa=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:{}}),HN={position:Do(),top:0,width:"100%",zIndex:1};function Et(t,e){if(typeof t!="string")return{context:e}}function qN(t,e){return{item:typeof t=="string"?void 0:e}}const VN=y.memo(function(){const t=xe("HeaderComponent"),e=Pt("headerHeight"),n=xe("HeaderFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,xe("skipAnimationFrameInResizeObserver")),a=xe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null}),zN=y.memo(function(){const t=xe("FooterComponent"),e=Pt("footerHeight"),n=xe("HeaderFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,xe("skipAnimationFrameInResizeObserver")),a=xe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null});function Pp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("scrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("scrollerRef"),_=e("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:m,scrollToCallback:E}=Dp(s,c,l,d,void 0,_);return t("scrollTo",E),t("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{..._?YN:GN,...a},tabIndex:0,...o,...Et(l,i),children:r})})}function kp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("windowScrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("totalListHeight"),_=e("deviation"),p=e("customScrollParent"),m=y.useRef(null),E=e("scrollerRef"),{scrollByCallback:f,scrollerRef:g,scrollToCallback:S}=Dp(s,c,l,E,p);return xp(()=>{var b;return g.current=p||((b=m.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,p]),t("windowScrollTo",S),t("scrollBy",f),u.jsx(l,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...a,...d!==0?{height:d+_}:{}},...o,...Et(l,i),children:r})})}const $N=({children:t})=>{const e=y.useContext(Ip),n=Pt("viewportHeight"),r=Pt("fixedItemHeight"),a=xe("alignToBottom"),i=xe("horizontalDirection"),o=y.useMemo(()=>Q_(n,l=>Tn(l,i?"width":"height")),[n,i]),s=kn(o,!0,xe("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{e&&(n(e.viewportHeight),r(e.itemHeight))},[e,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:s,style:xa(a),children:t})},WN=({children:t})=>{const e=y.useContext(Ip),n=Pt("windowViewportRect"),r=Pt("fixedItemHeight"),a=xe("customScrollParent"),i=ep(n,a,xe("skipAnimationFrameInResizeObserver")),o=xe("alignToBottom");return y.useEffect(()=>{e&&(r(e.itemHeight),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:100}))},[e,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:i,style:xa(o),children:t})},KN=({children:t})=>{const e=xe("TopItemListComponent")||"div",n=xe("headerHeight"),r={...HN,marginTop:`${n}px`},a=xe("context");return u.jsx(e,{style:r,...Et(e,a),children:t})},QN=y.memo(function(t){const e=xe("useWindowScroll"),n=xe("topItemsIndexes").length>0,r=xe("customScrollParent"),a=xe("context");return u.jsxs(r||e?ZN:XN,{...t,context:a,children:[n&&u.jsx(KN,{children:u.jsx(Lp,{showTopList:!0})}),u.jsxs(r||e?WN:$N,{children:[u.jsx(VN,{}),u.jsx(Lp,{}),u.jsx(zN,{})]})]})}),{Component:jN,useEmitter:Mo,useEmitterValue:xe,usePublisher:Pt}=yp(kN,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},QN),XN=Pp({useEmitter:Mo,useEmitterValue:xe,usePublisher:Pt}),ZN=kp({useEmitter:Mo,useEmitterValue:xe,usePublisher:Pt}),JN=jN;et(Op,He(()=>{const t=ne(c=>u.jsxs("td",{children:["Item $",c]})),e=ne(null),n=ne(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ne(null),a=ne(null),i=ne({}),o=ne(wo),s=ne(er),l=(c,d=null)=>gt(j(i,_e(_=>_[c]),tt()),d);return{components:i,computeItemKey:o,context:e,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:a,fixedHeaderContent:r,itemContent:t,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Do();const Up={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},eO={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Fp,floor:Da,max:Ur,min:Lo,round:Bp}=Math;function Gp(t,e,n){return Array.from({length:e-t+1}).map((r,a)=>({data:n===null?null:n[a+t],index:a+t}))}function tO(t){return{...eO,items:t}}function wa(t,e){return t&&t.width===e.width&&t.height===e.height}function nO(t,e){return t&&t.column===e.column&&t.row===e.row}const rO=He(([{increaseViewportBy:t,listBoundary:e,overscan:n,visibleRange:r},{footerHeight:a,headerHeight:i,scrollBy:o,scrollContainerState:s,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:_},p,m,{didMount:E,propsReady:f},{customScrollParent:g,useWindowScroll:S,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:N},R])=>{const C=ne(0),v=ne(0),O=ne(Up),x=ne({height:0,width:0}),w=ne({height:0,width:0}),L=Ge(),H=Ge(),z=ne(0),P=ne(null),G=ne({column:0,row:0}),I=Ge(),U=Ge(),M=ne(!1),k=ne(0),Y=ne(!0),W=ne(!1),re=ne(!1);We(j(E,Le(k),Oe(([F,K])=>!!K)),()=>{we(Y,!1)}),We(j(dt(E,Y,w,x,k,W),Oe(([F,K,te,le,,oe])=>F&&!K&&te.height!==0&&le.height!==0&&!oe)),([,,,,F])=>{we(W,!0),vo(1,()=>{we(L,F)}),Yt(j(c),()=>{we(e,[0,0]),we(Y,!0)})}),fe(j(U,Oe(F=>F!=null&&F.scrollTop>0),Xt(0)),v),We(j(E,Le(U),Oe(([,F])=>F!=null)),([,F])=>{F&&(we(x,F.viewport),we(w,F.item),we(G,F.gap),F.scrollTop>0&&(we(M,!0),Yt(j(c,Pn(1)),K=>{we(M,!1)}),we(l,{top:F.scrollTop})))}),fe(j(x,_e(({height:F})=>F)),_),fe(j(dt(Ne(x,wa),Ne(w,wa),Ne(G,(F,K)=>F&&F.column===K.column&&F.row===K.row),Ne(c)),_e(([F,K,te,le])=>({gap:te,item:K,scrollTop:le,viewport:F}))),I),fe(j(dt(Ne(C),r,Ne(G,nO),Ne(w,wa),Ne(x,wa),Ne(P),Ne(v),Ne(M),Ne(Y),Ne(k)),Oe(([,,,,,,,F])=>!F),_e(([F,[K,te],le,oe,Ae,qe,Me,,Se,Be])=>{const{column:ee,row:Q}=le,{height:ae,width:be}=oe,{width:Je}=Ae;if(Me===0&&(F===0||Je===0))return Up;if(be===0){const rt=No(Be,F),xt=rt+Math.max(Me-1,0);return tO(Gp(rt,xt,qe))}const Qe=Yp(Je,be,ee);let at,Ke;Se?K===0&&te===0&&Me>0?(at=0,Ke=Me-1):(at=Qe*Da((K+Q)/(ae+Q)),Ke=Qe*Fp((te+Q)/(ae+Q))-1,Ke=Lo(F-1,Ur(Ke,Qe-1)),at=Lo(Ke,Ur(0,at))):(at=0,Ke=-1);const Z=Gp(at,Ke,qe),{bottom:se,top:Ee}=Hp(Ae,le,oe,Z),he=Fp(F/Qe),Ue=he*ae+(he-1)*Q-se;return{bottom:se,itemHeight:ae,items:Z,itemWidth:be,offsetBottom:Ue,offsetTop:Ee,top:Ee}})),O),fe(j(P,Oe(F=>F!==null),_e(F=>F.length)),C),fe(j(dt(x,w,O,G),Oe(([F,K,{items:te}])=>te.length>0&&K.height!==0&&F.height!==0),_e(([F,K,{items:te},le])=>{const{bottom:oe,top:Ae}=Hp(F,le,K,te);return[Ae,oe]}),tt(xr)),e);const q=ne(!1);fe(j(c,Le(q),_e(([F,K])=>K||F!==0)),q);const X=Ot(j(dt(O,C),Oe(([{items:F}])=>F.length>0),Le(q),Oe(([[F,K],te])=>{const le=F.items[F.items.length-1].index===K-1;return(te||F.bottom>0&&F.itemHeight>0&&F.offsetBottom===0&&F.items.length===K)&&le}),_e(([[,F]])=>F-1),tt())),ce=Ot(j(Ne(O),Oe(({items:F})=>F.length>0&&F[0].index===0),Xt(0),tt())),ge=Ot(j(Ne(O),Le(M),Oe(([{items:F},K])=>F.length>0&&!K),_e(([{items:F}])=>({endIndex:F[F.length-1].index,startIndex:F[0].index})),tt(sp),dn(0)));fe(ge,m.scrollSeekRangeChanged),fe(j(L,Le(x,w,C,G),_e(([F,K,te,le,oe])=>{const Ae=pp(F),{align:qe,behavior:Me,offset:Se}=Ae;let Be=Ae.index;Be==="LAST"&&(Be=le-1),Be=Ur(0,Be,Lo(le-1,Be));let ee=Po(K,oe,te,Be);return qe==="end"?ee=Bp(ee-K.height+te.height):qe==="center"&&(ee=Bp(ee-K.height/2+te.height/2)),Se&&(ee+=Se),{behavior:Me,top:ee}})),l);const V=gt(j(O,_e(F=>F.offsetBottom+F.bottom)),0);return fe(j(N,_e(F=>({height:F.visibleHeight,width:F.visibleWidth}))),x),{customScrollParent:g,data:P,deviation:z,footerHeight:a,gap:G,headerHeight:i,increaseViewportBy:t,initialItemCount:v,itemDimensions:w,overscan:n,restoreStateFrom:U,scrollBy:o,scrollContainerState:s,scrollHeight:H,scrollTo:l,scrollToIndex:L,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:S,viewportDimensions:x,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:N,...m,gridState:O,horizontalDirection:re,initialTopMostItemIndex:k,totalListHeight:V,...p,endReached:X,propsReady:f,rangeChanged:ge,startReached:ce,stateChanged:I,stateRestoreInProgress:M,...R}},et(Oo,bt,kr,vp,hn,Io,bn));function Yp(t,e,n){return Ur(1,Da((t+n)/(Da(e)+n)))}function Hp(t,e,n,r){const{height:a}=n;if(a===void 0||r.length===0)return{bottom:0,top:0};const i=Po(t,e,n,r[0].index);return{bottom:Po(t,e,n,r[r.length-1].index)+a,top:i}}function Po(t,e,n,r){const a=Yp(t.width,n.width,e.column),i=Da(r/a),o=i*n.height+Ur(0,i-1)*e.row;return o>0?o+e.row:o}const aO=He(()=>{const t=ne(_=>`Item ${_}`),e=ne({}),n=ne(null),r=ne("virtuoso-grid-item"),a=ne("virtuoso-grid-list"),i=ne(wo),o=ne("div"),s=ne(er),l=(_,p=null)=>gt(j(e,_e(m=>m[_]),tt()),p),c=ne(!1),d=ne(!1);return fe(Ne(d),c),{components:e,computeItemKey:i,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:o,itemClassName:r,ItemComponent:l("Item","div"),itemContent:t,listClassName:a,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),iO=He(([t,e])=>({...t,...e}),et(rO,aO)),oO=y.memo(function(){const t=nt("gridState"),e=nt("listClassName"),n=nt("itemClassName"),r=nt("itemContent"),a=nt("computeItemKey"),i=nt("isSeeking"),o=kt("scrollHeight"),s=nt("ItemComponent"),l=nt("ListComponent"),c=nt("ScrollSeekPlaceholder"),d=nt("context"),_=kt("itemDimensions"),p=kt("gap"),m=nt("log"),E=nt("stateRestoreInProgress"),f=kt("reportReadyState"),g=kn(y.useMemo(()=>S=>{const b=S.parentElement.parentElement.scrollHeight;o(b);const h=S.firstChild;if(h){const{height:N,width:R}=h.getBoundingClientRect();_({height:N,width:R})}p({column:Vp("column-gap",getComputedStyle(S).columnGap,m),row:Vp("row-gap",getComputedStyle(S).rowGap,m)})},[o,_,p,m]),!0,!1);return xp(()=>{t.itemHeight>0&&t.itemWidth>0&&f(!0)},[t]),E?null:u.jsx(l,{className:e,ref:g,...Et(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(S=>{const b=a(S.index,S.data,d);return i?u.jsx(c,{...Et(c,d),height:t.itemHeight,index:S.index,width:t.itemWidth},b):y.createElement(s,{...Et(s,d),className:n,"data-index":S.index,key:b},r(S.index,S.data,d))})})}),sO=y.memo(function(){const t=nt("HeaderComponent"),e=kt("headerHeight"),n=nt("headerFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,!1),a=nt("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null}),lO=y.memo(function(){const t=nt("FooterComponent"),e=kt("footerHeight"),n=nt("headerFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,!1),a=nt("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null}),cO=({children:t})=>{const e=y.useContext(Ap),n=kt("itemDimensions"),r=kt("viewportDimensions"),a=kn(y.useMemo(()=>i=>{r(i.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{e&&(r({height:e.viewportHeight,width:e.viewportWidth}),n({height:e.itemHeight,width:e.itemWidth}))},[e,r,n]),u.jsx("div",{ref:a,style:xa(!1),children:t})},dO=({children:t})=>{const e=y.useContext(Ap),n=kt("windowViewportRect"),r=kt("itemDimensions"),a=nt("customScrollParent"),i=ep(n,a,!1);return y.useEffect(()=>{e&&(r({height:e.itemHeight,width:e.itemWidth}),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:e.viewportWidth}))},[e,n,r]),u.jsx("div",{ref:i,style:xa(!1),children:t})},uO=y.memo(function({...t}){const e=nt("useWindowScroll"),n=nt("customScrollParent"),r=n||e?pO:_O,a=n||e?dO:cO,i=nt("context");return u.jsx(r,{...t,...Et(r,i),children:u.jsxs(a,{children:[u.jsx(sO,{}),u.jsx(oO,{}),u.jsx(lO,{})]})})}),{useEmitter:qp,useEmitterValue:nt,usePublisher:kt}=yp(iO,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},uO),_O=Pp({useEmitter:qp,useEmitterValue:nt,usePublisher:kt}),pO=kp({useEmitter:qp,useEmitterValue:nt,usePublisher:kt});function Vp(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,Ct.WARN),e==="normal"?0:parseInt(e??"0",10)}const mO=br.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function zp({className:t,variant:e,...n}){return u.jsx("div",{className:$(mO({variant:e}),t),...n})}function de(t,e,{checkForDefaultPrevented:n=!0}={}){return function(a){if(t==null||t(a),n===!1||!a.defaultPrevented)return e==null?void 0:e(a)}}function gO(t,e){const n=T.createContext(e),r=i=>{const{children:o,...s}=i,l=T.useMemo(()=>s,Object.values(s));return u.jsx(n.Provider,{value:l,children:o})};r.displayName=t+"Provider";function a(i){const o=T.useContext(n);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${i}\` must be used within \`${t}\``)}return[r,a]}function qt(t,e=[]){let n=[];function r(i,o){const s=T.createContext(o),l=n.length;n=[...n,o];const c=_=>{var S;const{scope:p,children:m,...E}=_,f=((S=p==null?void 0:p[t])==null?void 0:S[l])||s,g=T.useMemo(()=>E,Object.values(E));return u.jsx(f.Provider,{value:g,children:m})};c.displayName=i+"Provider";function d(_,p){var f;const m=((f=p==null?void 0:p[t])==null?void 0:f[l])||s,E=T.useContext(m);if(E)return E;if(o!==void 0)return o;throw new Error(`\`${_}\` must be used within \`${i}\``)}return[c,d]}const a=()=>{const i=n.map(o=>T.createContext(o));return function(s){const l=(s==null?void 0:s[t])||i;return T.useMemo(()=>({[`__scope${t}`]:{...s,[t]:l}}),[s,l])}};return a.scopeName=t,[r,EO(a,...e)]}function EO(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(i){const o=r.reduce((s,{useScope:l,scopeName:c})=>{const _=l(i)[`__scope${c}`];return{...s,..._}},{});return T.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return n.scopeName=e.scopeName,n}var _t=globalThis!=null&&globalThis.document?T.useLayoutEffect:()=>{},fO=T[" useInsertionEffect ".trim().toString()]||_t;function Rn({prop:t,defaultProp:e,onChange:n=()=>{},caller:r}){const[a,i,o]=SO({defaultProp:e,onChange:n}),s=t!==void 0,l=s?t:a;{const d=T.useRef(t!==void 0);T.useEffect(()=>{const _=d.current;_!==s&&console.warn(`${r} is changing from ${_?"controlled":"uncontrolled"} to ${s?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=s},[s,r])}const c=T.useCallback(d=>{var _;if(s){const p=bO(d)?d(t):d;p!==t&&((_=o.current)==null||_.call(o,p))}else i(d)},[s,t,i,o]);return[l,c]}function SO({defaultProp:t,onChange:e}){const[n,r]=T.useState(t),a=T.useRef(n),i=T.useRef(e);return fO(()=>{i.current=e},[e]),T.useEffect(()=>{var o;a.current!==n&&((o=i.current)==null||o.call(i,n),a.current=n)},[n,a]),[n,r,i]}function bO(t){return typeof t=="function"}function $p(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function ko(...t){return e=>{let n=!1;const r=t.map(a=>{const i=$p(a,e);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():$p(t[a],null)}}}}function ke(...t){return T.useCallback(ko(...t),t)}var TO=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ye=TO.reduce((t,e)=>{const n=Nt.createSlot(`Primitive.${e}`),r=T.forwardRef((a,i)=>{const{asChild:o,...s}=a,l=o?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...s,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function Wp(t,e){t&&oa.flushSync(()=>t.dispatchEvent(e))}function hO(t,e){return T.useReducer((n,r)=>e[n][r]??n,t)}var vt=t=>{const{present:e,children:n}=t,r=RO(e),a=typeof n=="function"?n({present:r.isPresent}):T.Children.only(n),i=ke(r.ref,CO(a));return typeof n=="function"||r.isPresent?T.cloneElement(a,{ref:i}):null};vt.displayName="Presence";function RO(t){const[e,n]=T.useState(),r=T.useRef(null),a=T.useRef(t),i=T.useRef("none"),o=t?"mounted":"unmounted",[s,l]=hO(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return T.useEffect(()=>{const c=Ma(r.current);i.current=s==="mounted"?c:"none"},[s]),_t(()=>{const c=r.current,d=a.current;if(d!==t){const p=i.current,m=Ma(c);t?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),a.current=t}},[t,l]),_t(()=>{if(e){let c;const d=e.ownerDocument.defaultView??window,_=m=>{const f=Ma(r.current).includes(CSS.escape(m.animationName));if(m.target===e&&f&&(l("ANIMATION_END"),!a.current)){const g=e.style.animationFillMode;e.style.animationFillMode="forwards",c=d.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=g)})}},p=m=>{m.target===e&&(i.current=Ma(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",_),e.addEventListener("animationend",_),()=>{d.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",_),e.removeEventListener("animationend",_)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:T.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Ma(t){return(t==null?void 0:t.animationName)||"none"}function CO(t){var r,a;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(a=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:a.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var vO=T[" useId ".trim().toString()]||(()=>{}),NO=0;function Vt(t){const[e,n]=T.useState(vO());return _t(()=>{n(r=>r??String(NO++))},[t]),t||(e?`radix-${e}`:"")}var La="Collapsible",[OO,j0]=qt(La),[yO,Uo]=OO(La),Kp=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,open:r,defaultOpen:a,disabled:i,onOpenChange:o,...s}=t,[l,c]=Rn({prop:r,defaultProp:a??!1,onChange:o,caller:La});return u.jsx(yO,{scope:n,disabled:i,contentId:Vt(),open:l,onOpenToggle:T.useCallback(()=>c(d=>!d),[c]),children:u.jsx(ye.div,{"data-state":Bo(l),"data-disabled":i?"":void 0,...s,ref:e})})});Kp.displayName=La;var Qp="CollapsibleTrigger",jp=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,...r}=t,a=Uo(Qp,n);return u.jsx(ye.button,{type:"button","aria-controls":a.contentId,"aria-expanded":a.open||!1,"data-state":Bo(a.open),"data-disabled":a.disabled?"":void 0,disabled:a.disabled,...r,ref:e,onClick:de(t.onClick,a.onOpenToggle)})});jp.displayName=Qp;var Fo="CollapsibleContent",IO=T.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Uo(Fo,t.__scopeCollapsible);return u.jsx(vt,{present:n||a.open,children:({present:i})=>u.jsx(AO,{...r,ref:e,present:i})})});IO.displayName=Fo;var AO=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,present:r,children:a,...i}=t,o=Uo(Fo,n),[s,l]=T.useState(r),c=T.useRef(null),d=ke(e,c),_=T.useRef(0),p=_.current,m=T.useRef(0),E=m.current,f=o.open||s,g=T.useRef(f),S=T.useRef(void 0);return T.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),_t(()=>{const b=c.current;if(b){S.current=S.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const h=b.getBoundingClientRect();_.current=h.height,m.current=h.width,g.current||(b.style.transitionDuration=S.current.transitionDuration,b.style.animationName=S.current.animationName),l(r)}},[o.open,r]),u.jsx(ye.div,{"data-state":Bo(o.open),"data-disabled":o.disabled?"":void 0,id:o.contentId,hidden:!f,...i,ref:d,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...t.style},children:f&&a})});function Bo(t){return t?"open":"closed"}var xO=Kp;const Xp=xO,Zp=jp,Jp=new URL("data:video/mp2t;base64,Ly8vIDxyZWZlcmVuY2UgbGliPSJ3ZWJ3b3JrZXIiIC8+CmltcG9ydCBtYXJrZWQgZnJvbSAnbWFya2VkJzsKCmRlY2xhcmUgY29uc3Qgc2VsZjogRGVkaWNhdGVkV29ya2VyR2xvYmFsU2NvcGU7CmNvbnN0IHNjb3BlOiBEZWRpY2F0ZWRXb3JrZXJHbG9iYWxTY29wZSA9IHNlbGY7CgpzY29wZS5wb3N0TWVzc2FnZT8uKHsgd29ya2VyX3JlYWR5OiB0cnVlIH0pOwoKc2NvcGUuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIChldmVudDogTWVzc2FnZUV2ZW50KSA9PiB7CiAgY29uc3QgcGF5bG9hZDogYW55ID0gZXZlbnQ/LmRhdGEgPz8ge307CiAgY29uc3QgaWQgPSB0eXBlb2YgcGF5bG9hZC5pZCA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLmlkIDogdW5kZWZpbmVkOwogIGNvbnN0IHNvdXJjZSA9IHR5cGVvZiBwYXlsb2FkLnNvdXJjZSA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLnNvdXJjZSA6IHVuZGVmaW5lZDsKICBpZiAoIWlkIHx8IHR5cGVvZiBzb3VyY2UgIT09ICdzdHJpbmcnKSByZXR1cm47CgogIHRyeSB7CiAgICBjb25zdCBodG1sID0gbWFya2VkLnBhcnNlKHNvdXJjZSk7CiAgICBzY29wZS5wb3N0TWVzc2FnZSh7IGlkLCBodG1sIH0pOwogIH0gY2F0Y2ggKGVycikgewogICAgc2NvcGUucG9zdE1lc3NhZ2UoeyBpZCwgaHRtbDogYDxwcmU+RXJyb3IgcmVuZGVyaW5nIG1hcmtkb3duOiAke1N0cmluZyhlcnIpfTwvcHJlPmAgfSk7CiAgfQp9KTsK",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Wi&&Wi.tagName.toUpperCase()==="SCRIPT"&&Wi.src||new URL("index.umd.js",document.baseURI).href),Fr=Jp.toString(),DO=(()=>{try{if(typeof Worker>"u"||typeof URL>"u"||typeof Blob>"u")return!1;const t=new Blob(["export default null;"],{type:"application/javascript"}),e=URL.createObjectURL(t);return new Worker(e,{type:"module"}).terminate(),URL.revokeObjectURL(e),!0}catch{return!1}})(),wO=Fr.includes("data:"),MO=(()=>{if(typeof navigator>"u")return!1;const t=navigator.userAgent.toLowerCase();return t.includes("safari")&&!t.includes("chrome")&&!t.includes("android")})(),Pa=DO&&!(wO&&MO),Go=t=>typeof t=="object"&&t!==null,Yo=t=>typeof t=="function"?t:Go(t)&&typeof t.parse=="function"?t.parse:null;let ka=null;async function em(t){try{ka||(ka=Promise.resolve().then(()=>zM));const e=await ka,n=Go(e)?e:{},r=Yo(n.parse)??Yo(n.marked)??Yo(n.default);return r?r(t):""}catch(e){throw ka=null,e}}const LO=t=>Go(t)&&typeof t.highlightElement=="function"?{highlightElement:t.highlightElement}:null;console.log("[MarkdownContent] worker url",Fr);const Ho=[];let qo=!1;const tm={addEventListener:()=>{},removeEventListener:()=>{},postMessage:()=>{},terminate:()=>{}};let Cn=tm;const nm=t=>{console.error("[MarkdownContent] worker error",t)};function Vo(t){if(Cn&&Cn!==tm)try{Cn.removeEventListener("error",nm)}catch{}Cn=t,qo=!0;try{Cn.addEventListener("error",nm)}catch(e){console.warn("[MarkdownContent] failed to register worker error handler",e)}try{for(;Ho.length;){const e=Ho.shift();if(e)try{e()}catch{}}}catch(e){console.warn("[MarkdownContent] markWorkerOnline notify failed",e)}}function PO(t){if(!Pa)return null;const e=t.indexOf("data:");if(e===-1)return null;const r=t.slice(e).match(/^data:[^;]+;base64,(.*)$/);if(!r)return null;try{const a=r[1],i=atob(a),o=Uint8Array.from(i,c=>c.charCodeAt(0)),s=new Blob([o],{type:"application/javascript"}),l=URL.createObjectURL(s);try{const c=new Worker(l,{type:"module"});return URL.revokeObjectURL(l),c}catch(c){return URL.revokeObjectURL(l),console.error("[MarkdownContent] failed to initialize worker from data URI blob",c),null}}catch(a){return console.warn("[MarkdownContent] failed to decode embedded data URI",a),null}}async function kO(t){if(Pa)try{let e="";const n=await fetch(t);if(e=await n.text(),n.ok||console.warn("[MarkdownContent] fetch worker non-ok",n.status,n.statusText),!e){console.warn("[MarkdownContent] worker fetch returned empty content; aborting worker init.");return}if(e.trim().startsWith("<")){console.warn("[MarkdownContent] worker fetch returned HTML; dev server may be redirecting. Aborting worker init.");return}const r=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(r);try{const i=new Worker(a,{type:"module"});Vo(i)}catch(i){console.error("[MarkdownContent] failed to initialize worker from blob",i)}finally{URL.revokeObjectURL(a)}}catch(e){console.error("[MarkdownContent] fetch worker failed",e)}}function UO(){if(Fr.includes("data:")){const t=PO(Fr);if(t){Vo(t);return}console.warn("[MarkdownContent] data URI bootstrap failed; worker will remain offline until fallback succeeds");return}try{const t=new Worker(Jp,{type:"module"});Vo(t)}catch(t){console.warn("[MarkdownContent] worker constructor failed, will try fetch+blob fallback",t),kO(Fr)}}Pa?UO():console.warn("[MarkdownContent] module workers not supported; falling back to main-thread markdown parsing");const nr=new Map;function FO(t,e=!1){if(e){const a=t.slice(0,128);return`streaming:${Math.floor(t.length/50)*50}:${a}`}const n=t.slice(0,64),r=t.length>64?t.slice(-64):"";return`${t.length}:${n}:${r}`}function BO(t,e){const[n,r]=y.useState(t);return y.useEffect(()=>{if(e<=0){r(t);return}const a=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(a)}},[t,e]),n}function Br({content:t,className:e="",fallback:n=u.jsx("div",{"aria-busy":!0,children:"Rendering…"}),isStreaming:r=!1,hideFallbackDuringStreaming:a=!0}){const o=BO(t,r?150:0),s=FO(o,r),[l,c]=y.useState(()=>nr.get(s)??null);y.useEffect(()=>{if(nr.has(s)){const b=nr.get(s)??null;c(b);return}if(!Pa){let b=!1;return(async()=>{try{const h=await em(t);nr.set(s,h),b||c(h)}catch(h){console.error("[MarkdownContent] fallback parse failed",h)}})(),()=>{b=!0}}let _=!0,p=!1;const m=b=>{const h=b.data;if(!h||h.id!==s||!_)return;p=!0;const N=h.html??"";nr.set(s,N),c(N)};Cn.addEventListener("message",m);const E=()=>{try{Cn.postMessage({id:s,source:t})}catch(b){console.error("[MarkdownContent] worker.postMessage threw",b)}};qo?E():Ho.push(E);const g=((b,h,N)=>h?N?b>2e4?15e3:b>8e3?8e3:b>2e3?3e3:1e3:b>2e4?1e4:b>8e3?5e3:b>2e3?2e3:600:Math.min(15e3,2e3+Math.floor(b*.5)))(o.length,qo,r),S=window.setTimeout(async()=>{if(!p){console.warn("[MarkdownContent] worker timeout (ms="+g+"), falling back to main-thread parse for",s);try{const b=await em(t);nr.set(s,b),_&&c(b)}catch(b){console.error("[MarkdownContent] fallback parse failed",b)}}},g);return()=>{_=!1,clearTimeout(S),Cn.removeEventListener("message",m)}},[t,s]);const d=y.useRef(null);return y.useEffect(()=>{if(!l)return;const _=d.current;if(!_)return;const p=Array.from(_.querySelectorAll("pre code"));if(!p.length)return;let m=null,E=!1;const f=(S,b)=>{for(const h of S){if(!h.isIntersecting)continue;const N=h.target;if(!m)Promise.resolve().then(()=>g0).then(R=>{if(E)return;const C=LO(R.default??R);if(C){m=C;try{p.forEach(v=>{_.contains(v)&&(m==null||m.highlightElement(v))})}catch{}}}).catch(()=>{});else try{m.highlightElement(N)}catch{}b.unobserve(N)}},g=new IntersectionObserver(f,{root:_,threshold:.1});return p.forEach(S=>g.observe(S)),()=>{E=!0,g.disconnect()}},[l]),l?u.jsx("div",{ref:d,className:$("markdown prose max-w-none break-words dark:prose-invert",e),dangerouslySetInnerHTML:{__html:l}}):r&&a?u.jsx("div",{className:$("markdown prose max-w-none break-words dark:prose-invert",e)}):u.jsx("div",{className:$("markdown prose max-w-none break-words dark:prose-invert",e),children:n})}async function rm(t,e){return await Mt(t,{responseType:"blob",onDownloadProgress:r=>{try{e&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function am(t,e){return await(await rm(`/chat/files/${t}/view`,e)).text()}async function GO(t,e){const n=await rm(`/chat/files/${t}/download`,e),r=URL.createObjectURL(n);let a=`file_${t}`;try{const o=await Mt(`/chat/files/${t}`);a=(o==null?void 0:o.filename)??a}catch{}const i=document.createElement("a");i.href=r,i.download=a,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}const YO=1,HO=1e6;let zo=0;function qO(){return zo=(zo+1)%Number.MAX_SAFE_INTEGER,zo.toString()}const $o=new Map,im=t=>{if($o.has(t))return;const e=setTimeout(()=>{$o.delete(t),Gr({type:"REMOVE_TOAST",toastId:t})},HO);$o.set(t,e)},VO=(t,e)=>{switch(e.type){case"ADD_TOAST":return{...t,toasts:[e.toast,...t.toasts].slice(0,YO)};case"UPDATE_TOAST":return{...t,toasts:t.toasts.map(n=>n.id===e.toast.id?{...n,...e.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=e;return n?im(n):t.toasts.forEach(r=>{im(r.id)}),{...t,toasts:t.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return e.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(n=>n.id!==e.toastId)}}},Ua=[];let Fa={toasts:[]};function Gr(t){Fa=VO(Fa,t),Ua.forEach(e=>{e(Fa)})}function zO({...t}){const e=qO(),n=a=>Gr({type:"UPDATE_TOAST",toast:{...a,id:e}}),r=()=>Gr({type:"DISMISS_TOAST",toastId:e});return Gr({type:"ADD_TOAST",toast:{...t,id:e,open:!0,onOpenChange:a=>{a||r()}}}),{id:e,dismiss:r,update:n}}function Wo(){const[t,e]=T.useState(Fa);return T.useEffect(()=>(Ua.push(e),()=>{const n=Ua.indexOf(e);n>-1&&Ua.splice(n,1)}),[t]),{...t,toast:zO,dismiss:n=>Gr({type:"DISMISS_TOAST",toastId:n})}}function pt(t){const e=T.useRef(t);return T.useEffect(()=>{e.current=t}),T.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function $O(t,e=globalThis==null?void 0:globalThis.document){const n=pt(t);T.useEffect(()=>{const r=a=>{a.key==="Escape"&&n(a)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var WO="DismissableLayer",Ko="dismissableLayer.update",KO="dismissableLayer.pointerDownOutside",QO="dismissableLayer.focusOutside",om,sm=T.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Yr=T.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:a,onFocusOutside:i,onInteractOutside:o,onDismiss:s,...l}=t,c=T.useContext(sm),[d,_]=T.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=T.useState({}),E=ke(e,v=>_(v)),f=Array.from(c.layers),[g]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=f.indexOf(g),b=d?f.indexOf(d):-1,h=c.layersWithOutsidePointerEventsDisabled.size>0,N=b>=S,R=ZO(v=>{const O=v.target,x=[...c.branches].some(w=>w.contains(O));!N||x||(a==null||a(v),o==null||o(v),v.defaultPrevented||s==null||s())},p),C=JO(v=>{const O=v.target;[...c.branches].some(w=>w.contains(O))||(i==null||i(v),o==null||o(v),v.defaultPrevented||s==null||s())},p);return $O(v=>{b===c.layers.size-1&&(r==null||r(v),!v.defaultPrevented&&s&&(v.preventDefault(),s()))},p),T.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(om=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),lm(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=om)}},[d,p,n,c]),T.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),lm())},[d,c]),T.useEffect(()=>{const v=()=>m({});return document.addEventListener(Ko,v),()=>document.removeEventListener(Ko,v)},[]),u.jsx(ye.div,{...l,ref:E,style:{pointerEvents:h?N?"auto":"none":void 0,...t.style},onFocusCapture:de(t.onFocusCapture,C.onFocusCapture),onBlurCapture:de(t.onBlurCapture,C.onBlurCapture),onPointerDownCapture:de(t.onPointerDownCapture,R.onPointerDownCapture)})});Yr.displayName=WO;var jO="DismissableLayerBranch",XO=T.forwardRef((t,e)=>{const n=T.useContext(sm),r=T.useRef(null),a=ke(e,r);return T.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),u.jsx(ye.div,{...t,ref:a})});XO.displayName=jO;function ZO(t,e=globalThis==null?void 0:globalThis.document){const n=pt(t),r=T.useRef(!1),a=T.useRef(()=>{});return T.useEffect(()=>{const i=s=>{if(s.target&&!r.current){let l=function(){cm(KO,n,c,{discrete:!0})};const c={originalEvent:s};s.pointerType==="touch"?(e.removeEventListener("click",a.current),a.current=l,e.addEventListener("click",a.current,{once:!0})):l()}else e.removeEventListener("click",a.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",i),e.removeEventListener("click",a.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function JO(t,e=globalThis==null?void 0:globalThis.document){const n=pt(t),r=T.useRef(!1);return T.useEffect(()=>{const a=i=>{i.target&&!r.current&&cm(QO,n,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",a),()=>e.removeEventListener("focusin",a)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function lm(){const t=new CustomEvent(Ko);document.dispatchEvent(t)}function cm(t,e,n,{discrete:r}){const a=n.originalEvent.target,i=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&a.addEventListener(t,e,{once:!0}),r?Wp(a,i):a.dispatchEvent(i)}var Qo="focusScope.autoFocusOnMount",jo="focusScope.autoFocusOnUnmount",dm={bubbles:!1,cancelable:!0},ey="FocusScope",Ba=T.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:i,...o}=t,[s,l]=T.useState(null),c=pt(a),d=pt(i),_=T.useRef(null),p=ke(e,f=>l(f)),m=T.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;T.useEffect(()=>{if(r){let f=function(h){if(m.paused||!s)return;const N=h.target;s.contains(N)?_.current=N:vn(_.current,{select:!0})},g=function(h){if(m.paused||!s)return;const N=h.relatedTarget;N!==null&&(s.contains(N)||vn(_.current,{select:!0}))},S=function(h){if(document.activeElement===document.body)for(const R of h)R.removedNodes.length>0&&vn(s)};document.addEventListener("focusin",f),document.addEventListener("focusout",g);const b=new MutationObserver(S);return s&&b.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",f),document.removeEventListener("focusout",g),b.disconnect()}}},[r,s,m.paused]),T.useEffect(()=>{if(s){pm.add(m);const f=document.activeElement;if(!s.contains(f)){const S=new CustomEvent(Qo,dm);s.addEventListener(Qo,c),s.dispatchEvent(S),S.defaultPrevented||(ty(oy(um(s)),{select:!0}),document.activeElement===f&&vn(s))}return()=>{s.removeEventListener(Qo,c),setTimeout(()=>{const S=new CustomEvent(jo,dm);s.addEventListener(jo,d),s.dispatchEvent(S),S.defaultPrevented||vn(f??document.body,{select:!0}),s.removeEventListener(jo,d),pm.remove(m)},0)}}},[s,c,d,m]);const E=T.useCallback(f=>{if(!n&&!r||m.paused)return;const g=f.key==="Tab"&&!f.altKey&&!f.ctrlKey&&!f.metaKey,S=document.activeElement;if(g&&S){const b=f.currentTarget,[h,N]=ny(b);h&&N?!f.shiftKey&&S===N?(f.preventDefault(),n&&vn(h,{select:!0})):f.shiftKey&&S===h&&(f.preventDefault(),n&&vn(N,{select:!0})):S===b&&f.preventDefault()}},[n,r,m.paused]);return u.jsx(ye.div,{tabIndex:-1,...o,ref:p,onKeyDown:E})});Ba.displayName=ey;function ty(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(vn(r,{select:e}),document.activeElement!==n)return}function ny(t){const e=um(t),n=_m(e,t),r=_m(e.reverse(),t);return[n,r]}function um(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function _m(t,e){for(const n of t)if(!ry(n,{upTo:e}))return n}function ry(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function ay(t){return t instanceof HTMLInputElement&&"select"in t}function vn(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&ay(t)&&e&&t.select()}}var pm=iy();function iy(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=mm(t,e),t.unshift(e)},remove(e){var n;t=mm(t,e),(n=t[0])==null||n.resume()}}}function mm(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function oy(t){return t.filter(e=>e.tagName!=="A")}var sy="Portal",Ga=T.forwardRef((t,e)=>{var s;const{container:n,...r}=t,[a,i]=T.useState(!1);_t(()=>i(!0),[]);const o=n||a&&((s=globalThis==null?void 0:globalThis.document)==null?void 0:s.body);return o?$i.createPortal(u.jsx(ye.div,{...r,ref:e}),o):null});Ga.displayName=sy;var Xo=0;function Zo(){T.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??gm()),document.body.insertAdjacentElement("beforeend",t[1]??gm()),Xo++,()=>{Xo===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),Xo--}},[])}function gm(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var en=function(){return en=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},en.apply(this,arguments)};function Em(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function ly(t,e,n){if(n||arguments.length===2)for(var r=0,a=e.length,i;r<a;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;var Ya="right-scroll-bar-position",Ha="width-before-scroll-bar",cy="with-scroll-bars-hidden",dy="--removed-body-scroll-bar-size";function Jo(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function uy(t,e){var n=y.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=e,n.facade}var _y=typeof window<"u"?T.useLayoutEffect:T.useEffect,fm=new WeakMap;function py(t,e){var n=uy(null,function(r){return t.forEach(function(a){return Jo(a,r)})});return _y(function(){var r=fm.get(n);if(r){var a=new Set(r),i=new Set(t),o=n.current;a.forEach(function(s){i.has(s)||Jo(s,null)}),i.forEach(function(s){a.has(s)||Jo(s,o)})}fm.set(n,t)},[t]),n}function my(t){return t}function gy(t,e){e===void 0&&(e=my);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:t},useMedium:function(i){var o=e(i,r);return n.push(o),function(){n=n.filter(function(s){return s!==o})}},assignSyncMedium:function(i){for(r=!0;n.length;){var o=n;n=[],o.forEach(i)}n={push:function(s){return i(s)},filter:function(){return n}}},assignMedium:function(i){r=!0;var o=[];if(n.length){var s=n;n=[],s.forEach(i),o=n}var l=function(){var d=o;o=[],d.forEach(i)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){o.push(d),c()},filter:function(d){return o=o.filter(d),n}}}};return a}function Ey(t){t===void 0&&(t={});var e=gy(null);return e.options=en({async:!0,ssr:!1},t),e}var Sm=function(t){var e=t.sideCar,n=Em(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return T.createElement(r,en({},n))};Sm.isSideCarExport=!0;function fy(t,e){return t.useMedium(e),Sm}var bm=Ey(),es=function(){},qa=T.forwardRef(function(t,e){var n=T.useRef(null),r=T.useState({onScrollCapture:es,onWheelCapture:es,onTouchMoveCapture:es}),a=r[0],i=r[1],o=t.forwardProps,s=t.children,l=t.className,c=t.removeScrollBar,d=t.enabled,_=t.shards,p=t.sideCar,m=t.noRelative,E=t.noIsolation,f=t.inert,g=t.allowPinchZoom,S=t.as,b=S===void 0?"div":S,h=t.gapMode,N=Em(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),R=p,C=py([n,e]),v=en(en({},N),a);return T.createElement(T.Fragment,null,d&&T.createElement(R,{sideCar:bm,removeScrollBar:c,shards:_,noRelative:m,noIsolation:E,inert:f,setCallbacks:i,allowPinchZoom:!!g,lockRef:n,gapMode:h}),o?T.cloneElement(T.Children.only(s),en(en({},v),{ref:C})):T.createElement(b,en({},v,{className:l,ref:C}),s))});qa.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},qa.classNames={fullWidth:Ha,zeroRight:Ya};var Sy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function by(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Sy();return e&&t.setAttribute("nonce",e),t}function Ty(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function hy(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Ry=function(){var t=0,e=null;return{add:function(n){t==0&&(e=by())&&(Ty(e,n),hy(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Cy=function(){var t=Ry();return function(e,n){T.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},Tm=function(){var t=Cy(),e=function(n){var r=n.styles,a=n.dynamic;return t(r,a),null};return e},vy={left:0,top:0,right:0,gap:0},ts=function(t){return parseInt(t||"",10)||0},Ny=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],a=e[t==="padding"?"paddingRight":"marginRight"];return[ts(n),ts(r),ts(a)]},Oy=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return vy;var e=Ny(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},yy=Tm(),rr="data-scroll-locked",Iy=function(t,e,n,r){var a=t.left,i=t.top,o=t.right,s=t.gap;return n===void 0&&(n="margin"),`
33
+ `)}const Dv={messages:[],assemblingId:null,lastCheckpointId:null,toolIndex:{},lastBranch:null};function wv(t,e){var n;switch(e.type){case"reset":return{messages:co(((n=e.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,toolIndex:{},lastBranch:null};case"seed":return{...t,messages:co(e.payload.messages)};case"prepend":{const r=co(e.payload.messages);if(!r.length)return t;const a=new Set(t.messages.map(o=>o.id)),i=r.filter(o=>!a.has(o.id));return i.length?{...t,messages:[...i,...t.messages]}:t}case"user_message":{const r=e.payload.message;if(t.assemblingId){const a=t.messages.findIndex(i=>i.id===t.assemblingId&&i.role==="assistant");if(a>=0){const i=t.messages.slice(0,a),o=t.messages.slice(a);return{...t,messages:[...i,r,...o]}}}return{...t,messages:[...t.messages,r]}}case"event":return q_(t,e.payload.ev);case"batch":{const{events:r}=e.payload;return r.length?r.reduce((a,i)=>q_(a,i),t):t}default:return t}}function H_(t=[]){const[e,n]=y.useReducer(wv,{...Dv,messages:t}),r=y.useRef([]),a=y.useRef(null),i=y.useRef(null),o=y.useCallback(()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),a.current=null,i.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),s=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?a.current===null&&(a.current=window.requestAnimationFrame(()=>o())):i.current===null&&(i.current=setTimeout(o,16))},[o]),l=y.useCallback(d=>{r.current.push(d),s()},[s]);y.useEffect(()=>()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),r.current=[]},[]);const c=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:d=>n({type:"seed",payload:{messages:d}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:e,dispatch:n,...c}}function q_(t,e){var n;if(e.type==="message_start"&&e.role==="assistant"){const r=e.id,a=kv(e.model),i={id:r,role:"assistant",name:a||void 0,model:e.model,createdAt:new Date().toISOString(),content:[]};return{...t,assemblingId:r,messages:[...t.messages,i]}}if(e.type==="token"){const r=t.assemblingId??uo(t.messages);return r?{...t,messages:Mv(t.messages,r,e.content)}:t}if(e.type==="message_delta"){const r=t.assemblingId??uo(t.messages);return r?{...t,messages:V_(t.messages,r,e.delta)}:t}if(e.type==="message_end"){const r=t.assemblingId??uo(t.messages);if(!r)return{...t,assemblingId:null};const a=t.messages,i=a.findIndex(o=>o.id===r&&o.role==="assistant");if(i>=0&&!((n=a[i].content)==null?void 0:n.some(l=>{var c;return(l==null?void 0:l.type)==="text"&&((c=l.text)==null?void 0:c.trim())}))){const l=[...a.slice(0,i),...a.slice(i+1)];return{...t,assemblingId:null,messages:l}}return{...t,assemblingId:null}}if(e.type==="tool_start"){const r=`tool-${e.id}`,a={type:"tool_call",id:e.id,name:e.name,args:e.args},i={id:r,role:"tool",name:e.name,createdAt:new Date().toISOString(),content:[a]};return{...t,messages:[...t.messages,i],toolIndex:{...t.toolIndex,[e.id]:r}}}if(e.type==="tool_result"){const r=t.toolIndex[e.id]??`tool-${e.id}`,a={type:"tool_result",toolCallId:e.id,output:e.output,error:e.error},i=t.messages.find(l=>l.id===r),o={id:r,role:"tool",content:[a],createdAt:new Date().toISOString()},s=i?V_(t.messages,r,[a]):[...t.messages,o];return{...t,messages:s}}if(e.type==="checkpoint"){const r=Pv(t.messages,e.checkpointId);return{...t,lastCheckpointId:e.checkpointId,messages:r}}if(e.type==="branch"){const r=e.checkpointId??t.lastCheckpointId;return{...t,lastBranch:e,lastCheckpointId:r??null}}if(e.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${e.message}`}],createdAt:new Date().toISOString()};return{...t,messages:[...t.messages,r]}}return t}function co(t){return t.filter(e=>{if(e.role!=="assistant")return!0;const n=(e.content||[]).some(a=>{var i;return a&&a.type==="text"&&((i=a.text)==null?void 0:i.trim())}),r=(e.content||[]).some(a=>a&&a.type==="image_url");return!!(n||r)})}function uo(t){for(let e=t.length-1;e>=0;e--)if(t[e].role==="assistant")return t[e].id;return null}function Mv(t,e,n){return t.map(r=>{if(r.id!==e)return r;const a=r.content.slice(),i=a[a.length-1];return i&&i.type==="text"?i.text+=n:a.push({type:"text",text:n}),{...r,content:a}})}function V_(t,e,n){return t.map(r=>r.id===e?{...r,content:Lv(r.content,n)}:r)}function Lv(t,e){const n=t.slice();for(const r of e)if(r.type==="text"){const a=n[n.length-1];(a==null?void 0:a.type)==="text"?a.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Pv(t,e){for(let n=t.length-1;n>=0;n--)if(t[n].role==="assistant"){const a={...t[n],checkpointId:e};return[...t.slice(0,n),a,...t.slice(n+1)]}return t}function kv(t){if(!t)return null;const e=t.split("/");return e[e.length-1]||null}function Uv(t,e){const n=t==null?void 0:t.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],a=o=>o&&typeof o=="object"&&typeof o.checkpointId=="string"&&typeof o.createdAt=="string",i=r.filter(a).map(o=>({checkpointId:o.checkpointId,checkpointNs:o.checkpointNs??"",createdAt:o.createdAt,messagesLen:o.messagesLen??0,preview:o.preview??"",role:o.role??null,parentId:o.parentId??null,editedMessageId:o.editedMessageId??null,branchLabel:o.branchLabel??null}));return{threadId:(t==null?void 0:t.threadId)??e??null,checkpoints:i}}async function _o(t){return await new Promise((e,n)=>{const r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=a=>n(a),r.readAsDataURL(t)})}async function Fv(t){return await new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{try{const a=r.result,i=new Uint8Array(a);let o="";const s=i.byteLength;for(let l=0;l<s;l++)o+=String.fromCharCode(i[l]);e(btoa(o))}catch(a){n(a)}},r.onerror=a=>n(a),r.readAsArrayBuffer(t)})}async function Bv(t,e,n){try{return await _o(e)}catch{return null}}async function Gv(t,e=[],n,r,a,i){const o=[],s=[];for(const l of e){let c=null;try{c=await Bv(t,l,i)}catch{c=null}if(l.type&&l.type.startsWith("image/"))if(c){const d={type:"image_url",url:c,mimeType:l.type,alt:l.name};o.push(d)}else try{const d=await _o(l),_={type:"image_url",url:String(d),mimeType:l.type,alt:l.name};o.push(_)}catch{}else if(c){const d={type:"file",url:c,mimeType:l.type||void 0,name:l.name,size:l.size,sourceType:"base64"};o.push(d)}else try{const d=await _o(l),_={type:"file",url:String(d),mimeType:l.type||void 0,name:l.name,size:l.size,sourceType:"base64"};o.push(_)}catch{}try{const d=await Fv(l);s.push({filename:l.name,data:d,mime_type:l.type||"application/octet-stream"})}catch{}}return{contentParts:o,filesInfo:s}}const z_=y.createContext(null);function yr({children:t,apiConfig:e,onError:n,onThreadChange:r,initialThreadId:a=null,historyPageSize:i,autoLoadInitial:o=!0,enableFileAgentRouting:s=!1,fileAgentId:l="invoice_reader"}){const c=cn;y.useEffect(()=>{e&&c.updateConfig({baseUrl:e.baseUrl,authToken:e.apiKey})},[c,e]);const{isStreaming:d,error:_,stream:p,stop:m,setToken:E}=Y_({baseUrl:c.baseUrl,token:null,headers:e==null?void 0:e.headers,streamPath:"/chat/runs/stream"}),[f,g]=y.useState(()=>typeof c.getAuthToken=="function"?c.getAuthToken():null);y.useEffect(()=>{E(typeof c.getAuthToken=="function"?c.getAuthToken():null);const Q=c.onTokenChange(ae=>{g(ae),E(ae)});return()=>{Q()}},[c,E]);const S=y.useCallback(Q=>{c.setAuthToken(Q)},[c]),{state:b,seed:h,prepend:N,pushUser:R,onEvent:C,reset:v}=H_(),O=i&&i>0?i:6,[x,w]=y.useState(!1),[L,H]=y.useState(!1),[z,P]=y.useState(null),[G,I]=y.useState(void 0),U=y.useCallback((Q,ae)=>{const be=Array.isArray(Q==null?void 0:Q.messages)?Q.messages:[];ae==="replace"?h(be):ae==="prepend"&&be.length&&N(be),P((Q==null?void 0:Q.nextCursor)??null),w(!!(Q!=null&&Q.hasMore)),I(Je=>(Q==null?void 0:Q.checkpointId)??Je??void 0)},[h,N]),[M,k]=y.useState([]),[Y,W]=y.useState(null),re=y.useCallback(async()=>{const Q=await c.listThreads();k(Q)},[c]),[q,X]=y.useState(!1),ce=y.useCallback(async Q=>{const ae=(Q==null?void 0:Q.maxAttempts)??5,be=(Q==null?void 0:Q.baseDelayMs)??500,Je=(Q==null?void 0:Q.timeoutMs)??2e3;if(!c.baseUrl)return!1;const Qe=c.baseUrl.replace(/\/+$/,""),at=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],Ke=async se=>{try{const Ee=new AbortController,he=setTimeout(()=>Ee.abort(),Je),Ue=await fetch(se,{method:"GET",signal:Ee.signal});return clearTimeout(he),Ue.ok}catch{return!1}},Z=async se=>{try{const Ee=new AbortController,he=setTimeout(()=>Ee.abort(),Je),Ue=await fetch(se,{method:"HEAD",signal:Ee.signal});return clearTimeout(he),Ue.ok}catch{return!1}};for(let se=0;se<ae;se++){console.debug(`[ChatProvider] health-check attempt ${se+1}/${ae}`);for(const he of at){let Ue=he;Qe.endsWith("/api")&&he.startsWith("/api")&&(Ue=he.replace(/^\/api/,"")||"/");const rt=Ue==="/"?Qe+"/":Qe+Ue;if(console.debug(`[ChatProvider] checking ${rt}`),await Ke(rt)||he==="/"&&await Z(Qe+"/"))return X(!0),!0}const Ee=be*Math.pow(2,se);await new Promise(he=>setTimeout(he,Ee))}return X(!1),!1},[c.baseUrl]);y.useEffect(()=>{let Q=!0;if(!c.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const ae=await ce();if(!Q)return;ae?re().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{Q=!1}},[re,c.baseUrl,ce]),y.useEffect(()=>{r==null||r(Y)},[Y,r]);const ge=y.useRef(null);y.useEffect(()=>{if(a&&o){if(!c.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!q){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}ge.current!==a&&(ge.current=a,F(a).catch(()=>{}))}},[a,o,c.baseUrl,q]);const V=y.useRef(null),F=y.useCallback(async(Q,ae,be)=>{if(!c.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(V.current!==Q){V.current=Q;try{w(!1),P(null),I(void 0);const Je=await c.getMessages({threadId:Q,checkpointId:ae,checkpointNs:be,limit:O});W(Q),U(Je,"replace")}finally{V.current=null}}},[c,U]),K=y.useCallback(async Q=>{const ae=await c.listCheckpoints(Q);return Uv(ae,Q)},[c]),te=y.useCallback(async Q=>{if(!Y)throw new Error("No active thread");w(!1),P(null),I(void 0);const ae=await c.getMessages({threadId:Y,checkpointId:Q,limit:O});U(ae,"replace")},[c,Y,U,O]),le=y.useCallback(async()=>{if(!Y)throw new Error("No active thread");await F(Y)},[Y,F]),oe=y.useRef(!1);y.useEffect(()=>{const Q=oe.current;if(oe.current=d,Q&&!d&&Y){const ae=b.lastCheckpointId??void 0;(async()=>{try{const be=await c.getMessages({threadId:Y,checkpointId:ae,limit:O});U(be,"replace")}catch{}try{await re()}catch{}})()}},[d,Y,b.lastCheckpointId,c,U,re]);const Ae=y.useCallback(async Q=>{const ae=await c.createThread(Q);return await re(),await F(ae.threadId),ae.threadId},[c,re,F]),qe=y.useCallback(async Q=>{await c.deleteThread(Q),await re(),Y===Q&&(W(null),v([]),w(!1),P(null),I(void 0))},[c,re,Y,v]),Me=y.useCallback(async(Q,ae)=>{await c.updateThread(Q,ae),await re()},[c,re]),Se=y.useCallback(async(Q,ae)=>{var Qt;const be=(ae==null?void 0:ae.attachments)||[],{contentParts:Je,filesInfo:Qe}=await Gv(c,be,e==null?void 0:e.uploadPath,s,l,Y),at=[];Q&&at.push({type:"text",text:Q});for(const ie of Je)at.push(ie);const Ke={id:((Qt=crypto.randomUUID)==null?void 0:Qt.call(crypto))||`user-${Date.now()}`,role:"user",content:at,createdAt:new Date().toISOString(),checkpointId:(ae==null?void 0:ae.checkpointId)??b.lastCheckpointId??void 0};R(Ke);const Z={...Ke,content:Ke.content.filter(ie=>ie.type==="text"||ie.type==="image_url"||ie.type==="file")},se={...(ae==null?void 0:ae.payloadExtras)??{}},Ee=!!se.edit,he=se.originalMessageId,Ue=typeof he=="string"?he:void 0,rt=be&&be.length>0,xt={...Y?{threadId:Y}:{},payload:{messages:[Z],attachments:Ke.content.filter(ie=>ie.type==="file").map(ie=>({type:"file",url:ie.url,mimeType:ie.mimeType,name:ie.name,size:ie.size})),files_info:Qe,...s&&rt&&l?{active_agent:l}:{},...se},checkpointId:(ae==null?void 0:ae.checkpointId)??b.lastCheckpointId??void 0,checkpointNs:ae==null?void 0:ae.checkpointNs,nodeFilter:ae==null?void 0:ae.nodeFilter,config:ae==null?void 0:ae.config,edit:Ee,originalMessageId:Ue};p(xt,ie=>C(ie),{onError:ie=>console.warn("stream error",ie),onOpen:({threadId:ie,created:Te})=>{!Y&&ie&&(W(ie),Te&&re().catch(()=>{}))}})},[Y,R,p,C,b.lastCheckpointId,c,e==null?void 0:e.uploadPath,re,W,s,l]),Be=y.useCallback(async Q=>{if(!Y)throw new Error("No active thread");if(L||!x)return;const ae=z;if(ae){H(!0);try{const be=await c.getMessages({threadId:Y,checkpointId:G,limit:(Q==null?void 0:Q.limit)??O,beforeId:ae});U(be,"prepend")}finally{H(!1)}}},[c,Y,G,z,x,L,U]),ee={baseUrl:c.baseUrl,token:f,setToken:S,api:c,threads:M,currentThreadId:Y,setCurrentThreadId:W,messages:b.messages,isStreaming:d,error:_,lastCheckpointId:b.lastCheckpointId,streamingAssistantId:b.assemblingId,hasMoreHistory:x,isLoadingHistory:L,loadOlderMessages:Be,historyPageSize:O,listCheckpoints:K,navigateToCheckpoint:te,returnToLatest:le,refreshThreads:re,createThread:Ae,deleteThread:qe,renameThread:Me,loadThread:F,send:Se,stop:m};return u.jsx(z_.Provider,{value:ee,children:t})}function ba(){const t=y.useContext(z_);if(!t)throw new Error("useChat must be used within ChatProvider");return t}function $(...t){return rC.twMerge(nC.clsx(t))}const Yv=br.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ve=T.forwardRef(({className:t,variant:e,size:n,asChild:r=!1,...a},i)=>{const o=r?Nt.Slot:"button";return u.jsx(o,{className:$(Yv({variant:e,size:n,className:t})),ref:i,...a})});Ve.displayName="Button";const $_=T.forwardRef(({className:t,...e},n)=>u.jsx("textarea",{className:$("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),ref:n,...e}));$_.displayName="Textarea";function Hv({initialValue:t="",editingMessageId:e=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:a=!1,maxLength:i=2e4,onSend:o,onCancelEdit:s,onStop:l,className:c="",textareaClassName:d="",allowEmptySend:_=!1}){const[p,m]=y.useState(t),[E,f]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(t??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[t,e]);const S=y.useCallback(()=>{const O=g.current;O&&(O.style.height="auto",O.style.height=`${O.scrollHeight}px`)},[]);y.useEffect(()=>{S()},[S]);const b=y.useCallback(async O=>{O&&O.preventDefault();const x=(p??"").trim();!x&&!_||f(()=>{try{const w=o(x);w&&typeof w.then=="function"?w.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[p,o,_]),h=y.useCallback(O=>{m(O.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),N=y.useCallback(O=>{O.key==="Enter"&&!O.shiftKey?(O.preventDefault(),b()):O.key==="Escape"&&e&&(O.preventDefault(),s==null||s())},[b,e,s]),v=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${e?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return u.jsx("form",{onSubmit:O=>void b(O),className:`w-full ${c}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx($_,{ref:g,value:p,onChange:h,onKeyDown:N,placeholder:e?"Edit your message...":n,className:v,disabled:a,maxLength:i,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Ve,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:a||!l,children:u.jsx(pe.Square,{size:16})}):u.jsx(Ve,{type:"submit",size:"icon",className:"shrink-0",title:e?"Save changes":"Send message",disabled:a||!p.trim()&&!_||E,children:u.jsx(pe.Send,{size:16})})})]})})}const qv=y.memo(Hv),Ta=0,Sn=1,Jn=2,W_=4;function K_(t){return()=>t}function Vv(t){t()}function Q_(t,e){return n=>t(e(n))}function j_(t,e){return()=>t(e)}function zv(t,e){return n=>t(e,n)}function po(t){return t!==void 0}function $v(...t){return()=>{t.map(Vv)}}function er(){}function ha(t,e){return e(t),t}function Wv(t,e){return e(t)}function et(...t){return t}function We(t,e){return t(Sn,e)}function we(t,e){t(Ta,e)}function mo(t){t(Jn)}function lt(t){return t(W_)}function fe(t,e){return We(t,zv(e,Ta))}function Yt(t,e){const n=t(Sn,r=>{n(),e(r)});return n}function X_(t){let e,n;return r=>a=>{e=a,n&&clearTimeout(n),n=setTimeout(()=>{r(e)},t)}}function Z_(t,e){return t===e}function tt(t=Z_){let e;return n=>r=>{t(e,r)||(e=r,n(r))}}function Oe(t){return e=>n=>{t(n)&&e(n)}}function _e(t){return e=>Q_(e,t)}function Xt(t){return e=>()=>{e(t)}}function j(t,...e){const n=Kv(...e);return(r,a)=>{switch(r){case Jn:mo(t);return;case Sn:return We(t,n(a))}}}function Zt(t,e){return n=>r=>{n(e=t(e,r))}}function Pn(t){return e=>n=>{t>0?t--:e(n)}}function dn(t){let e=null,n;return r=>a=>{e=a,!n&&(n=setTimeout(()=>{n=void 0,r(e)},t))}}function Le(...t){const e=new Array(t.length);let n=0,r=null;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);We(i,l=>{const c=n;n=n|s,e[o]=l,c!==a&&n===a&&r&&(r(),r=null)})}),i=>o=>{const s=()=>{i([o].concat(e))};n===a?s():r=s}}function Kv(...t){return e=>t.reduceRight(Wv,e)}function Qv(t){let e,n;const r=()=>e==null?void 0:e();return function(a,i){switch(a){case Sn:return i?n===i?void 0:(r(),n=i,e=We(t,i),e):(r(),er);case Jn:r(),n=null;return}}}function ne(t){let e=t;const n=Ge();return(r,a)=>{switch(r){case Ta:e=a;break;case Sn:{a(e);break}case W_:return e}return n(r,a)}}function gt(t,e){return ha(ne(e),n=>fe(t,n))}function Ge(){const t=[];return(e,n)=>{switch(e){case Ta:t.slice().forEach(r=>{r(n)});return;case Jn:t.splice(0,t.length);return;case Sn:return t.push(n),()=>{const r=t.indexOf(n);r>-1&&t.splice(r,1)}}}}function Ot(t){return ha(Ge(),e=>fe(t,e))}function He(t,e=[],{singleton:n}={singleton:!0}){return{constructor:t,dependencies:e,id:jv(),singleton:n}}const jv=()=>Symbol();function Xv(t){const e=new Map,n=({constructor:r,dependencies:a,id:i,singleton:o})=>{if(o&&e.has(i))return e.get(i);const s=r(a.map(l=>n(l)));return o&&e.set(i,s),s};return n(t)}function dt(...t){const e=Ge(),n=new Array(t.length);let r=0;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);We(i,l=>{n[o]=l,r=r|s,r===a&&we(e,n)})}),function(i,o){switch(i){case Jn:{mo(e);return}case Sn:return r===a&&o(n),We(e,o)}}}function Ne(t,e=Z_){return j(t,tt(e))}function go(...t){return function(e,n){switch(e){case Jn:return;case Sn:return $v(...t.map(r=>We(r,n)))}}}var Ct=(t=>(t[t.DEBUG=0]="DEBUG",t[t.INFO=1]="INFO",t[t.WARN=2]="WARN",t[t.ERROR=3]="ERROR",t))(Ct||{});const Zv={0:"debug",3:"error",1:"log",2:"warn"},Jv=()=>typeof globalThis>"u"?window:globalThis,bn=He(()=>{const t=ne(3);return{log:ne((e,n,r=1)=>{var a;const i=(a=Jv().VIRTUOSO_LOG_LEVEL)!=null?a:lt(t);r>=i&&console[Zv[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",e,n)}),logLevel:t}},[],{singleton:!0});function kn(t,e,n){return Eo(t,e,n).callbackRef}function Eo(t,e,n){const r=y.useRef(null);let a=o=>{};const i=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(o=>{const s=()=>{const l=o[0].target;l.offsetParent!==null&&t(l)};n?s():requestAnimationFrame(s)}):null,[t,n]);return a=o=>{o&&e?(i==null||i.observe(o),r.current=o):(r.current&&(i==null||i.unobserve(r.current)),r.current=null)},{callbackRef:a,ref:r}}function eN(t,e,n,r,a,i,o,s,l){const c=y.useCallback(d=>{const _=tN(d.children,e,s?"offsetWidth":"offsetHeight",a);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const m=p.lastElementChild.dataset.viewportType==="window";let E;m&&(E=p.ownerDocument.defaultView);const f=o?s?o.scrollLeft:o.scrollTop:m?s?E.scrollX||E.document.documentElement.scrollLeft:E.scrollY||E.document.documentElement.scrollTop:s?p.scrollLeft:p.scrollTop,g=o?s?o.scrollWidth:o.scrollHeight:m?s?E.document.documentElement.scrollWidth:E.document.documentElement.scrollHeight:s?p.scrollWidth:p.scrollHeight,S=o?s?o.offsetWidth:o.offsetHeight:m?s?E.innerWidth:E.innerHeight:s?p.offsetWidth:p.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(f,0),viewportHeight:S}),i==null||i(s?J_("column-gap",getComputedStyle(d).columnGap,a):J_("row-gap",getComputedStyle(d).rowGap,a)),_!==null&&t(_)},[t,e,a,i,o,r,s]);return Eo(c,n,l)}function tN(t,e,n,r){const a=t.length;if(a===0)return null;const i=[];for(let o=0;o<a;o++){const s=t.item(o);if(s.dataset.index===void 0)continue;const l=parseInt(s.dataset.index),c=parseFloat(s.dataset.knownSize),d=e(s,n);if(d===0&&r("Zero-sized element, this should not happen",{child:s},Ct.ERROR),d===c)continue;const _=i[i.length-1];i.length===0||_.size!==d||_.endIndex!==l-1?i.push({endIndex:l,size:d,startIndex:l}):i[i.length-1].endIndex++}return i}function J_(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,Ct.WARN),e==="normal"?0:parseInt(e??"0",10)}function ep(t,e,n){const r=y.useRef(null),a=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let _,p;if(e){const m=e.getBoundingClientRect(),E=c.top-m.top;p=m.height-Math.max(0,E),_=E+e.scrollTop}else{const m=o.current.ownerDocument.defaultView;p=m.innerHeight-Math.max(0,c.top),_=c.top+m.scrollY}r.current={offsetTop:_,visibleHeight:p,visibleWidth:d},t(r.current)},[t,e]),{callbackRef:i,ref:o}=Eo(a,!0,n),s=y.useCallback(()=>{a(o.current)},[a,o]);return y.useEffect(()=>{var l;if(e){e.addEventListener("scroll",s);const c=new ResizeObserver(()=>{requestAnimationFrame(s)});return c.observe(e),()=>{e.removeEventListener("scroll",s),c.unobserve(e)}}else{const c=(l=o.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",s),c==null||c.addEventListener("resize",s),()=>{c==null||c.removeEventListener("scroll",s),c==null||c.removeEventListener("resize",s)}}},[s,e,o]),i}const bt=He(()=>{const t=Ge(),e=Ge(),n=ne(0),r=Ge(),a=ne(0),i=Ge(),o=Ge(),s=ne(0),l=ne(0),c=ne(0),d=ne(0),_=Ge(),p=Ge(),m=ne(!1),E=ne(!1),f=ne(!1);return fe(j(t,_e(({scrollTop:g})=>g)),e),fe(j(t,_e(({scrollHeight:g})=>g)),o),fe(e,a),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:s,horizontalDirection:E,scrollBy:p,scrollContainerState:t,scrollHeight:o,scrollingInProgress:m,scrollTo:_,scrollTop:e,skipAnimationFrameInResizeObserver:f,smoothScrollTargetReached:r,statefulScrollTop:a,viewportHeight:i}},[],{singleton:!0}),Ir={lvl:0};function tp(t,e){const n=t.length;if(n===0)return[];let{index:r,value:a}=e(t[0]);const i=[];for(let o=1;o<n;o++){const{index:s,value:l}=e(t[o]);i.push({end:s-1,start:r,value:a}),r=s,a=l}return i.push({end:1/0,start:r,value:a}),i}function Xe(t){return t===Ir}function Ar(t,e){if(!Xe(t))return e===t.k?t.v:e<t.k?Ar(t.l,e):Ar(t.r,e)}function Ht(t,e,n="k"){if(Xe(t))return[-1/0,void 0];if(Number(t[n])===e)return[t.k,t.v];if(Number(t[n])<e){const r=Ht(t.r,e,n);return r[0]===-1/0?[t.k,t.v]:r}return Ht(t.l,e,n)}function yt(t,e,n){return Xe(t)?ap(e,n,1):e===t.k?ut(t,{k:e,v:n}):e<t.k?ip(ut(t,{l:yt(t.l,e,n)})):ip(ut(t,{r:yt(t.r,e,n)}))}function tr(){return Ir}function Ra(t,e,n){if(Xe(t))return[];const r=Ht(t,e)[0];return nN(So(t,r,n))}function fo(t,e){if(Xe(t))return Ir;const{k:n,l:r,r:a}=t;if(e===n){if(Xe(r))return a;if(Xe(a))return r;{const[i,o]=rp(r);return Ca(ut(t,{k:i,l:np(r),v:o}))}}else return e<n?Ca(ut(t,{l:fo(r,e)})):Ca(ut(t,{r:fo(a,e)}))}function Un(t){return Xe(t)?[]:[...Un(t.l),{k:t.k,v:t.v},...Un(t.r)]}function So(t,e,n){if(Xe(t))return[];const{k:r,l:a,r:i,v:o}=t;let s=[];return r>e&&(s=s.concat(So(a,e,n))),r>=e&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(So(i,e,n))),s}function Ca(t){const{l:e,lvl:n,r}=t;if(r.lvl>=n-1&&e.lvl>=n-1)return t;if(n>r.lvl+1){if(bo(e))return op(ut(t,{lvl:n-1}));if(!Xe(e)&&!Xe(e.r))return ut(e.r,{l:ut(e,{r:e.r.l}),lvl:n,r:ut(t,{l:e.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(bo(t))return To(ut(t,{lvl:n-1}));if(!Xe(r)&&!Xe(r.l)){const a=r.l,i=bo(a)?r.lvl-1:r.lvl;return ut(a,{l:ut(t,{lvl:n-1,r:a.l}),lvl:a.lvl+1,r:To(ut(r,{l:a.r,lvl:i}))})}else throw new Error("Unexpected empty nodes")}}function ut(t,e){return ap(e.k!==void 0?e.k:t.k,e.v!==void 0?e.v:t.v,e.lvl!==void 0?e.lvl:t.lvl,e.l!==void 0?e.l:t.l,e.r!==void 0?e.r:t.r)}function np(t){return Xe(t.r)?t.l:Ca(ut(t,{r:np(t.r)}))}function bo(t){return Xe(t)||t.lvl>t.r.lvl}function rp(t){return Xe(t.r)?[t.k,t.v]:rp(t.r)}function ap(t,e,n,r=Ir,a=Ir){return{k:t,l:r,lvl:n,r:a,v:e}}function ip(t){return To(op(t))}function op(t){const{l:e}=t;return!Xe(e)&&e.lvl===t.lvl?ut(e,{r:ut(t,{l:e.r})}):t}function To(t){const{lvl:e,r:n}=t;return!Xe(n)&&!Xe(n.r)&&n.lvl===e&&n.r.lvl===e?ut(n,{l:ut(t,{r:n.l}),lvl:e+1}):t}function nN(t){return tp(t,({k:e,v:n})=>({index:e,value:n}))}function sp(t,e){return!!(t&&t.startIndex===e.startIndex&&t.endIndex===e.endIndex)}function xr(t,e){return!!(t&&t[0]===e[0]&&t[1]===e[1])}const ho=He(()=>({recalcInProgress:ne(!1)}),[],{singleton:!0});function lp(t,e,n){return t[va(t,e,n)]}function va(t,e,n,r=0){let a=t.length-1;for(;r<=a;){const i=Math.floor((r+a)/2),o=t[i],s=n(o,e);if(s===0)return i;if(s===-1){if(a-r<2)return i-1;a=i-1}else{if(a===r)return i;r=i+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${e}`)}function rN(t,e,n,r){const a=va(t,e,r),i=va(t,n,r,a);return t.slice(a,i+1)}function Tn(t,e){return Math.round(t.getBoundingClientRect()[e])}function Na(t){return!Xe(t.groupOffsetTree)}function Ro({index:t},e){return e===t?0:e<t?-1:1}function aN(){return{groupIndices:[],groupOffsetTree:tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:tr()}}function iN(t,e){let n=Xe(t)?0:1/0;for(const r of e){const{endIndex:a,size:i,startIndex:o}=r;if(n=Math.min(n,o),Xe(t)){t=yt(t,0,i);continue}const s=Ra(t,o-1,a+1);if(s.some(_N(r)))continue;let l=!1,c=!1;for(const{end:d,start:_,value:p}of s)l?(a>=_||i===p)&&(t=fo(t,_)):(c=p!==i,l=!0),d>a&&a>=_&&p!==i&&(t=yt(t,a+1,p));c&&(t=yt(t,o,i))}return[t,n]}function oN(t){return typeof t.groupIndex<"u"}function sN({offset:t},e){return e===t?0:e<t?-1:1}function Dr(t,e,n){if(e.length===0)return 0;const{index:r,offset:a,size:i}=lp(e,t,Ro),o=t-r,s=i*o+(o-1)*n+a;return s>0?s+n:s}function cp(t,e){if(!Na(e))return t;let n=0;for(;e.groupIndices[n]<=t+n;)n++;return t+n}function dp(t,e,n){if(oN(t))return e.groupIndices[t.groupIndex]+1;{const r=t.index==="LAST"?n:t.index;let a=cp(r,e);return a=Math.max(0,a,Math.min(n,a)),a}}function lN(t,e,n,r=0){return r>0&&(e=Math.max(e,lp(t,r,Ro).offset)),tp(rN(t,e,n,sN),uN)}function cN(t,[e,n,r,a]){e.length>0&&r("received item sizes",e,Ct.DEBUG);const i=t.sizeTree;let o=i,s=0;if(n.length>0&&Xe(i)&&e.length===2){const p=e[0].size,m=e[1].size;o=n.reduce((E,f)=>yt(yt(E,f,p),f+1,m),o)}else[o,s]=iN(o,e);if(o===i)return t;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_}=Co(t.offsetTree,s,o,a);return{groupIndices:n,groupOffsetTree:n.reduce((p,m)=>yt(p,m,Dr(m,_,a)),tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_,sizeTree:o}}function dN(t){return Un(t).map(({k:e,v:n},r,a)=>{const i=a[r+1];return{endIndex:i?i.k-1:1/0,size:n,startIndex:e}})}function up(t,e){let n=0,r=0;for(;n<t;)n+=e[r+1]-e[r]-1,r++;return r-(n===t?0:1)}function Co(t,e,n,r){let a=t,i=0,o=0,s=0,l=0;if(e!==0){l=va(a,e-1,Ro),s=a[l].offset;const c=Ht(n,e-1);i=c[0],o=c[1],a.length&&a[l].size===Ht(n,e)[1]&&(l-=1),a=a.slice(0,l+1)}else a=[];for(const{start:c,value:d}of Ra(n,e,1/0)){const _=c-i,p=_*o+s+_*r;a.push({index:c,offset:p,size:d}),i=c,s=p,o=d}return{lastIndex:i,lastOffset:s,lastSize:o,offsetTree:a}}function uN(t){return{index:t.index,value:t}}function _N(t){const{endIndex:e,size:n,startIndex:r}=t;return a=>a.start===r&&(a.end===e||a.end===1/0)&&a.value===n}const pN={offsetHeight:"height",offsetWidth:"width"},Jt=He(([{log:t},{recalcInProgress:e}])=>{const n=Ge(),r=Ge(),a=gt(r,0),i=Ge(),o=Ge(),s=ne(0),l=ne([]),c=ne(void 0),d=ne(void 0),_=ne((R,C)=>Tn(R,pN[C])),p=ne(void 0),m=ne(0),E=aN(),f=gt(j(n,Le(l,t,m),Zt(cN,E),tt()),E),g=gt(j(l,tt(),Zt((R,C)=>({current:C,prev:R.current}),{current:[],prev:[]}),_e(({prev:R})=>R)),[]);fe(j(l,Oe(R=>R.length>0),Le(f,m),_e(([R,C,v])=>{const O=R.reduce((x,w,L)=>yt(x,w,Dr(w,C.offsetTree,v)||L),tr());return{...C,groupIndices:R,groupOffsetTree:O}})),f),fe(j(r,Le(f),Oe(([R,{lastIndex:C}])=>R<C),_e(([R,{lastIndex:C,lastSize:v}])=>[{endIndex:C,size:v,startIndex:R}])),n),fe(c,d);const S=gt(j(c,_e(R=>R===void 0)),!0);fe(j(d,Oe(R=>R!==void 0&&Xe(lt(f).sizeTree)),_e(R=>[{endIndex:0,size:R,startIndex:0}])),n);const b=Ot(j(n,Le(f),Zt(({sizes:R},[C,v])=>({changed:v!==R,sizes:v}),{changed:!1,sizes:E}),_e(R=>R.changed)));We(j(s,Zt((R,C)=>({diff:R.prev-C,prev:C}),{diff:0,prev:0}),_e(R=>R.diff)),R=>{const{groupIndices:C}=lt(f);if(R>0)we(e,!0),we(i,R+up(R,C));else if(R<0){const v=lt(g);v.length>0&&(R-=up(-R,v)),we(o,R)}}),We(j(s,Le(t)),([R,C])=>{R<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},Ct.ERROR)});const h=Ot(i);fe(j(i,Le(f),_e(([R,C])=>{const v=C.groupIndices.length>0,O=[],x=C.lastSize;if(v){const w=Ar(C.sizeTree,0);let L=0,H=0;for(;L<R;){const P=C.groupIndices[H],G=C.groupIndices.length===H+1?1/0:C.groupIndices[H+1]-P-1;O.push({endIndex:P,size:w,startIndex:P}),O.push({endIndex:P+1+G-1,size:x,startIndex:P+1}),H++,L+=G+1}const z=Un(C.sizeTree);return L!==R&&z.shift(),z.reduce((P,{k:G,v:I})=>{let U=P.ranges;return P.prevSize!==0&&(U=[...P.ranges,{endIndex:G+R-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:G+R,prevSize:I,ranges:U}},{prevIndex:R,prevSize:0,ranges:O}).ranges}return Un(C.sizeTree).reduce((w,{k:L,v:H})=>({prevIndex:L+R,prevSize:H,ranges:[...w.ranges,{endIndex:L+R-1,size:w.prevSize,startIndex:w.prevIndex}]}),{prevIndex:0,prevSize:x,ranges:[]}).ranges})),n);const N=Ot(j(o,Le(f,m),_e(([R,{offsetTree:C},v])=>{const O=-R;return Dr(O,C,v)})));return fe(j(o,Le(f,m),_e(([R,C,v])=>{if(C.groupIndices.length>0){if(Xe(C.sizeTree))return C;let O=tr();const x=lt(g);let w=0,L=0,H=0;for(;w<-R;){H=x[L];const z=x[L+1]-H-1;L++,w+=z+1}if(O=Un(C.sizeTree).reduce((z,{k:P,v:G})=>yt(z,Math.max(0,P+R),G),O),w!==-R){const z=Ar(C.sizeTree,H);O=yt(O,0,z);const P=Ht(C.sizeTree,-R+1)[1];O=yt(O,1,P)}return{...C,sizeTree:O,...Co(C.offsetTree,0,O,v)}}else{const O=Un(C.sizeTree).reduce((x,{k:w,v:L})=>yt(x,Math.max(0,w+R),L),tr());return{...C,sizeTree:O,...Co(C.offsetTree,0,O,v)}}})),f),{beforeUnshiftWith:h,data:p,defaultItemSize:d,firstItemIndex:s,fixedItemSize:c,gap:m,groupIndices:l,itemSize:_,listRefresh:b,shiftWith:o,shiftWithOffset:N,sizeRanges:n,sizes:f,statefulTotalCount:a,totalCount:r,trackItemSizes:S,unshiftWith:i}},et(bn,ho),{singleton:!0});function mN(t){return t.reduce((e,n)=>(e.groupIndices.push(e.totalCount),e.totalCount+=n+1,e),{groupIndices:[],totalCount:0})}const _p=He(([{groupIndices:t,sizes:e,totalCount:n},{headerHeight:r,scrollTop:a}])=>{const i=Ge(),o=Ge(),s=Ot(j(i,_e(mN)));return fe(j(s,_e(l=>l.totalCount)),n),fe(j(s,_e(l=>l.groupIndices)),t),fe(j(dt(a,e,r),Oe(([l,c])=>Na(c)),_e(([l,c,d])=>Ht(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),tt(),_e(l=>[l])),o),{groupCounts:i,topItemsIndexes:o}},et(Jt,bt)),hn=He(([{log:t}])=>{const e=ne(!1),n=Ot(j(e,Oe(r=>r),tt()));return We(e,r=>{r&&lt(t)("props updated",{},Ct.DEBUG)}),{didMount:n,propsReady:e}},et(bn),{singleton:!0}),gN=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function pp(t){const e=typeof t=="number"?{index:t}:t;return e.align||(e.align="start"),(!e.behavior||!gN)&&(e.behavior="auto"),e.offset||(e.offset=0),e}const wr=He(([{gap:t,listRefresh:e,sizes:n,totalCount:r},{fixedFooterHeight:a,fixedHeaderHeight:i,footerHeight:o,headerHeight:s,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:_},{log:p}])=>{const m=Ge(),E=Ge(),f=ne(0);let g=null,S=null,b=null;function h(){g&&(g(),g=null),b&&(b(),b=null),S&&(clearTimeout(S),S=null),we(l,!1)}return fe(j(m,Le(n,_,r,f,s,o,p),Le(t,i,a),_e(([[N,R,C,v,O,x,w,L],H,z,P])=>{const G=pp(N),{align:I,behavior:U,offset:M}=G,k=v-1,Y=dp(G,R,k);let W=Dr(Y,R.offsetTree,H)+x;I==="end"?(W+=z+Ht(R.sizeTree,Y)[1]-C+P,Y===k&&(W+=w)):I==="center"?W+=(z+Ht(R.sizeTree,Y)[1]-C+P)/2:W-=O,M&&(W+=M);const re=q=>{h(),q?(L("retrying to scroll to",{location:N},Ct.DEBUG),we(m,N)):(we(E,!0),L("list did not change, scroll successful",{},Ct.DEBUG))};if(h(),U==="smooth"){let q=!1;b=We(e,X=>{q=q||X}),g=Yt(d,()=>{re(q)})}else g=Yt(j(e,EN(150)),re);return S=setTimeout(()=>{h()},1200),we(l,!0),L("scrolling from index to",{behavior:U,index:Y,top:W},Ct.DEBUG),{behavior:U,top:W}})),c),{scrollTargetReached:E,scrollToIndex:m,topListHeight:f}},et(Jt,bt,bn),{singleton:!0});function EN(t){return e=>{const n=setTimeout(()=>{e(!1)},t);return r=>{r&&(e(!0),clearTimeout(n))}}}function vo(t,e){t==0?e():requestAnimationFrame(()=>{vo(t-1,e)})}function No(t,e){const n=e-1;return typeof t=="number"?t:t.index==="LAST"?n:t.index}const Mr=He(([{defaultItemSize:t,listRefresh:e,sizes:n},{scrollTop:r},{scrollTargetReached:a,scrollToIndex:i},{didMount:o}])=>{const s=ne(!0),l=ne(0),c=ne(!0);return fe(j(o,Le(l),Oe(([d,_])=>!!_),Xt(!1)),s),fe(j(o,Le(l),Oe(([d,_])=>!!_),Xt(!1)),c),We(j(dt(e,o),Le(s,n,t,c),Oe(([[,d],_,{sizeTree:p},m,E])=>d&&(!Xe(p)||po(m))&&!_&&!E),Le(l)),([,d])=>{Yt(a,()=>{we(c,!0)}),vo(4,()=>{Yt(r,()=>{we(s,!0)}),we(i,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:s}},et(Jt,bt,wr,hn),{singleton:!0});function mp(t,e){return Math.abs(t-e)<1.01}const Lr="up",Pr="down",fN="none",SN={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},bN=0,kr=He(([{footerHeight:t,headerHeight:e,scrollBy:n,scrollContainerState:r,scrollTop:a,viewportHeight:i}])=>{const o=ne(!1),s=ne(!0),l=Ge(),c=Ge(),d=ne(4),_=ne(bN),p=gt(j(go(j(Ne(a),Pn(1),Xt(!0)),j(Ne(a),Pn(1),Xt(!1),X_(100))),tt()),!1),m=gt(j(go(j(n,Xt(!0)),j(n,Xt(!1),X_(200))),tt()),!1);fe(j(dt(Ne(a),Ne(_)),_e(([b,h])=>b<=h),tt()),s),fe(j(s,dn(50)),c);const E=Ot(j(dt(r,Ne(i),Ne(e),Ne(t),Ne(d)),Zt((b,[{scrollHeight:h,scrollTop:N},R,C,v,O])=>{const x=N+R-h>-O,w={scrollHeight:h,scrollTop:N,viewportHeight:R};if(x){let H,z;return N>b.state.scrollTop?(H="SCROLLED_DOWN",z=b.state.scrollTop-N):(H="SIZE_DECREASED",z=b.state.scrollTop-N||b.scrollTopDelta),{atBottom:!0,atBottomBecause:H,scrollTopDelta:z,state:w}}let L;return w.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":R<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":N<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:w}},SN),tt((b,h)=>b&&b.atBottom===h.atBottom))),f=gt(j(r,Zt((b,{scrollHeight:h,scrollTop:N,viewportHeight:R})=>{if(mp(b.scrollHeight,h))return{changed:!1,jump:0,scrollHeight:h,scrollTop:N};{const C=h-(N+R)<1;return b.scrollTop!==N&&C?{changed:!0,jump:b.scrollTop-N,scrollHeight:h,scrollTop:N}:{changed:!0,jump:0,scrollHeight:h,scrollTop:N}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Oe(b=>b.changed),_e(b=>b.jump)),0);fe(j(E,_e(b=>b.atBottom)),o),fe(j(o,dn(50)),l);const g=ne(Pr);fe(j(r,_e(({scrollTop:b})=>b),tt(),Zt((b,h)=>lt(m)?{direction:b.direction,prevScrollTop:h}:{direction:h<b.prevScrollTop?Lr:Pr,prevScrollTop:h},{direction:Pr,prevScrollTop:0}),_e(b=>b.direction)),g),fe(j(r,dn(50),Xt(fN)),g);const S=ne(0);return fe(j(p,Oe(b=>!b),Xt(0)),S),fe(j(a,dn(100),Le(p),Oe(([b,h])=>!!h),Zt(([b,h],[N])=>[h,N],[0,0]),_e(([b,h])=>h-b)),S),{atBottomState:E,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:_,isAtBottom:o,isAtTop:s,isScrolling:p,lastJumpDueToItemResize:f,scrollDirection:g,scrollVelocity:S}},et(bt)),Oa="top",ya="bottom",gp="none";function Ep(t,e,n){return typeof t=="number"?n===Lr&&e===Oa||n===Pr&&e===ya?t:0:n===Lr?e===Oa?t.main:t.reverse:e===ya?t.main:t.reverse}function fp(t,e){var n;return typeof t=="number"?t:(n=t[e])!=null?n:0}const Oo=He(([{deviation:t,fixedHeaderHeight:e,headerHeight:n,scrollTop:r,viewportHeight:a}])=>{const i=Ge(),o=ne(0),s=ne(0),l=ne(0),c=gt(j(dt(Ne(r),Ne(a),Ne(n),Ne(i,xr),Ne(l),Ne(o),Ne(e),Ne(t),Ne(s)),_e(([d,_,p,[m,E],f,g,S,b,h])=>{const N=d-b,R=g+S,C=Math.max(p-N,0);let v=gp;const O=fp(h,Oa),x=fp(h,ya);return m-=b,m+=p+S,E+=p+S,E-=b,m>d+R-O&&(v=Lr),E<d-C+_+x&&(v=Pr),v!==gp?[Math.max(N-p-Ep(f,Oa,v)-O,0),N-C-S+_+Ep(f,ya,v)+x]:null}),Oe(d=>d!=null),tt(xr)),[0,0]);return{increaseViewportBy:s,listBoundary:i,overscan:l,topListHeight:o,visibleRange:c}},et(bt),{singleton:!0});function TN(t,e,n){if(Na(e)){const r=cp(t,e);return[{index:Ht(e.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:t,offset:0,size:0}]}const yo={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ia(t,e,n,r,a,i){const{lastIndex:o,lastOffset:s,lastSize:l}=a;let c=0,d=0;if(t.length>0){c=t[0].offset;const f=t[t.length-1];d=f.offset+f.size}const _=n-o,p=s+_*l+(_-1)*r,m=c,E=p-d;return{bottom:d,firstItemIndex:i,items:bp(t,a,i),offsetBottom:E,offsetTop:c,top:m,topItems:bp(e,a,i),topListHeight:e.reduce((f,g)=>g.size+f,0),totalCount:n}}function Sp(t,e,n,r,a,i){let o=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-o>=t)break;o++}const s=t+o,l=No(e,s),c=Array.from({length:s}).map((d,_)=>({data:i[_+l],index:_+l,offset:0,size:0}));return Ia(c,[],s,a,n,r)}function bp(t,e,n){if(t.length===0)return[];if(!Na(e))return t.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=t[0].index,a=t[t.length-1].index,i=[],o=Ra(e.groupOffsetTree,r,a);let s,l=0;for(const c of t){(!s||s.end<c.index)&&(s=o.shift(),l=e.groupIndices.indexOf(s.start));let d;c.index===s.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},i.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return i}const Fn=He(([{data:t,firstItemIndex:e,gap:n,sizes:r,totalCount:a},i,{listBoundary:o,topListHeight:s,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:_},p,{didMount:m},{recalcInProgress:E}])=>{const f=ne([]),g=ne(0),S=Ge();fe(i.topItemsIndexes,f);const b=gt(j(dt(m,E,Ne(l,xr),Ne(a),Ne(r),Ne(c),d,Ne(f),Ne(e),Ne(n),t),Oe(([C,v,,O,,,,,,,x])=>{const w=x&&x.length!==O;return C&&!v&&!w}),_e(([,,[C,v],O,x,w,L,H,z,P,G])=>{const I=x,{offsetTree:U,sizeTree:M}=I,k=lt(g);if(O===0)return{...yo,totalCount:O};if(C===0&&v===0)return k===0?{...yo,totalCount:O}:Sp(k,w,x,z,P,G||[]);if(Xe(M))return k>0?null:Ia(TN(No(w,O),I,G),[],O,P,I,z);const Y=[];if(H.length>0){const ce=H[0],ge=H[H.length-1];let V=0;for(const F of Ra(M,ce,ge)){const K=F.value,te=Math.max(F.start,ce),le=Math.min(F.end,ge);for(let oe=te;oe<=le;oe++)Y.push({data:G==null?void 0:G[oe],index:oe,offset:V,size:K}),V+=K}}if(!L)return Ia([],Y,O,P,I,z);const W=H.length>0?H[H.length-1]+1:0,re=lN(U,C,v,W);if(re.length===0)return null;const q=O-1,X=ha([],ce=>{for(const ge of re){const V=ge.value;let F=V.offset,K=ge.start;const te=V.size;if(V.offset<C){K+=Math.floor((C-V.offset+P)/(te+P));const oe=K-ge.start;F+=oe*te+oe*P}K<W&&(F+=(W-K)*te,K=W);const le=Math.min(ge.end,q);for(let oe=K;oe<=le&&!(F>=v);oe++)ce.push({data:G==null?void 0:G[oe],index:oe,offset:F,size:te}),F+=te+P}});return Ia(X,Y,O,P,I,z)}),Oe(C=>C!==null),tt()),yo);fe(j(t,Oe(po),_e(C=>C==null?void 0:C.length)),a),fe(j(b,_e(C=>C.topListHeight)),_),fe(_,s),fe(j(b,_e(C=>[C.top,C.bottom])),o),fe(j(b,_e(C=>C.items)),S);const h=Ot(j(b,Oe(({items:C})=>C.length>0),Le(a,t),Oe(([{items:C},v])=>C[C.length-1].originalIndex===v-1),_e(([,C,v])=>[C-1,v]),tt(xr),_e(([C])=>C))),N=Ot(j(b,dn(200),Oe(({items:C,topItems:v})=>C.length>0&&C[0].originalIndex===v.length),_e(({items:C})=>C[0].index),tt())),R=Ot(j(b,Oe(({items:C})=>C.length>0),_e(({items:C})=>{let v=0,O=C.length-1;for(;C[v].type==="group"&&v<O;)v++;for(;C[O].type==="group"&&O>v;)O--;return{endIndex:C[O].index,startIndex:C[v].index}}),tt(sp)));return{endReached:h,initialItemCount:g,itemsRendered:S,listState:b,rangeChanged:R,startReached:N,topItemsIndexes:f,...p}},et(Jt,_p,Oo,Mr,wr,kr,hn,ho),{singleton:!0}),Tp=He(([{fixedFooterHeight:t,fixedHeaderHeight:e,footerHeight:n,headerHeight:r},{listState:a}])=>{const i=Ge(),o=gt(j(dt(n,t,r,e,a),_e(([s,l,c,d,_])=>s+l+c+d+_.offsetBottom+_.bottom)),0);return fe(Ne(o),i),{totalListHeight:o,totalListHeightChanged:i}},et(bt,Fn),{singleton:!0}),hN=He(([{viewportHeight:t},{totalListHeight:e}])=>{const n=ne(!1),r=gt(j(dt(n,t,e),Oe(([a])=>a),_e(([,a,i])=>Math.max(0,a-i)),dn(0),tt()),0);return{alignToBottom:n,paddingTopAddition:r}},et(bt,Tp),{singleton:!0}),hp=He(()=>({context:ne(null)})),RN=({itemBottom:t,itemTop:e,locationParams:{align:n,behavior:r,...a},viewportBottom:i,viewportTop:o})=>e<o?{...a,align:n??"start",behavior:r}:t>i?{...a,align:n??"end",behavior:r}:null,Rp=He(([{gap:t,sizes:e,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:a,headerHeight:i,scrollingInProgress:o,scrollTop:s,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ge();return fe(j(d,Le(e,l,n,i,a,r,s),Le(t),_e(([[_,p,m,E,f,g,S,b],h])=>{const{align:N,behavior:R,calculateViewLocation:C=RN,done:v,...O}=_,x=dp(_,p,E-1),w=Dr(x,p.offsetTree,h)+f+g,L=w+Ht(p.sizeTree,x)[1],H=b+g,z=b+m-S,P=C({itemBottom:L,itemTop:w,locationParams:{align:N,behavior:R,...O},viewportBottom:z,viewportTop:H});return P?v&&Yt(j(o,Oe(G=>!G),Pn(lt(o)?1:2)),v):v&&v(),P}),Oe(_=>_!==null)),c),{scrollIntoView:d}},et(Jt,bt,wr,Fn,bn),{singleton:!0});function Cp(t){return t?t==="smooth"?"smooth":"auto":!1}const CN=(t,e)=>typeof t=="function"?Cp(t(e)):e&&Cp(t),vN=He(([{listRefresh:t,totalCount:e,fixedItemSize:n,data:r},{atBottomState:a,isAtBottom:i},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:_},{context:p},{scrollIntoView:m}])=>{const E=ne(!1),f=Ge();let g=null;function S(R){we(o,{align:"end",behavior:R,index:"LAST"})}We(j(dt(j(Ne(e),Pn(1)),l),Le(Ne(E),i,s,_),_e(([[R,C],v,O,x,w])=>{let L=C&&x,H="auto";return L&&(H=CN(v,O||w),L=L&&!!H),{followOutputBehavior:H,shouldFollow:L,totalCount:R}}),Oe(({shouldFollow:R})=>R)),({followOutputBehavior:R,totalCount:C})=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("following output to ",{totalCount:C},Ct.DEBUG),S(R)}):g=Yt(t,()=>{lt(d)("following output to ",{totalCount:C},Ct.DEBUG),S(R),g=null})});function b(R){const C=Yt(a,v=>{R&&!v.atBottom&&v.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(lt(d)("scrolling to bottom due to increased size",{},Ct.DEBUG),S("auto"))});setTimeout(C,100)}We(j(dt(Ne(E),e,c),Oe(([R,,C])=>R&&C),Zt(({value:R},[,C])=>({refreshed:R===C,value:C}),{refreshed:!1,value:0}),Oe(({refreshed:R})=>R),Le(E,e)),([,R])=>{lt(s)&&b(R!==!1)}),We(f,()=>{b(lt(E)!==!1)}),We(dt(Ne(E),a),([R,C])=>{R&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&S("auto")});const h=ne(null),N=Ge();return fe(go(j(Ne(r),_e(R=>{var C;return(C=R==null?void 0:R.length)!=null?C:0})),j(Ne(e))),N),We(j(dt(j(N,Pn(1)),l),Le(Ne(h),s,_,p),_e(([[R,C],v,O,x,w])=>C&&O&&(v==null?void 0:v({context:w,totalCount:R,scrollingInProgress:x}))),Oe(R=>!!R),dn(0)),R=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("scrolling into view",{}),we(m,R)}):g=Yt(t,()=>{lt(d)("scrolling into view",{}),we(m,R),g=null})}),{autoscrollToBottom:f,followOutput:E,scrollIntoViewOnChange:h}},et(Jt,kr,wr,Mr,hn,bn,bt,hp,Rp)),NN=He(([{data:t,firstItemIndex:e,gap:n,sizes:r},{initialTopMostItemIndex:a},{initialItemCount:i,listState:o},{didMount:s}])=>(fe(j(s,Le(i),Oe(([,l])=>l!==0),Le(a,r,e,n,t),_e(([[,l],c,d,_,p,m=[]])=>Sp(l,c,d,_,p,m))),o),{}),et(Jt,Mr,Fn,hn),{singleton:!0}),ON=He(([{didMount:t},{scrollTo:e},{listState:n}])=>{const r=ne(0);return We(j(t,Le(r),Oe(([,a])=>a!==0),_e(([,a])=>({top:a}))),a=>{Yt(j(n,Pn(1),Oe(i=>i.items.length>1)),()=>{requestAnimationFrame(()=>{we(e,a)})})}),{initialScrollTop:r}},et(hn,bt,Fn),{singleton:!0}),vp=He(([{scrollVelocity:t}])=>{const e=ne(!1),n=Ge(),r=ne(!1);return fe(j(t,Le(r,e,n),Oe(([a,i])=>!!i),_e(([a,i,o,s])=>{const{enter:l,exit:c}=i;if(o){if(c(a,s))return!1}else if(l(a,s))return!0;return o}),tt()),e),We(j(dt(e,t,n),Le(r)),([[a,i,o],s])=>{a&&s&&s.change&&s.change(i,o)}),{isSeeking:e,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:t}},et(kr),{singleton:!0}),Io=He(([{scrollContainerState:t,scrollTo:e}])=>{const n=Ge(),r=Ge(),a=Ge(),i=ne(!1),o=ne(void 0);return fe(j(dt(n,r),_e(([{scrollHeight:s,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:s,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),fe(j(e,Le(r),_e(([s,{offsetTop:l}])=>({...s,top:s.top+l}))),a),{customScrollParent:o,useWindowScroll:i,windowScrollContainerState:n,windowScrollTo:a,windowViewportRect:r}},et(bt)),yN=He(([{sizeRanges:t,sizes:e},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:a},{didMount:i},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:l}])=>{const c=Ge(),d=ne(void 0),_=ne(null),p=ne(null);return fe(s,_),fe(l,p),We(j(c,Le(e,r,o,_,p,n)),([m,E,f,g,S,b,h])=>{const N=dN(E.sizeTree);g&&S!==null&&b!==null&&(f=S.scrollTop-b.offsetTop),f-=h,m({ranges:N,scrollTop:f})}),fe(j(d,Oe(po),_e(IN)),a),fe(j(i,Le(d),Oe(([,m])=>m!==void 0),tt(),_e(([,m])=>m.ranges)),t),{getState:c,restoreStateFrom:d}},et(Jt,bt,Mr,hn,Io));function IN(t){return{align:"start",index:0,offset:t.scrollTop}}const AN=He(([{topItemsIndexes:t}])=>{const e=ne(0);return fe(j(e,Oe(n=>n>=0),_e(n=>Array.from({length:n}).map((r,a)=>a))),t),{topItemCount:e}},et(Fn));function Np(t){let e=!1,n;return()=>(e||(e=!0,n=t()),n)}const xN=Np(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),DN=He(([{deviation:t,scrollBy:e,scrollingInProgress:n,scrollTop:r},{isAtBottom:a,isScrolling:i,lastJumpDueToItemResize:o,scrollDirection:s},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:_,sizes:p},{log:m},{recalcInProgress:E}])=>{const f=Ot(j(l,Le(o),Zt(([,S,b,h],[{bottom:N,items:R,offsetBottom:C,totalCount:v},O])=>{const x=N+C;let w=0;return b===v&&S.length>0&&R.length>0&&(R[0].originalIndex===0&&S[0].originalIndex===0||(w=x-h,w!==0&&(w+=O))),[w,R,v,x]},[0,[],0,0]),Oe(([S])=>S!==0),Le(r,s,n,a,m,E),Oe(([,S,b,h,,,N])=>!N&&!h&&S!==0&&b===Lr),_e(([[S],,,,,b])=>(b("Upward scrolling compensation",{amount:S},Ct.DEBUG),S))));function g(S){S>0?(we(e,{behavior:"auto",top:-S}),we(t,0)):(we(t,0),we(e,{behavior:"auto",top:-S}))}return We(j(f,Le(t,i)),([S,b,h])=>{h&&xN()?we(t,b-S):g(-S)}),We(j(dt(gt(i,!1),t,E),Oe(([S,b,h])=>!S&&!h&&b!==0),_e(([S,b])=>b),dn(1)),g),fe(j(_,_e(S=>({top:-S}))),e),We(j(c,Le(p,d),_e(([S,{groupIndices:b,lastSize:h,sizeTree:N},R])=>{function C(v){return v*(h+R)}if(b.length===0)return C(S);{let v=0;const O=Ar(N,0);let x=0,w=0;for(;x<S;){x++,v+=O;let L=b.length===w+1?1/0:b[w+1]-b[w]-1;x+L>S&&(v-=O,L=S-x+1),x+=L,v+=C(L),w++}return v}})),S=>{we(t,S),requestAnimationFrame(()=>{we(e,{top:S}),requestAnimationFrame(()=>{we(t,0),we(E,!1)})})}),{deviation:t}},et(bt,kr,Fn,Jt,bn,ho)),wN=He(([t,e,n,r,a,i,o,s,l,c,d])=>({...t,...e,...n,...r,...a,...i,...o,...s,...l,...c,...d}),et(Oo,NN,hn,vp,Tp,ON,hN,Io,Rp,bn,hp)),Op=He(([{data:t,defaultItemSize:e,firstItemIndex:n,fixedItemSize:r,gap:a,groupIndices:i,itemSize:o,sizeRanges:s,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:_},{initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E},f,g,S,{listState:b,topItemsIndexes:h,...N},{scrollToIndex:R},C,{topItemCount:v},{groupCounts:O},x])=>(fe(N.rangeChanged,x.scrollSeekRangeChanged),fe(j(x.windowViewportRect,_e(w=>w.visibleHeight)),f.viewportHeight),{data:t,defaultItemHeight:e,firstItemIndex:n,fixedItemHeight:r,gap:a,groupCounts:O,initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E,sizeRanges:s,topItemCount:v,topItemsIndexes:h,totalCount:d,...S,groupIndices:i,itemSize:o,listState:b,scrollToIndex:R,statefulTotalCount:c,trackItemSizes:_,...N,...x,...f,sizes:l,...g}),et(Jt,Mr,bt,yN,vN,Fn,wr,DN,AN,_p,wN));function MN(t,e){const n={},r={};let a=0;const i=t.length;for(;a<i;)r[t[a]]=1,a+=1;for(const o in e)Object.hasOwn(r,o)||(n[o]=e[o]);return n}const Aa=typeof document<"u"?y.useLayoutEffect:y.useEffect;function yp(t,e,n){const r=Object.keys(e.required||{}),a=Object.keys(e.optional||{}),i=Object.keys(e.methods||{}),o=Object.keys(e.events||{}),s=y.createContext({});function l(g,S){g.propsReady&&we(g.propsReady,!1);for(const b of r){const h=g[e.required[b]];we(h,S[b])}for(const b of a)if(b in S){const h=g[e.optional[b]];we(h,S[b])}g.propsReady&&we(g.propsReady,!0)}function c(g){return i.reduce((S,b)=>(S[b]=h=>{const N=g[e.methods[b]];we(N,h)},S),{})}function d(g){return o.reduce((S,b)=>(S[b]=Qv(g[e.events[b]]),S),{})}const _=y.forwardRef((g,S)=>{const{children:b,...h}=g,[N]=y.useState(()=>ha(Xv(t),v=>{l(v,h)})),[R]=y.useState(j_(d,N));Aa(()=>{for(const v of o)v in h&&We(R[v],h[v]);return()=>{Object.values(R).map(mo)}},[h,R,N]),Aa(()=>{l(N,h)}),y.useImperativeHandle(S,K_(c(N)));const C=n;return u.jsx(s.Provider,{value:N,children:n?u.jsx(C,{...MN([...r,...a,...o],h),children:b}):b})}),p=g=>{const S=y.useContext(s);return y.useCallback(b=>{we(S[g],b)},[S,g])},m=g=>{const S=y.useContext(s)[g],b=y.useCallback(h=>We(S,h),[S]);return y.useSyncExternalStore(b,()=>lt(S),()=>lt(S))},E=g=>{const S=y.useContext(s)[g],[b,h]=y.useState(j_(lt,S));return Aa(()=>We(S,N=>{N!==b&&h(K_(N))}),[S,b]),b},f=y.version.startsWith("18")?m:E;return{Component:_,useEmitter:(g,S)=>{const b=y.useContext(s)[g];Aa(()=>We(b,S),[S,b])},useEmitterValue:f,usePublisher:p}}const Ip=y.createContext(void 0),Ap=y.createContext(void 0),xp=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Ao(t){return"self"in t}function LN(t){return"body"in t}function Dp(t,e,n,r=er,a,i){const o=y.useRef(null),s=y.useRef(null),l=y.useRef(null),c=y.useCallback(p=>{let m,E,f;const g=p.target;if(LN(g)||Ao(g)){const b=Ao(g)?g:g.defaultView;f=i?b.scrollX:b.scrollY,m=i?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,E=i?b.innerWidth:b.innerHeight}else f=i?g.scrollLeft:g.scrollTop,m=i?g.scrollWidth:g.scrollHeight,E=i?g.offsetWidth:g.offsetHeight;const S=()=>{t({scrollHeight:m,scrollTop:Math.max(f,0),viewportHeight:E})};p.suppressFlushSync?S():$i.flushSync(S),s.current!==null&&(f===s.current||f<=0||f===m-E)&&(s.current=null,e(!0),l.current&&(clearTimeout(l.current),l.current=null))},[t,e,i]);y.useEffect(()=>{const p=a||o.current;return r(a||o.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[o,c,n,r,a]);function d(p){const m=o.current;if(!m||(i?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const E=p.behavior==="smooth";let f,g,S;Ao(m)?(g=Math.max(Tn(m.document.documentElement,i?"width":"height"),i?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),f=i?m.innerWidth:m.innerHeight,S=i?window.scrollX:window.scrollY):(g=m[i?"scrollWidth":"scrollHeight"],f=Tn(m,i?"width":"height"),S=m[i?"scrollLeft":"scrollTop"]);const b=g-f;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),mp(f,g)||p.top===S){t({scrollHeight:g,scrollTop:S,viewportHeight:f}),E&&e(!0);return}E?(s.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,s.current=null,e(!0)},1e3)):s.current=null,i&&(p={behavior:p.behavior,left:p.top}),m.scrollTo(p)}function _(p){i&&(p={behavior:p.behavior,left:p.top}),o.current.scrollBy(p)}return{scrollByCallback:_,scrollerRef:o,scrollToCallback:d}}const xo="-webkit-sticky",wp="sticky",Do=Np(()=>{if(typeof document>"u")return wp;const t=document.createElement("div");return t.style.position=xo,t.style.position===xo?xo:wp});function wo(t){return t}const PN=He(()=>{const t=ne(s=>`Item ${s}`),e=ne(s=>`Group ${s}`),n=ne({}),r=ne(wo),a=ne("div"),i=ne(er),o=(s,l=null)=>gt(j(n,_e(c=>c[s]),tt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:o("EmptyPlaceholder"),FooterComponent:o("Footer"),GroupComponent:o("Group","div"),groupContent:e,HeaderComponent:o("Header"),HeaderFooterTag:a,ItemComponent:o("Item","div"),itemContent:t,ListComponent:o("List","div"),ScrollerComponent:o("Scroller","div"),scrollerRef:i,ScrollSeekPlaceholder:o("ScrollSeekPlaceholder"),TopItemListComponent:o("TopItemList")}}),kN=He(([t,e])=>({...t,...e}),et(Op,PN)),UN=({height:t})=>u.jsx("div",{style:{height:t}}),FN={overflowAnchor:"none",position:Do(),zIndex:1},Mp={overflowAnchor:"none"},BN={...Mp,display:"inline-block",height:"100%"},Lp=y.memo(function({showTopList:t=!1}){const e=xe("listState"),n=Pt("sizeRanges"),r=xe("useWindowScroll"),a=xe("customScrollParent"),i=Pt("windowScrollContainerState"),o=Pt("scrollContainerState"),s=a||r?i:o,l=xe("itemContent"),c=xe("context"),d=xe("groupContent"),_=xe("trackItemSizes"),p=xe("itemSize"),m=xe("log"),E=Pt("gap"),f=xe("horizontalDirection"),{callbackRef:g}=eN(n,p,_,t?er:s,m,E,a,f,xe("skipAnimationFrameInResizeObserver")),[S,b]=y.useState(0);Mo("deviation",P=>{S!==P&&b(P)});const h=xe("EmptyPlaceholder"),N=xe("ScrollSeekPlaceholder")||UN,R=xe("ListComponent"),C=xe("ItemComponent"),v=xe("GroupComponent"),O=xe("computeItemKey"),x=xe("isSeeking"),w=xe("groupIndices").length>0,L=xe("alignToBottom"),H=xe("initialItemFinalLocationReached"),z=t?{}:{boxSizing:"border-box",...f?{display:"inline-block",height:"100%",marginLeft:S!==0?S:L?"auto":0,paddingLeft:e.offsetTop,paddingRight:e.offsetBottom,whiteSpace:"nowrap"}:{marginTop:S!==0?S:L?"auto":0,paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},...H?{}:{visibility:"hidden"}};return!t&&e.totalCount===0&&h?u.jsx(h,{...Et(h,c)}):u.jsx(R,{...Et(R,c),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:z,children:(t?e.topItems:e.items).map(P=>{const G=P.originalIndex,I=O(G+e.firstItemIndex,P.data,c);return x?y.createElement(N,{...Et(N,c),height:P.size,index:P.index,key:I,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?y.createElement(v,{...Et(v,c),"data-index":G,"data-item-index":P.index,"data-known-size":P.size,key:I,style:FN},d(P.index,c)):y.createElement(C,{...Et(C,c),...qN(C,P.data),"data-index":G,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:I,style:f?BN:Mp},w?l(P.index,P.groupIndex,P.data,c):l(P.index,P.data,c))})})}),GN={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},YN={outline:"none",overflowX:"auto",position:"relative"},xa=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:{}}),HN={position:Do(),top:0,width:"100%",zIndex:1};function Et(t,e){if(typeof t!="string")return{context:e}}function qN(t,e){return{item:typeof t=="string"?void 0:e}}const VN=y.memo(function(){const t=xe("HeaderComponent"),e=Pt("headerHeight"),n=xe("HeaderFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,xe("skipAnimationFrameInResizeObserver")),a=xe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null}),zN=y.memo(function(){const t=xe("FooterComponent"),e=Pt("footerHeight"),n=xe("HeaderFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,xe("skipAnimationFrameInResizeObserver")),a=xe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null});function Pp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("scrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("scrollerRef"),_=e("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:m,scrollToCallback:E}=Dp(s,c,l,d,void 0,_);return t("scrollTo",E),t("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{..._?YN:GN,...a},tabIndex:0,...o,...Et(l,i),children:r})})}function kp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("windowScrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("totalListHeight"),_=e("deviation"),p=e("customScrollParent"),m=y.useRef(null),E=e("scrollerRef"),{scrollByCallback:f,scrollerRef:g,scrollToCallback:S}=Dp(s,c,l,E,p);return xp(()=>{var b;return g.current=p||((b=m.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,p]),t("windowScrollTo",S),t("scrollBy",f),u.jsx(l,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...a,...d!==0?{height:d+_}:{}},...o,...Et(l,i),children:r})})}const $N=({children:t})=>{const e=y.useContext(Ip),n=Pt("viewportHeight"),r=Pt("fixedItemHeight"),a=xe("alignToBottom"),i=xe("horizontalDirection"),o=y.useMemo(()=>Q_(n,l=>Tn(l,i?"width":"height")),[n,i]),s=kn(o,!0,xe("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{e&&(n(e.viewportHeight),r(e.itemHeight))},[e,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:s,style:xa(a),children:t})},WN=({children:t})=>{const e=y.useContext(Ip),n=Pt("windowViewportRect"),r=Pt("fixedItemHeight"),a=xe("customScrollParent"),i=ep(n,a,xe("skipAnimationFrameInResizeObserver")),o=xe("alignToBottom");return y.useEffect(()=>{e&&(r(e.itemHeight),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:100}))},[e,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:i,style:xa(o),children:t})},KN=({children:t})=>{const e=xe("TopItemListComponent")||"div",n=xe("headerHeight"),r={...HN,marginTop:`${n}px`},a=xe("context");return u.jsx(e,{style:r,...Et(e,a),children:t})},QN=y.memo(function(t){const e=xe("useWindowScroll"),n=xe("topItemsIndexes").length>0,r=xe("customScrollParent"),a=xe("context");return u.jsxs(r||e?ZN:XN,{...t,context:a,children:[n&&u.jsx(KN,{children:u.jsx(Lp,{showTopList:!0})}),u.jsxs(r||e?WN:$N,{children:[u.jsx(VN,{}),u.jsx(Lp,{}),u.jsx(zN,{})]})]})}),{Component:jN,useEmitter:Mo,useEmitterValue:xe,usePublisher:Pt}=yp(kN,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},QN),XN=Pp({useEmitter:Mo,useEmitterValue:xe,usePublisher:Pt}),ZN=kp({useEmitter:Mo,useEmitterValue:xe,usePublisher:Pt}),JN=jN;et(Op,He(()=>{const t=ne(c=>u.jsxs("td",{children:["Item $",c]})),e=ne(null),n=ne(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ne(null),a=ne(null),i=ne({}),o=ne(wo),s=ne(er),l=(c,d=null)=>gt(j(i,_e(_=>_[c]),tt()),d);return{components:i,computeItemKey:o,context:e,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:a,fixedHeaderContent:r,itemContent:t,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Do();const Up={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},eO={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Fp,floor:Da,max:Ur,min:Lo,round:Bp}=Math;function Gp(t,e,n){return Array.from({length:e-t+1}).map((r,a)=>({data:n===null?null:n[a+t],index:a+t}))}function tO(t){return{...eO,items:t}}function wa(t,e){return t&&t.width===e.width&&t.height===e.height}function nO(t,e){return t&&t.column===e.column&&t.row===e.row}const rO=He(([{increaseViewportBy:t,listBoundary:e,overscan:n,visibleRange:r},{footerHeight:a,headerHeight:i,scrollBy:o,scrollContainerState:s,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:_},p,m,{didMount:E,propsReady:f},{customScrollParent:g,useWindowScroll:S,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:N},R])=>{const C=ne(0),v=ne(0),O=ne(Up),x=ne({height:0,width:0}),w=ne({height:0,width:0}),L=Ge(),H=Ge(),z=ne(0),P=ne(null),G=ne({column:0,row:0}),I=Ge(),U=Ge(),M=ne(!1),k=ne(0),Y=ne(!0),W=ne(!1),re=ne(!1);We(j(E,Le(k),Oe(([F,K])=>!!K)),()=>{we(Y,!1)}),We(j(dt(E,Y,w,x,k,W),Oe(([F,K,te,le,,oe])=>F&&!K&&te.height!==0&&le.height!==0&&!oe)),([,,,,F])=>{we(W,!0),vo(1,()=>{we(L,F)}),Yt(j(c),()=>{we(e,[0,0]),we(Y,!0)})}),fe(j(U,Oe(F=>F!=null&&F.scrollTop>0),Xt(0)),v),We(j(E,Le(U),Oe(([,F])=>F!=null)),([,F])=>{F&&(we(x,F.viewport),we(w,F.item),we(G,F.gap),F.scrollTop>0&&(we(M,!0),Yt(j(c,Pn(1)),K=>{we(M,!1)}),we(l,{top:F.scrollTop})))}),fe(j(x,_e(({height:F})=>F)),_),fe(j(dt(Ne(x,wa),Ne(w,wa),Ne(G,(F,K)=>F&&F.column===K.column&&F.row===K.row),Ne(c)),_e(([F,K,te,le])=>({gap:te,item:K,scrollTop:le,viewport:F}))),I),fe(j(dt(Ne(C),r,Ne(G,nO),Ne(w,wa),Ne(x,wa),Ne(P),Ne(v),Ne(M),Ne(Y),Ne(k)),Oe(([,,,,,,,F])=>!F),_e(([F,[K,te],le,oe,Ae,qe,Me,,Se,Be])=>{const{column:ee,row:Q}=le,{height:ae,width:be}=oe,{width:Je}=Ae;if(Me===0&&(F===0||Je===0))return Up;if(be===0){const rt=No(Be,F),xt=rt+Math.max(Me-1,0);return tO(Gp(rt,xt,qe))}const Qe=Yp(Je,be,ee);let at,Ke;Se?K===0&&te===0&&Me>0?(at=0,Ke=Me-1):(at=Qe*Da((K+Q)/(ae+Q)),Ke=Qe*Fp((te+Q)/(ae+Q))-1,Ke=Lo(F-1,Ur(Ke,Qe-1)),at=Lo(Ke,Ur(0,at))):(at=0,Ke=-1);const Z=Gp(at,Ke,qe),{bottom:se,top:Ee}=Hp(Ae,le,oe,Z),he=Fp(F/Qe),Ue=he*ae+(he-1)*Q-se;return{bottom:se,itemHeight:ae,items:Z,itemWidth:be,offsetBottom:Ue,offsetTop:Ee,top:Ee}})),O),fe(j(P,Oe(F=>F!==null),_e(F=>F.length)),C),fe(j(dt(x,w,O,G),Oe(([F,K,{items:te}])=>te.length>0&&K.height!==0&&F.height!==0),_e(([F,K,{items:te},le])=>{const{bottom:oe,top:Ae}=Hp(F,le,K,te);return[Ae,oe]}),tt(xr)),e);const q=ne(!1);fe(j(c,Le(q),_e(([F,K])=>K||F!==0)),q);const X=Ot(j(dt(O,C),Oe(([{items:F}])=>F.length>0),Le(q),Oe(([[F,K],te])=>{const le=F.items[F.items.length-1].index===K-1;return(te||F.bottom>0&&F.itemHeight>0&&F.offsetBottom===0&&F.items.length===K)&&le}),_e(([[,F]])=>F-1),tt())),ce=Ot(j(Ne(O),Oe(({items:F})=>F.length>0&&F[0].index===0),Xt(0),tt())),ge=Ot(j(Ne(O),Le(M),Oe(([{items:F},K])=>F.length>0&&!K),_e(([{items:F}])=>({endIndex:F[F.length-1].index,startIndex:F[0].index})),tt(sp),dn(0)));fe(ge,m.scrollSeekRangeChanged),fe(j(L,Le(x,w,C,G),_e(([F,K,te,le,oe])=>{const Ae=pp(F),{align:qe,behavior:Me,offset:Se}=Ae;let Be=Ae.index;Be==="LAST"&&(Be=le-1),Be=Ur(0,Be,Lo(le-1,Be));let ee=Po(K,oe,te,Be);return qe==="end"?ee=Bp(ee-K.height+te.height):qe==="center"&&(ee=Bp(ee-K.height/2+te.height/2)),Se&&(ee+=Se),{behavior:Me,top:ee}})),l);const V=gt(j(O,_e(F=>F.offsetBottom+F.bottom)),0);return fe(j(N,_e(F=>({height:F.visibleHeight,width:F.visibleWidth}))),x),{customScrollParent:g,data:P,deviation:z,footerHeight:a,gap:G,headerHeight:i,increaseViewportBy:t,initialItemCount:v,itemDimensions:w,overscan:n,restoreStateFrom:U,scrollBy:o,scrollContainerState:s,scrollHeight:H,scrollTo:l,scrollToIndex:L,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:S,viewportDimensions:x,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:N,...m,gridState:O,horizontalDirection:re,initialTopMostItemIndex:k,totalListHeight:V,...p,endReached:X,propsReady:f,rangeChanged:ge,startReached:ce,stateChanged:I,stateRestoreInProgress:M,...R}},et(Oo,bt,kr,vp,hn,Io,bn));function Yp(t,e,n){return Ur(1,Da((t+n)/(Da(e)+n)))}function Hp(t,e,n,r){const{height:a}=n;if(a===void 0||r.length===0)return{bottom:0,top:0};const i=Po(t,e,n,r[0].index);return{bottom:Po(t,e,n,r[r.length-1].index)+a,top:i}}function Po(t,e,n,r){const a=Yp(t.width,n.width,e.column),i=Da(r/a),o=i*n.height+Ur(0,i-1)*e.row;return o>0?o+e.row:o}const aO=He(()=>{const t=ne(_=>`Item ${_}`),e=ne({}),n=ne(null),r=ne("virtuoso-grid-item"),a=ne("virtuoso-grid-list"),i=ne(wo),o=ne("div"),s=ne(er),l=(_,p=null)=>gt(j(e,_e(m=>m[_]),tt()),p),c=ne(!1),d=ne(!1);return fe(Ne(d),c),{components:e,computeItemKey:i,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:o,itemClassName:r,ItemComponent:l("Item","div"),itemContent:t,listClassName:a,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),iO=He(([t,e])=>({...t,...e}),et(rO,aO)),oO=y.memo(function(){const t=nt("gridState"),e=nt("listClassName"),n=nt("itemClassName"),r=nt("itemContent"),a=nt("computeItemKey"),i=nt("isSeeking"),o=kt("scrollHeight"),s=nt("ItemComponent"),l=nt("ListComponent"),c=nt("ScrollSeekPlaceholder"),d=nt("context"),_=kt("itemDimensions"),p=kt("gap"),m=nt("log"),E=nt("stateRestoreInProgress"),f=kt("reportReadyState"),g=kn(y.useMemo(()=>S=>{const b=S.parentElement.parentElement.scrollHeight;o(b);const h=S.firstChild;if(h){const{height:N,width:R}=h.getBoundingClientRect();_({height:N,width:R})}p({column:Vp("column-gap",getComputedStyle(S).columnGap,m),row:Vp("row-gap",getComputedStyle(S).rowGap,m)})},[o,_,p,m]),!0,!1);return xp(()=>{t.itemHeight>0&&t.itemWidth>0&&f(!0)},[t]),E?null:u.jsx(l,{className:e,ref:g,...Et(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(S=>{const b=a(S.index,S.data,d);return i?u.jsx(c,{...Et(c,d),height:t.itemHeight,index:S.index,width:t.itemWidth},b):y.createElement(s,{...Et(s,d),className:n,"data-index":S.index,key:b},r(S.index,S.data,d))})})}),sO=y.memo(function(){const t=nt("HeaderComponent"),e=kt("headerHeight"),n=nt("headerFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,!1),a=nt("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null}),lO=y.memo(function(){const t=nt("FooterComponent"),e=kt("footerHeight"),n=nt("headerFooterTag"),r=kn(y.useMemo(()=>i=>{e(Tn(i,"height"))},[e]),!0,!1),a=nt("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...Et(t,a)})}):null}),cO=({children:t})=>{const e=y.useContext(Ap),n=kt("itemDimensions"),r=kt("viewportDimensions"),a=kn(y.useMemo(()=>i=>{r(i.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{e&&(r({height:e.viewportHeight,width:e.viewportWidth}),n({height:e.itemHeight,width:e.itemWidth}))},[e,r,n]),u.jsx("div",{ref:a,style:xa(!1),children:t})},dO=({children:t})=>{const e=y.useContext(Ap),n=kt("windowViewportRect"),r=kt("itemDimensions"),a=nt("customScrollParent"),i=ep(n,a,!1);return y.useEffect(()=>{e&&(r({height:e.itemHeight,width:e.itemWidth}),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:e.viewportWidth}))},[e,n,r]),u.jsx("div",{ref:i,style:xa(!1),children:t})},uO=y.memo(function({...t}){const e=nt("useWindowScroll"),n=nt("customScrollParent"),r=n||e?pO:_O,a=n||e?dO:cO,i=nt("context");return u.jsx(r,{...t,...Et(r,i),children:u.jsxs(a,{children:[u.jsx(sO,{}),u.jsx(oO,{}),u.jsx(lO,{})]})})}),{useEmitter:qp,useEmitterValue:nt,usePublisher:kt}=yp(iO,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},uO),_O=Pp({useEmitter:qp,useEmitterValue:nt,usePublisher:kt}),pO=kp({useEmitter:qp,useEmitterValue:nt,usePublisher:kt});function Vp(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,Ct.WARN),e==="normal"?0:parseInt(e??"0",10)}const mO=br.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function zp({className:t,variant:e,...n}){return u.jsx("div",{className:$(mO({variant:e}),t),...n})}function de(t,e,{checkForDefaultPrevented:n=!0}={}){return function(a){if(t==null||t(a),n===!1||!a.defaultPrevented)return e==null?void 0:e(a)}}function gO(t,e){const n=T.createContext(e),r=i=>{const{children:o,...s}=i,l=T.useMemo(()=>s,Object.values(s));return u.jsx(n.Provider,{value:l,children:o})};r.displayName=t+"Provider";function a(i){const o=T.useContext(n);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${i}\` must be used within \`${t}\``)}return[r,a]}function qt(t,e=[]){let n=[];function r(i,o){const s=T.createContext(o),l=n.length;n=[...n,o];const c=_=>{var S;const{scope:p,children:m,...E}=_,f=((S=p==null?void 0:p[t])==null?void 0:S[l])||s,g=T.useMemo(()=>E,Object.values(E));return u.jsx(f.Provider,{value:g,children:m})};c.displayName=i+"Provider";function d(_,p){var f;const m=((f=p==null?void 0:p[t])==null?void 0:f[l])||s,E=T.useContext(m);if(E)return E;if(o!==void 0)return o;throw new Error(`\`${_}\` must be used within \`${i}\``)}return[c,d]}const a=()=>{const i=n.map(o=>T.createContext(o));return function(s){const l=(s==null?void 0:s[t])||i;return T.useMemo(()=>({[`__scope${t}`]:{...s,[t]:l}}),[s,l])}};return a.scopeName=t,[r,EO(a,...e)]}function EO(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(i){const o=r.reduce((s,{useScope:l,scopeName:c})=>{const _=l(i)[`__scope${c}`];return{...s,..._}},{});return T.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return n.scopeName=e.scopeName,n}var _t=globalThis!=null&&globalThis.document?T.useLayoutEffect:()=>{},fO=T[" useInsertionEffect ".trim().toString()]||_t;function Rn({prop:t,defaultProp:e,onChange:n=()=>{},caller:r}){const[a,i,o]=SO({defaultProp:e,onChange:n}),s=t!==void 0,l=s?t:a;{const d=T.useRef(t!==void 0);T.useEffect(()=>{const _=d.current;_!==s&&console.warn(`${r} is changing from ${_?"controlled":"uncontrolled"} to ${s?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=s},[s,r])}const c=T.useCallback(d=>{var _;if(s){const p=bO(d)?d(t):d;p!==t&&((_=o.current)==null||_.call(o,p))}else i(d)},[s,t,i,o]);return[l,c]}function SO({defaultProp:t,onChange:e}){const[n,r]=T.useState(t),a=T.useRef(n),i=T.useRef(e);return fO(()=>{i.current=e},[e]),T.useEffect(()=>{var o;a.current!==n&&((o=i.current)==null||o.call(i,n),a.current=n)},[n,a]),[n,r,i]}function bO(t){return typeof t=="function"}function $p(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function ko(...t){return e=>{let n=!1;const r=t.map(a=>{const i=$p(a,e);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():$p(t[a],null)}}}}function ke(...t){return T.useCallback(ko(...t),t)}var TO=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ye=TO.reduce((t,e)=>{const n=Nt.createSlot(`Primitive.${e}`),r=T.forwardRef((a,i)=>{const{asChild:o,...s}=a,l=o?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...s,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function Wp(t,e){t&&oa.flushSync(()=>t.dispatchEvent(e))}function hO(t,e){return T.useReducer((n,r)=>e[n][r]??n,t)}var vt=t=>{const{present:e,children:n}=t,r=RO(e),a=typeof n=="function"?n({present:r.isPresent}):T.Children.only(n),i=ke(r.ref,CO(a));return typeof n=="function"||r.isPresent?T.cloneElement(a,{ref:i}):null};vt.displayName="Presence";function RO(t){const[e,n]=T.useState(),r=T.useRef(null),a=T.useRef(t),i=T.useRef("none"),o=t?"mounted":"unmounted",[s,l]=hO(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return T.useEffect(()=>{const c=Ma(r.current);i.current=s==="mounted"?c:"none"},[s]),_t(()=>{const c=r.current,d=a.current;if(d!==t){const p=i.current,m=Ma(c);t?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),a.current=t}},[t,l]),_t(()=>{if(e){let c;const d=e.ownerDocument.defaultView??window,_=m=>{const f=Ma(r.current).includes(CSS.escape(m.animationName));if(m.target===e&&f&&(l("ANIMATION_END"),!a.current)){const g=e.style.animationFillMode;e.style.animationFillMode="forwards",c=d.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=g)})}},p=m=>{m.target===e&&(i.current=Ma(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",_),e.addEventListener("animationend",_),()=>{d.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",_),e.removeEventListener("animationend",_)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:T.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Ma(t){return(t==null?void 0:t.animationName)||"none"}function CO(t){var r,a;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(a=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:a.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var vO=T[" useId ".trim().toString()]||(()=>{}),NO=0;function Vt(t){const[e,n]=T.useState(vO());return _t(()=>{n(r=>r??String(NO++))},[t]),t||(e?`radix-${e}`:"")}var La="Collapsible",[OO,j0]=qt(La),[yO,Uo]=OO(La),Kp=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,open:r,defaultOpen:a,disabled:i,onOpenChange:o,...s}=t,[l,c]=Rn({prop:r,defaultProp:a??!1,onChange:o,caller:La});return u.jsx(yO,{scope:n,disabled:i,contentId:Vt(),open:l,onOpenToggle:T.useCallback(()=>c(d=>!d),[c]),children:u.jsx(ye.div,{"data-state":Bo(l),"data-disabled":i?"":void 0,...s,ref:e})})});Kp.displayName=La;var Qp="CollapsibleTrigger",jp=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,...r}=t,a=Uo(Qp,n);return u.jsx(ye.button,{type:"button","aria-controls":a.contentId,"aria-expanded":a.open||!1,"data-state":Bo(a.open),"data-disabled":a.disabled?"":void 0,disabled:a.disabled,...r,ref:e,onClick:de(t.onClick,a.onOpenToggle)})});jp.displayName=Qp;var Fo="CollapsibleContent",IO=T.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=Uo(Fo,t.__scopeCollapsible);return u.jsx(vt,{present:n||a.open,children:({present:i})=>u.jsx(AO,{...r,ref:e,present:i})})});IO.displayName=Fo;var AO=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,present:r,children:a,...i}=t,o=Uo(Fo,n),[s,l]=T.useState(r),c=T.useRef(null),d=ke(e,c),_=T.useRef(0),p=_.current,m=T.useRef(0),E=m.current,f=o.open||s,g=T.useRef(f),S=T.useRef(void 0);return T.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),_t(()=>{const b=c.current;if(b){S.current=S.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const h=b.getBoundingClientRect();_.current=h.height,m.current=h.width,g.current||(b.style.transitionDuration=S.current.transitionDuration,b.style.animationName=S.current.animationName),l(r)}},[o.open,r]),u.jsx(ye.div,{"data-state":Bo(o.open),"data-disabled":o.disabled?"":void 0,id:o.contentId,hidden:!f,...i,ref:d,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...t.style},children:f&&a})});function Bo(t){return t?"open":"closed"}var xO=Kp;const Xp=xO,Zp=jp,Jp=new URL("data:video/mp2t;base64,Ly8vIDxyZWZlcmVuY2UgbGliPSJ3ZWJ3b3JrZXIiIC8+CmltcG9ydCBtYXJrZWQgZnJvbSAnbWFya2VkJzsKCmRlY2xhcmUgY29uc3Qgc2VsZjogRGVkaWNhdGVkV29ya2VyR2xvYmFsU2NvcGU7CmNvbnN0IHNjb3BlOiBEZWRpY2F0ZWRXb3JrZXJHbG9iYWxTY29wZSA9IHNlbGY7CgpzY29wZS5wb3N0TWVzc2FnZT8uKHsgd29ya2VyX3JlYWR5OiB0cnVlIH0pOwoKc2NvcGUuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIChldmVudDogTWVzc2FnZUV2ZW50KSA9PiB7CiAgY29uc3QgcGF5bG9hZDogYW55ID0gZXZlbnQ/LmRhdGEgPz8ge307CiAgY29uc3QgaWQgPSB0eXBlb2YgcGF5bG9hZC5pZCA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLmlkIDogdW5kZWZpbmVkOwogIGNvbnN0IHNvdXJjZSA9IHR5cGVvZiBwYXlsb2FkLnNvdXJjZSA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLnNvdXJjZSA6IHVuZGVmaW5lZDsKICBpZiAoIWlkIHx8IHR5cGVvZiBzb3VyY2UgIT09ICdzdHJpbmcnKSByZXR1cm47CgogIHRyeSB7CiAgICBjb25zdCBodG1sID0gbWFya2VkLnBhcnNlKHNvdXJjZSk7CiAgICBzY29wZS5wb3N0TWVzc2FnZSh7IGlkLCBodG1sIH0pOwogIH0gY2F0Y2ggKGVycikgewogICAgc2NvcGUucG9zdE1lc3NhZ2UoeyBpZCwgaHRtbDogYDxwcmU+RXJyb3IgcmVuZGVyaW5nIG1hcmtkb3duOiAke1N0cmluZyhlcnIpfTwvcHJlPmAgfSk7CiAgfQp9KTsK",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Wi&&Wi.tagName.toUpperCase()==="SCRIPT"&&Wi.src||new URL("index.umd.js",document.baseURI).href),Fr=Jp.toString(),DO=(()=>{try{if(typeof Worker>"u"||typeof URL>"u"||typeof Blob>"u")return!1;const t=new Blob(["export default null;"],{type:"application/javascript"}),e=URL.createObjectURL(t);return new Worker(e,{type:"module"}).terminate(),URL.revokeObjectURL(e),!0}catch{return!1}})(),wO=Fr.includes("data:"),MO=(()=>{if(typeof navigator>"u")return!1;const t=navigator.userAgent.toLowerCase();return t.includes("safari")&&!t.includes("chrome")&&!t.includes("android")})(),Pa=DO&&!(wO&&MO),Go=t=>typeof t=="object"&&t!==null,Yo=t=>typeof t=="function"?t:Go(t)&&typeof t.parse=="function"?t.parse:null;let ka=null;async function em(t){try{ka||(ka=Promise.resolve().then(()=>zM));const e=await ka,n=Go(e)?e:{},r=Yo(n.parse)??Yo(n.marked)??Yo(n.default);return r?r(t):""}catch(e){throw ka=null,e}}const LO=t=>Go(t)&&typeof t.highlightElement=="function"?{highlightElement:t.highlightElement}:null;console.log("[MarkdownContent] worker url",Fr);const Ho=[];let qo=!1;const tm={addEventListener:()=>{},removeEventListener:()=>{},postMessage:()=>{},terminate:()=>{}};let Cn=tm;const nm=t=>{console.error("[MarkdownContent] worker error",t)};function Vo(t){if(Cn&&Cn!==tm)try{Cn.removeEventListener("error",nm)}catch{}Cn=t,qo=!0;try{Cn.addEventListener("error",nm)}catch(e){console.warn("[MarkdownContent] failed to register worker error handler",e)}try{for(;Ho.length;){const e=Ho.shift();if(e)try{e()}catch{}}}catch(e){console.warn("[MarkdownContent] markWorkerOnline notify failed",e)}}function PO(t){if(!Pa)return null;const e=t.indexOf("data:");if(e===-1)return null;const r=t.slice(e).match(/^data:[^;]+;base64,(.*)$/);if(!r)return null;try{const a=r[1],i=atob(a),o=Uint8Array.from(i,c=>c.charCodeAt(0)),s=new Blob([o],{type:"application/javascript"}),l=URL.createObjectURL(s);try{const c=new Worker(l,{type:"module"});return URL.revokeObjectURL(l),c}catch(c){return URL.revokeObjectURL(l),console.error("[MarkdownContent] failed to initialize worker from data URI blob",c),null}}catch(a){return console.warn("[MarkdownContent] failed to decode embedded data URI",a),null}}async function kO(t){if(Pa)try{let e="";const n=await fetch(t);if(e=await n.text(),n.ok||console.warn("[MarkdownContent] fetch worker non-ok",n.status,n.statusText),!e){console.warn("[MarkdownContent] worker fetch returned empty content; aborting worker init.");return}if(e.trim().startsWith("<")){console.warn("[MarkdownContent] worker fetch returned HTML; dev server may be redirecting. Aborting worker init.");return}const r=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(r);try{const i=new Worker(a,{type:"module"});Vo(i)}catch(i){console.error("[MarkdownContent] failed to initialize worker from blob",i)}finally{URL.revokeObjectURL(a)}}catch(e){console.error("[MarkdownContent] fetch worker failed",e)}}function UO(){if(Fr.includes("data:")){const t=PO(Fr);if(t){Vo(t);return}console.warn("[MarkdownContent] data URI bootstrap failed; worker will remain offline until fallback succeeds");return}try{const t=new Worker(Jp,{type:"module"});Vo(t)}catch(t){console.warn("[MarkdownContent] worker constructor failed, will try fetch+blob fallback",t),kO(Fr)}}Pa?UO():console.warn("[MarkdownContent] module workers not supported; falling back to main-thread markdown parsing");const nr=new Map;function FO(t,e=!1){if(e){const a=t.slice(0,128);return`streaming:${Math.floor(t.length/50)*50}:${a}`}const n=t.slice(0,64),r=t.length>64?t.slice(-64):"";return`${t.length}:${n}:${r}`}function BO(t,e){const[n,r]=y.useState(t);return y.useEffect(()=>{if(e<=0){r(t);return}const a=setTimeout(()=>{r(t)},e);return()=>{clearTimeout(a)}},[t,e]),n}function Br({content:t,className:e="",fallback:n=u.jsx("div",{"aria-busy":!0,children:"Rendering…"}),isStreaming:r=!1,hideFallbackDuringStreaming:a=!0}){const o=BO(t,r?150:0),s=FO(o,r),[l,c]=y.useState(()=>nr.get(s)??null);y.useEffect(()=>{if(nr.has(s)){const b=nr.get(s)??null;c(b);return}if(!Pa){let b=!1;return(async()=>{try{const h=await em(t);nr.set(s,h),b||c(h)}catch(h){console.error("[MarkdownContent] fallback parse failed",h)}})(),()=>{b=!0}}let _=!0,p=!1;const m=b=>{const h=b.data;if(!h||h.id!==s||!_)return;p=!0;const N=h.html??"";nr.set(s,N),c(N)};Cn.addEventListener("message",m);const E=()=>{try{Cn.postMessage({id:s,source:t})}catch(b){console.error("[MarkdownContent] worker.postMessage threw",b)}};qo?E():Ho.push(E);const g=((b,h,N)=>h?N?b>2e4?15e3:b>8e3?8e3:b>2e3?3e3:1e3:b>2e4?1e4:b>8e3?5e3:b>2e3?2e3:600:Math.min(15e3,2e3+Math.floor(b*.5)))(o.length,qo,r),S=window.setTimeout(async()=>{if(!p){console.warn("[MarkdownContent] worker timeout (ms="+g+"), falling back to main-thread parse for",s);try{const b=await em(t);nr.set(s,b),_&&c(b)}catch(b){console.error("[MarkdownContent] fallback parse failed",b)}}},g);return()=>{_=!1,clearTimeout(S),Cn.removeEventListener("message",m)}},[t,s]);const d=y.useRef(null);return y.useEffect(()=>{if(!l)return;const _=d.current;if(!_)return;const p=Array.from(_.querySelectorAll("pre code"));if(!p.length)return;let m=null,E=!1;const f=(S,b)=>{for(const h of S){if(!h.isIntersecting)continue;const N=h.target;if(!m)Promise.resolve().then(()=>g0).then(R=>{if(E)return;const C=LO(R.default??R);if(C){m=C;try{p.forEach(v=>{_.contains(v)&&(m==null||m.highlightElement(v))})}catch{}}}).catch(()=>{});else try{m.highlightElement(N)}catch{}b.unobserve(N)}},g=new IntersectionObserver(f,{root:_,threshold:.1});return p.forEach(S=>g.observe(S)),()=>{E=!0,g.disconnect()}},[l]),l?u.jsx("div",{ref:d,className:$("markdown prose max-w-none break-words dark:prose-invert",e),dangerouslySetInnerHTML:{__html:l}}):r&&a?null:u.jsx("div",{className:$("markdown prose max-w-none break-words dark:prose-invert",e),children:n})}async function rm(t,e){return await Mt(t,{responseType:"blob",onDownloadProgress:r=>{try{e&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function am(t,e){return await(await rm(`/chat/files/${t}/view`,e)).text()}async function GO(t,e){const n=await rm(`/chat/files/${t}/download`,e),r=URL.createObjectURL(n);let a=`file_${t}`;try{const o=await Mt(`/chat/files/${t}`);a=(o==null?void 0:o.filename)??a}catch{}const i=document.createElement("a");i.href=r,i.download=a,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}const YO=1,HO=1e6;let zo=0;function qO(){return zo=(zo+1)%Number.MAX_SAFE_INTEGER,zo.toString()}const $o=new Map,im=t=>{if($o.has(t))return;const e=setTimeout(()=>{$o.delete(t),Gr({type:"REMOVE_TOAST",toastId:t})},HO);$o.set(t,e)},VO=(t,e)=>{switch(e.type){case"ADD_TOAST":return{...t,toasts:[e.toast,...t.toasts].slice(0,YO)};case"UPDATE_TOAST":return{...t,toasts:t.toasts.map(n=>n.id===e.toast.id?{...n,...e.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=e;return n?im(n):t.toasts.forEach(r=>{im(r.id)}),{...t,toasts:t.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return e.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(n=>n.id!==e.toastId)}}},Ua=[];let Fa={toasts:[]};function Gr(t){Fa=VO(Fa,t),Ua.forEach(e=>{e(Fa)})}function zO({...t}){const e=qO(),n=a=>Gr({type:"UPDATE_TOAST",toast:{...a,id:e}}),r=()=>Gr({type:"DISMISS_TOAST",toastId:e});return Gr({type:"ADD_TOAST",toast:{...t,id:e,open:!0,onOpenChange:a=>{a||r()}}}),{id:e,dismiss:r,update:n}}function Wo(){const[t,e]=T.useState(Fa);return T.useEffect(()=>(Ua.push(e),()=>{const n=Ua.indexOf(e);n>-1&&Ua.splice(n,1)}),[t]),{...t,toast:zO,dismiss:n=>Gr({type:"DISMISS_TOAST",toastId:n})}}function pt(t){const e=T.useRef(t);return T.useEffect(()=>{e.current=t}),T.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function $O(t,e=globalThis==null?void 0:globalThis.document){const n=pt(t);T.useEffect(()=>{const r=a=>{a.key==="Escape"&&n(a)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var WO="DismissableLayer",Ko="dismissableLayer.update",KO="dismissableLayer.pointerDownOutside",QO="dismissableLayer.focusOutside",om,sm=T.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Yr=T.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:a,onFocusOutside:i,onInteractOutside:o,onDismiss:s,...l}=t,c=T.useContext(sm),[d,_]=T.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=T.useState({}),E=ke(e,v=>_(v)),f=Array.from(c.layers),[g]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=f.indexOf(g),b=d?f.indexOf(d):-1,h=c.layersWithOutsidePointerEventsDisabled.size>0,N=b>=S,R=ZO(v=>{const O=v.target,x=[...c.branches].some(w=>w.contains(O));!N||x||(a==null||a(v),o==null||o(v),v.defaultPrevented||s==null||s())},p),C=JO(v=>{const O=v.target;[...c.branches].some(w=>w.contains(O))||(i==null||i(v),o==null||o(v),v.defaultPrevented||s==null||s())},p);return $O(v=>{b===c.layers.size-1&&(r==null||r(v),!v.defaultPrevented&&s&&(v.preventDefault(),s()))},p),T.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(om=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),lm(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=om)}},[d,p,n,c]),T.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),lm())},[d,c]),T.useEffect(()=>{const v=()=>m({});return document.addEventListener(Ko,v),()=>document.removeEventListener(Ko,v)},[]),u.jsx(ye.div,{...l,ref:E,style:{pointerEvents:h?N?"auto":"none":void 0,...t.style},onFocusCapture:de(t.onFocusCapture,C.onFocusCapture),onBlurCapture:de(t.onBlurCapture,C.onBlurCapture),onPointerDownCapture:de(t.onPointerDownCapture,R.onPointerDownCapture)})});Yr.displayName=WO;var jO="DismissableLayerBranch",XO=T.forwardRef((t,e)=>{const n=T.useContext(sm),r=T.useRef(null),a=ke(e,r);return T.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),u.jsx(ye.div,{...t,ref:a})});XO.displayName=jO;function ZO(t,e=globalThis==null?void 0:globalThis.document){const n=pt(t),r=T.useRef(!1),a=T.useRef(()=>{});return T.useEffect(()=>{const i=s=>{if(s.target&&!r.current){let l=function(){cm(KO,n,c,{discrete:!0})};const c={originalEvent:s};s.pointerType==="touch"?(e.removeEventListener("click",a.current),a.current=l,e.addEventListener("click",a.current,{once:!0})):l()}else e.removeEventListener("click",a.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",i),e.removeEventListener("click",a.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function JO(t,e=globalThis==null?void 0:globalThis.document){const n=pt(t),r=T.useRef(!1);return T.useEffect(()=>{const a=i=>{i.target&&!r.current&&cm(QO,n,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",a),()=>e.removeEventListener("focusin",a)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function lm(){const t=new CustomEvent(Ko);document.dispatchEvent(t)}function cm(t,e,n,{discrete:r}){const a=n.originalEvent.target,i=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&a.addEventListener(t,e,{once:!0}),r?Wp(a,i):a.dispatchEvent(i)}var Qo="focusScope.autoFocusOnMount",jo="focusScope.autoFocusOnUnmount",dm={bubbles:!1,cancelable:!0},ey="FocusScope",Ba=T.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:i,...o}=t,[s,l]=T.useState(null),c=pt(a),d=pt(i),_=T.useRef(null),p=ke(e,f=>l(f)),m=T.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;T.useEffect(()=>{if(r){let f=function(h){if(m.paused||!s)return;const N=h.target;s.contains(N)?_.current=N:vn(_.current,{select:!0})},g=function(h){if(m.paused||!s)return;const N=h.relatedTarget;N!==null&&(s.contains(N)||vn(_.current,{select:!0}))},S=function(h){if(document.activeElement===document.body)for(const R of h)R.removedNodes.length>0&&vn(s)};document.addEventListener("focusin",f),document.addEventListener("focusout",g);const b=new MutationObserver(S);return s&&b.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",f),document.removeEventListener("focusout",g),b.disconnect()}}},[r,s,m.paused]),T.useEffect(()=>{if(s){pm.add(m);const f=document.activeElement;if(!s.contains(f)){const S=new CustomEvent(Qo,dm);s.addEventListener(Qo,c),s.dispatchEvent(S),S.defaultPrevented||(ty(oy(um(s)),{select:!0}),document.activeElement===f&&vn(s))}return()=>{s.removeEventListener(Qo,c),setTimeout(()=>{const S=new CustomEvent(jo,dm);s.addEventListener(jo,d),s.dispatchEvent(S),S.defaultPrevented||vn(f??document.body,{select:!0}),s.removeEventListener(jo,d),pm.remove(m)},0)}}},[s,c,d,m]);const E=T.useCallback(f=>{if(!n&&!r||m.paused)return;const g=f.key==="Tab"&&!f.altKey&&!f.ctrlKey&&!f.metaKey,S=document.activeElement;if(g&&S){const b=f.currentTarget,[h,N]=ny(b);h&&N?!f.shiftKey&&S===N?(f.preventDefault(),n&&vn(h,{select:!0})):f.shiftKey&&S===h&&(f.preventDefault(),n&&vn(N,{select:!0})):S===b&&f.preventDefault()}},[n,r,m.paused]);return u.jsx(ye.div,{tabIndex:-1,...o,ref:p,onKeyDown:E})});Ba.displayName=ey;function ty(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(vn(r,{select:e}),document.activeElement!==n)return}function ny(t){const e=um(t),n=_m(e,t),r=_m(e.reverse(),t);return[n,r]}function um(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function _m(t,e){for(const n of t)if(!ry(n,{upTo:e}))return n}function ry(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function ay(t){return t instanceof HTMLInputElement&&"select"in t}function vn(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&ay(t)&&e&&t.select()}}var pm=iy();function iy(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=mm(t,e),t.unshift(e)},remove(e){var n;t=mm(t,e),(n=t[0])==null||n.resume()}}}function mm(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function oy(t){return t.filter(e=>e.tagName!=="A")}var sy="Portal",Ga=T.forwardRef((t,e)=>{var s;const{container:n,...r}=t,[a,i]=T.useState(!1);_t(()=>i(!0),[]);const o=n||a&&((s=globalThis==null?void 0:globalThis.document)==null?void 0:s.body);return o?$i.createPortal(u.jsx(ye.div,{...r,ref:e}),o):null});Ga.displayName=sy;var Xo=0;function Zo(){T.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??gm()),document.body.insertAdjacentElement("beforeend",t[1]??gm()),Xo++,()=>{Xo===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),Xo--}},[])}function gm(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var en=function(){return en=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},en.apply(this,arguments)};function Em(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function ly(t,e,n){if(n||arguments.length===2)for(var r=0,a=e.length,i;r<a;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;var Ya="right-scroll-bar-position",Ha="width-before-scroll-bar",cy="with-scroll-bars-hidden",dy="--removed-body-scroll-bar-size";function Jo(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function uy(t,e){var n=y.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=e,n.facade}var _y=typeof window<"u"?T.useLayoutEffect:T.useEffect,fm=new WeakMap;function py(t,e){var n=uy(null,function(r){return t.forEach(function(a){return Jo(a,r)})});return _y(function(){var r=fm.get(n);if(r){var a=new Set(r),i=new Set(t),o=n.current;a.forEach(function(s){i.has(s)||Jo(s,null)}),i.forEach(function(s){a.has(s)||Jo(s,o)})}fm.set(n,t)},[t]),n}function my(t){return t}function gy(t,e){e===void 0&&(e=my);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:t},useMedium:function(i){var o=e(i,r);return n.push(o),function(){n=n.filter(function(s){return s!==o})}},assignSyncMedium:function(i){for(r=!0;n.length;){var o=n;n=[],o.forEach(i)}n={push:function(s){return i(s)},filter:function(){return n}}},assignMedium:function(i){r=!0;var o=[];if(n.length){var s=n;n=[],s.forEach(i),o=n}var l=function(){var d=o;o=[],d.forEach(i)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){o.push(d),c()},filter:function(d){return o=o.filter(d),n}}}};return a}function Ey(t){t===void 0&&(t={});var e=gy(null);return e.options=en({async:!0,ssr:!1},t),e}var Sm=function(t){var e=t.sideCar,n=Em(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return T.createElement(r,en({},n))};Sm.isSideCarExport=!0;function fy(t,e){return t.useMedium(e),Sm}var bm=Ey(),es=function(){},qa=T.forwardRef(function(t,e){var n=T.useRef(null),r=T.useState({onScrollCapture:es,onWheelCapture:es,onTouchMoveCapture:es}),a=r[0],i=r[1],o=t.forwardProps,s=t.children,l=t.className,c=t.removeScrollBar,d=t.enabled,_=t.shards,p=t.sideCar,m=t.noRelative,E=t.noIsolation,f=t.inert,g=t.allowPinchZoom,S=t.as,b=S===void 0?"div":S,h=t.gapMode,N=Em(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),R=p,C=py([n,e]),v=en(en({},N),a);return T.createElement(T.Fragment,null,d&&T.createElement(R,{sideCar:bm,removeScrollBar:c,shards:_,noRelative:m,noIsolation:E,inert:f,setCallbacks:i,allowPinchZoom:!!g,lockRef:n,gapMode:h}),o?T.cloneElement(T.Children.only(s),en(en({},v),{ref:C})):T.createElement(b,en({},v,{className:l,ref:C}),s))});qa.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},qa.classNames={fullWidth:Ha,zeroRight:Ya};var Sy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function by(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Sy();return e&&t.setAttribute("nonce",e),t}function Ty(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function hy(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Ry=function(){var t=0,e=null;return{add:function(n){t==0&&(e=by())&&(Ty(e,n),hy(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Cy=function(){var t=Ry();return function(e,n){T.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},Tm=function(){var t=Cy(),e=function(n){var r=n.styles,a=n.dynamic;return t(r,a),null};return e},vy={left:0,top:0,right:0,gap:0},ts=function(t){return parseInt(t||"",10)||0},Ny=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],a=e[t==="padding"?"paddingRight":"marginRight"];return[ts(n),ts(r),ts(a)]},Oy=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return vy;var e=Ny(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},yy=Tm(),rr="data-scroll-locked",Iy=function(t,e,n,r){var a=t.left,i=t.top,o=t.right,s=t.gap;return n===void 0&&(n="margin"),`
34
34
  .`.concat(cy,` {
35
35
  overflow: hidden `).concat(r,`;
36
36
  padding-right: `).concat(s,"px ").concat(r,`;
@@ -74,7 +74,7 @@ Check the top-level render call using <`+ue+">.")}return J}}function Hu(A,J){{if
74
74
 
75
75
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
76
76
 
77
- For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return T.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},eI="DialogDescriptionWarning",tI=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vm(eI).contentName}}.`;return T.useEffect(()=>{var i;const a=(i=t.current)==null?void 0:i.getAttribute("aria-describedby");e&&a&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},zm=xm,nI=wm,$m=Lm,Xa=Pm,Za=km,Gn=Fm,Ja=Gm,Wm=Hm;const rI=zm,aI=$m,Km=T.forwardRef(({className:t,...e},n)=>u.jsx(Xa,{ref:n,className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));Km.displayName=Xa.displayName;const Qm=T.forwardRef(({className:t,children:e,...n},r)=>{const a=T.useMemo(()=>{let i=!1;function o(s){T.Children.forEach(s,l=>{if(i||!T.isValidElement(l))return;const c=l.type;if(c===Gn||(c==null?void 0:c.displayName)===Gn.displayName||(c==null?void 0:c.name)==="DialogTitle"){i=!0;return}l.props&&l.props.children&&o(l.props.children)})}return o(e),i},[e]);return u.jsxs(aI,{children:[u.jsx(Km,{}),u.jsxs(Za,{ref:r,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...n,children:[!a&&u.jsx(Gn,{className:"sr-only",children:"Dialog"}),e,u.jsxs(Wm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Qm.displayName=Za.displayName;const jm=({className:t,...e})=>u.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});jm.displayName="DialogHeader";const Xm=T.forwardRef(({className:t,...e},n)=>u.jsx(Gn,{ref:n,className:$("text-lg font-semibold leading-none tracking-tight",t),...e}));Xm.displayName=Gn.displayName;const iI=T.forwardRef(({className:t,...e},n)=>u.jsx(Ja,{ref:n,className:$("text-sm text-muted-foreground",t),...e}));iI.displayName=Ja.displayName;function oI({isOpen:t,onClose:e,fileId:n,fileName:r,mimeType:a}){const[i,o]=y.useState(!1),[s,l]=y.useState(null),[c,d]=y.useState(null),{toast:_}=Wo();y.useEffect(()=>{t&&n&&p()},[t,n]);const p=async()=>{if(n){o(!0),d(null),l(null);try{const S=await am(n);l(S)}catch(S){console.error("Failed to load file:",S),d(S instanceof Error?S.message:"Failed to load file")}finally{o(!1)}}},m=async()=>{if(n)try{await GO(n),_({title:"Download started",description:`Downloading ${r}`})}catch(S){console.error("Failed to download file:",S),_({title:"Download failed",description:String(S),variant:"destructive"})}},E=async()=>{if(n)try{const S=await am(n),b=new Blob([S],{type:a}),h=URL.createObjectURL(b);window.open(h,"_blank"),URL.revokeObjectURL(h)}catch(S){console.error("Failed to open file externally:",S),_({title:"Failed to open file",description:String(S),variant:"destructive"})}},f=()=>i?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(pe.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ve,{onClick:p,variant:"outline",children:"Try Again"})]}):s?a.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${a};base64,${s}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):a==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${s}`,className:"w-full h-full",title:r})}):a.startsWith("text/")||a.includes("json")||a.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:s})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(pe.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[a," • ",s.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>a.startsWith("image/")?u.jsx(pe.Image,{className:"h-5 w-5"}):u.jsx(pe.FileText,{className:"h-5 w-5"});return u.jsx(rI,{open:t,onOpenChange:e,children:u.jsxs(Qm,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(jm,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[g(),u.jsxs("div",{children:[u.jsx(Xm,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ve,{variant:"outline",size:"sm",onClick:E,className:"flex items-center gap-2",children:[u.jsx(pe.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ve,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(pe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:f()})]})})}const ei="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function sI({className:t}){const[e,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(a=>(a+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:$("inline-block text-xs opacity-70 ml-1",t),children:["Is thinking",".".repeat(e)]})}const Zm=y.memo(function({message:e,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:a=500,isEditing:i=!1,showActions:o=!0,showTimestamp:s=!0,showAgentName:l=!0,layoutSize:c="desktop",truncateToolMessages:d=!0,toolMessagePreviewLength:_=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:E={},onEdit:f,onRegenerate:g,onCancelEdit:S,onCopy:b}){const[h,N]=y.useState(!1),[R,C]=y.useState(!1),[v,O]=y.useState(!1),[x,w]=y.useState(!1),{currentThreadId:L}=ba();Wo();const[H,z]=y.useState({}),[P,G]=y.useState(!1),[I,U]=y.useState(null),M=c==="phone"||c==="half-screen",k=e.role,Y=k==="tool",W=y.useMemo(()=>{switch(k){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[k]),re=y.useMemo(()=>lI(e.content),[e.content]),q=y.useMemo(()=>pI(e.content),[e.content]),X=y.useMemo(()=>e.content.filter(Se=>Se.type==="image_url"),[e.content]),ce=y.useMemo(()=>e.content.filter(Se=>Se.type==="file"),[e.content]),ge=gI(re,r?a:0),V=async()=>{try{const Se=Y?sr(e.content):re;await navigator.clipboard.writeText(Se),N(!0),setTimeout(()=>N(!1),2e3),b==null||b(Se)}catch(Se){console.error("Failed to copy:",Se)}},F=()=>{if(!f)return;const Se=Y?sr(e.content):re;f(e.id,Se)},K=()=>g==null?void 0:g(n),te=()=>{const Be=$(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",W);switch(k){case"user":return u.jsx(pe.User,{className:Be});case"assistant":return u.jsx(pe.Bot,{className:Be});case"tool":return u.jsx(pe.Wrench,{className:Be});default:return u.jsx(pe.Bot,{className:Be})}},le=()=>{const Se="group relative mb-4 flex w-full";switch(k){case"user":return $(Se,"justify-end");case"assistant":case"tool":case"system":return $(Se,"justify-start");default:return Se}},oe=()=>{const Se=$("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");switch(k){case"user":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return $(Se,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return $(Se,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},Ae=Se=>{if(!Se)return"";try{return new Date(Se).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},qe=()=>{if(e.model==="reflection"){const ee=re.trim(),Q=ls(ee);if(Q&&typeof Q=="object")return u.jsx(EI,{data:Q})}if(Y&&q.name==="get_issues"){const ee=e.content.find(be=>be.type==="tool_result"),Q=(ee==null?void 0:ee.output)??sr(e.content),ae=tg(Q);if(ae)return u.jsx(fI,{issues:ae})}if(Y&&!v){const ee=sr(e.content).slice(0,80).replace(/\s+/g," ");return u.jsx("div",{className:$("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",M&&"text-[10px]"),children:u.jsxs("span",{className:"truncate max-w-full text-current",children:[ee,ee.length>=80?"…":""]})})}if(Y&&d){const ee=sr(e.content),Q=ee.length>_;return u.jsx(Xp,{open:R,onOpenChange:C,children:u.jsxs("div",{className:"font-mono text-sm text-current",children:[u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q&&!R?ee.substring(0,_)+"...":ee}),Q&&u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:R?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",ee.length-_," chars)"]})})})]})})}if(Y&&v&&!d){const ee=SI(e.content);if(ee&&cI(ee))return u.jsx(Br,{content:ee.trim()});const Q=sr(e.content);return u.jsx("div",{className:"font-mono text-sm text-current",children:u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q})})}const Se=X.length>0&&k!=="tool",Be=ce.length>0&&k!=="tool"&&!1;return u.jsxs("div",{children:[r?u.jsxs("div",{className:"relative",children:[(()=>{const ee=ls(ge);return ee!==null?u.jsx(Jm,{data:ee}):u.jsx(Br,{content:uI(dI(ge)),isStreaming:!0,hideFallbackDuringStreaming:!0})})(),u.jsx(sI,{className:$(W,M?"text-xs":"text-sm")})]}):(()=>{const ee=ls(re.trim());if(ee!==null)return u.jsx(Jm,{data:ee});if(k==="user"&&p){const Q=re.trim();if(Q.length>m)return u.jsxs(Xp,{open:x,onOpenChange:w,children:[u.jsx("div",{className:$("text-sm text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:x?u.jsx(Br,{content:Q,hideFallbackDuringStreaming:!0}):u.jsxs("pre",{className:$("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:[Q.substring(0,m),"..."]})}),u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:x?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Q.length-m," chars)"]})})})]})}return u.jsx(Br,{content:re.trim(),isStreaming:r,hideFallbackDuringStreaming:!0})})(),Se&&u.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:X.map((ee,Q)=>u.jsxs("div",{className:"relative border rounded overflow-hidden",children:[u.jsx("img",{src:ee.url,alt:ee.alt??"image",className:"w-full h-auto"}),u.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[u.jsx(pe.Image,{className:"h-3 w-3"}),u.jsx("span",{children:"image"})]})]},Q))}),Be]})},Me=y.useMemo(()=>mI(e),[e]);return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:$(le(),E.container),children:u.jsxs("div",{className:$(oe(),E.content),children:[(s||l||Y)&&u.jsxs("div",{className:$("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",W,E.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[te(),l&&Me&&u.jsx("span",{className:$("font-medium",M?"text-xs":"text-sm"),children:Me}),Y&&q.name&&u.jsxs(zp,{variant:"outline",className:$("text-xs flex items-center gap-1 cursor-pointer",W,"border border-current/40",M&&"text-xs h-4"),onClick:()=>O(Se=>!Se),children:[u.jsx("span",{children:q.name}),u.jsx("span",{className:"inline-flex items-center",children:v?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})})]}),Y&&!q.name&&u.jsx(Ve,{variant:"ghost",size:"sm",className:$("h-6 px-1",W,"hover:bg-foreground/10"),onClick:()=>O(Se=>!Se),children:u.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",v?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})]})})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[s&&u.jsx("span",{className:$("text-xs opacity-60",W,M&&"text-xs"),children:Ae(e.createdAt)}),o&&!i&&u.jsxs("div",{className:$("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",E.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":W,M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$(W,M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&g&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$(W,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:qe()}),Y&&v&&(q.toolCallId||q.name)&&u.jsxs("div",{className:$("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[q.name&&u.jsxs("div",{children:["Function: ",q.name]}),q.toolCallId&&u.jsxs("div",{children:["Call ID: ",q.toolCallId]})]}),!(s||l||Y)&&o&&!i&&u.jsxs("div",{className:$("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",E.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&g&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),I&&u.jsx(oI,{isOpen:P,onClose:()=>{G(!1),U(null)},fileId:I.id,fileName:I.name,mimeType:I.mimeType})]})},(t,e)=>e.isStreamingMessage?!1:t.message.id===e.message.id&&t.message.content===e.message.content&&t.isStreamingMessage===e.isStreamingMessage&&t.isEditing===e.isEditing);function lI(t){const e=t.filter(n=>n.type==="text").map(n=>n.text).join("");return e||JSON.stringify(t)}function cI(t){return t.includes(`
77
+ For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return T.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},eI="DialogDescriptionWarning",tI=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Vm(eI).contentName}}.`;return T.useEffect(()=>{var i;const a=(i=t.current)==null?void 0:i.getAttribute("aria-describedby");e&&a&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},zm=xm,nI=wm,$m=Lm,Xa=Pm,Za=km,Gn=Fm,Ja=Gm,Wm=Hm;const rI=zm,aI=$m,Km=T.forwardRef(({className:t,...e},n)=>u.jsx(Xa,{ref:n,className:$("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));Km.displayName=Xa.displayName;const Qm=T.forwardRef(({className:t,children:e,...n},r)=>{const a=T.useMemo(()=>{let i=!1;function o(s){T.Children.forEach(s,l=>{if(i||!T.isValidElement(l))return;const c=l.type;if(c===Gn||(c==null?void 0:c.displayName)===Gn.displayName||(c==null?void 0:c.name)==="DialogTitle"){i=!0;return}l.props&&l.props.children&&o(l.props.children)})}return o(e),i},[e]);return u.jsxs(aI,{children:[u.jsx(Km,{}),u.jsxs(Za,{ref:r,className:$("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...n,children:[!a&&u.jsx(Gn,{className:"sr-only",children:"Dialog"}),e,u.jsxs(Wm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Qm.displayName=Za.displayName;const jm=({className:t,...e})=>u.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});jm.displayName="DialogHeader";const Xm=T.forwardRef(({className:t,...e},n)=>u.jsx(Gn,{ref:n,className:$("text-lg font-semibold leading-none tracking-tight",t),...e}));Xm.displayName=Gn.displayName;const iI=T.forwardRef(({className:t,...e},n)=>u.jsx(Ja,{ref:n,className:$("text-sm text-muted-foreground",t),...e}));iI.displayName=Ja.displayName;function oI({isOpen:t,onClose:e,fileId:n,fileName:r,mimeType:a}){const[i,o]=y.useState(!1),[s,l]=y.useState(null),[c,d]=y.useState(null),{toast:_}=Wo();y.useEffect(()=>{t&&n&&p()},[t,n]);const p=async()=>{if(n){o(!0),d(null),l(null);try{const S=await am(n);l(S)}catch(S){console.error("Failed to load file:",S),d(S instanceof Error?S.message:"Failed to load file")}finally{o(!1)}}},m=async()=>{if(n)try{await GO(n),_({title:"Download started",description:`Downloading ${r}`})}catch(S){console.error("Failed to download file:",S),_({title:"Download failed",description:String(S),variant:"destructive"})}},E=async()=>{if(n)try{const S=await am(n),b=new Blob([S],{type:a}),h=URL.createObjectURL(b);window.open(h,"_blank"),URL.revokeObjectURL(h)}catch(S){console.error("Failed to open file externally:",S),_({title:"Failed to open file",description:String(S),variant:"destructive"})}},f=()=>i?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(pe.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ve,{onClick:p,variant:"outline",children:"Try Again"})]}):s?a.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${a};base64,${s}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):a==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${s}`,className:"w-full h-full",title:r})}):a.startsWith("text/")||a.includes("json")||a.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:s})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(pe.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[a," • ",s.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>a.startsWith("image/")?u.jsx(pe.Image,{className:"h-5 w-5"}):u.jsx(pe.FileText,{className:"h-5 w-5"});return u.jsx(rI,{open:t,onOpenChange:e,children:u.jsxs(Qm,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(jm,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[g(),u.jsxs("div",{children:[u.jsx(Xm,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ve,{variant:"outline",size:"sm",onClick:E,className:"flex items-center gap-2",children:[u.jsx(pe.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ve,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(pe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:f()})]})})}const ei="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function sI({className:t}){const[e,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(a=>(a+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:$("inline-block text-xs opacity-70 ml-1",t),children:["Is thinking",".".repeat(e)]})}const Zm=y.memo(function({message:e,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:a=500,isEditing:i=!1,showActions:o=!0,showTimestamp:s=!0,showAgentName:l=!0,layoutSize:c="desktop",truncateToolMessages:d=!0,toolMessagePreviewLength:_=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:E={},onEdit:f,onRegenerate:g,onCancelEdit:S,onCopy:b}){const[h,N]=y.useState(!1),[R,C]=y.useState(!1),[v,O]=y.useState(!1),[x,w]=y.useState(!1),{currentThreadId:L}=ba();Wo();const[H,z]=y.useState({}),[P,G]=y.useState(!1),[I,U]=y.useState(null),M=c==="phone"||c==="half-screen",k=e.role,Y=k==="tool",W=y.useMemo(()=>{switch(k){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[k]),re=y.useMemo(()=>lI(e.content),[e.content]),q=y.useMemo(()=>pI(e.content),[e.content]),X=y.useMemo(()=>e.content.filter(Se=>Se.type==="image_url"),[e.content]),ce=y.useMemo(()=>e.content.filter(Se=>Se.type==="file"),[e.content]),ge=gI(re,r?a:0),V=async()=>{try{const Se=Y?sr(e.content):re;await navigator.clipboard.writeText(Se),N(!0),setTimeout(()=>N(!1),2e3),b==null||b(Se)}catch(Se){console.error("Failed to copy:",Se)}},F=()=>{if(!f)return;const Se=Y?sr(e.content):re;f(e.id,Se)},K=()=>g==null?void 0:g(n),te=()=>{const Be=$(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",W);switch(k){case"user":return u.jsx(pe.User,{className:Be});case"assistant":return u.jsx(pe.Bot,{className:Be});case"tool":return u.jsx(pe.Wrench,{className:Be});default:return u.jsx(pe.Bot,{className:Be})}},le=()=>{const Se="group relative mb-4 flex w-full";switch(k){case"user":return $(Se,"justify-end");case"assistant":case"tool":case"system":return $(Se,"justify-start");default:return Se}},oe=()=>{const Se=$("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");switch(k){case"user":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return $(Se,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return $(Se,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return $(Se,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},Ae=Se=>{if(!Se)return"";try{return new Date(Se).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},qe=()=>{if(e.model==="reflection"){const ee=re.trim(),Q=ls(ee);if(Q&&typeof Q=="object")return u.jsx(EI,{data:Q})}if(Y&&q.name==="get_issues"){const ee=e.content.find(be=>be.type==="tool_result"),Q=(ee==null?void 0:ee.output)??sr(e.content),ae=tg(Q);if(ae)return u.jsx(fI,{issues:ae})}if(Y&&!v){const ee=sr(e.content).slice(0,80).replace(/\s+/g," ");return u.jsx("div",{className:$("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",M&&"text-[10px]"),children:u.jsxs("span",{className:"truncate max-w-full text-current",children:[ee,ee.length>=80?"…":""]})})}if(Y&&d){const ee=sr(e.content),Q=ee.length>_;return u.jsx(Xp,{open:R,onOpenChange:C,children:u.jsxs("div",{className:"font-mono text-sm text-current",children:[u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q&&!R?ee.substring(0,_)+"...":ee}),Q&&u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:R?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",ee.length-_," chars)"]})})})]})})}if(Y&&v&&!d){const ee=SI(e.content);if(ee&&cI(ee))return u.jsx(Br,{content:ee.trim(),hideFallbackDuringStreaming:!0});const Q=sr(e.content);return u.jsx("div",{className:"font-mono text-sm text-current",children:u.jsx("pre",{className:$("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:Q})})}const Se=X.length>0&&k!=="tool",Be=ce.length>0&&k!=="tool"&&!1;return u.jsxs("div",{children:[r?u.jsxs("div",{className:"relative",children:[(()=>{const ee=ls(ge);return ee!==null?u.jsx(Jm,{data:ee}):u.jsx(Br,{content:uI(dI(ge)),isStreaming:!0,hideFallbackDuringStreaming:!0})})(),u.jsx(sI,{className:$(W,M?"text-xs":"text-sm")})]}):(()=>{const ee=ls(re.trim());if(ee!==null)return u.jsx(Jm,{data:ee});if(k==="user"&&p){const Q=re.trim();if(Q.length>m)return u.jsxs(Xp,{open:x,onOpenChange:w,children:[u.jsx("div",{className:$("text-sm text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:x?u.jsx(Br,{content:Q,hideFallbackDuringStreaming:!0}):u.jsxs("pre",{className:$("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:[Q.substring(0,m),"..."]})}),u.jsx(Zp,{asChild:!0,children:u.jsx(Ve,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:x?u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Q.length-m," chars)"]})})})]})}return u.jsx(Br,{content:re.trim(),isStreaming:r,hideFallbackDuringStreaming:!0})})(),Se&&u.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:X.map((ee,Q)=>u.jsxs("div",{className:"relative border rounded overflow-hidden",children:[u.jsx("img",{src:ee.url,alt:ee.alt??"image",className:"w-full h-auto"}),u.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[u.jsx(pe.Image,{className:"h-3 w-3"}),u.jsx("span",{children:"image"})]})]},Q))}),Be]})},Me=y.useMemo(()=>mI(e),[e]);return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:$(le(),E.container),children:u.jsxs("div",{className:$(oe(),E.content),children:[(s||l||Y)&&u.jsxs("div",{className:$("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",W,E.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[te(),l&&Me&&u.jsx("span",{className:$("font-medium",M?"text-xs":"text-sm"),children:Me}),Y&&q.name&&u.jsxs(zp,{variant:"outline",className:$("text-xs flex items-center gap-1 cursor-pointer",W,"border border-current/40",M&&"text-xs h-4"),onClick:()=>O(Se=>!Se),children:[u.jsx("span",{children:q.name}),u.jsx("span",{className:"inline-flex items-center",children:v?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})})]}),Y&&!q.name&&u.jsx(Ve,{variant:"ghost",size:"sm",className:$("h-6 px-1",W,"hover:bg-foreground/10"),onClick:()=>O(Se=>!Se),children:u.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",v?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})]})})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[s&&u.jsx("span",{className:$("text-xs opacity-60",W,M&&"text-xs"),children:Ae(e.createdAt)}),o&&!i&&u.jsxs("div",{className:$("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",E.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":W,M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$(W,M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&g&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-foreground/10",W,M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$(W,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:qe()}),Y&&v&&(q.toolCallId||q.name)&&u.jsxs("div",{className:$("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[q.name&&u.jsxs("div",{children:["Function: ",q.name]}),q.toolCallId&&u.jsxs("div",{children:["Call ID: ",q.toolCallId]})]}),!(s||l||Y)&&o&&!i&&u.jsxs("div",{className:$("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",E.actions),children:[u.jsx(Ve,{variant:"ghost",size:"sm",onClick:V,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:$(h?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="user"&&f&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:F,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})}),k==="assistant"&&g&&u.jsx(Ve,{variant:"ghost",size:"sm",onClick:K,className:$("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:$("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),I&&u.jsx(oI,{isOpen:P,onClose:()=>{G(!1),U(null)},fileId:I.id,fileName:I.name,mimeType:I.mimeType})]})},(t,e)=>e.isStreamingMessage?!1:t.message.id===e.message.id&&t.message.content===e.message.content&&t.isStreamingMessage===e.isStreamingMessage&&t.isEditing===e.isEditing);function lI(t){const e=t.filter(n=>n.type==="text").map(n=>n.text).join("");return e||JSON.stringify(t)}function cI(t){return t.includes(`
78
78
  `)||t.includes("```")||/[-*] /.test(t)||/#+\s/.test(t)}function dI(t){let e=t;try{(e.match(/```/g)||[]).length%2===1&&(e+="\n```"),(e.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(e+="`")}catch{}return e}function uI(t){let e=t;try{const n=[],r=[],a="\0F",i="\0I";let o=e.replace(/```[\s\S]*?```/g,s=>(n.push(s),`${a}${n.length-1}\0`));o=o.replace(/`[^`]*`/g,s=>(r.push(s),`${i}${r.length-1}\0`)),o=o.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),o=o.replace(/\u0000F(\d+)\u0000/g,(s,l)=>n[Number(l)]??""),o=o.replace(/\u0000I(\d+)\u0000/g,(s,l)=>r[Number(l)]??""),e=o}catch{}return e}function ls(t){const e=t==null?void 0:t.trim();if(!e||!(e.startsWith("{")||e.startsWith("[")))return null;try{return JSON.parse(e)}catch{return null}}function Jm({data:t}){if(Array.isArray(t))return t.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:ei,children:u.jsx("ul",{className:"list-disc pl-5",children:t.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hr(t)});if(t&&typeof t=="object"){const e=Array.isArray(t.distilled_facts)?t.distilled_facts:null,n=Array.isArray(t.follow_up_queries)?t.follow_up_queries:null,r=typeof t.is_sufficient=="boolean"?t.is_sufficient:void 0;if(e||n||typeof r=="boolean")return u.jsxs("div",{className:ei,children:[typeof r=="boolean"&&u.jsxs("p",{children:[u.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Follow-up queries:"})}),u.jsx("ul",{className:"list-disc pl-5",children:n.map((i,o)=>u.jsx("li",{children:String(i)},o))})]}),e&&e.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Facts:"})}),u.jsx("ul",{className:"list-disc pl-5",children:e.map((i,o)=>u.jsx("li",{children:String(i)},o))})]})]});const a=Object.entries(t);return u.jsx("div",{className:ei,children:u.jsx("dl",{className:"mt-0",children:a.map(([i,o])=>u.jsxs("div",{className:"mb-1",children:[u.jsxs("dt",{className:"inline font-medium mr-1",children:[i,":"]}),u.jsx("dd",{className:"inline",children:_I(o)})]},i))})})}return u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Hr(t)})}function _I(t){if(t==null)return String(t);const e=typeof t;if(e==="string"||e==="number"||e==="boolean")return String(t);if(Array.isArray(t)&&t.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return t.join(", ");try{return u.jsx("code",{className:"text-xs",children:JSON.stringify(ti(t))})}catch{return String(t)}}function eg(t){return!!(t&&typeof t=="object"&&(t.type==="file"||t.mimeType||t.filename||t.sourceType==="base64"))}function ti(t){if(typeof t=="string")return t.length>2e3?t.slice(0,2e3)+"... [truncated]":t;if(t&&typeof t=="object"){if(Array.isArray(t)){const n=t.map(ti).filter(r=>r!==void 0);return n.length?n:void 0}if(eg(t))return;const e={};for(const n of Object.keys(t)){const r=t[n];if(n==="data"&&typeof r=="string"&&r.length>100)e[n]=`[base64 ${r.length} chars omitted]`;else{const a=ti(r);a!==void 0&&(e[n]=a)}}return Object.keys(e).length?e:void 0}return t}function Hr(t){if(typeof t=="string")return t;if(eg(t))return"";try{const e=ti(t);return e===void 0?"":typeof e=="string"?e:JSON.stringify(e,null,2)}catch{return""}}function pI(t){const e=t.find(r=>r.type==="tool_call"),n=t.find(r=>r.type==="tool_result");return{name:e==null?void 0:e.name,toolCallId:(n==null?void 0:n.toolCallId)??(e==null?void 0:e.id)}}function mI(t){return t.name&&t.name.trim()?t.name:t.model&&t.model.includes("/")?t.model.split("/").pop()||null:t.model||null}function gI(t,e){const[n,r]=y.useState(t),a=y.useRef(null),i=y.useRef(null);return y.useEffect(()=>{if(!e){r(t);return}return i.current&&clearTimeout(i.current),a.current&&cancelAnimationFrame(a.current),i.current=setTimeout(()=>{a.current=requestAnimationFrame(()=>{r(t)})},e),()=>{i.current&&clearTimeout(i.current),a.current&&cancelAnimationFrame(a.current)}},[t,e]),n}function EI({data:t}){return u.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(t).map(([e,n])=>u.jsxs("div",{className:"flex",children:[u.jsxs("dt",{className:"font-semibold mr-2",children:[e,":"]}),u.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,a)=>u.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},a)):String(n)})]},e))})}function tg(t){if(!t)return null;if(typeof t=="object"&&!Array.isArray(t)){if(t.desirability||t.feasibility||t.viability||t.other)return{desirability:Array.isArray(t.desirability)?t.desirability:[],feasibility:Array.isArray(t.feasibility)?t.feasibility:[],viability:Array.isArray(t.viability)?t.viability:[],other:Array.isArray(t.other)?t.other:[]};if(t.output&&typeof t.output!="object")t=t.output;else if(t.output&&typeof t.output=="object")return tg(t.output)}const e=String(t),n={desirability:[],feasibility:[],viability:[],other:[]};let r=e;const a=Math.min(...["desirability=","feasibility=","viability=","other="].map(o=>{const s=r.toLowerCase().indexOf(o);return s===-1?Number.MAX_SAFE_INTEGER:s}));a!==Number.MAX_SAFE_INTEGER&&(r=r.slice(a));for(const o of Object.keys(n)){const l=new RegExp(o+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const c=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let _=null;for(;(_=d.exec(c))!==null;){const p=_[1],m=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(p),E=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(p),f=m?m[2].trim():"",g=E?E[2].trim():"";n[o].push({title:f,description:g})}}return Object.values(n).some(o=>o.length>0)?n:null}function fI({issues:t}){const e=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return u.jsx("div",{className:ei,children:e.map(n=>{const r=t[n.key];return!r||!r.length?null:u.jsxs("div",{className:"mb-4",children:[u.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),u.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((a,i)=>u.jsxs("li",{children:[u.jsx("div",{className:"font-medium",children:a.title}),u.jsx("div",{className:"text-sm text-muted-foreground",children:a.description})]},i))})]},n.key)})})}function sr(t){const e=t.filter(n=>n.type==="tool_result");if(e.length)try{return e.length===1?Hr(e[0].output):Hr(e.map(n=>({toolCallId:n.toolCallId,output:n.output})))}catch{}return Hr(t)}function SI(t){const e=t.find(r=>r.type==="tool_result");if(!e)return null;const n=e.output;return typeof n=="string"?n:null}function ng({messages:t,isStreaming:e,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:a,enableMessageEditing:i,editingMessageId:o,onStartReached:s,onEdit:l,onRegenerate:c,onCancelEdit:d,className:_,style:p,emptyMessage:m}){const E=y.useRef(null),f=y.useRef(null),g=y.useRef(!1),S=y.useRef(!0),b=y.useRef(t.length),h=y.useRef(null),N=y.useRef(0);y.useEffect(()=>{const v=E.current;if(!v)return;let O=!1;const x=()=>{O||(window.requestAnimationFrame(()=>{const w=v.scrollHeight-v.scrollTop-v.clientHeight;S.current=w<=32,O=!1}),O=!0)};return v.addEventListener("scroll",x,{passive:!0}),x(),()=>{v.removeEventListener("scroll",x)}},[]),y.useEffect(()=>{t.length<b.current&&(S.current=!0),b.current=t.length},[t.length]),y.useEffect(()=>{var v;if(!g.current&&S.current){if(e){if(Date.now()-N.current<100)return;h.current&&cancelAnimationFrame(h.current),h.current=requestAnimationFrame(()=>{var w;(w=f.current)==null||w.scrollToIndex({index:Math.max(0,t.length-1),behavior:"auto",align:"end"}),N.current=Date.now(),h.current=null})}else(v=f.current)==null||v.scrollToIndex({index:Math.max(0,t.length-1),behavior:"auto",align:"end"});return()=>{h.current&&cancelAnimationFrame(h.current)}}},[t,e]);const R=y.useMemo(()=>{if(s)return async()=>{if(g.current)return;const v=E.current;if(!v){await(s==null?void 0:s());return}const O=v.scrollHeight,x=v.scrollTop;g.current=!0;try{await s()}finally{requestAnimationFrame(()=>{const w=E.current;if(!w){g.current=!1;return}const L=w.scrollHeight;w.scrollTop=x+(L-O);const H=L-w.scrollTop-w.clientHeight;S.current=H<=32,g.current=!1})}}},[s]),C=(v,O)=>{E.current=v,O&&(typeof O=="function"?O(v):O.current=v)};return t.length===0?u.jsx("div",{className:_,style:p,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:_,style:p,children:u.jsx(JN,{ref:v=>{f.current=v},data:t,followOutput:e?!1:"smooth",overscan:{main:300,reverse:300},increaseViewportBy:{top:600,bottom:600},defaultItemHeight:100,startReached:()=>{R&&R()},atBottomStateChange:v=>{S.current=v},style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(v,O)=>O.id??`message-${v}`,components:{Scroller:y.forwardRef((v,O)=>u.jsx("div",{...v,ref:x=>C(x,O),style:{overflowAnchor:"none",willChange:e?"scroll-position":"transform",contain:"layout style paint",...(v==null?void 0:v.style)??{}}}))},itemContent:(v,O)=>u.jsx("div",{className:"mb-4 last:mb-0",style:{contentVisibility:"auto",containIntrinsicSize:"auto 150px",transform:"translateZ(0)",isolation:"isolate"},children:u.jsx(Zm,{message:O,messageIndex:v,isStreamingMessage:e&&n===O.id,streamingDebounceMs:r,isEditing:o===O.id,showActions:i,showTimestamp:!1,showAgentName:!0,layoutSize:a,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>c(v),onCancelEdit:d},O.id??`msg-${O.role}-${v}-${O.createdAt??""}`)})})})}const ni=1e4;function bI(t){if(typeof t!="string")return String(t);const e=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=t;for(const a of e)n=n.replace(a,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
79
79
  `).replace(/<p>(.*?)<\/p>/gi,`$1
80
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "3.0.80",
3
+ "version": "3.0.81",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",