tako-cli 0.3.36 → 0.3.37
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 FS((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 r8,writeFileSync as a8,mkdirSync as s8}from"fs";import{join as OS}from"path";import{homedir as _S}from"os";function u8(){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 l8(){try{let e=r8(US,"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>A8)return null;return o.region}catch{return null}}function MS(e){try{s8(OS(_S(),".tako"),{recursive:!0}),a8(US,JSON.stringify({region:e,detectedAt:Date.now()}),"utf-8")}catch{}}function c8(){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 d8(){if(Rf)return Rf;return Rf=(async()=>{let o=[p8,f8,g8,m8].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"}})(),Rf}async function Mr(){if(ku)return ku;let e=u8();if(e)return ku=e,e;let o=l8();if(o)return ku=o,o;let i=c8();if(i)return ku=i,MS(i),i;let a=await d8();return ku=a,MS(a),a}async function p8(){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 f8(){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 g8(){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 m8(){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 E8(){let e=await Mr();return mA[e]}async function Ni(){return(await E8()).npm}function GS(){return"curl -fsSL https://bun.sh/install | bash"}async function C8(){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 HS(){let e=mA.cn.bunBinary,o=await C8(),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 Z0(){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 ku=null,Rf=null,US,A8=2592000000,mA;var Nc=O(()=>{Mn();Lr();US=OS(_S(),".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 h8=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)}},PS=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 h8({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 zS=()=>{};function JS(){if(!Lu)Lu=new PS({clientId:I8,clientSecret:B8,apiUrl:y8});return Lu}function KS(e,o,i){let a=JS().track(e,{profileId:o,...i}).catch(()=>{});Tf.push(a)}function YS(e,o){let{email:i,...a}=o,s=JS().identify({profileId:e,...typeof i==="string"?{email:i}:{},firstName:String(a.platform||""),properties:a}).catch(()=>{});Tf.push(s)}async function WS(){if(await Promise.allSettled(Tf),Tf.length=0,Lu){try{Lu.flush()}catch{}Lu=null}}var I8="d65a6d4b-f702-4af6-98e7-bdb999e01d5f",B8="sec_1e0ea34016bc3a5f8ef5",y8="https://op.shiroha.tech/api",Lu=null,Tf;var jS=O(()=>{zS();Tf=[]});function qS(){return{cli_version:D8,platform:process.platform,arch:process.arch,locale:xi(),node_version:process.version}}function VS(e){return Bun.hash(e).toString(16).slice(0,8)}var D8="0.3.36";var eh=O(()=>{Mn()});async function XS(){if(Mu!==null)return Mu;try{return Mu=(await tt()).telemetryEnabled!==!1,Mu}catch{return Mu=!1,!1}}async function $S(){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(th)return;try{if(!await XS())return;let e=await tt(),o=await $S();if(o==="anonymous")return;let a=(e.providers??[]).find((u)=>u.email)?.email,s=await Mr();YS(o,{...a?{email:a}:{},region:s,locale:xi(),first_seen_version:Q8,platform:process.platform,arch:process.arch}),th=!0}catch{}}function $n(e,o){w8(e,o).catch(()=>{})}async function w8(e,o){try{if(!await XS())return;let i=await $S();KS(e,i,{...qS(),...o})}catch{}}async function Rc(){await WS()}function wa(){Mu=null,th=!1}var Q8="0.3.36",th=!1,Mu=null;var Or=O(()=>{jS();on();Nc();Mn();eh();eh()});function b8(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(b8(o,s))};d();let p=setInterval(d,1000),g=(h)=>{if(!h)return;if(u.push(h),v8.test(h))s.phase="\u89E3\u6790\u4F9D\u8D56";else if(ZS.test(h)){s.phase="\u4E0B\u8F7D\u5E76\u89E3\u538B";let Q=h.match(ZS);if(Q)s.pkgCount=parseInt(Q[1],10)}else if(S8.test(h))s.phase="\u5199\u5165 lockfile";else if(x8.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 r8,writeFileSync as a8,mkdirSync as s8}from"fs";import{join as OS}from"path";import{homedir as _S}from"os";function u8(){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 l8(){try{let e=r8(US,"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>A8)return null;return o.region}catch{return null}}function MS(e){try{s8(OS(_S(),".tako"),{recursive:!0}),a8(US,JSON.stringify({region:e,detectedAt:Date.now()}),"utf-8")}catch{}}function c8(){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 d8(){if(Rf)return Rf;return Rf=(async()=>{let o=[p8,f8,g8,m8].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"}})(),Rf}async function Mr(){if(ku)return ku;let e=u8();if(e)return ku=e,e;let o=l8();if(o)return ku=o,o;let i=c8();if(i)return ku=i,MS(i),i;let a=await d8();return ku=a,MS(a),a}async function p8(){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 f8(){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 g8(){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 m8(){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 E8(){let e=await Mr();return mA[e]}async function Ni(){return(await E8()).npm}function GS(){return"curl -fsSL https://bun.sh/install | bash"}async function C8(){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 HS(){let e=mA.cn.bunBinary,o=await C8(),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 Z0(){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 ku=null,Rf=null,US,A8=2592000000,mA;var Nc=O(()=>{Mn();Lr();US=OS(_S(),".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 h8=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)}},PS=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 h8({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 zS=()=>{};function JS(){if(!Lu)Lu=new PS({clientId:I8,clientSecret:B8,apiUrl:y8});return Lu}function KS(e,o,i){let a=JS().track(e,{profileId:o,...i}).catch(()=>{});Tf.push(a)}function YS(e,o){let{email:i,...a}=o,s=JS().identify({profileId:e,...typeof i==="string"?{email:i}:{},firstName:String(a.platform||""),properties:a}).catch(()=>{});Tf.push(s)}async function WS(){if(await Promise.allSettled(Tf),Tf.length=0,Lu){try{Lu.flush()}catch{}Lu=null}}var I8="d65a6d4b-f702-4af6-98e7-bdb999e01d5f",B8="sec_1e0ea34016bc3a5f8ef5",y8="https://op.shiroha.tech/api",Lu=null,Tf;var jS=O(()=>{zS();Tf=[]});function qS(){return{cli_version:D8,platform:process.platform,arch:process.arch,locale:xi(),node_version:process.version}}function VS(e){return Bun.hash(e).toString(16).slice(0,8)}var D8="0.3.37";var eh=O(()=>{Mn()});async function XS(){if(Mu!==null)return Mu;try{return Mu=(await tt()).telemetryEnabled!==!1,Mu}catch{return Mu=!1,!1}}async function $S(){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(th)return;try{if(!await XS())return;let e=await tt(),o=await $S();if(o==="anonymous")return;let a=(e.providers??[]).find((u)=>u.email)?.email,s=await Mr();YS(o,{...a?{email:a}:{},region:s,locale:xi(),first_seen_version:Q8,platform:process.platform,arch:process.arch}),th=!0}catch{}}function $n(e,o){w8(e,o).catch(()=>{})}async function w8(e,o){try{if(!await XS())return;let i=await $S();KS(e,i,{...qS(),...o})}catch{}}async function Rc(){await WS()}function wa(){Mu=null,th=!1}var Q8="0.3.37",th=!1,Mu=null;var Or=O(()=>{jS();on();Nc();Mn();eh();eh()});function b8(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(b8(o,s))};d();let p=setInterval(d,1000),g=(h)=>{if(!h)return;if(u.push(h),v8.test(h))s.phase="\u89E3\u6790\u4F9D\u8D56";else if(ZS.test(h)){s.phase="\u4E0B\u8F7D\u5E76\u89E3\u538B";let Q=h.match(ZS);if(Q)s.pkgCount=parseInt(Q[1],10)}else if(S8.test(h))s.phase="\u5199\u5165 lockfile";else if(x8.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 v8,ZS,S8,x8;var Ff=O(()=>{v8=/^Resolving dependencies/,ZS=/^Resolved, downloaded and extracted \[(\d+)\]/,S8=/^Saved lockfile/,x8=/^(\d+) packages? installed/});function N8(e){return e.replace(/\r/g,`
|
|
294
294
|
`).replace(/\n{3,}/g,`
|
|
@@ -313,7 +313,7 @@ __HTTP__%{http_code}`,"https://chatgpt.com/backend-api/wham/usage","-H",`Authori
|
|
|
313
313
|
`).filter(Boolean).slice(-o),u=[];for(let d of s)try{u.push(JSON.parse(d))}catch{}return u}async function zh(e){try{await W_(or(e),{recursive:!0,force:!0})}catch{}}async function l1(e,o){await zc(Pc(e));let i=Uh(e,o.approvalId)+".tmp";await Hh(i,JSON.stringify(o,null,2),"utf-8"),await Ph(i,Uh(e,o.approvalId))}async function j_(e,o){try{return JSON.parse(await Zf(Uh(e,o),"utf-8"))}catch{return null}}async function ng(e,o,i){await zc(Pc(e));let a=Gh(e,o)+".tmp";await Hh(a,JSON.stringify(i,null,2),"utf-8"),await Ph(a,Gh(e,o))}async function Jc(e,o){try{return JSON.parse(await Zf(Gh(e,o),"utf-8"))}catch{return null}}async function Kc(e){try{let o=await a1(Pc(e)),i=[];for(let a of o){if(!a.endsWith(".req.json"))continue;let s=a.slice(0,-9),u=await j_(e,s);if(!u)continue;if(!await Jc(e,s))i.push(u)}return i.sort((a,s)=>a.requestedAt-s.requestedAt),i}catch{return[]}}var _h;var yA=O(()=>{_h=ms(K_(),".tako","agent-sessions")});import{spawn as q_}from"child_process";async function og(e,o,i){await ir(e,o),i?.onFrame?.(o)}function V_(e,o){let i=[],a=Gr();if(e?.type==="assistant"&&e?.message?.content){for(let s of e.message.content)if(s?.type==="text"&&typeof s.text==="string")i.push({ts:a,kind:"text_delta",text:s.text,itemId:e.message.id});else if(s?.type==="tool_use")i.push({ts:a,kind:"tool_use",name:s.name??"?",input:s.input,itemId:s.id});else if(s?.type==="thinking"&&typeof s.thinking==="string")i.push({ts:a,kind:"reasoning_delta",text:s.thinking})}else if(e?.type==="user"&&e?.message?.content){for(let s of e.message.content)if(s?.type==="tool_result")i.push({ts:a,kind:"tool_result",itemId:s.tool_use_id,output:s.content})}else if(e?.type==="result"){if(e.is_error)i.push({ts:a,kind:"error",message:typeof e.result==="string"?e.result:"claude reported error",raw:e});i.push({ts:a,kind:"turn_completed",turnId:o,stopReason:e.stop_reason,usage:e.usage})}else if(e?.type==="stream_event"&&e?.event?.delta?.thinking)i.push({ts:a,kind:"reasoning_delta",text:String(e.event.delta.thinking)});return i}function d1(e,o){return e.__env=o,e}var Gr=()=>Date.now(),Yc,c1;var p1=O(()=>{yA();zn();hA();Yc=new Map,c1={backend:"claude",async start(e){let o={sid:e.sid,backend:"claude",name:e.name,model:e.model,workdir:e.workdir,status:"idle",turnCount:0,createdAt:Gr(),lastActiveAt:Gr(),providerId:e.providerId};return await ir(o.sid,{ts:Gr(),kind:"session_started",sid:o.sid,backend:"claude",model:o.model}),o},async send(e,o,i){let a=Ln("claude-code");if(!a)throw Error("claude-code client \u672A\u6CE8\u518C");let s=await ls(a);if(!s)s=Su(a);let u=e.turnCount===0,d=["--print","--input-format","stream-json","--output-format","stream-json","--verbose"];if(u)d.push("--session-id",e.sid);else d.push("--resume",e.sid);if(e.model)d.push("--model",e.model);d.push("--permission-mode","bypassPermissions");let p={...process.env,...e.__env};delete e.__env;let g=a.runtime==="native"?s:await tr(),m=a.runtime==="native"?d:[s,...d],h=q_(g,m,{env:p,cwd:e.workdir,stdio:["pipe","pipe","pipe"]});Yc.set(e.sid,{pid:h.pid,kill:(S)=>h.kill(S??"SIGINT")});let Q={type:"user",message:{role:"user",content:[{type:"text",text:o}]}};h.stdin.write(JSON.stringify(Q)+`
|
|
314
314
|
`),h.stdin.end(),e.status="running",e.lastActiveAt=Gr(),await qo(e);let C="";h.stderr.on("data",(S)=>{C+=S.toString()});let w=`t${e.turnCount+1}`;await og(e.sid,{ts:Gr(),kind:"turn_started",turnId:w},i);let N="";h.stdout.on("data",async(S)=>{N+=S.toString();let L;while((L=N.indexOf(`
|
|
315
315
|
`))>=0){let q=N.slice(0,L).trim();if(N=N.slice(L+1),!q)continue;try{let ne=JSON.parse(q);for(let se of V_(ne,w))await og(e.sid,se,i)}catch{}}});let v=await new Promise((S)=>{h.on("close",(L)=>S(L??0))});if(Yc.delete(e.sid),v===0)e.turnCount++;if(e.lastActiveAt=Gr(),e.status="idle",v!==0)await og(e.sid,{ts:Gr(),kind:"error",message:`claude exited ${v}${C?`: ${C.slice(0,500)}`:""}`},i);return await qo(e),e},async cancel(e){let o=Yc.get(e.sid);if(o)o.kill("SIGINT")},async close(e){let o=Yc.get(e.sid);if(o)o.kill("SIGTERM");Yc.delete(e.sid),await og(e.sid,{ts:Gr(),kind:"session_closed"}),e.status="closed",e.lastActiveAt=Gr(),await qo(e)},async isAlive(){return!0}}});import{join as E1,isAbsolute as f1,relative as X_,resolve as Jh}from"path";import{readFile as $_,writeFile as Z_}from"fs/promises";import{homedir as e4}from"os";function t4(e){if(!e)return"";let o=e.match(/^(?:\S*sh|\S*bash|\S*zsh)(?:\s+-\w+)*\s+["'](.*)["']\s*$/s);return o?o[1]:e}function g1(e,o){if(!e)return!1;let i=f1(e)?Jh(e):Jh(o,e),a=Jh(o),s=X_(a,i);return s===""||!s.startsWith("..")&&!f1(s)}function C1(e,o,i,a){if(o==="item/commandExecution/requestApproval"||o==="execCommandApproval"){let s=String(i?.command??""),u=t4(s);for(let d of e.exec_deny??[])try{if(new RegExp(d).test(u))return{kind:"auto_deny",reason:`policy deny: /${d}/`}}catch{}for(let d of e.exec_allow??[])try{if(new RegExp(d).test(u))return{kind:"auto_allow",reason:`policy allow: /${d}/`}}catch{}return{kind:"ask"}}if(o==="item/fileChange/requestApproval"||o==="applyPatchApproval"){let s=n4(i);for(let d of s)for(let p of e.file_deny??[])try{if(new RegExp(p).test(d))return{kind:"auto_deny",reason:`file deny: ${d} matches /${p}/`}}catch{}if(e.strict_workdir){for(let d of s)if(!g1(d,a))return{kind:"auto_deny",reason:`file outside workdir: ${d}`}}let u=s.length>0;for(let d of s){let p=!1;for(let g of e.file_allow??[])try{if(new RegExp(g).test(d)){p=!0;break}}catch{}if(!p){u=!1;break}}if(u)return{kind:"auto_allow",reason:"all paths matched file_allow"};if(!e.strict_workdir&&s.length>0&&s.every((d)=>g1(d,a)))return{kind:"auto_allow",reason:"all paths inside workdir (non-strict)"};return{kind:"ask"}}return{kind:"ask"}}function n4(e){let o=[],i=(a)=>{if(typeof a==="string"&&a.length>0&&a.length<1024)o.push(a)};if(i(e?.path),Array.isArray(e?.changes))for(let a of e.changes)i(a?.path),i(a?.target);if(Array.isArray(e?.files))for(let a of e.files)i(a?.path??a);if(typeof e?.patch==="string")for(let a of e.patch.split(`
|
|
316
|
-
`)){let s=a.match(/^\+\+\+\s+b\/(.*)$/);if(s)o.push(s[1])}return Array.from(new Set(o))}function Wh(e){return E1(or(e),"policy.json")}async function Kh(e){try{return JSON.parse(await $_(e,"utf-8"))}catch{return null}}async function ig(e){let o=await Kh(o4),i=await Kh(Wh(e));return m1(m1(Yh,o),i)}function m1(e,o){if(!o)return e;return{exec_allow:[...e.exec_allow??[],...o.exec_allow??[]],exec_deny:[...e.exec_deny??[],...o.exec_deny??[]],file_allow:[...e.file_allow??[],...o.file_allow??[]],file_deny:[...e.file_deny??[],...o.file_deny??[]],strict_workdir:o.strict_workdir??e.strict_workdir}}async function rg(e){return await Kh(Wh(e))??{}}async function ag(e,o){await Z_(Wh(e),JSON.stringify(o,null,2),"utf-8")}async function h1(e,o){let i=await rg(e),a=i.exec_allow??[];if(!a.includes(o))a.push(o);i.exec_allow=a,await ag(e,i)}var Yh,o4;var jh=O(()=>{yA();Yh={exec_allow:["^\\s*(ls|pwd|whoami|hostname|date|uname|env|echo|printenv)(\\s|$)","^\\s*(cat|head|tail|less|more|file|stat)\\s+","^\\s*(grep|rg|ag|egrep|fgrep)\\s+","^\\s*find\\s+\\S+\\s+(-name|-type|-maxdepth|-path)","^\\s*(wc|awk|sed -n)\\s+","^\\s*(which|type|whereis|command -v)\\s+","^\\s*(ps|df|du|free|top -b|iostat|vmstat)(\\s|$)","^\\s*tree(\\s|$)","^\\s*git\\s+(status|log|diff|show|branch|remote|config --(get|list)|rev-parse|describe|ls-files|ls-tree|cat-file|tag\\s+--list|stash list|reflog|fetch)(\\s|$)","^\\s*(npm|yarn|pnpm|bun)\\s+(list|outdated|info|view|search|--version)(\\s|$)","^\\s*(node|bun|python|python3|deno|go|cargo|rustc|java|javac)\\s+(--version|-V|version)(\\s|$)","^\\s*pip\\s+(list|show|--version)(\\s|$)","^\\s*cargo\\s+(check|tree|metadata)(\\s|$)","^\\s*(tsc|tsc --noEmit)(\\s|$)","^\\s*(eslint|prettier|stylelint|tslint)\\s+","^\\s*(jest|vitest|mocha|pytest|bun test|cargo test)(\\s|$)","^\\s*npm run (lint|test|build|typecheck|check)"],exec_deny:["\\bsudo\\b","\\bsu\\s+-","\\bdoas\\b","\\brm\\s+-[rRf]+\\s+(/$|/\\s|/[^./])","\\brm\\s+-[rRf]+\\s+\\$HOME(/?)?\\s","\\brm\\s+-[rRf]+\\s+~(/?)?\\s","\\bdd\\s+if=.*\\s+of=/dev/","\\bmkfs\\.","\\bshred\\b","\\bdiskutil\\s+(erase|format)","\\bcurl\\s+[^|]*\\|\\s*(sh|bash|zsh|fish)","\\bwget\\s+[^|]*\\|\\s*(sh|bash|zsh|fish)","\\bcurl\\s+.*-o\\s+/(usr|etc|bin|sbin|lib)/",":\\(\\)\\s*\\{","\\bchmod\\s+-R\\s+[0-7]+\\s+/","\\bssh-keygen\\s+-t","\\bsshpass\\b","\\b(passwd|chpasswd)\\b","\\bgit\\s+push\\s+.*--force"],file_allow:[],file_deny:["
|
|
316
|
+
`)){let s=a.match(/^\+\+\+\s+b\/(.*)$/);if(s)o.push(s[1])}return Array.from(new Set(o))}function Wh(e){return E1(or(e),"policy.json")}async function Kh(e){try{return JSON.parse(await $_(e,"utf-8"))}catch{return null}}async function ig(e){let o=await Kh(o4),i=await Kh(Wh(e));return m1(m1(Yh,o),i)}function m1(e,o){if(!o)return e;return{exec_allow:[...e.exec_allow??[],...o.exec_allow??[]],exec_deny:[...e.exec_deny??[],...o.exec_deny??[]],file_allow:[...e.file_allow??[],...o.file_allow??[]],file_deny:[...e.file_deny??[],...o.file_deny??[]],strict_workdir:o.strict_workdir??e.strict_workdir}}async function rg(e){return await Kh(Wh(e))??{}}async function ag(e,o){await Z_(Wh(e),JSON.stringify(o,null,2),"utf-8")}async function h1(e,o){let i=await rg(e),a=i.exec_allow??[];if(!a.includes(o))a.push(o);i.exec_allow=a,await ag(e,i)}var Yh,o4;var jh=O(()=>{yA();Yh={exec_allow:["^\\s*(ls|pwd|whoami|hostname|date|uname|env|echo|printenv)(\\s|$)","^\\s*(cat|head|tail|less|more|file|stat)\\s+","^\\s*(grep|rg|ag|egrep|fgrep)\\s+","^\\s*find\\s+\\S+\\s+(-name|-type|-maxdepth|-path)","^\\s*(wc|awk|sed -n)\\s+","^\\s*(which|type|whereis|command -v)\\s+","^\\s*(ps|df|du|free|top -b|iostat|vmstat)(\\s|$)","^\\s*tree(\\s|$)","^\\s*git\\s+(status|log|diff|show|branch|remote|config --(get|list)|rev-parse|describe|ls-files|ls-tree|cat-file|tag\\s+--list|stash list|reflog|fetch)(\\s|$)","^\\s*(npm|yarn|pnpm|bun)\\s+(list|outdated|info|view|search|--version)(\\s|$)","^\\s*(node|bun|python|python3|deno|go|cargo|rustc|java|javac)\\s+(--version|-V|version)(\\s|$)","^\\s*pip\\s+(list|show|--version)(\\s|$)","^\\s*cargo\\s+(check|tree|metadata)(\\s|$)","^\\s*(tsc|tsc --noEmit)(\\s|$)","^\\s*(eslint|prettier|stylelint|tslint)\\s+","^\\s*(jest|vitest|mocha|pytest|bun test|cargo test)(\\s|$)","^\\s*npm run (lint|test|build|typecheck|check)"],exec_deny:["\\bsudo\\b","\\bsu\\s+-","\\bdoas\\b","\\brm\\s+-[rRf]+\\s+(/$|/\\s|/[^./])","\\brm\\s+-[rRf]+\\s+\\$HOME(/?)?\\s","\\brm\\s+-[rRf]+\\s+~(/?)?\\s","\\bdd\\s+if=.*\\s+of=/dev/","\\bmkfs\\.","\\bshred\\b","\\bdiskutil\\s+(erase|format)","\\bcurl\\s+[^|]*\\|\\s*(sh|bash|zsh|fish)","\\bwget\\s+[^|]*\\|\\s*(sh|bash|zsh|fish)","\\bcurl\\s+.*-o\\s+/(usr|etc|bin|sbin|lib)/",":\\(\\)\\s*\\{","\\bchmod\\s+-R\\s+[0-7]+\\s+/","\\bssh-keygen\\s+-t","\\bsshpass\\b","\\b(passwd|chpasswd)\\b","\\bgit\\s+push\\s+.*--force"],file_allow:[],file_deny:["[/\\\\]\\.ssh[/\\\\]","[/\\\\]\\.aws[/\\\\]","[/\\\\]\\.gnupg[/\\\\]","\\.env(\\.|$)","[/\\\\]etc[/\\\\](passwd|shadow|sudoers)","[/\\\\](usr|etc|bin|sbin)[/\\\\]"],strict_workdir:!1};o4=E1(e4(),".tako","agent-policy.json")});import{spawn as i4}from"child_process";import{writeFile as r4,unlink as a4}from"fs/promises";import{join as I1}from"path";class Q1{proc;buf="";nextId=1;pending=new Map;notifyHandlers=[];serverReqHandler=null;closed=!1;constructor(e){this.proc=e,e.stdout?.on("data",(o)=>this.onData(o)),e.on("close",()=>this.onClose()),e.on("error",()=>this.onClose())}onData(e){this.buf+=e.toString("utf-8");let o;while((o=this.buf.indexOf(`
|
|
317
317
|
`))>=0){let i=this.buf.slice(0,o).trim();if(this.buf=this.buf.slice(o+1),!i)continue;try{this.dispatch(JSON.parse(i))}catch{}}}dispatch(e){if(e&&typeof e==="object"){if(e.id!==void 0&&(("result"in e)||("error"in e))){let o=this.pending.get(e.id);if(o)if(this.pending.delete(e.id),e.error)o.reject(Error(JSON.stringify(e.error)));else o.resolve(e.result);return}if(e.method&&e.id!==void 0){this.serverReqHandler?.(e.method,e.id,e.params);return}if(e.method)for(let o of this.notifyHandlers)o(e.method,e.params)}}onClose(){this.closed=!0;for(let[,e]of this.pending)e.reject(Error("rpc closed"));this.pending.clear()}write(e){if(this.closed)return;this.proc.stdin?.write(JSON.stringify(e)+`
|
|
318
318
|
`)}request(e,o){if(this.closed)return Promise.reject(Error("rpc closed"));let i=this.nextId++;return new Promise((a,s)=>{this.pending.set(i,{resolve:a,reject:s}),this.write({jsonrpc:"2.0",method:e,params:o,id:i})})}notify(e,o){this.write({jsonrpc:"2.0",method:e,params:o})}reply(e,o){this.write({jsonrpc:"2.0",id:e,result:o})}replyError(e,o,i){this.write({jsonrpc:"2.0",id:e,error:{code:o,message:i}})}onNotification(e){this.notifyHandlers.push(e)}onServerRequest(e){this.serverReqHandler=e}pid(){return this.proc.pid}kill(e="SIGTERM"){try{this.proc.kill(e)}catch{}}close(){try{this.proc.stdin?.end()}catch{}this.kill("SIGTERM")}}async function B1(e,o){let i=Ln("codex");if(!i)throw Error("codex client \u672A\u6CE8\u518C");let a=await ls(i)??Su(i),s={...process.env,...o},u=i.runtime==="native"?a:await tr(),d=i.runtime==="native"?["app-server"]:[a,"app-server"],p=i4(u,d,{env:s,cwd:e,stdio:["pipe","pipe","pipe"]});return p.stderr?.on("data",()=>{}),new Q1(p)}async function y1(e){await e.request("initialize",{clientInfo:{name:"tako-agent",title:"Tako Agent",version:"0.1"},capabilities:null})}function D1(e,o={}){let i=e.approvalMode==="external",a={cwd:e.workdir,approvalPolicy:i?"untrusted":"never",sandbox:i?"workspace-write":"danger-full-access",...o};if(e.model)a.model=e.model;if(e.providerHint?.type==="tako"||e.providerHint?.type==="custom")a.modelProvider="tako";return a}function qh(e,o){if(e==="applyPatchApproval"||e==="execCommandApproval")return{decision:o?"approved":"denied"};if(e==="item/commandExecution/requestApproval"||e==="item/fileChange/requestApproval")return{decision:o?"accept":"decline"};if(e==="item/permissions/requestApproval")return o?{permissions:{allowedTools:["*"]},scope:"turn"}:{permissions:{},scope:"turn"};if(e==="mcpServer/elicitation/request")return{action:o?"accept":"decline"};return{decision:o?"approved":"denied"}}function s4(e){if(e.includes("commandExecution")||e==="execCommandApproval")return"exec";if(e.includes("fileChange")||e==="applyPatchApproval")return"patch";if(e.includes("permissions"))return"permission";if(e.includes("tool/"))return"tool";return"other"}async function A4(e,o,i=300000,a=200){let s=Date.now();while(Date.now()-s<i){let u=await Jc(e,o);if(u)return{allow:u.decision==="allow",reason:u.reason,by:u.by};await new Promise((d)=>setTimeout(d,a))}return{allow:!1,reason:`timeout after ${Math.round(i/1000)}s`,by:"tako-timeout"}}function sg(e,o){return e.__env=o,e}function u4(e,o){let i=[],a=fi();switch(e){case"turn/started":i.push({ts:a,kind:"turn_started",turnId:o?.turn?.id??"?"});break;case"turn/completed":i.push({ts:a,kind:"turn_completed",turnId:o?.turn?.id,usage:o?.turn?.usage});break;case"item/agentMessage/delta":if(typeof o?.delta==="string")i.push({ts:a,kind:"text_delta",text:o.delta,itemId:o.itemId});break;case"item/reasoning/textDelta":case"item/reasoning/summaryTextDelta":if(typeof o?.delta==="string")i.push({ts:a,kind:"reasoning_delta",text:o.delta});break;case"item/started":{let s=o?.item;if(!s)break;if(s.type==="commandExecution")i.push({ts:a,kind:"tool_use",name:"shell",input:{command:s.command},itemId:s.id});else if(s.type==="fileChange")i.push({ts:a,kind:"tool_use",name:"fileChange",input:s,itemId:s.id});else if(s.type==="mcpToolCall")i.push({ts:a,kind:"tool_use",name:s.serverName?`${s.serverName}.${s.toolName}`:s.toolName??"mcp",input:s.args,itemId:s.id});break}case"item/completed":{let s=o?.item;if(!s)break;if(s.type==="commandExecution"||s.type==="fileChange"||s.type==="mcpToolCall")i.push({ts:a,kind:"tool_result",itemId:s.id,output:s});break}case"error":case"warning":i.push({ts:a,kind:"error",message:o?.message??e,raw:o});break}return i}var fi=()=>Date.now(),w1;var v1=O(()=>{yA();jh();zn();hA();w1={backend:"codex",async start(e){let o={sid:e.sid,backend:"codex",name:e.name,model:e.model,workdir:e.workdir,status:"idle",approvalMode:e.approvalMode??"yolo",turnCount:0,createdAt:fi(),lastActiveAt:fi(),providerId:e.providerId};return await ir(o.sid,{ts:fi(),kind:"session_started",sid:o.sid,backend:"codex",model:o.model}),o.__providerHint=e.providerHint,o},async send(e,o,i){let a=e.__env??{},s=e.__providerHint,u=await B1(e.workdir,a),d=I1(or(e.sid),"turn.pid");if(u.pid())await r4(d,String(u.pid()));let p=e.approvalMode??"yolo";u.onServerRequest((Q,C,w)=>{if(p==="yolo"){u.replyError(C,-32603,`tako-agent yolo mode: ${Q} declined`);return}let N=String(C),v=s4(Q);(async()=>{let S=await ig(e.sid),L=C1(S,Q,w,e.workdir);if(L.kind==="auto_allow"){await ir(e.sid,{ts:fi(),kind:"tool_result",itemId:N,output:{approval:"auto_allowed",reason:L.reason}}),u.reply(C,qh(Q,!0));return}if(L.kind==="auto_deny"){await ir(e.sid,{ts:fi(),kind:"error",message:`auto_deny: ${L.reason}`,raw:{method:Q,params:w}}),u.reply(C,qh(Q,!1));return}let q={approvalId:N,method:Q,params:w,approvalType:v,requestedAt:fi()};await l1(e.sid,q),await ir(e.sid,{ts:fi(),kind:"approval_required",approvalId:N,approvalType:v,params:w}),e.status="awaiting_approval",await qo(e);let ne=await A4(e.sid,N);e.status="running",await qo(e),u.reply(C,qh(Q,ne.allow))})().catch((S)=>{u.replyError(C,-32603,`approval bridge error: ${S?.message??S}`)})});let g=Promise.resolve();u.onNotification((Q,C)=>{let w=u4(Q,C);if(!w.length)return;g=g.then(async()=>{for(let N of w)await ir(e.sid,N),i?.onFrame?.(N)})}),e.status="running",e.lastActiveAt=fi(),await qo(e);let m=new Promise((Q)=>{u.onNotification((C)=>{if(C==="turn/completed"||C==="turn/failed")Q()})}),h=!1;try{if(await y1(u),!e.codexThreadId){let Q=await u.request("thread/start",D1({workdir:e.workdir,model:e.model,providerHint:s,approvalMode:p}));if(e.codexThreadId=Q?.threadId??Q?.id??Q?.thread?.id,!e.codexThreadId)throw Error("thread/start \u65E0 threadId")}else await u.request("thread/resume",D1({workdir:e.workdir,model:e.model,providerHint:s,approvalMode:p},{threadId:e.codexThreadId}));await u.request("turn/start",{threadId:e.codexThreadId,input:[{type:"text",text:o,text_elements:[]}]}),await Promise.race([m,new Promise((Q,C)=>setTimeout(()=>C(Error("turn timeout 10min")),600000))]),await g,h=!0}catch(Q){await ir(e.sid,{ts:fi(),kind:"error",message:Q instanceof Error?Q.message:String(Q)})}if(u.close(),await a4(d).catch(()=>{}),h)e.turnCount++;return e.lastActiveAt=fi(),e.status="idle",await qo(e),e},async cancel(e){let o=I1(or(e.sid),"turn.pid");try{let i=await import("fs/promises"),a=parseInt(await i.readFile(o,"utf-8"),10);if(a>0)process.kill(a,"SIGTERM")}catch{}},async close(e){if(e.codexThreadId)try{let o=e.__env??{},i=await B1(e.workdir,o);await y1(i).catch(()=>{}),await i.request("thread/archive",{threadId:e.codexThreadId}).catch(()=>{}),i.close()}catch{}await ir(e.sid,{ts:fi(),kind:"session_closed"}),e.status="closed",e.lastActiveAt=fi(),await qo(e)},async isAlive(e){return e.status!=="closed"}}});import{randomUUID as l4}from"crypto";async function Wc(e){let o=Ju[e.backend],i=Vh[e.backend],a=Ln(i);if(!a)throw Error(`client ${i} \u672A\u6CE8\u518C`);let s=await S1(e.backend,e.providerId,e.model);if(!s)throw Error(`\u6CA1\u627E\u5230 ${e.backend} \u53EF\u7528\u7684 provider${e.model?`\uFF08\u542B\u6A21\u578B ${e.model}\uFF09`:""}`);let u=jo(s);if(e.model)u.model=e.model;let d=a.getEnvVars(u),p=l4(),g={sid:p,backend:e.backend,name:e.name??`${e.backend}-${p.slice(0,8)}`,model:e.model,workdir:e.workdir??process.cwd(),status:"idle",approvalMode:e.approvalMode??"yolo",turnCount:0,createdAt:Date.now(),lastActiveAt:Date.now(),providerId:s.id};await u1(g);let m=await o.start({sid:p,name:g.name,model:e.model,workdir:g.workdir,approvalMode:e.approvalMode??"yolo",env:d,providerId:s.id,providerHint:{type:s.type,apiKey:s.apiKey,baseUrl:s.baseUrl}});return await qo(m),m}async function jc(e,o,i){let a=await zu(e);if(!a)throw Error(`session ${e} \u4E0D\u5B58\u5728`);if(a.status==="closed")throw Error(`session ${e} \u5DF2\u5173\u95ED`);let s=Ju[a.backend],u=await Xh(a);if(a.backend==="claude")d1(a,u);else if(a.backend==="codex")sg(a,u);return s.send(a,o,i)}async function qc(e){let o=await zu(e);if(!o)return;if(o.backend==="codex")sg(o,await Xh(o));await Ju[o.backend].cancel(o)}async function DA(e,o=!1){let i=await zu(e);if(!i)return;if(i.backend==="codex")sg(i,await Xh(i));if(await Ju[i.backend].close(i),o)await zh(e)}async function Ag(){return eg()}function c4(e,o={}){return e.filter((i)=>{if(o.status&&o.status.length>0){if(!o.status.includes(i.status))return!1}else if(!o.includeClosed&&i.status==="closed")return!1;if(o.namePrefix&&!i.name.startsWith(o.namePrefix))return!1;if(o.backend&&i.backend!==o.backend)return!1;if(o.model&&i.model!==o.model)return!1;if(o.turns!==void 0&&i.turnCount!==o.turns)return!1;return!0})}async function ug(e={}){return c4(await eg(),e)}async function Ku(e,o=50){let i=await zu(e);if(!i)return null;let a=await tg(e,o),s=await Ju[i.backend].isAlive(i);return{meta:i,log:a,alive:s}}async function lg(){let e=await eg(),o=0;for(let i of e){if(i.status==="closed"){await zh(i.sid),o++;continue}if(i.backend==="codex"){if(!await Ju.codex.isAlive(i))i.status="dead",await qo(i)}}return o}async function S1(e,o,i){let a=await tt(),s=await Wo(),u=Vh[e];if(o){let h=s.find((Q)=>Q.id===o);if(h)return h}let p=a.agentDefaults?.[e];if(p){let h=s.find((Q)=>Q.id===p);if(h)return h}let g=await Da(u);if(i){let h=Ln(u);if(h){for(let Q of g)if(xu(h,Q).some((w)=>w.id===`model-${i}`))return Q}}let m=a.clientProviderMap?.[u];if(m){let h=s.find((Q)=>Q.id===m);if(h)return h}return g[0]}async function Xh(e){let o=Vh[e.backend],i=Ln(o);if(!i)return{};let a=await Wo(),s=e.providerId?a.find((d)=>d.id===e.providerId):void 0;if(!s)s=await S1(e.backend,void 0,e.model);if(!s)return{};let u=jo(s);if(e.model)u.model=e.model;return e.__providerHint={type:s.type,apiKey:s.apiKey,baseUrl:s.baseUrl},i.getEnvVars(u)}async function x1(e,o){let{saveConfig:i}=await Promise.resolve().then(() => (on(),Vv)),a=await tt(),s=a.agentDefaults??{};s[e]=o,a.agentDefaults=s,await i(a)}async function cg(){return(await tt()).agentDefaults??{}}var Ju,Vh;var dg=O(()=>{p1();v1();yA();on();bi();zn();Ju={claude:c1,codex:w1},Vh={claude:"claude-code",codex:"codex"}});function Yu(e,o="human",i={}){if(o==="json"){process.stdout.write(JSON.stringify($h(e))+`
|
|
319
319
|
`);return}if(o==="verbose"){p4(e,new Date(e.ts).toISOString().slice(11,23),{expandError:!0,...i});return}d4(e,i)}function b1(e){if(e===void 0||e===null)return"";let o;try{o=typeof e==="string"?e:JSON.stringify(e,null,2)}catch{o=String(e)}return o.split(`
|
|
@@ -693,7 +693,7 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
|
|
|
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=UA.__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};UA={react_stack_bottom_frame:function(V){return V()}};var ce,Ne={},ve=UA.react_stack_bottom_frame.bind(UA,u)(),We=Dt(a(u)),He={};cP.Fragment=v,cP.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 NT({zh:e}){return mt.jsxDEV(G,{marginTop:0,justifyContent:"center",gap:2,children:dP.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 RT({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(NT,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function TT({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"?ml(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(NT,{zh:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var mt,dP;var FT=O(async()=>{Rm();await Vo();mt=ye($t(),1),dP=[["\u2191\u2193","\u9009\u62E9","select"],["Enter","\u786E\u8BA4","confirm"],["m","\u5F53\u524D\u76EE\u5F55\u542F\u52A8","launch cwd"],["Esc","\u53D6\u6D88","cancel"]]});function pP({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 kT({options:e,enabled:o,pickerIdx:i,color:a,zh:s}){let{stdout:u}=gl(),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=El(e,u.columns||80,s),h=Cl(d,m),Q=Math.max(XB,...d.length>0?d.map((C)=>_A(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:QT(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(pP,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var cn;var LT=O(async()=>{Rm();await Vo();cn=ye($t(),1)});function MT(e,o){if(!e||o.ctrl||o.meta)return"";return e.replace(/[\x00-\x1f\x7f]/g,"")}function UT(e){return e.replace(/```[\s\S]*?```/g," [code] ").replace(/[`*_#>|]/g,"").replace(/\s+/g," ").trim()}function gP(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 mP(e){if(e==="claude")return"Claude";if(e==="codex")return"Codex";if(e==="pi")return"Pi";return"Gemini"}function EP(e){if(e==="claude")return"magenta";if(e==="codex")return"blue";if(e==="pi")return"magenta";return"cyan"}function CP(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 GT({color:e}){let{stdout:o}=gl(),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 hP(e){return e>30?"green":e>10?"yellow":"red"}function IP({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 BP({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:hP(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 yP({clients:e,defaultIdx:o,hasProviders:i,pickCounts:a,initialSessionSearch:s=!1,onResult:u}){let{stdout:d}=gl(),[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),Tt=e[p],Ot=Tt.projects,en=Tt.providers,Jt=OT[Tt.client.id]||_T,ke=ao()==="zh",In=en[v],ur=et.default.useMemo(()=>je?hg(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=Ig(),U=!1;wt(b),Mt(!0),Ae("");let j=$c(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(()=>xu(Tt.client,In),[Tt.client.id,In?.id,In?.type]),Tn=et.default.useMemo(()=>IT(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 Gc(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)=>yT(b,Kt,In?.model))},[Kt,In?.model]);let to=et.useCallback((b)=>{let U=Rd(Kt,L,b),j=Kt.filter((me)=>me.group===b);if(j.length===0)return;let W=b==="model"?$B(j,a):"collapsed",ge=0;if(U)if(b==="model"&&W==="grid"){let me=j.map((Le)=>Le.id),rt=El(j,d.columns||80,ke);ge=ZB(me,U.id,rt)}else ge=(b==="model"?ml(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=BT({launchOptions:Kt,enabled:L},"model",b);u({type:"launch",clientId:Tt.client.id,projectPath:Ot[0]?.path,...U})},[Kt,L,u,Tt.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 Sc(Tt.client.id,ge.id),Tt.client.setupConfigFiles)try{await Tt.client.setupConfigFiles(jo(ge))}catch(me){se(ke?"\u26A0 \u914D\u7F6E\u540C\u6B65\u5931\u8D25":"\u26A0 Config sync failed"),setTimeout(()=>se(""),2500);return}Tt.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=El(W,d.columns||80,ke),Ft=Cl(Le,Yt),Wn=bT(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($B(W,a)==="grid")pe(null);else{Ee("collapsed");let Ut=Rd(Kt,L,le),dn=ml(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?ml(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=Rd(Kt,L,le),Yt=W.map((Eo)=>Eo.id),Ft=El(W,d.columns||80,ke),Wn=Le?ZB(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=lI(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=MT(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=xm({launchOptions:Kt,enabled:L});u({type:"launch",clientId:Tt.client.id,projectPath:W.path,...ge})}},[m,p,Q,w,v,en,In,Tt,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",fP]},void 0,!0,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(IP,{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(BP,{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=OT[b.client.id]||_T;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(GT,{color:Jt.color},void 0,!1,void 0,this),ie?H.jsxDEV(RT,{provs:en,provIdx:v,pickerIdx:we,color:Jt.color,zh:ke},void 0,!1,void 0,this):le==="model"&&Qe==="grid"?H.jsxDEV(kT,{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(TT,{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 ",bm(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=EP(b.session.source),me=CP(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:mP(b.session.source)},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:[" \xB7 ",b.session.projectName??"\u672A\u77E5\u9879\u76EE"," \xB7 ",gP(b.session.updatedAt,ke)," "]},void 0,!0,void 0,this),H.jsxDEV(I,{bold:W,color:W?"white":void 0,children:bm(UT(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:[" ",bm(UT(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(GT,{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=Rd(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 HT({onResult:e,initialSessionSearch:o=!1}){let[i,a]=et.useState(null);if(et.useEffect(()=>{CT(45).then(a)},[]),!i)return H.jsxDEV(I,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this);return H.jsxDEV(yP,{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,fP="0.3.36",OT,_T;var PT=O(async()=>{zn();bi();Mn();Wf();hT();Rm();AI();cI();await ha([Vo(),FT(),LT()]);et=ye(ct(),1),H=ye($t(),1),OT={"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"}},_T={icon:"\u25AA",color:"white"}});function zT({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"?vc(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"?Ru(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 KT({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,ey,Td;var YT=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"}},ey={"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"}},Td=["claude-subscription","codex-subscription","tako","anthropic","deepseek","xiaomi","custom"]});function WT({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=ey[ce?.id]?.color||"white",ve=ce?a.filter((ae)=>Tu(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||U0(ne),X=ie||Ru(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 xc(),Ae=await bc(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(() => (Wf(),Zx));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:Tt}=await Promise.resolve().then(() => (Nf(),bf)),Ot=await Tt(),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((Tt)=>Tt.type==="codex-subscription"&&Tt.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];Sc(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")W0(v).then(()=>{q(Ie?"\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4":"Set as default"),je(),i("list"),C(0)});if(X==="delete")Y0(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:Td.length-1);return}if(Ae.downArrow){C((X)=>X<Td.length-1?X+1:0);return}if(Ae.escape){i("list"),C(0);return}if(Ae.return){let X=Td[Q];if(se(X),X==="claude-subscription"){Mt("claude");return}if(X==="codex-subscription"){Mt("codex");return}pe(""),Ee(""),Be(Ru(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=vc(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:Td.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(KT,{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=ey[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(zT,{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 jT=O(async()=>{Mn();bi();Mc();ds();ds();Nu();Or();await ha([Vo(),YT()]);an=ye(ct(),1),Ye=ye($t(),1)});async function qT(){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 _c(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 VT(e){return e.toLocaleString("en-US")}var XT=O(()=>{on();Yf()});function $T({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 qT();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:VT(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 ZT=O(async()=>{Mn();XT();await Vo();Ta=ye(ct(),1),Xo=ye($t(),1)});function DP(e){return e.startsWith("cr_")&&e.length>10}async function QP(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 eF(e){if(!DP(e))return $n("api_key_validated",{success:!1,error_type:"invalid_format"}),{success:!1,error:Ge("auth.invalidFormat")};let o=await QP(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 wP(e,o.apiId),$n("api_key_validated",{success:!0}),wa(),er(),{success:!0}}async function wP(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 tF=O(()=>{on();Mn();Or();bi();ds()});function ty({isReconfigure:e,onDone:o}){let[i,a]=Ss.useState(""),[s,u]=Ss.useState("idle"),[d,p]=Ss.useState(""),{stdin:g,setRawMode:m}=fl();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 eF(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 nF=O(async()=>{Mn();tF();Or();await Vo();Ss=ye(ct(),1),ki=ye($t(),1)});function iF({onDone:e}){let[o,i]=oF.useState(Fd.findIndex((a)=>a.value===ao()));return Yn((a,s)=>{if(s.upArrow)i((u)=>u>0?u-1:Fd.length-1);if(s.downArrow)i((u)=>u<Fd.length-1?u+1:0);if(s.return)z0(Fd[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),Fd.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 oF,Fa,Fd;var rF=O(async()=>{Mn();await Vo();oF=ye(ct(),1),Fa=ye($t(),1),Fd=[{value:"en",label:"English"},{value:"zh",label:"\u4E2D\u6587"}]});import{join as vP}from"path";async function SP(){try{return await Bun.file(sF).json()}catch{return{}}}async function aF(e){await Bun.write(sF,JSON.stringify(e))}async function AF(){if(await E0())return!1;let e=await SP();if(e.never)return!1;let o=new Date().toISOString().slice(0,10);if(e.dismissed===o)return!1;return!0}async function uF(e){if(e==="never")await aF({never:!0});else{let o=new Date().toISOString().slice(0,10);await aF({dismissed:o})}}function lF({onDone:e}){let[o,i]=Fm.useState(0),a=ao()==="zh";return Yn(Fm.useCallback((s,u)=>{if(u.upArrow){i((d)=>d>0?d-1:Tm.length-1);return}if(u.downArrow){i((d)=>d<Tm.length-1?d+1:0);return}if(u.escape){e("skip");return}if(u.return){e(Tm[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:Tm.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 Fm,wn,sF,Tm;var cF=O(async()=>{on();on();Mn();await Vo();Fm=ye(ct(),1),wn=ye($t(),1),sF=vP(Vt,".key-prompt.json");Tm=[{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 pF({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([Vf(Qe.package),$f(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 Xf(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+ny)g(Be-ny+1);return Be});return}if(Qe.return){let ie=q[u];if(ie&&!ie.isCurrent)ne(ie.version)}});let se=dF[v?.id]?.color||"white",le=q.slice(p,p+ny);return Rt.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Rt.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,children:[Rt.jsxDEV(I,{bold:!0,children:["\uD83D\uDCE6 ",i?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"]},void 0,!0,void 0,this),w&&Rt.jsxDEV(I,{color:w.startsWith("\u2713")?"green":"red",children:[" ",w]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Rt.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:o.map((pe,Qe)=>{let Ee=dF[pe.id]||{icon:"\u25AA",color:"white"},ie=Qe===a;return Rt.jsxDEV(G,{borderStyle:ie?"bold":"single",borderColor:ie?Ee.color:"gray",paddingX:2,children:Rt.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),Rt.jsxDEV(G,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:se,paddingX:2,paddingY:1,children:!L||L.loading?Rt.jsxDEV(I,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"Loading..."},void 0,!1,void 0,this):L.error?Rt.jsxDEV(I,{color:"red",children:[i?"\u52A0\u8F7D\u5931\u8D25\uFF1A":"Failed: ",L.error]},void 0,!0,void 0,this):q.length===0?Rt.jsxDEV(I,{dimColor:!0,children:i?"\u6682\u65E0\u7248\u672C":"No versions"},void 0,!1,void 0,this):Rt.jsxDEV(G,{flexDirection:"column",children:[Rt.jsxDEV(I,{dimColor:!0,children:[i?`\u5171 ${q.length} \u4E2A\u7248\u672C\uFF0C\u5F53\u524D\u5B89\u88C5\uFF1A`:`${q.length} versions, current: `,Rt.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),Rt.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 Rt.jsxDEV(G,{paddingLeft:1,children:Rt.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),Rt.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u5B89\u88C5":"install"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Rt.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,Rt,ny=12,dF;var fF=O(async()=>{Mc();Mh();Mn();await Vo();$o=ye(ct(),1),Rt=ye($t(),1),dF={"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 xP(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 EF({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 Ku(e,mF);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=UA.__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};UA={react_stack_bottom_frame:function(V){return V()}};var ce,Ne={},ve=UA.react_stack_bottom_frame.bind(UA,u)(),We=Dt(a(u)),He={};cP.Fragment=v,cP.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 NT({zh:e}){return mt.jsxDEV(G,{marginTop:0,justifyContent:"center",gap:2,children:dP.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 RT({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(NT,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function TT({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"?ml(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(NT,{zh:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var mt,dP;var FT=O(async()=>{Rm();await Vo();mt=ye($t(),1),dP=[["\u2191\u2193","\u9009\u62E9","select"],["Enter","\u786E\u8BA4","confirm"],["m","\u5F53\u524D\u76EE\u5F55\u542F\u52A8","launch cwd"],["Esc","\u53D6\u6D88","cancel"]]});function pP({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 kT({options:e,enabled:o,pickerIdx:i,color:a,zh:s}){let{stdout:u}=gl(),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=El(e,u.columns||80,s),h=Cl(d,m),Q=Math.max(XB,...d.length>0?d.map((C)=>_A(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:QT(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(pP,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var cn;var LT=O(async()=>{Rm();await Vo();cn=ye($t(),1)});function MT(e,o){if(!e||o.ctrl||o.meta)return"";return e.replace(/[\x00-\x1f\x7f]/g,"")}function UT(e){return e.replace(/```[\s\S]*?```/g," [code] ").replace(/[`*_#>|]/g,"").replace(/\s+/g," ").trim()}function gP(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 mP(e){if(e==="claude")return"Claude";if(e==="codex")return"Codex";if(e==="pi")return"Pi";return"Gemini"}function EP(e){if(e==="claude")return"magenta";if(e==="codex")return"blue";if(e==="pi")return"magenta";return"cyan"}function CP(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 GT({color:e}){let{stdout:o}=gl(),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 hP(e){return e>30?"green":e>10?"yellow":"red"}function IP({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 BP({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:hP(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 yP({clients:e,defaultIdx:o,hasProviders:i,pickCounts:a,initialSessionSearch:s=!1,onResult:u}){let{stdout:d}=gl(),[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),Tt=e[p],Ot=Tt.projects,en=Tt.providers,Jt=OT[Tt.client.id]||_T,ke=ao()==="zh",In=en[v],ur=et.default.useMemo(()=>je?hg(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=Ig(),U=!1;wt(b),Mt(!0),Ae("");let j=$c(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(()=>xu(Tt.client,In),[Tt.client.id,In?.id,In?.type]),Tn=et.default.useMemo(()=>IT(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 Gc(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)=>yT(b,Kt,In?.model))},[Kt,In?.model]);let to=et.useCallback((b)=>{let U=Rd(Kt,L,b),j=Kt.filter((me)=>me.group===b);if(j.length===0)return;let W=b==="model"?$B(j,a):"collapsed",ge=0;if(U)if(b==="model"&&W==="grid"){let me=j.map((Le)=>Le.id),rt=El(j,d.columns||80,ke);ge=ZB(me,U.id,rt)}else ge=(b==="model"?ml(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=BT({launchOptions:Kt,enabled:L},"model",b);u({type:"launch",clientId:Tt.client.id,projectPath:Ot[0]?.path,...U})},[Kt,L,u,Tt.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 Sc(Tt.client.id,ge.id),Tt.client.setupConfigFiles)try{await Tt.client.setupConfigFiles(jo(ge))}catch(me){se(ke?"\u26A0 \u914D\u7F6E\u540C\u6B65\u5931\u8D25":"\u26A0 Config sync failed"),setTimeout(()=>se(""),2500);return}Tt.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=El(W,d.columns||80,ke),Ft=Cl(Le,Yt),Wn=bT(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($B(W,a)==="grid")pe(null);else{Ee("collapsed");let Ut=Rd(Kt,L,le),dn=ml(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?ml(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=Rd(Kt,L,le),Yt=W.map((Eo)=>Eo.id),Ft=El(W,d.columns||80,ke),Wn=Le?ZB(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=lI(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=MT(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=xm({launchOptions:Kt,enabled:L});u({type:"launch",clientId:Tt.client.id,projectPath:W.path,...ge})}},[m,p,Q,w,v,en,In,Tt,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",fP]},void 0,!0,void 0,this),H.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(IP,{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(BP,{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=OT[b.client.id]||_T;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(GT,{color:Jt.color},void 0,!1,void 0,this),ie?H.jsxDEV(RT,{provs:en,provIdx:v,pickerIdx:we,color:Jt.color,zh:ke},void 0,!1,void 0,this):le==="model"&&Qe==="grid"?H.jsxDEV(kT,{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(TT,{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 ",bm(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=EP(b.session.source),me=CP(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:mP(b.session.source)},void 0,!1,void 0,this),H.jsxDEV(I,{dimColor:!0,children:[" \xB7 ",b.session.projectName??"\u672A\u77E5\u9879\u76EE"," \xB7 ",gP(b.session.updatedAt,ke)," "]},void 0,!0,void 0,this),H.jsxDEV(I,{bold:W,color:W?"white":void 0,children:bm(UT(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:[" ",bm(UT(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(GT,{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=Rd(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 HT({onResult:e,initialSessionSearch:o=!1}){let[i,a]=et.useState(null);if(et.useEffect(()=>{CT(45).then(a)},[]),!i)return H.jsxDEV(I,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this);return H.jsxDEV(yP,{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,fP="0.3.37",OT,_T;var PT=O(async()=>{zn();bi();Mn();Wf();hT();Rm();AI();cI();await ha([Vo(),FT(),LT()]);et=ye(ct(),1),H=ye($t(),1),OT={"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"}},_T={icon:"\u25AA",color:"white"}});function zT({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"?vc(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"?Ru(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 KT({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,ey,Td;var YT=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"}},ey={"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"}},Td=["claude-subscription","codex-subscription","tako","anthropic","deepseek","xiaomi","custom"]});function WT({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=ey[ce?.id]?.color||"white",ve=ce?a.filter((ae)=>Tu(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||U0(ne),X=ie||Ru(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 xc(),Ae=await bc(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(() => (Wf(),Zx));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:Tt}=await Promise.resolve().then(() => (Nf(),bf)),Ot=await Tt(),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((Tt)=>Tt.type==="codex-subscription"&&Tt.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];Sc(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")W0(v).then(()=>{q(Ie?"\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4":"Set as default"),je(),i("list"),C(0)});if(X==="delete")Y0(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:Td.length-1);return}if(Ae.downArrow){C((X)=>X<Td.length-1?X+1:0);return}if(Ae.escape){i("list"),C(0);return}if(Ae.return){let X=Td[Q];if(se(X),X==="claude-subscription"){Mt("claude");return}if(X==="codex-subscription"){Mt("codex");return}pe(""),Ee(""),Be(Ru(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=vc(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:Td.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(KT,{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=ey[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(zT,{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 jT=O(async()=>{Mn();bi();Mc();ds();ds();Nu();Or();await ha([Vo(),YT()]);an=ye(ct(),1),Ye=ye($t(),1)});async function qT(){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 _c(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 VT(e){return e.toLocaleString("en-US")}var XT=O(()=>{on();Yf()});function $T({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 qT();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:VT(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 ZT=O(async()=>{Mn();XT();await Vo();Ta=ye(ct(),1),Xo=ye($t(),1)});function DP(e){return e.startsWith("cr_")&&e.length>10}async function QP(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 eF(e){if(!DP(e))return $n("api_key_validated",{success:!1,error_type:"invalid_format"}),{success:!1,error:Ge("auth.invalidFormat")};let o=await QP(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 wP(e,o.apiId),$n("api_key_validated",{success:!0}),wa(),er(),{success:!0}}async function wP(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 tF=O(()=>{on();Mn();Or();bi();ds()});function ty({isReconfigure:e,onDone:o}){let[i,a]=Ss.useState(""),[s,u]=Ss.useState("idle"),[d,p]=Ss.useState(""),{stdin:g,setRawMode:m}=fl();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 eF(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 nF=O(async()=>{Mn();tF();Or();await Vo();Ss=ye(ct(),1),ki=ye($t(),1)});function iF({onDone:e}){let[o,i]=oF.useState(Fd.findIndex((a)=>a.value===ao()));return Yn((a,s)=>{if(s.upArrow)i((u)=>u>0?u-1:Fd.length-1);if(s.downArrow)i((u)=>u<Fd.length-1?u+1:0);if(s.return)z0(Fd[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),Fd.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 oF,Fa,Fd;var rF=O(async()=>{Mn();await Vo();oF=ye(ct(),1),Fa=ye($t(),1),Fd=[{value:"en",label:"English"},{value:"zh",label:"\u4E2D\u6587"}]});import{join as vP}from"path";async function SP(){try{return await Bun.file(sF).json()}catch{return{}}}async function aF(e){await Bun.write(sF,JSON.stringify(e))}async function AF(){if(await E0())return!1;let e=await SP();if(e.never)return!1;let o=new Date().toISOString().slice(0,10);if(e.dismissed===o)return!1;return!0}async function uF(e){if(e==="never")await aF({never:!0});else{let o=new Date().toISOString().slice(0,10);await aF({dismissed:o})}}function lF({onDone:e}){let[o,i]=Fm.useState(0),a=ao()==="zh";return Yn(Fm.useCallback((s,u)=>{if(u.upArrow){i((d)=>d>0?d-1:Tm.length-1);return}if(u.downArrow){i((d)=>d<Tm.length-1?d+1:0);return}if(u.escape){e("skip");return}if(u.return){e(Tm[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:Tm.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 Fm,wn,sF,Tm;var cF=O(async()=>{on();on();Mn();await Vo();Fm=ye(ct(),1),wn=ye($t(),1),sF=vP(Vt,".key-prompt.json");Tm=[{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 pF({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([Vf(Qe.package),$f(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 Xf(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+ny)g(Be-ny+1);return Be});return}if(Qe.return){let ie=q[u];if(ie&&!ie.isCurrent)ne(ie.version)}});let se=dF[v?.id]?.color||"white",le=q.slice(p,p+ny);return Rt.jsxDEV(G,{flexDirection:"column",paddingX:2,paddingY:1,children:[Rt.jsxDEV(G,{borderStyle:"round",borderColor:"gray",paddingX:3,children:[Rt.jsxDEV(I,{bold:!0,children:["\uD83D\uDCE6 ",i?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"]},void 0,!0,void 0,this),w&&Rt.jsxDEV(I,{color:w.startsWith("\u2713")?"green":"red",children:[" ",w]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Rt.jsxDEV(G,{marginTop:1,gap:1,justifyContent:"center",children:o.map((pe,Qe)=>{let Ee=dF[pe.id]||{icon:"\u25AA",color:"white"},ie=Qe===a;return Rt.jsxDEV(G,{borderStyle:ie?"bold":"single",borderColor:ie?Ee.color:"gray",paddingX:2,children:Rt.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),Rt.jsxDEV(G,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:se,paddingX:2,paddingY:1,children:!L||L.loading?Rt.jsxDEV(I,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"Loading..."},void 0,!1,void 0,this):L.error?Rt.jsxDEV(I,{color:"red",children:[i?"\u52A0\u8F7D\u5931\u8D25\uFF1A":"Failed: ",L.error]},void 0,!0,void 0,this):q.length===0?Rt.jsxDEV(I,{dimColor:!0,children:i?"\u6682\u65E0\u7248\u672C":"No versions"},void 0,!1,void 0,this):Rt.jsxDEV(G,{flexDirection:"column",children:[Rt.jsxDEV(I,{dimColor:!0,children:[i?`\u5171 ${q.length} \u4E2A\u7248\u672C\uFF0C\u5F53\u524D\u5B89\u88C5\uFF1A`:`${q.length} versions, current: `,Rt.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),Rt.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 Rt.jsxDEV(G,{paddingLeft:1,children:Rt.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),Rt.jsxDEV(G,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u5B89\u88C5":"install"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:i?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Rt.jsxDEV(I,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),Rt.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,Rt,ny=12,dF;var fF=O(async()=>{Mc();Mh();Mn();await Vo();$o=ye(ct(),1),Rt=ye($t(),1),dF={"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 xP(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 EF({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 Ku(e,mF);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(-mF))}if(Math.random()<0.1){let ie=await Ku(e,0);if(ie)s(ie.meta)}N(await Kc(e))}catch{}le=setTimeout(pe,gF)};return le=setTimeout(pe,gF),()=>{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 jc(e,se)}catch(le){C(le instanceof Error?le.message:String(le))}finally{h("idle");let le=await Ku(e,0);if(le)s(le.meta)}},[e,p,m]),q=mo.useCallback(async()=>{if(m!=="sending")return o();h("cancelling"),await qc(e).catch(()=>{})},[m,e,o]),ne=mo.useCallback(async(se)=>{let le=w[0];if(!le)return;await ng(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=xP(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,gF=300,mF=200;var CF=O(async()=>{Mn();dg();yA();await Vo();mo=ye(ct(),1),Bt=ye($t(),1)});function hF(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 bP(e){switch(e){case"running":return"yellow";case"idle":return"green";case"closed":return"gray";case"dead":return"red";default:return"white"}}function IF({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([Ag(),cg()]);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..."),lg().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)}...`),DA(L.sid,!1).then(()=>{m(null),N()});return}if(v==="x"){m(`purging ${L.sid.slice(0,8)}...`),DA(L.sid,!0).then(()=>{m(null),N()});return}}),C.kind==="detail")return be.jsxDEV(EF,{sid:C.sid,onBack:()=>{w({kind:"list"}),N()}},void 0,!1,void 0,this);if(C.kind==="new")return be.jsxDEV(NP,{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:bP(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:hF(Date.now()-v.createdAt).padEnd(6)},void 0,!1,void 0,this),be.jsxDEV(I,{dimColor:!0,children:hF(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 NP({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 Wc({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 BF=O(async()=>{Mn();dg();await ha([Vo(),CF()]);eo=ye(ct(),1),be=ye($t(),1)});function RP({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,AF().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 BS({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)}}}}),()=>Sf()},[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(HT,{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(WT,{onDone:(v)=>{if(v==="client-versions")u("client-versions");else Q()}},void 0,!1,void 0,this);case"agents":return Zo.jsxDEV(IF,{onDone:Q},void 0,!1,void 0,this);case"client-versions":return Zo.jsxDEV(pF,{onDone:()=>u("providers")},void 0,!1,void 0,this);case"stats":return Zo.jsxDEV($T,{onExit:Q},void 0,!1,void 0,this);case"config":return Zo.jsxDEV(ty,{isReconfigure:!0,onDone:Q},void 0,!1,void 0,this);case"language":return Zo.jsxDEV(iF,{onDone:Q},void 0,!1,void 0,this);case"key-guide":return Zo.jsxDEV(lF,{onDone:(v)=>{if(v==="configure")u("config");else uF(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 km(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(),Sf(),o(d)}function u(){i?.clear(),i?.unmount(),i=null,a(),Sf(),o(null)}i=Qm(Zo.jsxDEV(RP,{onLaunch:s,onExit:u,initialSessionSearch:e.initialSessionSearch},void 0,!1,void 0,this))})}function yF(){return new Promise((e)=>{let o=null;o=Qm(Zo.jsxDEV(ty,{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 DF=O(async()=>{Lr();await ha([Vo(),PT(),jT(),ZT(),nF(),rF(),cF(),fF(),BF()]);Li=ye(ct(),1),Zo=ye($t(),1)});var QF={};li(QF,{startApiKeySetup:()=>yF,startApp:()=>km});var oy=O(async()=>{await DF()});function jr(e){if(Ic||process.env.TAKO_DEBUG==="1")process.stderr.write(`[announcements] ${e}
|
|
698
698
|
`)}function vF(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 FP(e,o){let i=`${e}/v1/announcements/popup`;try{let a=await fetch(i,{headers:{Authorization:`Bearer ${o}`},signal:AbortSignal.timeout(TP)});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 kP(e){return((await tt()).seenAnnouncementIds??[]).includes(e)}async function LP(e){let o=await tt(),i=o.seenAnnouncementIds??[];if(i.includes(e))return;let a=[...i,e];if(a.length>wF)a.splice(0,a.length-wF);o.seenAnnouncementIds=a,await Go(o)}async function MP(){let e=vF(await pi());if(e)return e;for(let o of await Wo()){let i=vF(o);if(i)return i}return null}async function SF(){let e=await MP();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 FP(e.baseUrl,e.apiKey);if(!o)return;if(o.popup_once&&await kP(o.id)){jr(`\u5DF2\u5728 seenAnnouncementIds\uFF0C\u8DF3\u8FC7\uFF1A${o.id}`);return}if(jr(`\u5F39\u7A97\uFF1A${o.id}`),await LS(o),o.popup_once)await LP(o.id),jr(`\u6807\u8BB0\u5DF2\u770B\u8FC7\uFF1A${o.id}`)}var TP=2000,wF=100;var xF=O(()=>{on();bi()});var bF={};li(bF,{handleLaunchResult:()=>ry,runPreLaunchSetup:()=>iy});async function iy(){await j0(),await q0(),await n1(),await Promise.race([L0(await Wo()),new Promise((e)=>setTimeout(e,3000))]),await SF()}async function ry(e){let o=Ln(e.clientId);if(!o)return!1;$n("menu_action",{action:"launch",client_id:e.clientId});let i=await qf(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 Gu(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 ay=O(()=>{Pf();zn();Mn();Or();Lr();bi();kh();xF();pA()});var NF={};li(NF,{runSessionsCommand:()=>GP});function kd(e,o){let i=e.indexOf(o);return i>=0?e[i+1]:void 0}function OP(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 _P(e){if(e<1024)return`${e} B`;if(e<1048576)return`${(e/1024).toFixed(1)} KiB`;return`${(e/1024/1024).toFixed(1)} MiB`}function UP(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 GP(e){if(e.length===0&&process.stdin.isTTY&&process.stdout.isTTY){let{startApp:i}=await oy().then(() => QF),{handleLaunchResult:a}=await Promise.resolve().then(() => (ay(),bF)),s=await i({initialSessionSearch:!0});if(s?.type==="launch")await a(s);return}let o=Ig();try{let i=e[0]??"search";if(i==="index"){if(e.includes("--clear")){await f2(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 ${_P(g.bytes)} \xB7 schema v${g.schemaVersion}
|
|
699
699
|
${g.path}`);return}let p=e.includes("--rebuild")?await p2(o):await $c(o);console.log(`Indexed ${p} native session files.`);return}if(await $c(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 m2(p);return}let a=UP(e,i),s=kd(e,"--source")?.split(",").filter((p)=>p==="claude"||p==="codex"||p==="gemini"||p==="pi"),u=Number(kd(e,"--limit")??50),d=hg(o,a,{deep:e.includes("--deep"),sources:s,cwd:kd(e,"--cwd"),project:kd(e,"--project"),after:OP(kd(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??wf,u=o.read??Zi,d=o.now??(()=>Date.now()),p=o.columns??(()=>process.stdout.columns??80),g=await a(),m=KP(g);if(i.refresh&&m.length>0)await jP(m,s);let h=m.map((C)=>WP(C,u)),Q=new Date(d()).toISOString();if(i.json)process.stdout.write(e9(h,i.refresh,Q));else process.stdout.write(ZP(h,p()));return 0}var LF,qP=5;var OF=O(()=>{on();M0();LF=["openai","claude"]});Mc();Lr();Nc();on();Mn();Or();Ff();import{join as nr}from"path";function Ix(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 Bx(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 hh="tako-cli",gs="0.3.
|
|
853
|
+
`)}var hh="tako-cli",gs="0.3.37";function SO(){return[So,"update",hh,"--latest"]}function xO(){return[So,"add",`${hh}@latest`]}function bO(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 NO(){try{let e=await Ni(),o=await fetch(`${e}/${hh}/latest`,{signal:AbortSignal.timeout(5000)});if(!o.ok)return null;return(await o.json()).version||null}catch{return null}}async function yx(){let e=await NO();if(!e)return{hasUpdate:!1,currentVersion:gs};return{hasUpdate:bO(e,gs)>0,latestVersion:e,currentVersion:gs}}async function Dx(){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"),Ix(So,a)),await e.writeFile(nr(o,"tako.ps1"),Bx(So,a));else{let u=`#!/bin/bash
|
|
854
854
|
exec "${So}" "${a}" "$@"
|
|
855
855
|
`;await e.writeFile(i,u,{mode:493})}}async function Qx(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(SO(),{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 Dx(),$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: ${Ou(p)}`),!1}catch(a){return o.stop(),Fe.warn(`\u66F4\u65B0\u5931\u8D25: ${Ou(a instanceof Error?a.message:void 0)}`),!1}}async function RO(){let e=await import("fs/promises"),o=nr(Xi,"bun.lock");try{await e.unlink(o)}catch{}}async function TO(){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 RO();let a=Bun.spawn(xO(),{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 FO(){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 TO())return d.stop(Ge("updater.migrationFailed")),!1;d.stop(Ge("updater.installComplete"))}return await Dx(),!0}}catch{}return!1}async function IA(){try{if(await FO())Fe.info(Ge("updater.migrationComplete")),process.exit(0);let o=await yx();if(o.hasUpdate&&o.latestVersion){if(Fe.warn(Ge("updater.newVersionAvailable",{version:o.latestVersion,current:gs})),await Qx(o.latestVersion))Fe.info(Ge("updater.pleaseRestart")),process.exit(0)}}catch{}}async function wx(){console.log(`Tako CLI \u5F53\u524D\u7248\u672C: v${gs}`),console.log("\u6B63\u5728\u68C0\u67E5\u66F4\u65B0...");let e=await yx();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 Qx(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();Pf();Mn();Or();import{homedir as $O}from"os";var Nt={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:Nt.brightYellow,text:Nt.brightGreen},git:{icon:Nt.brightBlue,text:Nt.brightBlue,clean:Nt.brightGreen,dirty:Nt.brightYellow,conflict:Nt.brightRed},model:{icon:Nt.brightCyan,text:Nt.brightCyan},version:{icon:Nt.brightWhite,text:Nt.brightBlack},outputStyle:{icon:Nt.brightMagenta,text:Nt.brightMagenta},context:{icon:Nt.brightMagenta,low:Nt.brightGreen,medium:Nt.brightYellow,high:Nt.brightRed},todayUsage:{icon:Nt.brightGreen,text:Nt.brightGreen},separator:Nt.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 XO(){return!1}function _r(e){let o=va[e];if(typeof o==="string")return o;return XO()?o.nerd:o.plain}class zf{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=$O();if(e===o)return"~";if(e.startsWith(o+"/"))return"~"+e.slice(o.length);return e}}class Jf{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 ZO={"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 Kf{id="model";render(e){let o=e.model.id,i=ZO[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 e_=200000,t_=8192,n_=20,o_=13000,i_="TAKO_MODEL_CONTEXT_WINDOW";function r_(e,o=process.env[i_]){if(o){let i=Number(o);if(Number.isSafeInteger(i)&&i>0)return i}return Qc(e)?.contextWindow??e_}function a_(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 s_(e){let o=Math.max(0,e-Math.min(t_,20000));return Math.max(0,Math.min(o-Math.round(o*n_/100),o-o_))}class Ur{id="context";static cache=null;static CACHE_TTL=5000;async render(e){let i=a_(e)??await this.getTokensWithCache(e.transcript_path),a=r_(e.model.id),s=s_(a),u=Math.min(100,Math.max(0,Math.ceil((s-(i??0))/s*100))),d=_r("context"),p=u<=20?Nt.brightRed:u<=50?Nt.brightYellow:Nt.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}}}Wf();bi();class jf{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 Gc(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()} ${Nt.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?Nt.brightRed:o>=70?Nt.brightYellow:Nt.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?Nt.brightRed:i<=30?Nt.brightYellow:Nt.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()} ${Nt.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 Rh{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 BA,dirname as Q_}from"path";import{homedir as Th}from"os";import{mkdir as w_}from"fs/promises";var e1=BA(Th(),".tako"),v_=BA(e1,"cli"),S_=BA(e1,"bin",process.platform==="win32"?"tako.cmd":"tako");function x_(){if(process.platform==="win32")return BA(process.env.APPDATA||BA(Th(),"AppData","Roaming"),"claude","settings.json");return BA(Th(),".claude","settings.json")}var b_=process.platform==="win32",N_="0.1.48";function R_(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 T_(){let e=BA(v_,"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 F_(){let e=await T_();if(!e)return!1;return R_(e,N_)>=0}function k_(){return S_}function L_(){return`"${M_(k_())}" statusline`}function M_(e){if(b_)return e.replace(/\\/g,"/");return e}async function Fh(){if(!await F_())return;let o=x_(),i={};try{let u=Bun.file(o);if(await u.exists())i=await u.json()}catch{}let a={type:"command",command:L_(),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 w_(Q_(o),{recursive:!0}),await Bun.write(o,JSON.stringify(i,null,2))}var O_=[new zf,new Jf,new Kf,new Ur,new jf];async function __(e){let o=await Promise.all(O_.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 Rh().render(i)}async function t1(){try{let e=await Bun.stdin.json(),o=await __(e);console.log(o)}catch{process.exit(0)}}kh();$0();Gf();var U_={"claude-code":{optionId:"skip-permissions",flag:"--dangerously-skip-permissions"},codex:{optionId:"bypass-sandbox",flag:"--dangerously-bypass-approvals-and-sandbox"}};async function Pu(e,o,i,a){let s=o.filter((p)=>p!==i),u=await G_(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,Fu(s[p+1])),p++;continue}if(g.startsWith("--model=")){let m=g.slice(8);d.push(`--model=${Fu(m)}`);continue}d.push(g)}return d}async function G_(e,o,i){let a=U_[e];if(!a)return null;if(o.includes(a.flag))return null;return(await(i?.getLastSelectedOptionIds??Uf)(e)).includes(a.optionId)?a.flag:null}pA();Mh();on();var Mm="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}}}Wf();bi();class jf{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 Gc(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()} ${Nt.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?Nt.brightRed:o>=70?Nt.brightYellow:Nt.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?Nt.brightRed:i<=30?Nt.brightYellow:Nt.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()} ${Nt.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 Rh{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 BA,dirname as Q_}from"path";import{homedir as Th}from"os";import{mkdir as w_}from"fs/promises";var e1=BA(Th(),".tako"),v_=BA(e1,"cli"),S_=BA(e1,"bin",process.platform==="win32"?"tako.cmd":"tako");function x_(){if(process.platform==="win32")return BA(process.env.APPDATA||BA(Th(),"AppData","Roaming"),"claude","settings.json");return BA(Th(),".claude","settings.json")}var b_=process.platform==="win32",N_="0.1.48";function R_(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 T_(){let e=BA(v_,"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 F_(){let e=await T_();if(!e)return!1;return R_(e,N_)>=0}function k_(){return S_}function L_(){return`"${M_(k_())}" statusline`}function M_(e){if(b_)return e.replace(/\\/g,"/");return e}async function Fh(){if(!await F_())return;let o=x_(),i={};try{let u=Bun.file(o);if(await u.exists())i=await u.json()}catch{}let a={type:"command",command:L_(),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 w_(Q_(o),{recursive:!0}),await Bun.write(o,JSON.stringify(i,null,2))}var O_=[new zf,new Jf,new Kf,new Ur,new jf];async function __(e){let o=await Promise.all(O_.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 Rh().render(i)}async function t1(){try{let e=await Bun.stdin.json(),o=await __(e);console.log(o)}catch{process.exit(0)}}kh();$0();Gf();var U_={"claude-code":{optionId:"skip-permissions",flag:"--dangerously-skip-permissions"},codex:{optionId:"bypass-sandbox",flag:"--dangerously-bypass-approvals-and-sandbox"}};async function Pu(e,o,i,a){let s=o.filter((p)=>p!==i),u=await G_(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,Fu(s[p+1])),p++;continue}if(g.startsWith("--model=")){let m=g.slice(8);d.push(`--model=${Fu(m)}`);continue}d.push(g)}return d}async function G_(e,o,i){let a=U_[e];if(!a)return null;if(o.includes(a.flag))return null;return(await(i?.getLastSelectedOptionIds??Uf)(e)).includes(a.optionId)?a.flag:null}pA();Mh();on();var Mm="0.3.37",n9=!0;function hl(e){return n9&&!e}function o9(){console.log(`
|
|
857
857
|
${Ge("cli.version",{version:Mm})}
|
|
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.37",
|
|
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",
|