tako-cli 0.3.38 → 0.3.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -288,7 +288,7 @@ Press Enter, Esc, or q to close. This announcement is shown once.
|
|
|
288
288
|
Press Enter, Esc, or q to close.
|
|
289
289
|
`),await US((i)=>{if(i==="\r"||i===`
|
|
290
290
|
`)return!0;if(i==="\x1B"||i==="q"||i==="Q")return!0;return},!0),process.stdout.write(`
|
|
291
|
-
`)}import{readFileSync as u8,writeFileSync as l8,mkdirSync as c8}from"fs";import{join as zS}from"path";import{homedir as JS}from"os";function p8(){let e=process.env.TAKO_REGION?.trim().toLowerCase();if(e==="cn"||e==="china")return"cn";if(e==="global"||e==="intl"||e==="international")return"global";return null}function f8(){try{let e=u8(KS,"utf-8"),o=JSON.parse(e);if(o.region!=="cn"&&o.region!=="global")return null;if(typeof o.detectedAt!=="number")return null;if(Date.now()-o.detectedAt>d8)return null;return o.region}catch{return null}}function PS(e){try{c8(zS(JS(),".tako"),{recursive:!0}),l8(KS,JSON.stringify({region:e,detectedAt:Date.now()}),"utf-8")}catch{}}function g8(){try{let o=Intl.DateTimeFormat().resolvedOptions().timeZone||"";if(/^Asia\/(Shanghai|Urumqi|Chongqing|Harbin|Kashgar|Hong_Kong|Macau)$/i.test(o)){if(/^Asia\/(Shanghai|Urumqi|Chongqing|Harbin|Kashgar)$/i.test(o))return"cn"}}catch{}let e=(process.env.LANG||process.env.LC_ALL||process.env.LC_MESSAGES||"").toLowerCase();if(e.startsWith("zh_cn")||e.startsWith("zh-cn"))return"cn";return null}async function m8(){if(kf)return kf;return kf=(async()=>{let o=[E8,C8,h8,I8].map((i)=>i().then((a)=>a?a:Promise.reject(Error("null"))));try{return await Promise.race([Promise.any(o),new Promise((a,s)=>setTimeout(()=>s(Error("net-timeout")),1200))])}catch{return"cn"}})(),kf}async function Mr(){if(Mu)return Mu;let e=p8();if(e)return Mu=e,e;let o=f8();if(o)return Mu=o,o;let i=g8();if(i)return Mu=i,PS(i),i;let a=await m8();return Mu=a,PS(a),a}async function E8(){try{let e=await fetch("https://ip-api.com/json/?fields=countryCode",{signal:AbortSignal.timeout(1000)});if(!e.ok)return null;return(await e.json()).countryCode==="CN"?"cn":"global"}catch{return null}}async function C8(){try{let e=await fetch("https://ipinfo.io/json",{signal:AbortSignal.timeout(1000)});if(!e.ok)return null;return(await e.json()).country==="CN"?"cn":"global"}catch{return null}}async function h8(){try{let e=await fetch("https://api.ip.sb/geoip",{signal:AbortSignal.timeout(1000)});if(!e.ok)return null;return(await e.json()).country_code==="CN"?"cn":"global"}catch{return null}}async function I8(){let e=[async()=>{let o=await fetch("https://myip.ipip.net/json",{signal:AbortSignal.timeout(800)});if(!o.ok)return null;let i=await o.json(),a=i?.data?.location;if(Array.isArray(a)&&a[0]==="\u4E2D\u56FD")return"cn";let s=i?.data?.country_code;return s==="CN"?"cn":s?"global":null},async()=>{let o=await fetch("https://whois.pconline.com.cn/ipJson.jsp?json=true",{signal:AbortSignal.timeout(800)});if(!o.ok)return null;let i=await o.text();try{let a=JSON.parse(i.trim());if(a.proCode&&/^\d{6}$/.test(a.proCode))return"cn"}catch{}return null},async()=>{let o=await fetch("http://ip.3322.net/api/",{signal:AbortSignal.timeout(600)});if(!o.ok)return null;let i=(await o.text()).trim();if(/^\d+\.\d+\.\d+\.\d+$/.test(i))return"cn";return null}];try{return await Promise.any(e.map((o)=>o().then((i)=>i??Promise.reject())))}catch{return null}}async function B8(){let e=await Mr();return mA[e]}async function Ni(){return(await B8()).npm}function YS(){return"curl -fsSL https://bun.sh/install | bash"}async function y8(){let e=mA.cn.bunBinary,o=await fetch(`${e}/`,{signal:AbortSignal.timeout(1e4)});if(!o.ok)throw Error(`Failed to fetch bun versions: ${o.status}`);let a=(await o.json()).map((s)=>s.name.replace(/\/$/,"")).filter((s)=>/^bun-v\d+\.\d+\.\d+$/.test(s)).sort((s,u)=>{let d=s.replace("bun-v","").split(".").map(Number),p=u.replace("bun-v","").split(".").map(Number);for(let g=0;g<3;g++)if(d[g]!==p[g])return p[g]-d[g];return 0});if(a.length===0)throw Error("No bun versions found on mirror");return a[0]}async function WS(){let e=mA.cn.bunBinary,o=await y8(),a={darwin:"darwin",win32:"windows",linux:"linux"}[process.platform]||"linux",s=process.arch==="arm64"?"aarch64":"x64",u=`bun-${a}-${s}`;return`${e}/${o}/${u}.zip`}async function oh(){let e=await Mr(),o=mA[e];if(e==="cn")Fe.info(`${Ge("region.usingChinaMirror")} npm: ${o.npm}`);else Fe.info(Ge("region.usingGlobalMirror"))}var Mu=null,kf=null,KS,d8=2592000000,mA;var Tc=O(()=>{Mn();Lr();KS=zS(JS(),".tako","region.json"),mA={cn:{npm:"https://registry.npmmirror.com",bunBinary:"https://registry.npmmirror.com/-/binary/bun",nodeBinary:"https://cdn.npmmirror.com/binaries/node"},global:{npm:"https://registry.npmjs.org",bunBinary:null,nodeBinary:"https://nodejs.org/dist"}}});var D8=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[o,i]of Object.entries(this.headers)){let a=await i;a!==null&&(e[o]=a)}return e}addHeader(e,o){this.headers[e]=o}async post(e,o,i,a){try{let s=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:o?JSON.stringify(o??{}):void 0,keepalive:!0,...i});if(s.status===401)return null;if(s.status!==200&&s.status!==202)throw Error(`HTTP error! status: ${s.status}`);let u=await s.text();return u?JSON.parse(u):null}catch(s){if(a<this.maxRetries){let u=this.initialRetryDelay*2**a;return await new Promise((d)=>setTimeout(d,u)),this.post(e,o,i,a+1)}return console.error("Max retries reached:",s),null}}async fetch(e,o,i={}){let a=`${this.baseUrl}${e}`;return this.post(a,o,i,0)}},jS=class{constructor(e){this.groups=[],this.queue=[],this.options=e;let o={"openpanel-client-id":e.clientId};e.clientSecret&&(o["openpanel-client-secret"]=e.clientSecret),o["openpanel-sdk-name"]=e.sdk||"node",o["openpanel-sdk-version"]=e.sdkVersion||"1.3.1",this.api=new D8({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:o})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type==="replay"&&!this.sessionId)}addQueue(e){e.type==="track"&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let o=await this.api.fetch("/track",e,{keepalive:e.type!=="replay"});this.deviceId=o?.deviceId;let i=!!this.sessionId;return this.sessionId=o?.sessionId,!i&&this.sessionId&&this.flush(),o}setGlobalProperties(e){this.global={...this.global,...e}}track(e,o){this.log("track event",e,o);let{groups:i,profileId:a,...s}=o??{},u=[...new Set([...this.groups,...i??[]])];return this.send({type:"track",payload:{name:e,profileId:a??this.profileId,groups:u.length>0?u:void 0,properties:{...this.global??{},...s}}})}identify(e){if(this.log("identify user",e),e.profileId&&(this.profileId=e.profileId,this.flush()),e.profileId&&Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}upsertGroup(e){return this.log("upsert group",e),this.send({type:"group",payload:e})}setGroup(e){return this.log("set group",e),this.groups.includes(e)||(this.groups=[...this.groups,e]),this.send({type:"assign_group",payload:{groupIds:[e],profileId:this.profileId}})}setGroups(e){return this.log("set groups",e),this.groups=[...new Set([...this.groups,...e])],this.send({type:"assign_group",payload:{groupIds:e,profileId:this.profileId}})}alias(e){}increment(e){return this.send({type:"increment",payload:e})}decrement(e){return this.send({type:"decrement",payload:e})}revenue(e,o){let i=o?.deviceId;return delete o?.deviceId,this.track("revenue",{...o??{},...i?{__deviceId:i}:{},__revenue:e})}getDeviceId(){return this.deviceId??""}getSessionId(){return this.sessionId??""}fetchDeviceId(){return Promise.resolve(this.deviceId??"")}clear(){this.profileId=void 0,this.groups=[],this.deviceId=void 0,this.sessionId=void 0}buildFlushPayload(e){if(e.type==="replay")return e.payload;if(e.type==="track"){let o="groups"in e.payload?e.payload.groups??[]:[],i=[...new Set([...this.groups,...o])];return{...e.payload,profileId:e.payload.profileId??this.profileId,groups:i.length>0?i:void 0}}return e.type==="identify"||e.type==="increment"||e.type==="decrement"?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.type==="assign_group"?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.payload}flush(){let e=[];for(let o of this.queue){if(this.shouldQueue(o)){e.push(o);continue}let i=this.buildFlushPayload(o);this.send({...o,payload:i})}this.queue=e}log(...e){this.options.debug&&console.log("[OpenPanel.dev]",...e)}};var qS=()=>{};function VS(){if(!Ou)Ou=new jS({clientId:Q8,clientSecret:w8,apiUrl:v8});return Ou}function XS(e,o,i){let a=VS().track(e,{profileId:o,...i}).catch(()=>{});Lf.push(a)}function $S(e,o){let{email:i,...a}=o,s=VS().identify({profileId:e,...typeof i==="string"?{email:i}:{},firstName:String(a.platform||""),properties:a}).catch(()=>{});Lf.push(s)}async function ZS(){if(await Promise.allSettled(Lf),Lf.length=0,Ou){try{Ou.flush()}catch{}Ou=null}}var Q8="d65a6d4b-f702-4af6-98e7-bdb999e01d5f",w8="sec_1e0ea34016bc3a5f8ef5",v8="https://op.shiroha.tech/api",Ou=null,Lf;var ex=O(()=>{qS();Lf=[]});function tx(){return{cli_version:S8,platform:process.platform,arch:process.arch,locale:xi(),node_version:process.version}}function nx(e){return Bun.hash(e).toString(16).slice(0,8)}var S8="0.3.38";var ih=O(()=>{Mn()});async function ox(){if(_u!==null)return _u;try{return _u=(await tt()).telemetryEnabled!==!1,_u}catch{return _u=!1,!1}}async function ix(){try{let e=await tt();if(e.apiId)return e.apiId;let o=e.providers??[],i=e.defaultProviderId,a=i?o.find((s)=>s.id===i):o[0];if(a){if(a.apiId)return a.apiId;if(a.email)return a.email;return a.id}return"anonymous"}catch{return"anonymous"}}async function er(){if(rh)return;try{if(!await ox())return;let e=await tt(),o=await ix();if(o==="anonymous")return;let a=(e.providers??[]).find((u)=>u.email)?.email,s=await Mr();$S(o,{...a?{email:a}:{},region:s,locale:xi(),first_seen_version:x8,platform:process.platform,arch:process.arch}),rh=!0}catch{}}function $n(e,o){b8(e,o).catch(()=>{})}async function b8(e,o){try{if(!await ox())return;let i=await ix();XS(e,i,{...tx(),...o})}catch{}}async function Fc(){await ZS()}function wa(){_u=null,rh=!1}var x8="0.3.38",rh=!1,_u=null;var Or=O(()=>{ex();on();Tc();Mn();ih();ih()});function F8(e,o){let i=[];if(o.phase)i.push(o.phase);if(o.pkgCount>0)i.push(`\u5DF2\u5904\u7406 ${o.pkgCount} \u4E2A\u5305`);return i.push(`${o.elapsedSec}s`),`${e} \xB7 ${i.join(" \xB7 ")}`}async function fs(e,o,i){let a=Date.now(),s={phase:"\u6B63\u5728\u51C6\u5907",pkgCount:0,elapsedSec:0},u=[],d=()=>{s.elapsedSec=Math.floor((Date.now()-a)/1000),i(F8(o,s))};d();let p=setInterval(d,1000),g=(h)=>{if(!h)return;if(u.push(h),N8.test(h))s.phase="\u89E3\u6790\u4F9D\u8D56";else if(rx.test(h)){s.phase="\u4E0B\u8F7D\u5E76\u89E3\u538B";let Q=h.match(rx);if(Q)s.pkgCount=parseInt(Q[1],10)}else if(R8.test(h))s.phase="\u5199\u5165 lockfile";else if(T8.test(h))s.phase="\u5B8C\u6210";d()},m=async(h)=>{if(!h)return;let Q=h.getReader(),C=new TextDecoder,w="";try{while(!0){let{done:N,value:v}=await Q.read();if(N)break;w+=C.decode(v,{stream:!0}).replace(/\r/g,"");let S=w.split(`
|
|
291
|
+
`)}import{readFileSync as u8,writeFileSync as l8,mkdirSync as c8}from"fs";import{join as zS}from"path";import{homedir as JS}from"os";function p8(){let e=process.env.TAKO_REGION?.trim().toLowerCase();if(e==="cn"||e==="china")return"cn";if(e==="global"||e==="intl"||e==="international")return"global";return null}function f8(){try{let e=u8(KS,"utf-8"),o=JSON.parse(e);if(o.region!=="cn"&&o.region!=="global")return null;if(typeof o.detectedAt!=="number")return null;if(Date.now()-o.detectedAt>d8)return null;return o.region}catch{return null}}function PS(e){try{c8(zS(JS(),".tako"),{recursive:!0}),l8(KS,JSON.stringify({region:e,detectedAt:Date.now()}),"utf-8")}catch{}}function g8(){try{let o=Intl.DateTimeFormat().resolvedOptions().timeZone||"";if(/^Asia\/(Shanghai|Urumqi|Chongqing|Harbin|Kashgar|Hong_Kong|Macau)$/i.test(o)){if(/^Asia\/(Shanghai|Urumqi|Chongqing|Harbin|Kashgar)$/i.test(o))return"cn"}}catch{}let e=(process.env.LANG||process.env.LC_ALL||process.env.LC_MESSAGES||"").toLowerCase();if(e.startsWith("zh_cn")||e.startsWith("zh-cn"))return"cn";return null}async function m8(){if(kf)return kf;return kf=(async()=>{let o=[E8,C8,h8,I8].map((i)=>i().then((a)=>a?a:Promise.reject(Error("null"))));try{return await Promise.race([Promise.any(o),new Promise((a,s)=>setTimeout(()=>s(Error("net-timeout")),1200))])}catch{return"cn"}})(),kf}async function Mr(){if(Mu)return Mu;let e=p8();if(e)return Mu=e,e;let o=f8();if(o)return Mu=o,o;let i=g8();if(i)return Mu=i,PS(i),i;let a=await m8();return Mu=a,PS(a),a}async function E8(){try{let e=await fetch("https://ip-api.com/json/?fields=countryCode",{signal:AbortSignal.timeout(1000)});if(!e.ok)return null;return(await e.json()).countryCode==="CN"?"cn":"global"}catch{return null}}async function C8(){try{let e=await fetch("https://ipinfo.io/json",{signal:AbortSignal.timeout(1000)});if(!e.ok)return null;return(await e.json()).country==="CN"?"cn":"global"}catch{return null}}async function h8(){try{let e=await fetch("https://api.ip.sb/geoip",{signal:AbortSignal.timeout(1000)});if(!e.ok)return null;return(await e.json()).country_code==="CN"?"cn":"global"}catch{return null}}async function I8(){let e=[async()=>{let o=await fetch("https://myip.ipip.net/json",{signal:AbortSignal.timeout(800)});if(!o.ok)return null;let i=await o.json(),a=i?.data?.location;if(Array.isArray(a)&&a[0]==="\u4E2D\u56FD")return"cn";let s=i?.data?.country_code;return s==="CN"?"cn":s?"global":null},async()=>{let o=await fetch("https://whois.pconline.com.cn/ipJson.jsp?json=true",{signal:AbortSignal.timeout(800)});if(!o.ok)return null;let i=await o.text();try{let a=JSON.parse(i.trim());if(a.proCode&&/^\d{6}$/.test(a.proCode))return"cn"}catch{}return null},async()=>{let o=await fetch("http://ip.3322.net/api/",{signal:AbortSignal.timeout(600)});if(!o.ok)return null;let i=(await o.text()).trim();if(/^\d+\.\d+\.\d+\.\d+$/.test(i))return"cn";return null}];try{return await Promise.any(e.map((o)=>o().then((i)=>i??Promise.reject())))}catch{return null}}async function B8(){let e=await Mr();return mA[e]}async function Ni(){return(await B8()).npm}function YS(){return"curl -fsSL https://bun.sh/install | bash"}async function y8(){let e=mA.cn.bunBinary,o=await fetch(`${e}/`,{signal:AbortSignal.timeout(1e4)});if(!o.ok)throw Error(`Failed to fetch bun versions: ${o.status}`);let a=(await o.json()).map((s)=>s.name.replace(/\/$/,"")).filter((s)=>/^bun-v\d+\.\d+\.\d+$/.test(s)).sort((s,u)=>{let d=s.replace("bun-v","").split(".").map(Number),p=u.replace("bun-v","").split(".").map(Number);for(let g=0;g<3;g++)if(d[g]!==p[g])return p[g]-d[g];return 0});if(a.length===0)throw Error("No bun versions found on mirror");return a[0]}async function WS(){let e=mA.cn.bunBinary,o=await y8(),a={darwin:"darwin",win32:"windows",linux:"linux"}[process.platform]||"linux",s=process.arch==="arm64"?"aarch64":"x64",u=`bun-${a}-${s}`;return`${e}/${o}/${u}.zip`}async function oh(){let e=await Mr(),o=mA[e];if(e==="cn")Fe.info(`${Ge("region.usingChinaMirror")} npm: ${o.npm}`);else Fe.info(Ge("region.usingGlobalMirror"))}var Mu=null,kf=null,KS,d8=2592000000,mA;var Tc=O(()=>{Mn();Lr();KS=zS(JS(),".tako","region.json"),mA={cn:{npm:"https://registry.npmmirror.com",bunBinary:"https://registry.npmmirror.com/-/binary/bun",nodeBinary:"https://cdn.npmmirror.com/binaries/node"},global:{npm:"https://registry.npmjs.org",bunBinary:null,nodeBinary:"https://nodejs.org/dist"}}});var D8=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[o,i]of Object.entries(this.headers)){let a=await i;a!==null&&(e[o]=a)}return e}addHeader(e,o){this.headers[e]=o}async post(e,o,i,a){try{let s=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:o?JSON.stringify(o??{}):void 0,keepalive:!0,...i});if(s.status===401)return null;if(s.status!==200&&s.status!==202)throw Error(`HTTP error! status: ${s.status}`);let u=await s.text();return u?JSON.parse(u):null}catch(s){if(a<this.maxRetries){let u=this.initialRetryDelay*2**a;return await new Promise((d)=>setTimeout(d,u)),this.post(e,o,i,a+1)}return console.error("Max retries reached:",s),null}}async fetch(e,o,i={}){let a=`${this.baseUrl}${e}`;return this.post(a,o,i,0)}},jS=class{constructor(e){this.groups=[],this.queue=[],this.options=e;let o={"openpanel-client-id":e.clientId};e.clientSecret&&(o["openpanel-client-secret"]=e.clientSecret),o["openpanel-sdk-name"]=e.sdk||"node",o["openpanel-sdk-version"]=e.sdkVersion||"1.3.1",this.api=new D8({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:o})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type==="replay"&&!this.sessionId)}addQueue(e){e.type==="track"&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let o=await this.api.fetch("/track",e,{keepalive:e.type!=="replay"});this.deviceId=o?.deviceId;let i=!!this.sessionId;return this.sessionId=o?.sessionId,!i&&this.sessionId&&this.flush(),o}setGlobalProperties(e){this.global={...this.global,...e}}track(e,o){this.log("track event",e,o);let{groups:i,profileId:a,...s}=o??{},u=[...new Set([...this.groups,...i??[]])];return this.send({type:"track",payload:{name:e,profileId:a??this.profileId,groups:u.length>0?u:void 0,properties:{...this.global??{},...s}}})}identify(e){if(this.log("identify user",e),e.profileId&&(this.profileId=e.profileId,this.flush()),e.profileId&&Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}upsertGroup(e){return this.log("upsert group",e),this.send({type:"group",payload:e})}setGroup(e){return this.log("set group",e),this.groups.includes(e)||(this.groups=[...this.groups,e]),this.send({type:"assign_group",payload:{groupIds:[e],profileId:this.profileId}})}setGroups(e){return this.log("set groups",e),this.groups=[...new Set([...this.groups,...e])],this.send({type:"assign_group",payload:{groupIds:e,profileId:this.profileId}})}alias(e){}increment(e){return this.send({type:"increment",payload:e})}decrement(e){return this.send({type:"decrement",payload:e})}revenue(e,o){let i=o?.deviceId;return delete o?.deviceId,this.track("revenue",{...o??{},...i?{__deviceId:i}:{},__revenue:e})}getDeviceId(){return this.deviceId??""}getSessionId(){return this.sessionId??""}fetchDeviceId(){return Promise.resolve(this.deviceId??"")}clear(){this.profileId=void 0,this.groups=[],this.deviceId=void 0,this.sessionId=void 0}buildFlushPayload(e){if(e.type==="replay")return e.payload;if(e.type==="track"){let o="groups"in e.payload?e.payload.groups??[]:[],i=[...new Set([...this.groups,...o])];return{...e.payload,profileId:e.payload.profileId??this.profileId,groups:i.length>0?i:void 0}}return e.type==="identify"||e.type==="increment"||e.type==="decrement"?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.type==="assign_group"?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.payload}flush(){let e=[];for(let o of this.queue){if(this.shouldQueue(o)){e.push(o);continue}let i=this.buildFlushPayload(o);this.send({...o,payload:i})}this.queue=e}log(...e){this.options.debug&&console.log("[OpenPanel.dev]",...e)}};var qS=()=>{};function VS(){if(!Ou)Ou=new jS({clientId:Q8,clientSecret:w8,apiUrl:v8});return Ou}function XS(e,o,i){let a=VS().track(e,{profileId:o,...i}).catch(()=>{});Lf.push(a)}function $S(e,o){let{email:i,...a}=o,s=VS().identify({profileId:e,...typeof i==="string"?{email:i}:{},firstName:String(a.platform||""),properties:a}).catch(()=>{});Lf.push(s)}async function ZS(){if(await Promise.allSettled(Lf),Lf.length=0,Ou){try{Ou.flush()}catch{}Ou=null}}var Q8="d65a6d4b-f702-4af6-98e7-bdb999e01d5f",w8="sec_1e0ea34016bc3a5f8ef5",v8="https://op.shiroha.tech/api",Ou=null,Lf;var ex=O(()=>{qS();Lf=[]});function tx(){return{cli_version:S8,platform:process.platform,arch:process.arch,locale:xi(),node_version:process.version}}function nx(e){return Bun.hash(e).toString(16).slice(0,8)}var S8="0.3.39";var ih=O(()=>{Mn()});async function ox(){if(_u!==null)return _u;try{return _u=(await tt()).telemetryEnabled!==!1,_u}catch{return _u=!1,!1}}async function ix(){try{let e=await tt();if(e.apiId)return e.apiId;let o=e.providers??[],i=e.defaultProviderId,a=i?o.find((s)=>s.id===i):o[0];if(a){if(a.apiId)return a.apiId;if(a.email)return a.email;return a.id}return"anonymous"}catch{return"anonymous"}}async function er(){if(rh)return;try{if(!await ox())return;let e=await tt(),o=await ix();if(o==="anonymous")return;let a=(e.providers??[]).find((u)=>u.email)?.email,s=await Mr();$S(o,{...a?{email:a}:{},region:s,locale:xi(),first_seen_version:x8,platform:process.platform,arch:process.arch}),rh=!0}catch{}}function $n(e,o){b8(e,o).catch(()=>{})}async function b8(e,o){try{if(!await ox())return;let i=await ix();XS(e,i,{...tx(),...o})}catch{}}async function Fc(){await ZS()}function wa(){_u=null,rh=!1}var x8="0.3.39",rh=!1,_u=null;var Or=O(()=>{ex();on();Tc();Mn();ih();ih()});function F8(e,o){let i=[];if(o.phase)i.push(o.phase);if(o.pkgCount>0)i.push(`\u5DF2\u5904\u7406 ${o.pkgCount} \u4E2A\u5305`);return i.push(`${o.elapsedSec}s`),`${e} \xB7 ${i.join(" \xB7 ")}`}async function fs(e,o,i){let a=Date.now(),s={phase:"\u6B63\u5728\u51C6\u5907",pkgCount:0,elapsedSec:0},u=[],d=()=>{s.elapsedSec=Math.floor((Date.now()-a)/1000),i(F8(o,s))};d();let p=setInterval(d,1000),g=(h)=>{if(!h)return;if(u.push(h),N8.test(h))s.phase="\u89E3\u6790\u4F9D\u8D56";else if(rx.test(h)){s.phase="\u4E0B\u8F7D\u5E76\u89E3\u538B";let Q=h.match(rx);if(Q)s.pkgCount=parseInt(Q[1],10)}else if(R8.test(h))s.phase="\u5199\u5165 lockfile";else if(T8.test(h))s.phase="\u5B8C\u6210";d()},m=async(h)=>{if(!h)return;let Q=h.getReader(),C=new TextDecoder,w="";try{while(!0){let{done:N,value:v}=await Q.read();if(N)break;w+=C.decode(v,{stream:!0}).replace(/\r/g,"");let S=w.split(`
|
|
292
292
|
`);w=S.pop()??"";for(let L of S)g(L)}if(w)g(w)}finally{Q.releaseLock()}};try{await Promise.all([m(e.stderr),m(e.stdout)])}finally{clearInterval(p)}return u.join(`
|
|
293
293
|
`)}var N8,rx,R8,T8;var Mf=O(()=>{N8=/^Resolving dependencies/,rx=/^Resolved, downloaded and extracted \[(\d+)\]/,R8=/^Saved lockfile/,T8=/^(\d+) packages? installed/});function k8(e){return e.replace(/\r/g,`
|
|
294
294
|
`).replace(/\n{3,}/g,`
|
|
@@ -688,12 +688,12 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
|
|
|
688
688
|
`;if(this.lastOutputHeight>=this.options.stdout.rows){let p=_A(this.options.stdout);if(p)this.options.stdout.write(OA);if(this.options.stdout.write(Nn.clearTerminal+this.fullStaticOutput+o),this.lastOutput=o,this.lastOutputToRender=d,this.lastOutputHeight=i,this.log.sync(d),p)this.options.stdout.write(Qs);return}if(s){let p=_A(this.options.stdout);if(p)this.options.stdout.write(OA);if(this.log.clear(),this.options.stdout.write(a),this.log(d),p)this.options.stdout.write(Qs)}else if(o!==this.lastOutput||this.log.isCursorDirty())this.throttledLog(d);this.lastOutput=o,this.lastOutputToRender=d,this.lastOutputHeight=i};render(e){let o=VB.default.createElement(ws.Provider,{value:{isScreenReaderEnabled:this.isScreenReaderEnabled}},VB.default.createElement(zR,{stdin:this.options.stdin,stdout:this.options.stdout,stderr:this.options.stderr,exitOnCtrlC:this.options.exitOnCtrlC,writeToStdout:this.writeToStdout,writeToStderr:this.writeToStderr,setCursorPosition:this.setCursorPosition,onExit:this.handleAppExit},e));if(this.options.concurrent)Ti.updateContainer(o,this.container,null,Dm);else Ti.updateContainerSync(o,this.container,null,Dm),Ti.flushSyncWork()}writeToStdout(e){if(this.isUnmounted)return;if(this.options.debug){this.options.stdout.write(e+this.fullStaticOutput+this.lastOutput);return}if(zr){this.options.stdout.write(e);return}let o=_A(this.options.stdout);if(o)this.options.stdout.write(OA);if(this.log.clear(),this.options.stdout.write(e),this.restoreLastOutput(),o)this.options.stdout.write(Qs)}writeToStderr(e){if(this.isUnmounted)return;if(this.options.debug){this.options.stderr.write(e),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(zr){this.options.stderr.write(e);return}let o=_A(this.options.stdout);if(o)this.options.stdout.write(OA);if(this.log.clear(),this.options.stderr.write(e),this.restoreLastOutput(),o)this.options.stdout.write(Qs)}unmount(e){if(this.isUnmounted||this.isUnmounting)return;if(this.isUnmounting=!0,this.beforeExitHandler)gl.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0;let o=this.options.stdout,i=!o.destroyed&&!o.writableEnded&&(o.writable??!0),a=(m)=>{if(typeof m.flush!=="function")return;if(i)m.flush();else if(typeof m.cancel==="function")m.cancel()};if(a(this.throttledOnRender??{}),i){if(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")this.calculateLayout(),this.onRender()}if(this.isUnmounted=!0,this.unsubscribeExit(),typeof this.restoreConsole==="function")this.restoreConsole();if(typeof this.unsubscribeResize==="function")this.unsubscribeResize();if(this.cancelKittyDetection)this.cancelKittyDetection();let s=this.throttledLog;if(a(s),i){if(this.kittyProtocolEnabled)try{this.options.stdout.write("\x1B[<u")}catch{}if(zr)this.options.stdout.write(this.lastOutput+`
|
|
689
689
|
`);else if(!this.options.debug)this.log.done()}if(this.kittyProtocolEnabled=!1,this.options.concurrent)Ti.updateContainer(null,this.container,null,Dm);else Ti.updateContainerSync(null,this.container,null,Dm),Ti.flushSyncWork();pl.delete(this.options.stdout);let{exitResult:u}=this,d=()=>{if(qB(e))this.rejectExitPromise(e);else this.resolveExitPromise(u)},p=e!==void 0&&!qB(e),g=o._writableState!==void 0||o.writableLength!==void 0;if(p)d();else if(i&&g)this.options.stdout.write("",d);else setImmediate(d)}async waitUntilExit(){if(this.exitPromise||=new Promise((e,o)=>{this.resolveExitPromise=e,this.rejectExitPromise=o}),!this.beforeExitHandler)this.beforeExitHandler=()=>{this.unmount()},gl.once("beforeExit",this.beforeExitHandler);return this.exitPromise}clear(){if(!zr&&!this.options.debug)this.log.clear(),this.log.sync(this.lastOutputToRender||this.lastOutput+`
|
|
690
690
|
`)}patchConsole(){if(this.options.debug)return;this.restoreConsole=H2((e,o)=>{if(e==="stdout")this.writeToStdout(o);if(e==="stderr"){if(!o.startsWith("The above error occurred"))this.writeToStderr(o)}})}initKittyKeyboard(){if(!this.options.kittyKeyboard)return;let e=this.options.kittyKeyboard,o=e.mode??"auto";if(o==="disabled"||!this.options.stdin.isTTY||!this.options.stdout.isTTY)return;let i=e.flags??["disambiguateEscapeCodes"];if(o==="enabled"){this.enableKittyProtocol(i);return}let a=gl.env.TERM??"",s=gl.env.TERM_PROGRAM??"",u="KITTY_WINDOW_ID"in gl.env||a==="xterm-kitty"||s==="WezTerm"||s==="ghostty";if(!zr&&u)this.confirmKittySupport(i)}confirmKittySupport(e){let{stdin:o,stdout:i}=this.options,a=[],s=()=>{this.cancelKittyDetection=void 0,clearTimeout(d),o.removeListener("data",u);let p=O5(a);if(a=[],p.length>0)o.unshift(Buffer.from(p))},u=(p)=>{let g=typeof p==="string"?Buffer.from(p):p;for(let m of g)a.push(m);if(M5(a)){if(s(),!this.isUnmounted)this.enableKittyProtocol(e)}};o.on("data",u);let d=setTimeout(s,200);this.cancelKittyDetection=s,i.write("\x1B[?u")}enableKittyProtocol(e){this.options.stdout.write(`\x1B[>${YR(e)}u`),this.kittyProtocolEnabled=!0}}var VB,WR,Qm,Dm=()=>{},b5=27,N5=91,R5=63,T5=117,F5=48,k5=57,L5=(e)=>e>=F5&&e<=k5,jR=(e,o)=>{if(e[o]!==b5||e[o+1]!==N5||e[o+2]!==R5)return;let i=o+3,a=i;while(i<e.length&&L5(e[i]))i++;if(i===a)return;if(i===e.length)return{state:"partial"};if(e[i]===T5)return{state:"complete",endIndex:i};return},M5=(e)=>{for(let o=0;o<e.length;o++)if(jR(e,o)?.state==="complete")return!0;return!1},O5=(e)=>{let o=[],i=0;while(i<e.length){let a=jR(e,i);if(a?.state==="complete"){i=a.endIndex+1;continue}if(a?.state==="partial")break;o.push(e[i]),i++}return o},qB=(e)=>e instanceof Error||Object.prototype.toString.call(e)==="[object Error]";var qR=O(async()=>{S2();Sg();hI();P2();UI();Ib();zI();AR();uR();kB();JR();fl();ym();await ha([ys(),$g(),NB(),qg()]);VB=ye(ct(),1),WR=ye(wI(),1),Qm=ye(Rg(),1)});import{Stream as _5}from"stream";import vm from"process";var U5=(e,o)=>{let i={stdout:vm.stdout,stdin:vm.stdin,stderr:vm.stderr,debug:!1,exitOnCtrlC:!0,patchConsole:!0,maxFps:30,incrementalRendering:!1,concurrent:!1,...G5(o)},a=H5(i.stdout,()=>new wm(i),i.concurrent??!1);return a.render(e),{rerender:a.render,unmount(){a.unmount()},waitUntilExit:a.waitUntilExit,cleanup:()=>pl.delete(i.stdout),clear:a.clear}},Sm,G5=(e={})=>{if(e instanceof _5)return{stdout:e,stdin:vm.stdin};return e},H5=(e,o,i)=>{let a=pl.get(e);if(!a)a=o(),pl.set(e,a);else if(a.isConcurrent!==i)console.warn(`Warning: render() was called with concurrent: ${i}, but the existing instance for this stdout uses concurrent: ${a.isConcurrent}. The concurrent option only takes effect on the first render. Call unmount() first if you need to change the rendering mode.`);return a};var VR=O(async()=>{kB();await qR();Sm=U5});var P5;var XR=O(async()=>{await ha([ys(),$g(),NB(),qg()]);P5=ye(Rg(),1)});var xm;var $R=O(()=>{xm=ye(ct(),1)});var ZR;var eT=O(()=>{fl();ZR=ye(ct(),1)});var z5;var tT=O(()=>{z5=ye(ct(),1)});var J5;var nT=O(()=>{Cm();J5=ye(ct(),1)});import{Buffer as K5}from"buffer";function AT(e){if(e===3)return"release";if(e===2)return"repeat";return"press"}function uT(e){return{ctrl:!!(e&Yr.ctrl),shift:!!(e&Yr.shift),meta:!!(e&Yr.meta),option:!!(e&Yr.alt),super:!!(e&Yr.super),hyper:!!(e&Yr.hyper),capsLock:!!(e&Yr.capsLock),numLock:!!(e&Yr.numLock)}}var Y5,W5,iT,rT,j5=(e)=>["[a","[b","[c","[d","[e","[2$","[3$","[5$","[6$","[7$","[8$","[Z"].includes(e),q5=(e)=>["Oa","Ob","Oc","Od","Oe","[2^","[3^","[5^","[6^","[7^","[8^"].includes(e),aT,V5,X5,$5,oT,sT=(e)=>e>=0&&e<=1114111&&!(e>=55296&&e<=57343),XB=(e)=>sT(e)?String.fromCodePoint(e):"?",Z5=(e)=>{let o=aT.exec(e);if(!o)return null;let i=parseInt(o[1],10),a=o[2]?Math.max(0,parseInt(o[2],10)-1):0,s=o[3]?parseInt(o[3],10):1,u=o[4];if(!sT(i))return null;let d;if(u)d=u.split(":").map((m)=>XB(parseInt(m,10))).join("");let p,g;if(i===32)p="space",g=!0;else if(i===13)p="return",g=!0;else if(oT[i])p=oT[i],g=!1;else if(i>=1&&i<=26)p=String.fromCodePoint(i+96),g=!1;else p=XB(i).toLowerCase(),g=!0;if(g&&!d)d=XB(i);return{name:p,...uT(a),eventType:AT(s),sequence:e,raw:e,isKittyProtocol:!0,isPrintable:g,text:d}},eP=(e)=>{let o=V5.exec(e);if(!o)return null;let i=parseInt(o[1],10),a=Math.max(0,parseInt(o[2],10)-1),s=parseInt(o[3],10),u=o[4],d=u==="~"?$5[i]:X5[u];if(!d)return null;return{name:d,...uT(a),eventType:AT(s),sequence:e,raw:e,isKittyProtocol:!0,isPrintable:!1}},tP=(e="")=>{let o;if(K5.isBuffer(e))if(e[0]>127&&e[1]===void 0)e[0]-=128,e="\x1B"+String(e);else e=String(e);else if(e!==void 0&&typeof e!=="string")e=String(e);else if(!e)e="";let i=Z5(e);if(i)return i;let a=eP(e);if(a)return a;if(aT.test(e))return{name:"",ctrl:!1,meta:!1,shift:!1,option:!1,sequence:e,raw:e,isKittyProtocol:!0,isPrintable:!1};let s={name:"",ctrl:!1,meta:!1,shift:!1,option:!1,sequence:e,raw:e};if(s.sequence=s.sequence||e||s.name,e==="\r"||e==="\x1B\r")s.raw=void 0,s.name="return",s.option=e.length===2;else if(e===`
|
|
691
|
-
`)s.name="enter";else if(e==="\t")s.name="tab";else if(e==="\b"||e==="\x1B\b")s.name="backspace",s.meta=e.charAt(0)==="\x1B";else if(e==="\x7F"||e==="\x1B\x7F")s.name="delete",s.meta=e.charAt(0)==="\x1B";else if(e==="\x1B"||e==="\x1B\x1B")s.name="escape",s.meta=e.length===2;else if(e===" "||e==="\x1B ")s.name="space",s.meta=e.length===2;else if(e.length===1&&e<="\x1A")s.name=String.fromCharCode(e.charCodeAt(0)+97-1),s.ctrl=!0;else if(e.length===1&&e>="0"&&e<="9")s.name="number";else if(e.length===1&&e>="a"&&e<="z")s.name=e;else if(e.length===1&&e>="A"&&e<="Z")s.name=e.toLowerCase(),s.shift=!0;else if(o=Y5.exec(e))s.meta=!0,s.shift=/^[A-Z]$/.test(o[1]);else if(o=W5.exec(e)){let u=[...e];if(u[0]==="\x1B"&&u[1]==="\x1B")s.option=!0;let d=[o[1],o[2],o[4],o[6]].filter(Boolean).join(""),p=(o[3]||o[5]||1)-1;s.ctrl=!!(p&4),s.meta=!!(p&10),s.shift=!!(p&1),s.code=d,s.name=iT[d],s.shift=j5(d)||s.shift,s.ctrl=q5(d)||s.ctrl}return s},lT;var cT=O(()=>{ym();Y5=/^(?:\x1b)([a-zA-Z0-9])$/,W5=/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,iT={OP:"f1",OQ:"f2",OR:"f3",OS:"f4","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[A":"up","[B":"down","[C":"right","[D":"left","[E":"clear","[F":"end","[H":"home",OA:"up",OB:"down",OC:"right",OD:"left",OE:"clear",OF:"end",OH:"home","[1~":"home","[2~":"insert","[3~":"delete","[4~":"end","[5~":"pageup","[6~":"pagedown","[[5~":"pageup","[[6~":"pagedown","[7~":"home","[8~":"end","[a":"up","[b":"down","[c":"right","[d":"left","[e":"clear","[2$":"insert","[3$":"delete","[5$":"pageup","[6$":"pagedown","[7$":"home","[8$":"end",Oa:"up",Ob:"down",Oc:"right",Od:"left",Oe:"clear","[2^":"insert","[3^":"delete","[5^":"pageup","[6^":"pagedown","[7^":"home","[8^":"end","[Z":"tab"},rT=[...Object.values(iT),"backspace"],aT=/^\x1b\[(\d+)(?:;(\d+)(?::(\d+))?(?:;([\d:]+))?)?u$/,V5=/^\x1b\[(\d+);(\d+):(\d+)([A-Za-z~])$/,X5={A:"up",B:"down",C:"right",D:"left",E:"clear",F:"end",H:"home",P:"f1",Q:"f2",R:"f3",S:"f4"},$5={2:"insert",3:"delete",5:"pageup",6:"pagedown",7:"home",8:"end",11:"f1",12:"f2",13:"f3",14:"f4",15:"f5",17:"f6",18:"f7",19:"f8",20:"f9",21:"f10",23:"f11",24:"f12"},oT={27:"escape",9:"tab",127:"delete",8:"backspace",57358:"capslock",57359:"scrolllock",57360:"numlock",57361:"printscreen",57362:"pause",57363:"menu",57376:"f13",57377:"f14",57378:"f15",57379:"f16",57380:"f17",57381:"f18",57382:"f19",57383:"f20",57384:"f21",57385:"f22",57386:"f23",57387:"f24",57388:"f25",57389:"f26",57390:"f27",57391:"f28",57392:"f29",57393:"f30",57394:"f31",57395:"f32",57396:"f33",57397:"f34",57398:"f35",57399:"kp0",57400:"kp1",57401:"kp2",57402:"kp3",57403:"kp4",57404:"kp5",57405:"kp6",57406:"kp7",57407:"kp8",57408:"kp9",57409:"kpdecimal",57410:"kpdivide",57411:"kpmultiply",57412:"kpsubtract",57413:"kpadd",57414:"kpenter",57415:"kpequal",57416:"kpseparator",57417:"kpleft",57418:"kpright",57419:"kpup",57420:"kpdown",57421:"kppageup",57422:"kppagedown",57423:"kphome",57424:"kpend",57425:"kpinsert",57426:"kpdelete",57427:"kpbegin",57428:"mediaplay",57429:"mediapause",57430:"mediaplaypause",57431:"mediareverse",57432:"mediastop",57433:"mediafastforward",57434:"mediarewind",57435:"mediatracknext",57436:"mediatrackprevious",57437:"mediarecord",57438:"lowervolume",57439:"raisevolume",57440:"mutevolume",57441:"leftshift",57442:"leftcontrol",57443:"leftalt",57444:"leftsuper",57445:"lefthyper",57446:"leftmeta",57447:"rightshift",57448:"rightcontrol",57449:"rightalt",57450:"rightsuper",57451:"righthyper",57452:"rightmeta",57453:"isoLevel3Shift",57454:"isoLevel5Shift"};lT=tP});var dT,nP=()=>dT.useContext(pm),ml;var bm=O(()=>{OB();dT=ye(ct(),1),ml=nP});var $B,oP=(e,o={})=>{let{stdin:i,setRawMode:a,internal_exitOnCtrlC:s,internal_eventEmitter:u}=ml();$B.useEffect(()=>{if(o.isActive===!1)return;return a(!0),()=>{a(!1)}},[o.isActive,a]),$B.useEffect(()=>{if(o.isActive===!1)return;let d=(p)=>{let g=lT(p),m={upArrow:g.name==="up",downArrow:g.name==="down",leftArrow:g.name==="left",rightArrow:g.name==="right",pageDown:g.name==="pagedown",pageUp:g.name==="pageup",home:g.name==="home",end:g.name==="end",return:g.name==="return",escape:g.name==="escape",ctrl:g.ctrl,shift:g.shift,tab:g.name==="tab",backspace:g.name==="backspace",delete:g.name==="delete",meta:g.meta||g.name==="escape"||g.option,super:g.super??!1,hyper:g.hyper??!1,capsLock:g.capsLock??!1,numLock:g.numLock??!1,eventType:g.eventType},h;if(g.isKittyProtocol)if(g.isPrintable)h=g.text??g.name;else if(g.ctrl&&g.name.length===1)h=g.name;else h="";else if(g.ctrl)h=g.name;else h=g.sequence;if(!g.isKittyProtocol&&rT.includes(g.name))h="";if(h.startsWith("\x1B"))h=h.slice(1);if(h.length===1&&typeof h[0]==="string"&&/[A-Z]/.test(h[0]))m.shift=!0;if(!(h==="c"&&m.ctrl)||!s)Ti.batchedUpdates(()=>{e(h,m)})};return u?.on("input",d),()=>{u?.removeListener("input",d)}},[o.isActive,i,s,e])},Yn;var pT=O(async()=>{cT();bm();await $g();$B=ye(ct(),1),Yn=oP});var iP;var fT=O(()=>{MB();iP=ye(ct(),1)});var gT,rP=()=>gT.useContext(fm),El;var mT=O(()=>{_B();gT=ye(ct(),1),El=rP});var aP;var ET=O(()=>{GB();aP=ye(ct(),1)});var ZB;var CT=O(()=>{mm();bm();ZB=ye(ct(),1)});var sP;var hT=O(()=>{mm();sP=ye(ct(),1)});var AP;var IT=O(()=>{fl();AP=ye(ct(),1)});var Nm;var BT=O(()=>{PB();Nm=ye(ct(),1)});var yT=()=>{};var Vo=O(async()=>{Cm();KB();$R();eT();tT();nT();fT();bm();mT();ET();CT();hT();IT();BT();yT();ym();await ha([VR(),XR(),pT()])});function DT(e,o){let i=[],a=new Set;for(let s of e){if(!s.group){i.push({kind:"flag",opt:s});continue}if(!a.has(s.group))a.add(s.group),i.push({kind:"group",group:s.group,title:s.group==="model"?o?"\u6A21\u578B":"Model":s.group})}return i.push({kind:"provider",title:o?"\u670D\u52A1\u5546":"Provider"}),i}function kd(e,o,i){return e.find((a)=>a.group===i&&o.has(a.id))}function Rm(e){let o=[],i={},a=[];for(let s of e.launchOptions){if(!e.enabled.has(s.id))continue;if(o.push(...s.args),s.envVars)Object.assign(i,s.envVars);a.push(s.id)}return{args:o,envVars:i,selectedOptionIds:a}}function QT(e,o,i){if(!i)return Rm(e);let a=new Set(e.enabled);for(let s of e.launchOptions)if(s.group===o)a.delete(s.id);return a.add(i),Rm({launchOptions:e.launchOptions,enabled:a})}function Tm(e,o,i,a){let s=new Set(o.map((Q)=>Q.id)),u=o.filter((Q)=>Q.group==="model"),d=new Set(u.map((Q)=>Q.id)),p=[i?`model-${i}`:void 0,a,u[0]?.id].filter((Q)=>!!Q&&d.has(Q)),g=new Set,m=!1,h=!1;for(let Q of e)if(s.has(Q)){if(g.add(Q),d.has(Q))h=!0}else m=!0;if(!h&&p[0])g.add(p[0]),m=!0;return m?g:e}function uP(e,o,i="pi"){if(o==="pi-web")o="pi";if(o){let s=e.indexOf(o);if(s>=0)return s}let a=e.indexOf(i);return a>=0?a:0}async function wT(e=45){let o=lA(),i=await Fx(),a=await pi(),s=ao()==="zh",u=[];for(let p of o){let g=await Tx(p.id,Qh,!0),m=process.cwd(),h=[{label:s?"\u5728\u5F53\u524D\u76EE\u5F55\u542F\u52A8":"Launch in current directory",hint:vh(m,e),path:m},...g.map((ne)=>({label:vh(ne.path,e),hint:kx(ne.lastLaunchedAt),path:ne.path}))],Q=await Da(p.id),w=await Qa(p.id)||Q.find((ne)=>ne.id===a?.id)||Q[0],N=w?Q.findIndex((ne)=>ne.id===w.id):0,v=bu(p,w),S=new Set(v.map((ne)=>ne.id)),L=await Pf(p.id),q=[...Tm(new Set(L.filter((ne)=>S.has(ne))),v,w?.model,p.id==="pi"?`model-${IA}`:void 0)];u.push({client:p,projects:h,providers:Q,activeProvider:w,activeProvIdx:Math.max(N,0),launchOptions:v,lastSelectedOptionIds:q})}let d={};try{d=await Jx()}catch{d={}}return{clients:u,defaultIdx:uP(u.map((p)=>p.client.id),i),hasProviders:u.some((p)=>p.providers.length>0),pickCounts:d,zh:s}}var vT=O(()=>{Uc();zn();_c();Mn();Rh();zf();bi()});function ST(e){let o=e.codePointAt(0);if(!o)return!1;return o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=191471||o>=63744&&o<=64255||o>=194560&&o<=195103||o>=44032&&o<=55215||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=65280&&o<=65519||o>=126976&&o<=131071||o>=9728&&o<=10175||o===11088}function lP(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function UA(e){let o=lP(e),i=0;for(let a of o)i+=ST(a)?2:1;return i}function xT(e,o,i="left"){let a=UA(e),s=Math.max(0,o-a);if(s===0)return e;switch(i){case"left":return e+" ".repeat(s);case"right":return" ".repeat(s)+e;case"center":{let u=Math.floor(s/2),d=s-u;return" ".repeat(u)+e+" ".repeat(d)}}}function Fm(e,o,i="..."){if(UA(e)<=o)return e;let s=UA(i),u=o-s;if(u<=0)return i.slice(0,o);let d=0,p="";for(let g of e){let m=ST(g)?2:1;if(d+m>u)break;p+=g,d+=m}return p+i}function Cl(e,o,i){if(!e.some((h)=>(i[h.id]??0)>0))return{list:e,hiddenCount:0};let s=new Map(e.map((h,Q)=>[h.id,Q])),u=e.filter((h)=>(i[h.id]??0)>0).sort((h,Q)=>{let C=(i[Q.id]??0)-(i[h.id]??0);if(C!==0)return C;return(s.get(h.id)??0)-(s.get(Q.id)??0)}).slice(0,RT).map((h)=>h.id),d=new Set(u);for(let h of e)if(o.has(h.id))d.add(h.id);let p=new Map(u.map((h,Q)=>[h,Q])),g=u.length;for(let h of e)if(d.has(h.id)&&!p.has(h.id))p.set(h.id,g++);let m=e.filter((h)=>d.has(h.id)).sort((h,Q)=>{let C=(p.get(h.id)??Number.MAX_SAFE_INTEGER)-(p.get(Q.id)??Number.MAX_SAFE_INTEGER);if(C!==0)return C;return(s.get(h.id)??0)-(s.get(Q.id)??0)});return{list:m,hiddenCount:e.length-m.length}}function ny(e,o){return!e.some((a)=>(o[a.id]??0)>0)&&e.length>RT?"grid":"collapsed"}function dP(e,o){if(e.length===0)return 1;let i=Math.max(...e.map((u)=>UA(u))),a=Math.max(ty,i+4),s=Math.max(a,o-cP);return Math.max(1,Math.min(TT,e.length,Math.floor(s/a)))}function hl(e,o,i){let a=e.map((s)=>s.label[i?"zh":"en"]||s.label.en||s.id);return dP(a,o)}function pP(e,o){let i=Math.max(1,Math.min(TT,Math.floor(o)||1)),a=[];for(let s=0;s<e.length;s+=i)a.push(e.slice(s,s+i));return{rows:a,flat:a.flat()}}function km(e){return e.startsWith("model-")?e.slice(6):e}function ey(e){let o=km(e).toLowerCase();return o.replace(/^(?:full[-_]|\u6EE1\u8840[-_])+/u,"").slice(0,3)||o.slice(0,3)||o}function bT(e){let o=["gpt","ful","cla","dee","glm","kim","qwe","min","mim","spa"],i=o.indexOf(e);return i===-1?o.length:i}function NT(e){let o=km(e).toLowerCase(),i=[];for(let a of o.match(/\d+(?:\.\d+)?|[a-z]+/g)??[o]){let s=Number(a);i.push(Number.isFinite(s)&&/^\d/.test(a)?s:a)}return i}function fP(e,o){let i=ey(e),a=ey(o),s=bT(i)-bT(a)||i.localeCompare(a);if(s!==0)return s;let u=NT(e),d=NT(o),p=Math.max(u.length,d.length);for(let g=0;g<p;g++){let m=u[g],h=d[g];if(m===void 0)return 1;if(h===void 0)return-1;if(typeof m==="number"&&typeof h==="number"){if(m!==h)return h-m;continue}let Q=String(m),C=String(h);if(Q!==C)return Q.localeCompare(C)}return km(e).localeCompare(km(o))}function Il(e,o){let i=[...e].sort(fP),a=[];for(let u of i){let d=ey(u),p=a[a.length-1];if(p?.family===d)p.ids.push(u);else a.push({family:d,ids:[u]})}let s=a.map((u)=>({family:u.family,rows:pP(u.ids,o).rows}));return{groups:s,flat:s.flatMap((u)=>u.rows.flat())}}function oy(e,o,i){return Il(e,i).flat.indexOf(o)}function FT(e,o){return Il(e,o).groups.flatMap((i)=>i.rows)}var RT=6,TT=4,ty=16,cP=12;var Lm=()=>{};var $t=ui(function(gP){var GA=ye(ct());(function(){function e(V){if(V==null)return null;if(typeof V==="function")return V.$$typeof===Be?null:V.displayName||V.name||null;if(typeof V==="string")return V;switch(V){case v:return"Fragment";case L:return"Profiler";case S:return"StrictMode";case le:return"Suspense";case pe:return"SuspenseList";case ie:return"Activity"}if(typeof V==="object")switch(typeof V.tag==="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),V.$$typeof){case N:return"Portal";case ne:return V.displayName||"Context";case q:return(V._context.displayName||"Context")+".Consumer";case se:var Oe=V.render;return V=V.displayName,V||(V=Oe.displayName||Oe.name||"",V=V!==""?"ForwardRef("+V+")":"ForwardRef"),V;case Qe:return Oe=V.displayName||null,Oe!==null?Oe:e(V.type)||"Memo";case Ee:Oe=V._payload,V=V._init;try{return e(V(Oe))}catch(Pe){}}return null}function o(V){return""+V}function i(V){try{o(V);var Oe=!1}catch(wt){Oe=!0}if(Oe){Oe=console;var Pe=Oe.error,je=typeof Symbol==="function"&&Symbol.toStringTag&&V[Symbol.toStringTag]||V.constructor.name||"Object";return Pe.call(Oe,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",je),o(V)}}function a(V){if(V===v)return"<>";if(typeof V==="object"&&V!==null&&V.$$typeof===Ee)return"<...>";try{var Oe=e(V);return Oe?"<"+Oe+">":"<...>"}catch(Pe){return"<...>"}}function s(){var V=we.A;return V===null?null:V.getOwner()}function u(){return Error("react-stack-top-frame")}function d(V){if(De.call(V,"key")){var Oe=Object.getOwnPropertyDescriptor(V,"key").get;if(Oe&&Oe.isReactWarning)return!1}return V.key!==void 0}function p(V,Oe){function Pe(){ce||(ce=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",Oe))}Pe.isReactWarning=!0,Object.defineProperty(V,"key",{get:Pe,configurable:!0})}function g(){var V=e(this.type);return Ne[V]||(Ne[V]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),V=this.props.ref,V!==void 0?V:null}function m(V,Oe,Pe,je,wt,zt){var vt=Pe.ref;return V={$$typeof:w,type:V,key:Oe,props:Pe,_owner:je},(vt!==void 0?vt:null)!==null?Object.defineProperty(V,"ref",{enumerable:!1,get:g}):Object.defineProperty(V,"ref",{enumerable:!1,value:null}),V._store={},Object.defineProperty(V._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(V,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(V,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:wt}),Object.defineProperty(V,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:zt}),Object.freeze&&(Object.freeze(V.props),Object.freeze(V)),V}function h(V,Oe,Pe,je,wt,zt){var vt=Oe.children;if(vt!==void 0)if(je)if(Ie(vt)){for(je=0;je<vt.length;je++)Q(vt[je]);Object.freeze&&Object.freeze(vt)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Q(vt);if(De.call(Oe,"key")){vt=e(V);var Zt=Object.keys(Oe).filter(function(ae){return ae!=="key"});je=0<Zt.length?"{key: someKey, "+Zt.join(": ..., ")+": ...}":"{key: someKey}",He[vt+je]||(Zt=0<Zt.length?"{"+Zt.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
691
|
+
`)s.name="enter";else if(e==="\t")s.name="tab";else if(e==="\b"||e==="\x1B\b")s.name="backspace",s.meta=e.charAt(0)==="\x1B";else if(e==="\x7F"||e==="\x1B\x7F")s.name="delete",s.meta=e.charAt(0)==="\x1B";else if(e==="\x1B"||e==="\x1B\x1B")s.name="escape",s.meta=e.length===2;else if(e===" "||e==="\x1B ")s.name="space",s.meta=e.length===2;else if(e.length===1&&e<="\x1A")s.name=String.fromCharCode(e.charCodeAt(0)+97-1),s.ctrl=!0;else if(e.length===1&&e>="0"&&e<="9")s.name="number";else if(e.length===1&&e>="a"&&e<="z")s.name=e;else if(e.length===1&&e>="A"&&e<="Z")s.name=e.toLowerCase(),s.shift=!0;else if(o=Y5.exec(e))s.meta=!0,s.shift=/^[A-Z]$/.test(o[1]);else if(o=W5.exec(e)){let u=[...e];if(u[0]==="\x1B"&&u[1]==="\x1B")s.option=!0;let d=[o[1],o[2],o[4],o[6]].filter(Boolean).join(""),p=(o[3]||o[5]||1)-1;s.ctrl=!!(p&4),s.meta=!!(p&10),s.shift=!!(p&1),s.code=d,s.name=iT[d],s.shift=j5(d)||s.shift,s.ctrl=q5(d)||s.ctrl}return s},lT;var cT=O(()=>{ym();Y5=/^(?:\x1b)([a-zA-Z0-9])$/,W5=/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,iT={OP:"f1",OQ:"f2",OR:"f3",OS:"f4","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[A":"up","[B":"down","[C":"right","[D":"left","[E":"clear","[F":"end","[H":"home",OA:"up",OB:"down",OC:"right",OD:"left",OE:"clear",OF:"end",OH:"home","[1~":"home","[2~":"insert","[3~":"delete","[4~":"end","[5~":"pageup","[6~":"pagedown","[[5~":"pageup","[[6~":"pagedown","[7~":"home","[8~":"end","[a":"up","[b":"down","[c":"right","[d":"left","[e":"clear","[2$":"insert","[3$":"delete","[5$":"pageup","[6$":"pagedown","[7$":"home","[8$":"end",Oa:"up",Ob:"down",Oc:"right",Od:"left",Oe:"clear","[2^":"insert","[3^":"delete","[5^":"pageup","[6^":"pagedown","[7^":"home","[8^":"end","[Z":"tab"},rT=[...Object.values(iT),"backspace"],aT=/^\x1b\[(\d+)(?:;(\d+)(?::(\d+))?(?:;([\d:]+))?)?u$/,V5=/^\x1b\[(\d+);(\d+):(\d+)([A-Za-z~])$/,X5={A:"up",B:"down",C:"right",D:"left",E:"clear",F:"end",H:"home",P:"f1",Q:"f2",R:"f3",S:"f4"},$5={2:"insert",3:"delete",5:"pageup",6:"pagedown",7:"home",8:"end",11:"f1",12:"f2",13:"f3",14:"f4",15:"f5",17:"f6",18:"f7",19:"f8",20:"f9",21:"f10",23:"f11",24:"f12"},oT={27:"escape",9:"tab",127:"delete",8:"backspace",57358:"capslock",57359:"scrolllock",57360:"numlock",57361:"printscreen",57362:"pause",57363:"menu",57376:"f13",57377:"f14",57378:"f15",57379:"f16",57380:"f17",57381:"f18",57382:"f19",57383:"f20",57384:"f21",57385:"f22",57386:"f23",57387:"f24",57388:"f25",57389:"f26",57390:"f27",57391:"f28",57392:"f29",57393:"f30",57394:"f31",57395:"f32",57396:"f33",57397:"f34",57398:"f35",57399:"kp0",57400:"kp1",57401:"kp2",57402:"kp3",57403:"kp4",57404:"kp5",57405:"kp6",57406:"kp7",57407:"kp8",57408:"kp9",57409:"kpdecimal",57410:"kpdivide",57411:"kpmultiply",57412:"kpsubtract",57413:"kpadd",57414:"kpenter",57415:"kpequal",57416:"kpseparator",57417:"kpleft",57418:"kpright",57419:"kpup",57420:"kpdown",57421:"kppageup",57422:"kppagedown",57423:"kphome",57424:"kpend",57425:"kpinsert",57426:"kpdelete",57427:"kpbegin",57428:"mediaplay",57429:"mediapause",57430:"mediaplaypause",57431:"mediareverse",57432:"mediastop",57433:"mediafastforward",57434:"mediarewind",57435:"mediatracknext",57436:"mediatrackprevious",57437:"mediarecord",57438:"lowervolume",57439:"raisevolume",57440:"mutevolume",57441:"leftshift",57442:"leftcontrol",57443:"leftalt",57444:"leftsuper",57445:"lefthyper",57446:"leftmeta",57447:"rightshift",57448:"rightcontrol",57449:"rightalt",57450:"rightsuper",57451:"righthyper",57452:"rightmeta",57453:"isoLevel3Shift",57454:"isoLevel5Shift"};lT=tP});var dT,nP=()=>dT.useContext(pm),ml;var bm=O(()=>{OB();dT=ye(ct(),1),ml=nP});var $B,oP=(e,o={})=>{let{stdin:i,setRawMode:a,internal_exitOnCtrlC:s,internal_eventEmitter:u}=ml();$B.useEffect(()=>{if(o.isActive===!1)return;return a(!0),()=>{a(!1)}},[o.isActive,a]),$B.useEffect(()=>{if(o.isActive===!1)return;let d=(p)=>{let g=lT(p),m={upArrow:g.name==="up",downArrow:g.name==="down",leftArrow:g.name==="left",rightArrow:g.name==="right",pageDown:g.name==="pagedown",pageUp:g.name==="pageup",home:g.name==="home",end:g.name==="end",return:g.name==="return",escape:g.name==="escape",ctrl:g.ctrl,shift:g.shift,tab:g.name==="tab",backspace:g.name==="backspace",delete:g.name==="delete",meta:g.meta||g.name==="escape"||g.option,super:g.super??!1,hyper:g.hyper??!1,capsLock:g.capsLock??!1,numLock:g.numLock??!1,eventType:g.eventType},h;if(g.isKittyProtocol)if(g.isPrintable)h=g.text??g.name;else if(g.ctrl&&g.name.length===1)h=g.name;else h="";else if(g.ctrl)h=g.name;else h=g.sequence;if(!g.isKittyProtocol&&rT.includes(g.name))h="";if(h.startsWith("\x1B"))h=h.slice(1);if(h.length===1&&typeof h[0]==="string"&&/[A-Z]/.test(h[0]))m.shift=!0;if(!(h==="c"&&m.ctrl)||!s)Ti.batchedUpdates(()=>{e(h,m)})};return u?.on("input",d),()=>{u?.removeListener("input",d)}},[o.isActive,i,s,e])},Yn;var pT=O(async()=>{cT();bm();await $g();$B=ye(ct(),1),Yn=oP});var iP;var fT=O(()=>{MB();iP=ye(ct(),1)});var gT,rP=()=>gT.useContext(fm),El;var mT=O(()=>{_B();gT=ye(ct(),1),El=rP});var aP;var ET=O(()=>{GB();aP=ye(ct(),1)});var ZB;var CT=O(()=>{mm();bm();ZB=ye(ct(),1)});var sP;var hT=O(()=>{mm();sP=ye(ct(),1)});var AP;var IT=O(()=>{fl();AP=ye(ct(),1)});var Nm;var BT=O(()=>{PB();Nm=ye(ct(),1)});var yT=()=>{};var Vo=O(async()=>{Cm();KB();$R();eT();tT();nT();fT();bm();mT();ET();CT();hT();IT();BT();yT();ym();await ha([VR(),XR(),pT()])});function DT(e,o){let i=[],a=new Set;for(let s of e){if(!s.group){i.push({kind:"flag",opt:s});continue}if(!a.has(s.group))a.add(s.group),i.push({kind:"group",group:s.group,title:s.group==="model"?o?"\u6A21\u578B":"Model":s.group})}return i.push({kind:"provider",title:o?"\u670D\u52A1\u5546":"Provider"}),i}function kd(e,o,i){return e.find((a)=>a.group===i&&o.has(a.id))}function Rm(e){let o=[],i={},a=[];for(let s of e.launchOptions){if(!e.enabled.has(s.id))continue;if(o.push(...s.args),s.envVars)Object.assign(i,s.envVars);a.push(s.id)}return{args:o,envVars:i,selectedOptionIds:a}}function QT(e,o,i){if(!i)return Rm(e);let a=new Set(e.enabled);for(let s of e.launchOptions)if(s.group===o)a.delete(s.id);return a.add(i),Rm({launchOptions:e.launchOptions,enabled:a})}function Tm(e,o,i,a){let s=new Set(o.map((h)=>h.id)),u=new Set(o.filter((h)=>h.group==="model").map((h)=>h.id)),d=[i?`model-${i}`:void 0,a].filter((h)=>!!h&&u.has(h)),p=new Set,g=!1,m=!1;for(let h of e)if(s.has(h)){if(p.add(h),u.has(h))m=!0}else g=!0;if(!m&&d[0])p.add(d[0]),g=!0;return g?p:e}function uP(e,o,i="pi"){if(o==="pi-web")o="pi";if(o){let s=e.indexOf(o);if(s>=0)return s}let a=e.indexOf(i);return a>=0?a:0}async function wT(e=45){let o=lA(),i=await Fx(),a=await pi(),s=ao()==="zh",u=[];for(let p of o){let g=await Tx(p.id,Qh,!0),m=process.cwd(),h=[{label:s?"\u5728\u5F53\u524D\u76EE\u5F55\u542F\u52A8":"Launch in current directory",hint:vh(m,e),path:m},...g.map((ne)=>({label:vh(ne.path,e),hint:kx(ne.lastLaunchedAt),path:ne.path}))],Q=await Da(p.id),w=await Qa(p.id)||Q.find((ne)=>ne.id===a?.id)||Q[0],N=w?Q.findIndex((ne)=>ne.id===w.id):0,v=bu(p,w),S=new Set(v.map((ne)=>ne.id)),L=await Pf(p.id),q=[...Tm(new Set(L.filter((ne)=>S.has(ne))),v,w?.model,p.id==="pi"?`model-${IA}`:void 0)];u.push({client:p,projects:h,providers:Q,activeProvider:w,activeProvIdx:Math.max(N,0),launchOptions:v,lastSelectedOptionIds:q})}let d={};try{d=await Jx()}catch{d={}}return{clients:u,defaultIdx:uP(u.map((p)=>p.client.id),i),hasProviders:u.some((p)=>p.providers.length>0),pickCounts:d,zh:s}}var vT=O(()=>{Uc();zn();_c();Mn();Rh();zf();bi()});function ST(e){let o=e.codePointAt(0);if(!o)return!1;return o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=191471||o>=63744&&o<=64255||o>=194560&&o<=195103||o>=44032&&o<=55215||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=65280&&o<=65519||o>=126976&&o<=131071||o>=9728&&o<=10175||o===11088}function lP(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function UA(e){let o=lP(e),i=0;for(let a of o)i+=ST(a)?2:1;return i}function xT(e,o,i="left"){let a=UA(e),s=Math.max(0,o-a);if(s===0)return e;switch(i){case"left":return e+" ".repeat(s);case"right":return" ".repeat(s)+e;case"center":{let u=Math.floor(s/2),d=s-u;return" ".repeat(u)+e+" ".repeat(d)}}}function Fm(e,o,i="..."){if(UA(e)<=o)return e;let s=UA(i),u=o-s;if(u<=0)return i.slice(0,o);let d=0,p="";for(let g of e){let m=ST(g)?2:1;if(d+m>u)break;p+=g,d+=m}return p+i}function Cl(e,o,i){if(!e.some((h)=>(i[h.id]??0)>0))return{list:e,hiddenCount:0};let s=new Map(e.map((h,Q)=>[h.id,Q])),u=e.filter((h)=>(i[h.id]??0)>0).sort((h,Q)=>{let C=(i[Q.id]??0)-(i[h.id]??0);if(C!==0)return C;return(s.get(h.id)??0)-(s.get(Q.id)??0)}).slice(0,RT).map((h)=>h.id),d=new Set(u);for(let h of e)if(o.has(h.id))d.add(h.id);let p=new Map(u.map((h,Q)=>[h,Q])),g=u.length;for(let h of e)if(d.has(h.id)&&!p.has(h.id))p.set(h.id,g++);let m=e.filter((h)=>d.has(h.id)).sort((h,Q)=>{let C=(p.get(h.id)??Number.MAX_SAFE_INTEGER)-(p.get(Q.id)??Number.MAX_SAFE_INTEGER);if(C!==0)return C;return(s.get(h.id)??0)-(s.get(Q.id)??0)});return{list:m,hiddenCount:e.length-m.length}}function ny(e,o){return!e.some((a)=>(o[a.id]??0)>0)&&e.length>RT?"grid":"collapsed"}function dP(e,o){if(e.length===0)return 1;let i=Math.max(...e.map((u)=>UA(u))),a=Math.max(ty,i+4),s=Math.max(a,o-cP);return Math.max(1,Math.min(TT,e.length,Math.floor(s/a)))}function hl(e,o,i){let a=e.map((s)=>s.label[i?"zh":"en"]||s.label.en||s.id);return dP(a,o)}function pP(e,o){let i=Math.max(1,Math.min(TT,Math.floor(o)||1)),a=[];for(let s=0;s<e.length;s+=i)a.push(e.slice(s,s+i));return{rows:a,flat:a.flat()}}function km(e){return e.startsWith("model-")?e.slice(6):e}function ey(e){let o=km(e).toLowerCase();return o.replace(/^(?:full[-_]|\u6EE1\u8840[-_])+/u,"").slice(0,3)||o.slice(0,3)||o}function bT(e){let o=["gpt","ful","cla","dee","glm","kim","qwe","min","mim","spa"],i=o.indexOf(e);return i===-1?o.length:i}function NT(e){let o=km(e).toLowerCase(),i=[];for(let a of o.match(/\d+(?:\.\d+)?|[a-z]+/g)??[o]){let s=Number(a);i.push(Number.isFinite(s)&&/^\d/.test(a)?s:a)}return i}function fP(e,o){let i=ey(e),a=ey(o),s=bT(i)-bT(a)||i.localeCompare(a);if(s!==0)return s;let u=NT(e),d=NT(o),p=Math.max(u.length,d.length);for(let g=0;g<p;g++){let m=u[g],h=d[g];if(m===void 0)return 1;if(h===void 0)return-1;if(typeof m==="number"&&typeof h==="number"){if(m!==h)return h-m;continue}let Q=String(m),C=String(h);if(Q!==C)return Q.localeCompare(C)}return km(e).localeCompare(km(o))}function Il(e,o){let i=[...e].sort(fP),a=[];for(let u of i){let d=ey(u),p=a[a.length-1];if(p?.family===d)p.ids.push(u);else a.push({family:d,ids:[u]})}let s=a.map((u)=>({family:u.family,rows:pP(u.ids,o).rows}));return{groups:s,flat:s.flatMap((u)=>u.rows.flat())}}function oy(e,o,i){return Il(e,i).flat.indexOf(o)}function FT(e,o){return Il(e,o).groups.flatMap((i)=>i.rows)}var RT=6,TT=4,ty=16,cP=12;var Lm=()=>{};var $t=ui(function(gP){var GA=ye(ct());(function(){function e(V){if(V==null)return null;if(typeof V==="function")return V.$$typeof===Be?null:V.displayName||V.name||null;if(typeof V==="string")return V;switch(V){case v:return"Fragment";case L:return"Profiler";case S:return"StrictMode";case le:return"Suspense";case pe:return"SuspenseList";case ie:return"Activity"}if(typeof V==="object")switch(typeof V.tag==="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),V.$$typeof){case N:return"Portal";case ne:return V.displayName||"Context";case q:return(V._context.displayName||"Context")+".Consumer";case se:var Oe=V.render;return V=V.displayName,V||(V=Oe.displayName||Oe.name||"",V=V!==""?"ForwardRef("+V+")":"ForwardRef"),V;case Qe:return Oe=V.displayName||null,Oe!==null?Oe:e(V.type)||"Memo";case Ee:Oe=V._payload,V=V._init;try{return e(V(Oe))}catch(Pe){}}return null}function o(V){return""+V}function i(V){try{o(V);var Oe=!1}catch(wt){Oe=!0}if(Oe){Oe=console;var Pe=Oe.error,je=typeof Symbol==="function"&&Symbol.toStringTag&&V[Symbol.toStringTag]||V.constructor.name||"Object";return Pe.call(Oe,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",je),o(V)}}function a(V){if(V===v)return"<>";if(typeof V==="object"&&V!==null&&V.$$typeof===Ee)return"<...>";try{var Oe=e(V);return Oe?"<"+Oe+">":"<...>"}catch(Pe){return"<...>"}}function s(){var V=we.A;return V===null?null:V.getOwner()}function u(){return Error("react-stack-top-frame")}function d(V){if(De.call(V,"key")){var Oe=Object.getOwnPropertyDescriptor(V,"key").get;if(Oe&&Oe.isReactWarning)return!1}return V.key!==void 0}function p(V,Oe){function Pe(){ce||(ce=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",Oe))}Pe.isReactWarning=!0,Object.defineProperty(V,"key",{get:Pe,configurable:!0})}function g(){var V=e(this.type);return Ne[V]||(Ne[V]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),V=this.props.ref,V!==void 0?V:null}function m(V,Oe,Pe,je,wt,zt){var vt=Pe.ref;return V={$$typeof:w,type:V,key:Oe,props:Pe,_owner:je},(vt!==void 0?vt:null)!==null?Object.defineProperty(V,"ref",{enumerable:!1,get:g}):Object.defineProperty(V,"ref",{enumerable:!1,value:null}),V._store={},Object.defineProperty(V._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(V,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(V,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:wt}),Object.defineProperty(V,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:zt}),Object.freeze&&(Object.freeze(V.props),Object.freeze(V)),V}function h(V,Oe,Pe,je,wt,zt){var vt=Oe.children;if(vt!==void 0)if(je)if(Ie(vt)){for(je=0;je<vt.length;je++)Q(vt[je]);Object.freeze&&Object.freeze(vt)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Q(vt);if(De.call(Oe,"key")){vt=e(V);var Zt=Object.keys(Oe).filter(function(ae){return ae!=="key"});je=0<Zt.length?"{key: someKey, "+Zt.join(": ..., ")+": ...}":"{key: someKey}",He[vt+je]||(Zt=0<Zt.length?"{"+Zt.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
692
692
|
let props = %s;
|
|
693
693
|
<%s {...props} />
|
|
694
694
|
React keys must be passed directly to JSX without using spread:
|
|
695
695
|
let props = %s;
|
|
696
|
-
<%s key={someKey} {...props} />`,je,vt,Zt,vt),He[vt+je]=!0)}if(vt=null,Pe!==void 0&&(i(Pe),vt=""+Pe),d(Oe)&&(i(Oe.key),vt=""+Oe.key),"key"in Oe){Pe={};for(var Mt in Oe)Mt!=="key"&&(Pe[Mt]=Oe[Mt])}else Pe=Oe;return vt&&p(Pe,typeof V==="function"?V.displayName||V.name||"Unknown":V),m(V,vt,Pe,s(),wt,zt)}function Q(V){C(V)?V._store&&(V._store.validated=1):typeof V==="object"&&V!==null&&V.$$typeof===Ee&&(V._payload.status==="fulfilled"?C(V._payload.value)&&V._payload.value._store&&(V._payload.value._store.validated=1):V._store&&(V._store.validated=1))}function C(V){return typeof V==="object"&&V!==null&&V.$$typeof===w}var w=Symbol.for("react.transitional.element"),N=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),q=Symbol.for("react.consumer"),ne=Symbol.for("react.context"),se=Symbol.for("react.forward_ref"),le=Symbol.for("react.suspense"),pe=Symbol.for("react.suspense_list"),Qe=Symbol.for("react.memo"),Ee=Symbol.for("react.lazy"),ie=Symbol.for("react.activity"),Be=Symbol.for("react.client.reference"),we=GA.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,De=Object.prototype.hasOwnProperty,Ie=Array.isArray,Dt=console.createTask?console.createTask:function(){return null};GA={react_stack_bottom_frame:function(V){return V()}};var ce,Ne={},ve=GA.react_stack_bottom_frame.bind(GA,u)(),We=Dt(a(u)),He={};gP.Fragment=v,gP.jsxDEV=function(V,Oe,Pe,je){var wt=1e4>we.recentlyCreatedOwnerStacks++;return h(V,Oe,Pe,je,wt?Error("react-stack-top-frame"):ve,wt?Dt(a(V)):We)}})()});function kT({zh:e}){return mt.jsxDEV(G,{marginTop:0,justifyContent:"center",gap:2,children:mP.flatMap((o,i)=>[i>0?mt.jsxDEV(I,{dimColor:!0,children:"\u2502"},`s${i}`,!1,void 0,this):null,mt.jsxDEV(I,{dimColor:!0,bold:!0,children:o[0]},`k${i}`,!1,void 0,this),mt.jsxDEV(I,{dimColor:!0,children:e?o[1]:o[2]},`l${i}`,!1,void 0,this)])},void 0,!1,void 0,this)}function LT({provs:e,provIdx:o,pickerIdx:i,color:a,zh:s}){return mt.jsxDEV(G,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:a,paddingX:1,paddingY:0,children:[mt.jsxDEV(I,{bold:!0,color:a,children:["\u25A3 ",s?"\u9009\u62E9\u670D\u52A1\u5546":"Pick Provider"]},void 0,!0,void 0,this),mt.jsxDEV(G,{flexDirection:"column",marginTop:0,children:[e.length===0&&mt.jsxDEV(G,{paddingLeft:1,children:mt.jsxDEV(I,{dimColor:!0,children:s?"\u6682\u65E0\u517C\u5BB9\u6B64\u5DE5\u5177\u7684\u670D\u52A1\u5546":"No compatible providers"},void 0,!1,void 0,this)},void 0,!1,void 0,this),e.map((u,d)=>{let p=i===d,g=d===o;return mt.jsxDEV(G,{paddingLeft:1,children:[mt.jsxDEV(I,{color:p?a:void 0,bold:p,children:p?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:p,color:p?a:void 0,children:[" ",u.name]},void 0,!0,void 0,this),u.email&&mt.jsxDEV(I,{dimColor:!0,children:[" (",u.email,")"]},void 0,!0,void 0,this),g&&mt.jsxDEV(I,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},u.id,!0,void 0,this)}),(()=>{let u=i===e.length;return mt.jsxDEV(G,{paddingLeft:1,marginTop:1,children:[mt.jsxDEV(I,{color:u?a:void 0,bold:u,children:u?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:u,color:u?a:void 0,children:[" ","\u2699 ",s?"\u7BA1\u7406\u670D\u52A1\u5546\u2026":"Manage providers\u2026"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)})()]},void 0,!0,void 0,this),mt.jsxDEV(kT,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function MT({group:e,options:o,enabled:i,pickerIdx:a,color:s,zh:u,pickCounts:d={}}){let p=o.filter((Q)=>Q.group===e),g=e==="model"?Cl(p,i,d):{list:p,hiddenCount:0},m=e==="model"?u?"\u9009\u62E9\u6A21\u578B":"Pick Model":e,h=!p.some((Q)=>i.has(Q.id));return mt.jsxDEV(G,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:s,paddingX:1,paddingY:0,children:[mt.jsxDEV(I,{bold:!0,color:s,children:["\u25A3 ",m]},void 0,!0,void 0,this),mt.jsxDEV(G,{flexDirection:"column",marginTop:0,children:[(()=>{let Q=a===0;return mt.jsxDEV(G,{paddingLeft:1,children:[mt.jsxDEV(I,{color:Q?s:void 0,bold:Q,children:Q?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:Q,color:Q?s:void 0,children:[" ",u?"\u9ED8\u8BA4\uFF08\u4E0D\u6307\u5B9A\uFF09":"Default (none)"]},void 0,!0,void 0,this),h&&mt.jsxDEV(I,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),g.list.map((Q,C)=>{let w=a===C+1,N=i.has(Q.id);return mt.jsxDEV(G,{paddingLeft:1,flexDirection:"column",children:[mt.jsxDEV(G,{children:[mt.jsxDEV(I,{color:w?s:void 0,bold:w,children:w?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:w,color:w?s:void 0,children:[" ",Q.label[u?"zh":"en"]||Q.label.en]},void 0,!0,void 0,this),N&&mt.jsxDEV(I,{color:"green",children:" \u2605"},void 0,!1,void 0,this),mt.jsxDEV(I,{dimColor:!0,children:[" ",Q.flag]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),w&&mt.jsxDEV(G,{paddingLeft:3,children:mt.jsxDEV(I,{dimColor:!0,children:Q.description[u?"zh":"en"]||Q.description.en},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},Q.id,!0,void 0,this)}),g.hiddenCount>0&&mt.jsxDEV(G,{paddingLeft:1,children:[mt.jsxDEV(I,{color:a===g.list.length+1?s:void 0,bold:a===g.list.length+1,children:a===g.list.length+1?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:a===g.list.length+1,color:a===g.list.length+1?s:void 0,children:[" ",u?`\u25BE \u663E\u793A\u5168\u90E8 (${g.hiddenCount})`:`\u25BE Show all (${g.hiddenCount})`]},void 0,!0,void 0,this),mt.jsxDEV(I,{dimColor:!0,children:" \u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),mt.jsxDEV(kT,{zh:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var mt,mP;var OT=O(async()=>{Lm();await Vo();mt=ye($t(),1),mP=[["\u2191\u2193","\u9009\u62E9","select"],["Enter","\u786E\u8BA4","confirm"],["m","\u5F53\u524D\u76EE\u5F55\u542F\u52A8","launch cwd"],["Esc","\u53D6\u6D88","cancel"]]});function EP({zh:e}){return cn.jsxDEV(G,{marginTop:0,justifyContent:"center",gap:2,children:[cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193\u2190\u2192"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u9009\u62E9":"select"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u5F53\u524D\u76EE\u5F55\u542F\u52A8":"launch cwd"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _T({options:e,enabled:o,pickerIdx:i,color:a,zh:s}){let{stdout:u}=El(),d=e.map((C)=>C.id),p=new Map(e.map((C)=>[C.id,C])),g=(C)=>p.get(C)?.label[s?"zh":"en"]||p.get(C)?.label.en||C,m=hl(e,u.columns||80,s),h=Il(d,m),Q=Math.max(ty,...d.length>0?d.map((C)=>UA(g(C))+3):[0]);return cn.jsxDEV(G,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:a,paddingX:1,paddingY:0,children:[cn.jsxDEV(I,{bold:!0,color:a,children:["\u25A3 ",s?"\u9009\u62E9\u6A21\u578B":"Pick Model"]},void 0,!0,void 0,this),cn.jsxDEV(G,{flexDirection:"column",marginTop:0,children:h.groups.map((C,w)=>cn.jsxDEV(G,{flexDirection:"column",marginTop:0,children:[w>0&&cn.jsxDEV(G,{children:cn.jsxDEV(I,{dimColor:!0,children:"\u254C".repeat(Math.max(8,Q*m))},void 0,!1,void 0,this)},void 0,!1,void 0,this),C.rows.map((N,v)=>cn.jsxDEV(G,{children:N.map((S)=>{let q=h.flat.indexOf(S)===i,ne=o.has(S),se=g(S);return cn.jsxDEV(G,{marginRight:1,children:[cn.jsxDEV(I,{color:q?a:void 0,bold:q,children:q?"\u25B8":" "},void 0,!1,void 0,this),cn.jsxDEV(I,{color:q?a:void 0,bold:q,children:xT(se,Q)},void 0,!1,void 0,this),ne&&cn.jsxDEV(I,{color:"green",children:"\u2605"},void 0,!1,void 0,this)]},S,!0,void 0,this)})},`${C.family}-${v}`,!1,void 0,this))]},C.family,!0,void 0,this))},void 0,!1,void 0,this),cn.jsxDEV(EP,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var cn;var UT=O(async()=>{Lm();await Vo();cn=ye($t(),1)});function GT(e,o){if(!e||o.ctrl||o.meta)return"";return e.replace(/[\x00-\x1f\x7f]/g,"")}function zT(e){return e.replace(/```[\s\S]*?```/g," [code] ").replace(/[`*_#>|]/g,"").replace(/\s+/g," ").trim()}function hP(e,o){let i=Math.max(0,Date.now()-e);if(i<3600000)return`${Math.max(1,Math.floor(i/60000))}${o?"\u5206\u949F\u524D":"m"}`;if(i<86400000)return`${Math.floor(i/3600000)}${o?"\u5C0F\u65F6\u524D":"h"}`;return`${Math.floor(i/86400000)}${o?"\u5929\u524D":"d"}`}function IP(e){if(e==="claude")return"Claude";if(e==="codex")return"Codex";if(e==="pi")return"Pi";return"Gemini"}function BP(e){if(e==="claude")return"magenta";if(e==="codex")return"blue";if(e==="pi")return"magenta";return"cyan"}function yP(e,o){let i=Math.floor(Math.max(0,Date.now()-e)/86400000);if(i===0)return o?"\u4ECA\u5929":"Today";if(i===1)return o?"\u6628\u5929":"Yesterday";if(i<7)return o?"\u672C\u5468":"This week";return o?"\u66F4\u65E9":"Earlier"}function JT({color:e}){let{stdout:o}=El(),i=Math.max((o.columns||80)-6,20);return H.jsxDEV(G,{marginY:0,children:H.jsxDEV(I,{dimColor:!0,color:e,children:"\u2500".repeat(i)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function DP(e){return e>30?"green":e>10?"yellow":"red"}function QP({provider:e,zh:o}){if(!e)return H.jsxDEV(I,{color:"yellow",children:["\u26A0 ",o?"\u672A\u7ED1\u5B9A":"no provider"]},void 0,!0,void 0,this);let i={tako:{zh:"Tako \u4EE3\u7406",en:"Tako Proxy",color:"cyan",icon:"\uD83D\uDC19"},"claude-subscription":{zh:"Claude \u5B98\u65B9",en:"Claude Official",color:"yellow",icon:"\u2726"},"codex-subscription":{zh:"Codex \u5B98\u65B9",en:"Codex Official",color:"blue",icon:"\u25C8"},anthropic:{zh:"Anthropic \u76F4\u8FDE",en:"Anthropic Direct",color:"yellow",icon:"\u2726"},deepseek:{zh:"DeepSeek",en:"DeepSeek",color:"magenta",icon:"\u25C7"},xiaomi:{zh:"\u5C0F\u7C73 MiMo",en:"Xiaomi MiMo",color:"yellow",icon:"\uD83D\uDFE0"},custom:{zh:"\u81EA\u5B9A\u4E49",en:"Custom",color:"gray",icon:"\u25AA"}},a=i[e.type]??i.custom,s=o?a.zh:a.en,u=e.email??"";if(u.length>0){let[d,p]=u.split("@");if(d&&p)u=d.length>14?`${d.slice(0,12)}\u2026@${p}`:u}return H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{color:a.color,children:[a.icon," ",s]},void 0,!0,void 0,this),u&&H.jsxDEV(I,{dimColor:!0,children:[" \xB7 ",u]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function wP({quota:e,zh:o}){if(e.status==="unsupported")return null;if(e.status==="error")return H.jsxDEV(I,{dimColor:!0,children:["\uD83D\uDCB0 ",e.hint||(o?"\u7528\u91CF\u83B7\u53D6\u5931\u8D25":"quota unavailable")]},void 0,!0,void 0,this);if(e.provider==="tako")if(!!(e.primary?.costLimit||e.secondary?.costLimit||e.daily?.costLimit));else{let p=e.daily??e.primary??e.secondary;if(!p)return null;let g=p.costUsed??0;return H.jsxDEV(I,{dimColor:!0,children:["\uD83D\uDCB0 ",o?"\u4ECA\u65E5":"Today",": ",H.jsxDEV(I,{color:"green",children:["$",g.toFixed(2)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}let i=(d,p,g)=>{if(d&&d>=1440)return`${Math.round(d/1440)}d`;if(d)return`${Math.round(d/60)}h`;return g?`${g}d`:`${p}h`},a=(d)=>Math.max(0,Math.min(100,100-Math.round(d))),s=[],u=(d,p,g)=>{if(s.length)s.push(H.jsxDEV(I,{dimColor:!0,children:" \xB7 "},`sep-${d}`,!1,void 0,this));let m=a(g);s.push(H.jsxDEV(et.default.Fragment,{children:[`${p} \u5269 `,H.jsxDEV(I,{color:DP(m),children:[m,"%"]},void 0,!0,void 0,this)]},d,!0,void 0,this))};if(e.primary)u("primary",i(e.primary.windowMinutes,5),e.primary.usedPct);if(e.secondary)u("secondary",i(e.secondary.windowMinutes,24,7),e.secondary.usedPct);if(e.modelLimits?.opus)u("opus","opus",e.modelLimits.opus.usedPct);if(!s.length)return null;return H.jsxDEV(I,{dimColor:!0,children:["\uD83D\uDCB0 ",s]},void 0,!0,void 0,this)}function vP({clients:e,defaultIdx:o,hasProviders:i,pickCounts:a,initialSessionSearch:s=!1,onResult:u}){let{stdout:d}=El(),[p,g]=et.useState(o),[m,h]=et.useState(s?"search":"projects"),[Q,C]=et.useState(0),[w,N]=et.useState(0),[v,S]=et.useState(()=>e[o]?.activeProvIdx||0),[L,q]=et.useState(()=>new Set(e[o]?.lastSelectedOptionIds??[])),[ne,se]=et.useState(""),[le,pe]=et.useState(null),[Qe,Ee]=et.useState("collapsed"),[ie,Be]=et.useState(!1),[we,De]=et.useState(0),[Ie,Dt]=et.useState(""),[ce,Ne]=et.useState(""),[ve,We]=et.useState(0),He=et.useRef(0),[V,Oe]=et.useState(null),Pe=et.useRef(null),[je,wt]=et.useState(null),[zt,vt]=et.useState(0),[Zt,Mt]=et.useState(!1),[ae,Ae]=et.useState(""),[X,de]=et.useState(null),[Ke,_e]=et.useState(null),Xe=Math.max(2,Math.min((d.columns||80)<100?4:6,Math.floor(((d.rows||30)-12)/2))),[yt,St]=et.useState(Xe),Ue=et.useRef(!0),bt=e[p],Ot=bt.projects,en=bt.providers,Jt=HT[bt.client.id]||PT,ke=ao()==="zh",In=en[v],ur=et.default.useMemo(()=>je?yg(je,ce,{currentCwd:Ot[0]?.path,limit:yt+1}):[],[je,ce,zt,Ot,yt]),Ho=ur.length>yt,_t=et.default.useMemo(()=>ur.slice(0,yt),[ur,yt]),ei=Math.max(0,Math.min(ve-Xe+1,Math.max(0,_t.length-Xe))),lr=_t.slice(ei,ei+Xe);et.useEffect(()=>{let b=Dg(),U=!1;wt(b),Mt(!0),Ae("");let j=td(b).then(()=>{if(!U)vt((W)=>W+1)}).catch((W)=>{if(!U)Ae(W instanceof Error?W.message:String(W))}).finally(()=>{if(!U)Mt(!1)});return()=>{U=!0,wt(null),j.finally(()=>b.close())}},[]),et.useEffect(()=>{if(!Ie){Ne("");return}let b=setTimeout(()=>Ne(Ie),120);return()=>clearTimeout(b)},[Ie]),et.useEffect(()=>{St((b)=>Math.max(b,Xe)),We((b)=>{let U=Math.max(0,Math.min(b,yt-1));return He.current=U,U})},[Xe,yt]),et.useEffect(()=>{if(_t.length===0){He.current=0,Pe.current=null,We(0),Oe(null);return}let b=Pe.current?_t.findIndex((W)=>W.session.key===Pe.current):-1,U=b>=0?b:Math.min(He.current,_t.length-1),j=_t[U].session.key;He.current=U,Pe.current=j,We(U),Oe(j)},[_t]),et.useEffect(()=>{if(!je||!X){_e(null);return}let b=je.getSession(X),U=je.getRecentMessages(X,32).filter((j)=>j.role==="user"||j.role==="assistant").slice(-8);_e(b?{session:b,messages:U}:null)},[je,X]);let Kt=et.default.useMemo(()=>bu(bt.client,In),[bt.client.id,In?.id,In?.type]),Tn=et.default.useMemo(()=>DT(Kt,ke),[Kt,ke]),uo=In?.name||(ke?"\u672A\u914D\u7F6E":"N/A"),[sn,ti]=et.useState(null);et.useEffect(()=>{if(!In){ti(null);return}let b=!1;return zc(In).then((U)=>{if(!b)ti(U)}),()=>{b=!0}},[In?.id,In?.type]),et.useEffect(()=>{if(Ue.current){Ue.current=!1;return}C(0),N(0),h("projects"),S(e[p]?.activeProvIdx||0),pe(null),Ee("collapsed"),Be(!1),q(new Set(e[p]?.lastSelectedOptionIds??[]))},[p]),et.useEffect(()=>{q((b)=>Tm(b,Kt,In?.model,bt.client.id==="pi"?`model-${IA}`:void 0))},[Kt,In?.model]);let to=et.useCallback((b)=>{let U=kd(Kt,L,b),j=Kt.filter((me)=>me.group===b);if(j.length===0)return;let W=b==="model"?ny(j,a):"collapsed",ge=0;if(U)if(b==="model"&&W==="grid"){let me=j.map((Le)=>Le.id),rt=hl(j,d.columns||80,ke);ge=oy(me,U.id,rt)}else ge=(b==="model"?Cl(j,L,a).list:j).findIndex((rt)=>rt.id===U.id)+1;De(Math.max(0,ge)),Ee(W),pe(b)},[L,Kt,a,d.columns,ke]),B=et.useCallback((b)=>{let U=QT({launchOptions:Kt,enabled:L},"model",b);u({type:"launch",clientId:bt.client.id,projectPath:Ot[0]?.path,...U})},[Kt,L,u,bt.client.id,Ot]);return Yn(et.useCallback((b,U)=>{if(ie){let W=en.length+1;if(U.escape||b==="q"){Be(!1);return}if(U.upArrow){De((ge)=>ge>0?ge-1:W-1);return}if(U.downArrow){De((ge)=>ge<W-1?ge+1:0);return}if(U.return)if(we<en.length){let ge=en[we];S(we),(async()=>{if(await bc(bt.client.id,ge.id),bt.client.setupConfigFiles)try{await bt.client.setupConfigFiles(jo(ge))}catch(me){se(ke?"\u26A0 \u914D\u7F6E\u540C\u6B65\u5931\u8D25":"\u26A0 Config sync failed"),setTimeout(()=>se(""),2500);return}bt.activeProvIdx=we,se(ke?`\u2713 \u5DF2\u7ED1\u5B9A ${ge.name}`:`\u2713 Bound ${ge.name}`),setTimeout(()=>se(""),2000)})(),Be(!1)}else Be(!1),u({type:"providers"});return}if(le){let W=Kt.filter((Le)=>Le.group===le),ge=le==="model";if(ge&&Qe==="grid"){let Le=W.map((Ut)=>Ut.id),Yt=hl(W,d.columns||80,ke),Ft=Il(Le,Yt),Wn=FT(Le,Yt),Eo=Ft.flat.length;if(b==="q"){pe(null),Ee("collapsed");return}if(b==="m"){let Ut=Ft.flat[we];B(Ut);return}if(U.escape){if(ny(W,a)==="grid")pe(null);else{Ee("collapsed");let Ut=kd(Kt,L,le),dn=Cl(W,L,a).list;De(Ut?Math.max(0,dn.findIndex((No)=>No.id===Ut.id)+1):0)}return}if(Eo===0)return;if(U.leftArrow){De((Ut)=>Ut>0?Ut-1:Eo-1);return}if(U.rightArrow){De((Ut)=>Ut<Eo-1?Ut+1:0);return}if(U.upArrow||U.downArrow){De((Ut)=>{let dn=0,No=0,gi=0;for(let jn=0;jn<Wn.length;jn++){let Oi=Wn[jn].length;if(Ut<gi+Oi){dn=jn,No=Ut-gi;break}gi+=Oi}let Gt=U.upArrow?dn>0?dn-1:Wn.length-1:dn<Wn.length-1?dn+1:0,Mi=Math.min(No,Wn[Gt].length-1);return Wn.slice(0,Gt).reduce((jn,Oi)=>jn+Oi.length,0)+Mi});return}if(U.return){let Ut=Ft.flat[we],dn=W.find((No)=>No.id===Ut);if(dn)q((No)=>{let gi=new Set(No);for(let Gt of W)gi.delete(Gt.id);return gi.add(dn.id),gi});pe(null),Ee("collapsed")}return}let me=ge?Cl(W,L,a):{list:W,hiddenCount:0},rt=me.list.length+1+(me.hiddenCount>0?1:0);if(U.escape||b==="q"){pe(null),Ee("collapsed");return}if(ge&&b==="m"){if(we===0){B();return}if(me.hiddenCount>0&&we===me.list.length+1)return;let Le=me.list[we-1];B(Le?.id);return}if(U.upArrow){De((Le)=>Le>0?Le-1:rt-1);return}if(U.downArrow){De((Le)=>Le<rt-1?Le+1:0);return}if(U.return){if(we===0)q((Le)=>{let Yt=new Set(Le);for(let Ft of W)Yt.delete(Ft.id);return Yt});else if(ge&&me.hiddenCount>0&&we===me.list.length+1){let Le=kd(Kt,L,le),Yt=W.map((Eo)=>Eo.id),Ft=hl(W,d.columns||80,ke),Wn=Le?oy(Yt,Le.id,Ft):0;De(Math.max(0,Wn)),Ee("grid");return}else{let Le=me.list[we-1];q((Yt)=>{let Ft=new Set(Yt);for(let Wn of W)Ft.delete(Wn.id);return Ft.add(Le.id),Ft})}pe(null),Ee("collapsed")}return}if(m==="search"){if(X&&(U.escape||U.leftArrow)){de(null);return}if(U.escape||U.leftArrow){Dt(""),He.current=0,Pe.current=null,We(0),Oe(null),h("projects");return}if(U.rightArrow){let ge=_t.find((me)=>me.session.key===Pe.current)??_t[He.current];if(ge)de(ge.session.key);return}if(U.downArrow){if(_t.length===0)return;if(He.current>=_t.length-1&&Ho)St((ge)=>ge+Xe),He.current+=1,We(He.current);else He.current=Math.min(_t.length-1,He.current+1),We(He.current);Pe.current=_t[He.current]?.session.key??null,Oe(Pe.current);return}if(U.upArrow){He.current=Math.max(0,He.current-1),We(He.current),Pe.current=_t[He.current]?.session.key??null,Oe(Pe.current);return}if(U.backspace||U.delete){Dt((ge)=>ge.slice(0,-1)),He.current=0,Pe.current=null,We(0),Oe(null),de(null),St(Xe);return}if(U.return){let ge=_t.find((me)=>me.session.key===Pe.current)??_t[He.current];if(!ge)return;if(ge.session.resumeCapability==="unsupported"){de(ge.session.key);return}try{let me=fI(ge.session,Ot[0]?.path);u({type:"launch",clientId:me.clientId,projectPath:me.projectPath,args:me.args,envVars:{},selectedOptionIds:[]})}catch(me){Ae(me instanceof Error?me.message:String(me))}return}let W=GT(b,U);if(W)Dt((ge)=>ge+W),He.current=0,Pe.current=null,We(0),Oe(null),de(null),St(Xe);return}if(b==="q"){u({type:"exit"});return}if(b==="a"){u({type:"agent"});return}if(b==="s"){u({type:"stats"});return}if(b==="c"){u({type:"config"});return}if(b==="l"){u({type:"language"});return}if(b==="p"){u({type:"providers"});return}if(b==="m"){to("model");return}let j=parseInt(b);if(j>=1&&j<=e.length){g(j-1);return}if(U.leftArrow){g((W)=>W>0?W-1:e.length-1);return}if(U.rightArrow){g((W)=>W<e.length-1?W+1:0);return}if(m==="projects"){if(U.downArrow){if(Q<Ot.length-1)C((W)=>W+1);else if(Tn.length>0)h("options"),N(0);return}if(U.upArrow){if(Q>0)C((W)=>W-1);else He.current=0,Pe.current=_t[0]?.session.key??null,We(0),Oe(Pe.current),St(Xe),de(null),h("search");return}}if(m==="options"){if(U.downArrow){if(w<Tn.length-1)N((W)=>W+1);return}if(U.upArrow){if(w>0)N((W)=>W-1);else h("projects"),C(Ot.length-1);return}}if(b===" "&&m==="options"&&Tn.length>0){let W=Tn[w];if(W.kind==="flag")q((ge)=>{let me=new Set(ge);if(me.has(W.opt.id))me.delete(W.opt.id);else me.add(W.opt.id);return me});else if(W.kind==="group")to(W.group);else De(v),Be(!0);return}if(U.return){if(m==="options"&&Tn.length>0){let me=Tn[w];if(me.kind==="group"){to(me.group);return}if(me.kind==="provider"){De(v),Be(!0);return}}let W=Ot[Q],ge=Rm({launchOptions:Kt,enabled:L});u({type:"launch",clientId:bt.client.id,projectPath:W.path,...ge})}},[m,p,Q,w,v,en,In,bt,Ot,Kt,Tn,L,e,u,ke,le,ie,we,a,Qe,d.columns,to,B,Ie,ve,V,_t,X,yt,Xe,Ho])),H.jsxDEV(G,{flexDirection:"column",paddingX:0,paddingY:0,children:[H.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:m==="search"?"cyan":Jt.color,paddingX:1,paddingY:0,children:[H.jsxDEV(G,{justifyContent:"space-between",children:[H.jsxDEV(G,{gap:1,children:[H.jsxDEV(I,{bold:!0,children:"\uD83D\uDC19 Tako"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:["v",CP]},void 0,!0,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(QP,{provider:In,zh:ke},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(G,{children:[ne&&H.jsxDEV(I,{color:"green",children:ne},void 0,!1,void 0,this),!ne&&sn&&H.jsxDEV(wP,{quota:sn,zh:ke},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!i&&H.jsxDEV(G,{marginTop:1,justifyContent:"center",gap:1,children:[H.jsxDEV(I,{color:"yellow",children:"\u26A0"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u672A\u914D\u7F6E\u670D\u52A1\u5546 \u2014 \u6309 c \u6DFB\u52A0 API Key \u6216 p \u7BA1\u7406\u670D\u52A1\u5546":"No provider configured \u2014 press c for API Key or p to manage"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m!=="search"&&H.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:[H.jsxDEV(I,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),e.map((b,U)=>{let j=HT[b.client.id]||PT;return U===p?H.jsxDEV(G,{borderStyle:"bold",borderColor:j.color,paddingX:1,children:H.jsxDEV(I,{color:j.color,bold:!0,children:[j.icon," ",b.client.name]},void 0,!0,void 0,this)},b.client.id,!1,void 0,this):H.jsxDEV(G,{borderStyle:"single",borderColor:"gray",paddingX:1,children:H.jsxDEV(I,{dimColor:!0,children:[j.icon," ",b.client.name]},void 0,!0,void 0,this)},b.client.id,!1,void 0,this)}),H.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m!=="search"&&H.jsxDEV(JT,{color:Jt.color},void 0,!1,void 0,this),ie?H.jsxDEV(LT,{provs:en,provIdx:v,pickerIdx:we,color:Jt.color,zh:ke},void 0,!1,void 0,this):le==="model"&&Qe==="grid"?H.jsxDEV(_T,{options:Kt.filter((b)=>b.group==="model"),enabled:L,pickerIdx:we,color:Jt.color,zh:ke},void 0,!1,void 0,this):le?H.jsxDEV(MT,{group:le,options:Kt,enabled:L,pickerIdx:we,color:Jt.color,zh:ke,pickCounts:a},void 0,!1,void 0,this):H.jsxDEV(H.Fragment,{children:[m==="search"?H.jsxDEV(G,{borderStyle:"round",borderColor:"cyan",paddingX:1,flexDirection:"column",marginTop:1,marginBottom:1,children:[H.jsxDEV(G,{justifyContent:"space-between",children:[H.jsxDEV(I,{color:"cyan",bold:!0,children:["\u2315 ",ke?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD":"Search sessions"]},void 0,!0,void 0,this),Zt&&H.jsxDEV(I,{dimColor:!0,children:ke?"\u7D22\u5F15\u4E2D...":"indexing..."},void 0,!1,void 0,this),!Zt&&ae&&H.jsxDEV(I,{color:"red",children:["\u26A0 ",Fm(ae,Math.max(16,(d.columns||80)-48))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(G,{children:[H.jsxDEV(I,{color:"cyan",bold:!0,children:"\u203A "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:!!Ie,dimColor:!Ie,children:Ie||(ke?"\u8F93\u5165\u5173\u952E\u8BCD\uFF0C\u7559\u7A7A\u6D4F\u89C8\u6700\u8FD1\u4F1A\u8BDD":"Type to search, or browse recent sessions")},void 0,!1,void 0,this),H.jsxDEV(I,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(I,{children:" \u2315 "},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD...":"Search previous sessions..."},void 0,!1,void 0,this),Zt&&H.jsxDEV(I,{dimColor:!0,children:[" ",ke?"\u7D22\u5F15\u4E2D":"indexing"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X&&Ke?H.jsxDEV(G,{paddingLeft:2,flexDirection:"column",children:[H.jsxDEV(I,{bold:!0,color:"cyan",children:Ke.session.title??X},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:Ke.session.cwd},void 0,!1,void 0,this),Ke.session.resumeCapability==="unsupported"&&H.jsxDEV(I,{color:"yellow",children:ke?"\u6B64\u6765\u6E90\u6682\u4E0D\u652F\u6301\u76F4\u63A5\u7EED\u63A5\uFF0C\u4EC5\u53EF\u641C\u7D22\u548C\u67E5\u770B\u3002":"This source is view-only and cannot be resumed yet."},void 0,!1,void 0,this),Ke.messages.map((b)=>H.jsxDEV(I,{children:[H.jsxDEV(I,{color:b.role==="user"?"yellow":"green",children:[b.role==="user"?"You":"AI",": "]},void 0,!0,void 0,this),b.text.replace(/\s+/g," ").slice(0,Math.max(40,(d.columns||80)-12))]},b.ordinal,!0,void 0,this))]},void 0,!0,void 0,this):m==="search"?lr.map((b,U)=>{let W=ei+U===ve,ge=BP(b.session.source),me=yP(b.session.updatedAt,ke),rt=Math.max(30,(d.columns||80)-14);return H.jsxDEV(et.default.Fragment,{children:H.jsxDEV(G,{paddingLeft:1,flexDirection:"column",children:[H.jsxDEV(G,{children:[H.jsxDEV(I,{color:W?"cyan":void 0,bold:W,children:W?"\u25B8 ":" "},void 0,!1,void 0,this),H.jsxDEV(I,{color:"cyan",children:me},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:" \xB7 "},void 0,!1,void 0,this),H.jsxDEV(I,{color:ge,bold:!0,children:IP(b.session.source)},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:[" \xB7 ",b.session.projectName??"\u672A\u77E5\u9879\u76EE"," \xB7 ",hP(b.session.updatedAt,ke)," "]},void 0,!0,void 0,this),H.jsxDEV(I,{bold:W,color:W?"white":void 0,children:Fm(zT(b.session.title??b.session.nativeId.slice(0,8)),Math.max(12,rt-36))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(I,{dimColor:!0,children:[" ",Fm(zT(b.snippet),rt)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},b.session.key,!1,void 0,this)}).concat([H.jsxDEV(G,{paddingLeft:4,marginTop:1,children:H.jsxDEV(I,{dimColor:!0,children:[_t.length===0?ke?"\u6682\u65E0\u4F1A\u8BDD":"No sessions":`${ei+1}-${Math.min(ei+Xe,_t.length)} / ${_t.length}${Ho?"+":""}`,Ho?` \xB7 \u2193 ${ke?"\u7EE7\u7EED\u6D4F\u89C8":"more"}`:""]},void 0,!0,void 0,this)},"session-window-status",!1,void 0,this)]):Ot.map((b,U)=>{let j=m==="projects"&&U===Q;return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:b.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b.hint?H.jsxDEV(I,{dimColor:!0,children:b.hint},void 0,!1,void 0,this):null]},U,!0,void 0,this)}),m!=="search"&&Tn.length>0&&H.jsxDEV(H.Fragment,{children:[H.jsxDEV(JT,{color:Jt.color},void 0,!1,void 0,this),Tn.map((b,U)=>{let j=m==="options"&&U===w;if(b.kind==="flag"){let W=b.opt,ge=L.has(W.id);return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{color:ge?Jt.color:void 0,bold:ge,children:ge?"\u25C9":"\u25CB"},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:W.label[ke?"zh":"en"]||W.label.en},void 0,!1,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:W.flag},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:W.description[ke?"zh":"en"]||W.description.en},void 0,!1,void 0,this)]},W.id,!0,void 0,this)}if(b.kind==="group"){let W=kd(Kt,L,b.group),ge=W?W.shortLabel:ke?"\u9ED8\u8BA4":"Default";return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:[b.title,":"]},void 0,!0,void 0,this),H.jsxDEV(I,{color:W?Jt.color:void 0,children:ge},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:ke?"Enter \u8FDB\u5165\u9009\u62E9":"Enter to pick"},void 0,!1,void 0,this)]},`group-${b.group}`,!0,void 0,this)}return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:[b.title,":"]},void 0,!0,void 0,this),H.jsxDEV(I,{color:In?Jt.color:"yellow",children:In?uo:ke?"\u672A\u914D\u7F6E":"Not set"},void 0,!1,void 0,this),H.jsxDEV(I,{color:"yellow",children:"\u2605"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:ke?"Enter \u5207\u6362\u6216\u7BA1\u7406":"Enter to switch / manage"},void 0,!1,void 0,this)]},"provider-entry",!0,void 0,this)})]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(G,{paddingX:2,marginTop:0,justifyContent:"center",gap:2,children:m==="search"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:_t[ve]?.session.resumeCapability==="unsupported"?ke?"\u67E5\u770B":"open":ke?"\u7EED\u63A5":"resume"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2192"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u67E5\u770B":"details"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):m==="options"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Space"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u5F00\u5173":"toggle"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9000\u51FA":"quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"a"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"agent"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"p"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u670D\u52A1\u5546":"service"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"s"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u7EDF\u8BA1":"stats"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9000\u51FA":"quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function KT({onResult:e,initialSessionSearch:o=!1}){let[i,a]=et.useState(null);if(et.useEffect(()=>{wT(45).then(a)},[]),!i)return H.jsxDEV(I,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this);return H.jsxDEV(vP,{clients:i.clients,defaultIdx:i.defaultIdx,hasProviders:i.hasProviders,pickCounts:i.pickCounts,initialSessionSearch:o,onResult:e},void 0,!1,void 0,this)}var et,H,CP="0.3.38",HT,PT;var YT=O(async()=>{zn();_c();bi();Mn();Vf();vT();Lm();dI();gI();await ha([Vo(),OT(),UT()]);et=ye(ct(),1),H=ye($t(),1),HT={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},PT={icon:"\u25AA",color:"white"}});function WT({provider:e,focused:o,bound:i,isDefault:a,zh:s}){let u=Wr[e.type]||Wr.custom,d=s?Si[e.type]?.zh:Si[e.type]?.en;return fe.jsxDEV(G,{flexDirection:"column",borderStyle:o?"bold":"round",borderColor:o?u.color:i?u.color:"gray",paddingX:2,paddingY:0,children:[fe.jsxDEV(G,{justifyContent:"space-between",children:[fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:o||i,color:o?u.color:void 0,children:e.name},void 0,!1,void 0,this),a&&fe.jsxDEV(I,{color:"yellow",children:["\u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this),e.builtin&&fe.jsxDEV(I,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{gap:1,children:i?fe.jsxDEV(I,{color:u.color,bold:!0,children:["\u25CF ",s?"\u5DF2\u7ED1\u5B9A":"bound"]},void 0,!0,void 0,this):fe.jsxDEV(I,{dimColor:!0,children:["\u25CB ",s?"\u672A\u7ED1\u5B9A":"unbound"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:d},void 0,!1,void 0,this),e.model&&fe.jsxDEV(I,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.model&&fe.jsxDEV(I,{dimColor:!0,children:e.model},void 0,!1,void 0,this),e.email&&fe.jsxDEV(I,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.email&&fe.jsxDEV(I,{dimColor:!0,children:e.email},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(I,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(I,{dimColor:!0,children:["Key: ",e.apiKey.slice(0,8),"\u2022\u2022\u2022"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o&&fe.jsxDEV(G,{marginTop:0,children:fe.jsxDEV(I,{color:u.color,dimColor:!0,children:["Enter ",s?"\u7ED1\u5B9A\u5230\u5F53\u524D\u5DE5\u5177":"bind to this tool"," \xB7 d ",s?"\u8BE6\u60C5/\u64CD\u4F5C":"detail/actions"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jT({screen:e,addType:o,addKey:i,addUrl:a,addModel:s,addCtx:u,rowIdx:d,zh:p}){let g=Wr[o]||Wr.custom,m=p?Si[o]?.zh:Si[o]?.en,h=e==="add-model"?xc(o):void 0;if(h)return fe.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(G,{borderStyle:"bold",borderColor:g.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,marginBottom:1,children:[fe.jsxDEV(I,{color:g.color,bold:!0,children:g.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:!0,color:g.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:["\u2014 ",p?"\u9009\u62E9\u6A21\u578B":"Select Model"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h.map((v,S)=>{let L=d===S;return fe.jsxDEV(G,{paddingLeft:1,gap:1,children:[fe.jsxDEV(I,{color:L?g.color:void 0,bold:L,children:L?"\u25B8":" "},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:L,color:L?g.color:void 0,children:v},void 0,!1,void 0,this)]},v,!0,void 0,this)})]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u53D6\u6D88":"cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);let Q=e==="add-key"?p?"\u8F93\u5165 API Key":"Enter API Key":e==="add-url"?"Base URL":e==="add-ctx"?p?"\u4E0A\u4E0B\u6587\u7A97\u53E3\uFF08tokens\uFF0C\u53EF\u7559\u7A7A\uFF09":"Context Window (tokens, optional)":p?"\u6A21\u578B":"Model",C=e==="add-key"?i:e==="add-url"?a:e==="add-ctx"?u??"":s,w=e==="add-url"?"https://your-proxy.com":e==="add-ctx"?p?"\u5982 200000\uFF1Bcatalog \u6CA1\u6709\u8BE5\u6A21\u578B\u65F6\u5EFA\u8BAE\u586B\u5199":"e.g. 200000; recommended if model is unknown to catalog":e==="add-model"?Fu(o)||(p?"\u7559\u7A7A\u4F7F\u7528\u9ED8\u8BA4":"leave empty"):void 0,N=e==="add-url"?p?"\u4E0B\u4E00\u6B65":"next":e==="add-ctx"?p?"\u4FDD\u5B58":"save":e==="add-model"?p?"\u4FDD\u5B58":"save":p?"\u786E\u8BA4":"confirm";return fe.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(G,{borderStyle:"bold",borderColor:g.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,marginBottom:1,children:[fe.jsxDEV(I,{color:g.color,bold:!0,children:g.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:!0,color:g.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:["\u2014 ",Q]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e==="add-key"&&o==="xiaomi"&&fe.jsxDEV(I,{dimColor:!0,children:[" ",p?"sk- \u5F00\u5934\u8D70\u6309\u91CF\u4ED8\u8D39\uFF0Ctp- \u5F00\u5934\u8D70 Token Plan \u8BA2\u9605\uFF08\u81EA\u52A8\u8BC6\u522B\uFF09":"sk- = pay-as-you-go, tp- = Token Plan subscription (auto-detected)"]},void 0,!0,void 0,this),w&&fe.jsxDEV(I,{dimColor:!0,children:[" ",p?"\u9ED8\u8BA4":"Default",": ",w]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:w?1:0,children:[fe.jsxDEV(I,{color:g.color,bold:!0,children:["\u203A"," "]},void 0,!0,void 0,this),fe.jsxDEV(I,{children:C||w||""},void 0,!1,void 0,this),fe.jsxDEV(I,{color:g.color,children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:N},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u53D6\u6D88":"cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qT({provider:e,defaultId:o,detailActions:i,detailIdx:a,zh:s}){let u=Wr[e.type]||Wr.custom,d=s?Si[e.type]?.zh:Si[e.type]?.en;return fe.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(G,{borderStyle:"bold",borderColor:u.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:!0,color:u.color,children:e.name},void 0,!1,void 0,this),e.id===o&&fe.jsxDEV(I,{color:"yellow",children:[" \u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:[s?"\u7C7B\u578B":"Type",":"]},void 0,!0,void 0,this),fe.jsxDEV(I,{children:d},void 0,!1,void 0,this),e.builtin&&fe.jsxDEV(I,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.model&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:[s?"\u6A21\u578B":"Model",":"]},void 0,!0,void 0,this),fe.jsxDEV(I,{children:e.model},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.email&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:"Email:"},void 0,!1,void 0,this),fe.jsxDEV(I,{children:e.email},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.apiKey&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:"Key:"},void 0,!1,void 0,this),fe.jsxDEV(I,{children:[e.apiKey.slice(0,12),"\u2022\u2022\u2022"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e.baseUrl&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:"URL:"},void 0,!1,void 0,this),fe.jsxDEV(I,{children:e.baseUrl},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{gap:1,marginTop:1,children:i.map((p,g)=>{let m=p==="default"?`\u2B50 ${s?"\u8BBE\u4E3A\u9ED8\u8BA4":"Set Default"}`:p==="rekey"?`\uD83D\uDD11 ${s?"\u4FEE\u6539 Key":"Change Key"}`:p==="relogin"?`\uD83D\uDD04 ${s?"\u91CD\u65B0\u767B\u5F55":"Re-login"}`:p==="delete"?`\uD83D\uDDD1\uFE0F ${s?"\u5220\u9664":"Delete"}`:`\u2190 ${s?"\u8FD4\u56DE":"Back"}`,h=g===a;return fe.jsxDEV(G,{borderStyle:h?"bold":"round",borderColor:h?"cyan":"gray",paddingX:2,children:fe.jsxDEV(I,{bold:h,color:h?"cyan":void 0,dimColor:!h,children:m},void 0,!1,void 0,this)},p,!1,void 0,this)})},void 0,!1,void 0,this),fe.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:s?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:s?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:s?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var fe,Wr,iy,Ld;var VT=O(async()=>{ds();await Vo();fe=ye($t(),1),Wr={"claude-subscription":{icon:"\u2726",color:"yellow"},"codex-subscription":{icon:"\u25C8",color:"blue"},tako:{icon:"\uD83D\uDC19",color:"cyan"},anthropic:{icon:"\u25B3",color:"magenta"},deepseek:{icon:"\uD83D\uDD2E",color:"blue"},xiaomi:{icon:"\uD83D\uDFE0",color:"yellow"},custom:{icon:"\u2699",color:"gray"}},iy={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},Ld=["claude-subscription","codex-subscription","tako","anthropic","deepseek","xiaomi","custom"]});function XT({onDone:e}){let[o,i]=an.useState("list"),[a,s]=an.useState([]),[u,d]=an.useState(),[p,g]=an.useState({}),[m,h]=an.useState(0),[Q,C]=an.useState(0),[w,N]=an.useState(0),[v,S]=an.useState(""),[L,q]=an.useState(""),[ne,se]=an.useState("tako"),[le,pe]=an.useState(""),[Qe,Ee]=an.useState(""),[ie,Be]=an.useState(""),[we,De]=an.useState(""),Ie=ao()==="zh",Dt=lA(),ce=Dt[m],Ne=iy[ce?.id]?.color||"white",ve=ce?a.filter((ae)=>ku(ae,ce.id)):[],We=p[ce?.id]||u,He=ve.length+4,V=a.find((ae)=>ae.id===v),Oe=V?.type==="claude-subscription"||V?.type==="codex-subscription",Pe=V?[...V.id!==u?["default"]:[],...Oe?["relogin"]:[],...V.builtin?["rekey"]:["delete"],"back"]:["back"],je=an.useCallback(async()=>{let ae=await Wo(),Ae=await pi();s(ae),d(Ae?.id);let X={};for(let de of lA()){let Ke=await Qa(de.id);X[de.id]=Ke?.id}g(X)},[]);an.useEffect(()=>{je()},[je]),an.useEffect(()=>{C(0)},[m]),an.useEffect(()=>{if(L){let ae=setTimeout(()=>q(""),3000);return()=>clearTimeout(ae)}},[L]);let wt=an.useCallback(async()=>{if(v&&a.find((_e)=>_e.id===v)?.builtin){await gA(v,{apiKey:le}),q(Ie?"Key \u5DF2\u66F4\u65B0":"Key updated"),await je(),i("list"),C(0);return}let ae=Si[ne]?.[Ie?"zh":"en"]||ne,Ae=Qe||z0(ne),X=ie||Fu(ne),de=we?parseInt(we,10):NaN,Ke=Number.isFinite(de)&&de>0?de:void 0;await fA({name:ae,type:ne,apiKey:le,baseUrl:Ae,model:X,modelContextWindow:Ke,supportedClients:ci(ne)}),$n("provider_added",{provider_type:ne,method:"manual"}),wa(),er(),q(Ie?"\u5DF2\u6DFB\u52A0":"Added"),De(""),await je(),i("list"),C(0)},[ne,le,Qe,ie,we,Ie,je,v,a]),zt=an.useCallback(async()=>{i("scanning");let ae=await Nc(),Ae=await Rc(ae);if(Ae>0)wa(),er();q(Ie?`\u626B\u63CF\u5B8C\u6210\uFF0C\u65B0\u589E ${Ae} \u4E2A`:`Scan done, ${Ae} added`),await je(),i("list"),C(0)},[je,Ie]),[vt,Zt]=an.useState("claude"),Mt=an.useCallback(async(ae)=>{Zt(ae),i("logging-in");let Ae=ae==="claude"?["claude","auth","login","--claudeai"]:["codex","login"];await Bun.spawn(Ae,{stdin:"inherit",stdout:"pipe",stderr:"pipe"}).exited;let{invalidateQuotaCache:de}=await Promise.resolve().then(() => (Vf(),i1));if(ae==="claude")try{let Ke=Bun.spawn(["claude","auth","status"],{stdout:"pipe",stderr:"pipe"}),_e=await new Response(Ke.stdout).text();await Ke.exited;let Xe=JSON.parse(_e.trim());if(Xe.loggedIn&&Xe.authMethod==="claude.ai"){let yt=Xe.email||"",St=Xe.subscriptionType||"pro",Ue=`Claude ${St.charAt(0).toUpperCase()+St.slice(1)}${yt?` (${yt})`:""}`,{readClaudeAuth:bt}=await Promise.resolve().then(() => (Ff(),Tf)),Ot=await bt(),en=Ot.credentials||Ot.oauthAccount?{credentials:Ot.credentials,oauthAccount:Ot.oauthAccount}:void 0,Jt=a.find((ke)=>ke.type==="claude-subscription"&&ke.email===yt);if(!Jt)await fA({name:Ue,type:"claude-subscription",email:yt,subscriptionType:St,supportedClients:ci("claude-subscription"),authData:en}),q(Ie?"Claude \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Claude subscription added");else await gA(Jt.id,{authData:en}),de(Jt.id,"claude-subscription"),q(Ie?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else q(Ie?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{q(Ie?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}else try{let Ke=await import("fs/promises"),{homedir:_e}=await import("os"),{join:Xe}=await import("path"),yt=JSON.parse(await Ke.readFile(Xe(_e(),".codex","auth.json"),"utf-8"));if(yt.auth_mode==="chatgpt"&&yt.tokens?.access_token){let St="";try{St=JSON.parse(atob(yt.tokens.id_token.split(".")[1])).email||""}catch{}let Ue=a.find((bt)=>bt.type==="codex-subscription"&&bt.email===St);if(!Ue)await fA({name:St?`Codex Plus (${St})`:"Codex Subscription",type:"codex-subscription",email:St||void 0,supportedClients:ci("codex-subscription"),authData:yt}),q(Ie?"Codex \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Codex subscription added");else await gA(Ue.id,{authData:yt}),de(Ue.id,"codex-subscription"),q(Ie?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else q(Ie?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{q(Ie?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}await je(),i("list"),C(0)},[a,Ie,je]);if(Yn(an.useCallback((ae,Ae)=>{if(o==="list"){if(Ae.escape||ae==="q"){e();return}if(Ae.leftArrow){h((de)=>de>0?de-1:Dt.length-1);return}if(Ae.rightArrow){h((de)=>de<Dt.length-1?de+1:0);return}let X=parseInt(ae);if(X>=1&&X<=Dt.length){h(X-1);return}if(Ae.upArrow){C((de)=>de>0?de-1:He-1);return}if(Ae.downArrow){C((de)=>de<He-1?de+1:0);return}if(Ae.return){if(Q<ve.length){let de=ve[Q];bc(ce.id,de.id).then(()=>{e()})}else if(Q===ve.length)i("add-type"),C(0);else if(Q===ve.length+1)zt();else if(Q===ve.length+2)e("client-versions");else e();return}if((ae==="d"||ae==="e")&&Q<ve.length)S(ve[Q].id),i("detail"),N(0);return}if(o==="detail"){if(Ae.leftArrow){N((X)=>X>0?X-1:Pe.length-1);return}if(Ae.rightArrow){N((X)=>X<Pe.length-1?X+1:0);return}if(Ae.escape){i("list"),C(0);return}if(Ae.return){let X=Pe[w];if(X==="back"){i("list"),C(0);return}if(X==="default")X0(v).then(()=>{q(Ie?"\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4":"Set as default"),je(),i("list"),C(0)});if(X==="delete")V0(v).then(()=>{q(Ie?"\u5DF2\u5220\u9664":"Deleted"),je(),i("list"),C(0)});if(X==="rekey")se(V?.type||"tako"),pe(""),i("add-key"),C(0);if(X==="relogin"){let de=V?.type==="codex-subscription"?"codex":"claude";i("list"),C(0),Mt(de)}}return}if(o==="add-type"){if(Ae.upArrow){C((X)=>X>0?X-1:Ld.length-1);return}if(Ae.downArrow){C((X)=>X<Ld.length-1?X+1:0);return}if(Ae.escape){i("list"),C(0);return}if(Ae.return){let X=Ld[Q];if(se(X),X==="claude-subscription"){Mt("claude");return}if(X==="codex-subscription"){Mt("codex");return}pe(""),Ee(""),Be(Fu(X)||""),i("add-key"),C(0)}return}if(o==="add-key"){if(Ae.escape){i("list"),C(0);return}if(Ae.return&&le){if(ne==="custom")i("add-url");else if(ne==="deepseek"||ne==="anthropic"||ne==="tako"||ne==="xiaomi")i("add-model"),C(0);else wt();return}if(Ae.backspace||Ae.delete){pe((X)=>X.slice(0,-1));return}if(ae&&!Ae.ctrl)pe((X)=>X+ae);return}if(o==="add-url"){if(Ae.escape){i("list"),C(0);return}if(Ae.return){i("add-model"),C(0);return}if(Ae.backspace||Ae.delete){Ee((X)=>X.slice(0,-1));return}if(ae&&!Ae.ctrl)Ee((X)=>X+ae);return}if(o==="add-model"){let X=xc(ne);if(Ae.escape){i("list"),C(0);return}if(X){if(Ae.upArrow){C((de)=>de>0?de-1:X.length-1);return}if(Ae.downArrow){C((de)=>de<X.length-1?de+1:0);return}if(Ae.return){Be(X[Q]),setTimeout(()=>wt(),0);return}}else{if(Ae.return){let de=ie.trim();if(de&&bo.some((Ke)=>Ke.id===de))wt();else i("add-ctx");return}if(Ae.backspace||Ae.delete){Be((de)=>de.slice(0,-1));return}if(ae&&!Ae.ctrl)Be((de)=>de+ae)}return}if(o==="add-ctx"){if(Ae.escape){i("list"),C(0);return}if(Ae.return){wt();return}if(Ae.backspace||Ae.delete){De((X)=>X.slice(0,-1));return}if(ae&&!Ae.ctrl&&/^[0-9]$/.test(ae))De((X)=>X+ae);return}},[o,Q,w,ve,He,Dt.length,ce,v,V,Pe,ne,le,Qe,ie,we,e,zt,Mt,wt,je,Ie])),o==="scanning"||o==="logging-in"){let ae=o==="logging-in"?Wr[vt==="claude"?"claude-subscription":"codex-subscription"]:{icon:"\u23F3",color:"yellow"},Ae=o==="scanning"?Ie?"\u6B63\u5728\u626B\u63CF\u672C\u5730\u8BA2\u9605...":"Scanning local subscriptions...":Ie?"\u6B63\u5728\u767B\u5F55\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u6388\u6743...":"Logging in, please authorize in browser...";return Ye.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:Ye.jsxDEV(G,{borderStyle:"round",borderColor:ae.color,paddingX:3,paddingY:1,flexDirection:"column",alignItems:"center",children:[Ye.jsxDEV(I,{color:ae.color,bold:!0,children:[ae.icon," ",Ae]},void 0,!0,void 0,this),o==="logging-in"&&Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u5B8C\u6210\u540E\u5C06\u81EA\u52A8\u8FD4\u56DE":"Will return automatically when done"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}if(o==="add-key"||o==="add-url"||o==="add-model"||o==="add-ctx")return Ye.jsxDEV(jT,{screen:o,addType:ne,addKey:le,addUrl:Qe,addModel:ie,addCtx:we,rowIdx:Q,zh:Ie},void 0,!1,void 0,this);if(o==="add-type")return Ye.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Ye.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:Ye.jsxDEV(I,{bold:!0,children:["\u2795 ",Ie?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ye.jsxDEV(G,{flexDirection:"column",marginTop:1,gap:0,children:Ld.map((ae,Ae)=>{let X=Wr[ae]||Wr.custom,de=Q===Ae,Ke=Ie?Si[ae]?.zh:Si[ae]?.en,_e=ae==="claude-subscription"||ae==="codex-subscription";return Ye.jsxDEV(G,{borderStyle:de?"bold":"round",borderColor:de?X.color:"gray",paddingX:2,paddingY:0,children:Ye.jsxDEV(G,{gap:1,children:[Ye.jsxDEV(I,{color:X.color,bold:!0,children:X.icon},void 0,!1,void 0,this),Ye.jsxDEV(I,{bold:de,color:de?X.color:void 0,children:Ke},void 0,!1,void 0,this),_e&&Ye.jsxDEV(I,{dimColor:!0,children:["(",Ie?"\u767B\u5F55\u6388\u6743":"login auth",")"]},void 0,!0,void 0,this),!_e&&Ye.jsxDEV(I,{dimColor:!0,children:["(",Ie?"\u586B\u5199 Key":"enter key",")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},ae,!1,void 0,this)})},void 0,!1,void 0,this),Ye.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o==="detail"&&V)return Ye.jsxDEV(qT,{provider:V,defaultId:u,detailActions:Pe,detailIdx:w,zh:Ie},void 0,!1,void 0,this);return Ye.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Ye.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:[Ye.jsxDEV(I,{bold:!0,children:["\u26A1 ",Ie?"\u7BA1\u7406\u670D\u52A1\u5546":"Manage Providers"]},void 0,!0,void 0,this),L&&Ye.jsxDEV(I,{color:"green",children:[" \u2713 ",L]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ye.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:[Ye.jsxDEV(I,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),Dt.map((ae,Ae)=>{let X=iy[ae.id]||{icon:"\u25AA",color:"white"},de=Ae===m;return Ye.jsxDEV(G,{borderStyle:de?"bold":"single",borderColor:de?X.color:"gray",paddingX:2,children:Ye.jsxDEV(I,{color:de?X.color:void 0,bold:de,dimColor:!de,children:[X.icon," ",ae.name]},void 0,!0,void 0,this)},ae.id,!1,void 0,this)}),Ye.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ye.jsxDEV(G,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:Ne,paddingX:1,paddingY:1,children:[ve.length===0&&Ye.jsxDEV(G,{paddingX:2,paddingY:1,justifyContent:"center",children:Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u6682\u65E0\u517C\u5BB9\u7684\u670D\u52A1\u5546\uFF0C\u8BF7\u6DFB\u52A0":"No compatible providers yet"},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.map((ae,Ae)=>Ye.jsxDEV(WT,{provider:ae,focused:Q===Ae,bound:ae.id===We,isDefault:ae.id===u,zh:Ie},ae.id,!1,void 0,this))]},void 0,!0,void 0,this),Ye.jsxDEV(G,{marginTop:1,gap:1,children:[{id:"add",offset:0,icon:"\u2795",label:Ie?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"},{id:"scan",offset:1,icon:"\uD83D\uDD0D",label:Ie?"\u626B\u63CF\u8BA2\u9605":"Scan"},{id:"versions",offset:2,icon:"\uD83D\uDCE6",label:Ie?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"},{id:"back",offset:3,icon:"\u2190",label:Ie?"\u8FD4\u56DE":"Back"}].map((ae)=>{let Ae=Q===ve.length+ae.offset;return Ye.jsxDEV(G,{borderStyle:Ae?"bold":"round",borderColor:Ae?"cyan":"gray",paddingX:2,children:Ye.jsxDEV(I,{bold:Ae,color:Ae?"cyan":void 0,dimColor:!Ae,children:[ae.icon," ",ae.label]},void 0,!0,void 0,this)},ae.id,!1,void 0,this)})},void 0,!1,void 0,this),Ye.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u7ED1\u5B9A":"bind"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"d"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u8BE6\u60C5":"detail"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var an,Ye;var $T=O(async()=>{Mn();bi();Uc();ds();ds();Ru();Or();await ha([Vo(),VT()]);an=ye(ct(),1),Ye=ye($t(),1)});async function ZT(){try{let o=((await tt()).providers??[]).find((m)=>m.type==="tako");if(!o)return{success:!1,error:"\u672A\u914D\u7F6E Tako provider"};if(!o.apiKey)return{success:!1,error:"Tako provider \u7F3A\u5C11 API key\uFF0C\u8BF7\u91CD\u65B0\u914D\u7F6E"};let i=await Hc(o.apiKey);if(!i.valid)return{success:!1,error:i.message};let a=i.apiId,u=await(await fetch(`${xo}/apiStats/api/user-stats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiId:a})})).json(),p=await(await fetch(`${xo}/apiStats/api/user-model-stats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiId:a,period:"daily"})})).json();if(!u.success)return{success:!1,error:u.error||u.message||"\u83B7\u53D6\u7EDF\u8BA1\u5931\u8D25"};let g=(p.data||[]).map((m)=>({model:m.model,requests:m.requests,cost:m.formatted?.total||"$0.00"}));return{success:!0,data:{totalRequests:u.data?.usage?.total?.requests||0,totalCost:u.data?.usage?.total?.formattedCost||"$0.00",todayCost:`$${(u.data?.limits?.currentDailyCost||0).toFixed(2)}`,modelStats:g}}}catch(e){return{success:!1,error:e instanceof Error?e.message:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}}}function eF(e){return e.toLocaleString("en-US")}var tF=O(()=>{on();qf()});function nF({onExit:e}){let[o,i]=Ta.useState(null),[a,s]=Ta.useState(!0),[u,d]=Ta.useState(10),p=Ta.useCallback(async()=>{s(!0);let m=await ZT();if(m.success&&m.data)i(m.data);s(!1)},[]);Ta.useEffect(()=>{p()},[p]),Ta.useEffect(()=>{let m=setInterval(()=>{d((h)=>{if(h<=1)return p(),10;return h-1})},1000);return()=>clearInterval(m)},[p]),Yn((m,h)=>{if(m==="q"||h.escape)e()});let g=ao()==="zh";return Xo.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[Xo.jsxDEV(I,{bold:!0,children:Ge("stats.title")},void 0,!1,void 0,this),a&&!o?Xo.jsxDEV(I,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this):o?Xo.jsxDEV(G,{flexDirection:"column",marginTop:1,children:[Xo.jsxDEV(I,{children:Ge("stats.totalRequests",{count:eF(o.totalRequests)})},void 0,!1,void 0,this),Xo.jsxDEV(I,{children:Ge("stats.totalCost",{cost:o.totalCost})},void 0,!1,void 0,this),Xo.jsxDEV(I,{children:Ge("stats.todayCost",{cost:o.todayCost})},void 0,!1,void 0,this),o.modelStats.length>0&&Xo.jsxDEV(G,{flexDirection:"column",marginTop:1,children:[Xo.jsxDEV(I,{bold:!0,dimColor:!0,children:g?"\u6A21\u578B\u5206\u5E03":"Model Distribution"},void 0,!1,void 0,this),o.modelStats.map((m,h)=>Xo.jsxDEV(I,{dimColor:!0,children:[h===o.modelStats.length-1?"\u2514\u2500":"\u251C\u2500"," ",m.model.padEnd(25)," ",String(m.requests).padStart(5)," ",m.cost]},m.model,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):Xo.jsxDEV(I,{color:"red",children:g?"\u83B7\u53D6\u5931\u8D25":"Failed to load"},void 0,!1,void 0,this),Xo.jsxDEV(G,{marginTop:1,children:Xo.jsxDEV(I,{dimColor:!0,children:g?`${u}s \u540E\u5237\u65B0 q \u8FD4\u56DE`:`Refresh in ${u}s q back`},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ta,Xo;var oF=O(async()=>{Mn();tF();await Vo();Ta=ye(ct(),1),Xo=ye($t(),1)});function SP(e){return e.startsWith("cr_")&&e.length>10}async function xP(e){try{let i=await(await fetch(`${xo}/apiStats/api/get-key-id`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:e})})).json();if(i.success&&i.data?.id)return{valid:!0,apiId:i.data.id};return{valid:!1,error:i.error||Ge("auth.validationFailed")}}catch(o){return{valid:!1,error:o instanceof Error?o.message:Ge("auth.networkError")}}}async function iF(e){if(!SP(e))return $n("api_key_validated",{success:!1,error_type:"invalid_format"}),{success:!1,error:Ge("auth.invalidFormat")};let o=await xP(e);if(!o.valid)return $n("api_key_validated",{success:!1,error_type:"api_validation_failed"}),{success:!1,error:o.error};return await uA({apiKey:e,apiId:o.apiId}),await bP(e,o.apiId),$n("api_key_validated",{success:!0}),wa(),er(),{success:!0}}async function bP(e,o){let a=(await Wo()).find((s)=>s.type==="tako");if(a)await gA(a.id,{apiKey:e,apiId:o});else await fA({name:"Tako \u5B98\u65B9",type:"tako",apiKey:e,baseUrl:xo,apiId:o,supportedClients:ci("tako"),builtin:!0})}var rF=O(()=>{on();Mn();Or();bi();ds()});function ry({isReconfigure:e,onDone:o}){let[i,a]=Ss.useState(""),[s,u]=Ss.useState("idle"),[d,p]=Ss.useState(""),{stdin:g,setRawMode:m}=ml();Ss.useEffect(()=>{if(!g)return;m(!0);let w=(N)=>{let v=N.toString();if(v.length>1&&!v.startsWith("\x1B"))a((S)=>S+v.replace(/[\r\n]/g,""))};return g.on("data",w),()=>{g.off("data",w)}},[g,m]);let h=Ss.useCallback(async()=>{if(!i||s==="validating")return;u("validating");let w=await iF(i);if(w.success)u("success"),wa(),er(),setTimeout(()=>o(!0),500);else u("error"),p(w.error||"Validation failed")},[i,s,o]);Yn((w,N)=>{if(N.escape){o(!1);return}if(N.return){h();return}if(N.backspace||N.delete){a((v)=>v.slice(0,-1)),u("idle");return}if(w&&!N.ctrl&&w.length===1)a((v)=>v+w),u("idle")});let Q=i.length<=6?i:`${i.slice(0,3)}${"\u2022".repeat(Math.min(i.length-6,20))}${i.slice(-3)}`,C=ao()==="zh";return ki.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[ki.jsxDEV(I,{bold:!0,color:"cyan",children:["\uD83D\uDD11 ",e?Ge("prompts.enterApiKey"):"API Key"]},void 0,!0,void 0,this),ki.jsxDEV(G,{marginTop:1,children:[ki.jsxDEV(I,{color:"cyan",bold:!0,children:[">"," "]},void 0,!0,void 0,this),ki.jsxDEV(I,{children:Q},void 0,!1,void 0,this),s==="idle"&&ki.jsxDEV(I,{color:"cyan",children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s==="validating"&&ki.jsxDEV(I,{color:"yellow",children:["\u23F3 ",Ge("prompts.validating")]},void 0,!0,void 0,this),s==="success"&&ki.jsxDEV(I,{color:"green",children:["\u2713 ",Ge("prompts.keyConfigured")]},void 0,!0,void 0,this),s==="error"&&ki.jsxDEV(I,{color:"red",children:["\u2717 ",d]},void 0,!0,void 0,this),ki.jsxDEV(G,{marginTop:1,children:ki.jsxDEV(I,{dimColor:!0,children:["Enter ",C?"\u63D0\u4EA4":"submit"," Esc ",C?"\u53D6\u6D88":"cancel"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ss,ki;var aF=O(async()=>{Mn();rF();Or();await Vo();Ss=ye(ct(),1),ki=ye($t(),1)});function AF({onDone:e}){let[o,i]=sF.useState(Md.findIndex((a)=>a.value===ao()));return Yn((a,s)=>{if(s.upArrow)i((u)=>u>0?u-1:Md.length-1);if(s.downArrow)i((u)=>u<Md.length-1?u+1:0);if(s.return)W0(Md[o].value),e();if(s.escape)e()}),Fa.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[Fa.jsxDEV(I,{bold:!0,children:["\uD83C\uDF10 ",Ge("menu.changeLanguage")]},void 0,!0,void 0,this),Md.map((a,s)=>Fa.jsxDEV(G,{gap:1,marginTop:s===0?1:0,children:[Fa.jsxDEV(I,{color:"cyan",bold:s===o,children:s===o?"\u25B8":" "},void 0,!1,void 0,this),Fa.jsxDEV(I,{bold:s===o,children:a.label},void 0,!1,void 0,this),a.value===ao()&&Fa.jsxDEV(I,{dimColor:!0,children:"\u2190"},void 0,!1,void 0,this)]},a.value,!0,void 0,this)),Fa.jsxDEV(G,{marginTop:1,children:Fa.jsxDEV(I,{dimColor:!0,children:"Enter select Esc back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var sF,Fa,Md;var uF=O(async()=>{Mn();await Vo();sF=ye(ct(),1),Fa=ye($t(),1),Md=[{value:"en",label:"English"},{value:"zh",label:"\u4E2D\u6587"}]});import{join as NP}from"path";async function RP(){try{return await Bun.file(cF).json()}catch{return{}}}async function lF(e){await Bun.write(cF,JSON.stringify(e))}async function dF(){if(await B0())return!1;let e=await RP();if(e.never)return!1;let o=new Date().toISOString().slice(0,10);if(e.dismissed===o)return!1;return!0}async function pF(e){if(e==="never")await lF({never:!0});else{let o=new Date().toISOString().slice(0,10);await lF({dismissed:o})}}function fF({onDone:e}){let[o,i]=Om.useState(0),a=ao()==="zh";return Yn(Om.useCallback((s,u)=>{if(u.upArrow){i((d)=>d>0?d-1:Mm.length-1);return}if(u.downArrow){i((d)=>d<Mm.length-1?d+1:0);return}if(u.escape){e("skip");return}if(u.return){e(Mm[o].id);return}},[o,e])),wn.jsxDEV(G,{flexDirection:"column",paddingX:0,paddingY:1,children:[wn.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[wn.jsxDEV(G,{gap:1,children:[wn.jsxDEV(I,{color:"cyan",bold:!0,children:"\uD83D\uDD11"},void 0,!1,void 0,this),wn.jsxDEV(I,{bold:!0,children:a?"\u914D\u7F6E Tako API Key":"Configure Tako API Key"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wn.jsxDEV(G,{marginTop:1,flexDirection:"column",children:[wn.jsxDEV(I,{dimColor:!0,children:a?"\u914D\u7F6E API Key \u540E\u5373\u53EF\u4F7F\u7528 Tako \u4EE3\u7406\u670D\u52A1\uFF0C\u83B7\u5F97\u7EDF\u4E00\u7684\u914D\u989D\u7BA1\u7406\u548C\u66F4\u5FEB\u7684\u8BBF\u95EE\u901F\u5EA6\u3002":"Configure your API Key to use Tako proxy service with unified quota and faster access."},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u4F60\u4E5F\u53EF\u4EE5\u8DF3\u8FC7\u6B64\u6B65\u9AA4\uFF0C\u76F4\u63A5\u4F7F\u7528\u5176\u4ED6\u670D\u52A1\u5546\u3002":"You can skip this and use other providers instead."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wn.jsxDEV(G,{marginTop:1,flexDirection:"column",children:Mm.map((s,u)=>{let d=u===o;return wn.jsxDEV(G,{paddingLeft:1,gap:1,children:[wn.jsxDEV(I,{color:d?s.color||"white":void 0,bold:d,children:d?"\u25B8":" "},void 0,!1,void 0,this),wn.jsxDEV(I,{bold:d,color:d?s.color||"white":void 0,children:a?s.label.zh:s.label.en},void 0,!1,void 0,this),d&&wn.jsxDEV(I,{dimColor:!0,children:a?s.hint.zh:s.hint.en},void 0,!1,void 0,this)]},s.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wn.jsxDEV(G,{paddingX:2,marginTop:1,justifyContent:"center",gap:2,children:[wn.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u9009\u62E9":"select"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u8DF3\u8FC7":"skip"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Om,wn,cF,Mm;var gF=O(async()=>{on();on();Mn();await Vo();Om=ye(ct(),1),wn=ye($t(),1),cF=NP(Vt,".key-prompt.json");Mm=[{id:"configure",label:{en:"Configure now",zh:"\u73B0\u5728\u914D\u7F6E"},hint:{en:"Enter your Tako API Key",zh:"\u8F93\u5165\u4F60\u7684 Tako API Key"},color:"cyan"},{id:"skip",label:{en:"Not now",zh:"\u7A0D\u540E\u518D\u8BF4"},hint:{en:"Remind me tomorrow",zh:"\u660E\u5929\u518D\u63D0\u9192\u6211"}},{id:"never",label:{en:"Don't ask again",zh:"\u4E0D\u518D\u63D0\u793A"},hint:{en:"You can configure later via c key",zh:"\u4E4B\u540E\u53EF\u4EE5\u6309 c \u968F\u65F6\u914D\u7F6E"}}]});function EF({onDone:e}){let o=lA(),i=ao()==="zh",[a,s]=$o.useState(0),[u,d]=$o.useState(0),[p,g]=$o.useState(0),[m,h]=$o.useState({}),[Q,C]=$o.useState(null),[w,N]=$o.useState(""),v=o[a],S=$o.useCallback(async(pe)=>{h((Ee)=>({...Ee,[pe]:{loading:!0,versions:[],current:null}}));let Qe=o.find((Ee)=>Ee.id===pe);if(!Qe)return;try{let[Ee,ie]=await Promise.all([Zf(Qe.package),tg(Qe)]),Be=Ee.map((we)=>({...we,isCurrent:we.version===ie}));h((we)=>({...we,[pe]:{loading:!1,versions:Be,current:ie}}))}catch(Ee){h((ie)=>({...ie,[pe]:{loading:!1,error:Ee.message,versions:[],current:null}}))}},[o]);$o.useEffect(()=>{if(!v)return;if(!m[v.id])S(v.id)},[a,v?.id]),$o.useEffect(()=>{d(0),g(0)},[a]),$o.useEffect(()=>{if(!w)return;let pe=setTimeout(()=>N(""),3000);return()=>clearTimeout(pe)},[w]);let L=v?m[v.id]:void 0,q=L?.versions??[],ne=$o.useCallback(async(pe)=>{if(!v||Q)return;C(pe);try{await eg(v,pe),N(i?`\u2713 \u5DF2\u5207\u6362\u5230 ${pe}`:`\u2713 Switched to ${pe}`),await S(v.id)}catch(Qe){N(i?`\u2717 \u5B89\u88C5\u5931\u8D25\uFF1A${Qe.message}`:`\u2717 Install failed: ${Qe.message}`)}finally{C(null)}},[v,Q,S,i]);Yn((pe,Qe)=>{if(Q)return;if(Qe.escape||pe==="q"){e();return}if(Qe.leftArrow){s((ie)=>ie>0?ie-1:o.length-1);return}if(Qe.rightArrow){s((ie)=>ie<o.length-1?ie+1:0);return}if(pe==="r"){if(v)S(v.id);return}if(!q.length)return;let Ee=q.length-1;if(Qe.upArrow){d((ie)=>{let Be=Math.max(0,ie-1);if(Be<p)g(Be);return Be});return}if(Qe.downArrow){d((ie)=>{let Be=Math.min(Ee,ie+1);if(Be>=p+ay)g(Be-ay+1);return Be});return}if(Qe.return){let ie=q[u];if(ie&&!ie.isCurrent)ne(ie.version)}});let se=mF[v?.id]?.color||"white",le=q.slice(p,p+ay);return Tt.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Tt.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,children:[Tt.jsxDEV(I,{bold:!0,children:["\uD83D\uDCE6 ",i?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"]},void 0,!0,void 0,this),w&&Tt.jsxDEV(I,{color:w.startsWith("\u2713")?"green":"red",children:[" ",w]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:o.map((pe,Qe)=>{let Ee=mF[pe.id]||{icon:"\u25AA",color:"white"},ie=Qe===a;return Tt.jsxDEV(G,{borderStyle:ie?"bold":"single",borderColor:ie?Ee.color:"gray",paddingX:2,children:Tt.jsxDEV(I,{bold:ie,color:ie?Ee.color:void 0,dimColor:!ie,children:[Ee.icon," ",pe.name]},void 0,!0,void 0,this)},pe.id,!1,void 0,this)})},void 0,!1,void 0,this),Tt.jsxDEV(G,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:se,paddingX:2,paddingY:1,children:!L||L.loading?Tt.jsxDEV(I,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"Loading..."},void 0,!1,void 0,this):L.error?Tt.jsxDEV(I,{color:"red",children:[i?"\u52A0\u8F7D\u5931\u8D25\uFF1A":"Failed: ",L.error]},void 0,!0,void 0,this):q.length===0?Tt.jsxDEV(I,{dimColor:!0,children:i?"\u6682\u65E0\u7248\u672C":"No versions"},void 0,!1,void 0,this):Tt.jsxDEV(G,{flexDirection:"column",children:[Tt.jsxDEV(I,{dimColor:!0,children:[i?`\u5171 ${q.length} \u4E2A\u7248\u672C\uFF0C\u5F53\u524D\u5B89\u88C5\uFF1A`:`${q.length} versions, current: `,Tt.jsxDEV(I,{color:se,children:L.current??(i?"\u672A\u5B89\u88C5":"not installed")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV(G,{marginTop:1,flexDirection:"column",children:le.map((pe,Qe)=>{let ie=p+Qe===u,Be=pe.publishedAt?pe.publishedAt.slice(0,10):"",we=pe.isCurrent?i?" \u2605 \u5F53\u524D":" \u2605 current":"",De=Q===pe.version,Ie=ie?se:pe.isCurrent?"green":void 0;return Tt.jsxDEV(G,{paddingLeft:1,children:Tt.jsxDEV(I,{color:Ie,bold:ie,dimColor:!ie&&!pe.isCurrent,children:[ie?"\u25B6 ":" ",pe.version.padEnd(16),Be.padEnd(14),we,De?i?" \u23F3 \u5B89\u88C5\u4E2D...":" \u23F3 installing...":""]},void 0,!0,void 0,this)},pe.version,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Tt.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u5B89\u88C5":"install"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var $o,Tt,ay=12,mF;var CF=O(async()=>{Uc();Gh();Mn();await Vo();$o=ye(ct(),1),Tt=ye($t(),1),mF={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}}});function TP(e){let o=new Date(e.ts).toISOString().slice(11,19);switch(e.kind){case"session_started":return{dim:!0,text:`[${o}] \u25B6 session_started ${e.backend}`};case"turn_started":return{color:"cyan",text:`[${o}] \u25B6 turn_started`};case"text_delta":return{text:e.text};case"reasoning_delta":return{dim:!0,text:`[${o}] \uD83D\uDCAD ${e.text.slice(0,200)}`};case"tool_use":return{color:"yellow",text:`[${o}] \uD83D\uDD27 ${e.name} ${JSON.stringify(e.input).slice(0,160)}`};case"tool_result":return{color:"green",text:`[${o}] \u2713 result`};case"approval_required":return{color:"magenta",text:`[${o}] \u26A0 approval(${e.approvalType})`};case"turn_completed":return{color:"cyan",text:`[${o}] \u25C0 turn_completed`};case"error":return{color:"red",text:`[${o}] \u2717 ${e.message}`};case"session_closed":return{dim:!0,text:`[${o}] \u23F9 closed`};default:return{text:JSON.stringify(e)}}}function BF({sid:e,onBack:o}){let i=xi()==="zh",[a,s]=mo.useState(null),[u,d]=mo.useState([]),[p,g]=mo.useState(""),[m,h]=mo.useState("idle"),[Q,C]=mo.useState(null),[w,N]=mo.useState([]),v=mo.useRef(0),S=mo.useCallback(async()=>{let se=await Wu(e,IF);if(!se)return;s(se.meta),d(se.log);try{let pe=await(await import("fs/promises")).stat(so(e));v.current=pe.size}catch{v.current=0}},[e]);mo.useEffect(()=>{S()},[S]),mo.useEffect(()=>{let se=!1,le=null,pe=async()=>{if(se)return;try{let Qe=await import("fs/promises"),Ee=await Qe.stat(so(e));if(Ee.size>v.current){let ie=await Qe.open(so(e),"r"),Be=Buffer.alloc(Ee.size-v.current);await ie.read(Be,0,Be.length,v.current),await ie.close(),v.current=Ee.size;let we=[];for(let De of Be.toString("utf-8").split(`
|
|
696
|
+
<%s key={someKey} {...props} />`,je,vt,Zt,vt),He[vt+je]=!0)}if(vt=null,Pe!==void 0&&(i(Pe),vt=""+Pe),d(Oe)&&(i(Oe.key),vt=""+Oe.key),"key"in Oe){Pe={};for(var Mt in Oe)Mt!=="key"&&(Pe[Mt]=Oe[Mt])}else Pe=Oe;return vt&&p(Pe,typeof V==="function"?V.displayName||V.name||"Unknown":V),m(V,vt,Pe,s(),wt,zt)}function Q(V){C(V)?V._store&&(V._store.validated=1):typeof V==="object"&&V!==null&&V.$$typeof===Ee&&(V._payload.status==="fulfilled"?C(V._payload.value)&&V._payload.value._store&&(V._payload.value._store.validated=1):V._store&&(V._store.validated=1))}function C(V){return typeof V==="object"&&V!==null&&V.$$typeof===w}var w=Symbol.for("react.transitional.element"),N=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),q=Symbol.for("react.consumer"),ne=Symbol.for("react.context"),se=Symbol.for("react.forward_ref"),le=Symbol.for("react.suspense"),pe=Symbol.for("react.suspense_list"),Qe=Symbol.for("react.memo"),Ee=Symbol.for("react.lazy"),ie=Symbol.for("react.activity"),Be=Symbol.for("react.client.reference"),we=GA.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,De=Object.prototype.hasOwnProperty,Ie=Array.isArray,Dt=console.createTask?console.createTask:function(){return null};GA={react_stack_bottom_frame:function(V){return V()}};var ce,Ne={},ve=GA.react_stack_bottom_frame.bind(GA,u)(),We=Dt(a(u)),He={};gP.Fragment=v,gP.jsxDEV=function(V,Oe,Pe,je){var wt=1e4>we.recentlyCreatedOwnerStacks++;return h(V,Oe,Pe,je,wt?Error("react-stack-top-frame"):ve,wt?Dt(a(V)):We)}})()});function kT({zh:e}){return mt.jsxDEV(G,{marginTop:0,justifyContent:"center",gap:2,children:mP.flatMap((o,i)=>[i>0?mt.jsxDEV(I,{dimColor:!0,children:"\u2502"},`s${i}`,!1,void 0,this):null,mt.jsxDEV(I,{dimColor:!0,bold:!0,children:o[0]},`k${i}`,!1,void 0,this),mt.jsxDEV(I,{dimColor:!0,children:e?o[1]:o[2]},`l${i}`,!1,void 0,this)])},void 0,!1,void 0,this)}function LT({provs:e,provIdx:o,pickerIdx:i,color:a,zh:s}){return mt.jsxDEV(G,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:a,paddingX:1,paddingY:0,children:[mt.jsxDEV(I,{bold:!0,color:a,children:["\u25A3 ",s?"\u9009\u62E9\u670D\u52A1\u5546":"Pick Provider"]},void 0,!0,void 0,this),mt.jsxDEV(G,{flexDirection:"column",marginTop:0,children:[e.length===0&&mt.jsxDEV(G,{paddingLeft:1,children:mt.jsxDEV(I,{dimColor:!0,children:s?"\u6682\u65E0\u517C\u5BB9\u6B64\u5DE5\u5177\u7684\u670D\u52A1\u5546":"No compatible providers"},void 0,!1,void 0,this)},void 0,!1,void 0,this),e.map((u,d)=>{let p=i===d,g=d===o;return mt.jsxDEV(G,{paddingLeft:1,children:[mt.jsxDEV(I,{color:p?a:void 0,bold:p,children:p?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:p,color:p?a:void 0,children:[" ",u.name]},void 0,!0,void 0,this),u.email&&mt.jsxDEV(I,{dimColor:!0,children:[" (",u.email,")"]},void 0,!0,void 0,this),g&&mt.jsxDEV(I,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},u.id,!0,void 0,this)}),(()=>{let u=i===e.length;return mt.jsxDEV(G,{paddingLeft:1,marginTop:1,children:[mt.jsxDEV(I,{color:u?a:void 0,bold:u,children:u?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:u,color:u?a:void 0,children:[" ","\u2699 ",s?"\u7BA1\u7406\u670D\u52A1\u5546\u2026":"Manage providers\u2026"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)})()]},void 0,!0,void 0,this),mt.jsxDEV(kT,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function MT({group:e,options:o,enabled:i,pickerIdx:a,color:s,zh:u,pickCounts:d={}}){let p=o.filter((Q)=>Q.group===e),g=e==="model"?Cl(p,i,d):{list:p,hiddenCount:0},m=e==="model"?u?"\u9009\u62E9\u6A21\u578B":"Pick Model":e,h=!p.some((Q)=>i.has(Q.id));return mt.jsxDEV(G,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:s,paddingX:1,paddingY:0,children:[mt.jsxDEV(I,{bold:!0,color:s,children:["\u25A3 ",m]},void 0,!0,void 0,this),mt.jsxDEV(G,{flexDirection:"column",marginTop:0,children:[(()=>{let Q=a===0;return mt.jsxDEV(G,{paddingLeft:1,children:[mt.jsxDEV(I,{color:Q?s:void 0,bold:Q,children:Q?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:Q,color:Q?s:void 0,children:[" ",u?"\u9ED8\u8BA4\uFF08\u4E0D\u6307\u5B9A\uFF09":"Default (none)"]},void 0,!0,void 0,this),h&&mt.jsxDEV(I,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),g.list.map((Q,C)=>{let w=a===C+1,N=i.has(Q.id);return mt.jsxDEV(G,{paddingLeft:1,flexDirection:"column",children:[mt.jsxDEV(G,{children:[mt.jsxDEV(I,{color:w?s:void 0,bold:w,children:w?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:w,color:w?s:void 0,children:[" ",Q.label[u?"zh":"en"]||Q.label.en]},void 0,!0,void 0,this),N&&mt.jsxDEV(I,{color:"green",children:" \u2605"},void 0,!1,void 0,this),mt.jsxDEV(I,{dimColor:!0,children:[" ",Q.flag]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),w&&mt.jsxDEV(G,{paddingLeft:3,children:mt.jsxDEV(I,{dimColor:!0,children:Q.description[u?"zh":"en"]||Q.description.en},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},Q.id,!0,void 0,this)}),g.hiddenCount>0&&mt.jsxDEV(G,{paddingLeft:1,children:[mt.jsxDEV(I,{color:a===g.list.length+1?s:void 0,bold:a===g.list.length+1,children:a===g.list.length+1?"\u25B8":" "},void 0,!1,void 0,this),mt.jsxDEV(I,{bold:a===g.list.length+1,color:a===g.list.length+1?s:void 0,children:[" ",u?`\u25BE \u663E\u793A\u5168\u90E8 (${g.hiddenCount})`:`\u25BE Show all (${g.hiddenCount})`]},void 0,!0,void 0,this),mt.jsxDEV(I,{dimColor:!0,children:" \u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),mt.jsxDEV(kT,{zh:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var mt,mP;var OT=O(async()=>{Lm();await Vo();mt=ye($t(),1),mP=[["\u2191\u2193","\u9009\u62E9","select"],["Enter","\u786E\u8BA4","confirm"],["m","\u5F53\u524D\u76EE\u5F55\u542F\u52A8","launch cwd"],["Esc","\u53D6\u6D88","cancel"]]});function EP({zh:e}){return cn.jsxDEV(G,{marginTop:0,justifyContent:"center",gap:2,children:[cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193\u2190\u2192"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u9009\u62E9":"select"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u5F53\u524D\u76EE\u5F55\u542F\u52A8":"launch cwd"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),cn.jsxDEV(I,{dimColor:!0,children:e?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _T({options:e,enabled:o,pickerIdx:i,color:a,zh:s}){let{stdout:u}=El(),d=e.map((C)=>C.id),p=new Map(e.map((C)=>[C.id,C])),g=(C)=>p.get(C)?.label[s?"zh":"en"]||p.get(C)?.label.en||C,m=hl(e,u.columns||80,s),h=Il(d,m),Q=Math.max(ty,...d.length>0?d.map((C)=>UA(g(C))+3):[0]);return cn.jsxDEV(G,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:a,paddingX:1,paddingY:0,children:[cn.jsxDEV(I,{bold:!0,color:a,children:["\u25A3 ",s?"\u9009\u62E9\u6A21\u578B":"Pick Model"]},void 0,!0,void 0,this),cn.jsxDEV(G,{flexDirection:"column",marginTop:0,children:h.groups.map((C,w)=>cn.jsxDEV(G,{flexDirection:"column",marginTop:0,children:[w>0&&cn.jsxDEV(G,{children:cn.jsxDEV(I,{dimColor:!0,children:"\u254C".repeat(Math.max(8,Q*m))},void 0,!1,void 0,this)},void 0,!1,void 0,this),C.rows.map((N,v)=>cn.jsxDEV(G,{children:N.map((S)=>{let q=h.flat.indexOf(S)===i,ne=o.has(S),se=g(S);return cn.jsxDEV(G,{marginRight:1,children:[cn.jsxDEV(I,{color:q?a:void 0,bold:q,children:q?"\u25B8":" "},void 0,!1,void 0,this),cn.jsxDEV(I,{color:q?a:void 0,bold:q,children:xT(se,Q)},void 0,!1,void 0,this),ne&&cn.jsxDEV(I,{color:"green",children:"\u2605"},void 0,!1,void 0,this)]},S,!0,void 0,this)})},`${C.family}-${v}`,!1,void 0,this))]},C.family,!0,void 0,this))},void 0,!1,void 0,this),cn.jsxDEV(EP,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var cn;var UT=O(async()=>{Lm();await Vo();cn=ye($t(),1)});function GT(e,o){if(!e||o.ctrl||o.meta)return"";return e.replace(/[\x00-\x1f\x7f]/g,"")}function zT(e){return e.replace(/```[\s\S]*?```/g," [code] ").replace(/[`*_#>|]/g,"").replace(/\s+/g," ").trim()}function hP(e,o){let i=Math.max(0,Date.now()-e);if(i<3600000)return`${Math.max(1,Math.floor(i/60000))}${o?"\u5206\u949F\u524D":"m"}`;if(i<86400000)return`${Math.floor(i/3600000)}${o?"\u5C0F\u65F6\u524D":"h"}`;return`${Math.floor(i/86400000)}${o?"\u5929\u524D":"d"}`}function IP(e){if(e==="claude")return"Claude";if(e==="codex")return"Codex";if(e==="pi")return"Pi";return"Gemini"}function BP(e){if(e==="claude")return"magenta";if(e==="codex")return"blue";if(e==="pi")return"magenta";return"cyan"}function yP(e,o){let i=Math.floor(Math.max(0,Date.now()-e)/86400000);if(i===0)return o?"\u4ECA\u5929":"Today";if(i===1)return o?"\u6628\u5929":"Yesterday";if(i<7)return o?"\u672C\u5468":"This week";return o?"\u66F4\u65E9":"Earlier"}function JT({color:e}){let{stdout:o}=El(),i=Math.max((o.columns||80)-6,20);return H.jsxDEV(G,{marginY:0,children:H.jsxDEV(I,{dimColor:!0,color:e,children:"\u2500".repeat(i)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function DP(e){return e>30?"green":e>10?"yellow":"red"}function QP({provider:e,zh:o}){if(!e)return H.jsxDEV(I,{color:"yellow",children:["\u26A0 ",o?"\u672A\u7ED1\u5B9A":"no provider"]},void 0,!0,void 0,this);let i={tako:{zh:"Tako \u4EE3\u7406",en:"Tako Proxy",color:"cyan",icon:"\uD83D\uDC19"},"claude-subscription":{zh:"Claude \u5B98\u65B9",en:"Claude Official",color:"yellow",icon:"\u2726"},"codex-subscription":{zh:"Codex \u5B98\u65B9",en:"Codex Official",color:"blue",icon:"\u25C8"},anthropic:{zh:"Anthropic \u76F4\u8FDE",en:"Anthropic Direct",color:"yellow",icon:"\u2726"},deepseek:{zh:"DeepSeek",en:"DeepSeek",color:"magenta",icon:"\u25C7"},xiaomi:{zh:"\u5C0F\u7C73 MiMo",en:"Xiaomi MiMo",color:"yellow",icon:"\uD83D\uDFE0"},custom:{zh:"\u81EA\u5B9A\u4E49",en:"Custom",color:"gray",icon:"\u25AA"}},a=i[e.type]??i.custom,s=o?a.zh:a.en,u=e.email??"";if(u.length>0){let[d,p]=u.split("@");if(d&&p)u=d.length>14?`${d.slice(0,12)}\u2026@${p}`:u}return H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{color:a.color,children:[a.icon," ",s]},void 0,!0,void 0,this),u&&H.jsxDEV(I,{dimColor:!0,children:[" \xB7 ",u]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function wP({quota:e,zh:o}){if(e.status==="unsupported")return null;if(e.status==="error")return H.jsxDEV(I,{dimColor:!0,children:["\uD83D\uDCB0 ",e.hint||(o?"\u7528\u91CF\u83B7\u53D6\u5931\u8D25":"quota unavailable")]},void 0,!0,void 0,this);if(e.provider==="tako")if(!!(e.primary?.costLimit||e.secondary?.costLimit||e.daily?.costLimit));else{let p=e.daily??e.primary??e.secondary;if(!p)return null;let g=p.costUsed??0;return H.jsxDEV(I,{dimColor:!0,children:["\uD83D\uDCB0 ",o?"\u4ECA\u65E5":"Today",": ",H.jsxDEV(I,{color:"green",children:["$",g.toFixed(2)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}let i=(d,p,g)=>{if(d&&d>=1440)return`${Math.round(d/1440)}d`;if(d)return`${Math.round(d/60)}h`;return g?`${g}d`:`${p}h`},a=(d)=>Math.max(0,Math.min(100,100-Math.round(d))),s=[],u=(d,p,g)=>{if(s.length)s.push(H.jsxDEV(I,{dimColor:!0,children:" \xB7 "},`sep-${d}`,!1,void 0,this));let m=a(g);s.push(H.jsxDEV(et.default.Fragment,{children:[`${p} \u5269 `,H.jsxDEV(I,{color:DP(m),children:[m,"%"]},void 0,!0,void 0,this)]},d,!0,void 0,this))};if(e.primary)u("primary",i(e.primary.windowMinutes,5),e.primary.usedPct);if(e.secondary)u("secondary",i(e.secondary.windowMinutes,24,7),e.secondary.usedPct);if(e.modelLimits?.opus)u("opus","opus",e.modelLimits.opus.usedPct);if(!s.length)return null;return H.jsxDEV(I,{dimColor:!0,children:["\uD83D\uDCB0 ",s]},void 0,!0,void 0,this)}function vP({clients:e,defaultIdx:o,hasProviders:i,pickCounts:a,initialSessionSearch:s=!1,onResult:u}){let{stdout:d}=El(),[p,g]=et.useState(o),[m,h]=et.useState(s?"search":"projects"),[Q,C]=et.useState(0),[w,N]=et.useState(0),[v,S]=et.useState(()=>e[o]?.activeProvIdx||0),[L,q]=et.useState(()=>new Set(e[o]?.lastSelectedOptionIds??[])),[ne,se]=et.useState(""),[le,pe]=et.useState(null),[Qe,Ee]=et.useState("collapsed"),[ie,Be]=et.useState(!1),[we,De]=et.useState(0),[Ie,Dt]=et.useState(""),[ce,Ne]=et.useState(""),[ve,We]=et.useState(0),He=et.useRef(0),[V,Oe]=et.useState(null),Pe=et.useRef(null),[je,wt]=et.useState(null),[zt,vt]=et.useState(0),[Zt,Mt]=et.useState(!1),[ae,Ae]=et.useState(""),[X,de]=et.useState(null),[Ke,_e]=et.useState(null),Xe=Math.max(2,Math.min((d.columns||80)<100?4:6,Math.floor(((d.rows||30)-12)/2))),[yt,St]=et.useState(Xe),Ue=et.useRef(!0),bt=e[p],Ot=bt.projects,en=bt.providers,Jt=HT[bt.client.id]||PT,ke=ao()==="zh",In=en[v],ur=et.default.useMemo(()=>je?yg(je,ce,{currentCwd:Ot[0]?.path,limit:yt+1}):[],[je,ce,zt,Ot,yt]),Ho=ur.length>yt,_t=et.default.useMemo(()=>ur.slice(0,yt),[ur,yt]),ei=Math.max(0,Math.min(ve-Xe+1,Math.max(0,_t.length-Xe))),lr=_t.slice(ei,ei+Xe);et.useEffect(()=>{let b=Dg(),U=!1;wt(b),Mt(!0),Ae("");let j=td(b).then(()=>{if(!U)vt((W)=>W+1)}).catch((W)=>{if(!U)Ae(W instanceof Error?W.message:String(W))}).finally(()=>{if(!U)Mt(!1)});return()=>{U=!0,wt(null),j.finally(()=>b.close())}},[]),et.useEffect(()=>{if(!Ie){Ne("");return}let b=setTimeout(()=>Ne(Ie),120);return()=>clearTimeout(b)},[Ie]),et.useEffect(()=>{St((b)=>Math.max(b,Xe)),We((b)=>{let U=Math.max(0,Math.min(b,yt-1));return He.current=U,U})},[Xe,yt]),et.useEffect(()=>{if(_t.length===0){He.current=0,Pe.current=null,We(0),Oe(null);return}let b=Pe.current?_t.findIndex((W)=>W.session.key===Pe.current):-1,U=b>=0?b:Math.min(He.current,_t.length-1),j=_t[U].session.key;He.current=U,Pe.current=j,We(U),Oe(j)},[_t]),et.useEffect(()=>{if(!je||!X){_e(null);return}let b=je.getSession(X),U=je.getRecentMessages(X,32).filter((j)=>j.role==="user"||j.role==="assistant").slice(-8);_e(b?{session:b,messages:U}:null)},[je,X]);let Kt=et.default.useMemo(()=>bu(bt.client,In),[bt.client.id,In?.id,In?.type]),Tn=et.default.useMemo(()=>DT(Kt,ke),[Kt,ke]),uo=In?.name||(ke?"\u672A\u914D\u7F6E":"N/A"),[sn,ti]=et.useState(null);et.useEffect(()=>{if(!In){ti(null);return}let b=!1;return zc(In).then((U)=>{if(!b)ti(U)}),()=>{b=!0}},[In?.id,In?.type]),et.useEffect(()=>{if(Ue.current){Ue.current=!1;return}C(0),N(0),h("projects"),S(e[p]?.activeProvIdx||0),pe(null),Ee("collapsed"),Be(!1),q(new Set(e[p]?.lastSelectedOptionIds??[]))},[p]),et.useEffect(()=>{q((b)=>Tm(b,Kt,In?.model,bt.client.id==="pi"?`model-${IA}`:void 0))},[Kt,In?.model]);let to=et.useCallback((b)=>{let U=kd(Kt,L,b),j=Kt.filter((me)=>me.group===b);if(j.length===0)return;let W=b==="model"?ny(j,a):"collapsed",ge=0;if(U)if(b==="model"&&W==="grid"){let me=j.map((Le)=>Le.id),rt=hl(j,d.columns||80,ke);ge=oy(me,U.id,rt)}else ge=(b==="model"?Cl(j,L,a).list:j).findIndex((rt)=>rt.id===U.id)+1;De(Math.max(0,ge)),Ee(W),pe(b)},[L,Kt,a,d.columns,ke]),B=et.useCallback((b)=>{let U=QT({launchOptions:Kt,enabled:L},"model",b);u({type:"launch",clientId:bt.client.id,projectPath:Ot[0]?.path,...U})},[Kt,L,u,bt.client.id,Ot]);return Yn(et.useCallback((b,U)=>{if(ie){let W=en.length+1;if(U.escape||b==="q"){Be(!1);return}if(U.upArrow){De((ge)=>ge>0?ge-1:W-1);return}if(U.downArrow){De((ge)=>ge<W-1?ge+1:0);return}if(U.return)if(we<en.length){let ge=en[we];S(we),(async()=>{if(await bc(bt.client.id,ge.id),bt.client.setupConfigFiles)try{await bt.client.setupConfigFiles(jo(ge))}catch(me){se(ke?"\u26A0 \u914D\u7F6E\u540C\u6B65\u5931\u8D25":"\u26A0 Config sync failed"),setTimeout(()=>se(""),2500);return}bt.activeProvIdx=we,se(ke?`\u2713 \u5DF2\u7ED1\u5B9A ${ge.name}`:`\u2713 Bound ${ge.name}`),setTimeout(()=>se(""),2000)})(),Be(!1)}else Be(!1),u({type:"providers"});return}if(le){let W=Kt.filter((Le)=>Le.group===le),ge=le==="model";if(ge&&Qe==="grid"){let Le=W.map((Ut)=>Ut.id),Yt=hl(W,d.columns||80,ke),Ft=Il(Le,Yt),Wn=FT(Le,Yt),Eo=Ft.flat.length;if(b==="q"){pe(null),Ee("collapsed");return}if(b==="m"){let Ut=Ft.flat[we];B(Ut);return}if(U.escape){if(ny(W,a)==="grid")pe(null);else{Ee("collapsed");let Ut=kd(Kt,L,le),dn=Cl(W,L,a).list;De(Ut?Math.max(0,dn.findIndex((No)=>No.id===Ut.id)+1):0)}return}if(Eo===0)return;if(U.leftArrow){De((Ut)=>Ut>0?Ut-1:Eo-1);return}if(U.rightArrow){De((Ut)=>Ut<Eo-1?Ut+1:0);return}if(U.upArrow||U.downArrow){De((Ut)=>{let dn=0,No=0,gi=0;for(let jn=0;jn<Wn.length;jn++){let Oi=Wn[jn].length;if(Ut<gi+Oi){dn=jn,No=Ut-gi;break}gi+=Oi}let Gt=U.upArrow?dn>0?dn-1:Wn.length-1:dn<Wn.length-1?dn+1:0,Mi=Math.min(No,Wn[Gt].length-1);return Wn.slice(0,Gt).reduce((jn,Oi)=>jn+Oi.length,0)+Mi});return}if(U.return){let Ut=Ft.flat[we],dn=W.find((No)=>No.id===Ut);if(dn)q((No)=>{let gi=new Set(No);for(let Gt of W)gi.delete(Gt.id);return gi.add(dn.id),gi});pe(null),Ee("collapsed")}return}let me=ge?Cl(W,L,a):{list:W,hiddenCount:0},rt=me.list.length+1+(me.hiddenCount>0?1:0);if(U.escape||b==="q"){pe(null),Ee("collapsed");return}if(ge&&b==="m"){if(we===0){B();return}if(me.hiddenCount>0&&we===me.list.length+1)return;let Le=me.list[we-1];B(Le?.id);return}if(U.upArrow){De((Le)=>Le>0?Le-1:rt-1);return}if(U.downArrow){De((Le)=>Le<rt-1?Le+1:0);return}if(U.return){if(we===0)q((Le)=>{let Yt=new Set(Le);for(let Ft of W)Yt.delete(Ft.id);return Yt});else if(ge&&me.hiddenCount>0&&we===me.list.length+1){let Le=kd(Kt,L,le),Yt=W.map((Eo)=>Eo.id),Ft=hl(W,d.columns||80,ke),Wn=Le?oy(Yt,Le.id,Ft):0;De(Math.max(0,Wn)),Ee("grid");return}else{let Le=me.list[we-1];q((Yt)=>{let Ft=new Set(Yt);for(let Wn of W)Ft.delete(Wn.id);return Ft.add(Le.id),Ft})}pe(null),Ee("collapsed")}return}if(m==="search"){if(X&&(U.escape||U.leftArrow)){de(null);return}if(U.escape||U.leftArrow){Dt(""),He.current=0,Pe.current=null,We(0),Oe(null),h("projects");return}if(U.rightArrow){let ge=_t.find((me)=>me.session.key===Pe.current)??_t[He.current];if(ge)de(ge.session.key);return}if(U.downArrow){if(_t.length===0)return;if(He.current>=_t.length-1&&Ho)St((ge)=>ge+Xe),He.current+=1,We(He.current);else He.current=Math.min(_t.length-1,He.current+1),We(He.current);Pe.current=_t[He.current]?.session.key??null,Oe(Pe.current);return}if(U.upArrow){He.current=Math.max(0,He.current-1),We(He.current),Pe.current=_t[He.current]?.session.key??null,Oe(Pe.current);return}if(U.backspace||U.delete){Dt((ge)=>ge.slice(0,-1)),He.current=0,Pe.current=null,We(0),Oe(null),de(null),St(Xe);return}if(U.return){let ge=_t.find((me)=>me.session.key===Pe.current)??_t[He.current];if(!ge)return;if(ge.session.resumeCapability==="unsupported"){de(ge.session.key);return}try{let me=fI(ge.session,Ot[0]?.path);u({type:"launch",clientId:me.clientId,projectPath:me.projectPath,args:me.args,envVars:{},selectedOptionIds:[]})}catch(me){Ae(me instanceof Error?me.message:String(me))}return}let W=GT(b,U);if(W)Dt((ge)=>ge+W),He.current=0,Pe.current=null,We(0),Oe(null),de(null),St(Xe);return}if(b==="q"){u({type:"exit"});return}if(b==="a"){u({type:"agent"});return}if(b==="s"){u({type:"stats"});return}if(b==="c"){u({type:"config"});return}if(b==="l"){u({type:"language"});return}if(b==="p"){u({type:"providers"});return}if(b==="m"){to("model");return}let j=parseInt(b);if(j>=1&&j<=e.length){g(j-1);return}if(U.leftArrow){g((W)=>W>0?W-1:e.length-1);return}if(U.rightArrow){g((W)=>W<e.length-1?W+1:0);return}if(m==="projects"){if(U.downArrow){if(Q<Ot.length-1)C((W)=>W+1);else if(Tn.length>0)h("options"),N(0);return}if(U.upArrow){if(Q>0)C((W)=>W-1);else He.current=0,Pe.current=_t[0]?.session.key??null,We(0),Oe(Pe.current),St(Xe),de(null),h("search");return}}if(m==="options"){if(U.downArrow){if(w<Tn.length-1)N((W)=>W+1);return}if(U.upArrow){if(w>0)N((W)=>W-1);else h("projects"),C(Ot.length-1);return}}if(b===" "&&m==="options"&&Tn.length>0){let W=Tn[w];if(W.kind==="flag")q((ge)=>{let me=new Set(ge);if(me.has(W.opt.id))me.delete(W.opt.id);else me.add(W.opt.id);return me});else if(W.kind==="group")to(W.group);else De(v),Be(!0);return}if(U.return){if(m==="options"&&Tn.length>0){let me=Tn[w];if(me.kind==="group"){to(me.group);return}if(me.kind==="provider"){De(v),Be(!0);return}}let W=Ot[Q],ge=Rm({launchOptions:Kt,enabled:L});u({type:"launch",clientId:bt.client.id,projectPath:W.path,...ge})}},[m,p,Q,w,v,en,In,bt,Ot,Kt,Tn,L,e,u,ke,le,ie,we,a,Qe,d.columns,to,B,Ie,ve,V,_t,X,yt,Xe,Ho])),H.jsxDEV(G,{flexDirection:"column",paddingX:0,paddingY:0,children:[H.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:m==="search"?"cyan":Jt.color,paddingX:1,paddingY:0,children:[H.jsxDEV(G,{justifyContent:"space-between",children:[H.jsxDEV(G,{gap:1,children:[H.jsxDEV(I,{bold:!0,children:"\uD83D\uDC19 Tako"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:["v",CP]},void 0,!0,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(QP,{provider:In,zh:ke},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(G,{children:[ne&&H.jsxDEV(I,{color:"green",children:ne},void 0,!1,void 0,this),!ne&&sn&&H.jsxDEV(wP,{quota:sn,zh:ke},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!i&&H.jsxDEV(G,{marginTop:1,justifyContent:"center",gap:1,children:[H.jsxDEV(I,{color:"yellow",children:"\u26A0"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u672A\u914D\u7F6E\u670D\u52A1\u5546 \u2014 \u6309 c \u6DFB\u52A0 API Key \u6216 p \u7BA1\u7406\u670D\u52A1\u5546":"No provider configured \u2014 press c for API Key or p to manage"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m!=="search"&&H.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:[H.jsxDEV(I,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),e.map((b,U)=>{let j=HT[b.client.id]||PT;return U===p?H.jsxDEV(G,{borderStyle:"bold",borderColor:j.color,paddingX:1,children:H.jsxDEV(I,{color:j.color,bold:!0,children:[j.icon," ",b.client.name]},void 0,!0,void 0,this)},b.client.id,!1,void 0,this):H.jsxDEV(G,{borderStyle:"single",borderColor:"gray",paddingX:1,children:H.jsxDEV(I,{dimColor:!0,children:[j.icon," ",b.client.name]},void 0,!0,void 0,this)},b.client.id,!1,void 0,this)}),H.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m!=="search"&&H.jsxDEV(JT,{color:Jt.color},void 0,!1,void 0,this),ie?H.jsxDEV(LT,{provs:en,provIdx:v,pickerIdx:we,color:Jt.color,zh:ke},void 0,!1,void 0,this):le==="model"&&Qe==="grid"?H.jsxDEV(_T,{options:Kt.filter((b)=>b.group==="model"),enabled:L,pickerIdx:we,color:Jt.color,zh:ke},void 0,!1,void 0,this):le?H.jsxDEV(MT,{group:le,options:Kt,enabled:L,pickerIdx:we,color:Jt.color,zh:ke,pickCounts:a},void 0,!1,void 0,this):H.jsxDEV(H.Fragment,{children:[m==="search"?H.jsxDEV(G,{borderStyle:"round",borderColor:"cyan",paddingX:1,flexDirection:"column",marginTop:1,marginBottom:1,children:[H.jsxDEV(G,{justifyContent:"space-between",children:[H.jsxDEV(I,{color:"cyan",bold:!0,children:["\u2315 ",ke?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD":"Search sessions"]},void 0,!0,void 0,this),Zt&&H.jsxDEV(I,{dimColor:!0,children:ke?"\u7D22\u5F15\u4E2D...":"indexing..."},void 0,!1,void 0,this),!Zt&&ae&&H.jsxDEV(I,{color:"red",children:["\u26A0 ",Fm(ae,Math.max(16,(d.columns||80)-48))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(G,{children:[H.jsxDEV(I,{color:"cyan",bold:!0,children:"\u203A "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:!!Ie,dimColor:!Ie,children:Ie||(ke?"\u8F93\u5165\u5173\u952E\u8BCD\uFF0C\u7559\u7A7A\u6D4F\u89C8\u6700\u8FD1\u4F1A\u8BDD":"Type to search, or browse recent sessions")},void 0,!1,void 0,this),H.jsxDEV(I,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(I,{children:" \u2315 "},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD...":"Search previous sessions..."},void 0,!1,void 0,this),Zt&&H.jsxDEV(I,{dimColor:!0,children:[" ",ke?"\u7D22\u5F15\u4E2D":"indexing"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X&&Ke?H.jsxDEV(G,{paddingLeft:2,flexDirection:"column",children:[H.jsxDEV(I,{bold:!0,color:"cyan",children:Ke.session.title??X},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:Ke.session.cwd},void 0,!1,void 0,this),Ke.session.resumeCapability==="unsupported"&&H.jsxDEV(I,{color:"yellow",children:ke?"\u6B64\u6765\u6E90\u6682\u4E0D\u652F\u6301\u76F4\u63A5\u7EED\u63A5\uFF0C\u4EC5\u53EF\u641C\u7D22\u548C\u67E5\u770B\u3002":"This source is view-only and cannot be resumed yet."},void 0,!1,void 0,this),Ke.messages.map((b)=>H.jsxDEV(I,{children:[H.jsxDEV(I,{color:b.role==="user"?"yellow":"green",children:[b.role==="user"?"You":"AI",": "]},void 0,!0,void 0,this),b.text.replace(/\s+/g," ").slice(0,Math.max(40,(d.columns||80)-12))]},b.ordinal,!0,void 0,this))]},void 0,!0,void 0,this):m==="search"?lr.map((b,U)=>{let W=ei+U===ve,ge=BP(b.session.source),me=yP(b.session.updatedAt,ke),rt=Math.max(30,(d.columns||80)-14);return H.jsxDEV(et.default.Fragment,{children:H.jsxDEV(G,{paddingLeft:1,flexDirection:"column",children:[H.jsxDEV(G,{children:[H.jsxDEV(I,{color:W?"cyan":void 0,bold:W,children:W?"\u25B8 ":" "},void 0,!1,void 0,this),H.jsxDEV(I,{color:"cyan",children:me},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:" \xB7 "},void 0,!1,void 0,this),H.jsxDEV(I,{color:ge,bold:!0,children:IP(b.session.source)},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:[" \xB7 ",b.session.projectName??"\u672A\u77E5\u9879\u76EE"," \xB7 ",hP(b.session.updatedAt,ke)," "]},void 0,!0,void 0,this),H.jsxDEV(I,{bold:W,color:W?"white":void 0,children:Fm(zT(b.session.title??b.session.nativeId.slice(0,8)),Math.max(12,rt-36))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(I,{dimColor:!0,children:[" ",Fm(zT(b.snippet),rt)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},b.session.key,!1,void 0,this)}).concat([H.jsxDEV(G,{paddingLeft:4,marginTop:1,children:H.jsxDEV(I,{dimColor:!0,children:[_t.length===0?ke?"\u6682\u65E0\u4F1A\u8BDD":"No sessions":`${ei+1}-${Math.min(ei+Xe,_t.length)} / ${_t.length}${Ho?"+":""}`,Ho?` \xB7 \u2193 ${ke?"\u7EE7\u7EED\u6D4F\u89C8":"more"}`:""]},void 0,!0,void 0,this)},"session-window-status",!1,void 0,this)]):Ot.map((b,U)=>{let j=m==="projects"&&U===Q;return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:b.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b.hint?H.jsxDEV(I,{dimColor:!0,children:b.hint},void 0,!1,void 0,this):null]},U,!0,void 0,this)}),m!=="search"&&Tn.length>0&&H.jsxDEV(H.Fragment,{children:[H.jsxDEV(JT,{color:Jt.color},void 0,!1,void 0,this),Tn.map((b,U)=>{let j=m==="options"&&U===w;if(b.kind==="flag"){let W=b.opt,ge=L.has(W.id);return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{color:ge?Jt.color:void 0,bold:ge,children:ge?"\u25C9":"\u25CB"},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:W.label[ke?"zh":"en"]||W.label.en},void 0,!1,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:W.flag},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:W.description[ke?"zh":"en"]||W.description.en},void 0,!1,void 0,this)]},W.id,!0,void 0,this)}if(b.kind==="group"){let W=kd(Kt,L,b.group),ge=W?W.shortLabel:ke?"\u9ED8\u8BA4":"Default";return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:[b.title,":"]},void 0,!0,void 0,this),H.jsxDEV(I,{color:W?Jt.color:void 0,children:ge},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:ke?"Enter \u8FDB\u5165\u9009\u62E9":"Enter to pick"},void 0,!1,void 0,this)]},`group-${b.group}`,!0,void 0,this)}return H.jsxDEV(G,{paddingLeft:1,children:[H.jsxDEV(G,{flexGrow:1,gap:1,children:[H.jsxDEV(I,{color:j?Jt.color:void 0,bold:j,children:j?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(I,{bold:j,color:j?Jt.color:void 0,children:[b.title,":"]},void 0,!0,void 0,this),H.jsxDEV(I,{color:In?Jt.color:"yellow",children:In?uo:ke?"\u672A\u914D\u7F6E":"Not set"},void 0,!1,void 0,this),H.jsxDEV(I,{color:"yellow",children:"\u2605"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&H.jsxDEV(I,{dimColor:!0,children:ke?"Enter \u5207\u6362\u6216\u7BA1\u7406":"Enter to switch / manage"},void 0,!1,void 0,this)]},"provider-entry",!0,void 0,this)})]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(G,{paddingX:2,marginTop:0,justifyContent:"center",gap:2,children:m==="search"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:_t[ve]?.session.resumeCapability==="unsupported"?ke?"\u67E5\u770B":"open":ke?"\u7EED\u63A5":"resume"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2192"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u67E5\u770B":"details"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):m==="options"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Space"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u5F00\u5173":"toggle"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9000\u51FA":"quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(H.Fragment,{children:[H.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"a"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"agent"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"p"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u670D\u52A1\u5546":"service"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"s"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u7EDF\u8BA1":"stats"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:ke?"\u9000\u51FA":"quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function KT({onResult:e,initialSessionSearch:o=!1}){let[i,a]=et.useState(null);if(et.useEffect(()=>{wT(45).then(a)},[]),!i)return H.jsxDEV(I,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this);return H.jsxDEV(vP,{clients:i.clients,defaultIdx:i.defaultIdx,hasProviders:i.hasProviders,pickCounts:i.pickCounts,initialSessionSearch:o,onResult:e},void 0,!1,void 0,this)}var et,H,CP="0.3.39",HT,PT;var YT=O(async()=>{zn();_c();bi();Mn();Vf();vT();Lm();dI();gI();await ha([Vo(),OT(),UT()]);et=ye(ct(),1),H=ye($t(),1),HT={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},PT={icon:"\u25AA",color:"white"}});function WT({provider:e,focused:o,bound:i,isDefault:a,zh:s}){let u=Wr[e.type]||Wr.custom,d=s?Si[e.type]?.zh:Si[e.type]?.en;return fe.jsxDEV(G,{flexDirection:"column",borderStyle:o?"bold":"round",borderColor:o?u.color:i?u.color:"gray",paddingX:2,paddingY:0,children:[fe.jsxDEV(G,{justifyContent:"space-between",children:[fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:o||i,color:o?u.color:void 0,children:e.name},void 0,!1,void 0,this),a&&fe.jsxDEV(I,{color:"yellow",children:["\u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this),e.builtin&&fe.jsxDEV(I,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{gap:1,children:i?fe.jsxDEV(I,{color:u.color,bold:!0,children:["\u25CF ",s?"\u5DF2\u7ED1\u5B9A":"bound"]},void 0,!0,void 0,this):fe.jsxDEV(I,{dimColor:!0,children:["\u25CB ",s?"\u672A\u7ED1\u5B9A":"unbound"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:d},void 0,!1,void 0,this),e.model&&fe.jsxDEV(I,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.model&&fe.jsxDEV(I,{dimColor:!0,children:e.model},void 0,!1,void 0,this),e.email&&fe.jsxDEV(I,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.email&&fe.jsxDEV(I,{dimColor:!0,children:e.email},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(I,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(I,{dimColor:!0,children:["Key: ",e.apiKey.slice(0,8),"\u2022\u2022\u2022"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),o&&fe.jsxDEV(G,{marginTop:0,children:fe.jsxDEV(I,{color:u.color,dimColor:!0,children:["Enter ",s?"\u7ED1\u5B9A\u5230\u5F53\u524D\u5DE5\u5177":"bind to this tool"," \xB7 d ",s?"\u8BE6\u60C5/\u64CD\u4F5C":"detail/actions"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function jT({screen:e,addType:o,addKey:i,addUrl:a,addModel:s,addCtx:u,rowIdx:d,zh:p}){let g=Wr[o]||Wr.custom,m=p?Si[o]?.zh:Si[o]?.en,h=e==="add-model"?xc(o):void 0;if(h)return fe.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(G,{borderStyle:"bold",borderColor:g.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,marginBottom:1,children:[fe.jsxDEV(I,{color:g.color,bold:!0,children:g.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:!0,color:g.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:["\u2014 ",p?"\u9009\u62E9\u6A21\u578B":"Select Model"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h.map((v,S)=>{let L=d===S;return fe.jsxDEV(G,{paddingLeft:1,gap:1,children:[fe.jsxDEV(I,{color:L?g.color:void 0,bold:L,children:L?"\u25B8":" "},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:L,color:L?g.color:void 0,children:v},void 0,!1,void 0,this)]},v,!0,void 0,this)})]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u53D6\u6D88":"cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);let Q=e==="add-key"?p?"\u8F93\u5165 API Key":"Enter API Key":e==="add-url"?"Base URL":e==="add-ctx"?p?"\u4E0A\u4E0B\u6587\u7A97\u53E3\uFF08tokens\uFF0C\u53EF\u7559\u7A7A\uFF09":"Context Window (tokens, optional)":p?"\u6A21\u578B":"Model",C=e==="add-key"?i:e==="add-url"?a:e==="add-ctx"?u??"":s,w=e==="add-url"?"https://your-proxy.com":e==="add-ctx"?p?"\u5982 200000\uFF1Bcatalog \u6CA1\u6709\u8BE5\u6A21\u578B\u65F6\u5EFA\u8BAE\u586B\u5199":"e.g. 200000; recommended if model is unknown to catalog":e==="add-model"?Fu(o)||(p?"\u7559\u7A7A\u4F7F\u7528\u9ED8\u8BA4":"leave empty"):void 0,N=e==="add-url"?p?"\u4E0B\u4E00\u6B65":"next":e==="add-ctx"?p?"\u4FDD\u5B58":"save":e==="add-model"?p?"\u4FDD\u5B58":"save":p?"\u786E\u8BA4":"confirm";return fe.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(G,{borderStyle:"bold",borderColor:g.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,marginBottom:1,children:[fe.jsxDEV(I,{color:g.color,bold:!0,children:g.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:!0,color:g.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:["\u2014 ",Q]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e==="add-key"&&o==="xiaomi"&&fe.jsxDEV(I,{dimColor:!0,children:[" ",p?"sk- \u5F00\u5934\u8D70\u6309\u91CF\u4ED8\u8D39\uFF0Ctp- \u5F00\u5934\u8D70 Token Plan \u8BA2\u9605\uFF08\u81EA\u52A8\u8BC6\u522B\uFF09":"sk- = pay-as-you-go, tp- = Token Plan subscription (auto-detected)"]},void 0,!0,void 0,this),w&&fe.jsxDEV(I,{dimColor:!0,children:[" ",p?"\u9ED8\u8BA4":"Default",": ",w]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:w?1:0,children:[fe.jsxDEV(I,{color:g.color,bold:!0,children:["\u203A"," "]},void 0,!0,void 0,this),fe.jsxDEV(I,{children:C||w||""},void 0,!1,void 0,this),fe.jsxDEV(I,{color:g.color,children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:N},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:p?"\u53D6\u6D88":"cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qT({provider:e,defaultId:o,detailActions:i,detailIdx:a,zh:s}){let u=Wr[e.type]||Wr.custom,d=s?Si[e.type]?.zh:Si[e.type]?.en;return fe.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(G,{borderStyle:"bold",borderColor:u.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(I,{bold:!0,color:u.color,children:e.name},void 0,!1,void 0,this),e.id===o&&fe.jsxDEV(I,{color:"yellow",children:[" \u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{marginTop:1,flexDirection:"column",children:[fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:[s?"\u7C7B\u578B":"Type",":"]},void 0,!0,void 0,this),fe.jsxDEV(I,{children:d},void 0,!1,void 0,this),e.builtin&&fe.jsxDEV(I,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.model&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:[s?"\u6A21\u578B":"Model",":"]},void 0,!0,void 0,this),fe.jsxDEV(I,{children:e.model},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.email&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:"Email:"},void 0,!1,void 0,this),fe.jsxDEV(I,{children:e.email},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.apiKey&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:"Key:"},void 0,!1,void 0,this),fe.jsxDEV(I,{children:[e.apiKey.slice(0,12),"\u2022\u2022\u2022"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e.baseUrl&&fe.jsxDEV(G,{gap:1,children:[fe.jsxDEV(I,{dimColor:!0,children:"URL:"},void 0,!1,void 0,this),fe.jsxDEV(I,{children:e.baseUrl},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(G,{gap:1,marginTop:1,children:i.map((p,g)=>{let m=p==="default"?`\u2B50 ${s?"\u8BBE\u4E3A\u9ED8\u8BA4":"Set Default"}`:p==="rekey"?`\uD83D\uDD11 ${s?"\u4FEE\u6539 Key":"Change Key"}`:p==="relogin"?`\uD83D\uDD04 ${s?"\u91CD\u65B0\u767B\u5F55":"Re-login"}`:p==="delete"?`\uD83D\uDDD1\uFE0F ${s?"\u5220\u9664":"Delete"}`:`\u2190 ${s?"\u8FD4\u56DE":"Back"}`,h=g===a;return fe.jsxDEV(G,{borderStyle:h?"bold":"round",borderColor:h?"cyan":"gray",paddingX:2,children:fe.jsxDEV(I,{bold:h,color:h?"cyan":void 0,dimColor:!h,children:m},void 0,!1,void 0,this)},p,!1,void 0,this)})},void 0,!1,void 0,this),fe.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:s?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:s?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(I,{dimColor:!0,children:s?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var fe,Wr,iy,Ld;var VT=O(async()=>{ds();await Vo();fe=ye($t(),1),Wr={"claude-subscription":{icon:"\u2726",color:"yellow"},"codex-subscription":{icon:"\u25C8",color:"blue"},tako:{icon:"\uD83D\uDC19",color:"cyan"},anthropic:{icon:"\u25B3",color:"magenta"},deepseek:{icon:"\uD83D\uDD2E",color:"blue"},xiaomi:{icon:"\uD83D\uDFE0",color:"yellow"},custom:{icon:"\u2699",color:"gray"}},iy={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},Ld=["claude-subscription","codex-subscription","tako","anthropic","deepseek","xiaomi","custom"]});function XT({onDone:e}){let[o,i]=an.useState("list"),[a,s]=an.useState([]),[u,d]=an.useState(),[p,g]=an.useState({}),[m,h]=an.useState(0),[Q,C]=an.useState(0),[w,N]=an.useState(0),[v,S]=an.useState(""),[L,q]=an.useState(""),[ne,se]=an.useState("tako"),[le,pe]=an.useState(""),[Qe,Ee]=an.useState(""),[ie,Be]=an.useState(""),[we,De]=an.useState(""),Ie=ao()==="zh",Dt=lA(),ce=Dt[m],Ne=iy[ce?.id]?.color||"white",ve=ce?a.filter((ae)=>ku(ae,ce.id)):[],We=p[ce?.id]||u,He=ve.length+4,V=a.find((ae)=>ae.id===v),Oe=V?.type==="claude-subscription"||V?.type==="codex-subscription",Pe=V?[...V.id!==u?["default"]:[],...Oe?["relogin"]:[],...V.builtin?["rekey"]:["delete"],"back"]:["back"],je=an.useCallback(async()=>{let ae=await Wo(),Ae=await pi();s(ae),d(Ae?.id);let X={};for(let de of lA()){let Ke=await Qa(de.id);X[de.id]=Ke?.id}g(X)},[]);an.useEffect(()=>{je()},[je]),an.useEffect(()=>{C(0)},[m]),an.useEffect(()=>{if(L){let ae=setTimeout(()=>q(""),3000);return()=>clearTimeout(ae)}},[L]);let wt=an.useCallback(async()=>{if(v&&a.find((_e)=>_e.id===v)?.builtin){await gA(v,{apiKey:le}),q(Ie?"Key \u5DF2\u66F4\u65B0":"Key updated"),await je(),i("list"),C(0);return}let ae=Si[ne]?.[Ie?"zh":"en"]||ne,Ae=Qe||z0(ne),X=ie||Fu(ne),de=we?parseInt(we,10):NaN,Ke=Number.isFinite(de)&&de>0?de:void 0;await fA({name:ae,type:ne,apiKey:le,baseUrl:Ae,model:X,modelContextWindow:Ke,supportedClients:ci(ne)}),$n("provider_added",{provider_type:ne,method:"manual"}),wa(),er(),q(Ie?"\u5DF2\u6DFB\u52A0":"Added"),De(""),await je(),i("list"),C(0)},[ne,le,Qe,ie,we,Ie,je,v,a]),zt=an.useCallback(async()=>{i("scanning");let ae=await Nc(),Ae=await Rc(ae);if(Ae>0)wa(),er();q(Ie?`\u626B\u63CF\u5B8C\u6210\uFF0C\u65B0\u589E ${Ae} \u4E2A`:`Scan done, ${Ae} added`),await je(),i("list"),C(0)},[je,Ie]),[vt,Zt]=an.useState("claude"),Mt=an.useCallback(async(ae)=>{Zt(ae),i("logging-in");let Ae=ae==="claude"?["claude","auth","login","--claudeai"]:["codex","login"];await Bun.spawn(Ae,{stdin:"inherit",stdout:"pipe",stderr:"pipe"}).exited;let{invalidateQuotaCache:de}=await Promise.resolve().then(() => (Vf(),i1));if(ae==="claude")try{let Ke=Bun.spawn(["claude","auth","status"],{stdout:"pipe",stderr:"pipe"}),_e=await new Response(Ke.stdout).text();await Ke.exited;let Xe=JSON.parse(_e.trim());if(Xe.loggedIn&&Xe.authMethod==="claude.ai"){let yt=Xe.email||"",St=Xe.subscriptionType||"pro",Ue=`Claude ${St.charAt(0).toUpperCase()+St.slice(1)}${yt?` (${yt})`:""}`,{readClaudeAuth:bt}=await Promise.resolve().then(() => (Ff(),Tf)),Ot=await bt(),en=Ot.credentials||Ot.oauthAccount?{credentials:Ot.credentials,oauthAccount:Ot.oauthAccount}:void 0,Jt=a.find((ke)=>ke.type==="claude-subscription"&&ke.email===yt);if(!Jt)await fA({name:Ue,type:"claude-subscription",email:yt,subscriptionType:St,supportedClients:ci("claude-subscription"),authData:en}),q(Ie?"Claude \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Claude subscription added");else await gA(Jt.id,{authData:en}),de(Jt.id,"claude-subscription"),q(Ie?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else q(Ie?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{q(Ie?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}else try{let Ke=await import("fs/promises"),{homedir:_e}=await import("os"),{join:Xe}=await import("path"),yt=JSON.parse(await Ke.readFile(Xe(_e(),".codex","auth.json"),"utf-8"));if(yt.auth_mode==="chatgpt"&&yt.tokens?.access_token){let St="";try{St=JSON.parse(atob(yt.tokens.id_token.split(".")[1])).email||""}catch{}let Ue=a.find((bt)=>bt.type==="codex-subscription"&&bt.email===St);if(!Ue)await fA({name:St?`Codex Plus (${St})`:"Codex Subscription",type:"codex-subscription",email:St||void 0,supportedClients:ci("codex-subscription"),authData:yt}),q(Ie?"Codex \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Codex subscription added");else await gA(Ue.id,{authData:yt}),de(Ue.id,"codex-subscription"),q(Ie?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else q(Ie?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{q(Ie?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}await je(),i("list"),C(0)},[a,Ie,je]);if(Yn(an.useCallback((ae,Ae)=>{if(o==="list"){if(Ae.escape||ae==="q"){e();return}if(Ae.leftArrow){h((de)=>de>0?de-1:Dt.length-1);return}if(Ae.rightArrow){h((de)=>de<Dt.length-1?de+1:0);return}let X=parseInt(ae);if(X>=1&&X<=Dt.length){h(X-1);return}if(Ae.upArrow){C((de)=>de>0?de-1:He-1);return}if(Ae.downArrow){C((de)=>de<He-1?de+1:0);return}if(Ae.return){if(Q<ve.length){let de=ve[Q];bc(ce.id,de.id).then(()=>{e()})}else if(Q===ve.length)i("add-type"),C(0);else if(Q===ve.length+1)zt();else if(Q===ve.length+2)e("client-versions");else e();return}if((ae==="d"||ae==="e")&&Q<ve.length)S(ve[Q].id),i("detail"),N(0);return}if(o==="detail"){if(Ae.leftArrow){N((X)=>X>0?X-1:Pe.length-1);return}if(Ae.rightArrow){N((X)=>X<Pe.length-1?X+1:0);return}if(Ae.escape){i("list"),C(0);return}if(Ae.return){let X=Pe[w];if(X==="back"){i("list"),C(0);return}if(X==="default")X0(v).then(()=>{q(Ie?"\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4":"Set as default"),je(),i("list"),C(0)});if(X==="delete")V0(v).then(()=>{q(Ie?"\u5DF2\u5220\u9664":"Deleted"),je(),i("list"),C(0)});if(X==="rekey")se(V?.type||"tako"),pe(""),i("add-key"),C(0);if(X==="relogin"){let de=V?.type==="codex-subscription"?"codex":"claude";i("list"),C(0),Mt(de)}}return}if(o==="add-type"){if(Ae.upArrow){C((X)=>X>0?X-1:Ld.length-1);return}if(Ae.downArrow){C((X)=>X<Ld.length-1?X+1:0);return}if(Ae.escape){i("list"),C(0);return}if(Ae.return){let X=Ld[Q];if(se(X),X==="claude-subscription"){Mt("claude");return}if(X==="codex-subscription"){Mt("codex");return}pe(""),Ee(""),Be(Fu(X)||""),i("add-key"),C(0)}return}if(o==="add-key"){if(Ae.escape){i("list"),C(0);return}if(Ae.return&&le){if(ne==="custom")i("add-url");else if(ne==="deepseek"||ne==="anthropic"||ne==="tako"||ne==="xiaomi")i("add-model"),C(0);else wt();return}if(Ae.backspace||Ae.delete){pe((X)=>X.slice(0,-1));return}if(ae&&!Ae.ctrl)pe((X)=>X+ae);return}if(o==="add-url"){if(Ae.escape){i("list"),C(0);return}if(Ae.return){i("add-model"),C(0);return}if(Ae.backspace||Ae.delete){Ee((X)=>X.slice(0,-1));return}if(ae&&!Ae.ctrl)Ee((X)=>X+ae);return}if(o==="add-model"){let X=xc(ne);if(Ae.escape){i("list"),C(0);return}if(X){if(Ae.upArrow){C((de)=>de>0?de-1:X.length-1);return}if(Ae.downArrow){C((de)=>de<X.length-1?de+1:0);return}if(Ae.return){Be(X[Q]),setTimeout(()=>wt(),0);return}}else{if(Ae.return){let de=ie.trim();if(de&&bo.some((Ke)=>Ke.id===de))wt();else i("add-ctx");return}if(Ae.backspace||Ae.delete){Be((de)=>de.slice(0,-1));return}if(ae&&!Ae.ctrl)Be((de)=>de+ae)}return}if(o==="add-ctx"){if(Ae.escape){i("list"),C(0);return}if(Ae.return){wt();return}if(Ae.backspace||Ae.delete){De((X)=>X.slice(0,-1));return}if(ae&&!Ae.ctrl&&/^[0-9]$/.test(ae))De((X)=>X+ae);return}},[o,Q,w,ve,He,Dt.length,ce,v,V,Pe,ne,le,Qe,ie,we,e,zt,Mt,wt,je,Ie])),o==="scanning"||o==="logging-in"){let ae=o==="logging-in"?Wr[vt==="claude"?"claude-subscription":"codex-subscription"]:{icon:"\u23F3",color:"yellow"},Ae=o==="scanning"?Ie?"\u6B63\u5728\u626B\u63CF\u672C\u5730\u8BA2\u9605...":"Scanning local subscriptions...":Ie?"\u6B63\u5728\u767B\u5F55\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u6388\u6743...":"Logging in, please authorize in browser...";return Ye.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:Ye.jsxDEV(G,{borderStyle:"round",borderColor:ae.color,paddingX:3,paddingY:1,flexDirection:"column",alignItems:"center",children:[Ye.jsxDEV(I,{color:ae.color,bold:!0,children:[ae.icon," ",Ae]},void 0,!0,void 0,this),o==="logging-in"&&Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u5B8C\u6210\u540E\u5C06\u81EA\u52A8\u8FD4\u56DE":"Will return automatically when done"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}if(o==="add-key"||o==="add-url"||o==="add-model"||o==="add-ctx")return Ye.jsxDEV(jT,{screen:o,addType:ne,addKey:le,addUrl:Qe,addModel:ie,addCtx:we,rowIdx:Q,zh:Ie},void 0,!1,void 0,this);if(o==="add-type")return Ye.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Ye.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:Ye.jsxDEV(I,{bold:!0,children:["\u2795 ",Ie?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ye.jsxDEV(G,{flexDirection:"column",marginTop:1,gap:0,children:Ld.map((ae,Ae)=>{let X=Wr[ae]||Wr.custom,de=Q===Ae,Ke=Ie?Si[ae]?.zh:Si[ae]?.en,_e=ae==="claude-subscription"||ae==="codex-subscription";return Ye.jsxDEV(G,{borderStyle:de?"bold":"round",borderColor:de?X.color:"gray",paddingX:2,paddingY:0,children:Ye.jsxDEV(G,{gap:1,children:[Ye.jsxDEV(I,{color:X.color,bold:!0,children:X.icon},void 0,!1,void 0,this),Ye.jsxDEV(I,{bold:de,color:de?X.color:void 0,children:Ke},void 0,!1,void 0,this),_e&&Ye.jsxDEV(I,{dimColor:!0,children:["(",Ie?"\u767B\u5F55\u6388\u6743":"login auth",")"]},void 0,!0,void 0,this),!_e&&Ye.jsxDEV(I,{dimColor:!0,children:["(",Ie?"\u586B\u5199 Key":"enter key",")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},ae,!1,void 0,this)})},void 0,!1,void 0,this),Ye.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o==="detail"&&V)return Ye.jsxDEV(qT,{provider:V,defaultId:u,detailActions:Pe,detailIdx:w,zh:Ie},void 0,!1,void 0,this);return Ye.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Ye.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:[Ye.jsxDEV(I,{bold:!0,children:["\u26A1 ",Ie?"\u7BA1\u7406\u670D\u52A1\u5546":"Manage Providers"]},void 0,!0,void 0,this),L&&Ye.jsxDEV(I,{color:"green",children:[" \u2713 ",L]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ye.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:[Ye.jsxDEV(I,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),Dt.map((ae,Ae)=>{let X=iy[ae.id]||{icon:"\u25AA",color:"white"},de=Ae===m;return Ye.jsxDEV(G,{borderStyle:de?"bold":"single",borderColor:de?X.color:"gray",paddingX:2,children:Ye.jsxDEV(I,{color:de?X.color:void 0,bold:de,dimColor:!de,children:[X.icon," ",ae.name]},void 0,!0,void 0,this)},ae.id,!1,void 0,this)}),Ye.jsxDEV(I,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ye.jsxDEV(G,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:Ne,paddingX:1,paddingY:1,children:[ve.length===0&&Ye.jsxDEV(G,{paddingX:2,paddingY:1,justifyContent:"center",children:Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u6682\u65E0\u517C\u5BB9\u7684\u670D\u52A1\u5546\uFF0C\u8BF7\u6DFB\u52A0":"No compatible providers yet"},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.map((ae,Ae)=>Ye.jsxDEV(WT,{provider:ae,focused:Q===Ae,bound:ae.id===We,isDefault:ae.id===u,zh:Ie},ae.id,!1,void 0,this))]},void 0,!0,void 0,this),Ye.jsxDEV(G,{marginTop:1,gap:1,children:[{id:"add",offset:0,icon:"\u2795",label:Ie?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"},{id:"scan",offset:1,icon:"\uD83D\uDD0D",label:Ie?"\u626B\u63CF\u8BA2\u9605":"Scan"},{id:"versions",offset:2,icon:"\uD83D\uDCE6",label:Ie?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"},{id:"back",offset:3,icon:"\u2190",label:Ie?"\u8FD4\u56DE":"Back"}].map((ae)=>{let Ae=Q===ve.length+ae.offset;return Ye.jsxDEV(G,{borderStyle:Ae?"bold":"round",borderColor:Ae?"cyan":"gray",paddingX:2,children:Ye.jsxDEV(I,{bold:Ae,color:Ae?"cyan":void 0,dimColor:!Ae,children:[ae.icon," ",ae.label]},void 0,!0,void 0,this)},ae.id,!1,void 0,this)})},void 0,!1,void 0,this),Ye.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u7ED1\u5B9A":"bind"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"d"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u8BE6\u60C5":"detail"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Ye.jsxDEV(I,{dimColor:!0,children:Ie?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var an,Ye;var $T=O(async()=>{Mn();bi();Uc();ds();ds();Ru();Or();await ha([Vo(),VT()]);an=ye(ct(),1),Ye=ye($t(),1)});async function ZT(){try{let o=((await tt()).providers??[]).find((m)=>m.type==="tako");if(!o)return{success:!1,error:"\u672A\u914D\u7F6E Tako provider"};if(!o.apiKey)return{success:!1,error:"Tako provider \u7F3A\u5C11 API key\uFF0C\u8BF7\u91CD\u65B0\u914D\u7F6E"};let i=await Hc(o.apiKey);if(!i.valid)return{success:!1,error:i.message};let a=i.apiId,u=await(await fetch(`${xo}/apiStats/api/user-stats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiId:a})})).json(),p=await(await fetch(`${xo}/apiStats/api/user-model-stats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiId:a,period:"daily"})})).json();if(!u.success)return{success:!1,error:u.error||u.message||"\u83B7\u53D6\u7EDF\u8BA1\u5931\u8D25"};let g=(p.data||[]).map((m)=>({model:m.model,requests:m.requests,cost:m.formatted?.total||"$0.00"}));return{success:!0,data:{totalRequests:u.data?.usage?.total?.requests||0,totalCost:u.data?.usage?.total?.formattedCost||"$0.00",todayCost:`$${(u.data?.limits?.currentDailyCost||0).toFixed(2)}`,modelStats:g}}}catch(e){return{success:!1,error:e instanceof Error?e.message:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}}}function eF(e){return e.toLocaleString("en-US")}var tF=O(()=>{on();qf()});function nF({onExit:e}){let[o,i]=Ta.useState(null),[a,s]=Ta.useState(!0),[u,d]=Ta.useState(10),p=Ta.useCallback(async()=>{s(!0);let m=await ZT();if(m.success&&m.data)i(m.data);s(!1)},[]);Ta.useEffect(()=>{p()},[p]),Ta.useEffect(()=>{let m=setInterval(()=>{d((h)=>{if(h<=1)return p(),10;return h-1})},1000);return()=>clearInterval(m)},[p]),Yn((m,h)=>{if(m==="q"||h.escape)e()});let g=ao()==="zh";return Xo.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[Xo.jsxDEV(I,{bold:!0,children:Ge("stats.title")},void 0,!1,void 0,this),a&&!o?Xo.jsxDEV(I,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this):o?Xo.jsxDEV(G,{flexDirection:"column",marginTop:1,children:[Xo.jsxDEV(I,{children:Ge("stats.totalRequests",{count:eF(o.totalRequests)})},void 0,!1,void 0,this),Xo.jsxDEV(I,{children:Ge("stats.totalCost",{cost:o.totalCost})},void 0,!1,void 0,this),Xo.jsxDEV(I,{children:Ge("stats.todayCost",{cost:o.todayCost})},void 0,!1,void 0,this),o.modelStats.length>0&&Xo.jsxDEV(G,{flexDirection:"column",marginTop:1,children:[Xo.jsxDEV(I,{bold:!0,dimColor:!0,children:g?"\u6A21\u578B\u5206\u5E03":"Model Distribution"},void 0,!1,void 0,this),o.modelStats.map((m,h)=>Xo.jsxDEV(I,{dimColor:!0,children:[h===o.modelStats.length-1?"\u2514\u2500":"\u251C\u2500"," ",m.model.padEnd(25)," ",String(m.requests).padStart(5)," ",m.cost]},m.model,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):Xo.jsxDEV(I,{color:"red",children:g?"\u83B7\u53D6\u5931\u8D25":"Failed to load"},void 0,!1,void 0,this),Xo.jsxDEV(G,{marginTop:1,children:Xo.jsxDEV(I,{dimColor:!0,children:g?`${u}s \u540E\u5237\u65B0 q \u8FD4\u56DE`:`Refresh in ${u}s q back`},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ta,Xo;var oF=O(async()=>{Mn();tF();await Vo();Ta=ye(ct(),1),Xo=ye($t(),1)});function SP(e){return e.startsWith("cr_")&&e.length>10}async function xP(e){try{let i=await(await fetch(`${xo}/apiStats/api/get-key-id`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:e})})).json();if(i.success&&i.data?.id)return{valid:!0,apiId:i.data.id};return{valid:!1,error:i.error||Ge("auth.validationFailed")}}catch(o){return{valid:!1,error:o instanceof Error?o.message:Ge("auth.networkError")}}}async function iF(e){if(!SP(e))return $n("api_key_validated",{success:!1,error_type:"invalid_format"}),{success:!1,error:Ge("auth.invalidFormat")};let o=await xP(e);if(!o.valid)return $n("api_key_validated",{success:!1,error_type:"api_validation_failed"}),{success:!1,error:o.error};return await uA({apiKey:e,apiId:o.apiId}),await bP(e,o.apiId),$n("api_key_validated",{success:!0}),wa(),er(),{success:!0}}async function bP(e,o){let a=(await Wo()).find((s)=>s.type==="tako");if(a)await gA(a.id,{apiKey:e,apiId:o});else await fA({name:"Tako \u5B98\u65B9",type:"tako",apiKey:e,baseUrl:xo,apiId:o,supportedClients:ci("tako"),builtin:!0})}var rF=O(()=>{on();Mn();Or();bi();ds()});function ry({isReconfigure:e,onDone:o}){let[i,a]=Ss.useState(""),[s,u]=Ss.useState("idle"),[d,p]=Ss.useState(""),{stdin:g,setRawMode:m}=ml();Ss.useEffect(()=>{if(!g)return;m(!0);let w=(N)=>{let v=N.toString();if(v.length>1&&!v.startsWith("\x1B"))a((S)=>S+v.replace(/[\r\n]/g,""))};return g.on("data",w),()=>{g.off("data",w)}},[g,m]);let h=Ss.useCallback(async()=>{if(!i||s==="validating")return;u("validating");let w=await iF(i);if(w.success)u("success"),wa(),er(),setTimeout(()=>o(!0),500);else u("error"),p(w.error||"Validation failed")},[i,s,o]);Yn((w,N)=>{if(N.escape){o(!1);return}if(N.return){h();return}if(N.backspace||N.delete){a((v)=>v.slice(0,-1)),u("idle");return}if(w&&!N.ctrl&&w.length===1)a((v)=>v+w),u("idle")});let Q=i.length<=6?i:`${i.slice(0,3)}${"\u2022".repeat(Math.min(i.length-6,20))}${i.slice(-3)}`,C=ao()==="zh";return ki.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[ki.jsxDEV(I,{bold:!0,color:"cyan",children:["\uD83D\uDD11 ",e?Ge("prompts.enterApiKey"):"API Key"]},void 0,!0,void 0,this),ki.jsxDEV(G,{marginTop:1,children:[ki.jsxDEV(I,{color:"cyan",bold:!0,children:[">"," "]},void 0,!0,void 0,this),ki.jsxDEV(I,{children:Q},void 0,!1,void 0,this),s==="idle"&&ki.jsxDEV(I,{color:"cyan",children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s==="validating"&&ki.jsxDEV(I,{color:"yellow",children:["\u23F3 ",Ge("prompts.validating")]},void 0,!0,void 0,this),s==="success"&&ki.jsxDEV(I,{color:"green",children:["\u2713 ",Ge("prompts.keyConfigured")]},void 0,!0,void 0,this),s==="error"&&ki.jsxDEV(I,{color:"red",children:["\u2717 ",d]},void 0,!0,void 0,this),ki.jsxDEV(G,{marginTop:1,children:ki.jsxDEV(I,{dimColor:!0,children:["Enter ",C?"\u63D0\u4EA4":"submit"," Esc ",C?"\u53D6\u6D88":"cancel"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Ss,ki;var aF=O(async()=>{Mn();rF();Or();await Vo();Ss=ye(ct(),1),ki=ye($t(),1)});function AF({onDone:e}){let[o,i]=sF.useState(Md.findIndex((a)=>a.value===ao()));return Yn((a,s)=>{if(s.upArrow)i((u)=>u>0?u-1:Md.length-1);if(s.downArrow)i((u)=>u<Md.length-1?u+1:0);if(s.return)W0(Md[o].value),e();if(s.escape)e()}),Fa.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[Fa.jsxDEV(I,{bold:!0,children:["\uD83C\uDF10 ",Ge("menu.changeLanguage")]},void 0,!0,void 0,this),Md.map((a,s)=>Fa.jsxDEV(G,{gap:1,marginTop:s===0?1:0,children:[Fa.jsxDEV(I,{color:"cyan",bold:s===o,children:s===o?"\u25B8":" "},void 0,!1,void 0,this),Fa.jsxDEV(I,{bold:s===o,children:a.label},void 0,!1,void 0,this),a.value===ao()&&Fa.jsxDEV(I,{dimColor:!0,children:"\u2190"},void 0,!1,void 0,this)]},a.value,!0,void 0,this)),Fa.jsxDEV(G,{marginTop:1,children:Fa.jsxDEV(I,{dimColor:!0,children:"Enter select Esc back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var sF,Fa,Md;var uF=O(async()=>{Mn();await Vo();sF=ye(ct(),1),Fa=ye($t(),1),Md=[{value:"en",label:"English"},{value:"zh",label:"\u4E2D\u6587"}]});import{join as NP}from"path";async function RP(){try{return await Bun.file(cF).json()}catch{return{}}}async function lF(e){await Bun.write(cF,JSON.stringify(e))}async function dF(){if(await B0())return!1;let e=await RP();if(e.never)return!1;let o=new Date().toISOString().slice(0,10);if(e.dismissed===o)return!1;return!0}async function pF(e){if(e==="never")await lF({never:!0});else{let o=new Date().toISOString().slice(0,10);await lF({dismissed:o})}}function fF({onDone:e}){let[o,i]=Om.useState(0),a=ao()==="zh";return Yn(Om.useCallback((s,u)=>{if(u.upArrow){i((d)=>d>0?d-1:Mm.length-1);return}if(u.downArrow){i((d)=>d<Mm.length-1?d+1:0);return}if(u.escape){e("skip");return}if(u.return){e(Mm[o].id);return}},[o,e])),wn.jsxDEV(G,{flexDirection:"column",paddingX:0,paddingY:1,children:[wn.jsxDEV(G,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[wn.jsxDEV(G,{gap:1,children:[wn.jsxDEV(I,{color:"cyan",bold:!0,children:"\uD83D\uDD11"},void 0,!1,void 0,this),wn.jsxDEV(I,{bold:!0,children:a?"\u914D\u7F6E Tako API Key":"Configure Tako API Key"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wn.jsxDEV(G,{marginTop:1,flexDirection:"column",children:[wn.jsxDEV(I,{dimColor:!0,children:a?"\u914D\u7F6E API Key \u540E\u5373\u53EF\u4F7F\u7528 Tako \u4EE3\u7406\u670D\u52A1\uFF0C\u83B7\u5F97\u7EDF\u4E00\u7684\u914D\u989D\u7BA1\u7406\u548C\u66F4\u5FEB\u7684\u8BBF\u95EE\u901F\u5EA6\u3002":"Configure your API Key to use Tako proxy service with unified quota and faster access."},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u4F60\u4E5F\u53EF\u4EE5\u8DF3\u8FC7\u6B64\u6B65\u9AA4\uFF0C\u76F4\u63A5\u4F7F\u7528\u5176\u4ED6\u670D\u52A1\u5546\u3002":"You can skip this and use other providers instead."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wn.jsxDEV(G,{marginTop:1,flexDirection:"column",children:Mm.map((s,u)=>{let d=u===o;return wn.jsxDEV(G,{paddingLeft:1,gap:1,children:[wn.jsxDEV(I,{color:d?s.color||"white":void 0,bold:d,children:d?"\u25B8":" "},void 0,!1,void 0,this),wn.jsxDEV(I,{bold:d,color:d?s.color||"white":void 0,children:a?s.label.zh:s.label.en},void 0,!1,void 0,this),d&&wn.jsxDEV(I,{dimColor:!0,children:a?s.hint.zh:s.hint.en},void 0,!1,void 0,this)]},s.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wn.jsxDEV(G,{paddingX:2,marginTop:1,justifyContent:"center",gap:2,children:[wn.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u9009\u62E9":"select"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),wn.jsxDEV(I,{dimColor:!0,children:a?"\u8DF3\u8FC7":"skip"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Om,wn,cF,Mm;var gF=O(async()=>{on();on();Mn();await Vo();Om=ye(ct(),1),wn=ye($t(),1),cF=NP(Vt,".key-prompt.json");Mm=[{id:"configure",label:{en:"Configure now",zh:"\u73B0\u5728\u914D\u7F6E"},hint:{en:"Enter your Tako API Key",zh:"\u8F93\u5165\u4F60\u7684 Tako API Key"},color:"cyan"},{id:"skip",label:{en:"Not now",zh:"\u7A0D\u540E\u518D\u8BF4"},hint:{en:"Remind me tomorrow",zh:"\u660E\u5929\u518D\u63D0\u9192\u6211"}},{id:"never",label:{en:"Don't ask again",zh:"\u4E0D\u518D\u63D0\u793A"},hint:{en:"You can configure later via c key",zh:"\u4E4B\u540E\u53EF\u4EE5\u6309 c \u968F\u65F6\u914D\u7F6E"}}]});function EF({onDone:e}){let o=lA(),i=ao()==="zh",[a,s]=$o.useState(0),[u,d]=$o.useState(0),[p,g]=$o.useState(0),[m,h]=$o.useState({}),[Q,C]=$o.useState(null),[w,N]=$o.useState(""),v=o[a],S=$o.useCallback(async(pe)=>{h((Ee)=>({...Ee,[pe]:{loading:!0,versions:[],current:null}}));let Qe=o.find((Ee)=>Ee.id===pe);if(!Qe)return;try{let[Ee,ie]=await Promise.all([Zf(Qe.package),tg(Qe)]),Be=Ee.map((we)=>({...we,isCurrent:we.version===ie}));h((we)=>({...we,[pe]:{loading:!1,versions:Be,current:ie}}))}catch(Ee){h((ie)=>({...ie,[pe]:{loading:!1,error:Ee.message,versions:[],current:null}}))}},[o]);$o.useEffect(()=>{if(!v)return;if(!m[v.id])S(v.id)},[a,v?.id]),$o.useEffect(()=>{d(0),g(0)},[a]),$o.useEffect(()=>{if(!w)return;let pe=setTimeout(()=>N(""),3000);return()=>clearTimeout(pe)},[w]);let L=v?m[v.id]:void 0,q=L?.versions??[],ne=$o.useCallback(async(pe)=>{if(!v||Q)return;C(pe);try{await eg(v,pe),N(i?`\u2713 \u5DF2\u5207\u6362\u5230 ${pe}`:`\u2713 Switched to ${pe}`),await S(v.id)}catch(Qe){N(i?`\u2717 \u5B89\u88C5\u5931\u8D25\uFF1A${Qe.message}`:`\u2717 Install failed: ${Qe.message}`)}finally{C(null)}},[v,Q,S,i]);Yn((pe,Qe)=>{if(Q)return;if(Qe.escape||pe==="q"){e();return}if(Qe.leftArrow){s((ie)=>ie>0?ie-1:o.length-1);return}if(Qe.rightArrow){s((ie)=>ie<o.length-1?ie+1:0);return}if(pe==="r"){if(v)S(v.id);return}if(!q.length)return;let Ee=q.length-1;if(Qe.upArrow){d((ie)=>{let Be=Math.max(0,ie-1);if(Be<p)g(Be);return Be});return}if(Qe.downArrow){d((ie)=>{let Be=Math.min(Ee,ie+1);if(Be>=p+ay)g(Be-ay+1);return Be});return}if(Qe.return){let ie=q[u];if(ie&&!ie.isCurrent)ne(ie.version)}});let se=mF[v?.id]?.color||"white",le=q.slice(p,p+ay);return Tt.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Tt.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,children:[Tt.jsxDEV(I,{bold:!0,children:["\uD83D\uDCE6 ",i?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"]},void 0,!0,void 0,this),w&&Tt.jsxDEV(I,{color:w.startsWith("\u2713")?"green":"red",children:[" ",w]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:o.map((pe,Qe)=>{let Ee=mF[pe.id]||{icon:"\u25AA",color:"white"},ie=Qe===a;return Tt.jsxDEV(G,{borderStyle:ie?"bold":"single",borderColor:ie?Ee.color:"gray",paddingX:2,children:Tt.jsxDEV(I,{bold:ie,color:ie?Ee.color:void 0,dimColor:!ie,children:[Ee.icon," ",pe.name]},void 0,!0,void 0,this)},pe.id,!1,void 0,this)})},void 0,!1,void 0,this),Tt.jsxDEV(G,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:se,paddingX:2,paddingY:1,children:!L||L.loading?Tt.jsxDEV(I,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"Loading..."},void 0,!1,void 0,this):L.error?Tt.jsxDEV(I,{color:"red",children:[i?"\u52A0\u8F7D\u5931\u8D25\uFF1A":"Failed: ",L.error]},void 0,!0,void 0,this):q.length===0?Tt.jsxDEV(I,{dimColor:!0,children:i?"\u6682\u65E0\u7248\u672C":"No versions"},void 0,!1,void 0,this):Tt.jsxDEV(G,{flexDirection:"column",children:[Tt.jsxDEV(I,{dimColor:!0,children:[i?`\u5171 ${q.length} \u4E2A\u7248\u672C\uFF0C\u5F53\u524D\u5B89\u88C5\uFF1A`:`${q.length} versions, current: `,Tt.jsxDEV(I,{color:se,children:L.current??(i?"\u672A\u5B89\u88C5":"not installed")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV(G,{marginTop:1,flexDirection:"column",children:le.map((pe,Qe)=>{let ie=p+Qe===u,Be=pe.publishedAt?pe.publishedAt.slice(0,10):"",we=pe.isCurrent?i?" \u2605 \u5F53\u524D":" \u2605 current":"",De=Q===pe.version,Ie=ie?se:pe.isCurrent?"green":void 0;return Tt.jsxDEV(G,{paddingLeft:1,children:Tt.jsxDEV(I,{color:Ie,bold:ie,dimColor:!ie&&!pe.isCurrent,children:[ie?"\u25B6 ":" ",pe.version.padEnd(16),Be.padEnd(14),we,De?i?" \u23F3 \u5B89\u88C5\u4E2D...":" \u23F3 installing...":""]},void 0,!0,void 0,this)},pe.version,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Tt.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u5B89\u88C5":"install"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Tt.jsxDEV(I,{dimColor:!0,children:i?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var $o,Tt,ay=12,mF;var CF=O(async()=>{Uc();Gh();Mn();await Vo();$o=ye(ct(),1),Tt=ye($t(),1),mF={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}}});function TP(e){let o=new Date(e.ts).toISOString().slice(11,19);switch(e.kind){case"session_started":return{dim:!0,text:`[${o}] \u25B6 session_started ${e.backend}`};case"turn_started":return{color:"cyan",text:`[${o}] \u25B6 turn_started`};case"text_delta":return{text:e.text};case"reasoning_delta":return{dim:!0,text:`[${o}] \uD83D\uDCAD ${e.text.slice(0,200)}`};case"tool_use":return{color:"yellow",text:`[${o}] \uD83D\uDD27 ${e.name} ${JSON.stringify(e.input).slice(0,160)}`};case"tool_result":return{color:"green",text:`[${o}] \u2713 result`};case"approval_required":return{color:"magenta",text:`[${o}] \u26A0 approval(${e.approvalType})`};case"turn_completed":return{color:"cyan",text:`[${o}] \u25C0 turn_completed`};case"error":return{color:"red",text:`[${o}] \u2717 ${e.message}`};case"session_closed":return{dim:!0,text:`[${o}] \u23F9 closed`};default:return{text:JSON.stringify(e)}}}function BF({sid:e,onBack:o}){let i=xi()==="zh",[a,s]=mo.useState(null),[u,d]=mo.useState([]),[p,g]=mo.useState(""),[m,h]=mo.useState("idle"),[Q,C]=mo.useState(null),[w,N]=mo.useState([]),v=mo.useRef(0),S=mo.useCallback(async()=>{let se=await Wu(e,IF);if(!se)return;s(se.meta),d(se.log);try{let pe=await(await import("fs/promises")).stat(so(e));v.current=pe.size}catch{v.current=0}},[e]);mo.useEffect(()=>{S()},[S]),mo.useEffect(()=>{let se=!1,le=null,pe=async()=>{if(se)return;try{let Qe=await import("fs/promises"),Ee=await Qe.stat(so(e));if(Ee.size>v.current){let ie=await Qe.open(so(e),"r"),Be=Buffer.alloc(Ee.size-v.current);await ie.read(Be,0,Be.length,v.current),await ie.close(),v.current=Ee.size;let we=[];for(let De of Be.toString("utf-8").split(`
|
|
697
697
|
`)){if(!De.trim())continue;try{we.push(JSON.parse(De))}catch{}}if(we.length)d((De)=>[...De,...we].slice(-IF))}if(Math.random()<0.1){let ie=await Wu(e,0);if(ie)s(ie.meta)}N(await jc(e))}catch{}le=setTimeout(pe,hF)};return le=setTimeout(pe,hF),()=>{if(se=!0,le)clearTimeout(le)}},[e]);let L=mo.useCallback(async()=>{if(m!=="idle"||!p.trim())return;let se=p;g(""),C(null),h("sending");try{await Xc(e,se)}catch(le){C(le instanceof Error?le.message:String(le))}finally{h("idle");let le=await Wu(e,0);if(le)s(le.meta)}},[e,p,m]),q=mo.useCallback(async()=>{if(m!=="sending")return o();h("cancelling"),await $c(e).catch(()=>{})},[m,e,o]),ne=mo.useCallback(async(se)=>{let le=w[0];if(!le)return;await rg(e,le.approvalId,{decision:se?"allow":"deny",by:"tui",decidedAt:Date.now()}),N((pe)=>pe.filter((Qe)=>Qe.approvalId!==le.approvalId))},[w,e]);if(Yn((se,le)=>{if(le.ctrl&&se==="y"){ne(!0);return}if(le.ctrl&&se==="n"){ne(!1);return}if(le.escape){q();return}if(le.ctrl&&se==="c"){q();return}if(le.ctrl&&se==="d"){o();return}if(le.return){L();return}if(le.backspace||le.delete){g((pe)=>pe.slice(0,-1));return}if(p.length===0&&se==="q"){o();return}if(se&&!le.ctrl&&se.length===1)g((pe)=>pe+se)}),!a)return Bt.jsxDEV(G,{paddingX:2,paddingY:1,children:Bt.jsxDEV(I,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);return Bt.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Bt.jsxDEV(G,{children:[Bt.jsxDEV(I,{bold:!0,children:"Session "},void 0,!1,void 0,this),Bt.jsxDEV(I,{color:"cyan",children:a.sid.slice(0,8)},void 0,!1,void 0,this),Bt.jsxDEV(I,{children:" "},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,children:a.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Bt.jsxDEV(G,{children:Bt.jsxDEV(I,{dimColor:!0,children:[a.backend," \xB7 ",a.model??"-"," \xB7 status=",a.status," \xB7 turns=",a.turnCount]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Bt.jsxDEV(G,{children:Bt.jsxDEV(I,{dimColor:!0,children:[i?"\u5DE5\u4F5C\u76EE\u5F55\uFF1A":"cwd: ",a.workdir]},void 0,!0,void 0,this)},void 0,!1,void 0,this),w.length>0&&Bt.jsxDEV(G,{marginTop:1,flexDirection:"column",borderStyle:"round",borderColor:"magenta",paddingX:1,children:[Bt.jsxDEV(I,{color:"magenta",bold:!0,children:["\u26A0 ",w.length," ",i?"\u4E2A\u5F85\u5BA1\u6279":"pending"," \u2014 ",Bt.jsxDEV(I,{bold:!0,children:"Ctrl-Y"},void 0,!1,void 0,this)," ",i?"\u6279\u51C6":"allow"," / ",Bt.jsxDEV(I,{bold:!0,children:"Ctrl-N"},void 0,!1,void 0,this)," ",i?"\u62D2\u7EDD":"deny"]},void 0,!0,void 0,this),w.slice(0,3).map((se,le)=>Bt.jsxDEV(I,{color:le===0?"magenta":void 0,dimColor:le!==0,children:[le===0?"\u25B6 ":" ","[",se.approvalType,"] ",se.approvalId.slice(0,12)]},se.approvalId,!0,void 0,this))]},void 0,!0,void 0,this),Bt.jsxDEV(G,{marginTop:1,flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:1,children:u.length===0?Bt.jsxDEV(I,{dimColor:!0,children:i?"\uFF08\u6682\u65E0\u65E5\u5FD7\uFF09":"(no log yet)"},void 0,!1,void 0,this):u.slice(-30).map((se,le)=>{let pe=TP(se);return Bt.jsxDEV(I,{color:pe.color,dimColor:pe.dim,children:pe.text||" "},le,!1,void 0,this)})},void 0,!1,void 0,this),Q&&Bt.jsxDEV(G,{marginTop:1,children:Bt.jsxDEV(I,{color:"red",children:["\u2717 ",Q]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Bt.jsxDEV(G,{marginTop:1,children:[Bt.jsxDEV(I,{color:"cyan",bold:!0,children:m==="sending"?"\u23F3 ":m==="cancelling"?"\u270B ":"\u25B6 "},void 0,!1,void 0,this),Bt.jsxDEV(I,{children:p},void 0,!1,void 0,this),m==="idle"&&Bt.jsxDEV(I,{inverse:!0,children:" "},void 0,!1,void 0,this),m==="sending"&&Bt.jsxDEV(I,{dimColor:!0,children:[" (",i?"\u6B63\u5728\u53D1\u9001\u2026ESC \u53D6\u6D88":"sending\u2026 ESC cancel",")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Bt.jsxDEV(G,{marginTop:1,gap:2,children:[Bt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,children:i?"\u53D1\u9001":"send"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,bold:!0,children:"^Y/^N"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,children:i?"\u6279/\u62D2":"allow/deny"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,bold:!0,children:"ESC"},void 0,!1,void 0,this),Bt.jsxDEV(I,{dimColor:!0,children:i?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var mo,Bt,hF=300,IF=200;var yF=O(async()=>{Mn();gg();DA();await Vo();mo=ye(ct(),1),Bt=ye($t(),1)});function DF(e){let o=Math.floor(e/1000);if(o<60)return`${o}s`;if(o<3600)return`${Math.floor(o/60)}m`;if(o<86400)return`${Math.floor(o/3600)}h`;return`${Math.floor(o/86400)}d`}function FP(e){switch(e){case"running":return"yellow";case"idle":return"green";case"closed":return"gray";case"dead":return"red";default:return"white"}}function QF({onDone:e}){let o=xi()==="zh",[i,a]=eo.useState(null),[s,u]=eo.useState({}),[d,p]=eo.useState(0),[g,m]=eo.useState(null),[h,Q]=eo.useState(0),[C,w]=eo.useState({kind:"list"}),N=eo.useCallback(async()=>{let[v,S]=await Promise.all([cg(),fg()]);a(v),u(S),p((L)=>Math.max(0,Math.min(L,v.length-1)))},[]);if(eo.useEffect(()=>{N()},[N,h]),eo.useEffect(()=>{let v=setInterval(()=>Q((S)=>S+1),5000);return()=>clearInterval(v)},[]),Yn((v,S)=>{if(g)return;if(C.kind!=="list")return;if(S.escape||v==="q"){e();return}if(v==="n"){w({kind:"new",backend:"claude",model:"",name:"",field:"backend"});return}if(!i||i.length===0){if(v==="r")Q((q)=>q+1);return}if(S.upArrow||v==="k"){p((q)=>Math.max(0,q-1));return}if(S.downArrow||v==="j"){p((q)=>Math.min(i.length-1,q+1));return}if(v==="r"){Q((q)=>q+1);return}if(v==="p"){m(o?"\u6E05\u7406\u4E2D...":"purging..."),pg().then(()=>{m(null),N()});return}let L=i[d];if(!L)return;if(S.return||v==="o"){w({kind:"detail",sid:L.sid});return}if(v==="d"){m(`closing ${L.sid.slice(0,8)}...`),QA(L.sid,!1).then(()=>{m(null),N()});return}if(v==="x"){m(`purging ${L.sid.slice(0,8)}...`),QA(L.sid,!0).then(()=>{m(null),N()});return}}),C.kind==="detail")return be.jsxDEV(BF,{sid:C.sid,onBack:()=>{w({kind:"list"}),N()}},void 0,!1,void 0,this);if(C.kind==="new")return be.jsxDEV(kP,{initial:C,onCancel:()=>w({kind:"list"}),onCreated:(v)=>{w({kind:"detail",sid:v})}},void 0,!1,void 0,this);if(!i)return be.jsxDEV(G,{paddingX:2,paddingY:1,children:be.jsxDEV(I,{dimColor:!0,children:o?"\u52A0\u8F7D\u4E2D...":"loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);return be.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[be.jsxDEV(I,{bold:!0,children:o?"Agent \u4F1A\u8BDD\u7BA1\u7406":"Agent Sessions"},void 0,!1,void 0,this),be.jsxDEV(G,{marginTop:1,children:be.jsxDEV(I,{dimColor:!0,children:[o?"\u9ED8\u8BA4 Provider\uFF1A":"Defaults: ",Object.keys(s).length===0?o?"\uFF08\u672A\u8BBE\u7F6E\uFF09":"(unset)":Object.entries(s).map(([v,S])=>`${v}=${S.slice(0,8)}`).join(" \u2502 ")]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i.length===0?be.jsxDEV(G,{marginTop:2,flexDirection:"column",children:be.jsxDEV(I,{dimColor:!0,children:o?"\uFF08\u6682\u65E0 session \u2014 \u6309 n \u65B0\u5EFA\uFF09":"(no sessions \u2014 press n to create)"},void 0,!1,void 0,this)},void 0,!1,void 0,this):be.jsxDEV(G,{marginTop:1,flexDirection:"column",children:[be.jsxDEV(G,{children:be.jsxDEV(I,{bold:!0,children:["sid".padEnd(10),"backend".padEnd(9),"name".padEnd(20),"model".padEnd(22),"status".padEnd(9),"turns".padEnd(7),"age".padEnd(6),"last"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i.map((v,S)=>{let L=S===d;return be.jsxDEV(G,{children:[be.jsxDEV(I,{color:L?"cyan":void 0,inverse:L,children:L?"\u25B6 ":" "},void 0,!1,void 0,this),be.jsxDEV(I,{color:L?"cyan":void 0,children:v.sid.slice(0,8).padEnd(10)},void 0,!1,void 0,this),be.jsxDEV(I,{children:v.backend.padEnd(9)},void 0,!1,void 0,this),be.jsxDEV(I,{children:(v.name??"").slice(0,18).padEnd(20)},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:(v.model??"-").slice(0,20).padEnd(22)},void 0,!1,void 0,this),be.jsxDEV(I,{color:FP(v.status),children:v.status.padEnd(9)},void 0,!1,void 0,this),be.jsxDEV(I,{children:String(v.turnCount).padEnd(7)},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:DF(Date.now()-v.createdAt).padEnd(6)},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:DF(Date.now()-v.lastActiveAt)},void 0,!1,void 0,this)]},v.sid,!0,void 0,this)})]},void 0,!0,void 0,this),g&&be.jsxDEV(G,{marginTop:1,children:be.jsxDEV(I,{color:"yellow",children:["\u23F3 ",g]},void 0,!0,void 0,this)},void 0,!1,void 0,this),be.jsxDEV(G,{marginTop:2,gap:2,children:[be.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u9009\u62E9":"select"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u8FDB\u5165":"open"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"n"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u65B0\u5EFA":"new"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"d"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u5173\u95ED":"close"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"x"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u5220\u9664":"purge"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:o?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function kP({initial:e,onCancel:o,onCreated:i}){let a=xi()==="zh",[s,u]=eo.useState(e.backend),[d,p]=eo.useState(e.model),[g,m]=eo.useState(e.name),[h,Q]=eo.useState(e.field),[C,w]=eo.useState(!1),[N,v]=eo.useState(null),S=eo.useCallback(async()=>{if(C)return;w(!0),v(null);try{let L=await Vc({backend:s,model:d.trim()||void 0,name:g.trim()||void 0});i(L.sid)}catch(L){v(L instanceof Error?L.message:String(L)),w(!1)}},[s,d,g,C,i]);return Yn((L,q)=>{if(C)return;if(q.escape){o();return}if(q.tab||q.downArrow){Q((ne)=>ne==="backend"?"model":ne==="model"?"name":"backend");return}if(q.upArrow){Q((ne)=>ne==="backend"?"name":ne==="model"?"backend":"model");return}if(h==="backend"){if(q.leftArrow||q.rightArrow||L===" "){u((ne)=>ne==="claude"?"codex":"claude");return}if(q.return){S();return}return}if(h==="model"){if(q.return){Q("name");return}if(q.backspace||q.delete){p((ne)=>ne.slice(0,-1));return}if(L&&!q.ctrl&&L.length===1)p((ne)=>ne+L);return}if(h==="name"){if(q.return){S();return}if(q.backspace||q.delete){m((ne)=>ne.slice(0,-1));return}if(L&&!q.ctrl&&L.length===1)m((ne)=>ne+L)}}),be.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[be.jsxDEV(I,{bold:!0,children:a?"\u65B0\u5EFA Agent Session":"New agent session"},void 0,!1,void 0,this),be.jsxDEV(G,{marginTop:1,children:be.jsxDEV(I,{color:h==="backend"?"cyan":void 0,bold:h==="backend",children:[h==="backend"?"\u25B6 ":" ",a?"\u540E\u7AEF":"backend",": ",s==="claude"?"\u25CF claude \u25CB codex":"\u25CB claude \u25CF codex"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),be.jsxDEV(G,{children:be.jsxDEV(I,{color:h==="model"?"cyan":void 0,bold:h==="model",children:[h==="model"?"\u25B6 ":" ",a?"\u6A21\u578B":"model",": ",d||(a?"\uFF08\u7559\u7A7A\u8D70\u9ED8\u8BA4\uFF09":"(default)"),h==="model"&&be.jsxDEV(I,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),be.jsxDEV(G,{children:be.jsxDEV(I,{color:h==="name"?"cyan":void 0,bold:h==="name",children:[h==="name"?"\u25B6 ":" ",a?"\u540D\u5B57":"name",": ",g||(a?"\uFF08\u7559\u7A7A\u81EA\u52A8\uFF09":"(auto)"),h==="name"&&be.jsxDEV(I,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),N&&be.jsxDEV(G,{marginTop:1,children:be.jsxDEV(I,{color:"red",children:["\u2717 ",N]},void 0,!0,void 0,this)},void 0,!1,void 0,this),C&&be.jsxDEV(G,{marginTop:1,children:be.jsxDEV(I,{color:"yellow",children:["\u23F3 ",a?"\u521B\u5EFA\u4E2D...":"creating..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this),be.jsxDEV(G,{marginTop:1,gap:2,children:[be.jsxDEV(I,{dimColor:!0,bold:!0,children:"Tab/\u2191\u2193"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:a?"\u5207\u5B57\u6BB5":"switch"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:a?"\u521B\u5EFA":"create"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,bold:!0,children:"ESC"},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:a?"\u53D6\u6D88":"cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var eo,be;var wF=O(async()=>{Mn();gg();await ha([Vo(),yF()]);eo=ye(ct(),1),be=ye($t(),1)});function LP({onLaunch:e,onExit:o,initialView:i="launcher",initialSessionSearch:a=!1}){let[s,u]=Li.useState(i),[d,p]=Li.useState([]),g=Li.useRef(null),m=Li.useRef(!1);Li.useEffect(()=>{if(m.current||i!=="launcher")return;m.current=!0,dF().then((v)=>{if(v)u("key-guide")})},[i]);let h=Li.useCallback((v)=>{if(p((S)=>[...S.slice(-4),v]),g.current)clearTimeout(g.current);g.current=setTimeout(()=>p([]),5000)},[]);Li.useEffect(()=>{let v=0;return wS({info:(S)=>h({text:S,type:"info"}),warn:(S)=>h({text:S,type:"warn"}),error:(S)=>h({text:S,type:"error"}),success:(S)=>h({text:S,type:"success"}),spin:(S)=>{let L=++v;return h({id:L,text:S,type:"spin"}),{stop:(q)=>{if(p((ne)=>{let se=ne.filter((le)=>le.id!==L);if(q)se.push({text:q,type:"success"});return se.slice(-5)}),g.current)clearTimeout(g.current);g.current=setTimeout(()=>p([]),5000)},update:(q)=>{if(p((ne)=>ne.map((se)=>se.id===L?{...se,text:q}:se)),g.current)clearTimeout(g.current);g.current=setTimeout(()=>p([]),5000)}}}}),()=>Nf()},[h]);let Q=Li.useCallback(()=>u("launcher"),[]),C={info:"cyan",warn:"yellow",error:"red",success:"green",spin:"yellow"},w={info:"\u2139",warn:"\u26A0",error:"\u2717",success:"\u2713",spin:"\u23F3"},N=(()=>{switch(s){case"launcher":return Zo.jsxDEV(KT,{initialSessionSearch:a,onResult:(v)=>{switch(v.type){case"launch":e(v);break;case"agent":u("agents");break;case"providers":u("providers");break;case"stats":u("stats");break;case"config":u("config");break;case"language":u("language");break;case"exit":o();break}}},void 0,!1,void 0,this);case"providers":return Zo.jsxDEV(XT,{onDone:(v)=>{if(v==="client-versions")u("client-versions");else Q()}},void 0,!1,void 0,this);case"agents":return Zo.jsxDEV(QF,{onDone:Q},void 0,!1,void 0,this);case"client-versions":return Zo.jsxDEV(EF,{onDone:()=>u("providers")},void 0,!1,void 0,this);case"stats":return Zo.jsxDEV(nF,{onExit:Q},void 0,!1,void 0,this);case"config":return Zo.jsxDEV(ry,{isReconfigure:!0,onDone:Q},void 0,!1,void 0,this);case"language":return Zo.jsxDEV(AF,{onDone:Q},void 0,!1,void 0,this);case"key-guide":return Zo.jsxDEV(fF,{onDone:(v)=>{if(v==="configure")u("config");else pF(v).then(()=>u("launcher"))}},void 0,!1,void 0,this)}})();return Zo.jsxDEV(G,{flexDirection:"column",children:[d.length>0&&Zo.jsxDEV(G,{flexDirection:"column",paddingX:2,children:d.map((v,S)=>Zo.jsxDEV(I,{color:C[v.type],dimColor:v.type==="info",children:[w[v.type]," ",v.text]},S,!0,void 0,this))},void 0,!1,void 0,this),N]},void 0,!0,void 0,this)}function _m(e={}){return new Promise((o)=>{let i=null;function a(){try{if(process.stdin.removeAllListeners(),process.stdin.isTTY)process.stdin.setRawMode(!1);process.stdin.pause(),process.stdin.unref()}catch{}}function s(d){i?.clear(),i?.unmount(),i=null,a(),Nf(),o(d)}function u(){i?.clear(),i?.unmount(),i=null,a(),Nf(),o(null)}i=Sm(Zo.jsxDEV(LP,{onLaunch:s,onExit:u,initialSessionSearch:e.initialSessionSearch},void 0,!1,void 0,this))})}function vF(){return new Promise((e)=>{let o=null;o=Sm(Zo.jsxDEV(ry,{isReconfigure:!1,onDone:(i)=>{o?.clear(),o?.unmount();try{if(process.stdin.removeAllListeners(),process.stdin.isTTY)process.stdin.setRawMode(!1);process.stdin.pause(),process.stdin.unref()}catch{}e(i)}},void 0,!1,void 0,this))})}var Li,Zo;var SF=O(async()=>{Lr();await ha([Vo(),YT(),$T(),oF(),aF(),uF(),gF(),CF(),wF()]);Li=ye(ct(),1),Zo=ye($t(),1)});var xF={};li(xF,{startApiKeySetup:()=>vF,startApp:()=>_m});var sy=O(async()=>{await SF()});function jr(e){if(yc||process.env.TAKO_DEBUG==="1")process.stderr.write(`[announcements] ${e}
|
|
698
698
|
`)}function NF(e){if(!e)return null;if(e.type!=="tako"&&e.type!=="custom")return null;if(!e.baseUrl||!e.apiKey)return null;return{baseUrl:e.baseUrl.replace(/\/+$/,""),apiKey:e.apiKey}}async function OP(e,o){let i=`${e}/v1/announcements/popup`;try{let a=await fetch(i,{headers:{Authorization:`Bearer ${o}`},signal:AbortSignal.timeout(MP)});if(!a.ok)return jr(`HTTP ${a.status} from ${i}\uFF08par \u53EF\u80FD\u672A\u90E8\u7F72\u65B0\u8DEF\u7531 /v1/announcements/popup\uFF09`),null;let u=(await a.json())?.announcement;if(!u)return jr("\u8FD4\u56DE announcement=null\uFF08par \u540E\u53F0\u6CA1\u6709 published+popup=true \u7684\u516C\u544A\uFF09"),null;if(typeof u.id!=="string"||typeof u.title!=="string")return jr(`payload \u7F3A id/title\uFF0C\u4E22\u5F03\uFF1A${JSON.stringify(u)}`),null;return jr(`\u62C9\u5230\u516C\u544A id=${u.id} title=${u.title} popup_once=${!!u.popup_once}`),{id:u.id,title:u.title,content:u.content??"",type:u.type,popup_once:!!u.popup_once}}catch(a){return jr(`fetch \u5931\u8D25\uFF1A${a instanceof Error?a.message:String(a)}`),null}}async function _P(e){return((await tt()).seenAnnouncementIds??[]).includes(e)}async function UP(e){let o=await tt(),i=o.seenAnnouncementIds??[];if(i.includes(e))return;let a=[...i,e];if(a.length>bF)a.splice(0,a.length-bF);o.seenAnnouncementIds=a,await Go(o)}async function GP(){let e=NF(await pi());if(e)return e;for(let o of await Wo()){let i=NF(o);if(i)return i}return null}async function RF(){let e=await GP();if(!e){jr("\u8DF3\u8FC7\uFF1A\u6CA1\u6709\u53EF\u7528\u7684 tako/custom provider\uFF08apiKey + baseUrl\uFF09");return}jr(`\u67E5\u8BE2\u516C\u544A\uFF1A${e.baseUrl}/v1/announcements/popup`);let o=await OP(e.baseUrl,e.apiKey);if(!o)return;if(o.popup_once&&await _P(o.id)){jr(`\u5DF2\u5728 seenAnnouncementIds\uFF0C\u8DF3\u8FC7\uFF1A${o.id}`);return}if(jr(`\u5F39\u7A97\uFF1A${o.id}`),await HS(o),o.popup_once)await UP(o.id),jr(`\u6807\u8BB0\u5DF2\u770B\u8FC7\uFF1A${o.id}`)}var MP=2000,bF=100;var TF=O(()=>{on();bi()});var FF={};li(FF,{handleLaunchResult:()=>uy,runPreLaunchSetup:()=>Ay});async function Ay(){await $0(),await Z0(),await s1(),await Promise.race([U0(await Wo()),new Promise((e)=>setTimeout(e,3000))]),await RF()}async function uy(e){let o=Ln(e.clientId);if(!o)return!1;$n("menu_action",{action:"launch",client_id:e.clientId});let i=await $f(e.clientId);if(!i)return Fe.warn(Ge("cli.noProvider")||"\u672A\u914D\u7F6E\u53EF\u7528\u7684\u670D\u52A1\u5546"),!1;let s=process.platform==="win32"&&!!process.env.TAKO_WINDOWS_HANDOFF_FILE,u=await Pu(o,{projectPath:e.projectPath,args:e.args,envVars:e.envVars,selectedOptionIds:e.selectedOptionIds,providerContext:i,relaunchTakoOnWindows:s});if(!u.success)return Fe.error(u.error||Ge("cli.launchFailed")),!1;if(s)return!0;return!1}var ly=O(()=>{Kf();zn();Mn();Or();Lr();bi();_h();TF();pA()});var kF={};li(kF,{runSessionsCommand:()=>JP});function Od(e,o){let i=e.indexOf(o);return i>=0?e[i+1]:void 0}function HP(e){if(!e)return;let o=/^(\d+)([dhw])$/i.exec(e);if(o){let a=o[2].toLowerCase(),s=Number(o[1])*(a==="h"?0.041666666666666664:a==="w"?7:1);return Date.now()-s*86400000}let i=Date.parse(e);if(!Number.isFinite(i))throw Error(`Invalid --after value: ${e}`);return i}function PP(e){if(e<1024)return`${e} B`;if(e<1048576)return`${(e/1024).toFixed(1)} KiB`;return`${(e/1024/1024).toFixed(1)} MiB`}function zP(e,o){let i=o==="search"?e.slice(1):e,a=new Set(["--source","--cwd","--project","--after","--limit"]),s=[];for(let u=0;u<i.length;u++){if(a.has(i[u])){u++;continue}if(!i[u].startsWith("--"))s.push(i[u])}return s.join(" ")}async function JP(e){if(e.length===0&&process.stdin.isTTY&&process.stdout.isTTY){let{startApp:i}=await sy().then(() => xF),{handleLaunchResult:a}=await Promise.resolve().then(() => (ly(),FF)),s=await i({initialSessionSearch:!0});if(s?.type==="launch")await a(s);return}let o=Dg();try{let i=e[0]??"search";if(i==="index"){if(e.includes("--clear")){await h2(o),console.log("Cleared the native session index.");return}if(e.includes("--status")){let g=o.status();console.log(`${g.sessions} sessions from ${g.sourceFiles} files \xB7 ${PP(g.bytes)} \xB7 schema v${g.schemaVersion}
|
|
699
699
|
${g.path}`);return}let p=e.includes("--rebuild")?await C2(o):await td(o);console.log(`Indexed ${p} native session files.`);return}if(await td(o),i==="show"){let p=o.getSession(e[1]??"");if(!p)throw Error("Session not found");console.log(JSON.stringify({session:p,messages:o.getMessages(p.key)},null,2));return}if(i==="resume"){let p=o.getSession(e[1]??"");if(!p)throw Error("Session not found");await B2(p);return}let a=zP(e,i),s=Od(e,"--source")?.split(",").filter((p)=>p==="claude"||p==="codex"||p==="gemini"||p==="pi"),u=Number(Od(e,"--limit")??50),d=yg(o,a,{deep:e.includes("--deep"),sources:s,cwd:Od(e,"--cwd"),project:Od(e,"--project"),after:HP(Od(e,"--after")),limit:Number.isFinite(u)&&u>0?u:50,currentCwd:process.cwd()});if(e.includes("--json"))console.log(JSON.stringify(d,null,2));else for(let p of d)console.log(`${p.session.key} ${p.session.projectName??"-"} ${p.session.title??"(untitled)"}
|
|
@@ -850,10 +850,10 @@ Install: tako skill install <name>`),console.log(`Install all: tako skill instal
|
|
|
850
850
|
Usage: tako models [list] [--refresh] [--json]
|
|
851
851
|
`),1;let a=o.loadConfig??tt,s=o.refresh??xf,u=o.read??Zi,d=o.now??(()=>Date.now()),p=o.columns??(()=>process.stdout.columns??80),g=await a(),m=qP(g);if(i.refresh&&m.length>0)await $P(m,s);let h=m.map((C)=>XP(C,u)),Q=new Date(d()).toISOString();if(i.json)process.stdout.write(i9(h,i.refresh,Q));else process.stdout.write(o9(h,p()));return 0}var UF,ZP=5;var HF=O(()=>{on();G0();UF=["openai","claude"]});Uc();Lr();Tc();on();Mn();Or();Mf();import{join as nr}from"path";function wx(e,o){return["@echo off",'set "TAKO_WINDOWS_HANDOFF_FILE=%TEMP%\\tako-handoff-%RANDOM%-%RANDOM%.ps1"','if exist "%TAKO_WINDOWS_HANDOFF_FILE%" del "%TAKO_WINDOWS_HANDOFF_FILE%" >nul 2>nul',`"${e}" "${o}" %*`,'set "TAKO_EXIT_CODE=%ERRORLEVEL%"','if not exist "%TAKO_WINDOWS_HANDOFF_FILE%" exit /b %TAKO_EXIT_CODE%','powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%TAKO_WINDOWS_HANDOFF_FILE%"',"exit /b %ERRORLEVEL%",""].join(`\r
|
|
852
852
|
`)}function vx(e,o){return['$env:TAKO_WINDOWS_HANDOFF_FILE = Join-Path ([System.IO.Path]::GetTempPath()) ("tako-handoff-{0}-{1}.ps1" -f $PID, [System.Guid]::NewGuid().ToString("N"))',"Remove-Item -LiteralPath $env:TAKO_WINDOWS_HANDOFF_FILE -Force -ErrorAction SilentlyContinue",`& "${e}" "${o}" @args`,"$code = $LASTEXITCODE","if (Test-Path -LiteralPath $env:TAKO_WINDOWS_HANDOFF_FILE) {"," powershell.exe -NoProfile -ExecutionPolicy Bypass -File $env:TAKO_WINDOWS_HANDOFF_FILE"," exit $LASTEXITCODE","}","exit $code",""].join(`\r
|
|
853
|
-
`)}var Dh="tako-cli",gs="0.3.
|
|
853
|
+
`)}var Dh="tako-cli",gs="0.3.39";function RO(){return[So,"update",Dh,"--latest"]}function TO(){return[So,"add",`${Dh}@latest`]}function FO(e,o){let i=e.split(".").map(Number),a=o.split(".").map(Number);for(let s=0;s<3;s++){let u=i[s]||0,d=a[s]||0;if(u>d)return 1;if(u<d)return-1}return 0}async function kO(){try{let e=await Ni(),o=await fetch(`${e}/${Dh}/latest`,{signal:AbortSignal.timeout(5000)});if(!o.ok)return null;return(await o.json()).version||null}catch{return null}}async function Sx(){let e=await kO();if(!e)return{hasUpdate:!1,currentVersion:gs};return{hasUpdate:FO(e,gs)>0,latestVersion:e,currentVersion:gs}}async function xx(){let e=await import("fs/promises"),o=nr(Vt,"bin"),i=nr(o,"tako"),a=nr(Xi,"node_modules/tako-cli/dist/index.js");if(await e.mkdir(o,{recursive:!0}),process.platform==="win32")await e.writeFile(nr(o,"tako.cmd"),wx(So,a)),await e.writeFile(nr(o,"tako.ps1"),vx(So,a));else{let u=`#!/bin/bash
|
|
854
854
|
exec "${So}" "${a}" "$@"
|
|
855
855
|
`;await e.writeFile(i,u,{mode:493})}}async function bx(e){let o=di(),i=`\u6B63\u5728\u66F4\u65B0\u5230 v${e}`;o.start(i);try{let a=await Ni(),s=await import("fs/promises");await s.mkdir(Xi,{recursive:!0});let u=nr(Xi,"package.json");try{await s.access(u)}catch{await s.writeFile(u,JSON.stringify({name:"tako-local",private:!0},null,2))}let d=Bun.spawn(RO(),{cwd:Xi,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:a}}),p=await fs(d,i,(g)=>o.update(g));if(await d.exited,d.exitCode===0)return await xx(),$n("cli_updated",{from_version:gs,to_version:e}),o.stop(`\u66F4\u65B0\u6210\u529F\uFF01\u5DF2\u66F4\u65B0\u5230 v${e}`),!0;else return o.stop(),Fe.warn(`\u66F4\u65B0\u5931\u8D25: ${Uu(p)}`),!1}catch(a){return o.stop(),Fe.warn(`\u66F4\u65B0\u5931\u8D25: ${Uu(a instanceof Error?a.message:void 0)}`),!1}}async function LO(){let e=await import("fs/promises"),o=nr(Xi,"bun.lock");try{await e.unlink(o)}catch{}}async function MO(){let e=await import("fs/promises");try{let o=await Ni();await e.mkdir(Xi,{recursive:!0});let i=nr(Xi,"package.json");try{await e.access(i)}catch{await e.writeFile(i,JSON.stringify({name:"tako-local",private:!0},null,2))}await LO();let a=Bun.spawn(TO(),{cwd:Xi,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:o}});return await a.exited,a.exitCode===0}catch{return!1}}async function OO(){let e=await import("fs/promises"),o=nr(Vt,"bin"),i=nr(o,"tako"),a=nr(Xi,"node_modules/tako-cli/dist/index.js");try{let s=await e.readFile(i,"utf-8");if(s.includes("bun run tako-cli")||s.includes("run tako-cli")){Fe.info(Ge("updater.migrating"));let u=!1;try{await e.access(a),u=!0}catch{u=!1}if(!u){let d=di();if(d.start(Ge("updater.installingLocally")),!await MO())return d.stop(Ge("updater.migrationFailed")),!1;d.stop(Ge("updater.installComplete"))}return await xx(),!0}}catch{}return!1}async function BA(){try{if(await OO())Fe.info(Ge("updater.migrationComplete")),process.exit(0);let o=await Sx();if(o.hasUpdate&&o.latestVersion){if(Fe.warn(Ge("updater.newVersionAvailable",{version:o.latestVersion,current:gs})),await bx(o.latestVersion))Fe.info(Ge("updater.pleaseRestart")),process.exit(0)}}catch{}}async function Nx(){console.log(`Tako CLI \u5F53\u524D\u7248\u672C: v${gs}`),console.log("\u6B63\u5728\u68C0\u67E5\u66F4\u65B0...");let e=await Sx();if(!e.hasUpdate){if(e.latestVersion)console.log(`\u5DF2\u662F\u6700\u65B0\u7248\u672C v${gs}`);else console.log("\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u540E\u91CD\u8BD5");return}if(console.log(`\u53D1\u73B0\u65B0\u7248\u672C: v${e.latestVersion}\uFF08\u5F53\u524D: v${gs}\uFF09`),console.log("\u6B63\u5728\u66F4\u65B0..."),await bx(e.latestVersion))console.log("\u66F4\u65B0\u6210\u529F\uFF01\u8BF7\u91CD\u542F tako \u4EE5\u4F7F\u7528\u65B0\u7248\u672C\u3002");else console.error("\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u624B\u52A8\u6267\u884C:"),console.error(" cd ~/.tako/cli && bun update tako-cli --latest"),process.exit(1)}zn();Kf();Mn();Or();import{homedir as n_}from"os";var Rt={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"};var un={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",reset:"\x1B[0m"};var xn={directory:{icon:Rt.brightYellow,text:Rt.brightGreen},git:{icon:Rt.brightBlue,text:Rt.brightBlue,clean:Rt.brightGreen,dirty:Rt.brightYellow,conflict:Rt.brightRed},model:{icon:Rt.brightCyan,text:Rt.brightCyan},version:{icon:Rt.brightWhite,text:Rt.brightBlack},outputStyle:{icon:Rt.brightMagenta,text:Rt.brightMagenta},context:{icon:Rt.brightMagenta,low:Rt.brightGreen,medium:Rt.brightYellow,high:Rt.brightRed},todayUsage:{icon:Rt.brightGreen,text:Rt.brightGreen},separator:Rt.brightBlack},va={directory:{nerd:"\uF07B",plain:"\uD83D\uDCC1"},git:{nerd:"\uE725",plain:"\uD83C\uDF3F"},model:{nerd:"\uF11B",plain:"\uD83E\uDD16"},version:{nerd:"\uF412",plain:"\uD83D\uDCBE"},outputStyle:{nerd:"\uF12F5",plain:"\uD83C\uDFAF"},context:{nerd:"\uF0E7",plain:"\u26A1"},todayUsage:{nerd:"\uF155",plain:"\uD83D\uDCB0"},gitClean:"\u2713",gitDirty:"\u25CF",gitConflict:"\u26A0",gitAhead:"\u2191",gitBehind:"\u2193"};function t_(){return!1}function _r(e){let o=va[e];if(typeof o==="string")return o;return t_()?o.nerd:o.plain}class Yf{id="directory";render(e){let o=this.formatPath(e.workspace.current_dir),i=_r("directory");return`${xn.directory.icon}${i}${un.reset} ${xn.directory.text}${o}${un.reset}`}formatPath(e){let o=n_();if(e===o)return"~";if(e.startsWith(o+"/"))return"~"+e.slice(o.length);return e}}class Wf{id="git";async render(e){let o=e.workspace.current_dir;if(!await this.isGitRepository(o))return null;let a=await this.getBranch(o);if(!a)return null;let{status:s,statusColor:u}=await this.getStatus(o),{ahead:d,behind:p}=await this.getAheadBehind(o),g=_r("git"),m=`${xn.git.icon}${g}${un.reset} ${xn.git.text}${a}${un.reset}`;if(m+=` ${u}${s}${un.reset}`,d>0)m+=` ${xn.git.clean}${va.gitAhead}${d}${un.reset}`;if(p>0)m+=` ${xn.git.dirty}${va.gitBehind}${p}${un.reset}`;return m}async isGitRepository(e){try{return await Bun.spawn(["git","rev-parse","--git-dir"],{cwd:e,stdout:"pipe",stderr:"pipe"}).exited===0}catch{return!1}}async getBranch(e){try{let o=Bun.spawn(["git","branch","--show-current"],{cwd:e,stdout:"pipe",stderr:"pipe"}),i=await new Response(o.stdout).text();if(await o.exited===0&&i.trim())return i.trim();let s=Bun.spawn(["git","rev-parse","--short","HEAD"],{cwd:e,stdout:"pipe",stderr:"pipe"}),u=await new Response(s.stdout).text();if(await s.exited===0&&u.trim())return`detached:${u.trim()}`;return null}catch{return null}}async getStatus(e){try{let o=Bun.spawn(["git","status","--porcelain"],{cwd:e,stdout:"pipe",stderr:"pipe"}),i=await new Response(o.stdout).text();if(await o.exited!==0)return{status:va.gitClean,statusColor:xn.git.clean};let s=i.trim();if(!s)return{status:va.gitClean,statusColor:xn.git.clean};if(s.includes("UU")||s.includes("AA")||s.includes("DD"))return{status:va.gitConflict,statusColor:xn.git.conflict};return{status:va.gitDirty,statusColor:xn.git.dirty}}catch{return{status:va.gitClean,statusColor:xn.git.clean}}}async getAheadBehind(e){try{let o=Bun.spawn(["git","rev-list","--count","@{u}..HEAD"],{cwd:e,stdout:"pipe",stderr:"pipe"}),i=await new Response(o.stdout).text(),s=await o.exited===0?parseInt(i.trim(),10)||0:0,u=Bun.spawn(["git","rev-list","--count","HEAD..@{u}"],{cwd:e,stdout:"pipe",stderr:"pipe"}),d=await new Response(u.stdout).text(),g=await u.exited===0?parseInt(d.trim(),10)||0:0;return{ahead:s,behind:g}}catch{return{ahead:0,behind:0}}}}var o_={"claude-opus-4-5-20251101":"Opus 4.5","claude-opus-4-5":"Opus 4.5","claude-sonnet-4-5-20250514":"Sonnet 4.5","claude-sonnet-4-5":"Sonnet 4.5","claude-sonnet-4-20250514":"Sonnet 4","claude-sonnet-4":"Sonnet 4","claude-sonnet-3-5-20241022":"Sonnet 3.5","claude-3-5-sonnet-20241022":"Sonnet 3.5","claude-3-5-sonnet":"Sonnet 3.5","claude-haiku-3-5-20241022":"Haiku 3.5","claude-3-5-haiku-20241022":"Haiku 3.5","claude-3-5-haiku":"Haiku 3.5"};class jf{id="model";render(e){let o=e.model.id,i=o_[o]||this.simplifyModelName(e.model.display_name),a=_r("model");return`${xn.model.icon}${a}${un.reset} ${xn.model.text}${i}${un.reset}`}simplifyModelName(e){let o=e.replace(/^Claude\s+/i,"");return o=o.replace(/-\d{8}$/,""),o}}pA();var i_=200000,r_=8192,a_=20,s_=13000,A_="TAKO_MODEL_CONTEXT_WINDOW";function u_(e,o=process.env[A_]){if(o){let i=Number(o);if(Number.isSafeInteger(i)&&i>0)return i}return vc(e)?.contextWindow??i_}function l_(e){let o=e.context_window?.current_usage;if(!o)return null;return o.input_tokens+o.cache_creation_input_tokens+o.cache_read_input_tokens}function c_(e){let o=Math.max(0,e-Math.min(r_,20000));return Math.max(0,Math.min(o-Math.round(o*a_/100),o-s_))}class Ur{id="context";static cache=null;static CACHE_TTL=5000;async render(e){let i=l_(e)??await this.getTokensWithCache(e.transcript_path),a=u_(e.model.id),s=c_(a),u=Math.min(100,Math.max(0,Math.ceil((s-(i??0))/s*100))),d=_r("context"),p=u<=20?Rt.brightRed:u<=50?Rt.brightYellow:Rt.brightGreen;return`${xn.context.icon}${d}${un.reset} ${p}${u}%${un.reset}`}async getTokensWithCache(e){let o=Date.now();if(Ur.cache&&Ur.cache.path===e&&o-Ur.cache.timestamp<Ur.CACHE_TTL)return Ur.cache.tokens;let i=await this.parseTranscriptTokens(e);return Ur.cache={path:e,tokens:i,timestamp:o},i}async parseTranscriptTokens(e){try{let o=Bun.file(e);if(!await o.exists())return null;let i=await o.text();if(!i.trim())return null;let a=i.split(`
|
|
856
|
-
`).filter((s)=>s.trim());for(let s=a.length-1;s>=0;s--)try{let u=JSON.parse(a[s]);if(u.type==="assistant"&&u.message?.usage){let d=u.message.usage;return(d.input_tokens||0)+(d.cache_creation_input_tokens||0)+(d.cache_read_input_tokens||0)}}catch{continue}return null}catch{return null}}}Vf();bi();class Xf{id="quota";async render(e){let o=await this.tryRenderOfficial();if(o)return o;return this.renderSessionCost(e)}async tryRenderOfficial(){try{let e=await Qa("claude-code")??await pi();if(!e)return null;let o=await zc(e);if(o.status!=="ok")return null;switch(o.provider){case"tako":return this.renderTako(o);case"claude-subscription":return this.renderClaudeSub(o);case"codex-subscription":return this.renderCodexSub(o);default:return null}}catch{return null}}renderTako(e){if(e.status!=="ok")return null;if(!!(e.primary?.costLimit||e.secondary?.costLimit||e.daily?.costLimit))return this.renderSub(e);let i=e.daily??e.primary??e.secondary;if(!i)return null;let a=i.costUsed??0;return`${this.icon()} ${Rt.brightGreen}Day:${this.fmtCost(a)}${un.reset}`}renderSub(e){let o=(a,s,u)=>{if(a&&a>=1440)return`${Math.round(a/1440)}d`;if(a)return`${Math.round(a/60)}h`;return u?`${u}d`:`${s}h`},i=[];if(e.primary)i.push(this.remainChunk(o(e.primary.windowMinutes,5),e.primary.usedPct));if(e.secondary)i.push(this.remainChunk(o(e.secondary.windowMinutes,24,7),e.secondary.usedPct));if(e.modelLimits?.opus)i.push(this.remainChunk("opus",e.modelLimits.opus.usedPct));if(!i.length)return null;return`${this.icon()} ${i.join(`${un.dim} \xB7 ${un.reset}`)}`}renderClaudeSub=this.renderSub;renderCodexSub=this.renderSub;pctChunk(e,o){let i=o>=90?Rt.brightRed:o>=70?Rt.brightYellow:Rt.brightGreen;return`${e}:${i}${o}%${un.reset}`}remainChunk(e,o){let i=Math.max(0,Math.min(100,100-Math.round(o))),a=i<=10?Rt.brightRed:i<=30?Rt.brightYellow:Rt.brightGreen;return`${e} \u5269 ${a}${i}%${un.reset}`}renderSessionCost(e){let o=e.cost?.total_cost_usd;if(o==null||o<=0)return null;return`${this.icon()} ${Rt.brightGreen}Session:${this.fmtCost(o)}${un.reset}`}icon(){return`${xn.todayUsage.icon}${_r("todayUsage")}${un.reset}`}fmtCost(e){if(e>=100)return`$${Math.round(e)}`;if(e>=10)return`$${e.toFixed(1)}`;return`$${e.toFixed(2)}`}}class Lh{separator=`${xn.separator} \u2502 ${un.reset}`;render(e){let o=["directory","git","model","context","quota"],i=[];for(let a of o){let s=e.get(a);if(s)i.push(s)}return i.join(this.separator)}}import{join as yA,dirname as x_}from"path";import{homedir as Mh}from"os";import{mkdir as b_}from"fs/promises";var r1=yA(Mh(),".tako"),N_=yA(r1,"cli"),R_=yA(r1,"bin",process.platform==="win32"?"tako.cmd":"tako");function T_(){if(process.platform==="win32")return yA(process.env.APPDATA||yA(Mh(),"AppData","Roaming"),"claude","settings.json");return yA(Mh(),".claude","settings.json")}var F_=process.platform==="win32",k_="0.1.48";function L_(e,o){let i=e.split(".").map(Number),a=o.split(".").map(Number),s=Math.max(i.length,a.length);for(let u=0;u<s;u++){let d=i[u]||0,p=a[u]||0;if(d!==p)return d-p}return 0}async function M_(){let e=yA(N_,"node_modules","tako-cli","package.json");try{let o=Bun.file(e);if(!await o.exists())return null;return(await o.json()).version||null}catch{return null}}async function O_(){let e=await M_();if(!e)return!1;return L_(e,k_)>=0}function __(){return R_}function U_(){return`"${G_(__())}" statusline`}function G_(e){if(F_)return e.replace(/\\/g,"/");return e}async function Oh(){if(!await O_())return;let o=T_(),i={};try{let u=Bun.file(o);if(await u.exists())i=await u.json()}catch{}let a={type:"command",command:U_(),padding:0},s=typeof i.statusLine==="object"&&i.statusLine!==null?i.statusLine.command:null;if(typeof s==="string"&&s.includes("tako statusline"))return;i.statusLine=a,await b_(x_(o),{recursive:!0}),await Bun.write(o,JSON.stringify(i,null,2))}var H_=[new Yf,new Wf,new jf,new Ur,new Xf];async function P_(e){let o=await Promise.all(H_.map(async(s)=>{try{let u=await s.render(e);return{id:s.id,content:u}}catch{return{id:s.id,content:null}}})),i=new Map;for(let{id:s,content:u}of o)i.set(s,u);return new Lh().render(i)}async function a1(){try{let e=await Bun.stdin.json(),o=await P_(e);console.log(o)}catch{process.exit(0)}}_h();nh();zf();var z_={"claude-code":{optionId:"skip-permissions",flag:"--dangerously-skip-permissions"},codex:{optionId:"bypass-sandbox",flag:"--dangerously-bypass-approvals-and-sandbox"}};async function Ju(e,o,i,a){let s=o.filter((p)=>p!==i),u=await J_(e,s,a);if(e!=="claude-code")return u?[u,...s]:s;let d=[];if(u)d.push(u);for(let p=0;p<s.length;p++){let g=s[p];if(g==="--model"&&p+1<s.length){d.push(g,Lu(s[p+1])),p++;continue}if(g.startsWith("--model=")){let m=g.slice(8);d.push(`--model=${Lu(m)}`);continue}d.push(g)}return d}async function J_(e,o,i){let a=z_[e];if(!a)return null;if(o.includes(a.flag))return null;return(await(i?.getLastSelectedOptionIds??Pf)(e)).includes(a.optionId)?a.flag:null}pA();Gh();on();var Gm="0.3.
|
|
856
|
+
`).filter((s)=>s.trim());for(let s=a.length-1;s>=0;s--)try{let u=JSON.parse(a[s]);if(u.type==="assistant"&&u.message?.usage){let d=u.message.usage;return(d.input_tokens||0)+(d.cache_creation_input_tokens||0)+(d.cache_read_input_tokens||0)}}catch{continue}return null}catch{return null}}}Vf();bi();class Xf{id="quota";async render(e){let o=await this.tryRenderOfficial();if(o)return o;return this.renderSessionCost(e)}async tryRenderOfficial(){try{let e=await Qa("claude-code")??await pi();if(!e)return null;let o=await zc(e);if(o.status!=="ok")return null;switch(o.provider){case"tako":return this.renderTako(o);case"claude-subscription":return this.renderClaudeSub(o);case"codex-subscription":return this.renderCodexSub(o);default:return null}}catch{return null}}renderTako(e){if(e.status!=="ok")return null;if(!!(e.primary?.costLimit||e.secondary?.costLimit||e.daily?.costLimit))return this.renderSub(e);let i=e.daily??e.primary??e.secondary;if(!i)return null;let a=i.costUsed??0;return`${this.icon()} ${Rt.brightGreen}Day:${this.fmtCost(a)}${un.reset}`}renderSub(e){let o=(a,s,u)=>{if(a&&a>=1440)return`${Math.round(a/1440)}d`;if(a)return`${Math.round(a/60)}h`;return u?`${u}d`:`${s}h`},i=[];if(e.primary)i.push(this.remainChunk(o(e.primary.windowMinutes,5),e.primary.usedPct));if(e.secondary)i.push(this.remainChunk(o(e.secondary.windowMinutes,24,7),e.secondary.usedPct));if(e.modelLimits?.opus)i.push(this.remainChunk("opus",e.modelLimits.opus.usedPct));if(!i.length)return null;return`${this.icon()} ${i.join(`${un.dim} \xB7 ${un.reset}`)}`}renderClaudeSub=this.renderSub;renderCodexSub=this.renderSub;pctChunk(e,o){let i=o>=90?Rt.brightRed:o>=70?Rt.brightYellow:Rt.brightGreen;return`${e}:${i}${o}%${un.reset}`}remainChunk(e,o){let i=Math.max(0,Math.min(100,100-Math.round(o))),a=i<=10?Rt.brightRed:i<=30?Rt.brightYellow:Rt.brightGreen;return`${e} \u5269 ${a}${i}%${un.reset}`}renderSessionCost(e){let o=e.cost?.total_cost_usd;if(o==null||o<=0)return null;return`${this.icon()} ${Rt.brightGreen}Session:${this.fmtCost(o)}${un.reset}`}icon(){return`${xn.todayUsage.icon}${_r("todayUsage")}${un.reset}`}fmtCost(e){if(e>=100)return`$${Math.round(e)}`;if(e>=10)return`$${e.toFixed(1)}`;return`$${e.toFixed(2)}`}}class Lh{separator=`${xn.separator} \u2502 ${un.reset}`;render(e){let o=["directory","git","model","context","quota"],i=[];for(let a of o){let s=e.get(a);if(s)i.push(s)}return i.join(this.separator)}}import{join as yA,dirname as x_}from"path";import{homedir as Mh}from"os";import{mkdir as b_}from"fs/promises";var r1=yA(Mh(),".tako"),N_=yA(r1,"cli"),R_=yA(r1,"bin",process.platform==="win32"?"tako.cmd":"tako");function T_(){if(process.platform==="win32")return yA(process.env.APPDATA||yA(Mh(),"AppData","Roaming"),"claude","settings.json");return yA(Mh(),".claude","settings.json")}var F_=process.platform==="win32",k_="0.1.48";function L_(e,o){let i=e.split(".").map(Number),a=o.split(".").map(Number),s=Math.max(i.length,a.length);for(let u=0;u<s;u++){let d=i[u]||0,p=a[u]||0;if(d!==p)return d-p}return 0}async function M_(){let e=yA(N_,"node_modules","tako-cli","package.json");try{let o=Bun.file(e);if(!await o.exists())return null;return(await o.json()).version||null}catch{return null}}async function O_(){let e=await M_();if(!e)return!1;return L_(e,k_)>=0}function __(){return R_}function U_(){return`"${G_(__())}" statusline`}function G_(e){if(F_)return e.replace(/\\/g,"/");return e}async function Oh(){if(!await O_())return;let o=T_(),i={};try{let u=Bun.file(o);if(await u.exists())i=await u.json()}catch{}let a={type:"command",command:U_(),padding:0},s=typeof i.statusLine==="object"&&i.statusLine!==null?i.statusLine.command:null;if(typeof s==="string"&&s.includes("tako statusline"))return;i.statusLine=a,await b_(x_(o),{recursive:!0}),await Bun.write(o,JSON.stringify(i,null,2))}var H_=[new Yf,new Wf,new jf,new Ur,new Xf];async function P_(e){let o=await Promise.all(H_.map(async(s)=>{try{let u=await s.render(e);return{id:s.id,content:u}}catch{return{id:s.id,content:null}}})),i=new Map;for(let{id:s,content:u}of o)i.set(s,u);return new Lh().render(i)}async function a1(){try{let e=await Bun.stdin.json(),o=await P_(e);console.log(o)}catch{process.exit(0)}}_h();nh();zf();var z_={"claude-code":{optionId:"skip-permissions",flag:"--dangerously-skip-permissions"},codex:{optionId:"bypass-sandbox",flag:"--dangerously-bypass-approvals-and-sandbox"}};async function Ju(e,o,i,a){let s=o.filter((p)=>p!==i),u=await J_(e,s,a);if(e!=="claude-code")return u?[u,...s]:s;let d=[];if(u)d.push(u);for(let p=0;p<s.length;p++){let g=s[p];if(g==="--model"&&p+1<s.length){d.push(g,Lu(s[p+1])),p++;continue}if(g.startsWith("--model=")){let m=g.slice(8);d.push(`--model=${Lu(m)}`);continue}d.push(g)}return d}async function J_(e,o,i){let a=z_[e];if(!a)return null;if(o.includes(a.flag))return null;return(await(i?.getLastSelectedOptionIds??Pf)(e)).includes(a.optionId)?a.flag:null}pA();Gh();on();var Gm="0.3.39",a9=!0;function Bl(e){return a9&&!e}function s9(){console.log(`
|
|
857
857
|
${Ge("cli.version",{version:Gm})}
|
|
858
858
|
|
|
859
859
|
${Ge("cli.usage")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tako-cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.39",
|
|
4
4
|
"description": "Tako CLI — unified launcher for AI coding tools (Claude Code, Codex, Pi, Gemini) with multi-agent session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/tako-dev/cli#readme",
|