@ottocode/web-ui 0.1.233 → 0.1.234

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ccip-DZ76OyMt.js","assets/framework-NgVU3wuG.js","assets/icons-Dzd6rzzk.js","assets/syntax-C4QRbGiI.js","assets/markdown-Bcsl3Jct.js"])))=>i.map(i=>d[i]);
2
- import{R as wt,u as bt,a as Ye,b as it,r as k,j as o,_ as JQ,d as g1,e as qQ,g as mf,f as c1,O as l1,h as YQ,i as u1,k as B1,l as Q1,Q as E1,m as d1,n as C1,o as I1}from"./framework-NgVU3wuG.js";import{B as f1,U as HQ,X as yt,P as Qr,T as Pn,M as PQ,a as wf,C as xn,b as wr,E as rn,L as $e,c as _Q,d as xf,e as ka,F as bs,f as h1,g as p1,I as zQ,h as so,i as m1,j as qc,k as Ac,S as Rr,l as yf,K as Df,m as w1,n as Yc,G as _n,o as Dn,p as x1,q as Ma,r as WQ,R as Sn,s as Xd,t as bf,u as VQ,v as $i,w as y1,A as Nf,x as D1,y as Do,z as Dt,D as oo,H as kf,J as Mf,N as Aa,O as b1,Q as vf,V as N1,W as gs,Y as k1,Z as $d,_ as M1,$ as v1,a0 as va,a1 as Sf,a2 as AC,a3 as S1,a4 as io,a5 as F1,a6 as BB,a7 as ec,a8 as G1,a9 as ZQ,aa as Ff,ab as Gf,ac as Rf,ad as R1,ae as XQ,af as U1,ag as Uf,ah as T1,ai as Tf,aj as L1,ak as O1,al as K1,am as j1,an as J1,ao as q1,ap as Y1,aq as Lf,ar as H1,as as P1,at as tc,au as $Q,av as Wi,aw as _1,ax as z1,ay as W1,az as V1,aA as Z1,aB as X1}from"./icons-Dzd6rzzk.js";import{v as rr,p as sr,h as fn}from"./syntax-C4QRbGiI.js";import{M as Of,a as Kf,d as an}from"./markdown-Bcsl3Jct.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const s of r)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&n(i)}).observe(document,{childList:!0,subtree:!0});function t(r){const s={};return r.integrity&&(s.integrity=r.integrity),r.referrerPolicy&&(s.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?s.credentials="include":r.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(r){if(r.ep)return;r.ep=!0;const s=t(r);fetch(r.href,s)}})();const eC=A=>{let e;const t=new Set,n=(c,l)=>{const B=typeof c=="function"?c(e):c;if(!Object.is(B,e)){const Q=e;e=l??(typeof B!="object"||B===null)?B:Object.assign({},e,B),t.forEach(u=>u(e,Q))}},r=()=>e,a={setState:n,getState:r,getInitialState:()=>g,subscribe:c=>(t.add(c),()=>t.delete(c))},g=e=A(n,r,a);return a},$1=(A=>A?eC(A):eC),AD=A=>A;function eD(A,e=AD){const t=wt.useSyncExternalStore(A.subscribe,wt.useCallback(()=>e(A.getState()),[A,e]),wt.useCallback(()=>e(A.getInitialState()),[A,e]));return wt.useDebugValue(t),t}const tC=A=>{const e=$1(A),t=n=>eD(e,n);return Object.assign(t,e),t},Rt=(A=>A?tC(A):tC),tD=300,nD=150,qn=Rt(A=>({isOpen:!1,panelHeight:tD,activeTabId:null,isMaximized:!1,get isExpanded(){return this.isOpen},get selectedTerminalId(){return this.activeTabId},openPanel:()=>A({isOpen:!0}),closePanel:()=>A({isOpen:!1,isMaximized:!1}),togglePanel:()=>A(e=>({isOpen:!e.isOpen,isMaximized:e.isOpen?!1:e.isMaximized})),setPanelHeight:e=>A({panelHeight:Math.max(nD,e)}),selectTab:e=>A({activeTabId:e,isOpen:!0}),toggleMaximize:()=>A(e=>({isMaximized:!e.isMaximized})),expandSidebar:()=>A({isOpen:!0}),collapseSidebar:()=>A({isOpen:!1,activeTabId:null,isMaximized:!1}),toggleSidebar:()=>A(e=>({isOpen:!e.isOpen,isMaximized:e.isOpen?!1:e.isMaximized})),selectTerminal:e=>A({activeTabId:e,isOpen:!0})}));var nC;(function(A){A.OPENAI="openai",A.ANTHROPIC="anthropic",A.GOOGLE="google",A.OPENROUTER="openrouter",A.OPENCODE="opencode",A.ZAI="zai",A.ZAI_CODING="zai-coding",A.MOONSHOT="moonshot",A.MINIMAX="minimax",A.COPILOT="copilot",A.SETU="setu"})(nC||(nC={}));function jf(A,e){return function(){return A.apply(e,arguments)}}const{toString:rD}=Object.prototype,{getPrototypeOf:AE}=Object,{iterator:Hc,toStringTag:Jf}=Symbol,Pc=(A=>e=>{const t=rD.call(e);return A[t]||(A[t]=t.slice(8,-1).toLowerCase())})(Object.create(null)),xr=A=>(A=A.toLowerCase(),e=>Pc(e)===A),_c=A=>e=>typeof e===A,{isArray:Ii}=Array,Ai=_c("undefined");function Sa(A){return A!==null&&!Ai(A)&&A.constructor!==null&&!Ai(A.constructor)&&Rn(A.constructor.isBuffer)&&A.constructor.isBuffer(A)}const qf=xr("ArrayBuffer");function sD(A){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(A):e=A&&A.buffer&&qf(A.buffer),e}const oD=_c("string"),Rn=_c("function"),Yf=_c("number"),Fa=A=>A!==null&&typeof A=="object",iD=A=>A===!0||A===!1,Kg=A=>{if(Pc(A)!=="object")return!1;const e=AE(A);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Jf in A)&&!(Hc in A)},aD=A=>{if(!Fa(A)||Sa(A))return!1;try{return Object.keys(A).length===0&&Object.getPrototypeOf(A)===Object.prototype}catch{return!1}},gD=xr("Date"),cD=xr("File"),lD=A=>!!(A&&typeof A.uri<"u"),uD=A=>A&&typeof A.getParts<"u",BD=xr("Blob"),QD=xr("FileList"),ED=A=>Fa(A)&&Rn(A.pipe);function dD(){return typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}const rC=dD(),sC=typeof rC.FormData<"u"?rC.FormData:void 0,CD=A=>{let e;return A&&(sC&&A instanceof sC||Rn(A.append)&&((e=Pc(A))==="formdata"||e==="object"&&Rn(A.toString)&&A.toString()==="[object FormData]"))},ID=xr("URLSearchParams"),[fD,hD,pD,mD]=["ReadableStream","Request","Response","Headers"].map(xr),wD=A=>A.trim?A.trim():A.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Ga(A,e,{allOwnKeys:t=!1}={}){if(A===null||typeof A>"u")return;let n,r;if(typeof A!="object"&&(A=[A]),Ii(A))for(n=0,r=A.length;n<r;n++)e.call(null,A[n],n,A);else{if(Sa(A))return;const s=t?Object.getOwnPropertyNames(A):Object.keys(A),i=s.length;let a;for(n=0;n<i;n++)a=s[n],e.call(null,A[a],a,A)}}function Hf(A,e){if(Sa(A))return null;e=e.toLowerCase();const t=Object.keys(A);let n=t.length,r;for(;n-- >0;)if(r=t[n],e===r.toLowerCase())return r;return null}const Ps=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Pf=A=>!Ai(A)&&A!==Ps;function QB(){const{caseless:A,skipUndefined:e}=Pf(this)&&this||{},t={},n=(r,s)=>{if(s==="__proto__"||s==="constructor"||s==="prototype")return;const i=A&&Hf(t,s)||s;Kg(t[i])&&Kg(r)?t[i]=QB(t[i],r):Kg(r)?t[i]=QB({},r):Ii(r)?t[i]=r.slice():(!e||!Ai(r))&&(t[i]=r)};for(let r=0,s=arguments.length;r<s;r++)arguments[r]&&Ga(arguments[r],n);return t}const xD=(A,e,t,{allOwnKeys:n}={})=>(Ga(e,(r,s)=>{t&&Rn(r)?Object.defineProperty(A,s,{value:jf(r,t),writable:!0,enumerable:!0,configurable:!0}):Object.defineProperty(A,s,{value:r,writable:!0,enumerable:!0,configurable:!0})},{allOwnKeys:n}),A),yD=A=>(A.charCodeAt(0)===65279&&(A=A.slice(1)),A),DD=(A,e,t,n)=>{A.prototype=Object.create(e.prototype,n),Object.defineProperty(A.prototype,"constructor",{value:A,writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(A,"super",{value:e.prototype}),t&&Object.assign(A.prototype,t)},bD=(A,e,t,n)=>{let r,s,i;const a={};if(e=e||{},A==null)return e;do{for(r=Object.getOwnPropertyNames(A),s=r.length;s-- >0;)i=r[s],(!n||n(i,A,e))&&!a[i]&&(e[i]=A[i],a[i]=!0);A=t!==!1&&AE(A)}while(A&&(!t||t(A,e))&&A!==Object.prototype);return e},ND=(A,e,t)=>{A=String(A),(t===void 0||t>A.length)&&(t=A.length),t-=e.length;const n=A.indexOf(e,t);return n!==-1&&n===t},kD=A=>{if(!A)return null;if(Ii(A))return A;let e=A.length;if(!Yf(e))return null;const t=new Array(e);for(;e-- >0;)t[e]=A[e];return t},MD=(A=>e=>A&&e instanceof A)(typeof Uint8Array<"u"&&AE(Uint8Array)),vD=(A,e)=>{const n=(A&&A[Hc]).call(A);let r;for(;(r=n.next())&&!r.done;){const s=r.value;e.call(A,s[0],s[1])}},SD=(A,e)=>{let t;const n=[];for(;(t=A.exec(e))!==null;)n.push(t);return n},FD=xr("HTMLFormElement"),GD=A=>A.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(t,n,r){return n.toUpperCase()+r}),oC=(({hasOwnProperty:A})=>(e,t)=>A.call(e,t))(Object.prototype),RD=xr("RegExp"),_f=(A,e)=>{const t=Object.getOwnPropertyDescriptors(A),n={};Ga(t,(r,s)=>{let i;(i=e(r,s,A))!==!1&&(n[s]=i||r)}),Object.defineProperties(A,n)},UD=A=>{_f(A,(e,t)=>{if(Rn(A)&&["arguments","caller","callee"].indexOf(t)!==-1)return!1;const n=A[t];if(Rn(n)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+t+"'")})}})},TD=(A,e)=>{const t={},n=r=>{r.forEach(s=>{t[s]=!0})};return Ii(A)?n(A):n(String(A).split(e)),t},LD=()=>{},OD=(A,e)=>A!=null&&Number.isFinite(A=+A)?A:e;function KD(A){return!!(A&&Rn(A.append)&&A[Jf]==="FormData"&&A[Hc])}const jD=A=>{const e=new Array(10),t=(n,r)=>{if(Fa(n)){if(e.indexOf(n)>=0)return;if(Sa(n))return n;if(!("toJSON"in n)){e[r]=n;const s=Ii(n)?[]:{};return Ga(n,(i,a)=>{const g=t(i,r+1);!Ai(g)&&(s[a]=g)}),e[r]=void 0,s}}return n};return t(A,0)},JD=xr("AsyncFunction"),qD=A=>A&&(Fa(A)||Rn(A))&&Rn(A.then)&&Rn(A.catch),zf=((A,e)=>A?setImmediate:e?((t,n)=>(Ps.addEventListener("message",({source:r,data:s})=>{r===Ps&&s===t&&n.length&&n.shift()()},!1),r=>{n.push(r),Ps.postMessage(t,"*")}))(`axios@${Math.random()}`,[]):t=>setTimeout(t))(typeof setImmediate=="function",Rn(Ps.postMessage)),YD=typeof queueMicrotask<"u"?queueMicrotask.bind(Ps):typeof process<"u"&&process.nextTick||zf,HD=A=>A!=null&&Rn(A[Hc]),QA={isArray:Ii,isArrayBuffer:qf,isBuffer:Sa,isFormData:CD,isArrayBufferView:sD,isString:oD,isNumber:Yf,isBoolean:iD,isObject:Fa,isPlainObject:Kg,isEmptyObject:aD,isReadableStream:fD,isRequest:hD,isResponse:pD,isHeaders:mD,isUndefined:Ai,isDate:gD,isFile:cD,isReactNativeBlob:lD,isReactNative:uD,isBlob:BD,isRegExp:RD,isFunction:Rn,isStream:ED,isURLSearchParams:ID,isTypedArray:MD,isFileList:QD,forEach:Ga,merge:QB,extend:xD,trim:wD,stripBOM:yD,inherits:DD,toFlatObject:bD,kindOf:Pc,kindOfTest:xr,endsWith:ND,toArray:kD,forEachEntry:vD,matchAll:SD,isHTMLForm:FD,hasOwnProperty:oC,hasOwnProp:oC,reduceDescriptors:_f,freezeMethods:UD,toObjectSet:TD,toCamelCase:GD,noop:LD,toFiniteNumber:OD,findKey:Hf,global:Ps,isContextDefined:Pf,isSpecCompliantForm:KD,toJSONObject:jD,isAsyncFn:JD,isThenable:qD,setImmediate:zf,asap:YD,isIterable:HD};let Ce=class Wf extends Error{static from(e,t,n,r,s,i){const a=new Wf(e.message,t||e.code,n,r,s);return a.cause=e,a.name=e.name,e.status!=null&&a.status==null&&(a.status=e.status),i&&Object.assign(a,i),a}constructor(e,t,n,r,s){super(e),Object.defineProperty(this,"message",{value:e,enumerable:!0,writable:!0,configurable:!0}),this.name="AxiosError",this.isAxiosError=!0,t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s,this.status=s.status)}toJSON(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:QA.toJSONObject(this.config),code:this.code,status:this.status}}};Ce.ERR_BAD_OPTION_VALUE="ERR_BAD_OPTION_VALUE";Ce.ERR_BAD_OPTION="ERR_BAD_OPTION";Ce.ECONNABORTED="ECONNABORTED";Ce.ETIMEDOUT="ETIMEDOUT";Ce.ERR_NETWORK="ERR_NETWORK";Ce.ERR_FR_TOO_MANY_REDIRECTS="ERR_FR_TOO_MANY_REDIRECTS";Ce.ERR_DEPRECATED="ERR_DEPRECATED";Ce.ERR_BAD_RESPONSE="ERR_BAD_RESPONSE";Ce.ERR_BAD_REQUEST="ERR_BAD_REQUEST";Ce.ERR_CANCELED="ERR_CANCELED";Ce.ERR_NOT_SUPPORT="ERR_NOT_SUPPORT";Ce.ERR_INVALID_URL="ERR_INVALID_URL";const PD=null;function EB(A){return QA.isPlainObject(A)||QA.isArray(A)}function Vf(A){return QA.endsWith(A,"[]")?A.slice(0,-2):A}function _l(A,e,t){return A?A.concat(e).map(function(r,s){return r=Vf(r),!t&&s?"["+r+"]":r}).join(t?".":""):e}function _D(A){return QA.isArray(A)&&!A.some(EB)}const zD=QA.toFlatObject(QA,{},null,function(e){return/^is[A-Z]/.test(e)});function zc(A,e,t){if(!QA.isObject(A))throw new TypeError("target must be an object");e=e||new FormData,t=QA.toFlatObject(t,{metaTokens:!0,dots:!1,indexes:!1},!1,function(f,h){return!QA.isUndefined(h[f])});const n=t.metaTokens,r=t.visitor||l,s=t.dots,i=t.indexes,g=(t.Blob||typeof Blob<"u"&&Blob)&&QA.isSpecCompliantForm(e);if(!QA.isFunction(r))throw new TypeError("visitor must be a function");function c(d){if(d===null)return"";if(QA.isDate(d))return d.toISOString();if(QA.isBoolean(d))return d.toString();if(!g&&QA.isBlob(d))throw new Ce("Blob is not supported. Use a Buffer instead.");return QA.isArrayBuffer(d)||QA.isTypedArray(d)?g&&typeof Blob=="function"?new Blob([d]):Buffer.from(d):d}function l(d,f,h){let x=d;if(QA.isReactNative(e)&&QA.isReactNativeBlob(d))return e.append(_l(h,f,s),c(d)),!1;if(d&&!h&&typeof d=="object"){if(QA.endsWith(f,"{}"))f=n?f:f.slice(0,-2),d=JSON.stringify(d);else if(QA.isArray(d)&&_D(d)||(QA.isFileList(d)||QA.endsWith(f,"[]"))&&(x=QA.toArray(d)))return f=Vf(f),x.forEach(function(m,M){!(QA.isUndefined(m)||m===null)&&e.append(i===!0?_l([f],M,s):i===null?f:f+"[]",c(m))}),!1}return EB(d)?!0:(e.append(_l(h,f,s),c(d)),!1)}const B=[],Q=Object.assign(zD,{defaultVisitor:l,convertValue:c,isVisitable:EB});function u(d,f){if(!QA.isUndefined(d)){if(B.indexOf(d)!==-1)throw Error("Circular reference detected in "+f.join("."));B.push(d),QA.forEach(d,function(x,b){(!(QA.isUndefined(x)||x===null)&&r.call(e,x,QA.isString(b)?b.trim():b,f,Q))===!0&&u(x,f?f.concat(b):[b])}),B.pop()}}if(!QA.isObject(A))throw new TypeError("data must be an object");return u(A),e}function iC(A){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(A).replace(/[!'()~]|%20|%00/g,function(n){return e[n]})}function eE(A,e){this._pairs=[],A&&zc(A,this,e)}const Zf=eE.prototype;Zf.append=function(e,t){this._pairs.push([e,t])};Zf.toString=function(e){const t=e?function(n){return e.call(this,n,iC)}:iC;return this._pairs.map(function(r){return t(r[0])+"="+t(r[1])},"").join("&")};function WD(A){return encodeURIComponent(A).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Xf(A,e,t){if(!e)return A;const n=t&&t.encode||WD,r=QA.isFunction(t)?{serialize:t}:t,s=r&&r.serialize;let i;if(s?i=s(e,r):i=QA.isURLSearchParams(e)?e.toString():new eE(e,r).toString(n),i){const a=A.indexOf("#");a!==-1&&(A=A.slice(0,a)),A+=(A.indexOf("?")===-1?"?":"&")+i}return A}class aC{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){QA.forEach(this.handlers,function(n){n!==null&&e(n)})}}const tE={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1,legacyInterceptorReqResOrdering:!0},VD=typeof URLSearchParams<"u"?URLSearchParams:eE,ZD=typeof FormData<"u"?FormData:null,XD=typeof Blob<"u"?Blob:null,$D={isBrowser:!0,classes:{URLSearchParams:VD,FormData:ZD,Blob:XD},protocols:["http","https","file","blob","url","data"]},nE=typeof window<"u"&&typeof document<"u",dB=typeof navigator=="object"&&navigator||void 0,A2=nE&&(!dB||["ReactNative","NativeScript","NS"].indexOf(dB.product)<0),e2=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",t2=nE&&window.location.href||"http://localhost",n2=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:nE,hasStandardBrowserEnv:A2,hasStandardBrowserWebWorkerEnv:e2,navigator:dB,origin:t2},Symbol.toStringTag,{value:"Module"})),In={...n2,...$D};function r2(A,e){return zc(A,new In.classes.URLSearchParams,{visitor:function(t,n,r,s){return In.isNode&&QA.isBuffer(t)?(this.append(n,t.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...e})}function s2(A){return QA.matchAll(/\w+|\[(\w*)]/g,A).map(e=>e[0]==="[]"?"":e[1]||e[0])}function o2(A){const e={},t=Object.keys(A);let n;const r=t.length;let s;for(n=0;n<r;n++)s=t[n],e[s]=A[s];return e}function $f(A){function e(t,n,r,s){let i=t[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),g=s>=t.length;return i=!i&&QA.isArray(r)?r.length:i,g?(QA.hasOwnProp(r,i)?r[i]=[r[i],n]:r[i]=n,!a):((!r[i]||!QA.isObject(r[i]))&&(r[i]=[]),e(t,n,r[i],s)&&QA.isArray(r[i])&&(r[i]=o2(r[i])),!a)}if(QA.isFormData(A)&&QA.isFunction(A.entries)){const t={};return QA.forEachEntry(A,(n,r)=>{e(s2(n),r,t,0)}),t}return null}function i2(A,e,t){if(QA.isString(A))try{return(e||JSON.parse)(A),QA.trim(A)}catch(n){if(n.name!=="SyntaxError")throw n}return(t||JSON.stringify)(A)}const Ra={transitional:tE,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,s=QA.isObject(e);if(s&&QA.isHTMLForm(e)&&(e=new FormData(e)),QA.isFormData(e))return r?JSON.stringify($f(e)):e;if(QA.isArrayBuffer(e)||QA.isBuffer(e)||QA.isStream(e)||QA.isFile(e)||QA.isBlob(e)||QA.isReadableStream(e))return e;if(QA.isArrayBufferView(e))return e.buffer;if(QA.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let a;if(s){if(n.indexOf("application/x-www-form-urlencoded")>-1)return r2(e,this.formSerializer).toString();if((a=QA.isFileList(e))||n.indexOf("multipart/form-data")>-1){const g=this.env&&this.env.FormData;return zc(a?{"files[]":e}:e,g&&new g,this.formSerializer)}}return s||r?(t.setContentType("application/json",!1),i2(e)):e}],transformResponse:[function(e){const t=this.transitional||Ra.transitional,n=t&&t.forcedJSONParsing,r=this.responseType==="json";if(QA.isResponse(e)||QA.isReadableStream(e))return e;if(e&&QA.isString(e)&&(n&&!this.responseType||r)){const i=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Ce.from(a,Ce.ERR_BAD_RESPONSE,this,null,this.response):a}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:In.classes.FormData,Blob:In.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};QA.forEach(["delete","get","head","post","put","patch"],A=>{Ra.headers[A]={}});const a2=QA.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),g2=A=>{const e={};let t,n,r;return A&&A.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ccip-DT8hlmC4.js","assets/framework-D8VmzUzi.js","assets/icons-BWeqcfI3.js","assets/syntax-0PI0z6H_.js","assets/markdown-CN6Boxtq.js"])))=>i.map(i=>d[i]);
2
+ import{R as wt,u as bt,a as Ye,b as it,r as k,j as o,_ as JQ,d as g1,e as qQ,g as mf,f as c1,O as l1,h as YQ,i as u1,k as B1,l as Q1,Q as E1,m as d1,n as C1,o as I1}from"./framework-D8VmzUzi.js";import{B as f1,U as HQ,X as yt,P as Qr,T as Pn,M as PQ,a as wf,C as xn,b as wr,E as rn,L as $e,c as _Q,d as xf,e as ka,F as bs,f as h1,g as p1,I as zQ,h as so,i as m1,j as qc,k as Ac,S as Rr,l as yf,K as Df,m as w1,n as Yc,G as _n,o as Dn,p as x1,q as Ma,r as WQ,R as Sn,s as Xd,t as bf,u as VQ,v as $i,w as y1,A as Nf,x as D1,y as Do,z as Dt,D as oo,H as kf,J as Mf,N as Aa,O as b1,Q as vf,V as N1,W as gs,Y as k1,Z as $d,_ as M1,$ as v1,a0 as va,a1 as Sf,a2 as AC,a3 as S1,a4 as io,a5 as F1,a6 as BB,a7 as ec,a8 as G1,a9 as ZQ,aa as Ff,ab as Gf,ac as Rf,ad as R1,ae as XQ,af as U1,ag as Uf,ah as T1,ai as Tf,aj as L1,ak as O1,al as K1,am as j1,an as J1,ao as q1,ap as Y1,aq as Lf,ar as H1,as as P1,at as tc,au as $Q,av as Wi,aw as _1,ax as z1,ay as W1,az as V1,aA as Z1,aB as X1}from"./icons-BWeqcfI3.js";import{v as rr,p as sr,h as fn}from"./syntax-0PI0z6H_.js";import{M as Of,a as Kf,d as an}from"./markdown-CN6Boxtq.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const s of r)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&n(i)}).observe(document,{childList:!0,subtree:!0});function t(r){const s={};return r.integrity&&(s.integrity=r.integrity),r.referrerPolicy&&(s.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?s.credentials="include":r.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(r){if(r.ep)return;r.ep=!0;const s=t(r);fetch(r.href,s)}})();const eC=A=>{let e;const t=new Set,n=(c,l)=>{const B=typeof c=="function"?c(e):c;if(!Object.is(B,e)){const Q=e;e=l??(typeof B!="object"||B===null)?B:Object.assign({},e,B),t.forEach(u=>u(e,Q))}},r=()=>e,a={setState:n,getState:r,getInitialState:()=>g,subscribe:c=>(t.add(c),()=>t.delete(c))},g=e=A(n,r,a);return a},$1=(A=>A?eC(A):eC),AD=A=>A;function eD(A,e=AD){const t=wt.useSyncExternalStore(A.subscribe,wt.useCallback(()=>e(A.getState()),[A,e]),wt.useCallback(()=>e(A.getInitialState()),[A,e]));return wt.useDebugValue(t),t}const tC=A=>{const e=$1(A),t=n=>eD(e,n);return Object.assign(t,e),t},Rt=(A=>A?tC(A):tC),tD=300,nD=150,qn=Rt(A=>({isOpen:!1,panelHeight:tD,activeTabId:null,isMaximized:!1,get isExpanded(){return this.isOpen},get selectedTerminalId(){return this.activeTabId},openPanel:()=>A({isOpen:!0}),closePanel:()=>A({isOpen:!1,isMaximized:!1}),togglePanel:()=>A(e=>({isOpen:!e.isOpen,isMaximized:e.isOpen?!1:e.isMaximized})),setPanelHeight:e=>A({panelHeight:Math.max(nD,e)}),selectTab:e=>A({activeTabId:e,isOpen:!0}),toggleMaximize:()=>A(e=>({isMaximized:!e.isMaximized})),expandSidebar:()=>A({isOpen:!0}),collapseSidebar:()=>A({isOpen:!1,activeTabId:null,isMaximized:!1}),toggleSidebar:()=>A(e=>({isOpen:!e.isOpen,isMaximized:e.isOpen?!1:e.isMaximized})),selectTerminal:e=>A({activeTabId:e,isOpen:!0})}));var nC;(function(A){A.OPENAI="openai",A.ANTHROPIC="anthropic",A.GOOGLE="google",A.OPENROUTER="openrouter",A.OPENCODE="opencode",A.ZAI="zai",A.ZAI_CODING="zai-coding",A.MOONSHOT="moonshot",A.MINIMAX="minimax",A.COPILOT="copilot",A.SETU="setu"})(nC||(nC={}));function jf(A,e){return function(){return A.apply(e,arguments)}}const{toString:rD}=Object.prototype,{getPrototypeOf:AE}=Object,{iterator:Hc,toStringTag:Jf}=Symbol,Pc=(A=>e=>{const t=rD.call(e);return A[t]||(A[t]=t.slice(8,-1).toLowerCase())})(Object.create(null)),xr=A=>(A=A.toLowerCase(),e=>Pc(e)===A),_c=A=>e=>typeof e===A,{isArray:Ii}=Array,Ai=_c("undefined");function Sa(A){return A!==null&&!Ai(A)&&A.constructor!==null&&!Ai(A.constructor)&&Rn(A.constructor.isBuffer)&&A.constructor.isBuffer(A)}const qf=xr("ArrayBuffer");function sD(A){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(A):e=A&&A.buffer&&qf(A.buffer),e}const oD=_c("string"),Rn=_c("function"),Yf=_c("number"),Fa=A=>A!==null&&typeof A=="object",iD=A=>A===!0||A===!1,Kg=A=>{if(Pc(A)!=="object")return!1;const e=AE(A);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Jf in A)&&!(Hc in A)},aD=A=>{if(!Fa(A)||Sa(A))return!1;try{return Object.keys(A).length===0&&Object.getPrototypeOf(A)===Object.prototype}catch{return!1}},gD=xr("Date"),cD=xr("File"),lD=A=>!!(A&&typeof A.uri<"u"),uD=A=>A&&typeof A.getParts<"u",BD=xr("Blob"),QD=xr("FileList"),ED=A=>Fa(A)&&Rn(A.pipe);function dD(){return typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}}const rC=dD(),sC=typeof rC.FormData<"u"?rC.FormData:void 0,CD=A=>{let e;return A&&(sC&&A instanceof sC||Rn(A.append)&&((e=Pc(A))==="formdata"||e==="object"&&Rn(A.toString)&&A.toString()==="[object FormData]"))},ID=xr("URLSearchParams"),[fD,hD,pD,mD]=["ReadableStream","Request","Response","Headers"].map(xr),wD=A=>A.trim?A.trim():A.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Ga(A,e,{allOwnKeys:t=!1}={}){if(A===null||typeof A>"u")return;let n,r;if(typeof A!="object"&&(A=[A]),Ii(A))for(n=0,r=A.length;n<r;n++)e.call(null,A[n],n,A);else{if(Sa(A))return;const s=t?Object.getOwnPropertyNames(A):Object.keys(A),i=s.length;let a;for(n=0;n<i;n++)a=s[n],e.call(null,A[a],a,A)}}function Hf(A,e){if(Sa(A))return null;e=e.toLowerCase();const t=Object.keys(A);let n=t.length,r;for(;n-- >0;)if(r=t[n],e===r.toLowerCase())return r;return null}const Ps=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Pf=A=>!Ai(A)&&A!==Ps;function QB(){const{caseless:A,skipUndefined:e}=Pf(this)&&this||{},t={},n=(r,s)=>{if(s==="__proto__"||s==="constructor"||s==="prototype")return;const i=A&&Hf(t,s)||s;Kg(t[i])&&Kg(r)?t[i]=QB(t[i],r):Kg(r)?t[i]=QB({},r):Ii(r)?t[i]=r.slice():(!e||!Ai(r))&&(t[i]=r)};for(let r=0,s=arguments.length;r<s;r++)arguments[r]&&Ga(arguments[r],n);return t}const xD=(A,e,t,{allOwnKeys:n}={})=>(Ga(e,(r,s)=>{t&&Rn(r)?Object.defineProperty(A,s,{value:jf(r,t),writable:!0,enumerable:!0,configurable:!0}):Object.defineProperty(A,s,{value:r,writable:!0,enumerable:!0,configurable:!0})},{allOwnKeys:n}),A),yD=A=>(A.charCodeAt(0)===65279&&(A=A.slice(1)),A),DD=(A,e,t,n)=>{A.prototype=Object.create(e.prototype,n),Object.defineProperty(A.prototype,"constructor",{value:A,writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(A,"super",{value:e.prototype}),t&&Object.assign(A.prototype,t)},bD=(A,e,t,n)=>{let r,s,i;const a={};if(e=e||{},A==null)return e;do{for(r=Object.getOwnPropertyNames(A),s=r.length;s-- >0;)i=r[s],(!n||n(i,A,e))&&!a[i]&&(e[i]=A[i],a[i]=!0);A=t!==!1&&AE(A)}while(A&&(!t||t(A,e))&&A!==Object.prototype);return e},ND=(A,e,t)=>{A=String(A),(t===void 0||t>A.length)&&(t=A.length),t-=e.length;const n=A.indexOf(e,t);return n!==-1&&n===t},kD=A=>{if(!A)return null;if(Ii(A))return A;let e=A.length;if(!Yf(e))return null;const t=new Array(e);for(;e-- >0;)t[e]=A[e];return t},MD=(A=>e=>A&&e instanceof A)(typeof Uint8Array<"u"&&AE(Uint8Array)),vD=(A,e)=>{const n=(A&&A[Hc]).call(A);let r;for(;(r=n.next())&&!r.done;){const s=r.value;e.call(A,s[0],s[1])}},SD=(A,e)=>{let t;const n=[];for(;(t=A.exec(e))!==null;)n.push(t);return n},FD=xr("HTMLFormElement"),GD=A=>A.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(t,n,r){return n.toUpperCase()+r}),oC=(({hasOwnProperty:A})=>(e,t)=>A.call(e,t))(Object.prototype),RD=xr("RegExp"),_f=(A,e)=>{const t=Object.getOwnPropertyDescriptors(A),n={};Ga(t,(r,s)=>{let i;(i=e(r,s,A))!==!1&&(n[s]=i||r)}),Object.defineProperties(A,n)},UD=A=>{_f(A,(e,t)=>{if(Rn(A)&&["arguments","caller","callee"].indexOf(t)!==-1)return!1;const n=A[t];if(Rn(n)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+t+"'")})}})},TD=(A,e)=>{const t={},n=r=>{r.forEach(s=>{t[s]=!0})};return Ii(A)?n(A):n(String(A).split(e)),t},LD=()=>{},OD=(A,e)=>A!=null&&Number.isFinite(A=+A)?A:e;function KD(A){return!!(A&&Rn(A.append)&&A[Jf]==="FormData"&&A[Hc])}const jD=A=>{const e=new Array(10),t=(n,r)=>{if(Fa(n)){if(e.indexOf(n)>=0)return;if(Sa(n))return n;if(!("toJSON"in n)){e[r]=n;const s=Ii(n)?[]:{};return Ga(n,(i,a)=>{const g=t(i,r+1);!Ai(g)&&(s[a]=g)}),e[r]=void 0,s}}return n};return t(A,0)},JD=xr("AsyncFunction"),qD=A=>A&&(Fa(A)||Rn(A))&&Rn(A.then)&&Rn(A.catch),zf=((A,e)=>A?setImmediate:e?((t,n)=>(Ps.addEventListener("message",({source:r,data:s})=>{r===Ps&&s===t&&n.length&&n.shift()()},!1),r=>{n.push(r),Ps.postMessage(t,"*")}))(`axios@${Math.random()}`,[]):t=>setTimeout(t))(typeof setImmediate=="function",Rn(Ps.postMessage)),YD=typeof queueMicrotask<"u"?queueMicrotask.bind(Ps):typeof process<"u"&&process.nextTick||zf,HD=A=>A!=null&&Rn(A[Hc]),QA={isArray:Ii,isArrayBuffer:qf,isBuffer:Sa,isFormData:CD,isArrayBufferView:sD,isString:oD,isNumber:Yf,isBoolean:iD,isObject:Fa,isPlainObject:Kg,isEmptyObject:aD,isReadableStream:fD,isRequest:hD,isResponse:pD,isHeaders:mD,isUndefined:Ai,isDate:gD,isFile:cD,isReactNativeBlob:lD,isReactNative:uD,isBlob:BD,isRegExp:RD,isFunction:Rn,isStream:ED,isURLSearchParams:ID,isTypedArray:MD,isFileList:QD,forEach:Ga,merge:QB,extend:xD,trim:wD,stripBOM:yD,inherits:DD,toFlatObject:bD,kindOf:Pc,kindOfTest:xr,endsWith:ND,toArray:kD,forEachEntry:vD,matchAll:SD,isHTMLForm:FD,hasOwnProperty:oC,hasOwnProp:oC,reduceDescriptors:_f,freezeMethods:UD,toObjectSet:TD,toCamelCase:GD,noop:LD,toFiniteNumber:OD,findKey:Hf,global:Ps,isContextDefined:Pf,isSpecCompliantForm:KD,toJSONObject:jD,isAsyncFn:JD,isThenable:qD,setImmediate:zf,asap:YD,isIterable:HD};let Ce=class Wf extends Error{static from(e,t,n,r,s,i){const a=new Wf(e.message,t||e.code,n,r,s);return a.cause=e,a.name=e.name,e.status!=null&&a.status==null&&(a.status=e.status),i&&Object.assign(a,i),a}constructor(e,t,n,r,s){super(e),Object.defineProperty(this,"message",{value:e,enumerable:!0,writable:!0,configurable:!0}),this.name="AxiosError",this.isAxiosError=!0,t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s,this.status=s.status)}toJSON(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:QA.toJSONObject(this.config),code:this.code,status:this.status}}};Ce.ERR_BAD_OPTION_VALUE="ERR_BAD_OPTION_VALUE";Ce.ERR_BAD_OPTION="ERR_BAD_OPTION";Ce.ECONNABORTED="ECONNABORTED";Ce.ETIMEDOUT="ETIMEDOUT";Ce.ERR_NETWORK="ERR_NETWORK";Ce.ERR_FR_TOO_MANY_REDIRECTS="ERR_FR_TOO_MANY_REDIRECTS";Ce.ERR_DEPRECATED="ERR_DEPRECATED";Ce.ERR_BAD_RESPONSE="ERR_BAD_RESPONSE";Ce.ERR_BAD_REQUEST="ERR_BAD_REQUEST";Ce.ERR_CANCELED="ERR_CANCELED";Ce.ERR_NOT_SUPPORT="ERR_NOT_SUPPORT";Ce.ERR_INVALID_URL="ERR_INVALID_URL";const PD=null;function EB(A){return QA.isPlainObject(A)||QA.isArray(A)}function Vf(A){return QA.endsWith(A,"[]")?A.slice(0,-2):A}function _l(A,e,t){return A?A.concat(e).map(function(r,s){return r=Vf(r),!t&&s?"["+r+"]":r}).join(t?".":""):e}function _D(A){return QA.isArray(A)&&!A.some(EB)}const zD=QA.toFlatObject(QA,{},null,function(e){return/^is[A-Z]/.test(e)});function zc(A,e,t){if(!QA.isObject(A))throw new TypeError("target must be an object");e=e||new FormData,t=QA.toFlatObject(t,{metaTokens:!0,dots:!1,indexes:!1},!1,function(f,h){return!QA.isUndefined(h[f])});const n=t.metaTokens,r=t.visitor||l,s=t.dots,i=t.indexes,g=(t.Blob||typeof Blob<"u"&&Blob)&&QA.isSpecCompliantForm(e);if(!QA.isFunction(r))throw new TypeError("visitor must be a function");function c(d){if(d===null)return"";if(QA.isDate(d))return d.toISOString();if(QA.isBoolean(d))return d.toString();if(!g&&QA.isBlob(d))throw new Ce("Blob is not supported. Use a Buffer instead.");return QA.isArrayBuffer(d)||QA.isTypedArray(d)?g&&typeof Blob=="function"?new Blob([d]):Buffer.from(d):d}function l(d,f,h){let x=d;if(QA.isReactNative(e)&&QA.isReactNativeBlob(d))return e.append(_l(h,f,s),c(d)),!1;if(d&&!h&&typeof d=="object"){if(QA.endsWith(f,"{}"))f=n?f:f.slice(0,-2),d=JSON.stringify(d);else if(QA.isArray(d)&&_D(d)||(QA.isFileList(d)||QA.endsWith(f,"[]"))&&(x=QA.toArray(d)))return f=Vf(f),x.forEach(function(m,M){!(QA.isUndefined(m)||m===null)&&e.append(i===!0?_l([f],M,s):i===null?f:f+"[]",c(m))}),!1}return EB(d)?!0:(e.append(_l(h,f,s),c(d)),!1)}const B=[],Q=Object.assign(zD,{defaultVisitor:l,convertValue:c,isVisitable:EB});function u(d,f){if(!QA.isUndefined(d)){if(B.indexOf(d)!==-1)throw Error("Circular reference detected in "+f.join("."));B.push(d),QA.forEach(d,function(x,b){(!(QA.isUndefined(x)||x===null)&&r.call(e,x,QA.isString(b)?b.trim():b,f,Q))===!0&&u(x,f?f.concat(b):[b])}),B.pop()}}if(!QA.isObject(A))throw new TypeError("data must be an object");return u(A),e}function iC(A){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(A).replace(/[!'()~]|%20|%00/g,function(n){return e[n]})}function eE(A,e){this._pairs=[],A&&zc(A,this,e)}const Zf=eE.prototype;Zf.append=function(e,t){this._pairs.push([e,t])};Zf.toString=function(e){const t=e?function(n){return e.call(this,n,iC)}:iC;return this._pairs.map(function(r){return t(r[0])+"="+t(r[1])},"").join("&")};function WD(A){return encodeURIComponent(A).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Xf(A,e,t){if(!e)return A;const n=t&&t.encode||WD,r=QA.isFunction(t)?{serialize:t}:t,s=r&&r.serialize;let i;if(s?i=s(e,r):i=QA.isURLSearchParams(e)?e.toString():new eE(e,r).toString(n),i){const a=A.indexOf("#");a!==-1&&(A=A.slice(0,a)),A+=(A.indexOf("?")===-1?"?":"&")+i}return A}class aC{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){QA.forEach(this.handlers,function(n){n!==null&&e(n)})}}const tE={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1,legacyInterceptorReqResOrdering:!0},VD=typeof URLSearchParams<"u"?URLSearchParams:eE,ZD=typeof FormData<"u"?FormData:null,XD=typeof Blob<"u"?Blob:null,$D={isBrowser:!0,classes:{URLSearchParams:VD,FormData:ZD,Blob:XD},protocols:["http","https","file","blob","url","data"]},nE=typeof window<"u"&&typeof document<"u",dB=typeof navigator=="object"&&navigator||void 0,A2=nE&&(!dB||["ReactNative","NativeScript","NS"].indexOf(dB.product)<0),e2=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",t2=nE&&window.location.href||"http://localhost",n2=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:nE,hasStandardBrowserEnv:A2,hasStandardBrowserWebWorkerEnv:e2,navigator:dB,origin:t2},Symbol.toStringTag,{value:"Module"})),In={...n2,...$D};function r2(A,e){return zc(A,new In.classes.URLSearchParams,{visitor:function(t,n,r,s){return In.isNode&&QA.isBuffer(t)?(this.append(n,t.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...e})}function s2(A){return QA.matchAll(/\w+|\[(\w*)]/g,A).map(e=>e[0]==="[]"?"":e[1]||e[0])}function o2(A){const e={},t=Object.keys(A);let n;const r=t.length;let s;for(n=0;n<r;n++)s=t[n],e[s]=A[s];return e}function $f(A){function e(t,n,r,s){let i=t[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),g=s>=t.length;return i=!i&&QA.isArray(r)?r.length:i,g?(QA.hasOwnProp(r,i)?r[i]=[r[i],n]:r[i]=n,!a):((!r[i]||!QA.isObject(r[i]))&&(r[i]=[]),e(t,n,r[i],s)&&QA.isArray(r[i])&&(r[i]=o2(r[i])),!a)}if(QA.isFormData(A)&&QA.isFunction(A.entries)){const t={};return QA.forEachEntry(A,(n,r)=>{e(s2(n),r,t,0)}),t}return null}function i2(A,e,t){if(QA.isString(A))try{return(e||JSON.parse)(A),QA.trim(A)}catch(n){if(n.name!=="SyntaxError")throw n}return(t||JSON.stringify)(A)}const Ra={transitional:tE,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,s=QA.isObject(e);if(s&&QA.isHTMLForm(e)&&(e=new FormData(e)),QA.isFormData(e))return r?JSON.stringify($f(e)):e;if(QA.isArrayBuffer(e)||QA.isBuffer(e)||QA.isStream(e)||QA.isFile(e)||QA.isBlob(e)||QA.isReadableStream(e))return e;if(QA.isArrayBufferView(e))return e.buffer;if(QA.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let a;if(s){if(n.indexOf("application/x-www-form-urlencoded")>-1)return r2(e,this.formSerializer).toString();if((a=QA.isFileList(e))||n.indexOf("multipart/form-data")>-1){const g=this.env&&this.env.FormData;return zc(a?{"files[]":e}:e,g&&new g,this.formSerializer)}}return s||r?(t.setContentType("application/json",!1),i2(e)):e}],transformResponse:[function(e){const t=this.transitional||Ra.transitional,n=t&&t.forcedJSONParsing,r=this.responseType==="json";if(QA.isResponse(e)||QA.isReadableStream(e))return e;if(e&&QA.isString(e)&&(n&&!this.responseType||r)){const i=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Ce.from(a,Ce.ERR_BAD_RESPONSE,this,null,this.response):a}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:In.classes.FormData,Blob:In.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};QA.forEach(["delete","get","head","post","put","patch"],A=>{Ra.headers[A]={}});const a2=QA.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),g2=A=>{const e={};let t,n,r;return A&&A.split(`
3
3
  `).forEach(function(i){r=i.indexOf(":"),t=i.substring(0,r).trim().toLowerCase(),n=i.substring(r+1).trim(),!(!t||e[t]&&a2[t])&&(t==="set-cookie"?e[t]?e[t].push(n):e[t]=[n]:e[t]=e[t]?e[t]+", "+n:n)}),e},gC=Symbol("internals");function Gi(A){return A&&String(A).trim().toLowerCase()}function jg(A){return A===!1||A==null?A:QA.isArray(A)?A.map(jg):String(A)}function c2(A){const e=Object.create(null),t=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let n;for(;n=t.exec(A);)e[n[1]]=n[2];return e}const l2=A=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(A.trim());function zl(A,e,t,n,r){if(QA.isFunction(n))return n.call(this,e,t);if(r&&(e=t),!!QA.isString(e)){if(QA.isString(n))return e.indexOf(n)!==-1;if(QA.isRegExp(n))return n.test(e)}}function u2(A){return A.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,t,n)=>t.toUpperCase()+n)}function B2(A,e){const t=QA.toCamelCase(" "+e);["get","set","has"].forEach(n=>{Object.defineProperty(A,n+t,{value:function(r,s,i){return this[n].call(this,e,r,s,i)},configurable:!0})})}let Un=class{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function s(a,g,c){const l=Gi(g);if(!l)throw new Error("header name must be a non-empty string");const B=QA.findKey(r,l);(!B||r[B]===void 0||c===!0||c===void 0&&r[B]!==!1)&&(r[B||g]=jg(a))}const i=(a,g)=>QA.forEach(a,(c,l)=>s(c,l,g));if(QA.isPlainObject(e)||e instanceof this.constructor)i(e,t);else if(QA.isString(e)&&(e=e.trim())&&!l2(e))i(g2(e),t);else if(QA.isObject(e)&&QA.isIterable(e)){let a={},g,c;for(const l of e){if(!QA.isArray(l))throw TypeError("Object iterator must return a key-value pair");a[c=l[0]]=(g=a[c])?QA.isArray(g)?[...g,l[1]]:[g,l[1]]:l[1]}i(a,t)}else e!=null&&s(t,e,n);return this}get(e,t){if(e=Gi(e),e){const n=QA.findKey(this,e);if(n){const r=this[n];if(!t)return r;if(t===!0)return c2(r);if(QA.isFunction(t))return t.call(this,r,n);if(QA.isRegExp(t))return t.exec(r);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=Gi(e),e){const n=QA.findKey(this,e);return!!(n&&this[n]!==void 0&&(!t||zl(this,this[n],n,t)))}return!1}delete(e,t){const n=this;let r=!1;function s(i){if(i=Gi(i),i){const a=QA.findKey(n,i);a&&(!t||zl(n,n[a],a,t))&&(delete n[a],r=!0)}}return QA.isArray(e)?e.forEach(s):s(e),r}clear(e){const t=Object.keys(this);let n=t.length,r=!1;for(;n--;){const s=t[n];(!e||zl(this,this[s],s,e,!0))&&(delete this[s],r=!0)}return r}normalize(e){const t=this,n={};return QA.forEach(this,(r,s)=>{const i=QA.findKey(n,s);if(i){t[i]=jg(r),delete t[s];return}const a=e?u2(s):String(s).trim();a!==s&&delete t[s],t[a]=jg(r),n[a]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return QA.forEach(this,(n,r)=>{n!=null&&n!==!1&&(t[r]=e&&QA.isArray(n)?n.join(", "):n)}),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,t])=>e+": "+t).join(`
4
4
  `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach(r=>n.set(r)),n}static accessor(e){const n=(this[gC]=this[gC]={accessors:{}}).accessors,r=this.prototype;function s(i){const a=Gi(i);n[a]||(B2(r,i),n[a]=!0)}return QA.isArray(e)?e.forEach(s):s(e),this}};Un.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);QA.reduceDescriptors(Un.prototype,({value:A},e)=>{let t=e[0].toUpperCase()+e.slice(1);return{get:()=>A,set(n){this[t]=n}}});QA.freezeMethods(Un);function Wl(A,e){const t=this||Ra,n=e||t,r=Un.from(n.headers);let s=n.data;return QA.forEach(A,function(a){s=a.call(t,s,r.normalize(),e?e.status:void 0)}),r.normalize(),s}function Ah(A){return!!(A&&A.__CANCEL__)}let Ua=class extends Ce{constructor(e,t,n){super(e??"canceled",Ce.ERR_CANCELED,t,n),this.name="CanceledError",this.__CANCEL__=!0}};function eh(A,e,t){const n=t.config.validateStatus;!t.status||!n||n(t.status)?A(t):e(new Ce("Request failed with status code "+t.status,[Ce.ERR_BAD_REQUEST,Ce.ERR_BAD_RESPONSE][Math.floor(t.status/100)-4],t.config,t.request,t))}function Q2(A){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(A);return e&&e[1]||""}function E2(A,e){A=A||10;const t=new Array(A),n=new Array(A);let r=0,s=0,i;return e=e!==void 0?e:1e3,function(g){const c=Date.now(),l=n[s];i||(i=c),t[r]=g,n[r]=c;let B=s,Q=0;for(;B!==r;)Q+=t[B++],B=B%A;if(r=(r+1)%A,r===s&&(s=(s+1)%A),c-i<e)return;const u=l&&c-l;return u?Math.round(Q*1e3/u):void 0}}function d2(A,e){let t=0,n=1e3/e,r,s;const i=(c,l=Date.now())=>{t=l,r=null,s&&(clearTimeout(s),s=null),A(...c)};return[(...c)=>{const l=Date.now(),B=l-t;B>=n?i(c,l):(r=c,s||(s=setTimeout(()=>{s=null,i(r)},n-B)))},()=>r&&i(r)]}const nc=(A,e,t=3)=>{let n=0;const r=E2(50,250);return d2(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,g=i-n,c=r(g),l=i<=a;n=i;const B={loaded:i,total:a,progress:a?i/a:void 0,bytes:g,rate:c||void 0,estimated:c&&a&&l?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[e?"download":"upload"]:!0};A(B)},t)},cC=(A,e)=>{const t=A!=null;return[n=>e[0]({lengthComputable:t,total:A,loaded:n}),e[1]]},lC=A=>(...e)=>QA.asap(()=>A(...e)),C2=In.hasStandardBrowserEnv?((A,e)=>t=>(t=new URL(t,In.origin),A.protocol===t.protocol&&A.host===t.host&&(e||A.port===t.port)))(new URL(In.origin),In.navigator&&/(msie|trident)/i.test(In.navigator.userAgent)):()=>!0,I2=In.hasStandardBrowserEnv?{write(A,e,t,n,r,s,i){if(typeof document>"u")return;const a=[`${A}=${encodeURIComponent(e)}`];QA.isNumber(t)&&a.push(`expires=${new Date(t).toUTCString()}`),QA.isString(n)&&a.push(`path=${n}`),QA.isString(r)&&a.push(`domain=${r}`),s===!0&&a.push("secure"),QA.isString(i)&&a.push(`SameSite=${i}`),document.cookie=a.join("; ")},read(A){if(typeof document>"u")return null;const e=document.cookie.match(new RegExp("(?:^|; )"+A+"=([^;]*)"));return e?decodeURIComponent(e[1]):null},remove(A){this.write(A,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function f2(A){return typeof A!="string"?!1:/^([a-z][a-z\d+\-.]*:)?\/\//i.test(A)}function h2(A,e){return e?A.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):A}function th(A,e,t){let n=!f2(e);return A&&(n||t==!1)?h2(A,e):e}const uC=A=>A instanceof Un?{...A}:A;function ao(A,e){e=e||{};const t={};function n(c,l,B,Q){return QA.isPlainObject(c)&&QA.isPlainObject(l)?QA.merge.call({caseless:Q},c,l):QA.isPlainObject(l)?QA.merge({},l):QA.isArray(l)?l.slice():l}function r(c,l,B,Q){if(QA.isUndefined(l)){if(!QA.isUndefined(c))return n(void 0,c,B,Q)}else return n(c,l,B,Q)}function s(c,l){if(!QA.isUndefined(l))return n(void 0,l)}function i(c,l){if(QA.isUndefined(l)){if(!QA.isUndefined(c))return n(void 0,c)}else return n(void 0,l)}function a(c,l,B){if(B in e)return n(c,l);if(B in A)return n(void 0,c)}const g={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,l,B)=>r(uC(c),uC(l),B,!0)};return QA.forEach(Object.keys({...A,...e}),function(l){if(l==="__proto__"||l==="constructor"||l==="prototype")return;const B=QA.hasOwnProp(g,l)?g[l]:r,Q=B(A[l],e[l],l);QA.isUndefined(Q)&&B!==a||(t[l]=Q)}),t}const nh=A=>{const e=ao({},A);let{data:t,withXSRFToken:n,xsrfHeaderName:r,xsrfCookieName:s,headers:i,auth:a}=e;if(e.headers=i=Un.from(i),e.url=Xf(th(e.baseURL,e.url,e.allowAbsoluteUrls),A.params,A.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),QA.isFormData(t)){if(In.hasStandardBrowserEnv||In.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(QA.isFunction(t.getHeaders)){const g=t.getHeaders(),c=["content-type","content-length"];Object.entries(g).forEach(([l,B])=>{c.includes(l.toLowerCase())&&i.set(l,B)})}}if(In.hasStandardBrowserEnv&&(n&&QA.isFunction(n)&&(n=n(e)),n||n!==!1&&C2(e.url))){const g=r&&s&&I2.read(s);g&&i.set(r,g)}return e},p2=typeof XMLHttpRequest<"u",m2=p2&&function(A){return new Promise(function(t,n){const r=nh(A);let s=r.data;const i=Un.from(r.headers).normalize();let{responseType:a,onUploadProgress:g,onDownloadProgress:c}=r,l,B,Q,u,d;function f(){u&&u(),d&&d(),r.cancelToken&&r.cancelToken.unsubscribe(l),r.signal&&r.signal.removeEventListener("abort",l)}let h=new XMLHttpRequest;h.open(r.method.toUpperCase(),r.url,!0),h.timeout=r.timeout;function x(){if(!h)return;const m=Un.from("getAllResponseHeaders"in h&&h.getAllResponseHeaders()),G={data:!a||a==="text"||a==="json"?h.responseText:h.response,status:h.status,statusText:h.statusText,headers:m,config:A,request:h};eh(function(Z){t(Z),f()},function(Z){n(Z),f()},G),h=null}"onloadend"in h?h.onloadend=x:h.onreadystatechange=function(){!h||h.readyState!==4||h.status===0&&!(h.responseURL&&h.responseURL.indexOf("file:")===0)||setTimeout(x)},h.onabort=function(){h&&(n(new Ce("Request aborted",Ce.ECONNABORTED,A,h)),h=null)},h.onerror=function(M){const G=M&&M.message?M.message:"Network Error",Y=new Ce(G,Ce.ERR_NETWORK,A,h);Y.event=M||null,n(Y),h=null},h.ontimeout=function(){let M=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const G=r.transitional||tE;r.timeoutErrorMessage&&(M=r.timeoutErrorMessage),n(new Ce(M,G.clarifyTimeoutError?Ce.ETIMEDOUT:Ce.ECONNABORTED,A,h)),h=null},s===void 0&&i.setContentType(null),"setRequestHeader"in h&&QA.forEach(i.toJSON(),function(M,G){h.setRequestHeader(G,M)}),QA.isUndefined(r.withCredentials)||(h.withCredentials=!!r.withCredentials),a&&a!=="json"&&(h.responseType=r.responseType),c&&([Q,d]=nc(c,!0),h.addEventListener("progress",Q)),g&&h.upload&&([B,u]=nc(g),h.upload.addEventListener("progress",B),h.upload.addEventListener("loadend",u)),(r.cancelToken||r.signal)&&(l=m=>{h&&(n(!m||m.type?new Ua(null,A,h):m),h.abort(),h=null)},r.cancelToken&&r.cancelToken.subscribe(l),r.signal&&(r.signal.aborted?l():r.signal.addEventListener("abort",l)));const b=Q2(r.url);if(b&&In.protocols.indexOf(b)===-1){n(new Ce("Unsupported protocol "+b+":",Ce.ERR_BAD_REQUEST,A));return}h.send(s||null)})},w2=(A,e)=>{const{length:t}=A=A?A.filter(Boolean):[];if(e||t){let n=new AbortController,r;const s=function(c){if(!r){r=!0,a();const l=c instanceof Error?c:this.reason;n.abort(l instanceof Ce?l:new Ua(l instanceof Error?l.message:l))}};let i=e&&setTimeout(()=>{i=null,s(new Ce(`timeout of ${e}ms exceeded`,Ce.ETIMEDOUT))},e);const a=()=>{A&&(i&&clearTimeout(i),i=null,A.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),A=null)};A.forEach(c=>c.addEventListener("abort",s));const{signal:g}=n;return g.unsubscribe=()=>QA.asap(a),g}},x2=function*(A,e){let t=A.byteLength;if(t<e){yield A;return}let n=0,r;for(;n<t;)r=n+e,yield A.slice(n,r),n=r},y2=async function*(A,e){for await(const t of D2(A))yield*x2(t,e)},D2=async function*(A){if(A[Symbol.asyncIterator]){yield*A;return}const e=A.getReader();try{for(;;){const{done:t,value:n}=await e.read();if(t)break;yield n}}finally{await e.cancel()}},BC=(A,e,t,n)=>{const r=y2(A,e);let s=0,i,a=g=>{i||(i=!0,n&&n(g))};return new ReadableStream({async pull(g){try{const{done:c,value:l}=await r.next();if(c){a(),g.close();return}let B=l.byteLength;if(t){let Q=s+=B;t(Q)}g.enqueue(new Uint8Array(l))}catch(c){throw a(c),c}},cancel(g){return a(g),r.return()}},{highWaterMark:2})},QC=64*1024,{isFunction:hg}=QA,b2=(({Request:A,Response:e})=>({Request:A,Response:e}))(QA.global),{ReadableStream:EC,TextEncoder:dC}=QA.global,CC=(A,...e)=>{try{return!!A(...e)}catch{return!1}},N2=A=>{A=QA.merge.call({skipUndefined:!0},b2,A);const{fetch:e,Request:t,Response:n}=A,r=e?hg(e):typeof fetch=="function",s=hg(t),i=hg(n);if(!r)return!1;const a=r&&hg(EC),g=r&&(typeof dC=="function"?(d=>f=>d.encode(f))(new dC):async d=>new Uint8Array(await new t(d).arrayBuffer())),c=s&&a&&CC(()=>{let d=!1;const f=new t(In.origin,{body:new EC,method:"POST",get duplex(){return d=!0,"half"}}).headers.has("Content-Type");return d&&!f}),l=i&&a&&CC(()=>QA.isReadableStream(new n("").body)),B={stream:l&&(d=>d.body)};r&&["text","arrayBuffer","blob","formData","stream"].forEach(d=>{!B[d]&&(B[d]=(f,h)=>{let x=f&&f[d];if(x)return x.call(f);throw new Ce(`Response type '${d}' is not supported`,Ce.ERR_NOT_SUPPORT,h)})});const Q=async d=>{if(d==null)return 0;if(QA.isBlob(d))return d.size;if(QA.isSpecCompliantForm(d))return(await new t(In.origin,{method:"POST",body:d}).arrayBuffer()).byteLength;if(QA.isArrayBufferView(d)||QA.isArrayBuffer(d))return d.byteLength;if(QA.isURLSearchParams(d)&&(d=d+""),QA.isString(d))return(await g(d)).byteLength},u=async(d,f)=>{const h=QA.toFiniteNumber(d.getContentLength());return h??Q(f)};return async d=>{let{url:f,method:h,data:x,signal:b,cancelToken:m,timeout:M,onDownloadProgress:G,onUploadProgress:Y,responseType:Z,headers:P,withCredentials:L="same-origin",fetchOptions:q}=nh(d),v=e||fetch;Z=Z?(Z+"").toLowerCase():"text";let U=w2([b,m&&m.toAbortSignal()],M),w=null;const E=U&&U.unsubscribe&&(()=>{U.unsubscribe()});let C;try{if(Y&&c&&h!=="get"&&h!=="head"&&(C=await u(P,x))!==0){let R=new t(f,{method:"POST",body:x,duplex:"half"}),I;if(QA.isFormData(x)&&(I=R.headers.get("content-type"))&&P.setContentType(I),R.body){const[p,K]=cC(C,nc(lC(Y)));x=BC(R.body,QC,p,K)}}QA.isString(L)||(L=L?"include":"omit");const y=s&&"credentials"in t.prototype,F={...q,signal:U,method:h.toUpperCase(),headers:P.normalize().toJSON(),body:x,duplex:"half",credentials:y?L:void 0};w=s&&new t(f,F);let T=await(s?v(w,q):v(f,F));const J=l&&(Z==="stream"||Z==="response");if(l&&(G||J&&E)){const R={};["status","statusText","headers"].forEach(j=>{R[j]=T[j]});const I=QA.toFiniteNumber(T.headers.get("content-length")),[p,K]=G&&cC(I,nc(lC(G),!0))||[];T=new n(BC(T.body,QC,p,()=>{K&&K(),E&&E()}),R)}Z=Z||"text";let z=await B[QA.findKey(B,Z)||"text"](T,d);return!J&&E&&E(),await new Promise((R,I)=>{eh(R,I,{data:z,headers:Un.from(T.headers),status:T.status,statusText:T.statusText,config:d,request:w})})}catch(y){throw E&&E(),y&&y.name==="TypeError"&&/Load failed|fetch/i.test(y.message)?Object.assign(new Ce("Network Error",Ce.ERR_NETWORK,d,w,y&&y.response),{cause:y.cause||y}):Ce.from(y,y&&y.code,d,w,y&&y.response)}}},k2=new Map,rh=A=>{let e=A&&A.env||{};const{fetch:t,Request:n,Response:r}=e,s=[n,r,t];let i=s.length,a=i,g,c,l=k2;for(;a--;)g=s[a],c=l.get(g),c===void 0&&l.set(g,c=a?new Map:N2(e)),l=c;return c};rh();const rE={http:PD,xhr:m2,fetch:{get:rh}};QA.forEach(rE,(A,e)=>{if(A){try{Object.defineProperty(A,"name",{value:e})}catch{}Object.defineProperty(A,"adapterName",{value:e})}});const IC=A=>`- ${A}`,M2=A=>QA.isFunction(A)||A===null||A===!1;function v2(A,e){A=QA.isArray(A)?A:[A];const{length:t}=A;let n,r;const s={};for(let i=0;i<t;i++){n=A[i];let a;if(r=n,!M2(n)&&(r=rE[(a=String(n)).toLowerCase()],r===void 0))throw new Ce(`Unknown adapter '${a}'`);if(r&&(QA.isFunction(r)||(r=r.get(e))))break;s[a||"#"+i]=r}if(!r){const i=Object.entries(s).map(([g,c])=>`adapter ${g} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=t?i.length>1?`since :
5
5
  `+i.map(IC).join(`
@@ -33,7 +33,7 @@ For tests, pass a Ghostty instance directly:
33
33
  transition-all duration-150 ease-out cursor-pointer
34
34
  hover:bg-accent/50
35
35
  ${e?"opacity-100 translate-y-0":"opacity-0 translate-y-2"}
36
- `,onClick:r,role:"alert",children:[ak[A.type],o.jsx("span",{className:"text-sm text-foreground",children:A.message}),A.action&&o.jsxs("button",{type:"button",onClick:s=>{s.stopPropagation(),Br(A.action?.href)},className:"ml-auto flex items-center gap-1 text-xs text-primary hover:underline",children:[A.action.label,o.jsx(rn,{className:"h-3 w-3"})]})]})}function ck(){const A=Er(e=>e.toasts);return A.length===0?null:o.jsx("div",{className:"fixed bottom-4 right-4 z-[9999] flex flex-col gap-2 max-w-sm",children:A.map(e=>o.jsx(gk,{toast:e},e.id))})}const Ta=Rt(A=>({pendingApprovals:[],addPendingApproval:e=>A(t=>({pendingApprovals:[...t.pendingApprovals,e]})),removePendingApproval:e=>A(t=>({pendingApprovals:t.pendingApprovals.filter(n=>n.callId!==e)})),updatePendingApproval:(e,t)=>A(n=>({pendingApprovals:n.pendingApprovals.map(r=>r.callId===e?{...r,args:t}:r)})),clearPendingApprovals:()=>A({pendingApprovals:[]}),setPendingApprovals:e=>A({pendingApprovals:e})}));function lk(A,e){let t;try{t=A()}catch{return}return{getItem:r=>{var s;const i=g=>g===null?null:JSON.parse(g,void 0),a=(s=t.getItem(r))!=null?s:null;return a instanceof Promise?a.then(i):i(a)},setItem:(r,s)=>t.setItem(r,JSON.stringify(s,void 0)),removeItem:r=>t.removeItem(r)}}const pB=A=>e=>{try{const t=A(e);return t instanceof Promise?t:{then(n){return pB(n)(t)},catch(n){return this}}}catch(t){return{then(n){return this},catch(n){return pB(n)(t)}}}},uk=(A,e)=>(t,n,r)=>{let s={storage:lk(()=>window.localStorage),partialize:h=>h,version:0,merge:(h,x)=>({...x,...h}),...e},i=!1,a=0;const g=new Set,c=new Set;let l=s.storage;if(!l)return A((...h)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),t(...h)},n,r);const B=()=>{const h=s.partialize({...n()});return l.setItem(s.name,{state:h,version:s.version})},Q=r.setState;r.setState=(h,x)=>(Q(h,x),B());const u=A((...h)=>(t(...h),B()),n,r);r.getInitialState=()=>u;let d;const f=()=>{var h,x;if(!l)return;const b=++a;i=!1,g.forEach(M=>{var G;return M((G=n())!=null?G:u)});const m=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(h=n())!=null?h:u))||void 0;return pB(l.getItem.bind(l))(s.name).then(M=>{if(M)if(typeof M.version=="number"&&M.version!==s.version){if(s.migrate){const G=s.migrate(M.state,M.version);return G instanceof Promise?G.then(Y=>[!0,Y]):[!0,G]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,M.state];return[!1,void 0]}).then(M=>{var G;if(b!==a)return;const[Y,Z]=M;if(d=s.merge(Z,(G=n())!=null?G:u),t(d,!0),Y)return B()}).then(()=>{b===a&&(m?.(d,void 0),d=n(),i=!0,c.forEach(M=>M(d)))}).catch(M=>{b===a&&m?.(void 0,M)})};return r.persist={setOptions:h=>{s={...s,...h},h.storage&&(l=h.storage)},clearStorage:()=>{l?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>f(),hasHydrated:()=>i,onHydrate:h=>(g.add(h),()=>{g.delete(h)}),onFinishHydration:h=>(c.add(h),()=>{c.delete(h)})},s.skipHydration||f(),d||u},ph=uk,ks=Rt()(ph((A,e)=>({widths:{},setWidth:(t,n)=>A(r=>({widths:{...r.widths,[t]:n}})),getWidth:(t,n)=>e().widths[t]??n}),{name:"panel-widths"})),fi=k.memo(function({panelKey:e,side:t,minWidth:n,maxWidth:r,defaultWidth:s,onWidthChange:i}){const a=k.useRef(null),g=k.useCallback(c=>{c.preventDefault();const l=ks.getState().getWidth(e,s);a.current={startX:c.clientX,startWidth:l};const B=u=>{if(!a.current)return;const d=u.clientX-a.current.startX,f=t==="right"?a.current.startWidth-d:a.current.startWidth+d,h=Math.min(Math.max(n,f),r);ks.getState().setWidth(e,h),i?.(h)},Q=()=>{a.current=null,document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",Q),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",B),document.addEventListener("mouseup",Q),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[e,t,n,r,s,i]);return o.jsx("div",{className:`w-1 h-full cursor-col-resize hover:bg-primary/30 active:bg-primary/50 transition-colors absolute top-0 bottom-0 z-10 ${t==="right"?"left-0":"right-0"}`,onMouseDown:g})});function cs(A){return Array.isArray?Array.isArray(A):xh(A)==="[object Array]"}function Bk(A){if(typeof A=="string")return A;let e=A+"";return e=="0"&&1/A==-1/0?"-0":e}function Qk(A){return A==null?"":Bk(A)}function vr(A){return typeof A=="string"}function mh(A){return typeof A=="number"}function Ek(A){return A===!0||A===!1||dk(A)&&xh(A)=="[object Boolean]"}function wh(A){return typeof A=="object"}function dk(A){return wh(A)&&A!==null}function Yn(A){return A!=null}function Zl(A){return!A.trim().length}function xh(A){return A==null?A===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(A)}const Ck="Incorrect 'index' type",Ik=A=>`Invalid value for key ${A}`,fk=A=>`Pattern length exceeds max of ${A}.`,hk=A=>`Missing ${A} property in key`,pk=A=>`Property 'weight' in key '${A}' must be a positive integer`,MC=Object.prototype.hasOwnProperty;class mk{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(n=>{let r=yh(n);this._keys.push(r),this._keyMap[r.id]=r,t+=r.weight}),this._keys.forEach(n=>{n.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function yh(A){let e=null,t=null,n=null,r=1,s=null;if(vr(A)||cs(A))n=A,e=vC(A),t=mB(A);else{if(!MC.call(A,"name"))throw new Error(hk("name"));const i=A.name;if(n=i,MC.call(A,"weight")&&(r=A.weight,r<=0))throw new Error(pk(i));e=vC(i),t=mB(i),s=A.getFn}return{path:e,id:t,weight:r,src:n,getFn:s}}function vC(A){return cs(A)?A:A.split(".")}function mB(A){return cs(A)?A.join("."):A}function wk(A,e){let t=[],n=!1;const r=(s,i,a)=>{if(Yn(s))if(!i[a])t.push(s);else{let g=i[a];const c=s[g];if(!Yn(c))return;if(a===i.length-1&&(vr(c)||mh(c)||Ek(c)))t.push(Qk(c));else if(cs(c)){n=!0;for(let l=0,B=c.length;l<B;l+=1)r(c[l],i,a+1)}else i.length&&r(c,i,a+1)}};return r(A,vr(e)?e.split("."):e,0),n?t:t[0]}const xk={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},yk={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(A,e)=>A.score===e.score?A.idx<e.idx?-1:1:A.score<e.score?-1:1},Dk={location:0,threshold:.6,distance:100},bk={useExtendedSearch:!1,getFn:wk,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var Ie={...yk,...xk,...Dk,...bk};const Nk=/[^ ]+/g;function kk(A=1,e=3){const t=new Map,n=Math.pow(10,e);return{get(r){const s=r.match(Nk).length;if(t.has(s))return t.get(s);const i=1/Math.pow(s,.5*A),a=parseFloat(Math.round(i*n)/n);return t.set(s,a),a},clear(){t.clear()}}}class aE{constructor({getFn:e=Ie.getFn,fieldNormWeight:t=Ie.fieldNormWeight}={}){this.norm=kk(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((t,n)=>{this._keysMap[t.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,vr(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();vr(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!Yn(e)||Zl(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((r,s)=>{let i=r.getFn?r.getFn(e):this.getFn(e,r.path);if(Yn(i)){if(cs(i)){let a=[];const g=[{nestedArrIndex:-1,value:i}];for(;g.length;){const{nestedArrIndex:c,value:l}=g.pop();if(Yn(l))if(vr(l)&&!Zl(l)){let B={v:l,i:c,n:this.norm.get(l)};a.push(B)}else cs(l)&&l.forEach((B,Q)=>{g.push({nestedArrIndex:Q,value:B})})}n.$[s]=a}else if(vr(i)&&!Zl(i)){let a={v:i,n:this.norm.get(i)};n.$[s]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Dh(A,e,{getFn:t=Ie.getFn,fieldNormWeight:n=Ie.fieldNormWeight}={}){const r=new aE({getFn:t,fieldNormWeight:n});return r.setKeys(A.map(yh)),r.setSources(e),r.create(),r}function Mk(A,{getFn:e=Ie.getFn,fieldNormWeight:t=Ie.fieldNormWeight}={}){const{keys:n,records:r}=A,s=new aE({getFn:e,fieldNormWeight:t});return s.setKeys(n),s.setIndexRecords(r),s}function pg(A,{errors:e=0,currentLocation:t=0,expectedLocation:n=0,distance:r=Ie.distance,ignoreLocation:s=Ie.ignoreLocation}={}){const i=e/A.length;if(s)return i;const a=Math.abs(n-t);return r?i+a/r:a?1:i}function vk(A=[],e=Ie.minMatchCharLength){let t=[],n=-1,r=-1,s=0;for(let i=A.length;s<i;s+=1){let a=A[s];a&&n===-1?n=s:!a&&n!==-1&&(r=s-1,r-n+1>=e&&t.push([n,r]),n=-1)}return A[s-1]&&s-n>=e&&t.push([n,s-1]),t}const Ys=32;function Sk(A,e,t,{location:n=Ie.location,distance:r=Ie.distance,threshold:s=Ie.threshold,findAllMatches:i=Ie.findAllMatches,minMatchCharLength:a=Ie.minMatchCharLength,includeMatches:g=Ie.includeMatches,ignoreLocation:c=Ie.ignoreLocation}={}){if(e.length>Ys)throw new Error(fk(Ys));const l=e.length,B=A.length,Q=Math.max(0,Math.min(n,B));let u=s,d=Q;const f=a>1||g,h=f?Array(B):[];let x;for(;(x=A.indexOf(e,d))>-1;){let Z=pg(e,{currentLocation:x,expectedLocation:Q,distance:r,ignoreLocation:c});if(u=Math.min(Z,u),d=x+l,f){let P=0;for(;P<l;)h[x+P]=1,P+=1}}d=-1;let b=[],m=1,M=l+B;const G=1<<l-1;for(let Z=0;Z<l;Z+=1){let P=0,L=M;for(;P<L;)pg(e,{errors:Z,currentLocation:Q+L,expectedLocation:Q,distance:r,ignoreLocation:c})<=u?P=L:M=L,L=Math.floor((M-P)/2+P);M=L;let q=Math.max(1,Q-L+1),v=i?B:Math.min(Q+L,B)+l,U=Array(v+2);U[v+1]=(1<<Z)-1;for(let E=v;E>=q;E-=1){let C=E-1,y=t[A.charAt(C)];if(f&&(h[C]=+!!y),U[E]=(U[E+1]<<1|1)&y,Z&&(U[E]|=(b[E+1]|b[E])<<1|1|b[E+1]),U[E]&G&&(m=pg(e,{errors:Z,currentLocation:C,expectedLocation:Q,distance:r,ignoreLocation:c}),m<=u)){if(u=m,d=C,d<=Q)break;q=Math.max(1,2*Q-d)}}if(pg(e,{errors:Z+1,currentLocation:Q,expectedLocation:Q,distance:r,ignoreLocation:c})>u)break;b=U}const Y={isMatch:d>=0,score:Math.max(.001,m)};if(f){const Z=vk(h,a);Z.length?g&&(Y.indices=Z):Y.isMatch=!1}return Y}function Fk(A){let e={};for(let t=0,n=A.length;t<n;t+=1){const r=A.charAt(t);e[r]=(e[r]||0)|1<<n-t-1}return e}const sc=String.prototype.normalize?(A=>A.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(A=>A);class bh{constructor(e,{location:t=Ie.location,threshold:n=Ie.threshold,distance:r=Ie.distance,includeMatches:s=Ie.includeMatches,findAllMatches:i=Ie.findAllMatches,minMatchCharLength:a=Ie.minMatchCharLength,isCaseSensitive:g=Ie.isCaseSensitive,ignoreDiacritics:c=Ie.ignoreDiacritics,ignoreLocation:l=Ie.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:s,findAllMatches:i,minMatchCharLength:a,isCaseSensitive:g,ignoreDiacritics:c,ignoreLocation:l},e=g?e:e.toLowerCase(),e=c?sc(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const B=(u,d)=>{this.chunks.push({pattern:u,alphabet:Fk(u),startIndex:d})},Q=this.pattern.length;if(Q>Ys){let u=0;const d=Q%Ys,f=Q-d;for(;u<f;)B(this.pattern.substr(u,Ys),u),u+=Ys;if(d){const h=Q-Ys;B(this.pattern.substr(h),h)}}else B(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?sc(e):e,this.pattern===e){let f={isMatch:!0,score:0};return r&&(f.indices=[[0,e.length-1]]),f}const{location:s,distance:i,threshold:a,findAllMatches:g,minMatchCharLength:c,ignoreLocation:l}=this.options;let B=[],Q=0,u=!1;this.chunks.forEach(({pattern:f,alphabet:h,startIndex:x})=>{const{isMatch:b,score:m,indices:M}=Sk(e,f,h,{location:s+x,distance:i,threshold:a,findAllMatches:g,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});b&&(u=!0),Q+=m,b&&M&&(B=[...B,...M])});let d={isMatch:u,score:u?Q/this.chunks.length:1};return u&&r&&(d.indices=B),d}}class Us{constructor(e){this.pattern=e}static isMultiMatch(e){return SC(e,this.multiRegex)}static isSingleMatch(e){return SC(e,this.singleRegex)}search(){}}function SC(A,e){const t=A.match(e);return t?t[1]:null}class Gk extends Us{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class Rk extends Us{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class Uk extends Us{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class Tk extends Us{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Lk extends Us{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class Ok extends Us{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Nh extends Us{constructor(e,{location:t=Ie.location,threshold:n=Ie.threshold,distance:r=Ie.distance,includeMatches:s=Ie.includeMatches,findAllMatches:i=Ie.findAllMatches,minMatchCharLength:a=Ie.minMatchCharLength,isCaseSensitive:g=Ie.isCaseSensitive,ignoreDiacritics:c=Ie.ignoreDiacritics,ignoreLocation:l=Ie.ignoreLocation}={}){super(e),this._bitapSearch=new bh(e,{location:t,threshold:n,distance:r,includeMatches:s,findAllMatches:i,minMatchCharLength:a,isCaseSensitive:g,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class kh extends Us{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n;const r=[],s=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+s,r.push([n,t-1]);const i=!!r.length;return{isMatch:i,score:i?0:1,indices:r}}}const wB=[Gk,kh,Uk,Tk,Ok,Lk,Rk,Nh],FC=wB.length,Kk=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,jk="|";function Jk(A,e={}){return A.split(jk).map(t=>{let n=t.trim().split(Kk).filter(s=>s&&!!s.trim()),r=[];for(let s=0,i=n.length;s<i;s+=1){const a=n[s];let g=!1,c=-1;for(;!g&&++c<FC;){const l=wB[c];let B=l.isMultiMatch(a);B&&(r.push(new l(B,e)),g=!0)}if(!g)for(c=-1;++c<FC;){const l=wB[c];let B=l.isSingleMatch(a);if(B){r.push(new l(B,e));break}}}return r})}const qk=new Set([Nh.type,kh.type]);class Yk{constructor(e,{isCaseSensitive:t=Ie.isCaseSensitive,ignoreDiacritics:n=Ie.ignoreDiacritics,includeMatches:r=Ie.includeMatches,minMatchCharLength:s=Ie.minMatchCharLength,ignoreLocation:i=Ie.ignoreLocation,findAllMatches:a=Ie.findAllMatches,location:g=Ie.location,threshold:c=Ie.threshold,distance:l=Ie.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:s,findAllMatches:a,ignoreLocation:i,location:g,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?sc(e):e,this.pattern=e,this.query=Jk(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:s}=this.options;e=r?e:e.toLowerCase(),e=s?sc(e):e;let i=0,a=[],g=0;for(let c=0,l=t.length;c<l;c+=1){const B=t[c];a.length=0,i=0;for(let Q=0,u=B.length;Q<u;Q+=1){const d=B[Q],{isMatch:f,indices:h,score:x}=d.search(e);if(f){if(i+=1,g+=x,n){const b=d.constructor.type;qk.has(b)?a=[...a,...h]:a.push(h)}}else{g=0,i=0,a.length=0;break}}if(i){let Q={isMatch:!0,score:g/i};return n&&(Q.indices=a),Q}}return{isMatch:!1,score:1}}}const xB=[];function Hk(...A){xB.push(...A)}function yB(A,e){for(let t=0,n=xB.length;t<n;t+=1){let r=xB[t];if(r.condition(A,e))return new r(A,e)}return new bh(A,e)}const oc={AND:"$and",OR:"$or"},DB={PATH:"$path",PATTERN:"$val"},bB=A=>!!(A[oc.AND]||A[oc.OR]),Pk=A=>!!A[DB.PATH],_k=A=>!cs(A)&&wh(A)&&!bB(A),GC=A=>({[oc.AND]:Object.keys(A).map(e=>({[e]:A[e]}))});function Mh(A,e,{auto:t=!0}={}){const n=r=>{let s=Object.keys(r);const i=Pk(r);if(!i&&s.length>1&&!bB(r))return n(GC(r));if(_k(r)){const g=i?r[DB.PATH]:s[0],c=i?r[DB.PATTERN]:r[g];if(!vr(c))throw new Error(Ik(g));const l={keyId:mB(g),pattern:c};return t&&(l.searcher=yB(c,e)),l}let a={children:[],operator:s[0]};return s.forEach(g=>{const c=r[g];cs(c)&&c.forEach(l=>{a.children.push(n(l))})}),a};return bB(A)||(A=GC(A)),n(A)}function zk(A,{ignoreFieldNorm:e=Ie.ignoreFieldNorm}){A.forEach(t=>{let n=1;t.matches.forEach(({key:r,norm:s,score:i})=>{const a=r?r.weight:null;n*=Math.pow(i===0&&a?Number.EPSILON:i,(a||1)*(e?1:s))}),t.score=n})}function Wk(A,e){const t=A.matches;e.matches=[],Yn(t)&&t.forEach(n=>{if(!Yn(n.indices)||!n.indices.length)return;const{indices:r,value:s}=n;let i={indices:r,value:s};n.key&&(i.key=n.key.src),n.idx>-1&&(i.refIndex=n.idx),e.matches.push(i)})}function Vk(A,e){e.score=A.score}function Zk(A,e,{includeMatches:t=Ie.includeMatches,includeScore:n=Ie.includeScore}={}){const r=[];return t&&r.push(Wk),n&&r.push(Vk),A.map(s=>{const{idx:i}=s,a={item:e[i],refIndex:i};return r.length&&r.forEach(g=>{g(s,a)}),a})}class Ts{constructor(e,t={},n){this.options={...Ie,...t},this.options.useExtendedSearch,this._keyStore=new mk(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof aE))throw new Error(Ck);this._myIndex=t||Dh(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Yn(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let n=0,r=this._docs.length;n<r;n+=1){const s=this._docs[n];e(s,n)&&(this.removeAt(n),n-=1,r-=1,t.push(s))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:s,sortFn:i,ignoreFieldNorm:a}=this.options;let g=vr(e)?vr(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return zk(g,{ignoreFieldNorm:a}),s&&g.sort(i),mh(t)&&t>-1&&(g=g.slice(0,t)),Zk(g,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const t=yB(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:s,i,n:a})=>{if(!Yn(s))return;const{isMatch:g,score:c,indices:l}=t.searchIn(s);g&&r.push({item:s,idx:i,matches:[{score:c,value:s,norm:a,indices:l}]})}),r}_searchLogical(e){const t=Mh(e,this.options),n=(a,g,c)=>{if(!a.children){const{keyId:B,searcher:Q}=a,u=this._findMatches({key:this._keyStore.get(B),value:this._myIndex.getValueForItemAtKeyId(g,B),searcher:Q});return u&&u.length?[{idx:c,item:g,matches:u}]:[]}const l=[];for(let B=0,Q=a.children.length;B<Q;B+=1){const u=a.children[B],d=n(u,g,c);if(d.length)l.push(...d);else if(a.operator===oc.AND)return[]}return l},r=this._myIndex.records,s={},i=[];return r.forEach(({$:a,i:g})=>{if(Yn(a)){let c=n(t,a,g);c.length&&(s[g]||(s[g]={idx:g,item:a,matches:[]},i.push(s[g])),c.forEach(({matches:l})=>{s[g].matches.push(...l)}))}}),i}_searchObjectList(e){const t=yB(e,this.options),{keys:n,records:r}=this._myIndex,s=[];return r.forEach(({$:i,i:a})=>{if(!Yn(i))return;let g=[];n.forEach((c,l)=>{g.push(...this._findMatches({key:c,value:i[l],searcher:t}))}),g.length&&s.push({idx:a,item:i,matches:g})}),s}_findMatches({key:e,value:t,searcher:n}){if(!Yn(t))return[];let r=[];if(cs(t))t.forEach(({v:s,i,n:a})=>{if(!Yn(s))return;const{isMatch:g,score:c,indices:l}=n.searchIn(s);g&&r.push({score:c,key:e,value:s,idx:i,norm:a,indices:l})});else{const{v:s,n:i}=t,{isMatch:a,score:g,indices:c}=n.searchIn(s);a&&r.push({score:g,key:e,value:s,norm:i,indices:c})}return r}}Ts.version="7.1.0";Ts.createIndex=Dh;Ts.parseIndex=Mk;Ts.config=Ie;Ts.parseQuery=Mh;Hk(Yk);function Xk(A){switch(A.split(".").pop()?.toLowerCase()){case"ts":case"tsx":case"js":case"jsx":case"mjs":case"cjs":case"py":case"rb":case"go":case"rs":case"java":case"c":case"cpp":case"h":case"hpp":return qc;case"json":case"yaml":case"yml":case"toml":return m1;case"md":case"txt":case"log":return so;case"png":case"jpg":case"jpeg":case"gif":case"svg":case"webp":return zQ;case"css":case"scss":case"sass":case"less":return p1;case"html":case"xml":return h1;default:return bs}}function $k(A,e){const t=e.get(A);return t?{added:{icon:Qr,label:"Added",className:"text-green-500"},modified:{icon:Ac,label:"Modified",className:"text-yellow-500"},untracked:{icon:Qr,label:"Untracked",className:"text-blue-500"}}[t]||{icon:Ac,label:"Modified",className:"text-yellow-500"}:null}function AM({files:A,changedFiles:e=[],query:t,selectedIndex:n,onSelect:r,onEnterSelect:s,onClose:i}){const a=k.useMemo(()=>new Map(e?.map(l=>[l.path,l.status])||[]),[e]),g=k.useMemo(()=>new Ts(A.map(l=>({path:l,filename:l.split("/").pop()||l,normalized:l.replace(/[.\-_/]/g,"")})),{keys:[{name:"filename",weight:2},{name:"normalized",weight:1.5},{name:"path",weight:1}],threshold:.3,distance:200,ignoreLocation:!0,includeScore:!0}),[A]),c=k.useMemo(()=>{if(!t)return A.slice(0,20);const l=t.replace(/[.\-_/]/g,""),B=g.search(l);return B.sort((Q,u)=>{const d=Q.score??1,f=u.score??1;if(Math.abs(d-f)<.05){const x=a.has(Q.item.path),b=a.has(u.item.path);if(x&&!b)return-1;if(!x&&b)return 1}return d-f}),B.slice(0,20).map(Q=>Q.item.path)},[g,t,A,a]);return k.useEffect(()=>{document.getElementById(`file-item-${n}`)?.scrollIntoView({block:"nearest"})},[n]),k.useEffect(()=>{s(c[n])},[c,n,s]),k.useEffect(()=>{const l=B=>{B.target.closest("[data-file-mention-popup]")||i()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[i]),c.length===0?o.jsx("div",{"data-file-mention-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg z-50 p-3",children:o.jsx("span",{className:"text-muted-foreground text-sm",children:"No files found"})}):o.jsx("div",{"data-file-mention-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg max-h-[300px] overflow-y-auto z-50",children:c.map((l,B)=>o.jsx("button",{type:"button",id:`file-item-${B}`,onMouseDown:Q=>{Q.preventDefault(),r(l)},className:`w-full text-left px-3 py-2 hover:bg-accent ${B===n?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2 w-full",children:[(()=>{const Q=Xk(l);return o.jsx(Q,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"})})(),o.jsx("span",{className:"font-mono text-sm flex-1 truncate",children:l}),(()=>{const Q=$k(l,a);return Q&&o.jsx("span",{title:Q.label,children:o.jsx(Q.icon,{className:`w-3.5 h-3.5 flex-shrink-0 ${Q.className}`})})})()]})},l))})}function eM(){if(typeof window<"u"&&typeof window.fetch=="function")return"fetch"}function XA(A){if(!A)return"Unknown error";if(typeof A=="string")return A;if(A&&typeof A=="object"){const e=A;if(e.error&&typeof e.error=="object"){const t=e.error;if(typeof t.message=="string")return t.message}if(typeof e.error=="string")return e.error;if(typeof e.message=="string")return e.message;try{return JSON.stringify(A)}catch{return"Error occurred (unable to parse)"}}return"Unknown error"}function tM(){const e=window.OTTO_SERVER_URL||Rs;SA.setConfig({baseURL:e,adapter:eM()})}tM();function vh(){const A=window;return A.OTTO_SERVER_URL?A.OTTO_SERVER_URL:Rs}function Xl(A){return{...A,title:A.title??null,createdAt:typeof A.createdAt=="string"?new Date(A.createdAt).getTime():A.createdAt,lastActiveAt:typeof A.lastActiveAt=="string"?new Date(A.lastActiveAt).getTime():A.lastActiveAt}}function nM(A){return{...A,createdAt:typeof A.createdAt=="string"?new Date(A.createdAt).getTime():A.createdAt,completedAt:A.completedAt?typeof A.completedAt=="string"?new Date(A.completedAt).getTime():A.completedAt:null}}const Jn={async getSessions(){return(await this.getSessionsPage({limit:200})).items},async getSessionsPage(A={}){const{limit:e=50,offset:t=0}=A,n=await rN({query:{limit:e,offset:t}});if(n.error)throw new Error(XA(n.error));const r=n.data;return{items:(r?.items??[]).map(s=>Xl(s)),hasMore:r?.hasMore??!1,nextOffset:r?.nextOffset??null}},async createSession(A){const e=await sN({body:A});if(e.error)throw new Error(XA(e.error));if(!e.data)throw new Error("No data returned from create session");return Xl(e.data)},async updateSession(A,e){const t=await Vb({path:{sessionId:A},body:e});if(t.error)throw new Error(XA(t.error));return Xl(t.data)},async deleteSession(A){const e=await Wb({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async abortSession(A){const e=await xC({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async abortMessage(A,e){const t=await xC({path:{sessionId:A}});if(t.error)throw new Error("Failed to abort message");return t.data},async getQueueState(A){const e=await Zb({path:{sessionId:A}});if(e.error)throw new Error("Failed to get queue state");return e.data},async removeFromQueue(A,e){const t=await Xb({path:{sessionId:A,messageId:e}});if(t.error)throw new Error("Failed to remove from queue");return t.data},async getMessages(A){const e=await Yb({path:{id:A}});if(e.error)throw new Error(XA(e.error));return(e.data||[]).map(nM)},async sendMessage(A,e){const t=await Hb({path:{id:A},body:e});if(t.error)throw new Error(XA(t.error));return t.data},getStreamUrl(A){return`${vh()}/v1/sessions/${A}/stream`},async retryMessage(A,e){const t=await $b({path:{sessionId:A,messageId:e}});if(t.error)throw new Error(XA(t.error));return t.data}},un={async initGitRepo(){const A=await mb();if(A.error)throw new Error(XA(A.error));return A.data?.data},async getGitStatus(){const A=await wb();if(A.error)throw new Error(XA(A.error));return A.data?.data},async getGitDiff(A,e=!1){const t=await wC({query:{file:A,staged:e?"true":"false"}});if(t.error)throw new Error(XA(t.error));return t.data?.data},async getGitDiffFullFile(A,e=!1){const t=await wC({query:{file:A,staged:e?"true":"false",fullFile:"true"}});if(t.error)throw new Error(XA(t.error));return t.data?.data},async generateCommitMessage(A){const e=await Nb({body:A?{sessionId:A}:{}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async stageFiles(A){const e=await yb({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async unstageFiles(A){const e=await Db({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async restoreFiles(A){const e=await vb({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async deleteFiles(A){const e=await Sb({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async commitChanges(A){const e=await bb({body:{message:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async getGitBranch(){const A=await xb();if(A.error)throw new Error(XA(A.error));return A.data?.data},async pushCommits(){const A=await kb({body:{}});if(A.error)throw new Error(XA(A.error));return A.data?.data},async pullChanges(){const A=await Mb({body:{}});if(A.error)throw new Error(XA(A.error));return A.data?.data},async getRemotes(){const A=await Gb();if(A.error)throw new Error(XA(A.error));return A.data?.data?.remotes},async addRemote(A,e){const t=await Rb({body:{name:A,url:e}});if(t.error)throw new Error(XA(t.error));return t.data?.data},async removeRemote(A){const e=await Fb({body:{name:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data}},mg={async getConfig(){const A=await Eb();if(A.error)throw new Error(XA(A.error));return A.data},async getModels(A){const e=await db({path:{provider:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getAllModels(){const A=await Ib();if(A.error)throw new Error(XA(A.error));return A.data},async updateDefaults(A){const e=await Cb({body:A});if(e.error)throw new Error(XA(e.error));return e.data}},wg={async listFiles(){const A=await fb();if(A.error)throw new Error(XA(A.error));return A.data},async getFileTree(A="."){const e=await hb({query:{path:A}});if(e.error)throw new Error(XA(e.error));return e.data},async readFileContent(A){const e=await pb({query:{path:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getSessionFiles(A){const e=await nN({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data}},Go={async createBranch(A,e){const t=await ub({path:{sessionId:A},body:e});if(t.error)throw new Error(XA(t.error));return t.data},async listBranches(A){const e=await Bb({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getParentSession(A){const e=await Qb({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getShareStatus(A){const e=await AN({path:{sessionId:A}});return e.error?{shared:!1}:e.data},async shareSession(A){const e=await eN({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async syncSession(A){const e=await tN({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data}},RC={async approveToolCall(A,e,t){const n=await _b({path:{id:A},body:{callId:e,approved:t,sessionId:A}});if(n.error)throw new Error("Failed to send tool approval");return n.data},async getPendingApprovals(A){const e=await zb({path:{id:A}});return e.error?{ok:!1,pending:[]}:e.data}},Zn={async getSetuBalance(){try{const A=await oN();return A.error?null:A.data}catch{return null}},async getSetuWallet(){try{const A=await iN();return A.error?{configured:!1}:A.data}catch{return{configured:!1}}},async getSetuUsdcBalance(A="mainnet"){try{const e=await aN({query:{network:A}});return e.error?null:e.data}catch{return null}},async getPolarTopupEstimate(A){try{const e=await BN({query:{amount:A}});return e.error?null:e.data}catch{return null}},async createPolarCheckout(A,e){const t=await gN({body:{amount:A,successUrl:e}});if(t.error)throw new Error(XA(t.error));return t.data},async selectTopupMethod(A,e){const t=await cN({body:{sessionId:A,method:e}});if(t.error)throw new Error(XA(t.error));return t.data},async cancelTopup(A,e){const t=await lN({body:{sessionId:A,reason:e}});if(t.error)throw new Error(XA(t.error));return t.data},async getPendingTopup(A){try{const e=await uN({query:{sessionId:A}});return e.error?{hasPending:!1}:e.data}catch{return{hasPending:!1}}},async getPolarTopupStatus(A){try{const e=await QN({query:{checkoutId:A}});return e.error?null:e.data}catch{return null}},async getRazorpayTopupEstimate(A){try{const e=await EN({query:{amount:A}});return e.error?null:e.data}catch{return null}},async createRazorpayOrder(A){const e=await dN({body:{amount:A}});if(e.error)throw new Error(XA(e.error));return e.data},async verifyRazorpayPayment(A){const e=await CN({body:A});if(e.error)throw new Error(XA(e.error));return e.data}},en={async getAuthStatus(){const A=await Z2();if(A.error)throw new Error(XA(A.error));return A.data},async setupSetuWallet(){const A=await X2();if(A.error)throw new Error(XA(A.error));return A.data},async importSetuWallet(A){const e=await $2({body:{privateKey:A}});if(e.error)throw new Error(XA(e.error));return e.data},async exportSetuWallet(){const A=await Ab();if(A.error)throw new Error(XA(A.error));return A.data},async addProvider(A,e){const t=await tb({path:{provider:A},body:{apiKey:e}});if(t.error)throw new Error(XA(t.error));return t.data},async removeProvider(A){const e=await eb({path:{provider:A}});if(e.error)throw new Error(XA(e.error));return e.data},async completeOnboarding(){const A=await lb();if(A.error)throw new Error(XA(A.error));return A.data},getOAuthStartUrl(A,e){const t=`${vh()}/v1/auth/${A}/oauth/start`;return e?`${t}?mode=${e}`:t},async getOAuthUrl(A,e){const t=await nb({path:{provider:A},body:{mode:e}});if(t.error)throw new Error(XA(t.error));return t.data},async exchangeOAuthCode(A,e,t){const n=await rb({path:{provider:A},body:{code:e,sessionId:t}});if(n.error)throw new Error(XA(n.error));return n.data},async startCopilotDeviceFlow(){const A=await sb();if(A.error)throw new Error(XA(A.error));return A.data},async pollCopilotDeviceFlow(A){const e=await ob({body:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getCopilotAuthMethods(){const A=await ib();if(A.error)throw new Error(XA(A.error));return A.data},async saveCopilotToken(A){const e=await ab({body:{token:A}});if(e.error)throw new Error(XA(e.error));return e.data},async importCopilotTokenFromGh(){const A=await gb();if(A.error)throw new Error(XA(A.error));return A.data},async getCopilotDiagnostics(){const A=await cb();if(A.error)throw new Error(XA(A.error));return A.data},async getProviderUsage(A){const e=await Pb({path:{provider:A}});if(e.error)throw new Error(XA(e.error));return e.data}},xg={async listSkills(){const A=await IN();if(A.error)throw new Error(XA(A.error));return A.data},async getSkill(A){const e=await fN({path:{name:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getSkillFiles(A){const e=await hN({path:{name:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getSkillFileContent(A,e){const t=await pN({path:{name:A,filePath:e}});if(t.error)throw new Error(XA(t.error));return t.data}};class rM{getSessions=Jn.getSessions;getSessionsPage=Jn.getSessionsPage;createSession=Jn.createSession;updateSession=Jn.updateSession;deleteSession=Jn.deleteSession;abortSession=Jn.abortSession;abortMessage=Jn.abortMessage;getQueueState=Jn.getQueueState;removeFromQueue=Jn.removeFromQueue;getMessages=Jn.getMessages;sendMessage=Jn.sendMessage;getStreamUrl=Jn.getStreamUrl;retryMessage=Jn.retryMessage;initGitRepo=un.initGitRepo;getGitStatus=un.getGitStatus;getGitDiff=un.getGitDiff;getGitDiffFullFile=un.getGitDiffFullFile;generateCommitMessage=un.generateCommitMessage;stageFiles=un.stageFiles;unstageFiles=un.unstageFiles;restoreFiles=un.restoreFiles;deleteFiles=un.deleteFiles;commitChanges=un.commitChanges;getGitBranch=un.getGitBranch;pushCommits=un.pushCommits;pullChanges=un.pullChanges;getRemotes=un.getRemotes;addRemote=un.addRemote;removeRemote=un.removeRemote;getConfig=mg.getConfig;getModels=mg.getModels;getAllModels=mg.getAllModels;updateDefaults=mg.updateDefaults;listFiles=wg.listFiles;getFileTree=wg.getFileTree;readFileContent=wg.readFileContent;getSessionFiles=wg.getSessionFiles;createBranch=Go.createBranch;listBranches=Go.listBranches;getParentSession=Go.getParentSession;getShareStatus=Go.getShareStatus;shareSession=Go.shareSession;syncSession=Go.syncSession;approveToolCall=RC.approveToolCall;getPendingApprovals=RC.getPendingApprovals;getSetuBalance=Zn.getSetuBalance;getSetuWallet=Zn.getSetuWallet;getSetuUsdcBalance=Zn.getSetuUsdcBalance;getPolarTopupEstimate=Zn.getPolarTopupEstimate;createPolarCheckout=Zn.createPolarCheckout;selectTopupMethod=Zn.selectTopupMethod;cancelTopup=Zn.cancelTopup;getPendingTopup=Zn.getPendingTopup;getPolarTopupStatus=Zn.getPolarTopupStatus;getRazorpayTopupEstimate=Zn.getRazorpayTopupEstimate;createRazorpayOrder=Zn.createRazorpayOrder;verifyRazorpayPayment=Zn.verifyRazorpayPayment;getAuthStatus=en.getAuthStatus;setupSetuWallet=en.setupSetuWallet;importSetuWallet=en.importSetuWallet;exportSetuWallet=en.exportSetuWallet;addProvider=en.addProvider;removeProvider=en.removeProvider;completeOnboarding=en.completeOnboarding;getOAuthStartUrl=en.getOAuthStartUrl;getOAuthUrl=en.getOAuthUrl;exchangeOAuthCode=en.exchangeOAuthCode;startCopilotDeviceFlow=en.startCopilotDeviceFlow;pollCopilotDeviceFlow=en.pollCopilotDeviceFlow;getCopilotAuthMethods=en.getCopilotAuthMethods;saveCopilotToken=en.saveCopilotToken;importCopilotTokenFromGh=en.importCopilotTokenFromGh;getCopilotDiagnostics=en.getCopilotDiagnostics;getProviderUsage=en.getProviderUsage;listSkills=xg.listSkills;getSkill=xg.getSkill;getSkillFiles=xg.getSkillFiles;getSkillFileContent=xg.getSkillFileContent}const xA=new rM;function bo(){return bt({queryKey:["config"],queryFn:()=>xA.getConfig(),staleTime:3e4})}function La(){return bt({queryKey:["models","all"],queryFn:()=>xA.getAllModels()})}function $c(){const A=Ye();return it({mutationFn:e=>xA.updateDefaults(e),onMutate:async e=>{await A.cancelQueries({queryKey:["config"]});const t=A.getQueryData(["config"]);if(t){const n=Object.fromEntries(Object.entries(e).filter(([r,s])=>r!=="scope"&&s!==void 0));A.setQueryData(["config"],{...t,defaults:{...t.defaults,...n}})}return{previousConfig:t}},onError:(e,t,n)=>{n?.previousConfig&&A.setQueryData(["config"],n.previousConfig)},onSuccess:()=>{A.invalidateQueries({queryKey:["config"]})}})}const Sh="otto-preferences",Hi={vimMode:!1,compactThread:!0};function sM(){if(typeof window>"u")return Hi;try{const A=window.localStorage.getItem(Sh);if(A){const e=JSON.parse(A);return{vimMode:typeof e.vimMode=="boolean"?e.vimMode:Hi.vimMode,compactThread:typeof e.compactThread=="boolean"?e.compactThread:Hi.compactThread}}}catch(A){console.warn("Failed to load preferences",A)}return Hi}let Hg=sM();const NB=new Set;function oM(){return Hg}function iM(){return Hi}function aM(A){return NB.add(A),()=>NB.delete(A)}function gM(){for(const A of NB)A()}function cM(A){if(Hg={...Hg,...A},typeof window<"u")try{window.localStorage.setItem(Sh,JSON.stringify(Hg))}catch(e){console.warn("Failed to persist preferences",e)}gM()}function hi(){const A=k.useSyncExternalStore(aM,oM,iM),{data:e}=bo(),t=$c(),n=k.useCallback(s=>{const i={};s.vimMode!==void 0&&(i.vimMode=s.vimMode),s.compactThread!==void 0&&(i.compactThread=s.compactThread),Object.keys(i).length>0&&cM(i),s.fullWidthContent!==void 0&&s.fullWidthContent!==e?.defaults?.fullWidthContent&&t.mutate({fullWidthContent:s.fullWidthContent,scope:"global"})},[e?.defaults?.fullWidthContent,t]),r=k.useMemo(()=>({...A,fullWidthContent:e?.defaults?.fullWidthContent??!1}),[A,e?.defaults?.fullWidthContent]);return k.useMemo(()=>({preferences:r,updatePreferences:n}),[r,n])}function gE(A){const{data:e,isLoading:t,error:n}=bt({queryKey:["share-status",A],queryFn:()=>xA.getShareStatus(A),enabled:!!A,staleTime:3e4});return{data:e,isLoading:t,error:n}}const Fh=[{id:"models",label:"/models",description:"Open model selector",icon:Rr},{id:"agents",label:"/agents",description:"Open agent selector",icon:Pn},{id:"new",label:"/new",description:"Create new session",icon:Qr},{id:"stop",label:"/stop",description:"Stop current generation",icon:yf},{id:"help",label:"/help",description:"Show keyboard shortcuts and help",icon:Df},{id:"vim",label:"/vim",description:A=>A.vimModeEnabled?"Disable Vim mode":"Enable Vim mode",icon:w1},{id:"reasoning",label:"/reasoning",description:A=>A.reasoningEnabled?"Disable extended thinking":"Enable extended thinking",icon:Yc},{id:"stage",label:"/stage",description:"Stage all changes (git add -A)",icon:_n},{id:"commit",label:"/commit",description:"Commit staged changes",icon:Dn},{id:"compact",label:"/compact",description:"Compact conversation to reduce context size",icon:PQ},{id:"branch",label:"/branch",description:"Branch session from last message",icon:x1},{id:"delete",label:"/delete",description:"Delete current session",icon:Ma},{id:"share",label:"/share",description:"Share session publicly",icon:WQ},{id:"sync",label:"/sync",description:"Sync new messages to shared session",icon:Sn}];function Gh(A,e){return typeof A.description=="function"?A.description(e):A.description}function lM(A,e){const t=Fh.filter(s=>!(s.id==="share"&&e.isShared||s.id==="sync"&&!e.isShared));if(!A)return t;const n=A.toLowerCase(),r=[];for(const s of t){const i=Gh(s,e),a=s.label.toLowerCase().includes(n),g=i.toLowerCase().includes(n);if(a||g){const c=a?10:5;r.push({...s,matchScore:c})}}return r.sort((s,i)=>{const a=i.matchScore-s.matchScore;return a!==0?a:s.label.localeCompare(i.label)})}function uM({query:A,selectedIndex:e,onSelect:t,onEnterSelect:n,onClose:r,sessionId:s}){const{preferences:i}=hi(),{data:a}=bo(),{data:g}=gE(s),c=k.useMemo(()=>({vimModeEnabled:i.vimMode,reasoningEnabled:a?.defaults?.reasoningText??!0,isShared:g?.shared}),[i.vimMode,a?.defaults?.reasoningText,g?.shared]),l=k.useMemo(()=>lM(A,c),[A,c]);return k.useEffect(()=>{document.getElementById(`command-item-${e}`)?.scrollIntoView({block:"nearest"})},[e]),k.useEffect(()=>{n(l[e]?.id)},[l,e,n]),k.useEffect(()=>{const B=Q=>{Q.target.closest("[data-command-popup]")||r()};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[r]),l.length===0?o.jsx("div",{"data-command-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg z-50 p-3",children:o.jsx("span",{className:"text-muted-foreground text-sm",children:"No commands found"})}):o.jsx("div",{"data-command-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg max-h-[300px] overflow-y-auto z-50",children:l.map((B,Q)=>{const u=B.icon;return o.jsx("button",{type:"button",id:`command-item-${Q}`,onMouseDown:d=>{d.preventDefault(),t(B.id)},className:`w-full text-left px-3 py-2 hover:bg-accent ${Q===e?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-3 w-full",children:[o.jsx(u,{className:"w-4 h-4 flex-shrink-0 text-primary"}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"font-mono text-sm font-medium text-foreground",children:B.label}),o.jsx("div",{className:"text-xs text-muted-foreground truncate",children:Gh(B,c)})]})]})},B.id)})})}const BM={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl"};function ds({isOpen:A,onClose:e,title:t,children:n,showCloseButton:r=!0,closeOnBackdropClick:s=!0,closeOnEscape:i=!0,maxWidth:a="md"}){if(k.useEffect(()=>{if(!A||!i)return;const c=l=>{const B=l.target,Q=B.tagName==="INPUT"||B.tagName==="TEXTAREA"||B.isContentEditable;(l.key==="Escape"||l.key==="q"&&!Q)&&(l.preventDefault(),l.stopPropagation(),e())};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[A,i,e]),k.useEffect(()=>{if(A)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[A]),!A)return null;const g=c=>{s&&c.target===c.currentTarget&&e()};return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-[9999] cursor-default",onClick:g,onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&g(c)},"aria-label":"Close modal"}),o.jsx("div",{className:`fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[9999] w-full ${BM[a]} px-4`,children:o.jsxs("div",{className:"bg-background border border-border rounded-lg shadow-lg",children:[(t||r)&&o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[t&&o.jsx("div",{className:"text-lg font-semibold text-foreground",children:t}),r&&o.jsx("button",{type:"button",onClick:e,className:"text-muted-foreground hover:text-foreground transition-colors ml-auto","aria-label":"Close",children:o.jsx(yt,{className:"h-5 w-5"})})]}),o.jsx("div",{className:"p-6",children:n})]})})]})}const QM=[{keys:["Ctrl","H"],description:"Navigate to left sidebar (sessions)",category:"Navigation"},{keys:["Ctrl","L"],description:"Navigate to right sidebar (git)",category:"Navigation"},{keys:["Ctrl","/"],description:"Toggle left sidebar collapse/expand",category:"Navigation"},{keys:["Ctrl","\\"],description:"Toggle right sidebar collapse/expand",category:"Navigation"},{keys:["Ctrl","N"],description:"Create new session",category:"Navigation"},{keys:["ESC"],description:"Close sidebar and return to center",category:"Navigation"},{keys:["J"],description:"Navigate to next item (in focused list)",category:"List Navigation"},{keys:["K"],description:"Navigate to previous item (in focused list)",category:"List Navigation"},{keys:["Enter"],description:"Select focused item and return to input",category:"List Navigation"},{keys:["Space"],description:"Toggle stage/unstage for focused file (git panel)",category:"Git Operations"},{keys:["A"],description:"Stage all unstaged files",category:"Git Operations"},{keys:["U"],description:"Unstage all staged files",category:"Git Operations"},{keys:["C"],description:"Open commit modal (if files are staged)",category:"Git Operations"},{keys:["Tab"],description:"Toggle plan mode",category:"Chat"},{keys:["Enter"],description:"Send message",category:"Chat"},{keys:["Shift","Enter"],description:"New line in message",category:"Chat"},{keys:["@"],description:"Mention file (opens file picker)",category:"Chat"},{keys:["/"],description:"Slash command (opens command menu)",category:"Chat"}],EM=[{keys:["i"],description:"Enter insert mode at cursor (vim mode)",category:"Vim Mode"},{keys:["a"],description:"Enter insert mode after cursor (vim mode)",category:"Vim Mode"},{keys:["I"],description:"Enter insert mode at line start (vim mode)",category:"Vim Mode"},{keys:["A"],description:"Enter insert mode at line end (vim mode)",category:"Vim Mode"},{keys:["o"],description:"New line below and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["O"],description:"New line above and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["ESC"],description:"Return to normal mode (vim mode)",category:"Vim Mode"},{keys:["Enter"],description:"Send message in normal mode (vim mode)",category:"Vim Mode"},{keys:["w"],description:"Jump to next word start (vim mode)",category:"Vim Mode"},{keys:["e"],description:"Jump to next word end (vim mode)",category:"Vim Mode"},{keys:["b"],description:"Jump to previous word start (vim mode)",category:"Vim Mode"},{keys:["x"],description:"Delete character under cursor (vim mode)",category:"Vim Mode"},{keys:["s"],description:"Delete character and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["S"],description:"Delete line and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["f","{char}"],description:"Find and jump to next character on line (vim mode)",category:"Vim Mode"},{keys:["d","d"],description:"Delete current line (vim mode)",category:"Vim Mode"},{keys:["0"],description:"Jump to line start (vim mode)",category:"Vim Mode"},{keys:["$"],description:"Jump to line end (vim mode)",category:"Vim Mode"}],dM=[{command:"/models",description:"Open model selector"},{command:"/agents",description:"Open agent selector"},{command:"/new",description:"Create new session"},{command:"/help",description:"Show keyboard shortcuts and help (this modal)"},{command:"/compact",description:"Compact conversation to reduce context size"}];function CM(A){const e={};for(const t of A)e[t.category]||(e[t.category]=[]),e[t.category].push(t);return e}function IM({isOpen:A,onClose:e}){const t=[...QM,...EM],n=CM(t),r=k.useRef(null),s=k.useRef(null);return k.useEffect(()=>{A?(s.current=document.activeElement,s.current&&s.current.blur()):s.current&&(s.current.focus(),s.current=null)},[A]),k.useEffect(()=>{if(!A)return;const i=a=>{const g=a.target;if(!(g.tagName==="INPUT"||g.tagName==="TEXTAREA"||g.isContentEditable))if(a.key==="j"){a.preventDefault();const l=r.current;l&&l.scrollBy({top:100,behavior:"smooth"})}else if(a.key==="k"){a.preventDefault();const l=r.current;l&&l.scrollBy({top:-100,behavior:"smooth"})}else a.key==="Enter"&&(a.preventDefault(),e())};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[A,e]),o.jsx(ds,{isOpen:A,onClose:e,title:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Df,{className:"w-5 h-5"}),o.jsx("span",{children:"Keyboard Shortcuts & Help"})]}),maxWidth:"2xl",closeOnEscape:!0,closeOnBackdropClick:!0,children:o.jsxs("div",{ref:r,className:"space-y-6 max-h-[70vh] overflow-y-auto",children:[Object.entries(n).map(([i,a])=>o.jsxs("div",{children:[o.jsxs("h3",{className:"text-sm font-semibold text-foreground mb-3 flex items-center gap-2",children:[o.jsx(Xd,{className:"w-4 h-4"}),i]}),o.jsx("div",{className:"space-y-2",children:a.map((g,c)=>o.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-lg bg-accent/50 hover:bg-accent transition-colors",children:[o.jsx("span",{className:"text-sm text-foreground",children:g.description}),o.jsx("div",{className:"flex items-center gap-1",children:g.keys.map(l=>o.jsxs("span",{className:"flex items-center gap-1",children:[o.jsx("kbd",{className:"px-2 py-1 text-xs font-mono bg-background border border-border rounded shadow-sm",children:l}),g.keys.indexOf(l)<g.keys.length-1&&o.jsx("span",{className:"text-muted-foreground",children:"+"})]},l))})]},`${i}-${g.description}`))})]},i)),o.jsxs("div",{children:[o.jsxs("h3",{className:"text-sm font-semibold text-foreground mb-3 flex items-center gap-2",children:[o.jsx(Xd,{className:"w-4 h-4"}),"Slash Commands"]}),o.jsx("div",{className:"space-y-2",children:dM.map((i,a)=>o.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-lg bg-accent/50 hover:bg-accent transition-colors",children:[o.jsx("span",{className:"text-sm text-foreground",children:i.description}),o.jsx("kbd",{className:"px-2 py-1 text-xs font-mono bg-background border border-border rounded shadow-sm",children:i.command})]},i.command))})]}),o.jsx("div",{className:"pt-4 border-t border-border",children:o.jsxs("p",{className:"text-xs text-muted-foreground",children:[o.jsx("strong",{children:"Tip:"})," Shortcuts are disabled when typing in input fields. Press ",o.jsx("kbd",{className:"text-xs",children:"ESC"})," to close popups and return focus to chat input."]})})]})})}const fM=`<svg width="24" height="24" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
36
+ `,onClick:r,role:"alert",children:[ak[A.type],o.jsx("span",{className:"text-sm text-foreground",children:A.message}),A.action&&o.jsxs("button",{type:"button",onClick:s=>{s.stopPropagation(),Br(A.action?.href)},className:"ml-auto flex items-center gap-1 text-xs text-primary hover:underline",children:[A.action.label,o.jsx(rn,{className:"h-3 w-3"})]})]})}function ck(){const A=Er(e=>e.toasts);return A.length===0?null:o.jsx("div",{className:"fixed bottom-4 right-4 z-[9999] flex flex-col gap-2 max-w-sm",children:A.map(e=>o.jsx(gk,{toast:e},e.id))})}const Ta=Rt(A=>({pendingApprovals:[],addPendingApproval:e=>A(t=>({pendingApprovals:[...t.pendingApprovals,e]})),removePendingApproval:e=>A(t=>({pendingApprovals:t.pendingApprovals.filter(n=>n.callId!==e)})),updatePendingApproval:(e,t)=>A(n=>({pendingApprovals:n.pendingApprovals.map(r=>r.callId===e?{...r,args:t}:r)})),clearPendingApprovals:()=>A({pendingApprovals:[]}),setPendingApprovals:e=>A({pendingApprovals:e})}));function lk(A,e){let t;try{t=A()}catch{return}return{getItem:r=>{var s;const i=g=>g===null?null:JSON.parse(g,void 0),a=(s=t.getItem(r))!=null?s:null;return a instanceof Promise?a.then(i):i(a)},setItem:(r,s)=>t.setItem(r,JSON.stringify(s,void 0)),removeItem:r=>t.removeItem(r)}}const pB=A=>e=>{try{const t=A(e);return t instanceof Promise?t:{then(n){return pB(n)(t)},catch(n){return this}}}catch(t){return{then(n){return this},catch(n){return pB(n)(t)}}}},uk=(A,e)=>(t,n,r)=>{let s={storage:lk(()=>window.localStorage),partialize:h=>h,version:0,merge:(h,x)=>({...x,...h}),...e},i=!1,a=0;const g=new Set,c=new Set;let l=s.storage;if(!l)return A((...h)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),t(...h)},n,r);const B=()=>{const h=s.partialize({...n()});return l.setItem(s.name,{state:h,version:s.version})},Q=r.setState;r.setState=(h,x)=>(Q(h,x),B());const u=A((...h)=>(t(...h),B()),n,r);r.getInitialState=()=>u;let d;const f=()=>{var h,x;if(!l)return;const b=++a;i=!1,g.forEach(M=>{var G;return M((G=n())!=null?G:u)});const m=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(h=n())!=null?h:u))||void 0;return pB(l.getItem.bind(l))(s.name).then(M=>{if(M)if(typeof M.version=="number"&&M.version!==s.version){if(s.migrate){const G=s.migrate(M.state,M.version);return G instanceof Promise?G.then(Y=>[!0,Y]):[!0,G]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,M.state];return[!1,void 0]}).then(M=>{var G;if(b!==a)return;const[Y,Z]=M;if(d=s.merge(Z,(G=n())!=null?G:u),t(d,!0),Y)return B()}).then(()=>{b===a&&(m?.(n(),void 0),d=n(),i=!0,c.forEach(M=>M(d)))}).catch(M=>{b===a&&m?.(void 0,M)})};return r.persist={setOptions:h=>{s={...s,...h},h.storage&&(l=h.storage)},clearStorage:()=>{l?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>f(),hasHydrated:()=>i,onHydrate:h=>(g.add(h),()=>{g.delete(h)}),onFinishHydration:h=>(c.add(h),()=>{c.delete(h)})},s.skipHydration||f(),d||u},ph=uk,ks=Rt()(ph((A,e)=>({widths:{},setWidth:(t,n)=>A(r=>({widths:{...r.widths,[t]:n}})),getWidth:(t,n)=>e().widths[t]??n}),{name:"panel-widths"})),fi=k.memo(function({panelKey:e,side:t,minWidth:n,maxWidth:r,defaultWidth:s,onWidthChange:i}){const a=k.useRef(null),g=k.useCallback(c=>{c.preventDefault();const l=ks.getState().getWidth(e,s);a.current={startX:c.clientX,startWidth:l};const B=u=>{if(!a.current)return;const d=u.clientX-a.current.startX,f=t==="right"?a.current.startWidth-d:a.current.startWidth+d,h=Math.min(Math.max(n,f),r);ks.getState().setWidth(e,h),i?.(h)},Q=()=>{a.current=null,document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",Q),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",B),document.addEventListener("mouseup",Q),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[e,t,n,r,s,i]);return o.jsx("div",{className:`w-1 h-full cursor-col-resize hover:bg-primary/30 active:bg-primary/50 transition-colors absolute top-0 bottom-0 z-10 ${t==="right"?"left-0":"right-0"}`,onMouseDown:g})});function cs(A){return Array.isArray?Array.isArray(A):xh(A)==="[object Array]"}function Bk(A){if(typeof A=="string")return A;let e=A+"";return e=="0"&&1/A==-1/0?"-0":e}function Qk(A){return A==null?"":Bk(A)}function vr(A){return typeof A=="string"}function mh(A){return typeof A=="number"}function Ek(A){return A===!0||A===!1||dk(A)&&xh(A)=="[object Boolean]"}function wh(A){return typeof A=="object"}function dk(A){return wh(A)&&A!==null}function Yn(A){return A!=null}function Zl(A){return!A.trim().length}function xh(A){return A==null?A===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(A)}const Ck="Incorrect 'index' type",Ik=A=>`Invalid value for key ${A}`,fk=A=>`Pattern length exceeds max of ${A}.`,hk=A=>`Missing ${A} property in key`,pk=A=>`Property 'weight' in key '${A}' must be a positive integer`,MC=Object.prototype.hasOwnProperty;class mk{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(n=>{let r=yh(n);this._keys.push(r),this._keyMap[r.id]=r,t+=r.weight}),this._keys.forEach(n=>{n.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function yh(A){let e=null,t=null,n=null,r=1,s=null;if(vr(A)||cs(A))n=A,e=vC(A),t=mB(A);else{if(!MC.call(A,"name"))throw new Error(hk("name"));const i=A.name;if(n=i,MC.call(A,"weight")&&(r=A.weight,r<=0))throw new Error(pk(i));e=vC(i),t=mB(i),s=A.getFn}return{path:e,id:t,weight:r,src:n,getFn:s}}function vC(A){return cs(A)?A:A.split(".")}function mB(A){return cs(A)?A.join("."):A}function wk(A,e){let t=[],n=!1;const r=(s,i,a)=>{if(Yn(s))if(!i[a])t.push(s);else{let g=i[a];const c=s[g];if(!Yn(c))return;if(a===i.length-1&&(vr(c)||mh(c)||Ek(c)))t.push(Qk(c));else if(cs(c)){n=!0;for(let l=0,B=c.length;l<B;l+=1)r(c[l],i,a+1)}else i.length&&r(c,i,a+1)}};return r(A,vr(e)?e.split("."):e,0),n?t:t[0]}const xk={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},yk={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(A,e)=>A.score===e.score?A.idx<e.idx?-1:1:A.score<e.score?-1:1},Dk={location:0,threshold:.6,distance:100},bk={useExtendedSearch:!1,getFn:wk,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var Ie={...yk,...xk,...Dk,...bk};const Nk=/[^ ]+/g;function kk(A=1,e=3){const t=new Map,n=Math.pow(10,e);return{get(r){const s=r.match(Nk).length;if(t.has(s))return t.get(s);const i=1/Math.pow(s,.5*A),a=parseFloat(Math.round(i*n)/n);return t.set(s,a),a},clear(){t.clear()}}}class aE{constructor({getFn:e=Ie.getFn,fieldNormWeight:t=Ie.fieldNormWeight}={}){this.norm=kk(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((t,n)=>{this._keysMap[t.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,vr(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();vr(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!Yn(e)||Zl(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((r,s)=>{let i=r.getFn?r.getFn(e):this.getFn(e,r.path);if(Yn(i)){if(cs(i)){let a=[];const g=[{nestedArrIndex:-1,value:i}];for(;g.length;){const{nestedArrIndex:c,value:l}=g.pop();if(Yn(l))if(vr(l)&&!Zl(l)){let B={v:l,i:c,n:this.norm.get(l)};a.push(B)}else cs(l)&&l.forEach((B,Q)=>{g.push({nestedArrIndex:Q,value:B})})}n.$[s]=a}else if(vr(i)&&!Zl(i)){let a={v:i,n:this.norm.get(i)};n.$[s]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Dh(A,e,{getFn:t=Ie.getFn,fieldNormWeight:n=Ie.fieldNormWeight}={}){const r=new aE({getFn:t,fieldNormWeight:n});return r.setKeys(A.map(yh)),r.setSources(e),r.create(),r}function Mk(A,{getFn:e=Ie.getFn,fieldNormWeight:t=Ie.fieldNormWeight}={}){const{keys:n,records:r}=A,s=new aE({getFn:e,fieldNormWeight:t});return s.setKeys(n),s.setIndexRecords(r),s}function pg(A,{errors:e=0,currentLocation:t=0,expectedLocation:n=0,distance:r=Ie.distance,ignoreLocation:s=Ie.ignoreLocation}={}){const i=e/A.length;if(s)return i;const a=Math.abs(n-t);return r?i+a/r:a?1:i}function vk(A=[],e=Ie.minMatchCharLength){let t=[],n=-1,r=-1,s=0;for(let i=A.length;s<i;s+=1){let a=A[s];a&&n===-1?n=s:!a&&n!==-1&&(r=s-1,r-n+1>=e&&t.push([n,r]),n=-1)}return A[s-1]&&s-n>=e&&t.push([n,s-1]),t}const Ys=32;function Sk(A,e,t,{location:n=Ie.location,distance:r=Ie.distance,threshold:s=Ie.threshold,findAllMatches:i=Ie.findAllMatches,minMatchCharLength:a=Ie.minMatchCharLength,includeMatches:g=Ie.includeMatches,ignoreLocation:c=Ie.ignoreLocation}={}){if(e.length>Ys)throw new Error(fk(Ys));const l=e.length,B=A.length,Q=Math.max(0,Math.min(n,B));let u=s,d=Q;const f=a>1||g,h=f?Array(B):[];let x;for(;(x=A.indexOf(e,d))>-1;){let Z=pg(e,{currentLocation:x,expectedLocation:Q,distance:r,ignoreLocation:c});if(u=Math.min(Z,u),d=x+l,f){let P=0;for(;P<l;)h[x+P]=1,P+=1}}d=-1;let b=[],m=1,M=l+B;const G=1<<l-1;for(let Z=0;Z<l;Z+=1){let P=0,L=M;for(;P<L;)pg(e,{errors:Z,currentLocation:Q+L,expectedLocation:Q,distance:r,ignoreLocation:c})<=u?P=L:M=L,L=Math.floor((M-P)/2+P);M=L;let q=Math.max(1,Q-L+1),v=i?B:Math.min(Q+L,B)+l,U=Array(v+2);U[v+1]=(1<<Z)-1;for(let E=v;E>=q;E-=1){let C=E-1,y=t[A.charAt(C)];if(f&&(h[C]=+!!y),U[E]=(U[E+1]<<1|1)&y,Z&&(U[E]|=(b[E+1]|b[E])<<1|1|b[E+1]),U[E]&G&&(m=pg(e,{errors:Z,currentLocation:C,expectedLocation:Q,distance:r,ignoreLocation:c}),m<=u)){if(u=m,d=C,d<=Q)break;q=Math.max(1,2*Q-d)}}if(pg(e,{errors:Z+1,currentLocation:Q,expectedLocation:Q,distance:r,ignoreLocation:c})>u)break;b=U}const Y={isMatch:d>=0,score:Math.max(.001,m)};if(f){const Z=vk(h,a);Z.length?g&&(Y.indices=Z):Y.isMatch=!1}return Y}function Fk(A){let e={};for(let t=0,n=A.length;t<n;t+=1){const r=A.charAt(t);e[r]=(e[r]||0)|1<<n-t-1}return e}const sc=String.prototype.normalize?(A=>A.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(A=>A);class bh{constructor(e,{location:t=Ie.location,threshold:n=Ie.threshold,distance:r=Ie.distance,includeMatches:s=Ie.includeMatches,findAllMatches:i=Ie.findAllMatches,minMatchCharLength:a=Ie.minMatchCharLength,isCaseSensitive:g=Ie.isCaseSensitive,ignoreDiacritics:c=Ie.ignoreDiacritics,ignoreLocation:l=Ie.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:s,findAllMatches:i,minMatchCharLength:a,isCaseSensitive:g,ignoreDiacritics:c,ignoreLocation:l},e=g?e:e.toLowerCase(),e=c?sc(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const B=(u,d)=>{this.chunks.push({pattern:u,alphabet:Fk(u),startIndex:d})},Q=this.pattern.length;if(Q>Ys){let u=0;const d=Q%Ys,f=Q-d;for(;u<f;)B(this.pattern.substr(u,Ys),u),u+=Ys;if(d){const h=Q-Ys;B(this.pattern.substr(h),h)}}else B(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?sc(e):e,this.pattern===e){let f={isMatch:!0,score:0};return r&&(f.indices=[[0,e.length-1]]),f}const{location:s,distance:i,threshold:a,findAllMatches:g,minMatchCharLength:c,ignoreLocation:l}=this.options;let B=[],Q=0,u=!1;this.chunks.forEach(({pattern:f,alphabet:h,startIndex:x})=>{const{isMatch:b,score:m,indices:M}=Sk(e,f,h,{location:s+x,distance:i,threshold:a,findAllMatches:g,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});b&&(u=!0),Q+=m,b&&M&&(B=[...B,...M])});let d={isMatch:u,score:u?Q/this.chunks.length:1};return u&&r&&(d.indices=B),d}}class Us{constructor(e){this.pattern=e}static isMultiMatch(e){return SC(e,this.multiRegex)}static isSingleMatch(e){return SC(e,this.singleRegex)}search(){}}function SC(A,e){const t=A.match(e);return t?t[1]:null}class Gk extends Us{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class Rk extends Us{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class Uk extends Us{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class Tk extends Us{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Lk extends Us{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class Ok extends Us{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Nh extends Us{constructor(e,{location:t=Ie.location,threshold:n=Ie.threshold,distance:r=Ie.distance,includeMatches:s=Ie.includeMatches,findAllMatches:i=Ie.findAllMatches,minMatchCharLength:a=Ie.minMatchCharLength,isCaseSensitive:g=Ie.isCaseSensitive,ignoreDiacritics:c=Ie.ignoreDiacritics,ignoreLocation:l=Ie.ignoreLocation}={}){super(e),this._bitapSearch=new bh(e,{location:t,threshold:n,distance:r,includeMatches:s,findAllMatches:i,minMatchCharLength:a,isCaseSensitive:g,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class kh extends Us{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n;const r=[],s=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+s,r.push([n,t-1]);const i=!!r.length;return{isMatch:i,score:i?0:1,indices:r}}}const wB=[Gk,kh,Uk,Tk,Ok,Lk,Rk,Nh],FC=wB.length,Kk=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,jk="|";function Jk(A,e={}){return A.split(jk).map(t=>{let n=t.trim().split(Kk).filter(s=>s&&!!s.trim()),r=[];for(let s=0,i=n.length;s<i;s+=1){const a=n[s];let g=!1,c=-1;for(;!g&&++c<FC;){const l=wB[c];let B=l.isMultiMatch(a);B&&(r.push(new l(B,e)),g=!0)}if(!g)for(c=-1;++c<FC;){const l=wB[c];let B=l.isSingleMatch(a);if(B){r.push(new l(B,e));break}}}return r})}const qk=new Set([Nh.type,kh.type]);class Yk{constructor(e,{isCaseSensitive:t=Ie.isCaseSensitive,ignoreDiacritics:n=Ie.ignoreDiacritics,includeMatches:r=Ie.includeMatches,minMatchCharLength:s=Ie.minMatchCharLength,ignoreLocation:i=Ie.ignoreLocation,findAllMatches:a=Ie.findAllMatches,location:g=Ie.location,threshold:c=Ie.threshold,distance:l=Ie.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:s,findAllMatches:a,ignoreLocation:i,location:g,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?sc(e):e,this.pattern=e,this.query=Jk(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:s}=this.options;e=r?e:e.toLowerCase(),e=s?sc(e):e;let i=0,a=[],g=0;for(let c=0,l=t.length;c<l;c+=1){const B=t[c];a.length=0,i=0;for(let Q=0,u=B.length;Q<u;Q+=1){const d=B[Q],{isMatch:f,indices:h,score:x}=d.search(e);if(f){if(i+=1,g+=x,n){const b=d.constructor.type;qk.has(b)?a=[...a,...h]:a.push(h)}}else{g=0,i=0,a.length=0;break}}if(i){let Q={isMatch:!0,score:g/i};return n&&(Q.indices=a),Q}}return{isMatch:!1,score:1}}}const xB=[];function Hk(...A){xB.push(...A)}function yB(A,e){for(let t=0,n=xB.length;t<n;t+=1){let r=xB[t];if(r.condition(A,e))return new r(A,e)}return new bh(A,e)}const oc={AND:"$and",OR:"$or"},DB={PATH:"$path",PATTERN:"$val"},bB=A=>!!(A[oc.AND]||A[oc.OR]),Pk=A=>!!A[DB.PATH],_k=A=>!cs(A)&&wh(A)&&!bB(A),GC=A=>({[oc.AND]:Object.keys(A).map(e=>({[e]:A[e]}))});function Mh(A,e,{auto:t=!0}={}){const n=r=>{let s=Object.keys(r);const i=Pk(r);if(!i&&s.length>1&&!bB(r))return n(GC(r));if(_k(r)){const g=i?r[DB.PATH]:s[0],c=i?r[DB.PATTERN]:r[g];if(!vr(c))throw new Error(Ik(g));const l={keyId:mB(g),pattern:c};return t&&(l.searcher=yB(c,e)),l}let a={children:[],operator:s[0]};return s.forEach(g=>{const c=r[g];cs(c)&&c.forEach(l=>{a.children.push(n(l))})}),a};return bB(A)||(A=GC(A)),n(A)}function zk(A,{ignoreFieldNorm:e=Ie.ignoreFieldNorm}){A.forEach(t=>{let n=1;t.matches.forEach(({key:r,norm:s,score:i})=>{const a=r?r.weight:null;n*=Math.pow(i===0&&a?Number.EPSILON:i,(a||1)*(e?1:s))}),t.score=n})}function Wk(A,e){const t=A.matches;e.matches=[],Yn(t)&&t.forEach(n=>{if(!Yn(n.indices)||!n.indices.length)return;const{indices:r,value:s}=n;let i={indices:r,value:s};n.key&&(i.key=n.key.src),n.idx>-1&&(i.refIndex=n.idx),e.matches.push(i)})}function Vk(A,e){e.score=A.score}function Zk(A,e,{includeMatches:t=Ie.includeMatches,includeScore:n=Ie.includeScore}={}){const r=[];return t&&r.push(Wk),n&&r.push(Vk),A.map(s=>{const{idx:i}=s,a={item:e[i],refIndex:i};return r.length&&r.forEach(g=>{g(s,a)}),a})}class Ts{constructor(e,t={},n){this.options={...Ie,...t},this.options.useExtendedSearch,this._keyStore=new mk(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof aE))throw new Error(Ck);this._myIndex=t||Dh(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Yn(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let n=0,r=this._docs.length;n<r;n+=1){const s=this._docs[n];e(s,n)&&(this.removeAt(n),n-=1,r-=1,t.push(s))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:s,sortFn:i,ignoreFieldNorm:a}=this.options;let g=vr(e)?vr(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return zk(g,{ignoreFieldNorm:a}),s&&g.sort(i),mh(t)&&t>-1&&(g=g.slice(0,t)),Zk(g,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const t=yB(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:s,i,n:a})=>{if(!Yn(s))return;const{isMatch:g,score:c,indices:l}=t.searchIn(s);g&&r.push({item:s,idx:i,matches:[{score:c,value:s,norm:a,indices:l}]})}),r}_searchLogical(e){const t=Mh(e,this.options),n=(a,g,c)=>{if(!a.children){const{keyId:B,searcher:Q}=a,u=this._findMatches({key:this._keyStore.get(B),value:this._myIndex.getValueForItemAtKeyId(g,B),searcher:Q});return u&&u.length?[{idx:c,item:g,matches:u}]:[]}const l=[];for(let B=0,Q=a.children.length;B<Q;B+=1){const u=a.children[B],d=n(u,g,c);if(d.length)l.push(...d);else if(a.operator===oc.AND)return[]}return l},r=this._myIndex.records,s={},i=[];return r.forEach(({$:a,i:g})=>{if(Yn(a)){let c=n(t,a,g);c.length&&(s[g]||(s[g]={idx:g,item:a,matches:[]},i.push(s[g])),c.forEach(({matches:l})=>{s[g].matches.push(...l)}))}}),i}_searchObjectList(e){const t=yB(e,this.options),{keys:n,records:r}=this._myIndex,s=[];return r.forEach(({$:i,i:a})=>{if(!Yn(i))return;let g=[];n.forEach((c,l)=>{g.push(...this._findMatches({key:c,value:i[l],searcher:t}))}),g.length&&s.push({idx:a,item:i,matches:g})}),s}_findMatches({key:e,value:t,searcher:n}){if(!Yn(t))return[];let r=[];if(cs(t))t.forEach(({v:s,i,n:a})=>{if(!Yn(s))return;const{isMatch:g,score:c,indices:l}=n.searchIn(s);g&&r.push({score:c,key:e,value:s,idx:i,norm:a,indices:l})});else{const{v:s,n:i}=t,{isMatch:a,score:g,indices:c}=n.searchIn(s);a&&r.push({score:g,key:e,value:s,norm:i,indices:c})}return r}}Ts.version="7.1.0";Ts.createIndex=Dh;Ts.parseIndex=Mk;Ts.config=Ie;Ts.parseQuery=Mh;Hk(Yk);function Xk(A){switch(A.split(".").pop()?.toLowerCase()){case"ts":case"tsx":case"js":case"jsx":case"mjs":case"cjs":case"py":case"rb":case"go":case"rs":case"java":case"c":case"cpp":case"h":case"hpp":return qc;case"json":case"yaml":case"yml":case"toml":return m1;case"md":case"txt":case"log":return so;case"png":case"jpg":case"jpeg":case"gif":case"svg":case"webp":return zQ;case"css":case"scss":case"sass":case"less":return p1;case"html":case"xml":return h1;default:return bs}}function $k(A,e){const t=e.get(A);return t?{added:{icon:Qr,label:"Added",className:"text-green-500"},modified:{icon:Ac,label:"Modified",className:"text-yellow-500"},untracked:{icon:Qr,label:"Untracked",className:"text-blue-500"}}[t]||{icon:Ac,label:"Modified",className:"text-yellow-500"}:null}function AM({files:A,changedFiles:e=[],query:t,selectedIndex:n,onSelect:r,onEnterSelect:s,onClose:i}){const a=k.useMemo(()=>new Map(e?.map(l=>[l.path,l.status])||[]),[e]),g=k.useMemo(()=>new Ts(A.map(l=>({path:l,filename:l.split("/").pop()||l,normalized:l.replace(/[.\-_/]/g,"")})),{keys:[{name:"filename",weight:2},{name:"normalized",weight:1.5},{name:"path",weight:1}],threshold:.3,distance:200,ignoreLocation:!0,includeScore:!0}),[A]),c=k.useMemo(()=>{if(!t)return A.slice(0,20);const l=t.replace(/[.\-_/]/g,""),B=g.search(l);return B.sort((Q,u)=>{const d=Q.score??1,f=u.score??1;if(Math.abs(d-f)<.05){const x=a.has(Q.item.path),b=a.has(u.item.path);if(x&&!b)return-1;if(!x&&b)return 1}return d-f}),B.slice(0,20).map(Q=>Q.item.path)},[g,t,A,a]);return k.useEffect(()=>{document.getElementById(`file-item-${n}`)?.scrollIntoView({block:"nearest"})},[n]),k.useEffect(()=>{s(c[n])},[c,n,s]),k.useEffect(()=>{const l=B=>{B.target.closest("[data-file-mention-popup]")||i()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[i]),c.length===0?o.jsx("div",{"data-file-mention-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg z-50 p-3",children:o.jsx("span",{className:"text-muted-foreground text-sm",children:"No files found"})}):o.jsx("div",{"data-file-mention-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg max-h-[300px] overflow-y-auto z-50",children:c.map((l,B)=>o.jsx("button",{type:"button",id:`file-item-${B}`,onMouseDown:Q=>{Q.preventDefault(),r(l)},className:`w-full text-left px-3 py-2 hover:bg-accent ${B===n?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2 w-full",children:[(()=>{const Q=Xk(l);return o.jsx(Q,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"})})(),o.jsx("span",{className:"font-mono text-sm flex-1 truncate",children:l}),(()=>{const Q=$k(l,a);return Q&&o.jsx("span",{title:Q.label,children:o.jsx(Q.icon,{className:`w-3.5 h-3.5 flex-shrink-0 ${Q.className}`})})})()]})},l))})}function eM(){if(typeof window<"u"&&typeof window.fetch=="function")return"fetch"}function XA(A){if(!A)return"Unknown error";if(typeof A=="string")return A;if(A&&typeof A=="object"){const e=A;if(e.error&&typeof e.error=="object"){const t=e.error;if(typeof t.message=="string")return t.message}if(typeof e.error=="string")return e.error;if(typeof e.message=="string")return e.message;try{return JSON.stringify(A)}catch{return"Error occurred (unable to parse)"}}return"Unknown error"}function tM(){const e=window.OTTO_SERVER_URL||Rs;SA.setConfig({baseURL:e,adapter:eM()})}tM();function vh(){const A=window;return A.OTTO_SERVER_URL?A.OTTO_SERVER_URL:Rs}function Xl(A){return{...A,title:A.title??null,createdAt:typeof A.createdAt=="string"?new Date(A.createdAt).getTime():A.createdAt,lastActiveAt:typeof A.lastActiveAt=="string"?new Date(A.lastActiveAt).getTime():A.lastActiveAt}}function nM(A){return{...A,createdAt:typeof A.createdAt=="string"?new Date(A.createdAt).getTime():A.createdAt,completedAt:A.completedAt?typeof A.completedAt=="string"?new Date(A.completedAt).getTime():A.completedAt:null}}const Jn={async getSessions(){return(await this.getSessionsPage({limit:200})).items},async getSessionsPage(A={}){const{limit:e=50,offset:t=0}=A,n=await rN({query:{limit:e,offset:t}});if(n.error)throw new Error(XA(n.error));const r=n.data;return{items:(r?.items??[]).map(s=>Xl(s)),hasMore:r?.hasMore??!1,nextOffset:r?.nextOffset??null}},async createSession(A){const e=await sN({body:A});if(e.error)throw new Error(XA(e.error));if(!e.data)throw new Error("No data returned from create session");return Xl(e.data)},async updateSession(A,e){const t=await Vb({path:{sessionId:A},body:e});if(t.error)throw new Error(XA(t.error));return Xl(t.data)},async deleteSession(A){const e=await Wb({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async abortSession(A){const e=await xC({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async abortMessage(A,e){const t=await xC({path:{sessionId:A}});if(t.error)throw new Error("Failed to abort message");return t.data},async getQueueState(A){const e=await Zb({path:{sessionId:A}});if(e.error)throw new Error("Failed to get queue state");return e.data},async removeFromQueue(A,e){const t=await Xb({path:{sessionId:A,messageId:e}});if(t.error)throw new Error("Failed to remove from queue");return t.data},async getMessages(A){const e=await Yb({path:{id:A}});if(e.error)throw new Error(XA(e.error));return(e.data||[]).map(nM)},async sendMessage(A,e){const t=await Hb({path:{id:A},body:e});if(t.error)throw new Error(XA(t.error));return t.data},getStreamUrl(A){return`${vh()}/v1/sessions/${A}/stream`},async retryMessage(A,e){const t=await $b({path:{sessionId:A,messageId:e}});if(t.error)throw new Error(XA(t.error));return t.data}},un={async initGitRepo(){const A=await mb();if(A.error)throw new Error(XA(A.error));return A.data?.data},async getGitStatus(){const A=await wb();if(A.error)throw new Error(XA(A.error));return A.data?.data},async getGitDiff(A,e=!1){const t=await wC({query:{file:A,staged:e?"true":"false"}});if(t.error)throw new Error(XA(t.error));return t.data?.data},async getGitDiffFullFile(A,e=!1){const t=await wC({query:{file:A,staged:e?"true":"false",fullFile:"true"}});if(t.error)throw new Error(XA(t.error));return t.data?.data},async generateCommitMessage(A){const e=await Nb({body:A?{sessionId:A}:{}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async stageFiles(A){const e=await yb({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async unstageFiles(A){const e=await Db({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async restoreFiles(A){const e=await vb({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async deleteFiles(A){const e=await Sb({body:{files:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async commitChanges(A){const e=await bb({body:{message:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data},async getGitBranch(){const A=await xb();if(A.error)throw new Error(XA(A.error));return A.data?.data},async pushCommits(){const A=await kb({body:{}});if(A.error)throw new Error(XA(A.error));return A.data?.data},async pullChanges(){const A=await Mb({body:{}});if(A.error)throw new Error(XA(A.error));return A.data?.data},async getRemotes(){const A=await Gb();if(A.error)throw new Error(XA(A.error));return A.data?.data?.remotes},async addRemote(A,e){const t=await Rb({body:{name:A,url:e}});if(t.error)throw new Error(XA(t.error));return t.data?.data},async removeRemote(A){const e=await Fb({body:{name:A}});if(e.error)throw new Error(XA(e.error));return e.data?.data}},mg={async getConfig(){const A=await Eb();if(A.error)throw new Error(XA(A.error));return A.data},async getModels(A){const e=await db({path:{provider:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getAllModels(){const A=await Ib();if(A.error)throw new Error(XA(A.error));return A.data},async updateDefaults(A){const e=await Cb({body:A});if(e.error)throw new Error(XA(e.error));return e.data}},wg={async listFiles(){const A=await fb();if(A.error)throw new Error(XA(A.error));return A.data},async getFileTree(A="."){const e=await hb({query:{path:A}});if(e.error)throw new Error(XA(e.error));return e.data},async readFileContent(A){const e=await pb({query:{path:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getSessionFiles(A){const e=await nN({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data}},Go={async createBranch(A,e){const t=await ub({path:{sessionId:A},body:e});if(t.error)throw new Error(XA(t.error));return t.data},async listBranches(A){const e=await Bb({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getParentSession(A){const e=await Qb({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getShareStatus(A){const e=await AN({path:{sessionId:A}});return e.error?{shared:!1}:e.data},async shareSession(A){const e=await eN({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async syncSession(A){const e=await tN({path:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data}},RC={async approveToolCall(A,e,t){const n=await _b({path:{id:A},body:{callId:e,approved:t,sessionId:A}});if(n.error)throw new Error("Failed to send tool approval");return n.data},async getPendingApprovals(A){const e=await zb({path:{id:A}});return e.error?{ok:!1,pending:[]}:e.data}},Zn={async getSetuBalance(){try{const A=await oN();return A.error?null:A.data}catch{return null}},async getSetuWallet(){try{const A=await iN();return A.error?{configured:!1}:A.data}catch{return{configured:!1}}},async getSetuUsdcBalance(A="mainnet"){try{const e=await aN({query:{network:A}});return e.error?null:e.data}catch{return null}},async getPolarTopupEstimate(A){try{const e=await BN({query:{amount:A}});return e.error?null:e.data}catch{return null}},async createPolarCheckout(A,e){const t=await gN({body:{amount:A,successUrl:e}});if(t.error)throw new Error(XA(t.error));return t.data},async selectTopupMethod(A,e){const t=await cN({body:{sessionId:A,method:e}});if(t.error)throw new Error(XA(t.error));return t.data},async cancelTopup(A,e){const t=await lN({body:{sessionId:A,reason:e}});if(t.error)throw new Error(XA(t.error));return t.data},async getPendingTopup(A){try{const e=await uN({query:{sessionId:A}});return e.error?{hasPending:!1}:e.data}catch{return{hasPending:!1}}},async getPolarTopupStatus(A){try{const e=await QN({query:{checkoutId:A}});return e.error?null:e.data}catch{return null}},async getRazorpayTopupEstimate(A){try{const e=await EN({query:{amount:A}});return e.error?null:e.data}catch{return null}},async createRazorpayOrder(A){const e=await dN({body:{amount:A}});if(e.error)throw new Error(XA(e.error));return e.data},async verifyRazorpayPayment(A){const e=await CN({body:A});if(e.error)throw new Error(XA(e.error));return e.data}},en={async getAuthStatus(){const A=await Z2();if(A.error)throw new Error(XA(A.error));return A.data},async setupSetuWallet(){const A=await X2();if(A.error)throw new Error(XA(A.error));return A.data},async importSetuWallet(A){const e=await $2({body:{privateKey:A}});if(e.error)throw new Error(XA(e.error));return e.data},async exportSetuWallet(){const A=await Ab();if(A.error)throw new Error(XA(A.error));return A.data},async addProvider(A,e){const t=await tb({path:{provider:A},body:{apiKey:e}});if(t.error)throw new Error(XA(t.error));return t.data},async removeProvider(A){const e=await eb({path:{provider:A}});if(e.error)throw new Error(XA(e.error));return e.data},async completeOnboarding(){const A=await lb();if(A.error)throw new Error(XA(A.error));return A.data},getOAuthStartUrl(A,e){const t=`${vh()}/v1/auth/${A}/oauth/start`;return e?`${t}?mode=${e}`:t},async getOAuthUrl(A,e){const t=await nb({path:{provider:A},body:{mode:e}});if(t.error)throw new Error(XA(t.error));return t.data},async exchangeOAuthCode(A,e,t){const n=await rb({path:{provider:A},body:{code:e,sessionId:t}});if(n.error)throw new Error(XA(n.error));return n.data},async startCopilotDeviceFlow(){const A=await sb();if(A.error)throw new Error(XA(A.error));return A.data},async pollCopilotDeviceFlow(A){const e=await ob({body:{sessionId:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getCopilotAuthMethods(){const A=await ib();if(A.error)throw new Error(XA(A.error));return A.data},async saveCopilotToken(A){const e=await ab({body:{token:A}});if(e.error)throw new Error(XA(e.error));return e.data},async importCopilotTokenFromGh(){const A=await gb();if(A.error)throw new Error(XA(A.error));return A.data},async getCopilotDiagnostics(){const A=await cb();if(A.error)throw new Error(XA(A.error));return A.data},async getProviderUsage(A){const e=await Pb({path:{provider:A}});if(e.error)throw new Error(XA(e.error));return e.data}},xg={async listSkills(){const A=await IN();if(A.error)throw new Error(XA(A.error));return A.data},async getSkill(A){const e=await fN({path:{name:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getSkillFiles(A){const e=await hN({path:{name:A}});if(e.error)throw new Error(XA(e.error));return e.data},async getSkillFileContent(A,e){const t=await pN({path:{name:A,filePath:e}});if(t.error)throw new Error(XA(t.error));return t.data}};class rM{getSessions=Jn.getSessions;getSessionsPage=Jn.getSessionsPage;createSession=Jn.createSession;updateSession=Jn.updateSession;deleteSession=Jn.deleteSession;abortSession=Jn.abortSession;abortMessage=Jn.abortMessage;getQueueState=Jn.getQueueState;removeFromQueue=Jn.removeFromQueue;getMessages=Jn.getMessages;sendMessage=Jn.sendMessage;getStreamUrl=Jn.getStreamUrl;retryMessage=Jn.retryMessage;initGitRepo=un.initGitRepo;getGitStatus=un.getGitStatus;getGitDiff=un.getGitDiff;getGitDiffFullFile=un.getGitDiffFullFile;generateCommitMessage=un.generateCommitMessage;stageFiles=un.stageFiles;unstageFiles=un.unstageFiles;restoreFiles=un.restoreFiles;deleteFiles=un.deleteFiles;commitChanges=un.commitChanges;getGitBranch=un.getGitBranch;pushCommits=un.pushCommits;pullChanges=un.pullChanges;getRemotes=un.getRemotes;addRemote=un.addRemote;removeRemote=un.removeRemote;getConfig=mg.getConfig;getModels=mg.getModels;getAllModels=mg.getAllModels;updateDefaults=mg.updateDefaults;listFiles=wg.listFiles;getFileTree=wg.getFileTree;readFileContent=wg.readFileContent;getSessionFiles=wg.getSessionFiles;createBranch=Go.createBranch;listBranches=Go.listBranches;getParentSession=Go.getParentSession;getShareStatus=Go.getShareStatus;shareSession=Go.shareSession;syncSession=Go.syncSession;approveToolCall=RC.approveToolCall;getPendingApprovals=RC.getPendingApprovals;getSetuBalance=Zn.getSetuBalance;getSetuWallet=Zn.getSetuWallet;getSetuUsdcBalance=Zn.getSetuUsdcBalance;getPolarTopupEstimate=Zn.getPolarTopupEstimate;createPolarCheckout=Zn.createPolarCheckout;selectTopupMethod=Zn.selectTopupMethod;cancelTopup=Zn.cancelTopup;getPendingTopup=Zn.getPendingTopup;getPolarTopupStatus=Zn.getPolarTopupStatus;getRazorpayTopupEstimate=Zn.getRazorpayTopupEstimate;createRazorpayOrder=Zn.createRazorpayOrder;verifyRazorpayPayment=Zn.verifyRazorpayPayment;getAuthStatus=en.getAuthStatus;setupSetuWallet=en.setupSetuWallet;importSetuWallet=en.importSetuWallet;exportSetuWallet=en.exportSetuWallet;addProvider=en.addProvider;removeProvider=en.removeProvider;completeOnboarding=en.completeOnboarding;getOAuthStartUrl=en.getOAuthStartUrl;getOAuthUrl=en.getOAuthUrl;exchangeOAuthCode=en.exchangeOAuthCode;startCopilotDeviceFlow=en.startCopilotDeviceFlow;pollCopilotDeviceFlow=en.pollCopilotDeviceFlow;getCopilotAuthMethods=en.getCopilotAuthMethods;saveCopilotToken=en.saveCopilotToken;importCopilotTokenFromGh=en.importCopilotTokenFromGh;getCopilotDiagnostics=en.getCopilotDiagnostics;getProviderUsage=en.getProviderUsage;listSkills=xg.listSkills;getSkill=xg.getSkill;getSkillFiles=xg.getSkillFiles;getSkillFileContent=xg.getSkillFileContent}const xA=new rM;function bo(){return bt({queryKey:["config"],queryFn:()=>xA.getConfig(),staleTime:3e4})}function La(){return bt({queryKey:["models","all"],queryFn:()=>xA.getAllModels()})}function $c(){const A=Ye();return it({mutationFn:e=>xA.updateDefaults(e),onMutate:async e=>{await A.cancelQueries({queryKey:["config"]});const t=A.getQueryData(["config"]);if(t){const n=Object.fromEntries(Object.entries(e).filter(([r,s])=>r!=="scope"&&s!==void 0));A.setQueryData(["config"],{...t,defaults:{...t.defaults,...n}})}return{previousConfig:t}},onError:(e,t,n)=>{n?.previousConfig&&A.setQueryData(["config"],n.previousConfig)},onSuccess:()=>{A.invalidateQueries({queryKey:["config"]})}})}const Sh="otto-preferences",Hi={vimMode:!1,compactThread:!0};function sM(){if(typeof window>"u")return Hi;try{const A=window.localStorage.getItem(Sh);if(A){const e=JSON.parse(A);return{vimMode:typeof e.vimMode=="boolean"?e.vimMode:Hi.vimMode,compactThread:typeof e.compactThread=="boolean"?e.compactThread:Hi.compactThread}}}catch(A){console.warn("Failed to load preferences",A)}return Hi}let Hg=sM();const NB=new Set;function oM(){return Hg}function iM(){return Hi}function aM(A){return NB.add(A),()=>NB.delete(A)}function gM(){for(const A of NB)A()}function cM(A){if(Hg={...Hg,...A},typeof window<"u")try{window.localStorage.setItem(Sh,JSON.stringify(Hg))}catch(e){console.warn("Failed to persist preferences",e)}gM()}function hi(){const A=k.useSyncExternalStore(aM,oM,iM),{data:e}=bo(),t=$c(),n=k.useCallback(s=>{const i={};s.vimMode!==void 0&&(i.vimMode=s.vimMode),s.compactThread!==void 0&&(i.compactThread=s.compactThread),Object.keys(i).length>0&&cM(i),s.fullWidthContent!==void 0&&s.fullWidthContent!==e?.defaults?.fullWidthContent&&t.mutate({fullWidthContent:s.fullWidthContent,scope:"global"})},[e?.defaults?.fullWidthContent,t]),r=k.useMemo(()=>({...A,fullWidthContent:e?.defaults?.fullWidthContent??!1}),[A,e?.defaults?.fullWidthContent]);return k.useMemo(()=>({preferences:r,updatePreferences:n}),[r,n])}function gE(A){const{data:e,isLoading:t,error:n}=bt({queryKey:["share-status",A],queryFn:()=>xA.getShareStatus(A),enabled:!!A,staleTime:3e4});return{data:e,isLoading:t,error:n}}const Fh=[{id:"models",label:"/models",description:"Open model selector",icon:Rr},{id:"agents",label:"/agents",description:"Open agent selector",icon:Pn},{id:"new",label:"/new",description:"Create new session",icon:Qr},{id:"stop",label:"/stop",description:"Stop current generation",icon:yf},{id:"help",label:"/help",description:"Show keyboard shortcuts and help",icon:Df},{id:"vim",label:"/vim",description:A=>A.vimModeEnabled?"Disable Vim mode":"Enable Vim mode",icon:w1},{id:"reasoning",label:"/reasoning",description:A=>A.reasoningEnabled?"Disable extended thinking":"Enable extended thinking",icon:Yc},{id:"stage",label:"/stage",description:"Stage all changes (git add -A)",icon:_n},{id:"commit",label:"/commit",description:"Commit staged changes",icon:Dn},{id:"compact",label:"/compact",description:"Compact conversation to reduce context size",icon:PQ},{id:"branch",label:"/branch",description:"Branch session from last message",icon:x1},{id:"delete",label:"/delete",description:"Delete current session",icon:Ma},{id:"share",label:"/share",description:"Share session publicly",icon:WQ},{id:"sync",label:"/sync",description:"Sync new messages to shared session",icon:Sn}];function Gh(A,e){return typeof A.description=="function"?A.description(e):A.description}function lM(A,e){const t=Fh.filter(s=>!(s.id==="share"&&e.isShared||s.id==="sync"&&!e.isShared));if(!A)return t;const n=A.toLowerCase(),r=[];for(const s of t){const i=Gh(s,e),a=s.label.toLowerCase().includes(n),g=i.toLowerCase().includes(n);if(a||g){const c=a?10:5;r.push({...s,matchScore:c})}}return r.sort((s,i)=>{const a=i.matchScore-s.matchScore;return a!==0?a:s.label.localeCompare(i.label)})}function uM({query:A,selectedIndex:e,onSelect:t,onEnterSelect:n,onClose:r,sessionId:s}){const{preferences:i}=hi(),{data:a}=bo(),{data:g}=gE(s),c=k.useMemo(()=>({vimModeEnabled:i.vimMode,reasoningEnabled:a?.defaults?.reasoningText??!0,isShared:g?.shared}),[i.vimMode,a?.defaults?.reasoningText,g?.shared]),l=k.useMemo(()=>lM(A,c),[A,c]);return k.useEffect(()=>{document.getElementById(`command-item-${e}`)?.scrollIntoView({block:"nearest"})},[e]),k.useEffect(()=>{n(l[e]?.id)},[l,e,n]),k.useEffect(()=>{const B=Q=>{Q.target.closest("[data-command-popup]")||r()};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[r]),l.length===0?o.jsx("div",{"data-command-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg z-50 p-3",children:o.jsx("span",{className:"text-muted-foreground text-sm",children:"No commands found"})}):o.jsx("div",{"data-command-popup":!0,className:"absolute bottom-full left-0 right-0 mb-2 bg-card border border-border rounded-lg shadow-lg max-h-[300px] overflow-y-auto z-50",children:l.map((B,Q)=>{const u=B.icon;return o.jsx("button",{type:"button",id:`command-item-${Q}`,onMouseDown:d=>{d.preventDefault(),t(B.id)},className:`w-full text-left px-3 py-2 hover:bg-accent ${Q===e?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-3 w-full",children:[o.jsx(u,{className:"w-4 h-4 flex-shrink-0 text-primary"}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"font-mono text-sm font-medium text-foreground",children:B.label}),o.jsx("div",{className:"text-xs text-muted-foreground truncate",children:Gh(B,c)})]})]})},B.id)})})}const BM={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl"};function ds({isOpen:A,onClose:e,title:t,children:n,showCloseButton:r=!0,closeOnBackdropClick:s=!0,closeOnEscape:i=!0,maxWidth:a="md"}){if(k.useEffect(()=>{if(!A||!i)return;const c=l=>{const B=l.target,Q=B.tagName==="INPUT"||B.tagName==="TEXTAREA"||B.isContentEditable;(l.key==="Escape"||l.key==="q"&&!Q)&&(l.preventDefault(),l.stopPropagation(),e())};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[A,i,e]),k.useEffect(()=>{if(A)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[A]),!A)return null;const g=c=>{s&&c.target===c.currentTarget&&e()};return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-[9999] cursor-default",onClick:g,onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&g(c)},"aria-label":"Close modal"}),o.jsx("div",{className:`fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[9999] w-full ${BM[a]} px-4`,children:o.jsxs("div",{className:"bg-background border border-border rounded-lg shadow-lg",children:[(t||r)&&o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[t&&o.jsx("div",{className:"text-lg font-semibold text-foreground",children:t}),r&&o.jsx("button",{type:"button",onClick:e,className:"text-muted-foreground hover:text-foreground transition-colors ml-auto","aria-label":"Close",children:o.jsx(yt,{className:"h-5 w-5"})})]}),o.jsx("div",{className:"p-6",children:n})]})})]})}const QM=[{keys:["Ctrl","H"],description:"Navigate to left sidebar (sessions)",category:"Navigation"},{keys:["Ctrl","L"],description:"Navigate to right sidebar (git)",category:"Navigation"},{keys:["Ctrl","/"],description:"Toggle left sidebar collapse/expand",category:"Navigation"},{keys:["Ctrl","\\"],description:"Toggle right sidebar collapse/expand",category:"Navigation"},{keys:["Ctrl","N"],description:"Create new session",category:"Navigation"},{keys:["ESC"],description:"Close sidebar and return to center",category:"Navigation"},{keys:["J"],description:"Navigate to next item (in focused list)",category:"List Navigation"},{keys:["K"],description:"Navigate to previous item (in focused list)",category:"List Navigation"},{keys:["Enter"],description:"Select focused item and return to input",category:"List Navigation"},{keys:["Space"],description:"Toggle stage/unstage for focused file (git panel)",category:"Git Operations"},{keys:["A"],description:"Stage all unstaged files",category:"Git Operations"},{keys:["U"],description:"Unstage all staged files",category:"Git Operations"},{keys:["C"],description:"Open commit modal (if files are staged)",category:"Git Operations"},{keys:["Tab"],description:"Toggle plan mode",category:"Chat"},{keys:["Enter"],description:"Send message",category:"Chat"},{keys:["Shift","Enter"],description:"New line in message",category:"Chat"},{keys:["@"],description:"Mention file (opens file picker)",category:"Chat"},{keys:["/"],description:"Slash command (opens command menu)",category:"Chat"}],EM=[{keys:["i"],description:"Enter insert mode at cursor (vim mode)",category:"Vim Mode"},{keys:["a"],description:"Enter insert mode after cursor (vim mode)",category:"Vim Mode"},{keys:["I"],description:"Enter insert mode at line start (vim mode)",category:"Vim Mode"},{keys:["A"],description:"Enter insert mode at line end (vim mode)",category:"Vim Mode"},{keys:["o"],description:"New line below and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["O"],description:"New line above and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["ESC"],description:"Return to normal mode (vim mode)",category:"Vim Mode"},{keys:["Enter"],description:"Send message in normal mode (vim mode)",category:"Vim Mode"},{keys:["w"],description:"Jump to next word start (vim mode)",category:"Vim Mode"},{keys:["e"],description:"Jump to next word end (vim mode)",category:"Vim Mode"},{keys:["b"],description:"Jump to previous word start (vim mode)",category:"Vim Mode"},{keys:["x"],description:"Delete character under cursor (vim mode)",category:"Vim Mode"},{keys:["s"],description:"Delete character and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["S"],description:"Delete line and enter insert mode (vim mode)",category:"Vim Mode"},{keys:["f","{char}"],description:"Find and jump to next character on line (vim mode)",category:"Vim Mode"},{keys:["d","d"],description:"Delete current line (vim mode)",category:"Vim Mode"},{keys:["0"],description:"Jump to line start (vim mode)",category:"Vim Mode"},{keys:["$"],description:"Jump to line end (vim mode)",category:"Vim Mode"}],dM=[{command:"/models",description:"Open model selector"},{command:"/agents",description:"Open agent selector"},{command:"/new",description:"Create new session"},{command:"/help",description:"Show keyboard shortcuts and help (this modal)"},{command:"/compact",description:"Compact conversation to reduce context size"}];function CM(A){const e={};for(const t of A)e[t.category]||(e[t.category]=[]),e[t.category].push(t);return e}function IM({isOpen:A,onClose:e}){const t=[...QM,...EM],n=CM(t),r=k.useRef(null),s=k.useRef(null);return k.useEffect(()=>{A?(s.current=document.activeElement,s.current&&s.current.blur()):s.current&&(s.current.focus(),s.current=null)},[A]),k.useEffect(()=>{if(!A)return;const i=a=>{const g=a.target;if(!(g.tagName==="INPUT"||g.tagName==="TEXTAREA"||g.isContentEditable))if(a.key==="j"){a.preventDefault();const l=r.current;l&&l.scrollBy({top:100,behavior:"smooth"})}else if(a.key==="k"){a.preventDefault();const l=r.current;l&&l.scrollBy({top:-100,behavior:"smooth"})}else a.key==="Enter"&&(a.preventDefault(),e())};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[A,e]),o.jsx(ds,{isOpen:A,onClose:e,title:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Df,{className:"w-5 h-5"}),o.jsx("span",{children:"Keyboard Shortcuts & Help"})]}),maxWidth:"2xl",closeOnEscape:!0,closeOnBackdropClick:!0,children:o.jsxs("div",{ref:r,className:"space-y-6 max-h-[70vh] overflow-y-auto",children:[Object.entries(n).map(([i,a])=>o.jsxs("div",{children:[o.jsxs("h3",{className:"text-sm font-semibold text-foreground mb-3 flex items-center gap-2",children:[o.jsx(Xd,{className:"w-4 h-4"}),i]}),o.jsx("div",{className:"space-y-2",children:a.map((g,c)=>o.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-lg bg-accent/50 hover:bg-accent transition-colors",children:[o.jsx("span",{className:"text-sm text-foreground",children:g.description}),o.jsx("div",{className:"flex items-center gap-1",children:g.keys.map(l=>o.jsxs("span",{className:"flex items-center gap-1",children:[o.jsx("kbd",{className:"px-2 py-1 text-xs font-mono bg-background border border-border rounded shadow-sm",children:l}),g.keys.indexOf(l)<g.keys.length-1&&o.jsx("span",{className:"text-muted-foreground",children:"+"})]},l))})]},`${i}-${g.description}`))})]},i)),o.jsxs("div",{children:[o.jsxs("h3",{className:"text-sm font-semibold text-foreground mb-3 flex items-center gap-2",children:[o.jsx(Xd,{className:"w-4 h-4"}),"Slash Commands"]}),o.jsx("div",{className:"space-y-2",children:dM.map((i,a)=>o.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-lg bg-accent/50 hover:bg-accent transition-colors",children:[o.jsx("span",{className:"text-sm text-foreground",children:i.description}),o.jsx("kbd",{className:"px-2 py-1 text-xs font-mono bg-background border border-border rounded shadow-sm",children:i.command})]},i.command))})]}),o.jsx("div",{className:"pt-4 border-t border-border",children:o.jsxs("p",{className:"text-xs text-muted-foreground",children:[o.jsx("strong",{children:"Tip:"})," Shortcuts are disabled when typing in input fields. Press ",o.jsx("kbd",{className:"text-xs",children:"ESC"})," to close popups and return focus to chat input."]})})]})})}const fM=`<svg width="24" height="24" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
37
37
  <path d="M26.9568 9.88184H22.1265L30.7753 31.7848H35.4917L26.9568 9.88184ZM13.028 9.88184L4.4917 31.7848H9.32203L11.2305 27.1793H20.2166L22.0126 31.6724H26.8444L18.0832 9.88184H13.028ZM12.5783 23.1361L15.4987 15.3853L18.5315 23.1361H12.5783Z" fill="currentColor"/>
38
38
  </svg>`,hM=`<svg width="24" height="24" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
39
39
  <path d="M32.8377 17.282C33.2127 16.25 33.3072 15.218 33.2127 14.1875C33.1197 13.1571 32.7447 12.1251 32.2752 11.1876C31.4322 9.78209 30.2127 8.6571 28.8072 8.0001C27.3072 7.34461 25.7127 7.15711 24.1197 7.53211C23.3698 6.78212 22.5253 6.12512 21.5878 5.65713C20.6503 5.18913 19.5253 5.00013 18.4948 5.00013C16.8851 4.99074 15.3125 5.48246 13.9948 6.40712C12.6824 7.34311 11.7449 8.6571 11.2754 10.1571C10.1504 10.4376 9.21289 10.9071 8.27539 11.4696C7.4324 12.1251 6.77541 12.9696 6.21291 13.8126C5.36992 15.2195 5.08792 16.8125 5.27542 18.407C5.46399 19.9968 6.11605 21.496 7.1504 22.718C6.79608 23.7086 6.66795 24.7659 6.77541 25.8124C6.86991 26.8444 7.2449 27.8749 7.7129 28.8124C8.55739 30.2194 9.77538 31.3444 11.1824 31.9999C12.6824 32.6569 14.2753 32.8444 15.8698 32.4694C16.6198 33.2194 17.4628 33.8749 18.4003 34.3444C19.3378 34.8139 20.4628 34.9999 21.4948 34.9999C23.1043 35.0097 24.6769 34.5185 25.9947 33.5944C27.3072 32.6569 28.2447 31.3444 28.7127 29.8444C29.7719 29.6432 30.7682 29.1934 31.6197 28.5319C32.4627 27.8749 33.2127 27.1249 33.6822 26.1874C34.5251 24.7819 34.8071 23.1875 34.6196 21.5945C34.4322 20 33.8697 18.5015 32.8377 17.282ZM21.5878 33.0304C20.0878 33.0304 18.9628 32.5609 17.9323 31.7179C17.9323 31.7179 18.0253 31.6234 18.1198 31.6234L24.1197 28.1554C24.2862 28.0803 24.4196 27.9469 24.4947 27.7804C24.5698 27.636 24.6021 27.4731 24.5877 27.3109V18.875L27.1197 20.375V27.3124C27.1455 28.0547 27.0215 28.7945 26.755 29.4878C26.4885 30.181 26.085 30.8134 25.5687 31.3473C25.0523 31.8811 24.4337 32.3054 23.7497 32.5949C23.0658 32.8843 22.3305 33.0314 21.5878 33.0304ZM9.49488 27.8749C8.83789 26.7499 8.55739 25.4374 8.83789 24.125C8.83789 24.125 8.93239 24.2195 9.02539 24.2195L15.0253 27.6874C15.1693 27.7638 15.3325 27.7966 15.4948 27.7819C15.6823 27.7819 15.8698 27.7819 15.9628 27.6874L23.2753 23.4695V26.3749L17.1823 29.9374C16.5506 30.3042 15.8527 30.5427 15.1287 30.6393C14.4046 30.7358 13.6686 30.6884 12.9629 30.4999C11.4629 30.1249 10.2449 29.1874 9.49488 27.8749ZM7.9004 14.8445C8.56239 13.7234 9.58826 12.8627 10.8074 12.4056V19.532C10.8074 19.718 10.8074 19.907 10.9004 20C10.9755 20.1665 11.1089 20.2998 11.2754 20.375L18.5878 24.5944L16.0573 26.0944L10.0574 22.625C9.41842 22.2639 8.85742 21.7797 8.40684 21.2004C7.95627 20.6211 7.62506 19.9582 7.4324 19.25C7.05741 17.8445 7.1504 16.157 7.9004 14.8445ZM28.6197 19.625L21.3073 15.407L23.8377 13.9071L29.8377 17.375C30.7752 17.9375 31.5252 18.6875 31.9947 19.625C32.4642 20.5625 32.7447 21.5945 32.6502 22.7195C32.5603 23.7755 32.1699 24.7837 31.5252 25.6249C30.8697 26.4694 30.0252 27.1249 28.9947 27.4999V20.375C28.9947 20.1875 28.9947 20 28.9002 19.907C28.9002 19.907 28.8072 19.718 28.6197 19.625ZM31.1502 15.875C31.1502 15.875 31.0572 15.782 30.9627 15.782L24.9627 12.3126C24.7752 12.2196 24.6822 12.2196 24.4947 12.2196C24.3072 12.2196 24.1197 12.2196 24.0252 12.3126L16.7128 16.532V13.6251L22.8073 10.0626C23.7448 9.50009 24.7752 9.31259 25.9002 9.31259C26.9322 9.31259 27.9627 9.68759 28.9002 10.3446C29.7447 11.0001 30.4947 11.8446 30.8697 12.7821C31.2447 13.7196 31.3377 14.8445 31.1502 15.875ZM15.4003 21.125L12.8699 19.625V12.5946C12.8699 11.5626 13.1503 10.4376 13.7128 9.59459C14.2753 8.6571 15.1198 8.0001 16.0573 7.53211C17.0127 7.05249 18.0956 6.88812 19.1503 7.06261C20.1823 7.15711 21.2128 7.62511 22.0573 8.2821C22.0573 8.2821 21.9628 8.3751 21.8698 8.3751L15.8698 11.8446C15.7033 11.9197 15.57 12.0531 15.4948 12.2196C15.4003 12.4071 15.4003 12.5001 15.4003 12.6876V21.125ZM16.7128 18.125L19.9948 16.25L23.2753 18.125V21.875L19.9948 23.75L16.7128 21.875V18.125Z" fill="currentColor"/>
@@ -146,7 +146,7 @@ ${j6(u)}`),super(e.shortMessage,{cause:e,docsPath:n,metaMessages:[...e.metaMessa
146
146
  `),{cause:e,metaMessages:["This error could arise when the account does not have enough funds to:"," - pay for the total gas fee,"," - pay for the value to send."," ","The cost of the transaction is calculated as `gas * gas fee + value`, where:"," - `gas` is the amount of gas needed for transaction to execute,"," - `gas fee` is the gas fee,"," - `value` is the amount of ether to send to the recipient."],name:"InsufficientFundsError"})}}Object.defineProperty(sQ,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class oQ extends fA{constructor({cause:e,gas:t}={}){super(`The amount of gas ${t?`(${t}) `:""}provided for the transaction exceeds the limit allowed for the block.`,{cause:e,name:"IntrinsicGasTooHighError"})}}Object.defineProperty(oQ,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class iQ extends fA{constructor({cause:e,gas:t}={}){super(`The amount of gas ${t?`(${t}) `:""}provided for the transaction is too low.`,{cause:e,name:"IntrinsicGasTooLowError"})}}Object.defineProperty(iQ,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class aQ extends fA{constructor({cause:e}){super("The transaction type is not supported for this chain.",{cause:e,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty(aQ,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class ya extends fA{constructor({cause:e,maxPriorityFeePerGas:t,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${t?` = ${Ln(t)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${Ln(n)} gwei`:""}).`].join(`
147
147
  `),{cause:e,name:"TipAboveFeeCapError"})}}Object.defineProperty(ya,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class $a extends fA{constructor({cause:e}){super(`An error occurred while executing: ${e?.shortMessage}`,{cause:e,name:"UnknownNodeError"})}}function pl(A,e){const t=(A.details||"").toLowerCase(),n=A instanceof fA?A.walk(r=>r?.code===Yo.code):A;return n instanceof fA?new Yo({cause:A,message:n.details}):Yo.nodeMessage.test(t)?new Yo({cause:A,message:A.details}):fo.nodeMessage.test(t)?new fo({cause:A,maxFeePerGas:e?.maxFeePerGas}):eQ.nodeMessage.test(t)?new eQ({cause:A,maxFeePerGas:e?.maxFeePerGas}):tQ.nodeMessage.test(t)?new tQ({cause:A,nonce:e?.nonce}):nQ.nodeMessage.test(t)?new nQ({cause:A,nonce:e?.nonce}):rQ.nodeMessage.test(t)?new rQ({cause:A,nonce:e?.nonce}):sQ.nodeMessage.test(t)?new sQ({cause:A}):oQ.nodeMessage.test(t)?new oQ({cause:A,gas:e?.gas}):iQ.nodeMessage.test(t)?new iQ({cause:A,gas:e?.gas}):aQ.nodeMessage.test(t)?new aQ({cause:A}):ya.nodeMessage.test(t)?new ya({cause:A,maxFeePerGas:e?.maxFeePerGas,maxPriorityFeePerGas:e?.maxPriorityFeePerGas}):new $a({cause:A})}function nG(A,{docsPath:e,...t}){const n=(()=>{const r=pl(A,t);return r instanceof $a?A:r})();return new tG(n,{docsPath:e,...t})}function Ni(A,{format:e}){if(!e)return{};const t={};function n(s){const i=Object.keys(s);for(const a of i)a in A&&(t[a]=A[a]),s[a]&&typeof s[a]=="object"&&!Array.isArray(s[a])&&n(s[a])}const r=e(A||{});return n(r),t}function ml(A,e){return({exclude:t,format:n})=>({exclude:t,format:(r,s)=>{const i=e(r,s);if(t)for(const a of t)delete i[a];return{...i,...n(r,s)}},type:A})}const rG={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function Is(A,e){const t={};return typeof A.authorizationList<"u"&&(t.authorizationList=oG(A.authorizationList)),typeof A.accessList<"u"&&(t.accessList=A.accessList),typeof A.blobVersionedHashes<"u"&&(t.blobVersionedHashes=A.blobVersionedHashes),typeof A.blobs<"u"&&(typeof A.blobs[0]!="string"?t.blobs=A.blobs.map(n=>qt(n)):t.blobs=A.blobs),typeof A.data<"u"&&(t.data=A.data),A.account&&(t.from=A.account.address),typeof A.from<"u"&&(t.from=A.from),typeof A.gas<"u"&&(t.gas=NA(A.gas)),typeof A.gasPrice<"u"&&(t.gasPrice=NA(A.gasPrice)),typeof A.maxFeePerBlobGas<"u"&&(t.maxFeePerBlobGas=NA(A.maxFeePerBlobGas)),typeof A.maxFeePerGas<"u"&&(t.maxFeePerGas=NA(A.maxFeePerGas)),typeof A.maxPriorityFeePerGas<"u"&&(t.maxPriorityFeePerGas=NA(A.maxPriorityFeePerGas)),typeof A.nonce<"u"&&(t.nonce=NA(A.nonce)),typeof A.to<"u"&&(t.to=A.to),typeof A.type<"u"&&(t.type=rG[A.type]),typeof A.value<"u"&&(t.value=NA(A.value)),t}const sG=ml("transactionRequest",Is);function oG(A){return A.map(e=>({address:e.address,r:e.r?NA(BigInt(e.r)):e.r,s:e.s?NA(BigInt(e.s)):e.s,chainId:NA(e.chainId),nonce:NA(e.nonce),...typeof e.yParity<"u"?{yParity:NA(e.yParity)}:{},...typeof e.v<"u"&&typeof e.yParity>"u"?{v:NA(e.v)}:{}}))}function r0(A){if(!(!A||A.length===0))return A.reduce((e,{slot:t,value:n})=>{if(t.length!==66)throw new zI({size:t.length,targetSize:66,type:"hex"});if(n.length!==66)throw new zI({size:n.length,targetSize:66,type:"hex"});return e[t]=n,e},{})}function iG(A){const{balance:e,nonce:t,state:n,stateDiff:r,code:s}=A,i={};if(s!==void 0&&(i.code=s),e!==void 0&&(i.balance=NA(e)),t!==void 0&&(i.nonce=NA(t)),n!==void 0&&(i.state=r0(n)),r!==void 0){if(i.state)throw new K6;i.stateDiff=r0(r)}return i}function WE(A){if(!A)return;const e={};for(const{address:t,...n}of A){if(!mt(t,{strict:!1}))throw new Jt({address:t});if(e[t])throw new O6({address:t});e[t]=iG(n)}return e}const aG=2n**16n-1n,wl=2n**256n-1n;function jr(A){const{account:e,maxFeePerGas:t,maxPriorityFeePerGas:n,to:r}=A,s=e?Ct(e):void 0;if(s&&!mt(s.address))throw new Jt({address:s.address});if(r&&!mt(r))throw new Jt({address:r});if(t&&t>wl)throw new fo({maxFeePerGas:t});if(n&&t&&n>t)throw new ya({maxFeePerGas:t,maxPriorityFeePerGas:n})}class Vm extends fA{constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class VE extends fA{constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class gG extends fA{constructor({maxPriorityFeePerGas:e}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${Ln(e)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class Zm extends fA{constructor({blockHash:e,blockNumber:t}){let n="Block";e&&(n=`Block at hash "${e}"`),t&&(n=`Block at number "${t}"`),super(`${n} could not be found.`,{name:"BlockNotFoundError"})}}const Xm={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Ag(A,e){const t={...A,blockHash:A.blockHash?A.blockHash:null,blockNumber:A.blockNumber?BigInt(A.blockNumber):null,chainId:A.chainId?zn(A.chainId):void 0,gas:A.gas?BigInt(A.gas):void 0,gasPrice:A.gasPrice?BigInt(A.gasPrice):void 0,maxFeePerBlobGas:A.maxFeePerBlobGas?BigInt(A.maxFeePerBlobGas):void 0,maxFeePerGas:A.maxFeePerGas?BigInt(A.maxFeePerGas):void 0,maxPriorityFeePerGas:A.maxPriorityFeePerGas?BigInt(A.maxPriorityFeePerGas):void 0,nonce:A.nonce?zn(A.nonce):void 0,to:A.to?A.to:null,transactionIndex:A.transactionIndex?Number(A.transactionIndex):null,type:A.type?Xm[A.type]:void 0,typeHex:A.type?A.type:void 0,value:A.value?BigInt(A.value):void 0,v:A.v?BigInt(A.v):void 0};return A.authorizationList&&(t.authorizationList=cG(A.authorizationList)),t.yParity=(()=>{if(A.yParity)return Number(A.yParity);if(typeof t.v=="bigint"){if(t.v===0n||t.v===27n)return 0;if(t.v===1n||t.v===28n)return 1;if(t.v>=35n)return t.v%2n===0n?1:0}})(),t.type==="legacy"&&(delete t.accessList,delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas,delete t.yParity),t.type==="eip2930"&&(delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas),t.type==="eip1559"&&delete t.maxFeePerBlobGas,t}const $m=ml("transaction",Ag);function cG(A){return A.map(e=>({address:e.address,chainId:Number(e.chainId),nonce:Number(e.nonce),r:e.r,s:e.s,yParity:Number(e.yParity)}))}function ZE(A,e){const t=(A.transactions??[]).map(n=>typeof n=="string"?n:Ag(n));return{...A,baseFeePerGas:A.baseFeePerGas?BigInt(A.baseFeePerGas):null,blobGasUsed:A.blobGasUsed?BigInt(A.blobGasUsed):void 0,difficulty:A.difficulty?BigInt(A.difficulty):void 0,excessBlobGas:A.excessBlobGas?BigInt(A.excessBlobGas):void 0,gasLimit:A.gasLimit?BigInt(A.gasLimit):void 0,gasUsed:A.gasUsed?BigInt(A.gasUsed):void 0,hash:A.hash?A.hash:null,logsBloom:A.logsBloom?A.logsBloom:null,nonce:A.nonce?A.nonce:null,number:A.number?BigInt(A.number):null,size:A.size?BigInt(A.size):void 0,timestamp:A.timestamp?BigInt(A.timestamp):void 0,transactions:t,totalDifficulty:A.totalDifficulty?BigInt(A.totalDifficulty):null}}const Aw=ml("block",ZE);async function ur(A,{blockHash:e,blockNumber:t,blockTag:n=A.experimental_blockTag??"latest",includeTransactions:r}={}){const s=r??!1,i=t!==void 0?NA(t):void 0;let a=null;if(e?a=await A.request({method:"eth_getBlockByHash",params:[e,s]},{dedupe:!0}):a=await A.request({method:"eth_getBlockByNumber",params:[i||n,s]},{dedupe:!!i}),!a)throw new Zm({blockHash:e,blockNumber:t});return(A.chain?.formatters?.block?.format||ZE)(a,"getBlock")}async function XE(A){const e=await A.request({method:"eth_gasPrice"});return BigInt(e)}async function lG(A,e){return ew(A,e)}async function ew(A,e){const{block:t,chain:n=A.chain,request:r}=e||{};try{const s=n?.fees?.maxPriorityFeePerGas??n?.fees?.defaultPriorityFee;if(typeof s=="function"){const a=t||await qA(A,ur,"getBlock")({}),g=await s({block:a,client:A,request:r});if(g===null)throw new Error;return g}if(typeof s<"u")return s;const i=await A.request({method:"eth_maxPriorityFeePerGas"});return ot(i)}catch{const[s,i]=await Promise.all([t?Promise.resolve(t):qA(A,ur,"getBlock")({}),qA(A,XE,"getGasPrice")({})]);if(typeof s.baseFeePerGas!="bigint")throw new VE;const a=i-s.baseFeePerGas;return a<0n?0n:a}}async function uG(A,e){return gQ(A,e)}async function gQ(A,e){const{block:t,chain:n=A.chain,request:r,type:s="eip1559"}=e||{},i=await(async()=>typeof n?.fees?.baseFeeMultiplier=="function"?n.fees.baseFeeMultiplier({block:t,client:A,request:r}):n?.fees?.baseFeeMultiplier??1.2)();if(i<1)throw new Vm;const g=10**(i.toString().split(".")[1]?.length??0),c=Q=>Q*BigInt(Math.ceil(i*g))/BigInt(g),l=t||await qA(A,ur,"getBlock")({});if(typeof n?.fees?.estimateFeesPerGas=="function"){const Q=await n.fees.estimateFeesPerGas({block:t,client:A,multiply:c,request:r,type:s});if(Q!==null)return Q}if(s==="eip1559"){if(typeof l.baseFeePerGas!="bigint")throw new VE;const Q=typeof r?.maxPriorityFeePerGas=="bigint"?r.maxPriorityFeePerGas:await ew(A,{block:l,chain:n,request:r}),u=c(l.baseFeePerGas);return{maxFeePerGas:r?.maxFeePerGas??u+Q,maxPriorityFeePerGas:Q}}return{gasPrice:r?.gasPrice??c(await qA(A,XE,"getGasPrice")({}))}}async function $E(A,{address:e,blockTag:t="latest",blockNumber:n}){const r=await A.request({method:"eth_getTransactionCount",params:[e,typeof n=="bigint"?NA(n):t]},{dedupe:!!n});return zn(r)}function Ad(A){const{kzg:e}=A,t=A.to??(typeof A.blobs[0]=="string"?"hex":"bytes"),n=typeof A.blobs[0]=="string"?A.blobs.map(s=>Tn(s)):A.blobs,r=[];for(const s of n)r.push(Uint8Array.from(e.blobToKzgCommitment(s)));return t==="bytes"?r:r.map(s=>qt(s))}function ed(A){const{kzg:e}=A,t=A.to??(typeof A.blobs[0]=="string"?"hex":"bytes"),n=typeof A.blobs[0]=="string"?A.blobs.map(i=>Tn(i)):A.blobs,r=typeof A.commitments[0]=="string"?A.commitments.map(i=>Tn(i)):A.commitments,s=[];for(let i=0;i<n.length;i++){const a=n[i],g=r[i];s.push(Uint8Array.from(e.computeBlobKzgProof(a,g)))}return t==="bytes"?s:s.map(i=>qt(i))}function tw(A,e){const t=e||"hex",n=RB(Ir(A,{strict:!1})?os(A):A);return t==="bytes"?n:tt(n)}function BG(A){const{commitment:e,version:t=1}=A,n=A.to??(typeof e=="string"?"hex":"bytes"),r=tw(e,"bytes");return r.set([t],0),n==="bytes"?r:qt(r)}function nw(A){const{commitments:e,version:t}=A,n=A.to??(typeof e[0]=="string"?"hex":"bytes"),r=[];for(const s of e)r.push(BG({commitment:s,to:n,version:t}));return r}const s0=6,rw=32,td=4096,sw=rw*td,o0=sw*s0-1-1*td*s0,ow=1;class QG extends fA{constructor({maxSize:e,size:t}){super("Blob size is too large.",{metaMessages:[`Max: ${e} bytes`,`Given: ${t} bytes`],name:"BlobSizeTooLargeError"})}}class iw extends fA{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class EG extends fA{constructor({hash:e,size:t}){super(`Versioned hash "${e}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${t}`],name:"InvalidVersionedHashSizeError"})}}class dG extends fA{constructor({hash:e,version:t}){super(`Versioned hash "${e}" version is invalid.`,{metaMessages:[`Expected: ${ow}`,`Received: ${t}`],name:"InvalidVersionedHashVersionError"})}}function CG(A){const e=A.to??(typeof A.data=="string"?"hex":"bytes"),t=typeof A.data=="string"?Tn(A.data):A.data,n=pt(t);if(!n)throw new iw;if(n>o0)throw new QG({maxSize:o0,size:n});const r=[];let s=!0,i=0;for(;s;){const a=HE(new Uint8Array(sw));let g=0;for(;g<td;){const c=t.slice(i,i+(rw-1));if(a.pushByte(0),a.pushBytes(c),c.length<31){a.pushByte(128),s=!1;break}g++,i+=31}r.push(a)}return e==="bytes"?r.map(a=>a.bytes):r.map(a=>qt(a.bytes))}function aw(A){const{data:e,kzg:t,to:n}=A,r=A.blobs??CG({data:e,to:n}),s=A.commitments??Ad({blobs:r,kzg:t,to:n}),i=A.proofs??ed({blobs:r,commitments:s,kzg:t,to:n}),a=[];for(let g=0;g<r.length;g++)a.push({blob:r[g],commitment:s[g],proof:i[g]});return a}function gw(A){if(A.type)return A.type;if(typeof A.authorizationList<"u")return"eip7702";if(typeof A.blobs<"u"||typeof A.blobVersionedHashes<"u"||typeof A.maxFeePerBlobGas<"u"||typeof A.sidecars<"u")return"eip4844";if(typeof A.maxFeePerGas<"u"||typeof A.maxPriorityFeePerGas<"u")return"eip1559";if(typeof A.gasPrice<"u")return typeof A.accessList<"u"?"eip2930":"legacy";throw new q6({transaction:A})}function eg(A,{docsPath:e,...t}){const n=(()=>{const r=pl(A,t);return r instanceof $a?A:r})();return new H6(n,{docsPath:e,...t})}async function Jr(A){const e=await A.request({method:"eth_chainId"},{dedupe:!0});return zn(e)}async function nd(A,e){const{account:t=A.account,accessList:n,authorizationList:r,chain:s=A.chain,blobVersionedHashes:i,blobs:a,data:g,gas:c,gasPrice:l,maxFeePerBlobGas:B,maxFeePerGas:Q,maxPriorityFeePerGas:u,nonce:d,nonceManager:f,to:h,type:x,value:b,...m}=e,M=await(async()=>{if(!t||!f||typeof d<"u")return d;const P=Ct(t),L=s?s.id:await qA(A,Jr,"getChainId")({});return await f.consume({address:P.address,chainId:L,client:A})})();jr(e);const G=s?.formatters?.transactionRequest?.format,Z=(G||Is)({...Ni(m,{format:G}),account:t?Ct(t):void 0,accessList:n,authorizationList:r,blobs:a,blobVersionedHashes:i,data:g,gas:c,gasPrice:l,maxFeePerBlobGas:B,maxFeePerGas:Q,maxPriorityFeePerGas:u,nonce:M,to:h,type:x,value:b},"fillTransaction");try{const P=await A.request({method:"eth_fillTransaction",params:[Z]}),q=(s?.formatters?.transaction?.format||Ag)(P.tx);delete q.blockHash,delete q.blockNumber,delete q.r,delete q.s,delete q.transactionIndex,delete q.v,delete q.yParity,q.data=q.input,q.gas&&(q.gas=e.gas??q.gas),q.gasPrice&&(q.gasPrice=e.gasPrice??q.gasPrice),q.maxFeePerBlobGas&&(q.maxFeePerBlobGas=e.maxFeePerBlobGas??q.maxFeePerBlobGas),q.maxFeePerGas&&(q.maxFeePerGas=e.maxFeePerGas??q.maxFeePerGas),q.maxPriorityFeePerGas&&(q.maxPriorityFeePerGas=e.maxPriorityFeePerGas??q.maxPriorityFeePerGas),q.nonce&&(q.nonce=e.nonce??q.nonce);const v=await(async()=>{if(typeof s?.fees?.baseFeeMultiplier=="function"){const C=await qA(A,ur,"getBlock")({});return s.fees.baseFeeMultiplier({block:C,client:A,request:e})}return s?.fees?.baseFeeMultiplier??1.2})();if(v<1)throw new Vm;const w=10**(v.toString().split(".")[1]?.length??0),E=C=>C*BigInt(Math.ceil(v*w))/BigInt(w);return q.maxFeePerGas&&!e.maxFeePerGas&&(q.maxFeePerGas=E(q.maxFeePerGas)),q.gasPrice&&!e.gasPrice&&(q.gasPrice=E(q.gasPrice)),{raw:P.raw,transaction:{from:Z.from,...q}}}catch(P){throw eg(P,{...e,chain:A.chain})}}const rd=["blobVersionedHashes","chainId","fees","gas","nonce","type"],i0=new Map,Mu=new bi(128);async function ki(A,e){let t=e;t.account??=A.account,t.parameters??=rd;const{account:n,chain:r=A.chain,nonceManager:s,parameters:i}=t,a=(()=>{if(typeof r?.prepareTransactionRequest=="function")return{fn:r.prepareTransactionRequest,runAt:["beforeFillTransaction"]};if(Array.isArray(r?.prepareTransactionRequest))return{fn:r.prepareTransactionRequest[0],runAt:r.prepareTransactionRequest[1].runAt}})();let g;async function c(){return g||(typeof t.chainId<"u"?t.chainId:r?r.id:(g=await qA(A,Jr,"getChainId")({}),g))}const l=n&&Ct(n);let B=t.nonce;if(i.includes("nonce")&&typeof B>"u"&&l&&s){const M=await c();B=await s.consume({address:l.address,chainId:M,client:A})}a?.fn&&a.runAt?.includes("beforeFillTransaction")&&(t=await a.fn({...t,chain:r},{phase:"beforeFillTransaction"}),B??=t.nonce);const u=((i.includes("blobVersionedHashes")||i.includes("sidecars"))&&t.kzg&&t.blobs||Mu.get(A.uid)===!1||!["fees","gas"].some(G=>i.includes(G))?!1:!!(i.includes("chainId")&&typeof t.chainId!="number"||i.includes("nonce")&&typeof B!="number"||i.includes("fees")&&typeof t.gasPrice!="bigint"&&(typeof t.maxFeePerGas!="bigint"||typeof t.maxPriorityFeePerGas!="bigint")||i.includes("gas")&&typeof t.gas!="bigint"))?await qA(A,nd,"fillTransaction")({...t,nonce:B}).then(M=>{const{chainId:G,from:Y,gas:Z,gasPrice:P,nonce:L,maxFeePerBlobGas:q,maxFeePerGas:v,maxPriorityFeePerGas:U,type:w,...E}=M.transaction;return Mu.set(A.uid,!0),{...t,...Y?{from:Y}:{},...w&&!t.type?{type:w}:{},...typeof G<"u"?{chainId:G}:{},...typeof Z<"u"?{gas:Z}:{},...typeof P<"u"?{gasPrice:P}:{},...typeof L<"u"?{nonce:L}:{},...typeof q<"u"&&t.type!=="legacy"&&t.type!=="eip2930"?{maxFeePerBlobGas:q}:{},...typeof v<"u"&&t.type!=="legacy"&&t.type!=="eip2930"?{maxFeePerGas:v}:{},...typeof U<"u"&&t.type!=="legacy"&&t.type!=="eip2930"?{maxPriorityFeePerGas:U}:{},..."nonceKey"in E&&typeof E.nonceKey<"u"?{nonceKey:E.nonceKey}:{}}}).catch(M=>{const G=M;return G.name!=="TransactionExecutionError"||G.walk?.(Z=>{const P=Z;return P.name==="MethodNotFoundRpcError"||P.name==="MethodNotSupportedRpcError"})&&Mu.set(A.uid,!1),t}):t;B??=u.nonce,t={...u,...l?{from:l?.address}:{},...B?{nonce:B}:{}};const{blobs:d,gas:f,kzg:h,type:x}=t;a?.fn&&a.runAt?.includes("beforeFillParameters")&&(t=await a.fn({...t,chain:r},{phase:"beforeFillParameters"}));let b;async function m(){return b||(b=await qA(A,ur,"getBlock")({blockTag:"latest"}),b)}if(i.includes("nonce")&&typeof B>"u"&&l&&!s&&(t.nonce=await qA(A,$E,"getTransactionCount")({address:l.address,blockTag:"pending"})),(i.includes("blobVersionedHashes")||i.includes("sidecars"))&&d&&h){const M=Ad({blobs:d,kzg:h});if(i.includes("blobVersionedHashes")){const G=nw({commitments:M,to:"hex"});t.blobVersionedHashes=G}if(i.includes("sidecars")){const G=ed({blobs:d,commitments:M,kzg:h}),Y=aw({blobs:d,commitments:M,proofs:G,to:"hex"});t.sidecars=Y}}if(i.includes("chainId")&&(t.chainId=await c()),(i.includes("fees")||i.includes("type"))&&typeof x>"u")try{t.type=gw(t)}catch{let M=i0.get(A.uid);typeof M>"u"&&(M=typeof(await m())?.baseFeePerGas=="bigint",i0.set(A.uid,M)),t.type=M?"eip1559":"legacy"}if(i.includes("fees"))if(t.type!=="legacy"&&t.type!=="eip2930"){if(typeof t.maxFeePerGas>"u"||typeof t.maxPriorityFeePerGas>"u"){const M=await m(),{maxFeePerGas:G,maxPriorityFeePerGas:Y}=await gQ(A,{block:M,chain:r,request:t});if(typeof t.maxPriorityFeePerGas>"u"&&t.maxFeePerGas&&t.maxFeePerGas<Y)throw new gG({maxPriorityFeePerGas:Y});t.maxPriorityFeePerGas=Y,t.maxFeePerGas=G}}else{if(typeof t.maxFeePerGas<"u"||typeof t.maxPriorityFeePerGas<"u")throw new VE;if(typeof t.gasPrice>"u"){const M=await m(),{gasPrice:G}=await gQ(A,{block:M,chain:r,request:t,type:"legacy"});t.gasPrice=G}}return i.includes("gas")&&typeof f>"u"&&(t.gas=await qA(A,sd,"estimateGas")({...t,account:l,prepare:l?.type==="local"?[]:["blobVersionedHashes"]})),a?.fn&&a.runAt?.includes("afterFillParameters")&&(t=await a.fn({...t,chain:r},{phase:"afterFillParameters"})),jr(t),delete t.parameters,t}async function sd(A,e){const{account:t=A.account,prepare:n=!0}=e,r=t?Ct(t):void 0,s=(()=>{if(Array.isArray(n))return n;if(r?.type!=="local")return["blobVersionedHashes"]})();try{const i=await(async()=>{if(e.to)return e.to;if(e.authorizationList&&e.authorizationList.length>0)return await hl({authorization:e.authorizationList[0]}).catch(()=>{throw new fA("`to` is required. Could not infer from `authorizationList`")})})(),{accessList:a,authorizationList:g,blobs:c,blobVersionedHashes:l,blockNumber:B,blockTag:Q,data:u,gas:d,gasPrice:f,maxFeePerBlobGas:h,maxFeePerGas:x,maxPriorityFeePerGas:b,nonce:m,value:M,stateOverride:G,...Y}=n?await ki(A,{...e,parameters:s,to:i}):e;if(d&&e.gas!==d)return d;const P=(typeof B=="bigint"?NA(B):void 0)||Q,L=WE(G);jr(e);const q=A.chain?.formatters?.transactionRequest?.format,U=(q||Is)({...Ni(Y,{format:q}),account:r,accessList:a,authorizationList:g,blobs:c,blobVersionedHashes:l,data:u,gasPrice:f,maxFeePerBlobGas:h,maxFeePerGas:x,maxPriorityFeePerGas:b,nonce:m,to:i,value:M},"estimateGas");return BigInt(await A.request({method:"eth_estimateGas",params:L?[U,P??A.experimental_blockTag??"latest",L]:P?[U,P]:[U]}))}catch(i){throw nG(i,{...e,account:r,chain:A.chain})}}async function IG(A,e){const{abi:t,address:n,args:r,functionName:s,dataSuffix:i=typeof A.dataSuffix=="string"?A.dataSuffix:A.dataSuffix?.value,...a}=e,g=mn({abi:t,args:r,functionName:s});try{return await qA(A,sd,"estimateGas")({data:`${g}${i?i.replace("0x",""):""}`,to:n,...a})}catch(c){const l=a.account?Ct(a.account):void 0;throw Io(c,{abi:t,address:n,args:r,docsPath:"/docs/contract/estimateContractGas",functionName:s,sender:l?.address})}}function tg(A,e){if(!mt(A,{strict:!1}))throw new Jt({address:A});if(!mt(e,{strict:!1}))throw new Jt({address:e});return A.toLowerCase()===e.toLowerCase()}function fr(A,{args:e,eventName:t}={}){return{...A,blockHash:A.blockHash?A.blockHash:null,blockNumber:A.blockNumber?BigInt(A.blockNumber):null,blockTimestamp:A.blockTimestamp?BigInt(A.blockTimestamp):A.blockTimestamp===null?null:void 0,logIndex:A.logIndex?Number(A.logIndex):null,transactionHash:A.transactionHash?A.transactionHash:null,transactionIndex:A.transactionIndex?Number(A.transactionIndex):null,...t?{args:e,eventName:t}:{}}}const a0="/docs/contract/decodeEventLog";function kc(A){const{abi:e,data:t,strict:n,topics:r}=A,s=n??!0,[i,...a]=r;if(!i)throw new jF({docsPath:a0});const g=e.find(x=>x.type==="event"&&i===dl(Cr(x)));if(!(g&&"name"in g)||g.type!=="event")throw new JF(i,{docsPath:a0});const{name:c,inputs:l}=g,B=l?.some(x=>!("name"in x&&x.name)),Q=B?[]:{},u=l.map((x,b)=>[x,b]).filter(([x])=>"indexed"in x&&x.indexed),d=[];for(let x=0;x<u.length;x++){const[b,m]=u[x],M=a[x];if(!M){if(s)throw new KE({abiItem:g,param:b});d.push([b,m]);continue}Q[B?m:b.name||m]=fG({param:b,value:M})}const f=l.filter(x=>!("indexed"in x&&x.indexed)),h=s?f:[...d.map(([x])=>x),...f];if(h.length>0){if(t&&t!=="0x")try{const x=Za(h,t);if(x){let b=0;if(!s)for(const[m,M]of d)Q[B?M:m.name||M]=x[b++];if(B)for(let m=0;m<l.length;m++)Q[m]===void 0&&b<x.length&&(Q[m]=x[b++]);else for(let m=0;m<f.length;m++)Q[f[m].name]=x[b++]}}catch(x){if(s)throw x instanceof mm||x instanceof Tm?new Nc({abiItem:g,data:t,params:h,size:pt(t)}):x}else if(s)throw new Nc({abiItem:g,data:"0x",params:h,size:0})}return{eventName:c,args:Object.values(Q).length>0?Q:void 0}}function fG({param:A,value:e}){return A.type==="string"||A.type==="bytes"||A.type==="tuple"||A.type.match(/^(.*)\[(\d+)?\]$/)?e:(Za([A],e)||[])[0]}function od(A){const{abi:e,args:t,logs:n,strict:r=!0}=A,s=(()=>{if(A.eventName)return Array.isArray(A.eventName)?A.eventName:[A.eventName]})(),i=e.filter(a=>a.type==="event").map(a=>({abi:a,selector:dl(a)}));return n.map(a=>{const g=typeof a.blockNumber=="string"?fr(a):a,c=i.filter(Q=>g.topics[0]===Q.selector);if(c.length===0)return null;let l,B;for(const Q of c)try{l=kc({...g,abi:[Q.abi],strict:!0}),B=Q;break}catch{}if(!l&&!r){B=c[0];try{l=kc({data:g.data,topics:g.topics,abi:[B.abi],strict:!1})}catch{const Q=B.abi.inputs?.some(u=>!("name"in u&&u.name));return{...g,args:Q?[]:{},eventName:B.abi.name}}}return!l||!B||s&&!s.includes(l.eventName)||!hG({args:l.args,inputs:B.abi.inputs,matchArgs:t})?null:{...l,...g}}).filter(Boolean)}function hG(A){const{args:e,inputs:t,matchArgs:n}=A;if(!n)return!0;if(!e)return!1;function r(s,i,a){try{return s.type==="address"?tg(i,a):s.type==="string"||s.type==="bytes"?Vt(os(i))===a:i===a}catch{return!1}}return Array.isArray(e)&&Array.isArray(n)?n.every((s,i)=>{if(s==null)return!0;const a=t[i];return a?(Array.isArray(s)?s:[s]).some(c=>r(a,c,e[i])):!1}):typeof e=="object"&&!Array.isArray(e)&&typeof n=="object"&&!Array.isArray(n)?Object.entries(n).every(([s,i])=>{if(i==null)return!0;const a=t.find(c=>c.name===s);return a?(Array.isArray(i)?i:[i]).some(c=>r(a,c,e[s])):!1}):!1}async function id(A,{address:e,blockHash:t,fromBlock:n,toBlock:r,event:s,events:i,args:a,strict:g}={}){const c=g??!1,l=i??(s?[s]:void 0);let B=[];l&&(B=[l.flatMap(f=>Va({abi:[f],eventName:f.name,args:i?void 0:a}))],s&&(B=B[0]));let Q;t?Q=await A.request({method:"eth_getLogs",params:[{address:e,topics:B,blockHash:t}]}):Q=await A.request({method:"eth_getLogs",params:[{address:e,topics:B,fromBlock:typeof n=="bigint"?NA(n):n,toBlock:typeof r=="bigint"?NA(r):r}]});const u=Q.map(d=>fr(d));return l?od({abi:l,args:a,logs:u,strict:c}):u}async function cw(A,e){const{abi:t,address:n,args:r,blockHash:s,eventName:i,fromBlock:a,toBlock:g,strict:c}=e,l=i?Fo({abi:t,name:i}):void 0,B=l?void 0:t.filter(Q=>Q.type==="event");return qA(A,id,"getLogs")({address:n,args:r,blockHash:s,event:l,events:B,fromBlock:a,toBlock:g,strict:c})}const vu="/docs/contract/decodeFunctionResult";function Os(A){const{abi:e,args:t,functionName:n,data:r}=A;let s=e[0];if(n){const a=Fo({abi:e,args:t,name:n});if(!a)throw new gi(n,{docsPath:vu});s=a}if(s.type!=="function")throw new gi(void 0,{docsPath:vu});if(!s.outputs)throw new xm(s.name,{docsPath:vu});const i=Za(s.outputs,r);if(i&&i.length>1)return i;if(i&&i.length===1)return i[0]}const pG="0.1.1";function mG(){return pG}class pe extends Error{static setStaticOptions(e){pe.prototype.docsOrigin=e.docsOrigin,pe.prototype.showVersion=e.showVersion,pe.prototype.version=e.version}constructor(e,t={}){const n=(()=>{if(t.cause instanceof pe){if(t.cause.details)return t.cause.details;if(t.cause.shortMessage)return t.cause.shortMessage}return t.cause&&"details"in t.cause&&typeof t.cause.details=="string"?t.cause.details:t.cause?.message?t.cause.message:t.details})(),r=t.cause instanceof pe&&t.cause.docsPath||t.docsPath,s=t.docsOrigin??pe.prototype.docsOrigin,i=`${s}${r??""}`,a=!!(t.version??pe.prototype.showVersion),g=t.version??pe.prototype.version,c=[e||"An error occurred.",...t.metaMessages?["",...t.metaMessages]:[],...n||r||a?["",n?`Details: ${n}`:void 0,r?`See: ${i}`:void 0,a?`Version: ${g}`:void 0]:[]].filter(l=>typeof l=="string").join(`
148
148
  `);super(c,t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsOrigin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"showVersion",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.cause=t.cause,this.details=n,this.docs=i,this.docsOrigin=s,this.docsPath=r,this.shortMessage=e,this.showVersion=a,this.version=g}walk(e){return lw(this,e)}}Object.defineProperty(pe,"defaultStaticOptions",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:"https://oxlib.sh",showVersion:!1,version:`ox@${mG()}`}});pe.setStaticOptions(pe.defaultStaticOptions);function lw(A,e){return e?.(A)?A:A&&typeof A=="object"&&"cause"in A&&A.cause?lw(A.cause,e):e?null:A}function ng(A,e){if(Ho(A)>e)throw new OG({givenSize:Ho(A),maxSize:e})}const Vr={zero:48,nine:57,A:65,F:70,a:97,f:102};function g0(A){if(A>=Vr.zero&&A<=Vr.nine)return A-Vr.zero;if(A>=Vr.A&&A<=Vr.F)return A-(Vr.A-10);if(A>=Vr.a&&A<=Vr.f)return A-(Vr.a-10)}function wG(A,e={}){const{dir:t,size:n=32}=e;if(n===0)return A;if(A.length>n)throw new KG({size:A.length,targetSize:n,type:"Bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const i=t==="right";r[i?s:n-s-1]=A[i?s:A.length-s-1]}return r}function uw(A,e={}){const{dir:t="left"}=e;let n=A,r=0;for(let s=0;s<n.length-1&&n[t==="left"?s:n.length-s-1].toString()==="0";s++)r++;return n=t==="left"?n.slice(r):n.slice(0,n.length-r),n}function xl(A,e){if(Wn(A)>e)throw new PG({givenSize:Wn(A),maxSize:e})}function xG(A,e){if(typeof e=="number"&&e>0&&e>Wn(A)-1)throw new pw({offset:e,position:"start",size:Wn(A)})}function yG(A,e,t){if(typeof e=="number"&&typeof t=="number"&&Wn(A)!==t-e)throw new pw({offset:t,position:"end",size:Wn(A)})}function Bw(A,e={}){const{dir:t,size:n=32}=e;if(n===0)return A;const r=A.replace("0x","");if(r.length>n*2)throw new _G({size:Math.ceil(r.length/2),targetSize:n,type:"Hex"});return`0x${r[t==="right"?"padEnd":"padStart"](n*2,"0")}`}const DG="#__bigint";function Qw(A,e,t){return JSON.stringify(A,(n,r)=>typeof r=="bigint"?r.toString()+DG:r,t)}const bG=new TextDecoder,NG=new TextEncoder;function kG(A){return A instanceof Uint8Array?A:typeof A=="string"?Ew(A):MG(A)}function MG(A){return A instanceof Uint8Array?A:new Uint8Array(A)}function Ew(A,e={}){const{size:t}=e;let n=A;t&&(xl(A,t),n=po(A,t));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,i=new Uint8Array(s);for(let a=0,g=0;a<s;a++){const c=g0(r.charCodeAt(g++)),l=g0(r.charCodeAt(g++));if(c===void 0||l===void 0)throw new pe(`Invalid byte sequence ("${r[g-2]}${r[g-1]}" in "${r}").`);i[a]=c<<4|l}return i}function vG(A,e={}){const{size:t}=e,n=NG.encode(A);return typeof t=="number"?(ng(n,t),SG(n,t)):n}function SG(A,e){return wG(A,{dir:"right",size:e})}function Ho(A){return A.length}function FG(A,e,t,n={}){const{strict:r}=n;return A.slice(e,t)}function GG(A,e={}){const{size:t}=e;typeof t<"u"&&ng(A,t);const n=pr(A,e);return Iw(n,e)}function RG(A,e={}){const{size:t}=e;let n=A;if(typeof t<"u"&&(ng(n,t),n=dw(n)),n.length>1||n[0]>1)throw new LG(n);return!!n[0]}function as(A,e={}){const{size:t}=e;typeof t<"u"&&ng(A,t);const n=pr(A,e);return fw(n,e)}function UG(A,e={}){const{size:t}=e;let n=A;return typeof t<"u"&&(ng(n,t),n=TG(n)),bG.decode(n)}function dw(A){return uw(A,{dir:"left"})}function TG(A){return uw(A,{dir:"right"})}class LG extends pe{constructor(e){super(`Bytes value \`${e}\` is not a valid boolean.`,{metaMessages:["The bytes array must contain a single byte of either a `0` or `1` value."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.InvalidBytesBooleanError"})}}let OG=class extends pe{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}},KG=class extends pe{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}};const jG=new TextEncoder,JG=Array.from({length:256},(A,e)=>e.toString(16).padStart(2,"0"));function qG(A,e={}){const{strict:t=!1}=e;if(!A)throw new c0(A);if(typeof A!="string")throw new c0(A);if(t&&!/^0x[0-9a-fA-F]*$/.test(A))throw new l0(A);if(!A.startsWith("0x"))throw new l0(A)}function hr(...A){return`0x${A.reduce((e,t)=>e+t.replace("0x",""),"")}`}function YG(A){return A instanceof Uint8Array?pr(A):Array.isArray(A)?pr(new Uint8Array(A)):A}function Cw(A,e={}){const t=`0x${Number(A)}`;return typeof e.size=="number"?(xl(t,e.size),ho(t,e.size)):t}function pr(A,e={}){let t="";for(let r=0;r<A.length;r++)t+=JG[A[r]];const n=`0x${t}`;return typeof e.size=="number"?(xl(n,e.size),po(n,e.size)):n}function wn(A,e={}){const{signed:t,size:n}=e,r=BigInt(A);let s;n?t?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof A=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const i=typeof s=="bigint"&&t?-s-1n:0;if(s&&r>s||r<i){const c=typeof A=="bigint"?"n":"";throw new hw({max:s?`${s}${c}`:void 0,min:`${i}${c}`,signed:t,size:n,value:`${A}${c}`})}const g=`0x${(t&&r<0?BigInt.asUintN(n*8,BigInt(r)):r).toString(16)}`;return n?ho(g,n):g}function ad(A,e={}){return pr(jG.encode(A),e)}function ho(A,e){return Bw(A,{dir:"left",size:e})}function po(A,e){return Bw(A,{dir:"right",size:e})}function Gr(A,e,t,n={}){const{strict:r}=n;xG(A,e);const s=`0x${A.replace("0x","").slice((e??0)*2,(t??A.length)*2)}`;return r&&yG(s,e,t),s}function Wn(A){return Math.ceil((A.length-2)/2)}function Iw(A,e={}){const{signed:t}=e;e.size&&xl(A,e.size);const n=BigInt(A);if(!t)return n;const r=(A.length-2)/2,s=(1n<<BigInt(r)*8n)-1n,i=s>>1n;return n<=i?n:n-s-1n}function fw(A,e={}){const{signed:t,size:n}=e;return Number(!t&&!n?A:Iw(A,e))}function HG(A,e={}){const{strict:t=!1}=e;try{return qG(A,{strict:t}),!0}catch{return!1}}class hw extends pe{constructor({max:e,min:t,signed:n,size:r,value:s}){super(`Number \`${s}\` is not in safe${r?` ${r*8}-bit`:""}${n?" signed":" unsigned"} integer range ${e?`(\`${t}\` to \`${e}\`)`:`(above \`${t}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class c0 extends pe{constructor(e){super(`Value \`${typeof e=="object"?Qw(e):e}\` of type \`${typeof e}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}}class l0 extends pe{constructor(e){super(`Value \`${e}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}}class PG extends pe{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class pw extends pe{constructor({offset:e,position:t,size:n}){super(`Slice ${t==="start"?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}class _G extends pe{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}function zG(A){return{address:A.address,amount:wn(A.amount),index:wn(A.index),validatorIndex:wn(A.validatorIndex)}}function mw(A){return{...typeof A.baseFeePerGas=="bigint"&&{baseFeePerGas:wn(A.baseFeePerGas)},...typeof A.blobBaseFee=="bigint"&&{blobBaseFee:wn(A.blobBaseFee)},...typeof A.feeRecipient=="string"&&{feeRecipient:A.feeRecipient},...typeof A.gasLimit=="bigint"&&{gasLimit:wn(A.gasLimit)},...typeof A.number=="bigint"&&{number:wn(A.number)},...typeof A.prevRandao=="bigint"&&{prevRandao:wn(A.prevRandao)},...typeof A.time=="bigint"&&{time:wn(A.time)},...A.withdrawals&&{withdrawals:A.withdrawals.map(zG)}}}const Qi=[{inputs:[{components:[{name:"target",type:"address"},{name:"allowFailure",type:"bool"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate3",outputs:[{components:[{name:"success",type:"bool"},{name:"returnData",type:"bytes"}],name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{name:"addr",type:"address"}],name:"getEthBalance",outputs:[{name:"balance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockTimestamp",outputs:[{internalType:"uint256",name:"timestamp",type:"uint256"}],stateMutability:"view",type:"function"}],cQ=[{name:"query",type:"function",stateMutability:"view",inputs:[{type:"tuple[]",name:"queries",components:[{type:"address",name:"sender"},{type:"string[]",name:"urls"},{type:"bytes",name:"data"}]}],outputs:[{type:"bool[]",name:"failures"},{type:"bytes[]",name:"responses"}]},{name:"HttpError",type:"error",inputs:[{type:"uint16",name:"status"},{type:"string",name:"message"}]}],ww=[{inputs:[{name:"dns",type:"bytes"}],name:"DNSDecodingFailed",type:"error"},{inputs:[{name:"ens",type:"string"}],name:"DNSEncodingFailed",type:"error"},{inputs:[],name:"EmptyAddress",type:"error"},{inputs:[{name:"status",type:"uint16"},{name:"message",type:"string"}],name:"HttpError",type:"error"},{inputs:[],name:"InvalidBatchGatewayResponse",type:"error"},{inputs:[{name:"errorData",type:"bytes"}],name:"ResolverError",type:"error"},{inputs:[{name:"name",type:"bytes"},{name:"resolver",type:"address"}],name:"ResolverNotContract",type:"error"},{inputs:[{name:"name",type:"bytes"}],name:"ResolverNotFound",type:"error"},{inputs:[{name:"primary",type:"string"},{name:"primaryAddress",type:"bytes"}],name:"ReverseAddressMismatch",type:"error"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"UnsupportedResolverProfile",type:"error"}],xw=[...ww,{name:"resolveWithGateways",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes"},{name:"data",type:"bytes"},{name:"gateways",type:"string[]"}],outputs:[{name:"",type:"bytes"},{name:"address",type:"address"}]}],WG=[...ww,{name:"reverseWithGateways",type:"function",stateMutability:"view",inputs:[{type:"bytes",name:"reverseName"},{type:"uint256",name:"coinType"},{type:"string[]",name:"gateways"}],outputs:[{type:"string",name:"resolvedName"},{type:"address",name:"resolver"},{type:"address",name:"reverseResolver"}]}],u0=[{name:"text",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"key",type:"string"}],outputs:[{name:"",type:"string"}]}],B0=[{name:"addr",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"}],outputs:[{name:"",type:"address"}]},{name:"addr",type:"function",stateMutability:"view",inputs:[{name:"name",type:"bytes32"},{name:"coinType",type:"uint256"}],outputs:[{name:"",type:"bytes"}]}],yw=[{name:"isValidSignature",type:"function",stateMutability:"view",inputs:[{name:"hash",type:"bytes32"},{name:"signature",type:"bytes"}],outputs:[{name:"",type:"bytes4"}]}],Q0=[{inputs:[{name:"_signer",type:"address"},{name:"_hash",type:"bytes32"},{name:"_signature",type:"bytes"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{name:"_signer",type:"address"},{name:"_hash",type:"bytes32"},{name:"_signature",type:"bytes"}],outputs:[{type:"bool"}],stateMutability:"nonpayable",type:"function",name:"isValidSig"}],VG="0x82ad56cb",Dw="0x608060405234801561001057600080fd5b5060405161018e38038061018e83398101604081905261002f91610124565b6000808351602085016000f59050803b61004857600080fd5b6000808351602085016000855af16040513d6000823e81610067573d81fd5b3d81f35b634e487b7160e01b600052604160045260246000fd5b600082601f83011261009257600080fd5b81516001600160401b038111156100ab576100ab61006b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156100d9576100d961006b565b6040528181528382016020018510156100f157600080fd5b60005b82811015610110576020818601810151838301820152016100f4565b506000918101602001919091529392505050565b6000806040838503121561013757600080fd5b82516001600160401b0381111561014d57600080fd5b61015985828601610081565b602085015190935090506001600160401b0381111561017757600080fd5b61018385828601610081565b915050925092905056fe",ZG="0x608060405234801561001057600080fd5b506040516102c03803806102c083398101604081905261002f916101e6565b836001600160a01b03163b6000036100e457600080836001600160a01b03168360405161005c9190610270565b6000604051808303816000865af19150503d8060008114610099576040519150601f19603f3d011682016040523d82523d6000602084013e61009e565b606091505b50915091508115806100b857506001600160a01b0386163b155b156100e1578060405163101bb98d60e01b81526004016100d8919061028c565b60405180910390fd5b50505b6000808451602086016000885af16040513d6000823e81610103573d81fd5b3d81f35b80516001600160a01b038116811461011e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561015457818101518382015260200161013c565b50506000910152565b600082601f83011261016e57600080fd5b81516001600160401b0381111561018757610187610123565b604051601f8201601f19908116603f011681016001600160401b03811182821017156101b5576101b5610123565b6040528181528382016020018510156101cd57600080fd5b6101de826020830160208701610139565b949350505050565b600080600080608085870312156101fc57600080fd5b61020585610107565b60208601519094506001600160401b0381111561022157600080fd5b61022d8782880161015d565b93505061023c60408601610107565b60608601519092506001600160401b0381111561025857600080fd5b6102648782880161015d565b91505092959194509250565b60008251610282818460208701610139565b9190910192915050565b60208152600082518060208401526102ab816040850160208701610139565b601f01601f1916919091016040019291505056fe",XG="0x608060405234801561001057600080fd5b5060405161069438038061069483398101604081905261002f9161051e565b600061003c848484610048565b9050806000526001601ff35b60007f64926492649264926492649264926492649264926492649264926492649264926100748361040c565b036101e7576000606080848060200190518101906100929190610577565b60405192955090935091506000906001600160a01b038516906100b69085906105dd565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b9087906004016105f9565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d19190610633565b6001600160e01b03191614945050505050610405565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e9061022790879087906004016105f9565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102689190610633565b6001600160e01b031916149050610405565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e7610425565b5060208201516040808401518451859392600091859190811061030c5761030c61065d565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b60408051600081526020810180835289905260ff83169181019190915260608101849052608081018390526001600160a01b0389169060019060a0016020604051602081039080840390855afa1580156103ea573d6000803e3d6000fd5b505050602060405103516001600160a01b0316149450505050505b9392505050565b600060208251101561041d57600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b038116811461045857600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561048c578181015183820152602001610474565b50506000910152565b600082601f8301126104a657600080fd5b81516001600160401b038111156104bf576104bf61045b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156104ed576104ed61045b565b60405281815283820160200185101561050557600080fd5b610516826020830160208701610471565b949350505050565b60008060006060848603121561053357600080fd5b835161053e81610443565b6020850151604086015191945092506001600160401b0381111561056157600080fd5b61056d86828701610495565b9150509250925092565b60008060006060848603121561058c57600080fd5b835161059781610443565b60208501519093506001600160401b038111156105b357600080fd5b6105bf86828701610495565b604086015190935090506001600160401b0381111561056157600080fd5b600082516105ef818460208701610471565b9190910192915050565b828152604060208201526000825180604084015261061e816060850160208701610471565b601f01601f1916919091016060019392505050565b60006020828403121561064557600080fd5b81516001600160e01b03198116811461040557600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572",gd="0x608060405234801561001057600080fd5b506115b9806100206000396000f3fe6080604052600436106100f35760003560e01c80634d2301cc1161008a578063a8b0574e11610059578063a8b0574e14610325578063bce38bd714610350578063c3077fa914610380578063ee82ac5e146103b2576100f3565b80634d2301cc1461026257806372425d9d1461029f57806382ad56cb146102ca57806386d516e8146102fa576100f3565b80633408e470116100c65780633408e470146101af578063399542e9146101da5780633e64a6961461020c57806342cbb15c14610237576100f3565b80630f28c97d146100f8578063174dea7114610123578063252dba421461015357806327e86d6e14610184575b600080fd5b34801561010457600080fd5b5061010d6103ef565b60405161011a9190610c0a565b60405180910390f35b61013d60048036038101906101389190610c94565b6103f7565b60405161014a9190610e94565b60405180910390f35b61016d60048036038101906101689190610f0c565b610615565b60405161017b92919061101b565b60405180910390f35b34801561019057600080fd5b506101996107ab565b6040516101a69190611064565b60405180910390f35b3480156101bb57600080fd5b506101c46107b7565b6040516101d19190610c0a565b60405180910390f35b6101f460048036038101906101ef91906110ab565b6107bf565b6040516102039392919061110b565b60405180910390f35b34801561021857600080fd5b506102216107e1565b60405161022e9190610c0a565b60405180910390f35b34801561024357600080fd5b5061024c6107e9565b6040516102599190610c0a565b60405180910390f35b34801561026e57600080fd5b50610289600480360381019061028491906111a7565b6107f1565b6040516102969190610c0a565b60405180910390f35b3480156102ab57600080fd5b506102b4610812565b6040516102c19190610c0a565b60405180910390f35b6102e460048036038101906102df919061122a565b61081a565b6040516102f19190610e94565b60405180910390f35b34801561030657600080fd5b5061030f6109e4565b60405161031c9190610c0a565b60405180910390f35b34801561033157600080fd5b5061033a6109ec565b6040516103479190611286565b60405180910390f35b61036a600480360381019061036591906110ab565b6109f4565b6040516103779190610e94565b60405180910390f35b61039a60048036038101906103959190610f0c565b610ba6565b6040516103a99392919061110b565b60405180910390f35b3480156103be57600080fd5b506103d960048036038101906103d491906112cd565b610bca565b6040516103e69190611064565b60405180910390f35b600042905090565b60606000808484905090508067ffffffffffffffff81111561041c5761041b6112fa565b5b60405190808252806020026020018201604052801561045557816020015b610442610bd5565b81526020019060019003908161043a5790505b5092503660005b828110156105c957600085828151811061047957610478611329565b5b6020026020010151905087878381811061049657610495611329565b5b90506020028101906104a89190611367565b925060008360400135905080860195508360000160208101906104cb91906111a7565b73ffffffffffffffffffffffffffffffffffffffff16818580606001906104f2919061138f565b604051610500929190611431565b60006040518083038185875af1925050503d806000811461053d576040519150601f19603f3d011682016040523d82523d6000602084013e610542565b606091505b5083600001846020018290528215151515815250505081516020850135176105bc577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b826001019250505061045c565b5082341461060c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610603906114a7565b60405180910390fd5b50505092915050565b6000606043915060008484905090508067ffffffffffffffff81111561063e5761063d6112fa565b5b60405190808252806020026020018201604052801561067157816020015b606081526020019060019003908161065c5790505b5091503660005b828110156107a157600087878381811061069557610694611329565b5b90506020028101906106a791906114c7565b92508260000160208101906106bc91906111a7565b73ffffffffffffffffffffffffffffffffffffffff168380602001906106e2919061138f565b6040516106f0929190611431565b6000604051808303816000865af19150503d806000811461072d576040519150601f19603f3d011682016040523d82523d6000602084013e610732565b606091505b5086848151811061074657610745611329565b5b60200260200101819052819250505080610795576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078c9061153b565b60405180910390fd5b81600101915050610678565b5050509250929050565b60006001430340905090565b600046905090565b6000806060439250434091506107d68686866109f4565b905093509350939050565b600048905090565b600043905090565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b600044905090565b606060008383905090508067ffffffffffffffff81111561083e5761083d6112fa565b5b60405190808252806020026020018201604052801561087757816020015b610864610bd5565b81526020019060019003908161085c5790505b5091503660005b828110156109db57600084828151811061089b5761089a611329565b5b602002602001015190508686838181106108b8576108b7611329565b5b90506020028101906108ca919061155b565b92508260000160208101906108df91906111a7565b73ffffffffffffffffffffffffffffffffffffffff16838060400190610905919061138f565b604051610913929190611431565b6000604051808303816000865af19150503d8060008114610950576040519150601f19603f3d011682016040523d82523d6000602084013e610955565b606091505b5082600001836020018290528215151515815250505080516020840135176109cf577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b8160010191505061087e565b50505092915050565b600045905090565b600041905090565b606060008383905090508067ffffffffffffffff811115610a1857610a176112fa565b5b604051908082528060200260200182016040528015610a5157816020015b610a3e610bd5565b815260200190600190039081610a365790505b5091503660005b82811015610b9c576000848281518110610a7557610a74611329565b5b60200260200101519050868683818110610a9257610a91611329565b5b9050602002810190610aa491906114c7565b9250826000016020810190610ab991906111a7565b73ffffffffffffffffffffffffffffffffffffffff16838060200190610adf919061138f565b604051610aed929190611431565b6000604051808303816000865af19150503d8060008114610b2a576040519150601f19603f3d011682016040523d82523d6000602084013e610b2f565b606091505b508260000183602001829052821515151581525050508715610b90578060000151610b8f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b869061153b565b60405180910390fd5b5b81600101915050610a58565b5050509392505050565b6000806060610bb7600186866107bf565b8093508194508295505050509250925092565b600081409050919050565b6040518060400160405280600015158152602001606081525090565b6000819050919050565b610c0481610bf1565b82525050565b6000602082019050610c1f6000830184610bfb565b92915050565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f840112610c5457610c53610c2f565b5b8235905067ffffffffffffffff811115610c7157610c70610c34565b5b602083019150836020820283011115610c8d57610c8c610c39565b5b9250929050565b60008060208385031215610cab57610caa610c25565b5b600083013567ffffffffffffffff811115610cc957610cc8610c2a565b5b610cd585828601610c3e565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60008115159050919050565b610d2281610d0d565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610d62578082015181840152602081019050610d47565b83811115610d71576000848401525b50505050565b6000601f19601f8301169050919050565b6000610d9382610d28565b610d9d8185610d33565b9350610dad818560208601610d44565b610db681610d77565b840191505092915050565b6000604083016000830151610dd96000860182610d19565b5060208301518482036020860152610df18282610d88565b9150508091505092915050565b6000610e0a8383610dc1565b905092915050565b6000602082019050919050565b6000610e2a82610ce1565b610e348185610cec565b935083602082028501610e4685610cfd565b8060005b85811015610e825784840389528151610e638582610dfe565b9450610e6e83610e12565b925060208a01995050600181019050610e4a565b50829750879550505050505092915050565b60006020820190508181036000830152610eae8184610e1f565b905092915050565b60008083601f840112610ecc57610ecb610c2f565b5b8235905067ffffffffffffffff811115610ee957610ee8610c34565b5b602083019150836020820283011115610f0557610f04610c39565b5b9250929050565b60008060208385031215610f2357610f22610c25565b5b600083013567ffffffffffffffff811115610f4157610f40610c2a565b5b610f4d85828601610eb6565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000610f918383610d88565b905092915050565b6000602082019050919050565b6000610fb182610f59565b610fbb8185610f64565b935083602082028501610fcd85610f75565b8060005b858110156110095784840389528151610fea8582610f85565b9450610ff583610f99565b925060208a01995050600181019050610fd1565b50829750879550505050505092915050565b60006040820190506110306000830185610bfb565b81810360208301526110428184610fa6565b90509392505050565b6000819050919050565b61105e8161104b565b82525050565b60006020820190506110796000830184611055565b92915050565b61108881610d0d565b811461109357600080fd5b50565b6000813590506110a58161107f565b92915050565b6000806000604084860312156110c4576110c3610c25565b5b60006110d286828701611096565b935050602084013567ffffffffffffffff8111156110f3576110f2610c2a565b5b6110ff86828701610eb6565b92509250509250925092565b60006060820190506111206000830186610bfb565b61112d6020830185611055565b818103604083015261113f8184610e1f565b9050949350505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061117482611149565b9050919050565b61118481611169565b811461118f57600080fd5b50565b6000813590506111a18161117b565b92915050565b6000602082840312156111bd576111bc610c25565b5b60006111cb84828501611192565b91505092915050565b60008083601f8401126111ea576111e9610c2f565b5b8235905067ffffffffffffffff81111561120757611206610c34565b5b60208301915083602082028301111561122357611222610c39565b5b9250929050565b6000806020838503121561124157611240610c25565b5b600083013567ffffffffffffffff81111561125f5761125e610c2a565b5b61126b858286016111d4565b92509250509250929050565b61128081611169565b82525050565b600060208201905061129b6000830184611277565b92915050565b6112aa81610bf1565b81146112b557600080fd5b50565b6000813590506112c7816112a1565b92915050565b6000602082840312156112e3576112e2610c25565b5b60006112f1848285016112b8565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b600080fd5b600080fd5b60008235600160800383360303811261138357611382611358565b5b80830191505092915050565b600080833560016020038436030381126113ac576113ab611358565b5b80840192508235915067ffffffffffffffff8211156113ce576113cd61135d565b5b6020830192506001820236038313156113ea576113e9611362565b5b509250929050565b600081905092915050565b82818337600083830152505050565b600061141883856113f2565b93506114258385846113fd565b82840190509392505050565b600061143e82848661140c565b91508190509392505050565b600082825260208201905092915050565b7f4d756c746963616c6c333a2076616c7565206d69736d61746368000000000000600082015250565b6000611491601a8361144a565b915061149c8261145b565b602082019050919050565b600060208201905081810360008301526114c081611484565b9050919050565b6000823560016040038336030381126114e3576114e2611358565b5b80830191505092915050565b7f4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000600082015250565b600061152560178361144a565b9150611530826114ef565b602082019050919050565b6000602082019050818103600083015261155481611518565b9050919050565b60008235600160600383360303811261157757611576611358565b5b8083019150509291505056fea264697066735822122020c1bc9aacf8e4a6507193432a895a8e77094f45a1395583f07b24e860ef06cd64736f6c634300080c0033";class lQ extends fA{constructor({blockNumber:e,chain:t,contract:n}){super(`Chain "${t.name}" does not support contract "${n.name}".`,{metaMessages:["This could be due to any of the following:",...e&&n.blockCreated&&n.blockCreated>e?[`- The contract "${n.name}" was not deployed until block ${n.blockCreated} (current block ${e}).`]:[`- The chain does not have the contract "${n.name}" configured.`]],name:"ChainDoesNotSupportContract"})}}class $G extends fA{constructor({chain:e,currentChainId:t}){super(`The current chain of the wallet (id: ${t}) does not match the target chain for the transaction (id: ${e.id} – ${e.name}).`,{metaMessages:[`Current Chain ID: ${t}`,`Expected Chain ID: ${e.id} – ${e.name}`],name:"ChainMismatchError"})}}class AR extends fA{constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join(`
149
- `),{name:"ChainNotFoundError"})}}class bw extends fA{constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class rg extends fA{constructor({chainId:e}){super(typeof e=="number"?`Chain ID "${e}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const Su="/docs/contract/encodeDeployData";function yl(A){const{abi:e,args:t,bytecode:n}=A;if(!t||t.length===0)return n;const r=e.find(i=>"type"in i&&i.type==="constructor");if(!r)throw new pm({docsPath:Su});if(!("inputs"in r))throw new bc({docsPath:Su});if(!r.inputs||r.inputs.length===0)throw new bc({docsPath:Su});const s=Ls(r.inputs,t);return ir([n,s])}function Mi({blockNumber:A,chain:e,contract:t}){const n=e?.contracts?.[t];if(!n)throw new lQ({chain:e,contract:{name:t}});if(A&&n.blockCreated&&n.blockCreated>A)throw new lQ({blockNumber:A,chain:e,contract:{name:t,blockCreated:n.blockCreated}});return n.address}function Nw(A,{docsPath:e,...t}){const n=(()=>{const r=pl(A,t);return r instanceof $a?A:r})();return new qm(n,{docsPath:e,...t})}function cd(){let A=()=>{},e=()=>{};return{promise:new Promise((n,r)=>{A=n,e=r}),resolve:A,reject:e}}const Fu=new Map;function kw({fn:A,id:e,shouldSplitBatch:t,wait:n=0,sort:r}){const s=async()=>{const l=g();i();const B=l.map(({args:Q})=>Q);B.length!==0&&A(B).then(Q=>{r&&Array.isArray(Q)&&Q.sort(r);for(let u=0;u<l.length;u++){const{resolve:d}=l[u];d?.([Q[u],Q])}}).catch(Q=>{for(let u=0;u<l.length;u++){const{reject:d}=l[u];d?.(Q)}})},i=()=>Fu.delete(e),a=()=>g().map(({args:l})=>l),g=()=>Fu.get(e)||[],c=l=>Fu.set(e,[...g(),l]);return{flush:i,async schedule(l){const{promise:B,resolve:Q,reject:u}=cd();return t?.([...a(),l])&&s(),g().length>0?(c({args:l,resolve:Q,reject:u}),B):(c({args:l,resolve:Q,reject:u}),setTimeout(s,n),B)}}}async function sg(A,e){const{account:t=A.account,authorizationList:n,batch:r=!!A.batch?.multicall,blockNumber:s,blockTag:i=A.experimental_blockTag??"latest",accessList:a,blobs:g,blockOverrides:c,code:l,data:B,factory:Q,factoryData:u,gas:d,gasPrice:f,maxFeePerBlobGas:h,maxFeePerGas:x,maxPriorityFeePerGas:b,nonce:m,to:M,value:G,stateOverride:Y,...Z}=e,P=t?Ct(t):void 0;if(l&&(Q||u))throw new fA("Cannot provide both `code` & `factory`/`factoryData` as parameters.");if(l&&M)throw new fA("Cannot provide both `code` & `to` as parameters.");const L=l&&B,q=Q&&u&&M&&B,v=L||q,U=L?Mw({code:l,data:B}):q?nR({data:B,factory:Q,factoryData:u,to:M}):B;try{jr(e);const E=(typeof s=="bigint"?NA(s):void 0)||i,C=c?mw(c):void 0,y=WE(Y),F=A.chain?.formatters?.transactionRequest?.format,J=(F||Is)({...Ni(Z,{format:F}),accessList:a,account:P,authorizationList:n,blobs:g,data:U,gas:d,gasPrice:f,maxFeePerBlobGas:h,maxFeePerGas:x,maxPriorityFeePerGas:b,nonce:m,to:v?void 0:M,value:G},"call");if(r&&eR({request:J})&&!y&&!C)try{return await tR(A,{...J,blockNumber:s,blockTag:i})}catch(I){if(!(I instanceof bw)&&!(I instanceof lQ))throw I}const z=(()=>{const I=[J,E];return y&&C?[...I,y,C]:y?[...I,y]:C?[...I,{},C]:I})(),R=await A.request({method:"eth_call",params:z});return R==="0x"?{data:void 0}:{data:R}}catch(w){const E=rR(w),{offchainLookup:C,offchainLookupSignature:y}=await JQ(async()=>{const{offchainLookup:F,offchainLookupSignature:T}=await import("./ccip-DZ76OyMt.js");return{offchainLookup:F,offchainLookupSignature:T}},__vite__mapDeps([0,1,2,3,4]));if(A.ccipRead!==!1&&E?.slice(0,10)===y&&M)return{data:await C(A,{data:E,to:M})};throw v&&E?.slice(0,10)==="0x101bb98d"?new W6({factory:Q}):Nw(w,{...e,account:P,chain:A.chain})}}function eR({request:A}){const{data:e,to:t,...n}=A;return!(!e||e.startsWith(VG)||!t||Object.values(n).filter(r=>typeof r<"u").length>0)}async function tR(A,e){const{batchSize:t=1024,deployless:n=!1,wait:r=0}=typeof A.batch?.multicall=="object"?A.batch.multicall:{},{blockNumber:s,blockTag:i=A.experimental_blockTag??"latest",data:a,to:g}=e,c=(()=>{if(n)return null;if(e.multicallAddress)return e.multicallAddress;if(A.chain)return Mi({blockNumber:s,chain:A.chain,contract:"multicall3"});throw new bw})(),B=(typeof s=="bigint"?NA(s):void 0)||i,{schedule:Q}=kw({id:`${A.uid}.${B}`,wait:r,shouldSplitBatch(f){return f.reduce((x,{data:b})=>x+(b.length-2),0)>t*2},fn:async f=>{const h=f.map(m=>({allowFailure:!0,callData:m.data,target:m.to})),x=mn({abi:Qi,args:[h],functionName:"aggregate3"}),b=await A.request({method:"eth_call",params:[{...c===null?{data:Mw({code:gd,data:x})}:{to:c,data:x}},B]});return Os({abi:Qi,args:[h],functionName:"aggregate3",data:b||"0x"})}}),[{returnData:u,success:d}]=await Q({data:a,to:g});if(!d)throw new fl({data:u});return u==="0x"?{data:void 0}:{data:u}}function Mw(A){const{code:e,data:t}=A;return yl({abi:Im(["constructor(bytes, bytes)"]),bytecode:Dw,args:[e,t]})}function nR(A){const{data:e,factory:t,factoryData:n,to:r}=A;return yl({abi:Im(["constructor(address, bytes, address, bytes)"]),bytecode:ZG,args:[r,e,t,n]})}function rR(A){if(!(A instanceof fA))return;const e=A.walk();return typeof e?.data=="object"?e.data?.data:e.data}async function mr(A,e){const{abi:t,address:n,args:r,functionName:s,...i}=e,a=mn({abi:t,args:r,functionName:s});try{const{data:g}=await qA(A,sg,"call")({...i,data:a,to:n});return Os({abi:t,args:r,functionName:s,data:g||"0x"})}catch(g){throw Io(g,{abi:t,address:n,args:r,docsPath:"/docs/contract/readContract",functionName:s})}}async function sR(A,e){const{abi:t,address:n,args:r,functionName:s,dataSuffix:i=typeof A.dataSuffix=="string"?A.dataSuffix:A.dataSuffix?.value,...a}=e,g=a.account?Ct(a.account):A.account,c=mn({abi:t,args:r,functionName:s});try{const{data:l}=await qA(A,sg,"call")({batch:!1,data:`${c}${i?i.replace("0x",""):""}`,to:n,...a,account:g}),B=Os({abi:t,args:r,functionName:s,data:l||"0x"}),Q=t.filter(u=>"name"in u&&u.name===e.functionName);return{result:B,request:{abi:Q,address:n,args:r,dataSuffix:i,functionName:s,...a,account:g}}}catch(l){throw Io(l,{abi:t,address:n,args:r,docsPath:"/docs/contract/simulateContract",functionName:s,sender:g?.address})}}const Gu=new Map,E0=new Map;let oR=0;function Es(A,e,t){const n=++oR,r=()=>Gu.get(A)||[],s=()=>{const l=r();Gu.set(A,l.filter(B=>B.id!==n))},i=()=>{const l=r();if(!l.some(Q=>Q.id===n))return;const B=E0.get(A);if(l.length===1&&B){const Q=B();Q instanceof Promise&&Q.catch(()=>{})}s()},a=r();if(Gu.set(A,[...a,{id:n,fns:e}]),a&&a.length>0)return i;const g={};for(const l in e)g[l]=((...B)=>{const Q=r();if(Q.length!==0)for(const u of Q)u.fns[l]?.(...B)});const c=t(g);return typeof c=="function"&&E0.set(A,c),i}async function uQ(A){return new Promise(e=>setTimeout(e,A))}function vi(A,{emitOnBegin:e,initialWaitTime:t,interval:n}){let r=!0;const s=()=>r=!1;return(async()=>{let a;e&&(a=await A({unpoll:s}));const g=await t?.(a)??n;await uQ(g);const c=async()=>{r&&(await A({unpoll:s}),await uQ(n),c())};c()})(),s}const iR=new Map,aR=new Map;function gR(A){const e=(r,s)=>({clear:()=>s.delete(r),get:()=>s.get(r),set:i=>s.set(r,i)}),t=e(A,iR),n=e(A,aR);return{clear:()=>{t.clear(),n.clear()},promise:t,response:n}}async function cR(A,{cacheKey:e,cacheTime:t=Number.POSITIVE_INFINITY}){const n=gR(e),r=n.response.get();if(r&&t>0&&Date.now()-r.created.getTime()<t)return r.data;let s=n.promise.get();s||(s=A(),n.promise.set(s));try{const i=await s;return n.response.set({created:new Date,data:i}),i}finally{n.promise.clear()}}const lR=A=>`blockNumber.${A}`;async function og(A,{cacheTime:e=A.cacheTime}={}){const t=await cR(()=>A.request({method:"eth_blockNumber"}),{cacheKey:lR(A.uid),cacheTime:e});return BigInt(t)}async function Dl(A,{filter:e}){const t="strict"in e&&e.strict,n=await e.request({method:"eth_getFilterChanges",params:[e.id]});if(typeof n[0]=="string")return n;const r=n.map(s=>fr(s));return!("abi"in e)||!e.abi?r:od({abi:e.abi,logs:r,strict:t})}async function bl(A,{filter:e}){return e.request({method:"eth_uninstallFilter",params:[e.id]})}function uR(A,e){const{abi:t,address:n,args:r,batch:s=!0,eventName:i,fromBlock:a,onError:g,onLogs:c,poll:l,pollingInterval:B=A.pollingInterval,strict:Q}=e;return(typeof l<"u"?l:typeof a=="bigint"?!0:!(A.transport.type==="webSocket"||A.transport.type==="ipc"||A.transport.type==="fallback"&&(A.transport.transports[0].config.type==="webSocket"||A.transport.transports[0].config.type==="ipc")))?(()=>{const h=Q??!1,x=_t(["watchContractEvent",n,r,s,A.uid,i,B,h,a]);return Es(x,{onLogs:c,onError:g},b=>{let m;a!==void 0&&(m=a-1n);let M,G=!1;const Y=vi(async()=>{if(!G){try{M=await qA(A,Rm,"createContractEventFilter")({abi:t,address:n,args:r,eventName:i,strict:h,fromBlock:a})}catch{}G=!0;return}try{let Z;if(M)Z=await qA(A,Dl,"getFilterChanges")({filter:M});else{const P=await qA(A,og,"getBlockNumber")({});m&&m<P?Z=await qA(A,cw,"getContractEvents")({abi:t,address:n,args:r,eventName:i,fromBlock:m+1n,toBlock:P,strict:h}):Z=[],m=P}if(Z.length===0)return;if(s)b.onLogs(Z);else for(const P of Z)b.onLogs([P])}catch(Z){M&&Z instanceof Fs&&(G=!1),b.onError?.(Z)}},{emitOnBegin:!0,interval:B});return async()=>{M&&await qA(A,bl,"uninstallFilter")({filter:M}),Y()}})})():(()=>{const h=Q??!1,x=_t(["watchContractEvent",n,r,s,A.uid,i,B,h]);let b=!0,m=()=>b=!1;return Es(x,{onLogs:c,onError:g},M=>((async()=>{try{const G=(()=>{if(A.transport.type==="fallback"){const P=A.transport.transports.find(L=>L.config.type==="webSocket"||L.config.type==="ipc");return P?P.value:A.transport}return A.transport})(),Y=i?Va({abi:t,eventName:i,args:r}):[],{unsubscribe:Z}=await G.subscribe({params:["logs",{address:n,topics:Y}],onData(P){if(!b)return;const L=P.result;try{const{eventName:q,args:v}=kc({abi:t,data:L.data,topics:L.topics,strict:Q}),U=fr(L,{args:v,eventName:q});M.onLogs([U])}catch(q){let v,U;if(q instanceof Nc||q instanceof KE){if(Q)return;v=q.abiItem.name,U=q.abiItem.inputs?.some(E=>!("name"in E&&E.name))}const w=fr(L,{args:U?[]:{},eventName:v});M.onLogs([w])}},onError(P){M.onError?.(P)}});m=Z,b||m()}catch(G){g?.(G)}})(),()=>m()))})()}class qr extends fA{constructor({docsPath:e}={}){super(["Could not find an Account to execute with this Action.","Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client."].join(`
149
+ `),{name:"ChainNotFoundError"})}}class bw extends fA{constructor(){super("No chain was provided to the Client.",{name:"ClientChainNotConfiguredError"})}}class rg extends fA{constructor({chainId:e}){super(typeof e=="number"?`Chain ID "${e}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}const Su="/docs/contract/encodeDeployData";function yl(A){const{abi:e,args:t,bytecode:n}=A;if(!t||t.length===0)return n;const r=e.find(i=>"type"in i&&i.type==="constructor");if(!r)throw new pm({docsPath:Su});if(!("inputs"in r))throw new bc({docsPath:Su});if(!r.inputs||r.inputs.length===0)throw new bc({docsPath:Su});const s=Ls(r.inputs,t);return ir([n,s])}function Mi({blockNumber:A,chain:e,contract:t}){const n=e?.contracts?.[t];if(!n)throw new lQ({chain:e,contract:{name:t}});if(A&&n.blockCreated&&n.blockCreated>A)throw new lQ({blockNumber:A,chain:e,contract:{name:t,blockCreated:n.blockCreated}});return n.address}function Nw(A,{docsPath:e,...t}){const n=(()=>{const r=pl(A,t);return r instanceof $a?A:r})();return new qm(n,{docsPath:e,...t})}function cd(){let A=()=>{},e=()=>{};return{promise:new Promise((n,r)=>{A=n,e=r}),resolve:A,reject:e}}const Fu=new Map;function kw({fn:A,id:e,shouldSplitBatch:t,wait:n=0,sort:r}){const s=async()=>{const l=g();i();const B=l.map(({args:Q})=>Q);B.length!==0&&A(B).then(Q=>{r&&Array.isArray(Q)&&Q.sort(r);for(let u=0;u<l.length;u++){const{resolve:d}=l[u];d?.([Q[u],Q])}}).catch(Q=>{for(let u=0;u<l.length;u++){const{reject:d}=l[u];d?.(Q)}})},i=()=>Fu.delete(e),a=()=>g().map(({args:l})=>l),g=()=>Fu.get(e)||[],c=l=>Fu.set(e,[...g(),l]);return{flush:i,async schedule(l){const{promise:B,resolve:Q,reject:u}=cd();return t?.([...a(),l])&&s(),g().length>0?(c({args:l,resolve:Q,reject:u}),B):(c({args:l,resolve:Q,reject:u}),setTimeout(s,n),B)}}}async function sg(A,e){const{account:t=A.account,authorizationList:n,batch:r=!!A.batch?.multicall,blockNumber:s,blockTag:i=A.experimental_blockTag??"latest",accessList:a,blobs:g,blockOverrides:c,code:l,data:B,factory:Q,factoryData:u,gas:d,gasPrice:f,maxFeePerBlobGas:h,maxFeePerGas:x,maxPriorityFeePerGas:b,nonce:m,to:M,value:G,stateOverride:Y,...Z}=e,P=t?Ct(t):void 0;if(l&&(Q||u))throw new fA("Cannot provide both `code` & `factory`/`factoryData` as parameters.");if(l&&M)throw new fA("Cannot provide both `code` & `to` as parameters.");const L=l&&B,q=Q&&u&&M&&B,v=L||q,U=L?Mw({code:l,data:B}):q?nR({data:B,factory:Q,factoryData:u,to:M}):B;try{jr(e);const E=(typeof s=="bigint"?NA(s):void 0)||i,C=c?mw(c):void 0,y=WE(Y),F=A.chain?.formatters?.transactionRequest?.format,J=(F||Is)({...Ni(Z,{format:F}),accessList:a,account:P,authorizationList:n,blobs:g,data:U,gas:d,gasPrice:f,maxFeePerBlobGas:h,maxFeePerGas:x,maxPriorityFeePerGas:b,nonce:m,to:v?void 0:M,value:G},"call");if(r&&eR({request:J})&&!y&&!C)try{return await tR(A,{...J,blockNumber:s,blockTag:i})}catch(I){if(!(I instanceof bw)&&!(I instanceof lQ))throw I}const z=(()=>{const I=[J,E];return y&&C?[...I,y,C]:y?[...I,y]:C?[...I,{},C]:I})(),R=await A.request({method:"eth_call",params:z});return R==="0x"?{data:void 0}:{data:R}}catch(w){const E=rR(w),{offchainLookup:C,offchainLookupSignature:y}=await JQ(async()=>{const{offchainLookup:F,offchainLookupSignature:T}=await import("./ccip-DT8hlmC4.js");return{offchainLookup:F,offchainLookupSignature:T}},__vite__mapDeps([0,1,2,3,4]));if(A.ccipRead!==!1&&E?.slice(0,10)===y&&M)return{data:await C(A,{data:E,to:M})};throw v&&E?.slice(0,10)==="0x101bb98d"?new W6({factory:Q}):Nw(w,{...e,account:P,chain:A.chain})}}function eR({request:A}){const{data:e,to:t,...n}=A;return!(!e||e.startsWith(VG)||!t||Object.values(n).filter(r=>typeof r<"u").length>0)}async function tR(A,e){const{batchSize:t=1024,deployless:n=!1,wait:r=0}=typeof A.batch?.multicall=="object"?A.batch.multicall:{},{blockNumber:s,blockTag:i=A.experimental_blockTag??"latest",data:a,to:g}=e,c=(()=>{if(n)return null;if(e.multicallAddress)return e.multicallAddress;if(A.chain)return Mi({blockNumber:s,chain:A.chain,contract:"multicall3"});throw new bw})(),B=(typeof s=="bigint"?NA(s):void 0)||i,{schedule:Q}=kw({id:`${A.uid}.${B}`,wait:r,shouldSplitBatch(f){return f.reduce((x,{data:b})=>x+(b.length-2),0)>t*2},fn:async f=>{const h=f.map(m=>({allowFailure:!0,callData:m.data,target:m.to})),x=mn({abi:Qi,args:[h],functionName:"aggregate3"}),b=await A.request({method:"eth_call",params:[{...c===null?{data:Mw({code:gd,data:x})}:{to:c,data:x}},B]});return Os({abi:Qi,args:[h],functionName:"aggregate3",data:b||"0x"})}}),[{returnData:u,success:d}]=await Q({data:a,to:g});if(!d)throw new fl({data:u});return u==="0x"?{data:void 0}:{data:u}}function Mw(A){const{code:e,data:t}=A;return yl({abi:Im(["constructor(bytes, bytes)"]),bytecode:Dw,args:[e,t]})}function nR(A){const{data:e,factory:t,factoryData:n,to:r}=A;return yl({abi:Im(["constructor(address, bytes, address, bytes)"]),bytecode:ZG,args:[r,e,t,n]})}function rR(A){if(!(A instanceof fA))return;const e=A.walk();return typeof e?.data=="object"?e.data?.data:e.data}async function mr(A,e){const{abi:t,address:n,args:r,functionName:s,...i}=e,a=mn({abi:t,args:r,functionName:s});try{const{data:g}=await qA(A,sg,"call")({...i,data:a,to:n});return Os({abi:t,args:r,functionName:s,data:g||"0x"})}catch(g){throw Io(g,{abi:t,address:n,args:r,docsPath:"/docs/contract/readContract",functionName:s})}}async function sR(A,e){const{abi:t,address:n,args:r,functionName:s,dataSuffix:i=typeof A.dataSuffix=="string"?A.dataSuffix:A.dataSuffix?.value,...a}=e,g=a.account?Ct(a.account):A.account,c=mn({abi:t,args:r,functionName:s});try{const{data:l}=await qA(A,sg,"call")({batch:!1,data:`${c}${i?i.replace("0x",""):""}`,to:n,...a,account:g}),B=Os({abi:t,args:r,functionName:s,data:l||"0x"}),Q=t.filter(u=>"name"in u&&u.name===e.functionName);return{result:B,request:{abi:Q,address:n,args:r,dataSuffix:i,functionName:s,...a,account:g}}}catch(l){throw Io(l,{abi:t,address:n,args:r,docsPath:"/docs/contract/simulateContract",functionName:s,sender:g?.address})}}const Gu=new Map,E0=new Map;let oR=0;function Es(A,e,t){const n=++oR,r=()=>Gu.get(A)||[],s=()=>{const l=r();Gu.set(A,l.filter(B=>B.id!==n))},i=()=>{const l=r();if(!l.some(Q=>Q.id===n))return;const B=E0.get(A);if(l.length===1&&B){const Q=B();Q instanceof Promise&&Q.catch(()=>{})}s()},a=r();if(Gu.set(A,[...a,{id:n,fns:e}]),a&&a.length>0)return i;const g={};for(const l in e)g[l]=((...B)=>{const Q=r();if(Q.length!==0)for(const u of Q)u.fns[l]?.(...B)});const c=t(g);return typeof c=="function"&&E0.set(A,c),i}async function uQ(A){return new Promise(e=>setTimeout(e,A))}function vi(A,{emitOnBegin:e,initialWaitTime:t,interval:n}){let r=!0;const s=()=>r=!1;return(async()=>{let a;e&&(a=await A({unpoll:s}));const g=await t?.(a)??n;await uQ(g);const c=async()=>{r&&(await A({unpoll:s}),await uQ(n),c())};c()})(),s}const iR=new Map,aR=new Map;function gR(A){const e=(r,s)=>({clear:()=>s.delete(r),get:()=>s.get(r),set:i=>s.set(r,i)}),t=e(A,iR),n=e(A,aR);return{clear:()=>{t.clear(),n.clear()},promise:t,response:n}}async function cR(A,{cacheKey:e,cacheTime:t=Number.POSITIVE_INFINITY}){const n=gR(e),r=n.response.get();if(r&&t>0&&Date.now()-r.created.getTime()<t)return r.data;let s=n.promise.get();s||(s=A(),n.promise.set(s));try{const i=await s;return n.response.set({created:new Date,data:i}),i}finally{n.promise.clear()}}const lR=A=>`blockNumber.${A}`;async function og(A,{cacheTime:e=A.cacheTime}={}){const t=await cR(()=>A.request({method:"eth_blockNumber"}),{cacheKey:lR(A.uid),cacheTime:e});return BigInt(t)}async function Dl(A,{filter:e}){const t="strict"in e&&e.strict,n=await e.request({method:"eth_getFilterChanges",params:[e.id]});if(typeof n[0]=="string")return n;const r=n.map(s=>fr(s));return!("abi"in e)||!e.abi?r:od({abi:e.abi,logs:r,strict:t})}async function bl(A,{filter:e}){return e.request({method:"eth_uninstallFilter",params:[e.id]})}function uR(A,e){const{abi:t,address:n,args:r,batch:s=!0,eventName:i,fromBlock:a,onError:g,onLogs:c,poll:l,pollingInterval:B=A.pollingInterval,strict:Q}=e;return(typeof l<"u"?l:typeof a=="bigint"?!0:!(A.transport.type==="webSocket"||A.transport.type==="ipc"||A.transport.type==="fallback"&&(A.transport.transports[0].config.type==="webSocket"||A.transport.transports[0].config.type==="ipc")))?(()=>{const h=Q??!1,x=_t(["watchContractEvent",n,r,s,A.uid,i,B,h,a]);return Es(x,{onLogs:c,onError:g},b=>{let m;a!==void 0&&(m=a-1n);let M,G=!1;const Y=vi(async()=>{if(!G){try{M=await qA(A,Rm,"createContractEventFilter")({abi:t,address:n,args:r,eventName:i,strict:h,fromBlock:a})}catch{}G=!0;return}try{let Z;if(M)Z=await qA(A,Dl,"getFilterChanges")({filter:M});else{const P=await qA(A,og,"getBlockNumber")({});m&&m<P?Z=await qA(A,cw,"getContractEvents")({abi:t,address:n,args:r,eventName:i,fromBlock:m+1n,toBlock:P,strict:h}):Z=[],m=P}if(Z.length===0)return;if(s)b.onLogs(Z);else for(const P of Z)b.onLogs([P])}catch(Z){M&&Z instanceof Fs&&(G=!1),b.onError?.(Z)}},{emitOnBegin:!0,interval:B});return async()=>{M&&await qA(A,bl,"uninstallFilter")({filter:M}),Y()}})})():(()=>{const h=Q??!1,x=_t(["watchContractEvent",n,r,s,A.uid,i,B,h]);let b=!0,m=()=>b=!1;return Es(x,{onLogs:c,onError:g},M=>((async()=>{try{const G=(()=>{if(A.transport.type==="fallback"){const P=A.transport.transports.find(L=>L.config.type==="webSocket"||L.config.type==="ipc");return P?P.value:A.transport}return A.transport})(),Y=i?Va({abi:t,eventName:i,args:r}):[],{unsubscribe:Z}=await G.subscribe({params:["logs",{address:n,topics:Y}],onData(P){if(!b)return;const L=P.result;try{const{eventName:q,args:v}=kc({abi:t,data:L.data,topics:L.topics,strict:Q}),U=fr(L,{args:v,eventName:q});M.onLogs([U])}catch(q){let v,U;if(q instanceof Nc||q instanceof KE){if(Q)return;v=q.abiItem.name,U=q.abiItem.inputs?.some(E=>!("name"in E&&E.name))}const w=fr(L,{args:U?[]:{},eventName:v});M.onLogs([w])}},onError(P){M.onError?.(P)}});m=Z,b||m()}catch(G){g?.(G)}})(),()=>m()))})()}class qr extends fA{constructor({docsPath:e}={}){super(["Could not find an Account to execute with this Action.","Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client."].join(`
150
150
  `),{docsPath:e,docsSlug:"account",name:"AccountNotFoundError"})}}class no extends fA{constructor({docsPath:e,metaMessages:t,type:n}){super(`Account type "${n}" is not supported.`,{docsPath:e,metaMessages:t,name:"AccountTypeNotSupportedError"})}}function ig({chain:A,currentChainId:e}){if(!A)throw new AR;if(e!==A.id)throw new $G({chain:A,currentChainId:e})}async function Nl(A,{serializedTransaction:e}){return A.request({method:"eth_sendRawTransaction",params:[e]},{retryCount:0})}const Ru=new bi(128);async function ag(A,e){const{account:t=A.account,assertChainId:n=!0,chain:r=A.chain,accessList:s,authorizationList:i,blobs:a,data:g,dataSuffix:c=typeof A.dataSuffix=="string"?A.dataSuffix:A.dataSuffix?.value,gas:l,gasPrice:B,maxFeePerBlobGas:Q,maxFeePerGas:u,maxPriorityFeePerGas:d,nonce:f,type:h,value:x,...b}=e;if(typeof t>"u")throw new qr({docsPath:"/docs/actions/wallet/sendTransaction"});const m=t?Ct(t):null;try{jr(e);const M=await(async()=>{if(e.to)return e.to;if(e.to!==null&&i&&i.length>0)return await hl({authorization:i[0]}).catch(()=>{throw new fA("`to` is required. Could not infer from `authorizationList`.")})})();if(m?.type==="json-rpc"||m===null){let G;r!==null&&(G=await qA(A,Jr,"getChainId")({}),n&&ig({currentChainId:G,chain:r}));const Y=A.chain?.formatters?.transactionRequest?.format,P=(Y||Is)({...Ni(b,{format:Y}),accessList:s,account:m,authorizationList:i,blobs:a,chainId:G,data:g&&pn([g,c??"0x"]),gas:l,gasPrice:B,maxFeePerBlobGas:Q,maxFeePerGas:u,maxPriorityFeePerGas:d,nonce:f,to:M,type:h,value:x},"sendTransaction"),L=Ru.get(A.uid),q=L?"wallet_sendTransaction":"eth_sendTransaction";try{return await A.request({method:q,params:[P]},{retryCount:0})}catch(v){if(L===!1)throw v;const U=v;if(U.name==="InvalidInputRpcError"||U.name==="InvalidParamsRpcError"||U.name==="MethodNotFoundRpcError"||U.name==="MethodNotSupportedRpcError")return await A.request({method:"wallet_sendTransaction",params:[P]},{retryCount:0}).then(w=>(Ru.set(A.uid,!0),w)).catch(w=>{const E=w;throw E.name==="MethodNotFoundRpcError"||E.name==="MethodNotSupportedRpcError"?(Ru.set(A.uid,!1),U):E});throw U}}if(m?.type==="local"){const G=await qA(A,ki,"prepareTransactionRequest")({account:m,accessList:s,authorizationList:i,blobs:a,chain:r,data:g&&pn([g,c??"0x"]),gas:l,gasPrice:B,maxFeePerBlobGas:Q,maxFeePerGas:u,maxPriorityFeePerGas:d,nonce:f,nonceManager:m.nonceManager,parameters:[...rd,"sidecars"],type:h,value:x,...b,to:M}),Y=r?.serializers?.transaction,Z=await m.signTransaction(G,{serializer:Y});return await qA(A,Nl,"sendRawTransaction")({serializedTransaction:Z})}throw m?.type==="smart"?new no({metaMessages:["Consider using the `sendUserOperation` Action instead."],docsPath:"/docs/actions/bundler/sendUserOperation",type:"smart"}):new no({docsPath:"/docs/actions/wallet/sendTransaction",type:m?.type})}catch(M){throw M instanceof no?M:eg(M,{...e,account:m,chain:e.chain||void 0})}}async function Ei(A,e){return Ei.internal(A,ag,"sendTransaction",e)}(function(A){async function e(t,n,r,s){const{abi:i,account:a=t.account,address:g,args:c,functionName:l,...B}=s;if(typeof a>"u")throw new qr({docsPath:"/docs/contract/writeContract"});const Q=a?Ct(a):null,u=mn({abi:i,args:c,functionName:l});try{return await qA(t,n,r)({data:u,to:g,account:Q,...B})}catch(d){throw Io(d,{abi:i,address:g,args:c,docsPath:"/docs/contract/writeContract",functionName:l,sender:Q?.address})}}A.internal=e})(Ei||(Ei={}));class BR extends fA{constructor(e){super(`Call bundle failed with status: ${e.statusCode}`,{name:"BundleFailedError"}),Object.defineProperty(this,"result",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.result=e}}function Mc(A,{delay:e=100,retryCount:t=2,shouldRetry:n=()=>!0}={}){return new Promise((r,s)=>{const i=async({count:a=0}={})=>{const g=async({error:c})=>{const l=typeof e=="function"?e({count:a,error:c}):e;l&&await uQ(l),i({count:a+1})};try{const c=await A();r(c)}catch(c){if(a<t&&await n({count:a,error:c}))return g({error:c});s(c)}};i()})}const vw={"0x0":"reverted","0x1":"success"};function ld(A,e){const t={...A,blockNumber:A.blockNumber?BigInt(A.blockNumber):null,contractAddress:A.contractAddress?A.contractAddress:null,cumulativeGasUsed:A.cumulativeGasUsed?BigInt(A.cumulativeGasUsed):null,effectiveGasPrice:A.effectiveGasPrice?BigInt(A.effectiveGasPrice):null,gasUsed:A.gasUsed?BigInt(A.gasUsed):null,logs:A.logs?A.logs.map(n=>fr(n)):null,to:A.to?A.to:null,transactionIndex:A.transactionIndex?zn(A.transactionIndex):null,status:A.status?vw[A.status]:null,type:A.type?Xm[A.type]||A.type:null};return A.blobGasPrice&&(t.blobGasPrice=BigInt(A.blobGasPrice)),A.blobGasUsed&&(t.blobGasUsed=BigInt(A.blobGasUsed)),t}const Sw=ml("transactionReceipt",ld),Fw="0x5792579257925792579257925792579257925792579257925792579257925792",Gw=NA(0,{size:32});async function Rw(A,e){const{account:t=A.account,chain:n=A.chain,experimental_fallback:r,experimental_fallbackDelay:s=32,forceAtomic:i=!1,id:a,version:g="2.0.0"}=e,c=t?Ct(t):null;let l=e.capabilities;A.dataSuffix&&!e.capabilities?.dataSuffix&&(typeof A.dataSuffix=="string"?l={...e.capabilities,dataSuffix:{value:A.dataSuffix,optional:!0}}:l={...e.capabilities,dataSuffix:{value:A.dataSuffix.value,...A.dataSuffix.required?{}:{optional:!0}}});const B=e.calls.map(Q=>{const u=Q,d=u.abi?mn({abi:u.abi,functionName:u.functionName,args:u.args}):u.data;return{data:u.dataSuffix&&d?pn([d,u.dataSuffix]):d,to:u.to,value:u.value?NA(u.value):void 0}});try{const Q=await A.request({method:"wallet_sendCalls",params:[{atomicRequired:i,calls:B,capabilities:l,chainId:NA(n.id),from:c?.address,id:a,version:g}]},{retryCount:0});return typeof Q=="string"?{id:Q}:Q}catch(Q){const u=Q;if(r&&(u.name==="MethodNotFoundRpcError"||u.name==="MethodNotSupportedRpcError"||u.name==="UnknownRpcError"||u.details.toLowerCase().includes("does not exist / is not available")||u.details.toLowerCase().includes("missing or invalid. request()")||u.details.toLowerCase().includes("did not match any variant of untagged enum")||u.details.toLowerCase().includes("account upgraded to unsupported contract")||u.details.toLowerCase().includes("eip-7702 not supported")||u.details.toLowerCase().includes("unsupported wc_ method")||u.details.toLowerCase().includes("feature toggled misconfigured")||u.details.toLowerCase().includes("jsonrpcengine: response has no error or result for request"))){if(l&&Object.values(l).some(b=>!b.optional)){const b="non-optional `capabilities` are not supported on fallback to `eth_sendTransaction`.";throw new ui(new fA(b,{details:b}))}if(i&&B.length>1){const x="`forceAtomic` is not supported on fallback to `eth_sendTransaction`.";throw new Bi(new fA(x,{details:x}))}const d=[];for(const x of B){const b=ag(A,{account:c,chain:n,data:x.data,to:x.to,value:x.value?ot(x.value):void 0});d.push(b),s>0&&await new Promise(m=>setTimeout(m,s))}const f=await Promise.allSettled(d);if(f.every(x=>x.status==="rejected"))throw f[0].reason;const h=f.map(x=>x.status==="fulfilled"?x.value:Gw);return{id:pn([...h,NA(n.id,{size:32}),Fw])}}throw eg(Q,{...e,account:c,chain:e.chain})}}async function Uw(A,e){async function t(l){if(l.endsWith(Fw.slice(2))){const Q=tr(ZB(l,-64,-32)),u=ZB(l,0,-64).slice(2).match(/.{1,64}/g),d=await Promise.all(u.map(h=>Gw.slice(2)!==h?A.request({method:"eth_getTransactionReceipt",params:[`0x${h}`]},{dedupe:!0}):void 0)),f=d.some(h=>h===null)?100:d.every(h=>h?.status==="0x1")?200:d.every(h=>h?.status==="0x0")?500:600;return{atomic:!1,chainId:zn(Q),receipts:d.filter(Boolean),status:f,version:"2.0.0"}}return A.request({method:"wallet_getCallsStatus",params:[l]})}const{atomic:n=!1,chainId:r,receipts:s,version:i="2.0.0",...a}=await t(e.id),[g,c]=(()=>{const l=a.status;return l>=100&&l<200?["pending",l]:l>=200&&l<300?["success",l]:l>=300&&l<700?["failure",l]:l==="CONFIRMED"?["success",200]:l==="PENDING"?["pending",100]:[void 0,l]})();return{...a,atomic:n,chainId:r?zn(r):void 0,receipts:s?.map(l=>({...l,blockNumber:ot(l.blockNumber),gasUsed:ot(l.gasUsed),status:vw[l.status]}))??[],statusCode:c,status:g,version:i}}async function Tw(A,e){const{id:t,pollingInterval:n=A.pollingInterval,status:r=({statusCode:f})=>f===200||f>=300,retryCount:s=4,retryDelay:i=({count:f})=>~~(1<<f)*200,timeout:a=6e4,throwOnFailure:g=!1}=e,c=_t(["waitForCallsStatus",A.uid,t]),{promise:l,resolve:B,reject:Q}=cd();let u;const d=Es(c,{resolve:B,reject:Q},f=>{const h=vi(async()=>{const x=b=>{clearTimeout(u),h(),b(),d()};try{const b=await Mc(async()=>{const m=await qA(A,Uw,"getCallsStatus")({id:t});if(g&&m.status==="failure")throw new BR(m);return m},{retryCount:s,delay:i});if(!r(b))return;x(()=>f.resolve(b))}catch(b){x(()=>f.reject(b))}},{interval:n,emitOnBegin:!0});return h});return u=a?setTimeout(()=>{d(),clearTimeout(u),Q(new QR({id:t}))},a):void 0,await l}class QR extends fA{constructor({id:e}){super(`Timed out while waiting for call bundle with id "${e}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}const BQ=256;let Gg=BQ,Rg;function Lw(A=11){if(!Rg||Gg+A>BQ*2){Rg="",Gg=0;for(let e=0;e<BQ;e++)Rg+=(256+Math.random()*256|0).toString(16).substring(1)}return Rg.substring(Gg,Gg+++A)}function Ow(A){const{batch:e,chain:t,ccipRead:n,dataSuffix:r,key:s="base",name:i="Base Client",type:a="base"}=A,g=A.experimental_blockTag??(typeof t?.experimental_preconfirmationTime=="number"?"pending":void 0),c=t?.blockTime??12e3,l=Math.min(Math.max(Math.floor(c/2),500),4e3),B=A.pollingInterval??l,Q=A.cacheTime??B,u=A.account?Ct(A.account):void 0,{config:d,request:f,value:h}=A.transport({account:u,chain:t,pollingInterval:B}),x={...d,...h},b={account:u,batch:e,cacheTime:Q,ccipRead:n,chain:t,dataSuffix:r,key:s,name:i,pollingInterval:B,request:f,transport:x,type:a,uid:Lw(),...g?{experimental_blockTag:g}:{}};function m(M){return G=>{const Y=G(M);for(const P in b)delete Y[P];const Z={...M,...Y};return Object.assign(Z,{extend:m(Z)})}}return Object.assign(b,{extend:m(b)})}function ud(A){if(!(A instanceof fA))return!1;const e=A.walk(t=>t instanceof AQ);return e instanceof AQ?e.data?.errorName==="HttpError"||e.data?.errorName==="ResolverError"||e.data?.errorName==="ResolverNotContract"||e.data?.errorName==="ResolverNotFound"||e.data?.errorName==="ReverseAddressMismatch"||e.data?.errorName==="UnsupportedResolverProfile":!1}function ER(A){const{abi:e,data:t}=A,n=Ss(t,0,4),r=e.find(s=>s.type==="function"&&n===Wa(Cr(s)));if(!r)throw new qF(n,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:r.name,args:"inputs"in r&&r.inputs&&r.inputs.length>0?Za(r.inputs,Ss(t,4)):void 0}}const Uu="/docs/contract/encodeErrorResult";function d0(A){const{abi:e,errorName:t,args:n}=A;let r=e[0];if(t){const g=Fo({abi:e,args:n,name:t});if(!g)throw new PI(t,{docsPath:Uu});r=g}if(r.type!=="error")throw new PI(void 0,{docsPath:Uu});const s=Cr(r),i=Wa(s);let a="0x";if(n&&n.length>0){if(!r.inputs)throw new KF(r.name,{docsPath:Uu});a=Ls(r.inputs,n)}return ir([i,a])}const Tu="/docs/contract/encodeFunctionResult";function dR(A){const{abi:e,functionName:t,result:n}=A;let r=e[0];if(t){const i=Fo({abi:e,name:t});if(!i)throw new gi(t,{docsPath:Tu});r=i}if(r.type!=="function")throw new gi(void 0,{docsPath:Tu});if(!r.outputs)throw new xm(r.name,{docsPath:Tu});const s=(()=>{if(r.outputs.length===0)return[];if(r.outputs.length===1)return[n];if(Array.isArray(n))return n;throw new ym(n)})();return Ls(r.outputs,s)}const kl="x-batch-gateway:true";async function CR(A){const{data:e,ccipRequest:t}=A,{args:[n]}=ER({abi:cQ,data:e}),r=[],s=[];return await Promise.all(n.map(async(i,a)=>{try{s[a]=i.urls.includes(kl)?await CR({data:i.data,ccipRequest:t}):await t(i),r[a]=!1}catch(g){r[a]=!0,s[a]=IR(g)}})),dR({abi:cQ,functionName:"query",result:[r,s]})}function IR(A){return A.name==="HttpRequestError"&&A.status?d0({abi:cQ,errorName:"HttpError",args:[A.status,A.shortMessage]}):d0({abi:[Um],errorName:"Error",args:["shortMessage"in A?A.shortMessage:A.message]})}function Kw(A){if(A.length!==66||A.indexOf("[")!==0||A.indexOf("]")!==65)return null;const e=`0x${A.slice(1,65)}`;return Ir(e)?e:null}function QQ(A){let e=new Uint8Array(32).fill(0);if(!A)return qt(e);const t=A.split(".");for(let n=t.length-1;n>=0;n-=1){const r=Kw(t[n]),s=r?os(r):Vt(to(t[n]),"bytes");e=Vt(pn([e,s]),"bytes")}return qt(e)}function fR(A){return`[${A.slice(2)}]`}function hR(A){const e=new Uint8Array(32).fill(0);return A?Kw(A)||Vt(to(A)):qt(e)}function Bd(A){const e=A.replace(/^\.|\.$/gm,"");if(e.length===0)return new Uint8Array(1);const t=new Uint8Array(to(e).byteLength+2);let n=0;const r=e.split(".");for(let s=0;s<r.length;s++){let i=to(r[s]);i.byteLength>255&&(i=to(fR(hR(r[s])))),t[n]=i.length,t.set(i,n+1),n+=i.length+1}return t.byteLength!==n+1?t.slice(0,n+1):t}async function pR(A,e){const{blockNumber:t,blockTag:n,coinType:r,name:s,gatewayUrls:i,strict:a}=e,{chain:g}=A,c=(()=>{if(e.universalResolverAddress)return e.universalResolverAddress;if(!g)throw new Error("client chain not configured. universalResolverAddress is required.");return Mi({blockNumber:t,chain:g,contract:"ensUniversalResolver"})})(),l=g?.ensTlds;if(l&&!l.some(Q=>s.endsWith(Q)))return null;const B=r!=null?[QQ(s),BigInt(r)]:[QQ(s)];try{const Q=mn({abi:B0,functionName:"addr",args:B}),u={address:c,abi:xw,functionName:"resolveWithGateways",args:[tt(Bd(s)),Q,i??[kl]],blockNumber:t,blockTag:n},f=await qA(A,mr,"readContract")(u);if(f[0]==="0x")return null;const h=Os({abi:B0,args:B,functionName:"addr",data:f[0]});return h==="0x"||tr(h)==="0x00"?null:h}catch(Q){if(a)throw Q;if(ud(Q))return null;throw Q}}class mR extends fA{constructor({data:e}){super("Unable to extract image from metadata. The metadata may be malformed or invalid.",{metaMessages:["- Metadata must be a JSON object with at least an `image`, `image_url` or `image_data` property.","",`Provided data: ${JSON.stringify(e)}`],name:"EnsAvatarInvalidMetadataError"})}}class Ti extends fA{constructor({reason:e}){super(`ENS NFT avatar URI is invalid. ${e}`,{name:"EnsAvatarInvalidNftUriError"})}}class Qd extends fA{constructor({uri:e}){super(`Unable to resolve ENS avatar URI "${e}". The URI may be malformed, invalid, or does not respond with a valid image.`,{name:"EnsAvatarUriResolutionError"})}}class wR extends fA{constructor({namespace:e}){super(`ENS NFT avatar namespace "${e}" is not supported. Must be "erc721" or "erc1155".`,{name:"EnsAvatarUnsupportedNamespaceError"})}}const xR=/(?<protocol>https?:\/\/[^/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/,yR=/^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/,DR=/^data:([a-zA-Z\-/+]*);base64,([^"].*)/,bR=/^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;async function NR(A){try{const e=await fetch(A,{method:"HEAD"});return e.status===200?e.headers.get("content-type")?.startsWith("image/"):!1}catch(e){return typeof e=="object"&&typeof e.response<"u"||!Object.hasOwn(globalThis,"Image")?!1:new Promise(t=>{const n=new Image;n.onload=()=>{t(!0)},n.onerror=()=>{t(!1)},n.src=A})}}function C0(A,e){return A?A.endsWith("/")?A.slice(0,-1):A:e}function jw({uri:A,gatewayUrls:e}){const t=DR.test(A);if(t)return{uri:A,isOnChain:!0,isEncoded:t};const n=C0(e?.ipfs,"https://ipfs.io"),r=C0(e?.arweave,"https://arweave.net"),s=A.match(xR),{protocol:i,subpath:a,target:g,subtarget:c=""}=s?.groups||{},l=i==="ipns:/"||a==="ipns/",B=i==="ipfs:/"||a==="ipfs/"||yR.test(A);if(A.startsWith("http")&&!l&&!B){let u=A;return e?.arweave&&(u=A.replace(/https:\/\/arweave.net/g,e?.arweave)),{uri:u,isOnChain:!1,isEncoded:!1}}if((l||B)&&g)return{uri:`${n}/${l?"ipns":"ipfs"}/${g}${c}`,isOnChain:!1,isEncoded:!1};if(i==="ar:/"&&g)return{uri:`${r}/${g}${c||""}`,isOnChain:!1,isEncoded:!1};let Q=A.replace(bR,"");if(Q.startsWith("<svg")&&(Q=`data:image/svg+xml;base64,${btoa(Q)}`),Q.startsWith("data:")||Q.startsWith("{"))return{uri:Q,isOnChain:!0,isEncoded:!1};throw new Qd({uri:A})}function Jw(A){if(typeof A!="object"||!("image"in A)&&!("image_url"in A)&&!("image_data"in A))throw new mR({data:A});return A.image||A.image_url||A.image_data}async function kR({gatewayUrls:A,uri:e}){try{const t=await fetch(e).then(r=>r.json());return await Ed({gatewayUrls:A,uri:Jw(t)})}catch{throw new Qd({uri:e})}}async function Ed({gatewayUrls:A,uri:e}){const{uri:t,isOnChain:n}=jw({uri:e,gatewayUrls:A});if(n||await NR(t))return t;throw new Qd({uri:e})}function MR(A){let e=A;e.startsWith("did:nft:")&&(e=e.replace("did:nft:","").replace(/_/g,"/"));const[t,n,r]=e.split("/"),[s,i]=t.split(":"),[a,g]=n.split(":");if(!s||s.toLowerCase()!=="eip155")throw new Ti({reason:"Only EIP-155 supported"});if(!i)throw new Ti({reason:"Chain ID not found"});if(!g)throw new Ti({reason:"Contract address not found"});if(!r)throw new Ti({reason:"Token ID not found"});if(!a)throw new Ti({reason:"ERC namespace not found"});return{chainID:Number.parseInt(i,10),namespace:a.toLowerCase(),contractAddress:g,tokenID:r}}async function vR(A,{nft:e}){if(e.namespace==="erc721")return mr(A,{address:e.contractAddress,abi:[{name:"tokenURI",type:"function",stateMutability:"view",inputs:[{name:"tokenId",type:"uint256"}],outputs:[{name:"",type:"string"}]}],functionName:"tokenURI",args:[BigInt(e.tokenID)]});if(e.namespace==="erc1155")return mr(A,{address:e.contractAddress,abi:[{name:"uri",type:"function",stateMutability:"view",inputs:[{name:"_id",type:"uint256"}],outputs:[{name:"",type:"string"}]}],functionName:"uri",args:[BigInt(e.tokenID)]});throw new wR({namespace:e.namespace})}async function SR(A,{gatewayUrls:e,record:t}){return/eip155:/i.test(t)?FR(A,{gatewayUrls:e,record:t}):Ed({uri:t,gatewayUrls:e})}async function FR(A,{gatewayUrls:e,record:t}){const n=MR(t),r=await vR(A,{nft:n}),{uri:s,isOnChain:i,isEncoded:a}=jw({uri:r,gatewayUrls:e});if(i&&(s.includes("data:application/json;base64,")||s.startsWith("{"))){const c=a?atob(s.replace("data:application/json;base64,","")):s,l=JSON.parse(c);return Ed({uri:Jw(l),gatewayUrls:e})}let g=n.tokenID;return n.namespace==="erc1155"&&(g=g.replace("0x","").padStart(64,"0")),kR({gatewayUrls:e,uri:s.replace(/(?:0x)?{id}/,g)})}async function qw(A,e){const{blockNumber:t,blockTag:n,key:r,name:s,gatewayUrls:i,strict:a}=e,{chain:g}=A,c=(()=>{if(e.universalResolverAddress)return e.universalResolverAddress;if(!g)throw new Error("client chain not configured. universalResolverAddress is required.");return Mi({blockNumber:t,chain:g,contract:"ensUniversalResolver"})})(),l=g?.ensTlds;if(l&&!l.some(B=>s.endsWith(B)))return null;try{const B={address:c,abi:xw,args:[tt(Bd(s)),mn({abi:u0,functionName:"text",args:[QQ(s),r]}),i??[kl]],functionName:"resolveWithGateways",blockNumber:t,blockTag:n},u=await qA(A,mr,"readContract")(B);if(u[0]==="0x")return null;const d=Os({abi:u0,functionName:"text",data:u[0]});return d===""?null:d}catch(B){if(a)throw B;if(ud(B))return null;throw B}}async function GR(A,{blockNumber:e,blockTag:t,assetGatewayUrls:n,name:r,gatewayUrls:s,strict:i,universalResolverAddress:a}){const g=await qA(A,qw,"getEnsText")({blockNumber:e,blockTag:t,key:"avatar",name:r,universalResolverAddress:a,gatewayUrls:s,strict:i});if(!g)return null;try{return await SR(A,{record:g,gatewayUrls:n})}catch{return null}}async function RR(A,e){const{address:t,blockNumber:n,blockTag:r,coinType:s=60n,gatewayUrls:i,strict:a}=e,{chain:g}=A,c=(()=>{if(e.universalResolverAddress)return e.universalResolverAddress;if(!g)throw new Error("client chain not configured. universalResolverAddress is required.");return Mi({blockNumber:n,chain:g,contract:"ensUniversalResolver"})})();try{const l={address:c,abi:WG,args:[t,s,i??[kl]],functionName:"reverseWithGateways",blockNumber:n,blockTag:r},B=qA(A,mr,"readContract"),[Q]=await B(l);return Q||null}catch(l){if(a)throw l;if(ud(l))return null;throw l}}async function UR(A,e){const{blockNumber:t,blockTag:n,name:r}=e,{chain:s}=A,i=(()=>{if(e.universalResolverAddress)return e.universalResolverAddress;if(!s)throw new Error("client chain not configured. universalResolverAddress is required.");return Mi({blockNumber:t,chain:s,contract:"ensUniversalResolver"})})(),a=s?.ensTlds;if(a&&!a.some(c=>r.endsWith(c)))throw new Error(`${r} is not a valid ENS TLD (${a?.join(", ")}) for chain "${s.name}" (id: ${s.id}).`);const[g]=await qA(A,mr,"readContract")({address:i,abi:[{inputs:[{type:"bytes"}],name:"findResolver",outputs:[{type:"address"},{type:"bytes32"},{type:"uint256"}],stateMutability:"view",type:"function"}],functionName:"findResolver",args:[tt(Bd(r))],blockNumber:t,blockTag:n});return g}async function Yw(A,e){const{account:t=A.account,blockNumber:n,blockTag:r="latest",blobs:s,data:i,gas:a,gasPrice:g,maxFeePerBlobGas:c,maxFeePerGas:l,maxPriorityFeePerGas:B,to:Q,value:u,...d}=e,f=t?Ct(t):void 0;try{jr(e);const x=(typeof n=="bigint"?NA(n):void 0)||r,b=A.chain?.formatters?.transactionRequest?.format,M=(b||Is)({...Ni(d,{format:b}),account:f,blobs:s,data:i,gas:a,gasPrice:g,maxFeePerBlobGas:c,maxFeePerGas:l,maxPriorityFeePerGas:B,to:Q,value:u},"createAccessList"),G=await A.request({method:"eth_createAccessList",params:[M,x]});return{accessList:G.accessList,gasUsed:BigInt(G.gasUsed)}}catch(h){throw Nw(h,{...e,account:f,chain:A.chain})}}async function TR(A){const e=Il(A,{method:"eth_newBlockFilter"}),t=await A.request({method:"eth_newBlockFilter"});return{id:t,request:e(t),type:"block"}}async function Hw(A,{address:e,args:t,event:n,events:r,fromBlock:s,strict:i,toBlock:a}={}){const g=r??(n?[n]:void 0),c=Il(A,{method:"eth_newFilter"});let l=[];g&&(l=[g.flatMap(u=>Va({abi:[u],eventName:u.name,args:t}))],n&&(l=l[0]));const B=await A.request({method:"eth_newFilter",params:[{address:e,fromBlock:typeof s=="bigint"?NA(s):s,toBlock:typeof a=="bigint"?NA(a):a,...l.length?{topics:l}:{}}]});return{abi:g,args:t,eventName:n?n.name:void 0,fromBlock:s,id:B,request:c(B),strict:!!i,toBlock:a,type:"event"}}async function Pw(A){const e=Il(A,{method:"eth_newPendingTransactionFilter"}),t=await A.request({method:"eth_newPendingTransactionFilter"});return{id:t,request:e(t),type:"transaction"}}async function LR(A,{address:e,blockNumber:t,blockTag:n=A.experimental_blockTag??"latest"}){if(A.batch?.multicall&&A.chain?.contracts?.multicall3){const i=A.chain.contracts.multicall3.address,a=mn({abi:Qi,functionName:"getEthBalance",args:[e]}),{data:g}=await qA(A,sg,"call")({to:i,data:a,blockNumber:t,blockTag:n});return Os({abi:Qi,functionName:"getEthBalance",args:[e],data:g||"0x"})}const r=typeof t=="bigint"?NA(t):void 0,s=await A.request({method:"eth_getBalance",params:[e,r||n]});return BigInt(s)}async function OR(A){const e=await A.request({method:"eth_blobBaseFee"});return BigInt(e)}async function KR(A,{blockHash:e,blockNumber:t,blockTag:n="latest"}={}){const r=t!==void 0?NA(t):void 0;let s;return e?s=await A.request({method:"eth_getBlockTransactionCountByHash",params:[e]},{dedupe:!0}):s=await A.request({method:"eth_getBlockTransactionCountByNumber",params:[r||n]},{dedupe:!!r}),zn(s)}async function vc(A,{address:e,blockNumber:t,blockTag:n="latest"}){const r=t!==void 0?NA(t):void 0,s=await A.request({method:"eth_getCode",params:[e,r||n]},{dedupe:!!r});if(s!=="0x")return s}async function jR(A,{address:e,blockNumber:t,blockTag:n="latest"}){const r=await vc(A,{address:e,...t!==void 0?{blockNumber:t}:{blockTag:n}});if(r&&pt(r)===23&&r.startsWith("0xef0100"))return Cl(Ss(r,3,23))}class JR extends fA{constructor({address:e}){super(`No EIP-712 domain found on contract "${e}".`,{metaMessages:["Ensure that:",`- The contract is deployed at the address "${e}".`,"- `eip712Domain()` function exists on the contract.","- `eip712Domain()` function matches signature to ERC-5267 specification."],name:"Eip712DomainNotFoundError"})}}async function qR(A,e){const{address:t,factory:n,factoryData:r}=e;try{const[s,i,a,g,c,l,B]=await qA(A,mr,"readContract")({abi:YR,address:t,functionName:"eip712Domain",factory:n,factoryData:r});return{domain:{name:i,version:a,chainId:Number(g),verifyingContract:c,salt:l},extensions:B,fields:s}}catch(s){const i=s;throw i.name==="ContractFunctionExecutionError"&&i.cause.name==="ContractFunctionZeroDataError"?new JR({address:t}):i}}const YR=[{inputs:[],name:"eip712Domain",outputs:[{name:"fields",type:"bytes1"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"},{name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"}];function HR(A){return{baseFeePerGas:A.baseFeePerGas.map(e=>BigInt(e)),gasUsedRatio:A.gasUsedRatio,oldestBlock:BigInt(A.oldestBlock),reward:A.reward?.map(e=>e.map(t=>BigInt(t)))}}async function PR(A,{blockCount:e,blockNumber:t,blockTag:n="latest",rewardPercentiles:r}){const s=typeof t=="bigint"?NA(t):void 0,i=await A.request({method:"eth_feeHistory",params:[NA(e),s||n,r]},{dedupe:!!s});return HR(i)}async function _R(A,{filter:e}){const t=e.strict??!1,r=(await e.request({method:"eth_getFilterLogs",params:[e.id]})).map(s=>fr(s));return e.abi?od({abi:e.abi,logs:r,strict:t}):r}function zR(A){const{authorizationList:e}=A;if(e)for(const t of e){const{chainId:n}=t,r=t.address;if(!mt(r))throw new Jt({address:r});if(n<0)throw new rg({chainId:n})}dd(A)}function WR(A){const{blobVersionedHashes:e}=A;if(e){if(e.length===0)throw new iw;for(const t of e){const n=pt(t),r=zn(Ss(t,0,1));if(n!==32)throw new EG({hash:t,size:n});if(r!==ow)throw new dG({hash:t,version:r})}}dd(A)}function dd(A){const{chainId:e,maxPriorityFeePerGas:t,maxFeePerGas:n,to:r}=A;if(e<=0)throw new rg({chainId:e});if(r&&!mt(r))throw new Jt({address:r});if(n&&n>wl)throw new fo({maxFeePerGas:n});if(t&&n&&t>n)throw new ya({maxFeePerGas:n,maxPriorityFeePerGas:t})}function VR(A){const{chainId:e,maxPriorityFeePerGas:t,gasPrice:n,maxFeePerGas:r,to:s}=A;if(e<=0)throw new rg({chainId:e});if(s&&!mt(s))throw new Jt({address:s});if(t||r)throw new fA("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>wl)throw new fo({maxFeePerGas:n})}function ZR(A){const{chainId:e,maxPriorityFeePerGas:t,gasPrice:n,maxFeePerGas:r,to:s}=A;if(s&&!mt(s))throw new Jt({address:s});if(typeof e<"u"&&e<=0)throw new rg({chainId:e});if(t||r)throw new fA("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>wl)throw new fo({maxFeePerGas:n})}function Ml(A){if(!A||A.length===0)return[];const e=[];for(let t=0;t<A.length;t++){const{address:n,storageKeys:r}=A[t];for(let s=0;s<r.length;s++)if(r[s].length-2!==64)throw new Y6({storageKey:r[s]});if(!mt(n,{strict:!1}))throw new Jt({address:n});e.push([n,r])}return e}function Cd(A,e){const t=gw(A);return t==="eip1559"?AU(A,e):t==="eip2930"?eU(A,e):t==="eip4844"?$R(A,e):t==="eip7702"?XR(A,e):tU(A,e)}function XR(A,e){const{authorizationList:t,chainId:n,gas:r,nonce:s,to:i,value:a,maxFeePerGas:g,maxPriorityFeePerGas:c,accessList:l,data:B}=A;zR(A);const Q=Ml(l),u=nU(t);return ir(["0x04",Qs([NA(n),s?NA(s):"0x",c?NA(c):"0x",g?NA(g):"0x",r?NA(r):"0x",i??"0x",a?NA(a):"0x",B??"0x",Q,u,...gg(A,e)])])}function $R(A,e){const{chainId:t,gas:n,nonce:r,to:s,value:i,maxFeePerBlobGas:a,maxFeePerGas:g,maxPriorityFeePerGas:c,accessList:l,data:B}=A;WR(A);let Q=A.blobVersionedHashes,u=A.sidecars;if(A.blobs&&(typeof Q>"u"||typeof u>"u")){const m=typeof A.blobs[0]=="string"?A.blobs:A.blobs.map(Y=>qt(Y)),M=A.kzg,G=Ad({blobs:m,kzg:M});if(typeof Q>"u"&&(Q=nw({commitments:G})),typeof u>"u"){const Y=ed({blobs:m,commitments:G,kzg:M});u=aw({blobs:m,commitments:G,proofs:Y})}}const d=Ml(l),f=[NA(t),r?NA(r):"0x",c?NA(c):"0x",g?NA(g):"0x",n?NA(n):"0x",s??"0x",i?NA(i):"0x",B??"0x",d,a?NA(a):"0x",Q??[],...gg(A,e)],h=[],x=[],b=[];if(u)for(let m=0;m<u.length;m++){const{blob:M,commitment:G,proof:Y}=u[m];h.push(M),x.push(G),b.push(Y)}return ir(["0x03",Qs(u?[f,h,x,b]:f)])}function AU(A,e){const{chainId:t,gas:n,nonce:r,to:s,value:i,maxFeePerGas:a,maxPriorityFeePerGas:g,accessList:c,data:l}=A;dd(A);const B=Ml(c),Q=[NA(t),r?NA(r):"0x",g?NA(g):"0x",a?NA(a):"0x",n?NA(n):"0x",s??"0x",i?NA(i):"0x",l??"0x",B,...gg(A,e)];return ir(["0x02",Qs(Q)])}function eU(A,e){const{chainId:t,gas:n,data:r,nonce:s,to:i,value:a,accessList:g,gasPrice:c}=A;VR(A);const l=Ml(g),B=[NA(t),s?NA(s):"0x",c?NA(c):"0x",n?NA(n):"0x",i??"0x",a?NA(a):"0x",r??"0x",l,...gg(A,e)];return ir(["0x01",Qs(B)])}function tU(A,e){const{chainId:t=0,gas:n,data:r,nonce:s,to:i,value:a,gasPrice:g}=A;ZR(A);let c=[s?NA(s):"0x",g?NA(g):"0x",n?NA(n):"0x",i??"0x",a?NA(a):"0x",r??"0x"];if(e){const l=(()=>{if(e.v>=35n)return(e.v-35n)/2n>0?e.v:27n+(e.v===35n?0n:1n);if(t>0)return BigInt(t*2)+BigInt(35n+e.v-27n);const u=27n+(e.v===27n?0n:1n);if(e.v!==u)throw new J6({v:e.v});return u})(),B=tr(e.r),Q=tr(e.s);c=[...c,NA(l),B==="0x00"?"0x":B,Q==="0x00"?"0x":Q]}else t>0&&(c=[...c,NA(t),"0x","0x"]);return Qs(c)}function gg(A,e){const t=e??A,{v:n,yParity:r}=t;if(typeof t.r>"u")return[];if(typeof t.s>"u")return[];if(typeof n>"u"&&typeof r>"u")return[];const s=tr(t.r),i=tr(t.s);return[typeof r=="number"?r?NA(1):"0x":n===0n?"0x":n===1n?NA(1):n===27n?"0x":NA(1),s==="0x00"?"0x":s,i==="0x00"?"0x":i]}function nU(A){if(!A||A.length===0)return[];const e=[];for(const t of A){const{chainId:n,nonce:r,...s}=t,i=t.address;e.push([n?tt(n):"0x",i,r?tt(r):"0x",...gg({},s)])}return e}async function rU({address:A,authorization:e,signature:t}){return tg(Cl(A),await hl({authorization:e,signature:t}))}const Ug=new bi(8192);function sU(A,{enabled:e=!0,id:t}){if(!e||!t)return A();if(Ug.get(t))return Ug.get(t);const n=A().finally(()=>Ug.delete(t));return Ug.set(t,n),n}function oU(A,e={}){return async(t,n={})=>{const{dedupe:r=!1,methods:s,retryDelay:i=150,retryCount:a=3,uid:g}={...e,...n},{method:c}=t;if(s?.exclude?.includes(c))throw new Vs(new Error("method not supported"),{method:c});if(s?.include&&!s.include.includes(c))throw new Vs(new Error("method not supported"),{method:c});const l=r?ci(`${g}.${_t(t)}`):void 0;return sU(()=>Mc(async()=>{try{return await A(t)}catch(B){const Q=B;switch(Q.code){case oa.code:throw new oa(Q);case ia.code:throw new ia(Q);case aa.code:throw new aa(Q,{method:t.method});case ga.code:throw new ga(Q);case Co.code:throw new Co(Q);case Fs.code:throw new Fs(Q);case ca.code:throw new ca(Q);case la.code:throw new la(Q);case ua.code:throw new ua(Q);case Vs.code:throw new Vs(Q,{method:t.method});case li.code:throw new li(Q);case Ba.code:throw new Ba(Q);case Zo.code:throw new Zo(Q);case Qa.code:throw new Qa(Q);case Ea.code:throw new Ea(Q);case da.code:throw new da(Q);case Ca.code:throw new Ca(Q);case Ia.code:throw new Ia(Q);case ui.code:throw new ui(Q);case fa.code:throw new fa(Q);case ha.code:throw new ha(Q);case pa.code:throw new pa(Q);case ma.code:throw new ma(Q);case wa.code:throw new wa(Q);case Bi.code:throw new Bi(Q);case 5e3:throw new Zo(Q);case xa.code:throw new xa(Q);default:throw B instanceof fA?B:new Z6(Q)}}},{delay:({count:B,error:Q})=>{if(Q&&Q instanceof Xi){const u=Q?.headers?.get("Retry-After");if(u?.match(/\d/))return Number.parseInt(u,10)*1e3}return~~(1<<B)*i},retryCount:a,shouldRetry:({error:B})=>iU(B)}),{enabled:r,id:l})}}function iU(A){return"code"in A&&typeof A.code=="number"?A.code===-1||A.code===li.code||A.code===Co.code:A instanceof Xi&&A.status?A.status===403||A.status===408||A.status===413||A.status===429||A.status===500||A.status===502||A.status===503||A.status===504:!0}function aU(A,{errorInstance:e=new Error("timed out"),timeout:t,signal:n}){return new Promise((r,s)=>{(async()=>{let i;try{const a=new AbortController;t>0&&(i=setTimeout(()=>{n&&a.abort()},t)),r(await A({signal:a?.signal||null}))}catch(a){a?.name==="AbortError"&&s(e),s(a)}finally{clearTimeout(i)}})()})}function gU(){return{current:0,take(){return this.current++},reset(){this.current=0}}}const I0=gU();function cU(A,e={}){const{url:t,headers:n}=lU(A);return{async request(r){const{body:s,fetchFn:i=e.fetchFn??fetch,onRequest:a=e.onRequest,onResponse:g=e.onResponse,timeout:c=e.timeout??1e4}=r,l={...e.fetchOptions??{},...r.fetchOptions??{}},{headers:B,method:Q,signal:u}=l;try{const d=await aU(async({signal:h})=>{const x={...l,body:Array.isArray(s)?_t(s.map(G=>({jsonrpc:"2.0",id:G.id??I0.take(),...G}))):_t({jsonrpc:"2.0",id:s.id??I0.take(),...s}),headers:{...n,"Content-Type":"application/json",...B},method:Q||"POST",signal:u||(c>0?h:null)},b=new Request(t,x),m=await a?.(b,x)??{...x,url:t};return await i(m.url??t,m)},{errorInstance:new t0({body:s,url:t}),timeout:c,signal:!0});g&&await g(d);let f;if(d.headers.get("Content-Type")?.startsWith("application/json"))f=await d.json();else{f=await d.text();try{f=JSON.parse(f||"{}")}catch(h){if(d.ok)throw h;f={error:f}}}if(!d.ok)throw new Xi({body:s,details:_t(f.error)||d.statusText,headers:d.headers,status:d.status,url:t});return f}catch(d){throw d instanceof Xi||d instanceof t0?d:new Xi({body:s,cause:d,url:t})}}}}function lU(A){try{const e=new URL(A),t=(()=>{if(e.username){const n=`${decodeURIComponent(e.username)}:${decodeURIComponent(e.password)}`;return e.username="",e.password="",{url:e.toString(),headers:{Authorization:`Basic ${btoa(n)}`}}}})();return{url:e.toString(),...t}}catch{return{url:A}}}const uU=`Ethereum Signed Message:
151
151
  `;function BU(A){const e=typeof A=="string"?ci(A):typeof A.raw=="string"?A.raw:qt(A.raw),t=ci(`${uU}${pt(e)}`);return pn([t,e])}function Id(A,e){return Vt(BU(A),e)}class QU extends fA{constructor({domain:e}){super(`Invalid domain "${_t(e)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class EU extends fA{constructor({primaryType:e,types:t}){super(`Invalid primary type \`${e}\` must be one of \`${JSON.stringify(Object.keys(t))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class dU extends fA{constructor({type:e}){super(`Struct type "${e}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function CU(A){const{domain:e,message:t,primaryType:n,types:r}=A,s=(g,c)=>{const l={...c};for(const B of g){const{name:Q,type:u}=B;u==="address"&&(l[Q]=l[Q].toLowerCase())}return l},i=r.EIP712Domain?e?s(r.EIP712Domain,e):{}:{},a=(()=>{if(n!=="EIP712Domain")return s(r[n],t)})();return _t({domain:i,message:a,primaryType:n,types:r})}function _w(A){const{domain:e,message:t,primaryType:n,types:r}=A,s=(i,a)=>{for(const g of i){const{name:c,type:l}=g,B=a[c],Q=l.match(Fm);if(Q&&(typeof B=="number"||typeof B=="bigint")){const[f,h,x]=Q;NA(B,{signed:h==="int",size:Number.parseInt(x,10)/8})}if(l==="address"&&typeof B=="string"&&!mt(B))throw new Jt({address:B});const u=l.match(u6);if(u){const[f,h]=u;if(h&&pt(B)!==Number.parseInt(h,10))throw new HF({expectedSize:Number.parseInt(h,10),givenSize:pt(B)})}const d=r[l];d&&(IU(l),s(d,B))}};if(r.EIP712Domain&&e){if(typeof e!="object")throw new QU({domain:e});s(r.EIP712Domain,e)}if(n!=="EIP712Domain")if(r[n])s(r[n],t);else throw new EU({primaryType:n,types:r})}function zw({domain:A}){return[typeof A?.name=="string"&&{name:"name",type:"string"},A?.version&&{name:"version",type:"string"},(typeof A?.chainId=="number"||typeof A?.chainId=="bigint")&&{name:"chainId",type:"uint256"},A?.verifyingContract&&{name:"verifyingContract",type:"address"},A?.salt&&{name:"salt",type:"bytes32"}].filter(Boolean)}function IU(A){if(A==="address"||A==="bool"||A==="string"||A.startsWith("bytes")||A.startsWith("uint")||A.startsWith("int"))throw new dU({type:A})}function Ww(A){const{domain:e={},message:t,primaryType:n}=A,r={EIP712Domain:zw({domain:e}),...A.types};_w({domain:e,message:t,primaryType:n,types:r});const s=["0x1901"];return e&&s.push(fU({domain:e,types:r})),n!=="EIP712Domain"&&s.push(Vw({data:t,primaryType:n,types:r})),Vt(pn(s))}function fU({domain:A,types:e}){return Vw({data:A,primaryType:"EIP712Domain",types:e})}function Vw({data:A,primaryType:e,types:t}){const n=Zw({data:A,primaryType:e,types:t});return Vt(n)}function Zw({data:A,primaryType:e,types:t}){const n=[{type:"bytes32"}],r=[hU({primaryType:e,types:t})];for(const s of t[e]){const[i,a]=$w({types:t,name:s.name,type:s.type,value:A[s.name]});n.push(i),r.push(a)}return Ls(n,r)}function hU({primaryType:A,types:e}){const t=tt(pU({primaryType:A,types:e}));return Vt(t)}function pU({primaryType:A,types:e}){let t="";const n=Xw({primaryType:A,types:e});n.delete(A);const r=[A,...Array.from(n).sort()];for(const s of r)t+=`${s}(${e[s].map(({name:i,type:a})=>`${a} ${i}`).join(",")})`;return t}function Xw({primaryType:A,types:e},t=new Set){const r=A.match(/^\w*/u)?.[0];if(t.has(r)||e[r]===void 0)return t;t.add(r);for(const s of e[r])Xw({primaryType:s.type,types:e},t);return t}function $w({types:A,name:e,type:t,value:n}){if(A[t]!==void 0)return[{type:"bytes32"},Vt(Zw({data:n,primaryType:t,types:A}))];if(t==="bytes")return[{type:"bytes32"},Vt(n)];if(t==="string")return[{type:"bytes32"},Vt(tt(n))];if(t.lastIndexOf("]")===t.length-1){const r=t.slice(0,t.lastIndexOf("[")),s=n.map(i=>$w({name:e,type:r,types:A,value:i}));return[{type:"bytes32"},Vt(Ls(s.map(([i])=>i),s.map(([,i])=>i)))]}return[{type:t},n]}const f0="0x0000000000000000000000000000000000000000000000000000000000000000";class mU extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&t!==void 0&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const wU={checksum:new mU(8192)},Lu=wU.checksum;function Ax(A,e={}){const{as:t=typeof A=="string"?"Hex":"Bytes"}=e,n=Tp(kG(A));return t==="Bytes"?n:pr(n)}const xU=/^0x[a-fA-F0-9]{40}$/;function vl(A,e={}){const{strict:t=!0}=e;if(!xU.test(A))throw new h0({address:A,cause:new yU});if(t){if(A.toLowerCase()===A)return;if(ex(A)!==A)throw new h0({address:A,cause:new DU})}}function ex(A){if(Lu.has(A))return Lu.get(A);vl(A,{strict:!1});const e=A.substring(2).toLowerCase(),t=Ax(vG(e),{as:"Bytes"}),n=e.split("");for(let s=0;s<40;s+=2)t[s>>1]>>4>=8&&n[s]&&(n[s]=n[s].toUpperCase()),(t[s>>1]&15)>=8&&n[s+1]&&(n[s+1]=n[s+1].toUpperCase());const r=`0x${n.join("")}`;return Lu.set(A,r),r}function EQ(A,e={}){const{strict:t=!0}=e??{};try{return vl(A,{strict:t}),!0}catch{return!1}}class h0 extends pe{constructor({address:e,cause:t}){super(`Address "${e}" is invalid.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class yU extends pe{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class DU extends pe{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const bU=/^(.*)\[([0-9]*)\]$/,NU=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,tx=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/,p0=2n**256n-1n;function Xo(A,e,t){const{checksumAddress:n,staticPosition:r}=t,s=pd(e.type);if(s){const[i,a]=s;return MU(A,{...e,type:a},{checksumAddress:n,length:i,staticPosition:r})}if(e.type==="tuple")return GU(A,e,{checksumAddress:n,staticPosition:r});if(e.type==="address")return kU(A,{checksum:n});if(e.type==="bool")return vU(A);if(e.type.startsWith("bytes"))return SU(A,e,{staticPosition:r});if(e.type.startsWith("uint")||e.type.startsWith("int"))return FU(A,e);if(e.type==="string")return RU(A,{staticPosition:r});throw new wd(e.type)}const m0=32,dQ=32;function kU(A,e={}){const{checksum:t=!1}=e,n=A.readBytes(32);return[(s=>t?ex(s):s)(pr(FG(n,-20))),32]}function MU(A,e,t){const{checksumAddress:n,length:r,staticPosition:s}=t;if(!r){const g=as(A.readBytes(dQ)),c=s+g,l=c+m0;A.setPosition(c);const B=as(A.readBytes(m0)),Q=Da(e);let u=0;const d=[];for(let f=0;f<B;++f){A.setPosition(l+(Q?f*32:u));const[h,x]=Xo(A,e,{checksumAddress:n,staticPosition:l});u+=x,d.push(h)}return A.setPosition(s+32),[d,32]}if(Da(e)){const g=as(A.readBytes(dQ)),c=s+g,l=[];for(let B=0;B<r;++B){A.setPosition(c+B*32);const[Q]=Xo(A,e,{checksumAddress:n,staticPosition:c});l.push(Q)}return A.setPosition(s+32),[l,32]}let i=0;const a=[];for(let g=0;g<r;++g){const[c,l]=Xo(A,e,{checksumAddress:n,staticPosition:s+i});i+=l,a.push(c)}return[a,i]}function vU(A){return[RG(A.readBytes(32),{size:32}),32]}function SU(A,e,{staticPosition:t}){const[n,r]=e.type.split("bytes");if(!r){const i=as(A.readBytes(32));A.setPosition(t+i);const a=as(A.readBytes(32));if(a===0)return A.setPosition(t+32),["0x",32];const g=A.readBytes(a);return A.setPosition(t+32),[pr(g),32]}return[pr(A.readBytes(Number.parseInt(r,10),32)),32]}function FU(A,e){const t=e.type.startsWith("int"),n=Number.parseInt(e.type.split("int")[1]||"256",10),r=A.readBytes(32);return[n>48?GG(r,{signed:t}):as(r,{signed:t}),32]}function GU(A,e,t){const{checksumAddress:n,staticPosition:r}=t,s=e.components.length===0||e.components.some(({name:g})=>!g),i=s?[]:{};let a=0;if(Da(e)){const g=as(A.readBytes(dQ)),c=r+g;for(let l=0;l<e.components.length;++l){const B=e.components[l];A.setPosition(c+a);const[Q,u]=Xo(A,B,{checksumAddress:n,staticPosition:c});a+=u,i[s?l:B?.name]=Q}return A.setPosition(r+32),[i,32]}for(let g=0;g<e.components.length;++g){const c=e.components[g],[l,B]=Xo(A,c,{checksumAddress:n,staticPosition:r});i[s?g:c?.name]=l,a+=B}return[i,a]}function RU(A,{staticPosition:e}){const t=as(A.readBytes(32)),n=e+t;A.setPosition(n);const r=as(A.readBytes(32));if(r===0)return A.setPosition(e+32),["",32];const s=A.readBytes(r,32),i=UG(dw(s));return A.setPosition(e+32),[i,32]}function UU({checksumAddress:A,parameters:e,values:t}){const n=[];for(let r=0;r<e.length;r++)n.push(fd({checksumAddress:A,parameter:e[r],value:t[r]}));return n}function fd({checksumAddress:A=!1,parameter:e,value:t}){const n=e,r=pd(n.type);if(r){const[s,i]=r;return LU(t,{checksumAddress:A,length:s,parameter:{...n,type:i}})}if(n.type==="tuple")return qU(t,{checksumAddress:A,parameter:n});if(n.type==="address")return TU(t,{checksum:A});if(n.type==="bool")return KU(t);if(n.type.startsWith("uint")||n.type.startsWith("int")){const s=n.type.startsWith("int"),[,,i="256"]=tx.exec(n.type)??[];return jU(t,{signed:s,size:Number(i)})}if(n.type.startsWith("bytes"))return OU(t,{type:n.type});if(n.type==="string")return JU(t);throw new wd(n.type)}function hd(A){let e=0;for(let s=0;s<A.length;s++){const{dynamic:i,encoded:a}=A[s];i?e+=32:e+=Wn(a)}const t=[],n=[];let r=0;for(let s=0;s<A.length;s++){const{dynamic:i,encoded:a}=A[s];i?(t.push(wn(e+r,{size:32})),n.push(a),r+=Wn(a)):t.push(a)}return hr(...t,...n)}function TU(A,e){const{checksum:t=!1}=e;return vl(A,{strict:t}),{dynamic:!1,encoded:ho(A.toLowerCase())}}function LU(A,e){const{checksumAddress:t,length:n,parameter:r}=e,s=n===null;if(!Array.isArray(A))throw new XU(A);if(!s&&A.length!==n)throw new ZU({expectedLength:n,givenLength:A.length,type:`${r.type}[${n}]`});let i=!1;const a=[];for(let g=0;g<A.length;g++){const c=fd({checksumAddress:t,parameter:r,value:A[g]});c.dynamic&&(i=!0),a.push(c)}if(s||i){const g=hd(a);if(s){const c=wn(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?hr(c,g):c}}if(i)return{dynamic:!0,encoded:g}}return{dynamic:!1,encoded:hr(...a.map(({encoded:g})=>g))}}function OU(A,{type:e}){const[,t]=e.split("bytes"),n=Wn(A);if(!t){let r=A;return n%32!==0&&(r=po(r,Math.ceil((A.length-2)/2/32)*32)),{dynamic:!0,encoded:hr(ho(wn(n,{size:32})),r)}}if(n!==Number.parseInt(t,10))throw new rx({expectedSize:Number.parseInt(t,10),value:A});return{dynamic:!1,encoded:po(A)}}function KU(A){if(typeof A!="boolean")throw new pe(`Invalid boolean value: "${A}" (type: ${typeof A}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:ho(Cw(A))}}function jU(A,{signed:e,size:t}){if(typeof t=="number"){const n=2n**(BigInt(t)-(e?1n:0n))-1n,r=e?-n-1n:0n;if(A>n||A<r)throw new hw({max:n.toString(),min:r.toString(),signed:e,size:t/8,value:A.toString()})}return{dynamic:!1,encoded:wn(A,{size:32,signed:e})}}function JU(A){const e=ad(A),t=Math.ceil(Wn(e)/32),n=[];for(let r=0;r<t;r++)n.push(po(Gr(e,r*32,(r+1)*32)));return{dynamic:!0,encoded:hr(po(wn(Wn(e),{size:32})),...n)}}function qU(A,e){const{checksumAddress:t,parameter:n}=e;let r=!1;const s=[];for(let i=0;i<n.components.length;i++){const a=n.components[i],g=Array.isArray(A)?i:a.name,c=fd({checksumAddress:t,parameter:a,value:A[g]});s.push(c),c.dynamic&&(r=!0)}return{dynamic:r,encoded:r?hd(s):hr(...s.map(({encoded:i})=>i))}}function pd(A){const e=A.match(/^(.*)\[(\d+)?\]$/);return e?[e[2]?Number(e[2]):null,e[1]]:void 0}function Da(A){const{type:e}=A;if(e==="string"||e==="bytes"||e.endsWith("[]"))return!0;if(e==="tuple")return A.components?.some(Da);const t=pd(A.type);return!!(t&&Da({...A,type:t[1]}))}const YU={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new _U({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(A){if(A<0||A>this.bytes.length-1)throw new PU({length:this.bytes.length,position:A})},decrementPosition(A){if(A<0)throw new w0({offset:A});const e=this.position-A;this.assertPosition(e),this.position=e},getReadCount(A){return this.positionReadCount.get(A||this.position)||0},incrementPosition(A){if(A<0)throw new w0({offset:A});const e=this.position+A;this.assertPosition(e),this.position=e},inspectByte(A){const e=A??this.position;return this.assertPosition(e),this.bytes[e]},inspectBytes(A,e){const t=e??this.position;return this.assertPosition(t+A-1),this.bytes.subarray(t,t+A)},inspectUint8(A){const e=A??this.position;return this.assertPosition(e),this.bytes[e]},inspectUint16(A){const e=A??this.position;return this.assertPosition(e+1),this.dataView.getUint16(e)},inspectUint24(A){const e=A??this.position;return this.assertPosition(e+2),(this.dataView.getUint16(e)<<8)+this.dataView.getUint8(e+2)},inspectUint32(A){const e=A??this.position;return this.assertPosition(e+3),this.dataView.getUint32(e)},pushByte(A){this.assertPosition(this.position),this.bytes[this.position]=A,this.position++},pushBytes(A){this.assertPosition(this.position+A.length-1),this.bytes.set(A,this.position),this.position+=A.length},pushUint8(A){this.assertPosition(this.position),this.bytes[this.position]=A,this.position++},pushUint16(A){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,A),this.position+=2},pushUint24(A){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,A>>8),this.dataView.setUint8(this.position+2,A&255),this.position+=3},pushUint32(A){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,A),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const A=this.inspectByte();return this.position++,A},readBytes(A,e){this.assertReadLimit(),this._touch();const t=this.inspectBytes(A);return this.position+=e??A,t},readUint8(){this.assertReadLimit(),this._touch();const A=this.inspectUint8();return this.position+=1,A},readUint16(){this.assertReadLimit(),this._touch();const A=this.inspectUint16();return this.position+=2,A},readUint24(){this.assertReadLimit(),this._touch();const A=this.inspectUint24();return this.position+=3,A},readUint32(){this.assertReadLimit(),this._touch();const A=this.inspectUint32();return this.position+=4,A},get remaining(){return this.bytes.length-this.position},setPosition(A){const e=this.position;return this.assertPosition(A),this.position=A,()=>this.position=e},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const A=this.getReadCount();this.positionReadCount.set(this.position,A+1),A>0&&this.recursiveReadCount++}};function HU(A,{recursiveReadLimit:e=8192}={}){const t=Object.create(YU);return t.bytes=A,t.dataView=new DataView(A.buffer,A.byteOffset,A.byteLength),t.positionReadCount=new Map,t.recursiveReadLimit=e,t}class w0 extends pe{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Cursor.NegativeOffsetError"})}}class PU extends pe{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Cursor.PositionOutOfBoundsError"})}}class _U extends pe{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Cursor.RecursiveReadLimitExceededError"})}}function zU(A,e,t={}){const{as:n="Array",checksumAddress:r=!1}=t,s=typeof e=="string"?Ew(e):e,i=HU(s);if(Ho(s)===0&&A.length>0)throw new VU;if(Ho(s)&&Ho(s)<32)throw new WU({data:typeof e=="string"?e:pr(e),parameters:A,size:Ho(s)});let a=0;const g=n==="Array"?[]:{};for(let c=0;c<A.length;++c){const l=A[c];i.setPosition(a);const[B,Q]=Xo(i,l,{checksumAddress:r,staticPosition:0});a+=Q,n==="Array"?g.push(B):g[l.name??c]=B}return g}function md(A,e,t){const{checksumAddress:n=!1}={};if(A.length!==e.length)throw new sx({expectedLength:A.length,givenLength:e.length});const r=UU({checksumAddress:n,parameters:A,values:e}),s=hd(r);return s.length===0?"0x":s}function CQ(A,e){if(A.length!==e.length)throw new sx({expectedLength:A.length,givenLength:e.length});const t=[];for(let n=0;n<A.length;n++){const r=A[n],s=e[n];t.push(CQ.encode(r,s))}return hr(...t)}(function(A){function e(t,n,r=!1){if(t==="address"){const g=n;return vl(g),ho(g.toLowerCase(),r?32:0)}if(t==="string")return ad(n);if(t==="bytes")return n;if(t==="bool")return ho(Cw(n),r?32:1);const s=t.match(tx);if(s){const[g,c,l="256"]=s,B=Number.parseInt(l,10)/8;return wn(n,{size:r?32:B,signed:c==="int"})}const i=t.match(NU);if(i){const[g,c]=i;if(Number.parseInt(c,10)!==(n.length-2)/2)throw new rx({expectedSize:Number.parseInt(c,10),value:n});return po(n,r?32:0)}const a=t.match(bU);if(a&&Array.isArray(n)){const[g,c]=a,l=[];for(let B=0;B<n.length;B++)l.push(e(c,n[B],!0));return l.length===0?"0x":hr(...l)}throw new wd(t)}A.encode=e})(CQ||(CQ={}));function nx(A){return Array.isArray(A)&&typeof A[0]=="string"||typeof A=="string"?HI(A):A}class WU extends pe{constructor({data:e,parameters:t,size:n}){super(`Data size of ${n} bytes is too small for given parameters.`,{metaMessages:[`Params: (${jo(t)})`,`Data: ${e} (${n} bytes)`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.DataSizeTooSmallError"})}}class VU extends pe{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.'),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.ZeroDataError"})}}class ZU extends pe{constructor({expectedLength:e,givenLength:t,type:n}){super(`Array length mismatch for type \`${n}\`. Expected: \`${e}\`. Given: \`${t}\`.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.ArrayLengthMismatchError"})}}class rx extends pe{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${Wn(t)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class sx extends pe{constructor({expectedLength:e,givenLength:t}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${e}`,`Given length (values): ${t}`].join(`
152
152
  `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class XU extends pe{constructor(e){super(`Value \`${e}\` is not a valid array.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidArrayError"})}}class wd extends pe{constructor(e){super(`Type \`${e}\` is not a valid ABI Type.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidTypeError"})}}function ox(A,e={}){const{recovered:t}=e;if(typeof A.r>"u")throw new Ou({signature:A});if(typeof A.s>"u")throw new Ou({signature:A});if(t&&typeof A.yParity>"u")throw new Ou({signature:A});if(A.r<0n||A.r>p0)throw new sT({value:A.r});if(A.s<0n||A.s>p0)throw new oT({value:A.s});if(typeof A.yParity=="number"&&A.yParity!==0&&A.yParity!==1)throw new yd({value:A.yParity})}function $U(A){return ix(pr(A))}function ix(A){if(A.length!==130&&A.length!==132)throw new rT({signature:A});const e=BigInt(Gr(A,0,32)),t=BigInt(Gr(A,32,64)),n=(()=>{const r=+`0x${A.slice(130)}`;if(!Number.isNaN(r))try{return xd(r)}catch{throw new yd({value:r})}})();return typeof n>"u"?{r:e,s:t}:{r:e,s:t,yParity:n}}function AT(A){if(!(typeof A.r>"u")&&!(typeof A.s>"u"))return eT(A)}function eT(A){const e=typeof A=="string"?ix(A):A instanceof Uint8Array?$U(A):typeof A.r=="string"?nT(A):A.v?tT(A):{r:A.r,s:A.s,...typeof A.yParity<"u"?{yParity:A.yParity}:{}};return ox(e),e}function tT(A){return{r:A.r,s:A.s,yParity:xd(A.v)}}function nT(A){const e=(()=>{const t=A.v?Number(A.v):void 0;let n=A.yParity?Number(A.yParity):void 0;if(typeof t=="number"&&typeof n!="number"&&(n=xd(t)),typeof n!="number")throw new yd({value:A.yParity});return n})();return{r:BigInt(A.r),s:BigInt(A.s),yParity:e}}function xd(A){if(A===0||A===27)return 0;if(A===1||A===28)return 1;if(A>=35)return A%2===0?1:0;throw new iT({value:A})}class rT extends pe{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${Wn(YG(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class Ou extends pe{constructor({signature:e}){super(`Signature \`${Qw(e)}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.MissingPropertiesError"})}}class sT extends pe{constructor({value:e}){super(`Value \`${e}\` is an invalid r value. r must be a positive integer less than 2^256.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidRError"})}}class oT extends pe{constructor({value:e}){super(`Value \`${e}\` is an invalid s value. s must be a positive integer less than 2^256.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSError"})}}class yd extends pe{constructor({value:e}){super(`Value \`${e}\` is an invalid y-parity value. Y-parity must be 0 or 1.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidYParityError"})}}class iT extends pe{constructor({value:e}){super(`Value \`${e}\` is an invalid v value. v must be 27, 28 or >=35.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidVError"})}}function aT(A,e={}){return typeof A.chainId=="string"?gT(A):{...A,...e.signature}}function gT(A){const{address:e,chainId:t,nonce:n}=A,r=AT(A);return{address:e,chainId:Number(t),nonce:BigInt(n),...r}}const cT="0x8010801080108010801080108010801080108010801080108010801080108010",lT=nx("(uint256 chainId, address delegation, uint256 nonce, uint8 yParity, uint256 r, uint256 s), address to, bytes data");function ax(A){if(typeof A=="string"){if(Gr(A,-32)!==cT)throw new QT(A)}else ox(A.authorization)}function uT(A){ax(A);const e=fw(Gr(A,-64,-32)),t=Gr(A,-e-64,-64),n=Gr(A,0,-e-64),[r,s,i]=zU(lT,t);return{authorization:aT({address:r.delegation,chainId:Number(r.chainId),nonce:r.nonce,yParity:r.yParity,r:r.r,s:r.s}),signature:n,...i&&i!=="0x"?{data:i,to:s}:{}}}function BT(A){try{return ax(A),!0}catch{return!1}}let QT=class extends pe{constructor(e){super(`Value \`${e}\` is an invalid ERC-8010 wrapped signature.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SignatureErc8010.InvalidWrappedSignatureError"})}};function ET(A){return A.map(e=>({...e,value:BigInt(e.value)}))}function dT(A){return{...A,balance:A.balance?BigInt(A.balance):void 0,nonce:A.nonce?zn(A.nonce):void 0,storageProof:A.storageProof?ET(A.storageProof):void 0}}async function CT(A,{address:e,blockNumber:t,blockTag:n,storageKeys:r}){const s=n??"latest",i=t!==void 0?NA(t):void 0,a=await A.request({method:"eth_getProof",params:[e,r,i||s]});return dT(a)}async function IT(A,{address:e,blockNumber:t,blockTag:n="latest",slot:r}){const s=t!==void 0?NA(t):void 0;return await A.request({method:"eth_getStorageAt",params:[e,r,s||n]})}async function Dd(A,{blockHash:e,blockNumber:t,blockTag:n,hash:r,index:s,sender:i,nonce:a}){const g=n||"latest",c=t!==void 0?NA(t):void 0;let l=null;if(r?l=await A.request({method:"eth_getTransactionByHash",params:[r]},{dedupe:!0}):e?l=await A.request({method:"eth_getTransactionByBlockHashAndIndex",params:[e,NA(s)]},{dedupe:!0}):typeof s=="number"?l=await A.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[c||g,NA(s)]},{dedupe:!!c}):i&&typeof a=="number"&&(l=await A.request({method:"eth_getTransactionBySenderAndNonce",params:[i,NA(a)]},{dedupe:!0})),!l)throw new Km({blockHash:e,blockNumber:t,blockTag:g,hash:r,index:s});return(A.chain?.formatters?.transaction?.format||Ag)(l,"getTransaction")}async function fT(A,{hash:e,transactionReceipt:t}){const[n,r]=await Promise.all([qA(A,og,"getBlockNumber")({}),e?qA(A,Dd,"getTransaction")({hash:e}):void 0]),s=t?.blockNumber||r?.blockNumber;return s?n-s+1n:0n}async function Vg(A,{hash:e}){const t=await A.request({method:"eth_getTransactionReceipt",params:[e]},{dedupe:!0});if(!t)throw new jm({hash:e});return(A.chain?.formatters?.transactionReceipt?.format||ld)(t,"getTransactionReceipt")}async function hT(A,e){const{account:t,authorizationList:n,allowFailure:r=!0,blockNumber:s,blockOverrides:i,blockTag:a,stateOverride:g}=e,c=e.contracts,{batchSize:l=e.batchSize??1024,deployless:B=e.deployless??!1}=typeof A.batch?.multicall=="object"?A.batch.multicall:{},Q=(()=>{if(e.multicallAddress)return e.multicallAddress;if(B)return null;if(A.chain)return Mi({blockNumber:s,chain:A.chain,contract:"multicall3"});throw new Error("client chain not configured. multicallAddress is required.")})(),u=[[]];let d=0,f=0;for(let b=0;b<c.length;b++){const{abi:m,address:M,args:G,functionName:Y}=c[b];try{const Z=mn({abi:m,args:G,functionName:Y});f+=(Z.length-2)/2,l>0&&f>l&&u[d].length>0&&(d++,f=(Z.length-2)/2,u[d]=[]),u[d]=[...u[d],{allowFailure:!0,callData:Z,target:M}]}catch(Z){const P=Io(Z,{abi:m,address:M,args:G,docsPath:"/docs/contract/multicall",functionName:Y,sender:t});if(!r)throw P;u[d]=[...u[d],{allowFailure:!0,callData:"0x",target:M}]}}const h=await Promise.allSettled(u.map(b=>qA(A,mr,"readContract")({...Q===null?{code:gd}:{address:Q},abi:Qi,account:t,args:[b],authorizationList:n,blockNumber:s,blockOverrides:i,blockTag:a,functionName:"aggregate3",stateOverride:g}))),x=[];for(let b=0;b<h.length;b++){const m=h[b];if(m.status==="rejected"){if(!r)throw m.reason;for(let G=0;G<u[b].length;G++)x.push({status:"failure",error:m.reason,result:void 0});continue}const M=m.value;for(let G=0;G<M.length;G++){const{returnData:Y,success:Z}=M[G],{callData:P}=u[b][G],{abi:L,address:q,functionName:v,args:U}=c[x.length];try{if(P==="0x")throw new _a;if(!Z)throw new fl({data:Y});const w=Os({abi:L,args:U,data:Y,functionName:v});x.push(r?{result:w,status:"success"}:w)}catch(w){const E=Io(w,{abi:L,address:q,args:U,docsPath:"/docs/contract/multicall",functionName:v});if(!r)throw E;x.push({error:E,result:void 0,status:"failure"})}}}if(x.length!==c.length)throw new fA("multicall results mismatch");return x}async function IQ(A,e){const{blockNumber:t,blockTag:n=A.experimental_blockTag??"latest",blocks:r,returnFullTransactions:s,traceTransfers:i,validation:a}=e;try{const g=[];for(const Q of r){const u=Q.blockOverrides?mw(Q.blockOverrides):void 0,d=Q.calls.map(h=>{const x=h,b=x.account?Ct(x.account):void 0,m=x.abi?mn(x):x.data,M={...x,account:b,data:x.dataSuffix?pn([m||"0x",x.dataSuffix]):m,from:x.from??b?.address};return jr(M),Is(M)}),f=Q.stateOverrides?WE(Q.stateOverrides):void 0;g.push({blockOverrides:u,calls:d,stateOverrides:f})}const l=(typeof t=="bigint"?NA(t):void 0)||n;return(await A.request({method:"eth_simulateV1",params:[{blockStateCalls:g,returnFullTransactions:s,traceTransfers:i,validation:a},l]})).map((Q,u)=>({...ZE(Q),calls:Q.calls.map((d,f)=>{const{abi:h,args:x,functionName:b,to:m}=r[u].calls[f],M=d.error?.data??d.returnData,G=BigInt(d.gasUsed),Y=d.logs?.map(q=>fr(q)),Z=d.status==="0x1"?"success":"failure",P=h&&Z==="success"&&M!=="0x"?Os({abi:h,data:M,functionName:b}):null,L=(()=>{if(Z==="success")return;let q;if(M==="0x"?q=new _a:M&&(q=new fl({data:M})),!!q)return Io(q,{abi:h??[],address:m??"0x",args:x,functionName:b??"<unknown>"})})();return{data:M,gasUsed:G,logs:Y,status:Z,...Z==="success"?{result:P}:{error:L}}})}))}catch(g){const c=g,l=pl(c,{});throw l instanceof $a?c:l}}function fQ(A){let e=!0,t="",n=0,r="",s=!1;for(let i=0;i<A.length;i++){const a=A[i];if(["(",")",","].includes(a)&&(e=!0),a==="("&&n++,a===")"&&n--,!!e){if(n===0){if(a===" "&&["event","function","error",""].includes(r))r="";else if(r+=a,a===")"){s=!0;break}continue}if(a===" "){A[i-1]!==","&&t!==","&&t!==",("&&(t="",e=!1);continue}r+=a,t+=a}}if(!s)throw new pe("Unable to normalize signature.");return r}function hQ(A,e){const t=typeof A,n=e.type;switch(n){case"address":return EQ(A,{strict:!1});case"bool":return t==="boolean";case"function":return t==="string";case"string":return t==="string";default:return n==="tuple"&&"components"in e?Object.values(e.components).every((r,s)=>hQ(Object.values(A)[s],r)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(n)?t==="number"||t==="bigint":/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(n)?t==="string"||A instanceof Uint8Array:/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(n)?Array.isArray(A)&&A.every(r=>hQ(r,{...e,type:n.replace(/(\[[0-9]{0,}\])$/,"")})):!1}}function gx(A,e,t){for(const n in A){const r=A[n],s=e[n];if(r.type==="tuple"&&s.type==="tuple"&&"components"in r&&"components"in s)return gx(r.components,s.components,t[n]);const i=[r.type,s.type];if(i.includes("address")&&i.includes("bytes20")?!0:i.includes("address")&&i.includes("string")?EQ(t[n],{strict:!1}):i.includes("address")&&i.includes("bytes")?EQ(t[n],{strict:!1}):!1)return i}}function cx(A,e={}){const{prepare:t=!0}=e,n=Array.isArray(A)||typeof A=="string"?YI(A):A;return{...n,...t?{hash:Po(n)}:{}}}function Sl(A,e,t){const{args:n=[],prepare:r=!0}=t??{},s=HG(e,{strict:!1}),i=A.filter(c=>s?c.type==="function"||c.type==="error"?lx(c)===Gr(e,0,4):c.type==="event"?Po(c)===e:!1:"name"in c&&c.name===e);if(i.length===0)throw new Sc({name:e});if(i.length===1)return{...i[0],...r?{hash:Po(i[0])}:{}};let a;for(const c of i){if(!("inputs"in c))continue;if(!n||n.length===0){if(!c.inputs||c.inputs.length===0)return{...c,...r?{hash:Po(c)}:{}};continue}if(!c.inputs||c.inputs.length===0||c.inputs.length!==n.length)continue;if(n.every((B,Q)=>{const u="inputs"in c&&c.inputs[Q];return u?hQ(B,u):!1})){if(a&&"inputs"in a&&a.inputs){const B=gx(c.inputs,a.inputs,n);if(B)throw new mT({abiItem:c,type:B[0]},{abiItem:a,type:B[1]})}a=c}}const g=(()=>{if(a)return a;const[c,...l]=i;return{...c,overloads:l}})();if(!g)throw new Sc({name:e});return{...g,...r?{hash:Po(g)}:{}}}function lx(...A){const e=(()=>{if(Array.isArray(A[0])){const[t,n]=A;return Sl(t,n)}return A[0]})();return Gr(Po(e),0,4)}function pT(...A){const e=(()=>{if(Array.isArray(A[0])){const[n,r]=A;return Sl(n,r)}return A[0]})(),t=typeof e=="string"?e:Dc(e);return fQ(t)}function Po(...A){const e=(()=>{if(Array.isArray(A[0])){const[t,n]=A;return Sl(t,n)}return A[0]})();return typeof e!="string"&&"hash"in e&&e.hash?e.hash:Ax(ad(pT(e)))}class mT extends pe{constructor(e,t){super("Found ambiguous types in overloaded ABI Items.",{metaMessages:[`\`${e.type}\` in \`${fQ(Dc(e.abiItem))}\`, and`,`\`${t.type}\` in \`${fQ(Dc(t.abiItem))}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiItem.AmbiguityError"})}}class Sc extends pe{constructor({name:e,data:t,type:n="item"}){const r=e?` with name "${e}"`:t?` with data "${t}"`:"";super(`ABI ${n}${r} not found.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiItem.NotFoundError"})}}function wT(...A){const[e,t]=(()=>{if(Array.isArray(A[0])){const[s,i]=A;return[yT(s),i]}return A})(),{bytecode:n,args:r}=t;return hr(n,e.inputs?.length&&r?.length?md(e.inputs,r):"0x")}function xT(A){return cx(A)}function yT(A){const e=A.find(t=>t.type==="constructor");if(!e)throw new Sc({name:"constructor"});return e}function DT(...A){const[e,t=[]]=(()=>{if(Array.isArray(A[0])){const[c,l,B]=A;return[x0(c,l,{args:B}),B]}const[a,g]=A;return[a,g]})(),{overloads:n}=e,r=n?x0([e,...n],e.name,{args:t}):e,s=bT(r),i=t.length>0?md(r.inputs,t):void 0;return i?hr(s,i):s}function Oo(A,e={}){return cx(A,e)}function x0(A,e,t){const n=Sl(A,e,t);if(n.type!=="function")throw new Sc({name:e,type:"function"});return n}function bT(A){return lx(A)}const NT="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",ar="0x0000000000000000000000000000000000000000",kT="0x6080604052348015600e575f80fd5b5061016d8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063f8b2cb4f1461002d575b5f80fd5b610047600480360381019061004291906100db565b61005d565b604051610054919061011e565b60405180910390f35b5f8173ffffffffffffffffffffffffffffffffffffffff16319050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100aa82610081565b9050919050565b6100ba816100a0565b81146100c4575f80fd5b50565b5f813590506100d5816100b1565b92915050565b5f602082840312156100f0576100ef61007d565b5b5f6100fd848285016100c7565b91505092915050565b5f819050919050565b61011881610106565b82525050565b5f6020820190506101315f83018461010f565b9291505056fea26469706673582212203b9fe929fe995c7cf9887f0bdba8a36dd78e8b73f149b17d2d9ad7cd09d2dc6264736f6c634300081a0033";async function MT(A,e){const{blockNumber:t,blockTag:n,calls:r,stateOverrides:s,traceAssetChanges:i,traceTransfers:a,validation:g}=e,c=e.account?Ct(e.account):void 0;if(i&&!c)throw new fA("`account` is required when `traceAssetChanges` is true");const l=c?wT(xT("constructor(bytes, bytes)"),{bytecode:Dw,args:[kT,DT(Oo("function getBalance(address)"),[c.address])]}):void 0,B=i?await Promise.all(e.calls.map(async T=>{if(!T.data&&!T.abi)return;const{accessList:J}=await Yw(A,{account:c.address,...T,data:T.abi?mn(T):T.data});return J.map(({address:z,storageKeys:R})=>R.length>0?z:null)})).then(T=>T.flat().filter(Boolean)):[],Q=await IQ(A,{blockNumber:t,blockTag:n,blocks:[...i?[{calls:[{data:l}],stateOverrides:s},{calls:B.map((T,J)=>({abi:[Oo("function balanceOf(address) returns (uint256)")],functionName:"balanceOf",args:[c.address],to:T,from:ar,nonce:J})),stateOverrides:[{address:ar,nonce:0}]}]:[],{calls:[...r,{to:ar}].map(T=>({...T,from:c?.address})),stateOverrides:s},...i?[{calls:[{data:l}]},{calls:B.map((T,J)=>({abi:[Oo("function balanceOf(address) returns (uint256)")],functionName:"balanceOf",args:[c.address],to:T,from:ar,nonce:J})),stateOverrides:[{address:ar,nonce:0}]},{calls:B.map((T,J)=>({to:T,abi:[Oo("function decimals() returns (uint256)")],functionName:"decimals",from:ar,nonce:J})),stateOverrides:[{address:ar,nonce:0}]},{calls:B.map((T,J)=>({to:T,abi:[Oo("function tokenURI(uint256) returns (string)")],functionName:"tokenURI",args:[0n],from:ar,nonce:J})),stateOverrides:[{address:ar,nonce:0}]},{calls:B.map((T,J)=>({to:T,abi:[Oo("function symbol() returns (string)")],functionName:"symbol",from:ar,nonce:J})),stateOverrides:[{address:ar,nonce:0}]}]:[]],traceTransfers:a,validation:g}),u=i?Q[2]:Q[0],[d,f,,h,x,b,m,M]=i?Q:[],{calls:G,...Y}=u,Z=G.slice(0,-1)??[],P=d?.calls??[],L=f?.calls??[],q=[...P,...L].map(T=>T.status==="success"?ot(T.data):null),v=h?.calls??[],U=x?.calls??[],w=[...v,...U].map(T=>T.status==="success"?ot(T.data):null),E=(b?.calls??[]).map(T=>T.status==="success"?T.result:null),C=(M?.calls??[]).map(T=>T.status==="success"?T.result:null),y=(m?.calls??[]).map(T=>T.status==="success"?T.result:null),F=[];for(const[T,J]of w.entries()){const z=q[T];if(typeof J!="bigint"||typeof z!="bigint")continue;const R=E[T-1],I=C[T-1],p=y[T-1],K=T===0?{address:NT,decimals:18,symbol:"ETH"}:{address:B[T-1],decimals:p||R?Number(R??1):void 0,symbol:I??void 0};F.some(j=>j.token.address===K.address)||F.push({token:K,value:{pre:z,post:J,diff:J-z}})}return{assetChanges:F,block:Y,results:Z}}const ux="0x6492649264926492649264926492649264926492649264926492649264926492";function vT(A){if(Gr(A,-32)!==ux)throw new GT(A)}function ST(A){const{data:e,signature:t,to:n}=A;return hr(md(nx("address, bytes, bytes"),[n,e,t]),ux)}function FT(A){try{return vT(A),!0}catch{return!1}}class GT extends pe{constructor(e){super(`Value \`${e}\` is an invalid ERC-6492 wrapped signature.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SignatureErc6492.InvalidWrappedSignatureError"})}}const bd=BigInt(0),pQ=BigInt(1);function cg(A){return A instanceof Uint8Array||ArrayBuffer.isView(A)&&A.constructor.name==="Uint8Array"}function Nd(A){if(!cg(A))throw new Error("Uint8Array expected")}function ba(A,e){if(typeof e!="boolean")throw new Error(A+" boolean expected, got "+e)}function Tg(A){const e=A.toString(16);return e.length&1?"0"+e:e}function Bx(A){if(typeof A!="string")throw new Error("hex string expected, got "+typeof A);return A===""?bd:BigInt("0x"+A)}const Qx=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",RT=Array.from({length:256},(A,e)=>e.toString(16).padStart(2,"0"));function Na(A){if(Nd(A),Qx)return A.toHex();let e="";for(let t=0;t<A.length;t++)e+=RT[A[t]];return e}const Zr={_0:48,_9:57,A:65,F:70,a:97,f:102};function y0(A){if(A>=Zr._0&&A<=Zr._9)return A-Zr._0;if(A>=Zr.A&&A<=Zr.F)return A-(Zr.A-10);if(A>=Zr.a&&A<=Zr.f)return A-(Zr.a-10)}function Fc(A){if(typeof A!="string")throw new Error("hex string expected, got "+typeof A);if(Qx)return Uint8Array.fromHex(A);const e=A.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(t);for(let r=0,s=0;r<t;r++,s+=2){const i=y0(A.charCodeAt(s)),a=y0(A.charCodeAt(s+1));if(i===void 0||a===void 0){const g=A[s]+A[s+1];throw new Error('hex string expected, got non-hex character "'+g+'" at index '+s)}n[r]=i*16+a}return n}function ro(A){return Bx(Na(A))}function Ex(A){return Nd(A),Bx(Na(Uint8Array.from(A).reverse()))}function lg(A,e){return Fc(A.toString(16).padStart(e*2,"0"))}function dx(A,e){return lg(A,e).reverse()}function $n(A,e,t){let n;if(typeof e=="string")try{n=Fc(e)}catch(s){throw new Error(A+" must be hex string or Uint8Array, cause: "+s)}else if(cg(e))n=Uint8Array.from(e);else throw new Error(A+" must be hex string or Uint8Array");const r=n.length;if(typeof t=="number"&&r!==t)throw new Error(A+" of length "+t+" expected, got "+r);return n}function Gc(...A){let e=0;for(let n=0;n<A.length;n++){const r=A[n];Nd(r),e+=r.length}const t=new Uint8Array(e);for(let n=0,r=0;n<A.length;n++){const s=A[n];t.set(s,r),r+=s.length}return t}const Ku=A=>typeof A=="bigint"&&bd<=A;function kd(A,e,t){return Ku(A)&&Ku(e)&&Ku(t)&&e<=A&&A<t}function $o(A,e,t,n){if(!kd(e,t,n))throw new Error("expected valid "+A+": "+t+" <= n < "+n+", got "+e)}function UT(A){let e;for(e=0;A>bd;A>>=pQ,e+=1);return e}const Fl=A=>(pQ<<BigInt(A))-pQ,ju=A=>new Uint8Array(A),D0=A=>Uint8Array.from(A);function TT(A,e,t){if(typeof A!="number"||A<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=ju(A),r=ju(A),s=0;const i=()=>{n.fill(1),r.fill(0),s=0},a=(...B)=>t(r,n,...B),g=(B=ju(0))=>{r=a(D0([0]),B),n=a(),B.length!==0&&(r=a(D0([1]),B),n=a())},c=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let B=0;const Q=[];for(;B<e;){n=a();const u=n.slice();Q.push(u),B+=n.length}return Gc(...Q)};return(B,Q)=>{i(),g(B);let u;for(;!(u=Q(c()));)g();return i(),u}}const LT={bigint:A=>typeof A=="bigint",function:A=>typeof A=="function",boolean:A=>typeof A=="boolean",string:A=>typeof A=="string",stringOrUint8Array:A=>typeof A=="string"||cg(A),isSafeInteger:A=>Number.isSafeInteger(A),array:A=>Array.isArray(A),field:(A,e)=>e.Fp.isValid(A),hash:A=>typeof A=="function"&&Number.isSafeInteger(A.outputLen)};function Gl(A,e,t={}){const n=(r,s,i)=>{const a=LT[s];if(typeof a!="function")throw new Error("invalid validator function");const g=A[r];if(!(i&&g===void 0)&&!a(g,A))throw new Error("param "+String(r)+" is invalid. Expected "+s+", got "+g)};for(const[r,s]of Object.entries(e))n(r,s,!1);for(const[r,s]of Object.entries(t))n(r,s,!0);return A}function b0(A){const e=new WeakMap;return(t,...n)=>{const r=e.get(t);if(r!==void 0)return r;const s=A(t,...n);return e.set(t,s),s}}const Gn=BigInt(0),yn=BigInt(1),Zs=BigInt(2),OT=BigInt(3),Cx=BigInt(4),Ix=BigInt(5),fx=BigInt(8);function vn(A,e){const t=A%e;return t>=Gn?t:e+t}function Xn(A,e,t){let n=A;for(;e-- >Gn;)n*=n,n%=t;return n}function mQ(A,e){if(A===Gn)throw new Error("invert: expected non-zero number");if(e<=Gn)throw new Error("invert: expected positive modulus, got "+e);let t=vn(A,e),n=e,r=Gn,s=yn;for(;t!==Gn;){const a=n/t,g=n%t,c=r-s*a;n=t,t=g,r=s,s=c}if(n!==yn)throw new Error("invert: does not exist");return vn(r,e)}function hx(A,e){const t=(A.ORDER+yn)/Cx,n=A.pow(e,t);if(!A.eql(A.sqr(n),e))throw new Error("Cannot find square root");return n}function KT(A,e){const t=(A.ORDER-Ix)/fx,n=A.mul(e,Zs),r=A.pow(n,t),s=A.mul(e,r),i=A.mul(A.mul(s,Zs),r),a=A.mul(s,A.sub(i,A.ONE));if(!A.eql(A.sqr(a),e))throw new Error("Cannot find square root");return a}function jT(A){if(A<BigInt(3))throw new Error("sqrt is not defined for small field");let e=A-yn,t=0;for(;e%Zs===Gn;)e/=Zs,t++;let n=Zs;const r=Md(A);for(;N0(r,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return hx;let s=r.pow(n,e);const i=(e+yn)/Zs;return function(g,c){if(g.is0(c))return c;if(N0(g,c)!==1)throw new Error("Cannot find square root");let l=t,B=g.mul(g.ONE,s),Q=g.pow(c,e),u=g.pow(c,i);for(;!g.eql(Q,g.ONE);){if(g.is0(Q))return g.ZERO;let d=1,f=g.sqr(Q);for(;!g.eql(f,g.ONE);)if(d++,f=g.sqr(f),d===l)throw new Error("Cannot find square root");const h=yn<<BigInt(l-d-1),x=g.pow(B,h);l=d,B=g.sqr(x),Q=g.mul(Q,B),u=g.mul(u,x)}return u}}function JT(A){return A%Cx===OT?hx:A%fx===Ix?KT:jT(A)}const qT=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function YT(A){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=qT.reduce((n,r)=>(n[r]="function",n),e);return Gl(A,t)}function HT(A,e,t){if(t<Gn)throw new Error("invalid exponent, negatives unsupported");if(t===Gn)return A.ONE;if(t===yn)return e;let n=A.ONE,r=e;for(;t>Gn;)t&yn&&(n=A.mul(n,r)),r=A.sqr(r),t>>=yn;return n}function px(A,e,t=!1){const n=new Array(e.length).fill(t?A.ZERO:void 0),r=e.reduce((i,a,g)=>A.is0(a)?i:(n[g]=i,A.mul(i,a)),A.ONE),s=A.inv(r);return e.reduceRight((i,a,g)=>A.is0(a)?i:(n[g]=A.mul(i,n[g]),A.mul(i,a)),s),n}function N0(A,e){const t=(A.ORDER-yn)/Zs,n=A.pow(e,t),r=A.eql(n,A.ONE),s=A.eql(n,A.ZERO),i=A.eql(n,A.neg(A.ONE));if(!r&&!s&&!i)throw new Error("invalid Legendre symbol result");return r?1:s?0:-1}function mx(A,e){e!==void 0&&ei(e);const t=e!==void 0?e:A.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Md(A,e,t=!1,n={}){if(A<=Gn)throw new Error("invalid field: expected ORDER > 0, got "+A);const{nBitLength:r,nByteLength:s}=mx(A,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i;const a=Object.freeze({ORDER:A,isLE:t,BITS:r,BYTES:s,MASK:Fl(r),ZERO:Gn,ONE:yn,create:g=>vn(g,A),isValid:g=>{if(typeof g!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof g);return Gn<=g&&g<A},is0:g=>g===Gn,isOdd:g=>(g&yn)===yn,neg:g=>vn(-g,A),eql:(g,c)=>g===c,sqr:g=>vn(g*g,A),add:(g,c)=>vn(g+c,A),sub:(g,c)=>vn(g-c,A),mul:(g,c)=>vn(g*c,A),pow:(g,c)=>HT(a,g,c),div:(g,c)=>vn(g*mQ(c,A),A),sqrN:g=>g*g,addN:(g,c)=>g+c,subN:(g,c)=>g-c,mulN:(g,c)=>g*c,inv:g=>mQ(g,A),sqrt:n.sqrt||(g=>(i||(i=JT(A)),i(a,g))),toBytes:g=>t?dx(g,s):lg(g,s),fromBytes:g=>{if(g.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+g.length);return t?Ex(g):ro(g)},invertBatch:g=>px(a,g),cmov:(g,c,l)=>l?c:g});return Object.freeze(a)}function wx(A){if(typeof A!="bigint")throw new Error("field order must be bigint");const e=A.toString(2).length;return Math.ceil(e/8)}function xx(A){const e=wx(A);return e+Math.ceil(e/2)}function PT(A,e,t=!1){const n=A.length,r=wx(e),s=xx(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const i=t?Ex(A):ro(A),a=vn(i,e-yn)+yn;return t?dx(a,r):lg(a,r)}const k0=BigInt(0),wQ=BigInt(1);function Ju(A,e){const t=e.negate();return A?t:e}function yx(A,e){if(!Number.isSafeInteger(A)||A<=0||A>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+A)}function qu(A,e){yx(A,e);const t=Math.ceil(e/A)+1,n=2**(A-1),r=2**A,s=Fl(A),i=BigInt(A);return{windows:t,windowSize:n,mask:s,maxNumber:r,shiftBy:i}}function M0(A,e,t){const{windowSize:n,mask:r,maxNumber:s,shiftBy:i}=t;let a=Number(A&r),g=A>>i;a>n&&(a-=s,g+=wQ);const c=e*n,l=c+Math.abs(a)-1,B=a===0,Q=a<0,u=e%2!==0;return{nextN:g,offset:l,isZero:B,isNeg:Q,isNegF:u,offsetF:c}}function _T(A,e){if(!Array.isArray(A))throw new Error("array expected");A.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function zT(A,e){if(!Array.isArray(A))throw new Error("array of scalars expected");A.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}const Yu=new WeakMap,Dx=new WeakMap;function Hu(A){return Dx.get(A)||1}function WT(A,e){return{constTimeNegate:Ju,hasPrecomputes(t){return Hu(t)!==1},unsafeLadder(t,n,r=A.ZERO){let s=t;for(;n>k0;)n&wQ&&(r=r.add(s)),s=s.double(),n>>=wQ;return r},precomputeWindow(t,n){const{windows:r,windowSize:s}=qu(n,e),i=[];let a=t,g=a;for(let c=0;c<r;c++){g=a,i.push(g);for(let l=1;l<s;l++)g=g.add(a),i.push(g);a=g.double()}return i},wNAF(t,n,r){let s=A.ZERO,i=A.BASE;const a=qu(t,e);for(let g=0;g<a.windows;g++){const{nextN:c,offset:l,isZero:B,isNeg:Q,isNegF:u,offsetF:d}=M0(r,g,a);r=c,B?i=i.add(Ju(u,n[d])):s=s.add(Ju(Q,n[l]))}return{p:s,f:i}},wNAFUnsafe(t,n,r,s=A.ZERO){const i=qu(t,e);for(let a=0;a<i.windows&&r!==k0;a++){const{nextN:g,offset:c,isZero:l,isNeg:B}=M0(r,a,i);if(r=g,!l){const Q=n[c];s=s.add(B?Q.negate():Q)}}return s},getPrecomputes(t,n,r){let s=Yu.get(n);return s||(s=this.precomputeWindow(n,t),t!==1&&Yu.set(n,r(s))),s},wNAFCached(t,n,r){const s=Hu(t);return this.wNAF(s,this.getPrecomputes(s,t,r),n)},wNAFCachedUnsafe(t,n,r,s){const i=Hu(t);return i===1?this.unsafeLadder(t,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,t,r),n,s)},setWindowSize(t,n){yx(n,e),Dx.set(t,n),Yu.delete(t)}}}function VT(A,e,t,n){_T(t,A),zT(n,e);const r=t.length,s=n.length;if(r!==s)throw new Error("arrays of points and scalars must have equal length");const i=A.ZERO,a=UT(BigInt(r));let g=1;a>12?g=a-3:a>4?g=a-2:a>0&&(g=2);const c=Fl(g),l=new Array(Number(c)+1).fill(i),B=Math.floor((e.BITS-1)/g)*g;let Q=i;for(let u=B;u>=0;u-=g){l.fill(i);for(let f=0;f<s;f++){const h=n[f],x=Number(h>>BigInt(u)&c);l[x]=l[x].add(t[f])}let d=i;for(let f=l.length-1,h=i;f>0;f--)h=h.add(l[f]),d=d.add(h);if(Q=Q.add(d),u!==0)for(let f=0;f<g;f++)Q=Q.double()}return Q}function bx(A){return YT(A.Fp),Gl(A,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...mx(A.n,A.nBitLength),...A,p:A.Fp.ORDER})}function v0(A){A.lowS!==void 0&&ba("lowS",A.lowS),A.prehash!==void 0&&ba("prehash",A.prehash)}function ZT(A){const e=bx(A);Gl(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});const{endo:t,Fp:n,a:r}=e;if(t){if(!n.eql(r,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}class XT extends Error{constructor(e=""){super(e)}}const es={Err:XT,_tlv:{encode:(A,e)=>{const{Err:t}=es;if(A<0||A>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");const n=e.length/2,r=Tg(n);if(r.length/2&128)throw new t("tlv.encode: long form length too big");const s=n>127?Tg(r.length/2|128):"";return Tg(A)+s+r+e},decode(A,e){const{Err:t}=es;let n=0;if(A<0||A>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==A)throw new t("tlv.decode: wrong tlv");const r=e[n++],s=!!(r&128);let i=0;if(!s)i=r;else{const g=r&127;if(!g)throw new t("tlv.decode(long): indefinite length not supported");if(g>4)throw new t("tlv.decode(long): byte length is too big");const c=e.subarray(n,n+g);if(c.length!==g)throw new t("tlv.decode: length bytes not complete");if(c[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(const l of c)i=i<<8|l;if(n+=g,i<128)throw new t("tlv.decode(long): not minimal encoding")}const a=e.subarray(n,n+i);if(a.length!==i)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(A){const{Err:e}=es;if(A<ns)throw new e("integer: negative integers are not allowed");let t=Tg(A);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(A){const{Err:e}=es;if(A[0]&128)throw new e("invalid signature integer: negative");if(A[0]===0&&!(A[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ro(A)}},toSig(A){const{Err:e,_int:t,_tlv:n}=es,r=$n("signature",A),{v:s,l:i}=n.decode(48,r);if(i.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:g}=n.decode(2,s),{v:c,l}=n.decode(2,g);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(c)}},hexFromSig(A){const{_tlv:e,_int:t}=es,n=e.encode(2,t.encode(A.r)),r=e.encode(2,t.encode(A.s)),s=n+r;return e.encode(48,s)}};function Pu(A,e){return Na(lg(A,e))}const ns=BigInt(0),Wt=BigInt(1);BigInt(2);const _u=BigInt(3),$T=BigInt(4);function AL(A){const e=ZT(A),{Fp:t}=e,n=Md(e.n,e.nBitLength),r=e.toBytes||((m,M,G)=>{const Y=M.toAffine();return Gc(Uint8Array.from([4]),t.toBytes(Y.x),t.toBytes(Y.y))}),s=e.fromBytes||(m=>{const M=m.subarray(1),G=t.fromBytes(M.subarray(0,t.BYTES)),Y=t.fromBytes(M.subarray(t.BYTES,2*t.BYTES));return{x:G,y:Y}});function i(m){const{a:M,b:G}=e,Y=t.sqr(m),Z=t.mul(Y,m);return t.add(t.add(Z,t.mul(m,M)),G)}function a(m,M){const G=t.sqr(M),Y=i(m);return t.eql(G,Y)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const g=t.mul(t.pow(e.a,_u),$T),c=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(g,c)))throw new Error("bad curve params: a or b");function l(m){return kd(m,Wt,e.n)}function B(m){const{allowedPrivateKeyLengths:M,nByteLength:G,wrapPrivateKey:Y,n:Z}=e;if(M&&typeof m!="bigint"){if(cg(m)&&(m=Na(m)),typeof m!="string"||!M.includes(m.length))throw new Error("invalid private key");m=m.padStart(G*2,"0")}let P;try{P=typeof m=="bigint"?m:ro($n("private key",m,G))}catch{throw new Error("invalid private key, expected hex or "+G+" bytes, got "+typeof m)}return Y&&(P=vn(P,Z)),$o("private key",P,Wt,Z),P}function Q(m){if(!(m instanceof f))throw new Error("ProjectivePoint expected")}const u=b0((m,M)=>{const{px:G,py:Y,pz:Z}=m;if(t.eql(Z,t.ONE))return{x:G,y:Y};const P=m.is0();M==null&&(M=P?t.ONE:t.inv(Z));const L=t.mul(G,M),q=t.mul(Y,M),v=t.mul(Z,M);if(P)return{x:t.ZERO,y:t.ZERO};if(!t.eql(v,t.ONE))throw new Error("invZ was invalid");return{x:L,y:q}}),d=b0(m=>{if(m.is0()){if(e.allowInfinityPoint&&!t.is0(m.py))return;throw new Error("bad point: ZERO")}const{x:M,y:G}=m.toAffine();if(!t.isValid(M)||!t.isValid(G))throw new Error("bad point: x or y not FE");if(!a(M,G))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class f{constructor(M,G,Y){if(M==null||!t.isValid(M))throw new Error("x required");if(G==null||!t.isValid(G)||t.is0(G))throw new Error("y required");if(Y==null||!t.isValid(Y))throw new Error("z required");this.px=M,this.py=G,this.pz=Y,Object.freeze(this)}static fromAffine(M){const{x:G,y:Y}=M||{};if(!M||!t.isValid(G)||!t.isValid(Y))throw new Error("invalid affine point");if(M instanceof f)throw new Error("projective point not allowed");const Z=P=>t.eql(P,t.ZERO);return Z(G)&&Z(Y)?f.ZERO:new f(G,Y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(M){const G=px(t,M.map(Y=>Y.pz));return M.map((Y,Z)=>Y.toAffine(G[Z])).map(f.fromAffine)}static fromHex(M){const G=f.fromAffine(s($n("pointHex",M)));return G.assertValidity(),G}static fromPrivateKey(M){return f.BASE.multiply(B(M))}static msm(M,G){return VT(f,n,M,G)}_setWindowSize(M){b.setWindowSize(this,M)}assertValidity(){d(this)}hasEvenY(){const{y:M}=this.toAffine();if(t.isOdd)return!t.isOdd(M);throw new Error("Field doesn't support isOdd")}equals(M){Q(M);const{px:G,py:Y,pz:Z}=this,{px:P,py:L,pz:q}=M,v=t.eql(t.mul(G,q),t.mul(P,Z)),U=t.eql(t.mul(Y,q),t.mul(L,Z));return v&&U}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){const{a:M,b:G}=e,Y=t.mul(G,_u),{px:Z,py:P,pz:L}=this;let q=t.ZERO,v=t.ZERO,U=t.ZERO,w=t.mul(Z,Z),E=t.mul(P,P),C=t.mul(L,L),y=t.mul(Z,P);return y=t.add(y,y),U=t.mul(Z,L),U=t.add(U,U),q=t.mul(M,U),v=t.mul(Y,C),v=t.add(q,v),q=t.sub(E,v),v=t.add(E,v),v=t.mul(q,v),q=t.mul(y,q),U=t.mul(Y,U),C=t.mul(M,C),y=t.sub(w,C),y=t.mul(M,y),y=t.add(y,U),U=t.add(w,w),w=t.add(U,w),w=t.add(w,C),w=t.mul(w,y),v=t.add(v,w),C=t.mul(P,L),C=t.add(C,C),w=t.mul(C,y),q=t.sub(q,w),U=t.mul(C,E),U=t.add(U,U),U=t.add(U,U),new f(q,v,U)}add(M){Q(M);const{px:G,py:Y,pz:Z}=this,{px:P,py:L,pz:q}=M;let v=t.ZERO,U=t.ZERO,w=t.ZERO;const E=e.a,C=t.mul(e.b,_u);let y=t.mul(G,P),F=t.mul(Y,L),T=t.mul(Z,q),J=t.add(G,Y),z=t.add(P,L);J=t.mul(J,z),z=t.add(y,F),J=t.sub(J,z),z=t.add(G,Z);let R=t.add(P,q);return z=t.mul(z,R),R=t.add(y,T),z=t.sub(z,R),R=t.add(Y,Z),v=t.add(L,q),R=t.mul(R,v),v=t.add(F,T),R=t.sub(R,v),w=t.mul(E,z),v=t.mul(C,T),w=t.add(v,w),v=t.sub(F,w),w=t.add(F,w),U=t.mul(v,w),F=t.add(y,y),F=t.add(F,y),T=t.mul(E,T),z=t.mul(C,z),F=t.add(F,T),T=t.sub(y,T),T=t.mul(E,T),z=t.add(z,T),y=t.mul(F,z),U=t.add(U,y),y=t.mul(R,z),v=t.mul(J,v),v=t.sub(v,y),y=t.mul(J,F),w=t.mul(R,w),w=t.add(w,y),new f(v,U,w)}subtract(M){return this.add(M.negate())}is0(){return this.equals(f.ZERO)}wNAF(M){return b.wNAFCached(this,M,f.normalizeZ)}multiplyUnsafe(M){const{endo:G,n:Y}=e;$o("scalar",M,ns,Y);const Z=f.ZERO;if(M===ns)return Z;if(this.is0()||M===Wt)return this;if(!G||b.hasPrecomputes(this))return b.wNAFCachedUnsafe(this,M,f.normalizeZ);let{k1neg:P,k1:L,k2neg:q,k2:v}=G.splitScalar(M),U=Z,w=Z,E=this;for(;L>ns||v>ns;)L&Wt&&(U=U.add(E)),v&Wt&&(w=w.add(E)),E=E.double(),L>>=Wt,v>>=Wt;return P&&(U=U.negate()),q&&(w=w.negate()),w=new f(t.mul(w.px,G.beta),w.py,w.pz),U.add(w)}multiply(M){const{endo:G,n:Y}=e;$o("scalar",M,Wt,Y);let Z,P;if(G){const{k1neg:L,k1:q,k2neg:v,k2:U}=G.splitScalar(M);let{p:w,f:E}=this.wNAF(q),{p:C,f:y}=this.wNAF(U);w=b.constTimeNegate(L,w),C=b.constTimeNegate(v,C),C=new f(t.mul(C.px,G.beta),C.py,C.pz),Z=w.add(C),P=E.add(y)}else{const{p:L,f:q}=this.wNAF(M);Z=L,P=q}return f.normalizeZ([Z,P])[0]}multiplyAndAddUnsafe(M,G,Y){const Z=f.BASE,P=(q,v)=>v===ns||v===Wt||!q.equals(Z)?q.multiplyUnsafe(v):q.multiply(v),L=P(this,G).add(P(M,Y));return L.is0()?void 0:L}toAffine(M){return u(this,M)}isTorsionFree(){const{h:M,isTorsionFree:G}=e;if(M===Wt)return!0;if(G)return G(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:M,clearCofactor:G}=e;return M===Wt?this:G?G(f,this):this.multiplyUnsafe(e.h)}toRawBytes(M=!0){return ba("isCompressed",M),this.assertValidity(),r(f,this,M)}toHex(M=!0){return ba("isCompressed",M),Na(this.toRawBytes(M))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);const{endo:h,nBitLength:x}=e,b=WT(f,h?Math.ceil(x/2):x);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:B,weierstrassEquation:i,isWithinCurveOrder:l}}function eL(A){const e=bx(A);return Gl(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function tL(A){const e=eL(A),{Fp:t,n,nByteLength:r,nBitLength:s}=e,i=t.BYTES+1,a=2*t.BYTES+1;function g(C){return vn(C,n)}function c(C){return mQ(C,n)}const{ProjectivePoint:l,normPrivateKeyToScalar:B,weierstrassEquation:Q,isWithinCurveOrder:u}=AL({...e,toBytes(C,y,F){const T=y.toAffine(),J=t.toBytes(T.x),z=Gc;return ba("isCompressed",F),F?z(Uint8Array.from([y.hasEvenY()?2:3]),J):z(Uint8Array.from([4]),J,t.toBytes(T.y))},fromBytes(C){const y=C.length,F=C[0],T=C.subarray(1);if(y===i&&(F===2||F===3)){const J=ro(T);if(!kd(J,Wt,t.ORDER))throw new Error("Point is not on curve");const z=Q(J);let R;try{R=t.sqrt(z)}catch(K){const j=K instanceof Error?": "+K.message:"";throw new Error("Point is not on curve"+j)}const I=(R&Wt)===Wt;return(F&1)===1!==I&&(R=t.neg(R)),{x:J,y:R}}else if(y===a&&F===4){const J=t.fromBytes(T.subarray(0,t.BYTES)),z=t.fromBytes(T.subarray(t.BYTES,2*t.BYTES));return{x:J,y:z}}else{const J=i,z=a;throw new Error("invalid Point, expected length of "+J+", or uncompressed "+z+", got "+y)}}});function d(C){const y=n>>Wt;return C>y}function f(C){return d(C)?g(-C):C}const h=(C,y,F)=>ro(C.slice(y,F));class x{constructor(y,F,T){$o("r",y,Wt,n),$o("s",F,Wt,n),this.r=y,this.s=F,T!=null&&(this.recovery=T),Object.freeze(this)}static fromCompact(y){const F=r;return y=$n("compactSignature",y,F*2),new x(h(y,0,F),h(y,F,2*F))}static fromDER(y){const{r:F,s:T}=es.toSig($n("DER",y));return new x(F,T)}assertValidity(){}addRecoveryBit(y){return new x(this.r,this.s,y)}recoverPublicKey(y){const{r:F,s:T,recovery:J}=this,z=Z($n("msgHash",y));if(J==null||![0,1,2,3].includes(J))throw new Error("recovery id invalid");const R=J===2||J===3?F+e.n:F;if(R>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const I=(J&1)===0?"02":"03",p=l.fromHex(I+Pu(R,t.BYTES)),K=c(R),j=g(-z*K),$=g(T*K),eA=l.BASE.multiplyAndAddUnsafe(p,j,$);if(!eA)throw new Error("point at infinify");return eA.assertValidity(),eA}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,g(-this.s),this.recovery):this}toDERRawBytes(){return Fc(this.toDERHex())}toDERHex(){return es.hexFromSig(this)}toCompactRawBytes(){return Fc(this.toCompactHex())}toCompactHex(){const y=r;return Pu(this.r,y)+Pu(this.s,y)}}const b={isValidPrivateKey(C){try{return B(C),!0}catch{return!1}},normPrivateKeyToScalar:B,randomPrivateKey:()=>{const C=xx(e.n);return PT(e.randomBytes(C),e.n)},precompute(C=8,y=l.BASE){return y._setWindowSize(C),y.multiply(BigInt(3)),y}};function m(C,y=!0){return l.fromPrivateKey(C).toRawBytes(y)}function M(C){if(typeof C=="bigint")return!1;if(C instanceof l)return!0;const F=$n("key",C).length,T=t.BYTES,J=T+1,z=2*T+1;if(!(e.allowedPrivateKeyLengths||r===J))return F===J||F===z}function G(C,y,F=!0){if(M(C)===!0)throw new Error("first arg must be private key");if(M(y)===!1)throw new Error("second arg must be public key");return l.fromHex(y).multiply(B(C)).toRawBytes(F)}const Y=e.bits2int||function(C){if(C.length>8192)throw new Error("input is too large");const y=ro(C),F=C.length*8-s;return F>0?y>>BigInt(F):y},Z=e.bits2int_modN||function(C){return g(Y(C))},P=Fl(s);function L(C){return $o("num < 2^"+s,C,ns,P),lg(C,r)}function q(C,y,F=v){if(["recovered","canonical"].some(aA=>aA in F))throw new Error("sign() legacy options not supported");const{hash:T,randomBytes:J}=e;let{lowS:z,prehash:R,extraEntropy:I}=F;z==null&&(z=!0),C=$n("msgHash",C),v0(F),R&&(C=$n("prehashed msgHash",T(C)));const p=Z(C),K=B(y),j=[L(K),L(p)];if(I!=null&&I!==!1){const aA=I===!0?J(t.BYTES):I;j.push($n("extraEntropy",aA))}const $=Gc(...j),eA=p;function CA(aA){const LA=Y(aA);if(!u(LA))return;const ZA=c(LA),EA=l.BASE.multiply(LA).toAffine(),VA=g(EA.x);if(VA===ns)return;const oe=g(ZA*g(eA+VA*K));if(oe===ns)return;let Qe=(EA.x===VA?0:2)|Number(EA.y&Wt),vA=oe;return z&&d(oe)&&(vA=f(oe),Qe^=1),new x(VA,vA,Qe)}return{seed:$,k2sig:CA}}const v={lowS:e.lowS,prehash:!1},U={lowS:e.lowS,prehash:!1};function w(C,y,F=v){const{seed:T,k2sig:J}=q(C,y,F),z=e;return TT(z.hash.outputLen,z.nByteLength,z.hmac)(T,J)}l.BASE._setWindowSize(8);function E(C,y,F,T=U){const J=C;y=$n("msgHash",y),F=$n("publicKey",F);const{lowS:z,prehash:R,format:I}=T;if(v0(T),"strict"in T)throw new Error("options.strict was renamed to lowS");if(I!==void 0&&I!=="compact"&&I!=="der")throw new Error("format must be compact or der");const p=typeof J=="string"||cg(J),K=!p&&!I&&typeof J=="object"&&J!==null&&typeof J.r=="bigint"&&typeof J.s=="bigint";if(!p&&!K)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let j,$;try{if(K&&(j=new x(J.r,J.s)),p){try{I!=="compact"&&(j=x.fromDER(J))}catch(Qe){if(!(Qe instanceof es.Err))throw Qe}!j&&I!=="der"&&(j=x.fromCompact(J))}$=l.fromHex(F)}catch{return!1}if(!j||z&&j.hasHighS())return!1;R&&(y=e.hash(y));const{r:eA,s:CA}=j,aA=Z(y),LA=c(CA),ZA=g(aA*LA),EA=g(eA*LA),VA=l.BASE.multiplyAndAddUnsafe($,ZA,EA)?.toAffine();return VA?g(VA.x)===eA:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:G,sign:w,verify:E,ProjectivePoint:l,Signature:x,utils:b}}function nL(A){return{hash:A,hmac:(e,...t)=>ME(A,e,cr(...t)),randomBytes:rl}}function rL(A,e){const t=n=>tL({...A,...nL(n)});return{...t(e),create:t}}const Nx=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),S0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),sL=BigInt(0),oL=BigInt(1),xQ=BigInt(2),F0=(A,e)=>(A+e/xQ)/e;function iL(A){const e=Nx,t=BigInt(3),n=BigInt(6),r=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),g=BigInt(88),c=A*A*A%e,l=c*c*A%e,B=Xn(l,t,e)*l%e,Q=Xn(B,t,e)*l%e,u=Xn(Q,xQ,e)*c%e,d=Xn(u,r,e)*u%e,f=Xn(d,s,e)*d%e,h=Xn(f,a,e)*f%e,x=Xn(h,g,e)*h%e,b=Xn(x,a,e)*f%e,m=Xn(b,t,e)*l%e,M=Xn(m,i,e)*d%e,G=Xn(M,n,e)*c%e,Y=Xn(G,xQ,e);if(!yQ.eql(yQ.sqr(Y),A))throw new Error("Cannot find square root");return Y}const yQ=Md(Nx,void 0,void 0,{sqrt:iL}),Rl=rL({a:sL,b:BigInt(7),Fp:yQ,n:S0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:A=>{const e=S0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-oL*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),r=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=t,i=BigInt("0x100000000000000000000000000000000"),a=F0(s*A,e),g=F0(-n*A,e);let c=vn(A-a*t-g*r,e),l=vn(-a*n-g*s,e);const B=c>i,Q=l>i;if(B&&(c=e-c),Q&&(l=e-l),c>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+A);return{k1neg:B,k1:c,k2neg:Q,k2:l}}}},hE),aL=Object.freeze(Object.defineProperty({__proto__:null,secp256k1:Rl},Symbol.toStringTag,{value:"Module"}));function kx({r:A,s:e,to:t="hex",v:n,yParity:r}){const s=(()=>{if(r===0||r===1)return r;if(n&&(n===27n||n===28n||n>=35n))return n%2n===0n?1:0;throw new Error("Invalid `v` or `yParity` value")})(),i=`0x${new Rl.Signature(ot(A),ot(e)).toCompactHex()}${s===0?"1b":"1c"}`;return t==="hex"?i:Tn(i)}async function Ul(A,e){const{address:t,chain:n=A.chain,hash:r,erc6492VerifierAddress:s=e.universalSignatureVerifierAddress??n?.contracts?.erc6492Verifier?.address,multicallAddress:i=e.multicallAddress??n?.contracts?.multicall3?.address}=e;if(n?.verifyHash)return await n.verifyHash(A,e);const a=(()=>{const g=e.signature;return Ir(g)?g:typeof g=="object"&&"r"in g&&"s"in g?kx(g):qt(g)})();try{return BT(a)?await gL(A,{...e,multicallAddress:i,signature:a}):await cL(A,{...e,verifierAddress:s,signature:a})}catch(g){try{if(tg(Cl(t),await Pm({hash:r,signature:a})))return!0}catch{}if(g instanceof mo)return!1;throw g}}async function gL(A,e){const{address:t,blockNumber:n,blockTag:r,hash:s,multicallAddress:i}=e,{authorization:a,data:g,signature:c,to:l}=uT(e.signature);if(await vc(A,{address:t,blockNumber:n,blockTag:r})===ir(["0xef0100",a.address]))return await lL(A,{address:t,blockNumber:n,blockTag:r,hash:s,signature:c});const Q={address:a.address,chainId:Number(a.chainId),nonce:Number(a.nonce),r:NA(a.r,{size:32}),s:NA(a.s,{size:32}),yParity:a.yParity};if(!await rU({address:t,authorization:Q}))throw new mo;const d=await qA(A,mr,"readContract")({...i?{address:i}:{code:gd},authorizationList:[Q],abi:Qi,blockNumber:n,blockTag:"pending",functionName:"aggregate3",args:[[...g?[{allowFailure:!0,target:l??t,callData:g}]:[],{allowFailure:!0,target:t,callData:mn({abi:yw,functionName:"isValidSignature",args:[s,c]})}]]});if(d[d.length-1]?.returnData?.startsWith("0x1626ba7e"))return!0;throw new mo}async function cL(A,e){const{address:t,factory:n,factoryData:r,hash:s,signature:i,verifierAddress:a,...g}=e,c=await(async()=>!n&&!r||FT(i)?i:ST({data:r,signature:i,to:n}))(),l=a?{to:a,data:mn({abi:Q0,functionName:"isValidSig",args:[t,s,c]}),...g}:{data:yl({abi:Q0,args:[t,s,c],bytecode:XG}),...g},{data:B}=await qA(A,sg,"call")(l).catch(Q=>{throw Q instanceof qm?new mo:Q});if(A6(B??"0x0"))return!0;throw new mo}async function lL(A,e){const{address:t,blockNumber:n,blockTag:r,hash:s,signature:i}=e;if((await qA(A,mr,"readContract")({address:t,abi:yw,args:[s,i],blockNumber:n,blockTag:r,functionName:"isValidSignature"}).catch(g=>{throw g instanceof Ym?new mo:g})).startsWith("0x1626ba7e"))return!0;throw new mo}class mo extends Error{}async function uL(A,{address:e,message:t,factory:n,factoryData:r,signature:s,...i}){const a=Id(t);return qA(A,Ul,"verifyHash")({address:e,factory:n,factoryData:r,hash:a,signature:s,...i})}async function BL(A,e){const{address:t,factory:n,factoryData:r,signature:s,message:i,primaryType:a,types:g,domain:c,...l}=e,B=Ww({message:i,primaryType:a,types:g,domain:c});return qA(A,Ul,"verifyHash")({address:t,factory:n,factoryData:r,hash:B,signature:s,...l})}function Mx(A,{emitOnBegin:e=!1,emitMissed:t=!1,onBlockNumber:n,onError:r,poll:s,pollingInterval:i=A.pollingInterval}){const a=typeof s<"u"?s:!(A.transport.type==="webSocket"||A.transport.type==="ipc"||A.transport.type==="fallback"&&(A.transport.transports[0].config.type==="webSocket"||A.transport.transports[0].config.type==="ipc"));let g;return a?(()=>{const B=_t(["watchBlockNumber",A.uid,e,t,i]);return Es(B,{onBlockNumber:n,onError:r},Q=>vi(async()=>{try{const u=await qA(A,og,"getBlockNumber")({cacheTime:0});if(g!==void 0){if(u===g)return;if(u-g>1&&t)for(let d=g+1n;d<u;d++)Q.onBlockNumber(d,g),g=d}(g===void 0||u>g)&&(Q.onBlockNumber(u,g),g=u)}catch(u){Q.onError?.(u)}},{emitOnBegin:e,interval:i}))})():(()=>{const B=_t(["watchBlockNumber",A.uid,e,t]);return Es(B,{onBlockNumber:n,onError:r},Q=>{let u=!0,d=()=>u=!1;return(async()=>{try{const f=(()=>{if(A.transport.type==="fallback"){const x=A.transport.transports.find(b=>b.config.type==="webSocket"||b.config.type==="ipc");return x?x.value:A.transport}return A.transport})(),{unsubscribe:h}=await f.subscribe({params:["newHeads"],onData(x){if(!u)return;const b=ot(x.result?.number);Q.onBlockNumber(b,g),g=b},onError(x){Q.onError?.(x)}});d=h,u||d()}catch(f){r?.(f)}})(),()=>d()})})()}async function vx(A,e){const{checkReplacement:t=!0,confirmations:n=1,hash:r,onReplaced:s,retryCount:i=6,retryDelay:a=({count:G})=>~~(1<<G)*200,timeout:g=18e4}=e,c=_t(["waitForTransactionReceipt",A.uid,r]),l=e.pollingInterval?e.pollingInterval:A.chain?.experimental_preconfirmationTime?A.chain.experimental_preconfirmationTime:A.pollingInterval;let B,Q,u,d=!1,f,h;const{promise:x,resolve:b,reject:m}=cd(),M=g?setTimeout(()=>{h?.(),f?.(),m(new P6({hash:r}))},g):void 0;return f=Es(c,{onReplaced:s,resolve:b,reject:m},async G=>{if(u=await qA(A,Vg,"getTransactionReceipt")({hash:r}).catch(()=>{}),u&&n<=1){clearTimeout(M),G.resolve(u),f?.();return}h=qA(A,Mx,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:l,async onBlockNumber(Y){const Z=L=>{clearTimeout(M),h?.(),L(),f?.()};let P=Y;if(!d)try{if(u){if(n>1&&(!u.blockNumber||P-u.blockNumber+1n<n))return;Z(()=>G.resolve(u));return}if(t&&!B&&(d=!0,await Mc(async()=>{B=await qA(A,Dd,"getTransaction")({hash:r}),B.blockNumber&&(P=B.blockNumber)},{delay:a,retryCount:i}),d=!1),u=await qA(A,Vg,"getTransactionReceipt")({hash:r}),n>1&&(!u.blockNumber||P-u.blockNumber+1n<n))return;Z(()=>G.resolve(u))}catch(L){if(L instanceof Km||L instanceof jm){if(!B){d=!1;return}try{Q=B,d=!0;const q=await Mc(()=>qA(A,ur,"getBlock")({blockNumber:P,includeTransactions:!0}),{delay:a,retryCount:i,shouldRetry:({error:w})=>w instanceof Zm});d=!1;const v=q.transactions.find(({from:w,nonce:E})=>w===Q.from&&E===Q.nonce);if(!v||(u=await qA(A,Vg,"getTransactionReceipt")({hash:v.hash}),n>1&&(!u.blockNumber||P-u.blockNumber+1n<n)))return;let U="replaced";v.to===Q.to&&v.value===Q.value&&v.input===Q.input?U="repriced":v.from===v.to&&v.value===0n&&(U="cancelled"),Z(()=>{G.onReplaced?.({reason:U,replacedTransaction:Q,transaction:v,transactionReceipt:u}),G.resolve(u)})}catch(q){Z(()=>G.reject(q))}}else Z(()=>G.reject(L))}}})}),x}function QL(A,{blockTag:e=A.experimental_blockTag??"latest",emitMissed:t=!1,emitOnBegin:n=!1,onBlock:r,onError:s,includeTransactions:i,poll:a,pollingInterval:g=A.pollingInterval}){const c=typeof a<"u"?a:!(A.transport.type==="webSocket"||A.transport.type==="ipc"||A.transport.type==="fallback"&&(A.transport.transports[0].config.type==="webSocket"||A.transport.transports[0].config.type==="ipc")),l=i??!1;let B;return c?(()=>{const d=_t(["watchBlocks",A.uid,e,t,n,l,g]);return Es(d,{onBlock:r,onError:s},f=>vi(async()=>{try{const h=await qA(A,ur,"getBlock")({blockTag:e,includeTransactions:l});if(h.number!==null&&B?.number!=null){if(h.number===B.number)return;if(h.number-B.number>1&&t)for(let x=B?.number+1n;x<h.number;x++){const b=await qA(A,ur,"getBlock")({blockNumber:x,includeTransactions:l});f.onBlock(b,B),B=b}}(B?.number==null||e==="pending"&&h?.number==null||h.number!==null&&h.number>B.number)&&(f.onBlock(h,B),B=h)}catch(h){f.onError?.(h)}},{emitOnBegin:n,interval:g}))})():(()=>{let d=!0,f=!0,h=()=>d=!1;return(async()=>{try{n&&qA(A,ur,"getBlock")({blockTag:e,includeTransactions:l}).then(m=>{d&&f&&(r(m,void 0),f=!1)}).catch(s);const x=(()=>{if(A.transport.type==="fallback"){const m=A.transport.transports.find(M=>M.config.type==="webSocket"||M.config.type==="ipc");return m?m.value:A.transport}return A.transport})(),{unsubscribe:b}=await x.subscribe({params:["newHeads"],async onData(m){if(!d)return;const M=await qA(A,ur,"getBlock")({blockNumber:m.result?.number,includeTransactions:l}).catch(()=>{});d&&(r(M,B),f=!1,B=M)},onError(m){s?.(m)}});h=b,d||h()}catch(x){s?.(x)}})(),()=>h()})()}function EL(A,{address:e,args:t,batch:n=!0,event:r,events:s,fromBlock:i,onError:a,onLogs:g,poll:c,pollingInterval:l=A.pollingInterval,strict:B}){const Q=typeof c<"u"?c:typeof i=="bigint"?!0:!(A.transport.type==="webSocket"||A.transport.type==="ipc"||A.transport.type==="fallback"&&(A.transport.transports[0].config.type==="webSocket"||A.transport.transports[0].config.type==="ipc")),u=B??!1;return Q?(()=>{const h=_t(["watchEvent",e,t,n,A.uid,r,l,i]);return Es(h,{onLogs:g,onError:a},x=>{let b;i!==void 0&&(b=i-1n);let m,M=!1;const G=vi(async()=>{if(!M){try{m=await qA(A,Hw,"createEventFilter")({address:e,args:t,event:r,events:s,strict:u,fromBlock:i})}catch{}M=!0;return}try{let Y;if(m)Y=await qA(A,Dl,"getFilterChanges")({filter:m});else{const Z=await qA(A,og,"getBlockNumber")({});b&&b!==Z?Y=await qA(A,id,"getLogs")({address:e,args:t,event:r,events:s,fromBlock:b+1n,toBlock:Z}):Y=[],b=Z}if(Y.length===0)return;if(n)x.onLogs(Y);else for(const Z of Y)x.onLogs([Z])}catch(Y){m&&Y instanceof Fs&&(M=!1),x.onError?.(Y)}},{emitOnBegin:!0,interval:l});return async()=>{m&&await qA(A,bl,"uninstallFilter")({filter:m}),G()}})})():(()=>{let h=!0,x=()=>h=!1;return(async()=>{try{const b=(()=>{if(A.transport.type==="fallback"){const Y=A.transport.transports.find(Z=>Z.config.type==="webSocket"||Z.config.type==="ipc");return Y?Y.value:A.transport}return A.transport})(),m=s??(r?[r]:void 0);let M=[];m&&(M=[m.flatMap(Z=>Va({abi:[Z],eventName:Z.name,args:t}))],r&&(M=M[0]));const{unsubscribe:G}=await b.subscribe({params:["logs",{address:e,topics:M}],onData(Y){if(!h)return;const Z=Y.result;try{const{eventName:P,args:L}=kc({abi:m??[],data:Z.data,topics:Z.topics,strict:u}),q=fr(Z,{args:L,eventName:P});g([q])}catch(P){let L,q;if(P instanceof Nc||P instanceof KE){if(B)return;L=P.abiItem.name,q=P.abiItem.inputs?.some(U=>!("name"in U&&U.name))}const v=fr(Z,{args:q?[]:{},eventName:L});g([v])}},onError(Y){a?.(Y)}});x=G,h||x()}catch(b){a?.(b)}})(),()=>x()})()}function dL(A,{batch:e=!0,onError:t,onTransactions:n,poll:r,pollingInterval:s=A.pollingInterval}){return(typeof r<"u"?r:A.transport.type!=="webSocket"&&A.transport.type!=="ipc")?(()=>{const c=_t(["watchPendingTransactions",A.uid,e,s]);return Es(c,{onTransactions:n,onError:t},l=>{let B;const Q=vi(async()=>{try{if(!B)try{B=await qA(A,Pw,"createPendingTransactionFilter")({});return}catch(d){throw Q(),d}const u=await qA(A,Dl,"getFilterChanges")({filter:B});if(u.length===0)return;if(e)l.onTransactions(u);else for(const d of u)l.onTransactions([d])}catch(u){l.onError?.(u)}},{emitOnBegin:!0,interval:s});return async()=>{B&&await qA(A,bl,"uninstallFilter")({filter:B}),Q()}})})():(()=>{let c=!0,l=()=>c=!1;return(async()=>{try{const{unsubscribe:B}=await A.transport.subscribe({params:["newPendingTransactions"],onData(Q){if(!c)return;const u=Q.result;n([u])},onError(Q){t?.(Q)}});l=B,c||l()}catch(B){t?.(B)}})(),()=>l()})()}function CL(A){const{scheme:e,statement:t,...n}=A.match(IL)?.groups??{},{chainId:r,expirationTime:s,issuedAt:i,notBefore:a,requestId:g,...c}=A.match(fL)?.groups??{},l=A.split("Resources:")[1]?.split(`
@@ -179,4 +179,4 @@ ${f.map(h=>`+${h}`).join(`
179
179
  `)}`}return u?/@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@/.test(u)?u:wY(u):null},[l,t]);if(k.useEffect(()=>{if(e&&!c.current){const{isCollapsed:u}=xo.getState();g.current=u,a(!0)}else!e&&c.current&&g.current!==null&&(a(g.current),g.current=null);c.current=e},[e,a]),k.useEffect(()=>{const u=d=>{const f=d.target,h=f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.isContentEditable;(d.key==="Escape"||d.key==="q"&&!h)&&e&&i(),!h&&e&&n.length>1&&(d.key==="ArrowLeft"||d.key==="["?(d.preventDefault(),s(Math.max(0,r-1))):(d.key==="ArrowRight"||d.key==="]")&&(d.preventDefault(),s(Math.min(n.length-1,r+1))))};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[e,i,n.length,r,s]),!e||!t||!l)return null;const Q=n.length>1;return o.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[o.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3 shrink-0",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:i,title:"Close diff viewer (ESC)",children:o.jsx(yt,{className:"w-4 h-4"})}),o.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:t,children:t}),o.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-primary/10 text-primary flex-shrink-0 capitalize",children:l.operation}),l.artifact?.summary&&o.jsxs("div",{className:"flex items-center gap-1 text-xs flex-shrink-0",children:[o.jsxs("span",{className:"text-green-500",children:["+",l.artifact.summary.additions]}),o.jsxs("span",{className:"text-red-500",children:["-",l.artifact.summary.deletions]})]})]}),Q&&o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>s(Math.max(0,r-1)),disabled:r===0,title:"Previous operation (←)",children:o.jsx(J1,{className:"w-4 h-4"})}),o.jsxs("span",{className:"text-xs text-muted-foreground min-w-[60px] text-center",children:[r+1," / ",n.length]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>s(Math.min(n.length-1,r+1)),disabled:r===n.length-1,title:"Next operation (→)",children:o.jsx(Dt,{className:"w-4 h-4"})})]})]}),Q&&o.jsx("div",{className:"border-b border-border px-4 py-2 flex gap-2 overflow-x-auto shrink-0",children:n.map((u,d)=>o.jsxs("button",{type:"button",onClick:()=>s(d),className:`px-3 py-1.5 text-xs rounded-md flex items-center gap-2 shrink-0 transition-colors ${d===r?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80 text-muted-foreground"}`,children:[o.jsx("span",{className:"capitalize",children:u.operation}),o.jsx("span",{className:"opacity-70",children:bY(u.timestamp)}),u.artifact?.summary&&o.jsxs("span",{className:"opacity-70",children:["+",u.artifact.summary.additions,"/-",u.artifact.summary.deletions]})]},u.toolCallId))}),o.jsx("div",{className:"flex-1 overflow-hidden p-4",children:B?o.jsx(DY,{patch:B}):o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"No diff content available"})})]})}),kY={};class MY{get baseUrl(){const e=window;if(e.OTTO_SERVER_URL)return e.OTTO_SERVER_URL;if(!kY?.VITE_API_BASE_URL)return Rs}async listResearchSessions(e){const t=await fetch(`${this.baseUrl}/v1/sessions/${e}/research`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok){const n=await t.json().catch(()=>({error:"Failed to fetch research sessions"}));throw new Error(n.error||"Failed to fetch research sessions")}return t.json()}async createResearchSession(e,t){const n=await fetch(`${this.baseUrl}/v1/sessions/${e}/research`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to create research session"}));throw new Error(r.error||"Failed to create research session")}return n.json()}async deleteResearchSession(e){const t=await fetch(`${this.baseUrl}/v1/research/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"}});if(!t.ok){const n=await t.json().catch(()=>({error:"Failed to delete research session"}));throw new Error(n.error||"Failed to delete research session")}return t.json()}async injectContext(e,t,n){const r=await fetch(`${this.baseUrl}/v1/sessions/${e}/inject`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({researchSessionId:t,label:n})});if(!r.ok){const s=await r.json().catch(()=>({error:"Failed to inject context"}));throw new Error(s.error||"Failed to inject context")}return r.json()}async exportToNewSession(e,t){const n=await fetch(`${this.baseUrl}/v1/research/${e}/export`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to export to session"}));throw new Error(r.error||"Failed to export to session")}return n.json()}}const Yl=new MY;function Hy(A,e=!0){return bt({queryKey:["research","sessions",A],queryFn:()=>Yl.listResearchSessions(A),enabled:!!A&&e,staleTime:3e4})}function vY(){const A=Ye();return it({mutationFn:({parentSessionId:e,data:t})=>Yl.createResearchSession(e,t??{}),onSuccess:(e,{parentSessionId:t})=>{A.invalidateQueries({queryKey:["research","sessions",t]})}})}function SY(){const A=Pg(e=>e.addContext);return it({mutationFn:({parentSessionId:e,researchSessionId:t,label:n})=>Yl.injectContext(e,t,n),onSuccess:(e,{parentSessionId:t})=>{A(t,{id:e.sessionId,sessionId:e.sessionId,label:e.label,content:e.content})}})}function FY(){const A=Ye();return it({mutationFn:({researchId:e,data:t})=>Yl.exportToNewSession(e,t),onSuccess:()=>{A.invalidateQueries({queryKey:Ur})}})}const lf="research",uf=384,GY=384,RY=640,UY=k.memo(function({parentSessionId:e,onNavigateToSession:t}){const n=Tt(EA=>EA.isExpanded),r=Tt(EA=>EA.collapseSidebar),s=ks(EA=>EA.widths[lf]??uf),i=Tt(EA=>EA.activeResearchSessionId),a=Tt(EA=>EA.selectResearchSession),[g,c]=k.useState(!1),[l,B]=k.useState(""),[Q,u]=k.useState(!1),[d,f]=k.useState("idle"),h=k.useRef(null),x=k.useRef(null),{data:b,isLoading:m,refetch:M}=Hy(e,n),G=vY(),Y=SY(),Z=FY(),{data:P}=La(),{data:L}=kB(i??void 0,{enabled:n}),{data:q}=kB(e??void 0,{enabled:n});Jy(i??void 0,n);const v=lE(i??""),U=Ye(),w=it({mutationFn:async({sessionId:EA,content:VA})=>xA.sendMessage(EA,{content:VA}),onSuccess:(EA,{sessionId:VA})=>{U.invalidateQueries({queryKey:["messages",VA]})}});k.useEffect(()=>{e&&Tt.getState().setParentSessionId(e)},[e]),k.useEffect(()=>{b?.sessions?.length?b.sessions.some(VA=>VA.id===i)||a(b.sessions[0].id):b?.sessions?.length===0&&a(null)},[b,i,a]),k.useEffect(()=>{x.current?.scrollIntoView({behavior:"smooth"})},[]);const E=k.useCallback(()=>{const EA=h.current;EA&&(EA.style.height="auto",EA.style.height=`${Math.min(EA.scrollHeight,120)}px`)},[]);k.useEffect(()=>{E()},[E]);const C=k.useCallback(async()=>{if(e)try{const EA=await G.mutateAsync({parentSessionId:e,data:{}});await M(),a(EA.session.id),c(!1)}catch(EA){console.error("Failed to create research session:",EA)}},[e,G,a,M]),y=k.useCallback(EA=>{a(EA.id),c(!1)},[a]),F=k.useCallback(async()=>{if(!e||!i)return;if(q?.some(vA=>vA.role==="system"&&vA.parts?.some(JA=>typeof JA.content=="string"&&JA.content.includes(`from="${i}"`)))){f("error"),setTimeout(()=>f("idle"),3e3);return}const Qe=`Research ${new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`;try{await Y.mutateAsync({parentSessionId:e,researchSessionId:i,label:Qe}),f("success"),setTimeout(()=>f("idle"),5e3),U.invalidateQueries({queryKey:["messages",e]})}catch(vA){console.error("Failed to inject context:",vA),f("error"),setTimeout(()=>f("idle"),3e3)}},[e,i,Y,q,U]),T=k.useCallback(async()=>{if(i)try{const EA=await Z.mutateAsync({researchId:i});t&&EA.newSession?.id&&t(EA.newSession.id)}catch(EA){console.error("Failed to export to session:",EA)}},[i,Z,t]),J=k.useCallback(async()=>{if(!(!l.trim()||!e))try{let EA=i;EA||(EA=(await G.mutateAsync({parentSessionId:e,data:{}})).session.id,a(EA)),await w.mutateAsync({sessionId:EA,content:l}),B(""),h.current&&(h.current.style.height="auto")}catch(EA){console.error("Failed to send message:",EA)}},[l,e,i,G,a,w]),z=k.useCallback(EA=>{EA.key==="Enter"&&!EA.shiftKey&&(EA.preventDefault(),J())},[J]),R=k.useMemo(()=>L?.some(EA=>EA.role==="assistant"&&EA.status==="pending")??!1,[L]),I=k.useMemo(()=>!i||!q?!1:q.some(EA=>EA.role==="system"&&EA.parts?.some(VA=>typeof VA.content=="string"&&VA.content.includes(`from="${i}"`))),[i,q]),p=k.useCallback(async(EA,VA)=>{if(!i){u(!1);return}try{await v.mutateAsync({provider:EA,model:VA}),await U.invalidateQueries({queryKey:["research","sessions",e]}),u(!1)}catch(oe){console.error("Failed to update research session model:",oe)}},[i,v,U,e]),K=cE(e??"");if(!n)return null;const j=b?.sessions??[],$=j.find(EA=>EA.id===i),eA=L??[],CA=$?.provider??K?.provider??"",aA=$?.model??K?.model??"",LA=P?.[CA]?.label??CA,ZA=P?.[CA]?.models.find(EA=>EA.id===aA)?.label??aA;return o.jsxs("div",{className:"border-l border-sidebar-border sidebar-fade-in flex h-full relative",style:{width:s},children:[o.jsx(fi,{panelKey:lf,side:"right",minWidth:GY,maxWidth:RY,defaultWidth:uf}),o.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[o.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[o.jsx($i,{className:"w-4 h-4 text-teal-500"}),o.jsx("span",{className:"font-medium text-foreground text-sm",children:"Research"})]}),o.jsxs("div",{className:"flex items-center gap-0.5",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>c(!g),title:"Research history",className:"h-8 w-8",children:o.jsx(q1,{className:"w-4 h-4"})}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:C,disabled:!e||G.isPending,title:"New research session",className:"h-8 w-8",children:G.isPending?o.jsx($e,{className:"w-4 h-4 animate-spin"}):o.jsx(Qr,{className:"w-4 h-4"})}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:r,title:"Close sidebar",className:"h-8 w-8",children:o.jsx(Dt,{className:"w-4 h-4"})})]})]}),g?o.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o.jsx("div",{className:"p-2 border-b border-border",children:o.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Research Sessions"})}),m?o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading..."}):j.length===0?o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No research sessions yet"}):o.jsx("div",{className:"p-2 space-y-1",children:j.map(EA=>o.jsxs("button",{type:"button",onClick:()=>y(EA),className:`w-full text-left p-2 rounded-md text-sm transition-colors ${EA.id===i?"bg-teal-500/10 border border-teal-500/30 text-foreground":"hover:bg-muted"}`,children:[o.jsx("div",{className:"font-medium truncate",children:EA.title||"Untitled"}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[EA.messageCount," messages •"," ",TY(EA.lastActiveAt??EA.createdAt)]})]},EA.id))})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3 research-messages text-[13px]",children:i?eA.length===0?o.jsx("div",{className:"text-xs text-muted-foreground text-center py-8",children:o.jsx("p",{children:"Ask a question to start researching."})}):o.jsxs("div",{className:"space-y-1.5",children:[eA.map((EA,VA)=>{if(EA.role==="user"){const oe=eA[VA+1];return o.jsx(_h,{sessionId:i,message:EA,isFirst:VA===0,nextAssistantMessageId:oe?.role==="assistant"?oe.id:void 0},EA.id)}if(EA.role==="assistant"){const oe=VA>0?eA[VA-1]:null,Qe=eA[VA+1],vA=oe?.role!=="assistant",JA=Qe?.role==="assistant";return o.jsx(Ph,{sessionId:i,message:EA,showHeader:vA,hasNextAssistantMessage:JA,isLastMessage:VA===eA.length-1,compact:!0,onNavigateToSession:t},EA.id)}return null}),o.jsx("div",{ref:x})]}):o.jsxs("div",{className:"text-xs text-muted-foreground text-center py-8",children:[o.jsx($i,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground/50"}),o.jsx("p",{children:"Start researching by asking a question below."})]})}),o.jsxs("div",{className:"p-3 border-t border-border",children:[o.jsx("div",{className:"relative flex flex-col rounded-3xl bg-card border border-border focus-within:border-teal-500/60 focus-within:ring-1 focus-within:ring-teal-500/40 p-1",children:o.jsxs("div",{className:"flex items-end gap-1",children:[o.jsx(Xc,{ref:h,value:l,onChange:EA=>B(EA.target.value),onKeyDown:z,placeholder:"Ask anything...",disabled:!e||w.isPending||G.isPending,rows:1,className:"flex-1 border-0 bg-transparent pl-2 pr-1 py-2 max-h-[120px] overflow-y-auto leading-normal resize-none scrollbar-hide text-sm focus:ring-0 focus:outline-none",style:{height:"2.25rem"}}),o.jsx("button",{type:"button",onClick:J,disabled:!l.trim()||!e||w.isPending||G.isPending||R,className:`flex items-center justify-center w-9 h-9 rounded-full transition-colors flex-shrink-0 ${l.trim()&&e&&!R?"bg-teal-500 hover:bg-teal-600 text-white":"bg-transparent text-muted-foreground"}`,children:w.isPending||G.isPending?o.jsx($e,{className:"w-4 h-4 animate-spin"}):o.jsx(Nf,{className:"w-4 h-4"})})]})}),d==="success"&&o.jsxs("div",{className:"flex items-center gap-2 mt-2 px-2 py-1.5 text-xs rounded-lg bg-teal-500/10 border border-teal-500/30 text-teal-600 dark:text-teal-400",children:[o.jsx(Dn,{className:"w-3 h-3 flex-shrink-0"}),o.jsx("span",{className:"flex-1",children:"Context injected — will be used on next request"}),o.jsx("button",{type:"button",onClick:()=>f("idle"),className:"hover:text-teal-500",children:o.jsx(yt,{className:"w-3 h-3"})})]}),d==="error"&&o.jsxs("div",{className:"flex items-center gap-2 mt-2 px-2 py-1.5 text-xs rounded-lg bg-red-500/10 border border-red-500/30 text-red-600 dark:text-red-400",children:[o.jsx(yt,{className:"w-3 h-3 flex-shrink-0"}),o.jsx("span",{className:"flex-1",children:"Failed to inject context"}),o.jsx("button",{type:"button",onClick:()=>f("idle"),className:"hover:text-red-500",children:o.jsx(yt,{className:"w-3 h-3"})})]}),o.jsxs("div",{className:"flex gap-2 mt-2",children:[o.jsxs("button",{type:"button",onClick:F,disabled:!i||Y.isPending||R||I,className:`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${I?"bg-teal-500/10 text-teal-600 dark:text-teal-400 border border-teal-500/30":"bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground"}`,title:I?"Already injected into main session":"Inject findings into main session",children:[Y.isPending?o.jsx($e,{className:"w-3 h-3 animate-spin"}):I?o.jsx(Dn,{className:"w-3 h-3"}):o.jsx(Y1,{className:"w-3 h-3"}),I?"Injected":"Inject"]}),o.jsxs("button",{type:"button",onClick:T,disabled:!i||Z.isPending||R,className:"flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs rounded-lg bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Export to new main session",children:[Z.isPending?o.jsx($e,{className:"w-3 h-3 animate-spin"}):o.jsx(rn,{className:"w-3 h-3"}),"Export"]})]})]})]}),o.jsxs("div",{className:"h-12 px-3 border-t border-border text-xs text-muted-foreground flex items-center justify-between",children:[o.jsxs("span",{className:"text-[10px]",children:[j.length," research session",j.length!==1?"s":""]}),(LA||ZA)&&o.jsxs("button",{type:"button",onClick:()=>u(!0),className:"flex items-center gap-1 text-[10px] hover:text-foreground transition-colors",children:[o.jsx("span",{className:"opacity-60",children:LA}),o.jsx("span",{className:"opacity-40",children:"/"}),o.jsx("span",{children:ZA}),o.jsx(xn,{className:"w-3 h-3 opacity-40"})]})]}),o.jsx(ds,{isOpen:Q,onClose:()=>u(!1),title:"Select Model for Research",maxWidth:"md",children:(CA||aA)&&o.jsx(Kh,{provider:CA,model:aA,onChange:p})})]})]})});function TY(A){const e=Date.now()-A,t=Math.floor(e/6e4);if(t<1)return"just now";if(t<60)return`${t}m ago`;const n=Math.floor(t/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const LY=k.memo(function({parentSessionId:e}){const t=Tt(i=>i.isExpanded),n=Tt(i=>i.toggleSidebar),{data:r}=Hy(e??null),s=r?.sessions?.length??0;return o.jsxs("button",{type:"button",onClick:n,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${t?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Research (⌘⇧R)",children:[o.jsx($i,{className:"w-5 h-5 text-muted-foreground mx-auto"}),s>0&&o.jsx("span",{className:"absolute top-1 right-1 w-5 h-5 bg-primary text-primary-foreground text-xs rounded-full flex items-center justify-center font-semibold",children:s>9?"9+":s})]})});var OY=Object.defineProperty,Jc=Object.getOwnPropertySymbols,Py=Object.prototype.hasOwnProperty,_y=Object.prototype.propertyIsEnumerable,Bf=(A,e,t)=>e in A?OY(A,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):A[e]=t,OQ=(A,e)=>{for(var t in e||(e={}))Py.call(e,t)&&Bf(A,t,e[t]);if(Jc)for(var t of Jc(e))_y.call(e,t)&&Bf(A,t,e[t]);return A},KQ=(A,e)=>{var t={};for(var n in A)Py.call(A,n)&&e.indexOf(n)<0&&(t[n]=A[n]);if(A!=null&&Jc)for(var n of Jc(A))e.indexOf(n)<0&&_y.call(A,n)&&(t[n]=A[n]);return t};var yo;(A=>{const e=class Le{constructor(g,c,l,B){if(this.version=g,this.errorCorrectionLevel=c,this.modules=[],this.isFunction=[],g<Le.MIN_VERSION||g>Le.MAX_VERSION)throw new RangeError("Version value out of range");if(B<-1||B>7)throw new RangeError("Mask value out of range");this.size=g*4+17;let Q=[];for(let d=0;d<this.size;d++)Q.push(!1);for(let d=0;d<this.size;d++)this.modules.push(Q.slice()),this.isFunction.push(Q.slice());this.drawFunctionPatterns();const u=this.addEccAndInterleave(l);if(this.drawCodewords(u),B==-1){let d=1e9;for(let f=0;f<8;f++){this.applyMask(f),this.drawFormatBits(f);const h=this.getPenaltyScore();h<d&&(B=f,d=h),this.applyMask(f)}}r(0<=B&&B<=7),this.mask=B,this.applyMask(B),this.drawFormatBits(B),this.isFunction=[]}static encodeText(g,c){const l=A.QrSegment.makeSegments(g);return Le.encodeSegments(l,c)}static encodeBinary(g,c){const l=A.QrSegment.makeBytes(g);return Le.encodeSegments([l],c)}static encodeSegments(g,c,l=1,B=40,Q=-1,u=!0){if(!(Le.MIN_VERSION<=l&&l<=B&&B<=Le.MAX_VERSION)||Q<-1||Q>7)throw new RangeError("Invalid value");let d,f;for(d=l;;d++){const m=Le.getNumDataCodewords(d,c)*8,M=i.getTotalBits(g,d);if(M<=m){f=M;break}if(d>=B)throw new RangeError("Data too long")}for(const m of[Le.Ecc.MEDIUM,Le.Ecc.QUARTILE,Le.Ecc.HIGH])u&&f<=Le.getNumDataCodewords(d,m)*8&&(c=m);let h=[];for(const m of g){t(m.mode.modeBits,4,h),t(m.numChars,m.mode.numCharCountBits(d),h);for(const M of m.getData())h.push(M)}r(h.length==f);const x=Le.getNumDataCodewords(d,c)*8;r(h.length<=x),t(0,Math.min(4,x-h.length),h),t(0,(8-h.length%8)%8,h),r(h.length%8==0);for(let m=236;h.length<x;m^=253)t(m,8,h);let b=[];for(;b.length*8<h.length;)b.push(0);return h.forEach((m,M)=>b[M>>>3]|=m<<7-(M&7)),new Le(d,c,b,Q)}getModule(g,c){return 0<=g&&g<this.size&&0<=c&&c<this.size&&this.modules[c][g]}getModules(){return this.modules}drawFunctionPatterns(){for(let l=0;l<this.size;l++)this.setFunctionModule(6,l,l%2==0),this.setFunctionModule(l,6,l%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const g=this.getAlignmentPatternPositions(),c=g.length;for(let l=0;l<c;l++)for(let B=0;B<c;B++)l==0&&B==0||l==0&&B==c-1||l==c-1&&B==0||this.drawAlignmentPattern(g[l],g[B]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(g){const c=this.errorCorrectionLevel.formatBits<<3|g;let l=c;for(let Q=0;Q<10;Q++)l=l<<1^(l>>>9)*1335;const B=(c<<10|l)^21522;r(B>>>15==0);for(let Q=0;Q<=5;Q++)this.setFunctionModule(8,Q,n(B,Q));this.setFunctionModule(8,7,n(B,6)),this.setFunctionModule(8,8,n(B,7)),this.setFunctionModule(7,8,n(B,8));for(let Q=9;Q<15;Q++)this.setFunctionModule(14-Q,8,n(B,Q));for(let Q=0;Q<8;Q++)this.setFunctionModule(this.size-1-Q,8,n(B,Q));for(let Q=8;Q<15;Q++)this.setFunctionModule(8,this.size-15+Q,n(B,Q));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let g=this.version;for(let l=0;l<12;l++)g=g<<1^(g>>>11)*7973;const c=this.version<<12|g;r(c>>>18==0);for(let l=0;l<18;l++){const B=n(c,l),Q=this.size-11+l%3,u=Math.floor(l/3);this.setFunctionModule(Q,u,B),this.setFunctionModule(u,Q,B)}}drawFinderPattern(g,c){for(let l=-4;l<=4;l++)for(let B=-4;B<=4;B++){const Q=Math.max(Math.abs(B),Math.abs(l)),u=g+B,d=c+l;0<=u&&u<this.size&&0<=d&&d<this.size&&this.setFunctionModule(u,d,Q!=2&&Q!=4)}}drawAlignmentPattern(g,c){for(let l=-2;l<=2;l++)for(let B=-2;B<=2;B++)this.setFunctionModule(g+B,c+l,Math.max(Math.abs(B),Math.abs(l))!=1)}setFunctionModule(g,c,l){this.modules[c][g]=l,this.isFunction[c][g]=!0}addEccAndInterleave(g){const c=this.version,l=this.errorCorrectionLevel;if(g.length!=Le.getNumDataCodewords(c,l))throw new RangeError("Invalid argument");const B=Le.NUM_ERROR_CORRECTION_BLOCKS[l.ordinal][c],Q=Le.ECC_CODEWORDS_PER_BLOCK[l.ordinal][c],u=Math.floor(Le.getNumRawDataModules(c)/8),d=B-u%B,f=Math.floor(u/B);let h=[];const x=Le.reedSolomonComputeDivisor(Q);for(let m=0,M=0;m<B;m++){let G=g.slice(M,M+f-Q+(m<d?0:1));M+=G.length;const Y=Le.reedSolomonComputeRemainder(G,x);m<d&&G.push(0),h.push(G.concat(Y))}let b=[];for(let m=0;m<h[0].length;m++)h.forEach((M,G)=>{(m!=f-Q||G>=d)&&b.push(M[m])});return r(b.length==u),b}drawCodewords(g){if(g.length!=Math.floor(Le.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let c=0;for(let l=this.size-1;l>=1;l-=2){l==6&&(l=5);for(let B=0;B<this.size;B++)for(let Q=0;Q<2;Q++){const u=l-Q,f=(l+1&2)==0?this.size-1-B:B;!this.isFunction[f][u]&&c<g.length*8&&(this.modules[f][u]=n(g[c>>>3],7-(c&7)),c++)}}r(c==g.length*8)}applyMask(g){if(g<0||g>7)throw new RangeError("Mask value out of range");for(let c=0;c<this.size;c++)for(let l=0;l<this.size;l++){let B;switch(g){case 0:B=(l+c)%2==0;break;case 1:B=c%2==0;break;case 2:B=l%3==0;break;case 3:B=(l+c)%3==0;break;case 4:B=(Math.floor(l/3)+Math.floor(c/2))%2==0;break;case 5:B=l*c%2+l*c%3==0;break;case 6:B=(l*c%2+l*c%3)%2==0;break;case 7:B=((l+c)%2+l*c%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[c][l]&&B&&(this.modules[c][l]=!this.modules[c][l])}}getPenaltyScore(){let g=0;for(let Q=0;Q<this.size;Q++){let u=!1,d=0,f=[0,0,0,0,0,0,0];for(let h=0;h<this.size;h++)this.modules[Q][h]==u?(d++,d==5?g+=Le.PENALTY_N1:d>5&&g++):(this.finderPenaltyAddHistory(d,f),u||(g+=this.finderPenaltyCountPatterns(f)*Le.PENALTY_N3),u=this.modules[Q][h],d=1);g+=this.finderPenaltyTerminateAndCount(u,d,f)*Le.PENALTY_N3}for(let Q=0;Q<this.size;Q++){let u=!1,d=0,f=[0,0,0,0,0,0,0];for(let h=0;h<this.size;h++)this.modules[h][Q]==u?(d++,d==5?g+=Le.PENALTY_N1:d>5&&g++):(this.finderPenaltyAddHistory(d,f),u||(g+=this.finderPenaltyCountPatterns(f)*Le.PENALTY_N3),u=this.modules[h][Q],d=1);g+=this.finderPenaltyTerminateAndCount(u,d,f)*Le.PENALTY_N3}for(let Q=0;Q<this.size-1;Q++)for(let u=0;u<this.size-1;u++){const d=this.modules[Q][u];d==this.modules[Q][u+1]&&d==this.modules[Q+1][u]&&d==this.modules[Q+1][u+1]&&(g+=Le.PENALTY_N2)}let c=0;for(const Q of this.modules)c=Q.reduce((u,d)=>u+(d?1:0),c);const l=this.size*this.size,B=Math.ceil(Math.abs(c*20-l*10)/l)-1;return r(0<=B&&B<=9),g+=B*Le.PENALTY_N4,r(0<=g&&g<=2568888),g}getAlignmentPatternPositions(){if(this.version==1)return[];{const g=Math.floor(this.version/7)+2,c=this.version==32?26:Math.ceil((this.version*4+4)/(g*2-2))*2;let l=[6];for(let B=this.size-7;l.length<g;B-=c)l.splice(1,0,B);return l}}static getNumRawDataModules(g){if(g<Le.MIN_VERSION||g>Le.MAX_VERSION)throw new RangeError("Version number out of range");let c=(16*g+128)*g+64;if(g>=2){const l=Math.floor(g/7)+2;c-=(25*l-10)*l-55,g>=7&&(c-=36)}return r(208<=c&&c<=29648),c}static getNumDataCodewords(g,c){return Math.floor(Le.getNumRawDataModules(g)/8)-Le.ECC_CODEWORDS_PER_BLOCK[c.ordinal][g]*Le.NUM_ERROR_CORRECTION_BLOCKS[c.ordinal][g]}static reedSolomonComputeDivisor(g){if(g<1||g>255)throw new RangeError("Degree out of range");let c=[];for(let B=0;B<g-1;B++)c.push(0);c.push(1);let l=1;for(let B=0;B<g;B++){for(let Q=0;Q<c.length;Q++)c[Q]=Le.reedSolomonMultiply(c[Q],l),Q+1<c.length&&(c[Q]^=c[Q+1]);l=Le.reedSolomonMultiply(l,2)}return c}static reedSolomonComputeRemainder(g,c){let l=c.map(B=>0);for(const B of g){const Q=B^l.shift();l.push(0),c.forEach((u,d)=>l[d]^=Le.reedSolomonMultiply(u,Q))}return l}static reedSolomonMultiply(g,c){if(g>>>8||c>>>8)throw new RangeError("Byte out of range");let l=0;for(let B=7;B>=0;B--)l=l<<1^(l>>>7)*285,l^=(c>>>B&1)*g;return r(l>>>8==0),l}finderPenaltyCountPatterns(g){const c=g[1];r(c<=this.size*3);const l=c>0&&g[2]==c&&g[3]==c*3&&g[4]==c&&g[5]==c;return(l&&g[0]>=c*4&&g[6]>=c?1:0)+(l&&g[6]>=c*4&&g[0]>=c?1:0)}finderPenaltyTerminateAndCount(g,c,l){return g&&(this.finderPenaltyAddHistory(c,l),c=0),c+=this.size,this.finderPenaltyAddHistory(c,l),this.finderPenaltyCountPatterns(l)}finderPenaltyAddHistory(g,c){c[0]==0&&(g+=this.size),c.pop(),c.unshift(g)}};e.MIN_VERSION=1,e.MAX_VERSION=40,e.PENALTY_N1=3,e.PENALTY_N2=3,e.PENALTY_N3=40,e.PENALTY_N4=10,e.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],e.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],A.QrCode=e;function t(a,g,c){if(g<0||g>31||a>>>g)throw new RangeError("Value out of range");for(let l=g-1;l>=0;l--)c.push(a>>>l&1)}function n(a,g){return(a>>>g&1)!=0}function r(a){if(!a)throw new Error("Assertion error")}const s=class vt{constructor(g,c,l){if(this.mode=g,this.numChars=c,this.bitData=l,c<0)throw new RangeError("Invalid argument");this.bitData=l.slice()}static makeBytes(g){let c=[];for(const l of g)t(l,8,c);return new vt(vt.Mode.BYTE,g.length,c)}static makeNumeric(g){if(!vt.isNumeric(g))throw new RangeError("String contains non-numeric characters");let c=[];for(let l=0;l<g.length;){const B=Math.min(g.length-l,3);t(parseInt(g.substring(l,l+B),10),B*3+1,c),l+=B}return new vt(vt.Mode.NUMERIC,g.length,c)}static makeAlphanumeric(g){if(!vt.isAlphanumeric(g))throw new RangeError("String contains unencodable characters in alphanumeric mode");let c=[],l;for(l=0;l+2<=g.length;l+=2){let B=vt.ALPHANUMERIC_CHARSET.indexOf(g.charAt(l))*45;B+=vt.ALPHANUMERIC_CHARSET.indexOf(g.charAt(l+1)),t(B,11,c)}return l<g.length&&t(vt.ALPHANUMERIC_CHARSET.indexOf(g.charAt(l)),6,c),new vt(vt.Mode.ALPHANUMERIC,g.length,c)}static makeSegments(g){return g==""?[]:vt.isNumeric(g)?[vt.makeNumeric(g)]:vt.isAlphanumeric(g)?[vt.makeAlphanumeric(g)]:[vt.makeBytes(vt.toUtf8ByteArray(g))]}static makeEci(g){let c=[];if(g<0)throw new RangeError("ECI assignment value out of range");if(g<128)t(g,8,c);else if(g<16384)t(2,2,c),t(g,14,c);else if(g<1e6)t(6,3,c),t(g,21,c);else throw new RangeError("ECI assignment value out of range");return new vt(vt.Mode.ECI,0,c)}static isNumeric(g){return vt.NUMERIC_REGEX.test(g)}static isAlphanumeric(g){return vt.ALPHANUMERIC_REGEX.test(g)}getData(){return this.bitData.slice()}static getTotalBits(g,c){let l=0;for(const B of g){const Q=B.mode.numCharCountBits(c);if(B.numChars>=1<<Q)return 1/0;l+=4+Q+B.bitData.length}return l}static toUtf8ByteArray(g){g=encodeURI(g);let c=[];for(let l=0;l<g.length;l++)g.charAt(l)!="%"?c.push(g.charCodeAt(l)):(c.push(parseInt(g.substring(l+1,l+3),16)),l+=2);return c}};s.NUMERIC_REGEX=/^[0-9]*$/,s.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,s.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let i=s;A.QrSegment=s})(yo||(yo={}));(A=>{(e=>{const t=class{constructor(r,s){this.ordinal=r,this.formatBits=s}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(A.QrCode||(A.QrCode={}))})(yo||(yo={}));(A=>{(e=>{const t=class{constructor(r,s){this.modeBits=r,this.numBitsCharCount=s}numCharCountBits(r){return this.numBitsCharCount[Math.floor((r+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(A.QrSegment||(A.QrSegment={}))})(yo||(yo={}));var _o=yo;var KY={L:_o.QrCode.Ecc.LOW,M:_o.QrCode.Ecc.MEDIUM,Q:_o.QrCode.Ecc.QUARTILE,H:_o.QrCode.Ecc.HIGH},zy=128,Wy="L",Vy="#FFFFFF",Zy="#000000",Xy=!1,$y=1,jY=4,JY=0,qY=.1;function A1(A,e=0){const t=[];return A.forEach(function(n,r){let s=null;n.forEach(function(i,a){if(!i&&s!==null){t.push(`M${s+e} ${r+e}h${a-s}v1H${s+e}z`),s=null;return}if(a===n.length-1){if(!i)return;s===null?t.push(`M${a+e},${r+e} h1v1H${a+e}z`):t.push(`M${s+e},${r+e} h${a+1-s}v1H${s+e}z`);return}i&&s===null&&(s=a)})}),t.join("")}function e1(A,e){return A.slice().map((t,n)=>n<e.y||n>=e.y+e.h?t:t.map((r,s)=>s<e.x||s>=e.x+e.w?r:!1))}function YY(A,e,t,n){if(n==null)return null;const r=A.length+t*2,s=Math.floor(e*qY),i=r/e,a=(n.width||s)*i,g=(n.height||s)*i,c=n.x==null?A.length/2-a/2:n.x*i,l=n.y==null?A.length/2-g/2:n.y*i,B=n.opacity==null?1:n.opacity;let Q=null;if(n.excavate){let d=Math.floor(c),f=Math.floor(l),h=Math.ceil(a+c-d),x=Math.ceil(g+l-f);Q={x:d,y:f,w:h,h:x}}const u=n.crossOrigin;return{x:c,y:l,h:g,w:a,excavation:Q,opacity:B,crossOrigin:u}}function HY(A,e){return e!=null?Math.max(Math.floor(e),0):A?jY:JY}function t1({value:A,level:e,minVersion:t,includeMargin:n,marginSize:r,imageSettings:s,size:i,boostLevel:a}){let g=wt.useMemo(()=>{const d=(Array.isArray(A)?A:[A]).reduce((f,h)=>(f.push(..._o.QrSegment.makeSegments(h)),f),[]);return _o.QrCode.encodeSegments(d,KY[e],t,void 0,void 0,a)},[A,e,t,a]);const{cells:c,margin:l,numCells:B,calculatedImageSettings:Q}=wt.useMemo(()=>{let u=g.getModules();const d=HY(n,r),f=u.length+d*2,h=YY(u,i,d,s);return{cells:u,margin:d,numCells:f,calculatedImageSettings:h}},[g,i,s,n,r]);return{qrcode:g,margin:l,cells:c,numCells:B,calculatedImageSettings:Q}}var PY=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),_Y=wt.forwardRef(function(e,t){const n=e,{value:r,size:s=zy,level:i=Wy,bgColor:a=Vy,fgColor:g=Zy,includeMargin:c=Xy,minVersion:l=$y,boostLevel:B,marginSize:Q,imageSettings:u}=n,f=KQ(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:h}=f,x=KQ(f,["style"]),b=u?.src,m=wt.useRef(null),M=wt.useRef(null),G=wt.useCallback(E=>{m.current=E,typeof t=="function"?t(E):t&&(t.current=E)},[t]),[Y,Z]=wt.useState(!1),{margin:P,cells:L,numCells:q,calculatedImageSettings:v}=t1({value:r,level:i,minVersion:l,boostLevel:B,includeMargin:c,marginSize:Q,imageSettings:u,size:s});wt.useEffect(()=>{if(m.current!=null){const E=m.current,C=E.getContext("2d");if(!C)return;let y=L;const F=M.current,T=v!=null&&F!==null&&F.complete&&F.naturalHeight!==0&&F.naturalWidth!==0;T&&v.excavation!=null&&(y=e1(L,v.excavation));const J=window.devicePixelRatio||1;E.height=E.width=s*J;const z=s/q*J;C.scale(z,z),C.fillStyle=a,C.fillRect(0,0,q,q),C.fillStyle=g,PY?C.fill(new Path2D(A1(y,P))):L.forEach(function(R,I){R.forEach(function(p,K){p&&C.fillRect(K+P,I+P,1,1)})}),v&&(C.globalAlpha=v.opacity),T&&C.drawImage(F,v.x+P,v.y+P,v.w,v.h)}}),wt.useEffect(()=>{Z(!1)},[b]);const U=OQ({height:s,width:s},h);let w=null;return b!=null&&(w=wt.createElement("img",{src:b,key:b,style:{display:"none"},onLoad:()=>{Z(!0)},ref:M,crossOrigin:v?.crossOrigin})),wt.createElement(wt.Fragment,null,wt.createElement("canvas",OQ({style:U,height:s,width:s,ref:G,role:"img"},x)),w)});_Y.displayName="QRCodeCanvas";var Hl=wt.forwardRef(function(e,t){const n=e,{value:r,size:s=zy,level:i=Wy,bgColor:a=Vy,fgColor:g=Zy,includeMargin:c=Xy,minVersion:l=$y,boostLevel:B,title:Q,marginSize:u,imageSettings:d}=n,f=KQ(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:h,cells:x,numCells:b,calculatedImageSettings:m}=t1({value:r,level:i,minVersion:l,boostLevel:B,includeMargin:c,marginSize:u,imageSettings:d,size:s});let M=x,G=null;d!=null&&m!=null&&(m.excavation!=null&&(M=e1(x,m.excavation)),G=wt.createElement("image",{href:d.src,height:m.h,width:m.w,x:m.x+h,y:m.y+h,preserveAspectRatio:"none",opacity:m.opacity,crossOrigin:m.crossOrigin}));const Y=A1(M,h);return wt.createElement("svg",OQ({height:s,width:s,viewBox:`0 0 ${b} ${b}`,ref:t,role:"img"},f),!!Q&&wt.createElement("title",null,Q),wt.createElement("path",{fill:a,d:`M0,0 h${b}v${b}H0z`,shapeRendering:"crispEdges"}),wt.createElement("path",{fill:g,d:Y,shapeRendering:"crispEdges"}),G)});Hl.displayName="QRCodeSVG";const ji=["wallet","defaults"],nn=Rt((A,e)=>({isOpen:!1,currentStep:"wallet",manageMode:!1,isLoading:!1,error:null,authStatus:null,setOpen:t=>A({isOpen:t}),setStep:t=>A({currentStep:t}),setManageMode:t=>A({manageMode:t}),setLoading:t=>A({isLoading:t}),setError:t=>A({error:t}),setAuthStatus:t=>A({authStatus:t}),nextStep:()=>{const{currentStep:t}=e(),n=ji.indexOf(t);n<ji.length-1&&A({currentStep:ji[n+1]})},prevStep:()=>{const{currentStep:t}=e(),n=ji.indexOf(t);n>0&&A({currentStep:ji[n-1]})},reset:()=>A({isOpen:!1,currentStep:"wallet",manageMode:!1,isLoading:!1,error:null})})),uB=typeof window<"u"&&window.self!==window.top;function Vd(){const A=nn(v=>v.setAuthStatus),e=nn(v=>v.setOpen),t=nn(v=>v.setLoading),n=nn(v=>v.setError),r=nn(v=>v.authStatus),s=nn(v=>v.isOpen),i=Ye(),[a,g]=k.useState(!1),[c,l]=k.useState(!1),B=k.useRef(null),Q=k.useRef(new Set),u=k.useCallback(async()=>{t(!0),n(null);try{const v=await xA.getAuthStatus();return A(v),i.invalidateQueries({queryKey:["config"]}),i.invalidateQueries({queryKey:["models"]}),v}catch(v){const U=v instanceof Error?v.message:"Failed to load";return n(U),null}finally{t(!1)}},[A,t,n,i]),d=k.useCallback(async()=>{const v=await u();if(v){const U=Object.values(v.providers).some(E=>E.configured);(!v.onboardingComplete||!U||!v.setu.configured)&&e(!0)}g(!0)},[u,e]),f=k.useCallback(async()=>{t(!0),n(null);try{const v=await xA.setupSetuWallet();return await u(),v}catch(v){const U=v instanceof Error?v.message:"Setup failed";throw n(U),v}finally{t(!1)}},[u,t,n]),h=k.useCallback(async v=>{t(!0),n(null);try{const U=await xA.importSetuWallet(v);return await u(),U}catch(U){const w=U instanceof Error?U.message:"Import failed";throw n(w),U}finally{t(!1)}},[u,t,n]),x=k.useCallback(async(v,U)=>{t(!0),n(null);try{const w=await xA.addProvider(v,U);return await u(),w}catch(w){const E=w instanceof Error?w.message:"Failed to add provider";throw n(E),w}finally{t(!1)}},[u,t,n]),b=k.useCallback(async v=>{t(!0),n(null);try{const U=await xA.removeProvider(v);return await u(),U}catch(U){const w=U instanceof Error?U.message:"Failed to remove provider";throw n(w),U}finally{t(!1)}},[u,t,n]),m=k.useCallback(async()=>{t(!0),n(null);try{await xA.completeOnboarding(),await u(),e(!1)}catch(v){const U=v instanceof Error?v.message:"Failed to complete onboarding";throw n(U),v}finally{t(!1)}},[u,t,n,e]),M=k.useCallback(()=>{const v=nn.getState().authStatus;v&&(Q.current=new Set(Object.entries(v.providers).filter(([,U])=>U.configured).map(([U])=>U)))},[]),G=k.useCallback((v,U)=>{const w=xA.getOAuthStartUrl(v,U);if(uB)return M(),window.parent.postMessage({type:"otto-open-url",url:w},"*"),l(!0),null;const E=600,C=700,y=window.screenX+(window.outerWidth-E)/2,F=window.screenY+(window.outerHeight-C)/2;return window.open(w,"oauth_popup",`width=${E},height=${C},left=${y},top=${F},toolbar=no,menubar=no`)},[M]),Y=k.useCallback(async(v,U)=>{const{url:w,sessionId:E}=await xA.getOAuthUrl(v,U);if(uB)return M(),window.parent.postMessage({type:"otto-open-url",url:w},"*"),l(!0),{popup:null,sessionId:E};const C=600,y=700,F=window.screenX+(window.outerWidth-C)/2,T=window.screenY+(window.outerHeight-y)/2;return{popup:window.open(w,"oauth_popup",`width=${C},height=${y},left=${F},top=${T},toolbar=no,menubar=no`),sessionId:E}},[M]),Z=k.useCallback(async(v,U,w)=>{t(!0),n(null);try{return await xA.exchangeOAuthCode(v,U,w),await u(),!0}catch(E){const C=E instanceof Error?E.message:"Failed to exchange code";throw n(C),E}finally{t(!1)}},[u,t,n]);k.useEffect(()=>{if(!c||!uB)return;B.current=setInterval(()=>{u()},3e3);const v=setTimeout(()=>{l(!1)},3e5);return()=>{clearInterval(B.current),clearTimeout(v)}},[c,u]),k.useEffect(()=>{if(!c||!r)return;Object.entries(r.providers).filter(([,w])=>w.configured).some(([w])=>!Q.current.has(w))&&l(!1)},[r,c]),k.useEffect(()=>{const v=U=>{U.data?.type==="oauth-success"&&u()};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[u]);const P=k.useCallback(async v=>{const U=await xA.pollCopilotDeviceFlow(v);return U.status==="complete"&&await u(),U},[u]),L=k.useCallback(async v=>{t(!0),n(null);try{const U=await xA.saveCopilotToken(v);return await u(),U}catch(U){const w=U instanceof Error?U.message:"Failed to save Copilot token";throw n(w),U}finally{t(!1)}},[u,t,n]),q=k.useCallback(async()=>{t(!0),n(null);try{const v=await xA.importCopilotTokenFromGh();return await u(),v}catch(v){const U=v instanceof Error?v.message:"Failed to import Copilot token from GH";throw n(U),v}finally{t(!1)}},[u,t,n]);return{authStatus:r,isOpen:s,initialized:a,fetchAuthStatus:u,checkOnboarding:d,setupWallet:f,importWallet:h,addProvider:x,removeProvider:b,completeOnboarding:m,startOAuth:G,startOAuthManual:Y,exchangeOAuthCode:Z,startCopilotDeviceFlow:xA.startCopilotDeviceFlow.bind(xA),pollCopilotDeviceFlow:P,getCopilotAuthMethods:xA.getCopilotAuthMethods.bind(xA),saveCopilotToken:L,importCopilotTokenFromGh:q,getCopilotDiagnostics:xA.getCopilotDiagnostics.bind(xA)}}const Og="pendingPolarCheckout";function zY(){const A=k.useRef(!1),e=k.useRef(null),t=Te(r=>r.setBalance),n=Er(r=>r.removeToast);k.useEffect(()=>{if(A.current)return;const s=new URLSearchParams(window.location.search).get("topup"),i=localStorage.getItem(Og);if(s==="pending"||i){A.current=!0;const a=new URL(window.location.href);if(a.searchParams.delete("topup"),window.history.replaceState({},"",a.toString()),!i){ve.info("Checking top-up status...");return}e.current=ve.loading("Verifying top-up...");let g=0;const c=10,l=2e3,B=()=>{e.current&&(n(e.current),e.current=null)},Q=async()=>{g++;try{const u=await xA.getPolarTopupStatus(i);if(u?.confirmed){localStorage.removeItem(Og),B();const d=await xA.getSetuBalance();d?.balance!==void 0&&t(d.balance),ve.success(`Top-up confirmed! +$${u.amountUsd?.toFixed(2)} credited`);return}g<c?setTimeout(Q,l):(localStorage.removeItem(Og),B(),ve.info("Top-up is still processing. Balance will update automatically."))}catch{g<c?setTimeout(Q,l):(localStorage.removeItem(Og),B(),ve.error("Could not verify top-up. Please check your balance."))}};setTimeout(Q,1500)}},[t,n])}const Qf="settings",Ef=320,WY=320,VY=500,$g=k.memo(function({title:e,icon:t,children:n,action:r}){return o.jsxs("div",{className:"border-b border-border",children:[o.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 bg-muted/30",children:[t,o.jsx("span",{className:"text-sm font-medium flex-1",children:e}),r]}),o.jsx("div",{className:"px-4 py-3 space-y-3",children:n})]})}),Hs=k.memo(function({label:e,value:t}){return o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:e}),o.jsx("span",{className:"font-mono text-foreground",children:t})]})}),Ji=k.memo(function({label:e,checked:t,onChange:n}){return o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:e}),o.jsx("button",{type:"button",role:"switch","aria-checked":t,onClick:()=>n(!t),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${t?"bg-primary":"bg-muted"}`,children:o.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${t?"translate-x-6":"translate-x-1"} ${t?"bg-primary-foreground":"bg-foreground"}`})})]})}),qi=k.memo(function({label:e,value:t,options:n,onChange:r,disabled:s}){const[i,a]=k.useState(!1),g=n.find(c=>c.id===t);return o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:e}),o.jsxs("div",{className:"relative",children:[o.jsxs("button",{type:"button",onClick:()=>!s&&a(!i),disabled:s,className:"flex items-center gap-1 px-2 py-1 text-xs font-mono bg-muted hover:bg-muted/80 rounded border border-border disabled:opacity-50",children:[o.jsx("span",{className:"max-w-[120px] truncate",children:g?.label||t||"Select..."}),o.jsx(xn,{className:"w-3 h-3"})]}),i&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>a(!1),role:"presentation"}),o.jsx("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[160px] max-h-[200px] overflow-y-auto bg-popover border border-border rounded-md shadow-lg",children:n.map(c=>o.jsx("button",{type:"button",onClick:()=>{r(c.id),a(!1)},className:`w-full px-3 py-2 text-left text-xs font-mono hover:bg-muted truncate ${c.id===t?"bg-muted/50":""}`,children:c.label},c.id))})]})]})]})}),ZY=k.memo(function(){const e=Zt(v=>v.isExpanded),t=Zt(v=>v.collapseSidebar),n=ks(v=>v.widths[Qf]??Ef),{data:r}=bo(),{data:s}=La(),{preferences:i,updatePreferences:a}=hi(),g=$c(),c=Te(v=>v.balance),l=Te(v=>v.walletAddress),B=Te(v=>v.usdcBalance),Q=Te(v=>v.isLoading),u=Te(v=>v.openTopupModal);zY();const d=r?.providers?.includes("setu"),{fetchBalance:f}=ql(d?"setu":void 0),h=nn(v=>v.setOpen),x=nn(v=>v.setStep),b=nn(v=>v.setManageMode),{fetchAuthStatus:m}=Vd(),M=k.useCallback(async()=>await xA.exportSetuWallet(),[]),G=k.useMemo(()=>!r?.providers||!s?[]:r.providers.filter(v=>s[v]).map(v=>({id:v,label:s[v]?.label||v})),[r?.providers,s]),Y=k.useMemo(()=>{const v=r?.defaults?.provider;return!v||!s?.[v]?[]:s[v].models.map(U=>({id:U.id,label:U.label}))},[r?.defaults?.provider,s]),Z=k.useMemo(()=>r?.agents?r.agents.map(v=>({id:v,label:v})):[],[r?.agents]);if(!e)return null;const P=v=>{const U=s?.[v]?.models?.[0]?.id;g.mutate({provider:v,model:U||r?.defaults?.model,scope:"global"})},L=v=>{g.mutate({model:v,scope:"global"})},q=v=>{g.mutate({agent:v,scope:"global"})};return o.jsxs("div",{className:"border-l border-sidebar-border sidebar-fade-in flex h-full relative",style:{width:n},children:[o.jsx(fi,{panelKey:Qf,side:"right",minWidth:WY,maxWidth:VY,defaultWidth:Ef}),o.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[o.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Lf,{className:"w-4 h-4"}),o.jsx("span",{className:"font-medium",children:"Settings"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,children:o.jsx(Dt,{className:"w-4 h-4"})})]}),o.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o.jsxs($g,{title:"Default Model",icon:o.jsx(H1,{className:"w-4 h-4 text-muted-foreground"}),children:[o.jsx(qi,{label:"Provider",value:r?.defaults?.provider??"",options:G,onChange:P,disabled:g.isPending}),o.jsx(qi,{label:"Model",value:r?.defaults?.model??"",options:Y,onChange:L,disabled:g.isPending}),o.jsx(qi,{label:"Agent",value:r?.defaults?.agent??"",options:Z,onChange:q,disabled:g.isPending})]}),o.jsxs($g,{title:"Preferences",icon:o.jsx(HQ,{className:"w-4 h-4 text-muted-foreground"}),children:[o.jsx(Ji,{label:"Vim Mode",checked:i.vimMode,onChange:v=>a({vimMode:v})}),o.jsx(Ji,{label:"Compact Thread",checked:i.compactThread,onChange:v=>a({compactThread:v})}),o.jsx(Ji,{label:"Full Width Content",checked:i.fullWidthContent,onChange:v=>a({fullWidthContent:v})}),o.jsx(Ji,{label:"Show Reasoning",checked:r?.defaults?.reasoningText??!0,onChange:v=>g.mutate({reasoningText:v,scope:"global"})}),o.jsx(qi,{label:"Reasoning Level",value:r?.defaults?.reasoningLevel??"high",options:[{id:"minimal",label:"Minimal"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"max",label:"Max"},{id:"xhigh",label:"Extra High"}],onChange:v=>g.mutate({reasoningLevel:v,scope:"global"}),disabled:g.isPending}),o.jsx(qi,{label:"Tool Approval",value:r?.defaults?.toolApproval??"dangerous",options:[{id:"auto",label:"Auto (no approval)"},{id:"dangerous",label:"Dangerous only"},{id:"all",label:"All tools"}],onChange:v=>g.mutate({toolApproval:v,scope:"global"}),disabled:g.isPending}),o.jsx(Ji,{label:"Guided Mode",checked:r?.defaults?.guidedMode??!1,onChange:v=>g.mutate({guidedMode:v,scope:"global"})})]}),o.jsx($g,{title:"Providers",icon:o.jsx(P1,{className:"w-4 h-4 text-muted-foreground"}),action:o.jsx("button",{type:"button",onClick:()=>{m().then(()=>{x("wallet"),b(!0),h(!0)})},className:"p-1 hover:bg-muted rounded transition-colors",title:"Manage providers",children:o.jsx(Ac,{className:"w-3.5 h-3.5 text-muted-foreground"})}),children:o.jsx("div",{className:"flex flex-wrap gap-2",children:r?.providers?.map(v=>o.jsx("span",{className:"px-2 py-1 text-xs bg-muted rounded-md font-mono",children:v},v))??o.jsx("span",{className:"text-muted-foreground text-sm",children:"None"})})}),r?.providers?.includes("setu")&&o.jsx($Y,{setuWallet:l,setuBalance:c,setuUsdcBalance:B,setuLoading:Q,refreshSetuBalance:f,openTopupModal:u,onExportPrivateKey:M}),o.jsx(zd,{})]})]})]})});function XY(){const A=Te(t=>t.subscription),e=Te(t=>t.payg);return A?.active?o.jsxs(o.Fragment,{children:[o.jsx(Hs,{label:"Plan",value:A.tierName??"GO"}),A.usageWindows&&o.jsxs(o.Fragment,{children:[o.jsx(Hs,{label:"5h",value:`${Math.round(A.usageWindows.fiveHour.percentUsed)}%`}),o.jsx(Hs,{label:"Week",value:`${Math.round(A.usageWindows.weekly.percentUsed)}%`})]}),e&&e.effectiveSpendableUsd>0&&o.jsx(Hs,{label:"Credits",value:`$${e.effectiveSpendableUsd.toFixed(2)}`}),A.periodEnd&&o.jsx(Hs,{label:"Renews",value:new Date(A.periodEnd).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}).replace(",","")})]}):null}const $Y=k.memo(function({setuWallet:e,setuBalance:t,setuUsdcBalance:n,setuLoading:r,refreshSetuBalance:s,openTopupModal:i,onExportPrivateKey:a}){const g=Te(w=>!!w.subscription?.active),[c,l]=k.useState(!1),[B,Q]=k.useState(!1),[u,d]=k.useState(null),[f,h]=k.useState(!1),[x,b]=k.useState(null),[m,M]=k.useState(!1),G=k.useCallback(async()=>{e&&(await navigator.clipboard.writeText(e),l(!0),setTimeout(()=>l(!1),2e3))},[e]),Y=async()=>{Q(!0),M(!1),d(null),b(null),h(!0);try{const w=await a();d(w.privateKey)}catch(w){b(w instanceof Error?w.message:"Failed to export private key")}finally{h(!1)}},Z=()=>{f||(Q(!1),M(!1),d(null),b(null))},P=async()=>{u&&(await navigator.clipboard.writeText(u),M(!0),setTimeout(()=>M(!1),2e3))},L=w=>w?`${w.slice(0,4)}...${w.slice(-4)}`:"Not configured",q=w=>w===null?"—":`$${w.toFixed(4)}`,v=w=>w===null?"—":`${w.toFixed(2)} USDC`,U=e!==null;return o.jsxs($g,{title:"Setu Credits",icon:o.jsx(XQ,{className:"w-4 h-4 text-muted-foreground"}),action:o.jsx("button",{type:"button",onClick:s,disabled:r,className:"p-1 hover:bg-muted rounded transition-colors disabled:opacity-50",title:"Refresh balances",children:o.jsx(Sn,{className:`w-3.5 h-3.5 text-muted-foreground ${r?"animate-spin":""}`})}),children:[U?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex justify-center pb-3",children:o.jsx("div",{className:"p-2 bg-white rounded-lg",children:o.jsx(Hl,{value:e,size:120,level:"M",includeMargin:!1})})}),o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:"Address"}),o.jsxs("button",{type:"button",onClick:G,className:"flex items-center gap-1.5 font-mono text-foreground hover:text-muted-foreground transition-colors",title:"Copy address",children:[L(e),c?o.jsx(Dn,{className:"w-3 h-3 text-green-500"}):o.jsx(oo,{className:"w-3 h-3 text-muted-foreground"})]})]}),o.jsx(XY,{}),!g&&o.jsxs(o.Fragment,{children:[o.jsx(Hs,{label:"Balance",value:q(t)}),o.jsx(Hs,{label:"USDC",value:v(n)})]})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex justify-center pb-3",children:o.jsx("div",{className:"w-[136px] h-[136px] bg-muted rounded-lg animate-pulse"})}),o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:"Address"}),o.jsx("div",{className:"w-24 h-4 bg-muted rounded animate-pulse"})]}),o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:"Balance"}),o.jsx("div",{className:"w-16 h-4 bg-muted rounded animate-pulse"})]}),o.jsxs("div",{className:"flex items-center justify-between text-sm",children:[o.jsx("span",{className:"text-muted-foreground",children:"USDC"}),o.jsx("div",{className:"w-20 h-4 bg-muted rounded animate-pulse"})]})]}),o.jsxs(fe,{variant:"secondary",size:"sm",onClick:i,className:"w-full mt-2 gap-2",children:[o.jsx(Qr,{className:"w-4 h-4"}),"Top Up Balance"]}),o.jsxs(fe,{variant:"ghost",size:"sm",onClick:Y,className:"w-full gap-2",children:[o.jsx(tc,{className:"w-4 h-4"}),"Export Private Key"]}),B&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(tc,{className:"w-5 h-5 text-muted-foreground"}),o.jsx("h3",{className:"text-lg font-semibold",children:"Export Setu Private Key"})]}),o.jsxs("div",{className:"p-6",children:[o.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Keep this private key secret. Anyone with this key can spend funds from your Setu wallet."}),f&&o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx($e,{className:"w-4 h-4 animate-spin"}),"Exporting private key..."]}),!f&&u&&o.jsxs("div",{className:"space-y-3",children:[o.jsx("textarea",{readOnly:!0,value:u,className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground outline-none font-mono text-xs resize-y"}),o.jsxs(fe,{variant:"secondary",size:"sm",onClick:P,className:"w-full gap-2",children:[m?o.jsx(Dn,{className:"w-4 h-4 text-green-500"}):o.jsx(oo,{className:"w-4 h-4"}),m?"Copied":"Copy Private Key"]})]}),!f&&x&&o.jsx("p",{className:"text-sm text-red-500 mt-3",children:x}),o.jsx("div",{className:"flex gap-3 mt-5",children:o.jsx("button",{type:"button",onClick:Z,disabled:f,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Close"})})]})]})})]})}),AH=k.memo(function(){const e=Zt(n=>n.isExpanded),t=Zt(n=>n.toggleSidebar);return o.jsx("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Settings",children:o.jsx(Lf,{className:"w-5 h-5 text-muted-foreground mx-auto"})})});async function eH(){const A=await fetch(`${Rs}/v1/tunnel/status`);if(!A.ok)throw new Error("Failed to fetch tunnel status");return A.json()}async function tH(){return(await fetch(`${Rs}/v1/tunnel/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})})).json()}async function nH(){return(await fetch(`${Rs}/v1/tunnel/stop`,{method:"POST"})).json()}function rH(){const A=He(r=>r.setStatus),e=He(r=>r.setUrl),t=He(r=>r.setError),n=bt({queryKey:["tunnel","status"],queryFn:eH,refetchInterval:3e3});return k.useEffect(()=>{n.data&&(A(n.data.status),e(n.data.url),t(n.data.error))},[n.data,A,e,t]),n}function sH(){const A=Ye(),e=He(s=>s.setStatus),t=He(s=>s.setUrl),n=He(s=>s.setError),r=He(s=>s.setProgress);return it({mutationFn:()=>tH(),onMutate:()=>{e("starting"),r("Connecting..."),n(null)},onSuccess:s=>{s.ok&&s.url?(e("connected"),t(s.url),r(null)):s.ok||(e("error"),n(s.error||"Failed to start tunnel"),r(null)),A.invalidateQueries({queryKey:["tunnel"]})},onError:s=>{e("error"),n(s.message),r(null)}})}function oH(){const A=Ye(),e=He(t=>t.reset);return it({mutationFn:nH,onSuccess:()=>{e(),A.invalidateQueries({queryKey:["tunnel"]})}})}function iH(){const A=He(a=>a.setStatus),e=He(a=>a.setUrl),t=He(a=>a.setError),n=He(a=>a.setProgress),r=He(a=>a.isExpanded),s=k.useRef(null),i=k.useCallback(()=>{s.current&&s.current.close();const a=new EventSource(`${Rs}/v1/tunnel/stream`);return s.current=a,a.onmessage=g=>{try{const c=JSON.parse(g.data);c.type==="status"&&(A(c.status),e(c.url),t(c.error),n(c.progress))}catch{}},a.onerror=()=>{a.close(),s.current=null},()=>{a.close(),s.current=null}},[A,e,t,n]);return k.useEffect(()=>r?i():()=>{s.current&&(s.current.close(),s.current=null)},[r,i]),{connect:i}}function aH(A){try{const t=new URL(A).hostname;return t.length>24?`${t.slice(0,12)}...${t.slice(-8)}`:t}catch{return A.length>24?`${A.slice(0,12)}...${A.slice(-8)}`:A}}const gH=k.memo(function(){const e=He(d=>d.isExpanded),t=He(d=>d.collapseSidebar),n=He(d=>d.status),r=He(d=>d.url),s=He(d=>d.error),i=He(d=>d.progress),a=sH(),g=oH(),[c,l]=k.useState(!1);rH(),iH();const B=async()=>{r&&(await navigator.clipboard.writeText(r),l(!0),setTimeout(()=>l(!1),2e3))},Q=()=>{a.mutate()},u=()=>{g.mutate()};return e?o.jsxs("div",{className:"w-80 border-l border-sidebar-border sidebar-fade-in flex flex-col h-full",children:[o.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(gs,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium text-sm",children:"Remote Access"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"Close sidebar",children:o.jsx(Dt,{className:"w-4 h-4"})})]}),o.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[n==="idle"&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[o.jsx(gs,{className:"w-12 h-12 text-muted-foreground/30 mb-4"}),o.jsx("h3",{className:"text-sm font-medium mb-2",children:"Access from anywhere"}),o.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[200px]",children:"Start a secure tunnel to access otto from your phone or another device."}),o.jsx("button",{type:"button",onClick:Q,disabled:a.isPending,className:"px-4 py-2 bg-primary text-primary-foreground rounded-md text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:a.isPending?"Starting...":"Start Tunnel"})]}),n==="starting"&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[o.jsx($e,{className:"w-8 h-8 text-primary animate-spin mb-4"}),o.jsx("h3",{className:"text-sm font-medium mb-2",children:"Setting up..."}),i&&o.jsx("p",{className:"text-xs text-muted-foreground max-w-[220px] break-words",children:i})]}),n==="connected"&&r&&o.jsxs("div",{className:"flex flex-col",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[o.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),o.jsx("span",{className:"text-xs font-medium text-green-600",children:"Connected"})]}),o.jsx("div",{className:"flex justify-center pb-4",children:o.jsx("div",{className:"p-3 bg-white rounded-lg",children:o.jsx(Hl,{value:r,size:160,level:"M",includeMargin:!1})})}),o.jsx("p",{className:"text-xs text-muted-foreground mb-4 text-center",children:"Scan with your phone camera"}),o.jsxs("div",{className:"flex items-center justify-between text-sm mb-4",children:[o.jsx("span",{className:"text-muted-foreground",children:"URL"}),o.jsxs("button",{type:"button",onClick:B,className:"flex items-center gap-1.5 font-mono text-foreground hover:text-muted-foreground transition-colors",title:"Copy URL",children:[aH(r),c?o.jsx(Dn,{className:"w-3 h-3 text-green-500"}):o.jsx(oo,{className:"w-3 h-3 text-muted-foreground"})]})]}),o.jsxs("button",{type:"button",onClick:()=>Br(r),className:"flex items-center justify-center gap-2 px-4 py-2 border border-border rounded-md text-sm hover:bg-muted transition-colors mb-3",children:[o.jsx(rn,{className:"w-3.5 h-3.5"}),"Open in browser"]}),o.jsx("button",{type:"button",onClick:u,disabled:g.isPending,className:"w-full px-4 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:g.isPending?"Stopping...":"Stop Tunnel"})]}),n==="error"&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[s?.includes("Rate limited")?o.jsxs(o.Fragment,{children:[o.jsx(ZQ,{className:"w-8 h-8 text-yellow-500 mb-4"}),o.jsx("h3",{className:"text-sm font-medium mb-2",children:"Rate Limited"}),o.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[220px]",children:"Cloudflare limits anonymous tunnel requests. Please wait 5-10 minutes before trying again."})]}):o.jsxs(o.Fragment,{children:[o.jsx(wr,{className:"w-8 h-8 text-destructive mb-4"}),o.jsx("h3",{className:"text-sm font-medium mb-2",children:"Connection failed"}),o.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[200px]",children:s||"Unable to establish tunnel connection."})]}),o.jsx("button",{type:"button",onClick:Q,disabled:a.isPending||s?.includes("Rate limited"),className:"px-4 py-2 bg-primary text-primary-foreground rounded-md text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",title:s?.includes("Rate limited")?"Wait 5-10 minutes":void 0,children:s?.includes("Rate limited")?"Wait & Try Again":"Try Again"})]})]})]}):null}),cH=k.memo(function(){const e=He(s=>s.isExpanded),t=He(s=>s.toggleSidebar),r=He(s=>s.status)==="connected";return o.jsxs("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Remote Access",children:[o.jsx(gs,{className:"w-5 h-5 text-muted-foreground mx-auto"}),r&&o.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full animate-pulse"})]})});function lH(){const A=ct(t=>t.setServers),e=bt({queryKey:["mcp","servers"],queryFn:async()=>{const{data:t}=await Ub();return t},refetchInterval:1e4});return k.useEffect(()=>{e.data?.servers&&A(e.data.servers)},[e.data,A]),e}function uH(){const A=Ye();return it({mutationFn:async e=>{const{data:t,error:n}=await Ob({path:{name:e}});if(n)throw new Error("Failed to start server");const r=t;if(!r.ok)throw new Error(r.error||"Failed to start server");return r},onSettled:()=>{A.invalidateQueries({queryKey:["mcp","servers"]})}})}function BH(){const A=Ye(),e=ct(t=>t.setLoading);return it({mutationFn:async t=>{e(t,!0);const{data:n,error:r}=await Kb({path:{name:t}});if(r)throw new Error("Failed to stop server");const s=n;if(!s.ok)throw new Error(s.error||"Failed to stop server");return s},onSettled:(t,n,r)=>{e(r,!1),A.invalidateQueries({queryKey:["mcp","servers"]})}})}function QH(){const A=Ye();return it({mutationFn:async e=>{const{data:t,error:n}=await Tb({body:e});if(n)throw new Error("Failed to add MCP server");const r=t;if(!r.ok)throw new Error(r.error||"Failed to add MCP server");return r},onSuccess:()=>{A.invalidateQueries({queryKey:["mcp","servers"]})}})}function EH(){const A=Ye();return it({mutationFn:async e=>{const{data:t,error:n}=await Lb({path:{name:e}});if(n)throw new Error("Failed to remove MCP server");const r=t;if(!r.ok)throw new Error(r.error||"Failed to remove MCP server");return r},onSuccess:()=>{A.invalidateQueries({queryKey:["mcp","servers"]})}})}function dH(){const A=Ye();return it({mutationFn:async e=>{const{data:t,error:n}=await jb({path:{name:e}});if(n)throw new Error("Failed to initiate auth");const r=t;if(!r.ok)throw new Error(r.error||"Failed to initiate auth");return r},onSettled:()=>{A.invalidateQueries({queryKey:["mcp","servers"]})}})}function CH(A){return bt({queryKey:["mcp","auth",A],queryFn:async()=>{if(!A)return{authenticated:!1};const{data:e}=await qb({path:{name:A}});return e},enabled:!!A,refetchInterval:3e3})}function IH(){const A=ct(i=>i.copilotDevice),e=ct(i=>i.setCopilotDevice),t=ct(i=>i.setLoading),n=Ye(),r=k.useRef(null),s=k.useCallback(()=>{r.current&&(clearInterval(r.current),r.current=null)},[]);return k.useEffect(()=>{if(!A){s();return}const{sessionId:i,serverName:a,interval:g}=A,c=(g||5)*1e3+1e3;return r.current=setInterval(async()=>{try{const{data:l}=await Jb({path:{name:a},body:{sessionId:i}}),B=l;B?.status==="complete"?(s(),e(null),t(a,!1),n.invalidateQueries({queryKey:["mcp","servers"]})):B?.status==="error"&&(s(),e(null),t(a,!1))}catch{s(),e(null),t(a,!1)}},c),s},[A,e,t,n,s]),A}function fH(A){const e=A.trim().split(/\s+/);return{command:e[0]??"",args:e.slice(1)}}function hH(A){const e=A.trim();if(!e)return;const t={};for(const n of e.split(`
180
180
  `)){const r=n.indexOf("=");r>0&&(t[n.slice(0,r).trim()]=n.slice(r+1).trim())}return Object.keys(t).length>0?t:void 0}function pH(A){const e=A.trim();if(!e)return;const t={};for(const n of e.split(`
181
181
  `)){const r=n.indexOf(":");r>0&&(t[n.slice(0,r).trim()]=n.slice(r+1).trim())}return Object.keys(t).length>0?t:void 0}const mH=k.memo(function({isOpen:e,onClose:t}){const[n,r]=k.useState("local"),[s,i]=k.useState(""),[a,g]=k.useState(""),[c,l]=k.useState(""),[B,Q]=k.useState("http"),[u,d]=k.useState(""),[f,h]=k.useState(""),[x,b]=k.useState("global"),[m,M]=k.useState(null),G=QH(),Y=k.useCallback(()=>{i(""),g(""),l(""),Q("http"),d(""),h(""),b("global"),M(null),r("local")},[]),Z=k.useCallback(()=>{Y(),t()},[Y,t]),P=k.useCallback(async()=>{M(null);const U=s.trim();if(!U){M("Server name is required");return}try{if(n==="local"){const w=a.trim();if(!w){M("Command is required");return}if(/^https?:\/\//i.test(w)){M("Local commands cannot be URLs. Switch to Remote (HTTP) for remote servers.");return}const{command:E,args:C}=fH(w);await G.mutateAsync({name:U,transport:"stdio",command:E,args:C,env:hH(f),scope:x})}else{const w=c.trim();if(!w){M("URL is required");return}await G.mutateAsync({name:U,transport:B,url:w,headers:pH(u),scope:x})}Z()}catch(w){M(w instanceof Error?w.message:"Failed to add server")}},[s,n,a,f,c,B,u,x,G,Z]),L=k.useRef(null),[q,v]=k.useState(void 0);return k.useEffect(()=>{const U=L.current;if(!U)return;const w=new ResizeObserver(()=>{v(U.scrollHeight)});return w.observe(U),()=>w.disconnect()},[]),o.jsx(ds,{isOpen:e,onClose:Z,title:"Add MCP Server",children:o.jsx("div",{className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:q!==void 0?q:"auto"},children:o.jsxs("div",{ref:L,className:"space-y-4",children:[o.jsxs("div",{className:"relative flex w-full rounded-lg bg-muted p-1",children:[o.jsx("div",{className:"absolute top-1 bottom-1 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:n==="local"?"4px":"50%",right:n==="remote"?"4px":"50%"}}),o.jsxs("button",{type:"button",onClick:()=>r("local"),className:`relative z-10 flex items-center justify-center gap-2 flex-1 text-sm font-medium py-2 rounded-md transition-colors duration-200 ${n==="local"?"text-foreground":"text-muted-foreground/50"}`,children:[o.jsx(Pn,{className:"w-4 h-4"}),"Local (stdio)"]}),o.jsxs("button",{type:"button",onClick:()=>r("remote"),className:`relative z-10 flex items-center justify-center gap-2 flex-1 text-sm font-medium py-2 rounded-md transition-colors duration-200 ${n==="remote"?"text-foreground":"text-muted-foreground/50"}`,children:[o.jsx(gs,{className:"w-4 h-4"}),"Remote (HTTP)"]})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Name"}),o.jsx(Yg,{value:s,onChange:U=>i(U.target.value),placeholder:"e.g. github, linear, helius",autoFocus:!0})]}),n==="local"?o.jsxs(o.Fragment,{children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Command"}),o.jsx(Yg,{value:a,onChange:U=>g(U.target.value),placeholder:"e.g. npx -y @modelcontextprotocol/server-github",onKeyDown:U=>{U.key==="Enter"&&P()}}),o.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Like"," ",o.jsx("code",{className:"bg-muted px-1 rounded",children:"npx -y helius-mcp@latest"})]})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Environment Variables"}),o.jsx("textarea",{value:f,onChange:U=>h(U.target.value),placeholder:`GITHUB_TOKEN=ghp_xxx
182
- API_KEY=sk-xxx`,rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: KEY=VALUE"})]})]}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"URL"}),o.jsx(Yg,{value:c,onChange:U=>l(U.target.value),placeholder:"e.g. https://mcp.linear.app/mcp",onKeyDown:U=>{U.key==="Enter"&&P()}})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Transport"}),o.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[o.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:B==="http"?"2px":"50%",right:B==="sse"?"2px":"50%"}}),o.jsx("button",{type:"button",onClick:()=>Q("http"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${B==="http"?"text-foreground":"text-muted-foreground/50"}`,children:"HTTP (recommended)"}),o.jsx("button",{type:"button",onClick:()=>Q("sse"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${B==="sse"?"text-foreground":"text-muted-foreground/50"}`,children:"SSE (legacy)"})]})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Headers"}),o.jsx("textarea",{value:u,onChange:U=>d(U.target.value),placeholder:"Authorization: Bearer xxx",rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: Header-Name: value"})]}),o.jsx("p",{className:"text-xs text-muted-foreground",children:"For OAuth servers (Linear, Notion, etc.), leave headers empty and authenticate after adding."})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Scope"}),o.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[o.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:x==="global"?"2px":"50%",right:x==="project"?"2px":"50%"}}),o.jsxs("button",{type:"button",onClick:()=>b("global"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${x==="global"?"text-foreground":"text-muted-foreground/50"}`,children:[o.jsx($Q,{className:"w-3 h-3"}),"All projects"]}),o.jsxs("button",{type:"button",onClick:()=>b("project"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${x==="project"?"text-foreground":"text-muted-foreground/50"}`,children:[o.jsx(Wi,{className:"w-3 h-3"}),"This project only"]})]}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:x==="global"?"Saved to ~/.config/otto/config.json":"Saved to .otto/config.json (project-local)"})]}),m&&o.jsx("div",{className:"text-sm text-red-400 bg-red-500/10 px-3 py-2 rounded",children:m}),o.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o.jsx(fe,{variant:"ghost",onClick:Z,children:"Cancel"}),o.jsx(fe,{variant:"primary",onClick:P,disabled:G.isPending,children:G.isPending?o.jsxs(o.Fragment,{children:[o.jsx($e,{className:"w-3 h-3 animate-spin mr-1"}),"Adding..."]}):"Add Server"})]})]})})})}),wH=k.memo(function({checked:e,loading:t,onChange:n,disabled:r}){return o.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:r||t,onClick:s=>{s.stopPropagation(),n()},className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors duration-200 focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed ${e?"bg-green-500":"bg-muted-foreground/30"}`,children:o.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full transition-transform duration-200 ${e?"translate-x-[18px]":"translate-x-[3px]"} ${t?"bg-transparent":"bg-white"}`,children:t&&o.jsx($e,{className:"w-3.5 h-3.5 animate-spin text-white"})})})}),xH=k.memo(function({userCode:e,verificationUri:t}){const[n,r]=k.useState(!1),s=k.useCallback(()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),2e3)})},[e]);return o.jsx("div",{className:"px-3 pb-2.5 pt-0",children:o.jsxs("div",{className:"rounded-md bg-yellow-500/10 border border-yellow-500/20 p-2 space-y-1.5",children:[o.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[o.jsx($e,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),o.jsx("span",{className:"text-yellow-500/80",children:"Enter code at GitHub:"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("code",{className:"text-sm font-mono font-bold text-yellow-400 tracking-wider",children:e}),o.jsx("button",{type:"button",onClick:s,className:"text-yellow-500/60 hover:text-yellow-400 transition-colors",title:"Copy code",children:o.jsx(_1,{className:"w-3.5 h-3.5"})}),n&&o.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),o.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",onClick:i=>{i.preventDefault(),Br(t)},className:"inline-flex items-center gap-1 text-xs text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open GitHub login",o.jsx(rn,{className:"w-3 h-3"})]})]})})}),yH=k.memo(function({server:e,isLoading:t,authUrl:n,copilotDevice:r,onStart:s,onStop:i,onRemove:a,onAuth:g}){const[c,l]=k.useState(!1),B=e.connected&&e.tools.length>0,Q=e.transport==="http"||e.transport==="sse",u=(!!n||!!r)&&!e.connected,d=k.useCallback(()=>{e.authRequired&&!e.connected?g():e.connected?i():s()},[e.connected,e.authRequired,g,i,s]),f=k.useCallback(()=>{B&&l(h=>!h)},[B]);return o.jsxs("div",{className:`rounded-lg border transition-colors duration-200 group ${e.connected?"border-green-500/30 bg-green-500/5":u?"border-yellow-500/30 bg-yellow-500/5":"border-border bg-transparent"}`,children:[o.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[o.jsx(wH,{checked:e.connected,loading:t||u,onChange:d}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"text-sm font-medium truncate",children:e.name}),Q&&o.jsx(gs,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),e.authRequired&&!e.connected&&o.jsx(z1,{className:"w-3 h-3 text-yellow-500 flex-shrink-0"})]}),o.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[o.jsx("span",{className:"text-xs text-muted-foreground truncate",children:Q?e.url:`${e.command??""} ${e.args.join(" ")}`}),o.jsx("span",{className:"flex items-center flex-shrink-0 opacity-50",title:e.scope==="project"?"Project-local":"Global",children:e.scope==="project"?o.jsx(Wi,{className:"w-3 h-3"}):o.jsx($Q,{className:"w-3 h-3"})})]})]}),o.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[B&&o.jsxs("button",{type:"button",onClick:f,className:"flex items-center gap-0.5 text-xs text-muted-foreground hover:text-foreground px-1.5 py-1 rounded transition-colors",children:[o.jsx(W1,{className:"w-3 h-3"}),e.tools.length,c?o.jsx(xn,{className:"w-3 h-3"}):o.jsx(Dt,{className:"w-3 h-3"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:a,title:"Remove server",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity",children:o.jsx(Ma,{className:"w-3 h-3 text-muted-foreground hover:text-red-400"})})]})]}),r&&!e.connected&&o.jsx(xH,{userCode:r.userCode,verificationUri:r.verificationUri}),!r&&u&&n&&o.jsx("div",{className:"px-3 pb-2.5 pt-0",children:o.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[o.jsx($e,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),o.jsx("span",{className:"text-yellow-500/80",children:"Waiting for auth..."}),o.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",onClick:h=>{h.preventDefault(),Br(n)},className:"inline-flex items-center gap-0.5 text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open login",o.jsx(rn,{className:"w-3 h-3"})]})]})}),B&&c&&o.jsx("div",{className:"px-3 pb-2.5 pt-0",children:o.jsx("div",{className:"flex flex-wrap gap-1",children:e.tools.map(h=>o.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",title:h,children:h.split("__").pop()},h))})})]})});function DH(A,e){const{data:t}=CH(A),n=k.useRef(!1);k.useEffect(()=>{t?.authenticated&&!n.current&&e(),n.current=t?.authenticated??!1},[t?.authenticated,e])}const bH=k.memo(function(){const e=ct(U=>U.isExpanded),t=ct(U=>U.collapseSidebar),n=ct(U=>U.servers),r=ct(U=>U.loading),s=ct(U=>U.authUrls),i=ct(U=>U.setAuthUrl),a=ct(U=>U.setLoading),g=ct(U=>U.setCopilotDevice),{isLoading:c}=lH(),l=uH(),B=BH(),Q=EH(),u=dH(),d=IH(),[f,h]=k.useState(!1),[x,b]=k.useState(null),[m,M]=k.useState(null),G=Ye(),Y=k.useCallback(()=>{x&&(i(x,null),b(null),G.invalidateQueries({queryKey:["mcp","servers"]}))},[x,i,G]);DH(x,Y),k.useEffect(()=>{for(const U of r)n.find(E=>E.name===U)?.connected&&a(U,!1)},[n,r,a]);const Z=k.useCallback((U,w)=>{w.sessionId&&w.userCode&&w.verificationUri&&(g({sessionId:w.sessionId,userCode:w.userCode,verificationUri:w.verificationUri,interval:w.interval??5,serverName:U}),Br(w.verificationUri))},[g]),P=k.useCallback(async U=>{try{a(U,!0);const w=await u.mutateAsync(U);if(w.authType==="copilot-device"){if(w.authenticated){a(U,!1),G.invalidateQueries({queryKey:["mcp","servers"]});return}Z(U,w)}else w.authUrl?(i(U,w.authUrl),b(U),Br(w.authUrl)):a(U,!1)}catch{a(U,!1),i(U,null)}},[u,i,a,Z,G]),L=k.useCallback(async U=>{try{a(U,!0);const w=await l.mutateAsync(U);w.authType==="copilot-device"&&!w.connected?Z(U,w):w.authRequired&&w.authUrl?(i(U,w.authUrl),b(U),Br(w.authUrl)):a(U,!1)}catch{a(U,!1),i(U,null)}},[l,i,a,Z]),q=k.useMemo(()=>[...n].sort((U,w)=>U.connected&&!w.connected?-1:!U.connected&&w.connected?1:U.name.localeCompare(w.name)),[n]);if(!e)return null;const v=n.filter(U=>U.connected).length;return o.jsxs("div",{className:"w-80 border-l border-sidebar-border sidebar-fade-in flex flex-col h-full",children:[o.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(va,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium text-sm",children:"MCP Servers"}),v>0&&o.jsxs("span",{className:"text-xs bg-green-500/20 text-green-400 px-1.5 py-0.5 rounded-full",children:[v," active"]})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>h(!0),title:"Add MCP server",className:"h-7 w-7",children:o.jsx(Qr,{className:"w-4 h-4"})}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"Close sidebar",children:o.jsx(Dt,{className:"w-4 h-4"})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:c&&n.length===0?o.jsxs("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:[o.jsx($e,{className:"w-4 h-4 animate-spin mr-2"}),"Loading..."]}):n.length===0?o.jsxs("div",{className:"p-4 text-sm text-muted-foreground space-y-3",children:[o.jsx("p",{children:"No MCP servers configured."}),o.jsxs(fe,{variant:"primary",size:"sm",onClick:()=>h(!0),className:"w-full",children:[o.jsx(Qr,{className:"w-3 h-3 mr-1"}),"Add MCP Server"]}),o.jsxs("p",{className:"text-xs",children:["Or add servers to"," ",o.jsx("code",{className:"bg-muted px-1 py-0.5 rounded text-xs",children:".otto/config.json"})]})]}):o.jsx("div",{className:"p-2 space-y-1.5",children:q.map(U=>o.jsx(yH,{server:U,isLoading:r.has(U.name),authUrl:s.get(U.name),copilotDevice:d?.serverName===U.name?d:null,onStart:()=>L(U.name),onStop:()=>B.mutate(U.name),onRemove:()=>M(U.name),onAuth:()=>P(U.name)},U.name))})}),o.jsx(mH,{isOpen:f,onClose:()=>h(!1)}),o.jsxs(ds,{isOpen:!!m,onClose:()=>M(null),title:"Remove MCP Server",maxWidth:"sm",showCloseButton:!1,children:[o.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Are you sure you want to remove"," ",o.jsx("span",{className:"font-medium text-foreground",children:m}),"? This will stop the server and remove its configuration."]}),o.jsxs("div",{className:"flex justify-end gap-2",children:[o.jsx(fe,{variant:"secondary",size:"sm",onClick:()=>M(null),children:"Cancel"}),o.jsx(fe,{variant:"primary",size:"sm",className:"bg-red-500 hover:bg-red-600 text-white",onClick:()=>{m&&Q.mutate(m),M(null)},children:"Remove"})]})]})]})}),NH=k.memo(function(){const e=ct(s=>s.isExpanded),t=ct(s=>s.toggleSidebar),r=ct(s=>s.servers).filter(s=>s.connected).length;return o.jsxs("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"MCP Servers",children:[o.jsx(va,{className:"w-5 h-5 text-muted-foreground mx-auto"}),r>0&&o.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full"})]})});function kH(){const A=Bt(t=>t.setSkills),e=bt({queryKey:["skills"],queryFn:async()=>xA.listSkills(),refetchInterval:3e4});return k.useEffect(()=>{e.data?.skills&&A(e.data.skills)},[e.data,A]),e}function n1(A){return bt({queryKey:["skills",A],queryFn:async()=>A?xA.getSkill(A):null,enabled:!!A})}function MH(A){return bt({queryKey:["skills",A,"files"],queryFn:async()=>A?xA.getSkillFiles(A):null,enabled:!!A})}function vH(A,e){return bt({queryKey:["skills",A,"files",e],queryFn:async()=>!A||!e?null:xA.getSkillFileContent(A,e),enabled:!!A&&!!e})}const SH={cwd:Wi,parent:Wi,repo:Wi,user:$Q,system:gs},df={cwd:"Project",parent:"Parent",repo:"Repository",user:"User",system:"System"};function FH(A){return A<1024?`${A} B`:A<1024*1024?`${(A/1024).toFixed(1)} KB`:`${(A/(1024*1024)).toFixed(1)} MB`}const GH=k.memo(function(){const e=Bt(u=>u.isExpanded),t=Bt(u=>u.collapseSidebar),n=Bt(u=>u.skills),r=Bt(u=>u.selectedSkill),s=Bt(u=>u.selectSkill),i=Bt(u=>u.openViewer),a=Bt(u=>u.viewingFile),{isLoading:g}=kH(),{data:c}=n1(r),{data:l}=MH(r),B=l?.files??[],Q=k.useMemo(()=>{const u=new Map;for(const d of n){const f=u.get(d.scope)??[];f.push(d),u.set(d.scope,f)}return u},[n]);return e?o.jsxs("div",{className:"w-80 border-l border-sidebar-border sidebar-fade-in flex flex-col h-full",children:[o.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Rr,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium text-sm",children:"Skills"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"Close sidebar",children:o.jsx(Dt,{className:"w-4 h-4"})})]}),r&&c?o.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o.jsx("div",{className:"p-3 border-b border-border",children:o.jsx("button",{type:"button",onClick:()=>s(null),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"← Back to list"})}),o.jsxs("div",{className:"px-3 py-3 border-b border-border",children:[o.jsx("h3",{className:"font-medium text-sm mb-1",children:c.name}),o.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:c.description}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:df[c.scope]??c.scope}),c.license&&o.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:c.license})]})]}),o.jsxs("div",{className:"py-1",children:[o.jsx("div",{className:"flex items-center gap-1.5 px-3 py-2 text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:"Files"}),o.jsx("button",{type:"button",onClick:()=>i(null),className:`w-full text-left px-3 py-2 hover:bg-accent transition-colors ${a===null?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(so,{className:"w-3.5 h-3.5 flex-shrink-0 text-muted-foreground"}),o.jsx("span",{className:"text-sm font-mono truncate flex-1",children:"SKILL.md"})]})}),B.map(u=>o.jsx("button",{type:"button",onClick:()=>i(u.relativePath),className:`w-full text-left px-3 py-2 hover:bg-accent transition-colors ${a===u.relativePath?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(qc,{className:"w-3.5 h-3.5 flex-shrink-0 text-muted-foreground"}),o.jsx("span",{className:"text-sm font-mono truncate flex-1",children:u.relativePath}),o.jsx("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:FH(u.size)})]})},u.relativePath))]})]}):o.jsx("div",{className:"flex-1 overflow-y-auto",children:g?o.jsx("div",{className:"flex items-center justify-center py-8",children:o.jsx($e,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):n.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center p-4",children:[o.jsx(Rr,{className:"w-12 h-12 text-muted-foreground/30 mb-4"}),o.jsx("h3",{className:"text-sm font-medium mb-2",children:"No skills found"}),o.jsxs("p",{className:"text-xs text-muted-foreground max-w-[220px]",children:["Create skills in"," ",o.jsx("code",{className:"text-[10px] bg-muted px-1 rounded",children:".otto/skills/"})," ","or"," ",o.jsx("code",{className:"text-[10px] bg-muted px-1 rounded",children:"~/.config/otto/skills/"})]})]}):o.jsx("div",{className:"py-1",children:["cwd","parent","repo","user","system"].map(u=>{const d=Q.get(u);if(!d?.length)return null;const f=SH[u]??gs;return o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:[o.jsx(f,{className:"w-3 h-3"}),df[u]??u]}),d.map(h=>o.jsx("button",{type:"button",onClick:()=>s(h.name),className:`w-full text-left px-3 py-2 hover:bg-accent transition-colors ${r===h.name?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(so,{className:"w-3.5 h-3.5 flex-shrink-0 text-muted-foreground"}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"text-sm font-medium truncate",children:h.name}),o.jsx("div",{className:"text-xs text-muted-foreground truncate",children:h.description})]})]})},`${h.scope}-${h.name}`))]},u)})})})]}):null}),RH=k.memo(function(){const e=Bt(n=>n.isExpanded),t=Bt(n=>n.toggleSidebar);return o.jsx("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Skills",children:o.jsx(Rr,{className:"w-5 h-5 text-muted-foreground mx-auto"})})}),UH={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"plaintext",toml:"toml"};function TH(A){const e=A.split(".").pop()?.toLowerCase()??"";return UH[e]??"plaintext"}const LH=k.memo(function(){const e=Bt(d=>d.isViewerOpen),t=Bt(d=>d.viewingFile),n=Bt(d=>d.selectedSkill),r=Bt(d=>d.closeViewer),{data:s}=n1(n),{data:i,isLoading:a}=vH(n,t),g=t===null,c=g?s?.content:i?.content,l=g?!s:a,B=g?"SKILL.md":t??"",Q=TH(B);if(k.useEffect(()=>{const d=f=>{const h=f.target,x=h.tagName==="INPUT"||h.tagName==="TEXTAREA"||h.isContentEditable;(f.key==="Escape"||f.key==="q"&&!x)&&e&&r()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,r]),!e||!n)return null;const u=document?.documentElement.classList.contains("dark")?rr:sr;return o.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[o.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:r,title:"Close viewer (ESC)",children:o.jsx(yt,{className:"w-4 h-4"})}),o.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:n}),o.jsx("span",{className:"text-xs text-muted-foreground",children:"/"}),o.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:B,children:B})]}),o.jsx("span",{className:"text-xs text-muted-foreground",children:Q})]}),o.jsx("div",{className:"flex-1 overflow-auto",children:l?o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Loading..."}):c?o.jsx("div",{className:"code-with-line-numbers",children:o.jsx(fn,{language:Q,style:u,wrapLines:!0,wrapLongLines:!0,lineProps:()=>({className:"code-line"}),customStyle:{margin:0,padding:"1rem",background:"transparent",fontSize:"0.75rem",lineHeight:"1.25rem"},codeTagProps:{style:{flex:1}},children:c})}):o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Unable to load file"})})]})}),Cf="file-browser",If=320,OH=280,KH=600;function jH({dirPath:A}){const t=Qt(s=>s.expandedDirs).has(A),{data:n,isLoading:r}=qy(A,t);return t?r?o.jsx("div",{className:"pl-4 py-1 text-xs text-muted-foreground",children:"Loading..."}):o.jsx("div",{className:"pl-3",children:n?.items.map(s=>o.jsx(r1,{name:s.name,path:s.path,type:s.type,gitignored:s.gitignored},s.path))}):null}function r1({name:A,path:e,type:t,gitignored:n}){const r=Qt(B=>B.expandedDirs),s=Qt(B=>B.toggleDir),i=Qt(B=>B.openFile),a=Qt(B=>B.selectedFile),g=r.has(e),c=a===e,l=k.useCallback(()=>{t==="directory"?s(e):i(e)},[t,e,s,i]);return o.jsxs("div",{children:[o.jsxs("button",{type:"button",onClick:l,className:`w-full text-left flex items-center gap-1.5 px-2 py-1 text-sm hover:bg-muted/50 rounded transition-colors ${c?"bg-muted text-foreground":"text-foreground/80"} ${n?"opacity-40":""}`,children:[t==="directory"?o.jsxs(o.Fragment,{children:[g?o.jsx(xn,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}):o.jsx(Dt,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),g?o.jsx(kf,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"}):o.jsx(Mf,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"})]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"w-3 flex-shrink-0"}),o.jsx(qc,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"})]}),o.jsx("span",{className:"truncate",children:A})]}),t==="directory"&&o.jsx(jH,{dirPath:e})]})}const JH=k.memo(function(){const e=Qt(a=>a.isExpanded),t=Qt(a=>a.collapseSidebar),n=ks(a=>a.widths[Cf]??If),{data:r,isLoading:s,refetch:i}=qy(".");return e?o.jsxs("div",{className:"border-l border-sidebar-border sidebar-fade-in flex h-full relative",style:{width:n},children:[o.jsx(fi,{panelKey:Cf,side:"right",minWidth:OH,maxWidth:KH,defaultWidth:If}),o.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[o.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Aa,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium",children:"Files"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,children:o.jsx(Dt,{className:"w-4 h-4"})})]}),o.jsx("div",{className:"flex-1 overflow-y-auto p-1",children:s?o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading file tree..."}):!r||r.items.length===0?o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No files found"}):r.items.map(a=>o.jsx(r1,{name:a.name,path:a.path,type:a.type,gitignored:a.gitignored},a.path))}),o.jsxs("div",{className:"h-12 px-4 border-t border-border text-xs text-muted-foreground flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[o.jsx(Aa,{className:"w-3 h-3 flex-shrink-0"}),o.jsx("span",{className:"truncate",children:"Project Files"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>i(),title:"Refresh file tree",className:"h-6 w-6 flex-shrink-0",disabled:s,children:o.jsx(Sn,{className:`w-3 h-3 ${s?"animate-spin":""}`})})]})]})]}):null}),qH=k.memo(function(){const e=Qt(n=>n.isExpanded),t=Qt(n=>n.toggleSidebar);return o.jsx("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Files",children:o.jsx(Aa,{className:"w-5 h-5 text-muted-foreground mx-auto"})})}),YH={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"plaintext",svelte:"svelte",toml:"toml",lock:"plaintext"};function HH(A){const e=A.split(".").pop()?.toLowerCase()??"";return YH[e]??"plaintext"}const PH=k.memo(function(){const e=Qt(g=>g.isViewerOpen),t=Qt(g=>g.selectedFile),n=Qt(g=>g.closeViewer),{data:r,isLoading:s}=lY(t);if(k.useEffect(()=>{const g=c=>{const l=c.target,B=l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable;(c.key==="Escape"||c.key==="q"&&!B)&&e&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[e,n]),!e||!t)return null;const i=document?.documentElement.classList.contains("dark")?rr:sr,a=HH(t);return o.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[o.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:n,title:"Close file viewer (ESC)",children:o.jsx(yt,{className:"w-4 h-4"})}),o.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:t,children:t}),r&&o.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[r.lineCount," lines"]})]}),o.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),o.jsx("div",{className:"flex-1 overflow-auto",children:s?o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Loading file..."}):r?o.jsx("div",{className:"code-with-line-numbers",children:o.jsx(fn,{language:a,style:i,wrapLines:!0,wrapLongLines:!0,lineProps:()=>({className:"code-line"}),customStyle:{margin:0,padding:"1rem",background:"transparent",fontSize:"0.75rem",lineHeight:"1.25rem"},codeTagProps:{style:{flex:1}},children:r.content})}):o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Unable to load file"})})]})}),jQ=Rt(A=>({isOpen:!1,open:()=>A({isOpen:!0}),close:()=>A({isOpen:!1}),toggle:()=>A(e=>({isOpen:!e.isOpen}))}));function _H(A,e){const t=A.toLowerCase(),n=e.toLowerCase();if(t.length===0)return{match:!0,score:0};if(n.includes(t))return{match:!0,score:100-n.indexOf(t)};let r=0,s=0,i=-1;for(let a=0;a<n.length&&r<t.length;a++)n[a]===t[r]&&(s+=10,i===a-1&&(s+=5),(a===0||n[a-1]==="/"||n[a-1]===".")&&(s+=8),i=a,r++);return{match:r===t.length,score:s}}const zH=k.memo(function(){const e=jQ(x=>x.isOpen),t=jQ(x=>x.close),n=Qt(x=>x.openFile),r=Qt(x=>x.expandSidebar),[s,i]=k.useState(""),[a,g]=k.useState(0),c=k.useRef(null),l=k.useRef(null),{data:B}=Rh(),Q=k.useMemo(()=>new Set(B?.ignoredFiles??[]),[B?.ignoredFiles]),u=k.useMemo(()=>B?.files?s?B.files.map(b=>({file:b,..._H(s,b)})).filter(b=>b.match).sort((b,m)=>m.score-b.score).slice(0,50).map(b=>b.file):B.files.slice(0,50):[],[B?.files,s]);k.useEffect(()=>{e&&(i(""),g(0),setTimeout(()=>c.current?.focus(),0))},[e]),k.useEffect(()=>{l.current?.children[a]?.scrollIntoView({block:"nearest"})},[a]);const d=k.useCallback(x=>{r(),n(x),t()},[r,n,t]),f=k.useCallback(x=>{x.key==="ArrowDown"||x.ctrlKey&&x.key==="j"?(x.preventDefault(),g(b=>Math.min(b+1,u.length-1))):x.key==="ArrowUp"||x.ctrlKey&&x.key==="k"?(x.preventDefault(),g(b=>Math.max(b-1,0))):x.key==="Enter"&&u[a]?(x.preventDefault(),d(u[a])):x.key==="Escape"&&(x.preventDefault(),t())},[u,a,d,t]),h=k.useCallback(x=>{x.target===x.currentTarget&&t()},[t]);return e?o.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 bg-black/50 flex items-start justify-center z-[60] pt-[15vh]",onClick:h,onKeyDown:x=>{x.key==="Escape"&&t()},children:o.jsxs("div",{className:"bg-background border border-border rounded-lg shadow-2xl w-full max-w-lg overflow-hidden",children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 border-b border-border",children:[o.jsx(Do,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),o.jsx("input",{ref:c,type:"text",value:s,onChange:x=>{i(x.target.value),g(0)},onKeyDown:f,placeholder:"Search files by name...",className:"flex-1 bg-transparent py-3 text-sm text-foreground placeholder-muted-foreground outline-none"}),o.jsx("kbd",{className:"text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded border border-border font-mono",children:"ESC"})]}),o.jsx("div",{ref:l,className:"max-h-[40vh] overflow-y-auto",children:u.length===0?o.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:s?"No matching files":"No files found"}):u.map((x,b)=>{const m=Q.has(x);return o.jsxs("button",{type:"button",onClick:()=>d(x),className:`w-full text-left flex items-center gap-2 px-3 py-2 text-sm transition-colors ${b===a?"bg-accent text-accent-foreground":"text-foreground/80 hover:bg-muted/50"} ${m?"opacity-40":""}`,children:[o.jsx(qc,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),o.jsx(WH,{path:x,query:s}),m&&o.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground italic",children:"ignored"})]},x)})}),u.length>0&&o.jsxs("div",{className:"px-3 py-2 border-t border-border text-xs text-muted-foreground flex items-center gap-3",children:[o.jsxs("span",{children:[o.jsx("kbd",{className:"bg-muted px-1 py-0.5 rounded border border-border font-mono",children:"↑↓"})," ","navigate"]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"bg-muted px-1 py-0.5 rounded border border-border font-mono",children:"↵"})," ","open"]}),o.jsxs("span",{className:"ml-auto",children:[u.length," files"]})]})]})}):null});function WH({path:A,query:e}){if(!e)return o.jsx("span",{className:"truncate font-mono text-xs",children:A});const t=A.toLowerCase(),n=e.toLowerCase(),r=t.indexOf(n);return r>=0?o.jsxs("span",{className:"truncate font-mono text-xs",children:[A.slice(0,r),o.jsx("span",{className:"text-primary font-semibold",children:A.slice(r,r+e.length)}),A.slice(r+e.length)]}):o.jsx("span",{className:"truncate font-mono text-xs",children:A})}const VH=k.memo(function({authStatus:e,onSetupWallet:t,onImportWallet:n,onAddProvider:r,onRemoveProvider:s,onStartOAuth:i,onStartOAuthManual:a,onExchangeOAuthCode:g,onOpenTopup:c,onNext:l,manageMode:B=!1,onClose:Q,hideHeader:u=!1,onStartCopilotDeviceFlow:d,onPollCopilotDeviceFlow:f,onGetCopilotAuthMethods:h,onSaveCopilotToken:x,onImportCopilotTokenFromGh:b,onGetCopilotDiagnostics:m}){const[M,G]=k.useState(!1),[Y,Z]=k.useState(!1),[P,L]=k.useState(!1),[q,v]=k.useState(""),[U,w]=k.useState(!1),[E,C]=k.useState(null),[y,F]=k.useState(null),[T,J]=k.useState(""),[z,R]=k.useState(null),[I,p]=k.useState(null),[K,j]=k.useState(null),[$,eA]=k.useState(""),[CA,aA]=k.useState(!1),[LA,ZA]=k.useState(!1),[EA,VA]=k.useState(null),[oe,Qe]=k.useState(!1),[vA,JA]=k.useState(null),[we,Oe]=k.useState("oauth"),[ke,Ke]=k.useState(""),[GA,te]=k.useState(!1),[se,rt]=k.useState(!1),[xe,H]=k.useState(null),[N,S]=k.useState(null),[X,tA]=k.useState(!1),[iA,cA]=k.useState(!1),[ne,re]=k.useState(!1),$A=k.useRef(void 0),Ge=k.useRef(!1),Ae=k.useRef(f);Ae.current=f;const Ve=Te(oA=>oA.balance),kn=Te(oA=>oA.usdcBalance),lt=Te(oA=>oA.payg),ut=Te(oA=>oA.subscription),Yr=Te(oA=>oA.isLoading),je=k.useRef(null),Pe=k.useRef(null),An=k.useRef(null),st=Te(oA=>oA.isTopupModalOpen),HA=k.useRef(!1),{fetchBalance:Ot}=ql("setu"),ht=lt?.effectiveSpendableUsd??Ve??0,Je=ut?.active?`GO ${(ut.creditsRemaining??0).toFixed(1)} credits`:`$${ht.toFixed(2)}`;k.useEffect(()=>{HA.current&&!st&&Ot(),HA.current=st},[st,Ot]),k.useEffect(()=>{!e.setu.configured&&!Y&&(Z(!0),t().finally(()=>Z(!1)))},[e.setu.configured,t,Y]),k.useEffect(()=>{y&&je.current&&je.current.focus()},[y]),k.useEffect(()=>{K&&Pe.current&&Pe.current.focus()},[K]),k.useEffect(()=>{P&&An.current&&An.current.focus()},[P]),k.useEffect(()=>{if(!oe||!EA||!Ae.current)return;Ge.current=!1;const oA=Math.max((EA.interval||5)*1e3+2e3,7e3),TA=()=>{$A.current=setTimeout(async()=>{if(!Ge.current)try{const YA=Ae.current;if(!YA)return;const PA=await YA(EA.sessionId);if(Ge.current)return;PA.status==="complete"?(VA(null),Qe(!1),JA(null),cA(!1)):PA.status==="error"?(JA(PA.error||"Authorization failed"),Qe(!1)):TA()}catch{Ge.current||TA()}},oA)};TA();const FA=setTimeout(()=>{Qe(!1),JA("Authorization timed out. Please try again.")},3e5);return()=>{Ge.current=!0,$A.current&&clearTimeout($A.current),clearTimeout(FA)}},[oe,EA]);const Ks=async()=>{e.setu.publicKey&&(await navigator.clipboard.writeText(e.setu.publicKey),G(!0),setTimeout(()=>G(!1),2e3))},O=oA=>`${oA.slice(0,8)}...${oA.slice(-6)}`,_=async oA=>{if(T.trim())try{await r(oA,T.trim()),F(null),J("")}catch{}},W=async oA=>{if(I===oA){R(oA);try{await s(oA)}finally{R(null),p(null)}}else p(oA)},D=()=>{p(null)},V=()=>{d&&(re(!0),JA(null),d().then(oA=>{VA(oA),re(!1)}).catch(oA=>{JA(oA instanceof Error?oA.message:"Failed to start device flow"),re(!1)}))},sA=async(oA,TA)=>{oA==="anthropic"?j({provider:oA,sessionId:null,mode:TA}):oA==="copilot"?(Oe("oauth"),Ke(""),S(null),H(null),Qe(!1),VA(null),JA(null),cA(!0),h&&h().then(FA=>H(FA)).catch(()=>{}),m&&m().then(FA=>S(FA)).catch(()=>{}),V()):i(oA,TA)},nA=async()=>{if(K){ZA(!0);try{const{sessionId:oA}=await a(K.provider,K.mode);j({...K,sessionId:oA})}catch(oA){console.error("Failed to start OAuth:",oA)}ZA(!1)}},dA=async()=>{if(!(!K||!K.sessionId||!$.trim())){aA(!0);try{await g(K.provider,$.trim(),K.sessionId),j(null),eA("")}catch{}aA(!1)}},yA=()=>{j(null),eA("")},RA=()=>{EA&&(Br(EA.verificationUri),Qe(!0))},DA=oA=>{Oe(oA),JA(null),oA==="token"&&Qe(!1),oA==="oauth"&&!EA&&!ne&&V()},Re=async()=>{if(!(!ke.trim()||!x)){te(!0),JA(null);try{await x(ke.trim()),ie()}catch(oA){JA(oA instanceof Error?oA.message:"Failed to save Copilot token")}finally{te(!1)}}},KA=async()=>{if(b){rt(!0),JA(null);try{await b(),ie()}catch(oA){JA(oA instanceof Error?oA.message:"Failed to import token from GitHub CLI")}finally{rt(!1)}}},ce=async()=>{EA&&(await navigator.clipboard.writeText(EA.userCode),tA(!0),setTimeout(()=>tA(!1),2e3))},ie=()=>{VA(null),Qe(!1),JA(null),Ke(""),te(!1),rt(!1),Oe("oauth"),tA(!1),cA(!1),re(!1),Ge.current=!0,$A.current&&(clearTimeout($A.current),$A.current=void 0)},de=()=>{C(null),v(""),L(!0)},Ee=()=>{U||(L(!1),C(null),v(""))},le=async()=>{if(!(!q.trim()||U)){w(!0),C(null);try{await n(q.trim()),L(!1),v(""),Ot()}catch(oA){C(oA instanceof Error?oA.message:"Failed to import wallet")}finally{w(!1)}}},ae=Object.entries(e.providers).filter(([oA,TA])=>TA.configured&&oA!=="setu"),ue=Object.entries(e.providers).filter(([oA,TA])=>!TA.configured&&oA!=="setu");return o.jsxs("div",{className:"min-h-screen flex flex-col",children:[!u&&o.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Mn,{provider:"setu",size:24}),o.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),!B&&o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),"Step 1 of 2"]})]}),o.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${u?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:o.jsxs("div",{className:"max-w-7xl mx-auto",children:[o.jsxs("div",{className:"mb-10",children:[o.jsx("h1",{className:"text-2xl sm:text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:B?"Manage Providers":"Welcome to otto"}),o.jsx("p",{className:"text-lg text-muted-foreground max-w-2xl",children:B?"Add or remove AI providers. Your changes are saved automatically.":"Setu is your default AI provider. GO plan credits are applied automatically."})]}),o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 sm:gap-8",children:[o.jsx("div",{children:o.jsx("div",{className:"bg-card rounded-2xl border border-border p-5",children:e.setu.configured&&e.setu.publicKey?o.jsxs("div",{className:"flex flex-col h-full",children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-green-500/10 border border-green-500/20 rounded-lg",children:[o.jsx(Mn,{provider:"setu",size:16}),o.jsx("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:"Setu"}),o.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60 ml-auto",children:"Default Provider"})]}),o.jsx("div",{className:"flex justify-center py-4 mt-4",children:o.jsx("div",{className:"bg-white p-2 rounded-lg",children:o.jsx(Hl,{value:e.setu.publicKey,size:140,level:"M"})})}),o.jsxs("div",{className:"space-y-2 mt-4",children:[o.jsxs("button",{type:"button",onClick:Ks,className:"w-full flex items-center justify-center gap-2 px-3 py-2 bg-muted hover:bg-muted/80 rounded-lg text-xs font-mono text-muted-foreground transition-colors",children:[O(e.setu.publicKey),M?o.jsx(Dn,{className:"w-3.5 h-3.5 text-green-500"}):o.jsx(oo,{className:"w-3.5 h-3.5 text-muted-foreground"})]}),o.jsxs("div",{className:"space-y-1.5 px-3 py-2 bg-muted/50 rounded-lg",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"flex items-center gap-1.5 min-w-0",children:o.jsx("span",{className:"font-mono text-xs sm:text-sm text-foreground truncate",children:Je})}),o.jsx("button",{type:"button",onClick:Ot,disabled:Yr,className:"p-0.5 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:o.jsx(Sn,{className:`w-3 h-3 ${Yr?"animate-spin":""}`})})]}),o.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["Balance $",(Ve??0).toFixed(2)," • On-chain"," ",(kn??0).toFixed(2)," USDC"]})]})]}),o.jsxs("div",{className:"flex items-center gap-4 py-4",children:[o.jsx("div",{className:"flex-1 h-px bg-border"}),o.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"OR"}),o.jsx("div",{className:"flex-1 h-px bg-border"})]}),o.jsxs("button",{type:"button",onClick:c,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:bg-primary/90 transition-colors",children:[o.jsx(ka,{className:"w-4 h-4"}),"Top Up with Card"]}),o.jsxs("button",{type:"button",onClick:de,className:"w-full mt-2 flex items-center justify-center gap-2 px-4 py-2.5 border border-border text-foreground rounded-lg text-sm font-medium hover:bg-muted/50 transition-colors",children:[o.jsx(tc,{className:"w-4 h-4"}),"Import Wallet"]})]}):o.jsx("div",{className:"flex items-center justify-center py-16",children:o.jsx($e,{className:"w-8 h-8 animate-spin text-muted-foreground"})})})}),o.jsxs("div",{className:"sm:col-span-2 space-y-6",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsx("h2",{className:"font-semibold text-foreground",children:"Connected Providers"}),ae.length>0&&o.jsxs("span",{className:"text-sm text-muted-foreground",children:[ae.length," active"]})]}),ae.length===0?o.jsx("div",{className:"text-sm text-muted-foreground py-4",children:"No providers connected yet. Add one below."}):o.jsx("div",{className:"flex flex-wrap gap-2",children:ae.map(([oA,TA])=>o.jsxs("div",{className:`flex items-center gap-2 pl-3 pr-2 py-2 rounded-full transition-all duration-200 ${I===oA?"bg-destructive/10 border border-destructive/30":"group bg-green-500/10 border border-green-500/20"}`,children:[o.jsx(Mn,{provider:oA,size:16}),o.jsx("span",{className:`text-sm font-medium transition-colors ${I===oA?"text-destructive":"text-green-600 dark:text-green-400"}`,children:TA.label}),I!==oA&&o.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60",children:TA.type==="oauth"?"OAuth":"API"}),I===oA?o.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[o.jsx("span",{className:"text-xs text-destructive/80 mr-1",children:"Remove?"}),o.jsx("button",{type:"button",onClick:()=>W(oA),disabled:z===oA,className:"px-2 py-0.5 text-xs bg-destructive text-destructive-foreground rounded hover:bg-destructive/90 transition-colors disabled:opacity-50",children:z===oA?o.jsx($e,{className:"w-3 h-3 animate-spin"}):"Yes"}),o.jsx("button",{type:"button",onClick:D,className:"px-2 py-0.5 text-xs bg-muted text-muted-foreground rounded hover:bg-muted/80 transition-colors",children:"No"})]}):oA!=="setu"&&o.jsx("button",{type:"button",onClick:()=>W(oA),className:"ml-1 p-1 text-green-600/40 dark:text-green-500/40 hover:text-green-600/80 dark:hover:text-green-500/80 opacity-0 group-hover:opacity-100 transition-opacity",children:o.jsx(yt,{className:"w-3 h-3"})})]},oA))})]}),o.jsxs("div",{children:[o.jsx("h2",{className:"font-semibold text-foreground mb-4",children:"Add Providers"}),o.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 items-start",children:ue.map(([oA,TA])=>o.jsx("div",{children:y===oA?o.jsxs("div",{className:"flex items-center gap-2 p-3 bg-card border border-ring rounded-xl overflow-hidden",children:[o.jsx("div",{className:"shrink-0",children:o.jsx(Mn,{provider:oA,size:18})}),o.jsx("input",{ref:je,type:"password",value:T,onChange:FA=>J(FA.target.value),placeholder:`${TA.label} API key...`,className:"flex-1 min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground text-foreground",onKeyDown:FA=>{FA.key==="Enter"&&_(oA),FA.key==="Escape"&&(F(null),J(""))}}),o.jsx("button",{type:"button",onClick:()=>_(oA),disabled:!T.trim(),className:"shrink-0 px-3 py-1.5 bg-primary text-primary-foreground text-sm font-medium rounded-lg disabled:opacity-50",children:"Add"}),o.jsx("button",{type:"button",onClick:()=>{F(null),J("")},className:"shrink-0 p-1.5 text-muted-foreground hover:text-foreground",children:o.jsx(yt,{className:"w-4 h-4"})})]}):o.jsxs("div",{className:"flex items-center justify-between p-3 bg-card border border-border hover:border-border/80 rounded-xl transition-colors gap-2",children:[o.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[o.jsx(Mn,{provider:oA,size:20}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"font-medium text-foreground truncate",children:TA.label}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[TA.modelCount," models"]})]})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[oA!=="copilot"&&o.jsxs("button",{type:"button",onClick:()=>F(oA),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[o.jsx(tc,{className:"w-3.5 h-3.5"}),"API"]}),TA.supportsOAuth&&o.jsxs("button",{type:"button",onClick:()=>sA(oA,oA==="anthropic"?"max":void 0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[o.jsx(rn,{className:"w-3.5 h-3.5"}),oA==="anthropic"?"Pro":oA==="copilot"?"Login":"OAuth"]})]})]})},oA))})]})]})]})]})}),o.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:o.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[!B&&o.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground hidden sm:block",children:"You can add more providers later in settings"}),B?o.jsx("button",{type:"button",onClick:Q,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors ml-auto",children:"Done"}):o.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors",children:["Continue",o.jsx(vf,{className:"w-4 h-4"})]})]})}),P&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(Mn,{provider:"setu",size:24}),o.jsx("h3",{className:"text-lg font-semibold",children:"Import Setu Wallet"})]}),o.jsxs("div",{className:"p-6",children:[o.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste your base58 private key to replace the current wallet used for Setu."}),o.jsx("textarea",{ref:An,value:q,onChange:oA=>v(oA.target.value),placeholder:"Enter private key",className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors font-mono text-xs resize-y",onKeyDown:oA=>{(oA.metaKey||oA.ctrlKey)&&oA.key==="Enter"&&(oA.preventDefault(),le()),oA.key==="Escape"&&Ee()}}),E&&o.jsx("p",{className:"text-sm text-red-500 mt-3",children:E}),o.jsxs("div",{className:"flex gap-3 mt-5",children:[o.jsx("button",{type:"button",onClick:Ee,disabled:U,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Cancel"}),o.jsx("button",{type:"button",onClick:le,disabled:!q.trim()||U,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:U?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Import Wallet"})]})]})]})}),K&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(Mn,{provider:K.provider,size:24}),o.jsxs("h3",{className:"text-lg font-semibold",children:["Connect"," ",e.providers[K.provider]?.label||K.provider]})]}),K.sessionId?o.jsxs("div",{className:"p-6",children:[o.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste the authorization code:"}),o.jsx("input",{type:"text",ref:Pe,value:$,onChange:oA=>eA(oA.target.value),placeholder:"Paste code here...",className:"w-full h-11 px-4 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors mb-4 font-mono text-sm",onKeyDown:oA=>{oA.key==="Enter"&&dA(),oA.key==="Escape"&&yA()}}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{type:"button",onClick:yA,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),o.jsx("button",{type:"button",onClick:dA,disabled:!$.trim()||CA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:CA?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Connect"})]})]}):o.jsxs("div",{className:"p-6",children:[o.jsxs("p",{className:"text-sm text-muted-foreground mb-6",children:["You'll be redirected to"," ",e.providers[K.provider]?.label||K.provider," ","to authorize access. After authorizing, copy the code and return here."]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{type:"button",onClick:yA,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),o.jsx("button",{type:"button",onClick:nA,disabled:LA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:LA?o.jsx($e,{className:"w-4 h-4 animate-spin"}):o.jsxs(o.Fragment,{children:["Continue",o.jsx(rn,{className:"w-4 h-4"})]})})]})]})]})}),iA&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(Mn,{provider:"copilot",size:24}),o.jsx("h3",{className:"text-lg font-semibold",children:"Connect GitHub Copilot"})]}),o.jsxs("div",{className:"p-6 space-y-4",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:()=>DA("oauth"),className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${we==="oauth"?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"OAuth"}),o.jsx("button",{type:"button",onClick:()=>DA("token"),className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${we==="token"?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"Token"})]}),we==="oauth"?o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm text-muted-foreground",children:"Enter this code on GitHub to authorize:"}),o.jsx("div",{className:"flex items-center justify-center gap-3",children:ne?o.jsx("div",{className:"bg-muted px-6 py-3 rounded-lg animate-pulse",children:o.jsx("div",{className:"h-9 w-48 bg-muted-foreground/20 rounded"})}):EA?o.jsxs(o.Fragment,{children:[o.jsx("code",{className:"text-3xl font-mono font-bold tracking-widest text-foreground bg-muted px-6 py-3 rounded-lg select-all",children:EA.userCode}),o.jsx("button",{type:"button",onClick:ce,className:"p-2 text-muted-foreground hover:text-foreground transition-colors",children:X?o.jsx(Dn,{className:"w-5 h-5 text-green-500"}):o.jsx(oo,{className:"w-5 h-5"})})]}):null})]}):o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm text-muted-foreground",children:"Paste a GitHub token with Copilot model access."}),o.jsx("input",{type:"password",value:ke,onChange:oA=>Ke(oA.target.value),placeholder:"gho_...",className:"w-full h-11 px-4 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors"}),xe?.ghImport.available&&o.jsx("button",{type:"button",onClick:KA,disabled:se,className:"w-full h-10 px-4 bg-muted text-foreground rounded-lg font-medium hover:bg-muted/80 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:se?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Import from GH CLI"}),xe?.ghImport.available&&!xe.ghImport.authenticated&&o.jsx("p",{className:"text-xs text-muted-foreground",children:xe.ghImport.reason||"GitHub CLI is not authenticated"}),xe&&!xe.ghImport.available&&xe.ghImport.reason&&o.jsx("p",{className:"text-xs text-muted-foreground",children:xe.ghImport.reason})]}),N&&N.tokenSources.length>0&&o.jsx("div",{className:"text-xs text-muted-foreground space-y-1",children:N.tokenSources.map(oA=>o.jsxs("div",{children:[oA.source,":"," ",oA.configured?oA.error?oA.error:`${oA.modelCount??0} models visible`:"not configured",oA.restrictedByOrgPolicy&&oA.restrictedOrg?` (org restriction: ${oA.restrictedOrg})`:""]},oA.source))}),vA&&o.jsx("p",{className:"text-sm text-red-500 text-center",children:vA}),oe&&we==="oauth"&&o.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground",children:[o.jsx($e,{className:"w-4 h-4 animate-spin"}),"Waiting for authorization..."]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{type:"button",onClick:ie,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),we==="oauth"?o.jsx("button",{type:"button",onClick:RA,disabled:oe||ne,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:oe||ne?o.jsx($e,{className:"w-4 h-4 animate-spin"}):o.jsxs(o.Fragment,{children:["Open GitHub",o.jsx(rn,{className:"w-4 h-4"})]})}):o.jsx("button",{type:"button",onClick:Re,disabled:!ke.trim()||GA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:GA?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Save token"})]})]})]})})]})}),ZH=k.memo(function({authStatus:e,onComplete:t,onBack:n,hideHeader:r=!1}){const[s,i]=k.useState(null),[a,g]=k.useState(null),[c,l]=k.useState(!0),[B,Q]=k.useState(!1),[u,d]=k.useState("setu"),[f,h]=k.useState("kimi-k2.5"),[x,b]=k.useState(e.defaults.agent||"build"),[m,M]=k.useState(e.defaults.toolApproval||"dangerous"),[G,Y]=k.useState(!1),Z=k.useRef(!1),P=k.useId(),L=k.useId(),q=k.useId(),v=k.useId();k.useEffect(()=>{(async()=>{try{const[y,F]=await Promise.all([xA.getConfig(),xA.getAllModels()]);i(y),g(F);const T=y?.defaults?.provider||"setu",J=y?.defaults?.model||"kimi-k2.5",z=F?.[T]?.models?.length>0,R=z?T:"setu",I=z&&F[T].models.some(p=>p.id===J)?J:F?.[R]?.models?.[0]?.id||"kimi-k2.5";d(R),h(I),y?.defaults?.agent&&b(y.defaults.agent),y?.defaults?.toolApproval&&M(y.defaults.toolApproval),y?.defaults?.guidedMode&&Y(y.defaults.guidedMode)}catch{}finally{l(!1)}})()},[]),k.useEffect(()=>{if(s?.agents?.length){const C=s.agents;(!x||!C.includes(x))&&b(C.includes("build")?"build":C[0])}},[s,x]),k.useEffect(()=>{if(a?.[u]&&Z.current){const C=a[u];C.models.some(y=>y.id===f)||h(C.models[0]?.id||"")}},[u,a,f]);const U=async()=>{Q(!0);try{await xA.updateDefaults({provider:u,model:f,agent:x,toolApproval:m,guidedMode:G,fullWidthContent:s?.defaults?.fullWidthContent??!0,scope:"global"}),await t()}catch{}finally{Q(!1)}};if(c)return o.jsx("div",{className:"min-h-screen flex items-center justify-center",children:o.jsx($e,{className:"w-8 h-8 animate-spin text-muted-foreground"})});const w=s?.providers.filter(C=>(e.providers[C]?.configured||C==="setu")&&a?.[C]?.models?.length>0)||["setu"],E=a?.[u]?.models||[];return o.jsxs("div",{className:"min-h-screen flex flex-col",children:[!r&&o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Mn,{provider:"setu",size:24}),o.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500"}),"Step 2 of 2"]})]}),o.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${r?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:o.jsxs("div",{className:"max-w-7xl mx-auto",children:[o.jsxs("div",{className:"mb-10",children:[o.jsx("h1",{className:"text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:"Configure Defaults"}),o.jsx("p",{className:"text-lg text-muted-foreground",children:"Set your preferences. You can change these anytime in settings."})]}),o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[o.jsxs("div",{className:"md:col-span-2",children:[o.jsx("label",{htmlFor:P,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Provider"}),o.jsxs("div",{className:"relative",children:[o.jsx("select",{id:P,value:u,onChange:C=>{Z.current=!0,d(C.target.value)},className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:w.map(C=>o.jsx("option",{value:C,children:e.providers[C]?.label||C},C))}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),o.jsxs("div",{className:"md:col-span-2",children:[o.jsx("label",{htmlFor:L,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Model"}),o.jsxs("div",{className:"relative",children:[o.jsx("select",{id:L,value:f,onChange:C=>h(C.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:E.map(C=>o.jsx("option",{value:C.id,children:C.label||C.id},C.id))}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),o.jsxs("div",{children:[o.jsx("label",{htmlFor:q,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Agent"}),o.jsxs("div",{className:"relative",children:[o.jsx("select",{id:q,value:x,onChange:C=>b(C.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:(s?.agents||["build"]).map(C=>o.jsx("option",{value:C,children:C},C))}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),o.jsxs("div",{children:[o.jsx("label",{htmlFor:v,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Tool Approval"}),o.jsxs("div",{className:"relative",children:[o.jsxs("select",{id:v,value:m,onChange:C=>M(C.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:[o.jsx("option",{value:"auto",children:"Auto - run without asking"}),o.jsx("option",{value:"dangerous",children:"Dangerous - approve writes only"}),o.jsx("option",{value:"all",children:"All - approve every tool"})]}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]}),o.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Controls when tool executions need approval"})]}),o.jsx("div",{className:"md:col-span-2",children:o.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-card border border-border rounded-xl",children:[o.jsxs("div",{children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:"Guided Mode"}),o.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"AI will run commands and manage services for you instead of giving instructions"})]}),o.jsx("button",{type:"button",role:"switch","aria-checked":G,onClick:()=>Y(!G),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${G?"bg-primary":"bg-muted"}`,children:o.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${G?"translate-x-6":"translate-x-1"} ${G?"bg-primary-foreground":"bg-foreground"}`})})]})})]})]})}),o.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:o.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[o.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-2 px-4 py-3 text-muted-foreground hover:text-foreground transition-colors",children:[o.jsx(V1,{className:"w-4 h-4"}),"Back"]}),o.jsx("button",{type:"button",onClick:U,disabled:B,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:B?o.jsxs(o.Fragment,{children:[o.jsx($e,{className:"w-4 h-4 animate-spin"}),"Setting up..."]}):o.jsxs(o.Fragment,{children:["Start Using otto",o.jsx(Rr,{className:"w-4 h-4"})]})})]})})]})}),XH=k.memo(function({hideHeader:e=!1}){const t=nn(P=>P.isOpen),n=nn(P=>P.currentStep),r=nn(P=>P.manageMode),s=nn(P=>P.authStatus),i=nn(P=>P.nextStep),a=nn(P=>P.prevStep),g=nn(P=>P.reset),c=Te(P=>P.openTopupModal),{setupWallet:l,importWallet:B,addProvider:Q,removeProvider:u,completeOnboarding:d,startOAuth:f,startOAuthManual:h,exchangeOAuthCode:x,startCopilotDeviceFlow:b,pollCopilotDeviceFlow:m,getCopilotAuthMethods:M,saveCopilotToken:G,importCopilotTokenFromGh:Y,getCopilotDiagnostics:Z}=Vd();return!t||!s?null:o.jsxs("div",{className:"fixed inset-0 z-[9999] bg-background text-foreground overflow-y-auto",children:[n==="wallet"&&o.jsx(VH,{authStatus:s,onSetupWallet:l,onImportWallet:B,onAddProvider:Q,onRemoveProvider:u,onStartOAuth:f,onStartOAuthManual:h,onExchangeOAuthCode:x,onOpenTopup:c,onNext:i,manageMode:r,onClose:g,hideHeader:e,onStartCopilotDeviceFlow:b,onPollCopilotDeviceFlow:m,onGetCopilotAuthMethods:M,onSaveCopilotToken:G,onImportCopilotTokenFromGh:Y,onGetCopilotDiagnostics:Z}),n==="defaults"&&o.jsx(ZH,{authStatus:s,onComplete:d,onBack:a,hideHeader:e})]})}),s1="otto-theme";function $H(){if(typeof window>"u")return"dark";const A=window.localStorage.getItem(s1);return A==="light"||A==="dark"?A:window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}function A7(){const[A,e]=k.useState(()=>$H());k.useEffect(()=>{if(typeof document>"u")return;const n=document.documentElement;A==="dark"?n.classList.add("dark"):n.classList.remove("dark");try{window.localStorage.setItem(s1,A)}catch(r){console.warn("Failed to persist theme preference",r)}window.parent&&window.parent!==window&&window.parent.postMessage({type:"otto-set-theme",theme:A},"*")},[A]),k.useEffect(()=>{if(typeof window>"u")return;const n=r=>{r.data?.type==="otto-set-theme"&&(r.data.theme==="light"||r.data.theme==="dark")&&e(r.data.theme)};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[]);const t=k.useCallback(()=>{e(n=>n==="dark"?"light":"dark")},[]);return k.useMemo(()=>({theme:A,setTheme:e,toggleTheme:t}),[A,t])}function e7(){const[A,e]=k.useState(null);return k.useEffect(()=>{(async()=>{try{const s=`${window.OTTO_SERVER_URL||Rs}/v1/config/cwd`;console.log("[useWorkingDirectory] Fetching from:",s);const i=await fetch(s);if(!i.ok)throw console.error("[useWorkingDirectory] Failed:",i.status,i.statusText),new Error(`Failed to fetch working directory: ${i.status}`);const a=await i.json();console.log("[useWorkingDirectory] Success:",a),a.dirName&&(console.log("[useWorkingDirectory] Setting title to:",a.dirName),e(a.dirName),document.title=a.dirName)}catch(n){console.error("[useWorkingDirectory] Error:",n),document.title="otto"}})()},[]),A}function t7({sessionIds:A,activeSessionId:e,gitFiles:t,onSelectSession:n,onNewSession:r,onStageFile:s,onUnstageFile:i,onRestoreFile:a,onDeleteFile:g,onStageAll:c,onUnstageAll:l,onOpenCommitModal:B,onViewDiff:Q,onReturnToInput:u}){const{currentFocus:d,sessionIndex:f,gitFileIndex:h,setFocus:x,setSessionIndex:b,setGitFileIndex:m,resetGitFileIndex:M}=Wd(),{setCollapsed:G,toggleCollapse:Y}=xo(),{isExpanded:Z,toggleSidebar:P}=We(),L=We(w=>w.closeDiff),q=Tt(w=>w.toggleSidebar),v=A.indexOf(e||""),U=k.useCallback(w=>{const E=w.target,C=E.tagName==="INPUT"||E.tagName==="TEXTAREA"||E.isContentEditable,y=!!E.closest("[data-terminal-viewer]");if((w.ctrlKey||w.metaKey)&&w.key==="h"){w.preventDefault(),d==="sessions"?(document.activeElement?.blur(),x("input"),G(!0),setTimeout(()=>u?.(),50)):d==="git"?(document.activeElement?.blur(),x("input"),P(),L(),setTimeout(()=>u?.(),50)):(document.activeElement?.blur(),x("sessions"),G(!1),v>=0&&b(v));return}if((w.ctrlKey||w.metaKey)&&w.key==="l"){w.preventDefault(),d==="git"?(document.activeElement?.blur(),x("input"),P(),L(),setTimeout(()=>u?.(),50)):d==="sessions"?(document.activeElement?.blur(),x("input"),G(!0),setTimeout(()=>u?.(),50)):(document.activeElement?.blur(),Z||P(),x("git"),M());return}if((w.ctrlKey||w.metaKey)&&w.key==="/"){w.preventDefault(),Y();return}if((w.ctrlKey||w.metaKey)&&w.key==="\\"){w.preventDefault(),P();return}if((w.ctrlKey||w.metaKey)&&w.shiftKey&&w.key==="r"){w.preventDefault(),q();return}if((w.ctrlKey||w.metaKey)&&w.key==="n"){w.preventDefault(),r();return}if((w.ctrlKey||w.metaKey)&&w.key==="p"){w.preventDefault(),jQ.getState().toggle();return}if(w.key==="Escape"&&!y||w.key==="q"&&!C&&(d==="sessions"||d==="git")){w.preventDefault(),d==="sessions"?G(!0):d==="git"&&(P(),L()),x("input"),u?.();return}if(d==="sessions"&&!C){if(w.key==="j"&&A.length>0){w.preventDefault();const F=Math.min(f+1,A.length-1);b(F);return}if(w.key==="k"&&A.length>0){w.preventDefault();const F=Math.max(f-1,0);b(F);return}if(w.key==="Enter"&&A[f]){w.preventDefault(),n(A[f]),x("input");return}}if(d==="git"&&!C){if(w.key==="j"&&t.length>0){w.preventDefault();const F=Math.min(h+1,t.length-1);m(F);return}if(w.key==="k"&&t.length>0){w.preventDefault();const F=Math.max(h-1,0);m(F);return}if(w.key===" "&&t[h]){w.preventDefault();const F=t[h];F.staged?i?.(F.path):s?.(F.path);return}if(w.key==="a"){w.preventDefault(),c?.();return}if(w.key==="u"){w.preventDefault(),l?.();return}if(w.key==="R"&&t[h]){w.preventDefault();const F=t[h];!F.staged&&F.status!=="untracked"&&F.status!=="added"&&a?.(F.path);return}if(w.shiftKey&&w.key==="D"||w.key==="Backspace"){w.preventDefault();const F=t[h];F&&!F.staged&&F.status==="untracked"&&g?.(F.path);return}if(w.key==="c"){w.preventDefault(),B?.();return}if(w.key==="Enter"&&t[h]){w.preventDefault();const F=t[h];Q?.(F.path,F.staged);return}}},[d,f,h,A,t,v,Z,x,b,m,M,G,P,q,Y,n,r,s,i,a,g,c,l,B,Q,u,L]);return k.useEffect(()=>(window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)),[U]),{currentFocus:d,sessionIndex:f,gitFileIndex:h}}function n7(A){const e=k.useRef(null),t=k.useRef(null),n=Te(c=>c.setBalance),r=Te(c=>c.setPaymentPending),s=Er(c=>c.removeToast),i=Er(c=>c.updateToast),a=jc(c=>c.setPendingTopup),g=jc(c=>c.clearPendingTopup);k.useEffect(()=>{if(!A)return;const c=new jy;e.current=c;const l=xA.getStreamUrl(A);c.connect(l);const B=c.on("*",Q=>{const u=Q.payload;switch(Q.type){case"setu.topup.required":{const d=typeof u?.amountUsd=="number"?u.amountUsd:0,f=typeof u?.currentBalance=="number"?u.currentBalance:0,h=typeof u?.minTopupUsd=="number"?u.minTopupUsd:5,x=typeof u?.suggestedTopupUsd=="number"?u.suggestedTopupUsd:10,b=typeof u?.messageId=="string"?u.messageId:"";a({sessionId:A,messageId:b,amountUsd:d,currentBalance:f,minTopupUsd:h,suggestedTopupUsd:x});break}case"setu.topup.method_selected":{u?.method==="crypto"&&(r(!0),t.current=ve.loading("💳 Processing crypto payment..."));break}case"setu.topup.cancelled":{g();const d=typeof u?.reason=="string"?u.reason:"Request cancelled";ve(`⚠️ ${d}`);break}case"setu.payment.required":{const d=typeof u?.amountUsd=="number"?u.amountUsd:0;r(!0),t.current||(t.current=ve.loading(`💳 Payment required: $${d.toFixed(2)}`));break}case"setu.payment.signing":{t.current?i(t.current,{message:"✍️ Signing transaction..."}):t.current=ve.loading("✍️ Signing transaction...");break}case"setu.payment.complete":{g();const d=u?.amountUsd,f=u?.newBalance,h=typeof u?.transactionId=="string"?u.transactionId:void 0,x=typeof d=="number"?d:typeof d=="string"?parseFloat(d):0,b=typeof f=="number"?f:typeof f=="string"?parseFloat(f):0;n(b),r(!1),t.current&&(s(t.current),t.current=null);const m=`✅ Paid $${x.toFixed(2)}`;h?ve.successWithAction(m,{label:"View Tx",href:`https://orbmarkets.io/tx/${h}`}):ve.success(m);break}case"setu.fiat.checkout_created":{g(),r(!1),t.current&&(s(t.current),t.current=null),ve.success("💳 Complete payment, then retry your message");break}case"setu.balance.updated":{const d=u?.balanceRemaining,f=typeof d=="number"?d:typeof d=="string"?parseFloat(d):null;f!==null&&!Number.isNaN(f)&&n(f);break}case"setu.payment.error":{g();const d=typeof u?.error=="string"?u.error:"Payment failed";r(!1),t.current&&(s(t.current),t.current=null),ve.error(`❌ ${d}`);break}}});return()=>{B(),c.disconnect()}},[A,n,r,s,i,a,g])}const Pl=c1({component:r7});function r7(){const{checkOnboarding:A}=Vd();return k.useEffect(()=>{A()},[A]),o.jsxs(o.Fragment,{children:[o.jsx(l1,{}),o.jsx(XH,{}),o.jsx(zd,{}),null]})}const s7=YQ("/")({beforeLoad:()=>{throw u1({to:"/sessions"})},component:()=>null});function ff({height:A=16,className:e=""}){const t=Math.round(A*2.4686468646864688);return o.jsx("svg",{width:t,height:A,viewBox:"0 0 748 303",fill:"currentColor",className:e,"aria-label":"otto",role:"img",children:o.jsx("path",{d:"M192.877 257.682C192.877 263.287 191.783 268.551 189.596 273.473C187.545 278.395 184.674 282.701 180.982 286.393C177.428 289.947 173.189 292.818 168.268 295.006C163.482 297.057 158.287 298.082 152.682 298.082H44.1953C38.7266 298.082 33.5312 297.057 28.6094 295.006C23.6875 292.818 19.3809 289.947 15.6895 286.393C12.1348 282.701 9.26367 278.395 7.07617 273.473C5.02539 268.551 4 263.287 4 257.682V120.074C4 114.469 5.02539 109.205 7.07617 104.283C9.26367 99.3613 12.1348 95.123 15.6895 91.5684C19.3809 87.877 23.6875 85.0059 28.6094 82.9551C33.5312 80.7676 38.7266 79.6738 44.1953 79.6738H152.682C158.287 79.6738 163.482 80.7676 168.268 82.9551C173.189 85.0059 177.428 87.877 180.982 91.5684C184.674 95.123 187.545 99.3613 189.596 104.283C191.783 109.205 192.877 114.469 192.877 120.074V257.682ZM44.1953 120.074V257.682H152.682V120.074H44.1953ZM331.715 4V298.082H289.674V46.041H239.225V4H331.715ZM478.961 4V298.082H436.92V46.041H386.471V4H478.961ZM743.717 257.682C743.717 263.287 742.623 268.551 740.436 273.473C738.385 278.395 735.514 282.701 731.822 286.393C728.268 289.947 724.029 292.818 719.107 295.006C714.322 297.057 709.127 298.082 703.521 298.082H595.035C589.566 298.082 584.371 297.057 579.449 295.006C574.527 292.818 570.221 289.947 566.529 286.393C562.975 282.701 560.104 278.395 557.916 273.473C555.865 268.551 554.84 263.287 554.84 257.682V120.074C554.84 114.469 555.865 109.205 557.916 104.283C560.104 99.3613 562.975 95.123 566.529 91.5684C570.221 87.877 574.527 85.0059 579.449 82.9551C584.371 80.7676 589.566 79.6738 595.035 79.6738H703.521C709.127 79.6738 714.322 80.7676 719.107 82.9551C724.029 85.0059 728.268 87.877 731.822 91.5684C735.514 95.123 738.385 99.3613 740.436 104.283C742.623 109.205 743.717 114.469 743.717 120.074V257.682ZM595.035 120.074V257.682H703.521V120.074H595.035Z"})})}const hf="left-sidebar",pf=272,o7=256,i7=480,a7=k.memo(function({children:e,onNewSession:t}){const n=We(a=>a.isDiffOpen),r=xo(a=>a.isCollapsed),s=xo(a=>a.toggleCollapse),i=ks(a=>a.widths[hf]??pf);return k.useEffect(()=>(r?document.body.style.overflow="":document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[r]),r?o.jsxs("aside",{className:"w-12 md:w-12 border-r border-border bg-background flex flex-col transition-all duration-300 ease-in-out hidden md:flex",children:[o.jsx("div",{className:"h-14 border-b border-border flex items-center justify-center",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"New session",className:"rounded-full touch-manipulation text-muted-foreground hover:bg-muted/50",children:o.jsx(Qr,{className:"w-4 h-4"})})}),o.jsx("button",{type:"button",className:"flex-1 cursor-pointer hover:bg-muted/50 transition-colors touch-manipulation",onClick:n?void 0:s,title:n?void 0:"Expand sidebar","aria-label":"Expand sidebar"}),o.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:"Expand sidebar",disabled:n,className:"transition-transform duration-200 hover:scale-110 touch-manipulation text-muted-foreground hover:bg-muted/50",children:o.jsx(Dt,{className:"w-4 h-4"})})})]}):o.jsxs(o.Fragment,{children:[!r&&o.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 md:hidden",onClick:s,"aria-hidden":"true"}),o.jsxs("aside",{className:"border-r border-sidebar-border sidebar-fade-in flex transition-all duration-300 ease-in-out fixed md:relative top-0 left-0 z-50 h-screen md:h-auto w-full md:w-auto",style:{maxWidth:"100%"},children:[o.jsxs("div",{className:"flex-1 flex flex-col min-w-0 relative",style:{width:i},children:[o.jsxs("div",{className:"h-14 border-b border-sidebar-border px-4 flex items-center gap-2 md:hidden bg-sidebar",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:"Close menu",className:"touch-manipulation flex-shrink-0 text-sidebar-foreground hover:bg-sidebar-accent","aria-label":"Close menu",children:o.jsx(yt,{className:"w-5 h-5"})}),o.jsx("div",{className:"flex-1 flex items-center",children:o.jsx(ff,{height:14,className:"text-sidebar-foreground"})})]}),o.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[o.jsx("div",{className:"absolute top-0 left-0 right-0 z-10 pointer-events-none",children:o.jsxs("div",{className:"h-14 px-4 flex items-center justify-between border-b border-sidebar-border/40 bg-sidebar/40 backdrop-blur-xl supports-[backdrop-filter]:bg-sidebar/20",children:[o.jsx("div",{className:"flex items-center text-sidebar-foreground/90",children:o.jsx(ff,{height:14,className:"select-none"})}),o.jsx("button",{type:"button",onClick:t,className:"w-9 h-9 rounded-full bg-sidebar-primary flex items-center justify-center hover:opacity-90 transition-opacity touch-manipulation pointer-events-auto",title:"New session",children:o.jsx(Qr,{className:"w-4 h-4 text-sidebar-primary-foreground"})})]})}),o.jsx("div",{className:"absolute inset-0 overflow-hidden",children:e})]}),o.jsx("div",{className:"h-12 border-t border-sidebar-border px-2 flex items-center justify-end",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:"Collapse sidebar",disabled:n,className:"transition-transform duration-200 hover:scale-110 touch-manipulation text-sidebar-muted-foreground hover:bg-sidebar-accent w-8 h-8",children:o.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-300",role:"img","aria-label":"Collapse sidebar",children:[o.jsx("title",{children:"Collapse sidebar"}),o.jsx("path",{d:"M15 18l-6-6 6-6"})]})})})]}),o.jsx("div",{className:"hidden md:block",children:o.jsx(fi,{panelKey:hf,side:"left",minWidth:o7,maxWidth:i7,defaultWidth:pf})})]})]})}),g7=k.memo(function({sidebar:e,children:t,onNewSession:n,theme:r,onToggleTheme:s,sessionId:i,onNavigateToSession:a,onFixWithAI:g}){const c=We(b=>b.isExpanded),l=Et(b=>b.isExpanded),B=Tt(b=>b.isExpanded),Q=Zt(b=>b.isExpanded),u=He(b=>b.isExpanded),d=Qt(b=>b.isExpanded),f=ct(b=>b.isExpanded),h=Bt(b=>b.isExpanded),x=c||l||B||Q||u||d||f||h;return o.jsxs("div",{className:"h-screen flex bg-background touch-manipulation border-t border-border/50",children:[o.jsx(a7,{onNewSession:n,children:e}),o.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden w-full md:w-auto",children:[o.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[o.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[o.jsx(BY,{}),o.jsx(NY,{}),o.jsx(PH,{}),o.jsx(LH,{}),t]}),o.jsxs("div",{className:"hidden md:flex",children:[o.jsx(gY,{onFixWithAI:g}),o.jsx(pY,{sessionId:i}),o.jsx(UY,{parentSessionId:i??null,onNavigateToSession:a}),o.jsx(ZY,{}),o.jsx(gH,{}),o.jsx(JH,{}),o.jsx(bH,{}),o.jsx(GH,{}),o.jsxs("div",{className:`flex flex-col w-12 border-l ${x?"sidebar-fade-in border-sidebar-border":"bg-background border-border"}`,children:[o.jsx(cY,{}),o.jsx(mY,{sessionId:i}),o.jsx(LY,{parentSessionId:i}),o.jsx(qH,{}),o.jsx(AH,{}),o.jsx(cH,{}),o.jsx(NH,{}),o.jsx(RH,{}),o.jsx("div",{className:"flex-1"}),o.jsx(rk,{}),o.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:`Switch to ${r==="dark"?"light":"dark"} mode`,"aria-label":`Switch to ${r==="dark"?"light":"dark"} mode`,className:"touch-manipulation",children:r==="dark"?o.jsx(Z1,{className:"w-4 h-4"}):o.jsx(X1,{className:"w-4 h-4"})})})]})]})]}),o.jsx(nk,{})]}),o.jsx(QY,{}),o.jsx(ok,{}),o.jsx(zH,{})]})});function o1({sessionId:A}){const e=k.useRef(null),t=jM(),{data:n}=bo(),{theme:r,toggleTheme:s}=A7(),{openCommitModal:i,openDiff:a}=We(),g=B1(),{data:c=[]}=Al(),{data:l}=el(),B=tl(),Q=uE(),u=Uh(),d=Th(),f=iE(P=>P.openConfirmation);e7(),n7(A),ql(n?.defaults?.provider);const h=k.useCallback(()=>{setTimeout(()=>{e.current?.focus()},100)},[]),x=k.useCallback(async()=>{try{const P=await t.mutateAsync({agent:n?.defaults.agent||"general",provider:n?.defaults.provider,model:n?.defaults.model});g({to:"/sessions/$sessionId",params:{sessionId:P.id},replace:!1}),h()}catch(P){console.error("Failed to create session:",P)}},[t,n,g,h]),b=k.useCallback(()=>{g({to:"/sessions"})},[g]),m=k.useCallback(P=>{g({to:"/sessions/$sessionId",params:{sessionId:P}}),h()},[g,h]),M=k.useCallback(async P=>{try{const L=await t.mutateAsync({agent:n?.defaults.agent||"general",provider:n?.defaults.provider,model:n?.defaults.model,title:"Fix Git Error"});g({to:"/sessions/$sessionId",params:{sessionId:L.id},replace:!1}),await xA.sendMessage(L.id,{content:P})}catch(L){console.error("Failed to create fix session:",L)}},[t,n,g]),G=k.useMemo(()=>l?[...(l.conflicted??[]).map(P=>({path:P.path,staged:!1,status:P.status})),...l.staged.map(P=>({path:P.path,staged:!0,status:P.status})),...l.unstaged.map(P=>({path:P.path,staged:!1,status:P.status})),...l.untracked.map(P=>({path:P.path,staged:!1,status:P.status}))]:[],[l]),Y=k.useMemo(()=>c.map(P=>P.id),[c]);t7({sessionIds:Y,activeSessionId:A,gitFiles:G,onSelectSession:m,onNewSession:x,onStageFile:P=>B.mutate([P]),onUnstageFile:P=>Q.mutate([P]),onRestoreFile:P=>u.mutate([P]),onDeleteFile:P=>{f({title:"Delete File",message:`Delete ${P}? This will permanently remove the untracked file.`,confirmLabel:"Delete",variant:"destructive",onConfirm:async()=>{await d.mutateAsync([P])}})},onStageAll:()=>{const P=G.filter(L=>!L.staged).map(L=>L.path);P.length>0&&B.mutate(P)},onUnstageAll:()=>{const P=G.filter(L=>L.staged).map(L=>L.path);P.length>0&&Q.mutate(P)},onOpenCommitModal:i,onViewDiff:a,onReturnToInput:h}),k.useEffect(()=>{A&&h()},[A,h]);const Z=k.useMemo(()=>A?o.jsxs(o.Fragment,{children:[o.jsx(zq,{sessionId:A,onSelectSession:m}),o.jsx(u5,{ref:e,sessionId:A,onNewSession:x,onDeleteSession:b})]}):o.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a session or create a new one to start"}),[A,x,m,b]);return o.jsxs(o.Fragment,{children:[o.jsx(g7,{onNewSession:x,theme:r,onToggleTheme:s,sessionId:A,onNavigateToSession:m,onFixWithAI:M,sidebar:o.jsx(Xq,{activeSessionId:A,onSelectSession:m}),children:Z}),o.jsx(ck,{})]})}const c7=YQ("/sessions/")({component:l7});function l7(){return o.jsx(o1,{})}const i1=YQ("/sessions/$sessionId")({component:u7});function u7(){const{sessionId:A}=i1.useParams();return o.jsx(o1,{sessionId:A})}const B7=s7.update({id:"/",path:"/",getParentRoute:()=>Pl}),Q7=c7.update({id:"/sessions/",path:"/sessions/",getParentRoute:()=>Pl}),E7=i1.update({id:"/sessions/$sessionId",path:"/sessions/$sessionId",getParentRoute:()=>Pl}),d7={IndexRoute:B7,SessionsSessionIdRoute:E7,SessionsIndexRoute:Q7},C7=Pl._addFileChildren(d7)._addFileTypes(),I7=()=>{const t=(typeof globalThis<"u"?globalThis.OTTO_ROUTER_BASEPATH:void 0)??"/"??"/";if(!t||t==="/")return"/";const n=t.replace(/\/+$/,"")||"/";return n.startsWith("/")?n:`/${n}`},f7=Q1({routeTree:C7,basepath:I7()}),Zd=new E1({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1,structuralSharing:!0}}});Zd.prefetchQuery({queryKey:["sessions"],queryFn:()=>xA.getSessions()});Zd.prefetchQuery({queryKey:["config"],queryFn:()=>xA.getConfig()});function h7(){return o.jsx(d1,{client:Zd,children:o.jsx(C1,{router:f7})})}const a1=document.getElementById("root");if(!a1)throw new Error("Root element not found");I1.createRoot(a1).render(o.jsx(k.StrictMode,{children:o.jsx(h7,{})}));export{fA as B,Xi as H,CR as a,pn as b,sg as c,U6 as d,Ls as e,Ir as f,_E as g,tg as i,kl as l,_t as s};
182
+ API_KEY=sk-xxx`,rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: KEY=VALUE"})]})]}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"URL"}),o.jsx(Yg,{value:c,onChange:U=>l(U.target.value),placeholder:"e.g. https://mcp.linear.app/mcp",onKeyDown:U=>{U.key==="Enter"&&P()}})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Transport"}),o.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[o.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:B==="http"?"2px":"50%",right:B==="sse"?"2px":"50%"}}),o.jsx("button",{type:"button",onClick:()=>Q("http"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${B==="http"?"text-foreground":"text-muted-foreground/50"}`,children:"HTTP (recommended)"}),o.jsx("button",{type:"button",onClick:()=>Q("sse"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${B==="sse"?"text-foreground":"text-muted-foreground/50"}`,children:"SSE (legacy)"})]})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Headers"}),o.jsx("textarea",{value:u,onChange:U=>d(U.target.value),placeholder:"Authorization: Bearer xxx",rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: Header-Name: value"})]}),o.jsx("p",{className:"text-xs text-muted-foreground",children:"For OAuth servers (Linear, Notion, etc.), leave headers empty and authenticate after adding."})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-medium mb-1",children:"Scope"}),o.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[o.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:x==="global"?"2px":"50%",right:x==="project"?"2px":"50%"}}),o.jsxs("button",{type:"button",onClick:()=>b("global"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${x==="global"?"text-foreground":"text-muted-foreground/50"}`,children:[o.jsx($Q,{className:"w-3 h-3"}),"All projects"]}),o.jsxs("button",{type:"button",onClick:()=>b("project"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${x==="project"?"text-foreground":"text-muted-foreground/50"}`,children:[o.jsx(Wi,{className:"w-3 h-3"}),"This project only"]})]}),o.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:x==="global"?"Saved to ~/.config/otto/config.json":"Saved to .otto/config.json (project-local)"})]}),m&&o.jsx("div",{className:"text-sm text-red-400 bg-red-500/10 px-3 py-2 rounded",children:m}),o.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o.jsx(fe,{variant:"ghost",onClick:Z,children:"Cancel"}),o.jsx(fe,{variant:"primary",onClick:P,disabled:G.isPending,children:G.isPending?o.jsxs(o.Fragment,{children:[o.jsx($e,{className:"w-3 h-3 animate-spin mr-1"}),"Adding..."]}):"Add Server"})]})]})})})}),wH=k.memo(function({checked:e,loading:t,onChange:n,disabled:r}){return o.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:r||t,onClick:s=>{s.stopPropagation(),n()},className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors duration-200 focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed ${e?"bg-green-500":"bg-muted-foreground/30"}`,children:o.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full transition-transform duration-200 ${e?"translate-x-[18px]":"translate-x-[3px]"} ${t?"bg-transparent":"bg-white"}`,children:t&&o.jsx($e,{className:"w-3.5 h-3.5 animate-spin text-white"})})})}),xH=k.memo(function({userCode:e,verificationUri:t}){const[n,r]=k.useState(!1),s=k.useCallback(()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),2e3)})},[e]);return o.jsx("div",{className:"px-3 pb-2.5 pt-0",children:o.jsxs("div",{className:"rounded-md bg-yellow-500/10 border border-yellow-500/20 p-2 space-y-1.5",children:[o.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[o.jsx($e,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),o.jsx("span",{className:"text-yellow-500/80",children:"Enter code at GitHub:"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("code",{className:"text-sm font-mono font-bold text-yellow-400 tracking-wider",children:e}),o.jsx("button",{type:"button",onClick:s,className:"text-yellow-500/60 hover:text-yellow-400 transition-colors",title:"Copy code",children:o.jsx(_1,{className:"w-3.5 h-3.5"})}),n&&o.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),o.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",onClick:i=>{i.preventDefault(),Br(t)},className:"inline-flex items-center gap-1 text-xs text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open GitHub login",o.jsx(rn,{className:"w-3 h-3"})]})]})})}),yH=k.memo(function({server:e,isLoading:t,authUrl:n,copilotDevice:r,onStart:s,onStop:i,onRemove:a,onAuth:g}){const[c,l]=k.useState(!1),B=e.connected&&e.tools.length>0,Q=e.transport==="http"||e.transport==="sse",u=(!!n||!!r)&&!e.connected,d=k.useCallback(()=>{e.authRequired&&!e.connected?g():e.connected?i():s()},[e.connected,e.authRequired,g,i,s]),f=k.useCallback(()=>{B&&l(h=>!h)},[B]);return o.jsxs("div",{className:`rounded-lg border transition-colors duration-200 group ${e.connected?"border-green-500/30 bg-green-500/5":u?"border-yellow-500/30 bg-yellow-500/5":"border-border bg-transparent"}`,children:[o.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[o.jsx(wH,{checked:e.connected,loading:t||u,onChange:d}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"text-sm font-medium truncate",children:e.name}),Q&&o.jsx(gs,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),e.authRequired&&!e.connected&&o.jsx(z1,{className:"w-3 h-3 text-yellow-500 flex-shrink-0"})]}),o.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[o.jsx("span",{className:"text-xs text-muted-foreground truncate",children:Q?e.url:`${e.command??""} ${e.args.join(" ")}`}),o.jsx("span",{className:"flex items-center flex-shrink-0 opacity-50",title:e.scope==="project"?"Project-local":"Global",children:e.scope==="project"?o.jsx(Wi,{className:"w-3 h-3"}):o.jsx($Q,{className:"w-3 h-3"})})]})]}),o.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[B&&o.jsxs("button",{type:"button",onClick:f,className:"flex items-center gap-0.5 text-xs text-muted-foreground hover:text-foreground px-1.5 py-1 rounded transition-colors",children:[o.jsx(W1,{className:"w-3 h-3"}),e.tools.length,c?o.jsx(xn,{className:"w-3 h-3"}):o.jsx(Dt,{className:"w-3 h-3"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:a,title:"Remove server",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity",children:o.jsx(Ma,{className:"w-3 h-3 text-muted-foreground hover:text-red-400"})})]})]}),r&&!e.connected&&o.jsx(xH,{userCode:r.userCode,verificationUri:r.verificationUri}),!r&&u&&n&&o.jsx("div",{className:"px-3 pb-2.5 pt-0",children:o.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[o.jsx($e,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),o.jsx("span",{className:"text-yellow-500/80",children:"Waiting for auth..."}),o.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",onClick:h=>{h.preventDefault(),Br(n)},className:"inline-flex items-center gap-0.5 text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open login",o.jsx(rn,{className:"w-3 h-3"})]})]})}),B&&c&&o.jsx("div",{className:"px-3 pb-2.5 pt-0",children:o.jsx("div",{className:"flex flex-wrap gap-1",children:e.tools.map(h=>o.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",title:h,children:h.split("__").pop()},h))})})]})});function DH(A,e){const{data:t}=CH(A),n=k.useRef(!1);k.useEffect(()=>{t?.authenticated&&!n.current&&e(),n.current=t?.authenticated??!1},[t?.authenticated,e])}const bH=k.memo(function(){const e=ct(U=>U.isExpanded),t=ct(U=>U.collapseSidebar),n=ct(U=>U.servers),r=ct(U=>U.loading),s=ct(U=>U.authUrls),i=ct(U=>U.setAuthUrl),a=ct(U=>U.setLoading),g=ct(U=>U.setCopilotDevice),{isLoading:c}=lH(),l=uH(),B=BH(),Q=EH(),u=dH(),d=IH(),[f,h]=k.useState(!1),[x,b]=k.useState(null),[m,M]=k.useState(null),G=Ye(),Y=k.useCallback(()=>{x&&(i(x,null),b(null),G.invalidateQueries({queryKey:["mcp","servers"]}))},[x,i,G]);DH(x,Y),k.useEffect(()=>{for(const U of r)n.find(E=>E.name===U)?.connected&&a(U,!1)},[n,r,a]);const Z=k.useCallback((U,w)=>{w.sessionId&&w.userCode&&w.verificationUri&&(g({sessionId:w.sessionId,userCode:w.userCode,verificationUri:w.verificationUri,interval:w.interval??5,serverName:U}),Br(w.verificationUri))},[g]),P=k.useCallback(async U=>{try{a(U,!0);const w=await u.mutateAsync(U);if(w.authType==="copilot-device"){if(w.authenticated){a(U,!1),G.invalidateQueries({queryKey:["mcp","servers"]});return}Z(U,w)}else w.authUrl?(i(U,w.authUrl),b(U),Br(w.authUrl)):a(U,!1)}catch{a(U,!1),i(U,null)}},[u,i,a,Z,G]),L=k.useCallback(async U=>{try{a(U,!0);const w=await l.mutateAsync(U);w.authType==="copilot-device"&&!w.connected?Z(U,w):w.authRequired&&w.authUrl?(i(U,w.authUrl),b(U),Br(w.authUrl)):a(U,!1)}catch{a(U,!1),i(U,null)}},[l,i,a,Z]),q=k.useMemo(()=>[...n].sort((U,w)=>U.connected&&!w.connected?-1:!U.connected&&w.connected?1:U.name.localeCompare(w.name)),[n]);if(!e)return null;const v=n.filter(U=>U.connected).length;return o.jsxs("div",{className:"w-80 border-l border-sidebar-border sidebar-fade-in flex flex-col h-full",children:[o.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(va,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium text-sm",children:"MCP Servers"}),v>0&&o.jsxs("span",{className:"text-xs bg-green-500/20 text-green-400 px-1.5 py-0.5 rounded-full",children:[v," active"]})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>h(!0),title:"Add MCP server",className:"h-7 w-7",children:o.jsx(Qr,{className:"w-4 h-4"})}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"Close sidebar",children:o.jsx(Dt,{className:"w-4 h-4"})})]})]}),o.jsx("div",{className:"flex-1 overflow-y-auto",children:c&&n.length===0?o.jsxs("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:[o.jsx($e,{className:"w-4 h-4 animate-spin mr-2"}),"Loading..."]}):n.length===0?o.jsxs("div",{className:"p-4 text-sm text-muted-foreground space-y-3",children:[o.jsx("p",{children:"No MCP servers configured."}),o.jsxs(fe,{variant:"primary",size:"sm",onClick:()=>h(!0),className:"w-full",children:[o.jsx(Qr,{className:"w-3 h-3 mr-1"}),"Add MCP Server"]}),o.jsxs("p",{className:"text-xs",children:["Or add servers to"," ",o.jsx("code",{className:"bg-muted px-1 py-0.5 rounded text-xs",children:".otto/config.json"})]})]}):o.jsx("div",{className:"p-2 space-y-1.5",children:q.map(U=>o.jsx(yH,{server:U,isLoading:r.has(U.name),authUrl:s.get(U.name),copilotDevice:d?.serverName===U.name?d:null,onStart:()=>L(U.name),onStop:()=>B.mutate(U.name),onRemove:()=>M(U.name),onAuth:()=>P(U.name)},U.name))})}),o.jsx(mH,{isOpen:f,onClose:()=>h(!1)}),o.jsxs(ds,{isOpen:!!m,onClose:()=>M(null),title:"Remove MCP Server",maxWidth:"sm",showCloseButton:!1,children:[o.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Are you sure you want to remove"," ",o.jsx("span",{className:"font-medium text-foreground",children:m}),"? This will stop the server and remove its configuration."]}),o.jsxs("div",{className:"flex justify-end gap-2",children:[o.jsx(fe,{variant:"secondary",size:"sm",onClick:()=>M(null),children:"Cancel"}),o.jsx(fe,{variant:"primary",size:"sm",className:"bg-red-500 hover:bg-red-600 text-white",onClick:()=>{m&&Q.mutate(m),M(null)},children:"Remove"})]})]})]})}),NH=k.memo(function(){const e=ct(s=>s.isExpanded),t=ct(s=>s.toggleSidebar),r=ct(s=>s.servers).filter(s=>s.connected).length;return o.jsxs("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"MCP Servers",children:[o.jsx(va,{className:"w-5 h-5 text-muted-foreground mx-auto"}),r>0&&o.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full"})]})});function kH(){const A=Bt(t=>t.setSkills),e=bt({queryKey:["skills"],queryFn:async()=>xA.listSkills(),refetchInterval:3e4});return k.useEffect(()=>{e.data?.skills&&A(e.data.skills)},[e.data,A]),e}function n1(A){return bt({queryKey:["skills",A],queryFn:async()=>A?xA.getSkill(A):null,enabled:!!A})}function MH(A){return bt({queryKey:["skills",A,"files"],queryFn:async()=>A?xA.getSkillFiles(A):null,enabled:!!A})}function vH(A,e){return bt({queryKey:["skills",A,"files",e],queryFn:async()=>!A||!e?null:xA.getSkillFileContent(A,e),enabled:!!A&&!!e})}const SH={cwd:Wi,parent:Wi,repo:Wi,user:$Q,system:gs},df={cwd:"Project",parent:"Parent",repo:"Repository",user:"User",system:"System"};function FH(A){return A<1024?`${A} B`:A<1024*1024?`${(A/1024).toFixed(1)} KB`:`${(A/(1024*1024)).toFixed(1)} MB`}const GH=k.memo(function(){const e=Bt(u=>u.isExpanded),t=Bt(u=>u.collapseSidebar),n=Bt(u=>u.skills),r=Bt(u=>u.selectedSkill),s=Bt(u=>u.selectSkill),i=Bt(u=>u.openViewer),a=Bt(u=>u.viewingFile),{isLoading:g}=kH(),{data:c}=n1(r),{data:l}=MH(r),B=l?.files??[],Q=k.useMemo(()=>{const u=new Map;for(const d of n){const f=u.get(d.scope)??[];f.push(d),u.set(d.scope,f)}return u},[n]);return e?o.jsxs("div",{className:"w-80 border-l border-sidebar-border sidebar-fade-in flex flex-col h-full",children:[o.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Rr,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium text-sm",children:"Skills"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"Close sidebar",children:o.jsx(Dt,{className:"w-4 h-4"})})]}),r&&c?o.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o.jsx("div",{className:"p-3 border-b border-border",children:o.jsx("button",{type:"button",onClick:()=>s(null),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"← Back to list"})}),o.jsxs("div",{className:"px-3 py-3 border-b border-border",children:[o.jsx("h3",{className:"font-medium text-sm mb-1",children:c.name}),o.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:c.description}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:df[c.scope]??c.scope}),c.license&&o.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:c.license})]})]}),o.jsxs("div",{className:"py-1",children:[o.jsx("div",{className:"flex items-center gap-1.5 px-3 py-2 text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:"Files"}),o.jsx("button",{type:"button",onClick:()=>i(null),className:`w-full text-left px-3 py-2 hover:bg-accent transition-colors ${a===null?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(so,{className:"w-3.5 h-3.5 flex-shrink-0 text-muted-foreground"}),o.jsx("span",{className:"text-sm font-mono truncate flex-1",children:"SKILL.md"})]})}),B.map(u=>o.jsx("button",{type:"button",onClick:()=>i(u.relativePath),className:`w-full text-left px-3 py-2 hover:bg-accent transition-colors ${a===u.relativePath?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(qc,{className:"w-3.5 h-3.5 flex-shrink-0 text-muted-foreground"}),o.jsx("span",{className:"text-sm font-mono truncate flex-1",children:u.relativePath}),o.jsx("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:FH(u.size)})]})},u.relativePath))]})]}):o.jsx("div",{className:"flex-1 overflow-y-auto",children:g?o.jsx("div",{className:"flex items-center justify-center py-8",children:o.jsx($e,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):n.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center p-4",children:[o.jsx(Rr,{className:"w-12 h-12 text-muted-foreground/30 mb-4"}),o.jsx("h3",{className:"text-sm font-medium mb-2",children:"No skills found"}),o.jsxs("p",{className:"text-xs text-muted-foreground max-w-[220px]",children:["Create skills in"," ",o.jsx("code",{className:"text-[10px] bg-muted px-1 rounded",children:".otto/skills/ or .agents/skills/"})," ","or"," ",o.jsx("code",{className:"text-[10px] bg-muted px-1 rounded",children:"~/.config/otto/skills/ or ~/.agents/skills/"})]})]}):o.jsx("div",{className:"py-1",children:["cwd","parent","repo","user","system"].map(u=>{const d=Q.get(u);if(!d?.length)return null;const f=SH[u]??gs;return o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:[o.jsx(f,{className:"w-3 h-3"}),df[u]??u]}),d.map(h=>o.jsx("button",{type:"button",onClick:()=>s(h.name),className:`w-full text-left px-3 py-2 hover:bg-accent transition-colors ${r===h.name?"bg-accent":""}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(so,{className:"w-3.5 h-3.5 flex-shrink-0 text-muted-foreground"}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"text-sm font-medium truncate",children:h.name}),o.jsx("div",{className:"text-xs text-muted-foreground truncate",children:h.description})]})]})},`${h.scope}-${h.name}`))]},u)})})})]}):null}),RH=k.memo(function(){const e=Bt(n=>n.isExpanded),t=Bt(n=>n.toggleSidebar);return o.jsx("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Skills",children:o.jsx(Rr,{className:"w-5 h-5 text-muted-foreground mx-auto"})})}),UH={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"plaintext",toml:"toml"};function TH(A){const e=A.split(".").pop()?.toLowerCase()??"";return UH[e]??"plaintext"}const LH=k.memo(function(){const e=Bt(d=>d.isViewerOpen),t=Bt(d=>d.viewingFile),n=Bt(d=>d.selectedSkill),r=Bt(d=>d.closeViewer),{data:s}=n1(n),{data:i,isLoading:a}=vH(n,t),g=t===null,c=g?s?.content:i?.content,l=g?!s:a,B=g?"SKILL.md":t??"",Q=TH(B);if(k.useEffect(()=>{const d=f=>{const h=f.target,x=h.tagName==="INPUT"||h.tagName==="TEXTAREA"||h.isContentEditable;(f.key==="Escape"||f.key==="q"&&!x)&&e&&r()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,r]),!e||!n)return null;const u=document?.documentElement.classList.contains("dark")?rr:sr;return o.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[o.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:r,title:"Close viewer (ESC)",children:o.jsx(yt,{className:"w-4 h-4"})}),o.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:n}),o.jsx("span",{className:"text-xs text-muted-foreground",children:"/"}),o.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:B,children:B})]}),o.jsx("span",{className:"text-xs text-muted-foreground",children:Q})]}),o.jsx("div",{className:"flex-1 overflow-auto",children:l?o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Loading..."}):c?o.jsx("div",{className:"code-with-line-numbers",children:o.jsx(fn,{language:Q,style:u,wrapLines:!0,wrapLongLines:!0,lineProps:()=>({className:"code-line"}),customStyle:{margin:0,padding:"1rem",background:"transparent",fontSize:"0.75rem",lineHeight:"1.25rem"},codeTagProps:{style:{flex:1}},children:c})}):o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Unable to load file"})})]})}),Cf="file-browser",If=320,OH=280,KH=600;function jH({dirPath:A}){const t=Qt(s=>s.expandedDirs).has(A),{data:n,isLoading:r}=qy(A,t);return t?r?o.jsx("div",{className:"pl-4 py-1 text-xs text-muted-foreground",children:"Loading..."}):o.jsx("div",{className:"pl-3",children:n?.items.map(s=>o.jsx(r1,{name:s.name,path:s.path,type:s.type,gitignored:s.gitignored},s.path))}):null}function r1({name:A,path:e,type:t,gitignored:n}){const r=Qt(B=>B.expandedDirs),s=Qt(B=>B.toggleDir),i=Qt(B=>B.openFile),a=Qt(B=>B.selectedFile),g=r.has(e),c=a===e,l=k.useCallback(()=>{t==="directory"?s(e):i(e)},[t,e,s,i]);return o.jsxs("div",{children:[o.jsxs("button",{type:"button",onClick:l,className:`w-full text-left flex items-center gap-1.5 px-2 py-1 text-sm hover:bg-muted/50 rounded transition-colors ${c?"bg-muted text-foreground":"text-foreground/80"} ${n?"opacity-40":""}`,children:[t==="directory"?o.jsxs(o.Fragment,{children:[g?o.jsx(xn,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}):o.jsx(Dt,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),g?o.jsx(kf,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"}):o.jsx(Mf,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"})]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"w-3 flex-shrink-0"}),o.jsx(qc,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"})]}),o.jsx("span",{className:"truncate",children:A})]}),t==="directory"&&o.jsx(jH,{dirPath:e})]})}const JH=k.memo(function(){const e=Qt(a=>a.isExpanded),t=Qt(a=>a.collapseSidebar),n=ks(a=>a.widths[Cf]??If),{data:r,isLoading:s,refetch:i}=qy(".");return e?o.jsxs("div",{className:"border-l border-sidebar-border sidebar-fade-in flex h-full relative",style:{width:n},children:[o.jsx(fi,{panelKey:Cf,side:"right",minWidth:OH,maxWidth:KH,defaultWidth:If}),o.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[o.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Aa,{className:"w-4 h-4 text-muted-foreground"}),o.jsx("span",{className:"font-medium",children:"Files"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,children:o.jsx(Dt,{className:"w-4 h-4"})})]}),o.jsx("div",{className:"flex-1 overflow-y-auto p-1",children:s?o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading file tree..."}):!r||r.items.length===0?o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No files found"}):r.items.map(a=>o.jsx(r1,{name:a.name,path:a.path,type:a.type,gitignored:a.gitignored},a.path))}),o.jsxs("div",{className:"h-12 px-4 border-t border-border text-xs text-muted-foreground flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[o.jsx(Aa,{className:"w-3 h-3 flex-shrink-0"}),o.jsx("span",{className:"truncate",children:"Project Files"})]}),o.jsx(fe,{variant:"ghost",size:"icon",onClick:()=>i(),title:"Refresh file tree",className:"h-6 w-6 flex-shrink-0",disabled:s,children:o.jsx(Sn,{className:`w-3 h-3 ${s?"animate-spin":""}`})})]})]})]}):null}),qH=k.memo(function(){const e=Qt(n=>n.isExpanded),t=Qt(n=>n.toggleSidebar);return o.jsx("button",{type:"button",onClick:t,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${e?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Files",children:o.jsx(Aa,{className:"w-5 h-5 text-muted-foreground mx-auto"})})}),YH={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"plaintext",svelte:"svelte",toml:"toml",lock:"plaintext"};function HH(A){const e=A.split(".").pop()?.toLowerCase()??"";return YH[e]??"plaintext"}const PH=k.memo(function(){const e=Qt(g=>g.isViewerOpen),t=Qt(g=>g.selectedFile),n=Qt(g=>g.closeViewer),{data:r,isLoading:s}=lY(t);if(k.useEffect(()=>{const g=c=>{const l=c.target,B=l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable;(c.key==="Escape"||c.key==="q"&&!B)&&e&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[e,n]),!e||!t)return null;const i=document?.documentElement.classList.contains("dark")?rr:sr,a=HH(t);return o.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[o.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:n,title:"Close file viewer (ESC)",children:o.jsx(yt,{className:"w-4 h-4"})}),o.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[o.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:t,children:t}),r&&o.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[r.lineCount," lines"]})]}),o.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),o.jsx("div",{className:"flex-1 overflow-auto",children:s?o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Loading file..."}):r?o.jsx("div",{className:"code-with-line-numbers",children:o.jsx(fn,{language:a,style:i,wrapLines:!0,wrapLongLines:!0,lineProps:()=>({className:"code-line"}),customStyle:{margin:0,padding:"1rem",background:"transparent",fontSize:"0.75rem",lineHeight:"1.25rem"},codeTagProps:{style:{flex:1}},children:r.content})}):o.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Unable to load file"})})]})}),jQ=Rt(A=>({isOpen:!1,open:()=>A({isOpen:!0}),close:()=>A({isOpen:!1}),toggle:()=>A(e=>({isOpen:!e.isOpen}))}));function _H(A,e){const t=A.toLowerCase(),n=e.toLowerCase();if(t.length===0)return{match:!0,score:0};if(n.includes(t))return{match:!0,score:100-n.indexOf(t)};let r=0,s=0,i=-1;for(let a=0;a<n.length&&r<t.length;a++)n[a]===t[r]&&(s+=10,i===a-1&&(s+=5),(a===0||n[a-1]==="/"||n[a-1]===".")&&(s+=8),i=a,r++);return{match:r===t.length,score:s}}const zH=k.memo(function(){const e=jQ(x=>x.isOpen),t=jQ(x=>x.close),n=Qt(x=>x.openFile),r=Qt(x=>x.expandSidebar),[s,i]=k.useState(""),[a,g]=k.useState(0),c=k.useRef(null),l=k.useRef(null),{data:B}=Rh(),Q=k.useMemo(()=>new Set(B?.ignoredFiles??[]),[B?.ignoredFiles]),u=k.useMemo(()=>B?.files?s?B.files.map(b=>({file:b,..._H(s,b)})).filter(b=>b.match).sort((b,m)=>m.score-b.score).slice(0,50).map(b=>b.file):B.files.slice(0,50):[],[B?.files,s]);k.useEffect(()=>{e&&(i(""),g(0),setTimeout(()=>c.current?.focus(),0))},[e]),k.useEffect(()=>{l.current?.children[a]?.scrollIntoView({block:"nearest"})},[a]);const d=k.useCallback(x=>{r(),n(x),t()},[r,n,t]),f=k.useCallback(x=>{x.key==="ArrowDown"||x.ctrlKey&&x.key==="j"?(x.preventDefault(),g(b=>Math.min(b+1,u.length-1))):x.key==="ArrowUp"||x.ctrlKey&&x.key==="k"?(x.preventDefault(),g(b=>Math.max(b-1,0))):x.key==="Enter"&&u[a]?(x.preventDefault(),d(u[a])):x.key==="Escape"&&(x.preventDefault(),t())},[u,a,d,t]),h=k.useCallback(x=>{x.target===x.currentTarget&&t()},[t]);return e?o.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 bg-black/50 flex items-start justify-center z-[60] pt-[15vh]",onClick:h,onKeyDown:x=>{x.key==="Escape"&&t()},children:o.jsxs("div",{className:"bg-background border border-border rounded-lg shadow-2xl w-full max-w-lg overflow-hidden",children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 border-b border-border",children:[o.jsx(Do,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),o.jsx("input",{ref:c,type:"text",value:s,onChange:x=>{i(x.target.value),g(0)},onKeyDown:f,placeholder:"Search files by name...",className:"flex-1 bg-transparent py-3 text-sm text-foreground placeholder-muted-foreground outline-none"}),o.jsx("kbd",{className:"text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded border border-border font-mono",children:"ESC"})]}),o.jsx("div",{ref:l,className:"max-h-[40vh] overflow-y-auto",children:u.length===0?o.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:s?"No matching files":"No files found"}):u.map((x,b)=>{const m=Q.has(x);return o.jsxs("button",{type:"button",onClick:()=>d(x),className:`w-full text-left flex items-center gap-2 px-3 py-2 text-sm transition-colors ${b===a?"bg-accent text-accent-foreground":"text-foreground/80 hover:bg-muted/50"} ${m?"opacity-40":""}`,children:[o.jsx(qc,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),o.jsx(WH,{path:x,query:s}),m&&o.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground italic",children:"ignored"})]},x)})}),u.length>0&&o.jsxs("div",{className:"px-3 py-2 border-t border-border text-xs text-muted-foreground flex items-center gap-3",children:[o.jsxs("span",{children:[o.jsx("kbd",{className:"bg-muted px-1 py-0.5 rounded border border-border font-mono",children:"↑↓"})," ","navigate"]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"bg-muted px-1 py-0.5 rounded border border-border font-mono",children:"↵"})," ","open"]}),o.jsxs("span",{className:"ml-auto",children:[u.length," files"]})]})]})}):null});function WH({path:A,query:e}){if(!e)return o.jsx("span",{className:"truncate font-mono text-xs",children:A});const t=A.toLowerCase(),n=e.toLowerCase(),r=t.indexOf(n);return r>=0?o.jsxs("span",{className:"truncate font-mono text-xs",children:[A.slice(0,r),o.jsx("span",{className:"text-primary font-semibold",children:A.slice(r,r+e.length)}),A.slice(r+e.length)]}):o.jsx("span",{className:"truncate font-mono text-xs",children:A})}const VH=k.memo(function({authStatus:e,onSetupWallet:t,onImportWallet:n,onAddProvider:r,onRemoveProvider:s,onStartOAuth:i,onStartOAuthManual:a,onExchangeOAuthCode:g,onOpenTopup:c,onNext:l,manageMode:B=!1,onClose:Q,hideHeader:u=!1,onStartCopilotDeviceFlow:d,onPollCopilotDeviceFlow:f,onGetCopilotAuthMethods:h,onSaveCopilotToken:x,onImportCopilotTokenFromGh:b,onGetCopilotDiagnostics:m}){const[M,G]=k.useState(!1),[Y,Z]=k.useState(!1),[P,L]=k.useState(!1),[q,v]=k.useState(""),[U,w]=k.useState(!1),[E,C]=k.useState(null),[y,F]=k.useState(null),[T,J]=k.useState(""),[z,R]=k.useState(null),[I,p]=k.useState(null),[K,j]=k.useState(null),[$,eA]=k.useState(""),[CA,aA]=k.useState(!1),[LA,ZA]=k.useState(!1),[EA,VA]=k.useState(null),[oe,Qe]=k.useState(!1),[vA,JA]=k.useState(null),[we,Oe]=k.useState("oauth"),[ke,Ke]=k.useState(""),[GA,te]=k.useState(!1),[se,rt]=k.useState(!1),[xe,H]=k.useState(null),[N,S]=k.useState(null),[X,tA]=k.useState(!1),[iA,cA]=k.useState(!1),[ne,re]=k.useState(!1),$A=k.useRef(void 0),Ge=k.useRef(!1),Ae=k.useRef(f);Ae.current=f;const Ve=Te(oA=>oA.balance),kn=Te(oA=>oA.usdcBalance),lt=Te(oA=>oA.payg),ut=Te(oA=>oA.subscription),Yr=Te(oA=>oA.isLoading),je=k.useRef(null),Pe=k.useRef(null),An=k.useRef(null),st=Te(oA=>oA.isTopupModalOpen),HA=k.useRef(!1),{fetchBalance:Ot}=ql("setu"),ht=lt?.effectiveSpendableUsd??Ve??0,Je=ut?.active?`GO ${(ut.creditsRemaining??0).toFixed(1)} credits`:`$${ht.toFixed(2)}`;k.useEffect(()=>{HA.current&&!st&&Ot(),HA.current=st},[st,Ot]),k.useEffect(()=>{!e.setu.configured&&!Y&&(Z(!0),t().finally(()=>Z(!1)))},[e.setu.configured,t,Y]),k.useEffect(()=>{y&&je.current&&je.current.focus()},[y]),k.useEffect(()=>{K&&Pe.current&&Pe.current.focus()},[K]),k.useEffect(()=>{P&&An.current&&An.current.focus()},[P]),k.useEffect(()=>{if(!oe||!EA||!Ae.current)return;Ge.current=!1;const oA=Math.max((EA.interval||5)*1e3+2e3,7e3),TA=()=>{$A.current=setTimeout(async()=>{if(!Ge.current)try{const YA=Ae.current;if(!YA)return;const PA=await YA(EA.sessionId);if(Ge.current)return;PA.status==="complete"?(VA(null),Qe(!1),JA(null),cA(!1)):PA.status==="error"?(JA(PA.error||"Authorization failed"),Qe(!1)):TA()}catch{Ge.current||TA()}},oA)};TA();const FA=setTimeout(()=>{Qe(!1),JA("Authorization timed out. Please try again.")},3e5);return()=>{Ge.current=!0,$A.current&&clearTimeout($A.current),clearTimeout(FA)}},[oe,EA]);const Ks=async()=>{e.setu.publicKey&&(await navigator.clipboard.writeText(e.setu.publicKey),G(!0),setTimeout(()=>G(!1),2e3))},O=oA=>`${oA.slice(0,8)}...${oA.slice(-6)}`,_=async oA=>{if(T.trim())try{await r(oA,T.trim()),F(null),J("")}catch{}},W=async oA=>{if(I===oA){R(oA);try{await s(oA)}finally{R(null),p(null)}}else p(oA)},D=()=>{p(null)},V=()=>{d&&(re(!0),JA(null),d().then(oA=>{VA(oA),re(!1)}).catch(oA=>{JA(oA instanceof Error?oA.message:"Failed to start device flow"),re(!1)}))},sA=async(oA,TA)=>{oA==="anthropic"?j({provider:oA,sessionId:null,mode:TA}):oA==="copilot"?(Oe("oauth"),Ke(""),S(null),H(null),Qe(!1),VA(null),JA(null),cA(!0),h&&h().then(FA=>H(FA)).catch(()=>{}),m&&m().then(FA=>S(FA)).catch(()=>{}),V()):i(oA,TA)},nA=async()=>{if(K){ZA(!0);try{const{sessionId:oA}=await a(K.provider,K.mode);j({...K,sessionId:oA})}catch(oA){console.error("Failed to start OAuth:",oA)}ZA(!1)}},dA=async()=>{if(!(!K||!K.sessionId||!$.trim())){aA(!0);try{await g(K.provider,$.trim(),K.sessionId),j(null),eA("")}catch{}aA(!1)}},yA=()=>{j(null),eA("")},RA=()=>{EA&&(Br(EA.verificationUri),Qe(!0))},DA=oA=>{Oe(oA),JA(null),oA==="token"&&Qe(!1),oA==="oauth"&&!EA&&!ne&&V()},Re=async()=>{if(!(!ke.trim()||!x)){te(!0),JA(null);try{await x(ke.trim()),ie()}catch(oA){JA(oA instanceof Error?oA.message:"Failed to save Copilot token")}finally{te(!1)}}},KA=async()=>{if(b){rt(!0),JA(null);try{await b(),ie()}catch(oA){JA(oA instanceof Error?oA.message:"Failed to import token from GitHub CLI")}finally{rt(!1)}}},ce=async()=>{EA&&(await navigator.clipboard.writeText(EA.userCode),tA(!0),setTimeout(()=>tA(!1),2e3))},ie=()=>{VA(null),Qe(!1),JA(null),Ke(""),te(!1),rt(!1),Oe("oauth"),tA(!1),cA(!1),re(!1),Ge.current=!0,$A.current&&(clearTimeout($A.current),$A.current=void 0)},de=()=>{C(null),v(""),L(!0)},Ee=()=>{U||(L(!1),C(null),v(""))},le=async()=>{if(!(!q.trim()||U)){w(!0),C(null);try{await n(q.trim()),L(!1),v(""),Ot()}catch(oA){C(oA instanceof Error?oA.message:"Failed to import wallet")}finally{w(!1)}}},ae=Object.entries(e.providers).filter(([oA,TA])=>TA.configured&&oA!=="setu"),ue=Object.entries(e.providers).filter(([oA,TA])=>!TA.configured&&oA!=="setu");return o.jsxs("div",{className:"min-h-screen flex flex-col",children:[!u&&o.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Mn,{provider:"setu",size:24}),o.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),!B&&o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),"Step 1 of 2"]})]}),o.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${u?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:o.jsxs("div",{className:"max-w-7xl mx-auto",children:[o.jsxs("div",{className:"mb-10",children:[o.jsx("h1",{className:"text-2xl sm:text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:B?"Manage Providers":"Welcome to otto"}),o.jsx("p",{className:"text-lg text-muted-foreground max-w-2xl",children:B?"Add or remove AI providers. Your changes are saved automatically.":"Setu is your default AI provider. GO plan credits are applied automatically."})]}),o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 sm:gap-8",children:[o.jsx("div",{children:o.jsx("div",{className:"bg-card rounded-2xl border border-border p-5",children:e.setu.configured&&e.setu.publicKey?o.jsxs("div",{className:"flex flex-col h-full",children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-green-500/10 border border-green-500/20 rounded-lg",children:[o.jsx(Mn,{provider:"setu",size:16}),o.jsx("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:"Setu"}),o.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60 ml-auto",children:"Default Provider"})]}),o.jsx("div",{className:"flex justify-center py-4 mt-4",children:o.jsx("div",{className:"bg-white p-2 rounded-lg",children:o.jsx(Hl,{value:e.setu.publicKey,size:140,level:"M"})})}),o.jsxs("div",{className:"space-y-2 mt-4",children:[o.jsxs("button",{type:"button",onClick:Ks,className:"w-full flex items-center justify-center gap-2 px-3 py-2 bg-muted hover:bg-muted/80 rounded-lg text-xs font-mono text-muted-foreground transition-colors",children:[O(e.setu.publicKey),M?o.jsx(Dn,{className:"w-3.5 h-3.5 text-green-500"}):o.jsx(oo,{className:"w-3.5 h-3.5 text-muted-foreground"})]}),o.jsxs("div",{className:"space-y-1.5 px-3 py-2 bg-muted/50 rounded-lg",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"flex items-center gap-1.5 min-w-0",children:o.jsx("span",{className:"font-mono text-xs sm:text-sm text-foreground truncate",children:Je})}),o.jsx("button",{type:"button",onClick:Ot,disabled:Yr,className:"p-0.5 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:o.jsx(Sn,{className:`w-3 h-3 ${Yr?"animate-spin":""}`})})]}),o.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["Balance $",(Ve??0).toFixed(2)," • On-chain"," ",(kn??0).toFixed(2)," USDC"]})]})]}),o.jsxs("div",{className:"flex items-center gap-4 py-4",children:[o.jsx("div",{className:"flex-1 h-px bg-border"}),o.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"OR"}),o.jsx("div",{className:"flex-1 h-px bg-border"})]}),o.jsxs("button",{type:"button",onClick:c,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:bg-primary/90 transition-colors",children:[o.jsx(ka,{className:"w-4 h-4"}),"Top Up with Card"]}),o.jsxs("button",{type:"button",onClick:de,className:"w-full mt-2 flex items-center justify-center gap-2 px-4 py-2.5 border border-border text-foreground rounded-lg text-sm font-medium hover:bg-muted/50 transition-colors",children:[o.jsx(tc,{className:"w-4 h-4"}),"Import Wallet"]})]}):o.jsx("div",{className:"flex items-center justify-center py-16",children:o.jsx($e,{className:"w-8 h-8 animate-spin text-muted-foreground"})})})}),o.jsxs("div",{className:"sm:col-span-2 space-y-6",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsx("h2",{className:"font-semibold text-foreground",children:"Connected Providers"}),ae.length>0&&o.jsxs("span",{className:"text-sm text-muted-foreground",children:[ae.length," active"]})]}),ae.length===0?o.jsx("div",{className:"text-sm text-muted-foreground py-4",children:"No providers connected yet. Add one below."}):o.jsx("div",{className:"flex flex-wrap gap-2",children:ae.map(([oA,TA])=>o.jsxs("div",{className:`flex items-center gap-2 pl-3 pr-2 py-2 rounded-full transition-all duration-200 ${I===oA?"bg-destructive/10 border border-destructive/30":"group bg-green-500/10 border border-green-500/20"}`,children:[o.jsx(Mn,{provider:oA,size:16}),o.jsx("span",{className:`text-sm font-medium transition-colors ${I===oA?"text-destructive":"text-green-600 dark:text-green-400"}`,children:TA.label}),I!==oA&&o.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60",children:TA.type==="oauth"?"OAuth":"API"}),I===oA?o.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[o.jsx("span",{className:"text-xs text-destructive/80 mr-1",children:"Remove?"}),o.jsx("button",{type:"button",onClick:()=>W(oA),disabled:z===oA,className:"px-2 py-0.5 text-xs bg-destructive text-destructive-foreground rounded hover:bg-destructive/90 transition-colors disabled:opacity-50",children:z===oA?o.jsx($e,{className:"w-3 h-3 animate-spin"}):"Yes"}),o.jsx("button",{type:"button",onClick:D,className:"px-2 py-0.5 text-xs bg-muted text-muted-foreground rounded hover:bg-muted/80 transition-colors",children:"No"})]}):oA!=="setu"&&o.jsx("button",{type:"button",onClick:()=>W(oA),className:"ml-1 p-1 text-green-600/40 dark:text-green-500/40 hover:text-green-600/80 dark:hover:text-green-500/80 opacity-0 group-hover:opacity-100 transition-opacity",children:o.jsx(yt,{className:"w-3 h-3"})})]},oA))})]}),o.jsxs("div",{children:[o.jsx("h2",{className:"font-semibold text-foreground mb-4",children:"Add Providers"}),o.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 items-start",children:ue.map(([oA,TA])=>o.jsx("div",{children:y===oA?o.jsxs("div",{className:"flex items-center gap-2 p-3 bg-card border border-ring rounded-xl overflow-hidden",children:[o.jsx("div",{className:"shrink-0",children:o.jsx(Mn,{provider:oA,size:18})}),o.jsx("input",{ref:je,type:"password",value:T,onChange:FA=>J(FA.target.value),placeholder:`${TA.label} API key...`,className:"flex-1 min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground text-foreground",onKeyDown:FA=>{FA.key==="Enter"&&_(oA),FA.key==="Escape"&&(F(null),J(""))}}),o.jsx("button",{type:"button",onClick:()=>_(oA),disabled:!T.trim(),className:"shrink-0 px-3 py-1.5 bg-primary text-primary-foreground text-sm font-medium rounded-lg disabled:opacity-50",children:"Add"}),o.jsx("button",{type:"button",onClick:()=>{F(null),J("")},className:"shrink-0 p-1.5 text-muted-foreground hover:text-foreground",children:o.jsx(yt,{className:"w-4 h-4"})})]}):o.jsxs("div",{className:"flex items-center justify-between p-3 bg-card border border-border hover:border-border/80 rounded-xl transition-colors gap-2",children:[o.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[o.jsx(Mn,{provider:oA,size:20}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"font-medium text-foreground truncate",children:TA.label}),o.jsxs("div",{className:"text-xs text-muted-foreground",children:[TA.modelCount," models"]})]})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[oA!=="copilot"&&o.jsxs("button",{type:"button",onClick:()=>F(oA),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[o.jsx(tc,{className:"w-3.5 h-3.5"}),"API"]}),TA.supportsOAuth&&o.jsxs("button",{type:"button",onClick:()=>sA(oA,oA==="anthropic"?"max":void 0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[o.jsx(rn,{className:"w-3.5 h-3.5"}),oA==="anthropic"?"Pro":oA==="copilot"?"Login":"OAuth"]})]})]})},oA))})]})]})]})]})}),o.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:o.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[!B&&o.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground hidden sm:block",children:"You can add more providers later in settings"}),B?o.jsx("button",{type:"button",onClick:Q,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors ml-auto",children:"Done"}):o.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors",children:["Continue",o.jsx(vf,{className:"w-4 h-4"})]})]})}),P&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(Mn,{provider:"setu",size:24}),o.jsx("h3",{className:"text-lg font-semibold",children:"Import Setu Wallet"})]}),o.jsxs("div",{className:"p-6",children:[o.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste your base58 private key to replace the current wallet used for Setu."}),o.jsx("textarea",{ref:An,value:q,onChange:oA=>v(oA.target.value),placeholder:"Enter private key",className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors font-mono text-xs resize-y",onKeyDown:oA=>{(oA.metaKey||oA.ctrlKey)&&oA.key==="Enter"&&(oA.preventDefault(),le()),oA.key==="Escape"&&Ee()}}),E&&o.jsx("p",{className:"text-sm text-red-500 mt-3",children:E}),o.jsxs("div",{className:"flex gap-3 mt-5",children:[o.jsx("button",{type:"button",onClick:Ee,disabled:U,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Cancel"}),o.jsx("button",{type:"button",onClick:le,disabled:!q.trim()||U,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:U?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Import Wallet"})]})]})]})}),K&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(Mn,{provider:K.provider,size:24}),o.jsxs("h3",{className:"text-lg font-semibold",children:["Connect"," ",e.providers[K.provider]?.label||K.provider]})]}),K.sessionId?o.jsxs("div",{className:"p-6",children:[o.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste the authorization code:"}),o.jsx("input",{type:"text",ref:Pe,value:$,onChange:oA=>eA(oA.target.value),placeholder:"Paste code here...",className:"w-full h-11 px-4 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors mb-4 font-mono text-sm",onKeyDown:oA=>{oA.key==="Enter"&&dA(),oA.key==="Escape"&&yA()}}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{type:"button",onClick:yA,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),o.jsx("button",{type:"button",onClick:dA,disabled:!$.trim()||CA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:CA?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Connect"})]})]}):o.jsxs("div",{className:"p-6",children:[o.jsxs("p",{className:"text-sm text-muted-foreground mb-6",children:["You'll be redirected to"," ",e.providers[K.provider]?.label||K.provider," ","to authorize access. After authorizing, copy the code and return here."]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{type:"button",onClick:yA,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),o.jsx("button",{type:"button",onClick:nA,disabled:LA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:LA?o.jsx($e,{className:"w-4 h-4 animate-spin"}):o.jsxs(o.Fragment,{children:["Continue",o.jsx(rn,{className:"w-4 h-4"})]})})]})]})]})}),iA&&o.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:o.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[o.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[o.jsx(Mn,{provider:"copilot",size:24}),o.jsx("h3",{className:"text-lg font-semibold",children:"Connect GitHub Copilot"})]}),o.jsxs("div",{className:"p-6 space-y-4",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:()=>DA("oauth"),className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${we==="oauth"?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"OAuth"}),o.jsx("button",{type:"button",onClick:()=>DA("token"),className:`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${we==="token"?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"Token"})]}),we==="oauth"?o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm text-muted-foreground",children:"Enter this code on GitHub to authorize:"}),o.jsx("div",{className:"flex items-center justify-center gap-3",children:ne?o.jsx("div",{className:"bg-muted px-6 py-3 rounded-lg animate-pulse",children:o.jsx("div",{className:"h-9 w-48 bg-muted-foreground/20 rounded"})}):EA?o.jsxs(o.Fragment,{children:[o.jsx("code",{className:"text-3xl font-mono font-bold tracking-widest text-foreground bg-muted px-6 py-3 rounded-lg select-all",children:EA.userCode}),o.jsx("button",{type:"button",onClick:ce,className:"p-2 text-muted-foreground hover:text-foreground transition-colors",children:X?o.jsx(Dn,{className:"w-5 h-5 text-green-500"}):o.jsx(oo,{className:"w-5 h-5"})})]}):null})]}):o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm text-muted-foreground",children:"Paste a GitHub token with Copilot model access."}),o.jsx("input",{type:"password",value:ke,onChange:oA=>Ke(oA.target.value),placeholder:"gho_...",className:"w-full h-11 px-4 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors"}),xe?.ghImport.available&&o.jsx("button",{type:"button",onClick:KA,disabled:se,className:"w-full h-10 px-4 bg-muted text-foreground rounded-lg font-medium hover:bg-muted/80 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:se?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Import from GH CLI"}),xe?.ghImport.available&&!xe.ghImport.authenticated&&o.jsx("p",{className:"text-xs text-muted-foreground",children:xe.ghImport.reason||"GitHub CLI is not authenticated"}),xe&&!xe.ghImport.available&&xe.ghImport.reason&&o.jsx("p",{className:"text-xs text-muted-foreground",children:xe.ghImport.reason})]}),N&&N.tokenSources.length>0&&o.jsx("div",{className:"text-xs text-muted-foreground space-y-1",children:N.tokenSources.map(oA=>o.jsxs("div",{children:[oA.source,":"," ",oA.configured?oA.error?oA.error:`${oA.modelCount??0} models visible`:"not configured",oA.restrictedByOrgPolicy&&oA.restrictedOrg?` (org restriction: ${oA.restrictedOrg})`:""]},oA.source))}),vA&&o.jsx("p",{className:"text-sm text-red-500 text-center",children:vA}),oe&&we==="oauth"&&o.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground",children:[o.jsx($e,{className:"w-4 h-4 animate-spin"}),"Waiting for authorization..."]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsx("button",{type:"button",onClick:ie,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),we==="oauth"?o.jsx("button",{type:"button",onClick:RA,disabled:oe||ne,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:oe||ne?o.jsx($e,{className:"w-4 h-4 animate-spin"}):o.jsxs(o.Fragment,{children:["Open GitHub",o.jsx(rn,{className:"w-4 h-4"})]})}):o.jsx("button",{type:"button",onClick:Re,disabled:!ke.trim()||GA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:GA?o.jsx($e,{className:"w-4 h-4 animate-spin"}):"Save token"})]})]})]})})]})}),ZH=k.memo(function({authStatus:e,onComplete:t,onBack:n,hideHeader:r=!1}){const[s,i]=k.useState(null),[a,g]=k.useState(null),[c,l]=k.useState(!0),[B,Q]=k.useState(!1),[u,d]=k.useState("setu"),[f,h]=k.useState("kimi-k2.5"),[x,b]=k.useState(e.defaults.agent||"build"),[m,M]=k.useState(e.defaults.toolApproval||"dangerous"),[G,Y]=k.useState(!1),Z=k.useRef(!1),P=k.useId(),L=k.useId(),q=k.useId(),v=k.useId();k.useEffect(()=>{(async()=>{try{const[y,F]=await Promise.all([xA.getConfig(),xA.getAllModels()]);i(y),g(F);const T=y?.defaults?.provider||"setu",J=y?.defaults?.model||"kimi-k2.5",z=F?.[T]?.models?.length>0,R=z?T:"setu",I=z&&F[T].models.some(p=>p.id===J)?J:F?.[R]?.models?.[0]?.id||"kimi-k2.5";d(R),h(I),y?.defaults?.agent&&b(y.defaults.agent),y?.defaults?.toolApproval&&M(y.defaults.toolApproval),y?.defaults?.guidedMode&&Y(y.defaults.guidedMode)}catch{}finally{l(!1)}})()},[]),k.useEffect(()=>{if(s?.agents?.length){const C=s.agents;(!x||!C.includes(x))&&b(C.includes("build")?"build":C[0])}},[s,x]),k.useEffect(()=>{if(a?.[u]&&Z.current){const C=a[u];C.models.some(y=>y.id===f)||h(C.models[0]?.id||"")}},[u,a,f]);const U=async()=>{Q(!0);try{await xA.updateDefaults({provider:u,model:f,agent:x,toolApproval:m,guidedMode:G,fullWidthContent:s?.defaults?.fullWidthContent??!0,scope:"global"}),await t()}catch{}finally{Q(!1)}};if(c)return o.jsx("div",{className:"min-h-screen flex items-center justify-center",children:o.jsx($e,{className:"w-8 h-8 animate-spin text-muted-foreground"})});const w=s?.providers.filter(C=>(e.providers[C]?.configured||C==="setu")&&a?.[C]?.models?.length>0)||["setu"],E=a?.[u]?.models||[];return o.jsxs("div",{className:"min-h-screen flex flex-col",children:[!r&&o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Mn,{provider:"setu",size:24}),o.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500"}),"Step 2 of 2"]})]}),o.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${r?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:o.jsxs("div",{className:"max-w-7xl mx-auto",children:[o.jsxs("div",{className:"mb-10",children:[o.jsx("h1",{className:"text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:"Configure Defaults"}),o.jsx("p",{className:"text-lg text-muted-foreground",children:"Set your preferences. You can change these anytime in settings."})]}),o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[o.jsxs("div",{className:"md:col-span-2",children:[o.jsx("label",{htmlFor:P,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Provider"}),o.jsxs("div",{className:"relative",children:[o.jsx("select",{id:P,value:u,onChange:C=>{Z.current=!0,d(C.target.value)},className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:w.map(C=>o.jsx("option",{value:C,children:e.providers[C]?.label||C},C))}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),o.jsxs("div",{className:"md:col-span-2",children:[o.jsx("label",{htmlFor:L,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Model"}),o.jsxs("div",{className:"relative",children:[o.jsx("select",{id:L,value:f,onChange:C=>h(C.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:E.map(C=>o.jsx("option",{value:C.id,children:C.label||C.id},C.id))}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),o.jsxs("div",{children:[o.jsx("label",{htmlFor:q,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Agent"}),o.jsxs("div",{className:"relative",children:[o.jsx("select",{id:q,value:x,onChange:C=>b(C.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:(s?.agents||["build"]).map(C=>o.jsx("option",{value:C,children:C},C))}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),o.jsxs("div",{children:[o.jsx("label",{htmlFor:v,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Tool Approval"}),o.jsxs("div",{className:"relative",children:[o.jsxs("select",{id:v,value:m,onChange:C=>M(C.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:[o.jsx("option",{value:"auto",children:"Auto - run without asking"}),o.jsx("option",{value:"dangerous",children:"Dangerous - approve writes only"}),o.jsx("option",{value:"all",children:"All - approve every tool"})]}),o.jsx(xn,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]}),o.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Controls when tool executions need approval"})]}),o.jsx("div",{className:"md:col-span-2",children:o.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-card border border-border rounded-xl",children:[o.jsxs("div",{children:[o.jsx("span",{className:"text-sm font-medium text-foreground",children:"Guided Mode"}),o.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"AI will run commands and manage services for you instead of giving instructions"})]}),o.jsx("button",{type:"button",role:"switch","aria-checked":G,onClick:()=>Y(!G),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${G?"bg-primary":"bg-muted"}`,children:o.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${G?"translate-x-6":"translate-x-1"} ${G?"bg-primary-foreground":"bg-foreground"}`})})]})})]})]})}),o.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:o.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[o.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-2 px-4 py-3 text-muted-foreground hover:text-foreground transition-colors",children:[o.jsx(V1,{className:"w-4 h-4"}),"Back"]}),o.jsx("button",{type:"button",onClick:U,disabled:B,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:B?o.jsxs(o.Fragment,{children:[o.jsx($e,{className:"w-4 h-4 animate-spin"}),"Setting up..."]}):o.jsxs(o.Fragment,{children:["Start Using otto",o.jsx(Rr,{className:"w-4 h-4"})]})})]})})]})}),XH=k.memo(function({hideHeader:e=!1}){const t=nn(P=>P.isOpen),n=nn(P=>P.currentStep),r=nn(P=>P.manageMode),s=nn(P=>P.authStatus),i=nn(P=>P.nextStep),a=nn(P=>P.prevStep),g=nn(P=>P.reset),c=Te(P=>P.openTopupModal),{setupWallet:l,importWallet:B,addProvider:Q,removeProvider:u,completeOnboarding:d,startOAuth:f,startOAuthManual:h,exchangeOAuthCode:x,startCopilotDeviceFlow:b,pollCopilotDeviceFlow:m,getCopilotAuthMethods:M,saveCopilotToken:G,importCopilotTokenFromGh:Y,getCopilotDiagnostics:Z}=Vd();return!t||!s?null:o.jsxs("div",{className:"fixed inset-0 z-[9999] bg-background text-foreground overflow-y-auto",children:[n==="wallet"&&o.jsx(VH,{authStatus:s,onSetupWallet:l,onImportWallet:B,onAddProvider:Q,onRemoveProvider:u,onStartOAuth:f,onStartOAuthManual:h,onExchangeOAuthCode:x,onOpenTopup:c,onNext:i,manageMode:r,onClose:g,hideHeader:e,onStartCopilotDeviceFlow:b,onPollCopilotDeviceFlow:m,onGetCopilotAuthMethods:M,onSaveCopilotToken:G,onImportCopilotTokenFromGh:Y,onGetCopilotDiagnostics:Z}),n==="defaults"&&o.jsx(ZH,{authStatus:s,onComplete:d,onBack:a,hideHeader:e})]})}),s1="otto-theme";function $H(){if(typeof window>"u")return"dark";const A=window.localStorage.getItem(s1);return A==="light"||A==="dark"?A:window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}function A7(){const[A,e]=k.useState(()=>$H());k.useEffect(()=>{if(typeof document>"u")return;const n=document.documentElement;A==="dark"?n.classList.add("dark"):n.classList.remove("dark");try{window.localStorage.setItem(s1,A)}catch(r){console.warn("Failed to persist theme preference",r)}window.parent&&window.parent!==window&&window.parent.postMessage({type:"otto-set-theme",theme:A},"*")},[A]),k.useEffect(()=>{if(typeof window>"u")return;const n=r=>{r.data?.type==="otto-set-theme"&&(r.data.theme==="light"||r.data.theme==="dark")&&e(r.data.theme)};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[]);const t=k.useCallback(()=>{e(n=>n==="dark"?"light":"dark")},[]);return k.useMemo(()=>({theme:A,setTheme:e,toggleTheme:t}),[A,t])}function e7(){const[A,e]=k.useState(null);return k.useEffect(()=>{(async()=>{try{const s=`${window.OTTO_SERVER_URL||Rs}/v1/config/cwd`;console.log("[useWorkingDirectory] Fetching from:",s);const i=await fetch(s);if(!i.ok)throw console.error("[useWorkingDirectory] Failed:",i.status,i.statusText),new Error(`Failed to fetch working directory: ${i.status}`);const a=await i.json();console.log("[useWorkingDirectory] Success:",a),a.dirName&&(console.log("[useWorkingDirectory] Setting title to:",a.dirName),e(a.dirName),document.title=a.dirName)}catch(n){console.error("[useWorkingDirectory] Error:",n),document.title="otto"}})()},[]),A}function t7({sessionIds:A,activeSessionId:e,gitFiles:t,onSelectSession:n,onNewSession:r,onStageFile:s,onUnstageFile:i,onRestoreFile:a,onDeleteFile:g,onStageAll:c,onUnstageAll:l,onOpenCommitModal:B,onViewDiff:Q,onReturnToInput:u}){const{currentFocus:d,sessionIndex:f,gitFileIndex:h,setFocus:x,setSessionIndex:b,setGitFileIndex:m,resetGitFileIndex:M}=Wd(),{setCollapsed:G,toggleCollapse:Y}=xo(),{isExpanded:Z,toggleSidebar:P}=We(),L=We(w=>w.closeDiff),q=Tt(w=>w.toggleSidebar),v=A.indexOf(e||""),U=k.useCallback(w=>{const E=w.target,C=E.tagName==="INPUT"||E.tagName==="TEXTAREA"||E.isContentEditable,y=!!E.closest("[data-terminal-viewer]");if((w.ctrlKey||w.metaKey)&&w.key==="h"){w.preventDefault(),d==="sessions"?(document.activeElement?.blur(),x("input"),G(!0),setTimeout(()=>u?.(),50)):d==="git"?(document.activeElement?.blur(),x("input"),P(),L(),setTimeout(()=>u?.(),50)):(document.activeElement?.blur(),x("sessions"),G(!1),v>=0&&b(v));return}if((w.ctrlKey||w.metaKey)&&w.key==="l"){w.preventDefault(),d==="git"?(document.activeElement?.blur(),x("input"),P(),L(),setTimeout(()=>u?.(),50)):d==="sessions"?(document.activeElement?.blur(),x("input"),G(!0),setTimeout(()=>u?.(),50)):(document.activeElement?.blur(),Z||P(),x("git"),M());return}if((w.ctrlKey||w.metaKey)&&w.key==="/"){w.preventDefault(),Y();return}if((w.ctrlKey||w.metaKey)&&w.key==="\\"){w.preventDefault(),P();return}if((w.ctrlKey||w.metaKey)&&w.shiftKey&&w.key==="r"){w.preventDefault(),q();return}if((w.ctrlKey||w.metaKey)&&w.key==="n"){w.preventDefault(),r();return}if((w.ctrlKey||w.metaKey)&&w.key==="p"){w.preventDefault(),jQ.getState().toggle();return}if(w.key==="Escape"&&!y||w.key==="q"&&!C&&(d==="sessions"||d==="git")){w.preventDefault(),d==="sessions"?G(!0):d==="git"&&(P(),L()),x("input"),u?.();return}if(d==="sessions"&&!C){if(w.key==="j"&&A.length>0){w.preventDefault();const F=Math.min(f+1,A.length-1);b(F);return}if(w.key==="k"&&A.length>0){w.preventDefault();const F=Math.max(f-1,0);b(F);return}if(w.key==="Enter"&&A[f]){w.preventDefault(),n(A[f]),x("input");return}}if(d==="git"&&!C){if(w.key==="j"&&t.length>0){w.preventDefault();const F=Math.min(h+1,t.length-1);m(F);return}if(w.key==="k"&&t.length>0){w.preventDefault();const F=Math.max(h-1,0);m(F);return}if(w.key===" "&&t[h]){w.preventDefault();const F=t[h];F.staged?i?.(F.path):s?.(F.path);return}if(w.key==="a"){w.preventDefault(),c?.();return}if(w.key==="u"){w.preventDefault(),l?.();return}if(w.key==="R"&&t[h]){w.preventDefault();const F=t[h];!F.staged&&F.status!=="untracked"&&F.status!=="added"&&a?.(F.path);return}if(w.shiftKey&&w.key==="D"||w.key==="Backspace"){w.preventDefault();const F=t[h];F&&!F.staged&&F.status==="untracked"&&g?.(F.path);return}if(w.key==="c"){w.preventDefault(),B?.();return}if(w.key==="Enter"&&t[h]){w.preventDefault();const F=t[h];Q?.(F.path,F.staged);return}}},[d,f,h,A,t,v,Z,x,b,m,M,G,P,q,Y,n,r,s,i,a,g,c,l,B,Q,u,L]);return k.useEffect(()=>(window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)),[U]),{currentFocus:d,sessionIndex:f,gitFileIndex:h}}function n7(A){const e=k.useRef(null),t=k.useRef(null),n=Te(c=>c.setBalance),r=Te(c=>c.setPaymentPending),s=Er(c=>c.removeToast),i=Er(c=>c.updateToast),a=jc(c=>c.setPendingTopup),g=jc(c=>c.clearPendingTopup);k.useEffect(()=>{if(!A)return;const c=new jy;e.current=c;const l=xA.getStreamUrl(A);c.connect(l);const B=c.on("*",Q=>{const u=Q.payload;switch(Q.type){case"setu.topup.required":{const d=typeof u?.amountUsd=="number"?u.amountUsd:0,f=typeof u?.currentBalance=="number"?u.currentBalance:0,h=typeof u?.minTopupUsd=="number"?u.minTopupUsd:5,x=typeof u?.suggestedTopupUsd=="number"?u.suggestedTopupUsd:10,b=typeof u?.messageId=="string"?u.messageId:"";a({sessionId:A,messageId:b,amountUsd:d,currentBalance:f,minTopupUsd:h,suggestedTopupUsd:x});break}case"setu.topup.method_selected":{u?.method==="crypto"&&(r(!0),t.current=ve.loading("💳 Processing crypto payment..."));break}case"setu.topup.cancelled":{g();const d=typeof u?.reason=="string"?u.reason:"Request cancelled";ve(`⚠️ ${d}`);break}case"setu.payment.required":{const d=typeof u?.amountUsd=="number"?u.amountUsd:0;r(!0),t.current||(t.current=ve.loading(`💳 Payment required: $${d.toFixed(2)}`));break}case"setu.payment.signing":{t.current?i(t.current,{message:"✍️ Signing transaction..."}):t.current=ve.loading("✍️ Signing transaction...");break}case"setu.payment.complete":{g();const d=u?.amountUsd,f=u?.newBalance,h=typeof u?.transactionId=="string"?u.transactionId:void 0,x=typeof d=="number"?d:typeof d=="string"?parseFloat(d):0,b=typeof f=="number"?f:typeof f=="string"?parseFloat(f):0;n(b),r(!1),t.current&&(s(t.current),t.current=null);const m=`✅ Paid $${x.toFixed(2)}`;h?ve.successWithAction(m,{label:"View Tx",href:`https://orbmarkets.io/tx/${h}`}):ve.success(m);break}case"setu.fiat.checkout_created":{g(),r(!1),t.current&&(s(t.current),t.current=null),ve.success("💳 Complete payment, then retry your message");break}case"setu.balance.updated":{const d=u?.balanceRemaining,f=typeof d=="number"?d:typeof d=="string"?parseFloat(d):null;f!==null&&!Number.isNaN(f)&&n(f);break}case"setu.payment.error":{g();const d=typeof u?.error=="string"?u.error:"Payment failed";r(!1),t.current&&(s(t.current),t.current=null),ve.error(`❌ ${d}`);break}}});return()=>{B(),c.disconnect()}},[A,n,r,s,i,a,g])}const Pl=c1({component:r7});function r7(){const{checkOnboarding:A}=Vd();return k.useEffect(()=>{A()},[A]),o.jsxs(o.Fragment,{children:[o.jsx(l1,{}),o.jsx(XH,{}),o.jsx(zd,{}),null]})}const s7=YQ("/")({beforeLoad:()=>{throw u1({to:"/sessions"})},component:()=>null});function ff({height:A=16,className:e=""}){const t=Math.round(A*2.4686468646864688);return o.jsx("svg",{width:t,height:A,viewBox:"0 0 748 303",fill:"currentColor",className:e,"aria-label":"otto",role:"img",children:o.jsx("path",{d:"M192.877 257.682C192.877 263.287 191.783 268.551 189.596 273.473C187.545 278.395 184.674 282.701 180.982 286.393C177.428 289.947 173.189 292.818 168.268 295.006C163.482 297.057 158.287 298.082 152.682 298.082H44.1953C38.7266 298.082 33.5312 297.057 28.6094 295.006C23.6875 292.818 19.3809 289.947 15.6895 286.393C12.1348 282.701 9.26367 278.395 7.07617 273.473C5.02539 268.551 4 263.287 4 257.682V120.074C4 114.469 5.02539 109.205 7.07617 104.283C9.26367 99.3613 12.1348 95.123 15.6895 91.5684C19.3809 87.877 23.6875 85.0059 28.6094 82.9551C33.5312 80.7676 38.7266 79.6738 44.1953 79.6738H152.682C158.287 79.6738 163.482 80.7676 168.268 82.9551C173.189 85.0059 177.428 87.877 180.982 91.5684C184.674 95.123 187.545 99.3613 189.596 104.283C191.783 109.205 192.877 114.469 192.877 120.074V257.682ZM44.1953 120.074V257.682H152.682V120.074H44.1953ZM331.715 4V298.082H289.674V46.041H239.225V4H331.715ZM478.961 4V298.082H436.92V46.041H386.471V4H478.961ZM743.717 257.682C743.717 263.287 742.623 268.551 740.436 273.473C738.385 278.395 735.514 282.701 731.822 286.393C728.268 289.947 724.029 292.818 719.107 295.006C714.322 297.057 709.127 298.082 703.521 298.082H595.035C589.566 298.082 584.371 297.057 579.449 295.006C574.527 292.818 570.221 289.947 566.529 286.393C562.975 282.701 560.104 278.395 557.916 273.473C555.865 268.551 554.84 263.287 554.84 257.682V120.074C554.84 114.469 555.865 109.205 557.916 104.283C560.104 99.3613 562.975 95.123 566.529 91.5684C570.221 87.877 574.527 85.0059 579.449 82.9551C584.371 80.7676 589.566 79.6738 595.035 79.6738H703.521C709.127 79.6738 714.322 80.7676 719.107 82.9551C724.029 85.0059 728.268 87.877 731.822 91.5684C735.514 95.123 738.385 99.3613 740.436 104.283C742.623 109.205 743.717 114.469 743.717 120.074V257.682ZM595.035 120.074V257.682H703.521V120.074H595.035Z"})})}const hf="left-sidebar",pf=272,o7=256,i7=480,a7=k.memo(function({children:e,onNewSession:t}){const n=We(a=>a.isDiffOpen),r=xo(a=>a.isCollapsed),s=xo(a=>a.toggleCollapse),i=ks(a=>a.widths[hf]??pf);return k.useEffect(()=>(r?document.body.style.overflow="":document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[r]),r?o.jsxs("aside",{className:"w-12 md:w-12 border-r border-border bg-background flex flex-col transition-all duration-300 ease-in-out hidden md:flex",children:[o.jsx("div",{className:"h-14 border-b border-border flex items-center justify-center",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:t,title:"New session",className:"rounded-full touch-manipulation text-muted-foreground hover:bg-muted/50",children:o.jsx(Qr,{className:"w-4 h-4"})})}),o.jsx("button",{type:"button",className:"flex-1 cursor-pointer hover:bg-muted/50 transition-colors touch-manipulation",onClick:n?void 0:s,title:n?void 0:"Expand sidebar","aria-label":"Expand sidebar"}),o.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:"Expand sidebar",disabled:n,className:"transition-transform duration-200 hover:scale-110 touch-manipulation text-muted-foreground hover:bg-muted/50",children:o.jsx(Dt,{className:"w-4 h-4"})})})]}):o.jsxs(o.Fragment,{children:[!r&&o.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 md:hidden",onClick:s,"aria-hidden":"true"}),o.jsxs("aside",{className:"border-r border-sidebar-border sidebar-fade-in flex transition-all duration-300 ease-in-out fixed md:relative top-0 left-0 z-50 h-screen md:h-auto w-full md:w-auto",style:{maxWidth:"100%"},children:[o.jsxs("div",{className:"flex-1 flex flex-col min-w-0 relative",style:{width:i},children:[o.jsxs("div",{className:"h-14 border-b border-sidebar-border px-4 flex items-center gap-2 md:hidden bg-sidebar",children:[o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:"Close menu",className:"touch-manipulation flex-shrink-0 text-sidebar-foreground hover:bg-sidebar-accent","aria-label":"Close menu",children:o.jsx(yt,{className:"w-5 h-5"})}),o.jsx("div",{className:"flex-1 flex items-center",children:o.jsx(ff,{height:14,className:"text-sidebar-foreground"})})]}),o.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[o.jsx("div",{className:"absolute top-0 left-0 right-0 z-10 pointer-events-none",children:o.jsxs("div",{className:"h-14 px-4 flex items-center justify-between border-b border-sidebar-border/40 bg-sidebar/40 backdrop-blur-xl supports-[backdrop-filter]:bg-sidebar/20",children:[o.jsx("div",{className:"flex items-center text-sidebar-foreground/90",children:o.jsx(ff,{height:14,className:"select-none"})}),o.jsx("button",{type:"button",onClick:t,className:"w-9 h-9 rounded-full bg-sidebar-primary flex items-center justify-center hover:opacity-90 transition-opacity touch-manipulation pointer-events-auto",title:"New session",children:o.jsx(Qr,{className:"w-4 h-4 text-sidebar-primary-foreground"})})]})}),o.jsx("div",{className:"absolute inset-0 overflow-hidden",children:e})]}),o.jsx("div",{className:"h-12 border-t border-sidebar-border px-2 flex items-center justify-end",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:"Collapse sidebar",disabled:n,className:"transition-transform duration-200 hover:scale-110 touch-manipulation text-sidebar-muted-foreground hover:bg-sidebar-accent w-8 h-8",children:o.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-300",role:"img","aria-label":"Collapse sidebar",children:[o.jsx("title",{children:"Collapse sidebar"}),o.jsx("path",{d:"M15 18l-6-6 6-6"})]})})})]}),o.jsx("div",{className:"hidden md:block",children:o.jsx(fi,{panelKey:hf,side:"left",minWidth:o7,maxWidth:i7,defaultWidth:pf})})]})]})}),g7=k.memo(function({sidebar:e,children:t,onNewSession:n,theme:r,onToggleTheme:s,sessionId:i,onNavigateToSession:a,onFixWithAI:g}){const c=We(b=>b.isExpanded),l=Et(b=>b.isExpanded),B=Tt(b=>b.isExpanded),Q=Zt(b=>b.isExpanded),u=He(b=>b.isExpanded),d=Qt(b=>b.isExpanded),f=ct(b=>b.isExpanded),h=Bt(b=>b.isExpanded),x=c||l||B||Q||u||d||f||h;return o.jsxs("div",{className:"h-screen flex bg-background touch-manipulation border-t border-border/50",children:[o.jsx(a7,{onNewSession:n,children:e}),o.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden w-full md:w-auto",children:[o.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[o.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[o.jsx(BY,{}),o.jsx(NY,{}),o.jsx(PH,{}),o.jsx(LH,{}),t]}),o.jsxs("div",{className:"hidden md:flex",children:[o.jsx(gY,{onFixWithAI:g}),o.jsx(pY,{sessionId:i}),o.jsx(UY,{parentSessionId:i??null,onNavigateToSession:a}),o.jsx(ZY,{}),o.jsx(gH,{}),o.jsx(JH,{}),o.jsx(bH,{}),o.jsx(GH,{}),o.jsxs("div",{className:`flex flex-col w-12 border-l ${x?"sidebar-fade-in border-sidebar-border":"bg-background border-border"}`,children:[o.jsx(cY,{}),o.jsx(mY,{sessionId:i}),o.jsx(LY,{parentSessionId:i}),o.jsx(qH,{}),o.jsx(AH,{}),o.jsx(cH,{}),o.jsx(NH,{}),o.jsx(RH,{}),o.jsx("div",{className:"flex-1"}),o.jsx(rk,{}),o.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:o.jsx(fe,{variant:"ghost",size:"icon",onClick:s,title:`Switch to ${r==="dark"?"light":"dark"} mode`,"aria-label":`Switch to ${r==="dark"?"light":"dark"} mode`,className:"touch-manipulation",children:r==="dark"?o.jsx(Z1,{className:"w-4 h-4"}):o.jsx(X1,{className:"w-4 h-4"})})})]})]})]}),o.jsx(nk,{})]}),o.jsx(QY,{}),o.jsx(ok,{}),o.jsx(zH,{})]})});function o1({sessionId:A}){const e=k.useRef(null),t=jM(),{data:n}=bo(),{theme:r,toggleTheme:s}=A7(),{openCommitModal:i,openDiff:a}=We(),g=B1(),{data:c=[]}=Al(),{data:l}=el(),B=tl(),Q=uE(),u=Uh(),d=Th(),f=iE(P=>P.openConfirmation);e7(),n7(A),ql(n?.defaults?.provider);const h=k.useCallback(()=>{setTimeout(()=>{e.current?.focus()},100)},[]),x=k.useCallback(async()=>{try{const P=await t.mutateAsync({agent:n?.defaults.agent||"general",provider:n?.defaults.provider,model:n?.defaults.model});g({to:"/sessions/$sessionId",params:{sessionId:P.id},replace:!1}),h()}catch(P){console.error("Failed to create session:",P)}},[t,n,g,h]),b=k.useCallback(()=>{g({to:"/sessions"})},[g]),m=k.useCallback(P=>{g({to:"/sessions/$sessionId",params:{sessionId:P}}),h()},[g,h]),M=k.useCallback(async P=>{try{const L=await t.mutateAsync({agent:n?.defaults.agent||"general",provider:n?.defaults.provider,model:n?.defaults.model,title:"Fix Git Error"});g({to:"/sessions/$sessionId",params:{sessionId:L.id},replace:!1}),await xA.sendMessage(L.id,{content:P})}catch(L){console.error("Failed to create fix session:",L)}},[t,n,g]),G=k.useMemo(()=>l?[...(l.conflicted??[]).map(P=>({path:P.path,staged:!1,status:P.status})),...l.staged.map(P=>({path:P.path,staged:!0,status:P.status})),...l.unstaged.map(P=>({path:P.path,staged:!1,status:P.status})),...l.untracked.map(P=>({path:P.path,staged:!1,status:P.status}))]:[],[l]),Y=k.useMemo(()=>c.map(P=>P.id),[c]);t7({sessionIds:Y,activeSessionId:A,gitFiles:G,onSelectSession:m,onNewSession:x,onStageFile:P=>B.mutate([P]),onUnstageFile:P=>Q.mutate([P]),onRestoreFile:P=>u.mutate([P]),onDeleteFile:P=>{f({title:"Delete File",message:`Delete ${P}? This will permanently remove the untracked file.`,confirmLabel:"Delete",variant:"destructive",onConfirm:async()=>{await d.mutateAsync([P])}})},onStageAll:()=>{const P=G.filter(L=>!L.staged).map(L=>L.path);P.length>0&&B.mutate(P)},onUnstageAll:()=>{const P=G.filter(L=>L.staged).map(L=>L.path);P.length>0&&Q.mutate(P)},onOpenCommitModal:i,onViewDiff:a,onReturnToInput:h}),k.useEffect(()=>{A&&h()},[A,h]);const Z=k.useMemo(()=>A?o.jsxs(o.Fragment,{children:[o.jsx(zq,{sessionId:A,onSelectSession:m}),o.jsx(u5,{ref:e,sessionId:A,onNewSession:x,onDeleteSession:b})]}):o.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a session or create a new one to start"}),[A,x,m,b]);return o.jsxs(o.Fragment,{children:[o.jsx(g7,{onNewSession:x,theme:r,onToggleTheme:s,sessionId:A,onNavigateToSession:m,onFixWithAI:M,sidebar:o.jsx(Xq,{activeSessionId:A,onSelectSession:m}),children:Z}),o.jsx(ck,{})]})}const c7=YQ("/sessions/")({component:l7});function l7(){return o.jsx(o1,{})}const i1=YQ("/sessions/$sessionId")({component:u7});function u7(){const{sessionId:A}=i1.useParams();return o.jsx(o1,{sessionId:A})}const B7=s7.update({id:"/",path:"/",getParentRoute:()=>Pl}),Q7=c7.update({id:"/sessions/",path:"/sessions/",getParentRoute:()=>Pl}),E7=i1.update({id:"/sessions/$sessionId",path:"/sessions/$sessionId",getParentRoute:()=>Pl}),d7={IndexRoute:B7,SessionsSessionIdRoute:E7,SessionsIndexRoute:Q7},C7=Pl._addFileChildren(d7)._addFileTypes(),I7=()=>{const t=(typeof globalThis<"u"?globalThis.OTTO_ROUTER_BASEPATH:void 0)??"/"??"/";if(!t||t==="/")return"/";const n=t.replace(/\/+$/,"")||"/";return n.startsWith("/")?n:`/${n}`},f7=Q1({routeTree:C7,basepath:I7()}),Zd=new E1({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1,structuralSharing:!0}}});Zd.prefetchQuery({queryKey:["sessions"],queryFn:()=>xA.getSessions()});Zd.prefetchQuery({queryKey:["config"],queryFn:()=>xA.getConfig()});function h7(){return o.jsx(d1,{client:Zd,children:o.jsx(C1,{router:f7})})}const a1=document.getElementById("root");if(!a1)throw new Error("Root element not found");I1.createRoot(a1).render(o.jsx(k.StrictMode,{children:o.jsx(h7,{})}));export{fA as B,Xi as H,CR as a,pn as b,sg as c,U6 as d,Ls as e,Ir as f,_E as g,tg as i,kl as l,_t as s};