teodor-new-chat-ui 4.3.252 → 4.3.253
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 +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -4056,7 +4056,7 @@ function Xx({
|
|
|
4056
4056
|
j(!1);
|
|
4057
4057
|
}
|
|
4058
4058
|
}, [c, Y, I, s]), Tt = Te(async () => {
|
|
4059
|
-
N([], {}), y(null), De(), G([]), A(!1), P(null), C(!1), fe(!1), j(!1), k(null);
|
|
4059
|
+
N([], {}), y(null), De(), G([]), A(!1), P(null), C(!1), fe(!1), j(!1), k(null), await c.getAgent("default");
|
|
4060
4060
|
}, [N, De]), ht = Te(
|
|
4061
4061
|
async (ie, he, Le) => {
|
|
4062
4062
|
const ke = H.current;
|
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=Jn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&No.assertOptions(r,{silentJSONParsing:gn.transitional(gn.boolean),forcedJSONParsing:gn.transitional(gn.boolean),clarifyTimeoutError:gn.transitional(gn.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:No.assertOptions(o,{encode:gn.function,serialize:gn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),No.assertOptions(n,{baseUrl:gn.spelling("baseURL"),withXsrfToken:gn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&M.merge(s.common,s[n.method]);s&&M.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ut.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(y){typeof y.runWhen=="function"&&y.runWhen(n)===!1||(l=l&&y.synchronous,a.unshift(y.fulfilled,y.rejected))});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let d,f=0,h;if(!l){const m=[Ll.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,d=Promise.resolve(n);f<h;)d=d.then(m[f++],m[f++]);return d}h=a.length;let p=n;for(;f<h;){const m=a[f++],y=a[f++];try{p=m(p)}catch(x){y.call(this,x);break}}try{d=Ll.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Jn(this.defaults,t);const n=El(t.baseURL,t.url,t.allowAbsoluteUrls);return xl(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){Zn.prototype[t]=function(n,r){return this.request(Jn(r||{},{method:t,url:n,data:(r||{}).data}))}}),M.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Jn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Zn.prototype[t]=n(),Zn.prototype[t+"Form"]=n(!0)});let xg=class qp{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 gr(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 qp(function(o){t=o}),cancel:t}}};function yg(e){return function(n){return e.apply(null,n)}}function vg(e){return M.isObject(e)&&e.isAxiosError===!0}const ci={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(ci).forEach(([e,t])=>{ci[t]=e});function zl(e){const t=new Zn(e),n=nl(Zn.prototype.request,t);return M.extend(n,Zn.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return zl(Jn(e,o))},n}const St=zl(Lr);St.Axios=Zn,St.CanceledError=gr,St.CancelToken=xg,St.isCancel=Sl,St.VERSION=$l,St.toFormData=Co,St.AxiosError=Oe,St.Cancel=St.CanceledError,St.all=function(t){return Promise.all(t)},St.spread=yg,St.isAxiosError=vg,St.mergeConfig=Jn,St.AxiosHeaders=Ut,St.formToJSON=e=>wl(M.isHTMLForm(e)?new FormData(e):e),St.getAdapter=Dl.getAdapter,St.HttpStatusCode=ci,St.default=St;const{Axios:eT,AxiosError:tT,CanceledError:nT,isCancel:rT,CancelToken:oT,VERSION:sT,all:iT,Cancel:aT,isAxiosError:lT,spread:cT,toFormData:uT,AxiosHeaders:dT,HttpStatusCode:fT,formToJSON:hT,getAdapter:pT,mergeConfig:mT}=St,Bl=typeof window<"u"?window.__API_BASE_URL__:void 0,Hl=Bl?En(Bl):void 0;function En(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Ao=null;const ui=new Set;function Ul(){return Ao}function jo(e){Ao=e,ui.forEach(t=>t(e))}function Wl(e){return ui.add(e),()=>ui.delete(e)}const wg=3e4,bg=9e4,Zt=St.create({...Hl?{baseURL:Hl}:{},timeout:wg,withCredentials:!0});Zt.interceptors.request.use(e=>(Ao&&(e.headers.Authorization=`Bearer ${Ao}`),e)),Zt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),jo(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Qt(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function di(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Vl(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Kl(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function en(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class ql{get baseUrl(){const t=Zt.defaults.baseURL;return t?En(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=En(String(t.baseUrl))),t.authToken!==void 0&&jo(t.authToken)}getAuthToken(){return Ul()}setAuthToken(t){jo(t)}onTokenChange(t){return Wl(t)}async listThreads(){const t=await Qt("/threads"),n=en(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await di("/threads",t?{title:t}:void 0);return en(r)}async updateThread(t,n){const r=await Vl(`/threads/${t}`,{title:n});return en(r)}async deleteThread(t){const n=await Kl(`/threads/${t}`);return en(n)}async threadInfo(t){const n=await Qt(`/threads/${t}/info`);return en(n)}async listAgents(){const t=await Qt("/agents"),n=en(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Qt(`/agents/${t}`);return en(n)}async getAgentSchema(t){const n=await Qt(`/agents/${t}/schema`);return en(n)}async getState(t){const n=await Qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return en(n)}async getStateHistory(t){const n=await Qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:bg});return en(n)}async cancelRun(t){const n=await di("/runs/cancel",{threadId:t});return en(n)}async listCheckpointSummaries(t){const n=await Qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=en(n);return(r==null?void 0:r.items)??[]}}const Pn=new ql,Gl=b.createContext(null);function Sg({children:e,apiConfig:t}){const n=Pn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Gl.Provider,{value:r,children:e})}function fi(){const e=b.useContext(Gl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Cg(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 l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Tg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Cg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const kg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function hi(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Eg(e,t){return`${e??""}::${t??""}`}function Fr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!hi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ng(t),i=Yl(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Yl(e,t){if(!hi(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(j=>!!j&&typeof j=="object").map(j=>({...j})):a===null?null:void 0,c=r.map((j,A)=>Mg(j,A)).filter(j=>!!j),d=Wt(e.config),f=Wt(d==null?void 0:d.configurable),h=Nt(f,["checkpoint_id","checkpointId"]),p=Nt(f,["checkpoint_ns","checkpointNs"]),m=Wt(e==null?void 0:e.parentConfig),y=Wt(m==null?void 0:m.configurable),x=Nt(y,["checkpoint_id","checkpointId"])??null,g=Nt(y,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),k=c[c.length-1]??null,T=Wt(e==null?void 0:e.metadata),C=Nt(T,["branch_label","branchLabel"]),E=Nt(y,["checkpoint_id","checkpointId"]),N=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:x,nextCursorNs:g,interrupt:Ig(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:T??null,config:d??null,parentConfig:m??null,next:N??null,tasks:l??null,values:i??null}}function Ig(e,t,n){const r=Pg(e,n);return r||Rg(t,n)}function Ng(e){const t=new Map;e.forEach((o,s)=>{if(!hi(o))return;const i=Yl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Eg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ag(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Jl(s.createdAt??"")-Jl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ag(e,t){return{...e,metadata:_o(e.metadata,t.metadata)??null,config:_o(e.config,t.config)??null,parentConfig:_o(e.parentConfig,t.parentConfig)??null,next:jg(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:_o(e.values,t.values)??null}}function _o(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function jg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Rg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Pg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Og(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=zr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=zr(r.state,`${o}-state`);if(s)return s}}return null}function Og(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",y=Array.isArray(d)?d:void 0,x=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:y,state:x!==void 0?x:f}}const n=Wt(e);if(!n)return null;const r=Nt(n,["id","task_id","taskId"])??t,o=Nt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function zr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Xl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=zr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=zr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=zr(l,t,n+1,r);if(c)return c}}return null}function Xl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Nt(n,["type","event","kind"]),o=Nt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Xl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Jl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Wt(e)??{},o=Wt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=kg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Wt(o.additional_kwargs)??Wt(o.additionalKwargs),d=Wt(o.response_metadata)??Wt(o.responseMetadata),f=Nt(c,["createdAt","created_at"])??Nt(o,["created_at","createdAt"]),h=Nt(c,["checkpointId","checkpoint_id"]),p=Nt(c,["checkpointNs","checkpoint_ns"]),m=Dg(o.content),y={id:l,role:i,content:m};f&&(y.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(y.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(y.model=String(d.model_name)),!y.model&&typeof o.model=="string"&&(y.model=o.model),h&&(y.checkpointId=h),p&&(y.checkpointNs=p);const x=zg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),g=d?{...d}:void 0;x&&Object.keys(x).length&&(y.additionalKwargs=x),g&&Object.keys(g).length&&(y.responseMetadata=g);const w=Lg((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(y.content=[...y.content,...w]),i==="tool"){const S=$g(o,y.content);S&&(y.content=S)}return y}function Dg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Zl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Zl(e);return t?[t]:[]}return[]}function Zl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Nt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Nt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Ql(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Nt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Ql(e,t){var s;const n=Nt(e,["id","call_id"])??t,r=Nt(e,["name"])??Nt(Wt(e.function),["name"]);if(!n||!r)return null;const o=Fg(e.args??e.arguments??((s=Wt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Ql(t,`tool_call_${n}`)).filter(t=>!!t):[]}function $g(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Fg(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Wt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Nt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function zg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function ec(e={}){const t=b.useMemo(()=>En(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[f,h]=b.useState(""),[p,m]=b.useState(null),[y,x]=b.useState(0),[g,w]=b.useState(!1),S=b.useRef(null),k=b.useRef(!0),T=b.useRef(0),C=b.useRef(null),E=b.useRef(null),N=b.useRef(null),j=b.useRef(null),A=b.useCallback(_=>{o(_)},[]),P=b.useCallback(()=>{h(""),m(null),d(null),E.current=null,N.current=null,j.current=null},[]),$=b.useCallback(()=>{var _;console.debug("[use-chat] stop() invoked - aborting stream"),(_=S.current)==null||_.abort(),S.current=null,C.current=null,l(!1),w(!1),T.current=0,x(0)},[]),F=b.useCallback((_,z,R)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),m(null),E.current=null,N.current=null,j.current=null;const Y=new AbortController;S.current=Y;let O=null,L=null,G=!1;return C.current={threadId:_.threadId??null,headers:{}},(async()=>{var he,Ae,_e,H,ee,K,D,B,te,ie,ne,Le,Q,pe,Ne,Re,Ke,Ze;const J=He=>{var ze;try{const qe=JSON.parse(JSON.stringify(He));return(ze=qe==null?void 0:qe.payload)!=null&&ze.files_info&&Array.isArray(qe.payload.files_info)&&(qe.payload.files_info=qe.payload.files_info.map(Qe=>({...Qe,data:Qe!=null&&Qe.data?`<base64 ${String(Qe.data).length} chars>`:Qe==null?void 0:Qe.data}))),qe}catch{return He}};try{let He={};try{if(r)He={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const fe=window.__AUTH_TOKEN__,tt=((he=window.localStorage)==null?void 0:he.getItem("authToken"))||null;let yt=null;try{const be=(Ae=window.localStorage)==null?void 0:Ae.getItem("chat-settings");be&&(yt=((_e=JSON.parse(be))==null?void 0:_e.apiKey)||null)}catch{}const U=fe||tt||yt||null;U&&(He={Authorization:`Bearer ${U}`})}}catch{}console.debug("[use-chat] POST",t+n,J(_));let ze={};if(typeof window<"u")try{const we=(H=window.localStorage)==null?void 0:H.getItem("authSessionId");we&&(ze={"X-Session-Id":we})}catch{}const qe={...He,...ze,...s.current},Qe={"Content-Type":"application/json",Accept:"text/event-stream",...qe},et=await fetch(t+n,{method:"POST",headers:Qe,body:JSON.stringify(_),signal:Y.signal,credentials:i});if(C.current&&(C.current.headers=qe),!et.ok||!et.body){const we=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,we==null?void 0:we.slice(0,500));const fe=`stream ${et.status}${we?": "+we:""}`;throw(ee=R==null?void 0:R.onConnectionError)==null||ee.call(R,fe),G=!0,O="error",L=fe,new Error(fe)}w(!0);const st=et.body.getReader(),Tt=new TextDecoder;let ft="",it=[];T.current=0,x(0);let kt=0,wt=null;const Xe=()=>{if(it.length){const we=it.join("");it=[],k.current&&h(fe=>fe+we)}wt=null},ae=()=>{typeof window<"u"&&wt==null&&(wt=requestAnimationFrame(Xe))};let me=Date.now();const $e=setInterval(()=>{var we;if(Date.now()-me>18e5){const fe="Stream idle timeout";d(fe),O="error",L=fe,Y.abort(),(we=R==null?void 0:R.onError)==null||we.call(R,fe)}},5e3),ke=1024*1024;try{const we=et.headers.get("X-Thread-Id")||et.headers.get("x-thread-id"),fe=et.headers.get("X-Thread-Created")||et.headers.get("x-thread-created"),tt=we??null,yt=String(fe??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:tt}),(K=R==null?void 0:R.onOpen)==null||K.call(R,{threadId:tt,created:yt});;){const{value:U,done:be}=await st.read();if(be)break;ft+=Tt.decode(U,{stream:!0}),ft.length>ke&&(ft="",console.warn("Stream buffer reset: exceeded 1MB"));let ye;for(;(ye=ft.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const ht=ft.slice(0,ye);ft=ft.slice(ye+2);const gt=Hg(ht);if(!gt)continue;let Et;try{Et=JSON.parse(gt)}catch{console.debug("[use-chat] malformed SSE:",gt.slice(0,200));continue}const Me=Bg(Et)?Et.data:Et;me=Date.now();const Kt=Me.seq;if(Kt!==void 0){if(Kt<=kt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Kt,lastProcessedSeq:kt,type:Me.type});continue}kt>0&&Kt>kt+1&&((D=R==null?void 0:R.onGap)==null||D.call(R,{from:kt,to:Kt})),kt=Kt,T.current=Kt,x(Kt)}if(console.debug("[use-chat] received event",{seq:Me.seq,type:Me.type,preview:(()=>{var lt;try{return Me.type==="message_delta"?{deltaTypes:(lt=Me.delta)==null?void 0:lt.map(It=>It.type),textLen:(Me.delta||[]).filter(It=>It.type==="text").map(It=>String(It.text||"").length)}:Me.content||Me.delta?{hasContent:!0}:{}}catch(It){return{err:String(It)}}})()}),Me.type==="checkpoint")E.current=Me.checkpointId??null,N.current=Me.checkpointNs??null,m(Me.checkpointId??null);else if(Me.type==="state_history"){j.current=Me;try{const It=Fr(Me).latest;It&&(E.current=It.checkpointId??null,N.current=It.checkpointNs??null,m(It.checkpointId??null))}catch(lt){console.warn("[use-chat] Failed to hydrate state_history payload",lt)}}try{z==null||z(Me)}catch(lt){console.error("[use-chat] Error in onEvent callback:",lt,"for event:",Me.type)}if(Me.type==="token"&&e.autoAppendAssistant!==!1)it.push(Me.content),ae();else if(Me.type==="message_delta"){const lt=Me.delta.filter(It=>It.type==="text").map(It=>It.text).join("");lt&&e.autoAppendAssistant!==!1&&(it.push(lt),ae())}else if(Me.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(B=R==null?void 0:R.onHeartbeat)==null||B.call(R,Me)}catch(lt){console.warn("[use-chat] heartbeat callback failed",lt)}}else if(wt!==null&&cancelAnimationFrame(wt),Xe(),Me.type==="checkpoint")m(Me.checkpointId);else if(Me.type==="error"){const lt=Me;if(d(lt.message),O="error",L=lt.message,lt.error_type==="auth_error"||lt.code==="TOKEN_EXPIRED"||((te=lt.message)==null?void 0:te.includes("token"))||((ie=lt.message)==null?void 0:ie.includes("401"))||((ne=lt.message)==null?void 0:ne.includes("unauthorized"))||((Le=lt.message)==null?void 0:Le.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",lt.message);try{(Q=R==null?void 0:R.onAuthError)==null||Q.call(R,lt.message)}catch(Kn){console.warn("[use-chat] onAuthError handler failed",Kn)}Y.abort()}}}}Xe(),O===null&&!Y.signal.aborted&&(O="complete")}catch(we){if(we.name==="AbortError")O=O??"aborted";else{const fe=we.message||String(we);O="error",L=fe,d(fe),(pe=R==null?void 0:R.onError)==null||pe.call(R,fe)}}finally{try{await st.cancel()}catch{}finally{(Ne=st.releaseLock)==null||Ne.call(st)}wt!==null&&typeof window<"u"&&window.cancelAnimationFrame(wt),clearInterval($e)}}catch(He){if(He.name==="AbortError")O=O??"aborted";else{const ze=He.message||String(He);O="error",L=ze,d(ze),(Re=R==null?void 0:R.onError)==null||Re.call(R,ze),G||((Ke=R==null?void 0:R.onConnectionError)==null||Ke.call(R,ze),G=!0)}}finally{const He=T.current,ze=E.current,qe=N.current,Qe=j.current,et=O??(Y.signal.aborted?"aborted":L?"error":"complete");try{(Ze=R==null?void 0:R.onClosed)==null||Ze.call(R,{reason:et,lastSeq:He,lastCheckpointId:ze,lastCheckpointNs:qe,lastStateHistory:Qe,error:L})}catch(st){console.warn("[use-chat] onClosed callback failed",st)}l(!1),w(!1),S.current=null,T.current=0,x(0),C.current=null}})(),{close:()=>Y.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var _;k.current=!1,(_=S.current)==null||_.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:y,connected:g,stream:F,stop:$,clear:P,setToken:A}}function Bg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Hg(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 Ug(e){return e.type!=="token"}const Wg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Vg(e,t){var n;switch(t.type){case"reset":return{messages:pi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=pi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??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),o}case"prepend":{const r=pi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 nc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>nc(o,s),e):e}case"interrupt_response":return{...e,messages:rc(e.messages),pendingInterrupt:null};default:return e}}function tc(e=[]){const[t,n]=b.useReducer(Vg,{...Wg,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.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=b.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]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.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:l}),[l]);return{state:t,dispatch:n,...c}}function nc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Yg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??oc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:ac(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:m,newMeta:y,changed:x}=Kg(d.content,t.delta,h,p);if(!x)return e;const g={...d,content:m},w=Ro(l,c,g),S={...f,[a]:y};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??oc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=sc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=ic(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,y=d[0]??p,x={type:"tool_call",id:y,name:c,args:t.args};if(h){const S=gi(h,d,c,t.args),k={...h,name:h.name??c,additionalKwargs:S},T=f,C=T>=0?Ro(e.messages,T,k):e.messages,E=Po(k,d),N=xi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:N}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[x],additionalKwargs:gi(void 0,d.length?d:[y],c,t.args)},w=Po(g,d.length?d:[y]);return{...e,messages:[...e.messages,g],toolIndex:xi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=sc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=ic(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",h=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(d==null?void 0:d.id)??`tool-${h}`,m=Po(d,a);let y=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(y=JSON.parse(C))}catch{y=t.output}const x={type:"text",text:typeof y=="string"?y:JSON.stringify(y)},g=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=gi(d??void 0,m.length?m:a,f),S={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[x],createdAt:g,additionalKwargs:w},k=c>=0?Ro(e.messages,c,S):[...e.messages,S],T=Po(S,a.length?a:m);return{...e,messages:k,toolIndex:xi(e.toolIndex,p,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Gg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=Fr(t),l=a.interrupt,c=a.latest,d=l===null?rc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function pi(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 Ro(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function rc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function oc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function sc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function mi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function gi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=mi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Po(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=mi(e);for(const o of r)n.add(o);return Array.from(n)}function xi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function ic(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(mi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function ac(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Kg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??ac(e);let l="",c=e.slice();if(s){const f=qg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function lc(e){return e.replace(/\s+/g," ").trim()}function qg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=lc(e),o=lc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Gg(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 Ro(e,r,s)}return e}function Yg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const cc=200;function Xg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),h=b.useRef(null),p=b.useRef(null),m=b.useCallback(A=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(A)}catch{}try{return JSON.parse(JSON.stringify(A))}catch{return A}},[]),y=b.useCallback((A,P)=>{if(!A)return;const $=f.current.get(A)??[],F=m(P),_=$.length>=cc?[...$.slice($.length-cc+1),F]:[...$,F];f.current.set(A,_)},[m]),x=b.useCallback(A=>{A&&f.current.set(A,[])},[]),g=b.useCallback(A=>{const P=A??d.current;if(!P)return;const $=f.current.get(P);$!=null&&$.length&&$.forEach(F=>{try{n(F)}catch(_){console.error("[useChatStreamingService] Failed to replay buffered event",_)}})},[n]),w=b.useCallback(A=>{var F,_,z,R,Y;const P=A.seq??null;if(P!==null){const O=c.current;if(O!==null){if(P<=O)return;P>O+1&&(o==null||o({from:O,to:P}))}c.current=P}if(A.type==="thread_info"){d.current=A.threadId,h.current&&(h.current.threadIdGuess=A.threadId),p.current=A,x(A.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",A);try{t(A)}catch(O){console.error("[useChatStreamingService] Error in onThreadInfo handler:",O)}return}if(A.type==="heartbeat"){try{l==null||l(A)}catch(O){console.error("[useChatStreamingService] Error in onHeartbeat handler:",O)}return}if(A.type==="error"){const O=A;if(O.error_type==="auth_error"||O.code==="TOKEN_EXPIRED"||((F=O.message)==null?void 0:F.includes("token"))||((_=O.message)==null?void 0:_.includes("401"))||((z=O.message)==null?void 0:z.includes("unauthorized"))||((R=O.message)==null?void 0:R.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",O.message);try{a==null||a(O.message)}catch(G){console.warn("[useChatStreamingService] onAuthError handler failed",G)}}}const $=A.threadId??(A.type==="state_history"?A.threadId:void 0)??d.current??((Y=h.current)==null?void 0:Y.threadIdGuess)??null;if(A.type==="state_history"&&(d.current=$??d.current),Ug(A)){A.type==="checkpoint"||A.type==="state_history"?x($??null):y($??null,A);try{n(A)}catch(O){console.error("[useChatStreamingService] Error in onMessageEvent handler:",O)}return}try{r==null||r(A)}catch(O){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",O)}},[y,x,n,o,t,r]),{stream:S,stop:k,isStreaming:T,error:C,setToken:E}=ec({baseUrl:e,token:void 0}),N=b.useCallback((A,P)=>{c.current=null,p.current=null,d.current=A.threadId??null,h.current={request:A,callbacks:P,manualStop:!1,threadIdGuess:A.threadId??null},S(A,w,{onOpen:P==null?void 0:P.onOpen,onError:$=>{var F;(F=P==null?void 0:P.onError)==null||F.call(P,$)},onGap:(P==null?void 0:P.onGap)??o,onConnectionError:$=>{var F;i==null||i($),(F=P==null?void 0:P.onConnectionError)==null||F.call(P,$)},onAuthError:$=>{var F;a==null||a($),(F=P==null?void 0:P.onAuthError)==null||F.call(P,$)},onHeartbeat:$=>{var F;try{l==null||l($)}catch(_){console.warn("[useChatStreamingService] onHeartbeat handler failed",_)}try{(F=P==null?void 0:P.onHeartbeat)==null||F.call(P,$)}catch(_){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",_)}},onClosed:$=>{var R,Y,O,L;const F=((R=h.current)==null?void 0:R.manualStop)??!1,_=d.current??((Y=h.current)==null?void 0:Y.threadIdGuess)??((O=$.lastStateHistory)==null?void 0:O.threadId)??null;($.reason==="complete"||$.reason==="aborted"&&F)&&x(_);const z={...$,threadId:_,threadInfo:p.current,manualStop:F};try{s==null||s(z)}catch(G){console.warn("[useChatStreamingService] onStreamClosed handler failed",G)}try{(L=P==null?void 0:P.onClosed)==null||L.call(P,z)}catch(G){console.warn("[useChatStreamingService] downstream onClosed handler failed",G)}h.current&&(h.current=null)}})},[x,w,a,i,l,o,s,S]),j=b.useCallback(()=>{h.current&&(h.current.manualStop=!0),k()},[k]);return b.useMemo(()=>({startStream:N,stop:j,isStreaming:T,error:C,setAuthToken:E,replayBufferedEvents:g}),[N,j,T,C,E,g])}function Jg(){const e=b.useRef(new Map),t=b.useCallback((a,l)=>{const c=e.current.get(a),d=new Map;c&&c.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),l.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),e.current.set(a,Array.from(d.values()))},[]),n=b.useCallback((a,l)=>{const c=e.current.get(a);return c==null?void 0:c.find(d=>d.checkpointId===l)},[]),r=b.useCallback((a,l)=>{const c=e.current.get(a);return(c==null?void 0:c.some(d=>d.checkpointId===l))??!1},[]),o=b.useCallback(a=>e.current.get(a),[]),s=b.useCallback(a=>{e.current.delete(a)},[]),i=b.useCallback(()=>{e.current.clear()},[]);return{cache:e.current,setCacheForThread:t,getCachedMetadata:n,checkpointExists:r,getThreadMetadata:o,clearThreadCache:s,clearAllCache:i}}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,checkpointMetadataCache:l}){const{api:c,baseUrl:d}=fi(),f=b.useMemo(()=>En(d),[d]),[h,p]=b.useState([]),[m,y]=b.useState(t),[x,g]=b.useState(!1),[w,S]=b.useState(null),[k,T]=b.useState(!1),[C,E]=b.useState(null),{state:N,seed:j,prepend:A,pushUser:P,onEvent:$}=tc(),[F,_]=b.useState(!1),[z,R]=b.useState(!1),[Y,O]=b.useState(null),[L,G]=b.useState([]),[J,he]=b.useState(!1),Ae=l??Jg(),{setCacheForThread:_e}=Ae,H=b.useRef(m),ee=b.useRef(null),K=b.useRef(null);b.useEffect(()=>{H.current=m},[m]);const D=b.useRef(),B=b.useCallback(async()=>{g(!0),S(null);try{const ae=await c.listThreads();p(ae??[])}catch(ae){const me=String(ae);S(me),s==null||s(me)}finally{g(!1)}},[c,s]),te=b.useCallback(ae=>{if(!(ae!=null&&ae.threadId))return;const me={threadId:ae.threadId,title:ae.title||`Thread ${ae.threadId.slice(0,8)}`,createdAt:ae.createdAt||new Date().toISOString(),updatedAt:ae.updatedAt||new Date().toISOString(),messageCount:ae.messageCount??1};p($e=>$e.some(we=>we.threadId===me.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",me.threadId),$e):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",me.threadId),[me,...$e]))},[]),ie=b.useCallback(ae=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",ae.threadId),te(ae),H.current!==ae.threadId&&(!H.current&&N.messages.length<=1&&(K.current=ae.threadId),y(ae.threadId))},[te,N.messages.length]),{startStream:ne,stop:Le,isStreaming:Q,error:pe,setAuthToken:Ne}=Xg({baseUrl:f,onThreadInfo:ie,onMessageEvent:$,onUnhandledEvent:ae=>{console.warn("[ChatSessionProvider] Unhandled event:",ae.type)},onAuthError:i}),Re=b.useCallback(async ae=>{try{const me=await c.createThread(ae);return y(me.threadId),await B(),me.threadId}catch(me){return s==null||s(String(me)),null}},[c,B,s]),Ke=b.useCallback(async ae=>{try{await c.deleteThread(ae),H.current===ae&&(y(null),j([],{})),await B()}catch(me){s==null||s(String(me))}},[c,B,j,s]),Ze=b.useCallback(async(ae,me)=>{try{await c.updateThread(ae,me),await B()}catch($e){s==null||s(String($e))}},[c,B,s]),He=b.useCallback((ae,me,$e)=>{const ke=me.filter(we=>we.checkpointId).map(we=>({checkpointId:we.checkpointId,checkpointNs:we.checkpointNs??void 0,createdAt:we.createdAt??""}));console.log(`[ChatSessionProvider] Cached metadata for ${ke.length} checkpoints from ${$e}`),_e(ae,ke)},[_e]),ze=b.useCallback(async(ae,me)=>{if(!ae)return;const $e=ae;T(!0),E(null);try{const ke=await c.getStateHistory({threadId:$e,checkpointId:me||void 0});if(H.current!==$e){console.log(`[ChatSessionProvider] Thread changed during load (was ${$e}, now ${H.current}), discarding stale data`);return}const{checkpoints:we}=Fr(ke);He($e,we,`thread load (requested: ${me})`);const fe=we.find(tt=>tt.messages&&tt.messages.length>0)??(me?we.find(tt=>tt.checkpointId===me):null)??we[0];j((fe==null?void 0:fe.messages)??[],{checkpointId:(fe==null?void 0:fe.checkpointId)??null,checkpointNs:(fe==null?void 0:fe.checkpointNs)??null}),G(we),_(!!(fe!=null&&fe.nextCursor)),O((fe==null?void 0:fe.nextCursor)??null)}catch(ke){if(H.current===$e){const we=String(ke);E(we),s==null||s(we)}}finally{T(!1)}},[c,j,s,He]);b.useEffect(()=>{D.current=ze},[ze]);const qe=b.useCallback(async(ae,me)=>{const $e=H.current;if(!$e)return;const ke=$e;he(!0);try{const we=await c.getStateHistory({threadId:ke,checkpointId:ae,checkpointNs:me??void 0});if(H.current!==ke){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${ke}, now ${H.current}), discarding stale data`);return}const{checkpoints:fe}=Fr(we);He(ke,fe,"checkpoint navigation");const tt=fe.find(yt=>yt.checkpointId===ae&&(me?yt.checkpointNs===me:!0));if(!tt){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:ae,checkpointNs:me});return}G(fe),j(tt.messages??[],{checkpointId:tt.checkpointId??null,checkpointNs:tt.checkpointNs??null})}catch(we){H.current===ke&&(s==null||s(String(we)))}finally{he(!1)}},[c,j,s,He]),Qe=b.useCallback((ae,me)=>{j(N.messages,{checkpointId:ae??null,checkpointNs:me??null})},[j,N.messages]),et=b.useCallback(async()=>{H.current&&await ze(H.current)},[ze]),st=b.useCallback(async()=>{if(!H.current||!Y)return;const ae=H.current;R(!0);try{const me=await c.getStateHistory({threadId:ae,checkpointId:Y});if(H.current!==ae){console.log(`[ChatSessionProvider] Thread changed during history load (was ${ae}, now ${H.current}), discarding stale data`);return}const{checkpoints:$e}=Fr(me);if($e.length>0){const ke=$e[$e.length-1];A((ke==null?void 0:ke.messages)??[]),_(!!(ke!=null&&ke.nextCursor)),O((ke==null?void 0:ke.nextCursor)??null)}}catch(me){H.current===ae&&(s==null||s(String(me)))}finally{R(!1)}},[c,Y,A,s]),Tt=b.useCallback(async()=>{j([],{}),y(null),Le(),G([]),_(!1),O(null),T(!1),he(!1),R(!1),E(null)},[j,Le]),ft=b.useCallback(async(ae,me,$e)=>{const ke=H.current;if(!ke)throw new Error("No active thread to handle interrupt");const we=me?$e??!0:!1;try{const fe={threadId:ke,checkpointId:N.lastCheckpointId??void 0,checkpointNs:N.lastCheckpointNs??void 0,command:{kind:"resume",value:we}};ne(fe)}catch(fe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${ae}:`,fe),fe}},[N.lastCheckpointId,N.lastCheckpointNs,ne]);b.useEffect(()=>{B()},[B]),b.useEffect(()=>{var ae,me;if(!(!o||!m||k)){if(K.current===m){K.current=null;return}ee.current!==m&&(ee.current=m,n?(console.log("[ChatSessionProvider] Loading thread with checkpoint:",n),(ae=D.current)==null||ae.call(D,m,n)):(console.log("[ChatSessionProvider] Loading thread with latest checkpoint"),(me=D.current)==null||me.call(D,m)))}},[o,m,k,n,r]),b.useEffect(()=>{a==null||a(m)},[m,a]);const it=b.useCallback(async(ae,me)=>{let $e=H.current;const ke=(ae==null?void 0:ae.text)??"";if(!$e&&!ke)return;if(!$e&&ke){const U=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);$e=`${U}${be}`,K.current=$e,y($e)}const{contentParts:we}=await Tg(c,(ae==null?void 0:ae.attachments)??[]),fe=[...we];ke!=null&&ke.trim()&&fe.push({type:"text",text:ke});const tt={id:`msg-${Date.now()}`,role:"user",content:fe,createdAt:new Date().toISOString()};P(tt);const yt={threadId:$e,payload:{messages:[tt]},checkpointId:(me==null?void 0:me.checkpointId)??N.lastCheckpointId??void 0,checkpointNs:(me==null?void 0:me.checkpointNs)??N.lastCheckpointNs??void 0};ne(yt)},[c,Re,P,N,ne]),kt=b.useMemo(()=>({threads:h,currentThreadId:m,setCurrentThreadId:y,isLoading:x,error:w,actions:{createThread:Re,deleteThread:Ke,renameThread:Ze,refreshThreads:B}}),[h,m,x,w,Re,Ke,Ze,B]),wt=b.useMemo(()=>({threadId:m,messages:N.messages,interrupt:null,checkpoint:{id:N.lastCheckpointId??null,namespace:N.lastCheckpointNs??null},checkpoints:L,metadata:null,isLoading:k,isHistoryLoading:z,isLoadingCheckpoint:J,error:C,hasMore:F,loadOlder:st,clearState:Tt,navigateToCheckpoint:qe,setCurrentCheckpointId:Qe,returnToLatest:et,loadThread:ze,clearThread:Tt,respondToInterrupt:ft}),[m,N,L,k,z,J,C,F,st,Tt,qe,Qe,et,ze,ft]),Xe=b.useMemo(()=>({isStreaming:Q,error:pe,connectionState:Q?"connected":"idle",submit:it,send:it,stop:Le,setAuthToken:Ne}),[Q,pe,it,Le,Ne]);return u.jsx(uc.Provider,{value:kt,children:u.jsx(dc.Provider,{value:wt,children:u.jsx(fc.Provider,{value:Xe,children:e})})})}function Oo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function hc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Do({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c}){return u.jsx(Sg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c,children:e})})}function Z(...e){return Yp.twMerge(Gp.clsx(e))}const Qg=xo.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"}}),rt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yn.Slot:"button";return u.jsx(i,{className:Z(Qg({variant:t,size:n,className:e})),ref:s,...o})});rt.displayName="Button";const pc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:Z("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}));pc.displayName="Textarea";function mc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const m=i!==void 0,[y,x]=b.useState(e),g=(m?i:y)??"",[w,S]=b.useTransition(),k=b.useRef(null),T=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(x(e??""),C.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const N=b.useCallback((z,{fromUser:R})=>{m||x(z),R&&(a==null||a(z))},[m,a]),j=b.useCallback(async z=>{z&&z.preventDefault();const R=(g??"").trim();if(!R&&!p)return;const Y=++T.current;C.current={id:Y,shouldClear:!0},S(()=>{var O,L,G;try{const J=l(R);J&&typeof J.then=="function"?J.then(()=>{var he,Ae;((he=C.current)==null?void 0:he.id)===Y&&C.current.shouldClear&&(m||(x(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Ae=C.current)==null?void 0:Ae.id)===Y&&(C.current=null)}).catch(()=>{var he;((he=C.current)==null?void 0:he.id)===Y&&(C.current=null)}):(((O=C.current)==null?void 0:O.id)===Y&&C.current.shouldClear&&(m||(x(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((L=C.current)==null?void 0:L.id)===Y&&(C.current=null))}catch{((G=C.current)==null?void 0:G.id)===Y&&(C.current=null)}})},[g,l,p,m,a]),A=b.useCallback(z=>{const R=z.target.value;N(R,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),P=b.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),j()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[j,t,c]),_=`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))]":""} ${h}`;return u.jsx("form",{onSubmit:z=>void j(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(pc,{ref:k,value:g,onChange:A,onKeyDown:P,placeholder:t?"Edit your message...":n,className:_,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(rt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(oe.Square,{size:16})}):u.jsx(rt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!p||w,children:u.jsx(oe.Send,{size:16})})})]})})}const ex=b.memo(mc);function de(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 gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(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():gc(e[o],null)}}}}function We(...e){return v.useCallback(yi(...e),e)}function tx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.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 In(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:h,children:p,...m}=f,y=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,x=v.useMemo(()=>m,Object.values(m));return u.jsx(y.Provider,{value:x,children:p})};c.displayName=s+"Provider";function d(f,h){var y;const p=((y=h==null?void 0:h[e])==null?void 0:y[l])||a,m=v.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,nx(o,...t)]}function nx(...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:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var _t=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||_t;function xr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.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 c=v.useCallback(d=>{var f;if(a){const h=sx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Pe=ix.reduce((e,t)=>{const n=Yn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xc(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function vi(e){const t=e+"CollectionProvider",[n,r]=In(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=y=>{const{scope:x,children:g}=y,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:x,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Yn.createSlot(a),c=b.forwardRef((y,x)=>{const{scope:g,children:w}=y,S=s(a,g),k=We(x,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Yn.createSlot(d),p=b.forwardRef((y,x)=>{const{scope:g,children:w,...S}=y,k=b.useRef(null),T=We(x,k),C=s(d,g);return b.useEffect(()=>(C.itemMap.set(k,{ref:k,...S}),()=>void C.itemMap.delete(k))),u.jsx(h,{[f]:"",ref:T,children:w})});p.displayName=d;function m(y){const x=s(e+"CollectionConsumer",y);return b.useCallback(()=>{const w=x.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(x.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var ax=v.createContext(void 0);function Lo(e){const t=v.useContext(ax);return e||t||"ltr"}function Rt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function lx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var cx="DismissableLayer",wi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),$o=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),m=We(t,E=>f(E)),y=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=y.indexOf(x),w=d?y.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=g,T=px(E=>{const N=E.target,j=[...c.branches].some(A=>A.contains(N));!k||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),C=mx(E=>{const N=E.target;[...c.branches].some(A=>A.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return lx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=yc)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(wi,E),()=>document.removeEventListener(wi,E)},[]),u.jsx(Pe.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:de(e.onFocusCapture,C.onFocusCapture),onBlurCapture:de(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:de(e.onPointerDownCapture,T.onPointerDownCapture)})});$o.displayName=cx;var fx="DismissableLayerBranch",hx=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=We(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Pe.div,{...e,ref:o})});hx.displayName=fx;function px(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(ux,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc(dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wc(){const e=new CustomEvent(wi);document.dispatchEvent(e)}function bc(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?xc(o,s):o.dispatchEvent(s)}var bi=0;function Si(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),bi++,()=>{bi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),bi--}},[])}function Sc(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Ci="focusScope.autoFocusOnMount",Ti="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},gx="FocusScope",Fo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Rt(o),d=Rt(s),f=v.useRef(null),h=We(t,y=>l(y)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let y=function(S){if(p.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:On(f.current,{select:!0})},x=function(S){if(p.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||On(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&On(a)};document.addEventListener("focusin",y),document.addEventListener("focusout",x);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",x),w.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){Ec.add(p);const y=document.activeElement;if(!a.contains(y)){const g=new CustomEvent(Ci,Cc);a.addEventListener(Ci,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(Tc(a)),{select:!0}),document.activeElement===y&&On(a))}return()=>{a.removeEventListener(Ci,c),setTimeout(()=>{const g=new CustomEvent(Ti,Cc);a.addEventListener(Ti,d),a.dispatchEvent(g),g.defaultPrevented||On(y??document.body,{select:!0}),a.removeEventListener(Ti,d),Ec.remove(p)},0)}}},[a,c,d,p]);const m=v.useCallback(y=>{if(!n&&!r||p.paused)return;const x=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,g=document.activeElement;if(x&&g){const w=y.currentTarget,[S,k]=yx(w);S&&k?!y.shiftKey&&g===k?(y.preventDefault(),n&&On(S,{select:!0})):y.shiftKey&&g===S&&(y.preventDefault(),n&&On(k,{select:!0})):g===w&&y.preventDefault()}},[n,r,p.paused]);return u.jsx(Pe.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});Fo.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function kc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var Ec=bx();function bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Nn(e){const[t,n]=v.useState(Cx());return _t(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],Mn=Math.min,Gt=Math.max,zo=Math.round,Bo=Math.floor,xn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ix={start:"end",end:"start"};function ki(e,t,n){return Gt(e,Mn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function yr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ii(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function yn(e){return Nx.has(jn(e))?"y":"x"}function Ni(e){return Ei(yn(e))}function Ax(e,t,n){n===void 0&&(n=!1);const r=yr(e),o=Ni(e),s=Ii(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ho(i)),[i,Ho(i)]}function jx(e){const t=Ho(e);return[Ai(e),t,Ai(t)]}function Ai(e){return e.replace(/start|end/g,t=>Ix[t])}const Nc=["left","right"],Ac=["right","left"],_x=["top","bottom"],Rx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Ac:Nc:t?Nc:Ac;case"left":case"right":return t?_x:Rx;default:return[]}}function Ox(e,t,n,r){const o=yr(e);let s=Px(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ai)))),s}function Ho(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Mx(e){return{top:0,right:0,bottom:0,left:0,...e}}function jc(e){return typeof e!="number"?Mx(e):{top:e,right:e,bottom:e,left:e}}function Uo(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function _c(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Ni(t),a=Ii(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(yr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Dx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_c(c,r,l),h=r,p={},m=0;for(let y=0;y<a.length;y++){const{name:x,fn:g}=a[y],{x:w,y:S,data:k,reset:T}=await g({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,p={...p,[x]:{...p[x],...k}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=_c(c,h,l)),y=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=An(t,e),m=jc(p),x=a[h?f==="floating"?"reference":"floating":f],g=Uo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Uo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-T.top+m.top)/k.y,bottom:(T.bottom-g.bottom+m.bottom)/k.y,left:(g.left-T.left+m.left)/k.x,right:(T.right-g.right+m.right)/k.x}}const Lx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const f=jc(d),h={x:n,y:r},p=Ni(o),m=Ii(p),y=await i.getDimensions(c),x=p==="y",g=x?"top":"left",w=x?"bottom":"right",S=x?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[p]-h[p]-s.floating[m],T=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[m]);const N=k/2-T/2,j=E/2-y[m]/2-1,A=Mn(f[g],j),P=Mn(f[w],j),$=A,F=E-y[m]-P,_=E/2-y[m]/2+N,z=ki($,_,F),R=!l.arrow&&yr(o)!=null&&_!==z&&s.reference[m]/2-(_<$?A:P)-y[m]/2<0,Y=R?_<$?_-$:_-F:0;return{[p]:h[p]+Y,data:{[p]:z,centerOffset:_-z-Y,...R&&{alignmentOffset:Y}},reset:R}}}),$x=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:y=!0,...x}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=jn(o),w=yn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=h||(S||!y?[Ho(a)]:jx(a)),C=m!=="none";!h&&C&&T.push(...Ox(a,y,m,k));const E=[a,...T],N=await Br(t,x),j=[];let A=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(N[g]),f){const _=Ax(o,i,k);j.push(N[_[0]],N[_[1]])}if(A=[...A,{placement:o,overflows:j}],!j.every(_=>_<=0)){var P,$;const _=(((P=s.flip)==null?void 0:P.index)||0)+1,z=E[_];if(z&&(!(f==="alignment"?w!==yn(z):!1)||A.every(O=>yn(O.placement)===w?O.overflows[0]>0:!0)))return{data:{index:_,overflows:A},reset:{placement:z}};let R=($=A.filter(Y=>Y.overflows[0]<=0).sort((Y,O)=>Y.overflows[1]-O.overflows[1])[0])==null?void 0:$.placement;if(!R)switch(p){case"bestFit":{var F;const Y=(F=A.filter(O=>{if(C){const L=yn(O.placement);return L===w||L==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(L=>L>0).reduce((L,G)=>L+G,0)]).sort((O,L)=>O[1]-L[1])[0])==null?void 0:F[0];Y&&(R=Y);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}return{}}}};function Rc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return kx.some(t=>e[t]>=0)}const Fx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=Rc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Rc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Oc=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=yr(n),l=yn(n)==="y",c=Oc.has(i)?-1:1,d=s&&l?-1:1,f=An(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Bx=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await zx(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:x=>{let{x:g,y:w}=x;return{x:g,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await Br(t,l),f=yn(jn(o)),h=Ei(f);let p=c[h],m=c[f];if(s){const x=h==="y"?"top":"left",g=h==="y"?"bottom":"right",w=p+d[x],S=p-d[g];p=ki(w,p,S)}if(i){const x=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+d[x],S=m-d[g];m=ki(w,m,S)}const y=a.fn({...t,[h]:p,[f]:m});return{...y,data:{x:y.x-n,y:y.y-r,enabled:{[h]:s,[f]:i}}}}}},Ux=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},f=yn(o),h=Ei(f);let p=d[h],m=d[f];const y=An(a,t),x=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(l){const S=h==="y"?"height":"width",k=s.reference[h]-s.floating[S]+x.mainAxis,T=s.reference[h]+s.reference[S]-x.mainAxis;p<k?p=k:p>T&&(p=T)}if(c){var g,w;const S=h==="y"?"width":"height",k=Oc.has(jn(o)),T=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:x.crossAxis),C=s.reference[f]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[f])||0)-(k?x.crossAxis:0);m<T?m=T:m>C&&(m=C)}return{[h]:p,[f]:m}}}},Wx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await Br(t,c),f=jn(o),h=yr(o),p=yn(o)==="y",{width:m,height:y}=s.floating;let x,g;f==="top"||f==="bottom"?(x=f,g=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,x=h==="end"?"top":"bottom");const w=y-d.top-d.bottom,S=m-d.left-d.right,k=Mn(y-d[x],w),T=Mn(m-d[g],S),C=!t.middlewareData.shift;let E=k,N=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!h){const A=Gt(d.left,0),P=Gt(d.right,0),$=Gt(d.top,0),F=Gt(d.bottom,0);p?N=m-2*(A!==0||P!==0?A+P:Gt(d.left,d.right)):E=y-2*($!==0||F!==0?$+F:Gt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const j=await i.getDimensions(a.floating);return m!==j.width||y!==j.height?{reset:{rects:!0}}:{}}}};function Wo(){return typeof window<"u"}function vr(e){return Mc(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vn(e){var t;return(t=(Mc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mc(e){return Wo()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Wo()?e instanceof Element||e instanceof Yt(e).Element:!1}function wn(e){return Wo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function Dc(e){return!Wo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Hr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(vr(e))}const Gx=[":popover-open",":modal"];function Vo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function ji(e){const t=_i(),n=un(e)?dn(e):e;return Yx.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Dn(e);for(;wn(t)&&!wr(t);){if(ji(t))return t;if(Vo(t))return null;t=Dn(t)}return null}function _i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function wr(e){return Qx.has(vr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Ko(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(vr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||vn(e);return Dc(t)?t.host:t}function Lc(e){const t=Dn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:wn(t)&&Hr(t)?t:Lc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ri(i);return t.concat(i,i.visualViewport||[],Hr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Ri(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $c(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zo(n)!==s||zo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return un(e)?e:e.contextElement}function br(e){const t=Pi(e);if(!wn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=$c(t);let i=(s?zo(n.width):n.width)/r,a=(s?zo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=xn(0);function Fc(e){const t=Yt(e);return!_i()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=xn(1);t&&(r?un(r)&&(i=br(r)):i=br(e));const a=ty(s,n,r)?Fc(s):xn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Yt(s),p=r&&un(r)?Yt(r):r;let m=h,y=Ri(m);for(;y&&r&&p!==m;){const x=br(y),g=y.getBoundingClientRect(),w=dn(y),S=g.left+(y.clientLeft+parseFloat(w.paddingLeft))*x.x,k=g.top+(y.clientTop+parseFloat(w.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,f*=x.y,l+=S,c+=k,m=Yt(y),y=Ri(m)}}return Uo({width:d,height:f,x:l,y:c})}function qo(e,t){const n=Ko(e).scrollLeft;return t?t.left+n:Qn(vn(e)).left+n}function zc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=vn(r),a=t?Vo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=xn(1);const d=xn(0),f=wn(r);if((f||!f&&!s)&&((vr(r)!=="body"||Hr(i))&&(l=Ko(r)),wn(r))){const p=Qn(r);c=br(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?zc(i,l):xn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function ry(e){return Array.from(e.getClientRects())}function oy(e){const t=vn(e),n=Ko(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qo(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bc=25;function sy(e,t){const n=Yt(e),r=vn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=_i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qo(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=Bc&&(s-=m)}else c<=Bc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=wn(e)?br(e):xn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Hc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(vn(e));else if(un(t))r=ay(t,n);else{const o=Fc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Uo(r)}function Uc(e,t){const n=Dn(e);return n===t||!un(n)||wr(n)?!1:dn(n).position==="fixed"||Uc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>un(a)&&vr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Dn(e):e;for(;un(i)&&!wr(i);){const a=dn(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Hr(i)&&!l&&Uc(e,i))?r=r.filter(d=>d!==i):o=a,i=Dn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hc(t,d,o);return c.top=Gt(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},Hc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=$c(e);return{width:t,height:n}}function dy(e,t,n){const r=wn(t),o=vn(t),s=n==="fixed",i=Qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function c(){l.x=qo(o)}if(r||!r&&!s)if((vr(t)!=="body"||Hr(o))&&(a=Ko(t)),r){const p=Qn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?zc(o,a):xn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Oi(e){return dn(e).position==="static"}function Wc(e,t){if(!wn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return vn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Yt(e);if(Vo(e))return n;if(!wn(e)){let o=Dn(e);for(;o&&!wr(o);){if(un(o)&&!Oi(o))return o;o=Dn(o)}return n}let r=Wc(e,t);for(;r&&qx(r)&&Oi(r);)r=Wc(r,t);return r&&wr(r)&&Oi(r)&&!ji(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function hy(e){return dn(e).direction==="rtl"}const py={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:vn,getClippingRect:cy,getOffsetParent:Vc,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:br,isElement:un,isRTL:hy};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=vn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=Bo(f),y=Bo(o.clientWidth-(d+h)),x=Bo(o.clientHeight-(f+p)),g=Bo(d),S={rootMargin:-m+"px "+-y+"px "+-x+"px "+-g+"px",threshold:Gt(0,Mn(1,l))||1};let k=!0;function T(C){const E=C[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(g=>{let[w]=g;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,y=l?Qn(e):null;l&&x();function x(){const g=Qn(e);y&&!Kc(y,g)&&n(),y=g,m=requestAnimationFrame(x)}return n(),()=>{var g;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=p)==null||g.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const xy=Bx,yy=Hx,vy=$x,wy=Wx,by=Fx,qc=Lx,Sy=Ux,Cy=(e,t,n)=>{const r=new Map,o={platform:py,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Go=Ty?b.useLayoutEffect:ky;function Yo(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Yo(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Yo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Go(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=v.useState(r);Yo(h,r)||p(r);const[m,y]=v.useState(null),[x,g]=v.useState(null),w=v.useCallback(O=>{O!==C.current&&(C.current=O,y(O))},[]),S=v.useCallback(O=>{O!==E.current&&(E.current=O,g(O))},[]),k=s||m,T=i||x,C=v.useRef(null),E=v.useRef(null),N=v.useRef(d),j=l!=null,A=Mi(l),P=Mi(o),$=Mi(c),F=v.useCallback(()=>{if(!C.current||!E.current)return;const O={placement:t,strategy:n,middleware:h};P.current&&(O.platform=P.current),Cy(C.current,E.current,O).then(L=>{const G={...L,isPositioned:$.current!==!1};_.current&&!Yo(N.current,G)&&(N.current=G,yo.flushSync(()=>{f(G)}))})},[h,t,n,P,$]);Go(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(O=>({...O,isPositioned:!1})))},[c]);const _=v.useRef(!1);Go(()=>(_.current=!0,()=>{_.current=!1}),[]),Go(()=>{if(k&&(C.current=k),T&&(E.current=T),k&&T){if(A.current)return A.current(k,T,F);F()}},[k,T,F,A,j]);const z=v.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),R=v.useMemo(()=>({reference:k,floating:T}),[k,T]),Y=v.useMemo(()=>{const O={position:n,left:0,top:0};if(!R.floating)return O;const L=Yc(R.floating,d.x),G=Yc(R.floating,d.y);return a?{...O,transform:"translate("+L+"px, "+G+"px)",...Gc(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:L,top:G}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:z,elements:R,floatingStyles:Y}),[d,F,z,R,Y])}const Iy=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...Sy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...by(e),options:[e,t]}),Oy=(e,t)=>({...Iy(e),options:[e,t]});var My="Arrow",Xc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Pe.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Xc.displayName=My;var Dy=Xc;function Jc(e){const[t,n]=v.useState(void 0);return _t(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Di="Popper",[Zc,Xo]=In(Di),[Ly,Qc]=Zc(Di),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Di;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=We(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Pe.div,{...o,ref:a})});nu.displayName=tu;var Li="PopperContent",[$y,Fy]=Zc(Li),ru=v.forwardRef((e,t)=>{var K,D,B,te,ie,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...y}=e,x=Qc(Li,n),[g,w]=v.useState(null),S=We(t,Le=>w(Le)),[k,T]=v.useState(null),C=Jc(k),E=(C==null?void 0:C.width)??0,N=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),A=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],$=P.length>0,F={padding:A,boundary:P.filter(By),altBoundary:$},{refs:_,floatingStyles:z,placement:R,isPositioned:Y,middlewareData:O}=Ey({strategy:"fixed",placement:j,whileElementsMounted:(...Le)=>gy(...Le,{animationFrame:p==="always"}),elements:{reference:x.anchor},middleware:[Ny({mainAxis:o+N,alignmentAxis:i}),l&&Ay({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...F}),l&&_y({...F}),Ry({...F,apply:({elements:Le,rects:Q,availableWidth:pe,availableHeight:Ne})=>{const{width:Re,height:Ke}=Q.reference,Ze=Le.floating.style;Ze.setProperty("--radix-popper-available-width",`${pe}px`),Ze.setProperty("--radix-popper-available-height",`${Ne}px`),Ze.setProperty("--radix-popper-anchor-width",`${Re}px`),Ze.setProperty("--radix-popper-anchor-height",`${Ke}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:E,arrowHeight:N}),h&&Py({strategy:"referenceHidden",...F})]}),[L,G]=iu(R),J=Rt(m);_t(()=>{Y&&(J==null||J())},[Y,J]);const he=(K=O.arrow)==null?void 0:K.x,Ae=(D=O.arrow)==null?void 0:D.y,_e=((B=O.arrow)==null?void 0:B.centerOffset)!==0,[H,ee]=v.useState();return _t(()=>{g&&ee(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:_.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:Y?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:H,"--radix-popper-transform-origin":[(te=O.transformOrigin)==null?void 0:te.x,(ie=O.transformOrigin)==null?void 0:ie.y].join(" "),...((ne=O.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx($y,{scope:n,placedSide:L,onArrowChange:T,arrowX:he,arrowY:Ae,shouldHideArrow:_e,children:u.jsx(Pe.div,{"data-side":L,"data-align":G,...y,ref:S,style:{...y.style,animation:Y?void 0:"none"}})})})});ru.displayName=Li;var ou="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Fy(ou,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function By(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var x,g,w;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",y="";return c==="bottom"?(m=i?f:`${h}px`,y=`${-l}px`):c==="top"?(m=i?f:`${h}px`,y=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,y=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,y=i?f:`${p}px`),{data:{x:m,y}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,Uy="Portal",Jo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);_t(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Pe.div,{...r,ref:t}),i):null});Jo.displayName=Uy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var tn=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=We(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};tn.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Zo(r.current);s.current=a==="mounted"?c:"none"},[a]),_t(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Zo(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),_t(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const y=Zo(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&y&&(l("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},h=p=>{p.target===t&&(s.current=Zo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Zo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(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 $i="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Wr="RovingFocusGroup",[Fi,du,Gy]=vi(Wr),[Yy,fu]=In(Wr,[Gy]),[Xy,Jy]=Yy(Wr),hu=v.forwardRef((e,t)=>u.jsx(Fi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Fi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));hu.displayName=Wr;var Zy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=v.useRef(null),p=We(t,h),m=Lo(s),[y,x]=xr({prop:i,defaultProp:a??null,onChange:l,caller:Wr}),[g,w]=v.useState(!1),S=Rt(c),k=du(n),T=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const N=h.current;if(N)return N.addEventListener($i,S),()=>N.removeEventListener($i,S)},[S]),u.jsx(Xy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:y,onItemFocus:v.useCallback(N=>x(N),[x]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:v.useCallback(()=>E(N=>N-1),[]),children:u.jsx(Pe.div,{tabIndex:g||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:de(e.onMouseDown,()=>{T.current=!0}),onFocus:de(e.onFocus,N=>{const j=!T.current;if(N.target===N.currentTarget&&j&&!g){const A=new CustomEvent($i,qy);if(N.currentTarget.dispatchEvent(A),!A.defaultPrevented){const P=k().filter(R=>R.focusable),$=P.find(R=>R.active),F=P.find(R=>R.id===y),z=[$,F,...P].filter(Boolean).map(R=>R.ref.current);gu(z,d)}}T.current=!1}),onBlur:de(e.onBlur,()=>w(!1))})})}),pu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Nn(),c=s||l,d=Jy(pu,n),f=d.currentTabStopId===c,h=du(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:y}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Fi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Pe.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:de(e.onMouseDown,x=>{r?d.onItemFocus(c):x.preventDefault()}),onFocus:de(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){d.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const g=tv(x,d.orientation,d.dir);if(g!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let S=h().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(x.currentTarget);S=d.loop?nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:y!=null}):i})})});mu.displayName=pu;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=hu,ov=mu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Sr=new WeakMap,Qo=new WeakMap,es={},zi=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);es[n]||(es[n]=new WeakMap);var s=es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),m=p!==null&&p!=="false",y=(Sr.get(h)||0)+1,x=(s.get(h)||0)+1;Sr.set(h,y),s.set(h,x),i.push(h),y===1&&m&&Qo.set(h,!0),x===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return d(t),a.clear(),zi++,function(){i.forEach(function(f){var h=Sr.get(f)-1,p=s.get(f)-1;Sr.set(f,h),s.set(f,p),h||(Qo.has(f)||f.removeAttribute(r),Qo.delete(f)),p||f.removeAttribute(n)}),zi--,zi||(Sr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,es={})}},Bi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},bn=function(){return bn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},bn.apply(this,arguments)};function yu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function lv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var ts="right-scroll-bar-position",ns="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function hv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}vu.set(n,e)},[e]),n}function pv(e){return e}function mv(e,t){t===void 0&&(t=pv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function gv(e){e===void 0&&(e={});var t=mv(null);return t.options=bn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,bn({},n))};wu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),wu}var bu=gv(),Ui=function(){},rs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ui,onWheelCapture:Ui,onTouchMoveCapture:Ui}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,y=e.inert,x=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=h,C=hv([n,t]),E=bn(bn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(T,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:y,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),bn(bn({},E),{ref:C})):v.createElement(w,bn({},E,{className:l,ref:C}),a))});rs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},rs.classNames={fullWidth:ns,zeroRight:ts};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(wv(t,n),bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},Wi=function(e){return parseInt(e||"",10)||0},kv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Wi(n),Wi(r),Wi(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Iv=Su(),Cr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
38
|
+
`)}function Ug(e){return e.type!=="token"}const Wg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Vg(e,t){var n;switch(t.type){case"reset":return{messages:pi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=pi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??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),o}case"prepend":{const r=pi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 nc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>nc(o,s),e):e}case"interrupt_response":return{...e,messages:rc(e.messages),pendingInterrupt:null};default:return e}}function tc(e=[]){const[t,n]=b.useReducer(Vg,{...Wg,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.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=b.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]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.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:l}),[l]);return{state:t,dispatch:n,...c}}function nc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Yg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??oc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:ac(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:m,newMeta:y,changed:x}=Kg(d.content,t.delta,h,p);if(!x)return e;const g={...d,content:m},w=Ro(l,c,g),S={...f,[a]:y};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??oc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=sc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=ic(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,y=d[0]??p,x={type:"tool_call",id:y,name:c,args:t.args};if(h){const S=gi(h,d,c,t.args),k={...h,name:h.name??c,additionalKwargs:S},T=f,C=T>=0?Ro(e.messages,T,k):e.messages,E=Po(k,d),N=xi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:N}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[x],additionalKwargs:gi(void 0,d.length?d:[y],c,t.args)},w=Po(g,d.length?d:[y]);return{...e,messages:[...e.messages,g],toolIndex:xi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=sc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=ic(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",h=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(d==null?void 0:d.id)??`tool-${h}`,m=Po(d,a);let y=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(y=JSON.parse(C))}catch{y=t.output}const x={type:"text",text:typeof y=="string"?y:JSON.stringify(y)},g=(d==null?void 0:d.createdAt)??new Date().toISOString(),w=gi(d??void 0,m.length?m:a,f),S={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[x],createdAt:g,additionalKwargs:w},k=c>=0?Ro(e.messages,c,S):[...e.messages,S],T=Po(S,a.length?a:m);return{...e,messages:k,toolIndex:xi(e.toolIndex,p,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Gg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=Fr(t),l=a.interrupt,c=a.latest,d=l===null?rc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function pi(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 Ro(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function rc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function oc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function sc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function mi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function gi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=mi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Po(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=mi(e);for(const o of r)n.add(o);return Array.from(n)}function xi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function ic(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(mi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function ac(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Kg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??ac(e);let l="",c=e.slice();if(s){const f=qg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function lc(e){return e.replace(/\s+/g," ").trim()}function qg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=lc(e),o=lc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Gg(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 Ro(e,r,s)}return e}function Yg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const cc=200;function Xg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=b.useRef(null),d=b.useRef(null),f=b.useRef(new Map),h=b.useRef(null),p=b.useRef(null),m=b.useCallback(A=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(A)}catch{}try{return JSON.parse(JSON.stringify(A))}catch{return A}},[]),y=b.useCallback((A,P)=>{if(!A)return;const $=f.current.get(A)??[],F=m(P),_=$.length>=cc?[...$.slice($.length-cc+1),F]:[...$,F];f.current.set(A,_)},[m]),x=b.useCallback(A=>{A&&f.current.set(A,[])},[]),g=b.useCallback(A=>{const P=A??d.current;if(!P)return;const $=f.current.get(P);$!=null&&$.length&&$.forEach(F=>{try{n(F)}catch(_){console.error("[useChatStreamingService] Failed to replay buffered event",_)}})},[n]),w=b.useCallback(A=>{var F,_,z,R,Y;const P=A.seq??null;if(P!==null){const O=c.current;if(O!==null){if(P<=O)return;P>O+1&&(o==null||o({from:O,to:P}))}c.current=P}if(A.type==="thread_info"){d.current=A.threadId,h.current&&(h.current.threadIdGuess=A.threadId),p.current=A,x(A.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",A);try{t(A)}catch(O){console.error("[useChatStreamingService] Error in onThreadInfo handler:",O)}return}if(A.type==="heartbeat"){try{l==null||l(A)}catch(O){console.error("[useChatStreamingService] Error in onHeartbeat handler:",O)}return}if(A.type==="error"){const O=A;if(O.error_type==="auth_error"||O.code==="TOKEN_EXPIRED"||((F=O.message)==null?void 0:F.includes("token"))||((_=O.message)==null?void 0:_.includes("401"))||((z=O.message)==null?void 0:z.includes("unauthorized"))||((R=O.message)==null?void 0:R.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",O.message);try{a==null||a(O.message)}catch(G){console.warn("[useChatStreamingService] onAuthError handler failed",G)}}}const $=A.threadId??(A.type==="state_history"?A.threadId:void 0)??d.current??((Y=h.current)==null?void 0:Y.threadIdGuess)??null;if(A.type==="state_history"&&(d.current=$??d.current),Ug(A)){A.type==="checkpoint"||A.type==="state_history"?x($??null):y($??null,A);try{n(A)}catch(O){console.error("[useChatStreamingService] Error in onMessageEvent handler:",O)}return}try{r==null||r(A)}catch(O){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",O)}},[y,x,n,o,t,r]),{stream:S,stop:k,isStreaming:T,error:C,setToken:E}=ec({baseUrl:e,token:void 0}),N=b.useCallback((A,P)=>{c.current=null,p.current=null,d.current=A.threadId??null,h.current={request:A,callbacks:P,manualStop:!1,threadIdGuess:A.threadId??null},S(A,w,{onOpen:P==null?void 0:P.onOpen,onError:$=>{var F;(F=P==null?void 0:P.onError)==null||F.call(P,$)},onGap:(P==null?void 0:P.onGap)??o,onConnectionError:$=>{var F;i==null||i($),(F=P==null?void 0:P.onConnectionError)==null||F.call(P,$)},onAuthError:$=>{var F;a==null||a($),(F=P==null?void 0:P.onAuthError)==null||F.call(P,$)},onHeartbeat:$=>{var F;try{l==null||l($)}catch(_){console.warn("[useChatStreamingService] onHeartbeat handler failed",_)}try{(F=P==null?void 0:P.onHeartbeat)==null||F.call(P,$)}catch(_){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",_)}},onClosed:$=>{var R,Y,O,L;const F=((R=h.current)==null?void 0:R.manualStop)??!1,_=d.current??((Y=h.current)==null?void 0:Y.threadIdGuess)??((O=$.lastStateHistory)==null?void 0:O.threadId)??null;($.reason==="complete"||$.reason==="aborted"&&F)&&x(_);const z={...$,threadId:_,threadInfo:p.current,manualStop:F};try{s==null||s(z)}catch(G){console.warn("[useChatStreamingService] onStreamClosed handler failed",G)}try{(L=P==null?void 0:P.onClosed)==null||L.call(P,z)}catch(G){console.warn("[useChatStreamingService] downstream onClosed handler failed",G)}h.current&&(h.current=null)}})},[x,w,a,i,l,o,s,S]),j=b.useCallback(()=>{h.current&&(h.current.manualStop=!0),k()},[k]);return b.useMemo(()=>({startStream:N,stop:j,isStreaming:T,error:C,setAuthToken:E,replayBufferedEvents:g}),[N,j,T,C,E,g])}function Jg(){const e=b.useRef(new Map),t=b.useCallback((a,l)=>{const c=e.current.get(a),d=new Map;c&&c.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),l.forEach(f=>{d.set(`${f.checkpointId}::${f.checkpointNs}`,f)}),e.current.set(a,Array.from(d.values()))},[]),n=b.useCallback((a,l)=>{const c=e.current.get(a);return c==null?void 0:c.find(d=>d.checkpointId===l)},[]),r=b.useCallback((a,l)=>{const c=e.current.get(a);return(c==null?void 0:c.some(d=>d.checkpointId===l))??!1},[]),o=b.useCallback(a=>e.current.get(a),[]),s=b.useCallback(a=>{e.current.delete(a)},[]),i=b.useCallback(()=>{e.current.clear()},[]);return{cache:e.current,setCacheForThread:t,getCachedMetadata:n,checkpointExists:r,getThreadMetadata:o,clearThreadCache:s,clearAllCache:i}}const uc=b.createContext(null),dc=b.createContext(null),fc=b.createContext(null);b.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,checkpointMetadataCache:l}){const{api:c,baseUrl:d}=fi(),f=b.useMemo(()=>En(d),[d]),[h,p]=b.useState([]),[m,y]=b.useState(t),[x,g]=b.useState(!1),[w,S]=b.useState(null),[k,T]=b.useState(!1),[C,E]=b.useState(null),{state:N,seed:j,prepend:A,pushUser:P,onEvent:$}=tc(),[F,_]=b.useState(!1),[z,R]=b.useState(!1),[Y,O]=b.useState(null),[L,G]=b.useState([]),[J,he]=b.useState(!1),Ae=l??Jg(),{setCacheForThread:_e}=Ae,H=b.useRef(m),ee=b.useRef(null),K=b.useRef(null);b.useEffect(()=>{H.current=m},[m]);const D=b.useRef(),B=b.useCallback(async()=>{g(!0),S(null);try{const ae=await c.listThreads();p(ae??[])}catch(ae){const me=String(ae);S(me),s==null||s(me)}finally{g(!1)}},[c,s]),te=b.useCallback(ae=>{if(!(ae!=null&&ae.threadId))return;const me={threadId:ae.threadId,title:ae.title||`Thread ${ae.threadId.slice(0,8)}`,createdAt:ae.createdAt||new Date().toISOString(),updatedAt:ae.updatedAt||new Date().toISOString(),messageCount:ae.messageCount??1};p($e=>$e.some(we=>we.threadId===me.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",me.threadId),$e):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",me.threadId),[me,...$e]))},[]),ie=b.useCallback(ae=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",ae.threadId),te(ae),H.current!==ae.threadId&&(!H.current&&N.messages.length<=1&&(K.current=ae.threadId),y(ae.threadId))},[te,N.messages.length]),{startStream:ne,stop:Le,isStreaming:Q,error:pe,setAuthToken:Ne}=Xg({baseUrl:f,onThreadInfo:ie,onMessageEvent:$,onUnhandledEvent:ae=>{console.warn("[ChatSessionProvider] Unhandled event:",ae.type)},onAuthError:i}),Re=b.useCallback(async ae=>{try{const me=await c.createThread(ae);return y(me.threadId),await B(),me.threadId}catch(me){return s==null||s(String(me)),null}},[c,B,s]),Ke=b.useCallback(async ae=>{try{await c.deleteThread(ae),H.current===ae&&(y(null),j([],{})),await B()}catch(me){s==null||s(String(me))}},[c,B,j,s]),Ze=b.useCallback(async(ae,me)=>{try{await c.updateThread(ae,me),await B()}catch($e){s==null||s(String($e))}},[c,B,s]),He=b.useCallback((ae,me,$e)=>{const ke=me.filter(we=>we.checkpointId).map(we=>({checkpointId:we.checkpointId,checkpointNs:we.checkpointNs??void 0,createdAt:we.createdAt??""}));console.log(`[ChatSessionProvider] Cached metadata for ${ke.length} checkpoints from ${$e}`),_e(ae,ke)},[_e]),ze=b.useCallback(async(ae,me)=>{if(!ae)return;const $e=ae;T(!0),E(null);try{const ke=await c.getStateHistory({threadId:$e,checkpointId:me||void 0});if(H.current!==$e){console.log(`[ChatSessionProvider] Thread changed during load (was ${$e}, now ${H.current}), discarding stale data`);return}const{checkpoints:we}=Fr(ke);He($e,we,`thread load (requested: ${me})`);const fe=we.find(tt=>tt.messages&&tt.messages.length>0)??(me?we.find(tt=>tt.checkpointId===me):null)??we[0];j((fe==null?void 0:fe.messages)??[],{checkpointId:(fe==null?void 0:fe.checkpointId)??null,checkpointNs:(fe==null?void 0:fe.checkpointNs)??null}),G(we),_(!!(fe!=null&&fe.nextCursor)),O((fe==null?void 0:fe.nextCursor)??null)}catch(ke){if(H.current===$e){const we=String(ke);E(we),s==null||s(we)}}finally{T(!1)}},[c,j,s,He]);b.useEffect(()=>{D.current=ze},[ze]);const qe=b.useCallback(async(ae,me)=>{const $e=H.current;if(!$e)return;const ke=$e;he(!0);try{const we=await c.getStateHistory({threadId:ke,checkpointId:ae,checkpointNs:me??void 0});if(H.current!==ke){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${ke}, now ${H.current}), discarding stale data`);return}const{checkpoints:fe}=Fr(we);He(ke,fe,"checkpoint navigation");const tt=fe.find(yt=>yt.checkpointId===ae&&(me?yt.checkpointNs===me:!0));if(!tt){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:ae,checkpointNs:me});return}G(fe),j(tt.messages??[],{checkpointId:tt.checkpointId??null,checkpointNs:tt.checkpointNs??null})}catch(we){H.current===ke&&(s==null||s(String(we)))}finally{he(!1)}},[c,j,s,He]),Qe=b.useCallback((ae,me)=>{j(N.messages,{checkpointId:ae??null,checkpointNs:me??null})},[j,N.messages]),et=b.useCallback(async()=>{H.current&&await ze(H.current)},[ze]),st=b.useCallback(async()=>{if(!H.current||!Y)return;const ae=H.current;R(!0);try{const me=await c.getStateHistory({threadId:ae,checkpointId:Y});if(H.current!==ae){console.log(`[ChatSessionProvider] Thread changed during history load (was ${ae}, now ${H.current}), discarding stale data`);return}const{checkpoints:$e}=Fr(me);if($e.length>0){const ke=$e[$e.length-1];A((ke==null?void 0:ke.messages)??[]),_(!!(ke!=null&&ke.nextCursor)),O((ke==null?void 0:ke.nextCursor)??null)}}catch(me){H.current===ae&&(s==null||s(String(me)))}finally{R(!1)}},[c,Y,A,s]),Tt=b.useCallback(async()=>{j([],{}),y(null),Le(),G([]),_(!1),O(null),T(!1),he(!1),R(!1),E(null),await c.getAgent("default")},[j,Le]),ft=b.useCallback(async(ae,me,$e)=>{const ke=H.current;if(!ke)throw new Error("No active thread to handle interrupt");const we=me?$e??!0:!1;try{const fe={threadId:ke,checkpointId:N.lastCheckpointId??void 0,checkpointNs:N.lastCheckpointNs??void 0,command:{kind:"resume",value:we}};ne(fe)}catch(fe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${ae}:`,fe),fe}},[N.lastCheckpointId,N.lastCheckpointNs,ne]);b.useEffect(()=>{B()},[B]),b.useEffect(()=>{var ae,me;if(!(!o||!m||k)){if(K.current===m){K.current=null;return}ee.current!==m&&(ee.current=m,n?(console.log("[ChatSessionProvider] Loading thread with checkpoint:",n),(ae=D.current)==null||ae.call(D,m,n)):(console.log("[ChatSessionProvider] Loading thread with latest checkpoint"),(me=D.current)==null||me.call(D,m)))}},[o,m,k,n,r]),b.useEffect(()=>{a==null||a(m)},[m,a]);const it=b.useCallback(async(ae,me)=>{let $e=H.current;const ke=(ae==null?void 0:ae.text)??"";if(!$e&&!ke)return;if(!$e&&ke){const U=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);$e=`${U}${be}`,K.current=$e,y($e)}const{contentParts:we}=await Tg(c,(ae==null?void 0:ae.attachments)??[]),fe=[...we];ke!=null&&ke.trim()&&fe.push({type:"text",text:ke});const tt={id:`msg-${Date.now()}`,role:"user",content:fe,createdAt:new Date().toISOString()};P(tt);const yt={threadId:$e,payload:{messages:[tt]},checkpointId:(me==null?void 0:me.checkpointId)??N.lastCheckpointId??void 0,checkpointNs:(me==null?void 0:me.checkpointNs)??N.lastCheckpointNs??void 0};ne(yt)},[c,Re,P,N,ne]),kt=b.useMemo(()=>({threads:h,currentThreadId:m,setCurrentThreadId:y,isLoading:x,error:w,actions:{createThread:Re,deleteThread:Ke,renameThread:Ze,refreshThreads:B}}),[h,m,x,w,Re,Ke,Ze,B]),wt=b.useMemo(()=>({threadId:m,messages:N.messages,interrupt:null,checkpoint:{id:N.lastCheckpointId??null,namespace:N.lastCheckpointNs??null},checkpoints:L,metadata:null,isLoading:k,isHistoryLoading:z,isLoadingCheckpoint:J,error:C,hasMore:F,loadOlder:st,clearState:Tt,navigateToCheckpoint:qe,setCurrentCheckpointId:Qe,returnToLatest:et,loadThread:ze,clearThread:Tt,respondToInterrupt:ft}),[m,N,L,k,z,J,C,F,st,Tt,qe,Qe,et,ze,ft]),Xe=b.useMemo(()=>({isStreaming:Q,error:pe,connectionState:Q?"connected":"idle",submit:it,send:it,stop:Le,setAuthToken:Ne}),[Q,pe,it,Le,Ne]);return u.jsx(uc.Provider,{value:kt,children:u.jsx(dc.Provider,{value:wt,children:u.jsx(fc.Provider,{value:Xe,children:e})})})}function Oo(){const e=b.useContext(uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){const e=b.useContext(dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function hc(){const e=b.useContext(fc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Do({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c}){return u.jsx(Sg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,checkpointMetadataCache:c,children:e})})}function Z(...e){return Yp.twMerge(Gp.clsx(e))}const Qg=xo.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"}}),rt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yn.Slot:"button";return u.jsx(i,{className:Z(Qg({variant:t,size:n,className:e})),ref:s,...o})});rt.displayName="Button";const pc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:Z("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}));pc.displayName="Textarea";function mc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const m=i!==void 0,[y,x]=b.useState(e),g=(m?i:y)??"",[w,S]=b.useTransition(),k=b.useRef(null),T=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(x(e??""),C.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const N=b.useCallback((z,{fromUser:R})=>{m||x(z),R&&(a==null||a(z))},[m,a]),j=b.useCallback(async z=>{z&&z.preventDefault();const R=(g??"").trim();if(!R&&!p)return;const Y=++T.current;C.current={id:Y,shouldClear:!0},S(()=>{var O,L,G;try{const J=l(R);J&&typeof J.then=="function"?J.then(()=>{var he,Ae;((he=C.current)==null?void 0:he.id)===Y&&C.current.shouldClear&&(m||(x(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((Ae=C.current)==null?void 0:Ae.id)===Y&&(C.current=null)}).catch(()=>{var he;((he=C.current)==null?void 0:he.id)===Y&&(C.current=null)}):(((O=C.current)==null?void 0:O.id)===Y&&C.current.shouldClear&&(m||(x(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((L=C.current)==null?void 0:L.id)===Y&&(C.current=null))}catch{((G=C.current)==null?void 0:G.id)===Y&&(C.current=null)}})},[g,l,p,m,a]),A=b.useCallback(z=>{const R=z.target.value;N(R,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),P=b.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),j()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[j,t,c]),_=`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))]":""} ${h}`;return u.jsx("form",{onSubmit:z=>void j(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(pc,{ref:k,value:g,onChange:A,onKeyDown:P,placeholder:t?"Edit your message...":n,className:_,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(rt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(oe.Square,{size:16})}):u.jsx(rt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!p||w,children:u.jsx(oe.Send,{size:16})})})]})})}const ex=b.memo(mc);function de(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 gc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=gc(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():gc(e[o],null)}}}}function We(...e){return v.useCallback(yi(...e),e)}function tx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.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 In(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:h,children:p,...m}=f,y=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,x=v.useMemo(()=>m,Object.values(m));return u.jsx(y.Provider,{value:x,children:p})};c.displayName=s+"Provider";function d(f,h){var y;const p=((y=h==null?void 0:h[e])==null?void 0:y[l])||a,m=v.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,nx(o,...t)]}function nx(...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:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var _t=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||_t;function xr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.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 c=v.useCallback(d=>{var f;if(a){const h=sx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Pe=ix.reduce((e,t)=>{const n=Yn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xc(e,t){e&&yo.flushSync(()=>e.dispatchEvent(t))}function vi(e){const t=e+"CollectionProvider",[n,r]=In(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=y=>{const{scope:x,children:g}=y,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:x,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Yn.createSlot(a),c=b.forwardRef((y,x)=>{const{scope:g,children:w}=y,S=s(a,g),k=We(x,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Yn.createSlot(d),p=b.forwardRef((y,x)=>{const{scope:g,children:w,...S}=y,k=b.useRef(null),T=We(x,k),C=s(d,g);return b.useEffect(()=>(C.itemMap.set(k,{ref:k,...S}),()=>void C.itemMap.delete(k))),u.jsx(h,{[f]:"",ref:T,children:w})});p.displayName=d;function m(y){const x=s(e+"CollectionConsumer",y);return b.useCallback(()=>{const w=x.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(x.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var ax=v.createContext(void 0);function Lo(e){const t=v.useContext(ax);return e||t||"ltr"}function Rt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function lx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var cx="DismissableLayer",wi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",yc,vc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),$o=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(vc),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),m=We(t,E=>f(E)),y=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=y.indexOf(x),w=d?y.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=g,T=px(E=>{const N=E.target,j=[...c.branches].some(A=>A.contains(N));!k||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),C=mx(E=>{const N=E.target;[...c.branches].some(A=>A.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return lx(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(yc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=yc)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wc())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(wi,E),()=>document.removeEventListener(wi,E)},[]),u.jsx(Pe.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:de(e.onFocusCapture,C.onFocusCapture),onBlurCapture:de(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:de(e.onPointerDownCapture,T.onPointerDownCapture)})});$o.displayName=cx;var fx="DismissableLayerBranch",hx=v.forwardRef((e,t)=>{const n=v.useContext(vc),r=v.useRef(null),o=We(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Pe.div,{...e,ref:o})});hx.displayName=fx;function px(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){bc(ux,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=Rt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&bc(dx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function wc(){const e=new CustomEvent(wi);document.dispatchEvent(e)}function bc(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?xc(o,s):o.dispatchEvent(s)}var bi=0;function Si(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sc()),document.body.insertAdjacentElement("beforeend",e[1]??Sc()),bi++,()=>{bi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),bi--}},[])}function Sc(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Ci="focusScope.autoFocusOnMount",Ti="focusScope.autoFocusOnUnmount",Cc={bubbles:!1,cancelable:!0},gx="FocusScope",Fo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Rt(o),d=Rt(s),f=v.useRef(null),h=We(t,y=>l(y)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let y=function(S){if(p.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:On(f.current,{select:!0})},x=function(S){if(p.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||On(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const T of S)T.removedNodes.length>0&&On(a)};document.addEventListener("focusin",y),document.addEventListener("focusout",x);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",x),w.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){Ec.add(p);const y=document.activeElement;if(!a.contains(y)){const g=new CustomEvent(Ci,Cc);a.addEventListener(Ci,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(Tc(a)),{select:!0}),document.activeElement===y&&On(a))}return()=>{a.removeEventListener(Ci,c),setTimeout(()=>{const g=new CustomEvent(Ti,Cc);a.addEventListener(Ti,d),a.dispatchEvent(g),g.defaultPrevented||On(y??document.body,{select:!0}),a.removeEventListener(Ti,d),Ec.remove(p)},0)}}},[a,c,d,p]);const m=v.useCallback(y=>{if(!n&&!r||p.paused)return;const x=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,g=document.activeElement;if(x&&g){const w=y.currentTarget,[S,k]=yx(w);S&&k?!y.shiftKey&&g===k?(y.preventDefault(),n&&On(S,{select:!0})):y.shiftKey&&g===S&&(y.preventDefault(),n&&On(k,{select:!0})):g===w&&y.preventDefault()}},[n,r,p.paused]);return u.jsx(Pe.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});Fo.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=Tc(e),n=kc(t,e),r=kc(t.reverse(),e);return[n,r]}function Tc(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function kc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function wx(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var Ec=bx();function bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Ic(e,t),e.unshift(t)},remove(t){var n;e=Ic(e,t),(n=e[0])==null||n.resume()}}}function Ic(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Nn(e){const[t,n]=v.useState(Cx());return _t(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],Mn=Math.min,Gt=Math.max,zo=Math.round,Bo=Math.floor,xn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ix={start:"end",end:"start"};function ki(e,t,n){return Gt(e,Mn(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function yr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ii(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function yn(e){return Nx.has(jn(e))?"y":"x"}function Ni(e){return Ei(yn(e))}function Ax(e,t,n){n===void 0&&(n=!1);const r=yr(e),o=Ni(e),s=Ii(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ho(i)),[i,Ho(i)]}function jx(e){const t=Ho(e);return[Ai(e),t,Ai(t)]}function Ai(e){return e.replace(/start|end/g,t=>Ix[t])}const Nc=["left","right"],Ac=["right","left"],_x=["top","bottom"],Rx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Ac:Nc:t?Nc:Ac;case"left":case"right":return t?_x:Rx;default:return[]}}function Ox(e,t,n,r){const o=yr(e);let s=Px(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ai)))),s}function Ho(e){return e.replace(/left|right|bottom|top/g,t=>Ex[t])}function Mx(e){return{top:0,right:0,bottom:0,left:0,...e}}function jc(e){return typeof e!="number"?Mx(e):{top:e,right:e,bottom:e,left:e}}function Uo(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function _c(e,t,n){let{reference:r,floating:o}=e;const s=yn(t),i=Ni(t),a=Ii(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(yr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Dx=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=_c(c,r,l),h=r,p={},m=0;for(let y=0;y<a.length;y++){const{name:x,fn:g}=a[y],{x:w,y:S,data:k,reset:T}=await g({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,p={...p,[x]:{...p[x],...k}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(c=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=_c(c,h,l)),y=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=An(t,e),m=jc(p),x=a[h?f==="floating"?"reference":"floating":f],g=Uo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},T=Uo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-T.top+m.top)/k.y,bottom:(T.bottom-g.bottom+m.bottom)/k.y,left:(g.left-T.left+m.left)/k.x,right:(T.right-g.right+m.right)/k.x}}const Lx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const f=jc(d),h={x:n,y:r},p=Ni(o),m=Ii(p),y=await i.getDimensions(c),x=p==="y",g=x?"top":"left",w=x?"bottom":"right",S=x?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[p]-h[p]-s.floating[m],T=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[m]);const N=k/2-T/2,j=E/2-y[m]/2-1,A=Mn(f[g],j),P=Mn(f[w],j),$=A,F=E-y[m]-P,_=E/2-y[m]/2+N,z=ki($,_,F),R=!l.arrow&&yr(o)!=null&&_!==z&&s.reference[m]/2-(_<$?A:P)-y[m]/2<0,Y=R?_<$?_-$:_-F:0;return{[p]:h[p]+Y,data:{[p]:z,centerOffset:_-z-Y,...R&&{alignmentOffset:Y}},reset:R}}}),$x=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:y=!0,...x}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=jn(o),w=yn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=h||(S||!y?[Ho(a)]:jx(a)),C=m!=="none";!h&&C&&T.push(...Ox(a,y,m,k));const E=[a,...T],N=await Br(t,x),j=[];let A=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(N[g]),f){const _=Ax(o,i,k);j.push(N[_[0]],N[_[1]])}if(A=[...A,{placement:o,overflows:j}],!j.every(_=>_<=0)){var P,$;const _=(((P=s.flip)==null?void 0:P.index)||0)+1,z=E[_];if(z&&(!(f==="alignment"?w!==yn(z):!1)||A.every(O=>yn(O.placement)===w?O.overflows[0]>0:!0)))return{data:{index:_,overflows:A},reset:{placement:z}};let R=($=A.filter(Y=>Y.overflows[0]<=0).sort((Y,O)=>Y.overflows[1]-O.overflows[1])[0])==null?void 0:$.placement;if(!R)switch(p){case"bestFit":{var F;const Y=(F=A.filter(O=>{if(C){const L=yn(O.placement);return L===w||L==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(L=>L>0).reduce((L,G)=>L+G,0)]).sort((O,L)=>O[1]-L[1])[0])==null?void 0:F[0];Y&&(R=Y);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}return{}}}};function Rc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Pc(e){return kx.some(t=>e[t]>=0)}const Fx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=Rc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Pc(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Rc(s,n.floating);return{data:{escapedOffsets:i,escaped:Pc(i)}}}default:return{}}}}},Oc=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=yr(n),l=yn(n)==="y",c=Oc.has(i)?-1:1,d=s&&l?-1:1,f=An(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Bx=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await zx(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:x=>{let{x:g,y:w}=x;return{x:g,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await Br(t,l),f=yn(jn(o)),h=Ei(f);let p=c[h],m=c[f];if(s){const x=h==="y"?"top":"left",g=h==="y"?"bottom":"right",w=p+d[x],S=p-d[g];p=ki(w,p,S)}if(i){const x=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+d[x],S=m-d[g];m=ki(w,m,S)}const y=a.fn({...t,[h]:p,[f]:m});return{...y,data:{x:y.x-n,y:y.y-r,enabled:{[h]:s,[f]:i}}}}}},Ux=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},f=yn(o),h=Ei(f);let p=d[h],m=d[f];const y=An(a,t),x=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(l){const S=h==="y"?"height":"width",k=s.reference[h]-s.floating[S]+x.mainAxis,T=s.reference[h]+s.reference[S]-x.mainAxis;p<k?p=k:p>T&&(p=T)}if(c){var g,w;const S=h==="y"?"width":"height",k=Oc.has(jn(o)),T=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:x.crossAxis),C=s.reference[f]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[f])||0)-(k?x.crossAxis:0);m<T?m=T:m>C&&(m=C)}return{[h]:p,[f]:m}}}},Wx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await Br(t,c),f=jn(o),h=yr(o),p=yn(o)==="y",{width:m,height:y}=s.floating;let x,g;f==="top"||f==="bottom"?(x=f,g=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,x=h==="end"?"top":"bottom");const w=y-d.top-d.bottom,S=m-d.left-d.right,k=Mn(y-d[x],w),T=Mn(m-d[g],S),C=!t.middlewareData.shift;let E=k,N=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!h){const A=Gt(d.left,0),P=Gt(d.right,0),$=Gt(d.top,0),F=Gt(d.bottom,0);p?N=m-2*(A!==0||P!==0?A+P:Gt(d.left,d.right)):E=y-2*($!==0||F!==0?$+F:Gt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const j=await i.getDimensions(a.floating);return m!==j.width||y!==j.height?{reset:{rects:!0}}:{}}}};function Wo(){return typeof window<"u"}function vr(e){return Mc(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function vn(e){var t;return(t=(Mc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Mc(e){return Wo()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Wo()?e instanceof Element||e instanceof Yt(e).Element:!1}function wn(e){return Wo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function Dc(e){return!Wo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Hr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(vr(e))}const Gx=[":popover-open",":modal"];function Vo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function ji(e){const t=_i(),n=un(e)?dn(e):e;return Yx.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Dn(e);for(;wn(t)&&!wr(t);){if(ji(t))return t;if(Vo(t))return null;t=Dn(t)}return null}function _i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function wr(e){return Qx.has(vr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Ko(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(vr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Dc(e)&&e.host||vn(e);return Dc(t)?t.host:t}function Lc(e){const t=Dn(e);return wr(t)?e.ownerDocument?e.ownerDocument.body:e.body:wn(t)&&Hr(t)?t:Lc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Lc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ri(i);return t.concat(i,i.visualViewport||[],Hr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Ri(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function $c(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=wn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zo(n)!==s||zo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return un(e)?e:e.contextElement}function br(e){const t=Pi(e);if(!wn(t))return xn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=$c(t);let i=(s?zo(n.width):n.width)/r,a=(s?zo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=xn(0);function Fc(e){const t=Yt(e);return!_i()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=xn(1);t&&(r?un(r)&&(i=br(r)):i=br(e));const a=ty(s,n,r)?Fc(s):xn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Yt(s),p=r&&un(r)?Yt(r):r;let m=h,y=Ri(m);for(;y&&r&&p!==m;){const x=br(y),g=y.getBoundingClientRect(),w=dn(y),S=g.left+(y.clientLeft+parseFloat(w.paddingLeft))*x.x,k=g.top+(y.clientTop+parseFloat(w.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,f*=x.y,l+=S,c+=k,m=Yt(y),y=Ri(m)}}return Uo({width:d,height:f,x:l,y:c})}function qo(e,t){const n=Ko(e).scrollLeft;return t?t.left+n:Qn(vn(e)).left+n}function zc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=vn(r),a=t?Vo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=xn(1);const d=xn(0),f=wn(r);if((f||!f&&!s)&&((vr(r)!=="body"||Hr(i))&&(l=Ko(r)),wn(r))){const p=Qn(r);c=br(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?zc(i,l):xn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function ry(e){return Array.from(e.getClientRects())}function oy(e){const t=vn(e),n=Ko(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qo(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Bc=25;function sy(e,t){const n=Yt(e),r=vn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=_i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qo(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=Bc&&(s-=m)}else c<=Bc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=wn(e)?br(e):xn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Hc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(vn(e));else if(un(t))r=ay(t,n);else{const o=Fc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Uo(r)}function Uc(e,t){const n=Dn(e);return n===t||!un(n)||wr(n)?!1:dn(n).position==="fixed"||Uc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>un(a)&&vr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Dn(e):e;for(;un(i)&&!wr(i);){const a=dn(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Hr(i)&&!l&&Uc(e,i))?r=r.filter(d=>d!==i):o=a,i=Dn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Hc(t,d,o);return c.top=Gt(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Gt(f.left,c.left),c},Hc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=$c(e);return{width:t,height:n}}function dy(e,t,n){const r=wn(t),o=vn(t),s=n==="fixed",i=Qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=xn(0);function c(){l.x=qo(o)}if(r||!r&&!s)if((vr(t)!=="body"||Hr(o))&&(a=Ko(t)),r){const p=Qn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?zc(o,a):xn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Oi(e){return dn(e).position==="static"}function Wc(e,t){if(!wn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return vn(e)===n&&(n=n.ownerDocument.body),n}function Vc(e,t){const n=Yt(e);if(Vo(e))return n;if(!wn(e)){let o=Dn(e);for(;o&&!wr(o);){if(un(o)&&!Oi(o))return o;o=Dn(o)}return n}let r=Wc(e,t);for(;r&&qx(r)&&Oi(r);)r=Wc(r,t);return r&&wr(r)&&Oi(r)&&!ji(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||Vc,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function hy(e){return dn(e).direction==="rtl"}const py={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:vn,getClippingRect:cy,getOffsetParent:Vc,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:br,isElement:un,isRTL:hy};function Kc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=vn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=Bo(f),y=Bo(o.clientWidth-(d+h)),x=Bo(o.clientHeight-(f+p)),g=Bo(d),S={rootMargin:-m+"px "+-y+"px "+-x+"px "+-g+"px",threshold:Gt(0,Mn(1,l))||1};let k=!0;function T(C){const E=C[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Kc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(T,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,S)}n.observe(e)}return i(!0),s}function gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(g=>{let[w]=g;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,y=l?Qn(e):null;l&&x();function x(){const g=Qn(e);y&&!Kc(y,g)&&n(),y=g,m=requestAnimationFrame(x)}return n(),()=>{var g;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=p)==null||g.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const xy=Bx,yy=Hx,vy=$x,wy=Wx,by=Fx,qc=Lx,Sy=Ux,Cy=(e,t,n)=>{const r=new Map,o={platform:py,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Go=Ty?b.useLayoutEffect:ky;function Yo(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Yo(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Yo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Gc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Yc(e,t){const n=Gc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Go(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=v.useState(r);Yo(h,r)||p(r);const[m,y]=v.useState(null),[x,g]=v.useState(null),w=v.useCallback(O=>{O!==C.current&&(C.current=O,y(O))},[]),S=v.useCallback(O=>{O!==E.current&&(E.current=O,g(O))},[]),k=s||m,T=i||x,C=v.useRef(null),E=v.useRef(null),N=v.useRef(d),j=l!=null,A=Mi(l),P=Mi(o),$=Mi(c),F=v.useCallback(()=>{if(!C.current||!E.current)return;const O={placement:t,strategy:n,middleware:h};P.current&&(O.platform=P.current),Cy(C.current,E.current,O).then(L=>{const G={...L,isPositioned:$.current!==!1};_.current&&!Yo(N.current,G)&&(N.current=G,yo.flushSync(()=>{f(G)}))})},[h,t,n,P,$]);Go(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(O=>({...O,isPositioned:!1})))},[c]);const _=v.useRef(!1);Go(()=>(_.current=!0,()=>{_.current=!1}),[]),Go(()=>{if(k&&(C.current=k),T&&(E.current=T),k&&T){if(A.current)return A.current(k,T,F);F()}},[k,T,F,A,j]);const z=v.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),R=v.useMemo(()=>({reference:k,floating:T}),[k,T]),Y=v.useMemo(()=>{const O={position:n,left:0,top:0};if(!R.floating)return O;const L=Yc(R.floating,d.x),G=Yc(R.floating,d.y);return a?{...O,transform:"translate("+L+"px, "+G+"px)",...Gc(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:L,top:G}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:z,elements:R,floatingStyles:Y}),[d,F,z,R,Y])}const Iy=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?qc({element:r.current,padding:o}).fn(n):{}:r?qc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...Sy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...by(e),options:[e,t]}),Oy=(e,t)=>({...Iy(e),options:[e,t]});var My="Arrow",Xc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Pe.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Xc.displayName=My;var Dy=Xc;function Jc(e){const[t,n]=v.useState(void 0);return _t(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Di="Popper",[Zc,Xo]=In(Di),[Ly,Qc]=Zc(Di),eu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};eu.displayName=Di;var tu="PopperAnchor",nu=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Qc(tu,n),i=v.useRef(null),a=We(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Pe.div,{...o,ref:a})});nu.displayName=tu;var Li="PopperContent",[$y,Fy]=Zc(Li),ru=v.forwardRef((e,t)=>{var K,D,B,te,ie,ne;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...y}=e,x=Qc(Li,n),[g,w]=v.useState(null),S=We(t,Le=>w(Le)),[k,T]=v.useState(null),C=Jc(k),E=(C==null?void 0:C.width)??0,N=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),A=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],$=P.length>0,F={padding:A,boundary:P.filter(By),altBoundary:$},{refs:_,floatingStyles:z,placement:R,isPositioned:Y,middlewareData:O}=Ey({strategy:"fixed",placement:j,whileElementsMounted:(...Le)=>gy(...Le,{animationFrame:p==="always"}),elements:{reference:x.anchor},middleware:[Ny({mainAxis:o+N,alignmentAxis:i}),l&&Ay({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...F}),l&&_y({...F}),Ry({...F,apply:({elements:Le,rects:Q,availableWidth:pe,availableHeight:Ne})=>{const{width:Re,height:Ke}=Q.reference,Ze=Le.floating.style;Ze.setProperty("--radix-popper-available-width",`${pe}px`),Ze.setProperty("--radix-popper-available-height",`${Ne}px`),Ze.setProperty("--radix-popper-anchor-width",`${Re}px`),Ze.setProperty("--radix-popper-anchor-height",`${Ke}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:E,arrowHeight:N}),h&&Py({strategy:"referenceHidden",...F})]}),[L,G]=iu(R),J=Rt(m);_t(()=>{Y&&(J==null||J())},[Y,J]);const he=(K=O.arrow)==null?void 0:K.x,Ae=(D=O.arrow)==null?void 0:D.y,_e=((B=O.arrow)==null?void 0:B.centerOffset)!==0,[H,ee]=v.useState();return _t(()=>{g&&ee(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:_.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:Y?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:H,"--radix-popper-transform-origin":[(te=O.transformOrigin)==null?void 0:te.x,(ie=O.transformOrigin)==null?void 0:ie.y].join(" "),...((ne=O.hide)==null?void 0:ne.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx($y,{scope:n,placedSide:L,onArrowChange:T,arrowX:he,arrowY:Ae,shouldHideArrow:_e,children:u.jsx(Pe.div,{"data-side":L,"data-align":G,...y,ref:S,style:{...y.style,animation:Y?void 0:"none"}})})})});ru.displayName=Li;var ou="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},su=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Fy(ou,r),i=zy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});su.displayName=ou;function By(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var x,g,w;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=iu(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",y="";return c==="bottom"?(m=i?f:`${h}px`,y=`${-l}px`):c==="top"?(m=i?f:`${h}px`,y=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,y=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,y=i?f:`${p}px`),{data:{x:m,y}}}});function iu(e){const[t,n="center"]=e.split("-");return[t,n]}var au=eu,lu=nu,cu=ru,uu=su,Uy="Portal",Jo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);_t(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Pe.div,{...r,ref:t}),i):null});Jo.displayName=Uy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var tn=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=We(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};tn.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Zo(r.current);s.current=a==="mounted"?c:"none"},[a]),_t(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Zo(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),_t(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const y=Zo(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&y&&(l("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},h=p=>{p.target===t&&(s.current=Zo(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Zo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(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 $i="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Wr="RovingFocusGroup",[Fi,du,Gy]=vi(Wr),[Yy,fu]=In(Wr,[Gy]),[Xy,Jy]=Yy(Wr),hu=v.forwardRef((e,t)=>u.jsx(Fi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Fi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));hu.displayName=Wr;var Zy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=v.useRef(null),p=We(t,h),m=Lo(s),[y,x]=xr({prop:i,defaultProp:a??null,onChange:l,caller:Wr}),[g,w]=v.useState(!1),S=Rt(c),k=du(n),T=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const N=h.current;if(N)return N.addEventListener($i,S),()=>N.removeEventListener($i,S)},[S]),u.jsx(Xy,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:y,onItemFocus:v.useCallback(N=>x(N),[x]),onItemShiftTab:v.useCallback(()=>w(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:v.useCallback(()=>E(N=>N-1),[]),children:u.jsx(Pe.div,{tabIndex:g||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:de(e.onMouseDown,()=>{T.current=!0}),onFocus:de(e.onFocus,N=>{const j=!T.current;if(N.target===N.currentTarget&&j&&!g){const A=new CustomEvent($i,qy);if(N.currentTarget.dispatchEvent(A),!A.defaultPrevented){const P=k().filter(R=>R.focusable),$=P.find(R=>R.active),F=P.find(R=>R.id===y),z=[$,F,...P].filter(Boolean).map(R=>R.ref.current);gu(z,d)}}T.current=!1}),onBlur:de(e.onBlur,()=>w(!1))})})}),pu="RovingFocusGroupItem",mu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Nn(),c=s||l,d=Jy(pu,n),f=d.currentTabStopId===c,h=du(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:y}=d;return v.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),u.jsx(Fi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Pe.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:de(e.onMouseDown,x=>{r?d.onItemFocus(c):x.preventDefault()}),onFocus:de(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){d.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const g=tv(x,d.orientation,d.dir);if(g!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let S=h().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(x.currentTarget);S=d.loop?nv(S,k+1):S.slice(k+1)}setTimeout(()=>gu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:y!=null}):i})})});mu.displayName=pu;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function gu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=hu,ov=mu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Sr=new WeakMap,Qo=new WeakMap,es={},zi=0,xu=function(e){return e&&(e.host||xu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=xu(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);es[n]||(es[n]=new WeakMap);var s=es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),m=p!==null&&p!=="false",y=(Sr.get(h)||0)+1,x=(s.get(h)||0)+1;Sr.set(h,y),s.set(h,x),i.push(h),y===1&&m&&Qo.set(h,!0),x===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return d(t),a.clear(),zi++,function(){i.forEach(function(f){var h=Sr.get(f)-1,p=s.get(f)-1;Sr.set(f,h),s.set(f,p),h||(Qo.has(f)||f.removeAttribute(r),Qo.delete(f)),p||f.removeAttribute(n)}),zi--,zi||(Sr=new WeakMap,Sr=new WeakMap,Qo=new WeakMap,es={})}},Bi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},bn=function(){return bn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},bn.apply(this,arguments)};function yu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function lv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var ts="right-scroll-bar-position",ns="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,vu=new WeakMap;function hv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return fv(function(){var r=vu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}vu.set(n,e)},[e]),n}function pv(e){return e}function mv(e,t){t===void 0&&(t=pv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function gv(e){e===void 0&&(e={});var t=mv(null);return t.options=bn({async:!0,ssr:!1},e),t}var wu=function(e){var t=e.sideCar,n=yu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,bn({},n))};wu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),wu}var bu=gv(),Ui=function(){},rs=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ui,onWheelCapture:Ui,onTouchMoveCapture:Ui}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,y=e.inert,x=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,k=yu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=h,C=hv([n,t]),E=bn(bn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(T,{sideCar:bu,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:y,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),bn(bn({},E),{ref:C})):v.createElement(w,bn({},E,{className:l,ref:C}),a))});rs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},rs.classNames={fullWidth:ns,zeroRight:ts};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(wv(t,n),bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Su=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},Wi=function(e){return parseInt(e||"",10)||0},kv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Wi(n),Wi(r),Wi(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Iv=Su(),Cr="data-scroll-locked",Nv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
39
|
.`.concat(cv,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
package/package.json
CHANGED