teodor-new-chat-ui 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -2863,8 +2863,16 @@ function pl(e, t) {
2863
2863
  };
2864
2864
  }
2865
2865
  if (t.type === "tool_result") {
2866
- const r = e.toolIndex[t.id] ?? `tool-${t.id}`, o = { type: "tool_result", toolCallId: t.id, output: t.output, error: t.error }, s = e.messages.find((c) => c.id === r), i = { id: r, role: "tool", content: [o], createdAt: (/* @__PURE__ */ new Date()).toISOString() }, a = s ? Hs(e.messages, r, [o]) : [...e.messages, i];
2867
- return { ...e, messages: a };
2866
+ const r = t.id ?? t.call_id;
2867
+ if (!r)
2868
+ return e;
2869
+ const o = e.toolIndex[r] ?? `tool-${r}`, s = {
2870
+ type: "tool_result",
2871
+ toolCallId: r,
2872
+ output: t.output,
2873
+ error: t.error
2874
+ }, i = e.messages.find((u) => u.id === o), a = { id: o, role: "tool", content: [s], createdAt: (/* @__PURE__ */ new Date()).toISOString() }, c = i ? Hs(e.messages, o, [s]) : [...e.messages, a];
2875
+ return { ...e, messages: c };
2868
2876
  }
2869
2877
  if (t.type === "checkpoint") {
2870
2878
  const r = t.checkpointNs ?? e.lastCheckpointNs ?? null, o = Wg(e.messages, t.checkpointId, r);
package/dist/index.umd.js CHANGED
@@ -35,7 +35,7 @@ React keys must be passed directly to JSX without using spread:
35
35
  `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Ln(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&mo.assertOptions(r,{silentJSONParsing:rn.transitional(rn.boolean),forcedJSONParsing:rn.transitional(rn.boolean),clarifyTimeoutError:rn.transitional(rn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:mo.assertOptions(o,{encode:rn.function,serialize:rn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),mo.assertOptions(n,{baseUrl:rn.spelling("baseURL"),withXsrfToken:rn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],b=>{delete s[b]}),n.headers=jt.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(n)===!1||(c=c&&w.synchronous,a.unshift(w.fulfilled,w.rejected))});const u=[];this.interceptors.response.forEach(function(w){u.push(w.fulfilled,w.rejected)});let d,f=0,h;if(!c){const b=[bl.bind(this),void 0];for(b.unshift(...a),b.push(...u),h=b.length,d=Promise.resolve(n);f<h;)d=d.then(b[f++],b[f++]);return d}h=a.length;let m=n;for(;f<h;){const b=a[f++],w=a[f++];try{m=b(m)}catch(g){w.call(this,g);break}}try{d=bl.call(this,m)}catch(b){return Promise.reject(b)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Ln(this.defaults,t);const n=cl(t.baseURL,t.url,t.allowAbsoluteUrls);return el(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){$n.prototype[t]=function(n,r){return this.request(Ln(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Ln(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}$n.prototype[t]=n(),$n.prototype[t+"Form"]=n(!0)});let $m=class pp{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new sr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new pp(function(o){t=o}),cancel:t}}};function Fm(e){return function(n){return e.apply(null,n)}}function zm(e){return P.isObject(e)&&e.isAxiosError===!0}const Vs={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(Vs).forEach(([e,t])=>{Vs[t]=e});function Cl(e){const t=new $n(e),n=Fa($n.prototype.request,t);return P.extend(n,$n.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(Ln(e,o))},n}const ct=Cl(Nr);ct.Axios=$n,ct.CanceledError=sr,ct.CancelToken=$m,ct.isCancel=sl,ct.VERSION=yl,ct.toFormData=co,ct.AxiosError=Ee,ct.Cancel=ct.CanceledError,ct.all=function(t){return Promise.all(t)},ct.spread=Fm,ct.isAxiosError=zm,ct.mergeConfig=Ln,ct.AxiosHeaders=jt,ct.formToJSON=e=>rl(P.isHTMLForm(e)?new FormData(e):e),ct.getAdapter=wl.getAdapter,ct.HttpStatusCode=Vs,ct.default=ct;const{Axios:pC,AxiosError:mC,CanceledError:gC,isCancel:xC,CancelToken:vC,VERSION:wC,all:bC,Cancel:yC,isAxiosError:SC,spread:CC,toFormData:kC,AxiosHeaders:TC,HttpStatusCode:EC,formToJSON:IC,getAdapter:NC,mergeConfig:AC}=ct,kl=typeof window<"u"?window.__API_BASE_URL__:void 0,Tl=kl?kl.replace(/\/+$/,""):void 0;let go=null;const qs=new Set;function El(){return go}function Ks(e){go=e,qs.forEach(t=>t(e))}function Il(e){return qs.add(e),()=>qs.delete(e)}const Bt=ct.create({...Tl?{baseURL:Tl}:{},timeout:3e4,withCredentials:!0});Bt.interceptors.request.use(e=>(go&&(e.headers.Authorization=`Bearer ${go}`),e)),Bt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Ot(e,t){return Bt.defaults.baseURL?(await Bt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Gs(e,t,n){return Bt.defaults.baseURL?(await Bt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nl(e,t,n){return Bt.defaults.baseURL?(await Bt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t){return Bt.defaults.baseURL?(await Bt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Mt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class _l{get baseUrl(){const t=Bt.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(Bt.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Ks(t.authToken)}getAuthToken(){return El()}setAuthToken(t){Ks(t)}onTokenChange(t){return Il(t)}async listThreads(){const t=await Ot("/chat/threads"),n=Mt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Gs("/chat/threads",t?{title:t}:void 0);return Mt(r)}async updateThread(t,n){const r=await Nl(`/chat/threads/${t}`,{title:n});return Mt(r)}async deleteThread(t){const n=await Al(`/chat/threads/${t}`);return Mt(n)}async threadInfo(t){const n=await Ot(`/chat/threads/${t}/info`);return Mt(n)}async listAgents(){const t=await Ot("/chat/agents"),n=Mt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Ot(`/chat/agents/${t}`);return Mt(n)}async getAgentSchema(t){const n=await Ot(`/chat/agents/${t}/schema`);return Mt(n)}async getMessages(t){const n=await Ot(`/chat/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return Mt(n)}async getState(t){const n=await Ot(`/chat/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Mt(n)}async getStateHistory(t){const n=await Ot(`/chat/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Mt(n)}async listCheckpoints(t){const n=await Ot(`/chat/threads/${t}/checkpoints`,{params:{thread_id:t}});return Mt(n)}async resume(t){const n=await Gs("/chat/runs/resume",{thread_id:t.threadId,value:t.value});return Mt(n)}}const yn=new _l;function jl(e={}){const t=e.baseUrl??"/api/chat",n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),[i,a]=y.useState(!1),[c,u]=y.useState(null),[d,f]=y.useState(""),[h,m]=y.useState(null),[b,w]=y.useState(0),[g,x]=y.useState(!1),v=y.useRef(null),S=y.useRef(!0),E=y.useRef(0),C=y.useCallback(j=>{o(j)},[]),k=y.useCallback(()=>{var j;(j=v.current)==null||j.abort(),v.current=null,a(!1),x(!1)},[]),I=y.useCallback(()=>{f(""),m(null),u(null)},[]),N=y.useCallback((j,O,R)=>{v.current&&(v.current.abort(),v.current=null),a(!0),u(null),e.autoAppendAssistant!==!1&&f("");const $=new AbortController;return v.current=$,(async()=>{var M,W,U,V,L,A,q,J;const K=se=>{var te;try{const pe=JSON.parse(JSON.stringify(se));return(te=pe==null?void 0:pe.payload)!=null&&te.files_info&&Array.isArray(pe.payload.files_info)&&(pe.payload.files_info=pe.payload.files_info.map(Ie=>({...Ie,data:Ie!=null&&Ie.data?`<base64 ${String(Ie.data).length} chars>`:Ie==null?void 0:Ie.data}))),pe}catch{return se}};try{let se={};try{if(r)se={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const be=window.__AUTH_TOKEN__,Ue=((M=window.localStorage)==null?void 0:M.getItem("authToken"))||null;let Ye=null;try{const st=(W=window.localStorage)==null?void 0:W.getItem("chat-settings");st&&(Ye=((U=JSON.parse(st))==null?void 0:U.apiKey)||null)}catch{}const $e=be||Ue||Ye||null;$e&&(se={Authorization:`Bearer ${$e}`})}}catch{}console.debug("[use-chat] POST",t+n,K(j));const te=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...se,...s.current},body:JSON.stringify(j),signal:$.signal});if(!te.ok||!te.body){const ke=await te.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",te.status,ke==null?void 0:ke.slice(0,500)),new Error(`stream ${te.status}${ke?": "+ke:""}`)}x(!0);const pe=te.body.getReader(),Ie=new TextDecoder;let Ne="",B=[],_=E.current,H=null;const ee=()=>{if(B.length){const ke=B.join("");B=[],S.current&&f(be=>be+ke)}H=null},ue=()=>{typeof window<"u"&&H==null&&(H=requestAnimationFrame(ee))};let ce=Date.now();const Oe=setInterval(()=>{var ke;if(Date.now()-ce>2e4){const be="Stream idle timeout";u(be),$.abort(),(ke=R==null?void 0:R.onError)==null||ke.call(R,be)}},5e3),Ge=1024*1024;try{const ke=te.headers.get("X-Thread-Id")||te.headers.get("x-thread-id"),be=te.headers.get("X-Thread-Created")||te.headers.get("x-thread-created"),Ue=ke??null,Ye=String(be??"").toLowerCase()==="true";for((V=R==null?void 0:R.onOpen)==null||V.call(R,{threadId:Ue,created:Ye});;){const{value:$e,done:st}=await pe.read();if(st)break;Ne+=Ie.decode($e,{stream:!0}),Ne.length>Ge&&(Ne="",console.warn("Stream buffer reset: exceeded 1MB"));let pt;for(;(pt=Ne.indexOf(`
36
36
 
37
37
  `))>=0;){const it=Ne.slice(0,pt);Ne=Ne.slice(pt+2);const dt=Hm(it);if(!dt)continue;let at;try{at=JSON.parse(dt)}catch{console.debug("[use-chat] malformed SSE:",dt.slice(0,200));continue}const Fe=Bm(at)?at.data:at;ce=Date.now(),O==null||O(Fe);const Y=Fe.seq;if(Y!==void 0){if(Y<=_)continue;_>0&&Y>_+1&&((L=R==null?void 0:R.onGap)==null||L.call(R,{from:_,to:Y})),_=Y,E.current=Y,w(Y)}if(Fe.type==="token"&&e.autoAppendAssistant!==!1)B.push(Fe.content),ue();else if(Fe.type==="message_delta"){const re=Fe.delta.filter(he=>he.type==="text").map(he=>he.text).join("");re&&e.autoAppendAssistant!==!1&&(B.push(re),ue())}else H!==null&&cancelAnimationFrame(H),ee(),Fe.type==="checkpoint"?m(Fe.checkpointId):Fe.type==="error"&&u(Fe.message)}}ee()}catch(ke){if(ke.name!=="AbortError"){const be=ke.message||String(ke);u(be),(A=R==null?void 0:R.onError)==null||A.call(R,be)}}finally{try{await pe.cancel()}catch{}finally{(q=pe.releaseLock)==null||q.call(pe)}H!==null&&typeof window<"u"&&window.cancelAnimationFrame(H),clearInterval(Oe),a(!1),x(!1),v.current=null}}catch(se){if(se.name!=="AbortError"){const te=se.message||String(se);u(te),(J=R==null?void 0:R.onError)==null||J.call(R,te)}}finally{a(!1),x(!1),v.current=null}})(),{close:()=>$.abort()}},[t,n,r,e.autoAppendAssistant]);return y.useEffect(()=>()=>{var j;S.current=!1,(j=v.current)==null||j.abort()},[]),{isStreaming:i,error:c,assistantText:d,lastCheckpointId:h,lastSeq:b,connected:g,stream:N,stop:k,clear:I,setToken:C}}function Bm(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Hm(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
38
- `)}function Um(e){return e.type!=="thread_info"&&e.type!=="token"}const Wm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Vm(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ys(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ys(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ys(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Pl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pl(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Rl(e=[]){const[t,n]=y.useReducer(Vm,{...Wm,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),c=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:c}),[c]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n;if(t.type==="message_start"&&t.role==="assistant"){const r=t.id,o=Xm(t.model);if(e.messages.some(a=>a.id===r))return{...e,assemblingId:r};const i={id:r,role:"assistant",name:o||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:r,messages:[...e.messages,i]}}if(t.type==="message_delta"){const r=e.assemblingId??Xs(e.messages);return r?{...e,messages:Js(e.messages,r,t.delta)}:e}if(t.type==="message_end"){const r=e.assemblingId??Xs(e.messages);if(!r)return{...e,assemblingId:null};const o=e.messages,s=o.findIndex(i=>i.id===r&&i.role==="assistant");if(s>=0&&!((n=o[s].content)==null?void 0:n.some(c=>{var u;return(c==null?void 0:c.type)==="text"&&((u=c.text)==null?void 0:u.trim())}))){const c=[...o.slice(0,s),...o.slice(s+1)];return{...e,assemblingId:null,messages:c}}return e}if(t.type==="tool_start"){const r=t.id??t.call_id,o=t.name??t.tool;if(!r)return e;const s=`tool-${r}`,i={type:"tool_call",id:r,name:o,args:t.args};if(e.messages.find(u=>u.id===s))return{...e,toolIndex:{...e.toolIndex,[r]:s}};const c={id:s,role:"tool",name:o,createdAt:new Date().toISOString(),content:[i]};return{...e,messages:[...e.messages,c],toolIndex:{...e.toolIndex,[r]:s}}}if(t.type==="tool_result"){const r=e.toolIndex[t.id]??`tool-${t.id}`,o={type:"tool_result",toolCallId:t.id,output:t.output,error:t.error},s=e.messages.find(c=>c.id===r),i={id:r,role:"tool",content:[o],createdAt:new Date().toISOString()},a=s?Js(e.messages,r,[o]):[...e.messages,i];return{...e,messages:a}}if(t.type==="checkpoint"){const r=t.checkpointNs??e.lastCheckpointNs??null,o=Ym(e.messages,t.checkpointId,r);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:r,messages:o}}if(t.type==="branch"){const r=t.checkpointId??e.lastCheckpointId,o=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:r??null,lastCheckpointNs:o??null}}if(t.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,r]}}if(t.type==="interrupt"){const r=e.assemblingId??Xs(e.messages),o={type:"interrupt",value:t.value};if(r)return{...e,assemblingId:null,messages:Js(e.messages,r,[o]),pendingInterrupt:{id:t.id,value:t.value}};const s={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ys(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function qm(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Km(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Js(e,t,n){return Km(e,t,r=>({...r,content:Gm(r.content,n)}))}function Gm(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Ym(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return qm(e,r,s)}return e}function Xm(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Jm(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function Zm(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Qm(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await Zm(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const eg={MODE:"library"};function tg(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ps&&Ps.tagName.toUpperCase()==="SCRIPT"&&Ps.src||new URL("index.umd.js",document.baseURI).href}<"u"?eg:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function Zs(){return!tg()}function ng({currentThreadId:e,messageCount:t,setCurrentThreadId:n,markThreadRefreshPending:r,skipNextLoadRef:o}){return y.useCallback(s=>{const i=s.threadId,a=!!s.created,c=!!s.ready;if(e!==i){const u=!e&&t<=1;u&&(o.current=i),n(i),(c||a||u)&&r();return}(c||a)&&r()},[e,r,t,n,o])}function rg(e){const t=e.seq;return typeof t=="number"&&Number.isFinite(t)?t:null}function og({onThreadInfo:e,onMessageEvent:t,onUnhandledEvent:n,onSequenceGap:r}){const o=y.useRef(null),s=y.useCallback(a=>{const c=rg(a);if(c!==null){const u=o.current;if(u!==null){if(c<=u){Zs()&&console.debug("[StreamEventCoordinator] drop out-of-order seq",{prev:u,seq:c,type:a.type});return}c>u+1&&(r==null||r({from:u,to:c}))}o.current=c}if(a.type==="thread_info"){e==null||e(a);return}if(Um(a)){t(a);return}n==null||n(a)},[t,r,e,n]),i=y.useCallback(()=>{o.current=null},[]);return{handleEvent:s,reset:i}}const Ol=y.createContext(null);function xo({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null,autoLoadInitial:s=!0,disableAutoRestore:i=!1,enableFileAgentRouting:a=!1,fileAgentId:c="invoice_reader"}){const u=yn;y.useEffect(()=>{t&&u.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[u,t]);const{isStreaming:d,error:f,stream:h,stop:m,setToken:b}=jl({baseUrl:u.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/runs/stream"}),[w,g]=y.useState(()=>typeof u.getAuthToken=="function"?u.getAuthToken():null);y.useEffect(()=>{b(typeof u.getAuthToken=="function"?u.getAuthToken():null);const D=u.onTokenChange(Z=>{g(Z),b(Z)});return()=>{D()}},[u,b]);const x=y.useCallback(D=>{u.setAuthToken(D)},[u]),{state:v,dispatch:S,seed:E,prepend:C,pushUser:k,onEvent:I,reset:N}=Rl(),j=20,[O,R]=y.useState(!1),[$,K]=y.useState(!1),[M,W]=y.useState(null),[U,V]=y.useState(void 0),[L,A]=y.useState(void 0),q=y.useRef(!1),J=y.useRef([]),se=y.useRef(null),te=y.useCallback(D=>{D.cursor!==void 0&&W(D.cursor),D.hasMore!==void 0&&R(D.hasMore),D.checkpointId!==void 0&&V(D.checkpointId),D.checkpointNs!==void 0&&A(D.checkpointNs)},[]),pe=y.useCallback((D,Z)=>new Promise((Re,Ke)=>{const vt=async()=>{if(q.current){console.warn(`[ChatProvider] Operation "${Z}" queued - another operation in progress`),J.current.push(vt);return}q.current=!0;try{console.log(`[ChatProvider] Executing operation: ${Z}`),await D(),Re()}catch(X){console.error(`[ChatProvider] Operation "${Z}" failed:`,X),Ke(X)}finally{q.current=!1;const X=J.current.shift();X&&X().catch(()=>{})}};q.current?(J.current.push(vt),console.log(`[ChatProvider] Queued operation: ${Z}`)):vt().catch(X=>{Ke(X)})}),[]),Ie=y.useCallback((D,Z)=>{const Re=Array.isArray(D==null?void 0:D.messages)?D.messages:[];Z==="replace"?(console.log("[ChatProvider] Replacing messages, count:",Re.length),E(Re,{checkpointId:(D==null?void 0:D.checkpointId)??null,checkpointNs:(D==null?void 0:D.checkpointNs)??null})):Z==="prepend"&&Re.length?(console.log("[ChatProvider] Calling prepend with",Re.length,"messages"),C(Re)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),W((D==null?void 0:D.nextCursor)??null),R(!!(D!=null&&D.hasMore)),V(Ke=>(D==null?void 0:D.checkpointId)??Ke??void 0),A(Ke=>(D==null?void 0:D.checkpointNs)??Ke??void 0)},[E,C]),[Ne,B]=y.useState([]),[_,H]=y.useState(null),[ee,ue]=y.useState(!1),[ce,Oe]=y.useState(!1),Ge=y.useRef(!1),ke=y.useCallback(()=>{Ge.current=!0},[]),be=y.useCallback(async()=>{ue(!0);try{const D=await u.listThreads();B(D)}finally{ue(!1)}},[u]),Ue=ng({currentThreadId:_,messageCount:v.messages.length,setCurrentThreadId:H,markThreadRefreshPending:ke,skipNextLoadRef:se}),[Ye,$e]=y.useState(!1),st=y.useCallback(async D=>{const Z=(D==null?void 0:D.maxAttempts)??5,Re=(D==null?void 0:D.baseDelayMs)??500,Ke=(D==null?void 0:D.timeoutMs)??2e3;if(!u.baseUrl)return!1;const vt=u.baseUrl.replace(/\/+$/,""),X=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],fe=async Pe=>{try{const ye=new AbortController,et=setTimeout(()=>ye.abort(),Ke),wt=await fetch(Pe,{method:"GET",signal:ye.signal});return clearTimeout(et),wt.ok}catch{return!1}},_e=async Pe=>{try{const ye=new AbortController,et=setTimeout(()=>ye.abort(),Ke),wt=await fetch(Pe,{method:"HEAD",signal:ye.signal});return clearTimeout(et),wt.ok}catch{return!1}};for(let Pe=0;Pe<Z;Pe++){console.debug(`[ChatProvider] health-check attempt ${Pe+1}/${Z}`);for(const et of X){let wt=et;vt.endsWith("/api")&&et.startsWith("/api")&&(wt=et.replace(/^\/api/,"")||"/");const bn=wt==="/"?vt+"/":vt+wt;if(console.debug(`[ChatProvider] checking ${bn}`),await fe(bn)||et==="/"&&await _e(vt+"/"))return $e(!0),!0}const ye=Re*Math.pow(2,Pe);await new Promise(et=>setTimeout(et,ye))}return $e(!1),!1},[u.baseUrl]);y.useEffect(()=>{let D=!0;if(!u.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const Z=await st();if(!D)return;Z?be().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{D=!1}},[be,u.baseUrl,st]),y.useEffect(()=>{r==null||r(_)},[_,r]);const pt=y.useRef(null);y.useEffect(()=>{if(o&&s){if(!u.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!Ye){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}pt.current!==o&&(pt.current=o,Y(o).catch(()=>{}))}},[o,s,u.baseUrl,Ye]);const it=y.useRef(null),dt=y.useRef(null),at=y.useRef(null),Fe=y.useRef({count:0,checkpointId:null,checkpointNs:null});y.useEffect(()=>{at.current=_},[_]),y.useEffect(()=>{Fe.current={count:v.messages.length,checkpointId:v.lastCheckpointId,checkpointNs:v.lastCheckpointNs}},[v.messages.length,v.lastCheckpointId,v.lastCheckpointNs]);const Y=y.useCallback(async(D,Z,Re,Ke=!1)=>{await pe(async()=>{if(se.current===D){console.log(`[ChatProvider] Skipping auto-load for thread ${D} - suppressed after clear`),se.current=null;return}if(!u.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(it.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${it.current}) is loading`);return}const vt=dt.current!==null&&dt.current!==D,X=dt.current===D||at.current===D,fe=Z!==void 0||Re!==void 0,_e=Fe.current.count>0,Pe=Fe.current.checkpointId!==null||Fe.current.checkpointNs!==null;if(!Ke&&!vt&&X&&!fe&&!Pe&&_e){console.debug("[ChatProvider] Fast-return loadThread - reusing existing messages for thread",D),H(D),dt.current=D;return}vt&&(console.log(`[ChatProvider] Thread switch detected: ${dt.current} -> ${D}`),N([])),it.current=D,dt.current=D;try{Oe(!0),te({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),H(D);const ye=await u.getMessages({threadId:D,checkpointId:Z,checkpointNs:Re,limit:j}),et=Array.isArray(ye==null?void 0:ye.messages)?ye.messages:[];console.log("[ChatProvider] Loading thread with",et.length,"messages"),E(et,{checkpointId:(ye==null?void 0:ye.checkpointId)??null,checkpointNs:(ye==null?void 0:ye.checkpointNs)??null}),W((ye==null?void 0:ye.nextCursor)??null),R(!!(ye!=null&&ye.hasMore)),V(wt=>(ye==null?void 0:ye.checkpointId)??wt??void 0),A(wt=>(ye==null?void 0:ye.checkpointNs)??wt??void 0)}finally{it.current=null,Oe(!1)}},`loadThread-${D}`)},[u,pe,te,E]),re=y.useCallback(({from:D,to:Z})=>{const Re=at.current;Re&&(Zs()&&console.warn(`[ChatProvider] Stream sequence gap detected (${D} -> ${Z}) for thread ${Re}`),Y(Re,void 0,void 0,!0).catch(()=>{}))},[Y]),{handleEvent:he,reset:We}=og({onThreadInfo:Ue,onMessageEvent:I,onUnhandledEvent:D=>{Zs()&&console.warn(`[ChatProvider] Unhandled stream event type: ${D.type}`,D)},onSequenceGap:re}),Xe=y.useCallback(async D=>{const Z=await u.listCheckpoints(D);return Jm(Z,D)},[u]),Qe=y.useCallback(async(D,Z)=>{await pe(async()=>{if(!_)throw new Error("No active thread");te({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),Oe(!0);try{const Re=await u.getMessages({threadId:_,checkpointId:D,checkpointNs:Z??void 0,limit:j});Ie(Re,"replace")}finally{Oe(!1)}},`navigateToCheckpoint-${D}`)},[u,_,Ie,pe,te,j]),yt=y.useCallback(async()=>{if(!_)throw new Error("No active thread");await Y(_,void 0,void 0,!0)},[_,Y]),lt=y.useRef(!1);y.useEffect(()=>{const D=lt.current;lt.current=d,D&&!d&&_&&Ge.current&&pe(async()=>{try{await be()}catch(Z){console.warn("[ChatProvider] Post-streaming thread refresh failed:",Z)}finally{Ge.current=!1}},"postStreamingRefresh")},[d,_,be,pe]);const mt=y.useCallback(async()=>{console.log("[ChatProvider] 🔄 clearCurrentThread called"),console.log("[ChatProvider] 📊 Before clear - currentThreadId:",_),console.log("[ChatProvider] 📊 Before clear - messages count:",v.messages.length),_&&(se.current=_,console.log(`[ChatProvider] 🚫 Suppressing next auto-load for thread: ${_}`)),await pe(()=>(console.log("[ChatProvider] 🚀 Executing atomic clear operation"),H(null),N([]),te({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),typeof window<"u"&&localStorage.removeItem("currentThreadId"),console.log("[ChatProvider] ✅ Atomic clear operation completed"),Promise.resolve()),"clearCurrentThread"),console.log("[ChatProvider] 📊 After clear - currentThreadId should be null")},[N,te,_,v.messages.length,pe]),Kt=y.useCallback(async D=>{mt();let Z=null;try{return Z=await u.createThread(D),B(Re=>[...Re.filter(vt=>vt.threadId!==Z.threadId),Z]),await Y(Z.threadId),Z.threadId}catch(Re){if(await be(),Z!=null&&Z.threadId)try{return await Y(Z.threadId),Z.threadId}catch(Ke){console.error("[ChatProvider] Failed to load thread after refresh",Ke)}throw Re}},[u,be,Y,mt]),On=y.useCallback(async D=>{try{await u.deleteThread(D),B(Z=>Z.filter(Re=>Re.threadId!==D)),_===D&&(H(null),N([]),R(!1),W(null),V(void 0),A(void 0))}catch(Z){throw await be(),Z}},[u,be,_,N]),no=y.useCallback(async(D,Z)=>{try{await u.updateThread(D,Z),B(Re=>Re.map(Ke=>Ke.threadId===D?{...Ke,title:Z}:Ke))}catch(Re){throw await be(),Re}},[u,be]),er=y.useCallback(async(D,Z)=>{var Gt;const Re=(Z==null?void 0:Z.attachments)||[],{contentParts:Ke,filesInfo:vt}=await Qm(u,Re,t==null?void 0:t.uploadPath),X=[];D&&D.trim()&&X.push({type:"text",text:D.trim()});const fe={id:((Gt=crypto.randomUUID)==null?void 0:Gt.call(crypto))||`user-${Date.now()}`,role:"user",content:X,createdAt:new Date().toISOString(),checkpointId:(Z==null?void 0:Z.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(Z==null?void 0:Z.checkpointNs)??v.lastCheckpointNs??void 0};k(fe);const _e={...fe,content:X},Pe={...(Z==null?void 0:Z.payloadExtras)??{}},ye=!!Pe.edit,et=Pe.originalMessageId,wt=typeof et=="string"?et:void 0,bn=Re&&Re.length>0,yr={..._?{threadId:_}:{},payload:{messages:[_e],files_info:vt,...a&&bn&&c?{active_agent:c}:{},...Pe},checkpointId:(Z==null?void 0:Z.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(Z==null?void 0:Z.checkpointNs)??v.lastCheckpointNs??void 0,nodeFilter:Z==null?void 0:Z.nodeFilter,config:Z==null?void 0:Z.config,edit:ye,originalMessageId:wt};We(),ke(),h(yr,T=>{he(T)},{onError:T=>console.warn("stream error",T),onOpen:({threadId:T,created:z})=>{if(!_&&T){const ne=v.messages.length<=1;ne&&(se.current=T),H(T),(z||ne)&&ke()}},onGap:re})},[_,k,h,he,We,re,v.lastCheckpointId,v.lastCheckpointNs,u,t==null?void 0:t.uploadPath,ke,H,a,c,v.messages.length]),br=y.useCallback(async D=>{if(!_)throw new Error("No active thread");if($||!O)return;const Z=M;if(Z){K(!0);try{const Re=await u.getMessages({threadId:_,checkpointId:U,checkpointNs:L,limit:(D==null?void 0:D.limit)??j,beforeId:Z});Ie(Re,"prepend")}finally{K(!1)}}},[u,_,U,L,M,O,$,Ie,j]),gn=y.useCallback(async(D,Z,Re)=>{if(!_)throw new Error("No active thread to handle interrupt");try{console.log(`[ChatProvider] Handling interrupt ${D}: ${Z?"approved":"rejected"}`);const Ke=!!Z;await u.resume({threadId:_,value:Ke}),console.log(`[ChatProvider] Interrupt ${D} handled successfully`),S({type:"interrupt_response",payload:{interruptId:D}})}catch(Ke){throw console.error(`[ChatProvider] Failed to handle interrupt ${D}:`,Ke),Ke}},[u,_]),tr={baseUrl:u.baseUrl,token:w,setToken:x,api:u,threads:Ne,currentThreadId:_,setCurrentThreadId:H,isLoadingThreads:ee,isLoadingThread:ce,messages:v.messages,isStreaming:d,error:f,lastCheckpointId:v.lastCheckpointId,lastCheckpointNs:v.lastCheckpointNs,streamingAssistantId:v.assemblingId,hasMoreHistory:O,isLoadingHistory:$,loadOlderMessages:br,historyPageSize:j,listCheckpoints:Xe,navigateToCheckpoint:Qe,returnToLatest:yt,refreshThreads:be,createThread:Kt,deleteThread:On,renameThread:no,loadThread:Y,clearCurrentThread:mt,send:er,stop:m,handleInterrupt:gn};return l.jsx(Ol.Provider,{value:tr,children:e})}function _r(){const e=y.useContext(Ol);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function Q(...e){return gp.twMerge(mp.clsx(e))}const sg=ro.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"}}),Be=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Mn.Slot:"button";return l.jsx(i,{className:Q(sg({variant:t,size:n,className:e})),ref:s,...o})});Be.displayName="Button";const Ml=p.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:Q("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",e),ref:n,...t}));Ml.displayName="Textarea";function ig({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,m]=y.useState(e),[b,w]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const N=g.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);y.useEffect(()=>{x()},[x]);const v=y.useCallback(async N=>{N&&N.preventDefault();const j=(h??"").trim();!j&&!f||w(()=>{try{const O=i(j);O&&typeof O.then=="function"?O.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(N=>{m(N.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=y.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),v()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[v,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"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 l.jsx("form",{onSubmit:N=>void v(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Ml,{ref:g,value:h,onChange:S,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(Be,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(oe.Square,{size:16})}):l.jsx(Be,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||b,children:l.jsx(oe.Send,{size:16})})})]})})}const ag=y.memo(ig),vo=0,Sn=1,ir=2,Dl=4;function Ll(e){return()=>e}function lg(e){e()}function $l(e,t){return n=>e(t(n))}function Fl(e,t){return()=>e(t)}function cg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function ug(...e){return()=>{e.map(lg)}}function ar(){}function wo(e,t){return t(e),e}function dg(e,t){return t(e)}function nt(...e){return e}function Ve(e,t){return e(Sn,t)}function Ae(e,t){e(vo,t)}function ei(e){e(ir)}function ut(e){return e(Dl)}function de(e,t){return Ve(e,cg(t,vo))}function Jt(e,t){const n=e(Sn,r=>{n(),t(r)});return n}function zl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Bl(e,t){return e===t}function rt(e=Bl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ve(e){return t=>n=>{e(n)&&t(n)}}function ie(e){return t=>$l(t,e)}function on(e){return t=>()=>{t(e)}}function F(e,...t){const n=fg(...t);return(r,o)=>{switch(r){case ir:ei(e);return;case Sn:return Ve(e,n(o))}}}function sn(e,t){return n=>r=>{n(t=e(t,r))}}function Fn(e){return t=>n=>{e>0?e--:t(n)}}function xn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function je(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ve(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function fg(...e){return t=>e.reduceRight(dg,t)}function hg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Sn:return s?n===s?void 0:(r(),n=s,t=Ve(e,s),t):(r(),ar);case ir:r(),n=null;return}}}function G(e){let t=e;const n=Le();return(r,o)=>{switch(r){case vo:t=o;break;case Sn:{o(t);break}case Dl:return t}return n(r,o)}}function kt(e,t){return wo(G(t),n=>de(e,n))}function Le(){const e=[];return(t,n)=>{switch(t){case vo:e.slice().forEach(r=>{r(n)});return;case ir:e.splice(0,e.length);return;case Sn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Dt(e){return wo(Le(),t=>de(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:pg(),singleton:n}}const pg=()=>Symbol();function mg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function ht(...e){const t=Le(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ve(s,c=>{n[i]=c,r=r|a,r===o&&Ae(t,n)})}),function(s,i){switch(s){case ir:{ei(t);return}case Sn:return r===o&&i(n),Ve(t,i)}}}function xe(e,t=Bl){return F(e,rt(t))}function ti(...e){return function(t,n){switch(t){case ir:return;case Sn:return ug(...e.map(r=>Ve(r,n)))}}}var Rt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Rt||{});const gg={0:"debug",3:"error",1:"log",2:"warn"},xg=()=>typeof globalThis>"u"?window:globalThis,Cn=He(()=>{const e=G(3);return{log:G((t,n,r=1)=>{var o;const s=(o=xg().VIRTUOSO_LOG_LEVEL)!=null?o:ut(e);r>=s&&console[gg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function zn(e,t,n){return ni(e,t,n).callbackRef}function ni(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function vg(e,t,n,r,o,s,i,a,c){const u=y.useCallback(d=>{const f=wg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const m=h.lastElementChild.dataset.viewportType==="window";let b;m&&(b=h.ownerDocument.defaultView);const w=i?a?i.scrollLeft:i.scrollTop:m?a?b.scrollX||b.document.documentElement.scrollLeft:b.scrollY||b.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:m?a?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:m?a?b.innerWidth:b.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(w,0),viewportHeight:x}),s==null||s(a?Hl("column-gap",getComputedStyle(d).columnGap,o):Hl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,c)}function wg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Rt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Hl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Rt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ul(e,t,n){const r=y.useRef(null),o=y.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,h;if(t){const m=t.getBoundingClientRect(),b=u.top-m.top;h=m.height-Math.max(0,b),f=b+t.scrollTop}else{const m=i.current.ownerDocument.defaultView;h=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const It=He(()=>{const e=Le(),t=Le(),n=G(0),r=Le(),o=G(0),s=Le(),i=Le(),a=G(0),c=G(0),u=G(0),d=G(0),f=Le(),h=Le(),m=G(!1),b=G(!1),w=G(!1);return de(F(e,ie(({scrollTop:g})=>g)),t),de(F(e,ie(({scrollHeight:g})=>g)),i),de(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:b,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:w,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),jr={lvl:0};function Wl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Je(e){return e===jr}function Rr(e,t){if(!Je(e))return t===e.k?e.v:t<e.k?Rr(e.l,t):Rr(e.r,t)}function Zt(e,t,n="k"){if(Je(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Zt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Zt(e.l,t,n)}function Lt(e,t,n){return Je(e)?Kl(t,n,1):t===e.k?xt(e,{k:t,v:n}):t<e.k?Gl(xt(e,{l:Lt(e.l,t,n)})):Gl(xt(e,{r:Lt(e.r,t,n)}))}function lr(){return jr}function bo(e,t,n){if(Je(e))return[];const r=Zt(e,t)[0];return bg(oi(e,r,n))}function ri(e,t){if(Je(e))return jr;const{k:n,l:r,r:o}=e;if(t===n){if(Je(r))return o;if(Je(o))return r;{const[s,i]=ql(r);return yo(xt(e,{k:s,l:Vl(r),v:i}))}}else return t<n?yo(xt(e,{l:ri(r,t)})):yo(xt(e,{r:ri(o,t)}))}function Bn(e){return Je(e)?[]:[...Bn(e.l),{k:e.k,v:e.v},...Bn(e.r)]}function oi(e,t,n){if(Je(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oi(s,t,n))),a}function yo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(si(t))return Yl(xt(e,{lvl:n-1}));if(!Je(t)&&!Je(t.r))return xt(t.r,{l:xt(t,{r:t.r.l}),lvl:n,r:xt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(xt(e,{lvl:n-1}));if(!Je(r)&&!Je(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return xt(o,{l:xt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(xt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function xt(e,t){return Kl(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Vl(e){return Je(e.r)?e.l:yo(xt(e,{r:Vl(e.r)}))}function si(e){return Je(e)||e.lvl>e.r.lvl}function ql(e){return Je(e.r)?[e.k,e.v]:ql(e.r)}function Kl(e,t,n,r=jr,o=jr){return{k:e,l:r,lvl:n,r:o,v:t}}function Gl(e){return ii(Yl(e))}function Yl(e){const{l:t}=e;return!Je(t)&&t.lvl===e.lvl?xt(t,{r:xt(e,{l:t.r})}):e}function ii(e){const{lvl:t,r:n}=e;return!Je(n)&&!Je(n.r)&&n.lvl===t&&n.r.lvl===t?xt(n,{l:xt(e,{r:n.l}),lvl:t+1}):e}function bg(e){return Wl(e,({k:t,v:n})=>({index:t,value:n}))}function Xl(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Pr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=He(()=>({recalcInProgress:G(!1)}),[],{singleton:!0});function Jl(e,t,n){return e[So(e,t,n)]}function So(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function yg(e,t,n,r){const o=So(e,t,r),s=So(e,n,r,o);return e.slice(o,s+1)}function kn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Co(e){return!Je(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function Sg(){return{groupIndices:[],groupOffsetTree:lr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:lr()}}function Cg(e,t){let n=Je(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Je(e)){e=Lt(e,0,s);continue}const a=bo(e,i-1,o+1);if(a.some(_g(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=Lt(e,o+1,h));u&&(e=Lt(e,i,s))}return[e,n]}function kg(e){return typeof e.groupIndex<"u"}function Tg({offset:e},t){return t===e?0:t<e?-1:1}function Or(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Jl(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Zl(e,t){if(!Co(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ql(e,t,n){if(kg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Zl(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Eg(e,t,n,r=0){return r>0&&(t=Math.max(t,Jl(e,r,li).offset)),Wl(yg(e,t,n,Tg),Ag)}function Ig(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Rt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Je(s)&&t.length===2){const h=t[0].size,m=t[1].size;i=n.reduce((b,w)=>Lt(Lt(b,w,h),w+1,m),i)}else[i,a]=Cg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,m)=>Lt(h,m,Or(m,f,o)),lr()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Ng(e){return Bn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function ec(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function ci(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=So(o,t-1,li),a=o[c].offset;const u=Zt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Zt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of bo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Ag(e){return{index:e.index,value:e}}function _g(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const jg={offsetHeight:"height",offsetWidth:"width"},an=He(([{log:e},{recalcInProgress:t}])=>{const n=Le(),r=Le(),o=kt(r,0),s=Le(),i=Le(),a=G(0),c=G([]),u=G(void 0),d=G(void 0),f=G((C,k)=>kn(C,jg[k])),h=G(void 0),m=G(0),b=Sg(),w=kt(F(n,je(c,e,m),sn(Ig,b),rt()),b),g=kt(F(c,rt(),sn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),ie(({prev:C})=>C)),[]);de(F(c,ve(C=>C.length>0),je(w,m),ie(([C,k,I])=>{const N=C.reduce((j,O,R)=>Lt(j,O,Or(O,k.offsetTree,I)||R),lr());return{...k,groupIndices:C,groupOffsetTree:N}})),w),de(F(r,je(w),ve(([C,{lastIndex:k}])=>C<k),ie(([C,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:C}])),n),de(u,d);const x=kt(F(u,ie(C=>C===void 0)),!0);de(F(d,ve(C=>C!==void 0&&Je(ut(w).sizeTree)),ie(C=>[{endIndex:0,size:C,startIndex:0}])),n);const v=Dt(F(n,je(w),sn(({sizes:C},[k,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:b}),ie(C=>C.changed)));Ve(F(a,sn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),ie(C=>C.diff)),C=>{const{groupIndices:k}=ut(w);if(C>0)Ae(t,!0),Ae(s,C+ec(C,k));else if(C<0){const I=ut(g);I.length>0&&(C-=ec(-C,I)),Ae(i,C)}}),Ve(F(a,je(e)),([C,k])=>{C<0&&k("`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:a},Rt.ERROR)});const S=Dt(s);de(F(s,je(w),ie(([C,k])=>{const I=k.groupIndices.length>0,N=[],j=k.lastSize;if(I){const O=Rr(k.sizeTree,0);let R=0,$=0;for(;R<C;){const M=k.groupIndices[$],W=k.groupIndices.length===$+1?1/0:k.groupIndices[$+1]-M-1;N.push({endIndex:M,size:O,startIndex:M}),N.push({endIndex:M+1+W-1,size:j,startIndex:M+1}),$++,R+=W+1}const K=Bn(k.sizeTree);return R!==C&&K.shift(),K.reduce((M,{k:W,v:U})=>{let V=M.ranges;return M.prevSize!==0&&(V=[...M.ranges,{endIndex:W+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:W+C,prevSize:U,ranges:V}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Bn(k.sizeTree).reduce((O,{k:R,v:$})=>({prevIndex:R+C,prevSize:$,ranges:[...O.ranges,{endIndex:R+C-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=Dt(F(i,je(w,m),ie(([C,{offsetTree:k},I])=>{const N=-C;return Or(N,k,I)})));return de(F(i,je(w,m),ie(([C,k,I])=>{if(k.groupIndices.length>0){if(Je(k.sizeTree))return k;let N=lr();const j=ut(g);let O=0,R=0,$=0;for(;O<-C;){$=j[R];const K=j[R+1]-$-1;R++,O+=K+1}if(N=Bn(k.sizeTree).reduce((K,{k:M,v:W})=>Lt(K,Math.max(0,M+C),W),N),O!==-C){const K=Rr(k.sizeTree,$);N=Lt(N,0,K);const M=Zt(k.sizeTree,-C+1)[1];N=Lt(N,1,M)}return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}else{const N=Bn(k.sizeTree).reduce((j,{k:O,v:R})=>Lt(j,Math.max(0,O+C),R),lr());return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}})),w),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:m,groupIndices:c,itemSize:f,listRefresh:v,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:w,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},nt(Cn,ai),{singleton:!0});function Rg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const tc=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Le(),i=Le(),a=Dt(F(s,ie(Rg)));return de(F(a,ie(c=>c.totalCount)),n),de(F(a,ie(c=>c.groupIndices)),e),de(F(ht(o,t,r),ve(([c,u])=>Co(u)),ie(([c,u,d])=>Zt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),rt(),ie(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},nt(an,It)),Tn=He(([{log:e}])=>{const t=G(!1),n=Dt(F(t,ve(r=>r),rt()));return Ve(t,r=>{r&&ut(e)("props updated",{},Rt.DEBUG)}),{didMount:n,propsReady:t}},nt(Cn),{singleton:!0}),Pg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function nc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Pg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Mr=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const m=Le(),b=Le(),w=G(0);let g=null,x=null,v=null;function S(){g&&(g(),g=null),v&&(v(),v=null),x&&(clearTimeout(x),x=null),Ae(c,!1)}return de(F(m,je(n,f,r,w,a,i,h),je(e,s,o),ie(([[E,C,k,I,N,j,O,R],$,K,M])=>{const W=nc(E),{align:U,behavior:V,offset:L}=W,A=I-1,q=Ql(W,C,A);let J=Or(q,C.offsetTree,$)+j;U==="end"?(J+=K+Zt(C.sizeTree,q)[1]-k+M,q===A&&(J+=O)):U==="center"?J+=(K+Zt(C.sizeTree,q)[1]-k+M)/2:J-=N,L&&(J+=L);const se=te=>{S(),te?(R("retrying to scroll to",{location:E},Rt.DEBUG),Ae(m,E)):(Ae(b,!0),R("list did not change, scroll successful",{},Rt.DEBUG))};if(S(),V==="smooth"){let te=!1;v=Ve(t,pe=>{te=te||pe}),g=Jt(d,()=>{se(te)})}else g=Jt(F(t,Og(150)),se);return x=setTimeout(()=>{S()},1200),Ae(c,!0),R("scrolling from index to",{behavior:V,index:q,top:J},Rt.DEBUG),{behavior:V,top:J}})),u),{scrollTargetReached:b,scrollToIndex:m,topListHeight:w}},nt(an,It,Cn),{singleton:!0});function Og(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ui(e,t){e==0?t():requestAnimationFrame(()=>{ui(e-1,t)})}function di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Dr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=G(!0),c=G(0),u=G(!0);return de(F(i,je(c),ve(([d,f])=>!!f),on(!1)),a),de(F(i,je(c),ve(([d,f])=>!!f),on(!1)),u),Ve(F(ht(t,i),je(a,n,e,u),ve(([[,d],f,{sizeTree:h},m,b])=>d&&(!Je(h)||Qs(m))&&!f&&!b),je(c)),([,d])=>{Jt(o,()=>{Ae(u,!0)}),ui(4,()=>{Jt(r,()=>{Ae(a,!0)}),Ae(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},nt(an,It,Mr,Tn),{singleton:!0});function rc(e,t){return Math.abs(e-t)<1.01}const Lr="up",$r="down",Mg="none",Dg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Lg=0,Fr=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=G(!1),a=G(!0),c=Le(),u=Le(),d=G(4),f=G(Lg),h=kt(F(ti(F(xe(o),Fn(1),on(!0)),F(xe(o),Fn(1),on(!1),zl(100))),rt()),!1),m=kt(F(ti(F(n,on(!0)),F(n,on(!1),zl(200))),rt()),!1);de(F(ht(xe(o),xe(f)),ie(([v,S])=>v<=S),rt()),a),de(F(a,xn(50)),u);const b=Dt(F(ht(r,xe(s),xe(t),xe(e),xe(d)),sn((v,[{scrollHeight:S,scrollTop:E},C,k,I,N])=>{const j=E+C-S>-N,O={scrollHeight:S,scrollTop:E,viewportHeight:C};if(j){let $,K;return E>v.state.scrollTop?($="SCROLLED_DOWN",K=v.state.scrollTop-E):($="SIZE_DECREASED",K=v.state.scrollTop-E||v.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:K,state:O}}let R;return O.scrollHeight>v.state.scrollHeight?R="SIZE_INCREASED":C<v.state.viewportHeight?R="VIEWPORT_HEIGHT_DECREASING":E<v.state.scrollTop?R="SCROLLING_UPWARDS":R="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:R,state:O}},Dg),rt((v,S)=>v&&v.atBottom===S.atBottom))),w=kt(F(r,sn((v,{scrollHeight:S,scrollTop:E,viewportHeight:C})=>{if(rc(v.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:E};{const k=S-(E+C)<1;return v.scrollTop!==E&&k?{changed:!0,jump:v.scrollTop-E,scrollHeight:S,scrollTop:E}:{changed:!0,jump:0,scrollHeight:S,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ve(v=>v.changed),ie(v=>v.jump)),0);de(F(b,ie(v=>v.atBottom)),i),de(F(i,xn(50)),c);const g=G($r);de(F(r,ie(({scrollTop:v})=>v),rt(),sn((v,S)=>ut(m)?{direction:v.direction,prevScrollTop:S}:{direction:S<v.prevScrollTop?Lr:$r,prevScrollTop:S},{direction:$r,prevScrollTop:0}),ie(v=>v.direction)),g),de(F(r,xn(50),on(Mg)),g);const x=G(0);return de(F(h,ve(v=>!v),on(0)),x),de(F(o,xn(100),je(h),ve(([v,S])=>!!S),sn(([v,S],[E])=>[S,E],[0,0]),ie(([v,S])=>S-v)),x),{atBottomState:b,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:w,scrollDirection:g,scrollVelocity:x}},nt(It)),ko="top",To="bottom",oc="none";function sc(e,t,n){return typeof e=="number"?n===Lr&&t===ko||n===$r&&t===To?e:0:n===Lr?t===ko?e.main:e.reverse:t===To?e.main:e.reverse}function ic(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Le(),i=G(0),a=G(0),c=G(0),u=kt(F(ht(xe(r),xe(o),xe(n),xe(s,Pr),xe(c),xe(i),xe(t),xe(e),xe(a)),ie(([d,f,h,[m,b],w,g,x,v,S])=>{const E=d-v,C=g+x,k=Math.max(h-E,0);let I=oc;const N=ic(S,ko),j=ic(S,To);return m-=v,m+=h+x,b+=h+x,b-=v,m>d+C-N&&(I=Lr),b<d-k+f+j&&(I=$r),I!==oc?[Math.max(E-h-sc(w,ko,I)-N,0),E-k-x+f+sc(w,To,I)+j]:null}),ve(d=>d!=null),rt(Pr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},nt(It),{singleton:!0});function $g(e,t,n){if(Co(t)){const r=Zl(e,t);return[{index:Zt(t.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:e,offset:0,size:0}]}const hi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Eo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const w=e[e.length-1];d=w.offset+w.size}const f=n-i,h=a+f*c+(f-1)*r,m=u,b=h-d;return{bottom:d,firstItemIndex:s,items:lc(e,o,s),offsetBottom:b,offsetTop:u,top:m,topItems:lc(t,o,s),topListHeight:t.reduce((w,g)=>g.size+w,0),totalCount:n}}function ac(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,c=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return Eo(u,[],a,o,n,r)}function lc(e,t,n){if(e.length===0)return[];if(!Co(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=bo(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Hn=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:m},{recalcInProgress:b}])=>{const w=G([]),g=G(0),x=Le();de(s.topItemsIndexes,w);const v=kt(F(ht(m,b,xe(c,Pr),xe(o),xe(r),xe(u),d,xe(w),xe(t),xe(n),e),ve(([k,I,,N,,,,,,,j])=>{const O=j&&j.length!==N;return k&&!I&&!O}),ie(([,,[k,I],N,j,O,R,$,K,M,W])=>{const U=j,{offsetTree:V,sizeTree:L}=U,A=ut(g);if(N===0)return{...hi,totalCount:N};if(k===0&&I===0)return A===0?{...hi,totalCount:N}:ac(A,O,j,K,M,W||[]);if(Je(L))return A>0?null:Eo($g(di(O,N),U,W),[],N,M,U,K);const q=[];if($.length>0){const Ie=$[0],Ne=$[$.length-1];let B=0;for(const _ of bo(L,Ie,Ne)){const H=_.value,ee=Math.max(_.start,Ie),ue=Math.min(_.end,Ne);for(let ce=ee;ce<=ue;ce++)q.push({data:W==null?void 0:W[ce],index:ce,offset:B,size:H}),B+=H}}if(!R)return Eo([],q,N,M,U,K);const J=$.length>0?$[$.length-1]+1:0,se=Eg(V,k,I,J);if(se.length===0)return null;const te=N-1,pe=wo([],Ie=>{for(const Ne of se){const B=Ne.value;let _=B.offset,H=Ne.start;const ee=B.size;if(B.offset<k){H+=Math.floor((k-B.offset+M)/(ee+M));const ce=H-Ne.start;_+=ce*ee+ce*M}H<J&&(_+=(J-H)*ee,H=J);const ue=Math.min(Ne.end,te);for(let ce=H;ce<=ue&&!(_>=I);ce++)Ie.push({data:W==null?void 0:W[ce],index:ce,offset:_,size:ee}),_+=ee+M}});return Eo(pe,q,N,M,U,K)}),ve(k=>k!==null),rt()),hi);de(F(e,ve(Qs),ie(k=>k==null?void 0:k.length)),o),de(F(v,ie(k=>k.topListHeight)),f),de(f,a),de(F(v,ie(k=>[k.top,k.bottom])),i),de(F(v,ie(k=>k.items)),x);const S=Dt(F(v,ve(({items:k})=>k.length>0),je(o,e),ve(([{items:k},I])=>k[k.length-1].originalIndex===I-1),ie(([,k,I])=>[k-1,I]),rt(Pr),ie(([k])=>k))),E=Dt(F(v,xn(200),ve(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),ie(({items:k})=>k[0].index),rt())),C=Dt(F(v,ve(({items:k})=>k.length>0),ie(({items:k})=>{let I=0,N=k.length-1;for(;k[I].type==="group"&&I<N;)I++;for(;k[N].type==="group"&&N>I;)N--;return{endIndex:k[N].index,startIndex:k[I].index}}),rt(Xl)));return{endReached:S,initialItemCount:g,itemsRendered:x,listState:v,rangeChanged:C,startReached:E,topItemsIndexes:w,...h}},nt(an,tc,fi,Dr,Mr,Fr,Tn,ai),{singleton:!0}),cc=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Le(),i=kt(F(ht(n,e,r,t,o),ie(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return de(xe(i),s),{totalListHeight:i,totalListHeightChanged:s}},nt(It,Hn),{singleton:!0}),Fg=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=G(!1),r=kt(F(ht(n,e,t),ve(([o])=>o),ie(([,o,s])=>Math.max(0,o-s)),xn(0),rt()),0);return{alignToBottom:n,paddingTopAddition:r}},nt(It,cc),{singleton:!0}),uc=He(()=>({context:G(null)})),zg=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,dc=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=Le();return de(F(d,je(t,c,n,s,o,r,a),je(e),ie(([[f,h,m,b,w,g,x,v],S])=>{const{align:E,behavior:C,calculateViewLocation:k=zg,done:I,...N}=f,j=Ql(f,h,b-1),O=Or(j,h.offsetTree,S)+w+g,R=O+Zt(h.sizeTree,j)[1],$=v+g,K=v+m-x,M=k({itemBottom:R,itemTop:O,locationParams:{align:E,behavior:C,...N},viewportBottom:K,viewportTop:$});return M?I&&Jt(F(i,ve(W=>!W),Fn(ut(i)?1:2)),I):I&&I(),M}),ve(f=>f!==null)),u),{scrollIntoView:d}},nt(an,It,Mr,Hn,Cn),{singleton:!0});function fc(e){return e?e==="smooth"?"smooth":"auto":!1}const Bg=(e,t)=>typeof e=="function"?fc(e(t)):t&&fc(e),Hg=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:m}])=>{const b=G(!1),w=Le();let g=null;function x(C){Ae(i,{align:"end",behavior:C,index:"LAST"})}Ve(F(ht(F(xe(t),Fn(1)),c),je(xe(b),s,a,f),ie(([[C,k],I,N,j,O])=>{let R=k&&j,$="auto";return R&&($=Bg(I,N||O),R=R&&!!$),{followOutputBehavior:$,shouldFollow:R,totalCount:C}}),ve(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{g&&(g(),g=null),ut(n)?requestAnimationFrame(()=>{ut(d)("following output to ",{totalCount:k},Rt.DEBUG),x(C)}):g=Jt(e,()=>{ut(d)("following output to ",{totalCount:k},Rt.DEBUG),x(C),g=null})});function v(C){const k=Jt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ut(d)("scrolling to bottom due to increased size",{},Rt.DEBUG),x("auto"))});setTimeout(k,100)}Ve(F(ht(xe(b),t,u),ve(([C,,k])=>C&&k),sn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),ve(({refreshed:C})=>C),je(b,t)),([,C])=>{ut(a)&&v(C!==!1)}),Ve(w,()=>{v(ut(b)!==!1)}),Ve(ht(xe(b),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=G(null),E=Le();return de(ti(F(xe(r),ie(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),F(xe(t))),E),Ve(F(ht(F(E,Fn(1)),c),je(xe(S),a,f,h),ie(([[C,k],I,N,j,O])=>k&&N&&(I==null?void 0:I({context:O,totalCount:C,scrollingInProgress:j}))),ve(C=>!!C),xn(0)),C=>{g&&(g(),g=null),ut(n)?requestAnimationFrame(()=>{ut(d)("scrolling into view",{}),Ae(m,C)}):g=Jt(e,()=>{ut(d)("scrolling into view",{}),Ae(m,C),g=null})}),{autoscrollToBottom:w,followOutput:b,scrollIntoViewOnChange:S}},nt(an,Fr,Mr,Dr,Tn,Cn,It,uc,dc)),Ug=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(de(F(a,je(s),ve(([,c])=>c!==0),je(o,r,t,n,e),ie(([[,c],u,d,f,h,m=[]])=>ac(c,u,d,f,h,m))),i),{}),nt(an,Dr,Hn,Tn),{singleton:!0}),Wg=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=G(0);return Ve(F(e,je(r),ve(([,o])=>o!==0),ie(([,o])=>({top:o}))),o=>{Jt(F(n,Fn(1),ve(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(t,o)})})}),{initialScrollTop:r}},nt(Tn,It,Hn),{singleton:!0}),hc=He(([{scrollVelocity:e}])=>{const t=G(!1),n=Le(),r=G(!1);return de(F(e,je(r,t,n),ve(([o,s])=>!!s),ie(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),rt()),t),Ve(F(ht(t,e,n),je(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},nt(Fr),{singleton:!0}),pi=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=Le(),r=Le(),o=Le(),s=G(!1),i=G(void 0);return de(F(ht(n,r),ie(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),de(F(t,je(r),ie(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},nt(It)),Vg=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=Le(),d=G(void 0),f=G(null),h=G(null);return de(a,f),de(c,h),Ve(F(u,je(t,r,i,f,h,n)),([m,b,w,g,x,v,S])=>{const E=Ng(b.sizeTree);g&&x!==null&&v!==null&&(w=x.scrollTop-v.offsetTop),w-=S,m({ranges:E,scrollTop:w})}),de(F(d,ve(Qs),ie(qg)),o),de(F(s,je(d),ve(([,m])=>m!==void 0),rt(),ie(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:d}},nt(an,It,Dr,Tn,pi));function qg(e){return{align:"start",index:0,offset:e.scrollTop}}const Kg=He(([{topItemsIndexes:e}])=>{const t=G(0);return de(F(t,ve(n=>n>=0),ie(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},nt(Hn));function pc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Gg=pc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Yg=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:m},{recalcInProgress:b}])=>{const w=Dt(F(c,je(i),sn(([,x,v,S],[{bottom:E,items:C,offsetBottom:k,totalCount:I},N])=>{const j=E+k;let O=0;return v===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(O=j-S,O!==0&&(O+=N))),[O,C,I,j]},[0,[],0,0]),ve(([x])=>x!==0),je(r,a,n,o,m,b),ve(([,x,v,S,,,E])=>!E&&!S&&x!==0&&v===Lr),ie(([[x],,,,,v])=>(v("Upward scrolling compensation",{amount:x},Rt.DEBUG),x))));function g(x){x>0?(Ae(t,{behavior:"auto",top:-x}),Ae(e,0)):(Ae(e,0),Ae(t,{behavior:"auto",top:-x}))}return Ve(F(w,je(e,s)),([x,v,S])=>{S&&Gg()?Ae(e,v-x):g(-x)}),Ve(F(ht(kt(s,!1),e,b),ve(([x,v,S])=>!x&&!S&&v!==0),ie(([x,v])=>v),xn(1)),g),de(F(f,ie(x=>({top:-x}))),t),Ve(F(u,je(h,d),ie(([x,{groupIndices:v,lastSize:S,sizeTree:E},C])=>{function k(I){return I*(S+C)}if(v.length===0)return k(x);{let I=0;const N=Rr(E,0);let j=0,O=0;for(;j<x;){j++,I+=N;let R=v.length===O+1?1/0:v[O+1]-v[O]-1;j+R>x&&(I-=N,R=x-j+1),j+=R,I+=k(R),O++}return I}})),x=>{Ae(e,x),requestAnimationFrame(()=>{Ae(t,{top:x}),requestAnimationFrame(()=>{Ae(e,0),Ae(b,!1)})})}),{deviation:e}},nt(It,Fr,Hn,an,Cn,ai)),Xg=He(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),nt(fi,Ug,Tn,hc,cc,Wg,Fg,pi,dc,Cn,uc)),mc=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:b},w,g,x,{listState:v,topItemsIndexes:S,...E},{scrollToIndex:C},k,{topItemCount:I},{groupCounts:N},j])=>(de(E.rangeChanged,j.scrollSeekRangeChanged),de(F(j.windowViewportRect,ie(O=>O.visibleHeight)),w.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:b,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:v,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...j,...w,sizes:c,...g}),nt(an,Dr,It,Vg,Hg,Hn,Mr,Yg,Kg,tc,Xg));function Jg(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Io=typeof document<"u"?y.useLayoutEffect:y.useEffect;function gc(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=y.createContext({});function c(g,x){g.propsReady&&Ae(g.propsReady,!1);for(const v of r){const S=g[t.required[v]];Ae(S,x[v])}for(const v of o)if(v in x){const S=g[t.optional[v]];Ae(S,x[v])}g.propsReady&&Ae(g.propsReady,!0)}function u(g){return s.reduce((x,v)=>(x[v]=S=>{const E=g[t.methods[v]];Ae(E,S)},x),{})}function d(g){return i.reduce((x,v)=>(x[v]=hg(g[t.events[v]]),x),{})}const f=y.forwardRef((g,x)=>{const{children:v,...S}=g,[E]=y.useState(()=>wo(mg(e),I=>{c(I,S)})),[C]=y.useState(Fl(d,E));Io(()=>{for(const I of i)I in S&&Ve(C[I],S[I]);return()=>{Object.values(C).map(ei)}},[S,C,E]),Io(()=>{c(E,S)}),y.useImperativeHandle(x,Ll(u(E)));const k=n;return l.jsx(a.Provider,{value:E,children:n?l.jsx(k,{...Jg([...r,...o,...i],S),children:v}):v})}),h=g=>{const x=y.useContext(a);return y.useCallback(v=>{Ae(x[g],v)},[x,g])},m=g=>{const x=y.useContext(a)[g],v=y.useCallback(S=>Ve(x,S),[x]);return y.useSyncExternalStore(v,()=>ut(x),()=>ut(x))},b=g=>{const x=y.useContext(a)[g],[v,S]=y.useState(Fl(ut,x));return Io(()=>Ve(x,E=>{E!==v&&S(Ll(E))}),[x,v]),v},w=y.version.startsWith("18")?m:b;return{Component:f,useEmitter:(g,x)=>{const v=y.useContext(a)[g];Io(()=>Ve(v,x),[x,v])},useEmitterValue:w,usePublisher:h}}const xc=y.createContext(void 0),vc=y.createContext(void 0),wc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function mi(e){return"self"in e}function Zg(e){return"body"in e}function bc(e,t,n,r=ar,o,s){const i=y.useRef(null),a=y.useRef(null),c=y.useRef(null),u=y.useCallback(h=>{let m,b,w;const g=h.target;if(Zg(g)||mi(g)){const v=mi(g)?g:g.defaultView;w=s?v.scrollX:v.scrollY,m=s?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,b=s?v.innerWidth:v.innerHeight}else w=s?g.scrollLeft:g.scrollTop,m=s?g.scrollWidth:g.scrollHeight,b=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:m,scrollTop:Math.max(w,0),viewportHeight:b})};h.suppressFlushSync?x():Rs.flushSync(x),a.current!==null&&(w===a.current||w<=0||w===m-b)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const m=i.current;if(!m||(s?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const b=h.behavior==="smooth";let w,g,x;mi(m)?(g=Math.max(kn(m.document.documentElement,s?"width":"height"),s?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),w=s?m.innerWidth:m.innerHeight,x=s?window.scrollX:window.scrollY):(g=m[s?"scrollWidth":"scrollHeight"],w=kn(m,s?"width":"height"),x=m[s?"scrollLeft":"scrollTop"]);const v=g-w;if(h.top=Math.ceil(Math.max(Math.min(v,h.top),0)),rc(w,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:w}),b&&t(!0);return}b?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),m.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const gi="-webkit-sticky",yc="sticky",xi=pc(()=>{if(typeof document>"u")return yc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:yc});function vi(e){return e}const Qg=He(()=>{const e=G(a=>`Item ${a}`),t=G(a=>`Group ${a}`),n=G({}),r=G(vi),o=G("div"),s=G(ar),i=(a,c=null)=>kt(F(n,ie(u=>u[a]),rt()),c);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ex=He(([e,t])=>({...e,...t}),nt(mc,Qg)),tx=({height:e})=>l.jsx("div",{style:{height:e}}),nx={overflowAnchor:"none",position:xi(),zIndex:1},Sc={overflowAnchor:"none"},rx={...Sc,display:"inline-block",height:"100%"},Cc=y.memo(function({showTopList:e=!1}){const t=Ce("listState"),n=Ht("sizeRanges"),r=Ce("useWindowScroll"),o=Ce("customScrollParent"),s=Ht("windowScrollContainerState"),i=Ht("scrollContainerState"),a=o||r?s:i,c=Ce("itemContent"),u=Ce("context"),d=Ce("groupContent"),f=Ce("trackItemSizes"),h=Ce("itemSize"),m=Ce("log"),b=Ht("gap"),w=Ce("horizontalDirection"),{callbackRef:g}=vg(n,h,f,e?ar:a,m,b,o,w,Ce("skipAnimationFrameInResizeObserver")),[x,v]=y.useState(0);wi("deviation",M=>{x!==M&&v(M)});const S=Ce("EmptyPlaceholder"),E=Ce("ScrollSeekPlaceholder")||tx,C=Ce("ListComponent"),k=Ce("ItemComponent"),I=Ce("GroupComponent"),N=Ce("computeItemKey"),j=Ce("isSeeking"),O=Ce("groupIndices").length>0,R=Ce("alignToBottom"),$=Ce("initialItemFinalLocationReached"),K=e?{}:{boxSizing:"border-box",...w?{display:"inline-block",height:"100%",marginLeft:x!==0?x:R?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:R?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?l.jsx(S,{...Tt(S,u)}):l.jsx(C,{...Tt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:K,children:(e?t.topItems:t.items).map(M=>{const W=M.originalIndex,U=N(W+t.firstItemIndex,M.data,u);return j?y.createElement(E,{...Tt(E,u),height:M.size,index:M.index,key:U,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(I,{...Tt(I,u),"data-index":W,"data-item-index":M.index,"data-known-size":M.size,key:U,style:nx},d(M.index,u)):y.createElement(k,{...Tt(k,u),...ax(k,M.data),"data-index":W,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:U,style:w?rx:Sc},O?c(M.index,M.groupIndex,M.data,u):c(M.index,M.data,u))})})}),ox={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},sx={outline:"none",overflowX:"auto",position:"relative"},No=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),ix={position:xi(),top:0,width:"100%",zIndex:1};function Tt(e,t){if(typeof e!="string")return{context:t}}function ax(e,t){return{item:typeof e=="string"?void 0:t}}const lx=y.memo(function(){const e=Ce("HeaderComponent"),t=Ht("headerHeight"),n=Ce("HeaderFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,Ce("skipAnimationFrameInResizeObserver")),o=Ce("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null}),cx=y.memo(function(){const e=Ce("FooterComponent"),t=Ht("footerHeight"),n=Ce("HeaderFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,Ce("skipAnimationFrameInResizeObserver")),o=Ce("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null});function kc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:m,scrollToCallback:b}=bc(a,u,c,d,void 0,f);return e("scrollTo",b),e("scrollBy",h),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?sx:ox,...o},tabIndex:0,...i,...Tt(c,s),children:r})})}function Tc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),m=y.useRef(null),b=t("scrollerRef"),{scrollByCallback:w,scrollerRef:g,scrollToCallback:x}=bc(a,u,c,b,h);return wc(()=>{var v;return g.current=h||((v=m.current)==null?void 0:v.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",w),l.jsx(c,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Tt(c,s),children:r})})}const ux=({children:e})=>{const t=y.useContext(xc),n=Ht("viewportHeight"),r=Ht("fixedItemHeight"),o=Ce("alignToBottom"),s=Ce("horizontalDirection"),i=y.useMemo(()=>$l(n,c=>kn(c,s?"width":"height")),[n,s]),a=zn(i,!0,Ce("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:No(o),children:e})},dx=({children:e})=>{const t=y.useContext(xc),n=Ht("windowViewportRect"),r=Ht("fixedItemHeight"),o=Ce("customScrollParent"),s=Ul(n,o,Ce("skipAnimationFrameInResizeObserver")),i=Ce("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:No(i),children:e})},fx=({children:e})=>{const t=Ce("TopItemListComponent")||"div",n=Ce("headerHeight"),r={...ix,marginTop:`${n}px`},o=Ce("context");return l.jsx(t,{style:r,...Tt(t,o),children:e})},hx=y.memo(function(e){const t=Ce("useWindowScroll"),n=Ce("topItemsIndexes").length>0,r=Ce("customScrollParent"),o=Ce("context");return l.jsxs(r||t?gx:mx,{...e,context:o,children:[n&&l.jsx(fx,{children:l.jsx(Cc,{showTopList:!0})}),l.jsxs(r||t?dx:ux,{children:[l.jsx(lx,{}),l.jsx(Cc,{}),l.jsx(cx,{})]})]})}),{Component:px,useEmitter:wi,useEmitterValue:Ce,usePublisher:Ht}=gc(ex,{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"}},hx),mx=kc({useEmitter:wi,useEmitterValue:Ce,usePublisher:Ht}),gx=Tc({useEmitter:wi,useEmitterValue:Ce,usePublisher:Ht}),xx=px;nt(mc,He(()=>{const e=G(u=>l.jsxs("td",{children:["Item $",u]})),t=G(null),n=G(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=G(null),o=G(null),s=G({}),i=G(vi),a=G(ar),c=(u,d=null)=>kt(F(s,ie(f=>f[u]),rt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),xi();const Ec={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},vx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ic,floor:Ao,max:zr,min:bi,round:Nc}=Math;function Ac(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function wx(e){return{...vx,items:e}}function _o(e,t){return e&&e.width===t.width&&e.height===t.height}function bx(e,t){return e&&e.column===t.column&&e.row===t.row}const yx=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,m,{didMount:b,propsReady:w},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:v,windowScrollTo:S,windowViewportRect:E},C])=>{const k=G(0),I=G(0),N=G(Ec),j=G({height:0,width:0}),O=G({height:0,width:0}),R=Le(),$=Le(),K=G(0),M=G(null),W=G({column:0,row:0}),U=Le(),V=Le(),L=G(!1),A=G(0),q=G(!0),J=G(!1),se=G(!1);Ve(F(b,je(A),ve(([_,H])=>!!H)),()=>{Ae(q,!1)}),Ve(F(ht(b,q,O,j,A,J),ve(([_,H,ee,ue,,ce])=>_&&!H&&ee.height!==0&&ue.height!==0&&!ce)),([,,,,_])=>{Ae(J,!0),ui(1,()=>{Ae(R,_)}),Jt(F(u),()=>{Ae(t,[0,0]),Ae(q,!0)})}),de(F(V,ve(_=>_!=null&&_.scrollTop>0),on(0)),I),Ve(F(b,je(V),ve(([,_])=>_!=null)),([,_])=>{_&&(Ae(j,_.viewport),Ae(O,_.item),Ae(W,_.gap),_.scrollTop>0&&(Ae(L,!0),Jt(F(u,Fn(1)),H=>{Ae(L,!1)}),Ae(c,{top:_.scrollTop})))}),de(F(j,ie(({height:_})=>_)),f),de(F(ht(xe(j,_o),xe(O,_o),xe(W,(_,H)=>_&&_.column===H.column&&_.row===H.row),xe(u)),ie(([_,H,ee,ue])=>({gap:ee,item:H,scrollTop:ue,viewport:_}))),U),de(F(ht(xe(k),r,xe(W,bx),xe(O,_o),xe(j,_o),xe(M),xe(I),xe(L),xe(q),xe(A)),ve(([,,,,,,,_])=>!_),ie(([_,[H,ee],ue,ce,Oe,Ge,ke,,be,Ue])=>{const{column:Ye,row:$e}=ue,{height:st,width:pt}=ce,{width:it}=Oe;if(ke===0&&(_===0||it===0))return Ec;if(pt===0){const Qe=di(Ue,_),yt=Qe+Math.max(ke-1,0);return wx(Ac(Qe,yt,Ge))}const dt=_c(it,pt,Ye);let at,Fe;be?H===0&&ee===0&&ke>0?(at=0,Fe=ke-1):(at=dt*Ao((H+$e)/(st+$e)),Fe=dt*Ic((ee+$e)/(st+$e))-1,Fe=bi(_-1,zr(Fe,dt-1)),at=bi(Fe,zr(0,at))):(at=0,Fe=-1);const Y=Ac(at,Fe,Ge),{bottom:re,top:he}=jc(Oe,ue,ce,Y),We=Ic(_/dt),Xe=We*st+(We-1)*$e-re;return{bottom:re,itemHeight:st,items:Y,itemWidth:pt,offsetBottom:Xe,offsetTop:he,top:he}})),N),de(F(M,ve(_=>_!==null),ie(_=>_.length)),k),de(F(ht(j,O,N,W),ve(([_,H,{items:ee}])=>ee.length>0&&H.height!==0&&_.height!==0),ie(([_,H,{items:ee},ue])=>{const{bottom:ce,top:Oe}=jc(_,ue,H,ee);return[Oe,ce]}),rt(Pr)),t);const te=G(!1);de(F(u,je(te),ie(([_,H])=>H||_!==0)),te);const pe=Dt(F(ht(N,k),ve(([{items:_}])=>_.length>0),je(te),ve(([[_,H],ee])=>{const ue=_.items[_.items.length-1].index===H-1;return(ee||_.bottom>0&&_.itemHeight>0&&_.offsetBottom===0&&_.items.length===H)&&ue}),ie(([[,_]])=>_-1),rt())),Ie=Dt(F(xe(N),ve(({items:_})=>_.length>0&&_[0].index===0),on(0),rt())),Ne=Dt(F(xe(N),je(L),ve(([{items:_},H])=>_.length>0&&!H),ie(([{items:_}])=>({endIndex:_[_.length-1].index,startIndex:_[0].index})),rt(Xl),xn(0)));de(Ne,m.scrollSeekRangeChanged),de(F(R,je(j,O,k,W),ie(([_,H,ee,ue,ce])=>{const Oe=nc(_),{align:Ge,behavior:ke,offset:be}=Oe;let Ue=Oe.index;Ue==="LAST"&&(Ue=ue-1),Ue=zr(0,Ue,bi(ue-1,Ue));let Ye=yi(H,ce,ee,Ue);return Ge==="end"?Ye=Nc(Ye-H.height+ee.height):Ge==="center"&&(Ye=Nc(Ye-H.height/2+ee.height/2)),be&&(Ye+=be),{behavior:ke,top:Ye}})),c);const B=kt(F(N,ie(_=>_.offsetBottom+_.bottom)),0);return de(F(E,ie(_=>({height:_.visibleHeight,width:_.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:K,footerHeight:o,gap:W,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:O,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:c,scrollToIndex:R,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:v,windowScrollTo:S,windowViewportRect:E,...m,gridState:N,horizontalDirection:se,initialTopMostItemIndex:A,totalListHeight:B,...h,endReached:pe,propsReady:w,rangeChanged:Ne,startReached:Ie,stateChanged:U,stateRestoreInProgress:L,...C}},nt(fi,It,Fr,hc,Tn,pi,Cn));function _c(e,t,n){return zr(1,Ao((e+n)/(Ao(t)+n)))}function jc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=yi(e,t,n,r[0].index);return{bottom:yi(e,t,n,r[r.length-1].index)+o,top:s}}function yi(e,t,n,r){const o=_c(e.width,n.width,t.column),s=Ao(r/o),i=s*n.height+zr(0,s-1)*t.row;return i>0?i+t.row:i}const Sx=He(()=>{const e=G(f=>`Item ${f}`),t=G({}),n=G(null),r=G("virtuoso-grid-item"),o=G("virtuoso-grid-list"),s=G(vi),i=G("div"),a=G(ar),c=(f,h=null)=>kt(F(t,ie(m=>m[f]),rt()),h),u=G(!1),d=G(!1);return de(xe(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Cx=He(([e,t])=>({...e,...t}),nt(yx,Sx)),kx=y.memo(function(){const e=ot("gridState"),t=ot("listClassName"),n=ot("itemClassName"),r=ot("itemContent"),o=ot("computeItemKey"),s=ot("isSeeking"),i=Ut("scrollHeight"),a=ot("ItemComponent"),c=ot("ListComponent"),u=ot("ScrollSeekPlaceholder"),d=ot("context"),f=Ut("itemDimensions"),h=Ut("gap"),m=ot("log"),b=ot("stateRestoreInProgress"),w=Ut("reportReadyState"),g=zn(y.useMemo(()=>x=>{const v=x.parentElement.parentElement.scrollHeight;i(v);const S=x.firstChild;if(S){const{height:E,width:C}=S.getBoundingClientRect();f({height:E,width:C})}h({column:Pc("column-gap",getComputedStyle(x).columnGap,m),row:Pc("row-gap",getComputedStyle(x).rowGap,m)})},[i,f,h,m]),!0,!1);return wc(()=>{e.itemHeight>0&&e.itemWidth>0&&w(!0)},[e]),b?null:l.jsx(c,{className:t,ref:g,...Tt(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const v=o(x.index,x.data,d);return s?l.jsx(u,{...Tt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},v):y.createElement(a,{...Tt(a,d),className:n,"data-index":x.index,key:v},r(x.index,x.data,d))})})}),Tx=y.memo(function(){const e=ot("HeaderComponent"),t=Ut("headerHeight"),n=ot("headerFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,!1),o=ot("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null}),Ex=y.memo(function(){const e=ot("FooterComponent"),t=Ut("footerHeight"),n=ot("headerFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,!1),o=ot("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null}),Ix=({children:e})=>{const t=y.useContext(vc),n=Ut("itemDimensions"),r=Ut("viewportDimensions"),o=zn(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:No(!1),children:e})},Nx=({children:e})=>{const t=y.useContext(vc),n=Ut("windowViewportRect"),r=Ut("itemDimensions"),o=ot("customScrollParent"),s=Ul(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:No(!1),children:e})},Ax=y.memo(function({...e}){const t=ot("useWindowScroll"),n=ot("customScrollParent"),r=n||t?jx:_x,o=n||t?Nx:Ix,s=ot("context");return l.jsx(r,{...e,...Tt(r,s),children:l.jsxs(o,{children:[l.jsx(Tx,{}),l.jsx(kx,{}),l.jsx(Ex,{})]})})}),{useEmitter:Rc,useEmitterValue:ot,usePublisher:Ut}=gc(Cx,{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"}},Ax),_x=kc({useEmitter:Rc,useEmitterValue:ot,usePublisher:Ut}),jx=Tc({useEmitter:Rc,useEmitterValue:ot,usePublisher:Ut});function Pc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Rt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Rx=ro.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 Si({className:e,variant:t,...n}){return l.jsx("div",{className:Q(Rx({variant:t}),e),...n})}function le(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Px(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,c=p.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=p.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function ln(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:m,...b}=f,w=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,g=p.useMemo(()=>b,Object.values(b));return l.jsx(w.Provider,{value:g,children:m})};u.displayName=s+"Provider";function d(f,h){var w;const m=((w=h==null?void 0:h[e])==null?void 0:w[c])||a,b=p.useContext(m);if(b)return b;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>p.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,Ox(o,...t)]}function Ox(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var bt=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},Mx=p[" useInsertionEffect ".trim().toString()]||bt;function Un({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Dx({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=p.useRef(e!==void 0);p.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"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=a},[a,r])}const u=p.useCallback(d=>{var f;if(a){const h=Lx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[c,u]}function Dx({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Mx(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Lx(e){return typeof e=="function"}function Oc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ci(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Oc(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():Oc(e[o],null)}}}}function Me(...e){return p.useCallback(Ci(...e),e)}var $x=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],we=$x.reduce((e,t)=>{const n=Mn.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Mc(e,t){e&&oo.flushSync(()=>e.dispatchEvent(t))}function Fx(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var $t=e=>{const{present:t,children:n}=e,r=zx(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Me(r.ref,Bx(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};$t.displayName="Presence";function zx(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=Fx(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=jo(r.current);s.current=a==="mounted"?u:"none"},[a]),bt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,m=jo(u);e?c("MOUNT"):m==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==m?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),bt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=m=>{const w=jo(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&w&&(c("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=m=>{m.target===t&&(s.current=jo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function jo(e){return(e==null?void 0:e.animationName)||"none"}function Bx(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Hx=p[" useId ".trim().toString()]||(()=>{}),Ux=0;function cn(e){const[t,n]=p.useState(Hx());return bt(()=>{n(r=>r??String(Ux++))},[e]),e||(t?`radix-${t}`:"")}var Ro="Collapsible",[Wx,jC]=ln(Ro),[Vx,ki]=Wx(Ro),Dc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Un({prop:r,defaultProp:o??!1,onChange:i,caller:Ro});return l.jsx(Vx,{scope:n,disabled:s,contentId:cn(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(we.div,{"data-state":Ei(c),"data-disabled":s?"":void 0,...a,ref:t})})});Dc.displayName=Ro;var Lc="CollapsibleTrigger",$c=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ki(Lc,n);return l.jsx(we.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ei(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:le(e.onClick,o.onOpenToggle)})});$c.displayName=Lc;var Ti="CollapsibleContent",qx=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ki(Ti,e.__scopeCollapsible);return l.jsx($t,{present:n||o.open,children:({present:s})=>l.jsx(Kx,{...r,ref:t,present:s})})});qx.displayName=Ti;var Kx=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ki(Ti,n),[a,c]=p.useState(r),u=p.useRef(null),d=Me(t,u),f=p.useRef(0),h=f.current,m=p.useRef(0),b=m.current,w=i.open||a,g=p.useRef(w),x=p.useRef(void 0);return p.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),bt(()=>{const v=u.current;if(v){x.current=x.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const S=v.getBoundingClientRect();f.current=S.height,m.current=S.width,g.current||(v.style.transitionDuration=x.current.transitionDuration,v.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(we.div,{"data-state":Ei(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!w,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...e.style},children:w&&o})});function Ei(e){return e?"open":"closed"}var Gx=Dc;const Fc=Gx,zc=$c,Br=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Br.displayName="Card";const Hr=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("flex flex-col space-y-1.5 p-6",e),...t}));Hr.displayName="CardHeader";const Ur=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:Q("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ur.displayName="CardTitle";const Bc=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));Bc.displayName="CardDescription";const Po=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("p-6 pt-0",e),...t}));Po.displayName="CardContent";const Hc=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("flex items-center p-6 pt-0",e),...t}));Hc.displayName="CardFooter";function Uc(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Wn=Uc();function Yx(e){Wn=e}const Wc=/[&<>"']/,Xx=new RegExp(Wc.source,"g"),Vc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Jx=new RegExp(Vc.source,"g"),Zx={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},qc=e=>Zx[e];function Et(e,t){if(t){if(Wc.test(e))return e.replace(Xx,qc)}else if(Vc.test(e))return e.replace(Jx,qc);return e}const Qx=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Kc(e){return e.replace(Qx,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const ev=/(^|[^\[])\^/g;function Ze(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(ev,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const tv=/[^\w:]/g,nv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Gc(e,t,n){if(e){let r;try{r=decodeURIComponent(Kc(n)).replace(tv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!nv.test(n)&&(n=iv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Oo={},rv=/^[^:]+:\/*[^/]*$/,ov=/^([^:]+:)[\s\S]*$/,sv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function iv(e,t){Oo[" "+e]||(rv.test(e)?Oo[" "+e]=e+"/":Oo[" "+e]=Do(e,"/",!0)),e=Oo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(ov,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(sv,"$1")+t:e+t}const Mo={exec:function(){}};function Yc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Do(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function av(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function lv(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function Xc(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Jc(e,t,n,r){const o=t.href,s=t.title?Et(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:Et(i)}}function cv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
38
+ `)}function Um(e){return e.type!=="thread_info"&&e.type!=="token"}const Wm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Vm(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ys(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ys(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ys(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Pl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pl(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Rl(e=[]){const[t,n]=y.useReducer(Vm,{...Wm,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),c=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:c}),[c]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n;if(t.type==="message_start"&&t.role==="assistant"){const r=t.id,o=Xm(t.model);if(e.messages.some(a=>a.id===r))return{...e,assemblingId:r};const i={id:r,role:"assistant",name:o||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:r,messages:[...e.messages,i]}}if(t.type==="message_delta"){const r=e.assemblingId??Xs(e.messages);return r?{...e,messages:Js(e.messages,r,t.delta)}:e}if(t.type==="message_end"){const r=e.assemblingId??Xs(e.messages);if(!r)return{...e,assemblingId:null};const o=e.messages,s=o.findIndex(i=>i.id===r&&i.role==="assistant");if(s>=0&&!((n=o[s].content)==null?void 0:n.some(c=>{var u;return(c==null?void 0:c.type)==="text"&&((u=c.text)==null?void 0:u.trim())}))){const c=[...o.slice(0,s),...o.slice(s+1)];return{...e,assemblingId:null,messages:c}}return e}if(t.type==="tool_start"){const r=t.id??t.call_id,o=t.name??t.tool;if(!r)return e;const s=`tool-${r}`,i={type:"tool_call",id:r,name:o,args:t.args};if(e.messages.find(u=>u.id===s))return{...e,toolIndex:{...e.toolIndex,[r]:s}};const c={id:s,role:"tool",name:o,createdAt:new Date().toISOString(),content:[i]};return{...e,messages:[...e.messages,c],toolIndex:{...e.toolIndex,[r]:s}}}if(t.type==="tool_result"){const r=t.id??t.call_id;if(!r)return e;const o=e.toolIndex[r]??`tool-${r}`,s={type:"tool_result",toolCallId:r,output:t.output,error:t.error},i=e.messages.find(u=>u.id===o),a={id:o,role:"tool",content:[s],createdAt:new Date().toISOString()},c=i?Js(e.messages,o,[s]):[...e.messages,a];return{...e,messages:c}}if(t.type==="checkpoint"){const r=t.checkpointNs??e.lastCheckpointNs??null,o=Ym(e.messages,t.checkpointId,r);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:r,messages:o}}if(t.type==="branch"){const r=t.checkpointId??e.lastCheckpointId,o=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:r??null,lastCheckpointNs:o??null}}if(t.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,r]}}if(t.type==="interrupt"){const r=e.assemblingId??Xs(e.messages),o={type:"interrupt",value:t.value};if(r)return{...e,assemblingId:null,messages:Js(e.messages,r,[o]),pendingInterrupt:{id:t.id,value:t.value}};const s={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ys(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function qm(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Km(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Js(e,t,n){return Km(e,t,r=>({...r,content:Gm(r.content,n)}))}function Gm(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Ym(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return qm(e,r,s)}return e}function Xm(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Jm(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function Zm(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Qm(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await Zm(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const eg={MODE:"library"};function tg(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ps&&Ps.tagName.toUpperCase()==="SCRIPT"&&Ps.src||new URL("index.umd.js",document.baseURI).href}<"u"?eg:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function Zs(){return!tg()}function ng({currentThreadId:e,messageCount:t,setCurrentThreadId:n,markThreadRefreshPending:r,skipNextLoadRef:o}){return y.useCallback(s=>{const i=s.threadId,a=!!s.created,c=!!s.ready;if(e!==i){const u=!e&&t<=1;u&&(o.current=i),n(i),(c||a||u)&&r();return}(c||a)&&r()},[e,r,t,n,o])}function rg(e){const t=e.seq;return typeof t=="number"&&Number.isFinite(t)?t:null}function og({onThreadInfo:e,onMessageEvent:t,onUnhandledEvent:n,onSequenceGap:r}){const o=y.useRef(null),s=y.useCallback(a=>{const c=rg(a);if(c!==null){const u=o.current;if(u!==null){if(c<=u){Zs()&&console.debug("[StreamEventCoordinator] drop out-of-order seq",{prev:u,seq:c,type:a.type});return}c>u+1&&(r==null||r({from:u,to:c}))}o.current=c}if(a.type==="thread_info"){e==null||e(a);return}if(Um(a)){t(a);return}n==null||n(a)},[t,r,e,n]),i=y.useCallback(()=>{o.current=null},[]);return{handleEvent:s,reset:i}}const Ol=y.createContext(null);function xo({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null,autoLoadInitial:s=!0,disableAutoRestore:i=!1,enableFileAgentRouting:a=!1,fileAgentId:c="invoice_reader"}){const u=yn;y.useEffect(()=>{t&&u.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[u,t]);const{isStreaming:d,error:f,stream:h,stop:m,setToken:b}=jl({baseUrl:u.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/runs/stream"}),[w,g]=y.useState(()=>typeof u.getAuthToken=="function"?u.getAuthToken():null);y.useEffect(()=>{b(typeof u.getAuthToken=="function"?u.getAuthToken():null);const D=u.onTokenChange(Z=>{g(Z),b(Z)});return()=>{D()}},[u,b]);const x=y.useCallback(D=>{u.setAuthToken(D)},[u]),{state:v,dispatch:S,seed:E,prepend:C,pushUser:k,onEvent:I,reset:N}=Rl(),j=20,[O,R]=y.useState(!1),[$,K]=y.useState(!1),[M,W]=y.useState(null),[U,V]=y.useState(void 0),[L,A]=y.useState(void 0),q=y.useRef(!1),J=y.useRef([]),se=y.useRef(null),te=y.useCallback(D=>{D.cursor!==void 0&&W(D.cursor),D.hasMore!==void 0&&R(D.hasMore),D.checkpointId!==void 0&&V(D.checkpointId),D.checkpointNs!==void 0&&A(D.checkpointNs)},[]),pe=y.useCallback((D,Z)=>new Promise((Re,Ke)=>{const vt=async()=>{if(q.current){console.warn(`[ChatProvider] Operation "${Z}" queued - another operation in progress`),J.current.push(vt);return}q.current=!0;try{console.log(`[ChatProvider] Executing operation: ${Z}`),await D(),Re()}catch(X){console.error(`[ChatProvider] Operation "${Z}" failed:`,X),Ke(X)}finally{q.current=!1;const X=J.current.shift();X&&X().catch(()=>{})}};q.current?(J.current.push(vt),console.log(`[ChatProvider] Queued operation: ${Z}`)):vt().catch(X=>{Ke(X)})}),[]),Ie=y.useCallback((D,Z)=>{const Re=Array.isArray(D==null?void 0:D.messages)?D.messages:[];Z==="replace"?(console.log("[ChatProvider] Replacing messages, count:",Re.length),E(Re,{checkpointId:(D==null?void 0:D.checkpointId)??null,checkpointNs:(D==null?void 0:D.checkpointNs)??null})):Z==="prepend"&&Re.length?(console.log("[ChatProvider] Calling prepend with",Re.length,"messages"),C(Re)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),W((D==null?void 0:D.nextCursor)??null),R(!!(D!=null&&D.hasMore)),V(Ke=>(D==null?void 0:D.checkpointId)??Ke??void 0),A(Ke=>(D==null?void 0:D.checkpointNs)??Ke??void 0)},[E,C]),[Ne,B]=y.useState([]),[_,H]=y.useState(null),[ee,ue]=y.useState(!1),[ce,Oe]=y.useState(!1),Ge=y.useRef(!1),ke=y.useCallback(()=>{Ge.current=!0},[]),be=y.useCallback(async()=>{ue(!0);try{const D=await u.listThreads();B(D)}finally{ue(!1)}},[u]),Ue=ng({currentThreadId:_,messageCount:v.messages.length,setCurrentThreadId:H,markThreadRefreshPending:ke,skipNextLoadRef:se}),[Ye,$e]=y.useState(!1),st=y.useCallback(async D=>{const Z=(D==null?void 0:D.maxAttempts)??5,Re=(D==null?void 0:D.baseDelayMs)??500,Ke=(D==null?void 0:D.timeoutMs)??2e3;if(!u.baseUrl)return!1;const vt=u.baseUrl.replace(/\/+$/,""),X=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],fe=async Pe=>{try{const ye=new AbortController,et=setTimeout(()=>ye.abort(),Ke),wt=await fetch(Pe,{method:"GET",signal:ye.signal});return clearTimeout(et),wt.ok}catch{return!1}},_e=async Pe=>{try{const ye=new AbortController,et=setTimeout(()=>ye.abort(),Ke),wt=await fetch(Pe,{method:"HEAD",signal:ye.signal});return clearTimeout(et),wt.ok}catch{return!1}};for(let Pe=0;Pe<Z;Pe++){console.debug(`[ChatProvider] health-check attempt ${Pe+1}/${Z}`);for(const et of X){let wt=et;vt.endsWith("/api")&&et.startsWith("/api")&&(wt=et.replace(/^\/api/,"")||"/");const bn=wt==="/"?vt+"/":vt+wt;if(console.debug(`[ChatProvider] checking ${bn}`),await fe(bn)||et==="/"&&await _e(vt+"/"))return $e(!0),!0}const ye=Re*Math.pow(2,Pe);await new Promise(et=>setTimeout(et,ye))}return $e(!1),!1},[u.baseUrl]);y.useEffect(()=>{let D=!0;if(!u.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const Z=await st();if(!D)return;Z?be().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{D=!1}},[be,u.baseUrl,st]),y.useEffect(()=>{r==null||r(_)},[_,r]);const pt=y.useRef(null);y.useEffect(()=>{if(o&&s){if(!u.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!Ye){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}pt.current!==o&&(pt.current=o,Y(o).catch(()=>{}))}},[o,s,u.baseUrl,Ye]);const it=y.useRef(null),dt=y.useRef(null),at=y.useRef(null),Fe=y.useRef({count:0,checkpointId:null,checkpointNs:null});y.useEffect(()=>{at.current=_},[_]),y.useEffect(()=>{Fe.current={count:v.messages.length,checkpointId:v.lastCheckpointId,checkpointNs:v.lastCheckpointNs}},[v.messages.length,v.lastCheckpointId,v.lastCheckpointNs]);const Y=y.useCallback(async(D,Z,Re,Ke=!1)=>{await pe(async()=>{if(se.current===D){console.log(`[ChatProvider] Skipping auto-load for thread ${D} - suppressed after clear`),se.current=null;return}if(!u.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(it.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${it.current}) is loading`);return}const vt=dt.current!==null&&dt.current!==D,X=dt.current===D||at.current===D,fe=Z!==void 0||Re!==void 0,_e=Fe.current.count>0,Pe=Fe.current.checkpointId!==null||Fe.current.checkpointNs!==null;if(!Ke&&!vt&&X&&!fe&&!Pe&&_e){console.debug("[ChatProvider] Fast-return loadThread - reusing existing messages for thread",D),H(D),dt.current=D;return}vt&&(console.log(`[ChatProvider] Thread switch detected: ${dt.current} -> ${D}`),N([])),it.current=D,dt.current=D;try{Oe(!0),te({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),H(D);const ye=await u.getMessages({threadId:D,checkpointId:Z,checkpointNs:Re,limit:j}),et=Array.isArray(ye==null?void 0:ye.messages)?ye.messages:[];console.log("[ChatProvider] Loading thread with",et.length,"messages"),E(et,{checkpointId:(ye==null?void 0:ye.checkpointId)??null,checkpointNs:(ye==null?void 0:ye.checkpointNs)??null}),W((ye==null?void 0:ye.nextCursor)??null),R(!!(ye!=null&&ye.hasMore)),V(wt=>(ye==null?void 0:ye.checkpointId)??wt??void 0),A(wt=>(ye==null?void 0:ye.checkpointNs)??wt??void 0)}finally{it.current=null,Oe(!1)}},`loadThread-${D}`)},[u,pe,te,E]),re=y.useCallback(({from:D,to:Z})=>{const Re=at.current;Re&&(Zs()&&console.warn(`[ChatProvider] Stream sequence gap detected (${D} -> ${Z}) for thread ${Re}`),Y(Re,void 0,void 0,!0).catch(()=>{}))},[Y]),{handleEvent:he,reset:We}=og({onThreadInfo:Ue,onMessageEvent:I,onUnhandledEvent:D=>{Zs()&&console.warn(`[ChatProvider] Unhandled stream event type: ${D.type}`,D)},onSequenceGap:re}),Xe=y.useCallback(async D=>{const Z=await u.listCheckpoints(D);return Jm(Z,D)},[u]),Qe=y.useCallback(async(D,Z)=>{await pe(async()=>{if(!_)throw new Error("No active thread");te({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),Oe(!0);try{const Re=await u.getMessages({threadId:_,checkpointId:D,checkpointNs:Z??void 0,limit:j});Ie(Re,"replace")}finally{Oe(!1)}},`navigateToCheckpoint-${D}`)},[u,_,Ie,pe,te,j]),yt=y.useCallback(async()=>{if(!_)throw new Error("No active thread");await Y(_,void 0,void 0,!0)},[_,Y]),lt=y.useRef(!1);y.useEffect(()=>{const D=lt.current;lt.current=d,D&&!d&&_&&Ge.current&&pe(async()=>{try{await be()}catch(Z){console.warn("[ChatProvider] Post-streaming thread refresh failed:",Z)}finally{Ge.current=!1}},"postStreamingRefresh")},[d,_,be,pe]);const mt=y.useCallback(async()=>{console.log("[ChatProvider] 🔄 clearCurrentThread called"),console.log("[ChatProvider] 📊 Before clear - currentThreadId:",_),console.log("[ChatProvider] 📊 Before clear - messages count:",v.messages.length),_&&(se.current=_,console.log(`[ChatProvider] 🚫 Suppressing next auto-load for thread: ${_}`)),await pe(()=>(console.log("[ChatProvider] 🚀 Executing atomic clear operation"),H(null),N([]),te({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),typeof window<"u"&&localStorage.removeItem("currentThreadId"),console.log("[ChatProvider] ✅ Atomic clear operation completed"),Promise.resolve()),"clearCurrentThread"),console.log("[ChatProvider] 📊 After clear - currentThreadId should be null")},[N,te,_,v.messages.length,pe]),Kt=y.useCallback(async D=>{mt();let Z=null;try{return Z=await u.createThread(D),B(Re=>[...Re.filter(vt=>vt.threadId!==Z.threadId),Z]),await Y(Z.threadId),Z.threadId}catch(Re){if(await be(),Z!=null&&Z.threadId)try{return await Y(Z.threadId),Z.threadId}catch(Ke){console.error("[ChatProvider] Failed to load thread after refresh",Ke)}throw Re}},[u,be,Y,mt]),On=y.useCallback(async D=>{try{await u.deleteThread(D),B(Z=>Z.filter(Re=>Re.threadId!==D)),_===D&&(H(null),N([]),R(!1),W(null),V(void 0),A(void 0))}catch(Z){throw await be(),Z}},[u,be,_,N]),no=y.useCallback(async(D,Z)=>{try{await u.updateThread(D,Z),B(Re=>Re.map(Ke=>Ke.threadId===D?{...Ke,title:Z}:Ke))}catch(Re){throw await be(),Re}},[u,be]),er=y.useCallback(async(D,Z)=>{var Gt;const Re=(Z==null?void 0:Z.attachments)||[],{contentParts:Ke,filesInfo:vt}=await Qm(u,Re,t==null?void 0:t.uploadPath),X=[];D&&D.trim()&&X.push({type:"text",text:D.trim()});const fe={id:((Gt=crypto.randomUUID)==null?void 0:Gt.call(crypto))||`user-${Date.now()}`,role:"user",content:X,createdAt:new Date().toISOString(),checkpointId:(Z==null?void 0:Z.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(Z==null?void 0:Z.checkpointNs)??v.lastCheckpointNs??void 0};k(fe);const _e={...fe,content:X},Pe={...(Z==null?void 0:Z.payloadExtras)??{}},ye=!!Pe.edit,et=Pe.originalMessageId,wt=typeof et=="string"?et:void 0,bn=Re&&Re.length>0,yr={..._?{threadId:_}:{},payload:{messages:[_e],files_info:vt,...a&&bn&&c?{active_agent:c}:{},...Pe},checkpointId:(Z==null?void 0:Z.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(Z==null?void 0:Z.checkpointNs)??v.lastCheckpointNs??void 0,nodeFilter:Z==null?void 0:Z.nodeFilter,config:Z==null?void 0:Z.config,edit:ye,originalMessageId:wt};We(),ke(),h(yr,T=>{he(T)},{onError:T=>console.warn("stream error",T),onOpen:({threadId:T,created:z})=>{if(!_&&T){const ne=v.messages.length<=1;ne&&(se.current=T),H(T),(z||ne)&&ke()}},onGap:re})},[_,k,h,he,We,re,v.lastCheckpointId,v.lastCheckpointNs,u,t==null?void 0:t.uploadPath,ke,H,a,c,v.messages.length]),br=y.useCallback(async D=>{if(!_)throw new Error("No active thread");if($||!O)return;const Z=M;if(Z){K(!0);try{const Re=await u.getMessages({threadId:_,checkpointId:U,checkpointNs:L,limit:(D==null?void 0:D.limit)??j,beforeId:Z});Ie(Re,"prepend")}finally{K(!1)}}},[u,_,U,L,M,O,$,Ie,j]),gn=y.useCallback(async(D,Z,Re)=>{if(!_)throw new Error("No active thread to handle interrupt");try{console.log(`[ChatProvider] Handling interrupt ${D}: ${Z?"approved":"rejected"}`);const Ke=!!Z;await u.resume({threadId:_,value:Ke}),console.log(`[ChatProvider] Interrupt ${D} handled successfully`),S({type:"interrupt_response",payload:{interruptId:D}})}catch(Ke){throw console.error(`[ChatProvider] Failed to handle interrupt ${D}:`,Ke),Ke}},[u,_]),tr={baseUrl:u.baseUrl,token:w,setToken:x,api:u,threads:Ne,currentThreadId:_,setCurrentThreadId:H,isLoadingThreads:ee,isLoadingThread:ce,messages:v.messages,isStreaming:d,error:f,lastCheckpointId:v.lastCheckpointId,lastCheckpointNs:v.lastCheckpointNs,streamingAssistantId:v.assemblingId,hasMoreHistory:O,isLoadingHistory:$,loadOlderMessages:br,historyPageSize:j,listCheckpoints:Xe,navigateToCheckpoint:Qe,returnToLatest:yt,refreshThreads:be,createThread:Kt,deleteThread:On,renameThread:no,loadThread:Y,clearCurrentThread:mt,send:er,stop:m,handleInterrupt:gn};return l.jsx(Ol.Provider,{value:tr,children:e})}function _r(){const e=y.useContext(Ol);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function Q(...e){return gp.twMerge(mp.clsx(e))}const sg=ro.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"}}),Be=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Mn.Slot:"button";return l.jsx(i,{className:Q(sg({variant:t,size:n,className:e})),ref:s,...o})});Be.displayName="Button";const Ml=p.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:Q("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",e),ref:n,...t}));Ml.displayName="Textarea";function ig({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,m]=y.useState(e),[b,w]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const N=g.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);y.useEffect(()=>{x()},[x]);const v=y.useCallback(async N=>{N&&N.preventDefault();const j=(h??"").trim();!j&&!f||w(()=>{try{const O=i(j);O&&typeof O.then=="function"?O.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=y.useCallback(N=>{m(N.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=y.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),v()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[v,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"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 l.jsx("form",{onSubmit:N=>void v(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Ml,{ref:g,value:h,onChange:S,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(Be,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(oe.Square,{size:16})}):l.jsx(Be,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||b,children:l.jsx(oe.Send,{size:16})})})]})})}const ag=y.memo(ig),vo=0,Sn=1,ir=2,Dl=4;function Ll(e){return()=>e}function lg(e){e()}function $l(e,t){return n=>e(t(n))}function Fl(e,t){return()=>e(t)}function cg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function ug(...e){return()=>{e.map(lg)}}function ar(){}function wo(e,t){return t(e),e}function dg(e,t){return t(e)}function nt(...e){return e}function Ve(e,t){return e(Sn,t)}function Ae(e,t){e(vo,t)}function ei(e){e(ir)}function ut(e){return e(Dl)}function de(e,t){return Ve(e,cg(t,vo))}function Jt(e,t){const n=e(Sn,r=>{n(),t(r)});return n}function zl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Bl(e,t){return e===t}function rt(e=Bl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ve(e){return t=>n=>{e(n)&&t(n)}}function ie(e){return t=>$l(t,e)}function on(e){return t=>()=>{t(e)}}function F(e,...t){const n=fg(...t);return(r,o)=>{switch(r){case ir:ei(e);return;case Sn:return Ve(e,n(o))}}}function sn(e,t){return n=>r=>{n(t=e(t,r))}}function Fn(e){return t=>n=>{e>0?e--:t(n)}}function xn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function je(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ve(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function fg(...e){return t=>e.reduceRight(dg,t)}function hg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Sn:return s?n===s?void 0:(r(),n=s,t=Ve(e,s),t):(r(),ar);case ir:r(),n=null;return}}}function G(e){let t=e;const n=Le();return(r,o)=>{switch(r){case vo:t=o;break;case Sn:{o(t);break}case Dl:return t}return n(r,o)}}function kt(e,t){return wo(G(t),n=>de(e,n))}function Le(){const e=[];return(t,n)=>{switch(t){case vo:e.slice().forEach(r=>{r(n)});return;case ir:e.splice(0,e.length);return;case Sn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Dt(e){return wo(Le(),t=>de(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:pg(),singleton:n}}const pg=()=>Symbol();function mg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function ht(...e){const t=Le(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ve(s,c=>{n[i]=c,r=r|a,r===o&&Ae(t,n)})}),function(s,i){switch(s){case ir:{ei(t);return}case Sn:return r===o&&i(n),Ve(t,i)}}}function xe(e,t=Bl){return F(e,rt(t))}function ti(...e){return function(t,n){switch(t){case ir:return;case Sn:return ug(...e.map(r=>Ve(r,n)))}}}var Rt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Rt||{});const gg={0:"debug",3:"error",1:"log",2:"warn"},xg=()=>typeof globalThis>"u"?window:globalThis,Cn=He(()=>{const e=G(3);return{log:G((t,n,r=1)=>{var o;const s=(o=xg().VIRTUOSO_LOG_LEVEL)!=null?o:ut(e);r>=s&&console[gg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function zn(e,t,n){return ni(e,t,n).callbackRef}function ni(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function vg(e,t,n,r,o,s,i,a,c){const u=y.useCallback(d=>{const f=wg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const m=h.lastElementChild.dataset.viewportType==="window";let b;m&&(b=h.ownerDocument.defaultView);const w=i?a?i.scrollLeft:i.scrollTop:m?a?b.scrollX||b.document.documentElement.scrollLeft:b.scrollY||b.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:m?a?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:m?a?b.innerWidth:b.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(w,0),viewportHeight:x}),s==null||s(a?Hl("column-gap",getComputedStyle(d).columnGap,o):Hl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,c)}function wg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Rt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Hl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Rt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ul(e,t,n){const r=y.useRef(null),o=y.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,h;if(t){const m=t.getBoundingClientRect(),b=u.top-m.top;h=m.height-Math.max(0,b),f=b+t.scrollTop}else{const m=i.current.ownerDocument.defaultView;h=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const It=He(()=>{const e=Le(),t=Le(),n=G(0),r=Le(),o=G(0),s=Le(),i=Le(),a=G(0),c=G(0),u=G(0),d=G(0),f=Le(),h=Le(),m=G(!1),b=G(!1),w=G(!1);return de(F(e,ie(({scrollTop:g})=>g)),t),de(F(e,ie(({scrollHeight:g})=>g)),i),de(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:b,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:w,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),jr={lvl:0};function Wl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Je(e){return e===jr}function Rr(e,t){if(!Je(e))return t===e.k?e.v:t<e.k?Rr(e.l,t):Rr(e.r,t)}function Zt(e,t,n="k"){if(Je(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Zt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Zt(e.l,t,n)}function Lt(e,t,n){return Je(e)?Kl(t,n,1):t===e.k?xt(e,{k:t,v:n}):t<e.k?Gl(xt(e,{l:Lt(e.l,t,n)})):Gl(xt(e,{r:Lt(e.r,t,n)}))}function lr(){return jr}function bo(e,t,n){if(Je(e))return[];const r=Zt(e,t)[0];return bg(oi(e,r,n))}function ri(e,t){if(Je(e))return jr;const{k:n,l:r,r:o}=e;if(t===n){if(Je(r))return o;if(Je(o))return r;{const[s,i]=ql(r);return yo(xt(e,{k:s,l:Vl(r),v:i}))}}else return t<n?yo(xt(e,{l:ri(r,t)})):yo(xt(e,{r:ri(o,t)}))}function Bn(e){return Je(e)?[]:[...Bn(e.l),{k:e.k,v:e.v},...Bn(e.r)]}function oi(e,t,n){if(Je(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oi(s,t,n))),a}function yo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(si(t))return Yl(xt(e,{lvl:n-1}));if(!Je(t)&&!Je(t.r))return xt(t.r,{l:xt(t,{r:t.r.l}),lvl:n,r:xt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(xt(e,{lvl:n-1}));if(!Je(r)&&!Je(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return xt(o,{l:xt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(xt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function xt(e,t){return Kl(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Vl(e){return Je(e.r)?e.l:yo(xt(e,{r:Vl(e.r)}))}function si(e){return Je(e)||e.lvl>e.r.lvl}function ql(e){return Je(e.r)?[e.k,e.v]:ql(e.r)}function Kl(e,t,n,r=jr,o=jr){return{k:e,l:r,lvl:n,r:o,v:t}}function Gl(e){return ii(Yl(e))}function Yl(e){const{l:t}=e;return!Je(t)&&t.lvl===e.lvl?xt(t,{r:xt(e,{l:t.r})}):e}function ii(e){const{lvl:t,r:n}=e;return!Je(n)&&!Je(n.r)&&n.lvl===t&&n.r.lvl===t?xt(n,{l:xt(e,{r:n.l}),lvl:t+1}):e}function bg(e){return Wl(e,({k:t,v:n})=>({index:t,value:n}))}function Xl(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Pr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=He(()=>({recalcInProgress:G(!1)}),[],{singleton:!0});function Jl(e,t,n){return e[So(e,t,n)]}function So(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function yg(e,t,n,r){const o=So(e,t,r),s=So(e,n,r,o);return e.slice(o,s+1)}function kn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Co(e){return!Je(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function Sg(){return{groupIndices:[],groupOffsetTree:lr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:lr()}}function Cg(e,t){let n=Je(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Je(e)){e=Lt(e,0,s);continue}const a=bo(e,i-1,o+1);if(a.some(_g(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=Lt(e,o+1,h));u&&(e=Lt(e,i,s))}return[e,n]}function kg(e){return typeof e.groupIndex<"u"}function Tg({offset:e},t){return t===e?0:t<e?-1:1}function Or(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Jl(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Zl(e,t){if(!Co(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ql(e,t,n){if(kg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Zl(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Eg(e,t,n,r=0){return r>0&&(t=Math.max(t,Jl(e,r,li).offset)),Wl(yg(e,t,n,Tg),Ag)}function Ig(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Rt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Je(s)&&t.length===2){const h=t[0].size,m=t[1].size;i=n.reduce((b,w)=>Lt(Lt(b,w,h),w+1,m),i)}else[i,a]=Cg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,m)=>Lt(h,m,Or(m,f,o)),lr()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Ng(e){return Bn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function ec(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function ci(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=So(o,t-1,li),a=o[c].offset;const u=Zt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Zt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of bo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Ag(e){return{index:e.index,value:e}}function _g(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const jg={offsetHeight:"height",offsetWidth:"width"},an=He(([{log:e},{recalcInProgress:t}])=>{const n=Le(),r=Le(),o=kt(r,0),s=Le(),i=Le(),a=G(0),c=G([]),u=G(void 0),d=G(void 0),f=G((C,k)=>kn(C,jg[k])),h=G(void 0),m=G(0),b=Sg(),w=kt(F(n,je(c,e,m),sn(Ig,b),rt()),b),g=kt(F(c,rt(),sn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),ie(({prev:C})=>C)),[]);de(F(c,ve(C=>C.length>0),je(w,m),ie(([C,k,I])=>{const N=C.reduce((j,O,R)=>Lt(j,O,Or(O,k.offsetTree,I)||R),lr());return{...k,groupIndices:C,groupOffsetTree:N}})),w),de(F(r,je(w),ve(([C,{lastIndex:k}])=>C<k),ie(([C,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:C}])),n),de(u,d);const x=kt(F(u,ie(C=>C===void 0)),!0);de(F(d,ve(C=>C!==void 0&&Je(ut(w).sizeTree)),ie(C=>[{endIndex:0,size:C,startIndex:0}])),n);const v=Dt(F(n,je(w),sn(({sizes:C},[k,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:b}),ie(C=>C.changed)));Ve(F(a,sn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),ie(C=>C.diff)),C=>{const{groupIndices:k}=ut(w);if(C>0)Ae(t,!0),Ae(s,C+ec(C,k));else if(C<0){const I=ut(g);I.length>0&&(C-=ec(-C,I)),Ae(i,C)}}),Ve(F(a,je(e)),([C,k])=>{C<0&&k("`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:a},Rt.ERROR)});const S=Dt(s);de(F(s,je(w),ie(([C,k])=>{const I=k.groupIndices.length>0,N=[],j=k.lastSize;if(I){const O=Rr(k.sizeTree,0);let R=0,$=0;for(;R<C;){const M=k.groupIndices[$],W=k.groupIndices.length===$+1?1/0:k.groupIndices[$+1]-M-1;N.push({endIndex:M,size:O,startIndex:M}),N.push({endIndex:M+1+W-1,size:j,startIndex:M+1}),$++,R+=W+1}const K=Bn(k.sizeTree);return R!==C&&K.shift(),K.reduce((M,{k:W,v:U})=>{let V=M.ranges;return M.prevSize!==0&&(V=[...M.ranges,{endIndex:W+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:W+C,prevSize:U,ranges:V}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Bn(k.sizeTree).reduce((O,{k:R,v:$})=>({prevIndex:R+C,prevSize:$,ranges:[...O.ranges,{endIndex:R+C-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=Dt(F(i,je(w,m),ie(([C,{offsetTree:k},I])=>{const N=-C;return Or(N,k,I)})));return de(F(i,je(w,m),ie(([C,k,I])=>{if(k.groupIndices.length>0){if(Je(k.sizeTree))return k;let N=lr();const j=ut(g);let O=0,R=0,$=0;for(;O<-C;){$=j[R];const K=j[R+1]-$-1;R++,O+=K+1}if(N=Bn(k.sizeTree).reduce((K,{k:M,v:W})=>Lt(K,Math.max(0,M+C),W),N),O!==-C){const K=Rr(k.sizeTree,$);N=Lt(N,0,K);const M=Zt(k.sizeTree,-C+1)[1];N=Lt(N,1,M)}return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}else{const N=Bn(k.sizeTree).reduce((j,{k:O,v:R})=>Lt(j,Math.max(0,O+C),R),lr());return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}})),w),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:m,groupIndices:c,itemSize:f,listRefresh:v,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:w,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},nt(Cn,ai),{singleton:!0});function Rg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const tc=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Le(),i=Le(),a=Dt(F(s,ie(Rg)));return de(F(a,ie(c=>c.totalCount)),n),de(F(a,ie(c=>c.groupIndices)),e),de(F(ht(o,t,r),ve(([c,u])=>Co(u)),ie(([c,u,d])=>Zt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),rt(),ie(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},nt(an,It)),Tn=He(([{log:e}])=>{const t=G(!1),n=Dt(F(t,ve(r=>r),rt()));return Ve(t,r=>{r&&ut(e)("props updated",{},Rt.DEBUG)}),{didMount:n,propsReady:t}},nt(Cn),{singleton:!0}),Pg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function nc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Pg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Mr=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const m=Le(),b=Le(),w=G(0);let g=null,x=null,v=null;function S(){g&&(g(),g=null),v&&(v(),v=null),x&&(clearTimeout(x),x=null),Ae(c,!1)}return de(F(m,je(n,f,r,w,a,i,h),je(e,s,o),ie(([[E,C,k,I,N,j,O,R],$,K,M])=>{const W=nc(E),{align:U,behavior:V,offset:L}=W,A=I-1,q=Ql(W,C,A);let J=Or(q,C.offsetTree,$)+j;U==="end"?(J+=K+Zt(C.sizeTree,q)[1]-k+M,q===A&&(J+=O)):U==="center"?J+=(K+Zt(C.sizeTree,q)[1]-k+M)/2:J-=N,L&&(J+=L);const se=te=>{S(),te?(R("retrying to scroll to",{location:E},Rt.DEBUG),Ae(m,E)):(Ae(b,!0),R("list did not change, scroll successful",{},Rt.DEBUG))};if(S(),V==="smooth"){let te=!1;v=Ve(t,pe=>{te=te||pe}),g=Jt(d,()=>{se(te)})}else g=Jt(F(t,Og(150)),se);return x=setTimeout(()=>{S()},1200),Ae(c,!0),R("scrolling from index to",{behavior:V,index:q,top:J},Rt.DEBUG),{behavior:V,top:J}})),u),{scrollTargetReached:b,scrollToIndex:m,topListHeight:w}},nt(an,It,Cn),{singleton:!0});function Og(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ui(e,t){e==0?t():requestAnimationFrame(()=>{ui(e-1,t)})}function di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Dr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=G(!0),c=G(0),u=G(!0);return de(F(i,je(c),ve(([d,f])=>!!f),on(!1)),a),de(F(i,je(c),ve(([d,f])=>!!f),on(!1)),u),Ve(F(ht(t,i),je(a,n,e,u),ve(([[,d],f,{sizeTree:h},m,b])=>d&&(!Je(h)||Qs(m))&&!f&&!b),je(c)),([,d])=>{Jt(o,()=>{Ae(u,!0)}),ui(4,()=>{Jt(r,()=>{Ae(a,!0)}),Ae(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},nt(an,It,Mr,Tn),{singleton:!0});function rc(e,t){return Math.abs(e-t)<1.01}const Lr="up",$r="down",Mg="none",Dg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Lg=0,Fr=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=G(!1),a=G(!0),c=Le(),u=Le(),d=G(4),f=G(Lg),h=kt(F(ti(F(xe(o),Fn(1),on(!0)),F(xe(o),Fn(1),on(!1),zl(100))),rt()),!1),m=kt(F(ti(F(n,on(!0)),F(n,on(!1),zl(200))),rt()),!1);de(F(ht(xe(o),xe(f)),ie(([v,S])=>v<=S),rt()),a),de(F(a,xn(50)),u);const b=Dt(F(ht(r,xe(s),xe(t),xe(e),xe(d)),sn((v,[{scrollHeight:S,scrollTop:E},C,k,I,N])=>{const j=E+C-S>-N,O={scrollHeight:S,scrollTop:E,viewportHeight:C};if(j){let $,K;return E>v.state.scrollTop?($="SCROLLED_DOWN",K=v.state.scrollTop-E):($="SIZE_DECREASED",K=v.state.scrollTop-E||v.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:K,state:O}}let R;return O.scrollHeight>v.state.scrollHeight?R="SIZE_INCREASED":C<v.state.viewportHeight?R="VIEWPORT_HEIGHT_DECREASING":E<v.state.scrollTop?R="SCROLLING_UPWARDS":R="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:R,state:O}},Dg),rt((v,S)=>v&&v.atBottom===S.atBottom))),w=kt(F(r,sn((v,{scrollHeight:S,scrollTop:E,viewportHeight:C})=>{if(rc(v.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:E};{const k=S-(E+C)<1;return v.scrollTop!==E&&k?{changed:!0,jump:v.scrollTop-E,scrollHeight:S,scrollTop:E}:{changed:!0,jump:0,scrollHeight:S,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ve(v=>v.changed),ie(v=>v.jump)),0);de(F(b,ie(v=>v.atBottom)),i),de(F(i,xn(50)),c);const g=G($r);de(F(r,ie(({scrollTop:v})=>v),rt(),sn((v,S)=>ut(m)?{direction:v.direction,prevScrollTop:S}:{direction:S<v.prevScrollTop?Lr:$r,prevScrollTop:S},{direction:$r,prevScrollTop:0}),ie(v=>v.direction)),g),de(F(r,xn(50),on(Mg)),g);const x=G(0);return de(F(h,ve(v=>!v),on(0)),x),de(F(o,xn(100),je(h),ve(([v,S])=>!!S),sn(([v,S],[E])=>[S,E],[0,0]),ie(([v,S])=>S-v)),x),{atBottomState:b,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:w,scrollDirection:g,scrollVelocity:x}},nt(It)),ko="top",To="bottom",oc="none";function sc(e,t,n){return typeof e=="number"?n===Lr&&t===ko||n===$r&&t===To?e:0:n===Lr?t===ko?e.main:e.reverse:t===To?e.main:e.reverse}function ic(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Le(),i=G(0),a=G(0),c=G(0),u=kt(F(ht(xe(r),xe(o),xe(n),xe(s,Pr),xe(c),xe(i),xe(t),xe(e),xe(a)),ie(([d,f,h,[m,b],w,g,x,v,S])=>{const E=d-v,C=g+x,k=Math.max(h-E,0);let I=oc;const N=ic(S,ko),j=ic(S,To);return m-=v,m+=h+x,b+=h+x,b-=v,m>d+C-N&&(I=Lr),b<d-k+f+j&&(I=$r),I!==oc?[Math.max(E-h-sc(w,ko,I)-N,0),E-k-x+f+sc(w,To,I)+j]:null}),ve(d=>d!=null),rt(Pr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},nt(It),{singleton:!0});function $g(e,t,n){if(Co(t)){const r=Zl(e,t);return[{index:Zt(t.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:e,offset:0,size:0}]}const hi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Eo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const w=e[e.length-1];d=w.offset+w.size}const f=n-i,h=a+f*c+(f-1)*r,m=u,b=h-d;return{bottom:d,firstItemIndex:s,items:lc(e,o,s),offsetBottom:b,offsetTop:u,top:m,topItems:lc(t,o,s),topListHeight:t.reduce((w,g)=>g.size+w,0),totalCount:n}}function ac(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,c=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return Eo(u,[],a,o,n,r)}function lc(e,t,n){if(e.length===0)return[];if(!Co(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=bo(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Hn=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:m},{recalcInProgress:b}])=>{const w=G([]),g=G(0),x=Le();de(s.topItemsIndexes,w);const v=kt(F(ht(m,b,xe(c,Pr),xe(o),xe(r),xe(u),d,xe(w),xe(t),xe(n),e),ve(([k,I,,N,,,,,,,j])=>{const O=j&&j.length!==N;return k&&!I&&!O}),ie(([,,[k,I],N,j,O,R,$,K,M,W])=>{const U=j,{offsetTree:V,sizeTree:L}=U,A=ut(g);if(N===0)return{...hi,totalCount:N};if(k===0&&I===0)return A===0?{...hi,totalCount:N}:ac(A,O,j,K,M,W||[]);if(Je(L))return A>0?null:Eo($g(di(O,N),U,W),[],N,M,U,K);const q=[];if($.length>0){const Ie=$[0],Ne=$[$.length-1];let B=0;for(const _ of bo(L,Ie,Ne)){const H=_.value,ee=Math.max(_.start,Ie),ue=Math.min(_.end,Ne);for(let ce=ee;ce<=ue;ce++)q.push({data:W==null?void 0:W[ce],index:ce,offset:B,size:H}),B+=H}}if(!R)return Eo([],q,N,M,U,K);const J=$.length>0?$[$.length-1]+1:0,se=Eg(V,k,I,J);if(se.length===0)return null;const te=N-1,pe=wo([],Ie=>{for(const Ne of se){const B=Ne.value;let _=B.offset,H=Ne.start;const ee=B.size;if(B.offset<k){H+=Math.floor((k-B.offset+M)/(ee+M));const ce=H-Ne.start;_+=ce*ee+ce*M}H<J&&(_+=(J-H)*ee,H=J);const ue=Math.min(Ne.end,te);for(let ce=H;ce<=ue&&!(_>=I);ce++)Ie.push({data:W==null?void 0:W[ce],index:ce,offset:_,size:ee}),_+=ee+M}});return Eo(pe,q,N,M,U,K)}),ve(k=>k!==null),rt()),hi);de(F(e,ve(Qs),ie(k=>k==null?void 0:k.length)),o),de(F(v,ie(k=>k.topListHeight)),f),de(f,a),de(F(v,ie(k=>[k.top,k.bottom])),i),de(F(v,ie(k=>k.items)),x);const S=Dt(F(v,ve(({items:k})=>k.length>0),je(o,e),ve(([{items:k},I])=>k[k.length-1].originalIndex===I-1),ie(([,k,I])=>[k-1,I]),rt(Pr),ie(([k])=>k))),E=Dt(F(v,xn(200),ve(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),ie(({items:k})=>k[0].index),rt())),C=Dt(F(v,ve(({items:k})=>k.length>0),ie(({items:k})=>{let I=0,N=k.length-1;for(;k[I].type==="group"&&I<N;)I++;for(;k[N].type==="group"&&N>I;)N--;return{endIndex:k[N].index,startIndex:k[I].index}}),rt(Xl)));return{endReached:S,initialItemCount:g,itemsRendered:x,listState:v,rangeChanged:C,startReached:E,topItemsIndexes:w,...h}},nt(an,tc,fi,Dr,Mr,Fr,Tn,ai),{singleton:!0}),cc=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Le(),i=kt(F(ht(n,e,r,t,o),ie(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return de(xe(i),s),{totalListHeight:i,totalListHeightChanged:s}},nt(It,Hn),{singleton:!0}),Fg=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=G(!1),r=kt(F(ht(n,e,t),ve(([o])=>o),ie(([,o,s])=>Math.max(0,o-s)),xn(0),rt()),0);return{alignToBottom:n,paddingTopAddition:r}},nt(It,cc),{singleton:!0}),uc=He(()=>({context:G(null)})),zg=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,dc=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=Le();return de(F(d,je(t,c,n,s,o,r,a),je(e),ie(([[f,h,m,b,w,g,x,v],S])=>{const{align:E,behavior:C,calculateViewLocation:k=zg,done:I,...N}=f,j=Ql(f,h,b-1),O=Or(j,h.offsetTree,S)+w+g,R=O+Zt(h.sizeTree,j)[1],$=v+g,K=v+m-x,M=k({itemBottom:R,itemTop:O,locationParams:{align:E,behavior:C,...N},viewportBottom:K,viewportTop:$});return M?I&&Jt(F(i,ve(W=>!W),Fn(ut(i)?1:2)),I):I&&I(),M}),ve(f=>f!==null)),u),{scrollIntoView:d}},nt(an,It,Mr,Hn,Cn),{singleton:!0});function fc(e){return e?e==="smooth"?"smooth":"auto":!1}const Bg=(e,t)=>typeof e=="function"?fc(e(t)):t&&fc(e),Hg=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:m}])=>{const b=G(!1),w=Le();let g=null;function x(C){Ae(i,{align:"end",behavior:C,index:"LAST"})}Ve(F(ht(F(xe(t),Fn(1)),c),je(xe(b),s,a,f),ie(([[C,k],I,N,j,O])=>{let R=k&&j,$="auto";return R&&($=Bg(I,N||O),R=R&&!!$),{followOutputBehavior:$,shouldFollow:R,totalCount:C}}),ve(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{g&&(g(),g=null),ut(n)?requestAnimationFrame(()=>{ut(d)("following output to ",{totalCount:k},Rt.DEBUG),x(C)}):g=Jt(e,()=>{ut(d)("following output to ",{totalCount:k},Rt.DEBUG),x(C),g=null})});function v(C){const k=Jt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ut(d)("scrolling to bottom due to increased size",{},Rt.DEBUG),x("auto"))});setTimeout(k,100)}Ve(F(ht(xe(b),t,u),ve(([C,,k])=>C&&k),sn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),ve(({refreshed:C})=>C),je(b,t)),([,C])=>{ut(a)&&v(C!==!1)}),Ve(w,()=>{v(ut(b)!==!1)}),Ve(ht(xe(b),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=G(null),E=Le();return de(ti(F(xe(r),ie(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),F(xe(t))),E),Ve(F(ht(F(E,Fn(1)),c),je(xe(S),a,f,h),ie(([[C,k],I,N,j,O])=>k&&N&&(I==null?void 0:I({context:O,totalCount:C,scrollingInProgress:j}))),ve(C=>!!C),xn(0)),C=>{g&&(g(),g=null),ut(n)?requestAnimationFrame(()=>{ut(d)("scrolling into view",{}),Ae(m,C)}):g=Jt(e,()=>{ut(d)("scrolling into view",{}),Ae(m,C),g=null})}),{autoscrollToBottom:w,followOutput:b,scrollIntoViewOnChange:S}},nt(an,Fr,Mr,Dr,Tn,Cn,It,uc,dc)),Ug=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(de(F(a,je(s),ve(([,c])=>c!==0),je(o,r,t,n,e),ie(([[,c],u,d,f,h,m=[]])=>ac(c,u,d,f,h,m))),i),{}),nt(an,Dr,Hn,Tn),{singleton:!0}),Wg=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=G(0);return Ve(F(e,je(r),ve(([,o])=>o!==0),ie(([,o])=>({top:o}))),o=>{Jt(F(n,Fn(1),ve(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(t,o)})})}),{initialScrollTop:r}},nt(Tn,It,Hn),{singleton:!0}),hc=He(([{scrollVelocity:e}])=>{const t=G(!1),n=Le(),r=G(!1);return de(F(e,je(r,t,n),ve(([o,s])=>!!s),ie(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),rt()),t),Ve(F(ht(t,e,n),je(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},nt(Fr),{singleton:!0}),pi=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=Le(),r=Le(),o=Le(),s=G(!1),i=G(void 0);return de(F(ht(n,r),ie(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),de(F(t,je(r),ie(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},nt(It)),Vg=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=Le(),d=G(void 0),f=G(null),h=G(null);return de(a,f),de(c,h),Ve(F(u,je(t,r,i,f,h,n)),([m,b,w,g,x,v,S])=>{const E=Ng(b.sizeTree);g&&x!==null&&v!==null&&(w=x.scrollTop-v.offsetTop),w-=S,m({ranges:E,scrollTop:w})}),de(F(d,ve(Qs),ie(qg)),o),de(F(s,je(d),ve(([,m])=>m!==void 0),rt(),ie(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:d}},nt(an,It,Dr,Tn,pi));function qg(e){return{align:"start",index:0,offset:e.scrollTop}}const Kg=He(([{topItemsIndexes:e}])=>{const t=G(0);return de(F(t,ve(n=>n>=0),ie(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},nt(Hn));function pc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Gg=pc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Yg=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:m},{recalcInProgress:b}])=>{const w=Dt(F(c,je(i),sn(([,x,v,S],[{bottom:E,items:C,offsetBottom:k,totalCount:I},N])=>{const j=E+k;let O=0;return v===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(O=j-S,O!==0&&(O+=N))),[O,C,I,j]},[0,[],0,0]),ve(([x])=>x!==0),je(r,a,n,o,m,b),ve(([,x,v,S,,,E])=>!E&&!S&&x!==0&&v===Lr),ie(([[x],,,,,v])=>(v("Upward scrolling compensation",{amount:x},Rt.DEBUG),x))));function g(x){x>0?(Ae(t,{behavior:"auto",top:-x}),Ae(e,0)):(Ae(e,0),Ae(t,{behavior:"auto",top:-x}))}return Ve(F(w,je(e,s)),([x,v,S])=>{S&&Gg()?Ae(e,v-x):g(-x)}),Ve(F(ht(kt(s,!1),e,b),ve(([x,v,S])=>!x&&!S&&v!==0),ie(([x,v])=>v),xn(1)),g),de(F(f,ie(x=>({top:-x}))),t),Ve(F(u,je(h,d),ie(([x,{groupIndices:v,lastSize:S,sizeTree:E},C])=>{function k(I){return I*(S+C)}if(v.length===0)return k(x);{let I=0;const N=Rr(E,0);let j=0,O=0;for(;j<x;){j++,I+=N;let R=v.length===O+1?1/0:v[O+1]-v[O]-1;j+R>x&&(I-=N,R=x-j+1),j+=R,I+=k(R),O++}return I}})),x=>{Ae(e,x),requestAnimationFrame(()=>{Ae(t,{top:x}),requestAnimationFrame(()=>{Ae(e,0),Ae(b,!1)})})}),{deviation:e}},nt(It,Fr,Hn,an,Cn,ai)),Xg=He(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),nt(fi,Ug,Tn,hc,cc,Wg,Fg,pi,dc,Cn,uc)),mc=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:b},w,g,x,{listState:v,topItemsIndexes:S,...E},{scrollToIndex:C},k,{topItemCount:I},{groupCounts:N},j])=>(de(E.rangeChanged,j.scrollSeekRangeChanged),de(F(j.windowViewportRect,ie(O=>O.visibleHeight)),w.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:m,scrolledToInitialItem:b,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:v,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...j,...w,sizes:c,...g}),nt(an,Dr,It,Vg,Hg,Hn,Mr,Yg,Kg,tc,Xg));function Jg(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Io=typeof document<"u"?y.useLayoutEffect:y.useEffect;function gc(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=y.createContext({});function c(g,x){g.propsReady&&Ae(g.propsReady,!1);for(const v of r){const S=g[t.required[v]];Ae(S,x[v])}for(const v of o)if(v in x){const S=g[t.optional[v]];Ae(S,x[v])}g.propsReady&&Ae(g.propsReady,!0)}function u(g){return s.reduce((x,v)=>(x[v]=S=>{const E=g[t.methods[v]];Ae(E,S)},x),{})}function d(g){return i.reduce((x,v)=>(x[v]=hg(g[t.events[v]]),x),{})}const f=y.forwardRef((g,x)=>{const{children:v,...S}=g,[E]=y.useState(()=>wo(mg(e),I=>{c(I,S)})),[C]=y.useState(Fl(d,E));Io(()=>{for(const I of i)I in S&&Ve(C[I],S[I]);return()=>{Object.values(C).map(ei)}},[S,C,E]),Io(()=>{c(E,S)}),y.useImperativeHandle(x,Ll(u(E)));const k=n;return l.jsx(a.Provider,{value:E,children:n?l.jsx(k,{...Jg([...r,...o,...i],S),children:v}):v})}),h=g=>{const x=y.useContext(a);return y.useCallback(v=>{Ae(x[g],v)},[x,g])},m=g=>{const x=y.useContext(a)[g],v=y.useCallback(S=>Ve(x,S),[x]);return y.useSyncExternalStore(v,()=>ut(x),()=>ut(x))},b=g=>{const x=y.useContext(a)[g],[v,S]=y.useState(Fl(ut,x));return Io(()=>Ve(x,E=>{E!==v&&S(Ll(E))}),[x,v]),v},w=y.version.startsWith("18")?m:b;return{Component:f,useEmitter:(g,x)=>{const v=y.useContext(a)[g];Io(()=>Ve(v,x),[x,v])},useEmitterValue:w,usePublisher:h}}const xc=y.createContext(void 0),vc=y.createContext(void 0),wc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function mi(e){return"self"in e}function Zg(e){return"body"in e}function bc(e,t,n,r=ar,o,s){const i=y.useRef(null),a=y.useRef(null),c=y.useRef(null),u=y.useCallback(h=>{let m,b,w;const g=h.target;if(Zg(g)||mi(g)){const v=mi(g)?g:g.defaultView;w=s?v.scrollX:v.scrollY,m=s?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,b=s?v.innerWidth:v.innerHeight}else w=s?g.scrollLeft:g.scrollTop,m=s?g.scrollWidth:g.scrollHeight,b=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:m,scrollTop:Math.max(w,0),viewportHeight:b})};h.suppressFlushSync?x():Rs.flushSync(x),a.current!==null&&(w===a.current||w<=0||w===m-b)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const m=i.current;if(!m||(s?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const b=h.behavior==="smooth";let w,g,x;mi(m)?(g=Math.max(kn(m.document.documentElement,s?"width":"height"),s?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),w=s?m.innerWidth:m.innerHeight,x=s?window.scrollX:window.scrollY):(g=m[s?"scrollWidth":"scrollHeight"],w=kn(m,s?"width":"height"),x=m[s?"scrollLeft":"scrollTop"]);const v=g-w;if(h.top=Math.ceil(Math.max(Math.min(v,h.top),0)),rc(w,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:w}),b&&t(!0);return}b?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),m.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const gi="-webkit-sticky",yc="sticky",xi=pc(()=>{if(typeof document>"u")return yc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:yc});function vi(e){return e}const Qg=He(()=>{const e=G(a=>`Item ${a}`),t=G(a=>`Group ${a}`),n=G({}),r=G(vi),o=G("div"),s=G(ar),i=(a,c=null)=>kt(F(n,ie(u=>u[a]),rt()),c);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ex=He(([e,t])=>({...e,...t}),nt(mc,Qg)),tx=({height:e})=>l.jsx("div",{style:{height:e}}),nx={overflowAnchor:"none",position:xi(),zIndex:1},Sc={overflowAnchor:"none"},rx={...Sc,display:"inline-block",height:"100%"},Cc=y.memo(function({showTopList:e=!1}){const t=Ce("listState"),n=Ht("sizeRanges"),r=Ce("useWindowScroll"),o=Ce("customScrollParent"),s=Ht("windowScrollContainerState"),i=Ht("scrollContainerState"),a=o||r?s:i,c=Ce("itemContent"),u=Ce("context"),d=Ce("groupContent"),f=Ce("trackItemSizes"),h=Ce("itemSize"),m=Ce("log"),b=Ht("gap"),w=Ce("horizontalDirection"),{callbackRef:g}=vg(n,h,f,e?ar:a,m,b,o,w,Ce("skipAnimationFrameInResizeObserver")),[x,v]=y.useState(0);wi("deviation",M=>{x!==M&&v(M)});const S=Ce("EmptyPlaceholder"),E=Ce("ScrollSeekPlaceholder")||tx,C=Ce("ListComponent"),k=Ce("ItemComponent"),I=Ce("GroupComponent"),N=Ce("computeItemKey"),j=Ce("isSeeking"),O=Ce("groupIndices").length>0,R=Ce("alignToBottom"),$=Ce("initialItemFinalLocationReached"),K=e?{}:{boxSizing:"border-box",...w?{display:"inline-block",height:"100%",marginLeft:x!==0?x:R?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:R?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?l.jsx(S,{...Tt(S,u)}):l.jsx(C,{...Tt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:K,children:(e?t.topItems:t.items).map(M=>{const W=M.originalIndex,U=N(W+t.firstItemIndex,M.data,u);return j?y.createElement(E,{...Tt(E,u),height:M.size,index:M.index,key:U,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(I,{...Tt(I,u),"data-index":W,"data-item-index":M.index,"data-known-size":M.size,key:U,style:nx},d(M.index,u)):y.createElement(k,{...Tt(k,u),...ax(k,M.data),"data-index":W,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:U,style:w?rx:Sc},O?c(M.index,M.groupIndex,M.data,u):c(M.index,M.data,u))})})}),ox={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},sx={outline:"none",overflowX:"auto",position:"relative"},No=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),ix={position:xi(),top:0,width:"100%",zIndex:1};function Tt(e,t){if(typeof e!="string")return{context:t}}function ax(e,t){return{item:typeof e=="string"?void 0:t}}const lx=y.memo(function(){const e=Ce("HeaderComponent"),t=Ht("headerHeight"),n=Ce("HeaderFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,Ce("skipAnimationFrameInResizeObserver")),o=Ce("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null}),cx=y.memo(function(){const e=Ce("FooterComponent"),t=Ht("footerHeight"),n=Ce("HeaderFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,Ce("skipAnimationFrameInResizeObserver")),o=Ce("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null});function kc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:m,scrollToCallback:b}=bc(a,u,c,d,void 0,f);return e("scrollTo",b),e("scrollBy",h),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?sx:ox,...o},tabIndex:0,...i,...Tt(c,s),children:r})})}function Tc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),m=y.useRef(null),b=t("scrollerRef"),{scrollByCallback:w,scrollerRef:g,scrollToCallback:x}=bc(a,u,c,b,h);return wc(()=>{var v;return g.current=h||((v=m.current)==null?void 0:v.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",w),l.jsx(c,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Tt(c,s),children:r})})}const ux=({children:e})=>{const t=y.useContext(xc),n=Ht("viewportHeight"),r=Ht("fixedItemHeight"),o=Ce("alignToBottom"),s=Ce("horizontalDirection"),i=y.useMemo(()=>$l(n,c=>kn(c,s?"width":"height")),[n,s]),a=zn(i,!0,Ce("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:No(o),children:e})},dx=({children:e})=>{const t=y.useContext(xc),n=Ht("windowViewportRect"),r=Ht("fixedItemHeight"),o=Ce("customScrollParent"),s=Ul(n,o,Ce("skipAnimationFrameInResizeObserver")),i=Ce("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:No(i),children:e})},fx=({children:e})=>{const t=Ce("TopItemListComponent")||"div",n=Ce("headerHeight"),r={...ix,marginTop:`${n}px`},o=Ce("context");return l.jsx(t,{style:r,...Tt(t,o),children:e})},hx=y.memo(function(e){const t=Ce("useWindowScroll"),n=Ce("topItemsIndexes").length>0,r=Ce("customScrollParent"),o=Ce("context");return l.jsxs(r||t?gx:mx,{...e,context:o,children:[n&&l.jsx(fx,{children:l.jsx(Cc,{showTopList:!0})}),l.jsxs(r||t?dx:ux,{children:[l.jsx(lx,{}),l.jsx(Cc,{}),l.jsx(cx,{})]})]})}),{Component:px,useEmitter:wi,useEmitterValue:Ce,usePublisher:Ht}=gc(ex,{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"}},hx),mx=kc({useEmitter:wi,useEmitterValue:Ce,usePublisher:Ht}),gx=Tc({useEmitter:wi,useEmitterValue:Ce,usePublisher:Ht}),xx=px;nt(mc,He(()=>{const e=G(u=>l.jsxs("td",{children:["Item $",u]})),t=G(null),n=G(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=G(null),o=G(null),s=G({}),i=G(vi),a=G(ar),c=(u,d=null)=>kt(F(s,ie(f=>f[u]),rt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),xi();const Ec={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},vx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ic,floor:Ao,max:zr,min:bi,round:Nc}=Math;function Ac(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function wx(e){return{...vx,items:e}}function _o(e,t){return e&&e.width===t.width&&e.height===t.height}function bx(e,t){return e&&e.column===t.column&&e.row===t.row}const yx=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,m,{didMount:b,propsReady:w},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:v,windowScrollTo:S,windowViewportRect:E},C])=>{const k=G(0),I=G(0),N=G(Ec),j=G({height:0,width:0}),O=G({height:0,width:0}),R=Le(),$=Le(),K=G(0),M=G(null),W=G({column:0,row:0}),U=Le(),V=Le(),L=G(!1),A=G(0),q=G(!0),J=G(!1),se=G(!1);Ve(F(b,je(A),ve(([_,H])=>!!H)),()=>{Ae(q,!1)}),Ve(F(ht(b,q,O,j,A,J),ve(([_,H,ee,ue,,ce])=>_&&!H&&ee.height!==0&&ue.height!==0&&!ce)),([,,,,_])=>{Ae(J,!0),ui(1,()=>{Ae(R,_)}),Jt(F(u),()=>{Ae(t,[0,0]),Ae(q,!0)})}),de(F(V,ve(_=>_!=null&&_.scrollTop>0),on(0)),I),Ve(F(b,je(V),ve(([,_])=>_!=null)),([,_])=>{_&&(Ae(j,_.viewport),Ae(O,_.item),Ae(W,_.gap),_.scrollTop>0&&(Ae(L,!0),Jt(F(u,Fn(1)),H=>{Ae(L,!1)}),Ae(c,{top:_.scrollTop})))}),de(F(j,ie(({height:_})=>_)),f),de(F(ht(xe(j,_o),xe(O,_o),xe(W,(_,H)=>_&&_.column===H.column&&_.row===H.row),xe(u)),ie(([_,H,ee,ue])=>({gap:ee,item:H,scrollTop:ue,viewport:_}))),U),de(F(ht(xe(k),r,xe(W,bx),xe(O,_o),xe(j,_o),xe(M),xe(I),xe(L),xe(q),xe(A)),ve(([,,,,,,,_])=>!_),ie(([_,[H,ee],ue,ce,Oe,Ge,ke,,be,Ue])=>{const{column:Ye,row:$e}=ue,{height:st,width:pt}=ce,{width:it}=Oe;if(ke===0&&(_===0||it===0))return Ec;if(pt===0){const Qe=di(Ue,_),yt=Qe+Math.max(ke-1,0);return wx(Ac(Qe,yt,Ge))}const dt=_c(it,pt,Ye);let at,Fe;be?H===0&&ee===0&&ke>0?(at=0,Fe=ke-1):(at=dt*Ao((H+$e)/(st+$e)),Fe=dt*Ic((ee+$e)/(st+$e))-1,Fe=bi(_-1,zr(Fe,dt-1)),at=bi(Fe,zr(0,at))):(at=0,Fe=-1);const Y=Ac(at,Fe,Ge),{bottom:re,top:he}=jc(Oe,ue,ce,Y),We=Ic(_/dt),Xe=We*st+(We-1)*$e-re;return{bottom:re,itemHeight:st,items:Y,itemWidth:pt,offsetBottom:Xe,offsetTop:he,top:he}})),N),de(F(M,ve(_=>_!==null),ie(_=>_.length)),k),de(F(ht(j,O,N,W),ve(([_,H,{items:ee}])=>ee.length>0&&H.height!==0&&_.height!==0),ie(([_,H,{items:ee},ue])=>{const{bottom:ce,top:Oe}=jc(_,ue,H,ee);return[Oe,ce]}),rt(Pr)),t);const te=G(!1);de(F(u,je(te),ie(([_,H])=>H||_!==0)),te);const pe=Dt(F(ht(N,k),ve(([{items:_}])=>_.length>0),je(te),ve(([[_,H],ee])=>{const ue=_.items[_.items.length-1].index===H-1;return(ee||_.bottom>0&&_.itemHeight>0&&_.offsetBottom===0&&_.items.length===H)&&ue}),ie(([[,_]])=>_-1),rt())),Ie=Dt(F(xe(N),ve(({items:_})=>_.length>0&&_[0].index===0),on(0),rt())),Ne=Dt(F(xe(N),je(L),ve(([{items:_},H])=>_.length>0&&!H),ie(([{items:_}])=>({endIndex:_[_.length-1].index,startIndex:_[0].index})),rt(Xl),xn(0)));de(Ne,m.scrollSeekRangeChanged),de(F(R,je(j,O,k,W),ie(([_,H,ee,ue,ce])=>{const Oe=nc(_),{align:Ge,behavior:ke,offset:be}=Oe;let Ue=Oe.index;Ue==="LAST"&&(Ue=ue-1),Ue=zr(0,Ue,bi(ue-1,Ue));let Ye=yi(H,ce,ee,Ue);return Ge==="end"?Ye=Nc(Ye-H.height+ee.height):Ge==="center"&&(Ye=Nc(Ye-H.height/2+ee.height/2)),be&&(Ye+=be),{behavior:ke,top:Ye}})),c);const B=kt(F(N,ie(_=>_.offsetBottom+_.bottom)),0);return de(F(E,ie(_=>({height:_.visibleHeight,width:_.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:K,footerHeight:o,gap:W,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:O,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:c,scrollToIndex:R,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:v,windowScrollTo:S,windowViewportRect:E,...m,gridState:N,horizontalDirection:se,initialTopMostItemIndex:A,totalListHeight:B,...h,endReached:pe,propsReady:w,rangeChanged:Ne,startReached:Ie,stateChanged:U,stateRestoreInProgress:L,...C}},nt(fi,It,Fr,hc,Tn,pi,Cn));function _c(e,t,n){return zr(1,Ao((e+n)/(Ao(t)+n)))}function jc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=yi(e,t,n,r[0].index);return{bottom:yi(e,t,n,r[r.length-1].index)+o,top:s}}function yi(e,t,n,r){const o=_c(e.width,n.width,t.column),s=Ao(r/o),i=s*n.height+zr(0,s-1)*t.row;return i>0?i+t.row:i}const Sx=He(()=>{const e=G(f=>`Item ${f}`),t=G({}),n=G(null),r=G("virtuoso-grid-item"),o=G("virtuoso-grid-list"),s=G(vi),i=G("div"),a=G(ar),c=(f,h=null)=>kt(F(t,ie(m=>m[f]),rt()),h),u=G(!1),d=G(!1);return de(xe(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Cx=He(([e,t])=>({...e,...t}),nt(yx,Sx)),kx=y.memo(function(){const e=ot("gridState"),t=ot("listClassName"),n=ot("itemClassName"),r=ot("itemContent"),o=ot("computeItemKey"),s=ot("isSeeking"),i=Ut("scrollHeight"),a=ot("ItemComponent"),c=ot("ListComponent"),u=ot("ScrollSeekPlaceholder"),d=ot("context"),f=Ut("itemDimensions"),h=Ut("gap"),m=ot("log"),b=ot("stateRestoreInProgress"),w=Ut("reportReadyState"),g=zn(y.useMemo(()=>x=>{const v=x.parentElement.parentElement.scrollHeight;i(v);const S=x.firstChild;if(S){const{height:E,width:C}=S.getBoundingClientRect();f({height:E,width:C})}h({column:Pc("column-gap",getComputedStyle(x).columnGap,m),row:Pc("row-gap",getComputedStyle(x).rowGap,m)})},[i,f,h,m]),!0,!1);return wc(()=>{e.itemHeight>0&&e.itemWidth>0&&w(!0)},[e]),b?null:l.jsx(c,{className:t,ref:g,...Tt(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const v=o(x.index,x.data,d);return s?l.jsx(u,{...Tt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},v):y.createElement(a,{...Tt(a,d),className:n,"data-index":x.index,key:v},r(x.index,x.data,d))})})}),Tx=y.memo(function(){const e=ot("HeaderComponent"),t=Ut("headerHeight"),n=ot("headerFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,!1),o=ot("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null}),Ex=y.memo(function(){const e=ot("FooterComponent"),t=Ut("footerHeight"),n=ot("headerFooterTag"),r=zn(y.useMemo(()=>s=>{t(kn(s,"height"))},[t]),!0,!1),o=ot("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...Tt(e,o)})}):null}),Ix=({children:e})=>{const t=y.useContext(vc),n=Ut("itemDimensions"),r=Ut("viewportDimensions"),o=zn(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:No(!1),children:e})},Nx=({children:e})=>{const t=y.useContext(vc),n=Ut("windowViewportRect"),r=Ut("itemDimensions"),o=ot("customScrollParent"),s=Ul(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:No(!1),children:e})},Ax=y.memo(function({...e}){const t=ot("useWindowScroll"),n=ot("customScrollParent"),r=n||t?jx:_x,o=n||t?Nx:Ix,s=ot("context");return l.jsx(r,{...e,...Tt(r,s),children:l.jsxs(o,{children:[l.jsx(Tx,{}),l.jsx(kx,{}),l.jsx(Ex,{})]})})}),{useEmitter:Rc,useEmitterValue:ot,usePublisher:Ut}=gc(Cx,{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"}},Ax),_x=kc({useEmitter:Rc,useEmitterValue:ot,usePublisher:Ut}),jx=Tc({useEmitter:Rc,useEmitterValue:ot,usePublisher:Ut});function Pc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Rt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Rx=ro.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 Si({className:e,variant:t,...n}){return l.jsx("div",{className:Q(Rx({variant:t}),e),...n})}function le(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function Px(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,c=p.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=p.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function ln(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:m,...b}=f,w=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,g=p.useMemo(()=>b,Object.values(b));return l.jsx(w.Provider,{value:g,children:m})};u.displayName=s+"Provider";function d(f,h){var w;const m=((w=h==null?void 0:h[e])==null?void 0:w[c])||a,b=p.useContext(m);if(b)return b;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>p.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,Ox(o,...t)]}function Ox(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var bt=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},Mx=p[" useInsertionEffect ".trim().toString()]||bt;function Un({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Dx({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=p.useRef(e!==void 0);p.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"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=a},[a,r])}const u=p.useCallback(d=>{var f;if(a){const h=Lx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[c,u]}function Dx({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Mx(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Lx(e){return typeof e=="function"}function Oc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ci(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Oc(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():Oc(e[o],null)}}}}function Me(...e){return p.useCallback(Ci(...e),e)}var $x=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],we=$x.reduce((e,t)=>{const n=Mn.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Mc(e,t){e&&oo.flushSync(()=>e.dispatchEvent(t))}function Fx(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var $t=e=>{const{present:t,children:n}=e,r=zx(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Me(r.ref,Bx(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};$t.displayName="Presence";function zx(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=Fx(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=jo(r.current);s.current=a==="mounted"?u:"none"},[a]),bt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,m=jo(u);e?c("MOUNT"):m==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==m?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),bt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=m=>{const w=jo(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&w&&(c("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=m=>{m.target===t&&(s.current=jo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function jo(e){return(e==null?void 0:e.animationName)||"none"}function Bx(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Hx=p[" useId ".trim().toString()]||(()=>{}),Ux=0;function cn(e){const[t,n]=p.useState(Hx());return bt(()=>{n(r=>r??String(Ux++))},[e]),e||(t?`radix-${t}`:"")}var Ro="Collapsible",[Wx,jC]=ln(Ro),[Vx,ki]=Wx(Ro),Dc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Un({prop:r,defaultProp:o??!1,onChange:i,caller:Ro});return l.jsx(Vx,{scope:n,disabled:s,contentId:cn(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(we.div,{"data-state":Ei(c),"data-disabled":s?"":void 0,...a,ref:t})})});Dc.displayName=Ro;var Lc="CollapsibleTrigger",$c=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ki(Lc,n);return l.jsx(we.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ei(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:le(e.onClick,o.onOpenToggle)})});$c.displayName=Lc;var Ti="CollapsibleContent",qx=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ki(Ti,e.__scopeCollapsible);return l.jsx($t,{present:n||o.open,children:({present:s})=>l.jsx(Kx,{...r,ref:t,present:s})})});qx.displayName=Ti;var Kx=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ki(Ti,n),[a,c]=p.useState(r),u=p.useRef(null),d=Me(t,u),f=p.useRef(0),h=f.current,m=p.useRef(0),b=m.current,w=i.open||a,g=p.useRef(w),x=p.useRef(void 0);return p.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),bt(()=>{const v=u.current;if(v){x.current=x.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const S=v.getBoundingClientRect();f.current=S.height,m.current=S.width,g.current||(v.style.transitionDuration=x.current.transitionDuration,v.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(we.div,{"data-state":Ei(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!w,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...e.style},children:w&&o})});function Ei(e){return e?"open":"closed"}var Gx=Dc;const Fc=Gx,zc=$c,Br=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Br.displayName="Card";const Hr=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("flex flex-col space-y-1.5 p-6",e),...t}));Hr.displayName="CardHeader";const Ur=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:Q("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ur.displayName="CardTitle";const Bc=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));Bc.displayName="CardDescription";const Po=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("p-6 pt-0",e),...t}));Po.displayName="CardContent";const Hc=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:Q("flex items-center p-6 pt-0",e),...t}));Hc.displayName="CardFooter";function Uc(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Wn=Uc();function Yx(e){Wn=e}const Wc=/[&<>"']/,Xx=new RegExp(Wc.source,"g"),Vc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Jx=new RegExp(Vc.source,"g"),Zx={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},qc=e=>Zx[e];function Et(e,t){if(t){if(Wc.test(e))return e.replace(Xx,qc)}else if(Vc.test(e))return e.replace(Jx,qc);return e}const Qx=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Kc(e){return e.replace(Qx,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const ev=/(^|[^\[])\^/g;function Ze(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(ev,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const tv=/[^\w:]/g,nv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Gc(e,t,n){if(e){let r;try{r=decodeURIComponent(Kc(n)).replace(tv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!nv.test(n)&&(n=iv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Oo={},rv=/^[^:]+:\/*[^/]*$/,ov=/^([^:]+:)[\s\S]*$/,sv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function iv(e,t){Oo[" "+e]||(rv.test(e)?Oo[" "+e]=e+"/":Oo[" "+e]=Do(e,"/",!0)),e=Oo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(ov,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(sv,"$1")+t:e+t}const Mo={exec:function(){}};function Yc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Do(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function av(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function lv(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function Xc(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Jc(e,t,n,r){const o=t.href,s=t.title?Et(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:Et(i)}}function cv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
39
39
  `).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
40
40
  `)}class Ii{constructor(t){this.options=t||Wn}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Do(r,`
41
41
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=cv(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=Do(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,c,u,d,f,h,m,b,w=n[1].trim();const g=w.length>1,x={type:"list",raw:"",ordered:g,start:g?+w.slice(0,-1):"",loose:!1,items:[]};w=g?`\\d{1,9}\\${w.slice(-1)}`:`\\${w}`,this.options.pedantic&&(w=g?w:"[*+-]");const v=new RegExp(`^( {0,3}${w})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(b=!1,!(!(n=v.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
@@ -57,21 +57,24 @@ export interface ChatRequest {
57
57
  branchLabel?: string;
58
58
  active_agent?: string;
59
59
  }
60
- export type ToolStartEvent = {
61
- type: "tool_start";
60
+ type ToolEventIdentity = {
62
61
  id: string;
63
- name: string;
64
- args: Record<string, unknown>;
65
62
  call_id?: string;
66
- tool?: string;
67
63
  } | {
68
- type: "tool_start";
69
64
  call_id: string;
70
- tool: string;
71
- args: Record<string, unknown>;
72
65
  id?: string;
73
- name?: string;
74
66
  };
67
+ export type ToolStartEvent = {
68
+ type: "tool_start";
69
+ args: Record<string, unknown>;
70
+ name?: string;
71
+ tool?: string;
72
+ } & ToolEventIdentity;
73
+ export type ToolResultEvent = {
74
+ type: "tool_result";
75
+ output: unknown;
76
+ error?: string;
77
+ } & ToolEventIdentity;
75
78
  export type StreamEvent = {
76
79
  type: "token";
77
80
  content: string;
@@ -83,12 +86,7 @@ export type StreamEvent = {
83
86
  } | {
84
87
  type: "message_delta";
85
88
  delta: MessagePart[];
86
- } | ToolStartEvent | {
87
- type: "tool_result";
88
- id: string;
89
- output: unknown;
90
- error?: string;
91
- } | {
89
+ } | ToolStartEvent | ToolResultEvent | {
92
90
  type: "message_end";
93
91
  } | {
94
92
  type: "checkpoint";
@@ -221,3 +219,4 @@ export interface ApiConfig {
221
219
  getToken?: () => string | null;
222
220
  uploadPath?: string;
223
221
  }
222
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
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",