@codeflow-ai/cli 1.29.0 → 1.30.0

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/cli.js +31 -31
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,45 +1,45 @@
1
1
  #!/usr/bin/env node
2
- import{once as HC}from"events";import{createInterface as qC}from"readline/promises";import{parseArgs as GC}from"util";var km={name:"@codeflow-ai/cli",version:"1.29.0",type:"module",description:"CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF\uFF1A\u4E00\u952E\u914D\u7F6E AI \u5BA2\u6237\u7AEF",keywords:["codeflow","claude-code","codex","openclaw","hermes-agent","opencode","pi-coding-agent","cli"],license:"UNLICENSED",engines:{node:">=22"},bin:{codeflow:"dist/cli.js"},files:["dist"],publishConfig:{access:"public"},scripts:{dev:"tsx src/cli.ts",build:"tsup",typecheck:"tsc --noEmit"},dependencies:{"@decimalturn/toml-patch":"3.0.4",ink:"7.1.1",json5:"2.2.3","jsonc-parser":"3.3.1",marked:"18.0.9",qrcode:"1.5.4",react:"19.2.0","smol-toml":"1.9.0","string-width":"8.2.0",yaml:"2.9.1",zod:"4.4.3"},devDependencies:{"@codeflow/shared":"workspace:*","@types/node":"25.9.1","@types/qrcode":"1.5.6","@types/react":"19.2.2",tsup:"8.5.1",tsx:"4.22.3",typescript:"5.9.3"}};var zt="codeflow",Vt=km.version,vm="https://codeflow.asia",Bo="@codeflow-ai/cli",Cr=0,Fo=1,Wa=2,ro=3,Rm=4;import{randomBytes as sS}from"crypto";import{mkdirSync as Em,readFileSync as aS,rmSync as Mm,statSync as cS,writeFileSync as lS}from"fs";import{join as Im}from"path";import{setTimeout as mS}from"timers/promises";import{z as rn}from"zod";var j=class extends Error{exitCode;hint;constructor(t,n={}){super(t,{cause:n.cause}),this.name="CliError",this.exitCode=n.exitCode??Fo,this.hint=n.hint}};function xe(e){return e instanceof Error?e.message:String(e)}import{chmodSync as Zb,existsSync as eS,mkdirSync as tS,readFileSync as nS,writeFileSync as oS}from"fs";import{dirname as rS}from"path";function Nt(e){return eS(e)?nS(e,"utf8"):null}function wn(e,t,n){tS(rS(e),{recursive:!0,mode:448});try{oS(e,t,{mode:n}),Zb(e,n)}catch(o){throw new j(`\u5199\u5165 ${e} \u5931\u8D25\uFF1A${xe(o)}`,{cause:o})}}function Cm(e,t,n){wn(e,`${JSON.stringify(t,null,2)}
3
- `,n)}function Ai(e,t,n,o,r){let i=null,s=()=>{if(i)return i;let a=n(),c=Nt(a);if(c===null)return i=structuredClone(t),i;let l;try{l=JSON.parse(c)}catch(m){throw new j(`${o} ${a} \u5DF2\u635F\u574F\uFF0C\u8BF7\u5220\u9664\u8BE5\u6587\u4EF6\u540E${r}`,{cause:m})}let u=e.safeParse(l);if(!u.success)throw new j(`${o} ${a} \u7ED3\u6784\u4E0D\u7B26\uFF0C\u8BF7\u5220\u9664\u8BE5\u6587\u4EF6\u540E${r}`);return i=u.data,i};return{load:s,reload:()=>(i=null,s()),update:a=>{let c=structuredClone(s());return a(c),Cm(n(),c,384),i=c,c}}}import{homedir as iS}from"os";import{join as Uo}from"path";function kn(){let e=process.env.XDG_CONFIG_HOME;if(e)return Uo(e,"codeflow");if(process.platform==="win32"){let t=process.env.APPDATA;if(t)return Uo(t,"codeflow")}return Uo(iS(),".config","codeflow")}var _m=()=>Uo(kn(),"config.json"),Pm=()=>Uo(kn(),"credentials.json"),Am=()=>Uo(kn(),"refresh.lock");var uS=rn.object({refreshCookie:rn.string(),accessToken:rn.string(),accessExpiresAt:rn.number(),username:rn.string(),email:rn.string(),site:rn.string()}),dS=rn.object({site:rn.string(),cookie:rn.string()}),pS=rn.object({session:uS.nullable(),device:dS.nullable()}),za=Ai(pS,{session:null,device:null},Pm,"\u672C\u5730\u51ED\u636E","\u91CD\u65B0\u767B\u5F55"),Lt=za.load,Nm=za.reload,Va=za.update;function Lm(){let{session:e}=Lt();if(!e)throw new j("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return e}var fS=6e4,gS=75e3,hS=120;function yS(e,t){try{Em(e)}catch{try{Date.now()-cS(e).mtimeMs>fS&&Mm(e,{recursive:!0,force:!0})}catch{}return!1}return lS(Im(e,"owner"),t),!0}function bS(e,t){let n;try{n=aS(Im(e,"owner"),"utf8")}catch{return}n===t&&Mm(e,{recursive:!0,force:!0})}async function Om(e){let t=Am(),n=sS(16).toString("hex");Em(kn(),{recursive:!0,mode:448});let o=Date.now()+gS;for(;!yS(t,n);){if(Date.now()>o)throw new j(`\u7B49\u5F85\u5237\u65B0\u9501\u8D85\u65F6\uFF0C\u82E5\u786E\u8BA4\u6CA1\u6709\u5176\u4ED6 ${zt} \u5728\u8FD0\u884C\uFF0C\u8BF7\u5220\u9664 ${t}`);await mS(hS)}try{return await e()}finally{bS(t,n)}}function SS(){let e=process.env.CODEFLOW_SITE;if(e)return e;let t=Lt().session;return t?t.site:vm}function Dm(){return{site:SS()}}function io(e,t,n){if(!e.isTTY)return n;let o=Number.parseInt(t.slice(1),16);return`\x1B[38;2;${o>>16&255};${o>>8&255};${o&255}m${n}\x1B[39m`}import{existsSync as xx,rmSync as Tx}from"fs";import{z as qe}from"zod";var xS=["active","disabled"],__=qe.enum(xS),Ka=["subscription_first","balance_first","subscription_only","balance_only"],Ya=qe.enum(Ka),TS=["openai","anthropic"],$m=qe.enum(TS),wS=["openai-chat","openai-responses","anthropic-messages"],Bm=qe.enum(wS);var _r=["pending","paid","refund_requested","partially_refunded","refunded","failed","expired"],Fm=qe.enum(_r),kS=["recharge","subscription"],Ja=qe.enum(kS),vS=["requested","pending","succeeded","failed","rejected","canceled"],Um=qe.enum(vS),Xa=["pending","issued","rejected"],jm=qe.enum(Xa),RS=["special","general"],Qa=qe.enum(RS),CS=["info","success","warning","error"],Hm=qe.enum(CS),_S=["terms","privacy"],P_=qe.enum(_S),Za=["recharge","reserve","consume","reserve_refund","refund","refund_release","reward","admin_adjust"],qm=qe.enum(Za),PS=["usage_log","order","invitation","admin"],Gm=qe.enum(PS),ec=["first_inviter","first_invitee","subsequent_inviter"],Wm=qe.enum(ec),tc=["success","error","canceled","anomaly"],zm=qe.enum(tc),nc=["open","replied","closed"],Vm=qe.enum(nc),oc=["billing","technical","account","other"],Km=qe.enum(oc),rc=["low","normal","high"],Ym=qe.enum(rc),AS=["user","admin"],Jm=qe.enum(AS),ES=["pending","published","rejected","removed"],Pr=qe.enum(ES),ic=["activity","published"],Xm=qe.enum(ic),Ei=["spam","abuse","explicit","illegal","privacy","other"],Qm=qe.enum(Ei),MS=["none","minor","major","critical"],Zm=qe.enum(MS);import{z as jo}from"zod";var IS=["internal_error","validation_error","not_found","conflict","rate_limited","forbidden","unauthorized","invalid_credentials","password_incorrect","account_disabled","email_already_registered","username_taken","verification_code_invalid","verification_code_expired","token_expired","token_reuse_detected","token_limit_exceeded","totp_invalid","totp_replayed","totp_setup_expired","totp_not_enabled","login_ticket_invalid","recovery_code_invalid","passkey_registration_failed","passkey_verification_failed","passkey_not_found","passkey_origin_not_allowed","insufficient_quota","no_available_channel","model_not_found","model_not_in_group","token_group_missing","token_quota_exceeded","upstream_error","order_not_found","order_not_payable","payment_verify_failed","payment_precreate_failed","amount_mismatch","refund_not_allowed","refund_amount_invalid","refund_insufficient_balance","refund_failed","refund_pending","refund_in_progress","refund_blocked_by_pending_order","refund_order_superseded","refund_request_not_found","refund_nothing_refundable","subscription_limit_reached","no_subscription_coverage","subscription_revoked","plan_disabled","order_already_invoiced","order_not_eligible","order_invoiced","invoice_profile_exists","invite_code_invalid","ticket_closed","ticket_limit_exceeded","attachment_storage_unconfigured","attachment_too_large","attachment_image_too_large","attachment_invalid","attachment_staging_limit_exceeded","docs_not_configured","docs_source_unavailable","docs_page_not_found","provider_status_unavailable","community_muted","community_state_changed","community_category_missing"],NS=jo.enum(IS),eu=jo.object({error:jo.object({code:NS,message:jo.string(),details:jo.unknown().optional(),requestId:jo.string().optional()})});var tu={internal_error:"\u670D\u52A1\u6682\u65F6\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",validation_error:"\u63D0\u4EA4\u7684\u5185\u5BB9\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5",not_found:"\u8BBF\u95EE\u7684\u5185\u5BB9\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",conflict:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u8BB0\u5F55\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4",rate_limited:"\u64CD\u4F5C\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",forbidden:"\u6CA1\u6709\u6743\u9650\u6267\u884C\u6B64\u64CD\u4F5C",unauthorized:"\u8BF7\u5148\u767B\u5F55",invalid_credentials:"\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E",password_incorrect:"\u5F53\u524D\u5BC6\u7801\u4E0D\u6B63\u786E",account_disabled:"\u8D26\u6237\u5DF2\u88AB\u7981\u7528\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",email_already_registered:"\u8BE5\u90AE\u7BB1\u5DF2\u88AB\u6CE8\u518C",username_taken:"\u8BE5\u7528\u6237\u540D\u5DF2\u88AB\u4F7F\u7528",verification_code_invalid:"\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E",verification_code_expired:"\u9A8C\u8BC1\u7801\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u83B7\u53D6",token_expired:"\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_reuse_detected:"\u767B\u5F55\u72B6\u6001\u5F02\u5E38\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_limit_exceeded:"\u4EE4\u724C\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5220\u9664\u4E0D\u518D\u4F7F\u7528\u7684\u4EE4\u724C",totp_invalid:"\u52A8\u6001\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E\uFF0C\u8BF7\u91CD\u8BD5",totp_replayed:"\u8BE5\u9A8C\u8BC1\u7801\u521A\u521A\u5DF2\u88AB\u4F7F\u7528\uFF0C\u8BF7\u7B49\u5F85\u9A8C\u8BC1\u5668\u663E\u793A\u4E0B\u4E00\u4E2A\u9A8C\u8BC1\u7801\u540E\u518D\u8F93\u5165",totp_setup_expired:"\u7ED1\u5B9A\u4F1A\u8BDD\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5F00\u59CB\u7ED1\u5B9A",totp_not_enabled:"\u5C1A\u672A\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",login_ticket_invalid:"\u767B\u5F55\u9A8C\u8BC1\u5DF2\u8FC7\u671F\u6216\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",recovery_code_invalid:"\u6062\u590D\u7801\u4E0D\u6B63\u786E\u6216\u5DF2\u88AB\u4F7F\u7528",passkey_registration_failed:"Passkey \u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_verification_failed:"Passkey \u9A8C\u8BC1\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_not_found:"\u8BE5 Passkey \u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",passkey_origin_not_allowed:"\u5F53\u524D\u8BBF\u95EE\u5730\u5740\u672A\u914D\u7F6E\u4E3A\u7AD9\u70B9\u5730\u5740\uFF0C\u65E0\u6CD5\u4F7F\u7528 Passkey",insufficient_quota:"\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u8BD5",no_available_channel:"\u4E0A\u6E38\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",model_not_found:"\u8BE5\u6A21\u578B\u4E0D\u5B58\u5728",model_not_in_group:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u4E0D\u652F\u6301\u8BE5\u6A21\u578B\uFF0C\u8BF7\u66F4\u6362\u4EE4\u724C\u5206\u7EC4\u6216\u6539\u7528\u5206\u7EC4\u652F\u6301\u7684\u6A21\u578B",token_group_missing:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BF7\u7F16\u8F91\u4EE4\u724C\u91CD\u65B0\u9009\u62E9\u5206\u7EC4",token_quota_exceeded:"\u8BE5\u4EE4\u724C\u7684\u6D88\u8D39\u5DF2\u8FBE\u8D39\u7528\u9650\u5236\uFF0C\u8BF7\u8C03\u9AD8\u6216\u6E05\u9664\u9650\u5236\u540E\u518D\u4F7F\u7528",upstream_error:"\u4E0A\u6E38\u670D\u52A1\u8FD4\u56DE\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",order_not_found:"\u8BA2\u5355\u4E0D\u5B58\u5728",order_not_payable:"\u8BA2\u5355\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u518D\u8BD5",payment_verify_failed:"\u652F\u4ED8\u7ED3\u679C\u786E\u8BA4\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",payment_precreate_failed:"\u53D1\u8D77\u652F\u4ED8\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",amount_mismatch:"\u652F\u4ED8\u91D1\u989D\u4E0E\u8BA2\u5355\u4E0D\u7B26\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",refund_not_allowed:"\u8BE5\u8BA2\u5355\u5F53\u524D\u4E0D\u53EF\u9000\u6B3E",refund_amount_invalid:"\u9000\u6B3E\u91D1\u989D\u4E0D\u6B63\u786E\u6216\u8D85\u8FC7\u53EF\u9000\u4F59\u989D",refund_insufficient_balance:"\u53EF\u7528\u989D\u5EA6\u4E0D\u8DB3\u4EE5\u6263\u56DE\u672C\u6B21\u9000\u6B3E\uFF08\u5DF2\u6D88\u8017\u90E8\u5206\u5BF9\u5E94\u7684\u73B0\u91D1\u4E0D\u53EF\u9000\uFF09",refund_failed:"\u652F\u4ED8\u5B9D\u9000\u6B3E\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u68C0\u67E5\u652F\u4ED8\u5B9D\u5546\u6237\u540E\u53F0",refund_pending:"\u9000\u6B3E\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u8BF7\u7A0D\u540E\u67E5\u770B\u9000\u6B3E\u8BB0\u5F55",refund_in_progress:"\u8BE5\u8BA2\u5355\u6216\u8BA2\u9605\u6709\u9000\u6B3E\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u5F85\u5176\u5B8C\u6210\u540E\u518D\u64CD\u4F5C",refund_blocked_by_pending_order:"\u8BE5\u8BA2\u9605\u6709\u5F85\u652F\u4ED8\u7684\u7EED\u8D39\u8BA2\u5355\uFF0C\u8BF7\u5F85\u5176\u652F\u4ED8\u6216\u8D85\u65F6\u540E\u518D\u9000\u6B3E",refund_order_superseded:"\u5B58\u5728\u66F4\u665A\u5165\u8D26\u7684\u8BA2\u5355\uFF0C\u8BF7\u6309\u4ECE\u65B0\u5230\u65E7\u7684\u987A\u5E8F\u9000\u6B3E",refund_request_not_found:"\u9000\u6B3E\u7533\u8BF7\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5904\u7406\uFF0C\u8BF7\u5237\u65B0\u540E\u67E5\u770B",refund_nothing_refundable:"\u8BE5\u8BA2\u9605\u8BA2\u5355\u6309\u9650\u989D\u5468\u671F\u8BA1\u8D39\u540E\u5DF2\u65E0\u53EF\u9000\u91D1\u989D",subscription_limit_reached:"\u8BA2\u9605\u989D\u5EA6\u5DF2\u7528\u5C3D\uFF0C\u8BF7\u7B49\u5F85\u7A97\u53E3\u91CD\u7F6E",no_subscription_coverage:"\u5F53\u524D\u5206\u7EC4\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\uFF0C\u8BF7\u8BA2\u9605\u5957\u9910\u6216\u8C03\u6574\u6263\u8D39\u65B9\u5F0F",subscription_revoked:"\u8BE5\u8BA2\u9605\u5DF2\u88AB\u4F5C\u5E9F",plan_disabled:"\u8BE5\u5957\u9910\u5DF2\u505C\u552E",order_already_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u7533\u8BF7\u8FC7\u53D1\u7968",order_not_eligible:"\u6240\u9009\u8BA2\u5355\u4E0D\u7B26\u5408\u5F00\u7968\u6761\u4EF6",order_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u5F00\u7968\u6216\u6709\u672A\u5904\u7406\u7684\u5F00\u7968\u7533\u8BF7\uFF0C\u65E0\u6CD5\u9000\u6B3E",invoice_profile_exists:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u5E38\u7528\u5F00\u7968\u4FE1\u606F",invite_code_invalid:"\u9080\u8BF7\u7801\u65E0\u6548",ticket_closed:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u8BF7\u5148\u91CD\u65B0\u6253\u5F00\u540E\u518D\u56DE\u590D",ticket_limit_exceeded:"\u672A\u5173\u95ED\u7684\u5DE5\u5355\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5173\u95ED\u5DF2\u89E3\u51B3\u7684\u5DE5\u5355",attachment_storage_unconfigured:"\u5C1A\u672A\u914D\u7F6E\u9644\u4EF6\u5B58\u50A8",attachment_too_large:"\u9644\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236",attachment_image_too_large:"\u56FE\u7247\u5C3A\u5BF8\u6216\u5E27\u6570\u8D85\u8FC7\u9650\u5236",attachment_invalid:"\u9644\u4EF6\u65E0\u6548\u6216\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20",attachment_staging_limit_exceeded:"\u5F85\u63D0\u4EA4\u7684\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u63D0\u4EA4\u73B0\u6709\u9644\u4EF6",docs_not_configured:"\u6587\u6863\u4E2D\u5FC3\u672A\u542F\u7528",docs_source_unavailable:"\u6587\u6863\u5185\u5BB9\u83B7\u53D6\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",docs_page_not_found:"\u8BE5\u6587\u6863\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",provider_status_unavailable:"\u5B98\u65B9\u670D\u52A1\u72B6\u6001\u6682\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",community_muted:"\u8D26\u53F7\u5904\u4E8E\u7981\u8A00\u671F\u95F4\uFF0C\u6682\u65F6\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D",community_state_changed:"\u5185\u5BB9\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5",community_category_missing:"\u6240\u9009\u677F\u5757\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9"};import{z as Ho}from"zod";var LS=Ho.string().trim().min(1),sc=LS.pipe(Ho.url()),OS=Ho.object({name:Ho.string().trim().min(1),description:Ho.string().trim().min(1),url:sc}),L_=Ho.array(OS);function nu(e){return`codeflow-cli/${e.cliVersion} (${e.platform} ${e.release}; ${e.arch}) node/${e.nodeVersion}`}function qo(e){if(!e)return"\u672A\u77E5\u8BBE\u5907";let t=e.type==="cli"?e.clientVersion:e.clientVersion?.split(".")[0],o=[e.client?t?`${e.client} ${t}`:e.client:null,e.os].filter(r=>r!==null);return o.length>0?o.join(" \xB7 "):"\u672A\u77E5\u8BBE\u5907"}import{z as dn}from"zod";var ac=1e8;var B_=dn.object({id:dn.coerce.number().int().positive()}),ou=100,ru=dn.object({page:dn.coerce.number().int().min(1)});function lt(e){return dn.object({items:dn.array(e),total:dn.number()})}var se=dn.object({ok:dn.literal(!0)}),iu=(e=dn.string().trim())=>e.nullable().optional().transform(t=>t==null||t.length===0?null:t);import{z as ae}from"zod";var so=ae.email().max(254).toLowerCase(),Ot=8,Ar=ae.string().min(Ot).max(128),Er=ae.string().min(1).max(128),Kt=32,cc=ae.string().trim().min(1).max(Kt),lc=ae.string().trim().min(1).max(254),j_=ae.object({email:so}),H_=ae.object({username:cc,email:so,password:Ar,code:ae.string().min(4).max(8),inviteCode:ae.string().trim().min(1).max(32).optional()}),q_=ae.object({account:lc,password:Er}),G_=ae.object({email:so,code:ae.string().min(4).max(8),password:Ar}),W_=ae.object({oldPassword:Er,newPassword:Ar}),z_=ae.object({email:so}),V_=ae.object({email:so,code:ae.string().min(4).max(8),password:Er}),su=ae.object({username:ae.string(),email:ae.string(),avatarUrl:ae.string().nullable()}),Go=ae.object({accessToken:ae.string(),user:su}),au=ae.discriminatedUnion("status",[Go.extend({status:ae.literal("ok")}),ae.object({status:ae.literal("totp_required"),ticket:ae.string()})]),cu=ae.object({user:su}),mc=ae.object({client:ae.string().nullable(),clientVersion:ae.string().nullable(),os:ae.string().nullable(),osVersion:ae.string().nullable(),type:ae.string().nullable(),vendor:ae.string().nullable(),model:ae.string().nullable()}),DS=ae.object({id:ae.number().int(),ip:ae.string(),userAgent:ae.string().nullable(),device:mc.nullable(),loginAt:ae.string(),lastActiveAt:ae.string(),expiresAt:ae.string(),current:ae.boolean()}),lu=ae.object({sessions:ae.array(DS)});import{z as ke}from"zod";var Wo=ke.string().trim().length(6),$S=ke.string().trim().min(10).max(20),Mi=ke.string().trim().min(1).max(64),Ii=ke.record(ke.string(),ke.unknown()),J_=ke.object({ticket:ke.string().min(1),code:Wo}),X_=ke.object({ticket:ke.string().min(1),code:$S}),Q_=ke.object({code:Wo.optional()}),Z_=ke.object({code:Wo}),mu=ke.object({secret:ke.string(),otpauthUri:ke.string()}),uc=ke.object({recoveryCodes:ke.array(ke.string())}),BS=ke.object({id:ke.number().int(),name:ke.string(),createdAt:ke.string(),lastUsedAt:ke.string().nullable()}),uu=ke.object({totp:ke.object({enabled:ke.boolean(),enabledAt:ke.string().nullable(),recoveryCodesRemaining:ke.number().int()}),passkeys:ke.array(BS)}),e0=ke.object({name:Mi,response:Ii}),t0=ke.object({name:Mi}),n0=ke.object({response:Ii});import{z as Le}from"zod";var a0=Le.object({account:lc,password:Er}),FS=Le.object({totp:Le.boolean(),passkeys:Le.boolean()}),c0=Le.discriminatedUnion("status",[Le.object({status:Le.literal("totp_required"),ticket:Le.string()}),Le.object({status:Le.literal("setup_required"),ticket:Le.string(),missing:FS})]),l0=Le.object({ticket:Le.string().min(1)}),m0=Le.object({ticket:Le.string().min(1),code:Wo}),u0=Le.object({ticket:Le.string().min(1),name:Mi,response:Ii}),d0=Le.object({ticket:Le.string().min(1),code:Wo.optional()}),du=Le.object({username:Le.string(),email:Le.string(),avatarUrl:Le.string().nullable()}),p0=Le.object({accessToken:Le.string(),admin:du}),f0=Le.object({admin:du});import{z as dc}from"zod";var S0=dc.object({siteName:dc.string().trim().min(1).max(64),siteDescription:dc.string().trim().max(200).optional(),siteOrigin:sc,username:cc,email:so,password:Ar});import{z as Fe}from"zod";var pu={orderNo:Fe.string(),amountCny:Fe.number().int(),status:Fm,credited:Fe.boolean(),refundedAmountCny:Fe.number().int(),succeededRefundCny:Fe.number().int(),pendingRefundCny:Fe.number().int(),createdAt:Fe.string()},Mr=Fe.object({...pu,quota:Fe.number(),refundedQuota:Fe.number()}),Ir=Fe.object({...pu,planName:Fe.string(),renewal:Fe.boolean(),grantedDurationDays:Fe.number().int()}),Ni=Fe.object({order:Mr.pick({orderNo:!0,amountCny:!0,quota:!0}),qrCode:Fe.string()}),Nr=Fe.object({order:Ir.pick({orderNo:!0,amountCny:!0,planName:!0,grantedDurationDays:!0}),qrCode:Fe.string()}),fu=Fe.object({id:Fe.number().int(),amountCny:Fe.number().int(),status:Um,refundTradeNo:Fe.string().nullable(),reason:Fe.string().nullable(),rejectReason:Fe.string().nullable(),createdAt:Fe.string()});function gu(e){return e.status!=="paid"&&e.status!=="partially_refunded"||e.pendingRefundCny>0?!1:e.kind==="recharge"?e.refundedAmountCny<e.amountCny:e.refundedAmountCny===0}import{z as mt}from"zod";import{z as Yt}from"zod";var pc=Yt.object({kind:Yt.literal("user"),username:Yt.string(),avatarUrl:Yt.string().nullable(),points:Yt.number().int()}),fc=Yt.object({kind:Yt.literal("admin"),username:Yt.string(),avatarUrl:Yt.string().nullable()}),zo=Yt.discriminatedUnion("kind",[pc,fc]),hu=Yt.object({kind:Jm,username:Yt.string()});var Li=mt.object({id:mt.number().int(),title:mt.string(),category:Km,priority:Ym,status:Vm,createdAt:mt.string(),updatedAt:mt.string()}),yu=Li.pick({id:!0}),bu=25*1024*1024,Su=5,xu=mt.object({id:mt.number().int(),fileName:mt.string(),fileSize:mt.number().int(),contentType:mt.string()}),Tu=xu.pick({id:!0,fileSize:!0}),US=mt.object({id:mt.number().int(),author:zo,content:mt.string(),attachments:mt.array(xu),createdAt:mt.string()}),wu=mt.object({ticket:Li,messages:mt.array(US)});import{z as Lr}from"zod";var gc=Lr.object({id:Lr.number().int(),title:Lr.string(),content:Lr.string(),level:Hm,publishedAt:Lr.string()});import{z as Xe}from"zod";var hc=100,ku=Xe.object({groups:Xe.array(Xe.object({title:Xe.string(),items:Xe.array(Xe.object({slug:Xe.string(),title:Xe.string()}))}))}),vu=Xe.object({title:Xe.string(),markdown:Xe.string(),images:Xe.record(Xe.string(),Xe.object({width:Xe.number().int(),height:Xe.number().int()}))}),Ru=Xe.object({slug:Xe.string(),title:Xe.string(),anchor:Xe.string().nullable(),snippet:Xe.string()});function Cu(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-")}function yc(e){try{return decodeURIComponent(e)}catch{return e}}function Oi(e){if(!e.startsWith("/guides/"))return null;let t=e.indexOf("#");return{slug:(t===-1?e:e.slice(0,t)).slice(8,-3),anchor:t===-1?null:yc(e.slice(t+1))}}import{z as ot}from"zod";function Oe(e){return e.toLocaleString("en-US")}function qn(e){let t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(1)}B`:t>=1e6?`${(e/1e6).toFixed(1)}M`:t>=1e3?`${(e/1e3).toFixed(1)}k`:Oe(e)}function pn(e,t){return e===0&&t!==void 0?t:e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:6})}function ao(e){return(e/1e3).toFixed(2)}function Vo(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${(e/1024**2).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Di(e,t){return`${e}******${t}`}var bc=ot.object({inputPricePerMillionTokens:ot.number(),outputPricePerMillionTokens:ot.number(),cachedInputPricePerMillionTokens:ot.number(),cacheWritePricePerMillionTokens:ot.number()});var jS=ot.number().int().nonnegative(),HS=ot.discriminatedUnion("kind",[bc.extend({kind:ot.literal("price"),inputTokensOver:jS}),ot.object({kind:ot.literal("multiplier"),param:ot.string(),value:ot.string(),multiplier:ot.number()})]),_u=ot.array(HS);function qS(e){return e.kind==="price"}function Pu(e){return e.kind==="multiplier"}function Au(e){return e>=1e6&&e%1e5===0?`${e/1e6}M`:e>=1e3&&e%1e3===0?`${e/1e3}k`:Oe(e)}function Or(e){return e===null?"\u57FA\u7840":"\u6269\u5C55"}function Sc(e){return`> ${Au(e)}`}function Eu(e,t){let n=t.filter(qS).sort((r,i)=>r.inputTokensOver-i.inputTokensOver),o=n[0];return o===void 0?[{name:Or(null),range:null,price:e}]:[{name:Or(null),range:`\u2264 ${Au(o.inputTokensOver)}`,price:e},...n.map(r=>({name:Or(r.inputTokensOver),range:Sc(r.inputTokensOver),price:r}))]}var GS=ot.object({value:ot.string(),multiplier:ot.number()}),Mu=ot.array(GS);function Iu(e){return Lu(e.map(t=>t.multiplier))}function Nu(e,t){return Lu([e,...t.map(n=>n.multiplier)])}function Lu(e){return Number(e.reduce((t,n)=>t*n,1).toFixed(4))}import{z as co}from"zod";var WS=co.object({provider:$m,pageUrl:co.string(),indicator:Zm,incidents:co.array(co.object({title:co.string()}))}),Ou=co.object({providers:co.array(WS)}),zS={minor:{label:"\u90E8\u5206\u964D\u7EA7",tone:"warning"},major:{label:"\u90E8\u5206\u4E2D\u65AD",tone:"danger"},critical:{label:"\u4E25\u91CD\u4E2D\u65AD",tone:"danger"}};function Du(e){return e.filter(t=>t.indicator!=="none"||t.incidents.length>0)}function $u(e){return e.indicator==="none"?{label:"\u4E8B\u4EF6\u5904\u7406\u4E2D",tone:"warning"}:zS[e.indicator]}import{z as lo}from"zod";var Dr=25*1024*1024,Bu=20,Fu=5;var xc="/api/media/";function Uu(e){return`${xc}${e}`}var ju=lo.object({width:lo.number().int(),height:lo.number().int()}),$i=lo.record(lo.string(),ju),Hu=lo.object({id:lo.number().int(),image:ju.nullable()}),qu=String.raw`([1-9]\d{0,14})`,G0=new RegExp(String.raw`^${xc}${qu}$`),Gu=new RegExp(String.raw`(!?)\[((?:\\.|[^\\\]\n])*)\]\(${xc}${qu}(?:\s+"[^"\n]*")?\)`,"g");function Wu(e,t,n){return{id:Number(n),image:e==="!",name:t.replace(/\\(.)/g,"$1")}}function zu(e){return[...e.matchAll(Gu)].map(([,t="",n="",o=""])=>Wu(t,n,o))}function Tc(e,t){return e.replace(Gu,(n,o,r,i)=>t(Wu(o,r,i)))}import{z as ut}from"zod";import{z as I}from"zod";var mo=100,Bi=2e4,wc=5e3,Fi=500,Ui=64,VS=new RegExp("\\p{Cc}","u"),KS=new RegExp("(?![\\n\\t])\\p{Cc}","u");function kc(e){return I.string().trim().max(e).refine(t=>!VS.test(t))}function vc(e){return I.string().trim().max(e).refine(t=>!KS.test(t))}var Q0=I.object({categoryId:I.number().int().positive(),title:kc(mo).min(1),content:vc(Bi).min(1)}),Z0=I.object({categoryId:I.number().int().positive().nullable(),title:kc(mo),content:vc(Bi)}),eP=I.object({content:vc(wc).min(1),replyToId:I.number().int().positive().optional()}),tP=I.object({reason:Qm,detail:iu(kc(Fi))}),nP=ru.extend({sort:Xm,categoryId:I.coerce.number().int().positive().optional(),q:I.string().trim().min(1).max(Ui).optional(),author:I.string().trim().min(1).max(Kt).optional()}),Rc=I.object({id:I.number().int(),name:I.string(),description:I.string()}),ji=Rc.pick({id:!0,name:!0}),$r=I.object({id:I.number().int(),title:I.string()}),Ko=I.object({id:I.number().int(),title:I.string().nullable()}),oP=I.object({posts:I.array(I.object({id:I.number().int(),lastModified:I.string()})),users:I.array(I.string()),staff:I.array(I.string())}),Cc=I.object({id:I.number().int(),title:I.string(),category:ji,author:zo,commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),lastActivityAt:I.string()}),Vu=I.object({id:I.number().int(),title:I.string(),content:I.string(),images:$i,category:ji,author:zo,status:Pr,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),coverUrl:I.string().nullable(),createdAt:I.string(),publishedAt:I.string().nullable(),editedAt:I.string().nullable(),liked:I.boolean(),bookmarked:I.boolean()}),Ku={id:I.number().int(),author:zo,content:I.string(),images:$i,status:Pr,reviewReason:I.string().nullable(),likeCount:I.number().int(),liked:I.boolean(),createdAt:I.string()},_c=I.object({...Ku,replyTo:I.object({id:I.number().int(),author:hu}).nullable()}),Pc=I.object({...Ku,floor:I.number().int().nullable(),replyCount:I.number().int(),replies:I.array(_c)}),Ac=I.object({likeCount:I.number().int()}),Br=I.object({id:I.number().int(),status:I.enum(["pending","published","rejected"]),reviewReason:I.string().nullable()}),Fr=I.object({id:I.number().int(),title:I.string(),category:ji,status:Pr,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),createdAt:I.string(),publishedAt:I.string().nullable()}),Hi=I.object({id:I.number().int(),content:I.string(),post:Ko,floorId:I.number().int(),status:Pr,reviewReason:I.string().nullable(),likeCount:I.number().int(),createdAt:I.string()}),Ec=I.object({id:I.number().int(),category:ji.nullable(),title:I.string(),content:I.string(),images:$i,createdAt:I.string()}),Yu=I.object({posts:I.array(Fr),drafts:I.number().int()}),Ju=Ec.pick({id:!0}),Xu=I.object({muted:I.object({reason:I.string(),until:I.string().nullable()}).nullable()});var YS=ut.object({posts:ut.number().int(),comments:ut.number().int(),likesReceived:ut.number().int()}),JS=ut.object({start:ut.string(),end:ut.string(),days:ut.array(ut.object({day:ut.string(),count:ut.number().int()}))}),XS=ut.object({posts:ut.array(Fr),comments:ut.array(Hi)}),Qu={joinedAt:ut.string(),stats:YS,activity:JS,overview:XS},Zu=ut.object({identity:pc,...Qu}),ed=ut.object({identity:fc,...Qu});import{z as J}from"zod";var gt={id:J.number().int(),read:J.boolean(),createdAt:J.string()},Ur=J.object({floorId:J.number().int()}),td=J.object({username:J.string()}),nd=J.discriminatedUnion("kind",[J.object({...gt,kind:J.literal("post_commented"),post:$r,comment:Ur,actor:td}),J.object({...gt,kind:J.literal("comment_replied"),post:Ko,comment:Ur,actor:td}),J.object({...gt,kind:J.literal("post_approved"),post:$r}),J.object({...gt,kind:J.literal("post_rejected"),post:$r,reason:J.string()}),J.object({...gt,kind:J.literal("post_removed"),post:$r,reason:J.string()}),J.object({...gt,kind:J.literal("comment_approved"),post:Ko,comment:Ur}),J.object({...gt,kind:J.literal("comment_rejected"),post:Ko,comment:Ur,reason:J.string()}),J.object({...gt,kind:J.literal("comment_removed"),post:Ko,comment:Ur,reason:J.string()}),J.object({...gt,kind:J.literal("ticket_replied"),ticket:J.object({id:J.number().int(),title:J.string()})}),J.object({...gt,kind:J.literal("invoice_issued"),invoice:J.object({title:J.string(),amountCny:J.number().int()})}),J.object({...gt,kind:J.literal("invoice_rejected"),invoice:J.object({title:J.string()}),reason:J.string()}),J.object({...gt,kind:J.literal("refund_approved"),refund:J.object({orderNo:J.string(),orderType:Ja,amountCny:J.number().int()})}),J.object({...gt,kind:J.literal("refund_rejected"),refund:J.object({orderNo:J.string(),orderType:Ja}),reason:J.string()}),J.object({...gt,kind:J.literal("subscription_expiring"),subscription:J.object({planName:J.string(),expiresAt:J.string()})}),J.object({...gt,kind:J.literal("email_changed"),newEmail:J.string()}),J.object({...gt,kind:J.literal("new_device_login"),ip:J.string(),device:mc.nullable()})]),od=J.object({unread:J.boolean()});var rd="Asia/Shanghai",QS="+08:00";function ZS(e){return new Date(new Date(e).getTime()+288e5)}function ex(e=Date.now()){let t=ZS(e);return{day:t.toISOString().slice(0,10),hour:t.getUTCHours()}}function Mc(e=Date.now()){return ex(e).day}function Ic(e=Mc()){return new Date(`${e}T00:00:00${QS}`)}function Gn(e,t){let n=new Date(`${e}T00:00:00Z`);return new Date(n.getTime()+t*864e5).toISOString().slice(0,10)}var tx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium",timeZone:rd}),nx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"long",timeZone:rd});function V(e){return tx.format(new Date(e))}function jr(e){return nx.format(new Date(e))}var[ox,...rx]=[{min:0,name:"\u65B0\u624B"},{min:20,name:"\u5165\u95E8"},{min:100,name:"\u8FDB\u9636"},{min:300,name:"\u719F\u7EC3"},{min:800,name:"\u9AD8\u624B"},{min:2e3,name:"\u4E13\u5BB6"},{min:5e3,name:"\u5927\u5E08"}];function qi(e){let t=1,n=ox;for(let o of rx){if(e<o.min)return{level:t,name:n.name,min:n.min,next:o.min};t+=1,n=o}return{level:t,name:n.name,min:n.min,next:null}}function Gi(e){let t=qi(e);return`Lv.${t.level} ${t.name}`}function Wi(e){let t=qi(e);return t.next===null?"\u5DF2\u8FBE\u6700\u9AD8\u7B49\u7EA7":`\u8DDD Lv.${t.level+1} \u8FD8\u5DEE ${t.next-e} \u79EF\u5206`}var zi="\u7BA1\u7406\u5458",Hr={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4FEE\u6539\u540E\u53EF\u91CD\u65B0\u63D0\u4EA4",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1\u4E14\u65E0\u6CD5\u4FEE\u6539"},Yo={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1"};function Nc(e,t){if(t.status==="published")return null;let n=e[t.status];return t.reviewReason===null?n:`${n}\uFF0C\u539F\u56E0\uFF1A${t.reviewReason}`}var Vi="\u8BE5\u5E16\u5B50\u6682\u4E0D\u53EF\u89C1",ix=4;function id(e){let t=[],n=new Map;for(let o of e){let r=o.replyTo===null?void 0:n.get(o.replyTo.id),i={reply:o,mention:r===void 0&&o.replyTo!==null?o.replyTo.author:null,children:[]};n.set(o.id,i),r===void 0?t.push(i):r.children.push(i)}return sd(t,1)}function sd(e,t){return t<ix?e.map(n=>({...n,children:sd(n.children,t+1)})):e.flatMap(n=>[{...n,children:[]},...ad(n)])}function ad(e){return e.children.flatMap(t=>[{reply:t.reply,mention:e.reply.author,children:[]},...ad(t)])}function Lc(e){return`${e===null?"\u4F60\u5DF2\u88AB\u6C38\u4E45\u7981\u8A00":`\u4F60\u5DF2\u88AB\u7981\u8A00\u81F3 ${V(e)}`}\uFF0C\u671F\u95F4\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D`}function Re(e){let t=e/100;return`${t<0?"-":""}\xA5${Math.abs(t).toFixed(2)}`}function Oc(e){return Math.round(e*100)}function cd(e){return e/100}function ld(e,t,n){let o=e/t;return`${o<0?"-":""}$${Math.abs(o).toLocaleString("en-US",{minimumFractionDigits:n,maximumFractionDigits:n})}`}function Te(e,t){return ld(e,t,2)}function Jo(e,t){return ld(e,t,6)}var ud={post:"\u67E5\u770B\u5E16\u5B50",floor:"\u67E5\u770B\u8BC4\u8BBA",ticket:"\u67E5\u770B\u5DE5\u5355",invoices:"\u67E5\u770B\u53D1\u7968",recharge:"\u67E5\u770B\u5145\u503C\u8BB0\u5F55",subscription:"\u67E5\u770B\u8BA2\u9605",security:"\u67E5\u770B\u8D26\u6237"};function md(e){return e==="subscription"?{kind:"subscription"}:{kind:"recharge"}}function Dc(e){return e.title===null?"":`\u300C${e.title}\u300D\u4E0B\u7684`}function $c(e){switch(e.kind){case"post_commented":return{title:`${e.actor.username} \u8BC4\u8BBA\u4E86\u4F60\u7684\u5E16\u5B50`,body:`\u300C${e.post.title}\u300D`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_replied":return{title:`${e.actor.username} \u56DE\u590D\u4E86\u4F60\u7684\u8BC4\u8BBA`,body:e.post.title===null?Vi:`\u300C${e.post.title}\u300D`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"post_approved":return{title:"\u5E16\u5B50\u5DF2\u901A\u8FC7\u5BA1\u6838",body:`\u300C${e.post.title}\u300D\u5DF2\u516C\u5F00\u53D1\u5E03`,target:{kind:"post",postId:e.post.id}};case"post_rejected":return{title:"\u5E16\u5B50\u672A\u901A\u8FC7\u5BA1\u6838",body:`\u300C${e.post.title}\u300D\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u4FEE\u6539\u540E\u53EF\u91CD\u65B0\u63D0\u4EA4`,target:{kind:"post",postId:e.post.id}};case"post_removed":return{title:"\u5E16\u5B50\u5DF2\u88AB\u5C4F\u853D",body:`\u300C${e.post.title}\u300D\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"post",postId:e.post.id}};case"comment_approved":return{title:"\u8BC4\u8BBA\u5DF2\u901A\u8FC7\u5BA1\u6838",body:`${Dc(e.post)}\u8BC4\u8BBA\u5DF2\u516C\u5F00\u53D1\u5E03`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_rejected":return{title:"\u8BC4\u8BBA\u672A\u901A\u8FC7\u5BA1\u6838",body:`${Dc(e.post)}\u8BC4\u8BBA\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_removed":return{title:"\u8BC4\u8BBA\u5DF2\u88AB\u5C4F\u853D",body:`${Dc(e.post)}\u8BC4\u8BBA\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"ticket_replied":return{title:"\u5DE5\u5355\u6709\u65B0\u56DE\u590D",body:`\u5DE5\u5355\u300C${e.ticket.title}\u300D\u6536\u5230\u7BA1\u7406\u5458\u56DE\u590D`,target:{kind:"ticket",ticketId:e.ticket.id}};case"invoice_issued":return{title:"\u53D1\u7968\u5DF2\u5F00\u5177",body:`\u62AC\u5934\u300C${e.invoice.title}\u300D\u91D1\u989D ${Re(e.invoice.amountCny)} \u7684\u53D1\u7968\u5DF2\u5F00\u5177`,target:{kind:"invoices"}};case"invoice_rejected":return{title:"\u5F00\u7968\u7533\u8BF7\u88AB\u9A73\u56DE",body:`\u62AC\u5934\u300C${e.invoice.title}\u300D\u7684\u5F00\u7968\u7533\u8BF7\u88AB\u9A73\u56DE\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u4FEE\u6B63\u4FE1\u606F\u540E\u91CD\u65B0\u7533\u8BF7`,target:{kind:"invoices"}};case"refund_approved":return{title:"\u9000\u6B3E\u7533\u8BF7\u5DF2\u901A\u8FC7",body:`\u8BA2\u5355 ${e.refund.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\u5DF2\u901A\u8FC7\uFF0C${Re(e.refund.amountCny)} \u5C06\u539F\u8DEF\u9000\u56DE\u652F\u4ED8\u5B9D\u8D26\u6237`,target:md(e.refund.orderType)};case"refund_rejected":return{title:"\u9000\u6B3E\u7533\u8BF7\u88AB\u9A73\u56DE",body:`\u8BA2\u5355 ${e.refund.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\u88AB\u9A73\u56DE\uFF0C${e.refund.orderType==="subscription"?"\u8BA2\u9605\u65F6\u957F\u5DF2\u6062\u590D":"\u5230\u8D26\u989D\u5EA6\u5DF2\u6062\u590D"}\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:md(e.refund.orderType)};case"subscription_expiring":return{title:"\u8BA2\u9605\u5373\u5C06\u5230\u671F",body:`\u5957\u9910\u300C${e.subscription.planName}\u300D\u5C06\u4E8E ${V(e.subscription.expiresAt)} \u5230\u671F\uFF0C\u5230\u671F\u540E\u5C06\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528\u5957\u9910\u5185\u989D\u5EA6`,target:{kind:"subscription"}};case"email_changed":return{title:"\u90AE\u7BB1\u5DF2\u53D8\u66F4",body:`\u8D26\u53F7\u90AE\u7BB1\u5DF2\u53D8\u66F4\u4E3A ${e.newEmail}\uFF0C\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u8054\u7CFB\u7BA1\u7406\u5458`,target:{kind:"security"}};case"new_device_login":return{title:"\u65B0\u8BBE\u5907\u767B\u5F55\u63D0\u9192",body:`\u8D26\u53F7\u5728\u65B0\u8BBE\u5907\u4E0A\u767B\u5F55\uFF1A${qo(e.device)}\uFF0CIP \u5730\u5740 ${e.ip}\uFF1B\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u4FEE\u6539\u5BC6\u7801`,target:{kind:"security"}}}}function qr(e){if(e===void 0)return"";let t="";for(let n of e)switch(n.type){case"codespan":case"escape":case"html":case"image":t+=n.text;break;case"br":t+=" ";break;case"link":case"strong":case"em":case"del":t+=qr(n.tokens);break;case"text":t+="tokens"in n&&n.tokens!==void 0?qr(n.tokens):n.text;break}return t}function Bc(e){if(e===void 0)return[];let t=[];for(let n of e)switch(n.type){case"paragraph":case"heading":t.push(qr(n.tokens));break;case"text":t.push("tokens"in n&&n.tokens!==void 0?qr(n.tokens):n.text);break;case"code":case"html":t.push(n.text);break;case"blockquote":t.push(...Bc(n.tokens));break;case"list":n.items.forEach(o=>t.push(...Bc(o.tokens)));break;case"table":[...n.header,...n.rows.flat()].forEach(o=>t.push(qr(o.tokens)));break}return t}function dd(e){return Bc(e).join(" ").replace(/\s+/g," ").trim()}var sx=[{name:"\u4E00\u6574\u4E2A left-pad npm \u5305",tokens:110},{name:"\u5409\u5C3C\u65AF\u7EAA\u5F55\u6700\u5065\u8C08\u9E66\u9E49\u6BD5\u751F\u5B66\u4F1A\u7684\u8BCD\u6C47",tokens:2200},{name:"\u300A\u8BBA\u8BED\u300B",tokens:25e3},{name:"\u300A\u5C0F\u738B\u5B50\u300B",tokens:3e4},{name:"\u300A\u96F7\u950B\u65E5\u8BB0\u300B",tokens:54e3},{name:"\u300A\u8BD7\u7ECF\u300B",tokens:6e4},{name:"\u5468\u6770\u4F26\u5341\u4E94\u5F20\u4E13\u8F91\u7684\u5168\u90E8\u6B4C\u8BCD",tokens:82e3},{name:"\u300A\u6D3B\u7740\u300B",tokens:11e4},{name:"\u300A\u970D\u6BD4\u7279\u4EBA\u300B",tokens:12e4},{name:"\u300A\u4E2D\u534E\u4EBA\u6C11\u5171\u548C\u56FD\u6C11\u6CD5\u5178\u300B",tokens:126e3},{name:"\u300A\u94F6\u6CB3\u7CFB\u642D\u8F66\u5BA2\u6307\u5357\u300B\u4E94\u90E8\u66F2",tokens:26e4},{name:"\u79E6\u59CB\u7687\u4E00\u5929\u6279\u9605\u7684\u7AF9\u7B80\u594F\u7AE0",tokens:34e4},{name:"\u300A\u7EB3\u5C3C\u4E9A\u4F20\u5947\u300B\u5168\u4E03\u518C",tokens:45e4},{name:"\u300A\u5802\u5409\u8BC3\u5FB7\u300B",tokens:56e4},{name:"\u300A\u9B54\u6212\u300B\u4E09\u90E8\u66F2",tokens:59e4},{name:"\u300A\u804A\u658B\u5FD7\u5F02\u300B",tokens:6e5},{name:"\u300A\u6218\u4E89\u4E0E\u548C\u5E73\u300B",tokens:76e4},{name:"\u300A\u65B0\u534E\u5B57\u5178\u300B",tokens:8e5},{name:"\u300A\u7EA2\u697C\u68A6\u300B",tokens:9e5},{name:"\u300A\u897F\u6E38\u8BB0\u300B",tokens:1e6},{name:"\u300A\u4E09\u4F53\u300B\u4E09\u90E8\u66F2",tokens:11e5},{name:"\u838E\u58EB\u6BD4\u4E9A\u5168\u96C6",tokens:115e4},{name:"\u300A\u7504\u5B1B\u4F20\u300B\u5168\u5267\u5267\u672C",tokens:12e5},{name:"\u963F\u6CE2\u7F57 11 \u53F7\u767B\u6708\u5236\u5BFC\u7A0B\u5E8F\u6E90\u7801",tokens:13e5},{name:"\u300A\u54C8\u5229\xB7\u6CE2\u7279\u300B\u5168\u4E03\u90E8",tokens:14e5},{name:"\u8FC4\u4ECA\u51FA\u571F\u7684\u5168\u90E8\u7532\u9AA8\u6587",tokens:15e5},{name:"\u5409\u5C3C\u65AF\u7EAA\u5F55\u6700\u957F\u5C0F\u8BF4\u300A\u8FFD\u5FC6\u4F3C\u6C34\u5E74\u534E\u300B",tokens:165e4},{name:"\u300A\u51B0\u4E0E\u706B\u4E4B\u6B4C\u300B\u5DF2\u51FA\u4E94\u5377",tokens:226e4},{name:"\u300A\u65F6\u5149\u4E4B\u8F6E\u300B\u5168\u5341\u56DB\u5377",tokens:57e5},{name:"\u300A\u5168\u5510\u8BD7\u300B",tokens:64e5},{name:"\u300A\u9C81\u8FC5\u5168\u96C6\u300B",tokens:85e5},{name:"\u91D1\u5EB8\u5341\u4E94\u90E8\u5C0F\u8BF4",tokens:105e5},{name:"\u300A\u8F9E\u6D77\u300B",tokens:282e5},{name:"\u300A\u5927\u82F1\u767E\u79D1\u5168\u4E66\u300B",tokens:52e6},{name:"\u4E00\u6574\u5E74\u300A\u4EBA\u6C11\u65E5\u62A5\u300B",tokens:53e6},{name:"\u300A\u4E8C\u5341\u56DB\u53F2\u300B",tokens:6e7},{name:"\u300A\u725B\u6D25\u82F1\u8BED\u8BCD\u5178\u300B\u7B2C\u4E8C\u7248",tokens:767e5},{name:"\u5355\u7530\u82B3\u6BD5\u751F\u8BC4\u4E66\u4F5C\u54C1",tokens:86e6},{name:"\u300A\u4E2D\u56FD\u5927\u767E\u79D1\u5168\u4E66\u300B\u7B2C\u4E00\u7248",tokens:1508e5},{name:"\u6574\u5957 Linux \u5185\u6838\u6E90\u7801",tokens:4e8},{name:"\u4E00\u4E2A\u666E\u901A\u4EBA\u4E00\u751F\u8BF4\u51FA\u7684\u5168\u90E8\u8BDD\u8BED",tokens:5e8},{name:"\u4E2D\u6587\u7EF4\u57FA\u767E\u79D1",tokens:1e9},{name:"\u300A\u56DB\u5E93\u5168\u4E66\u300B",tokens:12e8},{name:"\u82F1\u6587\u7EF4\u57FA\u767E\u79D1",tokens:676e7},{name:"\u8C37\u6B4C\u5168\u90E8\u4EE3\u7801\u5E93",tokens:2e10}];function ax(e){return e>=10?Math.round(e).toLocaleString("en-US"):e>=1?e.toFixed(1):e.toFixed(-Math.floor(Math.log10(e)))}function Dt(e){return e>=10?Math.round(e).toLocaleString("en-US"):e.toFixed(1)}function pd(e){return e<365?`${Dt(e)} \u5929`:`${Dt(e/365)} \u5E74`}function cx(e){let t=e/1.2/250/60;if(t<48)return`${Math.max(1,Math.round(t))} \u5C0F\u65F6`;let n=t/24;return n<730?`${Math.round(n)} \u5929`:`${Dt(n/365)} \u5E74`}function lx(e){let t=e/1.2/80/60/8;return t<250?`${Dt(t)} \u4E2A\u5DE5\u4F5C\u65E5`:`${Dt(t/250)} \u4E2A\u5DE5\u4F5C\u5E74`}function mx(e){let t=e/1.2/30*4;return t<1e3?`${Math.round(t).toLocaleString("en-US")} \u514B`:t<1e6?`${Dt(t/1e3)} \u516C\u65A4`:`${Dt(t/1e6)} \u5428`}var ux=[...sx.map(e=>({min:e.tokens/10,max:e.tokens*1e4,suffix:t=>`\u7EA6\u4E3A${e.name}\u7684 ${ax(t/e.tokens)} \u500D`})),{min:3e5,max:1/0,suffix:e=>`\u6253\u5370\u6210 A4 \u7EB8\u7EA6\u6709 ${Math.round(e/1.2/1500).toLocaleString("en-US")} \u9875`},{min:3e5,max:1/0,suffix:e=>`\u6309\u6BCF\u5206\u949F 250 \u5B57\u7684\u8BED\u901F\u6717\u8BFB\u7EA6\u9700 ${cx(e)}`},{min:1680,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Math.round(e/1.2/140).toLocaleString("en-US")} \u6761\u5199\u6EE1 140 \u5B57\u7684\u5FAE\u535A`},{min:9600,max:1/0,suffix:e=>`\u7EA6\u5408 ${Math.round(e/1.2/800).toLocaleString("en-US")} \u7BC7 800 \u5B57\u7684\u9AD8\u8003\u4F5C\u6587`},{min:131400,max:1/0,suffix:e=>`\u6309\u6BCF\u5929\u4E00\u7BC7 300 \u5B57\u7684\u65E5\u8BB0\u8BA1\uFF0C\u591F\u8FDE\u7EED\u5199 ${Dt(e/1.2/300/365)} \u5E74`},{min:12e5,max:1/0,suffix:e=>`\u7EA6\u5408 ${Math.round(e/1.2/1e5).toLocaleString("en-US")} \u672C\u5341\u4E07\u5B57\u7684\u535A\u58EB\u8BBA\u6587`},{min:33e3,max:1/0,suffix:e=>`\u6309\u300A\u8D44\u6CBB\u901A\u9274\u300B\u7684\u7B14\u58A8\u5BC6\u5EA6\uFF0C\u7EA6\u591F\u53F8\u9A6C\u5149\u8BB0\u8F7D ${Math.round(e/45e5*1362).toLocaleString("en-US")} \u5E74\u5386\u53F2`},{min:49e3,max:1/0,suffix:e=>`\u7EA6\u5408\u300A\u4E00\u5343\u96F6\u4E00\u591C\u300B\u91CC\u5C71\u9C81\u4F50\u5FB7\u8BB2\u6545\u4E8B\u7684 ${Math.round(e/492e4*1001).toLocaleString("en-US")} \u4E2A\u591C\u665A`},{min:640,max:1/0,suffix:e=>`\u6309\u91D1\u9675\u523B\u7ECF\u5904\u523B\u5DE5\u534A\u6708\u523B\u6210\u4E00\u5757 800 \u5B57\u7ECF\u7248\u7684\u8FDB\u5EA6\uFF0C\u5168\u90E8\u523B\u4E0A\u96D5\u7248\u9700\u8981 ${pd(e/1.2/53)}`},{min:460800,max:1/0,suffix:e=>`\u6309\u6BCF\u5206\u949F 80 \u5B57\u3001\u6BCF\u5929 8 \u5C0F\u65F6\u8BA1\uFF0C\u591F\u4E00\u4F4D\u4E13\u804C\u6253\u5B57\u5458\u6253 ${lx(e)}`},{min:4500,max:1/0,suffix:e=>`\u82E5\u523B\u6210\u6BCF\u679A 30 \u5B57\u7684\u79E6\u6C49\u7AF9\u7B80\uFF0C\u603B\u91CD\u7EA6 ${mx(e)}`},{min:18e3,max:1/0,suffix:e=>`\u6309\u300A\u6C38\u4E50\u5927\u5178\u300B\u91CD\u5F55\u4E66\u624B\u6BCF\u5929\u4E09\u53F6\u3001\u7EA6 1500 \u5B57\u7684\u5B9A\u989D\uFF0C\u591F\u4E00\u4F4D\u4E66\u624B\u6284\u5199 ${pd(e/1.2/1500)}`},{min:108e3,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Math.round(e/1.2/9e3).toLocaleString("en-US")} \u671F\u300A\u65B0\u95FB\u8054\u64AD\u300B\u7684\u64AD\u62A5\u7A3F`},{min:4e4,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Dt(e/1.2/33e3)} \u5C4A\u592E\u89C6\u6625\u665A\u7684\u5168\u90E8\u53F0\u8BCD\u548C\u6B4C\u8BCD`},{min:96e3,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u6807\u51C6 400 \u7C73\u8DD1\u9053 ${Dt(e/1.2*.005/400)} \u5708`},{min:96e5,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u5408\u5730\u9762\u5230\u56FD\u9645\u7A7A\u95F4\u7AD9\u8DDD\u79BB\u7684 ${Dt(e/1.2*.005/4e5)} \u500D`},{min:26e7,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u6708\u7403\u8D64\u9053 ${Dt(e/1.2*.005/10917e3)} \u5708`},{min:96e7,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u5730\u7403\u8D64\u9053 ${Dt(e/1.2*.005/40075e3)} \u5708`}];function fd(e){let{tokens:t,scope:n,range:o}=e;if(t<=0)return null;let r=ux.filter(c=>t>=c.min&&t<=c.max),i=r[Math.floor(Math.random()*r.length)];return i?`${n==="user"?"\u4F60":"\u5168\u7AD9"}${o==="all"?"\u7D2F\u8BA1":o==="30d"?"\u8FD1 30 \u5929":"\u8FD1 7 \u5929"}\u4F7F\u7528\u7684 Token \u91CF${i.suffix(t)}`:null}function vn(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown status value: ${t}`);return n}}function $t(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown label value: ${t}`);return n}}var Wn=vn({pending:{label:"\u5F85\u652F\u4ED8",tone:"warning"},paid:{label:"\u5DF2\u652F\u4ED8",tone:"success"},refund_requested:{label:"\u9000\u6B3E\u5BA1\u6838\u4E2D",tone:"warning"},partially_refunded:{label:"\u90E8\u5206\u9000\u6B3E",tone:"warning"},refunded:{label:"\u5DF2\u9000\u6B3E",tone:"danger"},failed:{label:"\u5931\u8D25",tone:"danger"},expired:{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}}),CP=$t({recharge:"\u5145\u503C",subscription:"\u8BA2\u9605"}),Ki=vn({pending:{label:"\u5F85\u5904\u7406",tone:"warning"},issued:{label:"\u5DF2\u5F00\u5177",tone:"success"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"}}),_P=vn({active:{label:"\u6B63\u5E38",tone:"success"},disabled:{label:"\u7981\u7528",tone:"danger"}}),Fc=$t({subscription_first:"\u8BA2\u9605\u4F18\u5148",balance_first:"\u4F59\u989D\u4F18\u5148",subscription_only:"\u4EC5\u8BA2\u9605",balance_only:"\u4EC5\u4F59\u989D"}),Uc=$t({subscription_first:"\u6709\u53EF\u7528\u8BA2\u9605\u65F6\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6\uFF0C\u8BA2\u9605\u7528\u5C3D\u6216\u672A\u8986\u76D6\u5F53\u524D\u5206\u7EC4\u65F6\u6539\u6263\u4F59\u989D",balance_first:"\u4F59\u989D\u5145\u8DB3\u65F6\u6263\u4F59\u989D\uFF0C\u4F59\u989D\u4E0D\u8DB3\u65F6\u6539\u7528\u8BA2\u9605\u989D\u5EA6",subscription_only:"\u53EA\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6\uFF0C\u8BA2\u9605\u7528\u5C3D\u6216\u672A\u8986\u76D6\u5F53\u524D\u5206\u7EC4\u65F6\u62D2\u7EDD\u8BF7\u6C42",balance_only:"\u53EA\u6263\u8D26\u6237\u4F59\u989D\uFF0C\u4E0D\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6"}),gd=Ka.map(e=>({value:e,label:Fc(e)})),jc=$t({recharge:"\u5145\u503C",reserve:"\u9884\u6263",consume:"\u6D88\u8D39",reserve_refund:"\u9884\u6263\u9000\u56DE",refund:"\u9000\u6B3E",refund_release:"\u9000\u6B3E\u8FD4\u8FD8",reward:"\u5956\u52B1",admin_adjust:"\u7BA1\u7406\u5458\u8C03\u6574"}),hd=$t({usage_log:"\u7528\u91CF",order:"\u8BA2\u5355",invitation:"\u9080\u8BF7",admin:"\u7BA1\u7406\u5458"}),yd=vn({requested:{label:"\u5F85\u5BA1\u6838",tone:"warning"},pending:{label:"\u5F85\u786E\u8BA4",tone:"warning"},succeeded:{label:"\u5DF2\u9000\u6B3E",tone:"success"},failed:{label:"\u5931\u8D25",tone:"danger"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"},canceled:{label:"\u5DF2\u64A4\u9500",tone:"neutral"}}),Yi=vn({success:{label:"\u6210\u529F",tone:"success"},error:{label:"\u5931\u8D25",tone:"danger"},canceled:{label:"\u53D6\u6D88",tone:"neutral"},anomaly:{label:"\u5F02\u5E38",tone:"warning"}}),bd=$t({"openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"}),Gr=$t({special:"\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968",general:"\u589E\u503C\u7A0E\u666E\u901A\u53D1\u7968"}),uo=$t({special:"\u4E13\u7968",general:"\u666E\u7968"}),Ji=$t({first_inviter:"\u9996\u5145\u8FD4\u5229\uFF08\u9080\u8BF7\u4EBA\uFF09",first_invitee:"\u9996\u5145\u8FD4\u5229\uFF08\u88AB\u9080\u8BF7\u4EBA\uFF09",subsequent_inviter:"\u7EED\u5145\u8FD4\u5229\uFF08\u9080\u8BF7\u4EBA\uFF09"}),Wr=vn({info:{label:"\u4FE1\u606F",tone:"neutral"},success:{label:"\u6210\u529F",tone:"success"},warning:{label:"\u8B66\u544A",tone:"warning"},error:{label:"\u91CD\u8981",tone:"danger"}}),Hc=vn({open:{label:"\u5F85\u5904\u7406",tone:"warning"},replied:{label:"\u5DF2\u56DE\u590D",tone:"success"},closed:{label:"\u5DF2\u5173\u95ED",tone:"neutral"}}),Xi=$t({billing:"\u8BA1\u8D39",technical:"\u6280\u672F",account:"\u8D26\u53F7",other:"\u5176\u4ED6"}),qc=vn({low:{label:"\u8F83\u4F4E",tone:"neutral"},normal:{label:"\u666E\u901A",tone:"neutral"},high:{label:"\u7D27\u6025",tone:"danger"}}),Sd=$t({openai:"OpenAI",anthropic:"Anthropic"}),po=vn({pending:{label:"\u5BA1\u6838\u4E2D",tone:"warning"},published:{label:"\u5DF2\u53D1\u5E03",tone:"success"},rejected:{label:"\u672A\u901A\u8FC7",tone:"danger"},removed:{label:"\u5DF2\u5C4F\u853D",tone:"danger"}}),xd=$t({spam:"\u5783\u573E\u5E7F\u544A",abuse:"\u4EBA\u8EAB\u653B\u51FB",explicit:"\u8272\u60C5\u4F4E\u4FD7",illegal:"\u8FDD\u6CD5\u8FDD\u89C4",privacy:"\u6CC4\u9732\u9690\u79C1",other:"\u5176\u4ED6"}),Td=$t({activity:"\u6700\u65B0\u56DE\u590D",published:"\u6700\u65B0\u53D1\u5E03"});function _t(e,t,n){let o=r=>{let i=t(r);return typeof i=="string"?i:i.label};return[{value:"",label:n},...e.map(r=>({value:r,label:o(r)}))]}function es(e){return`${e.name} \xD7${e.multiplier}`}var Qi=10080,Zi=1440;function wd(e){if(e%Qi===0){let t=e/Qi;return t===1?"\u6BCF\u5468\u9650\u989D":`${t} \u5468\u9650\u989D`}if(e%Zi===0){let t=e/Zi;return t===1?"\u6BCF\u65E5\u9650\u989D":`${t} \u5929\u9650\u989D`}return e%60===0?`${e/60} \u5C0F\u65F6\u9650\u989D`:`${e} \u5206\u949F\u9650\u989D`}function dx(e){if(e%Qi===0){let t=e/Qi;return t===1?"\u6BCF\u5468":`\u6BCF ${t} \u5468`}if(e%Zi===0){let t=e/Zi;return t===1?"\u6BCF\u5929":`\u6BCF ${t} \u5929`}return e%60===0?`\u6BCF ${e/60} \u5C0F\u65F6`:`\u6BCF ${e} \u5206\u949F`}function kd(e,t){return e.windows.map(n=>`${dx(n.durationMinutes)} ${Te(n.quota,t)}`)}function Gc(e){return Math.min(100,Math.floor(e.used/e.quota*100))}function Wc(e){return e.revokedAt!==null?{label:"\u5DF2\u4F5C\u5E9F",tone:"danger"}:new Date(e.expiresAt).getTime()<=Date.now()?{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}:{label:"\u751F\u6548\u4E2D",tone:"success"}}var zc={recharge:["\u5145\u9519\u91D1\u989D\u6216\u91CD\u590D\u5145\u503C","\u9700\u8981\u7684\u6A21\u578B\u4E0D\u53EF\u7528","\u8C03\u7528\u7ECF\u5E38\u62A5\u9519\u6216\u8D85\u65F6","\u5B9E\u9645\u8BA1\u8D39\u9AD8\u4E8E\u9884\u671F","\u4F59\u989D\u7528\u4E0D\u5B8C\uFF0C\u4E0D\u518D\u9700\u8981"],subscription:["\u8BEF\u8D2D\u6216\u9009\u9519\u5957\u9910","\u5957\u9910\u4E0D\u542B\u9700\u8981\u7684\u6A21\u578B","\u9650\u989D\u592A\u4F4E\uFF0C\u4E0D\u591F\u7528","\u8C03\u7528\u7ECF\u5E38\u62A5\u9519\u6216\u8D85\u65F6","\u4F7F\u7528\u9891\u7387\u4F4E\uFF0C\u4E0D\u5212\u7B97"]},vd={recharge:"\u63D0\u4EA4\u540E\u672C\u5355\u5269\u4F59\u989D\u5EA6\u4E0E\u5173\u8054\u7684\u9080\u8BF7\u5956\u52B1\u5C06\u7ACB\u5373\u4ECE\u4F59\u989D\u6536\u56DE\uFF1B\u5BA1\u6838\u901A\u8FC7\u540E\u539F\u8DEF\u9000\u56DE\u652F\u4ED8\u5B9D\uFF0C\u9A73\u56DE\u6216\u64A4\u9500\u540E\u81EA\u52A8\u6062\u590D",subscription:"\u63D0\u4EA4\u540E\u672C\u5355\u672A\u5F00\u59CB\u7684\u65F6\u957F\u7ACB\u5373\u5931\u6548\uFF0C\u6B63\u5728\u670D\u52A1\u4E2D\u7684\u65F6\u6BB5\u4FDD\u7559\u81F3\u5F53\u524D\u9650\u989D\u5468\u671F\u7ED3\u675F\uFF1B\u5BA1\u6838\u901A\u8FC7\u540E\u6309\u672A\u5F00\u59CB\u7684\u9650\u989D\u5468\u671F\u6298\u7B97\u539F\u8DEF\u9000\u6B3E\uFF0C\u9A73\u56DE\u6216\u64A4\u9500\u540E\u81EA\u52A8\u6062\u590D"};import{release as px}from"os";var fx=3e4,gx=nu({cliVersion:Vt,platform:process.platform,release:px(),arch:process.arch,nodeVersion:process.versions.node});async function Rd(e,t){if(t.json!==void 0&&t.body!==void 0)throw new Error("httpRequest cannot accept both json and body");let n=new Headers(t.headers);n.set("user-agent",gx);let o=t.body;t.json!==void 0&&(n.set("content-type","application/json"),o=JSON.stringify(t.json));try{return await fetch(e,{method:t.method??(o===void 0?"GET":"POST"),headers:n,body:o,signal:AbortSignal.timeout(t.timeoutMs??fx),redirect:"follow"})}catch(r){let i=URL.canParse(e)?new URL(e).origin:e;throw new j(`\u65E0\u6CD5\u8FDE\u63A5 ${i}\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u7AD9\u70B9\u5730\u5740`,{exitCode:Rm,cause:r})}}async function Cd(e){let t=await e.text();if(t==="")return null;try{return JSON.parse(t)}catch{return null}}async function Jt(e,t={}){let n=await Rd(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Cd(n)};let o=await n.text(),r=null;if(o!=="")try{r=JSON.parse(o)}catch(i){throw new j(`${e} \u8FD4\u56DE\u4E86\u975E JSON \u5185\u5BB9\uFF0C\u53EF\u80FD\u88AB\u7F51\u5173\u6216\u4E2D\u95F4\u8BBE\u5907\u62E6\u622A`,{cause:i})}return{status:n.status,ok:!0,headers:n.headers,data:r}}async function _d(e,t={}){let n=await Rd(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Cd(n),bytes:null};let o=new Uint8Array(await n.arrayBuffer());return{status:n.status,ok:!0,headers:n.headers,data:null,bytes:o}}function hx(e,t){let n=eu.safeParse(t);if(!n.success)return new j(`\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${e}\uFF09`);let{code:o,message:r}=n.data.error,i=o==="unauthorized"||o==="token_expired"?ro:void 0;return new j(tu[o]??r,i?{exitCode:i}:{})}function sn(e){if(!e.ok)throw hx(e.status,e.data)}var Ed="cf_refresh",Md="cf_device",Pd=6e4;function Ad(e,t){for(let n of e.getSetCookie()){let o=n.split(";",1)[0];if(o===void 0)continue;let r=o.indexOf("=");if(!(r<0)&&o.slice(0,r).trim()===t)return o.slice(r+1).trim()}return null}function zr(e,t){return{refresh:Ad(t,Ed)??e.refresh,device:Ad(t,Md)??e.device}}function ts(e){let t=[];return e.refresh&&t.push(`${Ed}=${e.refresh}`),e.device&&t.push(`${Md}=${e.device}`),t.length>0?{cookie:t.join("; ")}:{}}function yx(e){let t=e.split(".")[1];if(t===void 0)throw new j("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u683C\u5F0F\u4E0D\u6B63\u786E");let n;try{n=JSON.parse(Buffer.from(t,"base64url").toString("utf8"))}catch(r){throw new j("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u65E0\u6CD5\u89E3\u6790",{cause:r})}let o=n.exp;if(typeof o!="number")throw new j("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u7F3A\u5C11\u6709\u6548\u671F");return o*1e3}function Vr(e,t,n){if(!t.refresh)throw new j("\u670D\u52A1\u7AEF\u672A\u4E0B\u53D1\u5237\u65B0\u51ED\u636E\uFF0C\u65E0\u6CD5\u4FDD\u6301\u767B\u5F55\u72B6\u6001");let o={refreshCookie:t.refresh,accessToken:n.accessToken,accessExpiresAt:yx(n.accessToken),username:n.user.username,email:n.user.email,site:e};return Va(r=>{r.session=o,t.device&&(r.device={site:e,cookie:t.device})}),o}function Vc(e){let{device:t}=Lt();return t!==null&&t.site===e?t.cookie:null}async function Id(e,t,n){let o={refresh:null,device:Vc(e)},r=await Jt(`${e}/api/auth/login`,{json:{account:t,password:n},headers:ts(o)});sn(r);let i=au.parse(r.data),s=zr(o,r.headers);return i.status==="totp_required"?{status:"totp_required",ticket:i.ticket,jar:s}:{status:"ok",session:Vr(e,s,i)}}async function Nd(e,t,n,o,r){let s=await Jt(`${e}/api/auth/${r==="totp"?"login/totp":"login/recovery-code"}`,{json:{ticket:n,code:o},headers:ts(t)});sn(s);let a=Go.parse(s.data);return Vr(e,zr(t,s.headers),a)}function ns(){Va(e=>{e.session=null})}async function bx(e){let t={refresh:e.refreshCookie,device:Vc(e.site)},n=await Jt(`${e.site}/api/auth/refresh`,{method:"POST",headers:ts(t)});if(n.status===401||n.status===403)throw ns(),new j("\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",{exitCode:ro});sn(n);let o=Go.parse(n.data);return Vr(e.site,zr(t,n.headers),o)}async function Kr(e=!1){let t=Lm();return!e&&Date.now()<t.accessExpiresAt-Pd?t:Om(async()=>{let n=Nm().session;if(!n)throw new j("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return(n.refreshCookie!==t.refreshCookie||n.accessToken!==t.accessToken)&&Date.now()<n.accessExpiresAt-Pd?n:bx(n)})}async function os(){let e=Lt().session;if(!e)return;let t=await Jt(`${e.site}/api/auth/logout`,{method:"POST",headers:ts({refresh:e.refreshCookie,device:Vc(e.site)})});ns(),sn(t)}import{spawn as Sx}from"child_process";function Yr(e,t={}){return new Promise((n,o)=>{let r=Sx("npm",e,{stdio:["ignore","pipe","pipe"],shell:process.platform==="win32"}),i=[],s=[],a=c=>{for(let l of c.toString("utf8").split(`
4
- `)){let u=l.trimEnd();u!==""&&(s.push(u),s.length>20&&s.shift())}};r.stdout.on("data",c=>{i.push(c.toString("utf8")),a(c)}),r.stderr.on("data",a),r.on("error",c=>o(new j(`\u6267\u884C npm \u5931\u8D25\uFF1A${c.message}`,{cause:c}))),r.on("close",c=>{if(c===0){n(i.join(""));return}let l=s.slice(-2).join(" / ");o(new j(`npm ${e.join(" ")} \u9000\u51FA\u7801 ${c??"null"}`,{...l===""?{}:{hint:l}}))}),t.background===!0&&(r.stdout.unref(),r.stderr.unref(),r.unref())})}async function Ld(e){let t=[],n=async(o,r)=>{try{await r(),e.done(o)}catch(i){t.push(`${o}\uFF1A${xe(i)}`),e.failed(o)}};return await n("\u9000\u51FA\u767B\u5F55",()=>os()),await n("\u5220\u9664\u672C\u5730\u6587\u4EF6",()=>{let o=kn();xx(o)&&Tx(o,{recursive:!0,force:!0})}),await n("\u5378\u8F7D\u672C\u7A0B\u5E8F",async()=>{await Yr(["uninstall","-g",Bo])}),t}import{z as Jr}from"zod";var wx=Jr.object({line:Jr.object({name:Jr.string(),url:Jr.string()}).nullable(),lastUpdateCheckAt:Jr.number().nullable()}),Od=Ai(wx,{line:null,lastUpdateCheckAt:null},_m,"\u672C\u5730\u914D\u7F6E","\u91CD\u65B0\u8FD0\u884C"),fo=Od.load,rs=Od.update;var kx=1440*60*1e3;async function Dd(){let e=(await Yr(["view",Bo,"version"])).trim();if(e==="")throw new j(`npm \u6CA1\u6709\u62A5\u51FA ${Bo} \u7684\u7248\u672C`);return e}async function $d(e,t){return await Yr(["install","-g",`${Bo}@${e}`],{background:t}),e}async function Bd(){let e=await Dd();return e===Vt?null:await $d(e,!1)}function vx(){let e=Date.now(),t=fo().lastUpdateCheckAt;return t!==null&&e-t<kx?!1:(rs(n=>{n.lastUpdateCheckAt=e}),!0)}async function Fd(){if(!vx())return null;let e;try{e=await Dd()}catch{return null}return e===Vt?null:await $d(e,!0)}import{Box as AC,render as EC,useInput as MC}from"ink";import{useEffect as wm,useRef as IC}from"react";async function fn(e,t,n={}){let o=await Jt(t,n);return sn(o),e.parse(o.data)}async function P(e,t,n={}){let o=await Kr(),r=s=>Jt(`${o.site}/api${t}`,{...n,headers:{...n.headers,authorization:`Bearer ${s}`}}),i=await r(o.accessToken);if(i.status===401){let s=await Kr(!0);i=await r(s.accessToken)}return sn(i),e.parse(i.data)}async function Kc(e,t={}){let n=await Kr(),o=i=>_d(`${n.site}/api${e}`,{...t,headers:{...t.headers,authorization:`Bearer ${i}`}}),r=await o(n.accessToken);if(r.status===401){let i=await Kr(!0);r=await o(i.accessToken)}return sn(r),{bytes:r.bytes,headers:r.headers}}async function is(e,t={}){return(await Kc(e,t)).bytes}function je(e,t){let n=new URLSearchParams;for(let[r,i]of Object.entries(t))i!==void 0&&n.set(r,String(i));let o=n.toString();return o===""?e:`${e}?${o}`}var Ud=e=>P(lt(gc),je("/announcements",{...e})),jd=()=>P(gc.nullable(),"/announcements/unread"),ss=e=>P(se,`/announcements/${e}/read`,{method:"POST"});import{Box as Hd,useWindowSize as Rx}from"ink";import{Children as Cx}from"react";import{jsx as qd}from"react/jsx-runtime";var _x=1,Yc=1,Q=1;function H(){let{columns:e,rows:t}=Rx();return{width:Math.max(1,e-_x*2),columns:e,rows:t}}function Gd({height:e,children:t}){return qd(Hd,{flexDirection:"column",height:e,justifyContent:"space-between",children:Cx.toArray(t).map((n,o)=>qd(Hd,{flexDirection:"column",flexShrink:0,children:n},o))})}import{useInput as Wd}from"ink";import{createContext as ls,useCallback as Xc,useContext as Px,useEffect as zd,useMemo as Vd,useRef as cs,useState as Ax}from"react";import{jsx as as}from"react/jsx-runtime";var ms=ls(null),Qc=ls(null),Zc=ls(null);function Jc(){let[e,t]=Ax(!1),n=cs(0),o=Xc(()=>(n.current+=1,t(!0),()=>{n.current-=1,n.current===0&&t(!1)}),[]);return Vd(()=>({held:e,acquire:o}),[e,o])}var zn={screen:0,panel:10,input:20},el=ls(null);function Kd({children:e}){let t=Jc(),n=Jc(),o=Jc(),r=cs([]),i=cs(0),s=Xc(l=>{let u={...l,seq:i.current+=1};return r.current.push(u),()=>{r.current=r.current.filter(m=>m!==u)}},[]),a=Xc(()=>{r.current.reduce((u,m)=>u===null||m.layer>u.layer||m.layer===u.layer&&m.seq>u.seq?m:u,null)?.handler()},[]);Wd((l,u)=>{u.escape&&a()});let c=Vd(()=>({push:s,fire:a}),[s,a]);return as(ms.Provider,{value:t,children:as(Qc.Provider,{value:n,children:as(Zc.Provider,{value:o,children:as(el.Provider,{value:c,children:e})})})})}function go(e){let t=Px(e);if(!t)throw new Error("\u952E\u76D8\u94A9\u5B50\u5FC5\u987B\u5728 KeyboardProvider \u5185\u4F7F\u7528");return t}function tl(e,t){let{acquire:n}=go(e);zd(()=>{if(t)return n()},[t,n])}function us(e){tl(ms,e)}function Ce(e){tl(Qc,e)}function Yd(e){tl(Zc,e)}function ds(){return go(Qc).held}function ps(){return go(ms).held}function Jd(){return go(Zc).held}function G(e,t=!0){let n=go(ms).held;Wd(e,{isActive:t&&!n})}function Xd(){return go(el).fire}function gn(e,{isActive:t=!0,layer:n=zn.screen}={}){let{push:o}=go(el),r=cs(e);r.current=e,zd(()=>{if(t)return o({handler:()=>r.current(),layer:n})},[t,n,o])}import{measureElement as Ex}from"ink";import{PassThrough as Mx}from"stream";import{createContext as Ix,useCallback as Nx,useContext as Lx,useEffect as tp,useRef as fs}from"react";import{jsx as Gx}from"react/jsx-runtime";var Ox="\x1B[?1000h\x1B[?1003h\x1B[?1006h",Dx="\x1B[?1006l\x1B[?1003l\x1B[?1000l",$x=27,Bx=91,Fx=60,Qd=77,Zd=109,ep=20,Ux=64,jx=32,Hx=20;function qx(e){let t=[],n=[],o=0;for(;o<e.length;){let r=e[o];if(r===void 0)break;if(r!==$x){n.push(r),o+=1;continue}let i=e[o+1],s=e[o+2];if(i===void 0||s===void 0)break;if(i!==Bx){n.push(r),o+=1;continue}if(s===Qd){if(o+6>e.length)break;o+=6;continue}if(s!==Fx){n.push(r),o+=1;continue}let a=o+3,c;for(;a<e.length&&a-o<ep;){let d=e[a];if(d===Qd||d===Zd){c=d;break}a+=1}if(c===void 0){if(a-o<ep)break;n.push(r),o+=1;continue}let l=e.subarray(o+3,a).toString("latin1").split(";");if(o=a+1,c===Zd||l.length!==3)continue;let u=Number(l[0]),m=Number(l[1]),f=Number(l[2]);!Number.isFinite(u)||!Number.isFinite(m)||!Number.isFinite(f)||t.push((u&Ux)!==0?{row:f,column:m,kind:"wheel",delta:(u&1)===0?-1:1}:{row:f,column:m,kind:(u&jx)!==0?"move":"press"})}return{events:t,clean:Buffer.from(n),pending:e.subarray(o)}}function np(e,t){let n=new Set,o=new Mx,r=Buffer.alloc(0),i=null,s=()=>{i=null,r.length!==0&&(o.write(r),r=Buffer.alloc(0))},a=f=>{i!==null&&clearTimeout(i),i=null;let d=qx(Buffer.concat([r,f]));r=d.pending,d.clean.length>0&&o.write(d.clean);for(let h of d.events)for(let y of n)y(h);r.length>0&&(i=setTimeout(s,Hx))},c=()=>{t.write(Dx)},l={SIGHUP:1,SIGINT:2,SIGTERM:15},u=f=>{process.exit(128+(l[f]??0))};e.on("data",a),process.once("exit",c);for(let f of Object.keys(l))process.on(f,u);t.write(Ox);let m=o;return Object.assign(m,{isTTY:!0,setRawMode(f){return e.setRawMode(f),m},ref(){return e.ref(),m},unref(){return e.unref(),m}}),{stdin:m,subscribe(f){return n.add(f),()=>{n.delete(f)}},dispose(){c(),i!==null&&clearTimeout(i),process.off("exit",c);for(let f of Object.keys(l))process.off(f,u);e.off("data",a),n.clear()}}}var op=Ix(null);function rp({subscribe:e,children:t}){let n=fs(new Set).current,o=fs(null),r=Nx(i=>(n.add(i),()=>{n.delete(i)}),[n]);return tp(()=>e(i=>{let s=i.row-1,a=i.column-1,c=null;for(let u of n){let m=u.node.current;if(m===null||u.handlers.current.isActive===!1)continue;let f=Ex(m);if(s<f.y||s>=f.y+f.height||a<f.x||a>=f.x+f.width)continue;let d=f.width*f.height;(c===null||d<c.area)&&(c={region:u,top:f.y,left:f.x,area:d})}if(i.kind==="move"){let u=c===null?null:c.region;if(o.current!==u){let m=o.current;m!==null&&n.has(m)&&m.handlers.current.onHoverLeave?.(),o.current=u}c!==null&&c.region.handlers.current.onHover?.({row:s-c.top,column:a-c.left});return}if(c===null)return;let l=c.region.handlers.current;i.kind==="wheel"?l.onWheel?.(i.delta):l.onClick?.({row:s-c.top,column:a-c.left})}),[e,n]),Gx(op.Provider,{value:r,children:t})}function rt(e){let t=Lx(op);if(t===null)throw new Error("useMouseRegion \u5FC5\u987B\u5728 MouseProvider \u5185\u4F7F\u7528");let n=fs(null),o=fs(e);return o.current=e,tp(()=>t({node:n,handlers:o}),[t]),n}import{useApp as Wx}from"ink";import{createContext as zx,useCallback as ho,useContext as Vx,useEffect as nl,useRef as hs,useState as Qr}from"react";var Tt=[{id:"usage",label:"\u6570\u636E\u770B\u677F"},{id:"tokens",label:"\u4EE4\u724C\u7BA1\u7406"},{id:"logs",label:"\u4F7F\u7528\u65E5\u5FD7"},{id:"models",label:"\u6A21\u578B\u5E7F\u573A"},{id:"docs",label:"\u4F7F\u7528\u6587\u6863"},{id:"recharge",label:"\u8D26\u6237\u5145\u503C"},{id:"subscription",label:"\u8BA2\u9605\u5957\u9910"},{id:"ledger",label:"\u989D\u5EA6\u6D41\u6C34"},{id:"invoices",label:"\u53D1\u7968\u7BA1\u7406"},{id:"invite",label:"\u9080\u8BF7\u597D\u53CB"},{id:"tickets",label:"\u5DE5\u5355\u652F\u6301"},{id:"community",label:"\u793E\u533A\u8BBA\u575B"},{id:"inbox",label:"\u7AD9\u5185\u6D88\u606F"},{id:"announcements",label:"\u7CFB\u7EDF\u516C\u544A"},{id:"profile",label:"\u4E2A\u4EBA\u4E3B\u9875"}],ip="usage",Xr=e=>Tt.findIndex(t=>t.id===e),gs=e=>Xr(e)>=0;import{jsx as Yx}from"react/jsx-runtime";var Kx=5e3,ap=zx(null),cp=e=>({id:e,params:void 0}),sp=()=>Lt().session===null?[{id:"home",params:void 0}]:[cp(ip)];function L(){let e=Vx(ap);if(!e)throw new Error("useNav \u5FC5\u987B\u5728 NavProvider \u5185\u4F7F\u7528");return e}function lp({ctx:e,children:t}){let n=Wx(),[o,r]=Qr(sp),[i,s]=Qr(0),[a,c]=Qr([]),l=hs({announcementsChecked:!1,announcementsShown:!1}).current,u=hs(new WeakMap).current,m=ho((v,...M)=>{r(N=>[...N,{id:v,params:M[0]}])},[]),f=ho(()=>{r(v=>v.length>1?v.slice(0,-1):v),s(v=>v+1)},[]),d=ho(v=>{r([cp(v)]),s(M=>M+1)},[]),h=ho(()=>{r(sp()),s(v=>v+1)},[]),y=ho(()=>s(v=>v+1),[]),g=ho((v,M)=>{c(N=>[...N,{tone:v,message:M}])},[]),x=ho(()=>c(v=>v.slice(1)),[]),T=a[0]??null;nl(()=>{if(T===null)return;let v=setTimeout(x,Kx);return()=>clearTimeout(v)},[T,x]);let R=o[o.length-1];if(R===void 0)throw new Error("\u5BFC\u822A\u6808\u4E3A\u7A7A");let b=u.get(R);b===void 0&&(b=new Map,u.set(R,b));let S={ctx:e,current:R,depth:o.length,push:m,pop:f,select:d,home:h,reload:y,toast:g,message:T,dismissToast:x,exit:n.exit,revision:i,gate:l,retained:b};return Yx(ap.Provider,{value:S,children:t})}function Ie(e,t){let{retained:n}=L(),[o,r]=Qr(()=>e!==void 0&&n.has(e)?n.get(e):t());return nl(()=>{e!==void 0&&n.set(e,o)},[n,e,o]),[o,r]}function ee(e,t){let[n,o]=Qr({phase:"loading"}),r=hs(t);r.current=t;let i=hs(0);return nl(()=>{let s=i.current+=1;o({phase:"loading"}),r.current().then(a=>{i.current===s&&o({phase:"ready",data:a})}).catch(a=>{i.current===s&&o({phase:"error",message:xe(a),hint:a instanceof j?a.hint:void 0})})},e),n}import{Box as Ns,Text as xo,useInput as UT}from"ink";import{Box as ni,Text as tr}from"ink";import{Lexer as eT}from"marked";import Qo from"string-width";import Zr from"string-width";var p={background:"#0d0d0d",foreground:"#f3f3f3",mutedForeground:"#949494",faintForeground:"#696969",cursorBackground:"#c8c8c8",border:"#393939",accent:"#37be95",success:"#34d399",warning:"#fbbf24",danger:"#f87171"},ys=["#242424","#5a4233","#746533","#70924f","#37be95"],bs=["#37be95","#2d9273","#246e58","#1e5443","#193f33"],tt={accent:p.accent,success:p.success,warning:p.warning,danger:p.danger},Xo=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],Ss=80,ie={cursor:"\u276F",bullet:"\xB7",dot:"\u2219",crumb:"\u203A",ok:"\u2714",warn:"!",fail:"\u2718",ellipsis:"\u2026",barFilled:"\u2588",barEmpty:"\u2591",section:"\u258D",prev:"\u2039",next:"\u203A"};var Jx=Zr(ie.ellipsis),Xx=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ol=e=>Array.from(Xx.segment(e),t=>t.segment),Qx=(e,t)=>e+" ".repeat(Math.max(0,t-Zr(e))),Zx=(e,t)=>" ".repeat(Math.max(0,t-Zr(e)))+e;function Ge(e,t){if(t<=0)return"";if(Zr(e)<=t)return e;let n=t-Jx,o="";for(let r of ol(e)){if(Zr(o+r)>n)break;o+=r}return o+ie.ellipsis}var Vn=e=>e.replaceAll(" "," "),Qe=(e,t)=>Qx(Ge(e,t),t),Kn=(e,t)=>Zx(Ge(e,t),t),_e=e=>e.filter(t=>typeof t=="string"&&t!=="").join(` ${ie.bullet} `);var tT=e=>e.startsWith("#")||Oi(e)!==null,nT={spans:[]},xs=e=>e===void 0||e.spans.every(t=>t.text.trim()==="");function mp(e){let t=[];for(let n of e){let o=t[t.length-1];o!==void 0&&o.color===n.color&&o.bold===n.bold?o.text+=n.ch:t.push({text:n.ch,color:n.color,bold:n.bold})}return{spans:t}}var oT=new Set([..."\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300D\u300F\u3011\u300B\u2026\u201D\u2019,.;:!?)]}"]),rT=new Set([..."\uFF08\u300C\u300E\u3010\u300A\u201C\u2018([{"]),iT=(e,t)=>(Qo(e)>1||Qo(t)>1)&&!rT.has(e)&&!oT.has(t);function sT(e,t,n){for(let o=e.length;o>n;o-=1){if(e[o]?.ch===" ")return{end:o,carry:o+1};let r=e[o-1]?.ch,i=o===e.length?t:e[o]?.ch;if(r!==void 0&&i!==void 0&&r!==" "&&iT(r,i))return{end:o,carry:o}}return null}function aT(e){let t=[],n=0,o=0,r=0;for(let i of ol(e.map(s=>s.text).join(""))){let s=e[n];for(;s!==void 0&&r>=o+s.text.length;)o+=s.text.length,n+=1,s=e[n];if(s===void 0)break;t.push({ch:i,color:s.color,bold:s.bold}),r+=i.length}return t}function Pt(e,t,n=0){let o=()=>Array.from({length:n},()=>({ch:" "})),r=[],i=[],s=0,a=()=>{r.push(mp(i)),i=o(),s=n};for(let c of aT(e)){let{ch:l}=c;if(l===`
2
+ import{once as WR}from"events";import{createInterface as VR}from"readline/promises";import{parseArgs as KR}from"util";var km={name:"@codeflow-ai/cli",version:"1.30.0",type:"module",description:"CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF\uFF1A\u4E00\u952E\u914D\u7F6E AI \u5BA2\u6237\u7AEF",keywords:["codeflow","claude-code","codex","openclaw","hermes-agent","opencode","pi-coding-agent","cli"],license:"UNLICENSED",engines:{node:">=22"},bin:{codeflow:"dist/cli.js"},files:["dist"],publishConfig:{access:"public"},scripts:{dev:"tsx src/cli.ts",build:"tsup",typecheck:"tsc --noEmit"},dependencies:{"@decimalturn/toml-patch":"3.0.4",ink:"7.1.1",json5:"2.2.3","jsonc-parser":"3.3.1",marked:"18.0.9",qrcode:"1.5.4",react:"19.2.0","smol-toml":"1.9.0","string-width":"8.2.0",yaml:"2.9.1",zod:"4.4.3"},devDependencies:{"@codeflow/shared":"workspace:*","@types/node":"25.9.1","@types/qrcode":"1.5.6","@types/react":"19.2.2",tsup:"8.5.1",tsx:"4.22.3",typescript:"5.9.3"}};var Wt="codeflow",Vt=km.version,vm="https://codeflow.asia",Fo="@codeflow-ai/cli",Rr=0,Uo=1,qa=2,ro=3,Cm=4;import{randomBytes as lS}from"crypto";import{mkdirSync as Em,readFileSync as mS,rmSync as Mm,statSync as uS,writeFileSync as dS}from"fs";import{join as Im}from"path";import{setTimeout as pS}from"timers/promises";import{z as rn}from"zod";var U=class extends Error{exitCode;hint;constructor(t,n={}){super(t,{cause:n.cause}),this.name="CliError",this.exitCode=n.exitCode??Uo,this.hint=n.hint}};function xe(e){return e instanceof Error?e.message:String(e)}import{chmodSync as nS,existsSync as oS,mkdirSync as rS,readFileSync as iS,writeFileSync as sS}from"fs";import{dirname as aS}from"path";function Nt(e){return oS(e)?iS(e,"utf8"):null}function kn(e,t,n){rS(aS(e),{recursive:!0,mode:448});try{sS(e,t,{mode:n}),nS(e,n)}catch(o){throw new U(`\u5199\u5165 ${e} \u5931\u8D25\uFF1A${xe(o)}`,{cause:o})}}function Rm(e,t,n){kn(e,`${JSON.stringify(t,null,2)}
3
+ `,n)}function _i(e,t,n,o,r){let i=null,s=()=>{if(i)return i;let a=n(),c=Nt(a);if(c===null)return i=structuredClone(t),i;let l;try{l=JSON.parse(c)}catch(m){throw new U(`${o} ${a} \u5DF2\u635F\u574F\uFF0C\u8BF7\u5220\u9664\u8BE5\u6587\u4EF6\u540E${r}`,{cause:m})}let u=e.safeParse(l);if(!u.success)throw new U(`${o} ${a} \u7ED3\u6784\u4E0D\u7B26\uFF0C\u8BF7\u5220\u9664\u8BE5\u6587\u4EF6\u540E${r}`);return i=u.data,i};return{load:s,reload:()=>(i=null,s()),update:a=>{let c=structuredClone(s());return a(c),Rm(n(),c,384),i=c,c}}}import{homedir as cS}from"os";import{join as jo}from"path";function vn(){let e=process.env.XDG_CONFIG_HOME;if(e)return jo(e,"codeflow");if(process.platform==="win32"){let t=process.env.APPDATA;if(t)return jo(t,"codeflow")}return jo(cS(),".config","codeflow")}var _m=()=>jo(vn(),"config.json"),Pm=()=>jo(vn(),"credentials.json"),Am=()=>jo(vn(),"refresh.lock");var fS=rn.object({refreshCookie:rn.string(),accessToken:rn.string(),accessExpiresAt:rn.number(),username:rn.string(),email:rn.string(),site:rn.string()}),gS=rn.object({site:rn.string(),cookie:rn.string()}),hS=rn.object({session:fS.nullable(),device:gS.nullable()}),Ga=_i(hS,{session:null,device:null},Pm,"\u672C\u5730\u51ED\u636E","\u91CD\u65B0\u767B\u5F55"),Lt=Ga.load,Nm=Ga.reload,za=Ga.update;function Lm(){let{session:e}=Lt();if(!e)throw new U("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return e}var yS=6e4,bS=75e3,SS=120;function xS(e,t){try{Em(e)}catch{try{Date.now()-uS(e).mtimeMs>yS&&Mm(e,{recursive:!0,force:!0})}catch{}return!1}return dS(Im(e,"owner"),t),!0}function TS(e,t){let n;try{n=mS(Im(e,"owner"),"utf8")}catch{return}n===t&&Mm(e,{recursive:!0,force:!0})}async function Om(e){let t=Am(),n=lS(16).toString("hex");Em(vn(),{recursive:!0,mode:448});let o=Date.now()+bS;for(;!xS(t,n);){if(Date.now()>o)throw new U(`\u7B49\u5F85\u5237\u65B0\u9501\u8D85\u65F6\uFF0C\u82E5\u786E\u8BA4\u6CA1\u6709\u5176\u4ED6 ${Wt} \u5728\u8FD0\u884C\uFF0C\u8BF7\u5220\u9664 ${t}`);await pS(SS)}try{return await e()}finally{TS(t,n)}}function wS(){let e=process.env.CODEFLOW_SITE;if(e)return e;let t=Lt().session;return t?t.site:vm}function Dm(){return{site:wS()}}function io(e,t,n){if(!e.isTTY)return n;let o=Number.parseInt(t.slice(1),16);return`\x1B[38;2;${o>>16&255};${o>>8&255};${o&255}m${n}\x1B[39m`}import{existsSync as vx,rmSync as Cx}from"fs";import{z as je}from"zod";var kS=["active","disabled"],M_=je.enum(kS),Wa=["subscription_first","balance_first","subscription_only","balance_only"],Va=je.enum(Wa),vS=["openai","anthropic"],$m=je.enum(vS),CS=["openai-chat","openai-responses","anthropic-messages"],Bm=je.enum(CS);var _r=["pending","paid","refund_requested","partially_refunded","refunded","failed","expired"],Fm=je.enum(_r),RS=["recharge","subscription"],Ka=je.enum(RS),_S=["requested","pending","succeeded","failed","rejected","canceled"],Um=je.enum(_S),Ya=["pending","issued","rejected"],jm=je.enum(Ya),PS=["special","general"],Ja=je.enum(PS),AS=["info","success","warning","error"],Hm=je.enum(AS),ES=["terms","privacy"],I_=je.enum(ES),Xa=["recharge","reserve","consume","reserve_refund","refund","refund_release","reward","admin_adjust"],qm=je.enum(Xa),MS=["usage_log","order","invitation","admin"],Gm=je.enum(MS),Qa=["first_inviter","first_invitee","subsequent_inviter"],zm=je.enum(Qa),Za=["success","error","canceled","anomaly"],Wm=je.enum(Za),ec=["open","replied","closed"],Vm=je.enum(ec),tc=["billing","technical","account","other"],Km=je.enum(tc),nc=["low","normal","high"],Ym=je.enum(nc),IS=["user","admin"],Jm=je.enum(IS),NS=["pending","published","rejected","removed"],Pr=je.enum(NS),oc=["activity","published"],Xm=je.enum(oc),Pi=["spam","abuse","explicit","illegal","privacy","other"],Qm=je.enum(Pi),LS=["none","minor","major","critical"],Zm=je.enum(LS);import{z as Ho}from"zod";var OS=["internal_error","validation_error","not_found","conflict","rate_limited","forbidden","unauthorized","invalid_credentials","password_incorrect","account_disabled","email_already_registered","username_taken","verification_code_invalid","verification_code_expired","token_expired","token_reuse_detected","token_limit_exceeded","totp_invalid","totp_replayed","totp_setup_expired","totp_not_enabled","login_ticket_invalid","recovery_code_invalid","passkey_registration_failed","passkey_verification_failed","passkey_not_found","passkey_origin_not_allowed","insufficient_quota","no_available_channel","model_not_found","model_not_in_group","token_group_missing","token_quota_exceeded","upstream_error","order_not_found","order_not_payable","payment_verify_failed","payment_precreate_failed","amount_mismatch","refund_not_allowed","refund_amount_invalid","refund_insufficient_balance","refund_failed","refund_pending","refund_in_progress","refund_blocked_by_pending_order","refund_order_superseded","refund_request_not_found","refund_nothing_refundable","subscription_limit_reached","no_subscription_coverage","subscription_revoked","plan_disabled","order_already_invoiced","order_not_eligible","order_invoiced","invoice_profile_exists","invite_code_invalid","ticket_closed","ticket_limit_exceeded","attachment_storage_unconfigured","attachment_too_large","attachment_image_too_large","attachment_invalid","attachment_staging_limit_exceeded","docs_not_configured","docs_source_unavailable","docs_page_not_found","provider_status_unavailable","community_muted","community_state_changed","community_category_missing"],DS=Ho.enum(OS),eu=Ho.object({error:Ho.object({code:DS,message:Ho.string(),details:Ho.unknown().optional(),requestId:Ho.string().optional()})});var tu={internal_error:"\u670D\u52A1\u6682\u65F6\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",validation_error:"\u63D0\u4EA4\u7684\u5185\u5BB9\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5",not_found:"\u8BBF\u95EE\u7684\u5185\u5BB9\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",conflict:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u8BB0\u5F55\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4",rate_limited:"\u64CD\u4F5C\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",forbidden:"\u6CA1\u6709\u6743\u9650\u6267\u884C\u6B64\u64CD\u4F5C",unauthorized:"\u8BF7\u5148\u767B\u5F55",invalid_credentials:"\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E",password_incorrect:"\u5F53\u524D\u5BC6\u7801\u4E0D\u6B63\u786E",account_disabled:"\u8D26\u6237\u5DF2\u88AB\u7981\u7528\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",email_already_registered:"\u8BE5\u90AE\u7BB1\u5DF2\u88AB\u6CE8\u518C",username_taken:"\u8BE5\u7528\u6237\u540D\u5DF2\u88AB\u4F7F\u7528",verification_code_invalid:"\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E",verification_code_expired:"\u9A8C\u8BC1\u7801\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u83B7\u53D6",token_expired:"\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_reuse_detected:"\u767B\u5F55\u72B6\u6001\u5F02\u5E38\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_limit_exceeded:"\u4EE4\u724C\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5220\u9664\u4E0D\u518D\u4F7F\u7528\u7684\u4EE4\u724C",totp_invalid:"\u52A8\u6001\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E\uFF0C\u8BF7\u91CD\u8BD5",totp_replayed:"\u8BE5\u9A8C\u8BC1\u7801\u521A\u521A\u5DF2\u88AB\u4F7F\u7528\uFF0C\u8BF7\u7B49\u5F85\u9A8C\u8BC1\u5668\u663E\u793A\u4E0B\u4E00\u4E2A\u9A8C\u8BC1\u7801\u540E\u518D\u8F93\u5165",totp_setup_expired:"\u7ED1\u5B9A\u4F1A\u8BDD\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5F00\u59CB\u7ED1\u5B9A",totp_not_enabled:"\u5C1A\u672A\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",login_ticket_invalid:"\u767B\u5F55\u9A8C\u8BC1\u5DF2\u8FC7\u671F\u6216\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",recovery_code_invalid:"\u6062\u590D\u7801\u4E0D\u6B63\u786E\u6216\u5DF2\u88AB\u4F7F\u7528",passkey_registration_failed:"Passkey \u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_verification_failed:"Passkey \u9A8C\u8BC1\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_not_found:"\u8BE5 Passkey \u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",passkey_origin_not_allowed:"\u5F53\u524D\u8BBF\u95EE\u5730\u5740\u672A\u914D\u7F6E\u4E3A\u7AD9\u70B9\u5730\u5740\uFF0C\u65E0\u6CD5\u4F7F\u7528 Passkey",insufficient_quota:"\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u8BD5",no_available_channel:"\u4E0A\u6E38\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",model_not_found:"\u8BE5\u6A21\u578B\u4E0D\u5B58\u5728",model_not_in_group:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u4E0D\u652F\u6301\u8BE5\u6A21\u578B\uFF0C\u8BF7\u66F4\u6362\u4EE4\u724C\u5206\u7EC4\u6216\u6539\u7528\u5206\u7EC4\u652F\u6301\u7684\u6A21\u578B",token_group_missing:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BF7\u7F16\u8F91\u4EE4\u724C\u91CD\u65B0\u9009\u62E9\u5206\u7EC4",token_quota_exceeded:"\u8BE5\u4EE4\u724C\u7684\u6D88\u8D39\u5DF2\u8FBE\u8D39\u7528\u9650\u5236\uFF0C\u8BF7\u8C03\u9AD8\u6216\u6E05\u9664\u9650\u5236\u540E\u518D\u4F7F\u7528",upstream_error:"\u4E0A\u6E38\u670D\u52A1\u8FD4\u56DE\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",order_not_found:"\u8BA2\u5355\u4E0D\u5B58\u5728",order_not_payable:"\u8BA2\u5355\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u518D\u8BD5",payment_verify_failed:"\u652F\u4ED8\u7ED3\u679C\u786E\u8BA4\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",payment_precreate_failed:"\u53D1\u8D77\u652F\u4ED8\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",amount_mismatch:"\u652F\u4ED8\u91D1\u989D\u4E0E\u8BA2\u5355\u4E0D\u7B26\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",refund_not_allowed:"\u8BE5\u8BA2\u5355\u5F53\u524D\u4E0D\u53EF\u9000\u6B3E",refund_amount_invalid:"\u9000\u6B3E\u91D1\u989D\u4E0D\u6B63\u786E\u6216\u8D85\u8FC7\u53EF\u9000\u4F59\u989D",refund_insufficient_balance:"\u53EF\u7528\u989D\u5EA6\u4E0D\u8DB3\u4EE5\u6263\u56DE\u672C\u6B21\u9000\u6B3E\uFF08\u5DF2\u6D88\u8017\u90E8\u5206\u5BF9\u5E94\u7684\u73B0\u91D1\u4E0D\u53EF\u9000\uFF09",refund_failed:"\u652F\u4ED8\u5B9D\u9000\u6B3E\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u68C0\u67E5\u652F\u4ED8\u5B9D\u5546\u6237\u540E\u53F0",refund_pending:"\u9000\u6B3E\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u8BF7\u7A0D\u540E\u67E5\u770B\u9000\u6B3E\u8BB0\u5F55",refund_in_progress:"\u8BE5\u8BA2\u5355\u6216\u8BA2\u9605\u6709\u9000\u6B3E\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u5F85\u5176\u5B8C\u6210\u540E\u518D\u64CD\u4F5C",refund_blocked_by_pending_order:"\u8BE5\u8BA2\u9605\u6709\u5F85\u652F\u4ED8\u7684\u7EED\u8D39\u8BA2\u5355\uFF0C\u8BF7\u5F85\u5176\u652F\u4ED8\u6216\u8D85\u65F6\u540E\u518D\u9000\u6B3E",refund_order_superseded:"\u5B58\u5728\u66F4\u665A\u5165\u8D26\u7684\u8BA2\u5355\uFF0C\u8BF7\u6309\u4ECE\u65B0\u5230\u65E7\u7684\u987A\u5E8F\u9000\u6B3E",refund_request_not_found:"\u9000\u6B3E\u7533\u8BF7\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5904\u7406\uFF0C\u8BF7\u5237\u65B0\u540E\u67E5\u770B",refund_nothing_refundable:"\u8BE5\u8BA2\u9605\u8BA2\u5355\u6309\u9650\u989D\u5468\u671F\u8BA1\u8D39\u540E\u5DF2\u65E0\u53EF\u9000\u91D1\u989D",subscription_limit_reached:"\u8BA2\u9605\u989D\u5EA6\u5DF2\u7528\u5C3D\uFF0C\u8BF7\u7B49\u5F85\u7A97\u53E3\u91CD\u7F6E",no_subscription_coverage:"\u5F53\u524D\u5206\u7EC4\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\uFF0C\u8BF7\u8BA2\u9605\u5957\u9910\u6216\u8C03\u6574\u6263\u8D39\u65B9\u5F0F",subscription_revoked:"\u8BE5\u8BA2\u9605\u5DF2\u88AB\u4F5C\u5E9F",plan_disabled:"\u8BE5\u5957\u9910\u5DF2\u505C\u552E",order_already_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u7533\u8BF7\u8FC7\u53D1\u7968",order_not_eligible:"\u6240\u9009\u8BA2\u5355\u4E0D\u7B26\u5408\u5F00\u7968\u6761\u4EF6",order_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u5F00\u7968\u6216\u6709\u672A\u5904\u7406\u7684\u5F00\u7968\u7533\u8BF7\uFF0C\u65E0\u6CD5\u9000\u6B3E",invoice_profile_exists:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u5E38\u7528\u5F00\u7968\u4FE1\u606F",invite_code_invalid:"\u9080\u8BF7\u7801\u65E0\u6548",ticket_closed:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u8BF7\u5148\u91CD\u65B0\u6253\u5F00\u540E\u518D\u56DE\u590D",ticket_limit_exceeded:"\u672A\u5173\u95ED\u7684\u5DE5\u5355\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5173\u95ED\u5DF2\u89E3\u51B3\u7684\u5DE5\u5355",attachment_storage_unconfigured:"\u5C1A\u672A\u914D\u7F6E\u9644\u4EF6\u5B58\u50A8",attachment_too_large:"\u9644\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236",attachment_image_too_large:"\u56FE\u7247\u5C3A\u5BF8\u6216\u5E27\u6570\u8D85\u8FC7\u9650\u5236",attachment_invalid:"\u9644\u4EF6\u65E0\u6548\u6216\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20",attachment_staging_limit_exceeded:"\u5F85\u63D0\u4EA4\u7684\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u63D0\u4EA4\u73B0\u6709\u9644\u4EF6",docs_not_configured:"\u6587\u6863\u4E2D\u5FC3\u672A\u542F\u7528",docs_source_unavailable:"\u6587\u6863\u5185\u5BB9\u83B7\u53D6\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",docs_page_not_found:"\u8BE5\u6587\u6863\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",provider_status_unavailable:"\u5B98\u65B9\u670D\u52A1\u72B6\u6001\u6682\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",community_muted:"\u8D26\u53F7\u5904\u4E8E\u7981\u8A00\u671F\u95F4\uFF0C\u6682\u65F6\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D",community_state_changed:"\u5185\u5BB9\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5",community_category_missing:"\u6240\u9009\u677F\u5757\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9"};import{z as qo}from"zod";var $S=qo.string().trim().min(1),rc=$S.pipe(qo.url()),BS=qo.object({name:qo.string().trim().min(1),description:qo.string().trim().min(1),url:rc}),B_=qo.array(BS);function nu(e){return`codeflow-cli/${e.cliVersion} (${e.platform} ${e.release}; ${e.arch}) node/${e.nodeVersion}`}function Go(e){if(!e)return"\u672A\u77E5\u8BBE\u5907";let t=e.type==="cli"?e.clientVersion:e.clientVersion?.split(".")[0],o=[e.client?t?`${e.client} ${t}`:e.client:null,e.os].filter(r=>r!==null);return o.length>0?o.join(" \xB7 "):"\u672A\u77E5\u8BBE\u5907"}import{z as dn}from"zod";var ic=1e8;var H_=dn.object({id:dn.coerce.number().int().positive()}),ou=100,ru=dn.object({page:dn.coerce.number().int().min(1)});function mt(e){return dn.object({items:dn.array(e),total:dn.number()})}var se=dn.object({ok:dn.literal(!0)}),iu=(e=dn.string().trim())=>e.nullable().optional().transform(t=>t==null||t.length===0?null:t);import{z as ce}from"zod";var so=ce.email().max(254).toLowerCase(),Ot=8,Ar=ce.string().min(Ot).max(128),Er=ce.string().min(1).max(128),Kt=32,sc=ce.string().trim().min(1).max(Kt),ac=ce.string().trim().min(1).max(254),z_=ce.object({email:so}),W_=ce.object({username:sc,email:so,password:Ar,code:ce.string().min(4).max(8),inviteCode:ce.string().trim().min(1).max(32).optional()}),V_=ce.object({account:ac,password:Er}),K_=ce.object({email:so,code:ce.string().min(4).max(8),password:Ar}),Y_=ce.object({oldPassword:Er,newPassword:Ar}),J_=ce.object({email:so}),X_=ce.object({email:so,code:ce.string().min(4).max(8),password:Er}),su=ce.object({username:ce.string(),email:ce.string(),avatarUrl:ce.string().nullable()}),zo=ce.object({accessToken:ce.string(),user:su}),au=ce.discriminatedUnion("status",[zo.extend({status:ce.literal("ok")}),ce.object({status:ce.literal("totp_required"),ticket:ce.string()})]),cu=ce.object({user:su}),cc=ce.object({client:ce.string().nullable(),clientVersion:ce.string().nullable(),os:ce.string().nullable(),osVersion:ce.string().nullable(),type:ce.string().nullable(),vendor:ce.string().nullable(),model:ce.string().nullable()}),FS=ce.object({id:ce.number().int(),ip:ce.string(),userAgent:ce.string().nullable(),device:cc.nullable(),loginAt:ce.string(),lastActiveAt:ce.string(),expiresAt:ce.string(),current:ce.boolean()}),lu=ce.object({sessions:ce.array(FS)});import{z as ke}from"zod";var Wo=ke.string().trim().length(6),US=ke.string().trim().min(10).max(20),Ai=ke.string().trim().min(1).max(64),Ei=ke.record(ke.string(),ke.unknown()),e0=ke.object({ticket:ke.string().min(1),code:Wo}),t0=ke.object({ticket:ke.string().min(1),code:US}),n0=ke.object({code:Wo.optional()}),o0=ke.object({code:Wo}),mu=ke.object({secret:ke.string(),otpauthUri:ke.string()}),lc=ke.object({recoveryCodes:ke.array(ke.string())}),jS=ke.object({id:ke.number().int(),name:ke.string(),createdAt:ke.string(),lastUsedAt:ke.string().nullable()}),uu=ke.object({totp:ke.object({enabled:ke.boolean(),enabledAt:ke.string().nullable(),recoveryCodesRemaining:ke.number().int()}),passkeys:ke.array(jS)}),r0=ke.object({name:Ai,response:Ei}),i0=ke.object({name:Ai}),s0=ke.object({response:Ei});import{z as Ne}from"zod";var u0=Ne.object({account:ac,password:Er}),HS=Ne.object({totp:Ne.boolean(),passkeys:Ne.boolean()}),d0=Ne.discriminatedUnion("status",[Ne.object({status:Ne.literal("totp_required"),ticket:Ne.string()}),Ne.object({status:Ne.literal("setup_required"),ticket:Ne.string(),missing:HS})]),p0=Ne.object({ticket:Ne.string().min(1)}),f0=Ne.object({ticket:Ne.string().min(1),code:Wo}),g0=Ne.object({ticket:Ne.string().min(1),name:Ai,response:Ei}),h0=Ne.object({ticket:Ne.string().min(1),code:Wo.optional()}),du=Ne.object({username:Ne.string(),email:Ne.string(),avatarUrl:Ne.string().nullable()}),y0=Ne.object({accessToken:Ne.string(),admin:du}),b0=Ne.object({admin:du});import{z as mc}from"zod";var k0=mc.object({siteName:mc.string().trim().min(1).max(64),siteDescription:mc.string().trim().max(200).optional(),siteOrigin:rc,username:sc,email:so,password:Ar});import{z as $e}from"zod";var pu={orderNo:$e.string(),amountCny:$e.number().int(),status:Fm,credited:$e.boolean(),refundedAmountCny:$e.number().int(),succeededRefundCny:$e.number().int(),pendingRefundCny:$e.number().int(),createdAt:$e.string()},Mr=$e.object({...pu,quota:$e.number(),refundedQuota:$e.number()}),Ir=$e.object({...pu,planName:$e.string(),renewal:$e.boolean(),grantedDurationDays:$e.number().int()}),Mi=$e.object({order:Mr.pick({orderNo:!0,amountCny:!0,quota:!0}),qrCode:$e.string()}),Nr=$e.object({order:Ir.pick({orderNo:!0,amountCny:!0,planName:!0,grantedDurationDays:!0}),qrCode:$e.string()}),fu=$e.object({id:$e.number().int(),amountCny:$e.number().int(),status:Um,refundTradeNo:$e.string().nullable(),reason:$e.string().nullable(),rejectReason:$e.string().nullable(),createdAt:$e.string()});function gu(e){return e.status!=="paid"&&e.status!=="partially_refunded"||e.pendingRefundCny>0?!1:e.kind==="recharge"?e.refundedAmountCny<e.amountCny:e.refundedAmountCny===0}import{z as ut}from"zod";import{z as Yt}from"zod";var uc=Yt.object({kind:Yt.literal("user"),username:Yt.string(),avatarUrl:Yt.string().nullable(),points:Yt.number().int()}),dc=Yt.object({kind:Yt.literal("admin"),username:Yt.string(),avatarUrl:Yt.string().nullable()}),Vo=Yt.discriminatedUnion("kind",[uc,dc]),hu=Yt.object({kind:Jm,username:Yt.string()});var Ii=ut.object({id:ut.number().int(),title:ut.string(),category:Km,priority:Ym,status:Vm,createdAt:ut.string(),updatedAt:ut.string()}),yu=Ii.pick({id:!0}),bu=25*1024*1024,Su=5,xu=ut.object({id:ut.number().int(),fileName:ut.string(),fileSize:ut.number().int(),contentType:ut.string()}),Tu=xu.pick({id:!0,fileSize:!0}),qS=ut.object({id:ut.number().int(),author:Vo,content:ut.string(),attachments:ut.array(xu),createdAt:ut.string()}),wu=ut.object({ticket:Ii,messages:ut.array(qS)});import{z as Lr}from"zod";var pc=Lr.object({id:Lr.number().int(),title:Lr.string(),content:Lr.string(),level:Hm,publishedAt:Lr.string()});import{z as Ye}from"zod";var fc=100,ku=Ye.object({groups:Ye.array(Ye.object({title:Ye.string(),items:Ye.array(Ye.object({slug:Ye.string(),title:Ye.string()}))}))}),vu=Ye.object({title:Ye.string(),markdown:Ye.string(),images:Ye.record(Ye.string(),Ye.object({width:Ye.number().int(),height:Ye.number().int()}))}),Cu=Ye.object({slug:Ye.string(),title:Ye.string(),anchor:Ye.string().nullable(),snippet:Ye.string()});function Ru(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-")}function gc(e){try{return decodeURIComponent(e)}catch{return e}}function Ni(e){if(!e.startsWith("/guides/"))return null;let t=e.indexOf("#");return{slug:(t===-1?e:e.slice(0,t)).slice(8,-3),anchor:t===-1?null:gc(e.slice(t+1))}}import{z as ot}from"zod";function Le(e){return e.toLocaleString("en-US")}function qn(e){let t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(1)}B`:t>=1e6?`${(e/1e6).toFixed(1)}M`:t>=1e3?`${(e/1e3).toFixed(1)}k`:Le(e)}function pn(e,t){return e===0&&t!==void 0?t:e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:6})}function ao(e){return(e/1e3).toFixed(2)}function Ko(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${(e/1024**2).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Li(e,t){return`${e}******${t}`}var hc=ot.object({inputPricePerMillionTokens:ot.number(),outputPricePerMillionTokens:ot.number(),cachedInputPricePerMillionTokens:ot.number(),cacheWritePricePerMillionTokens:ot.number()});var GS=ot.number().int().nonnegative(),zS=ot.discriminatedUnion("kind",[hc.extend({kind:ot.literal("price"),inputTokensOver:GS}),ot.object({kind:ot.literal("multiplier"),param:ot.string(),value:ot.string(),multiplier:ot.number()})]),_u=ot.array(zS);function WS(e){return e.kind==="price"}function Pu(e){return e.kind==="multiplier"}function Au(e){return e>=1e6&&e%1e5===0?`${e/1e6}M`:e>=1e3&&e%1e3===0?`${e/1e3}k`:Le(e)}function Or(e){return e===null?"\u57FA\u7840":"\u6269\u5C55"}function yc(e){return`> ${Au(e)}`}function Eu(e,t){let n=t.filter(WS).sort((r,i)=>r.inputTokensOver-i.inputTokensOver),o=n[0];return o===void 0?[{name:Or(null),range:null,price:e}]:[{name:Or(null),range:`\u2264 ${Au(o.inputTokensOver)}`,price:e},...n.map(r=>({name:Or(r.inputTokensOver),range:yc(r.inputTokensOver),price:r}))]}var VS=ot.object({value:ot.string(),multiplier:ot.number()}),Mu=ot.array(VS);function Iu(e){return Lu(e.map(t=>t.multiplier))}function Nu(e,t){return Lu([e,...t.map(n=>n.multiplier)])}function Lu(e){return Number(e.reduce((t,n)=>t*n,1).toFixed(4))}import{z as co}from"zod";var KS=co.object({provider:$m,pageUrl:co.string(),indicator:Zm,incidents:co.array(co.object({title:co.string()}))}),Ou=co.object({providers:co.array(KS)}),YS={minor:{label:"\u90E8\u5206\u964D\u7EA7",tone:"warning"},major:{label:"\u90E8\u5206\u4E2D\u65AD",tone:"danger"},critical:{label:"\u4E25\u91CD\u4E2D\u65AD",tone:"danger"}};function Du(e){return e.filter(t=>t.indicator!=="none"||t.incidents.length>0)}function $u(e){return e.indicator==="none"?{label:"\u4E8B\u4EF6\u5904\u7406\u4E2D",tone:"warning"}:YS[e.indicator]}import{z as lo}from"zod";var Dr=25*1024*1024,Bu=20,Fu=5;var bc="/api/media/";function Uu(e){return`${bc}${e}`}var ju=lo.object({width:lo.number().int(),height:lo.number().int()}),Oi=lo.record(lo.string(),ju),Hu=lo.object({id:lo.number().int(),image:ju.nullable()}),qu=String.raw`([1-9]\d{0,14})`,K0=new RegExp(String.raw`^${bc}${qu}$`),Gu=new RegExp(String.raw`(!?)\[((?:\\.|[^\\\]\n])*)\]\(${bc}${qu}(?:\s+"[^"\n]*")?\)`,"g");function zu(e,t,n){return{id:Number(n),image:e==="!",name:t.replace(/\\(.)/g,"$1")}}function Wu(e){return[...e.matchAll(Gu)].map(([,t="",n="",o=""])=>zu(t,n,o))}function Sc(e,t){return e.replace(Gu,(n,o,r,i)=>t(zu(o,r,i)))}import{z as dt}from"zod";import{z as I}from"zod";var mo=100,Di=2e4,xc=5e3,$i=500,Bi=64,JS=new RegExp("\\p{Cc}","u"),XS=new RegExp("(?![\\n\\t])\\p{Cc}","u");function Tc(e){return I.string().trim().max(e).refine(t=>!JS.test(t))}function wc(e){return I.string().trim().max(e).refine(t=>!XS.test(t))}var nP=I.object({categoryId:I.number().int().positive(),title:Tc(mo).min(1),content:wc(Di).min(1)}),oP=I.object({categoryId:I.number().int().positive().nullable(),title:Tc(mo),content:wc(Di)}),rP=I.object({content:wc(xc).min(1),replyToId:I.number().int().positive().optional()}),iP=I.object({reason:Qm,detail:iu(Tc($i))}),sP=ru.extend({sort:Xm,categoryId:I.coerce.number().int().positive().optional(),q:I.string().trim().min(1).max(Bi).optional(),author:I.string().trim().min(1).max(Kt).optional()}),kc=I.object({id:I.number().int(),name:I.string(),description:I.string()}),Fi=kc.pick({id:!0,name:!0}),$r=I.object({id:I.number().int(),title:I.string()}),Yo=I.object({id:I.number().int(),title:I.string().nullable()}),aP=I.object({posts:I.array(I.object({id:I.number().int(),lastModified:I.string()})),users:I.array(I.string()),staff:I.array(I.string())}),vc=I.object({id:I.number().int(),title:I.string(),category:Fi,author:Vo,commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),lastActivityAt:I.string()}),Cc=I.object({id:I.number().int(),title:I.string(),content:I.string(),images:Oi,category:Fi,author:Vo,status:Pr,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),coverUrl:I.string().nullable(),createdAt:I.string(),publishedAt:I.string().nullable(),editedAt:I.string().nullable(),liked:I.boolean(),bookmarked:I.boolean()}),Vu={id:I.number().int(),author:Vo,content:I.string(),images:Oi,status:Pr,reviewReason:I.string().nullable(),likeCount:I.number().int(),liked:I.boolean(),createdAt:I.string()},Rc=I.object({...Vu,replyTo:I.object({id:I.number().int(),author:hu}).nullable()}),Ui=I.object({...Vu,floor:I.number().int().nullable(),replyCount:I.number().int(),replies:I.array(Rc)}),_c=I.object({likeCount:I.number().int()}),Ku=Cc.pick({id:!0}),Yu=Ui.pick({id:!0}),QS=I.object({status:I.enum(["pending","rejected","removed"]),reviewReason:I.string().nullable()}),Pc=I.object({review:QS.nullable()}),Br=I.object({id:I.number().int(),title:I.string(),category:Fi,status:Pr,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),createdAt:I.string(),publishedAt:I.string().nullable()}),ji=I.object({id:I.number().int(),content:I.string(),post:Yo,floorId:I.number().int(),status:Pr,reviewReason:I.string().nullable(),likeCount:I.number().int(),createdAt:I.string()}),Ac=I.object({id:I.number().int(),category:Fi.nullable(),title:I.string(),content:I.string(),images:Oi,createdAt:I.string()}),Ju=I.object({posts:I.array(Br),drafts:I.number().int()}),Xu=Ac.pick({id:!0}),Qu=I.object({muted:I.object({reason:I.string(),until:I.string().nullable()}).nullable()});var ZS=dt.object({posts:dt.number().int(),comments:dt.number().int(),likesReceived:dt.number().int()}),ex=dt.object({start:dt.string(),end:dt.string(),days:dt.array(dt.object({day:dt.string(),count:dt.number().int()}))}),tx=dt.object({posts:dt.array(Br),comments:dt.array(ji)}),Zu={joinedAt:dt.string(),stats:ZS,activity:ex,overview:tx},ed=dt.object({identity:uc,...Zu}),td=dt.object({identity:dc,...Zu});import{z as q}from"zod";var tt={id:q.number().int(),read:q.boolean(),createdAt:q.string()},Fr=q.object({floorId:q.number().int()}),nd=q.object({username:q.string()}),od=q.discriminatedUnion("kind",[q.object({...tt,kind:q.literal("post_commented"),post:$r,comment:Fr,actor:nd}),q.object({...tt,kind:q.literal("comment_replied"),post:Yo,comment:Fr,actor:nd}),q.object({...tt,kind:q.literal("post_approved"),post:$r}),q.object({...tt,kind:q.literal("post_rejected"),post:$r,reason:q.string()}),q.object({...tt,kind:q.literal("post_removed"),post:$r,reason:q.string()}),q.object({...tt,kind:q.literal("comment_approved"),post:Yo,comment:Fr}),q.object({...tt,kind:q.literal("comment_rejected"),post:Yo,comment:Fr,reason:q.string()}),q.object({...tt,kind:q.literal("comment_removed"),post:Yo,comment:Fr,reason:q.string()}),q.object({...tt,kind:q.literal("avatar_approved")}),q.object({...tt,kind:q.literal("avatar_rejected"),reason:q.string()}),q.object({...tt,kind:q.literal("avatar_removed"),reason:q.string()}),q.object({...tt,kind:q.literal("ticket_replied"),ticket:q.object({id:q.number().int(),title:q.string()})}),q.object({...tt,kind:q.literal("invoice_issued"),invoice:q.object({title:q.string(),amountCny:q.number().int()})}),q.object({...tt,kind:q.literal("invoice_rejected"),invoice:q.object({title:q.string()}),reason:q.string()}),q.object({...tt,kind:q.literal("refund_approved"),refund:q.object({orderNo:q.string(),orderType:Ka,amountCny:q.number().int()})}),q.object({...tt,kind:q.literal("refund_rejected"),refund:q.object({orderNo:q.string(),orderType:Ka}),reason:q.string()}),q.object({...tt,kind:q.literal("subscription_expiring"),subscription:q.object({planName:q.string(),expiresAt:q.string()})}),q.object({...tt,kind:q.literal("email_changed"),newEmail:q.string()}),q.object({...tt,kind:q.literal("new_device_login"),ip:q.string(),device:cc.nullable()})]),rd=q.object({unread:q.boolean()});var id="Asia/Shanghai",nx="+08:00";function ox(e){return new Date(new Date(e).getTime()+288e5)}function rx(e=Date.now()){let t=ox(e);return{day:t.toISOString().slice(0,10),hour:t.getUTCHours()}}function Ec(e=Date.now()){return rx(e).day}function Mc(e=Ec()){return new Date(`${e}T00:00:00${nx}`)}function Gn(e,t){let n=new Date(`${e}T00:00:00Z`);return new Date(n.getTime()+t*864e5).toISOString().slice(0,10)}var ix=new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium",timeZone:id}),sx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"long",timeZone:id});function K(e){return ix.format(new Date(e))}function Ur(e){return sx.format(new Date(e))}var[ax,...cx]=[{min:0,name:"\u65B0\u624B"},{min:20,name:"\u5165\u95E8"},{min:100,name:"\u8FDB\u9636"},{min:300,name:"\u719F\u7EC3"},{min:800,name:"\u9AD8\u624B"},{min:2e3,name:"\u4E13\u5BB6"},{min:5e3,name:"\u5927\u5E08"}];function Hi(e){let t=1,n=ax;for(let o of cx){if(e<o.min)return{level:t,name:n.name,min:n.min,next:o.min};t+=1,n=o}return{level:t,name:n.name,min:n.min,next:null}}function qi(e){let t=Hi(e);return`Lv.${t.level} ${t.name}`}function Gi(e){let t=Hi(e);return t.next===null?"\u5DF2\u8FBE\u6700\u9AD8\u7B49\u7EA7":`\u8DDD Lv.${t.level+1} \u8FD8\u5DEE ${t.next-e} \u79EF\u5206`}var zi="\u7BA1\u7406\u5458",jr={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4FEE\u6539\u540E\u53EF\u91CD\u65B0\u63D0\u4EA4",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1\u4E14\u65E0\u6CD5\u4FEE\u6539"},Jo={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1"},Ic={pending:"\u65B0\u5934\u50CF\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u65B0\u5934\u50CF\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u53EF\u91CD\u65B0\u4E0A\u4F20",removed:"\u5934\u50CF\u5DF2\u88AB\u5C4F\u853D\uFF0C\u53EF\u91CD\u65B0\u4E0A\u4F20"};function sd(e,t){return t===null?e:`${e}\uFF0C\u539F\u56E0\uFF1A${t}`}function Nc(e,t){return t.status==="published"?null:sd(e[t.status],t.reviewReason)}function ad(e){return sd(Ic[e.status],e.reviewReason)}var Wi="\u8BE5\u5E16\u5B50\u6682\u4E0D\u53EF\u89C1",lx=4;function cd(e){let t=[],n=new Map;for(let o of e){let r=o.replyTo===null?void 0:n.get(o.replyTo.id),i={reply:o,mention:r===void 0&&o.replyTo!==null?o.replyTo.author:null,children:[]};n.set(o.id,i),r===void 0?t.push(i):r.children.push(i)}return ld(t,1)}function ld(e,t){return t<lx?e.map(n=>({...n,children:ld(n.children,t+1)})):e.flatMap(n=>[{...n,children:[]},...md(n)])}function md(e){return e.children.flatMap(t=>[{reply:t.reply,mention:e.reply.author,children:[]},...md(t)])}function Lc(e){return`${e===null?"\u4F60\u5DF2\u88AB\u6C38\u4E45\u7981\u8A00":`\u4F60\u5DF2\u88AB\u7981\u8A00\u81F3 ${K(e)}`}\uFF0C\u671F\u95F4\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D`}function Ce(e){let t=e/100;return`${t<0?"-":""}\xA5${Math.abs(t).toFixed(2)}`}function Oc(e){return Math.round(e*100)}function ud(e){return e/100}function dd(e,t,n){let o=e/t;return`${o<0?"-":""}$${Math.abs(o).toLocaleString("en-US",{minimumFractionDigits:n,maximumFractionDigits:n})}`}function Te(e,t){return dd(e,t,2)}function Xo(e,t){return dd(e,t,6)}var fd={post:"\u67E5\u770B\u5E16\u5B50",floor:"\u67E5\u770B\u8BC4\u8BBA",ticket:"\u67E5\u770B\u5DE5\u5355",invoices:"\u67E5\u770B\u53D1\u7968",recharge:"\u67E5\u770B\u5145\u503C\u8BB0\u5F55",subscription:"\u67E5\u770B\u8BA2\u9605",security:"\u67E5\u770B\u8D26\u6237"};function pd(e){return e==="subscription"?{kind:"subscription"}:{kind:"recharge"}}function Dc(e){return e.title===null?"":`\u300C${e.title}\u300D\u4E0B\u7684`}function $c(e){switch(e.kind){case"post_commented":return{title:`${e.actor.username} \u8BC4\u8BBA\u4E86\u4F60\u7684\u5E16\u5B50`,body:`\u300C${e.post.title}\u300D`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_replied":return{title:`${e.actor.username} \u56DE\u590D\u4E86\u4F60\u7684\u8BC4\u8BBA`,body:e.post.title===null?Wi:`\u300C${e.post.title}\u300D`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"post_approved":return{title:"\u5E16\u5B50\u5DF2\u901A\u8FC7\u5BA1\u6838",body:`\u300C${e.post.title}\u300D\u5DF2\u516C\u5F00\u53D1\u5E03`,target:{kind:"post",postId:e.post.id}};case"post_rejected":return{title:"\u5E16\u5B50\u672A\u901A\u8FC7\u5BA1\u6838",body:`\u300C${e.post.title}\u300D\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u4FEE\u6539\u540E\u53EF\u91CD\u65B0\u63D0\u4EA4`,target:{kind:"post",postId:e.post.id}};case"post_removed":return{title:"\u5E16\u5B50\u5DF2\u88AB\u5C4F\u853D",body:`\u300C${e.post.title}\u300D\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"post",postId:e.post.id}};case"comment_approved":return{title:"\u8BC4\u8BBA\u5DF2\u901A\u8FC7\u5BA1\u6838",body:`${Dc(e.post)}\u8BC4\u8BBA\u5DF2\u516C\u5F00\u53D1\u5E03`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_rejected":return{title:"\u8BC4\u8BBA\u672A\u901A\u8FC7\u5BA1\u6838",body:`${Dc(e.post)}\u8BC4\u8BBA\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_removed":return{title:"\u8BC4\u8BBA\u5DF2\u88AB\u5C4F\u853D",body:`${Dc(e.post)}\u8BC4\u8BBA\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"avatar_approved":return{title:"\u5934\u50CF\u5DF2\u901A\u8FC7\u5BA1\u6838",body:"\u5934\u50CF\u5DF2\u516C\u5F00\u663E\u793A",target:{kind:"security"}};case"avatar_rejected":return{title:"\u5934\u50CF\u672A\u901A\u8FC7\u5BA1\u6838",body:`\u65B0\u5934\u50CF\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u91CD\u65B0\u4E0A\u4F20`,target:{kind:"security"}};case"avatar_removed":return{title:"\u5934\u50CF\u5DF2\u88AB\u5C4F\u853D",body:`\u5934\u50CF\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u91CD\u65B0\u4E0A\u4F20`,target:{kind:"security"}};case"ticket_replied":return{title:"\u5DE5\u5355\u6709\u65B0\u56DE\u590D",body:`\u5DE5\u5355\u300C${e.ticket.title}\u300D\u6536\u5230\u7BA1\u7406\u5458\u56DE\u590D`,target:{kind:"ticket",ticketId:e.ticket.id}};case"invoice_issued":return{title:"\u53D1\u7968\u5DF2\u5F00\u5177",body:`\u62AC\u5934\u300C${e.invoice.title}\u300D\u91D1\u989D ${Ce(e.invoice.amountCny)} \u7684\u53D1\u7968\u5DF2\u5F00\u5177`,target:{kind:"invoices"}};case"invoice_rejected":return{title:"\u5F00\u7968\u7533\u8BF7\u88AB\u9A73\u56DE",body:`\u62AC\u5934\u300C${e.invoice.title}\u300D\u7684\u5F00\u7968\u7533\u8BF7\u88AB\u9A73\u56DE\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u4FEE\u6B63\u4FE1\u606F\u540E\u91CD\u65B0\u7533\u8BF7`,target:{kind:"invoices"}};case"refund_approved":return{title:"\u9000\u6B3E\u7533\u8BF7\u5DF2\u901A\u8FC7",body:`\u8BA2\u5355 ${e.refund.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\u5DF2\u901A\u8FC7\uFF0C${Ce(e.refund.amountCny)} \u5C06\u539F\u8DEF\u9000\u56DE\u652F\u4ED8\u5B9D\u8D26\u6237`,target:pd(e.refund.orderType)};case"refund_rejected":return{title:"\u9000\u6B3E\u7533\u8BF7\u88AB\u9A73\u56DE",body:`\u8BA2\u5355 ${e.refund.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\u88AB\u9A73\u56DE\uFF0C${e.refund.orderType==="subscription"?"\u8BA2\u9605\u65F6\u957F\u5DF2\u6062\u590D":"\u5230\u8D26\u989D\u5EA6\u5DF2\u6062\u590D"}\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:pd(e.refund.orderType)};case"subscription_expiring":return{title:"\u8BA2\u9605\u5373\u5C06\u5230\u671F",body:`\u5957\u9910\u300C${e.subscription.planName}\u300D\u5C06\u4E8E ${K(e.subscription.expiresAt)} \u5230\u671F\uFF0C\u5230\u671F\u540E\u5C06\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528\u5957\u9910\u5185\u989D\u5EA6`,target:{kind:"subscription"}};case"email_changed":return{title:"\u90AE\u7BB1\u5DF2\u53D8\u66F4",body:`\u8D26\u53F7\u90AE\u7BB1\u5DF2\u53D8\u66F4\u4E3A ${e.newEmail}\uFF0C\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u8054\u7CFB\u7BA1\u7406\u5458`,target:{kind:"security"}};case"new_device_login":return{title:"\u65B0\u8BBE\u5907\u767B\u5F55\u63D0\u9192",body:`\u8D26\u53F7\u5728\u65B0\u8BBE\u5907\u4E0A\u767B\u5F55\uFF1A${Go(e.device)}\uFF0CIP \u5730\u5740 ${e.ip}\uFF1B\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u4FEE\u6539\u5BC6\u7801`,target:{kind:"security"}}}}function Hr(e){if(e===void 0)return"";let t="";for(let n of e)switch(n.type){case"codespan":case"escape":case"html":case"image":t+=n.text;break;case"br":t+=" ";break;case"link":case"strong":case"em":case"del":t+=Hr(n.tokens);break;case"text":t+="tokens"in n&&n.tokens!==void 0?Hr(n.tokens):n.text;break}return t}function Bc(e){if(e===void 0)return[];let t=[];for(let n of e)switch(n.type){case"paragraph":case"heading":t.push(Hr(n.tokens));break;case"text":t.push("tokens"in n&&n.tokens!==void 0?Hr(n.tokens):n.text);break;case"code":case"html":t.push(n.text);break;case"blockquote":t.push(...Bc(n.tokens));break;case"list":n.items.forEach(o=>t.push(...Bc(o.tokens)));break;case"table":[...n.header,...n.rows.flat()].forEach(o=>t.push(Hr(o.tokens)));break}return t}function gd(e){return Bc(e).join(" ").replace(/\s+/g," ").trim()}var mx=[{name:"\u4E00\u6574\u4E2A left-pad npm \u5305",tokens:110},{name:"\u5409\u5C3C\u65AF\u7EAA\u5F55\u6700\u5065\u8C08\u9E66\u9E49\u6BD5\u751F\u5B66\u4F1A\u7684\u8BCD\u6C47",tokens:2200},{name:"\u300A\u8BBA\u8BED\u300B",tokens:25e3},{name:"\u300A\u5C0F\u738B\u5B50\u300B",tokens:3e4},{name:"\u300A\u96F7\u950B\u65E5\u8BB0\u300B",tokens:54e3},{name:"\u300A\u8BD7\u7ECF\u300B",tokens:6e4},{name:"\u5468\u6770\u4F26\u5341\u4E94\u5F20\u4E13\u8F91\u7684\u5168\u90E8\u6B4C\u8BCD",tokens:82e3},{name:"\u300A\u6D3B\u7740\u300B",tokens:11e4},{name:"\u300A\u970D\u6BD4\u7279\u4EBA\u300B",tokens:12e4},{name:"\u300A\u4E2D\u534E\u4EBA\u6C11\u5171\u548C\u56FD\u6C11\u6CD5\u5178\u300B",tokens:126e3},{name:"\u300A\u94F6\u6CB3\u7CFB\u642D\u8F66\u5BA2\u6307\u5357\u300B\u4E94\u90E8\u66F2",tokens:26e4},{name:"\u79E6\u59CB\u7687\u4E00\u5929\u6279\u9605\u7684\u7AF9\u7B80\u594F\u7AE0",tokens:34e4},{name:"\u300A\u7EB3\u5C3C\u4E9A\u4F20\u5947\u300B\u5168\u4E03\u518C",tokens:45e4},{name:"\u300A\u5802\u5409\u8BC3\u5FB7\u300B",tokens:56e4},{name:"\u300A\u9B54\u6212\u300B\u4E09\u90E8\u66F2",tokens:59e4},{name:"\u300A\u804A\u658B\u5FD7\u5F02\u300B",tokens:6e5},{name:"\u300A\u6218\u4E89\u4E0E\u548C\u5E73\u300B",tokens:76e4},{name:"\u300A\u65B0\u534E\u5B57\u5178\u300B",tokens:8e5},{name:"\u300A\u7EA2\u697C\u68A6\u300B",tokens:9e5},{name:"\u300A\u897F\u6E38\u8BB0\u300B",tokens:1e6},{name:"\u300A\u4E09\u4F53\u300B\u4E09\u90E8\u66F2",tokens:11e5},{name:"\u838E\u58EB\u6BD4\u4E9A\u5168\u96C6",tokens:115e4},{name:"\u300A\u7504\u5B1B\u4F20\u300B\u5168\u5267\u5267\u672C",tokens:12e5},{name:"\u963F\u6CE2\u7F57 11 \u53F7\u767B\u6708\u5236\u5BFC\u7A0B\u5E8F\u6E90\u7801",tokens:13e5},{name:"\u300A\u54C8\u5229\xB7\u6CE2\u7279\u300B\u5168\u4E03\u90E8",tokens:14e5},{name:"\u8FC4\u4ECA\u51FA\u571F\u7684\u5168\u90E8\u7532\u9AA8\u6587",tokens:15e5},{name:"\u5409\u5C3C\u65AF\u7EAA\u5F55\u6700\u957F\u5C0F\u8BF4\u300A\u8FFD\u5FC6\u4F3C\u6C34\u5E74\u534E\u300B",tokens:165e4},{name:"\u300A\u51B0\u4E0E\u706B\u4E4B\u6B4C\u300B\u5DF2\u51FA\u4E94\u5377",tokens:226e4},{name:"\u300A\u65F6\u5149\u4E4B\u8F6E\u300B\u5168\u5341\u56DB\u5377",tokens:57e5},{name:"\u300A\u5168\u5510\u8BD7\u300B",tokens:64e5},{name:"\u300A\u9C81\u8FC5\u5168\u96C6\u300B",tokens:85e5},{name:"\u91D1\u5EB8\u5341\u4E94\u90E8\u5C0F\u8BF4",tokens:105e5},{name:"\u300A\u8F9E\u6D77\u300B",tokens:282e5},{name:"\u300A\u5927\u82F1\u767E\u79D1\u5168\u4E66\u300B",tokens:52e6},{name:"\u4E00\u6574\u5E74\u300A\u4EBA\u6C11\u65E5\u62A5\u300B",tokens:53e6},{name:"\u300A\u4E8C\u5341\u56DB\u53F2\u300B",tokens:6e7},{name:"\u300A\u725B\u6D25\u82F1\u8BED\u8BCD\u5178\u300B\u7B2C\u4E8C\u7248",tokens:767e5},{name:"\u5355\u7530\u82B3\u6BD5\u751F\u8BC4\u4E66\u4F5C\u54C1",tokens:86e6},{name:"\u300A\u4E2D\u56FD\u5927\u767E\u79D1\u5168\u4E66\u300B\u7B2C\u4E00\u7248",tokens:1508e5},{name:"\u6574\u5957 Linux \u5185\u6838\u6E90\u7801",tokens:4e8},{name:"\u4E00\u4E2A\u666E\u901A\u4EBA\u4E00\u751F\u8BF4\u51FA\u7684\u5168\u90E8\u8BDD\u8BED",tokens:5e8},{name:"\u4E2D\u6587\u7EF4\u57FA\u767E\u79D1",tokens:1e9},{name:"\u300A\u56DB\u5E93\u5168\u4E66\u300B",tokens:12e8},{name:"\u82F1\u6587\u7EF4\u57FA\u767E\u79D1",tokens:676e7},{name:"\u8C37\u6B4C\u5168\u90E8\u4EE3\u7801\u5E93",tokens:2e10}];function ux(e){return e>=10?Math.round(e).toLocaleString("en-US"):e>=1?e.toFixed(1):e.toFixed(-Math.floor(Math.log10(e)))}function Dt(e){return e>=10?Math.round(e).toLocaleString("en-US"):e.toFixed(1)}function hd(e){return e<365?`${Dt(e)} \u5929`:`${Dt(e/365)} \u5E74`}function dx(e){let t=e/1.2/250/60;if(t<48)return`${Math.max(1,Math.round(t))} \u5C0F\u65F6`;let n=t/24;return n<730?`${Math.round(n)} \u5929`:`${Dt(n/365)} \u5E74`}function px(e){let t=e/1.2/80/60/8;return t<250?`${Dt(t)} \u4E2A\u5DE5\u4F5C\u65E5`:`${Dt(t/250)} \u4E2A\u5DE5\u4F5C\u5E74`}function fx(e){let t=e/1.2/30*4;return t<1e3?`${Math.round(t).toLocaleString("en-US")} \u514B`:t<1e6?`${Dt(t/1e3)} \u516C\u65A4`:`${Dt(t/1e6)} \u5428`}var gx=[...mx.map(e=>({min:e.tokens/10,max:e.tokens*1e4,suffix:t=>`\u7EA6\u4E3A${e.name}\u7684 ${ux(t/e.tokens)} \u500D`})),{min:3e5,max:1/0,suffix:e=>`\u6253\u5370\u6210 A4 \u7EB8\u7EA6\u6709 ${Math.round(e/1.2/1500).toLocaleString("en-US")} \u9875`},{min:3e5,max:1/0,suffix:e=>`\u6309\u6BCF\u5206\u949F 250 \u5B57\u7684\u8BED\u901F\u6717\u8BFB\u7EA6\u9700 ${dx(e)}`},{min:1680,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Math.round(e/1.2/140).toLocaleString("en-US")} \u6761\u5199\u6EE1 140 \u5B57\u7684\u5FAE\u535A`},{min:9600,max:1/0,suffix:e=>`\u7EA6\u5408 ${Math.round(e/1.2/800).toLocaleString("en-US")} \u7BC7 800 \u5B57\u7684\u9AD8\u8003\u4F5C\u6587`},{min:131400,max:1/0,suffix:e=>`\u6309\u6BCF\u5929\u4E00\u7BC7 300 \u5B57\u7684\u65E5\u8BB0\u8BA1\uFF0C\u591F\u8FDE\u7EED\u5199 ${Dt(e/1.2/300/365)} \u5E74`},{min:12e5,max:1/0,suffix:e=>`\u7EA6\u5408 ${Math.round(e/1.2/1e5).toLocaleString("en-US")} \u672C\u5341\u4E07\u5B57\u7684\u535A\u58EB\u8BBA\u6587`},{min:33e3,max:1/0,suffix:e=>`\u6309\u300A\u8D44\u6CBB\u901A\u9274\u300B\u7684\u7B14\u58A8\u5BC6\u5EA6\uFF0C\u7EA6\u591F\u53F8\u9A6C\u5149\u8BB0\u8F7D ${Math.round(e/45e5*1362).toLocaleString("en-US")} \u5E74\u5386\u53F2`},{min:49e3,max:1/0,suffix:e=>`\u7EA6\u5408\u300A\u4E00\u5343\u96F6\u4E00\u591C\u300B\u91CC\u5C71\u9C81\u4F50\u5FB7\u8BB2\u6545\u4E8B\u7684 ${Math.round(e/492e4*1001).toLocaleString("en-US")} \u4E2A\u591C\u665A`},{min:640,max:1/0,suffix:e=>`\u6309\u91D1\u9675\u523B\u7ECF\u5904\u523B\u5DE5\u534A\u6708\u523B\u6210\u4E00\u5757 800 \u5B57\u7ECF\u7248\u7684\u8FDB\u5EA6\uFF0C\u5168\u90E8\u523B\u4E0A\u96D5\u7248\u9700\u8981 ${hd(e/1.2/53)}`},{min:460800,max:1/0,suffix:e=>`\u6309\u6BCF\u5206\u949F 80 \u5B57\u3001\u6BCF\u5929 8 \u5C0F\u65F6\u8BA1\uFF0C\u591F\u4E00\u4F4D\u4E13\u804C\u6253\u5B57\u5458\u6253 ${px(e)}`},{min:4500,max:1/0,suffix:e=>`\u82E5\u523B\u6210\u6BCF\u679A 30 \u5B57\u7684\u79E6\u6C49\u7AF9\u7B80\uFF0C\u603B\u91CD\u7EA6 ${fx(e)}`},{min:18e3,max:1/0,suffix:e=>`\u6309\u300A\u6C38\u4E50\u5927\u5178\u300B\u91CD\u5F55\u4E66\u624B\u6BCF\u5929\u4E09\u53F6\u3001\u7EA6 1500 \u5B57\u7684\u5B9A\u989D\uFF0C\u591F\u4E00\u4F4D\u4E66\u624B\u6284\u5199 ${hd(e/1.2/1500)}`},{min:108e3,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Math.round(e/1.2/9e3).toLocaleString("en-US")} \u671F\u300A\u65B0\u95FB\u8054\u64AD\u300B\u7684\u64AD\u62A5\u7A3F`},{min:4e4,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Dt(e/1.2/33e3)} \u5C4A\u592E\u89C6\u6625\u665A\u7684\u5168\u90E8\u53F0\u8BCD\u548C\u6B4C\u8BCD`},{min:96e3,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u6807\u51C6 400 \u7C73\u8DD1\u9053 ${Dt(e/1.2*.005/400)} \u5708`},{min:96e5,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u5408\u5730\u9762\u5230\u56FD\u9645\u7A7A\u95F4\u7AD9\u8DDD\u79BB\u7684 ${Dt(e/1.2*.005/4e5)} \u500D`},{min:26e7,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u6708\u7403\u8D64\u9053 ${Dt(e/1.2*.005/10917e3)} \u5708`},{min:96e7,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u5730\u7403\u8D64\u9053 ${Dt(e/1.2*.005/40075e3)} \u5708`}];function yd(e){let{tokens:t,scope:n,range:o}=e;if(t<=0)return null;let r=gx.filter(c=>t>=c.min&&t<=c.max),i=r[Math.floor(Math.random()*r.length)];return i?`${n==="user"?"\u4F60":"\u5168\u7AD9"}${o==="all"?"\u7D2F\u8BA1":o==="30d"?"\u8FD1 30 \u5929":"\u8FD1 7 \u5929"}\u4F7F\u7528\u7684 Token \u91CF${i.suffix(t)}`:null}function Cn(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown status value: ${t}`);return n}}function $t(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown label value: ${t}`);return n}}var zn=Cn({pending:{label:"\u5F85\u652F\u4ED8",tone:"warning"},paid:{label:"\u5DF2\u652F\u4ED8",tone:"success"},refund_requested:{label:"\u9000\u6B3E\u5BA1\u6838\u4E2D",tone:"warning"},partially_refunded:{label:"\u90E8\u5206\u9000\u6B3E",tone:"warning"},refunded:{label:"\u5DF2\u9000\u6B3E",tone:"danger"},failed:{label:"\u5931\u8D25",tone:"danger"},expired:{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}}),EP=$t({recharge:"\u5145\u503C",subscription:"\u8BA2\u9605"}),Vi=Cn({pending:{label:"\u5F85\u5904\u7406",tone:"warning"},issued:{label:"\u5DF2\u5F00\u5177",tone:"success"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"}}),MP=Cn({active:{label:"\u6B63\u5E38",tone:"success"},disabled:{label:"\u7981\u7528",tone:"danger"}}),Fc=$t({subscription_first:"\u8BA2\u9605\u4F18\u5148",balance_first:"\u4F59\u989D\u4F18\u5148",subscription_only:"\u4EC5\u8BA2\u9605",balance_only:"\u4EC5\u4F59\u989D"}),Uc=$t({subscription_first:"\u6709\u53EF\u7528\u8BA2\u9605\u65F6\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6\uFF0C\u8BA2\u9605\u7528\u5C3D\u6216\u672A\u8986\u76D6\u5F53\u524D\u5206\u7EC4\u65F6\u6539\u6263\u4F59\u989D",balance_first:"\u4F59\u989D\u5145\u8DB3\u65F6\u6263\u4F59\u989D\uFF0C\u4F59\u989D\u4E0D\u8DB3\u65F6\u6539\u7528\u8BA2\u9605\u989D\u5EA6",subscription_only:"\u53EA\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6\uFF0C\u8BA2\u9605\u7528\u5C3D\u6216\u672A\u8986\u76D6\u5F53\u524D\u5206\u7EC4\u65F6\u62D2\u7EDD\u8BF7\u6C42",balance_only:"\u53EA\u6263\u8D26\u6237\u4F59\u989D\uFF0C\u4E0D\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6"}),bd=Wa.map(e=>({value:e,label:Fc(e)})),jc=$t({recharge:"\u5145\u503C",reserve:"\u9884\u6263",consume:"\u6D88\u8D39",reserve_refund:"\u9884\u6263\u9000\u56DE",refund:"\u9000\u6B3E",refund_release:"\u9000\u6B3E\u8FD4\u8FD8",reward:"\u5956\u52B1",admin_adjust:"\u7BA1\u7406\u5458\u8C03\u6574"}),Sd=$t({usage_log:"\u7528\u91CF",order:"\u8BA2\u5355",invitation:"\u9080\u8BF7",admin:"\u7BA1\u7406\u5458"}),xd=Cn({requested:{label:"\u5F85\u5BA1\u6838",tone:"warning"},pending:{label:"\u5F85\u786E\u8BA4",tone:"warning"},succeeded:{label:"\u5DF2\u9000\u6B3E",tone:"success"},failed:{label:"\u5931\u8D25",tone:"danger"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"},canceled:{label:"\u5DF2\u64A4\u9500",tone:"neutral"}}),Ki=Cn({success:{label:"\u6210\u529F",tone:"success"},error:{label:"\u5931\u8D25",tone:"danger"},canceled:{label:"\u53D6\u6D88",tone:"neutral"},anomaly:{label:"\u5F02\u5E38",tone:"warning"}}),Td=$t({"openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"}),qr=$t({special:"\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968",general:"\u589E\u503C\u7A0E\u666E\u901A\u53D1\u7968"}),uo=$t({special:"\u4E13\u7968",general:"\u666E\u7968"}),Yi=$t({first_inviter:"\u9996\u5145\u8FD4\u5229\uFF08\u9080\u8BF7\u4EBA\uFF09",first_invitee:"\u9996\u5145\u8FD4\u5229\uFF08\u88AB\u9080\u8BF7\u4EBA\uFF09",subsequent_inviter:"\u7EED\u5145\u8FD4\u5229\uFF08\u9080\u8BF7\u4EBA\uFF09"}),Gr=Cn({info:{label:"\u4FE1\u606F",tone:"neutral"},success:{label:"\u6210\u529F",tone:"success"},warning:{label:"\u8B66\u544A",tone:"warning"},error:{label:"\u91CD\u8981",tone:"danger"}}),Hc=Cn({open:{label:"\u5F85\u5904\u7406",tone:"warning"},replied:{label:"\u5DF2\u56DE\u590D",tone:"success"},closed:{label:"\u5DF2\u5173\u95ED",tone:"neutral"}}),Ji=$t({billing:"\u8BA1\u8D39",technical:"\u6280\u672F",account:"\u8D26\u53F7",other:"\u5176\u4ED6"}),qc=Cn({low:{label:"\u8F83\u4F4E",tone:"neutral"},normal:{label:"\u666E\u901A",tone:"neutral"},high:{label:"\u7D27\u6025",tone:"danger"}}),wd=$t({openai:"OpenAI",anthropic:"Anthropic"}),po=Cn({pending:{label:"\u5BA1\u6838\u4E2D",tone:"warning"},published:{label:"\u5DF2\u53D1\u5E03",tone:"success"},rejected:{label:"\u672A\u901A\u8FC7",tone:"danger"},removed:{label:"\u5DF2\u5C4F\u853D",tone:"danger"}}),kd=$t({spam:"\u5783\u573E\u5E7F\u544A",abuse:"\u4EBA\u8EAB\u653B\u51FB",explicit:"\u8272\u60C5\u4F4E\u4FD7",illegal:"\u8FDD\u6CD5\u8FDD\u89C4",privacy:"\u6CC4\u9732\u9690\u79C1",other:"\u5176\u4ED6"}),vd=$t({activity:"\u6700\u65B0\u56DE\u590D",published:"\u6700\u65B0\u53D1\u5E03"});function _t(e,t,n){let o=r=>{let i=t(r);return typeof i=="string"?i:i.label};return[{value:"",label:n},...e.map(r=>({value:r,label:o(r)}))]}function Zi(e){return`${e.name} \xD7${e.multiplier}`}var Xi=10080,Qi=1440;function Cd(e){if(e%Xi===0){let t=e/Xi;return t===1?"\u6BCF\u5468\u9650\u989D":`${t} \u5468\u9650\u989D`}if(e%Qi===0){let t=e/Qi;return t===1?"\u6BCF\u65E5\u9650\u989D":`${t} \u5929\u9650\u989D`}return e%60===0?`${e/60} \u5C0F\u65F6\u9650\u989D`:`${e} \u5206\u949F\u9650\u989D`}function hx(e){if(e%Xi===0){let t=e/Xi;return t===1?"\u6BCF\u5468":`\u6BCF ${t} \u5468`}if(e%Qi===0){let t=e/Qi;return t===1?"\u6BCF\u5929":`\u6BCF ${t} \u5929`}return e%60===0?`\u6BCF ${e/60} \u5C0F\u65F6`:`\u6BCF ${e} \u5206\u949F`}function Rd(e,t){return e.windows.map(n=>`${hx(n.durationMinutes)} ${Te(n.quota,t)}`)}function Gc(e){return Math.min(100,Math.floor(e.used/e.quota*100))}function zc(e){return e.revokedAt!==null?{label:"\u5DF2\u4F5C\u5E9F",tone:"danger"}:new Date(e.expiresAt).getTime()<=Date.now()?{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}:{label:"\u751F\u6548\u4E2D",tone:"success"}}var Wc={recharge:["\u5145\u9519\u91D1\u989D\u6216\u91CD\u590D\u5145\u503C","\u9700\u8981\u7684\u6A21\u578B\u4E0D\u53EF\u7528","\u8C03\u7528\u7ECF\u5E38\u62A5\u9519\u6216\u8D85\u65F6","\u5B9E\u9645\u8BA1\u8D39\u9AD8\u4E8E\u9884\u671F","\u4F59\u989D\u7528\u4E0D\u5B8C\uFF0C\u4E0D\u518D\u9700\u8981"],subscription:["\u8BEF\u8D2D\u6216\u9009\u9519\u5957\u9910","\u5957\u9910\u4E0D\u542B\u9700\u8981\u7684\u6A21\u578B","\u9650\u989D\u592A\u4F4E\uFF0C\u4E0D\u591F\u7528","\u8C03\u7528\u7ECF\u5E38\u62A5\u9519\u6216\u8D85\u65F6","\u4F7F\u7528\u9891\u7387\u4F4E\uFF0C\u4E0D\u5212\u7B97"]},_d={recharge:"\u63D0\u4EA4\u540E\u672C\u5355\u5269\u4F59\u989D\u5EA6\u4E0E\u5173\u8054\u7684\u9080\u8BF7\u5956\u52B1\u5C06\u7ACB\u5373\u4ECE\u4F59\u989D\u6536\u56DE\uFF1B\u5BA1\u6838\u901A\u8FC7\u540E\u539F\u8DEF\u9000\u56DE\u652F\u4ED8\u5B9D\uFF0C\u9A73\u56DE\u6216\u64A4\u9500\u540E\u81EA\u52A8\u6062\u590D",subscription:"\u63D0\u4EA4\u540E\u672C\u5355\u672A\u5F00\u59CB\u7684\u65F6\u957F\u7ACB\u5373\u5931\u6548\uFF0C\u6B63\u5728\u670D\u52A1\u4E2D\u7684\u65F6\u6BB5\u4FDD\u7559\u81F3\u5F53\u524D\u9650\u989D\u5468\u671F\u7ED3\u675F\uFF1B\u5BA1\u6838\u901A\u8FC7\u540E\u6309\u672A\u5F00\u59CB\u7684\u9650\u989D\u5468\u671F\u6298\u7B97\u539F\u8DEF\u9000\u6B3E\uFF0C\u9A73\u56DE\u6216\u64A4\u9500\u540E\u81EA\u52A8\u6062\u590D"};import{release as yx}from"os";var bx=3e4,Sx=nu({cliVersion:Vt,platform:process.platform,release:yx(),arch:process.arch,nodeVersion:process.versions.node});async function Pd(e,t){if(t.json!==void 0&&t.body!==void 0)throw new Error("httpRequest cannot accept both json and body");let n=new Headers(t.headers);n.set("user-agent",Sx);let o=t.body;t.json!==void 0&&(n.set("content-type","application/json"),o=JSON.stringify(t.json));try{return await fetch(e,{method:t.method??(o===void 0?"GET":"POST"),headers:n,body:o,signal:AbortSignal.timeout(t.timeoutMs??bx),redirect:"follow"})}catch(r){let i=URL.canParse(e)?new URL(e).origin:e;throw new U(`\u65E0\u6CD5\u8FDE\u63A5 ${i}\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u7AD9\u70B9\u5730\u5740`,{exitCode:Cm,cause:r})}}async function Ad(e){let t=await e.text();if(t==="")return null;try{return JSON.parse(t)}catch{return null}}async function Jt(e,t={}){let n=await Pd(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Ad(n)};let o=await n.text(),r=null;if(o!=="")try{r=JSON.parse(o)}catch(i){throw new U(`${e} \u8FD4\u56DE\u4E86\u975E JSON \u5185\u5BB9\uFF0C\u53EF\u80FD\u88AB\u7F51\u5173\u6216\u4E2D\u95F4\u8BBE\u5907\u62E6\u622A`,{cause:i})}return{status:n.status,ok:!0,headers:n.headers,data:r}}async function Ed(e,t={}){let n=await Pd(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Ad(n),bytes:null};let o=new Uint8Array(await n.arrayBuffer());return{status:n.status,ok:!0,headers:n.headers,data:null,bytes:o}}function xx(e,t){let n=eu.safeParse(t);if(!n.success)return new U(`\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${e}\uFF09`);let{code:o,message:r}=n.data.error,i=o==="unauthorized"||o==="token_expired"?ro:void 0;return new U(tu[o]??r,i?{exitCode:i}:{})}function sn(e){if(!e.ok)throw xx(e.status,e.data)}var Nd="cf_refresh",Ld="cf_device",Md=6e4;function Id(e,t){for(let n of e.getSetCookie()){let o=n.split(";",1)[0];if(o===void 0)continue;let r=o.indexOf("=");if(!(r<0)&&o.slice(0,r).trim()===t)return o.slice(r+1).trim()}return null}function zr(e,t){return{refresh:Id(t,Nd)??e.refresh,device:Id(t,Ld)??e.device}}function es(e){let t=[];return e.refresh&&t.push(`${Nd}=${e.refresh}`),e.device&&t.push(`${Ld}=${e.device}`),t.length>0?{cookie:t.join("; ")}:{}}function Tx(e){let t=e.split(".")[1];if(t===void 0)throw new U("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u683C\u5F0F\u4E0D\u6B63\u786E");let n;try{n=JSON.parse(Buffer.from(t,"base64url").toString("utf8"))}catch(r){throw new U("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u65E0\u6CD5\u89E3\u6790",{cause:r})}let o=n.exp;if(typeof o!="number")throw new U("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u7F3A\u5C11\u6709\u6548\u671F");return o*1e3}function Wr(e,t,n){if(!t.refresh)throw new U("\u670D\u52A1\u7AEF\u672A\u4E0B\u53D1\u5237\u65B0\u51ED\u636E\uFF0C\u65E0\u6CD5\u4FDD\u6301\u767B\u5F55\u72B6\u6001");let o={refreshCookie:t.refresh,accessToken:n.accessToken,accessExpiresAt:Tx(n.accessToken),username:n.user.username,email:n.user.email,site:e};return za(r=>{r.session=o,t.device&&(r.device={site:e,cookie:t.device})}),o}function Vc(e){let{device:t}=Lt();return t!==null&&t.site===e?t.cookie:null}async function Od(e,t,n){let o={refresh:null,device:Vc(e)},r=await Jt(`${e}/api/auth/login`,{json:{account:t,password:n},headers:es(o)});sn(r);let i=au.parse(r.data),s=zr(o,r.headers);return i.status==="totp_required"?{status:"totp_required",ticket:i.ticket,jar:s}:{status:"ok",session:Wr(e,s,i)}}async function Dd(e,t,n,o,r){let s=await Jt(`${e}/api/auth/${r==="totp"?"login/totp":"login/recovery-code"}`,{json:{ticket:n,code:o},headers:es(t)});sn(s);let a=zo.parse(s.data);return Wr(e,zr(t,s.headers),a)}function ts(){za(e=>{e.session=null})}async function wx(e){let t={refresh:e.refreshCookie,device:Vc(e.site)},n=await Jt(`${e.site}/api/auth/refresh`,{method:"POST",headers:es(t)});if(n.status===401||n.status===403)throw ts(),new U("\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",{exitCode:ro});sn(n);let o=zo.parse(n.data);return Wr(e.site,zr(t,n.headers),o)}async function Vr(e=!1){let t=Lm();return!e&&Date.now()<t.accessExpiresAt-Md?t:Om(async()=>{let n=Nm().session;if(!n)throw new U("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return(n.refreshCookie!==t.refreshCookie||n.accessToken!==t.accessToken)&&Date.now()<n.accessExpiresAt-Md?n:wx(n)})}async function ns(){let e=Lt().session;if(!e)return;let t=await Jt(`${e.site}/api/auth/logout`,{method:"POST",headers:es({refresh:e.refreshCookie,device:Vc(e.site)})});ts(),sn(t)}import{spawn as kx}from"child_process";function Kr(e,t={}){return new Promise((n,o)=>{let r=kx("npm",e,{stdio:["ignore","pipe","pipe"],shell:process.platform==="win32"}),i=[],s=[],a=c=>{for(let l of c.toString("utf8").split(`
4
+ `)){let u=l.trimEnd();u!==""&&(s.push(u),s.length>20&&s.shift())}};r.stdout.on("data",c=>{i.push(c.toString("utf8")),a(c)}),r.stderr.on("data",a),r.on("error",c=>o(new U(`\u6267\u884C npm \u5931\u8D25\uFF1A${c.message}`,{cause:c}))),r.on("close",c=>{if(c===0){n(i.join(""));return}let l=s.slice(-2).join(" / ");o(new U(`npm ${e.join(" ")} \u9000\u51FA\u7801 ${c??"null"}`,{...l===""?{}:{hint:l}}))}),t.background===!0&&(r.stdout.unref(),r.stderr.unref(),r.unref())})}async function $d(e){let t=[],n=async(o,r)=>{try{await r(),e.done(o)}catch(i){t.push(`${o}\uFF1A${xe(i)}`),e.failed(o)}};return await n("\u9000\u51FA\u767B\u5F55",()=>ns()),await n("\u5220\u9664\u672C\u5730\u6587\u4EF6",()=>{let o=vn();vx(o)&&Cx(o,{recursive:!0,force:!0})}),await n("\u5378\u8F7D\u672C\u7A0B\u5E8F",async()=>{await Kr(["uninstall","-g",Fo])}),t}import{z as Yr}from"zod";var Rx=Yr.object({line:Yr.object({name:Yr.string(),url:Yr.string()}).nullable(),lastUpdateCheckAt:Yr.number().nullable()}),Bd=_i(Rx,{line:null,lastUpdateCheckAt:null},_m,"\u672C\u5730\u914D\u7F6E","\u91CD\u65B0\u8FD0\u884C"),fo=Bd.load,os=Bd.update;var _x=1440*60*1e3;async function Fd(){let e=(await Kr(["view",Fo,"version"])).trim();if(e==="")throw new U(`npm \u6CA1\u6709\u62A5\u51FA ${Fo} \u7684\u7248\u672C`);return e}async function Ud(e,t){return await Kr(["install","-g",`${Fo}@${e}`],{background:t}),e}async function jd(){let e=await Fd();return e===Vt?null:await Ud(e,!1)}function Px(){let e=Date.now(),t=fo().lastUpdateCheckAt;return t!==null&&e-t<_x?!1:(os(n=>{n.lastUpdateCheckAt=e}),!0)}async function Hd(){if(!Px())return null;let e;try{e=await Fd()}catch{return null}return e===Vt?null:await Ud(e,!0)}import{Box as NR,render as LR,useInput as OR}from"ink";import{useEffect as wm,useRef as DR}from"react";async function fn(e,t,n={}){let o=await Jt(t,n);return sn(o),e.parse(o.data)}async function A(e,t,n={}){let o=await Vr(),r=s=>Jt(`${o.site}/api${t}`,{...n,headers:{...n.headers,authorization:`Bearer ${s}`}}),i=await r(o.accessToken);if(i.status===401){let s=await Vr(!0);i=await r(s.accessToken)}return sn(i),e.parse(i.data)}async function Kc(e,t={}){let n=await Vr(),o=i=>Ed(`${n.site}/api${e}`,{...t,headers:{...t.headers,authorization:`Bearer ${i}`}}),r=await o(n.accessToken);if(r.status===401){let i=await Vr(!0);r=await o(i.accessToken)}return sn(r),{bytes:r.bytes,headers:r.headers}}async function rs(e,t={}){return(await Kc(e,t)).bytes}function Fe(e,t){let n=new URLSearchParams;for(let[r,i]of Object.entries(t))i!==void 0&&n.set(r,String(i));let o=n.toString();return o===""?e:`${e}?${o}`}var qd=e=>A(mt(pc),Fe("/announcements",{...e})),Gd=()=>A(pc.nullable(),"/announcements/unread"),is=e=>A(se,`/announcements/${e}/read`,{method:"POST"});import{Box as zd,useWindowSize as Ax}from"ink";import{Children as Ex}from"react";import{jsx as Wd}from"react/jsx-runtime";var Mx=1,Yc=1,X=1;function j(){let{columns:e,rows:t}=Ax();return{width:Math.max(1,e-Mx*2),columns:e,rows:t}}function Vd({height:e,children:t}){return Wd(zd,{flexDirection:"column",height:e,justifyContent:"space-between",children:Ex.toArray(t).map((n,o)=>Wd(zd,{flexDirection:"column",flexShrink:0,children:n},o))})}import{useInput as Kd}from"ink";import{createContext as cs,useCallback as Xc,useContext as Ix,useEffect as Yd,useMemo as Jd,useRef as as,useState as Nx}from"react";import{jsx as ss}from"react/jsx-runtime";var ls=cs(null),Qc=cs(null),Zc=cs(null);function Jc(){let[e,t]=Nx(!1),n=as(0),o=Xc(()=>(n.current+=1,t(!0),()=>{n.current-=1,n.current===0&&t(!1)}),[]);return Jd(()=>({held:e,acquire:o}),[e,o])}var Wn={screen:0,panel:10,input:20},el=cs(null);function Xd({children:e}){let t=Jc(),n=Jc(),o=Jc(),r=as([]),i=as(0),s=Xc(l=>{let u={...l,seq:i.current+=1};return r.current.push(u),()=>{r.current=r.current.filter(m=>m!==u)}},[]),a=Xc(()=>{r.current.reduce((u,m)=>u===null||m.layer>u.layer||m.layer===u.layer&&m.seq>u.seq?m:u,null)?.handler()},[]);Kd((l,u)=>{u.escape&&a()});let c=Jd(()=>({push:s,fire:a}),[s,a]);return ss(ls.Provider,{value:t,children:ss(Qc.Provider,{value:n,children:ss(Zc.Provider,{value:o,children:ss(el.Provider,{value:c,children:e})})})})}function go(e){let t=Ix(e);if(!t)throw new Error("\u952E\u76D8\u94A9\u5B50\u5FC5\u987B\u5728 KeyboardProvider \u5185\u4F7F\u7528");return t}function tl(e,t){let{acquire:n}=go(e);Yd(()=>{if(t)return n()},[t,n])}function ms(e){tl(ls,e)}function Re(e){tl(Qc,e)}function Qd(e){tl(Zc,e)}function us(){return go(Qc).held}function ds(){return go(ls).held}function Zd(){return go(Zc).held}function G(e,t=!0){let n=go(ls).held;Kd(e,{isActive:t&&!n})}function ep(){return go(el).fire}function gn(e,{isActive:t=!0,layer:n=Wn.screen}={}){let{push:o}=go(el),r=as(e);r.current=e,Yd(()=>{if(t)return o({handler:()=>r.current(),layer:n})},[t,n,o])}import{measureElement as Lx}from"ink";import{PassThrough as Ox}from"stream";import{createContext as Dx,useCallback as $x,useContext as Bx,useEffect as rp,useRef as ps}from"react";import{jsx as Kx}from"react/jsx-runtime";var Fx="\x1B[?1000h\x1B[?1003h\x1B[?1006h",Ux="\x1B[?1006l\x1B[?1003l\x1B[?1000l",jx=27,Hx=91,qx=60,tp=77,np=109,op=20,Gx=64,zx=32,Wx=20;function Vx(e){let t=[],n=[],o=0;for(;o<e.length;){let r=e[o];if(r===void 0)break;if(r!==jx){n.push(r),o+=1;continue}let i=e[o+1],s=e[o+2];if(i===void 0||s===void 0)break;if(i!==Hx){n.push(r),o+=1;continue}if(s===tp){if(o+6>e.length)break;o+=6;continue}if(s!==qx){n.push(r),o+=1;continue}let a=o+3,c;for(;a<e.length&&a-o<op;){let d=e[a];if(d===tp||d===np){c=d;break}a+=1}if(c===void 0){if(a-o<op)break;n.push(r),o+=1;continue}let l=e.subarray(o+3,a).toString("latin1").split(";");if(o=a+1,c===np||l.length!==3)continue;let u=Number(l[0]),m=Number(l[1]),p=Number(l[2]);!Number.isFinite(u)||!Number.isFinite(m)||!Number.isFinite(p)||t.push((u&Gx)!==0?{row:p,column:m,kind:"wheel",delta:(u&1)===0?-1:1}:{row:p,column:m,kind:(u&zx)!==0?"move":"press"})}return{events:t,clean:Buffer.from(n),pending:e.subarray(o)}}function ip(e,t){let n=new Set,o=new Ox,r=Buffer.alloc(0),i=null,s=()=>{i=null,r.length!==0&&(o.write(r),r=Buffer.alloc(0))},a=p=>{i!==null&&clearTimeout(i),i=null;let d=Vx(Buffer.concat([r,p]));r=d.pending,d.clean.length>0&&o.write(d.clean);for(let b of d.events)for(let h of n)h(b);r.length>0&&(i=setTimeout(s,Wx))},c=()=>{t.write(Ux)},l={SIGHUP:1,SIGINT:2,SIGTERM:15},u=p=>{process.exit(128+(l[p]??0))};e.on("data",a),process.once("exit",c);for(let p of Object.keys(l))process.on(p,u);t.write(Fx);let m=o;return Object.assign(m,{isTTY:!0,setRawMode(p){return e.setRawMode(p),m},ref(){return e.ref(),m},unref(){return e.unref(),m}}),{stdin:m,subscribe(p){return n.add(p),()=>{n.delete(p)}},dispose(){c(),i!==null&&clearTimeout(i),process.off("exit",c);for(let p of Object.keys(l))process.off(p,u);e.off("data",a),n.clear()}}}var sp=Dx(null);function ap({subscribe:e,children:t}){let n=ps(new Set).current,o=ps(null),r=$x(i=>(n.add(i),()=>{n.delete(i)}),[n]);return rp(()=>e(i=>{let s=i.row-1,a=i.column-1,c=null;for(let u of n){let m=u.node.current;if(m===null||u.handlers.current.isActive===!1)continue;let p=Lx(m);if(s<p.y||s>=p.y+p.height||a<p.x||a>=p.x+p.width)continue;let d=p.width*p.height;(c===null||d<c.area)&&(c={region:u,top:p.y,left:p.x,area:d})}if(i.kind==="move"){let u=c===null?null:c.region;if(o.current!==u){let m=o.current;m!==null&&n.has(m)&&m.handlers.current.onHoverLeave?.(),o.current=u}c!==null&&c.region.handlers.current.onHover?.({row:s-c.top,column:a-c.left});return}if(c===null)return;let l=c.region.handlers.current;i.kind==="wheel"?l.onWheel?.(i.delta):l.onClick?.({row:s-c.top,column:a-c.left})}),[e,n]),Kx(sp.Provider,{value:r,children:t})}function rt(e){let t=Bx(sp);if(t===null)throw new Error("useMouseRegion \u5FC5\u987B\u5728 MouseProvider \u5185\u4F7F\u7528");let n=ps(null),o=ps(e);return o.current=e,rp(()=>t({node:n,handlers:o}),[t]),n}import{useApp as Yx}from"ink";import{createContext as Jx,useCallback as ho,useContext as Xx,useEffect as nl,useRef as gs,useState as Xr}from"react";var Tt=[{id:"usage",label:"\u6570\u636E\u770B\u677F"},{id:"tokens",label:"\u4EE4\u724C\u7BA1\u7406"},{id:"logs",label:"\u4F7F\u7528\u65E5\u5FD7"},{id:"models",label:"\u6A21\u578B\u5E7F\u573A"},{id:"docs",label:"\u4F7F\u7528\u6587\u6863"},{id:"recharge",label:"\u8D26\u6237\u5145\u503C"},{id:"subscription",label:"\u8BA2\u9605\u5957\u9910"},{id:"ledger",label:"\u989D\u5EA6\u6D41\u6C34"},{id:"invoices",label:"\u53D1\u7968\u7BA1\u7406"},{id:"invite",label:"\u9080\u8BF7\u597D\u53CB"},{id:"tickets",label:"\u5DE5\u5355\u652F\u6301"},{id:"community",label:"\u793E\u533A\u8BBA\u575B"},{id:"inbox",label:"\u7AD9\u5185\u6D88\u606F"},{id:"announcements",label:"\u7CFB\u7EDF\u516C\u544A"},{id:"profile",label:"\u4E2A\u4EBA\u4E3B\u9875"}],cp="usage",Jr=e=>Tt.findIndex(t=>t.id===e),fs=e=>Jr(e)>=0;import{jsx as Zx}from"react/jsx-runtime";var Qx=5e3,mp=Jx(null),up=e=>({id:e,params:void 0}),lp=()=>Lt().session===null?[{id:"home",params:void 0}]:[up(cp)];function O(){let e=Xx(mp);if(!e)throw new Error("useNav \u5FC5\u987B\u5728 NavProvider \u5185\u4F7F\u7528");return e}function dp({ctx:e,children:t}){let n=Yx(),[o,r]=Xr(lp),[i,s]=Xr(0),[a,c]=Xr([]),l=gs({announcementsChecked:!1,announcementsShown:!1}).current,u=gs(new WeakMap).current,m=ho((R,...N)=>{r(E=>[...E,{id:R,params:N[0]}])},[]),p=ho(()=>{r(R=>R.length>1?R.slice(0,-1):R),s(R=>R+1)},[]),d=ho(R=>{r([up(R)]),s(N=>N+1)},[]),b=ho(()=>{r(lp()),s(R=>R+1)},[]),h=ho(()=>s(R=>R+1),[]),g=ho((R,N)=>{c(E=>[...E,{tone:R,message:N}])},[]),x=ho(()=>c(R=>R.slice(1)),[]),T=a[0]??null;nl(()=>{if(T===null)return;let R=setTimeout(x,Qx);return()=>clearTimeout(R)},[T,x]);let k=o[o.length-1];if(k===void 0)throw new Error("\u5BFC\u822A\u6808\u4E3A\u7A7A");let S=u.get(k);S===void 0&&(S=new Map,u.set(k,S));let y={ctx:e,current:k,depth:o.length,push:m,pop:p,select:d,home:b,reload:h,toast:g,message:T,dismissToast:x,exit:n.exit,revision:i,gate:l,retained:S};return Zx(mp.Provider,{value:y,children:t})}function Me(e,t){let{retained:n}=O(),[o,r]=Xr(()=>e!==void 0&&n.has(e)?n.get(e):t());return nl(()=>{e!==void 0&&n.set(e,o)},[n,e,o]),[o,r]}function Q(e,t){let[n,o]=Xr({phase:"loading"}),r=gs(t);r.current=t;let i=gs(0);return nl(()=>{let s=i.current+=1;o({phase:"loading"}),r.current().then(a=>{i.current===s&&o({phase:"ready",data:a})}).catch(a=>{i.current===s&&o({phase:"error",message:xe(a),hint:a instanceof U?a.hint:void 0})})},e),n}import{Box as Is,Text as xo,useInput as GT}from"ink";import{Box as ti,Text as nr}from"ink";import{Lexer as rT}from"marked";import Zo from"string-width";import Qr from"string-width";var f={background:"#0d0d0d",foreground:"#f3f3f3",mutedForeground:"#949494",faintForeground:"#696969",cursorBackground:"#c8c8c8",border:"#393939",accent:"#37be95",success:"#34d399",warning:"#fbbf24",danger:"#f87171"},hs=["#242424","#5a4233","#746533","#70924f","#37be95"],ys=["#37be95","#2d9273","#246e58","#1e5443","#193f33"],et={accent:f.accent,success:f.success,warning:f.warning,danger:f.danger},Qo=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],bs=80,ae={cursor:"\u276F",bullet:"\xB7",dot:"\u2219",crumb:"\u203A",ok:"\u2714",warn:"!",fail:"\u2718",ellipsis:"\u2026",barFilled:"\u2588",barEmpty:"\u2591",section:"\u258D",prev:"\u2039",next:"\u203A"};var eT=Qr(ae.ellipsis),tT=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ol=e=>Array.from(tT.segment(e),t=>t.segment),nT=(e,t)=>e+" ".repeat(Math.max(0,t-Qr(e))),oT=(e,t)=>" ".repeat(Math.max(0,t-Qr(e)))+e;function He(e,t){if(t<=0)return"";if(Qr(e)<=t)return e;let n=t-eT,o="";for(let r of ol(e)){if(Qr(o+r)>n)break;o+=r}return o+ae.ellipsis}var Vn=e=>e.replaceAll(" "," "),Je=(e,t)=>nT(He(e,t),t),Kn=(e,t)=>oT(He(e,t),t),_e=e=>e.filter(t=>typeof t=="string"&&t!=="").join(` ${ae.bullet} `);var iT=e=>e.startsWith("#")||Ni(e)!==null,sT={spans:[]},Ss=e=>e===void 0||e.spans.every(t=>t.text.trim()==="");function pp(e){let t=[];for(let n of e){let o=t[t.length-1];o!==void 0&&o.color===n.color&&o.bold===n.bold?o.text+=n.ch:t.push({text:n.ch,color:n.color,bold:n.bold})}return{spans:t}}var aT=new Set([..."\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300D\u300F\u3011\u300B\u2026\u201D\u2019,.;:!?)]}"]),cT=new Set([..."\uFF08\u300C\u300E\u3010\u300A\u201C\u2018([{"]),lT=(e,t)=>(Zo(e)>1||Zo(t)>1)&&!cT.has(e)&&!aT.has(t);function mT(e,t,n){for(let o=e.length;o>n;o-=1){if(e[o]?.ch===" ")return{end:o,carry:o+1};let r=e[o-1]?.ch,i=o===e.length?t:e[o]?.ch;if(r!==void 0&&i!==void 0&&r!==" "&&lT(r,i))return{end:o,carry:o}}return null}function uT(e){let t=[],n=0,o=0,r=0;for(let i of ol(e.map(s=>s.text).join(""))){let s=e[n];for(;s!==void 0&&r>=o+s.text.length;)o+=s.text.length,n+=1,s=e[n];if(s===void 0)break;t.push({ch:i,color:s.color,bold:s.bold}),r+=i.length}return t}function Pt(e,t,n=0){let o=()=>Array.from({length:n},()=>({ch:" "})),r=[],i=[],s=0,a=()=>{r.push(pp(i)),i=o(),s=n};for(let c of uT(e)){let{ch:l}=c;if(l===`
5
5
  `||l===`\r
6
- `){a();continue}let u=Qo(l);if(s+u>t&&i.length>n){if(l===" "){a();continue}let m=sT(i,l,n),f=m===null?[]:i.slice(m.carry),d=f.reduce((h,y)=>h+Qo(y.ch),0);m===null||n+d+u>t?a():(i=i.slice(0,m.end),a(),i=[...i,...f],s=n+d)}i.push(c),s+=u}return(i.length>0||r.length===0)&&r.push(mp(i)),r}var pp=(e,t)=>t==="docs"?e.replaceAll(`
7
- `," "):e;function an(e,t,n){if(e===void 0)return[];let o=[];for(let r of e)switch(r.type){case"text":o.push(..."tokens"in r&&r.tokens!==void 0?an(r.tokens,t,n):[{text:pp(r.text,n),...t}]);break;case"strong":o.push(...an(r.tokens,{...t,bold:!0},n));break;case"em":o.push(...an(r.tokens,t,n));break;case"del":o.push(...an(r.tokens,{...t,color:p.faintForeground},n));break;case"codespan":o.push({text:r.text,color:p.accent,bold:t.bold});break;case"link":{let i=an(r.tokens,{...t,color:p.accent},n);o.push(...i);let s=i.map(a=>a.text).join("");r.href!==s&&!(n==="docs"&&tT(r.href))&&o.push({text:`\uFF08${r.href}\uFF09`,color:p.faintForeground});break}case"image":if(n==="docs"){o.push({text:r.text===""?"[\u56FE\u7247]":`[\u56FE\u7247] ${r.text}`,color:p.mutedForeground});break}o.push({text:r.text===""?"\u56FE\u7247":r.text,...t}),o.push({text:`\uFF08${r.href}\uFF09`,color:p.faintForeground});break;case"br":o.push({text:`
8
- `});break;case"escape":o.push({text:r.text,...t});break;default:o.push({text:r.raw,...t})}return o}var up=2,dp=e=>e.reduce((t,n)=>t+Qo(n.text),0);function cT(e,t,n,o,r){let i=e.map(d=>({spans:an(d.tokens,{bold:!0,color:p.foreground},r),align:d.align})),s=t.map(d=>d.map(h=>({spans:an(h.tokens,{color:p.foreground},r),align:h.align}))),a=o-(e.length+1)-e.length*2;if(a<e.length*up)return Pt([{text:n,color:p.foreground}],o);let c=e.map(()=>up);for(let d of[i,...s])d.forEach((h,y)=>{for(let g of Pt(h.spans,Number.MAX_SAFE_INTEGER)){let x=c[y],T=dp(g.spans);x!==void 0&&T>x&&(c[y]=T)}});let l=c.reduce((d,h)=>d+h,0);for(;l>a;){let d=0,h=0;c.forEach((y,g)=>{y>h&&(d=g,h=y)}),c[d]=h-1,l-=1}let u=d=>({text:d,color:p.faintForeground}),m=(d,h,y)=>({spans:[u(`${d}${c.map(g=>"\u2500".repeat(g+2)).join(h)}${y}`)]}),f=d=>{let h=c.map((x,T)=>{let R=d[T];return{width:x,align:R?.align??null,lines:Pt(R?.spans??[],x)}}),y=h.reduce((x,T)=>Math.max(x,T.lines.length),1),g=[];for(let x=0;x<y;x+=1){let T=[];for(let R of h){let b=R.lines[x]?.spans??[],S=R.width-dp(b),v=R.align==="right"?S:R.align==="center"?Math.floor(S/2):0;T.push(u("\u2502"),{text:` ${" ".repeat(v)}`}),T.push(...b),T.push({text:`${" ".repeat(S-v)} `})}T.push(u("\u2502")),g.push({spans:T})}return g};return[m("\u250C","\u252C","\u2510"),...f(i),m("\u251C","\u253C","\u2524"),...s.flatMap(f),m("\u2514","\u2534","\u2518")]}function rl(e,t,n){let o=[],r=()=>{o.length>0&&!xs(o[o.length-1])&&o.push(nT)};for(let i of e)switch(i.type){case"space":r();break;case"heading":{let s=an(i.tokens,{bold:!0,color:p.foreground},n),a=i.depth<=2?[{text:`${ie.section} `,color:p.accent},...s]:s,c=n==="docs"?Cu(i.text):void 0;Pt(a,t,i.depth<=2?2:0).forEach((l,u)=>o.push(u===0?{...l,anchor:c}:l)),r();break}case"paragraph":o.push(...Pt(an(i.tokens,{color:p.foreground},n),t)),r();break;case"text":o.push(...Pt("tokens"in i&&i.tokens!==void 0?an(i.tokens,{color:p.foreground},n):[{text:pp(i.text,n),color:p.foreground}],t));break;case"code":for(let s of i.text.split(`
9
- `))o.push(...Pt([{text:` ${s}`,color:p.mutedForeground}],t,2));r();break;case"blockquote":{let s=rl(i.tokens??[],Math.max(4,t-2),n);for(;s.length>0&&xs(s[s.length-1]);)s.pop();for(let a of s)o.push({spans:[{text:`${ie.section} `,color:p.accent},...a.spans.map(c=>({...c,color:c.color??p.mutedForeground}))]});r();break}case"list":{let s=i.ordered===!0,a=typeof i.start=="number"?i.start:1;i.items.forEach((c,l)=>{let u=s?`${a+l}. `:`${ie.bullet} `,m=Qo(u),f=rl(c.tokens,Math.max(4,t-m),n);f.forEach((d,h)=>{xs(d)&&h===f.length-1||o.push({spans:h===0?[{text:u,color:p.mutedForeground},...d.spans]:[{text:" ".repeat(m)},...d.spans]})})}),r();break}case"hr":o.push({spans:[{text:"\u2500".repeat(Math.max(1,t)),color:p.faintForeground}]}),r();break;case"table":o.push(...cT(i.header,i.rows,i.raw,t,n)),r();break;default:o.push(...Pt([{text:i.raw,color:p.foreground}],t))}return o}var il=(e,t)=>an(e,{},t).map(n=>n.text).join("");function hn(e,t,n="default"){let o=eT.lex(Vn(e),{gfm:!0,breaks:n!=="docs"}),r=rl(o,Math.max(8,t),n);for(;r.length>0&&xs(r[r.length-1]);)r.pop();return r}import{Text as cn,useInput as lT}from"ink";import{useImperativeHandle as mT,useRef as fp,useEffect as uT,useState as hp}from"react";import sl from"string-width";import{jsx as yn,jsxs as al}from"react/jsx-runtime";var dT=e=>e.replace(new RegExp("\\p{Cc}","gu"),"");function gp(e,t,n){let o=t,r=0;for(;o>0;){let s=sl(e[o-1]??"");if(r+s>n)break;r+=s,o-=1}let i=t;for(r+=1;i<e.length;){let s=sl(e[i]??"");if(r+s>n)break;r+=s,i+=1}return{start:o,before:e.slice(o,t).join(""),at:e[t]??" ",after:e.slice(t+1,i).join("")}}function ei({char:e}){return yn(cn,{backgroundColor:p.cursorBackground,color:p.foreground,children:e})}function Zo({value:e,onChange:t,onSubmit:n,placeholder:o,mask:r=!1,isActive:i=!0,width:s=40,ref:a}){let c=[...e],[l,u]=hp(c.length),m=Math.min(l,c.length),f=Math.max(8,s),d=fp(e),h=fp(m);d.current=e,h.current=m,us(i);let y=S=>{h.current=S,u(S)},g=(S,v)=>{d.current=S,y(v),t(S)};if(mT(a,()=>({moveToColumn:S=>{let v=[...d.current],M=r?Array.from({length:v.length},()=>"\u2022"):v,O=gp(M,Math.min(h.current,v.length),f).start,U=0;for(;O<v.length;){let C=sl(M[O]??"");if(U+C>S)break;U+=C,O+=1}y(O)}})),lT((S,v)=>{let M=[...d.current],N=Math.min(h.current,M.length);if(v.return){n(d.current);return}if(v.tab||v.upArrow||v.downArrow)return;if(v.leftArrow){y(Math.max(0,N-1));return}if(v.rightArrow){y(Math.min(M.length,N+1));return}if(v.home){y(0);return}if(v.end){y(M.length);return}if(v.backspace){if(N===0)return;g([...M.slice(0,N-1),...M.slice(N)].join(""),N-1);return}if(v.delete){if(N>=M.length)return;g([...M.slice(0,N),...M.slice(N+1)].join(""),N);return}if(v.ctrl){if(S==="a")y(0);else if(S==="e")y(M.length);else if(S==="k")g(M.slice(0,N).join(""),N);else if(S==="u")g(M.slice(N).join(""),0);else if(S==="w"){let w=N;for(;w>0&&M[w-1]===" ";)w-=1;for(;w>0&&M[w-1]!==" ";)w-=1;g([...M.slice(0,w),...M.slice(N)].join(""),w)}return}if(v.meta||!S)return;let O=S.search(/[\r\n]/),U=dT(O===-1?S:S.slice(0,O)),C=[...M.slice(0,N),U,...M.slice(N)].join("");g(C,N+[...U].length),O!==-1&&n(C)},{isActive:i}),e===""){let S=[...o??""];return i?al(cn,{children:[yn(ei,{char:S[0]??" "}),yn(cn,{color:p.faintForeground,children:S.slice(1).join("")})]}):yn(cn,{color:p.faintForeground,children:S.join("")})}let x=r?Array.from({length:c.length},()=>"\u2022"):c;if(!i)return yn(cn,{color:p.foreground,children:x.join("")});let{before:T,at:R,after:b}=gp(x,m,f);return al(cn,{children:[yn(cn,{color:p.foreground,children:T}),yn(ei,{char:R}),yn(cn,{color:p.foreground,children:b})]})}function De({label:e}){let[t,n]=hp(0);return uT(()=>{let o=setInterval(()=>n(r=>(r+1)%Xo.length),Ss);return()=>clearInterval(o)},[]),al(cn,{children:[yn(cn,{color:p.accent,children:Xo[t]}),yn(cn,{color:p.mutedForeground,children:` ${e}`})]})}import{Box as Sp,Text as er}from"ink";import{useEffect as Tp,useState as fT}from"react";import xp from"string-width";import{Box as yp,Text as Ts}from"ink";import pT from"string-width";import{jsx as ti,jsxs as bp}from"react/jsx-runtime";var pe=2,Bt=1,We=1,Ze=Bt+We;function Rn({title:e,note:t,width:n}){let o=t===void 0?0:pT(t)+2,r=Math.max(0,n-pe-o);return bp(Ts,{wrap:"truncate",children:[ti(Ts,{color:p.accent,children:`${ie.section} `}),ti(Ts,{bold:!0,color:p.foreground,children:Ge(e,r)}),t!==void 0&&ti(Ts,{color:p.faintForeground,children:` ${t}`})]})}function de({title:e,note:t,width:n,gap:o=We,children:r}){return bp(yp,{flexDirection:"column",children:[ti(Rn,{title:e,note:t,width:n}),ti(yp,{flexDirection:"column",marginTop:o,paddingLeft:pe,children:r})]})}import{jsx as Cn,jsxs as kp}from"react/jsx-runtime";var yo=e=>!("heading"in e),gT=e=>e.flatMap(t=>!yo(t)&&t.heading!==""?[t,{heading:""}]:[t]),wp=2,ws=2,hT=(e,t)=>t===void 0?e:e>t?Math.max(1,t-1):t;function yT(e,t,n,o){let[r,i]=Ie(o,()=>e.findIndex(u=>yo(u)&&u.disabled!==!0));Tp(()=>{i(u=>{let m=Math.min(u,e.length-1);for(let f=0;f<e.length;f+=1)for(let d of[m-f,m+f]){let h=e[d];if(h!==void 0&&yo(h)&&h.disabled!==!0)return d}return Math.max(0,m)})},[e.length]);let s=u=>{i(m=>{let f=e.length;if(f===0)return m;let d=m;for(let h=0;h<f;h+=1){d=(d+u+f)%f;let y=e[d];if(y!==void 0&&yo(y)&&y.disabled!==!0)return d}return m})},a=u=>{let m=e[u];return m!==void 0&&yo(m)&&m.disabled!==!0?m:null},c=u=>{a(u)!==null&&i(u)},l=u=>{let m=a(u);m!==null&&(i(u),n(m.value))};return G((u,m)=>{if(m.upArrow||u==="k"){s(-1);return}if(m.downArrow||u==="j"){s(1);return}m.return&&l(r)},t),{index:Math.max(0,r),step:s,pick:l,moveTo:c}}function cl(e,t){let[n,o]=fT(()=>e>=t?e-t+1:0);return Tp(()=>{o(r=>e<r?e:e>=r+t?e-t+1:r)},[e,t]),n}function bT(e,t){let n=e.filter(yo),o=Math.max(0,...n.map(s=>xp(s.label))),r=Math.max(0,...n.map(s=>s.badge===void 0?0:xp(s.badge))),i=wp+o+(r>0?r+ws:0)+ws;return{label:o,badge:r,hint:Math.max(0,t-i)}}function ST({item:e,active:t,metrics:n}){let o=e.disabled===!0,r=o?p.faintForeground:e.labelTone!==void 0?tt[e.labelTone]:t?p.accent:p.foreground;return kp(er,{wrap:"truncate",children:[Cn(er,{color:p.accent,children:t?`${ie.cursor} `:" "}),Cn(er,{color:r,bold:t,children:Qe(e.label,n.label)}),n.badge>0&&Cn(er,{color:e.badgeTone===void 0?p.faintForeground:tt[e.badgeTone],children:`${" ".repeat(ws)}${Qe(e.badge??"",n.badge)}`}),e.hint!==void 0&&n.hint>0&&Cn(er,{color:o||!t?p.faintForeground:p.mutedForeground,children:`${" ".repeat(ws)}${Ge(e.hint,n.hint)}`})]})}function xT({items:e,cursor:t,metrics:n,window:o,width:r,isActive:i,onPick:s,onHover:a,onScroll:c}){let l=cl(t,o),u=e.slice(l,l+o),m=d=>d<u.length?l+d:null,f=rt({isActive:i,onWheel:c,onClick:({row:d})=>{let h=m(d);h!==null&&s(h)},onHover:({row:d})=>{let h=m(d);h!==null&&a(h)}});return kp(Sp,{ref:f,flexDirection:"column",children:[u.map((d,h)=>{let y=l+h;return yo(d)?Cn(ST,{item:d,active:y===t&&i,metrics:n},y):d.heading===""?Cn(Sp,{height:1},y):Cn(Rn,{title:d.heading,width:r},y)}),e.length>o&&Cn(er,{color:p.faintForeground,children:`${" ".repeat(wp)}${l+1}-${Math.min(l+o,e.length)} / ${e.length}`})]})}function ce({items:e,onSelect:t,width:n,height:o,isActive:r=!0,retain:i}){let s=gT(e),a=yT(s,r,t,i);return Cn(xT,{items:s,cursor:a.index,metrics:bT(s,n),window:hT(s.length,o),width:n,isActive:r,onPick:a.pick,onHover:a.moveTo,onScroll:a.step})}import{jsx as Xt,jsxs as ks}from"react/jsx-runtime";var vp={ok:{glyph:ie.ok,color:p.success},warn:{glyph:ie.warn,color:p.warning},fail:{glyph:ie.fail,color:p.danger},info:{glyph:ie.bullet,color:p.mutedForeground}},ll=2,ml=(e,t)=>Pt([{text:Vn(e)}],t-ll).map(n=>n.spans.map(o=>o.text).join("")),ul=(e,t,n)=>ml(e,n).length+(t===void 0?0:ml(t,n).length);function he({tone:e,title:t,detail:n,width:o,wrap:r=!1}){let i=vp[e],s=c=>r?ml(c,o):[Ge(c,o-ll)],a=" ".repeat(ll);return ks(ni,{flexDirection:"column",children:[s(t).map((c,l)=>ks(tr,{children:[Xt(tr,{color:i.color,children:l===0?`${i.glyph} `:a}),Xt(tr,{color:p.foreground,children:c})]},l)),n!==void 0&&s(n).map((c,l)=>Xt(tr,{color:p.faintForeground,children:`${a}${c}`},`detail-${l}`))]})}function Ft({message:e,hint:t,width:n}){return Xt(he,{tone:"fail",title:e,detail:t,width:n})}var TT=2,wT=2;function Rp({tone:e,message:t,width:n,onDismiss:o}){let r=vp[e],i=rt({onClick:o});return ks(ni,{ref:i,children:[Xt(tr,{backgroundColor:p.border,color:r.color,wrap:"truncate",children:` ${r.glyph} `}),Xt(tr,{backgroundColor:p.border,color:p.foreground,wrap:"truncate",children:`${Ge(t,n-TT-wT)} `})]})}function Ae({title:e,detail:t,confirmLabel:n,onConfirm:o,onCancel:r,width:i,busy:s,error:a}){return ks(ni,{flexDirection:"column",children:[Xt(he,{tone:"warn",title:e,detail:t,width:i}),a!=null&&Xt(ni,{marginTop:1,children:Xt(Ft,{message:a.message,hint:a.hint,width:i})}),Xt(ni,{marginTop:1,children:typeof s=="string"?Xt(De,{label:s}):Xt(ce,{items:[{value:"cancel",label:"\u53D6\u6D88"},{value:"confirm",label:n,labelTone:"danger"}],width:i,onSelect:c=>c==="confirm"?o():r()})})]})}import{Box as kT,Text as vs,useInput as vT}from"ink";import{useRef as RT}from"react";import{jsx as Rs,jsxs as CT}from"react/jsx-runtime";function dt({lines:e,height:t,isActive:n=!0,pinBottom:o=!1,pageKeysOnly:r=!1,start:i=0,retain:s}){let a=e.length>t,c=a?Math.max(1,t-1):t,l=Math.max(0,e.length-c),[u,m]=Ie(s,()=>o?l:Math.min(i,l)),f=RT(l);if(l!==f.current||u>l){let g=u>=f.current;f.current=l;let x=o&&g?l:Math.min(u,l);x!==u&&m(x)}let d=g=>m(x=>Math.min(Math.max(0,x+g),l));vT((g,x)=>{x.pageUp?d(-c):x.pageDown?d(c):!r&&x.upArrow?d(-1):!r&&x.downArrow&&d(1)},{isActive:n&&a}),G(g=>{g==="k"?d(-1):g==="j"&&d(1)},n&&a&&!r);let h=rt({isActive:n&&a,onWheel:d}),y=e.slice(u,u+c);return CT(kT,{ref:h,flexDirection:"column",children:[y.map((g,x)=>Rs(vs,{wrap:"truncate",children:g.spans.length===0?" ":g.spans.map((T,R)=>Rs(vs,{color:T.color??p.foreground,bold:T.bold===!0,children:T.text},R))},u+x)),Array.from({length:Math.max(0,c-y.length)},(g,x)=>Rs(vs,{children:" "},x)),a&&Rs(vs,{color:p.faintForeground,wrap:"truncate",children:`${u+1}-${Math.min(u+c,e.length)} / ${e.length}`})]})}function ht(e){return e.tone==="neutral"?void 0:e.tone}function yt(e){let t=ht(e);return t===void 0?e.label:{text:e.label,tone:t}}import{useCallback as dl,useRef as _T,useState as Cp}from"react";function le(){let e=L(),[t,n]=Cp(null),[o,r]=Cp(null),i=_T(0),s=dl(()=>{i.current+=1,n(null),r(null)},[]),a=dl((l,u)=>{r({message:l,hint:u})},[]),c=dl((l,u,m={})=>{let f=i.current+=1;n(l),r(null),u().then(d=>{i.current===f&&(n(null),m.onSuccess?.(d))}).catch(d=>{if(i.current!==f)return;n(null);let h={message:xe(d),hint:d instanceof j?d.hint:void 0};m.failToast===!0?e.toast("fail",h.message):r(h)})},[e]);return{busy:t,error:o,reset:s,fail:a,run:c}}import{Box as rr}from"ink";import{Box as PT,Text as _p}from"ink";import Ap from"string-width";import{jsx as Pp,jsxs as AT}from"react/jsx-runtime";var Cs=["\u2588\u2580\u2580 \u2588\u2580\u2588 \u2588\u2580\u2584 \u2588\u2580\u2580 \u2588\u2580\u2580 \u2588 \u2588\u2580\u2588 \u2588 \u2588 \u2588","\u2588\u2584\u2584 \u2588\u2584\u2588 \u2588\u2584\u2580 \u2588\u2584\u2584 \u2588\u2580\u2580 \u2588\u2584\u2584 \u2588\u2584\u2588 \u2580\u2584\u2580\u2584\u2580"],Ep=Math.max(...Cs.map(e=>Ap(e))),_s=Cs.length,Ps=e=>Ep<=e;function As({width:e}){let t=`v${Vt}`,n=Ep+2+Ap(t)<=e;return Pp(PT,{flexDirection:"column",children:Cs.map((o,r)=>AT(_p,{color:p.accent,children:[o,r===Cs.length-1&&n&&Pp(_p,{color:p.faintForeground,children:` ${t}`})]},o))})}import{Box as gl,Text as wt}from"ink";import{useState as Mp}from"react";import bo from"string-width";import{jsx as Qt,jsxs as or}from"react/jsx-runtime";var Es=2,pl=` ${ie.crumb} `;function Ms({trail:e,width:t,onBack:n,isActive:o}){let r=e[e.length-1]??"",i=e.slice(0,-1),s=i.reduce((f,d)=>f+bo(d)+bo(pl),0),a=s+bo(r)<=t,c=a?s:0,[l,u]=Mp(!1),m=rt({isActive:o,onClick:({column:f})=>{f<c&&n()},onHover:({column:f})=>u(f<c),onHoverLeave:()=>u(!1)});return Qt(gl,{ref:m,marginBottom:1,children:a?or(wt,{children:[i.map((f,d)=>or(wt,{children:[Qt(wt,{color:d===0?p.accent:l&&o?p.foreground:p.mutedForeground,children:f}),Qt(wt,{color:p.faintForeground,children:pl})]},d)),Qt(wt,{bold:!0,color:p.foreground,children:r})]}):Qt(wt,{color:p.mutedForeground,children:Ge(e.join(pl),t)})})}var fl=2,oi=2,nr=2;function Ip({current:e,width:t,onPick:n,isActive:o,unread:r}){let i=Math.max(0,Xr(e)),[s,a]=Mp(null),c=S=>r[S.id]===!0,l=S=>c(S)?`${S.label} ${ie.dot}`:S.label,u=Math.max(...Tt.map(S=>bo(S.label))),m=Tt.some(c)?bo(` ${ie.dot}`):0,d=(S=>S*u+(S-1)*oi+fl+m)(Tt.length)>t,h=d?t-nr*2:t,y=d?Math.max(1,Math.floor((h-m+oi-fl)/(u+oi))):Tt.length,g=Math.min(Math.max(0,i-Math.floor((y-1)/2)),Tt.length-y),x=Tt.slice(g,g+y),T=[],R=d?nr:0;x.forEach((S,v)=>{v>0&&(R+=oi);let M=bo(l(S))+(S.id===e?fl:0);T.push({id:S.id,from:R,to:R+M}),R+=M});let b=rt({isActive:o,onHover:({column:S})=>{let v=T.find(M=>S>=M.from&&S<M.to);a(v?.id??null)},onHoverLeave:()=>a(null),onClick:({column:S})=>{let v=T.find(N=>S>=N.from&&S<N.to);if(v!==void 0){n(v.id);return}if(!d||S>=nr&&S<R)return;let M=S<nr?Tt[g-1]:Tt[g+y];M!==void 0&&n(M.id)}});return Qt(gl,{ref:b,marginBottom:1,children:or(wt,{wrap:"truncate",children:[d&&Qt(wt,{color:p.border,children:g>0?`${ie.prev} `:" ".repeat(nr)}),x.map((S,v)=>{let M=c(S)&&Qt(wt,{color:p.danger,children:` ${ie.dot}`});return or(wt,{children:[v>0&&" ".repeat(oi),S.id===e?or(wt,{backgroundColor:p.foreground,color:p.background,bold:!0,children:[` ${S.label}`,M," "]}):or(wt,{children:[Qt(wt,{color:o&&S.id===s?p.foreground:p.mutedForeground,children:S.label}),M]})]},S.id)}),d&&Qt(wt,{color:p.border,children:g+y<Tt.length?` ${ie.next}`:" ".repeat(nr)})]})})}var ET=2;function Np(e,t){let n=[];for(let o of e){let r=n[n.length-1];if(r!==void 0&&bo(_e([...r,o]))<=t)r.push(o);else if(n.length<ET)n.push([o]);else break}return n.map(_e)}function Lp({lines:e}){return Qt(gl,{flexDirection:"column",flexShrink:0,children:e.map((t,n)=>Qt(wt,{wrap:"truncate",color:p.faintForeground,children:t},n))})}import{createContext as MT,useCallback as IT,useContext as NT,useEffect as Fp,useMemo as LT,useRef as Up,useState as OT}from"react";var Op=e=>P(lt(nd),je("/inbox",{...e})),Dp=()=>P(od,"/inbox/unread"),$p=e=>P(se,`/inbox/${e}/read`,{method:"POST"}),Bp=()=>P(se,"/inbox/read-all",{method:"POST"});import{jsx as $T}from"react/jsx-runtime";var DT=6e4,jp=MT(null);function Hp({children:e}){let{revision:t,toast:n}=L(),[o,r]=OT(!1),i=Up(0),s=Up(!1),a=IT(()=>{let l=i.current+=1;if(Lt().session===null){r(!1);return}Dp().then(u=>{s.current=!1,i.current===l&&r(u.unread)},u=>{i.current!==l||s.current||(s.current=!0,n("warn",`\u7AD9\u5185\u6D88\u606F\u672A\u8BFB\u72B6\u6001\u83B7\u53D6\u5931\u8D25\uFF1A${xe(u)}`))})},[n]);Fp(a,[t,a]),Fp(()=>{let l=setInterval(a,DT);return()=>clearInterval(l)},[a]);let c=LT(()=>({any:o,refresh:a}),[o,a]);return $T(jp.Provider,{value:c,children:e})}function Is(){let e=NT(jp);if(!e)throw new Error("useUnread \u5FC5\u987B\u5728 UnreadProvider \u5185\u4F7F\u7528");return e}import{Fragment as FT,jsx as kt,jsxs as Wp}from"react/jsx-runtime";var qp=3,BT=8;function ri(e){let{rows:t}=H();return Math.max(1,t-Yc-qp-e)}function Gp(){let e=L(),{width:t,rows:n}=H(),o=e.current.id,r=e.depth===1&&gs(o)?o:null,i=Math.max(1,n-Yc-qp),s=_s+Q,a=r!==null&&Ps(t)&&i-Es-s>=BT;return{tab:r,mark:a,rows:a?Es+s:Es}}var te=()=>ri(Gp().rows);function So({header:e,hints:t,children:n}){let{width:o}=H(),{message:r,dismissToast:i}=L(),s=Np(t,o);return Wp(rr,{flexDirection:"column",flexGrow:1,children:[kt(rr,{flexDirection:"column",flexShrink:0,children:e}),kt(rr,{flexDirection:"column",flexGrow:1,overflow:"hidden",children:kt(rr,{flexDirection:"column",flexShrink:0,children:n})}),kt(rr,{height:1,marginTop:s.length>1?0:1,flexShrink:0,justifyContent:"flex-end",children:r!==null&&kt(Rp,{tone:r.tone,message:r.message,width:o,onDismiss:i})}),kt(Lp,{lines:s})]})}function K({trail:e,hints:t=[],children:n,onEscape:o,isActive:r=!0,locked:i=!1,bleed:s=!1}){let a=L(),{width:c}=H(),{tab:l,mark:u}=Gp(),m=Is(),f=ds(),d=ps(),h=Jd(),y=r&&!h,g=y?t:t.filter(S=>S!=="Esc \u8FD4\u56DE"),x=d||f?[]:[...r?["[] \u5207\u529F\u80FD"]:[],"q \u9000\u51FA","? \u5E2E\u52A9"],T=[...y?["Esc \u8FD4\u56DE"]:[],...d||f?[]:["? \u5E2E\u52A9"]];gn(o??a.pop,{isActive:r});let R=Xd(),b=r&&!i&&!f;return G(S=>{if(l===null||S!=="["&&S!=="]")return;let v=Tt[(Xr(l)+(S==="["?-1:1)+Tt.length)%Tt.length];v!==void 0&&a.select(v.id)},r&&!i&&!f&&!s),s?kt(So,{header:null,hints:i?g:[...g,...T],children:n}):l!==null?kt(So,{header:Wp(FT,{children:[u&&kt(rr,{marginBottom:Q,children:kt(As,{width:c})}),kt(Ip,{current:l,width:c,onPick:S=>{S===l?R():a.select(S)},isActive:b,unread:{inbox:m.any}})]}),hints:i?g:[...g,...x],children:n}):kt(So,{header:kt(Ms,{trail:["CodeFlow",...e??[]],width:c,onBack:R,isActive:b}),hints:i?g:[...g,...T],children:n})}function W({state:e,loading:t,width:n,children:o}){return e.phase==="loading"?kt(De,{label:t}):e.phase==="error"?kt(Ft,{message:e.message,hint:e.hint,width:n}):o(e.data)}import{jsx as Zt,jsxs as hl}from"react/jsx-runtime";function zp({params:e}){let t=L(),{width:n}=H(),o=te(),{item:r}=e,{busy:i,error:s,run:a}=le();UT((m,f)=>{f.return&&a("\u6B63\u5728\u786E\u8BA4",()=>ss(r.id),{onSuccess:()=>t.pop()})},{isActive:i===null});let c=Wr(r.level),l=ht(c),u=Math.max(3,o-4-(s===null?0:2));return Zt(K,{trail:["\u7CFB\u7EDF\u516C\u544A","\u672A\u8BFB\u786E\u8BA4"],hints:["\u2191\u2193 \u6EDA\u52A8","Enter \u6211\u77E5\u9053\u4E86"],locked:!0,onEscape:()=>{},children:hl(Ns,{flexDirection:"column",children:[hl(xo,{wrap:"truncate",children:[Zt(xo,{bold:!0,color:p.foreground,children:r.title}),Zt(xo,{color:l===void 0?p.mutedForeground:tt[l],children:` ${c.label}`}),Zt(xo,{color:p.faintForeground,children:` \u53D1\u5E03\u4E8E ${V(r.publishedAt)}`})]}),Zt(Ns,{marginTop:1,children:Zt(dt,{lines:hn(r.content,n),height:u})}),s!==null&&Zt(Ns,{marginTop:1,children:Zt(Ft,{message:s.message,hint:s.hint,width:n})}),Zt(Ns,{marginTop:1,children:i!==null?Zt(De,{label:i}):hl(xo,{wrap:"truncate",children:[Zt(xo,{color:p.accent,children:`${ie.cursor} `}),Zt(xo,{bold:!0,color:p.accent,children:"\u6211\u77E5\u9053\u4E86"})]})})]})})}import{Box as wl,Text as Ls}from"ink";import{useState as XT}from"react";import{Box as yl,Text as _n}from"ink";import{useEffect as bl,useRef as jT,useState as Vp}from"react";import Sl from"string-width";import{jsx as Yn,jsxs as si}from"react/jsx-runtime";var Kp=e=>e===void 0?"":typeof e=="string"?e:e.text,xl=2,HT=6;function qT(e,t,n){let o=e.map(a=>t===0?n/e.length:n*a/t),r=o.map(a=>Math.floor(a)),i=n-r.reduce((a,c)=>a+c,0),s=o.map((a,c)=>({i:c,fraction:a-Math.floor(a)})).sort((a,c)=>c.fraction-a.fraction);for(let{i:a}of s){if(i<=0)break;r[a]=(r[a]??0)+1,i-=1}return e.map((a,c)=>a+(r[c]??0))}function Tl(e,t,n){let o=e.map((c,l)=>Math.max(Sl(c.label),...t.map(u=>Sl(u[l]??"")))),r=o.reduce((c,l)=>c+l,0),i=r+xl*Math.max(0,e.length-1)-n;if(i<0)return qT(o,r,-i);e.forEach((c,l)=>{if(c.cap===void 0||i<=0)return;let u=Math.min(i,Math.max(0,(o[l]??0)-c.cap));o[l]=(o[l]??0)-u,i-=u});let s=e.flatMap((c,l)=>c.shrink===!0||c.cap!==void 0?[l]:[]),a=s.length>0?s:e.map((c,l)=>l);for(;i>0;){let c=a.filter(l=>(o[l]??0)>HT).sort((l,u)=>(o[u]??0)-(o[l]??0))[0];if(c===void 0)break;o[c]=(o[c]??0)-1,i-=1}return o}var GT=(e,t,n)=>t.map((o,r)=>o.align==="right"?Kn(e[r]??"",n[r]??0):Qe(e[r]??"",n[r]??0)).join(" ".repeat(xl)),ii=2,WT=2;function ue({items:e,columns:t,row:n,width:o,height:r,onOpen:i,searchOf:s,isActive:a=!0,emptyLabel:c="\u6682\u65E0\u6570\u636E",emptyDescription:l,retain:u,select:m}){let f=D=>u===void 0?void 0:`${u}:${D}`,d=i!==void 0,[h,y]=Ie(d?f("cursor"):void 0,()=>0),[g,x]=Ie(f("query"),()=>""),[T,R]=Vp(!1),b=g.trim().toLowerCase(),S=b===""||s===void 0?e:e.filter(D=>s(D).toLowerCase().includes(b)),v=T||b!=="",M=Math.max(1,r-1-(v?1:0)),N=S.length>M?Math.max(1,M-1):M,O=Math.max(0,S.length-N),[U,C]=Vp(()=>h>=N?h-N+1:0);bl(()=>{y(D=>Math.min(D,Math.max(0,S.length-1)))},[S.length]);let w=m===void 0?-1:S.findIndex(m);bl(()=>{w>=0&&y(w)},[w]),bl(()=>{C(D=>d?h<D?h:h>=D+N?h-N+1:D:Math.min(D,O))},[h,N,O,d]);let E=D=>{if(!d){C(k=>Math.min(Math.max(0,k+D),O));return}S.length!==0&&y(k=>(k+D+S.length)%S.length)};G((D,k)=>{if(k.upArrow||D==="k"){E(-1);return}if(k.downArrow||D==="j"){E(1);return}if(k.return){let X=S[h];X!==void 0&&i?.(X,h);return}s!==void 0&&D.startsWith("/")&&(R(!0),D.length>1&&x(D.slice(1)))},a&&!T),gn(()=>{R(!1),x("")},{isActive:T||b!=="",layer:T?zn.input:zn.panel});let _=v?1:0,A=jT(null),$=D=>{if(D<=_)return null;let k=U+D-_-1;return S[k]===void 0?null:k},Z=rt({isActive:a,onWheel:E,onClick:({row:D,column:k})=>{if(v&&D===0){R(!0),A.current?.moveToColumn(k-WT);return}if(i===void 0)return;let X=$(D);if(X===null)return;let F=S[X];F!==void 0&&(y(X),i(F,X))},onHover:d?({row:D})=>{let k=$(D);k!==null&&y(k)}:void 0}),oe=Tl(t,S.map(D=>n(D).map(Kp)),o-ii),fe=S.slice(U,U+N);return si(yl,{ref:Z,flexDirection:"column",children:[v&&si(yl,{children:[Yn(_n,{color:p.accent,children:"/ "}),Yn(Zo,{ref:A,value:g,onChange:x,onSubmit:()=>R(!1),isActive:T,placeholder:"\u8F93\u5165\u5173\u952E\u8BCD\u8FC7\u6EE4",width:o-2-Sl(` ${S.length}/${e.length}`)}),Yn(_n,{color:p.faintForeground,children:` ${S.length}/${e.length}`})]}),si(_n,{wrap:"truncate",color:p.faintForeground,children:[" ".repeat(ii),GT(t.map(D=>D.label),t,oe)]}),S.length===0?si(yl,{flexDirection:"column",children:[Yn(_n,{wrap:"truncate",color:p.mutedForeground,children:`${" ".repeat(ii)}${b===""?c:"\u65E0\u5339\u914D\u7ED3\u679C"}`}),l!==void 0&&b===""&&M>1&&Yn(_n,{wrap:"truncate",color:p.faintForeground,children:`${" ".repeat(ii)}${l}`})]}):fe.map((D,k)=>{let X=U+k,F=d&&X===h&&a,re=F?p.accent:a?p.foreground:p.mutedForeground,B=n(D);return si(_n,{wrap:"truncate",children:[Yn(_n,{color:p.accent,children:F?`${ie.cursor} `:" "}),t.map((z,Y)=>{let be=B[Y],Me=Kp(be),ge=z.align==="right"?Kn(Me,oe[Y]??0):Qe(Me,oe[Y]??0),et=typeof be=="object"?be.tone:void 0,Be=!F&&a&&et!==void 0?tt[et]:re;return Yn(_n,{color:Be,bold:F,children:Y>0?`${" ".repeat(xl)}${ge}`:ge},z.label)})]},X)}),(U>0||U+N<S.length)&&Yn(_n,{color:p.faintForeground,children:`${" ".repeat(ii)}${U+1}-${Math.min(U+N,S.length)} / ${S.length}`})]})}import{Text as zT}from"ink";import{useEffect as VT,useRef as KT,useState as YT}from"react";import{jsx as JT}from"react/jsx-runtime";function Ve(e,t,{retain:n}={}){let[o,r]=Ie(n,()=>1),[i,s]=YT({pages:1,total:0}),a=KT(!1),c=ee([...e,o],()=>t(o));VT(()=>{if(c.phase!=="ready")return;let f=Math.max(1,Math.ceil(c.data.total/ou));if(s({pages:f,total:c.data.total}),o>f){r(f);return}a.current&&(a.current=!1,o<f&&r(f))},[c]);let l=f=>{r(d=>Math.min(Math.max(1,d+f),i.pages))},u=()=>r(1),m=()=>{a.current=!0};return{state:c,page:o,pages:i.pages,total:i.total,go:l,reset:u,last:m}}function Ke({page:e,pages:t,total:n,width:o}){return JT(zT,{wrap:"truncate",color:p.faintForeground,children:Ge(_e([`\u7B2C ${e} / ${t} \u9875`,`\u5171 ${n} \u6761`,"\u2190\u2192 \u7FFB\u9875"]),o)})}import{jsx as Pn,jsxs as kl}from"react/jsx-runtime";function Yp(){let e=L(),{width:t}=H(),n=te(),[o,r]=XT({name:"list"}),i=Ve([e.revision],a=>Ud({page:a}),{retain:"page"});G((a,c)=>{o.name==="list"&&(a==="r"?e.reload():c.leftArrow?i.go(-1):c.rightArrow&&i.go(1))});let s=()=>{o.name==="list"?e.pop():r({name:"list"})};return Pn(K,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","Esc \u8FD4\u56DE"],onEscape:s,children:Pn(W,{state:i.state,loading:"\u6B63\u5728\u8BFB\u53D6\u516C\u544A",width:t,children:a=>{if(o.name==="detail"){let c=Wr(o.item.level),l=ht(c);return kl(wl,{flexDirection:"column",children:[kl(Ls,{wrap:"truncate",children:[Pn(Ls,{bold:!0,color:p.foreground,children:o.item.title}),Pn(Ls,{color:l===void 0?p.mutedForeground:tt[l],children:` ${c.label}`}),Pn(Ls,{color:p.faintForeground,children:` ${_e([`\u53D1\u5E03\u4E8E ${V(o.item.publishedAt)}`])}`})]}),Pn(wl,{marginTop:1,children:Pn(dt,{lines:hn(o.item.content,t),height:Math.max(3,n-2)})})]})}return kl(wl,{flexDirection:"column",children:[Pn(ue,{retain:"list",items:a.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u7EA7\u522B"},{label:"\u53D1\u5E03\u4E8E",align:"right"}],row:c=>[c.title,yt(Wr(c.level)),V(c.publishedAt)],onOpen:c=>{r({name:"detail",item:c}),ss(c.id).catch(()=>e.toast("warn","\u5DF2\u8BFB\u786E\u8BA4\u53D1\u9001\u5931\u8D25"))},emptyLabel:"\u6682\u65E0\u516C\u544A",emptyDescription:"\u5E73\u53F0\u6709\u65B0\u901A\u77E5\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),Pn(Ke,{page:i.page,pages:i.pages,total:i.total,width:t})]})}})})}import{Box as bt,Text as fi}from"ink";import{useState as hg}from"react";import Gw from"string-width";import{z as QT}from"zod";var Os=12e4,Ds=e=>`/community/${e.kind==="user"?"users":"staff"}/${encodeURIComponent(e.username)}`,$s=()=>P(QT.array(Rc),"/community/categories"),ir=()=>P(Xu,"/community/me"),Jp=e=>P(lt(Cc),je("/community/posts",{...e})),Bs=e=>P(Vu,`/community/posts/${e}`),Xp=e=>P(se,`/community/posts/${e}/view`,{method:"POST"}),Qp=(e,t)=>P(lt(Pc),je(`/community/posts/${e}/floors`,{page:t})),Zp=(e,t)=>P(Pc,`/community/posts/${e}/floors/${t}`),ef=(e,t)=>P(lt(_c),je(`/community/comments/${e}/replies`,{page:t})),vl=e=>P(Zu,Ds({kind:"user",username:e})),tf=e=>e.kind==="user"?vl(e.username):P(ed,Ds(e)),nf=(e,t)=>P(lt(Fr),je(`${Ds(e)}/posts`,{page:t})),of=(e,t)=>P(lt(Hi),je(`${Ds(e)}/comments`,{page:t})),rf=e=>P(lt(Cc),je("/community/mine/bookmarks",{page:e})),sf=e=>P(lt(Ec),je("/community/mine/drafts",{page:e})),af=()=>P(Yu,"/community/mine/todo"),cf=e=>P(Br,"/community/posts",{method:"POST",json:e,timeoutMs:Os}),lf=(e,t)=>P(Br,`/community/posts/${e}`,{method:"PATCH",json:t,timeoutMs:Os}),Fs=e=>P(se,`/community/posts/${e}`,{method:"DELETE"}),mf=e=>P(Ju,"/community/drafts",{method:"POST",json:e}),uf=(e,t)=>P(se,`/community/drafts/${e}`,{method:"PATCH",json:t}),df=(e,t)=>P(Br,`/community/drafts/${e}/publish`,{method:"POST",json:t,timeoutMs:Os}),pf=(e,t)=>P(Br,`/community/posts/${e}/comments`,{method:"POST",json:t,timeoutMs:Os}),ff=e=>P(se,`/community/comments/${e}`,{method:"DELETE"}),gf=(e,t)=>P(Ac,`/community/posts/${e}/like`,{method:t?"PUT":"DELETE"}),hf=(e,t)=>P(Ac,`/community/comments/${e}/like`,{method:t?"PUT":"DELETE"}),yf=(e,t)=>P(se,`/community/posts/${e}/bookmark`,{method:t?"PUT":"DELETE"}),bf=(e,t)=>P(se,`/community/posts/${e}/reports`,{method:"POST",json:t}),Sf=(e,t)=>P(se,`/community/comments/${e}/reports`,{method:"POST",json:t});var An=()=>P(cu,"/auth/me"),xf=e=>P(se,"/auth/me",{method:"PATCH",json:e}),Tf=e=>P(se,"/auth/me/password",{method:"POST",json:e}),wf=e=>P(se,"/auth/me/email/code",{method:"POST",json:e}),kf=e=>P(se,"/auth/me/email",{method:"POST",json:e}),vf=()=>P(lu,"/auth/me/sessions"),Rf=e=>P(se,`/auth/me/sessions/${e}`,{method:"DELETE"});async function Cf(){await P(se,"/auth/me/sessions",{method:"DELETE"}),ns()}var _f=()=>P(uu,"/auth/me/security"),Rl=e=>P(mu,"/auth/me/totp/setup",{method:"POST",json:e}),Pf=e=>P(uc,"/auth/me/totp/confirm",{method:"POST",json:e}),Af=e=>P(se,"/auth/me/totp/disable",{method:"POST",json:e}),Ef=e=>P(uc,"/auth/me/totp/recovery-codes",{method:"POST",json:e}),Mf=(e,t)=>P(se,`/auth/me/passkeys/${e}`,{method:"PATCH",json:t}),If=e=>P(se,`/auth/me/passkeys/${e}`,{method:"DELETE"});var Cl=12e4,ZT=e=>P(Hu,je("/media",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Cl}),ew=e=>P(se,`/media/${e}`,{method:"DELETE"}),ai={upload:async e=>({...await ZT(e),fileName:e.fileName}),discard:ew};async function Nf(e){let{bytes:t,headers:n}=await Kc(`/media/${e}`,{timeoutMs:Cl}),o=n.get("content-disposition")?.split("filename*=UTF-8''")[1];if(o===void 0)throw new j("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u9644\u4EF6\u6587\u4EF6\u540D");return{fileName:decodeURIComponent(o),bytes:t}}var Lf=e=>P(se,"/auth/me/avatar",{method:"PUT",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Cl}),Of=()=>P(se,"/auth/me/avatar",{method:"DELETE"});import{existsSync as Us,readFileSync as tw,statSync as Df,writeFileSync as nw}from"fs";import{homedir as _l}from"os";import en from"path";var ow={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif"},$f=e=>e.startsWith("~/")?en.join(_l(),e.slice(2)):e;function rw(e){return e.split(`
10
- `).map(t=>t.trim()).filter(t=>t!=="").map($f)}function Bf(e,t,n){if(!Us(e))throw new j(`${e} \u4E0D\u5B58\u5728`);let o=Df(e);if(!o.isFile())throw new j(`${e} \u4E0D\u662F\u6587\u4EF6`);if(o.size===0)throw new j(`${e} \u662F\u7A7A\u6587\u4EF6\uFF0C\u65E0\u6CD5\u4E0A\u4F20`);if(o.size>t)throw new j(`${e} \u8D85\u8FC7\u5355\u4E2A${n}\u5927\u5C0F\u4E0A\u9650 ${Vo(t)}`);let r=en.basename(e);return{filePath:e,fileName:r,contentType:ow[en.extname(r).toLowerCase()]??"application/octet-stream"}}function Ff(e){let t;try{t=tw(e.filePath)}catch(n){throw new j(`${e.filePath} \u8BFB\u53D6\u5931\u8D25\uFF1A${xe(n)}`,{cause:n})}return{fileName:e.fileName,contentType:e.contentType,bytes:t}}function Jn(e,t){let n=rw(e);if(n.length>t.maxCount)throw new j("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return n.map(o=>Bf(o,t.maxBytes,"\u9644\u4EF6"))}function Uf(e,t){let n=Bf($f(e),t,"\u56FE\u7247");if(!n.contentType.startsWith("image/"))throw new j("\u4EC5\u652F\u6301 PNG\u3001JPG\u3001WebP\u3001GIF\u3001AVIF \u683C\u5F0F\u7684\u56FE\u7247");return Ff(n)}async function En(e,t,n){let o=[];try{for(let r of e)o.push(await t.upload(Ff(r)));return await n(o)}catch(r){let s=(await Promise.allSettled(o.map(l=>t.discard(l.id)))).filter(l=>l.status==="rejected").length;if(s===0)throw r;let a=`${s} \u4E2A\u5DF2\u4E0A\u4F20\u7684\u9644\u4EF6\u672A\u80FD\u6E05\u7406\uFF0C\u5C06\u5728 24 \u5C0F\u65F6\u540E\u81EA\u52A8\u5220\u9664`,c=r instanceof j?r:null;throw new j(xe(r),{hint:c?.hint===void 0?a:`${c.hint}\uFF1B${a}`,...c===null?{}:{exitCode:c.exitCode},cause:r})}}function iw(e,t){let n=en.basename(t),o=en.extname(n),r=n.slice(0,n.length-o.length),i=en.join(e,n);for(let s=1;Us(i);s+=1)i=en.join(e,`${r}-${s}${o}`);return i}function sw(e,t){let n=e.trim();if(n==="")return{dir:process.cwd(),fileName:t};if(n==="~")return{dir:_l(),fileName:t};let o=n.startsWith("~/")||n.startsWith(`~${en.sep}`)?en.join(_l(),n.slice(2)):n;return n.endsWith("/")||n.endsWith(en.sep)||Us(o)&&Df(o).isDirectory()?{dir:o,fileName:t}:{dir:en.dirname(o),fileName:en.basename(o)}}function jf(e,t,n){let o=sw(e,t);if(!Us(o.dir))throw new j(`${o.dir} \u76EE\u5F55\u4E0D\u5B58\u5728`);let r=iw(o.dir,o.fileName);try{nw(r,n)}catch(i){throw new j(`\u5199\u5165 ${r} \u5931\u8D25\uFF1A${xe(i)}`,{cause:i})}return r}import{Box as tn,measureElement as Yf,Text as Ue,useInput as tg}from"ink";import{useEffect as Jf,useRef as Xf,useState as sr}from"react";import Ml from"string-width";import{Box as aw,Text as Xn,useInput as cw}from"ink";import{useRef as Hf,useState as qf}from"react";import Al from"string-width";import{jsx as Mn,jsxs as Vf}from"react/jsx-runtime";var lw=e=>e.replace(/\r\n?/g,`
11
- `).replace(new RegExp("(?!\\n)\\p{Cc}","gu"),"");function Gf(e,t){let n=[],o=0,r=0;for(let i=0;i<e.length;i+=1){let s=e[i]??"";if(s===`
12
- `){n.push({start:o,end:i,nl:!0}),o=i+1,r=0;continue}let a=Al(s);r+a>t&&i>o&&(n.push({start:o,end:i,nl:!1}),o=i,r=0),r+=a}return n.push({start:o,end:e.length,nl:!1}),n}function Wf(e,t){for(let n=0;n<e.length;n+=1){let o=e[n];if(o!==void 0&&(o.nl?t<=o.end:t<o.end))return n}return e.length-1}function zf(e,t,n){let o=0;for(let r=t.start;r<t.end;r+=1){let i=Al(e[r]??"");if(o+i>n)return r;o+=i}return t.end}var mw=(e,t,n)=>e.slice(t.start,n).reduce((o,r)=>o+Al(r),0);function Pl(e,t){let n=t;for(;n>0&&e[n-1]!==`
6
+ `){a();continue}let u=Zo(l);if(s+u>t&&i.length>n){if(l===" "){a();continue}let m=mT(i,l,n),p=m===null?[]:i.slice(m.carry),d=p.reduce((b,h)=>b+Zo(h.ch),0);m===null||n+d+u>t?a():(i=i.slice(0,m.end),a(),i=[...i,...p],s=n+d)}i.push(c),s+=u}return(i.length>0||r.length===0)&&r.push(pp(i)),r}var hp=(e,t)=>t==="docs"?e.replaceAll(`
7
+ `," "):e;function an(e,t,n){if(e===void 0)return[];let o=[];for(let r of e)switch(r.type){case"text":o.push(..."tokens"in r&&r.tokens!==void 0?an(r.tokens,t,n):[{text:hp(r.text,n),...t}]);break;case"strong":o.push(...an(r.tokens,{...t,bold:!0},n));break;case"em":o.push(...an(r.tokens,t,n));break;case"del":o.push(...an(r.tokens,{...t,color:f.faintForeground},n));break;case"codespan":o.push({text:r.text,color:f.accent,bold:t.bold});break;case"link":{let i=an(r.tokens,{...t,color:f.accent},n);o.push(...i);let s=i.map(a=>a.text).join("");r.href!==s&&!(n==="docs"&&iT(r.href))&&o.push({text:`\uFF08${r.href}\uFF09`,color:f.faintForeground});break}case"image":if(n==="docs"){o.push({text:r.text===""?"[\u56FE\u7247]":`[\u56FE\u7247] ${r.text}`,color:f.mutedForeground});break}o.push({text:r.text===""?"\u56FE\u7247":r.text,...t}),o.push({text:`\uFF08${r.href}\uFF09`,color:f.faintForeground});break;case"br":o.push({text:`
8
+ `});break;case"escape":o.push({text:r.text,...t});break;default:o.push({text:r.raw,...t})}return o}var fp=2,gp=e=>e.reduce((t,n)=>t+Zo(n.text),0);function dT(e,t,n,o,r){let i=e.map(d=>({spans:an(d.tokens,{bold:!0,color:f.foreground},r),align:d.align})),s=t.map(d=>d.map(b=>({spans:an(b.tokens,{color:f.foreground},r),align:b.align}))),a=o-(e.length+1)-e.length*2;if(a<e.length*fp)return Pt([{text:n,color:f.foreground}],o);let c=e.map(()=>fp);for(let d of[i,...s])d.forEach((b,h)=>{for(let g of Pt(b.spans,Number.MAX_SAFE_INTEGER)){let x=c[h],T=gp(g.spans);x!==void 0&&T>x&&(c[h]=T)}});let l=c.reduce((d,b)=>d+b,0);for(;l>a;){let d=0,b=0;c.forEach((h,g)=>{h>b&&(d=g,b=h)}),c[d]=b-1,l-=1}let u=d=>({text:d,color:f.faintForeground}),m=(d,b,h)=>({spans:[u(`${d}${c.map(g=>"\u2500".repeat(g+2)).join(b)}${h}`)]}),p=d=>{let b=c.map((x,T)=>{let k=d[T];return{width:x,align:k?.align??null,lines:Pt(k?.spans??[],x)}}),h=b.reduce((x,T)=>Math.max(x,T.lines.length),1),g=[];for(let x=0;x<h;x+=1){let T=[];for(let k of b){let S=k.lines[x]?.spans??[],y=k.width-gp(S),R=k.align==="right"?y:k.align==="center"?Math.floor(y/2):0;T.push(u("\u2502"),{text:` ${" ".repeat(R)}`}),T.push(...S),T.push({text:`${" ".repeat(y-R)} `})}T.push(u("\u2502")),g.push({spans:T})}return g};return[m("\u250C","\u252C","\u2510"),...p(i),m("\u251C","\u253C","\u2524"),...s.flatMap(p),m("\u2514","\u2534","\u2518")]}function rl(e,t,n){let o=[],r=()=>{o.length>0&&!Ss(o[o.length-1])&&o.push(sT)};for(let i of e)switch(i.type){case"space":r();break;case"heading":{let s=an(i.tokens,{bold:!0,color:f.foreground},n),a=i.depth<=2?[{text:`${ae.section} `,color:f.accent},...s]:s,c=n==="docs"?Ru(i.text):void 0;Pt(a,t,i.depth<=2?2:0).forEach((l,u)=>o.push(u===0?{...l,anchor:c}:l)),r();break}case"paragraph":o.push(...Pt(an(i.tokens,{color:f.foreground},n),t)),r();break;case"text":o.push(...Pt("tokens"in i&&i.tokens!==void 0?an(i.tokens,{color:f.foreground},n):[{text:hp(i.text,n),color:f.foreground}],t));break;case"code":for(let s of i.text.split(`
9
+ `))o.push(...Pt([{text:` ${s}`,color:f.mutedForeground}],t,2));r();break;case"blockquote":{let s=rl(i.tokens??[],Math.max(4,t-2),n);for(;s.length>0&&Ss(s[s.length-1]);)s.pop();for(let a of s)o.push({spans:[{text:`${ae.section} `,color:f.accent},...a.spans.map(c=>({...c,color:c.color??f.mutedForeground}))]});r();break}case"list":{let s=i.ordered===!0,a=typeof i.start=="number"?i.start:1;i.items.forEach((c,l)=>{let u=s?`${a+l}. `:`${ae.bullet} `,m=Zo(u),p=rl(c.tokens,Math.max(4,t-m),n);p.forEach((d,b)=>{Ss(d)&&b===p.length-1||o.push({spans:b===0?[{text:u,color:f.mutedForeground},...d.spans]:[{text:" ".repeat(m)},...d.spans]})})}),r();break}case"hr":o.push({spans:[{text:"\u2500".repeat(Math.max(1,t)),color:f.faintForeground}]}),r();break;case"table":o.push(...dT(i.header,i.rows,i.raw,t,n)),r();break;default:o.push(...Pt([{text:i.raw,color:f.foreground}],t))}return o}var il=(e,t)=>an(e,{},t).map(n=>n.text).join("");function hn(e,t,n="default"){let o=rT.lex(Vn(e),{gfm:!0,breaks:n!=="docs"}),r=rl(o,Math.max(8,t),n);for(;r.length>0&&Ss(r[r.length-1]);)r.pop();return r}import{Text as cn,useInput as pT}from"ink";import{useImperativeHandle as fT,useRef as yp,useEffect as gT,useState as Sp}from"react";import sl from"string-width";import{jsx as yn,jsxs as al}from"react/jsx-runtime";var hT=e=>e.replace(new RegExp("\\p{Cc}","gu"),"");function bp(e,t,n){let o=t,r=0;for(;o>0;){let s=sl(e[o-1]??"");if(r+s>n)break;r+=s,o-=1}let i=t;for(r+=1;i<e.length;){let s=sl(e[i]??"");if(r+s>n)break;r+=s,i+=1}return{start:o,before:e.slice(o,t).join(""),at:e[t]??" ",after:e.slice(t+1,i).join("")}}function Zr({char:e}){return yn(cn,{backgroundColor:f.cursorBackground,color:f.foreground,children:e})}function er({value:e,onChange:t,onSubmit:n,placeholder:o,mask:r=!1,isActive:i=!0,width:s=40,ref:a}){let c=[...e],[l,u]=Sp(c.length),m=Math.min(l,c.length),p=Math.max(8,s),d=yp(e),b=yp(m);d.current=e,b.current=m,ms(i);let h=y=>{b.current=y,u(y)},g=(y,R)=>{d.current=y,h(R),t(y)};if(fT(a,()=>({moveToColumn:y=>{let R=[...d.current],N=r?Array.from({length:R.length},()=>"\u2022"):R,W=bp(N,Math.min(b.current,R.length),p).start,M=0;for(;W<R.length;){let C=sl(N[W]??"");if(M+C>y)break;M+=C,W+=1}h(W)}})),pT((y,R)=>{let N=[...d.current],E=Math.min(b.current,N.length);if(R.return){n(d.current);return}if(R.tab||R.upArrow||R.downArrow)return;if(R.leftArrow){h(Math.max(0,E-1));return}if(R.rightArrow){h(Math.min(N.length,E+1));return}if(R.home){h(0);return}if(R.end){h(N.length);return}if(R.backspace){if(E===0)return;g([...N.slice(0,E-1),...N.slice(E)].join(""),E-1);return}if(R.delete){if(E>=N.length)return;g([...N.slice(0,E),...N.slice(E+1)].join(""),E);return}if(R.ctrl){if(y==="a")h(0);else if(y==="e")h(N.length);else if(y==="k")g(N.slice(0,E).join(""),E);else if(y==="u")g(N.slice(E).join(""),0);else if(y==="w"){let v=E;for(;v>0&&N[v-1]===" ";)v-=1;for(;v>0&&N[v-1]!==" ";)v-=1;g([...N.slice(0,v),...N.slice(E)].join(""),v)}return}if(R.meta||!y)return;let W=y.search(/[\r\n]/),M=hT(W===-1?y:y.slice(0,W)),C=[...N.slice(0,E),M,...N.slice(E)].join("");g(C,E+[...M].length),W!==-1&&n(C)},{isActive:i}),e===""){let y=[...o??""];return i?al(cn,{children:[yn(Zr,{char:y[0]??" "}),yn(cn,{color:f.faintForeground,children:y.slice(1).join("")})]}):yn(cn,{color:f.faintForeground,children:y.join("")})}let x=r?Array.from({length:c.length},()=>"\u2022"):c;if(!i)return yn(cn,{color:f.foreground,children:x.join("")});let{before:T,at:k,after:S}=bp(x,m,p);return al(cn,{children:[yn(cn,{color:f.foreground,children:T}),yn(Zr,{char:k}),yn(cn,{color:f.foreground,children:S})]})}function Oe({label:e}){let[t,n]=Sp(0);return gT(()=>{let o=setInterval(()=>n(r=>(r+1)%Qo.length),bs);return()=>clearInterval(o)},[]),al(cn,{children:[yn(cn,{color:f.accent,children:Qo[t]}),yn(cn,{color:f.mutedForeground,children:` ${e}`})]})}import{Box as wp,Text as tr}from"ink";import{useEffect as vp,useState as bT}from"react";import kp from"string-width";import{Box as xp,Text as xs}from"ink";import yT from"string-width";import{jsx as ei,jsxs as Tp}from"react/jsx-runtime";var ge=2,Bt=1,qe=1,Xe=Bt+qe;function Rn({title:e,note:t,width:n}){let o=t===void 0?0:yT(t)+2,r=Math.max(0,n-ge-o);return Tp(xs,{wrap:"truncate",children:[ei(xs,{color:f.accent,children:`${ae.section} `}),ei(xs,{bold:!0,color:f.foreground,children:He(e,r)}),t!==void 0&&ei(xs,{color:f.faintForeground,children:` ${t}`})]})}function pe({title:e,note:t,width:n,gap:o=qe,children:r}){return Tp(xp,{flexDirection:"column",children:[ei(Rn,{title:e,note:t,width:n}),ei(xp,{flexDirection:"column",marginTop:o,paddingLeft:ge,children:r})]})}import{jsx as _n,jsxs as Rp}from"react/jsx-runtime";var yo=e=>!("heading"in e),ST=e=>e.flatMap(t=>!yo(t)&&t.heading!==""?[t,{heading:""}]:[t]),Cp=2,Ts=2,xT=(e,t)=>t===void 0?e:e>t?Math.max(1,t-1):t;function TT(e,t,n,o){let[r,i]=Me(o,()=>e.findIndex(u=>yo(u)&&u.disabled!==!0));vp(()=>{i(u=>{let m=Math.min(u,e.length-1);for(let p=0;p<e.length;p+=1)for(let d of[m-p,m+p]){let b=e[d];if(b!==void 0&&yo(b)&&b.disabled!==!0)return d}return Math.max(0,m)})},[e.length]);let s=u=>{i(m=>{let p=e.length;if(p===0)return m;let d=m;for(let b=0;b<p;b+=1){d=(d+u+p)%p;let h=e[d];if(h!==void 0&&yo(h)&&h.disabled!==!0)return d}return m})},a=u=>{let m=e[u];return m!==void 0&&yo(m)&&m.disabled!==!0?m:null},c=u=>{a(u)!==null&&i(u)},l=u=>{let m=a(u);m!==null&&(i(u),n(m.value))};return G((u,m)=>{if(m.upArrow||u==="k"){s(-1);return}if(m.downArrow||u==="j"){s(1);return}m.return&&l(r)},t),{index:Math.max(0,r),step:s,pick:l,moveTo:c}}function cl(e,t){let[n,o]=bT(()=>e>=t?e-t+1:0);return vp(()=>{o(r=>e<r?e:e>=r+t?e-t+1:r)},[e,t]),n}function wT(e,t){let n=e.filter(yo),o=Math.max(0,...n.map(s=>kp(s.label))),r=Math.max(0,...n.map(s=>s.badge===void 0?0:kp(s.badge))),i=Cp+o+(r>0?r+Ts:0)+Ts;return{label:o,badge:r,hint:Math.max(0,t-i)}}function kT({item:e,active:t,metrics:n}){let o=e.disabled===!0,r=o?f.faintForeground:e.labelTone!==void 0?et[e.labelTone]:t?f.accent:f.foreground;return Rp(tr,{wrap:"truncate",children:[_n(tr,{color:f.accent,children:t?`${ae.cursor} `:" "}),_n(tr,{color:r,bold:t,children:Je(e.label,n.label)}),n.badge>0&&_n(tr,{color:e.badgeTone===void 0?f.faintForeground:et[e.badgeTone],children:`${" ".repeat(Ts)}${Je(e.badge??"",n.badge)}`}),e.hint!==void 0&&n.hint>0&&_n(tr,{color:o||!t?f.faintForeground:f.mutedForeground,children:`${" ".repeat(Ts)}${He(e.hint,n.hint)}`})]})}function vT({items:e,cursor:t,metrics:n,window:o,width:r,isActive:i,onPick:s,onHover:a,onScroll:c}){let l=cl(t,o),u=e.slice(l,l+o),m=d=>d<u.length?l+d:null,p=rt({isActive:i,onWheel:c,onClick:({row:d})=>{let b=m(d);b!==null&&s(b)},onHover:({row:d})=>{let b=m(d);b!==null&&a(b)}});return Rp(wp,{ref:p,flexDirection:"column",children:[u.map((d,b)=>{let h=l+b;return yo(d)?_n(kT,{item:d,active:h===t&&i,metrics:n},h):d.heading===""?_n(wp,{height:1},h):_n(Rn,{title:d.heading,width:r},h)}),e.length>o&&_n(tr,{color:f.faintForeground,children:`${" ".repeat(Cp)}${l+1}-${Math.min(l+o,e.length)} / ${e.length}`})]})}function le({items:e,onSelect:t,width:n,height:o,isActive:r=!0,retain:i}){let s=ST(e),a=TT(s,r,t,i);return _n(vT,{items:s,cursor:a.index,metrics:wT(s,n),window:xT(s.length,o),width:n,isActive:r,onPick:a.pick,onHover:a.moveTo,onScroll:a.step})}import{jsx as Xt,jsxs as ws}from"react/jsx-runtime";var _p={ok:{glyph:ae.ok,color:f.success},warn:{glyph:ae.warn,color:f.warning},fail:{glyph:ae.fail,color:f.danger},info:{glyph:ae.bullet,color:f.mutedForeground}},ll=2,ml=(e,t)=>Pt([{text:Vn(e)}],t-ll).map(n=>n.spans.map(o=>o.text).join("")),ul=(e,t,n)=>ml(e,n).length+(t===void 0?0:ml(t,n).length);function ye({tone:e,title:t,detail:n,width:o,wrap:r=!1}){let i=_p[e],s=c=>r?ml(c,o):[He(c,o-ll)],a=" ".repeat(ll);return ws(ti,{flexDirection:"column",children:[s(t).map((c,l)=>ws(nr,{children:[Xt(nr,{color:i.color,children:l===0?`${i.glyph} `:a}),Xt(nr,{color:f.foreground,children:c})]},l)),n!==void 0&&s(n).map((c,l)=>Xt(nr,{color:f.faintForeground,children:`${a}${c}`},`detail-${l}`))]})}function Ft({message:e,hint:t,width:n}){return Xt(ye,{tone:"fail",title:e,detail:t,width:n})}var CT=2,RT=2;function Pp({tone:e,message:t,width:n,onDismiss:o}){let r=_p[e],i=rt({onClick:o});return ws(ti,{ref:i,children:[Xt(nr,{backgroundColor:f.border,color:r.color,wrap:"truncate",children:` ${r.glyph} `}),Xt(nr,{backgroundColor:f.border,color:f.foreground,wrap:"truncate",children:`${He(t,n-CT-RT)} `})]})}function Ae({title:e,detail:t,confirmLabel:n,onConfirm:o,onCancel:r,width:i,busy:s,error:a}){return ws(ti,{flexDirection:"column",children:[Xt(ye,{tone:"warn",title:e,detail:t,width:i}),a!=null&&Xt(ti,{marginTop:1,children:Xt(Ft,{message:a.message,hint:a.hint,width:i})}),Xt(ti,{marginTop:1,children:typeof s=="string"?Xt(Oe,{label:s}):Xt(le,{items:[{value:"cancel",label:"\u53D6\u6D88"},{value:"confirm",label:n,labelTone:"danger"}],width:i,onSelect:c=>c==="confirm"?o():r()})})]})}import{Box as _T,Text as ks,useInput as PT}from"ink";import{useRef as AT}from"react";import{jsx as vs,jsxs as ET}from"react/jsx-runtime";function pt({lines:e,height:t,isActive:n=!0,pinBottom:o=!1,pageKeysOnly:r=!1,start:i=0,retain:s}){let a=e.length>t,c=a?Math.max(1,t-1):t,l=Math.max(0,e.length-c),[u,m]=Me(s,()=>o?l:Math.min(i,l)),p=AT(l);if(l!==p.current||u>l){let g=u>=p.current;p.current=l;let x=o&&g?l:Math.min(u,l);x!==u&&m(x)}let d=g=>m(x=>Math.min(Math.max(0,x+g),l));PT((g,x)=>{x.pageUp?d(-c):x.pageDown?d(c):!r&&x.upArrow?d(-1):!r&&x.downArrow&&d(1)},{isActive:n&&a}),G(g=>{g==="k"?d(-1):g==="j"&&d(1)},n&&a&&!r);let b=rt({isActive:n&&a,onWheel:d}),h=e.slice(u,u+c);return ET(_T,{ref:b,flexDirection:"column",children:[h.map((g,x)=>vs(ks,{wrap:"truncate",children:g.spans.length===0?" ":g.spans.map((T,k)=>vs(ks,{color:T.color??f.foreground,bold:T.bold===!0,children:T.text},k))},u+x)),Array.from({length:Math.max(0,c-h.length)},(g,x)=>vs(ks,{children:" "},x)),a&&vs(ks,{color:f.faintForeground,wrap:"truncate",children:`${u+1}-${Math.min(u+c,e.length)} / ${e.length}`})]})}function ht(e){return e.tone==="neutral"?void 0:e.tone}function yt(e){let t=ht(e);return t===void 0?e.label:{text:e.label,tone:t}}import{useCallback as dl,useRef as MT,useState as Ap}from"react";function ue(){let e=O(),[t,n]=Ap(null),[o,r]=Ap(null),i=MT(0),s=dl(()=>{i.current+=1,n(null),r(null)},[]),a=dl((l,u)=>{r({message:l,hint:u})},[]),c=dl((l,u,m={})=>{let p=i.current+=1;n(l),r(null),u().then(d=>{i.current===p&&(n(null),m.onSuccess?.(d))}).catch(d=>{if(i.current!==p)return;n(null);let b={message:xe(d),hint:d instanceof U?d.hint:void 0};m.failToast===!0?e.toast("fail",b.message):r(b)})},[e]);return{busy:t,error:o,reset:s,fail:a,run:c}}import{Box as ir}from"ink";import{Box as IT,Text as Ep}from"ink";import Ip from"string-width";import{jsx as Mp,jsxs as NT}from"react/jsx-runtime";var Cs=["\u2588\u2580\u2580 \u2588\u2580\u2588 \u2588\u2580\u2584 \u2588\u2580\u2580 \u2588\u2580\u2580 \u2588 \u2588\u2580\u2588 \u2588 \u2588 \u2588","\u2588\u2584\u2584 \u2588\u2584\u2588 \u2588\u2584\u2580 \u2588\u2584\u2584 \u2588\u2580\u2580 \u2588\u2584\u2584 \u2588\u2584\u2588 \u2580\u2584\u2580\u2584\u2580"],Np=Math.max(...Cs.map(e=>Ip(e))),Rs=Cs.length,_s=e=>Np<=e;function Ps({width:e}){let t=`v${Vt}`,n=Np+2+Ip(t)<=e;return Mp(IT,{flexDirection:"column",children:Cs.map((o,r)=>NT(Ep,{color:f.accent,children:[o,r===Cs.length-1&&n&&Mp(Ep,{color:f.faintForeground,children:` ${t}`})]},o))})}import{Box as gl,Text as wt}from"ink";import{useState as Lp}from"react";import bo from"string-width";import{jsx as Qt,jsxs as rr}from"react/jsx-runtime";var As=2,pl=` ${ae.crumb} `;function Es({trail:e,width:t,onBack:n,isActive:o}){let r=e[e.length-1]??"",i=e.slice(0,-1),s=i.reduce((p,d)=>p+bo(d)+bo(pl),0),a=s+bo(r)<=t,c=a?s:0,[l,u]=Lp(!1),m=rt({isActive:o,onClick:({column:p})=>{p<c&&n()},onHover:({column:p})=>u(p<c),onHoverLeave:()=>u(!1)});return Qt(gl,{ref:m,marginBottom:1,children:a?rr(wt,{children:[i.map((p,d)=>rr(wt,{children:[Qt(wt,{color:d===0?f.accent:l&&o?f.foreground:f.mutedForeground,children:p}),Qt(wt,{color:f.faintForeground,children:pl})]},d)),Qt(wt,{bold:!0,color:f.foreground,children:r})]}):Qt(wt,{color:f.mutedForeground,children:He(e.join(pl),t)})})}var fl=2,ni=2,or=2;function Op({current:e,width:t,onPick:n,isActive:o,unread:r}){let i=Math.max(0,Jr(e)),[s,a]=Lp(null),c=y=>r[y.id]===!0,l=y=>c(y)?`${y.label} ${ae.dot}`:y.label,u=Math.max(...Tt.map(y=>bo(y.label))),m=Tt.some(c)?bo(` ${ae.dot}`):0,d=(y=>y*u+(y-1)*ni+fl+m)(Tt.length)>t,b=d?t-or*2:t,h=d?Math.max(1,Math.floor((b-m+ni-fl)/(u+ni))):Tt.length,g=Math.min(Math.max(0,i-Math.floor((h-1)/2)),Tt.length-h),x=Tt.slice(g,g+h),T=[],k=d?or:0;x.forEach((y,R)=>{R>0&&(k+=ni);let N=bo(l(y))+(y.id===e?fl:0);T.push({id:y.id,from:k,to:k+N}),k+=N});let S=rt({isActive:o,onHover:({column:y})=>{let R=T.find(N=>y>=N.from&&y<N.to);a(R?.id??null)},onHoverLeave:()=>a(null),onClick:({column:y})=>{let R=T.find(E=>y>=E.from&&y<E.to);if(R!==void 0){n(R.id);return}if(!d||y>=or&&y<k)return;let N=y<or?Tt[g-1]:Tt[g+h];N!==void 0&&n(N.id)}});return Qt(gl,{ref:S,marginBottom:1,children:rr(wt,{wrap:"truncate",children:[d&&Qt(wt,{color:f.border,children:g>0?`${ae.prev} `:" ".repeat(or)}),x.map((y,R)=>{let N=c(y)&&Qt(wt,{color:f.danger,children:` ${ae.dot}`});return rr(wt,{children:[R>0&&" ".repeat(ni),y.id===e?rr(wt,{backgroundColor:f.foreground,color:f.background,bold:!0,children:[` ${y.label}`,N," "]}):rr(wt,{children:[Qt(wt,{color:o&&y.id===s?f.foreground:f.mutedForeground,children:y.label}),N]})]},y.id)}),d&&Qt(wt,{color:f.border,children:g+h<Tt.length?` ${ae.next}`:" ".repeat(or)})]})})}var LT=2;function Dp(e,t){let n=[];for(let o of e){let r=n[n.length-1];if(r!==void 0&&bo(_e([...r,o]))<=t)r.push(o);else if(n.length<LT)n.push([o]);else break}return n.map(_e)}function $p({lines:e}){return Qt(gl,{flexDirection:"column",flexShrink:0,children:e.map((t,n)=>Qt(wt,{wrap:"truncate",color:f.faintForeground,children:t},n))})}import{createContext as OT,useCallback as DT,useContext as $T,useEffect as Hp,useMemo as BT,useRef as qp,useState as FT}from"react";var Bp=e=>A(mt(od),Fe("/inbox",{...e})),Fp=()=>A(rd,"/inbox/unread"),Up=e=>A(se,`/inbox/${e}/read`,{method:"POST"}),jp=()=>A(se,"/inbox/read-all",{method:"POST"});import{jsx as jT}from"react/jsx-runtime";var UT=6e4,Gp=OT(null);function zp({children:e}){let{revision:t,toast:n}=O(),[o,r]=FT(!1),i=qp(0),s=qp(!1),a=DT(()=>{let l=i.current+=1;if(Lt().session===null){r(!1);return}Fp().then(u=>{s.current=!1,i.current===l&&r(u.unread)},u=>{i.current!==l||s.current||(s.current=!0,n("warn",`\u7AD9\u5185\u6D88\u606F\u672A\u8BFB\u72B6\u6001\u83B7\u53D6\u5931\u8D25\uFF1A${xe(u)}`))})},[n]);Hp(a,[t,a]),Hp(()=>{let l=setInterval(a,UT);return()=>clearInterval(l)},[a]);let c=BT(()=>({any:o,refresh:a}),[o,a]);return jT(Gp.Provider,{value:c,children:e})}function Ms(){let e=$T(Gp);if(!e)throw new Error("useUnread \u5FC5\u987B\u5728 UnreadProvider \u5185\u4F7F\u7528");return e}import{Fragment as qT,jsx as kt,jsxs as Kp}from"react/jsx-runtime";var Wp=3,HT=8;function oi(e){let{rows:t}=j();return Math.max(1,t-Yc-Wp-e)}function Vp(){let e=O(),{width:t,rows:n}=j(),o=e.current.id,r=e.depth===1&&fs(o)?o:null,i=Math.max(1,n-Yc-Wp),s=Rs+X,a=r!==null&&_s(t)&&i-As-s>=HT;return{tab:r,mark:a,rows:a?As+s:As}}var Z=()=>oi(Vp().rows);function So({header:e,hints:t,children:n}){let{width:o}=j(),{message:r,dismissToast:i}=O(),s=Dp(t,o);return Kp(ir,{flexDirection:"column",flexGrow:1,children:[kt(ir,{flexDirection:"column",flexShrink:0,children:e}),kt(ir,{flexDirection:"column",flexGrow:1,overflow:"hidden",children:kt(ir,{flexDirection:"column",flexShrink:0,children:n})}),kt(ir,{height:1,marginTop:s.length>1?0:1,flexShrink:0,justifyContent:"flex-end",children:r!==null&&kt(Pp,{tone:r.tone,message:r.message,width:o,onDismiss:i})}),kt($p,{lines:s})]})}function Y({trail:e,hints:t=[],children:n,onEscape:o,isActive:r=!0,locked:i=!1,bleed:s=!1}){let a=O(),{width:c}=j(),{tab:l,mark:u}=Vp(),m=Ms(),p=us(),d=ds(),b=Zd(),h=r&&!b,g=h?t:t.filter(y=>y!=="Esc \u8FD4\u56DE"),x=d||p?[]:[...r?["[] \u5207\u529F\u80FD"]:[],"q \u9000\u51FA","? \u5E2E\u52A9"],T=[...h?["Esc \u8FD4\u56DE"]:[],...d||p?[]:["? \u5E2E\u52A9"]];gn(o??a.pop,{isActive:r});let k=ep(),S=r&&!i&&!p;return G(y=>{if(l===null||y!=="["&&y!=="]")return;let R=Tt[(Jr(l)+(y==="["?-1:1)+Tt.length)%Tt.length];R!==void 0&&a.select(R.id)},r&&!i&&!p&&!s),s?kt(So,{header:null,hints:i?g:[...g,...T],children:n}):l!==null?kt(So,{header:Kp(qT,{children:[u&&kt(ir,{marginBottom:X,children:kt(Ps,{width:c})}),kt(Op,{current:l,width:c,onPick:y=>{y===l?k():a.select(y)},isActive:S,unread:{inbox:m.any}})]}),hints:i?g:[...g,...x],children:n}):kt(So,{header:kt(Es,{trail:["CodeFlow",...e??[]],width:c,onBack:k,isActive:S}),hints:i?g:[...g,...T],children:n})}function V({state:e,loading:t,width:n,children:o}){return e.phase==="loading"?kt(Oe,{label:t}):e.phase==="error"?kt(Ft,{message:e.message,hint:e.hint,width:n}):o(e.data)}import{jsx as Zt,jsxs as hl}from"react/jsx-runtime";function Yp({params:e}){let t=O(),{width:n}=j(),o=Z(),{item:r}=e,{busy:i,error:s,run:a}=ue();GT((m,p)=>{p.return&&a("\u6B63\u5728\u786E\u8BA4",()=>is(r.id),{onSuccess:()=>t.pop()})},{isActive:i===null});let c=Gr(r.level),l=ht(c),u=Math.max(3,o-4-(s===null?0:2));return Zt(Y,{trail:["\u7CFB\u7EDF\u516C\u544A","\u672A\u8BFB\u786E\u8BA4"],hints:["\u2191\u2193 \u6EDA\u52A8","Enter \u6211\u77E5\u9053\u4E86"],locked:!0,onEscape:()=>{},children:hl(Is,{flexDirection:"column",children:[hl(xo,{wrap:"truncate",children:[Zt(xo,{bold:!0,color:f.foreground,children:r.title}),Zt(xo,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),Zt(xo,{color:f.faintForeground,children:` \u53D1\u5E03\u4E8E ${K(r.publishedAt)}`})]}),Zt(Is,{marginTop:1,children:Zt(pt,{lines:hn(r.content,n),height:u})}),s!==null&&Zt(Is,{marginTop:1,children:Zt(Ft,{message:s.message,hint:s.hint,width:n})}),Zt(Is,{marginTop:1,children:i!==null?Zt(Oe,{label:i}):hl(xo,{wrap:"truncate",children:[Zt(xo,{color:f.accent,children:`${ae.cursor} `}),Zt(xo,{bold:!0,color:f.accent,children:"\u6211\u77E5\u9053\u4E86"})]})})]})})}import{Box as wl,Text as Ns}from"ink";import{useState as tw}from"react";import{Box as yl,Text as Pn}from"ink";import{useEffect as bl,useRef as zT,useState as Jp}from"react";import Sl from"string-width";import{jsx as Yn,jsxs as ii}from"react/jsx-runtime";var Xp=e=>e===void 0?"":typeof e=="string"?e:e.text,xl=2,WT=6;function VT(e,t,n){let o=e.map(a=>t===0?n/e.length:n*a/t),r=o.map(a=>Math.floor(a)),i=n-r.reduce((a,c)=>a+c,0),s=o.map((a,c)=>({i:c,fraction:a-Math.floor(a)})).sort((a,c)=>c.fraction-a.fraction);for(let{i:a}of s){if(i<=0)break;r[a]=(r[a]??0)+1,i-=1}return e.map((a,c)=>a+(r[c]??0))}function Tl(e,t,n){let o=e.map((c,l)=>Math.max(Sl(c.label),...t.map(u=>Sl(u[l]??"")))),r=o.reduce((c,l)=>c+l,0),i=r+xl*Math.max(0,e.length-1)-n;if(i<0)return VT(o,r,-i);e.forEach((c,l)=>{if(c.cap===void 0||i<=0)return;let u=Math.min(i,Math.max(0,(o[l]??0)-c.cap));o[l]=(o[l]??0)-u,i-=u});let s=e.flatMap((c,l)=>c.shrink===!0||c.cap!==void 0?[l]:[]),a=s.length>0?s:e.map((c,l)=>l);for(;i>0;){let c=a.filter(l=>(o[l]??0)>WT).sort((l,u)=>(o[u]??0)-(o[l]??0))[0];if(c===void 0)break;o[c]=(o[c]??0)-1,i-=1}return o}var KT=(e,t,n)=>t.map((o,r)=>o.align==="right"?Kn(e[r]??"",n[r]??0):Je(e[r]??"",n[r]??0)).join(" ".repeat(xl)),ri=2,YT=2;function de({items:e,columns:t,row:n,width:o,height:r,onOpen:i,searchOf:s,isActive:a=!0,emptyLabel:c="\u6682\u65E0\u6570\u636E",emptyDescription:l,retain:u,select:m}){let p=$=>u===void 0?void 0:`${u}:${$}`,d=i!==void 0,[b,h]=Me(d?p("cursor"):void 0,()=>0),[g,x]=Me(p("query"),()=>""),[T,k]=Jp(!1),S=g.trim().toLowerCase(),y=S===""||s===void 0?e:e.filter($=>s($).toLowerCase().includes(S)),R=T||S!=="",N=Math.max(1,r-1-(R?1:0)),E=y.length>N?Math.max(1,N-1):N,W=Math.max(0,y.length-E),[M,C]=Jp(()=>b>=E?b-E+1:0);bl(()=>{h($=>Math.min($,Math.max(0,y.length-1)))},[y.length]);let v=m===void 0?-1:y.findIndex(m);bl(()=>{v>=0&&h(v)},[v]),bl(()=>{C($=>d?b<$?b:b>=$+E?b-E+1:$:Math.min($,W))},[b,E,W,d]);let _=$=>{if(!d){C(ne=>Math.min(Math.max(0,ne+$),W));return}y.length!==0&&h(ne=>(ne+$+y.length)%y.length)};G(($,ne)=>{if(ne.upArrow||$==="k"){_(-1);return}if(ne.downArrow||$==="j"){_(1);return}if(ne.return){let w=y[b];w!==void 0&&i?.(w,b);return}s!==void 0&&$.startsWith("/")&&(k(!0),$.length>1&&x($.slice(1)))},a&&!T),gn(()=>{k(!1),x("")},{isActive:T||S!=="",layer:T?Wn.input:Wn.panel});let L=R?1:0,P=zT(null),B=$=>{if($<=L)return null;let ne=M+$-L-1;return y[ne]===void 0?null:ne},J=rt({isActive:a,onWheel:_,onClick:({row:$,column:ne})=>{if(R&&$===0){k(!0),P.current?.moveToColumn(ne-YT);return}if(i===void 0)return;let w=B($);if(w===null)return;let F=y[w];F!==void 0&&(h(w),i(F,w))},onHover:d?({row:$})=>{let ne=B($);ne!==null&&h(ne)}:void 0}),oe=Tl(t,y.map($=>n($).map(Xp)),o-ri),fe=y.slice(M,M+E);return ii(yl,{ref:J,flexDirection:"column",children:[R&&ii(yl,{children:[Yn(Pn,{color:f.accent,children:"/ "}),Yn(er,{ref:P,value:g,onChange:x,onSubmit:()=>k(!1),isActive:T,placeholder:"\u8F93\u5165\u5173\u952E\u8BCD\u8FC7\u6EE4",width:o-2-Sl(` ${y.length}/${e.length}`)}),Yn(Pn,{color:f.faintForeground,children:` ${y.length}/${e.length}`})]}),ii(Pn,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(ri),KT(t.map($=>$.label),t,oe)]}),y.length===0?ii(yl,{flexDirection:"column",children:[Yn(Pn,{wrap:"truncate",color:f.mutedForeground,children:`${" ".repeat(ri)}${S===""?c:"\u65E0\u5339\u914D\u7ED3\u679C"}`}),l!==void 0&&S===""&&N>1&&Yn(Pn,{wrap:"truncate",color:f.faintForeground,children:`${" ".repeat(ri)}${l}`})]}):fe.map(($,ne)=>{let w=M+ne,F=d&&w===b&&a,re=F?f.accent:a?f.foreground:f.mutedForeground,D=n($);return ii(Pn,{wrap:"truncate",children:[Yn(Pn,{color:f.accent,children:F?`${ae.cursor} `:" "}),t.map((z,ee)=>{let he=D[ee],ie=Xp(he),Qe=z.align==="right"?Kn(ie,oe[ee]??0):Je(ie,oe[ee]??0),xt=typeof he=="object"?he.tone:void 0,Ze=!F&&a&&xt!==void 0?et[xt]:re;return Yn(Pn,{color:Ze,bold:F,children:ee>0?`${" ".repeat(xl)}${Qe}`:Qe},z.label)})]},w)}),(M>0||M+E<y.length)&&Yn(Pn,{color:f.faintForeground,children:`${" ".repeat(ri)}${M+1}-${Math.min(M+E,y.length)} / ${y.length}`})]})}import{Text as JT}from"ink";import{useEffect as XT,useRef as QT,useState as ZT}from"react";import{jsx as ew}from"react/jsx-runtime";function ze(e,t,{retain:n}={}){let[o,r]=Me(n,()=>1),[i,s]=ZT({pages:1,total:0}),a=QT(!1),c=Q([...e,o],()=>t(o));XT(()=>{if(c.phase!=="ready")return;let p=Math.max(1,Math.ceil(c.data.total/ou));if(s({pages:p,total:c.data.total}),o>p){r(p);return}a.current&&(a.current=!1,o<p&&r(p))},[c]);let l=p=>{r(d=>Math.min(Math.max(1,d+p),i.pages))},u=()=>r(1),m=()=>{a.current=!0};return{state:c,page:o,pages:i.pages,total:i.total,go:l,reset:u,last:m}}function We({page:e,pages:t,total:n,width:o}){return ew(JT,{wrap:"truncate",color:f.faintForeground,children:He(_e([`\u7B2C ${e} / ${t} \u9875`,`\u5171 ${n} \u6761`,"\u2190\u2192 \u7FFB\u9875"]),o)})}import{jsx as An,jsxs as kl}from"react/jsx-runtime";function Qp(){let e=O(),{width:t}=j(),n=Z(),[o,r]=tw({name:"list"}),i=ze([e.revision],a=>qd({page:a}),{retain:"page"});G((a,c)=>{o.name==="list"&&(a==="r"?e.reload():c.leftArrow?i.go(-1):c.rightArrow&&i.go(1))});let s=()=>{o.name==="list"?e.pop():r({name:"list"})};return An(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","Esc \u8FD4\u56DE"],onEscape:s,children:An(V,{state:i.state,loading:"\u6B63\u5728\u8BFB\u53D6\u516C\u544A",width:t,children:a=>{if(o.name==="detail"){let c=Gr(o.item.level),l=ht(c);return kl(wl,{flexDirection:"column",children:[kl(Ns,{wrap:"truncate",children:[An(Ns,{bold:!0,color:f.foreground,children:o.item.title}),An(Ns,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),An(Ns,{color:f.faintForeground,children:` ${_e([`\u53D1\u5E03\u4E8E ${K(o.item.publishedAt)}`])}`})]}),An(wl,{marginTop:1,children:An(pt,{lines:hn(o.item.content,t),height:Math.max(3,n-2)})})]})}return kl(wl,{flexDirection:"column",children:[An(de,{retain:"list",items:a.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u7EA7\u522B"},{label:"\u53D1\u5E03\u4E8E",align:"right"}],row:c=>[c.title,yt(Gr(c.level)),K(c.publishedAt)],onOpen:c=>{r({name:"detail",item:c}),is(c.id).catch(()=>e.toast("warn","\u5DF2\u8BFB\u786E\u8BA4\u53D1\u9001\u5931\u8D25"))},emptyLabel:"\u6682\u65E0\u516C\u544A",emptyDescription:"\u5E73\u53F0\u6709\u65B0\u901A\u77E5\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),An(We,{page:i.page,pages:i.pages,total:i.total,width:t})]})}})})}import{Box as at,Text as fi}from"ink";import{useState as xg}from"react";import tk from"string-width";import{z as nw}from"zod";var Ls=e=>`/community/${e.kind==="user"?"users":"staff"}/${encodeURIComponent(e.username)}`,Os=()=>A(nw.array(kc),"/community/categories"),sr=()=>A(Qu,"/community/me"),Zp=e=>A(mt(vc),Fe("/community/posts",{...e})),Ds=e=>A(Cc,`/community/posts/${e}`),ef=e=>A(se,`/community/posts/${e}/view`,{method:"POST"}),tf=(e,t)=>A(mt(Ui),Fe(`/community/posts/${e}/floors`,{page:t})),nf=(e,t)=>A(Ui,`/community/posts/${e}/floors/${t}`),of=(e,t)=>A(mt(Rc),Fe(`/community/comments/${e}/replies`,{page:t})),vl=e=>A(ed,Ls({kind:"user",username:e})),rf=e=>e.kind==="user"?vl(e.username):A(td,Ls(e)),sf=(e,t)=>A(mt(Br),Fe(`${Ls(e)}/posts`,{page:t})),af=(e,t)=>A(mt(ji),Fe(`${Ls(e)}/comments`,{page:t})),cf=e=>A(mt(vc),Fe("/community/mine/bookmarks",{page:e})),lf=e=>A(mt(Ac),Fe("/community/mine/drafts",{page:e})),mf=()=>A(Ju,"/community/mine/todo"),uf=e=>A(Ku,"/community/posts",{method:"POST",json:e}),df=(e,t)=>A(se,`/community/posts/${e}`,{method:"PATCH",json:t}),$s=e=>A(se,`/community/posts/${e}`,{method:"DELETE"}),pf=e=>A(Xu,"/community/drafts",{method:"POST",json:e}),ff=(e,t)=>A(se,`/community/drafts/${e}`,{method:"PATCH",json:t}),gf=(e,t)=>A(se,`/community/drafts/${e}/publish`,{method:"POST",json:t}),hf=(e,t)=>A(Yu,`/community/posts/${e}/comments`,{method:"POST",json:t}),yf=e=>A(se,`/community/comments/${e}`,{method:"DELETE"}),bf=(e,t)=>A(_c,`/community/posts/${e}/like`,{method:t?"PUT":"DELETE"}),Sf=(e,t)=>A(_c,`/community/comments/${e}/like`,{method:t?"PUT":"DELETE"}),xf=(e,t)=>A(se,`/community/posts/${e}/bookmark`,{method:t?"PUT":"DELETE"}),Tf=(e,t)=>A(se,`/community/posts/${e}/reports`,{method:"POST",json:t}),wf=(e,t)=>A(se,`/community/comments/${e}/reports`,{method:"POST",json:t});var En=()=>A(cu,"/auth/me"),kf=e=>A(se,"/auth/me",{method:"PATCH",json:e}),vf=e=>A(se,"/auth/me/password",{method:"POST",json:e}),Cf=e=>A(se,"/auth/me/email/code",{method:"POST",json:e}),Rf=e=>A(se,"/auth/me/email",{method:"POST",json:e}),_f=()=>A(lu,"/auth/me/sessions"),Pf=e=>A(se,`/auth/me/sessions/${e}`,{method:"DELETE"});async function Af(){await A(se,"/auth/me/sessions",{method:"DELETE"}),ts()}var Ef=()=>A(uu,"/auth/me/security"),Cl=e=>A(mu,"/auth/me/totp/setup",{method:"POST",json:e}),Mf=e=>A(lc,"/auth/me/totp/confirm",{method:"POST",json:e}),If=e=>A(se,"/auth/me/totp/disable",{method:"POST",json:e}),Nf=e=>A(lc,"/auth/me/totp/recovery-codes",{method:"POST",json:e}),Lf=(e,t)=>A(se,`/auth/me/passkeys/${e}`,{method:"PATCH",json:t}),Of=e=>A(se,`/auth/me/passkeys/${e}`,{method:"DELETE"});var Rl=12e4,ow=e=>A(Hu,Fe("/media",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Rl}),rw=e=>A(se,`/media/${e}`,{method:"DELETE"}),si={upload:async e=>({...await ow(e),fileName:e.fileName}),discard:rw};async function Df(e){let{bytes:t,headers:n}=await Kc(`/media/${e}`,{timeoutMs:Rl}),o=n.get("content-disposition")?.split("filename*=UTF-8''")[1];if(o===void 0)throw new U("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u9644\u4EF6\u6587\u4EF6\u540D");return{fileName:decodeURIComponent(o),bytes:t}}var $f=()=>A(Pc,"/auth/me/avatar"),Bf=e=>A(Pc,"/auth/me/avatar",{method:"PUT",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Rl}),Ff=()=>A(se,"/auth/me/avatar",{method:"DELETE"});import{existsSync as Bs,readFileSync as iw,statSync as Uf,writeFileSync as sw}from"fs";import{homedir as _l}from"os";import en from"path";var aw={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif"},jf=e=>e.startsWith("~/")?en.join(_l(),e.slice(2)):e;function cw(e){return e.split(`
10
+ `).map(t=>t.trim()).filter(t=>t!=="").map(jf)}function Hf(e,t,n){if(!Bs(e))throw new U(`${e} \u4E0D\u5B58\u5728`);let o=Uf(e);if(!o.isFile())throw new U(`${e} \u4E0D\u662F\u6587\u4EF6`);if(o.size===0)throw new U(`${e} \u662F\u7A7A\u6587\u4EF6\uFF0C\u65E0\u6CD5\u4E0A\u4F20`);if(o.size>t)throw new U(`${e} \u8D85\u8FC7\u5355\u4E2A${n}\u5927\u5C0F\u4E0A\u9650 ${Ko(t)}`);let r=en.basename(e);return{filePath:e,fileName:r,contentType:aw[en.extname(r).toLowerCase()]??"application/octet-stream"}}function qf(e){let t;try{t=iw(e.filePath)}catch(n){throw new U(`${e.filePath} \u8BFB\u53D6\u5931\u8D25\uFF1A${xe(n)}`,{cause:n})}return{fileName:e.fileName,contentType:e.contentType,bytes:t}}function Jn(e,t){let n=cw(e);if(n.length>t.maxCount)throw new U("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return n.map(o=>Hf(o,t.maxBytes,"\u9644\u4EF6"))}function Gf(e,t){let n=Hf(jf(e),t,"\u56FE\u7247");if(!n.contentType.startsWith("image/"))throw new U("\u4EC5\u652F\u6301 PNG\u3001JPG\u3001WebP\u3001GIF\u3001AVIF \u683C\u5F0F\u7684\u56FE\u7247");return qf(n)}async function Mn(e,t,n){let o=[];try{for(let r of e)o.push(await t.upload(qf(r)));return await n(o)}catch(r){let s=(await Promise.allSettled(o.map(l=>t.discard(l.id)))).filter(l=>l.status==="rejected").length;if(s===0)throw r;let a=`${s} \u4E2A\u5DF2\u4E0A\u4F20\u7684\u9644\u4EF6\u672A\u80FD\u6E05\u7406\uFF0C\u5C06\u5728 24 \u5C0F\u65F6\u540E\u81EA\u52A8\u5220\u9664`,c=r instanceof U?r:null;throw new U(xe(r),{hint:c?.hint===void 0?a:`${c.hint}\uFF1B${a}`,...c===null?{}:{exitCode:c.exitCode},cause:r})}}function lw(e,t){let n=en.basename(t),o=en.extname(n),r=n.slice(0,n.length-o.length),i=en.join(e,n);for(let s=1;Bs(i);s+=1)i=en.join(e,`${r}-${s}${o}`);return i}function mw(e,t){let n=e.trim();if(n==="")return{dir:process.cwd(),fileName:t};if(n==="~")return{dir:_l(),fileName:t};let o=n.startsWith("~/")||n.startsWith(`~${en.sep}`)?en.join(_l(),n.slice(2)):n;return n.endsWith("/")||n.endsWith(en.sep)||Bs(o)&&Uf(o).isDirectory()?{dir:o,fileName:t}:{dir:en.dirname(o),fileName:en.basename(o)}}function zf(e,t,n){let o=mw(e,t);if(!Bs(o.dir))throw new U(`${o.dir} \u76EE\u5F55\u4E0D\u5B58\u5728`);let r=lw(o.dir,o.fileName);try{sw(r,n)}catch(i){throw new U(`\u5199\u5165 ${r} \u5931\u8D25\uFF1A${xe(i)}`,{cause:i})}return r}import{Box as tn,measureElement as Zf,Text as Be,useInput as ig}from"ink";import{useEffect as eg,useRef as tg,useState as ar}from"react";import Ml from"string-width";import{Box as uw,Text as Xn,useInput as dw}from"ink";import{useRef as Wf,useState as Vf}from"react";import Al from"string-width";import{jsx as In,jsxs as Xf}from"react/jsx-runtime";var pw=e=>e.replace(/\r\n?/g,`
11
+ `).replace(new RegExp("(?!\\n)\\p{Cc}","gu"),"");function Kf(e,t){let n=[],o=0,r=0;for(let i=0;i<e.length;i+=1){let s=e[i]??"";if(s===`
12
+ `){n.push({start:o,end:i,nl:!0}),o=i+1,r=0;continue}let a=Al(s);r+a>t&&i>o&&(n.push({start:o,end:i,nl:!1}),o=i,r=0),r+=a}return n.push({start:o,end:e.length,nl:!1}),n}function Yf(e,t){for(let n=0;n<e.length;n+=1){let o=e[n];if(o!==void 0&&(o.nl?t<=o.end:t<o.end))return n}return e.length-1}function Jf(e,t,n){let o=0;for(let r=t.start;r<t.end;r+=1){let i=Al(e[r]??"");if(o+i>n)return r;o+=i}return t.end}var fw=(e,t,n)=>e.slice(t.start,n).reduce((o,r)=>o+Al(r),0);function Pl(e,t){let n=t;for(;n>0&&e[n-1]!==`
13
13
  `;)n-=1;let o=t;for(;o<e.length&&e[o]!==`
14
- `;)o+=1;return{start:n,end:o}}function Kf({value:e,onChange:t,isActive:n,width:o,rows:r,placeholder:i,maxLength:s,onEdge:a,onFocusRequest:c}){let l=[...e],[u,m]=qf(l.length),f=Math.min(u,l.length),[d,h]=qf(0),y=Hf(e),g=Hf(f);y.current=e,g.current=f,us(n);let x=Math.max(4,o),T=C=>{g.current=C,m(C)},R=(C,w)=>{y.current=C,T(w),t(C)},b=C=>{let w=[...y.current],E=Math.min(g.current,w.length),_=Gf(w,x),A=Wf(_,E),$=_[A],Z=_[A+C];return $===void 0||Z===void 0?!1:(T(zf(w,Z,mw(w,$,E))),!0)},S=(C,w,E)=>{let _=lw(E);if(s!==void 0){let A=s-C.length;if(A<=0)return;_=[..._].slice(0,A).join("")}_!==""&&R([...C.slice(0,w),_,...C.slice(w)].join(""),w+[..._].length)};cw((C,w)=>{let E=[...y.current],_=Math.min(g.current,E.length);if(w.return){S(E,_,`
15
- `);return}if(!w.tab){if(w.upArrow||w.downArrow){let A=w.upArrow?-1:1;b(A)||a?.(w.upArrow?"up":"down");return}if(w.leftArrow){T(Math.max(0,_-1));return}if(w.rightArrow){T(Math.min(E.length,_+1));return}if(w.home){T(Pl(E,_).start);return}if(w.end){T(Pl(E,_).end);return}if(w.backspace){if(_===0)return;R([...E.slice(0,_-1),...E.slice(_)].join(""),_-1);return}if(w.delete){if(_>=E.length)return;R([...E.slice(0,_),...E.slice(_+1)].join(""),_);return}if(w.ctrl){let A=Pl(E,_);if(C==="a")T(A.start);else if(C==="e")T(A.end);else if(C==="k")R([...E.slice(0,_),...E.slice(A.end)].join(""),_);else if(C==="u")R([...E.slice(0,A.start),...E.slice(_)].join(""),A.start);else if(C==="w"){let $=_;for(;$>A.start&&E[$-1]===" ";)$-=1;for(;$>A.start&&E[$-1]!==" ";)$-=1;R([...E.slice(0,$),...E.slice(_)].join(""),$)}return}w.meta||!C||S(E,_,C)}},{isActive:n});let v=Gf(l,x),M=Wf(v,f),N=Math.min(d,Math.max(0,v.length-r));M<N&&(N=M),M>N+r-1&&(N=M-r+1),N!==d&&h(N);let O=[];for(let C=0;C<r;C+=1){let w=N+C,E=v[w];if(E===void 0){O.push(Mn(Xn,{children:" "},w));continue}let _=l.slice(E.start,E.end).join("");if(!n||w!==M){O.push(Mn(Xn,{wrap:"truncate",color:p.foreground,children:_===""?" ":_},w));continue}let A=l.slice(E.start,f).join(""),$=f<E.end?l[f]??" ":" ",Z=f<E.end?l.slice(f+1,E.end).join(""):"";O.push(Vf(Xn,{wrap:"truncate",children:[Mn(Xn,{color:p.foreground,children:A}),Mn(ei,{char:$}),Mn(Xn,{color:p.foreground,children:Z})]},w))}if(e===""&&i!==void 0){let C=[...i];O[0]=n?Vf(Xn,{wrap:"truncate",children:[Mn(ei,{char:C[0]??" "}),Mn(Xn,{color:p.faintForeground,children:C.slice(1).join("")})]},"placeholder"):Mn(Xn,{wrap:"truncate",color:p.faintForeground,children:i},"placeholder")}let U=rt({onWheel:C=>{b(C)},onClick:({row:C,column:w})=>{c?.();let E=v[N+C];T(E===void 0?l.length:zf(l,E,w))}});return Mn(aw,{ref:U,flexDirection:"column",children:O})}import{Fragment as eg,jsx as ve,jsxs as At}from"react/jsx-runtime";var uw=e=>Object.fromEntries(e.map(t=>[t.name,"initial"in t?t.initial??"":""])),Qf="\u9009\u586B",dw=(e,t)=>e.kind!=="text"&&e.kind!=="textarea"?!1:typeof e.optional=="function"?e.optional(t):e.optional===!0,pw=(e,t)=>{let n=typeof e.hint=="function"?e.hint(t[e.name]??""):e.hint;return dw(e,t)?n===void 0?Qf:`${Qf} \xB7 ${n}`:n},fw=(e,t)=>{let n=[];return e.forEach((o,r)=>{n.push({type:"field",index:r}),o.kind==="code"&&n.push({type:"send",index:r})}),n.push({type:"submit"}),t!==void 0&&n.push({type:"secondary",action:t}),n},gw=6e4,hw=4,El=4,yw=2,ci=(e,t)=>e?p.accent:t?p.foreground:p.mutedForeground;function ne({title:e,fields:t,submitLabel:n,onSubmit:o,onCancel:r,onChange:i,secondary:s,width:a,busy:c,busyLabel:l="\u6B63\u5728\u63D0\u4EA4",error:u}){let[m,f]=sr(()=>uw(t)),[d,h]=sr(0),[y,g]=sr({}),[x,T]=sr(null),[,R]=sr(0),b=c===!0,S=fw(t,s),v=S[Math.min(d,S.length-1)],M=v?.type==="field"||v?.type==="send"?t[v.index]:void 0;Jf(()=>{i?.(m)},[m]);let N=v?.type==="field"&&(M?.kind==="text"||M?.kind==="code"),O=v?.type==="field"&&M?.kind==="textarea",U=Object.values(y).some(B=>B.phase==="cooldown"&&B.until>Date.now());Jf(()=>{if(!U)return;let B=setInterval(()=>R(z=>z+1),1e3);return()=>clearInterval(B)},[U]);let C=B=>h(z=>(z+B+S.length)%S.length),w=(B,z)=>{if(B.options.length===0)return;let Y=B.options.findIndex(Me=>Me.value===m[B.name]),be=B.options[(Y+z+B.options.length)%B.options.length];be!==void 0&&f(Me=>({...Me,[B.name]:be.value}))},E=B=>{v?.type!=="field"||M?.kind!=="select"||w(M,B)},_=B=>{let z=t[B];if(z===void 0||z.kind!=="code")return;let Y=(m[z.emailField]??"").trim();if(Y===""){g(Me=>({...Me,[z.name]:{phase:"error",message:"\u8BF7\u5148\u586B\u5199\u90AE\u7BB1"}}));return}let be=y[z.name];be?.phase!=="sending"&&(be?.phase==="cooldown"&&be.email===Y&&be.until>Date.now()||(g(Me=>({...Me,[z.name]:{phase:"sending"}})),z.send(Y).then(()=>g(Me=>({...Me,[z.name]:{phase:"cooldown",email:Y,until:Date.now()+gw}}))).catch(Me=>g(ge=>({...ge,[z.name]:{phase:"error",message:xe(Me)}})))))};tg((B,z)=>{if(z.tab){C(z.shift?-1:1);return}if(!O){if(z.upArrow){C(-1);return}if(z.downArrow){C(1);return}if(!N){if(z.leftArrow){E(-1);return}if(z.rightArrow){E(1);return}z.return&&(v?.type==="submit"?o(m):v?.type==="secondary"?v.action.onSubmit(m):v?.type==="send"?_(v.index):C(1))}}},{isActive:!b}),gn(()=>{b||r(m)},{layer:zn.panel}),Yd(b),Ce(b);let A=Math.max(0,...t.map(B=>Ml(B.label))),$=a-pe,Z=Math.max(8,$-A-8),oe=(B,z)=>S.findIndex(Y=>Y.type===B&&(Y.type==="field"||Y.type==="send"?Y.index===z:!0)),fe=Xf(new Map).current,D=Xf(new Map).current,k=2+A+El,X=(B,z)=>{let Y=S[B];if(Y===void 0)return;if(h(B),Y.type==="submit"){o(m);return}if(Y.type==="secondary"){Y.action.onSubmit(m);return}if(Y.type==="send"){_(Y.index);return}let be=t[Y.index];if(be!==void 0){if(be.kind==="select"){let Me=be.options.find(et=>et.value===m[be.name]),ge=Ge(Me?.label??"\u2014",Z);z>=k-yw&&z<k?w(be,-1):z>=k+Ml(ge)&&w(be,1);return}z>=k&&D.get(Y.index)?.moveToColumn(z-k)}},F=(B,z)=>{if(B===null)return null;let Y=Yf(B),be=null;for(let[Me,ge]of fe){if(ge===null)continue;let et=Yf(ge),Be=et.y-Y.y;z<Be||z>=Be+et.height||(be===null||et.height<be.box.height)&&(be={index:Me,box:et})}return be===null?null:{...be,frameX:Y.x}},re=rt({isActive:!b,onClick:({row:B,column:z})=>{let Y=F(re.current,B);Y!==null&&X(Y.index,z-(Y.box.x-Y.frameX))},onHover:({row:B})=>T(F(re.current,B)?.index??null),onHoverLeave:()=>T(null)});return At(tn,{ref:re,flexDirection:"column",children:[ve(Rn,{title:e,width:a}),At(tn,{flexDirection:"column",marginTop:We,paddingLeft:pe,children:[u!=null&&ve(tn,{marginBottom:1,children:ve(Ft,{message:u.message,hint:u.hint,width:$})}),t.map((B,z)=>{let Y=d===oe("field",z)&&!b,be=pw(B,m),Me=B.kind==="select"?B.options.find(Be=>Be.value===m[B.name]):void 0;if(B.kind==="textarea")return At(tn,{flexDirection:"column",ref:Be=>{fe.set(oe("field",z),Be)},children:[At(Ue,{children:[ve(Ue,{color:p.accent,children:Y?`${ie.cursor} `:" "}),ve(Ue,{color:ci(Y,x===oe("field",z)),bold:Y,children:B.label})]}),ve(tn,{paddingLeft:2,children:ve(Kf,{value:m[B.name]??"",onChange:Be=>f(Ga=>({...Ga,[B.name]:Be})),isActive:Y,width:$-2,rows:B.rows??hw,placeholder:B.placeholder,maxLength:B.maxLength,onEdge:Be=>C(Be==="up"?-1:1),onFocusRequest:()=>h(oe("field",z))})}),Y&&be!==void 0&&ve(Ue,{color:p.faintForeground,children:` ${Ge(be,$-2)}`})]},B.name);let ge=B.kind==="code"&&d===oe("send",z)&&!b,et=y[B.name];return At(tn,{flexDirection:"column",ref:Be=>{fe.set(oe("field",z),Be)},children:[At(Ue,{children:[ve(Ue,{color:p.accent,children:Y?`${ie.cursor} `:" "}),ve(Ue,{color:ci(Y,x===oe("field",z)),bold:Y,children:Qe(B.label,A)}),B.kind==="select"?At(eg,{children:[ve(Ue,{color:Y?p.accent:p.border,children:` ${ie.prev} `}),ve(Ue,{color:p.foreground,children:Ge(Me?.label??"\u2014",Z)}),ve(Ue,{color:Y?p.accent:p.border,children:` ${ie.next}`})]}):At(eg,{children:[ve(Ue,{children:" ".repeat(El)}),ve(Zo,{ref:Be=>{D.set(z,Be)},value:m[B.name]??"",onChange:Be=>f(Ga=>({...Ga,[B.name]:Be})),onSubmit:()=>C(1),isActive:Y,placeholder:B.kind==="text"||B.kind==="code"?B.placeholder:void 0,mask:B.kind==="text"?B.mask:void 0,width:Z})]})]}),Y&&be!==void 0&&ve(Ue,{color:p.faintForeground,children:`${" ".repeat(2+A+El)}${Ge(be,Z)}`}),B.kind==="code"&&ve(bw,{active:ge,state:et,email:(m[B.emailField]??"").trim(),indent:k,width:Z,hovered:x===oe("send",z),nodeRef:Be=>{fe.set(oe("send",z),Be)}})]},B.name)}),At(tn,{marginTop:1,flexDirection:"column",children:[ve(tn,{ref:B=>{fe.set(oe("submit"),B)},children:b?ve(De,{label:l}):At(Ue,{children:[ve(Ue,{color:p.accent,children:v?.type==="submit"?`${ie.cursor} `:" "}),ve(Ue,{color:ci(v?.type==="submit",x===oe("submit")),bold:v?.type==="submit",children:n})]})}),s!==void 0&&!b&&ve(tn,{ref:B=>{fe.set(oe("secondary"),B)},children:At(Ue,{children:[ve(Ue,{color:p.accent,children:v?.type==="secondary"?`${ie.cursor} `:" "}),ve(Ue,{color:ci(v?.type==="secondary",x===oe("secondary")),bold:v?.type==="secondary",children:s.label})]})})]})]})]})}function bw({active:e,state:t,email:n,indent:o,width:r,hovered:i,nodeRef:s}){if(t?.phase==="sending")return ve(tn,{paddingLeft:o,children:ve(De,{label:"\u6B63\u5728\u53D1\u9001\u9A8C\u8BC1\u7801"})});let a=t?.phase==="cooldown"&&t.email===n?Math.ceil((t.until-Date.now())/1e3):0,c=a>0?`${a} \u79D2\u540E\u53EF\u91CD\u53D1`:"\u53D1\u9001\u9A8C\u8BC1\u7801";return At(tn,{ref:s,flexDirection:"column",paddingLeft:o-2,children:[At(Ue,{children:[ve(Ue,{color:p.accent,children:e?`${ie.cursor} `:" "}),ve(Ue,{color:a>0?p.faintForeground:ci(e,i),bold:e&&a===0,children:c})]}),t?.phase==="error"&&ve(Ue,{color:p.danger,children:` ${Ge(t.message,r)}`})]})}var Sw=2,Zf=2;function js({options:e,value:t,onChange:n,arrowKeys:o=!0}){let r=e.findIndex(m=>m.value===t),i=ps();tg((m,f)=>{if(!f.leftArrow&&!f.rightArrow)return;let d=f.leftArrow?-1:1,h=e[(r+d+e.length)%e.length];h!==void 0&&n(h.value)},{isActive:o&&!i});let s=[],a=0;e.forEach((m,f)=>{f>0&&(a+=Zf);let d=Ml(m.label)+Sw;s.push({value:m.value,from:a,to:a+d}),a+=d});let[c,l]=sr(null),u=rt({onClick:({column:m})=>{let f=s.find(d=>m>=d.from&&m<d.to);f!==void 0&&n(f.value)},onHover:({column:m})=>{let f=s.find(d=>m>=d.from&&m<d.to);l(f?.value??null)},onHoverLeave:()=>l(null)});return ve(tn,{ref:u,children:ve(Ue,{wrap:"truncate",children:e.map((m,f)=>{let d=m.value===t;return At(Ue,{children:[f>0&&" ".repeat(Zf),ve(Ue,{backgroundColor:d?p.foreground:p.border,color:d?p.background:m.value===c?p.foreground:p.mutedForeground,bold:d,children:` ${m.label} `})]},m.value)})})})}import{Box as ng,Text as Sn}from"ink";import xw from"string-width";import{jsx as bn,jsxs as Il}from"react/jsx-runtime";var Hs=3,In=2,To=10,Tw=8,og=e=>Math.floor((e-Hs)/In),ar=e=>og(e)>=Tw;function ww(e,t){let n=new Map(e.days.map(l=>[l.day,t(l)])),o=[...n.values()].sort((l,u)=>l-u),r=l=>o[Math.floor((o.length-1)*l)]??0,[i,s,a]=[r(.25),r(.5),r(.75)],c=[];for(let l=e.start;l<=e.end;l=Gn(l,1)){let u=n.get(l)??0;c.push({day:l,level:u<=0?0:u<=i?1:u<=s?2:u<=a?3:4})}return c}function kw(e,t){let n=t*In,o="",r=0,i="";for(;r<n;){let s=r%In===0?e[r/In*7]:void 0;if(s!==void 0){let a=s.day.slice(0,7);if(a!==i){i=a;let c=`${Number(s.day.slice(5,7))}\u6708`,l=xw(c);if(r+l<=n){o+=c,r+=l;continue}}}o+=" ",r+=1}return o}var vw={1:"\u4E00",3:"\u4E09",5:"\u4E94"};function Rw({cells:e,day:t,weeks:n}){return Il(Sn,{wrap:"truncate",children:[bn(Sn,{color:p.faintForeground,children:Qe(vw[t]??"",Hs)}),Array.from({length:n},(o,r)=>{let i=e[r*7+t];return i===void 0?bn(Sn,{children:" ".repeat(In)},r):bn(Sn,{backgroundColor:ys[i.level],children:" ".repeat(In)},r)})]})}function cr({data:e,value:t,caption:n,width:o}){let r=ww(e,t),i=Math.ceil(r.length/7),s=Math.min(i,og(o)),a=r.slice((i-s)*7),c=3+ys.length*In+3,l=Math.max(0,Hs+s*In-c-2);return Il(ng,{flexDirection:"column",children:[bn(Sn,{wrap:"truncate",color:p.faintForeground,children:" ".repeat(Hs)+kw(a,s)}),Array.from({length:7},(u,m)=>bn(Rw,{cells:a,day:m,weeks:s},m)),bn(ng,{marginTop:1,children:Il(Sn,{wrap:"truncate",children:[bn(Sn,{color:p.mutedForeground,children:Qe(n??"",l)})," ",bn(Sn,{color:p.faintForeground,children:"\u5C11 "}),ys.map(u=>bn(Sn,{backgroundColor:u,children:" ".repeat(In)},u)),bn(Sn,{color:p.faintForeground,children:" \u591A"})]})})]})}import{Box as Ol,Text as rg}from"ink";import Cw from"qrcode";import{jsx as li,jsxs as Iw}from"react/jsx-runtime";var _w="#000000",Pw="#ffffff",Nl=2,sg=2,Dl=1,ig,Ll;function ag(e){if(e===ig&&Ll!==void 0)return Ll;let t=Cw.create(e,{errorCorrectionLevel:"L"}),n=t.modules.size,o=t.modules.data,r=n+Nl*2,i=Array.from({length:r},()=>Array.from({length:r},()=>!1));for(let s=0;s<n;s+=1)for(let a=0;a<n;a+=1){let c=i[s+Nl];c!==void 0&&(c[a+Nl]=o[s*n+a]===1)}return ig=e,Ll=i,i}function Aw(e){let t=ag(e).length;return{columns:t*sg,rows:t}}function qs(e,t,n,o){let r=Aw(e),i=t.rows-r.rows-Dl;return r.columns<=t.width&&i>=n.rows?{fits:!0,qr:r,asideWidth:t.width,asideRows:i}:{fits:!1,target:{columns:Math.max(r.columns,n.columns)+o.columns,rows:r.rows+Dl+n.rows+o.rows}}}function Ew(e,t){let n=[],o=0;for(let r=1;r<=e.length;r+=1)r<e.length&&e[r]===e[o]||(n.push(li(rg,{backgroundColor:e[o]??!1?_w:Pw,children:" ".repeat((r-o)*sg)},o)),o=r);return li(rg,{children:n},t)}function Mw({value:e}){return li(Ol,{flexDirection:"column",flexShrink:0,children:ag(e).map((t,n)=>Ew(t,n))})}function Gs({value:e,aside:t}){return Iw(Ol,{flexDirection:"column",flexShrink:0,children:[li(Mw,{value:e}),li(Ol,{marginTop:Dl,flexDirection:"column",children:t})]})}import{Box as Ws,Text as Et}from"ink";import cg from"string-width";import{jsx as Mt,jsxs as mi}from"react/jsx-runtime";var zs=2,$l=4,lg=e=>" ".repeat(e),Bl=13,mg=4,ug=(e,t,n)=>Math.max(1,Math.min(e,n,Math.floor((t+zs)/(Bl+zs)))),Ut=(e,t,n=mg)=>Math.ceil(e/ug(e,t,n))*2;function it({tiles:e,width:t,maxPerRow:n=mg}){let o=ug(e.length,t,n),r=Math.floor((t-zs*(o-1))/o),i=[];for(let s=0;s<e.length;s+=o)i.push(e.slice(s,s+o));return Mt(Ws,{flexDirection:"column",children:i.map((s,a)=>Mt(Ws,{flexDirection:"column",children:["label","value"].map(c=>Mt(Et,{wrap:"truncate",children:s.map((l,u)=>mi(Et,{children:[u>0&&lg(zs),Mt(Et,{color:c==="label"?p.mutedForeground:p.foreground,bold:c==="value",children:Qe(l[c],r)})]},l.label))},c))},a))})}function dg({used:e,total:t,width:n=20}){let o=t<=0?1:Math.min(1,e/t),r=Math.round(o*n),i=o>=1?p.danger:o>=.8?p.warning:p.foreground;return mi(Et,{children:[Mt(Et,{color:i,children:ie.barFilled.repeat(r)}),Mt(Et,{color:p.border,children:ie.barEmpty.repeat(n-r)})]})}function Nw({items:e,width:t}){let n=Math.max(0,...e.map(([r])=>cg(r))),o=Math.max(0,t-n-3);return Mt(Ws,{flexDirection:"column",children:e.map(([r,i])=>mi(Et,{wrap:"truncate",children:[Mt(Et,{color:p.mutedForeground,children:Qe(r,n)})," ",Mt(Et,{color:p.foreground,children:Ge(i,o)})]},r))})}var Vs=(e,t)=>Math.floor((t-$l)/2)<Bl*2?e:Math.ceil(e/2);function Ye({items:e,width:t}){let n=Math.floor((t-$l)/2);if(n<Bl*2)return Mt(Nw,{items:e,width:t});let o=Math.max(0,...e.map(([a])=>cg(a))),r=n-o-2,i=[];for(let a=0;a<e.length;a+=2)i.push(e.slice(a,a+2));let s=a=>a===void 0?Mt(Et,{children:" ".repeat(n)}):mi(Et,{children:[Mt(Et,{color:p.mutedForeground,children:Qe(a[0],o)})," ",Mt(Et,{color:p.foreground,children:Qe(a[1],r)})]});return Mt(Ws,{flexDirection:"column",children:i.map((a,c)=>mi(Et,{wrap:"truncate",children:[s(a[0]),lg($l),s(a[1])]},c))})}import{Lexer as Lw}from"marked";var Ow=new RegExp("\\p{Cc}","gu"),Dw=/[\\[\]]/g,$w=/[\\`*_{}[\]()#+\-.!|<>~]/g,Bw=/[\uD800-\uDBFF]$/,Fw=400,Uw=12,jw=20,lr={label:"\u677F\u5757",cap:Uw},Qn={label:"\u4F5C\u8005",cap:jw},Ks={maxCount:Bu,maxBytes:Dr},Ys={maxCount:Fu,maxBytes:Dr},pg={published:{tone:"ok",message:"\u5DF2\u53D1\u5E03"},pending:{tone:"ok",message:"\u5DF2\u63D0\u4EA4\u5BA1\u6838"},rejected:{tone:"fail",message:"\u672A\u901A\u8FC7\u5BA1\u6838"}},st=e=>e.replace(Ow,""),ui=e=>({kind:e.kind,username:e.username});function vt(e){let t=st(e.username);return e.kind==="user"?`${t} Lv.${qi(e.points).level}`:`${t} [${zi}]`}var Js=e=>`@${st(e.username)}`,fg=e=>e.flatMap(t=>[{reply:t.reply,mention:t.mention,prefix:""},...gg(t.children,"")]);function gg(e,t){return e.flatMap((n,o)=>{let r=o===e.length-1;return[{reply:n.reply,mention:n.mention,prefix:`${t}${r?"\u2514\u2500 ":"\u251C\u2500 "}`},...gg(n.children,`${t}${r?" ":"\u2502 "}`)]})}var Nn=(e,t)=>e.kind==="user"&&e.username===t,Fl=e=>`${e.image?"[\u56FE\u7247]":"[\u9644\u4EF6]"} ${st(e.name)}`;function jt(e){let t=new Set;return zu(e).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}var Hw=e=>Tc(e,t=>Fl(t).replace($w,"\\$&")),di=(e,t)=>hn(Hw(e),t);function wo(e){let t=Tc(e,n=>n.image?"[\u56FE\u7247]":`[\u9644\u4EF6] ${n.name}`).slice(0,Fw).replace(Bw,"");return st(dd(Lw.lex(t,{gfm:!0,breaks:!0}))).trim()}var qw=e=>st(e).trim().replace(Dw,"\\$&");function pi(e,t){if(t.length===0)return e;let n=t.map(o=>`${o.image===null?"":"!"}[${qw(o.fileName)}](${Uu(o.id)})`).join(`
14
+ `;)o+=1;return{start:n,end:o}}function Qf({value:e,onChange:t,isActive:n,width:o,rows:r,placeholder:i,maxLength:s,onEdge:a,onFocusRequest:c}){let l=[...e],[u,m]=Vf(l.length),p=Math.min(u,l.length),[d,b]=Vf(0),h=Wf(e),g=Wf(p);h.current=e,g.current=p,ms(n);let x=Math.max(4,o),T=C=>{g.current=C,m(C)},k=(C,v)=>{h.current=C,T(v),t(C)},S=C=>{let v=[...h.current],_=Math.min(g.current,v.length),L=Kf(v,x),P=Yf(L,_),B=L[P],J=L[P+C];return B===void 0||J===void 0?!1:(T(Jf(v,J,fw(v,B,_))),!0)},y=(C,v,_)=>{let L=pw(_);if(s!==void 0){let P=s-C.length;if(P<=0)return;L=[...L].slice(0,P).join("")}L!==""&&k([...C.slice(0,v),L,...C.slice(v)].join(""),v+[...L].length)};dw((C,v)=>{let _=[...h.current],L=Math.min(g.current,_.length);if(v.return){y(_,L,`
15
+ `);return}if(!v.tab){if(v.upArrow||v.downArrow){let P=v.upArrow?-1:1;S(P)||a?.(v.upArrow?"up":"down");return}if(v.leftArrow){T(Math.max(0,L-1));return}if(v.rightArrow){T(Math.min(_.length,L+1));return}if(v.home){T(Pl(_,L).start);return}if(v.end){T(Pl(_,L).end);return}if(v.backspace){if(L===0)return;k([..._.slice(0,L-1),..._.slice(L)].join(""),L-1);return}if(v.delete){if(L>=_.length)return;k([..._.slice(0,L),..._.slice(L+1)].join(""),L);return}if(v.ctrl){let P=Pl(_,L);if(C==="a")T(P.start);else if(C==="e")T(P.end);else if(C==="k")k([..._.slice(0,L),..._.slice(P.end)].join(""),L);else if(C==="u")k([..._.slice(0,P.start),..._.slice(L)].join(""),P.start);else if(C==="w"){let B=L;for(;B>P.start&&_[B-1]===" ";)B-=1;for(;B>P.start&&_[B-1]!==" ";)B-=1;k([..._.slice(0,B),..._.slice(L)].join(""),B)}return}v.meta||!C||y(_,L,C)}},{isActive:n});let R=Kf(l,x),N=Yf(R,p),E=Math.min(d,Math.max(0,R.length-r));N<E&&(E=N),N>E+r-1&&(E=N-r+1),E!==d&&b(E);let W=[];for(let C=0;C<r;C+=1){let v=E+C,_=R[v];if(_===void 0){W.push(In(Xn,{children:" "},v));continue}let L=l.slice(_.start,_.end).join("");if(!n||v!==N){W.push(In(Xn,{wrap:"truncate",color:f.foreground,children:L===""?" ":L},v));continue}let P=l.slice(_.start,p).join(""),B=p<_.end?l[p]??" ":" ",J=p<_.end?l.slice(p+1,_.end).join(""):"";W.push(Xf(Xn,{wrap:"truncate",children:[In(Xn,{color:f.foreground,children:P}),In(Zr,{char:B}),In(Xn,{color:f.foreground,children:J})]},v))}if(e===""&&i!==void 0){let C=[...i];W[0]=n?Xf(Xn,{wrap:"truncate",children:[In(Zr,{char:C[0]??" "}),In(Xn,{color:f.faintForeground,children:C.slice(1).join("")})]},"placeholder"):In(Xn,{wrap:"truncate",color:f.faintForeground,children:i},"placeholder")}let M=rt({onWheel:C=>{S(C)},onClick:({row:C,column:v})=>{c?.();let _=R[E+C];T(_===void 0?l.length:Jf(l,_,v))}});return In(uw,{ref:M,flexDirection:"column",children:W})}import{Fragment as rg,jsx as ve,jsxs as At}from"react/jsx-runtime";var gw=e=>Object.fromEntries(e.map(t=>[t.name,"initial"in t?t.initial??"":""])),ng="\u9009\u586B",hw=(e,t)=>e.kind!=="text"&&e.kind!=="textarea"?!1:typeof e.optional=="function"?e.optional(t):e.optional===!0,yw=(e,t)=>{let n=typeof e.hint=="function"?e.hint(t[e.name]??""):e.hint;return hw(e,t)?n===void 0?ng:`${ng} \xB7 ${n}`:n},bw=(e,t)=>{let n=[];return e.forEach((o,r)=>{n.push({type:"field",index:r}),o.kind==="code"&&n.push({type:"send",index:r})}),n.push({type:"submit"}),t!==void 0&&n.push({type:"secondary",action:t}),n},Sw=6e4,xw=4,El=4,Tw=2,ai=(e,t)=>e?f.accent:t?f.foreground:f.mutedForeground;function te({title:e,fields:t,submitLabel:n,onSubmit:o,onCancel:r,onChange:i,secondary:s,width:a,busy:c,busyLabel:l="\u6B63\u5728\u63D0\u4EA4",error:u}){let[m,p]=ar(()=>gw(t)),[d,b]=ar(0),[h,g]=ar({}),[x,T]=ar(null),[,k]=ar(0),S=c===!0,y=bw(t,s),R=y[Math.min(d,y.length-1)],N=R?.type==="field"||R?.type==="send"?t[R.index]:void 0;eg(()=>{i?.(m)},[m]);let E=R?.type==="field"&&(N?.kind==="text"||N?.kind==="code"),W=R?.type==="field"&&N?.kind==="textarea",M=Object.values(h).some(D=>D.phase==="cooldown"&&D.until>Date.now());eg(()=>{if(!M)return;let D=setInterval(()=>k(z=>z+1),1e3);return()=>clearInterval(D)},[M]);let C=D=>b(z=>(z+D+y.length)%y.length),v=(D,z)=>{if(D.options.length===0)return;let ee=D.options.findIndex(ie=>ie.value===m[D.name]),he=D.options[(ee+z+D.options.length)%D.options.length];he!==void 0&&p(ie=>({...ie,[D.name]:he.value}))},_=D=>{R?.type!=="field"||N?.kind!=="select"||v(N,D)},L=D=>{let z=t[D];if(z===void 0||z.kind!=="code")return;let ee=(m[z.emailField]??"").trim();if(ee===""){g(ie=>({...ie,[z.name]:{phase:"error",message:"\u8BF7\u5148\u586B\u5199\u90AE\u7BB1"}}));return}let he=h[z.name];he?.phase!=="sending"&&(he?.phase==="cooldown"&&he.email===ee&&he.until>Date.now()||(g(ie=>({...ie,[z.name]:{phase:"sending"}})),z.send(ee).then(()=>g(ie=>({...ie,[z.name]:{phase:"cooldown",email:ee,until:Date.now()+Sw}}))).catch(ie=>g(Qe=>({...Qe,[z.name]:{phase:"error",message:xe(ie)}})))))};ig((D,z)=>{if(z.tab){C(z.shift?-1:1);return}if(!W){if(z.upArrow){C(-1);return}if(z.downArrow){C(1);return}if(!E){if(z.leftArrow){_(-1);return}if(z.rightArrow){_(1);return}z.return&&(R?.type==="submit"?o(m):R?.type==="secondary"?R.action.onSubmit(m):R?.type==="send"?L(R.index):C(1))}}},{isActive:!S}),gn(()=>{S||r(m)},{layer:Wn.panel}),Qd(S),Re(S);let P=Math.max(0,...t.map(D=>Ml(D.label))),B=a-ge,J=Math.max(8,B-P-8),oe=(D,z)=>y.findIndex(ee=>ee.type===D&&(ee.type==="field"||ee.type==="send"?ee.index===z:!0)),fe=tg(new Map).current,$=tg(new Map).current,ne=2+P+El,w=(D,z)=>{let ee=y[D];if(ee===void 0)return;if(b(D),ee.type==="submit"){o(m);return}if(ee.type==="secondary"){ee.action.onSubmit(m);return}if(ee.type==="send"){L(ee.index);return}let he=t[ee.index];if(he!==void 0){if(he.kind==="select"){let ie=he.options.find(xt=>xt.value===m[he.name]),Qe=He(ie?.label??"\u2014",J);z>=ne-Tw&&z<ne?v(he,-1):z>=ne+Ml(Qe)&&v(he,1);return}z>=ne&&$.get(ee.index)?.moveToColumn(z-ne)}},F=(D,z)=>{if(D===null)return null;let ee=Zf(D),he=null;for(let[ie,Qe]of fe){if(Qe===null)continue;let xt=Zf(Qe),Ze=xt.y-ee.y;z<Ze||z>=Ze+xt.height||(he===null||xt.height<he.box.height)&&(he={index:ie,box:xt})}return he===null?null:{...he,frameX:ee.x}},re=rt({isActive:!S,onClick:({row:D,column:z})=>{let ee=F(re.current,D);ee!==null&&w(ee.index,z-(ee.box.x-ee.frameX))},onHover:({row:D})=>T(F(re.current,D)?.index??null),onHoverLeave:()=>T(null)});return At(tn,{ref:re,flexDirection:"column",children:[ve(Rn,{title:e,width:a}),At(tn,{flexDirection:"column",marginTop:qe,paddingLeft:ge,children:[u!=null&&ve(tn,{marginBottom:1,children:ve(Ft,{message:u.message,hint:u.hint,width:B})}),t.map((D,z)=>{let ee=d===oe("field",z)&&!S,he=yw(D,m),ie=D.kind==="select"?D.options.find(Ze=>Ze.value===m[D.name]):void 0;if(D.kind==="textarea")return At(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",z),Ze)},children:[At(Be,{children:[ve(Be,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Be,{color:ai(ee,x===oe("field",z)),bold:ee,children:D.label})]}),ve(tn,{paddingLeft:2,children:ve(Qf,{value:m[D.name]??"",onChange:Ze=>p(Ha=>({...Ha,[D.name]:Ze})),isActive:ee,width:B-2,rows:D.rows??xw,placeholder:D.placeholder,maxLength:D.maxLength,onEdge:Ze=>C(Ze==="up"?-1:1),onFocusRequest:()=>b(oe("field",z))})}),ee&&he!==void 0&&ve(Be,{color:f.faintForeground,children:` ${He(he,B-2)}`})]},D.name);let Qe=D.kind==="code"&&d===oe("send",z)&&!S,xt=h[D.name];return At(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",z),Ze)},children:[At(Be,{children:[ve(Be,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Be,{color:ai(ee,x===oe("field",z)),bold:ee,children:Je(D.label,P)}),D.kind==="select"?At(rg,{children:[ve(Be,{color:ee?f.accent:f.border,children:` ${ae.prev} `}),ve(Be,{color:f.foreground,children:He(ie?.label??"\u2014",J)}),ve(Be,{color:ee?f.accent:f.border,children:` ${ae.next}`})]}):At(rg,{children:[ve(Be,{children:" ".repeat(El)}),ve(er,{ref:Ze=>{$.set(z,Ze)},value:m[D.name]??"",onChange:Ze=>p(Ha=>({...Ha,[D.name]:Ze})),onSubmit:()=>C(1),isActive:ee,placeholder:D.kind==="text"||D.kind==="code"?D.placeholder:void 0,mask:D.kind==="text"?D.mask:void 0,width:J})]})]}),ee&&he!==void 0&&ve(Be,{color:f.faintForeground,children:`${" ".repeat(2+P+El)}${He(he,J)}`}),D.kind==="code"&&ve(ww,{active:Qe,state:xt,email:(m[D.emailField]??"").trim(),indent:ne,width:J,hovered:x===oe("send",z),nodeRef:Ze=>{fe.set(oe("send",z),Ze)}})]},D.name)}),At(tn,{marginTop:1,flexDirection:"column",children:[ve(tn,{ref:D=>{fe.set(oe("submit"),D)},children:S?ve(Oe,{label:l}):At(Be,{children:[ve(Be,{color:f.accent,children:R?.type==="submit"?`${ae.cursor} `:" "}),ve(Be,{color:ai(R?.type==="submit",x===oe("submit")),bold:R?.type==="submit",children:n})]})}),s!==void 0&&!S&&ve(tn,{ref:D=>{fe.set(oe("secondary"),D)},children:At(Be,{children:[ve(Be,{color:f.accent,children:R?.type==="secondary"?`${ae.cursor} `:" "}),ve(Be,{color:ai(R?.type==="secondary",x===oe("secondary")),bold:R?.type==="secondary",children:s.label})]})})]})]})]})}function ww({active:e,state:t,email:n,indent:o,width:r,hovered:i,nodeRef:s}){if(t?.phase==="sending")return ve(tn,{paddingLeft:o,children:ve(Oe,{label:"\u6B63\u5728\u53D1\u9001\u9A8C\u8BC1\u7801"})});let a=t?.phase==="cooldown"&&t.email===n?Math.ceil((t.until-Date.now())/1e3):0,c=a>0?`${a} \u79D2\u540E\u53EF\u91CD\u53D1`:"\u53D1\u9001\u9A8C\u8BC1\u7801";return At(tn,{ref:s,flexDirection:"column",paddingLeft:o-2,children:[At(Be,{children:[ve(Be,{color:f.accent,children:e?`${ae.cursor} `:" "}),ve(Be,{color:a>0?f.faintForeground:ai(e,i),bold:e&&a===0,children:c})]}),t?.phase==="error"&&ve(Be,{color:f.danger,children:` ${He(t.message,r)}`})]})}var kw=2,og=2;function Fs({options:e,value:t,onChange:n,arrowKeys:o=!0}){let r=e.findIndex(m=>m.value===t),i=ds();ig((m,p)=>{if(!p.leftArrow&&!p.rightArrow)return;let d=p.leftArrow?-1:1,b=e[(r+d+e.length)%e.length];b!==void 0&&n(b.value)},{isActive:o&&!i});let s=[],a=0;e.forEach((m,p)=>{p>0&&(a+=og);let d=Ml(m.label)+kw;s.push({value:m.value,from:a,to:a+d}),a+=d});let[c,l]=ar(null),u=rt({onClick:({column:m})=>{let p=s.find(d=>m>=d.from&&m<d.to);p!==void 0&&n(p.value)},onHover:({column:m})=>{let p=s.find(d=>m>=d.from&&m<d.to);l(p?.value??null)},onHoverLeave:()=>l(null)});return ve(tn,{ref:u,children:ve(Be,{wrap:"truncate",children:e.map((m,p)=>{let d=m.value===t;return At(Be,{children:[p>0&&" ".repeat(og),ve(Be,{backgroundColor:d?f.foreground:f.border,color:d?f.background:m.value===c?f.foreground:f.mutedForeground,bold:d,children:` ${m.label} `})]},m.value)})})})}import{Box as sg,Text as Sn}from"ink";import vw from"string-width";import{jsx as bn,jsxs as Il}from"react/jsx-runtime";var Us=3,Nn=2,To=10,Cw=8,ag=e=>Math.floor((e-Us)/Nn),cr=e=>ag(e)>=Cw;function Rw(e,t){let n=new Map(e.days.map(l=>[l.day,t(l)])),o=[...n.values()].sort((l,u)=>l-u),r=l=>o[Math.floor((o.length-1)*l)]??0,[i,s,a]=[r(.25),r(.5),r(.75)],c=[];for(let l=e.start;l<=e.end;l=Gn(l,1)){let u=n.get(l)??0;c.push({day:l,level:u<=0?0:u<=i?1:u<=s?2:u<=a?3:4})}return c}function _w(e,t){let n=t*Nn,o="",r=0,i="";for(;r<n;){let s=r%Nn===0?e[r/Nn*7]:void 0;if(s!==void 0){let a=s.day.slice(0,7);if(a!==i){i=a;let c=`${Number(s.day.slice(5,7))}\u6708`,l=vw(c);if(r+l<=n){o+=c,r+=l;continue}}}o+=" ",r+=1}return o}var Pw={1:"\u4E00",3:"\u4E09",5:"\u4E94"};function Aw({cells:e,day:t,weeks:n}){return Il(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.faintForeground,children:Je(Pw[t]??"",Us)}),Array.from({length:n},(o,r)=>{let i=e[r*7+t];return i===void 0?bn(Sn,{children:" ".repeat(Nn)},r):bn(Sn,{backgroundColor:hs[i.level],children:" ".repeat(Nn)},r)})]})}function lr({data:e,value:t,caption:n,width:o}){let r=Rw(e,t),i=Math.ceil(r.length/7),s=Math.min(i,ag(o)),a=r.slice((i-s)*7),c=3+hs.length*Nn+3,l=Math.max(0,Us+s*Nn-c-2);return Il(sg,{flexDirection:"column",children:[bn(Sn,{wrap:"truncate",color:f.faintForeground,children:" ".repeat(Us)+_w(a,s)}),Array.from({length:7},(u,m)=>bn(Aw,{cells:a,day:m,weeks:s},m)),bn(sg,{marginTop:1,children:Il(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.mutedForeground,children:Je(n??"",l)})," ",bn(Sn,{color:f.faintForeground,children:"\u5C11 "}),hs.map(u=>bn(Sn,{backgroundColor:u,children:" ".repeat(Nn)},u)),bn(Sn,{color:f.faintForeground,children:" \u591A"})]})})]})}import{Box as Ol,Text as cg}from"ink";import Ew from"qrcode";import{jsx as ci,jsxs as Dw}from"react/jsx-runtime";var Mw="#000000",Iw="#ffffff",Nl=2,mg=2,Dl=1,lg,Ll;function ug(e){if(e===lg&&Ll!==void 0)return Ll;let t=Ew.create(e,{errorCorrectionLevel:"L"}),n=t.modules.size,o=t.modules.data,r=n+Nl*2,i=Array.from({length:r},()=>Array.from({length:r},()=>!1));for(let s=0;s<n;s+=1)for(let a=0;a<n;a+=1){let c=i[s+Nl];c!==void 0&&(c[a+Nl]=o[s*n+a]===1)}return lg=e,Ll=i,i}function Nw(e){let t=ug(e).length;return{columns:t*mg,rows:t}}function js(e,t,n,o){let r=Nw(e),i=t.rows-r.rows-Dl;return r.columns<=t.width&&i>=n.rows?{fits:!0,qr:r,asideWidth:t.width,asideRows:i}:{fits:!1,target:{columns:Math.max(r.columns,n.columns)+o.columns,rows:r.rows+Dl+n.rows+o.rows}}}function Lw(e,t){let n=[],o=0;for(let r=1;r<=e.length;r+=1)r<e.length&&e[r]===e[o]||(n.push(ci(cg,{backgroundColor:e[o]??!1?Mw:Iw,children:" ".repeat((r-o)*mg)},o)),o=r);return ci(cg,{children:n},t)}function Ow({value:e}){return ci(Ol,{flexDirection:"column",flexShrink:0,children:ug(e).map((t,n)=>Lw(t,n))})}function Hs({value:e,aside:t}){return Dw(Ol,{flexDirection:"column",flexShrink:0,children:[ci(Ow,{value:e}),ci(Ol,{marginTop:Dl,flexDirection:"column",children:t})]})}import{Box as qs,Text as Et}from"ink";import dg from"string-width";import{jsx as Mt,jsxs as li}from"react/jsx-runtime";var Gs=2,$l=4,pg=e=>" ".repeat(e),Bl=13,fg=4,gg=(e,t,n)=>Math.max(1,Math.min(e,n,Math.floor((t+Gs)/(Bl+Gs)))),Ut=(e,t,n=fg)=>Math.ceil(e/gg(e,t,n))*2;function it({tiles:e,width:t,maxPerRow:n=fg}){let o=gg(e.length,t,n),r=Math.floor((t-Gs*(o-1))/o),i=[];for(let s=0;s<e.length;s+=o)i.push(e.slice(s,s+o));return Mt(qs,{flexDirection:"column",children:i.map((s,a)=>Mt(qs,{flexDirection:"column",children:["label","value"].map(c=>Mt(Et,{wrap:"truncate",children:s.map((l,u)=>li(Et,{children:[u>0&&pg(Gs),Mt(Et,{color:c==="label"?f.mutedForeground:f.foreground,bold:c==="value",children:Je(l[c],r)})]},l.label))},c))},a))})}function hg({used:e,total:t,width:n=20}){let o=t<=0?1:Math.min(1,e/t),r=Math.round(o*n),i=o>=1?f.danger:o>=.8?f.warning:f.foreground;return li(Et,{children:[Mt(Et,{color:i,children:ae.barFilled.repeat(r)}),Mt(Et,{color:f.border,children:ae.barEmpty.repeat(n-r)})]})}function $w({items:e,width:t}){let n=Math.max(0,...e.map(([r])=>dg(r))),o=Math.max(0,t-n-3);return Mt(qs,{flexDirection:"column",children:e.map(([r,i])=>li(Et,{wrap:"truncate",children:[Mt(Et,{color:f.mutedForeground,children:Je(r,n)})," ",Mt(Et,{color:f.foreground,children:He(i,o)})]},r))})}var zs=(e,t)=>Math.floor((t-$l)/2)<Bl*2?e:Math.ceil(e/2);function Ve({items:e,width:t}){let n=Math.floor((t-$l)/2);if(n<Bl*2)return Mt($w,{items:e,width:t});let o=Math.max(0,...e.map(([a])=>dg(a))),r=n-o-2,i=[];for(let a=0;a<e.length;a+=2)i.push(e.slice(a,a+2));let s=a=>a===void 0?Mt(Et,{children:" ".repeat(n)}):li(Et,{children:[Mt(Et,{color:f.mutedForeground,children:Je(a[0],o)})," ",Mt(Et,{color:f.foreground,children:Je(a[1],r)})]});return Mt(qs,{flexDirection:"column",children:i.map((a,c)=>li(Et,{wrap:"truncate",children:[s(a[0]),pg($l),s(a[1])]},c))})}import{Lexer as Bw}from"marked";var Fw=new RegExp("\\p{Cc}","gu"),Uw=/[\\[\]]/g,jw=/[\\`*_{}[\]()#+\-.!|<>~]/g,Hw=/[\uD800-\uDBFF]$/,qw=400,Gw=12,zw=20,mr={label:"\u677F\u5757",cap:Gw},Qn={label:"\u4F5C\u8005",cap:zw},Ws={maxCount:Bu,maxBytes:Dr},Vs={maxCount:Fu,maxBytes:Dr},st=e=>e.replace(Fw,""),mi=e=>({kind:e.kind,username:e.username});function vt(e){let t=st(e.username);return e.kind==="user"?`${t} Lv.${Hi(e.points).level}`:`${t} [${zi}]`}var Ks=e=>`@${st(e.username)}`,yg=e=>e.flatMap(t=>[{reply:t.reply,mention:t.mention,prefix:""},...bg(t.children,"")]);function bg(e,t){return e.flatMap((n,o)=>{let r=o===e.length-1;return[{reply:n.reply,mention:n.mention,prefix:`${t}${r?"\u2514\u2500 ":"\u251C\u2500 "}`},...bg(n.children,`${t}${r?" ":"\u2502 "}`)]})}var Ln=(e,t)=>e.kind==="user"&&e.username===t,Fl=e=>`${e.image?"[\u56FE\u7247]":"[\u9644\u4EF6]"} ${st(e.name)}`;function jt(e){let t=new Set;return Wu(e).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}var Ww=e=>Sc(e,t=>Fl(t).replace(jw,"\\$&")),ui=(e,t)=>hn(Ww(e),t);function wo(e){let t=Sc(e,n=>n.image?"[\u56FE\u7247]":`[\u9644\u4EF6] ${n.name}`).slice(0,qw).replace(Hw,"");return st(gd(Bw.lex(t,{gfm:!0,breaks:!0}))).trim()}var Vw=e=>st(e).trim().replace(Uw,"\\$&");function di(e,t){if(t.length===0)return e;let n=t.map(o=>`${o.image===null?"":"!"}[${Vw(o.fileName)}](${Uu(o.id)})`).join(`
16
16
  `);return e===""?n:`${e}
17
17
 
18
- ${n}`}import{Fragment as Xw,jsx as me,jsxs as Ln}from"react/jsx-runtime";var Ww={cli:"\u547D\u4EE4\u884C",mobile:"\u624B\u673A",tablet:"\u5E73\u677F",smarttv:"\u667A\u80FD\u7535\u89C6",console:"\u6E38\u620F\u4E3B\u673A",wearable:"\u53EF\u7A7F\u6234\u8BBE\u5907",embedded:"\u5D4C\u5165\u5F0F\u8BBE\u5907"},yg="\u5BC6\u94A5 ",zw=10,Vw={rebind:{title:"\u91CD\u65B0\u7ED1\u5B9A\u4E24\u6B65\u9A8C\u8BC1",submit:"\u7EE7\u7EED",hint:"\u786E\u8BA4\u540E\u751F\u6210\u65B0\u5BC6\u94A5\uFF0C\u9A8C\u8BC1\u5668\u4E2D\u539F\u6709\u6761\u76EE\u5C06\u5931\u6548\uFF0C\u6062\u590D\u7801\u4E5F\u4F1A\u66F4\u6362"},regenerate:{title:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",submit:"\u751F\u6210",hint:"\u751F\u6210\u540E\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},disable:{title:"\u505C\u7528\u4E24\u6B65\u9A8C\u8BC1",submit:"\u505C\u7528",hint:"\u505C\u7528\u540E\u767B\u5F55\u4E0D\u518D\u8981\u6C42\u52A8\u6001\u7801\uFF0C\u6062\u590D\u7801\u540C\u65F6\u4F5C\u5E9F"}},Kw=3,Yw=8;function Jw({codes:e,width:t}){let n=Math.max(...e.map(r=>r.length))+4,o=[];for(let r=0;r<e.length;r+=2)o.push(Ln(fi,{wrap:"truncate",color:p.accent,children:[Qe(e[r]??"",Math.min(n,t)),e[r+1]??""]},r));return me(bt,{flexDirection:"column",children:o})}function bg(){let e=L(),{width:t,columns:n,rows:o}=H(),r=te(),[i,s]=hg({name:"menu"}),[a,c]=hg(!1),{busy:l,error:u,reset:m,fail:f,run:d}=le(),h=ee([e.revision],async()=>{let[b,S,v]=await Promise.all([An(),_f(),vf()]);return{user:b.user,security:S,sessions:v.sessions}}),y=ee([e.revision],async()=>{let[b,S]=await Promise.all([An(),af()]);return{homepage:await vl(b.user.username),todo:S}});G(b=>{i.name==="menu"&&l===null&&b==="r"&&e.reload()}),Ce(i.name==="codes"||l!==null);let g=()=>{if(i.name!=="codes"){if(i.name==="menu"){e.pop();return}m(),i.name==="passkey-rename"||i.name==="passkey-delete"?s({name:"passkey",item:i.item}):i.name==="confirm-revoke"?s({name:"session",item:i.item}):s({name:"menu"})}},x=b=>{s({name:"menu"}),e.reload(),e.toast("ok",b)},T=(b,S)=>{c(!1),s({name:"codes",codes:b,message:S})},R=(b,S)=>{b==="rebind"?d("\u6B63\u5728\u751F\u6210\u65B0\u5BC6\u94A5",()=>Rl({code:S}),{onSuccess:v=>s({name:"enroll",setup:v})}):b==="regenerate"?d("\u6B63\u5728\u751F\u6210\u6062\u590D\u7801",()=>Ef({code:S}),{onSuccess:({recoveryCodes:v})=>T(v,"\u6062\u590D\u7801\u5DF2\u66F4\u65B0")}):d("\u6B63\u5728\u505C\u7528",()=>Af({code:S}),{onSuccess:()=>x("\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u505C\u7528")})};return me(K,{hints:i.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","r \u5237\u65B0"]:i.name==="codes"?["\u2191\u2193 \u79FB\u52A8","Enter \u786E\u8BA4"]:["Esc \u8FD4\u56DE"],locked:i.name==="codes",onEscape:g,isActive:l===null,children:me(W,{state:h,loading:"\u6B63\u5728\u8BFB\u53D6\u8D26\u6237\u4FE1\u606F",width:t,children:({user:b,security:S,sessions:v})=>{if(i.name==="avatar")return me(ne,{title:"\u4FEE\u6539\u5934\u50CF",width:t,submitLabel:"\u4E0A\u4F20",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4E0A\u4F20",error:u,fields:[{kind:"text",name:"path",label:"\u56FE\u7247\u8DEF\u5F84",placeholder:"\u672C\u5730\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84"}],onCancel:g,onSubmit:k=>{let X=(k.path??"").trim();if(X===""){f("\u8BF7\u8F93\u5165\u56FE\u7247\u8DEF\u5F84");return}let F;try{F=Uf(X,Dr)}catch(re){f(xe(re));return}d("\u6B63\u5728\u4E0A\u4F20",()=>Lf(F),{onSuccess:()=>x("\u5934\u50CF\u5DF2\u66F4\u65B0")})}});if(i.name==="avatar-delete")return me(Ae,{width:t,title:"\u786E\u8BA4\u5220\u9664\u5934\u50CF\uFF1F",detail:"\u5220\u9664\u540E\u663E\u793A\u9ED8\u8BA4\u5934\u50CF",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Of(),{onSuccess:()=>x("\u5934\u50CF\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="rename")return me(ne,{title:"\u4FEE\u6539\u7528\u6237\u540D",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",initial:b.username,placeholder:"\u8BF7\u8F93\u5165\u65B0\u7528\u6237\u540D"}],onCancel:g,onSubmit:k=>{let X=(k.username??"").trim();if(X===""||X.length>Kt){f(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>xf({username:X}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="email")return me(ne,{title:"\u4FEE\u6539\u90AE\u7BB1",width:t,submitLabel:"\u786E\u8BA4\u4FEE\u6539",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"email",label:"\u65B0\u90AE\u7BB1",placeholder:"\u7528\u4E8E\u767B\u5F55\u4E0E\u63A5\u6536\u901A\u77E5\u7684\u65B0\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",emailField:"email",send:k=>wf({email:k})},{kind:"text",name:"password",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u7ACB\u5373\u4EE5\u65B0\u90AE\u7BB1\u767B\u5F55\u548C\u63A5\u6536\u901A\u77E5\uFF0C\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"}],onCancel:g,onSubmit:k=>{let X=(k.email??"").trim(),F=(k.code??"").trim(),re=k.password??"";if(X===""||F===""||re===""){f("\u8BF7\u586B\u5199\u65B0\u90AE\u7BB1\u3001\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801");return}d("\u6B63\u5728\u4FDD\u5B58",()=>kf({email:X,code:F,password:re}),{onSuccess:()=>x("\u90AE\u7BB1\u5DF2\u4FEE\u6539")})}});if(i.name==="password")return me(ne,{title:"\u4FEE\u6539\u5BC6\u7801",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"old",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801"},{kind:"text",name:"next",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u65B0\u5BC6\u7801",hint:`\u81F3\u5C11 ${Ot} \u4F4D\uFF0C\u4FDD\u5B58\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55`}],onCancel:g,onSubmit:k=>{let X=k.old??"",F=k.next??"";if(X===""){f("\u8BF7\u586B\u5199\u5F53\u524D\u5BC6\u7801");return}if(F.length<Ot){f(`\u65B0\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>Tf({oldPassword:X,newPassword:F}),{onSuccess:()=>x("\u5BC6\u7801\u5DF2\u4FEE\u6539")})}});if(i.name==="confirm-logout-all")return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u6240\u6709\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",detail:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u9000\u51FA",()=>Cf(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u6240\u6709\u8BBE\u5907"),e.home()}}),onCancel:g});if(i.name==="code"){let k=Vw[i.intent];return me(ne,{title:k.title,width:t,submitLabel:k.submit,busy:l!==null,busyLabel:l??"\u6B63\u5728\u5904\u7406",error:u,fields:[{kind:"text",name:"code",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",placeholder:"\u9A8C\u8BC1\u5668\u663E\u793A\u7684 6 \u4F4D\u6570\u5B57",hint:k.hint}],onCancel:g,onSubmit:X=>{let F=(X.code??"").trim();if(F===""){f("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}R(i.intent,F)}})}if(i.name==="enroll"){let k=(F,re)=>Ln(Xw,{children:[re&&me(fi,{color:p.mutedForeground,children:"\u4F7F\u7528 Google Authenticator \u7B49\u9A8C\u8BC1\u5668 App \u626B\u7801\u6DFB\u52A0"}),Ln(fi,{children:[me(fi,{color:p.mutedForeground,children:yg}),me(fi,{color:p.accent,children:i.setup.secret})]}),me(bt,{marginTop:1,children:me(ne,{title:"\u586B\u5165\u52A8\u6001\u9A8C\u8BC1\u7801\u5B8C\u6210\u7ED1\u5B9A",width:F,submitLabel:"\u7ED1\u5B9A",busy:l!==null,busyLabel:l??"\u6B63\u5728\u7ED1\u5B9A",error:u,fields:[{kind:"text",name:"code",label:"\u52A8\u6001\u9A8C\u8BC1\u7801"}],onCancel:g,onSubmit:B=>{let z=(B.code??"").trim();if(z===""){f("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}d("\u6B63\u5728\u7ED1\u5B9A",()=>Pf({code:z}),{onSuccess:({recoveryCodes:Y})=>T(Y,"\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u7ED1\u5B9A")})}})})]}),X=qs(i.setup.otpauthUri,{width:t,rows:r},{columns:Gw(yg)+i.setup.secret.length,rows:zw},{columns:n-t,rows:o-r});return X.fits?me(Gs,{value:i.setup.otpauthUri,aside:k(X.asideWidth,!0)}):Ln(bt,{flexDirection:"column",children:[me(he,{tone:"info",width:t,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u6539\u4E3A\u624B\u52A8\u5F55\u5165",detail:"\u5728\u9A8C\u8BC1\u5668\u4E2D\u9009\u62E9\u624B\u52A8\u8F93\u5165\uFF0C\u586B\u5165\u4E0B\u65B9\u5BC6\u94A5"}),k(t,!1)]})}if(i.name==="codes")return Ln(bt,{flexDirection:"column",children:[me(he,{tone:"warn",width:t,title:"\u6062\u590D\u7801\u4EC5\u6B64\u4E00\u6B21\u5C55\u793A\uFF0C\u8BF7\u7ACB\u5373\u4FDD\u5B58\u5230\u5B89\u5168\u7684\u4F4D\u7F6E",detail:"\u6BCF\u679A\u6062\u590D\u7801\u53EA\u80FD\u4F7F\u7528\u4E00\u6B21\uFF0C\u53EF\u5728\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u4EE3\u66FF\u52A8\u6001\u9A8C\u8BC1\u7801\u767B\u5F55"}),me(bt,{marginTop:1,children:me(Jw,{codes:i.codes,width:t})}),me(bt,{marginTop:1,children:me(ce,{width:t,items:[{value:"ack",label:`${a?"[x]":"[ ]"} \u6211\u5DF2\u59A5\u5584\u4FDD\u5B58\u8FD9\u4E9B\u6062\u590D\u7801`},{value:"done",label:"\u5B8C\u6210",disabled:!a}],onSelect:k=>{if(k==="ack"){c(F=>!F);return}let X=i.message;s({name:"menu"}),e.reload(),e.toast("ok",X)}})})]});if(i.name==="passkey-add")return me(he,{tone:"info",width:t,title:`\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00 ${e.ctx.site} \u7684\u300C\u4E2A\u4EBA\u4E3B\u9875\u300D\u5B8C\u6210\u6DFB\u52A0`,detail:"\u6DFB\u52A0\u4E0E\u4F7F\u7528 Passkey \u4F9D\u8D56\u6D4F\u89C8\u5668\u7684 WebAuthn \u80FD\u529B\uFF0C\u7EC8\u7AEF\u65E0\u6CD5\u5B8C\u6210"});if(i.name==="passkey-rename")return me(ne,{title:`\u91CD\u547D\u540D Passkey ${i.item.name}`,width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:i.item.name,placeholder:"\u6807\u8BB0\u6240\u5728\u8BBE\u5907\uFF0C\u5982 MacBook \u6307\u7EB9"}],onCancel:g,onSubmit:k=>{let X=(k.name??"").trim();if(X===""){f("\u8BF7\u8F93\u5165\u540D\u79F0");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Mf(i.item.id,{name:X}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="passkey-delete")return me(Ae,{width:t,title:`\u786E\u8BA4\u5220\u9664 Passkey\u300C${i.item.name}\u300D\uFF1F`,detail:"\u5220\u9664\u540E\u65E0\u6CD5\u518D\u7528\u5B83\u767B\u5F55",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>If(i.item.id),{onSuccess:()=>x("\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="passkey"){let k=i.item;return me(bt,{flexDirection:"column",children:Ln(de,{title:`Passkey ${k.name}`,width:t,children:[me(Ye,{width:t-pe,items:[["\u540D\u79F0",k.name],["\u6DFB\u52A0\u65F6\u95F4",V(k.createdAt)],["\u6700\u8FD1\u4F7F\u7528",k.lastUsedAt===null?"\u2014":V(k.lastUsedAt)]]}),me(bt,{marginTop:1,children:me(ce,{width:t-pe,items:[{value:"rename",label:"\u91CD\u547D\u540D"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:X=>{m(),s(X==="rename"?{name:"passkey-rename",item:k}:{name:"passkey-delete",item:k})}})})]})})}if(i.name==="confirm-revoke"){let k=i.item;return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u8BE5\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>{if(k.current){d("\u6B63\u5728\u9000\u51FA",()=>os(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u767B\u5F55"),e.home()}});return}d("\u6B63\u5728\u9000\u51FA\u8BE5\u8BBE\u5907",()=>Rf(k.id),{onSuccess:()=>x("\u5DF2\u9000\u51FA\u8BE5\u8BBE\u5907")})},onCancel:g})}if(i.name==="session"){let k=i.item;return Ln(bt,{flexDirection:"column",children:[me(de,{title:qo(k.device),note:k.current?"\u5F53\u524D\u8BBE\u5907":void 0,width:t,children:me(Ye,{width:t-pe,items:[["\u8BBE\u5907\u7C7B\u578B",k.device?.type!=null?Ww[k.device.type]??k.device.type:"\u684C\u9762\u8BBE\u5907"],["\u5BA2\u6237\u7AEF",k.device?.client!=null?`${k.device.client} ${k.device.clientVersion??""}`.trim():"\u2014"],["\u64CD\u4F5C\u7CFB\u7EDF",k.device?.os!=null?`${k.device.os} ${k.device.osVersion??""}`.trim():"\u2014"],["\u8BBE\u5907\u578B\u53F7",k.device?.model!=null?`${k.device.vendor??""} ${k.device.model}`.trim():"\u2014"],["IP \u5730\u5740",k.ip],["\u767B\u5F55\u65F6\u95F4",V(k.loginAt)],["\u6700\u540E\u6D3B\u8DC3",V(k.lastActiveAt)],["\u767B\u5F55\u6709\u6548\u671F\u81F3",V(k.expiresAt)],["\u5BA2\u6237\u7AEF\u6807\u8BC6",k.userAgent??"\u2014"]]})}),l===null&&me(bt,{marginTop:1,children:me(ce,{width:t,items:[{value:"revoke",label:"\u9000\u51FA\u8BE5\u8BBE\u5907",labelTone:"danger"}],onSelect:()=>{m(),s({name:"confirm-revoke",item:k})}})})]})}let M=S.totp,N=y.phase==="ready"?y.data:null,O=N===null?null:N.todo,U=O===null?0:O.posts.filter(k=>k.status==="pending").length,C=O===null?0:O.posts.filter(k=>k.status==="rejected").length,w=_e([U>0&&`${U} \u7BC7\u5BA1\u6838\u4E2D`,C>0&&`${C} \u7BC7\u672A\u901A\u8FC7`]),E=[{heading:"\u793E\u533A"},{value:{kind:"my-posts"},label:"\u6211\u7684\u5E16\u5B50",hint:w===""?void 0:w},{value:{kind:"my-comments"},label:"\u6211\u7684\u8BC4\u8BBA"},{value:{kind:"bookmarks"},label:"\u6211\u7684\u6536\u85CF"},{value:{kind:"drafts"},label:"\u6211\u7684\u8349\u7A3F",hint:O!==null&&O.drafts>0?`${O.drafts} \u7BC7\u672A\u53D1\u5E03`:void 0},{heading:""},{heading:"\u8D26\u6237"},{value:{kind:"avatar"},label:"\u4FEE\u6539\u5934\u50CF",hint:"\u663E\u793A\u5728\u4E2A\u4EBA\u4E3B\u9875\u548C\u4F60\u7684\u53D1\u8A00\u4E2D"},{value:{kind:"rename"},label:"\u4FEE\u6539\u7528\u6237\u540D"},{value:{kind:"email"},label:"\u4FEE\u6539\u90AE\u7BB1",hint:"\u9700\u8981\u90AE\u7BB1\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801"},{value:{kind:"password"},label:"\u4FEE\u6539\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"},...b.avatarUrl===null?[]:[{value:{kind:"avatar-delete"},label:"\u5220\u9664\u5934\u50CF",labelTone:"danger"}],{heading:""},{heading:"\u4E24\u6B65\u9A8C\u8BC1"},...M.enabled?[{value:{kind:"code",intent:"rebind"},label:"\u91CD\u65B0\u7ED1\u5B9A",hint:"\u751F\u6210\u65B0\u5BC6\u94A5\u5E76\u66F4\u6362\u6062\u590D\u7801"},{value:{kind:"code",intent:"regenerate"},label:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",hint:"\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},{value:{kind:"code",intent:"disable"},label:"\u505C\u7528",labelTone:"danger"}]:[{value:{kind:"enable"},label:"\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",hint:"\u767B\u5F55\u65F6\u8981\u6C42\u989D\u5916\u8F93\u5165\u9A8C\u8BC1\u5668\u52A8\u6001\u7801"}],{heading:""},{heading:"Passkey"},...S.passkeys.length===0?[{value:{kind:"none"},label:"\u6682\u65E0 Passkey",hint:"\u6DFB\u52A0\u540E\u53EF\u4F7F\u7528\u6307\u7EB9\u3001\u9762\u5BB9\u6216\u786C\u4EF6\u5BC6\u94A5\u4E00\u6B65\u767B\u5F55",disabled:!0}]:[],...S.passkeys.map(k=>({value:{kind:"passkey",item:k},label:k.name,hint:`\u6700\u8FD1\u4F7F\u7528 ${k.lastUsedAt===null?"\u2014":V(k.lastUsedAt)}`})),{value:{kind:"add-passkey"},label:"\u6DFB\u52A0 Passkey",hint:"\u9700\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"},{heading:""},{heading:"\u767B\u5F55\u8BBE\u5907"},...v.map(k=>({value:{kind:"session",item:k},label:k.current?`${qo(k.device)}\uFF08\u5F53\u524D\u8BBE\u5907\uFF09`:qo(k.device),...k.current?{labelTone:"accent"}:{},hint:`${k.ip} \xB7 \u6700\u540E\u6D3B\u8DC3 ${V(k.lastActiveAt)}`})),{value:{kind:"logout-all"},label:"\u9000\u51FA\u6240\u6709\u8BBE\u5907",labelTone:"danger",hint:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA"}],_=N===null?null:N.homepage,A=[["\u7528\u6237\u540D",st(b.username)],["\u90AE\u7BB1",b.email],...M.enabled?[["\u4E24\u6B65\u9A8C\u8BC1",`\u542F\u7528\u4E8E ${M.enabledAt===null?"\u2014":V(M.enabledAt)}`],["\u6062\u590D\u7801",M.recoveryCodesRemaining===0?"\u5DF2\u5168\u90E8\u7528\u5B8C\uFF0C\u8BF7\u91CD\u65B0\u751F\u6210":`\u5269\u4F59 ${M.recoveryCodesRemaining} \u679A\uFF0C\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u53EF\u4EE3\u66FF\u52A8\u6001\u7801\u767B\u5F55`]]:[],..._===null?[]:[["\u7B49\u7EA7",Gi(_.identity.points)],["\u79EF\u5206",`${_.identity.points} \xB7 ${Wi(_.identity.points)}`],["\u52A0\u5165\u65F6\u95F4",jr(_.joinedAt)]]],$=y.phase==="error"?y:null,Z=_!==null?Ut(Kw,t)+Q:$!==null?($.hint===void 0?1:2)+Q:0,oe=Vs(A.length,t)+Q+Z,fe=Q+Ze+To,D=_!==null&&ar(t)&&r-oe-fe>=Yw;return Ln(bt,{flexDirection:"column",children:[me(Ye,{width:t,items:A}),_!==null&&me(bt,{marginTop:Q,children:me(it,{width:t,tiles:[{label:"\u5E16\u5B50",value:String(_.stats.posts)},{label:"\u8BC4\u8BBA",value:String(_.stats.comments)},{label:"\u83B7\u8D5E",value:String(_.stats.likesReceived)}]})}),$!==null&&me(bt,{marginTop:Q,children:me(Ft,{message:`\u793E\u533A\u6570\u636E\u8BFB\u53D6\u5931\u8D25\uFF1A${$.message}`,hint:$.hint,width:t})}),D&&Ln(bt,{marginTop:Q,flexDirection:"column",children:[me(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:t}),me(bt,{marginTop:We,flexDirection:"column",children:me(cr,{data:_.activity,value:k=>k.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${_.activity.days.reduce((k,X)=>k+X.count,0)} \u6B21`,width:t})})]}),me(bt,{marginTop:Q,children:me(ce,{width:t,height:Math.max(3,r-oe-(D?fe:0)),isActive:l===null,items:E,retain:"menu",onSelect:k=>{m(),k.kind==="my-posts"?e.push("my-posts",{username:b.username}):k.kind==="my-comments"?e.push("my-comments",{username:b.username}):k.kind==="bookmarks"?e.push("bookmarks"):k.kind==="drafts"?e.push("drafts"):k.kind==="avatar"?s({name:"avatar"}):k.kind==="avatar-delete"?s({name:"avatar-delete"}):k.kind==="rename"?s({name:"rename"}):k.kind==="email"?s({name:"email"}):k.kind==="password"?s({name:"password"}):k.kind==="logout-all"?s({name:"confirm-logout-all"}):k.kind==="enable"?d("\u6B63\u5728\u751F\u6210\u5BC6\u94A5",()=>Rl({}),{failToast:!0,onSuccess:X=>s({name:"enroll",setup:X})}):k.kind==="code"?s({name:"code",intent:k.intent}):k.kind==="add-passkey"?s({name:"passkey-add"}):k.kind==="passkey"?s({name:"passkey",item:k.item}):k.kind==="session"&&s({name:"session",item:k.item})}})})]})}})})}import{Box as Zs,Text as ea,useInput as ik}from"ink";import{useRef as _g,useState as dr}from"react";import sk from"string-width";import{z as Rt}from"zod";var Qw=Rt.object({siteName:Rt.string(),apiLines:Rt.array(Rt.object({name:Rt.string(),description:Rt.string(),url:Rt.string()})),quotaPerUsd:Rt.number(),ticketAutoCloseMinutes:Rt.number(),legal:Rt.object({termsConfigured:Rt.boolean(),privacyConfigured:Rt.boolean()})});function ze(e,t){return fn(Qw,`${e}/api/site-config`,{...t===void 0?{}:{timeoutMs:t}})}var Zw=Rt.object({content:Rt.string(),configured:Rt.boolean()});function Sg(e,t){return fn(Zw,`${e}/api/agreements/${t}`)}var xg=12e4,Tg=e=>P(lt(Li),je("/tickets",{...e})),wg=e=>P(yu,"/tickets",{method:"POST",json:e}),Ul=e=>P(wu,`/tickets/${e}`),kg=(e,t,n)=>P(se,`/tickets/${e}/messages`,{method:"POST",json:{content:t,attachmentIds:n}}),ek=e=>P(Tu,je("/tickets/attachments",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:xg}),tk=e=>P(se,`/tickets/attachments/${e}`,{method:"DELETE"}),Xs={upload:ek,discard:tk},vg=(e,t)=>is(`/tickets/${e}/attachments/${t}`,{timeoutMs:xg}),Rg=e=>P(se,`/tickets/${e}/close`,{method:"POST"}),Cg=e=>P(se,`/tickets/${e}/reopen`,{method:"POST"});import{jsx as nk}from"react/jsx-runtime";function mr({title:e,width:t,download:n,onCancel:o,onSaved:r}){let{busy:i,error:s,run:a}=le();return nk(ne,{title:e,width:t,submitLabel:"\u4E0B\u8F7D",busy:i!==null,busyLabel:"\u6B63\u5728\u4E0B\u8F7D",error:s,fields:[{kind:"text",name:"path",label:"\u4FDD\u5B58\u8DEF\u5F84",placeholder:"\u7559\u7A7A\u4FDD\u5B58\u5230\u5F53\u524D\u76EE\u5F55",hint:"\u53EF\u586B\u76EE\u5F55\u6216\u5E26\u6587\u4EF6\u540D\u7684\u5B8C\u6574\u8DEF\u5F84",optional:!0}],onCancel:o,onSubmit:c=>{a("\u6B63\u5728\u4E0B\u8F7D",async()=>{let l=await n();return jf(c.path??"",l.fileName,l.bytes)},{onSuccess:r})}})}import{useEffect as ok,useRef as rk}from"react";function Qs(e,t,n=!0){let o=rk(t);o.current=t,ok(()=>{if(!n)return;let r=!1,i=setInterval(()=>{r||(r=!0,o.current().catch(()=>{}).finally(()=>{r=!1}))},e);return()=>clearInterval(i)},[e,n])}var ur={maxCount:Su,maxBytes:bu},Zn=e=>({kind:"textarea",name:"attachments",label:"\u9644\u4EF6\u8DEF\u5F84",rows:2,placeholder:"\u6BCF\u884C\u4E00\u4E2A\u672C\u5730\u6587\u4EF6\u8DEF\u5F84\uFF0C\u53EF\u7559\u7A7A",hint:`\u6700\u591A ${e.maxCount} \u4E2A\uFF0C\u5355\u4E2A\u4E0D\u8D85\u8FC7 ${e.maxBytes/1024/1024}MB`,optional:!0});import{jsx as Ht,jsxs as jl}from"react/jsx-runtime";var ak=5e3,ck=11,lk=3,Pg=1;function mk(e,t){let n=[],o=r=>{let i=r.spans.reduce((a,c)=>a+sk(c.text),0),s=Math.max(0,t-i);return s===0?r:{spans:[{text:" ".repeat(s)},...r.spans]}};return e.forEach((r,i)=>{i>0&&n.push({spans:[]});let s=r.author.kind==="user",a={spans:[{text:vt(r.author),color:s?p.accent:p.mutedForeground},{text:` ${V(r.createdAt)}`,color:p.faintForeground}]},c=r.content===""?[]:Pt([{text:Vn(r.content),color:p.foreground}],Math.max(8,t-4)),l=r.attachments.map(u=>({spans:[{text:"[\u9644\u4EF6] ",color:p.faintForeground},{text:u.fileName,color:p.foreground},{text:` (${Vo(u.fileSize)})`,color:p.mutedForeground}]}));s?n.push(o(a),...c.map(o),...l.map(o)):n.push(a,...c,...l)}),n}function Ag({params:e}){let t=L(),{width:n}=H(),o=te(),[r,i]=dr("main"),[s,a]=dr(!1),[c,l]=dr(null),[u,m]=dr(null),[f,d]=dr(0),{busy:h,error:y,reset:g,fail:x,run:T}=le();Ce(h!==null);let R=ee([e.id,t.revision],async()=>{let[_,A]=await Promise.all([Ul(e.id),ze(t.ctx.site)]);return{detail:_,site:A}}),[b,S]=dr(null),v=_g(0),M=_g(t.revision);M.current!==t.revision&&(M.current=t.revision,v.current+=1,b!==null&&S(null));let N=R.phase==="ready"?R.data:null,O=b??N?.detail??null;Qs(ak,async()=>{if(O===null||h!==null)return;let _=v.current,A=await Ul(e.id);_===v.current&&(A.ticket.updatedAt!==O.ticket.updatedAt||A.messages.length!==O.messages.length)&&S(A)},r==="main"&&N!==null);let U=O?.messages.some(_=>_.attachments.length>0)??!1;G(_=>{r!=="main"||s||h!==null||(_==="r"?t.reload():_==="x"&&O!==null&&O.ticket.status!=="closed"?(g(),i("confirm-close")):_==="a"&&U&&(g(),l(null),m(null),i("attachments")))}),ik((_,A)=>{A.tab&&r==="main"&&!s&&O?.ticket.status!=="closed"&&a(!0)},{isActive:r==="main"&&!s&&h===null});let C=()=>{if(r!=="main"){g(),i("main");return}if(s){a(!1);return}t.pop()},w=(_,A)=>{T("\u6B63\u5728\u53D1\u9001",()=>En(A,Xs,$=>kg(e.id,_,$.map(Z=>Z.id))),{onSuccess:()=>{a(!1),d($=>$+1),t.reload(),t.toast("ok","\u5DF2\u53D1\u9001")}})},E=r==="main"&&!s?["\u2191\u2193 \u6EDA\u52A8",...O?.ticket.status==="closed"?[]:["Tab \u56DE\u590D"],...U?["a \u9644\u4EF6"]:[],...O?.ticket.status==="closed"?[]:["x \u5173\u95ED\u5DE5\u5355"],"r \u5237\u65B0"]:[];return Ht(K,{trail:["\u5DE5\u5355\u652F\u6301",O?.ticket.title??"\u5DE5\u5355\u8BE6\u60C5"],hints:E,onEscape:C,isActive:h===null,children:Ht(W,{state:R,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:n,children:({site:_,detail:A})=>{let $=b??A,Z=$.ticket,oe=Z.status==="closed";if(r==="confirm-close")return Ht(Ae,{width:n,title:"\u5173\u95ED\u5DE5\u5355",detail:`\u786E\u5B9A\u5173\u95ED\u5DE5\u5355\u300C${Z.title}\u300D\u5417\uFF1F\u5173\u95ED\u540E\u53EF\u91CD\u65B0\u6253\u5F00`,confirmLabel:"\u5173\u95ED\u5DE5\u5355",busy:h,error:y,onConfirm:()=>T("\u6B63\u5728\u5173\u95ED",()=>Rg(e.id),{onSuccess:()=>{i("main"),t.reload(),t.toast("ok","\u5DF2\u5173\u95ED")}}),onCancel:C});if(r==="attachments")return u!==null?Ht(mr,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${u.fileName}`,width:n,download:async()=>({fileName:u.fileName,bytes:await vg(e.id,u.id)}),onCancel:()=>m(null),onSaved:X=>{m(null),l(X),t.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):jl(Zs,{flexDirection:"column",children:[Ht(ce,{width:n,height:Math.max(3,o-1),isActive:h===null,items:[{heading:"\u9644\u4EF6"},...$.messages.flatMap(X=>X.attachments.map(F=>({value:F,label:F.fileName,hint:`${vt(X.author)} \xB7 ${Vo(F.fileSize)} \xB7 ${V(X.createdAt)}`})))],onSelect:X=>{l(null),m(X)}}),c!==null&&Ht(ea,{wrap:"truncate",color:p.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${c}`})]});let fe=_.ticketAutoCloseMinutes>0?Pg:0,D=oe?lk:s?ck:Pg,k=Math.max(3,o-fe-D-Q);return jl(Zs,{flexDirection:"column",children:[fe>0&&Ht(ea,{wrap:"truncate",color:p.faintForeground,children:`\u7BA1\u7406\u5458\u56DE\u590D\u540E\u8D85\u8FC7 ${_.ticketAutoCloseMinutes} \u5206\u949F\u672A\u56DE\u5E94\uFF0C\u5DE5\u5355\u5C06\u81EA\u52A8\u5173\u95ED\uFF1B\u5DF2\u5173\u95ED\u7684\u5DE5\u5355\u53EF\u968F\u65F6\u91CD\u65B0\u6253\u5F00`}),Ht(dt,{lines:mk($.messages,n),height:k,isActive:!s&&h===null,pinBottom:!0}),Ht(Zs,{marginTop:1,flexDirection:"column",children:oe?jl(Zs,{flexDirection:"column",children:[Ht(ea,{color:p.mutedForeground,children:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u5982\u9700\u7EE7\u7EED\u6C9F\u901A\u53EF\u91CD\u65B0\u6253\u5F00"}),Ht(ce,{width:n,isActive:h===null,items:[{value:"reopen",label:"\u91CD\u65B0\u6253\u5F00"}],onSelect:()=>T("\u6B63\u5728\u91CD\u65B0\u6253\u5F00",()=>Cg(e.id),{failToast:!0,onSuccess:()=>{t.reload(),t.toast("ok","\u5DF2\u91CD\u65B0\u6253\u5F00")}})})]}):s?Ht(ne,{title:"\u56DE\u590D\u5DE5\u5355",width:n,submitLabel:"\u53D1\u9001\u56DE\u590D",busy:h!==null,busyLabel:h??"\u6B63\u5728\u53D1\u9001",error:y,fields:[{kind:"textarea",name:"content",label:"\u56DE\u590D\u5185\u5BB9",rows:3,maxLength:5e3,placeholder:"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9",optional:!0},Zn(ur)],onCancel:()=>a(!1),onSubmit:X=>{let F=(X.content??"").trim(),re;try{re=Jn(X.attachments??"",ur)}catch(B){x(xe(B));return}if(F===""&&re.length===0){x("\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9\u6216\u9644\u4EF6\u8DEF\u5F84");return}w(F,re)}},f):Ht(ea,{color:p.faintForeground,children:"\u6309 Tab \u64B0\u5199\u56DE\u590D"})})]})}})})}import{Box as uk}from"ink";import{useState as dk}from"react";import{jsx as ko,jsxs as gk}from"react/jsx-runtime";var pk=_t(nc,Hc,"\u5168\u90E8\u72B6\u6001"),fk={title:"\u7B80\u8981\u63CF\u8FF0\u4F60\u7684\u95EE\u9898",content:"\u8BE6\u7EC6\u63CF\u8FF0\u9047\u5230\u7684\u95EE\u9898\uFF0C\u4FBF\u4E8E\u7BA1\u7406\u5458\u5FEB\u901F\u5B9A\u4F4D"},Hl={billing:{title:"\u7B80\u8FF0\u8BA1\u8D39\u6216\u989D\u5EA6\u7591\u95EE",content:"\u8BF4\u660E\u7591\u95EE\u6D89\u53CA\u7684\u65F6\u95F4\u6BB5\u3001\u6A21\u578B\u4E0E\u9884\u671F\u5DEE\u5F02\uFF0C\u53EF\u9644\u989D\u5EA6\u6D41\u6C34\u6216\u4F7F\u7528\u65E5\u5FD7\u4E2D\u7684\u8BB0\u5F55"},technical:{title:"\u7B80\u8FF0\u63A5\u53E3\u6216\u8C03\u7528\u95EE\u9898",content:"\u63CF\u8FF0\u62A5\u9519\u73B0\u8C61\u4E0E\u590D\u73B0\u6B65\u9AA4\uFF0C\u9644\u8BF7\u6C42 ID\u3001\u6A21\u578B\u540D\u3001\u53D1\u751F\u65F6\u95F4\u7B49\u4FE1\u606F"},account:{title:"\u7B80\u8FF0\u8D26\u53F7\u76F8\u5173\u95EE\u9898",content:"\u63CF\u8FF0\u767B\u5F55\u3001\u90AE\u7BB1\u6216\u5B89\u5168\u76F8\u5173\u7684\u5177\u4F53\u95EE\u9898\uFF0C\u5207\u52FF\u586B\u5199\u5BC6\u7801\u7B49\u654F\u611F\u4FE1\u606F"},other:fk};function Eg(){let e=L(),{width:t}=H(),n=te(),[o,r]=dk({name:"list"}),[i,s]=Ie("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=le(),f=Ve([e.revision,i],y=>Tg({page:y,...i===""?{}:{status:i}}),{retain:"page"}),d=o.name==="list";G((y,g)=>{d&&(y==="r"?e.reload():y==="f"?r({name:"filter"}):y==="n"?r({name:"create-category"}):g.leftArrow?f.go(-1):g.rightArrow&&f.go(1))});let h=()=>{o.name==="list"?e.pop():o.name==="create"?r({name:"create-category"}):(l(),r({name:"list"}))};return ko(K,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u65B0\u5EFA","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:h,children:o.name==="filter"?ko(ne,{title:"\u7B5B\u9009\u5DE5\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:pk,initial:i}],onCancel:h,onSubmit:y=>{s(y.status??""),f.reset(),r({name:"list"})}}):o.name==="create-category"?ko(ce,{width:t,height:n,items:[{heading:"\u5206\u7C7B"},...oc.map(y=>({value:y,label:Xi(y),hint:Hl[y].title}))],onSelect:y=>r({name:"create",category:y})}):o.name==="create"?ko(ne,{title:`\u65B0\u5EFA\u5DE5\u5355 \u2014 ${Xi(o.category)}`,width:t,submitLabel:"\u63D0\u4EA4",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"select",name:"priority",label:"\u4F18\u5148\u7EA7",options:rc.map(y=>({value:y,label:qc(y).label})),initial:"normal"},{kind:"text",name:"title",label:"\u6807\u9898",placeholder:Hl[o.category].title},{kind:"textarea",name:"content",label:"\u95EE\u9898\u63CF\u8FF0",rows:5,maxLength:5e3,placeholder:Hl[o.category].content},Zn(ur)],onCancel:h,onSubmit:y=>{let g=(y.title??"").trim(),x=(y.content??"").trim();if(g===""){u("\u8BF7\u586B\u5199\u6807\u9898");return}if(x===""){u("\u8BF7\u586B\u5199\u95EE\u9898\u63CF\u8FF0");return}let T;try{T=Jn(y.attachments??"",ur)}catch(R){u(xe(R));return}m("\u6B63\u5728\u63D0\u4EA4\u5DE5\u5355",()=>En(T,Xs,R=>wg({title:g,category:o.category,priority:y.priority??"normal",content:x,attachmentIds:R.map(b=>b.id)})),{onSuccess:R=>{r({name:"list"}),f.reset(),e.reload(),e.push("ticket",{id:R.id}),e.toast("ok","\u5DE5\u5355\u5DF2\u63D0\u4EA4")}})}}):ko(W,{state:f.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:t,children:y=>gk(uk,{flexDirection:"column",children:[ko(ue,{retain:"list",items:y.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u4F18\u5148\u7EA7"},{label:"\u5206\u7C7B"},{label:"\u6700\u540E\u66F4\u65B0"},{label:"\u72B6\u6001",align:"right"}],row:g=>[g.title,yt(qc(g.priority)),Xi(g.category),V(g.updatedAt),yt(Hc(g.status))],onOpen:g=>e.push("ticket",{id:g.id}),emptyLabel:i===""?"\u6682\u65E0\u5DE5\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u9047\u5230\u95EE\u9898\u65F6\u53EF\u65B0\u5EFA\u5DE5\u5355\uFF0C\u7BA1\u7406\u5458\u4F1A\u5C3D\u5FEB\u56DE\u590D":void 0}),ko(Ke,{page:f.page,pages:f.pages,total:f.total,width:t})]})})})}import{Box as hk}from"ink";import{jsx as gi}from"react/jsx-runtime";function Mg({params:e}){let t=L(),{width:n}=H(),o=te(),r=ee([e.type,t.revision],()=>Sg(t.ctx.site,e.type));return gi(K,{trail:["\u6CD5\u5F8B\u6761\u6B3E",e.type==="terms"?"\u7528\u6237\u534F\u8BAE":"\u9690\u79C1\u653F\u7B56"],hints:["\u2191\u2193 \u6EDA\u52A8"],children:gi(W,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6761\u6B3E",width:n,children:i=>i.configured?gi(hk,{flexDirection:"column",children:gi(dt,{lines:hn(i.content,n),height:o})}):gi(he,{tone:"info",width:n,title:"\u8BE5\u6761\u6B3E\u5C1A\u672A\u914D\u7F6E"})})})}var Ig=(e,t)=>fn(se,`${e}/api/auth/send-code`,{json:t});async function Ng(e,t){let n=await Jt(`${e}/api/auth/register`,{json:t});sn(n);let o=Go.parse(n.data);return Vr(e,zr({refresh:null,device:null},n.headers),o)}var Lg=(e,t)=>fn(se,`${e}/api/auth/forgot-password`,{json:t}),Og=(e,t)=>fn(se,`${e}/api/auth/reset-password`,{json:t});import{jsx as Dg}from"react/jsx-runtime";function $g(){let e=L(),{width:t}=H(),{busy:n,error:o,fail:r,run:i}=le();return Ce(n!==null),Dg(K,{trail:["\u627E\u56DE\u5BC6\u7801"],isActive:n===null,children:Dg(ne,{title:"\u91CD\u7F6E\u5BC6\u7801",width:t,submitLabel:"\u63D0\u4EA4",busy:n!==null,busyLabel:n??"\u6B63\u5728\u91CD\u7F6E",error:o,fields:[{kind:"text",name:"email",label:"\u90AE\u7BB1",placeholder:"\u8BF7\u8F93\u5165\u6CE8\u518C\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",placeholder:"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801",emailField:"email",send:s=>Lg(e.ctx.site,{email:s})},{kind:"text",name:"password",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`,hint:"\u91CD\u7F6E\u540E\u6240\u6709\u8BBE\u5907\u90FD\u9700\u91CD\u65B0\u767B\u5F55"}],onCancel:()=>e.pop(),onSubmit:s=>{let a=(s.email??"").trim(),c=(s.code??"").trim(),l=s.password??"";if(a===""||c===""){r("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(l.length<Ot){r(`\u65B0\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}i("\u6B63\u5728\u91CD\u7F6E",()=>Og(e.ctx.site,{email:a,code:c,password:l}),{onSuccess:()=>{e.toast("ok","\u5BC6\u7801\u5DF2\u91CD\u7F6E\uFF0C\u8BF7\u767B\u5F55"),e.pop()}})}})})}import{Box as Gl,Text as bk}from"ink";import{useState as Fg}from"react";import{Box as Bg}from"ink";import{jsx as ql,jsxs as yk}from"react/jsx-runtime";var ta=e=>e.termsConfigured||e.privacyConfigured;function na({legal:e,width:t,onAgree:n}){let o=L(),r=[e.termsConfigured?"\u300A\u7528\u6237\u534F\u8BAE\u300B":"",e.privacyConfigured?"\u300A\u9690\u79C1\u653F\u7B56\u300B":""].filter(s=>s!==""),i=[{value:"agree",label:"\u6211\u5DF2\u9605\u8BFB\u5E76\u540C\u610F\uFF0C\u7EE7\u7EED",hint:r.join("\u4E0E")},...e.termsConfigured?[{value:"terms",label:"\u67E5\u770B\u7528\u6237\u534F\u8BAE"}]:[],...e.privacyConfigured?[{value:"privacy",label:"\u67E5\u770B\u9690\u79C1\u653F\u7B56"}]:[],{value:"back",label:"\u8FD4\u56DE"}];return yk(Bg,{flexDirection:"column",children:[ql(he,{tone:"info",width:t,title:`\u7EE7\u7EED\u524D\u8BF7\u9605\u8BFB\u5E76\u540C\u610F${r.join("\u4E0E")}`}),ql(Bg,{marginTop:1,children:ql(ce,{items:i,width:t,onSelect:s=>{s==="agree"?n():s==="terms"?o.push("agreement",{type:"terms"}):s==="privacy"?o.push("agreement",{type:"privacy"}):o.pop()}})})]})}import{jsx as eo,jsxs as Ug}from"react/jsx-runtime";function jg(){let e=L(),{width:t}=H(),[n,o]=Fg({name:"credentials"}),[r,i]=Fg(!1),{busy:s,error:a,reset:c,fail:l,run:u}=le(),m=ee([e.revision],()=>ze(e.ctx.site)),f=g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u5DF2\u767B\u5F55\uFF1A${g}`),e.home()},d=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Id(e.ctx.site,g,x),{onSuccess:T=>{if(T.status==="totp_required"){o({name:"factor",ticket:T.ticket,jar:T.jar});return}f(T.session.username)}})},h=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Nd(e.ctx.site,g.jar,g.ticket,x,g.kind),{onSuccess:T=>f(T.username)})},y=()=>{n.name==="credentials"?e.pop():(c(),o({name:"credentials"}))};return Ug(K,{trail:n.name==="credentials"?["\u767B\u5F55\u8D26\u53F7"]:["\u767B\u5F55\u8D26\u53F7","\u4E24\u6B65\u9A8C\u8BC1"],onEscape:y,isActive:s===null,children:[n.name==="credentials"&&eo(W,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:g=>ta(g.legal)&&!r?eo(na,{legal:g.legal,width:t,onAgree:()=>i(!0)}):Ug(Gl,{flexDirection:"column",children:[eo(ne,{title:"\u767B\u5F55",width:t,submitLabel:"\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"account",label:"\u8D26\u53F7",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1"},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5BC6\u7801"}],onCancel:y,onSubmit:x=>{let T=(x.account??"").trim(),R=x.password??"";if(T===""||R===""){l("\u8BF7\u586B\u5199\u8D26\u53F7\u4E0E\u5BC6\u7801");return}d(T,R)}}),eo(Gl,{marginTop:1,children:eo(bk,{color:p.faintForeground,children:"Passkey \u767B\u5F55\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"})})]})}),n.name==="factor"&&eo(ce,{width:t,items:[{value:"totp",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",hint:"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801"},{value:"recovery-code",label:"\u6062\u590D\u7801",hint:"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onSelect:g=>o({name:"code",ticket:n.ticket,jar:n.jar,kind:g})}),n.name==="code"&&eo(Gl,{flexDirection:"column",children:eo(ne,{title:"\u4E24\u6B65\u9A8C\u8BC1",width:t,submitLabel:"\u9A8C\u8BC1\u5E76\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"code",label:n.kind==="totp"?"\u52A8\u6001\u9A8C\u8BC1\u7801":"\u6062\u590D\u7801",placeholder:n.kind==="totp"?"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801":"\u8BF7\u8F93\u5165\u6062\u590D\u7801",hint:n.kind==="totp"?"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801":"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onCancel:y,onSubmit:g=>{let x=(g.code??"").trim();if(x===""){l("\u8BF7\u586B\u5199\u9A8C\u8BC1\u7801");return}h(n,x)}})})]})}import{useState as Sk}from"react";import{jsx as oa}from"react/jsx-runtime";function Hg(){let e=L(),{width:t}=H(),[n,o]=Sk(!1),{busy:r,error:i,fail:s,run:a}=le(),c=ee([e.revision],()=>ze(e.ctx.site));return oa(K,{trail:["\u6CE8\u518C\u8D26\u53F7"],isActive:r===null,children:oa(W,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:l=>ta(l.legal)&&!n?oa(na,{legal:l.legal,width:t,onAgree:()=>o(!0)}):oa(ne,{title:"\u6CE8\u518C",width:t,submitLabel:"\u6CE8\u518C",busy:r!==null,busyLabel:r??"\u6B63\u5728\u6CE8\u518C",error:i,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D"},{kind:"text",name:"email",label:"\u90AE\u7BB1",placeholder:"\u8BF7\u8F93\u5165\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",placeholder:"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801",emailField:"email",send:u=>Ig(e.ctx.site,{email:u})},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`},{kind:"text",name:"invite",label:"\u9080\u8BF7\u7801",placeholder:"\u8BF7\u8F93\u5165\u9080\u8BF7\u7801",optional:!0}],onCancel:()=>e.pop(),onSubmit:u=>{let m=(u.username??"").trim(),f=(u.email??"").trim(),d=(u.code??"").trim(),h=u.password??"",y=(u.invite??"").trim();if(m===""||m.length>Kt){s(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}if(f===""||d===""){s("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(h.length<Ot){s(`\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}a("\u6B63\u5728\u6CE8\u518C",()=>Ng(e.ctx.site,{username:m,email:f,password:h,code:d,...y===""?{}:{inviteCode:y}}),{onSuccess:g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u6CE8\u518C\u6210\u529F\uFF1A${g.username}`),e.home()}})}})})})}import{Box as bi}from"ink";import{useState as Ck}from"react";import{Box as qg,Text as xk}from"ink";import{useState as ra}from"react";import{jsx as On,jsxs as Rk}from"react/jsx-runtime";function pr(){let e=L();return t=>{let n=pg[t.status];e.toast(n.tone,n.message)}}var ia=e=>e===null?void 0:`\u539F\u56E0\uFF1A${e}`,fr=(e,t)=>e===null?0:ul(Lc(e.until),ia(e.reason),t)+1;function vo({muted:e,width:t}){return e===null?null:On(qg,{marginBottom:1,children:On(he,{tone:"warn",width:t,title:Lc(e.until),detail:ia(e.reason),wrap:!0})})}var sa=(e,t,n,o)=>t==="published"?0:ul(e[t],ia(n),o);function hi({notices:e,status:t,reason:n,width:o}){return t==="published"?null:On(he,{tone:t==="pending"?"warn":"fail",title:e[t],detail:ia(n),width:o,wrap:!0})}var yi=e=>e===null?0:(e.hint===void 0?1:2)+1,Tk=["content","attachments"],wk=9,kk=3,vk=8;function aa({postId:e,replyTo:t,width:n,height:o,onDone:r,onCancel:i}){let{busy:s,error:a,fail:c,run:l}=le(),[u,m]=ra({content:"",attachments:""}),[f,d]=ra(!1),h=Tk.some(g=>(u[g]??"").trim()!==""),y=Math.min(vk,Math.max(kk,o-wk-yi(a)));return Ce(h),gn(()=>d(!1),{isActive:f,layer:zn.panel}),G(g=>{g==="q"&&h&&d(!0)},!f&&s===null),f?On(Ae,{width:n,title:t===null?"\u653E\u5F03\u8BC4\u8BBA":"\u653E\u5F03\u56DE\u590D",detail:t===null?"\u8BC4\u8BBA\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F":"\u56DE\u590D\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03",onConfirm:i,onCancel:()=>d(!1)}):On(ne,{title:t===null?"\u53D1\u8868\u8BC4\u8BBA":`\u56DE\u590D ${t.mention}`,width:n,submitLabel:t===null?"\u53D1\u8868\u8BC4\u8BBA":"\u53D1\u8868\u56DE\u590D",busy:s!==null,busyLabel:s??"\u6B63\u5728\u63D0\u4EA4",error:a,fields:[{kind:"textarea",name:"content",label:"\u5185\u5BB9",rows:y,maxLength:wc,initial:u.content,placeholder:t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9\uFF0C\u652F\u6301 Markdown":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9"},{...Zn(Ys),initial:u.attachments}],onChange:m,onCancel:()=>h?d(!0):i(),onSubmit:g=>{let x=(g.content??"").trim(),T;try{T=Jn(g.attachments??"",Ys)}catch(R){c(xe(R));return}if(x===""&&T.length===0){c(t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9");return}if(jt(x).length+T.length>Ys.maxCount){c("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return}l("\u6B63\u5728\u63D0\u4EA4",()=>En(T,ai,R=>pf(e,{content:pi(x,R),...t===null?{}:{replyToId:t.id}})),{onSuccess:r})}})}function ca({target:e,width:t,onDone:n,onCancel:o}){let{busy:r,error:i,fail:s,run:a}=le();return On(ne,{title:e.kind==="post"?"\u4E3E\u62A5\u5E16\u5B50":"\u4E3E\u62A5\u8BC4\u8BBA",width:t,submitLabel:"\u63D0\u4EA4\u4E3E\u62A5",busy:r!==null,busyLabel:r??"\u6B63\u5728\u63D0\u4EA4",error:i,fields:[{kind:"select",name:"reason",label:"\u4E3E\u62A5\u539F\u56E0",options:[{value:"",label:"\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0"},...Ei.map(c=>({value:c,label:xd(c)}))],initial:""},{kind:"text",name:"detail",label:"\u8865\u5145\u8BF4\u660E",placeholder:"\u8BF4\u660E\u5177\u4F53\u95EE\u9898\uFF0C\u4FBF\u4E8E\u7BA1\u7406\u5458\u6838\u5B9E",optional:!0}],onCancel:o,onSubmit:c=>{let l=Ei.find(f=>f===c.reason);if(l===void 0){s("\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0");return}let u=(c.detail??"").trim();if(u.length>Fi){s(`\u8865\u5145\u8BF4\u660E\u6700\u591A ${Fi} \u4E2A\u5B57\u7B26`);return}let m={reason:l,detail:u===""?null:u};a("\u6B63\u5728\u63D0\u4EA4",()=>e.kind==="post"?bf(e.id,m):Sf(e.id,m),{onSuccess:n})}})}function la({refs:e,width:t,height:n}){let o=L(),[r,i]=ra(null),[s,a]=ra(null);return r!==null?On(mr,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${st(r.name)}`,width:t,download:async()=>{let c=await Nf(r.id);return{fileName:st(c.fileName),bytes:c.bytes}},onCancel:()=>i(null),onSaved:c=>{i(null),a(c),o.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):Rk(qg,{flexDirection:"column",children:[On(ce,{width:t,height:Math.max(3,n-(s===null?0:1)),items:[{heading:"\u9644\u4EF6"},...e.map(c=>({value:c,label:Fl(c)}))],onSelect:c=>{a(null),i(c)}}),s!==null&&On(xk,{wrap:"truncate",color:p.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${st(s)}`})]})}import{jsx as It,jsxs as Wg}from"react/jsx-runtime";var _k=["category","title","content","attachments"],Pk=11,Ak=2,Ek=3,Mk=16,Gg={new:"\u53D1\u5E03\u5E16\u5B50",draft:"\u7F16\u8F91\u8349\u7A3F",edit:"\u7F16\u8F91\u5E16\u5B50"};function Ik(e){return e.kind==="edit"?{category:String(e.post.category.id),title:e.post.title,content:e.post.content,attachments:""}:e.kind==="draft"?{category:e.draft.category===null?"":String(e.draft.category.id),title:e.draft.title,content:e.draft.content,attachments:""}:{category:"",title:"",content:"",attachments:""}}function Nk(e,t){return e.find(n=>String(n.id)===t)?.description}function zg({mode:e}){let t=L(),{width:n}=H(),o=te(),r=Ik(e),[i,s]=Ie("values",()=>r),[a,c]=Ck(!1),{busy:l,error:u,fail:m,reset:f,run:d}=le(),h=pr(),y=ee([],$s),g=_k.some(N=>(i[N]??"")!==(r[N]??""));Ce(g||l!==null);let x=N=>{let O=N.category??"";return{categoryId:O===""?null:Number(O),title:(N.title??"").trim(),content:(N.content??"").trim()}},T=(N,O)=>{let U;try{U=Jn(N.attachments??"",Ks)}catch(C){return m(xe(C)),null}return jt(O).length+U.length>Ks.maxCount?(m("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650"),null):U},R=N=>{if(e.kind==="edit"&&!g){m("\u5185\u5BB9\u672A\u4FEE\u6539");return}let{categoryId:O,title:U,content:C}=x(N);if(O===null){m("\u8BF7\u9009\u62E9\u677F\u5757");return}if(U===""){m("\u8BF7\u586B\u5199\u6807\u9898");return}if(U.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let w=T(N,C);if(w!==null){if(C===""&&w.length===0){m("\u8BF7\u586B\u5199\u6B63\u6587");return}d("\u6B63\u5728\u63D0\u4EA4",()=>En(w,ai,E=>{let _={categoryId:O,title:U,content:pi(C,E)};return e.kind==="edit"?lf(e.post.id,_):e.kind==="draft"?df(e.draft.id,_):cf(_)}),{onSuccess:E=>{h(E),t.pop(),e.kind!=="edit"&&t.push("post",{id:E.id})}})}},b=(N,O)=>{let{categoryId:U,title:C,content:w}=x(N);if(C.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let E=T(N,w);E!==null&&d("\u6B63\u5728\u4FDD\u5B58\u8349\u7A3F",()=>En(E,ai,async _=>{let A={categoryId:U,title:C,content:pi(w,_)};O===null?await mf(A):await uf(O,A)}),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5B58\u8349\u7A3F")}})},S=e.kind==="draft"?e.draft.id:null,v=()=>{if(!g){t.pop();return}f(),c(!0)},M=()=>{if(!a){t.pop();return}f(),c(!1)};return G(N=>{N==="q"&&g&&v()},!a&&l===null),It(K,{trail:["\u793E\u533A\u8BBA\u575B",Gg[e.kind]],onEscape:M,isActive:l===null,children:It(W,{state:y,loading:"\u6B63\u5728\u8BFB\u53D6\u677F\u5757",width:n,children:N=>{if(a&&e.kind==="edit")return It(Ae,{width:n,title:"\u653E\u5F03\u4FEE\u6539",detail:"\u4FEE\u6539\u5C1A\u672A\u63D0\u4EA4\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03\u4FEE\u6539",onConfirm:t.pop,onCancel:M});if(a)return Wg(bi,{flexDirection:"column",children:[It(he,{tone:"warn",width:n,title:"\u4FDD\u5B58\u8349\u7A3F",detail:"\u5185\u5BB9\u5C1A\u672A\u53D1\u5E03\uFF0C\u662F\u5426\u5B58\u4E3A\u8349\u7A3F\uFF1F"}),u!==null&&It(bi,{marginTop:1,children:It(Ft,{message:u.message,hint:u.hint,width:n})}),It(bi,{marginTop:1,children:l!==null?It(De,{label:l}):It(ce,{width:n,items:[{value:"save",label:"\u5B58\u8349\u7A3F"},{value:"stay",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"discard",label:"\u4E0D\u4FDD\u5B58",labelTone:"danger"}],onSelect:_=>{_==="save"?b(i,S):_==="stay"?M():t.pop()}})})]});let O=e.kind==="edit"?0:1,U=e.kind==="edit"&&e.post.status==="published",C=U?Ak:0,w=Math.min(Mk,Math.max(Ek,o-Pk-O-C-yi(u))),E=i.category??"";return Wg(bi,{flexDirection:"column",children:[U&&It(bi,{marginBottom:1,children:It(he,{tone:"info",width:n,title:"\u4FEE\u6539\u540E\u9700\u91CD\u65B0\u5BA1\u6838\uFF0C\u5BA1\u6838\u671F\u95F4\u5E16\u5B50\u6682\u65F6\u9690\u85CF"})}),It(ne,{title:Gg[e.kind],width:n,submitLabel:e.kind==="edit"?"\u63D0\u4EA4\u4FEE\u6539":"\u53D1\u5E03",busy:l!==null,busyLabel:l??"\u6B63\u5728\u63D0\u4EA4",error:u,fields:[{kind:"select",name:"category",label:"\u677F\u5757",options:[...E===""?[{value:"",label:"\u8BF7\u9009\u62E9\u677F\u5757"}]:[],...N.map(_=>({value:String(_.id),label:_.name}))],initial:i.category,hint:_=>Nk(N,_)},{kind:"text",name:"title",label:"\u6807\u9898",initial:i.title,placeholder:"\u8BF7\u8F93\u5165\u5E16\u5B50\u6807\u9898"},{kind:"textarea",name:"content",label:"\u6B63\u6587",rows:w,maxLength:Bi,initial:i.content,placeholder:"\u8BF7\u8F93\u5165\u6B63\u6587\uFF0C\u652F\u6301 Markdown"},{...Zn(Ks),initial:i.attachments}],secondary:e.kind==="edit"?void 0:{label:"\u5B58\u8349\u7A3F",onSubmit:_=>b(_,S)},onChange:s,onCancel:v,onSubmit:R})]})}})})}function Vg({params:e}){return It(zg,{mode:e.draft===null?{kind:"new"}:{kind:"draft",draft:e.draft}})}function Kg({params:e}){return It(zg,{mode:{kind:"edit",post:e.post}})}import{Box as to,Text as Wl}from"ink";import{useEffect as zl,useMemo as Yg,useState as ma}from"react";import{useRef as Lk}from"react";function qt(e){let t=Lk(null);return e.phase==="ready"&&(t.current={data:e.data}),e.phase==="error"&&(t.current=null),e.phase==="loading"&&t.current!==null?{phase:"ready",data:t.current.data}:e}import{jsx as Ee,jsxs as Vl}from"react/jsx-runtime";var ua={kind:"floor"},Ok=2,Jg=3,Dk=4,Zg=2,Xg=3,Qg="PgUp PgDn \u6EDA\u52A8\u6B63\u6587",da=(e,t)=>{let n=sa(Yo,e.status,e.reviewReason,t);return n===0?0:n+1};function $k(e,t,n,o,r){let i=Math.max(Zg+Xg,o-Ok-da(e,r)-3),s=Math.max(Xg,Math.min(Dk,i-Jg)),a=Math.min(Jg,i-s),c=Math.min(1+Math.max(2,n),Math.max(s,Math.floor(i/2))),l=Math.min(t.length,Math.max(a,i-c));return{bodyRows:l,listRows:i-l}}function Bk(e,t,n,o,r){let i=o-Ze-1-da(e,r)-2-n;return Math.min(t.length,Math.max(Zg,i))}function Fk(e,t,n,o){let r=e.status==="published"&&t.status==="published"&&n.status==="published",i=Nn(n.author,o);return[...r&&!i?[{value:"like",label:n.liked?"\u53D6\u6D88\u70B9\u8D5E":"\u70B9\u8D5E"}]:[],...r?[{value:"reply",label:"\u56DE\u590D"}]:[],...r&&!i?[{value:"report",label:"\u4E3E\u62A5"}]:[],...jt(n.content).length>0?[{value:"attachments",label:"\u9644\u4EF6"}]:[],{value:"author",label:"\u7528\u6237\u4E3B\u9875",hint:vt(n.author)},...i?[{value:"delete",label:"\u5220\u9664",labelTone:"danger"}]:[]]}function eh({params:e}){let t=L(),{width:n}=H(),o=te(),[r,i]=ma({name:"main"}),[s,a]=ma(null),{busy:c,error:l,reset:u,run:m}=le();Ce(r.name==="confirm-delete"&&c!==null);let f=pr(),d=qt(ee([e.postId,e.floorId,t.revision],async()=>{let[F,re,B,z]=await Promise.all([Bs(e.postId),Zp(e.postId,e.floorId),An(),ir()]);return{post:F,floor:re,me:B.user,muted:z.muted}})),h=Ve([e.floorId,t.revision],F=>ef(e.floorId,F),{retain:"replies-page"}),y=qt(h.state),g=d.phase==="ready"?d.data:null,x=y.phase==="ready"?y.data:null,[T,R]=ma(void 0);zl(()=>R(void 0),[g]);let[b,S]=ma(new Map);zl(()=>S(new Map),[x]);let v=g===null?null:{...g,floor:{...g.floor,...T}},M=x===null?[]:x.items.map(F=>({...F,...b.get(F.id)})),N=fg(id(M)),O=r.name==="actions"?M.find(F=>F.id===r.id)??null:null,U=s!==null&&M.some(F=>F.id===s);zl(()=>{U&&a(null)},[U]);let C=v===null?null:v.floor.content,w=Yg(()=>C===null?[]:di(C,n),[C,n]),E=O===null?null:O.content,_=Yg(()=>E===null?[]:di(E,n-pe),[E,n]),A=v===null?null:$k(v.floor,w,M.length,o-fr(v.muted,n),n),$=v===null||O===null?null:Fk(v.post,v.floor,O,v.me.username),Z=O===null||$===null?null:Bk(O,_,$.length,o,n-pe),oe=F=>v===null?null:F.kind==="floor"?v.floor:M.find(re=>re.id===F.id)??null,fe=(F,re)=>{m(F.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>hf(F.id,!F.liked),{failToast:!0,onSuccess:({likeCount:B})=>re({liked:!F.liked,likeCount:B})})};G((F,re)=>{if(v===null||r.name!=="main"||c!==null)return;let{post:B,floor:z,me:Y}=v,be=B.status==="published"&&z.status==="published",Me=Nn(z.author,Y.username);F==="r"?t.reload():re.leftArrow?h.go(-1):re.rightArrow?h.go(1):F==="c"&&be?i({name:"reply",target:ua}):F==="l"&&be&&!Me?fe(z,R):F==="p"&&be&&!Me?i({name:"report",target:ua}):F==="a"&&jt(z.content).length>0?i({name:"attachments",target:ua}):F==="u"?t.push("homepage",{author:ui(z.author)}):F==="d"&&Me&&(u(),i({name:"confirm-delete",target:ua}))});let D=()=>{if(r.name==="main"){t.pop();return}if(u(),r.name!=="actions"&&r.target.kind==="reply"){i({name:"actions",id:r.target.id});return}i({name:"main"})},k=(F,re)=>{let B={kind:"reply",id:F.id};re==="like"?fe(F,z=>S(Y=>new Map(Y).set(F.id,z))):re==="reply"?i({name:"reply",target:B}):re==="report"?i({name:"report",target:B}):re==="attachments"?i({name:"attachments",target:B}):re==="author"?t.push("homepage",{author:ui(F.author)}):(u(),i({name:"confirm-delete",target:B}))};return Ee(K,{trail:["\u793E\u533A\u8BBA\u575B","\u697C\u5C42\u8BE6\u60C5"],hints:(()=>{if(v===null)return[];if(r.name==="actions")return Z===null?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C",..._.length>Z?[Qg]:[]];if(r.name!=="main"||A===null)return[];let{post:F,floor:re,me:B}=v,z=F.status==="published"&&re.status==="published",Y=Nn(re.author,B.username);return[...M.length>0?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C"]:[],...w.length>A.bodyRows?[Qg]:[],...z?["c \u56DE\u590D"]:[],...z&&!Y?[re.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E","p \u4E3E\u62A5"]:[],...jt(re.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...Y?["d \u5220\u9664"]:[],"r \u5237\u65B0"]})(),onEscape:D,isActive:r.name==="main"||c===null,children:Ee(W,{state:d,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:n,children:({post:F,floor:re,me:B,muted:z})=>{let Y={...re,...T},be=ge=>`${Nn(ge.author,B.username)?"\u83B7\u8D5E":ge.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${ge.likeCount}`;if(r.name==="actions"){if(O===null||$===null||Z===null)return Ee(he,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});let ge=n-pe;return Vl(de,{title:vt(O.author),note:V(O.createdAt),width:n,children:[Ee(Wl,{wrap:"truncate",color:p.mutedForeground,children:_e([O.replyTo!==null&&`\u56DE\u590D ${Js(O.replyTo.author)}`,be(O)])}),da(O,ge)>0&&Ee(to,{marginTop:1,children:Ee(hi,{notices:Yo,status:O.status,reason:O.reviewReason,width:ge})}),Ee(to,{marginTop:1,children:Ee(dt,{lines:_,height:Z,isActive:c===null,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:c!==null?Ee(De,{label:c}):Ee(ce,{width:ge,items:$,onSelect:et=>k(O,et)})})]})}if(r.name!=="main"){let ge=oe(r.target);if(ge===null)return Ee(he,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});if(r.name==="reply")return Ee(aa,{postId:F.id,replyTo:{id:ge.id,mention:Js(ge.author)},width:n,height:o,onCancel:D,onDone:Be=>{i({name:"main"}),a(Be.id),h.last(),t.reload(),f(Be)}});if(r.name==="report")return Ee(ca,{target:{kind:"comment",id:ge.id},width:n,onCancel:D,onDone:()=>{D(),t.toast("ok","\u5DF2\u63D0\u4EA4\u4E3E\u62A5")}});if(r.name==="attachments")return Ee(la,{refs:jt(ge.content),width:n,height:o});let et=r.target.kind==="floor";return Ee(Ae,{width:n,title:et?"\u5220\u9664\u8BC4\u8BBA":"\u5220\u9664\u56DE\u590D",detail:et?"\u5220\u9664\u540E\u8BE5\u697C\u5C42\u53CA\u5176\u5168\u90E8\u56DE\u590D\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F":"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u6761\u56DE\u590D\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:c,error:l,onConfirm:()=>m("\u6B63\u5728\u5220\u9664",()=>ff(ge.id),{onSuccess:()=>{et?t.pop():(i({name:"main"}),t.reload()),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:D})}if(A===null)return null;let Me=c===null;return Vl(to,{flexDirection:"column",children:[Ee(vo,{muted:z,width:n}),Ee(Wl,{bold:!0,wrap:"truncate",color:p.foreground,children:F.title}),c!==null?Ee(De,{label:c}):Ee(Wl,{wrap:"truncate",color:p.mutedForeground,children:_e([Y.floor!==null&&`#${Y.floor}`,vt(Y.author),V(Y.createdAt),`\u56DE\u590D ${Y.replyCount}`,be(Y)])}),da(Y,n)>0&&Ee(to,{marginTop:1,children:Ee(hi,{notices:Yo,status:Y.status,reason:Y.reviewReason,width:n})}),Ee(to,{marginTop:1,children:Ee(dt,{lines:w,height:A.bodyRows,isActive:Me,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:Ee(W,{state:y,loading:"\u6B63\u5728\u8BFB\u53D6\u56DE\u590D",width:n,children:()=>Vl(to,{flexDirection:"column",children:[Ee(ue,{retain:"replies",items:N,width:n,height:A.listRows,isActive:Me,columns:[Qn,{label:"\u56DE\u590D",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:({reply:ge,mention:et,prefix:Be})=>[`${Be}${vt(ge.author)}`,et===null?wo(ge.content):`\u56DE\u590D ${Js(et)}\uFF1A${wo(ge.content)}`,String(ge.likeCount),V(ge.createdAt),ge.status==="published"?"":yt(po(ge.status))],onOpen:({reply:ge})=>i({name:"actions",id:ge.id}),select:s===null?void 0:({reply:ge})=>ge.id===s,emptyLabel:"\u6682\u65E0\u56DE\u590D",emptyDescription:F.status==="published"&&Y.status==="published"?"\u6309 c \u56DE\u590D\u672C\u697C":void 0}),Ee(Ke,{page:h.page,pages:h.pages,total:h.total,width:n})]})})})]})}})})}import{Box as Ro,Text as ga}from"ink";import{Box as th}from"ink";import{jsx as gr,jsxs as nh}from"react/jsx-runtime";function pa({author:e,owner:t,width:n,height:o}){let r=L(),i=Ve([e.kind,e.username,r.revision],a=>nf(e,a),{retain:"posts-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(W,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:a=>nh(th,{flexDirection:"column",children:[gr(ue,{retain:"posts",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u6807\u9898",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],lr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},t?{label:"\u65F6\u95F4"}:{label:"\u65F6\u95F4",align:"right"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[c.title,...t?[Nc(Hr,c)??""]:[],c.category.name,String(c.commentCount),String(c.viewCount),String(c.likeCount),V(c.publishedAt??c.createdAt),...t?[yt(po(c.status))]:[]],onOpen:c=>r.push("post",{id:c.id}),emptyLabel:"\u6682\u65E0\u5E16\u5B50"}),gr(Ke,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}function fa({author:e,owner:t,width:n,height:o}){let r=L(),i=Ve([e.kind,e.username,r.revision],a=>of(e,a),{retain:"comments-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(W,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u8BC4\u8BBA",width:n,children:a=>nh(th,{flexDirection:"column",children:[gr(ue,{retain:"comments",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u8BC4\u8BBA",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],{label:"\u5E16\u5B50",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[wo(c.content),...t?[Nc(Yo,c)??""]:[],c.post.title??Vi,String(c.likeCount),V(c.createdAt),...t?[yt(po(c.status))]:[]],onOpen:c=>r.push("floor",{postId:c.post.id,floorId:c.floorId}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA"}),gr(Ke,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}import{jsx as St,jsxs as ha}from"react/jsx-runtime";var Uk=[{value:"posts",label:"\u5E16\u5B50"},{value:"comments",label:"\u8BC4\u8BBA"}],jk=3,Hk=2,qk=5;function Gk({profile:e,owner:t,width:n,heatmapOn:o}){let{identity:r,stats:i}=e,s=e.activity.days.reduce((a,c)=>a+c.count,0);return ha(Ro,{flexDirection:"column",children:[ha(ga,{wrap:"truncate",children:[St(ga,{bold:!0,color:p.foreground,children:st(r.username)}),St(ga,{color:p.accent,children:` ${r.kind==="user"?Gi(r.points):`[${zi}]`}`})]}),St(ga,{wrap:"truncate",color:p.mutedForeground,children:_e([r.kind==="user"&&`${r.points} \u79EF\u5206`,t&&r.kind==="user"&&Wi(r.points),`\u52A0\u5165\u4E8E ${jr(e.joinedAt)}`])}),St(Ro,{marginTop:1,children:St(it,{width:n,tiles:[{label:"\u5E16\u5B50",value:String(i.posts)},{label:"\u8BC4\u8BBA",value:String(i.comments)},{label:"\u83B7\u8D5E",value:String(i.likesReceived)}]})}),o&&ha(Ro,{marginTop:Q,flexDirection:"column",children:[St(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:n}),St(Ro,{marginTop:We,flexDirection:"column",children:St(cr,{data:e.activity,value:a=>a.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${s} \u6B21`,width:n})})]})]})}function oh({params:e}){let t=L(),{width:n}=H(),o=te(),[r,i]=Ie("content",()=>"posts"),s=ee([e.author.kind,e.author.username,t.revision],async()=>{let[f,d]=await Promise.all([tf(e.author),An()]),h=e.author.kind==="user"&&e.author.username===d.user.username;return{profile:f,owner:h}});G(f=>{f==="r"?t.reload():f==="t"&&i(d=>d==="posts"?"comments":"posts")});let a=Hk+1+Ut(jk,n),c=o-a-2-1,l=Q+Ze+To,u=ar(n)&&c-l>=qk,m=Math.max(3,c-(u?l:0));return St(K,{trail:["\u793E\u533A\u8BBA\u575B","\u7528\u6237\u4E3B\u9875"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","t \u5207\u6362","r \u5237\u65B0"],children:St(W,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u6237\u4E3B\u9875",width:n,children:({profile:f,owner:d})=>ha(Ro,{flexDirection:"column",children:[St(Gk,{profile:f,owner:d,width:n,heatmapOn:u}),St(Ro,{marginTop:1,children:St(js,{options:Uk,value:r,onChange:i,arrowKeys:!1})}),St(Ro,{marginTop:1,children:r==="posts"?St(pa,{author:e.author,owner:d,width:n,height:m}):St(fa,{author:e.author,owner:d,width:n,height:m})})]})})})}import{Box as rh}from"ink";import{useState as Wk}from"react";import{jsx as Co,jsxs as sh}from"react/jsx-runtime";var zk={sort:"activity",categoryId:"",q:"",author:""},ih=e=>e.categoryId!==""||e.q!==""||e.author!=="",Vk=(e,t)=>({page:t,sort:e.sort,...e.categoryId===""?{}:{categoryId:Number(e.categoryId)},...e.q===""?{}:{q:e.q},...e.author===""?{}:{author:e.author}});function ah(){let e=L(),{width:t}=H(),n=te(),[o,r]=Wk(!1),[i,s]=Ie("filters",()=>zk),{error:a,fail:c,reset:l}=le(),u=ee([e.revision],async()=>{let[d,h]=await Promise.all([ir(),$s()]);return{muted:d.muted,categories:h}}),m=Ve([e.revision,JSON.stringify(i)],d=>Jp(Vk(i,d)),{retain:"page"});G((d,h)=>{o||(d==="r"?e.reload():d==="f"?r(!0):d==="n"?e.push("compose",{draft:null}):h.leftArrow?m.go(-1):h.rightArrow&&m.go(1))});let f=()=>{if(!o){e.pop();return}l(),r(!1)};return Co(K,{hints:o?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u53D1\u5E03\u5E16\u5B50","f \u7B5B\u9009","r \u5237\u65B0"],onEscape:f,children:Co(W,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u793E\u533A",width:t,children:({muted:d,categories:h})=>o?Co(ne,{title:"\u7B5B\u9009\u5E16\u5B50",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"select",name:"sort",label:"\u6392\u5E8F",options:ic.map(y=>({value:y,label:Td(y)})),initial:i.sort},{kind:"select",name:"category",label:"\u677F\u5757",options:[{value:"",label:"\u5168\u90E8\u677F\u5757"},...h.map(y=>({value:String(y.id),label:y.name}))],initial:i.categoryId},{kind:"text",name:"q",label:"\u5173\u952E\u8BCD",initial:i.q,placeholder:"\u641C\u7D22\u6807\u9898\u6216\u6B63\u6587"},{kind:"text",name:"author",label:"\u4F5C\u8005",initial:i.author,placeholder:"\u8F93\u5165\u4F5C\u8005\u5B8C\u6574\u7528\u6237\u540D"}],onCancel:f,onSubmit:y=>{let g=(y.q??"").trim(),x=(y.author??"").trim();if(g.length>Ui){c(`\u5173\u952E\u8BCD\u6700\u591A ${Ui} \u4E2A\u5B57\u7B26`);return}if(x.length>Kt){c(`\u7528\u6237\u540D\u6700\u591A ${Kt} \u4E2A\u5B57\u7B26`);return}s({sort:y.sort,categoryId:y.category??"",q:g,author:x}),m.reset(),l(),r(!1)}}):sh(rh,{flexDirection:"column",children:[Co(vo,{muted:d,width:t}),Co(W,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:t,children:y=>sh(rh,{flexDirection:"column",children:[Co(ue,{retain:"list",items:y.items,width:t,height:Math.max(3,n-1-fr(d,t)),columns:[{label:"\u4E3B\u9898",shrink:!0},Qn,lr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:g=>[g.title,vt(g.author),g.category.name,String(g.commentCount),String(g.viewCount),String(g.likeCount),V(g.lastActivityAt)],onOpen:g=>e.push("post",{id:g.id}),emptyLabel:ih(i)?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u5E16\u5B50",emptyDescription:ih(i)?void 0:"\u6309 n \u53D1\u5E03\u7B2C\u4E00\u7BC7\u5E16\u5B50"}),Co(Ke,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})})})}import{Box as ya}from"ink";import{useState as Kk}from"react";import{jsx as pt,jsxs as fh}from"react/jsx-runtime";var Yk=Q+Ze+2,Jk=Q+2+1+2;function lh(){let e=L();G(t=>{t==="r"&&e.reload()})}function mh({params:e}){let{width:t}=H(),n=te();return lh(),pt(K,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u5E16\u5B50"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:pt(pa,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function uh({params:e}){let{width:t}=H(),n=te();return lh(),pt(K,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u8BC4\u8BBA"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:pt(fa,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function dh(){let e=L(),{width:t}=H(),n=te(),o=Ve([e.revision],r=>rf(r),{retain:"page"});return G((r,i)=>{r==="r"?e.reload():i.leftArrow?o.go(-1):i.rightArrow&&o.go(1)}),pt(K,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u6536\u85CF"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:pt(W,{state:o.state,loading:"\u6B63\u5728\u8BFB\u53D6\u6536\u85CF",width:t,children:r=>fh(ya,{flexDirection:"column",children:[pt(ue,{retain:"list",items:r.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},Qn,{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:i=>[i.title,vt(i.author),String(i.commentCount),String(i.likeCount),V(i.lastActivityAt)],onOpen:i=>e.push("post",{id:i.id}),emptyLabel:"\u6682\u65E0\u6536\u85CF"}),pt(Ke,{page:o.page,pages:o.pages,total:o.total,width:t})]})})})}var ch=e=>e.title===""?"\u672A\u547D\u540D\u8349\u7A3F":e.title;function ph(){let e=L(),{width:t}=H(),n=te(),[o,r]=Kk({name:"list"}),{busy:i,error:s,reset:a,run:c}=le();Ce(i!==null);let l=Ve([e.revision],d=>sf(d),{retain:"page"}),u=o.name==="list";G((d,h)=>{u&&(d==="r"?e.reload():h.leftArrow?l.go(-1):h.rightArrow&&l.go(1))});let m=()=>{if(u){e.pop();return}a(),r({name:"list"})},f=o.name==="actions"?Yk:o.name==="confirm-delete"?Jk+yi(s):0;return pt(K,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u8349\u7A3F"],hints:u?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:pt(W,{state:l.state,loading:"\u6B63\u5728\u8BFB\u53D6\u8349\u7A3F",width:t,children:d=>fh(ya,{flexDirection:"column",children:[pt(ue,{retain:"list",items:d.items,width:t,height:Math.max(3,n-1-f),isActive:u,columns:[{label:"\u6807\u9898",shrink:!0},lr,{label:"\u521B\u5EFA\u65F6\u95F4",align:"right"}],row:h=>[ch(h),h.category===null?"\u2014":h.category.name,V(h.createdAt)],onOpen:h=>r({name:"actions",draft:h}),emptyLabel:"\u6682\u65E0\u8349\u7A3F",emptyDescription:"\u53D1\u5E03\u5E16\u5B50\u65F6\u53EF\u9009\u62E9\u5B58\u4E3A\u8349\u7A3F"}),pt(Ke,{page:l.page,pages:l.pages,total:l.total,width:t}),o.name==="actions"&&pt(ya,{marginTop:Q,children:pt(de,{title:ch(o.draft),width:t,children:pt(ce,{width:t-pe,items:[{value:"edit",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:h=>{if(h==="edit"){r({name:"list"}),e.push("compose",{draft:o.draft});return}a(),r({name:"confirm-delete",draft:o.draft})}})})}),o.name==="confirm-delete"&&pt(ya,{marginTop:Q,children:pt(Ae,{width:t,title:"\u5220\u9664\u8349\u7A3F",detail:"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u7BC7\u8349\u7A3F\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>c("\u6B63\u5728\u5220\u9664",()=>Fs(o.draft.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:m})})]})})})}import{Box as _o,Text as Kl}from"ink";import{useEffect as ba,useMemo as Xk,useRef as Qk,useState as Yl}from"react";import{jsx as Je,jsxs as Jl}from"react/jsx-runtime";var gh=2,Zk=2,ev=2;function tv({post:e,width:t,height:n,isActive:o,follow:r,onFollowed:i}){let s=L(),a=Ve([e.id,s.revision],u=>Qp(e.id,u),{retain:"floors-page"}),c=qt(a.state),l=r!==null&&c.phase==="ready"&&c.data.items.some(u=>u.id===r);return ba(()=>{r!==null&&a.last()},[r]),ba(()=>{l&&i()},[l]),G((u,m)=>{m.leftArrow?a.go(-1):m.rightArrow&&a.go(1)},o),Je(W,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:t,children:u=>Jl(_o,{flexDirection:"column",children:[Je(ue,{retain:"floors",items:u.items,width:t,height:Math.max(3,n-1),isActive:o,columns:[{label:"\u697C\u5C42"},Qn,{label:"\u5185\u5BB9",shrink:!0},{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[m.floor===null?"\u2014":`#${m.floor}`,vt(m.author),wo(m.content),String(m.replyCount),String(m.likeCount),m.status==="published"?"":yt(po(m.status))],onOpen:m=>s.push("floor",{postId:e.id,floorId:m.id}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA",emptyDescription:e.status==="published"?"\u6309 c \u53D1\u8868\u7B2C\u4E00\u6761\u8BC4\u8BBA":void 0,select:r===null?void 0:m=>m.id===r}),Je(Ke,{page:a.page,pages:a.pages,total:a.total,width:t})]})})}function hh({params:e}){let t=L(),{width:n}=H(),o=te(),[r,i]=Ie("mode",()=>"body"),[s,a]=Yl({name:"main"}),[c,l]=Yl(null),{busy:u,error:m,reset:f,run:d}=le();Ce(s.name==="confirm-delete"&&u!==null);let h=pr(),y=Qk(null),g=qt(ee([e.id,t.revision],async()=>{let[C,w,E]=await Promise.all([Bs(e.id),An(),ir()]);return{post:C,me:w.user,muted:E.muted}})),x=g.phase==="ready"?g.data:null,[T,R]=Yl(null);ba(()=>R(null),[x]);let b=x===null?null:{...x,post:{...x.post,...T}},S=b!==null&&b.post.status==="published";ba(()=>{!S||y.current===e.id||(y.current=e.id,Xp(e.id).catch(()=>t.toast("warn","\u6D4F\u89C8\u8BA1\u6570\u53D1\u9001\u5931\u8D25")))},[e.id,S]);let v=s.name==="main"&&u===null,M=b===null?null:b.post.content,N=Xk(()=>M===null?[]:di(M,n),[M,n]);G(C=>{if(b===null||!v)return;let{post:w,me:E}=b;if(C==="r"){t.reload();return}if(C==="v"){i(r==="body"?"floors":"body");return}if(C==="c"&&S){a({name:"comment"});return}if(r!=="body")return;let _=Nn(w.author,E.username),A={liked:w.liked,likeCount:w.likeCount,bookmarked:w.bookmarked};C==="l"&&S&&!_?d(w.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>gf(w.id,!w.liked),{failToast:!0,onSuccess:({likeCount:$})=>R({...A,liked:!w.liked,likeCount:$})}):C==="b"&&S?d(w.bookmarked?"\u6B63\u5728\u53D6\u6D88\u6536\u85CF":"\u6B63\u5728\u6536\u85CF",()=>yf(w.id,!w.bookmarked),{failToast:!0,onSuccess:()=>{R({...A,bookmarked:!w.bookmarked}),t.toast("ok",w.bookmarked?"\u5DF2\u53D6\u6D88\u6536\u85CF":"\u5DF2\u6536\u85CF")}}):C==="p"&&S&&!_?a({name:"report"}):C==="a"&&jt(w.content).length>0?a({name:"attachments"}):C==="u"?t.push("homepage",{author:ui(w.author)}):C==="e"&&_&&w.status!=="removed"?t.push("post-edit",{post:w}):C==="d"&&_&&(f(),a({name:"confirm-delete"}))});let O=()=>{if(s.name!=="main"){f(),a({name:"main"});return}if(r==="floors"){i("body");return}t.pop()},U=()=>{if(b===null||s.name!=="main")return[];let{post:C,me:w}=b;if(r==="floors")return["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...S?["c \u8BC4\u8BBA"]:[],"v \u6B63\u6587","r \u5237\u65B0"];let E=Nn(C.author,w.username);return["\u2191\u2193 \u6EDA\u52A8","v \u697C\u5C42\u5217\u8868",...S?["c \u8BC4\u8BBA",...E?[]:[C.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E"],C.bookmarked?"b \u53D6\u6D88\u6536\u85CF":"b \u6536\u85CF",...E?[]:["p \u4E3E\u62A5"]]:[],...jt(C.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...E&&C.status!=="removed"?["e \u7F16\u8F91\u5E16\u5B50"]:[],...E?["d \u5220\u9664"]:[],"r \u5237\u65B0"]};return Je(K,{trail:["\u793E\u533A\u8BBA\u575B",b===null?"\u5E16\u5B50\u8BE6\u60C5":b.post.category.name,...r==="floors"&&s.name==="main"?["\u697C\u5C42\u5217\u8868"]:[]],hints:U(),onEscape:O,isActive:s.name==="main"||u===null,children:Je(W,{state:g,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:({post:C,me:w,muted:E})=>{let _={...C,...T},A=Nn(_.author,w.username);if(s.name==="comment")return Je(aa,{postId:_.id,replyTo:null,width:n,height:o,onCancel:O,onDone:D=>{a({name:"main"}),i("floors"),l(D.id),t.reload(),h(D)}});if(s.name==="report")return Je(ca,{target:{kind:"post",id:_.id},width:n,onCancel:O,onDone:()=>{a({name:"main"}),t.toast("ok","\u5DF2\u63D0\u4EA4\u4E3E\u62A5")}});if(s.name==="attachments")return Je(la,{refs:jt(_.content),width:n,height:o});if(s.name==="confirm-delete")return Je(Ae,{width:n,title:"\u5220\u9664\u5E16\u5B50",detail:"\u5220\u9664\u540E\u5E16\u5B50\u53CA\u5176\u5168\u90E8\u8BC4\u8BBA\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:u,error:m,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Fs(_.id),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:O});let $=Je(Kl,{bold:!0,wrap:"truncate",color:p.foreground,children:_.title}),Z=fr(E,n);if(r==="floors")return Jl(_o,{flexDirection:"column",children:[Je(vo,{muted:E,width:n}),$,Je(_o,{marginTop:1,children:Je(tv,{post:_,width:n,height:o-gh-Z,isActive:v,follow:c,onFollowed:()=>l(null)})})]});let oe=sa(Hr,_.status,_.reviewReason,n),fe=Math.max(ev,o-Z-gh-(oe===0?0:oe+1)-1-Zk);return Jl(_o,{flexDirection:"column",children:[Je(vo,{muted:E,width:n}),$,Je(Kl,{wrap:"truncate",color:p.mutedForeground,children:_e([vt(_.author),V(_.publishedAt??_.createdAt),_.editedAt!==null&&`\u7F16\u8F91\u4E8E ${V(_.editedAt)}`,`\u6D4F\u89C8 ${_.viewCount}`])}),oe>0&&Je(_o,{marginTop:1,children:Je(hi,{notices:Hr,status:_.status,reason:_.reviewReason,width:n})}),Je(_o,{marginTop:1,children:Je(dt,{lines:N,height:fe,isActive:v})}),Je(_o,{marginTop:1,children:u!==null?Je(De,{label:u}):Je(Kl,{wrap:"truncate",color:p.mutedForeground,children:_e([`\u8BC4\u8BBA ${_.commentCount}`,`${A?"\u83B7\u8D5E":_.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${_.likeCount}`,_.bookmarked&&"\u5DF2\u6536\u85CF"])})})]})}})})}import{Box as Ao}from"ink";import{useEffect as uv,useRef as dv,useState as Zl}from"react";import{z as q}from"zod";var nv=q.object({balance:q.number(),today:q.object({requests:q.number(),tokens:q.number(),cost:q.number()})}),yh=()=>P(nv,"/dashboard/summary"),bh=["all","30d","7d"],ov=q.object({totals:q.object({requests:q.number(),tokens:q.number(),cost:q.number()}),hourly:q.array(q.number()),models:q.array(q.object({model:q.string(),displayName:q.string(),tokens:q.number(),inTokens:q.number(),outTokens:q.number()})),chart:q.object({start:q.string(),end:q.string(),points:q.array(q.object({day:q.string(),model:q.string(),tokens:q.number()}))}),heatmap:q.object({start:q.string(),end:q.string(),days:q.array(q.object({day:q.string(),cost:q.number()}))}),activeDays:q.number(),currentStreak:q.number(),longestStreak:q.number()}),Xl=e=>P(ov,je("/dashboard/stats",{range:e})),rv=q.object({id:q.number().int(),requestId:q.string(),tokenName:q.string(),protocol:Bm,model:q.string(),modelDisplayName:q.string(),groupName:q.string(),promptTokens:q.number(),completionTokens:q.number(),cachedTokens:q.number(),cacheWriteTokens:q.number(),cacheWrite1hTokens:q.number(),webSearchRequests:q.number(),imageGenerationCalls:q.number(),totalTokens:q.number(),quotaCost:q.number(),subscriptionPlanName:q.string().nullable(),multiplier:q.number(),tierOver:q.number().int().nullable(),paramMultipliers:Mu,status:zm,httpStatus:q.number().int(),stopReason:q.string().nullable(),latencyMs:q.number(),firstByteMs:q.number().nullable(),stream:q.boolean(),ip:q.string(),createdAt:q.string()}),Sh=e=>P(lt(rv),je("/logs",{...e})),iv=q.object({quotaCost:q.number(),rpm:q.number(),tpm:q.number(),concurrency:q.number()}),xh=e=>P(iv,je("/logs/stats",{...e})),sv=q.object({id:q.number().int(),type:qm,amount:q.number(),balanceAfter:q.number(),refType:Gm,refId:q.string().nullable(),createdAt:q.string()}),Th=e=>P(lt(sv),je("/quota-ledger",{...e}));import{Box as av,Text as ln}from"ink";import Si from"string-width";import{Fragment as kh,jsx as mn,jsxs as Ql}from"react/jsx-runtime";var Po=1,cv=4,lv=1,hr=8,mv=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587"],wh=e=>`${Number(e.slice(5,7))}\u6708${Number(e.slice(8,10))}\u65E5`;function vh({data:e,order:t,width:n,rows:o}){let r=o-lv,i=[];for(let U=e.start;U<=e.end;U=Gn(U,1))i.push(U);let s=Math.min(cv,Math.floor((n+Po)/i.length)-Po);s<1&&(s=1,i=i.slice(-Math.floor((n+Po)/(1+Po))));let a=i[0],c=i[i.length-1];if(a===void 0||c===void 0)return null;let l=new Map(t.slice(0,bs.length).map((U,C)=>[U,C])),u=bs.length,m=U=>bs[U]??p.faintForeground,f=new Map(i.map((U,C)=>[U,C])),d=i.map(()=>Array.from({length:u+1},()=>0));for(let U of e.points){let C=f.get(U.day);if(C===void 0)continue;let w=d[C];if(w===void 0)continue;let E=l.get(U.model)??u;w[E]=(w[E]??0)+U.tokens}let h=d.map(U=>U.reduce((C,w)=>C+w,0)),y=Math.max(0,...h),g=r*hr,x=d.map((U,C)=>{let w=Array.from({length:r},()=>null),E=h[C]??0;if(E<=0)return w;let _=Math.max(1,Math.round(E/y*g)),A=[],$=0,Z=0;U.forEach((oe,fe)=>{$+=oe;let D=Math.round($/E*_);for(let k=Z;k<D;k+=1)A[k]=m(fe);Z=D});for(let oe=0;oe<r;oe+=1){let fe=Math.min(hr,_-oe*hr);if(fe<=0)break;let D=new Map;for(let F=oe*hr;F<oe*hr+fe;F+=1){let re=A[F];re!==void 0&&D.set(re,(D.get(re)??0)+1)}let k=null,X=0;for(let[F,re]of D)re>X&&(k=F,X=re);if(k===null)break;w[oe]={color:k,glyph:fe===hr?null:mv[fe-1]??null}}return w}),T=U=>{let C=[],w=(E,_,A)=>{let $=C[C.length-1];$!==void 0&&$.color===E&&$.glyph===_?$.width+=A:C.push({color:E,glyph:_,width:A})};return x.forEach((E,_)=>{_>0&&w(null,null,Po);let A=E[U]??null;A===null?w(null,null,s):w(A.color,A.glyph,s)}),C},R=i.length*(s+Po)-Po,b=wh(a),S=wh(c),v=y>0?`\u5355\u65E5\u5CF0\u503C ${qn(y)}`:"",M=R-Si(b)-Si(S),N=v!==""&&M>=Si(v)+4,O=N?Math.floor((M-Si(v))/2):M;return Ql(av,{flexDirection:"column",children:[Array.from({length:r},(U,C)=>{let w=r-1-C;return mn(ln,{wrap:"truncate",children:T(w).map((E,_)=>E.color===null?mn(ln,{children:" ".repeat(E.width)},_):E.glyph===null?mn(ln,{backgroundColor:E.color,children:" ".repeat(E.width)},_):mn(ln,{color:E.color,children:E.glyph.repeat(E.width)},_))},w)}),mn(ln,{wrap:"truncate",children:M<2?mn(ln,{color:p.faintForeground,children:Ge(b,R)}):Ql(kh,{children:[mn(ln,{color:p.faintForeground,children:b}),mn(ln,{children:" ".repeat(O)}),N&&Ql(kh,{children:[mn(ln,{color:p.mutedForeground,children:v}),mn(ln,{children:" ".repeat(M-Si(v)-O)})]}),mn(ln,{color:p.faintForeground,children:S})]})})]})}import{jsx as at,jsxs as Ch}from"react/jsx-runtime";var pv={all:"\u5168\u90E8","30d":"30 \u5929","7d":"7 \u5929"},fv=1,Sa=4,Rh=5,gv=9;function hv(e){let t=-1,n=0;return e.forEach((o,r)=>{o>n&&(n=o,t=r)}),t<0?"\u2014":`${t} \u70B9`}function _h(){let e=L(),{width:t}=H(),n=te(),[o,r]=Zl("30d"),[i,s]=Zl("heatmap"),[a,c]=Zl(null),l=dv(null),u=ee([o,e.revision],async()=>{let m=l.current;if(m!==null&&m.revision===e.revision){let y=await Xl(o);return{summary:m.summary,stats:y,site:m.site}}let[f,d,h]=await Promise.all([yh(),Xl(o),ze(e.ctx.site)]);return l.current={revision:e.revision,summary:f,site:h},{summary:f,stats:d,site:h}});return uv(()=>{u.phase==="ready"&&c(fd({tokens:u.data.stats.totals.tokens,scope:"user",range:o}))},[u,o]),G(m=>{m==="r"&&e.reload(),m==="t"&&s(f=>f==="heatmap"?"chart":"heatmap")}),at(K,{hints:["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u5207\u6362\u533A\u95F4","t \u5207\u6362\u56FE\u8868","/ \u8FC7\u6EE4","r \u5237\u65B0"],children:at(Ao,{flexDirection:"column",children:at(W,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u91CF",width:t,children:({summary:m,stats:f,site:d})=>{let h=[{label:"\u8D26\u6237\u4F59\u989D",value:Te(m.balance,d.quotaPerUsd)},{label:"\u4ECA\u65E5\u8BF7\u6C42",value:Oe(m.today.requests)},{label:"\u4ECA\u65E5 Token",value:Oe(m.today.tokens)},{label:"\u4ECA\u65E5\u6D88\u8017",value:Te(m.today.cost,d.quotaPerUsd)}],y=[{label:"\u8BF7\u6C42\u6570",value:Oe(f.totals.requests)},{label:"Token \u603B\u91CF",value:qn(f.totals.tokens)},{label:"\u6D88\u8017",value:Te(f.totals.cost,d.quotaPerUsd)},{label:"\u6D3B\u8DC3\u5929\u6570",value:Oe(f.activeDays)},{label:"\u5F53\u524D\u8FDE\u7EED",value:`${f.currentStreak} \u5929`},{label:"\u6700\u957F\u8FDE\u7EED",value:`${f.longestStreak} \u5929`},{label:"\u9AD8\u5CF0\u65F6\u6BB5",value:hv(f.hourly)},{label:"\u5E38\u7528\u6A21\u578B",value:f.models[0]?.displayName??"\u2014"}],g=t-pe,x=C=>Bt+C+Ut(h.length,g)+Q+Bt+C+fv+C+Ut(y.length,g)+Q+Bt+C,T=n-x(We)>=Sa?We:0,R=n-x(T),b=Q+Bt+T+Rh,S=i==="chart"&&f.chart.points.length>0&&R>=b+Sa,v=i==="heatmap"&&ar(g)&&R-(Q+To)>=Sa,M=v?Q+To:0,N=S?Math.min(gv,Rh+Math.floor((R-b-Sa)/2)):0,O=R-M-(S?Q+Bt+T+N:0),U=C=>`${(f.totals.tokens>0?C/f.totals.tokens*100:0).toFixed(1)}%`;return Ch(Ao,{flexDirection:"column",children:[at(de,{title:"\u6982\u89C8",width:t,gap:T,children:at(it,{width:g,tiles:h})}),at(Ao,{marginTop:1,flexDirection:"column",children:Ch(de,{title:"\u533A\u95F4\u7EDF\u8BA1",width:t,gap:T,children:[at(js,{options:bh.map(C=>({value:C,label:pv[C]})),value:o,onChange:r}),at(Ao,{marginTop:T,children:at(it,{width:g,tiles:y})}),v&&at(Ao,{marginTop:1,flexDirection:"column",children:at(cr,{data:f.heatmap,value:C=>C.cost,caption:a,width:g})})]})}),S&&at(Ao,{marginTop:1,flexDirection:"column",children:at(de,{title:"\u7528\u91CF\u8D8B\u52BF",note:"\u67F1\u8272\u7531\u4EAE\u81F3\u6697\u5BF9\u5E94\u7528\u91CF\u524D\u4E94\u7684\u6A21\u578B\uFF0C\u7070\u8272\u4E3A\u5176\u4ED6",width:t,gap:T,children:at(vh,{data:f.chart,order:f.models.map(C=>C.model),width:g,rows:N})})}),at(Ao,{marginTop:1,flexDirection:"column",children:at(de,{title:"\u6A21\u578B\u7528\u91CF",width:t,gap:T,children:f.models.length===0?at(he,{tone:"info",width:g,title:"\u6682\u65E0\u7528\u91CF\u6570\u636E",detail:"\u8C03\u7528 API \u540E\u8FD9\u91CC\u4F1A\u663E\u793A\u5404\u6A21\u578B\u7684\u6BCF\u65E5 Token \u7528\u91CF"}):at(ue,{retain:"list",items:f.models,width:g,height:O,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u603B Token",align:"right"},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u5360\u6BD4",align:"right"}],row:C=>[C.displayName,qn(C.tokens),qn(C.inTokens),qn(C.outTokens),U(C.tokens)],searchOf:C=>C.displayName})})})]})}})})})}import{Box as yr,Text as tm}from"ink";import{useState as Eh}from"react";import{z as bv}from"zod";import{z as ft}from"zod";var yv=ft.object({id:ft.number().int(),name:ft.string(),description:ft.string(),multiplier:ft.number()}),xa=()=>P(ft.array(yv),"/groups"),em=ft.object({id:ft.number().int(),name:ft.string(),keyPrefix:ft.string(),keySuffix:ft.string(),groupId:ft.number().int().nullable(),groupName:ft.string().nullable(),usedQuota:ft.number(),quotaLimit:ft.number().nullable()}),Ta=()=>P(ft.array(em),"/tokens"),Ph=e=>P(em.extend({token:ft.string()}),"/tokens",{method:"POST",json:e}),wa=(e,t)=>P(em,`/tokens/${e}`,{method:"PATCH",json:t}),Ah=e=>P(se,`/tokens/${e}`,{method:"DELETE"});import{jsx as ct,jsxs as ka}from"react/jsx-runtime";var Mh={model:"",requestId:"",token:"",group:"",status:"",range:"today",since:"",until:""},Ih=bv.iso.date();function Sv(e){let t=Mc();return e.range==="today"?{since:t,until:t}:e.range==="7d"?{since:Gn(t,-6),until:t}:e.range==="30d"?{since:Gn(t,-29),until:t}:e.range==="custom"?{...e.since===""?{}:{since:e.since},...e.until===""?{}:{until:e.until}}:{}}function Nh(e){let t=Sv(e);return{...e.model.trim()===""?{}:{model:e.model.trim()},...e.requestId.trim()===""?{}:{requestId:e.requestId.trim()},...e.token===""?{}:{token:e.token},...e.group===""?{}:{group:e.group},...e.status===""?{}:{status:e.status},...t.since===void 0?{}:{since:Ic(t.since).toISOString()},...t.until===void 0?{}:{until:Ic(Gn(t.until,1)).toISOString()}}}var xv=_t(tc,Yi,"\u5168\u90E8\u72B6\u6001"),Tv=[{value:"",label:"\u4E0D\u9650"},{value:"today",label:"\u4ECA\u5929"},{value:"7d",label:"\u8FD1 7 \u5929"},{value:"30d",label:"\u8FD1 30 \u5929"},{value:"custom",label:"\u81EA\u5B9A\u4E49\u8D77\u6B62"}];function wv({log:e,quotaPerUsd:t,width:n}){let o=n-pe,r=Yi(e.status),i=ht(r),s=e.status!=="anomaly"?null:e.totalTokens>0?"\u672C\u6B21\u8C03\u7528\u672A\u8FD4\u56DE\u7528\u91CF\u6570\u636E\uFF0C\u8D39\u7528\u6309\u8BF7\u6C42\u4E0E\u54CD\u5E94\u7684\u6587\u672C\u91CF\u4F30\u7B97":"\u672C\u6B21\u8C03\u7528\u672A\u8FD4\u56DE\u7528\u91CF\u6570\u636E\u4E14\u65E0\u6CD5\u4F30\u7B97\uFF0C\u672A\u8BA1\u8D39",a=[];e.cachedTokens>0&&a.push(["\u7F13\u5B58\u8BFB",Oe(e.cachedTokens)]),e.cacheWriteTokens>0&&a.push(["\u7F13\u5B58\u5199",Oe(e.cacheWriteTokens)]),e.cacheWrite1hTokens>0&&a.push(["\u7F13\u5B58\u5199 1h",Oe(e.cacheWrite1hTokens)]),e.webSearchRequests>0&&a.push(["\u7F51\u9875\u641C\u7D22",`${Oe(e.webSearchRequests)} \u6B21`]),e.imageGenerationCalls>0&&a.push(["\u56FE\u50CF\u751F\u6210",`${Oe(e.imageGenerationCalls)} \u6B21`]),e.firstByteMs!==null&&a.push(["\u9996\u5B57\u8282",`${ao(e.firstByteMs)} s`]),e.tierOver!==null&&a.push(["\u8F93\u5165\u957F\u5EA6",Sc(e.tierOver)]),e.paramMultipliers.length>0&&a.push(["\u547D\u4E2D\u53C2\u6570",_e(e.paramMultipliers.map(l=>`${l.value} \xD7${l.multiplier}`))]);let c=[["\u8BF7\u6C42 ID",e.requestId],["\u4EE4\u724C",e.tokenName],["\u5206\u7EC4",e.groupName],["\u8BF7\u6C42 IP",e.ip],["\u534F\u8BAE",bd(e.protocol)],["\u8BA1\u8D39\u6765\u6E90",e.subscriptionPlanName!==null?`\u8BA2\u9605 \xB7 ${e.subscriptionPlanName}`:"\u4F59\u989D"],["HTTP \u72B6\u6001",String(e.httpStatus)],...e.stopReason===null?[]:[["\u7ED3\u675F\u539F\u56E0",e.stopReason]]];return ka(de,{title:e.modelDisplayName,note:V(e.createdAt),width:n,children:[ka(tm,{wrap:"truncate",children:[ct(tm,{color:i===void 0?p.mutedForeground:tt[i],children:r.label}),ct(tm,{color:p.faintForeground,children:` ${_e([e.stream?"\u6D41\u5F0F":"",e.model])}`})]}),ct(yr,{marginTop:1,children:ct(it,{width:o,tiles:[{label:"\u8F93\u5165 Token",value:Oe(e.promptTokens)},{label:"\u8F93\u51FA Token",value:Oe(e.completionTokens)},{label:"\u6D88\u8017",value:Jo(e.quotaCost,t)},{label:"\u603B\u8017\u65F6",value:`${ao(e.latencyMs)} s`},{label:"\u6863\u4F4D",value:Or(e.tierOver)},{label:"\u5206\u7EC4\u500D\u7387",value:`\xD7${e.multiplier}`},{label:"\u53C2\u6570\u500D\u7387",value:`\xD7${Iu(e.paramMultipliers)}`},{label:"\u603B\u500D\u7387",value:`\xD7${Nu(e.multiplier,e.paramMultipliers)}`}]})}),s!==null&&ct(yr,{marginTop:1,children:ct(he,{tone:"warn",width:o,title:s})}),ct(yr,{marginTop:1,children:ct(Ye,{width:o,items:[...a,...c]})})]})}function Lh(){let e=L(),{width:t}=H(),n=te(),[o,r]=Eh({name:"list"}),[i,s]=Eh(Mh),{error:a,fail:c,reset:l}=le(),u=ee([e.revision],async()=>{let[g,x,T]=await Promise.all([xa(),Ta(),ze(e.ctx.site)]);return{groups:g,tokens:x,site:T}}),m=Ve([e.revision,JSON.stringify(i)],g=>Sh({page:g,...Nh(i)}),{retain:"page"}),f=ee([e.revision,JSON.stringify(i)],()=>xh(Nh(i))),d=o.name==="list";G((g,x)=>{d&&(g==="r"?e.reload():g==="f"?(l(),r({name:"filter"})):x.leftArrow?m.go(-1):x.rightArrow&&m.go(1))});let h=()=>{o.name==="list"?e.pop():(l(),r({name:"list"}))},y=JSON.stringify(i)!==JSON.stringify(Mh);return ct(K,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:h,children:ct(W,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7B5B\u9009\u9009\u9879",width:t,children:({groups:g,tokens:x,site:T})=>{if(o.name==="filter")return ct(ne,{title:"\u7B5B\u9009\u65E5\u5FD7",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"text",name:"model",label:"\u6A21\u578B",initial:i.model,placeholder:"\u641C\u7D22\u6A21\u578B ID \u6216\u540D\u79F0"},{kind:"text",name:"requestId",label:"\u8BF7\u6C42 ID",initial:i.requestId,placeholder:"\u641C\u7D22\u8BF7\u6C42 ID"},{kind:"select",name:"token",label:"\u4EE4\u724C",options:[{value:"",label:"\u5168\u90E8\u4EE4\u724C"},...[...new Set(x.map(b=>b.name))].map(b=>({value:b,label:b}))],initial:i.token},{kind:"select",name:"group",label:"\u5206\u7EC4",options:[{value:"",label:"\u5168\u90E8\u5206\u7EC4"},...g.map(b=>({value:b.name,label:b.name}))],initial:i.group},{kind:"select",name:"status",label:"\u72B6\u6001",options:xv,initial:i.status},{kind:"select",name:"range",label:"\u65F6\u95F4\u8303\u56F4",options:Tv,initial:i.range},{kind:"text",name:"since",label:"\u5F00\u59CB\u65E5\u671F",initial:i.since,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"},{kind:"text",name:"until",label:"\u7ED3\u675F\u65E5\u671F",initial:i.until,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"}],onCancel:h,onSubmit:b=>{let S=b.range??"",v=(b.since??"").trim(),M=(b.until??"").trim();if(S==="custom"&&(v!==""&&!Ih.safeParse(v).success||M!==""&&!Ih.safeParse(M).success)){c("\u65E5\u671F\u65E0\u6548");return}s({model:b.model??"",requestId:b.requestId??"",token:b.token??"",group:b.group??"",status:b.status??"",range:S,since:v,until:M}),m.reset(),r({name:"list"})}});if(o.name==="detail")return ct(wv,{log:o.log,quotaPerUsd:T.quotaPerUsd,width:t});let R=Ut(4,t);return ka(yr,{flexDirection:"column",children:[ct(yr,{height:R+1,flexDirection:"column",overflow:"hidden",children:ct(W,{state:f,loading:"\u6B63\u5728\u7EDF\u8BA1\u7B5B\u9009\u7ED3\u679C",width:t,children:b=>ct(it,{width:t,tiles:[{label:"\u6D88\u8017",value:Te(b.quotaCost,T.quotaPerUsd)},{label:"RPM",value:Oe(b.rpm)},{label:"TPM",value:Oe(b.tpm)},{label:"\u5E76\u53D1",value:Oe(b.concurrency)}]})})}),ct(W,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u4F7F\u7528\u65E5\u5FD7",width:t,children:b=>ka(yr,{flexDirection:"column",children:[ct(ue,{retain:"list",items:b.items,width:t,height:Math.max(3,n-2-R),columns:[{label:"\u65F6\u95F4"},{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u6D88\u8017",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:S=>[V(S.createdAt),S.modelDisplayName,Oe(S.promptTokens),Oe(S.completionTokens),Jo(S.quotaCost,T.quotaPerUsd),yt(Yi(S.status))],onOpen:S=>r({name:"detail",log:S}),emptyLabel:y?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u8C03\u7528\u8BB0\u5F55",emptyDescription:y?void 0:"\u901A\u8FC7\u4EE4\u724C\u8C03\u7528 API \u540E\uFF0C\u660E\u7EC6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),ct(Ke,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})}})})}import{Box as Dn,Text as Eo}from"ink";import{useState as Pv}from"react";import{z as we}from"zod";var kv=bc.extend({id:we.number().int(),model:we.string(),displayName:we.string(),rules:_u}),vv=we.object({quotaPerUsd:we.number(),minTopupCny:we.number(),models:we.array(kv)});function va(e){return fn(vv,`${e}/api/pricing`)}var Rv=we.object({cnyPerUsd:we.number(),groups:we.array(we.object({id:we.number().int(),name:we.string(),description:we.string(),multiplier:we.number()})),stats:we.object({requests:we.number(),errors:we.number(),latencyP50Ms:we.number().nullable(),firstByteP50Ms:we.number().nullable()}),heartbeat:we.object({groups:we.array(we.object({id:we.number().int(),name:we.string(),minutes:we.array(we.object({requests:we.number(),errors:we.number()}))}))})});function Oh(e){return P(Rv,`/pricing/${e}`)}var Cv=we.object({data:we.array(we.object({id:we.string()}))});async function Dh(e,t,n){return(await fn(Cv,`${e}/v1/models`,{headers:{authorization:`Bearer ${t}`},...n===void 0?{}:{timeoutMs:n}})).data.map(r=>r.id)}var $h=()=>P(Ou,"/provider-status");import{Text as br}from"ink";import{jsx as Ra,jsxs as Bh}from"react/jsx-runtime";var _v=` ${ie.bullet} `,Fh=1;function Uh({providers:e}){return Bh(br,{wrap:"truncate",children:[Ra(br,{color:p.faintForeground,children:"\u5B98\u65B9\u72B6\u6001"}),e.map(t=>{let n=$u(t);return Bh(br,{children:[Ra(br,{color:p.faintForeground,children:_v}),Ra(br,{color:p.foreground,children:`${Sd(t.provider)} `}),Ra(br,{color:tt[n.tone],children:n.label})]},t.provider)})]})}import{jsx as Pe,jsxs as xi}from"react/jsx-runtime";var Av=4,Ev=1+We,Mv=e=>e.requests===0?p.border:e.errors===0?p.success:e.errors/e.requests>=.5?p.danger:p.warning;function Iv({minutes:e,width:t}){let n=e.slice(Math.max(0,e.length-t)),o=[];for(let r of n){let i=Mv(r),s=o[o.length-1];s!==void 0&&s.color===i?s.count+=1:o.push({color:i,count:1})}return Pe(Eo,{wrap:"truncate",children:o.map((r,i)=>Pe(Eo,{color:r.color,children:ie.barFilled.repeat(r.count)},i))})}function Nv({price:e,width:t,contentRows:n}){let o=L(),r=ee([e.id,o.revision],()=>Oh(e.id)),i=Eu(e,e.rules),s=i.length>1,a=e.rules.filter(Pu),c=t-pe,l=1+i.length,u=1+a.length;return Pe(W,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u8BE6\u60C5",width:t,children:m=>{let f=m.stats,d=[{label:"\u53EF\u7528\u7387",value:f.requests>0?`${((f.requests-f.errors)/f.requests*100).toFixed(1)}%`:"\u2014"},{label:"\u8C03\u7528\u6B21\u6570",value:Oe(f.requests)},{label:"\u5EF6\u8FDF P50",value:f.latencyP50Ms!==null?`${ao(f.latencyP50Ms)} s`:"\u2014"},{label:"\u9996\u5B57\u8282 P50",value:f.firstByteP50Ms!==null?`${ao(f.firstByteP50Ms)} s`:"\u2014"}],h=a.length>0?Q+Ze+u:0,y=Ev+Ze+Ut(d.length,c,2)+Q+Ze+l+h+Q+Ze,g=m.heartbeat.groups.length,x=n-y-Av-Q-Ze,T=Math.max(0,Math.floor(x/2));T<g&&(T=Math.max(0,Math.floor((x-1)/2))),T=Math.min(g,T);let R=T>0?Q+Ze+T*2+(T<g?1:0):0,b=Math.max(1,n-y-R);return xi(Dn,{flexDirection:"column",children:[Pe(Dn,{marginBottom:We,children:xi(Eo,{wrap:"truncate",children:[Pe(Eo,{bold:!0,color:p.foreground,children:e.displayName}),Pe(Eo,{color:p.faintForeground,children:` ${e.model}`})]})}),Pe(de,{title:"\u8FD1 24 \u5C0F\u65F6",note:"\u5168\u90E8\u5206\u7EC4\u7684\u7EFC\u5408\u8C03\u7528\u7EDF\u8BA1",width:t,children:Pe(it,{width:c,tiles:d,maxPerRow:2})}),T>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:xi(de,{title:"\u53EF\u7528\u6027",note:"\u6700\u8FD1\u4E00\u6BB5\u65F6\u95F4\u5404\u5206\u7EC4\u7684\u8C03\u7528\u5065\u5EB7\u72B6\u51B5",width:t,children:[m.heartbeat.groups.slice(0,T).map(S=>xi(Dn,{flexDirection:"column",children:[Pe(Eo,{wrap:"truncate",color:p.foreground,children:S.name}),Pe(Iv,{minutes:S.minutes,width:c})]},S.id)),T<g&&Pe(Eo,{color:p.faintForeground,children:`\u5176\u4F59 ${g-T} \u4E2A\u5206\u7EC4\u672A\u663E\u793A`})]})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(de,{title:"\u6A21\u578B\u4EF7\u683C",note:"\u6BCF\u767E\u4E07 Token \u7684\u7F8E\u5143\u6807\u4EF7",width:t,children:Pe(ue,{items:i,width:c,height:l,columns:[{label:"\u6863\u4F4D"},...s?[{label:"\u8F93\u5165\u957F\u5EA6"}]:[],{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:S=>[S.name,...S.range===null?[]:[S.range],pn(S.price.inputPricePerMillionTokens,"-"),pn(S.price.outputPricePerMillionTokens,"-"),pn(S.price.cachedInputPricePerMillionTokens,"-"),pn(S.price.cacheWritePricePerMillionTokens,"-")]})})}),a.length>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(de,{title:"\u8BF7\u6C42\u53C2\u6570\u500D\u7387",note:"\u547D\u4E2D\u65F6 Token \u8D39\u7528\u4E58\u4EE5\u500D\u7387\uFF0C\u591A\u6761\u547D\u4E2D\u4F9D\u6B21\u76F8\u4E58",width:t,children:Pe(ue,{items:a,width:c,height:u,columns:[{label:"\u53C2\u6570\u540D",shrink:!0},{label:"\u53C2\u6570\u503C",shrink:!0},{label:"\u500D\u7387",align:"right"}],row:S=>[S.param,S.value,`\xD7${S.multiplier}`]})})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(de,{title:"\u5206\u7EC4\u4EF7\u683C",note:"\u500D\u7387\u968F\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u800C\u5B9A\uFF0C\u5355\u4EF7\u4E3A 1 \u7F8E\u5143\u6807\u4EF7\u7528\u91CF\u7684\u4EBA\u6C11\u5E01\u4EF7\u683C",width:t,children:m.groups.length===0?Pe(he,{tone:"info",width:c,title:"\u6682\u65E0\u53EF\u7528\u5206\u7EC4",detail:"\u5F53\u524D\u6CA1\u6709\u542F\u7528\u7684\u6E20\u9053\u63D0\u4F9B\u8BE5\u6A21\u578B"}):Pe(ue,{items:m.groups,width:c,height:b,columns:[{label:"\u5206\u7EC4",shrink:!0},{label:"\u8BF4\u660E",shrink:!0},{label:"\u500D\u7387",align:"right"},{label:"\u5355\u4EF7",align:"right"}],row:S=>[S.name,S.description,`\xD7${S.multiplier}`,`\xA5${(m.cnyPerUsd*S.multiplier).toFixed(2)}`]})})})]})}})}function jh(){let e=L(),{width:t}=H(),n=te(),[o,r]=Pv({name:"list"}),i=ee([e.revision],async()=>(await va(e.ctx.site)).models),s=ee([e.revision],$h);G(c=>{c==="r"&&e.reload()});let a=()=>{o.name==="list"?e.pop():r({name:"list"})};return Pe(K,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","r \u5237\u65B0","Esc \u8FD4\u56DE"],onEscape:a,children:Pe(W,{state:i,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u5B9A\u4EF7",width:t,children:c=>{if(c.length===0)return Pe(he,{tone:"info",width:t,title:"\u6682\u65E0\u6A21\u578B"});if(o.name==="detail")return Pe(Nv,{price:o.price,width:t,contentRows:n});let l=s.phase==="ready"?Du(s.data.providers):[],u=l.length>0?Fh+Q:0;return xi(Dn,{flexDirection:"column",children:[l.length>0&&Pe(Dn,{marginBottom:Q,children:Pe(Uh,{providers:l})}),Pe(ue,{retain:"list",items:c,width:t,height:n-u,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:m=>[m.displayName,pn(m.inputPricePerMillionTokens,"-"),pn(m.outputPricePerMillionTokens,"-"),pn(m.cachedInputPricePerMillionTokens,"-"),pn(m.cacheWritePricePerMillionTokens,"-")],searchOf:m=>`${m.displayName} ${m.model}`,onOpen:m=>r({name:"detail",price:m}),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})]})}})})}import{Box as Mo,Text as mR}from"ink";import{useState as Na}from"react";function Hh(e,t){let n=e.line??t.apiLines[0];if(n===void 0)throw new j("\u7AD9\u70B9\u672A\u914D\u7F6E\u63A5\u5165\u7EBF\u8DEF",{hint:"\u8BF7\u8054\u7CFB\u7AD9\u70B9\u7BA1\u7406\u5458\u5728\u8BBE\u7F6E\u91CC\u6DFB\u52A0\u63A5\u5165\u7EBF\u8DEF"});return n}async function qh(e,t){let n=await ze(e.site);return Dh(Hh(fo(),n).url,t)}async function Gh(e,t,n){let o=await ze(e.site),r=Hh(fo(),o).url;return{input:{siteName:o.siteName,baseUrl:t.relayUrl(r),apiKey:n},at:t.resolveDir()}}async function Wh(e,t,n){let{input:o,at:r}=await Gh(e,t,n);t.apply(o,r)}async function zh(e,t,n,o,r){let{input:i,at:s}=await Gh(e,t,n);t.apply({...i,model:o,models:r},s)}import{homedir as Zh}from"os";import{join as _a,resolve as Bv}from"path";import Lv from"json5";import{applyEdits as Ov,modify as Dv,parse as $v}from"jsonc-parser";function Vh(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw new j(`${t} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);return e}function Kh(e){let t=[],n=$v(e,t,{allowTrailingComma:!0});return t.length>0?null:n}function Yh(e,t){let n=Kh(e);if(n!==null)return{root:Vh(n,t),jsonc:!0};try{return{root:Vh(Lv.parse(e),t),jsonc:!1}}catch(o){throw new j(`${t} \u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:o})}}function no(e,t){let n=e;for(let o of t){if(typeof n!="object"||n===null||Array.isArray(n))return;n=n[o]}return n}function Ti(e){let t=Nt(e);return t===null?null:Yh(t,e).root}function $n(e,t){let n=Ti(e),o=n===null?void 0:no(n,t);return typeof o=="string"?o:null}function Ca(e,t){let n=Ti(e);return n!==null&&no(n,t)!==void 0}function Gt(e,t){let n=Nt(e)??"{}",o=n.includes(`\r
18
+ ${n}`}import{Box as Sg,Text as Yw}from"ink";import{useState as Ys}from"react";import{jsx as Kw}from"react/jsx-runtime";function ur({title:e,width:t,download:n,onCancel:o,onSaved:r}){let{busy:i,error:s,run:a}=ue();return Kw(te,{title:e,width:t,submitLabel:"\u4E0B\u8F7D",busy:i!==null,busyLabel:"\u6B63\u5728\u4E0B\u8F7D",error:s,fields:[{kind:"text",name:"path",label:"\u4FDD\u5B58\u8DEF\u5F84",placeholder:"\u7559\u7A7A\u4FDD\u5B58\u5230\u5F53\u524D\u76EE\u5F55",hint:"\u53EF\u586B\u76EE\u5F55\u6216\u5E26\u6587\u4EF6\u540D\u7684\u5B8C\u6574\u8DEF\u5F84",optional:!0}],onCancel:o,onSubmit:c=>{a("\u6B63\u5728\u4E0B\u8F7D",async()=>{let l=await n();return zf(c.path??"",l.fileName,l.bytes)},{onSuccess:r})}})}var dr={maxCount:Su,maxBytes:bu},Zn=e=>({kind:"textarea",name:"attachments",label:"\u9644\u4EF6\u8DEF\u5F84",rows:2,placeholder:"\u6BCF\u884C\u4E00\u4E2A\u672C\u5730\u6587\u4EF6\u8DEF\u5F84\uFF0C\u53EF\u7559\u7A7A",hint:`\u6700\u591A ${e.maxCount} \u4E2A\uFF0C\u5355\u4E2A\u4E0D\u8D85\u8FC7 ${e.maxBytes/1024/1024}MB`,optional:!0});import{jsx as On,jsxs as ek}from"react/jsx-runtime";var Js=e=>e===null?void 0:`\u539F\u56E0\uFF1A${e}`,pr=(e,t)=>e===null?0:ul(Lc(e.until),Js(e.reason),t)+1;function ko({muted:e,width:t}){return e===null?null:On(Sg,{marginBottom:1,children:On(ye,{tone:"warn",width:t,title:Lc(e.until),detail:Js(e.reason),wrap:!0})})}var Xs=(e,t,n,o)=>t==="published"?0:ul(e[t],Js(n),o);function vo({notices:e,status:t,reason:n,width:o}){return t==="published"?null:On(ye,{tone:t==="pending"?"warn":"fail",title:e[t],detail:Js(n),width:o,wrap:!0})}var pi=e=>e===null?0:(e.hint===void 0?1:2)+1,Jw=["content","attachments"],Xw=9,Qw=3,Zw=8;function Qs({postId:e,replyTo:t,width:n,height:o,onDone:r,onCancel:i}){let{busy:s,error:a,fail:c,run:l}=ue(),[u,m]=Ys({content:"",attachments:""}),[p,d]=Ys(!1),b=Jw.some(g=>(u[g]??"").trim()!==""),h=Math.min(Zw,Math.max(Qw,o-Xw-pi(a)));return Re(b),gn(()=>d(!1),{isActive:p,layer:Wn.panel}),G(g=>{g==="q"&&b&&d(!0)},!p&&s===null),p?On(Ae,{width:n,title:t===null?"\u653E\u5F03\u8BC4\u8BBA":"\u653E\u5F03\u56DE\u590D",detail:t===null?"\u8BC4\u8BBA\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F":"\u56DE\u590D\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03",onConfirm:i,onCancel:()=>d(!1)}):On(te,{title:t===null?"\u53D1\u8868\u8BC4\u8BBA":`\u56DE\u590D ${t.mention}`,width:n,submitLabel:t===null?"\u53D1\u8868\u8BC4\u8BBA":"\u53D1\u8868\u56DE\u590D",busy:s!==null,busyLabel:s??"\u6B63\u5728\u63D0\u4EA4",error:a,fields:[{kind:"textarea",name:"content",label:"\u5185\u5BB9",rows:h,maxLength:xc,initial:u.content,placeholder:t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9\uFF0C\u652F\u6301 Markdown":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9"},{...Zn(Vs),initial:u.attachments}],onChange:m,onCancel:()=>b?d(!0):i(),onSubmit:g=>{let x=(g.content??"").trim(),T;try{T=Jn(g.attachments??"",Vs)}catch(k){c(xe(k));return}if(x===""&&T.length===0){c(t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9");return}if(jt(x).length+T.length>Vs.maxCount){c("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return}l("\u6B63\u5728\u63D0\u4EA4",()=>Mn(T,si,k=>hf(e,{content:di(x,k),...t===null?{}:{replyToId:t.id}})),{onSuccess:k=>r(k.id)})}})}function Zs({target:e,width:t,onDone:n,onCancel:o}){let{busy:r,error:i,fail:s,run:a}=ue();return On(te,{title:e.kind==="post"?"\u4E3E\u62A5\u5E16\u5B50":"\u4E3E\u62A5\u8BC4\u8BBA",width:t,submitLabel:"\u63D0\u4EA4\u4E3E\u62A5",busy:r!==null,busyLabel:r??"\u6B63\u5728\u63D0\u4EA4",error:i,fields:[{kind:"select",name:"reason",label:"\u4E3E\u62A5\u539F\u56E0",options:[{value:"",label:"\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0"},...Pi.map(c=>({value:c,label:kd(c)}))],initial:""},{kind:"text",name:"detail",label:"\u8865\u5145\u8BF4\u660E",placeholder:"\u8BF4\u660E\u5177\u4F53\u95EE\u9898\uFF0C\u4FBF\u4E8E\u7BA1\u7406\u5458\u6838\u5B9E",optional:!0}],onCancel:o,onSubmit:c=>{let l=Pi.find(p=>p===c.reason);if(l===void 0){s("\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0");return}let u=(c.detail??"").trim();if(u.length>$i){s(`\u8865\u5145\u8BF4\u660E\u6700\u591A ${$i} \u4E2A\u5B57\u7B26`);return}let m={reason:l,detail:u===""?null:u};a("\u6B63\u5728\u63D0\u4EA4",()=>e.kind==="post"?Tf(e.id,m):wf(e.id,m),{onSuccess:n})}})}function ea({refs:e,width:t,height:n}){let o=O(),[r,i]=Ys(null),[s,a]=Ys(null);return r!==null?On(ur,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${st(r.name)}`,width:t,download:async()=>{let c=await Df(r.id);return{fileName:st(c.fileName),bytes:c.bytes}},onCancel:()=>i(null),onSaved:c=>{i(null),a(c),o.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):ek(Sg,{flexDirection:"column",children:[On(le,{width:t,height:Math.max(3,n-(s===null?0:1)),items:[{heading:"\u9644\u4EF6"},...e.map(c=>({value:c,label:Fl(c)}))],onSelect:c=>{a(null),i(c)}}),s!==null&&On(Yw,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${st(s)}`})]})}import{Fragment as ck,jsx as me,jsxs as xn}from"react/jsx-runtime";var nk={cli:"\u547D\u4EE4\u884C",mobile:"\u624B\u673A",tablet:"\u5E73\u677F",smarttv:"\u667A\u80FD\u7535\u89C6",console:"\u6E38\u620F\u4E3B\u673A",wearable:"\u53EF\u7A7F\u6234\u8BBE\u5907",embedded:"\u5D4C\u5165\u5F0F\u8BBE\u5907"},Tg="\u5BC6\u94A5 ",ok=10,rk={rebind:{title:"\u91CD\u65B0\u7ED1\u5B9A\u4E24\u6B65\u9A8C\u8BC1",submit:"\u7EE7\u7EED",hint:"\u786E\u8BA4\u540E\u751F\u6210\u65B0\u5BC6\u94A5\uFF0C\u9A8C\u8BC1\u5668\u4E2D\u539F\u6709\u6761\u76EE\u5C06\u5931\u6548\uFF0C\u6062\u590D\u7801\u4E5F\u4F1A\u66F4\u6362"},regenerate:{title:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",submit:"\u751F\u6210",hint:"\u751F\u6210\u540E\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},disable:{title:"\u505C\u7528\u4E24\u6B65\u9A8C\u8BC1",submit:"\u505C\u7528",hint:"\u505C\u7528\u540E\u767B\u5F55\u4E0D\u518D\u8981\u6C42\u52A8\u6001\u7801\uFF0C\u6062\u590D\u7801\u540C\u65F6\u4F5C\u5E9F"}},ik=3,sk=8;function ak({codes:e,width:t}){let n=Math.max(...e.map(r=>r.length))+4,o=[];for(let r=0;r<e.length;r+=2)o.push(xn(fi,{wrap:"truncate",color:f.accent,children:[Je(e[r]??"",Math.min(n,t)),e[r+1]??""]},r));return me(at,{flexDirection:"column",children:o})}function wg(){let e=O(),{width:t,columns:n,rows:o}=j(),r=Z(),[i,s]=xg({name:"menu"}),[a,c]=xg(!1),{busy:l,error:u,reset:m,fail:p,run:d}=ue(),b=Q([e.revision],async()=>{let[S,y,R,N]=await Promise.all([En(),Ef(),_f(),$f()]);return{user:S.user,security:y,sessions:R.sessions,avatarReview:N.review}}),h=Q([e.revision],async()=>{let[S,y]=await Promise.all([En(),mf()]);return{homepage:await vl(S.user.username),todo:y}});G(S=>{i.name==="menu"&&l===null&&S==="r"&&e.reload()}),Re(i.name==="codes"||l!==null);let g=()=>{if(i.name!=="codes"){if(i.name==="menu"){e.pop();return}m(),i.name==="passkey-rename"||i.name==="passkey-delete"?s({name:"passkey",item:i.item}):i.name==="confirm-revoke"?s({name:"session",item:i.item}):s({name:"menu"})}},x=S=>{s({name:"menu"}),e.reload(),e.toast("ok",S)},T=(S,y)=>{c(!1),s({name:"codes",codes:S,message:y})},k=(S,y)=>{S==="rebind"?d("\u6B63\u5728\u751F\u6210\u65B0\u5BC6\u94A5",()=>Cl({code:y}),{onSuccess:R=>s({name:"enroll",setup:R})}):S==="regenerate"?d("\u6B63\u5728\u751F\u6210\u6062\u590D\u7801",()=>Nf({code:y}),{onSuccess:({recoveryCodes:R})=>T(R,"\u6062\u590D\u7801\u5DF2\u66F4\u65B0")}):d("\u6B63\u5728\u505C\u7528",()=>If({code:y}),{onSuccess:()=>x("\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u505C\u7528")})};return me(Y,{hints:i.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","r \u5237\u65B0"]:i.name==="codes"?["\u2191\u2193 \u79FB\u52A8","Enter \u786E\u8BA4"]:["Esc \u8FD4\u56DE"],locked:i.name==="codes",onEscape:g,isActive:l===null,children:me(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u8D26\u6237\u4FE1\u606F",width:t,children:({user:S,security:y,sessions:R,avatarReview:N})=>{if(i.name==="avatar")return xn(at,{flexDirection:"column",children:[N!==null&&me(at,{marginBottom:1,children:me(vo,{notices:Ic,status:N.status,reason:N.reviewReason,width:t})}),me(te,{title:"\u4FEE\u6539\u5934\u50CF",width:t,submitLabel:"\u4E0A\u4F20",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4E0A\u4F20",error:u,fields:[{kind:"text",name:"path",label:"\u56FE\u7247\u8DEF\u5F84",placeholder:"\u672C\u5730\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84"}],onCancel:g,onSubmit:w=>{let F=(w.path??"").trim();if(F===""){p("\u8BF7\u8F93\u5165\u56FE\u7247\u8DEF\u5F84");return}let re;try{re=Gf(F,Dr)}catch(D){p(xe(D));return}d("\u6B63\u5728\u4E0A\u4F20",()=>Bf(re),{onSuccess:()=>x("\u5DF2\u63D0\u4EA4\u5BA1\u6838")})}})]});if(i.name==="avatar-delete")return me(Ae,{width:t,title:"\u786E\u8BA4\u5220\u9664\u5934\u50CF\uFF1F",detail:"\u5220\u9664\u540E\u663E\u793A\u9ED8\u8BA4\u5934\u50CF",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Ff(),{onSuccess:()=>x("\u5934\u50CF\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="rename")return me(te,{title:"\u4FEE\u6539\u7528\u6237\u540D",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",initial:S.username,placeholder:"\u8BF7\u8F93\u5165\u65B0\u7528\u6237\u540D"}],onCancel:g,onSubmit:w=>{let F=(w.username??"").trim();if(F===""||F.length>Kt){p(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>kf({username:F}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="email")return me(te,{title:"\u4FEE\u6539\u90AE\u7BB1",width:t,submitLabel:"\u786E\u8BA4\u4FEE\u6539",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"email",label:"\u65B0\u90AE\u7BB1",placeholder:"\u7528\u4E8E\u767B\u5F55\u4E0E\u63A5\u6536\u901A\u77E5\u7684\u65B0\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",emailField:"email",send:w=>Cf({email:w})},{kind:"text",name:"password",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u7ACB\u5373\u4EE5\u65B0\u90AE\u7BB1\u767B\u5F55\u548C\u63A5\u6536\u901A\u77E5\uFF0C\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"}],onCancel:g,onSubmit:w=>{let F=(w.email??"").trim(),re=(w.code??"").trim(),D=w.password??"";if(F===""||re===""||D===""){p("\u8BF7\u586B\u5199\u65B0\u90AE\u7BB1\u3001\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Rf({email:F,code:re,password:D}),{onSuccess:()=>x("\u90AE\u7BB1\u5DF2\u4FEE\u6539")})}});if(i.name==="password")return me(te,{title:"\u4FEE\u6539\u5BC6\u7801",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"old",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801"},{kind:"text",name:"next",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u65B0\u5BC6\u7801",hint:`\u81F3\u5C11 ${Ot} \u4F4D\uFF0C\u4FDD\u5B58\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55`}],onCancel:g,onSubmit:w=>{let F=w.old??"",re=w.next??"";if(F===""){p("\u8BF7\u586B\u5199\u5F53\u524D\u5BC6\u7801");return}if(re.length<Ot){p(`\u65B0\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>vf({oldPassword:F,newPassword:re}),{onSuccess:()=>x("\u5BC6\u7801\u5DF2\u4FEE\u6539")})}});if(i.name==="confirm-logout-all")return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u6240\u6709\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",detail:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u9000\u51FA",()=>Af(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u6240\u6709\u8BBE\u5907"),e.home()}}),onCancel:g});if(i.name==="code"){let w=rk[i.intent];return me(te,{title:w.title,width:t,submitLabel:w.submit,busy:l!==null,busyLabel:l??"\u6B63\u5728\u5904\u7406",error:u,fields:[{kind:"text",name:"code",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",placeholder:"\u9A8C\u8BC1\u5668\u663E\u793A\u7684 6 \u4F4D\u6570\u5B57",hint:w.hint}],onCancel:g,onSubmit:F=>{let re=(F.code??"").trim();if(re===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}k(i.intent,re)}})}if(i.name==="enroll"){let w=(re,D)=>xn(ck,{children:[D&&me(fi,{color:f.mutedForeground,children:"\u4F7F\u7528 Google Authenticator \u7B49\u9A8C\u8BC1\u5668 App \u626B\u7801\u6DFB\u52A0"}),xn(fi,{children:[me(fi,{color:f.mutedForeground,children:Tg}),me(fi,{color:f.accent,children:i.setup.secret})]}),me(at,{marginTop:1,children:me(te,{title:"\u586B\u5165\u52A8\u6001\u9A8C\u8BC1\u7801\u5B8C\u6210\u7ED1\u5B9A",width:re,submitLabel:"\u7ED1\u5B9A",busy:l!==null,busyLabel:l??"\u6B63\u5728\u7ED1\u5B9A",error:u,fields:[{kind:"text",name:"code",label:"\u52A8\u6001\u9A8C\u8BC1\u7801"}],onCancel:g,onSubmit:z=>{let ee=(z.code??"").trim();if(ee===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}d("\u6B63\u5728\u7ED1\u5B9A",()=>Mf({code:ee}),{onSuccess:({recoveryCodes:he})=>T(he,"\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u7ED1\u5B9A")})}})})]}),F=js(i.setup.otpauthUri,{width:t,rows:r},{columns:tk(Tg)+i.setup.secret.length,rows:ok},{columns:n-t,rows:o-r});return F.fits?me(Hs,{value:i.setup.otpauthUri,aside:w(F.asideWidth,!0)}):xn(at,{flexDirection:"column",children:[me(ye,{tone:"info",width:t,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u6539\u4E3A\u624B\u52A8\u5F55\u5165",detail:"\u5728\u9A8C\u8BC1\u5668\u4E2D\u9009\u62E9\u624B\u52A8\u8F93\u5165\uFF0C\u586B\u5165\u4E0B\u65B9\u5BC6\u94A5"}),w(t,!1)]})}if(i.name==="codes")return xn(at,{flexDirection:"column",children:[me(ye,{tone:"warn",width:t,title:"\u6062\u590D\u7801\u4EC5\u6B64\u4E00\u6B21\u5C55\u793A\uFF0C\u8BF7\u7ACB\u5373\u4FDD\u5B58\u5230\u5B89\u5168\u7684\u4F4D\u7F6E",detail:"\u6BCF\u679A\u6062\u590D\u7801\u53EA\u80FD\u4F7F\u7528\u4E00\u6B21\uFF0C\u53EF\u5728\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u4EE3\u66FF\u52A8\u6001\u9A8C\u8BC1\u7801\u767B\u5F55"}),me(at,{marginTop:1,children:me(ak,{codes:i.codes,width:t})}),me(at,{marginTop:1,children:me(le,{width:t,items:[{value:"ack",label:`${a?"[x]":"[ ]"} \u6211\u5DF2\u59A5\u5584\u4FDD\u5B58\u8FD9\u4E9B\u6062\u590D\u7801`},{value:"done",label:"\u5B8C\u6210",disabled:!a}],onSelect:w=>{if(w==="ack"){c(re=>!re);return}let F=i.message;s({name:"menu"}),e.reload(),e.toast("ok",F)}})})]});if(i.name==="passkey-add")return me(ye,{tone:"info",width:t,title:`\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00 ${e.ctx.site} \u7684\u300C\u4E2A\u4EBA\u4E3B\u9875\u300D\u5B8C\u6210\u6DFB\u52A0`,detail:"\u6DFB\u52A0\u4E0E\u4F7F\u7528 Passkey \u4F9D\u8D56\u6D4F\u89C8\u5668\u7684 WebAuthn \u80FD\u529B\uFF0C\u7EC8\u7AEF\u65E0\u6CD5\u5B8C\u6210"});if(i.name==="passkey-rename")return me(te,{title:`\u91CD\u547D\u540D Passkey ${i.item.name}`,width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:i.item.name,placeholder:"\u6807\u8BB0\u6240\u5728\u8BBE\u5907\uFF0C\u5982 MacBook \u6307\u7EB9"}],onCancel:g,onSubmit:w=>{let F=(w.name??"").trim();if(F===""){p("\u8BF7\u8F93\u5165\u540D\u79F0");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Lf(i.item.id,{name:F}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="passkey-delete")return me(Ae,{width:t,title:`\u786E\u8BA4\u5220\u9664 Passkey\u300C${i.item.name}\u300D\uFF1F`,detail:"\u5220\u9664\u540E\u65E0\u6CD5\u518D\u7528\u5B83\u767B\u5F55",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Of(i.item.id),{onSuccess:()=>x("\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="passkey"){let w=i.item;return me(at,{flexDirection:"column",children:xn(pe,{title:`Passkey ${w.name}`,width:t,children:[me(Ve,{width:t-ge,items:[["\u540D\u79F0",w.name],["\u6DFB\u52A0\u65F6\u95F4",K(w.createdAt)],["\u6700\u8FD1\u4F7F\u7528",w.lastUsedAt===null?"\u2014":K(w.lastUsedAt)]]}),me(at,{marginTop:1,children:me(le,{width:t-ge,items:[{value:"rename",label:"\u91CD\u547D\u540D"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:F=>{m(),s(F==="rename"?{name:"passkey-rename",item:w}:{name:"passkey-delete",item:w})}})})]})})}if(i.name==="confirm-revoke"){let w=i.item;return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u8BE5\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>{if(w.current){d("\u6B63\u5728\u9000\u51FA",()=>ns(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u767B\u5F55"),e.home()}});return}d("\u6B63\u5728\u9000\u51FA\u8BE5\u8BBE\u5907",()=>Pf(w.id),{onSuccess:()=>x("\u5DF2\u9000\u51FA\u8BE5\u8BBE\u5907")})},onCancel:g})}if(i.name==="session"){let w=i.item;return xn(at,{flexDirection:"column",children:[me(pe,{title:Go(w.device),note:w.current?"\u5F53\u524D\u8BBE\u5907":void 0,width:t,children:me(Ve,{width:t-ge,items:[["\u8BBE\u5907\u7C7B\u578B",w.device?.type!=null?nk[w.device.type]??w.device.type:"\u684C\u9762\u8BBE\u5907"],["\u5BA2\u6237\u7AEF",w.device?.client!=null?`${w.device.client} ${w.device.clientVersion??""}`.trim():"\u2014"],["\u64CD\u4F5C\u7CFB\u7EDF",w.device?.os!=null?`${w.device.os} ${w.device.osVersion??""}`.trim():"\u2014"],["\u8BBE\u5907\u578B\u53F7",w.device?.model!=null?`${w.device.vendor??""} ${w.device.model}`.trim():"\u2014"],["IP \u5730\u5740",w.ip],["\u767B\u5F55\u65F6\u95F4",K(w.loginAt)],["\u6700\u540E\u6D3B\u8DC3",K(w.lastActiveAt)],["\u767B\u5F55\u6709\u6548\u671F\u81F3",K(w.expiresAt)],["\u5BA2\u6237\u7AEF\u6807\u8BC6",w.userAgent??"\u2014"]]})}),l===null&&me(at,{marginTop:1,children:me(le,{width:t,items:[{value:"revoke",label:"\u9000\u51FA\u8BE5\u8BBE\u5907",labelTone:"danger"}],onSelect:()=>{m(),s({name:"confirm-revoke",item:w})}})})]})}let E=y.totp,W=h.phase==="ready"?h.data:null,M=W===null?null:W.todo,C=M===null?0:M.posts.filter(w=>w.status==="pending").length,v=M===null?0:M.posts.filter(w=>w.status==="rejected").length,_=_e([C>0&&`${C} \u7BC7\u5BA1\u6838\u4E2D`,v>0&&`${v} \u7BC7\u672A\u901A\u8FC7`]),L=[{heading:"\u793E\u533A"},{value:{kind:"my-posts"},label:"\u6211\u7684\u5E16\u5B50",hint:_===""?void 0:_},{value:{kind:"my-comments"},label:"\u6211\u7684\u8BC4\u8BBA"},{value:{kind:"bookmarks"},label:"\u6211\u7684\u6536\u85CF"},{value:{kind:"drafts"},label:"\u6211\u7684\u8349\u7A3F",hint:M!==null&&M.drafts>0?`${M.drafts} \u7BC7\u672A\u53D1\u5E03`:void 0},{heading:""},{heading:"\u8D26\u6237"},{value:{kind:"avatar"},label:"\u4FEE\u6539\u5934\u50CF",hint:N===null?"\u663E\u793A\u5728\u4E2A\u4EBA\u4E3B\u9875\u548C\u4F60\u7684\u53D1\u8A00\u4E2D":ad(N)},{value:{kind:"rename"},label:"\u4FEE\u6539\u7528\u6237\u540D",hint:"\u4FEE\u6539\u540E\u4E2A\u4EBA\u4E3B\u9875\u5730\u5740\u968F\u4E4B\u6539\u53D8"},{value:{kind:"email"},label:"\u4FEE\u6539\u90AE\u7BB1",hint:"\u9700\u8981\u90AE\u7BB1\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801"},{value:{kind:"password"},label:"\u4FEE\u6539\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"},...S.avatarUrl===null?[]:[{value:{kind:"avatar-delete"},label:"\u5220\u9664\u5934\u50CF",labelTone:"danger"}],{heading:""},{heading:"\u4E24\u6B65\u9A8C\u8BC1"},...E.enabled?[{value:{kind:"code",intent:"rebind"},label:"\u91CD\u65B0\u7ED1\u5B9A",hint:"\u751F\u6210\u65B0\u5BC6\u94A5\u5E76\u66F4\u6362\u6062\u590D\u7801"},{value:{kind:"code",intent:"regenerate"},label:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",hint:"\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},{value:{kind:"code",intent:"disable"},label:"\u505C\u7528",labelTone:"danger"}]:[{value:{kind:"enable"},label:"\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",hint:"\u767B\u5F55\u65F6\u8981\u6C42\u989D\u5916\u8F93\u5165\u9A8C\u8BC1\u5668\u52A8\u6001\u7801"}],{heading:""},{heading:"Passkey"},...y.passkeys.length===0?[{value:{kind:"none"},label:"\u6682\u65E0 Passkey",hint:"\u6DFB\u52A0\u540E\u53EF\u4F7F\u7528\u6307\u7EB9\u3001\u9762\u5BB9\u6216\u786C\u4EF6\u5BC6\u94A5\u4E00\u6B65\u767B\u5F55",disabled:!0}]:[],...y.passkeys.map(w=>({value:{kind:"passkey",item:w},label:w.name,hint:`\u6700\u8FD1\u4F7F\u7528 ${w.lastUsedAt===null?"\u2014":K(w.lastUsedAt)}`})),{value:{kind:"add-passkey"},label:"\u6DFB\u52A0 Passkey",hint:"\u9700\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"},{heading:""},{heading:"\u767B\u5F55\u8BBE\u5907"},...R.map(w=>({value:{kind:"session",item:w},label:w.current?`${Go(w.device)}\uFF08\u5F53\u524D\u8BBE\u5907\uFF09`:Go(w.device),...w.current?{labelTone:"accent"}:{},hint:`${w.ip} \xB7 \u6700\u540E\u6D3B\u8DC3 ${K(w.lastActiveAt)}`})),{value:{kind:"logout-all"},label:"\u9000\u51FA\u6240\u6709\u8BBE\u5907",labelTone:"danger",hint:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA"}],P=W===null?null:W.homepage,B=[["\u7528\u6237\u540D",st(S.username)],["\u90AE\u7BB1",S.email],...E.enabled?[["\u4E24\u6B65\u9A8C\u8BC1",`\u542F\u7528\u4E8E ${E.enabledAt===null?"\u2014":K(E.enabledAt)}`],["\u6062\u590D\u7801",E.recoveryCodesRemaining===0?"\u5DF2\u5168\u90E8\u7528\u5B8C\uFF0C\u8BF7\u91CD\u65B0\u751F\u6210":`\u5269\u4F59 ${E.recoveryCodesRemaining} \u679A\uFF0C\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u53EF\u4EE3\u66FF\u52A8\u6001\u7801\u767B\u5F55`]]:[],...P===null?[]:[["\u7B49\u7EA7",qi(P.identity.points)],["\u79EF\u5206",`${P.identity.points} \xB7 ${Gi(P.identity.points)}`],["\u52A0\u5165\u65F6\u95F4",Ur(P.joinedAt)]]],J=h.phase==="error"?h:null,oe=P!==null?Ut(ik,t)+X:J!==null?(J.hint===void 0?1:2)+X:0,fe=zs(B.length,t)+X+oe,$=X+Xe+To,ne=P!==null&&cr(t)&&r-fe-$>=sk;return xn(at,{flexDirection:"column",children:[me(Ve,{width:t,items:B}),P!==null&&me(at,{marginTop:X,children:me(it,{width:t,tiles:[{label:"\u5E16\u5B50",value:String(P.stats.posts)},{label:"\u8BC4\u8BBA",value:String(P.stats.comments)},{label:"\u83B7\u8D5E",value:String(P.stats.likesReceived)}]})}),J!==null&&me(at,{marginTop:X,children:me(Ft,{message:`\u793E\u533A\u6570\u636E\u8BFB\u53D6\u5931\u8D25\uFF1A${J.message}`,hint:J.hint,width:t})}),ne&&xn(at,{marginTop:X,flexDirection:"column",children:[me(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:t}),me(at,{marginTop:qe,flexDirection:"column",children:me(lr,{data:P.activity,value:w=>w.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${P.activity.days.reduce((w,F)=>w+F.count,0)} \u6B21`,width:t})})]}),me(at,{marginTop:X,children:me(le,{width:t,height:Math.max(3,r-fe-(ne?$:0)),isActive:l===null,items:L,retain:"menu",onSelect:w=>{m(),w.kind==="my-posts"?e.push("my-posts",{username:S.username}):w.kind==="my-comments"?e.push("my-comments",{username:S.username}):w.kind==="bookmarks"?e.push("bookmarks"):w.kind==="drafts"?e.push("drafts"):w.kind==="avatar"?s({name:"avatar"}):w.kind==="avatar-delete"?s({name:"avatar-delete"}):w.kind==="rename"?s({name:"rename"}):w.kind==="email"?s({name:"email"}):w.kind==="password"?s({name:"password"}):w.kind==="logout-all"?s({name:"confirm-logout-all"}):w.kind==="enable"?d("\u6B63\u5728\u751F\u6210\u5BC6\u94A5",()=>Cl({}),{failToast:!0,onSuccess:F=>s({name:"enroll",setup:F})}):w.kind==="code"?s({name:"code",intent:w.intent}):w.kind==="add-passkey"?s({name:"passkey-add"}):w.kind==="passkey"?s({name:"passkey",item:w.item}):w.kind==="session"&&s({name:"session",item:w.item})}})})]})}})})}import{Box as oa,Text as ra,useInput as gk}from"ink";import{useRef as Mg,useState as fr}from"react";import hk from"string-width";import{z as Ct}from"zod";var lk=Ct.object({siteName:Ct.string(),apiLines:Ct.array(Ct.object({name:Ct.string(),description:Ct.string(),url:Ct.string()})),quotaPerUsd:Ct.number(),ticketAutoCloseMinutes:Ct.number(),legal:Ct.object({termsConfigured:Ct.boolean(),privacyConfigured:Ct.boolean()})});function Ge(e,t){return fn(lk,`${e}/api/site-config`,{...t===void 0?{}:{timeoutMs:t}})}var mk=Ct.object({content:Ct.string(),configured:Ct.boolean()});function kg(e,t){return fn(mk,`${e}/api/agreements/${t}`)}var vg=12e4,Cg=e=>A(mt(Ii),Fe("/tickets",{...e})),Rg=e=>A(yu,"/tickets",{method:"POST",json:e}),Ul=e=>A(wu,`/tickets/${e}`),_g=(e,t,n)=>A(se,`/tickets/${e}/messages`,{method:"POST",json:{content:t,attachmentIds:n}}),uk=e=>A(Tu,Fe("/tickets/attachments",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:vg}),dk=e=>A(se,`/tickets/attachments/${e}`,{method:"DELETE"}),ta={upload:uk,discard:dk},Pg=(e,t)=>rs(`/tickets/${e}/attachments/${t}`,{timeoutMs:vg}),Ag=e=>A(se,`/tickets/${e}/close`,{method:"POST"}),Eg=e=>A(se,`/tickets/${e}/reopen`,{method:"POST"});import{useEffect as pk,useRef as fk}from"react";function na(e,t,n=!0){let o=fk(t);o.current=t,pk(()=>{if(!n)return;let r=!1,i=setInterval(()=>{r||(r=!0,o.current().catch(()=>{}).finally(()=>{r=!1}))},e);return()=>clearInterval(i)},[e,n])}import{jsx as Ht,jsxs as jl}from"react/jsx-runtime";var yk=5e3,bk=11,Sk=3,Ig=1;function xk(e,t){let n=[],o=r=>{let i=r.spans.reduce((a,c)=>a+hk(c.text),0),s=Math.max(0,t-i);return s===0?r:{spans:[{text:" ".repeat(s)},...r.spans]}};return e.forEach((r,i)=>{i>0&&n.push({spans:[]});let s=r.author.kind==="user",a={spans:[{text:vt(r.author),color:s?f.accent:f.mutedForeground},{text:` ${K(r.createdAt)}`,color:f.faintForeground}]},c=r.content===""?[]:Pt([{text:Vn(r.content),color:f.foreground}],Math.max(8,t-4)),l=r.attachments.map(u=>({spans:[{text:"[\u9644\u4EF6] ",color:f.faintForeground},{text:u.fileName,color:f.foreground},{text:` (${Ko(u.fileSize)})`,color:f.mutedForeground}]}));s?n.push(o(a),...c.map(o),...l.map(o)):n.push(a,...c,...l)}),n}function Ng({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=fr("main"),[s,a]=fr(!1),[c,l]=fr(null),[u,m]=fr(null),[p,d]=fr(0),{busy:b,error:h,reset:g,fail:x,run:T}=ue();Re(b!==null);let k=Q([e.id,t.revision],async()=>{let[L,P]=await Promise.all([Ul(e.id),Ge(t.ctx.site)]);return{detail:L,site:P}}),[S,y]=fr(null),R=Mg(0),N=Mg(t.revision);N.current!==t.revision&&(N.current=t.revision,R.current+=1,S!==null&&y(null));let E=k.phase==="ready"?k.data:null,W=S??E?.detail??null;na(yk,async()=>{if(W===null||b!==null)return;let L=R.current,P=await Ul(e.id);L===R.current&&(P.ticket.updatedAt!==W.ticket.updatedAt||P.messages.length!==W.messages.length)&&y(P)},r==="main"&&E!==null);let M=W?.messages.some(L=>L.attachments.length>0)??!1;G(L=>{r!=="main"||s||b!==null||(L==="r"?t.reload():L==="x"&&W!==null&&W.ticket.status!=="closed"?(g(),i("confirm-close")):L==="a"&&M&&(g(),l(null),m(null),i("attachments")))}),gk((L,P)=>{P.tab&&r==="main"&&!s&&W?.ticket.status!=="closed"&&a(!0)},{isActive:r==="main"&&!s&&b===null});let C=()=>{if(r!=="main"){g(),i("main");return}if(s){a(!1);return}t.pop()},v=(L,P)=>{T("\u6B63\u5728\u53D1\u9001",()=>Mn(P,ta,B=>_g(e.id,L,B.map(J=>J.id))),{onSuccess:()=>{a(!1),d(B=>B+1),t.reload(),t.toast("ok","\u5DF2\u53D1\u9001")}})},_=r==="main"&&!s?["\u2191\u2193 \u6EDA\u52A8",...W?.ticket.status==="closed"?[]:["Tab \u56DE\u590D"],...M?["a \u9644\u4EF6"]:[],...W?.ticket.status==="closed"?[]:["x \u5173\u95ED\u5DE5\u5355"],"r \u5237\u65B0"]:[];return Ht(Y,{trail:["\u5DE5\u5355\u652F\u6301",W?.ticket.title??"\u5DE5\u5355\u8BE6\u60C5"],hints:_,onEscape:C,isActive:b===null,children:Ht(V,{state:k,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:n,children:({site:L,detail:P})=>{let B=S??P,J=B.ticket,oe=J.status==="closed";if(r==="confirm-close")return Ht(Ae,{width:n,title:"\u5173\u95ED\u5DE5\u5355",detail:`\u786E\u5B9A\u5173\u95ED\u5DE5\u5355\u300C${J.title}\u300D\u5417\uFF1F\u5173\u95ED\u540E\u53EF\u91CD\u65B0\u6253\u5F00`,confirmLabel:"\u5173\u95ED\u5DE5\u5355",busy:b,error:h,onConfirm:()=>T("\u6B63\u5728\u5173\u95ED",()=>Ag(e.id),{onSuccess:()=>{i("main"),t.reload(),t.toast("ok","\u5DF2\u5173\u95ED")}}),onCancel:C});if(r==="attachments")return u!==null?Ht(ur,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${u.fileName}`,width:n,download:async()=>({fileName:u.fileName,bytes:await Pg(e.id,u.id)}),onCancel:()=>m(null),onSaved:w=>{m(null),l(w),t.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):jl(oa,{flexDirection:"column",children:[Ht(le,{width:n,height:Math.max(3,o-1),isActive:b===null,items:[{heading:"\u9644\u4EF6"},...B.messages.flatMap(w=>w.attachments.map(F=>({value:F,label:F.fileName,hint:`${vt(w.author)} \xB7 ${Ko(F.fileSize)} \xB7 ${K(w.createdAt)}`})))],onSelect:w=>{l(null),m(w)}}),c!==null&&Ht(ra,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${c}`})]});let fe=L.ticketAutoCloseMinutes>0?Ig:0,$=oe?Sk:s?bk:Ig,ne=Math.max(3,o-fe-$-X);return jl(oa,{flexDirection:"column",children:[fe>0&&Ht(ra,{wrap:"truncate",color:f.faintForeground,children:`\u7BA1\u7406\u5458\u56DE\u590D\u540E\u8D85\u8FC7 ${L.ticketAutoCloseMinutes} \u5206\u949F\u672A\u56DE\u5E94\uFF0C\u5DE5\u5355\u5C06\u81EA\u52A8\u5173\u95ED\uFF1B\u5DF2\u5173\u95ED\u7684\u5DE5\u5355\u53EF\u968F\u65F6\u91CD\u65B0\u6253\u5F00`}),Ht(pt,{lines:xk(B.messages,n),height:ne,isActive:!s&&b===null,pinBottom:!0}),Ht(oa,{marginTop:1,flexDirection:"column",children:oe?jl(oa,{flexDirection:"column",children:[Ht(ra,{color:f.mutedForeground,children:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u5982\u9700\u7EE7\u7EED\u6C9F\u901A\u53EF\u91CD\u65B0\u6253\u5F00"}),Ht(le,{width:n,isActive:b===null,items:[{value:"reopen",label:"\u91CD\u65B0\u6253\u5F00"}],onSelect:()=>T("\u6B63\u5728\u91CD\u65B0\u6253\u5F00",()=>Eg(e.id),{failToast:!0,onSuccess:()=>{t.reload(),t.toast("ok","\u5DF2\u91CD\u65B0\u6253\u5F00")}})})]}):s?Ht(te,{title:"\u56DE\u590D\u5DE5\u5355",width:n,submitLabel:"\u53D1\u9001\u56DE\u590D",busy:b!==null,busyLabel:b??"\u6B63\u5728\u53D1\u9001",error:h,fields:[{kind:"textarea",name:"content",label:"\u56DE\u590D\u5185\u5BB9",rows:3,maxLength:5e3,placeholder:"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9",optional:!0},Zn(dr)],onCancel:()=>a(!1),onSubmit:w=>{let F=(w.content??"").trim(),re;try{re=Jn(w.attachments??"",dr)}catch(D){x(xe(D));return}if(F===""&&re.length===0){x("\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9\u6216\u9644\u4EF6\u8DEF\u5F84");return}v(F,re)}},p):Ht(ra,{color:f.faintForeground,children:"\u6309 Tab \u64B0\u5199\u56DE\u590D"})})]})}})})}import{Box as Tk}from"ink";import{useState as wk}from"react";import{jsx as Co,jsxs as Ck}from"react/jsx-runtime";var kk=_t(ec,Hc,"\u5168\u90E8\u72B6\u6001"),vk={title:"\u7B80\u8981\u63CF\u8FF0\u4F60\u7684\u95EE\u9898",content:"\u8BE6\u7EC6\u63CF\u8FF0\u9047\u5230\u7684\u95EE\u9898\uFF0C\u4FBF\u4E8E\u7BA1\u7406\u5458\u5FEB\u901F\u5B9A\u4F4D"},Hl={billing:{title:"\u7B80\u8FF0\u8BA1\u8D39\u6216\u989D\u5EA6\u7591\u95EE",content:"\u8BF4\u660E\u7591\u95EE\u6D89\u53CA\u7684\u65F6\u95F4\u6BB5\u3001\u6A21\u578B\u4E0E\u9884\u671F\u5DEE\u5F02\uFF0C\u53EF\u9644\u989D\u5EA6\u6D41\u6C34\u6216\u4F7F\u7528\u65E5\u5FD7\u4E2D\u7684\u8BB0\u5F55"},technical:{title:"\u7B80\u8FF0\u63A5\u53E3\u6216\u8C03\u7528\u95EE\u9898",content:"\u63CF\u8FF0\u62A5\u9519\u73B0\u8C61\u4E0E\u590D\u73B0\u6B65\u9AA4\uFF0C\u9644\u8BF7\u6C42 ID\u3001\u6A21\u578B\u540D\u3001\u53D1\u751F\u65F6\u95F4\u7B49\u4FE1\u606F"},account:{title:"\u7B80\u8FF0\u8D26\u53F7\u76F8\u5173\u95EE\u9898",content:"\u63CF\u8FF0\u767B\u5F55\u3001\u90AE\u7BB1\u6216\u5B89\u5168\u76F8\u5173\u7684\u5177\u4F53\u95EE\u9898\uFF0C\u5207\u52FF\u586B\u5199\u5BC6\u7801\u7B49\u654F\u611F\u4FE1\u606F"},other:vk};function Lg(){let e=O(),{width:t}=j(),n=Z(),[o,r]=wk({name:"list"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue(),p=ze([e.revision,i],h=>Cg({page:h,...i===""?{}:{status:i}}),{retain:"page"}),d=o.name==="list";G((h,g)=>{d&&(h==="r"?e.reload():h==="f"?r({name:"filter"}):h==="n"?r({name:"create-category"}):g.leftArrow?p.go(-1):g.rightArrow&&p.go(1))});let b=()=>{o.name==="list"?e.pop():o.name==="create"?r({name:"create-category"}):(l(),r({name:"list"}))};return Co(Y,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u65B0\u5EFA","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:b,children:o.name==="filter"?Co(te,{title:"\u7B5B\u9009\u5DE5\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:kk,initial:i}],onCancel:b,onSubmit:h=>{s(h.status??""),p.reset(),r({name:"list"})}}):o.name==="create-category"?Co(le,{width:t,height:n,items:[{heading:"\u5206\u7C7B"},...tc.map(h=>({value:h,label:Ji(h),hint:Hl[h].title}))],onSelect:h=>r({name:"create",category:h})}):o.name==="create"?Co(te,{title:`\u65B0\u5EFA\u5DE5\u5355 \u2014 ${Ji(o.category)}`,width:t,submitLabel:"\u63D0\u4EA4",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"select",name:"priority",label:"\u4F18\u5148\u7EA7",options:nc.map(h=>({value:h,label:qc(h).label})),initial:"normal"},{kind:"text",name:"title",label:"\u6807\u9898",placeholder:Hl[o.category].title},{kind:"textarea",name:"content",label:"\u95EE\u9898\u63CF\u8FF0",rows:5,maxLength:5e3,placeholder:Hl[o.category].content},Zn(dr)],onCancel:b,onSubmit:h=>{let g=(h.title??"").trim(),x=(h.content??"").trim();if(g===""){u("\u8BF7\u586B\u5199\u6807\u9898");return}if(x===""){u("\u8BF7\u586B\u5199\u95EE\u9898\u63CF\u8FF0");return}let T;try{T=Jn(h.attachments??"",dr)}catch(k){u(xe(k));return}m("\u6B63\u5728\u63D0\u4EA4\u5DE5\u5355",()=>Mn(T,ta,k=>Rg({title:g,category:o.category,priority:h.priority??"normal",content:x,attachmentIds:k.map(S=>S.id)})),{onSuccess:k=>{r({name:"list"}),p.reset(),e.reload(),e.push("ticket",{id:k.id}),e.toast("ok","\u5DE5\u5355\u5DF2\u63D0\u4EA4")}})}}):Co(V,{state:p.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:t,children:h=>Ck(Tk,{flexDirection:"column",children:[Co(de,{retain:"list",items:h.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u4F18\u5148\u7EA7"},{label:"\u5206\u7C7B"},{label:"\u6700\u540E\u66F4\u65B0"},{label:"\u72B6\u6001",align:"right"}],row:g=>[g.title,yt(qc(g.priority)),Ji(g.category),K(g.updatedAt),yt(Hc(g.status))],onOpen:g=>e.push("ticket",{id:g.id}),emptyLabel:i===""?"\u6682\u65E0\u5DE5\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u9047\u5230\u95EE\u9898\u65F6\u53EF\u65B0\u5EFA\u5DE5\u5355\uFF0C\u7BA1\u7406\u5458\u4F1A\u5C3D\u5FEB\u56DE\u590D":void 0}),Co(We,{page:p.page,pages:p.pages,total:p.total,width:t})]})})})}import{Box as Rk}from"ink";import{jsx as gi}from"react/jsx-runtime";function Og({params:e}){let t=O(),{width:n}=j(),o=Z(),r=Q([e.type,t.revision],()=>kg(t.ctx.site,e.type));return gi(Y,{trail:["\u6CD5\u5F8B\u6761\u6B3E",e.type==="terms"?"\u7528\u6237\u534F\u8BAE":"\u9690\u79C1\u653F\u7B56"],hints:["\u2191\u2193 \u6EDA\u52A8"],children:gi(V,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6761\u6B3E",width:n,children:i=>i.configured?gi(Rk,{flexDirection:"column",children:gi(pt,{lines:hn(i.content,n),height:o})}):gi(ye,{tone:"info",width:n,title:"\u8BE5\u6761\u6B3E\u5C1A\u672A\u914D\u7F6E"})})})}var Dg=(e,t)=>fn(se,`${e}/api/auth/send-code`,{json:t});async function $g(e,t){let n=await Jt(`${e}/api/auth/register`,{json:t});sn(n);let o=zo.parse(n.data);return Wr(e,zr({refresh:null,device:null},n.headers),o)}var Bg=(e,t)=>fn(se,`${e}/api/auth/forgot-password`,{json:t}),Fg=(e,t)=>fn(se,`${e}/api/auth/reset-password`,{json:t});import{jsx as Ug}from"react/jsx-runtime";function jg(){let e=O(),{width:t}=j(),{busy:n,error:o,fail:r,run:i}=ue();return Re(n!==null),Ug(Y,{trail:["\u627E\u56DE\u5BC6\u7801"],isActive:n===null,children:Ug(te,{title:"\u91CD\u7F6E\u5BC6\u7801",width:t,submitLabel:"\u63D0\u4EA4",busy:n!==null,busyLabel:n??"\u6B63\u5728\u91CD\u7F6E",error:o,fields:[{kind:"text",name:"email",label:"\u90AE\u7BB1",placeholder:"\u8BF7\u8F93\u5165\u6CE8\u518C\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",placeholder:"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801",emailField:"email",send:s=>Bg(e.ctx.site,{email:s})},{kind:"text",name:"password",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`,hint:"\u91CD\u7F6E\u540E\u6240\u6709\u8BBE\u5907\u90FD\u9700\u91CD\u65B0\u767B\u5F55"}],onCancel:()=>e.pop(),onSubmit:s=>{let a=(s.email??"").trim(),c=(s.code??"").trim(),l=s.password??"";if(a===""||c===""){r("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(l.length<Ot){r(`\u65B0\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}i("\u6B63\u5728\u91CD\u7F6E",()=>Fg(e.ctx.site,{email:a,code:c,password:l}),{onSuccess:()=>{e.toast("ok","\u5BC6\u7801\u5DF2\u91CD\u7F6E\uFF0C\u8BF7\u767B\u5F55"),e.pop()}})}})})}import{Box as Gl,Text as Pk}from"ink";import{useState as qg}from"react";import{Box as Hg}from"ink";import{jsx as ql,jsxs as _k}from"react/jsx-runtime";var ia=e=>e.termsConfigured||e.privacyConfigured;function sa({legal:e,width:t,onAgree:n}){let o=O(),r=[e.termsConfigured?"\u300A\u7528\u6237\u534F\u8BAE\u300B":"",e.privacyConfigured?"\u300A\u9690\u79C1\u653F\u7B56\u300B":""].filter(s=>s!==""),i=[{value:"agree",label:"\u6211\u5DF2\u9605\u8BFB\u5E76\u540C\u610F\uFF0C\u7EE7\u7EED",hint:r.join("\u4E0E")},...e.termsConfigured?[{value:"terms",label:"\u67E5\u770B\u7528\u6237\u534F\u8BAE"}]:[],...e.privacyConfigured?[{value:"privacy",label:"\u67E5\u770B\u9690\u79C1\u653F\u7B56"}]:[],{value:"back",label:"\u8FD4\u56DE"}];return _k(Hg,{flexDirection:"column",children:[ql(ye,{tone:"info",width:t,title:`\u7EE7\u7EED\u524D\u8BF7\u9605\u8BFB\u5E76\u540C\u610F${r.join("\u4E0E")}`}),ql(Hg,{marginTop:1,children:ql(le,{items:i,width:t,onSelect:s=>{s==="agree"?n():s==="terms"?o.push("agreement",{type:"terms"}):s==="privacy"?o.push("agreement",{type:"privacy"}):o.pop()}})})]})}import{jsx as eo,jsxs as Gg}from"react/jsx-runtime";function zg(){let e=O(),{width:t}=j(),[n,o]=qg({name:"credentials"}),[r,i]=qg(!1),{busy:s,error:a,reset:c,fail:l,run:u}=ue(),m=Q([e.revision],()=>Ge(e.ctx.site)),p=g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u5DF2\u767B\u5F55\uFF1A${g}`),e.home()},d=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Od(e.ctx.site,g,x),{onSuccess:T=>{if(T.status==="totp_required"){o({name:"factor",ticket:T.ticket,jar:T.jar});return}p(T.session.username)}})},b=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Dd(e.ctx.site,g.jar,g.ticket,x,g.kind),{onSuccess:T=>p(T.username)})},h=()=>{n.name==="credentials"?e.pop():(c(),o({name:"credentials"}))};return Gg(Y,{trail:n.name==="credentials"?["\u767B\u5F55\u8D26\u53F7"]:["\u767B\u5F55\u8D26\u53F7","\u4E24\u6B65\u9A8C\u8BC1"],onEscape:h,isActive:s===null,children:[n.name==="credentials"&&eo(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:g=>ia(g.legal)&&!r?eo(sa,{legal:g.legal,width:t,onAgree:()=>i(!0)}):Gg(Gl,{flexDirection:"column",children:[eo(te,{title:"\u767B\u5F55",width:t,submitLabel:"\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"account",label:"\u8D26\u53F7",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1"},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5BC6\u7801"}],onCancel:h,onSubmit:x=>{let T=(x.account??"").trim(),k=x.password??"";if(T===""||k===""){l("\u8BF7\u586B\u5199\u8D26\u53F7\u4E0E\u5BC6\u7801");return}d(T,k)}}),eo(Gl,{marginTop:1,children:eo(Pk,{color:f.faintForeground,children:"Passkey \u767B\u5F55\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"})})]})}),n.name==="factor"&&eo(le,{width:t,items:[{value:"totp",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",hint:"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801"},{value:"recovery-code",label:"\u6062\u590D\u7801",hint:"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onSelect:g=>o({name:"code",ticket:n.ticket,jar:n.jar,kind:g})}),n.name==="code"&&eo(Gl,{flexDirection:"column",children:eo(te,{title:"\u4E24\u6B65\u9A8C\u8BC1",width:t,submitLabel:"\u9A8C\u8BC1\u5E76\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"code",label:n.kind==="totp"?"\u52A8\u6001\u9A8C\u8BC1\u7801":"\u6062\u590D\u7801",placeholder:n.kind==="totp"?"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801":"\u8BF7\u8F93\u5165\u6062\u590D\u7801",hint:n.kind==="totp"?"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801":"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onCancel:h,onSubmit:g=>{let x=(g.code??"").trim();if(x===""){l("\u8BF7\u586B\u5199\u9A8C\u8BC1\u7801");return}b(n,x)}})})]})}import{useState as Ak}from"react";import{jsx as aa}from"react/jsx-runtime";function Wg(){let e=O(),{width:t}=j(),[n,o]=Ak(!1),{busy:r,error:i,fail:s,run:a}=ue(),c=Q([e.revision],()=>Ge(e.ctx.site));return aa(Y,{trail:["\u6CE8\u518C\u8D26\u53F7"],isActive:r===null,children:aa(V,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:l=>ia(l.legal)&&!n?aa(sa,{legal:l.legal,width:t,onAgree:()=>o(!0)}):aa(te,{title:"\u6CE8\u518C",width:t,submitLabel:"\u6CE8\u518C",busy:r!==null,busyLabel:r??"\u6B63\u5728\u6CE8\u518C",error:i,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D"},{kind:"text",name:"email",label:"\u90AE\u7BB1",placeholder:"\u8BF7\u8F93\u5165\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",placeholder:"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801",emailField:"email",send:u=>Dg(e.ctx.site,{email:u})},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`},{kind:"text",name:"invite",label:"\u9080\u8BF7\u7801",placeholder:"\u8BF7\u8F93\u5165\u9080\u8BF7\u7801",optional:!0}],onCancel:()=>e.pop(),onSubmit:u=>{let m=(u.username??"").trim(),p=(u.email??"").trim(),d=(u.code??"").trim(),b=u.password??"",h=(u.invite??"").trim();if(m===""||m.length>Kt){s(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}if(p===""||d===""){s("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(b.length<Ot){s(`\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}a("\u6B63\u5728\u6CE8\u518C",()=>$g(e.ctx.site,{username:m,email:p,password:b,code:d,...h===""?{}:{inviteCode:h}}),{onSuccess:g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u6CE8\u518C\u6210\u529F\uFF1A${g.username}`),e.home()}})}})})})}import{Box as hi}from"ink";import{useState as Ek}from"react";import{jsx as It,jsxs as Kg}from"react/jsx-runtime";var Mk=["category","title","content","attachments"],Ik=11,Nk=2,Lk=3,Ok=16,Vg={new:"\u53D1\u5E03\u5E16\u5B50",draft:"\u7F16\u8F91\u8349\u7A3F",edit:"\u7F16\u8F91\u5E16\u5B50"};function Dk(e){return e.kind==="edit"?{category:String(e.post.category.id),title:e.post.title,content:e.post.content,attachments:""}:e.kind==="draft"?{category:e.draft.category===null?"":String(e.draft.category.id),title:e.draft.title,content:e.draft.content,attachments:""}:{category:"",title:"",content:"",attachments:""}}function $k(e,t){return e.find(n=>String(n.id)===t)?.description}function Yg({mode:e}){let t=O(),{width:n}=j(),o=Z(),r=Dk(e),[i,s]=Me("values",()=>r),[a,c]=Ek(!1),{busy:l,error:u,fail:m,reset:p,run:d}=ue(),b=Q([],Os),h=Mk.some(E=>(i[E]??"")!==(r[E]??""));Re(h||l!==null);let g=E=>{let W=E.category??"";return{categoryId:W===""?null:Number(W),title:(E.title??"").trim(),content:(E.content??"").trim()}},x=(E,W)=>{let M;try{M=Jn(E.attachments??"",Ws)}catch(C){return m(xe(C)),null}return jt(W).length+M.length>Ws.maxCount?(m("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650"),null):M},T=async E=>{switch(e.kind){case"new":return(await uf(E)).id;case"draft":return await gf(e.draft.id,E),e.draft.id;case"edit":return await df(e.post.id,E),e.post.id}},k=E=>{if(e.kind==="edit"&&!h){m("\u5185\u5BB9\u672A\u4FEE\u6539");return}let{categoryId:W,title:M,content:C}=g(E);if(W===null){m("\u8BF7\u9009\u62E9\u677F\u5757");return}if(M===""){m("\u8BF7\u586B\u5199\u6807\u9898");return}if(M.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let v=x(E,C);if(v!==null){if(C===""&&v.length===0){m("\u8BF7\u586B\u5199\u6B63\u6587");return}d("\u6B63\u5728\u63D0\u4EA4",()=>Mn(v,si,_=>T({categoryId:W,title:M,content:di(C,_)})),{onSuccess:_=>{t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838"),t.pop(),e.kind!=="edit"&&t.push("post",{id:_})}})}},S=(E,W)=>{let{categoryId:M,title:C,content:v}=g(E);if(C.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let _=x(E,v);_!==null&&d("\u6B63\u5728\u4FDD\u5B58\u8349\u7A3F",()=>Mn(_,si,async L=>{let P={categoryId:M,title:C,content:di(v,L)};W===null?await pf(P):await ff(W,P)}),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5B58\u8349\u7A3F")}})},y=e.kind==="draft"?e.draft.id:null,R=()=>{if(!h){t.pop();return}p(),c(!0)},N=()=>{if(!a){t.pop();return}p(),c(!1)};return G(E=>{E==="q"&&h&&R()},!a&&l===null),It(Y,{trail:["\u793E\u533A\u8BBA\u575B",Vg[e.kind]],onEscape:N,isActive:l===null,children:It(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u677F\u5757",width:n,children:E=>{if(a&&e.kind==="edit")return It(Ae,{width:n,title:"\u653E\u5F03\u4FEE\u6539",detail:"\u4FEE\u6539\u5C1A\u672A\u63D0\u4EA4\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03\u4FEE\u6539",onConfirm:t.pop,onCancel:N});if(a)return Kg(hi,{flexDirection:"column",children:[It(ye,{tone:"warn",width:n,title:"\u4FDD\u5B58\u8349\u7A3F",detail:"\u5185\u5BB9\u5C1A\u672A\u53D1\u5E03\uFF0C\u662F\u5426\u5B58\u4E3A\u8349\u7A3F\uFF1F"}),u!==null&&It(hi,{marginTop:1,children:It(Ft,{message:u.message,hint:u.hint,width:n})}),It(hi,{marginTop:1,children:l!==null?It(Oe,{label:l}):It(le,{width:n,items:[{value:"save",label:"\u5B58\u8349\u7A3F"},{value:"stay",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"discard",label:"\u4E0D\u4FDD\u5B58",labelTone:"danger"}],onSelect:L=>{L==="save"?S(i,y):L==="stay"?N():t.pop()}})})]});let W=e.kind==="edit"?0:1,M=e.kind==="edit"&&e.post.status==="published",C=M?Nk:0,v=Math.min(Ok,Math.max(Lk,o-Ik-W-C-pi(u))),_=i.category??"";return Kg(hi,{flexDirection:"column",children:[M&&It(hi,{marginBottom:1,children:It(ye,{tone:"info",width:n,title:"\u4FEE\u6539\u540E\u9700\u91CD\u65B0\u5BA1\u6838\uFF0C\u5BA1\u6838\u671F\u95F4\u5E16\u5B50\u6682\u65F6\u9690\u85CF"})}),It(te,{title:Vg[e.kind],width:n,submitLabel:e.kind==="edit"?"\u63D0\u4EA4\u4FEE\u6539":"\u53D1\u5E03",busy:l!==null,busyLabel:l??"\u6B63\u5728\u63D0\u4EA4",error:u,fields:[{kind:"select",name:"category",label:"\u677F\u5757",options:[..._===""?[{value:"",label:"\u8BF7\u9009\u62E9\u677F\u5757"}]:[],...E.map(L=>({value:String(L.id),label:L.name}))],initial:i.category,hint:L=>$k(E,L)},{kind:"text",name:"title",label:"\u6807\u9898",initial:i.title,placeholder:"\u8BF7\u8F93\u5165\u5E16\u5B50\u6807\u9898"},{kind:"textarea",name:"content",label:"\u6B63\u6587",rows:v,maxLength:Di,initial:i.content,placeholder:"\u8BF7\u8F93\u5165\u6B63\u6587\uFF0C\u652F\u6301 Markdown"},{...Zn(Ws),initial:i.attachments}],secondary:e.kind==="edit"?void 0:{label:"\u5B58\u8349\u7A3F",onSubmit:L=>S(L,y)},onChange:s,onCancel:R,onSubmit:k})]})}})})}function Jg({params:e}){return It(Yg,{mode:e.draft===null?{kind:"new"}:{kind:"draft",draft:e.draft}})}function Xg({params:e}){return It(Yg,{mode:{kind:"edit",post:e.post}})}import{Box as to,Text as zl}from"ink";import{useEffect as Wl,useMemo as Qg,useState as ca}from"react";import{useRef as Bk}from"react";function qt(e){let t=Bk(null);return e.phase==="ready"&&(t.current={data:e.data}),e.phase==="error"&&(t.current=null),e.phase==="loading"&&t.current!==null?{phase:"ready",data:t.current.data}:e}import{jsx as Ee,jsxs as Vl}from"react/jsx-runtime";var la={kind:"floor"},Fk=2,Zg=3,Uk=4,nh=2,eh=3,th="PgUp PgDn \u6EDA\u52A8\u6B63\u6587",ma=(e,t)=>{let n=Xs(Jo,e.status,e.reviewReason,t);return n===0?0:n+1};function jk(e,t,n,o,r){let i=Math.max(nh+eh,o-Fk-ma(e,r)-3),s=Math.max(eh,Math.min(Uk,i-Zg)),a=Math.min(Zg,i-s),c=Math.min(1+Math.max(2,n),Math.max(s,Math.floor(i/2))),l=Math.min(t.length,Math.max(a,i-c));return{bodyRows:l,listRows:i-l}}function Hk(e,t,n,o,r){let i=o-Xe-1-ma(e,r)-2-n;return Math.min(t.length,Math.max(nh,i))}function qk(e,t,n,o){let r=e.status==="published"&&t.status==="published"&&n.status==="published",i=Ln(n.author,o);return[...r&&!i?[{value:"like",label:n.liked?"\u53D6\u6D88\u70B9\u8D5E":"\u70B9\u8D5E"}]:[],...r?[{value:"reply",label:"\u56DE\u590D"}]:[],...r&&!i?[{value:"report",label:"\u4E3E\u62A5"}]:[],...jt(n.content).length>0?[{value:"attachments",label:"\u9644\u4EF6"}]:[],{value:"author",label:"\u7528\u6237\u4E3B\u9875",hint:vt(n.author)},...i?[{value:"delete",label:"\u5220\u9664",labelTone:"danger"}]:[]]}function oh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=ca({name:"main"}),[s,a]=ca(null),{busy:c,error:l,reset:u,run:m}=ue();Re(r.name==="confirm-delete"&&c!==null);let p=qt(Q([e.postId,e.floorId,t.revision],async()=>{let[w,F,re,D]=await Promise.all([Ds(e.postId),nf(e.postId,e.floorId),En(),sr()]);return{post:w,floor:F,me:re.user,muted:D.muted}})),d=ze([e.floorId,t.revision],w=>of(e.floorId,w),{retain:"replies-page"}),b=qt(d.state),h=p.phase==="ready"?p.data:null,g=b.phase==="ready"?b.data:null,[x,T]=ca(void 0);Wl(()=>T(void 0),[h]);let[k,S]=ca(new Map);Wl(()=>S(new Map),[g]);let y=h===null?null:{...h,floor:{...h.floor,...x}},R=g===null?[]:g.items.map(w=>({...w,...k.get(w.id)})),N=yg(cd(R)),E=r.name==="actions"?R.find(w=>w.id===r.id)??null:null,W=s!==null&&R.some(w=>w.id===s);Wl(()=>{W&&a(null)},[W]);let M=y===null?null:y.floor.content,C=Qg(()=>M===null?[]:ui(M,n),[M,n]),v=E===null?null:E.content,_=Qg(()=>v===null?[]:ui(v,n-ge),[v,n]),L=y===null?null:jk(y.floor,C,R.length,o-pr(y.muted,n),n),P=y===null||E===null?null:qk(y.post,y.floor,E,y.me.username),B=E===null||P===null?null:Hk(E,_,P.length,o,n-ge),J=w=>y===null?null:w.kind==="floor"?y.floor:R.find(F=>F.id===w.id)??null,oe=(w,F)=>{m(w.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>Sf(w.id,!w.liked),{failToast:!0,onSuccess:({likeCount:re})=>F({liked:!w.liked,likeCount:re})})};G((w,F)=>{if(y===null||r.name!=="main"||c!==null)return;let{post:re,floor:D,me:z}=y,ee=re.status==="published"&&D.status==="published",he=Ln(D.author,z.username);w==="r"?t.reload():F.leftArrow?d.go(-1):F.rightArrow?d.go(1):w==="c"&&ee?i({name:"reply",target:la}):w==="l"&&ee&&!he?oe(D,T):w==="p"&&ee&&!he?i({name:"report",target:la}):w==="a"&&jt(D.content).length>0?i({name:"attachments",target:la}):w==="u"?t.push("homepage",{author:mi(D.author)}):w==="d"&&he&&(u(),i({name:"confirm-delete",target:la}))});let fe=()=>{if(r.name==="main"){t.pop();return}if(u(),r.name!=="actions"&&r.target.kind==="reply"){i({name:"actions",id:r.target.id});return}i({name:"main"})},$=(w,F)=>{let re={kind:"reply",id:w.id};F==="like"?oe(w,D=>S(z=>new Map(z).set(w.id,D))):F==="reply"?i({name:"reply",target:re}):F==="report"?i({name:"report",target:re}):F==="attachments"?i({name:"attachments",target:re}):F==="author"?t.push("homepage",{author:mi(w.author)}):(u(),i({name:"confirm-delete",target:re}))};return Ee(Y,{trail:["\u793E\u533A\u8BBA\u575B","\u697C\u5C42\u8BE6\u60C5"],hints:(()=>{if(y===null)return[];if(r.name==="actions")return B===null?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C",..._.length>B?[th]:[]];if(r.name!=="main"||L===null)return[];let{post:w,floor:F,me:re}=y,D=w.status==="published"&&F.status==="published",z=Ln(F.author,re.username);return[...R.length>0?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C"]:[],...C.length>L.bodyRows?[th]:[],...D?["c \u56DE\u590D"]:[],...D&&!z?[F.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E","p \u4E3E\u62A5"]:[],...jt(F.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...z?["d \u5220\u9664"]:[],"r \u5237\u65B0"]})(),onEscape:fe,isActive:r.name==="main"||c===null,children:Ee(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:n,children:({post:w,floor:F,me:re,muted:D})=>{let z={...F,...x},ee=ie=>`${Ln(ie.author,re.username)?"\u83B7\u8D5E":ie.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${ie.likeCount}`;if(r.name==="actions"){if(E===null||P===null||B===null)return Ee(ye,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});let ie=n-ge;return Vl(pe,{title:vt(E.author),note:K(E.createdAt),width:n,children:[Ee(zl,{wrap:"truncate",color:f.mutedForeground,children:_e([E.replyTo!==null&&`\u56DE\u590D ${Ks(E.replyTo.author)}`,ee(E)])}),ma(E,ie)>0&&Ee(to,{marginTop:1,children:Ee(vo,{notices:Jo,status:E.status,reason:E.reviewReason,width:ie})}),Ee(to,{marginTop:1,children:Ee(pt,{lines:_,height:B,isActive:c===null,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:c!==null?Ee(Oe,{label:c}):Ee(le,{width:ie,items:P,onSelect:Qe=>$(E,Qe)})})]})}if(r.name!=="main"){let ie=J(r.target);if(ie===null)return Ee(ye,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});if(r.name==="reply")return Ee(Qs,{postId:w.id,replyTo:{id:ie.id,mention:Ks(ie.author)},width:n,height:o,onCancel:fe,onDone:xt=>{i({name:"main"}),a(xt),d.last(),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838")}});if(r.name==="report")return Ee(Zs,{target:{kind:"comment",id:ie.id},width:n,onCancel:fe,onDone:()=>{fe(),t.toast("ok","\u5DF2\u63D0\u4EA4\u4E3E\u62A5")}});if(r.name==="attachments")return Ee(ea,{refs:jt(ie.content),width:n,height:o});let Qe=r.target.kind==="floor";return Ee(Ae,{width:n,title:Qe?"\u5220\u9664\u8BC4\u8BBA":"\u5220\u9664\u56DE\u590D",detail:Qe?"\u5220\u9664\u540E\u8BE5\u697C\u5C42\u53CA\u5176\u5168\u90E8\u56DE\u590D\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F":"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u6761\u56DE\u590D\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:c,error:l,onConfirm:()=>m("\u6B63\u5728\u5220\u9664",()=>yf(ie.id),{onSuccess:()=>{Qe?t.pop():(i({name:"main"}),t.reload()),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:fe})}if(L===null)return null;let he=c===null;return Vl(to,{flexDirection:"column",children:[Ee(ko,{muted:D,width:n}),Ee(zl,{bold:!0,wrap:"truncate",color:f.foreground,children:w.title}),c!==null?Ee(Oe,{label:c}):Ee(zl,{wrap:"truncate",color:f.mutedForeground,children:_e([z.floor!==null&&`#${z.floor}`,vt(z.author),K(z.createdAt),`\u56DE\u590D ${z.replyCount}`,ee(z)])}),ma(z,n)>0&&Ee(to,{marginTop:1,children:Ee(vo,{notices:Jo,status:z.status,reason:z.reviewReason,width:n})}),Ee(to,{marginTop:1,children:Ee(pt,{lines:C,height:L.bodyRows,isActive:he,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:Ee(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u56DE\u590D",width:n,children:()=>Vl(to,{flexDirection:"column",children:[Ee(de,{retain:"replies",items:N,width:n,height:L.listRows,isActive:he,columns:[Qn,{label:"\u56DE\u590D",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:({reply:ie,mention:Qe,prefix:xt})=>[`${xt}${vt(ie.author)}`,Qe===null?wo(ie.content):`\u56DE\u590D ${Ks(Qe)}\uFF1A${wo(ie.content)}`,String(ie.likeCount),K(ie.createdAt),ie.status==="published"?"":yt(po(ie.status))],onOpen:({reply:ie})=>i({name:"actions",id:ie.id}),select:s===null?void 0:({reply:ie})=>ie.id===s,emptyLabel:"\u6682\u65E0\u56DE\u590D",emptyDescription:w.status==="published"&&z.status==="published"?"\u6309 c \u56DE\u590D\u672C\u697C":void 0}),Ee(We,{page:d.page,pages:d.pages,total:d.total,width:n})]})})})]})}})})}import{Box as Ro,Text as pa}from"ink";import{Box as rh}from"ink";import{jsx as gr,jsxs as ih}from"react/jsx-runtime";function ua({author:e,owner:t,width:n,height:o}){let r=O(),i=ze([e.kind,e.username,r.revision],a=>sf(e,a),{retain:"posts-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:a=>ih(rh,{flexDirection:"column",children:[gr(de,{retain:"posts",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u6807\u9898",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],mr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},t?{label:"\u65F6\u95F4"}:{label:"\u65F6\u95F4",align:"right"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[c.title,...t?[Nc(jr,c)??""]:[],c.category.name,String(c.commentCount),String(c.viewCount),String(c.likeCount),K(c.publishedAt??c.createdAt),...t?[yt(po(c.status))]:[]],onOpen:c=>r.push("post",{id:c.id}),emptyLabel:"\u6682\u65E0\u5E16\u5B50"}),gr(We,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}function da({author:e,owner:t,width:n,height:o}){let r=O(),i=ze([e.kind,e.username,r.revision],a=>af(e,a),{retain:"comments-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u8BC4\u8BBA",width:n,children:a=>ih(rh,{flexDirection:"column",children:[gr(de,{retain:"comments",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u8BC4\u8BBA",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],{label:"\u5E16\u5B50",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[wo(c.content),...t?[Nc(Jo,c)??""]:[],c.post.title??Wi,String(c.likeCount),K(c.createdAt),...t?[yt(po(c.status))]:[]],onOpen:c=>r.push("floor",{postId:c.post.id,floorId:c.floorId}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA"}),gr(We,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}import{jsx as bt,jsxs as fa}from"react/jsx-runtime";var Gk=[{value:"posts",label:"\u5E16\u5B50"},{value:"comments",label:"\u8BC4\u8BBA"}],zk=3,Wk=2,Vk=5;function Kk({profile:e,owner:t,width:n,heatmapOn:o}){let{identity:r,stats:i}=e,s=e.activity.days.reduce((a,c)=>a+c.count,0);return fa(Ro,{flexDirection:"column",children:[fa(pa,{wrap:"truncate",children:[bt(pa,{bold:!0,color:f.foreground,children:st(r.username)}),bt(pa,{color:f.accent,children:` ${r.kind==="user"?qi(r.points):`[${zi}]`}`})]}),bt(pa,{wrap:"truncate",color:f.mutedForeground,children:_e([r.kind==="user"&&`${r.points} \u79EF\u5206`,t&&r.kind==="user"&&Gi(r.points),`\u52A0\u5165\u4E8E ${Ur(e.joinedAt)}`])}),bt(Ro,{marginTop:1,children:bt(it,{width:n,tiles:[{label:"\u5E16\u5B50",value:String(i.posts)},{label:"\u8BC4\u8BBA",value:String(i.comments)},{label:"\u83B7\u8D5E",value:String(i.likesReceived)}]})}),o&&fa(Ro,{marginTop:X,flexDirection:"column",children:[bt(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:n}),bt(Ro,{marginTop:qe,flexDirection:"column",children:bt(lr,{data:e.activity,value:a=>a.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${s} \u6B21`,width:n})})]})]})}function sh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("content",()=>"posts"),s=Q([e.author.kind,e.author.username,t.revision],async()=>{let[p,d]=await Promise.all([rf(e.author),En()]),b=e.author.kind==="user"&&e.author.username===d.user.username;return{profile:p,owner:b}});G(p=>{p==="r"?t.reload():p==="t"&&i(d=>d==="posts"?"comments":"posts")});let a=Wk+1+Ut(zk,n),c=o-a-2-1,l=X+Xe+To,u=cr(n)&&c-l>=Vk,m=Math.max(3,c-(u?l:0));return bt(Y,{trail:["\u793E\u533A\u8BBA\u575B","\u7528\u6237\u4E3B\u9875"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","t \u5207\u6362","r \u5237\u65B0"],children:bt(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u6237\u4E3B\u9875",width:n,children:({profile:p,owner:d})=>fa(Ro,{flexDirection:"column",children:[bt(Kk,{profile:p,owner:d,width:n,heatmapOn:u}),bt(Ro,{marginTop:1,children:bt(Fs,{options:Gk,value:r,onChange:i,arrowKeys:!1})}),bt(Ro,{marginTop:1,children:r==="posts"?bt(ua,{author:e.author,owner:d,width:n,height:m}):bt(da,{author:e.author,owner:d,width:n,height:m})})]})})})}import{Box as ah}from"ink";import{useState as Yk}from"react";import{jsx as _o,jsxs as lh}from"react/jsx-runtime";var Jk={sort:"activity",categoryId:"",q:"",author:""},ch=e=>e.categoryId!==""||e.q!==""||e.author!=="",Xk=(e,t)=>({page:t,sort:e.sort,...e.categoryId===""?{}:{categoryId:Number(e.categoryId)},...e.q===""?{}:{q:e.q},...e.author===""?{}:{author:e.author}});function mh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Yk(!1),[i,s]=Me("filters",()=>Jk),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[d,b]=await Promise.all([sr(),Os()]);return{muted:d.muted,categories:b}}),m=ze([e.revision,JSON.stringify(i)],d=>Zp(Xk(i,d)),{retain:"page"});G((d,b)=>{o||(d==="r"?e.reload():d==="f"?r(!0):d==="n"?e.push("compose",{draft:null}):b.leftArrow?m.go(-1):b.rightArrow&&m.go(1))});let p=()=>{if(!o){e.pop();return}l(),r(!1)};return _o(Y,{hints:o?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u53D1\u5E03\u5E16\u5B50","f \u7B5B\u9009","r \u5237\u65B0"],onEscape:p,children:_o(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u793E\u533A",width:t,children:({muted:d,categories:b})=>o?_o(te,{title:"\u7B5B\u9009\u5E16\u5B50",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"select",name:"sort",label:"\u6392\u5E8F",options:oc.map(h=>({value:h,label:vd(h)})),initial:i.sort},{kind:"select",name:"category",label:"\u677F\u5757",options:[{value:"",label:"\u5168\u90E8\u677F\u5757"},...b.map(h=>({value:String(h.id),label:h.name}))],initial:i.categoryId},{kind:"text",name:"q",label:"\u5173\u952E\u8BCD",initial:i.q,placeholder:"\u641C\u7D22\u6807\u9898\u6216\u6B63\u6587"},{kind:"text",name:"author",label:"\u4F5C\u8005",initial:i.author,placeholder:"\u8F93\u5165\u4F5C\u8005\u5B8C\u6574\u7528\u6237\u540D"}],onCancel:p,onSubmit:h=>{let g=(h.q??"").trim(),x=(h.author??"").trim();if(g.length>Bi){c(`\u5173\u952E\u8BCD\u6700\u591A ${Bi} \u4E2A\u5B57\u7B26`);return}if(x.length>Kt){c(`\u7528\u6237\u540D\u6700\u591A ${Kt} \u4E2A\u5B57\u7B26`);return}s({sort:h.sort,categoryId:h.category??"",q:g,author:x}),m.reset(),l(),r(!1)}}):lh(ah,{flexDirection:"column",children:[_o(ko,{muted:d,width:t}),_o(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:t,children:h=>lh(ah,{flexDirection:"column",children:[_o(de,{retain:"list",items:h.items,width:t,height:Math.max(3,n-1-pr(d,t)),columns:[{label:"\u4E3B\u9898",shrink:!0},Qn,mr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:g=>[g.title,vt(g.author),g.category.name,String(g.commentCount),String(g.viewCount),String(g.likeCount),K(g.lastActivityAt)],onOpen:g=>e.push("post",{id:g.id}),emptyLabel:ch(i)?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u5E16\u5B50",emptyDescription:ch(i)?void 0:"\u6309 n \u53D1\u5E03\u7B2C\u4E00\u7BC7\u5E16\u5B50"}),_o(We,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})})})}import{Box as ga}from"ink";import{useState as Qk}from"react";import{jsx as ft,jsxs as yh}from"react/jsx-runtime";var Zk=X+Xe+2,ev=X+2+1+2;function dh(){let e=O();G(t=>{t==="r"&&e.reload()})}function ph({params:e}){let{width:t}=j(),n=Z();return dh(),ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u5E16\u5B50"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:ft(ua,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function fh({params:e}){let{width:t}=j(),n=Z();return dh(),ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u8BC4\u8BBA"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:ft(da,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function gh(){let e=O(),{width:t}=j(),n=Z(),o=ze([e.revision],r=>cf(r),{retain:"page"});return G((r,i)=>{r==="r"?e.reload():i.leftArrow?o.go(-1):i.rightArrow&&o.go(1)}),ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u6536\u85CF"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:ft(V,{state:o.state,loading:"\u6B63\u5728\u8BFB\u53D6\u6536\u85CF",width:t,children:r=>yh(ga,{flexDirection:"column",children:[ft(de,{retain:"list",items:r.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},Qn,{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:i=>[i.title,vt(i.author),String(i.commentCount),String(i.likeCount),K(i.lastActivityAt)],onOpen:i=>e.push("post",{id:i.id}),emptyLabel:"\u6682\u65E0\u6536\u85CF"}),ft(We,{page:o.page,pages:o.pages,total:o.total,width:t})]})})})}var uh=e=>e.title===""?"\u672A\u547D\u540D\u8349\u7A3F":e.title;function hh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Qk({name:"list"}),{busy:i,error:s,reset:a,run:c}=ue();Re(i!==null);let l=ze([e.revision],d=>lf(d),{retain:"page"}),u=o.name==="list";G((d,b)=>{u&&(d==="r"?e.reload():b.leftArrow?l.go(-1):b.rightArrow&&l.go(1))});let m=()=>{if(u){e.pop();return}a(),r({name:"list"})},p=o.name==="actions"?Zk:o.name==="confirm-delete"?ev+pi(s):0;return ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u8349\u7A3F"],hints:u?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:ft(V,{state:l.state,loading:"\u6B63\u5728\u8BFB\u53D6\u8349\u7A3F",width:t,children:d=>yh(ga,{flexDirection:"column",children:[ft(de,{retain:"list",items:d.items,width:t,height:Math.max(3,n-1-p),isActive:u,columns:[{label:"\u6807\u9898",shrink:!0},mr,{label:"\u521B\u5EFA\u65F6\u95F4",align:"right"}],row:b=>[uh(b),b.category===null?"\u2014":b.category.name,K(b.createdAt)],onOpen:b=>r({name:"actions",draft:b}),emptyLabel:"\u6682\u65E0\u8349\u7A3F",emptyDescription:"\u53D1\u5E03\u5E16\u5B50\u65F6\u53EF\u9009\u62E9\u5B58\u4E3A\u8349\u7A3F"}),ft(We,{page:l.page,pages:l.pages,total:l.total,width:t}),o.name==="actions"&&ft(ga,{marginTop:X,children:ft(pe,{title:uh(o.draft),width:t,children:ft(le,{width:t-ge,items:[{value:"edit",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:b=>{if(b==="edit"){r({name:"list"}),e.push("compose",{draft:o.draft});return}a(),r({name:"confirm-delete",draft:o.draft})}})})}),o.name==="confirm-delete"&&ft(ga,{marginTop:X,children:ft(Ae,{width:t,title:"\u5220\u9664\u8349\u7A3F",detail:"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u7BC7\u8349\u7A3F\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>c("\u6B63\u5728\u5220\u9664",()=>$s(o.draft.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:m})})]})})})}import{Box as Po,Text as Kl}from"ink";import{useEffect as ha,useMemo as tv,useRef as nv,useState as Yl}from"react";import{jsx as Ke,jsxs as Jl}from"react/jsx-runtime";var bh=2,ov=2,rv=2;function iv({post:e,width:t,height:n,isActive:o,follow:r,onFollowed:i}){let s=O(),a=ze([e.id,s.revision],u=>tf(e.id,u),{retain:"floors-page"}),c=qt(a.state),l=r!==null&&c.phase==="ready"&&c.data.items.some(u=>u.id===r);return ha(()=>{r!==null&&a.last()},[r]),ha(()=>{l&&i()},[l]),G((u,m)=>{m.leftArrow?a.go(-1):m.rightArrow&&a.go(1)},o),Ke(V,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:t,children:u=>Jl(Po,{flexDirection:"column",children:[Ke(de,{retain:"floors",items:u.items,width:t,height:Math.max(3,n-1),isActive:o,columns:[{label:"\u697C\u5C42"},Qn,{label:"\u5185\u5BB9",shrink:!0},{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[m.floor===null?"\u2014":`#${m.floor}`,vt(m.author),wo(m.content),String(m.replyCount),String(m.likeCount),m.status==="published"?"":yt(po(m.status))],onOpen:m=>s.push("floor",{postId:e.id,floorId:m.id}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA",emptyDescription:e.status==="published"?"\u6309 c \u53D1\u8868\u7B2C\u4E00\u6761\u8BC4\u8BBA":void 0,select:r===null?void 0:m=>m.id===r}),Ke(We,{page:a.page,pages:a.pages,total:a.total,width:t})]})})}function Sh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("mode",()=>"body"),[s,a]=Yl({name:"main"}),[c,l]=Yl(null),{busy:u,error:m,reset:p,run:d}=ue();Re(s.name==="confirm-delete"&&u!==null);let b=nv(null),h=qt(Q([e.id,t.revision],async()=>{let[M,C,v]=await Promise.all([Ds(e.id),En(),sr()]);return{post:M,me:C.user,muted:v.muted}})),g=h.phase==="ready"?h.data:null,[x,T]=Yl(null);ha(()=>T(null),[g]);let k=g===null?null:{...g,post:{...g.post,...x}},S=k!==null&&k.post.status==="published";ha(()=>{!S||b.current===e.id||(b.current=e.id,ef(e.id).catch(()=>t.toast("warn","\u6D4F\u89C8\u8BA1\u6570\u53D1\u9001\u5931\u8D25")))},[e.id,S]);let y=s.name==="main"&&u===null,R=k===null?null:k.post.content,N=tv(()=>R===null?[]:ui(R,n),[R,n]);G(M=>{if(k===null||!y)return;let{post:C,me:v}=k;if(M==="r"){t.reload();return}if(M==="v"){i(r==="body"?"floors":"body");return}if(M==="c"&&S){a({name:"comment"});return}if(r!=="body")return;let _=Ln(C.author,v.username),L={liked:C.liked,likeCount:C.likeCount,bookmarked:C.bookmarked};M==="l"&&S&&!_?d(C.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>bf(C.id,!C.liked),{failToast:!0,onSuccess:({likeCount:P})=>T({...L,liked:!C.liked,likeCount:P})}):M==="b"&&S?d(C.bookmarked?"\u6B63\u5728\u53D6\u6D88\u6536\u85CF":"\u6B63\u5728\u6536\u85CF",()=>xf(C.id,!C.bookmarked),{failToast:!0,onSuccess:()=>{T({...L,bookmarked:!C.bookmarked}),t.toast("ok",C.bookmarked?"\u5DF2\u53D6\u6D88\u6536\u85CF":"\u5DF2\u6536\u85CF")}}):M==="p"&&S&&!_?a({name:"report"}):M==="a"&&jt(C.content).length>0?a({name:"attachments"}):M==="u"?t.push("homepage",{author:mi(C.author)}):M==="e"&&_&&C.status!=="removed"?t.push("post-edit",{post:C}):M==="d"&&_&&(p(),a({name:"confirm-delete"}))});let E=()=>{if(s.name!=="main"){p(),a({name:"main"});return}if(r==="floors"){i("body");return}t.pop()},W=()=>{if(k===null||s.name!=="main")return[];let{post:M,me:C}=k;if(r==="floors")return["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...S?["c \u8BC4\u8BBA"]:[],"v \u6B63\u6587","r \u5237\u65B0"];let v=Ln(M.author,C.username);return["\u2191\u2193 \u6EDA\u52A8","v \u697C\u5C42\u5217\u8868",...S?["c \u8BC4\u8BBA",...v?[]:[M.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E"],M.bookmarked?"b \u53D6\u6D88\u6536\u85CF":"b \u6536\u85CF",...v?[]:["p \u4E3E\u62A5"]]:[],...jt(M.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...v&&M.status!=="removed"?["e \u7F16\u8F91\u5E16\u5B50"]:[],...v?["d \u5220\u9664"]:[],"r \u5237\u65B0"]};return Ke(Y,{trail:["\u793E\u533A\u8BBA\u575B",k===null?"\u5E16\u5B50\u8BE6\u60C5":k.post.category.name,...r==="floors"&&s.name==="main"?["\u697C\u5C42\u5217\u8868"]:[]],hints:W(),onEscape:E,isActive:s.name==="main"||u===null,children:Ke(V,{state:h,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:({post:M,me:C,muted:v})=>{let _={...M,...x},L=Ln(_.author,C.username);if(s.name==="comment")return Ke(Qs,{postId:_.id,replyTo:null,width:n,height:o,onCancel:E,onDone:fe=>{a({name:"main"}),i("floors"),l(fe),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838")}});if(s.name==="report")return Ke(Zs,{target:{kind:"post",id:_.id},width:n,onCancel:E,onDone:()=>{a({name:"main"}),t.toast("ok","\u5DF2\u63D0\u4EA4\u4E3E\u62A5")}});if(s.name==="attachments")return Ke(ea,{refs:jt(_.content),width:n,height:o});if(s.name==="confirm-delete")return Ke(Ae,{width:n,title:"\u5220\u9664\u5E16\u5B50",detail:"\u5220\u9664\u540E\u5E16\u5B50\u53CA\u5176\u5168\u90E8\u8BC4\u8BBA\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:u,error:m,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>$s(_.id),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:E});let P=Ke(Kl,{bold:!0,wrap:"truncate",color:f.foreground,children:_.title}),B=pr(v,n);if(r==="floors")return Jl(Po,{flexDirection:"column",children:[Ke(ko,{muted:v,width:n}),P,Ke(Po,{marginTop:1,children:Ke(iv,{post:_,width:n,height:o-bh-B,isActive:y,follow:c,onFollowed:()=>l(null)})})]});let J=Xs(jr,_.status,_.reviewReason,n),oe=Math.max(rv,o-B-bh-(J===0?0:J+1)-1-ov);return Jl(Po,{flexDirection:"column",children:[Ke(ko,{muted:v,width:n}),P,Ke(Kl,{wrap:"truncate",color:f.mutedForeground,children:_e([vt(_.author),K(_.publishedAt??_.createdAt),_.editedAt!==null&&`\u7F16\u8F91\u4E8E ${K(_.editedAt)}`,`\u6D4F\u89C8 ${_.viewCount}`])}),J>0&&Ke(Po,{marginTop:1,children:Ke(vo,{notices:jr,status:_.status,reason:_.reviewReason,width:n})}),Ke(Po,{marginTop:1,children:Ke(pt,{lines:N,height:oe,isActive:y})}),Ke(Po,{marginTop:1,children:u!==null?Ke(Oe,{label:u}):Ke(Kl,{wrap:"truncate",color:f.mutedForeground,children:_e([`\u8BC4\u8BBA ${_.commentCount}`,`${L?"\u83B7\u8D5E":_.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${_.likeCount}`,_.bookmarked&&"\u5DF2\u6536\u85CF"])})})]})}})})}import{Box as Eo}from"ink";import{useEffect as gv,useRef as hv,useState as Zl}from"react";import{z as H}from"zod";var sv=H.object({balance:H.number(),today:H.object({requests:H.number(),tokens:H.number(),cost:H.number()})}),xh=()=>A(sv,"/dashboard/summary"),Th=["all","30d","7d"],av=H.object({totals:H.object({requests:H.number(),tokens:H.number(),cost:H.number()}),hourly:H.array(H.number()),models:H.array(H.object({model:H.string(),displayName:H.string(),tokens:H.number(),inTokens:H.number(),outTokens:H.number()})),chart:H.object({start:H.string(),end:H.string(),points:H.array(H.object({day:H.string(),model:H.string(),tokens:H.number()}))}),heatmap:H.object({start:H.string(),end:H.string(),days:H.array(H.object({day:H.string(),cost:H.number()}))}),activeDays:H.number(),currentStreak:H.number(),longestStreak:H.number()}),Xl=e=>A(av,Fe("/dashboard/stats",{range:e})),cv=H.object({id:H.number().int(),requestId:H.string(),tokenName:H.string(),protocol:Bm,model:H.string(),modelDisplayName:H.string(),groupName:H.string(),promptTokens:H.number(),completionTokens:H.number(),cachedTokens:H.number(),cacheWriteTokens:H.number(),cacheWrite1hTokens:H.number(),webSearchRequests:H.number(),imageGenerationCalls:H.number(),totalTokens:H.number(),quotaCost:H.number(),subscriptionPlanName:H.string().nullable(),multiplier:H.number(),tierOver:H.number().int().nullable(),paramMultipliers:Mu,status:Wm,httpStatus:H.number().int(),stopReason:H.string().nullable(),latencyMs:H.number(),firstByteMs:H.number().nullable(),stream:H.boolean(),ip:H.string(),createdAt:H.string()}),wh=e=>A(mt(cv),Fe("/logs",{...e})),lv=H.object({quotaCost:H.number(),rpm:H.number(),tpm:H.number(),concurrency:H.number()}),kh=e=>A(lv,Fe("/logs/stats",{...e})),mv=H.object({id:H.number().int(),type:qm,amount:H.number(),balanceAfter:H.number(),refType:Gm,refId:H.string().nullable(),createdAt:H.string()}),vh=e=>A(mt(mv),Fe("/quota-ledger",{...e}));import{Box as uv,Text as ln}from"ink";import yi from"string-width";import{Fragment as Rh,jsx as mn,jsxs as Ql}from"react/jsx-runtime";var Ao=1,dv=4,pv=1,hr=8,fv=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587"],Ch=e=>`${Number(e.slice(5,7))}\u6708${Number(e.slice(8,10))}\u65E5`;function _h({data:e,order:t,width:n,rows:o}){let r=o-pv,i=[];for(let M=e.start;M<=e.end;M=Gn(M,1))i.push(M);let s=Math.min(dv,Math.floor((n+Ao)/i.length)-Ao);s<1&&(s=1,i=i.slice(-Math.floor((n+Ao)/(1+Ao))));let a=i[0],c=i[i.length-1];if(a===void 0||c===void 0)return null;let l=new Map(t.slice(0,ys.length).map((M,C)=>[M,C])),u=ys.length,m=M=>ys[M]??f.faintForeground,p=new Map(i.map((M,C)=>[M,C])),d=i.map(()=>Array.from({length:u+1},()=>0));for(let M of e.points){let C=p.get(M.day);if(C===void 0)continue;let v=d[C];if(v===void 0)continue;let _=l.get(M.model)??u;v[_]=(v[_]??0)+M.tokens}let b=d.map(M=>M.reduce((C,v)=>C+v,0)),h=Math.max(0,...b),g=r*hr,x=d.map((M,C)=>{let v=Array.from({length:r},()=>null),_=b[C]??0;if(_<=0)return v;let L=Math.max(1,Math.round(_/h*g)),P=[],B=0,J=0;M.forEach((oe,fe)=>{B+=oe;let $=Math.round(B/_*L);for(let ne=J;ne<$;ne+=1)P[ne]=m(fe);J=$});for(let oe=0;oe<r;oe+=1){let fe=Math.min(hr,L-oe*hr);if(fe<=0)break;let $=new Map;for(let F=oe*hr;F<oe*hr+fe;F+=1){let re=P[F];re!==void 0&&$.set(re,($.get(re)??0)+1)}let ne=null,w=0;for(let[F,re]of $)re>w&&(ne=F,w=re);if(ne===null)break;v[oe]={color:ne,glyph:fe===hr?null:fv[fe-1]??null}}return v}),T=M=>{let C=[],v=(_,L,P)=>{let B=C[C.length-1];B!==void 0&&B.color===_&&B.glyph===L?B.width+=P:C.push({color:_,glyph:L,width:P})};return x.forEach((_,L)=>{L>0&&v(null,null,Ao);let P=_[M]??null;P===null?v(null,null,s):v(P.color,P.glyph,s)}),C},k=i.length*(s+Ao)-Ao,S=Ch(a),y=Ch(c),R=h>0?`\u5355\u65E5\u5CF0\u503C ${qn(h)}`:"",N=k-yi(S)-yi(y),E=R!==""&&N>=yi(R)+4,W=E?Math.floor((N-yi(R))/2):N;return Ql(uv,{flexDirection:"column",children:[Array.from({length:r},(M,C)=>{let v=r-1-C;return mn(ln,{wrap:"truncate",children:T(v).map((_,L)=>_.color===null?mn(ln,{children:" ".repeat(_.width)},L):_.glyph===null?mn(ln,{backgroundColor:_.color,children:" ".repeat(_.width)},L):mn(ln,{color:_.color,children:_.glyph.repeat(_.width)},L))},v)}),mn(ln,{wrap:"truncate",children:N<2?mn(ln,{color:f.faintForeground,children:He(S,k)}):Ql(Rh,{children:[mn(ln,{color:f.faintForeground,children:S}),mn(ln,{children:" ".repeat(W)}),E&&Ql(Rh,{children:[mn(ln,{color:f.mutedForeground,children:R}),mn(ln,{children:" ".repeat(N-yi(R)-W)})]}),mn(ln,{color:f.faintForeground,children:y})]})})]})}import{jsx as ct,jsxs as Ah}from"react/jsx-runtime";var yv={all:"\u5168\u90E8","30d":"30 \u5929","7d":"7 \u5929"},bv=1,ya=4,Ph=5,Sv=9;function xv(e){let t=-1,n=0;return e.forEach((o,r)=>{o>n&&(n=o,t=r)}),t<0?"\u2014":`${t} \u70B9`}function Eh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Zl("30d"),[i,s]=Zl("heatmap"),[a,c]=Zl(null),l=hv(null),u=Q([o,e.revision],async()=>{let m=l.current;if(m!==null&&m.revision===e.revision){let h=await Xl(o);return{summary:m.summary,stats:h,site:m.site}}let[p,d,b]=await Promise.all([xh(),Xl(o),Ge(e.ctx.site)]);return l.current={revision:e.revision,summary:p,site:b},{summary:p,stats:d,site:b}});return gv(()=>{u.phase==="ready"&&c(yd({tokens:u.data.stats.totals.tokens,scope:"user",range:o}))},[u,o]),G(m=>{m==="r"&&e.reload(),m==="t"&&s(p=>p==="heatmap"?"chart":"heatmap")}),ct(Y,{hints:["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u5207\u6362\u533A\u95F4","t \u5207\u6362\u56FE\u8868","/ \u8FC7\u6EE4","r \u5237\u65B0"],children:ct(Eo,{flexDirection:"column",children:ct(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u91CF",width:t,children:({summary:m,stats:p,site:d})=>{let b=[{label:"\u8D26\u6237\u4F59\u989D",value:Te(m.balance,d.quotaPerUsd)},{label:"\u4ECA\u65E5\u8BF7\u6C42",value:Le(m.today.requests)},{label:"\u4ECA\u65E5 Token",value:Le(m.today.tokens)},{label:"\u4ECA\u65E5\u6D88\u8017",value:Te(m.today.cost,d.quotaPerUsd)}],h=[{label:"\u8BF7\u6C42\u6570",value:Le(p.totals.requests)},{label:"Token \u603B\u91CF",value:qn(p.totals.tokens)},{label:"\u6D88\u8017",value:Te(p.totals.cost,d.quotaPerUsd)},{label:"\u6D3B\u8DC3\u5929\u6570",value:Le(p.activeDays)},{label:"\u5F53\u524D\u8FDE\u7EED",value:`${p.currentStreak} \u5929`},{label:"\u6700\u957F\u8FDE\u7EED",value:`${p.longestStreak} \u5929`},{label:"\u9AD8\u5CF0\u65F6\u6BB5",value:xv(p.hourly)},{label:"\u5E38\u7528\u6A21\u578B",value:p.models[0]?.displayName??"\u2014"}],g=t-ge,x=C=>Bt+C+Ut(b.length,g)+X+Bt+C+bv+C+Ut(h.length,g)+X+Bt+C,T=n-x(qe)>=ya?qe:0,k=n-x(T),S=X+Bt+T+Ph,y=i==="chart"&&p.chart.points.length>0&&k>=S+ya,R=i==="heatmap"&&cr(g)&&k-(X+To)>=ya,N=R?X+To:0,E=y?Math.min(Sv,Ph+Math.floor((k-S-ya)/2)):0,W=k-N-(y?X+Bt+T+E:0),M=C=>`${(p.totals.tokens>0?C/p.totals.tokens*100:0).toFixed(1)}%`;return Ah(Eo,{flexDirection:"column",children:[ct(pe,{title:"\u6982\u89C8",width:t,gap:T,children:ct(it,{width:g,tiles:b})}),ct(Eo,{marginTop:1,flexDirection:"column",children:Ah(pe,{title:"\u533A\u95F4\u7EDF\u8BA1",width:t,gap:T,children:[ct(Fs,{options:Th.map(C=>({value:C,label:yv[C]})),value:o,onChange:r}),ct(Eo,{marginTop:T,children:ct(it,{width:g,tiles:h})}),R&&ct(Eo,{marginTop:1,flexDirection:"column",children:ct(lr,{data:p.heatmap,value:C=>C.cost,caption:a,width:g})})]})}),y&&ct(Eo,{marginTop:1,flexDirection:"column",children:ct(pe,{title:"\u7528\u91CF\u8D8B\u52BF",note:"\u67F1\u8272\u7531\u4EAE\u81F3\u6697\u5BF9\u5E94\u7528\u91CF\u524D\u4E94\u7684\u6A21\u578B\uFF0C\u7070\u8272\u4E3A\u5176\u4ED6",width:t,gap:T,children:ct(_h,{data:p.chart,order:p.models.map(C=>C.model),width:g,rows:E})})}),ct(Eo,{marginTop:1,flexDirection:"column",children:ct(pe,{title:"\u6A21\u578B\u7528\u91CF",width:t,gap:T,children:p.models.length===0?ct(ye,{tone:"info",width:g,title:"\u6682\u65E0\u7528\u91CF\u6570\u636E",detail:"\u8C03\u7528 API \u540E\u8FD9\u91CC\u4F1A\u663E\u793A\u5404\u6A21\u578B\u7684\u6BCF\u65E5 Token \u7528\u91CF"}):ct(de,{retain:"list",items:p.models,width:g,height:W,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u603B Token",align:"right"},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u5360\u6BD4",align:"right"}],row:C=>[C.displayName,qn(C.tokens),qn(C.inTokens),qn(C.outTokens),M(C.tokens)],searchOf:C=>C.displayName})})})]})}})})})}import{Box as yr,Text as tm}from"ink";import{useState as Nh}from"react";import{z as wv}from"zod";import{z as gt}from"zod";var Tv=gt.object({id:gt.number().int(),name:gt.string(),description:gt.string(),multiplier:gt.number()}),ba=()=>A(gt.array(Tv),"/groups"),em=gt.object({id:gt.number().int(),name:gt.string(),keyPrefix:gt.string(),keySuffix:gt.string(),groupId:gt.number().int().nullable(),groupName:gt.string().nullable(),usedQuota:gt.number(),quotaLimit:gt.number().nullable()}),Sa=()=>A(gt.array(em),"/tokens"),Mh=e=>A(em.extend({token:gt.string()}),"/tokens",{method:"POST",json:e}),xa=(e,t)=>A(em,`/tokens/${e}`,{method:"PATCH",json:t}),Ih=e=>A(se,`/tokens/${e}`,{method:"DELETE"});import{jsx as lt,jsxs as Ta}from"react/jsx-runtime";var Lh={model:"",requestId:"",token:"",group:"",status:"",range:"today",since:"",until:""},Oh=wv.iso.date();function kv(e){let t=Ec();return e.range==="today"?{since:t,until:t}:e.range==="7d"?{since:Gn(t,-6),until:t}:e.range==="30d"?{since:Gn(t,-29),until:t}:e.range==="custom"?{...e.since===""?{}:{since:e.since},...e.until===""?{}:{until:e.until}}:{}}function Dh(e){let t=kv(e);return{...e.model.trim()===""?{}:{model:e.model.trim()},...e.requestId.trim()===""?{}:{requestId:e.requestId.trim()},...e.token===""?{}:{token:e.token},...e.group===""?{}:{group:e.group},...e.status===""?{}:{status:e.status},...t.since===void 0?{}:{since:Mc(t.since).toISOString()},...t.until===void 0?{}:{until:Mc(Gn(t.until,1)).toISOString()}}}var vv=_t(Za,Ki,"\u5168\u90E8\u72B6\u6001"),Cv=[{value:"",label:"\u4E0D\u9650"},{value:"today",label:"\u4ECA\u5929"},{value:"7d",label:"\u8FD1 7 \u5929"},{value:"30d",label:"\u8FD1 30 \u5929"},{value:"custom",label:"\u81EA\u5B9A\u4E49\u8D77\u6B62"}];function Rv({log:e,quotaPerUsd:t,width:n}){let o=n-ge,r=Ki(e.status),i=ht(r),s=e.status!=="anomaly"?null:e.totalTokens>0?"\u672C\u6B21\u8C03\u7528\u672A\u8FD4\u56DE\u7528\u91CF\u6570\u636E\uFF0C\u8D39\u7528\u6309\u8BF7\u6C42\u4E0E\u54CD\u5E94\u7684\u6587\u672C\u91CF\u4F30\u7B97":"\u672C\u6B21\u8C03\u7528\u672A\u8FD4\u56DE\u7528\u91CF\u6570\u636E\u4E14\u65E0\u6CD5\u4F30\u7B97\uFF0C\u672A\u8BA1\u8D39",a=[];e.cachedTokens>0&&a.push(["\u7F13\u5B58\u8BFB",Le(e.cachedTokens)]),e.cacheWriteTokens>0&&a.push(["\u7F13\u5B58\u5199",Le(e.cacheWriteTokens)]),e.cacheWrite1hTokens>0&&a.push(["\u7F13\u5B58\u5199 1h",Le(e.cacheWrite1hTokens)]),e.webSearchRequests>0&&a.push(["\u7F51\u9875\u641C\u7D22",`${Le(e.webSearchRequests)} \u6B21`]),e.imageGenerationCalls>0&&a.push(["\u56FE\u50CF\u751F\u6210",`${Le(e.imageGenerationCalls)} \u6B21`]),e.firstByteMs!==null&&a.push(["\u9996\u5B57\u8282",`${ao(e.firstByteMs)} s`]),e.tierOver!==null&&a.push(["\u8F93\u5165\u957F\u5EA6",yc(e.tierOver)]),e.paramMultipliers.length>0&&a.push(["\u547D\u4E2D\u53C2\u6570",_e(e.paramMultipliers.map(l=>`${l.value} \xD7${l.multiplier}`))]);let c=[["\u8BF7\u6C42 ID",e.requestId],["\u4EE4\u724C",e.tokenName],["\u5206\u7EC4",e.groupName],["\u8BF7\u6C42 IP",e.ip],["\u534F\u8BAE",Td(e.protocol)],["\u8BA1\u8D39\u6765\u6E90",e.subscriptionPlanName!==null?`\u8BA2\u9605 \xB7 ${e.subscriptionPlanName}`:"\u4F59\u989D"],["HTTP \u72B6\u6001",String(e.httpStatus)],...e.stopReason===null?[]:[["\u7ED3\u675F\u539F\u56E0",e.stopReason]]];return Ta(pe,{title:e.modelDisplayName,note:K(e.createdAt),width:n,children:[Ta(tm,{wrap:"truncate",children:[lt(tm,{color:i===void 0?f.mutedForeground:et[i],children:r.label}),lt(tm,{color:f.faintForeground,children:` ${_e([e.stream?"\u6D41\u5F0F":"",e.model])}`})]}),lt(yr,{marginTop:1,children:lt(it,{width:o,tiles:[{label:"\u8F93\u5165 Token",value:Le(e.promptTokens)},{label:"\u8F93\u51FA Token",value:Le(e.completionTokens)},{label:"\u6D88\u8017",value:Xo(e.quotaCost,t)},{label:"\u603B\u8017\u65F6",value:`${ao(e.latencyMs)} s`},{label:"\u6863\u4F4D",value:Or(e.tierOver)},{label:"\u5206\u7EC4\u500D\u7387",value:`\xD7${e.multiplier}`},{label:"\u53C2\u6570\u500D\u7387",value:`\xD7${Iu(e.paramMultipliers)}`},{label:"\u603B\u500D\u7387",value:`\xD7${Nu(e.multiplier,e.paramMultipliers)}`}]})}),s!==null&&lt(yr,{marginTop:1,children:lt(ye,{tone:"warn",width:o,title:s})}),lt(yr,{marginTop:1,children:lt(Ve,{width:o,items:[...a,...c]})})]})}function $h(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Nh({name:"list"}),[i,s]=Nh(Lh),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[g,x,T]=await Promise.all([ba(),Sa(),Ge(e.ctx.site)]);return{groups:g,tokens:x,site:T}}),m=ze([e.revision,JSON.stringify(i)],g=>wh({page:g,...Dh(i)}),{retain:"page"}),p=Q([e.revision,JSON.stringify(i)],()=>kh(Dh(i))),d=o.name==="list";G((g,x)=>{d&&(g==="r"?e.reload():g==="f"?(l(),r({name:"filter"})):x.leftArrow?m.go(-1):x.rightArrow&&m.go(1))});let b=()=>{o.name==="list"?e.pop():(l(),r({name:"list"}))},h=JSON.stringify(i)!==JSON.stringify(Lh);return lt(Y,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:b,children:lt(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7B5B\u9009\u9009\u9879",width:t,children:({groups:g,tokens:x,site:T})=>{if(o.name==="filter")return lt(te,{title:"\u7B5B\u9009\u65E5\u5FD7",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"text",name:"model",label:"\u6A21\u578B",initial:i.model,placeholder:"\u641C\u7D22\u6A21\u578B ID \u6216\u540D\u79F0"},{kind:"text",name:"requestId",label:"\u8BF7\u6C42 ID",initial:i.requestId,placeholder:"\u641C\u7D22\u8BF7\u6C42 ID"},{kind:"select",name:"token",label:"\u4EE4\u724C",options:[{value:"",label:"\u5168\u90E8\u4EE4\u724C"},...[...new Set(x.map(S=>S.name))].map(S=>({value:S,label:S}))],initial:i.token},{kind:"select",name:"group",label:"\u5206\u7EC4",options:[{value:"",label:"\u5168\u90E8\u5206\u7EC4"},...g.map(S=>({value:S.name,label:S.name}))],initial:i.group},{kind:"select",name:"status",label:"\u72B6\u6001",options:vv,initial:i.status},{kind:"select",name:"range",label:"\u65F6\u95F4\u8303\u56F4",options:Cv,initial:i.range},{kind:"text",name:"since",label:"\u5F00\u59CB\u65E5\u671F",initial:i.since,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"},{kind:"text",name:"until",label:"\u7ED3\u675F\u65E5\u671F",initial:i.until,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"}],onCancel:b,onSubmit:S=>{let y=S.range??"",R=(S.since??"").trim(),N=(S.until??"").trim();if(y==="custom"&&(R!==""&&!Oh.safeParse(R).success||N!==""&&!Oh.safeParse(N).success)){c("\u65E5\u671F\u65E0\u6548");return}s({model:S.model??"",requestId:S.requestId??"",token:S.token??"",group:S.group??"",status:S.status??"",range:y,since:R,until:N}),m.reset(),r({name:"list"})}});if(o.name==="detail")return lt(Rv,{log:o.log,quotaPerUsd:T.quotaPerUsd,width:t});let k=Ut(4,t);return Ta(yr,{flexDirection:"column",children:[lt(yr,{height:k+1,flexDirection:"column",overflow:"hidden",children:lt(V,{state:p,loading:"\u6B63\u5728\u7EDF\u8BA1\u7B5B\u9009\u7ED3\u679C",width:t,children:S=>lt(it,{width:t,tiles:[{label:"\u6D88\u8017",value:Te(S.quotaCost,T.quotaPerUsd)},{label:"RPM",value:Le(S.rpm)},{label:"TPM",value:Le(S.tpm)},{label:"\u5E76\u53D1",value:Le(S.concurrency)}]})})}),lt(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u4F7F\u7528\u65E5\u5FD7",width:t,children:S=>Ta(yr,{flexDirection:"column",children:[lt(de,{retain:"list",items:S.items,width:t,height:Math.max(3,n-2-k),columns:[{label:"\u65F6\u95F4"},{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u6D88\u8017",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:y=>[K(y.createdAt),y.modelDisplayName,Le(y.promptTokens),Le(y.completionTokens),Xo(y.quotaCost,T.quotaPerUsd),yt(Ki(y.status))],onOpen:y=>r({name:"detail",log:y}),emptyLabel:h?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u8C03\u7528\u8BB0\u5F55",emptyDescription:h?void 0:"\u901A\u8FC7\u4EE4\u724C\u8C03\u7528 API \u540E\uFF0C\u660E\u7EC6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),lt(We,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})}})})}import{Box as Dn,Text as Mo}from"ink";import{useState as Iv}from"react";import{z as we}from"zod";var _v=hc.extend({id:we.number().int(),model:we.string(),displayName:we.string(),rules:_u}),Pv=we.object({quotaPerUsd:we.number(),minTopupCny:we.number(),models:we.array(_v)});function wa(e){return fn(Pv,`${e}/api/pricing`)}var Av=we.object({cnyPerUsd:we.number(),groups:we.array(we.object({id:we.number().int(),name:we.string(),description:we.string(),multiplier:we.number()})),stats:we.object({requests:we.number(),errors:we.number(),latencyP50Ms:we.number().nullable(),firstByteP50Ms:we.number().nullable()}),heartbeat:we.object({groups:we.array(we.object({id:we.number().int(),name:we.string(),minutes:we.array(we.object({requests:we.number(),errors:we.number()}))}))})});function Bh(e){return A(Av,`/pricing/${e}`)}var Ev=we.object({data:we.array(we.object({id:we.string()}))});async function Fh(e,t,n){return(await fn(Ev,`${e}/v1/models`,{headers:{authorization:`Bearer ${t}`},...n===void 0?{}:{timeoutMs:n}})).data.map(r=>r.id)}var Uh=()=>A(Ou,"/provider-status");import{Text as br}from"ink";import{jsx as ka,jsxs as jh}from"react/jsx-runtime";var Mv=` ${ae.bullet} `,Hh=1;function qh({providers:e}){return jh(br,{wrap:"truncate",children:[ka(br,{color:f.faintForeground,children:"\u5B98\u65B9\u72B6\u6001"}),e.map(t=>{let n=$u(t);return jh(br,{children:[ka(br,{color:f.faintForeground,children:Mv}),ka(br,{color:f.foreground,children:`${wd(t.provider)} `}),ka(br,{color:et[n.tone],children:n.label})]},t.provider)})]})}import{jsx as Pe,jsxs as bi}from"react/jsx-runtime";var Nv=4,Lv=1+qe,Ov=e=>e.requests===0?f.border:e.errors===0?f.success:e.errors/e.requests>=.5?f.danger:f.warning;function Dv({minutes:e,width:t}){let n=e.slice(Math.max(0,e.length-t)),o=[];for(let r of n){let i=Ov(r),s=o[o.length-1];s!==void 0&&s.color===i?s.count+=1:o.push({color:i,count:1})}return Pe(Mo,{wrap:"truncate",children:o.map((r,i)=>Pe(Mo,{color:r.color,children:ae.barFilled.repeat(r.count)},i))})}function $v({price:e,width:t,contentRows:n}){let o=O(),r=Q([e.id,o.revision],()=>Bh(e.id)),i=Eu(e,e.rules),s=i.length>1,a=e.rules.filter(Pu),c=t-ge,l=1+i.length,u=1+a.length;return Pe(V,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u8BE6\u60C5",width:t,children:m=>{let p=m.stats,d=[{label:"\u53EF\u7528\u7387",value:p.requests>0?`${((p.requests-p.errors)/p.requests*100).toFixed(1)}%`:"\u2014"},{label:"\u8C03\u7528\u6B21\u6570",value:Le(p.requests)},{label:"\u5EF6\u8FDF P50",value:p.latencyP50Ms!==null?`${ao(p.latencyP50Ms)} s`:"\u2014"},{label:"\u9996\u5B57\u8282 P50",value:p.firstByteP50Ms!==null?`${ao(p.firstByteP50Ms)} s`:"\u2014"}],b=a.length>0?X+Xe+u:0,h=Lv+Xe+Ut(d.length,c,2)+X+Xe+l+b+X+Xe,g=m.heartbeat.groups.length,x=n-h-Nv-X-Xe,T=Math.max(0,Math.floor(x/2));T<g&&(T=Math.max(0,Math.floor((x-1)/2))),T=Math.min(g,T);let k=T>0?X+Xe+T*2+(T<g?1:0):0,S=Math.max(1,n-h-k);return bi(Dn,{flexDirection:"column",children:[Pe(Dn,{marginBottom:qe,children:bi(Mo,{wrap:"truncate",children:[Pe(Mo,{bold:!0,color:f.foreground,children:e.displayName}),Pe(Mo,{color:f.faintForeground,children:` ${e.model}`})]})}),Pe(pe,{title:"\u8FD1 24 \u5C0F\u65F6",note:"\u5168\u90E8\u5206\u7EC4\u7684\u7EFC\u5408\u8C03\u7528\u7EDF\u8BA1",width:t,children:Pe(it,{width:c,tiles:d,maxPerRow:2})}),T>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:bi(pe,{title:"\u53EF\u7528\u6027",note:"\u6700\u8FD1\u4E00\u6BB5\u65F6\u95F4\u5404\u5206\u7EC4\u7684\u8C03\u7528\u5065\u5EB7\u72B6\u51B5",width:t,children:[m.heartbeat.groups.slice(0,T).map(y=>bi(Dn,{flexDirection:"column",children:[Pe(Mo,{wrap:"truncate",color:f.foreground,children:y.name}),Pe(Dv,{minutes:y.minutes,width:c})]},y.id)),T<g&&Pe(Mo,{color:f.faintForeground,children:`\u5176\u4F59 ${g-T} \u4E2A\u5206\u7EC4\u672A\u663E\u793A`})]})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u6A21\u578B\u4EF7\u683C",note:"\u6BCF\u767E\u4E07 Token \u7684\u7F8E\u5143\u6807\u4EF7",width:t,children:Pe(de,{items:i,width:c,height:l,columns:[{label:"\u6863\u4F4D"},...s?[{label:"\u8F93\u5165\u957F\u5EA6"}]:[],{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:y=>[y.name,...y.range===null?[]:[y.range],pn(y.price.inputPricePerMillionTokens,"-"),pn(y.price.outputPricePerMillionTokens,"-"),pn(y.price.cachedInputPricePerMillionTokens,"-"),pn(y.price.cacheWritePricePerMillionTokens,"-")]})})}),a.length>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u8BF7\u6C42\u53C2\u6570\u500D\u7387",note:"\u547D\u4E2D\u65F6 Token \u8D39\u7528\u4E58\u4EE5\u500D\u7387\uFF0C\u591A\u6761\u547D\u4E2D\u4F9D\u6B21\u76F8\u4E58",width:t,children:Pe(de,{items:a,width:c,height:u,columns:[{label:"\u53C2\u6570\u540D",shrink:!0},{label:"\u53C2\u6570\u503C",shrink:!0},{label:"\u500D\u7387",align:"right"}],row:y=>[y.param,y.value,`\xD7${y.multiplier}`]})})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u5206\u7EC4\u4EF7\u683C",note:"\u500D\u7387\u968F\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u800C\u5B9A\uFF0C\u5355\u4EF7\u4E3A 1 \u7F8E\u5143\u6807\u4EF7\u7528\u91CF\u7684\u4EBA\u6C11\u5E01\u4EF7\u683C",width:t,children:m.groups.length===0?Pe(ye,{tone:"info",width:c,title:"\u6682\u65E0\u53EF\u7528\u5206\u7EC4",detail:"\u5F53\u524D\u6CA1\u6709\u542F\u7528\u7684\u6E20\u9053\u63D0\u4F9B\u8BE5\u6A21\u578B"}):Pe(de,{items:m.groups,width:c,height:S,columns:[{label:"\u5206\u7EC4",shrink:!0},{label:"\u8BF4\u660E",shrink:!0},{label:"\u500D\u7387",align:"right"},{label:"\u5355\u4EF7",align:"right"}],row:y=>[y.name,y.description,`\xD7${y.multiplier}`,`\xA5${(m.cnyPerUsd*y.multiplier).toFixed(2)}`]})})})]})}})}function Gh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Iv({name:"list"}),i=Q([e.revision],async()=>(await wa(e.ctx.site)).models),s=Q([e.revision],Uh);G(c=>{c==="r"&&e.reload()});let a=()=>{o.name==="list"?e.pop():r({name:"list"})};return Pe(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","r \u5237\u65B0","Esc \u8FD4\u56DE"],onEscape:a,children:Pe(V,{state:i,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u5B9A\u4EF7",width:t,children:c=>{if(c.length===0)return Pe(ye,{tone:"info",width:t,title:"\u6682\u65E0\u6A21\u578B"});if(o.name==="detail")return Pe($v,{price:o.price,width:t,contentRows:n});let l=s.phase==="ready"?Du(s.data.providers):[],u=l.length>0?Hh+X:0;return bi(Dn,{flexDirection:"column",children:[l.length>0&&Pe(Dn,{marginBottom:X,children:Pe(qh,{providers:l})}),Pe(de,{retain:"list",items:c,width:t,height:n-u,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:m=>[m.displayName,pn(m.inputPricePerMillionTokens,"-"),pn(m.outputPricePerMillionTokens,"-"),pn(m.cachedInputPricePerMillionTokens,"-"),pn(m.cacheWritePricePerMillionTokens,"-")],searchOf:m=>`${m.displayName} ${m.model}`,onOpen:m=>r({name:"detail",price:m}),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})]})}})})}import{Box as Io,Text as fC}from"ink";import{useState as Ma}from"react";function zh(e,t){let n=e.line??t.apiLines[0];if(n===void 0)throw new U("\u7AD9\u70B9\u672A\u914D\u7F6E\u63A5\u5165\u7EBF\u8DEF",{hint:"\u8BF7\u8054\u7CFB\u7AD9\u70B9\u7BA1\u7406\u5458\u5728\u8BBE\u7F6E\u91CC\u6DFB\u52A0\u63A5\u5165\u7EBF\u8DEF"});return n}async function Wh(e,t){let n=await Ge(e.site);return Fh(zh(fo(),n).url,t)}async function Vh(e,t,n){let o=await Ge(e.site),r=zh(fo(),o).url;return{input:{siteName:o.siteName,baseUrl:t.relayUrl(r),apiKey:n},at:t.resolveDir()}}async function Kh(e,t,n){let{input:o,at:r}=await Vh(e,t,n);t.apply(o,r)}async function Yh(e,t,n,o,r){let{input:i,at:s}=await Vh(e,t,n);t.apply({...i,model:o,models:r},s)}import{homedir as ny}from"os";import{join as Ca,resolve as Hv}from"path";import Bv from"json5";import{applyEdits as Fv,modify as Uv,parse as jv}from"jsonc-parser";function Jh(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw new U(`${t} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);return e}function Xh(e){let t=[],n=jv(e,t,{allowTrailingComma:!0});return t.length>0?null:n}function Qh(e,t){let n=Xh(e);if(n!==null)return{root:Jh(n,t),jsonc:!0};try{return{root:Jh(Bv.parse(e),t),jsonc:!1}}catch(o){throw new U(`${t} \u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:o})}}function no(e,t){let n=e;for(let o of t){if(typeof n!="object"||n===null||Array.isArray(n))return;n=n[o]}return n}function Si(e){let t=Nt(e);return t===null?null:Qh(t,e).root}function $n(e,t){let n=Si(e),o=n===null?void 0:no(n,t);return typeof o=="string"?o:null}function va(e,t){let n=Si(e);return n!==null&&no(n,t)!==void 0}function Gt(e,t){let n=Nt(e)??"{}",o=n.includes(`\r
19
19
  `)?`\r
20
20
  `:`
21
- `,r=Yh(n,e);r.jsonc||(n=JSON.stringify(r.root,null,2).replaceAll(`
22
- `,o));let i={insertSpaces:!0,tabSize:2,eol:o};try{for(let[a,c]of t)n=Ov(n,Dv(n,a,c,{formattingOptions:i}))}catch(a){throw new j(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`,{cause:a})}let s=Kh(n);if(s===null)throw new j(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);for(let[a,c]of t)if(JSON.stringify(no(s,a))!==JSON.stringify(c))throw new j(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);wn(e,n.endsWith(o)?n:`${n}${o}`,384)}var Jh=["env","ANTHROPIC_BASE_URL"],Fv=["env","ANTHROPIC_AUTH_TOKEN"],Xh=["hasCompletedOnboarding"],nm=e=>_a(e.dir,"settings.json"),Qh=e=>e.custom?_a(e.dir,".claude.json"):_a(Zh(),".claude.json"),ey={id:"claude-code",label:"Claude Code",requiresModel:!1,resolveDir(){let e=process.env.CLAUDE_CONFIG_DIR;return e?{dir:Bv(e),custom:!0}:{dir:_a(Zh(),".claude"),custom:!1}},relayUrl:e=>e,configPaths:e=>[nm(e),Qh(e)],read(e){return{baseUrl:$n(nm(e),Jh),model:null}},apply(e,t){Gt(nm(t),[[Jh,e.baseUrl],[Fv,e.apiKey]]);let n=Qh(t);Ca(n,Xh)||Gt(n,[[Xh,!0]])}};import{homedir as Hv}from"os";import{join as sm,resolve as qv}from"path";import{parse as Gv,patch as Wv}from"@decimalturn/toml-patch";import{parse as zv}from"smol-toml";import{homedir as Uv}from"os";import{resolve as jv}from"path";var xn=e=>e.toLowerCase(),Pa=e=>`${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}_API_KEY`;function Aa(e){let t=e.indexOf("/");return t===-1?null:[e.slice(0,t),e.slice(t+1)]}function Sr(e){let t=process.env[e]?.trim();if(!t)return null;let n=t.replace(/^~(?=$|[\\/])/,()=>Uv());return jv(n)}var Vv=["OPENAI_API_KEY"],ty="model_provider",om="model",rm=e=>sm(e.dir,"config.toml"),ny=e=>sm(e.dir,"auth.json");function im(e,t){try{return zv(e,{integersAsBigInt:"asNeeded"})}catch(n){throw new j(`${t} \u4E0D\u662F\u5408\u6CD5 TOML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function Kv(e,t){let n=rm(t),o=Nt(n)??"";o!==""&&im(o,n);let r=xn(e.siteName),i=Gv(o),s=i.model_providers;i.model_providers={...typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{},[r]:{name:e.siteName,base_url:e.baseUrl,wire_api:"responses",requires_openai_auth:!0}},i[ty]=r,i[om]=e.model;let a=Wv(o,i,{inlineTableStart:2}),c=im(a,n);if(c[ty]!==r||c[om]!==e.model||c.model_providers?.[r]?.base_url!==e.baseUrl)throw new j(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${n}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);wn(n,a,384)}var oy={id:"codex",label:"Codex",requiresModel:!0,resolveDir(){let e=process.env.CODEX_HOME;return e?{dir:qv(e),custom:!0}:{dir:sm(Hv(),".codex"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[rm(e),ny(e)],read(e){let t=rm(e),n=Nt(t),o=n===null?null:im(n,t),r=s=>typeof s=="string"?s:null,i=r(o?.model_provider);return{baseUrl:i===null?null:r(o?.model_providers?.[i]?.base_url),model:r(o?.[om])}},apply(e,t){Kv(e,t),Gt(ny(t),[[Vv,e.apiKey]])}};import{homedir as ry}from"os";import{join as wi,resolve as Yv}from"path";import{isMap as Jv,isScalar as Xv,parse as Qv,parseDocument as Zv}from"yaml";function Ea(e,t,n){let o=Nt(e)??"",r=o.includes(`\r
21
+ `,r=Qh(n,e);r.jsonc||(n=JSON.stringify(r.root,null,2).replaceAll(`
22
+ `,o));let i={insertSpaces:!0,tabSize:2,eol:o};try{for(let[a,c]of t)n=Fv(n,Uv(n,a,c,{formattingOptions:i}))}catch(a){throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`,{cause:a})}let s=Xh(n);if(s===null)throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);for(let[a,c]of t)if(JSON.stringify(no(s,a))!==JSON.stringify(c))throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);kn(e,n.endsWith(o)?n:`${n}${o}`,384)}var Zh=["env","ANTHROPIC_BASE_URL"],qv=["env","ANTHROPIC_AUTH_TOKEN"],ey=["hasCompletedOnboarding"],nm=e=>Ca(e.dir,"settings.json"),ty=e=>e.custom?Ca(e.dir,".claude.json"):Ca(ny(),".claude.json"),oy={id:"claude-code",label:"Claude Code",requiresModel:!1,resolveDir(){let e=process.env.CLAUDE_CONFIG_DIR;return e?{dir:Hv(e),custom:!0}:{dir:Ca(ny(),".claude"),custom:!1}},relayUrl:e=>e,configPaths:e=>[nm(e),ty(e)],read(e){return{baseUrl:$n(nm(e),Zh),model:null}},apply(e,t){Gt(nm(t),[[Zh,e.baseUrl],[qv,e.apiKey]]);let n=ty(t);va(n,ey)||Gt(n,[[ey,!0]])}};import{homedir as Wv}from"os";import{join as sm,resolve as Vv}from"path";import{parse as Kv,patch as Yv}from"@decimalturn/toml-patch";import{parse as Jv}from"smol-toml";import{homedir as Gv}from"os";import{resolve as zv}from"path";var Tn=e=>e.toLowerCase(),Ra=e=>`${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}_API_KEY`;function _a(e){let t=e.indexOf("/");return t===-1?null:[e.slice(0,t),e.slice(t+1)]}function Sr(e){let t=process.env[e]?.trim();if(!t)return null;let n=t.replace(/^~(?=$|[\\/])/,()=>Gv());return zv(n)}var Xv=["OPENAI_API_KEY"],ry="model_provider",om="model",rm=e=>sm(e.dir,"config.toml"),iy=e=>sm(e.dir,"auth.json");function im(e,t){try{return Jv(e,{integersAsBigInt:"asNeeded"})}catch(n){throw new U(`${t} \u4E0D\u662F\u5408\u6CD5 TOML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function Qv(e,t){let n=rm(t),o=Nt(n)??"";o!==""&&im(o,n);let r=Tn(e.siteName),i=Kv(o),s=i.model_providers;i.model_providers={...typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{},[r]:{name:e.siteName,base_url:e.baseUrl,wire_api:"responses",requires_openai_auth:!0}},i[ry]=r,i[om]=e.model;let a=Yv(o,i,{inlineTableStart:2}),c=im(a,n);if(c[ry]!==r||c[om]!==e.model||c.model_providers?.[r]?.base_url!==e.baseUrl)throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${n}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);kn(n,a,384)}var sy={id:"codex",label:"Codex",requiresModel:!0,resolveDir(){let e=process.env.CODEX_HOME;return e?{dir:Vv(e),custom:!0}:{dir:sm(Wv(),".codex"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[rm(e),iy(e)],read(e){let t=rm(e),n=Nt(t),o=n===null?null:im(n,t),r=s=>typeof s=="string"?s:null,i=r(o?.model_provider);return{baseUrl:i===null?null:r(o?.model_providers?.[i]?.base_url),model:r(o?.[om])}},apply(e,t){Qv(e,t),Gt(iy(t),[[Xv,e.apiKey]])}};import{homedir as ay}from"os";import{join as xi,resolve as Zv}from"path";import{isMap as eC,isScalar as tC,parse as nC,parseDocument as oC}from"yaml";function Pa(e,t,n){let o=Nt(e)??"",r=o.includes(`\r
23
23
  `)?`\r
24
24
  `:`
25
- `,i=o===""?[]:o.split(/\r?\n/);i.at(-1)===""&&i.pop();let s=new RegExp(`^\\s*(?:export\\s+)?${t}\\s*=`),a=i.findIndex(l=>s.test(l)),c=`${t}=${n}`;a===-1?i.push(c):i[a]=c,wn(e,`${i.join(r)}${r}`,384)}var am="custom:",cm=e=>wi(e.dir,"config.yaml"),iy=e=>wi(e.dir,".env"),Bn=e=>typeof e=="string"?e:null;function sy(e,t){try{return Qv(e)}catch(n){throw new j(`${t} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function eR(e,t,n,o){let r=cm(t),i=Zv(Nt(r)??"",{compat:"yaml-1.1"});if(i.errors.length>0)throw new j(`${r} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:i.errors[0]});if(i.contents!==null&&!Jv(i.contents))throw new j(`${r} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);let s=`${am}${n}`;try{i.setIn(["providers",n],{api:e.baseUrl,key_env:o,transport:"anthropic_messages",discover_models:!1,models:Object.fromEntries(e.models.map(l=>[l,{}]))}),Xv(i.get("model",!0))?i.set("model",{provider:s,default:e.model}):(i.setIn(["model","provider"],s),i.setIn(["model","default"],e.model))}catch(l){throw new j(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`,{cause:l})}let a=i.toString({lineWidth:0}),c=sy(a,r);if(Bn(c?.providers?.[n]?.api)!==e.baseUrl||Bn(c?.model?.provider)!==s||Bn(c?.model?.default)!==e.model)throw new j(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);wn(r,a,384)}var ay={id:"hermes-agent",label:"Hermes Agent",requiresModel:!0,resolveDir(){let e=process.env.HERMES_HOME?.trim();if(e)return{dir:Yv(e),custom:!0};if(process.platform==="win32"){let t=process.env.LOCALAPPDATA;return{dir:wi(t??wi(ry(),"AppData","Local"),"hermes"),custom:!1}}return{dir:wi(ry(),".hermes"),custom:!1}},relayUrl:e=>e,configPaths:e=>[cm(e),iy(e)],read(e){let t=cm(e),n=Nt(t),o=n===null?null:sy(n,t),r=Bn(o?.model?.provider),i=r!==null&&r.startsWith(am)?r.slice(am.length):null,s=i===null?void 0:o?.providers?.[i];return{baseUrl:Bn(s?.api)??Bn(s?.url)??Bn(s?.base_url),model:Bn(o?.model?.default)??Bn(o?.model?.model)}},apply(e,t){let n=xn(e.siteName),o=Pa(n);eR(e,t,n,o),Ea(iy(t),o,e.apiKey)}};import{existsSync as tR}from"fs";import{homedir as my}from"os";import{join as xr,resolve as uy}from"path";var nR="https://opencode.ai/config.json",dy="opencode.jsonc",oR=[dy,"opencode.json","config.json"],cy=["model"],lm=e=>oR.map(t=>xr(e.dir,t)).find(t=>tR(t))??xr(e.dir,dy),ly=()=>{let e=process.env.XDG_DATA_HOME;return xr(e?uy(e):xr(my(),".local","share"),"opencode","auth.json")},py={id:"opencode",label:"OpenCode",requiresModel:!0,resolveDir(){let e=process.env.XDG_CONFIG_HOME;return e?{dir:xr(uy(e),"opencode"),custom:!0}:{dir:xr(my(),".config","opencode"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[lm(e),ly()],read(e){let t=lm(e),n=$n(t,cy),o=n===null?null:Aa(n);if(o===null)return{baseUrl:null,model:null};let[r,i]=o;return{baseUrl:$n(t,["provider",r,"options","baseURL"]),model:i}},apply(e,t){let n=lm(t),o=xn(e.siteName),r=[[["provider",o],{npm:"@ai-sdk/anthropic",name:e.siteName,options:{baseURL:e.baseUrl},models:Object.fromEntries(e.models.map(i=>[i,{name:i}]))}],[cy,`${o}/${e.model}`]];Ca(n,["$schema"])||r.unshift([["$schema"],nR]),Gt(n,r),Gt(ly(),[[[o],{type:"api",key:e.apiKey}]])}};import{homedir as rR}from"os";import{join as um}from"path";var fy=["models","providers"],Ma=["agents","defaults","model"],gy=["agents","defaults","models"],mm=e=>Sr("OPENCLAW_CONFIG_PATH")??um(e.dir,"openclaw.json"),hy=e=>um(e.dir,".env"),yy=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function iR(e){let t=no(e,Ma),n=yy(t)?t.primary:t;return typeof n=="string"?n:null}var by={id:"openclaw",label:"OpenClaw",requiresModel:!0,resolveDir(){let e=Sr("OPENCLAW_STATE_DIR");if(e!==null)return{dir:e,custom:!0};let t=Sr("OPENCLAW_HOME");return{dir:um(t??rR(),".openclaw"),custom:t!==null}},relayUrl:e=>e,configPaths:e=>[mm(e),hy(e)],read(e){let t=Ti(mm(e)),n=t===null?null:iR(t),o=n===null?null:Aa(n);if(t===null||o===null)return{baseUrl:null,model:null};let[r,i]=o,s=no(t,[...fy,r,"baseUrl"]);return{baseUrl:typeof s=="string"?s:null,model:i}},apply(e,t){let n=mm(t),o=xn(e.siteName),r=Pa(o),i=Ti(n)??{},s=`${o}/${e.model}`,a=[[[...fy,o],{baseUrl:e.baseUrl,apiKey:{source:"env",provider:"default",id:r},api:"anthropic-messages",models:e.models.map(c=>({id:c,name:c}))}],yy(no(i,Ma))?[[...Ma,"primary"],s]:[Ma,{primary:s}]];for(let c of e.models){let l=`${o}/${c}`;no(i,[...gy,l])===void 0&&a.push([[...gy,l],{}])}Gt(n,a),Ea(hy(t),r,e.apiKey)}};import{homedir as sR}from"os";import{join as pm}from"path";var dm=e=>pm(e.dir,"models.json"),Ia=e=>pm(e.dir,"settings.json"),Sy={id:"pi-coding-agent",label:"Pi Coding Agent",requiresModel:!0,resolveDir(){let e=Sr("PI_CODING_AGENT_DIR");return e!==null?{dir:e,custom:!0}:{dir:pm(sR(),".pi","agent"),custom:!1}},relayUrl:e=>e,configPaths:e=>[dm(e),Ia(e)],read(e){let t=$n(Ia(e),["defaultProvider"]);return{baseUrl:t===null?null:$n(dm(e),["providers",t,"baseUrl"]),model:$n(Ia(e),["defaultModel"])}},apply(e,t){let n=xn(e.siteName);Gt(dm(t),[[["providers",n],{baseUrl:e.baseUrl,api:"anthropic-messages",apiKey:e.apiKey,models:e.models.map(o=>({id:o,name:o}))}]]),Gt(Ia(t),[[["defaultProvider"],n],[["defaultModel"],e.model]])}};var xy=[ey,oy,by,ay,py,Sy];var aR=6e3,cR=2,Ty=e=>Jt(`${e.url}/api/site-config`,{timeoutMs:aR});async function lR(e){try{await Ty(e);let t=Number.POSITIVE_INFINITY;for(let n=0;n<cR;n+=1){let o=Date.now();await Ty(e),t=Math.min(t,Date.now()-o)}return{line:e,latencyMs:t}}catch{return{line:e,latencyMs:null}}}async function wy(e){let t=[];for(let n of e)t.push(await lR(n));return t}import{jsx as $e,jsxs as La}from"react/jsx-runtime";var uR=10,dR=3,ky=4,_y=e=>1+Math.max(1,Math.min(e,ky))+(e>ky?1:0);function vy(e,t){let n=e.trim();if(n==="")return null;let o=Number(n),r=Math.round(o*t);return!Number.isFinite(o)||o<=0||r<1?"invalid":r}var Ry=e=>e.map(t=>({value:String(t.id),label:`${t.name} \xD7${t.multiplier}`})),Cy=(e,t)=>{let n=e.find(o=>String(o.id)===t);return n===void 0?void 0:`${n.description}\uFF08\u8BA1\u8D39\u500D\u7387 \xD7${n.multiplier}\uFF09`};function pR({lines:e,measured:t,effective:n,width:o,isActive:r,onPick:i}){let s=a=>{if(t===null)return"\u6D4B\u91CF\u4E2D";let c=t.find(l=>l.line.url===a.url);return c===void 0||c.latencyMs===null?"\u4E0D\u53EF\u8FBE":`${c.latencyMs} ms`};return $e(de,{title:"API \u63A5\u5165\u5730\u5740",note:n===void 0?void 0:`\u5F53\u524D ${n.name}`,width:o,children:$e(ue,{retain:"lines",items:e,width:o-pe,height:_y(e.length),isActive:r,columns:[{label:"\u7EBF\u8DEF"},{label:"\u5EF6\u8FDF",align:"right"},{label:"\u8BF4\u660E",shrink:!0},{label:"\u72B6\u6001"}],row:a=>[a.name,s(a),a.description,n?.url===a.url?"\u4F7F\u7528\u4E2D":""],searchOf:a=>`${a.name} ${a.url}`,onOpen:i,emptyLabel:"\u7AD9\u70B9\u672A\u914D\u7F6E\u63A5\u5165\u7EBF\u8DEF\uFF0C\u8BF7\u8054\u7CFB\u7AD9\u70B9\u7BA1\u7406\u5458\u6DFB\u52A0"})})}function Py(){let e=L(),{width:t}=H(),n=te(),[o,r]=Na({name:"list"}),[i,s]=Na(!1),[a,c]=Na(()=>fo().line),[l,u]=Na(0),{busy:m,error:f,reset:d,fail:h,run:y}=le();Ce(m!==null||o.name==="created"||o.name==="apply-pick"||o.name==="apply-model");let g=ee([e.revision],async()=>{let[A,$,Z]=await Promise.all([Ta(),xa(),ze(e.ctx.site)]);return{tokens:A,groups:$,site:Z}}),x=g.phase==="ready"?g.data.site.apiLines:[],T=ee([l,x.map(A=>A.url).join("|")],()=>wy(x)),R=m!==null,b=o.name==="list"&&!R,S=A=>{r({name:"list"}),e.reload(),e.toast("ok",A)};G(A=>{if(A==="r"){u($=>$+1),e.reload();return}i||(A==="n"?r({name:"create"}):A==="l"&&x.length>0&&s(!0))},b);let v=A=>{rs($=>{$.line={name:A.name,url:A.url}}),c({name:A.name,url:A.url}),s(!1),e.toast("ok",`\u5DF2\u9009\u7528\u7EBF\u8DEF ${A.name}\uFF0C\u65B0\u5EFA\u4EE4\u724C\u5E76\u5199\u5165\u914D\u7F6E\u540E\u751F\u6548`)},M=(A,$,Z)=>{y("\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",()=>Ph({name:A,groupId:$,quotaLimit:Z}),{onSuccess:oe=>{e.reload(),r({name:"created",token:oe,secret:oe.token})}})},N=A=>{y("\u6B63\u5728\u5220\u9664\u4EE4\u724C",()=>Ah(A.id),{onSuccess:()=>S("\u4EE4\u724C\u5DF2\u5220\u9664")})},O=(A,$)=>{y("\u6B63\u5728\u8BFB\u53D6\u5BA2\u6237\u7AEF\u914D\u7F6E",async()=>xy.map(Z=>{let oe=Z.resolveDir(),fe=Z.read(oe);return{client:Z,configured:fe.baseUrl!==null,paths:Z.configPaths(oe),model:fe.model}}),{failToast:!0,onSuccess:Z=>r({name:"apply-pick",token:A,secret:$,targets:Z})})},U=(A,$,Z)=>{y("\u6B63\u5728\u5199\u5165",Z,{failToast:!0,onSuccess:()=>{r({name:"list"}),e.toast("ok",_e([`\u5DF2\u5199\u5165 ${A}`,$]))}})},C=(A,$)=>{let Z=A.targets.find(fe=>fe.client.id===$);if(Z===void 0)return;let{client:oe}=Z;if(!oe.requiresModel){U(oe.label,void 0,()=>Wh(e.ctx,oe,A.secret));return}y("\u6B63\u5728\u8BFB\u53D6\u53EF\u8DEF\u7531\u7684\u6A21\u578B",async()=>{let fe=await qh(e.ctx,A.secret);if(fe.length===0)throw new j("\u8BE5\u4EE4\u724C\u6240\u5728\u5206\u7EC4\u6CA1\u6709\u53EF\u8DEF\u7531\u7684\u6A21\u578B\uFF0C\u6362\u4E00\u4E2A\u5206\u7EC4\u540E\u91CD\u65B0\u521B\u5EFA");return fe},{failToast:!0,onSuccess:fe=>r({name:"apply-model",token:A.token,secret:A.secret,targets:A.targets,needs:{...Z,client:oe},models:fe})})},w=(A,$)=>{d(),r(A==="rename"?{name:"rename",token:$}:A==="regroup"?{name:"regroup",token:$}:A==="relimit"?{name:"relimit",token:$}:{name:"confirm-delete",token:$})},E=()=>{if(o.name==="list"){i?s(!1):e.pop();return}if(d(),o.name==="apply-pick"){r({name:"created",token:o.token,secret:o.secret});return}if(o.name==="apply-model"){r({name:"apply-pick",token:o.token,secret:o.secret,targets:o.targets});return}r({name:"list"})},_=()=>o.name!=="list"?["Esc \u8FD4\u56DE"]:i?["\u2191\u2193 \u79FB\u52A8","Enter \u9009\u7528","/ \u8FC7\u6EE4","r \u5237\u65B0","Esc \u8FD4\u56DE"]:["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","l \u63A5\u5165\u5730\u5740","/ \u8FC7\u6EE4","r \u5237\u65B0"];return o.name==="created"||o.name==="apply-pick"||o.name==="apply-model"?$e(K,{hints:_(),onEscape:E,isActive:m===null,children:La(Mo,{flexDirection:"column",children:[m!==null&&$e(De,{label:m}),o.name==="created"&&!R&&La(Mo,{flexDirection:"column",children:[$e(he,{tone:"ok",width:t,title:"\u4EE4\u724C\u5DF2\u521B\u5EFA",detail:"\u8BF7\u7ACB\u5373\u590D\u5236\u5E76\u59A5\u5584\u4FDD\u5B58\u3002\u51FA\u4E8E\u5B89\u5168\u8003\u8651\uFF0C\u5B8C\u6574\u4EE4\u724C\u53EA\u663E\u793A\u8FD9\u4E00\u6B21\uFF0C\u5173\u95ED\u540E\u5C06\u65E0\u6CD5\u518D\u6B21\u67E5\u770B\u3002"}),$e(Mo,{marginTop:1,children:$e(mR,{color:p.accent,children:o.secret})}),$e(Mo,{marginTop:1,children:$e(ce,{width:t,items:[{value:"apply",label:"\u5199\u5165\u914D\u7F6E"},{value:"back",label:"\u6211\u5DF2\u4FDD\u5B58"}],onSelect:A=>{A==="back"?r({name:"list"}):O(o.token,o.secret)}})})]}),o.name==="apply-pick"&&!R&&$e(de,{title:"\u5199\u5165\u914D\u7F6E",note:o.token.name,width:t,children:$e(ce,{width:t-pe,height:n-Ze,retain:"apply",items:o.targets.map(A=>({value:A.client.id,label:A.client.label,badge:A.configured?"\u5DF2\u914D\u7F6E":"\u672A\u914D\u7F6E",badgeTone:A.configured?"accent":void 0,hint:A.paths.join(" ")})),onSelect:A=>C(o,A)})}),o.name==="apply-model"&&!R&&$e(ne,{title:`${o.needs.client.label} \u9ED8\u8BA4\u6A21\u578B`,width:t,submitLabel:"\u5199\u5165",error:f,fields:[{kind:"select",name:"model",label:"\u6A21\u578B",options:o.models.map(A=>({value:A,label:A})),initial:o.needs.model!==null&&o.models.includes(o.needs.model)?o.needs.model:o.models[0],hint:`\u5199\u5165\u540E\u4F5C\u4E3A ${o.needs.client.label} \u7684\u9ED8\u8BA4\u6A21\u578B`}],onCancel:E,onSubmit:A=>{let $=A.model;if($===void 0||$===""){h("\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B");return}U(o.needs.client.label,$,()=>zh(e.ctx,o.needs.client,o.secret,$,o.models))}})]})}):$e(K,{hints:_(),onEscape:E,isActive:m===null,children:$e(W,{state:g,loading:"\u6B63\u5728\u8BFB\u53D6\u4EE4\u724C",width:t,children:({tokens:A,groups:$,site:Z})=>{let oe=Q+Ze+_y(Z.apiLines.length),fe=Math.max(dR,n-(o.name==="list"?oe:uR));return La(Mo,{flexDirection:"column",children:[$e(Mo,{flexDirection:"column",marginBottom:Q,children:$e(ue,{retain:"list",items:A,width:t,height:fe,isActive:b&&!i,columns:[{label:"\u540D\u79F0",shrink:!0},{label:"\u5206\u7EC4"},{label:"\u5DF2\u6D88\u8D39",align:"right"},{label:"\u8D39\u7528\u9650\u5236",align:"right"},{label:"\u5BC6\u94A5"}],row:D=>{let k=Te(D.usedQuota,Z.quotaPerUsd);return[D.name,D.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664",D.quotaLimit!==null&&D.usedQuota>=D.quotaLimit?{text:k,tone:"danger"}:k,D.quotaLimit===null?"\u4E0D\u9650":Te(D.quotaLimit,Z.quotaPerUsd),Di(D.keyPrefix,D.keySuffix)]},searchOf:D=>`${D.name} ${D.groupName??""}`,onOpen:D=>r({name:"actions",token:D}),emptyLabel:"\u6682\u65E0\u4EE4\u724C",emptyDescription:"\u521B\u5EFA\u4E00\u4E2A\u4EE4\u724C\u5373\u53EF\u5F00\u59CB\u8C03\u7528\u4E2D\u8F6C API"})}),m!==null&&(o.name==="list"||o.name==="actions"||o.name==="confirm-delete")&&$e(De,{label:m}),o.name==="list"&&$e(pR,{lines:Z.apiLines,measured:T.phase==="ready"?T.data:null,effective:a??Z.apiLines[0],width:t,isActive:b&&i,onPick:v}),o.name==="actions"&&!R&&La(de,{title:o.token.name,width:t,children:[$e(Ye,{width:t-pe,items:[["\u5206\u7EC4",o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"],["\u5DF2\u6D88\u8D39",Te(o.token.usedQuota,Z.quotaPerUsd)],["\u8D39\u7528\u9650\u5236",o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,Z.quotaPerUsd)],["\u5BC6\u94A5",Di(o.token.keyPrefix,o.token.keySuffix)]]}),$e(Mo,{marginTop:1,children:$e(ce,{width:t-pe,items:[{value:"rename",label:"\u540D\u79F0",hint:o.token.name},{value:"regroup",label:"\u5206\u7EC4",hint:o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"},{value:"relimit",label:"\u8D39\u7528\u9650\u5236",hint:o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,Z.quotaPerUsd)},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:D=>w(D,o.token)})})]}),o.name==="create"&&$e(ne,{title:"\u521B\u5EFA\u4EE4\u724C",width:t,submitLabel:"\u521B\u5EFA",error:f,busy:R,busyLabel:"\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"},{kind:"select",name:"group",label:"\u5206\u7EC4",options:Ry($),initial:String($[0]?.id??""),hint:D=>Cy($,D)},{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:"\u7D2F\u8BA1\u6D88\u8D39\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD",optional:!0}],onCancel:E,onSubmit:D=>{let k=(D.name??"").trim();if(k===""){h("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}let X=$.find(re=>String(re.id)===D.group);if(X===void 0){h("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}let F=vy(D.limit??"",Z.quotaPerUsd);if(F==="invalid"){h("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}M(k,X.id,F)}}),o.name==="rename"&&$e(ne,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:f,busy:R,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:o.token.name,placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"}],onCancel:E,onSubmit:D=>{let k=(D.name??"").trim();if(k===""){h("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}y("\u6B63\u5728\u4FDD\u5B58",()=>wa(o.token.id,{name:k}),{onSuccess:()=>S("\u5DF2\u4FDD\u5B58")})}}),o.name==="regroup"&&$e(ne,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:f,busy:R,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"select",name:"group",label:"\u5206\u7EC4",options:Ry($),initial:String(o.token.groupId??$[0]?.id??""),hint:o.token.groupId===null?"\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u5206\u7EC4":D=>Cy($,D)}],onCancel:E,onSubmit:D=>{let k=$.find(X=>String(X.id)===D.group);if(k===void 0){h("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}y("\u6B63\u5728\u4FDD\u5B58",()=>wa(o.token.id,{groupId:k.id}),{onSuccess:()=>S("\u5DF2\u4FDD\u5B58")})}}),o.name==="relimit"&&$e(ne,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:f,busy:R,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",initial:o.token.quotaLimit===null?"":String(Math.round(o.token.quotaLimit/Z.quotaPerUsd*100)/100),placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:`\u8BE5\u4EE4\u724C\u5DF2\u7D2F\u8BA1\u6D88\u8D39 ${Te(o.token.usedQuota,Z.quotaPerUsd)}\uFF0C\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,optional:!0}],onCancel:E,onSubmit:D=>{let k=vy(D.limit??"",Z.quotaPerUsd);if(k==="invalid"){h("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}y("\u6B63\u5728\u4FDD\u5B58",()=>wa(o.token.id,{quotaLimit:k}),{onSuccess:()=>S("\u5DF2\u4FDD\u5B58")})}}),o.name==="confirm-delete"&&!R&&$e(Ae,{width:t,title:"\u5220\u9664\u4EE4\u724C",detail:`\u5220\u9664\u300C${o.token.name}\u300D\u540E\u8BE5\u4EE4\u724C\u7ACB\u5373\u5931\u6548\uFF0C\u4F7F\u7528\u5B83\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,confirmLabel:"\u5220\u9664",error:f,onConfirm:()=>N(o.token),onCancel:E})]})}})})}import{Box as My,Text as gR}from"ink";import{useEffect as hR,useState as Ly}from"react";import yR from"string-width";import{z as fR}from"zod";var Oa=()=>P(ku,"/docs/manifest"),Ay=e=>P(vu,`/docs/pages/${e}`),Ey=e=>P(fR.array(Ru),je("/docs/search",{q:e}));import{jsx as Fn,jsxs as Ny}from"react/jsx-runtime";var bR=250,Iy="/ ";function SR(e,t){let[n,o]=Ly(e);return hR(()=>{let r=setTimeout(()=>o(e),t);return()=>clearTimeout(r)},[e,t]),n}var xR=e=>e.groups.flatMap((t,n)=>[...n===0?[]:[{heading:""}],{heading:t.title},...t.items.map(o=>({value:o,label:o.title}))]);function Oy(){let e=L(),{width:t}=H(),n=te(),[o,r]=Ie("query",()=>""),[i,s]=Ly(!1),a=SR(o.trim(),bR),c=a.length>hc,l=ee([e.revision],Oa),u=qt(ee([a,e.revision],()=>a===""||c?Promise.resolve(null):Ey(a))),m=l.phase==="ready",f=o.trim()!=="",d=i||f;G(T=>{if(T==="r"){e.reload();return}m&&T.startsWith("/")&&(s(!0),T.length>1&&r(T.slice(1)))},!i);let h=()=>{if(!d){e.pop();return}s(!1),r("")},y=i?["Enter \u786E\u8BA4","Esc \u53D6\u6D88"]:m?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","/ \u641C\u7D22","r \u5237\u65B0",...f?["Esc \u8FD4\u56DE"]:[]]:["r \u5237\u65B0"],g=(T,R)=>e.push("doc",{slug:T,anchor:R}),x=Math.max(3,n-(d?1:0));return Fn(K,{hints:y,onEscape:h,children:Fn(W,{state:l,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u76EE\u5F55",width:t,children:T=>Ny(My,{flexDirection:"column",children:[d&&Ny(My,{children:[Fn(gR,{color:p.accent,children:Iy}),Fn(Zo,{value:o,onChange:r,onSubmit:()=>s(!1),isActive:i,placeholder:"\u641C\u7D22\u6587\u6863",width:t-yR(Iy)})]}),f?c?Fn(Ft,{message:`\u5173\u952E\u8BCD\u6700\u591A ${hc} \u4E2A\u5B57\u7B26`,width:t}):Fn(W,{state:u,loading:"\u6B63\u5728\u641C\u7D22",width:t,children:R=>R===null?Fn(De,{label:"\u6B63\u5728\u641C\u7D22"}):Fn(ue,{retain:"results",items:R,width:t,height:x,isActive:!i,columns:[{label:"\u6807\u9898"},{label:"\u6458\u8981",shrink:!0}],row:b=>[b.title,b.snippet],onOpen:b=>g(b.slug,b.anchor),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})}):Fn(ce,{retain:"toc",items:xR(T),width:t,height:x,isActive:!i,onSelect:R=>g(R.slug,null)})]})})})}import{Box as CR,Text as _R}from"ink";import{useMemo as PR,useState as AR}from"react";import{spawn as TR}from"child_process";var wR={darwin:[{command:"pbcopy",args:[]}],win32:[{command:"clip",args:[]}],linux:[{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}]};function kR(e,t){return new Promise((n,o)=>{let r=TR(e.command,e.args,{stdio:["pipe","ignore","ignore"]});r.on("error",i=>{i.code==="ENOENT"?n(!1):o(new j(`\u6267\u884C ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))}),r.on("close",i=>{i===0?n(!0):o(new j(`${e.command} \u9000\u51FA\u7801 ${i??"null"}`))}),r.stdin.on("error",i=>o(new j(`\u5199\u5165 ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))),r.stdin.end(t)})}async function Da(e){let t=wR[process.platform];if(t===void 0)throw new j(`\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u5199\u5165\u526A\u8D34\u677F\uFF08${process.platform}\uFF09`);for(let n of t)if(await kR(n,e))return;throw new j("\u672A\u627E\u5230\u53EF\u7528\u7684\u526A\u8D34\u677F\u547D\u4EE4")}import{Lexer as vR,walkTokens as RR}from"marked";function Dy(e,t){let n=[],o=[],r=new Set,i="";for(let s of vR.lex(e,{gfm:!0,breaks:!1}))s.type==="heading"&&(i=il(s.tokens,"docs")),RR([s],a=>{if(a.type==="code"){o.push({lang:a.lang??"",text:a.text,section:i});return}if(a.type!=="link"||r.has(a.href))return;r.add(a.href);let c=il(a.tokens,"docs"),l=a.href.startsWith("#")?{slug:t,anchor:yc(a.href.slice(1))}:Oi(a.href);n.push(l===null?{kind:"external",text:c,href:a.href}:{kind:"guide",text:c,...l})});return{links:n,codes:o}}var $y=e=>Vn(e).split(`
26
- `).map(t=>t.trim()).filter(t=>t!=="").join(" ");import{jsx as Io,jsxs as NR}from"react/jsx-runtime";var ER=1,MR=16;function By({params:e}){let{depth:t}=L();return Io(IR,{params:e},t)}function IR({params:e}){let t=L(),{width:n}=H(),o=te(),[r,i]=AR("body"),s=qt(ee([e.slug,t.revision],async()=>{let[y,g]=await Promise.all([Ay(e.slug),Oa()]),x=new Map(g.groups.flatMap(T=>T.items.map(R=>[R.slug,R.title])));return{page:y,titles:x,outline:Dy(y.markdown,e.slug)}})),a=s.phase==="ready"?s.data:null,c=a===null?null:a.page.markdown,l=PR(()=>c===null?[]:hn(c,n,"docs"),[c,n]);G(y=>{if(r!=="body")return;if(y==="r"){t.reload();return}if(a===null)return;let{outline:g}=a;y==="l"&&g.links.length>0?i("links"):y==="c"&&g.codes.length>0&&i("codes")});let u=()=>{r==="body"?t.pop():i("body")},m=y=>{i("body"),Da(y).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))},f=()=>{if(a===null)return["r \u5237\u65B0"];if(r==="links")return["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00\u6216\u590D\u5236"];if(r==="codes")return["\u2191\u2193 \u79FB\u52A8","Enter \u590D\u5236"];let{outline:y}=a;return["\u2191\u2193 \u6EDA\u52A8",...y.links.length>0?["l \u94FE\u63A5"]:[],...y.codes.length>0?["c \u590D\u5236\u4EE3\u7801"]:[],"r \u5237\u65B0"]},d=a===null?"\u6587\u6863\u8BE6\u60C5":a.page.title;return Io(K,{trail:r==="links"?["\u4F7F\u7528\u6587\u6863",d,"\u94FE\u63A5"]:r==="codes"?["\u4F7F\u7528\u6587\u6863",d,"\u4EE3\u7801"]:["\u4F7F\u7528\u6587\u6863",d],hints:f(),onEscape:u,children:Io(W,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863",width:n,children:({titles:y,outline:g})=>{if(r==="links")return Io(ue,{retain:"links",items:g.links,width:n,height:o,columns:[{label:"\u94FE\u63A5",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u76EE\u6807",shrink:!0}],row:T=>T.kind==="guide"?[T.text,"\u7AD9\u5185\u6587\u6863",y.get(T.slug)??""]:[T.text,"\u5916\u90E8\u94FE\u63A5",T.href],onOpen:T=>T.kind==="guide"?t.push("doc",{slug:T.slug,anchor:T.anchor}):m(T.href)});if(r==="codes")return Io(ue,{retain:"codes",items:g.codes,width:n,height:o,columns:[{label:"\u4EE3\u7801",shrink:!0},{label:"\u8BED\u8A00"},{label:"\u7AE0\u8282",cap:MR}],row:T=>[$y(T.text),T.lang,T.section],onOpen:T=>m(T.text)});let x=e.anchor===null?-1:l.findIndex(T=>T.anchor===e.anchor);return NR(CR,{flexDirection:"column",children:[Io(dt,{retain:"body",lines:l,height:Math.max(1,o-ER),start:Math.max(0,x)}),Io(_R,{wrap:"truncate",color:p.faintForeground,children:`\u7F51\u9875\u7248 ${t.ctx.site}/docs/${e.slug}`})]})}})})}import{Box as fm}from"ink";import{jsx as un,jsxs as LR}from"react/jsx-runtime";var Fy=[["\u2191\u2193 / k j","\u79FB\u52A8\u5149\u6807\u3001\u6EDA\u52A8\u5185\u5BB9"],["\u2190\u2192","\u5207\u6362\u5206\u6BB5\u3001\u7FFB\u9875\u3001\u6539\u53D6\u503C"],["[ ]","\u5207\u6362\u9876\u680F\u4E0A\u7684\u529F\u80FD"],["Enter","\u6253\u5F00\u3001\u786E\u8BA4\u3001\u63D0\u4EA4"],["Tab","\u8868\u5355\u4E0B\u4E00\u9879\u3001\u8FDB\u5165\u56DE\u590D\u6846"],["Esc","\u9000\u56DE\u4E0A\u4E00\u5C42"],["r","\u5237\u65B0\u5F53\u524D\u6570\u636E"],["n","\u65B0\u5EFA"],["f","\u7B5B\u9009\u5217\u8868"],["/","\u8FC7\u6EE4\u5217\u8868"],["Space / a","\u591A\u9009\u52FE\u9009\u3001\u5168\u9009"],["?","\u8FD9\u5F20\u8868"],["q","\u8FD4\u56DE\u4E0A\u5C42\uFF0C\u529F\u80FD\u5C4F\u4E0A\u9000\u51FA"],["Ctrl+C","\u9000\u51FA"]],Uy=[["\u70B9\u51FB / \u6EDA\u8F6E","\u9009\u4E2D\u6253\u5F00\u3001\u6EDA\u52A8"],["Option / Alt \u62D6\u9009","\u590D\u5236\u6587\u672C"]],jy=[["\u2190\u2192 Home End","\u79FB\u52A8\u5149\u6807"],["Ctrl+A / Ctrl+E","\u884C\u9996\u3001\u884C\u5C3E"],["Ctrl+W","\u5220\u9664\u524D\u4E00\u4E2A\u8BCD"],["Ctrl+U / Ctrl+K","\u5220\u5230\u884C\u9996\u3001\u884C\u5C3E"]];function Hy({width:e,height:t}){let n=e-pe,o=[["\u7248\u672C",`${zt} v${Vt}`],["\u672C\u5730\u5B58\u50A8",kn()]],r=[Fy,Uy,jy,o],s=(a=>r.reduce((c,l)=>c+Bt+a+Vs(l.length,n),Q*(r.length-1)))(We)<=t?We:0;return LR(Gd,{height:t,children:[un(de,{title:"\u901A\u7528",width:e,gap:s,children:un(Ye,{items:Fy,width:n})}),un(fm,{marginTop:Q,flexDirection:"column",children:un(de,{title:"\u9F20\u6807",width:e,gap:s,children:un(Ye,{items:Uy,width:n})})}),un(fm,{marginTop:Q,flexDirection:"column",children:un(de,{title:"\u6587\u672C\u8F93\u5165",width:e,gap:s,children:un(Ye,{items:jy,width:n})})}),un(fm,{marginTop:Q,flexDirection:"column",children:un(de,{title:"\u5173\u4E8E",width:e,gap:s,children:un(Ye,{items:o,width:n})})})]})}import{jsx as gm}from"react/jsx-runtime";function qy(){let e=L(),{width:t}=H(),n=te();return gn(e.pop),gm(So,{header:gm(Ms,{trail:["CodeFlow","\u952E\u4F4D\u5E2E\u52A9"],width:t,onBack:e.pop,isActive:!0}),hints:["Esc \u8FD4\u56DE"],children:gm(Hy,{width:t,height:n})})}import{Box as Gy,Text as OR}from"ink";import{jsx as ki,jsxs as DR}from"react/jsx-runtime";var Wy=[{value:"login",label:"\u767B\u5F55\u8D26\u53F7",hint:"\u4F7F\u7528\u7528\u6237\u540D\u6216\u90AE\u7BB1\u7EE7\u7EED"},{value:"register",label:"\u6CE8\u518C\u8D26\u53F7",hint:"\u521B\u5EFA\u8D26\u53F7\u5F00\u59CB\u4F7F\u7528"},{value:"forgot",label:"\u627E\u56DE\u5BC6\u7801",hint:"\u901A\u8FC7\u90AE\u7BB1\u9A8C\u8BC1\u7801\u8BBE\u7F6E\u65B0\u5BC6\u7801"}];function zy(){let e=L(),{width:t}=H(),n=ri(0),o=Q+1+Q+Wy.length,r=Ps(t)&&n-_s>=o;return DR(So,{header:r?ki(As,{width:t}):null,hints:["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","? \u5E2E\u52A9","q \u9000\u51FA"],children:[ki(Gy,{marginTop:1,children:ki(OR,{color:p.mutedForeground,wrap:"truncate",children:"\u767B\u5F55\u540E\u5373\u53EF\u521B\u5EFA\u4EE4\u724C\u3001\u5199\u5165\u914D\u7F6E\u5E76\u67E5\u770B\u7528\u91CF"})}),ki(Gy,{marginTop:1,children:ki(ce,{items:Wy,width:t,retain:"menu",onSelect:i=>e.push(i)})})]})}import{Box as hm,Text as ym}from"ink";import{useState as $R}from"react";import{jsx as nn,jsxs as bm}from"react/jsx-runtime";function Vy(){let e=L(),t=Is(),{width:n}=H(),o=te(),{busy:r,run:i}=le(),[s,a]=$R({name:"list"}),c=Ve([e.revision],m=>Op({page:m}),{retain:"page"}),l=m=>{switch(m.kind){case"post":e.push("post",{id:m.postId});return;case"floor":e.push("floor",{postId:m.postId,floorId:m.floorId});return;case"ticket":e.push("ticket",{id:m.ticketId});return;case"invoices":e.select("invoices");return;case"recharge":e.select("recharge");return;case"subscription":e.select("subscription");return;case"security":e.select("profile");return}},u=m=>{a({name:"detail",message:m}),!m.read&&i("\u6B63\u5728\u6807\u8BB0\u5DF2\u8BFB",()=>$p(m.id),{failToast:!0,onSuccess:e.reload})};if(G((m,f)=>{s.name!=="list"||r!==null||(m==="r"?e.reload():f.leftArrow?c.go(-1):f.rightArrow?c.go(1):m==="a"&&t.any&&i("\u6B63\u5728\u6807\u8BB0\u5DF2\u8BFB",()=>Bp(),{failToast:!0,onSuccess:()=>{e.reload(),e.toast("ok","\u5DF2\u5168\u90E8\u6807\u4E3A\u5DF2\u8BFB")}}))}),s.name==="detail"){let m=$c(s.message),f=ud[m.target.kind],d=Pt([{text:st(m.body),color:p.foreground}],n),h=Math.max(3,o-4);return bm(K,{hints:[...d.length>h?["\u2191\u2193 \u6EDA\u52A8"]:[],`Enter ${f}`,"Esc \u8FD4\u56DE"],onEscape:()=>a({name:"list"}),children:[bm(ym,{wrap:"truncate",children:[nn(ym,{bold:!0,color:p.foreground,children:st(m.title)}),nn(ym,{color:p.faintForeground,children:` ${V(s.message.createdAt)}`})]}),nn(hm,{marginTop:1,children:nn(dt,{lines:d,height:Math.min(d.length,h)})}),nn(hm,{marginTop:1,children:r!==null?nn(De,{label:r}):nn(ce,{width:n,items:[{value:m.target,label:f}],onSelect:l})})]})}return nn(K,{hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...t.any?["a \u5168\u90E8\u5DF2\u8BFB"]:[],"r \u5237\u65B0"],children:nn(W,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u5185\u6D88\u606F",width:n,children:m=>bm(hm,{flexDirection:"column",children:[nn(ue,{retain:"list",items:m.items,width:n,height:Math.max(3,o-1),isActive:r===null,columns:[{label:"\u6D88\u606F",shrink:!0},{label:"\u5185\u5BB9",shrink:!0},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:f=>{let d=$c(f),h=st(d.title);return[f.read?h:{text:h,tone:"accent"},st(d.body),V(f.createdAt),f.read?"":{text:"\u672A\u8BFB",tone:"accent"}]},onOpen:u,emptyLabel:"\u6682\u65E0\u6D88\u606F",emptyDescription:"\u6709\u65B0\u6D88\u606F\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),r!==null?nn(De,{label:r}):nn(Ke,{page:c.page,pages:c.pages,total:c.total,width:n})]})})})}import{Box as $a,Text as No}from"ink";import{useState as Yy}from"react";import{z as xt}from"zod";var BR=xt.object({inviteCode:xt.string(),invitedCount:xt.number(),totalReward:xt.number(),rewards:xt.object({firstInviterPercent:xt.number(),firstInviteePercent:xt.number(),subsequentInviterPercent:xt.number()}),items:xt.array(xt.object({id:xt.number().int(),rewardType:Wm,rewardQuota:xt.number(),rewardQuotaReversed:xt.number(),inviterUsername:xt.string(),inviteeUsername:xt.string(),createdAt:xt.string()}))}),Ky=()=>P(BR,"/invite");import{jsx as Ct,jsxs as Ba}from"react/jsx-runtime";var FR=_t(ec,Ji,"\u5168\u90E8\u7C7B\u578B"),Jy=3;function UR(e){let t=[];return e.firstInviterPercent>0&&t.push(`\u597D\u53CB\u9996\u6B21\u5145\u503C\uFF0C\u4F60\u83B7\u5F97 ${e.firstInviterPercent}% \u989D\u5EA6\u5956\u52B1`),e.firstInviteePercent>0&&t.push(`\u597D\u53CB\u9996\u6B21\u5145\u503C\uFF0C\u597D\u53CB\u672C\u4EBA\u83B7\u5F97 ${e.firstInviteePercent}% \u989D\u5EA6\u5956\u52B1`),e.subsequentInviterPercent>0&&t.push(`\u597D\u53CB\u540E\u7EED\u6BCF\u6B21\u5145\u503C\uFF0C\u4F60\u83B7\u5F97 ${e.subsequentInviterPercent}% \u989D\u5EA6\u5956\u52B1`),t.length===0?["\u9080\u8BF7\u5956\u52B1\u6682\u672A\u5F00\u542F"]:(t.push("\u5956\u52B1\u6309\u597D\u53CB\u5B9E\u4ED8\u91D1\u989D\u5BF9\u5E94\u989D\u5EA6\u6298\u7B97"),t)}function Xy(){let e=L(),{width:t}=H(),n=te(),[o,r]=Yy("main"),[i,s]=Yy(""),a=ee([e.revision],async()=>{let[l,u]=await Promise.all([Ky(),ze(e.ctx.site)]);return{invite:l,site:u}});G(l=>{o==="main"&&(l==="r"?e.reload():l==="f"&&r("filter"))});let c=()=>{o==="main"?e.pop():r("main")};return Ct(K,{hints:o==="main"?["\u2191\u2193 \u6EDA\u52A8","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:Ct(W,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u9080\u8BF7\u4FE1\u606F",width:t,children:({invite:l,site:u})=>{if(o==="filter")return Ct(ne,{title:"\u7B5B\u9009\u5956\u52B1\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:FR,initial:i}],onCancel:c,onSubmit:x=>{s(x.type??""),r("main")}});let m=t-pe,f=UR(l.rewards),d=i===""?l.items:l.items.filter(x=>x.rewardType===i),h=x=>Ut(2,t)+Q+Bt+x+2+Q+Bt+x+f.length+Q+Bt+x,y=n-h(We)>=Jy?We:0,g=Math.max(Jy,n-h(y));return Ba($a,{flexDirection:"column",children:[Ct(it,{width:t,tiles:[{label:"\u5DF2\u9080\u8BF7\u4EBA\u6570",value:Oe(l.invitedCount)},{label:"\u7D2F\u8BA1\u5956\u52B1\u989D\u5EA6",value:Te(l.totalReward,u.quotaPerUsd)}]}),Ct($a,{marginTop:1,flexDirection:"column",children:Ba(de,{title:"\u6211\u7684\u9080\u8BF7",width:t,gap:y,children:[Ba(No,{wrap:"truncate",children:[Ct(No,{color:p.mutedForeground,children:"\u6211\u7684\u9080\u8BF7\u7801 "}),Ct(No,{color:p.accent,children:l.inviteCode})]}),Ba(No,{wrap:"truncate",children:[Ct(No,{color:p.mutedForeground,children:"\u9080\u8BF7\u94FE\u63A5 "}),Ct(No,{color:p.accent,children:`${e.ctx.site}/register?invite=${l.inviteCode}`})]})]})}),Ct($a,{marginTop:1,flexDirection:"column",children:Ct(de,{title:"\u5956\u52B1\u89C4\u5219",width:t,gap:y,children:f.map((x,T)=>Ct(No,{wrap:"truncate",color:p.mutedForeground,children:x},T))})}),Ct($a,{marginTop:1,flexDirection:"column",children:Ct(de,{title:"\u9080\u8BF7\u5956\u52B1\u8BB0\u5F55",note:i===""?void 0:Ji(i),width:t,gap:y,children:Ct(ue,{retain:"list",items:d,width:m,height:g,columns:[{label:"\u65F6\u95F4"},{label:"\u597D\u53CB",shrink:!0},{label:"\u5956\u52B1\u7C7B\u578B"},{label:"\u5956\u52B1\u989D\u5EA6",align:"right"}],row:x=>{let T=x.rewardQuota-x.rewardQuotaReversed,R=x.rewardQuotaReversed>0?`\u9000\u6B3E\u51B2\u51CF -${Te(x.rewardQuotaReversed,u.quotaPerUsd)}`:"";return[V(x.createdAt),x.rewardType==="first_invitee"?x.inviterUsername:x.inviteeUsername,Ji(x.rewardType),_e([Te(T,u.quotaPerUsd),R])]},emptyLabel:i===""?"\u6682\u65E0\u5956\u52B1\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u597D\u53CB\u901A\u8FC7\u4F60\u7684\u9080\u8BF7\u7801\u6CE8\u518C\u5E76\u5B8C\u6210\u5145\u503C\u540E\uFF0C\u5956\u52B1\u4F1A\u663E\u793A\u5728\u8FD9\u91CC":void 0})})})]})}})})}import{useState as mb}from"react";import{z as Ne}from"zod";var jR=12e4,HR=Ne.object({id:Ne.number().int(),orderNo:Ne.string(),amountCny:Ne.number().int()}),Qy=()=>P(Ne.array(HR),"/invoices/eligible-orders"),Zy=Ne.object({id:Ne.number().int(),type:Qa,title:Ne.string(),taxId:Ne.string().nullable(),invoiceNo:Ne.string().nullable(),remark:Ne.string().nullable(),amountCny:Ne.number().int(),status:jm,rejectReason:Ne.string().nullable(),rejectedAt:Ne.string().nullable(),issuedAt:Ne.string().nullable(),createdAt:Ne.string()}),qR=Zy.extend({hasFile:Ne.boolean(),orders:Ne.array(Ne.object({orderNo:Ne.string(),amountCny:Ne.number().int()}))}),eb=()=>P(Ne.array(Zy),"/invoices"),tb=e=>P(qR,`/invoices/${e}`),nb=e=>P(se,"/invoices",{method:"POST",json:e}),ob=e=>is(`/invoices/${e}/file`,{timeoutMs:jR}),GR=Ne.object({id:Ne.number().int(),type:Qa,title:Ne.string(),taxId:Ne.string().nullable()}),Fa=()=>P(Ne.array(GR),"/invoices/profiles"),rb=e=>P(se,"/invoices/profiles",{method:"POST",json:e}),ib=(e,t)=>P(se,`/invoices/profiles/${e}`,{method:"PATCH",json:t}),sb=e=>P(se,`/invoices/profiles/${e}`,{method:"DELETE"});import{Box as WR,Text as Lo,useInput as zR}from"ink";import{useEffect as VR,useState as KR}from"react";import{jsx as vi,jsxs as Sm}from"react/jsx-runtime";var YR="[x]",JR="[ ]",ab=4,Ua=2,cb=2;function lb({items:e,columns:t,row:n,selected:o,onToggle:r,onToggleAll:i,onSubmit:s,width:a,height:c,emptyLabel:l}){let[u,m]=KR(0),f=Math.max(1,c-1),d=e.length>f?Math.max(1,f-1):f;VR(()=>{m(b=>Math.min(b,Math.max(0,e.length-1)))},[e.length]);let h=cl(u,d),y=b=>{e.length!==0&&m(S=>(S+b+e.length)%e.length)};zR((b,S)=>{if(S.upArrow){y(-1);return}if(S.downArrow){y(1);return}if(S.return){s();return}b===" "&&e.length>0&&r(u)}),G(b=>{if(b==="k"){y(-1);return}if(b==="j"){y(1);return}b==="a"&&i()});let g=b=>{let S=h+b-1;return S>=0&&S<e.length?S:null},x=rt({onWheel:y,onClick:({row:b})=>{let S=g(b);S!==null&&(m(S),r(S))},onHover:({row:b})=>{let S=g(b);S!==null&&m(S)}}),T=Tl(t,e.map(b=>n(b)),a-Ua-ab),R=e.slice(h,h+d);return Sm(WR,{ref:x,flexDirection:"column",children:[Sm(Lo,{wrap:"truncate",color:p.faintForeground,children:[" ".repeat(Ua+ab),t.map((b,S)=>b.align==="right"?Kn(b.label,T[S]??0):Qe(b.label,T[S]??0)).join(" ".repeat(cb))]}),e.length===0?vi(Lo,{color:p.faintForeground,children:`${" ".repeat(Ua)}${l}`}):R.map((b,S)=>{let v=h+S,M=v===u,N=o.has(v),O=M?p.accent:p.foreground,U=n(b);return Sm(Lo,{wrap:"truncate",children:[vi(Lo,{color:p.accent,children:M?`${ie.cursor} `:" "}),vi(Lo,{color:N?p.accent:O,bold:M,children:`${N?YR:JR} `}),t.map((C,w)=>{let E=C.align==="right"?Kn(U[w]??"",T[w]??0):Qe(U[w]??"",T[w]??0);return vi(Lo,{color:O,bold:M,children:w>0?`${" ".repeat(cb)}${E}`:E},C.label)})]},v)}),(h>0||h+d<e.length)&&vi(Lo,{color:p.faintForeground,children:`${" ".repeat(Ua)}${h+1}-${Math.min(h+d,e.length)} / ${e.length}`})]})}import{jsx as Tr}from"react/jsx-runtime";function ub(){let e=L(),{width:t}=H(),n=te(),[o,r]=mb({name:"pick"}),[i,s]=mb(new Set),{busy:a,error:c,reset:l,run:u}=le();Ce(a!==null);let m=ee([e.revision],async()=>{let[h,y]=await Promise.all([Qy(),Fa()]);return{orders:h,profiles:y}});G(h=>{o.name==="pick"&&h==="r"&&e.reload()});let f=()=>{o.name==="pick"?e.pop():o.name==="preset"?r({name:"pick"}):(l(),r({name:"preset"}))},d=(h,y,g)=>{let x=(g.remark??"").trim(),T=h.filter(R=>i.has(R.id)).map(R=>R.id);u("\u6B63\u5728\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7",()=>nb({orderIds:T,type:y.type,title:y.title,taxId:y.taxId,remark:x===""?null:x}),{onSuccess:()=>{e.toast("ok","\u5DF2\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7"),e.pop()}})};return Tr(K,{trail:["\u53D1\u7968\u7BA1\u7406","\u7533\u8BF7\u5F00\u7968"],hints:o.name==="pick"?["\u2191\u2193 \u79FB\u52A8","Space \u52FE\u9009","a \u5168\u9009","Enter \u4E0B\u4E00\u6B65","r \u5237\u65B0"]:[],onEscape:f,isActive:a===null,children:Tr(W,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u53EF\u5F00\u7968\u8BA2\u5355",width:t,children:({orders:h,profiles:y})=>{if(o.name==="pick")return h.length===0?Tr(he,{tone:"info",width:t,title:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355",detail:"\u5B8C\u6210\u5145\u503C\u5E76\u652F\u4ED8\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}):Tr(lb,{items:h,width:t,height:n,columns:[{label:"\u8BA2\u5355\u53F7",shrink:!0},{label:"\u91D1\u989D",align:"right"}],row:g=>[g.orderNo,Re(g.amountCny)],selected:new Set(h.flatMap((g,x)=>i.has(g.id)?[x]:[])),onToggle:g=>{let x=h[g]?.id;x!==void 0&&s(T=>{let R=new Set(T);return R.has(x)?R.delete(x):R.add(x),R})},onToggleAll:()=>s(g=>h.every(x=>g.has(x.id))?new Set:new Set(h.map(x=>x.id))),onSubmit:()=>{if(!h.some(g=>i.has(g.id))){e.toast("warn","\u8BF7\u5148\u52FE\u9009\u8981\u5F00\u7968\u7684\u8BA2\u5355");return}if(y.length===0){e.toast("warn","\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F\uFF0C\u8FD4\u56DE\u540E\u6309 p \u65B0\u589E");return}r({name:"preset"})},emptyLabel:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355"});if(o.name==="preset"){let g=[{heading:"\u5E38\u7528\u4FE1\u606F"},...y.map(x=>({value:x,label:`${uo(x.type)} \xB7 ${x.title}`,hint:x.taxId??void 0}))];return Tr(ce,{items:g,width:t,height:n,onSelect:x=>r({name:"remark",profile:x})})}return Tr(ne,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u5907\u6CE8",width:t,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"textarea",name:"remark",label:"\u5907\u6CE8",rows:2,maxLength:200,placeholder:"\u5C55\u793A\u5728\u53D1\u7968\u7968\u9762\u5907\u6CE8\u680F\u7684\u5185\u5BB9",optional:!0}],onCancel:f,onSubmit:g=>d(h,o.profile,g)})}})})}import{Box as xm}from"ink";import{useState as XR}from"react";function db(e,t){let n=e.type??"general",o=(e.title??"").trim(),r=(e.taxId??"").trim();return o===""?(t("\u8BF7\u8F93\u5165\u62AC\u5934"),null):n==="special"&&r===""?(t("\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968\u9700\u586B\u5199\u7A0E\u53F7"),null):{type:n,title:o,taxId:r===""?null:r}}var pb=e=>[{kind:"select",name:"type",label:"\u7C7B\u578B",options:[{value:"general",label:Gr("general")},{value:"special",label:Gr("special")}],initial:e?.type??"general"},{kind:"text",name:"title",label:"\u62AC\u5934",initial:e?.title??"",placeholder:"\u4E2A\u4EBA\u6216\u5355\u4F4D\u540D\u79F0"},{kind:"text",name:"taxId",label:"\u7A0E\u53F7",initial:e?.taxId??"",placeholder:"\u7EB3\u7A0E\u4EBA\u8BC6\u522B\u53F7",optional:t=>t.type!=="special"}];import{jsx as Un,jsxs as fb}from"react/jsx-runtime";var QR=8,ZR=3;function gb(){let e=L(),{width:t}=H(),n=te(),[o,r]=XR({name:"list"}),{busy:i,error:s,reset:a,fail:c,run:l}=le();Ce(i!==null);let u=ee([e.revision],Fa),m=i!==null,f=o.name==="list"&&!m;G(h=>{h==="r"?e.reload():h==="n"&&r({name:"create"})},f);let d=()=>{o.name==="list"?e.pop():(a(),r({name:"list"}))};return Un(K,{trail:["\u53D1\u7968\u7BA1\u7406","\u5E38\u7528\u4FE1\u606F"],hints:f?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","r \u5237\u65B0"]:[],onEscape:d,isActive:i===null,children:Un(W,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u5E38\u7528\u5F00\u7968\u4FE1\u606F",width:t,children:h=>{let y=o.name==="list"?n:Math.max(ZR,n-QR);return fb(xm,{flexDirection:"column",children:[Un(xm,{marginBottom:o.name==="list"?0:1,children:Un(ue,{retain:"list",items:h,width:t,height:y,isActive:f,columns:[{label:"\u7C7B\u578B"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7A0E\u53F7"}],row:g=>[uo(g.type),g.title,g.taxId??"\u2014"],onOpen:g=>r({name:"actions",profile:g}),emptyLabel:"\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F",emptyDescription:"\u6309 n \u4FDD\u5B58\u4E00\u6761\u5E38\u7528\u5F00\u7968\u4FE1\u606F"})}),o.name==="actions"&&!m&&fb(de,{title:o.profile.title,width:t,children:[Un(Ye,{width:t-pe,items:[["\u7C7B\u578B",Gr(o.profile.type)],["\u7A0E\u53F7",o.profile.taxId??"\u2014"]]}),Un(xm,{marginTop:1,children:Un(ce,{width:t-pe,items:[{value:"edit",label:"\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:g=>{a(),r(g==="edit"?{name:"edit",profile:o.profile}:{name:"confirm-delete",profile:o.profile})}})})]}),(o.name==="create"||o.name==="edit")&&Un(ne,{title:o.name==="create"?"\u65B0\u589E\u5E38\u7528\u4FE1\u606F":`\u7F16\u8F91\u5E38\u7528\u4FE1\u606F \u2014 ${o.profile.title}`,width:t,submitLabel:"\u4FDD\u5B58",busy:m,busyLabel:i??"\u6B63\u5728\u4FDD\u5B58",error:s,fields:pb(o.name==="edit"?o.profile:null),onCancel:d,onSubmit:g=>{let x=db(g,c);if(x===null)return;let T=o.name==="edit"?()=>ib(o.profile.id,x):()=>rb(x);l("\u6B63\u5728\u4FDD\u5B58",T,{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u4FDD\u5B58")}})}}),o.name==="confirm-delete"&&Un(Ae,{width:t,title:"\u5220\u9664\u5E38\u7528\u5F00\u7968\u4FE1\u606F",detail:`\u786E\u8BA4\u5220\u9664\u300C${o.profile.title}\u300D\uFF1F`,confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>l("\u6B63\u5728\u5220\u9664",()=>sb(o.profile.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:d})]})}})})}import{Box as Ri,Text as wr}from"ink";import{useState as Tm}from"react";import{jsx as nt,jsxs as hb}from"react/jsx-runtime";var eC=_t(Xa,Ki,"\u5168\u90E8\u72B6\u6001");function tC({id:e,width:t}){let n=L(),o=ee([e,n.revision],()=>tb(e)),r=t-pe,[i,s]=Tm(null),[a,c]=Tm(null),l=o.phase==="ready"?o.data:null;return G(u=>{if(u!=="d"||l===null||a!==null)return;let m=l.invoiceNo;!l.hasFile||m===null||(s(null),c(m))}),nt(W,{state:o,loading:"\u6B63\u5728\u8BFB\u53D6\u53D1\u7968\u8BE6\u60C5",width:t,children:u=>{if(a!==null)return nt(mr,{title:"\u4FDD\u5B58\u53D1\u7968\u6587\u4EF6",width:t,download:async()=>({fileName:`\u53D1\u7968-${a}.pdf`,bytes:await ob(u.id)}),onCancel:()=>c(null),onSaved:h=>{c(null),s(h),n.toast("ok","\u53D1\u7968\u5DF2\u4FDD\u5B58")}});let m=Ki(u.status),f=ht(m),d=[["\u62AC\u5934",u.title],...u.taxId===null?[]:[["\u7A0E\u53F7",u.taxId]],...u.invoiceNo===null?[]:[["\u53D1\u7968\u53F7\u7801",u.invoiceNo]],...u.remark===null?[]:[["\u5907\u6CE8",u.remark]],["\u7533\u8BF7\u65F6\u95F4",V(u.createdAt)],...u.rejectReason===null?[]:[["\u9A73\u56DE\u539F\u56E0",u.rejectReason]],...u.rejectedAt===null?[]:[["\u9A73\u56DE\u65F6\u95F4",V(u.rejectedAt)]],...u.issuedAt===null?[]:[["\u5F00\u7968\u65F6\u95F4",V(u.issuedAt)]]];return hb(de,{title:u.title,note:V(u.createdAt),width:t,children:[hb(wr,{wrap:"truncate",children:[nt(wr,{color:p.mutedForeground,children:uo(u.type)}),nt(wr,{color:f===void 0?p.mutedForeground:tt[f],children:` ${m.label}`})]}),nt(Ri,{marginTop:1,children:nt(it,{width:r,maxPerRow:2,tiles:[{label:"\u91D1\u989D",value:Re(u.amountCny)},{label:"\u5173\u8054\u8BA2\u5355",value:`${u.orders.length} \u7B14`}]})}),nt(Ri,{marginTop:1,children:nt(Ye,{width:r,items:d})}),nt(Ri,{marginTop:1,flexDirection:"column",children:u.orders.map(h=>nt(wr,{wrap:"truncate",color:p.faintForeground,children:_e([h.orderNo,Re(h.amountCny)])},h.orderNo))}),u.hasFile&&i===null&&nt(Ri,{marginTop:1,children:nt(wr,{wrap:"truncate",color:p.faintForeground,children:"\u6309 d \u4E0B\u8F7D\u53D1\u7968\u6587\u4EF6"})}),i!==null&&nt(Ri,{marginTop:1,children:nt(wr,{wrap:"truncate",color:p.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${i}`})})]})}})}function yb(){let e=L(),{width:t}=H(),n=te(),[o,r]=Tm({name:"list"}),[i,s]=Ie("status",()=>""),a=ee([e.revision],eb);G(l=>{o.name==="list"&&(l==="r"?e.reload():l==="f"?r({name:"filter"}):l==="n"?e.push("invoice-apply"):l==="p"&&e.push("invoice-profiles"))});let c=()=>{o.name==="list"?e.pop():r({name:"list"})};return nt(K,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","n \u7533\u8BF7\u5F00\u7968","p \u5E38\u7528\u4FE1\u606F","f \u7B5B\u9009","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:nt(W,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u5F00\u7968\u8BB0\u5F55",width:t,children:l=>{if(o.name==="filter")return nt(ne,{title:"\u7B5B\u9009\u53D1\u7968",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:eC,initial:i}],onCancel:c,onSubmit:m=>{s(m.status??""),r({name:"list"})}});if(o.name==="detail")return nt(tC,{id:o.id,width:t});let u=i===""?l:l.filter(m=>m.status===i);return nt(ue,{retain:"list",items:u,width:t,height:n,columns:[{label:"\u65F6\u95F4"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u91D1\u989D",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[V(m.createdAt),m.title,uo(m.type),Re(m.amountCny),yt(Ki(m.status))],searchOf:m=>m.title,onOpen:m=>r({name:"detail",id:m.id}),emptyLabel:i===""?"\u6682\u65E0\u5F00\u7968\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u6309 n \u4E3A\u5DF2\u4ED8\u6B3E\u8BA2\u5355\u7533\u8BF7\u5F00\u7968":void 0})}})})}import{Box as nC}from"ink";import{useState as bb}from"react";import{jsx as kr,jsxs as rC}from"react/jsx-runtime";var oC=_t(Za,jc,"\u5168\u90E8\u7C7B\u578B");function Sb(){let e=L(),{width:t}=H(),n=te(),[o,r]=bb("list"),[i,s]=bb(""),a=ee([e.revision],()=>ze(e.ctx.site)),c=Ve([e.revision,i],m=>Th({page:m,...i===""?{}:{type:i}}),{retain:"page"}),l=o==="list";G((m,f)=>{l&&(m==="r"?e.reload():m==="f"?r("filter"):f.leftArrow?c.go(-1):f.rightArrow&&c.go(1))});let u=()=>{o==="list"?e.pop():r("list")};return kr(K,{hints:l?["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:u,children:kr(W,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:m=>o==="filter"?kr(ne,{title:"\u7B5B\u9009\u6D41\u6C34",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:oC,initial:i}],onCancel:u,onSubmit:f=>{s(f.type??""),c.reset(),r("list")}}):kr(W,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6D41\u6C34",width:t,children:f=>rC(nC,{flexDirection:"column",children:[kr(ue,{retain:"list",items:f.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u65F6\u95F4"},{label:"\u7C7B\u578B"},{label:"\u53D8\u52A8",align:"right"},{label:"\u4F59\u989D",align:"right"},{label:"\u6765\u6E90",align:"right"}],row:d=>{let h=Jo(d.amount,m.quotaPerUsd);return[V(d.createdAt),jc(d.type),{text:d.amount>=0?`+${h}`:h,tone:d.amount>=0?"success":"danger"},Te(d.balanceAfter,m.quotaPerUsd),_e([hd(d.refType),d.refId??""])]},emptyLabel:i===""?"\u6682\u65E0\u989D\u5EA6\u6D41\u6C34":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u5145\u503C\u6216\u6D88\u8017\u540E\uFF0C\u6BCF\u7B14\u53D8\u52A8\u4F1A\u8BB0\u5F55\u5728\u8FD9\u91CC":void 0}),kr(Ke,{page:c.page,pages:c.pages,total:c.total,width:t})]})})})})}import{Box as Rb}from"ink";import{useState as sC}from"react";import{z as iC}from"zod";var Ci={recharge:"/recharge",subscription:"/subscriptions"};async function ja(e,t){let n=`${Ci[e]}/orders/${t}`;return e==="recharge"?{kind:e,...await P(Mr,n)}:{kind:e,...await P(Ir,n)}}async function xb(e,t){let n=`${Ci[e]}/orders/${t}/pay`;if(e==="recharge"){let{order:i,qrCode:s}=await P(Ni,n,{method:"POST"});return{order:{kind:e,...i},qrCode:s}}let{order:o,qrCode:r}=await P(Nr,n,{method:"POST"});return{order:{kind:e,...o},qrCode:r}}var Tb=(e,t)=>P(iC.array(fu),`${Ci[e]}/orders/${t}/refunds`),wb=(e,t,n)=>P(se,`${Ci[e]}/orders/${t}/refund-request`,{method:"POST",json:{reason:n}}),kb=(e,t)=>P(se,`${Ci[e]}/orders/${t}/refund-request/cancel`,{method:"POST"});import{Box as Ha,Text as Tn}from"ink";import{jsx as on,jsxs as _i}from"react/jsx-runtime";function vb({order:e,refunds:t,quotaPerUsd:n,width:o}){let r=o-pe,i=Wn(e.status),s=ht(i),a=[["\u521B\u5EFA\u65F6\u95F4",V(e.createdAt)]];return e.succeededRefundCny>0&&a.push(["\u5DF2\u9000\u91D1\u989D",Re(e.succeededRefundCny)]),e.kind==="recharge"&&e.refundedQuota>0&&a.push(["\u6263\u56DE\u989D\u5EA6",Te(e.refundedQuota,n)]),e.pendingRefundCny>0&&a.push(["\u5F85\u786E\u8BA4\u9000\u6B3E",Re(e.pendingRefundCny)]),_i(de,{title:e.kind==="recharge"?"\u5145\u503C":e.planName,note:e.orderNo,width:o,children:[_i(Tn,{wrap:"truncate",children:[on(Tn,{color:s===void 0?p.mutedForeground:tt[s],children:i.label}),e.kind==="subscription"&&on(Tn,{color:p.faintForeground,children:` ${e.renewal?"\u7EED\u8D39":"\u65B0\u8D2D"}`})]}),on(Ha,{marginTop:1,children:on(it,{width:r,maxPerRow:2,tiles:e.kind==="recharge"?[{label:"\u91D1\u989D",value:Re(e.amountCny)},{label:"\u5230\u8D26\u989D\u5EA6",value:Te(e.quota,n)}]:[{label:"\u91D1\u989D",value:Re(e.amountCny)},{label:"\u8BA2\u9605\u65F6\u957F",value:`${e.grantedDurationDays} \u5929`}]})}),on(Ha,{marginTop:1,children:on(Ye,{width:r,items:a})}),t!==null&&_i(Ha,{marginTop:1,flexDirection:"column",children:[on(Tn,{color:p.mutedForeground,children:"\u9000\u6B3E\u8BB0\u5F55"}),t.length===0?on(Tn,{color:p.faintForeground,children:"\u6682\u65E0\u9000\u6B3E\u8BB0\u5F55"}):t.map(c=>{let l=yd(c.status),u=ht(l);return _i(Ha,{flexDirection:"column",children:[_i(Tn,{wrap:"truncate",children:[on(Tn,{color:p.foreground,children:Re(c.amountCny)}),on(Tn,{color:u===void 0?p.mutedForeground:tt[u],children:` ${l.label}`}),on(Tn,{color:p.faintForeground,children:` ${V(c.createdAt)}`})]}),(c.reason!==null||c.rejectReason!==null||c.refundTradeNo!==null)&&on(Tn,{wrap:"truncate",color:p.faintForeground,children:` ${_e([c.reason??"",c.rejectReason===null?"":`\u9A73\u56DE\uFF1A${c.rejectReason}`,c.refundTradeNo??""])}`})]},c.id)})]})]})}import{jsx as Oo,jsxs as cC}from"react/jsx-runtime";var aC=new Set(["pending","expired","failed"]);function qa(e){let t=Wn(e.status);return e.pendingRefundCny>0?{badge:`${t.label}\uFF08\u5F85\u786E\u8BA4 ${Re(e.pendingRefundCny)}\uFF09`,badgeTone:"warning"}:{badge:t.label,badgeTone:ht(t)}}function vr(e,t,n){return e.kind==="recharge"?{kind:"recharge",orderNo:e.orderNo,qrCode:t,amountCny:e.amountCny,summary:[`\u5230\u8D26\u989D\u5EA6 ${Te(e.quota,n)}`],paidMessage:"\u5145\u503C\u6210\u529F\uFF01",paidNote:"\u4F59\u989D\u5DF2\u5230\u8D26",expiredNote:"\u82E5\u5DF2\u5B8C\u6210\u4ED8\u6B3E\uFF0C\u4F59\u989D\u4F1A\u81EA\u52A8\u5230\u8D26\uFF0C\u8BF7\u52FF\u91CD\u590D\u5145\u503C\uFF1B\u53EF\u5728\u300C\u5145\u503C\u8BB0\u5F55\u300D\u4E2D\u67E5\u770B"}:{kind:"subscription",orderNo:e.orderNo,qrCode:t,amountCny:e.amountCny,summary:[`${e.planName} \xB7 ${e.grantedDurationDays} \u5929`],paidMessage:"\u8BA2\u9605\u5DF2\u751F\u6548\uFF01",paidNote:"\u8BA2\u9605\u5DF2\u751F\u6548",expiredNote:"\u82E5\u5DF2\u5B8C\u6210\u4ED8\u6B3E\uFF0C\u8BA2\u9605\u4F1A\u81EA\u52A8\u751F\u6548\uFF0C\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\uFF1B\u53EF\u5728\u300C\u8BA2\u9605\u8BA2\u5355\u300D\u4E2D\u67E5\u770B"}}function Cb({params:e}){let t=L(),{width:n}=H(),[o,r]=sC("main"),{busy:i,error:s,reset:a,fail:c,run:l}=le();Ce(i!==null);let u=ee([e.kind,e.orderNo,t.revision],async()=>{let[y,g]=await Promise.all([ja(e.kind,e.orderNo),ze(t.ctx.site)]),x=aC.has(y.status)?null:await Tb(e.kind,e.orderNo);return{order:y,refunds:x,site:g}});G(y=>{o==="main"&&i===null&&y==="r"&&t.reload()});let m=()=>{o==="main"?t.pop():(a(),r("main"))},f=y=>{l("\u6B63\u5728\u62C9\u8D77\u652F\u4ED8",()=>xb(e.kind,e.orderNo),{failToast:!0,onSuccess:({order:g,qrCode:x})=>{t.push("pay",vr(g,x,y.quotaPerUsd))}})},d=y=>{l("\u6B63\u5728\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7",()=>wb(e.kind,e.orderNo,y),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7")}})},h=()=>{l("\u6B63\u5728\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",()=>kb(e.kind,e.orderNo),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u64A4\u9500\u9000\u6B3E\u7533\u8BF7")}})};return Oo(K,{trail:["\u8BA2\u5355\u8BE6\u60C5"],hints:o==="main"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:Oo(W,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u5355",width:n,children:({order:y,refunds:g,site:x})=>{if(o==="refund")return Oo(ne,{title:`\u7533\u8BF7\u9000\u6B3E \u2014 ${y.orderNo}`,width:n,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:i!==null,busyLabel:i??"\u6B63\u5728\u63D0\u4EA4",error:s,fields:[{kind:"select",name:"reason",label:"\u9000\u6B3E\u539F\u56E0",options:[...zc[e.kind].map(R=>({value:R,label:R})),{value:"other",label:"\u5176\u4ED6"}],initial:zc[e.kind][0],hint:vd[e.kind]},{kind:"textarea",name:"custom",label:"\u5177\u4F53\u8BF4\u660E",rows:3,maxLength:256,placeholder:"\u8BF4\u660E\u7533\u8BF7\u9000\u6B3E\u7684\u539F\u56E0",hint:"\u4EC5\u9000\u6B3E\u539F\u56E0\u9009\u300C\u5176\u4ED6\u300D\u65F6\u5FC5\u586B"}],onCancel:m,onSubmit:R=>{let b=R.reason??"",S=b==="other"?(R.custom??"").trim():b;if(S===""){c("\u8BF7\u586B\u5199\u5177\u4F53\u8BF4\u660E");return}d(S)}});if(o==="confirm-cancel")return Oo(Ae,{width:n,title:"\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",detail:`\u786E\u8BA4\u64A4\u9500\u8BA2\u5355 ${y.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\uFF1F${y.kind==="recharge"?"\u6536\u56DE\u7684\u989D\u5EA6":"\u51BB\u7ED3\u7684\u8BA2\u9605\u65F6\u957F"}\u5C06\u7ACB\u5373\u6062\u590D`,confirmLabel:"\u64A4\u9500\u7533\u8BF7",busy:i,error:s,onConfirm:h,onCancel:m});let T=[];return y.status==="pending"&&T.push({value:"pay",label:"\u7EE7\u7EED\u652F\u4ED8",hint:"\u91CD\u65B0\u62C9\u8D77\u652F\u4ED8\u5B9D\u4E8C\u7EF4\u7801"}),y.status==="refund_requested"&&T.push({value:"cancel-refund",label:"\u64A4\u9500\u7533\u8BF7",hint:"\u9000\u6B3E\u5C1A\u672A\u5BA1\u6838\uFF0C\u53EF\u64A4\u56DE"}),gu(y)&&T.push({value:"refund",label:"\u7533\u8BF7\u9000\u6B3E",labelTone:"danger"}),cC(Rb,{flexDirection:"column",children:[Oo(vb,{order:y,refunds:g,quotaPerUsd:x.quotaPerUsd,width:n}),T.length>0&&i===null&&Oo(Rb,{marginTop:1,children:Oo(ce,{width:n,items:T,retain:"menu",onSelect:R=>{a(),R==="pay"?f(x):r(R==="refund"?"refund":"confirm-cancel")}})})]})}})})}import{useRef as mC,useState as Ib}from"react";import{Box as _b,Text as Do}from"ink";import{Fragment as lC,jsx as Wt,jsxs as Pb}from"react/jsx-runtime";var Ab={columns:20,rows:2};function Eb(e,t,n){return qs(e,t,Ab,n)}function Mb({phase:e,qrCode:t,amountCny:n,summary:o,paidNote:r,expiredNote:i,pollError:s,width:a,layout:c}){let l=s===null?Wt(De,{label:"\u7B49\u5F85\u652F\u4ED8\u5230\u8D26\u2026"}):Wt(Do,{wrap:"truncate",color:tt.warning,children:`\u67E5\u8BE2\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1A${s}`});if(e==="paid")return Wt(he,{tone:"ok",width:a,title:"\u652F\u4ED8\u6210\u529F\uFF01",detail:r});if(e==="expired")return Wt(he,{tone:"warn",width:a,title:"\u8BA2\u5355\u5DF2\u8D85\u65F6",detail:i});if(!c.fits)return Pb(_b,{flexDirection:"column",children:[Wt(he,{tone:"warn",width:a,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u65E0\u6CD5\u7ED8\u5236\u4E8C\u7EF4\u7801",detail:`\u653E\u5927\u5230 ${c.target.columns} \xD7 ${c.target.rows} \u53EF\u663E\u793A\u4E8C\u7EF4\u7801\uFF0C\u6216\u6309 c \u590D\u5236\u4ED8\u6B3E\u94FE\u63A5`}),Wt(Do,{color:p.accent,children:t}),Wt(_b,{marginTop:1,children:Wt(Do,{bold:!0,color:p.foreground,children:Re(n)})}),l]});let u=c.asideRows-Ab.rows,m=u>=1,f=u>=2,d=u>=2+o.length;return Wt(Gs,{value:t,aside:Pb(lC,{children:[f&&Wt(Do,{bold:!0,color:p.foreground,children:"\u626B\u7801\u652F\u4ED8"}),Wt(Do,{bold:!0,color:p.foreground,children:Re(n)}),m&&Wt(Do,{color:p.mutedForeground,children:"\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u4E00\u626B\u5B8C\u6210\u652F\u4ED8"}),d&&o.map((h,y)=>Wt(Do,{wrap:"truncate",color:p.mutedForeground,children:h},y)),l]})})}import{jsx as Nb}from"react/jsx-runtime";var uC=5,dC=2e3;function Lb({params:e}){let t=L(),{width:n,columns:o,rows:r}=H(),i=ri(0),[s,a]=Ib("waiting"),[c,l]=Ib(null),u=mC(0);Qs(dC,async()=>{let d;try{d=await ja(e.kind,e.orderNo)}catch(h){l(xe(h));return}if(l(null),d.status==="paid"||d.credited){a("paid"),t.toast("ok",e.paidMessage);return}if(d.status==="expired"||d.status==="failed"){u.current+=1,u.current>=uC&&a("expired");return}u.current=0},s==="waiting"),G(d=>{d!=="c"||s!=="waiting"||Da(e.qrCode).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))});let m=Eb(e.qrCode,{width:n,rows:i},{columns:o-n,rows:r-i}),f=s==="waiting"&&m.fits;return Nb(K,{trail:["\u626B\u7801\u652F\u4ED8"],bleed:f,hints:s==="waiting"?["c \u590D\u5236\u94FE\u63A5"]:[],children:Nb(Mb,{phase:s,qrCode:e.qrCode,amountCny:e.amountCny,summary:e.summary,paidNote:e.paidNote,expiredNote:e.expiredNote,pollError:c,width:n,layout:m})})}import{useState as fC}from"react";import{z as jn}from"zod";var pC=jn.object({id:jn.number().int(),name:jn.string(),originalCny:jn.number().int(),discountPercent:jn.number().int(),payCny:jn.number().int(),quota:jn.number()}),Ob=()=>P(jn.array(pC),"/recharge-packages"),Db=e=>P(Ni,"/recharge/orders",{method:"POST",json:e}),$b=()=>P(jn.array(Mr),"/recharge/orders");import{jsx as Rr}from"react/jsx-runtime";var gC=_t(_r,Wn,"\u5168\u90E8\u72B6\u6001");function hC(e,t){let n=e.discountPercent<100?`\uFF08\u539F\u4EF7 ${Re(e.originalCny)} \xB7 ${e.discountPercent/10} \u6298\uFF09`:"";return`${Re(e.payCny)}${n} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(e.quota,t)}`}function Bb(){let e=L(),{width:t}=H(),n=te(),[o,r]=fC({name:"menu"}),[i,s]=Ie("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=le();Ce(a!==null);let f=ee([e.revision],async()=>{let[y,g,x]=await Promise.all([Ob(),va(e.ctx.site),$b()]);return{packages:y,pricing:g,orders:x}});G(y=>{o.name==="menu"&&(y==="r"?e.reload():y==="f"&&r({name:"filter"}))});let d=()=>{o.name==="menu"?e.pop():(l(),r({name:"menu"}))},h=(y,g)=>{m("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Db(y),{onSuccess:({order:x,qrCode:T})=>{r({name:"menu"}),e.push("pay",vr({kind:"recharge",...x},T,g))}})};return Rr(K,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BB0\u5F55","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:d,isActive:a===null,children:Rr(W,{state:f,loading:"\u6B63\u5728\u8BFB\u53D6\u5145\u503C\u5957\u9910",width:t,children:({packages:y,pricing:g,orders:x})=>{if(o.name==="confirm")return Rr(Ae,{width:t,title:`\u786E\u8BA4\u5145\u503C ${Re(o.pkg.payCny)}\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>h({packageId:o.pkg.id},g.quotaPerUsd),onCancel:d});if(o.name==="custom")return Rr(ne,{title:"\u81EA\u5B9A\u4E49\u91D1\u989D\u5145\u503C",width:t,submitLabel:"\u53BB\u652F\u4ED8",busy:a!==null,busyLabel:a??"\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",error:c,fields:[{kind:"text",name:"yuan",label:"\u5145\u503C\u91D1\u989D\uFF08\u5143\uFF09",placeholder:"\u8BF7\u8F93\u5165\u91D1\u989D",hint:`\u6700\u4F4E ${g.minTopupCny} \u5143 \xB7 \u5230\u8D26\u989D\u5EA6\u6309\u5145\u503C\u6C47\u7387\u6298\u7B97`}],onCancel:d,onSubmit:b=>{let S=Number((b.yuan??"").trim()),v=Oc(S);if(!Number.isFinite(S)||v<Oc(g.minTopupCny)||v>ac){u(`\u8BF7\u8F93\u5165 ${g.minTopupCny} \u5230 ${cd(ac)} \u5143\u4E4B\u95F4\u7684\u91D1\u989D`);return}h({amountCny:v},g.quotaPerUsd)}});if(o.name==="filter")return Rr(ne,{title:"\u7B5B\u9009\u5145\u503C\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:gC,initial:i}],onCancel:d,onSubmit:b=>{s(b.status??""),r({name:"menu"})}});let T=i===""?x:x.filter(b=>b.status===i),R=[{heading:"\u5145\u503C\u5957\u9910"},...y.map(b=>({value:{kind:"pkg",pkg:b},label:b.name,hint:hC(b,g.quotaPerUsd)})),{value:{kind:"custom"},label:"\u81EA\u5B9A\u4E49\u91D1\u989D",hint:"\u8F93\u5165\u4EFB\u610F\u91D1\u989D\u5145\u503C"},{heading:""},{heading:"\u5145\u503C\u8BB0\u5F55"},...T.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u5145\u503C\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u9009\u62E9\u4E0A\u65B9\u5957\u9910\u6216\u8F93\u5165\u81EA\u5B9A\u4E49\u91D1\u989D\u5373\u53EF\u5145\u503C"}:{},disabled:!0}]:T.map(b=>({value:{kind:"order",orderNo:b.orderNo},label:Re(b.amountCny),...qa(b),hint:`${V(b.createdAt)} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(b.quota,g.quotaPerUsd)}`}))];return Rr(ce,{items:R,width:t,height:n,retain:"menu",onSelect:b=>{l(),b.kind==="custom"?r({name:"custom"}):b.kind==="order"?e.push("order",{kind:"recharge",orderNo:b.orderNo}):b.kind==="pkg"&&r({name:"confirm",pkg:b.pkg})}})}})})}import{Box as Hn,Text as Pi}from"ink";import{useState as xC}from"react";import TC from"string-width";import{z as Se}from"zod";var yC=Se.object({windowId:Se.number().int(),durationMinutes:Se.number().int(),quota:Se.number(),used:Se.number(),resetAt:Se.string()}),Fb=Se.object({name:Se.string(),multiplier:Se.number()}),bC=Se.object({billingPreference:Ya,subscriptions:Se.array(Se.object({id:Se.number().int(),planName:Se.string(),groups:Se.array(Fb),startsAt:Se.string(),expiresAt:Se.string(),revokedAt:Se.string().nullable(),renewable:Se.boolean(),windows:Se.array(yC)}))}),Ub=()=>P(bC,"/subscriptions"),SC=Se.object({id:Se.number().int(),name:Se.string(),description:Se.string().nullable(),priceCny:Se.number().int(),durationDays:Se.number().int(),enabled:Se.boolean(),groups:Se.array(Fb),windows:Se.array(Se.object({durationMinutes:Se.number().int(),quota:Se.number()}))}),jb=()=>P(Se.array(SC),"/subscription-plans"),Hb=e=>P(Nr,"/subscriptions/orders",{method:"POST",json:e}),qb=e=>P(Nr,`/subscriptions/${e}/renew`,{method:"POST"}),Gb=()=>P(Se.array(Ir),"/subscriptions/orders"),Wb=e=>P(Se.object({billingPreference:Ya}),"/subscriptions/preference",{method:"PUT",json:e});import{jsx as He,jsxs as $o}from"react/jsx-runtime";var wC=_t(_r,Wn,"\u5168\u90E8\u72B6\u6001");function kC(e,t,n){if(e.name==="sub"||e.name==="confirm-renew"){let o=t.find(r=>r.id===e.id);return o===void 0?{kind:"missing-sub"}:{kind:"sub",sub:o,confirm:e.name==="confirm-renew"}}if(e.name==="plan"||e.name==="confirm-buy"){let o=n.find(r=>r.id===e.id);return o===void 0?{kind:"missing-plan"}:{kind:"plan",plan:o,confirm:e.name==="confirm-buy"}}return{kind:"none"}}var vC=3;function RC({win:e,quotaPerUsd:t,width:n}){let o=Gc(e),r=wd(e.durationMinutes),i=`\u5DF2\u7528 ${o}% ${ie.bullet} ${Te(e.used,t)} / ${Te(e.quota,t)}`;return $o(Hn,{flexDirection:"column",children:[$o(Pi,{wrap:"truncate",children:[He(Pi,{color:p.foreground,children:r}),He(Pi,{color:o>=100?p.danger:p.mutedForeground,children:Kn(i,Math.max(0,n-TC(r)))})]}),He(dg,{used:e.used,total:e.quota,width:n}),He(Pi,{wrap:"truncate",color:p.faintForeground,children:`\u5C06\u4E8E ${V(e.resetAt)} \u91CD\u7F6E`})]})}function CC(e){if(e.revokedAt!==null)return`${V(e.revokedAt)} \u4F5C\u5E9F`;let t=`${V(e.expiresAt)} \u5230\u671F`;return`\u5DF2\u7528 ${Math.max(...e.windows.map(Gc))}% \xB7 ${t}`}function _C(e){let t=e.windows.length*4;return Q+Ze+2+t+(e.renewable?Q+1:0)}function PC(e){let t=e.description!==null&&e.description!==""?1+We:0,n=Math.ceil((1+e.windows.length)/2);return Q+Ze+t+n+Q+1}function zb(){let e=L(),{width:t}=H(),n=te(),[o,r]=xC({name:"menu"}),[i,s]=Ie("status",()=>""),{busy:a,error:c,reset:l,run:u}=le();Ce(a!==null);let m=ee([e.revision],async()=>{let[g,x,T,R]=await Promise.all([Ub(),jb(),Gb(),ze(e.ctx.site)]);return{mine:g,plans:x,orders:T,site:R}});G(g=>{o.name!=="menu"||a!==null||(g==="r"?e.reload():g==="f"&&r({name:"filter"}))});let f=()=>{l(),o.name==="menu"?e.pop():o.name==="confirm-renew"?r({name:"sub",id:o.id}):o.name==="confirm-buy"?r({name:"plan",id:o.id}):r({name:"menu"})},d=g=>{u("\u6B63\u5728\u4FDD\u5B58\u504F\u597D",()=>Wb({billingPreference:g}),{onSuccess:()=>{r({name:"menu"}),e.reload(),e.toast("ok","\u504F\u597D\u5DF2\u4FDD\u5B58")}})},h=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u7EED\u8D39\u8BA2\u5355",()=>qb(g.id),{onSuccess:({order:T,qrCode:R})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},R,x.quotaPerUsd))}})},y=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Hb({planId:g.id}),{onSuccess:({order:T,qrCode:R})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},R,x.quotaPerUsd))}})};return He(K,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BA2\u5355","r \u5237\u65B0"]:o.name==="sub"||o.name==="plan"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","Esc \u8FD4\u56DE"]:["Esc \u8FD4\u56DE"],onEscape:f,isActive:a===null,children:He(W,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u9605",width:t,children:({mine:g,plans:x,orders:T,site:R})=>{if(o.name==="preference")return He(ne,{title:"\u6263\u8D39\u65B9\u5F0F",width:t,submitLabel:"\u4FDD\u5B58",busy:a!==null,busyLabel:a??"\u6B63\u5728\u4FDD\u5B58",error:c,fields:[{kind:"select",name:"billingPreference",label:"\u6263\u8D39\u65B9\u5F0F",options:gd,initial:g.billingPreference,hint:Uc}],onCancel:f,onSubmit:w=>{d(w.billingPreference??g.billingPreference)}});if(o.name==="filter")return He(ne,{title:"\u7B5B\u9009\u8BA2\u9605\u8BA2\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:wC,initial:i}],onCancel:f,onSubmit:w=>{s(w.status??""),r({name:"menu"})}});let b=kC(o,g.subscriptions,x);if(b.kind==="missing-sub")return He(he,{tone:"warn",width:t,title:"\u8BA2\u9605\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",detail:"\u6309 Esc \u8FD4\u56DE"});if(b.kind==="missing-plan")return He(he,{tone:"warn",width:t,title:"\u5957\u9910\u4E0D\u5B58\u5728\u6216\u5DF2\u4E0B\u67B6",detail:"\u6309 Esc \u8FD4\u56DE"});if(b.kind==="sub"&&b.confirm)return He(Ae,{width:t,title:`\u786E\u8BA4\u7EED\u8D39\u300C${b.sub.planName}\u300D\uFF1F`,detail:"\u5C06\u6309\u5957\u9910\u5F53\u524D\u4EF7\u683C\u4E0E\u65F6\u957F\u5728\u5230\u671F\u65F6\u95F4\u4E0A\u987A\u5EF6",confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>h(b.sub,R),onCancel:f});if(b.kind==="plan"&&b.confirm)return He(Ae,{width:t,title:`\u786E\u8BA4\u8BA2\u9605\u300C${b.plan.name}\u300D\uFF08${Re(b.plan.priceCny)} / ${b.plan.durationDays} \u5929\uFF09\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>y(b.plan,R),onCancel:f});let S=b.kind==="plan"?b.plan.description:"",v=i===""?T:T.filter(w=>w.status===i),M=[{heading:"\u6211\u7684\u8BA2\u9605"},...g.subscriptions.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u8BA2\u9605",hint:"\u8BA2\u9605\u4E0B\u65B9\u5957\u9910\u540E\uFF0C\u8986\u76D6\u8303\u56F4\u5185\u7684\u8C03\u7528\u5C06\u6309\u6263\u8D39\u65B9\u5F0F\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6",disabled:!0}]:g.subscriptions.map(w=>{let E=Wc(w);return{value:{kind:"sub",id:w.id},label:w.planName,badge:E.label,badgeTone:ht(E),hint:CC(w)}}),{heading:""},{value:{kind:"preference"},label:"\u6263\u8D39\u65B9\u5F0F",badge:Fc(g.billingPreference),badgeTone:"accent",hint:Uc(g.billingPreference)},{heading:""},{heading:"\u53EF\u9009\u5957\u9910"},...x.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u53EF\u9009\u5957\u9910",hint:"\u8BA2\u9605\u5957\u9910\u4E0A\u67B6\u540E\u5C06\u663E\u793A\u5728\u8FD9\u91CC",disabled:!0}]:x.map(w=>({value:{kind:"plan",id:w.id},label:w.name,...w.enabled?{}:{badge:"\u5DF2\u505C\u552E",badgeTone:"warning"},hint:`${Re(w.priceCny)} / ${w.durationDays} \u5929 \xB7 ${w.groups.map(es).join("\u3001")}`})),{heading:""},{heading:"\u8BA2\u9605\u8BA2\u5355"},...v.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u8BA2\u9605\u8BA2\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u8BA2\u9605\u4E0A\u65B9\u5957\u9910\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}:{},disabled:!0}]:v.map(w=>({value:{kind:"order",orderNo:w.orderNo},label:`${w.planName}${w.renewal?"\uFF08\u7EED\u8D39\uFF09":""}`,...qa(w),hint:`${V(w.createdAt)} \xB7 ${Re(w.amountCny)}`}))],N=b.kind==="sub"?_C(b.sub):b.kind==="plan"?PC(b.plan):0,O=N===0?n:n-N>=vC?n-N:0,U=t-pe,C=o.name==="menu"&&a===null;return $o(Hn,{flexDirection:"column",children:[O>0&&He(ce,{items:M,width:t,height:O,isActive:C,retain:"menu",onSelect:w=>{l(),w.kind==="preference"?r({name:"preference"}):w.kind==="order"?e.push("order",{kind:"subscription",orderNo:w.orderNo}):w.kind==="sub"?r({name:"sub",id:w.id}):w.kind==="plan"&&r({name:"plan",id:w.id})}}),b.kind==="sub"&&$o(Hn,{marginTop:O>0?Q:0,flexDirection:"column",children:[$o(de,{title:b.sub.planName,note:b.sub.revokedAt!==null?`${V(b.sub.revokedAt)} \u4F5C\u5E9F`:`${V(b.sub.expiresAt)} \u5230\u671F`,width:t,children:[He(Ye,{width:U,items:[["\u72B6\u6001",Wc(b.sub).label],["\u8986\u76D6\u5206\u7EC4",b.sub.groups.map(es).join("\u3001")],["\u751F\u6548\u65F6\u95F4",V(b.sub.startsAt)]]}),He(Hn,{marginTop:1,flexDirection:"column",children:b.sub.windows.map((w,E)=>He(Hn,{marginTop:E===0?0:1,flexDirection:"column",children:He(RC,{win:w,quotaPerUsd:R.quotaPerUsd,width:U})},w.windowId))})]}),b.sub.renewable&&a===null&&He(Hn,{marginTop:Q,children:He(ce,{width:t,items:[{value:"renew",label:"\u7EED\u8D39"}],onSelect:()=>r({name:"confirm-renew",id:b.sub.id})})})]}),b.kind==="plan"&&$o(Hn,{marginTop:O>0?Q:0,flexDirection:"column",children:[$o(de,{title:b.plan.name,note:`${Re(b.plan.priceCny)} / ${b.plan.durationDays} \u5929`,width:t,children:[S!==""&&He(Pi,{wrap:"truncate",color:p.mutedForeground,children:S}),He(Hn,{marginTop:S===""?0:We,children:He(Ye,{width:U,items:[["\u8986\u76D6\u5206\u7EC4",b.plan.groups.map(es).join("\u3001")],...kd(b.plan,R.quotaPerUsd).map((w,E)=>[E===0?"\u7528\u91CF\u7A97\u53E3":"",w])]})})]}),a===null&&He(Hn,{marginTop:Q,children:He(ce,{width:t,items:[{value:"subscribe",label:b.plan.enabled?"\u8BA2\u9605":"\u5DF2\u505C\u552E",disabled:!b.plan.enabled}],onSelect:()=>r({name:"confirm-buy",id:b.plan.id})})})]})]})}})})}import{jsx as ye}from"react/jsx-runtime";var Vb={home:{render:()=>ye(zy,{})},help:{render:()=>ye(qy,{})},login:{render:()=>ye(jg,{})},register:{render:()=>ye(Hg,{})},forgot:{render:()=>ye($g,{})},agreement:{render:e=>ye(Mg,{params:e})},tokens:{render:()=>ye(Py,{})},logs:{render:()=>ye(Lh,{})},usage:{render:()=>ye(_h,{})},ledger:{render:()=>ye(Sb,{})},subscription:{render:()=>ye(zb,{})},models:{render:()=>ye(jh,{})},docs:{render:()=>ye(Oy,{})},doc:{render:e=>ye(By,{params:e})},recharge:{render:()=>ye(Bb,{})},order:{render:e=>ye(Cb,{params:e})},pay:{render:e=>ye(Lb,{params:e})},invoices:{render:()=>ye(yb,{})},"invoice-apply":{render:()=>ye(ub,{})},"invoice-profiles":{render:()=>ye(gb,{})},invite:{render:()=>ye(Xy,{})},tickets:{render:()=>ye(Eg,{})},ticket:{render:e=>ye(Ag,{params:e})},community:{render:()=>ye(ah,{})},post:{render:e=>ye(hh,{params:e})},floor:{render:e=>ye(eh,{params:e})},compose:{render:e=>ye(Vg,{params:e})},"post-edit":{render:e=>ye(Kg,{params:e})},homepage:{render:e=>ye(oh,{params:e})},inbox:{render:()=>ye(Vy,{})},announcements:{render:()=>ye(Yp,{})},"announce-gate":{render:e=>ye(zp,{params:e}),lockNav:!0},profile:{render:()=>ye(bg,{})},"my-posts":{render:e=>ye(mh,{params:e})},"my-comments":{render:e=>ye(uh,{params:e})},bookmarks:{render:()=>ye(dh,{})},drafts:{render:()=>ye(ph,{})}};function Kb(e){return Vb[e].lockNav===!0}function Yb(e){let t=Vb[e.id].render;return t(e.params)}import{jsx as oo,jsxs as jC}from"react/jsx-runtime";function NC(){let e=L(),{rows:t}=H(),n=ds(),o=Kb(e.current.id)||n,r=e.depth===1&&gs(e.current.id)&&Lt().session===null;return wm(()=>{r&&e.home()}),MC((i,s)=>{s.ctrl&&i==="c"&&e.exit()}),G(i=>{if(i==="?"){e.current.id==="help"?e.pop():o||e.push("help");return}i==="q"&&!o&&(e.depth>1?e.pop():e.exit())}),oo(AC,{flexDirection:"column",height:Math.max(1,t),paddingX:1,paddingTop:1,overflow:"hidden",children:Yb(e.current)})}function LC(){let e=L(),t=ee([e.revision],async()=>{if(e.gate.announcementsChecked||Lt().session===null)return null;let n;try{n=await jd()}catch{return null}return e.gate.announcementsChecked=!0,n});return wm(()=>{t.phase!=="ready"||t.data===null||e.gate.announcementsShown||(e.gate.announcementsShown=!0,e.push("announce-gate",{item:t.data}))}),null}function OC(){let e=L(),t=IC(!1);return wm(()=>{t.current||(t.current=!0,Fd().then(n=>{n!==null&&e.toast("ok",`\u5DF2\u66F4\u65B0\u5230 v${n}\uFF0C\u91CD\u542F\u540E\u751F\u6548`)}).catch(n=>e.toast("fail",`\u81EA\u52A8\u66F4\u65B0\u5931\u8D25\uFF1A${xe(n)}`)))}),null}function DC({ctx:e,mouse:t}){return oo(rp,{subscribe:t.subscribe,children:oo(Kd,{children:oo(lp,{ctx:e,children:jC(Hp,{children:[oo(OC,{}),oo(LC,{}),oo(NC,{})]})})})})}var $C="\x1B[2J\x1B[3J\x1B[H",BC="\x1B[H\x1B[J",FC="\x1B[3J";function UC(e){return new Proxy(e,{get(t,n){if(n!=="write"){let o=Reflect.get(t,n,t);return typeof o=="function"?o.bind(t):o}return(...o)=>{let[r,...i]=o;if(typeof r!="string")return t.write(r,...i);let s=r.split($C).join(BC).split(FC).join("");return t.write(s,...i)}}})}async function Jb(e){let t=np(process.stdin,process.stdout);try{await EC(oo(DC,{ctx:e,mouse:t}),{exitOnCtrlC:!0,alternateScreen:!0,stdin:t.stdin,stdout:UC(process.stdout)}).waitUntilExit()}finally{t.dispose()}}var WC=`${zt} v${Vt} \u2014 CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF
25
+ `,i=o===""?[]:o.split(/\r?\n/);i.at(-1)===""&&i.pop();let s=new RegExp(`^\\s*(?:export\\s+)?${t}\\s*=`),a=i.findIndex(l=>s.test(l)),c=`${t}=${n}`;a===-1?i.push(c):i[a]=c,kn(e,`${i.join(r)}${r}`,384)}var am="custom:",cm=e=>xi(e.dir,"config.yaml"),cy=e=>xi(e.dir,".env"),Bn=e=>typeof e=="string"?e:null;function ly(e,t){try{return nC(e)}catch(n){throw new U(`${t} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function rC(e,t,n,o){let r=cm(t),i=oC(Nt(r)??"",{compat:"yaml-1.1"});if(i.errors.length>0)throw new U(`${r} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:i.errors[0]});if(i.contents!==null&&!eC(i.contents))throw new U(`${r} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);let s=`${am}${n}`;try{i.setIn(["providers",n],{api:e.baseUrl,key_env:o,transport:"anthropic_messages",discover_models:!1,models:Object.fromEntries(e.models.map(l=>[l,{}]))}),tC(i.get("model",!0))?i.set("model",{provider:s,default:e.model}):(i.setIn(["model","provider"],s),i.setIn(["model","default"],e.model))}catch(l){throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`,{cause:l})}let a=i.toString({lineWidth:0}),c=ly(a,r);if(Bn(c?.providers?.[n]?.api)!==e.baseUrl||Bn(c?.model?.provider)!==s||Bn(c?.model?.default)!==e.model)throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);kn(r,a,384)}var my={id:"hermes-agent",label:"Hermes Agent",requiresModel:!0,resolveDir(){let e=process.env.HERMES_HOME?.trim();if(e)return{dir:Zv(e),custom:!0};if(process.platform==="win32"){let t=process.env.LOCALAPPDATA;return{dir:xi(t??xi(ay(),"AppData","Local"),"hermes"),custom:!1}}return{dir:xi(ay(),".hermes"),custom:!1}},relayUrl:e=>e,configPaths:e=>[cm(e),cy(e)],read(e){let t=cm(e),n=Nt(t),o=n===null?null:ly(n,t),r=Bn(o?.model?.provider),i=r!==null&&r.startsWith(am)?r.slice(am.length):null,s=i===null?void 0:o?.providers?.[i];return{baseUrl:Bn(s?.api)??Bn(s?.url)??Bn(s?.base_url),model:Bn(o?.model?.default)??Bn(o?.model?.model)}},apply(e,t){let n=Tn(e.siteName),o=Ra(n);rC(e,t,n,o),Pa(cy(t),o,e.apiKey)}};import{existsSync as iC}from"fs";import{homedir as py}from"os";import{join as xr,resolve as fy}from"path";var sC="https://opencode.ai/config.json",gy="opencode.jsonc",aC=[gy,"opencode.json","config.json"],uy=["model"],lm=e=>aC.map(t=>xr(e.dir,t)).find(t=>iC(t))??xr(e.dir,gy),dy=()=>{let e=process.env.XDG_DATA_HOME;return xr(e?fy(e):xr(py(),".local","share"),"opencode","auth.json")},hy={id:"opencode",label:"OpenCode",requiresModel:!0,resolveDir(){let e=process.env.XDG_CONFIG_HOME;return e?{dir:xr(fy(e),"opencode"),custom:!0}:{dir:xr(py(),".config","opencode"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[lm(e),dy()],read(e){let t=lm(e),n=$n(t,uy),o=n===null?null:_a(n);if(o===null)return{baseUrl:null,model:null};let[r,i]=o;return{baseUrl:$n(t,["provider",r,"options","baseURL"]),model:i}},apply(e,t){let n=lm(t),o=Tn(e.siteName),r=[[["provider",o],{npm:"@ai-sdk/anthropic",name:e.siteName,options:{baseURL:e.baseUrl},models:Object.fromEntries(e.models.map(i=>[i,{name:i}]))}],[uy,`${o}/${e.model}`]];va(n,["$schema"])||r.unshift([["$schema"],sC]),Gt(n,r),Gt(dy(),[[[o],{type:"api",key:e.apiKey}]])}};import{homedir as cC}from"os";import{join as um}from"path";var yy=["models","providers"],Aa=["agents","defaults","model"],by=["agents","defaults","models"],mm=e=>Sr("OPENCLAW_CONFIG_PATH")??um(e.dir,"openclaw.json"),Sy=e=>um(e.dir,".env"),xy=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function lC(e){let t=no(e,Aa),n=xy(t)?t.primary:t;return typeof n=="string"?n:null}var Ty={id:"openclaw",label:"OpenClaw",requiresModel:!0,resolveDir(){let e=Sr("OPENCLAW_STATE_DIR");if(e!==null)return{dir:e,custom:!0};let t=Sr("OPENCLAW_HOME");return{dir:um(t??cC(),".openclaw"),custom:t!==null}},relayUrl:e=>e,configPaths:e=>[mm(e),Sy(e)],read(e){let t=Si(mm(e)),n=t===null?null:lC(t),o=n===null?null:_a(n);if(t===null||o===null)return{baseUrl:null,model:null};let[r,i]=o,s=no(t,[...yy,r,"baseUrl"]);return{baseUrl:typeof s=="string"?s:null,model:i}},apply(e,t){let n=mm(t),o=Tn(e.siteName),r=Ra(o),i=Si(n)??{},s=`${o}/${e.model}`,a=[[[...yy,o],{baseUrl:e.baseUrl,apiKey:{source:"env",provider:"default",id:r},api:"anthropic-messages",models:e.models.map(c=>({id:c,name:c}))}],xy(no(i,Aa))?[[...Aa,"primary"],s]:[Aa,{primary:s}]];for(let c of e.models){let l=`${o}/${c}`;no(i,[...by,l])===void 0&&a.push([[...by,l],{}])}Gt(n,a),Pa(Sy(t),r,e.apiKey)}};import{homedir as mC}from"os";import{join as pm}from"path";var dm=e=>pm(e.dir,"models.json"),Ea=e=>pm(e.dir,"settings.json"),wy={id:"pi-coding-agent",label:"Pi Coding Agent",requiresModel:!0,resolveDir(){let e=Sr("PI_CODING_AGENT_DIR");return e!==null?{dir:e,custom:!0}:{dir:pm(mC(),".pi","agent"),custom:!1}},relayUrl:e=>e,configPaths:e=>[dm(e),Ea(e)],read(e){let t=$n(Ea(e),["defaultProvider"]);return{baseUrl:t===null?null:$n(dm(e),["providers",t,"baseUrl"]),model:$n(Ea(e),["defaultModel"])}},apply(e,t){let n=Tn(e.siteName);Gt(dm(t),[[["providers",n],{baseUrl:e.baseUrl,api:"anthropic-messages",apiKey:e.apiKey,models:e.models.map(o=>({id:o,name:o}))}]]),Gt(Ea(t),[[["defaultProvider"],n],[["defaultModel"],e.model]])}};var ky=[oy,sy,Ty,my,hy,wy];var uC=6e3,dC=2,vy=e=>Jt(`${e.url}/api/site-config`,{timeoutMs:uC});async function pC(e){try{await vy(e);let t=Number.POSITIVE_INFINITY;for(let n=0;n<dC;n+=1){let o=Date.now();await vy(e),t=Math.min(t,Date.now()-o)}return{line:e,latencyMs:t}}catch{return{line:e,latencyMs:null}}}async function Cy(e){let t=[];for(let n of e)t.push(await pC(n));return t}import{jsx as De,jsxs as Ia}from"react/jsx-runtime";var gC=10,hC=3,Ry=4,Ey=e=>1+Math.max(1,Math.min(e,Ry))+(e>Ry?1:0);function _y(e,t){let n=e.trim();if(n==="")return null;let o=Number(n),r=Math.round(o*t);return!Number.isFinite(o)||o<=0||r<1?"invalid":r}var Py=e=>e.map(t=>({value:String(t.id),label:`${t.name} \xD7${t.multiplier}`})),Ay=(e,t)=>{let n=e.find(o=>String(o.id)===t);return n===void 0?void 0:`${n.description}\uFF08\u8BA1\u8D39\u500D\u7387 \xD7${n.multiplier}\uFF09`};function yC({lines:e,measured:t,effective:n,width:o,isActive:r,onPick:i}){let s=a=>{if(t===null)return"\u6D4B\u91CF\u4E2D";let c=t.find(l=>l.line.url===a.url);return c===void 0||c.latencyMs===null?"\u4E0D\u53EF\u8FBE":`${c.latencyMs} ms`};return De(pe,{title:"API \u63A5\u5165\u5730\u5740",note:n===void 0?void 0:`\u5F53\u524D ${n.name}`,width:o,children:De(de,{retain:"lines",items:e,width:o-ge,height:Ey(e.length),isActive:r,columns:[{label:"\u7EBF\u8DEF"},{label:"\u5EF6\u8FDF",align:"right"},{label:"\u8BF4\u660E",shrink:!0},{label:"\u72B6\u6001"}],row:a=>[a.name,s(a),a.description,n?.url===a.url?"\u4F7F\u7528\u4E2D":""],searchOf:a=>`${a.name} ${a.url}`,onOpen:i,emptyLabel:"\u7AD9\u70B9\u672A\u914D\u7F6E\u63A5\u5165\u7EBF\u8DEF\uFF0C\u8BF7\u8054\u7CFB\u7AD9\u70B9\u7BA1\u7406\u5458\u6DFB\u52A0"})})}function My(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Ma({name:"list"}),[i,s]=Ma(!1),[a,c]=Ma(()=>fo().line),[l,u]=Ma(0),{busy:m,error:p,reset:d,fail:b,run:h}=ue();Re(m!==null||o.name==="created"||o.name==="apply-pick"||o.name==="apply-model");let g=Q([e.revision],async()=>{let[P,B,J]=await Promise.all([Sa(),ba(),Ge(e.ctx.site)]);return{tokens:P,groups:B,site:J}}),x=g.phase==="ready"?g.data.site.apiLines:[],T=Q([l,x.map(P=>P.url).join("|")],()=>Cy(x)),k=m!==null,S=o.name==="list"&&!k,y=P=>{r({name:"list"}),e.reload(),e.toast("ok",P)};G(P=>{if(P==="r"){u(B=>B+1),e.reload();return}i||(P==="n"?r({name:"create"}):P==="l"&&x.length>0&&s(!0))},S);let R=P=>{os(B=>{B.line={name:P.name,url:P.url}}),c({name:P.name,url:P.url}),s(!1),e.toast("ok",`\u5DF2\u9009\u7528\u7EBF\u8DEF ${P.name}\uFF0C\u65B0\u5EFA\u4EE4\u724C\u5E76\u5199\u5165\u914D\u7F6E\u540E\u751F\u6548`)},N=(P,B,J)=>{h("\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",()=>Mh({name:P,groupId:B,quotaLimit:J}),{onSuccess:oe=>{e.reload(),r({name:"created",token:oe,secret:oe.token})}})},E=P=>{h("\u6B63\u5728\u5220\u9664\u4EE4\u724C",()=>Ih(P.id),{onSuccess:()=>y("\u4EE4\u724C\u5DF2\u5220\u9664")})},W=(P,B)=>{h("\u6B63\u5728\u8BFB\u53D6\u5BA2\u6237\u7AEF\u914D\u7F6E",async()=>ky.map(J=>{let oe=J.resolveDir(),fe=J.read(oe);return{client:J,configured:fe.baseUrl!==null,paths:J.configPaths(oe),model:fe.model}}),{failToast:!0,onSuccess:J=>r({name:"apply-pick",token:P,secret:B,targets:J})})},M=(P,B,J)=>{h("\u6B63\u5728\u5199\u5165",J,{failToast:!0,onSuccess:()=>{r({name:"list"}),e.toast("ok",_e([`\u5DF2\u5199\u5165 ${P}`,B]))}})},C=(P,B)=>{let J=P.targets.find(fe=>fe.client.id===B);if(J===void 0)return;let{client:oe}=J;if(!oe.requiresModel){M(oe.label,void 0,()=>Kh(e.ctx,oe,P.secret));return}h("\u6B63\u5728\u8BFB\u53D6\u53EF\u8DEF\u7531\u7684\u6A21\u578B",async()=>{let fe=await Wh(e.ctx,P.secret);if(fe.length===0)throw new U("\u8BE5\u4EE4\u724C\u6240\u5728\u5206\u7EC4\u6CA1\u6709\u53EF\u8DEF\u7531\u7684\u6A21\u578B\uFF0C\u6362\u4E00\u4E2A\u5206\u7EC4\u540E\u91CD\u65B0\u521B\u5EFA");return fe},{failToast:!0,onSuccess:fe=>r({name:"apply-model",token:P.token,secret:P.secret,targets:P.targets,needs:{...J,client:oe},models:fe})})},v=(P,B)=>{d(),r(P==="rename"?{name:"rename",token:B}:P==="regroup"?{name:"regroup",token:B}:P==="relimit"?{name:"relimit",token:B}:{name:"confirm-delete",token:B})},_=()=>{if(o.name==="list"){i?s(!1):e.pop();return}if(d(),o.name==="apply-pick"){r({name:"created",token:o.token,secret:o.secret});return}if(o.name==="apply-model"){r({name:"apply-pick",token:o.token,secret:o.secret,targets:o.targets});return}r({name:"list"})},L=()=>o.name!=="list"?["Esc \u8FD4\u56DE"]:i?["\u2191\u2193 \u79FB\u52A8","Enter \u9009\u7528","/ \u8FC7\u6EE4","r \u5237\u65B0","Esc \u8FD4\u56DE"]:["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","l \u63A5\u5165\u5730\u5740","/ \u8FC7\u6EE4","r \u5237\u65B0"];return o.name==="created"||o.name==="apply-pick"||o.name==="apply-model"?De(Y,{hints:L(),onEscape:_,isActive:m===null,children:Ia(Io,{flexDirection:"column",children:[m!==null&&De(Oe,{label:m}),o.name==="created"&&!k&&Ia(Io,{flexDirection:"column",children:[De(ye,{tone:"ok",width:t,title:"\u4EE4\u724C\u5DF2\u521B\u5EFA",detail:"\u8BF7\u7ACB\u5373\u590D\u5236\u5E76\u59A5\u5584\u4FDD\u5B58\u3002\u51FA\u4E8E\u5B89\u5168\u8003\u8651\uFF0C\u5B8C\u6574\u4EE4\u724C\u53EA\u663E\u793A\u8FD9\u4E00\u6B21\uFF0C\u5173\u95ED\u540E\u5C06\u65E0\u6CD5\u518D\u6B21\u67E5\u770B\u3002"}),De(Io,{marginTop:1,children:De(fC,{color:f.accent,children:o.secret})}),De(Io,{marginTop:1,children:De(le,{width:t,items:[{value:"apply",label:"\u5199\u5165\u914D\u7F6E"},{value:"back",label:"\u6211\u5DF2\u4FDD\u5B58"}],onSelect:P=>{P==="back"?r({name:"list"}):W(o.token,o.secret)}})})]}),o.name==="apply-pick"&&!k&&De(pe,{title:"\u5199\u5165\u914D\u7F6E",note:o.token.name,width:t,children:De(le,{width:t-ge,height:n-Xe,retain:"apply",items:o.targets.map(P=>({value:P.client.id,label:P.client.label,badge:P.configured?"\u5DF2\u914D\u7F6E":"\u672A\u914D\u7F6E",badgeTone:P.configured?"accent":void 0,hint:P.paths.join(" ")})),onSelect:P=>C(o,P)})}),o.name==="apply-model"&&!k&&De(te,{title:`${o.needs.client.label} \u9ED8\u8BA4\u6A21\u578B`,width:t,submitLabel:"\u5199\u5165",error:p,fields:[{kind:"select",name:"model",label:"\u6A21\u578B",options:o.models.map(P=>({value:P,label:P})),initial:o.needs.model!==null&&o.models.includes(o.needs.model)?o.needs.model:o.models[0],hint:`\u5199\u5165\u540E\u4F5C\u4E3A ${o.needs.client.label} \u7684\u9ED8\u8BA4\u6A21\u578B`}],onCancel:_,onSubmit:P=>{let B=P.model;if(B===void 0||B===""){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B");return}M(o.needs.client.label,B,()=>Yh(e.ctx,o.needs.client,o.secret,B,o.models))}})]})}):De(Y,{hints:L(),onEscape:_,isActive:m===null,children:De(V,{state:g,loading:"\u6B63\u5728\u8BFB\u53D6\u4EE4\u724C",width:t,children:({tokens:P,groups:B,site:J})=>{let oe=X+Xe+Ey(J.apiLines.length),fe=Math.max(hC,n-(o.name==="list"?oe:gC));return Ia(Io,{flexDirection:"column",children:[De(Io,{flexDirection:"column",marginBottom:X,children:De(de,{retain:"list",items:P,width:t,height:fe,isActive:S&&!i,columns:[{label:"\u540D\u79F0",shrink:!0},{label:"\u5206\u7EC4"},{label:"\u5DF2\u6D88\u8D39",align:"right"},{label:"\u8D39\u7528\u9650\u5236",align:"right"},{label:"\u5BC6\u94A5"}],row:$=>{let ne=Te($.usedQuota,J.quotaPerUsd);return[$.name,$.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664",$.quotaLimit!==null&&$.usedQuota>=$.quotaLimit?{text:ne,tone:"danger"}:ne,$.quotaLimit===null?"\u4E0D\u9650":Te($.quotaLimit,J.quotaPerUsd),Li($.keyPrefix,$.keySuffix)]},searchOf:$=>`${$.name} ${$.groupName??""}`,onOpen:$=>r({name:"actions",token:$}),emptyLabel:"\u6682\u65E0\u4EE4\u724C",emptyDescription:"\u521B\u5EFA\u4E00\u4E2A\u4EE4\u724C\u5373\u53EF\u5F00\u59CB\u8C03\u7528\u4E2D\u8F6C API"})}),m!==null&&(o.name==="list"||o.name==="actions"||o.name==="confirm-delete")&&De(Oe,{label:m}),o.name==="list"&&De(yC,{lines:J.apiLines,measured:T.phase==="ready"?T.data:null,effective:a??J.apiLines[0],width:t,isActive:S&&i,onPick:R}),o.name==="actions"&&!k&&Ia(pe,{title:o.token.name,width:t,children:[De(Ve,{width:t-ge,items:[["\u5206\u7EC4",o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"],["\u5DF2\u6D88\u8D39",Te(o.token.usedQuota,J.quotaPerUsd)],["\u8D39\u7528\u9650\u5236",o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,J.quotaPerUsd)],["\u5BC6\u94A5",Li(o.token.keyPrefix,o.token.keySuffix)]]}),De(Io,{marginTop:1,children:De(le,{width:t-ge,items:[{value:"rename",label:"\u540D\u79F0",hint:o.token.name},{value:"regroup",label:"\u5206\u7EC4",hint:o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"},{value:"relimit",label:"\u8D39\u7528\u9650\u5236",hint:o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,J.quotaPerUsd)},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:$=>v($,o.token)})})]}),o.name==="create"&&De(te,{title:"\u521B\u5EFA\u4EE4\u724C",width:t,submitLabel:"\u521B\u5EFA",error:p,busy:k,busyLabel:"\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"},{kind:"select",name:"group",label:"\u5206\u7EC4",options:Py(B),initial:String(B[0]?.id??""),hint:$=>Ay(B,$)},{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:"\u7D2F\u8BA1\u6D88\u8D39\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD",optional:!0}],onCancel:_,onSubmit:$=>{let ne=($.name??"").trim();if(ne===""){b("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}let w=B.find(re=>String(re.id)===$.group);if(w===void 0){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}let F=_y($.limit??"",J.quotaPerUsd);if(F==="invalid"){b("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}N(ne,w.id,F)}}),o.name==="rename"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:o.token.name,placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"}],onCancel:_,onSubmit:$=>{let ne=($.name??"").trim();if(ne===""){b("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}h("\u6B63\u5728\u4FDD\u5B58",()=>xa(o.token.id,{name:ne}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="regroup"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"select",name:"group",label:"\u5206\u7EC4",options:Py(B),initial:String(o.token.groupId??B[0]?.id??""),hint:o.token.groupId===null?"\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u5206\u7EC4":$=>Ay(B,$)}],onCancel:_,onSubmit:$=>{let ne=B.find(w=>String(w.id)===$.group);if(ne===void 0){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}h("\u6B63\u5728\u4FDD\u5B58",()=>xa(o.token.id,{groupId:ne.id}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="relimit"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",initial:o.token.quotaLimit===null?"":String(Math.round(o.token.quotaLimit/J.quotaPerUsd*100)/100),placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:`\u8BE5\u4EE4\u724C\u5DF2\u7D2F\u8BA1\u6D88\u8D39 ${Te(o.token.usedQuota,J.quotaPerUsd)}\uFF0C\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,optional:!0}],onCancel:_,onSubmit:$=>{let ne=_y($.limit??"",J.quotaPerUsd);if(ne==="invalid"){b("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}h("\u6B63\u5728\u4FDD\u5B58",()=>xa(o.token.id,{quotaLimit:ne}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="confirm-delete"&&!k&&De(Ae,{width:t,title:"\u5220\u9664\u4EE4\u724C",detail:`\u5220\u9664\u300C${o.token.name}\u300D\u540E\u8BE5\u4EE4\u724C\u7ACB\u5373\u5931\u6548\uFF0C\u4F7F\u7528\u5B83\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,confirmLabel:"\u5220\u9664",error:p,onConfirm:()=>E(o.token),onCancel:_})]})}})})}import{Box as Ly,Text as SC}from"ink";import{useEffect as xC,useState as $y}from"react";import TC from"string-width";import{z as bC}from"zod";var Na=()=>A(ku,"/docs/manifest"),Iy=e=>A(vu,`/docs/pages/${e}`),Ny=e=>A(bC.array(Cu),Fe("/docs/search",{q:e}));import{jsx as Fn,jsxs as Dy}from"react/jsx-runtime";var wC=250,Oy="/ ";function kC(e,t){let[n,o]=$y(e);return xC(()=>{let r=setTimeout(()=>o(e),t);return()=>clearTimeout(r)},[e,t]),n}var vC=e=>e.groups.flatMap((t,n)=>[...n===0?[]:[{heading:""}],{heading:t.title},...t.items.map(o=>({value:o,label:o.title}))]);function By(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Me("query",()=>""),[i,s]=$y(!1),a=kC(o.trim(),wC),c=a.length>fc,l=Q([e.revision],Na),u=qt(Q([a,e.revision],()=>a===""||c?Promise.resolve(null):Ny(a))),m=l.phase==="ready",p=o.trim()!=="",d=i||p;G(T=>{if(T==="r"){e.reload();return}m&&T.startsWith("/")&&(s(!0),T.length>1&&r(T.slice(1)))},!i);let b=()=>{if(!d){e.pop();return}s(!1),r("")},h=i?["Enter \u786E\u8BA4","Esc \u53D6\u6D88"]:m?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","/ \u641C\u7D22","r \u5237\u65B0",...p?["Esc \u8FD4\u56DE"]:[]]:["r \u5237\u65B0"],g=(T,k)=>e.push("doc",{slug:T,anchor:k}),x=Math.max(3,n-(d?1:0));return Fn(Y,{hints:h,onEscape:b,children:Fn(V,{state:l,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u76EE\u5F55",width:t,children:T=>Dy(Ly,{flexDirection:"column",children:[d&&Dy(Ly,{children:[Fn(SC,{color:f.accent,children:Oy}),Fn(er,{value:o,onChange:r,onSubmit:()=>s(!1),isActive:i,placeholder:"\u641C\u7D22\u6587\u6863",width:t-TC(Oy)})]}),p?c?Fn(Ft,{message:`\u5173\u952E\u8BCD\u6700\u591A ${fc} \u4E2A\u5B57\u7B26`,width:t}):Fn(V,{state:u,loading:"\u6B63\u5728\u641C\u7D22",width:t,children:k=>k===null?Fn(Oe,{label:"\u6B63\u5728\u641C\u7D22"}):Fn(de,{retain:"results",items:k,width:t,height:x,isActive:!i,columns:[{label:"\u6807\u9898"},{label:"\u6458\u8981",shrink:!0}],row:S=>[S.title,S.snippet],onOpen:S=>g(S.slug,S.anchor),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})}):Fn(le,{retain:"toc",items:vC(T),width:t,height:x,isActive:!i,onSelect:k=>g(k.slug,null)})]})})})}import{Box as EC,Text as MC}from"ink";import{useMemo as IC,useState as NC}from"react";import{spawn as CC}from"child_process";var RC={darwin:[{command:"pbcopy",args:[]}],win32:[{command:"clip",args:[]}],linux:[{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}]};function _C(e,t){return new Promise((n,o)=>{let r=CC(e.command,e.args,{stdio:["pipe","ignore","ignore"]});r.on("error",i=>{i.code==="ENOENT"?n(!1):o(new U(`\u6267\u884C ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))}),r.on("close",i=>{i===0?n(!0):o(new U(`${e.command} \u9000\u51FA\u7801 ${i??"null"}`))}),r.stdin.on("error",i=>o(new U(`\u5199\u5165 ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))),r.stdin.end(t)})}async function La(e){let t=RC[process.platform];if(t===void 0)throw new U(`\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u5199\u5165\u526A\u8D34\u677F\uFF08${process.platform}\uFF09`);for(let n of t)if(await _C(n,e))return;throw new U("\u672A\u627E\u5230\u53EF\u7528\u7684\u526A\u8D34\u677F\u547D\u4EE4")}import{Lexer as PC,walkTokens as AC}from"marked";function Fy(e,t){let n=[],o=[],r=new Set,i="";for(let s of PC.lex(e,{gfm:!0,breaks:!1}))s.type==="heading"&&(i=il(s.tokens,"docs")),AC([s],a=>{if(a.type==="code"){o.push({lang:a.lang??"",text:a.text,section:i});return}if(a.type!=="link"||r.has(a.href))return;r.add(a.href);let c=il(a.tokens,"docs"),l=a.href.startsWith("#")?{slug:t,anchor:gc(a.href.slice(1))}:Ni(a.href);n.push(l===null?{kind:"external",text:c,href:a.href}:{kind:"guide",text:c,...l})});return{links:n,codes:o}}var Uy=e=>Vn(e).split(`
26
+ `).map(t=>t.trim()).filter(t=>t!=="").join(" ");import{jsx as No,jsxs as $C}from"react/jsx-runtime";var LC=1,OC=16;function jy({params:e}){let{depth:t}=O();return No(DC,{params:e},t)}function DC({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=NC("body"),s=qt(Q([e.slug,t.revision],async()=>{let[h,g]=await Promise.all([Iy(e.slug),Na()]),x=new Map(g.groups.flatMap(T=>T.items.map(k=>[k.slug,k.title])));return{page:h,titles:x,outline:Fy(h.markdown,e.slug)}})),a=s.phase==="ready"?s.data:null,c=a===null?null:a.page.markdown,l=IC(()=>c===null?[]:hn(c,n,"docs"),[c,n]);G(h=>{if(r!=="body")return;if(h==="r"){t.reload();return}if(a===null)return;let{outline:g}=a;h==="l"&&g.links.length>0?i("links"):h==="c"&&g.codes.length>0&&i("codes")});let u=()=>{r==="body"?t.pop():i("body")},m=h=>{i("body"),La(h).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))},p=()=>{if(a===null)return["r \u5237\u65B0"];if(r==="links")return["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00\u6216\u590D\u5236"];if(r==="codes")return["\u2191\u2193 \u79FB\u52A8","Enter \u590D\u5236"];let{outline:h}=a;return["\u2191\u2193 \u6EDA\u52A8",...h.links.length>0?["l \u94FE\u63A5"]:[],...h.codes.length>0?["c \u590D\u5236\u4EE3\u7801"]:[],"r \u5237\u65B0"]},d=a===null?"\u6587\u6863\u8BE6\u60C5":a.page.title;return No(Y,{trail:r==="links"?["\u4F7F\u7528\u6587\u6863",d,"\u94FE\u63A5"]:r==="codes"?["\u4F7F\u7528\u6587\u6863",d,"\u4EE3\u7801"]:["\u4F7F\u7528\u6587\u6863",d],hints:p(),onEscape:u,children:No(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863",width:n,children:({titles:h,outline:g})=>{if(r==="links")return No(de,{retain:"links",items:g.links,width:n,height:o,columns:[{label:"\u94FE\u63A5",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u76EE\u6807",shrink:!0}],row:T=>T.kind==="guide"?[T.text,"\u7AD9\u5185\u6587\u6863",h.get(T.slug)??""]:[T.text,"\u5916\u90E8\u94FE\u63A5",T.href],onOpen:T=>T.kind==="guide"?t.push("doc",{slug:T.slug,anchor:T.anchor}):m(T.href)});if(r==="codes")return No(de,{retain:"codes",items:g.codes,width:n,height:o,columns:[{label:"\u4EE3\u7801",shrink:!0},{label:"\u8BED\u8A00"},{label:"\u7AE0\u8282",cap:OC}],row:T=>[Uy(T.text),T.lang,T.section],onOpen:T=>m(T.text)});let x=e.anchor===null?-1:l.findIndex(T=>T.anchor===e.anchor);return $C(EC,{flexDirection:"column",children:[No(pt,{retain:"body",lines:l,height:Math.max(1,o-LC),start:Math.max(0,x)}),No(MC,{wrap:"truncate",color:f.faintForeground,children:`\u7F51\u9875\u7248 ${t.ctx.site}/docs/${e.slug}`})]})}})})}import{Box as fm}from"ink";import{jsx as un,jsxs as BC}from"react/jsx-runtime";var Hy=[["\u2191\u2193 / k j","\u79FB\u52A8\u5149\u6807\u3001\u6EDA\u52A8\u5185\u5BB9"],["\u2190\u2192","\u5207\u6362\u5206\u6BB5\u3001\u7FFB\u9875\u3001\u6539\u53D6\u503C"],["[ ]","\u5207\u6362\u9876\u680F\u4E0A\u7684\u529F\u80FD"],["Enter","\u6253\u5F00\u3001\u786E\u8BA4\u3001\u63D0\u4EA4"],["Tab","\u8868\u5355\u4E0B\u4E00\u9879\u3001\u8FDB\u5165\u56DE\u590D\u6846"],["Esc","\u9000\u56DE\u4E0A\u4E00\u5C42"],["r","\u5237\u65B0\u5F53\u524D\u6570\u636E"],["n","\u65B0\u5EFA"],["f","\u7B5B\u9009\u5217\u8868"],["/","\u8FC7\u6EE4\u5217\u8868"],["Space / a","\u591A\u9009\u52FE\u9009\u3001\u5168\u9009"],["?","\u8FD9\u5F20\u8868"],["q","\u8FD4\u56DE\u4E0A\u5C42\uFF0C\u529F\u80FD\u5C4F\u4E0A\u9000\u51FA"],["Ctrl+C","\u9000\u51FA"]],qy=[["\u70B9\u51FB / \u6EDA\u8F6E","\u9009\u4E2D\u6253\u5F00\u3001\u6EDA\u52A8"],["Option / Alt \u62D6\u9009","\u590D\u5236\u6587\u672C"]],Gy=[["\u2190\u2192 Home End","\u79FB\u52A8\u5149\u6807"],["Ctrl+A / Ctrl+E","\u884C\u9996\u3001\u884C\u5C3E"],["Ctrl+W","\u5220\u9664\u524D\u4E00\u4E2A\u8BCD"],["Ctrl+U / Ctrl+K","\u5220\u5230\u884C\u9996\u3001\u884C\u5C3E"]];function zy({width:e,height:t}){let n=e-ge,o=[["\u7248\u672C",`${Wt} v${Vt}`],["\u672C\u5730\u5B58\u50A8",vn()]],r=[Hy,qy,Gy,o],s=(a=>r.reduce((c,l)=>c+Bt+a+zs(l.length,n),X*(r.length-1)))(qe)<=t?qe:0;return BC(Vd,{height:t,children:[un(pe,{title:"\u901A\u7528",width:e,gap:s,children:un(Ve,{items:Hy,width:n})}),un(fm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u9F20\u6807",width:e,gap:s,children:un(Ve,{items:qy,width:n})})}),un(fm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u6587\u672C\u8F93\u5165",width:e,gap:s,children:un(Ve,{items:Gy,width:n})})}),un(fm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u5173\u4E8E",width:e,gap:s,children:un(Ve,{items:o,width:n})})})]})}import{jsx as gm}from"react/jsx-runtime";function Wy(){let e=O(),{width:t}=j(),n=Z();return gn(e.pop),gm(So,{header:gm(Es,{trail:["CodeFlow","\u952E\u4F4D\u5E2E\u52A9"],width:t,onBack:e.pop,isActive:!0}),hints:["Esc \u8FD4\u56DE"],children:gm(zy,{width:t,height:n})})}import{Box as Vy,Text as FC}from"ink";import{jsx as Ti,jsxs as UC}from"react/jsx-runtime";var Ky=[{value:"login",label:"\u767B\u5F55\u8D26\u53F7",hint:"\u4F7F\u7528\u7528\u6237\u540D\u6216\u90AE\u7BB1\u7EE7\u7EED"},{value:"register",label:"\u6CE8\u518C\u8D26\u53F7",hint:"\u521B\u5EFA\u8D26\u53F7\u5F00\u59CB\u4F7F\u7528"},{value:"forgot",label:"\u627E\u56DE\u5BC6\u7801",hint:"\u901A\u8FC7\u90AE\u7BB1\u9A8C\u8BC1\u7801\u8BBE\u7F6E\u65B0\u5BC6\u7801"}];function Yy(){let e=O(),{width:t}=j(),n=oi(0),o=X+1+X+Ky.length,r=_s(t)&&n-Rs>=o;return UC(So,{header:r?Ti(Ps,{width:t}):null,hints:["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","? \u5E2E\u52A9","q \u9000\u51FA"],children:[Ti(Vy,{marginTop:1,children:Ti(FC,{color:f.mutedForeground,wrap:"truncate",children:"\u767B\u5F55\u540E\u5373\u53EF\u521B\u5EFA\u4EE4\u724C\u3001\u5199\u5165\u914D\u7F6E\u5E76\u67E5\u770B\u7528\u91CF"})}),Ti(Vy,{marginTop:1,children:Ti(le,{items:Ky,width:t,retain:"menu",onSelect:i=>e.push(i)})})]})}import{Box as hm,Text as ym}from"ink";import{useState as jC}from"react";import{jsx as nn,jsxs as bm}from"react/jsx-runtime";function Jy(){let e=O(),t=Ms(),{width:n}=j(),o=Z(),{busy:r,run:i}=ue(),[s,a]=jC({name:"list"}),c=ze([e.revision],m=>Bp({page:m}),{retain:"page"}),l=m=>{switch(m.kind){case"post":e.push("post",{id:m.postId});return;case"floor":e.push("floor",{postId:m.postId,floorId:m.floorId});return;case"ticket":e.push("ticket",{id:m.ticketId});return;case"invoices":e.select("invoices");return;case"recharge":e.select("recharge");return;case"subscription":e.select("subscription");return;case"security":e.select("profile");return}},u=m=>{a({name:"detail",message:m}),!m.read&&i("\u6B63\u5728\u6807\u8BB0\u5DF2\u8BFB",()=>Up(m.id),{failToast:!0,onSuccess:e.reload})};if(G((m,p)=>{s.name!=="list"||r!==null||(m==="r"?e.reload():p.leftArrow?c.go(-1):p.rightArrow?c.go(1):m==="a"&&t.any&&i("\u6B63\u5728\u6807\u8BB0\u5DF2\u8BFB",()=>jp(),{failToast:!0,onSuccess:()=>{e.reload(),e.toast("ok","\u5DF2\u5168\u90E8\u6807\u4E3A\u5DF2\u8BFB")}}))}),s.name==="detail"){let m=$c(s.message),p=fd[m.target.kind],d=Pt([{text:st(m.body),color:f.foreground}],n),b=Math.max(3,o-4);return bm(Y,{hints:[...d.length>b?["\u2191\u2193 \u6EDA\u52A8"]:[],`Enter ${p}`,"Esc \u8FD4\u56DE"],onEscape:()=>a({name:"list"}),children:[bm(ym,{wrap:"truncate",children:[nn(ym,{bold:!0,color:f.foreground,children:st(m.title)}),nn(ym,{color:f.faintForeground,children:` ${K(s.message.createdAt)}`})]}),nn(hm,{marginTop:1,children:nn(pt,{lines:d,height:Math.min(d.length,b)})}),nn(hm,{marginTop:1,children:r!==null?nn(Oe,{label:r}):nn(le,{width:n,items:[{value:m.target,label:p}],onSelect:l})})]})}return nn(Y,{hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...t.any?["a \u5168\u90E8\u5DF2\u8BFB"]:[],"r \u5237\u65B0"],children:nn(V,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u5185\u6D88\u606F",width:n,children:m=>bm(hm,{flexDirection:"column",children:[nn(de,{retain:"list",items:m.items,width:n,height:Math.max(3,o-1),isActive:r===null,columns:[{label:"\u6D88\u606F",shrink:!0},{label:"\u5185\u5BB9",shrink:!0},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:p=>{let d=$c(p),b=st(d.title);return[p.read?b:{text:b,tone:"accent"},st(d.body),K(p.createdAt),p.read?"":{text:"\u672A\u8BFB",tone:"accent"}]},onOpen:u,emptyLabel:"\u6682\u65E0\u6D88\u606F",emptyDescription:"\u6709\u65B0\u6D88\u606F\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),r!==null?nn(Oe,{label:r}):nn(We,{page:c.page,pages:c.pages,total:c.total,width:n})]})})})}import{Box as Oa,Text as Lo}from"ink";import{useState as Qy}from"react";import{z as St}from"zod";var HC=St.object({inviteCode:St.string(),invitedCount:St.number(),totalReward:St.number(),rewards:St.object({firstInviterPercent:St.number(),firstInviteePercent:St.number(),subsequentInviterPercent:St.number()}),items:St.array(St.object({id:St.number().int(),rewardType:zm,rewardQuota:St.number(),rewardQuotaReversed:St.number(),inviterUsername:St.string(),inviteeUsername:St.string(),createdAt:St.string()}))}),Xy=()=>A(HC,"/invite");import{jsx as Rt,jsxs as Da}from"react/jsx-runtime";var qC=_t(Qa,Yi,"\u5168\u90E8\u7C7B\u578B"),Zy=3;function GC(e){let t=[];return e.firstInviterPercent>0&&t.push(`\u597D\u53CB\u9996\u6B21\u5145\u503C\uFF0C\u4F60\u83B7\u5F97 ${e.firstInviterPercent}% \u989D\u5EA6\u5956\u52B1`),e.firstInviteePercent>0&&t.push(`\u597D\u53CB\u9996\u6B21\u5145\u503C\uFF0C\u597D\u53CB\u672C\u4EBA\u83B7\u5F97 ${e.firstInviteePercent}% \u989D\u5EA6\u5956\u52B1`),e.subsequentInviterPercent>0&&t.push(`\u597D\u53CB\u540E\u7EED\u6BCF\u6B21\u5145\u503C\uFF0C\u4F60\u83B7\u5F97 ${e.subsequentInviterPercent}% \u989D\u5EA6\u5956\u52B1`),t.length===0?["\u9080\u8BF7\u5956\u52B1\u6682\u672A\u5F00\u542F"]:(t.push("\u5956\u52B1\u6309\u597D\u53CB\u5B9E\u4ED8\u91D1\u989D\u5BF9\u5E94\u989D\u5EA6\u6298\u7B97"),t)}function eb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Qy("main"),[i,s]=Qy(""),a=Q([e.revision],async()=>{let[l,u]=await Promise.all([Xy(),Ge(e.ctx.site)]);return{invite:l,site:u}});G(l=>{o==="main"&&(l==="r"?e.reload():l==="f"&&r("filter"))});let c=()=>{o==="main"?e.pop():r("main")};return Rt(Y,{hints:o==="main"?["\u2191\u2193 \u6EDA\u52A8","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:Rt(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u9080\u8BF7\u4FE1\u606F",width:t,children:({invite:l,site:u})=>{if(o==="filter")return Rt(te,{title:"\u7B5B\u9009\u5956\u52B1\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:qC,initial:i}],onCancel:c,onSubmit:x=>{s(x.type??""),r("main")}});let m=t-ge,p=GC(l.rewards),d=i===""?l.items:l.items.filter(x=>x.rewardType===i),b=x=>Ut(2,t)+X+Bt+x+2+X+Bt+x+p.length+X+Bt+x,h=n-b(qe)>=Zy?qe:0,g=Math.max(Zy,n-b(h));return Da(Oa,{flexDirection:"column",children:[Rt(it,{width:t,tiles:[{label:"\u5DF2\u9080\u8BF7\u4EBA\u6570",value:Le(l.invitedCount)},{label:"\u7D2F\u8BA1\u5956\u52B1\u989D\u5EA6",value:Te(l.totalReward,u.quotaPerUsd)}]}),Rt(Oa,{marginTop:1,flexDirection:"column",children:Da(pe,{title:"\u6211\u7684\u9080\u8BF7",width:t,gap:h,children:[Da(Lo,{wrap:"truncate",children:[Rt(Lo,{color:f.mutedForeground,children:"\u6211\u7684\u9080\u8BF7\u7801 "}),Rt(Lo,{color:f.accent,children:l.inviteCode})]}),Da(Lo,{wrap:"truncate",children:[Rt(Lo,{color:f.mutedForeground,children:"\u9080\u8BF7\u94FE\u63A5 "}),Rt(Lo,{color:f.accent,children:`${e.ctx.site}/register?invite=${l.inviteCode}`})]})]})}),Rt(Oa,{marginTop:1,flexDirection:"column",children:Rt(pe,{title:"\u5956\u52B1\u89C4\u5219",width:t,gap:h,children:p.map((x,T)=>Rt(Lo,{wrap:"truncate",color:f.mutedForeground,children:x},T))})}),Rt(Oa,{marginTop:1,flexDirection:"column",children:Rt(pe,{title:"\u9080\u8BF7\u5956\u52B1\u8BB0\u5F55",note:i===""?void 0:Yi(i),width:t,gap:h,children:Rt(de,{retain:"list",items:d,width:m,height:g,columns:[{label:"\u65F6\u95F4"},{label:"\u597D\u53CB",shrink:!0},{label:"\u5956\u52B1\u7C7B\u578B"},{label:"\u5956\u52B1\u989D\u5EA6",align:"right"}],row:x=>{let T=x.rewardQuota-x.rewardQuotaReversed,k=x.rewardQuotaReversed>0?`\u9000\u6B3E\u51B2\u51CF -${Te(x.rewardQuotaReversed,u.quotaPerUsd)}`:"";return[K(x.createdAt),x.rewardType==="first_invitee"?x.inviterUsername:x.inviteeUsername,Yi(x.rewardType),_e([Te(T,u.quotaPerUsd),k])]},emptyLabel:i===""?"\u6682\u65E0\u5956\u52B1\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u597D\u53CB\u901A\u8FC7\u4F60\u7684\u9080\u8BF7\u7801\u6CE8\u518C\u5E76\u5B8C\u6210\u5145\u503C\u540E\uFF0C\u5956\u52B1\u4F1A\u663E\u793A\u5728\u8FD9\u91CC":void 0})})})]})}})})}import{useState as pb}from"react";import{z as Ie}from"zod";var zC=12e4,WC=Ie.object({id:Ie.number().int(),orderNo:Ie.string(),amountCny:Ie.number().int()}),tb=()=>A(Ie.array(WC),"/invoices/eligible-orders"),nb=Ie.object({id:Ie.number().int(),type:Ja,title:Ie.string(),taxId:Ie.string().nullable(),invoiceNo:Ie.string().nullable(),remark:Ie.string().nullable(),amountCny:Ie.number().int(),status:jm,rejectReason:Ie.string().nullable(),rejectedAt:Ie.string().nullable(),issuedAt:Ie.string().nullable(),createdAt:Ie.string()}),VC=nb.extend({hasFile:Ie.boolean(),orders:Ie.array(Ie.object({orderNo:Ie.string(),amountCny:Ie.number().int()}))}),ob=()=>A(Ie.array(nb),"/invoices"),rb=e=>A(VC,`/invoices/${e}`),ib=e=>A(se,"/invoices",{method:"POST",json:e}),sb=e=>rs(`/invoices/${e}/file`,{timeoutMs:zC}),KC=Ie.object({id:Ie.number().int(),type:Ja,title:Ie.string(),taxId:Ie.string().nullable()}),$a=()=>A(Ie.array(KC),"/invoices/profiles"),ab=e=>A(se,"/invoices/profiles",{method:"POST",json:e}),cb=(e,t)=>A(se,`/invoices/profiles/${e}`,{method:"PATCH",json:t}),lb=e=>A(se,`/invoices/profiles/${e}`,{method:"DELETE"});import{Box as YC,Text as Oo,useInput as JC}from"ink";import{useEffect as XC,useState as QC}from"react";import{jsx as wi,jsxs as Sm}from"react/jsx-runtime";var ZC="[x]",eR="[ ]",mb=4,Ba=2,ub=2;function db({items:e,columns:t,row:n,selected:o,onToggle:r,onToggleAll:i,onSubmit:s,width:a,height:c,emptyLabel:l}){let[u,m]=QC(0),p=Math.max(1,c-1),d=e.length>p?Math.max(1,p-1):p;XC(()=>{m(S=>Math.min(S,Math.max(0,e.length-1)))},[e.length]);let b=cl(u,d),h=S=>{e.length!==0&&m(y=>(y+S+e.length)%e.length)};JC((S,y)=>{if(y.upArrow){h(-1);return}if(y.downArrow){h(1);return}if(y.return){s();return}S===" "&&e.length>0&&r(u)}),G(S=>{if(S==="k"){h(-1);return}if(S==="j"){h(1);return}S==="a"&&i()});let g=S=>{let y=b+S-1;return y>=0&&y<e.length?y:null},x=rt({onWheel:h,onClick:({row:S})=>{let y=g(S);y!==null&&(m(y),r(y))},onHover:({row:S})=>{let y=g(S);y!==null&&m(y)}}),T=Tl(t,e.map(S=>n(S)),a-Ba-mb),k=e.slice(b,b+d);return Sm(YC,{ref:x,flexDirection:"column",children:[Sm(Oo,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(Ba+mb),t.map((S,y)=>S.align==="right"?Kn(S.label,T[y]??0):Je(S.label,T[y]??0)).join(" ".repeat(ub))]}),e.length===0?wi(Oo,{color:f.faintForeground,children:`${" ".repeat(Ba)}${l}`}):k.map((S,y)=>{let R=b+y,N=R===u,E=o.has(R),W=N?f.accent:f.foreground,M=n(S);return Sm(Oo,{wrap:"truncate",children:[wi(Oo,{color:f.accent,children:N?`${ae.cursor} `:" "}),wi(Oo,{color:E?f.accent:W,bold:N,children:`${E?ZC:eR} `}),t.map((C,v)=>{let _=C.align==="right"?Kn(M[v]??"",T[v]??0):Je(M[v]??"",T[v]??0);return wi(Oo,{color:W,bold:N,children:v>0?`${" ".repeat(ub)}${_}`:_},C.label)})]},R)}),(b>0||b+d<e.length)&&wi(Oo,{color:f.faintForeground,children:`${" ".repeat(Ba)}${b+1}-${Math.min(b+d,e.length)} / ${e.length}`})]})}import{jsx as Tr}from"react/jsx-runtime";function fb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=pb({name:"pick"}),[i,s]=pb(new Set),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[b,h]=await Promise.all([tb(),$a()]);return{orders:b,profiles:h}});G(b=>{o.name==="pick"&&b==="r"&&e.reload()});let p=()=>{o.name==="pick"?e.pop():o.name==="preset"?r({name:"pick"}):(l(),r({name:"preset"}))},d=(b,h,g)=>{let x=(g.remark??"").trim(),T=b.filter(k=>i.has(k.id)).map(k=>k.id);u("\u6B63\u5728\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7",()=>ib({orderIds:T,type:h.type,title:h.title,taxId:h.taxId,remark:x===""?null:x}),{onSuccess:()=>{e.toast("ok","\u5DF2\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7"),e.pop()}})};return Tr(Y,{trail:["\u53D1\u7968\u7BA1\u7406","\u7533\u8BF7\u5F00\u7968"],hints:o.name==="pick"?["\u2191\u2193 \u79FB\u52A8","Space \u52FE\u9009","a \u5168\u9009","Enter \u4E0B\u4E00\u6B65","r \u5237\u65B0"]:[],onEscape:p,isActive:a===null,children:Tr(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u53EF\u5F00\u7968\u8BA2\u5355",width:t,children:({orders:b,profiles:h})=>{if(o.name==="pick")return b.length===0?Tr(ye,{tone:"info",width:t,title:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355",detail:"\u5B8C\u6210\u5145\u503C\u5E76\u652F\u4ED8\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}):Tr(db,{items:b,width:t,height:n,columns:[{label:"\u8BA2\u5355\u53F7",shrink:!0},{label:"\u91D1\u989D",align:"right"}],row:g=>[g.orderNo,Ce(g.amountCny)],selected:new Set(b.flatMap((g,x)=>i.has(g.id)?[x]:[])),onToggle:g=>{let x=b[g]?.id;x!==void 0&&s(T=>{let k=new Set(T);return k.has(x)?k.delete(x):k.add(x),k})},onToggleAll:()=>s(g=>b.every(x=>g.has(x.id))?new Set:new Set(b.map(x=>x.id))),onSubmit:()=>{if(!b.some(g=>i.has(g.id))){e.toast("warn","\u8BF7\u5148\u52FE\u9009\u8981\u5F00\u7968\u7684\u8BA2\u5355");return}if(h.length===0){e.toast("warn","\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F\uFF0C\u8FD4\u56DE\u540E\u6309 p \u65B0\u589E");return}r({name:"preset"})},emptyLabel:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355"});if(o.name==="preset"){let g=[{heading:"\u5E38\u7528\u4FE1\u606F"},...h.map(x=>({value:x,label:`${uo(x.type)} \xB7 ${x.title}`,hint:x.taxId??void 0}))];return Tr(le,{items:g,width:t,height:n,onSelect:x=>r({name:"remark",profile:x})})}return Tr(te,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u5907\u6CE8",width:t,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"textarea",name:"remark",label:"\u5907\u6CE8",rows:2,maxLength:200,placeholder:"\u5C55\u793A\u5728\u53D1\u7968\u7968\u9762\u5907\u6CE8\u680F\u7684\u5185\u5BB9",optional:!0}],onCancel:p,onSubmit:g=>d(b,o.profile,g)})}})})}import{Box as xm}from"ink";import{useState as tR}from"react";function gb(e,t){let n=e.type??"general",o=(e.title??"").trim(),r=(e.taxId??"").trim();return o===""?(t("\u8BF7\u8F93\u5165\u62AC\u5934"),null):n==="special"&&r===""?(t("\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968\u9700\u586B\u5199\u7A0E\u53F7"),null):{type:n,title:o,taxId:r===""?null:r}}var hb=e=>[{kind:"select",name:"type",label:"\u7C7B\u578B",options:[{value:"general",label:qr("general")},{value:"special",label:qr("special")}],initial:e?.type??"general"},{kind:"text",name:"title",label:"\u62AC\u5934",initial:e?.title??"",placeholder:"\u4E2A\u4EBA\u6216\u5355\u4F4D\u540D\u79F0"},{kind:"text",name:"taxId",label:"\u7A0E\u53F7",initial:e?.taxId??"",placeholder:"\u7EB3\u7A0E\u4EBA\u8BC6\u522B\u53F7",optional:t=>t.type!=="special"}];import{jsx as Un,jsxs as yb}from"react/jsx-runtime";var nR=8,oR=3;function bb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=tR({name:"list"}),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.revision],$a),m=i!==null,p=o.name==="list"&&!m;G(b=>{b==="r"?e.reload():b==="n"&&r({name:"create"})},p);let d=()=>{o.name==="list"?e.pop():(a(),r({name:"list"}))};return Un(Y,{trail:["\u53D1\u7968\u7BA1\u7406","\u5E38\u7528\u4FE1\u606F"],hints:p?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","r \u5237\u65B0"]:[],onEscape:d,isActive:i===null,children:Un(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u5E38\u7528\u5F00\u7968\u4FE1\u606F",width:t,children:b=>{let h=o.name==="list"?n:Math.max(oR,n-nR);return yb(xm,{flexDirection:"column",children:[Un(xm,{marginBottom:o.name==="list"?0:1,children:Un(de,{retain:"list",items:b,width:t,height:h,isActive:p,columns:[{label:"\u7C7B\u578B"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7A0E\u53F7"}],row:g=>[uo(g.type),g.title,g.taxId??"\u2014"],onOpen:g=>r({name:"actions",profile:g}),emptyLabel:"\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F",emptyDescription:"\u6309 n \u4FDD\u5B58\u4E00\u6761\u5E38\u7528\u5F00\u7968\u4FE1\u606F"})}),o.name==="actions"&&!m&&yb(pe,{title:o.profile.title,width:t,children:[Un(Ve,{width:t-ge,items:[["\u7C7B\u578B",qr(o.profile.type)],["\u7A0E\u53F7",o.profile.taxId??"\u2014"]]}),Un(xm,{marginTop:1,children:Un(le,{width:t-ge,items:[{value:"edit",label:"\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:g=>{a(),r(g==="edit"?{name:"edit",profile:o.profile}:{name:"confirm-delete",profile:o.profile})}})})]}),(o.name==="create"||o.name==="edit")&&Un(te,{title:o.name==="create"?"\u65B0\u589E\u5E38\u7528\u4FE1\u606F":`\u7F16\u8F91\u5E38\u7528\u4FE1\u606F \u2014 ${o.profile.title}`,width:t,submitLabel:"\u4FDD\u5B58",busy:m,busyLabel:i??"\u6B63\u5728\u4FDD\u5B58",error:s,fields:hb(o.name==="edit"?o.profile:null),onCancel:d,onSubmit:g=>{let x=gb(g,c);if(x===null)return;let T=o.name==="edit"?()=>cb(o.profile.id,x):()=>ab(x);l("\u6B63\u5728\u4FDD\u5B58",T,{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u4FDD\u5B58")}})}}),o.name==="confirm-delete"&&Un(Ae,{width:t,title:"\u5220\u9664\u5E38\u7528\u5F00\u7968\u4FE1\u606F",detail:`\u786E\u8BA4\u5220\u9664\u300C${o.profile.title}\u300D\uFF1F`,confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>l("\u6B63\u5728\u5220\u9664",()=>lb(o.profile.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:d})]})}})})}import{Box as ki,Text as wr}from"ink";import{useState as Tm}from"react";import{jsx as nt,jsxs as Sb}from"react/jsx-runtime";var rR=_t(Ya,Vi,"\u5168\u90E8\u72B6\u6001");function iR({id:e,width:t}){let n=O(),o=Q([e,n.revision],()=>rb(e)),r=t-ge,[i,s]=Tm(null),[a,c]=Tm(null),l=o.phase==="ready"?o.data:null;return G(u=>{if(u!=="d"||l===null||a!==null)return;let m=l.invoiceNo;!l.hasFile||m===null||(s(null),c(m))}),nt(V,{state:o,loading:"\u6B63\u5728\u8BFB\u53D6\u53D1\u7968\u8BE6\u60C5",width:t,children:u=>{if(a!==null)return nt(ur,{title:"\u4FDD\u5B58\u53D1\u7968\u6587\u4EF6",width:t,download:async()=>({fileName:`\u53D1\u7968-${a}.pdf`,bytes:await sb(u.id)}),onCancel:()=>c(null),onSaved:b=>{c(null),s(b),n.toast("ok","\u53D1\u7968\u5DF2\u4FDD\u5B58")}});let m=Vi(u.status),p=ht(m),d=[["\u62AC\u5934",u.title],...u.taxId===null?[]:[["\u7A0E\u53F7",u.taxId]],...u.invoiceNo===null?[]:[["\u53D1\u7968\u53F7\u7801",u.invoiceNo]],...u.remark===null?[]:[["\u5907\u6CE8",u.remark]],["\u7533\u8BF7\u65F6\u95F4",K(u.createdAt)],...u.rejectReason===null?[]:[["\u9A73\u56DE\u539F\u56E0",u.rejectReason]],...u.rejectedAt===null?[]:[["\u9A73\u56DE\u65F6\u95F4",K(u.rejectedAt)]],...u.issuedAt===null?[]:[["\u5F00\u7968\u65F6\u95F4",K(u.issuedAt)]]];return Sb(pe,{title:u.title,note:K(u.createdAt),width:t,children:[Sb(wr,{wrap:"truncate",children:[nt(wr,{color:f.mutedForeground,children:uo(u.type)}),nt(wr,{color:p===void 0?f.mutedForeground:et[p],children:` ${m.label}`})]}),nt(ki,{marginTop:1,children:nt(it,{width:r,maxPerRow:2,tiles:[{label:"\u91D1\u989D",value:Ce(u.amountCny)},{label:"\u5173\u8054\u8BA2\u5355",value:`${u.orders.length} \u7B14`}]})}),nt(ki,{marginTop:1,children:nt(Ve,{width:r,items:d})}),nt(ki,{marginTop:1,flexDirection:"column",children:u.orders.map(b=>nt(wr,{wrap:"truncate",color:f.faintForeground,children:_e([b.orderNo,Ce(b.amountCny)])},b.orderNo))}),u.hasFile&&i===null&&nt(ki,{marginTop:1,children:nt(wr,{wrap:"truncate",color:f.faintForeground,children:"\u6309 d \u4E0B\u8F7D\u53D1\u7968\u6587\u4EF6"})}),i!==null&&nt(ki,{marginTop:1,children:nt(wr,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${i}`})})]})}})}function xb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Tm({name:"list"}),[i,s]=Me("status",()=>""),a=Q([e.revision],ob);G(l=>{o.name==="list"&&(l==="r"?e.reload():l==="f"?r({name:"filter"}):l==="n"?e.push("invoice-apply"):l==="p"&&e.push("invoice-profiles"))});let c=()=>{o.name==="list"?e.pop():r({name:"list"})};return nt(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","n \u7533\u8BF7\u5F00\u7968","p \u5E38\u7528\u4FE1\u606F","f \u7B5B\u9009","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:nt(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u5F00\u7968\u8BB0\u5F55",width:t,children:l=>{if(o.name==="filter")return nt(te,{title:"\u7B5B\u9009\u53D1\u7968",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:rR,initial:i}],onCancel:c,onSubmit:m=>{s(m.status??""),r({name:"list"})}});if(o.name==="detail")return nt(iR,{id:o.id,width:t});let u=i===""?l:l.filter(m=>m.status===i);return nt(de,{retain:"list",items:u,width:t,height:n,columns:[{label:"\u65F6\u95F4"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u91D1\u989D",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[K(m.createdAt),m.title,uo(m.type),Ce(m.amountCny),yt(Vi(m.status))],searchOf:m=>m.title,onOpen:m=>r({name:"detail",id:m.id}),emptyLabel:i===""?"\u6682\u65E0\u5F00\u7968\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u6309 n \u4E3A\u5DF2\u4ED8\u6B3E\u8BA2\u5355\u7533\u8BF7\u5F00\u7968":void 0})}})})}import{Box as sR}from"ink";import{useState as Tb}from"react";import{jsx as kr,jsxs as cR}from"react/jsx-runtime";var aR=_t(Xa,jc,"\u5168\u90E8\u7C7B\u578B");function wb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Tb("list"),[i,s]=Tb(""),a=Q([e.revision],()=>Ge(e.ctx.site)),c=ze([e.revision,i],m=>vh({page:m,...i===""?{}:{type:i}}),{retain:"page"}),l=o==="list";G((m,p)=>{l&&(m==="r"?e.reload():m==="f"?r("filter"):p.leftArrow?c.go(-1):p.rightArrow&&c.go(1))});let u=()=>{o==="list"?e.pop():r("list")};return kr(Y,{hints:l?["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:u,children:kr(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:m=>o==="filter"?kr(te,{title:"\u7B5B\u9009\u6D41\u6C34",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:aR,initial:i}],onCancel:u,onSubmit:p=>{s(p.type??""),c.reset(),r("list")}}):kr(V,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6D41\u6C34",width:t,children:p=>cR(sR,{flexDirection:"column",children:[kr(de,{retain:"list",items:p.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u65F6\u95F4"},{label:"\u7C7B\u578B"},{label:"\u53D8\u52A8",align:"right"},{label:"\u4F59\u989D",align:"right"},{label:"\u6765\u6E90",align:"right"}],row:d=>{let b=Xo(d.amount,m.quotaPerUsd);return[K(d.createdAt),jc(d.type),{text:d.amount>=0?`+${b}`:b,tone:d.amount>=0?"success":"danger"},Te(d.balanceAfter,m.quotaPerUsd),_e([Sd(d.refType),d.refId??""])]},emptyLabel:i===""?"\u6682\u65E0\u989D\u5EA6\u6D41\u6C34":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u5145\u503C\u6216\u6D88\u8017\u540E\uFF0C\u6BCF\u7B14\u53D8\u52A8\u4F1A\u8BB0\u5F55\u5728\u8FD9\u91CC":void 0}),kr(We,{page:c.page,pages:c.pages,total:c.total,width:t})]})})})})}import{Box as Pb}from"ink";import{useState as mR}from"react";import{z as lR}from"zod";var vi={recharge:"/recharge",subscription:"/subscriptions"};async function Fa(e,t){let n=`${vi[e]}/orders/${t}`;return e==="recharge"?{kind:e,...await A(Mr,n)}:{kind:e,...await A(Ir,n)}}async function kb(e,t){let n=`${vi[e]}/orders/${t}/pay`;if(e==="recharge"){let{order:i,qrCode:s}=await A(Mi,n,{method:"POST"});return{order:{kind:e,...i},qrCode:s}}let{order:o,qrCode:r}=await A(Nr,n,{method:"POST"});return{order:{kind:e,...o},qrCode:r}}var vb=(e,t)=>A(lR.array(fu),`${vi[e]}/orders/${t}/refunds`),Cb=(e,t,n)=>A(se,`${vi[e]}/orders/${t}/refund-request`,{method:"POST",json:{reason:n}}),Rb=(e,t)=>A(se,`${vi[e]}/orders/${t}/refund-request/cancel`,{method:"POST"});import{Box as Ua,Text as wn}from"ink";import{jsx as on,jsxs as Ci}from"react/jsx-runtime";function _b({order:e,refunds:t,quotaPerUsd:n,width:o}){let r=o-ge,i=zn(e.status),s=ht(i),a=[["\u521B\u5EFA\u65F6\u95F4",K(e.createdAt)]];return e.succeededRefundCny>0&&a.push(["\u5DF2\u9000\u91D1\u989D",Ce(e.succeededRefundCny)]),e.kind==="recharge"&&e.refundedQuota>0&&a.push(["\u6263\u56DE\u989D\u5EA6",Te(e.refundedQuota,n)]),e.pendingRefundCny>0&&a.push(["\u5F85\u786E\u8BA4\u9000\u6B3E",Ce(e.pendingRefundCny)]),Ci(pe,{title:e.kind==="recharge"?"\u5145\u503C":e.planName,note:e.orderNo,width:o,children:[Ci(wn,{wrap:"truncate",children:[on(wn,{color:s===void 0?f.mutedForeground:et[s],children:i.label}),e.kind==="subscription"&&on(wn,{color:f.faintForeground,children:` ${e.renewal?"\u7EED\u8D39":"\u65B0\u8D2D"}`})]}),on(Ua,{marginTop:1,children:on(it,{width:r,maxPerRow:2,tiles:e.kind==="recharge"?[{label:"\u91D1\u989D",value:Ce(e.amountCny)},{label:"\u5230\u8D26\u989D\u5EA6",value:Te(e.quota,n)}]:[{label:"\u91D1\u989D",value:Ce(e.amountCny)},{label:"\u8BA2\u9605\u65F6\u957F",value:`${e.grantedDurationDays} \u5929`}]})}),on(Ua,{marginTop:1,children:on(Ve,{width:r,items:a})}),t!==null&&Ci(Ua,{marginTop:1,flexDirection:"column",children:[on(wn,{color:f.mutedForeground,children:"\u9000\u6B3E\u8BB0\u5F55"}),t.length===0?on(wn,{color:f.faintForeground,children:"\u6682\u65E0\u9000\u6B3E\u8BB0\u5F55"}):t.map(c=>{let l=xd(c.status),u=ht(l);return Ci(Ua,{flexDirection:"column",children:[Ci(wn,{wrap:"truncate",children:[on(wn,{color:f.foreground,children:Ce(c.amountCny)}),on(wn,{color:u===void 0?f.mutedForeground:et[u],children:` ${l.label}`}),on(wn,{color:f.faintForeground,children:` ${K(c.createdAt)}`})]}),(c.reason!==null||c.rejectReason!==null||c.refundTradeNo!==null)&&on(wn,{wrap:"truncate",color:f.faintForeground,children:` ${_e([c.reason??"",c.rejectReason===null?"":`\u9A73\u56DE\uFF1A${c.rejectReason}`,c.refundTradeNo??""])}`})]},c.id)})]})]})}import{jsx as Do,jsxs as dR}from"react/jsx-runtime";var uR=new Set(["pending","expired","failed"]);function ja(e){let t=zn(e.status);return e.pendingRefundCny>0?{badge:`${t.label}\uFF08\u5F85\u786E\u8BA4 ${Ce(e.pendingRefundCny)}\uFF09`,badgeTone:"warning"}:{badge:t.label,badgeTone:ht(t)}}function vr(e,t,n){return e.kind==="recharge"?{kind:"recharge",orderNo:e.orderNo,qrCode:t,amountCny:e.amountCny,summary:[`\u5230\u8D26\u989D\u5EA6 ${Te(e.quota,n)}`],paidMessage:"\u5145\u503C\u6210\u529F\uFF01",paidNote:"\u4F59\u989D\u5DF2\u5230\u8D26",expiredNote:"\u82E5\u5DF2\u5B8C\u6210\u4ED8\u6B3E\uFF0C\u4F59\u989D\u4F1A\u81EA\u52A8\u5230\u8D26\uFF0C\u8BF7\u52FF\u91CD\u590D\u5145\u503C\uFF1B\u53EF\u5728\u300C\u5145\u503C\u8BB0\u5F55\u300D\u4E2D\u67E5\u770B"}:{kind:"subscription",orderNo:e.orderNo,qrCode:t,amountCny:e.amountCny,summary:[`${e.planName} \xB7 ${e.grantedDurationDays} \u5929`],paidMessage:"\u8BA2\u9605\u5DF2\u751F\u6548\uFF01",paidNote:"\u8BA2\u9605\u5DF2\u751F\u6548",expiredNote:"\u82E5\u5DF2\u5B8C\u6210\u4ED8\u6B3E\uFF0C\u8BA2\u9605\u4F1A\u81EA\u52A8\u751F\u6548\uFF0C\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\uFF1B\u53EF\u5728\u300C\u8BA2\u9605\u8BA2\u5355\u300D\u4E2D\u67E5\u770B"}}function Ab({params:e}){let t=O(),{width:n}=j(),[o,r]=mR("main"),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.kind,e.orderNo,t.revision],async()=>{let[h,g]=await Promise.all([Fa(e.kind,e.orderNo),Ge(t.ctx.site)]),x=uR.has(h.status)?null:await vb(e.kind,e.orderNo);return{order:h,refunds:x,site:g}});G(h=>{o==="main"&&i===null&&h==="r"&&t.reload()});let m=()=>{o==="main"?t.pop():(a(),r("main"))},p=h=>{l("\u6B63\u5728\u62C9\u8D77\u652F\u4ED8",()=>kb(e.kind,e.orderNo),{failToast:!0,onSuccess:({order:g,qrCode:x})=>{t.push("pay",vr(g,x,h.quotaPerUsd))}})},d=h=>{l("\u6B63\u5728\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7",()=>Cb(e.kind,e.orderNo,h),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7")}})},b=()=>{l("\u6B63\u5728\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",()=>Rb(e.kind,e.orderNo),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u64A4\u9500\u9000\u6B3E\u7533\u8BF7")}})};return Do(Y,{trail:["\u8BA2\u5355\u8BE6\u60C5"],hints:o==="main"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:Do(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u5355",width:n,children:({order:h,refunds:g,site:x})=>{if(o==="refund")return Do(te,{title:`\u7533\u8BF7\u9000\u6B3E \u2014 ${h.orderNo}`,width:n,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:i!==null,busyLabel:i??"\u6B63\u5728\u63D0\u4EA4",error:s,fields:[{kind:"select",name:"reason",label:"\u9000\u6B3E\u539F\u56E0",options:[...Wc[e.kind].map(k=>({value:k,label:k})),{value:"other",label:"\u5176\u4ED6"}],initial:Wc[e.kind][0],hint:_d[e.kind]},{kind:"textarea",name:"custom",label:"\u5177\u4F53\u8BF4\u660E",rows:3,maxLength:256,placeholder:"\u8BF4\u660E\u7533\u8BF7\u9000\u6B3E\u7684\u539F\u56E0",hint:"\u4EC5\u9000\u6B3E\u539F\u56E0\u9009\u300C\u5176\u4ED6\u300D\u65F6\u5FC5\u586B"}],onCancel:m,onSubmit:k=>{let S=k.reason??"",y=S==="other"?(k.custom??"").trim():S;if(y===""){c("\u8BF7\u586B\u5199\u5177\u4F53\u8BF4\u660E");return}d(y)}});if(o==="confirm-cancel")return Do(Ae,{width:n,title:"\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",detail:`\u786E\u8BA4\u64A4\u9500\u8BA2\u5355 ${h.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\uFF1F${h.kind==="recharge"?"\u6536\u56DE\u7684\u989D\u5EA6":"\u51BB\u7ED3\u7684\u8BA2\u9605\u65F6\u957F"}\u5C06\u7ACB\u5373\u6062\u590D`,confirmLabel:"\u64A4\u9500\u7533\u8BF7",busy:i,error:s,onConfirm:b,onCancel:m});let T=[];return h.status==="pending"&&T.push({value:"pay",label:"\u7EE7\u7EED\u652F\u4ED8",hint:"\u91CD\u65B0\u62C9\u8D77\u652F\u4ED8\u5B9D\u4E8C\u7EF4\u7801"}),h.status==="refund_requested"&&T.push({value:"cancel-refund",label:"\u64A4\u9500\u7533\u8BF7",hint:"\u9000\u6B3E\u5C1A\u672A\u5BA1\u6838\uFF0C\u53EF\u64A4\u56DE"}),gu(h)&&T.push({value:"refund",label:"\u7533\u8BF7\u9000\u6B3E",labelTone:"danger"}),dR(Pb,{flexDirection:"column",children:[Do(_b,{order:h,refunds:g,quotaPerUsd:x.quotaPerUsd,width:n}),T.length>0&&i===null&&Do(Pb,{marginTop:1,children:Do(le,{width:n,items:T,retain:"menu",onSelect:k=>{a(),k==="pay"?p(x):r(k==="refund"?"refund":"confirm-cancel")}})})]})}})})}import{useRef as fR,useState as Ob}from"react";import{Box as Eb,Text as $o}from"ink";import{Fragment as pR,jsx as zt,jsxs as Mb}from"react/jsx-runtime";var Ib={columns:20,rows:2};function Nb(e,t,n){return js(e,t,Ib,n)}function Lb({phase:e,qrCode:t,amountCny:n,summary:o,paidNote:r,expiredNote:i,pollError:s,width:a,layout:c}){let l=s===null?zt(Oe,{label:"\u7B49\u5F85\u652F\u4ED8\u5230\u8D26\u2026"}):zt($o,{wrap:"truncate",color:et.warning,children:`\u67E5\u8BE2\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1A${s}`});if(e==="paid")return zt(ye,{tone:"ok",width:a,title:"\u652F\u4ED8\u6210\u529F\uFF01",detail:r});if(e==="expired")return zt(ye,{tone:"warn",width:a,title:"\u8BA2\u5355\u5DF2\u8D85\u65F6",detail:i});if(!c.fits)return Mb(Eb,{flexDirection:"column",children:[zt(ye,{tone:"warn",width:a,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u65E0\u6CD5\u7ED8\u5236\u4E8C\u7EF4\u7801",detail:`\u653E\u5927\u5230 ${c.target.columns} \xD7 ${c.target.rows} \u53EF\u663E\u793A\u4E8C\u7EF4\u7801\uFF0C\u6216\u6309 c \u590D\u5236\u4ED8\u6B3E\u94FE\u63A5`}),zt($o,{color:f.accent,children:t}),zt(Eb,{marginTop:1,children:zt($o,{bold:!0,color:f.foreground,children:Ce(n)})}),l]});let u=c.asideRows-Ib.rows,m=u>=1,p=u>=2,d=u>=2+o.length;return zt(Hs,{value:t,aside:Mb(pR,{children:[p&&zt($o,{bold:!0,color:f.foreground,children:"\u626B\u7801\u652F\u4ED8"}),zt($o,{bold:!0,color:f.foreground,children:Ce(n)}),m&&zt($o,{color:f.mutedForeground,children:"\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u4E00\u626B\u5B8C\u6210\u652F\u4ED8"}),d&&o.map((b,h)=>zt($o,{wrap:"truncate",color:f.mutedForeground,children:b},h)),l]})})}import{jsx as Db}from"react/jsx-runtime";var gR=5,hR=2e3;function $b({params:e}){let t=O(),{width:n,columns:o,rows:r}=j(),i=oi(0),[s,a]=Ob("waiting"),[c,l]=Ob(null),u=fR(0);na(hR,async()=>{let d;try{d=await Fa(e.kind,e.orderNo)}catch(b){l(xe(b));return}if(l(null),d.status==="paid"||d.credited){a("paid"),t.toast("ok",e.paidMessage);return}if(d.status==="expired"||d.status==="failed"){u.current+=1,u.current>=gR&&a("expired");return}u.current=0},s==="waiting"),G(d=>{d!=="c"||s!=="waiting"||La(e.qrCode).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))});let m=Nb(e.qrCode,{width:n,rows:i},{columns:o-n,rows:r-i}),p=s==="waiting"&&m.fits;return Db(Y,{trail:["\u626B\u7801\u652F\u4ED8"],bleed:p,hints:s==="waiting"?["c \u590D\u5236\u94FE\u63A5"]:[],children:Db(Lb,{phase:s,qrCode:e.qrCode,amountCny:e.amountCny,summary:e.summary,paidNote:e.paidNote,expiredNote:e.expiredNote,pollError:c,width:n,layout:m})})}import{useState as bR}from"react";import{z as jn}from"zod";var yR=jn.object({id:jn.number().int(),name:jn.string(),originalCny:jn.number().int(),discountPercent:jn.number().int(),payCny:jn.number().int(),quota:jn.number()}),Bb=()=>A(jn.array(yR),"/recharge-packages"),Fb=e=>A(Mi,"/recharge/orders",{method:"POST",json:e}),Ub=()=>A(jn.array(Mr),"/recharge/orders");import{jsx as Cr}from"react/jsx-runtime";var SR=_t(_r,zn,"\u5168\u90E8\u72B6\u6001");function xR(e,t){let n=e.discountPercent<100?`\uFF08\u539F\u4EF7 ${Ce(e.originalCny)} \xB7 ${e.discountPercent/10} \u6298\uFF09`:"";return`${Ce(e.payCny)}${n} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(e.quota,t)}`}function jb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=bR({name:"menu"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue();Re(a!==null);let p=Q([e.revision],async()=>{let[h,g,x]=await Promise.all([Bb(),wa(e.ctx.site),Ub()]);return{packages:h,pricing:g,orders:x}});G(h=>{o.name==="menu"&&(h==="r"?e.reload():h==="f"&&r({name:"filter"}))});let d=()=>{o.name==="menu"?e.pop():(l(),r({name:"menu"}))},b=(h,g)=>{m("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Fb(h),{onSuccess:({order:x,qrCode:T})=>{r({name:"menu"}),e.push("pay",vr({kind:"recharge",...x},T,g))}})};return Cr(Y,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BB0\u5F55","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:d,isActive:a===null,children:Cr(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u5145\u503C\u5957\u9910",width:t,children:({packages:h,pricing:g,orders:x})=>{if(o.name==="confirm")return Cr(Ae,{width:t,title:`\u786E\u8BA4\u5145\u503C ${Ce(o.pkg.payCny)}\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b({packageId:o.pkg.id},g.quotaPerUsd),onCancel:d});if(o.name==="custom")return Cr(te,{title:"\u81EA\u5B9A\u4E49\u91D1\u989D\u5145\u503C",width:t,submitLabel:"\u53BB\u652F\u4ED8",busy:a!==null,busyLabel:a??"\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",error:c,fields:[{kind:"text",name:"yuan",label:"\u5145\u503C\u91D1\u989D\uFF08\u5143\uFF09",placeholder:"\u8BF7\u8F93\u5165\u91D1\u989D",hint:`\u6700\u4F4E ${g.minTopupCny} \u5143 \xB7 \u5230\u8D26\u989D\u5EA6\u6309\u5145\u503C\u6C47\u7387\u6298\u7B97`}],onCancel:d,onSubmit:S=>{let y=Number((S.yuan??"").trim()),R=Oc(y);if(!Number.isFinite(y)||R<Oc(g.minTopupCny)||R>ic){u(`\u8BF7\u8F93\u5165 ${g.minTopupCny} \u5230 ${ud(ic)} \u5143\u4E4B\u95F4\u7684\u91D1\u989D`);return}b({amountCny:R},g.quotaPerUsd)}});if(o.name==="filter")return Cr(te,{title:"\u7B5B\u9009\u5145\u503C\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:SR,initial:i}],onCancel:d,onSubmit:S=>{s(S.status??""),r({name:"menu"})}});let T=i===""?x:x.filter(S=>S.status===i),k=[{heading:"\u5145\u503C\u5957\u9910"},...h.map(S=>({value:{kind:"pkg",pkg:S},label:S.name,hint:xR(S,g.quotaPerUsd)})),{value:{kind:"custom"},label:"\u81EA\u5B9A\u4E49\u91D1\u989D",hint:"\u8F93\u5165\u4EFB\u610F\u91D1\u989D\u5145\u503C"},{heading:""},{heading:"\u5145\u503C\u8BB0\u5F55"},...T.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u5145\u503C\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u9009\u62E9\u4E0A\u65B9\u5957\u9910\u6216\u8F93\u5165\u81EA\u5B9A\u4E49\u91D1\u989D\u5373\u53EF\u5145\u503C"}:{},disabled:!0}]:T.map(S=>({value:{kind:"order",orderNo:S.orderNo},label:Ce(S.amountCny),...ja(S),hint:`${K(S.createdAt)} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(S.quota,g.quotaPerUsd)}`}))];return Cr(le,{items:k,width:t,height:n,retain:"menu",onSelect:S=>{l(),S.kind==="custom"?r({name:"custom"}):S.kind==="order"?e.push("order",{kind:"recharge",orderNo:S.orderNo}):S.kind==="pkg"&&r({name:"confirm",pkg:S.pkg})}})}})})}import{Box as Hn,Text as Ri}from"ink";import{useState as vR}from"react";import CR from"string-width";import{z as Se}from"zod";var TR=Se.object({windowId:Se.number().int(),durationMinutes:Se.number().int(),quota:Se.number(),used:Se.number(),resetAt:Se.string()}),Hb=Se.object({name:Se.string(),multiplier:Se.number()}),wR=Se.object({billingPreference:Va,subscriptions:Se.array(Se.object({id:Se.number().int(),planName:Se.string(),groups:Se.array(Hb),startsAt:Se.string(),expiresAt:Se.string(),revokedAt:Se.string().nullable(),renewable:Se.boolean(),windows:Se.array(TR)}))}),qb=()=>A(wR,"/subscriptions"),kR=Se.object({id:Se.number().int(),name:Se.string(),description:Se.string().nullable(),priceCny:Se.number().int(),durationDays:Se.number().int(),enabled:Se.boolean(),groups:Se.array(Hb),windows:Se.array(Se.object({durationMinutes:Se.number().int(),quota:Se.number()}))}),Gb=()=>A(Se.array(kR),"/subscription-plans"),zb=e=>A(Nr,"/subscriptions/orders",{method:"POST",json:e}),Wb=e=>A(Nr,`/subscriptions/${e}/renew`,{method:"POST"}),Vb=()=>A(Se.array(Ir),"/subscriptions/orders"),Kb=e=>A(Se.object({billingPreference:Va}),"/subscriptions/preference",{method:"PUT",json:e});import{jsx as Ue,jsxs as Bo}from"react/jsx-runtime";var RR=_t(_r,zn,"\u5168\u90E8\u72B6\u6001");function _R(e,t,n){if(e.name==="sub"||e.name==="confirm-renew"){let o=t.find(r=>r.id===e.id);return o===void 0?{kind:"missing-sub"}:{kind:"sub",sub:o,confirm:e.name==="confirm-renew"}}if(e.name==="plan"||e.name==="confirm-buy"){let o=n.find(r=>r.id===e.id);return o===void 0?{kind:"missing-plan"}:{kind:"plan",plan:o,confirm:e.name==="confirm-buy"}}return{kind:"none"}}var PR=3;function AR({win:e,quotaPerUsd:t,width:n}){let o=Gc(e),r=Cd(e.durationMinutes),i=`\u5DF2\u7528 ${o}% ${ae.bullet} ${Te(e.used,t)} / ${Te(e.quota,t)}`;return Bo(Hn,{flexDirection:"column",children:[Bo(Ri,{wrap:"truncate",children:[Ue(Ri,{color:f.foreground,children:r}),Ue(Ri,{color:o>=100?f.danger:f.mutedForeground,children:Kn(i,Math.max(0,n-CR(r)))})]}),Ue(hg,{used:e.used,total:e.quota,width:n}),Ue(Ri,{wrap:"truncate",color:f.faintForeground,children:`\u5C06\u4E8E ${K(e.resetAt)} \u91CD\u7F6E`})]})}function ER(e){if(e.revokedAt!==null)return`${K(e.revokedAt)} \u4F5C\u5E9F`;let t=`${K(e.expiresAt)} \u5230\u671F`;return`\u5DF2\u7528 ${Math.max(...e.windows.map(Gc))}% \xB7 ${t}`}function MR(e){let t=e.windows.length*4;return X+Xe+2+t+(e.renewable?X+1:0)}function IR(e){let t=e.description!==null&&e.description!==""?1+qe:0,n=Math.ceil((1+e.windows.length)/2);return X+Xe+t+n+X+1}function Yb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=vR({name:"menu"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[g,x,T,k]=await Promise.all([qb(),Gb(),Vb(),Ge(e.ctx.site)]);return{mine:g,plans:x,orders:T,site:k}});G(g=>{o.name!=="menu"||a!==null||(g==="r"?e.reload():g==="f"&&r({name:"filter"}))});let p=()=>{l(),o.name==="menu"?e.pop():o.name==="confirm-renew"?r({name:"sub",id:o.id}):o.name==="confirm-buy"?r({name:"plan",id:o.id}):r({name:"menu"})},d=g=>{u("\u6B63\u5728\u4FDD\u5B58\u504F\u597D",()=>Kb({billingPreference:g}),{onSuccess:()=>{r({name:"menu"}),e.reload(),e.toast("ok","\u504F\u597D\u5DF2\u4FDD\u5B58")}})},b=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u7EED\u8D39\u8BA2\u5355",()=>Wb(g.id),{onSuccess:({order:T,qrCode:k})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},k,x.quotaPerUsd))}})},h=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>zb({planId:g.id}),{onSuccess:({order:T,qrCode:k})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},k,x.quotaPerUsd))}})};return Ue(Y,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BA2\u5355","r \u5237\u65B0"]:o.name==="sub"||o.name==="plan"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","Esc \u8FD4\u56DE"]:["Esc \u8FD4\u56DE"],onEscape:p,isActive:a===null,children:Ue(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u9605",width:t,children:({mine:g,plans:x,orders:T,site:k})=>{if(o.name==="preference")return Ue(te,{title:"\u6263\u8D39\u65B9\u5F0F",width:t,submitLabel:"\u4FDD\u5B58",busy:a!==null,busyLabel:a??"\u6B63\u5728\u4FDD\u5B58",error:c,fields:[{kind:"select",name:"billingPreference",label:"\u6263\u8D39\u65B9\u5F0F",options:bd,initial:g.billingPreference,hint:Uc}],onCancel:p,onSubmit:v=>{d(v.billingPreference??g.billingPreference)}});if(o.name==="filter")return Ue(te,{title:"\u7B5B\u9009\u8BA2\u9605\u8BA2\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:RR,initial:i}],onCancel:p,onSubmit:v=>{s(v.status??""),r({name:"menu"})}});let S=_R(o,g.subscriptions,x);if(S.kind==="missing-sub")return Ue(ye,{tone:"warn",width:t,title:"\u8BA2\u9605\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",detail:"\u6309 Esc \u8FD4\u56DE"});if(S.kind==="missing-plan")return Ue(ye,{tone:"warn",width:t,title:"\u5957\u9910\u4E0D\u5B58\u5728\u6216\u5DF2\u4E0B\u67B6",detail:"\u6309 Esc \u8FD4\u56DE"});if(S.kind==="sub"&&S.confirm)return Ue(Ae,{width:t,title:`\u786E\u8BA4\u7EED\u8D39\u300C${S.sub.planName}\u300D\uFF1F`,detail:"\u5C06\u6309\u5957\u9910\u5F53\u524D\u4EF7\u683C\u4E0E\u65F6\u957F\u5728\u5230\u671F\u65F6\u95F4\u4E0A\u987A\u5EF6",confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b(S.sub,k),onCancel:p});if(S.kind==="plan"&&S.confirm)return Ue(Ae,{width:t,title:`\u786E\u8BA4\u8BA2\u9605\u300C${S.plan.name}\u300D\uFF08${Ce(S.plan.priceCny)} / ${S.plan.durationDays} \u5929\uFF09\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>h(S.plan,k),onCancel:p});let y=S.kind==="plan"?S.plan.description:"",R=i===""?T:T.filter(v=>v.status===i),N=[{heading:"\u6211\u7684\u8BA2\u9605"},...g.subscriptions.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u8BA2\u9605",hint:"\u8BA2\u9605\u4E0B\u65B9\u5957\u9910\u540E\uFF0C\u8986\u76D6\u8303\u56F4\u5185\u7684\u8C03\u7528\u5C06\u6309\u6263\u8D39\u65B9\u5F0F\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6",disabled:!0}]:g.subscriptions.map(v=>{let _=zc(v);return{value:{kind:"sub",id:v.id},label:v.planName,badge:_.label,badgeTone:ht(_),hint:ER(v)}}),{heading:""},{value:{kind:"preference"},label:"\u6263\u8D39\u65B9\u5F0F",badge:Fc(g.billingPreference),badgeTone:"accent",hint:Uc(g.billingPreference)},{heading:""},{heading:"\u53EF\u9009\u5957\u9910"},...x.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u53EF\u9009\u5957\u9910",hint:"\u8BA2\u9605\u5957\u9910\u4E0A\u67B6\u540E\u5C06\u663E\u793A\u5728\u8FD9\u91CC",disabled:!0}]:x.map(v=>({value:{kind:"plan",id:v.id},label:v.name,...v.enabled?{}:{badge:"\u5DF2\u505C\u552E",badgeTone:"warning"},hint:`${Ce(v.priceCny)} / ${v.durationDays} \u5929 \xB7 ${v.groups.map(Zi).join("\u3001")}`})),{heading:""},{heading:"\u8BA2\u9605\u8BA2\u5355"},...R.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u8BA2\u9605\u8BA2\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u8BA2\u9605\u4E0A\u65B9\u5957\u9910\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}:{},disabled:!0}]:R.map(v=>({value:{kind:"order",orderNo:v.orderNo},label:`${v.planName}${v.renewal?"\uFF08\u7EED\u8D39\uFF09":""}`,...ja(v),hint:`${K(v.createdAt)} \xB7 ${Ce(v.amountCny)}`}))],E=S.kind==="sub"?MR(S.sub):S.kind==="plan"?IR(S.plan):0,W=E===0?n:n-E>=PR?n-E:0,M=t-ge,C=o.name==="menu"&&a===null;return Bo(Hn,{flexDirection:"column",children:[W>0&&Ue(le,{items:N,width:t,height:W,isActive:C,retain:"menu",onSelect:v=>{l(),v.kind==="preference"?r({name:"preference"}):v.kind==="order"?e.push("order",{kind:"subscription",orderNo:v.orderNo}):v.kind==="sub"?r({name:"sub",id:v.id}):v.kind==="plan"&&r({name:"plan",id:v.id})}}),S.kind==="sub"&&Bo(Hn,{marginTop:W>0?X:0,flexDirection:"column",children:[Bo(pe,{title:S.sub.planName,note:S.sub.revokedAt!==null?`${K(S.sub.revokedAt)} \u4F5C\u5E9F`:`${K(S.sub.expiresAt)} \u5230\u671F`,width:t,children:[Ue(Ve,{width:M,items:[["\u72B6\u6001",zc(S.sub).label],["\u8986\u76D6\u5206\u7EC4",S.sub.groups.map(Zi).join("\u3001")],["\u751F\u6548\u65F6\u95F4",K(S.sub.startsAt)]]}),Ue(Hn,{marginTop:1,flexDirection:"column",children:S.sub.windows.map((v,_)=>Ue(Hn,{marginTop:_===0?0:1,flexDirection:"column",children:Ue(AR,{win:v,quotaPerUsd:k.quotaPerUsd,width:M})},v.windowId))})]}),S.sub.renewable&&a===null&&Ue(Hn,{marginTop:X,children:Ue(le,{width:t,items:[{value:"renew",label:"\u7EED\u8D39"}],onSelect:()=>r({name:"confirm-renew",id:S.sub.id})})})]}),S.kind==="plan"&&Bo(Hn,{marginTop:W>0?X:0,flexDirection:"column",children:[Bo(pe,{title:S.plan.name,note:`${Ce(S.plan.priceCny)} / ${S.plan.durationDays} \u5929`,width:t,children:[y!==""&&Ue(Ri,{wrap:"truncate",color:f.mutedForeground,children:y}),Ue(Hn,{marginTop:y===""?0:qe,children:Ue(Ve,{width:M,items:[["\u8986\u76D6\u5206\u7EC4",S.plan.groups.map(Zi).join("\u3001")],...Rd(S.plan,k.quotaPerUsd).map((v,_)=>[_===0?"\u7528\u91CF\u7A97\u53E3":"",v])]})})]}),a===null&&Ue(Hn,{marginTop:X,children:Ue(le,{width:t,items:[{value:"subscribe",label:S.plan.enabled?"\u8BA2\u9605":"\u5DF2\u505C\u552E",disabled:!S.plan.enabled}],onSelect:()=>r({name:"confirm-buy",id:S.plan.id})})})]})]})}})})}import{jsx as be}from"react/jsx-runtime";var Jb={home:{render:()=>be(Yy,{})},help:{render:()=>be(Wy,{})},login:{render:()=>be(zg,{})},register:{render:()=>be(Wg,{})},forgot:{render:()=>be(jg,{})},agreement:{render:e=>be(Og,{params:e})},tokens:{render:()=>be(My,{})},logs:{render:()=>be($h,{})},usage:{render:()=>be(Eh,{})},ledger:{render:()=>be(wb,{})},subscription:{render:()=>be(Yb,{})},models:{render:()=>be(Gh,{})},docs:{render:()=>be(By,{})},doc:{render:e=>be(jy,{params:e})},recharge:{render:()=>be(jb,{})},order:{render:e=>be(Ab,{params:e})},pay:{render:e=>be($b,{params:e})},invoices:{render:()=>be(xb,{})},"invoice-apply":{render:()=>be(fb,{})},"invoice-profiles":{render:()=>be(bb,{})},invite:{render:()=>be(eb,{})},tickets:{render:()=>be(Lg,{})},ticket:{render:e=>be(Ng,{params:e})},community:{render:()=>be(mh,{})},post:{render:e=>be(Sh,{params:e})},floor:{render:e=>be(oh,{params:e})},compose:{render:e=>be(Jg,{params:e})},"post-edit":{render:e=>be(Xg,{params:e})},homepage:{render:e=>be(sh,{params:e})},inbox:{render:()=>be(Jy,{})},announcements:{render:()=>be(Qp,{})},"announce-gate":{render:e=>be(Yp,{params:e}),lockNav:!0},profile:{render:()=>be(wg,{})},"my-posts":{render:e=>be(ph,{params:e})},"my-comments":{render:e=>be(fh,{params:e})},bookmarks:{render:()=>be(gh,{})},drafts:{render:()=>be(hh,{})}};function Xb(e){return Jb[e].lockNav===!0}function Qb(e){let t=Jb[e.id].render;return t(e.params)}import{jsx as oo,jsxs as zR}from"react/jsx-runtime";function $R(){let e=O(),{rows:t}=j(),n=us(),o=Xb(e.current.id)||n,r=e.depth===1&&fs(e.current.id)&&Lt().session===null;return wm(()=>{r&&e.home()}),OR((i,s)=>{s.ctrl&&i==="c"&&e.exit()}),G(i=>{if(i==="?"){e.current.id==="help"?e.pop():o||e.push("help");return}i==="q"&&!o&&(e.depth>1?e.pop():e.exit())}),oo(NR,{flexDirection:"column",height:Math.max(1,t),paddingX:1,paddingTop:1,overflow:"hidden",children:Qb(e.current)})}function BR(){let e=O(),t=Q([e.revision],async()=>{if(e.gate.announcementsChecked||Lt().session===null)return null;let n;try{n=await Gd()}catch{return null}return e.gate.announcementsChecked=!0,n});return wm(()=>{t.phase!=="ready"||t.data===null||e.gate.announcementsShown||(e.gate.announcementsShown=!0,e.push("announce-gate",{item:t.data}))}),null}function FR(){let e=O(),t=DR(!1);return wm(()=>{t.current||(t.current=!0,Hd().then(n=>{n!==null&&e.toast("ok",`\u5DF2\u66F4\u65B0\u5230 v${n}\uFF0C\u91CD\u542F\u540E\u751F\u6548`)}).catch(n=>e.toast("fail",`\u81EA\u52A8\u66F4\u65B0\u5931\u8D25\uFF1A${xe(n)}`)))}),null}function UR({ctx:e,mouse:t}){return oo(ap,{subscribe:t.subscribe,children:oo(Xd,{children:oo(dp,{ctx:e,children:zR(zp,{children:[oo(FR,{}),oo(BR,{}),oo($R,{})]})})})})}var jR="\x1B[2J\x1B[3J\x1B[H",HR="\x1B[H\x1B[J",qR="\x1B[3J";function GR(e){return new Proxy(e,{get(t,n){if(n!=="write"){let o=Reflect.get(t,n,t);return typeof o=="function"?o.bind(t):o}return(...o)=>{let[r,...i]=o;if(typeof r!="string")return t.write(r,...i);let s=r.split(jR).join(HR).split(qR).join("");return t.write(s,...i)}}})}async function Zb(e){let t=ip(process.stdin,process.stdout);try{await LR(oo(UR,{ctx:e,mouse:t}),{exitOnCtrlC:!0,alternateScreen:!0,stdin:t.stdin,stdout:GR(process.stdout)}).waitUntilExit()}finally{t.dispose()}}var YR=`${Wt} v${Vt} \u2014 CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF
27
27
 
28
28
  \u7528\u6CD5
29
- ${zt} \u8FDB\u5165\u4EA4\u4E92\u754C\u9762
30
- ${zt} help \u67E5\u770B\u672C\u8BF4\u660E
31
- ${zt} update \u68C0\u67E5\u5E76\u5B89\u88C5\u65B0\u7248\u672C
32
- ${zt} uninstall \u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
33
- `;async function zC(){let e;try{({positionals:e}=GC({args:process.argv.slice(2),allowPositionals:!0,options:{}}))}catch(n){throw new j(xe(n),{hint:`\u8FD0\u884C ${zt} help \u67E5\u770B\u7528\u6CD5`,exitCode:Wa})}let[t]=e;if(t==="help")return process.stdout.write(WC),Cr;if(t==="update")return VC();if(t==="uninstall")return YC();if(t!==void 0)throw new j(`\u672A\u77E5\u547D\u4EE4 ${t}\uFF0C\u8FD0\u884C ${zt} help \u67E5\u770B\u7528\u6CD5`,{exitCode:Wa});return XC(),await Jb(Dm()),Cr}async function VC(){let e=process.stdout,t=KC(e,"\u6B63\u5728\u68C0\u67E5\u65B0\u7248\u672C"),n;try{n=await Bd()}finally{t()}let o=io(e,p.accent,"\u2714");return e.write(n===null?`${o} \u5DF2\u662F\u6700\u65B0\u7248\u672C v${Vt}
29
+ ${Wt} \u8FDB\u5165\u4EA4\u4E92\u754C\u9762
30
+ ${Wt} help \u67E5\u770B\u672C\u8BF4\u660E
31
+ ${Wt} update \u68C0\u67E5\u5E76\u5B89\u88C5\u65B0\u7248\u672C
32
+ ${Wt} uninstall \u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
33
+ `;async function JR(){let e;try{({positionals:e}=KR({args:process.argv.slice(2),allowPositionals:!0,options:{}}))}catch(n){throw new U(xe(n),{hint:`\u8FD0\u884C ${Wt} help \u67E5\u770B\u7528\u6CD5`,exitCode:qa})}let[t]=e;if(t==="help")return process.stdout.write(YR),Rr;if(t==="update")return XR();if(t==="uninstall")return ZR();if(t!==void 0)throw new U(`\u672A\u77E5\u547D\u4EE4 ${t}\uFF0C\u8FD0\u884C ${Wt} help \u67E5\u770B\u7528\u6CD5`,{exitCode:qa});return t_(),await Zb(Dm()),Rr}async function XR(){let e=process.stdout,t=QR(e,"\u6B63\u5728\u68C0\u67E5\u65B0\u7248\u672C"),n;try{n=await jd()}finally{t()}let o=io(e,f.accent,"\u2714");return e.write(n===null?`${o} \u5DF2\u662F\u6700\u65B0\u7248\u672C v${Vt}
34
34
  `:`${o} \u5DF2\u66F4\u65B0\u5230 v${n}
35
- `),Cr}function KC(e,t){if(!e.isTTY)return e.write(`${t}
36
- `),()=>{};let n=io(e,p.mutedForeground,t),o=0,r=()=>{let s=Xo[o%Xo.length]??"";o+=1,e.write(`\r\x1B[2K${io(e,p.accent,s)} ${n}`)};r();let i=setInterval(r,Ss);return()=>{clearInterval(i),e.write("\r\x1B[2K")}}async function YC(){let e=process.stdout;if(e.write(`\u5378\u8F7D\u4F1A\u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
37
- `),!await JC("\u8F93\u5165 y \u786E\u8BA4\u5378\u8F7D\uFF1A"))return e.write(`\u5DF2\u53D6\u6D88
38
- `),Fo;let t=await Ld({done:n=>e.write(`${io(e,p.accent,"\u2714")} ${n}
39
- `),failed:n=>e.write(`${io(e,p.danger,"\u2718")} ${n}
35
+ `),Rr}function QR(e,t){if(!e.isTTY)return e.write(`${t}
36
+ `),()=>{};let n=io(e,f.mutedForeground,t),o=0,r=()=>{let s=Qo[o%Qo.length]??"";o+=1,e.write(`\r\x1B[2K${io(e,f.accent,s)} ${n}`)};r();let i=setInterval(r,bs);return()=>{clearInterval(i),e.write("\r\x1B[2K")}}async function ZR(){let e=process.stdout;if(e.write(`\u5378\u8F7D\u4F1A\u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
37
+ `),!await e_("\u8F93\u5165 y \u786E\u8BA4\u5378\u8F7D\uFF1A"))return e.write(`\u5DF2\u53D6\u6D88
38
+ `),Uo;let t=await $d({done:n=>e.write(`${io(e,f.accent,"\u2714")} ${n}
39
+ `),failed:n=>e.write(`${io(e,f.danger,"\u2718")} ${n}
40
40
  `)});if(t.length===0)return e.write(`\u767B\u5F55\u72B6\u6001\u3001\u672C\u5730\u6587\u4EF6\u4E0E\u672C\u7A0B\u5E8F\u5747\u5DF2\u6E05\u9664
41
- `),Cr;e.write(`\u4EE5\u4E0B\u9879\u76EE\u672A\u80FD\u6E05\u7406\uFF1A
41
+ `),Rr;e.write(`\u4EE5\u4E0B\u9879\u76EE\u672A\u80FD\u6E05\u7406\uFF1A
42
42
  `);for(let n of t)e.write(` ${n}
43
- `);return Fo}async function JC(e){let t=qC({input:process.stdin,output:process.stdout});t.once("SIGINT",()=>t.close());let n=await Promise.race([t.question(e),HC(t,"close").then(()=>"")]);return t.close(),n.trim().toLowerCase()==="y"}function XC(){if(!process.stdin.isTTY||!process.stdout.isTTY)throw new j("\u4EA4\u4E92\u754C\u9762\u9700\u8981\u5728\u7EC8\u7AEF\u4E2D\u76F4\u63A5\u8FD0\u884C")}var Xb=(e,t)=>io(process.stderr,e,t);try{process.exitCode=await zC()}catch(e){process.stderr.write(`${Xb(p.danger,"\u2718")} ${xe(e)}
44
- `),e instanceof j&&e.hint&&process.stderr.write(` ${Xb(p.faintForeground,e.hint)}
45
- `),process.exitCode=e instanceof j?e.exitCode:Fo}
43
+ `);return Uo}async function e_(e){let t=VR({input:process.stdin,output:process.stdout});t.once("SIGINT",()=>t.close());let n=await Promise.race([t.question(e),WR(t,"close").then(()=>"")]);return t.close(),n.trim().toLowerCase()==="y"}function t_(){if(!process.stdin.isTTY||!process.stdout.isTTY)throw new U("\u4EA4\u4E92\u754C\u9762\u9700\u8981\u5728\u7EC8\u7AEF\u4E2D\u76F4\u63A5\u8FD0\u884C")}var eS=(e,t)=>io(process.stderr,e,t);try{process.exitCode=await JR()}catch(e){process.stderr.write(`${eS(f.danger,"\u2718")} ${xe(e)}
44
+ `),e instanceof U&&e.hint&&process.stderr.write(` ${eS(f.faintForeground,e.hint)}
45
+ `),process.exitCode=e instanceof U?e.exitCode:Uo}