@codeflow-ai/cli 1.33.0 → 1.34.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.
- package/dist/cli.js +17 -17
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{once as t_}from"events";import{createInterface as n_}from"readline/promises";import{parseArgs as o_}from"util";var Am={name:"@codeflow-ai/cli",version:"1.
|
|
3
|
-
`,n)}function Ai(e,t,n,o,r){let i=null,s=()=>{if(i)return i;let a=n(),c=Lt(a);if(c===null)return i=structuredClone(t),i;let l;try{l=JSON.parse(c)}catch(m){throw new F(`${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 F(`${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),Mm(n(),c,384),i=c,c}}}import{homedir as hS}from"os";import{join as qo}from"path";function Cn(){let e=process.env.XDG_CONFIG_HOME;if(e)return qo(e,"codeflow");if(process.platform==="win32"){let t=process.env.APPDATA;if(t)return qo(t,"codeflow")}return qo(hS(),".config","codeflow")}var Im=()=>qo(Cn(),"config.json"),Ei=()=>qo(Cn(),"credentials.json"),Nm=()=>qo(Cn(),"refresh.lock");var wS=rn.object({refreshCookie:rn.string(),accessToken:rn.string(),accessExpiresAt:rn.number(),username:rn.string(),email:rn.string(),site:rn.string()}),kS=rn.object({site:rn.string(),cookie:rn.string()}),vS=rn.object({session:wS.nullable(),device:kS.nullable()}),Ya=Ai(vS,{session:null,device:null},Ei,"\u672C\u5730\u51ED\u636E","\u91CD\u65B0\u767B\u5F55"),wt=Ya.load,Mi=Ya.reload,Pr=Ya.update;function $m(){let{session:e}=wt();if(!e)throw new F("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:io});return e}var CS=6e4,RS=75e3,_S=120;function PS(e,t){try{Lm(e)}catch{try{Date.now()-SS(e).mtimeMs>CS&&Om(e,{recursive:!0,force:!0})}catch{}return!1}return xS(Dm(e,"owner"),t),!0}function AS(e,t){let n;try{n=bS(Dm(e,"owner"),"utf8")}catch{return}n===t&&Om(e,{recursive:!0,force:!0})}async function Ii(e){let t=Nm(),n=yS(16).toString("hex");Lm(Cn(),{recursive:!0,mode:448});let o=Date.now()+RS;for(;!PS(t,n);){if(Date.now()>o)throw new F(`\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 TS(_S)}try{return await e()}finally{AS(t,n)}}function ES(){let e=process.env.CODEFLOW_SITE;if(e)return e;let t=wt().session;return t?t.site:Pi}function Bm(){return{site:ES()}}function so(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{z as ht}from"zod";import{release as Cx}from"os";import{z as He}from"zod";var MS=["active","disabled"],F_=He.enum(MS),Ja=["subscription_first","balance_first","subscription_only","balance_only"],Xa=He.enum(Ja),IS=["openai","anthropic"],Fm=He.enum(IS),NS=["openai-chat","openai-responses","anthropic-messages"],Um=He.enum(NS);var Ar=["pending","paid","refund_requested","partially_refunded","refunded","failed","expired"],jm=He.enum(Ar),LS=["recharge","subscription"],Qa=He.enum(LS),OS=["requested","pending","succeeded","failed","rejected","canceled"],Hm=He.enum(OS),Za=["pending","issued","rejected"],qm=He.enum(Za),DS=["special","general"],ec=He.enum(DS),$S=["info","success","warning","error"],Gm=He.enum($S),BS=["terms","privacy"],U_=He.enum(BS),tc=["recharge","reserve","consume","reserve_refund","refund","refund_release","reward","admin_adjust"],Wm=He.enum(tc),FS=["usage_log","order","invitation","admin"],zm=He.enum(FS),nc=["first_inviter","first_invitee","subsequent_inviter"],Vm=He.enum(nc),oc=["success","error","canceled","anomaly"],Km=He.enum(oc),rc=["open","replied","closed"],Ym=He.enum(rc),ic=["billing","technical","account","other"],Jm=He.enum(ic),sc=["low","normal","high"],Xm=He.enum(sc),US=["user","admin"],Qm=He.enum(US),jS=["pending","published","rejected","removed"],Er=He.enum(jS),ac=["activity","published"],Zm=He.enum(ac),Ni=["spam","abuse","explicit","illegal","privacy","other"],eu=He.enum(Ni),HS=["none","minor","major","critical"],tu=He.enum(HS);import{z as Go}from"zod";var qS=["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"],GS=Go.enum(qS),nu=Go.object({error:Go.object({code:GS,message:Go.string(),details:Go.unknown().optional(),requestId:Go.string().optional()})});var ou={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 Wo}from"zod";var WS=Wo.string().trim().min(1),cc=WS.pipe(Wo.url()),zS=Wo.object({name:Wo.string().trim().min(1),description:Wo.string().trim().min(1),url:cc}),z_=Wo.array(zS);function ru(e){return`codeflow-cli/${e.cliVersion} (${e.platform} ${e.release}; ${e.arch}) node/${e.nodeVersion}`}function zo(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 lc=1e8;var J_=dn.object({id:dn.coerce.number().int().positive()}),iu=100,su=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)}),au=(e=dn.string().trim())=>e.nullable().optional().transform(t=>t==null||t.length===0?null:t);import{z as ce}from"zod";var ao=ce.email().max(254).toLowerCase(),Ot=8,Mr=ce.string().min(Ot).max(128),Ir=ce.string().min(1).max(128),Kt=32,mc=ce.string().trim().min(1).max(Kt),uc=ce.string().trim().min(1).max(254),Z_=ce.object({email:ao}),e0=ce.object({username:mc,email:ao,password:Mr,code:ce.string().min(4).max(8),inviteCode:ce.string().trim().min(1).max(32).optional()}),t0=ce.object({account:uc,password:Ir}),n0=ce.object({email:ao,code:ce.string().min(4).max(8),password:Mr}),o0=ce.object({oldPassword:Ir,newPassword:Mr}),r0=ce.object({email:ao}),i0=ce.object({email:ao,code:ce.string().min(4).max(8),password:Ir}),cu=ce.object({username:ce.string(),email:ce.string(),avatarUrl:ce.string().nullable()}),Vo=ce.object({accessToken:ce.string(),user:cu}),lu=ce.discriminatedUnion("status",[Vo.extend({status:ce.literal("ok")}),ce.object({status:ce.literal("totp_required"),ticket:ce.string()})]),mu=ce.object({user:cu}),dc=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()}),VS=ce.object({id:ce.number().int(),ip:ce.string(),userAgent:ce.string().nullable(),device:dc.nullable(),loginAt:ce.string(),lastActiveAt:ce.string(),expiresAt:ce.string(),current:ce.boolean()}),uu=ce.object({sessions:ce.array(VS)});import{z as ke}from"zod";var Ko=ke.string().trim().length(6),KS=ke.string().trim().min(10).max(20),Li=ke.string().trim().min(1).max(64),Oi=ke.record(ke.string(),ke.unknown()),c0=ke.object({ticket:ke.string().min(1),code:Ko}),l0=ke.object({ticket:ke.string().min(1),code:KS}),m0=ke.object({code:Ko.optional()}),u0=ke.object({code:Ko}),du=ke.object({secret:ke.string(),otpauthUri:ke.string()}),pc=ke.object({recoveryCodes:ke.array(ke.string())}),YS=ke.object({id:ke.number().int(),name:ke.string(),createdAt:ke.string(),lastUsedAt:ke.string().nullable()}),pu=ke.object({totp:ke.object({enabled:ke.boolean(),enabledAt:ke.string().nullable(),recoveryCodesRemaining:ke.number().int()}),passkeys:ke.array(YS)}),d0=ke.object({name:Li,response:Oi}),p0=ke.object({name:Li}),f0=ke.object({response:Oi});import{z as Ne}from"zod";var S0=Ne.object({account:uc,password:Ir}),JS=Ne.object({totp:Ne.boolean(),passkeys:Ne.boolean()}),x0=Ne.discriminatedUnion("status",[Ne.object({status:Ne.literal("totp_required"),ticket:Ne.string()}),Ne.object({status:Ne.literal("setup_required"),ticket:Ne.string(),missing:JS})]),T0=Ne.object({ticket:Ne.string().min(1)}),w0=Ne.object({ticket:Ne.string().min(1),code:Ko}),k0=Ne.object({ticket:Ne.string().min(1),name:Li,response:Oi}),v0=Ne.object({ticket:Ne.string().min(1),code:Ko.optional()}),fu=Ne.object({username:Ne.string(),email:Ne.string(),avatarUrl:Ne.string().nullable()}),C0=Ne.object({accessToken:Ne.string(),admin:fu}),R0=Ne.object({admin:fu});import{z as fc}from"zod";var M0=fc.object({siteName:fc.string().trim().min(1).max(64),siteDescription:fc.string().trim().max(200).optional(),siteOrigin:cc,username:mc,email:ao,password:Mr});import{z as $e}from"zod";var gu={orderNo:$e.string(),amountCny:$e.number().int(),status:jm,credited:$e.boolean(),refundedAmountCny:$e.number().int(),succeededRefundCny:$e.number().int(),pendingRefundCny:$e.number().int(),createdAt:$e.string()},Nr=$e.object({...gu,quota:$e.number(),refundedQuota:$e.number()}),Lr=$e.object({...gu,planName:$e.string(),renewal:$e.boolean(),grantedDurationDays:$e.number().int()}),Di=$e.object({order:Nr.pick({orderNo:!0,amountCny:!0,quota:!0}),qrCode:$e.string()}),Or=$e.object({order:Lr.pick({orderNo:!0,amountCny:!0,planName:!0,grantedDurationDays:!0}),qrCode:$e.string()}),hu=$e.object({id:$e.number().int(),amountCny:$e.number().int(),status:Hm,refundTradeNo:$e.string().nullable(),reason:$e.string().nullable(),rejectReason:$e.string().nullable(),createdAt:$e.string()});function yu(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 gc=Yt.object({kind:Yt.literal("user"),username:Yt.string(),avatarUrl:Yt.string().nullable(),points:Yt.number().int()}),hc=Yt.object({kind:Yt.literal("admin"),username:Yt.string(),avatarUrl:Yt.string().nullable()}),Yo=Yt.discriminatedUnion("kind",[gc,hc]),bu=Yt.object({kind:Qm,username:Yt.string()});var $i=ut.object({id:ut.number().int(),title:ut.string(),category:Jm,priority:Xm,status:Ym,createdAt:ut.string(),updatedAt:ut.string()}),Su=$i.pick({id:!0}),xu=25*1024*1024,Tu=5,wu=ut.object({id:ut.number().int(),fileName:ut.string(),fileSize:ut.number().int(),contentType:ut.string()}),ku=wu.pick({id:!0,fileSize:!0}),XS=ut.object({id:ut.number().int(),author:Yo,content:ut.string(),attachments:ut.array(wu),createdAt:ut.string()}),vu=ut.object({ticket:$i,messages:ut.array(XS)});import{z as Dr}from"zod";var yc=Dr.object({id:Dr.number().int(),title:Dr.string(),content:Dr.string(),level:Gm,publishedAt:Dr.string()});import{z as Ye}from"zod";var bc=100,Cu=Ye.object({groups:Ye.array(Ye.object({title:Ye.string(),items:Ye.array(Ye.object({slug:Ye.string(),title:Ye.string()}))}))}),Ru=Ye.object({title:Ye.string(),markdown:Ye.string(),images:Ye.record(Ye.string(),Ye.object({width:Ye.number().int(),height:Ye.number().int()}))}),_u=Ye.object({slug:Ye.string(),title:Ye.string(),anchor:Ye.string().nullable(),snippet:Ye.string()});function Pu(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-")}function Sc(e){try{return decodeURIComponent(e)}catch{return e}}function Bi(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:Sc(e.slice(t+1))}}import{z as ot}from"zod";function Le(e){return e.toLocaleString("en-US")}function Gn(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 co(e){return(e/1e3).toFixed(2)}function Jo(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 Fi(e,t){return`${e}******${t}`}var xc=ot.object({inputPricePerMillionTokens:ot.number(),outputPricePerMillionTokens:ot.number(),cachedInputPricePerMillionTokens:ot.number(),cacheWritePricePerMillionTokens:ot.number()});var QS=ot.number().int().nonnegative(),ZS=ot.discriminatedUnion("kind",[xc.extend({kind:ot.literal("price"),inputTokensOver:QS}),ot.object({kind:ot.literal("multiplier"),param:ot.string(),value:ot.string(),multiplier:ot.number()})]),Au=ot.array(ZS);function ex(e){return e.kind==="price"}function Eu(e){return e.kind==="multiplier"}function Mu(e){return e>=1e6&&e%1e5===0?`${e/1e6}M`:e>=1e3&&e%1e3===0?`${e/1e3}k`:Le(e)}function $r(e){return e===null?"\u57FA\u7840":"\u6269\u5C55"}function Tc(e){return`> ${Mu(e)}`}function Iu(e,t){let n=t.filter(ex).sort((r,i)=>r.inputTokensOver-i.inputTokensOver),o=n[0];return o===void 0?[{name:$r(null),range:null,price:e}]:[{name:$r(null),range:`\u2264 ${Mu(o.inputTokensOver)}`,price:e},...n.map(r=>({name:$r(r.inputTokensOver),range:Tc(r.inputTokensOver),price:r}))]}var tx=ot.object({value:ot.string(),multiplier:ot.number()}),Nu=ot.array(tx);function Lu(e){return Du(e.map(t=>t.multiplier))}function Ou(e,t){return Du([e,...t.map(n=>n.multiplier)])}function Du(e){return Number(e.reduce((t,n)=>t*n,1).toFixed(4))}import{z as lo}from"zod";var nx=lo.object({provider:Fm,pageUrl:lo.string(),indicator:tu,incidents:lo.array(lo.object({title:lo.string()}))}),$u=lo.object({providers:lo.array(nx)}),ox={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 Bu(e){return e.filter(t=>t.indicator!=="none"||t.incidents.length>0)}function Fu(e){return e.indicator==="none"?{label:"\u4E8B\u4EF6\u5904\u7406\u4E2D",tone:"warning"}:ox[e.indicator]}import{z as mo}from"zod";var Br=25*1024*1024,Uu=20,ju=5;var wc="/api/media/";function Hu(e){return`${wc}${e}`}var qu=mo.object({width:mo.number().int(),height:mo.number().int()}),Ui=mo.record(mo.string(),qu),Gu=mo.object({id:mo.number().int(),image:qu.nullable()}),Wu=String.raw`([1-9]\d{0,14})`,nP=new RegExp(String.raw`^${wc}${Wu}$`),zu=new RegExp(String.raw`(!?)\[((?:\\.|[^\\\]\n])*)\]\(${wc}${Wu}(?:\s+"[^"\n]*")?\)`,"g");function Vu(e,t,n){return{id:Number(n),image:e==="!",name:t.replace(/\\(.)/g,"$1")}}function Ku(e){return[...e.matchAll(zu)].map(([,t="",n="",o=""])=>Vu(t,n,o))}function kc(e,t){return e.replace(zu,(n,o,r,i)=>t(Vu(o,r,i)))}import{z as dt}from"zod";import{z as N}from"zod";var uo=100,ji=2e4,vc=5e3,Hi=500,qi=64,rx=new RegExp("\\p{Cc}","u"),ix=new RegExp("(?![\\n\\t])\\p{Cc}","u");function Cc(e){return N.string().trim().max(e).refine(t=>!rx.test(t))}function Rc(e){return N.string().trim().max(e).refine(t=>!ix.test(t))}var mP=N.object({categoryId:N.number().int().positive(),title:Cc(uo).min(1),content:Rc(ji).min(1)}),uP=N.object({categoryId:N.number().int().positive().nullable(),title:Cc(uo),content:Rc(ji)}),dP=N.object({content:Rc(vc).min(1),replyToId:N.number().int().positive().optional()}),pP=N.object({reason:eu,detail:au(Cc(Hi))}),fP=su.extend({sort:Zm,categoryId:N.coerce.number().int().positive().optional(),q:N.string().trim().min(1).max(qi).optional(),author:N.string().trim().min(1).max(Kt).optional()}),_c=N.object({id:N.number().int(),name:N.string(),description:N.string()}),Gi=_c.pick({id:!0,name:!0}),Fr=N.object({id:N.number().int(),title:N.string()}),Xo=N.object({id:N.number().int(),title:N.string().nullable()}),gP=N.object({posts:N.array(N.object({id:N.number().int(),lastModified:N.string()})),users:N.array(N.string()),staff:N.array(N.string())}),Pc=N.object({id:N.number().int(),title:N.string(),category:Gi,author:Yo,commentCount:N.number().int(),viewCount:N.number().int(),likeCount:N.number().int(),lastActivityAt:N.string()}),Ac=N.object({id:N.number().int(),title:N.string(),content:N.string(),images:Ui,category:Gi,author:Yo,status:Er,reviewReason:N.string().nullable(),commentCount:N.number().int(),viewCount:N.number().int(),likeCount:N.number().int(),coverUrl:N.string().nullable(),createdAt:N.string(),publishedAt:N.string().nullable(),editedAt:N.string().nullable(),liked:N.boolean(),bookmarked:N.boolean()}),Yu={id:N.number().int(),author:Yo,content:N.string(),images:Ui,status:Er,reviewReason:N.string().nullable(),likeCount:N.number().int(),liked:N.boolean(),createdAt:N.string()},Ec=N.object({...Yu,replyTo:N.object({id:N.number().int(),author:bu}).nullable()}),Wi=N.object({...Yu,floor:N.number().int().nullable(),replyCount:N.number().int(),replies:N.array(Ec)}),Mc=N.object({likeCount:N.number().int()}),Ju=Ac.pick({id:!0}),Xu=Wi.pick({id:!0}),sx=N.object({status:N.enum(["pending","rejected","removed"]),reviewReason:N.string().nullable()}),Ic=N.object({review:sx.nullable()}),Ur=N.object({id:N.number().int(),title:N.string(),category:Gi,status:Er,reviewReason:N.string().nullable(),commentCount:N.number().int(),viewCount:N.number().int(),likeCount:N.number().int(),createdAt:N.string(),publishedAt:N.string().nullable()}),zi=N.object({id:N.number().int(),content:N.string(),post:Xo,floorId:N.number().int(),status:Er,reviewReason:N.string().nullable(),likeCount:N.number().int(),createdAt:N.string()}),Nc=N.object({id:N.number().int(),category:Gi.nullable(),title:N.string(),content:N.string(),images:Ui,createdAt:N.string()}),Qu=N.object({posts:N.array(Ur),drafts:N.number().int()}),Zu=Nc.pick({id:!0}),ed=N.object({muted:N.object({reason:N.string(),until:N.string().nullable()}).nullable()});var ax=dt.object({posts:dt.number().int(),comments:dt.number().int(),likesReceived:dt.number().int()}),cx=dt.object({start:dt.string(),end:dt.string(),days:dt.array(dt.object({day:dt.string(),count:dt.number().int()}))}),lx=dt.object({posts:dt.array(Ur),comments:dt.array(zi)}),td={joinedAt:dt.string(),stats:ax,activity:cx,overview:lx},nd=dt.object({identity:gc,...td}),od=dt.object({identity:hc,...td});import{z as q}from"zod";var tt={id:q.number().int(),read:q.boolean(),createdAt:q.string()},jr=q.object({floorId:q.number().int()}),rd=q.object({username:q.string()}),id=q.discriminatedUnion("kind",[q.object({...tt,kind:q.literal("post_commented"),post:Fr,comment:jr,actor:rd}),q.object({...tt,kind:q.literal("comment_replied"),post:Xo,comment:jr,actor:rd}),q.object({...tt,kind:q.literal("post_approved"),post:Fr}),q.object({...tt,kind:q.literal("post_rejected"),post:Fr,reason:q.string()}),q.object({...tt,kind:q.literal("post_removed"),post:Fr,reason:q.string()}),q.object({...tt,kind:q.literal("comment_approved"),post:Xo,comment:jr}),q.object({...tt,kind:q.literal("comment_rejected"),post:Xo,comment:jr,reason:q.string()}),q.object({...tt,kind:q.literal("comment_removed"),post:Xo,comment:jr,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:Qa,amountCny:q.number().int()})}),q.object({...tt,kind:q.literal("refund_rejected"),refund:q.object({orderNo:q.string(),orderType:Qa}),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:dc.nullable()})]),sd=q.object({unread:q.boolean()});var ad="Asia/Shanghai",mx="+08:00";function ux(e){return new Date(new Date(e).getTime()+288e5)}function dx(e=Date.now()){let t=ux(e);return{day:t.toISOString().slice(0,10),hour:t.getUTCHours()}}function Lc(e=Date.now()){return dx(e).day}function Oc(e=Lc()){return new Date(`${e}T00:00:00${mx}`)}function Wn(e,t){let n=new Date(`${e}T00:00:00Z`);return new Date(n.getTime()+t*864e5).toISOString().slice(0,10)}var px=new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium",timeZone:ad}),fx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"long",timeZone:ad});function K(e){return px.format(new Date(e))}function Hr(e){return fx.format(new Date(e))}var[gx,...hx]=[{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 Vi(e){let t=1,n=gx;for(let o of hx){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 Ki(e){let t=Vi(e);return`Lv.${t.level} ${t.name}`}function Yi(e){let t=Vi(e);return t.next===null?"\u5DF2\u8FBE\u6700\u9AD8\u7B49\u7EA7":`\u8DDD Lv.${t.level+1} \u8FD8\u5DEE ${t.next-e} \u79EF\u5206`}var Ji="\u7BA1\u7406\u5458",qr={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"},Qo={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"},Dc={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 cd(e,t){return t===null?e:`${e}\uFF0C\u539F\u56E0\uFF1A${t}`}function $c(e,t){return t.status==="published"?null:cd(e[t.status],t.reviewReason)}function ld(e){return cd(Dc[e.status],e.reviewReason)}var Xi="\u8BE5\u5E16\u5B50\u6682\u4E0D\u53EF\u89C1",yx=4;function md(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 ud(t,1)}function ud(e,t){return t<yx?e.map(n=>({...n,children:ud(n.children,t+1)})):e.flatMap(n=>[{...n,children:[]},...dd(n)])}function dd(e){return e.children.flatMap(t=>[{reply:t.reply,mention:e.reply.author,children:[]},...dd(t)])}function Bc(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 Fc(e){return Math.round(e*100)}function pd(e){return e/100}function fd(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 fd(e,t,2)}function Zo(e,t){return fd(e,t,6)}var hd={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 gd(e){return e==="subscription"?{kind:"subscription"}:{kind:"recharge"}}function Uc(e){return e.title===null?"":`\u300C${e.title}\u300D\u4E0B\u7684`}function jc(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?Xi:`\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:`${Uc(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:`${Uc(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:`${Uc(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:gd(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:gd(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${zo(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 Gr(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+=Gr(n.tokens);break;case"text":t+="tokens"in n&&n.tokens!==void 0?Gr(n.tokens):n.text;break}return t}function Hc(e){if(e===void 0)return[];let t=[];for(let n of e)switch(n.type){case"paragraph":case"heading":t.push(Gr(n.tokens));break;case"text":t.push("tokens"in n&&n.tokens!==void 0?Gr(n.tokens):n.text);break;case"code":case"html":t.push(n.text);break;case"blockquote":t.push(...Hc(n.tokens));break;case"list":n.items.forEach(o=>t.push(...Hc(o.tokens)));break;case"table":[...n.header,...n.rows.flat()].forEach(o=>t.push(Gr(o.tokens)));break}return t}function yd(e){return Hc(e).join(" ").replace(/\s+/g," ").trim()}var bx=[{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 Sx(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 bd(e){return e<365?`${Dt(e)} \u5929`:`${Dt(e/365)} \u5E74`}function xx(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 Tx(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 wx(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 kx=[...bx.map(e=>({min:e.tokens/10,max:e.tokens*1e4,suffix:t=>`\u7EA6\u4E3A${e.name}\u7684 ${Sx(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 ${xx(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 ${bd(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 ${Tx(e)}`},{min:4500,max:1/0,suffix:e=>`\u82E5\u523B\u6210\u6BCF\u679A 30 \u5B57\u7684\u79E6\u6C49\u7AF9\u7B80\uFF0C\u603B\u91CD\u7EA6 ${wx(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 ${bd(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 Sd(e){let{tokens:t,scope:n,range:o}=e;if(t<=0)return null;let r=kx.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 Rn(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=Rn({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"}}),BP=$t({recharge:"\u5145\u503C",subscription:"\u8BA2\u9605"}),Qi=Rn({pending:{label:"\u5F85\u5904\u7406",tone:"warning"},issued:{label:"\u5DF2\u5F00\u5177",tone:"success"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"}}),FP=Rn({active:{label:"\u6B63\u5E38",tone:"success"},disabled:{label:"\u7981\u7528",tone:"danger"}}),qc=$t({subscription_first:"\u8BA2\u9605\u4F18\u5148",balance_first:"\u4F59\u989D\u4F18\u5148",subscription_only:"\u4EC5\u8BA2\u9605",balance_only:"\u4EC5\u4F59\u989D"}),Gc=$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"}),xd=Ja.map(e=>({value:e,label:qc(e)})),Wc=$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"}),Td=$t({usage_log:"\u7528\u91CF",order:"\u8BA2\u5355",invitation:"\u9080\u8BF7",admin:"\u7BA1\u7406\u5458"}),wd=Rn({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"}}),Zi=Rn({success:{label:"\u6210\u529F",tone:"success"},error:{label:"\u5931\u8D25",tone:"danger"},canceled:{label:"\u53D6\u6D88",tone:"neutral"},anomaly:{label:"\u5F02\u5E38",tone:"warning"}}),kd=$t({"openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"}),po=$t({special:"\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968",general:"\u589E\u503C\u7A0E\u666E\u901A\u53D1\u7968"}),fo=$t({special:"\u4E13\u7968",general:"\u666E\u7968"}),es=$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=Rn({info:{label:"\u4FE1\u606F",tone:"neutral"},success:{label:"\u6210\u529F",tone:"success"},warning:{label:"\u8B66\u544A",tone:"warning"},error:{label:"\u91CD\u8981",tone:"danger"}}),zc=Rn({open:{label:"\u5F85\u5904\u7406",tone:"warning"},replied:{label:"\u5DF2\u56DE\u590D",tone:"success"},closed:{label:"\u5DF2\u5173\u95ED",tone:"neutral"}}),ts=$t({billing:"\u8BA1\u8D39",technical:"\u6280\u672F",account:"\u8D26\u53F7",other:"\u5176\u4ED6"}),Vc=Rn({low:{label:"\u8F83\u4F4E",tone:"neutral"},normal:{label:"\u666E\u901A",tone:"neutral"},high:{label:"\u7D27\u6025",tone:"danger"}}),vd=$t({openai:"OpenAI",anthropic:"Anthropic"}),go=Rn({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"}}),Cd=$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"}),Rd=$t({activity:"\u6700\u65B0\u56DE\u590D",published:"\u6700\u65B0\u53D1\u5E03"});function Pt(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 rs(e){return`${e.name} \xD7${e.multiplier}`}var ns=10080,os=1440;function _d(e){if(e%ns===0){let t=e/ns;return t===1?"\u6BCF\u5468\u9650\u989D":`${t} \u5468\u9650\u989D`}if(e%os===0){let t=e/os;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 vx(e){if(e%ns===0){let t=e/ns;return t===1?"\u6BCF\u5468":`\u6BCF ${t} \u5468`}if(e%os===0){let t=e/os;return t===1?"\u6BCF\u5929":`\u6BCF ${t} \u5929`}return e%60===0?`\u6BCF ${e/60} \u5C0F\u65F6`:`\u6BCF ${e} \u5206\u949F`}function Pd(e,t){return e.windows.map(n=>`${vx(n.durationMinutes)} ${Te(n.quota,t)}`)}function Kc(e){return Math.min(100,Math.floor(e.used/e.quota*100))}function Yc(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 Jc={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"]},Ad={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"};var Ed=e=>e===null?"\u4E2A\u4EBA":"\u5355\u4F4D",Md="\u53D1\u7968\u5F00\u5177\u540E\u65E0\u6CD5\u7EA2\u51B2\uFF0C\u8BF7\u4ED4\u7EC6\u6838\u5BF9\u5F00\u7968\u4FE1\u606F";var Rx=3e4,_x=ru({cliVersion:Vt,platform:process.platform,release:Cx(),arch:process.arch,nodeVersion:process.versions.node});async function Id(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",_x);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??Rx),redirect:"follow"})}catch(r){let i=URL.canParse(e)?new URL(e).origin:e;throw new F(`\u65E0\u6CD5\u8FDE\u63A5 ${i}\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u7AD9\u70B9\u5730\u5740`,{exitCode:Em,cause:r})}}async function Nd(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 Id(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Nd(n)};let o=await n.text(),r=null;if(o!=="")try{r=JSON.parse(o)}catch(i){throw new F(`${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 Ld(e,t={}){let n=await Id(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Nd(n),bytes:null};let o=new Uint8Array(await n.arrayBuffer());return{status:n.status,ok:!0,headers:n.headers,data:null,bytes:o}}function Px(e,t){let n=nu.safeParse(t);if(!n.success)return new F(`\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${e}\uFF09`);let{code:o,message:r}=n.data.error,i=o==="unauthorized"||o==="token_expired"?io:void 0;return new F(ou[o]??r,i?{exitCode:i}:{})}function sn(e){if(!e.ok)throw Px(e.status,e.data)}var $d="cf_refresh",Bd="cf_device",Od=6e4;function Dd(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:Dd(t,$d)??e.refresh,device:Dd(t,Bd)??e.device}}function is(e){let t=[];return e.refresh&&t.push(`${$d}=${e.refresh}`),e.device&&t.push(`${Bd}=${e.device}`),t.length>0?{cookie:t.join("; ")}:{}}function Ax(e){let t=e.split(".")[1];if(t===void 0)throw new F("\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 F("\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 F("\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 F("\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:Ax(n.accessToken),username:n.user.username,email:n.user.email,site:e};return Pr(r=>{r.session=o,t.device&&(r.device={site:e,cookie:t.device})}),o}function Xc(e){let{device:t}=wt();return t!==null&&t.site===e?t.cookie:null}async function Fd(e,t,n){let o={refresh:null,device:Xc(e)},r=await Jt(`${e}/api/auth/login`,{json:{account:t,password:n},headers:is(o)});sn(r);let i=lu.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 Ud(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:is(t)});sn(s);let a=Vo.parse(s.data);return Vr(e,zr(t,s.headers),a)}function ss(){Pr(e=>{e.session=null})}async function Ex(e){let t={refresh:e.refreshCookie,device:Xc(e.site)},n=await Jt(`${e.site}/api/auth/refresh`,{method:"POST",headers:is(t)});if(n.status===401||n.status===403)throw ss(),new F("\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",{exitCode:io});sn(n);let o=Vo.parse(n.data);return Vr(e.site,zr(t,n.headers),o)}async function Kr(e=!1){let t=$m();return!e&&Date.now()<t.accessExpiresAt-Od?t:Ii(async()=>{let n=Mi().session;if(!n)throw new F("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:io});return(n.refreshCookie!==t.refreshCookie||n.accessToken!==t.accessToken)&&Date.now()<n.accessExpiresAt-Od?n:Ex(n)})}async function as(){let e=wt().session;if(!e)return;let t=await Jt(`${e.site}/api/auth/logout`,{method:"POST",headers:is({refresh:e.refreshCookie,device:Xc(e.site)})});ss(),sn(t)}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 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 Qc(e,t={}){let n=await Kr(),o=i=>Ld(`${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 cs(e,t={}){return(await Qc(e,t)).bytes}function Ue(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 Mx=ht.object({siteName:ht.string(),apiLines:ht.array(ht.object({name:ht.string(),description:ht.string(),url:ht.string()})),quotaPerUsd:ht.number(),ticketAutoCloseMinutes:ht.number(),legal:ht.object({termsConfigured:ht.boolean(),privacyConfigured:ht.boolean()}),siteOrigin:ht.string().nullable()});function Be(e,t){return fn(Mx,`${e}/api/site-config`,{...t===void 0?{}:{timeoutMs:t}})}var Ix=ht.object({content:ht.string(),configured:ht.boolean()});function jd(e,t){return fn(Ix,`${e}/api/agreements/${t}`)}var Nx=1e4;function Hd(){if(process.env.CODEFLOW_SITE)return null;let{session:e}=wt();return e!==null&&e.site!==Pi?e.site:null}async function qd(e){let t;try{({siteOrigin:t}=await Be(e,Nx))}catch(o){throw new F(Se(o),{...o instanceof F?{exitCode:o.exitCode}:{},hint:`\u767B\u5F55\u72B6\u6001\u8BB0\u5728 ${e}\uFF0C\u82E5\u8BE5\u7AD9\u70B9\u5DF2\u505C\u7528\uFF0C\u8BF7\u5220\u9664 ${Ei()} \u540E\u91CD\u65B0\u767B\u5F55`,cause:o})}let n=t;n!==e&&await Ii(async()=>{Mi(),Pr(o=>{o.session?.site===e&&(o.session.site=n),o.device?.site===e&&(o.device.site=n)})})}import{existsSync as Ox,rmSync as Dx}from"fs";import{spawn as Lx}from"child_process";function Yr(e,t={}){return new Promise((n,o)=>{let r=Lx("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 F(`\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 F(`npm ${e.join(" ")} \u9000\u51FA\u7801 ${c??"null"}`,{...l===""?{}:{hint:l}}))}),t.background===!0&&(r.stdout.unref(),r.stderr.unref(),r.unref())})}async function Gd(e){let t=[],n=async(o,r)=>{try{await r(),e.done(o)}catch(i){t.push(`${o}\uFF1A${Se(i)}`),e.failed(o)}};return await n("\u9000\u51FA\u767B\u5F55",()=>as()),await n("\u5220\u9664\u672C\u5730\u6587\u4EF6",()=>{let o=Cn();Ox(o)&&Dx(o,{recursive:!0,force:!0})}),await n("\u5378\u8F7D\u672C\u7A0B\u5E8F",async()=>{await Yr(["uninstall","-g",jo])}),t}import{z as Jr}from"zod";var $x=Jr.object({line:Jr.object({name:Jr.string(),url:Jr.string()}).nullable(),lastUpdateCheckAt:Jr.number().nullable()}),Wd=Ai($x,{line:null,lastUpdateCheckAt:null},Im,"\u672C\u5730\u914D\u7F6E","\u91CD\u65B0\u8FD0\u884C"),ho=Wd.load,ls=Wd.update;var Bx=1440*60*1e3;async function zd(){let e=(await Yr(["view",jo,"version"])).trim();if(e==="")throw new F(`npm \u6CA1\u6709\u62A5\u51FA ${jo} \u7684\u7248\u672C`);return e}async function Vd(e,t){return await Yr(["install","-g",`${jo}@${e}`],{background:t}),e}async function Kd(){let e=await zd();return e===Vt?null:await Vd(e,!1)}function Fx(){let e=Date.now(),t=ho().lastUpdateCheckAt;return t!==null&&e-t<Bx?!1:(ls(n=>{n.lastUpdateCheckAt=e}),!0)}async function Yd(){if(!Fx())return null;let e;try{e=await zd()}catch{return null}return e===Vt?null:await Vd(e,!0)}import{Box as HR,render as qR,useInput as GR}from"ink";import{useEffect as Pm,useRef as WR}from"react";var Jd=e=>A(mt(yc),Ue("/announcements",{...e})),Xd=()=>A(yc.nullable(),"/announcements/unread"),ms=e=>A(se,`/announcements/${e}/read`,{method:"POST"});import{Box as Qd,useWindowSize as Ux}from"ink";import{Children as jx}from"react";import{jsx as Zd}from"react/jsx-runtime";var Hx=1,Zc=1,X=1;function j(){let{columns:e,rows:t}=Ux();return{width:Math.max(1,e-Hx*2),columns:e,rows:t}}function ep({height:e,children:t}){return Zd(Qd,{flexDirection:"column",height:e,justifyContent:"space-between",children:jx.toArray(t).map((n,o)=>Zd(Qd,{flexDirection:"column",flexShrink:0,children:n},o))})}import{useInput as tp}from"ink";import{createContext as ps,useCallback as tl,useContext as qx,useEffect as np,useMemo as op,useRef as ds,useState as Gx}from"react";import{jsx as us}from"react/jsx-runtime";var fs=ps(null),nl=ps(null),ol=ps(null);function el(){let[e,t]=Gx(!1),n=ds(0),o=tl(()=>(n.current+=1,t(!0),()=>{n.current-=1,n.current===0&&t(!1)}),[]);return op(()=>({held:e,acquire:o}),[e,o])}var Vn={screen:0,panel:10,input:20},rl=ps(null);function rp({children:e}){let t=el(),n=el(),o=el(),r=ds([]),i=ds(0),s=tl(l=>{let u={...l,seq:i.current+=1};return r.current.push(u),()=>{r.current=r.current.filter(m=>m!==u)}},[]),a=tl(()=>{r.current.reduce((u,m)=>u===null||m.layer>u.layer||m.layer===u.layer&&m.seq>u.seq?m:u,null)?.handler()},[]);tp((l,u)=>{u.escape&&a()});let c=op(()=>({push:s,fire:a}),[s,a]);return us(fs.Provider,{value:t,children:us(nl.Provider,{value:n,children:us(ol.Provider,{value:o,children:us(rl.Provider,{value:c,children:e})})})})}function yo(e){let t=qx(e);if(!t)throw new Error("\u952E\u76D8\u94A9\u5B50\u5FC5\u987B\u5728 KeyboardProvider \u5185\u4F7F\u7528");return t}function il(e,t){let{acquire:n}=yo(e);np(()=>{if(t)return n()},[t,n])}function gs(e){il(fs,e)}function Re(e){il(nl,e)}function ip(e){il(ol,e)}function hs(){return yo(nl).held}function ys(){return yo(fs).held}function sp(){return yo(ol).held}function G(e,t=!0){let n=yo(fs).held;tp(e,{isActive:t&&!n})}function ap(){return yo(rl).fire}function gn(e,{isActive:t=!0,layer:n=Vn.screen}={}){let{push:o}=yo(rl),r=ds(e);r.current=e,np(()=>{if(t)return o({handler:()=>r.current(),layer:n})},[t,n,o])}import{measureElement as Wx}from"ink";import{PassThrough as zx}from"stream";import{createContext as Vx,useCallback as Kx,useContext as Yx,useEffect as up,useRef as bs}from"react";import{jsx as iT}from"react/jsx-runtime";var Jx="\x1B[?1000h\x1B[?1003h\x1B[?1006h",Xx="\x1B[?1006l\x1B[?1003l\x1B[?1000l",Qx=27,Zx=91,eT=60,cp=77,lp=109,mp=20,tT=64,nT=32,oT=20;function rT(e){let t=[],n=[],o=0;for(;o<e.length;){let r=e[o];if(r===void 0)break;if(r!==Qx){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!==Zx){n.push(r),o+=1;continue}if(s===cp){if(o+6>e.length)break;o+=6;continue}if(s!==eT){n.push(r),o+=1;continue}let a=o+3,c;for(;a<e.length&&a-o<mp;){let d=e[a];if(d===cp||d===lp){c=d;break}a+=1}if(c===void 0){if(a-o<mp)break;n.push(r),o+=1;continue}let l=e.subarray(o+3,a).toString("latin1").split(";");if(o=a+1,c===lp||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&tT)!==0?{row:p,column:m,kind:"wheel",delta:(u&1)===0?-1:1}:{row:p,column:m,kind:(u&nT)!==0?"move":"press"})}return{events:t,clean:Buffer.from(n),pending:e.subarray(o)}}function dp(e,t){let n=new Set,o=new zx,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=rT(Buffer.concat([r,p]));r=d.pending,d.clean.length>0&&o.write(d.clean);for(let S of d.events)for(let b of n)b(S);r.length>0&&(i=setTimeout(s,oT))},c=()=>{t.write(Xx)},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(Jx);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 pp=Vx(null);function fp({subscribe:e,children:t}){let n=bs(new Set).current,o=bs(null),r=Kx(i=>(n.add(i),()=>{n.delete(i)}),[n]);return up(()=>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=Wx(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]),iT(pp.Provider,{value:r,children:t})}function rt(e){let t=Yx(pp);if(t===null)throw new Error("useMouseRegion \u5FC5\u987B\u5728 MouseProvider \u5185\u4F7F\u7528");let n=bs(null),o=bs(e);return o.current=e,up(()=>t({node:n,handlers:o}),[t]),n}import{useApp as sT}from"ink";import{createContext as aT,useCallback as bo,useContext as cT,useEffect as sl,useRef as xs,useState as Qr}from"react";var kt=[{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"}],gp="usage",Xr=e=>kt.findIndex(t=>t.id===e),Ss=e=>Xr(e)>=0;import{jsx as mT}from"react/jsx-runtime";var lT=5e3,yp=aT(null),bp=e=>({id:e,params:void 0}),hp=()=>wt().session===null?[{id:"home",params:void 0}]:[bp(gp)];function O(){let e=cT(yp);if(!e)throw new Error("useNav \u5FC5\u987B\u5728 NavProvider \u5185\u4F7F\u7528");return e}function Sp({ctx:e,children:t}){let n=sT(),[o,r]=Qr(hp),[i,s]=Qr(0),[a,c]=Qr([]),l=xs({announcementsChecked:!1,announcementsShown:!1}).current,u=xs(new WeakMap).current,m=bo((R,...I)=>{r(E=>[...E,{id:R,params:I[0]}])},[]),p=bo(()=>{r(R=>R.length>1?R.slice(0,-1):R),s(R=>R+1)},[]),d=bo(R=>{r([bp(R)]),s(I=>I+1)},[]),S=bo(()=>{r(hp()),s(R=>R+1)},[]),b=bo(()=>s(R=>R+1),[]),g=bo((R,I)=>{c(E=>[...E,{tone:R,message:I}])},[]),T=bo(()=>c(R=>R.slice(1)),[]),x=a[0]??null;sl(()=>{if(x===null)return;let R=setTimeout(T,lT);return()=>clearTimeout(R)},[x,T]);let C=o[o.length-1];if(C===void 0)throw new Error("\u5BFC\u822A\u6808\u4E3A\u7A7A");let y=u.get(C);y===void 0&&(y=new Map,u.set(C,y));let h={ctx:e,current:C,depth:o.length,push:m,pop:p,select:d,home:S,reload:b,toast:g,message:x,dismissToast:T,exit:n.exit,revision:i,gate:l,retained:y};return mT(yp.Provider,{value:h,children:t})}function Me(e,t){let{retained:n}=O(),[o,r]=Qr(()=>e!==void 0&&n.has(e)?n.get(e):t());return sl(()=>{e!==void 0&&n.set(e,o)},[n,e,o]),[o,r]}function Q(e,t){let[n,o]=Qr({phase:"loading"}),r=xs(t);r.current=t;let i=xs(0);return sl(()=>{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:Se(a),hint:a instanceof F?a.hint:void 0})})},e),n}import{Box as $s,Text as wo,useInput as tw}from"ink";import{Box as ni,Text as rr}from"ink";import{Lexer as gT}from"marked";import tr from"string-width";import Zr 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"},Ts=["#242424","#5a4233","#746533","#70924f","#37be95"],ws=["#37be95","#2d9273","#246e58","#1e5443","#193f33"],et={accent:f.accent,success:f.success,warning:f.warning,danger:f.danger},er=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],ks=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 uT=Zr(ae.ellipsis),dT=new Intl.Segmenter(void 0,{granularity:"grapheme"}),al=e=>Array.from(dT.segment(e),t=>t.segment),pT=(e,t)=>e+" ".repeat(Math.max(0,t-Zr(e))),fT=(e,t)=>" ".repeat(Math.max(0,t-Zr(e)))+e;function qe(e,t){if(t<=0)return"";if(Zr(e)<=t)return e;let n=t-uT,o="";for(let r of al(e)){if(Zr(o+r)>n)break;o+=r}return o+ae.ellipsis}var Kn=e=>e.replaceAll(" "," "),Je=(e,t)=>pT(qe(e,t),t),Yn=(e,t)=>fT(qe(e,t),t),_e=e=>e.filter(t=>typeof t=="string"&&t!=="").join(` ${ae.bullet} `);var hT=e=>e.startsWith("#")||Bi(e)!==null,yT={spans:[]},vs=e=>e===void 0||e.spans.every(t=>t.text.trim()==="");function xp(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 bT=new Set([..."\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300D\u300F\u3011\u300B\u2026\u201D\u2019,.;:!?)]}"]),ST=new Set([..."\uFF08\u300C\u300E\u3010\u300A\u201C\u2018([{"]),xT=(e,t)=>(tr(e)>1||tr(t)>1)&&!ST.has(e)&&!bT.has(t);function TT(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!==" "&&xT(r,i))return{end:o,carry:o}}return null}function wT(e){let t=[],n=0,o=0,r=0;for(let i of al(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 At(e,t,n=0){let o=()=>Array.from({length:n},()=>({ch:" "})),r=[],i=[],s=0,a=()=>{r.push(xp(i)),i=o(),s=n};for(let c of wT(e)){let{ch:l}=c;if(l===`
|
|
2
|
+
import{once as t_}from"events";import{createInterface as n_}from"readline/promises";import{parseArgs as o_}from"util";var Am={name:"@codeflow-ai/cli",version:"1.34.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.6.7"},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=Am.version,_i="https://codeflow.sh",jo="@codeflow-ai/cli",Rr=0,Ho=1,za=2,io=3,Em=4;import{randomBytes as yS}from"crypto";import{mkdirSync as Lm,readFileSync as bS,rmSync as Om,statSync as SS,writeFileSync as xS}from"fs";import{join as Dm}from"path";import{setTimeout as TS}from"timers/promises";import{z as rn}from"zod";var F=class extends Error{exitCode;hint;constructor(t,n={}){super(t,{cause:n.cause}),this.name="CliError",this.exitCode=n.exitCode??Ho,this.hint=n.hint}};function Se(e){return e instanceof Error?e.message:String(e)}import{chmodSync as mS,existsSync as uS,mkdirSync as dS,readFileSync as pS,writeFileSync as fS}from"fs";import{dirname as gS}from"path";function Lt(e){return uS(e)?pS(e,"utf8"):null}function vn(e,t,n){dS(gS(e),{recursive:!0,mode:448});try{fS(e,t,{mode:n}),mS(e,n)}catch(o){throw new F(`\u5199\u5165 ${e} \u5931\u8D25\uFF1A${Se(o)}`,{cause:o})}}function Mm(e,t,n){vn(e,`${JSON.stringify(t,null,2)}
|
|
3
|
+
`,n)}function Pi(e,t,n,o,r){let i=null,s=()=>{if(i)return i;let a=n(),c=Lt(a);if(c===null)return i=structuredClone(t),i;let l;try{l=JSON.parse(c)}catch(m){throw new F(`${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 F(`${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),Mm(n(),c,384),i=c,c}}}import{homedir as hS}from"os";import{join as qo}from"path";function Cn(){let e=process.env.XDG_CONFIG_HOME;if(e)return qo(e,"codeflow");if(process.platform==="win32"){let t=process.env.APPDATA;if(t)return qo(t,"codeflow")}return qo(hS(),".config","codeflow")}var Im=()=>qo(Cn(),"config.json"),Ai=()=>qo(Cn(),"credentials.json"),Nm=()=>qo(Cn(),"refresh.lock");var wS=rn.object({refreshCookie:rn.string(),accessToken:rn.string(),accessExpiresAt:rn.number(),username:rn.string(),email:rn.string(),site:rn.string()}),kS=rn.object({site:rn.string(),cookie:rn.string()}),vS=rn.object({session:wS.nullable(),device:kS.nullable()}),Va=Pi(vS,{session:null,device:null},Ai,"\u672C\u5730\u51ED\u636E","\u91CD\u65B0\u767B\u5F55"),wt=Va.load,Ei=Va.reload,_r=Va.update;function $m(){let{session:e}=wt();if(!e)throw new F("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:io});return e}var CS=6e4,RS=75e3,_S=120;function PS(e,t){try{Lm(e)}catch{try{Date.now()-SS(e).mtimeMs>CS&&Om(e,{recursive:!0,force:!0})}catch{}return!1}return xS(Dm(e,"owner"),t),!0}function AS(e,t){let n;try{n=bS(Dm(e,"owner"),"utf8")}catch{return}n===t&&Om(e,{recursive:!0,force:!0})}async function Mi(e){let t=Nm(),n=yS(16).toString("hex");Lm(Cn(),{recursive:!0,mode:448});let o=Date.now()+RS;for(;!PS(t,n);){if(Date.now()>o)throw new F(`\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 TS(_S)}try{return await e()}finally{AS(t,n)}}function ES(){let e=process.env.CODEFLOW_SITE;if(e)return e;let t=wt().session;return t?t.site:_i}function Bm(){return{site:ES()}}function so(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{z as ht}from"zod";import{release as Cx}from"os";import{z as He}from"zod";var MS=["active","disabled"],F_=He.enum(MS),Ka=["subscription_first","balance_first","subscription_only","balance_only"],Ya=He.enum(Ka),IS=["openai","anthropic"],Fm=He.enum(IS),NS=["openai-chat","openai-responses","anthropic-messages"],Um=He.enum(NS);var Pr=["pending","paid","refund_requested","partially_refunded","refunded","failed","expired"],jm=He.enum(Pr),LS=["recharge","subscription"],Ja=He.enum(LS),OS=["requested","pending","succeeded","failed","rejected","canceled"],Hm=He.enum(OS),Xa=["pending","issued","rejected"],qm=He.enum(Xa),DS=["special","general"],Qa=He.enum(DS),$S=["info","success","warning","error"],Gm=He.enum($S),BS=["terms","privacy"],U_=He.enum(BS),Za=["recharge","reserve","consume","reserve_refund","refund","refund_release","reward","admin_adjust"],Wm=He.enum(Za),FS=["usage_log","order","invitation","admin"],zm=He.enum(FS),ec=["first_inviter","first_invitee","subsequent_inviter"],Vm=He.enum(ec),tc=["success","error","canceled","anomaly"],Km=He.enum(tc),nc=["open","replied","closed"],Ym=He.enum(nc),oc=["billing","technical","account","other"],Jm=He.enum(oc),rc=["low","normal","high"],Xm=He.enum(rc),US=["user","admin"],Qm=He.enum(US),jS=["pending","published","rejected","removed"],Ar=He.enum(jS),ic=["activity","published"],Zm=He.enum(ic),Ii=["spam","abuse","explicit","illegal","privacy","other"],eu=He.enum(Ii),HS=["none","minor","major","critical"],tu=He.enum(HS);import{z as Go}from"zod";var qS=["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"],GS=Go.enum(qS),nu=Go.object({error:Go.object({code:GS,message:Go.string(),details:Go.unknown().optional(),requestId:Go.string().optional()})});var ou={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 Wo}from"zod";var WS=Wo.string().trim().min(1),sc=WS.pipe(Wo.url()),zS=Wo.object({name:Wo.string().trim().min(1),description:Wo.string().trim().min(1),url:sc}),z_=Wo.array(zS);function ru(e){return`codeflow-cli/${e.cliVersion} (${e.platform} ${e.release}; ${e.arch}) node/${e.nodeVersion}`}function zo(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 J_=dn.object({id:dn.coerce.number().int().positive()}),iu=100,su=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)}),au=(e=dn.string().trim())=>e.nullable().optional().transform(t=>t==null||t.length===0?null:t);import{z as ce}from"zod";var ao=ce.email().max(254).toLowerCase(),Ot=8,Er=ce.string().min(Ot).max(128),Mr=ce.string().min(1).max(128),Kt=32,cc=ce.string().trim().min(1).max(Kt),lc=ce.string().trim().min(1).max(254),Z_=ce.object({email:ao}),e0=ce.object({username:cc,email:ao,password:Er,code:ce.string().min(4).max(8),inviteCode:ce.string().trim().min(1).max(32).optional()}),t0=ce.object({account:lc,password:Mr}),n0=ce.object({email:ao,code:ce.string().min(4).max(8),password:Er}),o0=ce.object({oldPassword:Mr,newPassword:Er}),r0=ce.object({email:ao}),i0=ce.object({email:ao,code:ce.string().min(4).max(8),password:Mr}),cu=ce.object({username:ce.string(),email:ce.string(),avatarUrl:ce.string().nullable()}),Vo=ce.object({accessToken:ce.string(),user:cu}),lu=ce.discriminatedUnion("status",[Vo.extend({status:ce.literal("ok")}),ce.object({status:ce.literal("totp_required"),ticket:ce.string()})]),mu=ce.object({user:cu}),mc=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()}),VS=ce.object({id:ce.number().int(),ip:ce.string(),userAgent:ce.string().nullable(),device:mc.nullable(),loginAt:ce.string(),lastActiveAt:ce.string(),expiresAt:ce.string(),current:ce.boolean()}),uu=ce.object({sessions:ce.array(VS)});import{z as ke}from"zod";var Ko=ke.string().trim().length(6),KS=ke.string().trim().min(10).max(20),Ni=ke.string().trim().min(1).max(64),Li=ke.record(ke.string(),ke.unknown()),c0=ke.object({ticket:ke.string().min(1),code:Ko}),l0=ke.object({ticket:ke.string().min(1),code:KS}),m0=ke.object({code:Ko.optional()}),u0=ke.object({code:Ko}),du=ke.object({secret:ke.string(),otpauthUri:ke.string()}),uc=ke.object({recoveryCodes:ke.array(ke.string())}),YS=ke.object({id:ke.number().int(),name:ke.string(),createdAt:ke.string(),lastUsedAt:ke.string().nullable()}),pu=ke.object({totp:ke.object({enabled:ke.boolean(),enabledAt:ke.string().nullable(),recoveryCodesRemaining:ke.number().int()}),passkeys:ke.array(YS)}),d0=ke.object({name:Ni,response:Li}),p0=ke.object({name:Ni}),f0=ke.object({response:Li});import{z as Ne}from"zod";var S0=Ne.object({account:lc,password:Mr}),JS=Ne.object({totp:Ne.boolean(),passkeys:Ne.boolean()}),x0=Ne.discriminatedUnion("status",[Ne.object({status:Ne.literal("totp_required"),ticket:Ne.string()}),Ne.object({status:Ne.literal("setup_required"),ticket:Ne.string(),missing:JS})]),T0=Ne.object({ticket:Ne.string().min(1)}),w0=Ne.object({ticket:Ne.string().min(1),code:Ko}),k0=Ne.object({ticket:Ne.string().min(1),name:Ni,response:Li}),v0=Ne.object({ticket:Ne.string().min(1),code:Ko.optional()}),fu=Ne.object({username:Ne.string(),email:Ne.string(),avatarUrl:Ne.string().nullable()}),C0=Ne.object({accessToken:Ne.string(),admin:fu}),R0=Ne.object({admin:fu});import{z as dc}from"zod";var M0=dc.object({siteName:dc.string().trim().min(1).max(64),siteDescription:dc.string().trim().max(200).optional(),siteOrigin:sc,username:cc,email:ao,password:Er});import{z as $e}from"zod";var gu={orderNo:$e.string(),amountCny:$e.number().int(),status:jm,credited:$e.boolean(),refundedAmountCny:$e.number().int(),succeededRefundCny:$e.number().int(),pendingRefundCny:$e.number().int(),createdAt:$e.string()},Ir=$e.object({...gu,quota:$e.number(),refundedQuota:$e.number()}),Nr=$e.object({...gu,planName:$e.string(),renewal:$e.boolean(),grantedDurationDays:$e.number().int()}),Oi=$e.object({order:Ir.pick({orderNo:!0,amountCny:!0,quota:!0}),qrCode:$e.string()}),Lr=$e.object({order:Nr.pick({orderNo:!0,amountCny:!0,planName:!0,grantedDurationDays:!0}),qrCode:$e.string()}),hu=$e.object({id:$e.number().int(),amountCny:$e.number().int(),status:Hm,refundTradeNo:$e.string().nullable(),reason:$e.string().nullable(),rejectReason:$e.string().nullable(),createdAt:$e.string()});function yu(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 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()}),Yo=Yt.discriminatedUnion("kind",[pc,fc]),bu=Yt.object({kind:Qm,username:Yt.string()});var Di=ut.object({id:ut.number().int(),title:ut.string(),category:Jm,priority:Xm,status:Ym,createdAt:ut.string(),updatedAt:ut.string()}),Su=Di.pick({id:!0}),xu=25*1024*1024,Tu=5,wu=ut.object({id:ut.number().int(),fileName:ut.string(),fileSize:ut.number().int(),contentType:ut.string()}),ku=wu.pick({id:!0,fileSize:!0}),XS=ut.object({id:ut.number().int(),author:Yo,content:ut.string(),attachments:ut.array(wu),createdAt:ut.string()}),vu=ut.object({ticket:Di,messages:ut.array(XS)});import{z as Or}from"zod";var gc=Or.object({id:Or.number().int(),title:Or.string(),content:Or.string(),level:Gm,publishedAt:Or.string()});import{z as Ye}from"zod";var hc=100,Cu=Ye.object({groups:Ye.array(Ye.object({title:Ye.string(),items:Ye.array(Ye.object({slug:Ye.string(),title:Ye.string()}))}))}),Ru=Ye.object({title:Ye.string(),markdown:Ye.string(),images:Ye.record(Ye.string(),Ye.object({width:Ye.number().int(),height:Ye.number().int()}))}),_u=Ye.object({slug:Ye.string(),title:Ye.string(),anchor:Ye.string().nullable(),snippet:Ye.string()});function Pu(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 $i(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 Le(e){return e.toLocaleString("en-US")}function Gn(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 co(e){return(e/1e3).toFixed(2)}function Jo(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 Bi(e,t){return`${e}******${t}`}var bc=ot.object({inputPricePerMillionTokens:ot.number(),outputPricePerMillionTokens:ot.number(),cachedInputPricePerMillionTokens:ot.number(),cacheWritePricePerMillionTokens:ot.number()});var QS=ot.number().int().nonnegative(),ZS=ot.discriminatedUnion("kind",[bc.extend({kind:ot.literal("price"),inputTokensOver:QS}),ot.object({kind:ot.literal("multiplier"),param:ot.string(),value:ot.string(),multiplier:ot.number()})]),Au=ot.array(ZS);function ex(e){return e.kind==="price"}function Eu(e){return e.kind==="multiplier"}function Mu(e){return e>=1e6&&e%1e5===0?`${e/1e6}M`:e>=1e3&&e%1e3===0?`${e/1e3}k`:Le(e)}function Dr(e){return e===null?"\u57FA\u7840":"\u6269\u5C55"}function Sc(e){return`> ${Mu(e)}`}function Iu(e,t){let n=t.filter(ex).sort((r,i)=>r.inputTokensOver-i.inputTokensOver),o=n[0];return o===void 0?[{name:Dr(null),range:null,price:e}]:[{name:Dr(null),range:`\u2264 ${Mu(o.inputTokensOver)}`,price:e},...n.map(r=>({name:Dr(r.inputTokensOver),range:Sc(r.inputTokensOver),price:r}))]}var tx=ot.object({value:ot.string(),multiplier:ot.number()}),Nu=ot.array(tx);function Lu(e){return Du(e.map(t=>t.multiplier))}function Ou(e,t){return Du([e,...t.map(n=>n.multiplier)])}function Du(e){return Number(e.reduce((t,n)=>t*n,1).toFixed(4))}import{z as lo}from"zod";var nx=lo.object({provider:Fm,pageUrl:lo.string(),indicator:tu,incidents:lo.array(lo.object({title:lo.string()}))}),$u=lo.object({providers:lo.array(nx)}),ox={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 Bu(e){return e.filter(t=>t.indicator!=="none"||t.incidents.length>0)}function Fu(e){return e.indicator==="none"?{label:"\u4E8B\u4EF6\u5904\u7406\u4E2D",tone:"warning"}:ox[e.indicator]}import{z as mo}from"zod";var $r=25*1024*1024,Uu=20,ju=5;var xc="/api/media/";function Hu(e){return`${xc}${e}`}var qu=mo.object({width:mo.number().int(),height:mo.number().int()}),Fi=mo.record(mo.string(),qu),Gu=mo.object({id:mo.number().int(),image:qu.nullable()}),Wu=String.raw`([1-9]\d{0,14})`,nP=new RegExp(String.raw`^${xc}${Wu}$`),zu=new RegExp(String.raw`(!?)\[((?:\\.|[^\\\]\n])*)\]\(${xc}${Wu}(?:\s+"[^"\n]*")?\)`,"g");function Vu(e,t,n){return{id:Number(n),image:e==="!",name:t.replace(/\\(.)/g,"$1")}}function Ku(e){return[...e.matchAll(zu)].map(([,t="",n="",o=""])=>Vu(t,n,o))}function Tc(e,t){return e.replace(zu,(n,o,r,i)=>t(Vu(o,r,i)))}import{z as dt}from"zod";import{z as N}from"zod";var uo=100,Ui=2e4,wc=5e3,ji=500,Hi=64,rx=new RegExp("\\p{Cc}","u"),ix=new RegExp("(?![\\n\\t])\\p{Cc}","u");function kc(e){return N.string().trim().max(e).refine(t=>!rx.test(t))}function vc(e){return N.string().trim().max(e).refine(t=>!ix.test(t))}var mP=N.object({categoryId:N.number().int().positive(),title:kc(uo).min(1),content:vc(Ui).min(1)}),uP=N.object({categoryId:N.number().int().positive().nullable(),title:kc(uo),content:vc(Ui)}),dP=N.object({content:vc(wc).min(1),replyToId:N.number().int().positive().optional()}),pP=N.object({reason:eu,detail:au(kc(ji))}),fP=su.extend({sort:Zm,categoryId:N.coerce.number().int().positive().optional(),q:N.string().trim().min(1).max(Hi).optional(),author:N.string().trim().min(1).max(Kt).optional()}),Cc=N.object({id:N.number().int(),name:N.string(),description:N.string()}),qi=Cc.pick({id:!0,name:!0}),Br=N.object({id:N.number().int(),title:N.string()}),Xo=N.object({id:N.number().int(),title:N.string().nullable()}),gP=N.object({posts:N.array(N.object({id:N.number().int(),lastModified:N.string()})),users:N.array(N.string()),staff:N.array(N.string())}),Rc=N.object({id:N.number().int(),title:N.string(),category:qi,author:Yo,commentCount:N.number().int(),viewCount:N.number().int(),likeCount:N.number().int(),lastActivityAt:N.string()}),_c=N.object({id:N.number().int(),title:N.string(),content:N.string(),images:Fi,category:qi,author:Yo,status:Ar,reviewReason:N.string().nullable(),commentCount:N.number().int(),viewCount:N.number().int(),likeCount:N.number().int(),coverUrl:N.string().nullable(),createdAt:N.string(),publishedAt:N.string().nullable(),editedAt:N.string().nullable(),liked:N.boolean(),bookmarked:N.boolean()}),Yu={id:N.number().int(),author:Yo,content:N.string(),images:Fi,status:Ar,reviewReason:N.string().nullable(),likeCount:N.number().int(),liked:N.boolean(),createdAt:N.string()},Pc=N.object({...Yu,replyTo:N.object({id:N.number().int(),author:bu}).nullable()}),Gi=N.object({...Yu,floor:N.number().int().nullable(),replyCount:N.number().int(),replies:N.array(Pc)}),Ac=N.object({likeCount:N.number().int()}),Ju=_c.pick({id:!0}),Xu=Gi.pick({id:!0}),sx=N.object({status:N.enum(["pending","rejected","removed"]),reviewReason:N.string().nullable()}),Ec=N.object({review:sx.nullable()}),Fr=N.object({id:N.number().int(),title:N.string(),category:qi,status:Ar,reviewReason:N.string().nullable(),commentCount:N.number().int(),viewCount:N.number().int(),likeCount:N.number().int(),createdAt:N.string(),publishedAt:N.string().nullable()}),Wi=N.object({id:N.number().int(),content:N.string(),post:Xo,floorId:N.number().int(),status:Ar,reviewReason:N.string().nullable(),likeCount:N.number().int(),createdAt:N.string()}),Mc=N.object({id:N.number().int(),category:qi.nullable(),title:N.string(),content:N.string(),images:Fi,createdAt:N.string()}),Qu=N.object({posts:N.array(Fr),drafts:N.number().int()}),Zu=Mc.pick({id:!0}),ed=N.object({muted:N.object({reason:N.string(),until:N.string().nullable()}).nullable()});var ax=dt.object({posts:dt.number().int(),comments:dt.number().int(),likesReceived:dt.number().int()}),cx=dt.object({start:dt.string(),end:dt.string(),days:dt.array(dt.object({day:dt.string(),count:dt.number().int()}))}),lx=dt.object({posts:dt.array(Fr),comments:dt.array(Wi)}),td={joinedAt:dt.string(),stats:ax,activity:cx,overview:lx},nd=dt.object({identity:pc,...td}),od=dt.object({identity:fc,...td});import{z as q}from"zod";var tt={id:q.number().int(),read:q.boolean(),createdAt:q.string()},Ur=q.object({floorId:q.number().int()}),rd=q.object({username:q.string()}),id=q.discriminatedUnion("kind",[q.object({...tt,kind:q.literal("post_commented"),post:Br,comment:Ur,actor:rd}),q.object({...tt,kind:q.literal("comment_replied"),post:Xo,comment:Ur,actor:rd}),q.object({...tt,kind:q.literal("post_approved"),post:Br}),q.object({...tt,kind:q.literal("post_rejected"),post:Br,reason:q.string()}),q.object({...tt,kind:q.literal("post_removed"),post:Br,reason:q.string()}),q.object({...tt,kind:q.literal("comment_approved"),post:Xo,comment:Ur}),q.object({...tt,kind:q.literal("comment_rejected"),post:Xo,comment:Ur,reason:q.string()}),q.object({...tt,kind:q.literal("comment_removed"),post:Xo,comment:Ur,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:Ja,amountCny:q.number().int()})}),q.object({...tt,kind:q.literal("refund_rejected"),refund:q.object({orderNo:q.string(),orderType:Ja}),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:mc.nullable()})]),sd=q.object({unread:q.boolean()});var ad="Asia/Shanghai",mx="+08:00";function ux(e){return new Date(new Date(e).getTime()+288e5)}function dx(e=Date.now()){let t=ux(e);return{day:t.toISOString().slice(0,10),hour:t.getUTCHours()}}function Ic(e=Date.now()){return dx(e).day}function Nc(e=Ic()){return new Date(`${e}T00:00:00${mx}`)}function Wn(e,t){let n=new Date(`${e}T00:00:00Z`);return new Date(n.getTime()+t*864e5).toISOString().slice(0,10)}var px=new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium",timeZone:ad}),fx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"long",timeZone:ad});function K(e){return px.format(new Date(e))}function jr(e){return fx.format(new Date(e))}var[gx,...hx]=[{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 zi(e){let t=1,n=gx;for(let o of hx){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 Vi(e){let t=zi(e);return`Lv.${t.level} ${t.name}`}function Ki(e){let t=zi(e);return t.next===null?"\u5DF2\u8FBE\u6700\u9AD8\u7B49\u7EA7":`\u8DDD Lv.${t.level+1} \u8FD8\u5DEE ${t.next-e} \u79EF\u5206`}var Yi="\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"},Qo={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"},Lc={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 cd(e,t){return t===null?e:`${e}\uFF0C\u539F\u56E0\uFF1A${t}`}function Oc(e,t){return t.status==="published"?null:cd(e[t.status],t.reviewReason)}function ld(e){return cd(Lc[e.status],e.reviewReason)}var Ji="\u8BE5\u5E16\u5B50\u6682\u4E0D\u53EF\u89C1",yx=4;function md(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 ud(t,1)}function ud(e,t){return t<yx?e.map(n=>({...n,children:ud(n.children,t+1)})):e.flatMap(n=>[{...n,children:[]},...dd(n)])}function dd(e){return e.children.flatMap(t=>[{reply:t.reply,mention:e.reply.author,children:[]},...dd(t)])}function Dc(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 $c(e){return Math.round(e*100)}function pd(e){return e/100}function fd(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 fd(e,t,2)}function Zo(e,t){return fd(e,t,6)}var hd={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 gd(e){return e==="subscription"?{kind:"subscription"}:{kind:"recharge"}}function Bc(e){return e.title===null?"":`\u300C${e.title}\u300D\u4E0B\u7684`}function Fc(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?Ji:`\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:`${Bc(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:`${Bc(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:`${Bc(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:gd(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:gd(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${zo(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 Uc(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(...Uc(n.tokens));break;case"list":n.items.forEach(o=>t.push(...Uc(o.tokens)));break;case"table":[...n.header,...n.rows.flat()].forEach(o=>t.push(qr(o.tokens)));break}return t}function yd(e){return Uc(e).join(" ").replace(/\s+/g," ").trim()}var bx=[{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 Sx(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 bd(e){return e<365?`${Dt(e)} \u5929`:`${Dt(e/365)} \u5E74`}function xx(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 Tx(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 wx(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 kx=[...bx.map(e=>({min:e.tokens/10,max:e.tokens*1e4,suffix:t=>`\u7EA6\u4E3A${e.name}\u7684 ${Sx(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 ${xx(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 ${bd(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 ${Tx(e)}`},{min:4500,max:1/0,suffix:e=>`\u82E5\u523B\u6210\u6BCF\u679A 30 \u5B57\u7684\u79E6\u6C49\u7AF9\u7B80\uFF0C\u603B\u91CD\u7EA6 ${wx(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 ${bd(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 Sd(e){let{tokens:t,scope:n,range:o}=e;if(t<=0)return null;let r=kx.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 Rn(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=Rn({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"}}),BP=$t({recharge:"\u5145\u503C",subscription:"\u8BA2\u9605"}),Xi=Rn({pending:{label:"\u5F85\u5904\u7406",tone:"warning"},issued:{label:"\u5DF2\u5F00\u5177",tone:"success"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"}}),FP=Rn({active:{label:"\u6B63\u5E38",tone:"success"},disabled:{label:"\u7981\u7528",tone:"danger"}}),jc=$t({subscription_first:"\u8BA2\u9605\u4F18\u5148",balance_first:"\u4F59\u989D\u4F18\u5148",subscription_only:"\u4EC5\u8BA2\u9605",balance_only:"\u4EC5\u4F59\u989D"}),Hc=$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"}),xd=Ka.map(e=>({value:e,label:jc(e)})),qc=$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"}),Td=$t({usage_log:"\u7528\u91CF",order:"\u8BA2\u5355",invitation:"\u9080\u8BF7",admin:"\u7BA1\u7406\u5458"}),wd=Rn({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"}}),Qi=Rn({success:{label:"\u6210\u529F",tone:"success"},error:{label:"\u5931\u8D25",tone:"danger"},canceled:{label:"\u53D6\u6D88",tone:"neutral"},anomaly:{label:"\u5F02\u5E38",tone:"warning"}}),kd=$t({"openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"}),po=$t({special:"\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968",general:"\u589E\u503C\u7A0E\u666E\u901A\u53D1\u7968"}),fo=$t({special:"\u4E13\u7968",general:"\u666E\u7968"}),Zi=$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=Rn({info:{label:"\u4FE1\u606F",tone:"neutral"},success:{label:"\u6210\u529F",tone:"success"},warning:{label:"\u8B66\u544A",tone:"warning"},error:{label:"\u91CD\u8981",tone:"danger"}}),Gc=Rn({open:{label:"\u5F85\u5904\u7406",tone:"warning"},replied:{label:"\u5DF2\u56DE\u590D",tone:"success"},closed:{label:"\u5DF2\u5173\u95ED",tone:"neutral"}}),es=$t({billing:"\u8BA1\u8D39",technical:"\u6280\u672F",account:"\u8D26\u53F7",other:"\u5176\u4ED6"}),Wc=Rn({low:{label:"\u8F83\u4F4E",tone:"neutral"},normal:{label:"\u666E\u901A",tone:"neutral"},high:{label:"\u7D27\u6025",tone:"danger"}}),vd=$t({openai:"OpenAI",anthropic:"Anthropic"}),go=Rn({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"}}),Cd=$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"}),Rd=$t({activity:"\u6700\u65B0\u56DE\u590D",published:"\u6700\u65B0\u53D1\u5E03"});function Pt(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 os(e){return`${e.name} \xD7${e.multiplier}`}var ts=10080,ns=1440;function _d(e){if(e%ts===0){let t=e/ts;return t===1?"\u6BCF\u5468\u9650\u989D":`${t} \u5468\u9650\u989D`}if(e%ns===0){let t=e/ns;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 vx(e){if(e%ts===0){let t=e/ts;return t===1?"\u6BCF\u5468":`\u6BCF ${t} \u5468`}if(e%ns===0){let t=e/ns;return t===1?"\u6BCF\u5929":`\u6BCF ${t} \u5929`}return e%60===0?`\u6BCF ${e/60} \u5C0F\u65F6`:`\u6BCF ${e} \u5206\u949F`}function Pd(e,t){return e.windows.map(n=>`${vx(n.durationMinutes)} ${Te(n.quota,t)}`)}function zc(e){return Math.min(100,Math.floor(e.used/e.quota*100))}function Vc(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 Kc={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"]},Ad={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"};var Ed=e=>e===null?"\u4E2A\u4EBA":"\u5355\u4F4D",Md="\u53D1\u7968\u5F00\u5177\u540E\u65E0\u6CD5\u7EA2\u51B2\uFF0C\u8BF7\u4ED4\u7EC6\u6838\u5BF9\u5F00\u7968\u4FE1\u606F";var Rx=3e4,_x=ru({cliVersion:Vt,platform:process.platform,release:Cx(),arch:process.arch,nodeVersion:process.versions.node});async function Id(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",_x);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??Rx),redirect:"follow"})}catch(r){let i=URL.canParse(e)?new URL(e).origin:e;throw new F(`\u65E0\u6CD5\u8FDE\u63A5 ${i}\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u7AD9\u70B9\u5730\u5740`,{exitCode:Em,cause:r})}}async function Nd(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 Id(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Nd(n)};let o=await n.text(),r=null;if(o!=="")try{r=JSON.parse(o)}catch(i){throw new F(`${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 Ld(e,t={}){let n=await Id(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Nd(n),bytes:null};let o=new Uint8Array(await n.arrayBuffer());return{status:n.status,ok:!0,headers:n.headers,data:null,bytes:o}}function Px(e,t){let n=nu.safeParse(t);if(!n.success)return new F(`\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${e}\uFF09`);let{code:o,message:r}=n.data.error,i=o==="unauthorized"||o==="token_expired"?io:void 0;return new F(ou[o]??r,i?{exitCode:i}:{})}function sn(e){if(!e.ok)throw Px(e.status,e.data)}var $d="cf_refresh",Bd="cf_device",Od=6e4;function Dd(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 Wr(e,t){return{refresh:Dd(t,$d)??e.refresh,device:Dd(t,Bd)??e.device}}function rs(e){let t=[];return e.refresh&&t.push(`${$d}=${e.refresh}`),e.device&&t.push(`${Bd}=${e.device}`),t.length>0?{cookie:t.join("; ")}:{}}function Ax(e){let t=e.split(".")[1];if(t===void 0)throw new F("\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 F("\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 F("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u7F3A\u5C11\u6709\u6548\u671F");return o*1e3}function zr(e,t,n){if(!t.refresh)throw new F("\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:Ax(n.accessToken),username:n.user.username,email:n.user.email,site:e};return _r(r=>{r.session=o,t.device&&(r.device={site:e,cookie:t.device})}),o}function Yc(e){let{device:t}=wt();return t!==null&&t.site===e?t.cookie:null}async function Fd(e,t,n){let o={refresh:null,device:Yc(e)},r=await Jt(`${e}/api/auth/login`,{json:{account:t,password:n},headers:rs(o)});sn(r);let i=lu.parse(r.data),s=Wr(o,r.headers);return i.status==="totp_required"?{status:"totp_required",ticket:i.ticket,jar:s}:{status:"ok",session:zr(e,s,i)}}async function Ud(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:rs(t)});sn(s);let a=Vo.parse(s.data);return zr(e,Wr(t,s.headers),a)}function is(){_r(e=>{e.session=null})}async function Ex(e){let t={refresh:e.refreshCookie,device:Yc(e.site)},n=await Jt(`${e.site}/api/auth/refresh`,{method:"POST",headers:rs(t)});if(n.status===401||n.status===403)throw is(),new F("\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",{exitCode:io});sn(n);let o=Vo.parse(n.data);return zr(e.site,Wr(t,n.headers),o)}async function Vr(e=!1){let t=$m();return!e&&Date.now()<t.accessExpiresAt-Od?t:Mi(async()=>{let n=Ei().session;if(!n)throw new F("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:io});return(n.refreshCookie!==t.refreshCookie||n.accessToken!==t.accessToken)&&Date.now()<n.accessExpiresAt-Od?n:Ex(n)})}async function ss(){let e=wt().session;if(!e)return;let t=await Jt(`${e.site}/api/auth/logout`,{method:"POST",headers:rs({refresh:e.refreshCookie,device:Yc(e.site)})});is(),sn(t)}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 Jc(e,t={}){let n=await Vr(),o=i=>Ld(`${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 as(e,t={}){return(await Jc(e,t)).bytes}function Ue(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 Mx=ht.object({siteName:ht.string(),apiLines:ht.array(ht.object({name:ht.string(),description:ht.string(),url:ht.string()})),quotaPerUsd:ht.number(),ticketAutoCloseMinutes:ht.number(),legal:ht.object({termsConfigured:ht.boolean(),privacyConfigured:ht.boolean()}),siteOrigin:ht.string().nullable()});function Be(e,t){return fn(Mx,`${e}/api/site-config`,{...t===void 0?{}:{timeoutMs:t}})}var Ix=ht.object({content:ht.string(),configured:ht.boolean()});function jd(e,t){return fn(Ix,`${e}/api/agreements/${t}`)}var Nx=1e4;function Hd(){if(process.env.CODEFLOW_SITE)return null;let{session:e}=wt();return e!==null&&e.site!==_i?e.site:null}async function qd(e){let t;try{({siteOrigin:t}=await Be(e,Nx))}catch(o){throw new F(Se(o),{...o instanceof F?{exitCode:o.exitCode}:{},hint:`\u767B\u5F55\u72B6\u6001\u8BB0\u5728 ${e}\uFF0C\u82E5\u8BE5\u7AD9\u70B9\u5DF2\u505C\u7528\uFF0C\u8BF7\u5220\u9664 ${Ai()} \u540E\u91CD\u65B0\u767B\u5F55`,cause:o})}let n=t;n!==e&&await Mi(async()=>{Ei(),_r(o=>{o.session?.site===e&&(o.session.site=n),o.device?.site===e&&(o.device.site=n)})})}import{existsSync as Ox,rmSync as Dx}from"fs";import{spawn as Lx}from"child_process";function Kr(e,t={}){return new Promise((n,o)=>{let r=Lx("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 F(`\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 F(`npm ${e.join(" ")} \u9000\u51FA\u7801 ${c??"null"}`,{...l===""?{}:{hint:l}}))}),t.background===!0&&(r.stdout.unref(),r.stderr.unref(),r.unref())})}async function Gd(e){let t=[],n=async(o,r)=>{try{await r(),e.done(o)}catch(i){t.push(`${o}\uFF1A${Se(i)}`),e.failed(o)}};return await n("\u9000\u51FA\u767B\u5F55",()=>ss()),await n("\u5220\u9664\u672C\u5730\u6587\u4EF6",()=>{let o=Cn();Ox(o)&&Dx(o,{recursive:!0,force:!0})}),await n("\u5378\u8F7D\u672C\u7A0B\u5E8F",async()=>{await Kr(["uninstall","-g",jo])}),t}import{z as Yr}from"zod";var $x=Yr.object({line:Yr.object({name:Yr.string(),url:Yr.string()}).nullable(),lastUpdateCheckAt:Yr.number().nullable()}),Wd=Pi($x,{line:null,lastUpdateCheckAt:null},Im,"\u672C\u5730\u914D\u7F6E","\u91CD\u65B0\u8FD0\u884C"),ho=Wd.load,cs=Wd.update;var Bx=1440*60*1e3;async function zd(){let e=(await Kr(["view",jo,"version"])).trim();if(e==="")throw new F(`npm \u6CA1\u6709\u62A5\u51FA ${jo} \u7684\u7248\u672C`);return e}async function Vd(e,t){return await Kr(["install","-g",`${jo}@${e}`],{background:t}),e}async function Kd(){let e=await zd();return e===Vt?null:await Vd(e,!1)}function Fx(){let e=Date.now(),t=ho().lastUpdateCheckAt;return t!==null&&e-t<Bx?!1:(cs(n=>{n.lastUpdateCheckAt=e}),!0)}async function Yd(){if(!Fx())return null;let e;try{e=await zd()}catch{return null}return e===Vt?null:await Vd(e,!0)}import{Box as HR,render as qR,useInput as GR}from"ink";import{useEffect as Pm,useRef as WR}from"react";var Jd=e=>A(mt(gc),Ue("/announcements",{...e})),Xd=()=>A(gc.nullable(),"/announcements/unread"),ls=e=>A(se,`/announcements/${e}/read`,{method:"POST"});import{Box as Qd,useWindowSize as Ux}from"ink";import{Children as jx}from"react";import{jsx as Zd}from"react/jsx-runtime";var Hx=1,Xc=1,X=1;function j(){let{columns:e,rows:t}=Ux();return{width:Math.max(1,e-Hx*2),columns:e,rows:t}}function ep({height:e,children:t}){return Zd(Qd,{flexDirection:"column",height:e,justifyContent:"space-between",children:jx.toArray(t).map((n,o)=>Zd(Qd,{flexDirection:"column",flexShrink:0,children:n},o))})}import{useInput as tp}from"ink";import{createContext as ds,useCallback as Zc,useContext as qx,useEffect as np,useMemo as op,useRef as us,useState as Gx}from"react";import{jsx as ms}from"react/jsx-runtime";var ps=ds(null),el=ds(null),tl=ds(null);function Qc(){let[e,t]=Gx(!1),n=us(0),o=Zc(()=>(n.current+=1,t(!0),()=>{n.current-=1,n.current===0&&t(!1)}),[]);return op(()=>({held:e,acquire:o}),[e,o])}var Vn={screen:0,panel:10,input:20},nl=ds(null);function rp({children:e}){let t=Qc(),n=Qc(),o=Qc(),r=us([]),i=us(0),s=Zc(l=>{let u={...l,seq:i.current+=1};return r.current.push(u),()=>{r.current=r.current.filter(m=>m!==u)}},[]),a=Zc(()=>{r.current.reduce((u,m)=>u===null||m.layer>u.layer||m.layer===u.layer&&m.seq>u.seq?m:u,null)?.handler()},[]);tp((l,u)=>{u.escape&&a()});let c=op(()=>({push:s,fire:a}),[s,a]);return ms(ps.Provider,{value:t,children:ms(el.Provider,{value:n,children:ms(tl.Provider,{value:o,children:ms(nl.Provider,{value:c,children:e})})})})}function yo(e){let t=qx(e);if(!t)throw new Error("\u952E\u76D8\u94A9\u5B50\u5FC5\u987B\u5728 KeyboardProvider \u5185\u4F7F\u7528");return t}function ol(e,t){let{acquire:n}=yo(e);np(()=>{if(t)return n()},[t,n])}function fs(e){ol(ps,e)}function Re(e){ol(el,e)}function ip(e){ol(tl,e)}function gs(){return yo(el).held}function hs(){return yo(ps).held}function sp(){return yo(tl).held}function G(e,t=!0){let n=yo(ps).held;tp(e,{isActive:t&&!n})}function ap(){return yo(nl).fire}function gn(e,{isActive:t=!0,layer:n=Vn.screen}={}){let{push:o}=yo(nl),r=us(e);r.current=e,np(()=>{if(t)return o({handler:()=>r.current(),layer:n})},[t,n,o])}import{measureElement as Wx}from"ink";import{PassThrough as zx}from"stream";import{createContext as Vx,useCallback as Kx,useContext as Yx,useEffect as up,useRef as ys}from"react";import{jsx as iT}from"react/jsx-runtime";var Jx="\x1B[?1000h\x1B[?1003h\x1B[?1006h",Xx="\x1B[?1006l\x1B[?1003l\x1B[?1000l",Qx=27,Zx=91,eT=60,cp=77,lp=109,mp=20,tT=64,nT=32,oT=20;function rT(e){let t=[],n=[],o=0;for(;o<e.length;){let r=e[o];if(r===void 0)break;if(r!==Qx){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!==Zx){n.push(r),o+=1;continue}if(s===cp){if(o+6>e.length)break;o+=6;continue}if(s!==eT){n.push(r),o+=1;continue}let a=o+3,c;for(;a<e.length&&a-o<mp;){let d=e[a];if(d===cp||d===lp){c=d;break}a+=1}if(c===void 0){if(a-o<mp)break;n.push(r),o+=1;continue}let l=e.subarray(o+3,a).toString("latin1").split(";");if(o=a+1,c===lp||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&tT)!==0?{row:p,column:m,kind:"wheel",delta:(u&1)===0?-1:1}:{row:p,column:m,kind:(u&nT)!==0?"move":"press"})}return{events:t,clean:Buffer.from(n),pending:e.subarray(o)}}function dp(e,t){let n=new Set,o=new zx,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=rT(Buffer.concat([r,p]));r=d.pending,d.clean.length>0&&o.write(d.clean);for(let S of d.events)for(let b of n)b(S);r.length>0&&(i=setTimeout(s,oT))},c=()=>{t.write(Xx)},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(Jx);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 pp=Vx(null);function fp({subscribe:e,children:t}){let n=ys(new Set).current,o=ys(null),r=Kx(i=>(n.add(i),()=>{n.delete(i)}),[n]);return up(()=>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=Wx(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]),iT(pp.Provider,{value:r,children:t})}function rt(e){let t=Yx(pp);if(t===null)throw new Error("useMouseRegion \u5FC5\u987B\u5728 MouseProvider \u5185\u4F7F\u7528");let n=ys(null),o=ys(e);return o.current=e,up(()=>t({node:n,handlers:o}),[t]),n}import{useApp as sT}from"ink";import{createContext as aT,useCallback as bo,useContext as cT,useEffect as rl,useRef as Ss,useState as Xr}from"react";var kt=[{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"}],gp="usage",Jr=e=>kt.findIndex(t=>t.id===e),bs=e=>Jr(e)>=0;import{jsx as mT}from"react/jsx-runtime";var lT=5e3,yp=aT(null),bp=e=>({id:e,params:void 0}),hp=()=>wt().session===null?[{id:"home",params:void 0}]:[bp(gp)];function O(){let e=cT(yp);if(!e)throw new Error("useNav \u5FC5\u987B\u5728 NavProvider \u5185\u4F7F\u7528");return e}function Sp({ctx:e,children:t}){let n=sT(),[o,r]=Xr(hp),[i,s]=Xr(0),[a,c]=Xr([]),l=Ss({announcementsChecked:!1,announcementsShown:!1}).current,u=Ss(new WeakMap).current,m=bo((R,...I)=>{r(E=>[...E,{id:R,params:I[0]}])},[]),p=bo(()=>{r(R=>R.length>1?R.slice(0,-1):R),s(R=>R+1)},[]),d=bo(R=>{r([bp(R)]),s(I=>I+1)},[]),S=bo(()=>{r(hp()),s(R=>R+1)},[]),b=bo(()=>s(R=>R+1),[]),g=bo((R,I)=>{c(E=>[...E,{tone:R,message:I}])},[]),T=bo(()=>c(R=>R.slice(1)),[]),x=a[0]??null;rl(()=>{if(x===null)return;let R=setTimeout(T,lT);return()=>clearTimeout(R)},[x,T]);let C=o[o.length-1];if(C===void 0)throw new Error("\u5BFC\u822A\u6808\u4E3A\u7A7A");let y=u.get(C);y===void 0&&(y=new Map,u.set(C,y));let h={ctx:e,current:C,depth:o.length,push:m,pop:p,select:d,home:S,reload:b,toast:g,message:x,dismissToast:T,exit:n.exit,revision:i,gate:l,retained:y};return mT(yp.Provider,{value:h,children:t})}function Me(e,t){let{retained:n}=O(),[o,r]=Xr(()=>e!==void 0&&n.has(e)?n.get(e):t());return rl(()=>{e!==void 0&&n.set(e,o)},[n,e,o]),[o,r]}function Q(e,t){let[n,o]=Xr({phase:"loading"}),r=Ss(t);r.current=t;let i=Ss(0);return rl(()=>{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:Se(a),hint:a instanceof F?a.hint:void 0})})},e),n}import{Box as Ds,Text as wo,useInput as tw}from"ink";import{Box as ti,Text as rr}from"ink";import{Lexer as gT}from"marked";import tr 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"},xs=["#242424","#5a4233","#746533","#70924f","#37be95"],Ts=["#37be95","#2d9273","#246e58","#1e5443","#193f33"],et={accent:f.accent,success:f.success,warning:f.warning,danger:f.danger},er=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],ws=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 uT=Qr(ae.ellipsis),dT=new Intl.Segmenter(void 0,{granularity:"grapheme"}),il=e=>Array.from(dT.segment(e),t=>t.segment),pT=(e,t)=>e+" ".repeat(Math.max(0,t-Qr(e))),fT=(e,t)=>" ".repeat(Math.max(0,t-Qr(e)))+e;function qe(e,t){if(t<=0)return"";if(Qr(e)<=t)return e;let n=t-uT,o="";for(let r of il(e)){if(Qr(o+r)>n)break;o+=r}return o+ae.ellipsis}var Kn=e=>e.replaceAll(" "," "),Je=(e,t)=>pT(qe(e,t),t),Yn=(e,t)=>fT(qe(e,t),t),_e=e=>e.filter(t=>typeof t=="string"&&t!=="").join(` ${ae.bullet} `);var hT=e=>e.startsWith("#")||$i(e)!==null,yT={spans:[]},ks=e=>e===void 0||e.spans.every(t=>t.text.trim()==="");function xp(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 bT=new Set([..."\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300D\u300F\u3011\u300B\u2026\u201D\u2019,.;:!?)]}"]),ST=new Set([..."\uFF08\u300C\u300E\u3010\u300A\u201C\u2018([{"]),xT=(e,t)=>(tr(e)>1||tr(t)>1)&&!ST.has(e)&&!bT.has(t);function TT(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!==" "&&xT(r,i))return{end:o,carry:o}}return null}function wT(e){let t=[],n=0,o=0,r=0;for(let i of il(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 At(e,t,n=0){let o=()=>Array.from({length:n},()=>({ch:" "})),r=[],i=[],s=0,a=()=>{r.push(xp(i)),i=o(),s=n};for(let c of wT(e)){let{ch:l}=c;if(l===`
|
|
5
5
|
`||l===`\r
|
|
6
6
|
`){a();continue}let u=tr(l);if(s+u>t&&i.length>n){if(l===" "){a();continue}let m=TT(i,l,n),p=m===null?[]:i.slice(m.carry),d=p.reduce((S,b)=>S+tr(b.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(xp(i)),r}var kp=(e,t)=>t==="docs"?e.replaceAll(`
|
|
7
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:kp(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"&&hT(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 Tp=2,wp=e=>e.reduce((t,n)=>t+tr(n.text),0);function kT(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(S=>({spans:an(S.tokens,{color:f.foreground},r),align:S.align}))),a=o-(e.length+1)-e.length*2;if(a<e.length*Tp)return At([{text:n,color:f.foreground}],o);let c=e.map(()=>Tp);for(let d of[i,...s])d.forEach((S,b)=>{for(let g of At(S.spans,Number.MAX_SAFE_INTEGER)){let T=c[b],x=wp(g.spans);T!==void 0&&x>T&&(c[b]=x)}});let l=c.reduce((d,S)=>d+S,0);for(;l>a;){let d=0,S=0;c.forEach((b,g)=>{b>S&&(d=g,S=b)}),c[d]=S-1,l-=1}let u=d=>({text:d,color:f.faintForeground}),m=(d,S,b)=>({spans:[u(`${d}${c.map(g=>"\u2500".repeat(g+2)).join(S)}${b}`)]}),p=d=>{let S=c.map((T,x)=>{let C=d[x];return{width:T,align:C?.align??null,lines:At(C?.spans??[],T)}}),b=S.reduce((T,x)=>Math.max(T,x.lines.length),1),g=[];for(let T=0;T<b;T+=1){let x=[];for(let C of S){let y=C.lines[T]?.spans??[],h=C.width-wp(y),R=C.align==="right"?h:C.align==="center"?Math.floor(h/2):0;x.push(u("\u2502"),{text:` ${" ".repeat(R)}`}),x.push(...y),x.push({text:`${" ".repeat(h-R)} `})}x.push(u("\u2502")),g.push({spans:x})}return g};return[m("\u250C","\u252C","\u2510"),...p(i),m("\u251C","\u253C","\u2524"),...s.flatMap(p),m("\u2514","\u2534","\u2518")]}function
|
|
9
|
-
`))o.push(...At([{text:` ${s}`,color:f.mutedForeground}],t,2));r();break;case"blockquote":{let s=cl(i.tokens??[],Math.max(4,t-2),n);for(;s.length>0&&vs(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=tr(u),p=cl(c.tokens,Math.max(4,t-m),n);p.forEach((d,S)=>{vs(d)&&S===p.length-1||o.push({spans:S===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(...kT(i.header,i.rows,i.raw,t,n)),r();break;default:o.push(...At([{text:i.raw,color:f.foreground}],t))}return o}var ll=(e,t)=>an(e,{},t).map(n=>n.text).join("");function hn(e,t,n="default"){let o=gT.lex(Kn(e),{gfm:!0,breaks:n!=="docs"}),r=cl(o,Math.max(8,t),n);for(;r.length>0&&vs(r[r.length-1]);)r.pop();return r}import{Text as cn,useInput as vT}from"ink";import{useImperativeHandle as CT,useRef as vp,useEffect as RT,useState as Rp}from"react";import ml from"string-width";import{jsx as yn,jsxs as ul}from"react/jsx-runtime";var _T=e=>e.replace(new RegExp("\\p{Cc}","gu"),"");function Cp(e,t,n){let o=t,r=0;for(;o>0;){let s=ml(e[o-1]??"");if(r+s>n)break;r+=s,o-=1}let i=t;for(r+=1;i<e.length;){let s=ml(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:f.cursorBackground,color:f.foreground,children:e})}function nr({value:e,onChange:t,onSubmit:n,placeholder:o,mask:r=!1,isActive:i=!0,width:s=40,ref:a}){let c=[...e],[l,u]=Rp(c.length),m=Math.min(l,c.length),p=Math.max(8,s),d=vp(e),S=vp(m);d.current=e,S.current=m,gs(i);let b=h=>{S.current=h,u(h)},g=(h,R)=>{d.current=h,b(R),t(h)};if(CT(a,()=>({moveToColumn:h=>{let R=[...d.current],I=r?Array.from({length:R.length},()=>"\u2022"):R,z=Cp(I,Math.min(S.current,R.length),p).start,M=0;for(;z<R.length;){let v=ml(I[z]??"");if(M+v>h)break;M+=v,z+=1}b(z)}})),vT((h,R)=>{let I=[...d.current],E=Math.min(S.current,I.length);if(R.return){n(d.current);return}if(R.tab||R.upArrow||R.downArrow)return;if(R.leftArrow){b(Math.max(0,E-1));return}if(R.rightArrow){b(Math.min(I.length,E+1));return}if(R.home){b(0);return}if(R.end){b(I.length);return}if(R.backspace){if(E===0)return;g([...I.slice(0,E-1),...I.slice(E)].join(""),E-1);return}if(R.delete){if(E>=I.length)return;g([...I.slice(0,E),...I.slice(E+1)].join(""),E);return}if(R.ctrl){if(h==="a")b(0);else if(h==="e")b(I.length);else if(h==="k")g(I.slice(0,E).join(""),E);else if(h==="u")g(I.slice(E).join(""),0);else if(h==="w"){let k=E;for(;k>0&&I[k-1]===" ";)k-=1;for(;k>0&&I[k-1]!==" ";)k-=1;g([...I.slice(0,k),...I.slice(E)].join(""),k)}return}if(R.meta||!h)return;let z=h.search(/[\r\n]/),M=_T(z===-1?h:h.slice(0,z)),v=[...I.slice(0,E),M,...I.slice(E)].join("");g(v,E+[...M].length),z!==-1&&n(v)},{isActive:i}),e===""){let h=[...o??""];return i?ul(cn,{children:[yn(ei,{char:h[0]??" "}),yn(cn,{color:f.faintForeground,children:h.slice(1).join("")})]}):yn(cn,{color:f.faintForeground,children:h.join("")})}let T=r?Array.from({length:c.length},()=>"\u2022"):c;if(!i)return yn(cn,{color:f.foreground,children:T.join("")});let{before:x,at:C,after:y}=Cp(T,m,p);return ul(cn,{children:[yn(cn,{color:f.foreground,children:x}),yn(ei,{char:C}),yn(cn,{color:f.foreground,children:y})]})}function Oe({label:e}){let[t,n]=Rp(0);return RT(()=>{let o=setInterval(()=>n(r=>(r+1)%er.length),ks);return()=>clearInterval(o)},[]),ul(cn,{children:[yn(cn,{color:f.accent,children:er[t]}),yn(cn,{color:f.mutedForeground,children:` ${e}`})]})}import{Box as Ap,Text as or}from"ink";import{useEffect as Mp,useState as AT}from"react";import Ep from"string-width";import{Box as _p,Text as Cs}from"ink";import PT from"string-width";import{jsx as ti,jsxs as Pp}from"react/jsx-runtime";var ge=2,Bt=1,Ge=1,Xe=Bt+Ge;function _n({title:e,note:t,width:n}){let o=t===void 0?0:PT(t)+2,r=Math.max(0,n-ge-o);return Pp(Cs,{wrap:"truncate",children:[ti(Cs,{color:f.accent,children:`${ae.section} `}),ti(Cs,{bold:!0,color:f.foreground,children:qe(e,r)}),t!==void 0&&ti(Cs,{color:f.faintForeground,children:` ${t}`})]})}function de({title:e,note:t,width:n,gap:o=Ge,children:r}){return Pp(_p,{flexDirection:"column",children:[ti(_n,{title:e,note:t,width:n}),ti(_p,{flexDirection:"column",marginTop:o,paddingLeft:ge,children:r})]})}import{jsx as Pn,jsxs as Np}from"react/jsx-runtime";var So=e=>!("heading"in e),ET=e=>e.flatMap(t=>!So(t)&&t.heading!==""?[t,{heading:""}]:[t]),Ip=2,Rs=2,MT=(e,t)=>t===void 0?e:e>t?Math.max(1,t-1):t;function IT(e,t,n,o){let[r,i]=Me(o,()=>e.findIndex(u=>So(u)&&u.disabled!==!0));Mp(()=>{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 S=e[d];if(S!==void 0&&So(S)&&S.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 S=0;S<p;S+=1){d=(d+u+p)%p;let b=e[d];if(b!==void 0&&So(b)&&b.disabled!==!0)return d}return m})},a=u=>{let m=e[u];return m!==void 0&&So(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 dl(e,t){let[n,o]=AT(()=>e>=t?e-t+1:0);return Mp(()=>{o(r=>e<r?e:e>=r+t?e-t+1:r)},[e,t]),n}function NT(e,t){let n=e.filter(So),o=Math.max(0,...n.map(s=>Ep(s.label))),r=Math.max(0,...n.map(s=>s.badge===void 0?0:Ep(s.badge))),i=Ip+o+(r>0?r+Rs:0)+Rs;return{label:o,badge:r,hint:Math.max(0,t-i)}}function LT({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 Np(or,{wrap:"truncate",children:[Pn(or,{color:f.accent,children:t?`${ae.cursor} `:" "}),Pn(or,{color:r,bold:t,children:Je(e.label,n.label)}),n.badge>0&&Pn(or,{color:e.badgeTone===void 0?f.faintForeground:et[e.badgeTone],children:`${" ".repeat(Rs)}${Je(e.badge??"",n.badge)}`}),e.hint!==void 0&&n.hint>0&&Pn(or,{color:o||!t?f.faintForeground:f.mutedForeground,children:`${" ".repeat(Rs)}${qe(e.hint,n.hint)}`})]})}function OT({items:e,cursor:t,metrics:n,window:o,width:r,isActive:i,onPick:s,onHover:a,onScroll:c}){let l=dl(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 S=m(d);S!==null&&s(S)},onHover:({row:d})=>{let S=m(d);S!==null&&a(S)}});return Np(Ap,{ref:p,flexDirection:"column",children:[u.map((d,S)=>{let b=l+S;return So(d)?Pn(LT,{item:d,active:b===t&&i,metrics:n},b):d.heading===""?Pn(Ap,{height:1},b):Pn(_n,{title:d.heading,width:r},b)}),e.length>o&&Pn(or,{color:f.faintForeground,children:`${" ".repeat(Ip)}${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=ET(e),a=IT(s,r,t,i);return Pn(OT,{items:s,cursor:a.index,metrics:NT(s,n),window:MT(s.length,o),width:n,isActive:r,onPick:a.pick,onHover:a.moveTo,onScroll:a.step})}import{jsx as Xt,jsxs as _s}from"react/jsx-runtime";var Lp={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}},pl=2,fl=(e,t)=>At([{text:Kn(e)}],t-pl).map(n=>n.spans.map(o=>o.text).join("")),gl=(e,t,n)=>fl(e,n).length+(t===void 0?0:fl(t,n).length);function ye({tone:e,title:t,detail:n,width:o,wrap:r=!1}){let i=Lp[e],s=c=>r?fl(c,o):[qe(c,o-pl)],a=" ".repeat(pl);return _s(ni,{flexDirection:"column",children:[s(t).map((c,l)=>_s(rr,{children:[Xt(rr,{color:i.color,children:l===0?`${i.glyph} `:a}),Xt(rr,{color:f.foreground,children:c})]},l)),n!==void 0&&s(n).map((c,l)=>Xt(rr,{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 DT=2,$T=2;function Op({tone:e,message:t,width:n,onDismiss:o}){let r=Lp[e],i=rt({onClick:o});return _s(ni,{ref:i,children:[Xt(rr,{backgroundColor:f.border,color:r.color,wrap:"truncate",children:` ${r.glyph} `}),Xt(rr,{backgroundColor:f.border,color:f.foreground,wrap:"truncate",children:`${qe(t,n-DT-$T)} `})]})}function Pe({title:e,detail:t,confirmLabel:n,onConfirm:o,onCancel:r,width:i,busy:s,error:a}){return _s(ni,{flexDirection:"column",children:[Xt(ye,{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(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 BT,Text as Ps,useInput as FT}from"ink";import{useRef as UT}from"react";import{jsx as As,jsxs as jT}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=UT(l);if(l!==p.current||u>l){let g=u>=p.current;p.current=l;let T=o&&g?l:Math.min(u,l);T!==u&&m(T)}let d=g=>m(T=>Math.min(Math.max(0,T+g),l));FT((g,T)=>{T.pageUp?d(-c):T.pageDown?d(c):!r&&T.upArrow?d(-1):!r&&T.downArrow&&d(1)},{isActive:n&&a}),G(g=>{g==="k"?d(-1):g==="j"&&d(1)},n&&a&&!r);let S=rt({isActive:n&&a,onWheel:d}),b=e.slice(u,u+c);return jT(BT,{ref:S,flexDirection:"column",children:[b.map((g,T)=>As(Ps,{wrap:"truncate",children:g.spans.length===0?" ":g.spans.map((x,C)=>As(Ps,{color:x.color??f.foreground,bold:x.bold===!0,children:x.text},C))},u+T)),Array.from({length:Math.max(0,c-b.length)},(g,T)=>As(Ps,{children:" "},T)),a&&As(Ps,{color:f.faintForeground,wrap:"truncate",children:`${u+1}-${Math.min(u+c,e.length)} / ${e.length}`})]})}function yt(e){return e.tone==="neutral"?void 0:e.tone}function bt(e){let t=yt(e);return t===void 0?e.label:{text:e.label,tone:t}}import{useCallback as hl,useRef as HT,useState as Dp}from"react";function ue(){let e=O(),[t,n]=Dp(null),[o,r]=Dp(null),i=HT(0),s=hl(()=>{i.current+=1,n(null),r(null)},[]),a=hl((l,u)=>{r({message:l,hint:u})},[]),c=hl((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 S={message:Se(d),hint:d instanceof F?d.hint:void 0};m.failToast===!0?e.toast("fail",S.message):r(S)})},[e]);return{busy:t,error:o,reset:s,fail:a,run:c}}import{Box as ar}from"ink";import{Box as qT,Text as $p}from"ink";import Fp from"string-width";import{jsx as Bp,jsxs as GT}from"react/jsx-runtime";var Es=["\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"],Up=Math.max(...Es.map(e=>Fp(e))),Ms=Es.length,Is=e=>Up<=e;function Ns({width:e}){let t=`v${Vt}`,n=Up+2+Fp(t)<=e;return Bp(qT,{flexDirection:"column",children:Es.map((o,r)=>GT($p,{color:f.accent,children:[o,r===Es.length-1&&n&&Bp($p,{color:f.faintForeground,children:` ${t}`})]},o))})}import{Box as Sl,Text as vt}from"ink";import{useState as jp}from"react";import xo from"string-width";import{jsx as Qt,jsxs as sr}from"react/jsx-runtime";var Ls=2,yl=` ${ae.crumb} `;function Os({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+xo(d)+xo(yl),0),a=s+xo(r)<=t,c=a?s:0,[l,u]=jp(!1),m=rt({isActive:o,onClick:({column:p})=>{p<c&&n()},onHover:({column:p})=>u(p<c),onHoverLeave:()=>u(!1)});return Qt(Sl,{ref:m,marginBottom:1,children:a?sr(vt,{children:[i.map((p,d)=>sr(vt,{children:[Qt(vt,{color:d===0?f.accent:l&&o?f.foreground:f.mutedForeground,children:p}),Qt(vt,{color:f.faintForeground,children:yl})]},d)),Qt(vt,{bold:!0,color:f.foreground,children:r})]}):Qt(vt,{color:f.mutedForeground,children:qe(e.join(yl),t)})})}var bl=2,oi=2,ir=2;function Hp({current:e,width:t,onPick:n,isActive:o,unread:r}){let i=Math.max(0,Xr(e)),[s,a]=jp(null),c=h=>r[h.id]===!0,l=h=>c(h)?`${h.label} ${ae.dot}`:h.label,u=Math.max(...kt.map(h=>xo(h.label))),m=kt.some(c)?xo(` ${ae.dot}`):0,d=(h=>h*u+(h-1)*oi+bl+m)(kt.length)>t,S=d?t-ir*2:t,b=d?Math.max(1,Math.floor((S-m+oi-bl)/(u+oi))):kt.length,g=Math.min(Math.max(0,i-Math.floor((b-1)/2)),kt.length-b),T=kt.slice(g,g+b),x=[],C=d?ir:0;T.forEach((h,R)=>{R>0&&(C+=oi);let I=xo(l(h))+(h.id===e?bl:0);x.push({id:h.id,from:C,to:C+I}),C+=I});let y=rt({isActive:o,onHover:({column:h})=>{let R=x.find(I=>h>=I.from&&h<I.to);a(R?.id??null)},onHoverLeave:()=>a(null),onClick:({column:h})=>{let R=x.find(E=>h>=E.from&&h<E.to);if(R!==void 0){n(R.id);return}if(!d||h>=ir&&h<C)return;let I=h<ir?kt[g-1]:kt[g+b];I!==void 0&&n(I.id)}});return Qt(Sl,{ref:y,marginBottom:1,children:sr(vt,{wrap:"truncate",children:[d&&Qt(vt,{color:f.border,children:g>0?`${ae.prev} `:" ".repeat(ir)}),T.map((h,R)=>{let I=c(h)&&Qt(vt,{color:f.danger,children:` ${ae.dot}`});return sr(vt,{children:[R>0&&" ".repeat(oi),h.id===e?sr(vt,{backgroundColor:f.foreground,color:f.background,bold:!0,children:[` ${h.label}`,I," "]}):sr(vt,{children:[Qt(vt,{color:o&&h.id===s?f.foreground:f.mutedForeground,children:h.label}),I]})]},h.id)}),d&&Qt(vt,{color:f.border,children:g+b<kt.length?` ${ae.next}`:" ".repeat(ir)})]})})}var WT=2;function qp(e,t){let n=[];for(let o of e){let r=n[n.length-1];if(r!==void 0&&xo(_e([...r,o]))<=t)r.push(o);else if(n.length<WT)n.push([o]);else break}return n.map(_e)}function Gp({lines:e}){return Qt(Sl,{flexDirection:"column",flexShrink:0,children:e.map((t,n)=>Qt(vt,{wrap:"truncate",color:f.faintForeground,children:t},n))})}import{createContext as zT,useCallback as VT,useContext as KT,useEffect as Yp,useMemo as YT,useRef as Jp,useState as JT}from"react";var Wp=e=>A(mt(id),Ue("/inbox",{...e})),zp=()=>A(sd,"/inbox/unread"),Vp=e=>A(se,`/inbox/${e}/read`,{method:"POST"}),Kp=()=>A(se,"/inbox/read-all",{method:"POST"});import{jsx as QT}from"react/jsx-runtime";var XT=6e4,Xp=zT(null);function Qp({children:e}){let{revision:t,toast:n}=O(),[o,r]=JT(!1),i=Jp(0),s=Jp(!1),a=VT(()=>{let l=i.current+=1;if(wt().session===null){r(!1);return}zp().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${Se(u)}`))})},[n]);Yp(a,[t,a]),Yp(()=>{let l=setInterval(a,XT);return()=>clearInterval(l)},[a]);let c=YT(()=>({any:o,refresh:a}),[o,a]);return QT(Xp.Provider,{value:c,children:e})}function Ds(){let e=KT(Xp);if(!e)throw new Error("useUnread \u5FC5\u987B\u5728 UnreadProvider \u5185\u4F7F\u7528");return e}import{Fragment as ew,jsx as Ct,jsxs as tf}from"react/jsx-runtime";var Zp=3,ZT=8;function ri(e){let{rows:t}=j();return Math.max(1,t-Zc-Zp-e)}function ef(){let e=O(),{width:t,rows:n}=j(),o=e.current.id,r=e.depth===1&&Ss(o)?o:null,i=Math.max(1,n-Zc-Zp),s=Ms+X,a=r!==null&&Is(t)&&i-Ls-s>=ZT;return{tab:r,mark:a,rows:a?Ls+s:Ls}}var Z=()=>ri(ef().rows);function To({header:e,hints:t,children:n}){let{width:o}=j(),{message:r,dismissToast:i}=O(),s=qp(t,o);return tf(ar,{flexDirection:"column",flexGrow:1,children:[Ct(ar,{flexDirection:"column",flexShrink:0,children:e}),Ct(ar,{flexDirection:"column",flexGrow:1,overflow:"hidden",children:Ct(ar,{flexDirection:"column",flexShrink:0,children:n})}),Ct(ar,{height:1,marginTop:s.length>1?0:1,flexShrink:0,justifyContent:"flex-end",children:r!==null&&Ct(Op,{tone:r.tone,message:r.message,width:o,onDismiss:i})}),Ct(Gp,{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}=ef(),m=Ds(),p=hs(),d=ys(),S=sp(),b=r&&!S,g=b?t:t.filter(h=>h!=="Esc \u8FD4\u56DE"),T=d||p?[]:[...r?["[] \u5207\u529F\u80FD"]:[],"q \u9000\u51FA","? \u5E2E\u52A9"],x=[...b?["Esc \u8FD4\u56DE"]:[],...d||p?[]:["? \u5E2E\u52A9"]];gn(o??a.pop,{isActive:r});let C=ap(),y=r&&!i&&!p;return G(h=>{if(l===null||h!=="["&&h!=="]")return;let R=kt[(Xr(l)+(h==="["?-1:1)+kt.length)%kt.length];R!==void 0&&a.select(R.id)},r&&!i&&!p&&!s),s?Ct(To,{header:null,hints:i?g:[...g,...x],children:n}):l!==null?Ct(To,{header:tf(ew,{children:[u&&Ct(ar,{marginBottom:X,children:Ct(Ns,{width:c})}),Ct(Hp,{current:l,width:c,onPick:h=>{h===l?C():a.select(h)},isActive:y,unread:{inbox:m.any}})]}),hints:i?g:[...g,...T],children:n}):Ct(To,{header:Ct(Os,{trail:["CodeFlow",...e??[]],width:c,onBack:C,isActive:y}),hints:i?g:[...g,...x],children:n})}function V({state:e,loading:t,width:n,children:o}){return e.phase==="loading"?Ct(Oe,{label:t}):e.phase==="error"?Ct(Ft,{message:e.message,hint:e.hint,width:n}):o(e.data)}import{jsx as Zt,jsxs as xl}from"react/jsx-runtime";function nf({params:e}){let t=O(),{width:n}=j(),o=Z(),{item:r}=e,{busy:i,error:s,run:a}=ue();tw((m,p)=>{p.return&&a("\u6B63\u5728\u786E\u8BA4",()=>ms(r.id),{onSuccess:()=>t.pop()})},{isActive:i===null});let c=Wr(r.level),l=yt(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:xl($s,{flexDirection:"column",children:[xl(wo,{wrap:"truncate",children:[Zt(wo,{bold:!0,color:f.foreground,children:r.title}),Zt(wo,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),Zt(wo,{color:f.faintForeground,children:` \u53D1\u5E03\u4E8E ${K(r.publishedAt)}`})]}),Zt($s,{marginTop:1,children:Zt(pt,{lines:hn(r.content,n),height:u})}),s!==null&&Zt($s,{marginTop:1,children:Zt(Ft,{message:s.message,hint:s.hint,width:n})}),Zt($s,{marginTop:1,children:i!==null?Zt(Oe,{label:i}):xl(wo,{wrap:"truncate",children:[Zt(wo,{color:f.accent,children:`${ae.cursor} `}),Zt(wo,{bold:!0,color:f.accent,children:"\u6211\u77E5\u9053\u4E86"})]})})]})})}import{Box as Rl,Text as Bs}from"ink";import{useState as dw}from"react";import{Box as Tl,Text as An}from"ink";import{useEffect as wl,useRef as nw,useState as of}from"react";import kl from"string-width";import{jsx as Jn,jsxs as si}from"react/jsx-runtime";var rf=e=>e===void 0?"":typeof e=="string"?e:e.text,vl=2,ow=6;function rw(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 Cl(e,t,n){let o=e.map((c,l)=>Math.max(kl(c.label),...t.map(u=>kl(u[l]??"")))),r=o.reduce((c,l)=>c+l,0),i=r+vl*Math.max(0,e.length-1)-n;if(i<0)return rw(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)>ow).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 iw=(e,t,n)=>t.map((o,r)=>o.align==="right"?Yn(e[r]??"",n[r]??0):Je(e[r]??"",n[r]??0)).join(" ".repeat(vl)),ii=2,sw=2;function pe({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,[S,b]=Me(d?p("cursor"):void 0,()=>0),[g,T]=Me(p("query"),()=>""),[x,C]=of(!1),y=g.trim().toLowerCase(),h=y===""||s===void 0?e:e.filter($=>s($).toLowerCase().includes(y)),R=x||y!=="",I=Math.max(1,r-1-(R?1:0)),E=h.length>I?Math.max(1,I-1):I,z=Math.max(0,h.length-E),[M,v]=of(()=>S>=E?S-E+1:0);wl(()=>{b($=>Math.min($,Math.max(0,h.length-1)))},[h.length]);let k=m===void 0?-1:h.findIndex(m);wl(()=>{k>=0&&b(k)},[k]),wl(()=>{v($=>d?S<$?S:S>=$+E?S-E+1:$:Math.min($,z))},[S,E,z,d]);let _=$=>{if(!d){v(ne=>Math.min(Math.max(0,ne+$),z));return}h.length!==0&&b(ne=>(ne+$+h.length)%h.length)};G(($,ne)=>{if(ne.upArrow||$==="k"){_(-1);return}if(ne.downArrow||$==="j"){_(1);return}if(ne.return){let w=h[S];w!==void 0&&i?.(w,S);return}s!==void 0&&$.startsWith("/")&&(C(!0),$.length>1&&T($.slice(1)))},a&&!x),gn(()=>{C(!1),T("")},{isActive:x||y!=="",layer:x?Vn.input:Vn.panel});let L=R?1:0,P=nw(null),B=$=>{if($<=L)return null;let ne=M+$-L-1;return h[ne]===void 0?null:ne},J=rt({isActive:a,onWheel:_,onClick:({row:$,column:ne})=>{if(R&&$===0){C(!0),P.current?.moveToColumn(ne-sw);return}if(i===void 0)return;let w=B($);if(w===null)return;let U=h[w];U!==void 0&&(b(w),i(U,w))},onHover:d?({row:$})=>{let ne=B($);ne!==null&&b(ne)}:void 0}),oe=Cl(t,h.map($=>n($).map(rf)),o-ii),fe=h.slice(M,M+E);return si(Tl,{ref:J,flexDirection:"column",children:[R&&si(Tl,{children:[Jn(An,{color:f.accent,children:"/ "}),Jn(nr,{ref:P,value:g,onChange:T,onSubmit:()=>C(!1),isActive:x,placeholder:"\u8F93\u5165\u5173\u952E\u8BCD\u8FC7\u6EE4",width:o-2-kl(` ${h.length}/${e.length}`)}),Jn(An,{color:f.faintForeground,children:` ${h.length}/${e.length}`})]}),si(An,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(ii),iw(t.map($=>$.label),t,oe)]}),h.length===0?si(Tl,{flexDirection:"column",children:[Jn(An,{wrap:"truncate",color:f.mutedForeground,children:`${" ".repeat(ii)}${y===""?c:"\u65E0\u5339\u914D\u7ED3\u679C"}`}),l!==void 0&&y===""&&I>1&&Jn(An,{wrap:"truncate",color:f.faintForeground,children:`${" ".repeat(ii)}${l}`})]}):fe.map(($,ne)=>{let w=M+ne,U=d&&w===S&&a,re=U?f.accent:a?f.foreground:f.mutedForeground,D=n($);return si(An,{wrap:"truncate",children:[Jn(An,{color:f.accent,children:U?`${ae.cursor} `:" "}),t.map((W,ee)=>{let he=D[ee],ie=rf(he),Qe=W.align==="right"?Yn(ie,oe[ee]??0):Je(ie,oe[ee]??0),Tt=typeof he=="object"?he.tone:void 0,Ze=!U&&a&&Tt!==void 0?et[Tt]:re;return Jn(An,{color:Ze,bold:U,children:ee>0?`${" ".repeat(vl)}${Qe}`:Qe},W.label)})]},w)}),(M>0||M+E<h.length)&&Jn(An,{color:f.faintForeground,children:`${" ".repeat(ii)}${M+1}-${Math.min(M+E,h.length)} / ${h.length}`})]})}import{Text as aw}from"ink";import{useEffect as cw,useRef as lw,useState as mw}from"react";import{jsx as uw}from"react/jsx-runtime";function We(e,t,{retain:n}={}){let[o,r]=Me(n,()=>1),[i,s]=mw({pages:1,total:0}),a=lw(!1),c=Q([...e,o],()=>t(o));cw(()=>{if(c.phase!=="ready")return;let p=Math.max(1,Math.ceil(c.data.total/iu));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 ze({page:e,pages:t,total:n,width:o}){return uw(aw,{wrap:"truncate",color:f.faintForeground,children:qe(_e([`\u7B2C ${e} / ${t} \u9875`,`\u5171 ${n} \u6761`,"\u2190\u2192 \u7FFB\u9875"]),o)})}import{jsx as En,jsxs as _l}from"react/jsx-runtime";function sf(){let e=O(),{width:t}=j(),n=Z(),[o,r]=dw({name:"list"}),i=We([e.revision],a=>Jd({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 En(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:En(V,{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=yt(c);return _l(Rl,{flexDirection:"column",children:[_l(Bs,{wrap:"truncate",children:[En(Bs,{bold:!0,color:f.foreground,children:o.item.title}),En(Bs,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),En(Bs,{color:f.faintForeground,children:` ${_e([`\u53D1\u5E03\u4E8E ${K(o.item.publishedAt)}`])}`})]}),En(Rl,{marginTop:1,children:En(pt,{lines:hn(o.item.content,t),height:Math.max(3,n-2)})})]})}return _l(Rl,{flexDirection:"column",children:[En(pe,{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,bt(Wr(c.level)),K(c.publishedAt)],onOpen:c=>{r({name:"detail",item:c}),ms(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"}),En(ze,{page:i.page,pages:i.pages,total:i.total,width:t})]})}})})}import{Box as at,Text as gi}from"ink";import{useState as _g}from"react";import uk from"string-width";import{z as pw}from"zod";var Fs=e=>`/community/${e.kind==="user"?"users":"staff"}/${encodeURIComponent(e.username)}`,Us=()=>A(pw.array(_c),"/community/categories"),cr=()=>A(ed,"/community/me"),af=e=>A(mt(Pc),Ue("/community/posts",{...e})),js=e=>A(Ac,`/community/posts/${e}`),cf=e=>A(se,`/community/posts/${e}/view`,{method:"POST"}),lf=(e,t)=>A(mt(Wi),Ue(`/community/posts/${e}/floors`,{page:t})),mf=(e,t)=>A(Wi,`/community/posts/${e}/floors/${t}`),uf=(e,t)=>A(mt(Ec),Ue(`/community/comments/${e}/replies`,{page:t})),Pl=e=>A(nd,Fs({kind:"user",username:e})),df=e=>e.kind==="user"?Pl(e.username):A(od,Fs(e)),pf=(e,t)=>A(mt(Ur),Ue(`${Fs(e)}/posts`,{page:t})),ff=(e,t)=>A(mt(zi),Ue(`${Fs(e)}/comments`,{page:t})),gf=e=>A(mt(Pc),Ue("/community/mine/bookmarks",{page:e})),hf=e=>A(mt(Nc),Ue("/community/mine/drafts",{page:e})),yf=()=>A(Qu,"/community/mine/todo"),bf=e=>A(Ju,"/community/posts",{method:"POST",json:e}),Sf=(e,t)=>A(se,`/community/posts/${e}`,{method:"PATCH",json:t}),Hs=e=>A(se,`/community/posts/${e}`,{method:"DELETE"}),xf=e=>A(Zu,"/community/drafts",{method:"POST",json:e}),Tf=(e,t)=>A(se,`/community/drafts/${e}`,{method:"PATCH",json:t}),wf=(e,t)=>A(se,`/community/drafts/${e}/publish`,{method:"POST",json:t}),kf=(e,t)=>A(Xu,`/community/posts/${e}/comments`,{method:"POST",json:t}),vf=e=>A(se,`/community/comments/${e}`,{method:"DELETE"}),Cf=(e,t)=>A(Mc,`/community/posts/${e}/like`,{method:t?"PUT":"DELETE"}),Rf=(e,t)=>A(Mc,`/community/comments/${e}/like`,{method:t?"PUT":"DELETE"}),_f=(e,t)=>A(se,`/community/posts/${e}/bookmark`,{method:t?"PUT":"DELETE"}),Pf=(e,t)=>A(se,`/community/posts/${e}/reports`,{method:"POST",json:t}),Af=(e,t)=>A(se,`/community/comments/${e}/reports`,{method:"POST",json:t});var Mn=()=>A(mu,"/auth/me"),Ef=e=>A(se,"/auth/me",{method:"PATCH",json:e}),Mf=e=>A(se,"/auth/me/password",{method:"POST",json:e}),If=e=>A(se,"/auth/me/email/code",{method:"POST",json:e}),Nf=e=>A(se,"/auth/me/email",{method:"POST",json:e}),Lf=()=>A(uu,"/auth/me/sessions"),Of=e=>A(se,`/auth/me/sessions/${e}`,{method:"DELETE"});async function Df(){await A(se,"/auth/me/sessions",{method:"DELETE"}),ss()}var $f=()=>A(pu,"/auth/me/security"),Al=e=>A(du,"/auth/me/totp/setup",{method:"POST",json:e}),Bf=e=>A(pc,"/auth/me/totp/confirm",{method:"POST",json:e}),Ff=e=>A(se,"/auth/me/totp/disable",{method:"POST",json:e}),Uf=e=>A(pc,"/auth/me/totp/recovery-codes",{method:"POST",json:e}),jf=(e,t)=>A(se,`/auth/me/passkeys/${e}`,{method:"PATCH",json:t}),Hf=e=>A(se,`/auth/me/passkeys/${e}`,{method:"DELETE"});var El=12e4,fw=e=>A(Gu,Ue("/media",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:El}),gw=e=>A(se,`/media/${e}`,{method:"DELETE"}),ai={upload:async e=>({...await fw(e),fileName:e.fileName}),discard:gw};async function qf(e){let{bytes:t,headers:n}=await Qc(`/media/${e}`,{timeoutMs:El}),o=n.get("content-disposition")?.split("filename*=UTF-8''")[1];if(o===void 0)throw new F("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u9644\u4EF6\u6587\u4EF6\u540D");return{fileName:decodeURIComponent(o),bytes:t}}var Gf=()=>A(Ic,"/auth/me/avatar"),Wf=e=>A(Ic,"/auth/me/avatar",{method:"PUT",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:El}),zf=()=>A(se,"/auth/me/avatar",{method:"DELETE"});import{existsSync as qs,readFileSync as hw,statSync as Vf,writeFileSync as yw}from"fs";import{homedir as Ml}from"os";import en from"path";var bw={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif"},Kf=e=>e.startsWith("~/")?en.join(Ml(),e.slice(2)):e;function Sw(e){return e.split(`
|
|
10
|
-
`).map(t=>t.trim()).filter(t=>t!=="").map(Kf)}function Yf(e,t,n){if(!
|
|
8
|
+
`});break;case"escape":o.push({text:r.text,...t});break;default:o.push({text:r.raw,...t})}return o}var Tp=2,wp=e=>e.reduce((t,n)=>t+tr(n.text),0);function kT(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(S=>({spans:an(S.tokens,{color:f.foreground},r),align:S.align}))),a=o-(e.length+1)-e.length*2;if(a<e.length*Tp)return At([{text:n,color:f.foreground}],o);let c=e.map(()=>Tp);for(let d of[i,...s])d.forEach((S,b)=>{for(let g of At(S.spans,Number.MAX_SAFE_INTEGER)){let T=c[b],x=wp(g.spans);T!==void 0&&x>T&&(c[b]=x)}});let l=c.reduce((d,S)=>d+S,0);for(;l>a;){let d=0,S=0;c.forEach((b,g)=>{b>S&&(d=g,S=b)}),c[d]=S-1,l-=1}let u=d=>({text:d,color:f.faintForeground}),m=(d,S,b)=>({spans:[u(`${d}${c.map(g=>"\u2500".repeat(g+2)).join(S)}${b}`)]}),p=d=>{let S=c.map((T,x)=>{let C=d[x];return{width:T,align:C?.align??null,lines:At(C?.spans??[],T)}}),b=S.reduce((T,x)=>Math.max(T,x.lines.length),1),g=[];for(let T=0;T<b;T+=1){let x=[];for(let C of S){let y=C.lines[T]?.spans??[],h=C.width-wp(y),R=C.align==="right"?h:C.align==="center"?Math.floor(h/2):0;x.push(u("\u2502"),{text:` ${" ".repeat(R)}`}),x.push(...y),x.push({text:`${" ".repeat(h-R)} `})}x.push(u("\u2502")),g.push({spans:x})}return g};return[m("\u250C","\u252C","\u2510"),...p(i),m("\u251C","\u253C","\u2524"),...s.flatMap(p),m("\u2514","\u2534","\u2518")]}function sl(e,t,n){let o=[],r=()=>{o.length>0&&!ks(o[o.length-1])&&o.push(yT)};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"?Pu(i.text):void 0;At(a,t,i.depth<=2?2:0).forEach((l,u)=>o.push(u===0?{...l,anchor:c}:l)),r();break}case"paragraph":o.push(...At(an(i.tokens,{color:f.foreground},n),t)),r();break;case"text":o.push(...At("tokens"in i&&i.tokens!==void 0?an(i.tokens,{color:f.foreground},n):[{text:kp(i.text,n),color:f.foreground}],t));break;case"code":for(let s of i.text.split(`
|
|
9
|
+
`))o.push(...At([{text:` ${s}`,color:f.mutedForeground}],t,2));r();break;case"blockquote":{let s=sl(i.tokens??[],Math.max(4,t-2),n);for(;s.length>0&&ks(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=tr(u),p=sl(c.tokens,Math.max(4,t-m),n);p.forEach((d,S)=>{ks(d)&&S===p.length-1||o.push({spans:S===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(...kT(i.header,i.rows,i.raw,t,n)),r();break;default:o.push(...At([{text:i.raw,color:f.foreground}],t))}return o}var al=(e,t)=>an(e,{},t).map(n=>n.text).join("");function hn(e,t,n="default"){let o=gT.lex(Kn(e),{gfm:!0,breaks:n!=="docs"}),r=sl(o,Math.max(8,t),n);for(;r.length>0&&ks(r[r.length-1]);)r.pop();return r}import{Text as cn,useInput as vT}from"ink";import{useImperativeHandle as CT,useRef as vp,useEffect as RT,useState as Rp}from"react";import cl from"string-width";import{jsx as yn,jsxs as ll}from"react/jsx-runtime";var _T=e=>e.replace(new RegExp("\\p{Cc}","gu"),"");function Cp(e,t,n){let o=t,r=0;for(;o>0;){let s=cl(e[o-1]??"");if(r+s>n)break;r+=s,o-=1}let i=t;for(r+=1;i<e.length;){let s=cl(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 nr({value:e,onChange:t,onSubmit:n,placeholder:o,mask:r=!1,isActive:i=!0,width:s=40,ref:a}){let c=[...e],[l,u]=Rp(c.length),m=Math.min(l,c.length),p=Math.max(8,s),d=vp(e),S=vp(m);d.current=e,S.current=m,fs(i);let b=h=>{S.current=h,u(h)},g=(h,R)=>{d.current=h,b(R),t(h)};if(CT(a,()=>({moveToColumn:h=>{let R=[...d.current],I=r?Array.from({length:R.length},()=>"\u2022"):R,z=Cp(I,Math.min(S.current,R.length),p).start,M=0;for(;z<R.length;){let v=cl(I[z]??"");if(M+v>h)break;M+=v,z+=1}b(z)}})),vT((h,R)=>{let I=[...d.current],E=Math.min(S.current,I.length);if(R.return){n(d.current);return}if(R.tab||R.upArrow||R.downArrow)return;if(R.leftArrow){b(Math.max(0,E-1));return}if(R.rightArrow){b(Math.min(I.length,E+1));return}if(R.home){b(0);return}if(R.end){b(I.length);return}if(R.backspace){if(E===0)return;g([...I.slice(0,E-1),...I.slice(E)].join(""),E-1);return}if(R.delete){if(E>=I.length)return;g([...I.slice(0,E),...I.slice(E+1)].join(""),E);return}if(R.ctrl){if(h==="a")b(0);else if(h==="e")b(I.length);else if(h==="k")g(I.slice(0,E).join(""),E);else if(h==="u")g(I.slice(E).join(""),0);else if(h==="w"){let k=E;for(;k>0&&I[k-1]===" ";)k-=1;for(;k>0&&I[k-1]!==" ";)k-=1;g([...I.slice(0,k),...I.slice(E)].join(""),k)}return}if(R.meta||!h)return;let z=h.search(/[\r\n]/),M=_T(z===-1?h:h.slice(0,z)),v=[...I.slice(0,E),M,...I.slice(E)].join("");g(v,E+[...M].length),z!==-1&&n(v)},{isActive:i}),e===""){let h=[...o??""];return i?ll(cn,{children:[yn(Zr,{char:h[0]??" "}),yn(cn,{color:f.faintForeground,children:h.slice(1).join("")})]}):yn(cn,{color:f.faintForeground,children:h.join("")})}let T=r?Array.from({length:c.length},()=>"\u2022"):c;if(!i)return yn(cn,{color:f.foreground,children:T.join("")});let{before:x,at:C,after:y}=Cp(T,m,p);return ll(cn,{children:[yn(cn,{color:f.foreground,children:x}),yn(Zr,{char:C}),yn(cn,{color:f.foreground,children:y})]})}function Oe({label:e}){let[t,n]=Rp(0);return RT(()=>{let o=setInterval(()=>n(r=>(r+1)%er.length),ws);return()=>clearInterval(o)},[]),ll(cn,{children:[yn(cn,{color:f.accent,children:er[t]}),yn(cn,{color:f.mutedForeground,children:` ${e}`})]})}import{Box as Ap,Text as or}from"ink";import{useEffect as Mp,useState as AT}from"react";import Ep from"string-width";import{Box as _p,Text as vs}from"ink";import PT from"string-width";import{jsx as ei,jsxs as Pp}from"react/jsx-runtime";var ge=2,Bt=1,Ge=1,Xe=Bt+Ge;function _n({title:e,note:t,width:n}){let o=t===void 0?0:PT(t)+2,r=Math.max(0,n-ge-o);return Pp(vs,{wrap:"truncate",children:[ei(vs,{color:f.accent,children:`${ae.section} `}),ei(vs,{bold:!0,color:f.foreground,children:qe(e,r)}),t!==void 0&&ei(vs,{color:f.faintForeground,children:` ${t}`})]})}function de({title:e,note:t,width:n,gap:o=Ge,children:r}){return Pp(_p,{flexDirection:"column",children:[ei(_n,{title:e,note:t,width:n}),ei(_p,{flexDirection:"column",marginTop:o,paddingLeft:ge,children:r})]})}import{jsx as Pn,jsxs as Np}from"react/jsx-runtime";var So=e=>!("heading"in e),ET=e=>e.flatMap(t=>!So(t)&&t.heading!==""?[t,{heading:""}]:[t]),Ip=2,Cs=2,MT=(e,t)=>t===void 0?e:e>t?Math.max(1,t-1):t;function IT(e,t,n,o){let[r,i]=Me(o,()=>e.findIndex(u=>So(u)&&u.disabled!==!0));Mp(()=>{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 S=e[d];if(S!==void 0&&So(S)&&S.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 S=0;S<p;S+=1){d=(d+u+p)%p;let b=e[d];if(b!==void 0&&So(b)&&b.disabled!==!0)return d}return m})},a=u=>{let m=e[u];return m!==void 0&&So(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 ml(e,t){let[n,o]=AT(()=>e>=t?e-t+1:0);return Mp(()=>{o(r=>e<r?e:e>=r+t?e-t+1:r)},[e,t]),n}function NT(e,t){let n=e.filter(So),o=Math.max(0,...n.map(s=>Ep(s.label))),r=Math.max(0,...n.map(s=>s.badge===void 0?0:Ep(s.badge))),i=Ip+o+(r>0?r+Cs:0)+Cs;return{label:o,badge:r,hint:Math.max(0,t-i)}}function LT({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 Np(or,{wrap:"truncate",children:[Pn(or,{color:f.accent,children:t?`${ae.cursor} `:" "}),Pn(or,{color:r,bold:t,children:Je(e.label,n.label)}),n.badge>0&&Pn(or,{color:e.badgeTone===void 0?f.faintForeground:et[e.badgeTone],children:`${" ".repeat(Cs)}${Je(e.badge??"",n.badge)}`}),e.hint!==void 0&&n.hint>0&&Pn(or,{color:o||!t?f.faintForeground:f.mutedForeground,children:`${" ".repeat(Cs)}${qe(e.hint,n.hint)}`})]})}function OT({items:e,cursor:t,metrics:n,window:o,width:r,isActive:i,onPick:s,onHover:a,onScroll:c}){let l=ml(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 S=m(d);S!==null&&s(S)},onHover:({row:d})=>{let S=m(d);S!==null&&a(S)}});return Np(Ap,{ref:p,flexDirection:"column",children:[u.map((d,S)=>{let b=l+S;return So(d)?Pn(LT,{item:d,active:b===t&&i,metrics:n},b):d.heading===""?Pn(Ap,{height:1},b):Pn(_n,{title:d.heading,width:r},b)}),e.length>o&&Pn(or,{color:f.faintForeground,children:`${" ".repeat(Ip)}${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=ET(e),a=IT(s,r,t,i);return Pn(OT,{items:s,cursor:a.index,metrics:NT(s,n),window:MT(s.length,o),width:n,isActive:r,onPick:a.pick,onHover:a.moveTo,onScroll:a.step})}import{jsx as Xt,jsxs as Rs}from"react/jsx-runtime";var Lp={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}},ul=2,dl=(e,t)=>At([{text:Kn(e)}],t-ul).map(n=>n.spans.map(o=>o.text).join("")),pl=(e,t,n)=>dl(e,n).length+(t===void 0?0:dl(t,n).length);function ye({tone:e,title:t,detail:n,width:o,wrap:r=!1}){let i=Lp[e],s=c=>r?dl(c,o):[qe(c,o-ul)],a=" ".repeat(ul);return Rs(ti,{flexDirection:"column",children:[s(t).map((c,l)=>Rs(rr,{children:[Xt(rr,{color:i.color,children:l===0?`${i.glyph} `:a}),Xt(rr,{color:f.foreground,children:c})]},l)),n!==void 0&&s(n).map((c,l)=>Xt(rr,{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 DT=2,$T=2;function Op({tone:e,message:t,width:n,onDismiss:o}){let r=Lp[e],i=rt({onClick:o});return Rs(ti,{ref:i,children:[Xt(rr,{backgroundColor:f.border,color:r.color,wrap:"truncate",children:` ${r.glyph} `}),Xt(rr,{backgroundColor:f.border,color:f.foreground,wrap:"truncate",children:`${qe(t,n-DT-$T)} `})]})}function Pe({title:e,detail:t,confirmLabel:n,onConfirm:o,onCancel:r,width:i,busy:s,error:a}){return Rs(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 BT,Text as _s,useInput as FT}from"ink";import{useRef as UT}from"react";import{jsx as Ps,jsxs as jT}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=UT(l);if(l!==p.current||u>l){let g=u>=p.current;p.current=l;let T=o&&g?l:Math.min(u,l);T!==u&&m(T)}let d=g=>m(T=>Math.min(Math.max(0,T+g),l));FT((g,T)=>{T.pageUp?d(-c):T.pageDown?d(c):!r&&T.upArrow?d(-1):!r&&T.downArrow&&d(1)},{isActive:n&&a}),G(g=>{g==="k"?d(-1):g==="j"&&d(1)},n&&a&&!r);let S=rt({isActive:n&&a,onWheel:d}),b=e.slice(u,u+c);return jT(BT,{ref:S,flexDirection:"column",children:[b.map((g,T)=>Ps(_s,{wrap:"truncate",children:g.spans.length===0?" ":g.spans.map((x,C)=>Ps(_s,{color:x.color??f.foreground,bold:x.bold===!0,children:x.text},C))},u+T)),Array.from({length:Math.max(0,c-b.length)},(g,T)=>Ps(_s,{children:" "},T)),a&&Ps(_s,{color:f.faintForeground,wrap:"truncate",children:`${u+1}-${Math.min(u+c,e.length)} / ${e.length}`})]})}function yt(e){return e.tone==="neutral"?void 0:e.tone}function bt(e){let t=yt(e);return t===void 0?e.label:{text:e.label,tone:t}}import{useCallback as fl,useRef as HT,useState as Dp}from"react";function ue(){let e=O(),[t,n]=Dp(null),[o,r]=Dp(null),i=HT(0),s=fl(()=>{i.current+=1,n(null),r(null)},[]),a=fl((l,u)=>{r({message:l,hint:u})},[]),c=fl((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 S={message:Se(d),hint:d instanceof F?d.hint:void 0};m.failToast===!0?e.toast("fail",S.message):r(S)})},[e]);return{busy:t,error:o,reset:s,fail:a,run:c}}import{Box as ar}from"ink";import{Box as qT,Text as $p}from"ink";import Fp from"string-width";import{jsx as Bp,jsxs as GT}from"react/jsx-runtime";var As=["\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"],Up=Math.max(...As.map(e=>Fp(e))),Es=As.length,Ms=e=>Up<=e;function Is({width:e}){let t=`v${Vt}`,n=Up+2+Fp(t)<=e;return Bp(qT,{flexDirection:"column",children:As.map((o,r)=>GT($p,{color:f.accent,children:[o,r===As.length-1&&n&&Bp($p,{color:f.faintForeground,children:` ${t}`})]},o))})}import{Box as yl,Text as vt}from"ink";import{useState as jp}from"react";import xo from"string-width";import{jsx as Qt,jsxs as sr}from"react/jsx-runtime";var Ns=2,gl=` ${ae.crumb} `;function Ls({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+xo(d)+xo(gl),0),a=s+xo(r)<=t,c=a?s:0,[l,u]=jp(!1),m=rt({isActive:o,onClick:({column:p})=>{p<c&&n()},onHover:({column:p})=>u(p<c),onHoverLeave:()=>u(!1)});return Qt(yl,{ref:m,marginBottom:1,children:a?sr(vt,{children:[i.map((p,d)=>sr(vt,{children:[Qt(vt,{color:d===0?f.accent:l&&o?f.foreground:f.mutedForeground,children:p}),Qt(vt,{color:f.faintForeground,children:gl})]},d)),Qt(vt,{bold:!0,color:f.foreground,children:r})]}):Qt(vt,{color:f.mutedForeground,children:qe(e.join(gl),t)})})}var hl=2,ni=2,ir=2;function Hp({current:e,width:t,onPick:n,isActive:o,unread:r}){let i=Math.max(0,Jr(e)),[s,a]=jp(null),c=h=>r[h.id]===!0,l=h=>c(h)?`${h.label} ${ae.dot}`:h.label,u=Math.max(...kt.map(h=>xo(h.label))),m=kt.some(c)?xo(` ${ae.dot}`):0,d=(h=>h*u+(h-1)*ni+hl+m)(kt.length)>t,S=d?t-ir*2:t,b=d?Math.max(1,Math.floor((S-m+ni-hl)/(u+ni))):kt.length,g=Math.min(Math.max(0,i-Math.floor((b-1)/2)),kt.length-b),T=kt.slice(g,g+b),x=[],C=d?ir:0;T.forEach((h,R)=>{R>0&&(C+=ni);let I=xo(l(h))+(h.id===e?hl:0);x.push({id:h.id,from:C,to:C+I}),C+=I});let y=rt({isActive:o,onHover:({column:h})=>{let R=x.find(I=>h>=I.from&&h<I.to);a(R?.id??null)},onHoverLeave:()=>a(null),onClick:({column:h})=>{let R=x.find(E=>h>=E.from&&h<E.to);if(R!==void 0){n(R.id);return}if(!d||h>=ir&&h<C)return;let I=h<ir?kt[g-1]:kt[g+b];I!==void 0&&n(I.id)}});return Qt(yl,{ref:y,marginBottom:1,children:sr(vt,{wrap:"truncate",children:[d&&Qt(vt,{color:f.border,children:g>0?`${ae.prev} `:" ".repeat(ir)}),T.map((h,R)=>{let I=c(h)&&Qt(vt,{color:f.danger,children:` ${ae.dot}`});return sr(vt,{children:[R>0&&" ".repeat(ni),h.id===e?sr(vt,{backgroundColor:f.foreground,color:f.background,bold:!0,children:[` ${h.label}`,I," "]}):sr(vt,{children:[Qt(vt,{color:o&&h.id===s?f.foreground:f.mutedForeground,children:h.label}),I]})]},h.id)}),d&&Qt(vt,{color:f.border,children:g+b<kt.length?` ${ae.next}`:" ".repeat(ir)})]})})}var WT=2;function qp(e,t){let n=[];for(let o of e){let r=n[n.length-1];if(r!==void 0&&xo(_e([...r,o]))<=t)r.push(o);else if(n.length<WT)n.push([o]);else break}return n.map(_e)}function Gp({lines:e}){return Qt(yl,{flexDirection:"column",flexShrink:0,children:e.map((t,n)=>Qt(vt,{wrap:"truncate",color:f.faintForeground,children:t},n))})}import{createContext as zT,useCallback as VT,useContext as KT,useEffect as Yp,useMemo as YT,useRef as Jp,useState as JT}from"react";var Wp=e=>A(mt(id),Ue("/inbox",{...e})),zp=()=>A(sd,"/inbox/unread"),Vp=e=>A(se,`/inbox/${e}/read`,{method:"POST"}),Kp=()=>A(se,"/inbox/read-all",{method:"POST"});import{jsx as QT}from"react/jsx-runtime";var XT=6e4,Xp=zT(null);function Qp({children:e}){let{revision:t,toast:n}=O(),[o,r]=JT(!1),i=Jp(0),s=Jp(!1),a=VT(()=>{let l=i.current+=1;if(wt().session===null){r(!1);return}zp().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${Se(u)}`))})},[n]);Yp(a,[t,a]),Yp(()=>{let l=setInterval(a,XT);return()=>clearInterval(l)},[a]);let c=YT(()=>({any:o,refresh:a}),[o,a]);return QT(Xp.Provider,{value:c,children:e})}function Os(){let e=KT(Xp);if(!e)throw new Error("useUnread \u5FC5\u987B\u5728 UnreadProvider \u5185\u4F7F\u7528");return e}import{Fragment as ew,jsx as Ct,jsxs as tf}from"react/jsx-runtime";var Zp=3,ZT=8;function oi(e){let{rows:t}=j();return Math.max(1,t-Xc-Zp-e)}function ef(){let e=O(),{width:t,rows:n}=j(),o=e.current.id,r=e.depth===1&&bs(o)?o:null,i=Math.max(1,n-Xc-Zp),s=Es+X,a=r!==null&&Ms(t)&&i-Ns-s>=ZT;return{tab:r,mark:a,rows:a?Ns+s:Ns}}var Z=()=>oi(ef().rows);function To({header:e,hints:t,children:n}){let{width:o}=j(),{message:r,dismissToast:i}=O(),s=qp(t,o);return tf(ar,{flexDirection:"column",flexGrow:1,children:[Ct(ar,{flexDirection:"column",flexShrink:0,children:e}),Ct(ar,{flexDirection:"column",flexGrow:1,overflow:"hidden",children:Ct(ar,{flexDirection:"column",flexShrink:0,children:n})}),Ct(ar,{height:1,marginTop:s.length>1?0:1,flexShrink:0,justifyContent:"flex-end",children:r!==null&&Ct(Op,{tone:r.tone,message:r.message,width:o,onDismiss:i})}),Ct(Gp,{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}=ef(),m=Os(),p=gs(),d=hs(),S=sp(),b=r&&!S,g=b?t:t.filter(h=>h!=="Esc \u8FD4\u56DE"),T=d||p?[]:[...r?["[] \u5207\u529F\u80FD"]:[],"q \u9000\u51FA","? \u5E2E\u52A9"],x=[...b?["Esc \u8FD4\u56DE"]:[],...d||p?[]:["? \u5E2E\u52A9"]];gn(o??a.pop,{isActive:r});let C=ap(),y=r&&!i&&!p;return G(h=>{if(l===null||h!=="["&&h!=="]")return;let R=kt[(Jr(l)+(h==="["?-1:1)+kt.length)%kt.length];R!==void 0&&a.select(R.id)},r&&!i&&!p&&!s),s?Ct(To,{header:null,hints:i?g:[...g,...x],children:n}):l!==null?Ct(To,{header:tf(ew,{children:[u&&Ct(ar,{marginBottom:X,children:Ct(Is,{width:c})}),Ct(Hp,{current:l,width:c,onPick:h=>{h===l?C():a.select(h)},isActive:y,unread:{inbox:m.any}})]}),hints:i?g:[...g,...T],children:n}):Ct(To,{header:Ct(Ls,{trail:["CodeFlow",...e??[]],width:c,onBack:C,isActive:y}),hints:i?g:[...g,...x],children:n})}function V({state:e,loading:t,width:n,children:o}){return e.phase==="loading"?Ct(Oe,{label:t}):e.phase==="error"?Ct(Ft,{message:e.message,hint:e.hint,width:n}):o(e.data)}import{jsx as Zt,jsxs as bl}from"react/jsx-runtime";function nf({params:e}){let t=O(),{width:n}=j(),o=Z(),{item:r}=e,{busy:i,error:s,run:a}=ue();tw((m,p)=>{p.return&&a("\u6B63\u5728\u786E\u8BA4",()=>ls(r.id),{onSuccess:()=>t.pop()})},{isActive:i===null});let c=Gr(r.level),l=yt(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:bl(Ds,{flexDirection:"column",children:[bl(wo,{wrap:"truncate",children:[Zt(wo,{bold:!0,color:f.foreground,children:r.title}),Zt(wo,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),Zt(wo,{color:f.faintForeground,children:` \u53D1\u5E03\u4E8E ${K(r.publishedAt)}`})]}),Zt(Ds,{marginTop:1,children:Zt(pt,{lines:hn(r.content,n),height:u})}),s!==null&&Zt(Ds,{marginTop:1,children:Zt(Ft,{message:s.message,hint:s.hint,width:n})}),Zt(Ds,{marginTop:1,children:i!==null?Zt(Oe,{label:i}):bl(wo,{wrap:"truncate",children:[Zt(wo,{color:f.accent,children:`${ae.cursor} `}),Zt(wo,{bold:!0,color:f.accent,children:"\u6211\u77E5\u9053\u4E86"})]})})]})})}import{Box as vl,Text as $s}from"ink";import{useState as dw}from"react";import{Box as Sl,Text as An}from"ink";import{useEffect as xl,useRef as nw,useState as of}from"react";import Tl from"string-width";import{jsx as Jn,jsxs as ii}from"react/jsx-runtime";var rf=e=>e===void 0?"":typeof e=="string"?e:e.text,wl=2,ow=6;function rw(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 kl(e,t,n){let o=e.map((c,l)=>Math.max(Tl(c.label),...t.map(u=>Tl(u[l]??"")))),r=o.reduce((c,l)=>c+l,0),i=r+wl*Math.max(0,e.length-1)-n;if(i<0)return rw(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)>ow).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 iw=(e,t,n)=>t.map((o,r)=>o.align==="right"?Yn(e[r]??"",n[r]??0):Je(e[r]??"",n[r]??0)).join(" ".repeat(wl)),ri=2,sw=2;function pe({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,[S,b]=Me(d?p("cursor"):void 0,()=>0),[g,T]=Me(p("query"),()=>""),[x,C]=of(!1),y=g.trim().toLowerCase(),h=y===""||s===void 0?e:e.filter($=>s($).toLowerCase().includes(y)),R=x||y!=="",I=Math.max(1,r-1-(R?1:0)),E=h.length>I?Math.max(1,I-1):I,z=Math.max(0,h.length-E),[M,v]=of(()=>S>=E?S-E+1:0);xl(()=>{b($=>Math.min($,Math.max(0,h.length-1)))},[h.length]);let k=m===void 0?-1:h.findIndex(m);xl(()=>{k>=0&&b(k)},[k]),xl(()=>{v($=>d?S<$?S:S>=$+E?S-E+1:$:Math.min($,z))},[S,E,z,d]);let _=$=>{if(!d){v(ne=>Math.min(Math.max(0,ne+$),z));return}h.length!==0&&b(ne=>(ne+$+h.length)%h.length)};G(($,ne)=>{if(ne.upArrow||$==="k"){_(-1);return}if(ne.downArrow||$==="j"){_(1);return}if(ne.return){let w=h[S];w!==void 0&&i?.(w,S);return}s!==void 0&&$.startsWith("/")&&(C(!0),$.length>1&&T($.slice(1)))},a&&!x),gn(()=>{C(!1),T("")},{isActive:x||y!=="",layer:x?Vn.input:Vn.panel});let L=R?1:0,P=nw(null),B=$=>{if($<=L)return null;let ne=M+$-L-1;return h[ne]===void 0?null:ne},J=rt({isActive:a,onWheel:_,onClick:({row:$,column:ne})=>{if(R&&$===0){C(!0),P.current?.moveToColumn(ne-sw);return}if(i===void 0)return;let w=B($);if(w===null)return;let U=h[w];U!==void 0&&(b(w),i(U,w))},onHover:d?({row:$})=>{let ne=B($);ne!==null&&b(ne)}:void 0}),oe=kl(t,h.map($=>n($).map(rf)),o-ri),fe=h.slice(M,M+E);return ii(Sl,{ref:J,flexDirection:"column",children:[R&&ii(Sl,{children:[Jn(An,{color:f.accent,children:"/ "}),Jn(nr,{ref:P,value:g,onChange:T,onSubmit:()=>C(!1),isActive:x,placeholder:"\u8F93\u5165\u5173\u952E\u8BCD\u8FC7\u6EE4",width:o-2-Tl(` ${h.length}/${e.length}`)}),Jn(An,{color:f.faintForeground,children:` ${h.length}/${e.length}`})]}),ii(An,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(ri),iw(t.map($=>$.label),t,oe)]}),h.length===0?ii(Sl,{flexDirection:"column",children:[Jn(An,{wrap:"truncate",color:f.mutedForeground,children:`${" ".repeat(ri)}${y===""?c:"\u65E0\u5339\u914D\u7ED3\u679C"}`}),l!==void 0&&y===""&&I>1&&Jn(An,{wrap:"truncate",color:f.faintForeground,children:`${" ".repeat(ri)}${l}`})]}):fe.map(($,ne)=>{let w=M+ne,U=d&&w===S&&a,re=U?f.accent:a?f.foreground:f.mutedForeground,D=n($);return ii(An,{wrap:"truncate",children:[Jn(An,{color:f.accent,children:U?`${ae.cursor} `:" "}),t.map((W,ee)=>{let he=D[ee],ie=rf(he),Qe=W.align==="right"?Yn(ie,oe[ee]??0):Je(ie,oe[ee]??0),Tt=typeof he=="object"?he.tone:void 0,Ze=!U&&a&&Tt!==void 0?et[Tt]:re;return Jn(An,{color:Ze,bold:U,children:ee>0?`${" ".repeat(wl)}${Qe}`:Qe},W.label)})]},w)}),(M>0||M+E<h.length)&&Jn(An,{color:f.faintForeground,children:`${" ".repeat(ri)}${M+1}-${Math.min(M+E,h.length)} / ${h.length}`})]})}import{Text as aw}from"ink";import{useEffect as cw,useRef as lw,useState as mw}from"react";import{jsx as uw}from"react/jsx-runtime";function We(e,t,{retain:n}={}){let[o,r]=Me(n,()=>1),[i,s]=mw({pages:1,total:0}),a=lw(!1),c=Q([...e,o],()=>t(o));cw(()=>{if(c.phase!=="ready")return;let p=Math.max(1,Math.ceil(c.data.total/iu));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 ze({page:e,pages:t,total:n,width:o}){return uw(aw,{wrap:"truncate",color:f.faintForeground,children:qe(_e([`\u7B2C ${e} / ${t} \u9875`,`\u5171 ${n} \u6761`,"\u2190\u2192 \u7FFB\u9875"]),o)})}import{jsx as En,jsxs as Cl}from"react/jsx-runtime";function sf(){let e=O(),{width:t}=j(),n=Z(),[o,r]=dw({name:"list"}),i=We([e.revision],a=>Jd({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 En(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:En(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=yt(c);return Cl(vl,{flexDirection:"column",children:[Cl($s,{wrap:"truncate",children:[En($s,{bold:!0,color:f.foreground,children:o.item.title}),En($s,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),En($s,{color:f.faintForeground,children:` ${_e([`\u53D1\u5E03\u4E8E ${K(o.item.publishedAt)}`])}`})]}),En(vl,{marginTop:1,children:En(pt,{lines:hn(o.item.content,t),height:Math.max(3,n-2)})})]})}return Cl(vl,{flexDirection:"column",children:[En(pe,{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,bt(Gr(c.level)),K(c.publishedAt)],onOpen:c=>{r({name:"detail",item:c}),ls(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"}),En(ze,{page:i.page,pages:i.pages,total:i.total,width:t})]})}})})}import{Box as at,Text as fi}from"ink";import{useState as _g}from"react";import uk from"string-width";import{z as pw}from"zod";var Bs=e=>`/community/${e.kind==="user"?"users":"staff"}/${encodeURIComponent(e.username)}`,Fs=()=>A(pw.array(Cc),"/community/categories"),cr=()=>A(ed,"/community/me"),af=e=>A(mt(Rc),Ue("/community/posts",{...e})),Us=e=>A(_c,`/community/posts/${e}`),cf=e=>A(se,`/community/posts/${e}/view`,{method:"POST"}),lf=(e,t)=>A(mt(Gi),Ue(`/community/posts/${e}/floors`,{page:t})),mf=(e,t)=>A(Gi,`/community/posts/${e}/floors/${t}`),uf=(e,t)=>A(mt(Pc),Ue(`/community/comments/${e}/replies`,{page:t})),Rl=e=>A(nd,Bs({kind:"user",username:e})),df=e=>e.kind==="user"?Rl(e.username):A(od,Bs(e)),pf=(e,t)=>A(mt(Fr),Ue(`${Bs(e)}/posts`,{page:t})),ff=(e,t)=>A(mt(Wi),Ue(`${Bs(e)}/comments`,{page:t})),gf=e=>A(mt(Rc),Ue("/community/mine/bookmarks",{page:e})),hf=e=>A(mt(Mc),Ue("/community/mine/drafts",{page:e})),yf=()=>A(Qu,"/community/mine/todo"),bf=e=>A(Ju,"/community/posts",{method:"POST",json:e}),Sf=(e,t)=>A(se,`/community/posts/${e}`,{method:"PATCH",json:t}),js=e=>A(se,`/community/posts/${e}`,{method:"DELETE"}),xf=e=>A(Zu,"/community/drafts",{method:"POST",json:e}),Tf=(e,t)=>A(se,`/community/drafts/${e}`,{method:"PATCH",json:t}),wf=(e,t)=>A(se,`/community/drafts/${e}/publish`,{method:"POST",json:t}),kf=(e,t)=>A(Xu,`/community/posts/${e}/comments`,{method:"POST",json:t}),vf=e=>A(se,`/community/comments/${e}`,{method:"DELETE"}),Cf=(e,t)=>A(Ac,`/community/posts/${e}/like`,{method:t?"PUT":"DELETE"}),Rf=(e,t)=>A(Ac,`/community/comments/${e}/like`,{method:t?"PUT":"DELETE"}),_f=(e,t)=>A(se,`/community/posts/${e}/bookmark`,{method:t?"PUT":"DELETE"}),Pf=(e,t)=>A(se,`/community/posts/${e}/reports`,{method:"POST",json:t}),Af=(e,t)=>A(se,`/community/comments/${e}/reports`,{method:"POST",json:t});var Mn=()=>A(mu,"/auth/me"),Ef=e=>A(se,"/auth/me",{method:"PATCH",json:e}),Mf=e=>A(se,"/auth/me/password",{method:"POST",json:e}),If=e=>A(se,"/auth/me/email/code",{method:"POST",json:e}),Nf=e=>A(se,"/auth/me/email",{method:"POST",json:e}),Lf=()=>A(uu,"/auth/me/sessions"),Of=e=>A(se,`/auth/me/sessions/${e}`,{method:"DELETE"});async function Df(){await A(se,"/auth/me/sessions",{method:"DELETE"}),is()}var $f=()=>A(pu,"/auth/me/security"),_l=e=>A(du,"/auth/me/totp/setup",{method:"POST",json:e}),Bf=e=>A(uc,"/auth/me/totp/confirm",{method:"POST",json:e}),Ff=e=>A(se,"/auth/me/totp/disable",{method:"POST",json:e}),Uf=e=>A(uc,"/auth/me/totp/recovery-codes",{method:"POST",json:e}),jf=(e,t)=>A(se,`/auth/me/passkeys/${e}`,{method:"PATCH",json:t}),Hf=e=>A(se,`/auth/me/passkeys/${e}`,{method:"DELETE"});var Pl=12e4,fw=e=>A(Gu,Ue("/media",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Pl}),gw=e=>A(se,`/media/${e}`,{method:"DELETE"}),si={upload:async e=>({...await fw(e),fileName:e.fileName}),discard:gw};async function qf(e){let{bytes:t,headers:n}=await Jc(`/media/${e}`,{timeoutMs:Pl}),o=n.get("content-disposition")?.split("filename*=UTF-8''")[1];if(o===void 0)throw new F("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u9644\u4EF6\u6587\u4EF6\u540D");return{fileName:decodeURIComponent(o),bytes:t}}var Gf=()=>A(Ec,"/auth/me/avatar"),Wf=e=>A(Ec,"/auth/me/avatar",{method:"PUT",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Pl}),zf=()=>A(se,"/auth/me/avatar",{method:"DELETE"});import{existsSync as Hs,readFileSync as hw,statSync as Vf,writeFileSync as yw}from"fs";import{homedir as Al}from"os";import en from"path";var bw={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif"},Kf=e=>e.startsWith("~/")?en.join(Al(),e.slice(2)):e;function Sw(e){return e.split(`
|
|
10
|
+
`).map(t=>t.trim()).filter(t=>t!=="").map(Kf)}function Yf(e,t,n){if(!Hs(e))throw new F(`${e} \u4E0D\u5B58\u5728`);let o=Vf(e);if(!o.isFile())throw new F(`${e} \u4E0D\u662F\u6587\u4EF6`);if(o.size===0)throw new F(`${e} \u662F\u7A7A\u6587\u4EF6\uFF0C\u65E0\u6CD5\u4E0A\u4F20`);if(o.size>t)throw new F(`${e} \u8D85\u8FC7\u5355\u4E2A${n}\u5927\u5C0F\u4E0A\u9650 ${Jo(t)}`);let r=en.basename(e);return{filePath:e,fileName:r,contentType:bw[en.extname(r).toLowerCase()]??"application/octet-stream"}}function Jf(e){let t;try{t=hw(e.filePath)}catch(n){throw new F(`${e.filePath} \u8BFB\u53D6\u5931\u8D25\uFF1A${Se(n)}`,{cause:n})}return{fileName:e.fileName,contentType:e.contentType,bytes:t}}function Xn(e,t){let n=Sw(e);if(n.length>t.maxCount)throw new F("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return n.map(o=>Yf(o,t.maxBytes,"\u9644\u4EF6"))}function Xf(e,t){let n=Yf(Kf(e),t,"\u56FE\u7247");if(!n.contentType.startsWith("image/"))throw new F("\u4EC5\u652F\u6301 PNG\u3001JPG\u3001WebP\u3001GIF\u3001AVIF \u683C\u5F0F\u7684\u56FE\u7247");return Jf(n)}async function In(e,t,n){let o=[];try{for(let r of e)o.push(await t.upload(Jf(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 F?r:null;throw new F(Se(r),{hint:c?.hint===void 0?a:`${c.hint}\uFF1B${a}`,...c===null?{}:{exitCode:c.exitCode},cause:r})}}function xw(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;Hs(i);s+=1)i=en.join(e,`${r}-${s}${o}`);return i}function Tw(e,t){let n=e.trim();if(n==="")return{dir:process.cwd(),fileName:t};if(n==="~")return{dir:Al(),fileName:t};let o=n.startsWith("~/")||n.startsWith(`~${en.sep}`)?en.join(Al(),n.slice(2)):n;return n.endsWith("/")||n.endsWith(en.sep)||Hs(o)&&Vf(o).isDirectory()?{dir:o,fileName:t}:{dir:en.dirname(o),fileName:en.basename(o)}}function Qf(e,t,n){let o=Tw(e,t);if(!Hs(o.dir))throw new F(`${o.dir} \u76EE\u5F55\u4E0D\u5B58\u5728`);let r=xw(o.dir,o.fileName);try{yw(r,n)}catch(i){throw new F(`\u5199\u5165 ${r} \u5931\u8D25\uFF1A${Se(i)}`,{cause:i})}return r}import{Box as tn,measureElement as sg,Text as Fe,useInput as dg}from"ink";import{useEffect as ag,useRef as cg,useState as lr}from"react";import Nl from"string-width";import{Box as ww,Text as Qn,useInput as kw}from"ink";import{useRef as Zf,useState as eg}from"react";import Ml from"string-width";import{jsx as Nn,jsxs as rg}from"react/jsx-runtime";var vw=e=>e.replace(/\r\n?/g,`
|
|
11
11
|
`).replace(new RegExp("(?!\\n)\\p{Cc}","gu"),"");function tg(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=
|
|
12
|
+
`){n.push({start:o,end:i,nl:!0}),o=i+1,r=0;continue}let a=Ml(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 ng(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 og(e,t,n){let o=0;for(let r=t.start;r<t.end;r+=1){let i=Ml(e[r]??"");if(o+i>n)return r;o+=i}return t.end}var Cw=(e,t,n)=>e.slice(t.start,n).reduce((o,r)=>o+Ml(r),0);function El(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 ig({value:e,onChange:t,isActive:n,width:o,rows:r,placeholder:i,maxLength:s,onEdge:a,onFocusRequest:c}){let l=[...e],[u,m]=eg(l.length),p=Math.min(u,l.length),[d,S]=eg(0),b=Zf(e),g=Zf(p);b.current=e,g.current=p,
|
|
15
|
-
`);return}if(!k.tab){if(k.upArrow||k.downArrow){let P=k.upArrow?-1:1;y(P)||a?.(k.upArrow?"up":"down");return}if(k.leftArrow){x(Math.max(0,L-1));return}if(k.rightArrow){x(Math.min(_.length,L+1));return}if(k.home){x(Il(_,L).start);return}if(k.end){x(Il(_,L).end);return}if(k.backspace){if(L===0)return;C([..._.slice(0,L-1),..._.slice(L)].join(""),L-1);return}if(k.delete){if(L>=_.length)return;C([..._.slice(0,L),..._.slice(L+1)].join(""),L);return}if(k.ctrl){let P=Il(_,L);if(v==="a")x(P.start);else if(v==="e")x(P.end);else if(v==="k")C([..._.slice(0,L),..._.slice(P.end)].join(""),L);else if(v==="u")C([..._.slice(0,P.start),..._.slice(L)].join(""),P.start);else if(v==="w"){let B=L;for(;B>P.start&&_[B-1]===" ";)B-=1;for(;B>P.start&&_[B-1]!==" ";)B-=1;C([..._.slice(0,B),..._.slice(L)].join(""),B)}return}k.meta||!v||h(_,L,v)}},{isActive:n});let R=tg(l,T),I=ng(R,p),E=Math.min(d,Math.max(0,R.length-r));I<E&&(E=I),I>E+r-1&&(E=I-r+1),E!==d&&S(E);let z=[];for(let v=0;v<r;v+=1){let k=E+v,_=R[k];if(_===void 0){z.push(Nn(Qn,{children:" "},k));continue}let L=l.slice(_.start,_.end).join("");if(!n||k!==I){z.push(Nn(Qn,{wrap:"truncate",color:f.foreground,children:L===""?" ":L},k));continue}let P=l.slice(_.start,p).join(""),B=p<_.end?l[p]??" ":" ",J=p<_.end?l.slice(p+1,_.end).join(""):"";z.push(rg(Qn,{wrap:"truncate",children:[Nn(Qn,{color:f.foreground,children:P}),Nn(ei,{char:B}),Nn(Qn,{color:f.foreground,children:J})]},k))}if(e===""&&i!==void 0){let v=[...i];z[0]=n?rg(Qn,{wrap:"truncate",children:[Nn(ei,{char:v[0]??" "}),Nn(Qn,{color:f.faintForeground,children:v.slice(1).join("")})]},"placeholder"):Nn(Qn,{wrap:"truncate",color:f.faintForeground,children:i},"placeholder")}let M=rt({onWheel:v=>{y(v)},onClick:({row:v,column:k})=>{c?.();let _=R[E+v];x(_===void 0?l.length:og(l,_,k))}});return Nn(ww,{ref:M,flexDirection:"column",children:z})}import{Fragment as ug,jsx as ve,jsxs as Et}from"react/jsx-runtime";var Rw=e=>Object.fromEntries(e.map(t=>[t.name,"initial"in t?t.initial??"":""])),lg="\u9009\u586B",_w=(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:e.kind==="select"?e.hint(t[e.name]??""):e.hint(t);return _w(e,t)?n===void 0?lg:`${lg} \xB7 ${n}`:n},Aw=(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},Ew=6e4,Mw=4,Ll=4,Iw=2,ci=(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]=lr(()=>Rw(t)),[d,S]=lr(0),[b,g]=lr({}),[T,x]=lr(null),[,C]=lr(0),y=c===!0,h=Aw(t,s),R=h[Math.min(d,h.length-1)],I=R?.type==="field"||R?.type==="send"?t[R.index]:void 0;ag(()=>{i?.(m)},[m]);let E=R?.type==="field"&&(I?.kind==="text"||I?.kind==="code"),z=R?.type==="field"&&I?.kind==="textarea",M=Object.values(b).some(D=>D.phase==="cooldown"&&D.until>Date.now());ag(()=>{if(!M)return;let D=setInterval(()=>C(W=>W+1),1e3);return()=>clearInterval(D)},[M]);let v=D=>S(W=>(W+D+h.length)%h.length),k=(D,W)=>{if(D.options.length===0)return;let ee=D.options.findIndex(ie=>ie.value===m[D.name]),he=D.options[(ee+W+D.options.length)%D.options.length];he!==void 0&&p(ie=>({...ie,[D.name]:he.value}))},_=D=>{R?.type!=="field"||I?.kind!=="select"||k(I,D)},L=D=>{let W=t[D];if(W===void 0||W.kind!=="code")return;let ee=(m[W.emailField]??"").trim();if(ee===""){g(ie=>({...ie,[W.name]:{phase:"error",message:"\u8BF7\u5148\u586B\u5199\u90AE\u7BB1"}}));return}let he=b[W.name];he?.phase!=="sending"&&(he?.phase==="cooldown"&&he.email===ee&&he.until>Date.now()||(g(ie=>({...ie,[W.name]:{phase:"sending"}})),W.send(ee).then(()=>g(ie=>({...ie,[W.name]:{phase:"cooldown",email:ee,until:Date.now()+Ew}}))).catch(ie=>g(Qe=>({...Qe,[W.name]:{phase:"error",message:Se(ie)}})))))};dg((D,W)=>{if(W.tab){v(W.shift?-1:1);return}if(!z){if(W.upArrow){v(-1);return}if(W.downArrow){v(1);return}if(!E){if(W.leftArrow){_(-1);return}if(W.rightArrow){_(1);return}W.return&&(R?.type==="submit"?o(m):R?.type==="secondary"?R.action.onSubmit(m):R?.type==="send"?L(R.index):v(1))}}},{isActive:!y}),gn(()=>{y||r(m)},{layer:Vn.panel}),ip(y),Re(y);let P=Math.max(0,...t.map(D=>Ol(D.label))),B=a-ge,J=Math.max(8,B-P-8),oe=(D,W)=>h.findIndex(ee=>ee.type===D&&(ee.type==="field"||ee.type==="send"?ee.index===W:!0)),fe=cg(new Map).current,$=cg(new Map).current,ne=2+P+Ll,w=(D,W)=>{let ee=h[D];if(ee===void 0)return;if(S(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(Tt=>Tt.value===m[he.name]),Qe=qe(ie?.label??"\u2014",J);W>=ne-Iw&&W<ne?k(he,-1):W>=ne+Ol(Qe)&&k(he,1);return}W>=ne&&$.get(ee.index)?.moveToColumn(W-ne)}},U=(D,W)=>{if(D===null)return null;let ee=sg(D),he=null;for(let[ie,Qe]of fe){if(Qe===null)continue;let Tt=sg(Qe),Ze=Tt.y-ee.y;W<Ze||W>=Ze+Tt.height||(he===null||Tt.height<he.box.height)&&(he={index:ie,box:Tt})}return he===null?null:{...he,frameX:ee.x}},re=rt({isActive:!y,onClick:({row:D,column:W})=>{let ee=U(re.current,D);ee!==null&&w(ee.index,W-(ee.box.x-ee.frameX))},onHover:({row:D})=>x(U(re.current,D)?.index??null),onHoverLeave:()=>x(null)});return Et(tn,{ref:re,flexDirection:"column",children:[ve(_n,{title:e,width:a}),Et(tn,{flexDirection:"column",marginTop:Ge,paddingLeft:ge,children:[u!=null&&ve(tn,{marginBottom:1,children:ve(Ft,{message:u.message,hint:u.hint,width:B})}),t.map((D,W)=>{let ee=d===oe("field",W)&&!y,he=Pw(D,m),ie=D.kind==="select"?D.options.find(Ze=>Ze.value===m[D.name]):void 0;if(D.kind==="textarea")return Et(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",W),Ze)},children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Fe,{color:ci(ee,T===oe("field",W)),bold:ee,children:D.label})]}),ve(tn,{paddingLeft:2,children:ve(ig,{value:m[D.name]??"",onChange:Ze=>p(Va=>({...Va,[D.name]:Ze})),isActive:ee,width:B-2,rows:D.rows??Mw,placeholder:D.placeholder,maxLength:D.maxLength,onEdge:Ze=>v(Ze==="up"?-1:1),onFocusRequest:()=>S(oe("field",W))})}),ee&&he!==void 0&&ve(Fe,{color:f.faintForeground,children:` ${qe(he,B-2)}`})]},D.name);let Qe=D.kind==="code"&&d===oe("send",W)&&!y,Tt=b[D.name];return Et(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",W),Ze)},children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Fe,{color:ci(ee,T===oe("field",W)),bold:ee,children:Je(D.label,P)}),D.kind==="select"?Et(ug,{children:[ve(Fe,{color:ee?f.accent:f.border,children:` ${ae.prev} `}),ve(Fe,{color:f.foreground,children:qe(ie?.label??"\u2014",J)}),ve(Fe,{color:ee?f.accent:f.border,children:` ${ae.next}`})]}):Et(ug,{children:[ve(Fe,{children:" ".repeat(Ll)}),ve(nr,{ref:Ze=>{$.set(W,Ze)},value:m[D.name]??"",onChange:Ze=>p(Va=>({...Va,[D.name]:Ze})),onSubmit:()=>v(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(Fe,{color:f.faintForeground,children:`${" ".repeat(2+P+Ll)}${qe(he,J)}`}),D.kind==="code"&&ve(Nw,{active:Qe,state:Tt,email:(m[D.emailField]??"").trim(),indent:ne,width:J,hovered:T===oe("send",W),nodeRef:Ze=>{fe.set(oe("send",W),Ze)}})]},D.name)}),Et(tn,{marginTop:1,flexDirection:"column",children:[ve(tn,{ref:D=>{fe.set(oe("submit"),D)},children:y?ve(Oe,{label:l}):Et(Fe,{children:[ve(Fe,{color:f.accent,children:R?.type==="submit"?`${ae.cursor} `:" "}),ve(Fe,{color:ci(R?.type==="submit",T===oe("submit")),bold:R?.type==="submit",children:n})]})}),s!==void 0&&!y&&ve(tn,{ref:D=>{fe.set(oe("secondary"),D)},children:Et(Fe,{children:[ve(Fe,{color:f.accent,children:R?.type==="secondary"?`${ae.cursor} `:" "}),ve(Fe,{color:ci(R?.type==="secondary",T===oe("secondary")),bold:R?.type==="secondary",children:s.label})]})})]})]})]})}function Nw({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 Et(tn,{ref:s,flexDirection:"column",paddingLeft:o-2,children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:e?`${ae.cursor} `:" "}),ve(Fe,{color:a>0?f.faintForeground:ci(e,i),bold:e&&a===0,children:c})]}),t?.phase==="error"&&ve(Fe,{color:f.danger,children:` ${qe(t.message,r)}`})]})}var Lw=2,mg=2;function Gs({options:e,value:t,onChange:n,arrowKeys:o=!0}){let r=e.findIndex(m=>m.value===t),i=ys();dg((m,p)=>{if(!p.leftArrow&&!p.rightArrow)return;let d=p.leftArrow?-1:1,S=e[(r+d+e.length)%e.length];S!==void 0&&n(S.value)},{isActive:o&&!i});let s=[],a=0;e.forEach((m,p)=>{p>0&&(a+=mg);let d=Ol(m.label)+Lw;s.push({value:m.value,from:a,to:a+d}),a+=d});let[c,l]=lr(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(Fe,{wrap:"truncate",children:e.map((m,p)=>{let d=m.value===t;return Et(Fe,{children:[p>0&&" ".repeat(mg),ve(Fe,{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 pg,Text as Sn}from"ink";import Ow from"string-width";import{jsx as bn,jsxs as Dl}from"react/jsx-runtime";var Ws=3,Ln=2,ko=10,Dw=8,fg=e=>Math.floor((e-Ws)/Ln),mr=e=>fg(e)>=Dw;function $w(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=Wn(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 Bw(e,t){let n=t*Ln,o="",r=0,i="";for(;r<n;){let s=r%Ln===0?e[r/Ln*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=Ow(c);if(r+l<=n){o+=c,r+=l;continue}}}o+=" ",r+=1}return o}var Fw={1:"\u4E00",3:"\u4E09",5:"\u4E94"};function Uw({cells:e,day:t,weeks:n}){return Dl(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.faintForeground,children:Je(Fw[t]??"",Ws)}),Array.from({length:n},(o,r)=>{let i=e[r*7+t];return i===void 0?bn(Sn,{children:" ".repeat(Ln)},r):bn(Sn,{backgroundColor:Ts[i.level],children:" ".repeat(Ln)},r)})]})}function ur({data:e,value:t,caption:n,width:o}){let r=$w(e,t),i=Math.ceil(r.length/7),s=Math.min(i,fg(o)),a=r.slice((i-s)*7),c=3+Ts.length*Ln+3,l=Math.max(0,Ws+s*Ln-c-2);return Dl(pg,{flexDirection:"column",children:[bn(Sn,{wrap:"truncate",color:f.faintForeground,children:" ".repeat(Ws)+Bw(a,s)}),Array.from({length:7},(u,m)=>bn(Uw,{cells:a,day:m,weeks:s},m)),bn(pg,{marginTop:1,children:Dl(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.mutedForeground,children:Je(n??"",l)})," ",bn(Sn,{color:f.faintForeground,children:"\u5C11 "}),Ts.map(u=>bn(Sn,{backgroundColor:u,children:" ".repeat(Ln)},u)),bn(Sn,{color:f.faintForeground,children:" \u591A"})]})})]})}import{Box as Fl,Text as gg}from"ink";import jw from"qrcode";import{jsx as li,jsxs as Vw}from"react/jsx-runtime";var Hw="#000000",qw="#ffffff",$l=2,yg=2,Ul=1,hg,Bl;function bg(e){if(e===hg&&Bl!==void 0)return Bl;let t=jw.create(e,{errorCorrectionLevel:"L"}),n=t.modules.size,o=t.modules.data,r=n+$l*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+$l];c!==void 0&&(c[a+$l]=o[s*n+a]===1)}return hg=e,Bl=i,i}function Gw(e){let t=bg(e).length;return{columns:t*yg,rows:t}}function zs(e,t,n,o){let r=Gw(e),i=t.rows-r.rows-Ul;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+Ul+n.rows+o.rows}}}function Ww(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(gg,{backgroundColor:e[o]??!1?Hw:qw,children:" ".repeat((r-o)*yg)},o)),o=r);return li(gg,{children:n},t)}function zw({value:e}){return li(Fl,{flexDirection:"column",flexShrink:0,children:bg(e).map((t,n)=>Ww(t,n))})}function Vs({value:e,aside:t}){return Vw(Fl,{flexDirection:"column",flexShrink:0,children:[li(zw,{value:e}),li(Fl,{marginTop:Ul,flexDirection:"column",children:t})]})}import{Box as Ks,Text as Mt}from"ink";import Sg from"string-width";import{jsx as It,jsxs as mi}from"react/jsx-runtime";var Ys=2,jl=4,xg=e=>" ".repeat(e),Hl=13,Tg=4,wg=(e,t,n)=>Math.max(1,Math.min(e,n,Math.floor((t+Ys)/(Hl+Ys)))),Ut=(e,t,n=Tg)=>Math.ceil(e/wg(e,t,n))*2;function it({tiles:e,width:t,maxPerRow:n=Tg}){let o=wg(e.length,t,n),r=Math.floor((t-Ys*(o-1))/o),i=[];for(let s=0;s<e.length;s+=o)i.push(e.slice(s,s+o));return It(Ks,{flexDirection:"column",children:i.map((s,a)=>It(Ks,{flexDirection:"column",children:["label","value"].map(c=>It(Mt,{wrap:"truncate",children:s.map((l,u)=>mi(Mt,{children:[u>0&&xg(Ys),It(Mt,{color:c==="label"?f.mutedForeground:f.foreground,bold:c==="value",children:Je(l[c],r)})]},l.label))},c))},a))})}function kg({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 mi(Mt,{children:[It(Mt,{color:i,children:ae.barFilled.repeat(r)}),It(Mt,{color:f.border,children:ae.barEmpty.repeat(n-r)})]})}function ql({items:e,width:t}){let n=Math.max(0,...e.map(([r])=>Sg(r))),o=Math.max(0,t-n-3);return It(Ks,{flexDirection:"column",children:e.map(([r,i])=>mi(Mt,{wrap:"truncate",children:[It(Mt,{color:f.mutedForeground,children:Je(r,n)})," ",It(Mt,{color:f.foreground,children:qe(i,o)})]},r))})}var Js=(e,t)=>Math.floor((t-jl)/2)<Hl*2?e:Math.ceil(e/2);function Ve({items:e,width:t}){let n=Math.floor((t-jl)/2);if(n<Hl*2)return It(ql,{items:e,width:t});let o=Math.max(0,...e.map(([a])=>Sg(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?It(Mt,{children:" ".repeat(n)}):mi(Mt,{children:[It(Mt,{color:f.mutedForeground,children:Je(a[0],o)})," ",It(Mt,{color:f.foreground,children:Je(a[1],r)})]});return It(Ks,{flexDirection:"column",children:i.map((a,c)=>mi(Mt,{wrap:"truncate",children:[s(a[0]),xg(jl),s(a[1])]},c))})}import{Lexer as Kw}from"marked";var Yw=new RegExp("\\p{Cc}","gu"),Jw=/[\\[\]]/g,Xw=/[\\`*_{}[\]()#+\-.!|<>~]/g,Qw=/[\uD800-\uDBFF]$/,Zw=400,ek=12,tk=20,dr={label:"\u677F\u5757",cap:ek},Zn={label:"\u4F5C\u8005",cap:tk},Xs={maxCount:Uu,maxBytes:Br},Qs={maxCount:ju,maxBytes:Br},st=e=>e.replace(Yw,""),ui=e=>({kind:e.kind,username:e.username});function Rt(e){let t=st(e.username);return e.kind==="user"?`${t} Lv.${Vi(e.points).level}`:`${t} [${Ji}]`}var Zs=e=>`@${st(e.username)}`,vg=e=>e.flatMap(t=>[{reply:t.reply,mention:t.mention,prefix:""},...Cg(t.children,"")]);function Cg(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 "}`},...Cg(n.children,`${t}${r?" ":"\u2502 "}`)]})}var On=(e,t)=>e.kind==="user"&&e.username===t,Gl=e=>`${e.image?"[\u56FE\u7247]":"[\u9644\u4EF6]"} ${st(e.name)}`;function jt(e){let t=new Set;return Ku(e).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}var nk=e=>kc(e,t=>Gl(t).replace(Xw,"\\$&")),di=(e,t)=>hn(nk(e),t);function vo(e){let t=kc(e,n=>n.image?"[\u56FE\u7247]":`[\u9644\u4EF6] ${n.name}`).slice(0,Zw).replace(Qw,"");return st(yd(Kw.lex(t,{gfm:!0,breaks:!0}))).trim()}var ok=e=>st(e).trim().replace(Jw,"\\$&");function pi(e,t){if(t.length===0)return e;let n=t.map(o=>`${o.image===null?"":"!"}[${ok(o.fileName)}](${Hu(o.id)})`).join(`
|
|
14
|
+
`;)o+=1;return{start:n,end:o}}function ig({value:e,onChange:t,isActive:n,width:o,rows:r,placeholder:i,maxLength:s,onEdge:a,onFocusRequest:c}){let l=[...e],[u,m]=eg(l.length),p=Math.min(u,l.length),[d,S]=eg(0),b=Zf(e),g=Zf(p);b.current=e,g.current=p,fs(n);let T=Math.max(4,o),x=v=>{g.current=v,m(v)},C=(v,k)=>{b.current=v,x(k),t(v)},y=v=>{let k=[...b.current],_=Math.min(g.current,k.length),L=tg(k,T),P=ng(L,_),B=L[P],J=L[P+v];return B===void 0||J===void 0?!1:(x(og(k,J,Cw(k,B,_))),!0)},h=(v,k,_)=>{let L=vw(_);if(s!==void 0){let P=s-v.length;if(P<=0)return;L=[...L].slice(0,P).join("")}L!==""&&C([...v.slice(0,k),L,...v.slice(k)].join(""),k+[...L].length)};kw((v,k)=>{let _=[...b.current],L=Math.min(g.current,_.length);if(k.return){h(_,L,`
|
|
15
|
+
`);return}if(!k.tab){if(k.upArrow||k.downArrow){let P=k.upArrow?-1:1;y(P)||a?.(k.upArrow?"up":"down");return}if(k.leftArrow){x(Math.max(0,L-1));return}if(k.rightArrow){x(Math.min(_.length,L+1));return}if(k.home){x(El(_,L).start);return}if(k.end){x(El(_,L).end);return}if(k.backspace){if(L===0)return;C([..._.slice(0,L-1),..._.slice(L)].join(""),L-1);return}if(k.delete){if(L>=_.length)return;C([..._.slice(0,L),..._.slice(L+1)].join(""),L);return}if(k.ctrl){let P=El(_,L);if(v==="a")x(P.start);else if(v==="e")x(P.end);else if(v==="k")C([..._.slice(0,L),..._.slice(P.end)].join(""),L);else if(v==="u")C([..._.slice(0,P.start),..._.slice(L)].join(""),P.start);else if(v==="w"){let B=L;for(;B>P.start&&_[B-1]===" ";)B-=1;for(;B>P.start&&_[B-1]!==" ";)B-=1;C([..._.slice(0,B),..._.slice(L)].join(""),B)}return}k.meta||!v||h(_,L,v)}},{isActive:n});let R=tg(l,T),I=ng(R,p),E=Math.min(d,Math.max(0,R.length-r));I<E&&(E=I),I>E+r-1&&(E=I-r+1),E!==d&&S(E);let z=[];for(let v=0;v<r;v+=1){let k=E+v,_=R[k];if(_===void 0){z.push(Nn(Qn,{children:" "},k));continue}let L=l.slice(_.start,_.end).join("");if(!n||k!==I){z.push(Nn(Qn,{wrap:"truncate",color:f.foreground,children:L===""?" ":L},k));continue}let P=l.slice(_.start,p).join(""),B=p<_.end?l[p]??" ":" ",J=p<_.end?l.slice(p+1,_.end).join(""):"";z.push(rg(Qn,{wrap:"truncate",children:[Nn(Qn,{color:f.foreground,children:P}),Nn(Zr,{char:B}),Nn(Qn,{color:f.foreground,children:J})]},k))}if(e===""&&i!==void 0){let v=[...i];z[0]=n?rg(Qn,{wrap:"truncate",children:[Nn(Zr,{char:v[0]??" "}),Nn(Qn,{color:f.faintForeground,children:v.slice(1).join("")})]},"placeholder"):Nn(Qn,{wrap:"truncate",color:f.faintForeground,children:i},"placeholder")}let M=rt({onWheel:v=>{y(v)},onClick:({row:v,column:k})=>{c?.();let _=R[E+v];x(_===void 0?l.length:og(l,_,k))}});return Nn(ww,{ref:M,flexDirection:"column",children:z})}import{Fragment as ug,jsx as ve,jsxs as Et}from"react/jsx-runtime";var Rw=e=>Object.fromEntries(e.map(t=>[t.name,"initial"in t?t.initial??"":""])),lg="\u9009\u586B",_w=(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:e.kind==="select"?e.hint(t[e.name]??""):e.hint(t);return _w(e,t)?n===void 0?lg:`${lg} \xB7 ${n}`:n},Aw=(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},Ew=6e4,Mw=4,Il=4,Iw=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]=lr(()=>Rw(t)),[d,S]=lr(0),[b,g]=lr({}),[T,x]=lr(null),[,C]=lr(0),y=c===!0,h=Aw(t,s),R=h[Math.min(d,h.length-1)],I=R?.type==="field"||R?.type==="send"?t[R.index]:void 0;ag(()=>{i?.(m)},[m]);let E=R?.type==="field"&&(I?.kind==="text"||I?.kind==="code"),z=R?.type==="field"&&I?.kind==="textarea",M=Object.values(b).some(D=>D.phase==="cooldown"&&D.until>Date.now());ag(()=>{if(!M)return;let D=setInterval(()=>C(W=>W+1),1e3);return()=>clearInterval(D)},[M]);let v=D=>S(W=>(W+D+h.length)%h.length),k=(D,W)=>{if(D.options.length===0)return;let ee=D.options.findIndex(ie=>ie.value===m[D.name]),he=D.options[(ee+W+D.options.length)%D.options.length];he!==void 0&&p(ie=>({...ie,[D.name]:he.value}))},_=D=>{R?.type!=="field"||I?.kind!=="select"||k(I,D)},L=D=>{let W=t[D];if(W===void 0||W.kind!=="code")return;let ee=(m[W.emailField]??"").trim();if(ee===""){g(ie=>({...ie,[W.name]:{phase:"error",message:"\u8BF7\u5148\u586B\u5199\u90AE\u7BB1"}}));return}let he=b[W.name];he?.phase!=="sending"&&(he?.phase==="cooldown"&&he.email===ee&&he.until>Date.now()||(g(ie=>({...ie,[W.name]:{phase:"sending"}})),W.send(ee).then(()=>g(ie=>({...ie,[W.name]:{phase:"cooldown",email:ee,until:Date.now()+Ew}}))).catch(ie=>g(Qe=>({...Qe,[W.name]:{phase:"error",message:Se(ie)}})))))};dg((D,W)=>{if(W.tab){v(W.shift?-1:1);return}if(!z){if(W.upArrow){v(-1);return}if(W.downArrow){v(1);return}if(!E){if(W.leftArrow){_(-1);return}if(W.rightArrow){_(1);return}W.return&&(R?.type==="submit"?o(m):R?.type==="secondary"?R.action.onSubmit(m):R?.type==="send"?L(R.index):v(1))}}},{isActive:!y}),gn(()=>{y||r(m)},{layer:Vn.panel}),ip(y),Re(y);let P=Math.max(0,...t.map(D=>Nl(D.label))),B=a-ge,J=Math.max(8,B-P-8),oe=(D,W)=>h.findIndex(ee=>ee.type===D&&(ee.type==="field"||ee.type==="send"?ee.index===W:!0)),fe=cg(new Map).current,$=cg(new Map).current,ne=2+P+Il,w=(D,W)=>{let ee=h[D];if(ee===void 0)return;if(S(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(Tt=>Tt.value===m[he.name]),Qe=qe(ie?.label??"\u2014",J);W>=ne-Iw&&W<ne?k(he,-1):W>=ne+Nl(Qe)&&k(he,1);return}W>=ne&&$.get(ee.index)?.moveToColumn(W-ne)}},U=(D,W)=>{if(D===null)return null;let ee=sg(D),he=null;for(let[ie,Qe]of fe){if(Qe===null)continue;let Tt=sg(Qe),Ze=Tt.y-ee.y;W<Ze||W>=Ze+Tt.height||(he===null||Tt.height<he.box.height)&&(he={index:ie,box:Tt})}return he===null?null:{...he,frameX:ee.x}},re=rt({isActive:!y,onClick:({row:D,column:W})=>{let ee=U(re.current,D);ee!==null&&w(ee.index,W-(ee.box.x-ee.frameX))},onHover:({row:D})=>x(U(re.current,D)?.index??null),onHoverLeave:()=>x(null)});return Et(tn,{ref:re,flexDirection:"column",children:[ve(_n,{title:e,width:a}),Et(tn,{flexDirection:"column",marginTop:Ge,paddingLeft:ge,children:[u!=null&&ve(tn,{marginBottom:1,children:ve(Ft,{message:u.message,hint:u.hint,width:B})}),t.map((D,W)=>{let ee=d===oe("field",W)&&!y,he=Pw(D,m),ie=D.kind==="select"?D.options.find(Ze=>Ze.value===m[D.name]):void 0;if(D.kind==="textarea")return Et(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",W),Ze)},children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Fe,{color:ai(ee,T===oe("field",W)),bold:ee,children:D.label})]}),ve(tn,{paddingLeft:2,children:ve(ig,{value:m[D.name]??"",onChange:Ze=>p(Wa=>({...Wa,[D.name]:Ze})),isActive:ee,width:B-2,rows:D.rows??Mw,placeholder:D.placeholder,maxLength:D.maxLength,onEdge:Ze=>v(Ze==="up"?-1:1),onFocusRequest:()=>S(oe("field",W))})}),ee&&he!==void 0&&ve(Fe,{color:f.faintForeground,children:` ${qe(he,B-2)}`})]},D.name);let Qe=D.kind==="code"&&d===oe("send",W)&&!y,Tt=b[D.name];return Et(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",W),Ze)},children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Fe,{color:ai(ee,T===oe("field",W)),bold:ee,children:Je(D.label,P)}),D.kind==="select"?Et(ug,{children:[ve(Fe,{color:ee?f.accent:f.border,children:` ${ae.prev} `}),ve(Fe,{color:f.foreground,children:qe(ie?.label??"\u2014",J)}),ve(Fe,{color:ee?f.accent:f.border,children:` ${ae.next}`})]}):Et(ug,{children:[ve(Fe,{children:" ".repeat(Il)}),ve(nr,{ref:Ze=>{$.set(W,Ze)},value:m[D.name]??"",onChange:Ze=>p(Wa=>({...Wa,[D.name]:Ze})),onSubmit:()=>v(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(Fe,{color:f.faintForeground,children:`${" ".repeat(2+P+Il)}${qe(he,J)}`}),D.kind==="code"&&ve(Nw,{active:Qe,state:Tt,email:(m[D.emailField]??"").trim(),indent:ne,width:J,hovered:T===oe("send",W),nodeRef:Ze=>{fe.set(oe("send",W),Ze)}})]},D.name)}),Et(tn,{marginTop:1,flexDirection:"column",children:[ve(tn,{ref:D=>{fe.set(oe("submit"),D)},children:y?ve(Oe,{label:l}):Et(Fe,{children:[ve(Fe,{color:f.accent,children:R?.type==="submit"?`${ae.cursor} `:" "}),ve(Fe,{color:ai(R?.type==="submit",T===oe("submit")),bold:R?.type==="submit",children:n})]})}),s!==void 0&&!y&&ve(tn,{ref:D=>{fe.set(oe("secondary"),D)},children:Et(Fe,{children:[ve(Fe,{color:f.accent,children:R?.type==="secondary"?`${ae.cursor} `:" "}),ve(Fe,{color:ai(R?.type==="secondary",T===oe("secondary")),bold:R?.type==="secondary",children:s.label})]})})]})]})]})}function Nw({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 Et(tn,{ref:s,flexDirection:"column",paddingLeft:o-2,children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:e?`${ae.cursor} `:" "}),ve(Fe,{color:a>0?f.faintForeground:ai(e,i),bold:e&&a===0,children:c})]}),t?.phase==="error"&&ve(Fe,{color:f.danger,children:` ${qe(t.message,r)}`})]})}var Lw=2,mg=2;function qs({options:e,value:t,onChange:n,arrowKeys:o=!0}){let r=e.findIndex(m=>m.value===t),i=hs();dg((m,p)=>{if(!p.leftArrow&&!p.rightArrow)return;let d=p.leftArrow?-1:1,S=e[(r+d+e.length)%e.length];S!==void 0&&n(S.value)},{isActive:o&&!i});let s=[],a=0;e.forEach((m,p)=>{p>0&&(a+=mg);let d=Nl(m.label)+Lw;s.push({value:m.value,from:a,to:a+d}),a+=d});let[c,l]=lr(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(Fe,{wrap:"truncate",children:e.map((m,p)=>{let d=m.value===t;return Et(Fe,{children:[p>0&&" ".repeat(mg),ve(Fe,{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 pg,Text as Sn}from"ink";import Ow from"string-width";import{jsx as bn,jsxs as Ll}from"react/jsx-runtime";var Gs=3,Ln=2,ko=10,Dw=8,fg=e=>Math.floor((e-Gs)/Ln),mr=e=>fg(e)>=Dw;function $w(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=Wn(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 Bw(e,t){let n=t*Ln,o="",r=0,i="";for(;r<n;){let s=r%Ln===0?e[r/Ln*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=Ow(c);if(r+l<=n){o+=c,r+=l;continue}}}o+=" ",r+=1}return o}var Fw={1:"\u4E00",3:"\u4E09",5:"\u4E94"};function Uw({cells:e,day:t,weeks:n}){return Ll(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.faintForeground,children:Je(Fw[t]??"",Gs)}),Array.from({length:n},(o,r)=>{let i=e[r*7+t];return i===void 0?bn(Sn,{children:" ".repeat(Ln)},r):bn(Sn,{backgroundColor:xs[i.level],children:" ".repeat(Ln)},r)})]})}function ur({data:e,value:t,caption:n,width:o}){let r=$w(e,t),i=Math.ceil(r.length/7),s=Math.min(i,fg(o)),a=r.slice((i-s)*7),c=3+xs.length*Ln+3,l=Math.max(0,Gs+s*Ln-c-2);return Ll(pg,{flexDirection:"column",children:[bn(Sn,{wrap:"truncate",color:f.faintForeground,children:" ".repeat(Gs)+Bw(a,s)}),Array.from({length:7},(u,m)=>bn(Uw,{cells:a,day:m,weeks:s},m)),bn(pg,{marginTop:1,children:Ll(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.mutedForeground,children:Je(n??"",l)})," ",bn(Sn,{color:f.faintForeground,children:"\u5C11 "}),xs.map(u=>bn(Sn,{backgroundColor:u,children:" ".repeat(Ln)},u)),bn(Sn,{color:f.faintForeground,children:" \u591A"})]})})]})}import{Box as $l,Text as gg}from"ink";import jw from"qrcode";import{jsx as ci,jsxs as Vw}from"react/jsx-runtime";var Hw="#000000",qw="#ffffff",Ol=2,yg=2,Bl=1,hg,Dl;function bg(e){if(e===hg&&Dl!==void 0)return Dl;let t=jw.create(e,{errorCorrectionLevel:"L"}),n=t.modules.size,o=t.modules.data,r=n+Ol*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+Ol];c!==void 0&&(c[a+Ol]=o[s*n+a]===1)}return hg=e,Dl=i,i}function Gw(e){let t=bg(e).length;return{columns:t*yg,rows:t}}function Ws(e,t,n,o){let r=Gw(e),i=t.rows-r.rows-Bl;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+Bl+n.rows+o.rows}}}function Ww(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(gg,{backgroundColor:e[o]??!1?Hw:qw,children:" ".repeat((r-o)*yg)},o)),o=r);return ci(gg,{children:n},t)}function zw({value:e}){return ci($l,{flexDirection:"column",flexShrink:0,children:bg(e).map((t,n)=>Ww(t,n))})}function zs({value:e,aside:t}){return Vw($l,{flexDirection:"column",flexShrink:0,children:[ci(zw,{value:e}),ci($l,{marginTop:Bl,flexDirection:"column",children:t})]})}import{Box as Vs,Text as Mt}from"ink";import Sg from"string-width";import{jsx as It,jsxs as li}from"react/jsx-runtime";var Ks=2,Fl=4,xg=e=>" ".repeat(e),Ul=13,Tg=4,wg=(e,t,n)=>Math.max(1,Math.min(e,n,Math.floor((t+Ks)/(Ul+Ks)))),Ut=(e,t,n=Tg)=>Math.ceil(e/wg(e,t,n))*2;function it({tiles:e,width:t,maxPerRow:n=Tg}){let o=wg(e.length,t,n),r=Math.floor((t-Ks*(o-1))/o),i=[];for(let s=0;s<e.length;s+=o)i.push(e.slice(s,s+o));return It(Vs,{flexDirection:"column",children:i.map((s,a)=>It(Vs,{flexDirection:"column",children:["label","value"].map(c=>It(Mt,{wrap:"truncate",children:s.map((l,u)=>li(Mt,{children:[u>0&&xg(Ks),It(Mt,{color:c==="label"?f.mutedForeground:f.foreground,bold:c==="value",children:Je(l[c],r)})]},l.label))},c))},a))})}function kg({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(Mt,{children:[It(Mt,{color:i,children:ae.barFilled.repeat(r)}),It(Mt,{color:f.border,children:ae.barEmpty.repeat(n-r)})]})}function jl({items:e,width:t}){let n=Math.max(0,...e.map(([r])=>Sg(r))),o=Math.max(0,t-n-3);return It(Vs,{flexDirection:"column",children:e.map(([r,i])=>li(Mt,{wrap:"truncate",children:[It(Mt,{color:f.mutedForeground,children:Je(r,n)})," ",It(Mt,{color:f.foreground,children:qe(i,o)})]},r))})}var Ys=(e,t)=>Math.floor((t-Fl)/2)<Ul*2?e:Math.ceil(e/2);function Ve({items:e,width:t}){let n=Math.floor((t-Fl)/2);if(n<Ul*2)return It(jl,{items:e,width:t});let o=Math.max(0,...e.map(([a])=>Sg(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?It(Mt,{children:" ".repeat(n)}):li(Mt,{children:[It(Mt,{color:f.mutedForeground,children:Je(a[0],o)})," ",It(Mt,{color:f.foreground,children:Je(a[1],r)})]});return It(Vs,{flexDirection:"column",children:i.map((a,c)=>li(Mt,{wrap:"truncate",children:[s(a[0]),xg(Fl),s(a[1])]},c))})}import{Lexer as Kw}from"marked";var Yw=new RegExp("\\p{Cc}","gu"),Jw=/[\\[\]]/g,Xw=/[\\`*_{}[\]()#+\-.!|<>~]/g,Qw=/[\uD800-\uDBFF]$/,Zw=400,ek=12,tk=20,dr={label:"\u677F\u5757",cap:ek},Zn={label:"\u4F5C\u8005",cap:tk},Hl={maxCount:Uu,maxBytes:$r},ql={maxCount:ju,maxBytes:$r},st=e=>e.replace(Yw,""),mi=e=>({kind:e.kind,username:e.username});function Rt(e){let t=st(e.username);return e.kind==="user"?`${t} Lv.${zi(e.points).level}`:`${t} [${Yi}]`}var Js=e=>`@${st(e.username)}`,vg=e=>e.flatMap(t=>[{reply:t.reply,mention:t.mention,prefix:""},...Cg(t.children,"")]);function Cg(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 "}`},...Cg(n.children,`${t}${r?" ":"\u2502 "}`)]})}var On=(e,t)=>e.kind==="user"&&e.username===t,Gl=e=>`${e.image?"[\u56FE\u7247]":"[\u9644\u4EF6]"} ${st(e.name)}`;function jt(e){let t=new Set;return Ku(e).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}var nk=e=>Tc(e,t=>Gl(t).replace(Xw,"\\$&")),ui=(e,t)=>hn(nk(e),t);function vo(e){let t=Tc(e,n=>n.image?"[\u56FE\u7247]":`[\u9644\u4EF6] ${n.name}`).slice(0,Zw).replace(Qw,"");return st(yd(Kw.lex(t,{gfm:!0,breaks:!0}))).trim()}var ok=e=>st(e).trim().replace(Jw,"\\$&");function di(e,t){if(t.length===0)return e;let n=t.map(o=>`${o.image===null?"":"!"}[${ok(o.fileName)}](${Hu(o.id)})`).join(`
|
|
16
16
|
`);return e===""?n:`${e}
|
|
17
17
|
|
|
18
|
-
${n}`}import{Box as Rg,Text as ik}from"ink";import{useState as ea}from"react";import{jsx as rk}from"react/jsx-runtime";function pr({title:e,width:t,download:n,onCancel:o,onSaved:r}){let{busy:i,error:s,run:a}=ue();return rk(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 Qf(c.path??"",l.fileName,l.bytes)},{onSuccess:r})}})}var fr={maxCount:Tu,maxBytes:xu},eo=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 Dn,jsxs as mk}from"react/jsx-runtime";var ta=e=>e===null?void 0:`\u539F\u56E0\uFF1A${e}`,gr=(e,t)=>e===null?0:gl(Bc(e.until),ta(e.reason),t)+1;function Co({muted:e,width:t}){return e===null?null:Dn(Rg,{marginBottom:1,children:Dn(ye,{tone:"warn",width:t,title:Bc(e.until),detail:ta(e.reason),wrap:!0})})}var na=(e,t,n,o)=>t==="published"?0:gl(e[t],ta(n),o);function Ro({notices:e,status:t,reason:n,width:o}){return t==="published"?null:Dn(ye,{tone:t==="pending"?"warn":"fail",title:e[t],detail:ta(n),width:o,wrap:!0})}var fi=e=>e===null?0:(e.hint===void 0?1:2)+1,sk=["content","attachments"],ak=9,ck=3,lk=8;function oa({postId:e,replyTo:t,width:n,height:o,onDone:r,onCancel:i}){let{busy:s,error:a,fail:c,run:l}=ue(),[u,m]=ea({content:"",attachments:""}),[p,d]=ea(!1),S=sk.some(g=>(u[g]??"").trim()!==""),b=Math.min(lk,Math.max(ck,o-ak-fi(a)));return Re(S),gn(()=>d(!1),{isActive:p,layer:Vn.panel}),G(g=>{g==="q"&&S&&d(!0)},!p&&s===null),p?Dn(Pe,{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)}):Dn(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:b,maxLength:vc,initial:u.content,placeholder:t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9\uFF0C\u652F\u6301 Markdown":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9"},{...eo(Qs),initial:u.attachments}],onChange:m,onCancel:()=>S?d(!0):i(),onSubmit:g=>{let T=(g.content??"").trim(),x;try{x=Xn(g.attachments??"",Qs)}catch(C){c(Se(C));return}if(T===""&&x.length===0){c(t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9");return}if(jt(T).length+x.length>Qs.maxCount){c("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return}l("\u6B63\u5728\u63D0\u4EA4",()=>In(x,ai,C=>kf(e,{content:pi(T,C),...t===null?{}:{replyToId:t.id}})),{onSuccess:C=>r(C.id)})}})}function ra({target:e,width:t,onDone:n,onCancel:o}){let{busy:r,error:i,fail:s,run:a}=ue();return Dn(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"},...Ni.map(c=>({value:c,label:Cd(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=Ni.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>Hi){s(`\u8865\u5145\u8BF4\u660E\u6700\u591A ${Hi} \u4E2A\u5B57\u7B26`);return}let m={reason:l,detail:u===""?null:u};a("\u6B63\u5728\u63D0\u4EA4",()=>e.kind==="post"?Pf(e.id,m):Af(e.id,m),{onSuccess:n})}})}function ia({refs:e,width:t,height:n}){let o=O(),[r,i]=ea(null),[s,a]=ea(null);return r!==null?Dn(pr,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${st(r.name)}`,width:t,download:async()=>{let c=await qf(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")}}):mk(Rg,{flexDirection:"column",children:[Dn(le,{width:t,height:Math.max(3,n-(s===null?0:1)),items:[{heading:"\u9644\u4EF6"},...e.map(c=>({value:c,label:Gl(c)}))],onSelect:c=>{a(null),i(c)}}),s!==null&&Dn(ik,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${st(s)}`})]})}import{Fragment as bk,jsx as me,jsxs as xn}from"react/jsx-runtime";var dk={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"},Pg="\u5BC6\u94A5 ",pk=10,fk={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"}},gk=3,hk=8;function yk({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(gi,{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 Ag(){let e=O(),{width:t,columns:n,rows:o}=j(),r=Z(),[i,s]=_g({name:"menu"}),[a,c]=_g(!1),{busy:l,error:u,reset:m,fail:p,run:d}=ue(),S=Q([e.revision],async()=>{let[y,h,R,I]=await Promise.all([Mn(),$f(),Lf(),Gf()]);return{user:y.user,security:h,sessions:R.sessions,avatarReview:I.review}}),b=Q([e.revision],async()=>{let[y,h]=await Promise.all([Mn(),yf()]);return{homepage:await Pl(y.user.username),todo:h}});G(y=>{i.name==="menu"&&l===null&&y==="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"})}},T=y=>{s({name:"menu"}),e.reload(),e.toast("ok",y)},x=(y,h)=>{c(!1),s({name:"codes",codes:y,message:h})},C=(y,h)=>{y==="rebind"?d("\u6B63\u5728\u751F\u6210\u65B0\u5BC6\u94A5",()=>Al({code:h}),{onSuccess:R=>s({name:"enroll",setup:R})}):y==="regenerate"?d("\u6B63\u5728\u751F\u6210\u6062\u590D\u7801",()=>Uf({code:h}),{onSuccess:({recoveryCodes:R})=>x(R,"\u6062\u590D\u7801\u5DF2\u66F4\u65B0")}):d("\u6B63\u5728\u505C\u7528",()=>Ff({code:h}),{onSuccess:()=>T("\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:S,loading:"\u6B63\u5728\u8BFB\u53D6\u8D26\u6237\u4FE1\u606F",width:t,children:({user:y,security:h,sessions:R,avatarReview:I})=>{if(i.name==="avatar")return xn(at,{flexDirection:"column",children:[I!==null&&me(at,{marginBottom:1,children:me(Ro,{notices:Dc,status:I.status,reason:I.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 U=(w.path??"").trim();if(U===""){p("\u8BF7\u8F93\u5165\u56FE\u7247\u8DEF\u5F84");return}let re;try{re=Xf(U,Br)}catch(D){p(Se(D));return}d("\u6B63\u5728\u4E0A\u4F20",()=>Wf(re),{onSuccess:()=>T("\u5DF2\u63D0\u4EA4\u5BA1\u6838")})}})]});if(i.name==="avatar-delete")return me(Pe,{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",()=>zf(),{onSuccess:()=>T("\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:y.username,placeholder:"\u8BF7\u8F93\u5165\u65B0\u7528\u6237\u540D"}],onCancel:g,onSubmit:w=>{let U=(w.username??"").trim();if(U===""||U.length>Kt){p(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>Ef({username:U}),{onSuccess:()=>T("\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=>If({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 U=(w.email??"").trim(),re=(w.code??"").trim(),D=w.password??"";if(U===""||re===""||D===""){p("\u8BF7\u586B\u5199\u65B0\u90AE\u7BB1\u3001\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Nf({email:U,code:re,password:D}),{onSuccess:()=>T("\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 U=w.old??"",re=w.next??"";if(U===""){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",()=>Mf({oldPassword:U,newPassword:re}),{onSuccess:()=>T("\u5BC6\u7801\u5DF2\u4FEE\u6539")})}});if(i.name==="confirm-logout-all")return me(Pe,{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",()=>Df(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u6240\u6709\u8BBE\u5907"),e.home()}}),onCancel:g});if(i.name==="code"){let w=fk[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:U=>{let re=(U.code??"").trim();if(re===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}C(i.intent,re)}})}if(i.name==="enroll"){let w=(re,D)=>xn(bk,{children:[D&&me(gi,{color:f.mutedForeground,children:"\u4F7F\u7528 Google Authenticator \u7B49\u9A8C\u8BC1\u5668 App \u626B\u7801\u6DFB\u52A0"}),xn(gi,{children:[me(gi,{color:f.mutedForeground,children:Pg}),me(gi,{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:W=>{let ee=(W.code??"").trim();if(ee===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}d("\u6B63\u5728\u7ED1\u5B9A",()=>Bf({code:ee}),{onSuccess:({recoveryCodes:he})=>x(he,"\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u7ED1\u5B9A")})}})})]}),U=zs(i.setup.otpauthUri,{width:t,rows:r},{columns:uk(Pg)+i.setup.secret.length,rows:pk},{columns:n-t,rows:o-r});return U.fits?me(Vs,{value:i.setup.otpauthUri,aside:w(U.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(yk,{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 U=i.message;s({name:"menu"}),e.reload(),e.toast("ok",U)}})})]});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 U=(w.name??"").trim();if(U===""){p("\u8BF7\u8F93\u5165\u540D\u79F0");return}d("\u6B63\u5728\u4FDD\u5B58",()=>jf(i.item.id,{name:U}),{onSuccess:()=>T("\u5DF2\u4FDD\u5B58")})}});if(i.name==="passkey-delete")return me(Pe,{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",()=>Hf(i.item.id),{onSuccess:()=>T("\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="passkey"){let w=i.item;return me(at,{flexDirection:"column",children:xn(de,{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:U=>{m(),s(U==="rename"?{name:"passkey-rename",item:w}:{name:"passkey-delete",item:w})}})})]})})}if(i.name==="confirm-revoke"){let w=i.item;return me(Pe,{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",()=>as(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u767B\u5F55"),e.home()}});return}d("\u6B63\u5728\u9000\u51FA\u8BE5\u8BBE\u5907",()=>Of(w.id),{onSuccess:()=>T("\u5DF2\u9000\u51FA\u8BE5\u8BBE\u5907")})},onCancel:g})}if(i.name==="session"){let w=i.item;return xn(at,{flexDirection:"column",children:[me(de,{title:zo(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?dk[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=h.totp,z=b.phase==="ready"?b.data:null,M=z===null?null:z.todo,v=M===null?0:M.posts.filter(w=>w.status==="pending").length,k=M===null?0:M.posts.filter(w=>w.status==="rejected").length,_=_e([v>0&&`${v} \u7BC7\u5BA1\u6838\u4E2D`,k>0&&`${k} \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:I===null?"\u663E\u793A\u5728\u4E2A\u4EBA\u4E3B\u9875\u548C\u4F60\u7684\u53D1\u8A00\u4E2D":ld(I)},{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"},...y.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"},...h.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}]:[],...h.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?`${zo(w.device)}\uFF08\u5F53\u524D\u8BBE\u5907\uFF09`:zo(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=z===null?null:z.homepage,B=[["\u7528\u6237\u540D",st(y.username)],["\u90AE\u7BB1",y.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",Ki(P.identity.points)],["\u79EF\u5206",`${P.identity.points} \xB7 ${Yi(P.identity.points)}`],["\u52A0\u5165\u65F6\u95F4",Hr(P.joinedAt)]]],J=b.phase==="error"?b:null,oe=P!==null?Ut(gk,t)+X:J!==null?(J.hint===void 0?1:2)+X:0,fe=Js(B.length,t)+X+oe,$=X+Xe+ko,ne=P!==null&&mr(t)&&r-fe-$>=hk;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(_n,{title:"\u793E\u533A\u8DB3\u8FF9",width:t}),me(at,{marginTop:Ge,flexDirection:"column",children:me(ur,{data:P.activity,value:w=>w.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${P.activity.days.reduce((w,U)=>w+U.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:y.username}):w.kind==="my-comments"?e.push("my-comments",{username:y.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",()=>Al({}),{failToast:!0,onSuccess:U=>s({name:"enroll",setup:U})}):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 ca,Text as la,useInput as kk}from"ink";import{useRef as $g,useState as hr}from"react";import vk from"string-width";var Eg=12e4,Mg=e=>A(mt($i),Ue("/tickets",{...e})),Ig=e=>A(Su,"/tickets",{method:"POST",json:e}),Wl=e=>A(vu,`/tickets/${e}`),Ng=(e,t,n)=>A(se,`/tickets/${e}/messages`,{method:"POST",json:{content:t,attachmentIds:n}}),Sk=e=>A(ku,Ue("/tickets/attachments",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Eg}),xk=e=>A(se,`/tickets/attachments/${e}`,{method:"DELETE"}),sa={upload:Sk,discard:xk},Lg=(e,t)=>cs(`/tickets/${e}/attachments/${t}`,{timeoutMs:Eg}),Og=e=>A(se,`/tickets/${e}/close`,{method:"POST"}),Dg=e=>A(se,`/tickets/${e}/reopen`,{method:"POST"});import{useEffect as Tk,useRef as wk}from"react";function aa(e,t,n=!0){let o=wk(t);o.current=t,Tk(()=>{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 zl}from"react/jsx-runtime";var Ck=5e3,Rk=11,_k=3,Bg=1;function Pk(e,t){let n=[],o=r=>{let i=r.spans.reduce((a,c)=>a+vk(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:Rt(r.author),color:s?f.accent:f.mutedForeground},{text:` ${K(r.createdAt)}`,color:f.faintForeground}]},c=r.content===""?[]:At([{text:Kn(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:` (${Jo(u.fileSize)})`,color:f.mutedForeground}]}));s?n.push(o(a),...c.map(o),...l.map(o)):n.push(a,...c,...l)}),n}function Fg({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=hr("main"),[s,a]=hr(!1),[c,l]=hr(null),[u,m]=hr(null),[p,d]=hr(0),{busy:S,error:b,reset:g,fail:T,run:x}=ue();Re(S!==null);let C=Q([e.id,t.revision],async()=>{let[L,P]=await Promise.all([Wl(e.id),Be(t.ctx.site)]);return{detail:L,site:P}}),[y,h]=hr(null),R=$g(0),I=$g(t.revision);I.current!==t.revision&&(I.current=t.revision,R.current+=1,y!==null&&h(null));let E=C.phase==="ready"?C.data:null,z=y??E?.detail??null;aa(Ck,async()=>{if(z===null||S!==null)return;let L=R.current,P=await Wl(e.id);L===R.current&&(P.ticket.updatedAt!==z.ticket.updatedAt||P.messages.length!==z.messages.length)&&h(P)},r==="main"&&E!==null);let M=z?.messages.some(L=>L.attachments.length>0)??!1;G(L=>{r!=="main"||s||S!==null||(L==="r"?t.reload():L==="x"&&z!==null&&z.ticket.status!=="closed"?(g(),i("confirm-close")):L==="a"&&M&&(g(),l(null),m(null),i("attachments")))}),kk((L,P)=>{P.tab&&r==="main"&&!s&&z?.ticket.status!=="closed"&&a(!0)},{isActive:r==="main"&&!s&&S===null});let v=()=>{if(r!=="main"){g(),i("main");return}if(s){a(!1);return}t.pop()},k=(L,P)=>{x("\u6B63\u5728\u53D1\u9001",()=>In(P,sa,B=>Ng(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",...z?.ticket.status==="closed"?[]:["Tab \u56DE\u590D"],...M?["a \u9644\u4EF6"]:[],...z?.ticket.status==="closed"?[]:["x \u5173\u95ED\u5DE5\u5355"],"r \u5237\u65B0"]:[];return Ht(Y,{trail:["\u5DE5\u5355\u652F\u6301",z?.ticket.title??"\u5DE5\u5355\u8BE6\u60C5"],hints:_,onEscape:v,isActive:S===null,children:Ht(V,{state:C,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:n,children:({site:L,detail:P})=>{let B=y??P,J=B.ticket,oe=J.status==="closed";if(r==="confirm-close")return Ht(Pe,{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:S,error:b,onConfirm:()=>x("\u6B63\u5728\u5173\u95ED",()=>Og(e.id),{onSuccess:()=>{i("main"),t.reload(),t.toast("ok","\u5DF2\u5173\u95ED")}}),onCancel:v});if(r==="attachments")return u!==null?Ht(pr,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${u.fileName}`,width:n,download:async()=>({fileName:u.fileName,bytes:await Lg(e.id,u.id)}),onCancel:()=>m(null),onSaved:w=>{m(null),l(w),t.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):zl(ca,{flexDirection:"column",children:[Ht(le,{width:n,height:Math.max(3,o-1),isActive:S===null,items:[{heading:"\u9644\u4EF6"},...B.messages.flatMap(w=>w.attachments.map(U=>({value:U,label:U.fileName,hint:`${Rt(w.author)} \xB7 ${Jo(U.fileSize)} \xB7 ${K(w.createdAt)}`})))],onSelect:w=>{l(null),m(w)}}),c!==null&&Ht(la,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${c}`})]});let fe=L.ticketAutoCloseMinutes>0?Bg:0,$=oe?_k:s?Rk:Bg,ne=Math.max(3,o-fe-$-X);return zl(ca,{flexDirection:"column",children:[fe>0&&Ht(la,{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:Pk(B.messages,n),height:ne,isActive:!s&&S===null,pinBottom:!0}),Ht(ca,{marginTop:1,flexDirection:"column",children:oe?zl(ca,{flexDirection:"column",children:[Ht(la,{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:S===null,items:[{value:"reopen",label:"\u91CD\u65B0\u6253\u5F00"}],onSelect:()=>x("\u6B63\u5728\u91CD\u65B0\u6253\u5F00",()=>Dg(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:S!==null,busyLabel:S??"\u6B63\u5728\u53D1\u9001",error:b,fields:[{kind:"textarea",name:"content",label:"\u56DE\u590D\u5185\u5BB9",rows:3,maxLength:5e3,placeholder:"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9",optional:!0},eo(fr)],onCancel:()=>a(!1),onSubmit:w=>{let U=(w.content??"").trim(),re;try{re=Xn(w.attachments??"",fr)}catch(D){T(Se(D));return}if(U===""&&re.length===0){T("\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9\u6216\u9644\u4EF6\u8DEF\u5F84");return}k(U,re)}},p):Ht(la,{color:f.faintForeground,children:"\u6309 Tab \u64B0\u5199\u56DE\u590D"})})]})}})})}import{Box as Ak}from"ink";import{useState as Ek}from"react";import{jsx as _o,jsxs as Nk}from"react/jsx-runtime";var Mk=Pt(rc,zc,"\u5168\u90E8\u72B6\u6001"),Ik={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"},Vl={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:Ik};function Ug(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Ek({name:"list"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue(),p=We([e.revision,i],b=>Mg({page:b,...i===""?{}:{status:i}}),{retain:"page"}),d=o.name==="list";G((b,g)=>{d&&(b==="r"?e.reload():b==="f"?r({name:"filter"}):b==="n"?r({name:"create-category"}):g.leftArrow?p.go(-1):g.rightArrow&&p.go(1))});let S=()=>{o.name==="list"?e.pop():o.name==="create"?r({name:"create-category"}):(l(),r({name:"list"}))};return _o(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:S,children:o.name==="filter"?_o(te,{title:"\u7B5B\u9009\u5DE5\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:Mk,initial:i}],onCancel:S,onSubmit:b=>{s(b.status??""),p.reset(),r({name:"list"})}}):o.name==="create-category"?_o(le,{width:t,height:n,items:[{heading:"\u5206\u7C7B"},...ic.map(b=>({value:b,label:ts(b),hint:Vl[b].title}))],onSelect:b=>r({name:"create",category:b})}):o.name==="create"?_o(te,{title:`\u65B0\u5EFA\u5DE5\u5355 \u2014 ${ts(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:sc.map(b=>({value:b,label:Vc(b).label})),initial:"normal"},{kind:"text",name:"title",label:"\u6807\u9898",placeholder:Vl[o.category].title},{kind:"textarea",name:"content",label:"\u95EE\u9898\u63CF\u8FF0",rows:5,maxLength:5e3,placeholder:Vl[o.category].content},eo(fr)],onCancel:S,onSubmit:b=>{let g=(b.title??"").trim(),T=(b.content??"").trim();if(g===""){u("\u8BF7\u586B\u5199\u6807\u9898");return}if(T===""){u("\u8BF7\u586B\u5199\u95EE\u9898\u63CF\u8FF0");return}let x;try{x=Xn(b.attachments??"",fr)}catch(C){u(Se(C));return}m("\u6B63\u5728\u63D0\u4EA4\u5DE5\u5355",()=>In(x,sa,C=>Ig({title:g,category:o.category,priority:b.priority??"normal",content:T,attachmentIds:C.map(y=>y.id)})),{onSuccess:C=>{r({name:"list"}),p.reset(),e.reload(),e.push("ticket",{id:C.id}),e.toast("ok","\u5DE5\u5355\u5DF2\u63D0\u4EA4")}})}}):_o(V,{state:p.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:t,children:b=>Nk(Ak,{flexDirection:"column",children:[_o(pe,{retain:"list",items:b.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,bt(Vc(g.priority)),ts(g.category),K(g.updatedAt),bt(zc(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}),_o(ze,{page:p.page,pages:p.pages,total:p.total,width:t})]})})})}import{Box as Lk}from"ink";import{jsx as hi}from"react/jsx-runtime";function jg({params:e}){let t=O(),{width:n}=j(),o=Z(),r=Q([e.type,t.revision],()=>jd(t.ctx.site,e.type));return hi(Y,{trail:["\u6CD5\u5F8B\u6761\u6B3E",e.type==="terms"?"\u7528\u6237\u534F\u8BAE":"\u9690\u79C1\u653F\u7B56"],hints:["\u2191\u2193 \u6EDA\u52A8"],children:hi(V,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6761\u6B3E",width:n,children:i=>i.configured?hi(Lk,{flexDirection:"column",children:hi(pt,{lines:hn(i.content,n),height:o})}):hi(ye,{tone:"info",width:n,title:"\u8BE5\u6761\u6B3E\u5C1A\u672A\u914D\u7F6E"})})})}var Hg=(e,t)=>fn(se,`${e}/api/auth/send-code`,{json:t});async function qg(e,t){let n=await Jt(`${e}/api/auth/register`,{json:t});sn(n);let o=Vo.parse(n.data);return Vr(e,zr({refresh:null,device:null},n.headers),o)}var Gg=(e,t)=>fn(se,`${e}/api/auth/forgot-password`,{json:t}),Wg=(e,t)=>fn(se,`${e}/api/auth/reset-password`,{json:t});import{jsx as zg}from"react/jsx-runtime";function Vg(){let e=O(),{width:t}=j(),{busy:n,error:o,fail:r,run:i}=ue();return Re(n!==null),zg(Y,{trail:["\u627E\u56DE\u5BC6\u7801"],isActive:n===null,children:zg(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=>Gg(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",()=>Wg(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 Yl,Text as Dk}from"ink";import{useState as Yg}from"react";import{Box as Kg}from"ink";import{jsx as Kl,jsxs as Ok}from"react/jsx-runtime";var ma=e=>e.termsConfigured||e.privacyConfigured;function ua({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 Ok(Kg,{flexDirection:"column",children:[Kl(ye,{tone:"info",width:t,title:`\u7EE7\u7EED\u524D\u8BF7\u9605\u8BFB\u5E76\u540C\u610F${r.join("\u4E0E")}`}),Kl(Kg,{marginTop:1,children:Kl(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 to,jsxs as Jg}from"react/jsx-runtime";function Xg(){let e=O(),{width:t}=j(),[n,o]=Yg({name:"credentials"}),[r,i]=Yg(!1),{busy:s,error:a,reset:c,fail:l,run:u}=ue(),m=Q([e.revision],()=>Be(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,T)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Fd(e.ctx.site,g,T),{onSuccess:x=>{if(x.status==="totp_required"){o({name:"factor",ticket:x.ticket,jar:x.jar});return}p(x.session.username)}})},S=(g,T)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Ud(e.ctx.site,g.jar,g.ticket,T,g.kind),{onSuccess:x=>p(x.username)})},b=()=>{n.name==="credentials"?e.pop():(c(),o({name:"credentials"}))};return Jg(Y,{trail:n.name==="credentials"?["\u767B\u5F55\u8D26\u53F7"]:["\u767B\u5F55\u8D26\u53F7","\u4E24\u6B65\u9A8C\u8BC1"],onEscape:b,isActive:s===null,children:[n.name==="credentials"&&to(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:g=>ma(g.legal)&&!r?to(ua,{legal:g.legal,width:t,onAgree:()=>i(!0)}):Jg(Yl,{flexDirection:"column",children:[to(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:b,onSubmit:T=>{let x=(T.account??"").trim(),C=T.password??"";if(x===""||C===""){l("\u8BF7\u586B\u5199\u8D26\u53F7\u4E0E\u5BC6\u7801");return}d(x,C)}}),to(Yl,{marginTop:1,children:to(Dk,{color:f.faintForeground,children:"Passkey \u767B\u5F55\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"})})]})}),n.name==="factor"&&to(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"&&to(Yl,{flexDirection:"column",children:to(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:b,onSubmit:g=>{let T=(g.code??"").trim();if(T===""){l("\u8BF7\u586B\u5199\u9A8C\u8BC1\u7801");return}S(n,T)}})})]})}import{useState as $k}from"react";import{jsx as da}from"react/jsx-runtime";function Qg(){let e=O(),{width:t}=j(),[n,o]=$k(!1),{busy:r,error:i,fail:s,run:a}=ue(),c=Q([e.revision],()=>Be(e.ctx.site));return da(Y,{trail:["\u6CE8\u518C\u8D26\u53F7"],isActive:r===null,children:da(V,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:l=>ma(l.legal)&&!n?da(ua,{legal:l.legal,width:t,onAgree:()=>o(!0)}):da(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=>Hg(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(),S=u.password??"",b=(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(S.length<Ot){s(`\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}a("\u6B63\u5728\u6CE8\u518C",()=>qg(e.ctx.site,{username:m,email:p,password:S,code:d,...b===""?{}:{inviteCode:b}}),{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 yi}from"ink";import{useState as Bk}from"react";import{jsx as Nt,jsxs as eh}from"react/jsx-runtime";var Fk=["category","title","content","attachments"],Uk=11,jk=2,Hk=3,qk=16,Zg={new:"\u53D1\u5E03\u5E16\u5B50",draft:"\u7F16\u8F91\u8349\u7A3F",edit:"\u7F16\u8F91\u5E16\u5B50"};function Gk(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 Wk(e,t){return e.find(n=>String(n.id)===t)?.description}function th({mode:e}){let t=O(),{width:n}=j(),o=Z(),r=Gk(e),[i,s]=Me("values",()=>r),[a,c]=Bk(!1),{busy:l,error:u,fail:m,reset:p,run:d}=ue(),S=Q([],Us),b=Fk.some(E=>(i[E]??"")!==(r[E]??""));Re(b||l!==null);let g=E=>{let z=E.category??"";return{categoryId:z===""?null:Number(z),title:(E.title??"").trim(),content:(E.content??"").trim()}},T=(E,z)=>{let M;try{M=Xn(E.attachments??"",Xs)}catch(v){return m(Se(v)),null}return jt(z).length+M.length>Xs.maxCount?(m("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650"),null):M},x=async E=>{switch(e.kind){case"new":return(await bf(E)).id;case"draft":return await wf(e.draft.id,E),e.draft.id;case"edit":return await Sf(e.post.id,E),e.post.id}},C=E=>{if(e.kind==="edit"&&!b){m("\u5185\u5BB9\u672A\u4FEE\u6539");return}let{categoryId:z,title:M,content:v}=g(E);if(z===null){m("\u8BF7\u9009\u62E9\u677F\u5757");return}if(M===""){m("\u8BF7\u586B\u5199\u6807\u9898");return}if(M.length>uo){m(`\u6807\u9898\u6700\u591A ${uo} \u4E2A\u5B57\u7B26`);return}let k=T(E,v);if(k!==null){if(v===""&&k.length===0){m("\u8BF7\u586B\u5199\u6B63\u6587");return}d("\u6B63\u5728\u63D0\u4EA4",()=>In(k,ai,_=>x({categoryId:z,title:M,content:pi(v,_)})),{onSuccess:_=>{t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838"),t.pop(),e.kind!=="edit"&&t.push("post",{id:_})}})}},y=(E,z)=>{let{categoryId:M,title:v,content:k}=g(E);if(v.length>uo){m(`\u6807\u9898\u6700\u591A ${uo} \u4E2A\u5B57\u7B26`);return}let _=T(E,k);_!==null&&d("\u6B63\u5728\u4FDD\u5B58\u8349\u7A3F",()=>In(_,ai,async L=>{let P={categoryId:M,title:v,content:pi(k,L)};z===null?await xf(P):await Tf(z,P)}),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5B58\u8349\u7A3F")}})},h=e.kind==="draft"?e.draft.id:null,R=()=>{if(!b){t.pop();return}p(),c(!0)},I=()=>{if(!a){t.pop();return}p(),c(!1)};return G(E=>{E==="q"&&b&&R()},!a&&l===null),Nt(Y,{trail:["\u793E\u533A\u8BBA\u575B",Zg[e.kind]],onEscape:I,isActive:l===null,children:Nt(V,{state:S,loading:"\u6B63\u5728\u8BFB\u53D6\u677F\u5757",width:n,children:E=>{if(a&&e.kind==="edit")return Nt(Pe,{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:I});if(a)return eh(yi,{flexDirection:"column",children:[Nt(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&&Nt(yi,{marginTop:1,children:Nt(Ft,{message:u.message,hint:u.hint,width:n})}),Nt(yi,{marginTop:1,children:l!==null?Nt(Oe,{label:l}):Nt(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"?y(i,h):L==="stay"?I():t.pop()}})})]});let z=e.kind==="edit"?0:1,M=e.kind==="edit"&&e.post.status==="published",v=M?jk:0,k=Math.min(qk,Math.max(Hk,o-Uk-z-v-fi(u))),_=i.category??"";return eh(yi,{flexDirection:"column",children:[M&&Nt(yi,{marginBottom:1,children:Nt(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"})}),Nt(te,{title:Zg[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=>Wk(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:k,maxLength:ji,initial:i.content,placeholder:"\u8BF7\u8F93\u5165\u6B63\u6587\uFF0C\u652F\u6301 Markdown"},{...eo(Xs),initial:i.attachments}],secondary:e.kind==="edit"?void 0:{label:"\u5B58\u8349\u7A3F",onSubmit:L=>y(L,h)},onChange:s,onCancel:R,onSubmit:C})]})}})})}function nh({params:e}){return Nt(th,{mode:e.draft===null?{kind:"new"}:{kind:"draft",draft:e.draft}})}function oh({params:e}){return Nt(th,{mode:{kind:"edit",post:e.post}})}import{Box as no,Text as Jl}from"ink";import{useEffect as Xl,useMemo as rh,useState as pa}from"react";import{useRef as zk}from"react";function qt(e){let t=zk(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 Ql}from"react/jsx-runtime";var fa={kind:"floor"},Vk=2,ih=3,Kk=4,ch=2,sh=3,ah="PgUp PgDn \u6EDA\u52A8\u6B63\u6587",ga=(e,t)=>{let n=na(Qo,e.status,e.reviewReason,t);return n===0?0:n+1};function Yk(e,t,n,o,r){let i=Math.max(ch+sh,o-Vk-ga(e,r)-3),s=Math.max(sh,Math.min(Kk,i-ih)),a=Math.min(ih,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 Jk(e,t,n,o,r){let i=o-Xe-1-ga(e,r)-2-n;return Math.min(t.length,Math.max(ch,i))}function Xk(e,t,n,o){let r=e.status==="published"&&t.status==="published"&&n.status==="published",i=On(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:Rt(n.author)},...i?[{value:"delete",label:"\u5220\u9664",labelTone:"danger"}]:[]]}function lh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=pa({name:"main"}),[s,a]=pa(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,U,re,D]=await Promise.all([js(e.postId),mf(e.postId,e.floorId),Mn(),cr()]);return{post:w,floor:U,me:re.user,muted:D.muted}})),d=We([e.floorId,t.revision],w=>uf(e.floorId,w),{retain:"replies-page"}),S=qt(d.state),b=p.phase==="ready"?p.data:null,g=S.phase==="ready"?S.data:null,[T,x]=pa(void 0);Xl(()=>x(void 0),[b]);let[C,y]=pa(new Map);Xl(()=>y(new Map),[g]);let h=b===null?null:{...b,floor:{...b.floor,...T}},R=g===null?[]:g.items.map(w=>({...w,...C.get(w.id)})),I=vg(md(R)),E=r.name==="actions"?R.find(w=>w.id===r.id)??null:null,z=s!==null&&R.some(w=>w.id===s);Xl(()=>{z&&a(null)},[z]);let M=h===null?null:h.floor.content,v=rh(()=>M===null?[]:di(M,n),[M,n]),k=E===null?null:E.content,_=rh(()=>k===null?[]:di(k,n-ge),[k,n]),L=h===null?null:Yk(h.floor,v,R.length,o-gr(h.muted,n),n),P=h===null||E===null?null:Xk(h.post,h.floor,E,h.me.username),B=E===null||P===null?null:Jk(E,_,P.length,o,n-ge),J=w=>h===null?null:w.kind==="floor"?h.floor:R.find(U=>U.id===w.id)??null,oe=(w,U)=>{m(w.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>Rf(w.id,!w.liked),{failToast:!0,onSuccess:({likeCount:re})=>U({liked:!w.liked,likeCount:re})})};G((w,U)=>{if(h===null||r.name!=="main"||c!==null)return;let{post:re,floor:D,me:W}=h,ee=re.status==="published"&&D.status==="published",he=On(D.author,W.username);w==="r"?t.reload():U.leftArrow?d.go(-1):U.rightArrow?d.go(1):w==="c"&&ee?i({name:"reply",target:fa}):w==="l"&&ee&&!he?oe(D,x):w==="p"&&ee&&!he?i({name:"report",target:fa}):w==="a"&&jt(D.content).length>0?i({name:"attachments",target:fa}):w==="u"?t.push("homepage",{author:ui(D.author)}):w==="d"&&he&&(u(),i({name:"confirm-delete",target:fa}))});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,U)=>{let re={kind:"reply",id:w.id};U==="like"?oe(w,D=>y(W=>new Map(W).set(w.id,D))):U==="reply"?i({name:"reply",target:re}):U==="report"?i({name:"report",target:re}):U==="attachments"?i({name:"attachments",target:re}):U==="author"?t.push("homepage",{author:ui(w.author)}):(u(),i({name:"confirm-delete",target:re}))};return Ee(Y,{trail:["\u793E\u533A\u8BBA\u575B","\u697C\u5C42\u8BE6\u60C5"],hints:(()=>{if(h===null)return[];if(r.name==="actions")return B===null?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C",..._.length>B?[ah]:[]];if(r.name!=="main"||L===null)return[];let{post:w,floor:U,me:re}=h,D=w.status==="published"&&U.status==="published",W=On(U.author,re.username);return[...R.length>0?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C"]:[],...v.length>L.bodyRows?[ah]:[],...D?["c \u56DE\u590D"]:[],...D&&!W?[U.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E","p \u4E3E\u62A5"]:[],...jt(U.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...W?["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:U,me:re,muted:D})=>{let W={...U,...T},ee=ie=>`${On(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 Ql(de,{title:Rt(E.author),note:K(E.createdAt),width:n,children:[Ee(Jl,{wrap:"truncate",color:f.mutedForeground,children:_e([E.replyTo!==null&&`\u56DE\u590D ${Zs(E.replyTo.author)}`,ee(E)])}),ga(E,ie)>0&&Ee(no,{marginTop:1,children:Ee(Ro,{notices:Qo,status:E.status,reason:E.reviewReason,width:ie})}),Ee(no,{marginTop:1,children:Ee(pt,{lines:_,height:B,isActive:c===null,pageKeysOnly:!0})}),Ee(no,{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(oa,{postId:w.id,replyTo:{id:ie.id,mention:Zs(ie.author)},width:n,height:o,onCancel:fe,onDone:Tt=>{i({name:"main"}),a(Tt),d.last(),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838")}});if(r.name==="report")return Ee(ra,{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(ia,{refs:jt(ie.content),width:n,height:o});let Qe=r.target.kind==="floor";return Ee(Pe,{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",()=>vf(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 Ql(no,{flexDirection:"column",children:[Ee(Co,{muted:D,width:n}),Ee(Jl,{bold:!0,wrap:"truncate",color:f.foreground,children:w.title}),c!==null?Ee(Oe,{label:c}):Ee(Jl,{wrap:"truncate",color:f.mutedForeground,children:_e([W.floor!==null&&`#${W.floor}`,Rt(W.author),K(W.createdAt),`\u56DE\u590D ${W.replyCount}`,ee(W)])}),ga(W,n)>0&&Ee(no,{marginTop:1,children:Ee(Ro,{notices:Qo,status:W.status,reason:W.reviewReason,width:n})}),Ee(no,{marginTop:1,children:Ee(pt,{lines:v,height:L.bodyRows,isActive:he,pageKeysOnly:!0})}),Ee(no,{marginTop:1,children:Ee(V,{state:S,loading:"\u6B63\u5728\u8BFB\u53D6\u56DE\u590D",width:n,children:()=>Ql(no,{flexDirection:"column",children:[Ee(pe,{retain:"replies",items:I,width:n,height:L.listRows,isActive:he,columns:[Zn,{label:"\u56DE\u590D",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:({reply:ie,mention:Qe,prefix:Tt})=>[`${Tt}${Rt(ie.author)}`,Qe===null?vo(ie.content):`\u56DE\u590D ${Zs(Qe)}\uFF1A${vo(ie.content)}`,String(ie.likeCount),K(ie.createdAt),ie.status==="published"?"":bt(go(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"&&W.status==="published"?"\u6309 c \u56DE\u590D\u672C\u697C":void 0}),Ee(ze,{page:d.page,pages:d.pages,total:d.total,width:n})]})})})]})}})})}import{Box as Po,Text as ba}from"ink";import{Box as mh}from"ink";import{jsx as yr,jsxs as uh}from"react/jsx-runtime";function ha({author:e,owner:t,width:n,height:o}){let r=O(),i=We([e.kind,e.username,r.revision],a=>pf(e,a),{retain:"posts-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),yr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:a=>uh(mh,{flexDirection:"column",children:[yr(pe,{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}]:[],dr,{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?[$c(qr,c)??""]:[],c.category.name,String(c.commentCount),String(c.viewCount),String(c.likeCount),K(c.publishedAt??c.createdAt),...t?[bt(go(c.status))]:[]],onOpen:c=>r.push("post",{id:c.id}),emptyLabel:"\u6682\u65E0\u5E16\u5B50"}),yr(ze,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}function ya({author:e,owner:t,width:n,height:o}){let r=O(),i=We([e.kind,e.username,r.revision],a=>ff(e,a),{retain:"comments-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),yr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u8BC4\u8BBA",width:n,children:a=>uh(mh,{flexDirection:"column",children:[yr(pe,{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=>[vo(c.content),...t?[$c(Qo,c)??""]:[],c.post.title??Xi,String(c.likeCount),K(c.createdAt),...t?[bt(go(c.status))]:[]],onOpen:c=>r.push("floor",{postId:c.post.id,floorId:c.floorId}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA"}),yr(ze,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}import{jsx as St,jsxs as Sa}from"react/jsx-runtime";var Qk=[{value:"posts",label:"\u5E16\u5B50"},{value:"comments",label:"\u8BC4\u8BBA"}],Zk=3,ev=2,tv=5;function nv({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 Sa(Po,{flexDirection:"column",children:[Sa(ba,{wrap:"truncate",children:[St(ba,{bold:!0,color:f.foreground,children:st(r.username)}),St(ba,{color:f.accent,children:` ${r.kind==="user"?Ki(r.points):`[${Ji}]`}`})]}),St(ba,{wrap:"truncate",color:f.mutedForeground,children:_e([r.kind==="user"&&`${r.points} \u79EF\u5206`,t&&r.kind==="user"&&Yi(r.points),`\u52A0\u5165\u4E8E ${Hr(e.joinedAt)}`])}),St(Po,{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&&Sa(Po,{marginTop:X,flexDirection:"column",children:[St(_n,{title:"\u793E\u533A\u8DB3\u8FF9",width:n}),St(Po,{marginTop:Ge,flexDirection:"column",children:St(ur,{data:e.activity,value:a=>a.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${s} \u6B21`,width:n})})]})]})}function dh({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([df(e.author),Mn()]),S=e.author.kind==="user"&&e.author.username===d.user.username;return{profile:p,owner:S}});G(p=>{p==="r"?t.reload():p==="t"&&i(d=>d==="posts"?"comments":"posts")});let a=ev+1+Ut(Zk,n),c=o-a-2-1,l=X+Xe+ko,u=mr(n)&&c-l>=tv,m=Math.max(3,c-(u?l:0));return St(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:St(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u6237\u4E3B\u9875",width:n,children:({profile:p,owner:d})=>Sa(Po,{flexDirection:"column",children:[St(nv,{profile:p,owner:d,width:n,heatmapOn:u}),St(Po,{marginTop:1,children:St(Gs,{options:Qk,value:r,onChange:i,arrowKeys:!1})}),St(Po,{marginTop:1,children:r==="posts"?St(ha,{author:e.author,owner:d,width:n,height:m}):St(ya,{author:e.author,owner:d,width:n,height:m})})]})})})}import{Box as ph}from"ink";import{useState as ov}from"react";import{jsx as Ao,jsxs as gh}from"react/jsx-runtime";var rv={sort:"activity",categoryId:"",q:"",author:""},fh=e=>e.categoryId!==""||e.q!==""||e.author!=="",iv=(e,t)=>({page:t,sort:e.sort,...e.categoryId===""?{}:{categoryId:Number(e.categoryId)},...e.q===""?{}:{q:e.q},...e.author===""?{}:{author:e.author}});function hh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=ov(!1),[i,s]=Me("filters",()=>rv),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[d,S]=await Promise.all([cr(),Us()]);return{muted:d.muted,categories:S}}),m=We([e.revision,JSON.stringify(i)],d=>af(iv(i,d)),{retain:"page"});G((d,S)=>{o||(d==="r"?e.reload():d==="f"?r(!0):d==="n"?e.push("compose",{draft:null}):S.leftArrow?m.go(-1):S.rightArrow&&m.go(1))});let p=()=>{if(!o){e.pop();return}l(),r(!1)};return Ao(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:Ao(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u793E\u533A",width:t,children:({muted:d,categories:S})=>o?Ao(te,{title:"\u7B5B\u9009\u5E16\u5B50",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"select",name:"sort",label:"\u6392\u5E8F",options:ac.map(b=>({value:b,label:Rd(b)})),initial:i.sort},{kind:"select",name:"category",label:"\u677F\u5757",options:[{value:"",label:"\u5168\u90E8\u677F\u5757"},...S.map(b=>({value:String(b.id),label:b.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:b=>{let g=(b.q??"").trim(),T=(b.author??"").trim();if(g.length>qi){c(`\u5173\u952E\u8BCD\u6700\u591A ${qi} \u4E2A\u5B57\u7B26`);return}if(T.length>Kt){c(`\u7528\u6237\u540D\u6700\u591A ${Kt} \u4E2A\u5B57\u7B26`);return}s({sort:b.sort,categoryId:b.category??"",q:g,author:T}),m.reset(),l(),r(!1)}}):gh(ph,{flexDirection:"column",children:[Ao(Co,{muted:d,width:t}),Ao(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:t,children:b=>gh(ph,{flexDirection:"column",children:[Ao(pe,{retain:"list",items:b.items,width:t,height:Math.max(3,n-1-gr(d,t)),columns:[{label:"\u4E3B\u9898",shrink:!0},Zn,dr,{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,Rt(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:fh(i)?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u5E16\u5B50",emptyDescription:fh(i)?void 0:"\u6309 n \u53D1\u5E03\u7B2C\u4E00\u7BC7\u5E16\u5B50"}),Ao(ze,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})})})}import{Box as xa}from"ink";import{useState as sv}from"react";import{jsx as ft,jsxs as kh}from"react/jsx-runtime";var av=X+Xe+2,cv=X+2+1+2;function bh(){let e=O();G(t=>{t==="r"&&e.reload()})}function Sh({params:e}){let{width:t}=j(),n=Z();return bh(),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(ha,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function xh({params:e}){let{width:t}=j(),n=Z();return bh(),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(ya,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function Th(){let e=O(),{width:t}=j(),n=Z(),o=We([e.revision],r=>gf(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=>kh(xa,{flexDirection:"column",children:[ft(pe,{retain:"list",items:r.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},Zn,{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:i=>[i.title,Rt(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(ze,{page:o.page,pages:o.pages,total:o.total,width:t})]})})})}var yh=e=>e.title===""?"\u672A\u547D\u540D\u8349\u7A3F":e.title;function wh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=sv({name:"list"}),{busy:i,error:s,reset:a,run:c}=ue();Re(i!==null);let l=We([e.revision],d=>hf(d),{retain:"page"}),u=o.name==="list";G((d,S)=>{u&&(d==="r"?e.reload():S.leftArrow?l.go(-1):S.rightArrow&&l.go(1))});let m=()=>{if(u){e.pop();return}a(),r({name:"list"})},p=o.name==="actions"?av:o.name==="confirm-delete"?cv+fi(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=>kh(xa,{flexDirection:"column",children:[ft(pe,{retain:"list",items:d.items,width:t,height:Math.max(3,n-1-p),isActive:u,columns:[{label:"\u6807\u9898",shrink:!0},dr,{label:"\u521B\u5EFA\u65F6\u95F4",align:"right"}],row:S=>[yh(S),S.category===null?"\u2014":S.category.name,K(S.createdAt)],onOpen:S=>r({name:"actions",draft:S}),emptyLabel:"\u6682\u65E0\u8349\u7A3F",emptyDescription:"\u53D1\u5E03\u5E16\u5B50\u65F6\u53EF\u9009\u62E9\u5B58\u4E3A\u8349\u7A3F"}),ft(ze,{page:l.page,pages:l.pages,total:l.total,width:t}),o.name==="actions"&&ft(xa,{marginTop:X,children:ft(de,{title:yh(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:S=>{if(S==="edit"){r({name:"list"}),e.push("compose",{draft:o.draft});return}a(),r({name:"confirm-delete",draft:o.draft})}})})}),o.name==="confirm-delete"&&ft(xa,{marginTop:X,children:ft(Pe,{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",()=>Hs(o.draft.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:m})})]})})})}import{Box as Eo,Text as Zl}from"ink";import{useEffect as Ta,useMemo as lv,useRef as mv,useState as em}from"react";import{jsx as Ke,jsxs as tm}from"react/jsx-runtime";var vh=2,uv=2,dv=2;function pv({post:e,width:t,height:n,isActive:o,follow:r,onFollowed:i}){let s=O(),a=We([e.id,s.revision],u=>lf(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 Ta(()=>{r!==null&&a.last()},[r]),Ta(()=>{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=>tm(Eo,{flexDirection:"column",children:[Ke(pe,{retain:"floors",items:u.items,width:t,height:Math.max(3,n-1),isActive:o,columns:[{label:"\u697C\u5C42"},Zn,{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}`,Rt(m.author),vo(m.content),String(m.replyCount),String(m.likeCount),m.status==="published"?"":bt(go(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(ze,{page:a.page,pages:a.pages,total:a.total,width:t})]})})}function Ch({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("mode",()=>"body"),[s,a]=em({name:"main"}),[c,l]=em(null),{busy:u,error:m,reset:p,run:d}=ue();Re(s.name==="confirm-delete"&&u!==null);let S=mv(null),b=qt(Q([e.id,t.revision],async()=>{let[M,v,k]=await Promise.all([js(e.id),Mn(),cr()]);return{post:M,me:v.user,muted:k.muted}})),g=b.phase==="ready"?b.data:null,[T,x]=em(null);Ta(()=>x(null),[g]);let C=g===null?null:{...g,post:{...g.post,...T}},y=C!==null&&C.post.status==="published";Ta(()=>{!y||S.current===e.id||(S.current=e.id,cf(e.id).catch(()=>t.toast("warn","\u6D4F\u89C8\u8BA1\u6570\u53D1\u9001\u5931\u8D25")))},[e.id,y]);let h=s.name==="main"&&u===null,R=C===null?null:C.post.content,I=lv(()=>R===null?[]:di(R,n),[R,n]);G(M=>{if(C===null||!h)return;let{post:v,me:k}=C;if(M==="r"){t.reload();return}if(M==="v"){i(r==="body"?"floors":"body");return}if(M==="c"&&y){a({name:"comment"});return}if(r!=="body")return;let _=On(v.author,k.username),L={liked:v.liked,likeCount:v.likeCount,bookmarked:v.bookmarked};M==="l"&&y&&!_?d(v.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>Cf(v.id,!v.liked),{failToast:!0,onSuccess:({likeCount:P})=>x({...L,liked:!v.liked,likeCount:P})}):M==="b"&&y?d(v.bookmarked?"\u6B63\u5728\u53D6\u6D88\u6536\u85CF":"\u6B63\u5728\u6536\u85CF",()=>_f(v.id,!v.bookmarked),{failToast:!0,onSuccess:()=>{x({...L,bookmarked:!v.bookmarked}),t.toast("ok",v.bookmarked?"\u5DF2\u53D6\u6D88\u6536\u85CF":"\u5DF2\u6536\u85CF")}}):M==="p"&&y&&!_?a({name:"report"}):M==="a"&&jt(v.content).length>0?a({name:"attachments"}):M==="u"?t.push("homepage",{author:ui(v.author)}):M==="e"&&_&&v.status!=="removed"?t.push("post-edit",{post:v}):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()},z=()=>{if(C===null||s.name!=="main")return[];let{post:M,me:v}=C;if(r==="floors")return["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...y?["c \u8BC4\u8BBA"]:[],"v \u6B63\u6587","r \u5237\u65B0"];let k=On(M.author,v.username);return["\u2191\u2193 \u6EDA\u52A8","v \u697C\u5C42\u5217\u8868",...y?["c \u8BC4\u8BBA",...k?[]:[M.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E"],M.bookmarked?"b \u53D6\u6D88\u6536\u85CF":"b \u6536\u85CF",...k?[]:["p \u4E3E\u62A5"]]:[],...jt(M.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...k&&M.status!=="removed"?["e \u7F16\u8F91\u5E16\u5B50"]:[],...k?["d \u5220\u9664"]:[],"r \u5237\u65B0"]};return Ke(Y,{trail:["\u793E\u533A\u8BBA\u575B",C===null?"\u5E16\u5B50\u8BE6\u60C5":C.post.category.name,...r==="floors"&&s.name==="main"?["\u697C\u5C42\u5217\u8868"]:[]],hints:z(),onEscape:E,isActive:s.name==="main"||u===null,children:Ke(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:({post:M,me:v,muted:k})=>{let _={...M,...T},L=On(_.author,v.username);if(s.name==="comment")return Ke(oa,{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(ra,{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(ia,{refs:jt(_.content),width:n,height:o});if(s.name==="confirm-delete")return Ke(Pe,{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",()=>Hs(_.id),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:E});let P=Ke(Zl,{bold:!0,wrap:"truncate",color:f.foreground,children:_.title}),B=gr(k,n);if(r==="floors")return tm(Eo,{flexDirection:"column",children:[Ke(Co,{muted:k,width:n}),P,Ke(Eo,{marginTop:1,children:Ke(pv,{post:_,width:n,height:o-vh-B,isActive:h,follow:c,onFollowed:()=>l(null)})})]});let J=na(qr,_.status,_.reviewReason,n),oe=Math.max(dv,o-B-vh-(J===0?0:J+1)-1-uv);return tm(Eo,{flexDirection:"column",children:[Ke(Co,{muted:k,width:n}),P,Ke(Zl,{wrap:"truncate",color:f.mutedForeground,children:_e([Rt(_.author),K(_.publishedAt??_.createdAt),_.editedAt!==null&&`\u7F16\u8F91\u4E8E ${K(_.editedAt)}`,`\u6D4F\u89C8 ${_.viewCount}`])}),J>0&&Ke(Eo,{marginTop:1,children:Ke(Ro,{notices:qr,status:_.status,reason:_.reviewReason,width:n})}),Ke(Eo,{marginTop:1,children:Ke(pt,{lines:I,height:oe,isActive:h})}),Ke(Eo,{marginTop:1,children:u!==null?Ke(Oe,{label:u}):Ke(Zl,{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 Io}from"ink";import{useEffect as kv,useRef as vv,useState as rm}from"react";import{z as H}from"zod";var fv=H.object({balance:H.number(),today:H.object({requests:H.number(),tokens:H.number(),cost:H.number()})}),Rh=()=>A(fv,"/dashboard/summary"),_h=["all","30d","7d"],gv=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()}),nm=e=>A(gv,Ue("/dashboard/stats",{range:e})),hv=H.object({id:H.number().int(),requestId:H.string(),tokenName:H.string(),protocol:Um,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:Nu,status:Km,httpStatus:H.number().int(),stopReason:H.string().nullable(),latencyMs:H.number(),firstByteMs:H.number().nullable(),stream:H.boolean(),ip:H.string(),createdAt:H.string()}),Ph=e=>A(mt(hv),Ue("/logs",{...e})),yv=H.object({quotaCost:H.number(),rpm:H.number(),tpm:H.number(),concurrency:H.number()}),Ah=e=>A(yv,Ue("/logs/stats",{...e})),bv=H.object({id:H.number().int(),type:Wm,amount:H.number(),balanceAfter:H.number(),refType:zm,refId:H.string().nullable(),createdAt:H.string()}),Eh=e=>A(mt(bv),Ue("/quota-ledger",{...e}));import{Box as Sv,Text as ln}from"ink";import bi from"string-width";import{Fragment as Ih,jsx as mn,jsxs as om}from"react/jsx-runtime";var Mo=1,xv=4,Tv=1,br=8,wv=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587"],Mh=e=>`${Number(e.slice(5,7))}\u6708${Number(e.slice(8,10))}\u65E5`;function Nh({data:e,order:t,width:n,rows:o}){let r=o-Tv,i=[];for(let M=e.start;M<=e.end;M=Wn(M,1))i.push(M);let s=Math.min(xv,Math.floor((n+Mo)/i.length)-Mo);s<1&&(s=1,i=i.slice(-Math.floor((n+Mo)/(1+Mo))));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,ws.length).map((M,v)=>[M,v])),u=ws.length,m=M=>ws[M]??f.faintForeground,p=new Map(i.map((M,v)=>[M,v])),d=i.map(()=>Array.from({length:u+1},()=>0));for(let M of e.points){let v=p.get(M.day);if(v===void 0)continue;let k=d[v];if(k===void 0)continue;let _=l.get(M.model)??u;k[_]=(k[_]??0)+M.tokens}let S=d.map(M=>M.reduce((v,k)=>v+k,0)),b=Math.max(0,...S),g=r*br,T=d.map((M,v)=>{let k=Array.from({length:r},()=>null),_=S[v]??0;if(_<=0)return k;let L=Math.max(1,Math.round(_/b*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(br,L-oe*br);if(fe<=0)break;let $=new Map;for(let U=oe*br;U<oe*br+fe;U+=1){let re=P[U];re!==void 0&&$.set(re,($.get(re)??0)+1)}let ne=null,w=0;for(let[U,re]of $)re>w&&(ne=U,w=re);if(ne===null)break;k[oe]={color:ne,glyph:fe===br?null:wv[fe-1]??null}}return k}),x=M=>{let v=[],k=(_,L,P)=>{let B=v[v.length-1];B!==void 0&&B.color===_&&B.glyph===L?B.width+=P:v.push({color:_,glyph:L,width:P})};return T.forEach((_,L)=>{L>0&&k(null,null,Mo);let P=_[M]??null;P===null?k(null,null,s):k(P.color,P.glyph,s)}),v},C=i.length*(s+Mo)-Mo,y=Mh(a),h=Mh(c),R=b>0?`\u5355\u65E5\u5CF0\u503C ${Gn(b)}`:"",I=C-bi(y)-bi(h),E=R!==""&&I>=bi(R)+4,z=E?Math.floor((I-bi(R))/2):I;return om(Sv,{flexDirection:"column",children:[Array.from({length:r},(M,v)=>{let k=r-1-v;return mn(ln,{wrap:"truncate",children:x(k).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))},k)}),mn(ln,{wrap:"truncate",children:I<2?mn(ln,{color:f.faintForeground,children:qe(y,C)}):om(Ih,{children:[mn(ln,{color:f.faintForeground,children:y}),mn(ln,{children:" ".repeat(z)}),E&&om(Ih,{children:[mn(ln,{color:f.mutedForeground,children:R}),mn(ln,{children:" ".repeat(I-bi(R)-z)})]}),mn(ln,{color:f.faintForeground,children:h})]})})]})}import{jsx as ct,jsxs as Oh}from"react/jsx-runtime";var Cv={all:"\u5168\u90E8","30d":"30 \u5929","7d":"7 \u5929"},Rv=1,wa=4,Lh=5,_v=9;function Pv(e){let t=-1,n=0;return e.forEach((o,r)=>{o>n&&(n=o,t=r)}),t<0?"\u2014":`${t} \u70B9`}function Dh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=rm("30d"),[i,s]=rm("heatmap"),[a,c]=rm(null),l=vv(null),u=Q([o,e.revision],async()=>{let m=l.current;if(m!==null&&m.revision===e.revision){let b=await nm(o);return{summary:m.summary,stats:b,site:m.site}}let[p,d,S]=await Promise.all([Rh(),nm(o),Be(e.ctx.site)]);return l.current={revision:e.revision,summary:p,site:S},{summary:p,stats:d,site:S}});return kv(()=>{u.phase==="ready"&&c(Sd({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(Io,{flexDirection:"column",children:ct(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u91CF",width:t,children:({summary:m,stats:p,site:d})=>{let S=[{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)}],b=[{label:"\u8BF7\u6C42\u6570",value:Le(p.totals.requests)},{label:"Token \u603B\u91CF",value:Gn(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:Pv(p.hourly)},{label:"\u5E38\u7528\u6A21\u578B",value:p.models[0]?.displayName??"\u2014"}],g=t-ge,T=v=>Bt+v+Ut(S.length,g)+X+Bt+v+Rv+v+Ut(b.length,g)+X+Bt+v,x=n-T(Ge)>=wa?Ge:0,C=n-T(x),y=X+Bt+x+Lh,h=i==="chart"&&p.chart.points.length>0&&C>=y+wa,R=i==="heatmap"&&mr(g)&&C-(X+ko)>=wa,I=R?X+ko:0,E=h?Math.min(_v,Lh+Math.floor((C-y-wa)/2)):0,z=C-I-(h?X+Bt+x+E:0),M=v=>`${(p.totals.tokens>0?v/p.totals.tokens*100:0).toFixed(1)}%`;return Oh(Io,{flexDirection:"column",children:[ct(de,{title:"\u6982\u89C8",width:t,gap:x,children:ct(it,{width:g,tiles:S})}),ct(Io,{marginTop:1,flexDirection:"column",children:Oh(de,{title:"\u533A\u95F4\u7EDF\u8BA1",width:t,gap:x,children:[ct(Gs,{options:_h.map(v=>({value:v,label:Cv[v]})),value:o,onChange:r}),ct(Io,{marginTop:x,children:ct(it,{width:g,tiles:b})}),R&&ct(Io,{marginTop:1,flexDirection:"column",children:ct(ur,{data:p.heatmap,value:v=>v.cost,caption:a,width:g})})]})}),h&&ct(Io,{marginTop:1,flexDirection:"column",children:ct(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:x,children:ct(Nh,{data:p.chart,order:p.models.map(v=>v.model),width:g,rows:E})})}),ct(Io,{marginTop:1,flexDirection:"column",children:ct(de,{title:"\u6A21\u578B\u7528\u91CF",width:t,gap:x,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(pe,{retain:"list",items:p.models,width:g,height:z,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:v=>[v.displayName,Gn(v.tokens),Gn(v.inTokens),Gn(v.outTokens),M(v.tokens)],searchOf:v=>v.displayName})})})]})}})})})}import{Box as Sr,Text as sm}from"ink";import{useState as Fh}from"react";import{z as Ev}from"zod";import{z as gt}from"zod";var Av=gt.object({id:gt.number().int(),name:gt.string(),description:gt.string(),multiplier:gt.number()}),ka=()=>A(gt.array(Av),"/groups"),im=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()}),va=()=>A(gt.array(im),"/tokens"),$h=e=>A(im.extend({token:gt.string()}),"/tokens",{method:"POST",json:e}),Ca=(e,t)=>A(im,`/tokens/${e}`,{method:"PATCH",json:t}),Bh=e=>A(se,`/tokens/${e}`,{method:"DELETE"});import{jsx as lt,jsxs as Ra}from"react/jsx-runtime";var Uh={model:"",requestId:"",token:"",group:"",status:"",range:"today",since:"",until:""},jh=Ev.iso.date();function Mv(e){let t=Lc();return e.range==="today"?{since:t,until:t}:e.range==="7d"?{since:Wn(t,-6),until:t}:e.range==="30d"?{since:Wn(t,-29),until:t}:e.range==="custom"?{...e.since===""?{}:{since:e.since},...e.until===""?{}:{until:e.until}}:{}}function Hh(e){let t=Mv(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:Oc(t.since).toISOString()},...t.until===void 0?{}:{until:Oc(Wn(t.until,1)).toISOString()}}}var Iv=Pt(oc,Zi,"\u5168\u90E8\u72B6\u6001"),Nv=[{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 Lv({log:e,quotaPerUsd:t,width:n}){let o=n-ge,r=Zi(e.status),i=yt(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\u6CA1\u6709\u8F93\u51FA\u5185\u5BB9\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",`${co(e.firstByteMs)} s`]),e.tierOver!==null&&a.push(["\u8F93\u5165\u957F\u5EA6",Tc(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",kd(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 Ra(de,{title:e.modelDisplayName,note:K(e.createdAt),width:n,children:[Ra(sm,{wrap:"truncate",children:[lt(sm,{color:i===void 0?f.mutedForeground:et[i],children:r.label}),lt(sm,{color:f.faintForeground,children:` ${_e([e.stream?"\u6D41\u5F0F":"",e.model])}`})]}),lt(Sr,{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:Zo(e.quotaCost,t)},{label:"\u603B\u8017\u65F6",value:`${co(e.latencyMs)} s`},{label:"\u6863\u4F4D",value:$r(e.tierOver)},{label:"\u5206\u7EC4\u500D\u7387",value:`\xD7${e.multiplier}`},{label:"\u53C2\u6570\u500D\u7387",value:`\xD7${Lu(e.paramMultipliers)}`},{label:"\u603B\u500D\u7387",value:`\xD7${Ou(e.multiplier,e.paramMultipliers)}`}]})}),s!==null&<(Sr,{marginTop:1,children:lt(ye,{tone:"warn",width:o,title:s})}),lt(Sr,{marginTop:1,children:lt(Ve,{width:o,items:[...a,...c]})})]})}function qh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Fh({name:"list"}),[i,s]=Fh(Uh),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[g,T,x]=await Promise.all([ka(),va(),Be(e.ctx.site)]);return{groups:g,tokens:T,site:x}}),m=We([e.revision,JSON.stringify(i)],g=>Ph({page:g,...Hh(i)}),{retain:"page"}),p=Q([e.revision,JSON.stringify(i)],()=>Ah(Hh(i))),d=o.name==="list";G((g,T)=>{d&&(g==="r"?e.reload():g==="f"?(l(),r({name:"filter"})):T.leftArrow?m.go(-1):T.rightArrow&&m.go(1))});let S=()=>{o.name==="list"?e.pop():(l(),r({name:"list"}))},b=JSON.stringify(i)!==JSON.stringify(Uh);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:S,children:lt(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7B5B\u9009\u9009\u9879",width:t,children:({groups:g,tokens:T,site:x})=>{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(T.map(y=>y.name))].map(y=>({value:y,label:y}))],initial:i.token},{kind:"select",name:"group",label:"\u5206\u7EC4",options:[{value:"",label:"\u5168\u90E8\u5206\u7EC4"},...g.map(y=>({value:y.name,label:y.name}))],initial:i.group},{kind:"select",name:"status",label:"\u72B6\u6001",options:Iv,initial:i.status},{kind:"select",name:"range",label:"\u65F6\u95F4\u8303\u56F4",options:Nv,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:S,onSubmit:y=>{let h=y.range??"",R=(y.since??"").trim(),I=(y.until??"").trim();if(h==="custom"&&(R!==""&&!jh.safeParse(R).success||I!==""&&!jh.safeParse(I).success)){c("\u65E5\u671F\u65E0\u6548");return}s({model:y.model??"",requestId:y.requestId??"",token:y.token??"",group:y.group??"",status:y.status??"",range:h,since:R,until:I}),m.reset(),r({name:"list"})}});if(o.name==="detail")return lt(Lv,{log:o.log,quotaPerUsd:x.quotaPerUsd,width:t});let C=Ut(4,t);return Ra(Sr,{flexDirection:"column",children:[lt(Sr,{height:C+1,flexDirection:"column",overflow:"hidden",children:lt(V,{state:p,loading:"\u6B63\u5728\u7EDF\u8BA1\u7B5B\u9009\u7ED3\u679C",width:t,children:y=>lt(it,{width:t,tiles:[{label:"\u6D88\u8017",value:Te(y.quotaCost,x.quotaPerUsd)},{label:"RPM",value:Le(y.rpm)},{label:"TPM",value:Le(y.tpm)},{label:"\u5E76\u53D1",value:Le(y.concurrency)}]})})}),lt(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u4F7F\u7528\u65E5\u5FD7",width:t,children:y=>Ra(Sr,{flexDirection:"column",children:[lt(pe,{retain:"list",items:y.items,width:t,height:Math.max(3,n-2-C),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:h=>[K(h.createdAt),h.modelDisplayName,Le(h.promptTokens),Le(h.completionTokens),Zo(h.quotaCost,x.quotaPerUsd),bt(Zi(h.status))],onOpen:h=>r({name:"detail",log:h}),emptyLabel:b?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u8C03\u7528\u8BB0\u5F55",emptyDescription:b?void 0:"\u901A\u8FC7\u4EE4\u724C\u8C03\u7528 API \u540E\uFF0C\u660E\u7EC6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),lt(ze,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})}})})}import{Box as $n,Text as No}from"ink";import{useState as Uv}from"react";import{z as we}from"zod";var Ov=xc.extend({id:we.number().int(),model:we.string(),displayName:we.string(),rules:Au}),Dv=we.object({quotaPerUsd:we.number(),minTopupCny:we.number(),models:we.array(Ov)});function _a(e){return fn(Dv,`${e}/api/pricing`)}var $v=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 Gh(e){return A($v,`/pricing/${e}`)}var Bv=we.object({data:we.array(we.object({id:we.string()}))});async function Wh(e,t,n){return(await fn(Bv,`${e}/v1/models`,{headers:{authorization:`Bearer ${t}`},...n===void 0?{}:{timeoutMs:n}})).data.map(r=>r.id)}var zh=()=>A($u,"/provider-status");import{Text as xr}from"ink";import{jsx as Pa,jsxs as Vh}from"react/jsx-runtime";var Fv=` ${ae.bullet} `,Kh=1;function Yh({providers:e}){return Vh(xr,{wrap:"truncate",children:[Pa(xr,{color:f.faintForeground,children:"\u5B98\u65B9\u72B6\u6001"}),e.map(t=>{let n=Fu(t);return Vh(xr,{children:[Pa(xr,{color:f.faintForeground,children:Fv}),Pa(xr,{color:f.foreground,children:`${vd(t.provider)} `}),Pa(xr,{color:et[n.tone],children:n.label})]},t.provider)})]})}import{jsx as Ae,jsxs as Si}from"react/jsx-runtime";var jv=4,Hv=1+Ge,qv=e=>e.requests===0?f.border:e.errors===0?f.success:e.errors/e.requests>=.5?f.danger:f.warning;function Gv({minutes:e,width:t}){let n=e.slice(Math.max(0,e.length-t)),o=[];for(let r of n){let i=qv(r),s=o[o.length-1];s!==void 0&&s.color===i?s.count+=1:o.push({color:i,count:1})}return Ae(No,{wrap:"truncate",children:o.map((r,i)=>Ae(No,{color:r.color,children:ae.barFilled.repeat(r.count)},i))})}function Wv({price:e,width:t,contentRows:n}){let o=O(),r=Q([e.id,o.revision],()=>Gh(e.id)),i=Iu(e,e.rules),s=i.length>1,a=e.rules.filter(Eu),c=t-ge,l=1+i.length,u=1+a.length;return Ae(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?`${co(p.latencyP50Ms)} s`:"\u2014"},{label:"\u9996\u5B57\u8282 P50",value:p.firstByteP50Ms!==null?`${co(p.firstByteP50Ms)} s`:"\u2014"}],S=a.length>0?X+Xe+u:0,b=Hv+Xe+Ut(d.length,c,2)+X+Xe+l+S+X+Xe,g=m.heartbeat.groups.length,T=n-b-jv-X-Xe,x=Math.max(0,Math.floor(T/2));x<g&&(x=Math.max(0,Math.floor((T-1)/2))),x=Math.min(g,x);let C=x>0?X+Xe+x*2+(x<g?1:0):0,y=Math.max(1,n-b-C);return Si($n,{flexDirection:"column",children:[Ae($n,{marginBottom:Ge,children:Si(No,{wrap:"truncate",children:[Ae(No,{bold:!0,color:f.foreground,children:e.displayName}),Ae(No,{color:f.faintForeground,children:` ${e.model}`})]})}),Ae(de,{title:"\u8FD1 24 \u5C0F\u65F6",note:"\u5168\u90E8\u5206\u7EC4\u7684\u7EFC\u5408\u8C03\u7528\u7EDF\u8BA1",width:t,children:Ae(it,{width:c,tiles:d,maxPerRow:2})}),x>0&&Ae($n,{marginTop:1,flexDirection:"column",children:Si(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,x).map(h=>Si($n,{flexDirection:"column",children:[Ae(No,{wrap:"truncate",color:f.foreground,children:h.name}),Ae(Gv,{minutes:h.minutes,width:c})]},h.id)),x<g&&Ae(No,{color:f.faintForeground,children:`\u5176\u4F59 ${g-x} \u4E2A\u5206\u7EC4\u672A\u663E\u793A`})]})}),Ae($n,{marginTop:1,flexDirection:"column",children:Ae(de,{title:"\u6A21\u578B\u4EF7\u683C",note:"\u6BCF\u767E\u4E07 Token \u7684\u7F8E\u5143\u6807\u4EF7",width:t,children:Ae(pe,{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:h=>[h.name,...h.range===null?[]:[h.range],pn(h.price.inputPricePerMillionTokens,"-"),pn(h.price.outputPricePerMillionTokens,"-"),pn(h.price.cachedInputPricePerMillionTokens,"-"),pn(h.price.cacheWritePricePerMillionTokens,"-")]})})}),a.length>0&&Ae($n,{marginTop:1,flexDirection:"column",children:Ae(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:Ae(pe,{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:h=>[h.param,h.value,`\xD7${h.multiplier}`]})})}),Ae($n,{marginTop:1,flexDirection:"column",children:Ae(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?Ae(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"}):Ae(pe,{items:m.groups,width:c,height:y,columns:[{label:"\u5206\u7EC4",shrink:!0},{label:"\u8BF4\u660E",shrink:!0},{label:"\u500D\u7387",align:"right"},{label:"\u5355\u4EF7",align:"right"}],row:h=>[h.name,h.description,`\xD7${h.multiplier}`,`\xA5${(m.cnyPerUsd*h.multiplier).toFixed(2)}`]})})})]})}})}function Jh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Uv({name:"list"}),i=Q([e.revision],async()=>(await _a(e.ctx.site)).models),s=Q([e.revision],zh);G(c=>{c==="r"&&e.reload()});let a=()=>{o.name==="list"?e.pop():r({name:"list"})};return Ae(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:Ae(V,{state:i,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u5B9A\u4EF7",width:t,children:c=>{if(c.length===0)return Ae(ye,{tone:"info",width:t,title:"\u6682\u65E0\u6A21\u578B"});if(o.name==="detail")return Ae(Wv,{price:o.price,width:t,contentRows:n});let l=s.phase==="ready"?Bu(s.data.providers):[],u=l.length>0?Kh+X:0;return Si($n,{flexDirection:"column",children:[l.length>0&&Ae($n,{marginBottom:X,children:Ae(Yh,{providers:l})}),Ae(pe,{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 Lo,Text as wC}from"ink";import{useState as Da}from"react";function am(e,t){if(e===null){let[o]=t;return o===void 0?{status:"none"}:{status:"ok",line:o}}let n=t.find(o=>o.url===e.url);return n===void 0?{status:"stale"}:{status:"ok",line:n}}function Xh(e,t){let n=am(e.line,t.apiLines);if(n.status==="none")throw new F("\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"});if(n.status==="stale")throw new F("\u5DF2\u9009\u7684\u63A5\u5165\u7EBF\u8DEF\u5DF2\u4E0B\u7EBF",{hint:"\u8BF7\u5728\u4EE4\u724C\u7BA1\u7406\u4E2D\u6309 l \u91CD\u65B0\u9009\u62E9\u63A5\u5165\u7EBF\u8DEF"});return n.line}async function Qh(e,t){let n=await Be(e.site);return Wh(Xh(ho(),n).url,t)}async function Zh(e,t,n){let o=await Be(e.site),r=Xh(ho(),o).url;return{input:{siteName:o.siteName,baseUrl:t.relayUrl(r),apiKey:n},at:t.resolveDir()}}async function ey(e,t,n){let{input:o,at:r}=await Zh(e,t,n);t.apply(o,r)}async function ty(e,t,n,o,r){let{input:i,at:s}=await Zh(e,t,n);t.apply({...i,model:o,models:r},s)}import{homedir as cy}from"os";import{join as Ea,resolve as Jv}from"path";import zv from"json5";import{applyEdits as Vv,modify as Kv,parse as Yv}from"jsonc-parser";function ny(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw new F(`${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 oy(e){let t=[],n=Yv(e,t,{allowTrailingComma:!0});return t.length>0?null:n}function ry(e,t){let n=oy(e);if(n!==null)return{root:ny(n,t),jsonc:!0};try{return{root:ny(zv.parse(e),t),jsonc:!1}}catch(o){throw new F(`${t} \u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:o})}}function oo(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 xi(e){let t=Lt(e);return t===null?null:ry(t,e).root}function Bn(e,t){let n=xi(e),o=n===null?void 0:oo(n,t);return typeof o=="string"?o:null}function Aa(e,t){let n=xi(e);return n!==null&&oo(n,t)!==void 0}function Gt(e,t){let n=Lt(e)??"{}",o=n.includes(`\r
|
|
18
|
+
${n}`}import{Box as Rg,Text as ik}from"ink";import{useState as Qs}from"react";import{jsx as rk}from"react/jsx-runtime";function pr({title:e,width:t,download:n,onCancel:o,onSaved:r}){let{busy:i,error:s,run:a}=ue();return rk(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 Qf(c.path??"",l.fileName,l.bytes)},{onSuccess:r})}})}var Xs={maxCount:Tu,maxBytes:xu},eo={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",optional:!0};import{jsx as Dn,jsxs as mk}from"react/jsx-runtime";var Zs=e=>e===null?void 0:`\u539F\u56E0\uFF1A${e}`,fr=(e,t)=>e===null?0:pl(Dc(e.until),Zs(e.reason),t)+1;function Co({muted:e,width:t}){return e===null?null:Dn(Rg,{marginBottom:1,children:Dn(ye,{tone:"warn",width:t,title:Dc(e.until),detail:Zs(e.reason),wrap:!0})})}var ea=(e,t,n,o)=>t==="published"?0:pl(e[t],Zs(n),o);function Ro({notices:e,status:t,reason:n,width:o}){return t==="published"?null:Dn(ye,{tone:t==="pending"?"warn":"fail",title:e[t],detail:Zs(n),width:o,wrap:!0})}var pi=e=>e===null?0:(e.hint===void 0?1:2)+1,sk=["content","attachments"],ak=9,ck=3,lk=8;function ta({postId:e,replyTo:t,width:n,height:o,onDone:r,onCancel:i}){let{busy:s,error:a,fail:c,run:l}=ue(),[u,m]=Qs({content:"",attachments:""}),[p,d]=Qs(!1),S=sk.some(g=>(u[g]??"").trim()!==""),b=Math.min(lk,Math.max(ck,o-ak-pi(a)));return Re(S),gn(()=>d(!1),{isActive:p,layer:Vn.panel}),G(g=>{g==="q"&&S&&d(!0)},!p&&s===null),p?Dn(Pe,{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)}):Dn(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:b,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"},{...eo,initial:u.attachments}],onChange:m,onCancel:()=>S?d(!0):i(),onSubmit:g=>{let T=(g.content??"").trim(),x;try{x=Xn(g.attachments??"",ql)}catch(C){c(Se(C));return}if(T===""&&x.length===0){c(t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9");return}if(jt(T).length+x.length>ql.maxCount){c("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return}l("\u6B63\u5728\u63D0\u4EA4",()=>In(x,si,C=>kf(e,{content:di(T,C),...t===null?{}:{replyToId:t.id}})),{onSuccess:C=>r(C.id)})}})}function na({target:e,width:t,onDone:n,onCancel:o}){let{busy:r,error:i,fail:s,run:a}=ue();return Dn(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"},...Ii.map(c=>({value:c,label:Cd(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=Ii.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>ji){s(`\u8865\u5145\u8BF4\u660E\u6700\u591A ${ji} \u4E2A\u5B57\u7B26`);return}let m={reason:l,detail:u===""?null:u};a("\u6B63\u5728\u63D0\u4EA4",()=>e.kind==="post"?Pf(e.id,m):Af(e.id,m),{onSuccess:n})}})}function oa({refs:e,width:t,height:n}){let o=O(),[r,i]=Qs(null),[s,a]=Qs(null);return r!==null?Dn(pr,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${st(r.name)}`,width:t,download:async()=>{let c=await qf(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")}}):mk(Rg,{flexDirection:"column",children:[Dn(le,{width:t,height:Math.max(3,n-(s===null?0:1)),items:[{heading:"\u9644\u4EF6"},...e.map(c=>({value:c,label:Gl(c)}))],onSelect:c=>{a(null),i(c)}}),s!==null&&Dn(ik,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${st(s)}`})]})}import{Fragment as bk,jsx as me,jsxs as xn}from"react/jsx-runtime";var dk={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"},Pg="\u5BC6\u94A5 ",pk=10,fk={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"}},gk=3,hk=8;function yk({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 Ag(){let e=O(),{width:t,columns:n,rows:o}=j(),r=Z(),[i,s]=_g({name:"menu"}),[a,c]=_g(!1),{busy:l,error:u,reset:m,fail:p,run:d}=ue(),S=Q([e.revision],async()=>{let[y,h,R,I]=await Promise.all([Mn(),$f(),Lf(),Gf()]);return{user:y.user,security:h,sessions:R.sessions,avatarReview:I.review}}),b=Q([e.revision],async()=>{let[y,h]=await Promise.all([Mn(),yf()]);return{homepage:await Rl(y.user.username),todo:h}});G(y=>{i.name==="menu"&&l===null&&y==="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"})}},T=y=>{s({name:"menu"}),e.reload(),e.toast("ok",y)},x=(y,h)=>{c(!1),s({name:"codes",codes:y,message:h})},C=(y,h)=>{y==="rebind"?d("\u6B63\u5728\u751F\u6210\u65B0\u5BC6\u94A5",()=>_l({code:h}),{onSuccess:R=>s({name:"enroll",setup:R})}):y==="regenerate"?d("\u6B63\u5728\u751F\u6210\u6062\u590D\u7801",()=>Uf({code:h}),{onSuccess:({recoveryCodes:R})=>x(R,"\u6062\u590D\u7801\u5DF2\u66F4\u65B0")}):d("\u6B63\u5728\u505C\u7528",()=>Ff({code:h}),{onSuccess:()=>T("\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:S,loading:"\u6B63\u5728\u8BFB\u53D6\u8D26\u6237\u4FE1\u606F",width:t,children:({user:y,security:h,sessions:R,avatarReview:I})=>{if(i.name==="avatar")return xn(at,{flexDirection:"column",children:[I!==null&&me(at,{marginBottom:1,children:me(Ro,{notices:Lc,status:I.status,reason:I.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 U=(w.path??"").trim();if(U===""){p("\u8BF7\u8F93\u5165\u56FE\u7247\u8DEF\u5F84");return}let re;try{re=Xf(U,$r)}catch(D){p(Se(D));return}d("\u6B63\u5728\u4E0A\u4F20",()=>Wf(re),{onSuccess:()=>T("\u5DF2\u63D0\u4EA4\u5BA1\u6838")})}})]});if(i.name==="avatar-delete")return me(Pe,{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",()=>zf(),{onSuccess:()=>T("\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:y.username,placeholder:"\u8BF7\u8F93\u5165\u65B0\u7528\u6237\u540D"}],onCancel:g,onSubmit:w=>{let U=(w.username??"").trim();if(U===""||U.length>Kt){p(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>Ef({username:U}),{onSuccess:()=>T("\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=>If({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 U=(w.email??"").trim(),re=(w.code??"").trim(),D=w.password??"";if(U===""||re===""||D===""){p("\u8BF7\u586B\u5199\u65B0\u90AE\u7BB1\u3001\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Nf({email:U,code:re,password:D}),{onSuccess:()=>T("\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 U=w.old??"",re=w.next??"";if(U===""){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",()=>Mf({oldPassword:U,newPassword:re}),{onSuccess:()=>T("\u5BC6\u7801\u5DF2\u4FEE\u6539")})}});if(i.name==="confirm-logout-all")return me(Pe,{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",()=>Df(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u6240\u6709\u8BBE\u5907"),e.home()}}),onCancel:g});if(i.name==="code"){let w=fk[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:U=>{let re=(U.code??"").trim();if(re===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}C(i.intent,re)}})}if(i.name==="enroll"){let w=(re,D)=>xn(bk,{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:Pg}),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:W=>{let ee=(W.code??"").trim();if(ee===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}d("\u6B63\u5728\u7ED1\u5B9A",()=>Bf({code:ee}),{onSuccess:({recoveryCodes:he})=>x(he,"\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u7ED1\u5B9A")})}})})]}),U=Ws(i.setup.otpauthUri,{width:t,rows:r},{columns:uk(Pg)+i.setup.secret.length,rows:pk},{columns:n-t,rows:o-r});return U.fits?me(zs,{value:i.setup.otpauthUri,aside:w(U.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(yk,{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 U=i.message;s({name:"menu"}),e.reload(),e.toast("ok",U)}})})]});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 U=(w.name??"").trim();if(U===""){p("\u8BF7\u8F93\u5165\u540D\u79F0");return}d("\u6B63\u5728\u4FDD\u5B58",()=>jf(i.item.id,{name:U}),{onSuccess:()=>T("\u5DF2\u4FDD\u5B58")})}});if(i.name==="passkey-delete")return me(Pe,{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",()=>Hf(i.item.id),{onSuccess:()=>T("\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="passkey"){let w=i.item;return me(at,{flexDirection:"column",children:xn(de,{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:U=>{m(),s(U==="rename"?{name:"passkey-rename",item:w}:{name:"passkey-delete",item:w})}})})]})})}if(i.name==="confirm-revoke"){let w=i.item;return me(Pe,{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",()=>ss(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u767B\u5F55"),e.home()}});return}d("\u6B63\u5728\u9000\u51FA\u8BE5\u8BBE\u5907",()=>Of(w.id),{onSuccess:()=>T("\u5DF2\u9000\u51FA\u8BE5\u8BBE\u5907")})},onCancel:g})}if(i.name==="session"){let w=i.item;return xn(at,{flexDirection:"column",children:[me(de,{title:zo(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?dk[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=h.totp,z=b.phase==="ready"?b.data:null,M=z===null?null:z.todo,v=M===null?0:M.posts.filter(w=>w.status==="pending").length,k=M===null?0:M.posts.filter(w=>w.status==="rejected").length,_=_e([v>0&&`${v} \u7BC7\u5BA1\u6838\u4E2D`,k>0&&`${k} \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:I===null?"\u663E\u793A\u5728\u4E2A\u4EBA\u4E3B\u9875\u548C\u4F60\u7684\u53D1\u8A00\u4E2D":ld(I)},{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"},...y.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"},...h.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}]:[],...h.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?`${zo(w.device)}\uFF08\u5F53\u524D\u8BBE\u5907\uFF09`:zo(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=z===null?null:z.homepage,B=[["\u7528\u6237\u540D",st(y.username)],["\u90AE\u7BB1",y.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",Vi(P.identity.points)],["\u79EF\u5206",`${P.identity.points} \xB7 ${Ki(P.identity.points)}`],["\u52A0\u5165\u65F6\u95F4",jr(P.joinedAt)]]],J=b.phase==="error"?b:null,oe=P!==null?Ut(gk,t)+X:J!==null?(J.hint===void 0?1:2)+X:0,fe=Ys(B.length,t)+X+oe,$=X+Xe+ko,ne=P!==null&&mr(t)&&r-fe-$>=hk;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(_n,{title:"\u793E\u533A\u8DB3\u8FF9",width:t}),me(at,{marginTop:Ge,flexDirection:"column",children:me(ur,{data:P.activity,value:w=>w.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${P.activity.days.reduce((w,U)=>w+U.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:y.username}):w.kind==="my-comments"?e.push("my-comments",{username:y.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",()=>_l({}),{failToast:!0,onSuccess:U=>s({name:"enroll",setup:U})}):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 sa,Text as aa,useInput as kk}from"ink";import{useRef as $g,useState as gr}from"react";import vk from"string-width";var Eg=12e4,Mg=e=>A(mt(Di),Ue("/tickets",{...e})),Ig=e=>A(Su,"/tickets",{method:"POST",json:e}),Wl=e=>A(vu,`/tickets/${e}`),Ng=(e,t,n)=>A(se,`/tickets/${e}/messages`,{method:"POST",json:{content:t,attachmentIds:n}}),Sk=e=>A(ku,Ue("/tickets/attachments",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Eg}),xk=e=>A(se,`/tickets/attachments/${e}`,{method:"DELETE"}),ra={upload:Sk,discard:xk},Lg=(e,t)=>as(`/tickets/${e}/attachments/${t}`,{timeoutMs:Eg}),Og=e=>A(se,`/tickets/${e}/close`,{method:"POST"}),Dg=e=>A(se,`/tickets/${e}/reopen`,{method:"POST"});import{useEffect as Tk,useRef as wk}from"react";function ia(e,t,n=!0){let o=wk(t);o.current=t,Tk(()=>{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 zl}from"react/jsx-runtime";var Ck=5e3,Rk=12,_k=3,Bg=1;function Pk(e,t){let n=[],o=r=>{let i=r.spans.reduce((a,c)=>a+vk(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:Rt(r.author),color:s?f.accent:f.mutedForeground},{text:` ${K(r.createdAt)}`,color:f.faintForeground}]},c=r.content===""?[]:At([{text:Kn(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:` (${Jo(u.fileSize)})`,color:f.mutedForeground}]}));s?n.push(o(a),...c.map(o),...l.map(o)):n.push(a,...c,...l)}),n}function Fg({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=gr("main"),[s,a]=gr(!1),[c,l]=gr(null),[u,m]=gr(null),[p,d]=gr(0),{busy:S,error:b,reset:g,fail:T,run:x}=ue();Re(S!==null);let C=Q([e.id,t.revision],async()=>{let[L,P]=await Promise.all([Wl(e.id),Be(t.ctx.site)]);return{detail:L,site:P}}),[y,h]=gr(null),R=$g(0),I=$g(t.revision);I.current!==t.revision&&(I.current=t.revision,R.current+=1,y!==null&&h(null));let E=C.phase==="ready"?C.data:null,z=y??E?.detail??null;ia(Ck,async()=>{if(z===null||S!==null)return;let L=R.current,P=await Wl(e.id);L===R.current&&(P.ticket.updatedAt!==z.ticket.updatedAt||P.messages.length!==z.messages.length)&&h(P)},r==="main"&&E!==null);let M=z?.messages.some(L=>L.attachments.length>0)??!1;G(L=>{r!=="main"||s||S!==null||(L==="r"?t.reload():L==="x"&&z!==null&&z.ticket.status!=="closed"?(g(),i("confirm-close")):L==="a"&&M&&(g(),l(null),m(null),i("attachments")))}),kk((L,P)=>{P.tab&&r==="main"&&!s&&z?.ticket.status!=="closed"&&a(!0)},{isActive:r==="main"&&!s&&S===null});let v=()=>{if(r!=="main"){g(),i("main");return}if(s){a(!1);return}t.pop()},k=(L,P)=>{x("\u6B63\u5728\u53D1\u9001",()=>In(P,ra,B=>Ng(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",...z?.ticket.status==="closed"?[]:["Tab \u56DE\u590D"],...M?["a \u9644\u4EF6"]:[],...z?.ticket.status==="closed"?[]:["x \u5173\u95ED\u5DE5\u5355"],"r \u5237\u65B0"]:[];return Ht(Y,{trail:["\u5DE5\u5355\u652F\u6301",z?.ticket.title??"\u5DE5\u5355\u8BE6\u60C5"],hints:_,onEscape:v,isActive:S===null,children:Ht(V,{state:C,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:n,children:({site:L,detail:P})=>{let B=y??P,J=B.ticket,oe=J.status==="closed";if(r==="confirm-close")return Ht(Pe,{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:S,error:b,onConfirm:()=>x("\u6B63\u5728\u5173\u95ED",()=>Og(e.id),{onSuccess:()=>{i("main"),t.reload(),t.toast("ok","\u5DF2\u5173\u95ED")}}),onCancel:v});if(r==="attachments")return u!==null?Ht(pr,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${u.fileName}`,width:n,download:async()=>({fileName:u.fileName,bytes:await Lg(e.id,u.id)}),onCancel:()=>m(null),onSaved:w=>{m(null),l(w),t.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):zl(sa,{flexDirection:"column",children:[Ht(le,{width:n,height:Math.max(3,o-1),isActive:S===null,items:[{heading:"\u9644\u4EF6"},...B.messages.flatMap(w=>w.attachments.map(U=>({value:U,label:U.fileName,hint:`${Rt(w.author)} \xB7 ${Jo(U.fileSize)} \xB7 ${K(w.createdAt)}`})))],onSelect:w=>{l(null),m(w)}}),c!==null&&Ht(aa,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${c}`})]});let fe=L.ticketAutoCloseMinutes>0?Bg:0,$=oe?_k:s?Rk:Bg,ne=Math.max(3,o-fe-$-X);return zl(sa,{flexDirection:"column",children:[fe>0&&Ht(aa,{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:Pk(B.messages,n),height:ne,isActive:!s&&S===null,pinBottom:!0}),Ht(sa,{marginTop:1,flexDirection:"column",children:oe?zl(sa,{flexDirection:"column",children:[Ht(aa,{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:S===null,items:[{value:"reopen",label:"\u91CD\u65B0\u6253\u5F00"}],onSelect:()=>x("\u6B63\u5728\u91CD\u65B0\u6253\u5F00",()=>Dg(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:S!==null,busyLabel:S??"\u6B63\u5728\u53D1\u9001",error:b,fields:[{kind:"textarea",name:"content",label:"\u56DE\u590D\u5185\u5BB9",rows:3,maxLength:5e3,placeholder:"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9",optional:!0},eo],onCancel:()=>a(!1),onSubmit:w=>{let U=(w.content??"").trim(),re;try{re=Xn(w.attachments??"",Xs)}catch(D){T(Se(D));return}if(U===""&&re.length===0){T("\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9\u6216\u9644\u4EF6\u8DEF\u5F84");return}k(U,re)}},p):Ht(aa,{color:f.faintForeground,children:"\u6309 Tab \u64B0\u5199\u56DE\u590D"})})]})}})})}import{Box as Ak}from"ink";import{useState as Ek}from"react";import{jsx as _o,jsxs as Nk}from"react/jsx-runtime";var Mk=Pt(nc,Gc,"\u5168\u90E8\u72B6\u6001"),Ik={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"},Vl={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:Ik};function Ug(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Ek({name:"list"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue(),p=We([e.revision,i],b=>Mg({page:b,...i===""?{}:{status:i}}),{retain:"page"}),d=o.name==="list";G((b,g)=>{d&&(b==="r"?e.reload():b==="f"?r({name:"filter"}):b==="n"?r({name:"create-category"}):g.leftArrow?p.go(-1):g.rightArrow&&p.go(1))});let S=()=>{o.name==="list"?e.pop():o.name==="create"?r({name:"create-category"}):(l(),r({name:"list"}))};return _o(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:S,children:o.name==="filter"?_o(te,{title:"\u7B5B\u9009\u5DE5\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:Mk,initial:i}],onCancel:S,onSubmit:b=>{s(b.status??""),p.reset(),r({name:"list"})}}):o.name==="create-category"?_o(le,{width:t,height:n,items:[{heading:"\u5206\u7C7B"},...oc.map(b=>({value:b,label:es(b),hint:Vl[b].title}))],onSelect:b=>r({name:"create",category:b})}):o.name==="create"?_o(te,{title:`\u65B0\u5EFA\u5DE5\u5355 \u2014 ${es(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(b=>({value:b,label:Wc(b).label})),initial:"normal"},{kind:"text",name:"title",label:"\u6807\u9898",placeholder:Vl[o.category].title},{kind:"textarea",name:"content",label:"\u95EE\u9898\u63CF\u8FF0",rows:5,maxLength:5e3,placeholder:Vl[o.category].content},eo],onCancel:S,onSubmit:b=>{let g=(b.title??"").trim(),T=(b.content??"").trim();if(g===""){u("\u8BF7\u586B\u5199\u6807\u9898");return}if(T===""){u("\u8BF7\u586B\u5199\u95EE\u9898\u63CF\u8FF0");return}let x;try{x=Xn(b.attachments??"",Xs)}catch(C){u(Se(C));return}m("\u6B63\u5728\u63D0\u4EA4\u5DE5\u5355",()=>In(x,ra,C=>Ig({title:g,category:o.category,priority:b.priority??"normal",content:T,attachmentIds:C.map(y=>y.id)})),{onSuccess:C=>{r({name:"list"}),p.reset(),e.reload(),e.push("ticket",{id:C.id}),e.toast("ok","\u5DE5\u5355\u5DF2\u63D0\u4EA4")}})}}):_o(V,{state:p.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:t,children:b=>Nk(Ak,{flexDirection:"column",children:[_o(pe,{retain:"list",items:b.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,bt(Wc(g.priority)),es(g.category),K(g.updatedAt),bt(Gc(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}),_o(ze,{page:p.page,pages:p.pages,total:p.total,width:t})]})})})}import{Box as Lk}from"ink";import{jsx as gi}from"react/jsx-runtime";function jg({params:e}){let t=O(),{width:n}=j(),o=Z(),r=Q([e.type,t.revision],()=>jd(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(Lk,{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 Hg=(e,t)=>fn(se,`${e}/api/auth/send-code`,{json:t});async function qg(e,t){let n=await Jt(`${e}/api/auth/register`,{json:t});sn(n);let o=Vo.parse(n.data);return zr(e,Wr({refresh:null,device:null},n.headers),o)}var Gg=(e,t)=>fn(se,`${e}/api/auth/forgot-password`,{json:t}),Wg=(e,t)=>fn(se,`${e}/api/auth/reset-password`,{json:t});import{jsx as zg}from"react/jsx-runtime";function Vg(){let e=O(),{width:t}=j(),{busy:n,error:o,fail:r,run:i}=ue();return Re(n!==null),zg(Y,{trail:["\u627E\u56DE\u5BC6\u7801"],isActive:n===null,children:zg(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=>Gg(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",()=>Wg(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 Yl,Text as Dk}from"ink";import{useState as Yg}from"react";import{Box as Kg}from"ink";import{jsx as Kl,jsxs as Ok}from"react/jsx-runtime";var ca=e=>e.termsConfigured||e.privacyConfigured;function la({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 Ok(Kg,{flexDirection:"column",children:[Kl(ye,{tone:"info",width:t,title:`\u7EE7\u7EED\u524D\u8BF7\u9605\u8BFB\u5E76\u540C\u610F${r.join("\u4E0E")}`}),Kl(Kg,{marginTop:1,children:Kl(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 to,jsxs as Jg}from"react/jsx-runtime";function Xg(){let e=O(),{width:t}=j(),[n,o]=Yg({name:"credentials"}),[r,i]=Yg(!1),{busy:s,error:a,reset:c,fail:l,run:u}=ue(),m=Q([e.revision],()=>Be(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,T)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Fd(e.ctx.site,g,T),{onSuccess:x=>{if(x.status==="totp_required"){o({name:"factor",ticket:x.ticket,jar:x.jar});return}p(x.session.username)}})},S=(g,T)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Ud(e.ctx.site,g.jar,g.ticket,T,g.kind),{onSuccess:x=>p(x.username)})},b=()=>{n.name==="credentials"?e.pop():(c(),o({name:"credentials"}))};return Jg(Y,{trail:n.name==="credentials"?["\u767B\u5F55\u8D26\u53F7"]:["\u767B\u5F55\u8D26\u53F7","\u4E24\u6B65\u9A8C\u8BC1"],onEscape:b,isActive:s===null,children:[n.name==="credentials"&&to(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:g=>ca(g.legal)&&!r?to(la,{legal:g.legal,width:t,onAgree:()=>i(!0)}):Jg(Yl,{flexDirection:"column",children:[to(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:b,onSubmit:T=>{let x=(T.account??"").trim(),C=T.password??"";if(x===""||C===""){l("\u8BF7\u586B\u5199\u8D26\u53F7\u4E0E\u5BC6\u7801");return}d(x,C)}}),to(Yl,{marginTop:1,children:to(Dk,{color:f.faintForeground,children:"Passkey \u767B\u5F55\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"})})]})}),n.name==="factor"&&to(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"&&to(Yl,{flexDirection:"column",children:to(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:b,onSubmit:g=>{let T=(g.code??"").trim();if(T===""){l("\u8BF7\u586B\u5199\u9A8C\u8BC1\u7801");return}S(n,T)}})})]})}import{useState as $k}from"react";import{jsx as ma}from"react/jsx-runtime";function Qg(){let e=O(),{width:t}=j(),[n,o]=$k(!1),{busy:r,error:i,fail:s,run:a}=ue(),c=Q([e.revision],()=>Be(e.ctx.site));return ma(Y,{trail:["\u6CE8\u518C\u8D26\u53F7"],isActive:r===null,children:ma(V,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:l=>ca(l.legal)&&!n?ma(la,{legal:l.legal,width:t,onAgree:()=>o(!0)}):ma(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=>Hg(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(),S=u.password??"",b=(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(S.length<Ot){s(`\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}a("\u6B63\u5728\u6CE8\u518C",()=>qg(e.ctx.site,{username:m,email:p,password:S,code:d,...b===""?{}:{inviteCode:b}}),{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 Bk}from"react";import{jsx as Nt,jsxs as eh}from"react/jsx-runtime";var Fk=["category","title","content","attachments"],Uk=11,jk=2,Hk=3,qk=16,Zg={new:"\u53D1\u5E03\u5E16\u5B50",draft:"\u7F16\u8F91\u8349\u7A3F",edit:"\u7F16\u8F91\u5E16\u5B50"};function Gk(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 Wk(e,t){return e.find(n=>String(n.id)===t)?.description}function th({mode:e}){let t=O(),{width:n}=j(),o=Z(),r=Gk(e),[i,s]=Me("values",()=>r),[a,c]=Bk(!1),{busy:l,error:u,fail:m,reset:p,run:d}=ue(),S=Q([],Fs),b=Fk.some(E=>(i[E]??"")!==(r[E]??""));Re(b||l!==null);let g=E=>{let z=E.category??"";return{categoryId:z===""?null:Number(z),title:(E.title??"").trim(),content:(E.content??"").trim()}},T=(E,z)=>{let M;try{M=Xn(E.attachments??"",Hl)}catch(v){return m(Se(v)),null}return jt(z).length+M.length>Hl.maxCount?(m("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650"),null):M},x=async E=>{switch(e.kind){case"new":return(await bf(E)).id;case"draft":return await wf(e.draft.id,E),e.draft.id;case"edit":return await Sf(e.post.id,E),e.post.id}},C=E=>{if(e.kind==="edit"&&!b){m("\u5185\u5BB9\u672A\u4FEE\u6539");return}let{categoryId:z,title:M,content:v}=g(E);if(z===null){m("\u8BF7\u9009\u62E9\u677F\u5757");return}if(M===""){m("\u8BF7\u586B\u5199\u6807\u9898");return}if(M.length>uo){m(`\u6807\u9898\u6700\u591A ${uo} \u4E2A\u5B57\u7B26`);return}let k=T(E,v);if(k!==null){if(v===""&&k.length===0){m("\u8BF7\u586B\u5199\u6B63\u6587");return}d("\u6B63\u5728\u63D0\u4EA4",()=>In(k,si,_=>x({categoryId:z,title:M,content:di(v,_)})),{onSuccess:_=>{t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838"),t.pop(),e.kind!=="edit"&&t.push("post",{id:_})}})}},y=(E,z)=>{let{categoryId:M,title:v,content:k}=g(E);if(v.length>uo){m(`\u6807\u9898\u6700\u591A ${uo} \u4E2A\u5B57\u7B26`);return}let _=T(E,k);_!==null&&d("\u6B63\u5728\u4FDD\u5B58\u8349\u7A3F",()=>In(_,si,async L=>{let P={categoryId:M,title:v,content:di(k,L)};z===null?await xf(P):await Tf(z,P)}),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5B58\u8349\u7A3F")}})},h=e.kind==="draft"?e.draft.id:null,R=()=>{if(!b){t.pop();return}p(),c(!0)},I=()=>{if(!a){t.pop();return}p(),c(!1)};return G(E=>{E==="q"&&b&&R()},!a&&l===null),Nt(Y,{trail:["\u793E\u533A\u8BBA\u575B",Zg[e.kind]],onEscape:I,isActive:l===null,children:Nt(V,{state:S,loading:"\u6B63\u5728\u8BFB\u53D6\u677F\u5757",width:n,children:E=>{if(a&&e.kind==="edit")return Nt(Pe,{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:I});if(a)return eh(hi,{flexDirection:"column",children:[Nt(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&&Nt(hi,{marginTop:1,children:Nt(Ft,{message:u.message,hint:u.hint,width:n})}),Nt(hi,{marginTop:1,children:l!==null?Nt(Oe,{label:l}):Nt(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"?y(i,h):L==="stay"?I():t.pop()}})})]});let z=e.kind==="edit"?0:1,M=e.kind==="edit"&&e.post.status==="published",v=M?jk:0,k=Math.min(qk,Math.max(Hk,o-Uk-z-v-pi(u))),_=i.category??"";return eh(hi,{flexDirection:"column",children:[M&&Nt(hi,{marginBottom:1,children:Nt(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"})}),Nt(te,{title:Zg[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=>Wk(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:k,maxLength:Ui,initial:i.content,placeholder:"\u8BF7\u8F93\u5165\u6B63\u6587\uFF0C\u652F\u6301 Markdown"},{...eo,initial:i.attachments}],secondary:e.kind==="edit"?void 0:{label:"\u5B58\u8349\u7A3F",onSubmit:L=>y(L,h)},onChange:s,onCancel:R,onSubmit:C})]})}})})}function nh({params:e}){return Nt(th,{mode:e.draft===null?{kind:"new"}:{kind:"draft",draft:e.draft}})}function oh({params:e}){return Nt(th,{mode:{kind:"edit",post:e.post}})}import{Box as no,Text as Jl}from"ink";import{useEffect as Xl,useMemo as rh,useState as ua}from"react";import{useRef as zk}from"react";function qt(e){let t=zk(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 Ql}from"react/jsx-runtime";var da={kind:"floor"},Vk=2,ih=3,Kk=4,ch=2,sh=3,ah="PgUp PgDn \u6EDA\u52A8\u6B63\u6587",pa=(e,t)=>{let n=ea(Qo,e.status,e.reviewReason,t);return n===0?0:n+1};function Yk(e,t,n,o,r){let i=Math.max(ch+sh,o-Vk-pa(e,r)-3),s=Math.max(sh,Math.min(Kk,i-ih)),a=Math.min(ih,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 Jk(e,t,n,o,r){let i=o-Xe-1-pa(e,r)-2-n;return Math.min(t.length,Math.max(ch,i))}function Xk(e,t,n,o){let r=e.status==="published"&&t.status==="published"&&n.status==="published",i=On(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:Rt(n.author)},...i?[{value:"delete",label:"\u5220\u9664",labelTone:"danger"}]:[]]}function lh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=ua({name:"main"}),[s,a]=ua(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,U,re,D]=await Promise.all([Us(e.postId),mf(e.postId,e.floorId),Mn(),cr()]);return{post:w,floor:U,me:re.user,muted:D.muted}})),d=We([e.floorId,t.revision],w=>uf(e.floorId,w),{retain:"replies-page"}),S=qt(d.state),b=p.phase==="ready"?p.data:null,g=S.phase==="ready"?S.data:null,[T,x]=ua(void 0);Xl(()=>x(void 0),[b]);let[C,y]=ua(new Map);Xl(()=>y(new Map),[g]);let h=b===null?null:{...b,floor:{...b.floor,...T}},R=g===null?[]:g.items.map(w=>({...w,...C.get(w.id)})),I=vg(md(R)),E=r.name==="actions"?R.find(w=>w.id===r.id)??null:null,z=s!==null&&R.some(w=>w.id===s);Xl(()=>{z&&a(null)},[z]);let M=h===null?null:h.floor.content,v=rh(()=>M===null?[]:ui(M,n),[M,n]),k=E===null?null:E.content,_=rh(()=>k===null?[]:ui(k,n-ge),[k,n]),L=h===null?null:Yk(h.floor,v,R.length,o-fr(h.muted,n),n),P=h===null||E===null?null:Xk(h.post,h.floor,E,h.me.username),B=E===null||P===null?null:Jk(E,_,P.length,o,n-ge),J=w=>h===null?null:w.kind==="floor"?h.floor:R.find(U=>U.id===w.id)??null,oe=(w,U)=>{m(w.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>Rf(w.id,!w.liked),{failToast:!0,onSuccess:({likeCount:re})=>U({liked:!w.liked,likeCount:re})})};G((w,U)=>{if(h===null||r.name!=="main"||c!==null)return;let{post:re,floor:D,me:W}=h,ee=re.status==="published"&&D.status==="published",he=On(D.author,W.username);w==="r"?t.reload():U.leftArrow?d.go(-1):U.rightArrow?d.go(1):w==="c"&&ee?i({name:"reply",target:da}):w==="l"&&ee&&!he?oe(D,x):w==="p"&&ee&&!he?i({name:"report",target:da}):w==="a"&&jt(D.content).length>0?i({name:"attachments",target:da}):w==="u"?t.push("homepage",{author:mi(D.author)}):w==="d"&&he&&(u(),i({name:"confirm-delete",target:da}))});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,U)=>{let re={kind:"reply",id:w.id};U==="like"?oe(w,D=>y(W=>new Map(W).set(w.id,D))):U==="reply"?i({name:"reply",target:re}):U==="report"?i({name:"report",target:re}):U==="attachments"?i({name:"attachments",target:re}):U==="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(h===null)return[];if(r.name==="actions")return B===null?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C",..._.length>B?[ah]:[]];if(r.name!=="main"||L===null)return[];let{post:w,floor:U,me:re}=h,D=w.status==="published"&&U.status==="published",W=On(U.author,re.username);return[...R.length>0?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C"]:[],...v.length>L.bodyRows?[ah]:[],...D?["c \u56DE\u590D"]:[],...D&&!W?[U.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E","p \u4E3E\u62A5"]:[],...jt(U.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...W?["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:U,me:re,muted:D})=>{let W={...U,...T},ee=ie=>`${On(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 Ql(de,{title:Rt(E.author),note:K(E.createdAt),width:n,children:[Ee(Jl,{wrap:"truncate",color:f.mutedForeground,children:_e([E.replyTo!==null&&`\u56DE\u590D ${Js(E.replyTo.author)}`,ee(E)])}),pa(E,ie)>0&&Ee(no,{marginTop:1,children:Ee(Ro,{notices:Qo,status:E.status,reason:E.reviewReason,width:ie})}),Ee(no,{marginTop:1,children:Ee(pt,{lines:_,height:B,isActive:c===null,pageKeysOnly:!0})}),Ee(no,{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(ta,{postId:w.id,replyTo:{id:ie.id,mention:Js(ie.author)},width:n,height:o,onCancel:fe,onDone:Tt=>{i({name:"main"}),a(Tt),d.last(),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838")}});if(r.name==="report")return Ee(na,{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(oa,{refs:jt(ie.content),width:n,height:o});let Qe=r.target.kind==="floor";return Ee(Pe,{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",()=>vf(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 Ql(no,{flexDirection:"column",children:[Ee(Co,{muted:D,width:n}),Ee(Jl,{bold:!0,wrap:"truncate",color:f.foreground,children:w.title}),c!==null?Ee(Oe,{label:c}):Ee(Jl,{wrap:"truncate",color:f.mutedForeground,children:_e([W.floor!==null&&`#${W.floor}`,Rt(W.author),K(W.createdAt),`\u56DE\u590D ${W.replyCount}`,ee(W)])}),pa(W,n)>0&&Ee(no,{marginTop:1,children:Ee(Ro,{notices:Qo,status:W.status,reason:W.reviewReason,width:n})}),Ee(no,{marginTop:1,children:Ee(pt,{lines:v,height:L.bodyRows,isActive:he,pageKeysOnly:!0})}),Ee(no,{marginTop:1,children:Ee(V,{state:S,loading:"\u6B63\u5728\u8BFB\u53D6\u56DE\u590D",width:n,children:()=>Ql(no,{flexDirection:"column",children:[Ee(pe,{retain:"replies",items:I,width:n,height:L.listRows,isActive:he,columns:[Zn,{label:"\u56DE\u590D",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:({reply:ie,mention:Qe,prefix:Tt})=>[`${Tt}${Rt(ie.author)}`,Qe===null?vo(ie.content):`\u56DE\u590D ${Js(Qe)}\uFF1A${vo(ie.content)}`,String(ie.likeCount),K(ie.createdAt),ie.status==="published"?"":bt(go(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"&&W.status==="published"?"\u6309 c \u56DE\u590D\u672C\u697C":void 0}),Ee(ze,{page:d.page,pages:d.pages,total:d.total,width:n})]})})})]})}})})}import{Box as Po,Text as ha}from"ink";import{Box as mh}from"ink";import{jsx as hr,jsxs as uh}from"react/jsx-runtime";function fa({author:e,owner:t,width:n,height:o}){let r=O(),i=We([e.kind,e.username,r.revision],a=>pf(e,a),{retain:"posts-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),hr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:a=>uh(mh,{flexDirection:"column",children:[hr(pe,{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}]:[],dr,{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?[Oc(Hr,c)??""]:[],c.category.name,String(c.commentCount),String(c.viewCount),String(c.likeCount),K(c.publishedAt??c.createdAt),...t?[bt(go(c.status))]:[]],onOpen:c=>r.push("post",{id:c.id}),emptyLabel:"\u6682\u65E0\u5E16\u5B50"}),hr(ze,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}function ga({author:e,owner:t,width:n,height:o}){let r=O(),i=We([e.kind,e.username,r.revision],a=>ff(e,a),{retain:"comments-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),hr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u8BC4\u8BBA",width:n,children:a=>uh(mh,{flexDirection:"column",children:[hr(pe,{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=>[vo(c.content),...t?[Oc(Qo,c)??""]:[],c.post.title??Ji,String(c.likeCount),K(c.createdAt),...t?[bt(go(c.status))]:[]],onOpen:c=>r.push("floor",{postId:c.post.id,floorId:c.floorId}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA"}),hr(ze,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}import{jsx as St,jsxs as ya}from"react/jsx-runtime";var Qk=[{value:"posts",label:"\u5E16\u5B50"},{value:"comments",label:"\u8BC4\u8BBA"}],Zk=3,ev=2,tv=5;function nv({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 ya(Po,{flexDirection:"column",children:[ya(ha,{wrap:"truncate",children:[St(ha,{bold:!0,color:f.foreground,children:st(r.username)}),St(ha,{color:f.accent,children:` ${r.kind==="user"?Vi(r.points):`[${Yi}]`}`})]}),St(ha,{wrap:"truncate",color:f.mutedForeground,children:_e([r.kind==="user"&&`${r.points} \u79EF\u5206`,t&&r.kind==="user"&&Ki(r.points),`\u52A0\u5165\u4E8E ${jr(e.joinedAt)}`])}),St(Po,{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&&ya(Po,{marginTop:X,flexDirection:"column",children:[St(_n,{title:"\u793E\u533A\u8DB3\u8FF9",width:n}),St(Po,{marginTop:Ge,flexDirection:"column",children:St(ur,{data:e.activity,value:a=>a.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${s} \u6B21`,width:n})})]})]})}function dh({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([df(e.author),Mn()]),S=e.author.kind==="user"&&e.author.username===d.user.username;return{profile:p,owner:S}});G(p=>{p==="r"?t.reload():p==="t"&&i(d=>d==="posts"?"comments":"posts")});let a=ev+1+Ut(Zk,n),c=o-a-2-1,l=X+Xe+ko,u=mr(n)&&c-l>=tv,m=Math.max(3,c-(u?l:0));return St(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:St(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u6237\u4E3B\u9875",width:n,children:({profile:p,owner:d})=>ya(Po,{flexDirection:"column",children:[St(nv,{profile:p,owner:d,width:n,heatmapOn:u}),St(Po,{marginTop:1,children:St(qs,{options:Qk,value:r,onChange:i,arrowKeys:!1})}),St(Po,{marginTop:1,children:r==="posts"?St(fa,{author:e.author,owner:d,width:n,height:m}):St(ga,{author:e.author,owner:d,width:n,height:m})})]})})})}import{Box as ph}from"ink";import{useState as ov}from"react";import{jsx as Ao,jsxs as gh}from"react/jsx-runtime";var rv={sort:"activity",categoryId:"",q:"",author:""},fh=e=>e.categoryId!==""||e.q!==""||e.author!=="",iv=(e,t)=>({page:t,sort:e.sort,...e.categoryId===""?{}:{categoryId:Number(e.categoryId)},...e.q===""?{}:{q:e.q},...e.author===""?{}:{author:e.author}});function hh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=ov(!1),[i,s]=Me("filters",()=>rv),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[d,S]=await Promise.all([cr(),Fs()]);return{muted:d.muted,categories:S}}),m=We([e.revision,JSON.stringify(i)],d=>af(iv(i,d)),{retain:"page"});G((d,S)=>{o||(d==="r"?e.reload():d==="f"?r(!0):d==="n"?e.push("compose",{draft:null}):S.leftArrow?m.go(-1):S.rightArrow&&m.go(1))});let p=()=>{if(!o){e.pop();return}l(),r(!1)};return Ao(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:Ao(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u793E\u533A",width:t,children:({muted:d,categories:S})=>o?Ao(te,{title:"\u7B5B\u9009\u5E16\u5B50",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"select",name:"sort",label:"\u6392\u5E8F",options:ic.map(b=>({value:b,label:Rd(b)})),initial:i.sort},{kind:"select",name:"category",label:"\u677F\u5757",options:[{value:"",label:"\u5168\u90E8\u677F\u5757"},...S.map(b=>({value:String(b.id),label:b.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:b=>{let g=(b.q??"").trim(),T=(b.author??"").trim();if(g.length>Hi){c(`\u5173\u952E\u8BCD\u6700\u591A ${Hi} \u4E2A\u5B57\u7B26`);return}if(T.length>Kt){c(`\u7528\u6237\u540D\u6700\u591A ${Kt} \u4E2A\u5B57\u7B26`);return}s({sort:b.sort,categoryId:b.category??"",q:g,author:T}),m.reset(),l(),r(!1)}}):gh(ph,{flexDirection:"column",children:[Ao(Co,{muted:d,width:t}),Ao(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:t,children:b=>gh(ph,{flexDirection:"column",children:[Ao(pe,{retain:"list",items:b.items,width:t,height:Math.max(3,n-1-fr(d,t)),columns:[{label:"\u4E3B\u9898",shrink:!0},Zn,dr,{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,Rt(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:fh(i)?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u5E16\u5B50",emptyDescription:fh(i)?void 0:"\u6309 n \u53D1\u5E03\u7B2C\u4E00\u7BC7\u5E16\u5B50"}),Ao(ze,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})})})}import{Box as ba}from"ink";import{useState as sv}from"react";import{jsx as ft,jsxs as kh}from"react/jsx-runtime";var av=X+Xe+2,cv=X+2+1+2;function bh(){let e=O();G(t=>{t==="r"&&e.reload()})}function Sh({params:e}){let{width:t}=j(),n=Z();return bh(),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(fa,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function xh({params:e}){let{width:t}=j(),n=Z();return bh(),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(ga,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function Th(){let e=O(),{width:t}=j(),n=Z(),o=We([e.revision],r=>gf(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=>kh(ba,{flexDirection:"column",children:[ft(pe,{retain:"list",items:r.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},Zn,{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:i=>[i.title,Rt(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(ze,{page:o.page,pages:o.pages,total:o.total,width:t})]})})})}var yh=e=>e.title===""?"\u672A\u547D\u540D\u8349\u7A3F":e.title;function wh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=sv({name:"list"}),{busy:i,error:s,reset:a,run:c}=ue();Re(i!==null);let l=We([e.revision],d=>hf(d),{retain:"page"}),u=o.name==="list";G((d,S)=>{u&&(d==="r"?e.reload():S.leftArrow?l.go(-1):S.rightArrow&&l.go(1))});let m=()=>{if(u){e.pop();return}a(),r({name:"list"})},p=o.name==="actions"?av:o.name==="confirm-delete"?cv+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=>kh(ba,{flexDirection:"column",children:[ft(pe,{retain:"list",items:d.items,width:t,height:Math.max(3,n-1-p),isActive:u,columns:[{label:"\u6807\u9898",shrink:!0},dr,{label:"\u521B\u5EFA\u65F6\u95F4",align:"right"}],row:S=>[yh(S),S.category===null?"\u2014":S.category.name,K(S.createdAt)],onOpen:S=>r({name:"actions",draft:S}),emptyLabel:"\u6682\u65E0\u8349\u7A3F",emptyDescription:"\u53D1\u5E03\u5E16\u5B50\u65F6\u53EF\u9009\u62E9\u5B58\u4E3A\u8349\u7A3F"}),ft(ze,{page:l.page,pages:l.pages,total:l.total,width:t}),o.name==="actions"&&ft(ba,{marginTop:X,children:ft(de,{title:yh(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:S=>{if(S==="edit"){r({name:"list"}),e.push("compose",{draft:o.draft});return}a(),r({name:"confirm-delete",draft:o.draft})}})})}),o.name==="confirm-delete"&&ft(ba,{marginTop:X,children:ft(Pe,{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",()=>js(o.draft.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:m})})]})})})}import{Box as Eo,Text as Zl}from"ink";import{useEffect as Sa,useMemo as lv,useRef as mv,useState as em}from"react";import{jsx as Ke,jsxs as tm}from"react/jsx-runtime";var vh=2,uv=2,dv=2;function pv({post:e,width:t,height:n,isActive:o,follow:r,onFollowed:i}){let s=O(),a=We([e.id,s.revision],u=>lf(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 Sa(()=>{r!==null&&a.last()},[r]),Sa(()=>{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=>tm(Eo,{flexDirection:"column",children:[Ke(pe,{retain:"floors",items:u.items,width:t,height:Math.max(3,n-1),isActive:o,columns:[{label:"\u697C\u5C42"},Zn,{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}`,Rt(m.author),vo(m.content),String(m.replyCount),String(m.likeCount),m.status==="published"?"":bt(go(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(ze,{page:a.page,pages:a.pages,total:a.total,width:t})]})})}function Ch({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("mode",()=>"body"),[s,a]=em({name:"main"}),[c,l]=em(null),{busy:u,error:m,reset:p,run:d}=ue();Re(s.name==="confirm-delete"&&u!==null);let S=mv(null),b=qt(Q([e.id,t.revision],async()=>{let[M,v,k]=await Promise.all([Us(e.id),Mn(),cr()]);return{post:M,me:v.user,muted:k.muted}})),g=b.phase==="ready"?b.data:null,[T,x]=em(null);Sa(()=>x(null),[g]);let C=g===null?null:{...g,post:{...g.post,...T}},y=C!==null&&C.post.status==="published";Sa(()=>{!y||S.current===e.id||(S.current=e.id,cf(e.id).catch(()=>t.toast("warn","\u6D4F\u89C8\u8BA1\u6570\u53D1\u9001\u5931\u8D25")))},[e.id,y]);let h=s.name==="main"&&u===null,R=C===null?null:C.post.content,I=lv(()=>R===null?[]:ui(R,n),[R,n]);G(M=>{if(C===null||!h)return;let{post:v,me:k}=C;if(M==="r"){t.reload();return}if(M==="v"){i(r==="body"?"floors":"body");return}if(M==="c"&&y){a({name:"comment"});return}if(r!=="body")return;let _=On(v.author,k.username),L={liked:v.liked,likeCount:v.likeCount,bookmarked:v.bookmarked};M==="l"&&y&&!_?d(v.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>Cf(v.id,!v.liked),{failToast:!0,onSuccess:({likeCount:P})=>x({...L,liked:!v.liked,likeCount:P})}):M==="b"&&y?d(v.bookmarked?"\u6B63\u5728\u53D6\u6D88\u6536\u85CF":"\u6B63\u5728\u6536\u85CF",()=>_f(v.id,!v.bookmarked),{failToast:!0,onSuccess:()=>{x({...L,bookmarked:!v.bookmarked}),t.toast("ok",v.bookmarked?"\u5DF2\u53D6\u6D88\u6536\u85CF":"\u5DF2\u6536\u85CF")}}):M==="p"&&y&&!_?a({name:"report"}):M==="a"&&jt(v.content).length>0?a({name:"attachments"}):M==="u"?t.push("homepage",{author:mi(v.author)}):M==="e"&&_&&v.status!=="removed"?t.push("post-edit",{post:v}):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()},z=()=>{if(C===null||s.name!=="main")return[];let{post:M,me:v}=C;if(r==="floors")return["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...y?["c \u8BC4\u8BBA"]:[],"v \u6B63\u6587","r \u5237\u65B0"];let k=On(M.author,v.username);return["\u2191\u2193 \u6EDA\u52A8","v \u697C\u5C42\u5217\u8868",...y?["c \u8BC4\u8BBA",...k?[]:[M.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E"],M.bookmarked?"b \u53D6\u6D88\u6536\u85CF":"b \u6536\u85CF",...k?[]:["p \u4E3E\u62A5"]]:[],...jt(M.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...k&&M.status!=="removed"?["e \u7F16\u8F91\u5E16\u5B50"]:[],...k?["d \u5220\u9664"]:[],"r \u5237\u65B0"]};return Ke(Y,{trail:["\u793E\u533A\u8BBA\u575B",C===null?"\u5E16\u5B50\u8BE6\u60C5":C.post.category.name,...r==="floors"&&s.name==="main"?["\u697C\u5C42\u5217\u8868"]:[]],hints:z(),onEscape:E,isActive:s.name==="main"||u===null,children:Ke(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:({post:M,me:v,muted:k})=>{let _={...M,...T},L=On(_.author,v.username);if(s.name==="comment")return Ke(ta,{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(na,{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(oa,{refs:jt(_.content),width:n,height:o});if(s.name==="confirm-delete")return Ke(Pe,{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",()=>js(_.id),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:E});let P=Ke(Zl,{bold:!0,wrap:"truncate",color:f.foreground,children:_.title}),B=fr(k,n);if(r==="floors")return tm(Eo,{flexDirection:"column",children:[Ke(Co,{muted:k,width:n}),P,Ke(Eo,{marginTop:1,children:Ke(pv,{post:_,width:n,height:o-vh-B,isActive:h,follow:c,onFollowed:()=>l(null)})})]});let J=ea(Hr,_.status,_.reviewReason,n),oe=Math.max(dv,o-B-vh-(J===0?0:J+1)-1-uv);return tm(Eo,{flexDirection:"column",children:[Ke(Co,{muted:k,width:n}),P,Ke(Zl,{wrap:"truncate",color:f.mutedForeground,children:_e([Rt(_.author),K(_.publishedAt??_.createdAt),_.editedAt!==null&&`\u7F16\u8F91\u4E8E ${K(_.editedAt)}`,`\u6D4F\u89C8 ${_.viewCount}`])}),J>0&&Ke(Eo,{marginTop:1,children:Ke(Ro,{notices:Hr,status:_.status,reason:_.reviewReason,width:n})}),Ke(Eo,{marginTop:1,children:Ke(pt,{lines:I,height:oe,isActive:h})}),Ke(Eo,{marginTop:1,children:u!==null?Ke(Oe,{label:u}):Ke(Zl,{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 Io}from"ink";import{useEffect as kv,useRef as vv,useState as rm}from"react";import{z as H}from"zod";var fv=H.object({balance:H.number(),today:H.object({requests:H.number(),tokens:H.number(),cost:H.number()})}),Rh=()=>A(fv,"/dashboard/summary"),_h=["all","30d","7d"],gv=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()}),nm=e=>A(gv,Ue("/dashboard/stats",{range:e})),hv=H.object({id:H.number().int(),requestId:H.string(),tokenName:H.string(),protocol:Um,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:Nu,status:Km,httpStatus:H.number().int(),stopReason:H.string().nullable(),latencyMs:H.number(),firstByteMs:H.number().nullable(),stream:H.boolean(),ip:H.string(),createdAt:H.string()}),Ph=e=>A(mt(hv),Ue("/logs",{...e})),yv=H.object({quotaCost:H.number(),rpm:H.number(),tpm:H.number(),concurrency:H.number()}),Ah=e=>A(yv,Ue("/logs/stats",{...e})),bv=H.object({id:H.number().int(),type:Wm,amount:H.number(),balanceAfter:H.number(),refType:zm,refId:H.string().nullable(),createdAt:H.string()}),Eh=e=>A(mt(bv),Ue("/quota-ledger",{...e}));import{Box as Sv,Text as ln}from"ink";import yi from"string-width";import{Fragment as Ih,jsx as mn,jsxs as om}from"react/jsx-runtime";var Mo=1,xv=4,Tv=1,yr=8,wv=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587"],Mh=e=>`${Number(e.slice(5,7))}\u6708${Number(e.slice(8,10))}\u65E5`;function Nh({data:e,order:t,width:n,rows:o}){let r=o-Tv,i=[];for(let M=e.start;M<=e.end;M=Wn(M,1))i.push(M);let s=Math.min(xv,Math.floor((n+Mo)/i.length)-Mo);s<1&&(s=1,i=i.slice(-Math.floor((n+Mo)/(1+Mo))));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,Ts.length).map((M,v)=>[M,v])),u=Ts.length,m=M=>Ts[M]??f.faintForeground,p=new Map(i.map((M,v)=>[M,v])),d=i.map(()=>Array.from({length:u+1},()=>0));for(let M of e.points){let v=p.get(M.day);if(v===void 0)continue;let k=d[v];if(k===void 0)continue;let _=l.get(M.model)??u;k[_]=(k[_]??0)+M.tokens}let S=d.map(M=>M.reduce((v,k)=>v+k,0)),b=Math.max(0,...S),g=r*yr,T=d.map((M,v)=>{let k=Array.from({length:r},()=>null),_=S[v]??0;if(_<=0)return k;let L=Math.max(1,Math.round(_/b*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(yr,L-oe*yr);if(fe<=0)break;let $=new Map;for(let U=oe*yr;U<oe*yr+fe;U+=1){let re=P[U];re!==void 0&&$.set(re,($.get(re)??0)+1)}let ne=null,w=0;for(let[U,re]of $)re>w&&(ne=U,w=re);if(ne===null)break;k[oe]={color:ne,glyph:fe===yr?null:wv[fe-1]??null}}return k}),x=M=>{let v=[],k=(_,L,P)=>{let B=v[v.length-1];B!==void 0&&B.color===_&&B.glyph===L?B.width+=P:v.push({color:_,glyph:L,width:P})};return T.forEach((_,L)=>{L>0&&k(null,null,Mo);let P=_[M]??null;P===null?k(null,null,s):k(P.color,P.glyph,s)}),v},C=i.length*(s+Mo)-Mo,y=Mh(a),h=Mh(c),R=b>0?`\u5355\u65E5\u5CF0\u503C ${Gn(b)}`:"",I=C-yi(y)-yi(h),E=R!==""&&I>=yi(R)+4,z=E?Math.floor((I-yi(R))/2):I;return om(Sv,{flexDirection:"column",children:[Array.from({length:r},(M,v)=>{let k=r-1-v;return mn(ln,{wrap:"truncate",children:x(k).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))},k)}),mn(ln,{wrap:"truncate",children:I<2?mn(ln,{color:f.faintForeground,children:qe(y,C)}):om(Ih,{children:[mn(ln,{color:f.faintForeground,children:y}),mn(ln,{children:" ".repeat(z)}),E&&om(Ih,{children:[mn(ln,{color:f.mutedForeground,children:R}),mn(ln,{children:" ".repeat(I-yi(R)-z)})]}),mn(ln,{color:f.faintForeground,children:h})]})})]})}import{jsx as ct,jsxs as Oh}from"react/jsx-runtime";var Cv={all:"\u5168\u90E8","30d":"30 \u5929","7d":"7 \u5929"},Rv=1,xa=4,Lh=5,_v=9;function Pv(e){let t=-1,n=0;return e.forEach((o,r)=>{o>n&&(n=o,t=r)}),t<0?"\u2014":`${t} \u70B9`}function Dh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=rm("30d"),[i,s]=rm("heatmap"),[a,c]=rm(null),l=vv(null),u=Q([o,e.revision],async()=>{let m=l.current;if(m!==null&&m.revision===e.revision){let b=await nm(o);return{summary:m.summary,stats:b,site:m.site}}let[p,d,S]=await Promise.all([Rh(),nm(o),Be(e.ctx.site)]);return l.current={revision:e.revision,summary:p,site:S},{summary:p,stats:d,site:S}});return kv(()=>{u.phase==="ready"&&c(Sd({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(Io,{flexDirection:"column",children:ct(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u91CF",width:t,children:({summary:m,stats:p,site:d})=>{let S=[{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)}],b=[{label:"\u8BF7\u6C42\u6570",value:Le(p.totals.requests)},{label:"Token \u603B\u91CF",value:Gn(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:Pv(p.hourly)},{label:"\u5E38\u7528\u6A21\u578B",value:p.models[0]?.displayName??"\u2014"}],g=t-ge,T=v=>Bt+v+Ut(S.length,g)+X+Bt+v+Rv+v+Ut(b.length,g)+X+Bt+v,x=n-T(Ge)>=xa?Ge:0,C=n-T(x),y=X+Bt+x+Lh,h=i==="chart"&&p.chart.points.length>0&&C>=y+xa,R=i==="heatmap"&&mr(g)&&C-(X+ko)>=xa,I=R?X+ko:0,E=h?Math.min(_v,Lh+Math.floor((C-y-xa)/2)):0,z=C-I-(h?X+Bt+x+E:0),M=v=>`${(p.totals.tokens>0?v/p.totals.tokens*100:0).toFixed(1)}%`;return Oh(Io,{flexDirection:"column",children:[ct(de,{title:"\u6982\u89C8",width:t,gap:x,children:ct(it,{width:g,tiles:S})}),ct(Io,{marginTop:1,flexDirection:"column",children:Oh(de,{title:"\u533A\u95F4\u7EDF\u8BA1",width:t,gap:x,children:[ct(qs,{options:_h.map(v=>({value:v,label:Cv[v]})),value:o,onChange:r}),ct(Io,{marginTop:x,children:ct(it,{width:g,tiles:b})}),R&&ct(Io,{marginTop:1,flexDirection:"column",children:ct(ur,{data:p.heatmap,value:v=>v.cost,caption:a,width:g})})]})}),h&&ct(Io,{marginTop:1,flexDirection:"column",children:ct(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:x,children:ct(Nh,{data:p.chart,order:p.models.map(v=>v.model),width:g,rows:E})})}),ct(Io,{marginTop:1,flexDirection:"column",children:ct(de,{title:"\u6A21\u578B\u7528\u91CF",width:t,gap:x,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(pe,{retain:"list",items:p.models,width:g,height:z,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:v=>[v.displayName,Gn(v.tokens),Gn(v.inTokens),Gn(v.outTokens),M(v.tokens)],searchOf:v=>v.displayName})})})]})}})})})}import{Box as br,Text as sm}from"ink";import{useState as Fh}from"react";import{z as Ev}from"zod";import{z as gt}from"zod";var Av=gt.object({id:gt.number().int(),name:gt.string(),description:gt.string(),multiplier:gt.number()}),Ta=()=>A(gt.array(Av),"/groups"),im=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()}),wa=()=>A(gt.array(im),"/tokens"),$h=e=>A(im.extend({token:gt.string()}),"/tokens",{method:"POST",json:e}),ka=(e,t)=>A(im,`/tokens/${e}`,{method:"PATCH",json:t}),Bh=e=>A(se,`/tokens/${e}`,{method:"DELETE"});import{jsx as lt,jsxs as va}from"react/jsx-runtime";var Uh={model:"",requestId:"",token:"",group:"",status:"",range:"today",since:"",until:""},jh=Ev.iso.date();function Mv(e){let t=Ic();return e.range==="today"?{since:t,until:t}:e.range==="7d"?{since:Wn(t,-6),until:t}:e.range==="30d"?{since:Wn(t,-29),until:t}:e.range==="custom"?{...e.since===""?{}:{since:e.since},...e.until===""?{}:{until:e.until}}:{}}function Hh(e){let t=Mv(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:Nc(t.since).toISOString()},...t.until===void 0?{}:{until:Nc(Wn(t.until,1)).toISOString()}}}var Iv=Pt(tc,Qi,"\u5168\u90E8\u72B6\u6001"),Nv=[{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 Lv({log:e,quotaPerUsd:t,width:n}){let o=n-ge,r=Qi(e.status),i=yt(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\u6CA1\u6709\u8F93\u51FA\u5185\u5BB9\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",`${co(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",kd(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 va(de,{title:e.modelDisplayName,note:K(e.createdAt),width:n,children:[va(sm,{wrap:"truncate",children:[lt(sm,{color:i===void 0?f.mutedForeground:et[i],children:r.label}),lt(sm,{color:f.faintForeground,children:` ${_e([e.stream?"\u6D41\u5F0F":"",e.model])}`})]}),lt(br,{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:Zo(e.quotaCost,t)},{label:"\u603B\u8017\u65F6",value:`${co(e.latencyMs)} s`},{label:"\u6863\u4F4D",value:Dr(e.tierOver)},{label:"\u5206\u7EC4\u500D\u7387",value:`\xD7${e.multiplier}`},{label:"\u53C2\u6570\u500D\u7387",value:`\xD7${Lu(e.paramMultipliers)}`},{label:"\u603B\u500D\u7387",value:`\xD7${Ou(e.multiplier,e.paramMultipliers)}`}]})}),s!==null&<(br,{marginTop:1,children:lt(ye,{tone:"warn",width:o,title:s})}),lt(br,{marginTop:1,children:lt(Ve,{width:o,items:[...a,...c]})})]})}function qh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Fh({name:"list"}),[i,s]=Fh(Uh),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[g,T,x]=await Promise.all([Ta(),wa(),Be(e.ctx.site)]);return{groups:g,tokens:T,site:x}}),m=We([e.revision,JSON.stringify(i)],g=>Ph({page:g,...Hh(i)}),{retain:"page"}),p=Q([e.revision,JSON.stringify(i)],()=>Ah(Hh(i))),d=o.name==="list";G((g,T)=>{d&&(g==="r"?e.reload():g==="f"?(l(),r({name:"filter"})):T.leftArrow?m.go(-1):T.rightArrow&&m.go(1))});let S=()=>{o.name==="list"?e.pop():(l(),r({name:"list"}))},b=JSON.stringify(i)!==JSON.stringify(Uh);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:S,children:lt(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7B5B\u9009\u9009\u9879",width:t,children:({groups:g,tokens:T,site:x})=>{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(T.map(y=>y.name))].map(y=>({value:y,label:y}))],initial:i.token},{kind:"select",name:"group",label:"\u5206\u7EC4",options:[{value:"",label:"\u5168\u90E8\u5206\u7EC4"},...g.map(y=>({value:y.name,label:y.name}))],initial:i.group},{kind:"select",name:"status",label:"\u72B6\u6001",options:Iv,initial:i.status},{kind:"select",name:"range",label:"\u65F6\u95F4\u8303\u56F4",options:Nv,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:S,onSubmit:y=>{let h=y.range??"",R=(y.since??"").trim(),I=(y.until??"").trim();if(h==="custom"&&(R!==""&&!jh.safeParse(R).success||I!==""&&!jh.safeParse(I).success)){c("\u65E5\u671F\u65E0\u6548");return}s({model:y.model??"",requestId:y.requestId??"",token:y.token??"",group:y.group??"",status:y.status??"",range:h,since:R,until:I}),m.reset(),r({name:"list"})}});if(o.name==="detail")return lt(Lv,{log:o.log,quotaPerUsd:x.quotaPerUsd,width:t});let C=Ut(4,t);return va(br,{flexDirection:"column",children:[lt(br,{height:C+1,flexDirection:"column",overflow:"hidden",children:lt(V,{state:p,loading:"\u6B63\u5728\u7EDF\u8BA1\u7B5B\u9009\u7ED3\u679C",width:t,children:y=>lt(it,{width:t,tiles:[{label:"\u6D88\u8017",value:Te(y.quotaCost,x.quotaPerUsd)},{label:"RPM",value:Le(y.rpm)},{label:"TPM",value:Le(y.tpm)},{label:"\u5E76\u53D1",value:Le(y.concurrency)}]})})}),lt(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u4F7F\u7528\u65E5\u5FD7",width:t,children:y=>va(br,{flexDirection:"column",children:[lt(pe,{retain:"list",items:y.items,width:t,height:Math.max(3,n-2-C),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:h=>[K(h.createdAt),h.modelDisplayName,Le(h.promptTokens),Le(h.completionTokens),Zo(h.quotaCost,x.quotaPerUsd),bt(Qi(h.status))],onOpen:h=>r({name:"detail",log:h}),emptyLabel:b?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u8C03\u7528\u8BB0\u5F55",emptyDescription:b?void 0:"\u901A\u8FC7\u4EE4\u724C\u8C03\u7528 API \u540E\uFF0C\u660E\u7EC6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),lt(ze,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})}})})}import{Box as $n,Text as No}from"ink";import{useState as Uv}from"react";import{z as we}from"zod";var Ov=bc.extend({id:we.number().int(),model:we.string(),displayName:we.string(),rules:Au}),Dv=we.object({quotaPerUsd:we.number(),minTopupCny:we.number(),models:we.array(Ov)});function Ca(e){return fn(Dv,`${e}/api/pricing`)}var $v=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 Gh(e){return A($v,`/pricing/${e}`)}var Bv=we.object({data:we.array(we.object({id:we.string()}))});async function Wh(e,t,n){return(await fn(Bv,`${e}/v1/models`,{headers:{authorization:`Bearer ${t}`},...n===void 0?{}:{timeoutMs:n}})).data.map(r=>r.id)}var zh=()=>A($u,"/provider-status");import{Text as Sr}from"ink";import{jsx as Ra,jsxs as Vh}from"react/jsx-runtime";var Fv=` ${ae.bullet} `,Kh=1;function Yh({providers:e}){return Vh(Sr,{wrap:"truncate",children:[Ra(Sr,{color:f.faintForeground,children:"\u5B98\u65B9\u72B6\u6001"}),e.map(t=>{let n=Fu(t);return Vh(Sr,{children:[Ra(Sr,{color:f.faintForeground,children:Fv}),Ra(Sr,{color:f.foreground,children:`${vd(t.provider)} `}),Ra(Sr,{color:et[n.tone],children:n.label})]},t.provider)})]})}import{jsx as Ae,jsxs as bi}from"react/jsx-runtime";var jv=4,Hv=1+Ge,qv=e=>e.requests===0?f.border:e.errors===0?f.success:e.errors/e.requests>=.5?f.danger:f.warning;function Gv({minutes:e,width:t}){let n=e.slice(Math.max(0,e.length-t)),o=[];for(let r of n){let i=qv(r),s=o[o.length-1];s!==void 0&&s.color===i?s.count+=1:o.push({color:i,count:1})}return Ae(No,{wrap:"truncate",children:o.map((r,i)=>Ae(No,{color:r.color,children:ae.barFilled.repeat(r.count)},i))})}function Wv({price:e,width:t,contentRows:n}){let o=O(),r=Q([e.id,o.revision],()=>Gh(e.id)),i=Iu(e,e.rules),s=i.length>1,a=e.rules.filter(Eu),c=t-ge,l=1+i.length,u=1+a.length;return Ae(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?`${co(p.latencyP50Ms)} s`:"\u2014"},{label:"\u9996\u5B57\u8282 P50",value:p.firstByteP50Ms!==null?`${co(p.firstByteP50Ms)} s`:"\u2014"}],S=a.length>0?X+Xe+u:0,b=Hv+Xe+Ut(d.length,c,2)+X+Xe+l+S+X+Xe,g=m.heartbeat.groups.length,T=n-b-jv-X-Xe,x=Math.max(0,Math.floor(T/2));x<g&&(x=Math.max(0,Math.floor((T-1)/2))),x=Math.min(g,x);let C=x>0?X+Xe+x*2+(x<g?1:0):0,y=Math.max(1,n-b-C);return bi($n,{flexDirection:"column",children:[Ae($n,{marginBottom:Ge,children:bi(No,{wrap:"truncate",children:[Ae(No,{bold:!0,color:f.foreground,children:e.displayName}),Ae(No,{color:f.faintForeground,children:` ${e.model}`})]})}),Ae(de,{title:"\u8FD1 24 \u5C0F\u65F6",note:"\u5168\u90E8\u5206\u7EC4\u7684\u7EFC\u5408\u8C03\u7528\u7EDF\u8BA1",width:t,children:Ae(it,{width:c,tiles:d,maxPerRow:2})}),x>0&&Ae($n,{marginTop:1,flexDirection:"column",children:bi(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,x).map(h=>bi($n,{flexDirection:"column",children:[Ae(No,{wrap:"truncate",color:f.foreground,children:h.name}),Ae(Gv,{minutes:h.minutes,width:c})]},h.id)),x<g&&Ae(No,{color:f.faintForeground,children:`\u5176\u4F59 ${g-x} \u4E2A\u5206\u7EC4\u672A\u663E\u793A`})]})}),Ae($n,{marginTop:1,flexDirection:"column",children:Ae(de,{title:"\u6A21\u578B\u4EF7\u683C",note:"\u6BCF\u767E\u4E07 Token \u7684\u7F8E\u5143\u6807\u4EF7",width:t,children:Ae(pe,{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:h=>[h.name,...h.range===null?[]:[h.range],pn(h.price.inputPricePerMillionTokens,"-"),pn(h.price.outputPricePerMillionTokens,"-"),pn(h.price.cachedInputPricePerMillionTokens,"-"),pn(h.price.cacheWritePricePerMillionTokens,"-")]})})}),a.length>0&&Ae($n,{marginTop:1,flexDirection:"column",children:Ae(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:Ae(pe,{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:h=>[h.param,h.value,`\xD7${h.multiplier}`]})})}),Ae($n,{marginTop:1,flexDirection:"column",children:Ae(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?Ae(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"}):Ae(pe,{items:m.groups,width:c,height:y,columns:[{label:"\u5206\u7EC4",shrink:!0},{label:"\u8BF4\u660E",shrink:!0},{label:"\u500D\u7387",align:"right"},{label:"\u5355\u4EF7",align:"right"}],row:h=>[h.name,h.description,`\xD7${h.multiplier}`,`\xA5${(m.cnyPerUsd*h.multiplier).toFixed(2)}`]})})})]})}})}function Jh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Uv({name:"list"}),i=Q([e.revision],async()=>(await Ca(e.ctx.site)).models),s=Q([e.revision],zh);G(c=>{c==="r"&&e.reload()});let a=()=>{o.name==="list"?e.pop():r({name:"list"})};return Ae(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:Ae(V,{state:i,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u5B9A\u4EF7",width:t,children:c=>{if(c.length===0)return Ae(ye,{tone:"info",width:t,title:"\u6682\u65E0\u6A21\u578B"});if(o.name==="detail")return Ae(Wv,{price:o.price,width:t,contentRows:n});let l=s.phase==="ready"?Bu(s.data.providers):[],u=l.length>0?Kh+X:0;return bi($n,{flexDirection:"column",children:[l.length>0&&Ae($n,{marginBottom:X,children:Ae(Yh,{providers:l})}),Ae(pe,{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 Lo,Text as wC}from"ink";import{useState as La}from"react";function am(e,t){if(e===null){let[o]=t;return o===void 0?{status:"none"}:{status:"ok",line:o}}let n=t.find(o=>o.url===e.url);return n===void 0?{status:"stale"}:{status:"ok",line:n}}function Xh(e,t){let n=am(e.line,t.apiLines);if(n.status==="none")throw new F("\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"});if(n.status==="stale")throw new F("\u5DF2\u9009\u7684\u63A5\u5165\u7EBF\u8DEF\u5DF2\u4E0B\u7EBF",{hint:"\u8BF7\u5728\u4EE4\u724C\u7BA1\u7406\u4E2D\u6309 l \u91CD\u65B0\u9009\u62E9\u63A5\u5165\u7EBF\u8DEF"});return n.line}async function Qh(e,t){let n=await Be(e.site);return Wh(Xh(ho(),n).url,t)}async function Zh(e,t,n){let o=await Be(e.site),r=Xh(ho(),o).url;return{input:{siteName:o.siteName,baseUrl:t.relayUrl(r),apiKey:n},at:t.resolveDir()}}async function ey(e,t,n){let{input:o,at:r}=await Zh(e,t,n);t.apply(o,r)}async function ty(e,t,n,o,r){let{input:i,at:s}=await Zh(e,t,n);t.apply({...i,model:o,models:r},s)}import{homedir as cy}from"os";import{join as Pa,resolve as Jv}from"path";import zv from"json5";import{applyEdits as Vv,modify as Kv,parse as Yv}from"jsonc-parser";function ny(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw new F(`${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 oy(e){let t=[],n=Yv(e,t,{allowTrailingComma:!0});return t.length>0?null:n}function ry(e,t){let n=oy(e);if(n!==null)return{root:ny(n,t),jsonc:!0};try{return{root:ny(zv.parse(e),t),jsonc:!1}}catch(o){throw new F(`${t} \u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:o})}}function oo(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=Lt(e);return t===null?null:ry(t,e).root}function Bn(e,t){let n=Si(e),o=n===null?void 0:oo(n,t);return typeof o=="string"?o:null}function _a(e,t){let n=Si(e);return n!==null&&oo(n,t)!==void 0}function Gt(e,t){let n=Lt(e)??"{}",o=n.includes(`\r
|
|
19
19
|
`)?`\r
|
|
20
20
|
`:`
|
|
21
21
|
`,r=ry(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=Vv(n,Kv(n,a,c,{formattingOptions:i}))}catch(a){throw new F(`\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=oy(n);if(s===null)throw new F(`\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(oo(s,a))!==JSON.stringify(c))throw new F(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);vn(e,n.endsWith(o)?n:`${n}${o}`,384)}var iy=["env","ANTHROPIC_BASE_URL"],Xv=["env","ANTHROPIC_AUTH_TOKEN"],sy=["hasCompletedOnboarding"],cm=e=>
|
|
22
|
+
`,o));let i={insertSpaces:!0,tabSize:2,eol:o};try{for(let[a,c]of t)n=Vv(n,Kv(n,a,c,{formattingOptions:i}))}catch(a){throw new F(`\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=oy(n);if(s===null)throw new F(`\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(oo(s,a))!==JSON.stringify(c))throw new F(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);vn(e,n.endsWith(o)?n:`${n}${o}`,384)}var iy=["env","ANTHROPIC_BASE_URL"],Xv=["env","ANTHROPIC_AUTH_TOKEN"],sy=["hasCompletedOnboarding"],cm=e=>Pa(e.dir,"settings.json"),ay=e=>e.custom?Pa(e.dir,".claude.json"):Pa(cy(),".claude.json"),ly={id:"claude-code",label:"Claude Code",requiresModel:!1,resolveDir(){let e=process.env.CLAUDE_CONFIG_DIR;return e?{dir:Jv(e),custom:!0}:{dir:Pa(cy(),".claude"),custom:!1}},relayUrl:e=>e,configPaths:e=>[cm(e),ay(e)],read(e){return{baseUrl:Bn(cm(e),iy),model:null}},apply(e,t){Gt(cm(t),[[iy,e.baseUrl],[Xv,e.apiKey]]);let n=ay(t);_a(n,sy)||Gt(n,[[sy,!0]])}};import{homedir as eC}from"os";import{join as dm,resolve as tC}from"path";import{parse as nC,patch as oC}from"@decimalturn/toml-patch";import{parse as rC}from"smol-toml";import{homedir as Qv}from"os";import{resolve as Zv}from"path";var Tn=e=>e.toLowerCase(),Aa=e=>`${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}_API_KEY`;function Ea(e){let t=e.indexOf("/");return t===-1?null:[e.slice(0,t),e.slice(t+1)]}function xr(e){let t=process.env[e]?.trim();if(!t)return null;let n=t.replace(/^~(?=$|[\\/])/,()=>Qv());return Zv(n)}var iC=["OPENAI_API_KEY"],my="model_provider",lm="model",mm=e=>dm(e.dir,"config.toml"),uy=e=>dm(e.dir,"auth.json");function um(e,t){try{return rC(e,{integersAsBigInt:"asNeeded"})}catch(n){throw new F(`${t} \u4E0D\u662F\u5408\u6CD5 TOML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function sC(e,t){let n=mm(t),o=Lt(n)??"";o!==""&&um(o,n);let r=Tn(e.siteName),i=nC(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[my]=r,i[lm]=e.model;let a=oC(o,i,{inlineTableStart:2}),c=um(a,n);if(c[my]!==r||c[lm]!==e.model||c.model_providers?.[r]?.base_url!==e.baseUrl)throw new F(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${n}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);vn(n,a,384)}var dy={id:"codex",label:"Codex",requiresModel:!0,resolveDir(){let e=process.env.CODEX_HOME;return e?{dir:tC(e),custom:!0}:{dir:dm(eC(),".codex"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[mm(e),uy(e)],read(e){let t=mm(e),n=Lt(t),o=n===null?null:um(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?.[lm])}},apply(e,t){sC(e,t),Gt(uy(t),[[iC,e.apiKey]])}};import{homedir as py}from"os";import{join as xi,resolve as aC}from"path";import{isMap as cC,isScalar as lC,parse as mC,parseDocument as uC}from"yaml";function Ma(e,t,n){let o=Lt(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,vn(e,`${i.join(r)}${r}`,384)}var pm="custom:",fm=e=>Ti(e.dir,"config.yaml"),fy=e=>Ti(e.dir,".env"),Fn=e=>typeof e=="string"?e:null;function gy(e,t){try{return mC(e)}catch(n){throw new F(`${t} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function dC(e,t,n,o){let r=fm(t),i=uC(Lt(r)??"",{compat:"yaml-1.1"});if(i.errors.length>0)throw new F(`${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&&!cC(i.contents))throw new F(`${r} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);let s=`${pm}${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,{}]))}),lC(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 F(`\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=gy(a,r);if(Fn(c?.providers?.[n]?.api)!==e.baseUrl||Fn(c?.model?.provider)!==s||Fn(c?.model?.default)!==e.model)throw new F(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);vn(r,a,384)}var hy={id:"hermes-agent",label:"Hermes Agent",requiresModel:!0,resolveDir(){let e=process.env.HERMES_HOME?.trim();if(e)return{dir:aC(e),custom:!0};if(process.platform==="win32"){let t=process.env.LOCALAPPDATA;return{dir:Ti(t??Ti(py(),"AppData","Local"),"hermes"),custom:!1}}return{dir:Ti(py(),".hermes"),custom:!1}},relayUrl:e=>e,configPaths:e=>[fm(e),fy(e)],read(e){let t=fm(e),n=Lt(t),o=n===null?null:gy(n,t),r=Fn(o?.model?.provider),i=r!==null&&r.startsWith(pm)?r.slice(pm.length):null,s=i===null?void 0:o?.providers?.[i];return{baseUrl:Fn(s?.api)??Fn(s?.url)??Fn(s?.base_url),model:Fn(o?.model?.default)??Fn(o?.model?.model)}},apply(e,t){let n=Tn(e.siteName),o=Ma(n);dC(e,t,n,o),Na(fy(t),o,e.apiKey)}};import{existsSync as pC}from"fs";import{homedir as Sy}from"os";import{join as wr,resolve as xy}from"path";var fC="https://opencode.ai/config.json",Ty="opencode.jsonc",gC=[Ty,"opencode.json","config.json"],yy=["model"],gm=e=>gC.map(t=>wr(e.dir,t)).find(t=>pC(t))??wr(e.dir,Ty),by=()=>{let e=process.env.XDG_DATA_HOME;return wr(e?xy(e):wr(Sy(),".local","share"),"opencode","auth.json")},wy={id:"opencode",label:"OpenCode",requiresModel:!0,resolveDir(){let e=process.env.XDG_CONFIG_HOME;return e?{dir:wr(xy(e),"opencode"),custom:!0}:{dir:wr(Sy(),".config","opencode"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[gm(e),by()],read(e){let t=gm(e),n=Bn(t,yy),o=n===null?null:Ia(n);if(o===null)return{baseUrl:null,model:null};let[r,i]=o;return{baseUrl:Bn(t,["provider",r,"options","baseURL"]),model:i}},apply(e,t){let n=gm(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}]))}],[yy,`${o}/${e.model}`]];Aa(n,["$schema"])||r.unshift([["$schema"],fC]),Gt(n,r),Gt(by(),[[[o],{type:"api",key:e.apiKey}]])}};import{homedir as hC}from"os";import{join as ym}from"path";var ky=["models","providers"],La=["agents","defaults","model"],vy=["agents","defaults","models"],hm=e=>Tr("OPENCLAW_CONFIG_PATH")??ym(e.dir,"openclaw.json"),Cy=e=>ym(e.dir,".env"),Ry=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function yC(e){let t=oo(e,La),n=Ry(t)?t.primary:t;return typeof n=="string"?n:null}var _y={id:"openclaw",label:"OpenClaw",requiresModel:!0,resolveDir(){let e=Tr("OPENCLAW_STATE_DIR");if(e!==null)return{dir:e,custom:!0};let t=Tr("OPENCLAW_HOME");return{dir:ym(t??hC(),".openclaw"),custom:t!==null}},relayUrl:e=>e,configPaths:e=>[hm(e),Cy(e)],read(e){let t=xi(hm(e)),n=t===null?null:yC(t),o=n===null?null:Ia(n);if(t===null||o===null)return{baseUrl:null,model:null};let[r,i]=o,s=oo(t,[...ky,r,"baseUrl"]);return{baseUrl:typeof s=="string"?s:null,model:i}},apply(e,t){let n=hm(t),o=Tn(e.siteName),r=Ma(o),i=xi(n)??{},s=`${o}/${e.model}`,a=[[[...ky,o],{baseUrl:e.baseUrl,apiKey:{source:"env",provider:"default",id:r},api:"anthropic-messages",models:e.models.map(c=>({id:c,name:c}))}],Ry(oo(i,La))?[[...La,"primary"],s]:[La,{primary:s}]];for(let c of e.models){let l=`${o}/${c}`;oo(i,[...vy,l])===void 0&&a.push([[...vy,l],{}])}Gt(n,a),Na(Cy(t),r,e.apiKey)}};import{homedir as bC}from"os";import{join as Sm}from"path";var bm=e=>Sm(e.dir,"models.json"),Oa=e=>Sm(e.dir,"settings.json"),Py={id:"pi-coding-agent",label:"Pi Coding Agent",requiresModel:!0,resolveDir(){let e=Tr("PI_CODING_AGENT_DIR");return e!==null?{dir:e,custom:!0}:{dir:Sm(bC(),".pi","agent"),custom:!1}},relayUrl:e=>e,configPaths:e=>[bm(e),Oa(e)],read(e){let t=Bn(Oa(e),["defaultProvider"]);return{baseUrl:t===null?null:Bn(bm(e),["providers",t,"baseUrl"]),model:Bn(Oa(e),["defaultModel"])}},apply(e,t){let n=Tn(e.siteName);Gt(bm(t),[[["providers",n],{baseUrl:e.baseUrl,api:"anthropic-messages",apiKey:e.apiKey,models:e.models.map(o=>({id:o,name:o}))}]]),Gt(Oa(t),[[["defaultProvider"],n],[["defaultModel"],e.model]])}};var Ay=[ly,dy,_y,hy,wy,Py];var SC=6e3,xC=2,Ey=e=>Jt(`${e.url}/api/site-config`,{timeoutMs:SC});async function TC(e){try{await Ey(e);let t=Number.POSITIVE_INFINITY;for(let n=0;n<xC;n+=1){let o=Date.now();await Ey(e),t=Math.min(t,Date.now()-o)}return{line:e,latencyMs:t}}catch{return{line:e,latencyMs:null}}}async function My(e){let t=[];for(let n of e)t.push(await TC(n));return t}import{jsx as De,jsxs as $a}from"react/jsx-runtime";var kC=10,vC=3,Iy=4,Dy=e=>1+Math.max(1,Math.min(e,Iy))+(e>Iy?1:0);function Ny(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 Ly=e=>e.map(t=>({value:String(t.id),label:`${t.name} \xD7${t.multiplier}`})),Oy=(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 CC({lines:e,measured:t,pick: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(de,{title:"API \u63A5\u5165\u5730\u5740",note:n.status==="ok"?`\u5F53\u524D ${n.line.name}`:n.status==="stale"?"\u5DF2\u9009\u7EBF\u8DEF\u5DF2\u4E0B\u7EBF\uFF0C\u6309 l \u91CD\u65B0\u9009\u62E9":void 0,width:o,children:De(pe,{retain:"lines",items:e,width:o-ge,height:Dy(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.status==="ok"&&n.line.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 $y(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Da({name:"list"}),[i,s]=Da(!1),[a,c]=Da(()=>ho().line),[l,u]=Da(0),{busy:m,error:p,reset:d,fail:S,run:b}=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([va(),ka(),Be(e.ctx.site)]);return{tokens:P,groups:B,site:J}}),T=g.phase==="ready"?g.data.site.apiLines:[],x=Q([l,T.map(P=>P.url).join("|")],()=>My(T)),C=m!==null,y=o.name==="list"&&!C,h=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"&&T.length>0&&s(!0))},y);let R=P=>{ls(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`)},I=(P,B,J)=>{b("\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",()=>$h({name:P,groupId:B,quotaLimit:J}),{onSuccess:oe=>{e.reload(),r({name:"created",token:oe,secret:oe.token})}})},E=P=>{b("\u6B63\u5728\u5220\u9664\u4EE4\u724C",()=>Bh(P.id),{onSuccess:()=>h("\u4EE4\u724C\u5DF2\u5220\u9664")})},z=(P,B)=>{b("\u6B63\u5728\u8BFB\u53D6\u5BA2\u6237\u7AEF\u914D\u7F6E",async()=>Ay.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)=>{b("\u6B63\u5728\u5199\u5165",J,{failToast:!0,onSuccess:()=>{r({name:"list"}),e.toast("ok",_e([`\u5DF2\u5199\u5165 ${P}`,B]))}})},v=(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,()=>ey(e.ctx,oe,P.secret));return}b("\u6B63\u5728\u8BFB\u53D6\u53EF\u8DEF\u7531\u7684\u6A21\u578B",async()=>{let fe=await Qh(e.ctx,P.secret);if(fe.length===0)throw new F("\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})})},k=(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:$a(Lo,{flexDirection:"column",children:[m!==null&&De(Oe,{label:m}),o.name==="created"&&!C&&$a(Lo,{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(Lo,{marginTop:1,children:De(wC,{color:f.accent,children:o.secret})}),De(Lo,{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"}):z(o.token,o.secret)}})})]}),o.name==="apply-pick"&&!C&&De(de,{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=>v(o,P)})}),o.name==="apply-model"&&!C&&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===""){S("\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B");return}M(o.needs.client.label,B,()=>ty(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+Dy(J.apiLines.length),fe=Math.max(vC,n-(o.name==="list"?oe:kC));return $a(Lo,{flexDirection:"column",children:[De(Lo,{flexDirection:"column",marginBottom:X,children:De(pe,{retain:"list",items:P,width:t,height:fe,isActive:y&&!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),Fi($.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(CC,{lines:J.apiLines,measured:x.phase==="ready"?x.data:null,pick:am(a,J.apiLines),width:t,isActive:y&&i,onPick:R}),o.name==="actions"&&!C&&$a(de,{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",Fi(o.token.keyPrefix,o.token.keySuffix)]]}),De(Lo,{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:$=>k($,o.token)})})]}),o.name==="create"&&De(te,{title:"\u521B\u5EFA\u4EE4\u724C",width:t,submitLabel:"\u521B\u5EFA",error:p,busy:C,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:Ly(B),initial:String(B[0]?.id??""),hint:$=>Oy(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===""){S("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}let w=B.find(re=>String(re.id)===$.group);if(w===void 0){S("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}let U=Ny($.limit??"",J.quotaPerUsd);if(U==="invalid"){S("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}I(ne,w.id,U)}}),o.name==="rename"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:C,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===""){S("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}b("\u6B63\u5728\u4FDD\u5B58",()=>Ca(o.token.id,{name:ne}),{onSuccess:()=>h("\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:C,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"select",name:"group",label:"\u5206\u7EC4",options:Ly(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":$=>Oy(B,$)}],onCancel:_,onSubmit:$=>{let ne=B.find(w=>String(w.id)===$.group);if(ne===void 0){S("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}b("\u6B63\u5728\u4FDD\u5B58",()=>Ca(o.token.id,{groupId:ne.id}),{onSuccess:()=>h("\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:C,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=Ny($.limit??"",J.quotaPerUsd);if(ne==="invalid"){S("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}b("\u6B63\u5728\u4FDD\u5B58",()=>Ca(o.token.id,{quotaLimit:ne}),{onSuccess:()=>h("\u5DF2\u4FDD\u5B58")})}}),o.name==="confirm-delete"&&!C&&De(Pe,{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 Uy,Text as _C}from"ink";import{useEffect as PC,useState as qy}from"react";import AC from"string-width";import{z as RC}from"zod";var Ba=()=>A(Cu,"/docs/manifest"),By=e=>A(Ru,`/docs/pages/${e}`),Fy=e=>A(RC.array(_u),Ue("/docs/search",{q:e}));import{jsx as Un,jsxs as Hy}from"react/jsx-runtime";var EC=250,jy="/ ";function MC(e,t){let[n,o]=qy(e);return PC(()=>{let r=setTimeout(()=>o(e),t);return()=>clearTimeout(r)},[e,t]),n}var IC=e=>e.groups.flatMap((t,n)=>[...n===0?[]:[{heading:""}],{heading:t.title},...t.items.map(o=>({value:o,label:o.title}))]);function Gy(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Me("query",()=>""),[i,s]=qy(!1),a=MC(o.trim(),EC),c=a.length>bc,l=Q([e.revision],Ba),u=qt(Q([a,e.revision],()=>a===""||c?Promise.resolve(null):Fy(a))),m=l.phase==="ready",p=o.trim()!=="",d=i||p;G(x=>{if(x==="r"){e.reload();return}m&&x.startsWith("/")&&(s(!0),x.length>1&&r(x.slice(1)))},!i);let S=()=>{if(!d){e.pop();return}s(!1),r("")},b=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=(x,C)=>e.push("doc",{slug:x,anchor:C}),T=Math.max(3,n-(d?1:0));return Un(Y,{hints:b,onEscape:S,children:Un(V,{state:l,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u76EE\u5F55",width:t,children:x=>Hy(Uy,{flexDirection:"column",children:[d&&Hy(Uy,{children:[Un(_C,{color:f.accent,children:jy}),Un(nr,{value:o,onChange:r,onSubmit:()=>s(!1),isActive:i,placeholder:"\u641C\u7D22\u6587\u6863",width:t-AC(jy)})]}),p?c?Un(Ft,{message:`\u5173\u952E\u8BCD\u6700\u591A ${bc} \u4E2A\u5B57\u7B26`,width:t}):Un(V,{state:u,loading:"\u6B63\u5728\u641C\u7D22",width:t,children:C=>C===null?Un(Oe,{label:"\u6B63\u5728\u641C\u7D22"}):Un(pe,{retain:"results",items:C,width:t,height:T,isActive:!i,columns:[{label:"\u6807\u9898"},{label:"\u6458\u8981",shrink:!0}],row:y=>[y.title,y.snippet],onOpen:y=>g(y.slug,y.anchor),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})}):Un(le,{retain:"toc",items:IC(x),width:t,height:T,isActive:!i,onSelect:C=>g(C.slug,null)})]})})})}import{Box as BC,Text as FC}from"ink";import{useMemo as UC,useState as jC}from"react";import{spawn as NC}from"child_process";var LC={darwin:[{command:"pbcopy",args:[]}],win32:[{command:"clip",args:[]}],linux:[{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}]};function OC(e,t){return new Promise((n,o)=>{let r=NC(e.command,e.args,{stdio:["pipe","ignore","ignore"]});r.on("error",i=>{i.code==="ENOENT"?n(!1):o(new F(`\u6267\u884C ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))}),r.on("close",i=>{i===0?n(!0):o(new F(`${e.command} \u9000\u51FA\u7801 ${i??"null"}`))}),r.stdin.on("error",i=>o(new F(`\u5199\u5165 ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))),r.stdin.end(t)})}async function Fa(e){let t=LC[process.platform];if(t===void 0)throw new F(`\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u5199\u5165\u526A\u8D34\u677F\uFF08${process.platform}\uFF09`);for(let n of t)if(await OC(n,e))return;throw new F("\u672A\u627E\u5230\u53EF\u7528\u7684\u526A\u8D34\u677F\u547D\u4EE4")}import{Lexer as DC,walkTokens as $C}from"marked";function Wy(e,t){let n=[],o=[],r=new Set,i="";for(let s of DC.lex(e,{gfm:!0,breaks:!1}))s.type==="heading"&&(i=ll(s.tokens,"docs")),$C([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=ll(a.tokens,"docs"),l=a.href.startsWith("#")?{slug:t,anchor:Sc(a.href.slice(1))}:Bi(a.href);n.push(l===null?{kind:"external",text:c,href:a.href}:{kind:"guide",text:c,...l})});return{links:n,codes:o}}var zy=e=>Kn(e).split(`
|
|
26
|
-
`).map(t=>t.trim()).filter(t=>t!=="").join(" ");import{jsx as Oo,jsxs as WC}from"react/jsx-runtime";var HC=1,qC=16;function Vy({params:e}){let{depth:t}=O();return Oo(GC,{params:e},t)}function GC({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=jC("body"),s=qt(Q([e.slug,t.revision],async()=>{let[b,g]=await Promise.all([By(e.slug),Ba()]),T=new Map(g.groups.flatMap(x=>x.items.map(C=>[C.slug,C.title])));return{page:b,titles:T,outline:Wy(b.markdown,e.slug)}})),a=s.phase==="ready"?s.data:null,c=a===null?null:a.page.markdown,l=UC(()=>c===null?[]:hn(c,n,"docs"),[c,n]);G(b=>{if(r!=="body")return;if(b==="r"){t.reload();return}if(a===null)return;let{outline:g}=a;b==="l"&&g.links.length>0?i("links"):b==="c"&&g.codes.length>0&&i("codes")});let u=()=>{r==="body"?t.pop():i("body")},m=b=>{i("body"),Fa(b).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:b}=a;return["\u2191\u2193 \u6EDA\u52A8",...b.links.length>0?["l \u94FE\u63A5"]:[],...b.codes.length>0?["c \u590D\u5236\u4EE3\u7801"]:[],"r \u5237\u65B0"]},d=a===null?"\u6587\u6863\u8BE6\u60C5":a.page.title;return Oo(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:Oo(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863",width:n,children:({titles:b,outline:g})=>{if(r==="links")return Oo(pe,{retain:"links",items:g.links,width:n,height:o,columns:[{label:"\u94FE\u63A5",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u76EE\u6807",shrink:!0}],row:x=>x.kind==="guide"?[x.text,"\u7AD9\u5185\u6587\u6863",b.get(x.slug)??""]:[x.text,"\u5916\u90E8\u94FE\u63A5",x.href],onOpen:x=>x.kind==="guide"?t.push("doc",{slug:x.slug,anchor:x.anchor}):m(x.href)});if(r==="codes")return Oo(pe,{retain:"codes",items:g.codes,width:n,height:o,columns:[{label:"\u4EE3\u7801",shrink:!0},{label:"\u8BED\u8A00"},{label:"\u7AE0\u8282",cap:qC}],row:x=>[zy(x.text),x.lang,x.section],onOpen:x=>m(x.text)});let T=e.anchor===null?-1:l.findIndex(x=>x.anchor===e.anchor);return WC(BC,{flexDirection:"column",children:[Oo(pt,{retain:"body",lines:l,height:Math.max(1,o-HC),start:Math.max(0,T)}),Oo(FC,{wrap:"truncate",color:f.faintForeground,children:`\u7F51\u9875\u7248 ${t.ctx.site}/docs/${e.slug}`})]})}})})}import{Box as xm}from"ink";import{jsx as un,jsxs as zC}from"react/jsx-runtime";var Ky=[["\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"]],Yy=[["\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 Xy({width:e,height:t}){let n=e-ge,o=[["\u7248\u672C",`${zt} v${Vt}`],["\u672C\u5730\u5B58\u50A8",Cn()]],r=[Ky,Yy,Jy,o],s=(a=>r.reduce((c,l)=>c+Bt+a+Js(l.length,n),X*(r.length-1)))(Ge)<=t?Ge:0;return zC(ep,{height:t,children:[un(de,{title:"\u901A\u7528",width:e,gap:s,children:un(Ve,{items:Ky,width:n})}),un(xm,{marginTop:X,flexDirection:"column",children:un(de,{title:"\u9F20\u6807",width:e,gap:s,children:un(Ve,{items:Yy,width:n})})}),un(xm,{marginTop:X,flexDirection:"column",children:un(de,{title:"\u6587\u672C\u8F93\u5165",width:e,gap:s,children:un(Ve,{items:Jy,width:n})})}),un(xm,{marginTop:X,flexDirection:"column",children:un(de,{title:"\u5173\u4E8E",width:e,gap:s,children:un(Ve,{items:o,width:n})})})]})}import{jsx as Tm}from"react/jsx-runtime";function Qy(){let e=O(),{width:t}=j(),n=Z();return gn(e.pop),Tm(To,{header:Tm(Os,{trail:["CodeFlow","\u952E\u4F4D\u5E2E\u52A9"],width:t,onBack:e.pop,isActive:!0}),hints:["Esc \u8FD4\u56DE"],children:Tm(Xy,{width:t,height:n})})}import{Box as Zy,Text as VC}from"ink";import{jsx as wi,jsxs as KC}from"react/jsx-runtime";var eb=[{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 tb(){let e=O(),{width:t}=j(),n=ri(0),o=X+1+X+eb.length,r=Is(t)&&n-Ms>=o;return KC(To,{header:r?wi(Ns,{width:t}):null,hints:["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","? \u5E2E\u52A9","q \u9000\u51FA"],children:[wi(Zy,{marginTop:1,children:wi(VC,{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"})}),wi(Zy,{marginTop:1,children:wi(le,{items:eb,width:t,retain:"menu",onSelect:i=>e.push(i)})})]})}import{Box as wm,Text as km}from"ink";import{useState as YC}from"react";import{jsx as nn,jsxs as vm}from"react/jsx-runtime";function nb(){let e=O(),t=Ds(),{width:n}=j(),o=Z(),{busy:r,run:i}=ue(),[s,a]=YC({name:"list"}),c=We([e.revision],m=>Wp({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",()=>Vp(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",()=>Kp(),{failToast:!0,onSuccess:()=>{e.reload(),e.toast("ok","\u5DF2\u5168\u90E8\u6807\u4E3A\u5DF2\u8BFB")}}))}),s.name==="detail"){let m=jc(s.message),p=hd[m.target.kind],d=At([{text:st(m.body),color:f.foreground}],n),S=Math.max(3,o-4);return vm(Y,{hints:[...d.length>S?["\u2191\u2193 \u6EDA\u52A8"]:[],`Enter ${p}`,"Esc \u8FD4\u56DE"],onEscape:()=>a({name:"list"}),children:[vm(km,{wrap:"truncate",children:[nn(km,{bold:!0,color:f.foreground,children:st(m.title)}),nn(km,{color:f.faintForeground,children:` ${K(s.message.createdAt)}`})]}),nn(wm,{marginTop:1,children:nn(pt,{lines:d,height:Math.min(d.length,S)})}),nn(wm,{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=>vm(wm,{flexDirection:"column",children:[nn(pe,{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=jc(p),S=st(d.title);return[p.read?S:{text:S,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(ze,{page:c.page,pages:c.pages,total:c.total,width:n})]})})})}import{Box as Ua,Text as Do}from"ink";import{useState as rb}from"react";import{z as xt}from"zod";var JC=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:Vm,rewardQuota:xt.number(),rewardQuotaReversed:xt.number(),inviterUsername:xt.string(),inviteeUsername:xt.string(),createdAt:xt.string()}))}),ob=()=>A(JC,"/invite");import{jsx as _t,jsxs as ja}from"react/jsx-runtime";var XC=Pt(nc,es,"\u5168\u90E8\u7C7B\u578B"),ib=3;function QC(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 sb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=rb("main"),[i,s]=rb(""),a=Q([e.revision],async()=>{let[l,u]=await Promise.all([ob(),Be(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 _t(Y,{hints:o==="main"?["\u2191\u2193 \u6EDA\u52A8","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:_t(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u9080\u8BF7\u4FE1\u606F",width:t,children:({invite:l,site:u})=>{if(o==="filter")return _t(te,{title:"\u7B5B\u9009\u5956\u52B1\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:XC,initial:i}],onCancel:c,onSubmit:T=>{s(T.type??""),r("main")}});let m=t-ge,p=QC(l.rewards),d=i===""?l.items:l.items.filter(T=>T.rewardType===i),S=T=>Ut(2,t)+X+Bt+T+2+X+Bt+T+p.length+X+Bt+T,b=n-S(Ge)>=ib?Ge:0,g=Math.max(ib,n-S(b));return ja(Ua,{flexDirection:"column",children:[_t(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)}]}),_t(Ua,{marginTop:1,flexDirection:"column",children:ja(de,{title:"\u6211\u7684\u9080\u8BF7",width:t,gap:b,children:[ja(Do,{wrap:"truncate",children:[_t(Do,{color:f.mutedForeground,children:"\u6211\u7684\u9080\u8BF7\u7801 "}),_t(Do,{color:f.accent,children:l.inviteCode})]}),ja(Do,{wrap:"truncate",children:[_t(Do,{color:f.mutedForeground,children:"\u9080\u8BF7\u94FE\u63A5 "}),_t(Do,{color:f.accent,children:`${e.ctx.site}/register?invite=${l.inviteCode}`})]})]})}),_t(Ua,{marginTop:1,flexDirection:"column",children:_t(de,{title:"\u5956\u52B1\u89C4\u5219",width:t,gap:b,children:p.map((T,x)=>_t(Do,{wrap:"truncate",color:f.mutedForeground,children:T},x))})}),_t(Ua,{marginTop:1,flexDirection:"column",children:_t(de,{title:"\u9080\u8BF7\u5956\u52B1\u8BB0\u5F55",note:i===""?void 0:es(i),width:t,gap:b,children:_t(pe,{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:T=>{let x=T.rewardQuota-T.rewardQuotaReversed,C=T.rewardQuotaReversed>0?`\u9000\u6B3E\u51B2\u51CF -${Te(T.rewardQuotaReversed,u.quotaPerUsd)}`:"";return[K(T.createdAt),T.rewardType==="first_invitee"?T.inviterUsername:T.inviteeUsername,es(T.rewardType),_e([Te(x,u.quotaPerUsd),C])]},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{Box as Sb}from"ink";import{useState as xb}from"react";import{z as Ie}from"zod";var ZC=12e4,eR=Ie.object({id:Ie.number().int(),orderNo:Ie.string(),amountCny:Ie.number().int()}),ab=()=>A(Ie.array(eR),"/invoices/eligible-orders"),cb=Ie.object({id:Ie.number().int(),type:ec,title:Ie.string(),taxId:Ie.string().nullable(),invoiceNo:Ie.string().nullable(),remark:Ie.string().nullable(),amountCny:Ie.number().int(),status:qm,rejectReason:Ie.string().nullable(),rejectedAt:Ie.string().nullable(),issuedAt:Ie.string().nullable(),createdAt:Ie.string()}),tR=cb.extend({hasFile:Ie.boolean(),orders:Ie.array(Ie.object({orderNo:Ie.string(),amountCny:Ie.number().int()}))}),lb=()=>A(Ie.array(cb),"/invoices"),mb=e=>A(tR,`/invoices/${e}`),ub=e=>A(se,"/invoices",{method:"POST",json:e}),db=e=>cs(`/invoices/${e}/file`,{timeoutMs:ZC}),nR=Ie.object({id:Ie.number().int(),type:ec,title:Ie.string(),taxId:Ie.string().nullable()}),Ha=()=>A(Ie.array(nR),"/invoices/profiles"),pb=e=>A(se,"/invoices/profiles",{method:"POST",json:e}),fb=(e,t)=>A(se,`/invoices/profiles/${e}`,{method:"PATCH",json:t}),gb=e=>A(se,`/invoices/profiles/${e}`,{method:"DELETE"});import{Box as oR,Text as $o,useInput as rR}from"ink";import{useEffect as iR,useState as sR}from"react";import{jsx as ki,jsxs as Cm}from"react/jsx-runtime";var aR="[x]",cR="[ ]",hb=4,qa=2,yb=2;function bb({items:e,columns:t,row:n,selected:o,onToggle:r,onToggleAll:i,onSubmit:s,width:a,height:c,emptyLabel:l}){let[u,m]=sR(0),p=Math.max(1,c-1),d=e.length>p?Math.max(1,p-1):p;iR(()=>{m(y=>Math.min(y,Math.max(0,e.length-1)))},[e.length]);let S=dl(u,d),b=y=>{e.length!==0&&m(h=>(h+y+e.length)%e.length)};rR((y,h)=>{if(h.upArrow){b(-1);return}if(h.downArrow){b(1);return}if(h.return){s();return}y===" "&&e.length>0&&r(u)}),G(y=>{if(y==="k"){b(-1);return}if(y==="j"){b(1);return}y==="a"&&i()});let g=y=>{let h=S+y-1;return h>=0&&h<e.length?h:null},T=rt({onWheel:b,onClick:({row:y})=>{let h=g(y);h!==null&&(m(h),r(h))},onHover:({row:y})=>{let h=g(y);h!==null&&m(h)}}),x=Cl(t,e.map(y=>n(y)),a-qa-hb),C=e.slice(S,S+d);return Cm(oR,{ref:T,flexDirection:"column",children:[Cm($o,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(qa+hb),t.map((y,h)=>y.align==="right"?Yn(y.label,x[h]??0):Je(y.label,x[h]??0)).join(" ".repeat(yb))]}),e.length===0?ki($o,{color:f.faintForeground,children:`${" ".repeat(qa)}${l}`}):C.map((y,h)=>{let R=S+h,I=R===u,E=o.has(R),z=I?f.accent:f.foreground,M=n(y);return Cm($o,{wrap:"truncate",children:[ki($o,{color:f.accent,children:I?`${ae.cursor} `:" "}),ki($o,{color:E?f.accent:z,bold:I,children:`${E?aR:cR} `}),t.map((v,k)=>{let _=v.align==="right"?Yn(M[k]??"",x[k]??0):Je(M[k]??"",x[k]??0);return ki($o,{color:z,bold:I,children:k>0?`${" ".repeat(yb)}${_}`:_},v.label)})]},R)}),(S>0||S+d<e.length)&&ki($o,{color:f.faintForeground,children:`${" ".repeat(qa)}${S+1}-${Math.min(S+d,e.length)} / ${e.length}`})]})}import{jsx as wn,jsxs as lR}from"react/jsx-runtime";function Tb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=xb({name:"pick"}),[i,s]=xb(new Set),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[S,b]=await Promise.all([ab(),Ha()]);return{orders:S,profiles:b}});G(S=>{o.name==="pick"&&S==="r"&&e.reload()});let p=()=>{o.name==="pick"?e.pop():o.name==="preset"?r({name:"pick"}):o.name==="remark"?r({name:"preset"}):(l(),r({name:"remark",profile:o.profile,remark:o.remark}))},d=(S,b,g)=>{let T=S.filter(x=>i.has(x.id)).map(x=>x.id);u("\u6B63\u5728\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7",()=>ub({orderIds:T,type:b.type,title:b.title,taxId:b.taxId,remark:g===""?null:g}),{onSuccess:()=>{e.toast("ok","\u5DF2\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7"),e.pop()}})};return wn(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:wn(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u53EF\u5F00\u7968\u8BA2\u5355",width:t,children:({orders:S,profiles:b})=>{if(o.name==="pick")return S.length===0?wn(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"}):wn(bb,{items:S,width:t,height:n,columns:[{label:"\u8BA2\u5355\u53F7",shrink:!0},{label:"\u91D1\u989D",align:"right"}],row:y=>[y.orderNo,Ce(y.amountCny)],selected:new Set(S.flatMap((y,h)=>i.has(y.id)?[h]:[])),onToggle:y=>{let h=S[y]?.id;h!==void 0&&s(R=>{let I=new Set(R);return I.has(h)?I.delete(h):I.add(h),I})},onToggleAll:()=>s(y=>S.every(h=>y.has(h.id))?new Set:new Set(S.map(h=>h.id))),onSubmit:()=>{if(!S.some(y=>i.has(y.id))){e.toast("warn","\u8BF7\u5148\u52FE\u9009\u8981\u5F00\u7968\u7684\u8BA2\u5355");return}if(b.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 y=[{heading:"\u5E38\u7528\u4FE1\u606F"},...b.map(h=>({value:h,label:`${fo(h.type)} \xB7 ${h.title}`,hint:h.taxId??void 0}))];return wn(le,{items:y,width:t,height:n,onSelect:h=>r({name:"remark",profile:h,remark:""})})}if(o.name==="remark")return wn(te,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u5907\u6CE8",width:t,submitLabel:"\u4E0B\u4E00\u6B65",fields:[{kind:"textarea",name:"remark",label:"\u5907\u6CE8",rows:2,maxLength:200,initial:o.remark,placeholder:"\u5C55\u793A\u5728\u53D1\u7968\u7968\u9762\u5907\u6CE8\u680F\u7684\u5185\u5BB9",optional:!0}],onCancel:p,onSubmit:y=>r({name:"confirm",profile:o.profile,remark:(y.remark??"").trim()})});let{profile:g,remark:T}=o,x=S.filter(y=>i.has(y.id)),C=x.reduce((y,h)=>y+h.amountCny,0);return lR(Sb,{flexDirection:"column",children:[wn(de,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u786E\u8BA4\u4FE1\u606F",note:`\u5DF2\u9009 ${x.length} \u7B14 \xB7 \u5408\u8BA1 ${Ce(C)}`,width:t,children:wn(ql,{width:t-ge,items:[["\u53D1\u7968\u7C7B\u578B",po(g.type)],["\u62AC\u5934\u7C7B\u578B",Ed(g.taxId)],["\u62AC\u5934",g.title],...g.taxId===null?[]:[["\u7A0E\u53F7",g.taxId]],...T===""?[]:[["\u5907\u6CE8",T]]]})}),wn(Sb,{marginTop:1,children:wn(Pe,{width:t,title:Md,confirmLabel:"\u786E\u8BA4\u63D0\u4EA4",busy:a,error:c,onConfirm:()=>d(S,g,T),onCancel:p})})]})}})})}import{Box as Rm}from"ink";import{useState as mR}from"react";function wb(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 kb=e=>[{kind:"select",name:"type",label:"\u7C7B\u578B",options:[{value:"general",label:po("general")},{value:"special",label:po("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",hint:t=>t.type!=="special"?"\u5355\u4F4D\u62AC\u5934\u9700\u586B\u5199\uFF0C\u7559\u7A7A\u5C06\u6309\u4E2A\u4EBA\u5F00\u5177":void 0,optional:t=>t.type!=="special"}];import{jsx as jn,jsxs as vb}from"react/jsx-runtime";var uR=8,dR=3;function Cb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=mR({name:"list"}),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.revision],Ha),m=i!==null,p=o.name==="list"&&!m;G(S=>{S==="r"?e.reload():S==="n"&&r({name:"create"})},p);let d=()=>{o.name==="list"?e.pop():(a(),r({name:"list"}))};return jn(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:jn(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u5E38\u7528\u5F00\u7968\u4FE1\u606F",width:t,children:S=>{let b=o.name==="list"?n:Math.max(dR,n-uR);return vb(Rm,{flexDirection:"column",children:[jn(Rm,{marginBottom:o.name==="list"?0:1,children:jn(pe,{retain:"list",items:S,width:t,height:b,isActive:p,columns:[{label:"\u7C7B\u578B"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7A0E\u53F7"}],row:g=>[fo(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&&vb(de,{title:o.profile.title,width:t,children:[jn(Ve,{width:t-ge,items:[["\u7C7B\u578B",po(o.profile.type)],["\u7A0E\u53F7",o.profile.taxId??"\u2014"]]}),jn(Rm,{marginTop:1,children:jn(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")&&jn(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:kb(o.name==="edit"?o.profile:null),onCancel:d,onSubmit:g=>{let T=wb(g,c);if(T===null)return;let x=o.name==="edit"?()=>fb(o.profile.id,T):()=>pb(T);l("\u6B63\u5728\u4FDD\u5B58",x,{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u4FDD\u5B58")}})}}),o.name==="confirm-delete"&&jn(Pe,{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",()=>gb(o.profile.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:d})]})}})})}import{Box as vi,Text as kr}from"ink";import{useState as _m}from"react";import{jsx as nt,jsxs as Rb}from"react/jsx-runtime";var pR=Pt(Za,Qi,"\u5168\u90E8\u72B6\u6001");function fR({id:e,width:t}){let n=O(),o=Q([e,n.revision],()=>mb(e)),r=t-ge,[i,s]=_m(null),[a,c]=_m(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(pr,{title:"\u4FDD\u5B58\u53D1\u7968\u6587\u4EF6",width:t,download:async()=>({fileName:`invoice-${a}.pdf`,bytes:await db(u.id)}),onCancel:()=>c(null),onSaved:S=>{c(null),s(S),n.toast("ok","\u53D1\u7968\u5DF2\u4FDD\u5B58")}});let m=Qi(u.status),p=yt(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 Rb(de,{title:u.title,note:K(u.createdAt),width:t,children:[Rb(kr,{wrap:"truncate",children:[nt(kr,{color:f.mutedForeground,children:fo(u.type)}),nt(kr,{color:p===void 0?f.mutedForeground:et[p],children:` ${m.label}`})]}),nt(vi,{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(vi,{marginTop:1,children:nt(Ve,{width:r,items:d})}),nt(vi,{marginTop:1,flexDirection:"column",children:u.orders.map(S=>nt(kr,{wrap:"truncate",color:f.faintForeground,children:_e([S.orderNo,Ce(S.amountCny)])},S.orderNo))}),u.hasFile&&i===null&&nt(vi,{marginTop:1,children:nt(kr,{wrap:"truncate",color:f.faintForeground,children:"\u6309 d \u4E0B\u8F7D\u53D1\u7968\u6587\u4EF6"})}),i!==null&&nt(vi,{marginTop:1,children:nt(kr,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${i}`})})]})}})}function _b(){let e=O(),{width:t}=j(),n=Z(),[o,r]=_m({name:"list"}),[i,s]=Me("status",()=>""),a=Q([e.revision],lb);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:pR,initial:i}],onCancel:c,onSubmit:m=>{s(m.status??""),r({name:"list"})}});if(o.name==="detail")return nt(fR,{id:o.id,width:t});let u=i===""?l:l.filter(m=>m.status===i);return nt(pe,{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,fo(m.type),Ce(m.amountCny),bt(Qi(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 gR}from"ink";import{useState as Pb}from"react";import{jsx as vr,jsxs as yR}from"react/jsx-runtime";var hR=Pt(tc,Wc,"\u5168\u90E8\u7C7B\u578B");function Ab(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Pb("list"),[i,s]=Pb(""),a=Q([e.revision],()=>Be(e.ctx.site)),c=We([e.revision,i],m=>Eh({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 vr(Y,{hints:l?["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:u,children:vr(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:m=>o==="filter"?vr(te,{title:"\u7B5B\u9009\u6D41\u6C34",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:hR,initial:i}],onCancel:u,onSubmit:p=>{s(p.type??""),c.reset(),r("list")}}):vr(V,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6D41\u6C34",width:t,children:p=>yR(gR,{flexDirection:"column",children:[vr(pe,{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 S=Zo(d.amount,m.quotaPerUsd);return[K(d.createdAt),Wc(d.type),{text:d.amount>=0?`+${S}`:S,tone:d.amount>=0?"success":"danger"},Te(d.balanceAfter,m.quotaPerUsd),_e([Td(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}),vr(ze,{page:c.page,pages:c.pages,total:c.total,width:t})]})})})})}import{Box as Ob}from"ink";import{useState as SR}from"react";import{z as bR}from"zod";var Ci={recharge:"/recharge",subscription:"/subscriptions"};async function Ga(e,t){let n=`${Ci[e]}/orders/${t}`;return e==="recharge"?{kind:e,...await A(Nr,n)}:{kind:e,...await A(Lr,n)}}async function Eb(e,t){let n=`${Ci[e]}/orders/${t}/pay`;if(e==="recharge"){let{order:i,qrCode:s}=await A(Di,n,{method:"POST"});return{order:{kind:e,...i},qrCode:s}}let{order:o,qrCode:r}=await A(Or,n,{method:"POST"});return{order:{kind:e,...o},qrCode:r}}var Mb=(e,t)=>A(bR.array(hu),`${Ci[e]}/orders/${t}/refunds`),Ib=(e,t,n)=>A(se,`${Ci[e]}/orders/${t}/refund-request`,{method:"POST",json:{reason:n}}),Nb=(e,t)=>A(se,`${Ci[e]}/orders/${t}/refund-request/cancel`,{method:"POST"});import{Box as Wa,Text as kn}from"ink";import{jsx as on,jsxs as Ri}from"react/jsx-runtime";function Lb({order:e,refunds:t,quotaPerUsd:n,width:o}){let r=o-ge,i=zn(e.status),s=yt(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)]),Ri(de,{title:e.kind==="recharge"?"\u5145\u503C":e.planName,note:e.orderNo,width:o,children:[Ri(kn,{wrap:"truncate",children:[on(kn,{color:s===void 0?f.mutedForeground:et[s],children:i.label}),e.kind==="subscription"&&on(kn,{color:f.faintForeground,children:` ${e.renewal?"\u7EED\u8D39":"\u65B0\u8D2D"}`})]}),on(Wa,{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(Wa,{marginTop:1,children:on(Ve,{width:r,items:a})}),t!==null&&Ri(Wa,{marginTop:1,flexDirection:"column",children:[on(kn,{color:f.mutedForeground,children:"\u9000\u6B3E\u8BB0\u5F55"}),t.length===0?on(kn,{color:f.faintForeground,children:"\u6682\u65E0\u9000\u6B3E\u8BB0\u5F55"}):t.map(c=>{let l=wd(c.status),u=yt(l);return Ri(Wa,{flexDirection:"column",children:[Ri(kn,{wrap:"truncate",children:[on(kn,{color:f.foreground,children:Ce(c.amountCny)}),on(kn,{color:u===void 0?f.mutedForeground:et[u],children:` ${l.label}`}),on(kn,{color:f.faintForeground,children:` ${K(c.createdAt)}`})]}),(c.reason!==null||c.rejectReason!==null||c.refundTradeNo!==null)&&on(kn,{wrap:"truncate",color:f.faintForeground,children:` ${_e([c.reason??"",c.rejectReason===null?"":`\u9A73\u56DE\uFF1A${c.rejectReason}`,c.refundTradeNo??""])}`})]},c.id)})]})]})}import{jsx as Bo,jsxs as TR}from"react/jsx-runtime";var xR=new Set(["pending","expired","failed"]);function za(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:yt(t)}}function Cr(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 Db({params:e}){let t=O(),{width:n}=j(),[o,r]=SR("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[b,g]=await Promise.all([Ga(e.kind,e.orderNo),Be(t.ctx.site)]),T=xR.has(b.status)?null:await Mb(e.kind,e.orderNo);return{order:b,refunds:T,site:g}});G(b=>{o==="main"&&i===null&&b==="r"&&t.reload()});let m=()=>{o==="main"?t.pop():(a(),r("main"))},p=b=>{l("\u6B63\u5728\u62C9\u8D77\u652F\u4ED8",()=>Eb(e.kind,e.orderNo),{failToast:!0,onSuccess:({order:g,qrCode:T})=>{t.push("pay",Cr(g,T,b.quotaPerUsd))}})},d=b=>{l("\u6B63\u5728\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7",()=>Ib(e.kind,e.orderNo,b),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7")}})},S=()=>{l("\u6B63\u5728\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",()=>Nb(e.kind,e.orderNo),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u64A4\u9500\u9000\u6B3E\u7533\u8BF7")}})};return Bo(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:Bo(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u5355",width:n,children:({order:b,refunds:g,site:T})=>{if(o==="refund")return Bo(te,{title:`\u7533\u8BF7\u9000\u6B3E \u2014 ${b.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:[...Jc[e.kind].map(C=>({value:C,label:C})),{value:"other",label:"\u5176\u4ED6"}],initial:Jc[e.kind][0],hint:Ad[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:C=>{let y=C.reason??"",h=y==="other"?(C.custom??"").trim():y;if(h===""){c("\u8BF7\u586B\u5199\u5177\u4F53\u8BF4\u660E");return}d(h)}});if(o==="confirm-cancel")return Bo(Pe,{width:n,title:"\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",detail:`\u786E\u8BA4\u64A4\u9500\u8BA2\u5355 ${b.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\uFF1F${b.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:S,onCancel:m});let x=[];return b.status==="pending"&&x.push({value:"pay",label:"\u7EE7\u7EED\u652F\u4ED8",hint:"\u91CD\u65B0\u62C9\u8D77\u652F\u4ED8\u5B9D\u4E8C\u7EF4\u7801"}),b.status==="refund_requested"&&x.push({value:"cancel-refund",label:"\u64A4\u9500\u7533\u8BF7",hint:"\u9000\u6B3E\u5C1A\u672A\u5BA1\u6838\uFF0C\u53EF\u64A4\u56DE"}),yu(b)&&x.push({value:"refund",label:"\u7533\u8BF7\u9000\u6B3E",labelTone:"danger"}),TR(Ob,{flexDirection:"column",children:[Bo(Lb,{order:b,refunds:g,quotaPerUsd:T.quotaPerUsd,width:n}),x.length>0&&i===null&&Bo(Ob,{marginTop:1,children:Bo(le,{width:n,items:x,retain:"menu",onSelect:C=>{a(),C==="pay"?p(T):r(C==="refund"?"refund":"confirm-cancel")}})})]})}})})}import{useRef as kR,useState as Hb}from"react";import{Box as $b,Text as Fo}from"ink";import{Fragment as wR,jsx as Wt,jsxs as Bb}from"react/jsx-runtime";var Fb={columns:20,rows:2};function Ub(e,t,n){return zs(e,t,Fb,n)}function jb({phase:e,qrCode:t,amountCny:n,summary:o,paidNote:r,expiredNote:i,pollError:s,width:a,layout:c}){let l=s===null?Wt(Oe,{label:"\u7B49\u5F85\u652F\u4ED8\u5230\u8D26\u2026"}):Wt(Fo,{wrap:"truncate",color:et.warning,children:`\u67E5\u8BE2\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1A${s}`});if(e==="paid")return Wt(ye,{tone:"ok",width:a,title:"\u652F\u4ED8\u6210\u529F\uFF01",detail:r});if(e==="expired")return Wt(ye,{tone:"warn",width:a,title:"\u8BA2\u5355\u5DF2\u8D85\u65F6",detail:i});if(!c.fits)return Bb($b,{flexDirection:"column",children:[Wt(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`}),Wt(Fo,{color:f.accent,children:t}),Wt($b,{marginTop:1,children:Wt(Fo,{bold:!0,color:f.foreground,children:Ce(n)})}),l]});let u=c.asideRows-Fb.rows,m=u>=1,p=u>=2,d=u>=2+o.length;return Wt(Vs,{value:t,aside:Bb(wR,{children:[p&&Wt(Fo,{bold:!0,color:f.foreground,children:"\u626B\u7801\u652F\u4ED8"}),Wt(Fo,{bold:!0,color:f.foreground,children:Ce(n)}),m&&Wt(Fo,{color:f.mutedForeground,children:"\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u4E00\u626B\u5B8C\u6210\u652F\u4ED8"}),d&&o.map((S,b)=>Wt(Fo,{wrap:"truncate",color:f.mutedForeground,children:S},b)),l]})})}import{jsx as qb}from"react/jsx-runtime";var vR=5,CR=2e3;function Gb({params:e}){let t=O(),{width:n,columns:o,rows:r}=j(),i=ri(0),[s,a]=Hb("waiting"),[c,l]=Hb(null),u=kR(0);aa(CR,async()=>{let d;try{d=await Ga(e.kind,e.orderNo)}catch(S){l(Se(S));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>=vR&&a("expired");return}u.current=0},s==="waiting"),G(d=>{d!=="c"||s!=="waiting"||Fa(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=Ub(e.qrCode,{width:n,rows:i},{columns:o-n,rows:r-i}),p=s==="waiting"&&m.fits;return qb(Y,{trail:["\u626B\u7801\u652F\u4ED8"],bleed:p,hints:s==="waiting"?["c \u590D\u5236\u94FE\u63A5"]:[],children:qb(jb,{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 _R}from"react";import{z as Hn}from"zod";var RR=Hn.object({id:Hn.number().int(),name:Hn.string(),originalCny:Hn.number().int(),discountPercent:Hn.number().int(),payCny:Hn.number().int(),quota:Hn.number()}),Wb=()=>A(Hn.array(RR),"/recharge-packages"),zb=e=>A(Di,"/recharge/orders",{method:"POST",json:e}),Vb=()=>A(Hn.array(Nr),"/recharge/orders");import{jsx as Rr}from"react/jsx-runtime";var PR=Pt(Ar,zn,"\u5168\u90E8\u72B6\u6001");function AR(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 Kb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=_R({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[b,g,T]=await Promise.all([Wb(),_a(e.ctx.site),Vb()]);return{packages:b,pricing:g,orders:T}});G(b=>{o.name==="menu"&&(b==="r"?e.reload():b==="f"&&r({name:"filter"}))});let d=()=>{o.name==="menu"?e.pop():(l(),r({name:"menu"}))},S=(b,g)=>{m("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>zb(b),{onSuccess:({order:T,qrCode:x})=>{r({name:"menu"}),e.push("pay",Cr({kind:"recharge",...T},x,g))}})};return Rr(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:Rr(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u5145\u503C\u5957\u9910",width:t,children:({packages:b,pricing:g,orders:T})=>{if(o.name==="confirm")return Rr(Pe,{width:t,title:`\u786E\u8BA4\u5145\u503C ${Ce(o.pkg.payCny)}\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>S({packageId:o.pkg.id},g.quotaPerUsd),onCancel:d});if(o.name==="custom")return Rr(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:y=>{let h=Number((y.yuan??"").trim()),R=Fc(h);if(!Number.isFinite(h)||R<Fc(g.minTopupCny)||R>lc){u(`\u8BF7\u8F93\u5165 ${g.minTopupCny} \u5230 ${pd(lc)} \u5143\u4E4B\u95F4\u7684\u91D1\u989D`);return}S({amountCny:R},g.quotaPerUsd)}});if(o.name==="filter")return Rr(te,{title:"\u7B5B\u9009\u5145\u503C\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:PR,initial:i}],onCancel:d,onSubmit:y=>{s(y.status??""),r({name:"menu"})}});let x=i===""?T:T.filter(y=>y.status===i),C=[{heading:"\u5145\u503C\u5957\u9910"},...b.map(y=>({value:{kind:"pkg",pkg:y},label:y.name,hint:AR(y,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"},...x.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}]:x.map(y=>({value:{kind:"order",orderNo:y.orderNo},label:Ce(y.amountCny),...za(y),hint:`${K(y.createdAt)} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(y.quota,g.quotaPerUsd)}`}))];return Rr(le,{items:C,width:t,height:n,retain:"menu",onSelect:y=>{l(),y.kind==="custom"?r({name:"custom"}):y.kind==="order"?e.push("order",{kind:"recharge",orderNo:y.orderNo}):y.kind==="pkg"&&r({name:"confirm",pkg:y.pkg})}})}})})}import{Box as qn,Text as _i}from"ink";import{useState as NR}from"react";import LR from"string-width";import{z as xe}from"zod";var ER=xe.object({windowId:xe.number().int(),durationMinutes:xe.number().int(),quota:xe.number(),used:xe.number(),resetAt:xe.string()}),Yb=xe.object({name:xe.string(),multiplier:xe.number()}),MR=xe.object({billingPreference:Xa,subscriptions:xe.array(xe.object({id:xe.number().int(),planName:xe.string(),groups:xe.array(Yb),startsAt:xe.string(),expiresAt:xe.string(),revokedAt:xe.string().nullable(),renewable:xe.boolean(),windows:xe.array(ER)}))}),Jb=()=>A(MR,"/subscriptions"),IR=xe.object({id:xe.number().int(),name:xe.string(),description:xe.string().nullable(),priceCny:xe.number().int(),durationDays:xe.number().int(),enabled:xe.boolean(),groups:xe.array(Yb),windows:xe.array(xe.object({durationMinutes:xe.number().int(),quota:xe.number()}))}),Xb=()=>A(xe.array(IR),"/subscription-plans"),Qb=e=>A(Or,"/subscriptions/orders",{method:"POST",json:e}),Zb=e=>A(Or,`/subscriptions/${e}/renew`,{method:"POST"}),eS=()=>A(xe.array(Lr),"/subscriptions/orders"),tS=e=>A(xe.object({billingPreference:Xa}),"/subscriptions/preference",{method:"PUT",json:e});import{jsx as je,jsxs as Uo}from"react/jsx-runtime";var OR=Pt(Ar,zn,"\u5168\u90E8\u72B6\u6001");function DR(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 $R=3;function BR({win:e,quotaPerUsd:t,width:n}){let o=Kc(e),r=_d(e.durationMinutes),i=`\u5DF2\u7528 ${o}% ${ae.bullet} ${Te(e.used,t)} / ${Te(e.quota,t)}`;return Uo(qn,{flexDirection:"column",children:[Uo(_i,{wrap:"truncate",children:[je(_i,{color:f.foreground,children:r}),je(_i,{color:o>=100?f.danger:f.mutedForeground,children:Yn(i,Math.max(0,n-LR(r)))})]}),je(kg,{used:e.used,total:e.quota,width:n}),je(_i,{wrap:"truncate",color:f.faintForeground,children:`\u5C06\u4E8E ${K(e.resetAt)} \u91CD\u7F6E`})]})}function FR(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(Kc))}% \xB7 ${t}`}function UR(e){let t=e.windows.length*4;return X+Xe+2+t+(e.renewable?X+1:0)}function jR(e){let t=e.description!==null&&e.description!==""?1+Ge:0,n=Math.ceil((1+e.windows.length)/2);return X+Xe+t+n+X+1}function nS(){let e=O(),{width:t}=j(),n=Z(),[o,r]=NR({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,T,x,C]=await Promise.all([Jb(),Xb(),eS(),Be(e.ctx.site)]);return{mine:g,plans:T,orders:x,site:C}});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",()=>tS({billingPreference:g}),{onSuccess:()=>{r({name:"menu"}),e.reload(),e.toast("ok","\u504F\u597D\u5DF2\u4FDD\u5B58")}})},S=(g,T)=>{u("\u6B63\u5728\u521B\u5EFA\u7EED\u8D39\u8BA2\u5355",()=>Zb(g.id),{onSuccess:({order:x,qrCode:C})=>{r({name:"menu"}),e.push("pay",Cr({kind:"subscription",...x},C,T.quotaPerUsd))}})},b=(g,T)=>{u("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Qb({planId:g.id}),{onSuccess:({order:x,qrCode:C})=>{r({name:"menu"}),e.push("pay",Cr({kind:"subscription",...x},C,T.quotaPerUsd))}})};return je(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:je(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u9605",width:t,children:({mine:g,plans:T,orders:x,site:C})=>{if(o.name==="preference")return je(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:xd,initial:g.billingPreference,hint:Gc}],onCancel:p,onSubmit:k=>{d(k.billingPreference??g.billingPreference)}});if(o.name==="filter")return je(te,{title:"\u7B5B\u9009\u8BA2\u9605\u8BA2\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:OR,initial:i}],onCancel:p,onSubmit:k=>{s(k.status??""),r({name:"menu"})}});let y=DR(o,g.subscriptions,T);if(y.kind==="missing-sub")return je(ye,{tone:"warn",width:t,title:"\u8BA2\u9605\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",detail:"\u6309 Esc \u8FD4\u56DE"});if(y.kind==="missing-plan")return je(ye,{tone:"warn",width:t,title:"\u5957\u9910\u4E0D\u5B58\u5728\u6216\u5DF2\u4E0B\u67B6",detail:"\u6309 Esc \u8FD4\u56DE"});if(y.kind==="sub"&&y.confirm)return je(Pe,{width:t,title:`\u786E\u8BA4\u7EED\u8D39\u300C${y.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:()=>S(y.sub,C),onCancel:p});if(y.kind==="plan"&&y.confirm)return je(Pe,{width:t,title:`\u786E\u8BA4\u8BA2\u9605\u300C${y.plan.name}\u300D\uFF08${Ce(y.plan.priceCny)} / ${y.plan.durationDays} \u5929\uFF09\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b(y.plan,C),onCancel:p});let h=y.kind==="plan"?y.plan.description:"",R=i===""?x:x.filter(k=>k.status===i),I=[{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(k=>{let _=Yc(k);return{value:{kind:"sub",id:k.id},label:k.planName,badge:_.label,badgeTone:yt(_),hint:FR(k)}}),{heading:""},{value:{kind:"preference"},label:"\u6263\u8D39\u65B9\u5F0F",badge:qc(g.billingPreference),badgeTone:"accent",hint:Gc(g.billingPreference)},{heading:""},{heading:"\u53EF\u9009\u5957\u9910"},...T.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}]:T.map(k=>({value:{kind:"plan",id:k.id},label:k.name,...k.enabled?{}:{badge:"\u5DF2\u505C\u552E",badgeTone:"warning"},hint:`${Ce(k.priceCny)} / ${k.durationDays} \u5929 \xB7 ${k.groups.map(rs).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(k=>({value:{kind:"order",orderNo:k.orderNo},label:`${k.planName}${k.renewal?"\uFF08\u7EED\u8D39\uFF09":""}`,...za(k),hint:`${K(k.createdAt)} \xB7 ${Ce(k.amountCny)}`}))],E=y.kind==="sub"?UR(y.sub):y.kind==="plan"?jR(y.plan):0,z=E===0?n:n-E>=$R?n-E:0,M=t-ge,v=o.name==="menu"&&a===null;return Uo(qn,{flexDirection:"column",children:[z>0&&je(le,{items:I,width:t,height:z,isActive:v,retain:"menu",onSelect:k=>{l(),k.kind==="preference"?r({name:"preference"}):k.kind==="order"?e.push("order",{kind:"subscription",orderNo:k.orderNo}):k.kind==="sub"?r({name:"sub",id:k.id}):k.kind==="plan"&&r({name:"plan",id:k.id})}}),y.kind==="sub"&&Uo(qn,{marginTop:z>0?X:0,flexDirection:"column",children:[Uo(de,{title:y.sub.planName,note:y.sub.revokedAt!==null?`${K(y.sub.revokedAt)} \u4F5C\u5E9F`:`${K(y.sub.expiresAt)} \u5230\u671F`,width:t,children:[je(Ve,{width:M,items:[["\u72B6\u6001",Yc(y.sub).label],["\u8986\u76D6\u5206\u7EC4",y.sub.groups.map(rs).join("\u3001")],["\u751F\u6548\u65F6\u95F4",K(y.sub.startsAt)]]}),je(qn,{marginTop:1,flexDirection:"column",children:y.sub.windows.map((k,_)=>je(qn,{marginTop:_===0?0:1,flexDirection:"column",children:je(BR,{win:k,quotaPerUsd:C.quotaPerUsd,width:M})},k.windowId))})]}),y.sub.renewable&&a===null&&je(qn,{marginTop:X,children:je(le,{width:t,items:[{value:"renew",label:"\u7EED\u8D39"}],onSelect:()=>r({name:"confirm-renew",id:y.sub.id})})})]}),y.kind==="plan"&&Uo(qn,{marginTop:z>0?X:0,flexDirection:"column",children:[Uo(de,{title:y.plan.name,note:`${Ce(y.plan.priceCny)} / ${y.plan.durationDays} \u5929`,width:t,children:[h!==""&&je(_i,{wrap:"truncate",color:f.mutedForeground,children:h}),je(qn,{marginTop:h===""?0:Ge,children:je(Ve,{width:M,items:[["\u8986\u76D6\u5206\u7EC4",y.plan.groups.map(rs).join("\u3001")],...Pd(y.plan,C.quotaPerUsd).map((k,_)=>[_===0?"\u7528\u91CF\u7A97\u53E3":"",k])]})})]}),a===null&&je(qn,{marginTop:X,children:je(le,{width:t,items:[{value:"subscribe",label:y.plan.enabled?"\u8BA2\u9605":"\u5DF2\u505C\u552E",disabled:!y.plan.enabled}],onSelect:()=>r({name:"confirm-buy",id:y.plan.id})})})]})]})}})})}import{jsx as be}from"react/jsx-runtime";var oS={home:{render:()=>be(tb,{})},help:{render:()=>be(Qy,{})},login:{render:()=>be(Xg,{})},register:{render:()=>be(Qg,{})},forgot:{render:()=>be(Vg,{})},agreement:{render:e=>be(jg,{params:e})},tokens:{render:()=>be($y,{})},logs:{render:()=>be(qh,{})},usage:{render:()=>be(Dh,{})},ledger:{render:()=>be(Ab,{})},subscription:{render:()=>be(nS,{})},models:{render:()=>be(Jh,{})},docs:{render:()=>be(Gy,{})},doc:{render:e=>be(Vy,{params:e})},recharge:{render:()=>be(Kb,{})},order:{render:e=>be(Db,{params:e})},pay:{render:e=>be(Gb,{params:e})},invoices:{render:()=>be(_b,{})},"invoice-apply":{render:()=>be(Tb,{})},"invoice-profiles":{render:()=>be(Cb,{})},invite:{render:()=>be(sb,{})},tickets:{render:()=>be(Ug,{})},ticket:{render:e=>be(Fg,{params:e})},community:{render:()=>be(hh,{})},post:{render:e=>be(Ch,{params:e})},floor:{render:e=>be(lh,{params:e})},compose:{render:e=>be(nh,{params:e})},"post-edit":{render:e=>be(oh,{params:e})},homepage:{render:e=>be(dh,{params:e})},inbox:{render:()=>be(nb,{})},announcements:{render:()=>be(sf,{})},"announce-gate":{render:e=>be(nf,{params:e}),lockNav:!0},profile:{render:()=>be(Ag,{})},"my-posts":{render:e=>be(Sh,{params:e})},"my-comments":{render:e=>be(xh,{params:e})},bookmarks:{render:()=>be(Th,{})},drafts:{render:()=>be(wh,{})}};function rS(e){return oS[e].lockNav===!0}function iS(e){let t=oS[e.id].render;return t(e.params)}import{jsx as ro,jsxs as e_}from"react/jsx-runtime";function zR(){let e=O(),{rows:t}=j(),n=hs(),o=rS(e.current.id)||n,r=e.depth===1&&Ss(e.current.id)&&wt().session===null;return Pm(()=>{r&&e.home()}),GR((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())}),ro(HR,{flexDirection:"column",height:Math.max(1,t),paddingX:1,paddingTop:1,overflow:"hidden",children:iS(e.current)})}function VR(){let e=O(),t=Q([e.revision],async()=>{if(e.gate.announcementsChecked||wt().session===null)return null;let n;try{n=await Xd()}catch{return null}return e.gate.announcementsChecked=!0,n});return Pm(()=>{t.phase!=="ready"||t.data===null||e.gate.announcementsShown||(e.gate.announcementsShown=!0,e.push("announce-gate",{item:t.data}))}),null}function KR(){let e=O(),t=WR(!1);return Pm(()=>{t.current||(t.current=!0,Yd().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${Se(n)}`)))}),null}function YR({ctx:e,mouse:t}){return ro(fp,{subscribe:t.subscribe,children:ro(rp,{children:ro(Sp,{ctx:e,children:e_(Qp,{children:[ro(KR,{}),ro(VR,{}),ro(zR,{})]})})})})}var JR="\x1B[2J\x1B[3J\x1B[H",XR="\x1B[H\x1B[J",QR="\x1B[3J";function ZR(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(XR).split(QR).join("");return t.write(s,...i)}}})}async function sS(e){let t=dp(process.stdin,process.stdout);try{await qR(ro(YR,{ctx:e,mouse:t}),{exitOnCtrlC:!0,alternateScreen:!0,stdin:t.stdin,stdout:ZR(process.stdout)}).waitUntilExit()}finally{t.dispose()}}var r_=`${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,vn(e,`${i.join(r)}${r}`,384)}var pm="custom:",fm=e=>xi(e.dir,"config.yaml"),fy=e=>xi(e.dir,".env"),Fn=e=>typeof e=="string"?e:null;function gy(e,t){try{return mC(e)}catch(n){throw new F(`${t} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function dC(e,t,n,o){let r=fm(t),i=uC(Lt(r)??"",{compat:"yaml-1.1"});if(i.errors.length>0)throw new F(`${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&&!cC(i.contents))throw new F(`${r} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);let s=`${pm}${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,{}]))}),lC(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 F(`\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=gy(a,r);if(Fn(c?.providers?.[n]?.api)!==e.baseUrl||Fn(c?.model?.provider)!==s||Fn(c?.model?.default)!==e.model)throw new F(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);vn(r,a,384)}var hy={id:"hermes-agent",label:"Hermes Agent",requiresModel:!0,resolveDir(){let e=process.env.HERMES_HOME?.trim();if(e)return{dir:aC(e),custom:!0};if(process.platform==="win32"){let t=process.env.LOCALAPPDATA;return{dir:xi(t??xi(py(),"AppData","Local"),"hermes"),custom:!1}}return{dir:xi(py(),".hermes"),custom:!1}},relayUrl:e=>e,configPaths:e=>[fm(e),fy(e)],read(e){let t=fm(e),n=Lt(t),o=n===null?null:gy(n,t),r=Fn(o?.model?.provider),i=r!==null&&r.startsWith(pm)?r.slice(pm.length):null,s=i===null?void 0:o?.providers?.[i];return{baseUrl:Fn(s?.api)??Fn(s?.url)??Fn(s?.base_url),model:Fn(o?.model?.default)??Fn(o?.model?.model)}},apply(e,t){let n=Tn(e.siteName),o=Aa(n);dC(e,t,n,o),Ma(fy(t),o,e.apiKey)}};import{existsSync as pC}from"fs";import{homedir as Sy}from"os";import{join as Tr,resolve as xy}from"path";var fC="https://opencode.ai/config.json",Ty="opencode.jsonc",gC=[Ty,"opencode.json","config.json"],yy=["model"],gm=e=>gC.map(t=>Tr(e.dir,t)).find(t=>pC(t))??Tr(e.dir,Ty),by=()=>{let e=process.env.XDG_DATA_HOME;return Tr(e?xy(e):Tr(Sy(),".local","share"),"opencode","auth.json")},wy={id:"opencode",label:"OpenCode",requiresModel:!0,resolveDir(){let e=process.env.XDG_CONFIG_HOME;return e?{dir:Tr(xy(e),"opencode"),custom:!0}:{dir:Tr(Sy(),".config","opencode"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[gm(e),by()],read(e){let t=gm(e),n=Bn(t,yy),o=n===null?null:Ea(n);if(o===null)return{baseUrl:null,model:null};let[r,i]=o;return{baseUrl:Bn(t,["provider",r,"options","baseURL"]),model:i}},apply(e,t){let n=gm(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}]))}],[yy,`${o}/${e.model}`]];_a(n,["$schema"])||r.unshift([["$schema"],fC]),Gt(n,r),Gt(by(),[[[o],{type:"api",key:e.apiKey}]])}};import{homedir as hC}from"os";import{join as ym}from"path";var ky=["models","providers"],Ia=["agents","defaults","model"],vy=["agents","defaults","models"],hm=e=>xr("OPENCLAW_CONFIG_PATH")??ym(e.dir,"openclaw.json"),Cy=e=>ym(e.dir,".env"),Ry=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function yC(e){let t=oo(e,Ia),n=Ry(t)?t.primary:t;return typeof n=="string"?n:null}var _y={id:"openclaw",label:"OpenClaw",requiresModel:!0,resolveDir(){let e=xr("OPENCLAW_STATE_DIR");if(e!==null)return{dir:e,custom:!0};let t=xr("OPENCLAW_HOME");return{dir:ym(t??hC(),".openclaw"),custom:t!==null}},relayUrl:e=>e,configPaths:e=>[hm(e),Cy(e)],read(e){let t=Si(hm(e)),n=t===null?null:yC(t),o=n===null?null:Ea(n);if(t===null||o===null)return{baseUrl:null,model:null};let[r,i]=o,s=oo(t,[...ky,r,"baseUrl"]);return{baseUrl:typeof s=="string"?s:null,model:i}},apply(e,t){let n=hm(t),o=Tn(e.siteName),r=Aa(o),i=Si(n)??{},s=`${o}/${e.model}`,a=[[[...ky,o],{baseUrl:e.baseUrl,apiKey:{source:"env",provider:"default",id:r},api:"anthropic-messages",models:e.models.map(c=>({id:c,name:c}))}],Ry(oo(i,Ia))?[[...Ia,"primary"],s]:[Ia,{primary:s}]];for(let c of e.models){let l=`${o}/${c}`;oo(i,[...vy,l])===void 0&&a.push([[...vy,l],{}])}Gt(n,a),Ma(Cy(t),r,e.apiKey)}};import{homedir as bC}from"os";import{join as Sm}from"path";var bm=e=>Sm(e.dir,"models.json"),Na=e=>Sm(e.dir,"settings.json"),Py={id:"pi-coding-agent",label:"Pi Coding Agent",requiresModel:!0,resolveDir(){let e=xr("PI_CODING_AGENT_DIR");return e!==null?{dir:e,custom:!0}:{dir:Sm(bC(),".pi","agent"),custom:!1}},relayUrl:e=>e,configPaths:e=>[bm(e),Na(e)],read(e){let t=Bn(Na(e),["defaultProvider"]);return{baseUrl:t===null?null:Bn(bm(e),["providers",t,"baseUrl"]),model:Bn(Na(e),["defaultModel"])}},apply(e,t){let n=Tn(e.siteName);Gt(bm(t),[[["providers",n],{baseUrl:e.baseUrl,api:"anthropic-messages",apiKey:e.apiKey,models:e.models.map(o=>({id:o,name:o}))}]]),Gt(Na(t),[[["defaultProvider"],n],[["defaultModel"],e.model]])}};var Ay=[ly,dy,_y,hy,wy,Py];var SC=6e3,xC=2,Ey=e=>Jt(`${e.url}/api/site-config`,{timeoutMs:SC});async function TC(e){try{await Ey(e);let t=Number.POSITIVE_INFINITY;for(let n=0;n<xC;n+=1){let o=Date.now();await Ey(e),t=Math.min(t,Date.now()-o)}return{line:e,latencyMs:t}}catch{return{line:e,latencyMs:null}}}async function My(e){let t=[];for(let n of e)t.push(await TC(n));return t}import{jsx as De,jsxs as Oa}from"react/jsx-runtime";var kC=10,vC=3,Iy=4,Dy=e=>1+Math.max(1,Math.min(e,Iy))+(e>Iy?1:0);function Ny(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 Ly=e=>e.map(t=>({value:String(t.id),label:`${t.name} \xD7${t.multiplier}`})),Oy=(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 CC({lines:e,measured:t,pick: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(de,{title:"API \u63A5\u5165\u5730\u5740",note:n.status==="ok"?`\u5F53\u524D ${n.line.name}`:n.status==="stale"?"\u5DF2\u9009\u7EBF\u8DEF\u5DF2\u4E0B\u7EBF\uFF0C\u6309 l \u91CD\u65B0\u9009\u62E9":void 0,width:o,children:De(pe,{retain:"lines",items:e,width:o-ge,height:Dy(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.status==="ok"&&n.line.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 $y(){let e=O(),{width:t}=j(),n=Z(),[o,r]=La({name:"list"}),[i,s]=La(!1),[a,c]=La(()=>ho().line),[l,u]=La(0),{busy:m,error:p,reset:d,fail:S,run:b}=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([wa(),Ta(),Be(e.ctx.site)]);return{tokens:P,groups:B,site:J}}),T=g.phase==="ready"?g.data.site.apiLines:[],x=Q([l,T.map(P=>P.url).join("|")],()=>My(T)),C=m!==null,y=o.name==="list"&&!C,h=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"&&T.length>0&&s(!0))},y);let R=P=>{cs(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`)},I=(P,B,J)=>{b("\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",()=>$h({name:P,groupId:B,quotaLimit:J}),{onSuccess:oe=>{e.reload(),r({name:"created",token:oe,secret:oe.token})}})},E=P=>{b("\u6B63\u5728\u5220\u9664\u4EE4\u724C",()=>Bh(P.id),{onSuccess:()=>h("\u4EE4\u724C\u5DF2\u5220\u9664")})},z=(P,B)=>{b("\u6B63\u5728\u8BFB\u53D6\u5BA2\u6237\u7AEF\u914D\u7F6E",async()=>Ay.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)=>{b("\u6B63\u5728\u5199\u5165",J,{failToast:!0,onSuccess:()=>{r({name:"list"}),e.toast("ok",_e([`\u5DF2\u5199\u5165 ${P}`,B]))}})},v=(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,()=>ey(e.ctx,oe,P.secret));return}b("\u6B63\u5728\u8BFB\u53D6\u53EF\u8DEF\u7531\u7684\u6A21\u578B",async()=>{let fe=await Qh(e.ctx,P.secret);if(fe.length===0)throw new F("\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})})},k=(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:Oa(Lo,{flexDirection:"column",children:[m!==null&&De(Oe,{label:m}),o.name==="created"&&!C&&Oa(Lo,{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(Lo,{marginTop:1,children:De(wC,{color:f.accent,children:o.secret})}),De(Lo,{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"}):z(o.token,o.secret)}})})]}),o.name==="apply-pick"&&!C&&De(de,{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=>v(o,P)})}),o.name==="apply-model"&&!C&&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===""){S("\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B");return}M(o.needs.client.label,B,()=>ty(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+Dy(J.apiLines.length),fe=Math.max(vC,n-(o.name==="list"?oe:kC));return Oa(Lo,{flexDirection:"column",children:[De(Lo,{flexDirection:"column",marginBottom:X,children:De(pe,{retain:"list",items:P,width:t,height:fe,isActive:y&&!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),Bi($.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(CC,{lines:J.apiLines,measured:x.phase==="ready"?x.data:null,pick:am(a,J.apiLines),width:t,isActive:y&&i,onPick:R}),o.name==="actions"&&!C&&Oa(de,{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",Bi(o.token.keyPrefix,o.token.keySuffix)]]}),De(Lo,{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:$=>k($,o.token)})})]}),o.name==="create"&&De(te,{title:"\u521B\u5EFA\u4EE4\u724C",width:t,submitLabel:"\u521B\u5EFA",error:p,busy:C,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:Ly(B),initial:String(B[0]?.id??""),hint:$=>Oy(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===""){S("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}let w=B.find(re=>String(re.id)===$.group);if(w===void 0){S("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}let U=Ny($.limit??"",J.quotaPerUsd);if(U==="invalid"){S("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}I(ne,w.id,U)}}),o.name==="rename"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:C,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===""){S("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}b("\u6B63\u5728\u4FDD\u5B58",()=>ka(o.token.id,{name:ne}),{onSuccess:()=>h("\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:C,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"select",name:"group",label:"\u5206\u7EC4",options:Ly(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":$=>Oy(B,$)}],onCancel:_,onSubmit:$=>{let ne=B.find(w=>String(w.id)===$.group);if(ne===void 0){S("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}b("\u6B63\u5728\u4FDD\u5B58",()=>ka(o.token.id,{groupId:ne.id}),{onSuccess:()=>h("\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:C,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=Ny($.limit??"",J.quotaPerUsd);if(ne==="invalid"){S("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}b("\u6B63\u5728\u4FDD\u5B58",()=>ka(o.token.id,{quotaLimit:ne}),{onSuccess:()=>h("\u5DF2\u4FDD\u5B58")})}}),o.name==="confirm-delete"&&!C&&De(Pe,{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 Uy,Text as _C}from"ink";import{useEffect as PC,useState as qy}from"react";import AC from"string-width";import{z as RC}from"zod";var Da=()=>A(Cu,"/docs/manifest"),By=e=>A(Ru,`/docs/pages/${e}`),Fy=e=>A(RC.array(_u),Ue("/docs/search",{q:e}));import{jsx as Un,jsxs as Hy}from"react/jsx-runtime";var EC=250,jy="/ ";function MC(e,t){let[n,o]=qy(e);return PC(()=>{let r=setTimeout(()=>o(e),t);return()=>clearTimeout(r)},[e,t]),n}var IC=e=>e.groups.flatMap((t,n)=>[...n===0?[]:[{heading:""}],{heading:t.title},...t.items.map(o=>({value:o,label:o.title}))]);function Gy(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Me("query",()=>""),[i,s]=qy(!1),a=MC(o.trim(),EC),c=a.length>hc,l=Q([e.revision],Da),u=qt(Q([a,e.revision],()=>a===""||c?Promise.resolve(null):Fy(a))),m=l.phase==="ready",p=o.trim()!=="",d=i||p;G(x=>{if(x==="r"){e.reload();return}m&&x.startsWith("/")&&(s(!0),x.length>1&&r(x.slice(1)))},!i);let S=()=>{if(!d){e.pop();return}s(!1),r("")},b=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=(x,C)=>e.push("doc",{slug:x,anchor:C}),T=Math.max(3,n-(d?1:0));return Un(Y,{hints:b,onEscape:S,children:Un(V,{state:l,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u76EE\u5F55",width:t,children:x=>Hy(Uy,{flexDirection:"column",children:[d&&Hy(Uy,{children:[Un(_C,{color:f.accent,children:jy}),Un(nr,{value:o,onChange:r,onSubmit:()=>s(!1),isActive:i,placeholder:"\u641C\u7D22\u6587\u6863",width:t-AC(jy)})]}),p?c?Un(Ft,{message:`\u5173\u952E\u8BCD\u6700\u591A ${hc} \u4E2A\u5B57\u7B26`,width:t}):Un(V,{state:u,loading:"\u6B63\u5728\u641C\u7D22",width:t,children:C=>C===null?Un(Oe,{label:"\u6B63\u5728\u641C\u7D22"}):Un(pe,{retain:"results",items:C,width:t,height:T,isActive:!i,columns:[{label:"\u6807\u9898"},{label:"\u6458\u8981",shrink:!0}],row:y=>[y.title,y.snippet],onOpen:y=>g(y.slug,y.anchor),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})}):Un(le,{retain:"toc",items:IC(x),width:t,height:T,isActive:!i,onSelect:C=>g(C.slug,null)})]})})})}import{Box as BC,Text as FC}from"ink";import{useMemo as UC,useState as jC}from"react";import{spawn as NC}from"child_process";var LC={darwin:[{command:"pbcopy",args:[]}],win32:[{command:"clip",args:[]}],linux:[{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}]};function OC(e,t){return new Promise((n,o)=>{let r=NC(e.command,e.args,{stdio:["pipe","ignore","ignore"]});r.on("error",i=>{i.code==="ENOENT"?n(!1):o(new F(`\u6267\u884C ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))}),r.on("close",i=>{i===0?n(!0):o(new F(`${e.command} \u9000\u51FA\u7801 ${i??"null"}`))}),r.stdin.on("error",i=>o(new F(`\u5199\u5165 ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))),r.stdin.end(t)})}async function $a(e){let t=LC[process.platform];if(t===void 0)throw new F(`\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u5199\u5165\u526A\u8D34\u677F\uFF08${process.platform}\uFF09`);for(let n of t)if(await OC(n,e))return;throw new F("\u672A\u627E\u5230\u53EF\u7528\u7684\u526A\u8D34\u677F\u547D\u4EE4")}import{Lexer as DC,walkTokens as $C}from"marked";function Wy(e,t){let n=[],o=[],r=new Set,i="";for(let s of DC.lex(e,{gfm:!0,breaks:!1}))s.type==="heading"&&(i=al(s.tokens,"docs")),$C([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=al(a.tokens,"docs"),l=a.href.startsWith("#")?{slug:t,anchor:yc(a.href.slice(1))}:$i(a.href);n.push(l===null?{kind:"external",text:c,href:a.href}:{kind:"guide",text:c,...l})});return{links:n,codes:o}}var zy=e=>Kn(e).split(`
|
|
26
|
+
`).map(t=>t.trim()).filter(t=>t!=="").join(" ");import{jsx as Oo,jsxs as WC}from"react/jsx-runtime";var HC=1,qC=16;function Vy({params:e}){let{depth:t}=O();return Oo(GC,{params:e},t)}function GC({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=jC("body"),s=qt(Q([e.slug,t.revision],async()=>{let[b,g]=await Promise.all([By(e.slug),Da()]),T=new Map(g.groups.flatMap(x=>x.items.map(C=>[C.slug,C.title])));return{page:b,titles:T,outline:Wy(b.markdown,e.slug)}})),a=s.phase==="ready"?s.data:null,c=a===null?null:a.page.markdown,l=UC(()=>c===null?[]:hn(c,n,"docs"),[c,n]);G(b=>{if(r!=="body")return;if(b==="r"){t.reload();return}if(a===null)return;let{outline:g}=a;b==="l"&&g.links.length>0?i("links"):b==="c"&&g.codes.length>0&&i("codes")});let u=()=>{r==="body"?t.pop():i("body")},m=b=>{i("body"),$a(b).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:b}=a;return["\u2191\u2193 \u6EDA\u52A8",...b.links.length>0?["l \u94FE\u63A5"]:[],...b.codes.length>0?["c \u590D\u5236\u4EE3\u7801"]:[],"r \u5237\u65B0"]},d=a===null?"\u6587\u6863\u8BE6\u60C5":a.page.title;return Oo(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:Oo(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863",width:n,children:({titles:b,outline:g})=>{if(r==="links")return Oo(pe,{retain:"links",items:g.links,width:n,height:o,columns:[{label:"\u94FE\u63A5",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u76EE\u6807",shrink:!0}],row:x=>x.kind==="guide"?[x.text,"\u7AD9\u5185\u6587\u6863",b.get(x.slug)??""]:[x.text,"\u5916\u90E8\u94FE\u63A5",x.href],onOpen:x=>x.kind==="guide"?t.push("doc",{slug:x.slug,anchor:x.anchor}):m(x.href)});if(r==="codes")return Oo(pe,{retain:"codes",items:g.codes,width:n,height:o,columns:[{label:"\u4EE3\u7801",shrink:!0},{label:"\u8BED\u8A00"},{label:"\u7AE0\u8282",cap:qC}],row:x=>[zy(x.text),x.lang,x.section],onOpen:x=>m(x.text)});let T=e.anchor===null?-1:l.findIndex(x=>x.anchor===e.anchor);return WC(BC,{flexDirection:"column",children:[Oo(pt,{retain:"body",lines:l,height:Math.max(1,o-HC),start:Math.max(0,T)}),Oo(FC,{wrap:"truncate",color:f.faintForeground,children:`\u7F51\u9875\u7248 ${t.ctx.site}/docs/${e.slug}`})]})}})})}import{Box as xm}from"ink";import{jsx as un,jsxs as zC}from"react/jsx-runtime";var Ky=[["\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"]],Yy=[["\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 Xy({width:e,height:t}){let n=e-ge,o=[["\u7248\u672C",`${zt} v${Vt}`],["\u672C\u5730\u5B58\u50A8",Cn()]],r=[Ky,Yy,Jy,o],s=(a=>r.reduce((c,l)=>c+Bt+a+Ys(l.length,n),X*(r.length-1)))(Ge)<=t?Ge:0;return zC(ep,{height:t,children:[un(de,{title:"\u901A\u7528",width:e,gap:s,children:un(Ve,{items:Ky,width:n})}),un(xm,{marginTop:X,flexDirection:"column",children:un(de,{title:"\u9F20\u6807",width:e,gap:s,children:un(Ve,{items:Yy,width:n})})}),un(xm,{marginTop:X,flexDirection:"column",children:un(de,{title:"\u6587\u672C\u8F93\u5165",width:e,gap:s,children:un(Ve,{items:Jy,width:n})})}),un(xm,{marginTop:X,flexDirection:"column",children:un(de,{title:"\u5173\u4E8E",width:e,gap:s,children:un(Ve,{items:o,width:n})})})]})}import{jsx as Tm}from"react/jsx-runtime";function Qy(){let e=O(),{width:t}=j(),n=Z();return gn(e.pop),Tm(To,{header:Tm(Ls,{trail:["CodeFlow","\u952E\u4F4D\u5E2E\u52A9"],width:t,onBack:e.pop,isActive:!0}),hints:["Esc \u8FD4\u56DE"],children:Tm(Xy,{width:t,height:n})})}import{Box as Zy,Text as VC}from"ink";import{jsx as Ti,jsxs as KC}from"react/jsx-runtime";var eb=[{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 tb(){let e=O(),{width:t}=j(),n=oi(0),o=X+1+X+eb.length,r=Ms(t)&&n-Es>=o;return KC(To,{header:r?Ti(Is,{width:t}):null,hints:["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","? \u5E2E\u52A9","q \u9000\u51FA"],children:[Ti(Zy,{marginTop:1,children:Ti(VC,{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(Zy,{marginTop:1,children:Ti(le,{items:eb,width:t,retain:"menu",onSelect:i=>e.push(i)})})]})}import{Box as wm,Text as km}from"ink";import{useState as YC}from"react";import{jsx as nn,jsxs as vm}from"react/jsx-runtime";function nb(){let e=O(),t=Os(),{width:n}=j(),o=Z(),{busy:r,run:i}=ue(),[s,a]=YC({name:"list"}),c=We([e.revision],m=>Wp({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",()=>Vp(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",()=>Kp(),{failToast:!0,onSuccess:()=>{e.reload(),e.toast("ok","\u5DF2\u5168\u90E8\u6807\u4E3A\u5DF2\u8BFB")}}))}),s.name==="detail"){let m=Fc(s.message),p=hd[m.target.kind],d=At([{text:st(m.body),color:f.foreground}],n),S=Math.max(3,o-4);return vm(Y,{hints:[...d.length>S?["\u2191\u2193 \u6EDA\u52A8"]:[],`Enter ${p}`,"Esc \u8FD4\u56DE"],onEscape:()=>a({name:"list"}),children:[vm(km,{wrap:"truncate",children:[nn(km,{bold:!0,color:f.foreground,children:st(m.title)}),nn(km,{color:f.faintForeground,children:` ${K(s.message.createdAt)}`})]}),nn(wm,{marginTop:1,children:nn(pt,{lines:d,height:Math.min(d.length,S)})}),nn(wm,{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=>vm(wm,{flexDirection:"column",children:[nn(pe,{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=Fc(p),S=st(d.title);return[p.read?S:{text:S,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(ze,{page:c.page,pages:c.pages,total:c.total,width:n})]})})})}import{Box as Ba,Text as Do}from"ink";import{useState as rb}from"react";import{z as xt}from"zod";var JC=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:Vm,rewardQuota:xt.number(),rewardQuotaReversed:xt.number(),inviterUsername:xt.string(),inviteeUsername:xt.string(),createdAt:xt.string()}))}),ob=()=>A(JC,"/invite");import{jsx as _t,jsxs as Fa}from"react/jsx-runtime";var XC=Pt(ec,Zi,"\u5168\u90E8\u7C7B\u578B"),ib=3;function QC(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 sb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=rb("main"),[i,s]=rb(""),a=Q([e.revision],async()=>{let[l,u]=await Promise.all([ob(),Be(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 _t(Y,{hints:o==="main"?["\u2191\u2193 \u6EDA\u52A8","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:_t(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u9080\u8BF7\u4FE1\u606F",width:t,children:({invite:l,site:u})=>{if(o==="filter")return _t(te,{title:"\u7B5B\u9009\u5956\u52B1\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:XC,initial:i}],onCancel:c,onSubmit:T=>{s(T.type??""),r("main")}});let m=t-ge,p=QC(l.rewards),d=i===""?l.items:l.items.filter(T=>T.rewardType===i),S=T=>Ut(2,t)+X+Bt+T+2+X+Bt+T+p.length+X+Bt+T,b=n-S(Ge)>=ib?Ge:0,g=Math.max(ib,n-S(b));return Fa(Ba,{flexDirection:"column",children:[_t(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)}]}),_t(Ba,{marginTop:1,flexDirection:"column",children:Fa(de,{title:"\u6211\u7684\u9080\u8BF7",width:t,gap:b,children:[Fa(Do,{wrap:"truncate",children:[_t(Do,{color:f.mutedForeground,children:"\u6211\u7684\u9080\u8BF7\u7801 "}),_t(Do,{color:f.accent,children:l.inviteCode})]}),Fa(Do,{wrap:"truncate",children:[_t(Do,{color:f.mutedForeground,children:"\u9080\u8BF7\u94FE\u63A5 "}),_t(Do,{color:f.accent,children:`${e.ctx.site}/register?invite=${l.inviteCode}`})]})]})}),_t(Ba,{marginTop:1,flexDirection:"column",children:_t(de,{title:"\u5956\u52B1\u89C4\u5219",width:t,gap:b,children:p.map((T,x)=>_t(Do,{wrap:"truncate",color:f.mutedForeground,children:T},x))})}),_t(Ba,{marginTop:1,flexDirection:"column",children:_t(de,{title:"\u9080\u8BF7\u5956\u52B1\u8BB0\u5F55",note:i===""?void 0:Zi(i),width:t,gap:b,children:_t(pe,{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:T=>{let x=T.rewardQuota-T.rewardQuotaReversed,C=T.rewardQuotaReversed>0?`\u9000\u6B3E\u51B2\u51CF -${Te(T.rewardQuotaReversed,u.quotaPerUsd)}`:"";return[K(T.createdAt),T.rewardType==="first_invitee"?T.inviterUsername:T.inviteeUsername,Zi(T.rewardType),_e([Te(x,u.quotaPerUsd),C])]},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{Box as Sb}from"ink";import{useState as xb}from"react";import{z as Ie}from"zod";var ZC=12e4,eR=Ie.object({id:Ie.number().int(),orderNo:Ie.string(),amountCny:Ie.number().int()}),ab=()=>A(Ie.array(eR),"/invoices/eligible-orders"),cb=Ie.object({id:Ie.number().int(),type:Qa,title:Ie.string(),taxId:Ie.string().nullable(),invoiceNo:Ie.string().nullable(),remark:Ie.string().nullable(),amountCny:Ie.number().int(),status:qm,rejectReason:Ie.string().nullable(),rejectedAt:Ie.string().nullable(),issuedAt:Ie.string().nullable(),createdAt:Ie.string()}),tR=cb.extend({hasFile:Ie.boolean(),orders:Ie.array(Ie.object({orderNo:Ie.string(),amountCny:Ie.number().int()}))}),lb=()=>A(Ie.array(cb),"/invoices"),mb=e=>A(tR,`/invoices/${e}`),ub=e=>A(se,"/invoices",{method:"POST",json:e}),db=e=>as(`/invoices/${e}/file`,{timeoutMs:ZC}),nR=Ie.object({id:Ie.number().int(),type:Qa,title:Ie.string(),taxId:Ie.string().nullable()}),Ua=()=>A(Ie.array(nR),"/invoices/profiles"),pb=e=>A(se,"/invoices/profiles",{method:"POST",json:e}),fb=(e,t)=>A(se,`/invoices/profiles/${e}`,{method:"PATCH",json:t}),gb=e=>A(se,`/invoices/profiles/${e}`,{method:"DELETE"});import{Box as oR,Text as $o,useInput as rR}from"ink";import{useEffect as iR,useState as sR}from"react";import{jsx as wi,jsxs as Cm}from"react/jsx-runtime";var aR="[x]",cR="[ ]",hb=4,ja=2,yb=2;function bb({items:e,columns:t,row:n,selected:o,onToggle:r,onToggleAll:i,onSubmit:s,width:a,height:c,emptyLabel:l}){let[u,m]=sR(0),p=Math.max(1,c-1),d=e.length>p?Math.max(1,p-1):p;iR(()=>{m(y=>Math.min(y,Math.max(0,e.length-1)))},[e.length]);let S=ml(u,d),b=y=>{e.length!==0&&m(h=>(h+y+e.length)%e.length)};rR((y,h)=>{if(h.upArrow){b(-1);return}if(h.downArrow){b(1);return}if(h.return){s();return}y===" "&&e.length>0&&r(u)}),G(y=>{if(y==="k"){b(-1);return}if(y==="j"){b(1);return}y==="a"&&i()});let g=y=>{let h=S+y-1;return h>=0&&h<e.length?h:null},T=rt({onWheel:b,onClick:({row:y})=>{let h=g(y);h!==null&&(m(h),r(h))},onHover:({row:y})=>{let h=g(y);h!==null&&m(h)}}),x=kl(t,e.map(y=>n(y)),a-ja-hb),C=e.slice(S,S+d);return Cm(oR,{ref:T,flexDirection:"column",children:[Cm($o,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(ja+hb),t.map((y,h)=>y.align==="right"?Yn(y.label,x[h]??0):Je(y.label,x[h]??0)).join(" ".repeat(yb))]}),e.length===0?wi($o,{color:f.faintForeground,children:`${" ".repeat(ja)}${l}`}):C.map((y,h)=>{let R=S+h,I=R===u,E=o.has(R),z=I?f.accent:f.foreground,M=n(y);return Cm($o,{wrap:"truncate",children:[wi($o,{color:f.accent,children:I?`${ae.cursor} `:" "}),wi($o,{color:E?f.accent:z,bold:I,children:`${E?aR:cR} `}),t.map((v,k)=>{let _=v.align==="right"?Yn(M[k]??"",x[k]??0):Je(M[k]??"",x[k]??0);return wi($o,{color:z,bold:I,children:k>0?`${" ".repeat(yb)}${_}`:_},v.label)})]},R)}),(S>0||S+d<e.length)&&wi($o,{color:f.faintForeground,children:`${" ".repeat(ja)}${S+1}-${Math.min(S+d,e.length)} / ${e.length}`})]})}import{jsx as wn,jsxs as lR}from"react/jsx-runtime";function Tb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=xb({name:"pick"}),[i,s]=xb(new Set),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[S,b]=await Promise.all([ab(),Ua()]);return{orders:S,profiles:b}});G(S=>{o.name==="pick"&&S==="r"&&e.reload()});let p=()=>{o.name==="pick"?e.pop():o.name==="preset"?r({name:"pick"}):o.name==="remark"?r({name:"preset"}):(l(),r({name:"remark",profile:o.profile,remark:o.remark}))},d=(S,b,g)=>{let T=S.filter(x=>i.has(x.id)).map(x=>x.id);u("\u6B63\u5728\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7",()=>ub({orderIds:T,type:b.type,title:b.title,taxId:b.taxId,remark:g===""?null:g}),{onSuccess:()=>{e.toast("ok","\u5DF2\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7"),e.pop()}})};return wn(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:wn(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u53EF\u5F00\u7968\u8BA2\u5355",width:t,children:({orders:S,profiles:b})=>{if(o.name==="pick")return S.length===0?wn(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"}):wn(bb,{items:S,width:t,height:n,columns:[{label:"\u8BA2\u5355\u53F7",shrink:!0},{label:"\u91D1\u989D",align:"right"}],row:y=>[y.orderNo,Ce(y.amountCny)],selected:new Set(S.flatMap((y,h)=>i.has(y.id)?[h]:[])),onToggle:y=>{let h=S[y]?.id;h!==void 0&&s(R=>{let I=new Set(R);return I.has(h)?I.delete(h):I.add(h),I})},onToggleAll:()=>s(y=>S.every(h=>y.has(h.id))?new Set:new Set(S.map(h=>h.id))),onSubmit:()=>{if(!S.some(y=>i.has(y.id))){e.toast("warn","\u8BF7\u5148\u52FE\u9009\u8981\u5F00\u7968\u7684\u8BA2\u5355");return}if(b.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 y=[{heading:"\u5E38\u7528\u4FE1\u606F"},...b.map(h=>({value:h,label:`${fo(h.type)} \xB7 ${h.title}`,hint:h.taxId??void 0}))];return wn(le,{items:y,width:t,height:n,onSelect:h=>r({name:"remark",profile:h,remark:""})})}if(o.name==="remark")return wn(te,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u5907\u6CE8",width:t,submitLabel:"\u4E0B\u4E00\u6B65",fields:[{kind:"textarea",name:"remark",label:"\u5907\u6CE8",rows:2,maxLength:200,initial:o.remark,placeholder:"\u5C55\u793A\u5728\u53D1\u7968\u7968\u9762\u5907\u6CE8\u680F\u7684\u5185\u5BB9",optional:!0}],onCancel:p,onSubmit:y=>r({name:"confirm",profile:o.profile,remark:(y.remark??"").trim()})});let{profile:g,remark:T}=o,x=S.filter(y=>i.has(y.id)),C=x.reduce((y,h)=>y+h.amountCny,0);return lR(Sb,{flexDirection:"column",children:[wn(de,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u786E\u8BA4\u4FE1\u606F",note:`\u5DF2\u9009 ${x.length} \u7B14 \xB7 \u5408\u8BA1 ${Ce(C)}`,width:t,children:wn(jl,{width:t-ge,items:[["\u53D1\u7968\u7C7B\u578B",po(g.type)],["\u62AC\u5934\u7C7B\u578B",Ed(g.taxId)],["\u62AC\u5934",g.title],...g.taxId===null?[]:[["\u7A0E\u53F7",g.taxId]],...T===""?[]:[["\u5907\u6CE8",T]]]})}),wn(Sb,{marginTop:1,children:wn(Pe,{width:t,title:Md,confirmLabel:"\u786E\u8BA4\u63D0\u4EA4",busy:a,error:c,onConfirm:()=>d(S,g,T),onCancel:p})})]})}})})}import{Box as Rm}from"ink";import{useState as mR}from"react";function wb(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 kb=e=>[{kind:"select",name:"type",label:"\u7C7B\u578B",options:[{value:"general",label:po("general")},{value:"special",label:po("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",hint:t=>t.type!=="special"?"\u5355\u4F4D\u62AC\u5934\u9700\u586B\u5199\uFF0C\u7559\u7A7A\u5C06\u6309\u4E2A\u4EBA\u5F00\u5177":void 0,optional:t=>t.type!=="special"}];import{jsx as jn,jsxs as vb}from"react/jsx-runtime";var uR=8,dR=3;function Cb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=mR({name:"list"}),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.revision],Ua),m=i!==null,p=o.name==="list"&&!m;G(S=>{S==="r"?e.reload():S==="n"&&r({name:"create"})},p);let d=()=>{o.name==="list"?e.pop():(a(),r({name:"list"}))};return jn(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:jn(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u5E38\u7528\u5F00\u7968\u4FE1\u606F",width:t,children:S=>{let b=o.name==="list"?n:Math.max(dR,n-uR);return vb(Rm,{flexDirection:"column",children:[jn(Rm,{marginBottom:o.name==="list"?0:1,children:jn(pe,{retain:"list",items:S,width:t,height:b,isActive:p,columns:[{label:"\u7C7B\u578B"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7A0E\u53F7"}],row:g=>[fo(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&&vb(de,{title:o.profile.title,width:t,children:[jn(Ve,{width:t-ge,items:[["\u7C7B\u578B",po(o.profile.type)],["\u7A0E\u53F7",o.profile.taxId??"\u2014"]]}),jn(Rm,{marginTop:1,children:jn(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")&&jn(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:kb(o.name==="edit"?o.profile:null),onCancel:d,onSubmit:g=>{let T=wb(g,c);if(T===null)return;let x=o.name==="edit"?()=>fb(o.profile.id,T):()=>pb(T);l("\u6B63\u5728\u4FDD\u5B58",x,{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u4FDD\u5B58")}})}}),o.name==="confirm-delete"&&jn(Pe,{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",()=>gb(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 _m}from"react";import{jsx as nt,jsxs as Rb}from"react/jsx-runtime";var pR=Pt(Xa,Xi,"\u5168\u90E8\u72B6\u6001");function fR({id:e,width:t}){let n=O(),o=Q([e,n.revision],()=>mb(e)),r=t-ge,[i,s]=_m(null),[a,c]=_m(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(pr,{title:"\u4FDD\u5B58\u53D1\u7968\u6587\u4EF6",width:t,download:async()=>({fileName:`invoice-${a}.pdf`,bytes:await db(u.id)}),onCancel:()=>c(null),onSaved:S=>{c(null),s(S),n.toast("ok","\u53D1\u7968\u5DF2\u4FDD\u5B58")}});let m=Xi(u.status),p=yt(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 Rb(de,{title:u.title,note:K(u.createdAt),width:t,children:[Rb(wr,{wrap:"truncate",children:[nt(wr,{color:f.mutedForeground,children:fo(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(S=>nt(wr,{wrap:"truncate",color:f.faintForeground,children:_e([S.orderNo,Ce(S.amountCny)])},S.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 _b(){let e=O(),{width:t}=j(),n=Z(),[o,r]=_m({name:"list"}),[i,s]=Me("status",()=>""),a=Q([e.revision],lb);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:pR,initial:i}],onCancel:c,onSubmit:m=>{s(m.status??""),r({name:"list"})}});if(o.name==="detail")return nt(fR,{id:o.id,width:t});let u=i===""?l:l.filter(m=>m.status===i);return nt(pe,{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,fo(m.type),Ce(m.amountCny),bt(Xi(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 gR}from"ink";import{useState as Pb}from"react";import{jsx as kr,jsxs as yR}from"react/jsx-runtime";var hR=Pt(Za,qc,"\u5168\u90E8\u7C7B\u578B");function Ab(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Pb("list"),[i,s]=Pb(""),a=Q([e.revision],()=>Be(e.ctx.site)),c=We([e.revision,i],m=>Eh({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:hR,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=>yR(gR,{flexDirection:"column",children:[kr(pe,{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 S=Zo(d.amount,m.quotaPerUsd);return[K(d.createdAt),qc(d.type),{text:d.amount>=0?`+${S}`:S,tone:d.amount>=0?"success":"danger"},Te(d.balanceAfter,m.quotaPerUsd),_e([Td(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(ze,{page:c.page,pages:c.pages,total:c.total,width:t})]})})})})}import{Box as Ob}from"ink";import{useState as SR}from"react";import{z as bR}from"zod";var vi={recharge:"/recharge",subscription:"/subscriptions"};async function Ha(e,t){let n=`${vi[e]}/orders/${t}`;return e==="recharge"?{kind:e,...await A(Ir,n)}:{kind:e,...await A(Nr,n)}}async function Eb(e,t){let n=`${vi[e]}/orders/${t}/pay`;if(e==="recharge"){let{order:i,qrCode:s}=await A(Oi,n,{method:"POST"});return{order:{kind:e,...i},qrCode:s}}let{order:o,qrCode:r}=await A(Lr,n,{method:"POST"});return{order:{kind:e,...o},qrCode:r}}var Mb=(e,t)=>A(bR.array(hu),`${vi[e]}/orders/${t}/refunds`),Ib=(e,t,n)=>A(se,`${vi[e]}/orders/${t}/refund-request`,{method:"POST",json:{reason:n}}),Nb=(e,t)=>A(se,`${vi[e]}/orders/${t}/refund-request/cancel`,{method:"POST"});import{Box as qa,Text as kn}from"ink";import{jsx as on,jsxs as Ci}from"react/jsx-runtime";function Lb({order:e,refunds:t,quotaPerUsd:n,width:o}){let r=o-ge,i=zn(e.status),s=yt(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(de,{title:e.kind==="recharge"?"\u5145\u503C":e.planName,note:e.orderNo,width:o,children:[Ci(kn,{wrap:"truncate",children:[on(kn,{color:s===void 0?f.mutedForeground:et[s],children:i.label}),e.kind==="subscription"&&on(kn,{color:f.faintForeground,children:` ${e.renewal?"\u7EED\u8D39":"\u65B0\u8D2D"}`})]}),on(qa,{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(qa,{marginTop:1,children:on(Ve,{width:r,items:a})}),t!==null&&Ci(qa,{marginTop:1,flexDirection:"column",children:[on(kn,{color:f.mutedForeground,children:"\u9000\u6B3E\u8BB0\u5F55"}),t.length===0?on(kn,{color:f.faintForeground,children:"\u6682\u65E0\u9000\u6B3E\u8BB0\u5F55"}):t.map(c=>{let l=wd(c.status),u=yt(l);return Ci(qa,{flexDirection:"column",children:[Ci(kn,{wrap:"truncate",children:[on(kn,{color:f.foreground,children:Ce(c.amountCny)}),on(kn,{color:u===void 0?f.mutedForeground:et[u],children:` ${l.label}`}),on(kn,{color:f.faintForeground,children:` ${K(c.createdAt)}`})]}),(c.reason!==null||c.rejectReason!==null||c.refundTradeNo!==null)&&on(kn,{wrap:"truncate",color:f.faintForeground,children:` ${_e([c.reason??"",c.rejectReason===null?"":`\u9A73\u56DE\uFF1A${c.rejectReason}`,c.refundTradeNo??""])}`})]},c.id)})]})]})}import{jsx as Bo,jsxs as TR}from"react/jsx-runtime";var xR=new Set(["pending","expired","failed"]);function Ga(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:yt(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 Db({params:e}){let t=O(),{width:n}=j(),[o,r]=SR("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[b,g]=await Promise.all([Ha(e.kind,e.orderNo),Be(t.ctx.site)]),T=xR.has(b.status)?null:await Mb(e.kind,e.orderNo);return{order:b,refunds:T,site:g}});G(b=>{o==="main"&&i===null&&b==="r"&&t.reload()});let m=()=>{o==="main"?t.pop():(a(),r("main"))},p=b=>{l("\u6B63\u5728\u62C9\u8D77\u652F\u4ED8",()=>Eb(e.kind,e.orderNo),{failToast:!0,onSuccess:({order:g,qrCode:T})=>{t.push("pay",vr(g,T,b.quotaPerUsd))}})},d=b=>{l("\u6B63\u5728\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7",()=>Ib(e.kind,e.orderNo,b),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7")}})},S=()=>{l("\u6B63\u5728\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",()=>Nb(e.kind,e.orderNo),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u64A4\u9500\u9000\u6B3E\u7533\u8BF7")}})};return Bo(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:Bo(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u5355",width:n,children:({order:b,refunds:g,site:T})=>{if(o==="refund")return Bo(te,{title:`\u7533\u8BF7\u9000\u6B3E \u2014 ${b.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:[...Kc[e.kind].map(C=>({value:C,label:C})),{value:"other",label:"\u5176\u4ED6"}],initial:Kc[e.kind][0],hint:Ad[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:C=>{let y=C.reason??"",h=y==="other"?(C.custom??"").trim():y;if(h===""){c("\u8BF7\u586B\u5199\u5177\u4F53\u8BF4\u660E");return}d(h)}});if(o==="confirm-cancel")return Bo(Pe,{width:n,title:"\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",detail:`\u786E\u8BA4\u64A4\u9500\u8BA2\u5355 ${b.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\uFF1F${b.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:S,onCancel:m});let x=[];return b.status==="pending"&&x.push({value:"pay",label:"\u7EE7\u7EED\u652F\u4ED8",hint:"\u91CD\u65B0\u62C9\u8D77\u652F\u4ED8\u5B9D\u4E8C\u7EF4\u7801"}),b.status==="refund_requested"&&x.push({value:"cancel-refund",label:"\u64A4\u9500\u7533\u8BF7",hint:"\u9000\u6B3E\u5C1A\u672A\u5BA1\u6838\uFF0C\u53EF\u64A4\u56DE"}),yu(b)&&x.push({value:"refund",label:"\u7533\u8BF7\u9000\u6B3E",labelTone:"danger"}),TR(Ob,{flexDirection:"column",children:[Bo(Lb,{order:b,refunds:g,quotaPerUsd:T.quotaPerUsd,width:n}),x.length>0&&i===null&&Bo(Ob,{marginTop:1,children:Bo(le,{width:n,items:x,retain:"menu",onSelect:C=>{a(),C==="pay"?p(T):r(C==="refund"?"refund":"confirm-cancel")}})})]})}})})}import{useRef as kR,useState as Hb}from"react";import{Box as $b,Text as Fo}from"ink";import{Fragment as wR,jsx as Wt,jsxs as Bb}from"react/jsx-runtime";var Fb={columns:20,rows:2};function Ub(e,t,n){return Ws(e,t,Fb,n)}function jb({phase:e,qrCode:t,amountCny:n,summary:o,paidNote:r,expiredNote:i,pollError:s,width:a,layout:c}){let l=s===null?Wt(Oe,{label:"\u7B49\u5F85\u652F\u4ED8\u5230\u8D26\u2026"}):Wt(Fo,{wrap:"truncate",color:et.warning,children:`\u67E5\u8BE2\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1A${s}`});if(e==="paid")return Wt(ye,{tone:"ok",width:a,title:"\u652F\u4ED8\u6210\u529F\uFF01",detail:r});if(e==="expired")return Wt(ye,{tone:"warn",width:a,title:"\u8BA2\u5355\u5DF2\u8D85\u65F6",detail:i});if(!c.fits)return Bb($b,{flexDirection:"column",children:[Wt(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`}),Wt(Fo,{color:f.accent,children:t}),Wt($b,{marginTop:1,children:Wt(Fo,{bold:!0,color:f.foreground,children:Ce(n)})}),l]});let u=c.asideRows-Fb.rows,m=u>=1,p=u>=2,d=u>=2+o.length;return Wt(zs,{value:t,aside:Bb(wR,{children:[p&&Wt(Fo,{bold:!0,color:f.foreground,children:"\u626B\u7801\u652F\u4ED8"}),Wt(Fo,{bold:!0,color:f.foreground,children:Ce(n)}),m&&Wt(Fo,{color:f.mutedForeground,children:"\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u4E00\u626B\u5B8C\u6210\u652F\u4ED8"}),d&&o.map((S,b)=>Wt(Fo,{wrap:"truncate",color:f.mutedForeground,children:S},b)),l]})})}import{jsx as qb}from"react/jsx-runtime";var vR=5,CR=2e3;function Gb({params:e}){let t=O(),{width:n,columns:o,rows:r}=j(),i=oi(0),[s,a]=Hb("waiting"),[c,l]=Hb(null),u=kR(0);ia(CR,async()=>{let d;try{d=await Ha(e.kind,e.orderNo)}catch(S){l(Se(S));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>=vR&&a("expired");return}u.current=0},s==="waiting"),G(d=>{d!=="c"||s!=="waiting"||$a(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=Ub(e.qrCode,{width:n,rows:i},{columns:o-n,rows:r-i}),p=s==="waiting"&&m.fits;return qb(Y,{trail:["\u626B\u7801\u652F\u4ED8"],bleed:p,hints:s==="waiting"?["c \u590D\u5236\u94FE\u63A5"]:[],children:qb(jb,{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 _R}from"react";import{z as Hn}from"zod";var RR=Hn.object({id:Hn.number().int(),name:Hn.string(),originalCny:Hn.number().int(),discountPercent:Hn.number().int(),payCny:Hn.number().int(),quota:Hn.number()}),Wb=()=>A(Hn.array(RR),"/recharge-packages"),zb=e=>A(Oi,"/recharge/orders",{method:"POST",json:e}),Vb=()=>A(Hn.array(Ir),"/recharge/orders");import{jsx as Cr}from"react/jsx-runtime";var PR=Pt(Pr,zn,"\u5168\u90E8\u72B6\u6001");function AR(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 Kb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=_R({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[b,g,T]=await Promise.all([Wb(),Ca(e.ctx.site),Vb()]);return{packages:b,pricing:g,orders:T}});G(b=>{o.name==="menu"&&(b==="r"?e.reload():b==="f"&&r({name:"filter"}))});let d=()=>{o.name==="menu"?e.pop():(l(),r({name:"menu"}))},S=(b,g)=>{m("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>zb(b),{onSuccess:({order:T,qrCode:x})=>{r({name:"menu"}),e.push("pay",vr({kind:"recharge",...T},x,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:b,pricing:g,orders:T})=>{if(o.name==="confirm")return Cr(Pe,{width:t,title:`\u786E\u8BA4\u5145\u503C ${Ce(o.pkg.payCny)}\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>S({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:y=>{let h=Number(y.yuan??""),R=$c(h);if(!Number.isFinite(h)||R<$c(g.minTopupCny)||R>ac){u(`\u8BF7\u8F93\u5165 ${g.minTopupCny} \u5230 ${pd(ac)} \u5143\u4E4B\u95F4\u7684\u91D1\u989D`);return}S({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:PR,initial:i}],onCancel:d,onSubmit:y=>{s(y.status??""),r({name:"menu"})}});let x=i===""?T:T.filter(y=>y.status===i),C=[{heading:"\u5145\u503C\u5957\u9910"},...b.map(y=>({value:{kind:"pkg",pkg:y},label:y.name,hint:AR(y,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"},...x.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}]:x.map(y=>({value:{kind:"order",orderNo:y.orderNo},label:Ce(y.amountCny),...Ga(y),hint:`${K(y.createdAt)} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(y.quota,g.quotaPerUsd)}`}))];return Cr(le,{items:C,width:t,height:n,retain:"menu",onSelect:y=>{l(),y.kind==="custom"?r({name:"custom"}):y.kind==="order"?e.push("order",{kind:"recharge",orderNo:y.orderNo}):y.kind==="pkg"&&r({name:"confirm",pkg:y.pkg})}})}})})}import{Box as qn,Text as Ri}from"ink";import{useState as NR}from"react";import LR from"string-width";import{z as xe}from"zod";var ER=xe.object({windowId:xe.number().int(),durationMinutes:xe.number().int(),quota:xe.number(),used:xe.number(),resetAt:xe.string()}),Yb=xe.object({name:xe.string(),multiplier:xe.number()}),MR=xe.object({billingPreference:Ya,subscriptions:xe.array(xe.object({id:xe.number().int(),planName:xe.string(),groups:xe.array(Yb),startsAt:xe.string(),expiresAt:xe.string(),revokedAt:xe.string().nullable(),renewable:xe.boolean(),windows:xe.array(ER)}))}),Jb=()=>A(MR,"/subscriptions"),IR=xe.object({id:xe.number().int(),name:xe.string(),description:xe.string().nullable(),priceCny:xe.number().int(),durationDays:xe.number().int(),enabled:xe.boolean(),groups:xe.array(Yb),windows:xe.array(xe.object({durationMinutes:xe.number().int(),quota:xe.number()}))}),Xb=()=>A(xe.array(IR),"/subscription-plans"),Qb=e=>A(Lr,"/subscriptions/orders",{method:"POST",json:e}),Zb=e=>A(Lr,`/subscriptions/${e}/renew`,{method:"POST"}),eS=()=>A(xe.array(Nr),"/subscriptions/orders"),tS=e=>A(xe.object({billingPreference:Ya}),"/subscriptions/preference",{method:"PUT",json:e});import{jsx as je,jsxs as Uo}from"react/jsx-runtime";var OR=Pt(Pr,zn,"\u5168\u90E8\u72B6\u6001");function DR(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 $R=3;function BR({win:e,quotaPerUsd:t,width:n}){let o=zc(e),r=_d(e.durationMinutes),i=`\u5DF2\u7528 ${o}% ${ae.bullet} ${Te(e.used,t)} / ${Te(e.quota,t)}`;return Uo(qn,{flexDirection:"column",children:[Uo(Ri,{wrap:"truncate",children:[je(Ri,{color:f.foreground,children:r}),je(Ri,{color:o>=100?f.danger:f.mutedForeground,children:Yn(i,Math.max(0,n-LR(r)))})]}),je(kg,{used:e.used,total:e.quota,width:n}),je(Ri,{wrap:"truncate",color:f.faintForeground,children:`\u5C06\u4E8E ${K(e.resetAt)} \u91CD\u7F6E`})]})}function FR(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(zc))}% \xB7 ${t}`}function UR(e){let t=e.windows.length*4;return X+Xe+2+t+(e.renewable?X+1:0)}function jR(e){let t=e.description!==null&&e.description!==""?1+Ge:0,n=Math.ceil((1+e.windows.length)/2);return X+Xe+t+n+X+1}function nS(){let e=O(),{width:t}=j(),n=Z(),[o,r]=NR({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,T,x,C]=await Promise.all([Jb(),Xb(),eS(),Be(e.ctx.site)]);return{mine:g,plans:T,orders:x,site:C}});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",()=>tS({billingPreference:g}),{onSuccess:()=>{r({name:"menu"}),e.reload(),e.toast("ok","\u504F\u597D\u5DF2\u4FDD\u5B58")}})},S=(g,T)=>{u("\u6B63\u5728\u521B\u5EFA\u7EED\u8D39\u8BA2\u5355",()=>Zb(g.id),{onSuccess:({order:x,qrCode:C})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...x},C,T.quotaPerUsd))}})},b=(g,T)=>{u("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Qb({planId:g.id}),{onSuccess:({order:x,qrCode:C})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...x},C,T.quotaPerUsd))}})};return je(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:je(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u9605",width:t,children:({mine:g,plans:T,orders:x,site:C})=>{if(o.name==="preference")return je(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:xd,initial:g.billingPreference,hint:Hc}],onCancel:p,onSubmit:k=>{d(k.billingPreference??g.billingPreference)}});if(o.name==="filter")return je(te,{title:"\u7B5B\u9009\u8BA2\u9605\u8BA2\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:OR,initial:i}],onCancel:p,onSubmit:k=>{s(k.status??""),r({name:"menu"})}});let y=DR(o,g.subscriptions,T);if(y.kind==="missing-sub")return je(ye,{tone:"warn",width:t,title:"\u8BA2\u9605\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",detail:"\u6309 Esc \u8FD4\u56DE"});if(y.kind==="missing-plan")return je(ye,{tone:"warn",width:t,title:"\u5957\u9910\u4E0D\u5B58\u5728\u6216\u5DF2\u4E0B\u67B6",detail:"\u6309 Esc \u8FD4\u56DE"});if(y.kind==="sub"&&y.confirm)return je(Pe,{width:t,title:`\u786E\u8BA4\u7EED\u8D39\u300C${y.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:()=>S(y.sub,C),onCancel:p});if(y.kind==="plan"&&y.confirm)return je(Pe,{width:t,title:`\u786E\u8BA4\u8BA2\u9605\u300C${y.plan.name}\u300D\uFF08${Ce(y.plan.priceCny)} / ${y.plan.durationDays} \u5929\uFF09\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b(y.plan,C),onCancel:p});let h=y.kind==="plan"?y.plan.description:"",R=i===""?x:x.filter(k=>k.status===i),I=[{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(k=>{let _=Vc(k);return{value:{kind:"sub",id:k.id},label:k.planName,badge:_.label,badgeTone:yt(_),hint:FR(k)}}),{heading:""},{value:{kind:"preference"},label:"\u6263\u8D39\u65B9\u5F0F",badge:jc(g.billingPreference),badgeTone:"accent",hint:Hc(g.billingPreference)},{heading:""},{heading:"\u53EF\u9009\u5957\u9910"},...T.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}]:T.map(k=>({value:{kind:"plan",id:k.id},label:k.name,...k.enabled?{}:{badge:"\u5DF2\u505C\u552E",badgeTone:"warning"},hint:`${Ce(k.priceCny)} / ${k.durationDays} \u5929 \xB7 ${k.groups.map(os).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(k=>({value:{kind:"order",orderNo:k.orderNo},label:`${k.planName}${k.renewal?"\uFF08\u7EED\u8D39\uFF09":""}`,...Ga(k),hint:`${K(k.createdAt)} \xB7 ${Ce(k.amountCny)}`}))],E=y.kind==="sub"?UR(y.sub):y.kind==="plan"?jR(y.plan):0,z=E===0?n:n-E>=$R?n-E:0,M=t-ge,v=o.name==="menu"&&a===null;return Uo(qn,{flexDirection:"column",children:[z>0&&je(le,{items:I,width:t,height:z,isActive:v,retain:"menu",onSelect:k=>{l(),k.kind==="preference"?r({name:"preference"}):k.kind==="order"?e.push("order",{kind:"subscription",orderNo:k.orderNo}):k.kind==="sub"?r({name:"sub",id:k.id}):k.kind==="plan"&&r({name:"plan",id:k.id})}}),y.kind==="sub"&&Uo(qn,{marginTop:z>0?X:0,flexDirection:"column",children:[Uo(de,{title:y.sub.planName,note:y.sub.revokedAt!==null?`${K(y.sub.revokedAt)} \u4F5C\u5E9F`:`${K(y.sub.expiresAt)} \u5230\u671F`,width:t,children:[je(Ve,{width:M,items:[["\u72B6\u6001",Vc(y.sub).label],["\u8986\u76D6\u5206\u7EC4",y.sub.groups.map(os).join("\u3001")],["\u751F\u6548\u65F6\u95F4",K(y.sub.startsAt)]]}),je(qn,{marginTop:1,flexDirection:"column",children:y.sub.windows.map((k,_)=>je(qn,{marginTop:_===0?0:1,flexDirection:"column",children:je(BR,{win:k,quotaPerUsd:C.quotaPerUsd,width:M})},k.windowId))})]}),y.sub.renewable&&a===null&&je(qn,{marginTop:X,children:je(le,{width:t,items:[{value:"renew",label:"\u7EED\u8D39"}],onSelect:()=>r({name:"confirm-renew",id:y.sub.id})})})]}),y.kind==="plan"&&Uo(qn,{marginTop:z>0?X:0,flexDirection:"column",children:[Uo(de,{title:y.plan.name,note:`${Ce(y.plan.priceCny)} / ${y.plan.durationDays} \u5929`,width:t,children:[h!==""&&je(Ri,{wrap:"truncate",color:f.mutedForeground,children:h}),je(qn,{marginTop:h===""?0:Ge,children:je(Ve,{width:M,items:[["\u8986\u76D6\u5206\u7EC4",y.plan.groups.map(os).join("\u3001")],...Pd(y.plan,C.quotaPerUsd).map((k,_)=>[_===0?"\u7528\u91CF\u7A97\u53E3":"",k])]})})]}),a===null&&je(qn,{marginTop:X,children:je(le,{width:t,items:[{value:"subscribe",label:y.plan.enabled?"\u8BA2\u9605":"\u5DF2\u505C\u552E",disabled:!y.plan.enabled}],onSelect:()=>r({name:"confirm-buy",id:y.plan.id})})})]})]})}})})}import{jsx as be}from"react/jsx-runtime";var oS={home:{render:()=>be(tb,{})},help:{render:()=>be(Qy,{})},login:{render:()=>be(Xg,{})},register:{render:()=>be(Qg,{})},forgot:{render:()=>be(Vg,{})},agreement:{render:e=>be(jg,{params:e})},tokens:{render:()=>be($y,{})},logs:{render:()=>be(qh,{})},usage:{render:()=>be(Dh,{})},ledger:{render:()=>be(Ab,{})},subscription:{render:()=>be(nS,{})},models:{render:()=>be(Jh,{})},docs:{render:()=>be(Gy,{})},doc:{render:e=>be(Vy,{params:e})},recharge:{render:()=>be(Kb,{})},order:{render:e=>be(Db,{params:e})},pay:{render:e=>be(Gb,{params:e})},invoices:{render:()=>be(_b,{})},"invoice-apply":{render:()=>be(Tb,{})},"invoice-profiles":{render:()=>be(Cb,{})},invite:{render:()=>be(sb,{})},tickets:{render:()=>be(Ug,{})},ticket:{render:e=>be(Fg,{params:e})},community:{render:()=>be(hh,{})},post:{render:e=>be(Ch,{params:e})},floor:{render:e=>be(lh,{params:e})},compose:{render:e=>be(nh,{params:e})},"post-edit":{render:e=>be(oh,{params:e})},homepage:{render:e=>be(dh,{params:e})},inbox:{render:()=>be(nb,{})},announcements:{render:()=>be(sf,{})},"announce-gate":{render:e=>be(nf,{params:e}),lockNav:!0},profile:{render:()=>be(Ag,{})},"my-posts":{render:e=>be(Sh,{params:e})},"my-comments":{render:e=>be(xh,{params:e})},bookmarks:{render:()=>be(Th,{})},drafts:{render:()=>be(wh,{})}};function rS(e){return oS[e].lockNav===!0}function iS(e){let t=oS[e.id].render;return t(e.params)}import{jsx as ro,jsxs as e_}from"react/jsx-runtime";function zR(){let e=O(),{rows:t}=j(),n=gs(),o=rS(e.current.id)||n,r=e.depth===1&&bs(e.current.id)&&wt().session===null;return Pm(()=>{r&&e.home()}),GR((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())}),ro(HR,{flexDirection:"column",height:Math.max(1,t),paddingX:1,paddingTop:1,overflow:"hidden",children:iS(e.current)})}function VR(){let e=O(),t=Q([e.revision],async()=>{if(e.gate.announcementsChecked||wt().session===null)return null;let n;try{n=await Xd()}catch{return null}return e.gate.announcementsChecked=!0,n});return Pm(()=>{t.phase!=="ready"||t.data===null||e.gate.announcementsShown||(e.gate.announcementsShown=!0,e.push("announce-gate",{item:t.data}))}),null}function KR(){let e=O(),t=WR(!1);return Pm(()=>{t.current||(t.current=!0,Yd().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${Se(n)}`)))}),null}function YR({ctx:e,mouse:t}){return ro(fp,{subscribe:t.subscribe,children:ro(rp,{children:ro(Sp,{ctx:e,children:e_(Qp,{children:[ro(KR,{}),ro(VR,{}),ro(zR,{})]})})})})}var JR="\x1B[2J\x1B[3J\x1B[H",XR="\x1B[H\x1B[J",QR="\x1B[3J";function ZR(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(XR).split(QR).join("");return t.write(s,...i)}}})}async function sS(e){let t=dp(process.stdin,process.stdout);try{await qR(ro(YR,{ctx:e,mouse:t}),{exitOnCtrlC:!0,alternateScreen:!0,stdin:t.stdin,stdout:ZR(process.stdout)}).waitUntilExit()}finally{t.dispose()}}var r_=`${zt} v${Vt} \u2014 CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF
|
|
27
27
|
|
|
28
28
|
\u7528\u6CD5
|
|
29
29
|
${zt} \u8FDB\u5165\u4EA4\u4E92\u754C\u9762
|
|
30
30
|
${zt} help \u67E5\u770B\u672C\u8BF4\u660E
|
|
31
31
|
${zt} update \u68C0\u67E5\u5E76\u5B89\u88C5\u65B0\u7248\u672C
|
|
32
32
|
${zt} uninstall \u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
|
|
33
|
-
`;async function i_(){let e;try{({positionals:e}=o_({args:process.argv.slice(2),allowPositionals:!0,options:{}}))}catch(o){throw new F(Se(o),{hint:`\u8FD0\u884C ${zt} help \u67E5\u770B\u7528\u6CD5`,exitCode:
|
|
33
|
+
`;async function i_(){let e;try{({positionals:e}=o_({args:process.argv.slice(2),allowPositionals:!0,options:{}}))}catch(o){throw new F(Se(o),{hint:`\u8FD0\u884C ${zt} help \u67E5\u770B\u7528\u6CD5`,exitCode:za})}let[t]=e;if(t==="help")return process.stdout.write(r_),Rr;if(t==="update")return s_();if(t==="uninstall")return a_();if(t!==void 0)throw new F(`\u672A\u77E5\u547D\u4EE4 ${t}\uFF0C\u8FD0\u884C ${zt} help \u67E5\u770B\u7528\u6CD5`,{exitCode:za});l_();let n=Hd();if(n!==null){let o=cS(process.stdout,"\u6B63\u5728\u6838\u5BF9\u7AD9\u70B9\u5730\u5740");try{await qd(n)}finally{o()}}return await sS(Bm()),Rr}async function s_(){let e=process.stdout,t=cS(e,"\u6B63\u5728\u68C0\u67E5\u65B0\u7248\u672C"),n;try{n=await Kd()}finally{t()}let o=so(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
|
-
`),
|
|
36
|
-
`),()=>{};let n=so(e,f.mutedForeground,t),o=0,r=()=>{let s=er[o%er.length]??"";o+=1,e.write(`\r\x1B[2K${so(e,f.accent,s)} ${n}`)};r();let i=setInterval(r,
|
|
35
|
+
`),Rr}function cS(e,t){if(!e.isTTY)return e.write(`${t}
|
|
36
|
+
`),()=>{};let n=so(e,f.mutedForeground,t),o=0,r=()=>{let s=er[o%er.length]??"";o+=1,e.write(`\r\x1B[2K${so(e,f.accent,s)} ${n}`)};r();let i=setInterval(r,ws);return()=>{clearInterval(i),e.write("\r\x1B[2K")}}async function a_(){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
37
|
`),!await c_("\u8F93\u5165 y \u786E\u8BA4\u5378\u8F7D\uFF1A"))return e.write(`\u5DF2\u53D6\u6D88
|
|
38
38
|
`),Ho;let t=await Gd({done:n=>e.write(`${so(e,f.accent,"\u2714")} ${n}
|
|
39
39
|
`),failed:n=>e.write(`${so(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
|
-
`),
|
|
41
|
+
`),Rr;e.write(`\u4EE5\u4E0B\u9879\u76EE\u672A\u80FD\u6E05\u7406\uFF1A
|
|
42
42
|
`);for(let n of t)e.write(` ${n}
|
|
43
43
|
`);return Ho}async function c_(e){let t=n_({input:process.stdin,output:process.stdout});t.once("SIGINT",()=>t.close());let n=await Promise.race([t.question(e),t_(t,"close").then(()=>"")]);return t.close(),n.trim().toLowerCase()==="y"}function l_(){if(!process.stdin.isTTY||!process.stdout.isTTY)throw new F("\u4EA4\u4E92\u754C\u9762\u9700\u8981\u5728\u7EC8\u7AEF\u4E2D\u76F4\u63A5\u8FD0\u884C")}var aS=(e,t)=>so(process.stderr,e,t);try{process.exitCode=await i_()}catch(e){process.stderr.write(`${aS(f.danger,"\u2718")} ${Se(e)}
|
|
44
44
|
`),e instanceof F&&e.hint&&process.stderr.write(` ${aS(f.faintForeground,e.hint)}
|