tako-cli 0.3.52 → 0.3.53

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.
Files changed (2) hide show
  1. package/dist/index.js +5 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -283,7 +283,7 @@ Press Enter, Esc, or q to close.
283
283
  `)return!0;if(i==="\x1B"||i==="q"||i==="Q")return!0;return},!0),process.stdout.write(`
284
284
  `)}function Ji(){if(Y0)return Y0;let e=process.env.LANG||process.env.LANGUAGE||process.env.LC_ALL||"";if(e.toLowerCase().includes("zh")||e.toLowerCase().includes("chinese"))return"zh";try{if(Intl.DateTimeFormat().resolvedOptions().locale.toLowerCase().startsWith("zh"))return"zh"}catch{}return"zh"}function FS(e){Y0=e}function Se(e,o){let i=Ji(),a=e.split("."),s=W_;for(let d of a)if(s=s?.[d],!s)return e;let u=s[i]||s.en||e;if(o)for(let[d,p]of Object.entries(o))u=u.replace(`{${d}}`,String(p));return u}function Ao(){return Ji()}var Y0=null,W_;var Tn=_(()=>{W_={launcher:{starting:{en:"Starting {client}...",zh:"\u6B63\u5728\u542F\u52A8 {client}..."},directoryNotFound:{en:"Directory not found: {path}",zh:"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A{path}"},apiKeyNotConfigured:{en:"API Key not configured",zh:"API Key \u672A\u914D\u7F6E"},error:{en:"Error: {message}",zh:"\u9519\u8BEF\uFF1A{message}"}},menu:{selectAction:{en:"Select an action:",zh:"\u8BF7\u9009\u62E9\u64CD\u4F5C\uFF1A"},launchClient:{en:"Launch {client}",zh:"\u542F\u52A8 {client}"},advanced:{en:"Advanced",zh:"\u9AD8\u7EA7"},advancedHint:{en:"Usage stats, configuration, etc.",zh:"\u7528\u91CF\u7EDF\u8BA1\u3001\u914D\u7F6E\u7B49"},exit:{en:"Exit",zh:"\u9000\u51FA"},advancedOptions:{en:"Advanced Options:",zh:"\u9AD8\u7EA7\u9009\u9879\uFF1A"},viewStats:{en:"View Usage Statistics",zh:"\u67E5\u770B\u7528\u91CF\u7EDF\u8BA1"},configApiKey:{en:"Configure API Key",zh:"\u914D\u7F6E API Key"},back:{en:"Back",zh:"\u8FD4\u56DE"},changeLanguage:{en:"Change Language",zh:"\u5207\u6362\u8BED\u8A00"},currentLanguage:{en:"Current Language: {lang}",zh:"\u5F53\u524D\u8BED\u8A00\uFF1A{lang}"},languageChanged:{en:"Language changed to {lang}",zh:"\u8BED\u8A00\u5DF2\u5207\u6362\u4E3A {lang}"},selectOptions:{en:"Select launch options (Space to toggle, Enter to confirm):",zh:"\u9009\u62E9\u542F\u52A8\u9009\u9879\uFF08\u7A7A\u683C\u5207\u6362\uFF0C\u56DE\u8F66\u786E\u8BA4\uFF09\uFF1A"},resetOptions:{en:"Reset Launch Options",zh:"\u91CD\u7F6E\u542F\u52A8\u9009\u9879"},optionsReset:{en:"Launch options have been reset. You will be prompted again next time.",zh:"\u542F\u52A8\u9009\u9879\u5DF2\u91CD\u7F6E\uFF0C\u4E0B\u6B21\u542F\u52A8\u65F6\u5C06\u91CD\u65B0\u9009\u62E9\u3002"}},language:{en:{en:"English",zh:"\u82F1\u8BED"},zh:{en:"Chinese",zh:"\u4E2D\u6587"}},banner:{welcome:{en:"Welcome!",zh:"\u6B22\u8FCE\u4F7F\u7528\uFF01"}},stats:{title:{en:"\uD83D\uDCCA Usage Statistics",zh:"\uD83D\uDCCA \u7528\u91CF\u7EDF\u8BA1"},totalRequests:{en:"Total Requests: {count} times",zh:"\u603B\u8C03\u7528\u6B21\u6570\uFF1A{count} \u6B21"},totalCost:{en:"Total Cost: {cost}",zh:"\u603B\u6D88\u8D39\uFF1A{cost}"},todayCost:{en:"Today's Cost: {cost}",zh:"\u4ECA\u65E5\u6D88\u8D39\uFF1A{cost}"},modelDistribution:{en:"Model Usage Distribution (Today):",zh:"\u6A21\u578B\u4F7F\u7528\u5206\u5E03\uFF08\u4ECA\u65E5\uFF09\uFF1A"},times:{en:"times",zh:"\u6B21"},refreshHint:{en:"{countdown}s until refresh | Press any key to return",zh:"{countdown}s \u540E\u5237\u65B0 | \u6309\u4EFB\u610F\u952E\u8FD4\u56DE"},fetching:{en:"Fetching usage statistics...",zh:"\u83B7\u53D6\u7528\u91CF\u7EDF\u8BA1..."},fetchFailed:{en:"Failed to fetch: {error}",zh:"\u83B7\u53D6\u5931\u8D25\uFF1A{error}"}},prompts:{enterApiKey:{en:"Please enter your API Key:",zh:"\u8BF7\u8F93\u5165\u60A8\u7684 API Key\uFF1A"},apiKeyPlaceholder:{en:"cr_xxxxxxxx",zh:"cr_xxxxxxxx"},validating:{en:"Validating API Key...",zh:"\u6B63\u5728\u9A8C\u8BC1 API Key..."},keyInvalidFormat:{en:"Invalid format, must start with cr_",zh:"\u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u5FC5\u987B\u4EE5 cr_ \u5F00\u5934"},keyValidationFailed:{en:"Validation failed: {error}",zh:"\u9A8C\u8BC1\u5931\u8D25\uFF1A{error}"},keyConfigured:{en:"API Key configured successfully!",zh:"API Key \u914D\u7F6E\u6210\u529F\uFF01"}},cli:{version:{en:"Tako CLI v{version}",zh:"Tako CLI v{version}"},usage:{en:"Usage: tako [options] [command]",zh:"\u7528\u6CD5\uFF1Atako [\u9009\u9879] [\u547D\u4EE4]"},options:{en:"Options:",zh:"\u9009\u9879\uFF1A"},optionVersion:{en:" -v, --version Display version number",zh:" -v, --version \u663E\u793A\u7248\u672C\u53F7"},optionHelp:{en:" -h, --help Display help information",zh:" -h, --help \u663E\u793A\u5E2E\u52A9\u4FE1\u606F"},shortcuts:{en:"Shortcuts:",zh:"\u5FEB\u6377\u547D\u4EE4\uFF1A"},shortcutClaude:{en:" --claude [args...] Launch Claude Code (passes extra args through, e.g. --model)",zh:" --claude [\u53C2\u6570...] \u542F\u52A8 Claude Code\uFF08\u989D\u5916\u53C2\u6570\u900F\u4F20\u7ED9 claude\uFF0C\u5982 --model\uFF09"},shortcutCodex:{en:" --codex [args...] Launch Codex (passes extra args through)",zh:" --codex [\u53C2\u6570...] \u542F\u52A8 Codex\uFF08\u989D\u5916\u53C2\u6570\u900F\u4F20\u7ED9 codex\uFF09"},shortcutGemini:{en:" --gemini [args...] Launch Gemini CLI (passes extra args through)",zh:" --gemini [\u53C2\u6570...] \u542F\u52A8 Gemini CLI\uFF08\u989D\u5916\u53C2\u6570\u900F\u4F20\u7ED9 gemini\uFF09"},shortcutGrok:{en:" --grok [args...] Launch Grok Build (passes extra args through)",zh:" --grok [\u53C2\u6570...] \u542F\u52A8 Grok Build\uFF08\u989D\u5916\u53C2\u6570\u900F\u4F20\u7ED9 grok\uFF09"},shortcutPi:{en:" --pi [args...] Launch Pi (passes extra args through)",zh:" --pi [\u53C2\u6570...] \u542F\u52A8 Pi\uFF08\u989D\u5916\u53C2\u6570\u900F\u4F20\u7ED9 pi\uFF09"},shortcutPiWeb:{en:" --pi-web [args...] Launch Pi Web (browser UI)",zh:" --pi-web [\u53C2\u6570...] \u542F\u52A8 Pi Web\uFF08\u6D4F\u89C8\u5668\u754C\u9762\uFF09"},examples:{en:"Examples:",zh:"\u793A\u4F8B\uFF1A"},exampleInteractive:{en:" tako Interactive tool selection",zh:" tako \u4EA4\u4E92\u5F0F\u9009\u62E9\u5DE5\u5177"},exampleClaude:{en:" tako --claude Launch Claude Code directly",zh:" tako --claude \u76F4\u63A5\u542F\u52A8 Claude Code"},exampleClaudeModel:{en:" tako --claude --model claude-opus-4-7 Launch Claude Code with a specific model",zh:" tako --claude --model claude-opus-4-7 \u6307\u5B9A\u6A21\u578B\u542F\u52A8 Claude Code"},exampleCodex:{en:" tako --codex Launch Codex directly",zh:" tako --codex \u76F4\u63A5\u542F\u52A8 Codex"},exampleGemini:{en:" tako --gemini Launch Gemini CLI directly",zh:" tako --gemini \u76F4\u63A5\u542F\u52A8 Gemini CLI"},exampleGrok:{en:" tako --grok Launch Grok Build directly",zh:" tako --grok \u76F4\u63A5\u542F\u52A8 Grok Build"},examplePi:{en:" tako --pi Launch Pi directly",zh:" tako --pi \u76F4\u63A5\u542F\u52A8 Pi"},examplePiWeb:{en:" tako --pi-web Launch Pi Web in the browser",zh:" tako --pi-web \u5728\u6D4F\u89C8\u5668\u91CC\u542F\u52A8 Pi Web"},clientNotFound:{en:"{client} client not found",zh:"{client} \u5BA2\u6237\u7AEF\u672A\u627E\u5230"},cliError:{en:"Tako CLI encountered an error:",zh:"Tako CLI \u53D1\u751F\u9519\u8BEF\uFF1A"},launchFailed:{en:"Launch failed",zh:"\u542F\u52A8\u5931\u8D25"}},auth:{invalidFormat:{en:"Invalid format, must start with cr_",zh:"\u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u5FC5\u987B\u4EE5 cr_ \u5F00\u5934"},validationFailed:{en:"Validation failed",zh:"\u9A8C\u8BC1\u5931\u8D25"},networkError:{en:"Network request failed",zh:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}},updater:{migrating:{en:"Detected old installation, migrating...",zh:"\u68C0\u6D4B\u5230\u65E7\u7248\u5B89\u88C5\u65B9\u5F0F\uFF0C\u6B63\u5728\u8FC1\u79FB..."},installingLocally:{en:"Installing to local directory...",zh:"\u6B63\u5728\u5B89\u88C5\u5230\u672C\u5730\u76EE\u5F55..."},migrationFailed:{en:"Local installation failed, skipping migration",zh:"\u672C\u5730\u5B89\u88C5\u5931\u8D25\uFF0C\u8DF3\u8FC7\u8FC1\u79FB"},installComplete:{en:"Local installation complete",zh:"\u672C\u5730\u5B89\u88C5\u5B8C\u6210"},migrationComplete:{en:"Detected old installation, migration complete. Please restart Tako CLI",zh:"\u68C0\u6D4B\u5230\u65E7\u7248\u5B89\u88C5\uFF0C\u5DF2\u5B8C\u6210\u8FC1\u79FB\uFF0C\u8BF7\u91CD\u65B0\u542F\u52A8 Tako CLI"},newVersionAvailable:{en:"New version v{version} available (current v{current})",zh:"\u53D1\u73B0\u65B0\u7248\u672C v{version}\uFF08\u5F53\u524D v{current}\uFF09"},pleaseRestart:{en:"Please restart Tako CLI to use the new version",zh:"\u8BF7\u91CD\u65B0\u542F\u52A8 Tako CLI \u4EE5\u4F7F\u7528\u65B0\u7248\u672C"}},region:{usingChinaMirror:{en:"Detected China mainland network, using domestic mirror",zh:"\u68C0\u6D4B\u5230\u4E2D\u56FD\u5927\u9646\u7F51\u7EDC\uFF0C\u4F7F\u7528\u56FD\u5185\u955C\u50CF\u6E90"},usingGlobalMirror:{en:"Using global mirror",zh:"\u4F7F\u7528\u56FD\u9645\u6E90"}},telemetry:{toggle:{en:"Toggle Telemetry",zh:"\u5207\u6362\u9065\u6D4B"},enabled:{en:"Telemetry is enabled",zh:"\u9065\u6D4B\u5DF2\u5F00\u542F"},disabled:{en:"Telemetry is disabled",zh:"\u9065\u6D4B\u5DF2\u5173\u95ED"},description:{en:"Anonymous usage data helps us improve Tako CLI",zh:"\u533F\u540D\u4F7F\u7528\u6570\u636E\u5E2E\u52A9\u6211\u4EEC\u6539\u8FDB Tako CLI"}},time:{justNow:{en:"just now",zh:"\u521A\u521A"},minutesAgo:{en:"{n}m ago",zh:"{n}\u5206\u949F\u524D"},hoursAgo:{en:"{n}h ago",zh:"{n}\u5C0F\u65F6\u524D"},yesterday:{en:"yesterday",zh:"\u6628\u5929"},daysAgo:{en:"{n}d ago",zh:"{n}\u5929\u524D"},weeksAgo:{en:"{n}w ago",zh:"{n}\u5468\u524D"},monthsAgo:{en:"{n}mo ago",zh:"{n}\u6708\u524D"}},claudeCode:{settingsDetected:{en:`Detected hardcoded config in Claude Code settings that conflicts with Tako:
285
285
  {fields}`,zh:`\u68C0\u6D4B\u5230 Claude Code settings \u4E2D\u5B58\u5728\u4E0E Tako \u51B2\u7A81\u7684\u914D\u7F6E\uFF1A
286
- {fields}`},confirmClean:{en:"Clean these settings? Tako will manage them automatically at launch",zh:"\u662F\u5426\u6E05\u7406\u8FD9\u4E9B\u914D\u7F6E\uFF1FTako \u542F\u52A8\u65F6\u4F1A\u81EA\u52A8\u6CE8\u5165\u6B63\u786E\u7684\u503C"},settingsCleaned:{en:"Settings cleaned, Tako will manage these configs automatically",zh:"\u5DF2\u6E05\u7406\u5B8C\u6210\uFF0CTako \u4F1A\u81EA\u52A8\u7BA1\u7406\u8FD9\u4E9B\u914D\u7F6E"},cleanSkipped:{en:"Skipped. Note: hardcoded settings may cause issues with Tako",zh:"\u5DF2\u8DF3\u8FC7\u3002\u6CE8\u610F\uFF1A\u5199\u6B7B\u7684\u914D\u7F6E\u53EF\u80FD\u5BFC\u81F4 Tako \u542F\u52A8\u5F02\u5E38"},usingIsolatedSettings:{en:"Using Tako-managed Claude Code settings for this launch: {path}",zh:"\u672C\u6B21\u542F\u52A8\u5C06\u4F7F\u7528 Tako \u6258\u7BA1\u7684 Claude Code settings\uFF1A{path}"},subscriptionMissingAuth:{en:"Selected Claude account has no captured credentials. Run `claude /login` for that account, then re-detect in Tako.",zh:"\u76EE\u6807 Claude \u8D26\u53F7\u7F3A\u5C11\u51ED\u636E\u3002\u8BF7\u7528 `claude /login` \u767B\u5F55\u8BE5\u8D26\u53F7\u540E\uFF0C\u8BA9 Tako \u91CD\u65B0\u68C0\u6D4B\u4E00\u6B21\u3002"},subscriptionSwitched:{en:"Switched Claude Code login to {email}",zh:"\u5DF2\u5207\u6362 Claude Code \u767B\u5F55\u8D26\u53F7\u4E3A {email}"},unknownCurrentAccount:{en:"Current Claude login ({email}) is not tracked by Tako; its tokens will be overwritten.",zh:"\u5F53\u524D Claude \u767B\u5F55\u8D26\u53F7 ({email}) \u672A\u88AB Tako \u8BB0\u5F55\uFF0C\u5207\u6362\u540E\u8BE5\u8D26\u53F7 token \u5C06\u88AB\u8986\u76D6\u3002"}},recentProjects:{title:{en:"Recent Projects",zh:"\u6700\u8FD1\u9879\u76EE"},launchInCurrent:{en:"Launch in current directory",zh:"\u5728\u5F53\u524D\u76EE\u5F55\u542F\u52A8"}},providers:{management:{en:"Manage Providers",zh:"\u7BA1\u7406\u670D\u52A1\u5546"},selectProvider:{en:"Select provider:",zh:"\u9009\u62E9\u670D\u52A1\u5546\uFF1A"},selectType:{en:"Provider type:",zh:"\u670D\u52A1\u5546\u7C7B\u578B\uFF1A"},enterName:{en:"Provider name:",zh:"\u670D\u52A1\u5546\u540D\u79F0\uFF1A"},enterApiKey:{en:"API Key:",zh:"API Key\uFF1A"},enterBaseUrl:{en:"Base URL:",zh:"\u57FA\u7840 URL\uFF1A"},add:{en:"Add Provider",zh:"\u6DFB\u52A0\u670D\u52A1\u5546"},edit:{en:"Edit Provider",zh:"\u7F16\u8F91\u670D\u52A1\u5546"},delete:{en:"Delete Provider",zh:"\u5220\u9664\u670D\u52A1\u5546"},setDefault:{en:"Set as Default",zh:"\u8BBE\u4E3A\u9ED8\u8BA4"},rescan:{en:"Re-scan Subscriptions",zh:"\u91CD\u65B0\u626B\u63CF\u8BA2\u9605"},back:{en:"Back",zh:"\u8FD4\u56DE"},added:{en:"Provider added",zh:"\u670D\u52A1\u5546\u5DF2\u6DFB\u52A0"},deleted:{en:"Provider deleted",zh:"\u670D\u52A1\u5546\u5DF2\u5220\u9664"},updated:{en:"Provider updated",zh:"\u670D\u52A1\u5546\u5DF2\u66F4\u65B0"},defaultSet:{en:"Default provider set",zh:"\u9ED8\u8BA4\u670D\u52A1\u5546\u5DF2\u8BBE\u7F6E"},noProviders:{en:"No providers configured",zh:"\u672A\u914D\u7F6E\u670D\u52A1\u5546"},noCompatible:{en:"No provider supports {client}",zh:"\u6CA1\u6709\u652F\u6301 {client} \u7684\u670D\u52A1\u5546"},defaultLabel:{en:"(default)",zh:"\uFF08\u9ED8\u8BA4\uFF09"},detected:{en:"Detected: {name}",zh:"\u68C0\u6D4B\u5230\uFF1A{name}"},confirmDelete:{en:"Delete {name}?",zh:"\u786E\u8BA4\u5220\u9664 {name}\uFF1F"},scanComplete:{en:"Scan complete, found {count} new provider(s)",zh:"\u626B\u63CF\u5B8C\u6210\uFF0C\u53D1\u73B0 {count} \u4E2A\u65B0\u670D\u52A1\u5546"}}}});import{readFileSync as j_,writeFileSync as V_,mkdirSync as q_}from"fs";import{join as MS}from"path";import{homedir as _S}from"os";function $_(){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 Z_(){try{let e=j_(OS,"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>X_)return null;return o.region}catch{return null}}function LS(e){try{q_(MS(_S(),".tako"),{recursive:!0}),V_(OS,JSON.stringify({region:e,detectedAt:Date.now()}),"utf-8")}catch{}}function eO(){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 tO(){if(_f)return _f;return _f=(async()=>{let o=[nO,oO,iO,rO].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"}})(),_f}async function Rr(){if(Pu)return Pu;let e=$_();if(e)return Pu=e,e;let o=Z_();if(o)return Pu=o,o;let i=eO();if(i)return Pu=i,LS(i),i;let a=await tO();return Pu=a,LS(a),a}async function nO(){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 oO(){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 iO(){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 rO(){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 aO(){let e=await Rr();return mA[e]}async function yi(){return(await aO()).npm}function US(){return"curl -fsSL https://bun.sh/install | bash"}async function sO(){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 f=0;f<3;f++)if(d[f]!==p[f])return p[f]-d[f];return 0});if(a.length===0)throw Error("No bun versions found on mirror");return a[0]}async function GS(){let e=mA.cn.bunBinary,o=await sO(),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 W0(){let e=await Rr(),o=mA[e];if(e==="cn")Me.info(`${Se("region.usingChinaMirror")} npm: ${o.npm}`);else Me.info(Se("region.usingGlobalMirror"))}var Pu=null,_f=null,OS,X_=2592000000,mA;var Nc=_(()=>{Tn();Nr();OS=MS(_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 AO=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)}},HS=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 AO({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 PS=()=>{};function zS(){if(!zu)zu=new HS({clientId:uO,clientSecret:lO,apiUrl:cO});return zu}function KS(e,o,i){let a=zS().track(e,{profileId:o,...i}).catch(()=>{});Of.push(a)}function JS(e,o){let{email:i,...a}=o,s=zS().identify({profileId:e,...typeof i==="string"?{email:i}:{},firstName:String(a.platform||""),properties:a}).catch(()=>{});Of.push(s)}async function YS(){if(await Promise.allSettled(Of),Of.length=0,zu){try{zu.flush()}catch{}zu=null}}var uO="d65a6d4b-f702-4af6-98e7-bdb999e01d5f",lO="sec_1e0ea34016bc3a5f8ef5",cO="https://op.shiroha.tech/api",zu=null,Of;var WS=_(()=>{PS();Of=[]});function jS(){return{cli_version:dO,platform:process.platform,arch:process.arch,locale:Ji(),node_version:process.version}}function VS(e){return Bun.hash(e).toString(16).slice(0,8)}var dO="0.3.52";var j0=_(()=>{Tn()});async function qS(){if(Ku!==null)return Ku;try{return Ku=(await nt()).telemetryEnabled!==!1,Ku}catch{return Ku=!1,!1}}async function XS(){try{let e=await nt();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 Yi(){if(V0)return;try{if(!await qS())return;let e=await nt(),o=await XS();if(o==="anonymous")return;let a=(e.providers??[]).find((u)=>u.email)?.email,s=await Rr();JS(o,{...a?{email:a}:{},region:s,locale:Ji(),first_seen_version:pO,platform:process.platform,arch:process.arch}),V0=!0}catch{}}function Jn(e,o){fO(e,o).catch(()=>{})}async function fO(e,o){try{if(!await qS())return;let i=await XS();KS(e,i,{...jS(),...o})}catch{}}async function Rc(){await YS()}function wa(){Ku=null,V0=!1}var pO="0.3.52",V0=!1,Ku=null;var Tr=_(()=>{WS();Kt();Nc();Tn();j0();j0()});function CO(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 ms(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(CO(o,s))};d();let p=setInterval(d,1000),f=(h)=>{if(!h)return;if(u.push(h),gO.test(h))s.phase="\u89E3\u6790\u4F9D\u8D56";else if($S.test(h)){s.phase="\u4E0B\u8F7D\u5E76\u89E3\u538B";let Q=h.match($S);if(Q)s.pkgCount=parseInt(Q[1],10)}else if(mO.test(h))s.phase="\u5199\u5165 lockfile";else if(EO.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:b,value:v}=await Q.read();if(b)break;w+=C.decode(v,{stream:!0}).replace(/\r/g,"");let S=w.split(`
286
+ {fields}`},confirmClean:{en:"Clean these settings? Tako will manage them automatically at launch",zh:"\u662F\u5426\u6E05\u7406\u8FD9\u4E9B\u914D\u7F6E\uFF1FTako \u542F\u52A8\u65F6\u4F1A\u81EA\u52A8\u6CE8\u5165\u6B63\u786E\u7684\u503C"},settingsCleaned:{en:"Settings cleaned, Tako will manage these configs automatically",zh:"\u5DF2\u6E05\u7406\u5B8C\u6210\uFF0CTako \u4F1A\u81EA\u52A8\u7BA1\u7406\u8FD9\u4E9B\u914D\u7F6E"},cleanSkipped:{en:"Skipped. Note: hardcoded settings may cause issues with Tako",zh:"\u5DF2\u8DF3\u8FC7\u3002\u6CE8\u610F\uFF1A\u5199\u6B7B\u7684\u914D\u7F6E\u53EF\u80FD\u5BFC\u81F4 Tako \u542F\u52A8\u5F02\u5E38"},usingIsolatedSettings:{en:"Using Tako-managed Claude Code settings for this launch: {path}",zh:"\u672C\u6B21\u542F\u52A8\u5C06\u4F7F\u7528 Tako \u6258\u7BA1\u7684 Claude Code settings\uFF1A{path}"},subscriptionMissingAuth:{en:"Selected Claude account has no captured credentials. Run `claude /login` for that account, then re-detect in Tako.",zh:"\u76EE\u6807 Claude \u8D26\u53F7\u7F3A\u5C11\u51ED\u636E\u3002\u8BF7\u7528 `claude /login` \u767B\u5F55\u8BE5\u8D26\u53F7\u540E\uFF0C\u8BA9 Tako \u91CD\u65B0\u68C0\u6D4B\u4E00\u6B21\u3002"},subscriptionSwitched:{en:"Switched Claude Code login to {email}",zh:"\u5DF2\u5207\u6362 Claude Code \u767B\u5F55\u8D26\u53F7\u4E3A {email}"},unknownCurrentAccount:{en:"Current Claude login ({email}) is not tracked by Tako; its tokens will be overwritten.",zh:"\u5F53\u524D Claude \u767B\u5F55\u8D26\u53F7 ({email}) \u672A\u88AB Tako \u8BB0\u5F55\uFF0C\u5207\u6362\u540E\u8BE5\u8D26\u53F7 token \u5C06\u88AB\u8986\u76D6\u3002"}},recentProjects:{title:{en:"Recent Projects",zh:"\u6700\u8FD1\u9879\u76EE"},launchInCurrent:{en:"Launch in current directory",zh:"\u5728\u5F53\u524D\u76EE\u5F55\u542F\u52A8"}},providers:{management:{en:"Manage Providers",zh:"\u7BA1\u7406\u670D\u52A1\u5546"},selectProvider:{en:"Select provider:",zh:"\u9009\u62E9\u670D\u52A1\u5546\uFF1A"},selectType:{en:"Provider type:",zh:"\u670D\u52A1\u5546\u7C7B\u578B\uFF1A"},enterName:{en:"Provider name:",zh:"\u670D\u52A1\u5546\u540D\u79F0\uFF1A"},enterApiKey:{en:"API Key:",zh:"API Key\uFF1A"},enterBaseUrl:{en:"Base URL:",zh:"\u57FA\u7840 URL\uFF1A"},add:{en:"Add Provider",zh:"\u6DFB\u52A0\u670D\u52A1\u5546"},edit:{en:"Edit Provider",zh:"\u7F16\u8F91\u670D\u52A1\u5546"},delete:{en:"Delete Provider",zh:"\u5220\u9664\u670D\u52A1\u5546"},setDefault:{en:"Set as Default",zh:"\u8BBE\u4E3A\u9ED8\u8BA4"},rescan:{en:"Re-scan Subscriptions",zh:"\u91CD\u65B0\u626B\u63CF\u8BA2\u9605"},back:{en:"Back",zh:"\u8FD4\u56DE"},added:{en:"Provider added",zh:"\u670D\u52A1\u5546\u5DF2\u6DFB\u52A0"},deleted:{en:"Provider deleted",zh:"\u670D\u52A1\u5546\u5DF2\u5220\u9664"},updated:{en:"Provider updated",zh:"\u670D\u52A1\u5546\u5DF2\u66F4\u65B0"},defaultSet:{en:"Default provider set",zh:"\u9ED8\u8BA4\u670D\u52A1\u5546\u5DF2\u8BBE\u7F6E"},noProviders:{en:"No providers configured",zh:"\u672A\u914D\u7F6E\u670D\u52A1\u5546"},noCompatible:{en:"No provider supports {client}",zh:"\u6CA1\u6709\u652F\u6301 {client} \u7684\u670D\u52A1\u5546"},defaultLabel:{en:"(default)",zh:"\uFF08\u9ED8\u8BA4\uFF09"},detected:{en:"Detected: {name}",zh:"\u68C0\u6D4B\u5230\uFF1A{name}"},confirmDelete:{en:"Delete {name}?",zh:"\u786E\u8BA4\u5220\u9664 {name}\uFF1F"},scanComplete:{en:"Scan complete, found {count} new provider(s)",zh:"\u626B\u63CF\u5B8C\u6210\uFF0C\u53D1\u73B0 {count} \u4E2A\u65B0\u670D\u52A1\u5546"}}}});import{readFileSync as j_,writeFileSync as V_,mkdirSync as q_}from"fs";import{join as MS}from"path";import{homedir as _S}from"os";function $_(){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 Z_(){try{let e=j_(OS,"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>X_)return null;return o.region}catch{return null}}function LS(e){try{q_(MS(_S(),".tako"),{recursive:!0}),V_(OS,JSON.stringify({region:e,detectedAt:Date.now()}),"utf-8")}catch{}}function eO(){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 tO(){if(_f)return _f;return _f=(async()=>{let o=[nO,oO,iO,rO].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"}})(),_f}async function Rr(){if(Pu)return Pu;let e=$_();if(e)return Pu=e,e;let o=Z_();if(o)return Pu=o,o;let i=eO();if(i)return Pu=i,LS(i),i;let a=await tO();return Pu=a,LS(a),a}async function nO(){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 oO(){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 iO(){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 rO(){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 aO(){let e=await Rr();return mA[e]}async function yi(){return(await aO()).npm}function US(){return"curl -fsSL https://bun.sh/install | bash"}async function sO(){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 f=0;f<3;f++)if(d[f]!==p[f])return p[f]-d[f];return 0});if(a.length===0)throw Error("No bun versions found on mirror");return a[0]}async function GS(){let e=mA.cn.bunBinary,o=await sO(),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 W0(){let e=await Rr(),o=mA[e];if(e==="cn")Me.info(`${Se("region.usingChinaMirror")} npm: ${o.npm}`);else Me.info(Se("region.usingGlobalMirror"))}var Pu=null,_f=null,OS,X_=2592000000,mA;var Nc=_(()=>{Tn();Nr();OS=MS(_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 AO=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)}},HS=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 AO({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 PS=()=>{};function zS(){if(!zu)zu=new HS({clientId:uO,clientSecret:lO,apiUrl:cO});return zu}function KS(e,o,i){let a=zS().track(e,{profileId:o,...i}).catch(()=>{});Of.push(a)}function JS(e,o){let{email:i,...a}=o,s=Promise.resolve(zS().identify({profileId:e,...typeof i==="string"?{email:i}:{},firstName:String(a.platform||""),properties:a})).catch(()=>{});Of.push(s)}async function YS(){if(await Promise.allSettled(Of),Of.length=0,zu){try{zu.flush()}catch{}zu=null}}var uO="d65a6d4b-f702-4af6-98e7-bdb999e01d5f",lO="sec_1e0ea34016bc3a5f8ef5",cO="https://op.shiroha.tech/api",zu=null,Of;var WS=_(()=>{PS();Of=[]});function jS(){return{cli_version:dO,platform:process.platform,arch:process.arch,locale:Ji(),node_version:process.version}}function VS(e){return Bun.hash(e).toString(16).slice(0,8)}var dO="0.3.53";var j0=_(()=>{Tn()});async function qS(){if(Ku!==null)return Ku;try{return Ku=(await nt()).telemetryEnabled!==!1,Ku}catch{return Ku=!1,!1}}async function XS(){try{let e=await nt();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 Yi(){if(V0)return;try{if(!await qS())return;let e=await nt(),o=await XS();if(o==="anonymous")return;let a=(e.providers??[]).find((u)=>u.email)?.email,s=await Rr();JS(o,{...a?{email:a}:{},region:s,locale:Ji(),first_seen_version:pO,platform:process.platform,arch:process.arch}),V0=!0}catch{}}function Jn(e,o){fO(e,o).catch(()=>{})}async function fO(e,o){try{if(!await qS())return;let i=await XS();KS(e,i,{...jS(),...o})}catch{}}async function Rc(){await YS()}function wa(){Ku=null,V0=!1}var pO="0.3.53",V0=!1,Ku=null;var Tr=_(()=>{WS();Kt();Nc();Tn();j0();j0()});function CO(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 ms(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(CO(o,s))};d();let p=setInterval(d,1000),f=(h)=>{if(!h)return;if(u.push(h),gO.test(h))s.phase="\u89E3\u6790\u4F9D\u8D56";else if($S.test(h)){s.phase="\u4E0B\u8F7D\u5E76\u89E3\u538B";let Q=h.match($S);if(Q)s.pkgCount=parseInt(Q[1],10)}else if(mO.test(h))s.phase="\u5199\u5165 lockfile";else if(EO.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:b,value:v}=await Q.read();if(b)break;w+=C.decode(v,{stream:!0}).replace(/\r/g,"");let S=w.split(`
287
287
  `);w=S.pop()??"";for(let L of S)f(L)}if(w)f(w)}finally{Q.releaseLock()}};try{await Promise.all([m(e.stderr),m(e.stdout)])}finally{clearInterval(p)}return u.join(`
288
288
  `)}var gO,$S,mO,EO;var Uf=_(()=>{gO=/^Resolving dependencies/,$S=/^Resolved, downloaded and extracted \[(\d+)\]/,mO=/^Saved lockfile/,EO=/^(\d+) packages? installed/});function hO(e){return e.replace(/\r/g,`
289
289
  `).replace(/\n{3,}/g,`
@@ -698,7 +698,7 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
698
698
  <%s {...props} />
699
699
  React keys must be passed directly to JSX without using spread:
700
700
  let props = %s;
701
- <%s key={someKey} {...props} />`,tt,Ct,Yt,Ct),xe[Ct+tt]=!0)}if(Ct=null,Re!==void 0&&(i(Re),Ct=""+Re),d(_e)&&(i(_e.key),Ct=""+_e.key),"key"in _e){Re={};for(var Wt in _e)Wt!=="key"&&(Re[Wt]=_e[Wt])}else Re=_e;return Ct&&p(Re,typeof ne==="function"?ne.displayName||ne.name||"Unknown":ne),m(ne,Ct,Re,s(),vt,ut)}function Q(ne){C(ne)?ne._store&&(ne._store.validated=1):typeof ne==="object"&&ne!==null&&ne.$$typeof===Ce&&(ne._payload.status==="fulfilled"?C(ne._payload.value)&&ne._payload.value._store&&(ne._payload.value._store.validated=1):ne._store&&(ne._store.validated=1))}function C(ne){return typeof ne==="object"&&ne!==null&&ne.$$typeof===w}var w=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),J=Symbol.for("react.consumer"),j=Symbol.for("react.context"),oe=Symbol.for("react.forward_ref"),de=Symbol.for("react.suspense"),pe=Symbol.for("react.suspense_list"),Ee=Symbol.for("react.memo"),Ce=Symbol.for("react.lazy"),se=Symbol.for("react.activity"),Ie=Symbol.for("react.client.reference"),ve=HA.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ye=Object.prototype.hasOwnProperty,gt=Array.isArray,Nt=console.createTask?console.createTask:function(){return null};HA={react_stack_bottom_frame:function(ne){return ne()}};var z,Qe={},Te=HA.react_stack_bottom_frame.bind(HA,u)(),ze=Nt(a(u)),xe={};r9.Fragment=v,r9.jsxDEV=function(ne,_e,Re,tt){var vt=1e4>ve.recentlyCreatedOwnerStacks++;return h(ne,_e,Re,tt,vt?Error("react-stack-top-frame"):Te,vt?Nt(a(ne)):ze)}})()});function pk({zh:e}){return at.jsxDEV(U,{marginTop:0,justifyContent:"center",gap:2,children:a9.flatMap((o,i)=>[i>0?at.jsxDEV(B,{dimColor:!0,children:"\u2502"},`s${i}`,!1,void 0,this):null,at.jsxDEV(B,{dimColor:!0,bold:!0,children:o[0]},`k${i}`,!1,void 0,this),at.jsxDEV(B,{dimColor:!0,children:e?o[1]:o[2]},`l${i}`,!1,void 0,this)])},void 0,!1,void 0,this)}function fk({provs:e,provIdx:o,pickerIdx:i,color:a,zh:s}){return at.jsxDEV(U,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:a,paddingX:1,paddingY:0,children:[at.jsxDEV(B,{bold:!0,color:a,children:["\u25A3 ",s?"\u9009\u62E9\u670D\u52A1\u5546":"Pick Provider"]},void 0,!0,void 0,this),at.jsxDEV(U,{flexDirection:"column",marginTop:0,children:[e.length===0&&at.jsxDEV(U,{paddingLeft:1,children:at.jsxDEV(B,{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,f=d===o;return at.jsxDEV(U,{paddingLeft:1,children:[at.jsxDEV(B,{color:p?a:void 0,bold:p,children:p?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:p,color:p?a:void 0,children:[" ",u.name]},void 0,!0,void 0,this),u.email&&at.jsxDEV(B,{dimColor:!0,children:[" (",u.email,")"]},void 0,!0,void 0,this),f&&at.jsxDEV(B,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},u.id,!0,void 0,this)}),(()=>{let u=i===e.length;return at.jsxDEV(U,{paddingLeft:1,marginTop:1,children:[at.jsxDEV(B,{color:u?a:void 0,bold:u,children:u?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{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),at.jsxDEV(pk,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gk({group:e,options:o,enabled:i,pickerIdx:a,color:s,zh:u,pickCounts:d={},query:p=""}){let f=o.filter((v)=>v.group===e),m=e==="model",h=m?Ym(f,d,p,u):f,Q=m?dk(a,h.length):{start:0,end:h.length},C=h.slice(Q.start,Q.end),w=m?u?"\u9009\u62E9\u6A21\u578B":"Pick Model":e==="subagent-model"?u?"\u5B50\u4EE3\u7406\u6A21\u578B":"Subagent Model":e,b=!f.some((v)=>i.has(v.id));return at.jsxDEV(U,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:s,paddingX:1,paddingY:0,children:[at.jsxDEV(B,{bold:!0,color:s,children:["\u25A3 ",w]},void 0,!0,void 0,this),m&&at.jsxDEV(U,{paddingLeft:1,children:[at.jsxDEV(B,{color:s,bold:!0,children:"\u203A "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:!!p,dimColor:!p,children:p||(u?"\u8F93\u5165\u5B57\u6BCD\u7B5B\u9009":"Type to filter")},void 0,!1,void 0,this),at.jsxDEV(B,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this),at.jsxDEV(U,{flexDirection:"column",marginTop:0,children:[!m&&(()=>{let v=a===0;return at.jsxDEV(U,{paddingLeft:1,children:[at.jsxDEV(B,{color:v?s:void 0,bold:v,children:v?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:v,color:v?s:void 0,children:[" ",u?"\u9ED8\u8BA4\uFF08\u4E0D\u6307\u5B9A\uFF09":"Default (none)"]},void 0,!0,void 0,this),b&&at.jsxDEV(B,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),C.map((v,S)=>{let L=Q.start+S,J=a===(m?L:L+1),j=i.has(v.id);return at.jsxDEV(U,{paddingLeft:1,flexDirection:"column",children:[at.jsxDEV(U,{children:[at.jsxDEV(B,{color:J?s:void 0,bold:J,children:J?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:J,color:J?s:void 0,children:[" ",v.label[u?"zh":"en"]||v.label.en]},void 0,!0,void 0,this),j&&at.jsxDEV(B,{color:"green",children:" \u2605"},void 0,!1,void 0,this),at.jsxDEV(B,{dimColor:!0,children:[" ",v.flag]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J&&at.jsxDEV(U,{paddingLeft:3,children:at.jsxDEV(B,{dimColor:!0,children:v.description[u?"zh":"en"]||v.description.en},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},v.id,!0,void 0,this)}),m&&h.length===0&&at.jsxDEV(U,{paddingLeft:1,children:at.jsxDEV(B,{dimColor:!0,children:u?"\u65E0\u5339\u914D\u6A21\u578B":"No matching models"},void 0,!1,void 0,this)},void 0,!1,void 0,this),m&&h.length>my&&at.jsxDEV(U,{paddingLeft:1,children:at.jsxDEV(B,{dimColor:!0,children:[a+1,"/",h.length]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),at.jsxDEV(pk,{zh:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var at,a9;var mk=_(async()=>{Ey();await si();at=Be(An(),1),a9=[["\u2191\u2193","\u9009\u62E9","select"],["Enter","\u786E\u8BA4","confirm"],["Esc","\u53D6\u6D88","cancel"]]});function Ck(e){let o=e.codePointAt(0);if(!o)return!1;return o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=191471||o>=63744&&o<=64255||o>=194560&&o<=195103||o>=44032&&o<=55215||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=65280&&o<=65519||o>=126976&&o<=131071||o>=9728&&o<=10175||o===11088}function s9(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Ek(e){let o=s9(e),i=0;for(let a of o)i+=Ck(a)?2:1;return i}function Wm(e,o,i="..."){if(Ek(e)<=o)return e;let s=Ek(i),u=o-s;if(u<=0)return i.slice(0,o);let d=0,p="";for(let f of e){let m=Ck(f)?2:1;if(d+m>u)break;p+=f,d+=m}return p+i}function Cy(e,o){if(!e||o.ctrl||o.meta)return"";return e.replace(/[\x00-\x1f\x7f]/g,"")}function hk(e,o){if(o.length>0)return new Set(o);return new Set(e.filter((i)=>i.defaultOn).map((i)=>i.id))}function yk(e){return e.replace(/```[\s\S]*?```/g," [code] ").replace(/[`*_#>|]/g,"").replace(/\s+/g," ").trim()}function u9(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 l9(e){if(e==="claude")return"Claude";if(e==="codex")return"Codex";if(e==="grok")return"Grok";if(e==="pi")return"Pi";return"Gemini"}function c9(e){if(e==="claude")return"magenta";if(e==="codex")return"blue";if(e==="grok")return"white";if(e==="pi")return"magenta";return"cyan"}function d9(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 Dk({color:e}){let{stdout:o}=zm(),i=Math.max((o.columns||80)-6,20);return H.jsxDEV(U,{marginY:0,children:H.jsxDEV(B,{dimColor:!0,color:e,children:"\u2500".repeat(i)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function p9(e){return e>30?"green":e>10?"yellow":"red"}function f9({provider:e,zh:o}){if(!e)return H.jsxDEV(B,{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(B,{color:a.color,children:[a.icon," ",s]},void 0,!0,void 0,this),u&&H.jsxDEV(B,{dimColor:!0,children:[" \xB7 ",u]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function g9({quota:e,zh:o}){if(e.status==="unsupported")return null;if(e.status==="error")return H.jsxDEV(B,{dimColor:!0,children:["\uD83D\uDCB0 ",qi(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 f=p.costUsed??0;return H.jsxDEV(B,{dimColor:!0,children:["\uD83D\uDCB0 ",o?"\u4ECA\u65E5":"Today",": ",H.jsxDEV(B,{color:"green",children:["$",f.toFixed(2)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}let i=(d,p,f)=>{if(d&&d>=1440)return`${Math.round(d/1440)}d`;if(d)return`${Math.round(d/60)}h`;return f?`${f}d`:`${p}h`},a=(d)=>Math.max(0,Math.min(100,100-Math.round(d))),s=[],u=(d,p,f)=>{if(s.length)s.push(H.jsxDEV(B,{dimColor:!0,children:" \xB7 "},`sep-${d}`,!1,void 0,this));let m=a(f);s.push(H.jsxDEV(Xe.default.Fragment,{children:[`${p} \u5269 `,H.jsxDEV(B,{color:p9(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(B,{dimColor:!0,children:["\uD83D\uDCB0 ",s]},void 0,!0,void 0,this)}function m9({clients:e,defaultIdx:o,hasProviders:i,pickCounts:a,initialSessionSearch:s=!1,onResult:u}){let{stdout:d}=zm(),[p,f]=Xe.useState(o),[m,h]=Xe.useState(s?"search":"projects"),[Q,C]=Xe.useState(0),[w,b]=Xe.useState(0),[v,S]=Xe.useState(()=>e[o]?.activeProvIdx||0),[L,J]=Xe.useState(()=>hk(e[o]?.launchOptions??[],e[o]?.lastSelectedOptionIds??[])),[j,oe]=Xe.useState(""),[de,pe]=Xe.useState(null),[Ee,Ce]=Xe.useState(""),[se,Ie]=Xe.useState(!1),[ve,ye]=Xe.useState(0),[gt,Nt]=Xe.useState(""),[z,Qe]=Xe.useState(""),[Te,ze]=Xe.useState(0),xe=Xe.useRef(0),[ne,_e]=Xe.useState(null),Re=Xe.useRef(null),[tt,vt]=Xe.useState(null),[ut,Ct]=Xe.useState(0),[Yt,Wt]=Xe.useState(!1),[je,ot]=Xe.useState(""),[X,re]=Xe.useState(null),[ee,ue]=Xe.useState(null),Oe=Math.max(2,Math.min((d.columns||80)<100?4:6,Math.floor(((d.rows||30)-12)/2))),[lt,Rt]=Xe.useState(Oe),ke=Xe.useRef(!0),yt=e[p],{projects:Ot,providers:Xt}=yt,Ut=Ik[yt.client.id]||Bk,Ge=Ao()==="zh",jt=Xt[v],Ko=Xe.default.useMemo(()=>tt?Lg(tt,z,{currentCwd:Ot[0]?.path,limit:lt+1}):[],[tt,z,ut,Ot,lt]),To=Ko.length>lt,Lt=Xe.default.useMemo(()=>Ko.slice(0,lt),[Ko,lt]),Jo=Math.max(0,Math.min(Te-Oe+1,Math.max(0,Lt.length-Oe))),or=Lt.slice(Jo,Jo+Oe);Xe.useEffect(()=>{let I=Mg(),N=!1;vt(I),Wt(!0),ot("");let P=id(I).then(()=>{if(!N)Ct((K)=>K+1)}).catch((K)=>{if(!N)ot(K instanceof Error?K.message:String(K))}).finally(()=>{if(!N)Wt(!1)});return()=>{N=!0,vt(null),P.finally(()=>I.close())}},[]),Xe.useEffect(()=>{if(!gt){Qe("");return}let I=setTimeout(()=>Qe(gt),120);return()=>clearTimeout(I)},[gt]),Xe.useEffect(()=>{Rt((I)=>Math.max(I,Oe)),ze((I)=>{let N=Math.max(0,Math.min(I,lt-1));return xe.current=N,N})},[Oe,lt]),Xe.useEffect(()=>{if(Lt.length===0){xe.current=0,Re.current=null,ze(0),_e(null);return}let I=Re.current?Lt.findIndex((K)=>K.session.key===Re.current):-1,N=I>=0?I:Math.min(xe.current,Lt.length-1),P=Lt[N].session.key;xe.current=N,Re.current=P,ze(N),_e(P)},[Lt]),Xe.useEffect(()=>{if(!tt||!X){ue(null);return}let I=tt.getSession(X),N=tt.getRecentMessages(X,32).filter((P)=>P.role==="user"||P.role==="assistant").slice(-8);ue(I?{session:I,messages:N}:null)},[tt,X]);let mn=Xe.default.useMemo(()=>Lu(yt.client,jt),[yt.client.id,jt?.id,jt?.type]),Sn=Xe.default.useMemo(()=>rk(mn,Ge),[mn,Ge]),no=jt?.name||(Ge?"\u672A\u914D\u7F6E":"N/A"),[nn,Yo]=Xe.useState(null);Xe.useEffect(()=>{if(!jt){Yo(null);return}let I=!1;return ug(jt).then((N)=>{if(!I)Yo(N)}),()=>{I=!0}},[jt?.id,jt?.type]),Xe.useEffect(()=>{if(ke.current){ke.current=!1;return}C(0),b(0),h("projects"),S(e[p]?.activeProvIdx||0),pe(null),Ce(""),Ie(!1),J(hk(e[p]?.launchOptions??[],e[p]?.lastSelectedOptionIds??[]))},[p]),Xe.useEffect(()=>{J((I)=>Jm(I,mn,jt?.model,yt.client.id==="pi"?`model-${IA}`:yt.client.id==="grok"?`model-${$u}`:void 0))},[mn,jt?.model]);let jn=Xe.useCallback((I)=>{if(mn.filter((P)=>P.group===I).length===0)return;Ce(""),ye(0),pe(I)},[mn]);return Hn(Xe.useCallback((I,N)=>{if(se){let K=Xt.length+1;if(N.escape||I==="q"){Ie(!1);return}if(N.upArrow){ye((Ae)=>Ae>0?Ae-1:K-1);return}if(N.downArrow){ye((Ae)=>Ae<K-1?Ae+1:0);return}if(N.return)if(ve<Xt.length){let Ae=Xt[ve];S(ve),(async()=>{if(await Jf(yt.client.id,Ae.id),yt.client.setupConfigFiles)try{await yt.client.setupConfigFiles(ri(Ae))}catch(De){oe(Ge?"\u26A0 \u914D\u7F6E\u540C\u6B65\u5931\u8D25":"\u26A0 Config sync failed"),setTimeout(()=>oe(""),2500);return}yt.activeProvIdx=ve,oe(Ge?`\u2713 \u5DF2\u7ED1\u5B9A ${Ae.name}`:`\u2713 Bound ${Ae.name}`),setTimeout(()=>oe(""),2000)})(),Ie(!1)}else Ie(!1),u({type:"providers"});return}if(de){let K=mn.filter((Ye)=>Ye.group===de),Ae=de==="model",De=Ae?Ym(K,a,Ee,Ge):K,Ue=Ae?De.length:De.length+1;if(N.escape||!Ae&&I==="q"){pe(null),Ce("");return}if(N.upArrow){if(Ue===0)return;ye((Ye)=>Ye>0?Ye-1:Ue-1);return}if(N.downArrow){if(Ue===0)return;ye((Ye)=>Ye<Ue-1?Ye+1:0);return}if(N.return){if(Ae){let Ye=De[ve];if(!Ye)return;J((Je)=>{let Gt=new Set(Je);for(let En of K)Gt.delete(En.id);return Gt.add(Ye.id),Gt})}else if(ve===0)J((Ye)=>{let Je=new Set(Ye);for(let Gt of K)Je.delete(Gt.id);return Je});else{let Ye=De[ve-1];J((Je)=>{let Gt=new Set(Je);for(let En of K)Gt.delete(En.id);return Gt.add(Ye.id),Gt})}pe(null),Ce("");return}if(Ae){if(N.backspace||N.delete){Ce((Je)=>Je.slice(0,-1)),ye(0);return}let Ye=Cy(I,N);if(Ye)Ce((Je)=>Je+Ye),ye(0)}return}if(m==="search"){if(X&&(N.escape||N.leftArrow)){re(null);return}if(N.escape||N.leftArrow){Nt(""),xe.current=0,Re.current=null,ze(0),_e(null),h("projects");return}if(N.rightArrow){let Ae=Lt.find((De)=>De.session.key===Re.current)??Lt[xe.current];if(Ae)re(Ae.session.key);return}if(N.downArrow){if(Lt.length===0)return;if(xe.current>=Lt.length-1&&To)Rt((Ae)=>Ae+Oe),xe.current+=1,ze(xe.current);else xe.current=Math.min(Lt.length-1,xe.current+1),ze(xe.current);Re.current=Lt[xe.current]?.session.key??null,_e(Re.current);return}if(N.upArrow){xe.current=Math.max(0,xe.current-1),ze(xe.current),Re.current=Lt[xe.current]?.session.key??null,_e(Re.current);return}if(N.backspace||N.delete){Nt((Ae)=>Ae.slice(0,-1)),xe.current=0,Re.current=null,ze(0),_e(null),re(null),Rt(Oe);return}if(N.return){let Ae=Lt.find((De)=>De.session.key===Re.current)??Lt[xe.current];if(!Ae)return;if(Ae.session.resumeCapability==="unsupported"){re(Ae.session.key);return}try{let De=xI(Ae.session,Ot[0]?.path);u({type:"launch",clientId:De.clientId,projectPath:De.projectPath,args:De.args,envVars:{},selectedOptionIds:[],resume:!0,resumeModelId:Ae.session.model})}catch(De){ot(De instanceof Error?De.message:String(De))}return}let K=Cy(I,N);if(K)Nt((Ae)=>Ae+K),xe.current=0,Re.current=null,ze(0),_e(null),re(null),Rt(Oe);return}if(I==="q"){u({type:"exit"});return}if(I==="a"){u({type:"agent"});return}if(I==="s"){u({type:"stats"});return}if(I==="c"){u({type:"config"});return}if(I==="l"){u({type:"language"});return}if(I==="p"){u({type:"providers"});return}if(I==="m"){jn("model");return}let P=parseInt(I);if(P>=1&&P<=e.length){f(P-1);return}if(N.leftArrow){f((K)=>K>0?K-1:e.length-1);return}if(N.rightArrow){f((K)=>K<e.length-1?K+1:0);return}if(m==="projects"){if(N.downArrow){if(Q<Ot.length-1)C((K)=>K+1);else if(Sn.length>0)h("options"),b(0);return}if(N.upArrow){if(Q>0)C((K)=>K-1);else xe.current=0,Re.current=Lt[0]?.session.key??null,ze(0),_e(Re.current),Rt(Oe),re(null),h("search");return}}if(m==="options"){if(N.downArrow){if(w<Sn.length-1)b((K)=>K+1);return}if(N.upArrow){if(w>0)b((K)=>K-1);else h("projects"),C(Ot.length-1);return}}if(I===" "&&m==="options"&&Sn.length>0){let K=Sn[w];if(K.kind==="flag")J((Ae)=>{let De=new Set(Ae);if(De.has(K.opt.id))De.delete(K.opt.id);else De.add(K.opt.id);return De});else if(K.kind==="group")jn(K.group);else ye(v),Ie(!0);return}if(N.return){if(m==="options"&&Sn.length>0){let De=Sn[w];if(De.kind==="group"){jn(De.group);return}if(De.kind==="provider"){ye(v),Ie(!0);return}}let K=Ot[Q],Ae=sk({launchOptions:mn,enabled:L});u({type:"launch",clientId:yt.client.id,projectPath:K.path,...Ae})}},[m,p,Q,w,v,Xt,jt,yt,Ot,mn,Sn,L,e,u,Ge,de,se,ve,a,Ee,jn,gt,Te,ne,Lt,X,lt,Oe,To])),H.jsxDEV(U,{flexDirection:"column",paddingX:0,paddingY:0,children:[H.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:m==="search"?"cyan":Ut.color,paddingX:1,paddingY:0,children:[H.jsxDEV(U,{justifyContent:"space-between",children:[H.jsxDEV(U,{gap:1,children:[H.jsxDEV(B,{bold:!0,children:"\uD83D\uDC19 Tako"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:["v",A9]},void 0,!0,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(f9,{provider:jt,zh:Ge},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(U,{children:[j&&H.jsxDEV(B,{color:"green",children:j},void 0,!1,void 0,this),!j&&nn&&H.jsxDEV(g9,{quota:nn,zh:Ge},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!i&&H.jsxDEV(U,{marginTop:1,justifyContent:"center",gap:1,children:[H.jsxDEV(B,{color:"yellow",children:"\u26A0"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\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(U,{marginTop:1,gap:1,justifyContent:"center",children:[H.jsxDEV(B,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),e.map((I,N)=>{let P=Ik[I.client.id]||Bk;return N===p?H.jsxDEV(U,{borderStyle:"bold",borderColor:P.color,paddingX:1,children:H.jsxDEV(B,{color:P.color,bold:!0,children:[P.icon," ",I.client.name]},void 0,!0,void 0,this)},I.client.id,!1,void 0,this):H.jsxDEV(U,{borderStyle:"single",borderColor:"gray",paddingX:1,children:H.jsxDEV(B,{dimColor:!0,children:[P.icon," ",I.client.name]},void 0,!0,void 0,this)},I.client.id,!1,void 0,this)}),H.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m!=="search"&&H.jsxDEV(Dk,{color:Ut.color},void 0,!1,void 0,this),se?H.jsxDEV(fk,{provs:Xt,provIdx:v,pickerIdx:ve,color:Ut.color,zh:Ge},void 0,!1,void 0,this):de?H.jsxDEV(gk,{group:de,options:mn,enabled:L,pickerIdx:ve,color:Ut.color,zh:Ge,pickCounts:a,query:Ee},void 0,!1,void 0,this):H.jsxDEV(H.Fragment,{children:[m==="search"?H.jsxDEV(U,{borderStyle:"round",borderColor:"cyan",paddingX:1,flexDirection:"column",marginTop:1,marginBottom:1,children:[H.jsxDEV(U,{justifyContent:"space-between",children:[H.jsxDEV(B,{color:"cyan",bold:!0,children:["\u2315 ",Ge?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD":"Search sessions"]},void 0,!0,void 0,this),Yt&&H.jsxDEV(B,{dimColor:!0,children:Ge?"\u7D22\u5F15\u4E2D...":"indexing..."},void 0,!1,void 0,this),!Yt&&je&&H.jsxDEV(B,{color:"red",children:["\u26A0 ",Wm(je,Math.max(16,(d.columns||80)-48))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(U,{children:[H.jsxDEV(B,{color:"cyan",bold:!0,children:"\u203A "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:!!gt,dimColor:!gt,children:gt||(Ge?"\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(B,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(B,{children:" \u2315 "},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD...":"Search previous sessions..."},void 0,!1,void 0,this),Yt&&H.jsxDEV(B,{dimColor:!0,children:[" ",Ge?"\u7D22\u5F15\u4E2D":"indexing"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X&&ee?H.jsxDEV(U,{paddingLeft:2,flexDirection:"column",children:[H.jsxDEV(B,{bold:!0,color:"cyan",children:ee.session.title??X},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:ee.session.cwd},void 0,!1,void 0,this),ee.session.resumeCapability==="unsupported"&&H.jsxDEV(B,{color:"yellow",children:Ge?"\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),ee.messages.map((I)=>H.jsxDEV(B,{children:[H.jsxDEV(B,{color:I.role==="user"?"yellow":"green",children:[I.role==="user"?"You":"AI",": "]},void 0,!0,void 0,this),I.text.replace(/\s+/g," ").slice(0,Math.max(40,(d.columns||80)-12))]},I.ordinal,!0,void 0,this))]},void 0,!0,void 0,this):m==="search"?or.map((I,N)=>{let K=Jo+N===Te,Ae=c9(I.session.source),De=d9(I.session.updatedAt,Ge),Ue=Math.max(30,(d.columns||80)-14);return H.jsxDEV(Xe.default.Fragment,{children:H.jsxDEV(U,{paddingLeft:1,flexDirection:"column",children:[H.jsxDEV(U,{children:[H.jsxDEV(B,{color:K?"cyan":void 0,bold:K,children:K?"\u25B8 ":" "},void 0,!1,void 0,this),H.jsxDEV(B,{color:"cyan",children:De},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:" \xB7 "},void 0,!1,void 0,this),H.jsxDEV(B,{color:Ae,bold:!0,children:l9(I.session.source)},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:[" \xB7 ",I.session.projectName??"\u672A\u77E5\u9879\u76EE"," \xB7 ",u9(I.session.updatedAt,Ge)," "]},void 0,!0,void 0,this),H.jsxDEV(B,{bold:K,color:K?"white":void 0,children:Wm(yk(I.session.title??I.session.nativeId.slice(0,8)),Math.max(12,Ue-36))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(B,{dimColor:!0,children:[" ",Wm(yk(I.snippet),Ue)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},I.session.key,!1,void 0,this)}).concat([H.jsxDEV(U,{paddingLeft:4,marginTop:1,children:H.jsxDEV(B,{dimColor:!0,children:[Lt.length===0?Ge?"\u6682\u65E0\u4F1A\u8BDD":"No sessions":`${Jo+1}-${Math.min(Jo+Oe,Lt.length)} / ${Lt.length}${To?"+":""}`,To?` \xB7 \u2193 ${Ge?"\u7EE7\u7EED\u6D4F\u89C8":"more"}`:""]},void 0,!0,void 0,this)},"session-window-status",!1,void 0,this)]):Ot.map((I,N)=>{let P=m==="projects"&&N===Q;return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:I.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I.hint?H.jsxDEV(B,{dimColor:!0,children:I.hint},void 0,!1,void 0,this):null]},N,!0,void 0,this)}),m!=="search"&&Sn.length>0&&H.jsxDEV(H.Fragment,{children:[H.jsxDEV(Dk,{color:Ut.color},void 0,!1,void 0,this),Sn.map((I,N)=>{let P=m==="options"&&N===w;if(I.kind==="flag"){let K=I.opt,Ae=L.has(K.id);return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{color:Ae?Ut.color:void 0,bold:Ae,children:Ae?"\u25C9":"\u25CB"},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:K.label[Ge?"zh":"en"]||K.label.en},void 0,!1,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:K.flag},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:K.description[Ge?"zh":"en"]||K.description.en},void 0,!1,void 0,this)]},K.id,!0,void 0,this)}if(I.kind==="group"){let K=ak(mn,L,I.group),Ae=K?K.shortLabel:Ge?"\u9ED8\u8BA4":"Default";return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:[I.title,":"]},void 0,!0,void 0,this),H.jsxDEV(B,{color:K?Ut.color:void 0,children:Ae},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:Ge?"Enter \u8FDB\u5165\u9009\u62E9":"Enter to pick"},void 0,!1,void 0,this)]},`group-${I.group}`,!0,void 0,this)}return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:[I.title,":"]},void 0,!0,void 0,this),H.jsxDEV(B,{color:jt?Ut.color:"yellow",children:jt?no:Ge?"\u672A\u914D\u7F6E":"Not set"},void 0,!1,void 0,this),H.jsxDEV(B,{color:"yellow",children:"\u2605"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:Ge?"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(U,{paddingX:2,marginTop:0,justifyContent:"center",gap:2,children:m==="search"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Lt[Te]?.session.resumeCapability==="unsupported"?Ge?"\u67E5\u770B":"open":Ge?"\u7EED\u63A5":"resume"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2192"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u67E5\u770B":"details"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):m==="options"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Space"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u5F00\u5173":"toggle"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9000\u51FA":"quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(H.Fragment,{children:[H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"a"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"agent"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"p"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u670D\u52A1\u5546":"service"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"s"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u7EDF\u8BA1":"stats"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\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 Qk({onResult:e,initialSessionSearch:o=!1}){let[i,a]=Xe.useState(null);if(Xe.useEffect(()=>{Ak(45).then(a)},[]),!i)return H.jsxDEV(B,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this);return H.jsxDEV(m9,{clients:i.clients,defaultIdx:i.defaultIdx,hasProviders:i.hasProviders,pickCounts:i.pickCounts,initialSessionSearch:o,onResult:e},void 0,!1,void 0,this)}var Xe,H,A9="0.3.52",Ik,Bk;var wk=_(async()=>{Rn();Gc();Oc();wi();Tn();lg();uk();Ey();vI();bI();await Ba([si(),mk()]);Xe=Be(pt(),1),H=Be(An(),1);Ik={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},grok:{icon:"\u2736",color:"white"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},Bk={icon:"\u25AA",color:"white"}});function vk({provider:e,focused:o,bound:i,isDefault:a,zh:s}){let u=jr[e.type]||jr.custom,d=s?ji[e.type]?.zh:ji[e.type]?.en;return fe.jsxDEV(U,{flexDirection:"column",borderStyle:o?"bold":"round",borderColor:o?u.color:i?u.color:"gray",paddingX:2,paddingY:0,children:[fe.jsxDEV(U,{justifyContent:"space-between",children:[fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:o||i,color:o?u.color:void 0,children:e.name},void 0,!1,void 0,this),a&&fe.jsxDEV(B,{color:"yellow",children:["\u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this),e.builtin&&fe.jsxDEV(B,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(U,{gap:1,children:i?fe.jsxDEV(B,{color:u.color,bold:!0,children:["\u25CF ",s?"\u5DF2\u7ED1\u5B9A":"bound"]},void 0,!0,void 0,this):fe.jsxDEV(B,{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(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:d},void 0,!1,void 0,this),e.model&&fe.jsxDEV(B,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.model&&fe.jsxDEV(B,{dimColor:!0,children:e.model},void 0,!1,void 0,this),e.email&&fe.jsxDEV(B,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.email&&fe.jsxDEV(B,{dimColor:!0,children:e.email},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(B,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(B,{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(U,{marginTop:0,children:fe.jsxDEV(B,{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 Sk({screen:e,addType:o,addKey:i,addUrl:a,addModel:s,addCtx:u,rowIdx:d,zh:p}){let f=jr[o]||jr.custom,m=p?ji[o]?.zh:ji[o]?.en,h=e==="add-model"?zf(o):void 0;if(h)return fe.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(U,{borderStyle:"bold",borderColor:f.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,marginBottom:1,children:[fe.jsxDEV(B,{color:f.color,bold:!0,children:f.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:!0,color:f.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(B,{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(U,{paddingLeft:1,gap:1,children:[fe.jsxDEV(B,{color:L?f.color:void 0,bold:L,children:L?"\u25B8":" "},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:L,color:L?f.color:void 0,children:v},void 0,!1,void 0,this)]},v,!0,void 0,this)})]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:p?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:p?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(B,{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"?Fc(o)||(p?"\u7559\u7A7A\u4F7F\u7528\u9ED8\u8BA4":"leave empty"):void 0,b=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(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(U,{borderStyle:"bold",borderColor:f.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,marginBottom:1,children:[fe.jsxDEV(B,{color:f.color,bold:!0,children:f.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:!0,color:f.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:["\u2014 ",Q]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e==="add-key"&&o==="xiaomi"&&fe.jsxDEV(B,{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(B,{dimColor:!0,children:[" ",p?"\u9ED8\u8BA4":"Default",": ",w]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:w?1:0,children:[fe.jsxDEV(B,{color:f.color,bold:!0,children:["\u203A"," "]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:C||w||""},void 0,!1,void 0,this),fe.jsxDEV(B,{color:f.color,children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:b},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(B,{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 xk({provider:e,defaultId:o,detailActions:i,detailIdx:a,zh:s}){let u=jr[e.type]||jr.custom,d=s?ji[e.type]?.zh:ji[e.type]?.en;return fe.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(U,{borderStyle:"bold",borderColor:u.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:!0,color:u.color,children:e.name},void 0,!1,void 0,this),e.id===o&&fe.jsxDEV(B,{color:"yellow",children:[" \u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:[s?"\u7C7B\u578B":"Type",":"]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:d},void 0,!1,void 0,this),e.builtin&&fe.jsxDEV(B,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.model&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:[s?"\u6A21\u578B":"Model",":"]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:e.model},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.type!=="claude-subscription"&&e.type!=="codex-subscription"&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:[s?"\u5B50\u4EE3\u7406":"Subagent",":"]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:e.subagentModel===ii?s?"Claude Code \u9ED8\u8BA4":"CC default":e.subagentModel?e.subagentModel:s?"\u8DDF\u968F\u4E3B\u6A21\u578B":"follow main"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.email&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:"Email:"},void 0,!1,void 0,this),fe.jsxDEV(B,{children:e.email},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.apiKey&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:"Key:"},void 0,!1,void 0,this),fe.jsxDEV(B,{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(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:"URL:"},void 0,!1,void 0,this),fe.jsxDEV(B,{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(U,{gap:1,marginTop:1,children:i.map((p,f)=>{let m=p==="default"?`\u2B50 ${s?"\u8BBE\u4E3A\u9ED8\u8BA4":"Set Default"}`:p==="rekey"?`\uD83D\uDD11 ${s?"\u4FEE\u6539 Key":"Change Key"}`:p==="submodel"?`\uD83E\uDDE9 ${s?"\u5B50\u4EE3\u7406\u6A21\u578B":"Subagent Model"}`: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=f===a;return fe.jsxDEV(U,{borderStyle:h?"bold":"round",borderColor:h?"cyan":"gray",paddingX:2,children:fe.jsxDEV(B,{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(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:s?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:s?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(B,{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,jr,hy,Md;var bk=_(async()=>{Es();await si();fe=Be(An(),1),jr={"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"}},hy={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},grok:{icon:"\u2736",color:"white"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},Md=["claude-subscription","codex-subscription","tako","anthropic","deepseek","xiaomi","custom"]});function Nk({onDone:e}){let[o,i]=qt.useState("list"),[a,s]=qt.useState([]),[u,d]=qt.useState(),[p,f]=qt.useState({}),[m,h]=qt.useState(0),[Q,C]=qt.useState(0),[w,b]=qt.useState(0),[v,S]=qt.useState(""),[L,J]=qt.useState(""),[j,oe]=qt.useState("tako"),[de,pe]=qt.useState(""),[Ee,Ce]=qt.useState(""),[se,Ie]=qt.useState(""),[ve,ye]=qt.useState(""),[gt,Nt]=qt.useState(""),z=Ao()==="zh",Qe=dA(),Te=Qe[m],ze=hy[Te?.id]?.color||"white",xe=Te?a.filter((X)=>Lc(X,Te.id)):[],ne=p[Te?.id]||u,_e=xe.length+4,Re=a.find((X)=>X.id===v),tt=Re?.type==="claude-subscription"||Re?.type==="codex-subscription",vt=Re?[...Re.id!==u?["default"]:[],...tt?["relogin"]:[],...!tt?["submodel"]:[],...Re.builtin?["rekey"]:["delete"],"back"]:["back"],ut=qt.useCallback(async()=>{let X=await Uo(),re=await Qi();s(X),d(re?.id);let ee={};for(let ue of dA()){let Oe=await hs(ue.id);ee[ue.id]=Oe?.id}f(ee)},[]);qt.useEffect(()=>{ut()},[ut]),qt.useEffect(()=>{C(0)},[m]),qt.useEffect(()=>{if(L){let X=setTimeout(()=>J(""),3000);return()=>clearTimeout(X)}},[L]);let Ct=qt.useCallback(async()=>{if(v&&a.find((lt)=>lt.id===v)?.builtin){await Vi(v,{apiKey:de}),J(z?"Key \u5DF2\u66F4\u65B0":"Key updated"),await ut(),i("list"),C(0);return}let X=ji[j]?.[z?"zh":"en"]||j,re=Ee||dx(j),ee=se||Fc(j),ue=ve?parseInt(ve,10):NaN,Oe=Number.isFinite(ue)&&ue>0?ue:void 0;await Vu({name:X,type:j,apiKey:de,baseUrl:re,model:ee,modelContextWindow:Oe,supportedClients:Di(j)}),Jn("provider_added",{provider_type:j,method:"manual"}),wa(),Yi(),J(z?"\u5DF2\u6DFB\u52A0":"Added"),ye(""),await ut(),i("list"),C(0)},[j,de,Ee,se,ve,z,ut,v,a]),Yt=qt.useCallback(async()=>{i("scanning");let X=await Yf(),re=await Wf(X);if(re>0)wa(),Yi();J(z?`\u626B\u63CF\u5B8C\u6210\uFF0C\u65B0\u589E ${re} \u4E2A`:`Scan done, ${re} added`),await ut(),i("list"),C(0)},[ut,z]),[Wt,je]=qt.useState("claude"),ot=qt.useCallback(async(X)=>{je(X),i("logging-in");let re=X==="claude"?["claude","auth","login","--claudeai"]:["codex","login"];await Bun.spawn(re,{stdin:"inherit",stdout:"pipe",stderr:"pipe"}).exited;await Promise.resolve().then(() => lg());if(X==="claude")try{let Oe=Bun.spawn(["claude","auth","status"],{stdout:"pipe",stderr:"pipe"}),lt=await new Response(Oe.stdout).text();await Oe.exited;let Rt=JSON.parse(lt.trim());if(Rt.loggedIn&&Rt.authMethod==="claude.ai"){let ke=Rt.email||"",yt=Rt.subscriptionType||"pro",Ot=`Claude ${yt.charAt(0).toUpperCase()+yt.slice(1)}${ke?` (${ke})`:""}`;await Promise.resolve().then(() => Kf());let Ut=await ju(),Ge=Ut.credentials||Ut.oauthAccount?{credentials:Ut.credentials,oauthAccount:Ut.oauthAccount}:void 0,jt=a.find((Ko)=>Ko.type==="claude-subscription"&&Ko.email===ke);if(!jt)await Vu({name:Ot,type:"claude-subscription",email:ke,subscriptionType:yt,supportedClients:Di("claude-subscription"),authData:Ge}),J(z?"Claude \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Claude subscription added");else await Vi(jt.id,{authData:Ge}),Wh(jt.id,"claude-subscription"),J(z?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else J(z?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{J(z?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}else try{let Oe=await import("fs/promises"),{homedir:lt}=await import("os"),{join:Rt}=await import("path"),ke=JSON.parse(await Oe.readFile(Rt(lt(),".codex","auth.json"),"utf-8"));if(ke.auth_mode==="chatgpt"&&ke.tokens?.access_token){let yt="";try{yt=JSON.parse(atob(ke.tokens.id_token.split(".")[1])).email||""}catch{}let Ot=a.find((Xt)=>Xt.type==="codex-subscription"&&Xt.email===yt);if(!Ot)await Vu({name:yt?`Codex Plus (${yt})`:"Codex Subscription",type:"codex-subscription",email:yt||void 0,supportedClients:Di("codex-subscription"),authData:ke}),J(z?"Codex \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Codex subscription added");else await Vi(Ot.id,{authData:ke}),Wh(Ot.id,"codex-subscription"),J(z?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else J(z?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{J(z?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}await ut(),i("list"),C(0)},[a,z,ut]);if(Hn(qt.useCallback((X,re)=>{if(o==="list"){if(re.escape||X==="q"){e();return}if(re.leftArrow){h((ue)=>ue>0?ue-1:Qe.length-1);return}if(re.rightArrow){h((ue)=>ue<Qe.length-1?ue+1:0);return}let ee=parseInt(X);if(ee>=1&&ee<=Qe.length){h(ee-1);return}if(re.upArrow){C((ue)=>ue>0?ue-1:_e-1);return}if(re.downArrow){C((ue)=>ue<_e-1?ue+1:0);return}if(re.return){if(Q<xe.length){let ue=xe[Q];Jf(Te.id,ue.id).then(()=>{e()})}else if(Q===xe.length)i("add-type"),C(0);else if(Q===xe.length+1)Yt();else if(Q===xe.length+2)e("client-versions");else e();return}if((X==="d"||X==="e")&&Q<xe.length)S(xe[Q].id),i("detail"),b(0);return}if(o==="detail"){if(re.leftArrow){b((ee)=>ee>0?ee-1:vt.length-1);return}if(re.rightArrow){b((ee)=>ee<vt.length-1?ee+1:0);return}if(re.escape){i("list"),C(0);return}if(re.return){let ee=vt[w];if(ee==="back"){i("list"),C(0);return}if(ee==="default")Qx(v).then(()=>{J(z?"\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4":"Set as default"),ut(),i("list"),C(0)});if(ee==="delete")Dx(v).then(()=>{J(z?"\u5DF2\u5220\u9664":"Deleted"),ut(),i("list"),C(0)});if(ee==="rekey")oe(Re?.type||"tako"),pe(""),i("add-key"),C(0);if(ee==="submodel"){let ue=Re?.subagentModel;C(ue===ii?1:ue?2:0),Nt(ue&&ue!==ii?ue:""),i("submodel")}if(ee==="relogin"){let ue=Re?.type==="codex-subscription"?"codex":"claude";i("list"),C(0),ot(ue)}}return}if(o==="submodel"){if(re.escape){i("detail"),b(0);return}if(re.upArrow){C((ee)=>ee>0?ee-1:2);return}if(re.downArrow){C((ee)=>ee<2?ee+1:0);return}if(re.return){let ee=(ue)=>{J(ue),ut(),i("detail"),b(0)};if(Q===0)Vi(v,{subagentModel:void 0}).then(()=>ee(z?"\u5B50\u4EE3\u7406\u6A21\u578B\uFF1A\u8DDF\u968F\u4E3B\u6A21\u578B":"Subagent: follow main"));else if(Q===1)Vi(v,{subagentModel:ii}).then(()=>ee(z?"\u5B50\u4EE3\u7406\u6A21\u578B\uFF1AClaude Code \u9ED8\u8BA4":"Subagent: CC default"));else i("submodel-custom");return}return}if(o==="submodel-custom"){if(re.escape){i("submodel");return}if(re.return){let ee=gt.trim();Vi(v,{subagentModel:ee||void 0}).then(()=>{J(ee?z?`\u5B50\u4EE3\u7406\u6A21\u578B\uFF1A${ee}`:`Subagent: ${ee}`:z?"\u5B50\u4EE3\u7406\u6A21\u578B\uFF1A\u8DDF\u968F\u4E3B\u6A21\u578B":"Subagent: follow main"),ut(),i("detail"),b(0)});return}if(re.backspace||re.delete){Nt((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl)Nt((ee)=>ee+X);return}if(o==="add-type"){if(re.upArrow){C((ee)=>ee>0?ee-1:Md.length-1);return}if(re.downArrow){C((ee)=>ee<Md.length-1?ee+1:0);return}if(re.escape){i("list"),C(0);return}if(re.return){let ee=Md[Q];if(oe(ee),ee==="claude-subscription"){ot("claude");return}if(ee==="codex-subscription"){ot("codex");return}pe(""),Ce(""),Ie(Fc(ee)||""),i("add-key"),C(0)}return}if(o==="add-key"){if(re.escape){i("list"),C(0);return}if(re.return&&de){if(j==="custom")i("add-url");else if(j==="deepseek"||j==="anthropic"||j==="tako"||j==="xiaomi")i("add-model"),C(0);else Ct();return}if(re.backspace||re.delete){pe((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl)pe((ee)=>ee+X);return}if(o==="add-url"){if(re.escape){i("list"),C(0);return}if(re.return){i("add-model"),C(0);return}if(re.backspace||re.delete){Ce((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl)Ce((ee)=>ee+X);return}if(o==="add-model"){let ee=zf(j);if(re.escape){i("list"),C(0);return}if(ee){if(re.upArrow){C((ue)=>ue>0?ue-1:ee.length-1);return}if(re.downArrow){C((ue)=>ue<ee.length-1?ue+1:0);return}if(re.return){Ie(ee[Q]),setTimeout(()=>Ct(),0);return}}else{if(re.return){let ue=se.trim();if(ue&&ni.some((Oe)=>Oe.id===ue))Ct();else i("add-ctx");return}if(re.backspace||re.delete){Ie((ue)=>ue.slice(0,-1));return}if(X&&!re.ctrl)Ie((ue)=>ue+X)}return}if(o==="add-ctx"){if(re.escape){i("list"),C(0);return}if(re.return){Ct();return}if(re.backspace||re.delete){ye((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl&&/^[0-9]$/.test(X))ye((ee)=>ee+X);return}},[o,Q,w,xe,_e,Qe.length,Te,v,Re,vt,j,de,Ee,se,ve,gt,e,Yt,ot,Ct,ut,z])),o==="scanning"||o==="logging-in"){let X=o==="logging-in"?jr[Wt==="claude"?"claude-subscription":"codex-subscription"]:{icon:"\u23F3",color:"yellow"},re=o==="scanning"?z?"\u6B63\u5728\u626B\u63CF\u672C\u5730\u8BA2\u9605...":"Scanning local subscriptions...":z?"\u6B63\u5728\u767B\u5F55\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u6388\u6743...":"Logging in, please authorize in browser...";return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:ge.jsxDEV(U,{borderStyle:"round",borderColor:X.color,paddingX:3,paddingY:1,flexDirection:"column",alignItems:"center",children:[ge.jsxDEV(B,{color:X.color,bold:!0,children:[X.icon," ",re]},void 0,!0,void 0,this),o==="logging-in"&&ge.jsxDEV(B,{dimColor:!0,children:z?"\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 ge.jsxDEV(Sk,{screen:o,addType:j,addKey:de,addUrl:Ee,addModel:se,addCtx:ve,rowIdx:Q,zh:z},void 0,!1,void 0,this);if(o==="add-type")return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:ge.jsxDEV(B,{bold:!0,children:["\u2795 ",z?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),ge.jsxDEV(U,{flexDirection:"column",marginTop:1,gap:0,children:Md.map((X,re)=>{let ee=jr[X]||jr.custom,ue=Q===re,Oe=z?ji[X]?.zh:ji[X]?.en,lt=X==="claude-subscription"||X==="codex-subscription";return ge.jsxDEV(U,{borderStyle:ue?"bold":"round",borderColor:ue?ee.color:"gray",paddingX:2,paddingY:0,children:ge.jsxDEV(U,{gap:1,children:[ge.jsxDEV(B,{color:ee.color,bold:!0,children:ee.icon},void 0,!1,void 0,this),ge.jsxDEV(B,{bold:ue,color:ue?ee.color:void 0,children:Oe},void 0,!1,void 0,this),lt&&ge.jsxDEV(B,{dimColor:!0,children:["(",z?"\u767B\u5F55\u6388\u6743":"login auth",")"]},void 0,!0,void 0,this),!lt&&ge.jsxDEV(B,{dimColor:!0,children:["(",z?"\u586B\u5199 Key":"enter key",")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},X,!1,void 0,this)})},void 0,!1,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u9009\u62E9":"select"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o==="submodel"&&Re){let X=Re.subagentModel,re=X===ii?1:X?2:0;return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"bold",borderColor:"cyan",paddingX:3,paddingY:1,flexDirection:"column",children:[ge.jsxDEV(U,{gap:1,marginBottom:1,children:[ge.jsxDEV(B,{bold:!0,color:"cyan",children:["\uD83E\uDDE9 ",z?"\u5B50\u4EE3\u7406\u6A21\u578B":"Subagent Model"]},void 0,!0,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2014 Claude Code"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),[{key:"follow",label:z?"\u8DDF\u968F\u4E3B\u6A21\u578B":"Follow main model",desc:z?"subagent / \u522B\u540D / utility \u5168\u90E8\u9501\u5B9A\u5230\u4E3B\u6A21\u578B\uFF08\u63A8\u8350\uFF09":"Pin subagent / alias / utility to main model (recommended)"},{key:"cc-default",label:z?"Claude Code \u9ED8\u8BA4":"Claude Code default",desc:z?"\u4E0D\u9501\u5B9A\uFF0C\u7531 Claude Code \u81EA\u5DF1\u89E3\u6790\uFF08settings.json / \u73AF\u5883\u53D8\u91CF\u53EF\u63A5\u7BA1\uFF09":"No pinning; Claude Code resolves on its own (settings.json / env can take over)"},{key:"custom",label:z?"\u6307\u5B9A\u6A21\u578B\u2026":"Custom model\u2026",desc:z?"\u9501\u5B9A\u5230\u4F60\u586B\u5199\u7684\u6A21\u578B ID\uFF08\u5982\u4E3B\u6A21\u578B\u4FBF\u5B9C + subagent \u5F3A\u529B\uFF09":"Pin to a model ID you enter (e.g. cheap main + strong subagent)"}].map((ue,Oe)=>{let lt=Q===Oe;return ge.jsxDEV(U,{flexDirection:"column",paddingLeft:1,children:[ge.jsxDEV(U,{gap:1,children:[ge.jsxDEV(B,{color:lt?"cyan":void 0,bold:lt,children:lt?"\u25B8":" "},void 0,!1,void 0,this),ge.jsxDEV(B,{bold:lt,color:lt?"cyan":void 0,children:[ue.label,Oe===re?z?"\uFF08\u5F53\u524D\uFF09":" (current)":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),lt&&ge.jsxDEV(B,{dimColor:!0,children:[" ",ue.desc]},void 0,!0,void 0,this)]},ue.key,!0,void 0,this)}),re===2&&ge.jsxDEV(U,{marginTop:1,children:ge.jsxDEV(B,{dimColor:!0,children:[z?"\u5F53\u524D\u6307\u5B9A":"Current",": ",X]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u9009\u62E9":"select"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}if(o==="submodel-custom"&&Re)return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"bold",borderColor:"cyan",paddingX:3,paddingY:1,flexDirection:"column",children:[ge.jsxDEV(U,{gap:1,marginBottom:1,children:[ge.jsxDEV(B,{bold:!0,color:"cyan",children:["\uD83E\uDDE9 ",z?"\u6307\u5B9A\u5B50\u4EE3\u7406\u6A21\u578B":"Custom Subagent Model"]},void 0,!0,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2014 Claude Code"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:[" ",z?"\u8F93\u5165\u6A21\u578B ID\uFF1B\u7559\u7A7A\u4FDD\u5B58 = \u6062\u590D\u8DDF\u968F\u4E3B\u6A21\u578B":"Enter a model ID; save empty = follow main model"]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,children:[ge.jsxDEV(B,{color:"cyan",bold:!0,children:["\u203A"," "]},void 0,!0,void 0,this),ge.jsxDEV(B,{children:gt},void 0,!1,void 0,this),ge.jsxDEV(B,{color:"cyan",children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u4FDD\u5B58":"save"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o==="detail"&&Re)return ge.jsxDEV(xk,{provider:Re,defaultId:u,detailActions:vt,detailIdx:w,zh:z},void 0,!1,void 0,this);return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:[ge.jsxDEV(B,{bold:!0,children:["\u26A1 ",z?"\u7BA1\u7406\u670D\u52A1\u5546":"Manage Providers"]},void 0,!0,void 0,this),L&&ge.jsxDEV(B,{color:"green",children:[" \u2713 ",L]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,gap:1,justifyContent:"center",children:[ge.jsxDEV(B,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),Qe.map((X,re)=>{let ee=hy[X.id]||{icon:"\u25AA",color:"white"},ue=re===m;return ge.jsxDEV(U,{borderStyle:ue?"bold":"single",borderColor:ue?ee.color:"gray",paddingX:2,children:ge.jsxDEV(B,{color:ue?ee.color:void 0,bold:ue,dimColor:!ue,children:[ee.icon," ",X.name]},void 0,!0,void 0,this)},X.id,!1,void 0,this)}),ge.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:ze,paddingX:1,paddingY:1,children:[xe.length===0&&ge.jsxDEV(U,{paddingX:2,paddingY:1,justifyContent:"center",children:ge.jsxDEV(B,{dimColor:!0,children:z?"\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),xe.map((X,re)=>ge.jsxDEV(vk,{provider:X,focused:Q===re,bound:X.id===ne,isDefault:X.id===u,zh:z},X.id,!1,void 0,this))]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,gap:1,children:[{id:"add",offset:0,icon:"\u2795",label:z?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"},{id:"scan",offset:1,icon:"\uD83D\uDD0D",label:z?"\u626B\u63CF\u8BA2\u9605":"Scan"},{id:"versions",offset:2,icon:"\uD83D\uDCE6",label:z?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"},{id:"back",offset:3,icon:"\u2190",label:z?"\u8FD4\u56DE":"Back"}].map((X)=>{let re=Q===xe.length+X.offset;return ge.jsxDEV(U,{borderStyle:re?"bold":"round",borderColor:re?"cyan":"gray",paddingX:2,children:ge.jsxDEV(B,{bold:re,color:re?"cyan":void 0,dimColor:!re,children:[X.icon," ",X.label]},void 0,!0,void 0,this)},X.id,!1,void 0,this)})},void 0,!1,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u9009\u62E9":"select"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u7ED1\u5B9A":"bind"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"d"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8BE6\u60C5":"detail"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var qt,ge;var Rk=_(async()=>{Tn();wi();Pc();Es();Es();Ou();Tr();await Ba([si(),bk()]);qt=Be(pt(),1),ge=Be(An(),1)});async function Tk(){try{let o=((await nt()).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 Kc(o.apiKey);if(!i.valid)return{success:!1,error:i.message};let a=i.apiId,u=await(await fetch(`${Zn}/apiStats/api/user-stats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiId:a})})).json(),p=await(await fetch(`${Zn}/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:qi(u,"\u83B7\u53D6\u7EDF\u8BA1\u5931\u8D25")};let f=(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:f}}}catch(e){return{success:!1,error:e instanceof Error?e.message:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}}}function kk(e){return e.toLocaleString("en-US")}var Fk=_(()=>{Kt();Ag()});function Lk({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 Tk();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]),Hn((m,h)=>{if(m==="q"||h.escape)e()});let f=Ao()==="zh";return Po.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[Po.jsxDEV(B,{bold:!0,children:Se("stats.title")},void 0,!1,void 0,this),a&&!o?Po.jsxDEV(B,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this):o?Po.jsxDEV(U,{flexDirection:"column",marginTop:1,children:[Po.jsxDEV(B,{children:Se("stats.totalRequests",{count:kk(o.totalRequests)})},void 0,!1,void 0,this),Po.jsxDEV(B,{children:Se("stats.totalCost",{cost:o.totalCost})},void 0,!1,void 0,this),Po.jsxDEV(B,{children:Se("stats.todayCost",{cost:o.todayCost})},void 0,!1,void 0,this),o.modelStats.length>0&&Po.jsxDEV(U,{flexDirection:"column",marginTop:1,children:[Po.jsxDEV(B,{bold:!0,dimColor:!0,children:f?"\u6A21\u578B\u5206\u5E03":"Model Distribution"},void 0,!1,void 0,this),o.modelStats.map((m,h)=>Po.jsxDEV(B,{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):Po.jsxDEV(B,{color:"red",children:f?"\u83B7\u53D6\u5931\u8D25":"Failed to load"},void 0,!1,void 0,this),Po.jsxDEV(U,{marginTop:1,children:Po.jsxDEV(B,{dimColor:!0,children:f?`${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,Po;var Mk=_(async()=>{Tn();Fk();await si();Ta=Be(pt(),1),Po=Be(An(),1)});function E9(e){return e.startsWith("cr_")&&e.length>10}async function C9(e){try{let i=await(await fetch(`${Zn}/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:qi(i,Se("auth.validationFailed"))}}catch(o){return{valid:!1,error:o instanceof Error?o.message:Se("auth.networkError")}}}async function _k(e){if(!E9(e))return Jn("api_key_validated",{success:!1,error_type:"invalid_format"}),{success:!1,error:Se("auth.invalidFormat")};let o=await C9(e);if(!o.valid)return Jn("api_key_validated",{success:!1,error_type:"api_validation_failed"}),{success:!1,error:o.error};return await ku({apiKey:e,apiId:o.apiId}),await h9(e,o.apiId),Jn("api_key_validated",{success:!0}),wa(),Yi(),{success:!0}}async function h9(e,o){let a=(await Uo()).find((s)=>s.type==="tako");if(a)await Vi(a.id,{apiKey:e,apiId:o});else await Vu({name:"Tako \u5B98\u65B9",type:"tako",apiKey:e,baseUrl:Zn,apiId:o,supportedClients:Di("tako"),builtin:!0})}var Ok=_(()=>{Kt();Tn();Tr();wi();Es()});function Uk({isReconfigure:e,onDone:o}){let[i,a]=bs.useState(""),[s,u]=bs.useState("idle"),[d,p]=bs.useState(""),{stdin:f,setRawMode:m}=vl();bs.useEffect(()=>{if(!f)return;m(!0);let w=(b)=>{let v=b.toString();if(v.length>1&&!v.startsWith("\x1B"))a((S)=>S+v.replace(/[\r\n]/g,""))};return f.on("data",w),()=>{f.off("data",w)}},[f,m]);let h=bs.useCallback(async()=>{if(!i||s==="validating")return;u("validating");let w=await _k(i);if(w.success)u("success"),wa(),Yi(),setTimeout(()=>o(!0),500);else u("error"),p(w.error||"Validation failed")},[i,s,o]);Hn((w,b)=>{if(b.escape){o(!1);return}if(b.return){h();return}if(b.backspace||b.delete){a((v)=>v.slice(0,-1)),u("idle");return}if(w&&!b.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 Ni.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[Ni.jsxDEV(B,{bold:!0,color:"cyan",children:["\uD83D\uDD11 ",e?Se("prompts.enterApiKey"):"API Key"]},void 0,!0,void 0,this),Ni.jsxDEV(U,{marginTop:1,children:[Ni.jsxDEV(B,{color:"cyan",bold:!0,children:[">"," "]},void 0,!0,void 0,this),Ni.jsxDEV(B,{children:Q},void 0,!1,void 0,this),s==="idle"&&Ni.jsxDEV(B,{color:"cyan",children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s==="validating"&&Ni.jsxDEV(B,{color:"yellow",children:["\u23F3 ",Se("prompts.validating")]},void 0,!0,void 0,this),s==="success"&&Ni.jsxDEV(B,{color:"green",children:["\u2713 ",Se("prompts.keyConfigured")]},void 0,!0,void 0,this),s==="error"&&Ni.jsxDEV(B,{color:"red",children:["\u2717 ",d]},void 0,!0,void 0,this),Ni.jsxDEV(U,{marginTop:1,children:Ni.jsxDEV(B,{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 bs,Ni;var Gk=_(async()=>{Tn();Ok();Tr();await si();bs=Be(pt(),1),Ni=Be(An(),1)});function Pk({onDone:e}){let[o,i]=Hk.useState(_d.findIndex((a)=>a.value===Ao()));return Hn((a,s)=>{if(s.upArrow)i((u)=>u>0?u-1:_d.length-1);if(s.downArrow)i((u)=>u<_d.length-1?u+1:0);if(s.return)FS(_d[o].value),e();if(s.escape)e()}),ka.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[ka.jsxDEV(B,{bold:!0,children:["\uD83C\uDF10 ",Se("menu.changeLanguage")]},void 0,!0,void 0,this),_d.map((a,s)=>ka.jsxDEV(U,{gap:1,marginTop:s===0?1:0,children:[ka.jsxDEV(B,{color:"cyan",bold:s===o,children:s===o?"\u25B8":" "},void 0,!1,void 0,this),ka.jsxDEV(B,{bold:s===o,children:a.label},void 0,!1,void 0,this),a.value===Ao()&&ka.jsxDEV(B,{dimColor:!0,children:"\u2190"},void 0,!1,void 0,this)]},a.value,!0,void 0,this)),ka.jsxDEV(U,{marginTop:1,children:ka.jsxDEV(B,{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 Hk,ka,_d;var zk=_(async()=>{Tn();await si();Hk=Be(pt(),1),ka=Be(An(),1),_d=[{value:"en",label:"English"},{value:"zh",label:"\u4E2D\u6587"}]});import{join as I9}from"path";async function B9(){try{return await Bun.file(Jk).json()}catch{return{}}}async function Kk(e){await Bun.write(Jk,JSON.stringify(e))}async function Yk(){if(await cS())return!1;let e=await B9();if(e.never)return!1;let o=new Date().toISOString().slice(0,10);if(e.dismissed===o)return!1;return!0}async function Wk(e){if(e==="never")await Kk({never:!0});else{let o=new Date().toISOString().slice(0,10);await Kk({dismissed:o})}}function jk({onDone:e}){let[o,i]=Vm.useState(0),a=Ao()==="zh";return Hn(Vm.useCallback((s,u)=>{if(u.upArrow){i((d)=>d>0?d-1:jm.length-1);return}if(u.downArrow){i((d)=>d<jm.length-1?d+1:0);return}if(u.escape){e("skip");return}if(u.return){e(jm[o].id);return}},[o,e])),yn.jsxDEV(U,{flexDirection:"column",paddingX:0,paddingY:1,children:[yn.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[yn.jsxDEV(U,{gap:1,children:[yn.jsxDEV(B,{color:"cyan",bold:!0,children:"\uD83D\uDD11"},void 0,!1,void 0,this),yn.jsxDEV(B,{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),yn.jsxDEV(U,{marginTop:1,flexDirection:"column",children:[yn.jsxDEV(B,{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),yn.jsxDEV(B,{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),yn.jsxDEV(U,{marginTop:1,flexDirection:"column",children:jm.map((s,u)=>{let d=u===o;return yn.jsxDEV(U,{paddingLeft:1,gap:1,children:[yn.jsxDEV(B,{color:d?s.color||"white":void 0,bold:d,children:d?"\u25B8":" "},void 0,!1,void 0,this),yn.jsxDEV(B,{bold:d,color:d?s.color||"white":void 0,children:a?s.label.zh:s.label.en},void 0,!1,void 0,this),d&&yn.jsxDEV(B,{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),yn.jsxDEV(U,{paddingX:2,marginTop:1,justifyContent:"center",gap:2,children:[yn.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:a?"\u9009\u62E9":"select"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:a?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),yn.jsxDEV(B,{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 Vm,yn,Jk,jm;var Vk=_(async()=>{Kt();Kt();Tn();await si();Vm=Be(pt(),1),yn=Be(An(),1),Jk=I9(Ft,".key-prompt.json");jm=[{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 Xk({onDone:e}){let o=dA(),i=Ao()==="zh",[a,s]=zo.useState(0),[u,d]=zo.useState(0),[p,f]=zo.useState(0),[m,h]=zo.useState({}),[Q,C]=zo.useState(null),[w,b]=zo.useState(""),v=o[a],S=zo.useCallback(async(pe)=>{h((Ce)=>({...Ce,[pe]:{loading:!0,versions:[],current:null}}));let Ee=o.find((Ce)=>Ce.id===pe);if(!Ee)return;try{if(Ee.install==="system"){let ve=await QA(Ee);h((ye)=>({...ye,[pe]:{loading:!1,versions:ve?[{version:ve,isCurrent:!0}]:[],current:ve}}));return}let[Ce,se]=await Promise.all([pg(Ee.package),QA(Ee)]),Ie=Ce.map((ve)=>({...ve,isCurrent:ve.version===se}));h((ve)=>({...ve,[pe]:{loading:!1,versions:Ie,current:se}}))}catch(Ce){h((se)=>({...se,[pe]:{loading:!1,error:Ce.message,versions:[],current:null}}))}},[o]);zo.useEffect(()=>{if(!v)return;if(!m[v.id])S(v.id)},[a,v?.id]),zo.useEffect(()=>{d(0),f(0)},[a]),zo.useEffect(()=>{if(!w)return;let pe=setTimeout(()=>b(""),3000);return()=>clearTimeout(pe)},[w]);let L=v?m[v.id]:void 0,J=L?.versions??[],j=zo.useCallback(async(pe)=>{if(!v||Q)return;C(pe);try{await Yc(v,pe),b(i?`\u2713 \u5DF2\u5207\u6362\u5230 ${pe}`:`\u2713 Switched to ${pe}`),await S(v.id)}catch(Ee){b(i?`\u2717 \u5B89\u88C5\u5931\u8D25\uFF1A${Ee.message}`:`\u2717 Install failed: ${Ee.message}`)}finally{C(null)}},[v,Q,S,i]);Hn((pe,Ee)=>{if(Q)return;if(Ee.escape||pe==="q"){e();return}if(Ee.leftArrow){s((se)=>se>0?se-1:o.length-1);return}if(Ee.rightArrow){s((se)=>se<o.length-1?se+1:0);return}if(pe==="r"){if(v)S(v.id);return}if(!J.length)return;let Ce=J.length-1;if(Ee.upArrow){d((se)=>{let Ie=Math.max(0,se-1);if(Ie<p)f(Ie);return Ie});return}if(Ee.downArrow){d((se)=>{let Ie=Math.min(Ce,se+1);if(Ie>=p+Iy)f(Ie-Iy+1);return Ie});return}if(Ee.return){let se=J[u];if(se&&!se.isCurrent)j(se.version)}});let oe=qk[v?.id]?.color||"white",de=J.slice(p,p+Iy);return bt.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[bt.jsxDEV(U,{borderStyle:"round",borderColor:"gray",paddingX:3,children:[bt.jsxDEV(B,{bold:!0,children:["\uD83D\uDCE6 ",i?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"]},void 0,!0,void 0,this),w&&bt.jsxDEV(B,{color:w.startsWith("\u2713")?"green":"red",children:[" ",w]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),bt.jsxDEV(U,{marginTop:1,gap:1,justifyContent:"center",children:o.map((pe,Ee)=>{let Ce=qk[pe.id]||{icon:"\u25AA",color:"white"},se=Ee===a;return bt.jsxDEV(U,{borderStyle:se?"bold":"single",borderColor:se?Ce.color:"gray",paddingX:2,children:bt.jsxDEV(B,{bold:se,color:se?Ce.color:void 0,dimColor:!se,children:[Ce.icon," ",pe.name]},void 0,!0,void 0,this)},pe.id,!1,void 0,this)})},void 0,!1,void 0,this),bt.jsxDEV(U,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:oe,paddingX:2,paddingY:1,children:!L||L.loading?bt.jsxDEV(B,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"Loading..."},void 0,!1,void 0,this):L.error?bt.jsxDEV(B,{color:"red",children:[i?"\u52A0\u8F7D\u5931\u8D25\uFF1A":"Failed: ",L.error]},void 0,!0,void 0,this):J.length===0?bt.jsxDEV(B,{dimColor:!0,children:i?"\u6682\u65E0\u7248\u672C":"No versions"},void 0,!1,void 0,this):bt.jsxDEV(U,{flexDirection:"column",children:[bt.jsxDEV(B,{dimColor:!0,children:[i?`\u5171 ${J.length} \u4E2A\u7248\u672C\uFF0C\u5F53\u524D\u5B89\u88C5\uFF1A`:`${J.length} versions, current: `,bt.jsxDEV(B,{color:oe,children:L.current??(i?"\u672A\u5B89\u88C5":"not installed")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),bt.jsxDEV(U,{marginTop:1,flexDirection:"column",children:de.map((pe,Ee)=>{let se=p+Ee===u,Ie=pe.publishedAt?pe.publishedAt.slice(0,10):"",ve=pe.isCurrent?i?" \u2605 \u5F53\u524D":" \u2605 current":"",ye=Q===pe.version,gt=se?oe:pe.isCurrent?"green":void 0;return bt.jsxDEV(U,{paddingLeft:1,children:bt.jsxDEV(B,{color:gt,bold:se,dimColor:!se&&!pe.isCurrent,children:[se?"\u25B6 ":" ",pe.version.padEnd(16),Ie.padEnd(14),ve,ye?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),bt.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u9009\u62E9":"select"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u5B89\u88C5":"install"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),bt.jsxDEV(B,{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 zo,bt,Iy=12,qk;var $k=_(async()=>{Pc();Zh();Tn();await si();zo=Be(pt(),1),bt=Be(An(),1),qk={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},grok:{icon:"\u2736",color:"white"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}}});function y9(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 tF({sid:e,onBack:o}){let i=Ji()==="zh",[a,s]=uo.useState(null),[u,d]=uo.useState([]),[p,f]=uo.useState(""),[m,h]=uo.useState("idle"),[Q,C]=uo.useState(null),[w,b]=uo.useState([]),v=uo.useRef(0),S=uo.useCallback(async()=>{let oe=await ol(e,eF);if(!oe)return;s(oe.meta),d(oe.log);try{let de=await import("fs/promises"),pe=await de.stat(eo(e));v.current=pe.size}catch{v.current=0}},[e]);uo.useEffect(()=>{S()},[S]),uo.useEffect(()=>{let oe=!1,de=null,pe=async()=>{if(oe)return;try{let Ee=await import("fs/promises"),Ce=await Ee.stat(eo(e));if(Ce.size>v.current){let se=await Ee.open(eo(e),"r"),Ie=Buffer.alloc(Ce.size-v.current);await se.read(Ie,0,Ie.length,v.current),await se.close(),v.current=Ce.size;let ve=[];for(let ye of Ie.toString("utf-8").split(`
701
+ <%s key={someKey} {...props} />`,tt,Ct,Yt,Ct),xe[Ct+tt]=!0)}if(Ct=null,Re!==void 0&&(i(Re),Ct=""+Re),d(_e)&&(i(_e.key),Ct=""+_e.key),"key"in _e){Re={};for(var Wt in _e)Wt!=="key"&&(Re[Wt]=_e[Wt])}else Re=_e;return Ct&&p(Re,typeof ne==="function"?ne.displayName||ne.name||"Unknown":ne),m(ne,Ct,Re,s(),vt,ut)}function Q(ne){C(ne)?ne._store&&(ne._store.validated=1):typeof ne==="object"&&ne!==null&&ne.$$typeof===Ce&&(ne._payload.status==="fulfilled"?C(ne._payload.value)&&ne._payload.value._store&&(ne._payload.value._store.validated=1):ne._store&&(ne._store.validated=1))}function C(ne){return typeof ne==="object"&&ne!==null&&ne.$$typeof===w}var w=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),J=Symbol.for("react.consumer"),j=Symbol.for("react.context"),oe=Symbol.for("react.forward_ref"),de=Symbol.for("react.suspense"),pe=Symbol.for("react.suspense_list"),Ee=Symbol.for("react.memo"),Ce=Symbol.for("react.lazy"),se=Symbol.for("react.activity"),Ie=Symbol.for("react.client.reference"),ve=HA.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ye=Object.prototype.hasOwnProperty,gt=Array.isArray,Nt=console.createTask?console.createTask:function(){return null};HA={react_stack_bottom_frame:function(ne){return ne()}};var z,Qe={},Te=HA.react_stack_bottom_frame.bind(HA,u)(),ze=Nt(a(u)),xe={};r9.Fragment=v,r9.jsxDEV=function(ne,_e,Re,tt){var vt=1e4>ve.recentlyCreatedOwnerStacks++;return h(ne,_e,Re,tt,vt?Error("react-stack-top-frame"):Te,vt?Nt(a(ne)):ze)}})()});function pk({zh:e}){return at.jsxDEV(U,{marginTop:0,justifyContent:"center",gap:2,children:a9.flatMap((o,i)=>[i>0?at.jsxDEV(B,{dimColor:!0,children:"\u2502"},`s${i}`,!1,void 0,this):null,at.jsxDEV(B,{dimColor:!0,bold:!0,children:o[0]},`k${i}`,!1,void 0,this),at.jsxDEV(B,{dimColor:!0,children:e?o[1]:o[2]},`l${i}`,!1,void 0,this)])},void 0,!1,void 0,this)}function fk({provs:e,provIdx:o,pickerIdx:i,color:a,zh:s}){return at.jsxDEV(U,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:a,paddingX:1,paddingY:0,children:[at.jsxDEV(B,{bold:!0,color:a,children:["\u25A3 ",s?"\u9009\u62E9\u670D\u52A1\u5546":"Pick Provider"]},void 0,!0,void 0,this),at.jsxDEV(U,{flexDirection:"column",marginTop:0,children:[e.length===0&&at.jsxDEV(U,{paddingLeft:1,children:at.jsxDEV(B,{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,f=d===o;return at.jsxDEV(U,{paddingLeft:1,children:[at.jsxDEV(B,{color:p?a:void 0,bold:p,children:p?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:p,color:p?a:void 0,children:[" ",u.name]},void 0,!0,void 0,this),u.email&&at.jsxDEV(B,{dimColor:!0,children:[" (",u.email,")"]},void 0,!0,void 0,this),f&&at.jsxDEV(B,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},u.id,!0,void 0,this)}),(()=>{let u=i===e.length;return at.jsxDEV(U,{paddingLeft:1,marginTop:1,children:[at.jsxDEV(B,{color:u?a:void 0,bold:u,children:u?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{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),at.jsxDEV(pk,{zh:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function gk({group:e,options:o,enabled:i,pickerIdx:a,color:s,zh:u,pickCounts:d={},query:p=""}){let f=o.filter((v)=>v.group===e),m=e==="model",h=m?Ym(f,d,p,u):f,Q=m?dk(a,h.length):{start:0,end:h.length},C=h.slice(Q.start,Q.end),w=m?u?"\u9009\u62E9\u6A21\u578B":"Pick Model":e==="subagent-model"?u?"\u5B50\u4EE3\u7406\u6A21\u578B":"Subagent Model":e,b=!f.some((v)=>i.has(v.id));return at.jsxDEV(U,{flexDirection:"column",marginTop:0,borderStyle:"round",borderColor:s,paddingX:1,paddingY:0,children:[at.jsxDEV(B,{bold:!0,color:s,children:["\u25A3 ",w]},void 0,!0,void 0,this),m&&at.jsxDEV(U,{paddingLeft:1,children:[at.jsxDEV(B,{color:s,bold:!0,children:"\u203A "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:!!p,dimColor:!p,children:p||(u?"\u8F93\u5165\u5B57\u6BCD\u7B5B\u9009":"Type to filter")},void 0,!1,void 0,this),at.jsxDEV(B,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this),at.jsxDEV(U,{flexDirection:"column",marginTop:0,children:[!m&&(()=>{let v=a===0;return at.jsxDEV(U,{paddingLeft:1,children:[at.jsxDEV(B,{color:v?s:void 0,bold:v,children:v?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:v,color:v?s:void 0,children:[" ",u?"\u9ED8\u8BA4\uFF08\u4E0D\u6307\u5B9A\uFF09":"Default (none)"]},void 0,!0,void 0,this),b&&at.jsxDEV(B,{color:"green",children:" \u2605"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),C.map((v,S)=>{let L=Q.start+S,J=a===(m?L:L+1),j=i.has(v.id);return at.jsxDEV(U,{paddingLeft:1,flexDirection:"column",children:[at.jsxDEV(U,{children:[at.jsxDEV(B,{color:J?s:void 0,bold:J,children:J?"\u25B8":" "},void 0,!1,void 0,this),at.jsxDEV(B,{bold:J,color:J?s:void 0,children:[" ",v.label[u?"zh":"en"]||v.label.en]},void 0,!0,void 0,this),j&&at.jsxDEV(B,{color:"green",children:" \u2605"},void 0,!1,void 0,this),at.jsxDEV(B,{dimColor:!0,children:[" ",v.flag]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J&&at.jsxDEV(U,{paddingLeft:3,children:at.jsxDEV(B,{dimColor:!0,children:v.description[u?"zh":"en"]||v.description.en},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},v.id,!0,void 0,this)}),m&&h.length===0&&at.jsxDEV(U,{paddingLeft:1,children:at.jsxDEV(B,{dimColor:!0,children:u?"\u65E0\u5339\u914D\u6A21\u578B":"No matching models"},void 0,!1,void 0,this)},void 0,!1,void 0,this),m&&h.length>my&&at.jsxDEV(U,{paddingLeft:1,children:at.jsxDEV(B,{dimColor:!0,children:[a+1,"/",h.length]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),at.jsxDEV(pk,{zh:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var at,a9;var mk=_(async()=>{Ey();await si();at=Be(An(),1),a9=[["\u2191\u2193","\u9009\u62E9","select"],["Enter","\u786E\u8BA4","confirm"],["Esc","\u53D6\u6D88","cancel"]]});function Ck(e){let o=e.codePointAt(0);if(!o)return!1;return o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=191471||o>=63744&&o<=64255||o>=194560&&o<=195103||o>=44032&&o<=55215||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=65280&&o<=65519||o>=126976&&o<=131071||o>=9728&&o<=10175||o===11088}function s9(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Ek(e){let o=s9(e),i=0;for(let a of o)i+=Ck(a)?2:1;return i}function Wm(e,o,i="..."){if(Ek(e)<=o)return e;let s=Ek(i),u=o-s;if(u<=0)return i.slice(0,o);let d=0,p="";for(let f of e){let m=Ck(f)?2:1;if(d+m>u)break;p+=f,d+=m}return p+i}function Cy(e,o){if(!e||o.ctrl||o.meta)return"";return e.replace(/[\x00-\x1f\x7f]/g,"")}function hk(e,o){if(o.length>0)return new Set(o);return new Set(e.filter((i)=>i.defaultOn).map((i)=>i.id))}function yk(e){return e.replace(/```[\s\S]*?```/g," [code] ").replace(/[`*_#>|]/g,"").replace(/\s+/g," ").trim()}function u9(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 l9(e){if(e==="claude")return"Claude";if(e==="codex")return"Codex";if(e==="grok")return"Grok";if(e==="pi")return"Pi";return"Gemini"}function c9(e){if(e==="claude")return"magenta";if(e==="codex")return"blue";if(e==="grok")return"white";if(e==="pi")return"magenta";return"cyan"}function d9(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 Dk({color:e}){let{stdout:o}=zm(),i=Math.max((o.columns||80)-6,20);return H.jsxDEV(U,{marginY:0,children:H.jsxDEV(B,{dimColor:!0,color:e,children:"\u2500".repeat(i)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function p9(e){return e>30?"green":e>10?"yellow":"red"}function f9({provider:e,zh:o}){if(!e)return H.jsxDEV(B,{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(B,{color:a.color,children:[a.icon," ",s]},void 0,!0,void 0,this),u&&H.jsxDEV(B,{dimColor:!0,children:[" \xB7 ",u]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function g9({quota:e,zh:o}){if(e.status==="unsupported")return null;if(e.status==="error")return H.jsxDEV(B,{dimColor:!0,children:["\uD83D\uDCB0 ",qi(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 f=p.costUsed??0;return H.jsxDEV(B,{dimColor:!0,children:["\uD83D\uDCB0 ",o?"\u4ECA\u65E5":"Today",": ",H.jsxDEV(B,{color:"green",children:["$",f.toFixed(2)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}let i=(d,p,f)=>{if(d&&d>=1440)return`${Math.round(d/1440)}d`;if(d)return`${Math.round(d/60)}h`;return f?`${f}d`:`${p}h`},a=(d)=>Math.max(0,Math.min(100,100-Math.round(d))),s=[],u=(d,p,f)=>{if(s.length)s.push(H.jsxDEV(B,{dimColor:!0,children:" \xB7 "},`sep-${d}`,!1,void 0,this));let m=a(f);s.push(H.jsxDEV(Xe.default.Fragment,{children:[`${p} \u5269 `,H.jsxDEV(B,{color:p9(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(B,{dimColor:!0,children:["\uD83D\uDCB0 ",s]},void 0,!0,void 0,this)}function m9({clients:e,defaultIdx:o,hasProviders:i,pickCounts:a,initialSessionSearch:s=!1,onResult:u}){let{stdout:d}=zm(),[p,f]=Xe.useState(o),[m,h]=Xe.useState(s?"search":"projects"),[Q,C]=Xe.useState(0),[w,b]=Xe.useState(0),[v,S]=Xe.useState(()=>e[o]?.activeProvIdx||0),[L,J]=Xe.useState(()=>hk(e[o]?.launchOptions??[],e[o]?.lastSelectedOptionIds??[])),[j,oe]=Xe.useState(""),[de,pe]=Xe.useState(null),[Ee,Ce]=Xe.useState(""),[se,Ie]=Xe.useState(!1),[ve,ye]=Xe.useState(0),[gt,Nt]=Xe.useState(""),[z,Qe]=Xe.useState(""),[Te,ze]=Xe.useState(0),xe=Xe.useRef(0),[ne,_e]=Xe.useState(null),Re=Xe.useRef(null),[tt,vt]=Xe.useState(null),[ut,Ct]=Xe.useState(0),[Yt,Wt]=Xe.useState(!1),[je,ot]=Xe.useState(""),[X,re]=Xe.useState(null),[ee,ue]=Xe.useState(null),Oe=Math.max(2,Math.min((d.columns||80)<100?4:6,Math.floor(((d.rows||30)-12)/2))),[lt,Rt]=Xe.useState(Oe),ke=Xe.useRef(!0),yt=e[p],{projects:Ot,providers:Xt}=yt,Ut=Ik[yt.client.id]||Bk,Ge=Ao()==="zh",jt=Xt[v],Ko=Xe.default.useMemo(()=>tt?Lg(tt,z,{currentCwd:Ot[0]?.path,limit:lt+1}):[],[tt,z,ut,Ot,lt]),To=Ko.length>lt,Lt=Xe.default.useMemo(()=>Ko.slice(0,lt),[Ko,lt]),Jo=Math.max(0,Math.min(Te-Oe+1,Math.max(0,Lt.length-Oe))),or=Lt.slice(Jo,Jo+Oe);Xe.useEffect(()=>{let I=Mg(),N=!1;vt(I),Wt(!0),ot("");let P=id(I).then(()=>{if(!N)Ct((K)=>K+1)}).catch((K)=>{if(!N)ot(K instanceof Error?K.message:String(K))}).finally(()=>{if(!N)Wt(!1)});return()=>{N=!0,vt(null),P.finally(()=>I.close())}},[]),Xe.useEffect(()=>{if(!gt){Qe("");return}let I=setTimeout(()=>Qe(gt),120);return()=>clearTimeout(I)},[gt]),Xe.useEffect(()=>{Rt((I)=>Math.max(I,Oe)),ze((I)=>{let N=Math.max(0,Math.min(I,lt-1));return xe.current=N,N})},[Oe,lt]),Xe.useEffect(()=>{if(Lt.length===0){xe.current=0,Re.current=null,ze(0),_e(null);return}let I=Re.current?Lt.findIndex((K)=>K.session.key===Re.current):-1,N=I>=0?I:Math.min(xe.current,Lt.length-1),P=Lt[N].session.key;xe.current=N,Re.current=P,ze(N),_e(P)},[Lt]),Xe.useEffect(()=>{if(!tt||!X){ue(null);return}let I=tt.getSession(X),N=tt.getRecentMessages(X,32).filter((P)=>P.role==="user"||P.role==="assistant").slice(-8);ue(I?{session:I,messages:N}:null)},[tt,X]);let mn=Xe.default.useMemo(()=>Lu(yt.client,jt),[yt.client.id,jt?.id,jt?.type]),Sn=Xe.default.useMemo(()=>rk(mn,Ge),[mn,Ge]),no=jt?.name||(Ge?"\u672A\u914D\u7F6E":"N/A"),[nn,Yo]=Xe.useState(null);Xe.useEffect(()=>{if(!jt){Yo(null);return}let I=!1;return ug(jt).then((N)=>{if(!I)Yo(N)}),()=>{I=!0}},[jt?.id,jt?.type]),Xe.useEffect(()=>{if(ke.current){ke.current=!1;return}C(0),b(0),h("projects"),S(e[p]?.activeProvIdx||0),pe(null),Ce(""),Ie(!1),J(hk(e[p]?.launchOptions??[],e[p]?.lastSelectedOptionIds??[]))},[p]),Xe.useEffect(()=>{J((I)=>Jm(I,mn,jt?.model,yt.client.id==="pi"?`model-${IA}`:yt.client.id==="grok"?`model-${$u}`:void 0))},[mn,jt?.model]);let jn=Xe.useCallback((I)=>{if(mn.filter((P)=>P.group===I).length===0)return;Ce(""),ye(0),pe(I)},[mn]);return Hn(Xe.useCallback((I,N)=>{if(se){let K=Xt.length+1;if(N.escape||I==="q"){Ie(!1);return}if(N.upArrow){ye((Ae)=>Ae>0?Ae-1:K-1);return}if(N.downArrow){ye((Ae)=>Ae<K-1?Ae+1:0);return}if(N.return)if(ve<Xt.length){let Ae=Xt[ve];S(ve),(async()=>{if(await Jf(yt.client.id,Ae.id),yt.client.setupConfigFiles)try{await yt.client.setupConfigFiles(ri(Ae))}catch(De){oe(Ge?"\u26A0 \u914D\u7F6E\u540C\u6B65\u5931\u8D25":"\u26A0 Config sync failed"),setTimeout(()=>oe(""),2500);return}yt.activeProvIdx=ve,oe(Ge?`\u2713 \u5DF2\u7ED1\u5B9A ${Ae.name}`:`\u2713 Bound ${Ae.name}`),setTimeout(()=>oe(""),2000)})(),Ie(!1)}else Ie(!1),u({type:"providers"});return}if(de){let K=mn.filter((Ye)=>Ye.group===de),Ae=de==="model",De=Ae?Ym(K,a,Ee,Ge):K,Ue=Ae?De.length:De.length+1;if(N.escape||!Ae&&I==="q"){pe(null),Ce("");return}if(N.upArrow){if(Ue===0)return;ye((Ye)=>Ye>0?Ye-1:Ue-1);return}if(N.downArrow){if(Ue===0)return;ye((Ye)=>Ye<Ue-1?Ye+1:0);return}if(N.return){if(Ae){let Ye=De[ve];if(!Ye)return;J((Je)=>{let Gt=new Set(Je);for(let En of K)Gt.delete(En.id);return Gt.add(Ye.id),Gt})}else if(ve===0)J((Ye)=>{let Je=new Set(Ye);for(let Gt of K)Je.delete(Gt.id);return Je});else{let Ye=De[ve-1];J((Je)=>{let Gt=new Set(Je);for(let En of K)Gt.delete(En.id);return Gt.add(Ye.id),Gt})}pe(null),Ce("");return}if(Ae){if(N.backspace||N.delete){Ce((Je)=>Je.slice(0,-1)),ye(0);return}let Ye=Cy(I,N);if(Ye)Ce((Je)=>Je+Ye),ye(0)}return}if(m==="search"){if(X&&(N.escape||N.leftArrow)){re(null);return}if(N.escape||N.leftArrow){Nt(""),xe.current=0,Re.current=null,ze(0),_e(null),h("projects");return}if(N.rightArrow){let Ae=Lt.find((De)=>De.session.key===Re.current)??Lt[xe.current];if(Ae)re(Ae.session.key);return}if(N.downArrow){if(Lt.length===0)return;if(xe.current>=Lt.length-1&&To)Rt((Ae)=>Ae+Oe),xe.current+=1,ze(xe.current);else xe.current=Math.min(Lt.length-1,xe.current+1),ze(xe.current);Re.current=Lt[xe.current]?.session.key??null,_e(Re.current);return}if(N.upArrow){xe.current=Math.max(0,xe.current-1),ze(xe.current),Re.current=Lt[xe.current]?.session.key??null,_e(Re.current);return}if(N.backspace||N.delete){Nt((Ae)=>Ae.slice(0,-1)),xe.current=0,Re.current=null,ze(0),_e(null),re(null),Rt(Oe);return}if(N.return){let Ae=Lt.find((De)=>De.session.key===Re.current)??Lt[xe.current];if(!Ae)return;if(Ae.session.resumeCapability==="unsupported"){re(Ae.session.key);return}try{let De=xI(Ae.session,Ot[0]?.path);u({type:"launch",clientId:De.clientId,projectPath:De.projectPath,args:De.args,envVars:{},selectedOptionIds:[],resume:!0,resumeModelId:Ae.session.model})}catch(De){ot(De instanceof Error?De.message:String(De))}return}let K=Cy(I,N);if(K)Nt((Ae)=>Ae+K),xe.current=0,Re.current=null,ze(0),_e(null),re(null),Rt(Oe);return}if(I==="q"){u({type:"exit"});return}if(I==="a"){u({type:"agent"});return}if(I==="s"){u({type:"stats"});return}if(I==="c"){u({type:"config"});return}if(I==="l"){u({type:"language"});return}if(I==="p"){u({type:"providers"});return}if(I==="m"){jn("model");return}let P=parseInt(I);if(P>=1&&P<=e.length){f(P-1);return}if(N.leftArrow){f((K)=>K>0?K-1:e.length-1);return}if(N.rightArrow){f((K)=>K<e.length-1?K+1:0);return}if(m==="projects"){if(N.downArrow){if(Q<Ot.length-1)C((K)=>K+1);else if(Sn.length>0)h("options"),b(0);return}if(N.upArrow){if(Q>0)C((K)=>K-1);else xe.current=0,Re.current=Lt[0]?.session.key??null,ze(0),_e(Re.current),Rt(Oe),re(null),h("search");return}}if(m==="options"){if(N.downArrow){if(w<Sn.length-1)b((K)=>K+1);return}if(N.upArrow){if(w>0)b((K)=>K-1);else h("projects"),C(Ot.length-1);return}}if(I===" "&&m==="options"&&Sn.length>0){let K=Sn[w];if(K.kind==="flag")J((Ae)=>{let De=new Set(Ae);if(De.has(K.opt.id))De.delete(K.opt.id);else De.add(K.opt.id);return De});else if(K.kind==="group")jn(K.group);else ye(v),Ie(!0);return}if(N.return){if(m==="options"&&Sn.length>0){let De=Sn[w];if(De.kind==="group"){jn(De.group);return}if(De.kind==="provider"){ye(v),Ie(!0);return}}let K=Ot[Q],Ae=sk({launchOptions:mn,enabled:L});u({type:"launch",clientId:yt.client.id,projectPath:K.path,...Ae})}},[m,p,Q,w,v,Xt,jt,yt,Ot,mn,Sn,L,e,u,Ge,de,se,ve,a,Ee,jn,gt,Te,ne,Lt,X,lt,Oe,To])),H.jsxDEV(U,{flexDirection:"column",paddingX:0,paddingY:0,children:[H.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:m==="search"?"cyan":Ut.color,paddingX:1,paddingY:0,children:[H.jsxDEV(U,{justifyContent:"space-between",children:[H.jsxDEV(U,{gap:1,children:[H.jsxDEV(B,{bold:!0,children:"\uD83D\uDC19 Tako"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:["v",A9]},void 0,!0,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(f9,{provider:jt,zh:Ge},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(U,{children:[j&&H.jsxDEV(B,{color:"green",children:j},void 0,!1,void 0,this),!j&&nn&&H.jsxDEV(g9,{quota:nn,zh:Ge},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!i&&H.jsxDEV(U,{marginTop:1,justifyContent:"center",gap:1,children:[H.jsxDEV(B,{color:"yellow",children:"\u26A0"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\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(U,{marginTop:1,gap:1,justifyContent:"center",children:[H.jsxDEV(B,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),e.map((I,N)=>{let P=Ik[I.client.id]||Bk;return N===p?H.jsxDEV(U,{borderStyle:"bold",borderColor:P.color,paddingX:1,children:H.jsxDEV(B,{color:P.color,bold:!0,children:[P.icon," ",I.client.name]},void 0,!0,void 0,this)},I.client.id,!1,void 0,this):H.jsxDEV(U,{borderStyle:"single",borderColor:"gray",paddingX:1,children:H.jsxDEV(B,{dimColor:!0,children:[P.icon," ",I.client.name]},void 0,!0,void 0,this)},I.client.id,!1,void 0,this)}),H.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m!=="search"&&H.jsxDEV(Dk,{color:Ut.color},void 0,!1,void 0,this),se?H.jsxDEV(fk,{provs:Xt,provIdx:v,pickerIdx:ve,color:Ut.color,zh:Ge},void 0,!1,void 0,this):de?H.jsxDEV(gk,{group:de,options:mn,enabled:L,pickerIdx:ve,color:Ut.color,zh:Ge,pickCounts:a,query:Ee},void 0,!1,void 0,this):H.jsxDEV(H.Fragment,{children:[m==="search"?H.jsxDEV(U,{borderStyle:"round",borderColor:"cyan",paddingX:1,flexDirection:"column",marginTop:1,marginBottom:1,children:[H.jsxDEV(U,{justifyContent:"space-between",children:[H.jsxDEV(B,{color:"cyan",bold:!0,children:["\u2315 ",Ge?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD":"Search sessions"]},void 0,!0,void 0,this),Yt&&H.jsxDEV(B,{dimColor:!0,children:Ge?"\u7D22\u5F15\u4E2D...":"indexing..."},void 0,!1,void 0,this),!Yt&&je&&H.jsxDEV(B,{color:"red",children:["\u26A0 ",Wm(je,Math.max(16,(d.columns||80)-48))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(U,{children:[H.jsxDEV(B,{color:"cyan",bold:!0,children:"\u203A "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:!!gt,dimColor:!gt,children:gt||(Ge?"\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(B,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(B,{children:" \u2315 "},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u641C\u7D22\u5386\u53F2\u4F1A\u8BDD...":"Search previous sessions..."},void 0,!1,void 0,this),Yt&&H.jsxDEV(B,{dimColor:!0,children:[" ",Ge?"\u7D22\u5F15\u4E2D":"indexing"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X&&ee?H.jsxDEV(U,{paddingLeft:2,flexDirection:"column",children:[H.jsxDEV(B,{bold:!0,color:"cyan",children:ee.session.title??X},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:ee.session.cwd},void 0,!1,void 0,this),ee.session.resumeCapability==="unsupported"&&H.jsxDEV(B,{color:"yellow",children:Ge?"\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),ee.messages.map((I)=>H.jsxDEV(B,{children:[H.jsxDEV(B,{color:I.role==="user"?"yellow":"green",children:[I.role==="user"?"You":"AI",": "]},void 0,!0,void 0,this),I.text.replace(/\s+/g," ").slice(0,Math.max(40,(d.columns||80)-12))]},I.ordinal,!0,void 0,this))]},void 0,!0,void 0,this):m==="search"?or.map((I,N)=>{let K=Jo+N===Te,Ae=c9(I.session.source),De=d9(I.session.updatedAt,Ge),Ue=Math.max(30,(d.columns||80)-14);return H.jsxDEV(Xe.default.Fragment,{children:H.jsxDEV(U,{paddingLeft:1,flexDirection:"column",children:[H.jsxDEV(U,{children:[H.jsxDEV(B,{color:K?"cyan":void 0,bold:K,children:K?"\u25B8 ":" "},void 0,!1,void 0,this),H.jsxDEV(B,{color:"cyan",children:De},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:" \xB7 "},void 0,!1,void 0,this),H.jsxDEV(B,{color:Ae,bold:!0,children:l9(I.session.source)},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:[" \xB7 ",I.session.projectName??"\u672A\u77E5\u9879\u76EE"," \xB7 ",u9(I.session.updatedAt,Ge)," "]},void 0,!0,void 0,this),H.jsxDEV(B,{bold:K,color:K?"white":void 0,children:Wm(yk(I.session.title??I.session.nativeId.slice(0,8)),Math.max(12,Ue-36))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H.jsxDEV(B,{dimColor:!0,children:[" ",Wm(yk(I.snippet),Ue)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},I.session.key,!1,void 0,this)}).concat([H.jsxDEV(U,{paddingLeft:4,marginTop:1,children:H.jsxDEV(B,{dimColor:!0,children:[Lt.length===0?Ge?"\u6682\u65E0\u4F1A\u8BDD":"No sessions":`${Jo+1}-${Math.min(Jo+Oe,Lt.length)} / ${Lt.length}${To?"+":""}`,To?` \xB7 \u2193 ${Ge?"\u7EE7\u7EED\u6D4F\u89C8":"more"}`:""]},void 0,!0,void 0,this)},"session-window-status",!1,void 0,this)]):Ot.map((I,N)=>{let P=m==="projects"&&N===Q;return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:I.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I.hint?H.jsxDEV(B,{dimColor:!0,children:I.hint},void 0,!1,void 0,this):null]},N,!0,void 0,this)}),m!=="search"&&Sn.length>0&&H.jsxDEV(H.Fragment,{children:[H.jsxDEV(Dk,{color:Ut.color},void 0,!1,void 0,this),Sn.map((I,N)=>{let P=m==="options"&&N===w;if(I.kind==="flag"){let K=I.opt,Ae=L.has(K.id);return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{color:Ae?Ut.color:void 0,bold:Ae,children:Ae?"\u25C9":"\u25CB"},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:K.label[Ge?"zh":"en"]||K.label.en},void 0,!1,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:K.flag},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:K.description[Ge?"zh":"en"]||K.description.en},void 0,!1,void 0,this)]},K.id,!0,void 0,this)}if(I.kind==="group"){let K=ak(mn,L,I.group),Ae=K?K.shortLabel:Ge?"\u9ED8\u8BA4":"Default";return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:[I.title,":"]},void 0,!0,void 0,this),H.jsxDEV(B,{color:K?Ut.color:void 0,children:Ae},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:Ge?"Enter \u8FDB\u5165\u9009\u62E9":"Enter to pick"},void 0,!1,void 0,this)]},`group-${I.group}`,!0,void 0,this)}return H.jsxDEV(U,{paddingLeft:1,children:[H.jsxDEV(U,{flexGrow:1,gap:1,children:[H.jsxDEV(B,{color:P?Ut.color:void 0,bold:P,children:P?"\u25B8":" "},void 0,!1,void 0,this),H.jsxDEV(B,{bold:P,color:P?Ut.color:void 0,children:[I.title,":"]},void 0,!0,void 0,this),H.jsxDEV(B,{color:jt?Ut.color:"yellow",children:jt?no:Ge?"\u672A\u914D\u7F6E":"Not set"},void 0,!1,void 0,this),H.jsxDEV(B,{color:"yellow",children:"\u2605"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&H.jsxDEV(B,{dimColor:!0,children:Ge?"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(U,{paddingX:2,marginTop:0,justifyContent:"center",gap:2,children:m==="search"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Lt[Te]?.session.resumeCapability==="unsupported"?Ge?"\u67E5\u770B":"open":Ge?"\u7EED\u63A5":"resume"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2192"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u67E5\u770B":"details"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):m==="options"?H.jsxDEV(H.Fragment,{children:[H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Space"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u5F00\u5173":"toggle"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9000\u51FA":"quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):H.jsxDEV(H.Fragment,{children:[H.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u542F\u52A8":"launch"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"a"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"agent"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u9009\u62E9":"select"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"m"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u6A21\u578B":"model"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u5207\u6362\u5DE5\u5177":"switch tool"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"p"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u670D\u52A1\u5546":"service"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"s"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\u7EDF\u8BA1":"stats"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),H.jsxDEV(B,{dimColor:!0,children:Ge?"\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 Qk({onResult:e,initialSessionSearch:o=!1}){let[i,a]=Xe.useState(null);if(Xe.useEffect(()=>{Ak(45).then(a)},[]),!i)return H.jsxDEV(B,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this);return H.jsxDEV(m9,{clients:i.clients,defaultIdx:i.defaultIdx,hasProviders:i.hasProviders,pickCounts:i.pickCounts,initialSessionSearch:o,onResult:e},void 0,!1,void 0,this)}var Xe,H,A9="0.3.53",Ik,Bk;var wk=_(async()=>{Rn();Gc();Oc();wi();Tn();lg();uk();Ey();vI();bI();await Ba([si(),mk()]);Xe=Be(pt(),1),H=Be(An(),1);Ik={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},grok:{icon:"\u2736",color:"white"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},Bk={icon:"\u25AA",color:"white"}});function vk({provider:e,focused:o,bound:i,isDefault:a,zh:s}){let u=jr[e.type]||jr.custom,d=s?ji[e.type]?.zh:ji[e.type]?.en;return fe.jsxDEV(U,{flexDirection:"column",borderStyle:o?"bold":"round",borderColor:o?u.color:i?u.color:"gray",paddingX:2,paddingY:0,children:[fe.jsxDEV(U,{justifyContent:"space-between",children:[fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:o||i,color:o?u.color:void 0,children:e.name},void 0,!1,void 0,this),a&&fe.jsxDEV(B,{color:"yellow",children:["\u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this),e.builtin&&fe.jsxDEV(B,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(U,{gap:1,children:i?fe.jsxDEV(B,{color:u.color,bold:!0,children:["\u25CF ",s?"\u5DF2\u7ED1\u5B9A":"bound"]},void 0,!0,void 0,this):fe.jsxDEV(B,{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(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:d},void 0,!1,void 0,this),e.model&&fe.jsxDEV(B,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.model&&fe.jsxDEV(B,{dimColor:!0,children:e.model},void 0,!1,void 0,this),e.email&&fe.jsxDEV(B,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.email&&fe.jsxDEV(B,{dimColor:!0,children:e.email},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(B,{dimColor:!0,children:"\xB7"},void 0,!1,void 0,this),e.apiKey&&fe.jsxDEV(B,{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(U,{marginTop:0,children:fe.jsxDEV(B,{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 Sk({screen:e,addType:o,addKey:i,addUrl:a,addModel:s,addCtx:u,rowIdx:d,zh:p}){let f=jr[o]||jr.custom,m=p?ji[o]?.zh:ji[o]?.en,h=e==="add-model"?zf(o):void 0;if(h)return fe.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(U,{borderStyle:"bold",borderColor:f.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,marginBottom:1,children:[fe.jsxDEV(B,{color:f.color,bold:!0,children:f.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:!0,color:f.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(B,{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(U,{paddingLeft:1,gap:1,children:[fe.jsxDEV(B,{color:L?f.color:void 0,bold:L,children:L?"\u25B8":" "},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:L,color:L?f.color:void 0,children:v},void 0,!1,void 0,this)]},v,!0,void 0,this)})]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:p?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:p?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(B,{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"?Fc(o)||(p?"\u7559\u7A7A\u4F7F\u7528\u9ED8\u8BA4":"leave empty"):void 0,b=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(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(U,{borderStyle:"bold",borderColor:f.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,marginBottom:1,children:[fe.jsxDEV(B,{color:f.color,bold:!0,children:f.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:!0,color:f.color,children:m},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:["\u2014 ",Q]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e==="add-key"&&o==="xiaomi"&&fe.jsxDEV(B,{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(B,{dimColor:!0,children:[" ",p?"\u9ED8\u8BA4":"Default",": ",w]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:w?1:0,children:[fe.jsxDEV(B,{color:f.color,bold:!0,children:["\u203A"," "]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:C||w||""},void 0,!1,void 0,this),fe.jsxDEV(B,{color:f.color,children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:b},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(B,{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 xk({provider:e,defaultId:o,detailActions:i,detailIdx:a,zh:s}){let u=jr[e.type]||jr.custom,d=s?ji[e.type]?.zh:ji[e.type]?.en;return fe.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[fe.jsxDEV(U,{borderStyle:"bold",borderColor:u.color,paddingX:3,paddingY:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{color:u.color,bold:!0,children:u.icon},void 0,!1,void 0,this),fe.jsxDEV(B,{bold:!0,color:u.color,children:e.name},void 0,!1,void 0,this),e.id===o&&fe.jsxDEV(B,{color:"yellow",children:[" \u2605 ",s?"\u9ED8\u8BA4":"default"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),fe.jsxDEV(U,{marginTop:1,flexDirection:"column",children:[fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:[s?"\u7C7B\u578B":"Type",":"]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:d},void 0,!1,void 0,this),e.builtin&&fe.jsxDEV(B,{dimColor:!0,children:"[built-in]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.model&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:[s?"\u6A21\u578B":"Model",":"]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:e.model},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.type!=="claude-subscription"&&e.type!=="codex-subscription"&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:[s?"\u5B50\u4EE3\u7406":"Subagent",":"]},void 0,!0,void 0,this),fe.jsxDEV(B,{children:e.subagentModel===ii?s?"Claude Code \u9ED8\u8BA4":"CC default":e.subagentModel?e.subagentModel:s?"\u8DDF\u968F\u4E3B\u6A21\u578B":"follow main"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.email&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:"Email:"},void 0,!1,void 0,this),fe.jsxDEV(B,{children:e.email},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e.apiKey&&fe.jsxDEV(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:"Key:"},void 0,!1,void 0,this),fe.jsxDEV(B,{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(U,{gap:1,children:[fe.jsxDEV(B,{dimColor:!0,children:"URL:"},void 0,!1,void 0,this),fe.jsxDEV(B,{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(U,{gap:1,marginTop:1,children:i.map((p,f)=>{let m=p==="default"?`\u2B50 ${s?"\u8BBE\u4E3A\u9ED8\u8BA4":"Set Default"}`:p==="rekey"?`\uD83D\uDD11 ${s?"\u4FEE\u6539 Key":"Change Key"}`:p==="submodel"?`\uD83E\uDDE9 ${s?"\u5B50\u4EE3\u7406\u6A21\u578B":"Subagent Model"}`: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=f===a;return fe.jsxDEV(U,{borderStyle:h?"bold":"round",borderColor:h?"cyan":"gray",paddingX:2,children:fe.jsxDEV(B,{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(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:s?"\u9009\u62E9":"select"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:s?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),fe.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),fe.jsxDEV(B,{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,jr,hy,Md;var bk=_(async()=>{Es();await si();fe=Be(An(),1),jr={"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"}},hy={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},grok:{icon:"\u2736",color:"white"},gemini:{icon:"\u25C6",color:"cyan"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}},Md=["claude-subscription","codex-subscription","tako","anthropic","deepseek","xiaomi","custom"]});function Nk({onDone:e}){let[o,i]=qt.useState("list"),[a,s]=qt.useState([]),[u,d]=qt.useState(),[p,f]=qt.useState({}),[m,h]=qt.useState(0),[Q,C]=qt.useState(0),[w,b]=qt.useState(0),[v,S]=qt.useState(""),[L,J]=qt.useState(""),[j,oe]=qt.useState("tako"),[de,pe]=qt.useState(""),[Ee,Ce]=qt.useState(""),[se,Ie]=qt.useState(""),[ve,ye]=qt.useState(""),[gt,Nt]=qt.useState(""),z=Ao()==="zh",Qe=dA(),Te=Qe[m],ze=hy[Te?.id]?.color||"white",xe=Te?a.filter((X)=>Lc(X,Te.id)):[],ne=p[Te?.id]||u,_e=xe.length+4,Re=a.find((X)=>X.id===v),tt=Re?.type==="claude-subscription"||Re?.type==="codex-subscription",vt=Re?[...Re.id!==u?["default"]:[],...tt?["relogin"]:[],...!tt?["submodel"]:[],...Re.builtin?["rekey"]:["delete"],"back"]:["back"],ut=qt.useCallback(async()=>{let X=await Uo(),re=await Qi();s(X),d(re?.id);let ee={};for(let ue of dA()){let Oe=await hs(ue.id);ee[ue.id]=Oe?.id}f(ee)},[]);qt.useEffect(()=>{ut()},[ut]),qt.useEffect(()=>{C(0)},[m]),qt.useEffect(()=>{if(L){let X=setTimeout(()=>J(""),3000);return()=>clearTimeout(X)}},[L]);let Ct=qt.useCallback(async()=>{if(v&&a.find((lt)=>lt.id===v)?.builtin){await Vi(v,{apiKey:de}),J(z?"Key \u5DF2\u66F4\u65B0":"Key updated"),await ut(),i("list"),C(0);return}let X=ji[j]?.[z?"zh":"en"]||j,re=Ee||dx(j),ee=se||Fc(j),ue=ve?parseInt(ve,10):NaN,Oe=Number.isFinite(ue)&&ue>0?ue:void 0;await Vu({name:X,type:j,apiKey:de,baseUrl:re,model:ee,modelContextWindow:Oe,supportedClients:Di(j)}),Jn("provider_added",{provider_type:j,method:"manual"}),wa(),Yi(),J(z?"\u5DF2\u6DFB\u52A0":"Added"),ye(""),await ut(),i("list"),C(0)},[j,de,Ee,se,ve,z,ut,v,a]),Yt=qt.useCallback(async()=>{i("scanning");let X=await Yf(),re=await Wf(X);if(re>0)wa(),Yi();J(z?`\u626B\u63CF\u5B8C\u6210\uFF0C\u65B0\u589E ${re} \u4E2A`:`Scan done, ${re} added`),await ut(),i("list"),C(0)},[ut,z]),[Wt,je]=qt.useState("claude"),ot=qt.useCallback(async(X)=>{je(X),i("logging-in");let re=X==="claude"?["claude","auth","login","--claudeai"]:["codex","login"];await Bun.spawn(re,{stdin:"inherit",stdout:"pipe",stderr:"pipe"}).exited;await Promise.resolve().then(() => lg());if(X==="claude")try{let Oe=Bun.spawn(["claude","auth","status"],{stdout:"pipe",stderr:"pipe"}),lt=await new Response(Oe.stdout).text();await Oe.exited;let Rt=JSON.parse(lt.trim());if(Rt.loggedIn&&Rt.authMethod==="claude.ai"){let ke=Rt.email||"",yt=Rt.subscriptionType||"pro",Ot=`Claude ${yt.charAt(0).toUpperCase()+yt.slice(1)}${ke?` (${ke})`:""}`;await Promise.resolve().then(() => Kf());let Ut=await ju(),Ge=Ut.credentials||Ut.oauthAccount?{credentials:Ut.credentials,oauthAccount:Ut.oauthAccount}:void 0,jt=a.find((Ko)=>Ko.type==="claude-subscription"&&Ko.email===ke);if(!jt)await Vu({name:Ot,type:"claude-subscription",email:ke,subscriptionType:yt,supportedClients:Di("claude-subscription"),authData:Ge}),J(z?"Claude \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Claude subscription added");else await Vi(jt.id,{authData:Ge}),Wh(jt.id,"claude-subscription"),J(z?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else J(z?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{J(z?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}else try{let Oe=await import("fs/promises"),{homedir:lt}=await import("os"),{join:Rt}=await import("path"),ke=JSON.parse(await Oe.readFile(Rt(lt(),".codex","auth.json"),"utf-8"));if(ke.auth_mode==="chatgpt"&&ke.tokens?.access_token){let yt="";try{yt=JSON.parse(atob(ke.tokens.id_token.split(".")[1])).email||""}catch{}let Ot=a.find((Xt)=>Xt.type==="codex-subscription"&&Xt.email===yt);if(!Ot)await Vu({name:yt?`Codex Plus (${yt})`:"Codex Subscription",type:"codex-subscription",email:yt||void 0,supportedClients:Di("codex-subscription"),authData:ke}),J(z?"Codex \u8BA2\u9605\u5DF2\u6DFB\u52A0":"Codex subscription added");else await Vi(Ot.id,{authData:ke}),Wh(Ot.id,"codex-subscription"),J(z?"\u5DF2\u66F4\u65B0 tokens":"Tokens updated")}else J(z?"\u767B\u5F55\u5931\u8D25":"Login failed")}catch{J(z?"\u68C0\u6D4B\u5931\u8D25":"Detection failed")}await ut(),i("list"),C(0)},[a,z,ut]);if(Hn(qt.useCallback((X,re)=>{if(o==="list"){if(re.escape||X==="q"){e();return}if(re.leftArrow){h((ue)=>ue>0?ue-1:Qe.length-1);return}if(re.rightArrow){h((ue)=>ue<Qe.length-1?ue+1:0);return}let ee=parseInt(X);if(ee>=1&&ee<=Qe.length){h(ee-1);return}if(re.upArrow){C((ue)=>ue>0?ue-1:_e-1);return}if(re.downArrow){C((ue)=>ue<_e-1?ue+1:0);return}if(re.return){if(Q<xe.length){let ue=xe[Q];Jf(Te.id,ue.id).then(()=>{e()})}else if(Q===xe.length)i("add-type"),C(0);else if(Q===xe.length+1)Yt();else if(Q===xe.length+2)e("client-versions");else e();return}if((X==="d"||X==="e")&&Q<xe.length)S(xe[Q].id),i("detail"),b(0);return}if(o==="detail"){if(re.leftArrow){b((ee)=>ee>0?ee-1:vt.length-1);return}if(re.rightArrow){b((ee)=>ee<vt.length-1?ee+1:0);return}if(re.escape){i("list"),C(0);return}if(re.return){let ee=vt[w];if(ee==="back"){i("list"),C(0);return}if(ee==="default")Qx(v).then(()=>{J(z?"\u5DF2\u8BBE\u4E3A\u9ED8\u8BA4":"Set as default"),ut(),i("list"),C(0)});if(ee==="delete")Dx(v).then(()=>{J(z?"\u5DF2\u5220\u9664":"Deleted"),ut(),i("list"),C(0)});if(ee==="rekey")oe(Re?.type||"tako"),pe(""),i("add-key"),C(0);if(ee==="submodel"){let ue=Re?.subagentModel;C(ue===ii?1:ue?2:0),Nt(ue&&ue!==ii?ue:""),i("submodel")}if(ee==="relogin"){let ue=Re?.type==="codex-subscription"?"codex":"claude";i("list"),C(0),ot(ue)}}return}if(o==="submodel"){if(re.escape){i("detail"),b(0);return}if(re.upArrow){C((ee)=>ee>0?ee-1:2);return}if(re.downArrow){C((ee)=>ee<2?ee+1:0);return}if(re.return){let ee=(ue)=>{J(ue),ut(),i("detail"),b(0)};if(Q===0)Vi(v,{subagentModel:void 0}).then(()=>ee(z?"\u5B50\u4EE3\u7406\u6A21\u578B\uFF1A\u8DDF\u968F\u4E3B\u6A21\u578B":"Subagent: follow main"));else if(Q===1)Vi(v,{subagentModel:ii}).then(()=>ee(z?"\u5B50\u4EE3\u7406\u6A21\u578B\uFF1AClaude Code \u9ED8\u8BA4":"Subagent: CC default"));else i("submodel-custom");return}return}if(o==="submodel-custom"){if(re.escape){i("submodel");return}if(re.return){let ee=gt.trim();Vi(v,{subagentModel:ee||void 0}).then(()=>{J(ee?z?`\u5B50\u4EE3\u7406\u6A21\u578B\uFF1A${ee}`:`Subagent: ${ee}`:z?"\u5B50\u4EE3\u7406\u6A21\u578B\uFF1A\u8DDF\u968F\u4E3B\u6A21\u578B":"Subagent: follow main"),ut(),i("detail"),b(0)});return}if(re.backspace||re.delete){Nt((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl)Nt((ee)=>ee+X);return}if(o==="add-type"){if(re.upArrow){C((ee)=>ee>0?ee-1:Md.length-1);return}if(re.downArrow){C((ee)=>ee<Md.length-1?ee+1:0);return}if(re.escape){i("list"),C(0);return}if(re.return){let ee=Md[Q];if(oe(ee),ee==="claude-subscription"){ot("claude");return}if(ee==="codex-subscription"){ot("codex");return}pe(""),Ce(""),Ie(Fc(ee)||""),i("add-key"),C(0)}return}if(o==="add-key"){if(re.escape){i("list"),C(0);return}if(re.return&&de){if(j==="custom")i("add-url");else if(j==="deepseek"||j==="anthropic"||j==="tako"||j==="xiaomi")i("add-model"),C(0);else Ct();return}if(re.backspace||re.delete){pe((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl)pe((ee)=>ee+X);return}if(o==="add-url"){if(re.escape){i("list"),C(0);return}if(re.return){i("add-model"),C(0);return}if(re.backspace||re.delete){Ce((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl)Ce((ee)=>ee+X);return}if(o==="add-model"){let ee=zf(j);if(re.escape){i("list"),C(0);return}if(ee){if(re.upArrow){C((ue)=>ue>0?ue-1:ee.length-1);return}if(re.downArrow){C((ue)=>ue<ee.length-1?ue+1:0);return}if(re.return){Ie(ee[Q]),setTimeout(()=>Ct(),0);return}}else{if(re.return){let ue=se.trim();if(ue&&ni.some((Oe)=>Oe.id===ue))Ct();else i("add-ctx");return}if(re.backspace||re.delete){Ie((ue)=>ue.slice(0,-1));return}if(X&&!re.ctrl)Ie((ue)=>ue+X)}return}if(o==="add-ctx"){if(re.escape){i("list"),C(0);return}if(re.return){Ct();return}if(re.backspace||re.delete){ye((ee)=>ee.slice(0,-1));return}if(X&&!re.ctrl&&/^[0-9]$/.test(X))ye((ee)=>ee+X);return}},[o,Q,w,xe,_e,Qe.length,Te,v,Re,vt,j,de,Ee,se,ve,gt,e,Yt,ot,Ct,ut,z])),o==="scanning"||o==="logging-in"){let X=o==="logging-in"?jr[Wt==="claude"?"claude-subscription":"codex-subscription"]:{icon:"\u23F3",color:"yellow"},re=o==="scanning"?z?"\u6B63\u5728\u626B\u63CF\u672C\u5730\u8BA2\u9605...":"Scanning local subscriptions...":z?"\u6B63\u5728\u767B\u5F55\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u6388\u6743...":"Logging in, please authorize in browser...";return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:ge.jsxDEV(U,{borderStyle:"round",borderColor:X.color,paddingX:3,paddingY:1,flexDirection:"column",alignItems:"center",children:[ge.jsxDEV(B,{color:X.color,bold:!0,children:[X.icon," ",re]},void 0,!0,void 0,this),o==="logging-in"&&ge.jsxDEV(B,{dimColor:!0,children:z?"\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 ge.jsxDEV(Sk,{screen:o,addType:j,addKey:de,addUrl:Ee,addModel:se,addCtx:ve,rowIdx:Q,zh:z},void 0,!1,void 0,this);if(o==="add-type")return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:ge.jsxDEV(B,{bold:!0,children:["\u2795 ",z?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),ge.jsxDEV(U,{flexDirection:"column",marginTop:1,gap:0,children:Md.map((X,re)=>{let ee=jr[X]||jr.custom,ue=Q===re,Oe=z?ji[X]?.zh:ji[X]?.en,lt=X==="claude-subscription"||X==="codex-subscription";return ge.jsxDEV(U,{borderStyle:ue?"bold":"round",borderColor:ue?ee.color:"gray",paddingX:2,paddingY:0,children:ge.jsxDEV(U,{gap:1,children:[ge.jsxDEV(B,{color:ee.color,bold:!0,children:ee.icon},void 0,!1,void 0,this),ge.jsxDEV(B,{bold:ue,color:ue?ee.color:void 0,children:Oe},void 0,!1,void 0,this),lt&&ge.jsxDEV(B,{dimColor:!0,children:["(",z?"\u767B\u5F55\u6388\u6743":"login auth",")"]},void 0,!0,void 0,this),!lt&&ge.jsxDEV(B,{dimColor:!0,children:["(",z?"\u586B\u5199 Key":"enter key",")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},X,!1,void 0,this)})},void 0,!1,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u9009\u62E9":"select"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o==="submodel"&&Re){let X=Re.subagentModel,re=X===ii?1:X?2:0;return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"bold",borderColor:"cyan",paddingX:3,paddingY:1,flexDirection:"column",children:[ge.jsxDEV(U,{gap:1,marginBottom:1,children:[ge.jsxDEV(B,{bold:!0,color:"cyan",children:["\uD83E\uDDE9 ",z?"\u5B50\u4EE3\u7406\u6A21\u578B":"Subagent Model"]},void 0,!0,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2014 Claude Code"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),[{key:"follow",label:z?"\u8DDF\u968F\u4E3B\u6A21\u578B":"Follow main model",desc:z?"subagent / \u522B\u540D / utility \u5168\u90E8\u9501\u5B9A\u5230\u4E3B\u6A21\u578B\uFF08\u63A8\u8350\uFF09":"Pin subagent / alias / utility to main model (recommended)"},{key:"cc-default",label:z?"Claude Code \u9ED8\u8BA4":"Claude Code default",desc:z?"\u4E0D\u9501\u5B9A\uFF0C\u7531 Claude Code \u81EA\u5DF1\u89E3\u6790\uFF08settings.json / \u73AF\u5883\u53D8\u91CF\u53EF\u63A5\u7BA1\uFF09":"No pinning; Claude Code resolves on its own (settings.json / env can take over)"},{key:"custom",label:z?"\u6307\u5B9A\u6A21\u578B\u2026":"Custom model\u2026",desc:z?"\u9501\u5B9A\u5230\u4F60\u586B\u5199\u7684\u6A21\u578B ID\uFF08\u5982\u4E3B\u6A21\u578B\u4FBF\u5B9C + subagent \u5F3A\u529B\uFF09":"Pin to a model ID you enter (e.g. cheap main + strong subagent)"}].map((ue,Oe)=>{let lt=Q===Oe;return ge.jsxDEV(U,{flexDirection:"column",paddingLeft:1,children:[ge.jsxDEV(U,{gap:1,children:[ge.jsxDEV(B,{color:lt?"cyan":void 0,bold:lt,children:lt?"\u25B8":" "},void 0,!1,void 0,this),ge.jsxDEV(B,{bold:lt,color:lt?"cyan":void 0,children:[ue.label,Oe===re?z?"\uFF08\u5F53\u524D\uFF09":" (current)":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),lt&&ge.jsxDEV(B,{dimColor:!0,children:[" ",ue.desc]},void 0,!0,void 0,this)]},ue.key,!0,void 0,this)}),re===2&&ge.jsxDEV(U,{marginTop:1,children:ge.jsxDEV(B,{dimColor:!0,children:[z?"\u5F53\u524D\u6307\u5B9A":"Current",": ",X]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u9009\u62E9":"select"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}if(o==="submodel-custom"&&Re)return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"bold",borderColor:"cyan",paddingX:3,paddingY:1,flexDirection:"column",children:[ge.jsxDEV(U,{gap:1,marginBottom:1,children:[ge.jsxDEV(B,{bold:!0,color:"cyan",children:["\uD83E\uDDE9 ",z?"\u6307\u5B9A\u5B50\u4EE3\u7406\u6A21\u578B":"Custom Subagent Model"]},void 0,!0,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2014 Claude Code"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:[" ",z?"\u8F93\u5165\u6A21\u578B ID\uFF1B\u7559\u7A7A\u4FDD\u5B58 = \u6062\u590D\u8DDF\u968F\u4E3B\u6A21\u578B":"Enter a model ID; save empty = follow main model"]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,children:[ge.jsxDEV(B,{color:"cyan",bold:!0,children:["\u203A"," "]},void 0,!0,void 0,this),ge.jsxDEV(B,{children:gt},void 0,!1,void 0,this),ge.jsxDEV(B,{color:"cyan",children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u4FDD\u5B58":"save"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(o==="detail"&&Re)return ge.jsxDEV(xk,{provider:Re,defaultId:u,detailActions:vt,detailIdx:w,zh:z},void 0,!1,void 0,this);return ge.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[ge.jsxDEV(U,{borderStyle:"round",borderColor:"gray",paddingX:3,paddingY:0,children:[ge.jsxDEV(B,{bold:!0,children:["\u26A1 ",z?"\u7BA1\u7406\u670D\u52A1\u5546":"Manage Providers"]},void 0,!0,void 0,this),L&&ge.jsxDEV(B,{color:"green",children:[" \u2713 ",L]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,gap:1,justifyContent:"center",children:[ge.jsxDEV(B,{dimColor:!0,children:"\u2039"},void 0,!1,void 0,this),Qe.map((X,re)=>{let ee=hy[X.id]||{icon:"\u25AA",color:"white"},ue=re===m;return ge.jsxDEV(U,{borderStyle:ue?"bold":"single",borderColor:ue?ee.color:"gray",paddingX:2,children:ge.jsxDEV(B,{color:ue?ee.color:void 0,bold:ue,dimColor:!ue,children:[ee.icon," ",X.name]},void 0,!0,void 0,this)},X.id,!1,void 0,this)}),ge.jsxDEV(B,{dimColor:!0,children:"\u203A"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ge.jsxDEV(U,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:ze,paddingX:1,paddingY:1,children:[xe.length===0&&ge.jsxDEV(U,{paddingX:2,paddingY:1,justifyContent:"center",children:ge.jsxDEV(B,{dimColor:!0,children:z?"\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),xe.map((X,re)=>ge.jsxDEV(vk,{provider:X,focused:Q===re,bound:X.id===ne,isDefault:X.id===u,zh:z},X.id,!1,void 0,this))]},void 0,!0,void 0,this),ge.jsxDEV(U,{marginTop:1,gap:1,children:[{id:"add",offset:0,icon:"\u2795",label:z?"\u6DFB\u52A0\u670D\u52A1\u5546":"Add Provider"},{id:"scan",offset:1,icon:"\uD83D\uDD0D",label:z?"\u626B\u63CF\u8BA2\u9605":"Scan"},{id:"versions",offset:2,icon:"\uD83D\uDCE6",label:z?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"},{id:"back",offset:3,icon:"\u2190",label:z?"\u8FD4\u56DE":"Back"}].map((X)=>{let re=Q===xe.length+X.offset;return ge.jsxDEV(U,{borderStyle:re?"bold":"round",borderColor:re?"cyan":"gray",paddingX:2,children:ge.jsxDEV(B,{bold:re,color:re?"cyan":void 0,dimColor:!re,children:[X.icon," ",X.label]},void 0,!0,void 0,this)},X.id,!1,void 0,this)})},void 0,!1,void 0,this),ge.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u9009\u62E9":"select"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u7ED1\u5B9A":"bind"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"d"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8BE6\u60C5":"detail"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),ge.jsxDEV(B,{dimColor:!0,children:z?"\u8FD4\u56DE":"back"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var qt,ge;var Rk=_(async()=>{Tn();wi();Pc();Es();Es();Ou();Tr();await Ba([si(),bk()]);qt=Be(pt(),1),ge=Be(An(),1)});async function Tk(){try{let o=((await nt()).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 Kc(o.apiKey);if(!i.valid)return{success:!1,error:i.message};let a=i.apiId,u=await(await fetch(`${Zn}/apiStats/api/user-stats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiId:a})})).json(),p=await(await fetch(`${Zn}/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:qi(u,"\u83B7\u53D6\u7EDF\u8BA1\u5931\u8D25")};let f=(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:f}}}catch(e){return{success:!1,error:e instanceof Error?e.message:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}}}function kk(e){return e.toLocaleString("en-US")}var Fk=_(()=>{Kt();Ag()});function Lk({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 Tk();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]),Hn((m,h)=>{if(m==="q"||h.escape)e()});let f=Ao()==="zh";return Po.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[Po.jsxDEV(B,{bold:!0,children:Se("stats.title")},void 0,!1,void 0,this),a&&!o?Po.jsxDEV(B,{dimColor:!0,children:"Loading..."},void 0,!1,void 0,this):o?Po.jsxDEV(U,{flexDirection:"column",marginTop:1,children:[Po.jsxDEV(B,{children:Se("stats.totalRequests",{count:kk(o.totalRequests)})},void 0,!1,void 0,this),Po.jsxDEV(B,{children:Se("stats.totalCost",{cost:o.totalCost})},void 0,!1,void 0,this),Po.jsxDEV(B,{children:Se("stats.todayCost",{cost:o.todayCost})},void 0,!1,void 0,this),o.modelStats.length>0&&Po.jsxDEV(U,{flexDirection:"column",marginTop:1,children:[Po.jsxDEV(B,{bold:!0,dimColor:!0,children:f?"\u6A21\u578B\u5206\u5E03":"Model Distribution"},void 0,!1,void 0,this),o.modelStats.map((m,h)=>Po.jsxDEV(B,{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):Po.jsxDEV(B,{color:"red",children:f?"\u83B7\u53D6\u5931\u8D25":"Failed to load"},void 0,!1,void 0,this),Po.jsxDEV(U,{marginTop:1,children:Po.jsxDEV(B,{dimColor:!0,children:f?`${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,Po;var Mk=_(async()=>{Tn();Fk();await si();Ta=Be(pt(),1),Po=Be(An(),1)});function E9(e){return e.startsWith("cr_")&&e.length>10}async function C9(e){try{let i=await(await fetch(`${Zn}/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:qi(i,Se("auth.validationFailed"))}}catch(o){return{valid:!1,error:o instanceof Error?o.message:Se("auth.networkError")}}}async function _k(e){if(!E9(e))return Jn("api_key_validated",{success:!1,error_type:"invalid_format"}),{success:!1,error:Se("auth.invalidFormat")};let o=await C9(e);if(!o.valid)return Jn("api_key_validated",{success:!1,error_type:"api_validation_failed"}),{success:!1,error:o.error};return await ku({apiKey:e,apiId:o.apiId}),await h9(e,o.apiId),Jn("api_key_validated",{success:!0}),wa(),Yi(),{success:!0}}async function h9(e,o){let a=(await Uo()).find((s)=>s.type==="tako");if(a)await Vi(a.id,{apiKey:e,apiId:o});else await Vu({name:"Tako \u5B98\u65B9",type:"tako",apiKey:e,baseUrl:Zn,apiId:o,supportedClients:Di("tako"),builtin:!0})}var Ok=_(()=>{Kt();Tn();Tr();wi();Es()});function Uk({isReconfigure:e,onDone:o}){let[i,a]=bs.useState(""),[s,u]=bs.useState("idle"),[d,p]=bs.useState(""),{stdin:f,setRawMode:m}=vl();bs.useEffect(()=>{if(!f)return;m(!0);let w=(b)=>{let v=b.toString();if(v.length>1&&!v.startsWith("\x1B"))a((S)=>S+v.replace(/[\r\n]/g,""))};return f.on("data",w),()=>{f.off("data",w)}},[f,m]);let h=bs.useCallback(async()=>{if(!i||s==="validating")return;u("validating");let w=await _k(i);if(w.success)u("success"),wa(),Yi(),setTimeout(()=>o(!0),500);else u("error"),p(w.error||"Validation failed")},[i,s,o]);Hn((w,b)=>{if(b.escape){o(!1);return}if(b.return){h();return}if(b.backspace||b.delete){a((v)=>v.slice(0,-1)),u("idle");return}if(w&&!b.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 Ni.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[Ni.jsxDEV(B,{bold:!0,color:"cyan",children:["\uD83D\uDD11 ",e?Se("prompts.enterApiKey"):"API Key"]},void 0,!0,void 0,this),Ni.jsxDEV(U,{marginTop:1,children:[Ni.jsxDEV(B,{color:"cyan",bold:!0,children:[">"," "]},void 0,!0,void 0,this),Ni.jsxDEV(B,{children:Q},void 0,!1,void 0,this),s==="idle"&&Ni.jsxDEV(B,{color:"cyan",children:"\u2588"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s==="validating"&&Ni.jsxDEV(B,{color:"yellow",children:["\u23F3 ",Se("prompts.validating")]},void 0,!0,void 0,this),s==="success"&&Ni.jsxDEV(B,{color:"green",children:["\u2713 ",Se("prompts.keyConfigured")]},void 0,!0,void 0,this),s==="error"&&Ni.jsxDEV(B,{color:"red",children:["\u2717 ",d]},void 0,!0,void 0,this),Ni.jsxDEV(U,{marginTop:1,children:Ni.jsxDEV(B,{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 bs,Ni;var Gk=_(async()=>{Tn();Ok();Tr();await si();bs=Be(pt(),1),Ni=Be(An(),1)});function Pk({onDone:e}){let[o,i]=Hk.useState(_d.findIndex((a)=>a.value===Ao()));return Hn((a,s)=>{if(s.upArrow)i((u)=>u>0?u-1:_d.length-1);if(s.downArrow)i((u)=>u<_d.length-1?u+1:0);if(s.return)FS(_d[o].value),e();if(s.escape)e()}),ka.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:[ka.jsxDEV(B,{bold:!0,children:["\uD83C\uDF10 ",Se("menu.changeLanguage")]},void 0,!0,void 0,this),_d.map((a,s)=>ka.jsxDEV(U,{gap:1,marginTop:s===0?1:0,children:[ka.jsxDEV(B,{color:"cyan",bold:s===o,children:s===o?"\u25B8":" "},void 0,!1,void 0,this),ka.jsxDEV(B,{bold:s===o,children:a.label},void 0,!1,void 0,this),a.value===Ao()&&ka.jsxDEV(B,{dimColor:!0,children:"\u2190"},void 0,!1,void 0,this)]},a.value,!0,void 0,this)),ka.jsxDEV(U,{marginTop:1,children:ka.jsxDEV(B,{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 Hk,ka,_d;var zk=_(async()=>{Tn();await si();Hk=Be(pt(),1),ka=Be(An(),1),_d=[{value:"en",label:"English"},{value:"zh",label:"\u4E2D\u6587"}]});import{join as I9}from"path";async function B9(){try{return await Bun.file(Jk).json()}catch{return{}}}async function Kk(e){await Bun.write(Jk,JSON.stringify(e))}async function Yk(){if(await cS())return!1;let e=await B9();if(e.never)return!1;let o=new Date().toISOString().slice(0,10);if(e.dismissed===o)return!1;return!0}async function Wk(e){if(e==="never")await Kk({never:!0});else{let o=new Date().toISOString().slice(0,10);await Kk({dismissed:o})}}function jk({onDone:e}){let[o,i]=Vm.useState(0),a=Ao()==="zh";return Hn(Vm.useCallback((s,u)=>{if(u.upArrow){i((d)=>d>0?d-1:jm.length-1);return}if(u.downArrow){i((d)=>d<jm.length-1?d+1:0);return}if(u.escape){e("skip");return}if(u.return){e(jm[o].id);return}},[o,e])),yn.jsxDEV(U,{flexDirection:"column",paddingX:0,paddingY:1,children:[yn.jsxDEV(U,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,children:[yn.jsxDEV(U,{gap:1,children:[yn.jsxDEV(B,{color:"cyan",bold:!0,children:"\uD83D\uDD11"},void 0,!1,void 0,this),yn.jsxDEV(B,{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),yn.jsxDEV(U,{marginTop:1,flexDirection:"column",children:[yn.jsxDEV(B,{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),yn.jsxDEV(B,{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),yn.jsxDEV(U,{marginTop:1,flexDirection:"column",children:jm.map((s,u)=>{let d=u===o;return yn.jsxDEV(U,{paddingLeft:1,gap:1,children:[yn.jsxDEV(B,{color:d?s.color||"white":void 0,bold:d,children:d?"\u25B8":" "},void 0,!1,void 0,this),yn.jsxDEV(B,{bold:d,color:d?s.color||"white":void 0,children:a?s.label.zh:s.label.en},void 0,!1,void 0,this),d&&yn.jsxDEV(B,{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),yn.jsxDEV(U,{paddingX:2,marginTop:1,justifyContent:"center",gap:2,children:[yn.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:a?"\u9009\u62E9":"select"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:a?"\u786E\u8BA4":"confirm"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),yn.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),yn.jsxDEV(B,{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 Vm,yn,Jk,jm;var Vk=_(async()=>{Kt();Kt();Tn();await si();Vm=Be(pt(),1),yn=Be(An(),1),Jk=I9(Ft,".key-prompt.json");jm=[{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 Xk({onDone:e}){let o=dA(),i=Ao()==="zh",[a,s]=zo.useState(0),[u,d]=zo.useState(0),[p,f]=zo.useState(0),[m,h]=zo.useState({}),[Q,C]=zo.useState(null),[w,b]=zo.useState(""),v=o[a],S=zo.useCallback(async(pe)=>{h((Ce)=>({...Ce,[pe]:{loading:!0,versions:[],current:null}}));let Ee=o.find((Ce)=>Ce.id===pe);if(!Ee)return;try{if(Ee.install==="system"){let ve=await QA(Ee);h((ye)=>({...ye,[pe]:{loading:!1,versions:ve?[{version:ve,isCurrent:!0}]:[],current:ve}}));return}let[Ce,se]=await Promise.all([pg(Ee.package),QA(Ee)]),Ie=Ce.map((ve)=>({...ve,isCurrent:ve.version===se}));h((ve)=>({...ve,[pe]:{loading:!1,versions:Ie,current:se}}))}catch(Ce){h((se)=>({...se,[pe]:{loading:!1,error:Ce.message,versions:[],current:null}}))}},[o]);zo.useEffect(()=>{if(!v)return;if(!m[v.id])S(v.id)},[a,v?.id]),zo.useEffect(()=>{d(0),f(0)},[a]),zo.useEffect(()=>{if(!w)return;let pe=setTimeout(()=>b(""),3000);return()=>clearTimeout(pe)},[w]);let L=v?m[v.id]:void 0,J=L?.versions??[],j=zo.useCallback(async(pe)=>{if(!v||Q)return;C(pe);try{await Yc(v,pe),b(i?`\u2713 \u5DF2\u5207\u6362\u5230 ${pe}`:`\u2713 Switched to ${pe}`),await S(v.id)}catch(Ee){b(i?`\u2717 \u5B89\u88C5\u5931\u8D25\uFF1A${Ee.message}`:`\u2717 Install failed: ${Ee.message}`)}finally{C(null)}},[v,Q,S,i]);Hn((pe,Ee)=>{if(Q)return;if(Ee.escape||pe==="q"){e();return}if(Ee.leftArrow){s((se)=>se>0?se-1:o.length-1);return}if(Ee.rightArrow){s((se)=>se<o.length-1?se+1:0);return}if(pe==="r"){if(v)S(v.id);return}if(!J.length)return;let Ce=J.length-1;if(Ee.upArrow){d((se)=>{let Ie=Math.max(0,se-1);if(Ie<p)f(Ie);return Ie});return}if(Ee.downArrow){d((se)=>{let Ie=Math.min(Ce,se+1);if(Ie>=p+Iy)f(Ie-Iy+1);return Ie});return}if(Ee.return){let se=J[u];if(se&&!se.isCurrent)j(se.version)}});let oe=qk[v?.id]?.color||"white",de=J.slice(p,p+Iy);return bt.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[bt.jsxDEV(U,{borderStyle:"round",borderColor:"gray",paddingX:3,children:[bt.jsxDEV(B,{bold:!0,children:["\uD83D\uDCE6 ",i?"\u5BA2\u6237\u7AEF\u7248\u672C\u7BA1\u7406":"Client Versions"]},void 0,!0,void 0,this),w&&bt.jsxDEV(B,{color:w.startsWith("\u2713")?"green":"red",children:[" ",w]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),bt.jsxDEV(U,{marginTop:1,gap:1,justifyContent:"center",children:o.map((pe,Ee)=>{let Ce=qk[pe.id]||{icon:"\u25AA",color:"white"},se=Ee===a;return bt.jsxDEV(U,{borderStyle:se?"bold":"single",borderColor:se?Ce.color:"gray",paddingX:2,children:bt.jsxDEV(B,{bold:se,color:se?Ce.color:void 0,dimColor:!se,children:[Ce.icon," ",pe.name]},void 0,!0,void 0,this)},pe.id,!1,void 0,this)})},void 0,!1,void 0,this),bt.jsxDEV(U,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:oe,paddingX:2,paddingY:1,children:!L||L.loading?bt.jsxDEV(B,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"Loading..."},void 0,!1,void 0,this):L.error?bt.jsxDEV(B,{color:"red",children:[i?"\u52A0\u8F7D\u5931\u8D25\uFF1A":"Failed: ",L.error]},void 0,!0,void 0,this):J.length===0?bt.jsxDEV(B,{dimColor:!0,children:i?"\u6682\u65E0\u7248\u672C":"No versions"},void 0,!1,void 0,this):bt.jsxDEV(U,{flexDirection:"column",children:[bt.jsxDEV(B,{dimColor:!0,children:[i?`\u5171 ${J.length} \u4E2A\u7248\u672C\uFF0C\u5F53\u524D\u5B89\u88C5\uFF1A`:`${J.length} versions, current: `,bt.jsxDEV(B,{color:oe,children:L.current??(i?"\u672A\u5B89\u88C5":"not installed")},void 0,!1,void 0,this)]},void 0,!0,void 0,this),bt.jsxDEV(U,{marginTop:1,flexDirection:"column",children:de.map((pe,Ee)=>{let se=p+Ee===u,Ie=pe.publishedAt?pe.publishedAt.slice(0,10):"",ve=pe.isCurrent?i?" \u2605 \u5F53\u524D":" \u2605 current":"",ye=Q===pe.version,gt=se?oe:pe.isCurrent?"green":void 0;return bt.jsxDEV(U,{paddingLeft:1,children:bt.jsxDEV(B,{color:gt,bold:se,dimColor:!se&&!pe.isCurrent,children:[se?"\u25B6 ":" ",pe.version.padEnd(16),Ie.padEnd(14),ve,ye?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),bt.jsxDEV(U,{marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:2,justifyContent:"center",gap:2,children:[bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2190\u2192"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u5207\u6362\u5DE5\u5177":"switch"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u9009\u62E9":"select"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u5B89\u88C5":"install"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:i?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),bt.jsxDEV(B,{dimColor:!0,bold:!0,children:"Esc"},void 0,!1,void 0,this),bt.jsxDEV(B,{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 zo,bt,Iy=12,qk;var $k=_(async()=>{Pc();Zh();Tn();await si();zo=Be(pt(),1),bt=Be(An(),1),qk={"claude-code":{icon:"\u2726",color:"yellow"},codex:{icon:"\u25C8",color:"blue"},gemini:{icon:"\u25C6",color:"cyan"},grok:{icon:"\u2736",color:"white"},pi:{icon:"\u03C0",color:"magenta"},"pi-web":{icon:"\u25CE",color:"magenta"}}});function y9(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 tF({sid:e,onBack:o}){let i=Ji()==="zh",[a,s]=uo.useState(null),[u,d]=uo.useState([]),[p,f]=uo.useState(""),[m,h]=uo.useState("idle"),[Q,C]=uo.useState(null),[w,b]=uo.useState([]),v=uo.useRef(0),S=uo.useCallback(async()=>{let oe=await ol(e,eF);if(!oe)return;s(oe.meta),d(oe.log);try{let de=await import("fs/promises"),pe=await de.stat(eo(e));v.current=pe.size}catch{v.current=0}},[e]);uo.useEffect(()=>{S()},[S]),uo.useEffect(()=>{let oe=!1,de=null,pe=async()=>{if(oe)return;try{let Ee=await import("fs/promises"),Ce=await Ee.stat(eo(e));if(Ce.size>v.current){let se=await Ee.open(eo(e),"r"),Ie=Buffer.alloc(Ce.size-v.current);await se.read(Ie,0,Ie.length,v.current),await se.close(),v.current=Ce.size;let ve=[];for(let ye of Ie.toString("utf-8").split(`
702
702
  `)){if(!ye.trim())continue;try{ve.push(JSON.parse(ye))}catch{}}if(ve.length)d((ye)=>[...ye,...ve].slice(-eF))}if(Math.random()<0.1){let se=await ol(e,0);if(se)s(se.meta)}b(await Xc(e))}catch{}de=setTimeout(pe,Zk)};return de=setTimeout(pe,Zk),()=>{if(oe=!0,de)clearTimeout(de)}},[e]);let L=uo.useCallback(async()=>{if(m!=="idle"||!p.trim())return;let oe=p;f(""),C(null),h("sending");try{await ed(e,oe)}catch(de){C(de instanceof Error?de.message:String(de))}finally{h("idle");let de=await ol(e,0);if(de)s(de.meta)}},[e,p,m]),J=uo.useCallback(async()=>{if(m!=="sending")return o();h("cancelling"),await td(e).catch(()=>{})},[m,e,o]),j=uo.useCallback(async(oe)=>{let de=w[0];if(!de)return;await Eg(e,de.approvalId,{decision:oe?"allow":"deny",by:"tui",decidedAt:Date.now()}),b((pe)=>pe.filter((Ee)=>Ee.approvalId!==de.approvalId))},[w,e]);if(Hn((oe,de)=>{if(de.ctrl&&oe==="y"){j(!0);return}if(de.ctrl&&oe==="n"){j(!1);return}if(de.escape){J();return}if(de.ctrl&&oe==="c"){J();return}if(de.ctrl&&oe==="d"){o();return}if(de.return){L();return}if(de.backspace||de.delete){f((pe)=>pe.slice(0,-1));return}if(p.length===0&&oe==="q"){o();return}if(oe&&!de.ctrl&&oe.length===1)f((pe)=>pe+oe)}),!a)return Qt.jsxDEV(U,{paddingX:2,paddingY:1,children:Qt.jsxDEV(B,{dimColor:!0,children:i?"\u52A0\u8F7D\u4E2D...":"loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);return Qt.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[Qt.jsxDEV(U,{children:[Qt.jsxDEV(B,{bold:!0,children:"Session "},void 0,!1,void 0,this),Qt.jsxDEV(B,{color:"cyan",children:a.sid.slice(0,8)},void 0,!1,void 0,this),Qt.jsxDEV(B,{children:" "},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,children:a.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Qt.jsxDEV(U,{children:Qt.jsxDEV(B,{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),Qt.jsxDEV(U,{children:Qt.jsxDEV(B,{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&&Qt.jsxDEV(U,{marginTop:1,flexDirection:"column",borderStyle:"round",borderColor:"magenta",paddingX:1,children:[Qt.jsxDEV(B,{color:"magenta",bold:!0,children:["\u26A0 ",w.length," ",i?"\u4E2A\u5F85\u5BA1\u6279":"pending"," \u2014 ",Qt.jsxDEV(B,{bold:!0,children:"Ctrl-Y"},void 0,!1,void 0,this)," ",i?"\u6279\u51C6":"allow"," / ",Qt.jsxDEV(B,{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((oe,de)=>Qt.jsxDEV(B,{color:de===0?"magenta":void 0,dimColor:de!==0,children:[de===0?"\u25B6 ":" ","[",oe.approvalType,"] ",oe.approvalId.slice(0,12)]},oe.approvalId,!0,void 0,this))]},void 0,!0,void 0,this),Qt.jsxDEV(U,{marginTop:1,flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:1,children:u.length===0?Qt.jsxDEV(B,{dimColor:!0,children:i?"\uFF08\u6682\u65E0\u65E5\u5FD7\uFF09":"(no log yet)"},void 0,!1,void 0,this):u.slice(-30).map((oe,de)=>{let pe=y9(oe);return Qt.jsxDEV(B,{color:pe.color,dimColor:pe.dim,children:pe.text||" "},de,!1,void 0,this)})},void 0,!1,void 0,this),Q&&Qt.jsxDEV(U,{marginTop:1,children:Qt.jsxDEV(B,{color:"red",children:["\u2717 ",Q]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Qt.jsxDEV(U,{marginTop:1,children:[Qt.jsxDEV(B,{color:"cyan",bold:!0,children:m==="sending"?"\u23F3 ":m==="cancelling"?"\u270B ":"\u25B6 "},void 0,!1,void 0,this),Qt.jsxDEV(B,{children:p},void 0,!1,void 0,this),m==="idle"&&Qt.jsxDEV(B,{inverse:!0,children:" "},void 0,!1,void 0,this),m==="sending"&&Qt.jsxDEV(B,{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),Qt.jsxDEV(U,{marginTop:1,gap:2,children:[Qt.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,children:i?"\u53D1\u9001":"send"},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,bold:!0,children:"^Y/^N"},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,children:i?"\u6279/\u62D2":"allow/deny"},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Qt.jsxDEV(B,{dimColor:!0,bold:!0,children:"ESC"},void 0,!1,void 0,this),Qt.jsxDEV(B,{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 uo,Qt,Zk=300,eF=200;var nF=_(async()=>{Tn();Sg();wA();await si();uo=Be(pt(),1),Qt=Be(An(),1)});function oF(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 D9(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=Ji()==="zh",[i,a]=Wn.useState(null),[s,u]=Wn.useState({}),[d,p]=Wn.useState(0),[f,m]=Wn.useState(null),[h,Q]=Wn.useState(0),[C,w]=Wn.useState({kind:"list"}),b=Wn.useCallback(async()=>{let[v,S]=await Promise.all([Dg(),vg()]);a(v),u(S),p((L)=>Math.max(0,Math.min(L,v.length-1)))},[]);if(Wn.useEffect(()=>{b()},[b,h]),Wn.useEffect(()=>{let v=setInterval(()=>Q((S)=>S+1),5000);return()=>clearInterval(v)},[]),Hn((v,S)=>{if(f)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((J)=>J+1);return}if(S.upArrow||v==="k"){p((J)=>Math.max(0,J-1));return}if(S.downArrow||v==="j"){p((J)=>Math.min(i.length-1,J+1));return}if(v==="r"){Q((J)=>J+1);return}if(v==="p"){m(o?"\u6E05\u7406\u4E2D...":"purging..."),wg().then(()=>{m(null),b()});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)}...`),vA(L.sid,!1).then(()=>{m(null),b()});return}if(v==="x"){m(`purging ${L.sid.slice(0,8)}...`),vA(L.sid,!0).then(()=>{m(null),b()});return}}),C.kind==="detail")return Ne.jsxDEV(tF,{sid:C.sid,onBack:()=>{w({kind:"list"}),b()}},void 0,!1,void 0,this);if(C.kind==="new")return Ne.jsxDEV(Q9,{initial:C,onCancel:()=>w({kind:"list"}),onCreated:(v)=>{w({kind:"detail",sid:v})}},void 0,!1,void 0,this);if(!i)return Ne.jsxDEV(U,{paddingX:2,paddingY:1,children:Ne.jsxDEV(B,{dimColor:!0,children:o?"\u52A0\u8F7D\u4E2D...":"loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);return Ne.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[Ne.jsxDEV(B,{bold:!0,children:o?"Agent \u4F1A\u8BDD\u7BA1\u7406":"Agent Sessions"},void 0,!1,void 0,this),Ne.jsxDEV(U,{marginTop:1,children:Ne.jsxDEV(B,{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?Ne.jsxDEV(U,{marginTop:2,flexDirection:"column",children:Ne.jsxDEV(B,{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):Ne.jsxDEV(U,{marginTop:1,flexDirection:"column",children:[Ne.jsxDEV(U,{children:Ne.jsxDEV(B,{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 Ne.jsxDEV(U,{children:[Ne.jsxDEV(B,{color:L?"cyan":void 0,inverse:L,children:L?"\u25B6 ":" "},void 0,!1,void 0,this),Ne.jsxDEV(B,{color:L?"cyan":void 0,children:v.sid.slice(0,8).padEnd(10)},void 0,!1,void 0,this),Ne.jsxDEV(B,{children:v.backend.padEnd(9)},void 0,!1,void 0,this),Ne.jsxDEV(B,{children:(v.name??"").slice(0,18).padEnd(20)},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:(v.model??"-").slice(0,20).padEnd(22)},void 0,!1,void 0,this),Ne.jsxDEV(B,{color:D9(v.status),children:v.status.padEnd(9)},void 0,!1,void 0,this),Ne.jsxDEV(B,{children:String(v.turnCount).padEnd(7)},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:oF(Date.now()-v.createdAt).padEnd(6)},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:oF(Date.now()-v.lastActiveAt)},void 0,!1,void 0,this)]},v.sid,!0,void 0,this)})]},void 0,!0,void 0,this),f&&Ne.jsxDEV(U,{marginTop:1,children:Ne.jsxDEV(B,{color:"yellow",children:["\u23F3 ",f]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ne.jsxDEV(U,{marginTop:2,gap:2,children:[Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"\u2191\u2193"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:o?"\u9009\u62E9":"select"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:o?"\u8FDB\u5165":"open"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"n"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:o?"\u65B0\u5EFA":"new"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"d"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:o?"\u5173\u95ED":"close"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"x"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:o?"\u5220\u9664":"purge"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"r"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:o?"\u5237\u65B0":"refresh"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"q"},void 0,!1,void 0,this),Ne.jsxDEV(B,{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 Q9({initial:e,onCancel:o,onCreated:i}){let a=Ji()==="zh",[s,u]=Wn.useState(e.backend),[d,p]=Wn.useState(e.model),[f,m]=Wn.useState(e.name),[h,Q]=Wn.useState(e.field),[C,w]=Wn.useState(!1),[b,v]=Wn.useState(null),S=Wn.useCallback(async()=>{if(C)return;w(!0),v(null);try{let L=await Zc({backend:s,model:d.trim()||void 0,name:f.trim()||void 0});i(L.sid)}catch(L){v(L instanceof Error?L.message:String(L)),w(!1)}},[s,d,f,C,i]);return Hn((L,J)=>{if(C)return;if(J.escape){o();return}if(J.tab||J.downArrow){Q((j)=>j==="backend"?"model":j==="model"?"name":"backend");return}if(J.upArrow){Q((j)=>j==="backend"?"name":j==="model"?"backend":"model");return}if(h==="backend"){if(J.leftArrow||J.rightArrow||L===" "){u((j)=>j==="claude"?"codex":"claude");return}if(J.return){S();return}return}if(h==="model"){if(J.return){Q("name");return}if(J.backspace||J.delete){p((j)=>j.slice(0,-1));return}if(L&&!J.ctrl&&L.length===1)p((j)=>j+L);return}if(h==="name"){if(J.return){S();return}if(J.backspace||J.delete){m((j)=>j.slice(0,-1));return}if(L&&!J.ctrl&&L.length===1)m((j)=>j+L)}}),Ne.jsxDEV(U,{flexDirection:"column",paddingX:2,paddingY:1,children:[Ne.jsxDEV(B,{bold:!0,children:a?"\u65B0\u5EFA Agent Session":"New agent session"},void 0,!1,void 0,this),Ne.jsxDEV(U,{marginTop:1,children:Ne.jsxDEV(B,{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),Ne.jsxDEV(U,{children:Ne.jsxDEV(B,{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"&&Ne.jsxDEV(B,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ne.jsxDEV(U,{children:Ne.jsxDEV(B,{color:h==="name"?"cyan":void 0,bold:h==="name",children:[h==="name"?"\u25B6 ":" ",a?"\u540D\u5B57":"name",": ",f||(a?"\uFF08\u7559\u7A7A\u81EA\u52A8\uFF09":"(auto)"),h==="name"&&Ne.jsxDEV(B,{inverse:!0,children:" "},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b&&Ne.jsxDEV(U,{marginTop:1,children:Ne.jsxDEV(B,{color:"red",children:["\u2717 ",b]},void 0,!0,void 0,this)},void 0,!1,void 0,this),C&&Ne.jsxDEV(U,{marginTop:1,children:Ne.jsxDEV(B,{color:"yellow",children:["\u23F3 ",a?"\u521B\u5EFA\u4E2D...":"creating..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ne.jsxDEV(U,{marginTop:1,gap:2,children:[Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"Tab/\u2191\u2193"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:a?"\u5207\u5B57\u6BB5":"switch"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"Enter"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:a?"\u521B\u5EFA":"create"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,children:"\u2502"},void 0,!1,void 0,this),Ne.jsxDEV(B,{dimColor:!0,bold:!0,children:"ESC"},void 0,!1,void 0,this),Ne.jsxDEV(B,{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 Wn,Ne;var rF=_(async()=>{Tn();Sg();await Ba([si(),nF()]);Wn=Be(pt(),1),Ne=Be(An(),1)});function w9({onLaunch:e,onExit:o,initialView:i="launcher",initialSessionSearch:a=!1}){let[s,u]=Ri.useState(i),[d,p]=Ri.useState([]),f=Ri.useRef(null),m=Ri.useRef(!1);Ri.useEffect(()=>{if(m.current||i!=="launcher")return;m.current=!0,Yk().then((v)=>{if(v)u("key-guide")})},[i]);let h=Ri.useCallback((v)=>{if(p((S)=>[...S.slice(-4),v]),f.current)clearTimeout(f.current);f.current=setTimeout(()=>p([]),5000)},[]);Ri.useEffect(()=>{let v=0;return NS({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:(J)=>{if(p((j)=>{let oe=j.filter((de)=>de.id!==L);if(J)oe.push({text:J,type:"success"});return oe.slice(-5)}),f.current)clearTimeout(f.current);f.current=setTimeout(()=>p([]),5000)},update:(J)=>{if(p((j)=>j.map((oe)=>oe.id===L?{...oe,text:J}:oe)),f.current)clearTimeout(f.current);f.current=setTimeout(()=>p([]),5000)}}}}),()=>Mf()},[h]);let Q=Ri.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"},b=(()=>{switch(s){case"launcher":return Ai.jsxDEV(Qk,{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 Ai.jsxDEV(Nk,{onDone:(v)=>{if(v==="client-versions")u("client-versions");else Q()}},void 0,!1,void 0,this);case"agents":return Ai.jsxDEV(iF,{onDone:Q},void 0,!1,void 0,this);case"client-versions":return Ai.jsxDEV(Xk,{onDone:()=>u("providers")},void 0,!1,void 0,this);case"stats":return Ai.jsxDEV(Lk,{onExit:Q},void 0,!1,void 0,this);case"config":return Ai.jsxDEV(Uk,{isReconfigure:!0,onDone:Q},void 0,!1,void 0,this);case"language":return Ai.jsxDEV(Pk,{onDone:Q},void 0,!1,void 0,this);case"key-guide":return Ai.jsxDEV(jk,{onDone:(v)=>{if(v==="configure")u("config");else Wk(v).then(()=>u("launcher"))}},void 0,!1,void 0,this)}})();return Ai.jsxDEV(U,{flexDirection:"column",children:[d.length>0&&Ai.jsxDEV(U,{flexDirection:"column",paddingX:2,children:d.map((v,S)=>Ai.jsxDEV(B,{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),b]},void 0,!0,void 0,this)}function Od(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(),Mf(),o(d)}function u(){i?.clear(),i?.unmount(),i=null,a(),Mf(),o(null)}i=dy(Ai.jsxDEV(w9,{onLaunch:s,onExit:u,initialSessionSearch:e.initialSessionSearch},void 0,!1,void 0,this))})}var Ri,Ai;var aF=_(async()=>{Nr();await Ba([si(),wk(),Rk(),Mk(),Gk(),zk(),Vk(),$k(),rF()]);Ri=Be(pt(),1),Ai=Be(An(),1)});var By=_(async()=>{await aF()});function Vr(e){if(yf||process.env.TAKO_DEBUG==="1")process.stderr.write(`[announcements] ${e}
703
703
  `)}function AF(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 S9(e,o){let i=`${e}/v1/announcements/popup`;try{let a=await fetch(i,{headers:{Authorization:`Bearer ${o}`},signal:AbortSignal.timeout(v9)});if(!a.ok)return Vr(`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 Vr("\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 Vr(`payload \u7F3A id/title\uFF0C\u4E22\u5F03\uFF1A${JSON.stringify(u)}`),null;return Vr(`\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 Vr(`fetch \u5931\u8D25\uFF1A${a instanceof Error?a.message:String(a)}`),null}}async function x9(e){return((await nt()).seenAnnouncementIds??[]).includes(e)}async function b9(e){let o=await nt(),i=o.seenAnnouncementIds??[];if(i.includes(e))return;let a=[...i,e];if(a.length>sF)a.splice(0,a.length-sF);o.seenAnnouncementIds=a,await Io(o)}async function N9(){let e=AF(await Qi());if(e)return e;for(let o of await Uo()){let i=AF(o);if(i)return i}return null}async function uF(){let e=await N9();if(!e){Vr("\u8DF3\u8FC7\uFF1A\u6CA1\u6709\u53EF\u7528\u7684 tako/custom provider\uFF08apiKey + baseUrl\uFF09");return}Vr(`\u67E5\u8BE2\u516C\u544A\uFF1A${e.baseUrl}/v1/announcements/popup`);let o=await S9(e.baseUrl,e.apiKey);if(!o)return;if(o.popup_once&&await x9(o.id)){Vr(`\u5DF2\u5728 seenAnnouncementIds\uFF0C\u8DF3\u8FC7\uFF1A${o.id}`);return}if(Vr(`\u5F39\u7A97\uFF1A${o.id}`),await kS(o),o.popup_once)await b9(o.id),Vr(`\u6807\u8BB0\u5DF2\u770B\u8FC7\uFF1A${o.id}`)}var v9=2000,sF=100;var lF=_(()=>{Kt();wi()});async function cF(){await wx(),await vx(),await J1(),await Promise.race([J0(await Uo()),new Promise((e)=>setTimeout(e,3000))]),await uF()}async function qm(e){let o=Nn(e.clientId);if(!o)return!1;Jn("menu_action",{action:"launch",client_id:e.clientId});let i=await dg(e.clientId);if(!i)return Me.warn(Se("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 el(o,{projectPath:e.projectPath,args:e.args,envVars:e.envVars,selectedOptionIds:e.selectedOptionIds,resume:e.resume,resumeModelId:e.resumeModelId,providerContext:i,relaunchTakoOnWindows:s});if(!u.success)return Me.error(u.error||Se("cli.launchFailed")),!1;if(s)return!0;return!1}var yy=_(()=>{og();Rn();Tn();Tr();Nr();wi();Xh();lF();fs()});function Ud(e,o){let i=e.indexOf(o);return i>=0?e[i+1]:void 0}function R9(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 T9(e){if(e<1024)return`${e} B`;if(e<1048576)return`${(e/1024).toFixed(1)} KiB`;return`${(e/1024/1024).toFixed(1)} MiB`}function k9(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 dF(e){if(e.length===0&&process.stdin.isTTY&&process.stdout.isTTY){await By();await Promise.resolve().then(() => yy());let s=await Od({initialSessionSearch:!0});if(s?.type==="launch")await qm(s);return}let o=Mg();try{let i=e[0]??"search";if(i==="index"){if(e.includes("--clear")){await Ab(o),console.log("Cleared the native session index.");return}if(e.includes("--status")){let f=o.status();console.log(`${f.sessions} sessions from ${f.sourceFiles} files \xB7 ${T9(f.bytes)} \xB7 schema v${f.schemaVersion}
704
704
  ${f.path}`);return}let p=e.includes("--rebuild")?await sb(o):await id(o);console.log(`Indexed ${p} native session files.`);return}if(await id(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 lb(p);return}let a=k9(e,i),s=Ud(e,"--source")?.split(",").filter((p)=>rb(p)),u=Number(Ud(e,"--limit")??50),d=Lg(o,a,{deep:e.includes("--deep"),sources:s,cwd:Ud(e,"--cwd"),project:Ud(e,"--project"),after:R9(Ud(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)"}
@@ -855,10 +855,10 @@ Install: tako skill install <name>`),console.log(`Install all: tako skill instal
855
855
  Usage: tako models [list] [--refresh] [--json]
856
856
  `),1;let a=o.loadConfig??nt,s=o.refresh??Lf,u=o.read??Ro,d=o.now??(()=>Date.now()),p=o.columns??(()=>process.stdout.columns??80),f=await a(),m=_9(f);if(i.refresh&&m.length>0)await G9(m,s);let h=m.map((C)=>U9(C,u)),Q=new Date(d()).toISOString();if(i.json)process.stdout.write(Y9(h,i.refresh,Q));else process.stdout.write(J9(h,p()));return 0}var EF,H9=5;var hF=_(()=>{Kt();Hu();EF=["openai","claude"]});Pc();Nr();Nc();Kt();Tn();Tr();Uf();import{join as vi}from"path";function s1(e){return!e||!e.includes("TAKO_WINDOWS_HANDOFF_FILE")}function A1(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
857
857
  `)}function u1(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
858
- `)}var Rh="tako-cli",Is="0.3.52";function U8(){return[No,"update",Rh,"--latest"]}function G8(){return[No,"add",`${Rh}@latest`]}function H8(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 P8(){try{let e=await yi(),o=await fetch(`${e}/${Rh}/latest`,{signal:AbortSignal.timeout(5000)});if(!o.ok)return null;return(await o.json()).version||null}catch{return null}}async function l1(){let e=await P8();if(!e)return{hasUpdate:!1,currentVersion:Is};return{hasUpdate:H8(e,Is)>0,latestVersion:e,currentVersion:Is}}async function Th(){let e=await import("fs/promises"),o=vi(Ft,"bin"),i=vi(o,"tako"),a=vi(wr,"node_modules/tako-cli/dist/index.js");if(await e.mkdir(o,{recursive:!0}),process.platform==="win32")await e.writeFile(vi(o,"tako.cmd"),A1(No,a)),await e.writeFile(vi(o,"tako.ps1"),u1(No,a));else{let u=`#!/bin/bash
858
+ `)}var Rh="tako-cli",Is="0.3.53";function U8(){return[No,"update",Rh,"--latest"]}function G8(){return[No,"add",`${Rh}@latest`]}function H8(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 P8(){try{let e=await yi(),o=await fetch(`${e}/${Rh}/latest`,{signal:AbortSignal.timeout(5000)});if(!o.ok)return null;return(await o.json()).version||null}catch{return null}}async function l1(){let e=await P8();if(!e)return{hasUpdate:!1,currentVersion:Is};return{hasUpdate:H8(e,Is)>0,latestVersion:e,currentVersion:Is}}async function Th(){let e=await import("fs/promises"),o=vi(Ft,"bin"),i=vi(o,"tako"),a=vi(wr,"node_modules/tako-cli/dist/index.js");if(await e.mkdir(o,{recursive:!0}),process.platform==="win32")await e.writeFile(vi(o,"tako.cmd"),A1(No,a)),await e.writeFile(vi(o,"tako.ps1"),u1(No,a));else{let u=`#!/bin/bash
859
859
  exec "${No}" "${a}" "$@"
860
- `;await e.writeFile(i,u,{mode:493})}}async function c1(){if(process.platform!=="win32")return!1;try{let e=await import("fs/promises"),o=vi(Ft,"bin","tako.cmd"),i=await e.readFile(o,"utf8").catch(()=>null);if(i===null)return!1;if(!s1(i))return!1;return await Th(),!0}catch{return!1}}async function d1(e){let o=oi(),i=`\u6B63\u5728\u66F4\u65B0\u5230 v${e}`;o.start(i);try{let a=await yi(),s=await import("fs/promises");await s.mkdir(wr,{recursive:!0});let u=vi(wr,"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(U8(),{cwd:wr,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:a}}),p=await ms(d,i,(f)=>o.update(f));if(await d.exited,d.exitCode===0)return await Th(),Jn("cli_updated",{from_version:Is,to_version:e}),o.stop(`\u66F4\u65B0\u6210\u529F\uFF01\u5DF2\u66F4\u65B0\u5230 v${e}`),!0;else return o.stop(),Me.warn(`\u66F4\u65B0\u5931\u8D25: ${Ju(p)}`),!1}catch(a){return o.stop(),Me.warn(`\u66F4\u65B0\u5931\u8D25: ${Ju(a instanceof Error?a.message:void 0)}`),!1}}async function z8(){let e=await import("fs/promises"),o=vi(wr,"bun.lock");try{await e.unlink(o)}catch{}}async function K8(){let e=await import("fs/promises");try{let o=await yi();await e.mkdir(wr,{recursive:!0});let i=vi(wr,"package.json");try{await e.access(i)}catch{await e.writeFile(i,JSON.stringify({name:"tako-local",private:!0},null,2))}await z8();let a=Bun.spawn(G8(),{cwd:wr,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:o}});return await a.exited,a.exitCode===0}catch{return!1}}async function J8(){let e=await import("fs/promises"),o=vi(Ft,"bin"),i=vi(o,"tako"),a=vi(wr,"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")){Me.info(Se("updater.migrating"));let u=!1;try{await e.access(a),u=!0}catch{u=!1}if(!u){let d=oi();if(d.start(Se("updater.installingLocally")),!await K8())return d.stop(Se("updater.migrationFailed")),!1;d.stop(Se("updater.installComplete"))}return await Th(),!0}}catch{}return!1}async function p1(){try{if(await J8())Me.info(Se("updater.migrationComplete")),process.exit(0);let o=await l1();if(o.hasUpdate&&o.latestVersion){if(Me.warn(Se("updater.newVersionAvailable",{version:o.latestVersion,current:Is})),await d1(o.latestVersion))Me.info(Se("updater.pleaseRestart")),process.exit(0)}}catch{}}async function f1(){console.log(`Tako CLI \u5F53\u524D\u7248\u672C: v${Is}`),console.log("\u6B63\u5728\u68C0\u67E5\u66F4\u65B0...");let e=await l1();if(!e.hasUpdate){if(e.latestVersion)console.log(`\u5DF2\u662F\u6700\u65B0\u7248\u672C v${Is}`);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${Is}\uFF09`),console.log("\u6B63\u5728\u66F4\u65B0..."),await d1(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)}Rn();og();Tn();Tr();import{homedir as p4}from"os";var xt={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 an={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",reset:"\x1B[0m"};var wn={directory:{icon:xt.brightYellow,text:xt.brightGreen},git:{icon:xt.brightBlue,text:xt.brightBlue,clean:xt.brightGreen,dirty:xt.brightYellow,conflict:xt.brightRed},model:{icon:xt.brightCyan,text:xt.brightCyan},version:{icon:xt.brightWhite,text:xt.brightBlack},outputStyle:{icon:xt.brightMagenta,text:xt.brightMagenta},context:{icon:xt.brightMagenta,low:xt.brightGreen,medium:xt.brightYellow,high:xt.brightRed},todayUsage:{icon:xt.brightGreen,text:xt.brightGreen},separator:xt.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 d4(){return!1}function Mr(e){let o=va[e];if(typeof o==="string")return o;return d4()?o.nerd:o.plain}class ig{id="directory";render(e){let o=this.formatPath(e.workspace.current_dir),i=Mr("directory");return`${wn.directory.icon}${i}${an.reset} ${wn.directory.text}${o}${an.reset}`}formatPath(e){let o=p4();if(e===o)return"~";if(e.startsWith(o+"/"))return"~"+e.slice(o.length);return e}}class rg{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),f=Mr("git"),m=`${wn.git.icon}${f}${an.reset} ${wn.git.text}${a}${an.reset}`;if(m+=` ${u}${s}${an.reset}`,d>0)m+=` ${wn.git.clean}${va.gitAhead}${d}${an.reset}`;if(p>0)m+=` ${wn.git.dirty}${va.gitBehind}${p}${an.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:wn.git.clean};let s=i.trim();if(!s)return{status:va.gitClean,statusColor:wn.git.clean};if(s.includes("UU")||s.includes("AA")||s.includes("DD"))return{status:va.gitConflict,statusColor:wn.git.conflict};return{status:va.gitDirty,statusColor:wn.git.dirty}}catch{return{status:va.gitClean,statusColor:wn.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(),f=await u.exited===0?parseInt(d.trim(),10)||0:0;return{ahead:s,behind:f}}catch{return{ahead:0,behind:0}}}}var f4={"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 ag{id="model";render(e){let o=e.model.id,i=f4[o]||this.simplifyModelName(e.model.display_name),a=Mr("model");return`${wn.model.icon}${a}${an.reset} ${wn.model.text}${i}${an.reset}`}simplifyModelName(e){let o=e.replace(/^Claude\s+/i,"");return o=o.replace(/-\d{8}$/,""),o}}fs();var g4=200000,R1=20000,m4=13000,E4="TAKO_MODEL_CONTEXT_WINDOW",C4="CLAUDE_CODE_AUTO_COMPACT_WINDOW";function h4(e,o=process.env[E4]){if(o){let i=Number(o);if(Number.isSafeInteger(i)&&i>0)return i}return gA(e)?.contextWindow??g4}function I4(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 B4(e){let o=e.context_window?.context_window_size;if(typeof o==="number"&&Number.isSafeInteger(o)&&o>0)return o;return h4(e.model.id)}function y4(e,o=process.env[C4]){if(o){let i=Number(o);if(Number.isSafeInteger(i)&&i>0)return Math.min(e,i)}return e}function D4(e,o=R1){let i=Math.min(Math.max(0,o),R1),a=Math.max(0,e-i);return Math.max(0,a-m4)}class _r{id="context";static cache=null;static CACHE_TTL=5000;async render(e){let i=I4(e)??await this.getTokensWithCache(e.transcript_path),a=B4(e),s=y4(a),u=D4(s);if(u<=0)return null;let d=Math.min(100,Math.max(0,Math.ceil((u-(i??0))/u*100))),p=Mr("context"),f=d<=20?xt.brightRed:d<=50?xt.brightYellow:xt.brightGreen;return`${wn.context.icon}${p}${an.reset} ${f}${d}%${an.reset}`}async getTokensWithCache(e){let o=Date.now();if(_r.cache&&_r.cache.path===e&&o-_r.cache.timestamp<_r.CACHE_TTL)return _r.cache.tokens;let i=await this.parseTranscriptTokens(e);return _r.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(`
861
- `).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}}}lg();wi();class cg{id="quota";async render(e){let o=await this.tryRenderOfficial();if(o)return o;return this.renderSessionCost(e)}async tryRenderOfficial(){try{let e=await hs("claude-code")??await Qi();if(!e)return null;let o=await ug(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()} ${xt.brightGreen}Day:${this.fmtCost(a)}${an.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(`${an.dim} \xB7 ${an.reset}`)}`}renderClaudeSub=this.renderSub;renderCodexSub=this.renderSub;pctChunk(e,o){let i=o>=90?xt.brightRed:o>=70?xt.brightYellow:xt.brightGreen;return`${e}:${i}${o}%${an.reset}`}remainChunk(e,o){let i=Math.max(0,Math.min(100,100-Math.round(o))),a=i<=10?xt.brightRed:i<=30?xt.brightYellow:xt.brightGreen;return`${e} \u5269 ${a}${i}%${an.reset}`}renderSessionCost(e){let o=e.cost?.total_cost_usd;if(o==null||o<=0)return null;return`${this.icon()} ${xt.brightGreen}Session:${this.fmtCost(o)}${an.reset}`}icon(){return`${wn.todayUsage.icon}${Mr("todayUsage")}${an.reset}`}fmtCost(e){if(e>=100)return`$${Math.round(e)}`;if(e>=10)return`$${e.toFixed(1)}`;return`$${e.toFixed(2)}`}}class jh{separator=`${wn.separator} \u2502 ${an.reset}`;render(e){let o=["directory","git","model","context","quota"],i=[];for(let a of o){let s=e.get(a);if(s)i.push(s)}return i.join(this.separator)}}import{join as yA,dirname as O4}from"path";import{homedir as Vh}from"os";import{mkdir as U4}from"fs/promises";var z1=yA(Vh(),".tako"),G4=yA(z1,"cli"),H4=yA(z1,"bin",process.platform==="win32"?"tako.cmd":"tako");function P4(){if(process.platform==="win32")return yA(process.env.APPDATA||yA(Vh(),"AppData","Roaming"),"claude","settings.json");return yA(Vh(),".claude","settings.json")}var z4=process.platform==="win32",K4="0.1.48";function J4(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 Y4(){let e=yA(G4,"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 W4(){let e=await Y4();if(!e)return!1;return J4(e,K4)>=0}function j4(){return H4}function V4(){return`"${q4(j4())}" statusline`}function q4(e){if(z4)return e.replace(/\\/g,"/");return e}async function qh(){if(!await W4())return;let o=P4(),i={};try{let u=Bun.file(o);if(await u.exists())i=await u.json()}catch{}let a={type:"command",command:V4(),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 U4(O4(o),{recursive:!0}),await Bun.write(o,JSON.stringify(i,null,2))}var X4=[new ig,new rg,new ag,new _r,new cg];async function $4(e){let o=await Promise.all(X4.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 jh().render(i)}async function K1(){try{let e=await Bun.stdin.json(),o=await $4(e);console.log(o)}catch{process.exit(0)}}Xh();qf();Gc();Ph();async function DA(e,o,i,a){let s=o.filter((p)=>p!==i),u=await Hh(e,s,a);if(e==="grok"){let p=[];if(u)p.push(u);let f=!1;for(let m=0;m<s.length;m++){let h=s[m];if((h==="--model"||h==="-m")&&m+1<s.length){if(f){m++;continue}p.push("-m",xh(s[m+1])),f=!0,m++;continue}if(h.startsWith("--model=")){if(f)continue;p.push("-m",xh(h.slice(8))),f=!0;continue}p.push(h)}if(!f)p.unshift("-m",Xu($u));return p}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 f=s[p];if(f==="--model"&&p+1<s.length){d.push(f,Fr(s[p+1])),p++;continue}if(f.startsWith("--model=")){let m=f.slice(8);d.push(`--model=${Fr(m)}`);continue}d.push(f)}return d}fs();Zh();Kt();var $m="0.3.52",W9=!0;function j9(e){return W9&&!e}function V9(e){return e.replace(/\\/g,"/").includes("/cli/node_modules/tako-cli/")}async function PA(e){if(!j9(e))return;if(!V9(process.argv[1]??""))return;await p1()}function q9(){console.log(`
860
+ `;await e.writeFile(i,u,{mode:493})}}async function c1(){if(process.platform!=="win32")return!1;try{let e=await import("fs/promises"),o=vi(Ft,"bin","tako.cmd"),i=await e.readFile(o,"utf8").catch(()=>null);if(i===null)return!1;if(!s1(i))return!1;return await Th(),!0}catch{return!1}}async function d1(e){let o=oi(),i=`\u6B63\u5728\u66F4\u65B0\u5230 v${e}`;o.start(i);try{let a=await yi(),s=await import("fs/promises");await s.mkdir(wr,{recursive:!0});let u=vi(wr,"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(U8(),{cwd:wr,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:a}}),p=await ms(d,i,(f)=>o.update(f));if(await d.exited,d.exitCode===0)return await Th(),Jn("cli_updated",{from_version:Is,to_version:e}),o.stop(`\u66F4\u65B0\u6210\u529F\uFF01\u5DF2\u66F4\u65B0\u5230 v${e}`),!0;else return o.stop(),Me.warn(`\u66F4\u65B0\u5931\u8D25: ${Ju(p)}`),!1}catch(a){return o.stop(),Me.warn(`\u66F4\u65B0\u5931\u8D25: ${Ju(a instanceof Error?a.message:void 0)}`),!1}}async function z8(){let e=await import("fs/promises"),o=vi(wr,"bun.lock");try{await e.unlink(o)}catch{}}async function K8(){let e=await import("fs/promises");try{let o=await yi();await e.mkdir(wr,{recursive:!0});let i=vi(wr,"package.json");try{await e.access(i)}catch{await e.writeFile(i,JSON.stringify({name:"tako-local",private:!0},null,2))}await z8();let a=Bun.spawn(G8(),{cwd:wr,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:o}});return await a.exited,a.exitCode===0}catch{return!1}}async function J8(){let e=await import("fs/promises"),o=vi(Ft,"bin"),i=vi(o,"tako"),a=vi(wr,"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")){Me.info(Se("updater.migrating"));let u=!1;try{await e.access(a),u=!0}catch{u=!1}if(!u){let d=oi();if(d.start(Se("updater.installingLocally")),!await K8())return d.stop(Se("updater.migrationFailed")),!1;d.stop(Se("updater.installComplete"))}return await Th(),!0}}catch{}return!1}async function p1(){try{if(await J8())Me.info(Se("updater.migrationComplete")),process.exit(0);let o=await l1();if(o.hasUpdate&&o.latestVersion){if(Me.warn(Se("updater.newVersionAvailable",{version:o.latestVersion,current:Is})),await d1(o.latestVersion))Me.info(Se("updater.pleaseRestart")),process.exit(0)}}catch{}}async function f1(){console.log(`Tako CLI \u5F53\u524D\u7248\u672C: v${Is}`),console.log("\u6B63\u5728\u68C0\u67E5\u66F4\u65B0...");let e=await l1();if(!e.hasUpdate||!e.latestVersion){if(e.latestVersion)console.log(`\u5DF2\u662F\u6700\u65B0\u7248\u672C v${Is}`);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${Is}\uFF09`),console.log("\u6B63\u5728\u66F4\u65B0..."),await d1(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)}Rn();og();Tn();Tr();import{homedir as p4}from"os";var xt={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 an={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",reset:"\x1B[0m"};var wn={directory:{icon:xt.brightYellow,text:xt.brightGreen},git:{icon:xt.brightBlue,text:xt.brightBlue,clean:xt.brightGreen,dirty:xt.brightYellow,conflict:xt.brightRed},model:{icon:xt.brightCyan,text:xt.brightCyan},version:{icon:xt.brightWhite,text:xt.brightBlack},outputStyle:{icon:xt.brightMagenta,text:xt.brightMagenta},context:{icon:xt.brightMagenta,low:xt.brightGreen,medium:xt.brightYellow,high:xt.brightRed},todayUsage:{icon:xt.brightGreen,text:xt.brightGreen},separator:xt.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 d4(){return!1}function Mr(e){let o=va[e];if(typeof o==="string")return o;return d4()?o.nerd:o.plain}class ig{id="directory";render(e){let o=this.formatPath(e.workspace.current_dir),i=Mr("directory");return`${wn.directory.icon}${i}${an.reset} ${wn.directory.text}${o}${an.reset}`}formatPath(e){let o=p4();if(e===o)return"~";if(e.startsWith(o+"/"))return"~"+e.slice(o.length);return e}}class rg{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),f=Mr("git"),m=`${wn.git.icon}${f}${an.reset} ${wn.git.text}${a}${an.reset}`;if(m+=` ${u}${s}${an.reset}`,d>0)m+=` ${wn.git.clean}${va.gitAhead}${d}${an.reset}`;if(p>0)m+=` ${wn.git.dirty}${va.gitBehind}${p}${an.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:wn.git.clean};let s=i.trim();if(!s)return{status:va.gitClean,statusColor:wn.git.clean};if(s.includes("UU")||s.includes("AA")||s.includes("DD"))return{status:va.gitConflict,statusColor:wn.git.conflict};return{status:va.gitDirty,statusColor:wn.git.dirty}}catch{return{status:va.gitClean,statusColor:wn.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(),f=await u.exited===0?parseInt(d.trim(),10)||0:0;return{ahead:s,behind:f}}catch{return{ahead:0,behind:0}}}}var f4={"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 ag{id="model";render(e){let o=e.model.id,i=f4[o]||this.simplifyModelName(e.model.display_name),a=Mr("model");return`${wn.model.icon}${a}${an.reset} ${wn.model.text}${i}${an.reset}`}simplifyModelName(e){let o=e.replace(/^Claude\s+/i,"");return o=o.replace(/-\d{8}$/,""),o}}fs();var g4=200000,R1=20000,m4=13000,E4="TAKO_MODEL_CONTEXT_WINDOW",C4="CLAUDE_CODE_AUTO_COMPACT_WINDOW";function h4(e,o=process.env[E4]){if(o){let i=Number(o);if(Number.isSafeInteger(i)&&i>0)return i}return gA(e)?.contextWindow??g4}function I4(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 B4(e){let o=e.context_window?.context_window_size;if(typeof o==="number"&&Number.isSafeInteger(o)&&o>0)return o;return h4(e.model.id)}function y4(e,o=process.env[C4]){if(o){let i=Number(o);if(Number.isSafeInteger(i)&&i>0)return Math.min(e,i)}return e}function D4(e,o=R1){let i=Math.min(Math.max(0,o),R1),a=Math.max(0,e-i);return Math.max(0,a-m4)}class _r{id="context";static cache=null;static CACHE_TTL=5000;async render(e){let i=I4(e)??await this.getTokensWithCache(e.transcript_path),a=B4(e),s=y4(a),u=D4(s);if(u<=0)return null;let d=Math.min(100,Math.max(0,Math.ceil((u-(i??0))/u*100))),p=Mr("context"),f=d<=20?xt.brightRed:d<=50?xt.brightYellow:xt.brightGreen;return`${wn.context.icon}${p}${an.reset} ${f}${d}%${an.reset}`}async getTokensWithCache(e){let o=Date.now();if(_r.cache&&_r.cache.path===e&&o-_r.cache.timestamp<_r.CACHE_TTL)return _r.cache.tokens;let i=await this.parseTranscriptTokens(e);return _r.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(`
861
+ `).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}}}lg();wi();class cg{id="quota";async render(e){let o=await this.tryRenderOfficial();if(o)return o;return this.renderSessionCost(e)}async tryRenderOfficial(){try{let e=await hs("claude-code")??await Qi();if(!e)return null;let o=await ug(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()} ${xt.brightGreen}Day:${this.fmtCost(a)}${an.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(`${an.dim} \xB7 ${an.reset}`)}`}renderClaudeSub=this.renderSub;renderCodexSub=this.renderSub;pctChunk(e,o){let i=o>=90?xt.brightRed:o>=70?xt.brightYellow:xt.brightGreen;return`${e}:${i}${o}%${an.reset}`}remainChunk(e,o){let i=Math.max(0,Math.min(100,100-Math.round(o))),a=i<=10?xt.brightRed:i<=30?xt.brightYellow:xt.brightGreen;return`${e} \u5269 ${a}${i}%${an.reset}`}renderSessionCost(e){let o=e.cost?.total_cost_usd;if(o==null||o<=0)return null;return`${this.icon()} ${xt.brightGreen}Session:${this.fmtCost(o)}${an.reset}`}icon(){return`${wn.todayUsage.icon}${Mr("todayUsage")}${an.reset}`}fmtCost(e){if(e>=100)return`$${Math.round(e)}`;if(e>=10)return`$${e.toFixed(1)}`;return`$${e.toFixed(2)}`}}class jh{separator=`${wn.separator} \u2502 ${an.reset}`;render(e){let o=["directory","git","model","context","quota"],i=[];for(let a of o){let s=e.get(a);if(s)i.push(s)}return i.join(this.separator)}}import{join as yA,dirname as O4}from"path";import{homedir as Vh}from"os";import{mkdir as U4}from"fs/promises";var z1=yA(Vh(),".tako"),G4=yA(z1,"cli"),H4=yA(z1,"bin",process.platform==="win32"?"tako.cmd":"tako");function P4(){if(process.platform==="win32")return yA(process.env.APPDATA||yA(Vh(),"AppData","Roaming"),"claude","settings.json");return yA(Vh(),".claude","settings.json")}var z4=process.platform==="win32",K4="0.1.48";function J4(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 Y4(){let e=yA(G4,"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 W4(){let e=await Y4();if(!e)return!1;return J4(e,K4)>=0}function j4(){return H4}function V4(){return`"${q4(j4())}" statusline`}function q4(e){if(z4)return e.replace(/\\/g,"/");return e}async function qh(){if(!await W4())return;let o=P4(),i={};try{let u=Bun.file(o);if(await u.exists())i=await u.json()}catch{}let a={type:"command",command:V4(),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 U4(O4(o),{recursive:!0}),await Bun.write(o,JSON.stringify(i,null,2))}var X4=[new ig,new rg,new ag,new _r,new cg];async function $4(e){let o=await Promise.all(X4.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 jh().render(i)}async function K1(){try{let e=await Bun.stdin.json(),o=await $4(e);console.log(o)}catch{process.exit(0)}}Xh();qf();Gc();Ph();async function DA(e,o,i,a){let s=o.filter((p)=>p!==i),u=await Hh(e,s,a);if(e==="grok"){let p=[];if(u)p.push(u);let f=!1;for(let m=0;m<s.length;m++){let h=s[m];if((h==="--model"||h==="-m")&&m+1<s.length){if(f){m++;continue}p.push("-m",xh(s[m+1])),f=!0,m++;continue}if(h.startsWith("--model=")){if(f)continue;p.push("-m",xh(h.slice(8))),f=!0;continue}p.push(h)}if(!f)p.unshift("-m",Xu($u));return p}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 f=s[p];if(f==="--model"&&p+1<s.length){d.push(f,Fr(s[p+1])),p++;continue}if(f.startsWith("--model=")){let m=f.slice(8);d.push(`--model=${Fr(m)}`);continue}d.push(f)}return d}fs();Zh();Kt();var $m="0.3.53",W9=!0;function j9(e){return W9&&!e}function V9(e){return e.replace(/\\/g,"/").includes("/cli/node_modules/tako-cli/")}async function PA(e){if(!j9(e))return;if(!V9(process.argv[1]??""))return;await p1()}function q9(){console.log(`
862
862
  ${Se("cli.version",{version:$m})}
863
863
 
864
864
  ${Se("cli.usage")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tako-cli",
3
- "version": "0.3.52",
3
+ "version": "0.3.53",
4
4
  "description": "Tako CLI — unified launcher for AI coding tools (Claude Code, Codex, Pi, Gemini, Grok Build) with multi-agent session management",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/tako-dev/cli#readme",